@imtbl/sdk 1.5.2 → 1.5.3-alpha

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.
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import globalAxios$1, { isAxiosError as isAxiosError$2, HttpStatusCode as HttpStatusCode$3, AxiosError as AxiosError$2 } from 'axios';
2
+ import { memorise } from 'lru-memorise';
3
+ import { getGlobalisedValue as getGlobalisedValue$3 } from 'global-const';
2
4
  import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner, TransfersApi as TransfersApi$1, OrdersApi as OrdersApi$2, UsersApi as UsersApi$1, Contracts, TradesApi as TradesApi$1, ExchangesApi as ExchangesApi$1, WithdrawalsApi as WithdrawalsApi$1, MintsApi as MintsApi$1, DepositsApi as DepositsApi$1, EncodingApi as EncodingApi$1, TokensApi as TokensApi$2, IMXError } from '@imtbl/core-sdk';
3
5
  import { UserManager, User, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
4
6
  import jwt_decode from 'jwt-decode';
@@ -37,12 +39,6 @@ var Detail$1;
37
39
  Detail["DOMAIN"] = "domain";
38
40
  Detail["SDK_VERSION"] = "sdkVersion";
39
41
  })(Detail$1 || (Detail$1 = {}));
40
- var Store$1;
41
- (function (Store) {
42
- Store["EVENTS"] = "events";
43
- Store["RUNTIME"] = "runtime";
44
- })(Store$1 || (Store$1 = {}));
45
- const POLLING_FREQUENCY$1 = 5000;
46
42
 
47
43
  const IMTBL_API$1 = 'https://api.x.immutable.com';
