@crvouga/mockingbird-service-stripe 0.1.2 → 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,32 @@
1
+ # Changelog — @crvouga/mockingbird-service-stripe
2
+
3
+ ## 0.2.0 (2026-09-21)
4
+
5
+ ### Features
6
+
7
+ - serve command and the shared service contract ([44b100d](https://github.com/crvouga/mockingbird/commit/44b100daa132da262b0098bdfbaadb5d739de41a))
8
+ - one service contract — health, admin, namespaces, clock, faults, metrics ([fea7dd1](https://github.com/crvouga/mockingbird/commit/fea7dd169cc16d11baebba38dced7f630f725714))
9
+
10
+ ### Fixes and improvements
11
+
12
+ - scope admin-injected faults to the calling namespace ([3c1d573](https://github.com/crvouga/mockingbird/commit/3c1d573ac0c404324bbd20855a5ac7a2cd50f738))
13
+ - take the admin namespace override only on admin routes ([37836a5](https://github.com/crvouga/mockingbird/commit/37836a5b0c51d17dd24e7b01c12dd6d8049646da))
14
+ - state what each mock does not model ([ee84a7d](https://github.com/crvouga/mockingbird/commit/ee84a7d7acc1944a3b3534d33288279ca990cbe3))
15
+
16
+ ### Dependencies
17
+
18
+ - `@crvouga/mockingbird-service-sqlite`
19
+
20
+ ## 0.1.2 (2026-09-19)
21
+
22
+ ### Fixes and improvements
23
+
24
+ - publish only mock services and bundle their private helpers ([f13120b](https://github.com/crvouga/mockingbird/commit/f13120b70596feb4341f1b5822060882a629952c))
25
+
26
+ ## 0.1.1 (2026-09-19)
27
+
28
+ Dependency updates only.
29
+
30
+ ## 0.1.0 (2026-09-19)
31
+
32
+ Initial release.
package/README.md CHANGED
@@ -25,8 +25,8 @@ npm install -D @crvouga/mockingbird-service-stripe
25
25
  ```
26
26
 
27
27
  ESM only. Requires Node >= 22 or Bun >= 1.2. No native dependencies: state lives in an in-memory
28
- SQLite engine (pure TypeScript, bundled in). To serve it over HTTP use `Bun.serve` under Bun, or
29
- install `@hono/node-server` under Node.
28
+ SQLite engine (pure TypeScript, bundled in). To serve it over HTTP run `npx mockingbird-stripe serve`, or
29
+ use `createServer` from `./server` (Node) or `createRuntime` with any Fetch server.
30
30
 
31
31
  ## Usage
32
32
 
@@ -44,6 +44,38 @@ Behaviour the examples rely on (all from the source):
44
44
  - `Idempotency-Key` on POSTs is honoured: a replay returns the cached response, a replay with
45
45
  different parameters returns 400.
46
46
 
47
+ ### Serve it: `mockingbird-stripe serve` or `createServer`
48
+
49
+ ```bash
50
+ npx mockingbird-stripe serve # http://127.0.0.1:12111
51
+ npx mockingbird-stripe serve --port 0 --log json --admin-key local-admin
52
+ npx mockingbird-stripe serve --config mockingbird.json # every service in one config
53
+ ```
54
+
55
+ ```ts
56
+ import { createServer } from "@crvouga/mockingbird-service-stripe/server"
57
+
58
+ const server = await createServer() // any free port; server.url, server.port
59
+ const response = await fetch(`${server.url}/v1/products?limit=3`, { headers: { authorization: "Bearer sk_test_mockingbird" } })
60
+ console.log(response.status) // 200
61
+ await server.close()
62
+ ```
63
+
64
+ Served this way — or through `createRuntime()`, the same thing as one runtime-neutral `fetch` —
65
+ the mock also answers Mockingbird's service contract, outside Stripe's bearer-key check:
66
+
67
+ - `GET /health` — unauthenticated readiness probe.
68
+ - `/__admin/*` — reset (`POST /__admin/reset`), snapshots (`POST /__admin/snapshots`,
69
+ `POST /__admin/snapshots/{id}/restore`), clock (`POST /__admin/clock {"advance": "2h"}`), fault
70
+ injection (`POST /__admin/faults {"operationId": …, "status": 503, "count": 1}`), and metrics with
71
+ unmatched-route counts (`GET /__admin/metrics`). `GET /__admin` lists every route; `--admin-key`
72
+ locks them behind `x-mockingbird-admin-key`.
73
+ - `x-mockingbird-namespace: <name>` — isolates a request's data, so parallel workers share one
74
+ process without seeing each other.
75
+
76
+ The [Junction README](https://github.com/crvouga/mockingbird/tree/main/packages/service/junction#the-service-contract)
77
+ documents the contract in full.
78
+
47
79
  ### In-process (inject `fetch`)
48
80
 
49
81
  ```ts
@@ -93,17 +125,8 @@ console.log(response.status) // 200
93
125
  server.stop()
94
126
  ```
95
127
 
96
- On Node use any Fetch-style server, e.g. `@hono/node-server` (`npm install -D @hono/node-server`),
97
- whose callback receives the bound port:
98
-
99
- ```js
100
- import { serve } from "@hono/node-server"
101
- const server = serve(
102
- { fetch: (request) => stripe.fetch(request), port: 0, hostname: "127.0.0.1" },
103
- (info) => console.log(`http://127.0.0.1:${info.port}`),
104
- )
105
- // ... later: server.close()
106
- ```
128
+ On Node, `createServer` (above) is the listener; any Fetch-style server also works with
129
+ `StripeAPI#fetch` or `createRuntime().fetch`.
107
130
 
108
131
  ### Pointing stripe-node at it
109
132
 
@@ -122,7 +145,8 @@ const client = new Stripe("sk_test_mockingbird", {
122
145
  await client.customers.create({ email: "qa@example.com" })
123
146
  ```
124
147
 
125
- Add a base-URL override (e.g. `STRIPE_API_BASE_URL=http://127.0.0.1:12111`) at every place your app
148
+ With `mockingbird-stripe serve` on port 12111, host, port and protocol are the only wiring. Add a
149
+ base-URL override (e.g. `STRIPE_API_BASE_URL=http://127.0.0.1:12111`) at every place your app
126
150
  constructs a Stripe client; a client built with `new Stripe(key)` and no options cannot be
127
151
  redirected. Test payment methods and tokens such as `pm_card_visa`, `pm_card_authenticationRequired`
128
152
  and `tok_chargeDeclinedInsufficientFunds` behave like their Stripe counterparts
@@ -182,6 +206,19 @@ test("starts empty", async () => {
182
206
  })
183
207
  ```
184
208
 
209
+ ## What is and is not modelled
210
+
211
+ - **Modelled**: the 88 operations in [SUPPORT.md](https://github.com/crvouga/mockingbird/blob/main/packages/service/stripe/SUPPORT.md),
212
+ whose behaviour is checked by live parity against Stripe test mode; state partitioned per API key;
213
+ the test payment methods and card tokens listed above.
214
+ - **Not modelled**: the 20 operations SUPPORT.md marks unsupported, each with its reason; Stripe.js
215
+ and hosted checkout (`js.stripe.com`, `checkout.stripe.com`); real rate-limit and 5xx bodies —
216
+ `POST /__admin/faults` injects Mockingbird's own, which are shape-plausible, not recorded;
217
+ anything outside the vendored spec, which 404s and is counted in `GET /__admin/metrics` under
218
+ `unmatched`.
219
+ - **Determinism**: with a fixed clock and `seed`, ids and timestamps replay exactly — two runtimes
220
+ given the same clock produce the same `cus_…` ids and `created` values.
221
+
185
222
  ## API
186
223
 
187
224
  `StripeAPI` is the main export; the rest supports account scoping, contract introspection and the
@@ -189,6 +226,7 @@ QA corpus used by the parity suites.
189
226
 
190
227
  | Export | Description |
191
228
  | --- | --- |
229
+ | `createRuntime` | `(options?) => StripeRuntime` — the mock with the service contract (health, admin, namespaces, clock, faults, metrics) as one runtime-neutral `fetch`. Options: `sqlite`, `clock`, `seed`, `adminKey`, `onLog`, `onWebhook`. `./server` adds `createServer(options?)` (Node; `port`, `host`), `serveTarget` and `DEFAULT_PORT` (`12111`). |
192
230
  | `StripeAPI` | Class. `new StripeAPI(options?)`; implements the Fetch contract `fetch(request: Request): Promise<Response>`. |
193
231
  | `accountOfKey` | `(key: string) => string` — the opaque `acct_...` partition id for an API key (use it to filter `webhookEvents`). |
194
232
  | `accountOf` | `(request: Request) => string` — the partition id for a request's bearer key. |