@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pplethai/cli",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,13 +12,10 @@
12
12
  },
13
13
  "files": [
14
14
  "askpass",
15
- "dist",
16
- "templates"
15
+ "dist"
17
16
  ],
18
17
  "scripts": {
19
- "build": "npm run build:template && node scripts/bundle.mjs",
20
- "build:template": "node scripts/bundle-template.mjs",
21
- "verify:template": "node scripts/verify-template.mjs",
18
+ "build": "node scripts/bundle.mjs",
22
19
  "typecheck": "tsc --noEmit",
23
20
  "test": "vitest run",
24
21
  "test:watch": "vitest"
@@ -1,33 +0,0 @@
1
- # Optional local-development overrides. `npm run dev` works with NO `.dev.vars`
2
- # at all — copy this to `.dev.vars` (gitignored) only if you want one of the
3
- # settings below. `vite dev` and `wrangler dev` load `.dev.vars` automatically.
4
-
5
- # Which mock identity to sign in as locally. Defaults to "hq-staff".
6
- # Built-in personas: hq-staff, province-coordinator, platform-admin, delegate,
7
- # member (a party member with no role), unverified, kyc-pending,
8
- # kyc-verified-nonmember
9
- # (add your own in src/dev-personas.ts). Set to "none" to turn the bypass off
10
- # and exercise the real PPLE ID sign-in path locally.
11
- # On /.pple/registry/…, "none" or an unknown name sends no x-pple-identity
12
- # (the same as userToken: none). An unknown name does not fall back to
13
- # hq-staff on that path; /api still does.
14
- # DEV_PERSONA="province-coordinator"
15
-
16
- # Make offline callService return a platform refusal instead of a mock.
17
- # A code applies to every entry. name=code applies to one entry
18
- # and wins over the global code. Separate several with commas.
19
- # invalid_app_key, not_listed, not_granted, needs_beta, user_token_invalid,
20
- # identity_unavailable, provider_unavailable, provider_timeout.
21
- # An unknown code is ignored.
22
- # DEV_REGISTRY_ERROR="needs_beta"
23
- # DEV_REGISTRY_ERROR="not_granted,orders=provider_timeout"
24
-
25
- # Consumer slug reported on the emulated registry path. Defaults to
26
- # "dev-consumer". `x-pple-entry` is the bare name;
27
- # the dev Provider is dev-provider.
28
- # DEV_CONSUMER="brave-purple-lion"
29
-
30
- # Exercise the notification helper locally. These are normally injected by the
31
- # platform at deploy time.
32
- # NOTIFY_API_BASE="https://today.peoplesparty.or.th"
33
- # NOTIFY_API_KEY="your-app-notification-key"
@@ -1,10 +0,0 @@
1
- # Frontend build-time config (Vite exposes VITE_* to the browser bundle).
2
- # These are the app's PPLE ID OIDC client details, used by the mini-app SDK
3
- # inside PPLE Today and for the browser PPLE ID login. They are public values,
4
- # safe to ship. The platform injects them at deploy time; copy to `.env` to
5
- # set locally.
6
- VITE_OAUTH_URL="https://id.peoplesparty.or.th"
7
- VITE_OAUTH_CLIENT_ID=""
8
- # Defaults to the app's own origin if unset — must match the redirect URI
9
- # on the app's provisioned PPLE ID OAuth client (the mini-app URL).
10
- # VITE_OAUTH_REDIRECT_URI=""
@@ -1,22 +0,0 @@
1
- # CI for a PPLE Platform Builder App. Runs on every push and pull request:
2
- # type-checks the Worker and the React app, runs the smoke tests in the
3
- # Workers runtime, and builds the deployable bundle.
4
- name: CI
5
-
6
- on:
7
- push:
8
- pull_request:
9
-
10
- jobs:
11
- check:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: actions/setup-node@v4
16
- with:
17
- node-version: 22
18
- cache: npm
19
- - run: npm ci
20
- - run: npm run typecheck
21
- - run: npm test
22
- - run: npm run build
@@ -1 +0,0 @@
1
- Before you start, read `.pple/rules.md` — the PPLE Platform Rules for this app. They win over anything else in the repo.
@@ -1,191 +0,0 @@
1
- # Working in this repo
2
-
3
- This is a **PPLE Platform Builder App** — a mobile-first mini-app that runs
4
- inside PPLE Today. Prefer editing the existing demo cards over introducing new
5
- patterns.
6
-
7
- The platform-wide rules (Platform Rules) and the `pple-platform` Skill are
8
- delivered by the `pple` CLI as git-ignored local files, and kept current by it.
9
- This file is only about *this* app, and where it disagrees with Platform Rules,
10
- Platform Rules win.
11
-
12
- ## Architecture (read once)
13
-
14
- One Cloudflare Worker serves everything:
15
-
16
- - **`src/`** — the Worker (API). Hono, TypeScript, Workers runtime. Routes
17
- live under `/api/*` in `src/index.ts`; keep handlers thin and put logic in
18
- the helper modules (`auth`, `db`, `files`, `notify`).
19
- - **`web/`** — the React app (browser). Built by Vite, served for every
20
- non-`/api` path. Uses the `@pplethai/components` design system.
21
- - **`shared/`** — types shared by both sides (Zod schemas in `shared/api.ts`).
22
- When you change an API shape, change it here and both sides update.
23
- - **`migrations/`** — D1 (SQLite) schema, applied in order.
24
-
25
- The frontend calls the backend with `api()` / `apiJson()` from `web/pple.ts`,
26
- which attach the PPLE ID bearer token. Same origin, so paths are relative
27
- (`/api/notes`).
28
-
29
- ## How auth works
30
-
31
- Every `/api/*` request carries a PPLE ID bearer token; the Worker resolves it
32
- to an `Identity` (`src/auth.ts`, shape in `shared/api.ts`) with two faces:
33
-
34
- - **`actor`** — the real human clicking (`sub`, `name`, `mobile`, `membership`).
35
- For audit and display only. `membership` is `{ memberSince }` while the
36
- party membership is active, and null otherwise.
37
- - **`effective`** — what they may do: `sub` (the person whose authority is
38
- in effect), `activeRole`, `eligibleRoles`, `provinces` (scope), `extraRoles`
39
- (capabilities like `platform:admin`). Under delegation these are the
40
- *supervisor's* values, `effective.sub` is that person's PPLE ID sub (or null
41
- when they have none), and `effective.isDelegated` is true.
42
-
43
- Where the token comes from:
44
-
45
- - Inside PPLE Today, the mini-app SDK (`web/pple.ts`) captures the access token
46
- from the launch URL; the Worker validates it against PPLE ID.
47
- - In a plain browser, the same SDK runs the PPLE ID OIDC login (redirect /
48
- callback).
49
- - Locally (`npm run dev`) there is no login: the Worker signs you in as a mock
50
- **persona** (`DEV_PERSONA`, default `hq-staff` — see `src/dev-personas.ts`).
51
- To test a province-scoped feature use `DEV_PERSONA=province-coordinator`;
52
- for delegation use `delegate`; for admin-only paths use `platform-admin`;
53
- for a party member with no role use `member`.
54
- This bypass is gated on `import.meta.env.DEV`, so it is compiled out of the
55
- deployed Worker — there is nothing to set or unset for production.
56
- - A Service handler lives on `registry` in `src/index.ts`. Locally, curl
57
- `/.pple/registry/<name>/…`. The dev wrapper sets `x-pple-consumer`
58
- (`DEV_CONSUMER`, default `dev-consumer`), `x-pple-entry`
59
- (the bare `<name>`; the dev Provider is `dev-provider`), and `x-pple-identity` from the active Persona.
60
- `DEV_PERSONA=none` or an unknown persona name omits the Identity (as
61
- `userToken: none` does) and does not fall back to `hq-staff` on this path.
62
- Read the caller with `serviceCall(request)`. Tests call `callRegistry` from
63
- `test/harness.ts`. An entry with no handler throws `registry handler missing`.
64
- The wrapper is compiled out of the deployed Worker.
65
- - `callService` takes the entry's full name: a bare name such as `branch-list`,
66
- a Namespace (กลุ่มชื่อ) name such as `election/2027/score`, or one of the
67
- platform's own entries, which all sit under `platform`: `platform/sms`,
68
- `platform/email`, `platform/legal-identity`. A bare `sms` names nothing, and `platform` on its
69
- own is refused. Locally it answers from
70
- `.pple/registry/<full name>/mocks/responses.json` (nested folders for a
71
- Namespace) as the active persona (`x-pple-mock` names the entry). A `userToken: required`
72
- entry called with no token is `user_token_invalid`. Nothing matched is
73
- `no_mock` (404), dev-only, with a Thai message that names `pple registry`.
74
- `DEV_REGISTRY_ERROR` (`<code>` or `<full name>=<code>`, commas) returns
75
- that platform refusal instead. A persona added in `dev-personas.ts` only
76
- hits cases that name no persona. `DEV_PERSONA=none` calls the real service.
77
- Vitest uses the injected fetch and does not read the overlay. The overlay
78
- glob keeps `.pple/registry` in its fixed base, and the whole path is
79
- compiled out of the deployed Worker. `getLegalIdentity` still uses its own
80
- offline answer.
81
- - `readDataset(env, entry, objectType, options)` reads a Dataset Object Type.
82
- A collection page is `{ objects, next, sweptAt, snapshot }`; a singleton or
83
- an id lookup is `{ object, sweptAt, snapshot }`. Pass `filter`, `sort` and
84
- `limit`; pass `id` to look one object up; pass `follow: true` to walk
85
- `next`. Pass `ifNoneMatch: <etag>` on a page, singleton or lookup to poll:
86
- a `304` is `{ ok: true, status: 304, etag, notModified: true }` with no `data`
87
- (check `notModified` after `ok`); `follow: true` refuses it. The user token is `options.userToken` and is sent only when set.
88
- Platform refusals are `x-pple-error` (`not_found`, `invalid_query`,
89
- `level_not_met`, and the same codes as `callService`). Locally it reads
90
- `.pple/registry/<full name>/mocks/<objectType>.json` through the same
91
- query rules and `passesLevel` against the active Persona. `sweptAt` is the
92
- mock file's write time. A level whose `subs` list is missing, including
93
- `subs: swept`, admits nobody offline. `DEV_REGISTRY_ERROR` and `no_mock`
94
- work as they do for `callService`. `DEV_PERSONA=none` calls the real
95
- service. Vitest uses the injected fetch. This path is compiled out of the
96
- deployed Worker.
97
-
98
- ## Conventions
99
-
100
- - **TypeScript is strict.** Run `npm run typecheck` after changes.
101
- - **Validate input with the Zod schemas** in `shared/api.ts`.
102
- - **Notifications**: the shape that makes the audience required is in
103
- `shared/api.ts`; read the rules that come with naming recipients before
104
- changing anything there.
105
- - **Interactive Notifications**: `sendNotification` takes an optional
106
- `interaction` and returns `notificationId`; `closeInteraction` closes it
107
- early. Keep `linkPath` as the fallback. `interaction.liveActivity: true`
108
- asks for a Live Activity on capable iPhones: urgent questions closing
109
- within 8 h only, and never rely on it being seen. Answers (Notification
110
- Responses) arrive at `notificationResponse` on the default export (`src/index.ts`,
111
- type in `src/notification-response.ts`): dedupe on `event.id`, pick a winner
112
- by `respondedAt` then `id` (answers can come after a close), return `410` to
113
- stop answers, do slow work in `ctx.waitUntil`. The responder is
114
- `event.responder.sub` only. Try the question with `pple notify test` (it
115
- reaches only you; its answers reach no handler). Full guide: the
116
- `pple-platform` Skill, mini-app reference.
117
- - **Payments**: take a donation, a sale (`items`), a fundraising (`event`) or a
118
- membership fee (`term`) through the Private Platform
119
- Service `platform/payments` (Use Grant needed; Beta or Live). `src/payment.ts`
120
- has `createPayment` (send the Payer to its `checkoutUrl`; never build a card
121
- form), `createCheckoutPass` (when the Payer is signed in and taps to pay, send
122
- them with `goToCheckout(paymentId)` from `web/pple.ts`, which posts the pass as
123
- a form from your page (never a link), so they skip signing in again; ask at
124
- the tap, not at create time; `not_your_payment` is a `409`: the Payment is
125
- someone else's; `POST /api/payments/:id/checkout` does it), `getPayment`, `issueReceipt`, `rejectPayment`, `verifyPaymentEvent`,
126
- `acceptPayment` and `paymentHandler`. Holding stock or a slot while the Payer
127
- pays: give `createPayment` an `expiresAt` (10 minutes to 30 days ahead), run your
128
- own timer for the hold (`payment.expired` can come up to about 60 minutes late),
129
- and answer `payment.late` (money confirmed after `expiresAt`) by checking your
130
- hold: `acceptPayment` or `rejectPayment`. The outcome arrives at `payment` on the default export
131
- (`createPaymentHandler` in `src/index.ts` is the starting point): it verifies
132
- the event and **does not issue a Receipt**: you choose, issue at payment or
133
- verify first and then issue or reject (both are in the Skill's payments reference).
134
- Gate the button on `actor.kyc.verified`. You only ever see `maskedCitizenId`:
135
- never show, log or store a full citizen ID. Only Live takes real money, and a
136
- rejected QR payment becomes a Refund Owed. Offline, the mocks pay
137
- for every Persona; `unverified` and `kyc-pending` are stopped by your own
138
- `actor.kyc.verified` gate (see `test/payment-app.test.ts`). A system outside the
139
- platform needs a stub app: the `pple-platform` Skill's payments reference has the
140
- recipe (it is not in this template).
141
- - **Email**: send through `platform/email` (Use Grant; Beta or Live) with
142
- `src/email.ts`. Build HTML only with its `html` tag, which escapes what users
143
- typed (`raw()` is for markup you wrote, never for user text), wrap it in
144
- `partyEmail()` for the party layout and a plain-text part, and send with
145
- `sendEmail()`. Button links must be `https:` or `mailto:`.
146
- - **Mobile-first layout** uses the layout classes in `web/app.css`.
147
- - **Add a DB table** by writing a new migration and running
148
- `npm run db:migrate:local`.
149
-
150
- ## KYC Status and Legal Identity
151
-
152
- **KYC Status** is `actor.kyc`. Gate on `actor.kyc.verified`. It is never on
153
- `effective`. After someone returns from `/kyc`, re-read userinfo — `?kyc=` is
154
- a UI hint only. `kyc.verified` means PPLE ID knows a real person behind the
155
- account; it does not prove the account holder is the cardholder, and an app
156
- that needs that check adds its own.
157
-
158
- A **Legal Identity** (name and citizen ID) is not in userinfo. Call
159
- `getLegalIdentity(env, token)` only at the moment it is needed, such as
160
- checkout, and copy it onto that record, such as the receipt. Not on page
161
- views, and nowhere else — do not log, cache, or store it aside from that
162
- record. `idCardNumber` may be `null` for a member without a KYC record; send
163
- them through `/kyc` (`kycStartUrl`) if the app needs the number.
164
-
165
- Under delegation the Legal Identity is the actor's. If delegated use should
166
- be blocked, check `effective.isDelegated`.
167
-
168
- Legal Identity is the Private Platform Service `platform/legal-identity`, so
169
- the app needs a Use Grant: with the Builder's agreement, file
170
- `pple request use platform/legal-identity --reason "…"`. Calls flow at Beta
171
- or Live. `getLegalIdentity` reasons:
172
- `not_configured` (bindings missing), `invalid_app_key`, `not_granted`,
173
- `needs_beta` (the grant is held and the app is still Draft), `not_verified`,
174
- `user_token_invalid`, `upstream_unavailable`.
175
-
176
- Locally, try `DEV_PERSONA=unverified`, `kyc-pending`, or
177
- `kyc-verified-nonmember`. Member Personas are verified via membership and the
178
- offline helper returns `idCardNumber: null`.
179
-
180
- ## Before you finish
181
-
182
- Run these and make sure they pass:
183
-
184
- ```bash
185
- npm run typecheck
186
- npm test
187
- npm run build
188
- ```
189
-
190
- `npm test` runs the smoke tests inside the real Workers runtime. If you add a
191
- capability, add a smoke test for it in `test/`.
@@ -1,121 +0,0 @@
1
- # PPLE Platform — Golden-path template
2
-
3
- The starting point for a **Builder App** on the PPLE Platform. It's a
4
- mobile-first mini-app that runs inside PPLE Today, built on the platform's
5
- managed Cloudflare stack, wired to the People's Party identity, data, file,
6
- and notification services out of the box.
7
-
8
- You don't need to understand Cloudflare, OAuth, or SQL to use it — describe
9
- what you want to your AI coding agent and edit the demo cards. See
10
- [CLAUDE.md](CLAUDE.md) for how the agent should work in this repo.
11
-
12
- ## What's inside
13
-
14
- | Capability | Where | Demo |
15
- | ---------- | ----- | ---- |
16
- | **API** | Hono Worker, `src/index.ts` | routes under `/api/*` |
17
- | **Identity** | `src/auth.ts` + `web/pple.ts` | validates PPLE ID tokens; browser PPLE ID login; local mock personas (`src/dev-personas.ts`) |
18
- | **Database** | D1, `src/db.ts` + `migrations/` | the Notes card |
19
- | **Files** | R2, `src/files.ts` | the Files card |
20
- | **Notifications** | `src/notify.ts` | the Notify card (Broadcast or Direct; optional `linkPath`) |
21
- | **Payments** | `src/payment.ts`, `POST /api/payments` | donations and membership fees through the platform's Checkout Page, with a Receipt (needs the `platform/payments` Use Grant; offline with `DEV_PERSONA`, see `test/payment-app.test.ts`) |
22
- | **Design system** | `@pplethai/components` | every screen |
23
-
24
- One Worker serves the API under `/api/*` and the React app (`web/`) for
25
- everything else — same origin, no CORS.
26
-
27
- ## Getting started
28
-
29
- ```bash
30
- npm install
31
- npm run dev # http://localhost:5173
32
- ```
33
-
34
- `npm run dev` applies your local database migrations, then starts the
35
- full-stack dev server. No config files, no PPLE Today, no OAuth: you're signed
36
- in automatically as a mock **persona** (`hq-staff` by default). To develop as
37
- someone else, set `DEV_PERSONA` in `.dev.vars` (see `.dev.vars.example`) to
38
- `hq-staff`, `province-coordinator`, `platform-admin`, `delegate`, or `member` —
39
- or add your own in `src/dev-personas.ts`.
40
-
41
- `callService` on `npm run dev` answers from
42
- `.pple/registry/<full name>/mocks/responses.json` (nested for a Namespace such as `election/2027/score`) as that persona. A
43
- missing entry or route is `no_mock` (404) and names `pple registry`. Set
44
- `DEV_REGISTRY_ERROR` to rehearse a platform refusal such as `not_granted` or
45
- `provider_timeout`: `<code>` for every entry, or `<full name>=<code>` for one
46
- (`orders=provider_timeout`). `DEV_PERSONA=none` calls the real service. This path is
47
- compiled out of the deployed Worker.
48
-
49
- `readDataset` on `npm run dev` reads
50
- `.pple/registry/<full name>/mocks/<objectType>.json` the same way:
51
- filters, sort and pages run locally, and the active persona has to pass the
52
- Object Type's level. `sweptAt` is the time that mock file was written. A
53
- level that only names people, or a swept list, admits nobody offline — those
54
- lists are not in the overlay. `DEV_REGISTRY_ERROR` and `no_mock` work as they
55
- do for `callService`. `DEV_PERSONA=none` reads the real Dataset. This path is
56
- compiled out of the deployed Worker.
57
-
58
- To exercise a Service this app provides, curl
59
- `/.pple/registry/<name>/…` on the dev server. That path is delivered to
60
- `registry[name]` with the active Persona's Identity and a fake Consumer
61
- (`dev-consumer`, or `DEV_CONSUMER`). `x-pple-entry` is the bare name; the dev Provider is `dev-provider`.
62
- `DEV_PERSONA=none`, or a persona name that is not defined, sends no
63
- Identity — the same as an entry that declares `userToken: none`. An unknown
64
- name does not fall back to `hq-staff` on this path. The wrapper is compiled
65
- out of the deployed Worker. Tests use `callRegistry` from `test/harness.ts`.
66
-
67
- Opened inside PPLE Today, the mini-app SDK signs the real user in from the
68
- launch URL; opened in a plain browser after deploy, the same SDK runs the
69
- PPLE ID login. (`pple init` runs `npm install` and the first migration for
70
- you, so a freshly created app is ready to `npm run dev` straight away.)
71
-
72
- ## Everyday commands
73
-
74
- | Command | Does |
75
- | ------- | ---- |
76
- | `npm run dev` | Full-stack dev server (React + Worker) with hot reload |
77
- | `npm run typecheck` | Type-check the app and the Worker |
78
- | `npm test` | Run the smoke tests in the Workers runtime |
79
- | `npm run build` | Build the deployable bundle |
80
- | `npm run db:migrate:local` | Apply migrations to the local database |
81
- | `pple deploy` | Ship it (the platform CLI; wraps `npm run deploy`) |
82
-
83
- ## Making it yours
84
-
85
- - **Add a table:** create `migrations/0002_*.sql`, run `npm run db:migrate:local`,
86
- add queries in `src/db.ts`. Deploying applies it to the live database for you
87
- — never edit a migration that has already shipped, add another one.
88
- - **Add an API route:** add it under `/api` in `src/index.ts`.
89
- - **Change the UI:** edit `web/App.tsx` using `@pplethai/components`.
90
- - **Send notifications:** the platform provisions `NOTIFY_API_KEY`; the helper
91
- in `src/notify.ts` speaks the shipped contract. Every send states its
92
- audience — everyone this app can reach, or the people it names by PPLE ID
93
- `sub` or mobile number. Naming only ever narrows that set: someone who has
94
- never opened this app receives nothing.
95
- - **Ask a question in a notification:** pass `interaction` to `notify()`, keep
96
- `linkPath` as the fallback, and add `notificationResponse` to the default
97
- export to receive the answers (dedupe on `id`; `410` stops them; slow work
98
- in `ctx.waitUntil`). `closeInteraction()` stops answers early. See a sample
99
- in `test/notification-response.test.ts`. `pple notify test <file.json | ->`
100
- shows the question on your own phone; its answers reach no handler.
101
-
102
- - **Take a payment:** `createPayment` in `src/payment.ts` asks the platform's
103
- `platform/payments` Service for a Payment; send the Payer to the
104
- `checkoutUrl` it returns (never build a card form). When the Payer is signed
105
- in, `createCheckoutPass` (`POST /api/payments/:id/checkout`) gives a
106
- `checkoutUrl` and a one-use `pass` that skip signing in again: ask for it when
107
- they tap to pay, post the pass as a form from your page (`goToCheckout` in
108
- `web/pple.ts`, never a link),
109
- and treat `not_your_payment` (`409`) as "this Payment is someone else's". The
110
- outcome arrives at
111
- `payment` on the default export, where `verifyPaymentEvent` checks it and
112
- your code decides: `issueReceipt` or `rejectPayment`. The starter handler only
113
- verifies and does not issue a Receipt for you. To hold something while the Payer
114
- pays, pass `expiresAt` to `createPayment` and run your own timer: `payment.expired`
115
- can come up to about an hour late, and money confirmed after `expiresAt` arrives
116
- as `payment.late`: `acceptPayment` or `rejectPayment` it. You only ever see a masked
117
- citizen ID. Only a Live app takes real money. A system outside the platform
118
- needs a stub app: the `pple-platform` Skill has the recipe (it is not part of
119
- this template).
120
-
121
- The demo cards (Notes / Files / Notify) are examples — replace them.
@@ -1,17 +0,0 @@
1
- node_modules/
2
- dist/
3
- .wrangler/
4
- .dev.vars
5
- *.log
6
- .claude/skills/pple-platform/
7
- .claude/rules/pple-platform.md
8
- .agents/skills/pple-platform/
9
- .cursor/rules/pple-platform.mdc
10
- .pple/rules.md
11
- .pple/guidance.json
12
- .claude/skills/pple-durable-objects/
13
- .agents/skills/pple-durable-objects/
14
- .pple/durable-object-guidance.json
15
- .pple/registry/
16
- .pple/registry.json
17
- .pple/registry-check.json
@@ -1,16 +0,0 @@
1
- <!doctype html>
2
- <html lang="th">
3
- <head>
4
- <meta charset="utf-8" />
5
- <!-- Mobile-first: fit the notch/safe areas of the PPLE Today WebView. -->
6
- <meta
7
- name="viewport"
8
- content="width=device-width, initial-scale=1, viewport-fit=cover"
9
- />
10
- <title>PPLE App</title>
11
- </head>
12
- <body>
13
- <div id="root"></div>
14
- <script type="module" src="/web/main.tsx"></script>
15
- </body>
16
- </html>
@@ -1,10 +0,0 @@
1
- -- The example table behind the D1 read/write demo. Replace it with your own
2
- -- schema: add a new file (0002_add_something.sql, …) and apply it locally with
3
- -- `npm run db:migrate:local`. Deployed databases migrate themselves — the
4
- -- platform applies everything in this directory on each deploy.
5
- CREATE TABLE notes (
6
- id INTEGER PRIMARY KEY AUTOINCREMENT,
7
- body TEXT NOT NULL,
8
- -- ISO-8601 UTC (…T…Z) so the timestamp is unambiguous everywhere it's read.
9
- created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
10
- );
@@ -1,30 +0,0 @@
1
- // Embeds an overlay file's mtime for offline readDataset (ADR-0030).
2
- //
3
- // The Worker cannot stat a file. Vite replaces `import.meta.glob` of `?mtime`
4
- // with this module, so `sweptAt` is the time the overlay was written. The
5
- // glob sits in an `import.meta.env.DEV` branch and is absent from the
6
- // production build.
7
-
8
- import fs from "node:fs";
9
-
10
- export function overlayMtimePlugin() {
11
- return {
12
- name: "pple-overlay-mtime",
13
- enforce: "pre",
14
- load(id) {
15
- const split = id.indexOf("?");
16
- if (split === -1) return null;
17
- const query = id.slice(split + 1);
18
- const wants = query.split("&").some((part) => part === "mtime" || part.startsWith("mtime="));
19
- if (!wants) return null;
20
- const file = id.slice(0, split);
21
- let iso = "";
22
- try {
23
- iso = fs.statSync(file).mtime.toISOString();
24
- } catch {
25
- iso = "";
26
- }
27
- return `export default ${JSON.stringify(iso)};`;
28
- },
29
- };
30
- }