@tagadapay/plugin-sdk 4.0.6 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +25 -46
  2. package/dist/external-tracker.js +103 -36
  3. package/dist/external-tracker.min.js +2 -2
  4. package/dist/external-tracker.min.js.map +3 -3
  5. package/dist/react/types.d.ts +2 -2
  6. package/dist/tagada-react-sdk-minimal.min.js +2 -2
  7. package/dist/tagada-react-sdk-minimal.min.js.map +3 -3
  8. package/dist/tagada-react-sdk.js +148 -28
  9. package/dist/tagada-react-sdk.min.js +2 -2
  10. package/dist/tagada-react-sdk.min.js.map +4 -4
  11. package/dist/tagada-sdk.js +125 -45
  12. package/dist/tagada-sdk.min.js +2 -2
  13. package/dist/tagada-sdk.min.js.map +4 -4
  14. package/dist/v2/core/funnelClient.js +14 -9
  15. package/dist/v2/core/pixelMapping.d.ts +84 -0
  16. package/dist/v2/core/pixelMapping.js +102 -0
  17. package/dist/v2/core/pixelTracker.d.ts +1 -6
  18. package/dist/v2/core/pixelTracker.js +36 -2
  19. package/dist/v2/core/resources/credits.d.ts +13 -0
  20. package/dist/v2/core/resources/credits.js +7 -0
  21. package/dist/v2/core/resources/offers.d.ts +5 -1
  22. package/dist/v2/core/resources/offers.js +3 -2
  23. package/dist/v2/core/resources/payments.d.ts +1 -0
  24. package/dist/v2/core/resources/payments.js +1 -0
  25. package/dist/v2/core/types.d.ts +17 -2
  26. package/dist/v2/core/utils/authHandoff.d.ts +2 -1
  27. package/dist/v2/index.d.ts +3 -1
  28. package/dist/v2/index.js +4 -1
  29. package/dist/v2/react/components/FunnelScriptInjector.js +42 -7
  30. package/dist/v2/react/hooks/useAuth.d.ts +1 -0
  31. package/dist/v2/react/hooks/useAuth.js +1 -0
  32. package/dist/v2/react/hooks/useClubOffers.d.ts +16 -0
  33. package/dist/v2/react/hooks/useClubOffers.js +29 -3
  34. package/dist/v2/react/hooks/useCustomer.d.ts +1 -0
  35. package/dist/v2/react/hooks/useCustomer.js +1 -0
  36. package/dist/v2/react/hooks/useStore.d.ts +5 -0
  37. package/dist/v2/react/hooks/useStore.js +16 -0
  38. package/dist/v2/react/index.d.ts +1 -0
  39. package/dist/v2/react/index.js +1 -0
  40. package/dist/v2/standalone/index.js +134 -46
  41. package/dist/v2/standalone/payment-service.d.ts +2 -1
  42. package/dist/v2/standalone/payment-service.js +6 -4
  43. package/package.json +113 -115
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TagadaPay React SDK v4.0.6
2
+ * TagadaPay React SDK v4.1.0
3
3
  * CDN Bundle - React hooks and TagadaProvider (Debug Build)
4
4
  * @license MIT
5
5
  */
@@ -10233,13 +10233,17 @@ var TagadaReactSDKBundle = (() => {
10233
10233
  }
10234
10234
  return scripts.length > 0 ? scripts : void 0;
10235
10235
  }
10236
+ function splitIds(rawId) {
10237
+ if (!rawId) return [];
10238
+ return rawId.split(/[;,]/).map((id) => id.trim()).filter((id) => id.length > 0);
10239
+ }
10236
10240
  function splitPixelConfig(px) {
10237
- const idField = "containerId" in px ? "containerId" : "pixelId";
10238
- const rawId = px[idField];
10239
- if (!rawId || !rawId.includes(";") && !rawId.includes(",")) return [px];
10240
- const ids = rawId.split(/[;,]/).map((id) => id.trim()).filter((id) => id.length > 0);
10241
- if (ids.length <= 1) return [px];
10242
- return ids.map((id) => __spreadProps(__spreadValues({}, px), { [idField]: id }));
10241
+ if ("containerId" in px) {
10242
+ const ids2 = splitIds(px.containerId);
10243
+ return ids2.length === 0 ? [px] : ids2.map((id) => __spreadProps(__spreadValues({}, px), { containerId: id }));
10244
+ }
10245
+ const ids = splitIds(px.pixelId);
10246
+ return ids.length === 0 ? [px] : ids.map((id) => __spreadProps(__spreadValues({}, px), { pixelId: id }));
10243
10247
  }
