@tagadapay/headless-sdk 1.9.0 → 1.13.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 (40) hide show
  1. package/README.md +233 -216
  2. package/dist/core/index.d.ts +1 -0
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/core/index.js +1 -0
  5. package/dist/core/index.js.map +1 -1
  6. package/dist/core/modules/checkout.d.ts +15 -0
  7. package/dist/core/modules/checkout.d.ts.map +1 -1
  8. package/dist/core/modules/checkout.js +14 -0
  9. package/dist/core/modules/checkout.js.map +1 -1
  10. package/dist/core/modules/customer.d.ts +28 -2
  11. package/dist/core/modules/customer.d.ts.map +1 -1
  12. package/dist/core/modules/customer.js +40 -6
  13. package/dist/core/modules/customer.js.map +1 -1
  14. package/dist/core/modules/payment.d.ts +35 -0
  15. package/dist/core/modules/payment.d.ts.map +1 -1
  16. package/dist/core/modules/payment.js +70 -2
  17. package/dist/core/modules/payment.js.map +1 -1
  18. package/dist/core/types.d.ts +9 -0
  19. package/dist/core/types.d.ts.map +1 -1
  20. package/dist/react/hooks/useCheckout.d.ts +23 -0
  21. package/dist/react/hooks/useCheckout.d.ts.map +1 -1
  22. package/dist/react/hooks/useCheckout.js +12 -0
  23. package/dist/react/hooks/useCheckout.js.map +1 -1
  24. package/dist/react/hooks/useOrder.d.ts +60 -0
  25. package/dist/react/hooks/useOrder.d.ts.map +1 -0
  26. package/dist/react/hooks/useOrder.js +103 -0
  27. package/dist/react/hooks/useOrder.js.map +1 -0
  28. package/dist/react/hooks/usePayment.d.ts +4 -0
  29. package/dist/react/hooks/usePayment.d.ts.map +1 -1
  30. package/dist/react/hooks/usePayment.js.map +1 -1
  31. package/dist/react/index.d.ts +3 -0
  32. package/dist/react/index.d.ts.map +1 -1
  33. package/dist/react/index.js +3 -0
  34. package/dist/react/index.js.map +1 -1
  35. package/dist/tagada-headless-react.min.js +2 -2
  36. package/dist/tagada-headless-react.min.js.map +4 -4
  37. package/dist/tagada-headless.js +115 -12
  38. package/dist/tagada-headless.min.js +2 -2
  39. package/dist/tagada-headless.min.js.map +3 -3
  40. package/package.json +79 -79
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOrder.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useOrder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yDAAyD;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;;;OAIG;IACH,aAAa,EAAE,KAAK,EAAE,CAAC;IACvB,mFAAmF;IACnF,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,uCAAuC;IACvC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,OAAO,CAAC,EAAE,eAAe,GACxB,cAAc,CAyEhB"}
@@ -0,0 +1,103 @@
1
+ import { useState, useEffect, useCallback, useRef } from 'react';
2
+ import { useHeadlessClient } from '../provider.js';
3
+ /**
4
+ * React hook for a single order — built for **thank-you pages**.
5
+ *
6
+ * Loads the order by id and, by default, keeps watching for the child
7
+ * orders created by accepted upsells (`relatedOrders`) so the summary
8
+ * fills in without any manual polling.
9
+ *
10
+ * @param orderId - Usually from the URL, e.g. `?orderId=order_xxx`.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * function ThankYouPage() {
15
+ * const orderId = new URLSearchParams(window.location.search).get('orderId');
16
+ * const { order, relatedOrders, isLoading } = useOrder(orderId);
17
+ *
18
+ * if (isLoading || !order) return <p>Loading…</p>;
19
+ *
20
+ * return (
21
+ * <div>
22
+ * <h1>Thank you! Order #{order.id}</h1>
23
+ * <OrderBlock order={order} />
24
+ * {relatedOrders.map((o) => <OrderBlock key={o.id} order={o} />)}
25
+ * </div>
26
+ * );
27
+ * }
28
+ * ```
29
+ */
30
+ export function useOrder(orderId, options) {
31
+ const client = useHeadlessClient();
32
+ const [order, setOrder] = useState(null);
33
+ const [isLoading, setIsLoading] = useState(false);
34
+ const [error, setError] = useState(null);
35
+ const watch = options?.watchRelatedOrders ?? true;
36
+ const watchTimeoutMs = options?.watchTimeoutMs ?? 8000;
37
+ const watchIntervalMs = options?.watchIntervalMs ?? 2000;
38
+ // Guards background refetches against unmount and orderId changes.
39
+ const generationRef = useRef(0);
40
+ const refresh = useCallback(async () => {
41
+ if (!orderId)
42
+ return;
43
+ try {
44
+ const o = await client.customer.getOrder(orderId);
45
+ setOrder(o);
46
+ }
47
+ catch (err) {
48
+ setError(err instanceof Error ? err : new Error(String(err)));
49
+ }
50
+ }, [client, orderId]);
51
+ useEffect(() => {
52
+ if (!orderId)
53
+ return;
54
+ const generation = ++generationRef.current;
55
+ const isCurrent = () => generationRef.current === generation;
56
+ setIsLoading(true);
57
+ setError(null);
58
+ (async () => {
59
+ try {
60
+ // First paint: render the main order immediately, don't block on upsells.
61
+ let o = await client.customer.getOrder(orderId);
62
+ if (!isCurrent())
63
+ return;
64
+ setOrder(o);
65
+ setIsLoading(false);
66
+ if (!watch || o.relatedOrders?.length)
67
+ return;
68
+ // Background: watch for the child orders from accepted upsells.
69
+ const deadline = Date.now() + watchTimeoutMs;
70
+ while (Date.now() < deadline && isCurrent()) {
71
+ await new Promise((resolve) => setTimeout(resolve, watchIntervalMs));
72
+ if (!isCurrent())
73
+ return;
74
+ o = await client.customer.getOrder(orderId);
75
+ if (!isCurrent())
76
+ return;
77
+ if (o.relatedOrders?.length) {
78
+ setOrder(o);
79
+ return;
80
+ }
81
+ }
82
+ }
83
+ catch (err) {
84
+ if (!isCurrent())
85
+ return;
86
+ setError(err instanceof Error ? err : new Error(String(err)));
87
+ setIsLoading(false);
88
+ }
89
+ })();
90
+ return () => {
91
+ // Invalidate in-flight work for this orderId.
92
+ generationRef.current++;
93
+ };
94
+ }, [client, orderId, watch, watchTimeoutMs, watchIntervalMs]);
95
+ return {
96
+ order,
97
+ relatedOrders: order?.relatedOrders ?? [],
98
+ isLoading,
99
+ error,
100
+ refresh,
101
+ };
102
+ }
103
+ //# sourceMappingURL=useOrder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOrder.js","sourceRoot":"","sources":["../../../src/react/hooks/useOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAmCnD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAkC,EAClC,OAAyB;IAEzB,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,OAAO,EAAE,kBAAkB,IAAI,IAAI,CAAC;IAClD,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,IAAI,CAAC;IACvD,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;IAEzD,mEAAmE;IACnE,M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AC;gBAC7C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,IAAI,SAAS,EAAE,EAAE,CAAC;oBAC5C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;oBACrE,IAAI,CAAC,SAAS,EAAE;wBAAE,OAAO;oBACzB,CAAC,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBAC5C,IAAI,CAAC,SAAS,EAAE;wBAAE,OAAO;oBACzB,IAAI,CAAC,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;wBAC5B,QAAQ,CAAC,CAAC,CAAC,CAAC;wBACZ,OAAO;oBACT,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,SAAS,EAAE;oBAAE,OAAO;gBACzB,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC9D,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,8CAA8C;YAC9C,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;IAE9D,OAAO;QACL,KAAK;QACL,aAAa,EAAE,KAAK,EAAE,aAAa,IAAI,EAAE;QACzC,SAAS;QACT,KAAK;QACL,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -70,12 +70,16 @@ export interface UsePaymentReturn {
70
70
  /**
71
71
  * Process Apple Pay. Pass the contacts from `onpaymentauthorized` so the
72
72
  * address approved in the wallet sheet reaches the order (#TAG-1989).
73
+ *
74
+ * `merchantRegistrationId` (BYOK / platform-integrator domains) is resolved
75
+ * automatically from the payment setup; pass it only to override.
73
76
  */
74
77
  processApplePay: (opts: {
75
78
  checkoutSessionId: string;
76
79
  applePayToken: unknown;
77
80
  billingContact?: ApplePayContact | null;
78
81
  shippingContact?: ApplePayContact | null;
82
+ merchantRegistrationId?: string;
79
83
  }) => Promise<PayResult>;
80
84
  /** Process Google Pay. Pass the wallet addresses for the same reason. */
