@crvouga/mockingbird-service-stripe 0.1.1 → 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.
Files changed (152) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +64 -20
  3. package/dist/chunk-I45CRFZX.js +5807 -0
  4. package/dist/chunk-I45CRFZX.js.map +7 -0
  5. package/dist/chunk-XJ7RQYFQ.js +287 -0
  6. package/dist/chunk-XJ7RQYFQ.js.map +7 -0
  7. package/dist/cli.js +19 -0
  8. package/dist/cli.js.map +7 -0
  9. package/dist/index.d.ts +583 -16
  10. package/dist/index.js +38 -171
  11. package/dist/index.js.map +7 -1
  12. package/dist/server.d.ts +621 -0
  13. package/dist/server.js +12 -0
  14. package/dist/server.js.map +7 -0
  15. package/package.json +26 -10
  16. package/dist/account.d.ts +0 -8
  17. package/dist/account.d.ts.map +0 -1
  18. package/dist/account.js +0 -13
  19. package/dist/account.js.map +0 -1
  20. package/dist/charges.d.ts +0 -4
  21. package/dist/charges.d.ts.map +0 -1
  22. package/dist/charges.js +0 -89
  23. package/dist/charges.js.map +0 -1
  24. package/dist/checkout-sessions.d.ts +0 -5
  25. package/dist/checkout-sessions.d.ts.map +0 -1
  26. package/dist/checkout-sessions.js +0 -303
  27. package/dist/checkout-sessions.js.map +0 -1
  28. package/dist/constants.d.ts +0 -3
  29. package/dist/constants.d.ts.map +0 -1
  30. package/dist/constants.js +0 -3
  31. package/dist/constants.js.map +0 -1
  32. package/dist/coupons.d.ts +0 -4
  33. package/dist/coupons.d.ts.map +0 -1
  34. package/dist/coupons.js +0 -158
  35. package/dist/coupons.js.map +0 -1
  36. package/dist/customers.d.ts +0 -4
  37. package/dist/customers.d.ts.map +0 -1
  38. package/dist/customers.js +0 -218
  39. package/dist/customers.js.map +0 -1
  40. package/dist/disputes.d.ts +0 -4
  41. package/dist/disputes.d.ts.map +0 -1
  42. package/dist/disputes.js +0 -36
  43. package/dist/disputes.js.map +0 -1
  44. package/dist/errors.d.ts +0 -29
  45. package/dist/errors.d.ts.map +0 -1
  46. package/dist/errors.js +0 -74
  47. package/dist/errors.js.map +0 -1
  48. package/dist/events.d.ts +0 -4
  49. package/dist/events.d.ts.map +0 -1
  50. package/dist/events.js +0 -76
  51. package/dist/events.js.map +0 -1
  52. package/dist/expand.d.ts +0 -11
  53. package/dist/expand.d.ts.map +0 -1
  54. package/dist/expand.js +0 -45
  55. package/dist/expand.js.map +0 -1
  56. package/dist/fields.d.ts +0 -25
  57. package/dist/fields.d.ts.map +0 -1
  58. package/dist/fields.js +0 -117
  59. package/dist/fields.js.map +0 -1
  60. package/dist/generated/openapi.d.ts +0 -7
  61. package/dist/generated/openapi.d.ts.map +0 -1
  62. package/dist/generated/openapi.js +0 -5
  63. package/dist/generated/openapi.js.map +0 -1
  64. package/dist/index.d.ts.map +0 -1
  65. package/dist/internal.d.ts +0 -134
  66. package/dist/internal.d.ts.map +0 -1
  67. package/dist/internal.js +0 -460
  68. package/dist/internal.js.map +0 -1
  69. package/dist/invoice-items.d.ts +0 -4
  70. package/dist/invoice-items.d.ts.map +0 -1
  71. package/dist/invoice-items.js +0 -179
  72. package/dist/invoice-items.js.map +0 -1
  73. package/dist/invoices.d.ts +0 -4
  74. package/dist/invoices.d.ts.map +0 -1
  75. package/dist/invoices.js +0 -312
  76. package/dist/invoices.js.map +0 -1
  77. package/dist/list.d.ts +0 -24
  78. package/dist/list.d.ts.map +0 -1
  79. package/dist/list.js +0 -68
  80. package/dist/list.js.map +0 -1
  81. package/dist/params.d.ts +0 -29
  82. package/dist/params.d.ts.map +0 -1
  83. package/dist/params.js +0 -165
  84. package/dist/params.js.map +0 -1
  85. package/dist/payment-intents.d.ts +0 -4
  86. package/dist/payment-intents.d.ts.map +0 -1
  87. package/dist/payment-intents.js +0 -232
  88. package/dist/payment-intents.js.map +0 -1
  89. package/dist/payment-methods.d.ts +0 -4
  90. package/dist/payment-methods.d.ts.map +0 -1
  91. package/dist/payment-methods.js +0 -99
  92. package/dist/payment-methods.js.map +0 -1
  93. package/dist/prices.d.ts +0 -4
  94. package/dist/prices.d.ts.map +0 -1
  95. package/dist/prices.js +0 -176
  96. package/dist/prices.js.map +0 -1
  97. package/dist/products.d.ts +0 -6
  98. package/dist/products.d.ts.map +0 -1
  99. package/dist/products.js +0 -202
  100. package/dist/products.js.map +0 -1
  101. package/dist/promotion-codes.d.ts +0 -4
  102. package/dist/promotion-codes.d.ts.map +0 -1
  103. package/dist/promotion-codes.js +0 -193
  104. package/dist/promotion-codes.js.map +0 -1
  105. package/dist/qa-corpus.d.ts +0 -26
  106. package/dist/qa-corpus.d.ts.map +0 -1
  107. package/dist/qa-corpus.js +0 -42
  108. package/dist/qa-corpus.js.map +0 -1
  109. package/dist/refunds.d.ts +0 -4
  110. package/dist/refunds.d.ts.map +0 -1
  111. package/dist/refunds.js +0 -125
  112. package/dist/refunds.js.map +0 -1
  113. package/dist/render.d.ts +0 -60
  114. package/dist/render.d.ts.map +0 -1
  115. package/dist/render.js +0 -426
  116. package/dist/render.js.map +0 -1
  117. package/dist/reshape-qa.d.ts +0 -8
  118. package/dist/reshape-qa.d.ts.map +0 -1
  119. package/dist/reshape-qa.js +0 -102
  120. package/dist/reshape-qa.js.map +0 -1
  121. package/dist/search.d.ts +0 -32
  122. package/dist/search.d.ts.map +0 -1
  123. package/dist/search.js +0 -64
  124. package/dist/search.js.map +0 -1
  125. package/dist/setup-intents.d.ts +0 -4
  126. package/dist/setup-intents.d.ts.map +0 -1
  127. package/dist/setup-intents.js +0 -129
  128. package/dist/setup-intents.js.map +0 -1
  129. package/dist/state.d.ts +0 -485
  130. package/dist/state.d.ts.map +0 -1
  131. package/dist/state.js +0 -143
  132. package/dist/state.js.map +0 -1
  133. package/dist/subscription-schedules.d.ts +0 -4
  134. package/dist/subscription-schedules.d.ts.map +0 -1
  135. package/dist/subscription-schedules.js +0 -122
  136. package/dist/subscription-schedules.js.map +0 -1
  137. package/dist/subscriptions.d.ts +0 -23
  138. package/dist/subscriptions.d.ts.map +0 -1
  139. package/dist/subscriptions.js +0 -260
  140. package/dist/subscriptions.js.map +0 -1
  141. package/dist/test-tokens.d.ts +0 -27
  142. package/dist/test-tokens.d.ts.map +0 -1
  143. package/dist/test-tokens.js +0 -61
  144. package/dist/test-tokens.js.map +0 -1
  145. package/dist/url.d.ts +0 -6
  146. package/dist/url.d.ts.map +0 -1
  147. package/dist/url.js +0 -38
  148. package/dist/url.js.map +0 -1
  149. package/dist/version.d.ts +0 -3
  150. package/dist/version.d.ts.map +0 -1
  151. package/dist/version.js +0 -3
  152. package/dist/version.js.map +0 -1
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 (`@crvouga/mockingbird-service-sqlite`, pure TypeScript). To serve it over HTTP also
29
- install an adapter: `@crvouga/mockingbird-adapter-node` or `@crvouga/mockingbird-adapter-bun`.
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
@@ -75,11 +107,14 @@ console.log(((await listed.json()) as { data: unknown[] }).data.length) // 1
75
107
  ### Over HTTP
