@tagadapay/plugin-sdk 3.1.11 → 3.1.22

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 (116) hide show
  1. package/README.md +1129 -1129
  2. package/build-cdn.js +231 -228
  3. package/dist/data/iso3166.d.ts +23 -33
  4. package/dist/data/iso3166.js +134 -198
  5. package/dist/data/languages.d.ts +5 -64
  6. package/dist/data/languages.js +23 -143
  7. package/dist/external-tracker.js +968 -102
  8. package/dist/external-tracker.min.js +2 -2
  9. package/dist/external-tracker.min.js.map +4 -4
  10. package/dist/react/hooks/useISOData.js +1 -1
  11. package/dist/react/hooks/usePaymentPolling.d.ts +3 -3
  12. package/dist/react/hooks/useShippingRates.d.ts +6 -0
  13. package/dist/react/hooks/useShippingRates.js +38 -0
  14. package/dist/react/providers/TagadaProvider.js +5 -5
  15. package/dist/react/services/apiService.d.ts +21 -0
  16. package/dist/react/services/apiService.js +10 -0
  17. package/dist/tagada-sdk.js +2079 -179
  18. package/dist/tagada-sdk.min.js +4 -2
  19. package/dist/tagada-sdk.min.js.map +4 -4
  20. package/dist/v2/core/client.d.ts +4 -2
  21. package/dist/v2/core/client.js +4 -3
  22. package/dist/v2/core/errors.d.ts +75 -0
  23. package/dist/v2/core/errors.js +104 -0
  24. package/dist/v2/core/funnelClient.d.ts +16 -15
  25. package/dist/v2/core/funnelClient.js +1 -1
  26. package/dist/v2/core/index.d.ts +1 -0
  27. package/dist/v2/core/index.js +2 -0
  28. package/dist/v2/core/pixelMapping.d.ts +49 -0
  29. package/dist/v2/core/pixelMapping.js +325 -0
  30. package/dist/v2/core/resources/apiClient.d.ts +2 -0
  31. package/dist/v2/core/resources/apiClient.js +52 -9
  32. package/dist/v2/core/resources/checkout.d.ts +89 -30
  33. package/dist/v2/core/resources/checkout.js +8 -0
  34. package/dist/v2/core/resources/customer.d.ts +20 -19
  35. package/dist/v2/core/resources/funnel.d.ts +17 -17
  36. package/dist/v2/core/resources/payments.d.ts +84 -13
  37. package/dist/v2/core/resources/payments.js +26 -9
  38. package/dist/v2/core/resources/shippingRates.d.ts +15 -0
  39. package/dist/v2/core/resources/shippingRates.js +11 -0
  40. package/dist/v2/core/types.d.ts +50 -12
  41. package/dist/v2/core/types.js +0 -3
  42. package/dist/v2/core/utils/checkout.d.ts +2 -2
  43. package/dist/v2/core/utils/checkout.js +7 -2
  44. package/dist/v2/core/utils/order.d.ts +11 -9
  45. package/dist/v2/core/utils/previewModeIndicator.js +101 -101
  46. package/dist/v2/index.d.ts +4 -2
  47. package/dist/v2/index.js +1 -1
  48. package/dist/v2/react/components/ApplePayButton.js +13 -4
  49. package/dist/v2/react/components/FunnelScriptInjector.js +51 -30
  50. package/dist/v2/react/components/WhopCheckout.d.ts +24 -0
  51. package/dist/v2/react/components/WhopCheckout.js +231 -0
  52. package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +1 -1
  53. package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.d.ts +14 -0
  54. package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.js +181 -0
  55. package/dist/v2/react/hooks/payment-actions/useErrorAction.d.ts +9 -0
  56. package/dist/v2/react/hooks/payment-actions/useErrorAction.js +21 -0
  57. package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.d.ts +14 -0
  58. package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.js +187 -0
  59. package/dist/v2/react/hooks/payment-actions/useKessPayAction.d.ts +11 -0
  60. package/dist/v2/react/hooks/payment-actions/useKessPayAction.js +91 -0
  61. package/dist/v2/react/hooks/payment-actions/useMasterCardAction.d.ts +24 -0
  62. package/dist/v2/react/hooks/payment-actions/useMasterCardAction.js +221 -0
  63. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.d.ts +15 -0
  64. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.js +142 -0
  65. package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.d.ts +3 -0
  66. package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.js +13 -0
  67. package/dist/v2/react/hooks/payment-actions/useRedirectAction.d.ts +10 -0
  68. package/dist/v2/react/hooks/payment-actions/useRedirectAction.js +35 -0
  69. package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.d.ts +14 -0
  70. package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.js +192 -0
  71. package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.d.ts +14 -0
  72. package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.js +81 -0
  73. package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.d.ts +11 -0
  74. package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.js +84 -0
  75. package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.d.ts +14 -0
  76. package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.js +36 -0
  77. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.d.ts +31 -0
  78. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.js +212 -0
  79. package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.d.ts +14 -0
  80. package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.js +207 -0
  81. package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.d.ts +12 -0
  82. package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.js +101 -0
  83. package/dist/v2/react/hooks/useCheckoutQuery.d.ts +6 -0
  84. package/dist/v2/react/hooks/useCheckoutQuery.js +45 -0
  85. package/dist/v2/react/hooks/useFunnel.d.ts +1 -2
  86. package/dist/v2/react/hooks/useGeoLocation.d.ts +2 -1
  87. package/dist/v2/react/hooks/useGeoLocation.js +4 -2
  88. package/dist/v2/react/hooks/useGoogleAutocomplete.js +82 -33
  89. package/dist/v2/react/hooks/useISOData.js +1 -1
  90. package/dist/v2/react/hooks/usePaymentPolling.d.ts +3 -3
  91. package/dist/v2/react/hooks/usePaymentQuery.d.ts +18 -5
  92. package/dist/v2/react/hooks/usePaymentQuery.js +63 -1015
  93. package/dist/v2/react/hooks/usePaymentRetrieve.d.ts +3 -2
  94. package/dist/v2/react/hooks/usePaymentRetrieve.js +3 -1
  95. package/dist/v2/react/hooks/usePixelTracking.d.ts +5 -43
  96. package/dist/v2/react/hooks/usePixelTracking.js +213 -407
  97. package/dist/v2/react/hooks/useShippingRatesQuery.d.ts +6 -0
  98. package/dist/v2/react/hooks/useShippingRatesQuery.js +47 -4
  99. package/dist/v2/react/hooks/useStepConfig.d.ts +2 -8
  100. package/dist/v2/react/hooks/useStepConfig.js +1 -1
  101. package/dist/v2/react/hooks/useWhopPaymentPolling.d.ts +30 -0
  102. package/dist/v2/react/hooks/useWhopPaymentPolling.js +61 -0
  103. package/dist/v2/react/index.d.ts +7 -0
  104. package/dist/v2/react/index.js +4 -0
  105. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.d.ts +2 -1
  106. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +3 -1
  107. package/dist/v2/react/providers/TagadaProvider.js +76 -7
  108. package/dist/v2/standalone/external-tracker.d.ts +52 -46
  109. package/dist/v2/standalone/external-tracker.js +205 -98
  110. package/dist/v2/standalone/index.d.ts +22 -0
  111. package/dist/v2/standalone/index.js +125 -0
  112. package/package.json +112 -112
  113. package/dist/react/utils/__tests__/urlUtils.test.d.ts +0 -1
  114. package/dist/react/utils/__tests__/urlUtils.test.js +0 -189
  115. package/dist/v2/core/__tests__/pathRemapping.test.d.ts +0 -11
  116. package/dist/v2/core/__tests__/pathRemapping.test.js +0 -776
@@ -1,16 +1,18 @@
1
1
  /**
2
- * TagadaPay External Tracker v3.1.11
2
+ * TagadaPay External Tracker v3.1.22
3
3
  * CDN Bundle - Standalone tracking for external pages (Debug Build)
4
4
  * @license MIT
5
5
  */
6
6
  "use strict";
