@zappie/sdk 0.16.0 → 0.17.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @zappie/sdk
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d9f3c7d: Order details on storefronts. `CustomerOrder` gains `reference`, the order number such as `#1042` to show instead of the id, and the status type gains `delivery_failed`. Each timeline step has a `step`, `title` and `description`, and `next_step` names the step to come. The order also carries `ready_at`, `delivery_instructions`, `charges`, `discounts`, `payments`, `voided_lines` and `amount_due`. Each line has `voided`, `texts` and its share of each charge, and each choice its `group_name`. `watchOrder` passes every field through. `customer.payBalance(orderId, { useWalletBalance, idempotencyKey })` raises a payment for what is left and returns the payment page's `url`. `customer.reorder(orderId)` rebuilds the order as bag lines at today's prices, and `customer.receiptUrl(orderId)` gives the receipt's address for a download link. New `@zappie/sdk/customer/reorder` entry: `addReorderToCart(zappie, reorder)` puts those lines in the bag and returns the lines it added and every line it left out, with the issues that say why.
8
+
9
+ New `@zappie/foundations/order` entry with the order details parts, without styles: `Order.Root`, `Order.Reference`, `Order.Status`, `Order.Timeline`, `Order.Fulfilment`, `Order.Lines`, `Order.Totals`, `Order.Payments` and `Order.Actions` with `Order.Receipt`, `Order.PayBalance` and `Order.OrderAgain`, plus `OrderDetails`, which puts them in one default layout, `useCustomerOrder` and `orderTotals`.
10
+
11
+ The kit's order status shows the order number and every part of the order details through the foundations parts (order-status 2.0.0, order-page 1.1.0). The orders page names each order by its number (orders-page 1.0.1).
12
+
3
13
  ## 0.16.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -234,6 +234,31 @@ address, such as a table bill's `inVenue.receiptUrl(orderId)`. Hand the file to
234
234
  `navigator.share` where `canShareReceipt()` says the device can share it, or link
235
235
  to the address with `download`.
236
236
 
237
+ ### Orders
238
+
239
+ `customer.order(orderId)` reads an order, and `customer.watchOrder(orderId, {
240
+ onOrder })` follows it live. Show `order.reference`, such as `#1042`, as the
241
+ order number. The timeline's steps come with a `title` and a `description`
242
+ ready to show, and `next_step` names the step that comes next. `charges`,
243
+ `discounts`, `payments` and `voided_lines` itemise the money, and
244
+ `amount_due` says what is left to pay.
245
+
246
+ `customer.payBalance(orderId)` raises a payment for `amount_due` and returns
247
+ the payment page's `url`. Send the customer there. `customer.reorder(orderId)`
248
+ rebuilds the order as bag lines priced at today's menu, and
249
+ `addReorderToCart(zappie, reorder)` from `@zappie/sdk/customer/reorder` puts
250
+ them in the bag. It returns the lines
251
+ it added and every line it left out, with the issues that say why.
252
+
253
+ ```ts
254
+ import { addReorderToCart } from "@zappie/sdk/customer/reorder";
255
+
256
+ const { dropped } = await addReorderToCart(
257
+ zappie,
258
+ await customer.reorder(orderId),
259
+ );
260
+ ```
261
+
237
262
  Pass any redirect target read from a query parameter through `safeRedirect`.
238
263
  It keeps same-origin relative paths and returns your trusted fallback for an
239
264
  external, malformed or unsupported target.
@@ -141,8 +141,35 @@ function createCustomer(options = {}) {
141
141
  return request(`/me/orders${query.size ? `?${query}` : ""}`);
142
142
  },
143
143
  order: readOrder,
144
+ /**
145
+ * Raise a payment for what is left on the order, its `amount_due`, and return the payment page
146
+ * to send the customer to. An order paid in full answers `nothing_to_pay`, and one that ended
147
+ * answers `order_closed`. Each call makes its own Idempotency-Key unless you pass one.
148
+ */
149
+ payBalance: (id, pay = {}) => request(
150
+ `/me/orders/${encodeURIComponent(id)}/payments`,
151
+ {
152
+ method: "POST",
153
+ headers: {
154
+ "Content-Type": "application/json",
155
+ "Idempotency-Key": pay.idempotencyKey ?? crypto.randomUUID()
156
+ },
157
+ // JSON leaves out use_wallet_balance when it is undefined.
158
+ body: JSON.stringify({ use_wallet_balance: pay.useWalletBalance })
159
+ }
160
+ ),
161
+ /**
162
+ * Rebuild the order as bag lines at the same branch, priced at today's menu. It creates
163
+ * nothing. Lines the branch no longer sells as ordered come back in `dropped`. Put the lines in
164
+ * the bag with `addReorderToCart` from `@zappie/sdk/customer/reorder`.
165
+ */
166
+ reorder: (id) => request(`/me/orders/${encodeURIComponent(id)}/reorder`, {
167
+ method: "POST"
168
+ }),
144
169
  /** The order's receipt as a PDF File, named as the API names it. Needs the orders:read scope. */
