@dunbackmeadow/commerce-sdk 0.0.0-stage → 0.5.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.
@@ -0,0 +1,282 @@
1
+ # Luma × Dunback Meadow: integration guide
2
+
3
+ This guide covers everything Luma needs to build so hosts can order food and
4
+ drinks for their events through Dunback Meadow. A complete reference
5
+ implementation is in [`examples/luma-integration`](../examples/luma-integration).
6
+
7
+ ## What hosts and guests see
8
+
9
+ | Step | Who | What they do in Luma | What Luma does |
10
+ | ---- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
11
+ | 1 | Host, creating an event | Turns on **Food & drinks by Dunback Meadow**, picks a cuisine (American, Chinese, Mexican, …), optionally sets a budget per guest and turns drinks off | Saves `DunbackEventSettings` with the event, then adds the allergy question to the registration form |
12
+ | 2 | Guest, registering | Optionally answers _"Food allergies or dietary needs"_ | Stores the answer with the registration, as usual |
13
+ | 3 | Host, after the guest list is final | Opens the event page and clicks **Order Food via Dunback Meadow** | Sends attendees (name, email, phone, allergy note) to Dunback |
14
+ | 4 | Dunback | Composes **3 catering options** with prices and fee breakdowns (usually within 30 s) | Luma shows the options when the `catering.options_ready` webhook arrives |
15
+ | 5 | Host | Picks an option | Luma gets an order with payment links: **Pay by card** (Stripe) and **Pay with USDC** |
16
+ | 6 | Host | Pays | Dunback verifies the payment, pays the restaurant, and the restaurant confirms. Luma receives `order.confirmed` |
17
+ | 7 | Restaurant | Delivers before the event starts (default: 30 minutes before) | — |
18
+
19
+ If a payment fails, Luma receives `order.payment_failed` with a message to show
20
+ the host. If the restaurant can't take the order after payment, the host is
21
+ refunded automatically and Luma receives `order.failed`.
22
+
23
+ ## 1. Setup
24
+
25
+ 1. **Credentials, from the Dunback Developer Dashboard**
26
+ (<https://dunbackmeadow.com/developer>). Luma's developer account applies
27
+ once as a business and is reviewed by Dunback. Then Luma creates an app
28
+ ("Luma event catering"), which has:
29
+ - a sandbox key (`dbk_test_app-…`) for `https://sandbox.dunbackmeadow.com/api/partner/v1`
30
+ - a production key (`dbk_live_app-…`) for `https://dunbackmeadow.com/api/partner/v1`
31
+ - a webhook signing secret (`whsec_…`) for each environment
32
+
33
+ Each key is shown once, when it's created. To rotate it, delete it in the
34
+ dashboard and create a new one.
35
+ 2. **Set in the dashboard, for each environment:**
36
+ - Luma's webhook URL (then click **Send test event**)
37
+ - the allowed return hosts for Stripe success and cancel URLs (for example `lu.ma`)
38
+ 3. **Install the SDK on Luma's servers:**
39
+
40
+ ```bash
41
+ npm install @dunbackmeadow/commerce-sdk
42
+ ```
43
+
44
+ ```ts
45
+ // The key decides the environment: dbk_test_ -> sandbox, dbk_live_ -> production.
46
+ const dunback = new DunbackClient({ apiKey: process.env.DUNBACK_API_KEY! });
47
+ ```
48
+
49
+ > The API key gives full ordering power. Keep it server-side. Luma's frontend
50
+ > talks only to Luma's backend.
51
+
52
+ ## 2. Event creation: enable catering and pick a cuisine
53
+
54
+ ```ts
55
+ // Backend: options for the picker, for the venue the host entered.
56
+ // Cache for a few minutes per venue; ask again when the address changes.
57
+ const venue = toVenueLocation(event.geo_address_json); // null until street, city and ZIP are in
58
+ const { data: cuisines, metro } = await dunback.cuisineCatalog(venue, { guests: settings?.expectedGuests, serviceStyle: settings?.serviceStyle });
59
+ // [{ id: "mexican", label: "Mexican", restaurants: 4 }, ...]
60
+ // With a venue, `restaurants` counts restaurants in its metro area only;
61
+ // 0 means none there serves that cuisine yet. metro: { id, name } or null.
62
+ // With guests, only restaurants able to cater that many count: restaurants
63
+ // may limit guests per order or require a minimum order.
64
+ ```
65
+
66
+ The host also chooses how food is served (`settings.serviceStyle`, asked by
67
+ `<DunbackCateringSettings>`): a **buffet** (trays to share; only restaurants
68
+ with catering trays) or **individual meal boxes** (one packed meal per guest;
69
+ more dishes and usually more restaurants). `buildCateringRequest()` sends it.
70
+
71
+ Pass the host's expected guest count (`settings.expectedGuests`, which
72
+ `<DunbackCateringSettings>` asks for, or the event's capacity) and the style,
73
+ and ask again when either changes. The real guest list is checked again when the host orders: if
74
+ it grew past what the chosen cuisine's restaurants cater for, the request ends
75
+ in `NO_OPTIONS` with `unavailableReasons[].code` `party_too_large`. Suggest
76
+ another cuisine then.
77
+
78
+ With `guests`, each cuisine also has `noticeHours`: restaurants can need more
79
+ advance notice for bigger parties (say 72 hours for more than 50 guests). Set
80
+ the event's `guestListDeadline` at least that long before delivery; ordering
81
+ later ends in `NO_OPTIONS` with code `notice_too_short`.
82
+ `<DunbackCateringSettings>` shows the notice under the cuisine.
83
+
84
+ Frontend: `<DunbackCateringSettings cuisines={cuisines} venueReady={!!venue} metroName={metro?.name} … />`.
85
+ While `venueReady` is false it shows no availability and asks the host to
86
+ enter the venue address first.
87
+
88
+ Save the host's choice with the event:
89
+
90
+ ```ts
91
+ type DunbackEventSettings = {
92
+ enabled: boolean;
93
+ cuisine: CuisineId; // "american" | "chinese" | "mexican" | ...
94
+ serviceStyle?: "buffet" | "meal_boxes"; // default "meal_boxes"
95
+ includeDrinks?: boolean; // default true (non-alcoholic only)
96
+ budgetPerGuest?: number; // USD; options above it are flagged, not hidden
97
+ guestListDeadline?: string; // ISO; "Order Food" is offered from then on
98
+ deliveryDeadlineLocal?: string; // default: 30 min before start, venue-local "YYYY-MM-DDTHH:mm"
99
+ deliveryNotes?: string; // "Loading dock on Emerson St"
100
+ onsiteContact?: { name: string; phone: string; email?: string }; // default: host
101
+ };
102
+ ```
103
+
104
+ The ready-made `<DunbackCateringSettings>` component renders this form
105
+ (`@dunbackmeadow/commerce-sdk/react`).
106
+
107
+ **Online events can't be catered.** `buildCateringRequest` throws if the venue
108
+ has no street address, city and ZIP.
109
+
110
+ ## 3. Registration: the allergy question
111
+
112
+ When catering is enabled, add `DUNBACK_REGISTRATION_QUESTION` to the event's
113
+ registration form:
114
+
115
+ ```ts
116
+ import { DUNBACK_REGISTRATION_QUESTION } from "@dunbackmeadow/commerce-sdk";
117
+ // { id: "dunback_food_allergies", label: "Food allergies or dietary needs", type: "long_text", required: false, ... }
118
+ ```
119
+
120
+ **Consent.** Allergy and diet answers are health information, so Dunback only
121
+ accepts them with the guest's consent. The question's description is that
122
+ consent: _"By answering, you agree that Dunback Meadow and the restaurant may
123
+ use your answer to prepare a safe meal for you."_ Keep this wording, or an
124
+ equivalent that names Dunback Meadow and the restaurant, and show it next to
125
+ the question.
126
+
127
+ `toDunbackAttendees()` sends an answer to `dunback_food_allergies` with
128
+ `allergyConsent: true`. If a host asks about allergies in their own question
129
+ instead, that answer is **not** sent, because the guest didn't see Dunback's
130
+ consent wording. Before ordering, call `guestsWithUnsharedAllergies(guests)`
131
+ and show the host those names, for example: _"Ana and Ben noted allergies
132
+ that Dunback can't check. Confirm their meals with them."_ If the host's own
133
+ question has the consent wording too, pass `{ otherQuestionsHaveConsent: true }`
134
+ to both helpers.
135
+
136
+ ## 4. "Order Food via Dunback Meadow"
137
+
138
+ Show the button on the host's event page when
139
+ `canOrderFood(settings, event).ok` is true. That requires all three of:
140
+
141
+ - catering is enabled
142
+ - the guest-list deadline has passed (if one is set)
143
+ - the event hasn't started
144
+
145
+ ```ts
146
+ import { buildCateringRequest } from "@dunbackmeadow/commerce-sdk";
147
+
148
+ const input = buildCateringRequest({
149
+ event, // Luma event: api_id, name, start_at, timezone, geo_address_json
150
+ guests, // Luma get-guests entries (raw or flattened); only approved/going guests are sent
151
+ settings, // DunbackEventSettings
152
+ host: { name, email, phone },
153
+ extraAttendees: [{ name: host.name }], // optional: hosts eat too
154
+ });
155
+ const request = await dunback.catering.create(input, {
156
+ idempotencyKey: `luma-${event.api_id}-${clickId}`,
157
+ });
158
+ ```
159
+
160
+ What is sent per guest: name, and email and phone when Luma has them (both
161
+ optional), plus the allergy answer when the guest consented.
162
+
163
+ - The **restaurant never receives the guest list.** It receives:
164
+ - the dishes and quantities
165
+ - the delivery address and on-site contact, only after payment
166
+ - a delivery note asking for allergy-labelled portions, which names the
167
+ guests with allergies (for example "no peanut for Ana")
168
+ - Dunback deletes guest data 30 days after the event. Orders are kept longer
169
+ for accounting, without guest names.
170
+
171
+ If Luma's guest model differs, build `attendees` yourself:
172
+ `{ externalId, name, email?, phone?, allergies?, dietaryPreferences?, allergyConsent? }`.
173
+ Set `allergyConsent: true` only for guests who agreed to share their notes.
174
+
175
+ ## 5. Showing the three options
176
+
177
+ Wait for the `catering.options_ready` webhook, or poll
178
+ `dunback.catering.get(id)` while `status === "COMPOSING"`.
179
+
180
+ | status | Show |
181
+ | --------------- | --------------------------------------------------------------- |
182
+ | `OPTIONS_READY` | `request.options` (up to 3) |
183
+ | `NO_OPTIONS` | "No restaurant can cater this event", plus `unavailableReasons` |
184
+ | `FAILED` | `error.message`, and offer a retry |
185
+
186
+ Each option contains:
187
+
188
+ | Field | What it holds |
189
+ | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
190
+ | `title`, `restaurant.name` | Heading for the card |
191
+ | `items` | Dishes and quantities. `role` is `main` (one per guest), `drink` (one per guest) or `extra` (shared sides and desserts) |
192
+ | `allergyCoverage` | Which dish each allergy group gets, e.g. "2 guests (no peanut): Veggie Bowl" |
193
+ | `unfedGuests` | Guests with no dish known to be safe for them. **Always show these to the host.** |
194
+ | `price.lines` | Food & drinks, delivery, restaurant fees, tax, Dunback fees |
195
+ | `price.totals.card` / `price.totals.usdc` | Totals for each payment method |
196
+ | `price.perGuest` | Per-guest price |
197
+ | `withinBudget` | Present when the host set a budget |
198
+ | `restaurant.policies` | The restaurant's `minimumOrder`, `maxGuests`, `freeDeliveryOver` (each `null` if none) |
199
+ | `freeDeliveryShortfall` | Food to add for free delivery, or `null`. A waived fee is a `Free delivery` price line of 0 |
200
+ | `items[].addedForMinimum` | A shared dish added to reach the restaurant's minimum order |
201
+ | `items[].serves` | A catering tray: people one unit serves (`quantity` counts trays). Restaurants' catering dishes are used first |
202
+ | `orderBy` | Last moment the restaurant can accept the order |
203
+
204
+ `<CateringOptionsPicker>` renders all of the above.
205
+
206
+ ## 6. Selection and payment
207
+
208
+ ```ts
209
+ const order = await dunback.catering.select(request.id, {
210
+ optionId,
211
+ payer: { name: host.name, email: host.email }, // pre-fills Stripe Checkout
212
+ successUrl: `https://lu.ma/event/manage/${eventId}?dunback=paid`,
213
+ cancelUrl: `https://lu.ma/event/manage/${eventId}?dunback=cancelled`,
214
+ });
215
+ ```
216
+
217
+ Show the host two buttons:
218
+
219
+ - **Pay $X by card**: `order.payment.stripe.checkoutUrl` (Stripe Checkout hosted by Dunback's Stripe account)
220
+ - **Pay with USDC**: `order.payment.hostedPaymentUrl` (Dunback page with the exact amount, address, wallet link and tx-hash box)
221
+
222
+ Or build your own USDC screen from `order.payment.usdc`.
223
+
224
+ After the Stripe redirect back to `successUrl`, call `dunback.orders.get(order.id)`.
225
+ It re-checks Stripe, so it doesn't depend on webhook timing. Then show
226
+ `<DunbackOrderStatus>` until the status is `CONFIRMED`.
227
+
228
+ The payment window is `order.payment.expiresAt`: 60 minutes by default, and
229
+ always before the restaurant's order deadline. When it expires, Luma receives
230
+ `order.expired`, the catering request goes back to `OPTIONS_READY`, and the
231
+ host can choose again.
232
+
233
+ ## 7. Webhooks
234
+
235
+ ```ts
236
+ app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, res) => {
237
+ const event = verifyWebhook(req.body, req.header("Dunback-Signature"), process.env.DUNBACK_WEBHOOK_SECRET!);
238
+ const lumaEventId = event.data.partnerReference.replace(/^luma:/, "");
239
+ ...
240
+ res.sendStatus(200);
241
+ });
242
+ ```
243
+
244
+ | Event | Suggested Luma behaviour |
245
+ | ------------------------ | -------------------------------------------------------------------------- |
246
+ | `catering.options_ready` | Notify the host: "Your catering options are ready" |
247
+ | `catering.no_options` | Notify the host, and suggest another cuisine or time |
248
+ | `order.created` | (optional) Store the order id |
249
+ | `order.payment_failed` | Show `payment.lastError.message` and keep the pay buttons |
250
+ | `order.confirmed` | Show "Catering confirmed" on the event page and email the host |
251
+ | `order.expired` | Let the host choose again |
252
+ | `order.failed` | Show the message. The host was refunded (`refund`). |
253
+ | `order.needs_attention` | Show "Dunback support is finishing your order". Dunback contacts the host. |
254
+ | `order.cancelled` | Show the cancellation and the refund |
255
+
256
+ ## 8. Cancellation
257
+
258
+ `dunback.orders.cancel(orderId, reason)` works in two cases:
259
+
260
+ - **Before payment:** the payment links are cancelled.
261
+ - **After confirmation, before the restaurant's order deadline:** the order is
262
+ cancelled at the restaurant and the host is refunded. Card refunds are
263
+ automatic; USDC refunds are sent after review.
264
+
265
+ After the deadline, the call fails with `cancel_refused`.
266
+
267
+ ## 9. Testing checklist (sandbox)
268
+
269
+ - [ ] `listCuisines()` returns the sandbox restaurants
270
+ - [ ] An event with 20 guests (3 with allergies) produces options whose `allergyCoverage` covers them
271
+ - [ ] A guest who noted allergies only in a host's own question is listed by `guestsWithUnsharedAllergies`, and the host sees the warning
272
+ - [ ] A guest whose allergy no dish can avoid appears in `unfedGuests`, and the warning is shown
273
+ - [ ] Card payment with `4242 4242 4242 4242` leads to `order.confirmed`
274
+ - [ ] A declined test card (`4000 0000 0000 0002`) keeps the order `AWAITING_PAYMENT`, and the host can retry
275
+ - [ ] A small USDC payment on Polygon is detected. The sandbox uses real Polygon USDC with Dunback's test restaurants.
276
+ - [ ] An expired link produces `order.expired`, and the host can choose again
277
+ - [ ] A webhook with a bad signature is rejected by Luma
278
+ - [ ] A double-clicked "Order Food" creates one request (same Idempotency-Key)
279
+
280
+ ## Support
281
+
282
+ support@dunbackmeadow.com. Include the `request.id` or `order.id` (`creq_…`, `ord_…`).
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@dunbackmeadow/commerce-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "Official Node.js/TypeScript SDK for the Dunback Meadow commerce API. Order from your app or agent and pay by card (Stripe) or USDC. Event catering is available now; more product types are coming.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/DunbackMeadow/commerce-sdk.git"
8
+ },
9
+ "homepage": "https://dunbackmeadow.com/developer",
10
+ "bugs": {
11
+ "url": "https://github.com/DunbackMeadow/commerce-sdk/issues"
12
+ },
13
+ "type": "module",
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./react": {
22
+ "types": "./dist/react/index.d.ts",
23
+ "import": "./dist/react/index.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE",
30
+ "docs"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsup src/index.ts src/react/index.tsx --format esm --dts --clean --external react",
34
+ "test": "vitest run",
35
+ "typecheck": "tsc --noEmit"
36
+ },
37
+ "keywords": [
38
+ "dunback-meadow",
39
+ "catering",
40
+ "luma",
41
+ "events",
42
+ "food-delivery",
43
+ "x402",
44
+ "usdc",
45
+ "stripe",
46
+ "agents"
47
+ ],
48
+ "author": "Dunback Meadow",
49
+ "license": "MIT",
50
+ "peerDependencies": {
51
+ "react": ">=18"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "react": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^22.10.7",
60
+ "@types/react": "^18.3.12",
61
+ "react": "^18.3.1",
62
+ "tsup": "^8.3.5",
63
+ "typescript": "^5.7.3",
64
+ "vitest": "^2.1.8"
65
+ },
66
+ "engines": {
67
+ "node": ">=18"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }