@crvouga/mockingbird-service-formbricks 1.0.0 → 1.0.2
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 +13 -4
- package/dist/{chunk-RITQFAWR.js → chunk-KO4C5CAN.js} +5 -3
- package/dist/chunk-KO4C5CAN.js.map +7 -0
- package/dist/{chunk-ZFDC3GHV.js → chunk-R2IPDPFY.js} +23 -6
- package/dist/chunk-R2IPDPFY.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +218 -190
- package/dist/index.js +1 -1
- package/dist/server.d.ts +323 -267
- package/dist/server.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-RITQFAWR.js.map +0 -7
- package/dist/chunk-ZFDC3GHV.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;
|
|
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;
|
|
776
777
|
};
|
|
777
|
-
type
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
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;
|
|
778
|
+
type CommitOptions = {
|
|
779
|
+
branch?: string;
|
|
780
|
+
/** Parent checkpoint. Defaults to the selected branch's current head. */
|
|
781
|
+
parent?: CheckpointId | null;
|
|
786
782
|
};
|
|
787
|
-
type
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
list(query?: JournalQuery): JournalEntry[];
|
|
791
|
-
/** Forget one namespace's entries, or every namespace's. */
|
|
792
|
-
clear(namespace?: string): void;
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
796
|
-
type CredentialRegistry = {
|
|
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}. */
|
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crvouga/mockingbird-service-formbricks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Stateful mock of open-source Formbricks: the client environment state (seeded with a synthetic survey corpus), response creation with upstream's validation and {code, message, details} errors, the v1 management API, the widget script, and signed response webhooks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|