@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 SDK v4.0.6
2
+ * TagadaPay SDK v4.1.0
3
3
  * CDN Bundle - Full standalone SDK (Debug Build)
4
4
  * Usage: window.tgd.createTagadaClient(), window.tgd.formatMoney(), etc.
5
5
  * @license MIT
@@ -1238,13 +1238,17 @@ var TagadaSDKBundle = (() => {
1238
1238
  }
1239
1239
  return scripts.length > 0 ? scripts : void 0;
1240
1240
  }
1241
+ function splitIds(rawId) {
1242
+ if (!rawId) return [];
1243
+ return rawId.split(/[;,]/).map((id) => id.trim()).filter((id) => id.length > 0);
1244
+ }
1241
1245
  function splitPixelConfig(px) {
1242
- const idField = "containerId" in px ? "containerId" : "pixelId";
1243
- const rawId = px[idField];
1244
- if (!rawId || !rawId.includes(";") && !rawId.includes(",")) return [px];
1245
- const ids = rawId.split(/[;,]/).map((id) => id.trim()).filter((id) => id.length > 0);
1246
- if (ids.length <= 1) return [px];
1247
- return ids.map((id) => __spreadProps(__spreadValues({}, px), { [idField]: id }));
1246
+ if ("containerId" in px) {
1247
+ const ids2 = splitIds(px.containerId);
1248
+ return ids2.length === 0 ? [px] : ids2.map((id) => __spreadProps(__spreadValues({}, px), { containerId: id }));
1249
+ }
1250
+ const ids = splitIds(px.pixelId);
1251
+ return ids.length === 0 ? [px] : ids.map((id) => __spreadProps(__spreadValues({}, px), { pixelId: id }));
1248
1252
  }
