@pplethai/cli 0.16.0 → 0.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pplethai/cli",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,6 +18,7 @@
18
18
  "scripts": {
19
19
  "build": "npm run build:template && node scripts/bundle.mjs",
20
20
  "build:template": "node scripts/bundle-template.mjs",
21
+ "verify:template": "node scripts/verify-template.mjs",
21
22
  "typecheck": "tsc --noEmit",
22
23
  "test": "vitest run",
23
24
  "test:watch": "vitest"
@@ -114,7 +114,8 @@ Where the token comes from:
114
114
  `event.responder.sub` only. Try the question with `pple notify test` (it
115
115
  reaches only you; its answers reach no handler). Full guide: the
116
116
  `pple-platform` Skill, mini-app reference.
117
- - **Payments**: take a donation or membership fee through the Private Platform
117
+ - **Payments**: take a donation, a sale (`items`), a fundraising (`event`) or a
118
+ membership fee (`term`) through the Private Platform
118
119
  Service `platform/payments` (Use Grant needed; Beta or Live). `src/payment.ts`
119
120
  has `createPayment` (send the Payer to its `checkoutUrl`; never build a card
120
121
  form), `getPayment`, `issueReceipt`, `rejectPayment`, `verifyPaymentEvent`
@@ -65,9 +65,40 @@
65
65
  import { callService, platformError, type CallServiceEnv, type PlatformErrorCode } from "./call-service";
66
66
  import type { Env } from "./env";
67
67
 
68
- /** What you send to create a Payment. Every field is required. */
69
- export interface CreatePaymentInput {
70
- kind: "donation" | "membership_fee";
68
+ /**
69
+ * What the money is for. The party's legal document follows the kind:
70
+ *
71
+ * - `donation`: a donation (record of donation แบบ พ.ก.10, receipt แบบ พ.ก.11)
72
+ * - `sale`: goods or services sold (receipt แบบ พ.ก.9/1, line by line)
73
+ * - `fundraising`: a fundraising event, such as a run ticket (receipt แบบ พ.ก.9)
74
+ * - `membership_fee`: a party membership fee, annual or lifetime (receipt แบบ พ.ก.9)
75
+ */
76
+ export type PaymentKind = "donation" | "sale" | "fundraising" | "membership_fee";
77
+
78
+ /** One line of a sale: goods or a service. */
79
+ export interface SaleItem {
80
+ type: "goods" | "service";
81
+ /** What it is, as the receipt prints it, e.g. `เสื้อยืดพรรค ไซซ์ M สีส้ม`. 1 to 120 characters. */
82
+ name: string;
83
+ /** A whole number, 1 or more. */
84
+ quantity: number;
85
+ /** What the quantity counts, e.g. `ชิ้น`. Up to 20 characters. Leave it out to print none. */
86
+ unit?: string | null;
87
+ /** The price of one, in satang. 0 or more. */
88
+ unitPriceSatang: number;
89
+ }
90
+
91
+ /** A fundraising event, as the receipt prints it. */
92
+ export interface FundraisingEvent {
93
+ /** 1 to 200 characters. */
94
+ name: string;
95
+ /** The event's day, `YYYY-MM-DD` (the receipt prints it in the Buddhist Era). */
96
+ date: string;
97
+ }
98
+
99
+ export type MembershipTerm = "annual" | "lifetime";
100
+
101
+ interface PaymentInputBase {
71
102
  /** 100 satang is 1 baht. A positive integer. */
72
103
  amountSatang: number;
73
104
  /** What the Payer sees on the Checkout Page. 1 to 200 characters. */
@@ -78,6 +109,30 @@ export interface CreatePaymentInput {
78
109
  returnUrl: string;
79
110
  }
80
111
 
112
+ /**
113
+ * What you send to create a Payment. Every field is required, and each kind
114
+ * carries what its receipt prints: a sale its 1 to 12 lines (which must add up to
115
+ * `amountSatang` exactly), a fundraising its event, a membership its term. A
116
+ * field of another kind is refused (`invalid_payment` naming it).
117
+ */
118
+ export type CreatePaymentInput =
119
+ | (PaymentInputBase & { kind: "donation" })
120
+ | (PaymentInputBase & { kind: "sale"; items: SaleItem[] })
121
+ | (PaymentInputBase & { kind: "fundraising"; event: FundraisingEvent })
122
+ | (PaymentInputBase & { kind: "membership_fee"; term: MembershipTerm });
123
+
124
+ /**
125
+ * What a Payment carries for its kind, as the platform answers it: `items` on
126
+ * a sale (each with `unit` null when none was sent), `event` on a fundraising,
127
+ * `term` on a membership. `event` and `term` are null only on a Payment made
128
+ * before kinds carried them.
129
+ */
130
+ export interface PaymentKindDetails {
131
+ items?: (SaleItem & { unit: string | null })[];
132
+ event?: FundraisingEvent | null;
133
+ term?: MembershipTerm | null;
134
+ }
135
+
81
136
  /** Why a call to `platform/payments` did not give you what you asked for. */
82
137
  export type PaymentReason =
83
138
  | "not_configured"
@@ -108,9 +163,9 @@ export interface PaymentReceipt {
108
163
  }
109
164
 
110
165
  /** The Payment as the platform answers a lookup. */
111
- export interface PaymentRecord {
166
+ export interface PaymentRecord extends PaymentKindDetails {
112
167
  id: string;
113
- kind: "donation" | "membership_fee";
168
+ kind: PaymentKind;
114
169
  amountSatang: number;
115
170
  description: string;
116
171
  reference: string;
@@ -318,9 +373,9 @@ export interface PaymentPaidEvent {
318
373
  type: "payment.paid";
319
374
  /** The same on every delivery of this outcome. */
320
375
  id: string;
321
- payment: {
376
+ payment: PaymentKindDetails & {
322
377
  id: string;
323
- kind: "donation" | "membership_fee";
378
+ kind: PaymentKind;
324
379
  /** 100 satang is 1 baht. */
325
380
  amountSatang: number;
326
381
  description: string;
@@ -1,17 +1,20 @@
1
- // Offline email (#435). The registry's own mocks for `platform/email`
2
- // (registry/email/mocks/responses.json) are the answers `npm run dev` gives. This
3
- // drives the real files through the same matcher a Builder's `callService` uses
1
+ // Offline email (#435). The mocks for `platform/email` (a copy of
2
+ // registry/email/mocks/responses.json) are the answers `npm run dev` gives. This
3
+ // drives those files through the same matcher a Builder's `callService` uses
4
4
  // offline, so a fresh app can send an email against them with nothing deployed.
5
5
 
6
6
  import { describe, expect, it } from "vitest";
7
7
  import { answerFromOverlay } from "../src/dev-call-service";
8
8
  import { callService } from "../src/call-service";
9
9
 
10
- // The registry's files, laid out as `pple registry` writes them into `.pple/registry/`.
10
+ // The mocks as a fresh app has them (test/fixtures/overlay/platform/email),
11
+ // laid out as `pple registry` writes them into `.pple/registry/`. They are a
12
+ // copy of the registry's own, which a Builder's app does not carry; the repo
13
+ // keeps the copy equal to the original (recipes/registry-fixtures.test.ts).
11
14
  const files: Record<string, unknown> = Object.fromEntries(
12
- Object.entries(import.meta.glob("../../registry/email/**/*", { eager: true, query: "?raw", import: "default" })).map(
13
- ([file, text]) => [file.replace("../../registry/email/", "overlay/platform/email/"), text],
14
- ),
15
+ Object.entries(
16
+ import.meta.glob("./fixtures/overlay/platform/email/**/*", { eager: true, query: "?raw", import: "default" }),
17
+ ).map(([file, text]) => [file.replace("./fixtures/", ""), text]),
15
18
  );
16
19
 
17
20
  const offline: typeof fetch = async (input, init) => {
@@ -0,0 +1,12 @@
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`).
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "method": "POST",
4
+ "path": "/",
5
+ "status": 200,
6
+ "body": {
7
+ "sent": [{ "to": "somying@example.com", "messageId": "offline-mock" }],
8
+ "rejected": []
9
+ }
10
+ }
11
+ ]
@@ -0,0 +1,12 @@
1
+ ---
2
+ kind: service
3
+ visibility: private
4
+ userToken: none
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`).
@@ -0,0 +1,62 @@
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": "GET",
14
+ "path": "/pay_offline-mock",
15
+ "status": 200,
16
+ "body": {
17
+ "id": "pay_offline-mock",
18
+ "kind": "donation",
19
+ "amountSatang": 50000,
20
+ "description": "รายการทดสอบ",
21
+ "reference": "offline-mock",
22
+ "state": "paid",
23
+ "mode": "test",
24
+ "payer": { "name": "บุคคลทดสอบ หนึ่ง", "maskedCitizenId": "x-xxxx-xxxxx-xx-0" },
25
+ "voucher": { "number": "TEST-PV-000001", "nameTh": "หลักฐานการรับชำระเงิน (ไม่ใช่ใบเสร็จรับเงิน)", "isReceipt": false },
26
+ "receipt": null,
27
+ "paidAt": "2026-01-01T00:00:00.000Z",
28
+ "refusal": null,
29
+ "undecided": false,
30
+ "refund": null
31
+ }
32
+ },
33
+ {
34
+ "method": "POST",
35
+ "path": "/pay_offline-mock/receipt",
36
+ "status": 201,
37
+ "body": {
38
+ "receipt": { "id": "rcp_offline-mock", "number": "TEST-2569-000001", "isTest": true, "issuedAt": "2026-01-01T00:00:00.000Z", "replaces": null }
39
+ }
40
+ },
41
+ {
42
+ "method": "POST",
43
+ "path": "/pay_offline-mock/reject",
44
+ "status": 200,
45
+ "body": {
46
+ "id": "pay_offline-mock",
47
+ "kind": "donation",
48
+ "amountSatang": 50000,
49
+ "description": "รายการทดสอบ",
50
+ "reference": "offline-mock",
51
+ "state": "refunded",
52
+ "mode": "test",
53
+ "payer": { "name": "บุคคลทดสอบ หนึ่ง", "maskedCitizenId": "x-xxxx-xxxxx-xx-0" },
54
+ "voucher": { "number": "TEST-PV-000001", "nameTh": "หลักฐานการรับชำระเงิน (ไม่ใช่ใบเสร็จรับเงิน)", "isReceipt": false },
55
+ "receipt": null,
56
+ "paidAt": "2026-01-01T00:00:00.000Z",
57
+ "refusal": null,
58
+ "undecided": false,
59
+ "refund": { "status": "refunded" }
60
+ }
61
+ }
62
+ ]
@@ -1,16 +1,18 @@
1
- // The registry's own `platform/payments` mocks, served the way `npm run dev`
2
- // serves them (ADR-0026): through the offline matcher, as a Persona. Tests use
3
- // it as the fake Platform Service, so a test runs the answers a Builder sees
4
- // offline, not a hand-written copy of them.
1
+ // The `platform/payments` mocks, served the way `npm run dev` serves them
2
+ // (ADR-0026): through the offline matcher, as a Persona. Tests use it as the
3
+ // fake Platform Service, so a test runs the answers a Builder sees offline, not
4
+ // a hand-written copy of them.
5
5
 
6
6
  import { answerFromOverlay } from "../src/dev-call-service";
7
7
 
8
- // The registry's files, laid out as `pple registry` writes them into
9
- // `.pple/registry/`: the platform's entries sit under `platform/`.
8
+ // The mocks as a fresh app has them (test/fixtures/overlay/platform/payments),
9
+ // laid out as `pple registry` writes them into `.pple/registry/`. They are a
10
+ // copy of the registry's own, which a Builder's app does not carry; the repo
11
+ // keeps the copy equal to the original (recipes/registry-fixtures.test.ts).
10
12
  const files: Record<string, unknown> = Object.fromEntries(
11
13
  Object.entries(
12
- import.meta.glob("../../registry/payments/**/*", { eager: true, query: "?raw", import: "default" }),
13
- ).map(([file, text]) => [file.replace("../../registry/payments/", "overlay/platform/payments/"), text]),
14
+ import.meta.glob("./fixtures/overlay/platform/payments/**/*", { eager: true, query: "?raw", import: "default" }),
15
+ ).map(([file, text]) => [file.replace("./fixtures/", ""), text]),
14
16
  );
15
17
 
16
18
  /** Handles `{PPLE_SERVICES_URL}/platform/payments/…` as the mocks would for `persona`. */