@crvouga/mockingbird-service-resend 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/dist/cli.js CHANGED
@@ -3,9 +3,9 @@ import {
3
3
  runCli,
4
4
  serveCommand,
5
5
  serveTarget
6
- } from "./chunk-WMQIKI4U.js";
7
- import "./chunk-XQ4BQDIK.js";
8
- import "./chunk-M73LWCCP.js";
6
+ } from "./chunk-YE2BKTX6.js";
7
+ import "./chunk-YJDLINUI.js";
8
+ import "./chunk-6Z2MR3PO.js";
9
9
 
10
10
  // src/cli.ts
11
11
  var code = await runCli(
@@ -0,0 +1,21 @@
1
+ import {
2
+ createHash,
3
+ createHmac,
4
+ random,
5
+ randomBytes,
6
+ randomUUID,
7
+ timingSafeEqual,
8
+ useRandom,
9
+ withRandom
10
+ } from "./chunk-6Z2MR3PO.js";
11
+ export {
12
+ createHash,
13
+ createHmac,
14
+ random,
15
+ randomBytes,
16
+ randomUUID,
17
+ timingSafeEqual,
18
+ useRandom,
19
+ withRandom
20
+ };
21
+ //# sourceMappingURL=crypto-II2ETGQQ.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  randomUUID
3
- } from "./chunk-M73LWCCP.js";
3
+ } from "./chunk-6Z2MR3PO.js";
4
4
 
5
5
  // ../../http/provider/dist/vendor/clerk/helpers.js
