@imtbl/sdk 1.5.2 → 1.5.3-alpha.1

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 (33) hide show
  1. package/dist/blockchain_data.js +81 -24
  2. package/dist/browser/checkout/BridgeWidget-2e0093b4.js +1 -0
  3. package/dist/browser/checkout/OnRampWidget-444ebe2b.js +1 -0
  4. package/dist/browser/checkout/SaleWidget-5f6ea630.js +2 -0
  5. package/dist/browser/checkout/SpendingCapHero-a6ef1dcc.js +1 -0
  6. package/dist/browser/checkout/SwapWidget-aee793d7.js +1 -0
  7. package/dist/browser/checkout/TopUpView-def404d5.js +1 -0
  8. package/dist/browser/checkout/WalletWidget-f87f80b4.js +1 -0
  9. package/dist/browser/checkout/auto-track-e03d4bb9.js +1 -0
  10. package/dist/browser/checkout/balance-c8477685.js +1 -0
  11. package/dist/browser/checkout/index-35beb3eb.js +1 -0
  12. package/dist/browser/checkout/index-43973ac4.js +1 -0
  13. package/dist/browser/checkout/index-49582766.js +1 -0
  14. package/dist/browser/checkout/index-500dddb2.js +1 -0
  15. package/dist/browser/checkout/index-6984b667.js +773 -0
  16. package/dist/browser/checkout/index-a8155f8b.js +1 -0
  17. package/dist/browser/checkout/index-ea3645ce.js +106 -0
  18. package/dist/browser/checkout/index.umd-9e885d58.js +1 -0
  19. package/dist/browser/checkout/is-plan-event-enabled-80f76ce6.js +1 -0
  20. package/dist/browser/checkout/retry-fc920719.js +1 -0
  21. package/dist/browser/checkout/sdk.js +22 -6
  22. package/dist/browser/checkout/useTransakEvents-cffde72e.js +2 -0
  23. package/dist/browser/checkout/widgets.js +1 -872
  24. package/dist/checkout.js +496 -54
  25. package/dist/config.js +59 -26
  26. package/dist/index.browser.js +28 -12
  27. package/dist/index.browser.js.map +1 -1
  28. package/dist/index.cjs +494 -60
  29. package/dist/index.js +494 -60
  30. package/dist/orderbook.js +80 -23
  31. package/dist/passport.js +65 -27
  32. package/dist/x.js +81 -24
  33. package/package.json +3 -1
package/dist/checkout.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import globalAxios, { HttpStatusCode as HttpStatusCode$2 } from 'axios';
2
+ import { memorise } from 'lru-memorise';
3
+ import { getGlobalisedValue as getGlobalisedValue$3 } from 'global-const';
2
4
  import { ethers, ContractFactory, utils as utils$2, Contract as Contract$1, BigNumber as BigNumber$1, providers, constants as constants$1 } from 'ethers';
3
5
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
4
6
  import detectEthereumProvider from '@metamask/detect-provider';
@@ -24,12 +26,6 @@ var Detail$1;
24
26
  Detail["DOMAIN"] = "domain";
25
27
  Detail["SDK_VERSION"] = "sdkVersion";
26
28
  })(Detail$1 || (Detail$1 = {}));
27
- var Store$1;
28
- (function (Store) {
29
- Store["EVENTS"] = "events";
30
- Store["RUNTIME"] = "runtime";
31
- })(Store$1 || (Store$1 = {}));
32
- const POLLING_FREQUENCY$1 = 5000;
33
29
 
34
30
  const IMTBL_API$1 = 'https://api.x.immutable.com';
