feat(provider-console): add mock latency support with jitter to ConsoleTransport

- Support latencyMs in ConsoleTransportOptions as a fixed number or range string (e.g. '60-150')\n- Apply randomized jitter between bounds to simulate real-world vendor network response times
This commit is contained in:
coo1estguy
2026-09-25 00:35:51 +05:30
parent 7624d5d3c2
commit 4173537aa4
+20 -1
View File
@@ -10,20 +10,39 @@ export interface ConsoleTransportOptions {
channel?: NotificationChannel;
logger?: Logger;
limits?: { limit: number; windowSeconds: number };
latencyMs?: number | string;
}
export class ConsoleTransport implements Transport {
readonly channel: NotificationChannel;
readonly limits?: { limit: number; windowSeconds: number };
readonly latencyMs?: number | string;
private readonly logger?: Logger;
constructor({ channel = "push", logger, limits }: ConsoleTransportOptions = {}) {
constructor({ channel = "push", logger, limits, latencyMs }: ConsoleTransportOptions = {}) {
this.channel = channel;
this.logger = logger;
this.limits = limits;
this.latencyMs = latencyMs;
}
async send(task: NotificationDispatchedPayload): Promise<DeliveryResult> {
if (this.latencyMs) {
let delay = 0;
if (typeof this.latencyMs === "number" && this.latencyMs > 0) {
delay = this.latencyMs;
} else if (typeof this.latencyMs === "string" && this.latencyMs.includes("-")) {
const [minStr, maxStr] = this.latencyMs.split("-");
const min = parseInt(minStr!, 10) || 0;
const max = parseInt(maxStr!, 10) || min;
delay = min === max ? min : Math.floor(Math.random() * (max - min + 1)) + min;
} else if (typeof this.latencyMs === "string") {
delay = parseInt(this.latencyMs, 10) || 0;
}
if (delay > 0) {
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
const providerMessageId = `console-${Date.now()}`;
console.log(