@tagadapay/headless-sdk 1.16.0 → 1.18.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 +22 -0
- package/dist/core/client.d.ts +5 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +6 -1
- package/dist/core/client.js.map +1 -1
- package/dist/core/http.d.ts +2 -0
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +21 -5
- package/dist/core/http.js.map +1 -1
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/modules/checkout.d.ts.map +1 -1
- package/dist/core/modules/checkout.js +12 -0
- package/dist/core/modules/checkout.js.map +1 -1
- package/dist/core/modules/commerce.d.ts +4 -0
- package/dist/core/modules/commerce.d.ts.map +1 -0
- package/dist/core/modules/commerce.js +5 -0
- package/dist/core/modules/commerce.js.map +1 -0
- package/dist/core/modules/customer.d.ts +73 -5
- package/dist/core/modules/customer.d.ts.map +1 -1
- package/dist/core/modules/customer.js +110 -19
- package/dist/core/modules/customer.js.map +1 -1
- package/dist/core/modules/experiments.d.ts +21 -0
- package/dist/core/modules/experiments.d.ts.map +1 -0
- package/dist/core/modules/experiments.js +85 -0
- package/dist/core/modules/experiments.js.map +1 -0
- package/dist/core/modules/funnel.d.ts +2 -1
- package/dist/core/modules/funnel.d.ts.map +1 -1
- package/dist/core/modules/funnel.js +6 -1
- package/dist/core/modules/funnel.js.map +1 -1
- package/dist/core/modules/lazyCommerce.d.ts +16 -0
- package/dist/core/modules/lazyCommerce.d.ts.map +1 -0
- package/dist/core/modules/lazyCommerce.js +20 -0
- package/dist/core/modules/lazyCommerce.js.map +1 -0
- package/dist/core/modules/offers.d.ts +30 -5
- package/dist/core/modules/offers.d.ts.map +1 -1
- package/dist/core/modules/offers.js +66 -7
- package/dist/core/modules/offers.js.map +1 -1
- package/dist/core/modules/portal/index.d.ts +102 -0
- package/dist/core/modules/portal/index.d.ts.map +1 -0
- package/dist/core/modules/portal/index.js +166 -0
- package/dist/core/modules/portal/index.js.map +1 -0
- package/dist/core/modules/portal/types.d.ts +617 -0
- package/dist/core/modules/portal/types.d.ts.map +1 -0
- package/dist/core/modules/portal/types.js +11 -0
- package/dist/core/modules/portal/types.js.map +1 -0
- package/dist/core/modules/track.d.ts +8 -0
- package/dist/core/modules/track.d.ts.map +1 -1
- package/dist/core/modules/track.js +49 -8
- package/dist/core/modules/track.js.map +1 -1
- package/dist/core/types.d.ts +11 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +0 -3
- package/dist/core/types.js.map +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/pixels/pixelTracker.d.ts.map +1 -1
- package/dist/pixels/pixelTracker.js +4 -2
- package/dist/pixels/pixelTracker.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/provider.d.ts +13 -2
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +35 -7
- package/dist/react/provider.js.map +1 -1
- package/dist/tagada-headless-commerce.min.js +8 -0
- package/dist/tagada-headless-commerce.min.js.map +7 -0
- package/dist/tagada-headless-react.min.js +2 -2
- package/dist/tagada-headless-react.min.js.map +4 -4
- package/dist/tagada-headless.js +299 -288
- package/dist/tagada-headless.min.js +2 -2
- package/dist/tagada-headless.min.js.map +4 -4
- package/dist/tagada-pixels.min.js +2 -2
- package/dist/tagada-pixels.min.js.map +3 -3
- package/dist/tgd/contract/attribution.d.ts +28 -0
- package/dist/tgd/contract/attribution.d.ts.map +1 -0
- package/dist/tgd/contract/attribution.js +44 -0
- package/dist/tgd/contract/attribution.js.map +1 -0
- package/dist/tgd/contract/browser-api.d.ts +57 -0
- package/dist/tgd/contract/browser-api.d.ts.map +1 -0
- package/dist/tgd/contract/browser-api.js +2 -0
- package/dist/tgd/contract/browser-api.js.map +1 -0
- package/dist/tgd/contract/canvas.d.ts +120 -0
- package/dist/tgd/contract/canvas.d.ts.map +1 -0
- package/dist/tgd/contract/canvas.js +12 -0
- package/dist/tgd/contract/canvas.js.map +1 -0
- package/dist/tgd/contract/dedup-keys.d.ts +24 -0
- package/dist/tgd/contract/dedup-keys.d.ts.map +1 -0
- package/dist/tgd/contract/dedup-keys.js +23 -0
- package/dist/tgd/contract/dedup-keys.js.map +1 -0
- package/dist/tgd/contract/destination-names.d.ts +4 -0
- package/dist/tgd/contract/destination-names.d.ts.map +1 -0
- package/dist/tgd/contract/destination-names.js +66 -0
- package/dist/tgd/contract/destination-names.js.map +1 -0
- package/dist/tgd/contract/destinations.d.ts +124 -0
- package/dist/tgd/contract/destinations.d.ts.map +1 -0
- package/dist/tgd/contract/destinations.js +63 -0
- package/dist/tgd/contract/destinations.js.map +1 -0
- package/dist/tgd/contract/envelope.d.ts +203 -0
- package/dist/tgd/contract/envelope.d.ts.map +1 -0
- package/dist/tgd/contract/envelope.js +103 -0
- package/dist/tgd/contract/envelope.js.map +1 -0
- package/dist/tgd/contract/experiments.d.ts +87 -0
- package/dist/tgd/contract/experiments.d.ts.map +1 -0
- package/dist/tgd/contract/experiments.js +2 -0
- package/dist/tgd/contract/experiments.js.map +1 -0
- package/dist/tgd/contract/index.d.ts +20 -0
- package/dist/tgd/contract/index.d.ts.map +1 -0
- package/dist/tgd/contract/index.js +20 -0
- package/dist/tgd/contract/index.js.map +1 -0
- package/dist/tgd/contract/is-test.d.ts +2 -0
- package/dist/tgd/contract/is-test.d.ts.map +1 -0
- package/dist/tgd/contract/is-test.js +3 -0
- package/dist/tgd/contract/is-test.js.map +1 -0
- package/dist/tgd/contract/junk-ids.d.ts +4 -0
- package/dist/tgd/contract/junk-ids.d.ts.map +1 -0
- package/dist/tgd/contract/junk-ids.js +7 -0
- package/dist/tgd/contract/junk-ids.js.map +1 -0
- package/dist/tgd/contract/limits.d.ts +19 -0
- package/dist/tgd/contract/limits.d.ts.map +1 -0
- package/dist/tgd/contract/limits.js +20 -0
- package/dist/tgd/contract/limits.js.map +1 -0
- package/dist/tgd/contract/names.d.ts +13 -0
- package/dist/tgd/contract/names.d.ts.map +1 -0
- package/dist/tgd/contract/names.js +15 -0
- package/dist/tgd/contract/names.js.map +1 -0
- package/dist/tgd/contract/registry.d.ts +116 -0
- package/dist/tgd/contract/registry.d.ts.map +1 -0
- package/dist/tgd/contract/registry.js +59 -0
- package/dist/tgd/contract/registry.js.map +1 -0
- package/dist/tgd/contract/signed-ids.d.ts +33 -0
- package/dist/tgd/contract/signed-ids.d.ts.map +1 -0
- package/dist/tgd/contract/signed-ids.js +26 -0
- package/dist/tgd/contract/signed-ids.js.map +1 -0
- package/dist/tgd/contract/snapshots.d.ts +69 -0
- package/dist/tgd/contract/snapshots.d.ts.map +1 -0
- package/dist/tgd/contract/snapshots.js +2 -0
- package/dist/tgd/contract/snapshots.js.map +1 -0
- package/dist/tgd/contract/time.d.ts +9 -0
- package/dist/tgd/contract/time.d.ts.map +1 -0
- package/dist/tgd/contract/time.js +9 -0
- package/dist/tgd/contract/time.js.map +1 -0
- package/dist/tgd/contract/unions.d.ts +21 -0
- package/dist/tgd/contract/unions.d.ts.map +1 -0
- package/dist/tgd/contract/unions.js +17 -0
- package/dist/tgd/contract/unions.js.map +1 -0
- package/dist/tgd/contract/unit.d.ts +12 -0
- package/dist/tgd/contract/unit.d.ts.map +1 -0
- package/dist/tgd/contract/unit.js +18 -0
- package/dist/tgd/contract/unit.js.map +1 -0
- package/dist/tgd/contract/wire.d.ts +59 -0
- package/dist/tgd/contract/wire.d.ts.map +1 -0
- package/dist/tgd/contract/wire.js +2 -0
- package/dist/tgd/contract/wire.js.map +1 -0
- package/package.json +6 -3
package/dist/tagada-headless.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @tagadapay/headless-sdk v1.
|
|
2
|
+
* @tagadapay/headless-sdk v1.18.0
|
|
3
3
|
* Headless checkout, payments, offers, and CRM
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -48,6 +48,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
48
48
|
CheckoutModule: () => CheckoutModule,
|
|
49
49
|
CurrencyUtils: () => CurrencyUtils,
|
|
50
50
|
CustomerModule: () => CustomerModule,
|
|
51
|
+
CustomerPortalModule: () => CustomerPortalModule,
|
|
52
|
+
ExperimentsModule: () => ExperimentsModule,
|
|
51
53
|
FunnelModule: () => FunnelModule,
|
|
52
54
|
GoogleAutocompleteCore: () => GoogleAutocompleteCore,
|
|
53
55
|
HeadlessClient: () => HeadlessClient,
|
|
@@ -138,6 +140,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
138
140
|
this.timeout = config.timeout;
|
|
139
141
|
this.apiKey = config.apiKey;
|
|
140
142
|
this.getToken = config.getToken;
|
|
143
|
+
this.redirect = config.redirect;
|
|
141
144
|
}
|
|
142
145
|
static resolveBaseUrl(environment, override) {
|
|
143
146
|
return override ?? BASE_URLS[environment] ?? BASE_URLS.production;
|
|
@@ -145,7 +148,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
145
148
|
async request(path, options = {}) {
|
|
146
149
|
var _a;
|
|
147
150
|
const { method = "GET", body, headers = {}, params, token, signal } = options;
|
|
148
|
-
let
|
|
151
|
+
let url2 = `${this.baseUrl}${path}`;
|
|
149
152
|
if (params) {
|
|
150
153
|
const qs = new URLSearchParams();
|
|
151
154
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -154,7 +157,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
154
157
|
}
|
|
155
158
|
const str = qs.toString();
|
|
156
159
|
if (str)
|
|
157
|
-
|
|
160
|
+
url2 += `?${str}`;
|
|
158
161
|
}
|
|
159
162
|
const reqHeaders = {
|
|
160
163
|
"Content-Type": "application/json",
|
|
@@ -167,11 +170,12 @@ var TagadaHeadlessBundle = (() => {
|
|
|
167
170
|
const controller = new AbortController();
|
|
168
171
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
169
172
|
try {
|
|
170
|
-
const res = await fetch(
|
|
173
|
+
const res = await fetch(url2, {
|
|
171
174
|
method,
|
|
172
175
|
headers: reqHeaders,
|
|
173
176
|
body: body != null ? JSON.stringify(body) : void 0,
|
|
174
|
-
signal: signal ?? controller.signal
|
|
177
|
+
signal: signal ?? controller.signal,
|
|
178
|
+
...this.redirect && { redirect: this.redirect }
|
|
175
179
|
});
|
|
176
180
|
clearTimeout(timeoutId);
|
|
177
181
|
if (res.ok) {
|
|
@@ -213,8 +217,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
213
217
|
parsed = await res.json();
|
|
214
218
|
} catch {
|
|
215
219
|
}
|
|
216
|
-
const data = parsed.data
|
|
217
|
-
const msg = parsed.message
|
|
220
|
+
const data = parseErrorData(parsed.data);
|
|
221
|
+
const msg = parsed.message || parsed.error || (typeof data.message === "string" ? data.message : void 0) || (typeof parsed.data === "string" && Object.keys(data).length === 0 ? parsed.data : void 0) || `Request failed: ${res.status} ${res.statusText} on ${path}`;
|
|
218
222
|
const appCode = typeof data.code === "string" ? data.code : void 0;
|
|
219
223
|
switch (res.status) {
|
|
220
224
|
case 401:
|
|
@@ -235,6 +239,18 @@ var TagadaHeadlessBundle = (() => {
|
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
241
|
};
|
|
242
|
+
function parseErrorData(value) {
|
|
243
|
+
if (value && typeof value === "object")
|
|
244
|
+
return value;
|
|
245
|
+
if (typeof value !== "string")
|
|
246
|
+
return {};
|
|
247
|
+
try {
|
|
248
|
+
const parsed = JSON.parse(value);
|
|
249
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
250
|
+
} catch {
|
|
251
|
+
return {};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
238
254
|
|
|
239
255
|
// src/core/modules/checkout.ts
|
|
240
256
|
var CheckoutModule = class _CheckoutModule {
|
|
@@ -301,6 +317,9 @@ var TagadaHeadlessBundle = (() => {
|
|
|
301
317
|
const lineItems = opts.items.map((i) => ({
|
|
302
318
|
variantId: i.variantId,
|
|
303
319
|
priceId: i.priceId,
|
|
320
|
+
...i.sellingPlanId !== void 0 ? { sellingPlanId: i.sellingPlanId } : {},
|
|
321
|
+
...i.trialDays !== void 0 ? { trialDays: i.trialDays } : {},
|
|
322
|
+
...i.trialPrice !== void 0 ? { trialPrice: i.trialPrice } : {},
|
|
304
323
|
quantity: i.quantity
|
|
305
324
|
}));
|
|
306
325
|
const body = {
|
|
@@ -309,6 +328,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
309
328
|
};
|
|
310
329
|
if (opts.returnUrl)
|
|
311
330
|
body.returnUrl = opts.returnUrl;
|
|
331
|
+
if (opts.funnelSessionId)
|
|
332
|
+
body.funnelSessionId = opts.funnelSessionId;
|
|
312
333
|
if ((_a = opts.discountCodes) == null ? void 0 : _a.length)
|
|
313
334
|
body.discountCodes = opts.discountCodes;
|
|
314
335
|
if (opts.metadata && Object.keys(opts.metadata).length > 0)
|
|
@@ -330,8 +351,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
330
351
|
body.customer = customerData;
|
|
331
352
|
}
|
|
332
353
|
const res = await this.http.post("/api/v1/checkout/session/init", body);
|
|
333
|
-
const
|
|
334
|
-
const sessionToken =
|
|
354
|
+
const url2 = new URL(res.checkoutUrl);
|
|
355
|
+
const sessionToken = url2.searchParams.get("token") ?? "";
|
|
335
356
|
this.sessionToken = sessionToken;
|
|
336
357
|
if (sessionToken)
|
|
337
358
|
(_c = this.onTokenChange) == null ? void 0 : _c.call(this, sessionToken);
|
|
@@ -372,8 +393,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
372
393
|
checkoutToken: session.checkoutToken,
|
|
373
394
|
sessionToken: session.sessionToken
|
|
374
395
|
});
|
|
375
|
-
const
|
|
376
|
-
return { ...session, url };
|
|
396
|
+
const url2 = `${origin}${checkoutPath}?${params.toString()}`;
|
|
397
|
+
return { ...session, url: url2 };
|
|
377
398
|
}
|
|
378
399
|
/**
|
|
379
400
|
* Read `checkoutToken` and session token from a URL.
|
|
@@ -398,10 +419,10 @@ var TagadaHeadlessBundle = (() => {
|
|
|
398
419
|
* );
|
|
399
420
|
* ```
|
|
400
421
|
*/
|
|
401
|
-
static parseTokensFromUrl(
|
|
402
|
-
if (typeof
|
|
422
|
+
static parseTokensFromUrl(url2) {
|
|
423
|
+
if (typeof url2 === "undefined" && typeof window === "undefined")
|
|
403
424
|
return null;
|
|
404
|
-
const href =
|
|
425
|
+
const href = url2 ?? window.location.href;
|
|
405
426
|
let parsed;
|
|
406
427
|
try {
|
|
407
428
|
parsed = new URL(href);
|
|
@@ -415,8 +436,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
415
436
|
return { checkoutToken, sessionToken };
|
|
416
437
|
}
|
|
417
438
|
/** Instance alias of {@link CheckoutModule.parseTokensFromUrl}. */
|
|
418
|
-
parseTokensFromUrl(
|
|
419
|
-
return _CheckoutModule.parseTokensFromUrl(
|
|
439
|
+
parseTokensFromUrl(url2) {
|
|
440
|
+
return _CheckoutModule.parseTokensFromUrl(url2);
|
|
420
441
|
}
|
|
421
442
|
/**
|
|
422
443
|
* Add or update cart items on an existing session (upsert by product).
|
|
@@ -440,6 +461,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
440
461
|
const lineItems = items.map((i) => ({
|
|
441
462
|
variantId: i.variantId,
|
|
442
463
|
priceId: i.priceId,
|
|
464
|
+
...i.sellingPlanId !== void 0 ? { sellingPlanId: i.sellingPlanId } : {},
|
|
443
465
|
quantity: i.quantity
|
|
444
466
|
}));
|
|
445
467
|
return this.http.post(
|
|
@@ -646,7 +668,13 @@ var TagadaHeadlessBundle = (() => {
|
|
|
646
668
|
unitAmount: amount,
|
|
647
669
|
totalAmount: amount * (li.quantity ?? 1),
|
|
648
670
|
currency: sessionCurrency ?? "USD",
|
|
649
|
-
imageUrl: variant.imageUrl ?? product.imageUrl ?? ""
|
|
671
|
+
imageUrl: variant.imageUrl ?? product.imageUrl ?? "",
|
|
672
|
+
...(price == null ? void 0 : price.recurring) ? {
|
|
673
|
+
recurring: {
|
|
674
|
+
interval: price.interval ?? "month",
|
|
675
|
+
intervalCount: price.intervalCount ?? 1
|
|
676
|
+
}
|
|
677
|
+
} : {}
|
|
650
678
|
};
|
|
651
679
|
});
|
|
652
680
|
const summaryItems = summary.items ?? [];
|
|
@@ -759,10 +787,22 @@ var TagadaHeadlessBundle = (() => {
|
|
|
759
787
|
|
|
760
788
|
// src/core/version.ts
|
|
761
789
|
var SDK_NAME = "headless";
|
|
762
|
-
var SDK_VERSION = "1.
|
|
790
|
+
var SDK_VERSION = "1.18.0";
|
|
763
791
|
|
|
764
792
|
// src/core/modules/track.ts
|
|
765
|
-
var CDN_URL = false ? "" : "https://cdn.jsdelivr.net/npm/@tagadapay/headless-sdk@1.
|
|
793
|
+
var CDN_URL = false ? "" : "https://cdn.jsdelivr.net/npm/@tagadapay/headless-sdk@1.18.0/dist/tagada-pixels.min.js";
|
|
794
|
+
function loadScript(src, isReady) {
|
|
795
|
+
if (isReady())
|
|
796
|
+
return Promise.resolve();
|
|
797
|
+
return new Promise((resolve, reject) => {
|
|
798
|
+
const script2 = document.createElement("script");
|
|
799
|
+
script2.src = src;
|
|
800
|
+
script2.async = true;
|
|
801
|
+
script2.onload = () => resolve();
|
|
802
|
+
script2.onerror = () => reject(new Error("runtime script failed to load"));
|
|
803
|
+
document.head.appendChild(script2);
|
|
804
|
+
});
|
|
805
|
+
}
|
|
766
806
|
async function loadPixels() {
|
|
767
807
|
if (typeof window === "undefined")
|
|
768
808
|
return null;
|
|
@@ -770,14 +810,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
770
810
|
const w = window;
|
|
771
811
|
if (w.TagadaPixels)
|
|
772
812
|
return w.TagadaPixels;
|
|
773
|
-
await
|
|
774
|
-
const s = document.createElement("script");
|
|
775
|
-
s.src = CDN_URL;
|
|
776
|
-
s.async = true;
|
|
777
|
-
s.onload = () => resolve();
|
|
778
|
-
s.onerror = () => reject(new Error("pixel bundle failed to load"));
|
|
779
|
-
document.head.appendChild(s);
|
|
780
|
-
});
|
|
813
|
+
await loadScript(CDN_URL, () => Boolean(w.TagadaPixels));
|
|
781
814
|
return w.TagadaPixels ?? null;
|
|
782
815
|
}
|
|
783
816
|
return await import("../../pixels/index.js");
|
|
@@ -836,6 +869,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
836
869
|
this.manifestHash = null;
|
|
837
870
|
this.loadedProviders = [];
|
|
838
871
|
this.configPromise = null;
|
|
872
|
+
this.corePromise = null;
|
|
839
873
|
this.enginePromise = null;
|
|
840
874
|
this.flushTimer = null;
|
|
841
875
|
this.listening = false;
|
|
@@ -885,6 +919,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
885
919
|
this.listen();
|
|
886
920
|
this.push({ kind: "step", stepId, at, path });
|
|
887
921
|
void this.pixels().then((engine) => engine == null ? void 0 : engine.pageView(path, { stepId }));
|
|
922
|
+
void this.core().then((t) => t == null ? void 0 : t.page({ step_id: stepId })).catch(() => void 0);
|
|
888
923
|
}
|
|
889
924
|
event(name, data) {
|
|
890
925
|
if (this.off())
|
|
@@ -898,6 +933,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
898
933
|
void this.pixels().then(
|
|
899
934
|
(engine) => standard ? engine == null ? void 0 : engine.track(standard, data, { stepId, eventId }) : engine == null ? void 0 : engine.trackCustom(name, data, { stepId })
|
|
900
935
|
);
|
|
936
|
+
void this.core().then((t) => t == null ? void 0 : t.track(name, { ...scalars(data) ?? {}, step_id: stepId, pixel_event_id: eventId })).catch(() => void 0);
|
|
901
937
|
}
|
|
902
938
|
/** Keep the dedup map to entries still inside the window, and never past `STEP_MEMORY`. */
|
|
903
939
|
remember(key, at) {
|
|
@@ -919,6 +955,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
919
955
|
void this.pixels().then(
|
|
920
956
|
(engine) => engine == null ? void 0 : engine.identify({ email: who.email, phone: who.phone, externalId: who.customerId })
|
|
921
957
|
);
|
|
958
|
+
void this.core().then((t) => t == null ? void 0 : t.identify(who.customerId ?? null, { email: who.email, phone: who.phone, customerId: who.customerId })).catch(() => void 0);
|
|
922
959
|
}
|
|
923
960
|
consent(state) {
|
|
924
961
|
if (this.off())
|
|
@@ -983,10 +1020,10 @@ var TagadaHeadlessBundle = (() => {
|
|
|
983
1020
|
config() {
|
|
984
1021
|
if (this.configPromise !== null)
|
|
985
1022
|
return this.configPromise;
|
|
986
|
-
const
|
|
1023
|
+
const url2 = `${this.baseUrl}/api/public/v1/sdk/config?storeId=${encodeURIComponent(this.storeId)}&funnel=${encodeURIComponent(this.flagFunnelKey())}`;
|
|
987
1024
|
this.configPromise = (async () => {
|
|
988
1025
|
try {
|
|
989
|
-
const response = await fetch(
|
|
1026
|
+
const response = await fetch(url2);
|
|
990
1027
|
if (!response.ok)
|
|
991
1028
|
return null;
|
|
992
1029
|
const config = await response.json();
|
|
@@ -998,6 +1035,46 @@ var TagadaHeadlessBundle = (() => {
|
|
|
998
1035
|
})();
|
|
999
1036
|
return this.configPromise;
|
|
1000
1037
|
}
|
|
1038
|
+
/** @internal R4 is reused; loading is allowed only when it opts this store in. */
|
|
1039
|
+
core() {
|
|
1040
|
+
if (typeof window === "undefined")
|
|
1041
|
+
return Promise.resolve(null);
|
|
1042
|
+
this.corePromise ?? (this.corePromise = (async () => {
|
|
1043
|
+
var _a, _b;
|
|
1044
|
+
try {
|
|
1045
|
+
const config = await this.config();
|
|
1046
|
+
if (!config || !config.collect && !config.experiments)
|
|
1047
|
+
return null;
|
|
1048
|
+
const base = this.baseUrl.replace(/\/+$/, "");
|
|
1049
|
+
const w = window;
|
|
1050
|
+
if (typeof ((_a = w.tgd) == null ? void 0 : _a.init) !== "function") {
|
|
1051
|
+
await loadScript(base + "/assets/js/tgd.js", () => {
|
|
1052
|
+
var _a2;
|
|
1053
|
+
return typeof ((_a2 = w.tgd) == null ? void 0 : _a2.init) === "function";
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof ((_b = w.tgd) == null ? void 0 : _b.init) !== "function")
|
|
1057
|
+
return null;
|
|
1058
|
+
w.tgd.init({
|
|
1059
|
+
storeId: this.storeId,
|
|
1060
|
+
apiHost: config.collect ? new URL(config.collect.url).origin : base,
|
|
1061
|
+
bootstrap: this.bootstrap,
|
|
1062
|
+
_source: "headless",
|
|
1063
|
+
_manualPages: true
|
|
1064
|
+
});
|
|
1065
|
+
return w.tgd;
|
|
1066
|
+
} catch {
|
|
1067
|
+
return null;
|
|
1068
|
+
}
|
|
1069
|
+
})());
|
|
1070
|
+
return this.corePromise;
|
|
1071
|
+
}
|
|
1072
|
+
/** @internal Funnel navigation alone must not opt a site into tracking. */
|
|
1073
|
+
noteFunnelSession(funnelSessionId) {
|
|
1074
|
+
if (this.off())
|
|
1075
|
+
return;
|
|
1076
|
+
void this.core().then((t) => t == null ? void 0 : t._link(funnelSessionId)).catch(() => void 0);
|
|
1077
|
+
}
|
|
1001
1078
|
pixels() {
|
|
1002
1079
|
if (!this.enabled())
|
|
1003
1080
|
return Promise.resolve(null);
|
|
@@ -1089,16 +1166,16 @@ var TagadaHeadlessBundle = (() => {
|
|
|
1089
1166
|
if (this.manifestHash !== null)
|
|
1090
1167
|
payload.manifestHash = this.manifestHash;
|
|
1091
1168
|
const body = JSON.stringify(payload);
|
|
1092
|
-
const
|
|
1169
|
+
const url2 = `${this.baseUrl}/api/public/v1/sdk/events`;
|
|
1093
1170
|
try {
|
|
1094
1171
|
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
1095
|
-
if (navigator.sendBeacon(
|
|
1172
|
+
if (navigator.sendBeacon(url2, new Blob([body], { type: "text/plain;charset=UTF-8" })))
|
|
1096
1173
|
return;
|
|
1097
1174
|
}
|
|
1098
1175
|
} catch {
|
|
1099
1176
|
}
|
|
1100
1177
|
try {
|
|
1101
|
-
void fetch(
|
|
1178
|
+
void fetch(url2, {
|
|
1102
1179
|
method: "POST",
|
|
1103
1180
|
body,
|
|
1104
1181
|
keepalive: true,
|
|
@@ -1712,15 +1789,15 @@ var TagadaHeadlessBundle = (() => {
|
|
|
1712
1789
|
if (typeof window === "undefined" && !(opts == null ? void 0 : opts.url))
|
|
1713
1790
|
return null;
|
|
1714
1791
|
const href = (opts == null ? void 0 : opts.url) ?? window.location.href;
|
|
1715
|
-
let
|
|
1792
|
+
let url2;
|
|
1716
1793
|
try {
|
|
1717
|
-
|
|
1794
|
+
url2 = new URL(href);
|
|
1718
1795
|
} catch {
|
|
1719
1796
|
return null;
|
|
1720
1797
|
}
|
|
1721
|
-
const action =
|
|
1722
|
-
const actionStatus =
|
|
1723
|
-
const paymentId =
|
|
1798
|
+
const action = url2.searchParams.get("paymentAction");
|
|
1799
|
+
const actionStatus = url2.searchParams.get("paymentActionStatus");
|
|
1800
|
+
const paymentId = url2.searchParams.get("paymentId");
|
|
1724
1801
|
if (action !== "requireAction" || actionStatus !== "completed" || !paymentId) {
|
|
1725
1802
|
return null;
|
|
1726
1803
|
}
|
|
@@ -1825,8 +1902,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
1825
1902
|
extractRedirect(payment, actionData) {
|
|
1826
1903
|
var _a, _b;
|
|
1827
1904
|
const redirect = (_a = actionData.metadata) == null ? void 0 : _a.redirect;
|
|
1828
|
-
const
|
|
1829
|
-
if (!
|
|
1905
|
+
const url2 = (redirect == null ? void 0 : redirect.redirectUrl) || actionData.redirectUrl;
|
|
1906
|
+
if (!url2) {
|
|
1830
1907
|
return {
|
|
1831
1908
|
status: "failed",
|
|
1832
1909
|
error: `Payment requires action (${actionData.type}) but no redirect URL was provided`,
|
|
@@ -1835,7 +1912,7 @@ var TagadaHeadlessBundle = (() => {
|
|
|
1835
1912
|
}
|
|
1836
1913
|
return {
|
|
1837
1914
|
status: "requires_redirect",
|
|
1838
|
-
redirectUrl:
|
|
1915
|
+
redirectUrl: url2,
|
|
1839
1916
|
method: ((_b = redirect == null ? void 0 : redirect.method) == null ? void 0 : _b.toUpperCase()) || "GET",
|
|
1840
1917
|
postData: redirect == null ? void 0 : redirect.data,
|
|
1841
1918
|
paymentId: payment.id
|
|
@@ -1982,248 +2059,83 @@ var TagadaHeadlessBundle = (() => {
|
|
|
1982
2059
|
}
|
|
1983
2060
|
};
|
|
1984
2061
|
|
|
2062
|
+
// src/core/modules/lazyCommerce.ts
|
|
2063
|
+
var script = typeof document === "undefined" ? null : document.currentScript;
|
|
2064
|
+
var url = (script == null ? void 0 : script.src) ? new URL("tagada-headless-commerce.min.js", script.src).href : "https://cdn.jsdelivr.net/npm/@tagadapay/headless-sdk@1.18.0/dist/tagada-headless-commerce.min.js";
|
|
2065
|
+
var loading;
|
|
2066
|
+
function loadCommerce() {
|
|
2067
|
+
if (window.TagadaHeadlessCommerce)
|
|
2068
|
+
return Promise.resolve(window.TagadaHeadlessCommerce);
|
|
2069
|
+
if (!loading)
|
|
2070
|
+
loading = new Promise((resolve, reject) => {
|
|
2071
|
+
const element = document.createElement("script");
|
|
2072
|
+
element.src = url;
|
|
2073
|
+
element.async = true;
|
|
2074
|
+
if (script == null ? void 0 : script.nonce)
|
|
2075
|
+
element.nonce = script.nonce;
|
|
2076
|
+
element.addEventListener("load", () => window.TagadaHeadlessCommerce ? resolve(window.TagadaHeadlessCommerce) : reject(new Error("Commerce bundle did not initialize")));
|
|
2077
|
+
element.addEventListener("error", () => {
|
|
2078
|
+
element.remove();
|
|
2079
|
+
reject(new Error("Unable to load commerce bundle"));
|
|
2080
|
+
});
|
|
2081
|
+
document.head.appendChild(element);
|
|
2082
|
+
}).catch((error) => {
|
|
2083
|
+
loading = void 0;
|
|
2084
|
+
throw error;
|
|
2085
|
+
});
|
|
2086
|
+
return loading;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
1985
2089
|
// src/core/modules/offers.ts
|
|
1986
2090
|
var OffersModule = class {
|
|
1987
|
-
constructor(
|
|
1988
|
-
this.
|
|
1989
|
-
this.storeId = storeId;
|
|
1990
|
-
this.payment = payment;
|
|
1991
|
-
}
|
|
1992
|
-
// ---------------------------------------------------------------------------
|
|
1993
|
-
// Offer loading
|
|
1994
|
-
// ---------------------------------------------------------------------------
|
|
1995
|
-
/** Get a single offer by ID. */
|
|
1996
|
-
async getOffer(offerId) {
|
|
1997
|
-
return this.http.get(`/api/v1/offers/${offerId}`);
|
|
1998
|
-
}
|
|
1999
|
-
/** List offers for the current store. Optionally filter by type or a set of IDs. */
|
|
2000
|
-
async listOffers(opts) {
|
|
2001
|
-
var _a;
|
|
2002
|
-
let url = `/api/v1/stores/${this.storeId}/offers`;
|
|
2003
|
-
const queryParts = [];
|
|
2004
|
-
if (opts == null ? void 0 : opts.type)
|
|
2005
|
-
queryParts.push(`type=${encodeURIComponent(opts.type)}`);
|
|
2006
|
-
if ((_a = opts == null ? void 0 : opts.ids) == null ? void 0 : _a.length) {
|
|
2007
|
-
for (const id of opts.ids)
|
|
2008
|
-
queryParts.push(`ids=${encodeURIComponent(id)}`);
|
|
2009
|
-
}
|
|
2010
|
-
if (queryParts.length)
|
|
2011
|
-
url += `?${queryParts.join("&")}`;
|
|
2012
|
-
const res = await this.http.get(url);
|
|
2013
|
-
return res.offers ?? [];
|
|
2014
|
-
}
|
|
2015
|
-
// ---------------------------------------------------------------------------
|
|
2016
|
-
// Preview & pay (one-click upsell flow from plugin-sdk)
|
|
2017
|
-
// ---------------------------------------------------------------------------
|
|
2018
|
-
/** Preview offer pricing. Returns line items with amounts and totals. */
|
|
2019
|
-
async previewOffer(opts) {
|
|
2020
|
-
return this.http.post(`/api/v1/offers/${opts.offerId}/preview`, {
|
|
2021
|
-
offerId: opts.offerId,
|
|
2022
|
-
currency: opts.currency ?? "",
|
|
2023
|
-
lineItems: opts.lineItems
|
|
2024
|
-
});
|
|
2091
|
+
constructor(...args) {
|
|
2092
|
+
this.args = args;
|
|
2025
2093
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
* polling, and 3DS redirects are NOT handled. For most cases, use
|
|
2032
|
-
* {@link processOfferPayment} which orchestrates the full lifecycle.
|
|
2033
|
-
*/
|
|
2034
|
-
async payPreviewedOffer(opts) {
|
|
2035
|
-
return this.http.post(`/api/v1/offers/${opts.offerId}/pay-preview`, {
|
|
2036
|
-
offerId: opts.offerId,
|
|
2037
|
-
currency: opts.currency ?? "",
|
|
2038
|
-
lineItems: opts.lineItems,
|
|
2039
|
-
returnUrl: opts.returnUrl ?? (typeof window !== "undefined" ? window.location.href : ""),
|
|
2040
|
-
mainOrderId: opts.mainOrderId,
|
|
2041
|
-
paymentInstrumentId: opts.paymentInstrumentId
|
|
2042
|
-
});
|
|
2043
|
-
}
|
|
2044
|
-
/**
|
|
2045
|
-
* One-click upsell with full lifecycle handling.
|
|
2046
|
-
*
|
|
2047
|
-
* Like `payment.processPayment()` but for previewed offers: charges the
|
|
2048
|
-
* stored instrument from `mainOrderId`, runs any 3DS challenge or bank
|
|
2049
|
-
* redirect, polls until terminal, and returns a typed
|
|
2050
|
-
* `ProcessPaymentResult` (`succeeded` / `requires_redirect` /
|
|
2051
|
-
* `failed` / `pending`).
|
|
2052
|
-
*
|
|
2053
|
-
* Use this instead of the lower-level `payPreviewedOffer()` whenever you
|
|
2054
|
-
* don't need to inspect the raw `OfferPayResult` shape — which is most
|
|
2055
|
-
* of the time.
|
|
2056
|
-
*
|
|
2057
|
-
* @example
|
|
2058
|
-
* ```ts
|
|
2059
|
-
* const result = await tagada.offers.processOfferPayment({
|
|
2060
|
-
* offerId: 'offer_xxx',
|
|
2061
|
-
* mainOrderId: order.id,
|
|
2062
|
-
* returnUrl: window.location.href,
|
|
2063
|
-
* });
|
|
2064
|
-
*
|
|
2065
|
-
* switch (result.status) {
|
|
2066
|
-
* case 'succeeded':
|
|
2067
|
-
* window.location.href = '/upsell-2';
|
|
2068
|
-
* break;
|
|
2069
|
-
* case 'requires_redirect':
|
|
2070
|
-
* window.location.href = result.redirectUrl;
|
|
2071
|
-
* break;
|
|
2072
|
-
* case 'failed':
|
|
2073
|
-
* showError(result.error);
|
|
2074
|
-
* break;
|
|
2075
|
-
* }
|
|
2076
|
-
* ```
|
|
2077
|
-
*/
|
|
2078
|
-
async processOfferPayment(opts) {
|
|
2079
|
-
if (!this.payment) {
|
|
2080
|
-
throw new Error(
|
|
2081
|
-
"OffersModule: no PaymentModule injected. Use createHeadlessClient() instead of constructing OffersModule directly."
|
|
2082
|
-
);
|
|
2083
|
-
}
|
|
2084
|
-
const returnUrl = opts.returnUrl ?? (typeof window !== "undefined" ? window.location.href : void 0);
|
|
2085
|
-
const payResult = await this.payPreviewedOffer({ ...opts, returnUrl });
|
|
2086
|
-
return this.payment.finalize(
|
|
2087
|
-
{ payment: payResult.payment, order: payResult.order },
|
|
2088
|
-
{ returnUrl }
|
|
2089
|
-
);
|
|
2090
|
-
}
|
|
2091
|
-
// ---------------------------------------------------------------------------
|
|
2092
|
-
// Order bumps (checkout-session scoped)
|
|
2093
|
-
// ---------------------------------------------------------------------------
|
|
2094
|
-
/** Toggle an order bump on/off within a checkout session. */
|
|
2095
|
-
async toggleOrderBump(opts) {
|
|
2096
|
-
return this.http.post(
|
|
2097
|
-
`/api/v1/checkout-sessions/${opts.checkoutSessionId}/toggle-order-bump`,
|
|
2098
|
-
{
|
|
2099
|
-
orderBumpOfferId: opts.orderBumpOfferId,
|
|
2100
|
-
selected: opts.selected
|
|
2101
|
-
}
|
|
2102
|
-
);
|
|
2103
|
-
}
|
|
2104
|
-
// ---------------------------------------------------------------------------
|
|
2105
|
-
// Post-purchase offers (order-scoped)
|
|
2106
|
-
// ---------------------------------------------------------------------------
|
|
2107
|
-
/** List post-purchase offers for an order. */
|
|
2108
|
-
async listPostPurchaseOffers(orderId) {
|
|
2109
|
-
const res = await this.http.get(`/api/v1/post-purchase/${orderId}/offers`);
|
|
2110
|
-
return Array.isArray(res) ? res : [];
|
|
2111
|
-
}
|
|
2112
|
-
/** Accept a post-purchase offer. */
|
|
2113
|
-
async acceptPostPurchaseOffer(opts) {
|
|
2114
|
-
return this.http.post(
|
|
2115
|
-
`/api/v1/orders/${opts.orderId}/post-purchase-offers/${opts.offerId}/accept`,
|
|
2116
|
-
{ items: opts.items ?? [] }
|
|
2117
|
-
);
|
|
2118
|
-
}
|
|
2119
|
-
/** Decline a post-purchase offer. */
|
|
2120
|
-
async declinePostPurchaseOffer(opts) {
|
|
2121
|
-
return this.http.post(
|
|
2122
|
-
`/api/v1/orders/${opts.orderId}/post-purchase-offers/${opts.offerId}/decline`
|
|
2123
|
-
);
|
|
2094
|
+
load() {
|
|
2095
|
+
return this.instance || (this.instance = loadCommerce().then((m) => new m.OffersModule(...this.args)).catch((e) => {
|
|
2096
|
+
this.instance = void 0;
|
|
2097
|
+
throw e;
|
|
2098
|
+
}));
|
|
2124
2099
|
}
|
|
2125
2100
|
};
|
|
2101
|
+
for (const method of ["getOffer", "listOffers", "previewOffer", "enterFunnelStep", "payPreviewedOffer", "processOfferPayment", "toggleOrderBump", "listPostPurchaseOffers", "acceptPostPurchaseOffer", "declinePostPurchaseOffer"])
|
|
2102
|
+
OffersModule.prototype[method] = function(...args) {
|
|
2103
|
+
return this.load().then((instance) => instance[method](...args));
|
|
2104
|
+
};
|
|
2126
2105
|
|
|
2127
2106
|
// src/core/modules/customer.ts
|
|
2128
2107
|
var CustomerModule = class {
|
|
2129
|
-
constructor(
|
|
2130
|
-
this.
|
|
2131
|
-
this.storeId = storeId;
|
|
2132
|
-
}
|
|
2133
|
-
/** Get customer profile by ID. */
|
|
2134
|
-
async getProfile(customerId) {
|
|
2135
|
-
const res = await this.http.get(
|
|
2136
|
-
`/api/v1/customers/${customerId}`,
|
|
2137
|
-
{ params: { storeId: this.storeId } }
|
|
2138
|
-
);
|
|
2139
|
-
return res.customer;
|
|
2140
|
-
}
|
|
2141
|
-
/** Get customer profile by email. */
|
|
2142
|
-
async getByEmail(email) {
|
|
2143
|
-
try {
|
|
2144
|
-
const res = await this.http.get(
|
|
2145
|
-
"/api/v1/customers/by-email",
|
|
2146
|
-
{ params: { email, storeId: this.storeId } }
|
|
2147
|
-
);
|
|
2148
|
-
return res.customer;
|
|
2149
|
-
} catch {
|
|
2150
|
-
return null;
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
/** Update customer profile fields. */
|
|
2154
|
-
async updateProfile(customerId, data) {
|
|
2155
|
-
const res = await this.http.patch(
|
|
2156
|
-
`/api/v1/customers/${customerId}`,
|
|
2157
|
-
{ storeId: this.storeId, ...data }
|
|
2158
|
-
);
|
|
2159
|
-
return res.customer;
|
|
2160
|
-
}
|
|
2161
|
-
/** List orders for a customer. */
|
|
2162
|
-
async getOrders(customerId, opts) {
|
|
2163
|
-
return this.http.get(
|
|
2164
|
-
`/api/v1/customers/${customerId}/orders`,
|
|
2165
|
-
{ params: { storeId: this.storeId, limit: opts == null ? void 0 : opts.limit, offset: opts == null ? void 0 : opts.offset } }
|
|
2166
|
-
);
|
|
2167
|
-
}
|
|
2168
|
-
/**
|
|
2169
|
-
* Get a single order by ID.
|
|
2170
|
-
*
|
|
2171
|
-
* **Thank-you pages:** accepted one-click upsells create *child orders*
|
|
2172
|
-
* (`metadata.mainOrderId` = this order's id) that land asynchronously —
|
|
2173
|
-
* the first fetch right after an accept usually misses them. Pass
|
|
2174
|
-
* `waitForRelatedOrders: true` to poll until `order.relatedOrders` is
|
|
2175
|
-
* non-empty or the timeout elapses. On timeout the latest snapshot is
|
|
2176
|
-
* returned (never throws), so an order with no accepted upsell simply
|
|
2177
|
-
* comes back with an empty `relatedOrders` after `timeoutMs`.
|
|
2178
|
-
*
|
|
2179
|
-
* @example
|
|
2180
|
-
* ```ts
|
|
2181
|
-
* // Thank-you page: show the main order AND the upsells
|
|
2182
|
-
* const order = await tagada.customer.getOrder(orderId, {
|
|
2183
|
-
* waitForRelatedOrders: true,
|
|
2184
|
-
* });
|
|
2185
|
-
* renderOrders([order, ...(order.relatedOrders ?? [])]);
|
|
2186
|
-
* ```
|
|
2187
|
-
*/
|
|
2188
|
-
async getOrder(orderId, opts) {
|
|
2189
|
-
var _a, _b;
|
|
2190
|
-
const fetchOrder = async () => {
|
|
2191
|
-
const res = await this.http.get(`/api/v1/orders/${orderId}`, {
|
|
2192
|
-
params: { storeId: this.storeId }
|
|
2193
|
-
});
|
|
2194
|
-
return res.order;
|
|
2195
|
-
};
|
|
2196
|
-
let order = await fetchOrder();
|
|
2197
|
-
if (!(opts == null ? void 0 : opts.waitForRelatedOrders) || ((_a = order.relatedOrders) == null ? void 0 : _a.length))
|
|
2198
|
-
return order;
|
|
2199
|
-
const timeoutMs = opts.timeoutMs ?? 8e3;
|
|
2200
|
-
const intervalMs = opts.intervalMs ?? 2e3;
|
|
2201
|
-
const deadline = Date.now() + timeoutMs;
|
|
2202
|
-
while (Date.now() < deadline) {
|
|
2203
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(intervalMs, Math.max(0, deadline - Date.now()))));
|
|
2204
|
-
order = await fetchOrder();
|
|
2205
|
-
if ((_b = order.relatedOrders) == null ? void 0 : _b.length)
|
|
2206
|
-
return order;
|
|
2207
|
-
}
|
|
2208
|
-
return order;
|
|
2108
|
+
constructor(...args) {
|
|
2109
|
+
this.args = args;
|
|
2209
2110
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
);
|
|
2216
|
-
return res.subscriptions;
|
|
2111
|
+
load() {
|
|
2112
|
+
return this.instance || (this.instance = loadCommerce().then((m) => new m.CustomerModule(...this.args)).catch((e) => {
|
|
2113
|
+
this.instance = void 0;
|
|
2114
|
+
throw e;
|
|
2115
|
+
}));
|
|
2217
2116
|
}
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2117
|
+
};
|
|
2118
|
+
for (const method of ["getProfile", "getByEmail", "updateProfile", "getOrders", "getOrder", "getSubscriptions", "getSubscription", "pauseSubscription", "resumeSubscription", "skipSubscription", "rescheduleSubscription", "updateSubscriptionQuantity", "changeSubscriptionFrequency", "swapSubscriptionProduct", "updateSubscriptionPaymentMethod", "cancelSubscription"])
|
|
2119
|
+
CustomerModule.prototype[method] = function(...args) {
|
|
2120
|
+
return this.load().then((instance) => instance[method](...args));
|
|
2121
|
+
};
|
|
2122
|
+
|
|
2123
|
+
// src/core/modules/portal/index.ts
|
|
2124
|
+
var CustomerPortalModule = class {
|
|
2125
|
+
constructor(...args) {
|
|
2126
|
+
this.args = args;
|
|
2127
|
+
}
|
|
2128
|
+
load() {
|
|
2129
|
+
return this.instance || (this.instance = loadCommerce().then((m) => new m.CustomerPortalModule(...this.args)).catch((e) => {
|
|
2130
|
+
this.instance = void 0;
|
|
2131
|
+
throw e;
|
|
2132
|
+
}));
|
|
2225
2133
|
}
|
|
2226
2134
|
};
|
|
2135
|
+
for (const method of ["requestCode", "verifyCode", "getConfig", "getMe", "cancelFlow", "acceptCancelOffer", "switchOption", "getOffer", "acceptOffer", "addToNextOrder", "getCredits", "redeemCredits", "buyCreditPack", "requestEmailChangeCode", "updateProfile", "saveAddress", "removeAddress", "setDefaultAddress", "addCard", "removeCard", "setDefaultPaymentMethod", "retryPayment", "buyAgain", "joinMembership", "buyNow", "sendNow", "reactivateSubscription", "setSubscriptionCard", "setSubscriptionAddress", "skipDate", "unskipDate"])
|
|
2136
|
+
CustomerPortalModule.prototype[method] = function(...args) {
|
|
2137
|
+
return this.load().then((instance) => instance[method](...args));
|
|
2138
|
+
};
|
|
2227
2139
|
|
|
2228
2140
|
// src/core/modules/catalog.ts
|
|
2229
2141
|
var CatalogModule = class {
|
|
@@ -2265,14 +2177,15 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2265
2177
|
|
|
2266
2178
|
// src/core/modules/funnel.ts
|
|
2267
2179
|
var FunnelModule = class {
|
|
2268
|
-
constructor(http, storeId, checkout, accountId) {
|
|
2180
|
+
constructor(http, storeId, checkout, accountId, onFunnelSession) {
|
|
2269
2181
|
this.http = http;
|
|
2270
2182
|
this.storeId = storeId;
|
|
2271
2183
|
this.checkout = checkout;
|
|
2272
2184
|
this.accountId = accountId;
|
|
2185
|
+
this.onFunnelSession = onFunnelSession;
|
|
2273
2186
|
}
|
|
2274
2187
|
async navigate(input) {
|
|
2275
|
-
var _a;
|
|
2188
|
+
var _a, _b;
|
|
2276
2189
|
const session = this.checkout.getCurrentSession();
|
|
2277
2190
|
if (!session) {
|
|
2278
2191
|
throw new TagadaError(
|
|
@@ -2295,14 +2208,18 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2295
2208
|
accountId,
|
|
2296
2209
|
currentUrl
|
|
2297
2210
|
});
|
|
2298
|
-
|
|
2211
|
+
try {
|
|
2212
|
+
(_b = this.onFunnelSession) == null ? void 0 : _b.call(this, funnelSessionId);
|
|
2213
|
+
} catch {
|
|
2214
|
+
}
|
|
2215
|
+
const url2 = await this.runNavigate({
|
|
2299
2216
|
funnelSessionId,
|
|
2300
2217
|
stepId: input.stepId,
|
|
2301
2218
|
session,
|
|
2302
2219
|
input,
|
|
2303
2220
|
currentUrl
|
|
2304
2221
|
});
|
|
2305
|
-
return { url, funnelSessionId };
|
|
2222
|
+
return { url: url2, funnelSessionId };
|
|
2306
2223
|
}
|
|
2307
2224
|
// -------------------------------------------------------------------------
|
|
2308
2225
|
// Internals
|
|
@@ -2475,6 +2392,96 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2475
2392
|
}
|
|
2476
2393
|
};
|
|
2477
2394
|
|
|
2395
|
+
// src/core/modules/experiments.ts
|
|
2396
|
+
var ExperimentsModule = class {
|
|
2397
|
+
constructor(core, bootstrap) {
|
|
2398
|
+
this.core = core;
|
|
2399
|
+
this.bootstrap = bootstrap;
|
|
2400
|
+
this.runtime = null;
|
|
2401
|
+
this.loading = null;
|
|
2402
|
+
this.settled = false;
|
|
2403
|
+
this.reads = /* @__PURE__ */ new Set();
|
|
2404
|
+
this.subscribers = [];
|
|
2405
|
+
}
|
|
2406
|
+
variant(key) {
|
|
2407
|
+
var _a, _b, _c, _d;
|
|
2408
|
+
return ((_b = (_a = this.bootstrap) == null ? void 0 : _a.experiments[key]) == null ? void 0 : _b.arm) ?? ((_d = (_c = this.bootstrap) == null ? void 0 : _c.flags[key]) == null ? void 0 : _d.variant) ?? null;
|
|
2409
|
+
}
|
|
2410
|
+
start() {
|
|
2411
|
+
if (typeof window === "undefined")
|
|
2412
|
+
return Promise.resolve();
|
|
2413
|
+
this.loading ?? (this.loading = (async () => {
|
|
2414
|
+
try {
|
|
2415
|
+
this.runtime = await this.core();
|
|
2416
|
+
} catch {
|
|
2417
|
+
}
|
|
2418
|
+
this.settled = true;
|
|
2419
|
+
const runtime = this.runtime;
|
|
2420
|
+
for (const key of this.reads) {
|
|
2421
|
+
try {
|
|
2422
|
+
runtime == null ? void 0 : runtime.getVariant(key);
|
|
2423
|
+
} catch {
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
this.reads.clear();
|
|
2427
|
+
for (const { key, cb } of this.subscribers.splice(0)) {
|
|
2428
|
+
try {
|
|
2429
|
+
if (runtime)
|
|
2430
|
+
runtime.onVariant(key, cb);
|
|
2431
|
+
else
|
|
2432
|
+
cb(this.variant(key));
|
|
2433
|
+
} catch {
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
try {
|
|
2437
|
+
await (runtime == null ? void 0 : runtime.ready());
|
|
2438
|
+
} catch {
|
|
2439
|
+
}
|
|
2440
|
+
})());
|
|
2441
|
+
return this.loading;
|
|
2442
|
+
}
|
|
2443
|
+
read(key) {
|
|
2444
|
+
if (!this.settled)
|
|
2445
|
+
this.reads.add(key);
|
|
2446
|
+
void this.start();
|
|
2447
|
+
}
|
|
2448
|
+
getVariant(key) {
|
|
2449
|
+
if (this.runtime)
|
|
2450
|
+
return this.runtime.getVariant(key);
|
|
2451
|
+
this.read(key);
|
|
2452
|
+
return this.variant(key);
|
|
2453
|
+
}
|
|
2454
|
+
getPayload(key) {
|
|
2455
|
+
var _a, _b, _c, _d;
|
|
2456
|
+
if (this.runtime)
|
|
2457
|
+
return this.runtime.getPayload(key);
|
|
2458
|
+
this.read(key);
|
|
2459
|
+
return ((_b = (_a = this.bootstrap) == null ? void 0 : _a.experiments[key]) == null ? void 0 : _b.payload) ?? ((_d = (_c = this.bootstrap) == null ? void 0 : _c.flags[key]) == null ? void 0 : _d.payload) ?? null;
|
|
2460
|
+
}
|
|
2461
|
+
isEnabled(flagKey) {
|
|
2462
|
+
var _a, _b;
|
|
2463
|
+
if (this.runtime)
|
|
2464
|
+
return this.runtime.isEnabled(flagKey);
|
|
2465
|
+
this.read(flagKey);
|
|
2466
|
+
return ((_b = (_a = this.bootstrap) == null ? void 0 : _a.flags[flagKey]) == null ? void 0 : _b.enabled) ?? false;
|
|
2467
|
+
}
|
|
2468
|
+
onVariant(key, cb) {
|
|
2469
|
+
if (this.runtime) {
|
|
2470
|
+
this.runtime.onVariant(key, cb);
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
if (this.settled) {
|
|
2474
|
+
cb(this.variant(key));
|
|
2475
|
+
return;
|
|
2476
|
+
}
|
|
2477
|
+
this.subscribers.push({ key, cb });
|
|
2478
|
+
void this.start();
|
|
2479
|
+
}
|
|
2480
|
+
ready() {
|
|
2481
|
+
return this.start();
|
|
2482
|
+
}
|
|
2483
|
+
};
|
|
2484
|
+
|
|
2478
2485
|
// src/core/client.ts
|
|
2479
2486
|
var HeadlessClient = class {
|
|
2480
2487
|
constructor(config) {
|
|
@@ -2493,6 +2500,8 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2493
2500
|
getToken: () => this._sessionToken
|
|
2494
2501
|
});
|
|
2495
2502
|
this.track = new TrackModule(baseUrl, this.config.storeId, this.config.funnel ?? "main");
|
|
2503
|
+
this.track.bootstrap = this.config.bootstrap;
|
|
2504
|
+
this.experiments = new ExperimentsModule(() => this.track.core(), this.config.bootstrap);
|
|
2496
2505
|
const setToken = (token) => {
|
|
2497
2506
|
this._sessionToken = token;
|
|
2498
2507
|
};
|
|
@@ -2517,12 +2526,14 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2517
2526
|
);
|
|
2518
2527
|
this.offers = new OffersModule(this.http, this.config.storeId, this.payment);
|
|
2519
2528
|
this.customer = new CustomerModule(this.http, this.config.storeId);
|
|
2529
|
+
this.portal = new CustomerPortalModule(this.http, this.config.storeId, setToken);
|
|
2520
2530
|
this.catalog = new CatalogModule(this.http, this.config.storeId);
|
|
2521
2531
|
this.funnel = new FunnelModule(
|
|
2522
2532
|
this.http,
|
|
2523
2533
|
this.config.storeId,
|
|
2524
2534
|
this.checkout,
|
|
2525
|
-
this.config.accountId
|
|
2535
|
+
this.config.accountId,
|
|
2536
|
+
(id) => this.track.noteFunnelSession(id)
|
|
2526
2537
|
);
|
|
2527
2538
|
this.rx = new RxModule(this.http, this.config.storeId);
|
|
2528
2539
|
}
|
|
@@ -2579,13 +2590,13 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2579
2590
|
params.set("language", opts.language);
|
|
2580
2591
|
if (opts.region)
|
|
2581
2592
|
params.set("region", opts.region);
|
|
2582
|
-
const
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
document.head.appendChild(
|
|
2593
|
+
const script2 = document.createElement("script");
|
|
2594
|
+
script2.src = `https://maps.googleapis.com/maps/api/js?${params}`;
|
|
2595
|
+
script2.async = true;
|
|
2596
|
+
script2.defer = true;
|
|
2597
|
+
script2.onload = () => onScriptReady();
|
|
2598
|
+
script2.onerror = () => reject(new Error("Failed to load Google Maps script"));
|
|
2599
|
+
document.head.appendChild(script2);
|
|
2589
2600
|
});
|
|
2590
2601
|
}
|
|
2591
2602
|
var GoogleAutocompleteCore = class _GoogleAutocompleteCore {
|
|
@@ -2734,10 +2745,10 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2734
2745
|
if (inflight)
|
|
2735
2746
|
return inflight;
|
|
2736
2747
|
inflight = (async () => {
|
|
2737
|
-
const
|
|
2738
|
-
const res = await fetch(
|
|
2748
|
+
const url2 = `${GEODATA_CDN_BASE}/${language}/countries.json`;
|
|
2749
|
+
const res = await fetch(url2);
|
|
2739
2750
|
if (!res.ok)
|
|
2740
|
-
throw new Error(`Geodata fetch failed: ${
|
|
2751
|
+
throw new Error(`Geodata fetch failed: ${url2} (${res.status})`);
|
|
2741
2752
|
const data = await res.json();
|
|
2742
2753
|
countriesCache.set(language, data);
|
|
2743
2754
|
inflightCountries.delete(language);
|
|
@@ -2754,10 +2765,10 @@ var TagadaHeadlessBundle = (() => {
|
|
|
2754
2765
|
if (inflight)
|
|
2755
2766
|
return inflight;
|
|
2756
2767
|
inflight = (async () => {
|
|
2757
|
-
const
|
|
2758
|
-
const res = await fetch(
|
|
2768
|
+
const url2 = `${GEODATA_CDN_BASE}/${language}/regions.json`;
|
|
2769
|
+
const res = await fetch(url2);
|
|
2759
2770
|
if (!res.ok)
|
|
2760
|
-
throw new Error(`Geodata fetch failed: ${
|
|
2771
|
+
throw new Error(`Geodata fetch failed: ${url2} (${res.status})`);
|
|
2761
2772
|
const data = await res.json();
|
|
2762
2773
|
regionsCache.set(language, data);
|
|
2763
2774
|
inflightRegions.delete(language);
|