@crvouga/mockingbird-service-workos 1.1.0 → 1.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,8 +3,8 @@ import {
3
3
  runCli,
4
4
  serveCommand,
5
5
  serveTarget
6
- } from "./chunk-BIGV6FI5.js";
7
- import "./chunk-JITNKKHL.js";
6
+ } from "./chunk-JPFEQTV6.js";
7
+ import "./chunk-DW6XZF4X.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -239,7 +239,7 @@ type ClockState = {
239
239
  now: number;
240
240
  /** True while time does not advance on its own. */
241
241
  frozen: boolean;
242
- /** Milliseconds this clock adds to its underlying source. */
242
+ /** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
243
243
  offsetMs: number;
244
244
  };
245
245
  type Clock = {
@@ -275,7 +275,10 @@ type Rng = {
275
275
  state(): number;
276
276
  /** Restore a state previously returned by {@link state}. */
277
277
  setState(state: number): void;
278
- seed: number;
278
+ /** Restart the stream from a new seed. `reset` then returns to this seed. */
279
+ reseed(seed: number | string): void;
280
+ /** The seed the stream currently starts from. */
281
+ readonly seed: number;
279
282
  };
280
283
 
281
284
  /**
@@ -284,44 +287,83 @@ type Rng = {
284
287
  * This is how a suite reaches the vendor's failure modes without the vendor: the
285
288
  * quota error that only appears when a shared sandbox is full, the 429 that only
286
289
  * appears under load, the 5xx that proves a retry path works.
290
+ *
291
+ * A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
292
+ * it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
293
+ * and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
287
294
  */
288
295
  type FaultRule = {
289
- /** Stable id, so a suite can retire exactly the rule it added. */
296
+ /** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
290
297
  id: string;
291
298
  /** Fault only this operation. Omit to match every operation. */
292
299
  operationId?: string;
293
300
  /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
294
301
  method?: string;
302
+ /** Fault only this exact path. */
303
+ path?: string;
295
304
  /** Fault only paths starting with this prefix. Omit to match every path. */
296
305
  pathPrefix?: string;
306
+ /** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
307
+ pathPattern?: string;
308
+ /** Fault only requests carrying these headers. `"*"` matches any value. */
309
+ requestHeaders?: Record<string, string>;
310
+ /** Fault only requests carrying these query parameters. `"*"` matches any value. */
311
+ query?: Record<string, string>;
297
312
  /**
298
313
  * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
299
314
  * an in-process caller usually wants, and what a parallel worker usually does not:
300
315
  * rules added through `POST /__admin/faults` default to the calling namespace.
301
316
  */
302
317
  namespace?: string;
318
+ /** Let this many matching requests through first. */
319
+ after?: number;
320
+ /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
321
+ every?: number;
322
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
323
+ count?: number;
324
+ /** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
325
+ rate?: number;
326
+ /**
327
+ * Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
328
+ * clock when the rule was added. Listed as epoch ms.
329
+ */
330
+ from?: Instant | Duration;
331
+ /** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
332
+ until?: Instant | Duration;
303
333
  /**
304
- * Status of the injected response. Omit for a rule that only delays (`delayMs` /
305
- * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
306
- * the request then still reaches the service.
334
+ * Status of the injected response. Omit for a rule that only delays, times out, drops,
335
+ * truncates, or switches on an `effect`: the request then still reaches the service.
307
336
  */
308
337
  status?: number;
309
338
  /** Response body, serialized as JSON. A string is sent as-is. */
310
339
  body?: unknown;
340
+ /** Response headers. */
311
341
  headers?: Record<string, string>;
312
- /** Retire the rule after this many faults. Omit to keep it until removed. */
313
- count?: number;
314
- /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
315
- rate?: number;
316
- /** Hold the response back this long, to exercise timeouts. */
342
+ /** Hold the response back this long. Listed as `delayMs`. */
343
+ delay?: Duration;
344
+ /** `delay`, in milliseconds. */
317
345
  delayMs?: number;
318
346
  /** Alias of `delayMs`. */
319
347
  latencyMs?: number;
348
+ /** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
349
+ jitter?: Duration;
350
+ jitterMs?: number;
351
+ /**
352
+ * Never answer: hold the request this long, then drop the connection. Listed as
353
+ * `timeoutMs`. With virtual time the wait is spent on the mock clock.
354
+ */
355
+ timeout?: Duration;
356
+ timeoutMs?: number;
320
357
  /**
321
358
  * Drop the connection instead of answering: an in-process `fetch` rejects with a
322
359
  * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
323
360
  */
324
361
  drop?: boolean;
362
+ /**
363
+ * Cut the response body off after this many bytes: the status and headers arrive, then
364
+ * the connection dies mid-body.
365
+ */
366
+ truncate?: number;
325
367
  /**
326
368
  * A named service behaviour to switch on for the matching request instead of (or
327
369
  * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
@@ -330,8 +372,8 @@ type FaultRule = {
330
372
  effect?: string;
331
373
  /** Parameters for `effect`. */
332
374
  params?: Record<string, unknown>;
333
- /** From the preset this rule was expanded from, if any. */
334
- preset?: string;
375
+ /** The preset this rule was expanded from, if any. */
376
+ fromPreset?: string;
335
377
  };
