@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.
- package/LICENSE +21 -0
- package/README.md +256 -3
- package/dist/index.d.ts +186 -0
- package/dist/index.js +378 -0
- package/dist/luma-Cza_vuOB.d.ts +581 -0
- package/dist/react/index.d.ts +67 -0
- package/dist/react/index.js +288 -0
- package/docs/API_REFERENCE.md +345 -0
- package/docs/LUMA_INTEGRATION_GUIDE.md +282 -0
- package/package.json +70 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dunback Meadow
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,256 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Dunback Meadow Commerce SDK
|
|
2
|
+
|
|
3
|
+
`@dunbackmeadow/commerce-sdk` lets your app or agent order **event catering**
|
|
4
|
+
from restaurants on Dunback Meadow. More product types will follow. Buyers pay
|
|
5
|
+
**by card (Stripe)** or in **USDC on Polygon** (a wallet transfer or x402).
|
|
6
|
+
|
|
7
|
+
Dunback handles three things:
|
|
8
|
+
|
|
9
|
+
- **Restaurant selection.** Its catering agent finds restaurants that serve
|
|
10
|
+
the chosen cuisine, deliver to the venue, and can make the event time.
|
|
11
|
+
- **Allergy-aware menus.** Each guest gets a dish that is safe for their
|
|
12
|
+
allergies and diet, according to the restaurant's allergen data.
|
|
13
|
+
- **Payment and placement.** Dunback verifies the buyer's payment, pays the
|
|
14
|
+
restaurant, and confirms the order back to you.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Your app Dunback Meadow Restaurant agent
|
|
18
|
+
──────── ────────────── ────────────────
|
|
19
|
+
catering.create(guests) ───────▶ catering agent composes 3 options ───▶ quote_cart (prices)
|
|
20
|
+
◀── webhook catering.options_ready (price + fee breakdowns)
|
|
21
|
+
catering.select(option) ───────▶ order + payment links
|
|
22
|
+
payer pays (card / USDC / x402) ▶ verifies payment (Stripe API / on-chain)
|
|
23
|
+
pays restaurant in USDC via x402 ─────▶ books the order
|
|
24
|
+
◀── webhook order.confirmed
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @dunbackmeadow/commerce-sdk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You need Node 18 or later. React is optional and only needed for `@dunbackmeadow/commerce-sdk/react`.
|
|
34
|
+
|
|
35
|
+
## Credentials
|
|
36
|
+
|
|
37
|
+
Get your credentials in the **Dunback Developer Dashboard**
|
|
38
|
+
(<https://dunbackmeadow.com/developer>, or Menu → More… → Developer Dashboard
|
|
39
|
+
in the Dunback app):
|
|
40
|
+
|
|
41
|
+
1. Apply for developer access (individual or business). Dunback reviews it,
|
|
42
|
+
usually within 2 business days.
|
|
43
|
+
2. Create an **app**. Each app has a **sandbox** and a **production** environment.
|
|
44
|
+
3. In each environment, create the **API key** and set your **webhook URL**
|
|
45
|
+
and **allowed return hosts**.
|
|
46
|
+
|
|
47
|
+
| What | Example | Where it lives |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| API key | `dbk_test_app-k3m9x2q7w4ze_…` / `dbk_live_app-k3m9x2q7w4ze_…` | Your servers only. Never put it in a browser or a mobile app. Shown once when created. |
|
|
50
|
+
| Webhook signing secret | `whsec_…` | Your servers; used to verify `Dunback-Signature`. One per environment. |
|
|
51
|
+
| Allowed return hosts | `lu.ma` | Set in the dashboard; Stripe success and cancel URLs must be on these hosts. |
|
|
52
|
+
|
|
53
|
+
One key per app and environment at a time: to rotate, delete the key in the
|
|
54
|
+
dashboard and create a new one. A deleted key stops working within a minute.
|
|
55
|
+
|
|
56
|
+
The client picks the environment from the key:
|
|
57
|
+
|
|
58
|
+
| Key | Base URL |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `dbk_test_…` | `https://sandbox.dunbackmeadow.com/api/partner/v1` |
|
|
61
|
+
| `dbk_live_…` | `https://dunbackmeadow.com/api/partner/v1` |
|
|
62
|
+
|
|
63
|
+
In the sandbox:
|
|
64
|
+
|
|
65
|
+
- Stripe runs in test mode.
|
|
66
|
+
- Orders go to Dunback's test restaurants.
|
|
67
|
+
- USDC payments use small real amounts on Polygon. There is no testnet USDC support yet.
|
|
68
|
+
|
|
69
|
+
Check a key with `await dunback.me()`: it returns the app and environment.
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { DunbackClient } from "@dunbackmeadow/commerce-sdk";
|
|
75
|
+
|
|
76
|
+
const dunback = new DunbackClient({ apiKey: process.env.DUNBACK_API_KEY! });
|
|
77
|
+
|
|
78
|
+
// 1. Send the event and guest list
|
|
79
|
+
const request = await dunback.catering.create({
|
|
80
|
+
partnerReference: "luma:evt-AbC123",
|
|
81
|
+
event: { name: "Founders Dinner", startsAt: "2026-11-14T02:00:00Z", timeZone: "America/Los_Angeles" },
|
|
82
|
+
cuisine: "mexican",
|
|
83
|
+
deliveryAddress: { address1: "100 University Ave", city: "Palo Alto", state: "CA", zip: "94301" },
|
|
84
|
+
onsiteContact: { name: "Sam Host", phone: "+14155550100" },
|
|
85
|
+
host: { name: "Sam Host", email: "sam@example.com" },
|
|
86
|
+
attendees: [
|
|
87
|
+
{ name: "Ana", email: "ana@example.com", allergies: "peanuts", allergyConsent: true },
|
|
88
|
+
{ name: "Ben", phone: "+14155550101", allergies: "" },
|
|
89
|
+
{ name: "Cleo", dietaryPreferences: "vegetarian", allergyConsent: true },
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// 2. Options are ready in seconds. Use the webhook in production; polling works too.
|
|
94
|
+
const ready = await dunback.catering.waitForOptions(request.id);
|
|
95
|
+
for (const o of ready.options) {
|
|
96
|
+
console.log(o.title, o.price.totals.card, o.price.lines, o.allergyCoverage, o.unfedGuests);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 3. The host picks one, and you get payment links
|
|
100
|
+
const order = await dunback.catering.select(ready.id, { optionId: ready.options[0].id });
|
|
101
|
+
order.payment.stripe?.checkoutUrl; // card: Stripe Checkout
|
|
102
|
+
order.payment.usdc; // USDC: amount, address, EIP-681 link, x402Url
|
|
103
|
+
order.payment.hostedPaymentUrl; // Dunback page offering both
|
|
104
|
+
|
|
105
|
+
// 4. Wait for the order.confirmed webhook, or poll
|
|
106
|
+
const final = await dunback.orders.waitForSettlement(order.id);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Paying
|
|
110
|
+
|
|
111
|
+
| Method | Who it suits | How Dunback verifies |
|
|
112
|
+
| --- | --- | --- |
|
|
113
|
+
| **Card** (`payment.stripe.checkoutUrl`) | People | Signed Stripe webhook, plus a re-read of the Checkout Session: paid, USD, exact amount, this order |
|
|
114
|
+
| **USDC transfer** (`payment.usdc`) | People with a wallet, treasury tools | Polygon logs: a transfer of the exact tagged amount to the receiver is matched automatically. You can also call `orders.confirmUsdcPayment(id, txHash)` with any amount ≥ the total. |
|
|
115
|
+
| **x402** (`payOrderWithX402`) | Agents | EIP-3009 authorization, verified and settled on-chain by Dunback's x402 facilitator |
|
|
116
|
+
|
|
117
|
+
The **card total** includes card processing, so it is a little higher than
|
|
118
|
+
the **USDC total**. Both are shown in `price.totals`, and the line items are in
|
|
119
|
+
`price.lines`.
|
|
120
|
+
|
|
121
|
+
Payment links expire at `payment.expiresAt`. That is usually 60 minutes, and
|
|
122
|
+
always before the restaurant's order deadline. When a link expires, the host
|
|
123
|
+
can select an option again to get new links.
|
|
124
|
+
|
|
125
|
+
### Agent payment with x402
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { payOrderWithX402 } from "@dunbackmeadow/commerce-sdk";
|
|
129
|
+
|
|
130
|
+
const paid = await payOrderWithX402(order, {
|
|
131
|
+
address: account.address,
|
|
132
|
+
signTypedData: (td) => account.signTypedData(td), // viem
|
|
133
|
+
// signTypedData: (td) => wallet.signTypedData(td.domain, td.types, td.message), // ethers v6
|
|
134
|
+
}, { maxAmountUsdc: 500 });
|
|
135
|
+
// paid.status === "CONFIRMED"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Payment errors
|
|
139
|
+
|
|
140
|
+
Payment problems come back as `DunbackApiError` with a `code` you can show to the payer:
|
|
141
|
+
|
|
142
|
+
| code | Meaning |
|
|
143
|
+
| --- | --- |
|
|
144
|
+
| `payment_pending` | The transaction isn't confirmed yet. Retry in a few seconds. |
|
|
145
|
+
| `payment_not_found` | That transaction didn't send USDC to Dunback. |
|
|
146
|
+
| `payment_amount_short` | Less than the order total arrived. |
|
|
147
|
+
| `payment_already_used` | That transaction already paid another order. |
|
|
148
|
+
| `invalid_payment_signature`, `invalid_payment`, `insufficient_funds`, `settlement_failed` | The x402 authorization was rejected. |
|
|
149
|
+
| `order_deadline_passed` | It's too late for the restaurant to make the event time. |
|
|
150
|
+
|
|
151
|
+
`isPaymentError(e)` tells you whether an error is one of these.
|
|
152
|
+
|
|
153
|
+
Asynchronous card failures, such as a declined bank debit, arrive as the
|
|
154
|
+
`order.payment_failed` webhook. `order.payment.lastError` holds the message.
|
|
155
|
+
|
|
156
|
+
## Correcting the delivery address
|
|
157
|
+
|
|
158
|
+
Until an order is paid, you (or the payer, on the hosted payment page) can
|
|
159
|
+
correct the delivery address, on-site contact and note:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const updated = await dunback.orders.updateDelivery(order.id, {
|
|
163
|
+
deliveryAddress: { address1: "120 University Ave", address2: "Suite 300", city: "Palo Alto", state: "CA", zip: "94301" },
|
|
164
|
+
onsiteContact: { name: "Sam Lee", phone: "+15550000000" },
|
|
165
|
+
deliveryNotes: "Loading dock on Bryant St.", // replaces the current note
|
|
166
|
+
});
|
|
167
|
+
// updated.delivery shows the corrected details
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The price stays as quoted, so the new address must stay within about a mile
|
|
171
|
+
of the original and inside the restaurant's delivery area. Otherwise the call
|
|
172
|
+
fails with `422 address_moved` or `outside_delivery_area`; create a new
|
|
173
|
+
catering request instead. Addresses where Dunback hasn't launched delivery
|
|
174
|
+
fail with `422 delivery_area_not_launched`, both here and when you create a
|
|
175
|
+
catering request.
|
|
176
|
+
|
|
177
|
+
## Order lifecycle
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
AWAITING_PAYMENT ─▶ PAID ─▶ FULFILLING ─▶ CONFIRMED ─▶ (CANCELLED)
|
|
181
|
+
│ ├─▶ REFUNDED / REFUND_PENDING restaurant couldn't take it; buyer refunded
|
|
182
|
+
│ └─▶ NEEDS_ATTENTION Dunback support finishes it by hand
|
|
183
|
+
└─▶ EXPIRED / CANCELLED
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Webhooks
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import express from "express";
|
|
190
|
+
import { verifyWebhook } from "@dunbackmeadow/commerce-sdk";
|
|
191
|
+
|
|
192
|
+
app.post("/webhooks/dunback", express.raw({ type: "application/json" }), (req, res) => {
|
|
193
|
+
const event = verifyWebhook(req.body, req.header("Dunback-Signature"), process.env.DUNBACK_WEBHOOK_SECRET!);
|
|
194
|
+
// event.type, event.data (CateringRequest or Order)
|
|
195
|
+
res.sendStatus(200);
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
| Event | `data` |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `catering.options_ready`, `catering.no_options`, `catering.failed` | CateringRequest |
|
|
202
|
+
| `order.created`, `order.confirmed`, `order.payment_failed`, `order.expired`, `order.failed`, `order.needs_attention`, `order.cancelled`, `order.delivery_updated` | Order |
|
|
203
|
+
| `ping` | `{ object: "ping", appId, message }`: sent by **Send test event** in the dashboard |
|
|
204
|
+
|
|
205
|
+
Each webhook is signed as `t=<unix>,v1=<HMAC-SHA256(secret, "<t>.<body>")>`.
|
|
206
|
+
A non-2xx answer is retried after 1 s, 5 s and 25 s. Handle events
|
|
207
|
+
idempotently by `event.id`.
|
|
208
|
+
|
|
209
|
+
## Reliability
|
|
210
|
+
|
|
211
|
+
- POST helpers send an `Idempotency-Key`. Pass your own (for example, per button
|
|
212
|
+
click) to make retries safe across processes. Dunback keeps keys for 24 h.
|
|
213
|
+
- The client retries network errors and 5xx responses for GETs and for POSTs
|
|
214
|
+
that carry an idempotency key.
|
|
215
|
+
- `orders.get()` also re-checks Stripe, so it is safe to call right after a
|
|
216
|
+
Checkout redirect.
|
|
217
|
+
|
|
218
|
+
## Allergies
|
|
219
|
+
|
|
220
|
+
Guests write allergy notes in their own words. Dunback turns them into
|
|
221
|
+
allergens (the US "Big 9" plus a few more) and diets. A dish is offered to a
|
|
222
|
+
guest with an allergy only when the restaurant has **declared** that dish's
|
|
223
|
+
allergens and none of them match. If no dish is known to be safe for a guest,
|
|
224
|
+
the option lists that guest in `unfedGuests` rather than guessing. Show those
|
|
225
|
+
warnings to the host. Allergy-labelled portions are requested from the
|
|
226
|
+
restaurant in the delivery note.
|
|
227
|
+
|
|
228
|
+
**Consent.** Allergy and diet notes are health information, so each guest
|
|
229
|
+
must agree to share theirs. Send `allergyConsent: true` for every guest whose
|
|
230
|
+
`allergies` or `dietaryPreferences` says more than "none". Without it, the
|
|
231
|
+
request fails with `400 allergy_consent_required`, and `details.guests` lists
|
|
232
|
+
the guests concerned. `toDunbackAttendees()` sets `allergyConsent` for answers
|
|
233
|
+
to `DUNBACK_REGISTRATION_QUESTION`, whose wording asks for that consent.
|
|
234
|
+
|
|
235
|
+
**Retention.** Dunback deletes guest data 30 days after the event. Orders are
|
|
236
|
+
kept longer for accounting, without guest names.
|
|
237
|
+
|
|
238
|
+
## React components (optional)
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { DunbackCateringSettings, CateringOptionsPicker, DunbackOrderStatus } from "@dunbackmeadow/commerce-sdk/react";
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
These components only render data. Your backend makes every Dunback call.
|
|
245
|
+
|
|
246
|
+
## More
|
|
247
|
+
|
|
248
|
+
- Developer Dashboard and documentation: <https://dunbackmeadow.com/developer>
|
|
249
|
+
- [Luma integration guide](docs/LUMA_INTEGRATION_GUIDE.md)
|
|
250
|
+
- [API reference](docs/API_REFERENCE.md)
|
|
251
|
+
- [examples/luma-integration](examples/luma-integration): Express backend and host panel
|
|
252
|
+
- [examples/agent-x402-payment.ts](examples/agent-x402-payment.ts): an agent ordering and paying with x402
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { A as AppInfo, V as VenueLocation, C as CuisineQuery, a as Cuisine, b as CuisineCatalog, c as CateringRequestInput, d as CateringRequest, S as SelectOptionInput, O as Order, U as UpdateDeliveryInput, W as WebhookEvent } from './luma-Cza_vuOB.js';
|
|
2
|
+
export { e as ATTENDING_STATUSES, f as Address, g as AllergyCoverage, h as Attendee, B as BuildCateringRequestArgs, i as CateringItem, j as CateringOption, k as CateringPolicies, l as CateringRequestStatus, m as CateringServiceStyle, n as CuisineId, o as CustomCuisineId, D as DUNBACK_REGISTRATION_QUESTION, p as DunbackEventSettings, L as LumaEventLike, q as LumaGuestLike, r as OrderDelivery, s as OrderStatus, P as PingData, t as Price, u as PriceLine, v as StandardCuisineId, w as UnavailableReason, x as UnavailableReasonCode, y as UnfedGuests, z as UsdcPaymentInstructions, E as WebhookEventType, F as buildCateringRequest, G as canOrderFood, H as guestsWithUnsharedAllergies, I as toDunbackAddress, J as toDunbackAttendees, K as toVenueLocation } from './luma-Cza_vuOB.js';
|
|
3
|
+
|
|
4
|
+
/** Any non-2xx answer from the Partner API. */
|
|
5
|
+
declare class DunbackApiError extends Error {
|
|
6
|
+
/** Machine-readable, e.g. "invalid_request", "payment_amount_short", "order_deadline_passed". */
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly details?: unknown;
|
|
10
|
+
constructor(status: number, code: string, message: string, details?: unknown);
|
|
11
|
+
}
|
|
12
|
+
/** Codes a payer can act on (show the message and let them retry or pay another way). */
|
|
13
|
+
declare const PAYMENT_ERROR_CODES: Set<string>;
|
|
14
|
+
declare function isPaymentError(e: unknown): e is DunbackApiError;
|
|
15
|
+
|
|
16
|
+
interface DunbackClientOptions {
|
|
17
|
+
/**
|
|
18
|
+
* `dbk_test_<appId>_...` (sandbox) or `dbk_live_<appId>_...` (production), from
|
|
19
|
+
* the Developer Dashboard (https://dunbackmeadow.com/developer).
|
|
20
|
+
* Server-side only: never ship it to a browser.
|
|
21
|
+
*/
|
|
22
|
+
apiKey: string;
|
|
23
|
+
/** Default: the sandbox for a `dbk_test_` key, production for a `dbk_live_` key. */
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
/** Per-request timeout, ms. Default 30 000. */
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
fetch?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
declare const DEFAULT_BASE_URL = "https://dunbackmeadow.com/api/partner/v1";
|
|
30
|
+
declare const SANDBOX_BASE_URL = "https://sandbox.dunbackmeadow.com/api/partner/v1";
|
|
31
|
+
/**
|
|
32
|
+
* Server-side client for the Dunback Meadow Partner API.
|
|
33
|
+
*
|
|
34
|
+
* const dunback = new DunbackClient({ apiKey: process.env.DUNBACK_API_KEY! });
|
|
35
|
+
* await dunback.me(); // which app and environment the key belongs to
|
|
36
|
+
* const req = await dunback.catering.create({...});
|
|
37
|
+
* const ready = await dunback.catering.waitForOptions(req.id);
|
|
38
|
+
* const order = await dunback.catering.select(ready.id, { optionId: ready.options[0].id });
|
|
39
|
+
* // send order.payment.hostedPaymentUrl (or the Stripe / USDC links) to the payer
|
|
40
|
+
*/
|
|
41
|
+
declare class DunbackClient {
|
|
42
|
+
/** "test" (sandbox) or "live" (production), from the key. */
|
|
43
|
+
readonly mode: "live" | "test";
|
|
44
|
+
/** The app the key belongs to, from the key. */
|
|
45
|
+
readonly appId: string;
|
|
46
|
+
private readonly apiKey;
|
|
47
|
+
private readonly baseUrl;
|
|
48
|
+
private readonly timeoutMs;
|
|
49
|
+
private readonly fetchImpl;
|
|
50
|
+
constructor(opts: DunbackClientOptions);
|
|
51
|
+
/** Low-level request. Retries network errors and 5xx (POSTs only with an Idempotency-Key). */
|
|
52
|
+
request<T>(method: "GET" | "POST", path: string, body?: unknown, opts?: {
|
|
53
|
+
idempotencyKey?: string;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}): Promise<T>;
|
|
56
|
+
/** The app and environment this key belongs to. Handy as a "is my key working?" check. */
|
|
57
|
+
me(): Promise<AppInfo>;
|
|
58
|
+
/**
|
|
59
|
+
* Cuisines a host can pick when creating an event. Pass the venue to count
|
|
60
|
+
* only restaurants in its metro area (the ones that can cater there);
|
|
61
|
+
* without one, counts cover the whole platform. Pass `{ guests }` (expected
|
|
62
|
+
* guests) to count only restaurants able to cater that many: restaurants
|
|
63
|
+
* may limit guests per order or require a minimum order. See also
|
|
64
|
+
* cuisineCatalog().
|
|
65
|
+
*/
|
|
66
|
+
listCuisines(venue?: VenueLocation | null, query?: CuisineQuery): Promise<Cuisine[]>;
|
|
67
|
+
/** listCuisines() plus which metro area the counts are for (`metro` is null when Dunback doesn't serve the venue's area). */
|
|
68
|
+
cuisineCatalog(venue?: VenueLocation | null, query?: CuisineQuery): Promise<CuisineCatalog>;
|
|
69
|
+
readonly catering: {
|
|
70
|
+
/** Sends the guest list; Dunback's catering agent composes up to 3 priced options (async). */
|
|
71
|
+
create: (input: CateringRequestInput, opts?: {
|
|
72
|
+
idempotencyKey?: string;
|
|
73
|
+
}) => Promise<CateringRequest>;
|
|
74
|
+
get: (requestId: string) => Promise<CateringRequest>;
|
|
75
|
+
/** All catering requests made under one partnerReference (e.g. one Luma event), newest first. */
|
|
76
|
+
listByReference: (partnerReference: string) => Promise<CateringRequest[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Polls until composing is done (usually 5-30 s). Prefer the
|
|
79
|
+
* `catering.options_ready` webhook in production; this is for scripts and agents.
|
|
80
|
+
*/
|
|
81
|
+
waitForOptions: (requestId: string, { timeoutMs, intervalMs }?: {
|
|
82
|
+
timeoutMs?: number | undefined;
|
|
83
|
+
intervalMs?: number | undefined;
|
|
84
|
+
}) => Promise<CateringRequest>;
|
|
85
|
+
/** The host picks an option: creates the order and its payment links. */
|
|
86
|
+
select: (requestId: string, input: SelectOptionInput, opts?: {
|
|
87
|
+
idempotencyKey?: string;
|
|
88
|
+
}) => Promise<Order>;
|
|
89
|
+
};
|
|
90
|
+
readonly orders: {
|
|
91
|
+
/** Current state; also re-checks Stripe, so it is safe to poll after a checkout redirect. */
|
|
92
|
+
get: (orderId: string) => Promise<Order>;
|
|
93
|
+
/** Tell Dunback about a USDC transfer (optional: transfers of the exact amount are detected automatically). */
|
|
94
|
+
confirmUsdcPayment: (orderId: string, txHash: string) => Promise<Order>;
|
|
95
|
+
/**
|
|
96
|
+
* Corrects the delivery address, on-site contact and note while the order
|
|
97
|
+
* is AWAITING_PAYMENT (the payer can do the same on the hosted payment
|
|
98
|
+
* page). The price stays as quoted, so the new address must be in an area
|
|
99
|
+
* Dunback delivers to, inside the restaurant's delivery area and within
|
|
100
|
+
* about a mile of the original; otherwise it fails with 422
|
|
101
|
+
* `delivery_area_not_launched`, `outside_delivery_area` or `address_moved`
|
|
102
|
+
* (create a new catering request instead). Sends `order.delivery_updated`.
|
|
103
|
+
*/
|
|
104
|
+
updateDelivery: (orderId: string, input: UpdateDeliveryInput) => Promise<Order>;
|
|
105
|
+
/** Unpaid orders: cancels the payment links. Confirmed orders: cancels at the restaurant (before its order deadline) and refunds. */
|
|
106
|
+
cancel: (orderId: string, reason?: string) => Promise<Order>;
|
|
107
|
+
/** Polls until the order leaves AWAITING_PAYMENT/PAID/FULFILLING. */
|
|
108
|
+
waitForSettlement: (orderId: string, { timeoutMs, intervalMs }?: {
|
|
109
|
+
timeoutMs?: number | undefined;
|
|
110
|
+
intervalMs?: number | undefined;
|
|
111
|
+
}) => Promise<Order>;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Verifies a Dunback webhook and returns the parsed event.
|
|
117
|
+
*
|
|
118
|
+
* Dunback-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>
|
|
119
|
+
*
|
|
120
|
+
* Pass the RAW request body (bytes or string exactly as received), not
|
|
121
|
+
* re-serialized JSON. Throws if the signature is wrong or older than
|
|
122
|
+
* `toleranceSeconds` (replay protection).
|
|
123
|
+
*
|
|
124
|
+
* app.post("/dunback/webhook", express.raw({ type: "application/json" }), (req, res) => {
|
|
125
|
+
* const event = verifyWebhook(req.body, req.header("Dunback-Signature"), process.env.DUNBACK_WEBHOOK_SECRET!);
|
|
126
|
+
* ...
|
|
127
|
+
* res.sendStatus(200);
|
|
128
|
+
* });
|
|
129
|
+
*/
|
|
130
|
+
declare function verifyWebhook<T = WebhookEvent>(rawBody: string | Uint8Array, signatureHeader: string | undefined | null, secret: string, { toleranceSeconds, now }?: {
|
|
131
|
+
toleranceSeconds?: number;
|
|
132
|
+
now?: number;
|
|
133
|
+
}): T;
|
|
134
|
+
/** Builds a signature header (for tests of your webhook endpoint). */
|
|
135
|
+
declare function signWebhookPayload(rawBody: string, secret: string, t?: number): string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Paying a Dunback order from an agent wallet with x402 (USDC on Polygon,
|
|
139
|
+
* EIP-3009). Bring any signer: viem, ethers, a smart wallet, an MPC wallet...
|
|
140
|
+
*
|
|
141
|
+
* // viem
|
|
142
|
+
* const order = await payOrderWithX402(order, {
|
|
143
|
+
* address: account.address,
|
|
144
|
+
* signTypedData: (td) => walletClient.signTypedData({ account, ...td }),
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* // ethers v6
|
|
148
|
+
* signTypedData: (td) => wallet.signTypedData(td.domain, td.types, td.message)
|
|
149
|
+
*
|
|
150
|
+
* Dunback's x402 facilitator verifies the signature and settles the transfer
|
|
151
|
+
* on-chain; the response is the updated order (normally CONFIRMED).
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
interface TypedDataToSign {
|
|
155
|
+
domain: {
|
|
156
|
+
name: string;
|
|
157
|
+
version: string;
|
|
158
|
+
chainId: number;
|
|
159
|
+
verifyingContract: `0x${string}`;
|
|
160
|
+
};
|
|
161
|
+
types: {
|
|
162
|
+
TransferWithAuthorization: Array<{
|
|
163
|
+
name: string;
|
|
164
|
+
type: string;
|
|
165
|
+
}>;
|
|
166
|
+
};
|
|
167
|
+
primaryType: "TransferWithAuthorization";
|
|
168
|
+
message: {
|
|
169
|
+
from: string;
|
|
170
|
+
to: string;
|
|
171
|
+
value: string;
|
|
172
|
+
validAfter: string;
|
|
173
|
+
validBefore: string;
|
|
174
|
+
nonce: `0x${string}`;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
interface X402Signer {
|
|
178
|
+
address: string;
|
|
179
|
+
signTypedData: (td: TypedDataToSign) => Promise<string>;
|
|
180
|
+
}
|
|
181
|
+
declare function payOrderWithX402(order: Pick<Order, "id" | "payment">, signer: X402Signer, { fetch: fetchImpl, maxAmountUsdc }?: {
|
|
182
|
+
fetch?: typeof fetch;
|
|
183
|
+
maxAmountUsdc?: number;
|
|
184
|
+
}): Promise<Order>;
|
|
185
|
+
|
|
186
|
+
export { AppInfo, CateringRequest, CateringRequestInput, Cuisine, CuisineCatalog, CuisineQuery, DEFAULT_BASE_URL, DunbackApiError, DunbackClient, type DunbackClientOptions, Order, PAYMENT_ERROR_CODES, SANDBOX_BASE_URL, SelectOptionInput, type TypedDataToSign, UpdateDeliveryInput, VenueLocation, WebhookEvent, type X402Signer, isPaymentError, payOrderWithX402, signWebhookPayload, verifyWebhook };
|