create-marcapony-app 0.1.0 → 0.2.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 (35) hide show
  1. package/README.md +29 -27
  2. package/dist/index.d.ts +37 -3
  3. package/dist/index.js +138 -23
  4. package/package.json +5 -4
  5. package/template/base/.dev.vars.example +7 -0
  6. package/template/{_package.json → base/_package.json} +14 -10
  7. package/template/{marcapony.json → base/marcapony.json} +1 -1
  8. package/template/{scripts → base/scripts}/dev.ts +19 -2
  9. package/template/base/src/server/marcapony.ts +85 -0
  10. package/template/base/src/ui/api.ts +34 -0
  11. package/template/base/src/ui/styles.css +115 -0
  12. package/template/blank/README.md +48 -0
  13. package/template/{src → blank/src}/server/index.ts +9 -7
  14. package/template/booking/README.md +58 -0
  15. package/template/booking/marcapony.json +26 -0
  16. package/template/booking/src/server/index.ts +113 -0
  17. package/template/booking/src/ui/App.tsx +188 -0
  18. package/template/shop/README.md +66 -0
  19. package/template/shop/marcapony.json +12 -0
  20. package/template/shop/src/server/index.ts +211 -0
  21. package/template/shop/src/ui/App.tsx +214 -0
  22. package/template/team-tool/README.md +59 -0
  23. package/template/team-tool/marcapony.json +25 -0
  24. package/template/team-tool/src/server/index.ts +116 -0
  25. package/template/team-tool/src/ui/App.tsx +179 -0
  26. package/template/.dev.vars.example +0 -5
  27. package/template/README.md +0 -59
  28. package/template/src/server/marcapony.ts +0 -28
  29. package/template/src/ui/styles.css +0 -45
  30. /package/template/{_gitignore → base/_gitignore} +0 -0
  31. /package/template/{index.html → base/index.html} +0 -0
  32. /package/template/{src → base/src}/ui/main.tsx +0 -0
  33. /package/template/{tsconfig.json → base/tsconfig.json} +0 -0
  34. /package/template/{vite.config.ts → base/vite.config.ts} +0 -0
  35. /package/template/{src → blank/src}/ui/App.tsx +0 -0
