@tagadapay/headless-sdk 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -7
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/modules/checkout.d.ts +71 -8
- package/dist/core/modules/checkout.d.ts.map +1 -1
- package/dist/core/modules/checkout.js +129 -35
- package/dist/core/modules/checkout.js.map +1 -1
- package/dist/core/modules/payment.d.ts +62 -1
- package/dist/core/modules/payment.d.ts.map +1 -1
- package/dist/core/modules/payment.js +225 -0
- package/dist/core/modules/payment.js.map +1 -1
- package/dist/core/types.d.ts +80 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/react/hooks/useCheckout.d.ts.map +1 -1
- package/dist/react/hooks/useCheckout.js +2 -12
- package/dist/react/hooks/useCheckout.js.map +1 -1
- package/dist/react/hooks/usePayment.d.ts +39 -10
- package/dist/react/hooks/usePayment.d.ts.map +1 -1
- package/dist/react/hooks/usePayment.js +116 -8
- package/dist/react/hooks/usePayment.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/tagada-headless-react.min.js +2 -2
- package/dist/tagada-headless-react.min.js.map +3 -3
- package/dist/tagada-headless.js +321 -34
- package/dist/tagada-headless.min.js +2 -2
- package/dist/tagada-headless.min.js.map +3 -3
- package/package.json +1 -1
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import { useState, useCallback, useRef } from 'react';
|
|
1
|
+
import { useState, useCallback, useRef, useEffect } from 'react';
|
|
2
2
|
import { useHeadlessClient } from '../provider.js';
|
|
3
3
|
/**
|
|
4
4
|
* React hook for payment processing.
|
|
5
5
|
*
|
|
6
|
+
* Handles the full payment lifecycle including 3DS redirects and return-URL detection.
|
|
7
|
+
*
|
|
6
8
|
* @example
|
|
7
9
|
* ```tsx
|
|
8
|
-
* const {
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* const { processPayment, isProcessing, error } = usePayment({
|
|
11
|
+
* onPaymentSuccess: (result) => router.push('/confirmation'),
|
|
12
|
+
* onPaymentFailed: (result) => toast.error(result.error),
|
|
13
|
+
* });
|
|
12
14
|
*
|
|
13
|
-
* // On submit
|
|
14
|
-
* const result = await
|
|
15
|
+
* // On submit — one function handles everything
|
|
16
|
+
* const result = await processPayment({
|
|
17
|
+
* checkoutSessionId: session.id,
|
|
18
|
+
* tagadaToken,
|
|
19
|
+
* });
|
|
15
20
|
* ```
|
|
16
21
|
*/
|
|
17
|
-
export function usePayment() {
|
|
22
|
+
export function usePayment(options) {
|
|
18
23
|
const client = useHeadlessClient();
|
|
19
24
|
const [paymentSetup, setPaymentSetup] = useState(null);
|
|
20
25
|
const [expressMethods, setExpressMethods] = useState(null);
|
|
@@ -23,6 +28,57 @@ export function usePayment() {
|
|
|
23
28
|
const [result, setResult] = useState(null);
|
|
24
29
|
const [error, setError] = useState(null);
|
|
25
30
|
const loadedRef = useRef(false);
|
|
31
|
+
const redirectReturnProcessedRef = useRef(false);
|
|
32
|
+
const optionsRef = useRef(options);
|
|
33
|
+
optionsRef.current = options;
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Return-URL detection: auto-resume after 3DS / processor redirect
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (typeof window === 'undefined')
|
|
39
|
+
return;
|
|
40
|
+
if (redirectReturnProcessedRef.current)
|
|
41
|
+
return;
|
|
42
|
+
const params = new URLSearchParams(window.location.search);
|
|
43
|
+
const paymentAction = params.get('paymentAction');
|
|
44
|
+
const paymentActionStatus = params.get('paymentActionStatus');
|
|
45
|
+
const paymentId = params.get('paymentId');
|
|
46
|
+
if (paymentAction !== 'requireAction' || paymentActionStatus !== 'completed' || !paymentId) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
redirectReturnProcessedRef.current = true;
|
|
50
|
+
setIsProcessing(true);
|
|
51
|
+
setError(null);
|
|
52
|
+
const resume = async () => {
|
|
53
|
+
try {
|
|
54
|
+
const resumeResult = await client.payment.resumeAfterRedirect(paymentId);
|
|
55
|
+
// Clean payment-related query params from URL
|
|
56
|
+
const cleanParams = new URLSearchParams(window.location.search);
|
|
57
|
+
['paymentAction', 'paymentActionStatus', 'paymentId', 'payment_intent', 'payment_intent_client_secret', 'source_type', 'redirect_status'].forEach((p) => cleanParams.delete(p));
|
|
58
|
+
const newUrl = cleanParams.toString()
|
|
59
|
+
? `${window.location.pathname}?${cleanParams.toString()}`
|
|
60
|
+
: window.location.pathname;
|
|
61
|
+
window.history.replaceState({}, document.title, newUrl);
|
|
62
|
+
if (resumeResult.status === 'succeeded') {
|
|
63
|
+
optionsRef.current?.onPaymentSuccess?.(resumeResult);
|
|
64
|
+
}
|
|
65
|
+
else if (resumeResult.status === 'failed') {
|
|
66
|
+
setError(new Error(resumeResult.error));
|
|
67
|
+
optionsRef.current?.onPaymentFailed?.(resumeResult);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
setIsProcessing(false);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
void resume();
|
|
78
|
+
}, [client]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Load payment setup
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
26
82
|
const loadPaymentSetup = useCallback(async (checkoutSessionId) => {
|
|
27
83
|
if (loadedRef.current)
|
|
28
84
|
return;
|
|
@@ -42,6 +98,57 @@ export function usePayment() {
|
|
|
42
98
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
43
99
|
}
|
|
44
100
|
}, [client]);
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// processPayment — high-level, handles everything
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
const processPayment = useCallback(async (opts) => {
|
|
105
|
+
setIsProcessing(true);
|
|
106
|
+
setError(null);
|
|
107
|
+
try {
|
|
108
|
+
const payResult = await client.payment.processPayment(opts);
|
|
109
|
+
if (payResult.status === 'requires_redirect') {
|
|
110
|
+
// Browser redirect — the hook will resume on return via the useEffect above
|
|
111
|
+
if (payResult.method === 'POST' && payResult.postData) {
|
|
112
|
+
const form = document.createElement('form');
|
|
113
|
+
form.method = 'POST';
|
|
114
|
+
form.action = payResult.redirectUrl;
|
|
115
|
+
for (const [key, value] of Object.entries(payResult.postData)) {
|
|
116
|
+
const input = document.createElement('input');
|
|
117
|
+
input.type = 'hidden';
|
|
118
|
+
input.name = key;
|
|
119
|
+
input.value = value;
|
|
120
|
+
form.appendChild(input);
|
|
121
|
+
}
|
|
122
|
+
document.body.appendChild(form);
|
|
123
|
+
form.submit();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
window.location.href = payResult.redirectUrl;
|
|
127
|
+
}
|
|
128
|
+
// Don't setIsProcessing(false) — page is navigating away
|
|
129
|
+
return payResult;
|
|
130
|
+
}
|
|
131
|
+
if (payResult.status === 'succeeded') {
|
|
132
|
+
optionsRef.current?.onPaymentSuccess?.(payResult);
|
|
133
|
+
}
|
|
134
|
+
else if (payResult.status === 'failed') {
|
|
135
|
+
setError(new Error(payResult.error));
|
|
136
|
+
optionsRef.current?.onPaymentFailed?.(payResult);
|
|
137
|
+
}
|
|
138
|
+
return payResult;
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
142
|
+
setError(e);
|
|
143
|
+
return { status: 'failed', error: e.message };
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
setIsProcessing(false);
|
|
147
|
+
}
|
|
148
|
+
}, [client]);
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
// Low-level pay (raw API, no action handling)
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
45
152
|
const wrapAsync = useCallback((fn) => async () => {
|
|
46
153
|
setIsProcessing(true);
|
|
47
154
|
setError(null);
|
|
@@ -103,6 +210,7 @@ export function usePayment() {
|
|
|
103
210
|
result,
|
|
104
211
|
error,
|
|
105
212
|
loadPaymentSetup,
|
|
213
|
+
processPayment,
|
|
106
214
|
pay,
|
|
107
215
|
tokenizeCard,
|
|
108
216
|
processApplePay,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayment.js","sourceRoot":"","sources":["../../../src/react/hooks/usePayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"usePayment.js","sourceRoot":"","sources":["../../../src/react/hooks/usePayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAmFnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACnC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAA4B,IAAI,CAAC,CAAC;IAClF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAClF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IACzE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAmB,IAAI,CAAC,CAAC;IAC7D,MAAM,C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AAC;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"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { TagadaHeadlessProviderProps } from './provider.js';
|
|
|
3
3
|
export { useCheckout } from './hooks/useCheckout.js';
|
|
4
4
|
export type { UseCheckoutReturn } from './hooks/useCheckout.js';
|
|
5
5
|
export { usePayment } from './hooks/usePayment.js';
|
|
6
|
-
export type { UsePaymentReturn } from './hooks/usePayment.js';
|
|
6
|
+
export type { UsePaymentReturn, UsePaymentOptions } from './hooks/usePayment.js';
|
|
7
7
|
export { useOffers } from './hooks/useOffers.js';
|
|
8
8
|
export type { UseOffersReturn } from './hooks/useOffers.js';
|
|
9
9
|
export { useCustomer } from './hooks/useCustomer.js';
|
|
@@ -16,5 +16,5 @@ export { useISOData, useCountryOptions, useRegionOptions } from './hooks/useISOD
|
|
|
16
16
|
export type { UseISODataReturn } from './hooks/useISOData.js';
|
|
17
17
|
export type { GooglePrediction, GooglePlaceDetails, ExtractedAddress, FormattedAddress, SupportedLanguage, ISOCountry, ISORegion, Currency, } from '../core/helpers/index.js';
|
|
18
18
|
export { formatMoney, CurrencyUtils, ISODataCore, GoogleAutocompleteCore, loadGoogleMapsScript } from '../core/helpers/index.js';
|
|
19
|
-
export type { HeadlessConfig, Environment, CheckoutSession, CheckoutLineItem, CheckoutTotals, CheckoutCustomer, Address, ShippingRate, LineItem, PaymentSetupConfig, PaymentMethodConfig, ExpressMethods, ExpressMethod, StoreConfig, PayResult, PayOptions, PaymentStatus, Offer, OfferLineItem, OfferPreview, OfferPreviewItem, OfferPayResult, Customer, Order, Subscription, CatalogProduct, CatalogVariant, CatalogPrice, CurrencyOption, } from '../core/types.js';
|
|
19
|
+
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, } from '../core/types.js';
|
|
20
20
|
//# 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,E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S,EACT,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEjI,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,GACf,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @tagadapay/headless-sdk v1.
|
|
2
|
+
* @tagadapay/headless-sdk v1.4.0
|
|
3
3
|
* Headless checkout, payments, offers, and CRM
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
"use strict";var TagadaHeadlessReactBundle=(()=>{var Le=Object.create;var B=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var L=(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 Ne=(s,e)=>{for(var t in e)B(s,t,{get:e[t],enumerable:!0})},pe=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Te(e))!Ue.call(s,n)&&n!==t&&B(s,n,{get:()=>e[n],enumerable:!(r=Ee(e,n))||r.enumerable});return s};var $e=(s,e,t)=>(t=s!=null?Le(De(s)):{},pe(e||!s||!s.__esModule?B(t,"default",{value:s,enumerable:!0}):t,s)),Ge=s=>pe(B({},"__esModule",{value:!0}),s);var Be={};Ne(Be,{CurrencyUtils:()=>H,GoogleAutocompleteCore:()=>T,ISODataCore:()=>D,TagadaHeadlessProvider:()=>ye,formatMoney:()=>le,loadGoogleMapsScript:()=>j,useCatalog:()=>Ce,useCheckout:()=>Pe,useCountryOptions:()=>be,useCustomer:()=>we,useGoogleAutocomplete:()=>Re,useHeadlessClient:()=>x,useISOData:()=>ne,useOffers:()=>Ie,usePayment:()=>Se,useRegionOptions:()=>Oe});var $=L("react");var E=class extends Error{constructor(e,t,r,n){super(e),this.name="TagadaError",this.code=t,this.statusCode=r,this.details=n}},z=class extends E{constructor(e="Authentication failed. Check your API key or checkout token."){super(e,"auth_error",401),this.name="TagadaAuthError"}},J=class extends E{constructor(e,t=[]){super(e,"validation_error",422,{errors:t}),this.name="TagadaValidationError",this.errors=t}},Y=class extends E{constructor(e,t){super(`${e} "${t}" not found.`,"not_found",404),this.name="TagadaNotFoundError"}},V=class extends E{constructor(e=1e3){super(`Rate limited. Retry after ${e}ms.`,"rate_limit",429),this.name="TagadaRateLimitError",this.retryAfterMs=e}};var M=class extends E{constructor(e="Network request failed. Check your connection."){super(e,"network_error"),this.name="TagadaNetworkError"}};var me={production:"https://app.tagadapay.com",development:"https://app.dev.tagadapay.com",local:"http://localhost:3000"},_=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??me[e]??me.production}async request(e,t={}){var f;let{method:r="GET",body:n,headers:i={},params:o,token:c,signal:u}=t,a=`${this.baseUrl}${e}`;if(o){let y=new URLSearchParams;for(let[P,l]of Object.entries(o))l!==void 0&&y.set(P,String(l));let S=y.toString();S&&(a+=`?${S}`)}let d={"Content-Type":"application/json",...i},g=c??this.apiKey??((f=this.getToken)==null?void 0:f.call(this));g&&(d["x-cms-token"]=g);let h=new AbortController,p=setTimeout(()=>h.abort(),this.timeout);try{let y=await fetch(a,{method:r,headers:d,body:n!=null?JSON.stringify(n):void 0,signal:u??h.signal});if(clearTimeout(p),y.ok){let S=await y.text();return S?JSON.parse(S):{}}throw await this.handleErrorResponse(y,e),new E("Unexpected error","unknown",y.status)}catch(y){throw clearTimeout(p),y instanceof E?y:y instanceof DOMException&&y.name==="AbortError"?new M(`Request to ${e} timed out after ${this.timeout}ms.`):new M(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.message??r.error??`Request failed: ${e.status} ${e.statusText} on ${t}`;switch(e.status){case 401:case 403:throw new z(n);case 404:throw new Y(t,"");case 422:{let i=Array.isArray(r.errors)?r.errors:[];throw new J(n,i)}case 429:{let i=Number(e.headers.get("Retry-After")??"1")*1e3;throw new V(i)}default:throw new E(n,"api_error",e.status,r)}}};var W=class{constructor(e,t,r){this.http=e;this.storeId=t;this.onTokenChange=r}async loadSession(e,t){var n;t&&(this.sessionToken=t,(n=this.onTokenChange)==null||n.call(this,t));let r=await this.http.get(`/api/v1/checkout-sessions/${e}/v2`,{params:{skipAsyncWait:"false"},token:this.sessionToken});return this.normalizeSession(r)}async createSession(e){var c;let t=e.items.map(u=>({variantId:u.variantId,priceId:u.priceId,quantity:u.quantity})),r={storeId:this.storeId,lineItems:t};e.currency&&(r.currency=e.currency),e.returnUrl&&(r.returnUrl=e.returnUrl),e.customerEmail&&(r.customer={email:e.customerEmail,firstName:e.customerFirstName,lastName:e.customerLastName,currency:e.currency});let n=await this.http.post("/api/v1/checkout/session/init",r),o=new URL(n.checkoutUrl).searchParams.get("token")??"";return this.sessionToken=o,o&&((c=this.onTokenChange)==null||c.call(this,o)),{checkoutUrl:n.checkoutUrl,checkoutToken:n.checkoutToken,sessionToken:o,customerId:n.customerId}}async updateCart(e,t){return this.http.post(`/api/v1/checkout-sessions/${e}/line-items`,{items:t},{token:this.sessionToken})}async updateCustomer(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/customer-and-session-info`,{checkoutSessionId:e,partial:!0,customerData:{email:t.email},shippingAddress:{firstName:t.firstName,lastName:t.lastName,phone:t.phone},billingAddress:{},differentBillingAddress:!1},{token:this.sessionToken})}async updateAddress(e,t){let r=n=>{if(n)return{address1:n.line1,address2:n.line2,city:n.city,state:n.state,postal:n.postalCode,country:n.country}};await this.http.post(`/api/v1/checkout-sessions/${e}/address`,{checkoutSessionId:e,data:{shippingAddress:r(t.shippingAddress)??{},billingAddress:r(t.billingAddress)}},{token:this.sessionToken})}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??[]}async selectShippingRate(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/shipping-rate`,{checkoutSessionId:e,shippingRateId:t},{token:this.sessionToken})}normalizeSession(e){let t=e.checkoutSession,r=t.orderSummaries??[],n=e.summary??t.summary??r[0]??{},i=t.sessionLineItems??[],o=t.customer,c=i.map(a=>{let d=a.price,g=(d==null?void 0:d.variant)??{},h=g.product??{},p=(d==null?void 0:d.currencyOptions)??{},f=p.USD??p[Object.keys(p)[0]];return{id:a.id,variantId:a.variantId,priceId:a.priceId,productName:h.name??"",variantName:g.name??"",quantity:a.quantity??1,unitAmount:(f==null?void 0:f.amount)??0,totalAmount:((f==null?void 0:f.amount)??0)*(a.quantity??1),currency:t.selectedPresentmentCurrency??"USD",imageUrl:g.imageUrl??""}}),u=n.items??[];return{id:t.id,storeId:t.storeId,checkoutToken:t.checkoutToken,currency:t.selectedPresentmentCurrency??"USD",items:c,totals:{subtotal:n.subtotalAmount??0,discount:n.totalPromotionAmount??0,shipping:n.shippingCost??0,tax:n.totalTaxAmount??0,total:n.totalAmount??u.reduce((a,d)=>a+(d.amount??0),0),currency:n.currency??t.selectedPresentmentCurrency??"USD"},customer:o?{id:o.id,email:o.email,firstName:o.firstName,lastName:o.lastName}:void 0,shippingAddress:t.shippingAddress,billingAddress:t.billingAddress,metadata:t.metadata}}};var Z=class{constructor(e,t,r){this.http=e;this.storeId=t;this.environment=r}async getPaymentSetup(e){let t=await this.http.get("/api/v1/payment-methods",{params:{checkoutSessionId:e}}),r={};for(let n of t.methods??[]){let i=n.provider?`${n.method}:${n.provider}`:n.method;r[i]=n}return r}async getExpressMethods(e){var n,i;let t=await this.getPaymentSetup(e),r={};for(let[,o]of Object.entries(t)){if(!o.enabled||!o.express)continue;let c=o.method,u={type:c,available:!0,processorId:o.processorId,publishableKey:o.publishableKey,metadata:o.metadata};if(c==="apple_pay"||o.type==="apple_pay"){let a=typeof window<"u"&&"ApplePaySession"in window&&((i=(n=window.ApplePaySession)==null?void 0:n.canMakePayments)==null?void 0:i.call(n));r.applePay={...u,available:!!a}}else c==="google_pay"||o.type==="google_pay"?r.googlePay=u:c==="paypal"?r.paypal=u:c==="klarna"||c==="klarna_express"?r.klarna=u:c==="link"&&(r.link=u)}return r}async getStoreConfig(){let e=await this.http.get("/api/v1/checkout/config",{params:{storeId:this.storeId}});return e.config??e}async getEnabledMethods(e){let t=await this.getPaymentSetup(e);return Object.entries(t).filter(([,r])=>r.enabled).map(([r])=>r)}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[i,o]=await Promise.all([r.tokenizeCard(n),r.tokenizeCardRaw(n)]);return{tagadaToken:i,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,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})}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})}async processApplePay(e){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){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 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,i=Date.now();for(;Date.now()-i<n;){let o=await this.getPaymentStatus(e);if(o.status==="succeeded"||o.status==="failed"||o.status==="declined")return o;await new Promise(c=>setTimeout(c,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 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 Q=class{constructor(e,t){this.http=e;this.storeId=t}async getOffer(e){return this.http.get(`/api/v1/offers/${e}`)}async listOffers(e){var i;let t=`/api/v1/stores/${this.storeId}/offers`,r=[];if(e!=null&&e.type&&r.push(`type=${encodeURIComponent(e.type)}`),(i=e==null?void 0:e.ids)!=null&&i.length)for(let o of e.ids)r.push(`ids=${encodeURIComponent(o)}`);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 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 X=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 ee=class{constructor(e,t){this.http=e;this.storeId=t}async getProducts(e){var n,i;let t={storeId:this.storeId,includeVariants:!0,includePrices:!0};return(n=e==null?void 0:e.productIds)!=null&&n.length&&(t.productIds=e.productIds),(i=e==null?void 0:e.variantIds)!=null&&i.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 oe=class{constructor(e){let t=e.environment??"production",r=_.resolveBaseUrl(t,e.baseUrl);this.config={...e,environment:t,baseUrl:r,timeout:e.timeout??3e4},this.http=new _({baseUrl:r,timeout:this.config.timeout,apiKey:e.apiKey,getToken:()=>this._sessionToken});let n=i=>{this._sessionToken=i};this.checkout=new W(this.http,this.config.storeId,n),this.payment=new Z(this.http,this.config.storeId,t),this.offers=new Q(this.http,this.config.storeId),this.customer=new X(this.http,this.config.storeId),this.catalog=new ee(this.http,this.config.storeId)}setSessionToken(e){this._sessionToken=e}};function ge(s){return new oe(s)}var he=L("react/jsx-runtime"),fe=(0,$.createContext)(null);function ye({storeId:s,environment:e,apiKey:t,baseUrl:r,config:n,children:i}){let o=(0,$.useMemo)(()=>ge(n??{storeId:s,environment:e,apiKey:t,baseUrl:r}),[s,e,t,r,n]),c=(0,$.useMemo)(()=>({client:o}),[o]);return(0,he.jsx)(fe.Provider,{value:c,children:i})}function x(){let s=(0,$.useContext)(fe);if(!s)throw new Error("useHeadlessClient must be used within <TagadaHeadlessProvider>");return s.client}var A=L("react");function Pe(s,e){let t=x(),[r,n]=(0,A.useState)(null),[i,o]=(0,A.useState)(!1),[c,u]=(0,A.useState)(null),a=(0,A.useCallback)(async()=>{if(s){o(!0),u(null);try{let l=await t.checkout.loadSession(s,e);n(l)}catch(l){u(l instanceof Error?l:new Error(String(l)))}finally{o(!1)}}},[t,s,e]);(0,A.useEffect)(()=>{a()},[a]);let d=(0,A.useCallback)(async l=>{o(!0),u(null);try{let m=await t.checkout.createSession(l),I=new URL(window.location.href);I.searchParams.set("checkoutToken",m.checkoutToken),I.searchParams.set("token",m.sessionToken),window.history.replaceState({},"",I.toString());let U=await t.checkout.loadSession(m.checkoutToken,m.sessionToken);n(U)}catch(m){u(m instanceof Error?m:new Error(String(m)))}finally{o(!1)}},[t]),g=(0,A.useCallback)(async l=>{if(!r)return;let m=await t.checkout.updateCart(r.id,l);n(m)},[t,r]),h=(0,A.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.updateCustomer(r.id,l),await a()}catch(m){u(m instanceof Error?m:new Error(String(m)))}finally{o(!1)}}},[t,r,a]),p=(0,A.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.updateAddress(r.id,l),await a()}catch(m){u(m instanceof Error?m:new Error(String(m)))}finally{o(!1)}}},[t,r,a]),f=(0,A.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.applyPromoCode(r.id,l),await a()}catch(m){u(m instanceof Error?m:new Error(String(m)))}finally{o(!1)}}},[t,r,a]),y=(0,A.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.removePromoCode(r.id,l),await a()}catch(m){u(m instanceof Error?m:new Error(String(m)))}finally{o(!1)}}},[t,r,a]),S=(0,A.useCallback)(async()=>r?t.checkout.getShippingRates(r.id):[],[t,r]),P=(0,A.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.selectShippingRate(r.id,l),await a()}catch(m){u(m instanceof Error?m:new Error(String(m)))}finally{o(!1)}}},[t,r,a]);return{session:r,isLoading:i,error:c,refresh:a,createSession:d,updateCart:g,updateCustomer:h,updateAddress:p,applyPromo:f,removePromo:y,getShippingRates:S,selectShippingRate:P}}var k=L("react");function Se(){let s=x(),[e,t]=(0,k.useState)(null),[r,n]=(0,k.useState)(null),[i,o]=(0,k.useState)(null),[c,u]=(0,k.useState)(!1),[a,d]=(0,k.useState)(null),[g,h]=(0,k.useState)(null),p=(0,k.useRef)(!1),f=(0,k.useCallback)(async C=>{if(!p.current){p.current=!0;try{let[w,R,xe]=await Promise.all([s.payment.getPaymentSetup(C),s.payment.getExpressMethods(C),s.payment.getStoreConfig()]);t(w),n(R),o(xe)}catch(w){p.current=!1,h(w instanceof Error?w:new Error(String(w)))}}},[s]),y=(0,k.useCallback)(C=>async()=>{u(!0),h(null);try{return await C()}catch(w){let R=w instanceof Error?w:new Error(String(w));throw h(R),R}finally{u(!1)}},[]),S=(0,k.useCallback)(async C=>{u(!0),h(null);try{let w=await s.payment.pay(C);return d(w),w}catch(w){let R=w instanceof Error?w:new Error(String(w));throw h(R),R}finally{u(!1)}},[s]),P=(0,k.useCallback)(C=>s.payment.tokenizeCard(C),[s]),l=(0,k.useCallback)(async C=>{let R=await y(()=>s.payment.processApplePay(C))();return d(R),R},[s,y]),m=(0,k.useCallback)(async C=>{let R=await y(()=>s.payment.processGooglePay(C))();return d(R),R},[s,y]),I=(0,k.useCallback)(async C=>{let R=await y(()=>s.payment.processApm(C))();return d(R),R},[s,y]),U=(0,k.useCallback)(C=>s.payment.pollPaymentStatus(C),[s]);return{paymentSetup:e,expressMethods:r,storeConfig:i,isProcessing:c,result:a,error:g,loadPaymentSetup:f,pay:S,tokenizeCard:P,processApplePay:l,processGooglePay:m,processApm:I,pollStatus:U}}var b=L("react");function Ie(){let s=x(),[e,t]=(0,b.useState)(null),[r,n]=(0,b.useState)(null),[i,o]=(0,b.useState)(!1),[c,u]=(0,b.useState)(null),a=(0,b.useCallback)(async l=>{o(!0),u(null);try{return await l()}catch(m){let I=m instanceof Error?m:new Error(String(m));throw u(I),I}finally{o(!1)}},[]),d=(0,b.useCallback)(l=>a(async()=>{let m=await s.offers.getOffer(l);return t(m),m}),[s,a]),g=(0,b.useCallback)(l=>s.offers.listOffers(l),[s]),h=(0,b.useCallback)(l=>a(async()=>{let m=await s.offers.previewOffer(l);return n(m),m}),[s,a]),p=(0,b.useCallback)(l=>a(()=>s.offers.payPreviewedOffer(l)),[s,a]),f=(0,b.useCallback)(l=>s.offers.toggleOrderBump(l),[s]),y=(0,b.useCallback)(l=>s.offers.listPostPurchaseOffers(l),[s]),S=(0,b.useCallback)(l=>a(()=>s.offers.acceptPostPurchaseOffer(l)),[s,a]),P=(0,b.useCallback)(l=>a(()=>s.offers.declinePostPurchaseOffer(l)),[s,a]);return{offer:e,preview:r,isLoading:i,error:c,getOffer:d,listOffers:g,previewOffer:h,payPreviewedOffer:p,toggleOrderBump:f,listPostPurchaseOffers:y,acceptPostPurchaseOffer:S,declinePostPurchaseOffer:P}}var O=L("react");function we(s){let e=x(),[t,r]=(0,O.useState)(null),[n,i]=(0,O.useState)([]),[o,c]=(0,O.useState)([]),[u,a]=(0,O.useState)(!1),[d,g]=(0,O.useState)(null),h=(0,O.useCallback)(async S=>{a(!0),g(null);try{let P=await e.customer.getProfile(S);r(P)}catch(P){g(P instanceof Error?P:new Error(String(P)))}finally{a(!1)}},[e]),p=(0,O.useCallback)(async S=>{try{let P=await e.customer.getOrders(S);i(P.orders)}catch(P){g(P instanceof Error?P:new Error(String(P)))}},[e]),f=(0,O.useCallback)(async S=>{try{let P=await e.customer.getSubscriptions(S);c(P)}catch(P){g(P instanceof Error?P:new Error(String(P)))}},[e]),y=(0,O.useCallback)(async(S,P)=>{try{let l=await e.customer.updateProfile(S,P);r(l)}catch(l){g(l instanceof Error?l:new Error(String(l)))}},[e]);return(0,O.useEffect)(()=>{s&&h(s)},[s,h]),{customer:t,orders:n,subscriptions:o,isLoading:u,error:d,loadCustomer:h,loadOrders:p,loadSubscriptions:f,updateProfile:y}}var G=L("react");function Ce(){let s=x(),[e,t]=(0,G.useState)([]),[r,n]=(0,G.useState)(!1),[i,o]=(0,G.useState)(null),c=(0,G.useCallback)(async a=>{n(!0),o(null);try{let d=await s.catalog.getProducts(a);return t(d),d}catch(d){let g=d instanceof Error?d:new Error(String(d));throw o(g),g}finally{n(!1)}},[s]),u=(0,G.useCallback)(async a=>{n(!0),o(null);try{return await s.catalog.getProduct(a)}catch(d){let g=d instanceof Error?d:new Error(String(d));throw o(g),g}finally{n(!1)}},[s]);return{products:e,isLoading:r,error:i,loadProducts:c,loadProduct:u}}var v=L("react");var ke=!1,ve=!1,te=[];function ie(){ve=!0;for(let s of te)s();te.length=0}function j(s,e={}){var t,r;return ve||(r=(t=window.google)==null?void 0:t.maps)!=null&&r.places?(ie(),Promise.resolve()):ke?new Promise(n=>te.push(n)):(ke=!0,new Promise((n,i)=>{if(te.push(n),document.querySelector('script[src*="maps.googleapis.com"]')){let a=()=>{var d,g;(g=(d=window.google)==null?void 0:d.maps)!=null&&g.places?ie():setTimeout(a,100)};a();return}let c=new URLSearchParams({key:s,libraries:"places",v:e.version??"weekly"});e.language&&c.set("language",e.language),e.region&&c.set("region",e.region);let u=document.createElement("script");u.src=`https://maps.googleapis.com/maps/api/js?${c}`,u.async=!0,u.defer=!0,u.onload=()=>ie(),u.onerror=()=>i(new Error("Failed to load Google Maps script")),document.head.appendChild(u)}))}var T=class s{static async searchPlaces(e,t={}){var n,i;if(!((i=(n=window.google)==null?void 0:n.maps)!=null&&i.places)||!e.trim())return[];let r=new window.google.maps.places.AutocompleteService;return new Promise(o=>{r.getPlacePredictions({input:e,types:t.types??["address"],componentRestrictions:t.componentRestrictions},(c,u)=>{var a,d,g;o(u===((g=(d=(a=window.google)==null?void 0:a.maps)==null?void 0:d.places)==null?void 0:g.PlacesServiceStatus.OK)&&c?c:[])})})}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(i=>{t.getDetails({placeId:e,fields:["place_id","formatted_address","address_components","geometry"]},(o,c)=>{var u,a,d;i(c===((d=(a=(u=window.google)==null?void 0:u.maps)==null?void 0:a.places)==null?void 0:d.PlacesServiceStatus.OK)&&o?o:null)})})}static extractAddressComponents(e){let t={subpremise:"",streetNumber:"",route:"",locality:"",administrativeAreaLevel1:"",administrativeAreaLevel1Long:"",administrativeAreaLevel2:"",administrativeAreaLevel2Long:"",country:"",postalCode:"",fullStreetAddress:""},r="",n="",i="",o="",c="",u="",a="",d="";for(let p of e.address_components??[]){let f=p.types;f.includes("subpremise")&&(t.subpremise=p.long_name),f.includes("street_number")&&(t.streetNumber=p.long_name),f.includes("premise")&&(r=p.long_name),f.includes("route")&&(t.route=p.long_name),f.includes("neighborhood")&&(n=p.long_name),f.includes("sublocality_level_5")&&(i=p.long_name),f.includes("sublocality_level_4")&&(o=p.long_name),f.includes("sublocality_level_3")&&(c=p.long_name),f.includes("sublocality_level_2")&&(u=p.long_name),f.includes("sublocality_level_1")&&(a=p.long_name),f.includes("locality")&&(t.locality=p.long_name),f.includes("postal_town")&&(d=p.long_name),f.includes("administrative_area_level_2")&&(t.administrativeAreaLevel2=p.short_name,t.administrativeAreaLevel2Long=p.long_name),f.includes("administrative_area_level_1")&&(t.administrativeAreaLevel1=p.short_name,t.administrativeAreaLevel1Long=p.long_name),f.includes("country")&&(t.country=p.short_name),f.includes("postal_code")&&(t.postalCode=p.long_name)}t.locality||(t.locality=d||u||a||""),!t.administrativeAreaLevel1&&t.administrativeAreaLevel2&&(t.administrativeAreaLevel1=t.administrativeAreaLevel2Long||t.administrativeAreaLevel2,t.administrativeAreaLevel1Long=t.administrativeAreaLevel2Long);let g=t.streetNumber||r,h=t.route||i||o||c||n;if(t.subpremise&&g&&h)t.fullStreetAddress=`${t.subpremise}/${g} ${h}`;else if(g&&h)if(r&&o&&c){let p=`${c}-${o}-${r}`;u&&(p=`${p} ${u}`),t.fullStreetAddress=p}else t.fullStreetAddress=`${g} ${h}`;else h?t.fullStreetAddress=h:g&&(t.fullStreetAddress=g);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 Re(s){let{apiKey:e,language:t,region:r,version:n,defer:i=!1}=s,[o,c]=(0,v.useState)([]),[u,a]=(0,v.useState)(!1),[d,g]=(0,v.useState)(!1),h=(0,v.useRef)(null),p=(0,v.useRef)(null),f=(0,v.useCallback)(()=>{j(e,{language:t,region:r,version:n}).then(()=>g(!0))},[e,t,r,n]);(0,v.useEffect)(()=>{!e||i||f()},[e,i,f]),(0,v.useEffect)(()=>{if(d&&p.current){let{input:I,country:U}=p.current;p.current=null,y(I,U)}},[d]);let y=(0,v.useCallback)((I,U)=>{if(!d){i&&(p.current={input:I,country:U},f());return}if(I.length<3){c([]);return}h.current&&clearTimeout(h.current),h.current=setTimeout(async()=>{a(!0);let C=await T.searchPlaces(I,{componentRestrictions:U?{country:U.toLowerCase()}:void 0});c(C),a(!1)},300)},[d,i,f]),S=(0,v.useCallback)(I=>T.getPlaceDetails(I),[]),P=(0,v.useCallback)(I=>T.extractAddressComponents(I),[]),l=(0,v.useCallback)(I=>T.extractFormattedAddress(I),[]),m=(0,v.useCallback)(()=>c([]),[]);return{predictions:o,isLoading:u,isScriptLoaded:d,searchPlaces:y,getPlaceDetails:S,extractAddressComponents:P,extractFormattedAddress:l,clearPredictions:m}}var N=L("react");var Ae="https://cvwnizdbugpz6jwk.public.blob.vercel-storage.com/geodata/v1",ue=["en","ru","de","da","fr","es","zh","hi","pt","ja","ar","it","he"],K=new Map,re=new Map,ae=new Map,ce=new Map;async function He(s){let e=K.get(s);if(e)return e;let t=ae.get(s);return t||(t=(async()=>{let r=`${Ae}/${s}/countries.json`,n=await fetch(r);if(!n.ok)throw new Error(`Geodata fetch failed: ${r} (${n.status})`);let i=await n.json();return K.set(s,i),ae.delete(s),i})(),ae.set(s,t),t)}async function Me(s){let e=re.get(s);if(e)return e;let t=ce.get(s);return t||(t=(async()=>{let r=`${Ae}/${s}/regions.json`,n=await fetch(r);if(!n.ok)throw new Error(`Geodata fetch failed: ${r} (${n.status})`);let i=await n.json();return re.set(s,i),ce.delete(s),i})(),ce.set(s,t),t)}function _e(s){return K.get(s)||K.get("en")||{}}function je(s){return re.get(s)||re.get("en")||{}}async function F(s="en"){await Promise.all([He(s),Me(s)])}var se=(s="en")=>{let e=_e(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))},de=(s,e="en")=>{let r=je(e)[s];return r?r.map(([n,i])=>({code:n,name:i,countryCode:s})).sort((n,i)=>n.name.localeCompare(i.name)):[]};function q(s){return K.has(s)}var D=class s{static ensureLoaded(e="en"){return F(e)}static getCountries(e="en"){let t=se(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 se(e).map(t=>({value:t.code,label:t.name}))}static getRegions(e,t="en"){return de(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 i=s.getRegions(r,n);if(i.length===0)return null;let o=i.find(c=>c.iso===e);return o||(o=i.find(c=>c.name.toLowerCase()===e.toLowerCase()),o)||(o=i.find(c=>c.name.toLowerCase()===t.toLowerCase()),o)?o:(o=i.find(c=>c.name.toLowerCase().includes(t.toLowerCase())||t.toLowerCase().includes(c.name.toLowerCase())),o??null)}static isLanguageLoaded(e){return q(e)}static getAvailableLanguages(){return ue}};function ne(s="en"){let[e,t]=(0,N.useState)(q(s));return(0,N.useEffect)(()=>{let r=!1;return F(s).then(()=>{r||t(!0)}).catch(n=>console.error("[headless-sdk] Failed to load geodata:",n)),()=>{r=!0}},[s]),(0,N.useMemo)(()=>e?{countries:D.getCountries(s),getRegions:r=>D.getRegions(r,s),findRegion:(r,n)=>D.findRegion(r,n,s),mapGoogleToISO:(r,n,i)=>D.mapGoogleToISO(r,n,i,s),isLoaded:!0}:{countries:{},getRegions:()=>[],findRegion:()=>null,mapGoogleToISO:()=>null,isLoaded:!1},[s,e])}function be(s="en"){let{countries:e,isLoaded:t}=ne(s);return(0,N.useMemo)(()=>t?Object.values(e).map(r=>({value:r.iso,label:r.name})).sort((r,n)=>r.label.localeCompare(n.label)):[],[e,t])}function Oe(s,e="en"){let{getRegions:t,isLoaded:r}=ne(e);return(0,N.useMemo)(()=>!r||!s?[]:t(s).map(n=>({value:n.iso,label:n.name})).sort((n,i)=>n.label.localeCompare(i.label)),[s,t,r])}var Ke={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"},Fe={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"},qe=new Set(["JPY","KRW","VND","IDR","LAK","KHR","MMK","PYG"]),H=class s{static getSymbol(e){return Ke[e]??e}static getName(e){return Fe[e]??e}static getDecimalPlaces(e){return qe.has(e)?0:2}static getCurrency(e){return{code:e,symbol:s.getSymbol(e),name:s.getName(e),decimalPlaces:s.getDecimalPlaces(e)}}};function le(s,e="USD",t="en-US"){let r=H.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`${H.getSymbol(e)}${n.toFixed(r)}`}}return Ge(Be);})();
|
|
6
|
+
"use strict";var TagadaHeadlessReactBundle=(()=>{var Ke=Object.create;var Z=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Je=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var L=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var Ye=(n,e)=>{for(var t in e)Z(n,t,{get:e[t],enumerable:!0})},Ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ze(e))!Ve.call(n,s)&&s!==t&&Z(n,s,{get:()=>e[s],enumerable:!(r=Be(e,s))||r.enumerable});return n};var Ce=(n,e,t)=>(t=n!=null?Ke(Je(n)):{},Ie(e||!n||!n.__esModule?Z(t,"default",{value:n,enumerable:!0}):t,n)),We=n=>Ie(Z({},"__esModule",{value:!0}),n);var ot={};Ye(ot,{CurrencyUtils:()=>F,GoogleAutocompleteCore:()=>N,ISODataCore:()=>_,TagadaHeadlessProvider:()=>Re,formatMoney:()=>Se,loadGoogleMapsScript:()=>z,useCatalog:()=>Te,useCheckout:()=>Oe,useCountryOptions:()=>$e,useCustomer:()=>Le,useGoogleAutocomplete:()=>Ne,useHeadlessClient:()=>T,useISOData:()=>de,useOffers:()=>xe,usePayment:()=>Ee,useRegionOptions:()=>Ge});var H=L("react");var U=class extends Error{constructor(e,t,r,s){super(e),this.name="TagadaError",this.code=t,this.statusCode=r,this.details=s}},Q=class extends U{constructor(e="Authentication failed. Check your API key or checkout token."){super(e,"auth_error",401),this.name="TagadaAuthError"}},X=class extends U{constructor(e,t=[]){super(e,"validation_error",422,{errors:t}),this.name="TagadaValidationError",this.errors=t}},ee=class extends U{constructor(e,t){super(`${e} "${t}" not found.`,"not_found",404),this.name="TagadaNotFoundError"}},te=class extends U{constructor(e=1e3){super(`Rate limited. Retry after ${e}ms.`,"rate_limit",429),this.name="TagadaRateLimitError",this.retryAfterMs=e}};var K=class extends U{constructor(e="Network request failed. Check your connection."){super(e,"network_error"),this.name="TagadaNetworkError"}};var ve={production:"https://app.tagadapay.com",development:"https://app.dev.tagadapay.com",local:"http://localhost:3000"},B=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??ve[e]??ve.production}async request(e,t={}){var f;let{method:r="GET",body:s,headers:i={},params:o,token:a,signal:u}=t,c=`${this.baseUrl}${e}`;if(o){let P=new URLSearchParams;for(let[y,l]of Object.entries(o))l!==void 0&&P.set(y,String(l));let S=P.toString();S&&(c+=`?${S}`)}let m={"Content-Type":"application/json",...i},g=a??this.apiKey??((f=this.getToken)==null?void 0:f.call(this));g&&(m["x-cms-token"]=g);let w=new AbortController,d=setTimeout(()=>w.abort(),this.timeout);try{let P=await fetch(c,{method:r,headers:m,body:s!=null?JSON.stringify(s):void 0,signal:u??w.signal});if(clearTimeout(d),P.ok){let S=await P.text();return S?JSON.parse(S):{}}throw await this.handleErrorResponse(P,e),new U("Unexpected error","unknown",P.status)}catch(P){throw clearTimeout(d),P instanceof U?P:P instanceof DOMException&&P.name==="AbortError"?new K(`Request to ${e} timed out after ${this.timeout}ms.`):new K(P instanceof Error?P.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 s=r.message??r.error??`Request failed: ${e.status} ${e.statusText} on ${t}`;switch(e.status){case 401:case 403:throw new Q(s);case 404:throw new ee(t,"");case 422:{let i=Array.isArray(r.errors)?r.errors:[];throw new X(s,i)}case 429:{let i=Number(e.headers.get("Retry-After")??"1")*1e3;throw new te(i)}default:throw new U(s,"api_error",e.status,r)}}};var re=class{constructor(e,t,r){this.http=e;this.storeId=t;this.onTokenChange=r}async loadSession(e,t){var s;t&&(this.sessionToken=t,(s=this.onTokenChange)==null||s.call(this,t));let r=await this.http.get(`/api/v1/checkout-sessions/${e}/v2`,{params:{skipAsyncWait:"false"},token:this.sessionToken});return this.normalizeSession(r)}async createSession(e){var a;let t=e.items.map(u=>({variantId:u.variantId,priceId:u.priceId,quantity:u.quantity})),r={storeId:this.storeId,lineItems:t};e.currency&&(r.currency=e.currency),e.returnUrl&&(r.returnUrl=e.returnUrl),e.customerEmail&&(r.customer={email:e.customerEmail,firstName:e.customerFirstName,lastName:e.customerLastName,currency:e.currency});let s=await this.http.post("/api/v1/checkout/session/init",r),o=new URL(s.checkoutUrl).searchParams.get("token")??"";return this.sessionToken=o,o&&((a=this.onTokenChange)==null||a.call(this,o)),{checkoutUrl:s.checkoutUrl,checkoutToken:s.checkoutToken,sessionToken:o,customerId:s.customerId}}async updateCart(e,t){return this.http.post(`/api/v1/checkout-sessions/${e}/line-items`,{items:t},{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),s=this.mapAddress(t.billingAddress),i=r??s??{},o=s??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:i,billingAddress:o??{},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),s=this.mapAddress(t.billingAddress),i=r??s??{},o=s??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:i,billingAddress:o??{},differentBillingAddress:a},{token:this.sessionToken})}mapAddress(e){if(e)return Ze({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??[]}async selectShippingRate(e,t){await this.http.post(`/api/v1/checkout-sessions/${e}/shipping-rate`,{checkoutSessionId:e,shippingRateId:t},{token:this.sessionToken})}normalizeSession(e){let t=e.checkoutSession,r=t.orderSummaries??[],s=e.summary??t.summary??r[0]??{},i=t.sessionLineItems??[],o=t.customer,a=i.map(c=>{let m=c.price,g=(m==null?void 0:m.variant)??{},w=g.product??{},d=(m==null?void 0:m.currencyOptions)??{},f=d.USD??d[Object.keys(d)[0]];return{id:c.id,variantId:c.variantId,priceId:c.priceId,productName:w.name??"",variantName:g.name??"",quantity:c.quantity??1,unitAmount:(f==null?void 0:f.amount)??0,totalAmount:((f==null?void 0:f.amount)??0)*(c.quantity??1),currency:t.selectedPresentmentCurrency??"USD",imageUrl:g.imageUrl??""}}),u=s.items??[];return{id:t.id,storeId:t.storeId,checkoutToken:t.checkoutToken,currency:t.selectedPresentmentCurrency??"USD",items:a,totals:{subtotal:s.subtotalAmount??0,discount:s.totalPromotionAmount??0,shipping:s.shippingCost??0,tax:s.totalTaxAmount??0,total:s.totalAmount??u.reduce((c,m)=>c+(m.amount??0),0),currency:s.currency??t.selectedPresentmentCurrency??"USD"},customer:o?{id:o.id,email:o.email,firstName:o.firstName,lastName:o.lastName}:void 0,shippingAddress:t.shippingAddress,billingAddress:t.billingAddress,metadata:t.metadata}}};function Ze(n){let e={};for(let[t,r]of Object.entries(n))r!=null&&r!==""&&(e[t]=r);return Object.keys(e).length>0?e:void 0}var se=class{constructor(e,t,r){this.http=e;this.storeId=t;this.environment=r}async getPaymentSetup(e){let t=await this.http.get("/api/v1/payment-methods",{params:{checkoutSessionId:e}}),r={};for(let s of t.methods??[]){let i=s.provider?`${s.method}:${s.provider}`:s.method;r[i]=s}return r}async getExpressMethods(e){var s,i;let t=await this.getPaymentSetup(e),r={};for(let[,o]of Object.entries(t)){if(!o.enabled||!o.express)continue;let a=o.method,u={type:a,available:!0,processorId:o.processorId,publishableKey:o.publishableKey,metadata:o.metadata};if(a==="apple_pay"||o.type==="apple_pay"){let c=typeof window<"u"&&"ApplePaySession"in window&&((i=(s=window.ApplePaySession)==null?void 0:s.canMakePayments)==null?void 0:i.call(s));r.applePay={...u,available:!!c}}else a==="google_pay"||o.type==="google_pay"?r.googlePay=u:a==="paypal"?r.paypal=u:a==="klarna"||a==="klarna_express"?r.klarna=u:a==="link"&&(r.link=u)}return r}async getStoreConfig(){let e=await this.http.get("/api/v1/checkout/config",{params:{storeId:this.storeId}});return e.config??e}async getEnabledMethods(e){let t=await this.getPaymentSetup(e);return Object.entries(t).filter(([,r])=>r.enabled).map(([r])=>r)}async tokenizeCard(e){let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let s={cardNumber:e.cardNumber,expiryDate:e.expiryDate,cvc:e.cvc};e.cardholderName&&(s.cardholderName=e.cardholderName);let[i,o]=await Promise.all([r.tokenizeCard(s),r.tokenizeCardRaw(s)]);return{tagadaToken:i,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})}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})}async processApplePay(e){let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let{tagadaToken:s}=await r.tokenizeApplePay(e.applePayToken);return this.pay({checkoutSessionId:e.checkoutSessionId,tagadaToken:s,paymentFlowId:e.paymentFlowId,processorId:e.processorId,paymentMethod:"apple_pay",isExpress:!0})}async processGooglePay(e){let t=await this.loadCoreJs(),r=new t.Tokenizer({environment:this.environment});await r.initialize();let{tagadaToken:s}=await r.tokenizeGooglePay(e.googlePayToken);return this.pay({checkoutSessionId:e.checkoutSessionId,tagadaToken:s,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 processPayment(e){var s,i;!e.returnUrl&&typeof window<"u"&&(e={...e,returnUrl:window.location.href});let t=await this.pay(e),r=t.payment;return r.status==="succeeded"?{status:"succeeded",payment:r,order:t.order}:r.status==="failed"||r.status==="declined"?{status:"failed",error:((s=r.requireActionData)==null?void 0:s.message)||((i=r.requireActionData)==null?void 0:i.errorCode)||`Payment ${r.status}`,payment:r}:r.requireAction&&r.requireAction!=="none"&&r.requireActionData?this.handlePaymentAction(r,e):this.pollUntilDone(r.id)}async resumeAfterRedirect(e){return this.pollUntilDone(e)}async getPaymentStatus(e){return this.http.get(`/api/v1/payments/${e}`)}async pollPaymentStatus(e,t){let r=(t==null?void 0:t.intervalMs)??1500,s=(t==null?void 0:t.timeoutMs)??6e4,i=Date.now();for(;Date.now()-i<s;){let o=await this.getPaymentStatus(e);if(o.status==="succeeded"||o.status==="failed"||o.status==="declined")return o;await new Promise(a=>setTimeout(a,r))}throw new Error(`Payment ${e} did not reach terminal status within ${s}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 i,o;let r=(i=t.metadata)==null?void 0:i.redirect,s=(r==null?void 0:r.redirectUrl)||t.redirectUrl;return s?{status:"requires_redirect",redirectUrl:s,method:((o=r==null?void 0:r.method)==null?void 0:o.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 i,o;let r=(o=(i=e.requireActionData)==null?void 0:i.metadata)==null?void 0:o.threedsSession;if(!(r!=null&&r.externalSessionId))return this.extractRedirect(e,e.requireActionData);let s;try{s=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 s.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,s=(t==null?void 0:t.timeoutMs)??6e4,i=Date.now(),o=0;for(;Date.now()-i<s;){let a;try{a=await this.getPaymentStatus(e),o=0}catch{if(o++,o>=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}}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 ne=class{constructor(e,t){this.http=e;this.storeId=t}async getOffer(e){return this.http.get(`/api/v1/offers/${e}`)}async listOffers(e){var i;let t=`/api/v1/stores/${this.storeId}/offers`,r=[];if(e!=null&&e.type&&r.push(`type=${encodeURIComponent(e.type)}`),(i=e==null?void 0:e.ids)!=null&&i.length)for(let o of e.ids)r.push(`ids=${encodeURIComponent(o)}`);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 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 oe=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 ie=class{constructor(e,t){this.http=e;this.storeId=t}async getProducts(e){var s,i;let t={storeId:this.storeId,includeVariants:!0,includePrices:!0};return(s=e==null?void 0:e.productIds)!=null&&s.length&&(t.productIds=e.productIds),(i=e==null?void 0:e.variantIds)!=null&&i.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 ge=class{constructor(e){let t=e.environment??"production",r=B.resolveBaseUrl(t,e.baseUrl);this.config={...e,environment:t,baseUrl:r,timeout:e.timeout??3e4},this.http=new B({baseUrl:r,timeout:this.config.timeout,apiKey:e.apiKey,getToken:()=>this._sessionToken});let s=i=>{this._sessionToken=i};this.checkout=new re(this.http,this.config.storeId,s),this.payment=new se(this.http,this.config.storeId,t),this.offers=new ne(this.http,this.config.storeId),this.customer=new oe(this.http,this.config.storeId),this.catalog=new ie(this.http,this.config.storeId)}setSessionToken(e){this._sessionToken=e}};function ke(n){return new ge(n)}var be=L("react/jsx-runtime"),Ae=(0,H.createContext)(null);function Re({storeId:n,environment:e,apiKey:t,baseUrl:r,config:s,children:i}){let o=(0,H.useMemo)(()=>ke(s??{storeId:n,environment:e,apiKey:t,baseUrl:r}),[n,e,t,r,s]),a=(0,H.useMemo)(()=>({client:o}),[o]);return(0,be.jsx)(Ae.Provider,{value:a,children:i})}function T(){let n=(0,H.useContext)(Ae);if(!n)throw new Error("useHeadlessClient must be used within <TagadaHeadlessProvider>");return n.client}var b=L("react");function Oe(n,e){let t=T(),[r,s]=(0,b.useState)(null),[i,o]=(0,b.useState)(!1),[a,u]=(0,b.useState)(null),c=(0,b.useCallback)(async()=>{if(n){o(!0),u(null);try{let l=await t.checkout.loadSession(n,e);s(l)}catch(l){u(l instanceof Error?l:new Error(String(l)))}finally{o(!1)}}},[t,n,e]);(0,b.useEffect)(()=>{c()},[c]);let m=(0,b.useCallback)(async l=>{o(!0),u(null);try{let p=await t.checkout.createSession(l),A=new URL(window.location.href);A.searchParams.set("checkoutToken",p.checkoutToken),A.searchParams.set("token",p.sessionToken),window.history.replaceState({},"",A.toString());let $=await t.checkout.loadSession(p.checkoutToken,p.sessionToken);s($)}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{o(!1)}},[t]),g=(0,b.useCallback)(async l=>{if(!r)return;let p=await t.checkout.updateCart(r.id,l);s(p)},[t,r]),w=(0,b.useCallback)(async l=>{r&&await t.checkout.updateCustomer(r.id,l)},[t,r]),d=(0,b.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.updateAddress(r.id,l),await c()}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{o(!1)}}},[t,r,c]),f=(0,b.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.applyPromoCode(r.id,l),await c()}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{o(!1)}}},[t,r,c]),P=(0,b.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.removePromoCode(r.id,l),await c()}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{o(!1)}}},[t,r,c]),S=(0,b.useCallback)(async()=>r?t.checkout.getShippingRates(r.id):[],[t,r]),y=(0,b.useCallback)(async l=>{if(r){o(!0);try{await t.checkout.selectShippingRate(r.id,l),await c()}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{o(!1)}}},[t,r,c]);return{session:r,isLoading:i,error:a,refresh:c,createSession:m,updateCart:g,updateCustomer:w,updateAddress:d,applyPromo:f,removePromo:P,getShippingRates:S,selectShippingRate:y}}var I=L("react");function Ee(n){let e=T(),[t,r]=(0,I.useState)(null),[s,i]=(0,I.useState)(null),[o,a]=(0,I.useState)(null),[u,c]=(0,I.useState)(!1),[m,g]=(0,I.useState)(null),[w,d]=(0,I.useState)(null),f=(0,I.useRef)(!1),P=(0,I.useRef)(!1),S=(0,I.useRef)(n);S.current=n,(0,I.useEffect)(()=>{if(typeof window>"u"||P.current)return;let C=new URLSearchParams(window.location.search),h=C.get("paymentAction"),k=C.get("paymentActionStatus"),G=C.get("paymentId");if(h!=="requireAction"||k!=="completed"||!G)return;P.current=!0,c(!0),d(null),(async()=>{var v,D,j,W;try{let E=await e.payment.resumeAfterRedirect(G),pe=new URLSearchParams(window.location.search);["paymentAction","paymentActionStatus","paymentId","payment_intent","payment_intent_client_secret","source_type","redirect_status"].forEach(je=>pe.delete(je));let Fe=pe.toString()?`${window.location.pathname}?${pe.toString()}`:window.location.pathname;window.history.replaceState({},document.title,Fe),E.status==="succeeded"?(D=(v=S.current)==null?void 0:v.onPaymentSuccess)==null||D.call(v,E):E.status==="failed"&&(d(new Error(E.error)),(W=(j=S.current)==null?void 0:j.onPaymentFailed)==null||W.call(j,E))}catch(E){d(E instanceof Error?E:new Error(String(E)))}finally{c(!1)}})()},[e]);let y=(0,I.useCallback)(async C=>{if(!f.current){f.current=!0;try{let[h,k,G]=await Promise.all([e.payment.getPaymentSetup(C),e.payment.getExpressMethods(C),e.payment.getStoreConfig()]);r(h),i(k),a(G)}catch(h){f.current=!1,d(h instanceof Error?h:new Error(String(h)))}}},[e]),l=(0,I.useCallback)(async C=>{var h,k,G,me;c(!0),d(null);try{let v=await e.payment.processPayment(C);if(v.status==="requires_redirect"){if(v.method==="POST"&&v.postData){let D=document.createElement("form");D.method="POST",D.action=v.redirectUrl;for(let[j,W]of Object.entries(v.postData)){let E=document.createElement("input");E.type="hidden",E.name=j,E.value=W,D.appendChild(E)}document.body.appendChild(D),D.submit()}else window.location.href=v.redirectUrl;return v}return v.status==="succeeded"?(k=(h=S.current)==null?void 0:h.onPaymentSuccess)==null||k.call(h,v):v.status==="failed"&&(d(new Error(v.error)),(me=(G=S.current)==null?void 0:G.onPaymentFailed)==null||me.call(G,v)),v}catch(v){let D=v instanceof Error?v:new Error(String(v));return d(D),{status:"failed",error:D.message}}finally{c(!1)}},[e]),p=(0,I.useCallback)(C=>async()=>{c(!0),d(null);try{return await C()}catch(h){let k=h instanceof Error?h:new Error(String(h));throw d(k),k}finally{c(!1)}},[]),A=(0,I.useCallback)(async C=>{c(!0),d(null);try{let h=await e.payment.pay(C);return g(h),h}catch(h){let k=h instanceof Error?h:new Error(String(h));throw d(k),k}finally{c(!1)}},[e]),$=(0,I.useCallback)(C=>e.payment.tokenizeCard(C),[e]),le=(0,I.useCallback)(async C=>{let k=await p(()=>e.payment.processApplePay(C))();return g(k),k},[e,p]),Me=(0,I.useCallback)(async C=>{let k=await p(()=>e.payment.processGooglePay(C))();return g(k),k},[e,p]),He=(0,I.useCallback)(async C=>{let k=await p(()=>e.payment.processApm(C))();return g(k),k},[e,p]),qe=(0,I.useCallback)(C=>e.payment.pollPaymentStatus(C),[e]);return{paymentSetup:t,expressMethods:s,storeConfig:o,isProcessing:u,result:m,error:w,loadPaymentSetup:y,processPayment:l,pay:A,tokenizeCard:$,processApplePay:le,processGooglePay:Me,processApm:He,pollStatus:qe}}var O=L("react");function xe(){let n=T(),[e,t]=(0,O.useState)(null),[r,s]=(0,O.useState)(null),[i,o]=(0,O.useState)(!1),[a,u]=(0,O.useState)(null),c=(0,O.useCallback)(async l=>{o(!0),u(null);try{return await l()}catch(p){let A=p instanceof Error?p:new Error(String(p));throw u(A),A}finally{o(!1)}},[]),m=(0,O.useCallback)(l=>c(async()=>{let p=await n.offers.getOffer(l);return t(p),p}),[n,c]),g=(0,O.useCallback)(l=>n.offers.listOffers(l),[n]),w=(0,O.useCallback)(l=>c(async()=>{let p=await n.offers.previewOffer(l);return s(p),p}),[n,c]),d=(0,O.useCallback)(l=>c(()=>n.offers.payPreviewedOffer(l)),[n,c]),f=(0,O.useCallback)(l=>n.offers.toggleOrderBump(l),[n]),P=(0,O.useCallback)(l=>n.offers.listPostPurchaseOffers(l),[n]),S=(0,O.useCallback)(l=>c(()=>n.offers.acceptPostPurchaseOffer(l)),[n,c]),y=(0,O.useCallback)(l=>c(()=>n.offers.declinePostPurchaseOffer(l)),[n,c]);return{offer:e,preview:r,isLoading:i,error:a,getOffer:m,listOffers:g,previewOffer:w,payPreviewedOffer:d,toggleOrderBump:f,listPostPurchaseOffers:P,acceptPostPurchaseOffer:S,declinePostPurchaseOffer:y}}var x=L("react");function Le(n){let e=T(),[t,r]=(0,x.useState)(null),[s,i]=(0,x.useState)([]),[o,a]=(0,x.useState)([]),[u,c]=(0,x.useState)(!1),[m,g]=(0,x.useState)(null),w=(0,x.useCallback)(async S=>{c(!0),g(null);try{let y=await e.customer.getProfile(S);r(y)}catch(y){g(y instanceof Error?y:new Error(String(y)))}finally{c(!1)}},[e]),d=(0,x.useCallback)(async S=>{try{let y=await e.customer.getOrders(S);i(y.orders)}catch(y){g(y instanceof Error?y:new Error(String(y)))}},[e]),f=(0,x.useCallback)(async S=>{try{let y=await e.customer.getSubscriptions(S);a(y)}catch(y){g(y instanceof Error?y:new Error(String(y)))}},[e]),P=(0,x.useCallback)(async(S,y)=>{try{let l=await e.customer.updateProfile(S,y);r(l)}catch(l){g(l instanceof Error?l:new Error(String(l)))}},[e]);return(0,x.useEffect)(()=>{n&&w(n)},[n,w]),{customer:t,orders:s,subscriptions:o,isLoading:u,error:m,loadCustomer:w,loadOrders:d,loadSubscriptions:f,updateProfile:P}}var q=L("react");function Te(){let n=T(),[e,t]=(0,q.useState)([]),[r,s]=(0,q.useState)(!1),[i,o]=(0,q.useState)(null),a=(0,q.useCallback)(async c=>{s(!0),o(null);try{let m=await n.catalog.getProducts(c);return t(m),m}catch(m){let g=m instanceof Error?m:new Error(String(m));throw o(g),g}finally{s(!1)}},[n]),u=(0,q.useCallback)(async c=>{s(!0),o(null);try{return await n.catalog.getProduct(c)}catch(m){let g=m instanceof Error?m:new Error(String(m));throw o(g),g}finally{s(!1)}},[n]);return{products:e,isLoading:r,error:i,loadProducts:a,loadProduct:u}}var R=L("react");var De=!1,Ue=!1,ae=[];function fe(){Ue=!0;for(let n of ae)n();ae.length=0}function z(n,e={}){var t,r;return Ue||(r=(t=window.google)==null?void 0:t.maps)!=null&&r.places?(fe(),Promise.resolve()):De?new Promise(s=>ae.push(s)):(De=!0,new Promise((s,i)=>{if(ae.push(s),document.querySelector('script[src*="maps.googleapis.com"]')){let c=()=>{var m,g;(g=(m=window.google)==null?void 0:m.maps)!=null&&g.places?fe():setTimeout(c,100)};c();return}let a=new URLSearchParams({key:n,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=()=>fe(),u.onerror=()=>i(new Error("Failed to load Google Maps script")),document.head.appendChild(u)}))}var N=class n{static async searchPlaces(e,t={}){var s,i;if(!((i=(s=window.google)==null?void 0:s.maps)!=null&&i.places)||!e.trim())return[];let r=new window.google.maps.places.AutocompleteService;return new Promise(o=>{r.getPlacePredictions({input:e,types:t.types??["address"],componentRestrictions:t.componentRestrictions},(a,u)=>{var c,m,g;o(u===((g=(m=(c=window.google)==null?void 0:c.maps)==null?void 0:m.places)==null?void 0:g.PlacesServiceStatus.OK)&&a?a:[])})})}static async getPlaceDetails(e){var r,s;if(!((s=(r=window.google)==null?void 0:r.maps)!=null&&s.places))return null;let t=new window.google.maps.places.PlacesService(document.createElement("div"));return new Promise(i=>{t.getDetails({placeId:e,fields:["place_id","formatted_address","address_components","geometry"]},(o,a)=>{var u,c,m;i(a===((m=(c=(u=window.google)==null?void 0:u.maps)==null?void 0:c.places)==null?void 0:m.PlacesServiceStatus.OK)&&o?o:null)})})}static extractAddressComponents(e){let t={subpremise:"",streetNumber:"",route:"",locality:"",administrativeAreaLevel1:"",administrativeAreaLevel1Long:"",administrativeAreaLevel2:"",administrativeAreaLevel2Long:"",country:"",postalCode:"",fullStreetAddress:""},r="",s="",i="",o="",a="",u="",c="",m="";for(let d of e.address_components??[]){let f=d.types;f.includes("subpremise")&&(t.subpremise=d.long_name),f.includes("street_number")&&(t.streetNumber=d.long_name),f.includes("premise")&&(r=d.long_name),f.includes("route")&&(t.route=d.long_name),f.includes("neighborhood")&&(s=d.long_name),f.includes("sublocality_level_5")&&(i=d.long_name),f.includes("sublocality_level_4")&&(o=d.long_name),f.includes("sublocality_level_3")&&(a=d.long_name),f.includes("sublocality_level_2")&&(u=d.long_name),f.includes("sublocality_level_1")&&(c=d.long_name),f.includes("locality")&&(t.locality=d.long_name),f.includes("postal_town")&&(m=d.long_name),f.includes("administrative_area_level_2")&&(t.administrativeAreaLevel2=d.short_name,t.administrativeAreaLevel2Long=d.long_name),f.includes("administrative_area_level_1")&&(t.administrativeAreaLevel1=d.short_name,t.administrativeAreaLevel1Long=d.long_name),f.includes("country")&&(t.country=d.short_name),f.includes("postal_code")&&(t.postalCode=d.long_name)}t.locality||(t.locality=m||u||c||""),!t.administrativeAreaLevel1&&t.administrativeAreaLevel2&&(t.administrativeAreaLevel1=t.administrativeAreaLevel2Long||t.administrativeAreaLevel2,t.administrativeAreaLevel1Long=t.administrativeAreaLevel2Long);let g=t.streetNumber||r,w=t.route||i||o||a||s;if(t.subpremise&&g&&w)t.fullStreetAddress=`${t.subpremise}/${g} ${w}`;else if(g&&w)if(r&&o&&a){let d=`${a}-${o}-${r}`;u&&(d=`${d} ${u}`),t.fullStreetAddress=d}else t.fullStreetAddress=`${g} ${w}`;else w?t.fullStreetAddress=w:g&&(t.fullStreetAddress=g);return t.fullStreetAddress=t.fullStreetAddress.trim(),t}static extractFormattedAddress(e){let t=n.extractAddressComponents(e);return{address1:t.fullStreetAddress,city:t.locality,country:t.country,state:t.administrativeAreaLevel1,postal:t.postalCode}}};function Ne(n){let{apiKey:e,language:t,region:r,version:s,defer:i=!1}=n,[o,a]=(0,R.useState)([]),[u,c]=(0,R.useState)(!1),[m,g]=(0,R.useState)(!1),w=(0,R.useRef)(null),d=(0,R.useRef)(null),f=(0,R.useCallback)(()=>{z(e,{language:t,region:r,version:s}).then(()=>g(!0))},[e,t,r,s]);(0,R.useEffect)(()=>{!e||i||f()},[e,i,f]),(0,R.useEffect)(()=>{if(m&&d.current){let{input:A,country:$}=d.current;d.current=null,P(A,$)}},[m]);let P=(0,R.useCallback)((A,$)=>{if(!m){i&&(d.current={input:A,country:$},f());return}if(A.length<3){a([]);return}w.current&&clearTimeout(w.current),w.current=setTimeout(async()=>{c(!0);let le=await N.searchPlaces(A,{componentRestrictions:$?{country:$.toLowerCase()}:void 0});a(le),c(!1)},300)},[m,i,f]),S=(0,R.useCallback)(A=>N.getPlaceDetails(A),[]),y=(0,R.useCallback)(A=>N.extractAddressComponents(A),[]),l=(0,R.useCallback)(A=>N.extractFormattedAddress(A),[]),p=(0,R.useCallback)(()=>a([]),[]);return{predictions:o,isLoading:u,isScriptLoaded:m,searchPlaces:P,getPlaceDetails:S,extractAddressComponents:y,extractFormattedAddress:l,clearPredictions:p}}var M=L("react");var _e="https://cvwnizdbugpz6jwk.public.blob.vercel-storage.com/geodata/v1",Pe=["en","ru","de","da","fr","es","zh","hi","pt","ja","ar","it","he"],J=new Map,ce=new Map,ye=new Map,he=new Map;async function Qe(n){let e=J.get(n);if(e)return e;let t=ye.get(n);return t||(t=(async()=>{let r=`${_e}/${n}/countries.json`,s=await fetch(r);if(!s.ok)throw new Error(`Geodata fetch failed: ${r} (${s.status})`);let i=await s.json();return J.set(n,i),ye.delete(n),i})(),ye.set(n,t),t)}async function Xe(n){let e=ce.get(n);if(e)return e;let t=he.get(n);return t||(t=(async()=>{let r=`${_e}/${n}/regions.json`,s=await fetch(r);if(!s.ok)throw new Error(`Geodata fetch failed: ${r} (${s.status})`);let i=await s.json();return ce.set(n,i),he.delete(n),i})(),he.set(n,t),t)}function et(n){return J.get(n)||J.get("en")||{}}function tt(n){return ce.get(n)||ce.get("en")||{}}async function V(n="en"){await Promise.all([Qe(n),Xe(n)])}var ue=(n="en")=>{let e=et(n);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))},we=(n,e="en")=>{let r=tt(e)[n];return r?r.map(([s,i])=>({code:s,name:i,countryCode:n})).sort((s,i)=>s.name.localeCompare(i.name)):[]};function Y(n){return J.has(n)}var _=class n{static ensureLoaded(e="en"){return V(e)}static getCountries(e="en"){let t=ue(e),r={};for(let s of t)r[s.code]={iso:s.code,iso3:s.iso3??"",numeric:s.numeric??0,name:s.name};return r}static getCountryOptions(e="en"){return ue(e).map(t=>({value:t.code,label:t.name}))}static getRegions(e,t="en"){return we(e,t).map(r=>({iso:r.code,name:r.name}))}static getRegionOptions(e,t="en"){return n.getRegions(e,t).map(r=>({value:r.iso,label:r.name}))}static findRegion(e,t,r="en"){return n.getRegions(e,r).find(s=>s.iso===t)??null}static mapGoogleToISO(e,t,r,s="en"){let i=n.getRegions(r,s);if(i.length===0)return null;let o=i.find(a=>a.iso===e);return o||(o=i.find(a=>a.name.toLowerCase()===e.toLowerCase()),o)||(o=i.find(a=>a.name.toLowerCase()===t.toLowerCase()),o)?o:(o=i.find(a=>a.name.toLowerCase().includes(t.toLowerCase())||t.toLowerCase().includes(a.name.toLowerCase())),o??null)}static isLanguageLoaded(e){return Y(e)}static getAvailableLanguages(){return Pe}};function de(n="en"){let[e,t]=(0,M.useState)(Y(n));return(0,M.useEffect)(()=>{let r=!1;return V(n).then(()=>{r||t(!0)}).catch(s=>console.error("[headless-sdk] Failed to load geodata:",s)),()=>{r=!0}},[n]),(0,M.useMemo)(()=>e?{countries:_.getCountries(n),getRegions:r=>_.getRegions(r,n),findRegion:(r,s)=>_.findRegion(r,s,n),mapGoogleToISO:(r,s,i)=>_.mapGoogleToISO(r,s,i,n),isLoaded:!0}:{countries:{},getRegions:()=>[],findRegion:()=>null,mapGoogleToISO:()=>null,isLoaded:!1},[n,e])}function $e(n="en"){let{countries:e,isLoaded:t}=de(n);return(0,M.useMemo)(()=>t?Object.values(e).map(r=>({value:r.iso,label:r.name})).sort((r,s)=>r.label.localeCompare(s.label)):[],[e,t])}function Ge(n,e="en"){let{getRegions:t,isLoaded:r}=de(e);return(0,M.useMemo)(()=>!r||!n?[]:t(n).map(s=>({value:s.iso,label:s.name})).sort((s,i)=>s.label.localeCompare(i.label)),[n,t,r])}var rt={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"},st={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"},nt=new Set(["JPY","KRW","VND","IDR","LAK","KHR","MMK","PYG"]),F=class n{static getSymbol(e){return rt[e]??e}static getName(e){return st[e]??e}static getDecimalPlaces(e){return nt.has(e)?0:2}static getCurrency(e){return{code:e,symbol:n.getSymbol(e),name:n.getName(e),decimalPlaces:n.getDecimalPlaces(e)}}};function Se(n,e="USD",t="en-US"){let r=F.getDecimalPlaces(e),s=n/(r===0?100:Math.pow(10,r));try{return new Intl.NumberFormat(t,{style:"currency",currency:e,minimumFractionDigits:r,maximumFractionDigits:r}).format(s)}catch{return`${F.getSymbol(e)}${s.toFixed(r)}`}}return We(ot);})();
|
|
7
7
|
if(typeof window!=="undefined"&&TagadaHeadlessReactBundle){ window.TagadaHeadlessReact=TagadaHeadlessReactBundle;}
|
|
8
8
|
//# sourceMappingURL=tagada-headless-react.min.js.map
|