@tagadapay/plugin-sdk 4.0.7 → 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 (42) hide show
  1. package/dist/external-tracker.js +103 -36
  2. package/dist/external-tracker.min.js +2 -2
  3. package/dist/external-tracker.min.js.map +3 -3
  4. package/dist/react/types.d.ts +2 -2
  5. package/dist/tagada-react-sdk-minimal.min.js +2 -2
  6. package/dist/tagada-react-sdk-minimal.min.js.map +3 -3
  7. package/dist/tagada-react-sdk.js +148 -28
  8. package/dist/tagada-react-sdk.min.js +2 -2
  9. package/dist/tagada-react-sdk.min.js.map +4 -4
  10. package/dist/tagada-sdk.js +125 -45
  11. package/dist/tagada-sdk.min.js +2 -2
  12. package/dist/tagada-sdk.min.js.map +4 -4
  13. package/dist/v2/core/funnelClient.js +14 -9
  14. package/dist/v2/core/pixelMapping.d.ts +84 -0
  15. package/dist/v2/core/pixelMapping.js +102 -0
  16. package/dist/v2/core/pixelTracker.d.ts +1 -6
  17. package/dist/v2/core/pixelTracker.js +36 -2
  18. package/dist/v2/core/resources/credits.d.ts +13 -0
  19. package/dist/v2/core/resources/credits.js +7 -0
  20. package/dist/v2/core/resources/offers.d.ts +5 -1
  21. package/dist/v2/core/resources/offers.js +3 -2
  22. package/dist/v2/core/resources/payments.d.ts +1 -0
  23. package/dist/v2/core/resources/payments.js +1 -0
  24. package/dist/v2/core/types.d.ts +17 -2
  25. package/dist/v2/core/utils/authHandoff.d.ts +2 -1
  26. package/dist/v2/index.d.ts +3 -1
  27. package/dist/v2/index.js +4 -1
  28. package/dist/v2/react/components/FunnelScriptInjector.js +42 -7
  29. package/dist/v2/react/hooks/useAuth.d.ts +1 -0
  30. package/dist/v2/react/hooks/useAuth.js +1 -0
  31. package/dist/v2/react/hooks/useClubOffers.d.ts +16 -0
  32. package/dist/v2/react/hooks/useClubOffers.js +29 -3
  33. package/dist/v2/react/hooks/useCustomer.d.ts +1 -0
  34. package/dist/v2/react/hooks/useCustomer.js +1 -0
  35. package/dist/v2/react/hooks/useStore.d.ts +5 -0
  36. package/dist/v2/react/hooks/useStore.js +16 -0
  37. package/dist/v2/react/index.d.ts +1 -0
  38. package/dist/v2/react/index.js +1 -0
  39. package/dist/v2/standalone/index.js +134 -46
  40. package/dist/v2/standalone/payment-service.d.ts +2 -1
  41. package/dist/v2/standalone/payment-service.js +6 -4
  42. package/package.json +2 -3
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TagadaPay External Tracker v4.0.7
2
+ * TagadaPay External Tracker v4.1.0
3
3
  * CDN Bundle - Standalone tracking for external pages (Debug Build)
4
4
  * @license MIT
5
5
  */
@@ -1144,13 +1144,17 @@ var TagadaTrackerBundle = (() => {
1144
1144
  }
1145
1145
  return scripts.length > 0 ? scripts : void 0;
1146
1146
  }
