@pplethai/cli 0.22.0 → 0.23.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 (118) hide show
  1. package/README.md +12 -14
  2. package/dist/bin.js +102 -102
  3. package/package.json +3 -6
  4. package/templates/golden-path/.dev.vars.example +0 -33
  5. package/templates/golden-path/.env.example +0 -10
  6. package/templates/golden-path/.github/workflows/ci.yml +0 -22
  7. package/templates/golden-path/AGENTS.md +0 -1
  8. package/templates/golden-path/CLAUDE.md +0 -191
  9. package/templates/golden-path/README.md +0 -121
  10. package/templates/golden-path/gitignore +0 -17
  11. package/templates/golden-path/index.html +0 -16
  12. package/templates/golden-path/migrations/0001_init.sql +0 -10
  13. package/templates/golden-path/overlay-mtime.mjs +0 -30
  14. package/templates/golden-path/package-lock.json +0 -4318
  15. package/templates/golden-path/package.json +0 -41
  16. package/templates/golden-path/scripts/assert-dev-compiled-out.mjs +0 -45
  17. package/templates/golden-path/shared/api.ts +0 -325
  18. package/templates/golden-path/src/auth.ts +0 -230
  19. package/templates/golden-path/src/call-service.ts +0 -147
  20. package/templates/golden-path/src/dataset-query.ts +0 -470
  21. package/templates/golden-path/src/dataset-schema.ts +0 -398
  22. package/templates/golden-path/src/db.ts +0 -32
  23. package/templates/golden-path/src/dev-call-service.ts +0 -392
  24. package/templates/golden-path/src/dev-personas.ts +0 -186
  25. package/templates/golden-path/src/dev-read-dataset.ts +0 -444
  26. package/templates/golden-path/src/dev-registry.ts +0 -294
  27. package/templates/golden-path/src/email.ts +0 -49
  28. package/templates/golden-path/src/entry-name.ts +0 -114
  29. package/templates/golden-path/src/env.ts +0 -38
  30. package/templates/golden-path/src/files.ts +0 -38
  31. package/templates/golden-path/src/identity-header.ts +0 -17
  32. package/templates/golden-path/src/index.ts +0 -282
  33. package/templates/golden-path/src/legal-identity.ts +0 -180
  34. package/templates/golden-path/src/levels.ts +0 -132
  35. package/templates/golden-path/src/notification-response.ts +0 -55
  36. package/templates/golden-path/src/notify.ts +0 -311
  37. package/templates/golden-path/src/party-email.ts +0 -183
  38. package/templates/golden-path/src/payment.ts +0 -676
  39. package/templates/golden-path/src/read-dataset.ts +0 -490
  40. package/templates/golden-path/src/registry.ts +0 -128
  41. package/templates/golden-path/src/vite-env.d.ts +0 -27
  42. package/templates/golden-path/test/apply-migrations.ts +0 -4
  43. package/templates/golden-path/test/call-service.test.ts +0 -288
  44. package/templates/golden-path/test/dev-call-service.test.ts +0 -455
  45. package/templates/golden-path/test/dev-read-dataset.test.ts +0 -379
  46. package/templates/golden-path/test/dev-registry.test.ts +0 -404
  47. package/templates/golden-path/test/effective-sub.test.ts +0 -101
  48. package/templates/golden-path/test/email-offline.test.ts +0 -51
  49. package/templates/golden-path/test/email.test.ts +0 -117
  50. package/templates/golden-path/test/env.d.ts +0 -17
  51. package/templates/golden-path/test/fixtures/overlay/branch-list/entry.md +0 -85
  52. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/audience.json +0 -3
  53. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/named.json +0 -3
  54. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/offices.json +0 -6
  55. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/roster.json +0 -3
  56. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/summary.json +0 -1
  57. package/templates/golden-path/test/fixtures/overlay/catalog/entry.md +0 -8
  58. package/templates/golden-path/test/fixtures/overlay/catalog/mocks/responses.json +0 -7
  59. package/templates/golden-path/test/fixtures/overlay/election/2027/score/entry.md +0 -11
  60. package/templates/golden-path/test/fixtures/overlay/election/2027/score/mocks/responses.json +0 -7
  61. package/templates/golden-path/test/fixtures/overlay/election/results/entry.md +0 -24
  62. package/templates/golden-path/test/fixtures/overlay/election/results/mocks/turnout.json +0 -1
  63. package/templates/golden-path/test/fixtures/overlay/orders/entry.md +0 -12
  64. package/templates/golden-path/test/fixtures/overlay/orders/mocks/responses.json +0 -36
  65. package/templates/golden-path/test/fixtures/overlay/platform/email/entry.md +0 -12
  66. package/templates/golden-path/test/fixtures/overlay/platform/email/mocks/responses.json +0 -11
  67. package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/entry.md +0 -8
  68. package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/mocks/responses.json +0 -13
  69. package/templates/golden-path/test/fixtures/overlay/platform/payments/entry.md +0 -12
  70. package/templates/golden-path/test/fixtures/overlay/platform/payments/mocks/responses.json +0 -98
  71. package/templates/golden-path/test/fixtures/overlay/platform/sms/entry.md +0 -10
  72. package/templates/golden-path/test/fixtures/overlay/platform/sms/mocks/responses.json +0 -7
  73. package/templates/golden-path/test/fixtures/overlay/score/entry.md +0 -10
  74. package/templates/golden-path/test/fixtures/overlay/score/mocks/responses.json +0 -7
  75. package/templates/golden-path/test/harness.ts +0 -153
  76. package/templates/golden-path/test/interaction.test.ts +0 -230
  77. package/templates/golden-path/test/legal-identity.test.ts +0 -323
  78. package/templates/golden-path/test/membership.test.ts +0 -105
  79. package/templates/golden-path/test/notification-response.test.ts +0 -79
  80. package/templates/golden-path/test/payment-app.test.ts +0 -211
  81. package/templates/golden-path/test/payment-offline.test.ts +0 -91
  82. package/templates/golden-path/test/payment.test.ts +0 -518
  83. package/templates/golden-path/test/payments-offline.ts +0 -33
  84. package/templates/golden-path/test/read-dataset.test.ts +0 -387
  85. package/templates/golden-path/test/service-call.test.ts +0 -166
  86. package/templates/golden-path/test/smoke.test.ts +0 -464
  87. package/templates/golden-path/tsconfig.json +0 -20
  88. package/templates/golden-path/tsconfig.worker.json +0 -21
  89. package/templates/golden-path/vite.config.ts +0 -12
  90. package/templates/golden-path/vitest.config.ts +0 -28
  91. package/templates/golden-path/web/App.tsx +0 -478
  92. package/templates/golden-path/web/app.css +0 -83
  93. package/templates/golden-path/web/main.tsx +0 -51
  94. package/templates/golden-path/web/pple.ts +0 -124
  95. package/templates/golden-path/web/vite-env.d.ts +0 -10
  96. package/templates/golden-path/wrangler.jsonc +0 -89
  97. package/templates/payment-bridge/.github/workflows/ci.yml +0 -21
  98. package/templates/payment-bridge/CLAUDE.md +0 -9
  99. package/templates/payment-bridge/README.md +0 -57
  100. package/templates/payment-bridge/docs/verify-webhook.md +0 -80
  101. package/templates/payment-bridge/docs/verify-webhook.ts +0 -29
  102. package/templates/payment-bridge/gitignore +0 -5
  103. package/templates/payment-bridge/package-lock.json +0 -4198
  104. package/templates/payment-bridge/package.json +0 -21
  105. package/templates/payment-bridge/src/bridge-key.ts +0 -18
  106. package/templates/payment-bridge/src/env.ts +0 -14
  107. package/templates/payment-bridge/src/index.ts +0 -39
  108. package/templates/payment-bridge/src/platform.ts +0 -49
  109. package/templates/payment-bridge/src/webhook.ts +0 -86
  110. package/templates/payment-bridge/test/docs.test.ts +0 -9
  111. package/templates/payment-bridge/test/fixtures/payments-responses.json +0 -98
  112. package/templates/payment-bridge/test/harness.ts +0 -78
  113. package/templates/payment-bridge/test/inbound.test.ts +0 -138
  114. package/templates/payment-bridge/test/webhook.test.ts +0 -174
  115. package/templates/payment-bridge/tsconfig.json +0 -22
  116. package/templates/payment-bridge/vitest.config.ts +0 -8
  117. package/templates/payment-bridge/wrangler.jsonc +0 -15
  118. package/templates/payment-bridge.version +0 -1
