@pplethai/cli 0.21.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.
- package/README.md +12 -14
- package/dist/bin.js +102 -102
- 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 -187
- package/templates/golden-path/README.md +0 -118
- 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 -224
- 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 -276
- 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/payment.ts +0 -554
- 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 -71
- 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 -210
- package/templates/golden-path/test/payment-offline.test.ts +0 -91
- package/templates/golden-path/test/payment.test.ts +0 -427
- 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 -71
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pplethai/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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": "
|
|
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,187 +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
|
-
and `paymentHandler`. The outcome arrives at `payment` on the default export
|
|
127
|
-
(`createPaymentHandler` in `src/index.ts` is the starting point): it verifies
|
|
128
|
-
the event and **does not issue a Receipt**: you choose, issue at payment or
|
|
129
|
-
verify first and then issue or reject (both are in the Skill's payments reference).
|
|
130
|
-
Gate the button on `actor.kyc.verified`. You only ever see `maskedCitizenId`:
|
|
131
|
-
never show, log or store a full citizen ID. Only Live takes real money, and a
|
|
132
|
-
rejected QR payment becomes a Refund Owed. Offline, the mocks pay
|
|
133
|
-
for every Persona; `unverified` and `kyc-pending` are stopped by your own
|
|
134
|
-
`actor.kyc.verified` gate (see `test/payment-app.test.ts`). A system outside the
|
|
135
|
-
platform needs a stub app: the `pple-platform` Skill's payments reference has the
|
|
136
|
-
recipe (it is not in this template).
|
|
137
|
-
- **Email**: send through `platform/email` (Use Grant; Beta or Live) with
|
|
138
|
-
`src/email.ts`. Build HTML only with its `html` tag, which escapes what users
|
|
139
|
-
typed (`raw()` is for markup you wrote, never for user text), wrap it in
|
|
140
|
-
`partyEmail()` for the party layout and a plain-text part, and send with
|
|
141
|
-
`sendEmail()`. Button links must be `https:` or `mailto:`.
|
|
142
|
-
- **Mobile-first layout** uses the layout classes in `web/app.css`.
|
|
143
|
-
- **Add a DB table** by writing a new migration and running
|
|
144
|
-
`npm run db:migrate:local`.
|
|
145
|
-
|
|
146
|
-
## KYC Status and Legal Identity
|
|
147
|
-
|
|
148
|
-
**KYC Status** is `actor.kyc`. Gate on `actor.kyc.verified`. It is never on
|
|
149
|
-
`effective`. After someone returns from `/kyc`, re-read userinfo — `?kyc=` is
|
|
150
|
-
a UI hint only. `kyc.verified` means PPLE ID knows a real person behind the
|
|
151
|
-
account; it does not prove the account holder is the cardholder, and an app
|
|
152
|
-
that needs that check adds its own.
|
|
153
|
-
|
|
154
|
-
A **Legal Identity** (name and citizen ID) is not in userinfo. Call
|
|
155
|
-
`getLegalIdentity(env, token)` only at the moment it is needed, such as
|
|
156
|
-
checkout, and copy it onto that record, such as the receipt. Not on page
|
|
157
|
-
views, and nowhere else — do not log, cache, or store it aside from that
|
|
158
|
-
record. `idCardNumber` may be `null` for a member without a KYC record; send
|
|
159
|
-
them through `/kyc` (`kycStartUrl`) if the app needs the number.
|
|
160
|
-
|
|
161
|
-
Under delegation the Legal Identity is the actor's. If delegated use should
|
|
162
|
-
be blocked, check `effective.isDelegated`.
|
|
163
|
-
|
|
164
|
-
Legal Identity is the Private Platform Service `platform/legal-identity`, so
|
|
165
|
-
the app needs a Use Grant: with the Builder's agreement, file
|
|
166
|
-
`pple request use platform/legal-identity --reason "…"`. Calls flow at Beta
|
|
167
|
-
or Live. `getLegalIdentity` reasons:
|
|
168
|
-
`not_configured` (bindings missing), `invalid_app_key`, `not_granted`,
|
|
169
|
-
`needs_beta` (the grant is held and the app is still Draft), `not_verified`,
|
|
170
|
-
`user_token_invalid`, `upstream_unavailable`.
|
|
171
|
-
|
|
172
|
-
Locally, try `DEV_PERSONA=unverified`, `kyc-pending`, or
|
|
173
|
-
`kyc-verified-nonmember`. Member Personas are verified via membership and the
|
|
174
|
-
offline helper returns `idCardNumber: null`.
|
|
175
|
-
|
|
176
|
-
## Before you finish
|
|
177
|
-
|
|
178
|
-
Run these and make sure they pass:
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
npm run typecheck
|
|
182
|
-
npm test
|
|
183
|
-
npm run build
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
`npm test` runs the smoke tests inside the real Workers runtime. If you add a
|
|
187
|
-
capability, add a smoke test for it in `test/`.
|
|
@@ -1,118 +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. You only ever see a masked
|
|
114
|
-
citizen ID. Only a Live app takes real money. A system outside the platform
|
|
115
|
-
needs a stub app: the `pple-platform` Skill has the recipe (it is not part of
|
|
116
|
-
this template).
|
|
117
|
-
|
|
118
|
-
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
|
-
}
|