48
44
  async function post$1(path, data) {
@@ -102,6 +98,11 @@ const setItem$1 = (key, payload) => {
102
98
  return false;
103
99
  };
104
100
 
101
+ var Store$1;
102
+ (function (Store) {
103
+ Store["EVENTS"] = "events";
104
+ Store["RUNTIME"] = "runtime";
105
+ })(Store$1 || (Store$1 = {}));
105
106
  // In memory storage for events and other data
106
107
  let EVENT_STORE$1;
107
108
  let RUNTIME_DETAILS$1;
@@ -129,7 +130,7 @@ const getDetail$1 = (key) => {
129
130
  const getAllDetails$1 = () => RUNTIME_DETAILS$1;
130
131
  // Events
131
132
  const getEvents$1 = () => EVENT_STORE$1;
132
- const addEvent = (event) => {
133
+ const addEvent$1 = (event) => {
133
134
  EVENT_STORE$1.push(event);
134
135
  setItem$1(Store$1.EVENTS, EVENT_STORE$1);
135
136
  };
@@ -151,9 +152,7 @@ const flattenProperties$1 = (properties) => {
151
152
  };
152
153
 
153
154
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
154
- const SDK_VERSION$1 = '1.5.2';
155
- let initialised$1 = false;
156
- const isInitialised$1 = () => initialised$1;
155
+ const SDK_VERSION$1 = '1.5.3-alpha';
157
156
  const getReferrer$1 = () => {
158
157
  if (isNode$1()) {
159
158
  return '';
@@ -190,21 +189,28 @@ const getRuntimeDetails$1 = () => {
190
189
  screen: `${window.screen.width}x${window.screen.height}`,
191
190
  };
192
191
  };
192
+ let initialised$1 = false;
193
+ const isInitialised$1 = () => initialised$1;
193
194
  const initialise$2 = async () => {
194
- const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
195
- const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
196
- const body = {
197
- version: 1,
198
- data: {
199
- runtimeDetails,
200
- runtimeId: existingRuntimeId,
201
- },
202
- };
203
- const response = await post$1('/v1/sdk/initialise', body);
204
- // Get runtimeId and store it
205
- const { runtimeId } = response;
206
- storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
207
195
  initialised$1 = true;
196
+ try {
197
+ const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
198
+ const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
199
+ const body = {
200
+ version: 1,
201
+ data: {
202
+ runtimeDetails,
203
+ runtimeId: existingRuntimeId,
204
+ },
205
+ };
206
+ const response = await post$1('/v1/sdk/initialise', body);
207
+ // Get runtimeId and store it
208
+ const { runtimeId } = response;
209
+ storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
210
+ }
211
+ catch (error) {
212
+ initialised$1 = false;
213
+ }
208
214
  };
209
215
 
210
216
  function errorBoundary$1(fn) {
@@ -236,16 +242,31 @@ function isTestEnvironment$1() {
236
242
  return process.env.JEST_WORKER_ID !== undefined;
237
243
  }
238
244
 
245
+ const GLOBALISE_KEY$1 = 'imtbl__metrics';
246
+ const MEMORISE_TIMEFRAME$1 = 1000;
247
+ const MEMORISE_MAX$1 = 1000;
248
+ const getGlobalisedValue$2 = (key, value) => getGlobalisedValue$3(GLOBALISE_KEY$1, key, value);
249
+ const getGlobalisedCachedFunction$1 = (key, fn) => {
250
+ // Some applications (esp backend, or frontends using the split bundles) can sometimes
251
+ // initialise the same request multiple times. This will prevent multiple of the
252
+ // same event,value from being reported in a 1 second period.
253
+ const memorisedFn = memorise(fn, {
254
+ lruOptions: { ttl: MEMORISE_TIMEFRAME$1, max: MEMORISE_MAX$1 },
255
+ });
256
+ return getGlobalisedValue$3(GLOBALISE_KEY$1, key, memorisedFn);
257
+ };
258
+
259
+ const POLLING_FREQUENCY$1 = 5000;
239
260
  // Store the event in the event store
240
- const trackFn = (moduleName, eventName, properties) => {
261
+ const trackFn$1 = (moduleName, eventName, properties) => {
241
262
  const event = {
242
263
  event: `${moduleName}.${eventName}`,
243
264
  time: new Date().toISOString(),
244
265
  ...(properties && { properties: flattenProperties$1(properties) }),
245
266
  };
246
- addEvent(event);
267
+ addEvent$1(event);
247
268
  };
248
- const track = errorBoundary$1(trackFn);
269
+ const track = errorBoundary$1(getGlobalisedCachedFunction$1('track', trackFn$1));
249
270
  // Sending events to the server
250
271
  const flushFn$1 = async () => {
251
272
  // Don't flush if not initialised
@@ -281,9 +302,17 @@ const flushPoll$1 = async () => {
281
302
  await flush$1();
282
303
  setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
283
304
  };
305
+ let flushingStarted$1 = false;
306
+ const startFlushing$1 = () => {
307
+ if (flushingStarted$1) {
308
+ return;
309
+ }
310
+ flushingStarted$1 = true;
311
+ flushPoll$1();
312
+ };
284
313
  // This will get initialised when module is imported.
285
314
  if (!isTestEnvironment$1()) {
286
- errorBoundary$1(flushPoll$1)();
315
+ errorBoundary$1(getGlobalisedValue$2('startFlushing', startFlushing$1))();
287
316
  }
288
317
 
289
318
  const parseIdentity = (params) => {
@@ -307,18 +336,18 @@ const identifyFn = (params) => {
307
336
  };
308
337
  const identify = errorBoundary$1(identifyFn);
309
338
 
310
- const setEnvironmentFn = (env) => {
339
+ const setEnvironmentFn$1 = (env) => {
311
340
  storeDetail$1(Detail$1.ENVIRONMENT, env);
312
341
  };
313
- const setEnvironment = errorBoundary$1(setEnvironmentFn);
314
- const setPassportClientIdFn = (passportClientId) => {
342
+ const setEnvironment = errorBoundary$1(getGlobalisedValue$2('setEnvironment', setEnvironmentFn$1));
343
+ const setPassportClientIdFn$1 = (passportClientId) => {
315
344
  storeDetail$1(Detail$1.PASSPORT_CLIENT_ID, passportClientId);
316
345
  };
317
- const setPassportClientId = errorBoundary$1(setPassportClientIdFn);
318
- const setPublishableApiKeyFn = (publishableApiKey) => {
346
+ const setPassportClientId = errorBoundary$1(getGlobalisedValue$2('setPassportClientId', setPassportClientIdFn$1));
347
+ const setPublishableApiKeyFn$1 = (publishableApiKey) => {
319
348
  storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
320
349
  };
321
- const setPublishableApiKey = errorBoundary$1(setPublishableApiKeyFn);
350
+ const setPublishableApiKey = errorBoundary$1(getGlobalisedValue$2('setPublishableApiKey', setPublishableApiKeyFn$1));
322
351
 
323
352
  var Environment$1;
324
353
  (function (Environment) {
@@ -11238,7 +11267,7 @@ class MultiRollupApiClients {
11238
11267
  }
11239
11268
 
11240
11269
  // eslint-disable-next-line @typescript-eslint/naming-convention
11241
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.2' };
11270
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.3-alpha' };
11242
11271
  const createConfig = ({ basePath, headers, }) => {
11243
11272
  if (!basePath.trim()) {
11244
11273
  throw Error('basePath can not be empty');
@@ -11310,7 +11339,7 @@ class APIError extends Error {
11310
11339
 
11311
11340
  /* eslint-disable implicit-arrow-linebreak */
11312
11341
  const defaultHeaders = {
11313
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.2',
11342
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.3-alpha',
11314
11343
  };
11315
11344
  /**
11316
11345
  * createAPIConfiguration to create a custom Configuration
@@ -11743,7 +11772,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11743
11772
  chainID,
11744
11773
  coreContractAddress,
11745
11774
  registrationContractAddress,
11746
- sdkVersion: 'ts-immutable-sdk-1.5.2',
11775
+ sdkVersion: 'ts-immutable-sdk-1.5.3-alpha',
11747
11776
  });
11748
11777
  /**
11749
11778
  * Sets `sdkVersion` at the time of build
@@ -36921,6 +36950,356 @@ class TokenBridge {
36921
36950
  }
36922
36951
  }
36923
36952
 
36953
+ var lib$1 = {};
36954
+
36955
+ var tinyLru = {};
36956
+
36957
+ /**
36958
+ * tiny-lru
36959
+ *
36960
+ * @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
36961
+ * @license BSD-3-Clause
36962
+ * @version 11.2.5
36963
+ */
36964
+
36965
+ class LRU {
36966
+ constructor (max = 0, ttl = 0, resetTtl = false) {
36967
+ this.first = null;
36968
+ this.items = Object.create(null);
36969
+ this.last = null;
36970
+ this.max = max;
36971
+ this.resetTtl = resetTtl;
36972
+ this.size = 0;
36973
+ this.ttl = ttl;
36974
+ }
36975
+
36976
+ clear () {
36977
+ this.first = null;
36978
+ this.items = Object.create(null);
36979
+ this.last = null;
36980
+ this.size = 0;
36981
+
36982
+ return this;
36983
+ }
36984
+
36985
+ delete (key) {
36986
+ if (this.has(key)) {
36987
+ const item = this.items[key];
36988
+
36989
+ delete this.items[key];
36990
+ this.size--;
36991
+
36992
+ if (item.prev !== null) {
36993
+ item.prev.next = item.next;
36994
+ }
36995
+
36996
+ if (item.next !== null) {
36997
+ item.next.prev = item.prev;
36998
+ }
36999
+
37000
+ if (this.first === item) {
37001
+ this.first = item.next;
37002
+ }
37003
+
37004
+ if (this.last === item) {
37005
+ this.last = item.prev;
37006
+ }
37007
+ }
37008
+
37009
+ return this;
37010
+ }
37011
+
37012
+ entries (keys = this.keys()) {
37013
+ return keys.map(key => [key, this.get(key)]);
37014
+ }
37015
+
37016
+ evict (bypass = false) {
37017
+ if (bypass || this.size > 0) {
37018
+ const item = this.first;
37019
+
37020
+ delete this.items[item.key];
37021
+
37022
+ if (--this.size === 0) {
37023
+ this.first = null;
37024
+ this.last = null;
37025
+ } else {
37026
+ this.first = item.next;
37027
+ this.first.prev = null;
37028
+ }
37029
+ }
37030
+
37031
+ return this;
37032
+ }
37033
+
37034
+ expiresAt (key) {
37035
+ let result;
37036
+
37037
+ if (this.has(key)) {
37038
+ result = this.items[key].expiry;
37039
+ }
37040
+
37041
+ return result;
37042
+ }
37043
+
37044
+ get (key) {
37045
+ let result;
37046
+
37047
+ if (this.has(key)) {
37048
+ const item = this.items[key];
37049
+
37050
+ if (this.ttl > 0 && item.expiry <= Date.now()) {
37051
+ this.delete(key);
37052
+ } else {
37053
+ result = item.value;
37054
+ this.set(key, result, true);
37055
+ }
37056
+ }
37057
+
37058
+ return result;
37059
+ }
37060
+
37061
+ has (key) {
37062
+ return key in this.items;
37063
+ }
37064
+
37065
+ keys () {
37066
+ const result = [];
37067
+ let x = this.first;
37068
+
37069
+ while (x !== null) {
37070
+ result.push(x.key);
37071
+ x = x.next;
37072
+ }
37073
+
37074
+ return result;
37075
+ }
37076
+
37077
+ set (key, value, bypass = false, resetTtl = this.resetTtl) {
37078
+ let item;
37079
+
37080
+ if (bypass || this.has(key)) {
37081
+ item = this.items[key];
37082
+ item.value = value;
37083
+
37084
+ if (bypass === false && resetTtl) {
37085
+ item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
37086
+ }
37087
+
37088
+ if (this.last !== item) {
37089
+ const last = this.last,
37090
+ next = item.next,
37091
+ prev = item.prev;
37092
+
37093
+ if (this.first === item) {
37094
+ this.first = item.next;
37095
+ }
37096
+
37097
+ item.next = null;
37098
+ item.prev = this.last;
37099
+ last.next = item;
37100
+
37101
+ if (prev !== null) {
37102
+ prev.next = next;
37103
+ }
37104
+
37105
+ if (next !== null) {
37106
+ next.prev = prev;
37107
+ }
37108
+ }
37109
+ } else {
37110
+ if (this.max > 0 && this.size === this.max) {
37111
+ this.evict(true);
37112
+ }
37113
+
37114
+ item = this.items[key] = {
37115
+ expiry: this.ttl > 0 ? Date.now() + this.ttl : this.ttl,
37116
+ key: key,
37117
+ prev: this.last,
37118
+ next: null,
37119
+ value
37120
+ };
37121
+
37122
+ if (++this.size === 1) {
37123
+ this.first = item;
37124
+ } else {
37125
+ this.last.next = item;
37126
+ }
37127
+ }
37128
+
37129
+ this.last = item;
37130
+
37131
+ return this;
37132
+ }
37133
+
37134
+ values (keys = this.keys()) {
37135
+ return keys.map(key => this.get(key));
37136
+ }
37137
+ }
37138
+
37139
+ function lru (max = 1000, ttl = 0, resetTtl = false) {
37140
+ if (isNaN(max) || max < 0) {
37141
+ throw new TypeError("Invalid max value");
37142
+ }
37143
+
37144
+ if (isNaN(ttl) || ttl < 0) {
37145
+ throw new TypeError("Invalid ttl value");
37146
+ }
37147
+
37148
+ if (typeof resetTtl !== "boolean") {
37149
+ throw new TypeError("Invalid resetTtl value");
37150
+ }
37151
+
37152
+ return new LRU(max, ttl, resetTtl);
37153
+ }
37154
+
37155
+ tinyLru.LRU = LRU;
37156
+ tinyLru.lru = lru;
37157
+
37158
+ (function (exports) {
37159
+ Object.defineProperty(exports, "__esModule", { value: true });
37160
+ exports.memorise = void 0;
37161
+ const tiny_lru_1 = tinyLru;
37162
+ const defaultLRUOptions = {
37163
+ max: 1000,
37164
+ };
37165
+ /**
37166
+ * Returns a memorised version of the target function.
37167
+ * The cache key depends on the arguments passed to the function.
37168
+ *
37169
+ * Pass in options to customise the caching behaviour
37170
+ * @param cachedFn Function to cache
37171
+ * @param options Memorization and LRUCache Options
37172
+ */
37173
+ const memorise = (cachedFn, options = {}) => {
37174
+ // Extract defaults
37175
+ const { cache, cacheKeyResolver = defaultGenCacheKey, onHit, lruOptions = {}, } = options;
37176
+ const cacheOptions = { ...defaultLRUOptions, ...lruOptions };
37177
+ const _cache = (cache ||
37178
+ (0, tiny_lru_1.lru)(cacheOptions.max, cacheOptions.ttl));
37179
+ // Cached fn
37180
+ const returnFn = (...args) => {
37181
+ const cacheKey = cacheKeyResolver(...args);
37182
+ const cachedValue = _cache.get(cacheKey);
37183
+ const keyCached = _cache.has(cacheKey);
37184
+ // Use cached key, even if value is void
37185
+ if (keyCached) {
37186
+ // If onHit handler is there, run it
37187
+ if (onHit) {
37188
+ onHit(cacheKey, cachedValue, _cache);
37189
+ }
37190
+ return cachedValue;
37191
+ }
37192
+ // No cache hit, run function and cache result
37193
+ const result = cachedFn.apply(this, args);
37194
+ _cache.set(cacheKey, result);
37195
+ return result;
37196
+ };
37197
+ // Expose the cache
37198
+ returnFn._cache = _cache;
37199
+ return returnFn;
37200
+ };
37201
+ exports.memorise = memorise;
37202
+ // Default export
37203
+ exports.default = exports.memorise;
37204
+ /**
37205
+ * Generic args handler function.
37206
+ * @param args Argument array
37207
+ */
37208
+ const defaultGenCacheKey = (...args) => {
37209
+ if (args.length === 0) {
37210
+ return "no-args";
37211
+ }
37212
+ return args
37213
+ .map((val) => {
37214
+ if (val === undefined) {
37215
+ return "undefined";
37216
+ }
37217
+ if (val === null) {
37218
+ return "null";
37219
+ }
37220
+ if (Array.isArray(val)) {
37221
+ return `[${defaultGenCacheKey(...val)}]`;
37222
+ }
37223
+ if (typeof val === "object") {
37224
+ return `{${defaultGenCacheKey(...sortedObjectEntries(val))}}`;
37225
+ }
37226
+ return JSON.stringify(val);
37227
+ })
37228
+ .join(",");
37229
+ };
37230
+ const sortedObjectEntries = (obj) => {
37231
+ return Object.entries(obj).sort((a, b) => {
37232
+ if (a[0] < b[0]) {
37233
+ return -1;
37234
+ }
37235
+ return 1;
37236
+ });
37237
+ };
37238
+
37239
+ } (lib$1));
37240
+
37241
+ var lib = {};
37242
+
37243
+ Object.defineProperty(lib, "__esModule", { value: true });
37244
+ lib.clearGlobalNamespace = getGlobalisedValue_1 = lib.getGlobalisedValue = void 0;
37245
+ const GLOBALISE_KEY_PREFIX = "globalise__singleton__";
37246
+ const fallbackGlobal = {};
37247
+ const getGlobalObject = () => {
37248
+ if (typeof window !== "undefined") {
37249
+ return window;
37250
+ }
37251
+ if (typeof globalThis !== "undefined") {
37252
+ return globalThis;
37253
+ }
37254
+ return fallbackGlobal;
37255
+ };
37256
+ const validateInputs = (namespace, key) => {
37257
+ if (typeof namespace !== "string") {
37258
+ throw "Invalid namespace key";
37259
+ }
37260
+ if (typeof key !== "string") {
37261
+ throw "Invalid item key";
37262
+ }
37263
+ };
37264
+ const createGlobalisedKey = (namespace) => {
37265
+ return `${GLOBALISE_KEY_PREFIX}${namespace}`;
37266
+ };
37267
+ const getGlobalScopedObject = (namespace) => {
37268
+ const globalObject = getGlobalObject();
37269
+ const GLOBALISE_KEY = createGlobalisedKey(namespace);
37270
+ // Initialise global object
37271
+ if (!globalObject[GLOBALISE_KEY]) {
37272
+ globalObject[GLOBALISE_KEY] = {};
37273
+ }
37274
+ return globalObject[GLOBALISE_KEY];
37275
+ };
37276
+ const getSingleton = (namespace, key) => {
37277
+ const scopedObject = getGlobalScopedObject(namespace);
37278
+ return scopedObject[key] || undefined;
37279
+ };
37280
+ const setSingleton = (namespace, key, value) => {
37281
+ const scopedObject = getGlobalScopedObject(namespace);
37282
+ scopedObject[key] = value;
37283
+ };
37284
+ const getGlobalisedValue$1 = (namespace, key, value) => {
37285
+ validateInputs(namespace, key);
37286
+ const existing = getSingleton(namespace, key);
37287
+ if (existing !== undefined) {
37288
+ return existing;
37289
+ }
37290
+ setSingleton(namespace, key, value);
37291
+ return value;
37292
+ };
37293
+ var getGlobalisedValue_1 = lib.getGlobalisedValue = getGlobalisedValue$1;
37294
+ const clearGlobalNamespace = (namespace) => {
37295
+ const globalObject = getGlobalObject();
37296
+ const globalisedKey = createGlobalisedKey(namespace);
37297
+ if (globalObject[globalisedKey] !== undefined) {
37298
+ delete globalObject[globalisedKey];
37299
+ }
37300
+ };
37301
+ lib.clearGlobalNamespace = clearGlobalNamespace;
37302
+
36924
37303
  const isNode = () => typeof window === 'undefined';
36925
37304
  const isBrowser = () => !isNode();
36926
37305
 
@@ -36934,12 +37313,6 @@ var Detail;
36934
37313
  Detail["DOMAIN"] = "domain";
36935
37314
  Detail["SDK_VERSION"] = "sdkVersion";
36936
37315
  })(Detail || (Detail = {}));
36937
- var Store;
36938
- (function (Store) {
36939
- Store["EVENTS"] = "events";
36940
- Store["RUNTIME"] = "runtime";
36941
- })(Store || (Store = {}));
36942
- const POLLING_FREQUENCY = 5000;
36943
37316
 
36944
37317
  const IMTBL_API = 'https://api.x.immutable.com';
36945
37318
  async function post(path, data) {
@@ -36999,6 +37372,11 @@ const setItem = (key, payload) => {
36999
37372
  return false;
37000
37373
  };
37001
37374
 
37375
+ var Store;
37376
+ (function (Store) {
37377
+ Store["EVENTS"] = "events";
37378
+ Store["RUNTIME"] = "runtime";
37379
+ })(Store || (Store = {}));
37002
37380
  // In memory storage for events and other data
37003
37381
  let EVENT_STORE;
37004
37382
  let RUNTIME_DETAILS;
@@ -37026,6 +37404,10 @@ const getDetail = (key) => {
37026
37404
  const getAllDetails = () => RUNTIME_DETAILS;
37027
37405
  // Events
37028
37406
  const getEvents = () => EVENT_STORE;
37407
+ const addEvent = (event) => {
37408
+ EVENT_STORE.push(event);
37409
+ setItem(Store.EVENTS, EVENT_STORE);
37410
+ };
37029
37411
  const removeSentEvents = (numberOfEvents) => {
37030
37412
  EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
37031
37413
  setItem(Store.EVENTS, EVENT_STORE);
@@ -37044,9 +37426,7 @@ const flattenProperties = (properties) => {
37044
37426
  };
37045
37427
 
37046
37428
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
37047
- const SDK_VERSION = '1.5.2';
37048
- let initialised = false;
37049
- const isInitialised = () => initialised;
37429
+ const SDK_VERSION = '1.5.3-alpha';
37050
37430
  const getReferrer = () => {
37051
37431
  if (isNode()) {
37052
37432
  return '';
@@ -37083,21 +37463,28 @@ const getRuntimeDetails = () => {
37083
37463
  screen: `${window.screen.width}x${window.screen.height}`,
37084
37464
  };
37085
37465
  };
37466
+ let initialised = false;
37467
+ const isInitialised = () => initialised;
37086
37468
  const initialise = async () => {
37087
- const runtimeDetails = flattenProperties(getRuntimeDetails());
37088
- const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
37089
- const body = {
37090
- version: 1,
37091
- data: {
37092
- runtimeDetails,
37093
- runtimeId: existingRuntimeId,
37094
- },
37095
- };
37096
- const response = await post('/v1/sdk/initialise', body);
37097
- // Get runtimeId and store it
37098
- const { runtimeId } = response;
37099
- storeDetail(Detail.RUNTIME_ID, runtimeId);
37100
37469
  initialised = true;
37470
+ try {
37471
+ const runtimeDetails = flattenProperties(getRuntimeDetails());
37472
+ const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
37473
+ const body = {
37474
+ version: 1,
37475
+ data: {
37476
+ runtimeDetails,
37477
+ runtimeId: existingRuntimeId,
37478
+ },
37479
+ };
37480
+ const response = await post('/v1/sdk/initialise', body);
37481
+ // Get runtimeId and store it
37482
+ const { runtimeId } = response;
37483
+ storeDetail(Detail.RUNTIME_ID, runtimeId);
37484
+ }
37485
+ catch (error) {
37486
+ initialised = false;
37487
+ }
37101
37488
  };
37102
37489
 
37103
37490
  function errorBoundary(fn) {
@@ -37128,6 +37515,32 @@ function isTestEnvironment() {
37128
37515
  // Just use process.env.CI for now.
37129
37516
  return process.env.JEST_WORKER_ID !== undefined;
37130
37517
  }
37518
+
37519
+ const GLOBALISE_KEY = 'imtbl__metrics';
37520
+ const MEMORISE_TIMEFRAME = 1000;
37521
+ const MEMORISE_MAX = 1000;
37522
+ const getGlobalisedValue = (key, value) => getGlobalisedValue_1(GLOBALISE_KEY, key, value);
37523
+ const getGlobalisedCachedFunction = (key, fn) => {
37524
+ // Some applications (esp backend, or frontends using the split bundles) can sometimes
37525
+ // initialise the same request multiple times. This will prevent multiple of the
37526
+ // same event,value from being reported in a 1 second period.
37527
+ const memorisedFn = lib$1.memorise(fn, {
37528
+ lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
37529
+ });
37530
+ return getGlobalisedValue_1(GLOBALISE_KEY, key, memorisedFn);
37531
+ };
37532
+
37533
+ const POLLING_FREQUENCY = 5000;
37534
+ // Store the event in the event store
37535
+ const trackFn = (moduleName, eventName, properties) => {
37536
+ const event = {
37537
+ event: `${moduleName}.${eventName}`,
37538
+ time: new Date().toISOString(),
37539
+ ...(properties && { properties: flattenProperties(properties) }),
37540
+ };
37541
+ addEvent(event);
37542
+ };
37543
+ errorBoundary(getGlobalisedCachedFunction('track', trackFn));
37131
37544
  // Sending events to the server
37132
37545
  const flushFn = async () => {
37133
37546
  // Don't flush if not initialised
@@ -37163,11 +37576,32 @@ const flushPoll = async () => {
37163
37576
  await flush();
37164
37577
  setTimeout(flushPoll, POLLING_FREQUENCY);
37165
37578
  };
37579
+ let flushingStarted = false;
37580
+ const startFlushing = () => {
37581
+ if (flushingStarted) {
37582
+ return;
37583
+ }
37584
+ flushingStarted = true;
37585
+ flushPoll();
37586
+ };
37166
37587
  // This will get initialised when module is imported.
37167
37588
  if (!isTestEnvironment()) {
37168
- errorBoundary(flushPoll)();
37589
+ errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
37169
37590
  }
37170
37591
 
37592
+ const setEnvironmentFn = (env) => {
37593
+ storeDetail(Detail.ENVIRONMENT, env);
37594
+ };
37595
+ errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
37596
+ const setPassportClientIdFn = (passportClientId) => {
37597
+ storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
37598
+ };
37599
+ errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
37600
+ const setPublishableApiKeyFn = (publishableApiKey) => {
37601
+ storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
37602
+ };
37603
+ errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
37604
+
37171
37605
  var Environment;
37172
37606
  (function (Environment) {
37173
37607
  Environment["PRODUCTION"] = "production";
@@ -42159,7 +42593,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42159
42593
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
42160
42594
  };
42161
42595
 
42162
- const SDK_VERSION_MARKER = '1.5.2';
42596
+ const SDK_VERSION_MARKER = '1.5.3-alpha';
42163
42597
  // This SDK version is replaced by the `yarn build` command ran on the root level
42164
42598
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42165
42599