@crvouga/mockingbird-service-junction 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 CHANGED
@@ -1,15 +1,25 @@
1
1
  # Changelog — @crvouga/mockingbird-service-junction
2
2
 
3
+ ## 1.0.2 (2026-09-26)
4
+
5
+ ### Fixes and improvements
6
+
7
+ - take the rejected-request byte count from content-length, never by reading the body ([a0e5fb2](https://github.com/crvouga/mockingbird/commit/a0e5fb2fc80ab725c3552b612f3f091fd6c857fb))
8
+ - place orders through another lab's account and with several active accounts, as the sandbox does ([6f7d756](https://github.com/crvouga/mockingbird/commit/6f7d7569a1c78e32f259fbcd2f5f76dac106c7d6))
9
+ - reject a present body by media type, and log what a rejected request sent ([12e351a](https://github.com/crvouga/mockingbird/commit/12e351aba53cfb7b41e31a7809419455fc2902eb))
10
+
11
+ ## 1.0.1 (2026-09-25)
12
+
13
+ ### Fixes and improvements
14
+
15
+ - match the sandbox on lab_test_id orders, order rendering, platform preset, radii and billing default ([e5497c7](https://github.com/crvouga/mockingbird/commit/e5497c7b78e99595e3226679f8494e9e29677a7d))
16
+
3
17
  ## 1.0.0 (2026-09-24)
4
18
 
5
19
  ### ⚠️ Breaking changes
6
20
 
7
21
  - vendor branding for every service; purge internal mocks and consumer names ([f689534](https://github.com/crvouga/mockingbird/commit/f6895343543550dafcb7d76b426cae7635e03226))
8
22
 
9
- ### Dependencies
10
-
11
- - `@crvouga/mockingbird-service-sqlite`
12
-
13
23
  ## 0.8.0 (2026-09-23)
14
24
 
15
25
  ### Features
package/README.md CHANGED
@@ -59,6 +59,7 @@ npx mockingbird-junction serve --help
59
59
  | `--team-id <uuid>` | the corpus's team | The [team](#team-identity) the mock answers as |
60
60
  | `--max-users <n>` | unlimited | Enforce the sandbox's [live-user cap](#sandbox-limits) |
61
61
  | `--identity <strict\|adopt-users>` | `strict` | Unknown `user_id`s: 404, or [create on first use](#fixtures-and-identity) |
62
+ | `--default-billing-type <lab=type,…>` | `client_bill` | The `billing_type` an order for that lab gets when it omits one ([billing](#default-billing-type)) |
62
63
  | `--fixtures <file>` | — | [Users and orders](#fixtures-and-identity) every namespace starts with |
63
64
  | `--journal-size <n>` | `1000` | Requests each namespace's [journal](#is-this-the-mock) keeps |
64
65
  | `--webhook-url <url>` / `--webhook-secret <whsec_…>` | off | Deliver [signed webhooks](#webhooks) (secret also from `MOCKINGBIRD_JUNCTION_WEBHOOK_SECRET`) |
@@ -250,17 +251,18 @@ Every Mockingbird service answers the same control surface, outside the vendor's
250
251
  | `GET` / `POST` / `DELETE /__admin/faults` | List, add or clear [fault rules](#faults-and-error-shapes) (`DELETE ?id=` removes one) |
251
252
  | `POST /__admin/faults/presets/{name}` | Add a named Junction fault; body may override `count`, `rate`, `operationId`… |
252
253
  | `GET /__admin/metrics` | Requests by operation and status, fault count, and **unmatched routes** |
253
- | `GET /__admin/orders` | Orders in the namespace with their current status |
254
+ | `GET /__admin/orders` | Orders in the namespace with their current status and the `lab_account_id` each was placed with (`null`: Junction's platform account) |
254
255
  | `POST /__admin/orders/{id}/transition` | Move an order: `{ "to": "completed", "result": "abnormal" }` ([order control](#order-control)) |
255
256
  | `GET` / `PUT /__admin/results/{id}` | Read or install an exact result payload / PDF for an order |
256
257
  | `GET /__admin/result-fixtures` | The named results |
257
258
  | `GET` / `PUT /__admin/lab-accounts` | Read or replace the namespace's [lab accounts](#lab-accounts) (`{ "accounts": [...], "presets": [...] }`; `{ "accounts": null }` restores the default) |
258
259
  | `POST /__admin/lab-accounts` | Add one account; 409 if the id exists |
259
260
  | `PATCH` / `DELETE /__admin/lab-accounts/{id}` | Merge fields into an account (`{ "status": "suspended" }`, `{ "states": [...] }`) / remove it; 404 if absent |
260
- | `GET /__admin/lab-accounts/presets` | Every [preset](#lab-account-presets), with its full record |
261
+ | `GET /__admin/lab-accounts/presets` | Every [preset](#lab-account-presets), with its full record, plus `aliases` (deprecated names) and `synthetic` (presets that are not a recorded account) |
261
262
  | `POST /__admin/lab-accounts/presets/{name}` | Add a preset account; body `{ "id": "…" }` overrides its id |
262
263
  | `GET /__admin/team` | `{ "teamId" }` — the [team](#team-identity) the namespace answers as |
263
264
  | `GET` / `PUT /__admin/limits` | Read or change the namespace's [sandbox limits](#sandbox-limits) |
265
+ | `GET` / `PUT /__admin/default-billing-types` | Read or replace `{ "defaultBillingTypes": { "<lab slug>": "<billing_type>" } }` ([billing](#default-billing-type)); `{}` restores `client_bill` |
264
266
  | `GET` / `PUT /__admin/identity` | Read or set `{ "mode": "strict" \| "adopt-users" }` ([identity](#fixtures-and-identity)) |
265
267
  | `POST /__admin/users`, `POST /__admin/users/bulk` | Insert a user (or `{ "users": [...] }`, all or none) with a chosen `user_id`; 409 on a duplicate id or `client_user_id` |
266
268
  | `DELETE /__admin/users/{id}` | Remove a user outright, leaving no deletion tombstone |
@@ -322,13 +324,39 @@ loudly instead of silently disagreeing with production. A malformed ZIP still ge
322
324
  instead — right for property tests that walk random ZIPs, wrong for a suite standing in for
323
325
  production.
324
326
 
327
+ A covered ZIP is answered from its recordings, never next to them. The corpus records `area/info`
328
+ and `psc/info` at the default radius (25 miles, so `radius=25` and no `radius` are the same read)
329
+ and at 100 miles. A `psc/info` read at another radius is the smallest wider recording filtered to
330
+ `distance < radius`: the sandbox lists the nearest sites (at most 30), and `distance` is rounded, so
331
+ this reproduces every recorded 25-mile answer from its 100-mile one exactly. An `area/info` read at
332
+ a radius with no recording, or any read with parameters the corpus did not record (for example
333
+ `capabilities`), gets the same 424, because `within_radius` counts cannot be derived. In
334
+ `--geo synthetic` the derivation still applies, and only reads with nothing to derive from are
335
+ invented.
336
+
325
337
  ## Lab accounts
326
338
 
327
- `create_order` routes, accepts and rejects `lab_account_id` against the team's lab accounts,
328
- following Junction's documented rules: an explicit id must exist, be linked to the team, belong to
329
- the ordered lab and be active; with no id, one active account for the lab is selected, several are
330
- an error, and a lab with none falls back to Junction's platform account. The billing type must be
331
- allowed in the patient's state by the account's `allowed_billing`.
339
+ `create_order` routes, accepts and rejects `lab_account_id` against the team's lab accounts, the
340
+ way the sandbox does: an explicit id must exist, be linked to the team and be active; with no id,
341
+ one active account for the lab is selected, several select the first listed, and a lab with none
342
+ falls back to Junction's platform account. The billing type must be allowed in the patient's
343
+ state by the account's `allowed_billing`.
344
+
345
+ Two of Junction's documented rules are **not** enforced by the sandbox, so the mock does not
346
+ enforce them either. An id naming another lab's account is accepted and the order is placed with
347
+ that account (the guide says it must be "associated with the lab selected for the order"):
348
+ recorded in `corpus/lab-account-probes.json`, where a Labcorp test ordered through Junction's
349
+ BioReference account was placed, and reported live by a consumer's team
350
+ ([#138](https://github.com/crvouga/mockingbird/issues/138)). An omitted id while several active
351
+ accounts are linked for the lab places the order (the guide says it "may be rejected"): reported
352
+ live by a consumer's team ([#136](https://github.com/crvouga/mockingbird/issues/136)); the
353
+ sandbox team the parity run uses has one account per lab, so `verify --orders` checks it whenever
354
+ a corpus has such a lab. Which of the several accounts the sandbox bills through is not visible
355
+ from outside; the mock uses the first listed.
356
+
357
+ Junction's order (`ClientFacingOrder`) has no `lab_account_id`, so neither does the mock's: not on
358
+ the create response, `GET /v3/order/{id}`, `GET /v3/orders` or webhooks. The account an order was
359
+ placed with is reported only by `GET /__admin/orders` and `instance().orderLabAccount(orderId)`.
332
360
 
333
361
  The accounts come from, in order: `labAccounts` / `--lab-accounts`, else the corpus (a pulled
334
362
  corpus carries your team's real accounts), else built-in fixtures. Configure them as
@@ -351,12 +379,34 @@ const junction = createRuntime({
351
379
  console.log(junction.instance().labAccounts().length) // 3
352
380
  ```
353
381
 
354
- Rejections keep Junction's body shape, `400 {"detail": "Lab account is not associated with lab labcorp"}`.
382
+ Rejections keep Junction's body shape, `400 {"detail": "Lab account is not linked to your team"}`.
355
383
  `delegated_flow` is stored and listed, but see [not modelled](#what-is-and-is-not-modelled).
356
384
 
357
385
  Availability reads that take a `lab_account_id` (`GET /v3/order/area/info`) check it against the
358
386
  same live list, so an id `create_order` accepts is never a 404 there.
359
387
 
388
+ ### Default billing type
389
+
390
+ An order that omits `billing_type` is evaluated as `client_bill`, Junction's documented default.
391
+ A sandbox team has been observed evaluating BioReference orders as `patient_bill_passthrough`
392
+ instead (whether that is a team, lab or account setting is not visible from outside), so the
393
+ default is configurable per lab slug:
394
+
395
+ ```ts
396
+ import { createRuntime } from "@crvouga/mockingbird-service-junction"
397
+
398
+ const junction = createRuntime({ defaultBillingTypes: { bioreference: "patient_bill_passthrough" } })
399
+ console.log(junction.instance().defaultBillingTypes) // { bioreference: "patient_bill_passthrough" }
400
+ ```
401
+
402
+ `--default-billing-type bioreference=patient_bill_passthrough` and
403
+ `PUT /__admin/default-billing-types` (per namespace, kept across its reset) do the same. When the
404
+ default resolves to a billing type the account lacks, the rejection is worded as the sandbox words
405
+ it, `400 {"detail": "Lab 13 does not support billing type patient_bill_passthrough"}`; an explicit
406
+ `billing_type` the account lacks keeps `Billing type … is not supported by the lab account used for
407
+ this order`. `verify --orders` orders through each active account with `billing_type` omitted, so a
408
+ run against your team shows which default it uses.
409
+
360
410
  ### Changing accounts at runtime
361
411
 
362
412
  Each namespace has its own layout, kept across its own reset. Change one account at a time, or
@@ -381,7 +431,8 @@ declare it at boot with no admin call:
381
431
  ### Lab-account presets
382
432
 
383
433
  Named after what they model; ids are `deterministicUuid("junction:lab-account:<name>")` unless
384
- given. Where a preset copies an account recorded from a real BioReference-linked sandbox team
434
+ given. `*_platform` presets are Junction's own accounts (`org_id: null`, `team_id_allowlist: []`);
435
+ the other active presets are customer-owned (an Org's account linked to the team). Where a preset copies an account recorded from a real BioReference-linked sandbox team
385
436
  (2026-09-21), its billing states are the recording's. `PLATFORM_ACCOUNT_STATES` is every state
386
437
  but NJ, NY and RI (47).
387
438
 
@@ -389,13 +440,16 @@ but NJ, NY and RI (47).
389
440
  | --- | --- | --- | --- | --- | --- |
390
441
  | `bioreference_ny_nj_delegated` | `bioreference` | `order_delegated` | `client_bill`: NY, NJ | the team | requested shape, **not** a recorded account |
391
442
  | `bioreference_delegated_multi_state` | `bioreference` | `order_delegated` | `client_bill`: every state but NY, NJ (48) | the team | recorded |
392
- | `bioreference_customer_multi_state` | `bioreference` | `not_delegated` | `client_bill`: `PLATFORM_ACCOUNT_STATES` | `[]` | recorded ("Junction BioReference Account") |
443
+ | `bioreference_platform` | `bioreference` | `not_delegated` | `client_bill`: `PLATFORM_ACCOUNT_STATES` | `[]` | recorded ("Junction BioReference Account") |
393
444
  | `bioreference_patient_bill_passthrough` | `bioreference` | `not_delegated` | `patient_bill_passthrough`: NJ, NY | the team | recorded |
394
445
  | `quest_platform` / `labcorp_platform` | `quest` / `labcorp` | `not_delegated` | `client_bill`: `PLATFORM_ACCOUNT_STATES` | `[]` | recorded ("Junction Quest/Labcorp Account") |
395
446
  | `suspended_bioreference` / `suspended_quest` / `suspended_labcorp` | as above | `not_delegated` | as the platform accounts | `[]` | the platform shapes with `status: "suspended"` |
396
447
 
397
448
  Every preset is `status: "active"` unless named `suspended_*`. `GET /__admin/lab-accounts/presets`
398
- returns the full records.
449
+ returns the full records, the deprecated `aliases`, and the `synthetic` presets (not a recorded
450
+ account). `bioreference_customer_multi_state` is a deprecated alias of `bioreference_platform`: it
451
+ was misnamed, since the record is Junction's platform account, not a customer-owned one. It still
452
+ works and keeps its own default id (`presetAccountId("bioreference_customer_multi_state")`).
399
453
 
400
454
  ### Team identity
401
455
 
@@ -409,12 +463,12 @@ linked to answers `400 {"detail": "Lab account is not linked to your team"}` exa
409
463
  live. A version-1 corpus (no `teamId`) still loads and behaves as 0.2.0 did: every recorded account
410
464
  is also linked to the mock team.
411
465
 
412
- **Open question — empty allowlists.** Junction's own Quest, Labcorp and BioReference accounts carry
466
+ **Empty allowlists.** Junction's own Quest, Labcorp and BioReference accounts carry
413
467
  `team_id_allowlist: []`, and a real team's listing returns them, so the mock lists them and treats
414
- them as linked. Whether *ordering* through one — by explicit id, or when it is one of several
415
- active accounts for a lab with the id omitted — behaves the same live is **not verified**.
416
- `verify --orders` checks it whenever the corpus has such an account; until a run records the
417
- answer, a suite that depends on it should run against the sandbox too.
468
+ them as linked. Ordering through one by explicit id, and with the id omitted when it is the lab's
469
+ only active account, places the order on the sandbox (`corpus/lab-account-probes.json`, recorded
470
+ by the parity run), as the mock does. `verify --orders` re-checks it whenever the corpus has such
471
+ an account.
418
472
 
419
473
  ## Sandbox limits
420
474
 
@@ -657,8 +711,8 @@ A mock that is silent about its gaps is how a green suite starts lying. Specific
657
711
  accounts is not reproduced. Run `verify --orders` with your team's corpus to check what you rely on.
658
712
  - Rate limits and outages, except when injected as faults or switched on as
659
713
  [limits](#sandbox-limits).
660
- - Whether an account with an empty `team_id_allowlist` can be ordered through (see
661
- [Team identity](#team-identity)); the mock assumes it can.
714
+ - Which of several active accounts for a lab the sandbox bills an order through when
715
+ `lab_account_id` is omitted (see [Lab accounts](#lab-accounts)); the mock uses the first listed.
662
716
  - Adopted users (`adopt-users`) have `client_user_id` equal to their `user_id`; nothing in
663
717
  Junction corresponds to adoption.
664
718
  - Real 429 / 5xx bodies: the presets are plausible, not recorded.
@@ -674,7 +728,7 @@ Main entry (`@crvouga/mockingbird-service-junction`, runtime-neutral):
674
728
 
675
729
  | Export | Description |
676
730
  | --- | --- |
677
- | `createRuntime` | `(options?: JunctionRuntimeOptions) => JunctionRuntime` — the served mock (health, admin, namespaces, clock, faults, metrics, journal, webhooks) as one `fetch`. Options: `corpus`, `geo`, `labAccounts`, `teamId`, `limits`, `identity`, `fixtures`, `journalSize`, `webhooks`, `onWebhook`, `sqlite`, `clock`, `seed`, `adminKey`, `onLog`. |
731
+ | `createRuntime` | `(options?: JunctionRuntimeOptions) => JunctionRuntime` — the served mock (health, admin, namespaces, clock, faults, metrics, journal, webhooks) as one `fetch`. Options: `corpus`, `geo`, `labAccounts`, `teamId`, `limits`, `identity`, `defaultBillingTypes`, `fixtures`, `journalSize`, `webhooks`, `onWebhook`, `sqlite`, `clock`, `seed`, `adminKey`, `onLog`. |
678
732
  | `JunctionAPI` | Class. `new JunctionAPI(options?)`: one namespace's mock, implementing `fetch(request: Request): Promise<Response>`. |
679
733
  | `JUNCTION_NAMESPACE` | `"junction"` — the default namespace's storage key when sharing a `sqlite` client. |
680
734
  | `document` | The vendored Junction OpenAPI document (Mockingbird subset) that drives routing. |
@@ -691,6 +745,9 @@ Main entry (`@crvouga/mockingbird-service-junction`, runtime-neutral):
691
745
  | `OTHER_TEAM_ID` | A team that is not the mock's, for fixtures modelling another team's account. |
692
746
  | `isLinkedToTeam` | `(account, teamId) => boolean` — the allowlist rule (`[]` counts as linked). |
693
747
  | `LAB_ACCOUNT_PRESETS` | The [lab-account presets](#lab-account-presets), without ids. |
748
+ | `LAB_ACCOUNT_PRESET_ALIASES` | Deprecated preset names → the preset each stands for (`bioreference_customer_multi_state` → `bioreference_platform`). |
749
+ | `SYNTHETIC_LAB_ACCOUNT_PRESETS` | Presets that model a requested shape, not a recorded account. |
750
+ | `BILLING_TYPES` | The `billing_type` values `create_order` accepts. |
694
751
  | `presetAccountId` | `(name) => string` — a preset's default id. |
695
752
  | `PLATFORM_ACCOUNT_STATES` / `DELEGATED_ACCOUNT_STATES` | The recorded 47- and 48-state client-bill lists. |
696
753
  | `LabAccountConflict` | Thrown by `addLabAccount` for an id that exists. |
@@ -748,8 +805,10 @@ Main entry (`@crvouga/mockingbird-service-junction`, runtime-neutral):
748
805
  | `teamId` | The team this namespace answers as. |
749
806
  | `limits` / `configureLimits(input)` | Read / change the sandbox limits; kept across `reset()`. |
750
807
  | `identity` | `"strict" \| "adopt-users"`, settable. |
808
+ | `defaultBillingTypes` | Lab slug → the `billing_type` an order gets when it omits one ([default billing type](#default-billing-type)); settable, kept across `reset()`. |
751
809
  | `insertUsers(users)` / `insertOrders(orders, { emitWebhooks? })` / `importFixtures(fixtures, options?)` / `hardDeleteUser(id)` | The [fixture backdoor](#fixtures-and-identity). |
752
810
  | `order(id)` / `orders()` | Read orders. |
811
+ | `orderLabAccount(id)` | The lab account id an order was placed with (`null`: Junction's platform account; `undefined`: unknown order). |
753
812
  | `transitionOrder(id, status, { now, flags? })` | Move an order to a full status and publish its webhook. |
754
813
  | `installResultFixture(orderId, fixture)` / `resultFixture(orderId)` | Serve an exact result payload / PDF for an order. |
755
814
  | `seedFrom(source, observations?)` | `Promise<SeedReport>` — copy users, orders, appointments, catalog and labs from a real Junction environment. |
@@ -772,6 +831,7 @@ type JunctionAPIOptions = {
772
831
  teamId?: string // default: the corpus's recorded team, else MOCK_TEAM_ID
773
832
  limits?: { maxUsers?: number | null; simulateRequiresSandbox?: boolean; rateLimitPerSecond?: number | null }
774
833
  identity?: "strict" | "adopt-users" // default "strict"
834
+ defaultBillingTypes?: Record<string, BillingType> // lab slug → billing_type when omitted; default client_bill
775
835
  fixtures?: { users?: UserFixture[]; orders?: OrderFixture[] } // loaded now and on every reset()
776
836
  onWebhook?: WebhookPublisher // called with every recorded event
777
837
  webhook?: JunctionWebhookOptions
@@ -817,7 +877,7 @@ bun test junction.sdk.property.test.ts # drives the served mock through @try
817
877
 
818
878
  bun run mock:serve # env-configured `serve`: HOST, PORT, MOCKINGBIRD_JUNCTION_CORPUS,
819
879
  # MOCKINGBIRD_JUNCTION_WEBHOOK_URL / _SECRET / _SCOPE
820
- bun run corpus:record -- --force # re-record the shipped corpus/sandbox-sealed.json (MOCKINGBIRD_JUNCTION_API_KEY)
880
+ bun run corpus:record -- --force # re-record the shipped corpus/sandbox-sealed.json (JUNCTION_API_KEY)
821
881
  bun run verify -- --real-key "$KEY" # `mockingbird-junction verify` from source
822
882
  ```
823
883
 
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  IDENTITY_MODES,
3
3
  createRuntime,
4
+ defaultBillingTypesFrom,
4
5
  pullCorpus
5
- } from "./chunk-MS774AJA.js";
6
+ } from "./chunk-GWXEPT6A.js";
6
7
  import {
7
8
  defaultCorpus
8
9
  } from "./chunk-C2UGIPPM.js";
@@ -219,7 +220,9 @@ var formatLog = (format) => {
219
220
  const ns = entry.namespace === "default" ? "" : ` [${entry.namespace}]`;
220
221
  const fault = entry.faultId ? ` fault=${entry.faultId}` : "";
221
222
  const adopted = entry.adopted ? " adopted" : "";
222
- console.log(`${entry.service} ${entry.method} ${entry.path} ${entry.status} ${op} ${entry.durationMs}ms${ns}${fault}${adopted}`);
223
+ const received = entry.request ? ` received=${entry.request.bodyBytes === null ? "?" : `${entry.request.bodyBytes}B`} ct=${entry.request.contentType ?? "-"}${entry.request.transferEncoding ? ` te=${entry.request.transferEncoding}` : ""}` : "";
224
+ 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})` : ""}` : "";
225
+ console.log(`${entry.service} ${entry.method} ${entry.path} ${entry.status} ${op} ${entry.durationMs}ms${ns}${fault}${adopted}${received}${issues}`);
223
226
  };
224
227
  };
225
228
  var asString = (value) => typeof value === "string" ? value : void 0;
@@ -354,6 +357,18 @@ var retryDelays = (value) => {
354
357
  }
355
358
  return delays;
356
359
  };
360
+ var billingDefaults = (value) => {
361
+ if (value === void 0) return void 0;
362
+ const entries = value.split(",").map((part) => part.split("=").map((side) => side.trim()));
363
+ if (entries.some((entry) => entry.length !== 2 || !entry[0] || !entry[1])) {
364
+ throw new Error(`--default-billing-type must be lab=billing_type pairs (got ${value})`);
365
+ }
366
+ try {
367
+ return defaultBillingTypesFrom(Object.fromEntries(entries));
368
+ } catch (error) {
369
+ throw new Error(`--default-billing-type: ${error.message}`);
370
+ }
371
+ };
357
372
  var serveTarget = {
358
373
  name: "junction",
359
374
  defaultPort: DEFAULT_PORT,
@@ -390,6 +405,11 @@ var serveTarget = {
390
405
  description: "Unknown user ids: 404 (strict) or create on first use",
391
406
  default: "strict"
392
407
  },
408
+ "default-billing-type": {
409
+ type: "string",
410
+ value: "<lab=type,\u2026>",
411
+ description: "billing_type an order for that lab gets when it omits one (default: client_bill), e.g. bioreference=patient_bill_passthrough"
412
+ },
393
413
  fixtures: {
394
414
  type: "string",
395
415
  value: "<file>",
@@ -459,6 +479,7 @@ var serveTarget = {
459
479
  if (identity !== void 0 && !IDENTITY_MODES.includes(identity)) {
460
480
  throw new Error(`--identity must be one of ${IDENTITY_MODES.join(", ")} (got ${identity})`);
461
481
  }
482
+ const defaultBillingTypes = billingDefaults(asString2(values["default-billing-type"]));
462
483
  const webhookUrl = asString2(values["webhook-url"]);
463
484
  const webhookSecret = asString2(values["webhook-secret"]) ?? process.env.MOCKINGBIRD_JUNCTION_WEBHOOK_SECRET;
464
485
  if (webhookUrl !== void 0 && webhookSecret === void 0) {
@@ -474,6 +495,7 @@ var serveTarget = {
474
495
  ...teamId !== void 0 ? { teamId } : {},
475
496
  ...maxUsers !== void 0 ? { limits: { maxUsers } } : {},
476
497
  ...identity !== void 0 ? { identity } : {},
498
+ ...defaultBillingTypes ? { defaultBillingTypes } : {},
477
499
  ...journalSize !== void 0 ? { journalSize } : {},
478
500
  ...webhookUrl !== void 0 && webhookSecret !== void 0 ? {
479
501
  webhooks: {
@@ -513,4 +535,4 @@ export {
513
535
  createServer2 as createServer,
514
536
  serveTarget
515
537
  };
516
- //# sourceMappingURL=chunk-TG2EOH3J.js.map
538
+ //# sourceMappingURL=chunk-A4KJJ5V3.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/server.ts", "../../../adapters/node/src/cli.ts", "../../../adapters/node/src/serve.ts", "../../../adapters/node/src/listen.ts"],
4
+ "sourcesContent": ["/// <reference types=\"node\" />\nimport { readFile } from \"node:fs/promises\"\nimport {\n type CliValues,\n type Listening,\n listen,\n type ServeTarget,\n} from \"@crvouga/mockingbird-adapter-node\"\nimport { defaultCorpus } from \"./corpus.js\"\nimport { pullCorpus } from \"./corpus-tools.js\"\nimport { IDENTITY_MODES, type IdentityMode, type JunctionFixtures } from \"./fixtures.js\"\nimport type { LabAccountLayout } from \"./lab-account-presets.js\"\nimport { type BillingType, defaultBillingTypesFrom } from \"./lab-accounts.js\"\nimport { createRuntime, type JunctionRuntime, type JunctionRuntimeOptions } from \"./runtime.js\"\nimport { parseSealedCorpus, type SealedCorpus } from \"./sealed-corpus.js\"\nimport type { GeoMode } from \"./state.js\"\n\n/** Port `mockingbird-junction serve` listens on when none is given. */\nexport const DEFAULT_PORT = 8787\n\n/** A corpus to serve: the shipped one, none (synthetic), a file path, or a loaded corpus. */\nexport type CorpusSource = \"default\" | \"none\" | (string & {}) | SealedCorpus\n\nexport type JunctionServerOptions = Omit<JunctionRuntimeOptions, \"corpus\"> & {\n /** Default `0`: the OS picks a free port (read it from `url` / `port`). */\n port?: number\n /** Default `127.0.0.1`. */\n host?: string\n /** Default `\"default\"`: the corpus shipped with this package. */\n corpus?: CorpusSource\n}\n\nexport type JunctionServer = Listening & { runtime: JunctionRuntime }\n\n/** Resolve a {@link CorpusSource} to a corpus, or `undefined` for synthetic data. */\nexport const loadCorpus = async (source: CorpusSource): Promise<SealedCorpus | undefined> => {\n if (typeof source !== \"string\") return source\n if (source === \"none\") return undefined\n if (source === \"default\") return defaultCorpus\n const raw = await readFile(source, \"utf8\").catch(() => undefined)\n if (raw === undefined) throw new Error(`junction mock corpus not found: ${source}`)\n return parseSealedCorpus(JSON.parse(raw))\n}\n\n/**\n * Serve the Junction mock over `node:http`. Resolves once it is listening.\n *\n * const server = await createServer()\n * // point the Vital SDK at server.url; await server.close() when done\n */\nexport const createServer = async (\n options: JunctionServerOptions = {},\n): Promise<JunctionServer> => {\n const { port, host, corpus: source, ...rest } = options\n const corpus = await loadCorpus(source ?? \"default\")\n const runtime = createRuntime({ ...rest, ...(corpus ? { corpus } : {}) })\n const listening = await listen(runtime, {\n port: port ?? 0,\n ...(host !== undefined ? { host } : {}),\n })\n return { ...listening, runtime }\n}\n\nconst asString = (value: string | boolean | undefined): string | undefined =>\n typeof value === \"string\" && value !== \"\" ? value : undefined\n\nconst UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\nconst count = (value: string | undefined, flag: string): number | undefined => {\n if (value === undefined) return undefined\n if (!/^\\d+$/.test(value)) throw new Error(`${flag} must be a non-negative integer (got ${value})`)\n return Number.parseInt(value, 10)\n}\n\nconst readJson = async <T>(path: string): Promise<T> => {\n const raw = await readFile(path, \"utf8\").catch(() => undefined)\n if (raw === undefined) throw new Error(`junction mock: file not found: ${path}`)\n try {\n return JSON.parse(raw) as T\n } catch (error) {\n throw new Error(`junction mock: ${path} is not JSON (${(error as Error).message})`)\n }\n}\n\nconst retryDelays = (value: string | undefined): number[] | undefined => {\n if (value === undefined) return undefined\n const delays = value.split(\",\").map((part) => Number.parseInt(part.trim(), 10))\n if (delays.some((delay) => !Number.isFinite(delay) || delay < 0)) {\n throw new Error(`--webhook-retry-delays must be comma-separated milliseconds (got ${value})`)\n }\n return delays\n}\n\n/** `--default-billing-type bioreference=patient_bill_passthrough,quest=client_bill`. */\nconst billingDefaults = (value: string | undefined): Record<string, BillingType> | undefined => {\n if (value === undefined) return undefined\n const entries = value.split(\",\").map((part) => part.split(\"=\").map((side) => side.trim()))\n if (entries.some((entry) => entry.length !== 2 || !entry[0] || !entry[1])) {\n throw new Error(`--default-billing-type must be lab=billing_type pairs (got ${value})`)\n }\n try {\n return defaultBillingTypesFrom(Object.fromEntries(entries))\n } catch (error) {\n throw new Error(`--default-billing-type: ${(error as Error).message}`)\n }\n}\n\n/** How `serve` (and `serve --config`) builds the Junction mock from flags. */\nexport const serveTarget: ServeTarget = {\n name: \"junction\",\n defaultPort: DEFAULT_PORT,\n options: {\n corpus: {\n type: \"string\",\n value: \"<default|none|file>\",\n description: \"Corpus to serve: the shipped one, none (synthetic), or a pulled file\",\n default: \"default\",\n },\n geo: {\n type: \"string\",\n value: \"<corpus|synthetic>\",\n description: \"Unknown ZIPs: refuse (corpus) or invent coverage (synthetic)\",\n },\n \"lab-accounts\": {\n type: \"string\",\n value: \"<file>\",\n description:\n 'Lab accounts to route orders through: a JSON array, or { \"presets\": [...], \"accounts\": [...] }',\n },\n \"team-id\": {\n type: \"string\",\n value: \"<uuid>\",\n description: \"Team the mock answers as (default: the corpus's recorded team)\",\n },\n \"max-users\": {\n type: \"string\",\n value: \"<n>\",\n description: \"Enforce the sandbox's live-user cap (default: unlimited)\",\n },\n identity: {\n type: \"string\",\n value: \"<strict|adopt-users>\",\n description: \"Unknown user ids: 404 (strict) or create on first use\",\n default: \"strict\",\n },\n \"default-billing-type\": {\n type: \"string\",\n value: \"<lab=type,\u2026>\",\n description:\n \"billing_type an order for that lab gets when it omits one (default: client_bill), e.g. bioreference=patient_bill_passthrough\",\n },\n fixtures: {\n type: \"string\",\n value: \"<file>\",\n description:\n 'Users and orders every namespace starts with: { \"users\": [...], \"orders\": [...] }',\n },\n \"journal-size\": {\n type: \"string\",\n value: \"<n>\",\n description: \"Requests each namespace's journal keeps (GET /__admin/requests)\",\n default: \"1000\",\n },\n \"seed-url\": {\n type: \"string\",\n value: \"<url>\",\n description: \"Pull a corpus from this Junction team at boot (prefer a committed corpus)\",\n },\n \"seed-key\": {\n type: \"string\",\n value: \"<key>\",\n description: \"API key for --seed-url (env MOCKINGBIRD_JUNCTION_SEED_KEY)\",\n },\n \"webhook-url\": { type: \"string\", value: \"<url>\", description: \"Deliver signed webhooks here\" },\n \"webhook-secret\": {\n type: \"string\",\n value: \"<whsec_\u2026>\",\n description: \"Svix signing secret (env MOCKINGBIRD_JUNCTION_WEBHOOK_SECRET)\",\n },\n \"webhook-retry-delays\": {\n type: \"string\",\n value: \"<ms,ms,\u2026>\",\n description: \"Delay before each delivery attempt (default: Svix's schedule)\",\n },\n \"webhook-scope\": {\n type: \"string\",\n value: \"<scope>\",\n description: \"Sent as x-mockingbird-scope on every delivery\",\n },\n },\n async create(values: CliValues, common) {\n const seedUrl = asString(values[\"seed-url\"])\n const seedKey = asString(values[\"seed-key\"]) ?? process.env.MOCKINGBIRD_JUNCTION_SEED_KEY\n let corpus: SealedCorpus | undefined\n if (seedUrl !== undefined) {\n if (seedKey === undefined) throw new Error(\"--seed-url needs --seed-key\")\n console.log(\n `junction pulling a corpus from ${seedUrl} (commit one with \\`corpus pull\\` to skip this)`,\n )\n corpus = await pullCorpus({ baseUrl: seedUrl, apiKey: seedKey })\n } else {\n corpus = await loadCorpus(asString(values.corpus) ?? \"default\")\n }\n const geo = asString(values.geo)\n if (geo !== undefined && geo !== \"corpus\" && geo !== \"synthetic\") {\n throw new Error(`--geo must be corpus or synthetic (got ${geo})`)\n }\n const accountsFile = asString(values[\"lab-accounts\"])\n const labAccounts =\n accountsFile === undefined ? undefined : await readJson<LabAccountLayout>(accountsFile)\n const fixturesFile = asString(values.fixtures)\n const fixtures =\n fixturesFile === undefined ? undefined : await readJson<JunctionFixtures>(fixturesFile)\n const teamId = asString(values[\"team-id\"])\n if (teamId !== undefined && !UUID.test(teamId)) {\n throw new Error(`--team-id must be a UUID (got ${teamId})`)\n }\n const maxUsers = count(asString(values[\"max-users\"]), \"--max-users\")\n const journalSize = count(asString(values[\"journal-size\"]), \"--journal-size\")\n const identity = asString(values.identity)\n if (identity !== undefined && !IDENTITY_MODES.includes(identity as IdentityMode)) {\n throw new Error(`--identity must be one of ${IDENTITY_MODES.join(\", \")} (got ${identity})`)\n }\n const defaultBillingTypes = billingDefaults(asString(values[\"default-billing-type\"]))\n const webhookUrl = asString(values[\"webhook-url\"])\n const webhookSecret =\n asString(values[\"webhook-secret\"]) ?? process.env.MOCKINGBIRD_JUNCTION_WEBHOOK_SECRET\n if (webhookUrl !== undefined && webhookSecret === undefined) {\n throw new Error(\"--webhook-url needs --webhook-secret (the whsec_\u2026 your receiver verifies)\")\n }\n const delays = retryDelays(asString(values[\"webhook-retry-delays\"]))\n const scope = asString(values[\"webhook-scope\"])\n return createRuntime({\n ...(corpus ? { corpus } : {}),\n ...(geo ? { geo: geo as GeoMode } : {}),\n ...(labAccounts ? { labAccounts } : {}),\n ...(fixtures ? { fixtures } : {}),\n ...(teamId !== undefined ? { teamId } : {}),\n ...(maxUsers !== undefined ? { limits: { maxUsers } } : {}),\n ...(identity !== undefined ? { identity: identity as IdentityMode } : {}),\n ...(defaultBillingTypes ? { defaultBillingTypes } : {}),\n ...(journalSize !== undefined ? { journalSize } : {}),\n ...(webhookUrl !== undefined && webhookSecret !== undefined\n ? {\n webhooks: {\n url: webhookUrl,\n secret: webhookSecret,\n ...(delays ? { retryDelaysMs: delays } : {}),\n ...(scope ? { headers: { \"x-mockingbird-scope\": scope } } : {}),\n },\n }\n : {}),\n ...(common.adminKey !== undefined ? { adminKey: common.adminKey } : {}),\n ...(common.seed !== undefined ? { seed: common.seed } : {}),\n ...(common.onLog ? { onLog: common.onLog } : {}),\n })\n },\n banner(runtime) {\n const junction = runtime as JunctionRuntime\n const api = junction.instance()\n const info = api.corpusInfo()\n return [\n info\n ? `corpus ${info.label}: ${info.observations} observations, ${info.zips} ZIPs, ${info.labTests} lab tests, ${info.labAccounts} lab accounts (recorded ${info.recordedAt} from ${info.source})`\n : \"corpus none: synthetic catalog and coverage\",\n `geo ${api.geoMode}${api.geoMode === \"corpus\" ? \" (unknown ZIPs answer 424 MOCKINGBIRD_UNKNOWN_ZIP)\" : \"\"}`,\n `team ${api.teamId}`,\n `lab accounts: ${api.labAccounts().length}`,\n `limits: ${\n Object.entries(api.limits)\n .filter(([, value]) => value !== null && value !== false)\n .map(([key, value]) => `${key}=${String(value)}`)\n .join(\", \") || \"none (sandbox caps off)\"\n }`,\n `identity ${api.identity}`,\n `webhooks: ${junction.webhooks ? \"signed delivery on\" : \"off\"}`,\n \"auth: any x-vital-api-key value (e.g. sk_us_mockingbird)\",\n ]\n },\n}\n", "import { readFile } from \"node:fs/promises\"\nimport { type ParseArgsConfig, parseArgs } from \"node:util\"\nimport type { RequestLog, ServiceInstance, ServiceRuntime } from \"@crvouga/mockingbird-service\"\nimport { type Listening, listen } from \"./listen.js\"\n\nexport type CliOption = {\n type: \"string\" | \"boolean\"\n description: string\n /** Shown in help; the value placeholder, e.g. `<port>`. */\n value?: string\n default?: string | boolean\n}\n\nexport type CliValues = Record<string, string | boolean | undefined>\n\nexport type CliCommand = {\n summary: string\n usage?: string\n options?: Record<string, CliOption>\n /** Resolves to an exit code; a server command resolves only when it stops. */\n run(values: CliValues, positionals: string[]): Promise<number>\n}\n\nexport type CliSpec = {\n bin: string\n description: string\n commands: Record<string, CliCommand>\n}\n\nconst optionHelp = (options: Record<string, CliOption>): string[] =>\n Object.entries(options).map(([name, option]) => {\n const flag = `--${name}${option.type === \"string\" ? ` ${option.value ?? \"<value>\"}` : \"\"}`\n const fallback = option.default !== undefined ? ` (default: ${String(option.default)})` : \"\"\n return ` ${flag.padEnd(30)} ${option.description}${fallback}`\n })\n\nconst help = (spec: CliSpec): string =>\n [\n `${spec.bin} \u2014 ${spec.description}`,\n \"\",\n \"Usage:\",\n ` ${spec.bin} <command> [options]`,\n \"\",\n \"Commands:\",\n ...Object.entries(spec.commands).map(([name, c]) => ` ${name.padEnd(30)} ${c.summary}`),\n \"\",\n `Run \\`${spec.bin} <command> --help\\` for a command's options.`,\n ].join(\"\\n\")\n\nconst commandHelp = (spec: CliSpec, name: string, command: CliCommand): string =>\n [\n `${spec.bin} ${name} \u2014 ${command.summary}`,\n \"\",\n \"Usage:\",\n ` ${command.usage ?? `${spec.bin} ${name} [options]`}`,\n ...(command.options ? [\"\", \"Options:\", ...optionHelp(command.options)] : []),\n ].join(\"\\n\")\n\n/** Parse `argv` against `spec` and run the chosen command. Resolves to an exit code. */\nexport const runCli = async (spec: CliSpec, argv: string[]): Promise<number> => {\n // Two-word commands (`corpus pull`) win over one-word ones.\n const pair = argv.length >= 2 ? `${argv[0]} ${argv[1]}` : undefined\n const words = pair !== undefined && spec.commands[pair] ? 2 : 1\n const name = words === 2 ? pair : argv[0]\n const rest = argv.slice(words)\n if (name === undefined || name === \"--help\" || name === \"-h\" || name === \"help\") {\n console.log(help(spec))\n return 0\n }\n const command = spec.commands[name]\n if (!command) {\n console.error(`${spec.bin}: unknown command ${JSON.stringify(name)}\\n\\n${help(spec)}`)\n return 2\n }\n if (rest.includes(\"--help\") || rest.includes(\"-h\")) {\n console.log(commandHelp(spec, name, command))\n return 0\n }\n let parsed: { values: CliValues; positionals: string[] }\n try {\n parsed = parseArgs({\n args: rest,\n allowPositionals: true,\n strict: true,\n options: Object.fromEntries(\n Object.entries(command.options ?? {}).map(([key, option]) => [\n key,\n {\n type: option.type,\n ...(option.default !== undefined ? { default: option.default } : {}),\n },\n ]),\n ) as ParseArgsConfig[\"options\"],\n }) as { values: CliValues; positionals: string[] }\n } catch (error) {\n console.error(\n `${spec.bin} ${name}: ${error instanceof Error ? error.message : String(error)}\\n\\n${commandHelp(spec, name, command)}`,\n )\n return 2\n }\n return command.run(parsed.values, parsed.positionals)\n}\n\n// \u2500\u2500 serve \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport type LogFormat = \"pretty\" | \"json\" | \"off\"\n\nexport type CommonServeOptions = {\n adminKey: string | undefined\n seed: string | undefined\n onLog: ((entry: RequestLog) => void) | undefined\n}\n\n/**\n * What a service contributes to `serve`: how to build its runtime from CLI flags,\n * and what to say at startup. Every service's `./server` entry exports one as\n * `serveTarget`, which is also how `serve --config` finds services by name.\n */\nexport type ServeTarget = {\n name: string\n defaultPort: number\n /** Serve flags beyond the common ones. */\n options?: Record<string, CliOption>\n create(\n values: CliValues,\n common: CommonServeOptions,\n ): Promise<ServiceRuntime<ServiceInstance>> | ServiceRuntime<ServiceInstance>\n /** Startup lines after the listen address, e.g. the loaded corpus version. */\n banner?(runtime: ServiceRuntime<ServiceInstance>): string[]\n}\n\nconst COMMON_SERVE_OPTIONS: Record<string, CliOption> = {\n port: { type: \"string\", value: \"<port>\", description: \"Port to listen on\" },\n host: { type: \"string\", value: \"<host>\", description: \"Interface to bind\", default: \"127.0.0.1\" },\n \"admin-key\": {\n type: \"string\",\n value: \"<key>\",\n description: \"Require x-mockingbird-admin-key on /__admin/* (env MOCKINGBIRD_ADMIN_KEY)\",\n },\n seed: { type: \"string\", value: \"<seed>\", description: \"Seed for every random choice\" },\n log: {\n type: \"string\",\n value: \"<pretty|json|off>\",\n description: \"Request log format\",\n default: \"pretty\",\n },\n \"log-requests\": {\n type: \"boolean\",\n description:\n \"One JSON line per request: namespace, operationId, status, ids touched (never bodies). Same as --log json\",\n },\n config: {\n type: \"string\",\n value: \"<file>\",\n description: \"Serve every service in a mockingbird.json config instead\",\n },\n}\n\nconst formatLog = (format: LogFormat) => {\n if (format === \"off\") return undefined\n if (format === \"json\") return (entry: RequestLog) => console.log(JSON.stringify(entry))\n return (entry: RequestLog) => {\n const op = entry.operationId ?? (entry.unmatched ? \"UNMATCHED\" : \"-\")\n const ns = entry.namespace === \"default\" ? \"\" : ` [${entry.namespace}]`\n const fault = entry.faultId ? ` fault=${entry.faultId}` : \"\"\n const adopted = entry.adopted ? \" adopted\" : \"\"\n // A rejection says what arrived (never the body) and why the service refused it.\n const received = entry.request\n ? ` received=${entry.request.bodyBytes === null ? \"?\" : `${entry.request.bodyBytes}B`} ct=${entry.request.contentType ?? \"-\"}${\n entry.request.transferEncoding ? ` te=${entry.request.transferEncoding}` : \"\"\n }`\n : \"\"\n const issues = entry.issues?.length\n ? ` issues=${entry.issues\n .slice(0, 3)\n .map((issue) => `${issue.path || \"$\"}: ${issue.message}`)\n .join(\"; \")}${entry.issues.length > 3 ? ` (+${entry.issues.length - 3})` : \"\"}`\n : \"\"\n console.log(\n `${entry.service} ${entry.method} ${entry.path} ${entry.status} ${op} ${entry.durationMs}ms${ns}${fault}${adopted}${received}${issues}`,\n )\n }\n}\n\nconst asString = (value: string | boolean | undefined): string | undefined =>\n typeof value === \"string\" ? value : undefined\n\n/** A service entry in `mockingbird.json`. */\nexport type ConfigService = {\n port?: number\n host?: string\n adminKey?: string\n seed?: string\n /** Service-specific serve flags, by long name: `{ \"webhook-url\": \"\u2026\" }`. */\n options?: Record<string, string | boolean>\n}\n\nexport type MockingbirdConfig = {\n /** Keyed by service name: `junction` loads `@crvouga/mockingbird-service-junction`. */\n services: Record<string, ConfigService>\n log?: LogFormat\n}\n\nconst loadTarget = async (name: string, own: ServeTarget): Promise<ServeTarget> => {\n if (name === own.name) return own\n const specifier = `@crvouga/mockingbird-service-${name}/server`\n try {\n const mod = (await import(specifier)) as { serveTarget?: ServeTarget }\n if (!mod.serveTarget) throw new Error(`${specifier} exports no serveTarget`)\n return mod.serveTarget\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(\n `cannot load service \"${name}\": ${reason}. Install @crvouga/mockingbird-service-${name}.`,\n )\n }\n}\n\nconst start = async (\n target: ServeTarget,\n values: CliValues,\n config: { port: number; host: string; adminKey?: string; seed?: string; log: LogFormat },\n): Promise<Listening> => {\n const runtime = await target.create(values, {\n adminKey: config.adminKey,\n seed: config.seed,\n onLog: formatLog(config.log),\n })\n const listening = await listen(runtime, { port: config.port, host: config.host })\n console.log(`${target.name} mock listening on ${listening.url}`)\n console.log(`${target.name} health: GET ${listening.url}/health`)\n console.log(\n `${target.name} admin: ${listening.url}/__admin (${config.adminKey ? \"x-mockingbird-admin-key required\" : \"open \u2014 pass --admin-key to lock\"})`,\n )\n for (const line of target.banner?.(runtime) ?? []) console.log(`${target.name} ${line}`)\n return listening\n}\n\nconst untilSignal = async (servers: Listening[]): Promise<number> =>\n new Promise((resolve) => {\n const stop = async () => {\n await Promise.allSettled(servers.map((s) => s.close()))\n resolve(0)\n }\n process.once(\"SIGINT\", stop)\n process.once(\"SIGTERM\", stop)\n })\n\n/** The standard `serve` command for a service, including multi-service `--config`. */\nexport const serveCommand = (target: ServeTarget): CliCommand => ({\n summary: `Serve the ${target.name} mock over HTTP`,\n options: { ...COMMON_SERVE_OPTIONS, ...target.options },\n async run(values) {\n const log = (\n values[\"log-requests\"] === true ? \"json\" : (asString(values.log) ?? \"pretty\")\n ) as LogFormat\n if (![\"pretty\", \"json\", \"off\"].includes(log)) {\n console.error(`--log must be pretty, json or off (got ${log})`)\n return 2\n }\n const configPath = asString(values.config)\n if (configPath !== undefined) {\n const config = JSON.parse(await readFile(configPath, \"utf8\")) as MockingbirdConfig\n const servers: Listening[] = []\n try {\n for (const [name, entry] of Object.entries(config.services ?? {})) {\n const each = await loadTarget(name, target)\n servers.push(\n await start(each, entry.options ?? {}, {\n port: entry.port ?? each.defaultPort,\n host: entry.host ?? \"127.0.0.1\",\n ...(entry.adminKey !== undefined ? { adminKey: entry.adminKey } : {}),\n ...(entry.seed !== undefined ? { seed: entry.seed } : {}),\n log: config.log ?? log,\n }),\n )\n }\n } catch (error) {\n await Promise.allSettled(servers.map((s) => s.close()))\n console.error(error instanceof Error ? error.message : String(error))\n return 1\n }\n return untilSignal(servers)\n }\n const port = asString(values.port)\n const adminKey = asString(values[\"admin-key\"]) ?? process.env.MOCKINGBIRD_ADMIN_KEY\n const seed = asString(values.seed)\n let listening: Listening\n try {\n listening = await start(target, values, {\n port: port === undefined ? target.defaultPort : Number.parseInt(port, 10),\n host: asString(values.host) ?? \"127.0.0.1\",\n ...(adminKey !== undefined ? { adminKey } : {}),\n ...(seed !== undefined ? { seed } : {}),\n log,\n })\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n return 1\n }\n return untilSignal([listening])\n },\n})\n", "import { createServer } from \"node:http\"\nimport type { FetchAPI } from \"@crvouga/mockingbird-core\"\n\n/** Options for {@link serve}. */\nexport type NodeServeOptions = {\n port?: number\n host?: string\n}\n\n/**\n * Serve any Mockingbird {@link FetchAPI} over `node:http`.\n * Port defaults to `0`, so the OS assigns an ephemeral port (read from `server.address()`).\n */\nexport const serve = async (api: FetchAPI, options: NodeServeOptions = {}) => {\n const server = createServer(async (req, res) => {\n const chunks: Buffer[] = []\n for await (const chunk of req) {\n chunks.push(Buffer.from(chunk))\n }\n const body = Buffer.concat(chunks)\n const address = server.address()\n const port = typeof address === \"object\" && address !== null ? address.port : undefined\n const base = `http://${req.headers.host ?? `localhost:${port ?? 80}`}`\n const raw = req.url ?? \"/\"\n const url = new URL(raw.replace(/^\\/+/, \"/\"), base)\n const method = req.method ?? \"GET\"\n const init: RequestInit = { method, headers: req.headers as Record<string, string> }\n if (method !== \"GET\" && method !== \"HEAD\" && body.length > 0) {\n init.body = body\n }\n const aborted = new AbortController()\n res.once(\"close\", () => {\n if (!res.writableFinished) aborted.abort()\n })\n init.signal = aborted.signal\n const request = new Request(url, init)\n let response: Response\n try {\n response = await api.fetch(request)\n } catch (error) {\n // A `drop` fault: destroy the socket so the client sees the connection die.\n if ((error as { code?: string }).code === \"MOCKINGBIRD_DROP\") {\n req.socket.destroy()\n return\n }\n res.writeHead(500, { \"content-type\": \"application/json\" })\n res.end(\n JSON.stringify({\n error: {\n type: \"mockingbird_internal\",\n message: error instanceof Error ? error.message : String(error),\n },\n }),\n )\n return\n }\n // Headers#entries() joins repeated headers; Set-Cookie must stay one header per cookie.\n const headers: Record<string, string | string[]> = Object.fromEntries(response.headers)\n const cookies = response.headers.getSetCookie()\n if (cookies.length > 0) headers[\"set-cookie\"] = cookies\n if (!response.body) {\n res.writeHead(response.status, headers)\n res.end()\n return\n }\n // Stream the body chunk by chunk: event streams and long-polls must not be buffered.\n res.writeHead(response.status, headers)\n res.flushHeaders()\n const reader = response.body.getReader()\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n if (!res.write(value)) await new Promise<void>((resolve) => res.once(\"drain\", resolve))\n }\n res.end()\n } catch {\n res.destroy()\n } finally {\n reader.releaseLock()\n }\n })\n await new Promise<void>((resolve, reject) => {\n server.once(\"error\", reject)\n server.listen(options.port ?? 0, options.host, resolve)\n })\n return server\n}\n", "import type { Server } from \"node:http\"\nimport type { FetchAPI } from \"@crvouga/mockingbird-core\"\nimport { serve } from \"./serve.js\"\n\nexport type ListenOptions = {\n /** Default `0`: the OS picks a free port. */\n port?: number\n /** Default `127.0.0.1`: a mock should not be reachable off the machine by accident. */\n host?: string\n}\n\n/** A running server, with the address it actually bound. */\nexport type Listening = {\n url: string\n port: number\n host: string\n server: Server\n close(): Promise<void>\n}\n\nexport const listen = async (api: FetchAPI, options: ListenOptions = {}): Promise<Listening> => {\n const host = options.host ?? \"127.0.0.1\"\n const server = await serve(api, { port: options.port ?? 0, host })\n const address = server.address()\n const port = typeof address === \"object\" && address !== null ? address.port : (options.port ?? 0)\n const shown = host.includes(\":\") ? `[${host}]` : host\n return {\n url: `http://${shown}:${port}`,\n port,\n host,\n server,\n close: () =>\n new Promise<void>((resolve, reject) => {\n // Stop accepting first, then drop keep-alive sockets so close() can finish.\n server.close((error) => {\n if (error && (error as { code?: string }).code !== \"ERR_SERVER_NOT_RUNNING\") reject(error)\n else resolve()\n })\n server.closeAllConnections?.()\n }),\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AACA,SAAS,YAAAA,iBAAgB;;;ACDzB,SAAS,gBAAgB;AACzB,SAA+B,iBAAiB;;;ACDhD,SAAS,oBAAoB;AAatB,IAAM,QAAQ,OAAO,KAAe,UAA4B,CAAA,MAAM;AAC3E,QAAM,SAAS,aAAa,OAAO,KAAK,QAAO;AAC7C,UAAM,SAAmB,CAAA;AACzB,qBAAiB,SAAS,KAAK;AAC7B,aAAO,KAAK,OAAO,KAAK,KAAK,CAAC;IAChC;AACA,UAAM,OAAO,OAAO,OAAO,MAAM;AACjC,UAAM,UAAU,OAAO,QAAO;AAC9B,UAAM,OAAO,OAAO,YAAY,YAAY,YAAY,OAAO,QAAQ,OAAO;AAC9E,UAAM,OAAO,UAAU,IAAI,QAAQ,QAAQ,aAAa,QAAQ,EAAE,EAAE;AACpE,UAAM,MAAM,IAAI,OAAO;AACvB,UAAM,MAAM,IAAI,IAAI,IAAI,QA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