336
378
  /** A fault that fired for one request. */
337
379
  type FaultHit = {
@@ -339,6 +381,10 @@ type FaultHit = {
339
381
  /** The injected response; absent when the rule only delays, drops, or sets an effect. */
340
382
  response?: Response;
341
383
  drop?: boolean;
384
+ /** Set with `drop` when the rule held the request for its `timeout` first. */
385
+ timeout?: boolean;
386
+ /** Bytes of response body to let through before the connection dies. */
387
+ truncate?: number;
342
388
  effect?: {
343
389
  name: string;
344
390
  params: Record<string, unknown>;
@@ -363,38 +409,202 @@ type FaultCandidate = {
363
409
  method: string;
364
410
  path: string;
365
411
  namespace: string;
412
+ /** Request headers and query, for rules that match on them. */
413
+ headers?: Headers;
414
+ query?: URLSearchParams;
415
+ /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
416
+ now?: number;
417
+ /** How to spend a delay for this request. Default: the registry's own sleep. */
418
+ wait?: (ms: number) => Promise<void>;
419
+ };
420
+ /** A stored rule and how often it was consulted. */
421
+ type FaultListing = FaultRule & {
422
+ /** Faults left before the rule retires. `null` when it has no `count`. */
423
+ remaining: number | null;
424
+ /** Times the rule faulted a request. */
425
+ hits: number;
426
+ /** Requests that matched the rule, faulted or not. */
427
+ seen: number;
428
+ };
429
+ /** A namespace's own rules, with their counters, in the order they are tried. */
430
+ type FaultSnapshot = {
431
+ /**
432
+ * `position` is how many `"*"` rules are tried before the rule, which is what its place
433
+ * in the order means to a request and holds in any process.
434
+ */
435
+ rules: (FaultListing & {
436
+ position?: number;
437
+ })[];
438
+ /** How many `fault_<n>` ids the namespace has handed out. */
439
+ nextId?: number;
366
440
  };
367
441
  type FaultRegistry = {
368
- isolateNamespaces(): void;
369
- snapshot(namespace: string): {
370
- rules: (FaultRule & {
371
- remaining: number | null;
372
- hits: number;
373
- position: number;
374
- })[];
375
- rngState: number;
376
- };
442
+ snapshot(namespace: string): FaultSnapshot;
443
+ /** Add a rule, or replace the rule with the same id in the same namespace. */
377
444
  add(rule: FaultRule): FaultRule;
378
- list(): (FaultRule & {
379
- remaining: number | null;
380
- hits: number;
381
- })[];
382
- remove(id: string): boolean;
383
- clear(): void;
384
- restore(namespace: string, state: {
385
- rules: (FaultRule & {
386
- remaining: number | null;
387
- hits: number;
388
- position: number;
389
- })[];
390
- rngState: number;
391
- }): void;
445
+ /** The next unused `fault_<n>` id in `namespace`. */
446
+ nextId(namespace: string): string;
447
+ /** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
448
+ list(namespace?: string): FaultListing[];
449
+ get(id: string, namespace?: string): FaultListing | undefined;
450
+ /** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
451
+ remove(id: string, namespace?: string): boolean;
452
+ /** Remove every rule, or one namespace's own rules. */
453
+ clear(namespace?: string): void;
454
+ /** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
455
+ restore(namespace: string, state: FaultSnapshot): void;
392
456
  /**
393
457
  * Every fault this request should get, in rule order, stopping at the first that answers
394
458
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
395
459
  * each matching rule's remaining uses.
396
460
  */
397
461
  take(candidate: FaultCandidate): Promise<FaultHit[]>;
462
+ /**
463
+ * Fire these rules at one request without storing them: no matching, no schedule, in order,
464
+ * stopping at the first that answers or drops. Jitter draws from the namespace's stream.
465
+ */
466
+ fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
467
+ };
468
+
469
+ /**
470
+ * The admin controls every mock shares, as one document.
471
+ *
472
+ * The same shape is accepted in three places, and means the same thing in each:
473
+ *
474
+ * - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
475
+ * `MOCKINGBIRD_ADMIN_CONTROLS`
476
+ * - over HTTP: `PUT /__admin/controls`
477
+ * - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
478
+ *
479
+ * Every control is deterministic: given the same seed, clock and requests, a mock answers
480
+ * the same bytes. Nothing here reads the wall clock or `Math.random`.
481
+ */
482
+ /** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
483
+ type Duration = number | string;
484
+ /** Epoch milliseconds, or an ISO-8601 string. */
485
+ type Instant = number | string;
486
+ type ClockControls = {
487
+ /** Move the clock to this instant. */
488
+ now?: Instant;
489
+ /** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
490
+ frozen?: boolean;
491
+ /**
492
+ * Step the clock forward by this much before every vendor request. With a frozen clock
493
+ * each request still gets its own, reproducible timestamp.
494
+ */
495
+ autoAdvance?: Duration;
496
+ };
497
+ /** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
498
+ type LatencyRuleInput = {
499
+ delay?: Duration;
500
+ jitter?: Duration;
501
+ };
502
+ type LatencyControls = LatencyRuleInput & {
503
+ /** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
504
+ operations?: Record<string, Duration | LatencyRuleInput>;
505
+ };
506
+ /** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
507
+ type FaultInput = (Omit<FaultRule, "id"> & {
508
+ id?: string;
509
+ }) | ({
510
+ preset: string;
511
+ } & Partial<FaultRule>);
512
+ /** Identifies a {@link SnapshotDocument}. */
513
+ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
514
+ /**
515
+ * A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
516
+ * `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
517
+ * `records` are required, so a hand-written seed file is a valid snapshot.
518
+ */
519
+ type SnapshotDocument = {
520
+ format: typeof SNAPSHOT_FORMAT;
521
+ /** The service that wrote it. A snapshot is rejected by any other service. */
522
+ service?: string;
523
+ /**
524
+ * Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
525
+ * the stored text of a row that is not a plain record, and replaces `value` when present.
526
+ */
527
+ records: {
528
+ collection: string;
529
+ id: string;
530
+ seq?: number;
531
+ value?: unknown;
532
+ raw?: string;
533
+ }[];
534
+ /** Id counters, so the next generated id continues where the snapshot left off. */
535
+ sequences?: {
536
+ name: string;
537
+ kind: string;
538
+ value: number;
539
+ }[];
540
+ clock?: {
541
+ now: number;
542
+ frozen: boolean;
543
+ autoAdvanceMs?: number;
544
+ };
545
+ seed?: number | string;
546
+ /** Positions of the seeded random streams. */
547
+ rng?: {
548
+ state: number;
549
+ faults?: number;
550
+ latency?: number;
551
+ };
552
+ faults?: unknown;
553
+ latency?: unknown;
554
+ virtualTime?: boolean;
555
+ /** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
556
+ webhooks?: unknown;
557
+ };
558
+ /** Controls for one namespace. */
559
+ type NamespaceControls = {
560
+ /** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
561
+ seed?: number | string;
562
+ clock?: ClockControls;
563
+ /**
564
+ * Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
565
+ * wall clock: the request returns at once, the clock has moved, and the journal records
566
+ * the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
567
+ */
568
+ virtualTime?: boolean;
569
+ /** Baseline response time for every vendor request. A bare duration is its `delay`. */
570
+ latency?: Duration | LatencyControls;
571
+ faults?: readonly FaultInput[];
572
+ /** Start from this state instead of the service's own seed data. */
573
+ snapshot?: SnapshotDocument;
574
+ };
575
+ /** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
576
+ type MockControls = NamespaceControls & {
577
+ /** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
578
+ credentials?: Record<string, string>;
579
+ /** Overrides for named namespaces. A key given here replaces the shared value. */
580
+ namespaces?: Record<string, NamespaceControls>;
581
+ };
582
+ /** A latency rule in milliseconds. */
583
+ type LatencyRule = {
584
+ delayMs: number;
585
+ jitterMs: number;
586
+ };
587
+ /** Baseline latency for a namespace, normalized. */
588
+ type LatencyState = LatencyRule & {
589
+ operations: Record<string, LatencyRule>;
590
+ };
591
+ /** What {@link controlHeaders} turns into request headers. */
592
+ type ControlHeaderInput = {
593
+ namespace?: string;
594
+ adminKey?: string;
595
+ branch?: string;
596
+ at?: string;
597
+ reset?: boolean;
598
+ restore?: string;
599
+ seed?: number | string;
600
+ time?: Instant | Date;
601
+ advance?: Duration;
602
+ virtualTime?: boolean;
603
+ delay?: Duration;
604
+ timeout?: Duration;
605
+ /** A status, `"drop"`, a preset name, or a fault rule. */
606
+ fault?: number | string | Record<string, unknown>;
607
+ snapshot?: string;
398
608
  };
399
609
 
400
610
  /**
@@ -434,6 +644,8 @@ type RequestLog = {
434
644
  unmatched: boolean;
435
645
  /** Set when a fault rule produced the response. */
436
646
  faultId?: string;
647
+ /** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
648
+ delayMs?: number;
437
649
  /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
438
650
  ids?: Record<string, string>;
439
651
  /** Set when the service created a resource the request referred to but that did not exist. */
@@ -479,6 +691,12 @@ type JournalQuery = {
479
691
  /** Only this namespace. Omit for every namespace, oldest first across all of them. */
480
692
  namespace?: string;
481
693
  operationId?: string;
694
+ /** Only this HTTP method, case-insensitive. */
695
+ method?: string;
696
+ /** Only this exact path. */
697
+ path?: string;
698
+ /** Only requests this fault rule answered or shaped. */
699
+ faultId?: string;
482
700
  status?: number;
483
701
  /** Only entries at or after this instant (epoch ms). */
484
702
  since?: number;
@@ -493,6 +711,50 @@ type Journal = {
493
711
  clear(namespace?: string): void;
494
712
  };
495
713
 
714
+ /**
715
+ * Baseline response time, per namespace: how long every vendor request takes before any
716
+ * fault is considered. Jitter draws from a stream the caller owns, one per namespace and
717
+ * separate from the fault stream, so adding latency never shifts which requests a `rate`
718
+ * fault hits.
719
+ */
720
+ type LatencyRegistry = {
721
+ get(namespace: string): LatencyState;
722
+ set(namespace: string, state: LatencyState): LatencyState;
723
+ /** Remove one namespace's latency, or every namespace's. */
724
+ clear(namespace?: string): void;
725
+ /** Milliseconds this request waits. Draws jitter, so call it once per request. */
726
+ take(namespace: string, operationId: string | undefined): number;
727
+ };
728
+
729
+ /** Clock state as the admin API reports it. */
730
+ type ControlClock = ClockState & {
731
+ /** `now`, as ISO-8601. */
732
+ iso: string;
733
+ /** Milliseconds the clock steps before every vendor request. */
734
+ autoAdvanceMs: number;
735
+ };
736
+ /** One namespace's controls: the body of `GET /__admin/controls`. */
737
+ type ControlState = {
738
+ namespace: string;
739
+ seed: number | string;
740
+ clock: ControlClock;
741
+ virtualTime: boolean;
742
+ latency: LatencyState;
743
+ faults: FaultListing[];
744
+ };
745
+
746
+ /** What `GET /__admin/snapshots` lists for each snapshot. */
747
+ type SnapshotInfo = {
748
+ id: string;
749
+ namespace: string;
750
+ /** Stored rows in the snapshot. */
751
+ records: number;
752
+ /** The namespace clock when it was taken, epoch ms. */
753
+ at: number;
754
+ /** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
755
+ portable: boolean;
756
+ };
757
+
496
758
  /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
497
759
  type CredentialRegistry = {
498
760
  set(credential: string, namespace: string): void;
@@ -505,6 +767,8 @@ type CredentialRegistry = {
505
767
  }[];
506
768
  };
507
769
 
770
+ type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
771
+
508
772
  /**
509
773
  * A point-in-time copy of everything a service namespace holds.
510
774
  *
@@ -622,8 +886,16 @@ type PublishInput = {
622
886
  id?: string;
623
887
  };
624
888
  type WebhookHub = {
889
+ observeDeliveries(listener: (event: {
890
+ namespace: string;
891
+ state: string;
892
+ deliveryId: string;
893
+ }) => void): () => void;
894
+ setTransportPolicy(policy: OwnedTransport): void;
625
895
  pending(namespace: string): number;
626
896
  snapshot(namespace: string): unknown;
897
+ exportSnapshot(handle: unknown): unknown;
898
+ importSnapshot(namespace: string, document: unknown): unknown;
627
899
  restore(namespace: string, snapshot: unknown): void;
628
900
  publish(input: PublishInput): WebhookMessage;
629
901
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
@@ -636,7 +908,7 @@ type WebhookHub = {
636
908
  /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
637
909
  flush(): Promise<void>;
638
910
  /** Resolve once nothing is in flight. */
639
- idle(): Promise<void>;
911
+ idle(namespace?: string): Promise<void>;
640
912
  fault(namespace: string, fault: WebhookFault): void;
641
913
  clear(namespace?: string): void;
642
914
  };
@@ -647,7 +919,10 @@ type ServiceInstance = FetchAPI & {
647
919
  };
648
920
  type ServiceTimelineState = Readonly<{
649
921
  snapshot: NamespaceSnapshot;
650
- clock: Readonly<ReturnType<Clock["state"]>>;
922
+ /** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
923
+ clock: Readonly<ClockState & {
924
+ pinned?: boolean;
925
+ }>;
651
926
  rngState: number;
652
927
  }>;
653
928
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
@@ -660,27 +935,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
660
935
  readonly sqlite: SqliteClient;
661
936
  readonly clock: Clock;
662
937
  readonly faults: FaultRegistry;
938
+ /** Baseline response time per namespace. */
939
+ readonly latency: LatencyRegistry;
663
940
  readonly metrics: Metrics;
664
941
  readonly journal: Journal;
665
942
  readonly rng: Rng;
666
943
  readonly credentials: CredentialRegistry;
667
944
  /** The webhook hub, when the service has outbound webhooks. */
668
945
  readonly webhooks: WebhookHub | undefined;
669
- /** Enable independent namespace clocks and PRNGs before serving a fleet. */
670
- isolateNamespaces(): void;
946
+ /**
947
+ * A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
948
+ * offset and a freeze of its own, so moving one never moves another.
949
+ */
671
950
  namespaceClock(namespace?: string): Clock;
672
951
  namespaceOf(request: Request): string;
673
952
  /** Opaque in-process checkpoint including records, controls and webhook history. */
674
953
  fleetSnapshot(namespace: string): object;
675
954
  fleetRestore(snapshot: unknown, namespace: string): void;
955
+ fleetExport(snapshot: unknown): SnapshotDocument;
956
+ fleetImport(namespace: string, document: unknown): object;
676
957
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
677
958
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
678
959
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
679
960
  instance(namespace?: string): T;
680
961
  /** Public names of every namespace created so far. */
681
962
  namespaces(): string[];
682
- /** Reset one namespace, or every namespace with `"*"`. */
963
+ /** Return one namespace to its boot state, or every namespace with `"*"`. */
683
964
  reset(namespace?: string): Promise<void>;
965
+ /** Reset a namespace and forget it, releasing everything it held. */
966
+ dropNamespace(namespace: string): Promise<void>;
967
+ /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
968
+ controls(namespace?: string): ControlState & {
969
+ snapshots: SnapshotInfo[];
970
+ };
971
+ /** Apply a control document to a namespace. A given key replaces that control. */
972
+ configure(controls: NamespaceControls, namespace?: string): ControlState & {
973
+ snapshots: SnapshotInfo[];
974
+ };
975
+ /** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
976
+ readonly snapshots: {
977
+ /** Capture the namespace now. Reusing a name replaces that snapshot. */
978
+ create(options?: {
979
+ name?: string;
980
+ namespace?: string;
981
+ }): SnapshotInfo;
982
+ list(namespace?: string): SnapshotInfo[];
983
+ /** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
984
+ export(id: string, namespace?: string): SnapshotDocument;
985
+ /** Store a document as a snapshot without restoring it. */
986
+ import(document: SnapshotDocument, options?: {
987
+ name?: string;
988
+ namespace?: string;
989
+ }): SnapshotInfo;
990
+ restore(id: string, namespace?: string): void;
991
+ delete(id: string, namespace?: string): boolean;
992
+ };
993
+ /** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
994
+ headers(input: ControlHeaderInput): Record<string, string>;
684
995
  snapshot(namespace?: string): NamespaceSnapshot;
685
996
  restore(snapshot: NamespaceSnapshot, namespace?: string): void;
686
997
  /** Capture the current branch. Mutating HTTP calls do this automatically. */
@@ -878,6 +1189,8 @@ type WorkOSRuntimeOptions = Omit<WorkOSAPIOptions, "namespace" | "now"> & {
878
1189
  seed?: string | number;
879
1190
  adminPrefix?: string;
880
1191
  adminKey?: string;
1192
+ /** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
1193
+ adminControls?: MockControls;
881
1194
  onLog?: (entry: RequestLog) => void;
882
1195
  };
883
1196
  type WorkOSRuntime = ServiceRuntime<WorkOSAPI>;
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  document,
9
9
  operationIds,
10
10
  supportedOperationIds
11
- } from "./chunk-JITNKKHL.js";
11
+ } from "./chunk-DW6XZF4X.js";
12
12
  export {
13
13
  DEFAULT_CLIENTS,
14
14
  DEFAULT_USERS,