@crvouga/mockingbird-service-stripe 3.3.1 → 3.4.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 +12 -0
- package/dist/{chunk-NLXVX6IV.js → chunk-EUF2MBTV.js} +179 -5647
- package/dist/chunk-EUF2MBTV.js.map +7 -0
- package/dist/chunk-VV2ZADSQ.js +90 -0
- package/dist/chunk-VV2ZADSQ.js.map +7 -0
- package/dist/chunk-XEIHQZPI.js +6358 -0
- package/dist/chunk-XEIHQZPI.js.map +7 -0
- package/dist/chunk-Z5GZOENC.js +5736 -0
- package/dist/chunk-Z5GZOENC.js.map +7 -0
- package/dist/cli.js +7 -4
- package/dist/cli.js.map +1 -1
- package/dist/fleet.d.ts +2237 -0
- package/dist/fleet.js +113 -0
- package/dist/fleet.js.map +7 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +2 -1
- package/dist/server.d.ts +31 -2
- package/dist/server.js +4 -2
- package/package.json +7 -2
- package/dist/chunk-5TMQKXTS.js +0 -990
- package/dist/chunk-5TMQKXTS.js.map +0 -7
- package/dist/chunk-NLXVX6IV.js.map +0 -7
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRuntime,
|
|
3
|
+
validateAccounts
|
|
4
|
+
} from "./chunk-EUF2MBTV.js";
|
|
5
|
+
import {
|
|
6
|
+
listen
|
|
7
|
+
} from "./chunk-XEIHQZPI.js";
|
|
8
|
+
|
|
9
|
+
// src/server.ts
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
var DEFAULT_PORT = 12111;
|
|
12
|
+
var createServer = async (options = {}) => {
|
|
13
|
+
const { port, host, ...rest } = options;
|
|
14
|
+
const runtime = createRuntime(rest);
|
|
15
|
+
const listening = await listen(runtime, {
|
|
16
|
+
port: port ?? 0,
|
|
17
|
+
...host !== void 0 ? { host } : {}
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
...listening,
|
|
21
|
+
runtime,
|
|
22
|
+
close: async () => {
|
|
23
|
+
runtime.stop();
|
|
24
|
+
await listening.close();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
var text = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
29
|
+
var readAccounts = (value) => {
|
|
30
|
+
const raw = value.trim().startsWith("[") || value.trim().startsWith("{") ? value : readFileSync(value, "utf8");
|
|
31
|
+
const parsed = validateAccounts(JSON.parse(raw));
|
|
32
|
+
if (typeof parsed === "string") throw new Error(`--accounts: ${parsed}`);
|
|
33
|
+
return parsed;
|
|
34
|
+
};
|
|
35
|
+
var serveTarget = {
|
|
36
|
+
name: "stripe",
|
|
37
|
+
defaultPort: DEFAULT_PORT,
|
|
38
|
+
options: {
|
|
39
|
+
accounts: {
|
|
40
|
+
type: "string",
|
|
41
|
+
value: "<json|file>",
|
|
42
|
+
description: 'Accounts and their keys, e.g. [{"id":"acct_mso","keys":["sk_test_\u2026"],"webhookSecrets":{"http://\u2026/billing/webhooks/stripe/mso":"whsec_\u2026"},"corpus":true}]'
|
|
43
|
+
},
|
|
44
|
+
"webhook-url": {
|
|
45
|
+
type: "string",
|
|
46
|
+
value: "<url>",
|
|
47
|
+
description: "Deliver every account's events here (signed with --webhook-secret)"
|
|
48
|
+
},
|
|
49
|
+
"webhook-secret": {
|
|
50
|
+
type: "string",
|
|
51
|
+
value: "<whsec_\u2026>",
|
|
52
|
+
description: "Secret for --webhook-url's Stripe-Signature"
|
|
53
|
+
},
|
|
54
|
+
"public-url": {
|
|
55
|
+
type: "string",
|
|
56
|
+
value: "<url>",
|
|
57
|
+
description: "Base URL of the hosted Checkout page and Stripe.js when behind a proxy"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
create: (values, common) => {
|
|
61
|
+
const url = text(values["webhook-url"]);
|
|
62
|
+
const secret = text(values["webhook-secret"]);
|
|
63
|
+
const accounts = text(values.accounts);
|
|
64
|
+
const publicUrl = common.baseUrl ?? text(values["public-url"]);
|
|
65
|
+
return createRuntime({
|
|
66
|
+
...common.adminPrefix !== void 0 ? { adminPrefix: common.adminPrefix } : {},
|
|
67
|
+
...common.adminKey !== void 0 ? { adminKey: common.adminKey } : {},
|
|
68
|
+
...common.adminControls !== void 0 ? { adminControls: common.adminControls } : {},
|
|
69
|
+
...common.seed !== void 0 ? { seed: common.seed } : {},
|
|
70
|
+
...common.onLog ? { onLog: common.onLog } : {},
|
|
71
|
+
...accounts ? { accounts: readAccounts(accounts) } : {},
|
|
72
|
+
...url ? { webhooks: { endpoints: [{ url, ...secret ? { secret } : {} }] } } : {},
|
|
73
|
+
...publicUrl ? { publicUrl } : {},
|
|
74
|
+
tickMs: 1e3
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
banner: () => [
|
|
78
|
+
"auth: Authorization: Bearer sk_test_<anything>; unconfigured keys are accounts of their own",
|
|
79
|
+
'stripe-node: new Stripe(key, { host: "127.0.0.1", port: <port>, protocol: "http" })',
|
|
80
|
+
"accounts: PUT /__admin/accounts; webhooks: PUT /__admin/webhook-endpoints",
|
|
81
|
+
"hosted Checkout: session.url \u2192 /c/pay/<id>; Stripe.js stand-in: /v3"
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
DEFAULT_PORT,
|
|
87
|
+
createServer,
|
|
88
|
+
serveTarget
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=chunk-VV2ZADSQ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/server.ts"],
|
|
4
|
+
"sourcesContent": ["/// <reference types=\"node\" />\nimport { readFileSync } from \"node:fs\"\nimport { type Listening, listen, type ServeTarget } from \"@crvouga/mockingbird-adapter-node\"\nimport { validateAccounts } from \"./accounts.js\"\nimport { createRuntime, type StripeRuntime, type StripeRuntimeOptions } from \"./runtime.js\"\n\n/** Port `mockingbird-stripe serve` listens on when none is given. */\nexport const DEFAULT_PORT = 12111\n\nexport type StripeServerOptions = StripeRuntimeOptions & {\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}\n\nexport type StripeServer = Listening & { runtime: StripeRuntime }\n\n/** Serve the Stripe mock over `node:http`. Resolves once it is listening. */\nexport const createServer = async (options: StripeServerOptions = {}): Promise<StripeServer> => {\n const { port, host, ...rest } = options\n const runtime = createRuntime(rest)\n const listening = await listen(runtime, {\n port: port ?? 0,\n ...(host !== undefined ? { host } : {}),\n })\n return {\n ...listening,\n runtime,\n close: async () => {\n runtime.stop()\n await listening.close()\n },\n }\n}\n\nconst text = (value: string | boolean | undefined) =>\n typeof value === \"string\" && value !== \"\" ? value : undefined\n\n/** `--accounts` takes inline JSON or a path to a JSON file. */\nconst readAccounts = (value: string) => {\n const raw =\n value.trim().startsWith(\"[\") || value.trim().startsWith(\"{\")\n ? value\n : readFileSync(value, \"utf8\")\n const parsed = validateAccounts(JSON.parse(raw))\n if (typeof parsed === \"string\") throw new Error(`--accounts: ${parsed}`)\n return parsed\n}\n\n/** How `serve` (and `serve --config`) builds the Stripe mock from flags. */\nexport const serveTarget: ServeTarget = {\n name: \"stripe\",\n defaultPort: DEFAULT_PORT,\n options: {\n accounts: {\n type: \"string\",\n value: \"<json|file>\",\n description:\n 'Accounts and their keys, e.g. [{\"id\":\"acct_mso\",\"keys\":[\"sk_test_\u2026\"],\"webhookSecrets\":{\"http://\u2026/billing/webhooks/stripe/mso\":\"whsec_\u2026\"},\"corpus\":true}]',\n },\n \"webhook-url\": {\n type: \"string\",\n value: \"<url>\",\n description: \"Deliver every account's events here (signed with --webhook-secret)\",\n },\n \"webhook-secret\": {\n type: \"string\",\n value: \"<whsec_\u2026>\",\n description: \"Secret for --webhook-url's Stripe-Signature\",\n },\n \"public-url\": {\n type: \"string\",\n value: \"<url>\",\n description: \"Base URL of the hosted Checkout page and Stripe.js when behind a proxy\",\n },\n },\n create: (values, common) => {\n const url = text(values[\"webhook-url\"])\n const secret = text(values[\"webhook-secret\"])\n const accounts = text(values.accounts)\n const publicUrl = common.baseUrl ?? text(values[\"public-url\"])\n return createRuntime({\n ...(common.adminPrefix !== undefined ? { adminPrefix: common.adminPrefix } : {}),\n ...(common.adminKey !== undefined ? { adminKey: common.adminKey } : {}),\n ...(common.adminControls !== undefined ? { adminControls: common.adminControls } : {}),\n ...(common.seed !== undefined ? { seed: common.seed } : {}),\n ...(common.onLog ? { onLog: common.onLog } : {}),\n ...(accounts ? { accounts: readAccounts(accounts) } : {}),\n ...(url ? { webhooks: { endpoints: [{ url, ...(secret ? { secret } : {}) }] } } : {}),\n ...(publicUrl ? { publicUrl } : {}),\n tickMs: 1000,\n })\n },\n banner: () => [\n \"auth: Authorization: Bearer sk_test_<anything>; unconfigured keys are accounts of their own\",\n 'stripe-node: new Stripe(key, { host: \"127.0.0.1\", port: <port>, protocol: \"http\" })',\n \"accounts: PUT /__admin/accounts; webhooks: PUT /__admin/webhook-endpoints\",\n \"hosted Checkout: session.url \u2192 /c/pay/<id>; Stripe.js stand-in: /v3\",\n ],\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AACA,SAAS,oBAAoB;AAMtB,IAAM,eAAe;AAYrB,IAAM,eAAe,OAAO,UAA+B,CAAC,MAA6B;AAC9F,QAAM,EAAE,MAAM,MAAM,GAAG,KAAK,IAAI;AAChC,QAAM,UAAU,cAAc,IAAI;AAClC,QAAM,YAAY,MAAM,OAAO,SAAS;AAAA,IACtC,MAAM,QAAQ;AAAA,IACd,GAAI,SAAS,SAAY,EAAE,KAAK,IAAI,CAAC;AAAA,EACvC,CAAC;AACD,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,OAAO,YAAY;AACjB,cAAQ,KAAK;AACb,YAAM,UAAU,MAAM;AAAA,IACxB;AAAA,EACF;AACF;AAEA,IAAM,OAAO,CAAC,UACZ,OAAO,UAAU,YAAY,UA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