@zappie/sdk 0.1.4 → 0.1.6
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/CHANGELOG.md +12 -0
- package/dist/cart/branch.d.ts +26 -0
- package/dist/cart/branch.js +79 -0
- package/dist/cart/branch.js.map +7 -0
- package/dist/cart/index.js +1 -1
- package/dist/cart/index.js.map +2 -2
- package/dist/cart/item.d.ts +2 -1
- package/dist/cart/quote-client.js +48 -3
- package/dist/cart/quote-client.js.map +2 -2
- package/dist/cart/quote.d.ts +7 -2
- package/dist/client-Bm2cCYea.d.ts +400 -0
- package/dist/client.js +4 -2
- package/dist/client.js.map +2 -2
- package/dist/config/index.d.ts +11 -0
- package/dist/config.js.map +2 -2
- package/dist/debug.d.ts +2 -1
- package/dist/debug.js +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/integrations/index.d.ts +2 -1
- package/dist/internal.d.ts +2 -2
- package/dist/persist/catalogue.d.ts +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/server/index.d.ts +3 -1
- package/dist/site-config/types.js.map +1 -1
- package/dist/site-config/validate.js +32 -0
- package/dist/site-config/validate.js.map +2 -2
- package/dist/testing/index.d.ts +3 -1
- package/dist/transport/rest.js +6 -1
- package/dist/transport/rest.js.map +2 -2
- package/dist/transport/search.d.ts +2 -1
- package/dist/transport/selected-menu.d.ts +2 -1
- package/dist/types-CuDvfW9g.d.ts +380 -0
- package/package.json +5 -1
- package/dist/client-RFcLoZ04.d.ts +0 -764
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { d as Currency, M as Money, I as Item } from './models-Rg5kQUkv.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An item selection you submit to the cart, with optional quantity, choices, inputs and source menu.
|
|
5
|
+
*/
|
|
6
|
+
type CartLineInput = {
|
|
7
|
+
itemId: string;
|
|
8
|
+
/** The source menu the shopper selected. The SDK checks catalogue membership. */
|
|
9
|
+
menuId?: string;
|
|
10
|
+
quantity?: number;
|
|
11
|
+
choices?: {
|
|
12
|
+
groupId: string;
|
|
13
|
+
choiceId: string;
|
|
14
|
+
quantity?: number;
|
|
15
|
+
}[];
|
|
16
|
+
inputs?: Record<string, string>;
|
|
17
|
+
variantId?: string;
|
|
18
|
+
note?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A readonly cart line with its selection, local price estimate and time added.
|
|
22
|
+
*/
|
|
23
|
+
type CartLine = Readonly<{
|
|
24
|
+
id: string;
|
|
25
|
+
itemId: string;
|
|
26
|
+
/** The source menu the shopper selected. The SDK checks catalogue membership. */
|
|
27
|
+
menuId?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
quantity: number;
|
|
30
|
+
choices: readonly Readonly<{
|
|
31
|
+
groupId: string;
|
|
32
|
+
choiceId: string;
|
|
33
|
+
quantity: number;
|
|
34
|
+
}>[];
|
|
35
|
+
inputs: Readonly<Record<string, string>>;
|
|
36
|
+
variantId?: string;
|
|
37
|
+
note?: string;
|
|
38
|
+
unitPrice: Money;
|
|
39
|
+
lineSubtotal: Money;
|
|
40
|
+
addedAt: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* A cart delivery address with optional place coordinates and instructions.
|
|
44
|
+
*/
|
|
45
|
+
type DeliveryAddress = {
|
|
46
|
+
line1: string;
|
|
47
|
+
line2?: string;
|
|
48
|
+
city?: string;
|
|
49
|
+
placeId?: string;
|
|
50
|
+
coordinates?: {
|
|
51
|
+
lat: number;
|
|
52
|
+
lng: number;
|
|
53
|
+
};
|
|
54
|
+
instructions?: string;
|
|
55
|
+
};
|
|
56
|
+
/** A shopper's selection, distinct from the store's Fulfilment capabilities. */
|
|
57
|
+
type CartFulfilment = {
|
|
58
|
+
type: "pickup";
|
|
59
|
+
branchId: string;
|
|
60
|
+
scheduledFor?: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: "delivery";
|
|
63
|
+
branchId: string;
|
|
64
|
+
address: DeliveryAddress;
|
|
65
|
+
/** The delivery region you selected from the branch. */
|
|
66
|
+
deliveryRegionId?: string;
|
|
67
|
+
scheduledFor?: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "dine_in";
|
|
70
|
+
branchId: string;
|
|
71
|
+
table?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Stable identifiers for cart validation and quote issues you can handle in your UI.
|
|
75
|
+
*/
|
|
76
|
+
type CartIssueCode = "item_unavailable" | "item_not_found" | "option_unavailable" | "option_required" | "option_limit" | "quantity_limit" | "price_changed" | "branch_closed" | "fulfilment_unavailable" | "outside_delivery_zone" | "delivery_region_required" | "schedule_invalid" | "promo_invalid" | "promo_min_spend" | "min_order" | "menu_version_stale";
|
|
77
|
+
/**
|
|
78
|
+
* A suggested cart correction, including any option, quantity or fulfilment details it needs.
|
|
79
|
+
*/
|
|
80
|
+
type CartFix = {
|
|
81
|
+
action: "remove_line" | "accept_price" | "remove_promo" | "change_address" | "choose_region";
|
|
82
|
+
} | {
|
|
83
|
+
action: "choose_option" | "choose_other_option";
|
|
84
|
+
groupId: string;
|
|
85
|
+
} | {
|
|
86
|
+
action: "set_quantity";
|
|
87
|
+
quantity: number;
|
|
88
|
+
} | {
|
|
89
|
+
action: "schedule";
|
|
90
|
+
nextOpenAt?: string;
|
|
91
|
+
slots?: string[];
|
|
92
|
+
} | {
|
|
93
|
+
action: "switch_fulfilment";
|
|
94
|
+
types: CartFulfilment["type"][];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* A local or quoted cart issue with severity, display message and suggested fixes.
|
|
98
|
+
*/
|
|
99
|
+
type CartIssue = {
|
|
100
|
+
code: CartIssueCode;
|
|
101
|
+
severity: "blocking" | "warning" | "info";
|
|
102
|
+
lineId?: string;
|
|
103
|
+
groupId?: string;
|
|
104
|
+
message: string;
|
|
105
|
+
data?: Record<string, unknown>;
|
|
106
|
+
fixes: CartFix[];
|
|
107
|
+
source: "local" | "quote";
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Server-provided cart pricing, fees, discounts, issues and checkout readiness with an expiry.
|
|
111
|
+
*/
|
|
112
|
+
type Quote = {
|
|
113
|
+
/** Null prices mean the service could not split the subtotal across lines. */
|
|
114
|
+
lines: {
|
|
115
|
+
lineId: string;
|
|
116
|
+
unitPrice: Money | null;
|
|
117
|
+
total: Money | null;
|
|
118
|
+
/** Item identity echoed by the quote. */
|
|
119
|
+
itemId?: string;
|
|
120
|
+
/** Item name returned by the quote. */
|
|
121
|
+
name?: string;
|
|
122
|
+
/** Quantity priced by the quote. */
|
|
123
|
+
quantity?: number;
|
|
124
|
+
/** Authoritative option total, or null when the line could not be priced. */
|
|
125
|
+
optionsTotal?: Money | null;
|
|
126
|
+
/** Line status returned by the service. */
|
|
127
|
+
status?: string;
|
|
128
|
+
}[];
|
|
129
|
+
/** Whether the submitted menu version differs from the current version. */
|
|
130
|
+
menuVersionStale?: boolean;
|
|
131
|
+
/** Fulfilment details and arrival estimate returned by the service. */
|
|
132
|
+
fulfilment?: {
|
|
133
|
+
type: string;
|
|
134
|
+
scheduledFor: string | null;
|
|
135
|
+
etaMinutes?: number[];
|
|
136
|
+
deliveryRegionId?: string;
|
|
137
|
+
};
|
|
138
|
+
linesUnpriced?: boolean;
|
|
139
|
+
subtotal: Money;
|
|
140
|
+
fees: {
|
|
141
|
+
code: string;
|
|
142
|
+
label: string;
|
|
143
|
+
amount: Money;
|
|
144
|
+
}[];
|
|
145
|
+
delivery?: Money;
|
|
146
|
+
discounts: {
|
|
147
|
+
code: string;
|
|
148
|
+
label: string;
|
|
149
|
+
amount: Money;
|
|
150
|
+
}[];
|
|
151
|
+
total: Money;
|
|
152
|
+
issues: CartIssue[];
|
|
153
|
+
canCheckout: boolean;
|
|
154
|
+
checkout: {
|
|
155
|
+
ready: boolean;
|
|
156
|
+
reason?: "issues" | "customer_required";
|
|
157
|
+
};
|
|
158
|
+
menuVersion: string;
|
|
159
|
+
expiresAt: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* The cart validation and quoting state, with a quote or issues when available.
|
|
163
|
+
*/
|
|
164
|
+
type CartState = {
|
|
165
|
+
status: "ready";
|
|
166
|
+
} | {
|
|
167
|
+
status: "quoting";
|
|
168
|
+
} | {
|
|
169
|
+
status: "quoted";
|
|
170
|
+
quote: Quote;
|
|
171
|
+
} | {
|
|
172
|
+
status: "needs_attention";
|
|
173
|
+
quote?: Quote;
|
|
174
|
+
issues: readonly CartIssue[];
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* The current readonly cart view, including lines, branch, fulfilment and hydration state.
|
|
178
|
+
*/
|
|
179
|
+
type CartSnapshot = {
|
|
180
|
+
/** Selected branch remains available before a fulfilment mode is chosen. */
|
|
181
|
+
readonly branchId?: string | undefined;
|
|
182
|
+
readonly lines: readonly CartLine[];
|
|
183
|
+
readonly count: number;
|
|
184
|
+
readonly subtotal: Money | null;
|
|
185
|
+
readonly fulfilment: CartFulfilment | null;
|
|
186
|
+
readonly promoCode: string | null;
|
|
187
|
+
readonly state: CartState;
|
|
188
|
+
readonly issues: readonly CartIssue[];
|
|
189
|
+
readonly isHydrated: boolean;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Cart state and operations for editing lines, quoting, persistence and subscriptions.
|
|
193
|
+
*/
|
|
194
|
+
interface CartModule extends CartSnapshot {
|
|
195
|
+
validate(input: CartLineInput): {
|
|
196
|
+
ok: true;
|
|
197
|
+
} | {
|
|
198
|
+
ok: false;
|
|
199
|
+
issues: CartIssue[];
|
|
200
|
+
};
|
|
201
|
+
add(item: Item | string, input?: Omit<CartLineInput, "itemId">): CartLine;
|
|
202
|
+
update(lineId: string, patch: Partial<Omit<CartLineInput, "itemId">>): CartLine;
|
|
203
|
+
remove(lineId: string): void;
|
|
204
|
+
clear(): void;
|
|
205
|
+
setFulfilment(fulfilment: CartFulfilment): void;
|
|
206
|
+
setPromoCode(code: string | null): void;
|
|
207
|
+
quote(opts?: {
|
|
208
|
+
force?: boolean;
|
|
209
|
+
}): Promise<Quote>;
|
|
210
|
+
/** Handle interactive fixes by calling the option, address or time setter. */
|
|
211
|
+
applyFix(issue: CartIssue, fix?: CartFix): void;
|
|
212
|
+
moveTo(branchId: string): Promise<void>;
|
|
213
|
+
hydrate(): Promise<void>;
|
|
214
|
+
/** Attach browser listeners. Use the returned cleanup in your component effect. */
|
|
215
|
+
mount(): () => void;
|
|
216
|
+
dispose(): void;
|
|
217
|
+
subscribe(fn: () => void): () => void;
|
|
218
|
+
getSnapshot(): CartSnapshot;
|
|
219
|
+
toCheckoutPayload(): {
|
|
220
|
+
lines: WireLine[];
|
|
221
|
+
fulfilment: CartFulfilment;
|
|
222
|
+
promo_code?: string;
|
|
223
|
+
menu_version: string;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A cart line serialized with API field names for quote and checkout requests.
|
|
228
|
+
*/
|
|
229
|
+
type WireLine = {
|
|
230
|
+
line_id: string;
|
|
231
|
+
item_id: string;
|
|
232
|
+
menu_id?: string;
|
|
233
|
+
quantity: number;
|
|
234
|
+
variant_id?: string;
|
|
235
|
+
options: {
|
|
236
|
+
group_id: string;
|
|
237
|
+
choice_id: string;
|
|
238
|
+
quantity: number;
|
|
239
|
+
}[];
|
|
240
|
+
inputs: Record<string, string>;
|
|
241
|
+
note?: string;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* A fulfilment selection serialized with API field names, without its branch ID.
|
|
245
|
+
*/
|
|
246
|
+
type WireFulfilment = {
|
|
247
|
+
/** Selected delivery region in API field names. */
|
|
248
|
+
delivery_region_id?: string;
|
|
249
|
+
/** Delivery instructions sent alongside the address. */
|
|
250
|
+
instructions?: string;
|
|
251
|
+
type: CartFulfilment["type"];
|
|
252
|
+
scheduled_for?: string;
|
|
253
|
+
table?: string;
|
|
254
|
+
address?: {
|
|
255
|
+
line1: string;
|
|
256
|
+
line2?: string;
|
|
257
|
+
city?: string;
|
|
258
|
+
place_id?: string;
|
|
259
|
+
lat?: number;
|
|
260
|
+
lng?: number;
|
|
261
|
+
instructions?: string;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* The branch, menu version and cart contents you send for a server quote.
|
|
266
|
+
*/
|
|
267
|
+
type QuoteRequest = {
|
|
268
|
+
branch_id: string;
|
|
269
|
+
lines: WireLine[];
|
|
270
|
+
fulfilment?: WireFulfilment;
|
|
271
|
+
promo_code?: string;
|
|
272
|
+
menu_version: string;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* An API monetary amount in minor units with its currency code.
|
|
276
|
+
*/
|
|
277
|
+
type WireMoney = {
|
|
278
|
+
amount_minor: number;
|
|
279
|
+
currency: Currency;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* A suggested cart correction in API field names, before conversion to CartFix.
|
|
283
|
+
*/
|
|
284
|
+
type WireFix = {
|
|
285
|
+
action: CartFix["action"];
|
|
286
|
+
group_id?: string;
|
|
287
|
+
next_open_at?: string;
|
|
288
|
+
quantity?: number;
|
|
289
|
+
slots?: string[];
|
|
290
|
+
types?: CartFulfilment["type"][];
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* A server cart issue in API field names, before adding its quote source.
|
|
294
|
+
*/
|
|
295
|
+
type WireIssue = Omit<CartIssue, "source" | "lineId" | "groupId" | "fixes"> & {
|
|
296
|
+
line_id?: string;
|
|
297
|
+
group_id?: string;
|
|
298
|
+
fixes: WireFix[];
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* The server quote response in API field names, including prices, charges and checkout readiness.
|
|
302
|
+
*/
|
|
303
|
+
type WireQuote = {
|
|
304
|
+
/** Whether the submitted menu version is stale. */
|
|
305
|
+
menu_version_stale?: boolean;
|
|
306
|
+
/** Fulfilment details returned by the quote service. */
|
|
307
|
+
fulfilment?: {
|
|
308
|
+
type: string;
|
|
309
|
+
scheduled_for: string | null;
|
|
310
|
+
eta_minutes?: number[];
|
|
311
|
+
delivery_region_id?: string;
|
|
312
|
+
};
|
|
313
|
+
branch_id: string;
|
|
314
|
+
menu_version: string;
|
|
315
|
+
expires_at: string;
|
|
316
|
+
lines_unpriced?: boolean;
|
|
317
|
+
lines: {
|
|
318
|
+
line_id: string;
|
|
319
|
+
item_id?: string;
|
|
320
|
+
name?: string;
|
|
321
|
+
quantity?: number;
|
|
322
|
+
options_total?: WireMoney | null;
|
|
323
|
+
status?: string;
|
|
324
|
+
unit_price: WireMoney | null;
|
|
325
|
+
line_total: WireMoney | null;
|
|
326
|
+
}[];
|
|
327
|
+
subtotal: WireMoney;
|
|
328
|
+
charges: {
|
|
329
|
+
code: string;
|
|
330
|
+
label: string;
|
|
331
|
+
amount: WireMoney;
|
|
332
|
+
}[];
|
|
333
|
+
discounts: {
|
|
334
|
+
code: string;
|
|
335
|
+
label: string;
|
|
336
|
+
amount: WireMoney;
|
|
337
|
+
}[];
|
|
338
|
+
total: WireMoney;
|
|
339
|
+
issues: WireIssue[];
|
|
340
|
+
can_checkout: boolean;
|
|
341
|
+
checkout: {
|
|
342
|
+
ready: boolean;
|
|
343
|
+
reason?: "issues" | "customer_required";
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
/** A saved cart with its scope, revision and expiry. */
|
|
347
|
+
type CartSyncDocument = {
|
|
348
|
+
schemaVersion: 1;
|
|
349
|
+
store: string;
|
|
350
|
+
branchId: string;
|
|
351
|
+
revision: string;
|
|
352
|
+
expiresAt: string;
|
|
353
|
+
lines: WireLine[];
|
|
354
|
+
fulfilment: CartFulfilment | null;
|
|
355
|
+
promoCode: string | null;
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* A storage adapter for reading cart documents and writing them with revision checks.
|
|
359
|
+
* Writes return the saved document or the current document when revisions conflict.
|
|
360
|
+
*/
|
|
361
|
+
interface CartSyncAdapter {
|
|
362
|
+
read(scope: {
|
|
363
|
+
store: string;
|
|
364
|
+
branchId: string;
|
|
365
|
+
}, signal?: AbortSignal): Promise<CartSyncDocument | null>;
|
|
366
|
+
/** Write if the revision matches. Reuse the operation ID when you retry to avoid applying a change twice. */
|
|
367
|
+
write(document: Omit<CartSyncDocument, "revision" | "expiresAt">, options: {
|
|
368
|
+
expectedRevision: string | null;
|
|
369
|
+
operationId: string;
|
|
370
|
+
signal?: AbortSignal;
|
|
371
|
+
}): Promise<{
|
|
372
|
+
status: "saved";
|
|
373
|
+
document: CartSyncDocument;
|
|
374
|
+
} | {
|
|
375
|
+
status: "conflict";
|
|
376
|
+
document: CartSyncDocument;
|
|
377
|
+
}>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export type { CartLine as C, DeliveryAddress as D, QuoteRequest as Q, WireFulfilment as W, Quote as a, CartLineInput as b, CartFulfilment as c, CartModule as d, CartState as e, CartIssue as f, WireQuote as g, CartFix as h, CartIssueCode as i, CartSnapshot as j, CartSyncAdapter as k, CartSyncDocument as l, WireFix as m, WireIssue as n, WireLine as o, WireMoney as p };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zappie/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"types": "./dist/cart/item.d.ts",
|
|
38
38
|
"import": "./dist/cart/item.js"
|
|
39
39
|
},
|
|
40
|
+
"./cart/branch": {
|
|
41
|
+
"types": "./dist/cart/branch.d.ts",
|
|
42
|
+
"import": "./dist/cart/branch.js"
|
|
43
|
+
},
|
|
40
44
|
"./checkout": {
|
|
41
45
|
"types": "./dist/checkout/index.d.ts",
|
|
42
46
|
"import": "./dist/checkout/index.js"
|