145
170
  receipt: (id) => orderReceipt(base, id, fetcher),
171
+ /** The receipt's same-origin address, for a download link. */
172
+ receiptUrl: (id) => `${base}/me/orders/${encodeURIComponent(id)}/receipt`,
146
173
  watchOrder(id, watchOptions) {
147
174
  return watchOrder(base, id, readOrder, watchOptions);
148
175
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/customer/client.ts"],
4
- "mappings": ";AAEA,SAAS,+BAA+B;AACxC,SAAS,wBAAwB;AAGjC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,SAAS,oBAAoB;AACnD,SAAS,uBAAuB,4BAA4B;AAa5D,SAAS,kBAAkB;AAE3B,IAAM,wBAAwB;AAC9B,IAAM,uBAAuB;AAStB,SAAS,eAAe,UAAiC,CAAC,GAAG;AAClE,QAAM,QAAQ,QAAQ,gBAAgB,uBAAuB;AAAA,IAC3D;AAAA,IACA;AAAA,EACF;AACA,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,UAAU,QAAQ,SAAS,WAAW;AAC5C,MAAI,WAAW,QAAQ,mBAAmB;AAC1C,MAAI,QACF,QAAQ,oBAAoB,SACxB,YACA,WACE,kBACA;AAGR,QAAM,SAAS,MAAM;AACnB,QAAI,UAAU,WAAW;AACvB,oBAAc,UAAU,MAAM,IAAI;AAAA,IACpC;AAAA,EACF;AACA,SAAO;AACP,QAAM,YAAY,oBAAI,IAAsB;AAC5C,QAAM,SAAS,MAAM;AACnB,eAAW,YAAY,WAAW;AAChC,eAAS,OAAO,QAAQ;AAAA,IAC1B;AAAA,EACF;AACA,QAAM,SAAS,CAAC,MAA8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AAAA,MACpC;AAAA,QACE,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,UAChB,mBAAmB,IAAI,kBAAkB,OAAO,WAAW;AAAA,QAC7D;AAAA;AAAA,QAEA,MAAM,KAAK,UAAU,EAAE,oBAAoB,IAAI,iBAAiB,CAAC;AAAA,MACnE;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMF,SAAS,CAAC,OACR,QAAiB,cAAc,mBAAmB,EAAE,CAAC,YAAY;AAAA,MAC/D,QAAQ;AAAA,IACV,CAAC;AAAA;AAAA,IAEH,SAAS,CAAC,OAAe,aAAa,MAAM,IAAI,OAAO;AAAA;AAAA,IAEvD,YAAY,CAAC,OACX,GAAG,IAAI,cAAc,mBAAmB,EAAE,CAAC;AAAA,IAC7C,WAAW,IAAY,cAAiC;AACtD,aAAO,WAAW,MAAM,IAAI,WAAW,YAAY;AAAA,IACrD;AAAA,EACF;AACF;",
5
5
  "names": ["options"]
6
6
  }
@@ -1,4 +1,4 @@
1
- import { ZappieError } from '@zappie/sdk';
1
+ import { WireIssue, ZappieError } from '@zappie/sdk';
2
2
 
3
3
  /**
4
4
  * Whether the customer session is unchecked, anonymous or authenticated.
@@ -43,17 +43,67 @@ type Money = {
43
43
  currency: string;
44
44
  };
45
45
  /**
46
- * A selected option recorded on an order line, including its name, quantity and price.
46
+ * A selected option recorded on an order line, including its group, name, quantity and price.
47
47
  */
48
48
  type OrderChoice = {
49
49
  group_id: string;
50
+ /** The option group's name, such as "Spread". */
51
+ group_name: string;
50
52
  choice_id: string;
51
53
  name: string;
52
54
  price: Money;
53
55
  quantity: number;
54
56
  };