1249
1253
  function getAssignedPixels() {
1250
1254
  const stepConfig = getAssignedStepConfig();
@@ -6996,7 +7000,7 @@ var TagadaSDKBundle = (() => {
6996
7000
  var _constants = require_constants2();
6997
7001
  var _script2 = require_script();
6998
7002
  var elementsPromise;
6999
- var loadScript = (url, retryCount) => new Promise((resolve, reject) => {
7003
+ var loadScript2 = (url, retryCount) => new Promise((resolve, reject) => {
7000
7004
  let script = (0, _script2.findScript)(url);
7001
7005
  if (!script) {
7002
7006
  script = (0, _script2.injectScript)(url);
@@ -7054,7 +7058,7 @@ var TagadaSDKBundle = (() => {
7054
7058
  }
7055
7059
  });
7056
7060
  if (retryCount === 0) {
7057
- loadScript(url, retryCount + 1).then(resolve).catch(reject);
7061
+ loadScript2(url, retryCount + 1).then(resolve).catch(reject);
7058
7062
  return;
7059
7063
  }
7060
7064
  try {
@@ -7137,7 +7141,7 @@ var TagadaSDKBundle = (() => {
7137
7141
  throw new Error("Invalid format for the given Elements client url.");
7138
7142
  }
7139
7143
  }
7140
- loadScript(url, 0).then(resolve).catch((error) => {
7144
+ loadScript2(url, 0).then(resolve).catch((error) => {
7141
7145
  reject(error);
7142
7146
  });
7143
7147
  });
@@ -10937,10 +10941,10 @@ var TagadaSDKBundle = (() => {
10937
10941
  console.log("[PaymentsResource] Full options object:", JSON.stringify(options, null, 2));
10938
10942
  console.log("[PaymentsResource] processorId:", options.processorId, "paymentMethod:", options.paymentMethod);
10939
10943
  try {
10940
- const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
10944
+ const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
10941
10945
  checkoutSessionId,
10942
10946
  paymentInstrumentId
10943
- }, 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 });
10947
+ }, 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 });
10944
10948
  console.log("[PaymentsResource] Request body being sent:", JSON.stringify(requestBody, null, 2));
10945
10949
  const response = await this.apiClient.post("/api/public/v1/checkout/pay-v2", requestBody);
10946
10950
  console.log("[PaymentsResource] processPaymentDirect SUCCESS:", response);
@@ -11226,15 +11230,14 @@ var TagadaSDKBundle = (() => {
11226
11230
  /**
11227
11231
  * Pay for an offer directly
11228
11232
  */
11229
- async payOffer(offerId, orderId, initiatedBy) {
11233
+ async payOffer(offerId, orderId, initiatedBy, customerId) {
11230
11234
  const draft = isDraftMode();
11231
11235
  const effectiveInitiatedBy = initiatedBy != null ? initiatedBy : getAssignedPaymentInitiator();
11232
- return this.apiClient.post("/api/v1/offers/".concat(offerId, "/pay"), __spreadProps(__spreadValues({
11236
+ return this.apiClient.post("/api/v1/offers/".concat(offerId, "/pay"), __spreadProps(__spreadValues(__spreadValues({
11233
11237
  offerId,
11234
11238
  draft,
11235
- // 🎯 Use dynamic draft mode instead of hardcoded false
11236
11239
  returnUrl: typeof window !== "undefined" ? window.location.href : ""
11237
- }, effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}), {
11240
+ }, customerId ? { customerId } : {}), effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}), {
11238
11241
  metadata: orderId ? {
11239
11242
  comingFromPostPurchase: true,
11240
11243
  postOrder: orderId,
@@ -12835,6 +12838,7 @@ var TagadaSDKBundle = (() => {
12835
12838
  paymentFlowId,
12836
12839
  processorId: extra == null ? void 0 : extra.processorId,
12837
12840
  paymentMethod: extra == null ? void 0 : extra.paymentMethod,
12841
+ blikCode: extra == null ? void 0 : extra.blikCode,
12838
12842
  shippingRateId: extra == null ? void 0 : extra.shippingRateId
12839
12843
  }
12840
12844
  );
@@ -13657,6 +13661,7 @@ var TagadaSDKBundle = (() => {
13657
13661
  return await this.processAndHandle(checkoutSessionId, "", void 0, {
13658
13662
  processorId: apmData.processorId,
13659
13663
  paymentMethod: apmData.paymentMethod,
13664
+ blikCode: apmData.blikCode,
13660
13665
  initiatedBy: apmData.initiatedBy,
13661
13666
  source: apmData.source,
13662
13667
  shippingRateId: options == null ? void 0 : options.shippingRateId
@@ -13764,6 +13769,18 @@ var TagadaSDKBundle = (() => {
13764
13769
  AirwallexRadarErrorCode2["SSR_NOT_SUPPORTED"] = "SSR_NOT_SUPPORTED";
13765
13770
  })(AirwallexRadarErrorCode || (AirwallexRadarErrorCode = {}));
13766
13771
 
13772
+ // ../core-js/dist/radar/stripe-types.js
13773
+ var StripeRadarErrorCode;
13774
+ (function(StripeRadarErrorCode2) {
13775
+ StripeRadarErrorCode2["SCRIPT_LOAD_FAILED"] = "SCRIPT_LOAD_FAILED";
13776
+ StripeRadarErrorCode2["MISSING_CONFIG"] = "MISSING_CONFIG";
13777
+ StripeRadarErrorCode2["SESSION_CREATE_FAILED"] = "SESSION_CREATE_FAILED";
13778
+ StripeRadarErrorCode2["SESSION_SAVE_FAILED"] = "SESSION_SAVE_FAILED";
13779
+ StripeRadarErrorCode2["RESUME_FAILED"] = "RESUME_FAILED";
13780
+ StripeRadarErrorCode2["NO_API_CLIENT"] = "NO_API_CLIENT";
13781
+ StripeRadarErrorCode2["SSR_NOT_SUPPORTED"] = "SSR_NOT_SUPPORTED";
13782
+ })(StripeRadarErrorCode || (StripeRadarErrorCode = {}));
13783
+
13767
13784
  // ../core-js/dist/payments/types.js
13768
13785
  var PaymentsClientErrorCode;
13769
13786
  (function(PaymentsClientErrorCode2) {
@@ -17056,48 +17073,111 @@ var TagadaSDKBundle = (() => {
17056
17073
  }
17057
17074
  return [];
17058
17075
  }
17059
- function injectScript(script, index) {
17060
- const position = script.position || "body-end";
17061
- const scriptId = "tagada-stepconfig-script-".concat(index);
17062
- if (document.getElementById(scriptId)) {
17063
- return;
17076
+ function classifyLooseChunk(chunk) {
17077
+ if (!chunk || /^<!--[\s\S]*?-->$/.test(chunk)) return null;
17078
+ const looksLikeMarkup = /^</.test(chunk) || /<\/?[a-zA-Z][\w-]*[\s/>]/.test(chunk);
17079
+ return looksLikeMarkup ? { type: "html", html: chunk } : { type: "inline", code: chunk };
17080
+ }
17081
+ function parseScriptContent(content) {
17082
+ const trimmed = content.trim();
17083
+ if (!/<(?:script|noscript)[\s>]/i.test(trimmed)) {
17084
+ return trimmed ? [{ type: "inline", code: trimmed }] : [];
17085
+ }
17086
+ const elements = [];
17087
+ const tagRegex = /<(script|noscript)([^>]*)>([\s\S]*?)<\/\1>/gi;
17088
+ let lastIndex = 0;
17089
+ let match3;
17090
+ while ((match3 = tagRegex.exec(trimmed)) !== null) {
17091
+ const between = classifyLooseChunk(trimmed.slice(lastIndex, match3.index).trim());
17092
+ if (between) elements.push(between);
17093
+ const [, tagName, attrs, body] = match3;
17094
+ if (tagName.toLowerCase() === "noscript") {
17095
+ if (body.trim()) elements.push({ type: "noscript", html: body.trim() });
17096
+ } else {
17097
+ const srcMatch = attrs.match(/src=["']([^"']+)["']/i);
17098
+ if (srcMatch) {
17099
+ elements.push({
17100
+ type: "external",
17101
+ src: srcMatch[1],
17102
+ async: /\basync\b/i.test(attrs),
17103
+ defer: /\bdefer\b/i.test(attrs)
17104
+ });
17105
+ }
17106
+ if (body.trim()) elements.push({ type: "inline", code: body.trim() });
17107
+ }
17108
+ lastIndex = match3.index + match3[0].length;
17064
17109
  }
17065
- let scriptBody = script.content.trim();
17066
- const scriptTagMatch = scriptBody.match(/^<script[^>]*>([\s\S]*)<\/script>$/i);
17067
- if (scriptTagMatch) {
17068
- scriptBody = scriptTagMatch[1].trim();
17069
- }
17070
- if (!scriptBody) return;
17071
- const wrappedScript = "(function() {\n try {\n // Script: " + script.name + "\n" + scriptBody + '\n } catch (error) {\n console.error("[TagadaPay] StepConfig script error:", error);\n }\n})();';
17072
- const scriptElement = document.createElement("script");
17073
- scriptElement.id = scriptId;
17074
- scriptElement.setAttribute("data-tagada-stepconfig-script", "true");
17075
- scriptElement.setAttribute("data-script-name", script.name);
17076
- scriptElement.textContent = wrappedScript;
17110
+ const trailing = classifyLooseChunk(trimmed.slice(lastIndex).trim());
17111
+ if (trailing) elements.push(trailing);
17112
+ return elements;
17113
+ }
17114
+ function injectAtPosition(element, position) {
17077
17115
  switch (position) {
17078
17116
  case "head-start":
17079
- if (document.head.firstChild) {
17080
- document.head.insertBefore(scriptElement, document.head.firstChild);
17081
- } else {
17082
- document.head.appendChild(scriptElement);
17083
- }
17117
+ if (document.head.firstChild) document.head.insertBefore(element, document.head.firstChild);
17118
+ else document.head.appendChild(element);
17084
17119
  break;
17085
17120
  case "head-end":
17086
- document.head.appendChild(scriptElement);
17121
+ document.head.appendChild(element);
17087
17122
  break;
17088
17123
  case "body-start":
17089
- if (document.body.firstChild) {
17090
- document.body.insertBefore(scriptElement, document.body.firstChild);
17091
- } else {
17092
- document.body.appendChild(scriptElement);
17093
- }
17124
+ if (document.body.firstChild) document.body.insertBefore(element, document.body.firstChild);
17125
+ else document.body.appendChild(element);
17094
17126
  break;
17095
17127
  case "body-end":
17096
17128
  default:
17097
- document.body.appendChild(scriptElement);
17129
+ document.body.appendChild(element);
17098
17130
  break;
17099
17131
  }
17100
17132
  }
17133
+ function injectScript(script, index) {
17134
+ const position = script.position || "body-end";
17135
+ const content = script.content.trim();
17136
+ if (!content) return;
17137
+ if (document.querySelector('[data-tagada-stepconfig-index="'.concat(index, '"]'))) {
17138
+ return;
17139
+ }
17140
+ parseScriptContent(content).forEach((element, elemIndex) => {
17141
+ const elemId = "tagada-stepconfig-script-".concat(index, "-").concat(elemIndex);
17142
+ if (element.type === "external") {
17143
+ const el = document.createElement("script");
17144
+ el.id = elemId;
17145
+ el.setAttribute("data-tagada-stepconfig-script", "true");
17146
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
17147
+ el.setAttribute("data-script-name", script.name);
17148
+ el.src = element.src;
17149
+ if (element.async) el.async = true;
17150
+ if (element.defer) el.defer = true;
17151
+ injectAtPosition(el, position);
17152
+ } else if (element.type === "inline") {
17153
+ const el = document.createElement("script");
17154
+ el.id = elemId;
17155
+ el.setAttribute("data-tagada-stepconfig-script", "true");
17156
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
17157
+ el.setAttribute("data-script-name", script.name);
17158
+ el.textContent = "(function() {\n try {\n // Script: " + script.name + "\n" + element.code + '\n } catch (error) {\n console.error("[TagadaPay] StepConfig script error:", error);\n }\n})();';
17159
+ injectAtPosition(el, position);
17160
+ } else if (element.type === "noscript") {
17161
+ const el = document.createElement("noscript");
17162
+ el.id = elemId;
17163
+ el.setAttribute("data-tagada-stepconfig-script", "true");
17164
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
17165
+ el.innerHTML = element.html;
17166
+ injectAtPosition(el, position);
17167
+ } else if (element.type === "html") {
17168
+ const template = document.createElement("template");
17169
+ template.innerHTML = element.html;
17170
+ Array.from(template.content.childNodes).forEach((node) => {
17171
+ if (node.nodeType !== 1) return;
17172
+ const el = node;
17173
+ el.setAttribute("data-tagada-stepconfig-script", "true");
17174
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
17175
+ el.setAttribute("data-script-name", script.name);
17176
+ injectAtPosition(el, position);
17177
+ });
17178
+ }
17179
+ });
17180
+ }
17101
17181
  function injectStepConfigScripts() {
17102
17182
  const scripts = parseStepConfigScripts();
17103
17183
  if (scripts.length === 0) return;