@crvouga/mockingbird-service-formbricks 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  runCli,
4
4
  serveCommand,
5
5
  serveTarget
6
- } from "./chunk-D6GS7TTF.js";
7
- import "./chunk-PISQJCVW.js";
6
+ } from "./chunk-CEGOD5GL.js";
7
+ import "./chunk-JEV2BAL7.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -219,6 +219,15 @@ type FaultCandidate = {
219
219
  namespace: string;
220
220
  };
221
221
  type FaultRegistry = {
222
+ isolateNamespaces(): void;
223
+ snapshot(namespace: string): {
224
+ rules: (FaultRule & {
225
+ remaining: number | null;
226
+ hits: number;
227
+ position: number;
228
+ })[];
229
+ rngState: number;
230
+ };
222
231
  add(rule: FaultRule): FaultRule;
223
232
  list(): (FaultRule & {
224
233
  remaining: number | null;
@@ -226,6 +235,14 @@ type FaultRegistry = {
226
235
  })[];
227
236
  remove(id: string): boolean;
228
237
  clear(): void;
238
+ restore(namespace: string, state: {
239
+ rules: (FaultRule & {
240
+ remaining: number | null;
241
+ hits: number;
242
+ position: number;
243
+ })[];
244
+ rngState: number;
245
+ }): void;
229
246
  /**
230
247
  * Every fault this request should get, in rule order, stopping at the first that answers
231
248
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
@@ -637,8 +654,8 @@ type MetricsReport = {
637
654
  };
638
655
  type Metrics = {
639
656
  record(entry: RequestLog): void;
640
- report(): MetricsReport;
641
- reset(): void;
657
+ report(namespace?: string): MetricsReport;
658
+ reset(namespace?: string): void;
642
659
  };
643
660
 
644
661
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -804,6 +821,9 @@ type PublishInput = {
804
821
  id?: string;
805
822
  };
806
823
  type WebhookHub = {
824
+ pending(namespace: string): number;
825
+ snapshot(namespace: string): unknown;
826
+ restore(namespace: string, snapshot: unknown): void;
807
827
  publish(input: PublishInput): WebhookMessage;
808
828
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
809
829
  setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
@@ -831,6 +851,8 @@ type ServiceTimelineState = Readonly<{
831
851
  }>;
832
852
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
833
853
  type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
854
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
855
+ stop?(): void;
834
856
  readonly name: string;
835
857
  readonly sqlite: SqliteClient$1;
836
858
  readonly clock: Clock;
@@ -841,6 +863,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
841
863
  readonly credentials: CredentialRegistry;
842
864
  /** The webhook hub, when the service has outbound webhooks. */
843
865
  readonly webhooks: WebhookHub | undefined;
866
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
867
+ isolateNamespaces(): void;
868
+ namespaceClock(namespace?: string): Clock;
869
+ namespaceOf(request: Request): string;
870
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
871
+ fleetSnapshot(namespace: string): object;
872
+ fleetRestore(snapshot: unknown, namespace: string): void;
844
873
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
845
874
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
846
875
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  operationIds,
15
15
  supportedOperationIds,
16
16
  validateResponseData
17
- } from "./chunk-PISQJCVW.js";
17
+ } from "./chunk-JEV2BAL7.js";
18
18
  export {
19
19
  CORPUS_SURVEYS,
20
20
  DEFAULT_SETTINGS,
package/dist/server.d.ts CHANGED
@@ -155,6 +155,15 @@ type FaultCandidate$1 = {
155
155
  namespace: string;
156
156
  };
157
157
  type FaultRegistry$1 = {
158
+ isolateNamespaces(): void;
159
+ snapshot(namespace: string): {
160
+ rules: (FaultRule$1 & {
161
+ remaining: number | null;
162
+ hits: number;
163
+ position: number;
164
+ })[];
165
+ rngState: number;
166
+ };
158
167
  add(rule: FaultRule$1): FaultRule$1;
159
168
  list(): (FaultRule$1 & {
160
169
  remaining: number | null;
@@ -162,6 +171,14 @@ type FaultRegistry$1 = {
162
171
  })[];
163
172
  remove(id: string): boolean;
164
173
  clear(): void;
174
+ restore(namespace: string, state: {
175
+ rules: (FaultRule$1 & {
176
+ remaining: number | null;
177
+ hits: number;
178
+ position: number;
179
+ })[];
180
+ rngState: number;
181
+ }): void;
165
182
  /**
166
183
  * Every fault this request should get, in rule order, stopping at the first that answers
167
184
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
@@ -326,8 +343,8 @@ type MetricsReport$1 = {
326
343
  };
327
344
  type Metrics$1 = {
328
345
  record(entry: RequestLog$1): void;
329
- report(): MetricsReport$1;
330
- reset(): void;
346
+ report(namespace?: string): MetricsReport$1;
347
+ reset(namespace?: string): void;
331
348
  };
332
349
 
333
350
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -481,6 +498,9 @@ type PublishInput$1 = {
481
498
  id?: string;
482
499
  };
483
500
  type WebhookHub$1 = {
501
+ pending(namespace: string): number;
502
+ snapshot(namespace: string): unknown;
503
+ restore(namespace: string, snapshot: unknown): void;
484
504
  publish(input: PublishInput$1): WebhookMessage$1;
485
505
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
486
506
  setEndpoints(namespace: string, endpoints: WebhookEndpoint$1[]): WebhookEndpoint$1[];
@@ -508,6 +528,8 @@ type ServiceTimelineState$1 = Readonly<{
508
528
  }>;
509
529
  type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
510
530
  type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
531
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
532
+ stop?(): void;
511
533
  readonly name: string;
512
534
  readonly sqlite: SqliteClient$2;
513
535
  readonly clock: Clock$1;
@@ -518,6 +540,13 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
518
540
  readonly credentials: CredentialRegistry$1;
519
541
  /** The webhook hub, when the service has outbound webhooks. */
520
542
  readonly webhooks: WebhookHub$1 | undefined;
543
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
544
+ isolateNamespaces(): void;
545
+ namespaceClock(namespace?: string): Clock$1;
546
+ namespaceOf(request: Request): string;
547
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
548
+ fleetSnapshot(namespace: string): object;
549
+ fleetRestore(snapshot: unknown, namespace: string): void;
521
550
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
522
551
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule$1>): FaultRule$1[];
523
552
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
@@ -781,6 +810,15 @@ type FaultCandidate = {
781
810
  namespace: string;
782
811
  };
783
812
  type FaultRegistry = {
813
+ isolateNamespaces(): void;
814
+ snapshot(namespace: string): {
815
+ rules: (FaultRule & {
816
+ remaining: number | null;
817
+ hits: number;
818
+ position: number;
819
+ })[];
820
+ rngState: number;
821
+ };
784
822
  add(rule: FaultRule): FaultRule;
785
823
  list(): (FaultRule & {
786
824
  remaining: number | null;
@@ -788,6 +826,14 @@ type FaultRegistry = {
788
826
  })[];
789
827
  remove(id: string): boolean;
790
828
  clear(): void;
829
+ restore(namespace: string, state: {
830
+ rules: (FaultRule & {
831
+ remaining: number | null;
832
+ hits: number;
833
+ position: number;
834
+ })[];
835
+ rngState: number;
836
+ }): void;
791
837
  /**
792
838
  * Every fault this request should get, in rule order, stopping at the first that answers
793
839
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
@@ -1199,8 +1245,8 @@ type MetricsReport = {
1199
1245
  };
1200
1246
  type Metrics = {
1201
1247
  record(entry: RequestLog): void;
1202
- report(): MetricsReport;
1203
- reset(): void;
1248
+ report(namespace?: string): MetricsReport;
1249
+ reset(namespace?: string): void;
1204
1250
  };
1205
1251
 
1206
1252
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -1366,6 +1412,9 @@ type PublishInput = {
1366
1412
  id?: string;
1367
1413
  };
1368
1414
  type WebhookHub = {
1415
+ pending(namespace: string): number;
1416
+ snapshot(namespace: string): unknown;
1417
+ restore(namespace: string, snapshot: unknown): void;
1369
1418
  publish(input: PublishInput): WebhookMessage;
1370
1419
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
1371
1420
  setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
@@ -1393,6 +1442,8 @@ type ServiceTimelineState = Readonly<{
1393
1442
  }>;
1394
1443
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
1395
1444
  type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1445
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
1446
+ stop?(): void;
1396
1447
  readonly name: string;
1397
1448
  readonly sqlite: SqliteClient$1;
1398
1449
  readonly clock: Clock;
@@ -1403,6 +1454,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1403
1454
  readonly credentials: CredentialRegistry;
1404
1455
  /** The webhook hub, when the service has outbound webhooks. */
1405
1456
  readonly webhooks: WebhookHub | undefined;
1457
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
1458
+ isolateNamespaces(): void;
1459
+ namespaceClock(namespace?: string): Clock;
1460
+ namespaceOf(request: Request): string;
1461
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
1462
+ fleetSnapshot(namespace: string): object;
1463
+ fleetRestore(snapshot: unknown, namespace: string): void;
1406
1464
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
1407
1465
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
1408
1466
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
package/dist/server.js CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  DEFAULT_PORT,
3
3
  createServer,
4
4
  serveTarget
5
- } from "./chunk-D6GS7TTF.js";
6
- import "./chunk-PISQJCVW.js";
5
+ } from "./chunk-CEGOD5GL.js";
6
+ import "./chunk-JEV2BAL7.js";
7
7
  export {
8
8
  DEFAULT_PORT,
9
9
  createServer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crvouga/mockingbird-service-formbricks",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
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",
@@ -1,371 +0,0 @@
1
- import {
2
- DEFAULT_SETTINGS,
3
- createRuntime
4
- } from "./chunk-PISQJCVW.js";
5
-
6
- // ../../adapters/node/dist/cli.js
7
- import { readFile } from "node:fs/promises";
8
- import { parseArgs } from "node:util";
9
-
10
- // ../../adapters/node/dist/serve.js
11
- import { createServer } from "node:http";
12
- var serve = async (api, options = {}) => {
13
- const server = createServer(async (req, res) => {
14
- const chunks = [];
15
- for await (const chunk of req) {
16
- chunks.push(Buffer.from(chunk));
17
- }
18
- const body = Buffer.concat(chunks);
19
- const address = server.address();
20
- const port = typeof address === "object" && address !== null ? address.port : void 0;
21
- const base = `http://${req.headers.host ?? `localhost:${port ?? 80}`}`;
22
- const raw = req.url ?? "/";
23
- const url = new URL(raw.replace(/^\/+/, "/"), base);
24
- const method = req.method ?? "GET";
25
- const init = { method, headers: req.headers };
26
- if (method !== "GET" && method !== "HEAD" && body.length > 0) {
27
- init.body = body;
28
- }
29
- const aborted = new AbortController();
30
- res.once("close", () => {
31
- if (!res.writableFinished)
32
- aborted.abort();
33
- });
34
- init.signal = aborted.signal;
35
- const request = new Request(url, init);
36
- let response;
37
- try {
38
- response = await api.fetch(request);
39
- } catch (error) {
40
- if (error.code === "MOCKINGBIRD_DROP") {
41
- req.socket.destroy();
42
- return;
43
- }
44
- res.writeHead(500, { "content-type": "application/json" });
45
- res.end(JSON.stringify({
46
- error: {
47
- type: "mockingbird_internal",
48
- message: error instanceof Error ? error.message : String(error)
49
- }
50
- }));
51
- return;
52
- }
53
- const headers = Object.fromEntries(response.headers);
54
- const cookies = response.headers.getSetCookie();
55
- if (cookies.length > 0)
56
- headers["set-cookie"] = cookies;
57
- if (!response.body) {
58
- res.writeHead(response.status, headers);
59
- res.end();
60
- return;
61
- }
62
- res.writeHead(response.status, headers);
63
- res.flushHeaders();
64
- const reader = response.body.getReader();
65
- try {
66
- for (; ; ) {
67
- const { done, value } = await reader.read();
68
- if (done)
69
- break;
70
- if (!res.write(value))
71
- await new Promise((resolve) => res.once("drain", resolve));
72
- }
73
- res.end();
74
- } catch {
75
- res.destroy();
76
- } finally {
77
- reader.releaseLock();
78
- }
79
- });
80
- await new Promise((resolve, reject) => {
81
- server.once("error", reject);
82
- server.listen(options.port ?? 0, options.host, resolve);
83
- });
84
- return server;
85
- };
86
-
87
- // ../../adapters/node/dist/listen.js
88
- var listen = async (api, options = {}) => {
89
- const host = options.host ?? "127.0.0.1";
90
- const server = await serve(api, { port: options.port ?? 0, host });
91
- const address = server.address();
92
- const port = typeof address === "object" && address !== null ? address.port : options.port ?? 0;
93
- const shown = host.includes(":") ? `[${host}]` : host;
94
- return {
95
- url: `http://${shown}:${port}`,
96
- port,
97
- host,
98
- server,
99
- close: () => new Promise((resolve, reject) => {
100
- server.close((error) => {
101
- if (error && error.code !== "ERR_SERVER_NOT_RUNNING")
102
- reject(error);
103
- else
104
- resolve();
105
- });
106
- server.closeAllConnections?.();
107
- })
108
- };
109
- };
110
-
111
- // ../../adapters/node/dist/cli.js
112
- var optionHelp = (options) => Object.entries(options).map(([name, option]) => {
113
- const flag = `--${name}${option.type === "string" ? ` ${option.value ?? "<value>"}` : ""}`;
114
- const fallback = option.default !== void 0 ? ` (default: ${String(option.default)})` : "";
115
- return ` ${flag.padEnd(30)} ${option.description}${fallback}`;
116
- });
117
- var help = (spec) => [
118
- `${spec.bin} \u2014 ${spec.description}`,
119
- "",
120
- "Usage:",
121
- ` ${spec.bin} <command> [options]`,
122
- "",
123
- "Commands:",
124
- ...Object.entries(spec.commands).map(([name, c]) => ` ${name.padEnd(30)} ${c.summary}`),
125
- "",
126
- `Run \`${spec.bin} <command> --help\` for a command's options.`
127
- ].join("\n");
128
- var commandHelp = (spec, name, command) => [
129
- `${spec.bin} ${name} \u2014 ${command.summary}`,
130
- "",
131
- "Usage:",
132
- ` ${command.usage ?? `${spec.bin} ${name} [options]`}`,
133
- ...command.options ? ["", "Options:", ...optionHelp(command.options)] : []
134
- ].join("\n");
135
- var runCli = async (spec, argv) => {
136
- const pair = argv.length >= 2 ? `${argv[0]} ${argv[1]}` : void 0;
137
- const words = pair !== void 0 && spec.commands[pair] ? 2 : 1;
138
- const name = words === 2 ? pair : argv[0];
139
- const rest = argv.slice(words);
140
- if (name === void 0 || name === "--help" || name === "-h" || name === "help") {
141
- console.log(help(spec));
142
- return 0;
143
- }
144
- const command = spec.commands[name];
145
- if (!command) {
146
- console.error(`${spec.bin}: unknown command ${JSON.stringify(name)}
147
-
148
- ${help(spec)}`);
149
- return 2;
150
- }
151
- if (rest.includes("--help") || rest.includes("-h")) {
152
- console.log(commandHelp(spec, name, command));
153
- return 0;
154
- }
155
- let parsed;
156
- try {
157
- parsed = parseArgs({
158
- args: rest,
159
- allowPositionals: true,
160
- strict: true,
161
- options: Object.fromEntries(Object.entries(command.options ?? {}).map(([key, option]) => [
162
- key,
163
- {
164
- type: option.type,
165
- ...option.default !== void 0 ? { default: option.default } : {}
166
- }
167
- ]))
168
- });
169
- } catch (error) {
170
- console.error(`${spec.bin} ${name}: ${error instanceof Error ? error.message : String(error)}
171
-
172
- ${commandHelp(spec, name, command)}`);
173
- return 2;
174
- }
175
- return command.run(parsed.values, parsed.positionals);
176
- };
177
- var COMMON_SERVE_OPTIONS = {
178
- port: { type: "string", value: "<port>", description: "Port to listen on" },
179
- host: { type: "string", value: "<host>", description: "Interface to bind", default: "127.0.0.1" },
180
- "admin-key": {
181
- type: "string",
182
- value: "<key>",
183
- description: "Require x-mockingbird-admin-key on /__admin/* (env MOCKINGBIRD_ADMIN_KEY)"
184
- },
185
- seed: { type: "string", value: "<seed>", description: "Seed for every random choice" },
186
- log: {
187
- type: "string",
188
- value: "<pretty|json|off>",
189
- description: "Request log format",
190
- default: "pretty"
191
- },
192
- "log-requests": {
193
- type: "boolean",
194
- description: "One JSON line per request: namespace, operationId, status, ids touched (never bodies). Same as --log json"
195
- },
196
- config: {
197
- type: "string",
198
- value: "<file>",
199
- description: "Serve every service in a mockingbird.json config instead"
200
- }
201
- };
202
- var formatLog = (format) => {
203
- if (format === "off")
204
- return void 0;
205
- if (format === "json")
206
- return (entry) => console.log(JSON.stringify(entry));
207
- return (entry) => {
208
- const op = entry.operationId ?? (entry.unmatched ? "UNMATCHED" : "-");
209
- const ns = entry.namespace === "default" ? "" : ` [${entry.namespace}]`;
210
- const fault = entry.faultId ? ` fault=${entry.faultId}` : "";
211
- const adopted = entry.adopted ? " adopted" : "";
212
- const received = entry.request ? ` received=${entry.request.bodyBytes === null ? "?" : `${entry.request.bodyBytes}B`} ct=${entry.request.contentType ?? "-"}${entry.request.transferEncoding ? ` te=${entry.request.transferEncoding}` : ""}` : "";
213
- const issues = entry.issues?.length ? ` issues=${entry.issues.slice(0, 3).map((issue) => `${issue.path || "$"}: ${issue.message}`).join("; ")}${entry.issues.length > 3 ? ` (+${entry.issues.length - 3})` : ""}` : "";
214
- console.log(`${entry.service} ${entry.method} ${entry.path} ${entry.status} ${op} ${entry.durationMs}ms${ns}${fault}${adopted}${received}${issues}`);
215
- };
216
- };
217
- var asString = (value) => typeof value === "string" ? value : void 0;
218
- var loadTarget = async (name, own) => {
219
- if (name === own.name)
220
- return own;
221
- const specifier = `@crvouga/mockingbird-service-${name}/server`;
222
- try {
223
- const mod = await import(specifier);
224
- if (!mod.serveTarget)
225
- throw new Error(`${specifier} exports no serveTarget`);
226
- return mod.serveTarget;
227
- } catch (error) {
228
- const reason = error instanceof Error ? error.message : String(error);
229
- throw new Error(`cannot load service "${name}": ${reason}. Install @crvouga/mockingbird-service-${name}.`);
230
- }
231
- };
232
- var start = async (target, values, config) => {
233
- const runtime = await target.create(values, {
234
- adminKey: config.adminKey,
235
- seed: config.seed,
236
- onLog: formatLog(config.log)
237
- });
238
- const listening = await listen(runtime, { port: config.port, host: config.host });
239
- target.listening?.(listening);
240
- console.log(`${target.name} mock listening on ${listening.url}`);
241
- console.log(`${target.name} health: GET ${listening.url}/health`);
242
- console.log(`${target.name} admin: ${listening.url}/__admin (${config.adminKey ? "x-mockingbird-admin-key required" : "open \u2014 pass --admin-key to lock"})`);
243
- console.log(`${target.name} admin ui: ${listening.url}/__admin/ui`);
244
- for (const line of target.banner?.(runtime) ?? [])
245
- console.log(`${target.name} ${line}`);
246
- return listening;
247
- };
248
- var untilSignal = async (servers) => new Promise((resolve) => {
249
- const stop = async () => {
250
- await Promise.allSettled(servers.map((s) => s.close()));
251
- resolve(0);
252
- };
253
- process.once("SIGINT", stop);
254
- process.once("SIGTERM", stop);
255
- });
256
- var serveCommand = (target) => ({
257
- summary: `Serve the ${target.name} mock over HTTP`,
258
- options: { ...COMMON_SERVE_OPTIONS, ...target.options },
259
- async run(values) {
260
- const log = values["log-requests"] === true ? "json" : asString(values.log) ?? "pretty";
261
- if (!["pretty", "json", "off"].includes(log)) {
262
- console.error(`--log must be pretty, json or off (got ${log})`);
263
- return 2;
264
- }
265
- const configPath = asString(values.config);
266
- if (configPath !== void 0) {
267
- const config = JSON.parse(await readFile(configPath, "utf8"));
268
- const servers = [];
269
- try {
270
- for (const [name, entry] of Object.entries(config.services ?? {})) {
271
- const each = await loadTarget(name, target);
272
- servers.push(await start(each, entry.options ?? {}, {
273
- port: entry.port ?? each.defaultPort,
274
- host: entry.host ?? "127.0.0.1",
275
- ...entry.adminKey !== void 0 ? { adminKey: entry.adminKey } : {},
276
- ...entry.seed !== void 0 ? { seed: entry.seed } : {},
277
- log: config.log ?? log
278
- }));
279
- }
280
- } catch (error) {
281
- await Promise.allSettled(servers.map((s) => s.close()));
282
- console.error(error instanceof Error ? error.message : String(error));
283
- return 1;
284
- }
285
- return untilSignal(servers);
286
- }
287
- const port = asString(values.port);
288
- const adminKey = asString(values["admin-key"]) ?? process.env.MOCKINGBIRD_ADMIN_KEY;
289
- const seed = asString(values.seed);
290
- let listening;
291
- try {
292
- listening = await start(target, values, {
293
- port: port === void 0 ? target.defaultPort : Number.parseInt(port, 10),
294
- host: asString(values.host) ?? "127.0.0.1",
295
- ...adminKey !== void 0 ? { adminKey } : {},
296
- ...seed !== void 0 ? { seed } : {},
297
- log
298
- });
299
- } catch (error) {
300
- console.error(error instanceof Error ? error.message : String(error));
301
- return 1;
302
- }
303
- return untilSignal([listening]);
304
- }
305
- });
306
-
307
- // src/server.ts
308
- var DEFAULT_PORT = 8813;
309
- var createServer2 = async (options = {}) => {
310
- const { port, host, ...rest } = options;
311
- const runtime = createRuntime(rest);
312
- const listening = await listen(runtime, {
313
- port: port ?? 0,
314
- ...host !== void 0 ? { host } : {}
315
- });
316
- return { ...listening, runtime };
317
- };
318
- var text = (value) => typeof value === "string" ? value : void 0;
319
- var serveTarget = {
320
- name: "formbricks",
321
- defaultPort: DEFAULT_PORT,
322
- options: {
323
- "webhook-url": {
324
- type: "string",
325
- value: "<url>",
326
- description: "Deliver webhooks here (e.g. http://127.0.0.1:3000/webhooks/formbricks)"
327
- },
328
- "webhook-token": {
329
- type: "string",
330
- value: "<token>",
331
- description: "Appended to the webhook url as ?token= (for receivers that check one)"
332
- },
333
- "webhook-secret": {
334
- type: "string",
335
- value: "<whsec_\u2026>",
336
- description: "Standard Webhooks key that signs webhook-signature (optional)"
337
- },
338
- "workspace-id": {
339
- type: "string",
340
- value: "<id>",
341
- description: "An extra workspace id that serves the survey corpus"
342
- }
343
- },
344
- create: (values, common) => {
345
- const url = text(values["webhook-url"]);
346
- const token = text(values["webhook-token"]);
347
- const secret = text(values["webhook-secret"]);
348
- const workspace = text(values["workspace-id"]);
349
- const target = url && token ? `${url}${url.includes("?") ? "&" : "?"}token=${encodeURIComponent(token)}` : url;
350
- return createRuntime({
351
- ...target ? { webhooks: { url: target, ...secret ? { secret } : {} } } : {},
352
- ...workspace ? { settings: { workspaces: [workspace, ...DEFAULT_SETTINGS.workspaces] } } : {},
353
- ...common.adminKey !== void 0 ? { adminKey: common.adminKey } : {},
354
- ...common.seed !== void 0 ? { seed: common.seed } : {},
355
- ...common.onLog ? { onLog: common.onLog } : {}
356
- });
357
- },
358
- banner: () => [
359
- `point the SDK's appUrl at this url; workspace ${DEFAULT_SETTINGS.workspaces[0]} (legacy environment ${Object.keys(DEFAULT_SETTINGS.legacyEnvironmentIds)[0]}) serves the survey corpus`,
360
- "management API: x-api-key <any>; namespaces: x-mockingbird-namespace, /ns/<name>/\u2026, or PUT /__admin/credentials {<workspace id | api key>: <ns>}"
361
- ]
362
- };
363
-
364
- export {
365
- runCli,
366
- serveCommand,
367
- DEFAULT_PORT,
368
- createServer2 as createServer,
369
- serveTarget
370
- };
371
- //# sourceMappingURL=chunk-D6GS7TTF.js.map