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