55
57
  /**
56
- * An ordered item with its recorded prices, selected options and optional variant and notes.
58
+ * What the customer typed for one text group on an order line.
59
+ */
60
+ type OrderText = {
61
+ group_id: string;
62
+ group_name: string;
63
+ value: string;
64
+ };
65
+ /**
66
+ * The kind of a charge on an order.
67
+ */
68
+ type OrderChargeCode = "service_charge" | "delivery" | "packaging" | "vat" | "small_order" | "platform_fee" | "other";
69
+ /**
70
+ * A line's share of a charge on the order. An included share is already in the line's price.
71
+ */
72
+ type OrderLineCharge = {
73
+ code: OrderChargeCode;
74
+ label: string;
75
+ amount: Money;
76
+ included: boolean;
77
+ };
78
+ /**
79
+ * A charge on the order. An included charge is already in the menu prices and adds nothing to the
80
+ * total. A waived charge shows at zero.
81
+ */
82
+ type OrderCharge = OrderLineCharge & {
83
+ waived: boolean;
84
+ };
85
+ /**
86
+ * A discount on the order. The amount is positive, like the order's discount.
87
+ */
88
+ type OrderDiscount = {
89
+ label: string;
90
+ /** The code the customer entered, when the discount came with one. */
91
+ promo_code?: string;
92
+ amount: Money;
93
+ };
94
+ /**
95
+ * A successful or refunded payment toward the order. It never carries a card number or a payment
96
+ * reference.
97
+ */
98
+ type OrderPayment = {
99
+ method: string;
100
+ amount: Money;
101
+ status: "successful" | "refunded";
102
+ paid_at: string;
103
+ };
104
+ /**
105
+ * An ordered item with its recorded prices, selected options, typed text and its share of each
106
+ * charge. `voided` is true only on a line in `voided_lines`.
57
107
  */
