@crvouga/mockingbird-service-stripe 3.2.0 → 3.3.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 +8 -2
- package/DISCOVERY.md +23 -0
- package/README.md +20 -17
- package/dist/{chunk-3ANL4Q47.js → chunk-ESFURE4Z.js} +2449 -653
- package/dist/{chunk-3ANL4Q47.js.map → chunk-ESFURE4Z.js.map} +4 -4
- package/dist/{chunk-QYOTTK3Z.js → chunk-N7LLU7DT.js} +135 -24
- package/dist/chunk-N7LLU7DT.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +339 -40
- package/dist/index.js +1 -1
- package/dist/server.d.ts +678 -80
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-QYOTTK3Z.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -211,7 +211,7 @@ type ClockState = {
|
|
|
211
211
|
now: number;
|
|
212
212
|
/** True while time does not advance on its own. */
|
|
213
213
|
frozen: boolean;
|
|
214
|
-
/** Milliseconds
|
|
214
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
215
215
|
offsetMs: number;
|
|
216
216
|
};
|
|
217
217
|
type Clock = {
|
|
@@ -247,7 +247,10 @@ type Rng = {
|
|
|
247
247
|
state(): number;
|
|
248
248
|
/** Restore a state previously returned by {@link state}. */
|
|
249
249
|
setState(state: number): void;
|
|
250
|
-
seed
|
|
250
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
251
|
+
reseed(seed: number | string): void;
|
|
252
|
+
/** The seed the stream currently starts from. */
|
|
253
|
+
readonly seed: number;
|
|
251
254
|
};
|
|
252
255
|
|
|
253
256
|
/**
|
|
@@ -256,44 +259,83 @@ type Rng = {
|
|
|
256
259
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
257
260
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
258
261
|
* appears under load, the 5xx that proves a retry path works.
|
|
262
|
+
*
|
|
263
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
264
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
265
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
259
266
|
*/
|
|
260
267
|
type FaultRule = {
|
|
261
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
268
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
262
269
|
id: string;
|
|
263
270
|
/** Fault only this operation. Omit to match every operation. */
|
|
264
271
|
operationId?: string;
|
|
265
272
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
266
273
|
method?: string;
|
|
274
|
+
/** Fault only this exact path. */
|
|
275
|
+
path?: string;
|
|
267
276
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
268
277
|
pathPrefix?: string;
|
|
278
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
279
|
+
pathPattern?: string;
|
|
280
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
281
|
+
requestHeaders?: Record<string, string>;
|
|
282
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
283
|
+
query?: Record<string, string>;
|
|
269
284
|
/**
|
|
270
285
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
271
286
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
272
287
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
273
288
|
*/
|
|
274
289
|
namespace?: string;
|
|
290
|
+
/** Let this many matching requests through first. */
|
|
291
|
+
after?: number;
|
|
292
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
293
|
+
every?: number;
|
|
294
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
295
|
+
count?: number;
|
|
296
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
297
|
+
rate?: number;
|
|
298
|
+
/**
|
|
299
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
300
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
301
|
+
*/
|
|
302
|
+
from?: Instant | Duration;
|
|
303
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
304
|
+
until?: Instant | Duration;
|
|
275
305
|
/**
|
|
276
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
277
|
-
*
|
|
278
|
-
* the request then still reaches the service.
|
|
306
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
307
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
279
308
|
*/
|
|
280
309
|
status?: number;
|
|
281
310
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
282
311
|
body?: unknown;
|
|
312
|
+
/** Response headers. */
|
|
283
313
|
headers?: Record<string, string>;
|
|
284
|
-
/**
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
rate?: number;
|
|
288
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
314
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
315
|
+
delay?: Duration;
|
|
316
|
+
/** `delay`, in milliseconds. */
|
|
289
317
|
delayMs?: number;
|
|
290
318
|
/** Alias of `delayMs`. */
|
|
291
319
|
latencyMs?: number;
|
|
320
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
321
|
+
jitter?: Duration;
|
|
322
|
+
jitterMs?: number;
|
|
323
|
+
/**
|
|
324
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
325
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
326
|
+
*/
|
|
327
|
+
timeout?: Duration;
|
|
328
|
+
timeoutMs?: number;
|
|
292
329
|
/**
|
|
293
330
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
294
331
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
295
332
|
*/
|
|
296
333
|
drop?: boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
336
|
+
* the connection dies mid-body.
|
|
337
|
+
*/
|
|
338
|
+
truncate?: number;
|
|
297
339
|
/**
|
|
298
340
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
299
341
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -302,8 +344,8 @@ type FaultRule = {
|
|
|
302
344
|
effect?: string;
|
|
303
345
|
/** Parameters for `effect`. */
|
|
304
346
|
params?: Record<string, unknown>;
|
|
305
|
-
/**
|
|
306
|
-
|
|
347
|
+
/** The preset this rule was expanded from, if any. */
|
|
348
|
+
fromPreset?: string;
|
|
307
349
|
};
|
|
308
350
|
/** A fault that fired for one request. */
|
|
309
351
|
type FaultHit = {
|
|
@@ -311,6 +353,10 @@ type FaultHit = {
|
|
|
311
353
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
312
354
|
response?: Response;
|
|
313
355
|
drop?: boolean;
|
|
356
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
357
|
+
timeout?: boolean;
|
|
358
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
359
|
+
truncate?: number;
|
|
314
360
|
effect?: {
|
|
315
361
|
name: string;
|
|
316
362
|
params: Record<string, unknown>;
|
|
@@ -335,38 +381,200 @@ type FaultCandidate = {
|
|
|
335
381
|
method: string;
|
|
336
382
|
path: string;
|
|
337
383
|
namespace: string;
|
|
384
|
+
/** Request headers and query, for rules that match on them. */
|
|
385
|
+
headers?: Headers;
|
|
386
|
+
query?: URLSearchParams;
|
|
387
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
388
|
+
now?: number;
|
|
389
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
390
|
+
wait?: (ms: number) => Promise<void>;
|
|
391
|
+
};
|
|
392
|
+
/** A stored rule and how often it was consulted. */
|
|
393
|
+
type FaultListing = FaultRule & {
|
|
394
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
395
|
+
remaining: number | null;
|
|
396
|
+
/** Times the rule faulted a request. */
|
|
397
|
+
hits: number;
|
|
398
|
+
/** Requests that matched the rule, faulted or not. */
|
|
399
|
+
seen: number;
|
|
400
|
+
};
|
|
401
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
402
|
+
type FaultSnapshot = {
|
|
403
|
+
/**
|
|
404
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
405
|
+
* in the order means to a request and holds in any process.
|
|
406
|
+
*/
|
|
407
|
+
rules: (FaultListing & {
|
|
408
|
+
position?: number;
|
|
409
|
+
})[];
|
|
410
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
411
|
+
nextId?: number;
|
|
338
412
|
};
|
|
339
413
|
type FaultRegistry = {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
rules: (FaultRule & {
|
|
343
|
-
remaining: number | null;
|
|
344
|
-
hits: number;
|
|
345
|
-
position: number;
|
|
346
|
-
})[];
|
|
347
|
-
rngState: number;
|
|
348
|
-
};
|
|
414
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
415
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
349
416
|
add(rule: FaultRule): FaultRule;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
})[];
|
|
362
|
-
rngState: number;
|
|
363
|
-
}): void;
|
|
417
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
418
|
+
nextId(namespace: string): string;
|
|
419
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
420
|
+
list(namespace?: string): FaultListing[];
|
|
421
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
422
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
423
|
+
remove(id: string, namespace?: string): boolean;
|
|
424
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
425
|
+
clear(namespace?: string): void;
|
|
426
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
427
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
364
428
|
/**
|
|
365
429
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
366
430
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
367
431
|
* each matching rule's remaining uses.
|
|
368
432
|
*/
|
|
369
433
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
434
|
+
/**
|
|
435
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
436
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
437
|
+
*/
|
|
438
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The admin controls every mock shares, as one document.
|
|
443
|
+
*
|
|
444
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
445
|
+
*
|
|
446
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
447
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
448
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
449
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
450
|
+
*
|
|
451
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
452
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
453
|
+
*/
|
|
454
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
455
|
+
type Duration = number | string;
|
|
456
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
457
|
+
type Instant = number | string;
|
|
458
|
+
type ClockControls = {
|
|
459
|
+
/** Move the clock to this instant. */
|
|
460
|
+
now?: Instant;
|
|
461
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
462
|
+
frozen?: boolean;
|
|
463
|
+
/**
|
|
464
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
465
|
+
* each request still gets its own, reproducible timestamp.
|
|
466
|
+
*/
|
|
467
|
+
autoAdvance?: Duration;
|
|
468
|
+
};
|
|
469
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
470
|
+
type LatencyRuleInput = {
|
|
471
|
+
delay?: Duration;
|
|
472
|
+
jitter?: Duration;
|
|
473
|
+
};
|
|
474
|
+
type LatencyControls = LatencyRuleInput & {
|
|
475
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
476
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
477
|
+
};
|
|
478
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
479
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
480
|
+
id?: string;
|
|
481
|
+
}) | ({
|
|
482
|
+
preset: string;
|
|
483
|
+
} & Partial<FaultRule>);
|
|
484
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
485
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
486
|
+
/**
|
|
487
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
488
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
489
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
490
|
+
*/
|
|
491
|
+
type SnapshotDocument = {
|
|
492
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
493
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
494
|
+
service?: string;
|
|
495
|
+
/**
|
|
496
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
497
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
498
|
+
*/
|
|
499
|
+
records: {
|
|
500
|
+
collection: string;
|
|
501
|
+
id: string;
|
|
502
|
+
seq?: number;
|
|
503
|
+
value?: unknown;
|
|
504
|
+
raw?: string;
|
|
505
|
+
}[];
|
|
506
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
507
|
+
sequences?: {
|
|
508
|
+
name: string;
|
|
509
|
+
kind: string;
|
|
510
|
+
value: number;
|
|
511
|
+
}[];
|
|
512
|
+
clock?: {
|
|
513
|
+
now: number;
|
|
514
|
+
frozen: boolean;
|
|
515
|
+
autoAdvanceMs?: number;
|
|
516
|
+
};
|
|
517
|
+
seed?: number | string;
|
|
518
|
+
/** Positions of the seeded random streams. */
|
|
519
|
+
rng?: {
|
|
520
|
+
state: number;
|
|
521
|
+
faults?: number;
|
|
522
|
+
latency?: number;
|
|
523
|
+
};
|
|
524
|
+
faults?: unknown;
|
|
525
|
+
latency?: unknown;
|
|
526
|
+
virtualTime?: boolean;
|
|
527
|
+
};
|
|
528
|
+
/** Controls for one namespace. */
|
|
529
|
+
type NamespaceControls = {
|
|
530
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
531
|
+
seed?: number | string;
|
|
532
|
+
clock?: ClockControls;
|
|
533
|
+
/**
|
|
534
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
535
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
536
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
537
|
+
*/
|
|
538
|
+
virtualTime?: boolean;
|
|
539
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
540
|
+
latency?: Duration | LatencyControls;
|
|
541
|
+
faults?: readonly FaultInput[];
|
|
542
|
+
/** Start from this state instead of the service's own seed data. */
|
|
543
|
+
snapshot?: SnapshotDocument;
|
|
544
|
+
};
|
|
545
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
546
|
+
type MockControls = NamespaceControls & {
|
|
547
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
548
|
+
credentials?: Record<string, string>;
|
|
549
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
550
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
551
|
+
};
|
|
552
|
+
/** A latency rule in milliseconds. */
|
|
553
|
+
type LatencyRule = {
|
|
554
|
+
delayMs: number;
|
|
555
|
+
jitterMs: number;
|
|
556
|
+
};
|
|
557
|
+
/** Baseline latency for a namespace, normalized. */
|
|
558
|
+
type LatencyState = LatencyRule & {
|
|
559
|
+
operations: Record<string, LatencyRule>;
|
|
560
|
+
};
|
|
561
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
562
|
+
type ControlHeaderInput = {
|
|
563
|
+
namespace?: string;
|
|
564
|
+
adminKey?: string;
|
|
565
|
+
branch?: string;
|
|
566
|
+
at?: string;
|
|
567
|
+
reset?: boolean;
|
|
568
|
+
restore?: string;
|
|
569
|
+
seed?: number | string;
|
|
570
|
+
time?: Instant | Date;
|
|
571
|
+
advance?: Duration;
|
|
572
|
+
virtualTime?: boolean;
|
|
573
|
+
delay?: Duration;
|
|
574
|
+
timeout?: Duration;
|
|
575
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
576
|
+
fault?: number | string | Record<string, unknown>;
|
|
577
|
+
snapshot?: string;
|
|
370
578
|
};
|
|
371
579
|
|
|
372
580
|
/**
|
|
@@ -406,6 +614,8 @@ type RequestLog = {
|
|
|
406
614
|
unmatched: boolean;
|
|
407
615
|
/** Set when a fault rule produced the response. */
|
|
408
616
|
faultId?: string;
|
|
617
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
618
|
+
delayMs?: number;
|
|
409
619
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
410
620
|
ids?: Record<string, string>;
|
|
411
621
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -451,6 +661,12 @@ type JournalQuery = {
|
|
|
451
661
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
452
662
|
namespace?: string;
|
|
453
663
|
operationId?: string;
|
|
664
|
+
/** Only this HTTP method, case-insensitive. */
|
|
665
|
+
method?: string;
|
|
666
|
+
/** Only this exact path. */
|
|
667
|
+
path?: string;
|
|
668
|
+
/** Only requests this fault rule answered or shaped. */
|
|
669
|
+
faultId?: string;
|
|
454
670
|
status?: number;
|
|
455
671
|
/** Only entries at or after this instant (epoch ms). */
|
|
456
672
|
since?: number;
|
|
@@ -465,6 +681,50 @@ type Journal = {
|
|
|
465
681
|
clear(namespace?: string): void;
|
|
466
682
|
};
|
|
467
683
|
|
|
684
|
+
/**
|
|
685
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
686
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
687
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
688
|
+
* fault hits.
|
|
689
|
+
*/
|
|
690
|
+
type LatencyRegistry = {
|
|
691
|
+
get(namespace: string): LatencyState;
|
|
692
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
693
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
694
|
+
clear(namespace?: string): void;
|
|
695
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
696
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
/** Clock state as the admin API reports it. */
|
|
700
|
+
type ControlClock = ClockState & {
|
|
701
|
+
/** `now`, as ISO-8601. */
|
|
702
|
+
iso: string;
|
|
703
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
704
|
+
autoAdvanceMs: number;
|
|
705
|
+
};
|
|
706
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
707
|
+
type ControlState = {
|
|
708
|
+
namespace: string;
|
|
709
|
+
seed: number | string;
|
|
710
|
+
clock: ControlClock;
|
|
711
|
+
virtualTime: boolean;
|
|
712
|
+
latency: LatencyState;
|
|
713
|
+
faults: FaultListing[];
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
717
|
+
type SnapshotInfo = {
|
|
718
|
+
id: string;
|
|
719
|
+
namespace: string;
|
|
720
|
+
/** Stored rows in the snapshot. */
|
|
721
|
+
records: number;
|
|
722
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
723
|
+
at: number;
|
|
724
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
725
|
+
portable: boolean;
|
|
726
|
+
};
|
|
727
|
+
|
|
468
728
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
469
729
|
type CredentialRegistry = {
|
|
470
730
|
set(credential: string, namespace: string): void;
|
|
@@ -619,7 +879,10 @@ type ServiceInstance = FetchAPI$1 & {
|
|
|
619
879
|
};
|
|
620
880
|
type ServiceTimelineState = Readonly<{
|
|
621
881
|
snapshot: NamespaceSnapshot;
|
|
622
|
-
clock
|
|
882
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
883
|
+
clock: Readonly<ClockState & {
|
|
884
|
+
pinned?: boolean;
|
|
885
|
+
}>;
|
|
623
886
|
rngState: number;
|
|
624
887
|
}>;
|
|
625
888
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -632,14 +895,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
632
895
|
readonly sqlite: SqliteClient$1;
|
|
633
896
|
readonly clock: Clock;
|
|
634
897
|
readonly faults: FaultRegistry;
|
|
898
|
+
/** Baseline response time per namespace. */
|
|
899
|
+
readonly latency: LatencyRegistry;
|
|
635
900
|
readonly metrics: Metrics;
|
|
636
901
|
readonly journal: Journal;
|
|
637
902
|
readonly rng: Rng;
|
|
638
903
|
readonly credentials: CredentialRegistry;
|
|
639
904
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
640
905
|
readonly webhooks: WebhookHub | undefined;
|
|
641
|
-
/**
|
|
642
|
-
|
|
906
|
+
/**
|
|
907
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
908
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
909
|
+
*/
|
|
643
910
|
namespaceClock(namespace?: string): Clock;
|
|
644
911
|
namespaceOf(request: Request): string;
|
|
645
912
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -651,8 +918,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
651
918
|
instance(namespace?: string): T;
|
|
652
919
|
/** Public names of every namespace created so far. */
|
|
653
920
|
namespaces(): string[];
|
|
654
|
-
/**
|
|
921
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
655
922
|
reset(namespace?: string): Promise<void>;
|
|
923
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
924
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
925
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
926
|
+
controls(namespace?: string): ControlState & {
|
|
927
|
+
snapshots: SnapshotInfo[];
|
|
928
|
+
};
|
|
929
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
930
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
931
|
+
snapshots: SnapshotInfo[];
|
|
932
|
+
};
|
|
933
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
934
|
+
readonly snapshots: {
|
|
935
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
936
|
+
create(options?: {
|
|
937
|
+
name?: string;
|
|
938
|
+
namespace?: string;
|
|
939
|
+
}): SnapshotInfo;
|
|
940
|
+
list(namespace?: string): SnapshotInfo[];
|
|
941
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
942
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
943
|
+
/** Store a document as a snapshot without restoring it. */
|
|
944
|
+
import(document: SnapshotDocument, options?: {
|
|
945
|
+
name?: string;
|
|
946
|
+
namespace?: string;
|
|
947
|
+
}): SnapshotInfo;
|
|
948
|
+
restore(id: string, namespace?: string): void;
|
|
949
|
+
delete(id: string, namespace?: string): boolean;
|
|
950
|
+
};
|
|
951
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
952
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
656
953
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
657
954
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
658
955
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1933,6 +2230,8 @@ type StripeRuntimeOptions = {
|
|
|
1933
2230
|
adminPrefix?: string;
|
|
1934
2231
|
/** Require `x-mockingbird-admin-key` on `/__admin/*`. */
|
|
1935
2232
|
adminKey?: string;
|
|
2233
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
2234
|
+
adminControls?: MockControls;
|
|
1936
2235
|
onLog?: (entry: RequestLog) => void;
|
|
1937
2236
|
/** Called in-process with every event the mock records. */
|
|
1938
2237
|
onWebhook?: StripeAPIOptions["onWebhook"];
|