7
7
  var TagadaTrackerBundle = (() => {
8
+ var __create = Object.create;
8
9
  var __defProp = Object.defineProperty;
9
10
  var __defProps = Object.defineProperties;
10
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
12
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
12
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
14
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
15
+ var __getProtoOf = Object.getPrototypeOf;
14
16
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
17
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
16
18
  var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
@@ -33,6 +35,9 @@ var TagadaTrackerBundle = (() => {
33
35
  var __esm = (fn, res) => function __init() {
34
36
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
35
37
  };
38
+ var __commonJS = (cb, mod) => function __require() {
39
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
40
+ };
36
41
  var __export = (target, all3) => {
37
42
  for (var name in all3)
38
43
  __defProp(target, name, { get: all3[name], enumerable: true });
@@ -45,6 +50,14 @@ var TagadaTrackerBundle = (() => {
45
50
  }
46
51
  return to;
47
52
  };
53
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
54
+ // If the importer is in node compatibility mode or this is not an ESM
55
+ // file that has been converted to a CommonJS file using a Babel-
56
+ // compatible transform (i.e. "__esModule" has not been set), then set
57
+ // "default" to the CommonJS "module.exports" for node compatibility.
58
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
59
+ mod
60
+ ));
48
61
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
49
62
  var __await = function(promise, isYieldStar) {
50
63
  this[0] = promise;
@@ -1140,7 +1153,7 @@ var TagadaTrackerBundle = (() => {
1140
1153
  TrackingProvider2["FACEBOOK"] = "facebook";
1141
1154
  TrackingProvider2["TIKTOK"] = "tiktok";
1142
1155
  TrackingProvider2["SNAPCHAT"] = "snapchat";
1143
- TrackingProvider2["META_CONVERSION"] = "meta_conversion";
1156
+ TrackingProvider2["PINTEREST"] = "pinterest";
1144
1157
  TrackingProvider2["GTM"] = "gtm";
1145
1158
  return TrackingProvider2;
1146
1159
  })(TrackingProvider || {});
@@ -1549,9 +1562,365 @@ var TagadaTrackerBundle = (() => {
1549
1562
  }
1550
1563
  });
1551
1564
 
1565
+ // ../../node_modules/.pnpm/path-to-regexp@8.3.0/node_modules/path-to-regexp/dist/index.js
1566
+ var require_dist = __commonJS({
1567
+ "../../node_modules/.pnpm/path-to-regexp@8.3.0/node_modules/path-to-regexp/dist/index.js"(exports) {
1568
+ "use strict";
1569
+ Object.defineProperty(exports, "__esModule", { value: true });
1570
+ exports.PathError = exports.TokenData = void 0;
1571
+ exports.parse = parse;
1572
+ exports.compile = compile;
1573
+ exports.match = match2;
1574
+ exports.pathToRegexp = pathToRegexp;
1575
+ exports.stringify = stringify;
1576
+ var DEFAULT_DELIMITER = "/";
1577
+ var NOOP_VALUE = (value) => value;
1578
+ var ID_START = new RegExp("^[$_\\p{ID_Start}]$", "u");
1579
+ var ID_CONTINUE = new RegExp("^[$\\u200c\\u200d\\p{ID_Continue}]$", "u");
1580
+ var SIMPLE_TOKENS = {
1581
+ // Groups.
1582
+ "{": "{",
1583
+ "}": "}",
1584
+ // Reserved.
1585
+ "(": "(",
1586
+ ")": ")",
1587
+ "[": "[",
1588
+ "]": "]",
1589
+ "+": "+",
1590
+ "?": "?",
1591
+ "!": "!"
1592
+ };
1593
+ function escapeText(str) {
1594
+ return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
1595
+ }
1596
+ function escape(str) {
1597
+ return str.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&");
1598
+ }
1599
+ var TokenData = class {
1600
+ constructor(tokens, originalPath) {
1601
+ this.tokens = tokens;
1602
+ this.originalPath = originalPath;
1603
+ }
1604
+ };
1605
+ exports.TokenData = TokenData;
1606
+ var PathError = class extends TypeError {
1607
+ constructor(message, originalPath) {
1608
+ let text = message;
1609
+ if (originalPath)
1610
+ text += ": ".concat(originalPath);
1611
+ text += "; visit https://git.new/pathToRegexpError for info";
1612
+ super(text);
1613
+ this.originalPath = originalPath;
1614
+ }
1615
+ };
1616
+ exports.PathError = PathError;
1617
+ function parse(str, options = {}) {
1618
+ const { encodePath = NOOP_VALUE } = options;
1619
+ const chars = [...str];
1620
+ const tokens = [];
1621
+ let index = 0;
1622
+ let pos = 0;
1623
+ function name() {
1624
+ let value = "";
1625
+ if (ID_START.test(chars[index])) {
1626
+ do {
1627
+ value += chars[index++];
1628
+ } while (ID_CONTINUE.test(chars[index]));
1629
+ } else if (chars[index] === '"') {
1630
+ let quoteStart = index;
1631
+ while (index++ < chars.length) {
1632
+ if (chars[index] === '"') {
1633
+ index++;
1634
+ quoteStart = 0;
1635
+ break;
1636
+ }
1637
+ if (chars[index] === "\\")
1638
+ index++;
1639
+ value += chars[index];
1640
+ }
1641
+ if (quoteStart) {
1642
+ throw new PathError("Unterminated quote at index ".concat(quoteStart), str);
1643
+ }
1644
+ }
1645
+ if (!value) {
1646
+ throw new PathError("Missing parameter name at index ".concat(index), str);
1647
+ }
1648
+ return value;
1649
+ }
1650
+ while (index < chars.length) {
1651
+ const value = chars[index];
1652
+ const type = SIMPLE_TOKENS[value];
1653
+ if (type) {
1654
+ tokens.push({ type, index: index++, value });
1655
+ } else if (value === "\\") {
1656
+ tokens.push({ type: "escape", index: index++, value: chars[index++] });
1657
+ } else if (value === ":") {
1658
+ tokens.push({ type: "param", index: index++, value: name() });
1659
+ } else if (value === "*") {
1660
+ tokens.push({ type: "wildcard", index: index++, value: name() });
1661
+ } else {
1662
+ tokens.push({ type: "char", index: index++, value });
1663
+ }
1664
+ }
1665
+ tokens.push({ type: "end", index, value: "" });
1666
+ function consumeUntil(endType) {
1667
+ const output = [];
1668
+ while (true) {
1669
+ const token = tokens[pos++];
1670
+ if (token.type === endType)
1671
+ break;
1672
+ if (token.type === "char" || token.type === "escape") {
1673
+ let path = token.value;
1674
+ let cur = tokens[pos];
1675
+ while (cur.type === "char" || cur.type === "escape") {
1676
+ path += cur.value;
1677
+ cur = tokens[++pos];
1678
+ }
1679
+ output.push({
1680
+ type: "text",
1681
+ value: encodePath(path)
1682
+ });
1683
+ continue;
1684
+ }
1685
+ if (token.type === "param" || token.type === "wildcard") {
1686
+ output.push({
1687
+ type: token.type,
1688
+ name: token.value
1689
+ });
1690
+ continue;
1691
+ }
1692
+ if (token.type === "{") {
1693
+ output.push({
1694
+ type: "group",
1695
+ tokens: consumeUntil("}")
1696
+ });
1697
+ continue;
1698
+ }
1699
+ throw new PathError("Unexpected ".concat(token.type, " at index ").concat(token.index, ", expected ").concat(endType), str);
1700
+ }
1701
+ return output;
1702
+ }
1703
+ return new TokenData(consumeUntil("end"), str);
1704
+ }
1705
+ function compile(path, options = {}) {
1706
+ const { encode: encode3 = encodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
1707
+ const data = typeof path === "object" ? path : parse(path, options);
1708
+ const fn = tokensToFunction(data.tokens, delimiter, encode3);
1709
+ return function path2(params = {}) {
1710
+ const [path3, ...missing] = fn(params);
1711
+ if (missing.length) {
1712
+ throw new TypeError("Missing parameters: ".concat(missing.join(", ")));
1713
+ }
1714
+ return path3;
1715
+ };
1716
+ }
1717
+ function tokensToFunction(tokens, delimiter, encode3) {
1718
+ const encoders = tokens.map((token) => tokenToFunction(token, delimiter, encode3));
1719
+ return (data) => {
1720
+ const result = [""];
1721
+ for (const encoder of encoders) {
1722
+ const [value, ...extras] = encoder(data);
1723
+ result[0] += value;
1724
+ result.push(...extras);
1725
+ }
1726
+ return result;
1727
+ };
1728
+ }
1729
+ function tokenToFunction(token, delimiter, encode3) {
1730
+ if (token.type === "text")
1731
+ return () => [token.value];
1732
+ if (token.type === "group") {
1733
+ const fn = tokensToFunction(token.tokens, delimiter, encode3);
1734
+ return (data) => {
1735
+ const [value, ...missing] = fn(data);
1736
+ if (!missing.length)
1737
+ return [value];
1738
+ return [""];
1739
+ };
1740
+ }
1741
+ const encodeValue = encode3 || NOOP_VALUE;
1742
+ if (token.type === "wildcard" && encode3 !== false) {
1743
+ return (data) => {
1744
+ const value = data[token.name];
1745
+ if (value == null)
1746
+ return ["", token.name];
1747
+ if (!Array.isArray(value) || value.length === 0) {
1748
+ throw new TypeError('Expected "'.concat(token.name, '" to be a non-empty array'));
1749
+ }
1750
+ return [
1751
+ value.map((value2, index) => {
1752
+ if (typeof value2 !== "string") {
1753
+ throw new TypeError('Expected "'.concat(token.name, "/").concat(index, '" to be a string'));
1754
+ }
1755
+ return encodeValue(value2);
1756
+ }).join(delimiter)
1757
+ ];
1758
+ };
1759
+ }
1760
+ return (data) => {
1761
+ const value = data[token.name];
1762
+ if (value == null)
1763
+ return ["", token.name];
1764
+ if (typeof value !== "string") {
1765
+ throw new TypeError('Expected "'.concat(token.name, '" to be a string'));
1766
+ }
1767
+ return [encodeValue(value)];
1768
+ };
1769
+ }
1770
+ function match2(path, options = {}) {
1771
+ const { decode = decodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
1772
+ const { regexp, keys } = pathToRegexp(path, options);
1773
+ const decoders = keys.map((key) => {
1774
+ if (decode === false)
1775
+ return NOOP_VALUE;
1776
+ if (key.type === "param")
1777
+ return decode;
1778
+ return (value) => value.split(delimiter).map(decode);
1779
+ });
1780
+ return function match3(input) {
1781
+ const m = regexp.exec(input);
1782
+ if (!m)
1783
+ return false;
1784
+ const path2 = m[0];
1785
+ const params = /* @__PURE__ */ Object.create(null);
1786
+ for (let i = 1; i < m.length; i++) {
1787
+ if (m[i] === void 0)
1788
+ continue;
1789
+ const key = keys[i - 1];
1790
+ const decoder = decoders[i - 1];
1791
+ params[key.name] = decoder(m[i]);
1792
+ }
1793
+ return { path: path2, params };
1794
+ };
1795
+ }
1796
+ function pathToRegexp(path, options = {}) {
1797
+ const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true } = options;
1798
+ const keys = [];
1799
+ const flags = sensitive ? "" : "i";
1800
+ const sources = [];
1801
+ for (const input of pathsToArray(path, [])) {
1802
+ const data = typeof input === "object" ? input : parse(input, options);
1803
+ for (const tokens of flatten(data.tokens, 0, [])) {
1804
+ sources.push(toRegExpSource(tokens, delimiter, keys, data.originalPath));
1805
+ }
1806
+ }
1807
+ let pattern = "^(?:".concat(sources.join("|"), ")");
1808
+ if (trailing)
1809
+ pattern += "(?:".concat(escape(delimiter), "$)?");
1810
+ pattern += end ? "$" : "(?=".concat(escape(delimiter), "|$)");
1811
+ const regexp = new RegExp(pattern, flags);
1812
+ return { regexp, keys };
1813
+ }
1814
+ function pathsToArray(paths, init) {
1815
+ if (Array.isArray(paths)) {
1816
+ for (const p of paths)
1817
+ pathsToArray(p, init);
1818
+ } else {
1819
+ init.push(paths);
1820
+ }
1821
+ return init;
1822
+ }
1823
+ function* flatten(tokens, index, init) {
1824
+ if (index === tokens.length) {
1825
+ return yield init;
1826
+ }
1827
+ const token = tokens[index];
1828
+ if (token.type === "group") {
1829
+ for (const seq of flatten(token.tokens, 0, init.slice())) {
1830
+ yield* __yieldStar(flatten(tokens, index + 1, seq));
1831
+ }
1832
+ } else {
1833
+ init.push(token);
1834
+ }
1835
+ yield* __yieldStar(flatten(tokens, index + 1, init));
1836
+ }
1837
+ function toRegExpSource(tokens, delimiter, keys, originalPath) {
1838
+ let result = "";
1839
+ let backtrack = "";
1840
+ let isSafeSegmentParam = true;
1841
+ for (const token of tokens) {
1842
+ if (token.type === "text") {
1843
+ result += escape(token.value);
1844
+ backtrack += token.value;
1845
+ isSafeSegmentParam || (isSafeSegmentParam = token.value.includes(delimiter));
1846
+ continue;
1847
+ }
1848
+ if (token.type === "param" || token.type === "wildcard") {
1849
+ if (!isSafeSegmentParam && !backtrack) {
1850
+ throw new PathError('Missing text before "'.concat(token.name, '" ').concat(token.type), originalPath);
1851
+ }
1852
+ if (token.type === "param") {
1853
+ result += "(".concat(negate(delimiter, isSafeSegmentParam ? "" : backtrack), "+)");
1854
+ } else {
1855
+ result += "([\\s\\S]+)";
1856
+ }
1857
+ keys.push(token);
1858
+ backtrack = "";
1859
+ isSafeSegmentParam = false;
1860
+ continue;
1861
+ }
1862
+ }
1863
+ return result;
1864
+ }
1865
+ function negate(delimiter, backtrack) {
1866
+ if (backtrack.length < 2) {
1867
+ if (delimiter.length < 2)
1868
+ return "[^".concat(escape(delimiter + backtrack), "]");
1869
+ return "(?:(?!".concat(escape(delimiter), ")[^").concat(escape(backtrack), "])");
1870
+ }
1871
+ if (delimiter.length < 2) {
1872
+ return "(?:(?!".concat(escape(backtrack), ")[^").concat(escape(delimiter), "])");
1873
+ }
1874
+ return "(?:(?!".concat(escape(backtrack), "|").concat(escape(delimiter), ")[\\s\\S])");
1875
+ }
1876
+ function stringifyTokens(tokens) {
1877
+ let value = "";
1878
+ let i = 0;
1879
+ function name(value2) {
1880
+ const isSafe = isNameSafe(value2) && isNextNameSafe(tokens[i]);
1881
+ return isSafe ? value2 : JSON.stringify(value2);
1882
+ }
1883
+ while (i < tokens.length) {
1884
+ const token = tokens[i++];
1885
+ if (token.type === "text") {
1886
+ value += escapeText(token.value);
1887
+ continue;
1888
+ }
1889
+ if (token.type === "group") {
1890
+ value += "{".concat(stringifyTokens(token.tokens), "}");
1891
+ continue;
1892
+ }
1893
+ if (token.type === "param") {
1894
+ value += ":".concat(name(token.name));
1895
+ continue;
1896
+ }
1897
+ if (token.type === "wildcard") {
1898
+ value += "*".concat(name(token.name));
1899
+ continue;
1900
+ }
1901
+ throw new TypeError("Unknown token type: ".concat(token.type));
1902
+ }
1903
+ return value;
1904
+ }
1905
+ function stringify(data) {
1906
+ return stringifyTokens(data.tokens);
1907
+ }
1908
+ function isNameSafe(name) {
1909
+ const [first, ...rest] = name;
1910
+ return ID_START.test(first) && rest.every((char) => ID_CONTINUE.test(char));
1911
+ }
1912
+ function isNextNameSafe(token) {
1913
+ if (token && token.type === "text")
1914
+ return !ID_CONTINUE.test(token.value[0]);
1915
+ return true;
1916
+ }
1917
+ }
1918
+ });
1919
+
1552
1920
  // src/v2/standalone/external-tracker.ts
1553
1921
  var external_tracker_exports = {};
1554
1922
  __export(external_tracker_exports, {
1923
+ TRACKER_VERSION: () => TRACKER_VERSION,
1555
1924
  TagadaExternalTracker: () => TagadaExternalTracker,
1556
1925
  TagadaTracker: () => TagadaTracker
1557
1926
  });
@@ -2160,8 +2529,8 @@ var TagadaTrackerBundle = (() => {
2160
2529
  "%20": "+",
2161
2530
  "%00": "\0"
2162
2531
  };
2163
- return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
2164
- return charMap[match];
2532
+ return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match2) {
2533
+ return charMap[match2];
2165
2534
  });
2166
2535
  }
2167
2536
  function AxiosURLSearchParams(params, options) {
@@ -2340,8 +2709,8 @@ var TagadaTrackerBundle = (() => {
2340
2709
 
2341
2710
  // ../../node_modules/.pnpm/axios@1.13.2/node_modules/axios/lib/helpers/formDataToJSON.js
2342
2711
  function parsePropPath(name) {
2343
- return utils_default.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
2344
- return match[0] === "[]" ? "" : match[1] || match[0];
2712
+ return utils_default.matchAll(/\w+|\[(\w*)]/g, name).map((match2) => {
2713
+ return match2[0] === "[]" ? "" : match2[1] || match2[0];
2345
2714
  });
2346
2715
  }
2347
2716
  function arrayToObject(arr) {
@@ -2559,9 +2928,9 @@ var TagadaTrackerBundle = (() => {
2559
2928
  function parseTokens(str) {
2560
2929
  const tokens = /* @__PURE__ */ Object.create(null);
2561
2930
  const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
2562
- let match;
2563
- while (match = tokensRE.exec(str)) {
2564
- tokens[match[1]] = match[2];
2931
+ let match2;
2932
+ while (match2 = tokensRE.exec(str)) {
2933
+ tokens[match2[1]] = match2[2];
2565
2934
  }
2566
2935
  return tokens;
2567
2936
  }
@@ -2820,8 +3189,8 @@ var TagadaTrackerBundle = (() => {
2820
3189
 
2821
3190
  // ../../node_modules/.pnpm/axios@1.13.2/node_modules/axios/lib/helpers/parseProtocol.js
2822
3191
  function parseProtocol(url) {
2823
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2824
- return match && match[1] || "";
3192
+ const match2 = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
3193
+ return match2 && match2[1] || "";
2825
3194
  }
2826
3195
 
2827
3196
  // ../../node_modules/.pnpm/axios@1.13.2/node_modules/axios/lib/helpers/speedometer.js
@@ -2965,8 +3334,8 @@ var TagadaTrackerBundle = (() => {
2965
3334
  },
2966
3335
  read(name) {
2967
3336
  if (typeof document === "undefined") return null;
2968
- const match = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
2969
- return match ? decodeURIComponent(match[1]) : null;
3337
+ const match2 = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
3338
+ return match2 ? decodeURIComponent(match2[1]) : null;
2970
3339
  },
2971
3340
  remove(name) {
2972
3341
  this.write(name, "", Date.now() - 864e5, "/");
@@ -4177,6 +4546,75 @@ var TagadaTrackerBundle = (() => {
4177
4546
  mergeConfig: mergeConfig2
4178
4547
  } = axios_default;
4179
4548
 
4549
+ // src/v2/core/errors.ts
4550
+ var TagadaErrorCode = {
4551
+ NETWORK_ERROR: "network_error",
4552
+ API_ERROR: "api_error",
4553
+ AUTH_REQUIRED: "auth_required",
4554
+ TOKEN_EXPIRED: "token_expired",
4555
+ NOT_FOUND: "not_found",
4556
+ VALIDATION_ERROR: "validation_error",
4557
+ CIRCUIT_BREAKER: "circuit_breaker",
4558
+ PAYMENT_FAILED: "payment_failed",
4559
+ CARD_DECLINED: "card_declined",
4560
+ SESSION_EXPIRED: "session_expired",
4561
+ RATE_LIMITED: "rate_limited",
4562
+ TIMEOUT: "timeout",
4563
+ UNKNOWN: "unknown"
4564
+ };
4565
+ var TagadaError = class extends Error {
4566
+ constructor(message, options) {
4567
+ var _a;
4568
+ super(message);
4569
+ this.name = "TagadaError";
4570
+ this.code = options.code;
4571
+ this.statusCode = options.statusCode;
4572
+ this.retryable = (_a = options.retryable) != null ? _a : false;
4573
+ this.details = options.details;
4574
+ Object.setPrototypeOf(this, new.target.prototype);
4575
+ }
4576
+ };
4577
+ var TagadaApiError = class extends TagadaError {
4578
+ constructor(message, statusCode, options) {
4579
+ var _a, _b;
4580
+ super(message, {
4581
+ code: (_a = options == null ? void 0 : options.code) != null ? _a : TagadaErrorCode.API_ERROR,
4582
+ statusCode,
4583
+ retryable: (_b = options == null ? void 0 : options.retryable) != null ? _b : statusCode >= 500,
4584
+ details: options == null ? void 0 : options.details
4585
+ });
4586
+ this.name = "TagadaApiError";
4587
+ }
4588
+ };
4589
+ var TagadaNetworkError = class extends TagadaError {
4590
+ constructor(message = "Network request failed") {
4591
+ super(message, {
4592
+ code: TagadaErrorCode.NETWORK_ERROR,
4593
+ retryable: true
4594
+ });
4595
+ this.name = "TagadaNetworkError";
4596
+ }
4597
+ };
4598
+ var TagadaAuthError = class extends TagadaError {
4599
+ constructor(message = "Authentication required", statusCode = 401) {
4600
+ super(message, {
4601
+ code: TagadaErrorCode.AUTH_REQUIRED,
4602
+ statusCode,
4603
+ retryable: false
4604
+ });
4605
+ this.name = "TagadaAuthError";
4606
+ }
4607
+ };
4608
+ var TagadaCircuitBreakerError = class extends TagadaError {
4609
+ constructor(message) {
4610
+ super(message, {
4611
+ code: TagadaErrorCode.CIRCUIT_BREAKER,
4612
+ retryable: false
4613
+ });
4614
+ this.name = "TagadaCircuitBreakerError";
4615
+ }
4616
+ };
4617
+
4180
4618
  // src/v2/core/resources/apiClient.ts
4181
4619
  var ApiClient = class {
4182
4620
  // Max 30 requests per endpoint in window
@@ -4234,12 +4672,18 @@ var TagadaTrackerBundle = (() => {
4234
4672
  }
4235
4673
  );
4236
4674
  this.axios.interceptors.response.use(
4237
- (response) => {
4238
- return response;
4239
- },
4675
+ (response) => response,
4240
4676
  (error) => {
4241
4677
  console.error("[SDK] Response error:", error.message);
4242
- return Promise.reject(error instanceof Error ? error : new Error(String(error)));
4678
+ if (error instanceof TagadaError) {
4679
+ return Promise.reject(error);
4680
+ }
4681
+ if (axios_default.isAxiosError(error)) {
4682
+ return Promise.reject(this.toTagadaError(error));
4683
+ }
4684
+ return Promise.reject(
4685
+ error instanceof Error ? error : new Error(String(error))
4686
+ );
4243
4687
  }
4244
4688
  );
4245
4689
  }
@@ -4305,30 +4749,66 @@ var TagadaTrackerBundle = (() => {
4305
4749
  // Circuit Breaker Implementation
4306
4750
  checkRequestLimit(key) {
4307
4751
  const now = Date.now();
4308
- const history = this.requestHistory.get(key);
4309
- if (!history) {
4752
+ const history2 = this.requestHistory.get(key);
4753
+ if (!history2) {
4310
4754
  this.requestHistory.set(key, { count: 1, firstRequestTime: now });
4311
4755
  return;
4312
4756
  }
4313
- if (now - history.firstRequestTime > this.WINDOW_MS) {
4757
+ if (now - history2.firstRequestTime > this.WINDOW_MS) {
4314
4758
  this.requestHistory.set(key, { count: 1, firstRequestTime: now });
4315
4759
  return;
4316
4760
  }
4317
- history.count++;
4318
- if (history.count > this.MAX_REQUESTS) {
4319
- const error = new Error("Circuit Breaker: Too many requests to ".concat(key, " (").concat(history.count, " in ").concat(this.WINDOW_MS, "ms)"));
4320
- error.isCircuitBreaker = true;
4321
- throw error;
4761
+ history2.count++;
4762
+ if (history2.count > this.MAX_REQUESTS) {
4763
+ throw new TagadaCircuitBreakerError(
4764
+ "Circuit Breaker: Too many requests to ".concat(key, " (").concat(history2.count, " in ").concat(this.WINDOW_MS, "ms)")
4765
+ );
4322
4766
  }
4323
4767
  }
4324
4768
  cleanupHistory() {
4325
4769
  const now = Date.now();
4326
- for (const [key, history] of this.requestHistory.entries()) {
4327
- if (now - history.firstRequestTime > this.WINDOW_MS) {
4770
+ for (const [key, history2] of this.requestHistory.entries()) {
4771
+ if (now - history2.firstRequestTime > this.WINDOW_MS) {
4328
4772
  this.requestHistory.delete(key);
4329
4773
  }
4330
4774
  }
4331
4775
  }
4776
+ /** Convert an AxiosError into the appropriate TagadaError subclass. */
4777
+ toTagadaError(error) {
4778
+ var _a, _b, _c, _d, _e;
4779
+ const status = (_a = error.response) == null ? void 0 : _a.status;
4780
+ const data = (_b = error.response) == null ? void 0 : _b.data;
4781
+ const serverMessage = (_d = (_c = data == null ? void 0 : data.message) != null ? _c : data == null ? void 0 : data.error) != null ? _d : error.message;
4782
+ if (!error.response) {
4783
+ if (error.code === "ECONNABORTED") {
4784
+ return new TagadaApiError("Request timed out", 0, {
4785
+ code: TagadaErrorCode.TIMEOUT,
4786
+ retryable: true
4787
+ });
4788
+ }
4789
+ return new TagadaNetworkError(serverMessage);
4790
+ }
4791
+ if (status === 401 || status === 403) {
4792
+ return new TagadaAuthError(serverMessage, status);
4793
+ }
4794
+ if (status === 429) {
4795
+ return new TagadaApiError(serverMessage, 429, {
4796
+ code: TagadaErrorCode.RATE_LIMITED,
4797
+ retryable: true
4798
+ });
4799
+ }
4800
+ if (status === 404) {
4801
+ return new TagadaApiError(serverMessage, 404, {
4802
+ code: TagadaErrorCode.NOT_FOUND,
4803
+ retryable: false
4804
+ });
4805
+ }
4806
+ return new TagadaApiError(serverMessage, status != null ? status : 0, {
4807
+ code: (_e = data == null ? void 0 : data.code) != null ? _e : TagadaErrorCode.API_ERROR,
4808
+ details: data,
4809
+ retryable: (status != null ? status : 0) >= 500
4810
+ });
4811
+ }
4332
4812
  };
4333
4813
 
4334
4814
  // ../../node_modules/.pnpm/@ua-parser-js+pro-enterprise@2.0.6/node_modules/@ua-parser-js/pro-enterprise/src/main/ua-parser.mjs
@@ -4497,7 +4977,7 @@ var TagadaTrackerBundle = (() => {
4497
4977
  };
4498
4978
  var rgxMapper = function(ua, arrays) {
4499
4979
  if (!ua || !arrays) return;
4500
- var i = 0, j, k, p, q, matches, match;
4980
+ var i = 0, j, k, p, q, matches, match2;
4501
4981
  while (i < arrays.length && !matches) {
4502
4982
  var regex = arrays[i], props = arrays[i + 1];
4503
4983
  j = k = 0;
@@ -4508,34 +4988,34 @@ var TagadaTrackerBundle = (() => {
4508
4988
  matches = regex[j++].exec(ua);
4509
4989
  if (!!matches) {
4510
4990
  for (p = 0; p < props.length; p++) {
4511
- match = matches[++k];
4991
+ match2 = matches[++k];
4512
4992
  q = props[p];
4513
4993
  if (typeof q === TYPEOF.OBJECT && q.length > 0) {
4514
4994
  if (q.length === 2) {
4515
4995
  if (typeof q[1] == TYPEOF.FUNCTION) {
4516
- this[q[0]] = q[1].call(this, match);
4996
+ this[q[0]] = q[1].call(this, match2);
4517
4997
  } else {
4518
4998
  this[q[0]] = q[1];
4519
4999
  }
4520
5000
  } else if (q.length >= 3) {
4521
5001
  if (typeof q[1] === TYPEOF.FUNCTION && !(q[1].exec && q[1].test)) {
4522
5002
  if (q.length > 3) {
4523
- this[q[0]] = match ? q[1].apply(this, q.slice(2)) : void 0;
5003
+ this[q[0]] = match2 ? q[1].apply(this, q.slice(2)) : void 0;
4524
5004
  } else {
4525
- this[q[0]] = match ? q[1].call(this, match, q[2]) : void 0;
5005
+ this[q[0]] = match2 ? q[1].call(this, match2, q[2]) : void 0;
4526
5006
  }
4527
5007
  } else {
4528
5008
  if (q.length == 3) {
4529
- this[q[0]] = match ? match.replace(q[1], q[2]) : void 0;
5009
+ this[q[0]] = match2 ? match2.replace(q[1], q[2]) : void 0;
4530
5010
  } else if (q.length == 4) {
4531
- this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : void 0;
5011
+ this[q[0]] = match2 ? q[3].call(this, match2.replace(q[1], q[2])) : void 0;
4532
5012
  } else if (q.length > 4) {
4533
- this[q[0]] = match ? q[3].apply(this, [match.replace(q[1], q[2])].concat(q.slice(4))) : void 0;
5013
+ this[q[0]] = match2 ? q[3].apply(this, [match2.replace(q[1], q[2])].concat(q.slice(4))) : void 0;
4534
5014
  }
4535
5015
  }
4536
5016
  }
4537
5017
  } else {
4538
- this[q] = match ? match : void 0;
5018
+ this[q] = match2 ? match2 : void 0;
4539
5019
  }
4540
5020
  }
4541
5021
  }
@@ -8652,7 +9132,7 @@ var TagadaTrackerBundle = (() => {
8652
9132
  }
8653
9133
  }
8654
9134
  updateSessionState(response, sessionData) {
8655
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
9135
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
8656
9136
  if (response.store) {
8657
9137
  const storeData = response.store;
8658
9138
  const storeConfig = __spreadProps(__spreadValues({}, response.store), {
@@ -8690,8 +9170,10 @@ var TagadaTrackerBundle = (() => {
8690
9170
  customer: (_g = response.customer) != null ? _g : null,
8691
9171
  auth: authState
8692
9172
  });
8693
- if (this.funnel && sessionData.customerId && ((_h = response.store) == null ? void 0 : _h.id)) {
8694
- const accountId = response.store.accountId || ((_i = this.state.pluginConfig) == null ? void 0 : _i.accountId) || sessionData.accountId || "";
9173
+ const funnelFeature = (_h = this.config.features) == null ? void 0 : _h.funnel;
9174
+ const skipAutoInit = typeof funnelFeature === "object" && funnelFeature.skipAutoInit;
9175
+ if (this.funnel && !skipAutoInit && sessionData.customerId && ((_i = response.store) == null ? void 0 : _i.id)) {
9176
+ const accountId = response.store.accountId || ((_j = this.state.pluginConfig) == null ? void 0 : _j.accountId) || sessionData.accountId || "";
8695
9177
  if (accountId) {
8696
9178
  const urlParams = new URLSearchParams(typeof window !== "undefined" ? window.location.search : "");
8697
9179
  const funnelId = urlParams.get("funnelId") || void 0;
@@ -9017,19 +9499,275 @@ var TagadaTrackerBundle = (() => {
9017
9499
  }
9018
9500
  };
9019
9501
 
9502
+ // src/v2/standalone/index.ts
9503
+ init_funnelClient();
9504
+
9505
+ // src/data/iso3166.ts
9506
+ var GEODATA_CDN_BASE = "https://cvwnizdbugpz6jwk.public.blob.vercel-storage.com/geodata/v1";
9507
+ var countriesCache = /* @__PURE__ */ new Map();
9508
+ var regionsCache = /* @__PURE__ */ new Map();
9509
+ var inflightCountries = /* @__PURE__ */ new Map();
9510
+ var inflightRegions = /* @__PURE__ */ new Map();
9511
+ async function fetchCountriesRaw(language) {
9512
+ const cached = countriesCache.get(language);
9513
+ if (cached) return cached;
9514
+ let inflight = inflightCountries.get(language);
9515
+ if (inflight) return inflight;
9516
+ inflight = (async () => {
9517
+ const url = "".concat(GEODATA_CDN_BASE, "/").concat(language, "/countries.json");
9518
+ const res = await fetch(url);
9519
+ if (!res.ok) throw new Error("Geodata fetch failed: ".concat(url, " (").concat(res.status, ")"));
9520
+ const data = await res.json();
9521
+ countriesCache.set(language, data);
9522
+ inflightCountries.delete(language);
9523
+ return data;
9524
+ })();
9525
+ inflightCountries.set(language, inflight);
9526
+ return inflight;
9527
+ }
9528
+ async function fetchRegionsRaw(language) {
9529
+ const cached = regionsCache.get(language);
9530
+ if (cached) return cached;
9531
+ let inflight = inflightRegions.get(language);
9532
+ if (inflight) return inflight;
9533
+ inflight = (async () => {
9534
+ const url = "".concat(GEODATA_CDN_BASE, "/").concat(language, "/regions.json");
9535
+ const res = await fetch(url);
9536
+ if (!res.ok) throw new Error("Geodata fetch failed: ".concat(url, " (").concat(res.status, ")"));
9537
+ const data = await res.json();
9538
+ regionsCache.set(language, data);
9539
+ inflightRegions.delete(language);
9540
+ return data;
9541
+ })();
9542
+ inflightRegions.set(language, inflight);
9543
+ return inflight;
9544
+ }
9545
+ async function ensureGeoDataLoaded(language = "en") {
9546
+ await Promise.all([fetchCountriesRaw(language), fetchRegionsRaw(language)]);
9547
+ }
9548
+ if (typeof globalThis !== "undefined" && typeof fetch !== "undefined") {
9549
+ ensureGeoDataLoaded("en").catch(() => {
9550
+ });
9551
+ }
9552
+
9553
+ // src/v2/core/googleAutocomplete.ts
9554
+ var GoogleAutocompleteCore = class {
9555
+ /**
9556
+ * Initialize Google Places API
9557
+ */
9558
+ static initialize(apiKey) {
9559
+ var _a, _b;
9560
+ this.apiKey = apiKey;
9561
+ if (typeof window !== "undefined" && ((_b = (_a = window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.places)) {
9562
+ this.service = new window.google.maps.places.AutocompleteService();
9563
+ }
9564
+ }
9565
+ /**
9566
+ * Search for places
9567
+ */
9568
+ static async searchPlaces(input, options = {}) {
9569
+ if (!this.service || !input.trim()) {
9570
+ return [];
9571
+ }
9572
+ return new Promise((resolve, reject) => {
9573
+ this.service.getPlacePredictions(
9574
+ {
9575
+ input,
9576
+ types: options.types || ["address"],
9577
+ componentRestrictions: options.componentRestrictions
9578
+ },
9579
+ (predictions, status) => {
9580
+ var _a, _b, _c;
9581
+ if (status === ((_c = (_b = (_a = window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.places) == null ? void 0 : _c.PlacesServiceStatus.OK) && predictions) {
9582
+ resolve(predictions);
9583
+ } else {
9584
+ resolve([]);
9585
+ }
9586
+ }
9587
+ );
9588
+ });
9589
+ }
9590
+ /**
9591
+ * Get place details
9592
+ */
9593
+ static async getPlaceDetails(placeId) {
9594
+ var _a, _b;
9595
+ if (typeof window === "undefined" || !((_b = (_a = window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.places)) {
9596
+ return null;
9597
+ }
9598
+ return new Promise((resolve, reject) => {
9599
+ const service = new window.google.maps.places.PlacesService(
9600
+ document.createElement("div")
9601
+ );
9602
+ service.getDetails(
9603
+ {
9604
+ placeId,
9605
+ fields: ["place_id", "formatted_address", "address_components", "geometry"]
9606
+ },
9607
+ (place, status) => {
9608
+ var _a2, _b2, _c;
9609
+ if (status === ((_c = (_b2 = (_a2 = window.google) == null ? void 0 : _a2.maps) == null ? void 0 : _b2.places) == null ? void 0 : _c.PlacesServiceStatus.OK) && place) {
9610
+ resolve(place);
9611
+ } else {
9612
+ resolve(null);
9613
+ }
9614
+ }
9615
+ );
9616
+ });
9617
+ }
9618
+ /**
9619
+ * Extract address components from place details
9620
+ */
9621
+ static extractAddressComponents(placeDetails) {
9622
+ const components = {};
9623
+ for (const component of placeDetails.address_components) {
9624
+ const types = component.types;
9625
+ if (types.includes("street_number")) {
9626
+ components.streetNumber = component.long_name;
9627
+ } else if (types.includes("route")) {
9628
+ components.route = component.long_name;
9629
+ } else if (types.includes("locality")) {
9630
+ components.city = component.long_name;
9631
+ components.locality = component.long_name;
9632
+ } else if (types.includes("administrative_area_level_2")) {
9633
+ components.administrativeAreaLevel2 = component.short_name;
9634
+ components.administrativeAreaLevel2Long = component.long_name;
9635
+ if (!components.city) {
9636
+ components.city = component.long_name;
9637
+ components.locality = component.long_name;
9638
+ }
9639
+ } else if (types.includes("administrative_area_level_1")) {
9640
+ components.state = component.long_name;
9641
+ components.administrativeAreaLevel1 = component.short_name;
9642
+ components.administrativeAreaLevel1Long = component.long_name;
9643
+ } else if (types.includes("postal_code")) {
9644
+ components.postalCode = component.long_name;
9645
+ } else if (types.includes("country")) {
9646
+ components.country = component.long_name;
9647
+ components.countryCode = component.short_name;
9648
+ components.iso = component.short_name;
9649
+ }
9650
+ }
9651
+ if (!components.administrativeAreaLevel1 && components.administrativeAreaLevel2) {
9652
+ components.state = components.administrativeAreaLevel2Long || components.administrativeAreaLevel2;
9653
+ components.administrativeAreaLevel1 = components.administrativeAreaLevel2;
9654
+ components.administrativeAreaLevel1Long = components.administrativeAreaLevel2Long;
9655
+ }
9656
+ return components;
9657
+ }
9658
+ };
9659
+ GoogleAutocompleteCore.apiKey = null;
9660
+ GoogleAutocompleteCore.service = null;
9661
+
9020
9662
  // src/v2/standalone/index.ts
9021
9663
  init_funnel();
9022
9664
 
9023
9665
  // src/v2/core/utils/index.ts
9024
9666
  init_sessionStorage();
9025
9667
 
9668
+ // src/v2/core/pathRemapping.ts
9669
+ var import_path_to_regexp = __toESM(require_dist());
9670
+ var internalPathCache = void 0;
9671
+ var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
9672
+ var originalPushState = isBrowser ? history.pushState.bind(history) : null;
9673
+ var originalReplaceState = isBrowser ? history.replaceState.bind(history) : null;
9674
+ function clearCache() {
9675
+ internalPathCache = void 0;
9676
+ }
9677
+ if (isBrowser) {
9678
+ window.addEventListener("popstate", clearCache);
9679
+ window.addEventListener("hashchange", clearCache);
9680
+ history.pushState = function(...args) {
9681
+ clearCache();
9682
+ return originalPushState.apply(this, args);
9683
+ };
9684
+ history.replaceState = function(...args) {
9685
+ clearCache();
9686
+ return originalReplaceState.apply(this, args);
9687
+ };
9688
+ }
9689
+
9026
9690
  // src/v2/standalone/index.ts
9691
+ function parseStepConfigScripts() {
9692
+ if (typeof window === "undefined" || typeof document === "undefined") {
9693
+ return [];
9694
+ }
9695
+ const stepConfig = getAssignedStepConfig();
9696
+ if (stepConfig == null ? void 0 : stepConfig.scripts) {
9697
+ return stepConfig.scripts.filter((s) => s.enabled);
9698
+ }
9699
+ return [];
9700
+ }
9701
+ function injectScript(script, index) {
9702
+ const position = script.position || "body-end";
9703
+ const scriptId = "tagada-stepconfig-script-".concat(index);
9704
+ if (document.getElementById(scriptId)) {
9705
+ return;
9706
+ }
9707
+ let scriptBody = script.content.trim();
9708
+ const scriptTagMatch = scriptBody.match(/^<script[^>]*>([\s\S]*)<\/script>$/i);
9709
+ if (scriptTagMatch) {
9710
+ scriptBody = scriptTagMatch[1].trim();
9711
+ }
9712
+ if (!scriptBody) return;
9713
+ const wrappedScript = "(function() {\n try {\n // Script: " + script.name + "\n" + scriptBody + '\n } catch (error) {\n console.error("[TagadaPay] StepConfig script error:", error);\n }\n})();';
9714
+ const scriptElement = document.createElement("script");
9715
+ scriptElement.id = scriptId;
9716
+ scriptElement.setAttribute("data-tagada-stepconfig-script", "true");
9717
+ scriptElement.setAttribute("data-script-name", script.name);
9718
+ scriptElement.textContent = wrappedScript;
9719
+ switch (position) {
9720
+ case "head-start":
9721
+ if (document.head.firstChild) {
9722
+ document.head.insertBefore(scriptElement, document.head.firstChild);
9723
+ } else {
9724
+ document.head.appendChild(scriptElement);
9725
+ }
9726
+ break;
9727
+ case "head-end":
9728
+ document.head.appendChild(scriptElement);
9729
+ break;
9730
+ case "body-start":
9731
+ if (document.body.firstChild) {
9732
+ document.body.insertBefore(scriptElement, document.body.firstChild);
9733
+ } else {
9734
+ document.body.appendChild(scriptElement);
9735
+ }
9736
+ break;
9737
+ case "body-end":
9738
+ default:
9739
+ document.body.appendChild(scriptElement);
9740
+ break;
9741
+ }
9742
+ }
9743
+ function injectStepConfigScripts() {
9744
+ const scripts = parseStepConfigScripts();
9745
+ if (scripts.length === 0) return;
9746
+ scripts.forEach((script, index) => {
9747
+ injectScript(script, index);
9748
+ });
9749
+ }
9750
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
9751
+ const runInjection = () => {
9752
+ if (document.body) {
9753
+ injectStepConfigScripts();
9754
+ } else {
9755
+ document.addEventListener("DOMContentLoaded", injectStepConfigScripts, { once: true });
9756
+ }
9757
+ };
9758
+ if ("requestIdleCallback" in window) {
9759
+ window.requestIdleCallback(runInjection, { timeout: 100 });
9760
+ } else {
9761
+ setTimeout(runInjection, 0);
9762
+ }
9763
+ }
9027
9764
  function createTagadaClient(config = {}) {
9028
9765
  return new TagadaClient(config);
9029
9766
  }
9030
9767
 
9031
9768
  // src/v2/standalone/external-tracker.ts
9032
9769
  init_tokenStorage();
9770
+ var TRACKER_VERSION = "1.0.0";
9033
9771
  function getUrlParam(name) {
9034
9772
  if (typeof window === "undefined") return null;
9035
9773
  const params = new URLSearchParams(window.location.search);
@@ -9040,58 +9778,133 @@ var TagadaTrackerBundle = (() => {
9040
9778
  console.log("[TagadaTracker]", ...args);
9041
9779
  }
9042
9780
  }
9781
+ function warn(...args) {
9782
+ console.warn("[TagadaTracker]", ...args);
9783
+ }
9784
+ function validate(config) {
9785
+ if (!config.storeId || typeof config.storeId !== "string") {
9786
+ throw new Error("TagadaTracker: storeId is required and must be a non-empty string.");
9787
+ }
9788
+ if (!config.accountId || typeof config.accountId !== "string") {
9789
+ throw new Error("TagadaTracker: accountId is required and must be a non-empty string.");
9790
+ }
9791
+ if (!config.stepId || typeof config.stepId !== "string") {
9792
+ throw new Error("TagadaTracker: stepId is required and must be a non-empty string.");
9793
+ }
9794
+ if (config.apiBaseUrl) {
9795
+ try {
9796
+ new URL(config.apiBaseUrl);
9797
+ } catch (e) {
9798
+ throw new Error('TagadaTracker: apiBaseUrl is not a valid URL: "'.concat(config.apiBaseUrl, '"'));
9799
+ }
9800
+ }
9801
+ }
9802
+ async function retryWithBackoff(fn, maxRetries, debug) {
9803
+ let lastError;
9804
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
9805
+ try {
9806
+ return await fn();
9807
+ } catch (err) {
9808
+ lastError = err instanceof Error ? err : new Error(String(err));
9809
+ if (attempt < maxRetries) {
9810
+ const delay = Math.min(1e3 * 2 ** attempt, 8e3);
9811
+ log(debug, "Retry ".concat(attempt + 1, "/").concat(maxRetries, " in ").concat(delay, "ms..."));
9812
+ await new Promise((r) => setTimeout(r, delay));
9813
+ }
9814
+ }
9815
+ }
9816
+ throw lastError;
9817
+ }
9043
9818
  var TagadaExternalTracker = class {
9044
9819
  constructor() {
9045
9820
  this.config = null;
9046
9821
  this.client = null;
9047
9822
  this.initialized = false;
9048
9823
  this.initializing = false;
9824
+ this.unsubscribe = null;
9825
+ /** Tracker version */
9826
+ this.version = TRACKER_VERSION;
9049
9827
  }
9050
9828
  /**
9051
- * Initialize the tracker using SDK infrastructure
9829
+ * Initialize the tracker.
9830
+ * When `onError` is provided, errors are passed to the callback and init()
9831
+ * resolves to `null` instead of throwing.
9052
9832
  */
9053
9833
  async init(config) {
9054
- var _a, _b, _c, _d;
9055
- if (this.initialized || this.initializing) {
9056
- log(config.debug || false, "Already initialized or initializing");
9834
+ var _a, _b;
9835
+ if (this.initialized) {
9836
+ log(config.debug || false, "Already initialized \u2014 returning existing session.");
9057
9837
  return this.getSession();
9058
9838
  }
9839
+ if (this.initializing) {
9840
+ log(config.debug || false, "Initialization in progress \u2014 skipping duplicate call.");
9841
+ return null;
9842
+ }
9059
9843
  this.initializing = true;
9060
- this.config = __spreadValues({
9061
- debug: false
9062
- }, config);
9063
- log(this.config.debug, "\u{1F680} Initializing external tracker with SDK...", config);
9844
+ this.config = __spreadValues({ debug: false }, config);
9845
+ const debug = this.config.debug;
9846
+ try {
9847
+ validate(this.config);
9848
+ } catch (err) {
9849
+ this.initializing = false;
9850
+ const error = err instanceof Error ? err : new Error(String(err));
9851
+ if (this.config.onError) {
9852
+ this.config.onError(error);
9853
+ return null;
9854
+ }
9855
+ throw error;
9856
+ }
9857
+ log(debug, "\u{1F680} Initializing external tracker v".concat(TRACKER_VERSION), {
9858
+ storeId: config.storeId,
9859
+ accountId: config.accountId,
9860
+ stepId: config.stepId,
9861
+ funnelId: config.funnelId
9862
+ });
9064
9863
  try {
9065
9864
  const urlToken = getUrlParam("token");
9066
9865
  if (urlToken) {
9067
9866
  setClientToken(urlToken);
9068
- log(this.config.debug, "\u{1F511} Bootstrapped token from URL");
9867
+ log(debug, "\u{1F511} Bootstrapped token from URL");
9069
9868
  }
9070
9869
  this.client = createTagadaClient({
9071
- debugMode: this.config.debug,
9072
- features: { funnel: true }
9870
+ debugMode: debug,
9871
+ features: { funnel: { skipAutoInit: true } },
9872
+ rawPluginConfig: {
9873
+ storeId: this.config.storeId,
9874
+ accountId: this.config.accountId
9875
+ },
9876
+ customApiConfig: this.config.apiBaseUrl ? {
9877
+ apiConfig: {
9878
+ baseUrl: this.config.apiBaseUrl.trim()
9879
+ }
9880
+ } : void 0
9073
9881
  });
9074
9882
  await this.waitForClientReady();
9075
- const funnelContext = await this.initializeFunnel();
9076
- log(this.config.debug, "\u2705 Session initialized (tracking handled by orchestrator):", funnelContext);
9883
+ const funnelContext = await retryWithBackoff(
9884
+ () => this.initializeFunnel(),
9885
+ 2,
9886
+ debug
9887
+ );
9888
+ log(debug, "\u2705 Session initialized:", funnelContext);
9077
9889
  this.initialized = true;
9078
9890
  const session = this.getSession();
9079
9891
  if (session) {
9080
9892
  (_b = (_a = this.config).onReady) == null ? void 0 : _b.call(_a, session);
9081
9893
  }
9082
9894
  return session;
9083
- } catch (error) {
9084
- const err = error instanceof Error ? error : new Error(String(error));
9085
- log(this.config.debug, "\u274C Initialization failed:", err);
9086
- (_d = (_c = this.config).onError) == null ? void 0 : _d.call(_c, err);
9087
- throw err;
9895
+ } catch (err) {
9896
+ const error = err instanceof Error ? err : new Error(String(err));
9897
+ log(debug, "\u274C Initialization failed:", error);
9898
+ if (this.config.onError) {
9899
+ this.config.onError(error);
9900
+ return null;
9901
+ }
9902
+ throw error;
9088
9903
  } finally {
9089
9904
  this.initializing = false;
9090
9905
  }
9091
9906
  }
9092
- /**
9093
- * Get current session from SDK state
9094
- */
9907
+ /** Get current session data. */
9095
9908
  getSession() {
9096
9909
  var _a, _b;
9097
9910
  if (!((_b = (_a = this.client) == null ? void 0 : _a.funnel) == null ? void 0 : _b.state.context)) return null;
@@ -9105,19 +9918,18 @@ var TagadaTrackerBundle = (() => {
9105
9918
  cmsToken: this.client.state.token || void 0
9106
9919
  };
9107
9920
  }
9108
- /**
9109
- * Check if tracker is ready
9110
- */
9921
+ /** Whether the tracker is fully initialized and ready. */
9111
9922
  isReady() {
9112
9923
  var _a, _b;
9113
9924
  return this.initialized && !!((_b = (_a = this.client) == null ? void 0 : _a.funnel) == null ? void 0 : _b.state.context);
9114
9925
  }
9115
9926
  /**
9116
- * Navigate to next step in funnel using SDK's funnel client
9927
+ * Navigate to the next step in the funnel.
9928
+ * By default, auto-redirects the browser window.
9117
9929
  */
9118
9930
  async navigate(options) {
9119
9931
  if (!this.isReady()) {
9120
- throw new Error("Tracker not initialized. Call init() first.");
9932
+ throw new Error("TagadaTracker: not initialized. Call init() first.");
9121
9933
  }
9122
9934
  log(this.config.debug, "\u{1F680} Navigating:", options);
9123
9935
  const shouldAutoRedirect = options.autoRedirect !== false;
@@ -9128,7 +9940,6 @@ var TagadaTrackerBundle = (() => {
9128
9940
  data: options.eventData || {}
9129
9941
  },
9130
9942
  { autoRedirect: false }
9131
- // Always disable SDK auto-redirect, we handle it here
9132
9943
  );
9133
9944
  if (result == null ? void 0 : result.url) {
9134
9945
  log(this.config.debug, "\u2705 Navigation result:", result.url);
@@ -9144,36 +9955,48 @@ var TagadaTrackerBundle = (() => {
9144
9955
  }
9145
9956
  }
9146
9957
  /**
9147
- * Get customer ID (for identifying the user)
9958
+ * Track a custom event (e.g., button click, scroll depth, video play).
9959
+ * Events are sent through the funnel orchestrator for unified analytics.
9148
9960
  */
9961
+ async trackEvent(options) {
9962
+ if (!this.isReady()) {
9963
+ warn("trackEvent called before init \u2014 event dropped:", options.name);
9964
+ return;
9965
+ }
9966
+ log(this.config.debug, "\u{1F4CA} Tracking event:", options.name, options.data);
9967
+ try {
9968
+ await this.client.funnel.navigate(
9969
+ {
9970
+ type: options.name,
9971
+ data: options.data || {}
9972
+ },
9973
+ { autoRedirect: false }
9974
+ );
9975
+ } catch (e) {
9976
+ log(this.config.debug, "\u26A0\uFE0F Event tracking failed (non-critical):", options.name);
9977
+ }
9978
+ }
9979
+ /** Get customer ID. */
9149
9980
  getCustomerId() {
9150
9981
  var _a, _b, _c, _d, _e;
9151
9982
  return ((_b = (_a = this.client) == null ? void 0 : _a.state.auth.customer) == null ? void 0 : _b.id) || ((_e = (_d = (_c = this.client) == null ? void 0 : _c.funnel) == null ? void 0 : _d.state.context) == null ? void 0 : _e.customerId) || null;
9152
9983
  }
9153
- /**
9154
- * Get funnel session ID
9155
- */
9984
+ /** Get funnel session ID. */
9156
9985
  getFunnelSessionId() {
9157
9986
  var _a, _b, _c;
9158
9987
  return ((_c = (_b = (_a = this.client) == null ? void 0 : _a.funnel) == null ? void 0 : _b.state.context) == null ? void 0 : _c.sessionId) || null;
9159
9988
  }
9160
9989
  /**
9161
- * Build a URL with funnel context parameters
9162
- * Useful for linking to other external pages while preserving session
9990
+ * Build a URL that preserves funnel session context.
9991
+ * Use this to link to other external pages within the same funnel.
9163
9992
  */
9164
9993
  buildUrl(baseUrl, additionalParams) {
9165
9994
  const session = this.getSession();
9166
- if (!session) {
9167
- return baseUrl;
9168
- }
9995
+ if (!session) return baseUrl;
9169
9996
  const url = new URL(baseUrl, typeof window !== "undefined" ? window.location.origin : void 0);
9170
9997
  url.searchParams.set("funnelSessionId", session.sessionId);
9171
- if (session.cmsToken) {
9172
- url.searchParams.set("token", session.cmsToken);
9173
- }
9174
- if (session.funnelId) {
9175
- url.searchParams.set("funnelId", session.funnelId);
9176
- }
9998
+ if (session.cmsToken) url.searchParams.set("token", session.cmsToken);
9999
+ if (session.funnelId) url.searchParams.set("funnelId", session.funnelId);
9177
10000
  url.searchParams.set("storeId", session.storeId);
9178
10001
  if (additionalParams) {
9179
10002
  Object.entries(additionalParams).forEach(([key, value]) => {
@@ -9182,55 +10005,98 @@ var TagadaTrackerBundle = (() => {
9182
10005
  }
9183
10006
  return url.toString();
9184
10007
  }
9185
- /**
9186
- * Get the underlying SDK client (for advanced usage)
9187
- */
10008
+ /** Get the underlying SDK client (advanced usage). */
9188
10009
  getClient() {
9189
10010
  return this.client;
9190
10011
  }
10012
+ /**
10013
+ * Reset the tracker to a new step without re-creating the session.
10014
+ * Useful for SPAs that navigate between funnel steps client-side.
10015
+ */
10016
+ async reset(newStepId) {
10017
+ var _a, _b;
10018
+ if (!this.client || !this.config) {
10019
+ throw new Error("TagadaTracker: not initialized. Call init() first.");
10020
+ }
10021
+ log(this.config.debug, "\u{1F504} Resetting to step:", newStepId);
10022
+ this.config.stepId = newStepId;
10023
+ const ctx = await this.initializeFunnel();
10024
+ const session = this.getSession();
10025
+ if (session) (_b = (_a = this.config).onReady) == null ? void 0 : _b.call(_a, session);
10026
+ return session;
10027
+ }
10028
+ /**
10029
+ * Destroy the tracker, clean up event listeners and state.
10030
+ * Call this when the tracker is no longer needed (e.g., SPA teardown).
10031
+ */
10032
+ destroy() {
10033
+ var _a, _b;
10034
+ if (this.unsubscribe) {
10035
+ this.unsubscribe();
10036
+ this.unsubscribe = null;
10037
+ }
10038
+ if (this.client) {
10039
+ (_b = (_a = this.client).destroy) == null ? void 0 : _b.call(_a);
10040
+ }
10041
+ this.client = null;
10042
+ this.config = null;
10043
+ this.initialized = false;
10044
+ this.initializing = false;
10045
+ log(false, "\u{1F5D1}\uFE0F Tracker destroyed");
10046
+ }
9191
10047
  // ========================================================================
9192
10048
  // PRIVATE METHODS
9193
10049
  // ========================================================================
9194
10050
  async waitForClientReady() {
9195
10051
  if (!this.client) return;
9196
10052
  return new Promise((resolve) => {
9197
- let retries = 0;
9198
- const checkReady = () => {
9199
- var _a, _b;
9200
- if (((_a = this.client) == null ? void 0 : _a.state.isInitialized) || ((_b = this.client) == null ? void 0 : _b.state.token)) {
10053
+ var _a;
10054
+ if ((_a = this.client) == null ? void 0 : _a.state.isInitialized) {
10055
+ resolve();
10056
+ return;
10057
+ }
10058
+ let resolved = false;
10059
+ const timeout = setTimeout(() => {
10060
+ var _a2;
10061
+ if (!resolved) {
10062
+ resolved = true;
10063
+ log(((_a2 = this.config) == null ? void 0 : _a2.debug) || false, "\u23F1\uFE0F Client ready timeout \u2014 proceeding");
9201
10064
  resolve();
9202
- } else if (retries > 40) {
10065
+ }
10066
+ }, 1e4);
10067
+ this.unsubscribe = this.client.subscribe(() => {
10068
+ var _a2;
10069
+ if (!resolved && ((_a2 = this.client) == null ? void 0 : _a2.state.isInitialized)) {
10070
+ resolved = true;
10071
+ clearTimeout(timeout);
9203
10072
  resolve();
9204
- } else {
9205
- retries++;
9206
- setTimeout(checkReady, 50);
9207
10073
  }
9208
- };
9209
- checkReady();
10074
+ });
9210
10075
  });
9211
10076
  }
9212
10077
  async initializeFunnel() {
9213
10078
  var _a, _b, _c;
9214
10079
  if (!((_a = this.client) == null ? void 0 : _a.funnel)) return null;
10080
+ const customerId = (_b = this.client.state.auth.customer) == null ? void 0 : _b.id;
10081
+ const sessionId = (_c = this.client.state.auth.session) == null ? void 0 : _c.sessionId;
10082
+ if (!customerId && !sessionId) {
10083
+ warn("No auth session available \u2014 funnel init may fail.");
10084
+ }
9215
10085
  const authSession = {
9216
- customerId: ((_b = this.client.state.auth.customer) == null ? void 0 : _b.id) || "anon_placeholder",
9217
- sessionId: ((_c = this.client.state.auth.session) == null ? void 0 : _c.sessionId) || "sess_placeholder"
10086
+ customerId: customerId || "anon_placeholder",
10087
+ sessionId: sessionId || "sess_placeholder"
9218
10088
  };
9219
10089
  const store = {
9220
10090
  id: this.config.storeId,
9221
- accountId: this.config.accountId || ""
10091
+ accountId: this.config.accountId
9222
10092
  };
9223
10093
  const entryStepId = this.config.stepId;
9224
- if (!entryStepId) {
9225
- throw new Error("stepId is required for external page tracking (URL mapping does not work for external pages)");
9226
- }
9227
- log(this.config.debug, "\u{1F50D} Initializing external page at step:", entryStepId);
10094
+ log(this.config.debug, "\u{1F50D} Initializing funnel at step:", entryStepId);
9228
10095
  return this.client.funnel.initialize(
9229
10096
  authSession,
9230
10097
  store,
9231
10098
  this.config.funnelId || getUrlParam("funnelId") || void 0,
9232
10099
  entryStepId
9233
- // ✅ Explicitly tell orchestrator which step we're on
9234
10100
  );
9235
10101
  }
9236
10102
  };