@crvouga/mockingbird-service-posthog 1.7.1 → 2.0.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-FWRNARH5.js";
7
- import "./chunk-ZRB53DZ6.js";
6
+ } from "./chunk-FM7IAA7L.js";
7
+ import "./chunk-NRFKITRM.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -280,6 +280,15 @@ type FaultCandidate = {
280
280
  namespace: string;
281
281
  };
282
282
  type FaultRegistry = {
283
+ isolateNamespaces(): void;
284
+ snapshot(namespace: string): {
285
+ rules: (FaultRule & {
286
+ remaining: number | null;
287
+ hits: number;
288
+ position: number;
289
+ })[];
290
+ rngState: number;
291
+ };
283
292
  add(rule: FaultRule): FaultRule;
284
293
  list(): (FaultRule & {
285
294
  remaining: number | null;
@@ -287,6 +296,14 @@ type FaultRegistry = {
287
296
  })[];
288
297
  remove(id: string): boolean;
289
298
  clear(): void;
299
+ restore(namespace: string, state: {
300
+ rules: (FaultRule & {
301
+ remaining: number | null;
302
+ hits: number;
303
+ position: number;
304
+ })[];
305
+ rngState: number;
306
+ }): void;
290
307
  /**
291
308
  * Every fault this request should get, in rule order, stopping at the first that answers
292
309
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
@@ -464,8 +481,8 @@ type MetricsReport = {
464
481
  };
465
482
  type Metrics = {
466
483
  record(entry: RequestLog): void;
467
- report(): MetricsReport;
468
- reset(): void;
484
+ report(namespace?: string): MetricsReport;
485
+ reset(namespace?: string): void;
469
486
  };
470
487
 
471
488
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -631,6 +648,9 @@ type PublishInput = {
631
648
  id?: string;
632
649
  };
633
650
  type WebhookHub = {
651
+ pending(namespace: string): number;
652
+ snapshot(namespace: string): unknown;
653
+ restore(namespace: string, snapshot: unknown): void;
634
654
  publish(input: PublishInput): WebhookMessage;
635
655
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
636
656
  setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
@@ -658,6 +678,8 @@ type ServiceTimelineState = Readonly<{
658
678
  }>;
659
679
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
660
680
  type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
681
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
682
+ stop?(): void;
661
683
  readonly name: string;
662
684
  readonly sqlite: SqliteClient$1;
663
685
  readonly clock: Clock;
@@ -668,6 +690,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
668
690
  readonly credentials: CredentialRegistry;
669
691
  /** The webhook hub, when the service has outbound webhooks. */
670
692
  readonly webhooks: WebhookHub | undefined;
693
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
694
+ isolateNamespaces(): void;
695
+ namespaceClock(namespace?: string): Clock;
696
+ namespaceOf(request: Request): string;
697
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
698
+ fleetSnapshot(namespace: string): object;
699
+ fleetRestore(snapshot: unknown, namespace: string): void;
671
700
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
672
701
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
673
702
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
@@ -1015,6 +1044,7 @@ type PostHogRuntimeOptions = {
1015
1044
  sqlite?: SqliteClient;
1016
1045
  clock?: Clock;
1017
1046
  seed?: number | string;
1047
+ adminPrefix?: string;
1018
1048
  adminKey?: string;
1019
1049
  onLog?: (entry: RequestLog) => void;
1020
1050
  /** Flags every namespace starts with (and returns to on reset). */
@@ -1023,9 +1053,9 @@ type PostHogRuntimeOptions = {
1023
1053
  };
1024
1054
  type PostHogRuntime = ServiceRuntime<PostHogAPI>;
1025
1055
  /**
1026
- * The PostHog mock with Mockingbird's full service contract: `/health`, `/__admin/*`, clock,
1056
+ * The PostHog mock with Mockingbird's full service contract: `/__admin/health`, `/__admin/*`, clock,
1027
1057
  * fault presets and a request journal. PostHog SDKs cannot add headers, so a namespace is
1028
- * chosen by the `/ns/<name>` host prefix (`POSTHOG_HOST=http://127.0.0.1:8795/ns/w1`), or by
1058
+ * chosen by the `/__admin/ns/<name>` host prefix (`POSTHOG_HOST=http://127.0.0.1:8795/__admin/ns/w1`), or by
1029
1059
  * project token: `PUT /__admin/credentials {"credentials": {"<phc_token>": "<namespace>"}}`.
1030
1060
  * The token is read from `/array/{token}/…`, `?token=`, the body (`token`, `api_key`, a
1031
1061
  * batch's first event), or a personal API key's `Authorization: Bearer`.
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  supportedOperationIds,
16
16
  tokenFromBody,
17
17
  valueForState
18
- } from "./chunk-ZRB53DZ6.js";
18
+ } from "./chunk-NRFKITRM.js";
19
19
  export {
20
20
  ACME_FLAG_STATE,
21
21
  POSTHOG_NAMESPACE,
package/dist/server.d.ts CHANGED
@@ -155,6 +155,15 @@ type FaultCandidate$1 = {
155
155
  namespace: string;
156
156
  };
157
157
  type FaultRegistry$1 = {
158
+ isolateNamespaces(): void;
159
+ snapshot(namespace: string): {
160
+ rules: (FaultRule$1 & {
161
+ remaining: number | null;
162
+ hits: number;
163
+ position: number;
164
+ })[];
165
+ rngState: number;
166
+ };
158
167
  add(rule: FaultRule$1): FaultRule$1;
159
168
  list(): (FaultRule$1 & {
160
169
  remaining: number | null;
@@ -162,6 +171,14 @@ type FaultRegistry$1 = {
162
171
  })[];
163
172
  remove(id: string): boolean;
164
173
  clear(): void;
174
+ restore(namespace: string, state: {
175
+ rules: (FaultRule$1 & {
176
+ remaining: number | null;
177
+ hits: number;
178
+ position: number;
179
+ })[];
180
+ rngState: number;
181
+ }): void;
165
182
  /**
166
183
  * Every fault this request should get, in rule order, stopping at the first that answers
167
184
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
@@ -326,8 +343,8 @@ type MetricsReport$1 = {
326
343
  };
327
344
  type Metrics$1 = {
328
345
  record(entry: RequestLog$1): void;
329
- report(): MetricsReport$1;
330
- reset(): void;
346
+ report(namespace?: string): MetricsReport$1;
347
+ reset(namespace?: string): void;
331
348
  };
332
349
 
333
350
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -481,6 +498,9 @@ type PublishInput$1 = {
481
498
  id?: string;
482
499
  };
483
500
  type WebhookHub$1 = {
501
+ pending(namespace: string): number;
502
+ snapshot(namespace: string): unknown;
503
+ restore(namespace: string, snapshot: unknown): void;
484
504
  publish(input: PublishInput$1): WebhookMessage$1;
485
505
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
486
506
  setEndpoints(namespace: string, endpoints: WebhookEndpoint$1[]): WebhookEndpoint$1[];
@@ -508,6 +528,8 @@ type ServiceTimelineState$1 = Readonly<{
508
528
  }>;
509
529
  type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
510
530
  type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
531
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
532
+ stop?(): void;
511
533
  readonly name: string;
512
534
  readonly sqlite: SqliteClient$2;
513
535
  readonly clock: Clock$1;
@@ -518,6 +540,13 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
518
540
  readonly credentials: CredentialRegistry$1;
519
541
  /** The webhook hub, when the service has outbound webhooks. */
520
542
  readonly webhooks: WebhookHub$1 | undefined;
543
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
544
+ isolateNamespaces(): void;
545
+ namespaceClock(namespace?: string): Clock$1;
546
+ namespaceOf(request: Request): string;
547
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
548
+ fleetSnapshot(namespace: string): object;
549
+ fleetRestore(snapshot: unknown, namespace: string): void;
521
550
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
522
551
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule$1>): FaultRule$1[];
523
552
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
@@ -564,6 +593,7 @@ type CliOption = {
564
593
  };
565
594
  type CliValues = Record<string, string | boolean | undefined>;
566
595
  type CommonServeOptions = {
596
+ adminPrefix?: string;
567
597
  adminKey: string | undefined;
568
598
  seed: string | undefined;
569
599
  onLog: ((entry: RequestLog$1) => void) | undefined;
@@ -781,6 +811,15 @@ type FaultCandidate = {
781
811
  namespace: string;
782
812
  };
783
813
  type FaultRegistry = {
814
+ isolateNamespaces(): void;
815
+ snapshot(namespace: string): {
816
+ rules: (FaultRule & {
817
+ remaining: number | null;
818
+ hits: number;
819
+ position: number;
820
+ })[];
821
+ rngState: number;
822
+ };
784
823
  add(rule: FaultRule): FaultRule;
785
824
  list(): (FaultRule & {
786
825
  remaining: number | null;
@@ -788,6 +827,14 @@ type FaultRegistry = {
788
827
  })[];
789
828
  remove(id: string): boolean;
790
829
  clear(): void;
830
+ restore(namespace: string, state: {
831
+ rules: (FaultRule & {
832
+ remaining: number | null;
833
+ hits: number;
834
+ position: number;
835
+ })[];
836
+ rngState: number;
837
+ }): void;
791
838
  /**
792
839
  * Every fault this request should get, in rule order, stopping at the first that answers
793
840
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
@@ -965,8 +1012,8 @@ type MetricsReport = {
965
1012
  };
966
1013
  type Metrics = {
967
1014
  record(entry: RequestLog): void;
968
- report(): MetricsReport;
969
- reset(): void;
1015
+ report(namespace?: string): MetricsReport;
1016
+ reset(namespace?: string): void;
970
1017
  };
971
1018
 
972
1019
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -1132,6 +1179,9 @@ type PublishInput = {
1132
1179
  id?: string;
1133
1180
  };
1134
1181
  type WebhookHub = {
1182
+ pending(namespace: string): number;
1183
+ snapshot(namespace: string): unknown;
1184
+ restore(namespace: string, snapshot: unknown): void;
1135
1185
  publish(input: PublishInput): WebhookMessage;
1136
1186
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
1137
1187
  setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
@@ -1159,6 +1209,8 @@ type ServiceTimelineState = Readonly<{
1159
1209
  }>;
1160
1210
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
1161
1211
  type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1212
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
1213
+ stop?(): void;
1162
1214
  readonly name: string;
1163
1215
  readonly sqlite: SqliteClient$1;
1164
1216
  readonly clock: Clock;
@@ -1169,6 +1221,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1169
1221
  readonly credentials: CredentialRegistry;
1170
1222
  /** The webhook hub, when the service has outbound webhooks. */
1171
1223
  readonly webhooks: WebhookHub | undefined;
1224
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
1225
+ isolateNamespaces(): void;
1226
+ namespaceClock(namespace?: string): Clock;
1227
+ namespaceOf(request: Request): string;
1228
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
1229
+ fleetSnapshot(namespace: string): object;
1230
+ fleetRestore(snapshot: unknown, namespace: string): void;
1172
1231
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
1173
1232
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
1174
1233
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
@@ -1419,6 +1478,7 @@ type PostHogRuntimeOptions = {
1419
1478
  sqlite?: SqliteClient;
1420
1479
  clock?: Clock;
1421
1480
  seed?: number | string;
1481
+ adminPrefix?: string;
1422
1482
  adminKey?: string;
1423
1483
  onLog?: (entry: RequestLog) => void;
1424
1484
  /** Flags every namespace starts with (and returns to on reset). */
package/dist/server.js CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  DEFAULT_PORT,
3
3
  createServer,
4
4
  serveTarget
5
- } from "./chunk-FWRNARH5.js";
6
- import "./chunk-ZRB53DZ6.js";
5
+ } from "./chunk-FM7IAA7L.js";
6
+ import "./chunk-NRFKITRM.js";
7
7
  export {
8
8
  DEFAULT_PORT,
9
9
  createServer,