@@ -0,0 +1,115 @@
1
+ :root {
2
+ color-scheme: light dark;
3
+ font-family:
4
+ ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
5
+ line-height: 1.5;
6
+ --border: #d4d4d8;
7
+ --muted: #52525b;
8
+ --notice: #fef3c7;
9
+ --notice-text: #78350f;
10
+ --error: #b91c1c;
11
+ }
12
+
13
+ @media (prefers-color-scheme: dark) {
14
+ :root {
15
+ --border: #3f3f46;
16
+ --muted: #a1a1aa;
17
+ --notice: #422006;
18
+ --notice-text: #fde68a;
19
+ --error: #fca5a5;
20
+ }
21
+ }
22
+
23
+ body {
24
+ margin: 0;
25
+ }
26
+
27
+ main {
28
+ max-width: 42rem;
29
+ margin: 0 auto;
30
+ padding: 3rem 1.5rem;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 1.5rem;
35
+ margin-bottom: 0.5rem;
36
+ }
37
+
38
+ h2 {
39
+ font-size: 1.125rem;
40
+ margin-top: 2rem;
41
+ }
42
+
43
+ code {
44
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
45
+ font-size: 0.875em;
46
+ }
47
+
48
+ ul {
49
+ padding-left: 1.25rem;
50
+ }
51
+
52
+ button,
53
+ input,
54
+ select,
55
+ textarea {
56
+ font: inherit;
57
+ }
58
+
59
+ button {
60
+ padding: 0.25rem 0.75rem;
61
+ cursor: pointer;
62
+ }
63
+
64
+ button:disabled {
65
+ cursor: default;
66
+ }
67
+
68
+ label {
69
+ display: block;
70
+ margin-bottom: 0.75rem;
71
+ }
72
+
73
+ label > input,
74
+ label > select,
75
+ label > textarea {
76
+ display: block;
77
+ margin-top: 0.25rem;
78
+ }
79
+
80
+ .muted {
81
+ color: var(--muted);
82
+ }
83
+
84
+ .error {
85
+ color: var(--error);
86
+ }
87
+
88
+ .notice {
89
+ background: var(--notice);
90
+ color: var(--notice-text);
91
+ padding: 0.5rem 0.75rem;
92
+ border-radius: 0.25rem;
93
+ }
94
+
95
+ .rows {
96
+ list-style: none;
97
+ padding: 0;
98
+ margin: 0;
99
+ }
100
+
101
+ .rows > li {
102
+ display: flex;
103
+ flex-wrap: wrap;
104
+ align-items: center;
105
+ justify-content: space-between;
106
+ gap: 0.5rem;
107
+ padding: 0.75rem 0;
108
+ border-bottom: 1px solid var(--border);
109
+ }
110
+
111
+ .actions {
112
+ display: flex;
113
+ flex-wrap: wrap;
114
+ gap: 0.5rem;
115
+ }
@@ -0,0 +1,48 @@
1
+ # Marcapony app: blank
2
+
3
+ A small starting point with its own backend. As an example it lists the
4
+ account's products.
5
+
6
+ ## Set up in the dashboard
7
+
8
+ Create the app under **My Apps** with:
9
+
10
+ - **Placement:** public (`placement` is not set in `marcapony.json`)
11
+ - **Data access:** visitor
12
+ - **Scopes:** `products:read`
13
+ - **Permissions:** none
14
+
15
+ ## Routes
16
+
17
+ | Route | What it does |
18
+ | ------------------- | ---------------------------------- |
19
+ | `GET /api/health` | Answers `{ "ok": true }` |
20
+ | `GET /api/products` | Up to 12 published products of the account |
21
+
22
+ ## What to change first
23
+
24
+ 1. Replace the products example in `src/server/index.ts` and `src/ui/App.tsx`
25
+ with what the app is for.
26
+ 2. Enable the scopes the new calls need, then run `bun run link` again so
27
+ `AGENTS.md` lists them.
28
+ 3. Set the page title in `index.html`.
29
+
30
+ ## Develop and publish
31
+
32
+ Requires [Bun](https://bun.sh).
33
+
34
+ ```sh
35
+ bun install
36
+ bun run link # paste the connection code from the app's page; writes .dev.vars and AGENTS.md
37
+ bun run dev # interface and /api routes on your machine
38
+ bun run deploy # build and publish; prints the address
39
+ ```
40
+
41
+ `.dev.vars` holds the app key. Never commit it, and never send it to the
42
+ browser: the interface calls this app's own `/api` routes, and only those talk
43
+ to Marcapony. `MARCAPONY_APP_ID` is set by Marcapony when the app is deployed;
44
+ locally there is none, so nobody is signed in during `bun run dev`.
45
+
46
+ New apps start in test mode: writes are simulated until you switch test mode off
47
+ on the app's page. Pass an `idempotencyKey` to every create call so a retry
48
+ cannot create the same thing twice.
@@ -1,5 +1,5 @@
1
1
  import { Hono } from 'hono'
2
- import { marcaponyFromEnv, type MarcaponyBindings } from './marcapony'
2
+ import { errorResponse, marcaponyFromEnv, type MarcaponyBindings } from './marcapony'
3
3
 
4
4
  /**
5
5
  * The app's server. Only `/api/*` reaches this worker — everything else is
@@ -14,10 +14,15 @@ app.get('/api/health', (c) => c.json({ ok: true }))
14
14
  * Example read. The app key never leaves the server: the browser calls this
15
15
  * route, and this route calls Marcapony.
16
16
  */
17
+ /** `Product.status`: 1 draft, 2 published, 3 archived. Show visitors only published products. */
18
+ const PUBLISHED = 2
19
+
17
20
  app.get('/api/products', async (c) => {
18
21
  const mp = marcaponyFromEnv(c.env)
19
- const page = await mp.products.list({ perPage: 12 })
20
- return c.json({ products: page.data, total: page.meta.total })
22
+ // The list has no status filter, so drop drafts and archived products here.
23
+ const page = await mp.products.list({ perPage: 50 })
24
+ const products = page.data.filter((product) => product.status === PUBLISHED).slice(0, 12)
25
+ return c.json({ products })
21
26
  })
22
27
 
23
28
  /**
@@ -33,9 +38,6 @@ app.get('/api/products', async (c) => {
33
38
  * })
34
39
  */
35
40
 
36
- app.onError((err, c) => {
37
- console.error(err)
38
- return c.json({ error: err instanceof Error ? err.message : 'Unexpected error' }, 500)
39
- })
41
+ app.onError((err) => errorResponse(err))
40
42
 
41
43
  export default app
@@ -0,0 +1,58 @@
1
+ # Marcapony app: booking
2
+
3
+ Lets a signed-in customer see their appointments, book a new one and cancel one.
4
+ It runs inside the customer portal of the business's site.
5
+
6
+ ## Set up in the dashboard
7
+
8
+ Create the app under **My Apps** with:
9
+
10
+ - **Placement:** customer portal (`"placement": "portal"`)
11
+ - **Data access:** customer (`"dataAccess": "customer"`)
12
+ - **Scopes:** `reservations:read`, `reservations:write`
13
+ - **Plugin:** the account needs reservations enabled
14
+ - **Permissions** (declared in `marcapony.json`; choose who gets them):
15
+ - `view-bookings`, "See my appointments": `reservations.own.read`
16
+ - `book`, "Book and cancel appointments": `reservations.own.create`, `reservations.own.cancel`
17
+
18
+ ## Routes
19
+
20
+ | Route | What it does |
21
+ | ------------------------------------ | ----------------------------------------------- |
22
+ | `GET /api/me` | Who is signed in and what they may do; 401 if nobody |
23
+ | `GET /api/reservations` | The customer's own appointments |
24
+ | `POST /api/reservations` | Book: `{ requestId, date, time, notes? }` |
25
+ | `POST /api/reservations/:id/cancel` | Cancel one of the customer's appointments |
26
+
27
+ Every call is made for the signed-in customer only, so one customer can never
28
+ see another's bookings. When the owner previews the page, a banner says that
29
+ changes are simulated.
30
+
31
+ ## What to change first
32
+
33
+ 1. The booking form in `src/ui/App.tsx`: add the fields the business needs
34
+ (pass them as `customFields` in `src/server/index.ts`) and a duration if
35
+ appointments are not the default length.
36
+ 2. The menu title in `marcapony.json` (`portal.title`).
37
+ 3. Test sign-in flows on the deployed app: locally nobody is signed in, so
38
+ `/api/me` answers 401.
39
+
40
+ ## Develop and publish
41
+
42
+ Requires [Bun](https://bun.sh).
43
+
44
+ ```sh
45
+ bun install
46
+ bun run link # paste the connection code from the app's page; writes .dev.vars and AGENTS.md
47
+ bun run dev # interface and /api routes on your machine
48
+ bun run deploy # build and publish; prints the address
49
+ ```
50
+
51
+ `.dev.vars` holds the app key. Never commit it, and never send it to the
52
+ browser: the interface calls this app's own `/api` routes, and only those talk
53
+ to Marcapony. `MARCAPONY_APP_ID` is set by Marcapony when the app is deployed;
54
+ locally there is none, so nobody is signed in during `bun run dev`.
55
+
56
+ New apps start in test mode: writes are simulated until you switch test mode off
57
+ on the app's page. Pass an `idempotencyKey` to every create call so a retry
58
+ cannot create the same thing twice.
@@ -0,0 +1,26 @@
1
+ {
2
+ "build": "bun run build",
3
+ "worker": "dist/worker/index.js",
4
+ "assets": "dist/client",
5
+ "assetsConfig": {
6
+ "not_found_handling": "single-page-application",
7
+ "run_worker_first": ["/api/*"]
8
+ },
9
+ "compatibilityDate": "2026-10-01",
10
+ "compatibilityFlags": ["nodejs_compat"],
11
+ "placement": "portal",
12
+ "dataAccess": "customer",
13
+ "permissions": [
14
+ {
15
+ "id": "view-bookings",
16
+ "label": "See my appointments",
17
+ "grants": ["reservations.own.read"]
18
+ },
19
+ {
20
+ "id": "book",
21
+ "label": "Book and cancel appointments",
22
+ "grants": ["reservations.own.create", "reservations.own.cancel"]
23
+ }
24
+ ],
25
+ "portal": { "title": "Appointments" }
26
+ }
@@ -0,0 +1,113 @@
1
+ import { Hono } from 'hono'
2
+ import type { Identity } from 'marcapony-sdk'
3
+ import {
4
+ errorResponse,
5
+ identityOf,
6
+ isSimulated,
7
+ marcaponyFromEnv,
8
+ type Marcapony,
9
+ type MarcaponyBindings,
10
+ } from './marcapony'
11
+
12
+ /**
13
+ * A booking page inside the customer portal. Only `/api/*` reaches this worker;
14
+ * everything else is served from `dist/client` (see `run_worker_first` in
15
+ * marcapony.json).
16
+ *
17
+ * Every call about the visitor goes through `mp.forRequest(c.req.raw).me`, so
18
+ * the platform limits it to the signed-in customer. Never use the plain client
19
+ * for a visitor's own records, and never keep a scoped client or its answers in
20
+ * module scope: one worker serves many visitors.
21
+ */
22
+ const app = new Hono<{ Bindings: MarcaponyBindings }>()
23
+
24
+ const DATE = /^\d{4}-\d{2}-\d{2}$/
25
+ const TIME = /^\d{2}:\d{2}$/
26
+ const REQUEST_ID = /^[A-Za-z0-9-]{8,64}$/
27
+
28
+ /** The signed-in customer, or a 401/403 answer to send instead. */
29
+ async function customerOf(
30
+ mp: Marcapony,
31
+ env: MarcaponyBindings,
32
+ request: Request,
33
+ ): Promise<Identity | Response> {
34
+ const who = await identityOf(mp, env, request)
35
+ if (!who) return Response.json({ error: 'Please sign in to the portal.' }, { status: 401 })
36
+ if (who.kind !== 'customer') {
37
+ return Response.json({ error: 'This page is for customers.' }, { status: 403 })
38
+ }
39
+ return who
40
+ }
41
+
42
+ app.get('/api/health', (c) => c.json({ ok: true }))
43
+
44
+ app.get('/api/me', async (c) => {
45
+ const mp = marcaponyFromEnv(c.env)
46
+ const who = await customerOf(mp, c.env, c.req.raw)
47
+ if (who instanceof Response) return who
48
+ return c.json({
49
+ email: who.email,
50
+ preview: who.preview,
51
+ canView: who.can('view-bookings'),
52
+ canBook: who.can('book'),
53
+ })
54
+ })
55
+
56
+ app.get('/api/reservations', async (c) => {
57
+ const mp = marcaponyFromEnv(c.env)
58
+ const who = await customerOf(mp, c.env, c.req.raw)
59
+ if (who instanceof Response) return who
60
+ const page = await mp.forRequest(c.req.raw).me.reservations.list({ perPage: 50 })
61
+ return c.json({ reservations: page.data })
62
+ })
63
+
64
+ interface CreateBody {
65
+ requestId?: unknown
66
+ date?: unknown
67
+ time?: unknown
68
+ notes?: unknown
69
+ }
70
+
71
+ app.post('/api/reservations', async (c) => {
72
+ const mp = marcaponyFromEnv(c.env)
73
+ const who = await customerOf(mp, c.env, c.req.raw)
74
+ if (who instanceof Response) return who
75
+
76
+ const body = (await c.req.json().catch(() => ({}))) as CreateBody
77
+ const { requestId, date, time, notes } = body
78
+ if (typeof requestId !== 'string' || !REQUEST_ID.test(requestId)) {
79
+ return c.json({ error: 'requestId is missing or malformed.' }, 400)
80
+ }
81
+ if (typeof date !== 'string' || !DATE.test(date)) {
82
+ return c.json({ error: 'Pick a date.' }, 400)
83
+ }
84
+ if (typeof time !== 'string' || !TIME.test(time)) {
85
+ return c.json({ error: 'Pick a time.' }, 400)
86
+ }
87
+
88
+ // The browser sends one request id per booking attempt and reuses it when it
89
+ // retries, so a double click or a retried request books once. The customer
90
+ // id is part of the key so two visitors can never collide.
91
+ const reservation = await mp.forRequest(c.req.raw).me.reservations.create(
92
+ {
93
+ requestedDate: date,
94
+ requestedTime: time,
95
+ ...(typeof notes === 'string' && notes.trim() ? { notes: notes.trim().slice(0, 500) } : {}),
96
+ },
97
+ { idempotencyKey: `booking-${who.sub}-${requestId}` },
98
+ )
99
+ // Simulated in a preview, and in test mode for every visitor.
100
+ return c.json({ reservation, simulated: who.preview || isSimulated(reservation) }, 201)
101
+ })
102
+
103
+ app.post('/api/reservations/:id/cancel', async (c) => {
104
+ const mp = marcaponyFromEnv(c.env)
105
+ const who = await customerOf(mp, c.env, c.req.raw)
106
+ if (who instanceof Response) return who
107
+ const result = await mp.forRequest(c.req.raw).me.reservations.cancel(c.req.param('id'))
108
+ return c.json({ reservation: result, simulated: who.preview || isSimulated(result) })
109
+ })
110
+
111
+ app.onError((err) => errorResponse(err))
112
+
113
+ export default app
@@ -0,0 +1,188 @@
1
+ import { useCallback, useEffect, useState, type FormEvent } from 'react'
2
+ import { api, ApiError, errorMessage, newRequestId } from './api'
3
+
4
+ interface Me {
5
+ email: string
6
+ preview: boolean
7
+ canView: boolean
8
+ canBook: boolean
9
+ }
10
+
11
+ interface Reservation {
12
+ id: string
13
+ requestedDate: string
14
+ requestedTime: string
15
+ duration: number | null
16
+ status: string | number
17
+ notes: string | null
18
+ productName: string | null
19
+ }
20
+
21
+ const CANCELLABLE = new Set(['pending', 'approved'])
22
+
23
+ export function App() {
24
+ const [me, setMe] = useState<Me | null>(null)
25
+ const [signedOut, setSignedOut] = useState(false)
26
+ const [reservations, setReservations] = useState<Reservation[] | null>(null)
27
+ const [error, setError] = useState<string | null>(null)
28
+ const [notice, setNotice] = useState<string | null>(null)
29
+
30
+ const loadReservations = useCallback(() => {
31
+ api<{ reservations: Reservation[] }>('/api/reservations')
32
+ .then((body) => setReservations(body.reservations))
33
+ .catch((err: unknown) => setError(errorMessage(err)))
34
+ }, [])
35
+
36
+ useEffect(() => {
37
+ api<Me>('/api/me')
38
+ .then((body) => {
39
+ setMe(body)
40
+ if (body.canView) loadReservations()
41
+ })
42
+ .catch((err: unknown) => {
43
+ if (err instanceof ApiError && err.status === 401) setSignedOut(true)
44
+ else setError(errorMessage(err))
45
+ })
46
+ }, [loadReservations])
47
+
48
+ if (signedOut) {
49
+ return (
50
+ <main>
51
+ <h1>Appointments</h1>
52
+ <p>Sign in to the portal to see and book your appointments.</p>
53
+ </main>
54
+ )
55
+ }
56
+
57
+ if (!me) {
58
+ return (
59
+ <main>
60
+ <h1>Appointments</h1>
61
+ {error ? <p className="error">{error}</p> : <p>Loading…</p>}
62
+ </main>
63
+ )
64
+ }
65
+
66
+ async function cancel(id: string) {
67
+ setError(null)
68
+ try {
69
+ const body = await api<{ simulated: boolean }>(
70
+ `/api/reservations/${encodeURIComponent(id)}/cancel`,
71
+ { method: 'POST' },
72
+ )
73
+ setNotice(
74
+ body.simulated ? 'Cancellation simulated (test mode or preview). Nothing was saved.' : null,
75
+ )
76
+ loadReservations()
77
+ } catch (err) {
78
+ setError(errorMessage(err))
79
+ }
80
+ }
81
+
82
+ return (
83
+ <main>
84
+ <h1>Appointments</h1>
85
+ <p className="muted">Signed in as {me.email}</p>
86
+ {me.preview ? (
87
+ <p className="notice">
88
+ Preview: you are viewing this page as a customer. Bookings and cancellations are
89
+ simulated and nothing is saved.
90
+ </p>
91
+ ) : null}
92
+ {error ? <p className="error">{error}</p> : null}
93
+ {notice ? <p>{notice}</p> : null}
94
+
95
+ <h2>My appointments</h2>
96
+ {!me.canView ? <p>You do not have access to your appointment list.</p> : null}
97
+ {me.canView && reservations === null ? <p>Loading…</p> : null}
98
+ {reservations?.length === 0 ? <p>You have no appointments yet.</p> : null}
99
+ <ul className="rows">
100
+ {reservations?.map((reservation) => (
101
+ <li key={reservation.id}>
102
+ <span>
103
+ {reservation.requestedDate} at {reservation.requestedTime}
104
+ {reservation.productName ? `, ${reservation.productName}` : ''}{' '}
105
+ <span className="muted">({String(reservation.status)})</span>
106
+ </span>
107
+ {me.canBook && CANCELLABLE.has(String(reservation.status)) ? (
108
+ <button type="button" onClick={() => void cancel(reservation.id)}>
109
+ Cancel
110
+ </button>
111
+ ) : null}
112
+ </li>
113
+ ))}
114
+ </ul>
115
+
116
+ {me.canBook ? <BookingForm onBooked={loadReservations} /> : null}
117
+ </main>
118
+ )
119
+ }
120
+
121
+ function BookingForm({ onBooked }: { onBooked: () => void }) {
122
+ const [date, setDate] = useState('')
123
+ const [time, setTime] = useState('')
124
+ const [notes, setNotes] = useState('')
125
+ // One id per booking attempt: a retry of the same booking (double click,
126
+ // network error) reuses it, and changing what is being booked starts a new one.
127
+ const [requestId, setRequestId] = useState(newRequestId)
128
+ const edit = (set: (value: string) => void) => (value: string) => {
129
+ set(value)
130
+ setRequestId(newRequestId())
131
+ }
132
+ const [busy, setBusy] = useState(false)
133
+ const [message, setMessage] = useState<string | null>(null)
134
+ const [error, setError] = useState<string | null>(null)
135
+
136
+ async function submit(event: FormEvent) {
137
+ event.preventDefault()
138
+ setBusy(true)
139
+ setError(null)
140
+ setMessage(null)
141
+ try {
142
+ const body = await api<{ simulated: boolean }>('/api/reservations', {
143
+ body: { requestId, date, time, notes },
144
+ })
145
+ setMessage(
146
+ body.simulated
147
+ ? 'Booking simulated (test mode or preview). Nothing was saved.'
148
+ : 'Booked. We will confirm it.',
149
+ )
150
+ setRequestId(newRequestId())
151
+ setNotes('')
152
+ onBooked()
153
+ } catch (err) {
154
+ setError(errorMessage(err))
155
+ } finally {
156
+ setBusy(false)
157
+ }
158
+ }
159
+
160
+ return (
161
+ <form onSubmit={(event) => void submit(event)}>
162
+ <h2>Book an appointment</h2>
163
+ <label>
164
+ Date
165
+ <input type="date" required value={date} onChange={(e) => edit(setDate)(e.target.value)} />
166
+ </label>
167
+ <label>
168
+ Time
169
+ <input
170
+ type="time"
171
+ required
172
+ step={900}
173
+ value={time}
174
+ onChange={(e) => edit(setTime)(e.target.value)}
175
+ />
176
+ </label>
177
+ <label>
178
+ Notes (optional)
179
+ <textarea rows={3} maxLength={500} value={notes} onChange={(e) => edit(setNotes)(e.target.value)} />
180
+ </label>
181
+ <button type="submit" disabled={busy}>
182
+ {busy ? 'Booking…' : 'Book'}
183
+ </button>
184
+ {message ? <p>{message}</p> : null}
185
+ {error ? <p className="error">{error}</p> : null}
186
+ </form>
187
+ )
188
+ }
@@ -0,0 +1,66 @@
1
+ # Marcapony app: shop
2
+
3
+ A small public shop: the product list with a category filter, a cart kept in
4
+ the visitor's browser, and a checkout that creates a payment link and sends the
5
+ buyer to pay.
6
+
7
+ ## Set up in the dashboard
8
+
9
+ Create the app under **My Apps** with:
10
+
11
+ - **Placement:** public (`"placement": "public"`)
12
+ - **Data access:** account. Creating a payment link is not available to visitor
13
+ apps, so set this in the dashboard; a deploy cannot widen it.
14
+ - **Scopes:** `products:read`, `site:read`, `payment-links:write`. Grant nothing
15
+ else: with account data access, the key reaches everything its scopes allow.
16
+ - **Plugin:** the account needs payment links enabled
17
+ - **Permissions:** none
18
+
19
+ ## Routes
20
+
21
+ | Route | What it does |
22
+ | --------------------- | --------------------------------------------------------------- |
23
+ | `GET /api/catalog` | Shop name, categories and products (`?category=<slug>` filters) |
24
+ | `POST /api/checkout` | `{ attemptId, items: [{ productId, quantity }] }` → total and pay link |
25
+
26
+ The browser sends only product ids and quantities. The server reads every
27
+ product again, uses its sale price when it has one, checks stock and computes
28
+ the total itself. The buyer pays at `/pay/<linkId>` on the business's site.
29
+
30
+ ## What to change first
31
+
32
+ 1. The product view in `src/ui/App.tsx` (images, descriptions, layout).
33
+ 2. Add a `successUrl` to the payment link in `src/server/index.ts` if buyers
34
+ should return somewhere after paying; it must be on one of the account's
35
+ verified domains.
36
+ 3. If the business ships goods, collect an address before checkout.
37
+
38
+ ## Before going live
39
+
40
+ Checkout is open to anyone, and every new checkout attempt creates a real
41
+ payment link once test mode is off. A script can call it in a loop: that
42
+ fills the account with unpaid links and uses up the app's request limit, which
43
+ the catalog shares, so the shop stops loading for real buyers. Before you switch
44
+ test mode off, add a bot check (for example Turnstile) or a rate limit in front
45
+ of `/api/checkout`. `guardCheckout` in `src/server/index.ts` is where the check
46
+ goes.
47
+
48
+ ## Develop and publish
49
+
50
+ Requires [Bun](https://bun.sh).
51
+
52
+ ```sh
53
+ bun install
54
+ bun run link # paste the connection code from the app's page; writes .dev.vars and AGENTS.md
55
+ bun run dev # interface and /api routes on your machine
56
+ bun run deploy # build and publish; prints the address
57
+ ```
58
+
59
+ `.dev.vars` holds the app key. Never commit it, and never send it to the
60
+ browser: the interface calls this app's own `/api` routes, and only those talk
61
+ to Marcapony. `MARCAPONY_APP_ID` is set by Marcapony when the app is deployed;
62
+ locally there is none, so nobody is signed in during `bun run dev`.
63
+
64
+ New apps start in test mode: writes are simulated until you switch test mode off
65
+ on the app's page. Pass an `idempotencyKey` to every create call so a retry
66
+ cannot create the same thing twice.
@@ -0,0 +1,12 @@
1
+ {
2
+ "build": "bun run build",
3
+ "worker": "dist/worker/index.js",
4
+ "assets": "dist/client",
5
+ "assetsConfig": {
6
+ "not_found_handling": "single-page-application",
7
+ "run_worker_first": ["/api/*"]
8
+ },
9
+ "compatibilityDate": "2026-10-01",
10
+ "compatibilityFlags": ["nodejs_compat"],
11
+ "placement": "public"
12
+ }