1147
+ function splitIds(rawId) {
1148
+ if (!rawId) return [];
1149
+ return rawId.split(/[;,]/).map((id) => id.trim()).filter((id) => id.length > 0);
1150
+ }
1147
1151
  function splitPixelConfig(px) {
1148
- const idField = "containerId" in px ? "containerId" : "pixelId";
1149
- const rawId = px[idField];
1150
- if (!rawId || !rawId.includes(";") && !rawId.includes(",")) return [px];
1151
- const ids = rawId.split(/[;,]/).map((id) => id.trim()).filter((id) => id.length > 0);
1152
- if (ids.length <= 1) return [px];
1153
- return ids.map((id) => __spreadProps(__spreadValues({}, px), { [idField]: id }));
1152
+ if ("containerId" in px) {
1153
+ const ids2 = splitIds(px.containerId);
1154
+ return ids2.length === 0 ? [px] : ids2.map((id) => __spreadProps(__spreadValues({}, px), { containerId: id }));
1155
+ }
1156
+ const ids = splitIds(px.pixelId);
1157
+ return ids.length === 0 ? [px] : ids.map((id) => __spreadProps(__spreadValues({}, px), { pixelId: id }));
1154
1158
  }
1155
1159
  function getAssignedPixels() {
1156
1160
  const stepConfig = getAssignedStepConfig();
@@ -3572,48 +3576,111 @@ var TagadaTrackerBundle = (() => {
3572
3576
  }
3573
3577
  return [];
3574
3578
  }
3575
- function injectScript(script, index) {
3576
- const position = script.position || "body-end";
3577
- const scriptId = "tagada-stepconfig-script-".concat(index);
3578
- if (document.getElementById(scriptId)) {
3579
- return;
3579
+ function classifyLooseChunk(chunk) {
3580
+ if (!chunk || /^<!--[\s\S]*?-->$/.test(chunk)) return null;
3581
+ const looksLikeMarkup = /^</.test(chunk) || /<\/?[a-zA-Z][\w-]*[\s/>]/.test(chunk);
3582
+ return looksLikeMarkup ? { type: "html", html: chunk } : { type: "inline", code: chunk };
3583
+ }
3584
+ function parseScriptContent(content) {
3585
+ const trimmed = content.trim();
3586
+ if (!/<(?:script|noscript)[\s>]/i.test(trimmed)) {
3587
+ return trimmed ? [{ type: "inline", code: trimmed }] : [];
3588
+ }
3589
+ const elements = [];
3590
+ const tagRegex = /<(script|noscript)([^>]*)>([\s\S]*?)<\/\1>/gi;
3591
+ let lastIndex = 0;
3592
+ let match2;
3593
+ while ((match2 = tagRegex.exec(trimmed)) !== null) {
3594
+ const between = classifyLooseChunk(trimmed.slice(lastIndex, match2.index).trim());
3595
+ if (between) elements.push(between);
3596
+ const [, tagName, attrs, body] = match2;
3597
+ if (tagName.toLowerCase() === "noscript") {
3598
+ if (body.trim()) elements.push({ type: "noscript", html: body.trim() });
3599
+ } else {
3600
+ const srcMatch = attrs.match(/src=["']([^"']+)["']/i);
3601
+ if (srcMatch) {
3602
+ elements.push({
3603
+ type: "external",
3604
+ src: srcMatch[1],
3605
+ async: /\basync\b/i.test(attrs),
3606
+ defer: /\bdefer\b/i.test(attrs)
3607
+ });
3608
+ }
3609
+ if (body.trim()) elements.push({ type: "inline", code: body.trim() });
3610
+ }
3611
+ lastIndex = match2.index + match2[0].length;
3580
3612
  }
3581
- let scriptBody = script.content.trim();
3582
- const scriptTagMatch = scriptBody.match(/^<script[^>]*>([\s\S]*)<\/script>$/i);
3583
- if (scriptTagMatch) {
3584
- scriptBody = scriptTagMatch[1].trim();
3585
- }
3586
- if (!scriptBody) return;
3587
- const wrappedScript = "(function() {\n try {\n // Script: " + script.name + "\n" + scriptBody + '\n } catch (error) {\n console.error("[TagadaPay] StepConfig script error:", error);\n }\n})();';
3588
- const scriptElement = document.createElement("script");
3589
- scriptElement.id = scriptId;
3590
- scriptElement.setAttribute("data-tagada-stepconfig-script", "true");
3591
- scriptElement.setAttribute("data-script-name", script.name);
3592
- scriptElement.textContent = wrappedScript;
3613
+ const trailing = classifyLooseChunk(trimmed.slice(lastIndex).trim());
3614
+ if (trailing) elements.push(trailing);
3615
+ return elements;
3616
+ }
3617
+ function injectAtPosition(element, position) {
3593
3618
  switch (position) {
3594
3619
  case "head-start":
3595
- if (document.head.firstChild) {
3596
- document.head.insertBefore(scriptElement, document.head.firstChild);
3597
- } else {
3598
- document.head.appendChild(scriptElement);
3599
- }
3620
+ if (document.head.firstChild) document.head.insertBefore(element, document.head.firstChild);
3621
+ else document.head.appendChild(element);
3600
3622
  break;
3601
3623
  case "head-end":
3602
- document.head.appendChild(scriptElement);
3624
+ document.head.appendChild(element);
3603
3625
  break;
3604
3626
  case "body-start":
3605
- if (document.body.firstChild) {
3606
- document.body.insertBefore(scriptElement, document.body.firstChild);
3607
- } else {
3608
- document.body.appendChild(scriptElement);
3609
- }
3627
+ if (document.body.firstChild) document.body.insertBefore(element, document.body.firstChild);
3628
+ else document.body.appendChild(element);
3610
3629
  break;
3611
3630
  case "body-end":
3612
3631
  default:
3613
- document.body.appendChild(scriptElement);
3632
+ document.body.appendChild(element);
3614
3633
  break;
3615
3634
  }
3616
3635
  }
3636
+ function injectScript(script, index) {
3637
+ const position = script.position || "body-end";
3638
+ const content = script.content.trim();
3639
+ if (!content) return;
3640
+ if (document.querySelector('[data-tagada-stepconfig-index="'.concat(index, '"]'))) {
3641
+ return;
3642
+ }
3643
+ parseScriptContent(content).forEach((element, elemIndex) => {
3644
+ const elemId = "tagada-stepconfig-script-".concat(index, "-").concat(elemIndex);
3645
+ if (element.type === "external") {
3646
+ const el = document.createElement("script");
3647
+ el.id = elemId;
3648
+ el.setAttribute("data-tagada-stepconfig-script", "true");
3649
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
3650
+ el.setAttribute("data-script-name", script.name);
3651
+ el.src = element.src;
3652
+ if (element.async) el.async = true;
3653
+ if (element.defer) el.defer = true;
3654
+ injectAtPosition(el, position);
3655
+ } else if (element.type === "inline") {
3656
+ const el = document.createElement("script");
3657
+ el.id = elemId;
3658
+ el.setAttribute("data-tagada-stepconfig-script", "true");
3659
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
3660
+ el.setAttribute("data-script-name", script.name);
3661
+ 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})();';
3662
+ injectAtPosition(el, position);
3663
+ } else if (element.type === "noscript") {
3664
+ const el = document.createElement("noscript");
3665
+ el.id = elemId;
3666
+ el.setAttribute("data-tagada-stepconfig-script", "true");
3667
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
3668
+ el.innerHTML = element.html;
3669
+ injectAtPosition(el, position);
3670
+ } else if (element.type === "html") {
3671
+ const template = document.createElement("template");
3672
+ template.innerHTML = element.html;
3673
+ Array.from(template.content.childNodes).forEach((node) => {
3674
+ if (node.nodeType !== 1) return;
3675
+ const el = node;
3676
+ el.setAttribute("data-tagada-stepconfig-script", "true");
3677
+ el.setAttribute("data-tagada-stepconfig-index", String(index));
3678
+ el.setAttribute("data-script-name", script.name);
3679
+ injectAtPosition(el, position);
3680
+ });
3681
+ }
3682
+ });
3683
+ }
3617
3684
  function injectStepConfigScripts() {
3618
3685
  const scripts = parseStepConfigScripts();
3619
3686
  if (scripts.length === 0) return;