@cimplify/sdk 0.103.0 → 0.104.1

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 (72) hide show
  1. package/dist/advanced.d.mts +3 -7
  2. package/dist/advanced.d.ts +3 -7
  3. package/dist/advanced.js +23 -23
  4. package/dist/advanced.mjs +4 -4
  5. package/dist/{client-DHBwvh7U.d.ts → catalogue-BlQ85Uma.d.mts} +492 -748
  6. package/dist/{client-BfpNjJ_a.d.mts → catalogue-C8TqOj9K.d.ts} +492 -748
  7. package/dist/{payment-H5LoIvXU.d.mts → checkout-BqK9XUz5.d.mts} +4338 -1495
  8. package/dist/{payment-H5LoIvXU.d.ts → checkout-BqK9XUz5.d.ts} +4338 -1495
  9. package/dist/{chunk-GOHSXBKW.mjs → chunk-33VCYWVL.mjs} +25 -1
  10. package/dist/{chunk-C2JSNJUC.mjs → chunk-6G3ANKQA.mjs} +1080 -369
  11. package/dist/{chunk-QOWPGS7Z.js → chunk-BWEIMKLF.js} +572 -17
  12. package/dist/{chunk-JSWJ4XDE.js → chunk-DQEXY542.js} +1630 -824
  13. package/dist/{chunk-CNN7Z2IP.js → chunk-EV2EVOYS.js} +27 -0
  14. package/dist/{chunk-VIL6IQCG.js → chunk-HYFA67A7.js} +1084 -373
  15. package/dist/{chunk-H7ACMHM3.mjs → chunk-L5SNEU2O.mjs} +553 -16
  16. package/dist/{chunk-JG5CQNCB.js → chunk-RBNBSQI7.mjs} +221 -19
  17. package/dist/{chunk-VNPEYLB2.mjs → chunk-SFUJMS5E.js} +265 -2
  18. package/dist/{chunk-M4URVKHE.mjs → chunk-U54CWUUT.mjs} +11 -2
  19. package/dist/{chunk-GERXZQSX.mjs → chunk-UFOWPN3D.mjs} +967 -582
  20. package/dist/{chunk-J6PNHDHL.mjs → chunk-V4457OKB.mjs} +1580 -785
  21. package/dist/{chunk-R6OLQ33I.js → chunk-WXREIBFW.js} +1041 -654
  22. package/dist/{chunk-NNG6IFFX.js → chunk-XAUSDMMZ.js} +13 -3
  23. package/dist/{client-DpqRobY9.d.mts → client-DhXeiUrf.d.ts} +2 -2
  24. package/dist/{client-Dqg2mc-7.d.ts → client-mXiUrV4X.d.mts} +2 -2
  25. package/dist/{index-C8uDqLwJ.d.ts → index-B0AdZvrM.d.mts} +9 -4
  26. package/dist/{index-e2y6AK70.d.mts → index-CK8Nk5uQ.d.ts} +9 -4
  27. package/dist/index-DPWI5XcU.d.ts +8 -0
  28. package/dist/index-DVfUh-ci.d.mts +8 -0
  29. package/dist/index.d.mts +34 -15
  30. package/dist/index.d.ts +34 -15
  31. package/dist/index.js +306 -133
  32. package/dist/index.mjs +7 -6
  33. package/dist/mock/cli.mjs +1494 -395
  34. package/dist/mock/library.js +1220 -361
  35. package/dist/mock/library.mjs +1220 -361
  36. package/dist/mock/msw.js +1220 -361
  37. package/dist/mock/msw.mjs +1220 -361
  38. package/dist/{price-C2RqscMY.d.ts → price-6hQIIac9.d.ts} +1 -1
  39. package/dist/{price-BvePgDXe.d.mts → price-BUDv1rI7.d.mts} +1 -1
  40. package/dist/react.d.mts +10 -5
  41. package/dist/react.d.ts +10 -5
  42. package/dist/react.js +279 -225
  43. package/dist/react.mjs +140 -86
  44. package/dist/{server-DoXIpSd7.d.ts → server-DJ0mSs9i.d.mts} +33 -57
  45. package/dist/{server-C7FyLdrz.d.mts → server-DSTX76Ki.d.ts} +33 -57
  46. package/dist/server.d.mts +3 -4
  47. package/dist/server.d.ts +3 -4
  48. package/dist/server.js +12 -11
  49. package/dist/server.mjs +6 -5
  50. package/dist/styles.css +2 -2
  51. package/dist/testing/msw.d.mts +2 -2
  52. package/dist/testing/msw.d.ts +2 -2
  53. package/dist/testing/msw.js +4 -4
  54. package/dist/testing/msw.mjs +3 -3
  55. package/dist/testing/suite.d.mts +5 -6
  56. package/dist/testing/suite.d.ts +5 -6
  57. package/dist/testing/suite.js +29 -28
  58. package/dist/testing/suite.mjs +10 -9
  59. package/dist/testing.d.mts +2217 -14
  60. package/dist/testing.d.ts +2217 -14
  61. package/dist/testing.js +173 -83
  62. package/dist/testing.mjs +28 -10
  63. package/dist/utils.d.mts +3 -4
  64. package/dist/utils.d.ts +3 -4
  65. package/dist/utils.js +35 -31
  66. package/dist/utils.mjs +2 -2
  67. package/package.json +9 -9
  68. package/registry/chat-widget.json +1 -1
  69. package/registry/order-history.json +1 -1
  70. package/registry/order-summary.json +1 -1
  71. package/dist/link-cuNVYc2s.d.mts +0 -297
  72. package/dist/link-cuNVYc2s.d.ts +0 -297
