@imtbl/checkout-widgets 2.24.8 → 2.24.9-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 (126) hide show
  1. package/dist/browser/{AddTokensWidget-BQfrLKCo.js → AddTokensWidget-CIR8BF_I.js} +24 -297
  2. package/dist/browser/{BridgeWidget-6KlgTXwZ.js → BridgeWidget-C5Uljhhx.js} +13 -294
  3. package/dist/browser/{CommerceWidget-CcCuv661.js → CommerceWidget-CeBBYCbK.js} +17 -47
  4. package/dist/browser/{FeesBreakdown-DvoQJlP-.js → FeesBreakdown-BU4haotD.js} +1 -1
  5. package/dist/browser/{OnRampWidget-DaL34PiA.js → OnRampWidget-Ccvb3QkT.js} +5 -80
  6. package/dist/browser/{SaleWidget-D-IBBRTL.js → SaleWidget-CPARFlzv.js} +61 -219
  7. package/dist/browser/{SpendingCapHero-Z5NIcrWw.js → SpendingCapHero-B-0YYZho.js} +1 -1
  8. package/dist/browser/{SwapWidget-C4B2Answ.js → SwapWidget-ujE6uX-N.js} +12 -206
  9. package/dist/browser/{TokenImage-DucOedrZ.js → TokenImage-BeUf_Ulv.js} +1 -1
  10. package/dist/browser/{TopUpView-BIvdNYib.js → TopUpView-GMv3360Q.js} +3 -54
  11. package/dist/browser/{WalletApproveHero-ge2JSOYk.js → WalletApproveHero-BJi7ufqM.js} +4 -12
  12. package/dist/browser/{WalletWidget-hiUotMuQ.js → WalletWidget-BABrqsfd.js} +4 -96
  13. package/dist/browser/{index-2esq4Cem.js → index-CcxHW36j.js} +1275 -9717
  14. package/dist/browser/{index-DWNAmu0n.js → index-Cp1w6map.js} +1 -1
  15. package/dist/browser/index.js +1 -1
  16. package/dist/browser/{useInterval-1gu4cbu3.js → useInterval-DbCsm_gG.js} +1 -1
  17. package/dist/types/components/FormComponents/SelectForm/SelectForm.d.ts +1 -5
  18. package/dist/types/components/FormComponents/SelectInput/SelectInput.d.ts +1 -5
  19. package/dist/types/components/Transak/TransakIframe.d.ts +0 -1
  20. package/dist/types/components/Transak/useTransakEvents.d.ts +0 -4
  21. package/dist/types/components/WalletDrawer/ConnectWalletDrawer.d.ts +1 -2
  22. package/dist/types/lib/squid/hooks/useExecute.d.ts +1 -2
  23. package/dist/types/views/top-up/TopUpView.d.ts +1 -5
  24. package/dist/types/widgets/add-tokens/hooks/useError.d.ts +1 -1
  25. package/dist/types/widgets/purchase/components/PurchaseConnectWalletDrawer.d.ts +1 -3
  26. package/dist/types/widgets/sale/hooks/useSaleEvents.d.ts +5 -31
  27. package/dist/types/widgets/swap/components/Fees.d.ts +1 -1
  28. package/package.json +7 -9
  29. package/src/components/ConnectLoader/ConnectLoader.tsx +0 -16
  30. package/src/components/FormComponents/SelectForm/SelectForm.tsx +2 -18
  31. package/src/components/FormComponents/SelectInput/SelectInput.tsx +1 -12
  32. package/src/components/RouteOptionsDrawer/RouteOptionsDrawer.tsx +2 -26
  33. package/src/components/Transactions/ChangeWallet.tsx +1 -12
  34. package/src/components/Transactions/ClaimWithdrawalInProgress.tsx +0 -11
  35. package/src/components/Transactions/NoTransactions.tsx +0 -10
  36. package/src/components/Transactions/TransactionItemWithdrawPending.tsx +1 -13
  37. package/src/components/Transactions/Transactions.tsx +2 -28
  38. package/src/components/Transak/TransakIframe.tsx +0 -6
  39. package/src/components/Transak/useTransakEvents.ts +1 -70
  40. package/src/components/WalletDrawer/ConnectWalletDrawer.tsx +2 -35
  41. package/src/components/WalletDrawer/PayWithWalletDrawer.tsx +0 -1
  42. package/src/context/view-context/test-components/ViewContextTestComponent.tsx +14 -15
  43. package/src/lib/squid/hooks/useExecute.ts +5 -18
  44. package/src/views/top-up/TopUpView.tsx +5 -56
  45. package/src/widgets/add-tokens/AddTokensRoot.tsx +28 -29
  46. package/src/widgets/add-tokens/AddTokensWidget.tsx +2 -17
  47. package/src/widgets/add-tokens/components/TokenDrawerMenu.tsx +2 -18
  48. package/src/widgets/add-tokens/hooks/useError.tsx +1 -18
  49. package/src/widgets/add-tokens/hooks/useErrorHandler.ts +2 -12
  50. package/src/widgets/add-tokens/views/AddTokens.tsx +8 -154
  51. package/src/widgets/add-tokens/views/Review.tsx +6 -94
  52. package/src/widgets/bridge/BridgeWidget.tsx +0 -35
  53. package/src/widgets/bridge/BridgeWidgetRoot.tsx +17 -18
  54. package/src/widgets/bridge/components/BridgeForm.tsx +0 -20
  55. package/src/widgets/bridge/components/BridgeReviewSummary.tsx +1 -49
  56. package/src/widgets/bridge/components/WalletAndNetworkSelector.tsx +3 -122
  57. package/src/widgets/bridge/views/ApproveTransaction.tsx +1 -15
  58. package/src/widgets/bridge/views/Bridge.tsx +1 -16
  59. package/src/widgets/bridge/views/BridgeReview.tsx +1 -12
  60. package/src/widgets/bridge/views/ClaimWithdrawal.tsx +0 -11
  61. package/src/widgets/bridge/views/MoveInProgress.tsx +0 -24
  62. package/src/widgets/bridge/views/WalletNetworkSelectionView.tsx +1 -12
  63. package/src/widgets/connect/ConnectWidget.tsx +2 -18
  64. package/src/widgets/connect/ConnectWidgetRoot.tsx +15 -16
  65. package/src/widgets/connect/components/WalletList.tsx +6 -55
  66. package/src/widgets/connect/views/ConnectWallet.tsx +1 -12
  67. package/src/widgets/connect/views/ReadyToConnect.tsx +2 -29
  68. package/src/widgets/connect/views/SwitchNetworkEth.tsx +3 -22
  69. package/src/widgets/connect/views/SwitchNetworkZkEVM.tsx +0 -18
  70. package/src/widgets/immutable-commerce/CommerceWidgetRoot.tsx +17 -19
  71. package/src/widgets/on-ramp/OnRampWidget.tsx +0 -2
  72. package/src/widgets/on-ramp/OnRampWidgetRoot.tsx +23 -24
  73. package/src/widgets/on-ramp/views/OnRampMain.tsx +1 -91
  74. package/src/widgets/purchase/PurchaseWidgetRoot.tsx +22 -23
  75. package/src/widgets/purchase/components/PurchaseConnectWalletDrawer.tsx +2 -34
  76. package/src/widgets/purchase/components/PurchaseDeliverToWalletDrawer.tsx +0 -1
  77. package/src/widgets/purchase/components/PurchasePayWithWalletDrawer.tsx +0 -2
  78. package/src/widgets/purchase/components/PurchaseRouteOptionsDrawer/RouteOptionsDrawer.tsx +1 -30
  79. package/src/widgets/purchase/components/WithCard.tsx +0 -4
  80. package/src/widgets/purchase/views/Purchase.tsx +1 -2
  81. package/src/widgets/sale/SaleWidget.tsx +0 -2
  82. package/src/widgets/sale/SaleWidgetRoot.tsx +32 -33
  83. package/src/widgets/sale/components/OrderReview.tsx +2 -29
  84. package/src/widgets/sale/components/WithCard.tsx +0 -2
  85. package/src/widgets/sale/hooks/useSaleEvents.ts +3 -185
  86. package/src/widgets/sale/views/OrderSummary.tsx +2 -15
  87. package/src/widgets/sale/views/PayWithCard.tsx +4 -46
  88. package/src/widgets/sale/views/PayWithCoins.tsx +4 -9
  89. package/src/widgets/sale/views/PaymentMethods.tsx +3 -6
  90. package/src/widgets/sale/views/SaleErrorView.tsx +1 -1
  91. package/src/widgets/swap/SwapWidget.tsx +0 -24
  92. package/src/widgets/swap/SwapWidgetRoot.tsx +29 -30
  93. package/src/widgets/swap/components/Fees.tsx +1 -1
  94. package/src/widgets/swap/components/SwapForm.tsx +2 -140
  95. package/src/widgets/swap/views/ApproveERC20Onboarding.tsx +1 -36
  96. package/src/widgets/swap/views/SwapCoins.tsx +0 -17
  97. package/src/widgets/swap/views/SwapInProgress.tsx +0 -14
  98. package/src/widgets/transfer/TransferForm.tsx +3 -25
  99. package/src/widgets/transfer/TransferWidget.tsx +1 -23
  100. package/src/widgets/wallet/WalletWidgetRoot.tsx +24 -25
  101. package/src/widgets/wallet/components/BalanceItem/BalanceItem.tsx +1 -50
  102. package/src/widgets/wallet/components/NetworkMenu/NetworkMenu.tsx +0 -13
  103. package/src/widgets/wallet/components/WalletAddress/WalletAddress.tsx +0 -13
  104. package/src/widgets/wallet/views/CoinInfo.tsx +1 -12
  105. package/src/widgets/wallet/views/Settings.tsx +1 -15
  106. package/src/widgets/wallet/views/WalletBalances.tsx +0 -24
  107. package/tsconfig.json +0 -1
  108. package/dist/browser/auto-track-C-H4NHVE.js +0 -105
  109. package/dist/browser/index-CcQ-5rAF.js +0 -446
  110. package/dist/browser/index-CvpdSuud.js +0 -5634
  111. package/dist/browser/index-D3m5uC9C.js +0 -60
  112. package/dist/browser/index-DJEaNohG.js +0 -65
  113. package/dist/browser/index-DPz4F2rf.js +0 -27
  114. package/dist/browser/index-DQZhPkHy.js +0 -65
  115. package/dist/browser/index.umd-brf0Qwxh.js +0 -32
  116. package/dist/browser/is-plan-event-enabled-mXX0dwl-.js +0 -17
  117. package/dist/types/context/analytics-provider/CustomAnalyticsProvider.d.ts +0 -7
  118. package/dist/types/context/analytics-provider/SegmentAnalyticsProvider.d.ts +0 -42
  119. package/dist/types/context/analytics-provider/SetupAnalytics.d.ts +0 -7
  120. package/dist/types/lib/analytics/identifyUser.d.ts +0 -8
  121. package/dist/types/lib/analytics/identifyUser.test.d.ts +0 -1
  122. package/src/context/analytics-provider/CustomAnalyticsProvider.tsx +0 -22
  123. package/src/context/analytics-provider/SegmentAnalyticsProvider.ts +0 -41
  124. package/src/context/analytics-provider/SetupAnalytics.tsx +0 -35
  125. package/src/lib/analytics/identifyUser.test.ts +0 -44
  126. package/src/lib/analytics/identifyUser.ts +0 -26