@@ -1,174 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { verifyWebhook } from "../docs/verify-webhook";
3
- import { createBridge } from "../src/index";
4
- import { APP_KEY, BRIDGE_KEY, WEBHOOK_SECRET, WEBHOOK_URL, recordingFetch, testEnv, testExecutionContext } from "./harness";
5
-
6
- const ctx = testExecutionContext();
7
-
8
- const PAID_EVENT = {
9
- type: "payment.paid",
10
- id: "evt_paid_pay_1",
11
- payment: { id: "pay_1", kind: "donation", amountSatang: 50_000, description: "บริจาค", reference: "ref-1", mode: "live" },
12
- payer: { name: "สมชาย ใจดี", maskedCitizenId: "1-xxxx-xxxxx-12-3" },
13
- voucher: null,
14
- paidAt: "2026-01-01T00:00:00.000Z",
15
- };
16
-
17
- describe("relaying a payment event to the External System", () => {
18
- it("POSTs the event unchanged to the webhook, signed, and answers 2xx when it is delivered", async () => {
19
- const external = recordingFetch(() => new Response("ok", { status: 200 }));
20
- const bridge = createBridge({ fetchImpl: external.fetchImpl, now: () => 1_800_000_000_000 });
21
-
22
- const answer = await bridge.payment(PAID_EVENT as never, testEnv(), ctx);
23
-
24
- expect(answer?.status).toBe(200);
25
- expect(external.calls).toHaveLength(1);
26
- const [seen] = external.calls;
27
- expect(seen?.url).toBe(WEBHOOK_URL);
28
- expect(seen?.method).toBe("POST");
29
- expect(seen?.body).toBe(JSON.stringify(PAID_EVENT));
30
- expect(seen?.headers.get("content-type")).toBe("application/json");
31
- expect(seen?.headers.get("x-pple-webhook-id")).toBe("evt_paid_pay_1");
32
- expect(seen?.headers.get("x-pple-webhook-timestamp")).toBe("1800000000");
33
- // The documented check accepts it.
34
- expect(
35
- await verifyWebhook({
36
- secret: WEBHOOK_SECRET,
37
- body: seen!.body,
38
- timestamp: seen!.headers.get("x-pple-webhook-timestamp")!,
39
- signature: seen!.headers.get("x-pple-webhook-signature")!,
40
- now: 1_800_000_000,
41
- }),
42
- ).toBe(true);
43
- });
44
-
45
- it("sends the same id on every retry of the same event, and a new timestamp and signature each time", async () => {
46
- const external = recordingFetch(() => new Response(null, { status: 200 }));
47
- let now = 1_800_000_000_000;
48
- const bridge = createBridge({ fetchImpl: external.fetchImpl, now: () => now });
49
- await bridge.payment(PAID_EVENT as never, testEnv(), ctx);
50
- now += 300_000;
51
- await bridge.payment(PAID_EVENT as never, testEnv(), ctx);
52
- const [first, second] = external.calls;
53
- expect(second?.headers.get("x-pple-webhook-id")).toBe(first?.headers.get("x-pple-webhook-id"));
54
- expect(second?.body).toBe(first?.body);
55
- expect(second?.headers.get("x-pple-webhook-timestamp")).not.toBe(first?.headers.get("x-pple-webhook-timestamp"));
56
- expect(second?.headers.get("x-pple-webhook-signature")).not.toBe(first?.headers.get("x-pple-webhook-signature"));
57
- });
58
-
59
- it("is not verified by the documented check once the body, timestamp, secret or signature is wrong", async () => {
60
- const external = recordingFetch(() => new Response(null, { status: 204 }));
61
- const bridge = createBridge({ fetchImpl: external.fetchImpl, now: () => 1_800_000_000_000 });
62
- await bridge.payment(PAID_EVENT as never, testEnv(), ctx);
63
- const [seen] = external.calls;
64
- const good = {
65
- secret: WEBHOOK_SECRET,
66
- body: seen!.body,
67
- timestamp: seen!.headers.get("x-pple-webhook-timestamp")!,
68
- signature: seen!.headers.get("x-pple-webhook-signature")!,
69
- now: 1_800_000_000,
70
- };
71
- expect(await verifyWebhook(good)).toBe(true);
72
- expect(await verifyWebhook({ ...good, body: good.body.replace("50000", "50001") })).toBe(false);
73
- expect(await verifyWebhook({ ...good, timestamp: "1800000001" })).toBe(false);
74
- expect(await verifyWebhook({ ...good, secret: BRIDGE_KEY })).toBe(false);
75
- expect(await verifyWebhook({ ...good, signature: "v1=" + "0".repeat(64) })).toBe(false);
76
- expect(await verifyWebhook({ ...good, signature: "garbage" })).toBe(false);
77
- // A replay from long ago.
78
- expect(await verifyWebhook({ ...good, now: 1_800_000_000 + 301 })).toBe(false);
79
- expect(await verifyWebhook({ ...good, now: 1_800_000_000 + 301, toleranceSeconds: 600 })).toBe(true);
80
- });
81
-
82
- it("never sends the App Key or the Bridge Key out", async () => {
83
- const external = recordingFetch(() => new Response(null, { status: 200 }));
84
- const bridge = createBridge({ fetchImpl: external.fetchImpl });
85
- await bridge.payment(PAID_EVENT as never, testEnv(), ctx);
86
- const [seen] = external.calls;
87
- const everything = `${seen?.url} ${[...(seen?.headers ?? [])].join(" ")} ${seen?.body}`;
88
- expect(everything).not.toContain(APP_KEY);
89
- expect(everything).not.toContain(BRIDGE_KEY);
90
- expect(seen?.headers.has("authorization")).toBe(false);
91
- });
92
- });
93
-
94
- describe("what the platform is told", () => {
95
- const answerFor = async (answer: () => Response | Promise<Response>, env = testEnv(), options = {}) => {
96
- const external = recordingFetch(answer);
97
- const bridge = createBridge({ fetchImpl: external.fetchImpl, ...options });
98
- return { answer: await bridge.payment(PAID_EVENT as never, env, ctx), calls: external.calls };
99
- };
100
- const delivered = (r: Response | void | undefined) => !!r && r.status >= 200 && r.status < 300;
101
-
102
- it.each([200, 201, 202, 204])("a %i from the External System is delivered", async (status) => {
103
- expect(delivered((await answerFor(() => new Response(null, { status }))).answer)).toBe(true);
104
- });
105
-
106
- it.each([301, 302, 400, 401, 404, 429, 500, 502, 503])("a %i from the External System is not delivered", async (status) => {
107
- const { answer, calls } = await answerFor(() => new Response(null, { status, headers: { location: "https://elsewhere.test" } }));
108
- expect(delivered(answer)).toBe(false);
109
- expect(calls).toHaveLength(1); // a redirect is not followed with the signed body
110
- });
111
-
112
- it("a network error is not delivered", async () => {
113
- const { answer } = await answerFor(() => { throw new TypeError("connection refused"); });
114
- expect(delivered(answer)).toBe(false);
115
- });
116
-
117
- it("a hang is not delivered, and the platform hears before its own 9 seconds are up", async () => {
118
- const { answer } = await answerFor(
119
- () => new Promise<Response>(() => {}),
120
- testEnv(),
121
- { webhookTimeoutMs: 50 },
122
- );
123
- expect(delivered(answer)).toBe(false);
124
- });
125
-
126
- it("the default timeout is under the platform's 9 seconds", async () => {
127
- const { WEBHOOK_TIMEOUT_MS } = await import("../src/webhook");
128
- expect(WEBHOOK_TIMEOUT_MS).toBeLessThan(9_000);
129
- expect(WEBHOOK_TIMEOUT_MS).toBeGreaterThan(0);
130
- });
131
-
132
- it.each([
133
- ["no webhook URL", { WEBHOOK_URL: undefined }],
134
- ["an empty webhook URL", { WEBHOOK_URL: "" }],
135
- ["a webhook URL that is not https", { WEBHOOK_URL: "http://external.test/hook" }],
136
- ["a webhook URL that is not a URL", { WEBHOOK_URL: "not a url" }],
137
- ["no signing secret", { WEBHOOK_SECRET: undefined }],
138
- ])("%s is not delivered, and nothing is sent", async (_name, env) => {
139
- const { answer, calls } = await answerFor(() => new Response(null, { status: 200 }), testEnv(env));
140
- expect(delivered(answer)).toBe(false);
141
- expect(calls).toEqual([]);
142
- });
143
-
144
- it("an event with no id is not delivered", async () => {
145
- const external = recordingFetch(() => new Response(null, { status: 200 }));
146
- const bridge = createBridge({ fetchImpl: external.fetchImpl });
147
- const { id: _id, ...noId } = PAID_EVENT;
148
- expect(delivered(await bridge.payment(noId as never, testEnv(), ctx))).toBe(false);
149
- expect(external.calls).toEqual([]);
150
- });
151
- });
152
-
153
- describe("what is logged", () => {
154
- it("never a body, a key or a secret, on delivery or on failure", async () => {
155
- const lines: string[] = [];
156
- const spies = (["log", "info", "warn", "error", "debug"] as const).map((level) => {
157
- const original = console[level];
158
- console[level] = (...args: unknown[]) => void lines.push(args.map(String).join(" "));
159
- return () => (console[level] = original);
160
- });
161
- try {
162
- const failing = createBridge({ fetchImpl: async () => { throw new Error(`boom ${JSON.stringify(PAID_EVENT)}`); } });
163
- await failing.payment(PAID_EVENT as never, testEnv(), ctx);
164
- const refusing = createBridge({ fetchImpl: async () => new Response("payer สมชาย", { status: 500 }) });
165
- await refusing.payment(PAID_EVENT as never, testEnv(), ctx);
166
- const platform = createBridge({ fetchImpl: async () => { throw new Error(`down ${APP_KEY}`); } });
167
- await platform.fetch(new Request("https://bridge.test/api/pay_1", { method: "POST", body: "สมชาย", headers: { authorization: `Bearer ${BRIDGE_KEY}` } }), testEnv(), ctx);
168
- } finally {
169
- spies.forEach((restore) => restore());
170
- }
171
- const logged = lines.join("\n");
172
- for (const secret of ["สมชาย", "50000", APP_KEY, BRIDGE_KEY, WEBHOOK_SECRET]) expect(logged).not.toContain(secret);
173
- });
174
- });
@@ -1,22 +0,0 @@
1
- // TypeScript config for the Worker, its tests and the signature check in docs/.
2
- {
3
- "compilerOptions": {
4
- "target": "es2022",
5
- "lib": ["es2022"],
6
- "module": "es2022",
7
- "moduleResolution": "bundler",
8
- "types": [
9
- "@cloudflare/workers-types",
10
- "@cloudflare/vitest-pool-workers/types",
11
- "vite/client"
12
- ],
13
- "strict": true,
14
- "resolveJsonModule": true,
15
- "noUncheckedIndexedAccess": true,
16
- "noEmit": true,
17
- "skipLibCheck": true,
18
- "isolatedModules": true,
19
- "forceConsistentCasingInFileNames": true
20
- },
21
- "include": ["src", "test", "docs", "recipes"]
22
- }
@@ -1,8 +0,0 @@
1
- import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2
- import { defineConfig } from "vitest/config";
3
-
4
- // Runs the tests inside the real Workers runtime (workerd), so the Web Crypto
5
- // and `Response` behaviour they rely on is the production one.
6
- export default defineConfig({
7
- plugins: [cloudflareTest({ wrangler: { configPath: "./wrangler.jsonc" } })],
8
- });
@@ -1,15 +0,0 @@
1
- // A Payment Bridge's Cloudflare configuration (ADR-0045). The platform uploads
2
- // the Worker through the Cloudflare API and sets its bindings itself, so this
3
- // file only drives local type generation and tests. There is no `assets`
4
- // block: a Bridge serves no pages, and everything outside /api/* is a 404.
5
- {
6
- "name": "pple-app",
7
- "main": "src/index.ts",
8
- "compatibility_date": "2026-06-01"
9
-
10
- // Config (set through the platform, never in this file):
11
- // BRIDGE_KEY secret the key the External System calls /api/* with
12
- // WEBHOOK_SECRET secret the key webhooks are signed with
13
- // WEBHOOK_URL var where every payment event is POSTed (https)
14
- // The App Key and PPLE_SERVICES_URL are bound by the platform.
15
- }
@@ -1 +0,0 @@
1
- 4