package/dist/react.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  "use client";
2
- import { splitGenUIContent, messagePreview } from './chunk-U4MW6PYU.mjs';
3
- export { messagePreview, splitGenUIContent } from './chunk-U4MW6PYU.mjs';
4
2
  import { DURATION_UNIT, getVariantDisplayName, INPUT_FIELD_TYPE, isMultiDayService, serviceBillingMultiplier, PRODUCT_TYPE, BOUNDARY_KIND, resolveGallery, chatMessageCards, RENDER_HINT, displaysGrossPrices, DEFAULT_CDN_BASE_URL } from './chunk-3V4DVXV3.mjs';
5
3
  export { getVariantDisplayName } from './chunk-3V4DVXV3.mjs';
6
- import { SESSION_CLAIMED, SESSION_CLEARED, createCimplifyClient, AUTH_TOKEN_CHANGED, MUTATION_ERROR } from './chunk-GERXZQSX.mjs';
7
- import { generateIdempotencyKey, ELEMENT_TYPES, EVENT_TYPES, startSignIn } from './chunk-J6PNHDHL.mjs';
8
- import './chunk-GOHSXBKW.mjs';
9
- import { parsePrice, formatMoney, formatPrice, getVariantUnitPrice, getProductCurrency, getUnitPriceAtQuantity, isOnSale, getDiscountPercentage, getBasePrice, getPriceRange, formatPriceRange } from './chunk-M4URVKHE.mjs';
10
- import { isSupportedCurrency, currencyCode, CimplifyError } from './chunk-VNPEYLB2.mjs';
4
+ import { chatRealtimeUpdateFromWire, SESSION_CLAIMED, SESSION_CLEARED, createCimplifyClient, AUTH_TOKEN_CHANGED, MUTATION_ERROR } from './chunk-UFOWPN3D.mjs';
5
+ import { splitGenUIContent, messagePreview } from './chunk-U4MW6PYU.mjs';
6
+ export { messagePreview, splitGenUIContent } from './chunk-U4MW6PYU.mjs';
7
+ import { ELEMENT_TYPES, EVENT_TYPES, generateIdempotencyKey, startSignIn } from './chunk-V4457OKB.mjs';
8
+ import { ORDER_TYPE, CHECKOUT_STATUS } from './chunk-33VCYWVL.mjs';
9
+ import { parsePrice, formatMoney, formatPrice, getVariantUnitPrice, getProductCurrency, getUnitPriceAtQuantity, isOnSale, getDiscountPercentage, getBasePrice, getPriceRange, formatPriceRange } from './chunk-U54CWUUT.mjs';
10
+ import { isSupportedCurrency, ErrorCode, currencyCode, CimplifyError } from './chunk-RBNBSQI7.mjs';
11
11
  import './chunk-3G6RQLXK.mjs';
12
12
  import React14, { createContext, lazy, memo, Suspense, useMemo, useContext, useRef, useCallback, useState, useEffect, useId, useSyncExternalStore } from 'react';
