@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.
- package/README.md +12 -14
- package/dist/bin.js +109 -109
- package/package.json +3 -6
- package/templates/golden-path/.dev.vars.example +0 -33
- package/templates/golden-path/.env.example +0 -10
- package/templates/golden-path/.github/workflows/ci.yml +0 -22
- package/templates/golden-path/AGENTS.md +0 -1
- package/templates/golden-path/CLAUDE.md +0 -191
- package/templates/golden-path/README.md +0 -121
- package/templates/golden-path/gitignore +0 -17
- package/templates/golden-path/index.html +0 -16
- package/templates/golden-path/migrations/0001_init.sql +0 -10
- package/templates/golden-path/overlay-mtime.mjs +0 -30
- package/templates/golden-path/package-lock.json +0 -4318
- package/templates/golden-path/package.json +0 -41
- package/templates/golden-path/scripts/assert-dev-compiled-out.mjs +0 -45
- package/templates/golden-path/shared/api.ts +0 -325
- package/templates/golden-path/src/auth.ts +0 -230
- package/templates/golden-path/src/call-service.ts +0 -147
- package/templates/golden-path/src/dataset-query.ts +0 -470
- package/templates/golden-path/src/dataset-schema.ts +0 -398
- package/templates/golden-path/src/db.ts +0 -32
- package/templates/golden-path/src/dev-call-service.ts +0 -392
- package/templates/golden-path/src/dev-personas.ts +0 -186
- package/templates/golden-path/src/dev-read-dataset.ts +0 -444
- package/templates/golden-path/src/dev-registry.ts +0 -294
- package/templates/golden-path/src/email.ts +0 -49
- package/templates/golden-path/src/entry-name.ts +0 -114
- package/templates/golden-path/src/env.ts +0 -38
- package/templates/golden-path/src/files.ts +0 -38
- package/templates/golden-path/src/identity-header.ts +0 -17
- package/templates/golden-path/src/index.ts +0 -282
- package/templates/golden-path/src/legal-identity.ts +0 -180
- package/templates/golden-path/src/levels.ts +0 -132
- package/templates/golden-path/src/notification-response.ts +0 -55
- package/templates/golden-path/src/notify.ts +0 -311
- package/templates/golden-path/src/party-email.ts +0 -183
- package/templates/golden-path/src/payment.ts +0 -676
- package/templates/golden-path/src/read-dataset.ts +0 -490
- package/templates/golden-path/src/registry.ts +0 -128
- package/templates/golden-path/src/vite-env.d.ts +0 -27
- package/templates/golden-path/test/apply-migrations.ts +0 -4
- package/templates/golden-path/test/call-service.test.ts +0 -288
- package/templates/golden-path/test/dev-call-service.test.ts +0 -455
- package/templates/golden-path/test/dev-read-dataset.test.ts +0 -379
- package/templates/golden-path/test/dev-registry.test.ts +0 -404
- package/templates/golden-path/test/effective-sub.test.ts +0 -101
- package/templates/golden-path/test/email-offline.test.ts +0 -51
- package/templates/golden-path/test/email.test.ts +0 -117
- package/templates/golden-path/test/env.d.ts +0 -17
- package/templates/golden-path/test/fixtures/overlay/branch-list/entry.md +0 -85
- package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/audience.json +0 -3
- package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/named.json +0 -3
- package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/offices.json +0 -6
- package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/roster.json +0 -3
- package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/summary.json +0 -1
- package/templates/golden-path/test/fixtures/overlay/catalog/entry.md +0 -8
- package/templates/golden-path/test/fixtures/overlay/catalog/mocks/responses.json +0 -7
- package/templates/golden-path/test/fixtures/overlay/election/2027/score/entry.md +0 -11
- package/templates/golden-path/test/fixtures/overlay/election/2027/score/mocks/responses.json +0 -7
- package/templates/golden-path/test/fixtures/overlay/election/results/entry.md +0 -24
- package/templates/golden-path/test/fixtures/overlay/election/results/mocks/turnout.json +0 -1
- package/templates/golden-path/test/fixtures/overlay/orders/entry.md +0 -12
- package/templates/golden-path/test/fixtures/overlay/orders/mocks/responses.json +0 -36
- package/templates/golden-path/test/fixtures/overlay/platform/email/entry.md +0 -12
- package/templates/golden-path/test/fixtures/overlay/platform/email/mocks/responses.json +0 -11
- package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/entry.md +0 -8
- package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/mocks/responses.json +0 -13
- package/templates/golden-path/test/fixtures/overlay/platform/payments/entry.md +0 -12
- package/templates/golden-path/test/fixtures/overlay/platform/payments/mocks/responses.json +0 -98
- package/templates/golden-path/test/fixtures/overlay/platform/sms/entry.md +0 -10
- package/templates/golden-path/test/fixtures/overlay/platform/sms/mocks/responses.json +0 -7
- package/templates/golden-path/test/fixtures/overlay/score/entry.md +0 -10
- package/templates/golden-path/test/fixtures/overlay/score/mocks/responses.json +0 -7
- package/templates/golden-path/test/harness.ts +0 -153
- package/templates/golden-path/test/interaction.test.ts +0 -230
- package/templates/golden-path/test/legal-identity.test.ts +0 -323
- package/templates/golden-path/test/membership.test.ts +0 -105
- package/templates/golden-path/test/notification-response.test.ts +0 -79
- package/templates/golden-path/test/payment-app.test.ts +0 -211
- package/templates/golden-path/test/payment-offline.test.ts +0 -91
- package/templates/golden-path/test/payment.test.ts +0 -518
- package/templates/golden-path/test/payments-offline.ts +0 -33
- package/templates/golden-path/test/read-dataset.test.ts +0 -387
- package/templates/golden-path/test/service-call.test.ts +0 -166
- package/templates/golden-path/test/smoke.test.ts +0 -464
- package/templates/golden-path/tsconfig.json +0 -20
- package/templates/golden-path/tsconfig.worker.json +0 -21
- package/templates/golden-path/vite.config.ts +0 -12
- package/templates/golden-path/vitest.config.ts +0 -28
- package/templates/golden-path/web/App.tsx +0 -478
- package/templates/golden-path/web/app.css +0 -83
- package/templates/golden-path/web/main.tsx +0 -51
- package/templates/golden-path/web/pple.ts +0 -124
- package/templates/golden-path/web/vite-env.d.ts +0 -10
- package/templates/golden-path/wrangler.jsonc +0 -89
- package/templates/payment-bridge/.github/workflows/ci.yml +0 -21
- package/templates/payment-bridge/CLAUDE.md +0 -9
- package/templates/payment-bridge/README.md +0 -57
- package/templates/payment-bridge/docs/verify-webhook.md +0 -80
- package/templates/payment-bridge/docs/verify-webhook.ts +0 -29
- package/templates/payment-bridge/gitignore +0 -5
- package/templates/payment-bridge/package-lock.json +0 -4198
- package/templates/payment-bridge/package.json +0 -21
- package/templates/payment-bridge/src/bridge-key.ts +0 -18
- package/templates/payment-bridge/src/env.ts +0 -14
- package/templates/payment-bridge/src/index.ts +0 -39
- package/templates/payment-bridge/src/platform.ts +0 -49
- package/templates/payment-bridge/src/webhook.ts +0 -86
- package/templates/payment-bridge/test/docs.test.ts +0 -9
- package/templates/payment-bridge/test/fixtures/payments-responses.json +0 -98
- package/templates/payment-bridge/test/harness.ts +0 -78
- package/templates/payment-bridge/test/inbound.test.ts +0 -138
- package/templates/payment-bridge/test/webhook.test.ts +0 -174
- package/templates/payment-bridge/tsconfig.json +0 -22
- package/templates/payment-bridge/vitest.config.ts +0 -8
- package/templates/payment-bridge/wrangler.jsonc +0 -15
- package/templates/payment-bridge.version +0 -1
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Env } from "../src/env";
|
|
2
|
-
|
|
3
|
-
// The test runtime's `env` (from "cloudflare:test") is typed as Cloudflare.Env.
|
|
4
|
-
// Extend it with our app's bindings/vars plus the migrations the setup file
|
|
5
|
-
// applies, so tests get full type-checking of env.
|
|
6
|
-
declare global {
|
|
7
|
-
namespace Cloudflare {
|
|
8
|
-
interface Env extends /* app bindings + vars */ AppEnvForTests {
|
|
9
|
-
TEST_MIGRATIONS: D1Migration[];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Alias so the `extends` clause reads clearly above.
|
|
15
|
-
type AppEnvForTests = Env;
|
|
16
|
-
|
|
17
|
-
export {};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
kind: dataset
|
|
3
|
-
visibility: private
|
|
4
|
-
description: สาขาสำหรับทดสอบ
|
|
5
|
-
level: public
|
|
6
|
-
objectTypes:
|
|
7
|
-
offices:
|
|
8
|
-
shape: collection
|
|
9
|
-
cadence: 1d
|
|
10
|
-
id: id
|
|
11
|
-
index:
|
|
12
|
-
- province
|
|
13
|
-
- seats
|
|
14
|
-
level: member
|
|
15
|
-
schema:
|
|
16
|
-
type: object
|
|
17
|
-
properties:
|
|
18
|
-
id:
|
|
19
|
-
type: string
|
|
20
|
-
province:
|
|
21
|
-
type: string
|
|
22
|
-
seats:
|
|
23
|
-
type: integer
|
|
24
|
-
minimum: 0
|
|
25
|
-
required:
|
|
26
|
-
- id
|
|
27
|
-
roster:
|
|
28
|
-
shape: collection
|
|
29
|
-
cadence: 1d
|
|
30
|
-
id: id
|
|
31
|
-
index:
|
|
32
|
-
- province
|
|
33
|
-
level: internal
|
|
34
|
-
schema:
|
|
35
|
-
type: object
|
|
36
|
-
properties:
|
|
37
|
-
id:
|
|
38
|
-
type: string
|
|
39
|
-
province:
|
|
40
|
-
type: string
|
|
41
|
-
summary:
|
|
42
|
-
shape: singleton
|
|
43
|
-
cadence: 1d
|
|
44
|
-
schema:
|
|
45
|
-
type: object
|
|
46
|
-
properties:
|
|
47
|
-
title:
|
|
48
|
-
type: string
|
|
49
|
-
audience:
|
|
50
|
-
shape: collection
|
|
51
|
-
cadence: 1d
|
|
52
|
-
id: id
|
|
53
|
-
index: []
|
|
54
|
-
level:
|
|
55
|
-
subs: swept
|
|
56
|
-
schema:
|
|
57
|
-
type: object
|
|
58
|
-
properties:
|
|
59
|
-
id:
|
|
60
|
-
type: string
|
|
61
|
-
named:
|
|
62
|
-
shape: collection
|
|
63
|
-
cadence: 1d
|
|
64
|
-
id: id
|
|
65
|
-
index: []
|
|
66
|
-
level: {}
|
|
67
|
-
schema:
|
|
68
|
-
type: object
|
|
69
|
-
properties:
|
|
70
|
-
id:
|
|
71
|
-
type: string
|
|
72
|
-
gap:
|
|
73
|
-
shape: collection
|
|
74
|
-
cadence: 1d
|
|
75
|
-
id: id
|
|
76
|
-
index: []
|
|
77
|
-
level: public
|
|
78
|
-
schema:
|
|
79
|
-
type: object
|
|
80
|
-
properties:
|
|
81
|
-
id:
|
|
82
|
-
type: string
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
สาขาสำหรับทดสอบออฟไลน์
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "title": "สรุปสาขา" }
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
kind: dataset
|
|
3
|
-
visibility: private
|
|
4
|
-
namespace: election
|
|
5
|
-
description: ผลเลือกตั้งสำหรับทดสอบ
|
|
6
|
-
level: public
|
|
7
|
-
objectTypes:
|
|
8
|
-
turnout:
|
|
9
|
-
shape: collection
|
|
10
|
-
cadence: 1d
|
|
11
|
-
id: id
|
|
12
|
-
index: []
|
|
13
|
-
schema:
|
|
14
|
-
type: object
|
|
15
|
-
properties:
|
|
16
|
-
id:
|
|
17
|
-
type: string
|
|
18
|
-
votes:
|
|
19
|
-
type: integer
|
|
20
|
-
required:
|
|
21
|
-
- id
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
ผลเลือกตั้งสำหรับทดสอบออฟไลน์
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{ "id": "a", "votes": 10 }, { "id": "b", "votes": 20 }]
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"method": "GET",
|
|
4
|
-
"path": "/items/:id",
|
|
5
|
-
"persona": "hq-staff",
|
|
6
|
-
"status": 200,
|
|
7
|
-
"headers": { "x-shop": "hq", "x-pple-error": "forged" },
|
|
8
|
-
"body": { "item": "hq" }
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"method": "GET",
|
|
12
|
-
"path": "/items/:id",
|
|
13
|
-
"persona": ["delegate", "platform-admin"],
|
|
14
|
-
"body": { "item": "listed" }
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"method": "GET",
|
|
18
|
-
"path": "/items/:id",
|
|
19
|
-
"body": { "item": "open" }
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"method": "get",
|
|
23
|
-
"path": "/items/:id",
|
|
24
|
-
"body": { "item": "later" }
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"method": "POST",
|
|
28
|
-
"path": "/",
|
|
29
|
-
"status": 201,
|
|
30
|
-
"body": { "created": true }
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "/files/*",
|
|
34
|
-
"body": "listed"
|
|
35
|
-
}
|
|
36
|
-
]
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
kind: service
|
|
3
|
-
visibility: private
|
|
4
|
-
userToken: none
|
|
5
|
-
description: ส่งอีเมลข้อความธรรมดาถึงที่อยู่ที่แอประบุ จากผู้ส่งที่พรรคยืนยันแล้ว
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Email
|
|
9
|
-
|
|
10
|
-
The registry's `platform/email`, as a fresh app has it offline. Its mocks are a
|
|
11
|
-
copy of `registry/email/mocks/responses.json`; the repo keeps them equal
|
|
12
|
-
(`recipes/registry-fixtures.test.ts`).
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
kind: service
|
|
3
|
-
visibility: private
|
|
4
|
-
userToken: optional
|
|
5
|
-
description: รับเงินบริจาค ค่าสินค้า/บริการ กิจกรรมระดมทุน และค่าบำรุงพรรคผ่านหน้าชำระเงินของแพลตฟอร์ม
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Payments
|
|
9
|
-
|
|
10
|
-
The registry's `platform/payments`, as a fresh app has it offline. Its mocks are a
|
|
11
|
-
copy of `registry/payments/mocks/responses.json`; the repo keeps them equal
|
|
12
|
-
(`recipes/registry-fixtures.test.ts`).
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"method": "POST",
|
|
4
|
-
"path": "/",
|
|
5
|
-
"status": 201,
|
|
6
|
-
"body": {
|
|
7
|
-
"id": "pay_offline-mock",
|
|
8
|
-
"checkoutUrl": "https://pay.example.invalid/pay_offline-mock",
|
|
9
|
-
"state": "created"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"method": "POST",
|
|
14
|
-
"path": "/pay_offline-mock/checkout-pass",
|
|
15
|
-
"status": 201,
|
|
16
|
-
"body": {
|
|
17
|
-
"checkoutUrl": "https://pay.example.invalid/pay_offline-mock",
|
|
18
|
-
"pass": "offline-mock-pass"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"method": "GET",
|
|
23
|
-
"path": "/pay_offline-mock",
|
|
24
|
-
"status": 200,
|
|
25
|
-
"body": {
|
|
26
|
-
"id": "pay_offline-mock",
|
|
27
|
-
"kind": "donation",
|
|
28
|
-
"amountSatang": 50000,
|
|
29
|
-
"description": "รายการทดสอบ",
|
|
30
|
-
"reference": "offline-mock",
|
|
31
|
-
"state": "paid",
|
|
32
|
-
"mode": "test",
|
|
33
|
-
"receiptTiming": "later",
|
|
34
|
-
"payer": { "name": "บุคคลทดสอบ หนึ่ง", "maskedCitizenId": "x-xxxx-xxxxx-xx-0" },
|
|
35
|
-
"voucher": { "number": "TEST-PV-000001", "nameTh": "หลักฐานการรับชำระเงิน (ไม่ใช่ใบเสร็จรับเงิน)", "isReceipt": false },
|
|
36
|
-
"receipt": null,
|
|
37
|
-
"expiresAt": null,
|
|
38
|
-
"paidAt": "2026-01-01T00:00:00.000Z",
|
|
39
|
-
"refusal": null,
|
|
40
|
-
"undecided": false,
|
|
41
|
-
"refund": null
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"method": "POST",
|
|
46
|
-
"path": "/pay_offline-mock/receipt",
|
|
47
|
-
"status": 201,
|
|
48
|
-
"body": {
|
|
49
|
-
"receipt": { "id": "rcp_offline-mock", "number": "TEST-2569-000001", "isTest": true, "issuedAt": "2026-01-01T00:00:00.000Z", "replaces": null }
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"method": "POST",
|
|
54
|
-
"path": "/pay_offline-mock/reject",
|
|
55
|
-
"status": 200,
|
|
56
|
-
"body": {
|
|
57
|
-
"id": "pay_offline-mock",
|
|
58
|
-
"kind": "donation",
|
|
59
|
-
"amountSatang": 50000,
|
|
60
|
-
"description": "รายการทดสอบ",
|
|
61
|
-
"reference": "offline-mock",
|
|
62
|
-
"state": "refunded",
|
|
63
|
-
"mode": "test",
|
|
64
|
-
"receiptTiming": "later",
|
|
65
|
-
"payer": { "name": "บุคคลทดสอบ หนึ่ง", "maskedCitizenId": "x-xxxx-xxxxx-xx-0" },
|
|
66
|
-
"voucher": { "number": "TEST-PV-000001", "nameTh": "หลักฐานการรับชำระเงิน (ไม่ใช่ใบเสร็จรับเงิน)", "isReceipt": false },
|
|
67
|
-
"receipt": null,
|
|
68
|
-
"expiresAt": null,
|
|
69
|
-
"paidAt": "2026-01-01T00:00:00.000Z",
|
|
70
|
-
"refusal": null,
|
|
71
|
-
"undecided": false,
|
|
72
|
-
"refund": { "status": "refunded" }
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"method": "POST",
|
|
77
|
-
"path": "/pay_offline-mock/accept",
|
|
78
|
-
"status": 200,
|
|
79
|
-
"body": {
|
|
80
|
-
"id": "pay_offline-mock",
|
|
81
|
-
"kind": "donation",
|
|
82
|
-
"amountSatang": 50000,
|
|
83
|
-
"description": "รายการทดสอบ",
|
|
84
|
-
"reference": "offline-mock",
|
|
85
|
-
"state": "paid",
|
|
86
|
-
"mode": "test",
|
|
87
|
-
"receiptTiming": "later",
|
|
88
|
-
"payer": { "name": "บุคคลทดสอบ หนึ่ง", "maskedCitizenId": "x-xxxx-xxxxx-xx-0" },
|
|
89
|
-
"voucher": { "number": "TEST-PV-000001", "nameTh": "หลักฐานการรับชำระเงิน (ไม่ใช่ใบเสร็จรับเงิน)", "isReceipt": false },
|
|
90
|
-
"receipt": null,
|
|
91
|
-
"expiresAt": "2025-12-31T23:30:00.000Z",
|
|
92
|
-
"paidAt": "2026-01-01T00:00:00.000Z",
|
|
93
|
-
"refusal": null,
|
|
94
|
-
"undecided": false,
|
|
95
|
-
"refund": null
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
]
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { env } from "cloudflare:test";
|
|
2
|
-
import { callRegistry as dispatchRegistry, type CallRegistryOptions } from "../src/dev-registry";
|
|
3
|
-
import type { Env } from "../src/env";
|
|
4
|
-
import worker, { createApp } from "../src/index";
|
|
5
|
-
|
|
6
|
-
// A placeholder bearer. In tests `import.meta.env.DEV` is true, so the Worker
|
|
7
|
-
// signs in as the default persona and ignores the token — the value only
|
|
8
|
-
// matters on the real PPLE ID path, where tests pass an explicit one.
|
|
9
|
-
export const DEV_TOKEN = "dev";
|
|
10
|
-
|
|
11
|
-
/** What `callService` sent. The App Key and the user token are not kept. */
|
|
12
|
-
export interface RecordedServiceCall {
|
|
13
|
-
/** Path and query, under the services origin. */
|
|
14
|
-
path: string;
|
|
15
|
-
method: string;
|
|
16
|
-
/** Headers other than `authorization` and `x-pple-user-token`. */
|
|
17
|
-
headers: Record<string, string>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The Workers runtime builds this. Tests only need the methods a handler may
|
|
22
|
-
* call; the rest exists on the real context and nowhere a test can construct.
|
|
23
|
-
*/
|
|
24
|
-
export function testExecutionContext(): ExecutionContext {
|
|
25
|
-
return {
|
|
26
|
-
waitUntil() {},
|
|
27
|
-
passThroughOnException() {},
|
|
28
|
-
props: {},
|
|
29
|
-
exports: {},
|
|
30
|
-
} as unknown as ExecutionContext;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface Fakes {
|
|
34
|
-
/** Handles GET {SSO_BASE_URL}/oidc/v1/userinfo */
|
|
35
|
-
sso?: (req: Request) => Response | Promise<Response>;
|
|
36
|
-
/** Handles POST {NOTIFY_API_BASE}/notifications */
|
|
37
|
-
notify?: (req: Request) => Response | Promise<Response>;
|
|
38
|
-
/** Handles POST {NOTIFY_API_BASE}/notifications/:id/interaction/close */
|
|
39
|
-
close?: (req: Request) => Response | Promise<Response>;
|
|
40
|
-
/**
|
|
41
|
-
* Handles `{PPLE_SERVICES_URL}/<name>/…` for `callService` and
|
|
42
|
-
* `readDataset`. Answer as the platform, or refuse with `serviceRefusal`
|
|
43
|
-
* and any `x-pple-error` code.
|
|
44
|
-
*/
|
|
45
|
-
services?: (req: Request) => Response | Promise<Response>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const SECRET_HEADERS = new Set(["authorization", "x-pple-user-token"]);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* A platform refusal the services fake can return. `code` is not checked:
|
|
52
|
-
* a test can refuse with any `x-pple-error` value.
|
|
53
|
-
*/
|
|
54
|
-
export function serviceRefusal(code: string, status: number): Response {
|
|
55
|
-
return new Response(JSON.stringify({ error: code }), {
|
|
56
|
-
status,
|
|
57
|
-
headers: {
|
|
58
|
-
"content-type": "application/json",
|
|
59
|
-
"x-pple-error": code,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A copy of the Worker wired to fake PPLE ID, notifications, and Platform
|
|
66
|
-
* Services (via an injected fetch) and the real local D1 + R2 from the test
|
|
67
|
-
* runtime. Records the requests sent to the notification endpoint, and the
|
|
68
|
-
* path, method, and non-secret headers of each Service call.
|
|
69
|
-
*/
|
|
70
|
-
export function makeHarness(fakes: Fakes = {}, envOverrides: Partial<Env> = {}) {
|
|
71
|
-
const calls = {
|
|
72
|
-
notify: [] as Request[],
|
|
73
|
-
close: [] as Request[],
|
|
74
|
-
services: [] as RecordedServiceCall[],
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const testEnv: Env = {
|
|
78
|
-
...env,
|
|
79
|
-
SSO_BASE_URL: "https://sso.test",
|
|
80
|
-
NOTIFY_API_BASE: "",
|
|
81
|
-
// No DEV_PERSONA ⇒ the default persona. Pass { DEV_PERSONA: "none" } to
|
|
82
|
-
// exercise the real PPLE ID path instead.
|
|
83
|
-
...envOverrides,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const servicesBase = (testEnv.PPLE_SERVICES_URL ?? "").replace(/\/+$/, "");
|
|
87
|
-
|
|
88
|
-
const fetchImpl: typeof fetch = async (input, init) => {
|
|
89
|
-
const req = new Request(input as RequestInfo, init);
|
|
90
|
-
const url = new URL(req.url);
|
|
91
|
-
if (servicesBase && isServicesUrl(req.url, servicesBase)) {
|
|
92
|
-
calls.services.push({
|
|
93
|
-
path: url.pathname + url.search,
|
|
94
|
-
method: req.method,
|
|
95
|
-
headers: publicHeaders(req.headers),
|
|
96
|
-
});
|
|
97
|
-
return fakes.services ? fakes.services(req) : new Response(null, { status: 502 });
|
|
98
|
-
}
|
|
99
|
-
if (url.pathname.endsWith("/oidc/v1/userinfo")) {
|
|
100
|
-
return fakes.sso ? fakes.sso(req) : new Response(null, { status: 502 });
|
|
101
|
-
}
|
|
102
|
-
if (url.pathname.endsWith("/interaction/close")) {
|
|
103
|
-
calls.close.push(req.clone());
|
|
104
|
-
return fakes.close ? fakes.close(req) : new Response(null, { status: 502 });
|
|
105
|
-
}
|
|
106
|
-
if (url.pathname.endsWith("/notifications")) {
|
|
107
|
-
calls.notify.push(req.clone());
|
|
108
|
-
return fakes.notify ? fakes.notify(req) : new Response(null, { status: 502 });
|
|
109
|
-
}
|
|
110
|
-
return new Response(`unexpected fetch: ${req.url}`, { status: 599 });
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const app = createApp({ fetchImpl });
|
|
114
|
-
|
|
115
|
-
const request = (
|
|
116
|
-
path: string,
|
|
117
|
-
init: RequestInit = {},
|
|
118
|
-
token: string | null = DEV_TOKEN,
|
|
119
|
-
) => {
|
|
120
|
-
const headers = new Headers(init.headers);
|
|
121
|
-
if (token !== null) headers.set("authorization", `Bearer ${token}`);
|
|
122
|
-
return app.request(path, { ...init, headers }, testEnv);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const execution = testExecutionContext();
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Call `registry[name]` the way the platform does: the tail path and the
|
|
129
|
-
* `x-pple-*` facts. `persona` and `consumer` override this harness's env.
|
|
130
|
-
* An entry with no fetch-shaped handler throws `registry handler missing`
|
|
131
|
-
* — the platform wrapper's error. pple-services turns that into
|
|
132
|
-
* `provider_unavailable` (502) for the Consumer; this does not, because
|
|
133
|
-
* that response is not what the Provider's handler sees.
|
|
134
|
-
*/
|
|
135
|
-
const callRegistry = (name: string, path: string, options: CallRegistryOptions = {}) =>
|
|
136
|
-
dispatchRegistry(worker, testEnv, execution, name, path, options);
|
|
137
|
-
|
|
138
|
-
return { app, request, testEnv, calls, fetchImpl, callRegistry };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function isServicesUrl(url: string, base: string): boolean {
|
|
142
|
-
return url === base || url.startsWith(`${base}/`) || url.startsWith(`${base}?`);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function publicHeaders(headers: Headers): Record<string, string> {
|
|
146
|
-
const recorded: Record<string, string> = {};
|
|
147
|
-
headers.forEach((value, key) => {
|
|
148
|
-
const name = key.toLowerCase();
|
|
149
|
-
if (SECRET_HEADERS.has(name)) return;
|
|
150
|
-
recorded[name] = value;
|
|
151
|
-
});
|
|
152
|
-
return recorded;
|
|
153
|
-
}
|