@crvouga/mockingbird-service-posthog 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/dist/cli.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  runCli,
4
4
  serveCommand,
5
5
  serveTarget
6
- } from "./chunk-I3QG7TBO.js";
7
- import "./chunk-3R4Y742O.js";
6
+ } from "./chunk-IODRZUXV.js";
7
+ import "./chunk-YTVQ24KD.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -285,7 +285,7 @@ type ClockState = {
285
285
  now: number;
286
286
  /** True while time does not advance on its own. */
287
287
  frozen: boolean;
288
- /** Milliseconds this clock adds to its underlying source. */
288
+ /** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
289
289
  offsetMs: number;
290
290
  };
291
291
  type Clock = {
@@ -321,7 +321,10 @@ type Rng = {
321
321
  state(): number;
322
322
  /** Restore a state previously returned by {@link state}. */
323
323
  setState(state: number): void;
324
- seed: number;
324
+ /** Restart the stream from a new seed. `reset` then returns to this seed. */
325
+ reseed(seed: number | string): void;
326
+ /** The seed the stream currently starts from. */
327
+ readonly seed: number;
325
328
  };
326
329
 
327
330
  /**
@@ -330,44 +333,83 @@ type Rng = {
330
333
  * This is how a suite reaches the vendor's failure modes without the vendor: the
331
334
  * quota error that only appears when a shared sandbox is full, the 429 that only
332
335
  * appears under load, the 5xx that proves a retry path works.
336
+ *
337
+ * A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
338
+ * it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
339
+ * and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
333
340
  */
334
341
  type FaultRule = {
335
- /** Stable id, so a suite can retire exactly the rule it added. */
342
+ /** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
336
343
  id: string;
337
344
  /** Fault only this operation. Omit to match every operation. */
338
345
  operationId?: string;
339
346
  /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
340
347
  method?: string;
348
+ /** Fault only this exact path. */
349
+ path?: string;
341
350
  /** Fault only paths starting with this prefix. Omit to match every path. */
342
351
  pathPrefix?: string;
352
+ /** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
353
+ pathPattern?: string;
354
+ /** Fault only requests carrying these headers. `"*"` matches any value. */
355
+ requestHeaders?: Record<string, string>;
356
+ /** Fault only requests carrying these query parameters. `"*"` matches any value. */
357
+ query?: Record<string, string>;
343
358
  /**
344
359
  * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
345
360
  * an in-process caller usually wants, and what a parallel worker usually does not:
346
361
  * rules added through `POST /__admin/faults` default to the calling namespace.
347
362
  */
348
363
  namespace?: string;
364
+ /** Let this many matching requests through first. */
365
+ after?: number;
366
+ /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
367
+ every?: number;
368
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
369
+ count?: number;
370
+ /** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
371
+ rate?: number;
372
+ /**
373
+ * Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
374
+ * clock when the rule was added. Listed as epoch ms.
375
+ */
376
+ from?: Instant | Duration;
377
+ /** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
378
+ until?: Instant | Duration;
349
379
  /**
350
- * Status of the injected response. Omit for a rule that only delays (`delayMs` /
351
- * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
352
- * the request then still reaches the service.
380
+ * Status of the injected response. Omit for a rule that only delays, times out, drops,
381
+ * truncates, or switches on an `effect`: the request then still reaches the service.
353
382
  */
354
383
  status?: number;
355
384
  /** Response body, serialized as JSON. A string is sent as-is. */
356
385
  body?: unknown;
386
+ /** Response headers. */
357
387
  headers?: Record<string, string>;
358
- /** Retire the rule after this many faults. Omit to keep it until removed. */
359
- count?: number;
360
- /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
361
- rate?: number;
362
- /** Hold the response back this long, to exercise timeouts. */
388
+ /** Hold the response back this long. Listed as `delayMs`. */
389
+ delay?: Duration;
390
+ /** `delay`, in milliseconds. */
363
391
  delayMs?: number;
364
392
  /** Alias of `delayMs`. */
365
393
  latencyMs?: number;
394
+ /** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
395
+ jitter?: Duration;
396
+ jitterMs?: number;
397
+ /**
398
+ * Never answer: hold the request this long, then drop the connection. Listed as
399
+ * `timeoutMs`. With virtual time the wait is spent on the mock clock.
400
+ */
401
+ timeout?: Duration;
402
+ timeoutMs?: number;
366
403
  /**
367
404
  * Drop the connection instead of answering: an in-process `fetch` rejects with a
368
405
  * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
369
406
  */
370
407
  drop?: boolean;
408
+ /**
409
+ * Cut the response body off after this many bytes: the status and headers arrive, then
410
+ * the connection dies mid-body.
411
+ */
412
+ truncate?: number;
371
413
  /**
372
414
  * A named service behaviour to switch on for the matching request instead of (or
373
415
  * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
@@ -376,8 +418,8 @@ type FaultRule = {
376
418
  effect?: string;
377
419
  /** Parameters for `effect`. */
378
420
  params?: Record<string, unknown>;
379
- /** From the preset this rule was expanded from, if any. */
380
- preset?: string;
421
+ /** The preset this rule was expanded from, if any. */
422
+ fromPreset?: string;
381
423
  };
