@zappie/sdk 0.15.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +52 -0
  3. package/dist/cart/index.js +30 -39
  4. package/dist/cart/index.js.map +1 -1
  5. package/dist/cart/item.d.ts +1 -1
  6. package/dist/cart/quote-client.js +4 -20
  7. package/dist/cart/quote-client.js.map +1 -1
  8. package/dist/cart/quote-response.js +10 -5
  9. package/dist/cart/quote-response.js.map +1 -1
  10. package/dist/cart/storage.js +2 -0
  11. package/dist/cart/storage.js.map +1 -1
  12. package/dist/checkout/embed.d.ts +2 -0
  13. package/dist/checkout/index.d.ts +2 -0
  14. package/dist/checkout/react.d.ts +2 -0
  15. package/dist/checkout-defaults/index.d.ts +3 -0
  16. package/dist/{client-C47e44tl.d.ts → client-uRLLtZJU.d.ts} +1 -1
  17. package/dist/customer/client.js +34 -12
  18. package/dist/customer/client.js.map +1 -1
  19. package/dist/customer/index.d.ts +181 -10
  20. package/dist/customer/reorder.d.ts +40 -0
  21. package/dist/customer/reorder.js +61 -0
  22. package/dist/customer/reorder.js.map +6 -0
  23. package/dist/debug.js +1 -1
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +1 -1
  26. package/dist/integrations/index.d.ts +1 -1
  27. package/dist/internal/perk-hold.js +35 -0
  28. package/dist/internal/perk-hold.js.map +6 -0
  29. package/dist/internal/remembered-address.js +8 -2
  30. package/dist/internal/remembered-address.js.map +1 -1
  31. package/dist/internal.d.ts +1 -1
  32. package/dist/loyalty/cart.js +56 -0
  33. package/dist/loyalty/cart.js.map +6 -0
  34. package/dist/loyalty/client.js +89 -0
  35. package/dist/loyalty/client.js.map +6 -0
  36. package/dist/loyalty/index.d.ts +526 -0
  37. package/dist/loyalty/index.js +13 -0
  38. package/dist/loyalty/index.js.map +6 -0
  39. package/dist/loyalty/react.d.ts +116 -0
  40. package/dist/loyalty/react.js +200 -0
  41. package/dist/loyalty/react.js.map +6 -0
  42. package/dist/loyalty/release.js +43 -0
  43. package/dist/loyalty/release.js.map +6 -0
  44. package/dist/loyalty/types.js +1 -0
  45. package/dist/loyalty/types.js.map +6 -0
  46. package/dist/persist/catalogue.d.ts +2 -2
  47. package/dist/react/index.d.ts +2 -1
  48. package/dist/server/index.d.ts +1 -1
  49. package/dist/testing/index.d.ts +92 -4
  50. package/dist/testing/index.js +2 -0
  51. package/dist/testing/loyalty.js +110 -0
  52. package/dist/testing/loyalty.js.map +6 -0
  53. package/dist/transport/search.d.ts +1 -1
  54. package/dist/transport/selected-menu.d.ts +2 -2
  55. package/dist/{types-ooHA0lwH.d.ts → types-K01NHM_a.d.ts} +28 -3
  56. package/package.json +14 -2
@@ -1,3 +1,3 @@
1
- export { z as SelectedMenu, i as SelectedMenuRequest, j as SelectedMenuResponse, B as SelectedMenuTransport, D as createSelectedMenuReader, F as selectedMenu, G as selectedMenuKey } from '../client-C47e44tl.js';
1
+ export { z as SelectedMenu, i as SelectedMenuRequest, j as SelectedMenuResponse, B as SelectedMenuTransport, D as createSelectedMenuReader, F as selectedMenu, G as selectedMenuKey } from '../client-uRLLtZJU.js';
2
2
  import '../models-asoc6fS3.js';