81
85
  processGooglePay: (opts: {
@@ -1 +1 @@
1
- {"version":3,"file":"usePayment.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/usePayment.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAM7F,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,GAAG;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,GAAG;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE,KAAK,IAAI,CAAC;IAChF;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED,MAAM,WAAW,gBAAgB;IAC/B,iFAAiF;IACjF,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,+EAA+E;IAC/E,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,4CAA4C;IAC5C,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,yFAAyF;IACzF,YAAY,EAAE,OAAO,CAAC;IACtB,2BAA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M,EAAE,SAAS,CAAC,CACpB,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAClC,KAAK,EAAE,IAMN,EAAE,EAAE;QACH,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAClE,MAAM,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC;QACrB,SAAS,CAAC,CAAC,CAAC,CAAC;QACb,OAAO,CAAC,CAAC;IACX,CAAC,EACD,CAAC,MAAM,EAAE,SAAS,CAAC,CACpB,CAAC;IAEF,MAAM,UAAU,GAAG,WAAW,CAC5B,KAAK,EAAE,IAA+E,EAAE,EAAE;QACxF,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC;QACrB,SAAS,CAAC,CAAC,CAAC,CAAC;QACb,OAAO,CAAC,CAAC;IACX,CAAC,EACD,CAAC,MAAM,EAAE,SAAS,CAAC,CACpB,CAAC;IAEF,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,SAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAClE,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO;QACL,YAAY;QACZ,cAAc;QACd,WAAW;QACX,YAAY;QACZ,MAAM;QACN,KAAK;QACL,gBAAgB;QAChB,cAAc;QACd,GAAG;QACH,YAAY;QACZ,eAAe;QACf,gBAAgB;QAChB,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC"}
@@ -8,6 +8,8 @@ export { useOffers } from './hooks/useOffers.js';
8
8
  export type { UseOffersReturn } from './hooks/useOffers.js';
9
9
  export { useCustomer } from './hooks/useCustomer.js';
10
10
  export type { UseCustomerReturn } from './hooks/useCustomer.js';
11
+ export { useOrder } from './hooks/useOrder.js';
12
+ export type { UseOrderReturn, UseOrderOptions } from './hooks/useOrder.js';
11
13
  export { useCatalog } from './hooks/useCatalog.js';
12
14
  export type { UseCatalogReturn } from './hooks/useCatalog.js';
13
15
  export { useRx } from './hooks/useRx.js';
@@ -18,5 +20,6 @@ export { useISOData, useCountryOptions, useRegionOptions } from './hooks/useISOD
18
20
  export type { UseISODataReturn } from './hooks/useISOData.js';
19
21
  export type { GooglePrediction, GooglePlaceDetails, ExtractedAddress, FormattedAddress, SupportedLanguage, ISOCountry, ISORegion, Currency, } from '../core/helpers/index.js';
20
22
  export { formatMoney, CurrencyUtils, ISODataCore, GoogleAutocompleteCore, loadGoogleMapsScript } from '../core/helpers/index.js';
23
+ export { parseTokensFromUrl } from '../core/modules/checkout.js';
21
24
  export type { HeadlessConfig, Environment, CheckoutSession, CheckoutLineItem, CheckoutTotals, CheckoutCustomer, Address, ShippingRate, LineItem, PaymentSetupConfig, PaymentMethodConfig, ExpressMethods, ExpressMethod, StoreConfig, PayResult, PayOptions, PaymentStatus, ProcessPaymentOptions, ProcessPaymentResult, Offer, OfferLineItem, OfferPreview, OfferPreviewItem, OfferPayResult, Customer, Order, Subscription, CatalogProduct, CatalogVariant, CatalogPrice, CurrencyOption, StripeExpressOptions, } from '../core/types.js';
22
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC1E,YAAY,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAE,gBAAgB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U,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxF,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGjI,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,YAAY,EACV,cAAc,EACd,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAC"}
@@ -3,10 +3,13 @@ export { useCheckout } from './hooks/useCheckout.js';
3
3
  export { usePayment } from './hooks/usePayment.js';
4
4
  export { useOffers } from './hooks/useOffers.js';
5
5
  export { useCustomer } from './hooks/useCustomer.js';
6
+ export { useOrder } from './hooks/useOrder.js';
6
7
  export { useCatalog } from './hooks/useCatalog.js';
7
8
  export { useRx } from './hooks/useRx.js';
8
9
  // Helpers hooks
9
10
  export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete.js';
10
11
  export { useISOData, useCountryOptions, useRegionOptions } from './hooks/useISOData.js';
11
12
  export { formatMoney, CurrencyUtils, ISODataCore, GoogleAutocompleteCore, loadGoogleMapsScript } from '../core/helpers/index.js';
13
+ // URL token helper — landing → self-hosted checkout handoff
14
+ export { parseTokensFromUrl } from '../core/modules/checkout.js';
12
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,gBAAgB;AAChB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAexF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,gBAAgB;AAChB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAexF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEjI,4DAA4D;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @tagadapay/headless-sdk v1.9.0
2
+ * @tagadapay/headless-sdk v1.13.0
3
3
  * Headless checkout, payments, offers, and CRM
4
4
  * @license MIT
5
5
  */
6
- "use strict";var TagadaHeadlessReactBundle=(()=>{var Xe=Object.create;var ne=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var F=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var st=(s,e)=>{for(var t in e)ne(s,t,{get:e[t],enumerable:!0})},Ee=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of tt(e))!nt.call(s,n)&&n!==t&&ne(s,n,{get:()=>e[n],enumerable:!(r=et(e,n))||r.enumerable});return s};var Te=(s,e,t)=>(t=s!=null?Xe(rt(s)):{},Ee(e||!s||!s.__esModule?ne(t,"default",{value:s,enumerable:!0}):t,s)),it=s=>Ee(ne({},"__esModule",{value:!0}),s);var ht={};st(ht,{CurrencyUtils:()=>V,GoogleAutocompleteCore:()=>j,ISODataCore:()=>K,TagadaHeadlessProvider:()=>De,formatMoney:()=>Oe,loadGoogleMapsScript:()=>X,useCatalog:()=>je,useCheckout:()=>qe,useCountryOptions:()=>Ve,useCustomer:()=>He,useGoogleAutocomplete:()=>Je,useHeadlessClient:()=>q,useISOData:()=>Ie,useOffers:()=>$e,usePayment:()=>Ge,useRegionOptions:()=>Ye,useRx:()=>Ke});var J=F("react");var M=class extends Error{constructor(e,t,r,n){super(e),this.name="TagadaError",this.code=t,this.statusCode=r,this.details=n}},se=class extends M{constructor(e="Authentication failed. Check your API key or checkout token."){super(e,"auth_error",401),this.name="TagadaAuthError"}},ie=class extends M{constructor(e,t=[],r,n){super(e,"validation_error",422,{errors:t,...n}),this.name="TagadaValidationError",this.errors=t,this.appCode=r}},oe=class extends M{constructor(e,t){super(`${e} "${t}" not found.`,"not_found",404),this.name="TagadaNotFoundError"}},ae=class extends M{constructor(e=1e3){super(`Rate limited. Retry after ${e}ms.`,"rate_limit",429),this.name="TagadaRateLimitError",this.retryAfterMs=e}};var W=class extends M{constructor(e="Network request failed. Check your connection."){super(e,"network_error"),this.name="TagadaNetworkError"}};var Le={production:"https://api.tagada.io",development:"https://api.tagada.dev",local:"http://localhost:3000"},Z=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.timeout=e.timeout,this.apiKey=e.apiKey,this.getToken=e.getToken}static resolveBaseUrl(e,t){return t??Le[e]??Le.production}async request(e,t={}){var p;let{method:r="GET",body:n,headers:o={},params:i,token:a,signal:u}=t,c=`${this.baseUrl}${e}`;if(i){let h=new URLSearchParams;for(let[l,R]of Object.entries(i))R!==void 0&&h.set(l,String(R));let g=h.toString();g&&(c+=`?${g}`)}let f={"Content-Type":"application/json",...o},d=a??this.apiKey??((p=this.getToken)==null?void 0:p.call(this));d&&(f["x-cms-token"]=d);let y=new AbortController,m=setTimeout(()=>y.abort(),this.timeout);try{let h=await fetch(c,{method:r,headers:f,body:n!=null?JSON.stringify(n):void 0,signal:u??y.signal});if(clearTimeout(m),h.ok){let g=await h.text();return g?JSON.parse(g):{}}throw await this.handleErrorResponse(h,e),new M("Unexpected error","unknown",h.status)}catch(h){throw clearTimeout(m),h instanceof M?h:h instanceof DOMException&&h.name==="AbortError"?new W(`Request to ${e} timed out after ${this.timeout}ms.`):new W(h instanceof Error?h.message:"Network request failed.")}}get(e,t){return this.request(e,{...t,method:"GET"})}post(e,t,r){return this.request(e,{...r,method:"POST",body:t})}patch(e,t,r){return this.request(e,{...r,method:"PATCH",body:t})}put(e,t,r){return this.request(e,{...r,method:"PUT",body:t})}delete(e,t){return this.request(e,{...t,method:"DELETE"})}async handleErrorResponse(e,t){let r={};try{r=await e.json()}catch{}let n=r.data??{},o=r.message??r.error??(typeof n.message=="string"?n.message:void 0)??(typeof r.data=="string"?r.data:void 0)??`Request failed: ${e.status} ${e.statusText} on ${t}`,i=typeof n.code=="string"?n.code:void 0;switch(e.status){case 401:case 403:throw new se(o);case 404:throw new oe(t,"");case 422:{let a=Array.isArray(r.errors)?r.errors:[];throw new ie(o,a,i,r)}case 429:{let a=Number(e.headers.get("Retry-After")??"1")*1e3;throw new ae(a)}default:throw new M(o,"api_error",e.status,r)}}};var ce=class{constructor(e,t,r){this.http=e;this.storeId=t;this.onTokenChange=r}getCurrentSession(){return this._currentSession}async loadSession(e,t,r){var a;t&&(this.sessionToken=t,(a=this.onTokenChange)==null||a.call(this,t));let n={skipAsyncWait:"false"};r!=null&&r.currency&&(n.currency=r.currency);let o=await this.http.get(`/api/v1/checkout-sessions/${e}/v2`,{params:n,token:this.sessionToken}),i=this.normalizeSession(o);return this._currentSession=i,i}async createSession(e){var u;let t=e.items.map(c=>({variantId:c.variantId,priceId:c.priceId,quantity:c.quantity})),r={storeId:this.storeId,lineItems:t};e.returnUrl&&(r.returnUrl=e.returnUrl);let n={};e.currency&&(n.currency=e.currency),e.customerEmail&&(n.email=e.customerEmail,n.firstName=e.customerFirstName,n.lastName=e.customerLastName),Object.keys(n).length>0&&(r.customer=n);let o=await this.http.post("/api/v1/checkout/session/init",r),a=new URL(o.checkoutUrl).searchParams.get("token")??"";return this.sessionToken=a,a&&((u=this.onTokenChange)==null||u.call(this,a)),{checkoutUrl:o.checkoutUrl,checkoutToken:o.checkoutToken,sessionToken:a,customerId:o.customerId}}async createSessionUrl(e){let t=await this.createSession({items:e.items,currency:e.currency,returnUrl:e.returnUrl,customerEmail:e.customerEmail,customerFirstName:e.customerFirstName,customerLastName:e.customerLastName}),r=e.origin??(typeof window<"u"?window.location.origin:""),n=e.checkoutPath??"/checkout",o=new URLSearchParams({checkoutToken:t.checkoutToken,sessionToken:t.sessionToken}),i=`${r}${n}?${o.toString()}`;return{...t,url:i}}static parseTokensFromUrl(e){if(typeof e>"u"&&typeof window>"u")return null;let t=e??window.location.href,r;try{r=new URL(t)}catch{return null}let n=r.searchParams.get("checkoutToken");if(!n)return null;let o=r.searchParams.get("sessionToken")??r.searchParams.get("token")??"";return{checkoutToken:n,sessionToken:o}}async updateCart(e,t){let r=t.map(n=>({variantId:n.variantId,priceId:n.priceId,quantity:n.quantity}));return this.http.post(`/api/v1/checkout-sessions/${e}/line-items`,{lineItems:r},{token:this.sessionToken})}async updateCustomer(e,t){t.email&&(this.customerEmail=t.email),t.firstName&&(this.customerFirstName=t.firstName),t.lastName&&(this.customerLastName=t.lastName),t.phone&&(this.customerPhone=t.phone)}async updateAddress(e,t){let r=this.mapAddress(t.shippingAddress),n=this.mapAddress(t.billingAddress),o=r??n??{},i=n??r,a=!!(t.billingAddress&&t.shippingAddress);await this.http.post(`/api/v1/checkout-sessions/${e}/customer-and-session-info`,{checkoutSessionId:e,customerData:{email:this.customerEmail},shippingAddress:o,billingAddress:i??{},differentBillingAddress:a},{token:this.sessionToken})}async updateCustomerAndAddress(e,t){t.customer.email&&(this.customerEmail=t.customer.email),t.customer.firstName&&(this.customerFirstName=t.customer.firstName),t.customer.lastName&&(this.customerLastName=t.customer.lastName),t.customer.phone&&(this.customerPhone=t.customer.phone);let r=this.mapAddress(t.shippingAddress),n=this.mapAddress(t.billingAddress),o=r??n??{},i=n??r,a=!!(t.billingAddress&&t.shippingAddress);await this.http.post(`/api/v1/checkout-sessions/${e}/customer-and-session-info`,{checkoutSessionId:e,customerData:{email:this.customerEmail},shippingAddress:o,billingAddress:i??{},differentBillingAddress:a},{token:this.sessionToken})}mapAddress(e){if(e)return ot({firstName:e.firstName??this.customerFirstName,lastName:e.lastName??this.customerLastName,phone:e.phone??this.customerPhone,address1:e.line1,address2:e.line2,city:e.city,state:e.state,postal:e.postalCode,country:e.country})}async applyPromoCode(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/promotions/apply`,{checkoutSessionId:e,code:t},{token:this.sessionToken})}async removePromoCode(e,t){let r=t??"default";await this.http.delete(`/api/v1/checkout-sessions/${e}/promotions/${r}`,{token:this.sessionToken})}async getShippingRates(e){return((await this.http.get(`/api/v1/checkout-sessions/${e}/shipping-rates`,{token:this.sessionToken})).rates??[]).map(r=>this.normalizeShippingRate(r))}normalizeShippingRate(e){return{id:e.id,name:e.name??e.shippingRateName??"",description:e.description??void 0,amount:e.amount??0,currency:e.currency??"USD",estimatedDays:e.estimatedDays??e.estimatedDeliveryTime??void 0}}async selectShippingRate(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/shipping-rate`,{checkoutSessionId:e,shippingRateId:t},{token:this.sessionToken})}normalizeSession(e){var f;let t=e.checkoutSession,r=t.orderSummaries??[],n=e.summary??t.summary??r[0]??{},o=t.sessionLineItems??[],i=t.customer,a=(f=n.currency??t.selectedPresentmentCurrency)==null?void 0:f.toUpperCase(),u=o.map(d=>{let y=d.price,m=d.variant??(y==null?void 0:y.variant)??{},p=d.product??m.product??{},h=(y==null?void 0:y.currencyOptions)??{},g=(a?h[a]:void 0)??h[Object.keys(h)[0]],l=(g==null?void 0:g.amount)??0;return{id:d.id,variantId:d.variantId,priceId:d.priceId,productName:p.name??"",variantName:m.name??"",quantity:d.quantity??1,unitAmount:l,totalAmount:l*(d.quantity??1),currency:a??"USD",imageUrl:m.imageUrl??p.imageUrl??""}}),c=n.items??[];return{id:t.id,storeId:t.storeId,checkoutToken:t.checkoutToken,currency:a??"USD",items:u,totals:{subtotal:n.subtotalAmount??0,discount:n.totalPromotionAmount??0,shipping:n.shippingCost??0,tax:n.totalTaxAmount??0,total:n.totalAmount??c.reduce((d,y)=>d+(y.amount??0),0),currency:a??"USD"},customer:i?{id:i.id,email:i.email,firstName:i.firstName,lastName:i.lastName,phone:i.phone}:void 0,shippingAddress:this.normalizeAddress(t.shippingAddress),billingAddress:this.normalizeAddress(t.billingAddress),selectedShippingRateId:t.shippingRateId??null,metadata:t.metadata}}normalizeAddress(e){if(!e||typeof e!="object")return;let t=e,r={firstName:t.firstName,lastName:t.lastName,line1:t.line1??t.address1,line2:t.line2??t.address2,city:t.city,state:t.state,postalCode:t.postalCode??t.postal,country:t.country,phone:t.phone};return Object.values(r).some(n=>n!==void 0&&n!=="")?r:void 0}};function ot(s){let e={};for(let[t,r]of Object.entries(s))r!=null&&r!==""&&(e[t]=r);return Object.keys(e).length>0?e:void 0}function ue(s){var t,r;if(!s)return;let e={firstName:s.givenName,lastName:s.familyName,line1:(t=s.addressLines)==null?void 0:t[0],line2:(r=s.addressLines)==null?void 0:r[1],city:s.locality,state:s.administrativeArea,postalCode:s.postalCode,country:s.countryCode,phone:s.phoneNumber};return Ue(e)?e:void 0}function de(s){if(!s)return;let[e,...t]=(s.name??"").trim().split(/\s+/),r={firstName:e||void 0,lastName:t.length?t.join(" "):void 0,line1:s.address1,line2:[s.address2,s.address3].filter(Boolean).join(" ")||void 0,city:s.locality,state:s.administrativeArea,postalCode:s.postalCode,country:s.countryCode,phone:s.phoneNumber};return Ue(r)?r:void 0}function Ue(s){var e,t;return!!((e=s.line1)!=null&&e.trim()&&((t=s.country)!=null&&t.trim()))}var le=class{constructor(e,t,r,n){this.http=e;this.storeId=t;this.environment=r;this.checkout=n}async getPaymentSetup(e,t){if(t!=null&&t.paymentSetupConfig)return t.paymentSetupConfig;let r=this.readInjectedStepConfig();if(r)return r;let n=await this.http.get("/api/v1/payment-methods",{params:{checkoutSessionId:e}}),o={};for(let i of n.methods??[]){let a=i.provider?`${i.method}:${i.provider}`:i.method;o[a]=i}return o}async getExpressMethods(e,t){var o,i,a,u,c,f,d,y;let r=await this.getPaymentSetup(e,t),n={};for(let[m,p]of Object.entries(r)){if(!p.enabled)continue;if(m.startsWith("express_checkout:")&&p.methods){let l={available:!0,processorId:p.processorId,publishableKey:p.publishableKey,metadata:p.metadata};if((o=p.methods.apple_pay)!=null&&o.enabled){let R=typeof window<"u"&&"ApplePaySession"in window&&((a=(i=window.ApplePaySession)==null?void 0:i.canMakePayments)==null?void 0:a.call(i));n.applePay={...l,type:"apple_pay",available:!!R}}(u=p.methods.google_pay)!=null&&u.enabled&&(n.googlePay={...l,type:"google_pay"}),(c=p.methods.link)!=null&&c.enabled&&(n.link={...l,type:"link"}),(f=p.methods.klarna_express)!=null&&f.enabled&&(n.klarna={...l,type:"klarna_express"});continue}if(!p.express)continue;let h=p.method,g={type:h,available:!0,processorId:p.processorId,publishableKey:p.publishableKey,metadata:p.metadata};if(h==="apple_pay"||p.type==="apple_pay"){let l=typeof window<"u"&&"ApplePaySession"in window&&((y=(d=window.ApplePaySession)==null?void 0:d.canMakePayments)==null?void 0:y.call(d));n.applePay={...g,available:!!l}}else h==="google_pay"||p.type==="google_pay"?n.googlePay=g:h==="paypal"?n.paypal=g:h==="klarna"||h==="klarna_express"?n.klarna=g:h==="link"&&(n.link=g)}return n}async getStoreConfig(){let e=await this.http.get("/api/v1/checkout/config",{params:{storeId:this.storeId}});return e.config??e}async getEnabledMethods(e,t){let r=await this.getPaymentSetup(e,t);return Object.entries(r).filter(([,n])=>n.enabled).map(([n])=>n)}async tokenizeCard(e){let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let n={cardNumber:e.cardNumber,expiryDate:e.expiryDate,cvc:e.cvc};e.cardholderName&&(n.cardholderName=e.cardholderName);let o=await r.tokenizeCardRaw(n);return{tagadaToken:t.createTagadaToken(o,r.getProvider().getProviderName()),rawToken:o}}async createInstrument(e){return this.http.post("/api/v1/payment/create-instrument-from-token",{tagadaToken:e.tagadaToken})}async create3dsSession(e){return this.http.post("/api/public/v1/threeds/create-session",{provider:e.provider??"basis_theory",storeId:this.storeId,paymentInstrumentId:e.paymentInstrumentId,sessionData:e.sessionData})}async pay(e){return e.tagadaToken&&!e.paymentInstrumentId?this.http.post("/api/v1/payment/pay-with-token",{tagadaToken:e.tagadaToken,checkoutSessionId:e.checkoutSessionId,returnUrl:e.returnUrl,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:e.isExpress,metadata:e.metadata}):this.http.post("/api/public/v1/checkout/pay-v2",{checkoutSessionId:e.checkoutSessionId,paymentInstrumentId:e.paymentInstrumentId,storeId:this.storeId,paymentFlowId:e.paymentFlowId,threedsSessionId:e.threedsSessionId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:e.isExpress,metadata:e.metadata,returnUrl:e.returnUrl})}async payDirect(e){return this.http.post("/api/public/v1/checkout/pay-v2",{checkoutSessionId:e.checkoutSessionId,paymentInstrumentId:e.paymentInstrumentId??"",storeId:this.storeId,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:e.isExpress,threedsSessionId:e.threedsSessionId,returnUrl:e.returnUrl})}async syncWalletContact(e,t){let{shippingAddress:r,billingAddress:n}=t;if(!r&&!n)return;if(!this.checkout)throw new Error("PaymentModule cannot persist the wallet contact: no CheckoutModule was provided. Build the SDK through createTagadaClient() rather than constructing PaymentModule directly.");let o={};t.email&&(o.email=t.email),t.phone&&(o.phone=t.phone),t.firstName&&(o.firstName=t.firstName),t.lastName&&(o.lastName=t.lastName),await this.checkout.updateCustomerAndAddress(e,{customer:o,shippingAddress:r,billingAddress:n})}async processApplePay(e){var o,i,a,u,c,f,d,y;await this.syncWalletContact(e.checkoutSessionId,{shippingAddress:ue(e.shippingContact),billingAddress:ue(e.billingContact),email:((o=e.shippingContact)==null?void 0:o.emailAddress)??((i=e.billingContact)==null?void 0:i.emailAddress),phone:((a=e.shippingContact)==null?void 0:a.phoneNumber)??((u=e.billingContact)==null?void 0:u.phoneNumber),firstName:((c=e.shippingContact)==null?void 0:c.givenName)??((f=e.billingContact)==null?void 0:f.givenName),lastName:((d=e.shippingContact)==null?void 0:d.familyName)??((y=e.billingContact)==null?void 0:y.familyName)});let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let{tagadaToken:n}=await r.tokenizeApplePay(e.applePayToken);return this.pay({checkoutSessionId:e.checkoutSessionId,tagadaToken:n,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:"apple_pay",isExpress:!0})}async processGooglePay(e){var o,i,a,u;await this.syncWalletContact(e.checkoutSessionId,{shippingAddress:de(e.shippingAddress),billingAddress:de(e.billingAddress),email:e.email??((o=e.shippingAddress)==null?void 0:o.emailAddress)??((i=e.billingAddress)==null?void 0:i.emailAddress),phone:((a=e.shippingAddress)==null?void 0:a.phoneNumber)??((u=e.billingAddress)==null?void 0:u.phoneNumber)});let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let{tagadaToken:n}=await r.tokenizeGooglePay(e.googlePayToken);return this.pay({checkoutSessionId:e.checkoutSessionId,tagadaToken:n,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:"google_pay",isExpress:!0})}async processApm(e){return this.payDirect({checkoutSessionId:e.checkoutSessionId,paymentMethod:e.paymentMethod,processorId:e.processorId,paymentFlowId:e.paymentFlowId})}async processStripeExpress(e){return this.payDirect({checkoutSessionId:e.checkoutSessionId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:!0})}async processPayment(e){!e.returnUrl&&typeof window<"u"&&(e={...e,returnUrl:window.location.href});let t=await this.pay(e);return this.finalize(t,{returnUrl:e.returnUrl})}async finalize(e,t){var o,i;let r=e.payment,n=(t==null?void 0:t.returnUrl)??(typeof window<"u"?window.location.href:void 0);return r.status==="succeeded"?{status:"succeeded",payment:r,order:e.order}:r.status==="failed"||r.status==="declined"?{status:"failed",error:((o=r.requireActionData)==null?void 0:o.message)||((i=r.requireActionData)==null?void 0:i.errorCode)||`Payment ${r.status}`,payment:r}:r.requireAction&&r.requireAction!=="none"&&r.requireActionData?this.handlePaymentAction(r,{returnUrl:n}):this.pollUntilDone(r.id)}async resumeAfterRedirect(e){return this.pollUntilDone(e)}async maybeResumeFromUrl(e){if(typeof window>"u"&&!(e!=null&&e.url))return null;let t=(e==null?void 0:e.url)??window.location.href,r;try{r=new URL(t)}catch{return null}let n=r.searchParams.get("paymentAction"),o=r.searchParams.get("paymentActionStatus"),i=r.searchParams.get("paymentId");if(n!=="requireAction"||o!=="completed"||!i)return null;let a=await this.resumeAfterRedirect(i);if((e==null?void 0:e.cleanUrl)!==!1&&typeof window<"u"&&!(e!=null&&e.url)){let u=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status","sessionId"].forEach(f=>u.delete(f));let c=u.toString();try{window.history.replaceState({},document.title,window.location.pathname+(c?"?"+c:""))}catch{}}return a}async getPaymentStatus(e){return this.http.get(`/api/v1/payments/${e}`)}async pollPaymentStatus(e,t){let r=(t==null?void 0:t.intervalMs)??1500,n=(t==null?void 0:t.timeoutMs)??6e4,o=Date.now();for(;Date.now()-o<n;){let i=await this.getPaymentStatus(e);if(i.status==="succeeded"||i.status==="failed"||i.status==="declined")return i;await new Promise(a=>setTimeout(a,r))}throw new Error(`Payment ${e} did not reach terminal status within ${n}ms.`)}async completeAfter3ds(e){return this.http.post("/api/v1/payments/complete-after-3ds",{paymentId:e})}async markActionProcessed(e){try{await this.http.post("/api/v1/payments/require-action/processed",{paymentId:e})}catch{}}async handlePaymentAction(e,t){let r=e.requireActionData;switch(await this.markActionProcessed(e.id),r.type){case"threeds_auth":return this.handleThreedsAuth(e,t);case"processor_auth":case"redirect_to_payment":return this.extractRedirect(e,r);case"redirect":return this.extractRedirect(e,r);case"error":return{status:"failed",error:r.message||r.errorCode||"Payment failed",payment:e};default:return this.extractRedirect(e,r)}}extractRedirect(e,t){var o,i;let r=(o=t.metadata)==null?void 0:o.redirect,n=(r==null?void 0:r.redirectUrl)||t.redirectUrl;return n?{status:"requires_redirect",redirectUrl:n,method:((i=r==null?void 0:r.method)==null?void 0:i.toUpperCase())||"GET",postData:r==null?void 0:r.data,paymentId:e.id}:{status:"failed",error:`Payment requires action (${t.type}) but no redirect URL was provided`,payment:e}}async handleThreedsAuth(e,t){var o,i;let r=(i=(o=e.requireActionData)==null?void 0:o.metadata)==null?void 0:i.threedsSession;if(!(r!=null&&r.externalSessionId))return this.extractRedirect(e,e.requireActionData);let n;try{n=await import("@tagadapay/core-js")}catch{return r.acsChallengeUrl?{status:"requires_redirect",redirectUrl:r.acsChallengeUrl,paymentId:e.id}:this.extractRedirect(e,e.requireActionData)}try{let a=new n.ThreedsManager({provider:"basis_theory"});return await a.initialize({apiKey:void 0}),await a.startChallenge({sessionId:r.externalSessionId,acsChallengeUrl:r.acsChallengeUrl,acsTransactionId:r.acsTransID,threeDSVersion:r.messageVersion}),await this.completeAfter3ds(e.id),this.pollUntilDone(e.id)}catch{return r.acsChallengeUrl?{status:"requires_redirect",redirectUrl:r.acsChallengeUrl,paymentId:e.id}:{status:"failed",error:"3D Secure authentication failed",payment:e}}}async pollUntilDone(e,t){let r=(t==null?void 0:t.intervalMs)??1500,n=(t==null?void 0:t.timeoutMs)??6e4,o=Date.now(),i=0;for(;Date.now()-o<n;){let a;try{a=await this.getPaymentStatus(e),i=0}catch{if(i++,i>=3)return{status:"failed",error:"Payment verification failed due to network errors"};await new Promise(u=>setTimeout(u,r));continue}if(a.status==="succeeded"||a.status==="pending"&&a.subStatus==="authorized")return{status:"succeeded",payment:a,order:a.order};if(a.status==="failed"||a.status==="declined")return{status:"failed",error:a.status,payment:a};if(a.requireAction&&a.requireAction!=="none"&&a.requireActionData&&!a.requireActionData.processed)return this.handlePaymentAction(a,{});await new Promise(u=>setTimeout(u,r))}return{status:"pending",paymentId:e}}readInjectedStepConfig(){if(typeof window>"u")return null;let e=window.__TGD_STEP_CONFIG__;if(!e)return null;try{let t=typeof e=="string"?JSON.parse(e):e;return(t==null?void 0:t.paymentSetupConfig)??null}catch{return null}}async loadCoreJs(){try{return await import("@tagadapay/core-js")}catch{throw new Error("This method requires @tagadapay/core-js. Install it: npm install @tagadapay/core-js")}}};var me=class{constructor(e,t,r){this.http=e;this.storeId=t;this.payment=r}async getOffer(e){return this.http.get(`/api/v1/offers/${e}`)}async listOffers(e){var o;let t=`/api/v1/stores/${this.storeId}/offers`,r=[];if(e!=null&&e.type&&r.push(`type=${encodeURIComponent(e.type)}`),(o=e==null?void 0:e.ids)!=null&&o.length)for(let i of e.ids)r.push(`ids=${encodeURIComponent(i)}`);return r.length&&(t+=`?${r.join("&")}`),(await this.http.get(t)).offers??[]}async previewOffer(e){return this.http.post(`/api/v1/offers/${e.offerId}/preview`,{offerId:e.offerId,currency:e.currency??"",lineItems:e.lineItems})}async payPreviewedOffer(e){return this.http.post(`/api/v1/offers/${e.offerId}/pay-preview`,{offerId:e.offerId,currency:e.currency??"",lineItems:e.lineItems,returnUrl:e.returnUrl??(typeof window<"u"?window.location.href:""),mainOrderId:e.mainOrderId,paymentInstrumentId:e.paymentInstrumentId})}async processOfferPayment(e){if(!this.payment)throw new Error("OffersModule: no PaymentModule injected. Use createHeadlessClient() instead of constructing OffersModule directly.");let t=e.returnUrl??(typeof window<"u"?window.location.href:void 0),r=await this.payPreviewedOffer({...e,returnUrl:t});return this.payment.finalize({payment:r.payment,order:r.order},{returnUrl:t})}async toggleOrderBump(e){return this.http.post(`/api/v1/checkout-sessions/${e.checkoutSessionId}/toggle-order-bump`,{orderBumpOfferId:e.orderBumpOfferId,selected:e.selected})}async listPostPurchaseOffers(e){let t=await this.http.get(`/api/v1/post-purchase/${e}/offers`);return Array.isArray(t)?t:[]}async acceptPostPurchaseOffer(e){return this.http.post(`/api/v1/orders/${e.orderId}/post-purchase-offers/${e.offerId}/accept`,{items:e.items??[]})}async declinePostPurchaseOffer(e){return this.http.post(`/api/v1/orders/${e.orderId}/post-purchase-offers/${e.offerId}/decline`)}};var pe=class{constructor(e,t){this.http=e;this.storeId=t}async getProfile(e){return(await this.http.get(`/api/v1/customers/${e}`,{params:{storeId:this.storeId}})).customer}async getByEmail(e){try{return(await this.http.get("/api/v1/customers/by-email",{params:{email:e,storeId:this.storeId}})).customer}catch{return null}}async updateProfile(e,t){return(await this.http.patch(`/api/v1/customers/${e}`,{storeId:this.storeId,...t})).customer}async getOrders(e,t){return this.http.get(`/api/v1/customers/${e}/orders`,{params:{storeId:this.storeId,limit:t==null?void 0:t.limit,offset:t==null?void 0:t.offset}})}async getOrder(e){return(await this.http.get(`/api/v1/orders/${e}`,{params:{storeId:this.storeId}})).order}async getSubscriptions(e){return(await this.http.get(`/api/v1/customers/${e}/subscriptions`,{params:{storeId:this.storeId}})).subscriptions}async getSubscription(e){return(await this.http.get(`/api/v1/subscriptions/${e}`,{params:{storeId:this.storeId}})).subscription}};var ge=class{constructor(e,t){this.http=e;this.storeId=t}async getProducts(e){var n,o;let t={storeId:this.storeId,includeVariants:!0,includePrices:!0};return(n=e==null?void 0:e.productIds)!=null&&n.length&&(t.productIds=e.productIds),(o=e==null?void 0:e.variantIds)!=null&&o.length&&(t.variantIds=e.variantIds),(await this.http.post("/api/v1/products",t)).items??[]}async getProduct(e){return(await this.getProducts({productIds:[e]}))[0]??null}};var fe=class{constructor(e,t,r,n){this.http=e;this.storeId=t;this.checkout=r;this.accountId=n}async navigate(e){var a;let t=this.checkout.getCurrentSession();if(!t)throw new M("No checkout session loaded. Call sdk.checkout.loadSession(...) before sdk.funnel.navigate(...).","no_cart_loaded");let r=e.accountId??this.accountId;if(!r)throw new M("accountId is required for funnel.navigate(). Set it on createHeadlessClient({ accountId }) or pass it per call.","missing_account_id");let n=e.currentUrl??(typeof globalThis<"u"?(a=globalThis.location)==null?void 0:a.href:void 0);await this.ensureCmsSession(t,r,e);let o=await this.initializeFunnel({funnelId:e.funnelId,stepId:e.stepId,accountId:r,currentUrl:n});return{url:await this.runNavigate({funnelSessionId:o,stepId:e.stepId,session:t,input:e,currentUrl:n}),funnelSessionId:o}}async ensureCmsSession(e,t,r){var i,a,u;if(this._cmsToken&&this._cmsSessionId&&this._cmsCustomerId)return;let n=await this.http.post("/api/v1/cms/session/anonymous",{storeId:this.storeId,role:"anonymous",draft:!1});this._cmsToken=n.token,this._cmsSessionId=n.sessionId;let o=await this.http.post("/api/v1/cms/session/v2/init",{storeId:this.storeId,accountId:t,customerId:"anon_placeholder",browserLocale:((i=r.customer)==null?void 0:i.locale)??at(),userAgent:ct(),queryCurrency:((a=r.customer)==null?void 0:a.currency)??e.currency,queryLocale:(u=r.customer)==null?void 0:u.locale},{token:this._cmsToken});this._cmsCustomerId=o.customer.id}async initializeFunnel(e){return(await this.http.post("/api/v1/funnel/initialize",{cmsSession:{customerId:this._cmsCustomerId,sessionId:this._cmsSessionId,storeId:this.storeId,accountId:e.accountId},funnelId:e.funnelId,entryStepId:e.stepId,funnelStepId:e.stepId,currentUrl:e.currentUrl,draft:!1},{token:this._cmsToken})).context.sessionId}async runNavigate(e){var d,y,m,p;let{funnelSessionId:t,stepId:r,session:n,input:o,currentUrl:i}=e,a=n.items.map(h=>({variantId:h.variantId,priceId:h.priceId,quantity:h.quantity})),u=o.discountCodes??(n.promotionCode?[n.promotionCode]:void 0),c={email:((d=o.customer)==null?void 0:d.email)??((y=n.customer)==null?void 0:y.email),currency:((m=o.customer)==null?void 0:m.currency)??n.currency,locale:(p=o.customer)==null?void 0:p.locale};return(await this.http.post("/api/v1/funnel/navigate",{sessionId:t,currentUrl:i,funnelStepId:r,fireAndForget:!1,event:{type:"INIT_CHECKOUT",data:{checkoutInit:{cartToken:n.id,lineItems:a,customer:c,returnUrl:o.returnUrl,storeId:this.storeId,metadata:o.metadata,discountCodes:u,externalShipping:o.externalShipping}}}},{token:this._cmsToken})).result.url}};function at(){return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}function ct(){return typeof navigator<"u"&&navigator.userAgent?navigator.userAgent:"tagadapay-headless-sdk"}var ye=class{constructor(e){this.http=e}async isRequiredForProduct(e,t){return this.http.get("/api/public/v1/rx/required-for-product",{params:{productId:e,clinicalNetworkId:t==null?void 0:t.clinicalNetworkId}})}async getCasesForOrder(e){return this.http.post("/api/public/v1/rx/cases/lookup",e)}async submitCase(e){return this.http.post("/api/public/v1/rx/cases/submit",e)}async getQuestionsForProduct(e){return this.http.get("/api/public/v1/rx/questions-for-product",{params:{productId:e}})}};var ke=class{constructor(e){let t=e.environment??"production",r=Z.resolveBaseUrl(t,e.baseUrl);this.config={...e,environment:t,baseUrl:r,timeout:e.timeout??3e4},this.http=new Z({baseUrl:r,timeout:this.config.timeout,apiKey:e.apiKey,getToken:()=>this._sessionToken});let n=o=>{this._sessionToken=o};this.checkout=new ce(this.http,this.config.storeId,n),this.payment=new le(this.http,this.config.storeId,t,this.checkout),this.offers=new me(this.http,this.config.storeId,this.payment),this.customer=new pe(this.http,this.config.storeId),this.catalog=new ge(this.http,this.config.storeId),this.funnel=new fe(this.http,this.config.storeId,this.checkout,this.config.accountId),this.rx=new ye(this.http)}setSessionToken(e){this._sessionToken=e}};function Ne(s){return new ke(s)}var Me=F("react/jsx-runtime"),_e=(0,J.createContext)(null);function De({storeId:s,environment:e,apiKey:t,baseUrl:r,config:n,children:o}){let i=(0,J.useMemo)(()=>Ne(n??{storeId:s,environment:e,apiKey:t,baseUrl:r}),[s,e,t,r,n]),a=(0,J.useMemo)(()=>({client:i}),[i]);return(0,Me.jsx)(_e.Provider,{value:a,children:o})}function q(){let s=(0,J.useContext)(_e);if(!s)throw new Error("useHeadlessClient must be used within <TagadaHeadlessProvider>");return s.client}var T=F("react");function qe(s,e){let t=q(),[r,n]=(0,T.useState)(null),[o,i]=(0,T.useState)(!1),[a,u]=(0,T.useState)(null),c=(0,T.useCallback)(async()=>{if(s){i(!0),u(null);try{let I=await t.checkout.loadSession(s,e);n(I)}catch(I){u(I instanceof Error?I:new Error(String(I)))}finally{i(!1)}}},[t,s,e]);(0,T.useEffect)(()=>{c()},[c]);let f=(0,T.useCallback)(async I=>{i(!0),u(null);try{let P=await t.checkout.createSession(I),x=new URL(window.location.href);x.searchParams.set("checkoutToken",P.checkoutToken),x.searchParams.set("token",P.sessionToken),window.history.replaceState({},"",x.toString());let S=await t.checkout.loadSession(P.checkoutToken,P.sessionToken);n(S)}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}},[t]),d=(0,T.useCallback)(async I=>{if(r){i(!0);try{await t.checkout.updateCart(r.id,I),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),y=(0,T.useCallback)(async I=>{r&&await t.checkout.updateCustomer(r.id,I)},[t,r]),m=(0,T.useCallback)(async I=>{if(r){i(!0);try{await t.checkout.updateAddress(r.id,I),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),p=(0,T.useCallback)(async I=>{if(r){i(!0);try{await t.checkout.updateCustomerAndAddress(r.id,I),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),h=(0,T.useCallback)(async I=>{if(r){i(!0);try{await t.checkout.applyPromoCode(r.id,I),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),g=(0,T.useCallback)(async I=>{if(r){i(!0);try{await t.checkout.removePromoCode(r.id,I),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),l=(0,T.useCallback)(async()=>r?t.checkout.getShippingRates(r.id):[],[t,r]),R=(0,T.useCallback)(async I=>{if(r){i(!0);try{await t.checkout.selectShippingRate(r.id,I),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]);return{session:r,isLoading:o,error:a,refresh:c,createSession:f,updateCart:d,updateCustomer:y,updateAddress:m,updateCustomerAndAddress:p,applyPromo:h,removePromo:g,getShippingRates:l,selectShippingRate:R}}var b=F("react");var Fe=new Set;function he(s){return Fe.has(s)?!1:(Fe.add(s),!0)}function Ge(s){let e=q(),[t,r]=(0,b.useState)(null),[n,o]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),[u,c]=(0,b.useState)(!1),[f,d]=(0,b.useState)(null),[y,m]=(0,b.useState)(null),p=(0,b.useRef)(!1),h=(0,b.useRef)(!1),g=(0,b.useRef)(s);g.current=s,(0,b.useEffect)(()=>{if(typeof window>"u"||h.current)return;let v=new URLSearchParams(window.location.search),w=v.get("paymentAction"),C=v.get("paymentActionStatus"),U=v.get("paymentId");if(w!=="requireAction"||C!=="completed"||!U||(h.current=!0,!he(U)))return;c(!0),m(null),(async()=>{var k,A,H,Y;try{let _=await e.payment.resumeAfterRedirect(U),Se=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status"].forEach(Ze=>Se.delete(Ze));let We=Se.toString()?`${window.location.pathname}?${Se.toString()}`:window.location.pathname;window.history.replaceState({},document.title,We),_.status==="succeeded"?(A=(k=g.current)==null?void 0:k.onPaymentSuccess)==null||A.call(k,_):_.status==="failed"&&(m(new Error(_.error)),(Y=(H=g.current)==null?void 0:H.onPaymentFailed)==null||Y.call(H,_))}catch(_){m(_ instanceof Error?_:new Error(String(_)))}finally{c(!1)}})()},[e]);let l=(0,b.useCallback)(async(v,w)=>{var U;if(p.current)return;p.current=!0;let C=w!=null&&w.paymentSetupConfig?{paymentSetupConfig:w.paymentSetupConfig}:(U=g.current)!=null&&U.paymentSetupConfig?{paymentSetupConfig:g.current.paymentSetupConfig}:void 0;try{let[N,k,A]=await Promise.all([e.payment.getPaymentSetup(v,C),e.payment.getExpressMethods(v,C),e.payment.getStoreConfig()]);r(N),o(k),a(A)}catch(N){p.current=!1,m(N instanceof Error?N:new Error(String(N)))}},[e]),R=(0,b.useCallback)(async v=>{var w,C,U,N;c(!0),m(null);try{let k=await e.payment.processPayment(v);if(k.status==="requires_redirect"){if(k.method==="POST"&&k.postData){let A=document.createElement("form");A.method="POST",A.action=k.redirectUrl;for(let[H,Y]of Object.entries(k.postData)){let _=document.createElement("input");_.type="hidden",_.name=H,_.value=Y,A.appendChild(_)}document.body.appendChild(A),A.submit()}else window.location.href=k.redirectUrl;return k}return k.status==="succeeded"?(C=(w=g.current)==null?void 0:w.onPaymentSuccess)==null||C.call(w,k):k.status==="failed"&&(m(new Error(k.error)),(N=(U=g.current)==null?void 0:U.onPaymentFailed)==null||N.call(U,k)),k}catch(k){let A=k instanceof Error?k:new Error(String(k));return m(A),{status:"failed",error:A.message}}finally{c(!1)}},[e]),I=(0,b.useCallback)(v=>async()=>{c(!0),m(null);try{return await v()}catch(w){let C=w instanceof Error?w:new Error(String(w));throw m(C),C}finally{c(!1)}},[]),P=(0,b.useCallback)(async v=>{c(!0),m(null);try{let w=await e.payment.pay(v);return d(w),w}catch(w){let C=w instanceof Error?w:new Error(String(w));throw m(C),C}finally{c(!1)}},[e]),x=(0,b.useCallback)(v=>e.payment.tokenizeCard(v),[e]),S=(0,b.useCallback)(async v=>{let C=await I(()=>e.payment.processApplePay(v))();return d(C),C},[e,I]),E=(0,b.useCallback)(async v=>{let C=await I(()=>e.payment.processGooglePay(v))();return d(C),C},[e,I]),B=(0,b.useCallback)(async v=>{let C=await I(()=>e.payment.processApm(v))();return d(C),C},[e,I]),$=(0,b.useCallback)(v=>e.payment.pollPaymentStatus(v),[e]);return{paymentSetup:t,expressMethods:n,storeConfig:i,isProcessing:u,result:f,error:y,loadPaymentSetup:l,processPayment:R,pay:P,tokenizeCard:x,processApplePay:S,processGooglePay:E,processApm:B,pollStatus:$}}var O=F("react");function $e(s){let e=q(),[t,r]=(0,O.useState)(null),[n,o]=(0,O.useState)(null),[i,a]=(0,O.useState)(!1),[u,c]=(0,O.useState)(null),f=(0,O.useRef)(s);f.current=s;let d=(0,O.useRef)(!1);(0,O.useEffect)(()=>{var w;if(typeof window>"u"||(w=f.current)!=null&&w.disableAutoResume||d.current)return;let S=new URLSearchParams(window.location.search),E=S.get("paymentAction"),B=S.get("paymentActionStatus"),$=S.get("paymentId");if(E!=="requireAction"||B!=="completed"||!$||(d.current=!0,!he($)))return;a(!0),c(null),(async()=>{var C,U,N,k;try{let A=await e.payment.resumeAfterRedirect($),H=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status"].forEach(_=>H.delete(_));let Y=H.toString()?`${window.location.pathname}?${H.toString()}`:window.location.pathname;window.history.replaceState({},document.title,Y),A.status==="succeeded"?(U=(C=f.current)==null?void 0:C.onOfferAccepted)==null||U.call(C,A):A.status==="failed"&&(c(new Error(A.error)),(k=(N=f.current)==null?void 0:N.onOfferDeclined)==null||k.call(N,A))}catch(A){c(A instanceof Error?A:new Error(String(A)))}finally{a(!1)}})()},[e]);let y=(0,O.useCallback)(async S=>{a(!0),c(null);try{return await S()}catch(E){let B=E instanceof Error?E:new Error(String(E));throw c(B),B}finally{a(!1)}},[]),m=(0,O.useCallback)(S=>y(async()=>{let E=await e.offers.getOffer(S);return r(E),E}),[e,y]),p=(0,O.useCallback)(S=>e.offers.listOffers(S),[e]),h=(0,O.useCallback)(S=>y(async()=>{let E=await e.offers.previewOffer(S);return o(E),E}),[e,y]),g=(0,O.useCallback)(S=>y(()=>e.offers.payPreviewedOffer(S)),[e,y]),l=(0,O.useCallback)(async S=>{var E,B,$,v;a(!0),c(null);try{let w=await e.offers.processOfferPayment(S);if(w.status==="requires_redirect"){if(w.method==="POST"&&w.postData){let C=document.createElement("form");C.method="POST",C.action=w.redirectUrl;for(let[U,N]of Object.entries(w.postData)){let k=document.createElement("input");k.type="hidden",k.name=U,k.value=N,C.appendChild(k)}document.body.appendChild(C),C.submit()}else window.location.href=w.redirectUrl;return w}return w.status==="succeeded"?(B=(E=f.current)==null?void 0:E.onOfferAccepted)==null||B.call(E,w):w.status==="failed"&&(c(new Error(w.error)),(v=($=f.current)==null?void 0:$.onOfferDeclined)==null||v.call($,w)),w}catch(w){let C=w instanceof Error?w:new Error(String(w));return c(C),{status:"failed",error:C.message}}finally{a(!1)}},[e]),R=(0,O.useCallback)(S=>e.offers.toggleOrderBump(S),[e]),I=(0,O.useCallback)(S=>e.offers.listPostPurchaseOffers(S),[e]),P=(0,O.useCallback)(S=>y(()=>e.offers.acceptPostPurchaseOffer(S)),[e,y]),x=(0,O.useCallback)(S=>y(()=>e.offers.declinePostPurchaseOffer(S)),[e,y]);return{offer:t,preview:n,isLoading:i,error:u,getOffer:m,listOffers:p,previewOffer:h,processOfferPayment:l,payPreviewedOffer:g,toggleOrderBump:R,listPostPurchaseOffers:I,acceptPostPurchaseOffer:P,declinePostPurchaseOffer:x}}var G=F("react");function He(s){let e=q(),[t,r]=(0,G.useState)(null),[n,o]=(0,G.useState)([]),[i,a]=(0,G.useState)([]),[u,c]=(0,G.useState)(!1),[f,d]=(0,G.useState)(null),y=(0,G.useCallback)(async g=>{c(!0),d(null);try{let l=await e.customer.getProfile(g);r(l)}catch(l){d(l instanceof Error?l:new Error(String(l)))}finally{c(!1)}},[e]),m=(0,G.useCallback)(async g=>{try{let l=await e.customer.getOrders(g);o(l.orders)}catch(l){d(l instanceof Error?l:new Error(String(l)))}},[e]),p=(0,G.useCallback)(async g=>{try{let l=await e.customer.getSubscriptions(g);a(l)}catch(l){d(l instanceof Error?l:new Error(String(l)))}},[e]),h=(0,G.useCallback)(async(g,l)=>{try{let R=await e.customer.updateProfile(g,l);r(R)}catch(R){d(R instanceof Error?R:new Error(String(R)))}},[e]);return(0,G.useEffect)(()=>{s&&y(s)},[s,y]),{customer:t,orders:n,subscriptions:i,isLoading:u,error:f,loadCustomer:y,loadOrders:m,loadSubscriptions:p,updateProfile:h}}var Q=F("react");function je(){let s=q(),[e,t]=(0,Q.useState)([]),[r,n]=(0,Q.useState)(!1),[o,i]=(0,Q.useState)(null),a=(0,Q.useCallback)(async c=>{n(!0),i(null);try{let f=await s.catalog.getProducts(c);return t(f),f}catch(f){let d=f instanceof Error?f:new Error(String(f));throw i(d),d}finally{n(!1)}},[s]),u=(0,Q.useCallback)(async c=>{n(!0),i(null);try{return await s.catalog.getProduct(c)}catch(f){let d=f instanceof Error?f:new Error(String(f));throw i(d),d}finally{n(!1)}},[s]);return{products:e,isLoading:r,error:o,loadProducts:a,loadProduct:u}}var D=F("react");var ut=new Set(["approved","shipped","delivered","declined","cancelled","error"]);function Ke(){let s=q(),[e,t]=(0,D.useState)([]),[r,n]=(0,D.useState)(null),[o,i]=(0,D.useState)(!1),[a,u]=(0,D.useState)(null),c=(0,D.useRef)(null);(0,D.useEffect)(()=>()=>{c.current&&clearInterval(c.current)},[]);let f=(0,D.useCallback)(async(h,g)=>{i(!0),u(null);try{return await s.rx.isRequiredForProduct(h,g)}catch(l){let R=l instanceof Error?l:new Error(String(l));throw u(R),R}finally{i(!1)}},[s]),d=(0,D.useCallback)(async h=>{i(!0),u(null);try{return await s.rx.getQuestionsForProduct(h)}catch(g){let l=g instanceof Error?g:new Error(String(g));throw u(l),l}finally{i(!1)}},[s]),y=(0,D.useCallback)(async h=>{i(!0),u(null);try{let g=await s.rx.submitCase(h);return n(g),g}catch(g){let l=g instanceof Error?g:new Error(String(g));throw u(l),l}finally{i(!1)}},[s]),m=(0,D.useCallback)(async h=>{i(!0),u(null);try{let g=await s.rx.getCasesForOrder(h);return t(g.cases),g.cases}catch(g){let l=g instanceof Error?g:new Error(String(g));throw u(l),l}finally{i(!1)}},[s]),p=(0,D.useCallback)(({orderId:h,checkoutToken:g},l)=>{c.current&&clearInterval(c.current);let R=(l==null?void 0:l.intervalMs)??5e3,I=async()=>{var P;try{let x=await s.rx.getCasesForOrder({orderId:h,checkoutToken:g});t(x.cases),(P=l==null?void 0:l.onUpdate)==null||P.call(l,x.cases),x.cases.length>0&&x.cases.every(S=>ut.has(S.status))&&(c.current&&clearInterval(c.current),c.current=null)}catch(x){let S=x instanceof Error?x:new Error(String(x));u(S)}};return I(),c.current=setInterval(I,R),()=>{c.current&&clearInterval(c.current),c.current=null}},[s]);return{cases:e,lastSubmission:r,isLoading:o,error:a,isRequiredForProduct:f,getQuestionsForProduct:d,submitCase:y,fetchCasesForOrder:m,pollOrder:p}}var L=F("react");var Be=!1,ze=!1,Pe=[];function ve(){ze=!0;for(let s of Pe)s();Pe.length=0}function X(s,e={}){var t,r;return ze||(r=(t=window.google)==null?void 0:t.maps)!=null&&r.places?(ve(),Promise.resolve()):Be?new Promise(n=>Pe.push(n)):(Be=!0,new Promise((n,o)=>{if(Pe.push(n),document.querySelector('script[src*="maps.googleapis.com"]')){let c=()=>{var f,d;(d=(f=window.google)==null?void 0:f.maps)!=null&&d.places?ve():setTimeout(c,100)};c();return}let a=new URLSearchParams({key:s,libraries:"places",v:e.version??"weekly"});e.language&&a.set("language",e.language),e.region&&a.set("region",e.region);let u=document.createElement("script");u.src=`https://maps.googleapis.com/maps/api/js?${a}`,u.async=!0,u.defer=!0,u.onload=()=>ve(),u.onerror=()=>o(new Error("Failed to load Google Maps script")),document.head.appendChild(u)}))}var j=class s{static async searchPlaces(e,t={}){var n,o;if(!((o=(n=window.google)==null?void 0:n.maps)!=null&&o.places)||!e.trim())return[];let r=new window.google.maps.places.AutocompleteService;return new Promise(i=>{r.getPlacePredictions({input:e,types:t.types??["address"],componentRestrictions:t.componentRestrictions},(a,u)=>{var c,f,d;i(u===((d=(f=(c=window.google)==null?void 0:c.maps)==null?void 0:f.places)==null?void 0:d.PlacesServiceStatus.OK)&&a?a:[])})})}static async getPlaceDetails(e){var r,n;if(!((n=(r=window.google)==null?void 0:r.maps)!=null&&n.places))return null;let t=new window.google.maps.places.PlacesService(document.createElement("div"));return new Promise(o=>{t.getDetails({placeId:e,fields:["place_id","formatted_address","address_components","geometry"]},(i,a)=>{var u,c,f;o(a===((f=(c=(u=window.google)==null?void 0:u.maps)==null?void 0:c.places)==null?void 0:f.PlacesServiceStatus.OK)&&i?i:null)})})}static extractAddressComponents(e){let t={subpremise:"",streetNumber:"",route:"",locality:"",administrativeAreaLevel1:"",administrativeAreaLevel1Long:"",administrativeAreaLevel2:"",administrativeAreaLevel2Long:"",country:"",postalCode:"",fullStreetAddress:""},r="",n="",o="",i="",a="",u="",c="",f="";for(let m of e.address_components??[]){let p=m.types;p.includes("subpremise")&&(t.subpremise=m.long_name),p.includes("street_number")&&(t.streetNumber=m.long_name),p.includes("premise")&&(r=m.long_name),p.includes("route")&&(t.route=m.long_name),p.includes("neighborhood")&&(n=m.long_name),p.includes("sublocality_level_5")&&(o=m.long_name),p.includes("sublocality_level_4")&&(i=m.long_name),p.includes("sublocality_level_3")&&(a=m.long_name),p.includes("sublocality_level_2")&&(u=m.long_name),p.includes("sublocality_level_1")&&(c=m.long_name),p.includes("locality")&&(t.locality=m.long_name),p.includes("postal_town")&&(f=m.long_name),p.includes("administrative_area_level_2")&&(t.administrativeAreaLevel2=m.short_name,t.administrativeAreaLevel2Long=m.long_name),p.includes("administrative_area_level_1")&&(t.administrativeAreaLevel1=m.short_name,t.administrativeAreaLevel1Long=m.long_name),p.includes("country")&&(t.country=m.short_name),p.includes("postal_code")&&(t.postalCode=m.long_name)}t.locality||(t.locality=f||u||c||""),!t.administrativeAreaLevel1&&t.administrativeAreaLevel2&&(t.administrativeAreaLevel1=t.administrativeAreaLevel2Long||t.administrativeAreaLevel2,t.administrativeAreaLevel1Long=t.administrativeAreaLevel2Long);let d=t.streetNumber||r,y=t.route||o||i||a||n;if(t.subpremise&&d&&y)t.fullStreetAddress=`${t.subpremise}/${d} ${y}`;else if(d&&y)if(r&&i&&a){let m=`${a}-${i}-${r}`;u&&(m=`${m} ${u}`),t.fullStreetAddress=m}else t.fullStreetAddress=`${d} ${y}`;else y?t.fullStreetAddress=y:d&&(t.fullStreetAddress=d);return t.fullStreetAddress=t.fullStreetAddress.trim(),t}static extractFormattedAddress(e){let t=s.extractAddressComponents(e);return{address1:t.fullStreetAddress,city:t.locality,country:t.country,state:t.administrativeAreaLevel1,postal:t.postalCode}}};function Je(s){let{apiKey:e,language:t,region:r,version:n,defer:o=!1}=s,[i,a]=(0,L.useState)([]),[u,c]=(0,L.useState)(!1),[f,d]=(0,L.useState)(!1),y=(0,L.useRef)(null),m=(0,L.useRef)(null),p=(0,L.useCallback)(()=>{X(e,{language:t,region:r,version:n}).then(()=>d(!0))},[e,t,r,n]);(0,L.useEffect)(()=>{!e||o||p()},[e,o,p]),(0,L.useEffect)(()=>{if(f&&m.current){let{input:P,country:x}=m.current;m.current=null,h(P,x)}},[f]);let h=(0,L.useCallback)((P,x)=>{if(!f){o&&(m.current={input:P,country:x},p());return}if(P.length<3){a([]);return}y.current&&clearTimeout(y.current),y.current=setTimeout(async()=>{c(!0);let S=await j.searchPlaces(P,{componentRestrictions:x?{country:x.toLowerCase()}:void 0});a(S),c(!1)},300)},[f,o,p]),g=(0,L.useCallback)(P=>j.getPlaceDetails(P),[]),l=(0,L.useCallback)(P=>j.extractAddressComponents(P),[]),R=(0,L.useCallback)(P=>j.extractFormattedAddress(P),[]),I=(0,L.useCallback)(()=>a([]),[]);return{predictions:i,isLoading:u,isScriptLoaded:f,searchPlaces:h,getPlaceDetails:g,extractAddressComponents:l,extractFormattedAddress:R,clearPredictions:I}}var z=F("react");var Qe="https://cvwnizdbugpz6jwk.public.blob.vercel-storage.com/geodata/v1",be=["en","ru","de","da","fr","es","zh","hi","pt","ja","ar","it","he"],ee=new Map,we=new Map,Re=new Map,Ae=new Map;async function dt(s){let e=ee.get(s);if(e)return e;let t=Re.get(s);return t||(t=(async()=>{let r=`${Qe}/${s}/countries.json`,n=await fetch(r);if(!n.ok)throw new Error(`Geodata fetch failed: ${r} (${n.status})`);let o=await n.json();return ee.set(s,o),Re.delete(s),o})(),Re.set(s,t),t)}async function lt(s){let e=we.get(s);if(e)return e;let t=Ae.get(s);return t||(t=(async()=>{let r=`${Qe}/${s}/regions.json`,n=await fetch(r);if(!n.ok)throw new Error(`Geodata fetch failed: ${r} (${n.status})`);let o=await n.json();return we.set(s,o),Ae.delete(s),o})(),Ae.set(s,t),t)}function mt(s){return ee.get(s)||ee.get("en")||{}}function pt(s){return we.get(s)||we.get("en")||{}}async function te(s="en"){await Promise.all([dt(s),lt(s)])}var Ce=(s="en")=>{let e=mt(s);return Object.entries(e).map(([t,r])=>({code:t,name:r.n,iso3:r.i3,numeric:r.nu})).sort((t,r)=>t.name.localeCompare(r.name))},xe=(s,e="en")=>{let r=pt(e)[s];return r?r.map(([n,o])=>({code:n,name:o,countryCode:s})).sort((n,o)=>n.name.localeCompare(o.name)):[]};function re(s){return ee.has(s)}var K=class s{static ensureLoaded(e="en"){return te(e)}static getCountries(e="en"){let t=Ce(e),r={};for(let n of t)r[n.code]={iso:n.code,iso3:n.iso3??"",numeric:n.numeric??0,name:n.name};return r}static getCountryOptions(e="en"){return Ce(e).map(t=>({value:t.code,label:t.name}))}static getRegions(e,t="en"){return xe(e,t).map(r=>({iso:r.code,name:r.name}))}static getRegionOptions(e,t="en"){return s.getRegions(e,t).map(r=>({value:r.iso,label:r.name}))}static findRegion(e,t,r="en"){return s.getRegions(e,r).find(n=>n.iso===t)??null}static mapGoogleToISO(e,t,r,n="en"){let o=s.getRegions(r,n);if(o.length===0)return null;let i=o.find(a=>a.iso===e);return i||(i=o.find(a=>a.name.toLowerCase()===e.toLowerCase()),i)||(i=o.find(a=>a.name.toLowerCase()===t.toLowerCase()),i)?i:(i=o.find(a=>a.name.toLowerCase().includes(t.toLowerCase())||t.toLowerCase().includes(a.name.toLowerCase())),i??null)}static isLanguageLoaded(e){return re(e)}static getAvailableLanguages(){return be}};function Ie(s="en"){let[e,t]=(0,z.useState)(re(s));return(0,z.useEffect)(()=>{let r=!1;return te(s).then(()=>{r||t(!0)}).catch(n=>console.error("[headless-sdk] Failed to load geodata:",n)),()=>{r=!0}},[s]),(0,z.useMemo)(()=>e?{countries:K.getCountries(s),getRegions:r=>K.getRegions(r,s),findRegion:(r,n)=>K.findRegion(r,n,s),mapGoogleToISO:(r,n,o)=>K.mapGoogleToISO(r,n,o,s),isLoaded:!0}:{countries:{},getRegions:()=>[],findRegion:()=>null,mapGoogleToISO:()=>null,isLoaded:!1},[s,e])}function Ve(s="en"){let{countries:e,isLoaded:t}=Ie(s);return(0,z.useMemo)(()=>t?Object.values(e).map(r=>({value:r.iso,label:r.name})).sort((r,n)=>r.label.localeCompare(n.label)):[],[e,t])}function Ye(s,e="en"){let{getRegions:t,isLoaded:r}=Ie(e);return(0,z.useMemo)(()=>!r||!s?[]:t(s).map(n=>({value:n.iso,label:n.name})).sort((n,o)=>n.label.localeCompare(o.label)),[s,t,r])}var gt={USD:"$",EUR:"\u20AC",GBP:"\xA3",JPY:"\xA5",CAD:"C$",AUD:"A$",CHF:"CHF",CNY:"\xA5",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"z\u0142",CZK:"K\u010D",HUF:"Ft",RON:"lei",BGN:"\u043B\u0432",HRK:"kn",RUB:"\u20BD",UAH:"\u20B4",TRY:"\u20BA",BRL:"R$",MXN:"$",ZAR:"R",INR:"\u20B9",KRW:"\u20A9",THB:"\u0E3F",VND:"\u20AB",IDR:"Rp",MYR:"RM",SGD:"S$",PHP:"\u20B1",TWD:"NT$",HKD:"HK$",ILS:"\u20AA",AED:"\u062F.\u0625",SAR:"\u0631.\u0633",QAR:"\u0631.\u0642",KWD:"\u062F.\u0643",BHD:"\u062F.\u0628",OMR:"\u0631.\u0639.",EGP:"\xA3",NGN:"\u20A6",KES:"KSh",GHS:"\u20B5",COP:"$",ARS:"$",CLP:"$",PEN:"S/",CRC:"\u20A1",DOP:"RD$",JMD:"J$",BOB:"Bs",PYG:"\u20B2",GTQ:"Q",NIO:"C$",PAB:"B/.",PKR:"\u20A8",BDT:"\u09F3",LKR:"\u20A8",NPR:"\u20A8",GEL:"\u20BE",AMD:"\u058F",AZN:"\u20BC",KZT:"\u20B8"},ft={USD:"US Dollar",EUR:"Euro",GBP:"British Pound",JPY:"Japanese Yen",CAD:"Canadian Dollar",AUD:"Australian Dollar",CHF:"Swiss Franc",CNY:"Chinese Yuan",SEK:"Swedish Krona",NOK:"Norwegian Krone",DKK:"Danish Krone",PLN:"Polish Zloty",CZK:"Czech Koruna",HUF:"Hungarian Forint",BRL:"Brazilian Real",MXN:"Mexican Peso",INR:"Indian Rupee",KRW:"South Korean Won",THB:"Thai Baht",SGD:"Singapore Dollar",HKD:"Hong Kong Dollar",TWD:"Taiwan Dollar",ILS:"Israeli Shekel",AED:"UAE Dirham",SAR:"Saudi Riyal",ZAR:"South African Rand",TRY:"Turkish Lira",RUB:"Russian Ruble",NGN:"Nigerian Naira"},yt=new Set(["JPY","KRW","VND","IDR","LAK","KHR","MMK","PYG"]),V=class s{static getSymbol(e){return gt[e]??e}static getName(e){return ft[e]??e}static getDecimalPlaces(e){return yt.has(e)?0:2}static getCurrency(e){return{code:e,symbol:s.getSymbol(e),name:s.getName(e),decimalPlaces:s.getDecimalPlaces(e)}}};function Oe(s,e="USD",t="en-US"){let r=V.getDecimalPlaces(e),n=s/(r===0?100:Math.pow(10,r));try{return new Intl.NumberFormat(t,{style:"currency",currency:e,minimumFractionDigits:r,maximumFractionDigits:r}).format(n)}catch{return`${V.getSymbol(e)}${n.toFixed(r)}`}}return it(ht);})();
6
+ "use strict";var TagadaHeadlessReactBundle=(()=>{var rt=Object.create;var ie=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var F=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var at=(s,e)=>{for(var t in e)ie(s,t,{get:e[t],enumerable:!0})},Ee=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of st(e))!ot.call(s,n)&&n!==t&&ie(s,n,{get:()=>e[n],enumerable:!(r=nt(e,n))||r.enumerable});return s};var Le=(s,e,t)=>(t=s!=null?rt(it(s)):{},Ee(e||!s||!s.__esModule?ie(t,"default",{value:s,enumerable:!0}):t,s)),ct=s=>Ee(ie({},"__esModule",{value:!0}),s);var Ct={};at(Ct,{CurrencyUtils:()=>V,GoogleAutocompleteCore:()=>K,ISODataCore:()=>B,TagadaHeadlessProvider:()=>Fe,formatMoney:()=>Te,loadGoogleMapsScript:()=>te,parseTokensFromUrl:()=>Ne,useCatalog:()=>ze,useCheckout:()=>Ge,useCountryOptions:()=>Ze,useCustomer:()=>Ke,useGoogleAutocomplete:()=>Ve,useHeadlessClient:()=>D,useISOData:()=>Se,useOffers:()=>je,useOrder:()=>Be,usePayment:()=>He,useRegionOptions:()=>Xe,useRx:()=>Je});var Q=F("react");var q=class extends Error{constructor(e,t,r,n){super(e),this.name="TagadaError",this.code=t,this.statusCode=r,this.details=n}},oe=class extends q{constructor(e="Authentication failed. Check your API key or checkout token."){super(e,"auth_error",401),this.name="TagadaAuthError"}},ae=class extends q{constructor(e,t=[],r,n){super(e,"validation_error",422,{errors:t,...n}),this.name="TagadaValidationError",this.errors=t,this.appCode=r}},ce=class extends q{constructor(e,t){super(`${e} "${t}" not found.`,"not_found",404),this.name="TagadaNotFoundError"}},ue=class extends q{constructor(e=1e3){super(`Rate limited. Retry after ${e}ms.`,"rate_limit",429),this.name="TagadaRateLimitError",this.retryAfterMs=e}};var Z=class extends q{constructor(e="Network request failed. Check your connection."){super(e,"network_error"),this.name="TagadaNetworkError"}};var Ue={production:"https://api.tagada.io",development:"https://api.tagada.dev",local:"http://localhost:3000"},X=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.timeout=e.timeout,this.apiKey=e.apiKey,this.getToken=e.getToken}static resolveBaseUrl(e,t){return t??Ue[e]??Ue.production}async request(e,t={}){var d;let{method:r="GET",body:n,headers:o={},params:i,token:a,signal:u}=t,c=`${this.baseUrl}${e}`;if(i){let y=new URLSearchParams;for(let[g,k]of Object.entries(i))k!==void 0&&y.set(g,String(k));let f=y.toString();f&&(c+=`?${f}`)}let p={"Content-Type":"application/json",...o},l=a??this.apiKey??((d=this.getToken)==null?void 0:d.call(this));l&&(p["x-cms-token"]=l);let h=new AbortController,m=setTimeout(()=>h.abort(),this.timeout);try{let y=await fetch(c,{method:r,headers:p,body:n!=null?JSON.stringify(n):void 0,signal:u??h.signal});if(clearTimeout(m),y.ok){let f=await y.text();return f?JSON.parse(f):{}}throw await this.handleErrorResponse(y,e),new q("Unexpected error","unknown",y.status)}catch(y){throw clearTimeout(m),y instanceof q?y:y instanceof DOMException&&y.name==="AbortError"?new Z(`Request to ${e} timed out after ${this.timeout}ms.`):new Z(y instanceof Error?y.message:"Network request failed.")}}get(e,t){return this.request(e,{...t,method:"GET"})}post(e,t,r){return this.request(e,{...r,method:"POST",body:t})}patch(e,t,r){return this.request(e,{...r,method:"PATCH",body:t})}put(e,t,r){return this.request(e,{...r,method:"PUT",body:t})}delete(e,t){return this.request(e,{...t,method:"DELETE"})}async handleErrorResponse(e,t){let r={};try{r=await e.json()}catch{}let n=r.data??{},o=r.message??r.error??(typeof n.message=="string"?n.message:void 0)??(typeof r.data=="string"?r.data:void 0)??`Request failed: ${e.status} ${e.statusText} on ${t}`,i=typeof n.code=="string"?n.code:void 0;switch(e.status){case 401:case 403:throw new oe(o);case 404:throw new ce(t,"");case 422:{let a=Array.isArray(r.errors)?r.errors:[];throw new ae(o,a,i,r)}case 429:{let a=Number(e.headers.get("Retry-After")??"1")*1e3;throw new ue(a)}default:throw new q(o,"api_error",e.status,r)}}};var ee=class s{constructor(e,t,r){this.http=e;this.storeId=t;this.onTokenChange=r}getCurrentSession(){return this._currentSession}async loadSession(e,t,r){var a;t&&(this.sessionToken=t,(a=this.onTokenChange)==null||a.call(this,t));let n={skipAsyncWait:"false"};r!=null&&r.currency&&(n.currency=r.currency);let o=await this.http.get(`/api/v1/checkout-sessions/${e}/v2`,{params:n,token:this.sessionToken}),i=this.normalizeSession(o);return this._currentSession=i,i}async createSession(e){var u;let t=e.items.map(c=>({variantId:c.variantId,priceId:c.priceId,quantity:c.quantity})),r={storeId:this.storeId,lineItems:t};e.returnUrl&&(r.returnUrl=e.returnUrl);let n={};e.currency&&(n.currency=e.currency),e.customerEmail&&(n.email=e.customerEmail,n.firstName=e.customerFirstName,n.lastName=e.customerLastName),Object.keys(n).length>0&&(r.customer=n);let o=await this.http.post("/api/v1/checkout/session/init",r),a=new URL(o.checkoutUrl).searchParams.get("token")??"";return this.sessionToken=a,a&&((u=this.onTokenChange)==null||u.call(this,a)),{checkoutUrl:o.checkoutUrl,checkoutToken:o.checkoutToken,sessionToken:a,customerId:o.customerId}}async createSessionUrl(e){let t=await this.createSession({items:e.items,currency:e.currency,returnUrl:e.returnUrl,customerEmail:e.customerEmail,customerFirstName:e.customerFirstName,customerLastName:e.customerLastName}),r=e.origin??(typeof window<"u"?window.location.origin:""),n=e.checkoutPath??"/checkout",o=new URLSearchParams({checkoutToken:t.checkoutToken,sessionToken:t.sessionToken}),i=`${r}${n}?${o.toString()}`;return{...t,url:i}}static parseTokensFromUrl(e){if(typeof e>"u"&&typeof window>"u")return null;let t=e??window.location.href,r;try{r=new URL(t)}catch{return null}let n=r.searchParams.get("checkoutToken");if(!n)return null;let o=r.searchParams.get("sessionToken")??r.searchParams.get("token")??"";return{checkoutToken:n,sessionToken:o}}parseTokensFromUrl(e){return s.parseTokensFromUrl(e)}async updateCart(e,t){let r=t.map(n=>({variantId:n.variantId,priceId:n.priceId,quantity:n.quantity}));return this.http.post(`/api/v1/checkout-sessions/${e}/line-items`,{lineItems:r},{token:this.sessionToken})}async updateCustomer(e,t){t.email&&(this.customerEmail=t.email),t.firstName&&(this.customerFirstName=t.firstName),t.lastName&&(this.customerLastName=t.lastName),t.phone&&(this.customerPhone=t.phone)}async updateAddress(e,t){let r=this.mapAddress(t.shippingAddress),n=this.mapAddress(t.billingAddress),o=r??n??{},i=n??r,a=!!(t.billingAddress&&t.shippingAddress);await this.http.post(`/api/v1/checkout-sessions/${e}/customer-and-session-info`,{checkoutSessionId:e,customerData:{email:this.customerEmail},shippingAddress:o,billingAddress:i??{},differentBillingAddress:a},{token:this.sessionToken})}async updateCustomerAndAddress(e,t){t.customer.email&&(this.customerEmail=t.customer.email),t.customer.firstName&&(this.customerFirstName=t.customer.firstName),t.customer.lastName&&(this.customerLastName=t.customer.lastName),t.customer.phone&&(this.customerPhone=t.customer.phone);let r=this.mapAddress(t.shippingAddress),n=this.mapAddress(t.billingAddress),o=r??n??{},i=n??r,a=!!(t.billingAddress&&t.shippingAddress);await this.http.post(`/api/v1/checkout-sessions/${e}/customer-and-session-info`,{checkoutSessionId:e,customerData:{email:this.customerEmail},shippingAddress:o,billingAddress:i??{},differentBillingAddress:a},{token:this.sessionToken})}mapAddress(e){if(e)return ut({firstName:e.firstName??this.customerFirstName,lastName:e.lastName??this.customerLastName,phone:e.phone??this.customerPhone,address1:e.line1,address2:e.line2,city:e.city,state:e.state,postal:e.postalCode,country:e.country})}async applyPromoCode(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/promotions/apply`,{checkoutSessionId:e,code:t},{token:this.sessionToken})}async removePromoCode(e,t){let r=t??"default";await this.http.delete(`/api/v1/checkout-sessions/${e}/promotions/${r}`,{token:this.sessionToken})}async getShippingRates(e){return((await this.http.get(`/api/v1/checkout-sessions/${e}/shipping-rates`,{token:this.sessionToken})).rates??[]).map(r=>this.normalizeShippingRate(r))}normalizeShippingRate(e){return{id:e.id,name:e.name??e.shippingRateName??"",description:e.description??void 0,amount:e.amount??0,currency:e.currency??"USD",estimatedDays:e.estimatedDays??e.estimatedDeliveryTime??void 0}}async selectShippingRate(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/shipping-rate`,{checkoutSessionId:e,shippingRateId:t},{token:this.sessionToken})}normalizeSession(e){var p;let t=e.checkoutSession,r=t.orderSummaries??[],n=e.summary??t.summary??r[0]??{},o=t.sessionLineItems??[],i=t.customer,a=(p=n.currency??t.selectedPresentmentCurrency)==null?void 0:p.toUpperCase(),u=o.map(l=>{let h=l.price,m=l.variant??(h==null?void 0:h.variant)??{},d=l.product??m.product??{},y=(h==null?void 0:h.currencyOptions)??{},f=(a?y[a]:void 0)??y[Object.keys(y)[0]],g=(f==null?void 0:f.amount)??0;return{id:l.id,variantId:l.variantId,priceId:l.priceId,productName:d.name??"",variantName:m.name??"",quantity:l.quantity??1,unitAmount:g,totalAmount:g*(l.quantity??1),currency:a??"USD",imageUrl:m.imageUrl??d.imageUrl??""}}),c=n.items??[];return{id:t.id,storeId:t.storeId,checkoutToken:t.checkoutToken,currency:a??"USD",items:u,totals:{subtotal:n.subtotalAmount??0,discount:n.totalPromotionAmount??0,shipping:n.shippingCost??0,tax:n.totalTaxAmount??0,total:n.totalAmount??c.reduce((l,h)=>l+(h.amount??0),0),currency:a??"USD"},customer:i?{id:i.id,email:i.email,firstName:i.firstName,lastName:i.lastName,phone:i.phone}:void 0,shippingAddress:this.normalizeAddress(t.shippingAddress),billingAddress:this.normalizeAddress(t.billingAddress),selectedShippingRateId:t.shippingRateId??null,metadata:t.metadata}}normalizeAddress(e){if(!e||typeof e!="object")return;let t=e,r={firstName:t.firstName,lastName:t.lastName,line1:t.line1??t.address1,line2:t.line2??t.address2,city:t.city,state:t.state,postalCode:t.postalCode??t.postal,country:t.country,phone:t.phone};return Object.values(r).some(n=>n!==void 0&&n!=="")?r:void 0}},Ne=ee.parseTokensFromUrl;function ut(s){let e={};for(let[t,r]of Object.entries(s))r!=null&&r!==""&&(e[t]=r);return Object.keys(e).length>0?e:void 0}function de(s){var t,r;if(!s)return;let e={firstName:s.givenName,lastName:s.familyName,line1:(t=s.addressLines)==null?void 0:t[0],line2:(r=s.addressLines)==null?void 0:r[1],city:s.locality,state:s.administrativeArea,postalCode:s.postalCode,country:s.countryCode,phone:s.phoneNumber};return _e(e)?e:void 0}function le(s){if(!s)return;let[e,...t]=(s.name??"").trim().split(/\s+/),r={firstName:e||void 0,lastName:t.length?t.join(" "):void 0,line1:s.address1,line2:[s.address2,s.address3].filter(Boolean).join(" ")||void 0,city:s.locality,state:s.administrativeArea,postalCode:s.postalCode,country:s.countryCode,phone:s.phoneNumber};return _e(r)?r:void 0}function _e(s){var e,t;return!!((e=s.line1)!=null&&e.trim()&&((t=s.country)!=null&&t.trim()))}var me=class{constructor(e,t,r,n){this.http=e;this.storeId=t;this.environment=r;this.checkout=n;this.lastPaymentSetup=null}async getPaymentSetup(e,t){if(t!=null&&t.paymentSetupConfig)return this.lastPaymentSetup=t.paymentSetupConfig,t.paymentSetupConfig;let r=this.readInjectedStepConfig();if(r)return this.lastPaymentSetup=r,r;let n=await this.http.get("/api/v1/payment-methods",{params:{checkoutSessionId:e}}),o={};for(let i of n.methods??[]){let a=i.provider?`${i.method}:${i.provider}`:i.method;o[a]=i}return this.lastPaymentSetup=o,o}async getExpressMethods(e,t){var o,i,a,u,c,p,l,h;let r=await this.getPaymentSetup(e,t),n={};for(let[m,d]of Object.entries(r)){if(!d.enabled)continue;if(m.startsWith("express_checkout:")&&d.methods){let g={available:!0,processorId:d.processorId,publishableKey:d.publishableKey,metadata:d.metadata};if((o=d.methods.apple_pay)!=null&&o.enabled){let k=typeof window<"u"&&"ApplePaySession"in window&&((a=(i=window.ApplePaySession)==null?void 0:i.canMakePayments)==null?void 0:a.call(i));n.applePay={...g,type:"apple_pay",available:!!k}}(u=d.methods.google_pay)!=null&&u.enabled&&(n.googlePay={...g,type:"google_pay"}),(c=d.methods.link)!=null&&c.enabled&&(n.link={...g,type:"link"}),(p=d.methods.klarna_express)!=null&&p.enabled&&(n.klarna={...g,type:"klarna_express"});continue}if(!d.express)continue;let y=d.method,f={type:y,available:!0,processorId:d.processorId,publishableKey:d.publishableKey,metadata:d.metadata};if(y==="apple_pay"||d.type==="apple_pay"){let g=typeof window<"u"&&"ApplePaySession"in window&&((h=(l=window.ApplePaySession)==null?void 0:l.canMakePayments)==null?void 0:h.call(l));n.applePay={...f,available:!!g}}else y==="google_pay"||d.type==="google_pay"?n.googlePay=f:y==="paypal"?n.paypal=f:y==="klarna"||y==="klarna_express"?n.klarna=f:y==="link"&&(n.link=f)}return n}async getStoreConfig(){let e=await this.http.get("/api/v1/checkout/config",{params:{storeId:this.storeId}});return e.config??e}async getEnabledMethods(e,t){let r=await this.getPaymentSetup(e,t);return Object.entries(r).filter(([,n])=>n.enabled).map(([n])=>n)}async tokenizeCard(e){let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let n={cardNumber:e.cardNumber,expiryDate:e.expiryDate,cvc:e.cvc};e.cardholderName&&(n.cardholderName=e.cardholderName);let o=await r.tokenizeCardRaw(n);return{tagadaToken:t.createTagadaToken(o,r.getProvider().getProviderName()),rawToken:o}}async createInstrument(e){return this.http.post("/api/v1/payment/create-instrument-from-token",{tagadaToken:e.tagadaToken})}async create3dsSession(e){return this.http.post("/api/public/v1/threeds/create-session",{provider:e.provider??"basis_theory",storeId:this.storeId,paymentInstrumentId:e.paymentInstrumentId,sessionData:e.sessionData})}async pay(e){return e.tagadaToken&&!e.paymentInstrumentId?this.http.post("/api/v1/payment/pay-with-token",{tagadaToken:e.tagadaToken,checkoutSessionId:e.checkoutSessionId,returnUrl:e.returnUrl,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:e.isExpress,metadata:e.metadata}):this.http.post("/api/public/v1/checkout/pay-v2",{checkoutSessionId:e.checkoutSessionId,paymentInstrumentId:e.paymentInstrumentId,storeId:this.storeId,paymentFlowId:e.paymentFlowId,threedsSessionId:e.threedsSessionId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:e.isExpress,metadata:e.metadata,returnUrl:e.returnUrl})}async payDirect(e){return this.http.post("/api/public/v1/checkout/pay-v2",{checkoutSessionId:e.checkoutSessionId,paymentInstrumentId:e.paymentInstrumentId??"",storeId:this.storeId,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:e.isExpress,threedsSessionId:e.threedsSessionId,returnUrl:e.returnUrl})}async syncWalletContact(e,t){let{shippingAddress:r,billingAddress:n}=t;if(!r&&!n)return;if(!this.checkout)throw new Error("PaymentModule cannot persist the wallet contact: no CheckoutModule was provided. Build the SDK through createTagadaClient() rather than constructing PaymentModule directly.");let o={};t.email&&(o.email=t.email),t.phone&&(o.phone=t.phone),t.firstName&&(o.firstName=t.firstName),t.lastName&&(o.lastName=t.lastName),await this.checkout.updateCustomerAndAddress(e,{customer:o,shippingAddress:r,billingAddress:n})}async processApplePay(e){var a,u,c,p,l,h,m,d,y;await this.syncWalletContact(e.checkoutSessionId,{shippingAddress:de(e.shippingContact),billingAddress:de(e.billingContact),email:((a=e.shippingContact)==null?void 0:a.emailAddress)??((u=e.billingContact)==null?void 0:u.emailAddress),phone:((c=e.shippingContact)==null?void 0:c.phoneNumber)??((p=e.billingContact)==null?void 0:p.phoneNumber),firstName:((l=e.shippingContact)==null?void 0:l.givenName)??((h=e.billingContact)==null?void 0:h.givenName),lastName:((m=e.shippingContact)==null?void 0:m.familyName)??((d=e.billingContact)==null?void 0:d.familyName)});let t=e.merchantRegistrationId??((y=await this.resolveApplePayRegistration(e.checkoutSessionId))==null?void 0:y.merchantRegistrationId),r=await this.loadCoreJs(),n=new r.Tokenizer({environment:this.environment});await n.initialize();let o=await n.tokenizeApplePay(e.applePayToken,t),i=btoa(JSON.stringify(r.createTagadaDigitalWalletToken(o,"apple_pay")));return this.pay({checkoutSessionId:e.checkoutSessionId,tagadaToken:i,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:"apple_pay",isExpress:!0})}async resolveApplePayRegistration(e){if(typeof window>"u")return null;let t=window.location.hostname.toLowerCase().split(":")[0];t.startsWith("www.")&&(t=t.slice(4));let r=o=>{var i;for(let a of Object.values(o??{})){let u=(i=a==null?void 0:a.metadata)==null?void 0:i.applePayByok;if(!u||typeof u!="object")continue;let c=u[t];if(c!=null&&c.merchantRegistrationId)return{merchantRegistrationId:c.merchantRegistrationId,displayName:c.displayName}}return null},n=r(this.readInjectedStepConfig())??r(this.lastPaymentSetup);if(n)return n;if(this.lastPaymentSetup||this.readInjectedStepConfig()||!e)return null;try{return r(await this.getPaymentSetup(e))}catch{return null}}async processGooglePay(e){var i,a,u,c;await this.syncWalletContact(e.checkoutSessionId,{shippingAddress:le(e.shippingAddress),billingAddress:le(e.billingAddress),email:e.email??((i=e.shippingAddress)==null?void 0:i.emailAddress)??((a=e.billingAddress)==null?void 0:a.emailAddress),phone:((u=e.shippingAddress)==null?void 0:u.phoneNumber)??((c=e.billingAddress)==null?void 0:c.phoneNumber)});let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let n=await r.tokenizeGooglePay(e.googlePayToken),o=btoa(JSON.stringify(t.createTagadaDigitalWalletToken(n,"google_pay")));return this.pay({checkoutSessionId:e.checkoutSessionId,tagadaToken:o,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:"google_pay",isExpress:!0})}async processApm(e){return this.payDirect({checkoutSessionId:e.checkoutSessionId,paymentMethod:e.paymentMethod,processorId:e.processorId,paymentFlowId:e.paymentFlowId})}async processStripeExpress(e){return this.payDirect({checkoutSessionId:e.checkoutSessionId,processorId:e.processorId,paymentMethod:e.paymentMethod,isExpress:!0})}async processPayment(e){!e.returnUrl&&typeof window<"u"&&(e={...e,returnUrl:window.location.href});let t=await this.pay(e);return this.finalize(t,{returnUrl:e.returnUrl})}async finalize(e,t){var o,i;let r=e.payment,n=(t==null?void 0:t.returnUrl)??(typeof window<"u"?window.location.href:void 0);return r.status==="succeeded"?{status:"succeeded",payment:r,order:e.order}:r.status==="failed"||r.status==="declined"?{status:"failed",error:((o=r.requireActionData)==null?void 0:o.message)||((i=r.requireActionData)==null?void 0:i.errorCode)||`Payment ${r.status}`,payment:r}:r.requireAction&&r.requireAction!=="none"&&r.requireActionData?this.handlePaymentAction(r,{returnUrl:n}):this.pollUntilDone(r.id)}async resumeAfterRedirect(e){return this.pollUntilDone(e)}async maybeResumeFromUrl(e){if(typeof window>"u"&&!(e!=null&&e.url))return null;let t=(e==null?void 0:e.url)??window.location.href,r;try{r=new URL(t)}catch{return null}let n=r.searchParams.get("paymentAction"),o=r.searchParams.get("paymentActionStatus"),i=r.searchParams.get("paymentId");if(n!=="requireAction"||o!=="completed"||!i)return null;let a=await this.resumeAfterRedirect(i);if((e==null?void 0:e.cleanUrl)!==!1&&typeof window<"u"&&!(e!=null&&e.url)){let u=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status","sessionId"].forEach(p=>u.delete(p));let c=u.toString();try{window.history.replaceState({},document.title,window.location.pathname+(c?"?"+c:""))}catch{}}return a}async getPaymentStatus(e){return this.http.get(`/api/v1/payments/${e}`)}async pollPaymentStatus(e,t){let r=(t==null?void 0:t.intervalMs)??1500,n=(t==null?void 0:t.timeoutMs)??6e4,o=Date.now();for(;Date.now()-o<n;){let i=await this.getPaymentStatus(e);if(i.status==="succeeded"||i.status==="failed"||i.status==="declined")return i;await new Promise(a=>setTimeout(a,r))}throw new Error(`Payment ${e} did not reach terminal status within ${n}ms.`)}async completeAfter3ds(e){return this.http.post("/api/v1/payments/complete-after-3ds",{paymentId:e})}async markActionProcessed(e){try{await this.http.post("/api/v1/payments/require-action/processed",{paymentId:e})}catch{}}async handlePaymentAction(e,t){let r=e.requireActionData;switch(await this.markActionProcessed(e.id),r.type){case"threeds_auth":return this.handleThreedsAuth(e,t);case"processor_auth":case"redirect_to_payment":return this.extractRedirect(e,r);case"redirect":return this.extractRedirect(e,r);case"error":return{status:"failed",error:r.message||r.errorCode||"Payment failed",payment:e};default:return this.extractRedirect(e,r)}}extractRedirect(e,t){var o,i;let r=(o=t.metadata)==null?void 0:o.redirect,n=(r==null?void 0:r.redirectUrl)||t.redirectUrl;return n?{status:"requires_redirect",redirectUrl:n,method:((i=r==null?void 0:r.method)==null?void 0:i.toUpperCase())||"GET",postData:r==null?void 0:r.data,paymentId:e.id}:{status:"failed",error:`Payment requires action (${t.type}) but no redirect URL was provided`,payment:e}}async handleThreedsAuth(e,t){var o,i;let r=(i=(o=e.requireActionData)==null?void 0:o.metadata)==null?void 0:i.threedsSession;if(!(r!=null&&r.externalSessionId))return this.extractRedirect(e,e.requireActionData);let n;try{n=await import("@tagadapay/core-js")}catch{return r.acsChallengeUrl?{status:"requires_redirect",redirectUrl:r.acsChallengeUrl,paymentId:e.id}:this.extractRedirect(e,e.requireActionData)}try{let a=new n.ThreedsManager({provider:"basis_theory"});return await a.initialize({apiKey:void 0}),await a.startChallenge({sessionId:r.externalSessionId,acsChallengeUrl:r.acsChallengeUrl,acsTransactionId:r.acsTransID,threeDSVersion:r.messageVersion}),await this.completeAfter3ds(e.id),this.pollUntilDone(e.id)}catch{return r.acsChallengeUrl?{status:"requires_redirect",redirectUrl:r.acsChallengeUrl,paymentId:e.id}:{status:"failed",error:"3D Secure authentication failed",payment:e}}}async pollUntilDone(e,t){let r=(t==null?void 0:t.intervalMs)??1500,n=(t==null?void 0:t.timeoutMs)??6e4,o=Date.now(),i=0;for(;Date.now()-o<n;){let a;try{a=await this.getPaymentStatus(e),i=0}catch{if(i++,i>=3)return{status:"failed",error:"Payment verification failed due to network errors"};await new Promise(u=>setTimeout(u,r));continue}if(a.status==="succeeded"||a.status==="pending"&&a.subStatus==="authorized")return{status:"succeeded",payment:a,order:a.order};if(a.status==="failed"||a.status==="declined")return{status:"failed",error:a.status,payment:a};if(a.requireAction&&a.requireAction!=="none"&&a.requireActionData&&!a.requireActionData.processed)return this.handlePaymentAction(a,{});await new Promise(u=>setTimeout(u,r))}return{status:"pending",paymentId:e}}readInjectedStepConfig(){if(typeof window>"u")return null;let e=window.__TGD_STEP_CONFIG__;if(!e)return null;try{let t=typeof e=="string"?JSON.parse(e):e;return(t==null?void 0:t.paymentSetupConfig)??null}catch{return null}}async loadCoreJs(){try{return await import("@tagadapay/core-js")}catch{throw new Error("This method requires @tagadapay/core-js. Install it: npm install @tagadapay/core-js")}}};var pe=class{constructor(e,t,r){this.http=e;this.storeId=t;this.payment=r}async getOffer(e){return this.http.get(`/api/v1/offers/${e}`)}async listOffers(e){var o;let t=`/api/v1/stores/${this.storeId}/offers`,r=[];if(e!=null&&e.type&&r.push(`type=${encodeURIComponent(e.type)}`),(o=e==null?void 0:e.ids)!=null&&o.length)for(let i of e.ids)r.push(`ids=${encodeURIComponent(i)}`);return r.length&&(t+=`?${r.join("&")}`),(await this.http.get(t)).offers??[]}async previewOffer(e){return this.http.post(`/api/v1/offers/${e.offerId}/preview`,{offerId:e.offerId,currency:e.currency??"",lineItems:e.lineItems})}async payPreviewedOffer(e){return this.http.post(`/api/v1/offers/${e.offerId}/pay-preview`,{offerId:e.offerId,currency:e.currency??"",lineItems:e.lineItems,returnUrl:e.returnUrl??(typeof window<"u"?window.location.href:""),mainOrderId:e.mainOrderId,paymentInstrumentId:e.paymentInstrumentId})}async processOfferPayment(e){if(!this.payment)throw new Error("OffersModule: no PaymentModule injected. Use createHeadlessClient() instead of constructing OffersModule directly.");let t=e.returnUrl??(typeof window<"u"?window.location.href:void 0),r=await this.payPreviewedOffer({...e,returnUrl:t});return this.payment.finalize({payment:r.payment,order:r.order},{returnUrl:t})}async toggleOrderBump(e){return this.http.post(`/api/v1/checkout-sessions/${e.checkoutSessionId}/toggle-order-bump`,{orderBumpOfferId:e.orderBumpOfferId,selected:e.selected})}async listPostPurchaseOffers(e){let t=await this.http.get(`/api/v1/post-purchase/${e}/offers`);return Array.isArray(t)?t:[]}async acceptPostPurchaseOffer(e){return this.http.post(`/api/v1/orders/${e.orderId}/post-purchase-offers/${e.offerId}/accept`,{items:e.items??[]})}async declinePostPurchaseOffer(e){return this.http.post(`/api/v1/orders/${e.orderId}/post-purchase-offers/${e.offerId}/decline`)}};var ge=class{constructor(e,t){this.http=e;this.storeId=t}async getProfile(e){return(await this.http.get(`/api/v1/customers/${e}`,{params:{storeId:this.storeId}})).customer}async getByEmail(e){try{return(await this.http.get("/api/v1/customers/by-email",{params:{email:e,storeId:this.storeId}})).customer}catch{return null}}async updateProfile(e,t){return(await this.http.patch(`/api/v1/customers/${e}`,{storeId:this.storeId,...t})).customer}async getOrders(e,t){return this.http.get(`/api/v1/customers/${e}/orders`,{params:{storeId:this.storeId,limit:t==null?void 0:t.limit,offset:t==null?void 0:t.offset}})}async getOrder(e,t){var u,c;let r=async()=>(await this.http.get(`/api/v1/orders/${e}`,{params:{storeId:this.storeId}})).order,n=await r();if(!(t!=null&&t.waitForRelatedOrders)||(u=n.relatedOrders)!=null&&u.length)return n;let o=t.timeoutMs??8e3,i=t.intervalMs??2e3,a=Date.now()+o;for(;Date.now()<a;)if(await new Promise(p=>setTimeout(p,Math.min(i,Math.max(0,a-Date.now())))),n=await r(),(c=n.relatedOrders)!=null&&c.length)return n;return n}async getSubscriptions(e){return(await this.http.get(`/api/v1/customers/${e}/subscriptions`,{params:{storeId:this.storeId}})).subscriptions}async getSubscription(e){return(await this.http.get(`/api/v1/subscriptions/${e}`,{params:{storeId:this.storeId}})).subscription}};var fe=class{constructor(e,t){this.http=e;this.storeId=t}async getProducts(e){var n,o;let t={storeId:this.storeId,includeVariants:!0,includePrices:!0};return(n=e==null?void 0:e.productIds)!=null&&n.length&&(t.productIds=e.productIds),(o=e==null?void 0:e.variantIds)!=null&&o.length&&(t.variantIds=e.variantIds),(await this.http.post("/api/v1/products",t)).items??[]}async getProduct(e){return(await this.getProducts({productIds:[e]}))[0]??null}};var ye=class{constructor(e,t,r,n){this.http=e;this.storeId=t;this.checkout=r;this.accountId=n}async navigate(e){var a;let t=this.checkout.getCurrentSession();if(!t)throw new q("No checkout session loaded. Call sdk.checkout.loadSession(...) before sdk.funnel.navigate(...).","no_cart_loaded");let r=e.accountId??this.accountId;if(!r)throw new q("accountId is required for funnel.navigate(). Set it on createHeadlessClient({ accountId }) or pass it per call.","missing_account_id");let n=e.currentUrl??(typeof globalThis<"u"?(a=globalThis.location)==null?void 0:a.href:void 0);await this.ensureCmsSession(t,r,e);let o=await this.initializeFunnel({funnelId:e.funnelId,stepId:e.stepId,accountId:r,currentUrl:n});return{url:await this.runNavigate({funnelSessionId:o,stepId:e.stepId,session:t,input:e,currentUrl:n}),funnelSessionId:o}}async ensureCmsSession(e,t,r){var i,a,u;if(this._cmsToken&&this._cmsSessionId&&this._cmsCustomerId)return;let n=await this.http.post("/api/v1/cms/session/anonymous",{storeId:this.storeId,role:"anonymous",draft:!1});this._cmsToken=n.token,this._cmsSessionId=n.sessionId;let o=await this.http.post("/api/v1/cms/session/v2/init",{storeId:this.storeId,accountId:t,customerId:"anon_placeholder",browserLocale:((i=r.customer)==null?void 0:i.locale)??dt(),userAgent:lt(),queryCurrency:((a=r.customer)==null?void 0:a.currency)??e.currency,queryLocale:(u=r.customer)==null?void 0:u.locale},{token:this._cmsToken});this._cmsCustomerId=o.customer.id}async initializeFunnel(e){return(await this.http.post("/api/v1/funnel/initialize",{cmsSession:{customerId:this._cmsCustomerId,sessionId:this._cmsSessionId,storeId:this.storeId,accountId:e.accountId},funnelId:e.funnelId,entryStepId:e.stepId,funnelStepId:e.stepId,currentUrl:e.currentUrl,draft:!1},{token:this._cmsToken})).context.sessionId}async runNavigate(e){var l,h,m,d;let{funnelSessionId:t,stepId:r,session:n,input:o,currentUrl:i}=e,a=n.items.map(y=>({variantId:y.variantId,priceId:y.priceId,quantity:y.quantity})),u=o.discountCodes??(n.promotionCode?[n.promotionCode]:void 0),c={email:((l=o.customer)==null?void 0:l.email)??((h=n.customer)==null?void 0:h.email),currency:((m=o.customer)==null?void 0:m.currency)??n.currency,locale:(d=o.customer)==null?void 0:d.locale};return(await this.http.post("/api/v1/funnel/navigate",{sessionId:t,currentUrl:i,funnelStepId:r,fireAndForget:!1,event:{type:"INIT_CHECKOUT",data:{checkoutInit:{cartToken:n.id,lineItems:a,customer:c,returnUrl:o.returnUrl,storeId:this.storeId,metadata:o.metadata,discountCodes:u,externalShipping:o.externalShipping}}}},{token:this._cmsToken})).result.url}};function dt(){return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}function lt(){return typeof navigator<"u"&&navigator.userAgent?navigator.userAgent:"tagadapay-headless-sdk"}var he=class{constructor(e){this.http=e}async isRequiredForProduct(e,t){return this.http.get("/api/public/v1/rx/required-for-product",{params:{productId:e,clinicalNetworkId:t==null?void 0:t.clinicalNetworkId}})}async getCasesForOrder(e){return this.http.post("/api/public/v1/rx/cases/lookup",e)}async submitCase(e){return this.http.post("/api/public/v1/rx/cases/submit",e)}async getQuestionsForProduct(e){return this.http.get("/api/public/v1/rx/questions-for-product",{params:{productId:e}})}};var Re=class{constructor(e){let t=e.environment??"production",r=X.resolveBaseUrl(t,e.baseUrl);this.config={...e,environment:t,baseUrl:r,timeout:e.timeout??3e4},this.http=new X({baseUrl:r,timeout:this.config.timeout,apiKey:e.apiKey,getToken:()=>this._sessionToken});let n=o=>{this._sessionToken=o};this.checkout=new ee(this.http,this.config.storeId,n),this.payment=new me(this.http,this.config.storeId,t,this.checkout),this.offers=new pe(this.http,this.config.storeId,this.payment),this.customer=new ge(this.http,this.config.storeId),this.catalog=new fe(this.http,this.config.storeId),this.funnel=new ye(this.http,this.config.storeId,this.checkout,this.config.accountId),this.rx=new he(this.http)}setSessionToken(e){this._sessionToken=e}};function De(s){return new Re(s)}var qe=F("react/jsx-runtime"),Me=(0,Q.createContext)(null);function Fe({storeId:s,environment:e,apiKey:t,baseUrl:r,config:n,children:o}){let i=(0,Q.useMemo)(()=>De(n??{storeId:s,environment:e,apiKey:t,baseUrl:r}),[s,e,t,r,n]),a=(0,Q.useMemo)(()=>({client:i}),[i]);return(0,qe.jsx)(Me.Provider,{value:a,children:o})}function D(){let s=(0,Q.useContext)(Me);if(!s)throw new Error("useHeadlessClient must be used within <TagadaHeadlessProvider>");return s.client}var T=F("react");function Ge(s,e){let t=D(),[r,n]=(0,T.useState)(null),[o,i]=(0,T.useState)(!1),[a,u]=(0,T.useState)(null),c=(0,T.useCallback)(async()=>{if(s){i(!0),u(null);try{let C=await t.checkout.loadSession(s,e);n(C)}catch(C){u(C instanceof Error?C:new Error(String(C)))}finally{i(!1)}}},[t,s,e]);(0,T.useEffect)(()=>{c()},[c]);let p=(0,T.useCallback)(async C=>{i(!0),u(null);try{let P=await t.checkout.createSession(C),I=new URL(window.location.href);I.searchParams.set("checkoutToken",P.checkoutToken),I.searchParams.set("token",P.sessionToken),window.history.replaceState({},"",I.toString());let O=await t.checkout.loadSession(P.checkoutToken,P.sessionToken);n(O)}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}},[t]),l=(0,T.useCallback)(async C=>{u(null);try{return await t.checkout.createSessionUrl(C)}catch(P){let I=P instanceof Error?P:new Error(String(P));throw u(I),I}},[t]),h=(0,T.useCallback)(async C=>{if(r){i(!0);try{await t.checkout.updateCart(r.id,C),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),m=(0,T.useCallback)(async C=>{r&&await t.checkout.updateCustomer(r.id,C)},[t,r]),d=(0,T.useCallback)(async C=>{if(r){i(!0);try{await t.checkout.updateAddress(r.id,C),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),y=(0,T.useCallback)(async C=>{if(r){i(!0);try{await t.checkout.updateCustomerAndAddress(r.id,C),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),f=(0,T.useCallback)(async C=>{if(r){i(!0);try{await t.checkout.applyPromoCode(r.id,C),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),g=(0,T.useCallback)(async C=>{if(r){i(!0);try{await t.checkout.removePromoCode(r.id,C),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]),k=(0,T.useCallback)(async()=>r?t.checkout.getShippingRates(r.id):[],[t,r]),E=(0,T.useCallback)(async C=>{if(r){i(!0);try{await t.checkout.selectShippingRate(r.id,C),await c()}catch(P){u(P instanceof Error?P:new Error(String(P)))}finally{i(!1)}}},[t,r,c]);return{session:r,isLoading:o,error:a,refresh:c,createSession:p,createSessionUrl:l,updateCart:h,updateCustomer:m,updateAddress:d,updateCustomerAndAddress:y,applyPromo:f,removePromo:g,getShippingRates:k,selectShippingRate:E}}var b=F("react");var $e=new Set;function Pe(s){return $e.has(s)?!1:($e.add(s),!0)}function He(s){let e=D(),[t,r]=(0,b.useState)(null),[n,o]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),[u,c]=(0,b.useState)(!1),[p,l]=(0,b.useState)(null),[h,m]=(0,b.useState)(null),d=(0,b.useRef)(!1),y=(0,b.useRef)(!1),f=(0,b.useRef)(s);f.current=s,(0,b.useEffect)(()=>{if(typeof window>"u"||y.current)return;let v=new URLSearchParams(window.location.search),w=v.get("paymentAction"),S=v.get("paymentActionStatus"),U=v.get("paymentId");if(w!=="requireAction"||S!=="completed"||!U||(y.current=!0,!Pe(U)))return;c(!0),m(null),(async()=>{var R,A,H,Y;try{let _=await e.payment.resumeAfterRedirect(U),ke=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status"].forEach(tt=>ke.delete(tt));let et=ke.toString()?`${window.location.pathname}?${ke.toString()}`:window.location.pathname;window.history.replaceState({},document.title,et),_.status==="succeeded"?(A=(R=f.current)==null?void 0:R.onPaymentSuccess)==null||A.call(R,_):_.status==="failed"&&(m(new Error(_.error)),(Y=(H=f.current)==null?void 0:H.onPaymentFailed)==null||Y.call(H,_))}catch(_){m(_ instanceof Error?_:new Error(String(_)))}finally{c(!1)}})()},[e]);let g=(0,b.useCallback)(async(v,w)=>{var U;if(d.current)return;d.current=!0;let S=w!=null&&w.paymentSetupConfig?{paymentSetupConfig:w.paymentSetupConfig}:(U=f.current)!=null&&U.paymentSetupConfig?{paymentSetupConfig:f.current.paymentSetupConfig}:void 0;try{let[N,R,A]=await Promise.all([e.payment.getPaymentSetup(v,S),e.payment.getExpressMethods(v,S),e.payment.getStoreConfig()]);r(N),o(R),a(A)}catch(N){d.current=!1,m(N instanceof Error?N:new Error(String(N)))}},[e]),k=(0,b.useCallback)(async v=>{var w,S,U,N;c(!0),m(null);try{let R=await e.payment.processPayment(v);if(R.status==="requires_redirect"){if(R.method==="POST"&&R.postData){let A=document.createElement("form");A.method="POST",A.action=R.redirectUrl;for(let[H,Y]of Object.entries(R.postData)){let _=document.createElement("input");_.type="hidden",_.name=H,_.value=Y,A.appendChild(_)}document.body.appendChild(A),A.submit()}else window.location.href=R.redirectUrl;return R}return R.status==="succeeded"?(S=(w=f.current)==null?void 0:w.onPaymentSuccess)==null||S.call(w,R):R.status==="failed"&&(m(new Error(R.error)),(N=(U=f.current)==null?void 0:U.onPaymentFailed)==null||N.call(U,R)),R}catch(R){let A=R instanceof Error?R:new Error(String(R));return m(A),{status:"failed",error:A.message}}finally{c(!1)}},[e]),E=(0,b.useCallback)(v=>async()=>{c(!0),m(null);try{return await v()}catch(w){let S=w instanceof Error?w:new Error(String(w));throw m(S),S}finally{c(!1)}},[]),C=(0,b.useCallback)(async v=>{c(!0),m(null);try{let w=await e.payment.pay(v);return l(w),w}catch(w){let S=w instanceof Error?w:new Error(String(w));throw m(S),S}finally{c(!1)}},[e]),P=(0,b.useCallback)(v=>e.payment.tokenizeCard(v),[e]),I=(0,b.useCallback)(async v=>{let S=await E(()=>e.payment.processApplePay(v))();return l(S),S},[e,E]),O=(0,b.useCallback)(async v=>{let S=await E(()=>e.payment.processGooglePay(v))();return l(S),S},[e,E]),z=(0,b.useCallback)(async v=>{let S=await E(()=>e.payment.processApm(v))();return l(S),S},[e,E]),$=(0,b.useCallback)(v=>e.payment.pollPaymentStatus(v),[e]);return{paymentSetup:t,expressMethods:n,storeConfig:i,isProcessing:u,result:p,error:h,loadPaymentSetup:g,processPayment:k,pay:C,tokenizeCard:P,processApplePay:I,processGooglePay:O,processApm:z,pollStatus:$}}var x=F("react");function je(s){let e=D(),[t,r]=(0,x.useState)(null),[n,o]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[u,c]=(0,x.useState)(null),p=(0,x.useRef)(s);p.current=s;let l=(0,x.useRef)(!1);(0,x.useEffect)(()=>{var w;if(typeof window>"u"||(w=p.current)!=null&&w.disableAutoResume||l.current)return;let I=new URLSearchParams(window.location.search),O=I.get("paymentAction"),z=I.get("paymentActionStatus"),$=I.get("paymentId");if(O!=="requireAction"||z!=="completed"||!$||(l.current=!0,!Pe($)))return;a(!0),c(null),(async()=>{var S,U,N,R;try{let A=await e.payment.resumeAfterRedirect($),H=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status"].forEach(_=>H.delete(_));let Y=H.toString()?`${window.location.pathname}?${H.toString()}`:window.location.pathname;window.history.replaceState({},document.title,Y),A.status==="succeeded"?(U=(S=p.current)==null?void 0:S.onOfferAccepted)==null||U.call(S,A):A.status==="failed"&&(c(new Error(A.error)),(R=(N=p.current)==null?void 0:N.onOfferDeclined)==null||R.call(N,A))}catch(A){c(A instanceof Error?A:new Error(String(A)))}finally{a(!1)}})()},[e]);let h=(0,x.useCallback)(async I=>{a(!0),c(null);try{return await I()}catch(O){let z=O instanceof Error?O:new Error(String(O));throw c(z),z}finally{a(!1)}},[]),m=(0,x.useCallback)(I=>h(async()=>{let O=await e.offers.getOffer(I);return r(O),O}),[e,h]),d=(0,x.useCallback)(I=>e.offers.listOffers(I),[e]),y=(0,x.useCallback)(I=>h(async()=>{let O=await e.offers.previewOffer(I);return o(O),O}),[e,h]),f=(0,x.useCallback)(I=>h(()=>e.offers.payPreviewedOffer(I)),[e,h]),g=(0,x.useCallback)(async I=>{var O,z,$,v;a(!0),c(null);try{let w=await e.offers.processOfferPayment(I);if(w.status==="requires_redirect"){if(w.method==="POST"&&w.postData){let S=document.createElement("form");S.method="POST",S.action=w.redirectUrl;for(let[U,N]of Object.entries(w.postData)){let R=document.createElement("input");R.type="hidden",R.name=U,R.value=N,S.appendChild(R)}document.body.appendChild(S),S.submit()}else window.location.href=w.redirectUrl;return w}return w.status==="succeeded"?(z=(O=p.current)==null?void 0:O.onOfferAccepted)==null||z.call(O,w):w.status==="failed"&&(c(new Error(w.error)),(v=($=p.current)==null?void 0:$.onOfferDeclined)==null||v.call($,w)),w}catch(w){let S=w instanceof Error?w:new Error(String(w));return c(S),{status:"failed",error:S.message}}finally{a(!1)}},[e]),k=(0,x.useCallback)(I=>e.offers.toggleOrderBump(I),[e]),E=(0,x.useCallback)(I=>e.offers.listPostPurchaseOffers(I),[e]),C=(0,x.useCallback)(I=>h(()=>e.offers.acceptPostPurchaseOffer(I)),[e,h]),P=(0,x.useCallback)(I=>h(()=>e.offers.declinePostPurchaseOffer(I)),[e,h]);return{offer:t,preview:n,isLoading:i,error:u,getOffer:m,listOffers:d,previewOffer:y,processOfferPayment:g,payPreviewedOffer:f,toggleOrderBump:k,listPostPurchaseOffers:E,acceptPostPurchaseOffer:C,declinePostPurchaseOffer:P}}var G=F("react");function Ke(s){let e=D(),[t,r]=(0,G.useState)(null),[n,o]=(0,G.useState)([]),[i,a]=(0,G.useState)([]),[u,c]=(0,G.useState)(!1),[p,l]=(0,G.useState)(null),h=(0,G.useCallback)(async f=>{c(!0),l(null);try{let g=await e.customer.getProfile(f);r(g)}catch(g){l(g instanceof Error?g:new Error(String(g)))}finally{c(!1)}},[e]),m=(0,G.useCallback)(async f=>{try{let g=await e.customer.getOrders(f);o(g.orders)}catch(g){l(g instanceof Error?g:new Error(String(g)))}},[e]),d=(0,G.useCallback)(async f=>{try{let g=await e.customer.getSubscriptions(f);a(g)}catch(g){l(g instanceof Error?g:new Error(String(g)))}},[e]),y=(0,G.useCallback)(async(f,g)=>{try{let k=await e.customer.updateProfile(f,g);r(k)}catch(k){l(k instanceof Error?k:new Error(String(k)))}},[e]);return(0,G.useEffect)(()=>{s&&h(s)},[s,h]),{customer:t,orders:n,subscriptions:i,isLoading:u,error:p,loadCustomer:h,loadOrders:m,loadSubscriptions:d,updateProfile:y}}var j=F("react");function Be(s,e){let t=D(),[r,n]=(0,j.useState)(null),[o,i]=(0,j.useState)(!1),[a,u]=(0,j.useState)(null),c=(e==null?void 0:e.watchRelatedOrders)??!0,p=(e==null?void 0:e.watchTimeoutMs)??8e3,l=(e==null?void 0:e.watchIntervalMs)??2e3,h=(0,j.useRef)(0),m=(0,j.useCallback)(async()=>{if(s)try{let d=await t.customer.getOrder(s);n(d)}catch(d){u(d instanceof Error?d:new Error(String(d)))}},[t,s]);return(0,j.useEffect)(()=>{if(!s)return;let d=++h.current,y=()=>h.current===d;return i(!0),u(null),(async()=>{var f,g;try{let k=await t.customer.getOrder(s);if(!y()||(n(k),i(!1),!c||(f=k.relatedOrders)!=null&&f.length))return;let E=Date.now()+p;for(;Date.now()<E&&y();){if(await new Promise(C=>setTimeout(C,l)),!y()||(k=await t.customer.getOrder(s),!y()))return;if((g=k.relatedOrders)!=null&&g.length){n(k);return}}}catch(k){if(!y())return;u(k instanceof Error?k:new Error(String(k))),i(!1)}})(),()=>{h.current++}},[t,s,c,p,l]),{order:r,relatedOrders:(r==null?void 0:r.relatedOrders)??[],isLoading:o,error:a,refresh:m}}var W=F("react");function ze(){let s=D(),[e,t]=(0,W.useState)([]),[r,n]=(0,W.useState)(!1),[o,i]=(0,W.useState)(null),a=(0,W.useCallback)(async c=>{n(!0),i(null);try{let p=await s.catalog.getProducts(c);return t(p),p}catch(p){let l=p instanceof Error?p:new Error(String(p));throw i(l),l}finally{n(!1)}},[s]),u=(0,W.useCallback)(async c=>{n(!0),i(null);try{return await s.catalog.getProduct(c)}catch(p){let l=p instanceof Error?p:new Error(String(p));throw i(l),l}finally{n(!1)}},[s]);return{products:e,isLoading:r,error:o,loadProducts:a,loadProduct:u}}var M=F("react");var mt=new Set(["approved","shipped","delivered","declined","cancelled","error"]);function Je(){let s=D(),[e,t]=(0,M.useState)([]),[r,n]=(0,M.useState)(null),[o,i]=(0,M.useState)(!1),[a,u]=(0,M.useState)(null),c=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{c.current&&clearInterval(c.current)},[]);let p=(0,M.useCallback)(async(y,f)=>{i(!0),u(null);try{return await s.rx.isRequiredForProduct(y,f)}catch(g){let k=g instanceof Error?g:new Error(String(g));throw u(k),k}finally{i(!1)}},[s]),l=(0,M.useCallback)(async y=>{i(!0),u(null);try{return await s.rx.getQuestionsForProduct(y)}catch(f){let g=f instanceof Error?f:new Error(String(f));throw u(g),g}finally{i(!1)}},[s]),h=(0,M.useCallback)(async y=>{i(!0),u(null);try{let f=await s.rx.submitCase(y);return n(f),f}catch(f){let g=f instanceof Error?f:new Error(String(f));throw u(g),g}finally{i(!1)}},[s]),m=(0,M.useCallback)(async y=>{i(!0),u(null);try{let f=await s.rx.getCasesForOrder(y);return t(f.cases),f.cases}catch(f){let g=f instanceof Error?f:new Error(String(f));throw u(g),g}finally{i(!1)}},[s]),d=(0,M.useCallback)(({orderId:y,checkoutToken:f},g)=>{c.current&&clearInterval(c.current);let k=(g==null?void 0:g.intervalMs)??5e3,E=async()=>{var C;try{let P=await s.rx.getCasesForOrder({orderId:y,checkoutToken:f});t(P.cases),(C=g==null?void 0:g.onUpdate)==null||C.call(g,P.cases),P.cases.length>0&&P.cases.every(I=>mt.has(I.status))&&(c.current&&clearInterval(c.current),c.current=null)}catch(P){let I=P instanceof Error?P:new Error(String(P));u(I)}};return E(),c.current=setInterval(E,k),()=>{c.current&&clearInterval(c.current),c.current=null}},[s]);return{cases:e,lastSubmission:r,isLoading:o,error:a,isRequiredForProduct:p,getQuestionsForProduct:l,submitCase:h,fetchCasesForOrder:m,pollOrder:d}}var L=F("react");var Qe=!1,We=!1,we=[];function ve(){We=!0;for(let s of we)s();we.length=0}function te(s,e={}){var t,r;return We||(r=(t=window.google)==null?void 0:t.maps)!=null&&r.places?(ve(),Promise.resolve()):Qe?new Promise(n=>we.push(n)):(Qe=!0,new Promise((n,o)=>{if(we.push(n),document.querySelector('script[src*="maps.googleapis.com"]')){let c=()=>{var p,l;(l=(p=window.google)==null?void 0:p.maps)!=null&&l.places?ve():setTimeout(c,100)};c();return}let a=new URLSearchParams({key:s,libraries:"places",v:e.version??"weekly"});e.language&&a.set("language",e.language),e.region&&a.set("region",e.region);let u=document.createElement("script");u.src=`https://maps.googleapis.com/maps/api/js?${a}`,u.async=!0,u.defer=!0,u.onload=()=>ve(),u.onerror=()=>o(new Error("Failed to load Google Maps script")),document.head.appendChild(u)}))}var K=class s{static async searchPlaces(e,t={}){var n,o;if(!((o=(n=window.google)==null?void 0:n.maps)!=null&&o.places)||!e.trim())return[];let r=new window.google.maps.places.AutocompleteService;return new Promise(i=>{r.getPlacePredictions({input:e,types:t.types??["address"],componentRestrictions:t.componentRestrictions},(a,u)=>{var c,p,l;i(u===((l=(p=(c=window.google)==null?void 0:c.maps)==null?void 0:p.places)==null?void 0:l.PlacesServiceStatus.OK)&&a?a:[])})})}static async getPlaceDetails(e){var r,n;if(!((n=(r=window.google)==null?void 0:r.maps)!=null&&n.places))return null;let t=new window.google.maps.places.PlacesService(document.createElement("div"));return new Promise(o=>{t.getDetails({placeId:e,fields:["place_id","formatted_address","address_components","geometry"]},(i,a)=>{var u,c,p;o(a===((p=(c=(u=window.google)==null?void 0:u.maps)==null?void 0:c.places)==null?void 0:p.PlacesServiceStatus.OK)&&i?i:null)})})}static extractAddressComponents(e){let t={subpremise:"",streetNumber:"",route:"",locality:"",administrativeAreaLevel1:"",administrativeAreaLevel1Long:"",administrativeAreaLevel2:"",administrativeAreaLevel2Long:"",country:"",postalCode:"",fullStreetAddress:""},r="",n="",o="",i="",a="",u="",c="",p="";for(let m of e.address_components??[]){let d=m.types;d.includes("subpremise")&&(t.subpremise=m.long_name),d.includes("street_number")&&(t.streetNumber=m.long_name),d.includes("premise")&&(r=m.long_name),d.includes("route")&&(t.route=m.long_name),d.includes("neighborhood")&&(n=m.long_name),d.includes("sublocality_level_5")&&(o=m.long_name),d.includes("sublocality_level_4")&&(i=m.long_name),d.includes("sublocality_level_3")&&(a=m.long_name),d.includes("sublocality_level_2")&&(u=m.long_name),d.includes("sublocality_level_1")&&(c=m.long_name),d.includes("locality")&&(t.locality=m.long_name),d.includes("postal_town")&&(p=m.long_name),d.includes("administrative_area_level_2")&&(t.administrativeAreaLevel2=m.short_name,t.administrativeAreaLevel2Long=m.long_name),d.includes("administrative_area_level_1")&&(t.administrativeAreaLevel1=m.short_name,t.administrativeAreaLevel1Long=m.long_name),d.includes("country")&&(t.country=m.short_name),d.includes("postal_code")&&(t.postalCode=m.long_name)}t.locality||(t.locality=p||u||c||""),!t.administrativeAreaLevel1&&t.administrativeAreaLevel2&&(t.administrativeAreaLevel1=t.administrativeAreaLevel2Long||t.administrativeAreaLevel2,t.administrativeAreaLevel1Long=t.administrativeAreaLevel2Long);let l=t.streetNumber||r,h=t.route||o||i||a||n;if(t.subpremise&&l&&h)t.fullStreetAddress=`${t.subpremise}/${l} ${h}`;else if(l&&h)if(r&&i&&a){let m=`${a}-${i}-${r}`;u&&(m=`${m} ${u}`),t.fullStreetAddress=m}else t.fullStreetAddress=`${l} ${h}`;else h?t.fullStreetAddress=h:l&&(t.fullStreetAddress=l);return t.fullStreetAddress=t.fullStreetAddress.trim(),t}static extractFormattedAddress(e){let t=s.extractAddressComponents(e);return{address1:t.fullStreetAddress,city:t.locality,country:t.country,state:t.administrativeAreaLevel1,postal:t.postalCode}}};function Ve(s){let{apiKey:e,language:t,region:r,version:n,defer:o=!1}=s,[i,a]=(0,L.useState)([]),[u,c]=(0,L.useState)(!1),[p,l]=(0,L.useState)(!1),h=(0,L.useRef)(null),m=(0,L.useRef)(null),d=(0,L.useCallback)(()=>{te(e,{language:t,region:r,version:n}).then(()=>l(!0))},[e,t,r,n]);(0,L.useEffect)(()=>{!e||o||d()},[e,o,d]),(0,L.useEffect)(()=>{if(p&&m.current){let{input:C,country:P}=m.current;m.current=null,y(C,P)}},[p]);let y=(0,L.useCallback)((C,P)=>{if(!p){o&&(m.current={input:C,country:P},d());return}if(C.length<3){a([]);return}h.current&&clearTimeout(h.current),h.current=setTimeout(async()=>{c(!0);let I=await K.searchPlaces(C,{componentRestrictions:P?{country:P.toLowerCase()}:void 0});a(I),c(!1)},300)},[p,o,d]),f=(0,L.useCallback)(C=>K.getPlaceDetails(C),[]),g=(0,L.useCallback)(C=>K.extractAddressComponents(C),[]),k=(0,L.useCallback)(C=>K.extractFormattedAddress(C),[]),E=(0,L.useCallback)(()=>a([]),[]);return{predictions:i,isLoading:u,isScriptLoaded:p,searchPlaces:y,getPlaceDetails:f,extractAddressComponents:g,extractFormattedAddress:k,clearPredictions:E}}var J=F("react");var Ye="https://cvwnizdbugpz6jwk.public.blob.vercel-storage.com/geodata/v1",xe=["en","ru","de","da","fr","es","zh","hi","pt","ja","ar","it","he"],re=new Map,Ce=new Map,Ae=new Map,be=new Map;async function pt(s){let e=re.get(s);if(e)return e;let t=Ae.get(s);return t||(t=(async()=>{let r=`${Ye}/${s}/countries.json`,n=await fetch(r);if(!n.ok)throw new Error(`Geodata fetch failed: ${r} (${n.status})`);let o=await n.json();return re.set(s,o),Ae.delete(s),o})(),Ae.set(s,t),t)}async function gt(s){let e=Ce.get(s);if(e)return e;let t=be.get(s);return t||(t=(async()=>{let r=`${Ye}/${s}/regions.json`,n=await fetch(r);if(!n.ok)throw new Error(`Geodata fetch failed: ${r} (${n.status})`);let o=await n.json();return Ce.set(s,o),be.delete(s),o})(),be.set(s,t),t)}function ft(s){return re.get(s)||re.get("en")||{}}function yt(s){return Ce.get(s)||Ce.get("en")||{}}async function ne(s="en"){await Promise.all([pt(s),gt(s)])}var Ie=(s="en")=>{let e=ft(s);return Object.entries(e).map(([t,r])=>({code:t,name:r.n,iso3:r.i3,numeric:r.nu})).sort((t,r)=>t.name.localeCompare(r.name))},Oe=(s,e="en")=>{let r=yt(e)[s];return r?r.map(([n,o])=>({code:n,name:o,countryCode:s})).sort((n,o)=>n.name.localeCompare(o.name)):[]};function se(s){return re.has(s)}var B=class s{static ensureLoaded(e="en"){return ne(e)}static getCountries(e="en"){let t=Ie(e),r={};for(let n of t)r[n.code]={iso:n.code,iso3:n.iso3??"",numeric:n.numeric??0,name:n.name};return r}static getCountryOptions(e="en"){return Ie(e).map(t=>({value:t.code,label:t.name}))}static getRegions(e,t="en"){return Oe(e,t).map(r=>({iso:r.code,name:r.name}))}static getRegionOptions(e,t="en"){return s.getRegions(e,t).map(r=>({value:r.iso,label:r.name}))}static findRegion(e,t,r="en"){return s.getRegions(e,r).find(n=>n.iso===t)??null}static mapGoogleToISO(e,t,r,n="en"){let o=s.getRegions(r,n);if(o.length===0)return null;let i=o.find(a=>a.iso===e);return i||(i=o.find(a=>a.name.toLowerCase()===e.toLowerCase()),i)||(i=o.find(a=>a.name.toLowerCase()===t.toLowerCase()),i)?i:(i=o.find(a=>a.name.toLowerCase().includes(t.toLowerCase())||t.toLowerCase().includes(a.name.toLowerCase())),i??null)}static isLanguageLoaded(e){return se(e)}static getAvailableLanguages(){return xe}};function Se(s="en"){let[e,t]=(0,J.useState)(se(s));return(0,J.useEffect)(()=>{let r=!1;return ne(s).then(()=>{r||t(!0)}).catch(n=>console.error("[headless-sdk] Failed to load geodata:",n)),()=>{r=!0}},[s]),(0,J.useMemo)(()=>e?{countries:B.getCountries(s),getRegions:r=>B.getRegions(r,s),findRegion:(r,n)=>B.findRegion(r,n,s),mapGoogleToISO:(r,n,o)=>B.mapGoogleToISO(r,n,o,s),isLoaded:!0}:{countries:{},getRegions:()=>[],findRegion:()=>null,mapGoogleToISO:()=>null,isLoaded:!1},[s,e])}function Ze(s="en"){let{countries:e,isLoaded:t}=Se(s);return(0,J.useMemo)(()=>t?Object.values(e).map(r=>({value:r.iso,label:r.name})).sort((r,n)=>r.label.localeCompare(n.label)):[],[e,t])}function Xe(s,e="en"){let{getRegions:t,isLoaded:r}=Se(e);return(0,J.useMemo)(()=>!r||!s?[]:t(s).map(n=>({value:n.iso,label:n.name})).sort((n,o)=>n.label.localeCompare(o.label)),[s,t,r])}var ht={USD:"$",EUR:"\u20AC",GBP:"\xA3",JPY:"\xA5",CAD:"C$",AUD:"A$",CHF:"CHF",CNY:"\xA5",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"z\u0142",CZK:"K\u010D",HUF:"Ft",RON:"lei",BGN:"\u043B\u0432",HRK:"kn",RUB:"\u20BD",UAH:"\u20B4",TRY:"\u20BA",BRL:"R$",MXN:"$",ZAR:"R",INR:"\u20B9",KRW:"\u20A9",THB:"\u0E3F",VND:"\u20AB",IDR:"Rp",MYR:"RM",SGD:"S$",PHP:"\u20B1",TWD:"NT$",HKD:"HK$",ILS:"\u20AA",AED:"\u062F.\u0625",SAR:"\u0631.\u0633",QAR:"\u0631.\u0642",KWD:"\u062F.\u0643",BHD:"\u062F.\u0628",OMR:"\u0631.\u0639.",EGP:"\xA3",NGN:"\u20A6",KES:"KSh",GHS:"\u20B5",COP:"$",ARS:"$",CLP:"$",PEN:"S/",CRC:"\u20A1",DOP:"RD$",JMD:"J$",BOB:"Bs",PYG:"\u20B2",GTQ:"Q",NIO:"C$",PAB:"B/.",PKR:"\u20A8",BDT:"\u09F3",LKR:"\u20A8",NPR:"\u20A8",GEL:"\u20BE",AMD:"\u058F",AZN:"\u20BC",KZT:"\u20B8"},Pt={USD:"US Dollar",EUR:"Euro",GBP:"British Pound",JPY:"Japanese Yen",CAD:"Canadian Dollar",AUD:"Australian Dollar",CHF:"Swiss Franc",CNY:"Chinese Yuan",SEK:"Swedish Krona",NOK:"Norwegian Krone",DKK:"Danish Krone",PLN:"Polish Zloty",CZK:"Czech Koruna",HUF:"Hungarian Forint",BRL:"Brazilian Real",MXN:"Mexican Peso",INR:"Indian Rupee",KRW:"South Korean Won",THB:"Thai Baht",SGD:"Singapore Dollar",HKD:"Hong Kong Dollar",TWD:"Taiwan Dollar",ILS:"Israeli Shekel",AED:"UAE Dirham",SAR:"Saudi Riyal",ZAR:"South African Rand",TRY:"Turkish Lira",RUB:"Russian Ruble",NGN:"Nigerian Naira"},wt=new Set(["JPY","KRW","VND","IDR","LAK","KHR","MMK","PYG"]),V=class s{static getSymbol(e){return ht[e]??e}static getName(e){return Pt[e]??e}static getDecimalPlaces(e){return wt.has(e)?0:2}static getCurrency(e){return{code:e,symbol:s.getSymbol(e),name:s.getName(e),decimalPlaces:s.getDecimalPlaces(e)}}};function Te(s,e="USD",t="en-US"){let r=V.getDecimalPlaces(e),n=s/(r===0?100:Math.pow(10,r));try{return new Intl.NumberFormat(t,{style:"currency",currency:e,minimumFractionDigits:r,maximumFractionDigits:r}).format(n)}catch{return`${V.getSymbol(e)}${n.toFixed(r)}`}}return ct(Ct);})();
7
7
  if(typeof window!=="undefined"&&TagadaHeadlessReactBundle){ window.TagadaHeadlessReact=TagadaHeadlessReactBundle;}
8
8
  //# sourceMappingURL=tagada-headless-react.min.js.map