@crvouga/mockingbird-service-formbricks 0.2.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/CHANGELOG.md +14 -1
- package/README.md +63 -56
- package/dist/{chunk-2FV4RSDZ.js → chunk-KO4C5CAN.js} +14 -15
- package/dist/chunk-KO4C5CAN.js.map +7 -0
- package/dist/chunk-R2IPDPFY.js +3997 -0
- package/dist/chunk-R2IPDPFY.js.map +7 -0
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +292 -250
- package/dist/index.js +7 -9
- package/dist/server.d.ts +369 -300
- package/dist/server.js +2 -2
- package/package.json +7 -3
- package/dist/chunk-2FV4RSDZ.js.map +0 -7
- package/dist/chunk-FZI2QHRQ.js +0 -11714
- package/dist/chunk-FZI2QHRQ.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -228,81 +228,95 @@ type FaultRegistry = {
|
|
|
228
228
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
-
/**
|
|
232
|
-
type
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
-
/**
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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
|
-
*
|
|
566
|
-
*
|
|
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
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
-
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
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
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
623
|
-
|
|
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}. */
|
|
@@ -832,14 +860,20 @@ interface SqliteClient {
|
|
|
832
860
|
transaction<T>(fn: () => T): T;
|
|
833
861
|
}
|
|
834
862
|
|
|
835
|
-
/** A survey definition, passed through as Formbricks serves it (blocks, elements,
|
|
863
|
+
/** A survey definition, passed through as Formbricks serves it (blocks, elements, endings, …). */
|
|
836
864
|
type Survey = Record<string, unknown> & {
|
|
837
865
|
id: string;
|
|
838
866
|
name: string;
|
|
839
867
|
type: string;
|
|
840
868
|
status: string;
|
|
841
|
-
/** `null` for the shared
|
|
842
|
-
|
|
869
|
+
/** `null` for the shared corpus surveys, which every configured workspace serves. */
|
|
870
|
+
workspaceId?: string | null;
|
|
871
|
+
};
|
|
872
|
+
/** A contact (`PUT /__admin/contacts`); `attributes.userId` becomes the response's `contact.userId`. */
|
|
873
|
+
type Contact = {
|
|
874
|
+
id: string;
|
|
875
|
+
workspaceId: string | null;
|
|
876
|
+
attributes: Record<string, string>;
|
|
843
877
|
};
|
|
844
878
|
/** One stored response, in Formbricks' `TResponse` shape. */
|
|
845
879
|
type ResponseRecord = {
|
|
@@ -847,11 +881,11 @@ type ResponseRecord = {
|
|
|
847
881
|
createdAt: string;
|
|
848
882
|
updatedAt: string;
|
|
849
883
|
surveyId: string;
|
|
850
|
-
|
|
884
|
+
workspaceId: string;
|
|
851
885
|
displayId: string | null;
|
|
852
886
|
contact: {
|
|
853
887
|
id: string;
|
|
854
|
-
userId
|
|
888
|
+
userId?: string;
|
|
855
889
|
} | null;
|
|
856
890
|
contactAttributes: Record<string, string> | null;
|
|
857
891
|
finished: boolean;
|
|
@@ -866,34 +900,29 @@ type ResponseRecord = {
|
|
|
866
900
|
};
|
|
867
901
|
/** Per-namespace knobs, set through `PUT /__admin/settings`; cleared on reset. */
|
|
868
902
|
type Settings = {
|
|
869
|
-
/**
|
|
870
|
-
|
|
903
|
+
/** Workspace ids that exist and serve the shared corpus surveys. */
|
|
904
|
+
workspaces: string[];
|
|
905
|
+
/** Pre-Formbricks-5 environment ids, each an alias of a workspace (`{envId: workspaceId}`). */
|
|
906
|
+
legacyEnvironmentIds: Record<string, string>;
|
|
871
907
|
/** Accepted management API keys; empty means any non-empty `x-api-key` works. */
|
|
872
908
|
apiKeys: string[];
|
|
873
909
|
/** The `webhookId` put in webhook bodies. */
|
|
874
910
|
webhookId: string;
|
|
875
|
-
/**
|
|
911
|
+
/** Contacts are an Enterprise feature: when off, a response with a `contactId` is 403. */
|
|
876
912
|
contactsEnabled: boolean;
|
|
877
913
|
};
|
|
878
|
-
/**
|
|
879
|
-
declare const
|
|
880
|
-
|
|
914
|
+
/** The default workspace every namespace starts with. */
|
|
915
|
+
declare const WORKSPACE_ID = "cworkspace000000000000001";
|
|
916
|
+
/** A legacy environment id that resolves to {@link WORKSPACE_ID} (older SDKs still send one). */
|
|
917
|
+
declare const ENVIRONMENT_ID = "cenvironment0000000000001";
|
|
881
918
|
declare const DEFAULT_SETTINGS: Settings;
|
|
882
|
-
/**
|
|
883
|
-
|
|
884
|
-
* (`packages/forms-fixtures/formbricks/prod-clone.json` in geviti-monorepo).
|
|
885
|
-
*/
|
|
886
|
-
declare const PROD_CLONE_SURVEYS: readonly Survey[];
|
|
887
|
-
declare const PROD_CLONE_EXPORTED_AT: string;
|
|
919
|
+
/** The synthetic survey corpus every namespace is seeded with (`src/corpus/surveys.json`). */
|
|
920
|
+
declare const CORPUS_SURVEYS: readonly Survey[];
|
|
888
921
|
declare class FormbricksState {
|
|
889
922
|
private readonly seed;
|
|
890
923
|
readonly surveys: Collection<Survey>;
|
|
891
924
|
readonly responses: Collection<ResponseRecord>;
|
|
892
|
-
readonly contacts: Collection<
|
|
893
|
-
id: string;
|
|
894
|
-
environmentId: string;
|
|
895
|
-
userId: string;
|
|
896
|
-
}>;
|
|
925
|
+
readonly contacts: Collection<Contact>;
|
|
897
926
|
readonly settings: Collection<Settings>;
|
|
898
927
|
readonly ids: IdSequence;
|
|
899
928
|
constructor(sqlite: SqliteClient, namespace: string, seed: {
|
|
@@ -905,17 +934,20 @@ declare class FormbricksState {
|
|
|
905
934
|
update(patch: Partial<Settings>): Settings;
|
|
906
935
|
/** Formbricks ids are cuid2: lower-case alphanumerics starting with a letter, 25 long. */
|
|
907
936
|
nextId(): string;
|
|
908
|
-
|
|
937
|
+
/**
|
|
938
|
+
* `resolveClientApiIds`: a workspace id, or a legacy environment id, to its workspace id
|
|
939
|
+
* (`undefined` when neither is known).
|
|
940
|
+
*/
|
|
941
|
+
resolveWorkspace(id: string): string | undefined;
|
|
942
|
+
/** The v1 `environmentId` of a workspace: its legacy environment id, else its own id. */
|
|
943
|
+
legacyEnvironmentId(workspaceId: string): string;
|
|
909
944
|
allSurveys(): Survey[];
|
|
910
|
-
/** Surveys
|
|
911
|
-
surveysOf(
|
|
912
|
-
/** Whether a survey belongs to
|
|
913
|
-
belongsTo(survey: Survey,
|
|
914
|
-
/**
|
|
915
|
-
|
|
916
|
-
id: string;
|
|
917
|
-
userId: string;
|
|
918
|
-
};
|
|
945
|
+
/** Surveys a workspace serves: its own, plus the shared corpus when it is configured. */
|
|
946
|
+
surveysOf(workspaceId: string): Survey[];
|
|
947
|
+
/** Whether a survey belongs to a workspace (`survey.workspaceId !== workspaceId` check). */
|
|
948
|
+
belongsTo(survey: Survey, workspaceId: string): boolean;
|
|
949
|
+
/** `getContact(contactId, workspaceId)`: a contact of that workspace (or a shared one). */
|
|
950
|
+
contactOf(contactId: string, workspaceId: string): Contact | undefined;
|
|
919
951
|
}
|
|
920
952
|
|
|
921
953
|
/**
|
|
@@ -1090,20 +1122,21 @@ declare const operationIds: readonly ["GetEnvironmentState", "CreateClientRespon
|
|
|
1090
1122
|
declare const supportedOperationIds: readonly ["GetEnvironmentState", "CreateClientResponse", "ListResponses", "GetResponse", "ListSurveys", "CreateSurvey", "GetSurvey", "GetWidgetScript"];
|
|
1091
1123
|
|
|
1092
1124
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
* in `packages/surveys/src/lib/validation/evaluator.ts`), trimmed to
|
|
1095
|
-
* required elements,
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1125
|
+
* Formbricks' response validation (`validateResponseData` in `apps/web/modules/api/lib/validation.ts`
|
|
1126
|
+
* → `validateBlockResponses` in `packages/surveys/src/lib/validation/evaluator.ts`), trimmed to the
|
|
1127
|
+
* structural checks: required elements, choice membership for choice elements without an "other"
|
|
1128
|
+
* option, and the implicit email / url / phone rules of openText elements. Only the elements
|
|
1129
|
+
* present in `data` are checked, finished or not (upstream never checks absent elements).
|
|
1130
|
+
* Custom `validation.rules` are not evaluated.
|
|
1098
1131
|
*/
|
|
1099
1132
|
|
|
1100
1133
|
/** `{<elementId>: [messages]}`, or `null` when the response passes. */
|
|
1101
|
-
declare const validateResponseData: (survey: Survey, data: Record<string, unknown>,
|
|
1134
|
+
declare const validateResponseData: (survey: Survey, data: Record<string, unknown>, language?: string) => Record<string, string[]> | null;
|
|
1102
1135
|
|
|
1103
|
-
/**
|
|
1104
|
-
declare const WEBHOOK_PATH = "/
|
|
1136
|
+
/** A conventional path for the consumer app's webhook receiver (examples and the CLI help use it). */
|
|
1137
|
+
declare const WEBHOOK_PATH = "/webhooks/formbricks";
|
|
1105
1138
|
/**
|
|
1106
|
-
* Every named Formbricks misbehaviour
|
|
1139
|
+
* Every named Formbricks misbehaviour a consumer app may branch on, switched on with
|
|
1107
1140
|
* `POST /__admin/faults {"preset": "<name>"}` (add `count` to limit it).
|
|
1108
1141
|
*/
|
|
1109
1142
|
declare const FORMBRICKS_PRESETS: Record<string, FaultPreset>;
|
|
@@ -1120,8 +1153,8 @@ type FormbricksRuntimeOptions = {
|
|
|
1120
1153
|
surveys?: readonly Survey[];
|
|
1121
1154
|
settings?: Partial<Settings>;
|
|
1122
1155
|
/**
|
|
1123
|
-
* Where webhooks go: `url`
|
|
1124
|
-
* `whsec_…` Standard Webhooks key) signs `webhook-signature`; `events` defaults to
|
|
1156
|
+
* Where webhooks go: `url` (any query, e.g. a `?token=` your receiver checks, is kept); `secret`
|
|
1157
|
+
* (a `whsec_…` Standard Webhooks key) signs `webhook-signature`; `events` defaults to
|
|
1125
1158
|
* `["responseFinished"]` (add `"responseCreated"` for both).
|
|
1126
1159
|
*/
|
|
1127
1160
|
webhooks?: Omit<WebhookEndpoint, "id"> & WebhookHubOptionsSubset;
|
|
@@ -1130,22 +1163,22 @@ type FormbricksRuntime = ServiceRuntime<FormbricksAPI> & {
|
|
|
1130
1163
|
readonly webhooks: WebhookHub;
|
|
1131
1164
|
};
|
|
1132
1165
|
/**
|
|
1133
|
-
* The namespace carrier for the client API is the environment id in the
|
|
1134
|
-
*
|
|
1166
|
+
* The namespace carrier for the client API is the workspace (or legacy environment) id in the
|
|
1167
|
+
* path (the SDK cannot add headers); the management API's is its `x-api-key`.
|
|
1135
1168
|
*/
|
|
1136
1169
|
declare const formbricksCredential: (request: Request) => string | undefined;
|
|
1137
1170
|
/**
|
|
1138
1171
|
* The Formbricks mock with Mockingbird's full service contract: `/health`, `/__admin/*`,
|
|
1139
|
-
* namespaces by header, by `/ns/<name>` prefix on
|
|
1140
|
-
*
|
|
1172
|
+
* namespaces by header, by `/ns/<name>` prefix on the app URL, or by workspace id / API key
|
|
1173
|
+
* (`PUT /__admin/credentials {"credentials": {"<workspace id or key>": "<namespace>"}}`),
|
|
1141
1174
|
* clock control, fault presets, and Standard-Webhooks-signed `responseFinished` webhooks.
|
|
1142
1175
|
*/
|
|
1143
1176
|
declare const createRuntime: (options?: FormbricksRuntimeOptions) => FormbricksRuntime;
|
|
1144
1177
|
|
|
1145
1178
|
declare const FORMBRICKS_NAMESPACE = "formbricks";
|
|
1146
1179
|
/** The response as the API (and the webhook) renders it: `TResponse`. */
|
|
1147
|
-
type ApiResponse = Omit<ResponseRecord, "
|
|
1148
|
-
/** The body Formbricks' pipeline posts to a webhook (`
|
|
1180
|
+
type ApiResponse = Omit<ResponseRecord, "workspaceId">;
|
|
1181
|
+
/** The body Formbricks' response pipeline posts to a webhook (`process-response-pipeline-job.ts`). */
|
|
1149
1182
|
type FormbricksWebhook = {
|
|
1150
1183
|
webhookId: string;
|
|
1151
1184
|
event: "responseCreated" | "responseFinished";
|
|
@@ -1160,18 +1193,21 @@ type FormbricksWebhook = {
|
|
|
1160
1193
|
};
|
|
1161
1194
|
};
|
|
1162
1195
|
type FormbricksAPIOptions = APIOptions & {
|
|
1163
|
-
/** Surveys every namespace starts with. Default:
|
|
1196
|
+
/** Surveys every namespace starts with. Default: the synthetic corpus (`CORPUS_SURVEYS`). */
|
|
1164
1197
|
surveys?: readonly Survey[];
|
|
1165
1198
|
settings?: Partial<Settings>;
|
|
1166
1199
|
/** Called for every pipeline event; the runtime signs and delivers it. */
|
|
1167
1200
|
onWebhook?: (event: FormbricksWebhook) => void;
|
|
1168
1201
|
};
|
|
1169
|
-
type ErrorCode = "not_found" | "bad_request" | "internal_server_error" | "not_authenticated" | "forbidden" | "too_many_requests";
|
|
1170
|
-
/**
|
|
1171
|
-
|
|
1202
|
+
type ErrorCode = "not_found" | "bad_request" | "internal_server_error" | "unauthorized" | "not_authenticated" | "forbidden" | "too_many_requests";
|
|
1203
|
+
/**
|
|
1204
|
+
* Formbricks' v1 error envelope (`apps/web/app/lib/api/response.ts`): `{code, message, details}`,
|
|
1205
|
+
* `Cache-Control: private, no-store`, and the CORS headers on the routes that pass `cors`.
|
|
1206
|
+
*/
|
|
1207
|
+
declare const formbricksError: (status: number, code: ErrorCode, message: string, details?: Record<string, unknown>, cors?: boolean) => Response;
|
|
1172
1208
|
/**
|
|
1173
|
-
* Stateful mock of Formbricks
|
|
1174
|
-
*
|
|
1209
|
+
* Stateful mock of open-source Formbricks: the client environment state and response creation
|
|
1210
|
+
* the JS SDK uses, the v1 management API, and the response pipeline's webhooks.
|
|
1175
1211
|
*/
|
|
1176
1212
|
declare class FormbricksAPI implements FetchAPI$1 {
|
|
1177
1213
|
readonly app: Hono;
|
|
@@ -1184,17 +1220,23 @@ declare class FormbricksAPI implements FetchAPI$1 {
|
|
|
1184
1220
|
fetch(request: Request): Promise<Response>;
|
|
1185
1221
|
reset(): Promise<void>;
|
|
1186
1222
|
private iso;
|
|
1187
|
-
/**
|
|
1188
|
-
|
|
1223
|
+
/**
|
|
1224
|
+
* A survey as the v1 management API serves it: `questions` derived from `blocks`, the owning
|
|
1225
|
+
* `workspaceId` and its legacy `environmentId`, and `projectOverwrites`. Shared corpus surveys
|
|
1226
|
+
* are reported under the first configured workspace.
|
|
1227
|
+
*/
|
|
1228
|
+
wireSurvey(survey: Survey): Survey;
|
|
1189
1229
|
render(record: ResponseRecord, context?: OperationContext): ApiResponse;
|
|
1190
1230
|
private environmentState;
|
|
1191
1231
|
private createResponse;
|
|
1192
|
-
/** Emit a pipeline event for a stored response
|
|
1232
|
+
/** Emit a pipeline event (`responseCreated` / `responseFinished`) for a stored response. */
|
|
1193
1233
|
pipeline(event: FormbricksWebhook["event"], record: ResponseRecord, survey: Survey): void;
|
|
1194
1234
|
private listResponses;
|
|
1235
|
+
/** `getSurveys(workspaceIds, limit, offset)`: newest `updatedAt` first. */
|
|
1236
|
+
private listSurveys;
|
|
1195
1237
|
private createSurvey;
|
|
1196
1238
|
responses(): ApiResponse[];
|
|
1197
1239
|
}
|
|
1198
1240
|
|
|
1199
|
-
export { DEFAULT_SETTINGS,
|
|
1200
|
-
export type { ApiResponse, FetchAPI$1 as FetchAPI, FormbricksAPIOptions, FormbricksRuntime, FormbricksRuntimeOptions, FormbricksWebhook, OperationId, ResponseRecord, Settings, SqliteClient, SupportedOperationId, Survey };
|
|
1241
|
+
export { CORPUS_SURVEYS, DEFAULT_SETTINGS, ENVIRONMENT_ID, FORMBRICKS_NAMESPACE, FORMBRICKS_PRESETS, FormbricksAPI, WEBHOOK_PATH, WORKSPACE_ID, createRuntime, document, formbricksCredential, formbricksError, operationIds, supportedOperationIds, validateResponseData };
|
|
1242
|
+
export type { ApiResponse, Contact, FetchAPI$1 as FetchAPI, FormbricksAPIOptions, FormbricksRuntime, FormbricksRuntimeOptions, FormbricksWebhook, OperationId, ResponseRecord, Settings, SqliteClient, SupportedOperationId, Survey };
|