@pplethai/cli 0.16.1 → 0.18.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.1",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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`
@@ -1,4 +1,6 @@
1
- // The deployed Worker is dist/pple_app/index.js. Vite inlines
1
+ // The deployed Worker is dist/<worker name>/index.js (the name in
2
+ // wrangler.jsonc, which `pple init` sets to the app's slug), found the way the
3
+ // deploy workflow finds it. Vite inlines
2
4
  // `import.meta.env.DEV` to false and drops the Persona bypass and the
3
5
  // offline registry wrapper (ADR-0011). Strings that exist only in those
4
6
  // modules must not survive. The client bundle is a different compile.
@@ -7,13 +9,14 @@ import fs from "node:fs";
7
9
  import path from "node:path";
8
10
  import { fileURLToPath } from "node:url";
9
11
 
10
- const bundle = path.resolve(
11
- path.dirname(fileURLToPath(import.meta.url)),
12
- "../dist/pple_app/index.js",
13
- );
12
+ const dist = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../dist");
13
+ const bundle = (fs.existsSync(dist) ? fs.readdirSync(dist) : [])
14
+ .filter((dir) => dir !== "client")
15
+ .map((dir) => path.join(dist, dir, "index.js"))
16
+ .find((file) => fs.existsSync(file));
14
17
 
15
- if (!fs.existsSync(bundle)) {
16
- console.error(`production Worker bundle not found at ${bundle}`);
18
+ if (!bundle) {
19
+ console.error(`production Worker bundle not found at ${dist}/*/index.js`);
17
20
  process.exit(1);
18
21
  }
19
22
 
@@ -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;