@crvouga/mockingbird-service-easypost 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -4
- package/DISCOVERY.md +23 -0
- package/README.md +19 -21
- package/dist/chunk-5324HY4K.js +5701 -0
- package/dist/chunk-5324HY4K.js.map +7 -0
- package/dist/chunk-SATJWSEK.js +4759 -0
- package/dist/chunk-SATJWSEK.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +354 -41
- package/dist/index.js +1 -1
- package/dist/server.d.ts +709 -82
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-BLZBXMKY.js +0 -3806
- package/dist/chunk-BLZBXMKY.js.map +0 -7
- package/dist/chunk-HN4W2OFU.js +0 -840
- package/dist/chunk-HN4W2OFU.js.map +0 -7
package/dist/server.d.ts
CHANGED
|
@@ -145,7 +145,7 @@ type ClockState$1 = {
|
|
|
145
145
|
now: number;
|
|
146
146
|
/** True while time does not advance on its own. */
|
|
147
147
|
frozen: boolean;
|
|
148
|
-
/** Milliseconds
|
|
148
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
149
149
|
offsetMs: number;
|
|
150
150
|
};
|
|
151
151
|
type Clock$1 = {
|
|
@@ -181,7 +181,10 @@ type Rng$1 = {
|
|
|
181
181
|
state(): number;
|
|
182
182
|
/** Restore a state previously returned by {@link state}. */
|
|
183
183
|
setState(state: number): void;
|
|
184
|
-
seed
|
|
184
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
185
|
+
reseed(seed: number | string): void;
|
|
186
|
+
/** The seed the stream currently starts from. */
|
|
187
|
+
readonly seed: number;
|
|
185
188
|
};
|
|
186
189
|
|
|
187
190
|
/**
|
|
@@ -190,44 +193,83 @@ type Rng$1 = {
|
|
|
190
193
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
191
194
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
192
195
|
* appears under load, the 5xx that proves a retry path works.
|
|
196
|
+
*
|
|
197
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
198
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
199
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
193
200
|
*/
|
|
194
201
|
type FaultRule$1 = {
|
|
195
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
202
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
196
203
|
id: string;
|
|
197
204
|
/** Fault only this operation. Omit to match every operation. */
|
|
198
205
|
operationId?: string;
|
|
199
206
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
200
207
|
method?: string;
|
|
208
|
+
/** Fault only this exact path. */
|
|
209
|
+
path?: string;
|
|
201
210
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
202
211
|
pathPrefix?: string;
|
|
212
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
213
|
+
pathPattern?: string;
|
|
214
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
215
|
+
requestHeaders?: Record<string, string>;
|
|
216
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
217
|
+
query?: Record<string, string>;
|
|
203
218
|
/**
|
|
204
219
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
205
220
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
206
221
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
207
222
|
*/
|
|
208
223
|
namespace?: string;
|
|
224
|
+
/** Let this many matching requests through first. */
|
|
225
|
+
after?: number;
|
|
226
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
227
|
+
every?: number;
|
|
228
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
229
|
+
count?: number;
|
|
230
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
231
|
+
rate?: number;
|
|
232
|
+
/**
|
|
233
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
234
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
235
|
+
*/
|
|
236
|
+
from?: Instant$1 | Duration$1;
|
|
237
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
238
|
+
until?: Instant$1 | Duration$1;
|
|
209
239
|
/**
|
|
210
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
211
|
-
*
|
|
212
|
-
* the request then still reaches the service.
|
|
240
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
241
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
213
242
|
*/
|
|
214
243
|
status?: number;
|
|
215
244
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
216
245
|
body?: unknown;
|
|
246
|
+
/** Response headers. */
|
|
217
247
|
headers?: Record<string, string>;
|
|
218
|
-
/**
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
rate?: number;
|
|
222
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
248
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
249
|
+
delay?: Duration$1;
|
|
250
|
+
/** `delay`, in milliseconds. */
|
|
223
251
|
delayMs?: number;
|
|
224
252
|
/** Alias of `delayMs`. */
|
|
225
253
|
latencyMs?: number;
|
|
254
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
255
|
+
jitter?: Duration$1;
|
|
256
|
+
jitterMs?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
259
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
260
|
+
*/
|
|
261
|
+
timeout?: Duration$1;
|
|
262
|
+
timeoutMs?: number;
|
|
226
263
|
/**
|
|
227
264
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
228
265
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
229
266
|
*/
|
|
230
267
|
drop?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
270
|
+
* the connection dies mid-body.
|
|
271
|
+
*/
|
|
272
|
+
truncate?: number;
|
|
231
273
|
/**
|
|
232
274
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
233
275
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -236,8 +278,8 @@ type FaultRule$1 = {
|
|
|
236
278
|
effect?: string;
|
|
237
279
|
/** Parameters for `effect`. */
|
|
238
280
|
params?: Record<string, unknown>;
|
|
239
|
-
/**
|
|
240
|
-
|
|
281
|
+
/** The preset this rule was expanded from, if any. */
|
|
282
|
+
fromPreset?: string;
|
|
241
283
|
};
|
|
242
284
|
/** A fault that fired for one request. */
|
|
243
285
|
type FaultHit$1 = {
|
|
@@ -245,6 +287,10 @@ type FaultHit$1 = {
|
|
|
245
287
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
246
288
|
response?: Response;
|
|
247
289
|
drop?: boolean;
|
|
290
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
291
|
+
timeout?: boolean;
|
|
292
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
293
|
+
truncate?: number;
|
|
248
294
|
effect?: {
|
|
249
295
|
name: string;
|
|
250
296
|
params: Record<string, unknown>;
|
|
@@ -256,38 +302,202 @@ type FaultCandidate$1 = {
|
|
|
256
302
|
method: string;
|
|
257
303
|
path: string;
|
|
258
304
|
namespace: string;
|
|
305
|
+
/** Request headers and query, for rules that match on them. */
|
|
306
|
+
headers?: Headers;
|
|
307
|
+
query?: URLSearchParams;
|
|
308
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
309
|
+
now?: number;
|
|
310
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
311
|
+
wait?: (ms: number) => Promise<void>;
|
|
312
|
+
};
|
|
313
|
+
/** A stored rule and how often it was consulted. */
|
|
314
|
+
type FaultListing$1 = FaultRule$1 & {
|
|
315
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
316
|
+
remaining: number | null;
|
|
317
|
+
/** Times the rule faulted a request. */
|
|
318
|
+
hits: number;
|
|
319
|
+
/** Requests that matched the rule, faulted or not. */
|
|
320
|
+
seen: number;
|
|
321
|
+
};
|
|
322
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
323
|
+
type FaultSnapshot$1 = {
|
|
324
|
+
/**
|
|
325
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
326
|
+
* in the order means to a request and holds in any process.
|
|
327
|
+
*/
|
|
328
|
+
rules: (FaultListing$1 & {
|
|
329
|
+
position?: number;
|
|
330
|
+
})[];
|
|
331
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
332
|
+
nextId?: number;
|
|
259
333
|
};
|
|
260
334
|
type FaultRegistry$1 = {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
rules: (FaultRule$1 & {
|
|
264
|
-
remaining: number | null;
|
|
265
|
-
hits: number;
|
|
266
|
-
position: number;
|
|
267
|
-
})[];
|
|
268
|
-
rngState: number;
|
|
269
|
-
};
|
|
335
|
+
snapshot(namespace: string): FaultSnapshot$1;
|
|
336
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
270
337
|
add(rule: FaultRule$1): FaultRule$1;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
})[];
|
|
283
|
-
rngState: number;
|
|
284
|
-
}): void;
|
|
338
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
339
|
+
nextId(namespace: string): string;
|
|
340
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
341
|
+
list(namespace?: string): FaultListing$1[];
|
|
342
|
+
get(id: string, namespace?: string): FaultListing$1 | undefined;
|
|
343
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
344
|
+
remove(id: string, namespace?: string): boolean;
|
|
345
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
346
|
+
clear(namespace?: string): void;
|
|
347
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
348
|
+
restore(namespace: string, state: FaultSnapshot$1): void;
|
|
285
349
|
/**
|
|
286
350
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
287
351
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
288
352
|
* each matching rule's remaining uses.
|
|
289
353
|
*/
|
|
290
354
|
take(candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
355
|
+
/**
|
|
356
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
357
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
358
|
+
*/
|
|
359
|
+
fire(rules: readonly FaultRule$1[], candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The admin controls every mock shares, as one document.
|
|
364
|
+
*
|
|
365
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
366
|
+
*
|
|
367
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
368
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
369
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
370
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
371
|
+
*
|
|
372
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
373
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
374
|
+
*/
|
|
375
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
376
|
+
type Duration$1 = number | string;
|
|
377
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
378
|
+
type Instant$1 = number | string;
|
|
379
|
+
type ClockControls$1 = {
|
|
380
|
+
/** Move the clock to this instant. */
|
|
381
|
+
now?: Instant$1;
|
|
382
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
383
|
+
frozen?: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
386
|
+
* each request still gets its own, reproducible timestamp.
|
|
387
|
+
*/
|
|
388
|
+
autoAdvance?: Duration$1;
|
|
389
|
+
};
|
|
390
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
391
|
+
type LatencyRuleInput$1 = {
|
|
392
|
+
delay?: Duration$1;
|
|
393
|
+
jitter?: Duration$1;
|
|
394
|
+
};
|
|
395
|
+
type LatencyControls$1 = LatencyRuleInput$1 & {
|
|
396
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
397
|
+
operations?: Record<string, Duration$1 | LatencyRuleInput$1>;
|
|
398
|
+
};
|
|
399
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
400
|
+
type FaultInput$1 = (Omit<FaultRule$1, "id"> & {
|
|
401
|
+
id?: string;
|
|
402
|
+
}) | ({
|
|
403
|
+
preset: string;
|
|
404
|
+
} & Partial<FaultRule$1>);
|
|
405
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
406
|
+
declare const SNAPSHOT_FORMAT$1 = "mockingbird.snapshot/v1";
|
|
407
|
+
/**
|
|
408
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
409
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
410
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
411
|
+
*/
|
|
412
|
+
type SnapshotDocument$1 = {
|
|
413
|
+
format: typeof SNAPSHOT_FORMAT$1;
|
|
414
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
415
|
+
service?: string;
|
|
416
|
+
/**
|
|
417
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
418
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
419
|
+
*/
|
|
420
|
+
records: {
|
|
421
|
+
collection: string;
|
|
422
|
+
id: string;
|
|
423
|
+
seq?: number;
|
|
424
|
+
value?: unknown;
|
|
425
|
+
raw?: string;
|
|
426
|
+
}[];
|
|
427
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
428
|
+
sequences?: {
|
|
429
|
+
name: string;
|
|
430
|
+
kind: string;
|
|
431
|
+
value: number;
|
|
432
|
+
}[];
|
|
433
|
+
clock?: {
|
|
434
|
+
now: number;
|
|
435
|
+
frozen: boolean;
|
|
436
|
+
autoAdvanceMs?: number;
|
|
437
|
+
};
|
|
438
|
+
seed?: number | string;
|
|
439
|
+
/** Positions of the seeded random streams. */
|
|
440
|
+
rng?: {
|
|
441
|
+
state: number;
|
|
442
|
+
faults?: number;
|
|
443
|
+
latency?: number;
|
|
444
|
+
};
|
|
445
|
+
faults?: unknown;
|
|
446
|
+
latency?: unknown;
|
|
447
|
+
virtualTime?: boolean;
|
|
448
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
449
|
+
webhooks?: unknown;
|
|
450
|
+
};
|
|
451
|
+
/** Controls for one namespace. */
|
|
452
|
+
type NamespaceControls$1 = {
|
|
453
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
454
|
+
seed?: number | string;
|
|
455
|
+
clock?: ClockControls$1;
|
|
456
|
+
/**
|
|
457
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
458
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
459
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
460
|
+
*/
|
|
461
|
+
virtualTime?: boolean;
|
|
462
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
463
|
+
latency?: Duration$1 | LatencyControls$1;
|
|
464
|
+
faults?: readonly FaultInput$1[];
|
|
465
|
+
/** Start from this state instead of the service's own seed data. */
|
|
466
|
+
snapshot?: SnapshotDocument$1;
|
|
467
|
+
};
|
|
468
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
469
|
+
type MockControls$1 = NamespaceControls$1 & {
|
|
470
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
471
|
+
credentials?: Record<string, string>;
|
|
472
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
473
|
+
namespaces?: Record<string, NamespaceControls$1>;
|
|
474
|
+
};
|
|
475
|
+
/** A latency rule in milliseconds. */
|
|
476
|
+
type LatencyRule$1 = {
|
|
477
|
+
delayMs: number;
|
|
478
|
+
jitterMs: number;
|
|
479
|
+
};
|
|
480
|
+
/** Baseline latency for a namespace, normalized. */
|
|
481
|
+
type LatencyState$1 = LatencyRule$1 & {
|
|
482
|
+
operations: Record<string, LatencyRule$1>;
|
|
483
|
+
};
|
|
484
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
485
|
+
type ControlHeaderInput$1 = {
|
|
486
|
+
namespace?: string;
|
|
487
|
+
adminKey?: string;
|
|
488
|
+
branch?: string;
|
|
489
|
+
at?: string;
|
|
490
|
+
reset?: boolean;
|
|
491
|
+
restore?: string;
|
|
492
|
+
seed?: number | string;
|
|
493
|
+
time?: Instant$1 | Date;
|
|
494
|
+
advance?: Duration$1;
|
|
495
|
+
virtualTime?: boolean;
|
|
496
|
+
delay?: Duration$1;
|
|
497
|
+
timeout?: Duration$1;
|
|
498
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
499
|
+
fault?: number | string | Record<string, unknown>;
|
|
500
|
+
snapshot?: string;
|
|
291
501
|
};
|
|
292
502
|
|
|
293
503
|
/**
|
|
@@ -327,6 +537,8 @@ type RequestLog$1 = {
|
|
|
327
537
|
unmatched: boolean;
|
|
328
538
|
/** Set when a fault rule produced the response. */
|
|
329
539
|
faultId?: string;
|
|
540
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
541
|
+
delayMs?: number;
|
|
330
542
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
331
543
|
ids?: Record<string, string>;
|
|
332
544
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -372,6 +584,12 @@ type JournalQuery$1 = {
|
|
|
372
584
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
373
585
|
namespace?: string;
|
|
374
586
|
operationId?: string;
|
|
587
|
+
/** Only this HTTP method, case-insensitive. */
|
|
588
|
+
method?: string;
|
|
589
|
+
/** Only this exact path. */
|
|
590
|
+
path?: string;
|
|
591
|
+
/** Only requests this fault rule answered or shaped. */
|
|
592
|
+
faultId?: string;
|
|
375
593
|
status?: number;
|
|
376
594
|
/** Only entries at or after this instant (epoch ms). */
|
|
377
595
|
since?: number;
|
|
@@ -386,6 +604,50 @@ type Journal$1 = {
|
|
|
386
604
|
clear(namespace?: string): void;
|
|
387
605
|
};
|
|
388
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
609
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
610
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
611
|
+
* fault hits.
|
|
612
|
+
*/
|
|
613
|
+
type LatencyRegistry$1 = {
|
|
614
|
+
get(namespace: string): LatencyState$1;
|
|
615
|
+
set(namespace: string, state: LatencyState$1): LatencyState$1;
|
|
616
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
617
|
+
clear(namespace?: string): void;
|
|
618
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
619
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/** Clock state as the admin API reports it. */
|
|
623
|
+
type ControlClock$1 = ClockState$1 & {
|
|
624
|
+
/** `now`, as ISO-8601. */
|
|
625
|
+
iso: string;
|
|
626
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
627
|
+
autoAdvanceMs: number;
|
|
628
|
+
};
|
|
629
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
630
|
+
type ControlState$1 = {
|
|
631
|
+
namespace: string;
|
|
632
|
+
seed: number | string;
|
|
633
|
+
clock: ControlClock$1;
|
|
634
|
+
virtualTime: boolean;
|
|
635
|
+
latency: LatencyState$1;
|
|
636
|
+
faults: FaultListing$1[];
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
640
|
+
type SnapshotInfo$1 = {
|
|
641
|
+
id: string;
|
|
642
|
+
namespace: string;
|
|
643
|
+
/** Stored rows in the snapshot. */
|
|
644
|
+
records: number;
|
|
645
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
646
|
+
at: number;
|
|
647
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
648
|
+
portable: boolean;
|
|
649
|
+
};
|
|
650
|
+
|
|
389
651
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
390
652
|
type CredentialRegistry$1 = {
|
|
391
653
|
set(credential: string, namespace: string): void;
|
|
@@ -398,6 +660,8 @@ type CredentialRegistry$1 = {
|
|
|
398
660
|
}[];
|
|
399
661
|
};
|
|
400
662
|
|
|
663
|
+
type OwnedTransport$1 = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
664
|
+
|
|
401
665
|
/**
|
|
402
666
|
* A point-in-time copy of everything a service namespace holds.
|
|
403
667
|
*
|
|
@@ -515,8 +779,16 @@ type PublishInput$1 = {
|
|
|
515
779
|
id?: string;
|
|
516
780
|
};
|
|
517
781
|
type WebhookHub$1 = {
|
|
782
|
+
observeDeliveries(listener: (event: {
|
|
783
|
+
namespace: string;
|
|
784
|
+
state: string;
|
|
785
|
+
deliveryId: string;
|
|
786
|
+
}) => void): () => void;
|
|
787
|
+
setTransportPolicy(policy: OwnedTransport$1): void;
|
|
518
788
|
pending(namespace: string): number;
|
|
519
789
|
snapshot(namespace: string): unknown;
|
|
790
|
+
exportSnapshot(handle: unknown): unknown;
|
|
791
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
520
792
|
restore(namespace: string, snapshot: unknown): void;
|
|
521
793
|
publish(input: PublishInput$1): WebhookMessage$1;
|
|
522
794
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -529,7 +801,7 @@ type WebhookHub$1 = {
|
|
|
529
801
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
530
802
|
flush(): Promise<void>;
|
|
531
803
|
/** Resolve once nothing is in flight. */
|
|
532
|
-
idle(): Promise<void>;
|
|
804
|
+
idle(namespace?: string): Promise<void>;
|
|
533
805
|
fault(namespace: string, fault: WebhookFault$1): void;
|
|
534
806
|
clear(namespace?: string): void;
|
|
535
807
|
};
|
|
@@ -540,7 +812,10 @@ type ServiceInstance$1 = FetchAPI$2 & {
|
|
|
540
812
|
};
|
|
541
813
|
type ServiceTimelineState$1 = Readonly<{
|
|
542
814
|
snapshot: NamespaceSnapshot$1;
|
|
543
|
-
clock
|
|
815
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
816
|
+
clock: Readonly<ClockState$1 & {
|
|
817
|
+
pinned?: boolean;
|
|
818
|
+
}>;
|
|
544
819
|
rngState: number;
|
|
545
820
|
}>;
|
|
546
821
|
type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
|
|
@@ -553,27 +828,63 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
|
|
|
553
828
|
readonly sqlite: SqliteClient$2;
|
|
554
829
|
readonly clock: Clock$1;
|
|
555
830
|
readonly faults: FaultRegistry$1;
|
|
831
|
+
/** Baseline response time per namespace. */
|
|
832
|
+
readonly latency: LatencyRegistry$1;
|
|
556
833
|
readonly metrics: Metrics$1;
|
|
557
834
|
readonly journal: Journal$1;
|
|
558
835
|
readonly rng: Rng$1;
|
|
559
836
|
readonly credentials: CredentialRegistry$1;
|
|
560
837
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
561
838
|
readonly webhooks: WebhookHub$1 | undefined;
|
|
562
|
-
/**
|
|
563
|
-
|
|
839
|
+
/**
|
|
840
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
841
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
842
|
+
*/
|
|
564
843
|
namespaceClock(namespace?: string): Clock$1;
|
|
565
844
|
namespaceOf(request: Request): string;
|
|
566
845
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
567
846
|
fleetSnapshot(namespace: string): object;
|
|
568
847
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
848
|
+
fleetExport(snapshot: unknown): SnapshotDocument$1;
|
|
849
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
569
850
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
570
851
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule$1>): FaultRule$1[];
|
|
571
852
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
572
853
|
instance(namespace?: string): T;
|
|
573
854
|
/** Public names of every namespace created so far. */
|
|
574
855
|
namespaces(): string[];
|
|
575
|
-
/**
|
|
856
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
576
857
|
reset(namespace?: string): Promise<void>;
|
|
858
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
859
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
860
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
861
|
+
controls(namespace?: string): ControlState$1 & {
|
|
862
|
+
snapshots: SnapshotInfo$1[];
|
|
863
|
+
};
|
|
864
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
865
|
+
configure(controls: NamespaceControls$1, namespace?: string): ControlState$1 & {
|
|
866
|
+
snapshots: SnapshotInfo$1[];
|
|
867
|
+
};
|
|
868
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
869
|
+
readonly snapshots: {
|
|
870
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
871
|
+
create(options?: {
|
|
872
|
+
name?: string;
|
|
873
|
+
namespace?: string;
|
|
874
|
+
}): SnapshotInfo$1;
|
|
875
|
+
list(namespace?: string): SnapshotInfo$1[];
|
|
876
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
877
|
+
export(id: string, namespace?: string): SnapshotDocument$1;
|
|
878
|
+
/** Store a document as a snapshot without restoring it. */
|
|
879
|
+
import(document: SnapshotDocument$1, options?: {
|
|
880
|
+
name?: string;
|
|
881
|
+
namespace?: string;
|
|
882
|
+
}): SnapshotInfo$1;
|
|
883
|
+
restore(id: string, namespace?: string): void;
|
|
884
|
+
delete(id: string, namespace?: string): boolean;
|
|
885
|
+
};
|
|
886
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
887
|
+
headers(input: ControlHeaderInput$1): Record<string, string>;
|
|
577
888
|
snapshot(namespace?: string): NamespaceSnapshot$1;
|
|
578
889
|
restore(snapshot: NamespaceSnapshot$1, namespace?: string): void;
|
|
579
890
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -616,6 +927,8 @@ type CommonServeOptions = {
|
|
|
616
927
|
adminKey: string | undefined;
|
|
617
928
|
seed: string | undefined;
|
|
618
929
|
onLog: ((entry: RequestLog$1) => void) | undefined;
|
|
930
|
+
/** Admin controls to boot with: clock, latency, faults, a starting snapshot. */
|
|
931
|
+
adminControls?: MockControls$1;
|
|
619
932
|
/** Synthetic provider fixture objects supplied by a fleet entry. */
|
|
620
933
|
fixtures?: Record<string, unknown>;
|
|
621
934
|
baseUrl?: string;
|
|
@@ -626,6 +939,7 @@ type CommonServeOptions = {
|
|
|
626
939
|
* `serveTarget`, which is also how `serve --config` finds services by name.
|
|
627
940
|
*/
|
|
628
941
|
type ServeTarget = {
|
|
942
|
+
packageVersion?: string;
|
|
629
943
|
name: string;
|
|
630
944
|
defaultPort: number;
|
|
631
945
|
/** Serve flags beyond the common ones. */
|
|
@@ -848,7 +1162,7 @@ type ClockState = {
|
|
|
848
1162
|
now: number;
|
|
849
1163
|
/** True while time does not advance on its own. */
|
|
850
1164
|
frozen: boolean;
|
|
851
|
-
/** Milliseconds
|
|
1165
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
852
1166
|
offsetMs: number;
|
|
853
1167
|
};
|
|
854
1168
|
type Clock = {
|
|
@@ -884,7 +1198,10 @@ type Rng = {
|
|
|
884
1198
|
state(): number;
|
|
885
1199
|
/** Restore a state previously returned by {@link state}. */
|
|
886
1200
|
setState(state: number): void;
|
|
887
|
-
seed
|
|
1201
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
1202
|
+
reseed(seed: number | string): void;
|
|
1203
|
+
/** The seed the stream currently starts from. */
|
|
1204
|
+
readonly seed: number;
|
|
888
1205
|
};
|
|
889
1206
|
|
|
890
1207
|
/**
|
|
@@ -893,44 +1210,83 @@ type Rng = {
|
|
|
893
1210
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
894
1211
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
895
1212
|
* appears under load, the 5xx that proves a retry path works.
|
|
1213
|
+
*
|
|
1214
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
1215
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
1216
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
896
1217
|
*/
|
|
897
1218
|
type FaultRule = {
|
|
898
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
1219
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
899
1220
|
id: string;
|
|
900
1221
|
/** Fault only this operation. Omit to match every operation. */
|
|
901
1222
|
operationId?: string;
|
|
902
1223
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
903
1224
|
method?: string;
|
|
1225
|
+
/** Fault only this exact path. */
|
|
1226
|
+
path?: string;
|
|
904
1227
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
905
1228
|
pathPrefix?: string;
|
|
1229
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
1230
|
+
pathPattern?: string;
|
|
1231
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
1232
|
+
requestHeaders?: Record<string, string>;
|
|
1233
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
1234
|
+
query?: Record<string, string>;
|
|
906
1235
|
/**
|
|
907
1236
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
908
1237
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
909
1238
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
910
1239
|
*/
|
|
911
1240
|
namespace?: string;
|
|
1241
|
+
/** Let this many matching requests through first. */
|
|
1242
|
+
after?: number;
|
|
1243
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
1244
|
+
every?: number;
|
|
1245
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
1246
|
+
count?: number;
|
|
1247
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
1248
|
+
rate?: number;
|
|
1249
|
+
/**
|
|
1250
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
1251
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
1252
|
+
*/
|
|
1253
|
+
from?: Instant | Duration;
|
|
1254
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
1255
|
+
until?: Instant | Duration;
|
|
912
1256
|
/**
|
|
913
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
914
|
-
*
|
|
915
|
-
* the request then still reaches the service.
|
|
1257
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
1258
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
916
1259
|
*/
|
|
917
1260
|
status?: number;
|
|
918
1261
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
919
1262
|
body?: unknown;
|
|
1263
|
+
/** Response headers. */
|
|
920
1264
|
headers?: Record<string, string>;
|
|
921
|
-
/**
|
|
922
|
-
|
|
923
|
-
/**
|
|
924
|
-
rate?: number;
|
|
925
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
1265
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
1266
|
+
delay?: Duration;
|
|
1267
|
+
/** `delay`, in milliseconds. */
|
|
926
1268
|
delayMs?: number;
|
|
927
1269
|
/** Alias of `delayMs`. */
|
|
928
1270
|
latencyMs?: number;
|
|
1271
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
1272
|
+
jitter?: Duration;
|
|
1273
|
+
jitterMs?: number;
|
|
1274
|
+
/**
|
|
1275
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
1276
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
1277
|
+
*/
|
|
1278
|
+
timeout?: Duration;
|
|
1279
|
+
timeoutMs?: number;
|
|
929
1280
|
/**
|
|
930
1281
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
931
1282
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
932
1283
|
*/
|
|
933
1284
|
drop?: boolean;
|
|
1285
|
+
/**
|
|
1286
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
1287
|
+
* the connection dies mid-body.
|
|
1288
|
+
*/
|
|
1289
|
+
truncate?: number;
|
|
934
1290
|
/**
|
|
935
1291
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
936
1292
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -939,8 +1295,8 @@ type FaultRule = {
|
|
|
939
1295
|
effect?: string;
|
|
940
1296
|
/** Parameters for `effect`. */
|
|
941
1297
|
params?: Record<string, unknown>;
|
|
942
|
-
/**
|
|
943
|
-
|
|
1298
|
+
/** The preset this rule was expanded from, if any. */
|
|
1299
|
+
fromPreset?: string;
|
|
944
1300
|
};
|
|
945
1301
|
/** A fault that fired for one request. */
|
|
946
1302
|
type FaultHit = {
|
|
@@ -948,6 +1304,10 @@ type FaultHit = {
|
|
|
948
1304
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
949
1305
|
response?: Response;
|
|
950
1306
|
drop?: boolean;
|
|
1307
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
1308
|
+
timeout?: boolean;
|
|
1309
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
1310
|
+
truncate?: number;
|
|
951
1311
|
effect?: {
|
|
952
1312
|
name: string;
|
|
953
1313
|
params: Record<string, unknown>;
|
|
@@ -959,38 +1319,202 @@ type FaultCandidate = {
|
|
|
959
1319
|
method: string;
|
|
960
1320
|
path: string;
|
|
961
1321
|
namespace: string;
|
|
1322
|
+
/** Request headers and query, for rules that match on them. */
|
|
1323
|
+
headers?: Headers;
|
|
1324
|
+
query?: URLSearchParams;
|
|
1325
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
1326
|
+
now?: number;
|
|
1327
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
1328
|
+
wait?: (ms: number) => Promise<void>;
|
|
1329
|
+
};
|
|
1330
|
+
/** A stored rule and how often it was consulted. */
|
|
1331
|
+
type FaultListing = FaultRule & {
|
|
1332
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
1333
|
+
remaining: number | null;
|
|
1334
|
+
/** Times the rule faulted a request. */
|
|
1335
|
+
hits: number;
|
|
1336
|
+
/** Requests that matched the rule, faulted or not. */
|
|
1337
|
+
seen: number;
|
|
1338
|
+
};
|
|
1339
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
1340
|
+
type FaultSnapshot = {
|
|
1341
|
+
/**
|
|
1342
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
1343
|
+
* in the order means to a request and holds in any process.
|
|
1344
|
+
*/
|
|
1345
|
+
rules: (FaultListing & {
|
|
1346
|
+
position?: number;
|
|
1347
|
+
})[];
|
|
1348
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
1349
|
+
nextId?: number;
|
|
962
1350
|
};
|
|
963
1351
|
type FaultRegistry = {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
rules: (FaultRule & {
|
|
967
|
-
remaining: number | null;
|
|
968
|
-
hits: number;
|
|
969
|
-
position: number;
|
|
970
|
-
})[];
|
|
971
|
-
rngState: number;
|
|
972
|
-
};
|
|
1352
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
1353
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
973
1354
|
add(rule: FaultRule): FaultRule;
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
})[];
|
|
986
|
-
rngState: number;
|
|
987
|
-
}): void;
|
|
1355
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
1356
|
+
nextId(namespace: string): string;
|
|
1357
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
1358
|
+
list(namespace?: string): FaultListing[];
|
|
1359
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
1360
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
1361
|
+
remove(id: string, namespace?: string): boolean;
|
|
1362
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
1363
|
+
clear(namespace?: string): void;
|
|
1364
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
1365
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
988
1366
|
/**
|
|
989
1367
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
990
1368
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
991
1369
|
* each matching rule's remaining uses.
|
|
992
1370
|
*/
|
|
993
1371
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1372
|
+
/**
|
|
1373
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
1374
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
1375
|
+
*/
|
|
1376
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* The admin controls every mock shares, as one document.
|
|
1381
|
+
*
|
|
1382
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
1383
|
+
*
|
|
1384
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
1385
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
1386
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
1387
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
1388
|
+
*
|
|
1389
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
1390
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
1391
|
+
*/
|
|
1392
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
1393
|
+
type Duration = number | string;
|
|
1394
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
1395
|
+
type Instant = number | string;
|
|
1396
|
+
type ClockControls = {
|
|
1397
|
+
/** Move the clock to this instant. */
|
|
1398
|
+
now?: Instant;
|
|
1399
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
1400
|
+
frozen?: boolean;
|
|
1401
|
+
/**
|
|
1402
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
1403
|
+
* each request still gets its own, reproducible timestamp.
|
|
1404
|
+
*/
|
|
1405
|
+
autoAdvance?: Duration;
|
|
1406
|
+
};
|
|
1407
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
1408
|
+
type LatencyRuleInput = {
|
|
1409
|
+
delay?: Duration;
|
|
1410
|
+
jitter?: Duration;
|
|
1411
|
+
};
|
|
1412
|
+
type LatencyControls = LatencyRuleInput & {
|
|
1413
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
1414
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
1415
|
+
};
|
|
1416
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
1417
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
1418
|
+
id?: string;
|
|
1419
|
+
}) | ({
|
|
1420
|
+
preset: string;
|
|
1421
|
+
} & Partial<FaultRule>);
|
|
1422
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
1423
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
1424
|
+
/**
|
|
1425
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
1426
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
1427
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
1428
|
+
*/
|
|
1429
|
+
type SnapshotDocument = {
|
|
1430
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
1431
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
1432
|
+
service?: string;
|
|
1433
|
+
/**
|
|
1434
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
1435
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
1436
|
+
*/
|
|
1437
|
+
records: {
|
|
1438
|
+
collection: string;
|
|
1439
|
+
id: string;
|
|
1440
|
+
seq?: number;
|
|
1441
|
+
value?: unknown;
|
|
1442
|
+
raw?: string;
|
|
1443
|
+
}[];
|
|
1444
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
1445
|
+
sequences?: {
|
|
1446
|
+
name: string;
|
|
1447
|
+
kind: string;
|
|
1448
|
+
value: number;
|
|
1449
|
+
}[];
|
|
1450
|
+
clock?: {
|
|
1451
|
+
now: number;
|
|
1452
|
+
frozen: boolean;
|
|
1453
|
+
autoAdvanceMs?: number;
|
|
1454
|
+
};
|
|
1455
|
+
seed?: number | string;
|
|
1456
|
+
/** Positions of the seeded random streams. */
|
|
1457
|
+
rng?: {
|
|
1458
|
+
state: number;
|
|
1459
|
+
faults?: number;
|
|
1460
|
+
latency?: number;
|
|
1461
|
+
};
|
|
1462
|
+
faults?: unknown;
|
|
1463
|
+
latency?: unknown;
|
|
1464
|
+
virtualTime?: boolean;
|
|
1465
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
1466
|
+
webhooks?: unknown;
|
|
1467
|
+
};
|
|
1468
|
+
/** Controls for one namespace. */
|
|
1469
|
+
type NamespaceControls = {
|
|
1470
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
1471
|
+
seed?: number | string;
|
|
1472
|
+
clock?: ClockControls;
|
|
1473
|
+
/**
|
|
1474
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
1475
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
1476
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
1477
|
+
*/
|
|
1478
|
+
virtualTime?: boolean;
|
|
1479
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
1480
|
+
latency?: Duration | LatencyControls;
|
|
1481
|
+
faults?: readonly FaultInput[];
|
|
1482
|
+
/** Start from this state instead of the service's own seed data. */
|
|
1483
|
+
snapshot?: SnapshotDocument;
|
|
1484
|
+
};
|
|
1485
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
1486
|
+
type MockControls = NamespaceControls & {
|
|
1487
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
1488
|
+
credentials?: Record<string, string>;
|
|
1489
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
1490
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
1491
|
+
};
|
|
1492
|
+
/** A latency rule in milliseconds. */
|
|
1493
|
+
type LatencyRule = {
|
|
1494
|
+
delayMs: number;
|
|
1495
|
+
jitterMs: number;
|
|
1496
|
+
};
|
|
1497
|
+
/** Baseline latency for a namespace, normalized. */
|
|
1498
|
+
type LatencyState = LatencyRule & {
|
|
1499
|
+
operations: Record<string, LatencyRule>;
|
|
1500
|
+
};
|
|
1501
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
1502
|
+
type ControlHeaderInput = {
|
|
1503
|
+
namespace?: string;
|
|
1504
|
+
adminKey?: string;
|
|
1505
|
+
branch?: string;
|
|
1506
|
+
at?: string;
|
|
1507
|
+
reset?: boolean;
|
|
1508
|
+
restore?: string;
|
|
1509
|
+
seed?: number | string;
|
|
1510
|
+
time?: Instant | Date;
|
|
1511
|
+
advance?: Duration;
|
|
1512
|
+
virtualTime?: boolean;
|
|
1513
|
+
delay?: Duration;
|
|
1514
|
+
timeout?: Duration;
|
|
1515
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
1516
|
+
fault?: number | string | Record<string, unknown>;
|
|
1517
|
+
snapshot?: string;
|
|
994
1518
|
};
|
|
995
1519
|
|
|
996
1520
|
/**
|
|
@@ -1030,6 +1554,8 @@ type RequestLog = {
|
|
|
1030
1554
|
unmatched: boolean;
|
|
1031
1555
|
/** Set when a fault rule produced the response. */
|
|
1032
1556
|
faultId?: string;
|
|
1557
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
1558
|
+
delayMs?: number;
|
|
1033
1559
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
1034
1560
|
ids?: Record<string, string>;
|
|
1035
1561
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -1075,6 +1601,12 @@ type JournalQuery = {
|
|
|
1075
1601
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
1076
1602
|
namespace?: string;
|
|
1077
1603
|
operationId?: string;
|
|
1604
|
+
/** Only this HTTP method, case-insensitive. */
|
|
1605
|
+
method?: string;
|
|
1606
|
+
/** Only this exact path. */
|
|
1607
|
+
path?: string;
|
|
1608
|
+
/** Only requests this fault rule answered or shaped. */
|
|
1609
|
+
faultId?: string;
|
|
1078
1610
|
status?: number;
|
|
1079
1611
|
/** Only entries at or after this instant (epoch ms). */
|
|
1080
1612
|
since?: number;
|
|
@@ -1089,6 +1621,50 @@ type Journal = {
|
|
|
1089
1621
|
clear(namespace?: string): void;
|
|
1090
1622
|
};
|
|
1091
1623
|
|
|
1624
|
+
/**
|
|
1625
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
1626
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
1627
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
1628
|
+
* fault hits.
|
|
1629
|
+
*/
|
|
1630
|
+
type LatencyRegistry = {
|
|
1631
|
+
get(namespace: string): LatencyState;
|
|
1632
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
1633
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
1634
|
+
clear(namespace?: string): void;
|
|
1635
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
1636
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
/** Clock state as the admin API reports it. */
|
|
1640
|
+
type ControlClock = ClockState & {
|
|
1641
|
+
/** `now`, as ISO-8601. */
|
|
1642
|
+
iso: string;
|
|
1643
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
1644
|
+
autoAdvanceMs: number;
|
|
1645
|
+
};
|
|
1646
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
1647
|
+
type ControlState = {
|
|
1648
|
+
namespace: string;
|
|
1649
|
+
seed: number | string;
|
|
1650
|
+
clock: ControlClock;
|
|
1651
|
+
virtualTime: boolean;
|
|
1652
|
+
latency: LatencyState;
|
|
1653
|
+
faults: FaultListing[];
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1656
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
1657
|
+
type SnapshotInfo = {
|
|
1658
|
+
id: string;
|
|
1659
|
+
namespace: string;
|
|
1660
|
+
/** Stored rows in the snapshot. */
|
|
1661
|
+
records: number;
|
|
1662
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
1663
|
+
at: number;
|
|
1664
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
1665
|
+
portable: boolean;
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1092
1668
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
1093
1669
|
type CredentialRegistry = {
|
|
1094
1670
|
set(credential: string, namespace: string): void;
|
|
@@ -1101,6 +1677,8 @@ type CredentialRegistry = {
|
|
|
1101
1677
|
}[];
|
|
1102
1678
|
};
|
|
1103
1679
|
|
|
1680
|
+
type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
1681
|
+
|
|
1104
1682
|
/**
|
|
1105
1683
|
* A point-in-time copy of everything a service namespace holds.
|
|
1106
1684
|
*
|
|
@@ -1218,8 +1796,16 @@ type PublishInput = {
|
|
|
1218
1796
|
id?: string;
|
|
1219
1797
|
};
|
|
1220
1798
|
type WebhookHub = {
|
|
1799
|
+
observeDeliveries(listener: (event: {
|
|
1800
|
+
namespace: string;
|
|
1801
|
+
state: string;
|
|
1802
|
+
deliveryId: string;
|
|
1803
|
+
}) => void): () => void;
|
|
1804
|
+
setTransportPolicy(policy: OwnedTransport): void;
|
|
1221
1805
|
pending(namespace: string): number;
|
|
1222
1806
|
snapshot(namespace: string): unknown;
|
|
1807
|
+
exportSnapshot(handle: unknown): unknown;
|
|
1808
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
1223
1809
|
restore(namespace: string, snapshot: unknown): void;
|
|
1224
1810
|
publish(input: PublishInput): WebhookMessage;
|
|
1225
1811
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -1232,7 +1818,7 @@ type WebhookHub = {
|
|
|
1232
1818
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
1233
1819
|
flush(): Promise<void>;
|
|
1234
1820
|
/** Resolve once nothing is in flight. */
|
|
1235
|
-
idle(): Promise<void>;
|
|
1821
|
+
idle(namespace?: string): Promise<void>;
|
|
1236
1822
|
fault(namespace: string, fault: WebhookFault): void;
|
|
1237
1823
|
clear(namespace?: string): void;
|
|
1238
1824
|
};
|
|
@@ -1243,7 +1829,10 @@ type ServiceInstance = FetchAPI$1 & {
|
|
|
1243
1829
|
};
|
|
1244
1830
|
type ServiceTimelineState = Readonly<{
|
|
1245
1831
|
snapshot: NamespaceSnapshot;
|
|
1246
|
-
clock
|
|
1832
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1833
|
+
clock: Readonly<ClockState & {
|
|
1834
|
+
pinned?: boolean;
|
|
1835
|
+
}>;
|
|
1247
1836
|
rngState: number;
|
|
1248
1837
|
}>;
|
|
1249
1838
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -1256,27 +1845,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
1256
1845
|
readonly sqlite: SqliteClient$1;
|
|
1257
1846
|
readonly clock: Clock;
|
|
1258
1847
|
readonly faults: FaultRegistry;
|
|
1848
|
+
/** Baseline response time per namespace. */
|
|
1849
|
+
readonly latency: LatencyRegistry;
|
|
1259
1850
|
readonly metrics: Metrics;
|
|
1260
1851
|
readonly journal: Journal;
|
|
1261
1852
|
readonly rng: Rng;
|
|
1262
1853
|
readonly credentials: CredentialRegistry;
|
|
1263
1854
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
1264
1855
|
readonly webhooks: WebhookHub | undefined;
|
|
1265
|
-
/**
|
|
1266
|
-
|
|
1856
|
+
/**
|
|
1857
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1858
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1859
|
+
*/
|
|
1267
1860
|
namespaceClock(namespace?: string): Clock;
|
|
1268
1861
|
namespaceOf(request: Request): string;
|
|
1269
1862
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
1270
1863
|
fleetSnapshot(namespace: string): object;
|
|
1271
1864
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
1865
|
+
fleetExport(snapshot: unknown): SnapshotDocument;
|
|
1866
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
1272
1867
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
1273
1868
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
1274
1869
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
1275
1870
|
instance(namespace?: string): T;
|
|
1276
1871
|
/** Public names of every namespace created so far. */
|
|
1277
1872
|
namespaces(): string[];
|
|
1278
|
-
/**
|
|
1873
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
1279
1874
|
reset(namespace?: string): Promise<void>;
|
|
1875
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1876
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1877
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1878
|
+
controls(namespace?: string): ControlState & {
|
|
1879
|
+
snapshots: SnapshotInfo[];
|
|
1880
|
+
};
|
|
1881
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1882
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1883
|
+
snapshots: SnapshotInfo[];
|
|
1884
|
+
};
|
|
1885
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1886
|
+
readonly snapshots: {
|
|
1887
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1888
|
+
create(options?: {
|
|
1889
|
+
name?: string;
|
|
1890
|
+
namespace?: string;
|
|
1891
|
+
}): SnapshotInfo;
|
|
1892
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1893
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1894
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1895
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1896
|
+
import(document: SnapshotDocument, options?: {
|
|
1897
|
+
name?: string;
|
|
1898
|
+
namespace?: string;
|
|
1899
|
+
}): SnapshotInfo;
|
|
1900
|
+
restore(id: string, namespace?: string): void;
|
|
1901
|
+
delete(id: string, namespace?: string): boolean;
|
|
1902
|
+
};
|
|
1903
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1904
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
1280
1905
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
1281
1906
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
1282
1907
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1442,6 +2067,8 @@ type EasyPostRuntimeOptions = {
|
|
|
1442
2067
|
seed?: number | string;
|
|
1443
2068
|
adminPrefix?: string;
|
|
1444
2069
|
adminKey?: string;
|
|
2070
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
2071
|
+
adminControls?: MockControls;
|
|
1445
2072
|
onLog?: (entry: RequestLog) => void;
|
|
1446
2073
|
settings?: Partial<Settings>;
|
|
1447
2074
|
};
|