13
13
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -1494,25 +1494,28 @@ function statusToLabel(status) {
1494
1494
  if (!status) {
1495
1495
  return "";
1496
1496
  }
1497
- if (status === "preparing") {
1497
+ if (status === CHECKOUT_STATUS.PREPARING) {
1498
1498
  return "Preparing checkout";
1499
1499
  }
1500
- if (status === "recovering") {
1500
+ if (status === CHECKOUT_STATUS.REVIEWING_TERMS) {
1501
+ return "Review updated terms";
1502
+ }
1503
+ if (status === CHECKOUT_STATUS.RECOVERING) {
1501
1504
  return "Resuming payment";
1502
1505
  }
1503
- if (status === "processing") {
1506
+ if (status === CHECKOUT_STATUS.PROCESSING) {
1504
1507
  return "Processing payment";
1505
1508
  }
1506
- if (status === "awaiting_authorization") {
1509
+ if (status === CHECKOUT_STATUS.AWAITING_AUTHORIZATION) {
1507
1510
  return "Waiting for authorization";
1508
1511
  }
1509
- if (status === "polling") {
1512
+ if (status === CHECKOUT_STATUS.POLLING) {
1510
1513
  return "Confirming payment";
1511
1514
  }
1512
- if (status === "finalizing") {
1515
+ if (status === CHECKOUT_STATUS.FINALIZING) {
1513
1516
  return "Finalizing order";
1514
1517
  }
1515
- if (status === "success") {
1518
+ if (status === CHECKOUT_STATUS.SUCCESS) {
1516
1519
  return "Payment complete";
1517
1520
  }
1518
1521
  return "Payment failed";
@@ -1521,6 +1524,9 @@ function CimplifyCheckout({
1521
1524
  client,
1522
1525
  businessId,
1523
1526
  cartId,
1527
+ intentId,
1528
+ hostedSessionId,
1529
+ initialTerms,
1524
1530
  locationId,
1525
1531
  linkUrl,
1526
1532
  orderTypes,
@@ -1534,14 +1540,14 @@ function CimplifyCheckout({
1534
1540
  className
1535
1541
  }) {
1536
1542
  const resolvedOrderTypes = useMemo(
1537
- () => orderTypes && orderTypes.length > 0 ? orderTypes : ["pickup", "delivery"],
1543
+ () => orderTypes && orderTypes.length > 0 ? orderTypes : [ORDER_TYPE.PICKUP, ORDER_TYPE.DELIVERY],
1538
1544
  [orderTypes]
1539
1545
  );
1540
1546
  const resolvedDefaultOrderType = useMemo(() => {
1541
1547
  if (defaultOrderType && resolvedOrderTypes.includes(defaultOrderType)) {
1542
1548
  return defaultOrderType;
1543
1549
  }
1544
- return resolvedOrderTypes[0] || "pickup";
1550
+ return resolvedOrderTypes[0] || ORDER_TYPE.PICKUP;
1545
1551
  }, [defaultOrderType, resolvedOrderTypes]);
1546
1552
  const [orderType, setOrderType] = useState(resolvedDefaultOrderType);
1547
1553
  const [status, setStatus] = useState(null);
@@ -1567,7 +1573,12 @@ function CimplifyCheckout({
1567
1573
  displayCurrency: cimplifyCtx.displayCurrency,
1568
1574
  convertPrice: cimplifyCtx.convertPrice
1569
1575
  };
1570
- }, [cimplifyCtx?.fxRate, cimplifyCtx?.displayCurrency, cimplifyCtx?.baseCurrency, cimplifyCtx?.convertPrice]);
1576
+ }, [
1577
+ cimplifyCtx?.fxRate,
1578
+ cimplifyCtx?.displayCurrency,
1579
+ cimplifyCtx?.baseCurrency,
1580
+ cimplifyCtx?.convertPrice
1581
+ ]);
1571
1582
  const fxOptionsRef = useRef(fxOptions);
1572
1583
  fxOptionsRef.current = fxOptions;
1573
1584
  const resolvedCartRef = useRef(resolvedCart);
@@ -1580,11 +1591,9 @@ function CimplifyCheckout({
1580
1591
  onStatusChange?.(nextStatus, context);
1581
1592
  }
1582
1593
  );
1583
- const fireError = React14.useEffectEvent(
1584
- (error) => {
1585
- onError?.(error);
1586
- }
1587
- );
1594
+ const fireError = React14.useEffectEvent((error) => {
1595
+ onError?.(error);
1596
+ });
1588
1597
  useEffect(() => {
1589
1598
  if (!resolvedOrderTypes.includes(orderType)) {
1590
1599
  setOrderType(resolvedDefaultOrderType);
@@ -1602,20 +1611,23 @@ function CimplifyCheckout({
1602
1611
  let cancelled = false;
1603
1612
  async function bootstrap() {
1604
1613
  const needsBusinessResolve = !businessId;
1605
- const needsCartResolve = !cartId;
1614
+ const needsCartResolve = !cartId && !intentId;
1606
1615
  if (!needsBusinessResolve && !needsCartResolve) {
1607
1616
  if (!cancelled) {
1608
1617
  setResolvedBusinessId(businessId || null);
1609
- setResolvedCartId(cartId || null);
1618
+ setResolvedCartId(intentId ? null : cartId || null);
1619
+ if (intentId) setResolvedCart(null);
1610
1620
  setIsInitializing(false);
1611
1621
  setErrorMessage(null);
1612
1622
  }
1613
- client.cart.get().then((cartResult) => {
1614
- if (!cancelled && cartResult.ok && cartResult.value) {
1615
- setResolvedCart(cartResult.value);
1616
- }
1617
- }).catch(() => {
1618
- });
1623
+ if (!intentId) {
1624
+ client.cart.get().then((cartResult) => {
1625
+ if (!cancelled && cartResult.ok && cartResult.value) {
1626
+ setResolvedCart(cartResult.value);
1627
+ }
1628
+ }).catch(() => {
1629
+ });
1630
+ }
1619
1631
  return;
1620
1632
  }
1621
1633
  if (!cancelled) {
@@ -1633,13 +1645,13 @@ function CimplifyCheckout({
1633
1645
  setResolvedCartId(null);
1634
1646
  setErrorMessage(message);
1635
1647
  setIsInitializing(false);
1636
- fireError({ code: "BUSINESS_ID_REQUIRED", message });
1648
+ fireError({ code: ErrorCode.BUSINESS_ID_REQUIRED, message });
1637
1649
  }
1638
1650
  return;
1639
1651
  }
1640
1652
  }
1641
- let nextCartId = cartId ?? null;
1642
- if (!nextCartId) {
1653
+ let nextCartId = intentId ? null : cartId ?? null;
1654
+ if (!intentId && !nextCartId) {
1643
1655
  const cartResult = await client.cart.get();
1644
1656
  if (!cartResult.ok || !cartResult.value?.id || cartResult.value.items.length === 0) {
1645
1657
  if (!cancelled) {
@@ -1648,7 +1660,7 @@ function CimplifyCheckout({
1648
1660
  setResolvedCartId(null);
1649
1661
  setErrorMessage(message);
1650
1662
  setIsInitializing(false);
1651
- fireError({ code: "CART_EMPTY", message });
1663
+ fireError({ code: ErrorCode.CART_EMPTY, message });
1652
1664
  }
1653
1665
  return;
1654
1666
  }
@@ -1668,7 +1680,7 @@ function CimplifyCheckout({
1668
1680
  return () => {
1669
1681
  cancelled = true;
1670
1682
  };
1671
- }, [businessId, cartId, client]);
1683
+ }, [businessId, cartId, client, intentId]);
1672
1684
  useEffect(() => {
1673
1685
  return () => {
1674
1686
  isMountedRef.current = false;
@@ -1677,31 +1689,36 @@ function CimplifyCheckout({
1677
1689
  };
1678
1690
  }, []);
1679
1691
  const handleSubmit = React14.useEffectEvent(async () => {
1680
- if (isSubmitting || isInitializing || !resolvedCartId) {
1681
- if (!resolvedCartId && !isInitializing) {
1682
- const message = "Your cart is empty. Add items before checkout.";
1692
+ if (isSubmitting || isInitializing || !resolvedCartId && !intentId) {
1693
+ if (!resolvedCartId && !intentId && !isInitializing) {
1694
+ const message = "A cart or purchase intent is required before checkout.";
1683
1695
  setErrorMessage(message);
1684
- fireError({ code: "CART_EMPTY", message });
1696
+ fireError({ code: ErrorCode.CHECKOUT_AUTHORITY_REQUIRED, message });
1685
1697
  }
1686
1698
  return;
1687
1699
  }
1688
1700
  setErrorMessage(null);
1689
1701
  setIsSubmitting(true);
1690
- emitStatus("preparing", { display_text: statusToLabel("preparing") });
1702
+ emitStatus(CHECKOUT_STATUS.PREPARING, {
1703
+ display_text: statusToLabel(CHECKOUT_STATUS.PREPARING)
1704
+ });
1691
1705
  if (!elementsRef.current) {
1692
1706
  const message = "Checkout is still initializing. Please try again.";
1693
1707
  setErrorMessage(message);
1694
- fireError({ code: "CHECKOUT_NOT_READY", message });
1708
+ fireError({ code: ErrorCode.CHECKOUT_NOT_READY, message });
1695
1709
  setIsSubmitting(false);
1696
1710
  return;
1697
1711
  }
1698
1712
  const checkout = elementsRef.current.processCheckout({
1699
- cart_id: resolvedCartId,
1713
+ cart_id: intentId ? void 0 : resolvedCartId ?? void 0,
1714
+ intent_id: intentId,
1715
+ hosted_session_id: hostedSessionId,
1716
+ initial_terms: initialTerms,
1700
1717
  location_id: locationId ?? client.getLocationId() ?? void 0,
1701
1718
  order_type: orderType,
1702
1719
  enroll_in_link: enrollInLink,
1703
1720
  on_status_change: emitStatus,
1704
- pay_currency: fxOptions?.displayCurrency
1721
+ pay_currency: intentId ? void 0 : fxOptions?.displayCurrency
1705
1722
  });
1706
1723
  activeCheckoutRef.current = checkout;
1707
1724
  try {
@@ -1710,7 +1727,7 @@ function CimplifyCheckout({
1710
1727
  onComplete(result);
1711
1728
  return;
1712
1729
  }
1713
- const code = result.error?.code || "CHECKOUT_FAILED";
1730
+ const code = result.error?.code || ErrorCode.CHECKOUT_FAILED;
1714
1731
  const message = result.error?.message || "Payment failed.";
1715
1732
  setErrorMessage(message);
1716
1733
  fireError({ code, message });
@@ -1731,27 +1748,30 @@ function CimplifyCheckout({
1731
1748
  linkUrl
1732
1749
  });
1733
1750
  elementsRef.current = elements;
1734
- const checkout = elements.create("checkout", {
1751
+ const checkout = elements.create(ELEMENT_TYPES.CHECKOUT, {
1735
1752
  orderTypes: resolvedOrderTypes,
1736
1753
  defaultOrderType: resolvedDefaultOrderType,
1737
- submitLabel
1754
+ submitLabel,
1755
+ intentId,
1756
+ hostedSessionId,
1757
+ initialTerms
1738
1758
  });
1739
1759
  if (checkoutMountRef.current) {
1740
1760
  checkout.mount(checkoutMountRef.current);
1741
1761
  }
1742
- checkout.on("ready", () => {
1762
+ checkout.on(EVENT_TYPES.READY, () => {
1743
1763
  const cart = resolvedCartRef.current;
1744
1764
  if (cart) {
1745
1765
  checkout.setCart(transformToCheckoutCart(cart, fxOptionsRef.current));
1746
1766
  }
1747
1767
  });
1748
- checkout.on("order_type_changed", (data) => {
1768
+ checkout.on(EVENT_TYPES.ORDER_TYPE_CHANGED, (data) => {
1749
1769
  const typed = data;
1750
1770
  if (typed.orderType) {
1751
1771
  setOrderType(typed.orderType);
1752
1772
  }
1753
1773
  });
1754
- checkout.on("request_submit", () => {
1774
+ checkout.on(EVENT_TYPES.REQUEST_SUBMIT, () => {
1755
1775
  void handleSubmit();
1756
1776
  });
1757
1777
  return () => {
@@ -1765,11 +1785,14 @@ function CimplifyCheckout({
1765
1785
  resolvedBusinessId,
1766
1786
  resolvedOrderTypes,
1767
1787
  resolvedDefaultOrderType,
1768
- submitLabel
1788
+ submitLabel,
1789
+ intentId,
1790
+ hostedSessionId,
1791
+ initialTerms
1769
1792
  ]);
1770
1793
  useEffect(() => {
1771
1794
  if (!resolvedCart || !elementsRef.current) return;
1772
- const checkoutElement = elementsRef.current.getElement("checkout");
1795
+ const checkoutElement = elementsRef.current.getElement(ELEMENT_TYPES.CHECKOUT);
1773
1796
  if (checkoutElement) {
1774
1797
  checkoutElement.setCart(transformToCheckoutCart(resolvedCart, fxOptions));
1775
1798
  }
@@ -1778,7 +1801,7 @@ function CimplifyCheckout({
1778
1801
  if (isInitializing) {
1779
1802
  return /* @__PURE__ */ jsx("div", { className, "data-cimplify-checkout": "", children: /* @__PURE__ */ jsx("p", { "data-cimplify-status": "", style: { fontSize: 13, color: colors.textSecondary }, children: "Preparing checkout..." }) });
1780
1803
  }
1781
- if (!resolvedBusinessId || !resolvedCartId) {
1804
+ if (!resolvedBusinessId || !resolvedCartId && !intentId) {
1782
1805
  return /* @__PURE__ */ jsx("div", { className, "data-cimplify-checkout": "", children: /* @__PURE__ */ jsx("p", { "data-cimplify-error": "", style: { fontSize: 13, color: colors.error }, children: errorMessage || "Unable to initialize checkout. Please refresh and try again." }) });
1783
1806
  }
1784
1807
  return /* @__PURE__ */ jsxs("div", { className, "data-cimplify-checkout": "", children: [
@@ -1796,7 +1819,14 @@ function CimplifyCheckout({
1796
1819
  }
1797
1820
  ),
1798
1821
  /* @__PURE__ */ jsx("div", { "data-cimplify-section": "checkout", children: /* @__PURE__ */ jsx("div", { ref: checkoutMountRef }) }),
1799
- status && /* @__PURE__ */ jsx("p", { "data-cimplify-status": "", style: { marginTop: 8, fontSize: 13, color: colors.textSecondary }, children: statusText || statusToLabel(status) }),
1822
+ status && /* @__PURE__ */ jsx(
1823
+ "p",
1824
+ {
1825
+ "data-cimplify-status": "",
1826
+ style: { marginTop: 8, fontSize: 13, color: colors.textSecondary },
1827
+ children: statusText || statusToLabel(status)
1828
+ }
1829
+ ),
1800
1830
  errorMessage && /* @__PURE__ */ jsx("p", { "data-cimplify-error": "", style: { marginTop: 8, fontSize: 13, color: colors.error }, children: errorMessage })
1801
1831
  ] });
1802
1832
  }
@@ -3288,8 +3318,7 @@ var STATUS_TONE2 = {
3288
3318
  picked_up: "positive",
3289
3319
  served: "positive",
3290
3320
  completed: "positive",
3291
- cancelled: "muted",
3292
- refunded: "muted"
3321
+ cancelled: "muted"
3293
3322
  };
3294
3323
  var PAYMENT_TONE = {
3295
3324
  paid: "positive",
@@ -4589,9 +4618,12 @@ function useCategories(options = {}) {
4589
4618
  const { data, isLoading, error, refetch } = categoriesQuery(options);
4590
4619
  return { categories: data ?? [], isLoading, error, refetch };
4591
4620
  }
4592
- var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "cancelled", "refunded"]);
4621
+ var TERMINAL_STATUSES = {
4622
+ completed: true,
4623
+ cancelled: true
4624
+ };
4593
4625
  function isTerminalOrderStatus(status) {
4594
- return TERMINAL_STATUSES.has(status);
4626
+ return Object.prototype.hasOwnProperty.call(TERMINAL_STATUSES, status);
4595
4627
  }
4596
4628
  var orderCache = /* @__PURE__ */ new Map();
4597
4629
  var orderInflight = /* @__PURE__ */ new Map();
@@ -4684,7 +4716,7 @@ function useOrder(orderId, options = {}) {
4684
4716
  useEffect(() => {
4685
4717
  void load(false);
4686
4718
  }, [load]);
4687
- const isTerminal = order ? TERMINAL_STATUSES.has(order.status) : false;
4719
+ const isTerminal = order ? isTerminalOrderStatus(order.status) : false;
4688
4720
  useEffect(() => {
4689
4721
  if (!poll || !enabled || normalizedOrderId.length === 0 || isTerminal) {
4690
4722
  return;
@@ -6139,7 +6171,7 @@ function useChat(options = {}) {
6139
6171
  if (!c) return;
6140
6172
  const last = lastConfirmedMessage();
6141
6173
  const result = await c.support.getMessages({
6142
- after: last?.created_at,
6174
+ afterSequence: last?.sequence,
6143
6175
  limit: 50
6144
6176
  });
6145
6177
  if (result.ok && result.value.length > 0) {
@@ -6182,9 +6214,9 @@ function useChat(options = {}) {
6182
6214
  );
6183
6215
  return mergeMessages(snapshot, extras);
6184
6216
  });
6185
- aiEnabledRef.current = result.value.conversation.ai_enabled;
6186
- setHumanRequested(result.value.conversation.needs_human_review ?? false);
6187
- setSeenAt(result.value.conversation.team_read_at ?? null);
6217
+ aiEnabledRef.current = result.value.conversation.ai_mode === "auto";
6218
+ setHumanRequested(result.value.conversation.ai_mode === "off");
6219
+ setSeenAt(null);
6188
6220
  setMayHaveOlder(result.value.messages.length >= 50);
6189
6221
  }, []);
6190
6222
  const connectWebSocket = useCallback(() => {
@@ -6212,23 +6244,36 @@ function useChat(options = {}) {
6212
6244
  ws.onmessage = (event) => {
6213
6245
  try {
6214
6246
  const envelope = JSON.parse(event.data);
6215
- if (envelope.type === "message.created" && envelope.data) {
6216
- appendMessages([envelope.data]);
6217
- } else if (envelope.type === "thread.read") {
6218
- const at = envelope.data?.last_read_at;
6219
- if (at) setSeenAt((prev) => !prev || prev < at ? at : prev);
6220
- } else if (envelope.type === "thread.responding") {
6221
- const active = envelope.data?.active;
6222
- if (active) startAwaitingReply();
6223
- else stopAwaitingReply();
6224
- } else if (envelope.type === "resync") {
6225
- const latest = envelope.latest_message_at;
6247
+ const update = chatRealtimeUpdateFromWire(envelope);
6248
+ if (update.kind === "message") {
6249
+ appendMessages([update.message]);
6250
+ } else if (update.kind === "message_updated") {
6251
+ lastActivityRef.current = Date.now();
6252
+ setMessages(
6253
+ (previous) => update.message.deleted_at ? previous.filter((message) => message.id !== update.message.id) : previous.map(
6254
+ (message) => message.id === update.message.id ? update.message : message
6255
+ )
6256
+ );
6257
+ } else if (update.kind === "business_read") {
6258
+ setSeenAt(
6259
+ (prev) => !prev || prev < update.occurredAt ? update.occurredAt : prev
6260
+ );
6261
+ } else if (update.kind === "ai_mode") {
6262
+ aiEnabledRef.current = update.mode === "auto";
6263
+ setHumanRequested(update.mode === "off");
6264
+ if (update.mode !== "auto") stopAwaitingReply();
6265
+ } else if (update.kind === "handoff") {
6266
+ aiEnabledRef.current = false;
6267
+ setHumanRequested(true);
6268
+ stopAwaitingReply();
6269
+ } else if (update.kind === "reload") {
6270
+ void resyncConversation();
6271
+ } else if (update.kind === "resync") {
6272
+ const latest = update.latestSequence;
6226
6273
  const last = lastConfirmedMessage();
6227
- if (latest && (!last || new Date(last.created_at).getTime() < new Date(latest).getTime())) {
6274
+ if (latest === void 0 || !last?.sequence || last.sequence < latest) {
6228
6275
  fetchNewMessages();
6229
6276
  }
6230
- } else if (envelope.type === "rekey") {
6231
- void resyncConversation();
6232
6277
  }
6233
6278
  } catch {
6234
6279
  }
@@ -6249,7 +6294,15 @@ function useChat(options = {}) {
6249
6294
  ws.onerror = () => {
6250
6295
  };
6251
6296
  wsRef.current = ws;
6252
- }, [appendMessages, startPolling, stopPolling, fetchNewMessages, resyncConversation, lastConfirmedMessage]);
6297
+ }, [
6298
+ appendMessages,
6299
+ startPolling,
6300
+ stopPolling,
6301
+ fetchNewMessages,
6302
+ resyncConversation,
6303
+ lastConfirmedMessage,
6304
+ stopAwaitingReply
6305
+ ]);
6253
6306
  const resetConversation = useCallback(() => {
6254
6307
  stopPolling();
6255
6308
  if (wsReconnectTimerRef.current) {
@@ -6277,9 +6330,9 @@ function useChat(options = {}) {
6277
6330
  const c = clientRef.current;
6278
6331
  setMessages(value.messages);
6279
6332
  setConversationOpened(true);
6280
- aiEnabledRef.current = value.conversation.ai_enabled;
6281
- setHumanRequested(value.conversation.needs_human_review ?? false);
6282
- setSeenAt(value.conversation.team_read_at ?? null);
6333
+ aiEnabledRef.current = value.conversation.ai_mode === "auto";
6334
+ setHumanRequested(value.conversation.ai_mode === "off");
6335
+ setSeenAt(null);
6283
6336
  setMayHaveOlder(value.messages.length >= 50);
6284
6337
  setClaimedAs(c?.support.claimedCustomerName ?? null);
6285
6338
  connectWebSocket();
@@ -6448,7 +6501,7 @@ function useChat(options = {}) {
6448
6501
  const c = clientRef.current;
6449
6502
  const earliest = messagesRef.current[0];
6450
6503
  if (!c || !earliest) return false;
6451
- const result = await c.support.getMessages({ before: earliest.created_at, limit: 50 });
6504
+ const result = await c.support.getMessages({ beforeSequence: earliest.sequence, limit: 50 });
6452
6505
  if (!result.ok) {
6453
6506
  setError(result.error);
6454
6507
  return false;
@@ -13454,8 +13507,7 @@ var STATUS_LABELS = {
13454
13507
  delivered: "Delivered",
13455
13508
  picked_up: "Picked Up",
13456
13509
  completed: "Completed",
13457
- cancelled: "Cancelled",
13458
- refunded: "Refunded"
13510
+ cancelled: "Cancelled"
13459
13511
  };
13460
13512
  var PAYMENT_STATE_LABELS = {
13461
13513
  not_paid: "Not Paid",
@@ -13667,8 +13719,7 @@ var STATUS_LABELS2 = {
13667
13719
  delivered: "Delivered",
13668
13720
  picked_up: "Picked Up",
13669
13721
  completed: "Completed",
13670
- cancelled: "Cancelled",
13671
- refunded: "Refunded"
13722
+ cancelled: "Cancelled"
13672
13723
  };
13673
13724
  function OrderHistory({
13674
13725
  orders: ordersProp,
@@ -20871,6 +20922,7 @@ function KeepConversation({ client }) {
20871
20922
  const [dismissed, setDismissed] = useState(readKeepDismissed);
20872
20923
  const [contact, setContact] = useState("");
20873
20924
  const [code, setCode] = useState("");
20925
+ const [challengeId, setChallengeId] = useState(null);
20874
20926
  const [busy, setBusy] = useState(false);
20875
20927
  const [verifyError, setVerifyError] = useState(null);
20876
20928
  if (dismissed) return null;
@@ -20883,6 +20935,7 @@ function KeepConversation({ client }) {
20883
20935
  const result = await client.link.requestOtp({ contact: trimmed, contact_type: contactType });
20884
20936
  setBusy(false);
20885
20937
  if (result.ok) {
20938
+ setChallengeId(result.value.challenge_id);
20886
20939
  setCode("");
20887
20940
  setStep("code");
20888
20941
  } else {
@@ -20890,10 +20943,11 @@ function KeepConversation({ client }) {
20890
20943
  }
20891
20944
  };
20892
20945
  const verify = async (value) => {
20893
- if (value.length !== 6 || busy) return;
20946
+ if (value.length !== 6 || busy || challengeId === null) return;
20894
20947
  setBusy(true);
20895
20948
  setVerifyError(null);
20896
20949
  const result = await client.link.verifyOtp({
20950
+ ...challengeId === void 0 ? {} : { challenge_id: challengeId },
20897
20951
  contact: contact.trim(),
20898
20952
  contact_type: contactType,
20899
20953
  otp_code: value
@@ -1,5 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- import { bk as ProductInputField, bF as SubmitAuthorizationInput } from './payment-H5LoIvXU.js';
2
+ import { dH as ProductInputField, e3 as PurchaseIntentView, cx as MintPurchaseIntentRequest, bc as ConfirmPurchaseIntentResponse, el as SubmitAuthorizationInput, ab as CHECKOUT_NEXT_ACTION, i as ConfirmPurchaseIntentRequest, em as SubmitPurchaseIntentActionRequest } from './checkout-BqK9XUz5.mjs';
3
3
 
4
4
  interface Clock {
5
5
  now(): Date;
@@ -71,6 +71,7 @@ interface Session {
71
71
  id: string;
72
72
  token: string;
73
73
  business_id: string;
74
+ account_id?: string;
74
75
  customer_id?: string;
75
76
  customer_name?: string;
76
77
  customer_email?: string;
@@ -296,6 +297,17 @@ interface MockOrder {
296
297
  created_at: string;
297
298
  updated_at: string;
298
299
  }
300
+ interface MockPurchaseIntent extends PurchaseIntentView {
301
+ intent_owner: {
302
+ kind: "account";
303
+ id: string;
304
+ } | {
305
+ kind: "storefront_session";
306
+ id: string;
307
+ };
308
+ mint_request: MintPurchaseIntentRequest;
309
+ last_confirmation?: ConfirmPurchaseIntentResponse;
310
+ }
299
311
  interface MockSubscription {
300
312
  id: string;
301
313
  business_id: string;
@@ -552,6 +564,7 @@ interface StateRegistry {
552
564
  collections: Store<MockCollection>;
553
565
  carts: Store<MockCart>;
554
566
  orders: Store<MockOrder>;
567
+ purchaseIntents: Store<MockPurchaseIntent>;
555
568
  subscriptions: Store<MockSubscription>;
556
569
  bookings: Store<MockBooking>;
557
570
  services: Store<MockService>;
@@ -583,7 +596,7 @@ interface AuthService {
583
596
  expires_at: string;
584
597
  code_hint?: string;
585
598
  };
586
- verifyOtp(contact: string, code: string): Session;
599
+ verifyOtp(contact: string, code: string, challengeId?: string): Session;
587
600
  logout(token: string): void;
588
601
  updateProfile(token: string, profile: {
589
602
  name?: string;
@@ -730,66 +743,27 @@ interface CartService {
730
743
  resolveCart(session: Session): MockCart;
731
744
  }
732
745
 
733
- interface CheckoutService {
734
- process(session: Session, body: CheckoutBody): CheckoutResult;
735
- authorize(body: SubmitAuthorizationInput): CheckoutResult;
736
- }
737
- interface CheckoutBody {
738
- cart_id: string;
739
- location_id?: string;
740
- customer: {
741
- name: string;
742
- email: string;
743
- phone: string;
744
- notes?: string;
745
- save_details?: boolean;
746
- };
747
- order_type: string;
748
- address_info?: Record<string, unknown>;
749
- payment_method: string;
750
- mobile_money_details?: {
751
- phone_number: string;
752
- provider: string;
753
- };
754
- special_instructions?: string;
755
- metadata?: Record<string, unknown>;
756
- pay_currency?: string;
757
- fx_quote_id?: string;
758
- }
759
- interface CheckoutResult {
746
+ interface MockPaymentResult {
760
747
  order_id: string;
761
748
  order_number: string;
762
- payment_id?: string;
763
- payment_status: string;
749
+ payment_id: string;
764
750
  payment_reference?: string;
751
+ payment_status: string;
765
752
  requires_authorization: boolean;
766
- authorization_type?: "otp" | "pin" | "phone" | "birthday" | "address";
767
753
  next_action: {
768
- type: "none";
769
- } | {
770
- type: "card_popup";
771
- provider: string;
772
- client_secret: string;
773
- public_key: string;
774
- } | {
775
- type: "redirect";
776
- authorization_url: string;
777
- } | {
778
- type: "authorization";
779
- authorization_type: string;
780
- display_text?: string;
781
- } | {
782
- type: "poll";
754
+ type: typeof CHECKOUT_NEXT_ACTION.NONE;
783
755
  };
784
- provider?: string;
785
- authorization_url?: string;
786
- display_text?: string;
787
- /** Bearer token used for guest order access (lookup `/orders/{id}?token=...`). */
788
- bill_token?: string;
789
- /** Stripe-style client secret for direct PaymentIntent confirmation. */
790
- client_secret?: string;
791
- /** Stripe publishable key (mock value in dev). */
792
- public_key?: string;
756
+ }
757
+ interface PaymentService {
758
+ authorize(body: SubmitAuthorizationInput): MockPaymentResult;
759
+ }
760
+
761
+ interface PurchaseIntentMockService {
762
+ mint(session: Session, request: MintPurchaseIntentRequest): PurchaseIntentView;
763
+ get(session: Session, intentId: string): PurchaseIntentView;
764
+ refresh(session: Session, intentId: string, expectedRevision: number): PurchaseIntentView;
765
+ confirm(session: Session, intentId: string, request: ConfirmPurchaseIntentRequest): ConfirmPurchaseIntentResponse;
766
+ submitAction(session: Session, intentId: string, attemptId: string, request: SubmitPurchaseIntentActionRequest): ConfirmPurchaseIntentResponse;
793
767
  }
794
768
 
795
769
  interface OrderService {
@@ -918,6 +892,7 @@ interface MockDeliveryOption {
918
892
  name: string;
919
893
  description?: string;
920
894
  fee: string;
895
+ fee_status: "priced" | "arranged";
921
896
  currency: string;
922
897
  free_delivery_applied: boolean;
923
898
  free_over_amount?: string;
@@ -1246,7 +1221,8 @@ interface Deps {
1246
1221
  business: BusinessService;
1247
1222
  catalogue: CatalogueService;
1248
1223
  cart: CartService;
1249
- checkout: CheckoutService;
1224
+ payments: PaymentService;
1225
+ purchaseIntents: PurchaseIntentMockService;
1250
1226
  orders: OrderService;
1251
1227
  subscriptions: SubscriptionService;
1252
1228
  scheduling: SchedulingService;