382
424
  /** A fault that fired for one request. */
383
425
  type FaultHit = {
@@ -385,6 +427,10 @@ type FaultHit = {
385
427
  /** The injected response; absent when the rule only delays, drops, or sets an effect. */
386
428
  response?: Response;
387
429
  drop?: boolean;
430
+ /** Set with `drop` when the rule held the request for its `timeout` first. */
431
+ timeout?: boolean;
432
+ /** Bytes of response body to let through before the connection dies. */
433
+ truncate?: number;
388
434
  effect?: {
389
435
  name: string;
390
436
  params: Record<string, unknown>;
@@ -409,38 +455,202 @@ type FaultCandidate = {
409
455
  method: string;
410
456
  path: string;
411
457
  namespace: string;
458
+ /** Request headers and query, for rules that match on them. */
459
+ headers?: Headers;
460
+ query?: URLSearchParams;
461
+ /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
462
+ now?: number;
463
+ /** How to spend a delay for this request. Default: the registry's own sleep. */
464
+ wait?: (ms: number) => Promise<void>;
465
+ };
466
+ /** A stored rule and how often it was consulted. */
467
+ type FaultListing = FaultRule & {
468
+ /** Faults left before the rule retires. `null` when it has no `count`. */
469
+ remaining: number | null;
470
+ /** Times the rule faulted a request. */
471
+ hits: number;
472
+ /** Requests that matched the rule, faulted or not. */
473
+ seen: number;
474
+ };
475
+ /** A namespace's own rules, with their counters, in the order they are tried. */
476
+ type FaultSnapshot = {
477
+ /**
478
+ * `position` is how many `"*"` rules are tried before the rule, which is what its place
479
+ * in the order means to a request and holds in any process.
480
+ */
481
+ rules: (FaultListing & {
482
+ position?: number;
483
+ })[];
484
+ /** How many `fault_<n>` ids the namespace has handed out. */
485
+ nextId?: number;
412
486
  };
413
487
  type FaultRegistry = {
414
- isolateNamespaces(): void;
415
- snapshot(namespace: string): {
416
- rules: (FaultRule & {
417
- remaining: number | null;
418
- hits: number;
419
- position: number;
420
- })[];
421
- rngState: number;
422
- };
488
+ snapshot(namespace: string): FaultSnapshot;
489
+ /** Add a rule, or replace the rule with the same id in the same namespace. */
423
490
  add(rule: FaultRule): FaultRule;
424
- list(): (FaultRule & {
425
- remaining: number | null;
426
- hits: number;
427
- })[];
428
- remove(id: string): boolean;
429
- clear(): void;
430
- restore(namespace: string, state: {
431
- rules: (FaultRule & {
432
- remaining: number | null;
433
- hits: number;
434
- position: number;
435
- })[];
436
- rngState: number;
437
- }): void;
491
+ /** The next unused `fault_<n>` id in `namespace`. */
492
+ nextId(namespace: string): string;
493
+ /** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
494
+ list(namespace?: string): FaultListing[];
495
+ get(id: string, namespace?: string): FaultListing | undefined;
496
+ /** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
497
+ remove(id: string, namespace?: string): boolean;
498
+ /** Remove every rule, or one namespace's own rules. */
499
+ clear(namespace?: string): void;
500
+ /** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
501
+ restore(namespace: string, state: FaultSnapshot): void;
438
502
  /**
439
503
  * Every fault this request should get, in rule order, stopping at the first that answers
440
504
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
441
505
  * each matching rule's remaining uses.
442
506
  */
443
507
  take(candidate: FaultCandidate): Promise<FaultHit[]>;
508
+ /**
509
+ * Fire these rules at one request without storing them: no matching, no schedule, in order,
510
+ * stopping at the first that answers or drops. Jitter draws from the namespace's stream.
511
+ */
512
+ fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
513
+ };
514
+
515
+ /**
516
+ * The admin controls every mock shares, as one document.
517
+ *
518
+ * The same shape is accepted in three places, and means the same thing in each:
519
+ *
520
+ * - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
521
+ * `MOCKINGBIRD_ADMIN_CONTROLS`
522
+ * - over HTTP: `PUT /__admin/controls`
523
+ * - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
524
+ *
525
+ * Every control is deterministic: given the same seed, clock and requests, a mock answers
526
+ * the same bytes. Nothing here reads the wall clock or `Math.random`.
527
+ */
528
+ /** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
529
+ type Duration = number | string;
530
+ /** Epoch milliseconds, or an ISO-8601 string. */
531
+ type Instant = number | string;
532
+ type ClockControls = {
533
+ /** Move the clock to this instant. */
534
+ now?: Instant;
535
+ /** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
536
+ frozen?: boolean;
537
+ /**
538
+ * Step the clock forward by this much before every vendor request. With a frozen clock
539
+ * each request still gets its own, reproducible timestamp.
540
+ */
541
+ autoAdvance?: Duration;
542
+ };
543
+ /** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
544
+ type LatencyRuleInput = {
545
+ delay?: Duration;
546
+ jitter?: Duration;
547
+ };
548
+ type LatencyControls = LatencyRuleInput & {
549
+ /** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
550
+ operations?: Record<string, Duration | LatencyRuleInput>;
551
+ };
552
+ /** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
553
+ type FaultInput = (Omit<FaultRule, "id"> & {
554
+ id?: string;
555
+ }) | ({
556
+ preset: string;
557
+ } & Partial<FaultRule>);
558
+ /** Identifies a {@link SnapshotDocument}. */
559
+ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
560
+ /**
561
+ * A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
562
+ * `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
563
+ * `records` are required, so a hand-written seed file is a valid snapshot.
564
+ */
565
+ type SnapshotDocument = {
566
+ format: typeof SNAPSHOT_FORMAT;
567
+ /** The service that wrote it. A snapshot is rejected by any other service. */
568
+ service?: string;
569
+ /**
570
+ * Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
571
+ * the stored text of a row that is not a plain record, and replaces `value` when present.
572
+ */
573
+ records: {
574
+ collection: string;
575
+ id: string;
576
+ seq?: number;
577
+ value?: unknown;
578
+ raw?: string;
579
+ }[];
580
+ /** Id counters, so the next generated id continues where the snapshot left off. */
581
+ sequences?: {
582
+ name: string;
583
+ kind: string;
584
+ value: number;
585
+ }[];
586
+ clock?: {
587
+ now: number;
588
+ frozen: boolean;
589
+ autoAdvanceMs?: number;
590
+ };
591
+ seed?: number | string;
592
+ /** Positions of the seeded random streams. */
593
+ rng?: {
594
+ state: number;
595
+ faults?: number;
596
+ latency?: number;
597
+ };
598
+ faults?: unknown;
599
+ latency?: unknown;
600
+ virtualTime?: boolean;
601
+ /** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
602
+ webhooks?: unknown;
603
+ };
604
+ /** Controls for one namespace. */
605
+ type NamespaceControls = {
606
+ /** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
607
+ seed?: number | string;
608
+ clock?: ClockControls;
609
+ /**
610
+ * Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
611
+ * wall clock: the request returns at once, the clock has moved, and the journal records
612
+ * the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
613
+ */
614
+ virtualTime?: boolean;
615
+ /** Baseline response time for every vendor request. A bare duration is its `delay`. */
616
+ latency?: Duration | LatencyControls;
617
+ faults?: readonly FaultInput[];
618
+ /** Start from this state instead of the service's own seed data. */
619
+ snapshot?: SnapshotDocument;
620
+ };
621
+ /** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
622
+ type MockControls = NamespaceControls & {
623
+ /** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
624
+ credentials?: Record<string, string>;
625
+ /** Overrides for named namespaces. A key given here replaces the shared value. */
626
+ namespaces?: Record<string, NamespaceControls>;
627
+ };
628
+ /** A latency rule in milliseconds. */
629
+ type LatencyRule = {
630
+ delayMs: number;
631
+ jitterMs: number;
632
+ };
633
+ /** Baseline latency for a namespace, normalized. */
634
+ type LatencyState = LatencyRule & {
635
+ operations: Record<string, LatencyRule>;
636
+ };
637
+ /** What {@link controlHeaders} turns into request headers. */
638
+ type ControlHeaderInput = {
639
+ namespace?: string;
640
+ adminKey?: string;
641
+ branch?: string;
642
+ at?: string;
643
+ reset?: boolean;
644
+ restore?: string;
645
+ seed?: number | string;
646
+ time?: Instant | Date;
647
+ advance?: Duration;
648
+ virtualTime?: boolean;
649
+ delay?: Duration;
650
+ timeout?: Duration;
651
+ /** A status, `"drop"`, a preset name, or a fault rule. */
652
+ fault?: number | string | Record<string, unknown>;
653
+ snapshot?: string;
444
654
  };
445
655
 
446
656
  /**
@@ -480,6 +690,8 @@ type RequestLog = {
480
690
  unmatched: boolean;
481
691
  /** Set when a fault rule produced the response. */
482
692
  faultId?: string;
693
+ /** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
694
+ delayMs?: number;
483
695
  /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
484
696
  ids?: Record<string, string>;
485
697
  /** Set when the service created a resource the request referred to but that did not exist. */
@@ -525,6 +737,12 @@ type JournalQuery = {
525
737
  /** Only this namespace. Omit for every namespace, oldest first across all of them. */
526
738
  namespace?: string;
527
739
  operationId?: string;
740
+ /** Only this HTTP method, case-insensitive. */
741
+ method?: string;
742
+ /** Only this exact path. */
743
+ path?: string;
744
+ /** Only requests this fault rule answered or shaped. */
745
+ faultId?: string;
528
746
  status?: number;
529
747
  /** Only entries at or after this instant (epoch ms). */
530
748
  since?: number;
@@ -539,6 +757,50 @@ type Journal = {
539
757
  clear(namespace?: string): void;
540
758
  };
541
759
 
760
+ /**
761
+ * Baseline response time, per namespace: how long every vendor request takes before any
762
+ * fault is considered. Jitter draws from a stream the caller owns, one per namespace and
763
+ * separate from the fault stream, so adding latency never shifts which requests a `rate`
764
+ * fault hits.
765
+ */
766
+ type LatencyRegistry = {
767
+ get(namespace: string): LatencyState;
768
+ set(namespace: string, state: LatencyState): LatencyState;
769
+ /** Remove one namespace's latency, or every namespace's. */
770
+ clear(namespace?: string): void;
771
+ /** Milliseconds this request waits. Draws jitter, so call it once per request. */
772
+ take(namespace: string, operationId: string | undefined): number;
773
+ };
774
+
775
+ /** Clock state as the admin API reports it. */
776
+ type ControlClock = ClockState & {
777
+ /** `now`, as ISO-8601. */
778
+ iso: string;
779
+ /** Milliseconds the clock steps before every vendor request. */
780
+ autoAdvanceMs: number;
781
+ };
782
+ /** One namespace's controls: the body of `GET /__admin/controls`. */
783
+ type ControlState = {
784
+ namespace: string;
785
+ seed: number | string;
786
+ clock: ControlClock;
787
+ virtualTime: boolean;
788
+ latency: LatencyState;
789
+ faults: FaultListing[];
790
+ };
791
+
792
+ /** What `GET /__admin/snapshots` lists for each snapshot. */
793
+ type SnapshotInfo = {
794
+ id: string;
795
+ namespace: string;
796
+ /** Stored rows in the snapshot. */
797
+ records: number;
798
+ /** The namespace clock when it was taken, epoch ms. */
799
+ at: number;
800
+ /** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
801
+ portable: boolean;
802
+ };
803
+
542
804
  /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
543
805
  type CredentialRegistry = {
544
806
  set(credential: string, namespace: string): void;
@@ -551,6 +813,8 @@ type CredentialRegistry = {
551
813
  }[];
552
814
  };
553
815
 
816
+ type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
817
+
554
818
  /**
555
819
  * A point-in-time copy of everything a service namespace holds.
556
820
  *
@@ -668,8 +932,16 @@ type PublishInput = {
668
932
  id?: string;
669
933
  };
670
934
  type WebhookHub = {
935
+ observeDeliveries(listener: (event: {
936
+ namespace: string;
937
+ state: string;
938
+ deliveryId: string;
939
+ }) => void): () => void;
940
+ setTransportPolicy(policy: OwnedTransport): void;
671
941
  pending(namespace: string): number;
672
942
  snapshot(namespace: string): unknown;
943
+ exportSnapshot(handle: unknown): unknown;
944
+ importSnapshot(namespace: string, document: unknown): unknown;
673
945
  restore(namespace: string, snapshot: unknown): void;
674
946
  publish(input: PublishInput): WebhookMessage;
675
947
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
@@ -682,7 +954,7 @@ type WebhookHub = {
682
954
  /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
683
955
  flush(): Promise<void>;
684
956
  /** Resolve once nothing is in flight. */
685
- idle(): Promise<void>;
957
+ idle(namespace?: string): Promise<void>;
686
958
  fault(namespace: string, fault: WebhookFault): void;
687
959
  clear(namespace?: string): void;
688
960
  };
@@ -693,7 +965,10 @@ type ServiceInstance = FetchAPI & {
693
965
  };
694
966
  type ServiceTimelineState = Readonly<{
695
967
  snapshot: NamespaceSnapshot;
696
- clock: Readonly<ReturnType<Clock["state"]>>;
968
+ /** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
969
+ clock: Readonly<ClockState & {
970
+ pinned?: boolean;
971
+ }>;
697
972
  rngState: number;
698
973
  }>;
699
974
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
@@ -706,27 +981,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
706
981
  readonly sqlite: SqliteClient$1;
707
982
  readonly clock: Clock;
708
983
  readonly faults: FaultRegistry;
984
+ /** Baseline response time per namespace. */
985
+ readonly latency: LatencyRegistry;
709
986
  readonly metrics: Metrics;
710
987
  readonly journal: Journal;
711
988
  readonly rng: Rng;
712
989
  readonly credentials: CredentialRegistry;
713
990
  /** The webhook hub, when the service has outbound webhooks. */
714
991
  readonly webhooks: WebhookHub | undefined;
715
- /** Enable independent namespace clocks and PRNGs before serving a fleet. */
716
- isolateNamespaces(): void;
992
+ /**
993
+ * A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
994
+ * offset and a freeze of its own, so moving one never moves another.
995
+ */
717
996
  namespaceClock(namespace?: string): Clock;
718
997
  namespaceOf(request: Request): string;
719
998
  /** Opaque in-process checkpoint including records, controls and webhook history. */
720
999
  fleetSnapshot(namespace: string): object;
721
1000
  fleetRestore(snapshot: unknown, namespace: string): void;
1001
+ fleetExport(snapshot: unknown): SnapshotDocument;
1002
+ fleetImport(namespace: string, document: unknown): object;
722
1003
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
723
1004
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
724
1005
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
725
1006
  instance(namespace?: string): T;
726
1007
  /** Public names of every namespace created so far. */
727
1008
  namespaces(): string[];
728
- /** Reset one namespace, or every namespace with `"*"`. */
1009
+ /** Return one namespace to its boot state, or every namespace with `"*"`. */
729
1010
  reset(namespace?: string): Promise<void>;
1011
+ /** Reset a namespace and forget it, releasing everything it held. */
1012
+ dropNamespace(namespace: string): Promise<void>;
1013
+ /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
1014
+ controls(namespace?: string): ControlState & {
1015
+ snapshots: SnapshotInfo[];
1016
+ };
1017
+ /** Apply a control document to a namespace. A given key replaces that control. */
1018
+ configure(controls: NamespaceControls, namespace?: string): ControlState & {
1019
+ snapshots: SnapshotInfo[];
1020
+ };
1021
+ /** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
1022
+ readonly snapshots: {
1023
+ /** Capture the namespace now. Reusing a name replaces that snapshot. */
1024
+ create(options?: {
1025
+ name?: string;
1026
+ namespace?: string;
1027
+ }): SnapshotInfo;
1028
+ list(namespace?: string): SnapshotInfo[];
1029
+ /** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
1030
+ export(id: string, namespace?: string): SnapshotDocument;
1031
+ /** Store a document as a snapshot without restoring it. */
1032
+ import(document: SnapshotDocument, options?: {
1033
+ name?: string;
1034
+ namespace?: string;
1035
+ }): SnapshotInfo;
1036
+ restore(id: string, namespace?: string): void;
1037
+ delete(id: string, namespace?: string): boolean;
1038
+ };
1039
+ /** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
1040
+ headers(input: ControlHeaderInput): Record<string, string>;
730
1041
  snapshot(namespace?: string): NamespaceSnapshot;
731
1042
  restore(snapshot: NamespaceSnapshot, namespace?: string): void;
732
1043
  /** Capture the current branch. Mutating HTTP calls do this automatically. */
@@ -1082,6 +1393,8 @@ type PostHogRuntimeOptions = {
1082
1393
  seed?: number | string;
1083
1394
  adminPrefix?: string;
1084
1395
  adminKey?: string;
1396
+ /** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
1397
+ adminControls?: MockControls;
1085
1398
  onLog?: (entry: RequestLog) => void;
1086
1399
  /** Flags every namespace starts with (and returns to on reset). */
1087
1400
  flags?: Record<string, FlagSpec>;
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  supportedOperationIds,
16
16
  tokenFromBody,
17
17
  valueForState
18
- } from "./chunk-3R4Y742O.js";
18
+ } from "./chunk-YTVQ24KD.js";
19
19
  export {
20
20
  ACME_FLAG_STATE,
21
21
  POSTHOG_NAMESPACE,