@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/server.d.ts
CHANGED
|
@@ -170,82 +170,6 @@ type FaultRegistry$1 = {
|
|
|
170
170
|
take(candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
-
/** One handled request, as the structured log sees it. */
|
|
174
|
-
type RequestLog$1 = {
|
|
175
|
-
service: string;
|
|
176
|
-
namespace: string;
|
|
177
|
-
operationId: string | undefined;
|
|
178
|
-
method: string;
|
|
179
|
-
path: string;
|
|
180
|
-
status: number;
|
|
181
|
-
durationMs: number;
|
|
182
|
-
/** True when the path matched no operation in the contract. */
|
|
183
|
-
unmatched: boolean;
|
|
184
|
-
/** Set when a fault rule produced the response. */
|
|
185
|
-
faultId?: string;
|
|
186
|
-
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
187
|
-
ids?: Record<string, string>;
|
|
188
|
-
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
189
|
-
adopted?: boolean;
|
|
190
|
-
};
|
|
191
|
-
type MetricsReport$1 = {
|
|
192
|
-
requests: number;
|
|
193
|
-
/** Counts keyed `<operationId> <status>`. */
|
|
194
|
-
byOperation: Record<string, number>;
|
|
195
|
-
/**
|
|
196
|
-
* Paths that matched no operation, most frequent first.
|
|
197
|
-
*
|
|
198
|
-
* This is the early-warning signal: a consumer calling something the mock does
|
|
199
|
-
* not implement shows up here as a count, before it fails a suite as a 404.
|
|
200
|
-
*/
|
|
201
|
-
unmatched: {
|
|
202
|
-
method: string;
|
|
203
|
-
path: string;
|
|
204
|
-
count: number;
|
|
205
|
-
}[];
|
|
206
|
-
faults: number;
|
|
207
|
-
totalDurationMs: number;
|
|
208
|
-
};
|
|
209
|
-
type Metrics$1 = {
|
|
210
|
-
record(entry: RequestLog$1): void;
|
|
211
|
-
report(): MetricsReport$1;
|
|
212
|
-
reset(): void;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
216
|
-
type JournalEntry$1 = RequestLog$1 & {
|
|
217
|
-
at: string;
|
|
218
|
-
};
|
|
219
|
-
type JournalQuery$1 = {
|
|
220
|
-
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
221
|
-
namespace?: string;
|
|
222
|
-
operationId?: string;
|
|
223
|
-
status?: number;
|
|
224
|
-
/** Only entries at or after this instant (epoch ms). */
|
|
225
|
-
since?: number;
|
|
226
|
-
/** At most this many, the most recent kept. */
|
|
227
|
-
limit?: number;
|
|
228
|
-
};
|
|
229
|
-
type Journal$1 = {
|
|
230
|
-
readonly size: number;
|
|
231
|
-
record(entry: JournalEntry$1): void;
|
|
232
|
-
list(query?: JournalQuery$1): JournalEntry$1[];
|
|
233
|
-
/** Forget one namespace's entries, or every namespace's. */
|
|
234
|
-
clear(namespace?: string): void;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
238
|
-
type CredentialRegistry$1 = {
|
|
239
|
-
set(credential: string, namespace: string): void;
|
|
240
|
-
get(credential: string): string | undefined;
|
|
241
|
-
remove(credential: string): boolean;
|
|
242
|
-
clear(): void;
|
|
243
|
-
entries(): {
|
|
244
|
-
credential: string;
|
|
245
|
-
namespace: string;
|
|
246
|
-
}[];
|
|
247
|
-
};
|
|
248
|
-
|
|
249
173
|
/** A stable identifier for a point in a {@link Timeline}. */
|
|
250
174
|
type CheckpointId$1 = string;
|
|
251
175
|
/** An immutable node in a timeline's checkpoint DAG. */
|
|
@@ -336,6 +260,110 @@ interface FetchAPI$2 {
|
|
|
336
260
|
fetch(request: Request): Promise<Response>;
|
|
337
261
|
}
|
|
338
262
|
|
|
263
|
+
/**
|
|
264
|
+
* One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
|
|
265
|
+
* `kind` is `media_type` when the body is present but its media type is not one the operation
|
|
266
|
+
* accepts (a `415` on most vendors), `syntax` when it could not be decoded, `required` when
|
|
267
|
+
* the operation needs a body and none arrived, and `schema` for a contract violation.
|
|
268
|
+
*/
|
|
269
|
+
type BodyIssue$1 = {
|
|
270
|
+
path: string;
|
|
271
|
+
message: string;
|
|
272
|
+
kind?: "media_type" | "syntax" | "required" | "schema";
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* What the mock received from a request it rejected, so a 4xx can be attributed after the
|
|
277
|
+
* fact (an empty body, a missing `content-type`, a schema violation) without logging the body.
|
|
278
|
+
*/
|
|
279
|
+
type RejectedRequest$1 = {
|
|
280
|
+
/** The raw `content-type` header, or `null` when the request sent none. */
|
|
281
|
+
contentType: string | null;
|
|
282
|
+
/** Bytes of body received from `content-length` (`0` for none), or `null` when the client sent no length (a streamed / chunked body). */
|
|
283
|
+
bodyBytes: number | null;
|
|
284
|
+
/** The raw `transfer-encoding` header (`chunked`), or `null`. */
|
|
285
|
+
transferEncoding: string | null;
|
|
286
|
+
};
|
|
287
|
+
/** One handled request, as the structured log sees it. */
|
|
288
|
+
type RequestLog$1 = {
|
|
289
|
+
service: string;
|
|
290
|
+
namespace: string;
|
|
291
|
+
operationId: string | undefined;
|
|
292
|
+
method: string;
|
|
293
|
+
path: string;
|
|
294
|
+
status: number;
|
|
295
|
+
durationMs: number;
|
|
296
|
+
/** True when the path matched no operation in the contract. */
|
|
297
|
+
unmatched: boolean;
|
|
298
|
+
/** Set when a fault rule produced the response. */
|
|
299
|
+
faultId?: string;
|
|
300
|
+
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
301
|
+
ids?: Record<string, string>;
|
|
302
|
+
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
303
|
+
adopted?: boolean;
|
|
304
|
+
/** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
|
|
305
|
+
request?: RejectedRequest$1;
|
|
306
|
+
/** The validation issues behind a rejection, when the service found any. */
|
|
307
|
+
issues?: BodyIssue$1[];
|
|
308
|
+
};
|
|
309
|
+
type MetricsReport$1 = {
|
|
310
|
+
requests: number;
|
|
311
|
+
/** Counts keyed `<operationId> <status>`. */
|
|
312
|
+
byOperation: Record<string, number>;
|
|
313
|
+
/**
|
|
314
|
+
* Paths that matched no operation, most frequent first.
|
|
315
|
+
*
|
|
316
|
+
* This is the early-warning signal: a consumer calling something the mock does
|
|
317
|
+
* not implement shows up here as a count, before it fails a suite as a 404.
|
|
318
|
+
*/
|
|
319
|
+
unmatched: {
|
|
320
|
+
method: string;
|
|
321
|
+
path: string;
|
|
322
|
+
count: number;
|
|
323
|
+
}[];
|
|
324
|
+
faults: number;
|
|
325
|
+
totalDurationMs: number;
|
|
326
|
+
};
|
|
327
|
+
type Metrics$1 = {
|
|
328
|
+
record(entry: RequestLog$1): void;
|
|
329
|
+
report(): MetricsReport$1;
|
|
330
|
+
reset(): void;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
334
|
+
type JournalEntry$1 = RequestLog$1 & {
|
|
335
|
+
at: string;
|
|
336
|
+
};
|
|
337
|
+
type JournalQuery$1 = {
|
|
338
|
+
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
339
|
+
namespace?: string;
|
|
340
|
+
operationId?: string;
|
|
341
|
+
status?: number;
|
|
342
|
+
/** Only entries at or after this instant (epoch ms). */
|
|
343
|
+
since?: number;
|
|
344
|
+
/** At most this many, the most recent kept. */
|
|
345
|
+
limit?: number;
|
|
346
|
+
};
|
|
347
|
+
type Journal$1 = {
|
|
348
|
+
readonly size: number;
|
|
349
|
+
record(entry: JournalEntry$1): void;
|
|
350
|
+
list(query?: JournalQuery$1): JournalEntry$1[];
|
|
351
|
+
/** Forget one namespace's entries, or every namespace's. */
|
|
352
|
+
clear(namespace?: string): void;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
356
|
+
type CredentialRegistry$1 = {
|
|
357
|
+
set(credential: string, namespace: string): void;
|
|
358
|
+
get(credential: string): string | undefined;
|
|
359
|
+
remove(credential: string): boolean;
|
|
360
|
+
clear(): void;
|
|
361
|
+
entries(): {
|
|
362
|
+
credential: string;
|
|
363
|
+
namespace: string;
|
|
364
|
+
}[];
|
|
365
|
+
};
|
|
366
|
+
|
|
339
367
|
/**
|
|
340
368
|
* A point-in-time copy of everything a service namespace holds.
|
|
341
369
|
*
|
|
@@ -728,81 +756,95 @@ type FaultRegistry = {
|
|
|
728
756
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
729
757
|
};
|
|
730
758
|
|
|
731
|
-
/**
|
|
732
|
-
type
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
type MetricsReport = {
|
|
750
|
-
requests: number;
|
|
751
|
-
/** Counts keyed `<operationId> <status>`. */
|
|
752
|
-
byOperation: Record<string, number>;
|
|
753
|
-
/**
|
|
754
|
-
* Paths that matched no operation, most frequent first.
|
|
755
|
-
*
|
|
756
|
-
* This is the early-warning signal: a consumer calling something the mock does
|
|
757
|
-
* not implement shows up here as a count, before it fails a suite as a 404.
|
|
758
|
-
*/
|
|
759
|
-
unmatched: {
|
|
760
|
-
method: string;
|
|
761
|
-
path: string;
|
|
762
|
-
count: number;
|
|
763
|
-
}[];
|
|
764
|
-
faults: number;
|
|
765
|
-
totalDurationMs: number;
|
|
766
|
-
};
|
|
767
|
-
type Metrics = {
|
|
768
|
-
record(entry: RequestLog): void;
|
|
769
|
-
report(): MetricsReport;
|
|
770
|
-
reset(): void;
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
774
|
-
type JournalEntry = RequestLog & {
|
|
775
|
-
at: string;
|
|
776
|
-
};
|
|
777
|
-
type JournalQuery = {
|
|
778
|
-
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
779
|
-
namespace?: string;
|
|
780
|
-
operationId?: string;
|
|
781
|
-
status?: number;
|
|
782
|
-
/** Only entries at or after this instant (epoch ms). */
|
|
783
|
-
since?: number;
|
|
784
|
-
/** At most this many, the most recent kept. */
|
|
785
|
-
limit?: number;
|
|
759
|
+
/** A stable identifier for a point in a {@link Timeline}. */
|
|
760
|
+
type CheckpointId = string;
|
|
761
|
+
/** An immutable node in a timeline's checkpoint DAG. */
|
|
762
|
+
type Checkpoint<T> = Readonly<{
|
|
763
|
+
id: CheckpointId;
|
|
764
|
+
branch: string;
|
|
765
|
+
parent: CheckpointId | null;
|
|
766
|
+
/** Logical time supplied by the timeline's injected clock. */
|
|
767
|
+
at: number;
|
|
768
|
+
value: T;
|
|
769
|
+
}>;
|
|
770
|
+
type TimelineOptions = {
|
|
771
|
+
/** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
|
|
772
|
+
now?: () => number;
|
|
773
|
+
/** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
|
|
774
|
+
maxCheckpoints?: number;
|
|
775
|
+
/** Customize deterministic checkpoint IDs. */
|
|
776
|
+
id?: (sequence: number) => CheckpointId;
|
|
786
777
|
};
|
|
787
|
-
type
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
/** Forget one namespace's entries, or every namespace's. */
|
|
792
|
-
clear(namespace?: string): void;
|
|
778
|
+
type CommitOptions = {
|
|
779
|
+
branch?: string;
|
|
780
|
+
/** Parent checkpoint. Defaults to the selected branch's current head. */
|
|
781
|
+
parent?: CheckpointId | null;
|
|
793
782
|
};
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
|
|
797
|
-
set(credential: string, namespace: string): void;
|
|
798
|
-
get(credential: string): string | undefined;
|
|
799
|
-
remove(credential: string): boolean;
|
|
800
|
-
clear(): void;
|
|
801
|
-
entries(): {
|
|
802
|
-
credential: string;
|
|
803
|
-
namespace: string;
|
|
804
|
-
}[];
|
|
783
|
+
type ForkOptions = {
|
|
784
|
+
/** Checkpoint to fork from. Defaults to the main branch's head. */
|
|
785
|
+
from?: CheckpointId;
|
|
805
786
|
};
|
|
787
|
+
/**
|
|
788
|
+
* Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
|
|
789
|
+
* records, namespace images, or copy-on-write SQL engine snapshots.
|
|
790
|
+
*
|
|
791
|
+
* Values are retained by reference. Engines can therefore use persistent/COW snapshots while
|
|
792
|
+
* simpler services can use immutable values. IDs and GC order are deterministic, and all IO
|
|
793
|
+
* (the logical clock) is injected.
|
|
794
|
+
*/
|
|
795
|
+
declare class Timeline<T> {
|
|
796
|
+
readonly maxCheckpoints: number;
|
|
797
|
+
private readonly now;
|
|
798
|
+
private readonly makeId;
|
|
799
|
+
private readonly nodes;
|
|
800
|
+
private readonly heads;
|
|
801
|
+
/** Unreferenced nodes in the exact order they became collectible. */
|
|
802
|
+
private readonly evictable;
|
|
803
|
+
/** Branch heads plus explicit retainers. Absent means zero. */
|
|
804
|
+
private readonly references;
|
|
805
|
+
private readonly explicitPins;
|
|
806
|
+
private sequence;
|
|
807
|
+
constructor(options?: TimelineOptions);
|
|
808
|
+
/** Capture a new immutable value and move `branch` to it. */
|
|
809
|
+
commit(value: T, options?: CommitOptions): Checkpoint<T>;
|
|
810
|
+
/** Create a branch pointer without copying its checkpoint value. */
|
|
811
|
+
fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
|
|
812
|
+
/** Move a branch pointer to an existing checkpoint. */
|
|
813
|
+
checkout(branch: string, id: CheckpointId): Checkpoint<T>;
|
|
814
|
+
get(id: CheckpointId): Checkpoint<T>;
|
|
815
|
+
head(branch?: string): Checkpoint<T> | undefined;
|
|
816
|
+
hasBranch(branch: string): boolean;
|
|
817
|
+
branches(): Readonly<Record<string, CheckpointId>>;
|
|
818
|
+
checkpoints(): readonly Checkpoint<T>[];
|
|
819
|
+
/** Number of retained checkpoints without allocating an array. */
|
|
820
|
+
get size(): number;
|
|
821
|
+
/** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
|
|
822
|
+
retain(id: CheckpointId): Checkpoint<T>;
|
|
823
|
+
/** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
|
|
824
|
+
release(id: CheckpointId): boolean;
|
|
825
|
+
deleteBranch(branch: string): boolean;
|
|
826
|
+
/**
|
|
827
|
+
* Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
|
|
828
|
+
* commits never scan pinned nodes or the retained history. Parents are metadata rather than a
|
|
829
|
+
* storage dependency, so a retained node remains usable after pruning.
|
|
830
|
+
*/
|
|
831
|
+
gc(max?: number): CheckpointId[];
|
|
832
|
+
private collect;
|
|
833
|
+
private moveHead;
|
|
834
|
+
private addReference;
|
|
835
|
+
private removeReference;
|
|
836
|
+
private assertBranch;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Anything that can answer a Fetch `Request` with a `Response`.
|
|
841
|
+
*
|
|
842
|
+
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
843
|
+
* It is the only contract shared across the whole graph.
|
|
844
|
+
*/
|
|
845
|
+
interface FetchAPI$1 {
|
|
846
|
+
fetch(request: Request): Promise<Response>;
|
|
847
|
+
}
|
|
806
848
|
|
|
807
849
|
type DecodedBody = {
|
|
808
850
|
kind: "empty";
|
|
@@ -1021,106 +1063,150 @@ type Operation = {
|
|
|
1021
1063
|
responses: Record<string, ResponseObject>;
|
|
1022
1064
|
};
|
|
1023
1065
|
|
|
1024
|
-
/**
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
private readonly sqlite;
|
|
1030
|
-
private readonly namespace;
|
|
1031
|
-
private readonly salt;
|
|
1032
|
-
constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
|
|
1033
|
-
next(prefix: string, length?: number): string;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
/** A stable identifier for a point in a {@link Timeline}. */
|
|
1037
|
-
type CheckpointId = string;
|
|
1038
|
-
/** An immutable node in a timeline's checkpoint DAG. */
|
|
1039
|
-
type Checkpoint<T> = Readonly<{
|
|
1040
|
-
id: CheckpointId;
|
|
1041
|
-
branch: string;
|
|
1042
|
-
parent: CheckpointId | null;
|
|
1043
|
-
/** Logical time supplied by the timeline's injected clock. */
|
|
1044
|
-
at: number;
|
|
1045
|
-
value: T;
|
|
1046
|
-
}>;
|
|
1047
|
-
type TimelineOptions = {
|
|
1048
|
-
/** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
|
|
1066
|
+
/** Options every provider constructor accepts. */
|
|
1067
|
+
type APIOptions = {
|
|
1068
|
+
/** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
|
|
1069
|
+
sqlite?: SqliteClient$1;
|
|
1070
|
+
/** Clock used for `created`-style fields. Default `Date.now`. */
|
|
1049
1071
|
now?: () => number;
|
|
1050
|
-
/**
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1072
|
+
/**
|
|
1073
|
+
* Storage namespace for this instance's records. Instances sharing one SQLite
|
|
1074
|
+
* client stay isolated when their namespaces differ. Defaults to the service name.
|
|
1075
|
+
*/
|
|
1076
|
+
namespace?: string;
|
|
1054
1077
|
};
|
|
1055
|
-
type
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1078
|
+
type OperationContext = {
|
|
1079
|
+
request: Request;
|
|
1080
|
+
url: URL;
|
|
1081
|
+
/** Path parameters. */
|
|
1082
|
+
params: Record<string, string>;
|
|
1083
|
+
/** Query string decoded with bracket notation (`created[gte]=1` -> `{ created: { gte: "1" } }`). */
|
|
1084
|
+
query: FormObject;
|
|
1085
|
+
body: DecodedBody;
|
|
1086
|
+
/** Shared SQLite client for this service (already migrated). */
|
|
1087
|
+
sqlite: SqliteClient$1;
|
|
1088
|
+
/** Service namespace used for records / sequences. */
|
|
1089
|
+
namespace: string;
|
|
1090
|
+
operation: Operation;
|
|
1091
|
+
/** The vendor contract the service was built from. */
|
|
1092
|
+
document: OpenAPIDocument;
|
|
1093
|
+
now: () => number;
|
|
1059
1094
|
};
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1095
|
+
|
|
1096
|
+
/**
|
|
1097
|
+
* One problem with a request body, at a dotted path (`patient.address.city`, `items.0.sku`).
|
|
1098
|
+
* `kind` is `media_type` when the body is present but its media type is not one the operation
|
|
1099
|
+
* accepts (a `415` on most vendors), `syntax` when it could not be decoded, `required` when
|
|
1100
|
+
* the operation needs a body and none arrived, and `schema` for a contract violation.
|
|
1101
|
+
*/
|
|
1102
|
+
type BodyIssue = {
|
|
1103
|
+
path: string;
|
|
1104
|
+
message: string;
|
|
1105
|
+
kind?: "media_type" | "syntax" | "required" | "schema";
|
|
1063
1106
|
};
|
|
1107
|
+
|
|
1064
1108
|
/**
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
* Values are retained by reference. Engines can therefore use persistent/COW snapshots while
|
|
1069
|
-
* simpler services can use immutable values. IDs and GC order are deterministic, and all IO
|
|
1070
|
-
* (the logical clock) is injected.
|
|
1109
|
+
* What the mock received from a request it rejected, so a 4xx can be attributed after the
|
|
1110
|
+
* fact (an empty body, a missing `content-type`, a schema violation) without logging the body.
|
|
1071
1111
|
*/
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
/**
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1112
|
+
type RejectedRequest = {
|
|
1113
|
+
/** The raw `content-type` header, or `null` when the request sent none. */
|
|
1114
|
+
contentType: string | null;
|
|
1115
|
+
/** Bytes of body received from `content-length` (`0` for none), or `null` when the client sent no length (a streamed / chunked body). */
|
|
1116
|
+
bodyBytes: number | null;
|
|
1117
|
+
/** The raw `transfer-encoding` header (`chunked`), or `null`. */
|
|
1118
|
+
transferEncoding: string | null;
|
|
1119
|
+
};
|
|
1120
|
+
/** One handled request, as the structured log sees it. */
|
|
1121
|
+
type RequestLog = {
|
|
1122
|
+
service: string;
|
|
1123
|
+
namespace: string;
|
|
1124
|
+
operationId: string | undefined;
|
|
1125
|
+
method: string;
|
|
1126
|
+
path: string;
|
|
1127
|
+
status: number;
|
|
1128
|
+
durationMs: number;
|
|
1129
|
+
/** True when the path matched no operation in the contract. */
|
|
1130
|
+
unmatched: boolean;
|
|
1131
|
+
/** Set when a fault rule produced the response. */
|
|
1132
|
+
faultId?: string;
|
|
1133
|
+
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
1134
|
+
ids?: Record<string, string>;
|
|
1135
|
+
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
1136
|
+
adopted?: boolean;
|
|
1137
|
+
/** Set on a rejection (status ≥ 400) the mock produced itself, never on a scripted fault. */
|
|
1138
|
+
request?: RejectedRequest;
|
|
1139
|
+
/** The validation issues behind a rejection, when the service found any. */
|
|
1140
|
+
issues?: BodyIssue[];
|
|
1141
|
+
};
|
|
1142
|
+
type MetricsReport = {
|
|
1143
|
+
requests: number;
|
|
1144
|
+
/** Counts keyed `<operationId> <status>`. */
|
|
1145
|
+
byOperation: Record<string, number>;
|
|
1103
1146
|
/**
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1147
|
+
* Paths that matched no operation, most frequent first.
|
|
1148
|
+
*
|
|
1149
|
+
* This is the early-warning signal: a consumer calling something the mock does
|
|
1150
|
+
* not implement shows up here as a count, before it fails a suite as a 404.
|
|
1107
1151
|
*/
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1152
|
+
unmatched: {
|
|
1153
|
+
method: string;
|
|
1154
|
+
path: string;
|
|
1155
|
+
count: number;
|
|
1156
|
+
}[];
|
|
1157
|
+
faults: number;
|
|
1158
|
+
totalDurationMs: number;
|
|
1159
|
+
};
|
|
1160
|
+
type Metrics = {
|
|
1161
|
+
record(entry: RequestLog): void;
|
|
1162
|
+
report(): MetricsReport;
|
|
1163
|
+
reset(): void;
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
1167
|
+
type JournalEntry = RequestLog & {
|
|
1168
|
+
at: string;
|
|
1169
|
+
};
|
|
1170
|
+
type JournalQuery = {
|
|
1171
|
+
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
1172
|
+
namespace?: string;
|
|
1173
|
+
operationId?: string;
|
|
1174
|
+
status?: number;
|
|
1175
|
+
/** Only entries at or after this instant (epoch ms). */
|
|
1176
|
+
since?: number;
|
|
1177
|
+
/** At most this many, the most recent kept. */
|
|
1178
|
+
limit?: number;
|
|
1179
|
+
};
|
|
1180
|
+
type Journal = {
|
|
1181
|
+
readonly size: number;
|
|
1182
|
+
record(entry: JournalEntry): void;
|
|
1183
|
+
list(query?: JournalQuery): JournalEntry[];
|
|
1184
|
+
/** Forget one namespace's entries, or every namespace's. */
|
|
1185
|
+
clear(namespace?: string): void;
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
1189
|
+
type CredentialRegistry = {
|
|
1190
|
+
set(credential: string, namespace: string): void;
|
|
1191
|
+
get(credential: string): string | undefined;
|
|
1192
|
+
remove(credential: string): boolean;
|
|
1193
|
+
clear(): void;
|
|
1194
|
+
entries(): {
|
|
1195
|
+
credential: string;
|
|
1196
|
+
namespace: string;
|
|
1197
|
+
}[];
|
|
1198
|
+
};
|
|
1115
1199
|
|
|
1116
1200
|
/**
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
1120
|
-
* It is the only contract shared across the whole graph.
|
|
1201
|
+
* Sequential id source persisted in SQLite. Ids are deterministic for a given
|
|
1202
|
+
* sequence history (`cus_` + 14 opaque chars), so reproductions stay stable.
|
|
1121
1203
|
*/
|
|
1122
|
-
|
|
1123
|
-
|
|
1204
|
+
declare class IdSequence {
|
|
1205
|
+
private readonly sqlite;
|
|
1206
|
+
private readonly namespace;
|
|
1207
|
+
private readonly salt;
|
|
1208
|
+
constructor(sqlite: SqliteClient$1, namespace: string, salt?: string);
|
|
1209
|
+
next(prefix: string, length?: number): string;
|
|
1124
1210
|
}
|
|
1125
1211
|
|
|
1126
1212
|
/**
|
|
@@ -1273,36 +1359,6 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
1273
1359
|
timeline(namespace?: string): Timeline<ServiceTimelineState>;
|
|
1274
1360
|
};
|
|
1275
1361
|
|
|
1276
|
-
/** Options every provider constructor accepts. */
|
|
1277
|
-
type APIOptions = {
|
|
1278
|
-
/** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
|
|
1279
|
-
sqlite?: SqliteClient$1;
|
|
1280
|
-
/** Clock used for `created`-style fields. Default `Date.now`. */
|
|
1281
|
-
now?: () => number;
|
|
1282
|
-
/**
|
|
1283
|
-
* Storage namespace for this instance's records. Instances sharing one SQLite
|
|
1284
|
-
* client stay isolated when their namespaces differ. Defaults to the service name.
|
|
1285
|
-
*/
|
|
1286
|
-
namespace?: string;
|
|
1287
|
-
};
|
|
1288
|
-
type OperationContext = {
|
|
1289
|
-
request: Request;
|
|
1290
|
-
url: URL;
|
|
1291
|
-
/** Path parameters. */
|
|
1292
|
-
params: Record<string, string>;
|
|
1293
|
-
/** Query string decoded with bracket notation (`created[gte]=1` -> `{ created: { gte: "1" } }`). */
|
|
1294
|
-
query: FormObject;
|
|
1295
|
-
body: DecodedBody;
|
|
1296
|
-
/** Shared SQLite client for this service (already migrated). */
|
|
1297
|
-
sqlite: SqliteClient$1;
|
|
1298
|
-
/** Service namespace used for records / sequences. */
|
|
1299
|
-
namespace: string;
|
|
1300
|
-
operation: Operation;
|
|
1301
|
-
/** The vendor contract the service was built from. */
|
|
1302
|
-
document: OpenAPIDocument;
|
|
1303
|
-
now: () => number;
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
1362
|
/** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
|
|
1307
1363
|
type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
|
|
1308
1364
|
/** Mutation counters returned by {@link SqliteStatement.run}. */
|
|
@@ -1342,14 +1398,20 @@ interface FetchAPI {
|
|
|
1342
1398
|
fetch(request: Request): Promise<Response>;
|
|
1343
1399
|
}
|
|
1344
1400
|
|
|
1345
|
-
/** A survey definition, passed through as Formbricks serves it (blocks, elements,
|
|
1401
|
+
/** A survey definition, passed through as Formbricks serves it (blocks, elements, endings, …). */
|
|
1346
1402
|
type Survey = Record<string, unknown> & {
|
|
1347
1403
|
id: string;
|
|
1348
1404
|
name: string;
|
|
1349
1405
|
type: string;
|
|
1350
1406
|
status: string;
|
|
1351
|
-
/** `null` for the shared
|
|
1352
|
-
|
|
1407
|
+
/** `null` for the shared corpus surveys, which every configured workspace serves. */
|
|
1408
|
+
workspaceId?: string | null;
|
|
1409
|
+
};
|
|
1410
|
+
/** A contact (`PUT /__admin/contacts`); `attributes.userId` becomes the response's `contact.userId`. */
|
|
1411
|
+
type Contact = {
|
|
1412
|
+
id: string;
|
|
1413
|
+
workspaceId: string | null;
|
|
1414
|
+
attributes: Record<string, string>;
|
|
1353
1415
|
};
|
|
1354
1416
|
/** One stored response, in Formbricks' `TResponse` shape. */
|
|
1355
1417
|
type ResponseRecord = {
|
|
@@ -1357,11 +1419,11 @@ type ResponseRecord = {
|
|
|
1357
1419
|
createdAt: string;
|
|
1358
1420
|
updatedAt: string;
|
|
1359
1421
|
surveyId: string;
|
|
1360
|
-
|
|
1422
|
+
workspaceId: string;
|
|
1361
1423
|
displayId: string | null;
|
|
1362
1424
|
contact: {
|
|
1363
1425
|
id: string;
|
|
1364
|
-
userId
|
|
1426
|
+
userId?: string;
|
|
1365
1427
|
} | null;
|
|
1366
1428
|
contactAttributes: Record<string, string> | null;
|
|
1367
1429
|
finished: boolean;
|
|
@@ -1376,24 +1438,22 @@ type ResponseRecord = {
|
|
|
1376
1438
|
};
|
|
1377
1439
|
/** Per-namespace knobs, set through `PUT /__admin/settings`; cleared on reset. */
|
|
1378
1440
|
type Settings = {
|
|
1379
|
-
/**
|
|
1380
|
-
|
|
1441
|
+
/** Workspace ids that exist and serve the shared corpus surveys. */
|
|
1442
|
+
workspaces: string[];
|
|
1443
|
+
/** Pre-Formbricks-5 environment ids, each an alias of a workspace (`{envId: workspaceId}`). */
|
|
1444
|
+
legacyEnvironmentIds: Record<string, string>;
|
|
1381
1445
|
/** Accepted management API keys; empty means any non-empty `x-api-key` works. */
|
|
1382
1446
|
apiKeys: string[];
|
|
1383
1447
|
/** The `webhookId` put in webhook bodies. */
|
|
1384
1448
|
webhookId: string;
|
|
1385
|
-
/**
|
|
1449
|
+
/** Contacts are an Enterprise feature: when off, a response with a `contactId` is 403. */
|
|
1386
1450
|
contactsEnabled: boolean;
|
|
1387
1451
|
};
|
|
1388
1452
|
declare class FormbricksState {
|
|
1389
1453
|
private readonly seed;
|
|
1390
1454
|
readonly surveys: Collection<Survey>;
|
|
1391
1455
|
readonly responses: Collection<ResponseRecord>;
|
|
1392
|
-
readonly contacts: Collection<
|
|
1393
|
-
id: string;
|
|
1394
|
-
environmentId: string;
|
|
1395
|
-
userId: string;
|
|
1396
|
-
}>;
|
|
1456
|
+
readonly contacts: Collection<Contact>;
|
|
1397
1457
|
readonly settings: Collection<Settings>;
|
|
1398
1458
|
readonly ids: IdSequence;
|
|
1399
1459
|
constructor(sqlite: SqliteClient, namespace: string, seed: {
|
|
@@ -1405,22 +1465,25 @@ declare class FormbricksState {
|
|
|
1405
1465
|
update(patch: Partial<Settings>): Settings;
|
|
1406
1466
|
/** Formbricks ids are cuid2: lower-case alphanumerics starting with a letter, 25 long. */
|
|
1407
1467
|
nextId(): string;
|
|
1408
|
-
|
|
1468
|
+
/**
|
|
1469
|
+
* `resolveClientApiIds`: a workspace id, or a legacy environment id, to its workspace id
|
|
1470
|
+
* (`undefined` when neither is known).
|
|
1471
|
+
*/
|
|
1472
|
+
resolveWorkspace(id: string): string | undefined;
|
|
1473
|
+
/** The v1 `environmentId` of a workspace: its legacy environment id, else its own id. */
|
|
1474
|
+
legacyEnvironmentId(workspaceId: string): string;
|
|
1409
1475
|
allSurveys(): Survey[];
|
|
1410
|
-
/** Surveys
|
|
1411
|
-
surveysOf(
|
|
1412
|
-
/** Whether a survey belongs to
|
|
1413
|
-
belongsTo(survey: Survey,
|
|
1414
|
-
/**
|
|
1415
|
-
|
|
1416
|
-
id: string;
|
|
1417
|
-
userId: string;
|
|
1418
|
-
};
|
|
1476
|
+
/** Surveys a workspace serves: its own, plus the shared corpus when it is configured. */
|
|
1477
|
+
surveysOf(workspaceId: string): Survey[];
|
|
1478
|
+
/** Whether a survey belongs to a workspace (`survey.workspaceId !== workspaceId` check). */
|
|
1479
|
+
belongsTo(survey: Survey, workspaceId: string): boolean;
|
|
1480
|
+
/** `getContact(contactId, workspaceId)`: a contact of that workspace (or a shared one). */
|
|
1481
|
+
contactOf(contactId: string, workspaceId: string): Contact | undefined;
|
|
1419
1482
|
}
|
|
1420
1483
|
|
|
1421
1484
|
/** The response as the API (and the webhook) renders it: `TResponse`. */
|
|
1422
|
-
type ApiResponse = Omit<ResponseRecord, "
|
|
1423
|
-
/** The body Formbricks' pipeline posts to a webhook (`
|
|
1485
|
+
type ApiResponse = Omit<ResponseRecord, "workspaceId">;
|
|
1486
|
+
/** The body Formbricks' response pipeline posts to a webhook (`process-response-pipeline-job.ts`). */
|
|
1424
1487
|
type FormbricksWebhook = {
|
|
1425
1488
|
webhookId: string;
|
|
1426
1489
|
event: "responseCreated" | "responseFinished";
|
|
@@ -1435,15 +1498,15 @@ type FormbricksWebhook = {
|
|
|
1435
1498
|
};
|
|
1436
1499
|
};
|
|
1437
1500
|
type FormbricksAPIOptions = APIOptions & {
|
|
1438
|
-
/** Surveys every namespace starts with. Default:
|
|
1501
|
+
/** Surveys every namespace starts with. Default: the synthetic corpus (`CORPUS_SURVEYS`). */
|
|
1439
1502
|
surveys?: readonly Survey[];
|
|
1440
1503
|
settings?: Partial<Settings>;
|
|
1441
1504
|
/** Called for every pipeline event; the runtime signs and delivers it. */
|
|
1442
1505
|
onWebhook?: (event: FormbricksWebhook) => void;
|
|
1443
1506
|
};
|
|
1444
1507
|
/**
|
|
1445
|
-
* Stateful mock of Formbricks
|
|
1446
|
-
*
|
|
1508
|
+
* Stateful mock of open-source Formbricks: the client environment state and response creation
|
|
1509
|
+
* the JS SDK uses, the v1 management API, and the response pipeline's webhooks.
|
|
1447
1510
|
*/
|
|
1448
1511
|
declare class FormbricksAPI implements FetchAPI {
|
|
1449
1512
|
readonly app: Hono;
|
|
@@ -1456,14 +1519,20 @@ declare class FormbricksAPI implements FetchAPI {
|
|
|
1456
1519
|
fetch(request: Request): Promise<Response>;
|
|
1457
1520
|
reset(): Promise<void>;
|
|
1458
1521
|
private iso;
|
|
1459
|
-
/**
|
|
1460
|
-
|
|
1522
|
+
/**
|
|
1523
|
+
* A survey as the v1 management API serves it: `questions` derived from `blocks`, the owning
|
|
1524
|
+
* `workspaceId` and its legacy `environmentId`, and `projectOverwrites`. Shared corpus surveys
|
|
1525
|
+
* are reported under the first configured workspace.
|
|
1526
|
+
*/
|
|
1527
|
+
wireSurvey(survey: Survey): Survey;
|
|
1461
1528
|
render(record: ResponseRecord, context?: OperationContext): ApiResponse;
|
|
1462
1529
|
private environmentState;
|
|
1463
1530
|
private createResponse;
|
|
1464
|
-
/** Emit a pipeline event for a stored response
|
|
1531
|
+
/** Emit a pipeline event (`responseCreated` / `responseFinished`) for a stored response. */
|
|
1465
1532
|
pipeline(event: FormbricksWebhook["event"], record: ResponseRecord, survey: Survey): void;
|
|
1466
1533
|
private listResponses;
|
|
1534
|
+
/** `getSurveys(workspaceIds, limit, offset)`: newest `updatedAt` first. */
|
|
1535
|
+
private listSurveys;
|
|
1467
1536
|
private createSurvey;
|
|
1468
1537
|
responses(): ApiResponse[];
|
|
1469
1538
|
}
|
|
@@ -1481,8 +1550,8 @@ type FormbricksRuntimeOptions = {
|
|
|
1481
1550
|
surveys?: readonly Survey[];
|
|
1482
1551
|
settings?: Partial<Settings>;
|
|
1483
1552
|
/**
|
|
1484
|
-
* Where webhooks go: `url`
|
|
1485
|
-
* `whsec_…` Standard Webhooks key) signs `webhook-signature`; `events` defaults to
|
|
1553
|
+
* Where webhooks go: `url` (any query, e.g. a `?token=` your receiver checks, is kept); `secret`
|
|
1554
|
+
* (a `whsec_…` Standard Webhooks key) signs `webhook-signature`; `events` defaults to
|
|
1486
1555
|
* `["responseFinished"]` (add `"responseCreated"` for both).
|
|
1487
1556
|
*/
|
|
1488
1557
|
webhooks?: Omit<WebhookEndpoint, "id"> & WebhookHubOptionsSubset;
|