@crvouga/mockingbird-service-google-maps 1.8.1 → 1.9.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-45IZ6HBU.js";
7
- import "./chunk-5R4HFNRA.js";
6
+ } from "./chunk-6O3ECBQ4.js";
7
+ import "./chunk-CODFR63R.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
@@ -403,8 +420,8 @@ type MetricsReport = {
403
420
  };
404
421
  type Metrics = {
405
422
  record(entry: RequestLog): void;
406
- report(): MetricsReport;
407
- reset(): void;
423
+ report(namespace?: string): MetricsReport;
424
+ reset(namespace?: string): void;
408
425
  };
409
426
 
410
427
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -558,6 +575,9 @@ type PublishInput = {
558
575
  id?: string;
559
576
  };
560
577
  type WebhookHub = {
578
+ pending(namespace: string): number;
579
+ snapshot(namespace: string): unknown;
580
+ restore(namespace: string, snapshot: unknown): void;
561
581
  publish(input: PublishInput): WebhookMessage;
562
582
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
563
583
  setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
@@ -585,6 +605,8 @@ type ServiceTimelineState = Readonly<{
585
605
  }>;
586
606
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
587
607
  type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
608
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
609
+ stop?(): void;
588
610
  readonly name: string;
589
611
  readonly sqlite: SqliteClient$1;
590
612
  readonly clock: Clock;
@@ -595,6 +617,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
595
617
  readonly credentials: CredentialRegistry;
596
618
  /** The webhook hub, when the service has outbound webhooks. */
597
619
  readonly webhooks: WebhookHub | undefined;
620
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
621
+ isolateNamespaces(): void;
622
+ namespaceClock(namespace?: string): Clock;
623
+ namespaceOf(request: Request): string;
624
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
625
+ fleetSnapshot(namespace: string): object;
626
+ fleetRestore(snapshot: unknown, namespace: string): void;
598
627
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
599
628
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
600
629
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  normalize,
18
18
  operationIds,
19
19
  supportedOperationIds
20
- } from "./chunk-5R4HFNRA.js";
20
+ } from "./chunk-CODFR63R.js";
21
21
  export {
22
22
  DEFAULT_CORPUS,
23
23
  GOOGLE_MAPS_NAMESPACE,
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
@@ -965,8 +1011,8 @@ type MetricsReport = {
965
1011
  };
966
1012
  type Metrics = {
967
1013
  record(entry: RequestLog): void;
968
- report(): MetricsReport;
969
- reset(): void;
1014
+ report(namespace?: string): MetricsReport;
1015
+ reset(namespace?: string): void;
970
1016
  };
971
1017
 
972
1018
  /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
@@ -1120,6 +1166,9 @@ type PublishInput = {
1120
1166
  id?: string;
1121
1167
  };
1122
1168
  type WebhookHub = {
1169
+ pending(namespace: string): number;
1170
+ snapshot(namespace: string): unknown;
1171
+ restore(namespace: string, snapshot: unknown): void;
1123
1172
  publish(input: PublishInput): WebhookMessage;
1124
1173
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
1125
1174
  setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
@@ -1147,6 +1196,8 @@ type ServiceTimelineState = Readonly<{
1147
1196
  }>;
1148
1197
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
1149
1198
  type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1199
+ /** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
1200
+ stop?(): void;
1150
1201
  readonly name: string;
1151
1202
  readonly sqlite: SqliteClient$1;
1152
1203
  readonly clock: Clock;
@@ -1157,6 +1208,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
1157
1208
  readonly credentials: CredentialRegistry;
1158
1209
  /** The webhook hub, when the service has outbound webhooks. */
1159
1210
  readonly webhooks: WebhookHub | undefined;
1211
+ /** Enable independent namespace clocks and PRNGs before serving a fleet. */
1212
+ isolateNamespaces(): void;
1213
+ namespaceClock(namespace?: string): Clock;
1214
+ namespaceOf(request: Request): string;
1215
+ /** Opaque in-process checkpoint including records, controls and webhook history. */
1216
+ fleetSnapshot(namespace: string): object;
1217
+ fleetRestore(snapshot: unknown, namespace: string): void;
1160
1218
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
1161
1219
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
1162
1220
  /** 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-45IZ6HBU.js";
6
- import "./chunk-5R4HFNRA.js";
5
+ } from "./chunk-6O3ECBQ4.js";
6
+ import "./chunk-CODFR63R.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-google-maps",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "Mock of Google Places Autocomplete / Details / Find Place, the Geocoding API, a Maps JavaScript (places) shim and the Address Validation API (USPS CASS/DPV verdicts), over a QA address corpus, with Google's status codes and fault presets.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,363 +0,0 @@
1
- import {
2
- createRuntime
3
- } from "./chunk-5R4HFNRA.js";
4
-
5
- // ../../adapters/node/dist/cli.js
6
- import { readFile } from "node:fs/promises";
7
- import { parseArgs } from "node:util";
8
-
9
- // ../../adapters/node/dist/serve.js
10
- import { createServer } from "node:http";
11
- var serve = async (api, options = {}) => {
12
- const server = createServer(async (req, res) => {
13
- const chunks = [];
14
- for await (const chunk of req) {
15
- chunks.push(Buffer.from(chunk));
16
- }
17
- const body = Buffer.concat(chunks);
18
- const address = server.address();
19
- const port = typeof address === "object" && address !== null ? address.port : void 0;
20
- const base = `http://${req.headers.host ?? `localhost:${port ?? 80}`}`;
21
- const raw = req.url ?? "/";
22
- const url = new URL(raw.replace(/^\/+/, "/"), base);
23
- const method = req.method ?? "GET";
24
- const init = { method, headers: req.headers };
25
- if (method !== "GET" && method !== "HEAD" && body.length > 0) {
26
- init.body = body;
27
- }
28
- const aborted = new AbortController();
29
- res.once("close", () => {
30
- if (!res.writableFinished)
31
- aborted.abort();
32
- });
33
- init.signal = aborted.signal;
34
- const request = new Request(url, init);
35
- let response;
36
- try {
37
- response = await api.fetch(request);
38
- } catch (error) {
39
- if (error.code === "MOCKINGBIRD_DROP") {
40
- req.socket.destroy();
41
- return;
42
- }
43
- res.writeHead(500, { "content-type": "application/json" });
44
- res.end(JSON.stringify({
45
- error: {
46
- type: "mockingbird_internal",
47
- message: error instanceof Error ? error.message : String(error)
48
- }
49
- }));
50
- return;
51
- }
52
- const headers = Object.fromEntries(response.headers);
53
- const cookies = response.headers.getSetCookie();
54
- if (cookies.length > 0)
55
- headers["set-cookie"] = cookies;
56
- if (!response.body) {
57
- res.writeHead(response.status, headers);
58
- res.end();
59
- return;
60
- }
61
- res.writeHead(response.status, headers);
62
- res.flushHeaders();
63
- const reader = response.body.getReader();
64
- try {
65
- for (; ; ) {
66
- const { done, value } = await reader.read();
67
- if (done)
68
- break;
69
- if (!res.write(value))
70
- await new Promise((resolve) => res.once("drain", resolve));
71
- }
72
- res.end();
73
- } catch {
74
- res.destroy();
75
- } finally {
76
- reader.releaseLock();
77
- }
78
- });
79
- await new Promise((resolve, reject) => {
80
- server.once("error", reject);
81
- server.listen(options.port ?? 0, options.host, resolve);
82
- });
83
- return server;
84
- };
85
-
86
- // ../../adapters/node/dist/listen.js
87
- var listen = async (api, options = {}) => {
88
- const host = options.host ?? "127.0.0.1";
89
- const server = await serve(api, { port: options.port ?? 0, host });
90
- const address = server.address();
91
- const port = typeof address === "object" && address !== null ? address.port : options.port ?? 0;
92
- const shown = host.includes(":") ? `[${host}]` : host;
93
- return {
94
- url: `http://${shown}:${port}`,
95
- port,
96
- host,
97
- server,
98
- close: () => new Promise((resolve, reject) => {
99
- server.close((error) => {
100
- if (error && error.code !== "ERR_SERVER_NOT_RUNNING")
101
- reject(error);
102
- else
103
- resolve();
104
- });
105
- server.closeAllConnections?.();
106
- })
107
- };
108
- };
109
-
110
- // ../../adapters/node/dist/cli.js
111
- var optionHelp = (options) => Object.entries(options).map(([name, option]) => {
112
- const flag = `--${name}${option.type === "string" ? ` ${option.value ?? "<value>"}` : ""}`;
113
- const fallback = option.default !== void 0 ? ` (default: ${String(option.default)})` : "";
114
- return ` ${flag.padEnd(30)} ${option.description}${fallback}`;
115
- });
116
- var help = (spec) => [
117
- `${spec.bin} \u2014 ${spec.description}`,
118
- "",
119
- "Usage:",
120
- ` ${spec.bin} <command> [options]`,
121
- "",
122
- "Commands:",
123
- ...Object.entries(spec.commands).map(([name, c]) => ` ${name.padEnd(30)} ${c.summary}`),
124
- "",
125
- `Run \`${spec.bin} <command> --help\` for a command's options.`
126
- ].join("\n");
127
- var commandHelp = (spec, name, command) => [
128
- `${spec.bin} ${name} \u2014 ${command.summary}`,
129
- "",
130
- "Usage:",
131
- ` ${command.usage ?? `${spec.bin} ${name} [options]`}`,
132
- ...command.options ? ["", "Options:", ...optionHelp(command.options)] : []
133
- ].join("\n");
134
- var runCli = async (spec, argv) => {
135
- const pair = argv.length >= 2 ? `${argv[0]} ${argv[1]}` : void 0;
136
- const words = pair !== void 0 && spec.commands[pair] ? 2 : 1;
137
- const name = words === 2 ? pair : argv[0];
138
- const rest = argv.slice(words);
139
- if (name === void 0 || name === "--help" || name === "-h" || name === "help") {
140
- console.log(help(spec));
141
- return 0;
142
- }
143
- const command = spec.commands[name];
144
- if (!command) {
145
- console.error(`${spec.bin}: unknown command ${JSON.stringify(name)}
146
-
147
- ${help(spec)}`);
148
- return 2;
149
- }
150
- if (rest.includes("--help") || rest.includes("-h")) {
151
- console.log(commandHelp(spec, name, command));
152
- return 0;
153
- }
154
- let parsed;
155
- try {
156
- parsed = parseArgs({
157
- args: rest,
158
- allowPositionals: true,
159
- strict: true,
160
- options: Object.fromEntries(Object.entries(command.options ?? {}).map(([key, option]) => [
161
- key,
162
- {
163
- type: option.type,
164
- ...option.default !== void 0 ? { default: option.default } : {}
165
- }
166
- ]))
167
- });
168
- } catch (error) {
169
- console.error(`${spec.bin} ${name}: ${error instanceof Error ? error.message : String(error)}
170
-
171
- ${commandHelp(spec, name, command)}`);
172
- return 2;
173
- }
174
- return command.run(parsed.values, parsed.positionals);
175
- };
176
- var COMMON_SERVE_OPTIONS = {
177
- port: { type: "string", value: "<port>", description: "Port to listen on" },
178
- host: { type: "string", value: "<host>", description: "Interface to bind", default: "127.0.0.1" },
179
- "admin-key": {
180
- type: "string",
181
- value: "<key>",
182
- description: "Require x-mockingbird-admin-key on /__admin/* (env MOCKINGBIRD_ADMIN_KEY)"
183
- },
184
- seed: { type: "string", value: "<seed>", description: "Seed for every random choice" },
185
- log: {
186
- type: "string",
187
- value: "<pretty|json|off>",
188
- description: "Request log format",
189
- default: "pretty"
190
- },
191
- "log-requests": {
192
- type: "boolean",
193
- description: "One JSON line per request: namespace, operationId, status, ids touched (never bodies). Same as --log json"
194
- },
195
- config: {
196
- type: "string",
197
- value: "<file>",
198
- description: "Serve every service in a mockingbird.json config instead"
199
- }
200
- };
201
- var formatLog = (format) => {
202
- if (format === "off")
203
- return void 0;
204
- if (format === "json")
205
- return (entry) => console.log(JSON.stringify(entry));
206
- return (entry) => {
207
- const op = entry.operationId ?? (entry.unmatched ? "UNMATCHED" : "-");
208
- const ns = entry.namespace === "default" ? "" : ` [${entry.namespace}]`;
209
- const fault = entry.faultId ? ` fault=${entry.faultId}` : "";
210
- const adopted = entry.adopted ? " adopted" : "";
211
- const received = entry.request ? ` received=${entry.request.bodyBytes === null ? "?" : `${entry.request.bodyBytes}B`} ct=${entry.request.contentType ?? "-"}${entry.request.transferEncoding ? ` te=${entry.request.transferEncoding}` : ""}` : "";
212
- 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})` : ""}` : "";
213
- console.log(`${entry.service} ${entry.method} ${entry.path} ${entry.status} ${op} ${entry.durationMs}ms${ns}${fault}${adopted}${received}${issues}`);
214
- };
215
- };
216
- var asString = (value) => typeof value === "string" ? value : void 0;
217
- var loadTarget = async (name, own) => {
218
- if (name === own.name)
219
- return own;
220
- const specifier = `@crvouga/mockingbird-service-${name}/server`;
221
- try {
222
- const mod = await import(specifier);
223
- if (!mod.serveTarget)
224
- throw new Error(`${specifier} exports no serveTarget`);
225
- return mod.serveTarget;
226
- } catch (error) {
227
- const reason = error instanceof Error ? error.message : String(error);
228
- throw new Error(`cannot load service "${name}": ${reason}. Install @crvouga/mockingbird-service-${name}.`);
229
- }
230
- };
231
- var start = async (target, values, config) => {
232
- const runtime = await target.create(values, {
233
- adminKey: config.adminKey,
234
- seed: config.seed,
235
- onLog: formatLog(config.log)
236
- });
237
- const listening = await listen(runtime, { port: config.port, host: config.host });
238
- target.listening?.(listening);
239
- console.log(`${target.name} mock listening on ${listening.url}`);
240
- console.log(`${target.name} health: GET ${listening.url}/health`);
241
- console.log(`${target.name} admin: ${listening.url}/__admin (${config.adminKey ? "x-mockingbird-admin-key required" : "open \u2014 pass --admin-key to lock"})`);
242
- console.log(`${target.name} admin ui: ${listening.url}/__admin/ui`);
243
- for (const line of target.banner?.(runtime) ?? [])
244
- console.log(`${target.name} ${line}`);
245
- return listening;
246
- };
247
- var untilSignal = async (servers) => new Promise((resolve) => {
248
- const stop = async () => {
249
- await Promise.allSettled(servers.map((s) => s.close()));
250
- resolve(0);
251
- };
252
- process.once("SIGINT", stop);
253
- process.once("SIGTERM", stop);
254
- });
255
- var serveCommand = (target) => ({
256
- summary: `Serve the ${target.name} mock over HTTP`,
257
- options: { ...COMMON_SERVE_OPTIONS, ...target.options },
258
- async run(values) {
259
- const log = values["log-requests"] === true ? "json" : asString(values.log) ?? "pretty";
260
- if (!["pretty", "json", "off"].includes(log)) {
261
- console.error(`--log must be pretty, json or off (got ${log})`);
262
- return 2;
263
- }
264
- const configPath = asString(values.config);
265
- if (configPath !== void 0) {
266
- const config = JSON.parse(await readFile(configPath, "utf8"));
267
- const servers = [];
268
- try {
269
- for (const [name, entry] of Object.entries(config.services ?? {})) {
270
- const each = await loadTarget(name, target);
271
- servers.push(await start(each, entry.options ?? {}, {
272
- port: entry.port ?? each.defaultPort,
273
- host: entry.host ?? "127.0.0.1",
274
- ...entry.adminKey !== void 0 ? { adminKey: entry.adminKey } : {},
275
- ...entry.seed !== void 0 ? { seed: entry.seed } : {},
276
- log: config.log ?? log
277
- }));
278
- }
279
- } catch (error) {
280
- await Promise.allSettled(servers.map((s) => s.close()));
281
- console.error(error instanceof Error ? error.message : String(error));
282
- return 1;
283
- }
284
- return untilSignal(servers);
285
- }
286
- const port = asString(values.port);
287
- const adminKey = asString(values["admin-key"]) ?? process.env.MOCKINGBIRD_ADMIN_KEY;
288
- const seed = asString(values.seed);
289
- let listening;
290
- try {
291
- listening = await start(target, values, {
292
- port: port === void 0 ? target.defaultPort : Number.parseInt(port, 10),
293
- host: asString(values.host) ?? "127.0.0.1",
294
- ...adminKey !== void 0 ? { adminKey } : {},
295
- ...seed !== void 0 ? { seed } : {},
296
- log
297
- });
298
- } catch (error) {
299
- console.error(error instanceof Error ? error.message : String(error));
300
- return 1;
301
- }
302
- return untilSignal([listening]);
303
- }
304
- });
305
-
306
- // src/server.ts
307
- var DEFAULT_PORT = 8814;
308
- var createServer2 = async (options = {}) => {
309
- const { port, host, ...rest } = options;
310
- const runtime = createRuntime(rest);
311
- const listening = await listen(runtime, {
312
- port: port ?? 0,
313
- ...host !== void 0 ? { host } : {}
314
- });
315
- return { ...listening, runtime };
316
- };
317
- var text = (value) => typeof value === "string" ? value : void 0;
318
- var serveTarget = {
319
- name: "google-maps",
320
- defaultPort: DEFAULT_PORT,
321
- options: {
322
- "api-key": {
323
- type: "string",
324
- value: "<key[,key\u2026]>",
325
- description: "Accept only these API keys (the app's PLACES_KEY); default: any non-empty key"
326
- },
327
- "public-url": {
328
- type: "string",
329
- value: "<url>",
330
- description: "Origin the Maps JavaScript shim calls back to, when it differs from the request's"
331
- }
332
- },
333
- create: (values, common) => {
334
- const keys = text(values["api-key"]);
335
- const publicUrl = text(values["public-url"]);
336
- return createRuntime({
337
- settings: {
338
- ...keys ? {
339
- keys: keys.split(",").map((k) => k.trim()).filter(Boolean)
340
- } : {},
341
- ...publicUrl ? { publicUrl } : {}
342
- },
343
- ...common.adminKey !== void 0 ? { adminKey: common.adminKey } : {},
344
- ...common.seed !== void 0 ? { seed: common.seed } : {},
345
- ...common.onLog ? { onLog: common.onLog } : {}
346
- });
347
- },
348
- banner: () => [
349
- "REST: /maps/api/place/{autocomplete,details,findplacefromtext}/json, /maps/api/geocode/json (?key=)",
350
- 'web: <script src="<this server>/maps/api/js?key=\u2026&libraries=places">',
351
- "Address Validation: POST /v1:validateAddress?key= (addressvalidation.googleapis.com)",
352
- "namespaces: x-mockingbird-namespace, /ns/<name>/\u2026, or PUT /__admin/credentials {<key>: <ns>}"
353
- ]
354
- };
355
-
356
- export {
357
- runCli,
358
- serveCommand,
359
- DEFAULT_PORT,
360
- createServer2 as createServer,
361
- serveTarget
362
- };
363
- //# sourceMappingURL=chunk-45IZ6HBU.js.map