create-marcapony-app 0.2.0 → 0.2.1
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": "create-marcapony-app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Scaffold a Marcapony app \u2014 a Worker backed by the Marcapony API, ready for `marcapony app link` and `marcapony app deploy`",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"hono": "^4.13.0",
|
|
17
|
-
"marcapony-sdk": "^0.
|
|
17
|
+
"marcapony-sdk": "^0.7.0",
|
|
18
18
|
"react": "^19.3.0",
|
|
19
19
|
"react-dom": "^19.3.0"
|
|
20
20
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@types/react-dom": "^19.3.0",
|
|
25
25
|
"@vitejs/plugin-react": "^5.2.0",
|
|
26
26
|
"esbuild": "^0.28.0",
|
|
27
|
-
"marcapony": "^0.4.
|
|
27
|
+
"marcapony": "^0.4.2",
|
|
28
28
|
"typescript": "^5.9.0",
|
|
29
29
|
"vite": "^7.3.0"
|
|
30
30
|
}
|
|
@@ -53,20 +53,6 @@ export async function identityOf(
|
|
|
53
53
|
return mp.identity(request)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* Whether Marcapony only simulated a write. New apps start in test mode, where
|
|
58
|
-
* writes answer with the record they would have created, marked
|
|
59
|
-
* `simulated: true`, and nothing is saved. The SDK types do not declare the
|
|
60
|
-
* marker yet, so read it defensively.
|
|
61
|
-
*/
|
|
62
|
-
export function isSimulated(result: unknown): boolean {
|
|
63
|
-
return (
|
|
64
|
-
typeof result === 'object' &&
|
|
65
|
-
result !== null &&
|
|
66
|
-
(result as { simulated?: unknown }).simulated === true
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
56
|
/**
|
|
71
57
|
* Turns a failed call into a JSON answer for the browser. A Marcapony error
|
|
72
58
|
* keeps its status (401 not signed in, 403 not allowed, 404, 422 invalid
|
|
@@ -3,7 +3,6 @@ import type { Identity } from 'marcapony-sdk'
|
|
|
3
3
|
import {
|
|
4
4
|
errorResponse,
|
|
5
5
|
identityOf,
|
|
6
|
-
isSimulated,
|
|
7
6
|
marcaponyFromEnv,
|
|
8
7
|
type Marcapony,
|
|
9
8
|
type MarcaponyBindings,
|
|
@@ -97,7 +96,7 @@ app.post('/api/reservations', async (c) => {
|
|
|
97
96
|
{ idempotencyKey: `booking-${who.sub}-${requestId}` },
|
|
98
97
|
)
|
|
99
98
|
// Simulated in a preview, and in test mode for every visitor.
|
|
100
|
-
return c.json({ reservation, simulated: who.preview ||
|
|
99
|
+
return c.json({ reservation, simulated: who.preview || reservation.simulated === true }, 201)
|
|
101
100
|
})
|
|
102
101
|
|
|
103
102
|
app.post('/api/reservations/:id/cancel', async (c) => {
|
|
@@ -105,7 +104,7 @@ app.post('/api/reservations/:id/cancel', async (c) => {
|
|
|
105
104
|
const who = await customerOf(mp, c.env, c.req.raw)
|
|
106
105
|
if (who instanceof Response) return who
|
|
107
106
|
const result = await mp.forRequest(c.req.raw).me.reservations.cancel(c.req.param('id'))
|
|
108
|
-
return c.json({ reservation: result, simulated: who.preview ||
|
|
107
|
+
return c.json({ reservation: result, simulated: who.preview || result.simulated === true })
|
|
109
108
|
})
|
|
110
109
|
|
|
111
110
|
app.onError((err) => errorResponse(err))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hono, type Context } from 'hono'
|
|
2
|
-
import type {
|
|
3
|
-
import { errorResponse,
|
|
2
|
+
import type { PaymentLinkLineItem, Product } from 'marcapony-sdk'
|
|
3
|
+
import { errorResponse, marcaponyFromEnv, type MarcaponyBindings } from './marcapony'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A small public shop: the catalog, a cart kept in the browser, and a checkout
|
|
@@ -179,7 +179,7 @@ app.post('/api/checkout', async (c) => {
|
|
|
179
179
|
// are part of the key too: a reused attempt id with a different cart must
|
|
180
180
|
// not be answered with the earlier cart's link.
|
|
181
181
|
const idempotencyKey = `checkout-${attemptId}-${await cartFingerprint(quantities)}`
|
|
182
|
-
const link =
|
|
182
|
+
const link = await mp.paymentLinks.create(
|
|
183
183
|
{
|
|
184
184
|
title: `${site.name} order`,
|
|
185
185
|
amount,
|
|
@@ -187,21 +187,15 @@ app.post('/api/checkout', async (c) => {
|
|
|
187
187
|
lineItems,
|
|
188
188
|
},
|
|
189
189
|
{ idempotencyKey },
|
|
190
|
-
)
|
|
190
|
+
)
|
|
191
191
|
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
// In test mode the link is only simulated: nothing was saved and there is
|
|
193
|
+
// nothing to pay yet, so there is no payment page either.
|
|
194
|
+
if (link.simulated) {
|
|
195
|
+
return c.json({ amount, currency, payUrl: null, linkId: link.linkId ?? null, simulated: true }, 201)
|
|
196
|
+
}
|
|
197
197
|
return c.json(
|
|
198
|
-
{
|
|
199
|
-
amount,
|
|
200
|
-
currency: link.currency ?? currency,
|
|
201
|
-
payUrl: simulated ? null : payUrl,
|
|
202
|
-
linkId: link.linkId,
|
|
203
|
-
simulated,
|
|
204
|
-
},
|
|
198
|
+
{ amount, currency: link.currency, payUrl: link.paymentUrl, linkId: link.linkId, simulated: false },
|
|
205
199
|
201,
|
|
206
200
|
)
|
|
207
201
|
})
|
|
@@ -3,7 +3,6 @@ import type { Identity, Reservation, UpdateReservationStatusInput } from 'marcap
|
|
|
3
3
|
import {
|
|
4
4
|
errorResponse,
|
|
5
5
|
identityOf,
|
|
6
|
-
isSimulated,
|
|
7
6
|
marcaponyFromEnv,
|
|
8
7
|
type Marcapony,
|
|
9
8
|
type MarcaponyBindings,
|
|
@@ -108,7 +107,7 @@ app.post('/api/reservations/:id/status', async (c) => {
|
|
|
108
107
|
|
|
109
108
|
const result = await mp.forRequest(c.req.raw).reservations.updateStatus(c.req.param('id'), input)
|
|
110
109
|
// Simulated in a preview, and in test mode for every member.
|
|
111
|
-
return c.json({ ok: true, simulated: who.preview ||
|
|
110
|
+
return c.json({ ok: true, simulated: who.preview || result.simulated === true })
|
|
112
111
|
})
|
|
113
112
|
|
|
114
113
|
app.onError((err) => errorResponse(err))
|