35
31
  async function post$1(path, data) {
@@ -89,6 +85,11 @@ const setItem$1 = (key, payload) => {
89
85
  return false;
90
86
  };
91
87
 
88
+ var Store$1;
89
+ (function (Store) {
90
+ Store["EVENTS"] = "events";
91
+ Store["RUNTIME"] = "runtime";
92
+ })(Store$1 || (Store$1 = {}));
92
93
  // In memory storage for events and other data
93
94
  let EVENT_STORE$1;
94
95
  let RUNTIME_DETAILS$1;
@@ -116,7 +117,7 @@ const getDetail$1 = (key) => {
116
117
  const getAllDetails$1 = () => RUNTIME_DETAILS$1;
117
118
  // Events
118
119
  const getEvents$1 = () => EVENT_STORE$1;
119
- const addEvent = (event) => {
120
+ const addEvent$1 = (event) => {
120
121
  EVENT_STORE$1.push(event);
121
122
  setItem$1(Store$1.EVENTS, EVENT_STORE$1);
122
123
  };
@@ -138,9 +139,7 @@ const flattenProperties$1 = (properties) => {
138
139
  };
139
140
 
140
141
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
141
- const SDK_VERSION$1 = '1.5.2';
142
- let initialised$1 = false;
143
- const isInitialised$1 = () => initialised$1;
142
+ const SDK_VERSION$1 = '1.5.3-alpha.1';
144
143
  const getReferrer$1 = () => {
145
144
  if (isNode$1()) {
146
145
  return '';
@@ -177,21 +176,28 @@ const getRuntimeDetails$1 = () => {
177
176
  screen: `${window.screen.width}x${window.screen.height}`,
178
177
  };
179
178
  };
179
+ let initialised$1 = false;
180
+ const isInitialised$1 = () => initialised$1;
180
181
  const initialise$2 = async () => {
181
- const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
182
- const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
183
- const body = {
184
- version: 1,
185
- data: {
186
- runtimeDetails,
187
- runtimeId: existingRuntimeId,
188
- },
189
- };
190
- const response = await post$1('/v1/sdk/initialise', body);
191
- // Get runtimeId and store it
192
- const { runtimeId } = response;
193
- storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
194
182
  initialised$1 = true;
183
+ try {
184
+ const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
185
+ const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
186
+ const body = {
187
+ version: 1,
188
+ data: {
189
+ runtimeDetails,
190
+ runtimeId: existingRuntimeId,
191
+ },
192
+ };
193
+ const response = await post$1('/v1/sdk/initialise', body);
194
+ // Get runtimeId and store it
195
+ const { runtimeId } = response;
196
+ storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
197
+ }
198
+ catch (error) {
199
+ initialised$1 = false;
200
+ }
195
201
  };
196
202
 
197
203
  function errorBoundary$1(fn) {
@@ -223,16 +229,31 @@ function isTestEnvironment$1() {
223
229
  return process.env.JEST_WORKER_ID !== undefined;
224
230
  }
225
231
 
232
+ const GLOBALISE_KEY$1 = 'imtbl__metrics';
233
+ const MEMORISE_TIMEFRAME$1 = 1000;
234
+ const MEMORISE_MAX$1 = 1000;
235
+ const getGlobalisedValue$2 = (key, value) => getGlobalisedValue$3(GLOBALISE_KEY$1, key, value);
236
+ const getGlobalisedCachedFunction$1 = (key, fn) => {
237
+ // Some applications (esp backend, or frontends using the split bundles) can sometimes
238
+ // initialise the same request multiple times. This will prevent multiple of the
239
+ // same event,value from being reported in a 1 second period.
240
+ const memorisedFn = memorise(fn, {
241
+ lruOptions: { ttl: MEMORISE_TIMEFRAME$1, max: MEMORISE_MAX$1 },
242
+ });
243
+ return getGlobalisedValue$3(GLOBALISE_KEY$1, key, memorisedFn);
244
+ };
245
+
246
+ const POLLING_FREQUENCY$1 = 5000;
226
247
  // Store the event in the event store
227
- const trackFn = (moduleName, eventName, properties) => {
248
+ const trackFn$1 = (moduleName, eventName, properties) => {
228
249
  const event = {
229
250
  event: `${moduleName}.${eventName}`,
230
251
  time: new Date().toISOString(),
231
252
  ...(properties && { properties: flattenProperties$1(properties) }),
232
253
  };
233
- addEvent(event);
254
+ addEvent$1(event);
234
255
  };
235
- const track = errorBoundary$1(trackFn);
256
+ const track = errorBoundary$1(getGlobalisedCachedFunction$1('track', trackFn$1));
236
257
  // Sending events to the server
237
258
  const flushFn$1 = async () => {
238
259
  // Don't flush if not initialised
@@ -268,15 +289,31 @@ const flushPoll$1 = async () => {
268
289
  await flush$1();
269
290
  setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
270
291
  };
292
+ let flushingStarted$1 = false;
293
+ const startFlushing$1 = () => {
294
+ if (flushingStarted$1) {
295
+ return;
296
+ }
297
+ flushingStarted$1 = true;
298
+ flushPoll$1();
299
+ };
271
300
  // This will get initialised when module is imported.
272
301
  if (!isTestEnvironment$1()) {
273
- errorBoundary$1(flushPoll$1)();
302
+ errorBoundary$1(getGlobalisedValue$2('startFlushing', startFlushing$1))();
274
303
  }
275
304
 
276
- const setEnvironmentFn = (env) => {
305
+ const setEnvironmentFn$1 = (env) => {
277
306
  storeDetail$1(Detail$1.ENVIRONMENT, env);
278
307
  };
279
- const setEnvironment = errorBoundary$1(setEnvironmentFn);
308
+ const setEnvironment = errorBoundary$1(getGlobalisedValue$2('setEnvironment', setEnvironmentFn$1));
309
+ const setPassportClientIdFn$1 = (passportClientId) => {
310
+ storeDetail$1(Detail$1.PASSPORT_CLIENT_ID, passportClientId);
311
+ };
312
+ errorBoundary$1(getGlobalisedValue$2('setPassportClientId', setPassportClientIdFn$1));
313
+ const setPublishableApiKeyFn$1 = (publishableApiKey) => {
314
+ storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
315
+ };
316
+ errorBoundary$1(getGlobalisedValue$2('setPublishableApiKey', setPublishableApiKeyFn$1));
280
317
 
281
318
  var Environment$1;
282
319
  (function (Environment) {
@@ -16965,6 +17002,356 @@ class TokenBridge {
16965
17002
  }
16966
17003
  }
16967
17004
 
17005
+ var lib$1 = {};
17006
+
17007
+ var tinyLru = {};
17008
+
17009
+ /**
17010
+ * tiny-lru
17011
+ *
17012
+ * @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
17013
+ * @license BSD-3-Clause
17014
+ * @version 11.2.5
17015
+ */
17016
+
17017
+ class LRU {
17018
+ constructor (max = 0, ttl = 0, resetTtl = false) {
17019
+ this.first = null;
17020
+ this.items = Object.create(null);
17021
+ this.last = null;
17022
+ this.max = max;
17023
+ this.resetTtl = resetTtl;
17024
+ this.size = 0;
17025
+ this.ttl = ttl;
17026
+ }
17027
+
17028
+ clear () {
17029
+ this.first = null;
17030
+ this.items = Object.create(null);
17031
+ this.last = null;
17032
+ this.size = 0;
17033
+
17034
+ return this;
17035
+ }
17036
+
17037
+ delete (key) {
17038
+ if (this.has(key)) {
17039
+ const item = this.items[key];
17040
+
17041
+ delete this.items[key];
17042
+ this.size--;
17043
+
17044
+ if (item.prev !== null) {
17045
+ item.prev.next = item.next;
17046
+ }
17047
+
17048
+ if (item.next !== null) {
17049
+ item.next.prev = item.prev;
17050
+ }
17051
+
17052
+ if (this.first === item) {
17053
+ this.first = item.next;
17054
+ }
17055
+
17056
+ if (this.last === item) {
17057
+ this.last = item.prev;
17058
+ }
17059
+ }
17060
+
17061
+ return this;
17062
+ }
17063
+
17064
+ entries (keys = this.keys()) {
17065
+ return keys.map(key => [key, this.get(key)]);
17066
+ }
17067
+
17068
+ evict (bypass = false) {
17069
+ if (bypass || this.size > 0) {
17070
+ const item = this.first;
17071
+
17072
+ delete this.items[item.key];
17073
+
17074
+ if (--this.size === 0) {
17075
+ this.first = null;
17076
+ this.last = null;
17077
+ } else {
17078
+ this.first = item.next;
17079
+ this.first.prev = null;
17080
+ }
17081
+ }
17082
+
17083
+ return this;
17084
+ }
17085
+
17086
+ expiresAt (key) {
17087
+ let result;
17088
+
17089
+ if (this.has(key)) {
17090
+ result = this.items[key].expiry;
17091
+ }
17092
+
17093
+ return result;
17094
+ }
17095
+
17096
+ get (key) {
17097
+ let result;
17098
+
17099
+ if (this.has(key)) {
17100
+ const item = this.items[key];
17101
+
17102
+ if (this.ttl > 0 && item.expiry <= Date.now()) {
17103
+ this.delete(key);
17104
+ } else {
17105
+ result = item.value;
17106
+ this.set(key, result, true);
17107
+ }
17108
+ }
17109
+
17110
+ return result;
17111
+ }
17112
+
17113
+ has (key) {
17114
+ return key in this.items;
17115
+ }
17116
+
17117
+ keys () {
17118
+ const result = [];
17119
+ let x = this.first;
17120
+
17121
+ while (x !== null) {
17122
+ result.push(x.key);
17123
+ x = x.next;
17124
+ }
17125
+
17126
+ return result;
17127
+ }
17128
+
17129
+ set (key, value, bypass = false, resetTtl = this.resetTtl) {
17130
+ let item;
17131
+
17132
+ if (bypass || this.has(key)) {
17133
+ item = this.items[key];
17134
+ item.value = value;
17135
+
17136
+ if (bypass === false && resetTtl) {
17137
+ item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
17138
+ }
17139
+
17140
+ if (this.last !== item) {
17141
+ const last = this.last,
17142
+ next = item.next,
17143
+ prev = item.prev;
17144
+
17145
+ if (this.first === item) {
17146
+ this.first = item.next;
17147
+ }
17148
+
17149
+ item.next = null;
17150
+ item.prev = this.last;
17151
+ last.next = item;
17152
+
17153
+ if (prev !== null) {
17154
+ prev.next = next;
17155
+ }
17156
+
17157
+ if (next !== null) {
17158
+ next.prev = prev;
17159
+ }
17160
+ }
17161
+ } else {
17162
+ if (this.max > 0 && this.size === this.max) {
17163
+ this.evict(true);
17164
+ }
17165
+
17166
+ item = this.items[key] = {
17167
+ expiry: this.ttl > 0 ? Date.now() + this.ttl : this.ttl,
17168
+ key: key,
17169
+ prev: this.last,
17170
+ next: null,
17171
+ value
17172
+ };
17173
+
17174
+ if (++this.size === 1) {
17175
+ this.first = item;
17176
+ } else {
17177
+ this.last.next = item;
17178
+ }
17179
+ }
17180
+
17181
+ this.last = item;
17182
+
17183
+ return this;
17184
+ }
17185
+
17186
+ values (keys = this.keys()) {
17187
+ return keys.map(key => this.get(key));
17188
+ }
17189
+ }
17190
+
17191
+ function lru (max = 1000, ttl = 0, resetTtl = false) {
17192
+ if (isNaN(max) || max < 0) {
17193
+ throw new TypeError("Invalid max value");
17194
+ }
17195
+
17196
+ if (isNaN(ttl) || ttl < 0) {
17197
+ throw new TypeError("Invalid ttl value");
17198
+ }
17199
+
17200
+ if (typeof resetTtl !== "boolean") {
17201
+ throw new TypeError("Invalid resetTtl value");
17202
+ }
17203
+
17204
+ return new LRU(max, ttl, resetTtl);
17205
+ }
17206
+
17207
+ tinyLru.LRU = LRU;
17208
+ tinyLru.lru = lru;
17209
+
17210
+ (function (exports) {
17211
+ Object.defineProperty(exports, "__esModule", { value: true });
17212
+ exports.memorise = void 0;
17213
+ const tiny_lru_1 = tinyLru;
17214
+ const defaultLRUOptions = {
17215
+ max: 1000,
17216
+ };
17217
+ /**
17218
+ * Returns a memorised version of the target function.
17219
+ * The cache key depends on the arguments passed to the function.
17220
+ *
17221
+ * Pass in options to customise the caching behaviour
17222
+ * @param cachedFn Function to cache
17223
+ * @param options Memorization and LRUCache Options
17224
+ */
17225
+ const memorise = (cachedFn, options = {}) => {
17226
+ // Extract defaults
17227
+ const { cache, cacheKeyResolver = defaultGenCacheKey, onHit, lruOptions = {}, } = options;
17228
+ const cacheOptions = { ...defaultLRUOptions, ...lruOptions };
17229
+ const _cache = (cache ||
17230
+ (0, tiny_lru_1.lru)(cacheOptions.max, cacheOptions.ttl));
17231
+ // Cached fn
17232
+ const returnFn = (...args) => {
17233
+ const cacheKey = cacheKeyResolver(...args);
17234
+ const cachedValue = _cache.get(cacheKey);
17235
+ const keyCached = _cache.has(cacheKey);
17236
+ // Use cached key, even if value is void
17237
+ if (keyCached) {
17238
+ // If onHit handler is there, run it
17239
+ if (onHit) {
17240
+ onHit(cacheKey, cachedValue, _cache);
17241
+ }
17242
+ return cachedValue;
17243
+ }
17244
+ // No cache hit, run function and cache result
17245
+ const result = cachedFn.apply(this, args);
17246
+ _cache.set(cacheKey, result);
17247
+ return result;
17248
+ };
17249
+ // Expose the cache
17250
+ returnFn._cache = _cache;
17251
+ return returnFn;
17252
+ };
17253
+ exports.memorise = memorise;
17254
+ // Default export
17255
+ exports.default = exports.memorise;
17256
+ /**
17257
+ * Generic args handler function.
17258
+ * @param args Argument array
17259
+ */
17260
+ const defaultGenCacheKey = (...args) => {
17261
+ if (args.length === 0) {
17262
+ return "no-args";
17263
+ }
17264
+ return args
17265
+ .map((val) => {
17266
+ if (val === undefined) {
17267
+ return "undefined";
17268
+ }
17269
+ if (val === null) {
17270
+ return "null";
17271
+ }
17272
+ if (Array.isArray(val)) {
17273
+ return `[${defaultGenCacheKey(...val)}]`;
17274
+ }
17275
+ if (typeof val === "object") {
17276
+ return `{${defaultGenCacheKey(...sortedObjectEntries(val))}}`;
17277
+ }
17278
+ return JSON.stringify(val);
17279
+ })
17280
+ .join(",");
17281
+ };
17282
+ const sortedObjectEntries = (obj) => {
17283
+ return Object.entries(obj).sort((a, b) => {
17284
+ if (a[0] < b[0]) {
17285
+ return -1;
17286
+ }
17287
+ return 1;
17288
+ });
17289
+ };
17290
+
17291
+ } (lib$1));
17292
+
17293
+ var lib = {};
17294
+
17295
+ Object.defineProperty(lib, "__esModule", { value: true });
17296
+ lib.clearGlobalNamespace = getGlobalisedValue_1 = lib.getGlobalisedValue = void 0;
17297
+ const GLOBALISE_KEY_PREFIX = "globalise__singleton__";
17298
+ const fallbackGlobal = {};
17299
+ const getGlobalObject = () => {
17300
+ if (typeof window !== "undefined") {
17301
+ return window;
17302
+ }
17303
+ if (typeof globalThis !== "undefined") {
17304
+ return globalThis;
17305
+ }
17306
+ return fallbackGlobal;
17307
+ };
17308
+ const validateInputs = (namespace, key) => {
17309
+ if (typeof namespace !== "string") {
17310
+ throw "Invalid namespace key";
17311
+ }
17312
+ if (typeof key !== "string") {
17313
+ throw "Invalid item key";
17314
+ }
17315
+ };
17316
+ const createGlobalisedKey = (namespace) => {
17317
+ return `${GLOBALISE_KEY_PREFIX}${namespace}`;
17318
+ };
17319
+ const getGlobalScopedObject = (namespace) => {
17320
+ const globalObject = getGlobalObject();
17321
+ const GLOBALISE_KEY = createGlobalisedKey(namespace);
17322
+ // Initialise global object
17323
+ if (!globalObject[GLOBALISE_KEY]) {
17324
+ globalObject[GLOBALISE_KEY] = {};
17325
+ }
17326
+ return globalObject[GLOBALISE_KEY];
17327
+ };
17328
+ const getSingleton = (namespace, key) => {
17329
+ const scopedObject = getGlobalScopedObject(namespace);
17330
+ return scopedObject[key] || undefined;
17331
+ };
17332
+ const setSingleton = (namespace, key, value) => {
17333
+ const scopedObject = getGlobalScopedObject(namespace);
17334
+ scopedObject[key] = value;
17335
+ };
17336
+ const getGlobalisedValue$1 = (namespace, key, value) => {
17337
+ validateInputs(namespace, key);
17338
+ const existing = getSingleton(namespace, key);
17339
+ if (existing !== undefined) {
17340
+ return existing;
17341
+ }
17342
+ setSingleton(namespace, key, value);
17343
+ return value;
17344
+ };
17345
+ var getGlobalisedValue_1 = lib.getGlobalisedValue = getGlobalisedValue$1;
17346
+ const clearGlobalNamespace = (namespace) => {
17347
+ const globalObject = getGlobalObject();
17348
+ const globalisedKey = createGlobalisedKey(namespace);
17349
+ if (globalObject[globalisedKey] !== undefined) {
17350
+ delete globalObject[globalisedKey];
17351
+ }
17352
+ };
17353
+ lib.clearGlobalNamespace = clearGlobalNamespace;
17354
+
16968
17355
  const isNode = () => typeof window === 'undefined';
16969
17356
  const isBrowser = () => !isNode();
16970
17357
 
@@ -16978,12 +17365,6 @@ var Detail;
16978
17365
  Detail["DOMAIN"] = "domain";
16979
17366
  Detail["SDK_VERSION"] = "sdkVersion";
16980
17367
  })(Detail || (Detail = {}));
16981
- var Store;
16982
- (function (Store) {
16983
- Store["EVENTS"] = "events";
16984
- Store["RUNTIME"] = "runtime";
16985
- })(Store || (Store = {}));
16986
- const POLLING_FREQUENCY = 5000;
16987
17368
 
16988
17369
  const IMTBL_API = 'https://api.x.immutable.com';
16989
17370
  async function post(path, data) {
@@ -17043,6 +17424,11 @@ const setItem = (key, payload) => {
17043
17424
  return false;
17044
17425
  };
17045
17426
 
17427
+ var Store;
17428
+ (function (Store) {
17429
+ Store["EVENTS"] = "events";
17430
+ Store["RUNTIME"] = "runtime";
17431
+ })(Store || (Store = {}));
17046
17432
  // In memory storage for events and other data
17047
17433
  let EVENT_STORE;
17048
17434
  let RUNTIME_DETAILS;
@@ -17070,6 +17456,10 @@ const getDetail = (key) => {
17070
17456
  const getAllDetails = () => RUNTIME_DETAILS;
17071
17457
  // Events
17072
17458
  const getEvents = () => EVENT_STORE;
17459
+ const addEvent = (event) => {
17460
+ EVENT_STORE.push(event);
17461
+ setItem(Store.EVENTS, EVENT_STORE);
17462
+ };
17073
17463
  const removeSentEvents = (numberOfEvents) => {
17074
17464
  EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
17075
17465
  setItem(Store.EVENTS, EVENT_STORE);
@@ -17088,9 +17478,7 @@ const flattenProperties = (properties) => {
17088
17478
  };
17089
17479
 
17090
17480
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
17091
- const SDK_VERSION = '1.5.2';
17092
- let initialised = false;
17093
- const isInitialised = () => initialised;
17481
+ const SDK_VERSION = '1.5.3-alpha.1';
17094
17482
  const getReferrer = () => {
17095
17483
  if (isNode()) {
17096
17484
  return '';
@@ -17127,21 +17515,28 @@ const getRuntimeDetails = () => {
17127
17515
  screen: `${window.screen.width}x${window.screen.height}`,
17128
17516
  };
17129
17517
  };
17518
+ let initialised = false;
17519
+ const isInitialised = () => initialised;
17130
17520
  const initialise = async () => {
17131
- const runtimeDetails = flattenProperties(getRuntimeDetails());
17132
- const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
17133
- const body = {
17134
- version: 1,
17135
- data: {
17136
- runtimeDetails,
17137
- runtimeId: existingRuntimeId,
17138
- },
17139
- };
17140
- const response = await post('/v1/sdk/initialise', body);
17141
- // Get runtimeId and store it
17142
- const { runtimeId } = response;
17143
- storeDetail(Detail.RUNTIME_ID, runtimeId);
17144
17521
  initialised = true;
17522
+ try {
17523
+ const runtimeDetails = flattenProperties(getRuntimeDetails());
17524
+ const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
17525
+ const body = {
17526
+ version: 1,
17527
+ data: {
17528
+ runtimeDetails,
17529
+ runtimeId: existingRuntimeId,
17530
+ },
17531
+ };
17532
+ const response = await post('/v1/sdk/initialise', body);
17533
+ // Get runtimeId and store it
17534
+ const { runtimeId } = response;
17535
+ storeDetail(Detail.RUNTIME_ID, runtimeId);
17536
+ }
17537
+ catch (error) {
17538
+ initialised = false;
17539
+ }
17145
17540
  };
17146
17541
 
17147
17542
  function errorBoundary(fn) {
@@ -17172,6 +17567,32 @@ function isTestEnvironment() {
17172
17567
  // Just use process.env.CI for now.
17173
17568
  return process.env.JEST_WORKER_ID !== undefined;
17174
17569
  }
17570
+
17571
+ const GLOBALISE_KEY = 'imtbl__metrics';
17572
+ const MEMORISE_TIMEFRAME = 1000;
17573
+ const MEMORISE_MAX = 1000;
17574
+ const getGlobalisedValue = (key, value) => getGlobalisedValue_1(GLOBALISE_KEY, key, value);
17575
+ const getGlobalisedCachedFunction = (key, fn) => {
17576
+ // Some applications (esp backend, or frontends using the split bundles) can sometimes
17577
+ // initialise the same request multiple times. This will prevent multiple of the
17578
+ // same event,value from being reported in a 1 second period.
17579
+ const memorisedFn = lib$1.memorise(fn, {
17580
+ lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
17581
+ });
17582
+ return getGlobalisedValue_1(GLOBALISE_KEY, key, memorisedFn);
17583
+ };
17584
+
17585
+ const POLLING_FREQUENCY = 5000;
17586
+ // Store the event in the event store
17587
+ const trackFn = (moduleName, eventName, properties) => {
17588
+ const event = {
17589
+ event: `${moduleName}.${eventName}`,
17590
+ time: new Date().toISOString(),
17591
+ ...(properties && { properties: flattenProperties(properties) }),
17592
+ };
17593
+ addEvent(event);
17594
+ };
17595
+ errorBoundary(getGlobalisedCachedFunction('track', trackFn));
17175
17596
  // Sending events to the server
17176
17597
  const flushFn = async () => {
17177
17598
  // Don't flush if not initialised
@@ -17207,11 +17628,32 @@ const flushPoll = async () => {
17207
17628
  await flush();
17208
17629
  setTimeout(flushPoll, POLLING_FREQUENCY);
17209
17630
  };
17631
+ let flushingStarted = false;
17632
+ const startFlushing = () => {
17633
+ if (flushingStarted) {
17634
+ return;
17635
+ }
17636
+ flushingStarted = true;
17637
+ flushPoll();
17638
+ };
17210
17639
  // This will get initialised when module is imported.
17211
17640
  if (!isTestEnvironment()) {
17212
- errorBoundary(flushPoll)();
17641
+ errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
17213
17642
  }
17214
17643
 
17644
+ const setEnvironmentFn = (env) => {
17645
+ storeDetail(Detail.ENVIRONMENT, env);
17646
+ };
17647
+ errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
17648
+ const setPassportClientIdFn = (passportClientId) => {
17649
+ storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
17650
+ };
17651
+ errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
17652
+ const setPublishableApiKeyFn = (publishableApiKey) => {
17653
+ storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
17654
+ };
17655
+ errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
17656
+
17215
17657
  var Environment;
17216
17658
  (function (Environment) {
17217
17659
  Environment["PRODUCTION"] = "production";
@@ -27273,7 +27715,7 @@ class APIError extends Error {
27273
27715
 
27274
27716
  /* eslint-disable implicit-arrow-linebreak */
27275
27717
  const defaultHeaders = {
27276
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.2',
27718
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.3-alpha.1',
27277
27719
  };
27278
27720
  /**
27279
27721
  * createAPIConfiguration to create a custom Configuration
@@ -28640,7 +29082,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
28640
29082
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
28641
29083
  };
28642
29084
 
28643
- const SDK_VERSION_MARKER = '1.5.2';
29085
+ const SDK_VERSION_MARKER = '1.5.3-alpha.1';
28644
29086
  // This SDK version is replaced by the `yarn build` command ran on the root level
28645
29087
  const globalPackageVersion = () => SDK_VERSION_MARKER;
28646
29088