@pplethai/cli 0.22.0 → 0.24.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 +109 -109
  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,288 +0,0 @@
1
- // callService (issue #253). The harness is the platform: tests see the URL,
2
- // the method, and the headers the Builder would observe, and the record
3
- // keeps no App Key and no user token.
4
-
5
- import { describe, expect, it, vi } from "vitest";
6
- import { callService, PLATFORM_ERROR_CODES, platformError } from "../src/call-service";
7
- import { makeHarness, serviceRefusal } from "./harness";
8
-
9
- const env = {
10
- DEV_PERSONA: "none",
11
- PPLE_SERVICES_URL: "https://services.test",
12
- PPLE_APP_KEY: "app-key",
13
- };
14
-
15
- describe("callService", () => {
16
- it("sends the App Key and the user token to the entry URL", async () => {
17
- let seen: { authorization: string | null; userToken: string | null; method: string } | undefined;
18
- const h = makeHarness(
19
- {
20
- services: (req) => {
21
- seen = {
22
- authorization: req.headers.get("authorization"),
23
- userToken: req.headers.get("x-pple-user-token"),
24
- method: req.method,
25
- };
26
- return Response.json({ ok: true });
27
- },
28
- },
29
- env,
30
- );
31
-
32
- const res = await callService(
33
- h.testEnv,
34
- "platform/legal-identity",
35
- "",
36
- {
37
- method: "POST",
38
- headers: {
39
- accept: "application/json",
40
- authorization: "Bearer caller",
41
- "x-pple-user-token": "smuggled",
42
- },
43
- },
44
- { userToken: "user-token", fetchImpl: h.fetchImpl },
45
- );
46
-
47
- expect(res.status).toBe(200);
48
- expect(seen).toEqual({
49
- authorization: "Bearer app-key",
50
- userToken: "user-token",
51
- method: "POST",
52
- });
53
- expect(h.calls.services).toEqual([
54
- {
55
- path: "/platform/legal-identity",
56
- method: "POST",
57
- headers: { accept: "application/json" },
58
- },
59
- ]);
60
- });
61
-
62
- it("omits the user token unless one was given, and joins the path onto the entry", async () => {
63
- let userToken: string | null = "unset";
64
- const h = makeHarness(
65
- {
66
- services: (req) => {
67
- userToken = req.headers.get("x-pple-user-token");
68
- return new Response(null, { status: 204 });
69
- },
70
- },
71
- { ...env, PPLE_SERVICES_URL: "https://services.test/" },
72
- );
73
-
74
- await callService(
75
- h.testEnv,
76
- "orders",
77
- "items/1?limit=2",
78
- { method: "GET", headers: { "x-pple-user-token": "smuggled" } },
79
- { fetchImpl: h.fetchImpl },
80
- );
81
-
82
- expect(userToken).toBeNull();
83
- expect(h.calls.services).toEqual([
84
- { path: "/orders/items/1?limit=2", method: "GET", headers: {} },
85
- ]);
86
- });
87
-
88
- it("uses the injected fetch under vitest", async () => {
89
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("from-injected"));
90
- const globalFetch = vi.spyOn(globalThis, "fetch");
91
- try {
92
- const res = await callService(env, "platform/legal-identity", "?dry=1", { method: "POST" }, {
93
- userToken: "t",
94
- fetchImpl,
95
- });
96
- expect(await res.text()).toBe("from-injected");
97
- expect(fetchImpl).toHaveBeenCalledOnce();
98
- expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/platform/legal-identity?dry=1");
99
- expect(globalFetch).not.toHaveBeenCalled();
100
- } finally {
101
- globalFetch.mockRestore();
102
- }
103
-
104
- await expect(callService(env, "platform/legal-identity", "")).rejects.toThrow(/injected fetch/);
105
- });
106
-
107
- it("keeps the injected fetch when a persona and DEV_REGISTRY_ERROR are set", async () => {
108
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("from-injected"));
109
- const res = await callService(
110
- { ...env, DEV_PERSONA: "hq-staff", DEV_REGISTRY_ERROR: "not_granted" },
111
- "orders",
112
- "/items/1",
113
- { method: "GET" },
114
- { userToken: "t", fetchImpl },
115
- );
116
- expect(await res.text()).toBe("from-injected");
117
- expect(fetchImpl).toHaveBeenCalledOnce();
118
- expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/orders/items/1");
119
- });
120
-
121
- it("calls an app's entry by its bare name, with no provider in the URL", async () => {
122
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
123
- await callService(env, "branch-list", "/offices", { method: "GET" }, { fetchImpl });
124
- expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/branch-list/offices");
125
- });
126
-
127
- it('builds services.<domain>/platform/sms/… for the platform\'s "platform/sms"', async () => {
128
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
129
- await callService(env, "platform/sms", "", { method: "POST" }, { userToken: "tok", fetchImpl });
130
- await callService(env, "platform/sms", "/send", { method: "POST" }, { fetchImpl });
131
- await callService(env, "platform/legal-identity", "?dry=1", { method: "POST" }, { fetchImpl });
132
- expect(fetchImpl.mock.calls.map((call) => String(call[0]))).toEqual([
133
- "https://services.test/platform/sms",
134
- "https://services.test/platform/sms/send",
135
- "https://services.test/platform/legal-identity?dry=1",
136
- ]);
137
- const headers = new Headers(fetchImpl.mock.calls[0]?.[1]?.headers);
138
- expect(headers.get("authorization")).toBe("Bearer app-key");
139
- expect(headers.get("x-pple-user-token")).toBe("tok");
140
- });
141
-
142
- it("builds services.<domain>/<full name>/… for a Namespace name, up to four segments", async () => {
143
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
144
- await callService(env, "election/2027/score", "/units/7?limit=2", { method: "GET" }, { fetchImpl });
145
- await callService(env, "election/score", "", {}, { fetchImpl });
146
- await callService(env, "election/2027/regional/score", "units", {}, { fetchImpl });
147
- expect(fetchImpl.mock.calls.map((call) => String(call[0]))).toEqual([
148
- "https://services.test/election/2027/score/units/7?limit=2",
149
- "https://services.test/election/score",
150
- "https://services.test/election/2027/regional/score/units",
151
- ]);
152
- });
153
-
154
- it("sends the App Key for a full name, as for a bare one", async () => {
155
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
156
- await callService(env, "election/score", "/", {}, { userToken: "tok", fetchImpl });
157
- const init = fetchImpl.mock.calls[0]?.[1];
158
- const headers = new Headers(init?.headers);
159
- expect(headers.get("authorization")).toBe("Bearer app-key");
160
- expect(headers.get("x-pple-user-token")).toBe("tok");
161
- });
162
-
163
- it.each([
164
- ["health", /"health" is reserved/],
165
- ["overlay/x", /"overlay" is reserved/],
166
- ["platform", /"platform" belongs to the platform.*such as "platform\/sms"/],
167
- ])('rejects the reserved name "%s"', async (id, message) => {
168
- const fetchImpl = vi.fn<typeof fetch>();
169
- await expect(callService(env, id, "", {}, { fetchImpl })).rejects.toThrow(message);
170
- expect(fetchImpl).not.toHaveBeenCalled();
171
- });
172
-
173
- it.each([
174
- "",
175
- "Election/score",
176
- "election//score",
177
- "/election/score",
178
- "election/score/",
179
- "election/ score",
180
- "election/a/b/c/d",
181
- "-election/score",
182
- "election_2027/score",
183
- `${"a".repeat(64)}/score`,
184
- `${"a".repeat(63)}/${"b".repeat(63)}/c`,
185
- ])('rejects the name "%s" as not an entry name', async (id) => {
186
- const fetchImpl = vi.fn<typeof fetch>();
187
- await expect(callService(env, id, "", {}, { fetchImpl })).rejects.toThrow(/is not an entry name/);
188
- expect(fetchImpl).not.toHaveBeenCalled();
189
- });
190
-
191
- it("accepts the longest names the validator allows", async () => {
192
- const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
193
- const full = `${"a".repeat(63)}/${"b".repeat(63)}`; // 127 characters
194
- await callService(env, full, "", {}, { fetchImpl });
195
- expect(String(fetchImpl.mock.calls[0]?.[0])).toBe(`https://services.test/${full}`);
196
- });
197
-
198
- it("does not call out without the services URL or the App Key", async () => {
199
- const fetchImpl = vi.fn<typeof fetch>();
200
- await expect(
201
- callService({ PPLE_SERVICES_URL: "https://services.test" }, "platform/legal-identity", "", {}, { fetchImpl }),
202
- ).rejects.toThrow(/PPLE_APP_KEY/);
203
- await expect(
204
- callService({ PPLE_APP_KEY: "app-key" }, "platform/legal-identity", "", {}, { fetchImpl }),
205
- ).rejects.toThrow(/PPLE_SERVICES_URL/);
206
- expect(fetchImpl).not.toHaveBeenCalled();
207
- });
208
- });
209
-
210
- describe("a renamed entry", () => {
211
- // pple-services answers an old full name with 410, `x-pple-error: renamed`
212
- // and the new name in the body (ADR-0032, #346).
213
- const renamedAnswer = () =>
214
- Response.json(
215
- {
216
- error: "renamed",
217
- renamed: "entry",
218
- renamedTo: "vote/score",
219
- message: "renamed to vote/score",
220
- },
221
- { status: 410, headers: { "x-pple-error": "renamed" } },
222
- );
223
-
224
- it("is a typed platform refusal on callService, and the body still names the new entry", async () => {
225
- const h = makeHarness({ services: renamedAnswer }, env);
226
-
227
- const res = await callService(h.testEnv, "election/score", "/results", { method: "GET" }, {
228
- fetchImpl: h.fetchImpl,
229
- });
230
-
231
- expect(h.calls.services[0]?.path).toBe("/election/score/results");
232
- expect(res.status).toBe(410);
233
- expect(platformError(res)).toBe("renamed");
234
- expect(await res.json()).toMatchObject({ renamedTo: "vote/score" });
235
- });
236
-
237
- it("is listed with the other codes", () => {
238
- expect(PLATFORM_ERROR_CODES).toContain("renamed");
239
- });
240
- });
241
-
242
- describe("services fake", () => {
243
- it("answers as any Provider and refuses with any x-pple-error code", async () => {
244
- const codes = [
245
- "invalid_app_key",
246
- "not_listed",
247
- "not_granted",
248
- "needs_beta",
249
- "user_token_invalid",
250
- "identity_unavailable",
251
- "provider_unavailable",
252
- "provider_timeout",
253
- "renamed",
254
- "no_mock",
255
- "made_up",
256
- ];
257
- let next = Response.json({ items: ["a"] });
258
- const h = makeHarness({ services: () => next }, env);
259
-
260
- const answered = await callService(h.testEnv, "catalog", "/search", { method: "GET" }, {
261
- fetchImpl: h.fetchImpl,
262
- });
263
- expect(answered.status).toBe(200);
264
- expect(await answered.json()).toEqual({ items: ["a"] });
265
- expect(platformError(answered)).toBeNull();
266
-
267
- for (const code of codes) {
268
- next = serviceRefusal(code, 418);
269
- const res = await callService(h.testEnv, "catalog", "", { method: "POST" }, {
270
- userToken: "t",
271
- fetchImpl: h.fetchImpl,
272
- });
273
- expect(res.status).toBe(418);
274
- expect(res.headers.get("x-pple-error")).toBe(code);
275
- expect(await res.json()).toEqual({ error: code });
276
- const known = platformError(res);
277
- if (code === "no_mock" || code === "made_up") expect(known).toBeNull();
278
- else expect(known).toBe(code);
279
- }
280
-
281
- expect(h.calls.services[0]).toEqual({ path: "/catalog/search", method: "GET", headers: {} });
282
- expect(h.calls.services).toHaveLength(1 + codes.length);
283
- for (const call of h.calls.services) {
284
- expect(call.headers).not.toHaveProperty("authorization");
285
- expect(call.headers).not.toHaveProperty("x-pple-user-token");
286
- }
287
- });
288
- });