@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
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Badge,
|
|
3
|
-
Button,
|
|
4
|
-
Card,
|
|
5
|
-
CardContent,
|
|
6
|
-
CardDescription,
|
|
7
|
-
CardHeader,
|
|
8
|
-
CardTitle,
|
|
9
|
-
DropdownMenu,
|
|
10
|
-
DropdownMenuContent,
|
|
11
|
-
DropdownMenuItem,
|
|
12
|
-
DropdownMenuLabel,
|
|
13
|
-
DropdownMenuSeparator,
|
|
14
|
-
DropdownMenuTrigger,
|
|
15
|
-
Icon,
|
|
16
|
-
Input,
|
|
17
|
-
Navbar,
|
|
18
|
-
Spinner,
|
|
19
|
-
Tabs,
|
|
20
|
-
TabsContent,
|
|
21
|
-
TabsList,
|
|
22
|
-
TabsTrigger,
|
|
23
|
-
Textarea,
|
|
24
|
-
showToast,
|
|
25
|
-
} from "@pplethai/components";
|
|
26
|
-
import { ChevronDown, LogOut, Plus, Send, Upload, User } from "lucide-react";
|
|
27
|
-
import { useEffect, useRef, useState } from "react";
|
|
28
|
-
import type {
|
|
29
|
-
Me,
|
|
30
|
-
Note,
|
|
31
|
-
NotificationAudience,
|
|
32
|
-
NotificationDelivery,
|
|
33
|
-
NotificationRecipient,
|
|
34
|
-
UploadedFile,
|
|
35
|
-
} from "../shared/api";
|
|
36
|
-
import { MAX_DIRECT_RECIPIENTS } from "../shared/api";
|
|
37
|
-
import { api, apiJson, logout } from "./pple";
|
|
38
|
-
|
|
39
|
-
function bytes(n: number): string {
|
|
40
|
-
if (n < 1024) return `${n} B`;
|
|
41
|
-
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
42
|
-
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function message(e: unknown): string {
|
|
46
|
-
return e instanceof Error ? e.message : String(e);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Starter nav — replace with your routes. With a client router, pass
|
|
50
|
-
// renderHomeLink / renderLink (see pple-erp's Navbar wrapper).
|
|
51
|
-
const NAV_ITEMS = [{ href: "/", label: "หน้าหลัก", end: true }];
|
|
52
|
-
|
|
53
|
-
export function App() {
|
|
54
|
-
const [me, setMe] = useState<Me | null>(null);
|
|
55
|
-
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
apiJson<Me>("/api/me").then(setMe).catch((e) => showToast({
|
|
58
|
-
title: "โหลดโปรไฟล์ไม่สำเร็จ",
|
|
59
|
-
description: message(e),
|
|
60
|
-
variant: "error",
|
|
61
|
-
}));
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
const displayName = me?.actor.name ?? me?.actor.sub ?? "";
|
|
65
|
-
const roleLabels = me
|
|
66
|
-
? [me.effective.activeRole, ...me.effective.extraRoles]
|
|
67
|
-
: [];
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<>
|
|
71
|
-
<Navbar
|
|
72
|
-
title="PPLE App"
|
|
73
|
-
pathname={window.location.pathname}
|
|
74
|
-
items={NAV_ITEMS}
|
|
75
|
-
mobileMenuAriaLabel={{ open: "เปิดเมนู", close: "ปิดเมนู" }}
|
|
76
|
-
navAriaLabel="เมนูหลัก"
|
|
77
|
-
>
|
|
78
|
-
{me && (
|
|
79
|
-
<DropdownMenu>
|
|
80
|
-
<DropdownMenuTrigger asChild>
|
|
81
|
-
<Button variant="outline" size="default" className="gap-2">
|
|
82
|
-
<Icon icon={User} />
|
|
83
|
-
<span>{displayName}</span>
|
|
84
|
-
<Icon icon={ChevronDown} size="sm" />
|
|
85
|
-
</Button>
|
|
86
|
-
</DropdownMenuTrigger>
|
|
87
|
-
<DropdownMenuContent align="end" className="w-64">
|
|
88
|
-
<DropdownMenuLabel>
|
|
89
|
-
<div className="font-medium">{displayName}</div>
|
|
90
|
-
{me.actor.mobile && (
|
|
91
|
-
<div className="text-xs text-muted-foreground font-normal">
|
|
92
|
-
{me.actor.mobile}
|
|
93
|
-
</div>
|
|
94
|
-
)}
|
|
95
|
-
{me.effective.isDelegated && (
|
|
96
|
-
<div className="text-xs text-muted-foreground font-normal">
|
|
97
|
-
(ปฏิบัติงานแทน — สิทธิ์เป็นของหัวหน้า)
|
|
98
|
-
</div>
|
|
99
|
-
)}
|
|
100
|
-
</DropdownMenuLabel>
|
|
101
|
-
<DropdownMenuSeparator />
|
|
102
|
-
<DropdownMenuLabel className="text-xs text-muted-foreground font-normal">
|
|
103
|
-
บทบาทของคุณ
|
|
104
|
-
</DropdownMenuLabel>
|
|
105
|
-
{roleLabels.map((label) => (
|
|
106
|
-
<DropdownMenuItem key={label} disabled className="opacity-70">
|
|
107
|
-
{label}
|
|
108
|
-
</DropdownMenuItem>
|
|
109
|
-
))}
|
|
110
|
-
<DropdownMenuSeparator />
|
|
111
|
-
<DropdownMenuItem onClick={() => void logout()}>
|
|
112
|
-
<Icon icon={LogOut} />
|
|
113
|
-
ออกจากระบบ
|
|
114
|
-
</DropdownMenuItem>
|
|
115
|
-
</DropdownMenuContent>
|
|
116
|
-
</DropdownMenu>
|
|
117
|
-
)}
|
|
118
|
-
</Navbar>
|
|
119
|
-
|
|
120
|
-
<main className="screen">
|
|
121
|
-
<div className="stack">
|
|
122
|
-
<p className="muted">
|
|
123
|
-
นี่คือเทมเพลตเริ่มต้น แต่ละการ์ดด้านล่างแสดงความสามารถหนึ่งอย่างของ
|
|
124
|
-
แพลตฟอร์ม แทนที่ด้วยแอปของคุณเองได้เลย
|
|
125
|
-
</p>
|
|
126
|
-
<NotesCard />
|
|
127
|
-
<FilesCard />
|
|
128
|
-
<NotifyCard />
|
|
129
|
-
</div>
|
|
130
|
-
</main>
|
|
131
|
-
</>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// --- D1: a shared notes list ---------------------------------------------
|
|
136
|
-
function NotesCard() {
|
|
137
|
-
const [notes, setNotes] = useState<Note[] | null>(null);
|
|
138
|
-
const [body, setBody] = useState("");
|
|
139
|
-
const [saving, setSaving] = useState(false);
|
|
140
|
-
|
|
141
|
-
const load = () =>
|
|
142
|
-
apiJson<{ notes: Note[] }>("/api/notes")
|
|
143
|
-
.then((r) => setNotes(r.notes))
|
|
144
|
-
.catch((e) => {
|
|
145
|
-
showToast({ title: "โหลดบันทึกไม่สำเร็จ", description: message(e), variant: "error" });
|
|
146
|
-
// Land on the empty state. Leaving this null would spin forever.
|
|
147
|
-
setNotes([]);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
useEffect(() => void load(), []);
|
|
151
|
-
|
|
152
|
-
async function add() {
|
|
153
|
-
// `saving` guards the Enter key too — the button is disabled while a save
|
|
154
|
-
// is in flight, but a keypress doesn't go through the button.
|
|
155
|
-
if (saving || !body.trim()) return;
|
|
156
|
-
setSaving(true);
|
|
157
|
-
try {
|
|
158
|
-
await apiJson<Note>("/api/notes", {
|
|
159
|
-
method: "POST",
|
|
160
|
-
headers: { "content-type": "application/json" },
|
|
161
|
-
body: JSON.stringify({ body }),
|
|
162
|
-
});
|
|
163
|
-
setBody("");
|
|
164
|
-
await load();
|
|
165
|
-
} catch (e) {
|
|
166
|
-
showToast({ title: "บันทึกไม่สำเร็จ", description: message(e), variant: "error" });
|
|
167
|
-
} finally {
|
|
168
|
-
setSaving(false);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<Card className="card">
|
|
174
|
-
<CardHeader>
|
|
175
|
-
<CardTitle>บันทึก</CardTitle>
|
|
176
|
-
<CardDescription>อ่านและเขียนฐานข้อมูล D1 ของแอป</CardDescription>
|
|
177
|
-
</CardHeader>
|
|
178
|
-
<CardContent>
|
|
179
|
-
<div className="stack">
|
|
180
|
-
<div className="row">
|
|
181
|
-
<Input
|
|
182
|
-
value={body}
|
|
183
|
-
placeholder="เขียนบันทึก…"
|
|
184
|
-
onChange={(e) => setBody(e.target.value)}
|
|
185
|
-
onKeyDown={(e) => e.key === "Enter" && add()}
|
|
186
|
-
/>
|
|
187
|
-
<Button onClick={add} disabled={saving || !body.trim()}>
|
|
188
|
-
{saving ? <Spinner /> : <Icon icon={Plus} />}
|
|
189
|
-
เพิ่ม
|
|
190
|
-
</Button>
|
|
191
|
-
</div>
|
|
192
|
-
{notes === null ? (
|
|
193
|
-
<Spinner />
|
|
194
|
-
) : notes.length === 0 ? (
|
|
195
|
-
<p className="muted">ยังไม่มีบันทึก</p>
|
|
196
|
-
) : (
|
|
197
|
-
<ul className="list">
|
|
198
|
-
{notes.map((n) => (
|
|
199
|
-
<li key={n.id} className="list__item">
|
|
200
|
-
<span>{n.body}</span>
|
|
201
|
-
<span className="muted">
|
|
202
|
-
{new Date(n.createdAt).toLocaleString("th-TH")}
|
|
203
|
-
</span>
|
|
204
|
-
</li>
|
|
205
|
-
))}
|
|
206
|
-
</ul>
|
|
207
|
-
)}
|
|
208
|
-
</div>
|
|
209
|
-
</CardContent>
|
|
210
|
-
</Card>
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// --- R2: file upload ------------------------------------------------------
|
|
215
|
-
function FilesCard() {
|
|
216
|
-
const [files, setFiles] = useState<UploadedFile[] | null>(null);
|
|
217
|
-
const [uploading, setUploading] = useState(false);
|
|
218
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
219
|
-
|
|
220
|
-
const load = () =>
|
|
221
|
-
apiJson<{ files: UploadedFile[] }>("/api/files")
|
|
222
|
-
.then((r) => setFiles(r.files))
|
|
223
|
-
.catch((e) => {
|
|
224
|
-
showToast({ title: "โหลดไฟล์ไม่สำเร็จ", description: message(e), variant: "error" });
|
|
225
|
-
// Land on the empty state. Leaving this null would spin forever.
|
|
226
|
-
setFiles([]);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
useEffect(() => void load(), []);
|
|
230
|
-
|
|
231
|
-
async function upload() {
|
|
232
|
-
const file = inputRef.current?.files?.[0];
|
|
233
|
-
if (!file) return;
|
|
234
|
-
setUploading(true);
|
|
235
|
-
try {
|
|
236
|
-
const fd = new FormData();
|
|
237
|
-
fd.append("file", file);
|
|
238
|
-
const res = await api("/api/files", { method: "POST", body: fd });
|
|
239
|
-
if (!res.ok) throw new Error(`อัปโหลดไม่สำเร็จ (${res.status})`);
|
|
240
|
-
if (inputRef.current) inputRef.current.value = "";
|
|
241
|
-
await load();
|
|
242
|
-
} catch (e) {
|
|
243
|
-
showToast({ title: "อัปโหลดไฟล์ไม่สำเร็จ", description: message(e), variant: "error" });
|
|
244
|
-
} finally {
|
|
245
|
-
setUploading(false);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return (
|
|
250
|
-
<Card className="card">
|
|
251
|
-
<CardHeader>
|
|
252
|
-
<CardTitle>ไฟล์</CardTitle>
|
|
253
|
-
<CardDescription>อัปโหลดไปยังบัคเก็ต R2 ของแอป</CardDescription>
|
|
254
|
-
</CardHeader>
|
|
255
|
-
<CardContent>
|
|
256
|
-
<div className="stack">
|
|
257
|
-
<div className="row">
|
|
258
|
-
{/* Hidden native picker; the design-system Button opens it. Disabled
|
|
259
|
-
while uploading so a second pick can't start a concurrent upload. */}
|
|
260
|
-
<input
|
|
261
|
-
ref={inputRef}
|
|
262
|
-
type="file"
|
|
263
|
-
className="hidden"
|
|
264
|
-
onChange={upload}
|
|
265
|
-
disabled={uploading}
|
|
266
|
-
/>
|
|
267
|
-
<Button
|
|
268
|
-
variant="outline"
|
|
269
|
-
disabled={uploading}
|
|
270
|
-
onClick={() => inputRef.current?.click()}
|
|
271
|
-
>
|
|
272
|
-
{uploading ? <Spinner /> : <Icon icon={Upload} />}
|
|
273
|
-
เลือกไฟล์
|
|
274
|
-
</Button>
|
|
275
|
-
</div>
|
|
276
|
-
{files === null ? (
|
|
277
|
-
<Spinner />
|
|
278
|
-
) : files.length === 0 ? (
|
|
279
|
-
<p className="muted">ยังไม่มีไฟล์</p>
|
|
280
|
-
) : (
|
|
281
|
-
<ul className="list">
|
|
282
|
-
{files.map((f) => (
|
|
283
|
-
<li key={f.key} className="list__item">
|
|
284
|
-
<span>{f.name}</span>
|
|
285
|
-
<span className="muted">{bytes(f.size)}</span>
|
|
286
|
-
</li>
|
|
287
|
-
))}
|
|
288
|
-
</ul>
|
|
289
|
-
)}
|
|
290
|
-
</div>
|
|
291
|
-
</CardContent>
|
|
292
|
-
</Card>
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// --- Notifications: Broadcast and Direct ----------------------------------
|
|
297
|
-
//
|
|
298
|
-
// Two modes, one card. The audience is always stated — there is no way to
|
|
299
|
-
// start a send from this UI without choosing one, which mirrors the schema in
|
|
300
|
-
// shared/api.ts, where leaving it out is a compile error.
|
|
301
|
-
|
|
302
|
-
/** Builder-facing Thai for every refusal this card can receive. */
|
|
303
|
-
const NOTIFY_ERRORS: Record<string, string> = {
|
|
304
|
-
// This app's own Zod check (src/index.ts), before anything is sent.
|
|
305
|
-
invalid_body: `ข้อมูลไม่ครบหรือไม่ถูกต้อง — ต้องมีหัวข้อ ข้อความ และกลุ่มผู้รับ ไม่เกิน ${MAX_DIRECT_RECIPIENTS} คน`,
|
|
306
|
-
invalid_request: "คำขอไม่ถูกต้อง — ตรวจสอบว่าระบุกลุ่มผู้รับแล้ว",
|
|
307
|
-
invalid_recipients: `รายชื่อผู้รับไม่ถูกต้อง — ต้องมีอย่างน้อยหนึ่งคน ไม่เกิน ${MAX_DIRECT_RECIPIENTS} คน และหนึ่งบรรทัดระบุได้อย่างเดียวระหว่าง sub กับเบอร์โทรศัพท์`,
|
|
308
|
-
idempotency_key_conflict: "คีย์กันส่งซ้ำถูกใช้กับรายชื่อจำนวนอื่นไปแล้ว",
|
|
309
|
-
quota_exceeded: "โควตาการแจ้งเตือนหมด — ยังไม่มีใครได้รับข้อความนี้ ลองใหม่หลังโควตารีเซ็ต",
|
|
310
|
-
not_permitted: "คีย์การแจ้งเตือนนี้ไม่มีสิทธิ์ส่งผ่านช่องทางนี้",
|
|
311
|
-
send_failed: "ส่งไม่สำเร็จ",
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* One entry per line (commas work too). An entry that is all digits — with or
|
|
316
|
-
* without a leading `+` — is sent as a mobile number; anything else as a PPLE
|
|
317
|
-
* ID `sub`. Never both in one entry: the platform refuses those.
|
|
318
|
-
*/
|
|
319
|
-
function parseRecipients(text: string): NotificationRecipient[] {
|
|
320
|
-
return text
|
|
321
|
-
.split(/[\n,]/)
|
|
322
|
-
.map((entry) => entry.trim())
|
|
323
|
-
.filter(Boolean)
|
|
324
|
-
.map((entry) =>
|
|
325
|
-
/^\+?[\d\s-]+$/.test(entry)
|
|
326
|
-
? { phone: entry.replace(/[\s-]/g, "") }
|
|
327
|
-
: { sub: entry },
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function recipientLabel(r: NotificationRecipient): string {
|
|
332
|
-
return "sub" in r ? r.sub : r.phone;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function NotifyCard() {
|
|
336
|
-
const [kind, setKind] = useState<NotificationAudience["kind"]>("all");
|
|
337
|
-
const [recipientsText, setRecipientsText] = useState("");
|
|
338
|
-
const [title, setTitle] = useState("");
|
|
339
|
-
const [body, setBody] = useState("");
|
|
340
|
-
const [sending, setSending] = useState(false);
|
|
341
|
-
const [results, setResults] = useState<NotificationDelivery[] | null>(null);
|
|
342
|
-
|
|
343
|
-
const recipients = parseRecipients(recipientsText);
|
|
344
|
-
// The cap is the platform's, and going over it is a refusal rather than a
|
|
345
|
-
// truncation — so hold the send here and say so, rather than letting a
|
|
346
|
-
// Builder discover it from an error toast.
|
|
347
|
-
const tooMany = recipients.length > MAX_DIRECT_RECIPIENTS;
|
|
348
|
-
const ready =
|
|
349
|
-
!!title.trim() &&
|
|
350
|
-
!!body.trim() &&
|
|
351
|
-
(kind === "all" || (recipients.length > 0 && !tooMany));
|
|
352
|
-
|
|
353
|
-
async function send() {
|
|
354
|
-
if (!ready) return;
|
|
355
|
-
setSending(true);
|
|
356
|
-
setResults(null);
|
|
357
|
-
try {
|
|
358
|
-
// The audience travels with the send, always. Choosing it is the first
|
|
359
|
-
// thing this form does, not an afterthought a dropped field can undo.
|
|
360
|
-
const audience: NotificationAudience =
|
|
361
|
-
kind === "all" ? { kind: "all" } : { kind: "direct", recipients };
|
|
362
|
-
const res = await api("/api/notify", {
|
|
363
|
-
method: "POST",
|
|
364
|
-
headers: { "content-type": "application/json" },
|
|
365
|
-
body: JSON.stringify({ audience, title, body }),
|
|
366
|
-
});
|
|
367
|
-
const data = (await res.json().catch(() => ({}))) as {
|
|
368
|
-
error?: string;
|
|
369
|
-
results?: NotificationDelivery[];
|
|
370
|
-
};
|
|
371
|
-
if (res.ok) {
|
|
372
|
-
showToast({ title: "ส่งการแจ้งเตือนแล้ว", variant: "success" });
|
|
373
|
-
setResults(data.results ?? null);
|
|
374
|
-
setTitle("");
|
|
375
|
-
setBody("");
|
|
376
|
-
} else if (data.error === "notifications_not_configured") {
|
|
377
|
-
showToast({
|
|
378
|
-
title: "ยังไม่ได้ตั้งค่าการแจ้งเตือน",
|
|
379
|
-
description: "ตั้งค่า NOTIFY_API_BASE และ NOTIFY_API_KEY เพื่อส่งจริง",
|
|
380
|
-
variant: "warning",
|
|
381
|
-
});
|
|
382
|
-
} else {
|
|
383
|
-
showToast({
|
|
384
|
-
title: "ส่งไม่สำเร็จ",
|
|
385
|
-
description: NOTIFY_ERRORS[data.error ?? ""] ?? data.error,
|
|
386
|
-
variant: "error",
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
} catch (e) {
|
|
390
|
-
showToast({ title: "ส่งไม่สำเร็จ", description: message(e), variant: "error" });
|
|
391
|
-
} finally {
|
|
392
|
-
setSending(false);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
return (
|
|
397
|
-
<Card className="card">
|
|
398
|
-
<CardHeader>
|
|
399
|
-
<CardTitle>แจ้งเตือนผู้ใช้</CardTitle>
|
|
400
|
-
<CardDescription>
|
|
401
|
-
ส่งถึงผู้ใช้ของแอปนี้ — ทุกคน หรือระบุรายบุคคลด้วย PPLE ID (sub)
|
|
402
|
-
หรือเบอร์โทรศัพท์ การระบุชื่อเป็นการ<em>จำกัด</em>ผู้รับให้แคบลงเท่านั้น
|
|
403
|
-
ไม่เคยขยายออก คนที่ยังไม่เคยเปิดแอปนี้จะไม่ได้รับ
|
|
404
|
-
</CardDescription>
|
|
405
|
-
</CardHeader>
|
|
406
|
-
<CardContent>
|
|
407
|
-
<div className="stack">
|
|
408
|
-
<Tabs
|
|
409
|
-
value={kind}
|
|
410
|
-
onValueChange={(v) => {
|
|
411
|
-
setKind(v as NotificationAudience["kind"]);
|
|
412
|
-
setResults(null);
|
|
413
|
-
}}
|
|
414
|
-
>
|
|
415
|
-
<TabsList>
|
|
416
|
-
<TabsTrigger value="all">การแจ้งเตือนทุกคน</TabsTrigger>
|
|
417
|
-
<TabsTrigger value="direct">การแจ้งเตือนรายบุคคล</TabsTrigger>
|
|
418
|
-
</TabsList>
|
|
419
|
-
<TabsContent value="all">
|
|
420
|
-
<p className="muted">
|
|
421
|
-
ส่งถึงผู้ใช้แอปนี้ทุกคน — นับโควตาตามจำนวนผู้รับทั้งหมด
|
|
422
|
-
</p>
|
|
423
|
-
</TabsContent>
|
|
424
|
-
<TabsContent value="direct">
|
|
425
|
-
<div className="stack">
|
|
426
|
-
<Textarea
|
|
427
|
-
value={recipientsText}
|
|
428
|
-
placeholder={"บรรทัดละหนึ่งคน\n0812345678\nu-42"}
|
|
429
|
-
onChange={(e) => setRecipientsText(e.target.value)}
|
|
430
|
-
/>
|
|
431
|
-
<p className="muted">
|
|
432
|
-
ระบุได้สูงสุด {MAX_DIRECT_RECIPIENTS} คนต่อครั้ง (ตอนนี้{" "}
|
|
433
|
-
{recipients.length} คน{tooMany ? " — เกินจำนวน ต้องแบ่งส่งเป็นรอบ" : ""})
|
|
434
|
-
— ทุกชื่อที่ระบุถูกนับโควตา แม้จะส่งไม่ถึง
|
|
435
|
-
จึงควรตัดรายชื่อที่ส่งไม่ถึงออก
|
|
436
|
-
</p>
|
|
437
|
-
</div>
|
|
438
|
-
</TabsContent>
|
|
439
|
-
</Tabs>
|
|
440
|
-
<Input
|
|
441
|
-
value={title}
|
|
442
|
-
placeholder="หัวข้อ"
|
|
443
|
-
onChange={(e) => setTitle(e.target.value)}
|
|
444
|
-
/>
|
|
445
|
-
<Textarea
|
|
446
|
-
value={body}
|
|
447
|
-
placeholder="ข้อความ"
|
|
448
|
-
onChange={(e) => setBody(e.target.value)}
|
|
449
|
-
/>
|
|
450
|
-
<Button onClick={send} disabled={sending || !ready}>
|
|
451
|
-
{sending ? <Spinner /> : <Icon icon={Send} />}
|
|
452
|
-
ส่งการแจ้งเตือน
|
|
453
|
-
</Button>
|
|
454
|
-
{results && (
|
|
455
|
-
<div className="stack">
|
|
456
|
-
<ul className="list">
|
|
457
|
-
{results.map((r, i) => (
|
|
458
|
-
<li key={`${recipientLabel(r.recipient)}-${i}`} className="list__item">
|
|
459
|
-
<span>{recipientLabel(r.recipient)}</span>
|
|
460
|
-
<Badge variant={r.status === "delivered" ? "default" : "outline"}>
|
|
461
|
-
{r.status === "delivered" ? "ส่งแล้ว" : "ส่งไม่ถึง"}
|
|
462
|
-
</Badge>
|
|
463
|
-
</li>
|
|
464
|
-
))}
|
|
465
|
-
</ul>
|
|
466
|
-
{/* One collapsed reason, on purpose: the app is never told which
|
|
467
|
-
of these applies (docs/adr/0017). Do not guess in the UI. */}
|
|
468
|
-
<p className="muted">
|
|
469
|
-
“ส่งไม่ถึง” หมายถึงยังไม่เคยเปิดแอปนี้ อยู่นอกกลุ่มผู้รับ
|
|
470
|
-
ไม่มีบัญชี PPLE ID หรือปิดรับการแจ้งเตือน — ระบบไม่ระบุว่าเป็นข้อใด
|
|
471
|
-
</p>
|
|
472
|
-
</div>
|
|
473
|
-
)}
|
|
474
|
-
</div>
|
|
475
|
-
</CardContent>
|
|
476
|
-
</Card>
|
|
477
|
-
);
|
|
478
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/* App layout. The design system (@pplethai/components) styles the components;
|
|
2
|
-
this file only handles page layout, and stays mobile-first: one column,
|
|
3
|
-
comfortable tap targets, safe-area padding for the PPLE Today WebView. */
|
|
4
|
-
|
|
5
|
-
* {
|
|
6
|
-
box-sizing: border-box;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
body {
|
|
10
|
-
margin: 0;
|
|
11
|
-
font-family: "IBM Plex Sans Thai Looped", system-ui, -apple-system, sans-serif;
|
|
12
|
-
background: #f5f5f5;
|
|
13
|
-
color: #212121;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.screen {
|
|
17
|
-
max-width: 640px;
|
|
18
|
-
margin: 0 auto;
|
|
19
|
-
padding: 16px;
|
|
20
|
-
/* Navbar is position:fixed below the md breakpoint; give content room. */
|
|
21
|
-
padding-top: 4.5rem;
|
|
22
|
-
padding-bottom: max(16px, env(safe-area-inset-bottom));
|
|
23
|
-
min-height: 100vh;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@media (min-width: 768px) {
|
|
27
|
-
.screen {
|
|
28
|
-
padding-top: 16px;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.screen--center {
|
|
33
|
-
display: grid;
|
|
34
|
-
place-items: center;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.stack {
|
|
38
|
-
display: flex;
|
|
39
|
-
flex-direction: column;
|
|
40
|
-
gap: 16px;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.row {
|
|
44
|
-
display: flex;
|
|
45
|
-
gap: 8px;
|
|
46
|
-
align-items: center;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.row > :first-child {
|
|
50
|
-
flex: 1;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.card {
|
|
54
|
-
width: 100%;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.list {
|
|
58
|
-
list-style: none;
|
|
59
|
-
margin: 0;
|
|
60
|
-
padding: 0;
|
|
61
|
-
display: flex;
|
|
62
|
-
flex-direction: column;
|
|
63
|
-
gap: 8px;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.list__item {
|
|
67
|
-
display: flex;
|
|
68
|
-
justify-content: space-between;
|
|
69
|
-
gap: 12px;
|
|
70
|
-
align-items: baseline;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.muted {
|
|
74
|
-
color: #6b6b6b;
|
|
75
|
-
font-size: 14px;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/* Icon defaults to text-foreground, which overrides the parent Button text
|
|
79
|
-
colour (primary-foreground on filled buttons, …). Inherit so the glyph
|
|
80
|
-
matches its label — including hover states on outline/ghost buttons. */
|
|
81
|
-
button svg.text-foreground {
|
|
82
|
-
color: inherit;
|
|
83
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// App entry point. Import the design-system styles first, then our own.
|
|
2
|
-
import "@pplethai/components/styles.css";
|
|
3
|
-
|
|
4
|
-
// The body font, re-declared from @fontsource so it actually loads:
|
|
5
|
-
// @pplethai/components inlines Fontsource's @font-face rules but ships no
|
|
6
|
-
// dist/files/*.woff2, so every `url(files/…)` 404s and the body font silently
|
|
7
|
-
// falls back to system-ui. Anakotmai, the heading face, loads from an absolute
|
|
8
|
-
// URL and is unaffected. Importing the same weights gives Vite real files to
|
|
9
|
-
// bundle; identical @font-face rules declared later win the cascade. These are
|
|
10
|
-
// the all-subset entrypoints, not `thai-400.css` — only those carry
|
|
11
|
-
// `unicode-range`, without which one rule would win for every character and
|
|
12
|
-
// Thai text would match the Latin file, which has no Thai glyphs.
|
|
13
|
-
// Remove once the upstream package ships its font files: PPLEThai/pple-design-system#16.
|
|
14
|
-
import "@fontsource/ibm-plex-sans-thai-looped/400.css";
|
|
15
|
-
import "@fontsource/ibm-plex-sans-thai-looped/600.css";
|
|
16
|
-
|
|
17
|
-
import "./app.css";
|
|
18
|
-
|
|
19
|
-
import { Alert, AlertDescription, AlertTitle, Toaster } from "@pplethai/components";
|
|
20
|
-
import { StrictMode } from "react";
|
|
21
|
-
import { createRoot } from "react-dom/client";
|
|
22
|
-
import { App } from "./App";
|
|
23
|
-
import { bootstrap } from "./pple";
|
|
24
|
-
|
|
25
|
-
function ErrorScreen({ message }: { message: string }) {
|
|
26
|
-
return (
|
|
27
|
-
<main className="screen screen--center">
|
|
28
|
-
<Alert variant="destructive" className="card">
|
|
29
|
-
<AlertTitle>เริ่มต้นแอปไม่สำเร็จ</AlertTitle>
|
|
30
|
-
<AlertDescription>{message}</AlertDescription>
|
|
31
|
-
</Alert>
|
|
32
|
-
</main>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const root = createRoot(document.getElementById("root")!);
|
|
37
|
-
|
|
38
|
-
// Establish the session (PPLE Today token, browser PPLE ID login, or a local
|
|
39
|
-
// dev persona) before rendering, so the first paint is the right screen.
|
|
40
|
-
bootstrap().then((result) => {
|
|
41
|
-
root.render(
|
|
42
|
-
<StrictMode>
|
|
43
|
-
<Toaster />
|
|
44
|
-
{result.kind === "signed-in" ? (
|
|
45
|
-
<App />
|
|
46
|
-
) : (
|
|
47
|
-
<ErrorScreen message={result.message} />
|
|
48
|
-
)}
|
|
49
|
-
</StrictMode>,
|
|
50
|
-
);
|
|
51
|
-
});
|