10244
10248
  function getAssignedPixels() {
10245
10249
  const stepConfig = getAssignedStepConfig();
@@ -12569,6 +12573,10 @@ var TagadaReactSDKBundle = (() => {
12569
12573
  p3 = convertValueToMajor(p3);
12570
12574
  p3 = convertMonetaryFieldsToMajor(p3);
12571
12575
  p3 = convertContentsPricesToMajor(p3);
12576
+ if (GA4_PARAM_KEY in p3) {
12577
+ p3 = __spreadValues({}, p3);
12578
+ delete p3[GA4_PARAM_KEY];
12579
+ }
12572
12580
  return p3;
12573
12581
  }
12574
12582
  function mapMetaEvent(eventName, parameters) {
@@ -12658,8 +12666,31 @@ var TagadaReactSDKBundle = (() => {
12658
12666
  return { name, params };
12659
12667
  }
12660
12668
  function mapGTMEvent(eventName, parameters) {
12661
- var _a11;
12669
+ var _a11, _b2;
12662
12670
  const name = (_a11 = GTM_EVENT_MAP[eventName]) != null ? _a11 : eventName.toLowerCase();
12671
+ const ga4 = parameters[GA4_PARAM_KEY];
12672
+ if (ga4) {
12673
+ const currency = typeof parameters.currency === "string" ? parameters.currency.toUpperCase() : void 0;
12674
+ const toMajor = (v2) => v2 == null || !currency ? v2 : minorToMajor(Number(v2), currency);
12675
+ const ecommerce = {
12676
+ transaction_id: parameters.transaction_id,
12677
+ currency,
12678
+ value: toMajor(ga4.value)
12679
+ };
12680
+ if (ga4.tax != null) ecommerce.tax = toMajor(ga4.tax);
12681
+ if (ga4.shipping != null) ecommerce.shipping = toMajor(ga4.shipping);
12682
+ ecommerce.items = ((_b2 = ga4.items) != null ? _b2 : []).map((item) => ({
12683
+ item_id: item.item_id,
12684
+ item_name: item.item_name,
12685
+ item_variant: item.item_variant,
12686
+ price: toMajor(item.price),
12687
+ quantity: item.quantity != null ? Number(item.quantity) : void 0
12688
+ }));
12689
+ const out = { ecommerce };
12690
+ if (ga4.user_id) out.user_id = ga4.user_id;
12691
+ if (ga4.user_data) out.user_data = ga4.user_data;
12692
+ return { name, params: out };
12693
+ }
12663
12694
  const params = baseTransform(parameters);
12664
12695
  if (params.num_items !== void 0) {
12665
12696
  params.num_items = Number(params.num_items);
@@ -12720,10 +12751,11 @@ var TagadaReactSDKBundle = (() => {
12720
12751
  }
12721
12752
  return results;
12722
12753
  }
12723
- var ZERO_DECIMAL_CURRENCIES, THREE_DECIMAL_CURRENCIES, META_EVENT_MAP, TIKTOK_EVENT_MAP, SNAPCHAT_EVENT_MAP, PINTEREST_EVENT_MAP, GTM_EVENT_MAP;
12754
+ var GA4_PARAM_KEY, ZERO_DECIMAL_CURRENCIES, THREE_DECIMAL_CURRENCIES, META_EVENT_MAP, TIKTOK_EVENT_MAP, SNAPCHAT_EVENT_MAP, PINTEREST_EVENT_MAP, GTM_EVENT_MAP;
12724
12755
  var init_pixelMapping = __esm({
12725
12756
  "src/v2/core/pixelMapping.ts"() {
12726
12757
  "use strict";
12758
+ GA4_PARAM_KEY = "_ga4";
12727
12759
  ZERO_DECIMAL_CURRENCIES = /* @__PURE__ */ new Set([
12728
12760
  "BIF",
12729
12761
  "CLP",
@@ -12863,9 +12895,16 @@ var TagadaReactSDKBundle = (() => {
12863
12895
  function fireGTM(event, params) {
12864
12896
  try {
12865
12897
  const w2 = window;
12898
+ const hasEcommerce = params && typeof params === "object" && "ecommerce" in params;
12866
12899
  if (w2.gtag) {
12867
- w2.gtag("event", event, params);
12900
+ if (hasEcommerce) {
12901
+ const _a11 = params, { ecommerce } = _a11, rest = __objRest(_a11, ["ecommerce"]);
12902
+ w2.gtag("event", event, __spreadValues(__spreadValues({}, rest), ecommerce));
12903
+ } else {
12904
+ w2.gtag("event", event, params);
12905
+ }
12868
12906
  } else if (w2.dataLayer) {
12907
+ if (hasEcommerce) w2.dataLayer.push({ ecommerce: null });
12869
12908
  w2.dataLayer.push(__spreadValues({ event }, params));
12870
12909
  }
12871
12910
  } catch (error) {
@@ -13070,7 +13109,21 @@ var TagadaReactSDKBundle = (() => {
13070
13109
  return waitForScriptLoad(script);
13071
13110
  }
13072
13111
  }
13073
- function createPixelTracker(pixels) {
13112
+ function trimPixelIds(pixels) {
13113
+ const out = {};
13114
+ for (const [provider, list] of Object.entries(pixels)) {
13115
+ if (!Array.isArray(list)) continue;
13116
+ out[provider] = list.map((px) => {
13117
+ if ("containerId" in px) {
13118
+ return typeof px.containerId === "string" ? __spreadProps(__spreadValues({}, px), { containerId: px.containerId.trim() }) : px;
13119
+ }
13120
+ return typeof px.pixelId === "string" ? __spreadProps(__spreadValues({}, px), { pixelId: px.pixelId.trim() }) : px;
13121
+ });
13122
+ }
13123
+ return out;
13124
+ }
13125
+ function createPixelTracker(rawPixels) {
13126
+ const pixels = rawPixels ? trimPixelIds(rawPixels) : rawPixels;
13074
13127
  const shouldTrackEvent = createDuplicateGuard(5e3);
13075
13128
  let pixelsInitialized = false;
13076
13129
  const initPromise = (async () => {
@@ -14015,6 +14068,13 @@ var TagadaReactSDKBundle = (() => {
14015
14068
  async redeemProduct(data) {
14016
14069
  return this.apiClient.post("/api/v1/credits/redeem", data);
14017
14070
  }
14071
+ /**
14072
+ * Redeem an offer (its full bundle of line items) using credits.
14073
+ * customerId/storeId/accountId are derived server-side from the verified session.
14074
+ */
14075
+ async redeemOffer(data) {
14076
+ return this.apiClient.post("/api/v1/credits/redeem-offer", data);
14077
+ }
14018
14078
  };
14019
14079
  }
14020
14080
  });
@@ -14281,15 +14341,14 @@ var TagadaReactSDKBundle = (() => {
14281
14341
  /**
14282
14342
  * Pay for an offer directly
14283
14343
  */
14284
- async payOffer(offerId, orderId, initiatedBy) {
14344
+ async payOffer(offerId, orderId, initiatedBy, customerId) {
14285
14345
  const draft = isDraftMode();
14286
14346
  const effectiveInitiatedBy = initiatedBy != null ? initiatedBy : getAssignedPaymentInitiator();
14287
- return this.apiClient.post("/api/v1/offers/".concat(offerId, "/pay"), __spreadProps(__spreadValues({
14347
+ return this.apiClient.post("/api/v1/offers/".concat(offerId, "/pay"), __spreadProps(__spreadValues(__spreadValues({
14288
14348
  offerId,
14289
14349
  draft,
14290
- // 🎯 Use dynamic draft mode instead of hardcoded false
14291
14350
  returnUrl: typeof window !== "undefined" ? window.location.href : ""
14292
- }, effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}), {
14351
+ }, customerId ? { customerId } : {}), effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}), {
14293
14352
  metadata: orderId ? {
14294
14353
  comingFromPostPurchase: true,
14295
14354
  postOrder: orderId,
@@ -14604,10 +14663,10 @@ var TagadaReactSDKBundle = (() => {
14604
14663
  console.log("[PaymentsResource] Full options object:", JSON.stringify(options, null, 2));
14605
14664
  console.log("[PaymentsResource] processorId:", options.processorId, "paymentMethod:", options.paymentMethod);
14606
14665
  try {
14607
- const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
14666
+ const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
14608
14667
  checkoutSessionId,
14609
14668
  paymentInstrumentId
14610
- }, threedsSessionId && { threedsSessionId }), options.initiatedBy && { initiatedBy: options.initiatedBy }), options.source && { source: options.source }), options.paymentFlowId && { paymentFlowId: options.paymentFlowId }), options.processorId && { processorId: options.processorId }), options.paymentMethod && { paymentMethod: options.paymentMethod }), options.isExpress && { isExpress: options.isExpress }), options.shippingRateId && { shippingRateId: options.shippingRateId });
14669
+ }, threedsSessionId && { threedsSessionId }), options.initiatedBy && { initiatedBy: options.initiatedBy }), options.source && { source: options.source }), options.paymentFlowId && { paymentFlowId: options.paymentFlowId }), options.processorId && { processorId: options.processorId }), options.paymentMethod && { paymentMethod: options.paymentMethod }), options.blikCode && { blikCode: options.blikCode }), options.isExpress && { isExpress: options.isExpress }), options.shippingRateId && { shippingRateId: options.shippingRateId });
14611
14670
  console.log("[PaymentsResource] Request body being sent:", JSON.stringify(requestBody, null, 2));
14612
14671
  const response = await this.apiClient.post("/api/public/v1/checkout/pay-v2", requestBody);
14613
14672
  console.log("[PaymentsResource] processPaymentDirect SUCCESS:", response);
@@ -16451,6 +16510,11 @@ var TagadaReactSDKBundle = (() => {
16451
16510
  __export(FunnelScriptInjector_exports, {
16452
16511
  FunnelScriptInjector: () => FunnelScriptInjector
16453
16512
  });
16513
+ function classifyLooseChunk(chunk) {
16514
+ if (!chunk || /^<!--[\s\S]*?-->$/.test(chunk)) return null;
16515
+ const looksLikeMarkup = /^</.test(chunk) || /<\/?[a-zA-Z][\w-]*[\s/>]/.test(chunk);
16516
+ return looksLikeMarkup ? { type: "html", html: chunk } : { type: "inline", code: chunk };
16517
+ }
16454
16518
  function parseScriptContent(content) {
16455
16519
  const trimmed = content.trim();
16456
16520
  if (!/<(?:script|noscript)[\s>]/i.test(trimmed)) {
@@ -16462,8 +16526,9 @@ var TagadaReactSDKBundle = (() => {
16462
16526
  let match4;
16463
16527
  while ((match4 = tagRegex.exec(trimmed)) !== null) {
16464
16528
  const between = trimmed.slice(lastIndex, match4.index).trim();
16465
- if (between && !/^<!--[\s\S]*?-->$/.test(between)) {
16466
- elements.push({ type: "inline", code: between });
16529
+ const betweenElement = classifyLooseChunk(between);
16530
+ if (betweenElement) {
16531
+ elements.push(betweenElement);
16467
16532
  }
16468
16533
  const [, tagName, attrs, body] = match4;
16469
16534
  if (tagName.toLowerCase() === "noscript") {
@@ -16487,8 +16552,9 @@ var TagadaReactSDKBundle = (() => {
16487
16552
  lastIndex = match4.index + match4[0].length;
16488
16553
  }
16489
16554
  const trailing = trimmed.slice(lastIndex).trim();
16490
- if (trailing && !/^<!--[\s\S]*?-->$/.test(trailing)) {
16491
- elements.push({ type: "inline", code: trailing });
16555
+ const trailingElement = classifyLooseChunk(trailing);
16556
+ if (trailingElement) {
16557
+ elements.push(trailingElement);
16492
16558
  }
16493
16559
  return elements;
16494
16560
  }
@@ -16885,6 +16951,16 @@ var TagadaReactSDKBundle = (() => {
16885
16951
  el.setAttribute("data-tagada-stepconfig-script", "true");
16886
16952
  el.innerHTML = element.html;
16887
16953
  injectAtPosition(el, position);
16954
+ } else if (element.type === "html") {
16955
+ const template = document.createElement("template");
16956
+ template.innerHTML = element.html;
16957
+ Array.from(template.content.childNodes).forEach((node) => {
16958
+ if (node.nodeType !== 1) return;
16959
+ const el = node;
16960
+ el.setAttribute("data-tagada-stepconfig-script", "true");
16961
+ el.setAttribute("data-script-name", script.name);
16962
+ injectAtPosition(el, position);
16963
+ });
16888
16964
  }
16889
16965
  });
16890
16966
  });
@@ -28113,6 +28189,7 @@ var TagadaReactSDKBundle = (() => {
28113
28189
  useShippingRates: () => useShippingRatesQuery,
28114
28190
  useSimpleFunnel: () => useSimpleFunnel,
28115
28191
  useStepConfig: () => useStepConfig,
28192
+ useStore: () => useStore,
28116
28193
  useStoreConfig: () => useStoreConfigQuery,
28117
28194
  useTagadaContext: () => useTagadaContext,
28118
28195
  useThreeds: () => useThreeds,
@@ -34756,9 +34833,11 @@ var TagadaReactSDKBundle = (() => {
34756
34833
  // src/v2/react/hooks/useAuth.ts
34757
34834
  init_TagadaProvider();
34758
34835
  function useAuth() {
34836
+ var _a11;
34759
34837
  const { auth, isInitialized } = useTagadaContext();
34760
34838
  return __spreadProps(__spreadValues({}, auth), {
34761
- isInitialized
34839
+ isInitialized,
34840
+ isVerified: ((_a11 = auth.customer) == null ? void 0 : _a11.role) === "verified"
34762
34841
  });
34763
34842
  }
34764
34843
 
@@ -34878,10 +34957,12 @@ var TagadaReactSDKBundle = (() => {
34878
34957
  init_modern2();
34879
34958
  var import_react50 = __require("react");
34880
34959
  init_offers();
34960
+ init_credits();
34881
34961
  init_TagadaProvider();
34882
34962
  init_useApiQuery();
34883
34963
  init_usePluginConfig();
34884
34964
  function transformToClubOffer(offer) {
34965
+ var _a11;
34885
34966
  return {
34886
34967
  id: offer.id,
34887
34968
  titleTrans: offer.titleTrans,
@@ -34910,14 +34991,16 @@ var TagadaReactSDKBundle = (() => {
34910
34991
  adjustedAmount: item.adjustedAmount
34911
34992
  }))
34912
34993
  })),
34913
- offerLineItems: []
34994
+ offerLineItems: [],
34914
34995
  // Not available in base Offer
34996
+ // Resolved server-side and attached to the list response (not part of base Offer).
34997
+ creditsRequired: (_a11 = offer.creditsRequired) != null ? _a11 : null
34915
34998
  };
34916
34999
  }
34917
35000
  function useClubOffers(options = {}) {
34918
35001
  const { enabled = true, returnUrl } = options;
34919
35002
  const { storeId } = usePluginConfig();
34920
- const { isSessionInitialized } = useTagadaContext();
35003
+ const { isSessionInitialized, session } = useTagadaContext();
34921
35004
  const offersResource = (0, import_react50.useMemo)(() => {
34922
35005
  try {
34923
35006
  return new OffersResource(getGlobalApiClient());
@@ -34927,6 +35010,15 @@ var TagadaReactSDKBundle = (() => {
34927
35010
  );
34928
35011
  }
34929
35012
  }, []);
35013
+ const creditsResource = (0, import_react50.useMemo)(() => {
35014
+ try {
35015
+ return new CreditsResource(getGlobalApiClient());
35016
+ } catch (error2) {
35017
+ throw new Error(
35018
+ "Failed to initialize credits resource: " + (error2 instanceof Error ? error2.message : "Unknown error")
35019
+ );
35020
+ }
35021
+ }, []);
34930
35022
  const queryKey = (0, import_react50.useMemo)(() => ["club-offers", { storeId }], [storeId]);
34931
35023
  const {
34932
35024
  data: offers = [],
@@ -34956,13 +35048,20 @@ var TagadaReactSDKBundle = (() => {
34956
35048
  });
34957
35049
  const payOfferMutation = useMutation({
34958
35050
  mutationFn: async ({ offerId, returnUrl: returnUrl2 }) => {
34959
- const url = returnUrl2 || (typeof window !== "undefined" ? window.location.href : "");
34960
- return await offersResource.payOffer(offerId);
35051
+ return await offersResource.payOffer(offerId, void 0, void 0, session == null ? void 0 : session.customerId);
34961
35052
  },
34962
35053
  onError: (error2) => {
34963
35054
  console.error("[SDK] Failed to pay offer:", error2);
34964
35055
  }
34965
35056
  });
35057
+ const redeemOfferMutation = useMutation({
35058
+ mutationFn: async ({ offerId }) => {
35059
+ return await creditsResource.redeemOffer({ offerId });
35060
+ },
35061
+ onError: (error2) => {
35062
+ console.error("[SDK] Failed to redeem offer with credits:", error2);
35063
+ }
35064
+ });
34966
35065
  const getOffer = (0, import_react50.useCallback)(
34967
35066
  (offerId) => {
34968
35067
  return offers.find((offer) => offer.id === offerId);
@@ -34989,6 +35088,12 @@ var TagadaReactSDKBundle = (() => {
34989
35088
  },
34990
35089
  [payOfferMutation]
34991
35090
  );
35091
+ const redeemOffer = (0, import_react50.useCallback)(
35092
+ async (offerId) => {
35093
+ return await redeemOfferMutation.mutateAsync({ offerId });
35094
+ },
35095
+ [redeemOfferMutation]
35096
+ );
34992
35097
  return {
34993
35098
  offers,
34994
35099
  isLoading,
@@ -35000,7 +35105,9 @@ var TagadaReactSDKBundle = (() => {
35000
35105
  getTotalValue,
35001
35106
  getTotalSavings,
35002
35107
  clearError,
35003
- payOffer
35108
+ payOffer,
35109
+ redeemOffer,
35110
+ isRedeeming: redeemOfferMutation.isPending
35004
35111
  };
35005
35112
  }
35006
35113
 
@@ -35108,7 +35215,8 @@ var TagadaReactSDKBundle = (() => {
35108
35215
  customer,
35109
35216
  isAuthenticated: (customer == null ? void 0 : customer.isAuthenticated) || false,
35110
35217
  isLoading,
35111
- isAnonymous: (customer == null ? void 0 : customer.role) === "anonymous"
35218
+ isAnonymous: (customer == null ? void 0 : customer.role) === "anonymous",
35219
+ isVerified: (customer == null ? void 0 : customer.role) === "verified"
35112
35220
  };
35113
35221
  }
35114
35222
 
@@ -36087,6 +36195,18 @@ var TagadaReactSDKBundle = (() => {
36087
36195
  };
36088
36196
  }
36089
36197
 
36198
+ // src/v2/react/hooks/useStore.ts
36199
+ init_TagadaProvider();
36200
+ function useStore() {
36201
+ var _a11;
36202
+ const { store } = useTagadaContext();
36203
+ return {
36204
+ store,
36205
+ /** Whether the store's credit system is enabled. */
36206
+ isCreditEnabled: Boolean((_a11 = store == null ? void 0 : store.creditSettings) == null ? void 0 : _a11.enabled)
36207
+ };
36208
+ }
36209
+
36090
36210
  // src/v2/react/index.ts
36091
36211
  init_usePixelTracking();
36092
36212
  init_usePluginConfig();