3
- import '../types-ooHA0lwH.js';
3
+ import '../types-K01NHM_a.js';
@@ -75,12 +75,12 @@ type CartFulfilment = {
75
75
  /**
76
76
  * Stable identifiers for cart validation and quote issues you can handle in your UI.
77
77
  */
78
- 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";
78
+ 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" | "perk_invalid";
79
79
  /**
80
80
  * A suggested cart correction, including any option, quantity or fulfilment details it needs.
81
81
  */
82
82
  type CartFix = {
83
- action: "remove_line" | "accept_price" | "remove_promo" | "change_address" | "choose_region";
83
+ action: "remove_line" | "accept_price" | "remove_promo" | "change_address" | "choose_region" | "remove_perks";
84
84
  } | {
85
85
  action: "choose_option" | "choose_other_option";
86
86
  groupId: string;
@@ -147,10 +147,12 @@ type Quote = {
147
147
  /** The sum of `fees`, so you can show one fees line. Zero when there are none. Delivery is not included. */
148
148
  feesTotal: Money;
149
149
  delivery?: Money;
150
+ /** A perk's discount has code `perk` and the `redemptionId` it comes from. */
150
151
  discounts: {
151
152
  code: string;
152
153
  label: string;
153
154
  amount: Money;
155
+ redemptionId?: string;
154
156
  }[];
155
157
  total: Money;
156
158
  issues: CartIssue[];
@@ -177,6 +179,19 @@ type CartState = {
177
179
  quote?: Quote;
178
180
  issues: readonly CartIssue[];
179
181
  };
182
+ /**
183
+ * A loyalty perk the shopper redeemed into the bag. The quote prices it, and checkout spends it.
184
+ */
185
+ type AppliedPerk = Readonly<{
186
+ redemptionId: string;
187
+ perkId: string;
188
+ name: string;
189
+ pointsSpent: number;
190
+ /** When the reservation gives its points back if no order uses it. */
191
+ expiresAt: string;
192
+ /** What the perk gives, when the perk was applied from the perk list. */
193
+ reward?: "order_discount" | "free_item";
194
+ }>;
180
195
  /**
181
196
  * The current readonly cart view, including lines, branch, fulfilment and hydration state.
182
197
  */
@@ -188,6 +203,8 @@ type CartSnapshot = {
188
203
  readonly subtotal: Money | null;
189
204
  readonly fulfilment: CartFulfilment | null;
190
205
  readonly promoCode: string | null;
206
+ /** The perks redeemed into the bag, sent with each quote and checkout. Never on an in-venue order. */
207
+ readonly perks: readonly AppliedPerk[];
191
208
  readonly state: CartState;
192
209
  readonly issues: readonly CartIssue[];
193
210
  readonly isHydrated: boolean;
@@ -208,6 +225,11 @@ interface CartModule extends CartSnapshot {
208
225
  clear(): void;
209
226
  setFulfilment(fulfilment: CartFulfilment): void;
210
227
  setPromoCode(code: string | null): void;
228
+ /**
229
+ * Replace the perks the cart sends. Use `applyPerk` and `removePerk` from `@zappie/sdk/loyalty`,
230
+ * which redeem and cancel them with the API first.
231
+ */
232
+ setPerks(perks: readonly AppliedPerk[]): void;
211
233
  quote(opts?: {
212
234
  force?: boolean;
213
235
  }): Promise<Quote>;
@@ -224,6 +246,7 @@ interface CartModule extends CartSnapshot {
224
246
  lines: WireLine[];
225
247
  fulfilment: CartFulfilment;
226
248
  promo_code?: string;
249
+ perk_redemption_ids?: string[];
227
250
  menu_version: string;
228
251
  };
229
252
  }
@@ -273,6 +296,7 @@ type QuoteRequest = {
273
296
  lines: WireLine[];
274
297
  fulfilment?: WireFulfilment;
275
298
  promo_code?: string;
299
+ perk_redemption_ids?: string[];
276
300
  menu_version: string;
277
301
  };
278
302
  /**
@@ -338,6 +362,7 @@ type WireQuote = {
338
362
  code: string;
339
363
  label: string;
340
364
  amount: WireMoney;
365
+ redemption_id?: string;
341
366
  }[];
342
367
  total: WireMoney;
343
368
  issues: WireIssue[];
@@ -381,4 +406,4 @@ interface CartSyncAdapter {
381
406
  }>;
382
407
  }
383
408
 
384
- 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, CartIssueCode as e, CartState as f, CartIssue as g, WireQuote as h, CartFix as i, CartSnapshot as j, CartSyncAdapter as k, CartSyncDocument as l, WireFix as m, WireIssue as n, WireLine as o, WireMoney as p };
409
+ export type { AppliedPerk as A, CartLine as C, DeliveryAddress as D, QuoteRequest as Q, WireFulfilment as W, Quote as a, CartLineInput as b, CartFulfilment as c, CartModule as d, CartIssueCode as e, CartState as f, CartIssue as g, WireMoney as h, WireQuote as i, CartFix as j, CartSnapshot as k, CartSyncAdapter as l, CartSyncDocument as m, WireFix as n, WireIssue as o, WireLine as p };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/sdk",
3
- "version": "0.15.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,18 @@
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
+ },
90
+ "./loyalty": {
91
+ "types": "./dist/loyalty/index.d.ts",
92
+ "import": "./dist/loyalty/index.js"
93
+ },
94
+ "./loyalty/react": {
95
+ "types": "./dist/loyalty/react.d.ts",
96
+ "import": "./dist/loyalty/react.js"
97
+ },
86
98
  "./in-venue": {
87
99
  "types": "./dist/in-venue/index.d.ts",
88
100
  "import": "./dist/in-venue/index.js"
@@ -215,7 +227,7 @@
215
227
  "vite": "8.3.5"
216
228
  },
217
229
  "scripts": {
218
- "build": "tsup && tsup --config tsup.checkout.config.ts && tsup --config tsup.checkout-defaults.config.ts && tsup --config tsup.customer.config.ts && tsup --config tsup.in-venue.config.ts && tsup --config tsup.account.config.ts && tsup --config tsup.places.config.ts && tsup --config tsup.url.config.ts && tsup --config tsup.redirect.config.ts && tsup --config tsup.navigation.config.ts && tsup --config tsup.services.config.ts && tsup --config tsup.visits.config.ts && tsup --config tsup.pricing.config.ts && tsup --config tsup.display.config.ts && tsup --config tsup.branches.config.ts && tsup --config tsup.options.config.ts && tsup --config tsup.site-config.config.ts && tsup --config tsup.template.config.ts && tsup --config tsup.error-pages.config.ts && tsup --config tsup.site-error.config.ts && tsup --config tsup.site-closed.config.ts && tsup --config tsup.navigation-progress.config.ts && tsup --config tsup.receipts.config.ts && node ../../scripts/release-packages/build-modules.mjs --no-sources-content --unmapped=studio/index.js --unmapped=testing/index.js --unmapped=vite/index.js",
230
+ "build": "node ../../scripts/release-packages/build-declarations.mjs tsup.config.ts tsup.checkout.config.ts tsup.checkout-defaults.config.ts tsup.customer.config.ts tsup.loyalty.config.ts tsup.in-venue.config.ts tsup.account.config.ts tsup.places.config.ts tsup.url.config.ts tsup.redirect.config.ts tsup.navigation.config.ts tsup.services.config.ts tsup.visits.config.ts tsup.pricing.config.ts tsup.display.config.ts tsup.branches.config.ts tsup.options.config.ts tsup.site-config.config.ts tsup.template.config.ts tsup.error-pages.config.ts tsup.site-error.config.ts tsup.site-closed.config.ts tsup.navigation-progress.config.ts tsup.receipts.config.ts && node ../../scripts/release-packages/build-modules.mjs --no-sources-content --unmapped=studio/index.js --unmapped=testing/index.js --unmapped=vite/index.js",
219
231
  "test": "vitest run --root ../.. packages/sdk/test",
220
232
  "size": "node ../../scripts/release-packages/size-sdk.mjs && size-limit"
221
233
  }