58
108
  type OrderLine = {
59
109
  item_id: string;
@@ -63,14 +113,48 @@ type OrderLine = {
63
113
  unit_price: Money;
64
114
  total: Money;
65
115
  notes?: string;
116
+ voided: boolean;
66
117
  choices: OrderChoice[];
118
+ texts: OrderText[];
119
+ charges: OrderLineCharge[];
67
120
  };
68
121
  /**
69
- * A customer order with fulfilment, payment totals, lines and a status timeline.
122
+ * Where an order stands.
123
+ */
124
+ type OrderStatus = "pending" | "accepted" | "ready" | "out_for_delivery" | "arrived" | "delivery_failed" | "completed" | "cancelled" | "rejected";
125
+ /**
126
+ * A detailed step. `ready_for_pickup`, `ready_for_rider_pickup`, `searching_for_rider`,
127
+ * `rider_assigned` and `waiting_for_pickup` read as the `ready` status, `picked_up` and
128
+ * `on_the_way` as `out_for_delivery`. The rest match the status of the same name.
129
+ */
130
+ type OrderStepCode = "pending" | "accepted" | "ready_for_pickup" | "ready_for_rider_pickup" | "searching_for_rider" | "rider_assigned" | "waiting_for_pickup" | "picked_up" | "on_the_way" | "arrived" | "completed" | "cancelled" | "rejected" | "delivery_failed";
131
+ /**
132
+ * A step the order took, with its name and one sentence on what it means, ready to show.
133
+ */
134
+ type OrderTimelineStep = {
135
+ /** The public status the step reads as. Several steps can share one. */
136
+ status: string;
137
+ step: OrderStepCode;
138
+ title: string;
139
+ description: string;
140
+ at: string;
141
+ };
142
+ /**
143
+ * The step the business moves the order to next.
144
+ */
145
+ type OrderNextStep = {
146
+ step: OrderStepCode;
147
+ title: string;
148
+ description: string;
149
+ };
150
+ /**
151
+ * A customer order with its number, fulfilment, charges, discounts, payments, lines and timeline.
70
152
  */
71
153
  type CustomerOrder = {
72
154
  id: string;
73
- status: "pending" | "accepted" | "ready" | "out_for_delivery" | "arrived" | "completed" | "cancelled" | "rejected";
155
+ /** The order number the business and the customer know the order by, such as "#1042". Show it instead of the id. */
156
+ reference: string;
157
+ status: OrderStatus;
74
158
  fulfilment: "delivery" | "pickup";
75
159
  branch_id?: string;
76
160
  currency: string;
@@ -80,16 +164,29 @@ type CustomerOrder = {
80
164
  total: Money;
81
165
  paid: boolean;
82
166
  amount_paid: Money;
167
+ /** What the customer can still pay with `payBalance`. Zero once the order is paid or has ended. */
168
+ amount_due: Money;
83
169
  lines: OrderLine[];
170
+ /** Lines the business took off the order after it was placed. No total counts them. */
171
+ voided_lines: OrderLine[];
172
+ /** Each charge in the order it was added, the delivery fee among them. */
173
+ charges: OrderCharge[];
174
+ discounts: OrderDiscount[];
175
+ /** Successful and refunded payments, oldest first. */
176
+ payments: OrderPayment[];
84
177
  placed_at: string;
85
178
  updated_at: string;
86
179
  scheduled_at?: string;
87
- timeline: {
88
- status: string;
89
- at: string;
90
- }[];
180
+ /** When the business expects the order to be ready. It stays after that time passes. */
181
+ ready_at?: string;
182
+ /** Every step the order has taken, oldest first. */
183
+ timeline: OrderTimelineStep[];
184
+ /** The step that comes next. Null once the order has ended and during the rider's steps. */
185
+ next_step: OrderNextStep | null;
91
186
  eta_minutes?: number;
92
187
  contact_phone?: string;
188
+ /** The customer's note for whoever brings the order. */
189
+ delivery_instructions?: string;
93
190
  dropoff_address?: {
94
191
  line1?: string;
95
192
  lat?: number;
@@ -100,6 +197,66 @@ type CustomerOrder = {
100
197
  method?: string;
101
198
  };
102
199
  };
200
+ /**
201
+ * The payment `payBalance` raised. Send the customer to `url` to finish it.
202
+ */
203
+ type OrderBalancePayment = {
204
+ payment_request_id: string;
205
+ amount: Money;
206
+ url: string;
207
+ };
208
+ /**
209
+ * Options for paying what is left on an order.
210
+ */
211
+ type PayBalanceOptions = {
212
+ /** Take what the customer's wallet holds first. Needs the wallet scope. */
213
+ useWalletBalance?: boolean;
214
+ /** Retry a failed attempt with the same key. Each call makes its own by default. */
215
+ idempotencyKey?: string;
216
+ };
217
+ /**
218
+ * An order line rebuilt for the bag at today's prices, as POST /quote takes it.
219
+ */
220
+ type ReorderLine = {
221
+ line_id: string;
222
+ item_id: string;
223
+ menu_id?: string;
224
+ variant_id?: string;
225
+ quantity: number;
226
+ options?: {
227
+ group_id: string;
228
+ choice_id: string;
229
+ quantity?: number;
230
+ }[];
231
+ inputs?: Record<string, string>;
232
+ note?: string;
233
+ name: string;
234
+ unit_price: Money;
235
+ options_total: Money;
236
+ line_total: Money;
237
+ };
238
+ /**
239
+ * An order line the branch no longer sells as it was ordered, with the issues that say why.
240
+ */
241
+ type ReorderDroppedLine = {
242
+ line_id: string;
243
+ /** The name on the original order. */
244
+ name: string;
245
+ quantity: number;
246
+ /** Each issue as the quote words it. */
247
+ issues: WireIssue[];
248
+ };
249
+ /**
250
+ * An order rebuilt as bag lines at the same branch, for the same fulfilment, priced at today's menu.
251
+ */
252
+ type Reorder = {
253
+ order_id: string;
254
+ branch_id: string;
255
+ fulfilment: "delivery" | "pickup";
256
+ menu_version: string;
257
+ lines: ReorderLine[];
258
+ dropped: ReorderDroppedLine[];
259
+ };
103
260
  /**
104
261
  * A page of customer orders and the cursor for the next page, or null at the end.
105
262
  */
@@ -159,8 +316,22 @@ declare function createCustomer(options?: CustomerClientOptions): {
159
316
  limit?: number;
160
317
  }): Promise<OrdersPage>;
161
318
  order: (id: string, signal?: AbortSignal) => Promise<CustomerOrder>;
319
+ /**
320
+ * Raise a payment for what is left on the order, its `amount_due`, and return the payment page
321
+ * to send the customer to. An order paid in full answers `nothing_to_pay`, and one that ended
322
+ * answers `order_closed`. Each call makes its own Idempotency-Key unless you pass one.
323
+ */
324
+ payBalance: (id: string, pay?: PayBalanceOptions) => Promise<OrderBalancePayment>;
325
+ /**
326
+ * Rebuild the order as bag lines at the same branch, priced at today's menu. It creates
327
+ * nothing. Lines the branch no longer sells as ordered come back in `dropped`. Put the lines in
328
+ * the bag with `addReorderToCart` from `@zappie/sdk/customer/reorder`.
329
+ */
330
+ reorder: (id: string) => Promise<Reorder>;
162
331
  /** The order's receipt as a PDF File, named as the API names it. Needs the orders:read scope. */
163
332
  receipt: (id: string) => Promise<File>;
333
+ /** The receipt's same-origin address, for a download link. */
334
+ receiptUrl: (id: string) => string;
164
335
  watchOrder(id: string, watchOptions: WatchOrderOptions): () => void;
165
336
  };
166
337
  /**
@@ -179,4 +350,4 @@ declare class CustomerError extends ZappieError {
179
350
  }
180
351
 
181
352
  export { CustomerError, createCustomer };
182
- export type { AuthState, CreateAddress, CustomerClient, CustomerClientOptions, CustomerListener, CustomerOrder, CustomerProfile, Money, OrderChoice, OrderLine, OrdersPage, SavedAddress, SessionCustomer, WatchOrderOptions };
353
+ export type { AuthState, CreateAddress, CustomerClient, CustomerClientOptions, CustomerListener, CustomerOrder, CustomerProfile, Money, OrderBalancePayment, OrderCharge, OrderChargeCode, OrderChoice, OrderDiscount, OrderLine, OrderLineCharge, OrderNextStep, OrderPayment, OrderStatus, OrderStepCode, OrderText, OrderTimelineStep, OrdersPage, PayBalanceOptions, Reorder, ReorderDroppedLine, ReorderLine, SavedAddress, SessionCustomer, WatchOrderOptions };
@@ -0,0 +1,40 @@
1
+ import { CartLine, Zappie } from '@zappie/sdk';
2
+ import { Reorder } from '@zappie/sdk/customer';
3
+
4
+ /**
5
+ * An order line that didn't make it into the bag, with the issues that say why.
6
+ */
7
+ type DroppedReorderLine = {
8
+ lineId: string;
9
+ /** The name on the original order. */
10
+ name: string;
11
+ quantity: number;
12
+ issues: {
13
+ code: string;
14
+ message: string;
15
+ }[];
16
+ };
17
+ /**
18
+ * What `addReorderToCart` put in the bag and what it left out.
19
+ */
20
+ type ReorderResult = {
21
+ added: CartLine[];
22
+ /** The lines the API dropped, then the lines the bag refused. Show them so the customer knows. */
23
+ dropped: DroppedReorderLine[];
24
+ };
25
+ /**
26
+ * Put a reorder's lines in the bag, next to what it already holds. A bag at another branch moves to
27
+ * the order's branch first, which keeps the lines that branch sells. A pickup order sets pickup
28
+ * when the bag has no fulfilment yet. A delivery order leaves the address to checkout.
29
+ *
30
+ * @param zappie - The storefront client, whose cart and menu take the lines.
31
+ * @param reorder - What `customer.reorder(orderId)` returned.
32
+ * @param options - A signal that stops it between lines.
33
+ * @returns The lines added, and every line left out with the issues that say why.
34
+ */
35
+ declare function addReorderToCart(zappie: Pick<Zappie, "cart" | "menu">, reorder: Reorder, options?: {
36
+ signal?: AbortSignal;
37
+ }): Promise<ReorderResult>;
38
+
39
+ export { addReorderToCart };
40
+ export type { DroppedReorderLine, ReorderResult };
@@ -0,0 +1,61 @@
1
+ // src/customer/reorder.ts
2
+ async function addReorderToCart(zappie, reorder, options = {}) {
3
+ const { cart } = zappie;
4
+ const branch = reorder.branch_id;
5
+ await cart.hydrate();
6
+ if (cart.getSnapshot().branchId !== branch) {
7
+ await cart.moveTo(branch);
8
+ }
9
+ const added = [];
10
+ const dropped = reorder.dropped.map((line) => ({
11
+ lineId: line.line_id,
12
+ name: line.name,
13
+ quantity: line.quantity,
14
+ issues: line.issues.map(({ code, message }) => ({ code, message }))
15
+ }));
16
+ for (const line of reorder.lines) {
17
+ options.signal?.throwIfAborted();
18
+ try {
19
+ const item = await zappie.menu.item(line.item_id, {
20
+ branch,
21
+ ...options.signal ? { signal: options.signal } : {}
22
+ });
23
+ added.push(
24
+ cart.add(item, {
25
+ quantity: line.quantity,
26
+ choices: (line.options ?? []).map((option) => ({
27
+ groupId: option.group_id,
28
+ choiceId: option.choice_id,
29
+ quantity: option.quantity ?? 1
30
+ })),
31
+ ...line.menu_id ? { menuId: line.menu_id } : {},
32
+ ...line.variant_id ? { variantId: line.variant_id } : {},
33
+ ...line.inputs ? { inputs: line.inputs } : {},
34
+ ...line.note ? { note: line.note } : {}
35
+ })
36
+ );
37
+ } catch (error) {
38
+ options.signal?.throwIfAborted();
39
+ const reasons = error.issues;
40
+ dropped.push({
41
+ lineId: line.line_id,
42
+ name: line.name,
43
+ quantity: line.quantity,
44
+ issues: reasons?.length ? reasons.map(({ code, message }) => ({ code, message })) : [
45
+ {
46
+ code: error.code ?? "item_unavailable",
47
+ message: `${line.name} isn't available right now.`
48
+ }
49
+ ]
50
+ });
51
+ }
52
+ }
53
+ if (reorder.fulfilment === "pickup" && !cart.getSnapshot().fulfilment) {
54
+ cart.setFulfilment({ type: "pickup", branchId: branch });
55
+ }
56
+ return { added, dropped };
57
+ }
58
+ export {
59
+ addReorderToCart
60
+ };
61
+ //# sourceMappingURL=reorder.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/customer/reorder.ts"],
4
+ "mappings": ";AAoCA,eAAsB,iBACpB,QACA,SACA,UAAoC,CAAC,GACb;AACxB,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,SAAS,QAAQ;AACvB,QAAM,KAAK,QAAQ;AACnB,MAAI,KAAK,YAAY,EAAE,aAAa,QAAQ;AAC1C,UAAM,KAAK,OAAO,MAAM;AAAA,EAC1B;AACA,QAAM,QAAoB,CAAC;AAC3B,QAAM,UAAgC,QAAQ,QAAQ,IAAI,CAAC,UAAU;AAAA,IACnE,QAAQ,KAAK;AAAA,IACb,MAAM,KAAK;AAAA,IACX,UAAU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,MACN,CAAC;AAAA,IACH;AAAA,EACF;AACA,MAAI,QAAQ,eAAe,YAAY,CAAC,KAAK,YAAY,EAAE,YAAY;AACrE,SAAK,cAAc,EAAE,MAAM,UAAU,UAAU,OAAO,CAAC;AAAA,EACzD;AACA,SAAO,EAAE,OAAO,QAAQ;AAC1B;",
5
+ "names": []
6
+ }
package/dist/debug.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/debug.ts
2
- var VERSION = true ? "0.16.0" : "0.0.0-development";
2
+ var VERSION = true ? "0.17.0" : "0.0.0-development";
3
3
  function installDebug(client) {
4
4
  if (typeof window === "undefined" || client.mode !== "test") {
5
5
  return;
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { ZappieError, isZappieError } from "./errors.js";
11
11
  export * from "./models.js";
12
12
  import { format, money } from "./money.js";
13
13
  import { RestTransport } from "./transport/rest.js";
14
- var VERSION = true ? "0.16.0" : "0.0.0-development";
14
+ var VERSION = true ? "0.17.0" : "0.0.0-development";
15
15
  export {
16
16
  API_VERSION,
17
17
  RestTransport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/sdk",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -83,6 +83,10 @@
83
83
  "types": "./dist/customer/react.d.ts",
84
84
  "import": "./dist/customer/react.js"
85
85
  },
86
+ "./customer/reorder": {
87
+ "types": "./dist/customer/reorder.d.ts",
88
+ "import": "./dist/customer/reorder.js"
89
+ },
86
90
  "./loyalty": {
87
91
  "types": "./dist/loyalty/index.d.ts",
88
92
  "import": "./dist/loyalty/index.js"