76
108
 
77
109
  ```ts
78
- import { serve } from "@crvouga/mockingbird-adapter-bun"
79
110
  import { StripeAPI } from "@crvouga/mockingbird-service-stripe"
80
111
 
81
112
  const stripe = new StripeAPI()
82
- const server = serve(stripe, { port: 0, hostname: "127.0.0.1" }) // port 0 = ephemeral
113
+ const server = Bun.serve({
114
+ port: 0, // ephemeral
115
+ hostname: "127.0.0.1",
116
+ fetch: (request) => stripe.fetch(request),
117
+ })
83
118
  const baseUrl = `http://127.0.0.1:${server.port}`
84
119
 
85
120
  const response = await fetch(`${baseUrl}/v1/products?limit=3`, {
@@ -90,15 +125,8 @@ console.log(response.status) // 200
90
125
  server.stop()
91
126
  ```
92
127
 
93
- On Node use `@crvouga/mockingbird-adapter-node`, whose `serve` is async and returns a
94
- `node:http` server:
95
-
96
- ```js
97
- import { serve } from "@crvouga/mockingbird-adapter-node"
98
- const server = await serve(stripe, { port: 0, host: "127.0.0.1" })
99
- const { port } = server.address()
100
- // ... later: server.close()
101
- ```
128
+ On Node, `createServer` (above) is the listener; any Fetch-style server also works with
129
+ `StripeAPI#fetch` or `createRuntime().fetch`.
102
130
 
103
131
  ### Pointing stripe-node at it
104
132
 
@@ -111,13 +139,14 @@ import Stripe from "stripe"
111
139
  const client = new Stripe("sk_test_mockingbird", {
112
140
  apiVersion: "2024-06-20",
113
141
  host: "127.0.0.1",
114
- port: server.port, // from serve() above
142
+ port: server.port, // from Bun.serve() above
115
143
  protocol: "http",
116
144
  })
117
145
  await client.customers.create({ email: "qa@example.com" })
118
146
  ```
119
147
 
120
- 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
121
150
  constructs a Stripe client; a client built with `new Stripe(key)` and no options cannot be
122
151
  redirected. Test payment methods and tokens such as `pm_card_visa`, `pm_card_authenticationRequired`
123
152
  and `tok_chargeDeclinedInsufficientFunds` behave like their Stripe counterparts
@@ -177,6 +206,19 @@ test("starts empty", async () => {
177
206
  })
178
207
  ```
179
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
+
180
222
  ## API
181
223
 
182
224
  `StripeAPI` is the main export; the rest supports account scoping, contract introspection and the
@@ -184,7 +226,8 @@ QA corpus used by the parity suites.
184
226
 
185
227
  | Export | Description |
186
228
  | --- | --- |
187
- | `StripeAPI` | Class. `new StripeAPI(options?)`; implements `FetchAPI` (`fetch(request: Request): Promise<Response>`). |
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`). |
230
+ | `StripeAPI` | Class. `new StripeAPI(options?)`; implements the Fetch contract `fetch(request: Request): Promise<Response>`. |
188
231
  | `accountOfKey` | `(key: string) => string` — the opaque `acct_...` partition id for an API key (use it to filter `webhookEvents`). |
189
232
  | `accountOf` | `(request: Request) => string` — the partition id for a request's bearer key. |
190
233
  | `STRIPE_NAMESPACE` | `"stripe"` — SQLite namespace holding every Stripe record when sharing a `sqlite` client. |
@@ -199,7 +242,7 @@ QA corpus used by the parity suites.
199
242
  | `QA_TEST_CARD_TOKENS` | Test card tokens the suites use (`tok_visa`, decline tokens, ...). |
200
243
  | `QA_SEARCH_QUERIES` | Search queries the suites issue against `/v1/customers/search`. |
201
244
  | `QA_COUPON_CODES` | Coupon / promotion codes used by the coupon flows. |
202
- | `reshapeQaCommand` | Parity-walk hook that pins sampled commands onto QA corpus values (for `@crvouga/mockingbird-parity`). |
245
+ | `reshapeQaCommand` | Parity-walk hook that pins sampled commands onto QA corpus values (for the repo's parity runner). |
203
246
 
204
247
  `StripeAPI` members:
205
248
 
@@ -226,8 +269,9 @@ type WebhookPublisher = (event: StripeWebhookEvent) => void
226
269
  type OperationId / SupportedOperationId // string unions of operationIds / supportedOperationIds
227
270
  ```
228
271
 
229
- `SqliteClient` is the port from `@crvouga/mockingbird-sqlite`; `Database` from
230
- `@crvouga/mockingbird-service-sqlite` satisfies it, as do better-sqlite3 and wrapped `bun:sqlite`.
272
+ `SqliteClient` is the storage port bundled with this package (`exec`, `prepare(sql).run/all/get`,
273
+ `transaction`); `Database` from `@crvouga/mockingbird-service-sqlite` satisfies it, as do
274
+ better-sqlite3 and wrapped `bun:sqlite`.
231
275
 
232
276
  ## Development
233
277
 
@@ -251,4 +295,4 @@ PORT=12111 MOCKINGBIRD_STRIPE_WEBHOOK_TARGETS='[{"apiKey":"sk_test_mso","url":"h
251
295
 
252
296
  Live parity needs a real `sk_test_` key and mutates a shared test account.
253
297
 
254
- Part of [mockingbird](https://github.com/crvouga/mockingbird) — agent integration guide: [`@crvouga/mockingbird`](https://github.com/crvouga/mockingbird/tree/main/packages/facade#readme).
298
+ Part of [mockingbird](https://github.com/crvouga/mockingbird) — agent integration guide: [README](https://github.com/crvouga/mockingbird#readme) · [llms.txt](https://github.com/crvouga/mockingbird/blob/main/llms.txt).