6
6
  function generateClerkId(prefix) {
@@ -83,4 +83,4 @@ export {
83
83
  userDisplayName
84
84
  };
85
85
  /*! Adapted from vercel-labs/emulate (Apache-2.0), modified for Mockingbird. See port.json, LICENSE_EMULATE and THIRD_PARTY_NOTICES.md. */
86
- //# sourceMappingURL=helpers-BMHFVPFA.js.map
86
+ //# sourceMappingURL=helpers-5D4ROPWG.js.map
package/dist/index.d.ts CHANGED
@@ -93,6 +93,11 @@ type ProviderOptions = APIOptions$1 & {
93
93
  fallbackUser?: AuthFallback;
94
94
  publicNamespace?: string;
95
95
  adminPrefix?: string;
96
+ /**
97
+ * A seeded stream of `[0, 1)` that ids and tokens are minted from, so a run replays from
98
+ * its seed. Default: the platform's randomness.
99
+ */
100
+ random?: () => number;
96
101
  };
97
102
 
98
103
  type MountedAPI = FetchAPI & {
@@ -294,7 +299,7 @@ type ClockState = {
294
299
  now: number;
295
300
  /** True while time does not advance on its own. */
296
301
  frozen: boolean;
297
- /** Milliseconds this clock adds to its underlying source. */
302
+ /** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
298
303
  offsetMs: number;
299
304
  };
300
305
  type Clock = {
@@ -330,7 +335,10 @@ type Rng = {
330
335
  state(): number;
331
336
  /** Restore a state previously returned by {@link state}. */
332
337
  setState(state: number): void;
333
- seed: number;
338
+ /** Restart the stream from a new seed. `reset` then returns to this seed. */
339
+ reseed(seed: number | string): void;
340
+ /** The seed the stream currently starts from. */
341
+ readonly seed: number;
334
342
  };
335
343
 
336
344
  /**
@@ -339,44 +347,83 @@ type Rng = {
339
347
  * This is how a suite reaches the vendor's failure modes without the vendor: the
340
348
  * quota error that only appears when a shared sandbox is full, the 429 that only
341
349
  * appears under load, the 5xx that proves a retry path works.
350
+ *
351
+ * A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
352
+ * it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
353
+ * and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
342
354
  */
343
355
  type FaultRule = {
344
- /** Stable id, so a suite can retire exactly the rule it added. */
356
+ /** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
345
357
  id: string;
346
358
  /** Fault only this operation. Omit to match every operation. */
347
359
  operationId?: string;
348
360
  /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
349
361
  method?: string;
362
+ /** Fault only this exact path. */
363
+ path?: string;
350
364
  /** Fault only paths starting with this prefix. Omit to match every path. */
351
365
  pathPrefix?: string;
366
+ /** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
367
+ pathPattern?: string;
368
+ /** Fault only requests carrying these headers. `"*"` matches any value. */
369
+ requestHeaders?: Record<string, string>;
370
+ /** Fault only requests carrying these query parameters. `"*"` matches any value. */
371
+ query?: Record<string, string>;
352
372
  /**
353
373
  * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
354
374
  * an in-process caller usually wants, and what a parallel worker usually does not:
355
375
  * rules added through `POST /__admin/faults` default to the calling namespace.
356
376
  */
357
377
  namespace?: string;
378
+ /** Let this many matching requests through first. */
379
+ after?: number;
380
+ /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
381
+ every?: number;
382
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
383
+ count?: number;
384
+ /** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
385
+ rate?: number;
358
386
  /**
359
- * Status of the injected response. Omit for a rule that only delays (`delayMs` /
360
- * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
361
- * the request then still reaches the service.
387
+ * Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
388
+ * clock when the rule was added. Listed as epoch ms.
389
+ */
390
+ from?: Instant | Duration;
391
+ /** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
392
+ until?: Instant | Duration;
393
+ /**
394
+ * Status of the injected response. Omit for a rule that only delays, times out, drops,
395
+ * truncates, or switches on an `effect`: the request then still reaches the service.
362
396
  */
363
397
  status?: number;
364
398
  /** Response body, serialized as JSON. A string is sent as-is. */
365
399
  body?: unknown;
400
+ /** Response headers. */
366
401
  headers?: Record<string, string>;
367
- /** Retire the rule after this many faults. Omit to keep it until removed. */
368
- count?: number;
369
- /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
370
- rate?: number;
371
- /** Hold the response back this long, to exercise timeouts. */
402
+ /** Hold the response back this long. Listed as `delayMs`. */
403
+ delay?: Duration;
404
+ /** `delay`, in milliseconds. */
372
405
  delayMs?: number;
373
406
  /** Alias of `delayMs`. */
374
407
  latencyMs?: number;
408
+ /** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
409
+ jitter?: Duration;
410
+ jitterMs?: number;
411
+ /**
412
+ * Never answer: hold the request this long, then drop the connection. Listed as
413
+ * `timeoutMs`. With virtual time the wait is spent on the mock clock.
414
+ */
415
+ timeout?: Duration;
416
+ timeoutMs?: number;
375
417
  /**
376
418
  * Drop the connection instead of answering: an in-process `fetch` rejects with a
377
419
  * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
378
420
  */
379
421
  drop?: boolean;
422
+ /**
423
+ * Cut the response body off after this many bytes: the status and headers arrive, then
424
+ * the connection dies mid-body.
425
+ */
426
+ truncate?: number;
380
427
  /**
381
428
  * A named service behaviour to switch on for the matching request instead of (or
382
429
  * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
@@ -385,8 +432,8 @@ type FaultRule = {
385
432
  effect?: string;
386
433
  /** Parameters for `effect`. */
387
434
  params?: Record<string, unknown>;
388
- /** From the preset this rule was expanded from, if any. */
389
- preset?: string;
435
+ /** The preset this rule was expanded from, if any. */
436
+ fromPreset?: string;
390
437
  };
391
438
  /** A fault that fired for one request. */
392
439
  type FaultHit = {
@@ -394,6 +441,10 @@ type FaultHit = {
394
441
  /** The injected response; absent when the rule only delays, drops, or sets an effect. */
395
442
  response?: Response;
396
443
  drop?: boolean;
444
+ /** Set with `drop` when the rule held the request for its `timeout` first. */
445
+ timeout?: boolean;
446
+ /** Bytes of response body to let through before the connection dies. */
447
+ truncate?: number;
397
448
  effect?: {
398
449
  name: string;
399
450
  params: Record<string, unknown>;
@@ -418,38 +469,200 @@ type FaultCandidate = {
418
469
  method: string;
419
470
  path: string;
420
471
  namespace: string;
472
+ /** Request headers and query, for rules that match on them. */
473
+ headers?: Headers;
474
+ query?: URLSearchParams;
475
+ /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
476
+ now?: number;
477
+ /** How to spend a delay for this request. Default: the registry's own sleep. */
478
+ wait?: (ms: number) => Promise<void>;
479
+ };
480
+ /** A stored rule and how often it was consulted. */
481
+ type FaultListing = FaultRule & {
482
+ /** Faults left before the rule retires. `null` when it has no `count`. */
483
+ remaining: number | null;
484
+ /** Times the rule faulted a request. */
485
+ hits: number;
486
+ /** Requests that matched the rule, faulted or not. */
487
+ seen: number;
488
+ };
489
+ /** A namespace's own rules, with their counters, in the order they are tried. */
490
+ type FaultSnapshot = {
491
+ /**
492
+ * `position` is how many `"*"` rules are tried before the rule, which is what its place
493
+ * in the order means to a request and holds in any process.
494
+ */
495
+ rules: (FaultListing & {
496
+ position?: number;
497
+ })[];
498
+ /** How many `fault_<n>` ids the namespace has handed out. */
499
+ nextId?: number;
421
500
  };
422
501
  type FaultRegistry = {
423
- isolateNamespaces(): void;
424
- snapshot(namespace: string): {
425
- rules: (FaultRule & {
426
- remaining: number | null;
427
- hits: number;
428
- position: number;
429
- })[];
430
- rngState: number;
431
- };
502
+ snapshot(namespace: string): FaultSnapshot;
503
+ /** Add a rule, or replace the rule with the same id in the same namespace. */
432
504
  add(rule: FaultRule): FaultRule;
433
- list(): (FaultRule & {
434
- remaining: number | null;
435
- hits: number;
436
- })[];
437
- remove(id: string): boolean;
438
- clear(): void;
439
- restore(namespace: string, state: {
440
- rules: (FaultRule & {
441
- remaining: number | null;
442
- hits: number;
443
- position: number;
444
- })[];
445
- rngState: number;
446
- }): void;
505
+ /** The next unused `fault_<n>` id in `namespace`. */
506
+ nextId(namespace: string): string;
507
+ /** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
508
+ list(namespace?: string): FaultListing[];
509
+ get(id: string, namespace?: string): FaultListing | undefined;
510
+ /** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
511
+ remove(id: string, namespace?: string): boolean;
512
+ /** Remove every rule, or one namespace's own rules. */
513
+ clear(namespace?: string): void;
514
+ /** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
515
+ restore(namespace: string, state: FaultSnapshot): void;
447
516
  /**
448
517
  * Every fault this request should get, in rule order, stopping at the first that answers
449
518
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
450
519
  * each matching rule's remaining uses.
451
520
  */
452
521
  take(candidate: FaultCandidate): Promise<FaultHit[]>;
522
+ /**
523
+ * Fire these rules at one request without storing them: no matching, no schedule, in order,
524
+ * stopping at the first that answers or drops. Jitter draws from the namespace's stream.
525
+ */
526
+ fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
527
+ };
528
+
529
+ /**
530
+ * The admin controls every mock shares, as one document.
531
+ *
532
+ * The same shape is accepted in three places, and means the same thing in each:
533
+ *
534
+ * - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
535
+ * `MOCKINGBIRD_ADMIN_CONTROLS`
536
+ * - over HTTP: `PUT /__admin/controls`
537
+ * - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
538
+ *
539
+ * Every control is deterministic: given the same seed, clock and requests, a mock answers
540
+ * the same bytes. Nothing here reads the wall clock or `Math.random`.
541
+ */
542
+ /** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
543
+ type Duration = number | string;
544
+ /** Epoch milliseconds, or an ISO-8601 string. */
545
+ type Instant = number | string;
546
+ type ClockControls = {
547
+ /** Move the clock to this instant. */
548
+ now?: Instant;
549
+ /** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
550
+ frozen?: boolean;
551
+ /**
552
+ * Step the clock forward by this much before every vendor request. With a frozen clock
553
+ * each request still gets its own, reproducible timestamp.
554
+ */
555
+ autoAdvance?: Duration;
556
+ };
557
+ /** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
558
+ type LatencyRuleInput = {
559
+ delay?: Duration;
560
+ jitter?: Duration;
561
+ };
562
+ type LatencyControls = LatencyRuleInput & {
563
+ /** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
564
+ operations?: Record<string, Duration | LatencyRuleInput>;
565
+ };
566
+ /** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
567
+ type FaultInput = (Omit<FaultRule, "id"> & {
568
+ id?: string;
569
+ }) | ({
570
+ preset: string;
571
+ } & Partial<FaultRule>);
572
+ /** Identifies a {@link SnapshotDocument}. */
573
+ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
574
+ /**
575
+ * A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
576
+ * `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
577
+ * `records` are required, so a hand-written seed file is a valid snapshot.
578
+ */
579
+ type SnapshotDocument = {
580
+ format: typeof SNAPSHOT_FORMAT;
581
+ /** The service that wrote it. A snapshot is rejected by any other service. */
582
+ service?: string;
583
+ /**
584
+ * Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
585
+ * the stored text of a row that is not a plain record, and replaces `value` when present.
586
+ */
587
+ records: {
588
+ collection: string;
589
+ id: string;
590
+ seq?: number;
591
+ value?: unknown;
592
+ raw?: string;
593
+ }[];
594
+ /** Id counters, so the next generated id continues where the snapshot left off. */
595
+ sequences?: {
596
+ name: string;
597
+ kind: string;
598
+ value: number;
599
+ }[];
600
+ clock?: {
601
+ now: number;
602
+ frozen: boolean;
603
+ autoAdvanceMs?: number;
604
+ };
605
+ seed?: number | string;
606
+ /** Positions of the seeded random streams. */
607
+ rng?: {
608
+ state: number;
609
+ faults?: number;
610
+ latency?: number;
611
+ };
612
+ faults?: unknown;
613
+ latency?: unknown;
614
+ virtualTime?: boolean;
615
+ };
616
+ /** Controls for one namespace. */
617
+ type NamespaceControls = {
618
+ /** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
619
+ seed?: number | string;
620
+ clock?: ClockControls;
621
+ /**
622
+ * Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
623
+ * wall clock: the request returns at once, the clock has moved, and the journal records
624
+ * the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
625
+ */
626
+ virtualTime?: boolean;
627
+ /** Baseline response time for every vendor request. A bare duration is its `delay`. */
628
+ latency?: Duration | LatencyControls;
629
+ faults?: readonly FaultInput[];
630
+ /** Start from this state instead of the service's own seed data. */
631
+ snapshot?: SnapshotDocument;
632
+ };
633
+ /** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
634
+ type MockControls = NamespaceControls & {
635
+ /** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
636
+ credentials?: Record<string, string>;
637
+ /** Overrides for named namespaces. A key given here replaces the shared value. */
638
+ namespaces?: Record<string, NamespaceControls>;
639
+ };
640
+ /** A latency rule in milliseconds. */
641
+ type LatencyRule = {
642
+ delayMs: number;
643
+ jitterMs: number;
644
+ };
645
+ /** Baseline latency for a namespace, normalized. */
646
+ type LatencyState = LatencyRule & {
647
+ operations: Record<string, LatencyRule>;
648
+ };
649
+ /** What {@link controlHeaders} turns into request headers. */
650
+ type ControlHeaderInput = {
651
+ namespace?: string;
652
+ adminKey?: string;
653
+ branch?: string;
654
+ at?: string;
655
+ reset?: boolean;
656
+ restore?: string;
657
+ seed?: number | string;
658
+ time?: Instant | Date;
659
+ advance?: Duration;
660
+ virtualTime?: boolean;
661
+ delay?: Duration;
662
+ timeout?: Duration;
663
+ /** A status, `"drop"`, a preset name, or a fault rule. */
664
+ fault?: number | string | Record<string, unknown>;
665
+ snapshot?: string;
453
666
  };
454
667
 
455
668
  /**
@@ -489,6 +702,8 @@ type RequestLog = {
489
702
  unmatched: boolean;
490
703
  /** Set when a fault rule produced the response. */
491
704
  faultId?: string;
705
+ /** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
706
+ delayMs?: number;
492
707
  /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
493
708
  ids?: Record<string, string>;
494
709
  /** Set when the service created a resource the request referred to but that did not exist. */
@@ -534,6 +749,12 @@ type JournalQuery = {
534
749
  /** Only this namespace. Omit for every namespace, oldest first across all of them. */
535
750
  namespace?: string;
536
751
  operationId?: string;
752
+ /** Only this HTTP method, case-insensitive. */
753
+ method?: string;
754
+ /** Only this exact path. */
755
+ path?: string;
756
+ /** Only requests this fault rule answered or shaped. */
757
+ faultId?: string;
537
758
  status?: number;
538
759
  /** Only entries at or after this instant (epoch ms). */
539
760
  since?: number;
@@ -548,6 +769,50 @@ type Journal = {
548
769
  clear(namespace?: string): void;
549
770
  };
550
771
 
772
+ /**
773
+ * Baseline response time, per namespace: how long every vendor request takes before any
774
+ * fault is considered. Jitter draws from a stream the caller owns, one per namespace and
775
+ * separate from the fault stream, so adding latency never shifts which requests a `rate`
776
+ * fault hits.
777
+ */
778
+ type LatencyRegistry = {
779
+ get(namespace: string): LatencyState;
780
+ set(namespace: string, state: LatencyState): LatencyState;
781
+ /** Remove one namespace's latency, or every namespace's. */
782
+ clear(namespace?: string): void;
783
+ /** Milliseconds this request waits. Draws jitter, so call it once per request. */
784
+ take(namespace: string, operationId: string | undefined): number;
785
+ };
786
+
787
+ /** Clock state as the admin API reports it. */
788
+ type ControlClock = ClockState & {
789
+ /** `now`, as ISO-8601. */
790
+ iso: string;
791
+ /** Milliseconds the clock steps before every vendor request. */
792
+ autoAdvanceMs: number;
793
+ };
794
+ /** One namespace's controls: the body of `GET /__admin/controls`. */
795
+ type ControlState = {
796
+ namespace: string;
797
+ seed: number | string;
798
+ clock: ControlClock;
799
+ virtualTime: boolean;
800
+ latency: LatencyState;
801
+ faults: FaultListing[];
802
+ };
803
+
804
+ /** What `GET /__admin/snapshots` lists for each snapshot. */
805
+ type SnapshotInfo = {
806
+ id: string;
807
+ namespace: string;
808
+ /** Stored rows in the snapshot. */
809
+ records: number;
810
+ /** The namespace clock when it was taken, epoch ms. */
811
+ at: number;
812
+ /** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
813
+ portable: boolean;
814
+ };
815
+
551
816
  /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
552
817
  type CredentialRegistry = {
553
818
  set(credential: string, namespace: string): void;
@@ -720,7 +985,10 @@ type ServiceInstance = FetchAPI & {
720
985
  };
721
986
  type ServiceTimelineState = Readonly<{
722
987
  snapshot: NamespaceSnapshot;
723
- clock: Readonly<ReturnType<Clock["state"]>>;
988
+ /** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
989
+ clock: Readonly<ClockState & {
990
+ pinned?: boolean;
991
+ }>;
724
992
  rngState: number;
725
993
  }>;
726
994
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
@@ -733,14 +1001,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
733
1001
  readonly sqlite: SqliteClient$1;
734
1002
  readonly clock: Clock;
735
1003
  readonly faults: FaultRegistry;
1004
+ /** Baseline response time per namespace. */
1005
+ readonly latency: LatencyRegistry;
736
1006
  readonly metrics: Metrics;
737
1007
  readonly journal: Journal;
738
1008
  readonly rng: Rng;
739
1009
  readonly credentials: CredentialRegistry;
740
1010
  /** The webhook hub, when the service has outbound webhooks. */
741
1011
  readonly webhooks: WebhookHub | undefined;
742
- /** Enable independent namespace clocks and PRNGs before serving a fleet. */
743
- isolateNamespaces(): void;
1012
+ /**
1013
+ * A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
1014
+ * offset and a freeze of its own, so moving one never moves another.
1015
+ */
744
1016
  namespaceClock(namespace?: string): Clock;
745
1017
  namespaceOf(request: Request): string;
746
1018
  /** Opaque in-process checkpoint including records, controls and webhook history. */
@@ -752,8 +1024,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
752
1024
  instance(namespace?: string): T;
753
1025
  /** Public names of every namespace created so far. */
754
1026
  namespaces(): string[];
755
- /** Reset one namespace, or every namespace with `"*"`. */
1027
+ /** Return one namespace to its boot state, or every namespace with `"*"`. */
756
1028
  reset(namespace?: string): Promise<void>;
1029
+ /** Reset a namespace and forget it, releasing everything it held. */
1030
+ dropNamespace(namespace: string): Promise<void>;
1031
+ /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
1032
+ controls(namespace?: string): ControlState & {
1033
+ snapshots: SnapshotInfo[];
1034
+ };
1035
+ /** Apply a control document to a namespace. A given key replaces that control. */
1036
+ configure(controls: NamespaceControls, namespace?: string): ControlState & {
1037
+ snapshots: SnapshotInfo[];
1038
+ };
1039
+ /** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
1040
+ readonly snapshots: {
1041
+ /** Capture the namespace now. Reusing a name replaces that snapshot. */
1042
+ create(options?: {
1043
+ name?: string;
1044
+ namespace?: string;
1045
+ }): SnapshotInfo;
1046
+ list(namespace?: string): SnapshotInfo[];
1047
+ /** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
1048
+ export(id: string, namespace?: string): SnapshotDocument;
1049
+ /** Store a document as a snapshot without restoring it. */
1050
+ import(document: SnapshotDocument, options?: {
1051
+ name?: string;
1052
+ namespace?: string;
1053
+ }): SnapshotInfo;
1054
+ restore(id: string, namespace?: string): void;
1055
+ delete(id: string, namespace?: string): boolean;
1056
+ };
1057
+ /** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
1058
+ headers(input: ControlHeaderInput): Record<string, string>;
757
1059
  snapshot(namespace?: string): NamespaceSnapshot;
758
1060
  restore(snapshot: NamespaceSnapshot, namespace?: string): void;
759
1061
  /** Capture the current branch. Mutating HTTP calls do this automatically. */
@@ -1090,6 +1392,8 @@ type ForwardTarget = {
1090
1392
  adminPrefix?: string;
1091
1393
  /** Its `x-mockingbird-admin-key`, when it has one. */
1092
1394
  adminKey?: string;
1395
+ /** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
1396
+ adminControls?: MockControls;
1093
1397
  /** Give up on a forward after this long (the send still succeeds). Default 2000 ms. */
1094
1398
  timeoutMs?: number;
1095
1399
  fetch?: (request: Request) => Promise<Response>;
@@ -1110,6 +1414,8 @@ type ResendRuntimeOptions = Pick<ResendAPIOptions, "fixtures" | "baseUrl" | "tok
1110
1414
  seed?: number | string;
1111
1415
  adminPrefix?: string;
1112
1416
  adminKey?: string;
1417
+ /** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
1418
+ adminControls?: MockControls;
1113
1419
  onLog?: (entry: RequestLog) => void;
1114
1420
  /**
1115
1421
  * Where `email.received` webhooks go (`POST /messaging/inbound/email`), signed with the
@@ -1202,7 +1508,7 @@ type SendOutcomeEvent = {
1202
1508
  namespace: string;
1203
1509
  emailId?: string;
1204
1510
  };
1205
- type ResendAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix"> & {
1511
+ type ResendAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix" | "random"> & {
1206
1512
  fixtures?: ResendSeedConfig;
1207
1513
  /** The public namespace name, for `/__admin/ns/<name>` download URLs. Default: the default namespace. */
1208
1514
  adminPrefix?: string;
package/dist/index.js CHANGED
@@ -9,8 +9,8 @@ import {
9
9
  forwardToInbox,
10
10
  operationIds,
11
11
  supportedOperationIds
12
- } from "./chunk-XQ4BQDIK.js";
13
- import "./chunk-M73LWCCP.js";
12
+ } from "./chunk-YJDLINUI.js";
13
+ import "./chunk-6Z2MR3PO.js";
14
14
  export {
15
15
  DOWNLOAD_URL_TTL_MS,
16
16
  RESEND_NAMESPACE,