@crvouga/mockingbird-service-lifefile 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog — @crvouga/mockingbird-service-lifefile
2
+
3
+ ## 0.2.0 (2026-10-21)
4
+
5
+ ### Features
6
+
7
+ - add manual response controls ([4599960](https://github.com/crvouga/mockingbird/commit/45999603e8b860c633181367afc7baa906ba486b))
8
+
9
+ ## 0.1.0 (2026-10-21)
10
+
11
+ Initial release.
package/DISCOVERY.md ADDED
@@ -0,0 +1,78 @@
1
+ # @crvouga/mockingbird-service-lifefile discovery
2
+
3
+ This is the installed-package index for coding agents and tooling. All relative links resolve
4
+ inside `node_modules/@crvouga/mockingbird-service-lifefile/`; no repository checkout is needed to discover the emulator's
5
+ supported surface or documented behavior.
6
+
7
+ ## Capability and behavior sources
8
+
9
+ | Question | Authoritative file | What it contains |
10
+ | --- | --- | --- |
11
+ | Behaviour and integration | [`README.md`](README.md) | Routes, state transitions, auth, webhooks, controls, presets and deliberate omissions. |
12
+ | Exact capabilities | [`SUPPORT.md`](SUPPORT.md) | Supported, unsupported and parity-covered operations or commands, including reasons for gaps. |
13
+ | Wire contract | [`openapi.yaml`](openapi.yaml) | Machine-readable paths, methods, schemas, responses and parity annotations. |
14
+ | Public API | [`dist/index.d.ts`](dist/index.d.ts) | The installed package's exact TypeScript exports and signatures. |
15
+ | Package metadata | [`package.json`](package.json) | Runtime/entry-point claims, vendor links, parity scope/tier and `mockingbird.discovery`. |
16
+
17
+ Read these together: the contract/capability matrix says *what* is available, while the README
18
+ defines stateful behavior, lifecycle rules, test controls, and intentional oracle differences.
19
+ If prose and an executable surface disagree, report a parity mismatch instead of adding a
20
+ consumer-side workaround.
21
+
22
+ ## Parity and oracle
23
+
24
+ - Declared parity surface: **Orders, cancellation and Data Push (best guess)**.
25
+ - Parity tier: **cold** (the repository controls when live checks run).
26
+ - Oracle: **Live vendor API or sandbox**.
27
+ - Repository command: `bun run parity:service -- lifefile`.
28
+ - Evidence model: Run from a Mockingbird checkout; credentials come only from .env.local or GitHub Actions secrets. Missing credentials exit 2.
29
+
30
+ The npm package contains evidence summaries and the exact contract, not credentials or the
31
+ repository-only parity harness. Self-parity/property and acceptance tests run in the Mockingbird
32
+ repository; live parity is an additional oracle check, not a substitute for the packaged matrix.
33
+
34
+ ## Runtime introspection
35
+
36
+ - `GET /__admin/health`
37
+ - `GET /__admin`
38
+ - `GET /__admin/controls`
39
+ - `GET /__admin/state`
40
+ - `GET /__admin/requests`
41
+ - `GET /__admin/metrics`
42
+ - `GET /__admin/faults/presets`
43
+ - `GET /__admin/ui`
44
+
45
+ For HTTP services, use `x-mockingbird-namespace` (or the documented credential/path carrier) so
46
+ parallel tests do not share state. Admin state, journal, metrics and fault-preset endpoints are
47
+ designed for assertions and diagnosis by consuming test suites.
48
+
49
+ ## Admin controls
50
+
51
+ Every HTTP emulator takes the same controls, and each means the same thing at boot
52
+ (`createRuntime({ adminControls })`, `serve --admin-controls`), over `/__admin`, and in a request header:
53
+
54
+ | Control | Admin API | Request header | Interface |
55
+ | --- | --- | --- | --- |
56
+ | Isolate state by key | `GET /__admin/namespaces` | `x-mockingbird-namespace: <key>` | [Namespaces](https://mockingbird.chrisvouga.dev/docs/admin-controls/namespaces) |
57
+ | Reset to boot | `POST /__admin/reset` | `x-mockingbird-reset: true` | [Reset](https://mockingbird.chrisvouga.dev/docs/admin-controls/reset) |
58
+ | Snapshot and restore | `POST /__admin/snapshots`, `POST /__admin/snapshots/<id>/restore` | `x-mockingbird-snapshot: <name>`, `x-mockingbird-restore: <name>` | [Snapshot and restore](https://mockingbird.chrisvouga.dev/docs/admin-controls/snapshot-and-restore) |
59
+ | Move the clock | `POST /__admin/clock` | `x-mockingbird-time: <instant>`, `x-mockingbird-advance: <duration>` | [Clock](https://mockingbird.chrisvouga.dev/docs/admin-controls/clock) |
60
+ | Read or branch from old state | `GET /__admin/timeline` | `x-mockingbird-at: <checkpoint>`, `x-mockingbird-branch: <name>` | [Checkpoints and branches](https://mockingbird.chrisvouga.dev/docs/admin-controls/checkpoints-and-branches) |
61
+ | Inject a fault | `POST /__admin/faults` | `x-mockingbird-fault: <fault>` | [Faults](https://mockingbird.chrisvouga.dev/docs/admin-controls/faults) |
62
+ | Latency and timeouts | `PUT /__admin/latency` | `x-mockingbird-delay: <duration>`, `x-mockingbird-timeout: <duration>` | [Latency and timeouts](https://mockingbird.chrisvouga.dev/docs/admin-controls/latency-and-timeouts) |
63
+ | Replay from a seed | `PUT /__admin/controls` | `x-mockingbird-seed: <seed>` | [Seed and determinism](https://mockingbird.chrisvouga.dev/docs/admin-controls/seed-and-determinism) |
64
+ | See what happened | `GET /__admin/requests`, `GET /__admin/state` | | [Journal, metrics and state](https://mockingbird.chrisvouga.dev/docs/admin-controls/journal-and-state) |
65
+
66
+ `GET /__admin` lists every route and header with a one-line summary, and `GET /__admin/controls`
67
+ is the namespace's current control document. The same seed and the same requests give the same
68
+ bytes. Setting controls as an emulator starts is [Boot](https://mockingbird.chrisvouga.dev/docs/admin-controls/boot); every route and header is in
69
+ the [Reference](https://mockingbird.chrisvouga.dev/docs/admin-controls/reference). The full guide: <https://mockingbird.chrisvouga.dev/docs/admin-controls>.
70
+
71
+ ## Report a mismatch or missing capability
72
+
73
+ Follow the [agent reporting contract](https://github.com/crvouga/mockingbird/blob/main/docs/REPORTING_ISSUES.md). Include package version,
74
+ operation/command, a minimal redacted request, actual emulator result, expected oracle result or vendor
75
+ documentation, and whether the mismatch appears in the matrix. Never include keys, tokens,
76
+ customer data, prompts, PHI, card data, or unredacted recordings.
77
+
78
+ Service key: `lifefile`.
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ # @crvouga/mockingbird-service-lifefile
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Local emulators. Real API contracts. Part of [Mockingbird](https://github.com/crvouga/mockingbird).
4
+
5
+ Work-in-progress LifeFile pharmacy order gateway for synthetic integration tests. This is a
6
+ **best guess, not oracle-verified**. It models order submission, idempotency, configurable shipping
7
+ refusals, cancellation and Basic-auth Data Push without contacting a pharmacy.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ bun add -d @crvouga/mockingbird-service-lifefile
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Point your application's LifeFile base URL at the local server. Keep real pharmacy credentials
18
+ and patient data out of tests.
19
+
20
+ ```ts
21
+ import { createServer } from "@crvouga/mockingbird-service-lifefile/server"
22
+
23
+ const server = await createServer()
24
+ try {
25
+ const response = await fetch(`${server.url}/order`, {
26
+ method: "POST",
27
+ headers: {
28
+ authorization: `Basic ${btoa("test:test")}`,
29
+ "content-type": "application/json",
30
+ "X-Vendor-ID": "1",
31
+ "X-Location-ID": "1",
32
+ "X-API-Network-ID": "1",
33
+ },
34
+ body: JSON.stringify({
35
+ message: { id: 1 },
36
+ order: { general: { referenceId: "synthetic-order" }, shipping: { state: "AZ" } },
37
+ }),
38
+ })
39
+ if (!response.ok) throw new Error(`Order refused: ${response.status}`)
40
+ const result = await response.json()
41
+ if (result.type !== "success" || !result.data?.orderId) {
42
+ throw new Error(result.message ?? "Order rejected")
43
+ }
44
+ console.log(result.data.orderId)
45
+ } finally {
46
+ await server.close()
47
+ }
48
+ ```
49
+
50
+ ## Evidence and chosen contract
51
+
52
+ The public [Revelation Pharma integration example](https://github.com/RevelationPharma/lifefile-example)
53
+ provides primary integration source for the LifeFile order API: Basic authentication, the three
54
+ integer `X-*` headers, order creation, status updates and a Data Push receiver. It is a pharmacy's
55
+ integration example, not a complete vendor specification. The reporting consumer's client and
56
+ response schema supplied the `{type, message, data}` envelope, `data.orderId`, numeric `message.id`,
57
+ `order.general.referenceId` and `order.shipping.state` fields.
58
+
59
+ No live vendor responses were observed. Idempotency, rejection status/envelope details, duplicate
60
+ cancellation handling, shipping restrictions and push timing are deterministic emulator choices.
61
+ They are **best guesses, not oracle-verified**. Shipping restrictions are configured fixtures;
62
+ the default refusal list is empty and asserts no global vendor shipping policy.
63
+
64
+ `POST /order` returns an order id in `data.orderId`; repeating a `message.id` reuses its id.
65
+ Authentication and header/body validation failures do not create orders. The emulator stores
66
+ order metadata rather than patient, prescriber or prescription bodies.
67
+
68
+ `PUT /order/{id}/status` requires an explicitly configured `cancelStatus`. Without it the emulator
69
+ returns an explicit unsupported error (HTTP 501), with no state change. This is an emulator
70
+ limitation, not an observed LifeFile error. With it, the configured status is the cancellation
71
+ fixture contract; unknown orders and other requested statuses fail deterministically.
72
+
73
+ ## Deliberately not modelled
74
+
75
+ Real prescription processing, pharmacy fulfilment, clinical validation, payments, inventory,
76
+ account-specific shipping policy, production credentials and comprehensive vendor schemas.
77
+ There is no official JavaScript SDK pinned by the report; acceptance uses a fetch-based consumer.
78
+ Do not use this emulator as evidence that a real pharmacy accepted or cancelled an order.
79
+
80
+ ## Settings and test controls
81
+
82
+ `createRuntime({settings, webhooks})` and `createServer({settings, webhooks})` accept:
83
+
84
+ | Setting | Default | Behavior |
85
+ | --- | --- | --- |
86
+ | `accounts` | `[]` | With no fixtures, accept any nonempty Basic username/password. Otherwise require an exact configured `{username,password}` pair. |
87
+ | `refusedShippingStates` | `[]` | Reject matching `order.shipping.state` values with an error envelope and no order creation. |
88
+ | `cancelStatus` | `null` | Configure the exact status string used by cancellation requests; otherwise status updates return 501. |
89
+ | `pushFormat` | `"consumer"` | Provisional object `{orderId, referenceId?, status}`; `"vendor"` selects an array with `orderId`, `referenceId`, `rxStatus`, `rxStatusDateTime` based on the public pharmacy demo. Neither is oracle-verified. |
90
+ | `pushBeforeResponse` | `false` | Flush Data Push deliveries before completing the order response when enabled. |
91
+
92
+ Configure `webhooks: {url, username, password, fetch?}` for the receiver. The optional `fetch`
93
+ lets tests supply a local receiver. Production credentials are unnecessary. Orders start at
94
+ `Received`; configured cancellation transitions to `Cancelled`. Automatic push delivery and the
95
+ state transitions are emulator fixture behavior. Duplicate order submission reuses the id without
96
+ creating another order or sending a second push.
97
+
98
+ The standard admin prefix is `/__admin` (override with `adminPrefix`). Service controls are:
99
+
100
+ | Route | Behavior |
101
+ | --- | --- |
102
+ | `GET /orders` | Metadata-only order journal. |
103
+ | `GET /settings` | Current settings, with account passwords omitted. |
104
+ | `PUT /settings` | Update validated settings for the selected namespace. |
105
+ | `POST /orders/:id/push` | Change status and enqueue a push; body `{status, duplicate?, badCredentials?}`. |
106
+
107
+ These routes are relative to the admin prefix. Standard controls include `/requests`, `/state`,
108
+ `/faults`, `/webhooks/events` and `/webhooks/flush`. The webhook journal records delivery metadata
109
+ and payloads contain only the modeled order metadata. Request logs do not retain order bodies.
110
+
111
+ Fault presets are `reject` (business error envelope), `server_error` (500), `malformed` (invalid
112
+ JSON), `duplicate_push` and `bad_push_credentials`; standard `timeout` is also available. Apply
113
+ one through `POST /__admin/faults` with `{"preset":"reject"}`. For a particular reference, use
114
+ `{"operationId":"CreateOrder","requestBody":{"order.general.referenceId":"synthetic-order"},"effect":"reject"}`.
115
+ The same matcher scopes 500/malformed/timeout rules. Faults that refuse creation leave no order
116
+ or push behind. Duplicate and invalid-auth push controls deliberately exercise receiver handling.
117
+
118
+ Namespaces select isolated fixtures/state by `x-mockingbird-namespace`, by the standard
119
+ `/__admin/ns/<name>/` prefix, or by Basic username after mapping it through
120
+ `PUT /__admin/credentials`. Snapshots, reset and Timeline history use the shared runtime.
121
+
122
+ ## API
123
+
124
+ The package root exports `LifeFileAPI`, `createRuntime`, `LIFEFILE_NAMESPACE`, `basicUsername`,
125
+ `LIFEFILE_PRESETS`, `document`, `operationIds` and `supportedOperationIds`. `basicUsername(request)`
126
+ extracts the credential namespace carrier. `LifeFileAPI` supplies `fetch`, `reset` and `transition`;
127
+ `createRuntime` adds the standard admin controls and the `webhooks` hub.
128
+
129
+ Public types are `LifeFileAPIOptions`, `PushOptions`, `OrderRecord`, `Settings`, `OperationId`,
130
+ `SupportedOperationId`, `LifeFileRuntime` and `LifeFileRuntimeOptions`.
131
+
132
+ The `./server` entry exports `createServer`, `serveTarget` and `DEFAULT_PORT` (8819), plus types
133
+ `LifeFileServer` and `LifeFileServerOptions`. `createServer` listens on an ephemeral local port by
134
+ default and returns `{url, close, runtime, ...}`. The `mockingbird-lifefile serve` CLI uses the
135
+ fixed default port. `serveTarget` supports fleet hosting and the shared admin controls.
136
+
137
+ ## Live parity
138
+
139
+ `bun run parity:service -- lifefile` reports missing sandbox credentials by name. Required keys
140
+ are `LIFEFILE_API_URL`, `LIFEFILE_USERNAME`, `LIFEFILE_PASSWORD`, `LIFEFILE_VENDOR_ID`,
141
+ `LIFEFILE_LOCATION_ID` and `LIFEFILE_API_NETWORK_ID`, stored only in GitHub Actions secrets or
142
+ `.env.local`. None were available for this implementation. Every modeled operation can affect
143
+ a real pharmacy queue; the parity script refuses mutation without `--include-unsafe` and an
144
+ isolated sandbox. No live parity claim is made.
package/SUPPORT.md ADDED
@@ -0,0 +1,12 @@
1
+ # LifeFile order API (best-guess subset) — operation support
2
+
3
+ Generated from `openapi.yaml`; do not edit by hand.
4
+
5
+ - operations in spec: **2**
6
+ - supported by the emulator: **2**
7
+ - parity enabled: **2**
8
+
9
+ | operationId | route | emulator | parity | notes |
10
+ | --- | --- | --- | --- | --- |
11
+ | `CreateOrder` | `POST /order` | ✅ supported | ⚠️ unsafe (opt-in) | |
12
+ | `UpdateOrderStatus` | `PUT /order/{id}/status` | ✅ supported | ⚠️ unsafe (opt-in) | |