@@ -1,105 +0,0 @@
1
- import { eq as pTimeout } from './index-2esq4Cem.js';
2
-
3
- // Check if a user is opening the link in a new tab
4
- function userNewTab(event) {
5
- var typedEvent = event;
6
- if (typedEvent.ctrlKey ||
7
- typedEvent.shiftKey ||
8
- typedEvent.metaKey ||
9
- (typedEvent.button && typedEvent.button == 1)) {
10
- return true;
11
- }
12
- return false;
13
- }
14
- // Check if the link opens in new tab
15
- function linkNewTab(element, href) {
16
- if (element.target === '_blank' && href) {
17
- return true;
18
- }
19
- return false;
20
- }
21
- function link(links, event, properties, options) {
22
- var _this = this;
23
- var elements = [];
24
- // always arrays, handles jquery
25
- if (!links) {
26
- return this;
27
- }
28
- if (links instanceof Element) {
29
- elements = [links];
30
- }
31
- else if ('toArray' in links) {
32
- elements = links.toArray();
33
- }
34
- else {
35
- elements = links;
36
- }
37
- elements.forEach(function (el) {
38
- el.addEventListener('click', function (elementEvent) {
39
- var _a, _b;
40
- var ev = event instanceof Function ? event(el) : event;
41
- var props = properties instanceof Function ? properties(el) : properties;
42
- var href = el.getAttribute('href') ||
43
- el.getAttributeNS('http://www.w3.org/1999/xlink', 'href') ||
44
- el.getAttribute('xlink:href') ||
45
- ((_a = el.getElementsByTagName('a')[0]) === null || _a === void 0 ? void 0 : _a.getAttribute('href'));
46
- var trackEvent = pTimeout(_this.track(ev, props, options !== null && options !== void 0 ? options : {}), (_b = _this.settings.timeout) !== null && _b !== void 0 ? _b : 500);
47
- if (!linkNewTab(el, href) &&
48
- !userNewTab(elementEvent)) {
49
- if (href) {
50
- elementEvent.preventDefault
51
- ? elementEvent.preventDefault()
52
- : (elementEvent.returnValue = false);
53
- trackEvent
54
- .catch(console.error)
55
- .then(function () {
56
- window.location.href = href;
57
- })
58
- .catch(console.error);
59
- }
60
- }
61
- }, false);
62
- });
63
- return this;
64
- }
65
- function form(forms, event, properties, options) {
66
- var _this = this;
67
- // always arrays, handles jquery
68
- if (!forms)
69
- return this;
70
- if (forms instanceof HTMLFormElement)
71
- forms = [forms];
72
- var elements = forms;
73
- elements.forEach(function (el) {
74
- if (!(el instanceof Element))
75
- throw new TypeError('Must pass HTMLElement to trackForm/trackSubmit.');
76
- var handler = function (elementEvent) {
77
- var _a;
78
- elementEvent.preventDefault
79
- ? elementEvent.preventDefault()
80
- : (elementEvent.returnValue = false);
81
- var ev = event instanceof Function ? event(el) : event;
82
- var props = properties instanceof Function ? properties(el) : properties;
83
- var trackEvent = pTimeout(_this.track(ev, props, options !== null && options !== void 0 ? options : {}), (_a = _this.settings.timeout) !== null && _a !== void 0 ? _a : 500);
84
- trackEvent
85
- .catch(console.error)
86
- .then(function () {
87
- el.submit();
88
- })
89
- .catch(console.error);
90
- };
91
- // Support the events happening through jQuery or Zepto instead of through
92
- // the normal DOM API, because `el.submit` doesn't bubble up events...
93
- var $ = window.jQuery || window.Zepto;
94
- if ($) {
95
- $(el).submit(handler);
96
- }
97
- else {
98
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
99
- el.addEventListener('submit', handler, false);
100
- }
101
- });
102
- return this;
103
- }
104
-
105
- export { form, link };
@@ -1,446 +0,0 @@
1
- import { e6 as __awaiter, e7 as __generator, e8 as loadScript, e9 as getNextIntegrationsURL, ea as unloadScript, eb as __spreadArray, ec as isOffline, ed as __assign, ee as ContextCancelation, ef as applyDestinationMiddleware, eg as dist, eh as isServer, ei as mergedOptions, ej as isPlainObject, ek as pWhile, el as PriorityQueue, em as PersistedPriorityQueue, en as attempt, eo as isOnline, ep as Context } from './index-2esq4Cem.js';
2
- import { i as isPlanEventEnabled } from './is-plan-event-enabled-mXX0dwl-.js';
3
-
4
- function normalizeName(name) {
5
- return name.toLowerCase().replace('.', '').replace(/\s+/g, '-');
6
- }
7
- function obfuscatePathName(pathName, obfuscate) {
8
- if (obfuscate === void 0) { obfuscate = false; }
9
- return obfuscate ? btoa(pathName).replace(/=/g, '') : undefined;
10
- }
11
- function resolveIntegrationNameFromSource(integrationSource) {
12
- return ('Integration' in integrationSource
13
- ? integrationSource.Integration
14
- : integrationSource).prototype.name;
15
- }
16
- function recordLoadMetrics(fullPath, ctx, name) {
17
- var _a, _b;
18
- try {
19
- var metric = ((_b = (_a = window === null || window === void 0 ? void 0 : window.performance) === null || _a === void 0 ? void 0 : _a.getEntriesByName(fullPath, 'resource')) !== null && _b !== void 0 ? _b : [])[0];
20
- // we assume everything that took under 100ms is cached
21
- metric &&
22
- ctx.stats.gauge('legacy_destination_time', Math.round(metric.duration), __spreadArray([
23
- name
24
- ], (metric.duration < 100 ? ['cached'] : []), true));
25
- }
26
- catch (_) {
27
- // not available
28
- }
29
- }
30
- function buildIntegration(integrationSource, integrationSettings, analyticsInstance) {
31
- var integrationCtr;
32
- // GA and Appcues use a different interface to instantiating integrations
33
- if ('Integration' in integrationSource) {
34
- var analyticsStub = {
35
- user: function () { return analyticsInstance.user(); },
36
- addIntegration: function () { },
37
- };
38
- integrationSource(analyticsStub);
39
- integrationCtr = integrationSource.Integration;
40
- }
41
- else {
42
- integrationCtr = integrationSource;
43
- }
44
- var integration = new integrationCtr(integrationSettings);
45
- integration.analytics = analyticsInstance;
46
- return integration;
47
- }
48
- function loadIntegration(ctx, name, version, obfuscate) {
49
- return __awaiter(this, void 0, void 0, function () {
50
- var pathName, obfuscatedPathName, path, fullPath, err_1, deps;
51
- return __generator(this, function (_a) {
52
- switch (_a.label) {
53
- case 0:
54
- pathName = normalizeName(name);
55
- obfuscatedPathName = obfuscatePathName(pathName, obfuscate);
56
- path = getNextIntegrationsURL();
57
- fullPath = "".concat(path, "/integrations/").concat(obfuscatedPathName !== null && obfuscatedPathName !== void 0 ? obfuscatedPathName : pathName, "/").concat(version, "/").concat(obfuscatedPathName !== null && obfuscatedPathName !== void 0 ? obfuscatedPathName : pathName, ".dynamic.js.gz");
58
- _a.label = 1;
59
- case 1:
60
- _a.trys.push([1, 3, , 4]);
61
- return [4 /*yield*/, loadScript(fullPath)];
62
- case 2:
63
- _a.sent();
64
- recordLoadMetrics(fullPath, ctx, name);
65
- return [3 /*break*/, 4];
66
- case 3:
67
- err_1 = _a.sent();
68
- ctx.stats.gauge('legacy_destination_time', -1, ["plugin:".concat(name), "failed"]);
69
- throw err_1;
70
- case 4:
71
- deps = window["".concat(pathName, "Deps")];
72
- return [4 /*yield*/, Promise.all(deps.map(function (dep) { return loadScript(path + dep + '.gz'); }))
73
- // @ts-ignore
74
- ];
75
- case 5:
76
- _a.sent();
77
- // @ts-ignore
78
- window["".concat(pathName, "Loader")]();
79
- return [2 /*return*/, window[
80
- // @ts-ignore
81
- "".concat(pathName, "Integration")]];
82
- }
83
- });
84
- });
85
- }
86
- function unloadIntegration(name, version, obfuscate) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- var path, pathName, obfuscatedPathName, fullPath;
89
- return __generator(this, function (_a) {
90
- path = getNextIntegrationsURL();
91
- pathName = normalizeName(name);
92
- obfuscatedPathName = obfuscatePathName(name, obfuscate);
93
- fullPath = "".concat(path, "/integrations/").concat(obfuscatedPathName !== null && obfuscatedPathName !== void 0 ? obfuscatedPathName : pathName, "/").concat(version, "/").concat(obfuscatedPathName !== null && obfuscatedPathName !== void 0 ? obfuscatedPathName : pathName, ".dynamic.js.gz");
94
- return [2 /*return*/, unloadScript(fullPath)];
95
- });
96
- });
97
- }
98
- function resolveVersion(settings) {
99
- var _a, _b, _c, _d;
100
- return ((_d = (_b = (_a = settings === null || settings === void 0 ? void 0 : settings.versionSettings) === null || _a === void 0 ? void 0 : _a.override) !== null && _b !== void 0 ? _b : (_c = settings === null || settings === void 0 ? void 0 : settings.versionSettings) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : 'latest');
101
- }
102
-
103
- var isInstallableIntegration = function (name, integrationSettings) {
104
- var _a;
105
- var type = integrationSettings.type, bundlingStatus = integrationSettings.bundlingStatus, versionSettings = integrationSettings.versionSettings;
106
- // We use `!== 'unbundled'` (versus `=== 'bundled'`) to be inclusive of
107
- // destinations without a defined value for `bundlingStatus`
108
- var deviceMode = bundlingStatus !== 'unbundled' &&
109
- (type === 'browser' || ((_a = versionSettings === null || versionSettings === void 0 ? void 0 : versionSettings.componentTypes) === null || _a === void 0 ? void 0 : _a.includes('browser')));
110
- // checking for iterable is a quick fix we need in place to prevent
111
- // errors showing Iterable as a failed destiantion. Ideally, we should
112
- // fix the Iterable metadata instead, but that's a longer process.
113
- return !name.startsWith('Segment') && name !== 'Iterable' && deviceMode;
114
- };
115
- var isDisabledIntegration = function (integrationName, globalIntegrations) {
116
- var allDisableAndNotDefined = globalIntegrations.All === false &&
117
- globalIntegrations[integrationName] === undefined;
118
- return (globalIntegrations[integrationName] === false || allDisableAndNotDefined);
119
- };
120
-
121
- function flushQueue(xt, queue) {
122
- return __awaiter(this, void 0, void 0, function () {
123
- var failedQueue;
124
- var _this = this;
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0:
128
- failedQueue = [];
129
- if (isOffline()) {
130
- return [2 /*return*/, queue];
131
- }
132
- return [4 /*yield*/, pWhile(function () { return queue.length > 0 && isOnline(); }, function () { return __awaiter(_this, void 0, void 0, function () {
133
- var ctx, result, success;
134
- return __generator(this, function (_a) {
135
- switch (_a.label) {
136
- case 0:
137
- ctx = queue.pop();
138
- if (!ctx) {
139
- return [2 /*return*/];
140
- }
141
- return [4 /*yield*/, attempt(ctx, xt)];
142
- case 1:
143
- result = _a.sent();
144
- success = result instanceof Context;
145
- if (!success) {
146
- failedQueue.push(ctx);
147
- }
148
- return [2 /*return*/];
149
- }
150
- });
151
- }); })
152
- // re-add failed tasks
153
- ];
154
- case 1:
155
- _a.sent();
156
- // re-add failed tasks
157
- failedQueue.map(function (failed) { return queue.pushWithBackoff(failed); });
158
- return [2 /*return*/, queue];
159
- }
160
- });
161
- });
162
- }
163
- var LegacyDestination = /** @class */ (function () {
164
- function LegacyDestination(name, version, writeKey, settings, options, integrationSource) {
165
- if (settings === void 0) { settings = {}; }
166
- this.options = {};
167
- this.type = 'destination';
168
- this.middleware = [];
169
- this._ready = false;
170
- this._initialized = false;
171
- this.flushing = false;
172
- this.name = name;
173
- this.version = version;
174
- this.settings = __assign({}, settings);
175
- this.disableAutoISOConversion = options.disableAutoISOConversion || false;
176
- this.integrationSource = integrationSource;
177
- // AJS-Renderer sets an extraneous `type` setting that clobbers
178
- // existing type defaults. We need to remove it if it's present
179
- if (this.settings['type'] && this.settings['type'] === 'browser') {
180
- delete this.settings['type'];
181
- }
182
- this.options = options;
183
- this.buffer = options.disableClientPersistence
184
- ? new PriorityQueue(4, [])
185
- : new PersistedPriorityQueue(4, "".concat(writeKey, ":dest-").concat(name));
186
- this.scheduleFlush();
187
- }
188
- LegacyDestination.prototype.isLoaded = function () {
189
- return this._ready;
190
- };
191
- LegacyDestination.prototype.ready = function () {
192
- var _a;
193
- return (_a = this.onReady) !== null && _a !== void 0 ? _a : Promise.resolve();
194
- };
195
- LegacyDestination.prototype.load = function (ctx, analyticsInstance) {
196
- var _a;
197
- return __awaiter(this, void 0, void 0, function () {
198
- var integrationSource, _b;
199
- var _this = this;
200
- return __generator(this, function (_c) {
201
- switch (_c.label) {
202
- case 0:
203
- if (this._ready || this.onReady !== undefined) {
204
- return [2 /*return*/];
205
- }
206
- if (!((_a = this.integrationSource) !== null && _a !== void 0)) return [3 /*break*/, 1];
207
- _b = _a;
208
- return [3 /*break*/, 3];
209
- case 1: return [4 /*yield*/, loadIntegration(ctx, this.name, this.version, this.options.obfuscate)];
210
- case 2:
211
- _b = (_c.sent());
212
- _c.label = 3;
213
- case 3:
214
- integrationSource = _b;
215
- this.integration = buildIntegration(integrationSource, this.settings, analyticsInstance);
216
- this.onReady = new Promise(function (resolve) {
217
- var onReadyFn = function () {
218
- _this._ready = true;
219
- resolve(true);
220
- };
221
- _this.integration.once('ready', onReadyFn);
222
- });
223
- this.onInitialize = new Promise(function (resolve) {
224
- var onInit = function () {
225
- _this._initialized = true;
226
- resolve(true);
227
- };
228
- _this.integration.on('initialize', onInit);
229
- });
230
- try {
231
- ctx.stats.increment('analytics_js.integration.invoke', 1, [
232
- "method:initialize",
233
- "integration_name:".concat(this.name),
234
- ]);
235
- this.integration.initialize();
236
- }
237
- catch (error) {
238
- ctx.stats.increment('analytics_js.integration.invoke.error', 1, [
239
- "method:initialize",
240
- "integration_name:".concat(this.name),
241
- ]);
242
- throw error;
243
- }
244
- return [2 /*return*/];
245
- }
246
- });
247
- });
248
- };
249
- LegacyDestination.prototype.unload = function (_ctx, _analyticsInstance) {
250
- return unloadIntegration(this.name, this.version, this.options.obfuscate);
251
- };
252
- LegacyDestination.prototype.addMiddleware = function () {
253
- var _a;
254
- var fn = [];
255
- for (var _i = 0; _i < arguments.length; _i++) {
256
- fn[_i] = arguments[_i];
257
- }
258
- this.middleware = (_a = this.middleware).concat.apply(_a, fn);
259
- };
260
- LegacyDestination.prototype.shouldBuffer = function (ctx) {
261
- return (
262
- // page events can't be buffered because of destinations that automatically add page views
263
- ctx.event.type !== 'page' &&
264
- (isOffline() || this._ready === false || this._initialized === false));
265
- };
266
- LegacyDestination.prototype.send = function (ctx, clz, eventType) {
267
- var _a, _b;
268
- return __awaiter(this, void 0, void 0, function () {
269
- var plan, ev, planEvent, afterMiddleware, event, err_1;
270
- return __generator(this, function (_c) {
271
- switch (_c.label) {
272
- case 0:
273
- if (this.shouldBuffer(ctx)) {
274
- this.buffer.push(ctx);
275
- this.scheduleFlush();
276
- return [2 /*return*/, ctx];
277
- }
278
- plan = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.plan) === null || _b === void 0 ? void 0 : _b.track;
279
- ev = ctx.event.event;
280
- if (plan && ev && this.name !== 'Segment.io') {
281
- planEvent = plan[ev];
282
- if (!isPlanEventEnabled(plan, planEvent)) {
283
- ctx.updateEvent('integrations', __assign(__assign({}, ctx.event.integrations), { All: false, 'Segment.io': true }));
284
- ctx.cancel(new ContextCancelation({
285
- retry: false,
286
- reason: "Event ".concat(ev, " disabled for integration ").concat(this.name, " in tracking plan"),
287
- type: 'Dropped by plan',
288
- }));
289
- return [2 /*return*/, ctx];
290
- }
291
- else {
292
- ctx.updateEvent('integrations', __assign(__assign({}, ctx.event.integrations), planEvent === null || planEvent === void 0 ? void 0 : planEvent.integrations));
293
- }
294
- if ((planEvent === null || planEvent === void 0 ? void 0 : planEvent.enabled) && (planEvent === null || planEvent === void 0 ? void 0 : planEvent.integrations[this.name]) === false) {
295
- ctx.cancel(new ContextCancelation({
296
- retry: false,
297
- reason: "Event ".concat(ev, " disabled for integration ").concat(this.name, " in tracking plan"),
298
- type: 'Dropped by plan',
299
- }));
300
- return [2 /*return*/, ctx];
301
- }
302
- }
303
- return [4 /*yield*/, applyDestinationMiddleware(this.name, ctx.event, this.middleware)];
304
- case 1:
305
- afterMiddleware = _c.sent();
306
- if (afterMiddleware === null) {
307
- return [2 /*return*/, ctx];
308
- }
309
- event = new clz(afterMiddleware, {
310
- traverse: !this.disableAutoISOConversion,
311
- });
312
- ctx.stats.increment('analytics_js.integration.invoke', 1, [
313
- "method:".concat(eventType),
314
- "integration_name:".concat(this.name),
315
- ]);
316
- _c.label = 2;
317
- case 2:
318
- _c.trys.push([2, 5, , 6]);
319
- if (!this.integration) return [3 /*break*/, 4];
320
- return [4 /*yield*/, this.integration.invoke.call(this.integration, eventType, event)];
321
- case 3:
322
- _c.sent();
323
- _c.label = 4;
324
- case 4: return [3 /*break*/, 6];
325
- case 5:
326
- err_1 = _c.sent();
327
- ctx.stats.increment('analytics_js.integration.invoke.error', 1, [
328
- "method:".concat(eventType),
329
- "integration_name:".concat(this.name),
330
- ]);
331
- throw err_1;
332
- case 6: return [2 /*return*/, ctx];
333
- }
334
- });
335
- });
336
- };
337
- LegacyDestination.prototype.track = function (ctx) {
338
- return __awaiter(this, void 0, void 0, function () {
339
- return __generator(this, function (_a) {
340
- return [2 /*return*/, this.send(ctx, dist.Track, 'track')];
341
- });
342
- });
343
- };
344
- LegacyDestination.prototype.page = function (ctx) {
345
- var _a;
346
- return __awaiter(this, void 0, void 0, function () {
347
- var _this = this;
348
- return __generator(this, function (_b) {
349
- if (((_a = this.integration) === null || _a === void 0 ? void 0 : _a._assumesPageview) && !this._initialized) {
350
- this.integration.initialize();
351
- }
352
- return [2 /*return*/, this.onInitialize.then(function () {
353
- return _this.send(ctx, dist.Page, 'page');
354
- })];
355
- });
356
- });
357
- };
358
- LegacyDestination.prototype.identify = function (ctx) {
359
- return __awaiter(this, void 0, void 0, function () {
360
- return __generator(this, function (_a) {
361
- return [2 /*return*/, this.send(ctx, dist.Identify, 'identify')];
362
- });
363
- });
364
- };
365
- LegacyDestination.prototype.alias = function (ctx) {
366
- return __awaiter(this, void 0, void 0, function () {
367
- return __generator(this, function (_a) {
368
- return [2 /*return*/, this.send(ctx, dist.Alias, 'alias')];
369
- });
370
- });
371
- };
372
- LegacyDestination.prototype.group = function (ctx) {
373
- return __awaiter(this, void 0, void 0, function () {
374
- return __generator(this, function (_a) {
375
- return [2 /*return*/, this.send(ctx, dist.Group, 'group')];
376
- });
377
- });
378
- };
379
- LegacyDestination.prototype.scheduleFlush = function () {
380
- var _this = this;
381
- if (this.flushing) {
382
- return;
383
- }
384
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
385
- setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
386
- var _a;
387
- return __generator(this, function (_b) {
388
- switch (_b.label) {
389
- case 0:
390
- this.flushing = true;
391
- _a = this;
392
- return [4 /*yield*/, flushQueue(this, this.buffer)];
393
- case 1:
394
- _a.buffer = _b.sent();
395
- this.flushing = false;
396
- if (this.buffer.todo > 0) {
397
- this.scheduleFlush();
398
- }
399
- return [2 /*return*/];
400
- }
401
- });
402
- }); }, Math.random() * 5000);
403
- };
404
- return LegacyDestination;
405
- }());
406
- function ajsDestinations(writeKey, settings, globalIntegrations, options, routingMiddleware, legacyIntegrationSources) {
407
- var _a, _b;
408
- if (globalIntegrations === void 0) { globalIntegrations = {}; }
409
- if (options === void 0) { options = {}; }
410
- if (isServer()) {
411
- return [];
412
- }
413
- if (settings.plan) {
414
- options = options !== null && options !== void 0 ? options : {};
415
- options.plan = settings.plan;
416
- }
417
- var routingRules = (_b = (_a = settings.middlewareSettings) === null || _a === void 0 ? void 0 : _a.routingRules) !== null && _b !== void 0 ? _b : [];
418
- var remoteIntegrationsConfig = settings.integrations;
419
- var localIntegrationsConfig = options.integrations;
420
- // merged remote CDN settings with user provided options
421
- var integrationOptions = mergedOptions(settings, options !== null && options !== void 0 ? options : {});
422
- var adhocIntegrationSources = legacyIntegrationSources === null || legacyIntegrationSources === void 0 ? void 0 : legacyIntegrationSources.reduce(function (acc, integrationSource) {
423
- var _a;
424
- return (__assign(__assign({}, acc), (_a = {}, _a[resolveIntegrationNameFromSource(integrationSource)] = integrationSource, _a)));
425
- }, {});
426
- var installableIntegrations = new Set(__spreadArray(__spreadArray([], Object.keys(remoteIntegrationsConfig).filter(function (name) {
427
- return isInstallableIntegration(name, remoteIntegrationsConfig[name]);
428
- }), true), Object.keys(adhocIntegrationSources || {}).filter(function (name) {
429
- return isPlainObject(remoteIntegrationsConfig[name]) ||
430
- isPlainObject(localIntegrationsConfig === null || localIntegrationsConfig === void 0 ? void 0 : localIntegrationsConfig[name]);
431
- }), true));
432
- return Array.from(installableIntegrations)
433
- .filter(function (name) { return !isDisabledIntegration(name, globalIntegrations); })
434
- .map(function (name) {
435
- var integrationSettings = remoteIntegrationsConfig[name];
436
- var version = resolveVersion(integrationSettings);
437
- var destination = new LegacyDestination(name, version, writeKey, integrationOptions[name], options, adhocIntegrationSources === null || adhocIntegrationSources === void 0 ? void 0 : adhocIntegrationSources[name]);
438
- var routing = routingRules.filter(function (rule) { return rule.destinationName === name; });
439
- if (routing.length > 0 && routingMiddleware) {
440
- destination.addMiddleware(routingMiddleware);
441
- }
442
- return destination;
443
- });
444
- }
445
-
446
- export { LegacyDestination, ajsDestinations };