@crvouga/mockingbird-service-formbricks 1.0.0 → 1.0.1

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-RITQFAWR.js";
7
- import "./chunk-ZFDC3GHV.js";
6
+ } from "./chunk-KO4C5CAN.js";
7
+ import "./chunk-R2IPDPFY.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -228,81 +228,95 @@ type FaultRegistry = {
228
228
  take(candidate: FaultCandidate): Promise<FaultHit[]>;
229
229
  };
230
230
 
231
- /** One handled request, as the structured log sees it. */
232
- type RequestLog = {
233
- service: string;
234
- namespace: string;
235
- operationId: string | undefined;
236
- method: string;
237
- path: string;
238
- status: number;
239
- durationMs: number;
240
- /** True when the path matched no operation in the contract. */
241
- unmatched: boolean;
242
- /** Set when a fault rule produced the response. */
243
- faultId?: string;
244
- /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
245
- ids?: Record<string, string>;
246
- /** Set when the service created a resource the request referred to but that did not exist. */
247
- adopted?: boolean;
248
- };
249
- type MetricsReport = {
250
- requests: number;
251
- /** Counts keyed `<operationId> <status>`. */
252
- byOperation: Record<string, number>;
253
- /**
254
- * Paths that matched no operation, most frequent first.
255
- *
256
- * This is the early-warning signal: a consumer calling something the mock does
257
- * not implement shows up here as a count, before it fails a suite as a 404.
258
- */
259
- unmatched: {
260
- method: string;
261
- path: string;
262
- count: number;
263
- }[];
264
- faults: number;
265
- totalDurationMs: number;
266
- };
267
- type Metrics = {
268
- record(entry: RequestLog): void;
269
- report(): MetricsReport;
270
- reset(): void;
271
- };
272
-
273
- /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
274
- type JournalEntry = RequestLog & {
275
- at: string;
231
+ /** A stable identifier for a point in a {@link Timeline}. */
232
+ type CheckpointId = string;
233
+ /** An immutable node in a timeline's checkpoint DAG. */
234
+ type Checkpoint<T> = Readonly<{
235
+ id: CheckpointId;
236
+ branch: string;
237
+ parent: CheckpointId | null;
238
+ /** Logical time supplied by the timeline's injected clock. */
239
+ at: number;
240
+ value: T;
241
+ }>;
242
+ type TimelineOptions = {
243
+ /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
244
+ now?: () => number;
245
+ /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
246
+ maxCheckpoints?: number;
247
+ /** Customize deterministic checkpoint IDs. */
248
+ id?: (sequence: number) => CheckpointId;
276
249
  };
277
- type JournalQuery = {
278
- /** Only this namespace. Omit for every namespace, oldest first across all of them. */
279
- namespace?: string;
280
- operationId?: string;
281
- status?: number;
282
- /** Only entries at or after this instant (epoch ms). */
283
- since?: number;
284
- /** At most this many, the most recent kept. */
285
- limit?: number;
250
+ type CommitOptions = {
251
+ branch?: string;
252
+ /** Parent checkpoint. Defaults to the selected branch's current head. */
253
+ parent?: CheckpointId | null;
286
254
  };
287
- type Journal = {
288
- readonly size: number;
289
- record(entry: JournalEntry): void;
290
- list(query?: JournalQuery): JournalEntry[];
291
- /** Forget one namespace's entries, or every namespace's. */
292
- clear(namespace?: string): void;
255
+ type ForkOptions = {
256
+ /** Checkpoint to fork from. Defaults to the main branch's head. */
257
+ from?: CheckpointId;
293
258
  };
259
+ /**
260
+ * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
261
+ * records, namespace images, or copy-on-write SQL engine snapshots.
262
+ *
263
+ * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
264
+ * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
265
+ * (the logical clock) is injected.
266
+ */
267
+ declare class Timeline<T> {
268
+ readonly maxCheckpoints: number;
269
+ private readonly now;
270
+ private readonly makeId;
271
+ private readonly nodes;
272
+ private readonly heads;
273
+ /** Unreferenced nodes in the exact order they became collectible. */
274
+ private readonly evictable;
275
+ /** Branch heads plus explicit retainers. Absent means zero. */
276
+ private readonly references;
277
+ private readonly explicitPins;
278
+ private sequence;
279
+ constructor(options?: TimelineOptions);
280
+ /** Capture a new immutable value and move `branch` to it. */
281
+ commit(value: T, options?: CommitOptions): Checkpoint<T>;
282
+ /** Create a branch pointer without copying its checkpoint value. */
283
+ fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
284
+ /** Move a branch pointer to an existing checkpoint. */
285
+ checkout(branch: string, id: CheckpointId): Checkpoint<T>;
286
+ get(id: CheckpointId): Checkpoint<T>;
287
+ head(branch?: string): Checkpoint<T> | undefined;
288
+ hasBranch(branch: string): boolean;
289
+ branches(): Readonly<Record<string, CheckpointId>>;
290
+ checkpoints(): readonly Checkpoint<T>[];
291
+ /** Number of retained checkpoints without allocating an array. */
292
+ get size(): number;
293
+ /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
294
+ retain(id: CheckpointId): Checkpoint<T>;
295
+ /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
296
+ release(id: CheckpointId): boolean;
297
+ deleteBranch(branch: string): boolean;
298
+ /**
299
+ * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
300
+ * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
301
+ * storage dependency, so a retained node remains usable after pruning.
302
+ */
303
+ gc(max?: number): CheckpointId[];
304
+ private collect;
305
+ private moveHead;
306
+ private addReference;
307
+ private removeReference;
308
+ private assertBranch;
309
+ }
294
310
 
295
- /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
296
- type CredentialRegistry = {
297
- set(credential: string, namespace: string): void;
298
- get(credential: string): string | undefined;
299
- remove(credential: string): boolean;
300
- clear(): void;
301
- entries(): {
302
- credential: string;
303
- namespace: string;
304
- }[];
305
- };
311
+ /**
312
+ * Anything that can answer a Fetch `Request` with a `Response`.
313
+ *
314
+ * Every Mockingbird service implements this, and every runtime adapter consumes it.
315
+ * It is the only contract shared across the whole graph.
316
+ */
317
+ interface FetchAPI {
318
+ fetch(request: Request): Promise<Response>;
319
+ }
306
320
 
307
321
  type DecodedBody = {
308
322
  kind: "empty";
@@ -521,106 +535,150 @@ type Operation = {
521
535
  responses: Record<string, ResponseObject$1>;
522
536
  };
523
537
 
524
- /**
525
- * Sequential id source persisted in SQLite. Ids are deterministic for a given
526
- * sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
527
- */
528
- declare class IdSequence {
529
- private readonly sqlite;
530
- private readonly namespace;
531
- private readonly salt;
532
- constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
533
- next(prefix: string, length?: number): string;
534
- }
535
-
536
- /** A stable identifier for a point in a {@link Timeline}. */
537
- type CheckpointId = string;
538
- /** An immutable node in a timeline's checkpoint DAG. */
539
- type Checkpoint<T> = Readonly<{
540
- id: CheckpointId;
541
- branch: string;
542
- parent: CheckpointId | null;
543
- /** Logical time supplied by the timeline's injected clock. */
544
- at: number;
545
- value: T;
546
- }>;
547
- type TimelineOptions = {
548
- /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
538
+ /** Options every provider constructor accepts. */
539
+ type APIOptions = {
540
+ /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
541
+ sqlite?: SqliteClient$1;
542
+ /** Clock used for `created`-style fields. Default `Date.now`. */
549
543
  now?: () => number;
550
- /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
551
- maxCheckpoints?: number;
552
- /** Customize deterministic checkpoint IDs. */
553
- id?: (sequence: number) => CheckpointId;
544
+ /**
545
+ * Storage namespace for this instance's records. Instances sharing one SQLite
546
+ * client stay isolated when their namespaces differ. Defaults to the service name.
547
+ */
548
+ namespace?: string;
554
549
  };
555
- type CommitOptions = {
556
- branch?: string;
557
- /** Parent checkpoint. Defaults to the selected branch's current head. */
558
- parent?: CheckpointId | null;
550
+ type OperationContext = {
551
+ request: Request;
552
+ url: URL;
553
+ /** Path parameters. */
554
+ params: Record<string, string>;
555
+ /** Query string decoded with bracket notation (`created[gte]=1` -> `{ created: { gte: "1" } }`). */
556
+ query: FormObject;
557
+ body: DecodedBody;
558
+ /** Shared SQLite client for this service (already migrated). */
559
+ sqlite: SqliteClient$1;
560
+ /** Service namespace used for records / sequences. */
561
+ namespace: string;
562
+ operation: Operation;
563
+ /** The vendor contract the service was built from. */
564
+ document: OpenAPIDocument$1;
565
+ now: () => number;
559
566
  };
560
- type ForkOptions = {
561
- /** Checkpoint to fork from. Defaults to the main branch's head. */
562
- from?: CheckpointId;
567
+
568
+ /**
569
+ * One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
570
+ * `kind` is `media_type` when the body is present but its media type is not one the operation
571
+ * accepts (a `415` on most vendors), `syntax` when it could not be decoded, `required` when
572
+ * the operation needs a body and none arrived, and `schema` for a contract violation.
573
+ */
574
+ type BodyIssue = {
575
+ path: string;
576
+ message: string;
577
+ kind?: "media_type" | "syntax" | "required" | "schema";
563
578
  };
579
+
564
580
  /**
565
- * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
566
- * records, namespace images, or copy-on-write SQL engine snapshots.
567
- *
568
- * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
569
- * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
570
- * (the logical clock) is injected.
581
+ * What the mock received from a request it rejected, so a 4xx can be attributed after the
582
+ * fact (an empty body, a missing `content-type`, a schema violation) without logging the body.
571
583
  */
572
- declare class Timeline<T> {
573
- readonly maxCheckpoints: number;
574
- private readonly now;
575
- private readonly makeId;
576
- private readonly nodes;
577
- private readonly heads;
578
- /** Unreferenced nodes in the exact order they became collectible. */
579
- private readonly evictable;
580
- /** Branch heads plus explicit retainers. Absent means zero. */
581
- private readonly references;
582
- private readonly explicitPins;
583
- private sequence;
584
- constructor(options?: TimelineOptions);
585
- /** Capture a new immutable value and move `branch` to it. */
586
- commit(value: T, options?: CommitOptions): Checkpoint<T>;
587
- /** Create a branch pointer without copying its checkpoint value. */
588
- fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
589
- /** Move a branch pointer to an existing checkpoint. */
590
- checkout(branch: string, id: CheckpointId): Checkpoint<T>;
591
- get(id: CheckpointId): Checkpoint<T>;
592
- head(branch?: string): Checkpoint<T> | undefined;
593
- hasBranch(branch: string): boolean;
594
- branches(): Readonly<Record<string, CheckpointId>>;
595
- checkpoints(): readonly Checkpoint<T>[];
596
- /** Number of retained checkpoints without allocating an array. */
597
- get size(): number;
598
- /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
599
- retain(id: CheckpointId): Checkpoint<T>;
600
- /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
601
- release(id: CheckpointId): boolean;
602
- deleteBranch(branch: string): boolean;
584
+ type RejectedRequest = {
585
+ /** The raw `content-type` header, or `null` when the request sent none. */
586
+ contentType: string | null;
587
+ /** Bytes of body received from `content-length` (`0` for none), or `null` when the client sent no length (a streamed / chunked body). */
588
+ bodyBytes: number | null;
589
+ /** The raw `transfer-encoding` header (`chunked`), or `null`. */
590
+ transferEncoding: string | null;
591
+ };
592
+ /** One handled request, as the structured log sees it. */
593
+ type RequestLog = {
594
+ service: string;
595
+ namespace: string;
596
+ operationId: string | undefined;
597
+ method: string;
598
+ path: string;
599
+ status: number;
600
+ durationMs: number;
601
+ /** True when the path matched no operation in the contract. */
602
+ unmatched: boolean;
603
+ /** Set when a fault rule produced the response. */
604
+ faultId?: string;
605
+ /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
606
+ ids?: Record<string, string>;
607
+ /** Set when the service created a resource the request referred to but that did not exist. */
608
+ adopted?: boolean;
609
+ /** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
610
+ request?: RejectedRequest;
611
+ /** The validation issues behind a rejection, when the service found any. */
612
+ issues?: BodyIssue[];
613
+ };
614
+ type MetricsReport = {
615
+ requests: number;
616
+ /** Counts keyed `<operationId> <status>`. */
617
+ byOperation: Record<string, number>;
603
618
  /**
604
- * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
605
- * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
606
- * storage dependency, so a retained node remains usable after pruning.
619
+ * Paths that matched no operation, most frequent first.
620
+ *
621
+ * This is the early-warning signal: a consumer calling something the mock does
622
+ * not implement shows up here as a count, before it fails a suite as a 404.
607
623
  */
608
- gc(max?: number): CheckpointId[];
609
- private collect;
610
- private moveHead;
611
- private addReference;
612
- private removeReference;
613
- private assertBranch;
614
- }
624
+ unmatched: {
625
+ method: string;
626
+ path: string;
627
+ count: number;
628
+ }[];
629
+ faults: number;
630
+ totalDurationMs: number;
631
+ };
632
+ type Metrics = {
633
+ record(entry: RequestLog): void;
634
+ report(): MetricsReport;
635
+ reset(): void;
636
+ };
637
+
638
+ /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
639
+ type JournalEntry = RequestLog & {
640
+ at: string;
641
+ };
642
+ type JournalQuery = {
643
+ /** Only this namespace. Omit for every namespace, oldest first across all of them. */
644
+ namespace?: string;
645
+ operationId?: string;
646
+ status?: number;
647
+ /** Only entries at or after this instant (epoch ms). */
648
+ since?: number;
649
+ /** At most this many, the most recent kept. */
650
+ limit?: number;
651
+ };
652
+ type Journal = {
653
+ readonly size: number;
654
+ record(entry: JournalEntry): void;
655
+ list(query?: JournalQuery): JournalEntry[];
656
+ /** Forget one namespace's entries, or every namespace's. */
657
+ clear(namespace?: string): void;
658
+ };
659
+
660
+ /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
661
+ type CredentialRegistry = {
662
+ set(credential: string, namespace: string): void;
663
+ get(credential: string): string | undefined;
664
+ remove(credential: string): boolean;
665
+ clear(): void;
666
+ entries(): {
667
+ credential: string;
668
+ namespace: string;
669
+ }[];
670
+ };
615
671
 
616
672
  /**
617
- * Anything that can answer a Fetch `Request` with a `Response`.
618
- *
619
- * Every Mockingbird service implements this, and every runtime adapter consumes it.
620
- * It is the only contract shared across the whole graph.
673
+ * Sequential id source persisted in SQLite. Ids are deterministic for a given
674
+ * sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
621
675
  */
622
- interface FetchAPI {
623
- fetch(request: Request): Promise<Response>;
676
+ declare class IdSequence {
677
+ private readonly sqlite;
678
+ private readonly namespace;
679
+ private readonly salt;
680
+ constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
681
+ next(prefix: string, length?: number): string;
624
682
  }
625
683
 
626
684
  /**
@@ -773,36 +831,6 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
773
831
  timeline(namespace?: string): Timeline<ServiceTimelineState>;
774
832
  };
775
833
 
776
- /** Options every provider constructor accepts. */
777
- type APIOptions = {
778
- /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
779
- sqlite?: SqliteClient$1;
780
- /** Clock used for `created`-style fields. Default `Date.now`. */
781
- now?: () => number;
782
- /**
783
- * Storage namespace for this instance's records. Instances sharing one SQLite
784
- * client stay isolated when their namespaces differ. Defaults to the service name.
785
- */
786
- namespace?: string;
787
- };
788
- type OperationContext = {
789
- request: Request;
790
- url: URL;
791
- /** Path parameters. */
792
- params: Record<string, string>;
793
- /** Query string decoded with bracket notation (`created[gte]=1` -> `{ created: { gte: "1" } }`). */
794
- query: FormObject;
795
- body: DecodedBody;
796
- /** Shared SQLite client for this service (already migrated). */
797
- sqlite: SqliteClient$1;
798
- /** Service namespace used for records / sequences. */
799
- namespace: string;
800
- operation: Operation;
801
- /** The vendor contract the service was built from. */
802
- document: OpenAPIDocument$1;
803
- now: () => number;
804
- };
805
-
806
834
  /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
807
835
  type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
808
836
  /** Mutation counters returned by {@link SqliteStatement.run}. */
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  operationIds,
15
15
  supportedOperationIds,
16
16
  validateResponseData
17
- } from "./chunk-ZFDC3GHV.js";
17
+ } from "./chunk-R2IPDPFY.js";
18
18
  export {
19
19
  CORPUS_SURVEYS,
20
20
  DEFAULT_SETTINGS,