@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.
- package/dist/blockchain_data.js +81 -24
- package/dist/browser/checkout/BridgeWidget-2e0093b4.js +1 -0
- package/dist/browser/checkout/OnRampWidget-444ebe2b.js +1 -0
- package/dist/browser/checkout/SaleWidget-5f6ea630.js +2 -0
- package/dist/browser/checkout/SpendingCapHero-a6ef1dcc.js +1 -0
- package/dist/browser/checkout/SwapWidget-aee793d7.js +1 -0
- package/dist/browser/checkout/TopUpView-def404d5.js +1 -0
- package/dist/browser/checkout/WalletWidget-f87f80b4.js +1 -0
- package/dist/browser/checkout/auto-track-e03d4bb9.js +1 -0
- package/dist/browser/checkout/balance-c8477685.js +1 -0
- package/dist/browser/checkout/index-35beb3eb.js +1 -0
- package/dist/browser/checkout/index-43973ac4.js +1 -0
- package/dist/browser/checkout/index-49582766.js +1 -0
- package/dist/browser/checkout/index-500dddb2.js +1 -0
- package/dist/browser/checkout/index-6984b667.js +773 -0
- package/dist/browser/checkout/index-a8155f8b.js +1 -0
- package/dist/browser/checkout/index-ea3645ce.js +106 -0
- package/dist/browser/checkout/index.umd-9e885d58.js +1 -0
- package/dist/browser/checkout/is-plan-event-enabled-80f76ce6.js +1 -0
- package/dist/browser/checkout/retry-fc920719.js +1 -0
- package/dist/browser/checkout/sdk.js +22 -6
- package/dist/browser/checkout/useTransakEvents-cffde72e.js +2 -0
- package/dist/browser/checkout/widgets.js +1 -872
- package/dist/checkout.js +496 -54
- package/dist/config.js +59 -26
- package/dist/index.browser.js +28 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +494 -60
- package/dist/index.js +494 -60
- package/dist/orderbook.js +80 -23
- package/dist/passport.js +65 -27
- package/dist/x.js +81 -24
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var globalAxios$1 = require('axios');
|
|
4
|
+
var lruMemorise = require('lru-memorise');
|
|
5
|
+
var globalConst = require('global-const');
|
|
4
6
|
var coreSdk = require('@imtbl/core-sdk');
|
|
5
7
|
var oidcClientTs = require('oidc-client-ts');
|
|
6
8
|
var jwt_decode = require('jwt-decode');
|
|
@@ -59,12 +61,6 @@ var Detail$1;
|
|
|
59
61
|
Detail["DOMAIN"] = "domain";
|
|
60
62
|
Detail["SDK_VERSION"] = "sdkVersion";
|
|
61
63
|
})(Detail$1 || (Detail$1 = {}));
|
|
62
|
-
var Store$1;
|
|
63
|
-
(function (Store) {
|
|
64
|
-
Store["EVENTS"] = "events";
|
|
65
|
-
Store["RUNTIME"] = "runtime";
|
|
66
|
-
})(Store$1 || (Store$1 = {}));
|
|
67
|
-
const POLLING_FREQUENCY$1 = 5000;
|
|
68
64
|
|
|
69
65
|
const IMTBL_API$1 = 'https://api.x.immutable.com';
|
|
70
66
|
async function post$1(path, data) {
|
|
@@ -124,6 +120,11 @@ const setItem$1 = (key, payload) => {
|
|
|
124
120
|
return false;
|
|
125
121
|
};
|
|
126
122
|
|
|
123
|
+
var Store$1;
|
|
124
|
+
(function (Store) {
|
|
125
|
+
Store["EVENTS"] = "events";
|
|
126
|
+
Store["RUNTIME"] = "runtime";
|
|
127
|
+
})(Store$1 || (Store$1 = {}));
|
|
127
128
|
// In memory storage for events and other data
|
|
128
129
|
let EVENT_STORE$1;
|
|
129
130
|
let RUNTIME_DETAILS$1;
|
|
@@ -151,7 +152,7 @@ const getDetail$1 = (key) => {
|
|
|
151
152
|
const getAllDetails$1 = () => RUNTIME_DETAILS$1;
|
|
152
153
|
// Events
|
|
153
154
|
const getEvents$1 = () => EVENT_STORE$1;
|
|
154
|
-
const addEvent = (event) => {
|
|
155
|
+
const addEvent$1 = (event) => {
|
|
155
156
|
EVENT_STORE$1.push(event);
|
|
156
157
|
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
157
158
|
};
|
|
@@ -173,9 +174,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
173
174
|
};
|
|
174
175
|
|
|
175
176
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
176
|
-
const SDK_VERSION$1 = '1.5.
|
|
177
|
-
let initialised$1 = false;
|
|
178
|
-
const isInitialised$1 = () => initialised$1;
|
|
177
|
+
const SDK_VERSION$1 = '1.5.3-alpha.1';
|
|
179
178
|
const getReferrer$1 = () => {
|
|
180
179
|
if (isNode$1()) {
|
|
181
180
|
return '';
|
|
@@ -212,21 +211,28 @@ const getRuntimeDetails$1 = () => {
|
|
|
212
211
|
screen: `${window.screen.width}x${window.screen.height}`,
|
|
213
212
|
};
|
|
214
213
|
};
|
|
214
|
+
let initialised$1 = false;
|
|
215
|
+
const isInitialised$1 = () => initialised$1;
|
|
215
216
|
const initialise$2 = async () => {
|
|
216
|
-
const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
|
|
217
|
-
const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
|
|
218
|
-
const body = {
|
|
219
|
-
version: 1,
|
|
220
|
-
data: {
|
|
221
|
-
runtimeDetails,
|
|
222
|
-
runtimeId: existingRuntimeId,
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
const response = await post$1('/v1/sdk/initialise', body);
|
|
226
|
-
// Get runtimeId and store it
|
|
227
|
-
const { runtimeId } = response;
|
|
228
|
-
storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
|
|
229
217
|
initialised$1 = true;
|
|
218
|
+
try {
|
|
219
|
+
const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
|
|
220
|
+
const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
|
|
221
|
+
const body = {
|
|
222
|
+
version: 1,
|
|
223
|
+
data: {
|
|
224
|
+
runtimeDetails,
|
|
225
|
+
runtimeId: existingRuntimeId,
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
const response = await post$1('/v1/sdk/initialise', body);
|
|
229
|
+
// Get runtimeId and store it
|
|
230
|
+
const { runtimeId } = response;
|
|
231
|
+
storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
initialised$1 = false;
|
|
235
|
+
}
|
|
230
236
|
};
|
|
231
237
|
|
|
232
238
|
function errorBoundary$1(fn) {
|
|
@@ -258,16 +264,31 @@ function isTestEnvironment$1() {
|
|
|
258
264
|
return process.env.JEST_WORKER_ID !== undefined;
|
|
259
265
|
}
|
|
260
266
|
|
|
267
|
+
const GLOBALISE_KEY$1 = 'imtbl__metrics';
|
|
268
|
+
const MEMORISE_TIMEFRAME$1 = 1000;
|
|
269
|
+
const MEMORISE_MAX$1 = 1000;
|
|
270
|
+
const getGlobalisedValue$2 = (key, value) => globalConst.getGlobalisedValue(GLOBALISE_KEY$1, key, value);
|
|
271
|
+
const getGlobalisedCachedFunction$1 = (key, fn) => {
|
|
272
|
+
// Some applications (esp backend, or frontends using the split bundles) can sometimes
|
|
273
|
+
// initialise the same request multiple times. This will prevent multiple of the
|
|
274
|
+
// same event,value from being reported in a 1 second period.
|
|
275
|
+
const memorisedFn = lruMemorise.memorise(fn, {
|
|
276
|
+
lruOptions: { ttl: MEMORISE_TIMEFRAME$1, max: MEMORISE_MAX$1 },
|
|
277
|
+
});
|
|
278
|
+
return globalConst.getGlobalisedValue(GLOBALISE_KEY$1, key, memorisedFn);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const POLLING_FREQUENCY$1 = 5000;
|
|
261
282
|
// Store the event in the event store
|
|
262
|
-
const trackFn = (moduleName, eventName, properties) => {
|
|
283
|
+
const trackFn$1 = (moduleName, eventName, properties) => {
|
|
263
284
|
const event = {
|
|
264
285
|
event: `${moduleName}.${eventName}`,
|
|
265
286
|
time: new Date().toISOString(),
|
|
266
287
|
...(properties && { properties: flattenProperties$1(properties) }),
|
|
267
288
|
};
|
|
268
|
-
addEvent(event);
|
|
289
|
+
addEvent$1(event);
|
|
269
290
|
};
|
|
270
|
-
const track = errorBoundary$1(trackFn);
|
|
291
|
+
const track = errorBoundary$1(getGlobalisedCachedFunction$1('track', trackFn$1));
|
|
271
292
|
// Sending events to the server
|
|
272
293
|
const flushFn$1 = async () => {
|
|
273
294
|
// Don't flush if not initialised
|
|
@@ -303,9 +324,17 @@ const flushPoll$1 = async () => {
|
|
|
303
324
|
await flush$1();
|
|
304
325
|
setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
|
|
305
326
|
};
|
|
327
|
+
let flushingStarted$1 = false;
|
|
328
|
+
const startFlushing$1 = () => {
|
|
329
|
+
if (flushingStarted$1) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
flushingStarted$1 = true;
|
|
333
|
+
flushPoll$1();
|
|
334
|
+
};
|
|
306
335
|
// This will get initialised when module is imported.
|
|
307
336
|
if (!isTestEnvironment$1()) {
|
|
308
|
-
errorBoundary$1(
|
|
337
|
+
errorBoundary$1(getGlobalisedValue$2('startFlushing', startFlushing$1))();
|
|
309
338
|
}
|
|
310
339
|
|
|
311
340
|
const parseIdentity = (params) => {
|
|
@@ -329,18 +358,18 @@ const identifyFn = (params) => {
|
|
|
329
358
|
};
|
|
330
359
|
const identify = errorBoundary$1(identifyFn);
|
|
331
360
|
|
|
332
|
-
const setEnvironmentFn = (env) => {
|
|
361
|
+
const setEnvironmentFn$1 = (env) => {
|
|
333
362
|
storeDetail$1(Detail$1.ENVIRONMENT, env);
|
|
334
363
|
};
|
|
335
|
-
const setEnvironment = errorBoundary$1(setEnvironmentFn);
|
|
336
|
-
const setPassportClientIdFn = (passportClientId) => {
|
|
364
|
+
const setEnvironment = errorBoundary$1(getGlobalisedValue$2('setEnvironment', setEnvironmentFn$1));
|
|
365
|
+
const setPassportClientIdFn$1 = (passportClientId) => {
|
|
337
366
|
storeDetail$1(Detail$1.PASSPORT_CLIENT_ID, passportClientId);
|
|
338
367
|
};
|
|
339
|
-
const setPassportClientId = errorBoundary$1(setPassportClientIdFn);
|
|
340
|
-
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
368
|
+
const setPassportClientId = errorBoundary$1(getGlobalisedValue$2('setPassportClientId', setPassportClientIdFn$1));
|
|
369
|
+
const setPublishableApiKeyFn$1 = (publishableApiKey) => {
|
|
341
370
|
storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
342
371
|
};
|
|
343
|
-
const setPublishableApiKey = errorBoundary$1(setPublishableApiKeyFn);
|
|
372
|
+
const setPublishableApiKey = errorBoundary$1(getGlobalisedValue$2('setPublishableApiKey', setPublishableApiKeyFn$1));
|
|
344
373
|
|
|
345
374
|
var Environment$1;
|
|
346
375
|
(function (Environment) {
|
|
@@ -11260,7 +11289,7 @@ class MultiRollupApiClients {
|
|
|
11260
11289
|
}
|
|
11261
11290
|
|
|
11262
11291
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11263
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.
|
|
11292
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.3-alpha.1' };
|
|
11264
11293
|
const createConfig = ({ basePath, headers, }) => {
|
|
11265
11294
|
if (!basePath.trim()) {
|
|
11266
11295
|
throw Error('basePath can not be empty');
|
|
@@ -11332,7 +11361,7 @@ class APIError extends Error {
|
|
|
11332
11361
|
|
|
11333
11362
|
/* eslint-disable implicit-arrow-linebreak */
|
|
11334
11363
|
const defaultHeaders = {
|
|
11335
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.
|
|
11364
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.3-alpha.1',
|
|
11336
11365
|
};
|
|
11337
11366
|
/**
|
|
11338
11367
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11765,7 +11794,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11765
11794
|
chainID,
|
|
11766
11795
|
coreContractAddress,
|
|
11767
11796
|
registrationContractAddress,
|
|
11768
|
-
sdkVersion: 'ts-immutable-sdk-1.5.
|
|
11797
|
+
sdkVersion: 'ts-immutable-sdk-1.5.3-alpha.1',
|
|
11769
11798
|
});
|
|
11770
11799
|
/**
|
|
11771
11800
|
* Sets `sdkVersion` at the time of build
|
|
@@ -36943,6 +36972,356 @@ class TokenBridge {
|
|
|
36943
36972
|
}
|
|
36944
36973
|
}
|
|
36945
36974
|
|
|
36975
|
+
var lib$1 = {};
|
|
36976
|
+
|
|
36977
|
+
var tinyLru = {};
|
|
36978
|
+
|
|
36979
|
+
/**
|
|
36980
|
+
* tiny-lru
|
|
36981
|
+
*
|
|
36982
|
+
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
|
|
36983
|
+
* @license BSD-3-Clause
|
|
36984
|
+
* @version 11.2.5
|
|
36985
|
+
*/
|
|
36986
|
+
|
|
36987
|
+
class LRU {
|
|
36988
|
+
constructor (max = 0, ttl = 0, resetTtl = false) {
|
|
36989
|
+
this.first = null;
|
|
36990
|
+
this.items = Object.create(null);
|
|
36991
|
+
this.last = null;
|
|
36992
|
+
this.max = max;
|
|
36993
|
+
this.resetTtl = resetTtl;
|
|
36994
|
+
this.size = 0;
|
|
36995
|
+
this.ttl = ttl;
|
|
36996
|
+
}
|
|
36997
|
+
|
|
36998
|
+
clear () {
|
|
36999
|
+
this.first = null;
|
|
37000
|
+
this.items = Object.create(null);
|
|
37001
|
+
this.last = null;
|
|
37002
|
+
this.size = 0;
|
|
37003
|
+
|
|
37004
|
+
return this;
|
|
37005
|
+
}
|
|
37006
|
+
|
|
37007
|
+
delete (key) {
|
|
37008
|
+
if (this.has(key)) {
|
|
37009
|
+
const item = this.items[key];
|
|
37010
|
+
|
|
37011
|
+
delete this.items[key];
|
|
37012
|
+
this.size--;
|
|
37013
|
+
|
|
37014
|
+
if (item.prev !== null) {
|
|
37015
|
+
item.prev.next = item.next;
|
|
37016
|
+
}
|
|
37017
|
+
|
|
37018
|
+
if (item.next !== null) {
|
|
37019
|
+
item.next.prev = item.prev;
|
|
37020
|
+
}
|
|
37021
|
+
|
|
37022
|
+
if (this.first === item) {
|
|
37023
|
+
this.first = item.next;
|
|
37024
|
+
}
|
|
37025
|
+
|
|
37026
|
+
if (this.last === item) {
|
|
37027
|
+
this.last = item.prev;
|
|
37028
|
+
}
|
|
37029
|
+
}
|
|
37030
|
+
|
|
37031
|
+
return this;
|
|
37032
|
+
}
|
|
37033
|
+
|
|
37034
|
+
entries (keys = this.keys()) {
|
|
37035
|
+
return keys.map(key => [key, this.get(key)]);
|
|
37036
|
+
}
|
|
37037
|
+
|
|
37038
|
+
evict (bypass = false) {
|
|
37039
|
+
if (bypass || this.size > 0) {
|
|
37040
|
+
const item = this.first;
|
|
37041
|
+
|
|
37042
|
+
delete this.items[item.key];
|
|
37043
|
+
|
|
37044
|
+
if (--this.size === 0) {
|
|
37045
|
+
this.first = null;
|
|
37046
|
+
this.last = null;
|
|
37047
|
+
} else {
|
|
37048
|
+
this.first = item.next;
|
|
37049
|
+
this.first.prev = null;
|
|
37050
|
+
}
|
|
37051
|
+
}
|
|
37052
|
+
|
|
37053
|
+
return this;
|
|
37054
|
+
}
|
|
37055
|
+
|
|
37056
|
+
expiresAt (key) {
|
|
37057
|
+
let result;
|
|
37058
|
+
|
|
37059
|
+
if (this.has(key)) {
|
|
37060
|
+
result = this.items[key].expiry;
|
|
37061
|
+
}
|
|
37062
|
+
|
|
37063
|
+
return result;
|
|
37064
|
+
}
|
|
37065
|
+
|
|
37066
|
+
get (key) {
|
|
37067
|
+
let result;
|
|
37068
|
+
|
|
37069
|
+
if (this.has(key)) {
|
|
37070
|
+
const item = this.items[key];
|
|
37071
|
+
|
|
37072
|
+
if (this.ttl > 0 && item.expiry <= Date.now()) {
|
|
37073
|
+
this.delete(key);
|
|
37074
|
+
} else {
|
|
37075
|
+
result = item.value;
|
|
37076
|
+
this.set(key, result, true);
|
|
37077
|
+
}
|
|
37078
|
+
}
|
|
37079
|
+
|
|
37080
|
+
return result;
|
|
37081
|
+
}
|
|
37082
|
+
|
|
37083
|
+
has (key) {
|
|
37084
|
+
return key in this.items;
|
|
37085
|
+
}
|
|
37086
|
+
|
|
37087
|
+
keys () {
|
|
37088
|
+
const result = [];
|
|
37089
|
+
let x = this.first;
|
|
37090
|
+
|
|
37091
|
+
while (x !== null) {
|
|
37092
|
+
result.push(x.key);
|
|
37093
|
+
x = x.next;
|
|
37094
|
+
}
|
|
37095
|
+
|
|
37096
|
+
return result;
|
|
37097
|
+
}
|
|
37098
|
+
|
|
37099
|
+
set (key, value, bypass = false, resetTtl = this.resetTtl) {
|
|
37100
|
+
let item;
|
|
37101
|
+
|
|
37102
|
+
if (bypass || this.has(key)) {
|
|
37103
|
+
item = this.items[key];
|
|
37104
|
+
item.value = value;
|
|
37105
|
+
|
|
37106
|
+
if (bypass === false && resetTtl) {
|
|
37107
|
+
item.expiry = this.ttl > 0 ? Date.now() + this.ttl : this.ttl;
|
|
37108
|
+
}
|
|
37109
|
+
|
|
37110
|
+
if (this.last !== item) {
|
|
37111
|
+
const last = this.last,
|
|
37112
|
+
next = item.next,
|
|
37113
|
+
prev = item.prev;
|
|
37114
|
+
|
|
37115
|
+
if (this.first === item) {
|
|
37116
|
+
this.first = item.next;
|
|
37117
|
+
}
|
|
37118
|
+
|
|
37119
|
+
item.next = null;
|
|
37120
|
+
item.prev = this.last;
|
|
37121
|
+
last.next = item;
|
|
37122
|
+
|
|
37123
|
+
if (prev !== null) {
|
|
37124
|
+
prev.next = next;
|
|
37125
|
+
}
|
|
37126
|
+
|
|
37127
|
+
if (next !== null) {
|
|
37128
|
+
next.prev = prev;
|
|
37129
|
+
}
|
|
37130
|
+
}
|
|
37131
|
+
} else {
|
|
37132
|
+
if (this.max > 0 && this.size === this.max) {
|
|
37133
|
+
this.evict(true);
|
|
37134
|
+
}
|
|
37135
|
+
|
|
37136
|
+
item = this.items[key] = {
|
|
37137
|
+
expiry: this.ttl > 0 ? Date.now() + this.ttl : this.ttl,
|
|
37138
|
+
key: key,
|
|
37139
|
+
prev: this.last,
|
|
37140
|
+
next: null,
|
|
37141
|
+
value
|
|
37142
|
+
};
|
|
37143
|
+
|
|
37144
|
+
if (++this.size === 1) {
|
|
37145
|
+
this.first = item;
|
|
37146
|
+
} else {
|
|
37147
|
+
this.last.next = item;
|
|
37148
|
+
}
|
|
37149
|
+
}
|
|
37150
|
+
|
|
37151
|
+
this.last = item;
|
|
37152
|
+
|
|
37153
|
+
return this;
|
|
37154
|
+
}
|
|
37155
|
+
|
|
37156
|
+
values (keys = this.keys()) {
|
|
37157
|
+
return keys.map(key => this.get(key));
|
|
37158
|
+
}
|
|
37159
|
+
}
|
|
37160
|
+
|
|
37161
|
+
function lru (max = 1000, ttl = 0, resetTtl = false) {
|
|
37162
|
+
if (isNaN(max) || max < 0) {
|
|
37163
|
+
throw new TypeError("Invalid max value");
|
|
37164
|
+
}
|
|
37165
|
+
|
|
37166
|
+
if (isNaN(ttl) || ttl < 0) {
|
|
37167
|
+
throw new TypeError("Invalid ttl value");
|
|
37168
|
+
}
|
|
37169
|
+
|
|
37170
|
+
if (typeof resetTtl !== "boolean") {
|
|
37171
|
+
throw new TypeError("Invalid resetTtl value");
|
|
37172
|
+
}
|
|
37173
|
+
|
|
37174
|
+
return new LRU(max, ttl, resetTtl);
|
|
37175
|
+
}
|
|
37176
|
+
|
|
37177
|
+
tinyLru.LRU = LRU;
|
|
37178
|
+
tinyLru.lru = lru;
|
|
37179
|
+
|
|
37180
|
+
(function (exports) {
|
|
37181
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37182
|
+
exports.memorise = void 0;
|
|
37183
|
+
const tiny_lru_1 = tinyLru;
|
|
37184
|
+
const defaultLRUOptions = {
|
|
37185
|
+
max: 1000,
|
|
37186
|
+
};
|
|
37187
|
+
/**
|
|
37188
|
+
* Returns a memorised version of the target function.
|
|
37189
|
+
* The cache key depends on the arguments passed to the function.
|
|
37190
|
+
*
|
|
37191
|
+
* Pass in options to customise the caching behaviour
|
|
37192
|
+
* @param cachedFn Function to cache
|
|
37193
|
+
* @param options Memorization and LRUCache Options
|
|
37194
|
+
*/
|
|
37195
|
+
const memorise = (cachedFn, options = {}) => {
|
|
37196
|
+
// Extract defaults
|
|
37197
|
+
const { cache, cacheKeyResolver = defaultGenCacheKey, onHit, lruOptions = {}, } = options;
|
|
37198
|
+
const cacheOptions = { ...defaultLRUOptions, ...lruOptions };
|
|
37199
|
+
const _cache = (cache ||
|
|
37200
|
+
(0, tiny_lru_1.lru)(cacheOptions.max, cacheOptions.ttl));
|
|
37201
|
+
// Cached fn
|
|
37202
|
+
const returnFn = (...args) => {
|
|
37203
|
+
const cacheKey = cacheKeyResolver(...args);
|
|
37204
|
+
const cachedValue = _cache.get(cacheKey);
|
|
37205
|
+
const keyCached = _cache.has(cacheKey);
|
|
37206
|
+
// Use cached key, even if value is void
|
|
37207
|
+
if (keyCached) {
|
|
37208
|
+
// If onHit handler is there, run it
|
|
37209
|
+
if (onHit) {
|
|
37210
|
+
onHit(cacheKey, cachedValue, _cache);
|
|
37211
|
+
}
|
|
37212
|
+
return cachedValue;
|
|
37213
|
+
}
|
|
37214
|
+
// No cache hit, run function and cache result
|
|
37215
|
+
const result = cachedFn.apply(this, args);
|
|
37216
|
+
_cache.set(cacheKey, result);
|
|
37217
|
+
return result;
|
|
37218
|
+
};
|
|
37219
|
+
// Expose the cache
|
|
37220
|
+
returnFn._cache = _cache;
|
|
37221
|
+
return returnFn;
|
|
37222
|
+
};
|
|
37223
|
+
exports.memorise = memorise;
|
|
37224
|
+
// Default export
|
|
37225
|
+
exports.default = exports.memorise;
|
|
37226
|
+
/**
|
|
37227
|
+
* Generic args handler function.
|
|
37228
|
+
* @param args Argument array
|
|
37229
|
+
*/
|
|
37230
|
+
const defaultGenCacheKey = (...args) => {
|
|
37231
|
+
if (args.length === 0) {
|
|
37232
|
+
return "no-args";
|
|
37233
|
+
}
|
|
37234
|
+
return args
|
|
37235
|
+
.map((val) => {
|
|
37236
|
+
if (val === undefined) {
|
|
37237
|
+
return "undefined";
|
|
37238
|
+
}
|
|
37239
|
+
if (val === null) {
|
|
37240
|
+
return "null";
|
|
37241
|
+
}
|
|
37242
|
+
if (Array.isArray(val)) {
|
|
37243
|
+
return `[${defaultGenCacheKey(...val)}]`;
|
|
37244
|
+
}
|
|
37245
|
+
if (typeof val === "object") {
|
|
37246
|
+
return `{${defaultGenCacheKey(...sortedObjectEntries(val))}}`;
|
|
37247
|
+
}
|
|
37248
|
+
return JSON.stringify(val);
|
|
37249
|
+
})
|
|
37250
|
+
.join(",");
|
|
37251
|
+
};
|
|
37252
|
+
const sortedObjectEntries = (obj) => {
|
|
37253
|
+
return Object.entries(obj).sort((a, b) => {
|
|
37254
|
+
if (a[0] < b[0]) {
|
|
37255
|
+
return -1;
|
|
37256
|
+
}
|
|
37257
|
+
return 1;
|
|
37258
|
+
});
|
|
37259
|
+
};
|
|
37260
|
+
|
|
37261
|
+
} (lib$1));
|
|
37262
|
+
|
|
37263
|
+
var lib = {};
|
|
37264
|
+
|
|
37265
|
+
Object.defineProperty(lib, "__esModule", { value: true });
|
|
37266
|
+
lib.clearGlobalNamespace = getGlobalisedValue_1 = lib.getGlobalisedValue = void 0;
|
|
37267
|
+
const GLOBALISE_KEY_PREFIX = "globalise__singleton__";
|
|
37268
|
+
const fallbackGlobal = {};
|
|
37269
|
+
const getGlobalObject = () => {
|
|
37270
|
+
if (typeof window !== "undefined") {
|
|
37271
|
+
return window;
|
|
37272
|
+
}
|
|
37273
|
+
if (typeof globalThis !== "undefined") {
|
|
37274
|
+
return globalThis;
|
|
37275
|
+
}
|
|
37276
|
+
return fallbackGlobal;
|
|
37277
|
+
};
|
|
37278
|
+
const validateInputs = (namespace, key) => {
|
|
37279
|
+
if (typeof namespace !== "string") {
|
|
37280
|
+
throw "Invalid namespace key";
|
|
37281
|
+
}
|
|
37282
|
+
if (typeof key !== "string") {
|
|
37283
|
+
throw "Invalid item key";
|
|
37284
|
+
}
|
|
37285
|
+
};
|
|
37286
|
+
const createGlobalisedKey = (namespace) => {
|
|
37287
|
+
return `${GLOBALISE_KEY_PREFIX}${namespace}`;
|
|
37288
|
+
};
|
|
37289
|
+
const getGlobalScopedObject = (namespace) => {
|
|
37290
|
+
const globalObject = getGlobalObject();
|
|
37291
|
+
const GLOBALISE_KEY = createGlobalisedKey(namespace);
|
|
37292
|
+
// Initialise global object
|
|
37293
|
+
if (!globalObject[GLOBALISE_KEY]) {
|
|
37294
|
+
globalObject[GLOBALISE_KEY] = {};
|
|
37295
|
+
}
|
|
37296
|
+
return globalObject[GLOBALISE_KEY];
|
|
37297
|
+
};
|
|
37298
|
+
const getSingleton = (namespace, key) => {
|
|
37299
|
+
const scopedObject = getGlobalScopedObject(namespace);
|
|
37300
|
+
return scopedObject[key] || undefined;
|
|
37301
|
+
};
|
|
37302
|
+
const setSingleton = (namespace, key, value) => {
|
|
37303
|
+
const scopedObject = getGlobalScopedObject(namespace);
|
|
37304
|
+
scopedObject[key] = value;
|
|
37305
|
+
};
|
|
37306
|
+
const getGlobalisedValue$1 = (namespace, key, value) => {
|
|
37307
|
+
validateInputs(namespace, key);
|
|
37308
|
+
const existing = getSingleton(namespace, key);
|
|
37309
|
+
if (existing !== undefined) {
|
|
37310
|
+
return existing;
|
|
37311
|
+
}
|
|
37312
|
+
setSingleton(namespace, key, value);
|
|
37313
|
+
return value;
|
|
37314
|
+
};
|
|
37315
|
+
var getGlobalisedValue_1 = lib.getGlobalisedValue = getGlobalisedValue$1;
|
|
37316
|
+
const clearGlobalNamespace = (namespace) => {
|
|
37317
|
+
const globalObject = getGlobalObject();
|
|
37318
|
+
const globalisedKey = createGlobalisedKey(namespace);
|
|
37319
|
+
if (globalObject[globalisedKey] !== undefined) {
|
|
37320
|
+
delete globalObject[globalisedKey];
|
|
37321
|
+
}
|
|
37322
|
+
};
|
|
37323
|
+
lib.clearGlobalNamespace = clearGlobalNamespace;
|
|
37324
|
+
|
|
36946
37325
|
const isNode = () => typeof window === 'undefined';
|
|
36947
37326
|
const isBrowser = () => !isNode();
|
|
36948
37327
|
|
|
@@ -36956,12 +37335,6 @@ var Detail;
|
|
|
36956
37335
|
Detail["DOMAIN"] = "domain";
|
|
36957
37336
|
Detail["SDK_VERSION"] = "sdkVersion";
|
|
36958
37337
|
})(Detail || (Detail = {}));
|
|
36959
|
-
var Store;
|
|
36960
|
-
(function (Store) {
|
|
36961
|
-
Store["EVENTS"] = "events";
|
|
36962
|
-
Store["RUNTIME"] = "runtime";
|
|
36963
|
-
})(Store || (Store = {}));
|
|
36964
|
-
const POLLING_FREQUENCY = 5000;
|
|
36965
37338
|
|
|
36966
37339
|
const IMTBL_API = 'https://api.x.immutable.com';
|
|
36967
37340
|
async function post(path, data) {
|
|
@@ -37021,6 +37394,11 @@ const setItem = (key, payload) => {
|
|
|
37021
37394
|
return false;
|
|
37022
37395
|
};
|
|
37023
37396
|
|
|
37397
|
+
var Store;
|
|
37398
|
+
(function (Store) {
|
|
37399
|
+
Store["EVENTS"] = "events";
|
|
37400
|
+
Store["RUNTIME"] = "runtime";
|
|
37401
|
+
})(Store || (Store = {}));
|
|
37024
37402
|
// In memory storage for events and other data
|
|
37025
37403
|
let EVENT_STORE;
|
|
37026
37404
|
let RUNTIME_DETAILS;
|
|
@@ -37048,6 +37426,10 @@ const getDetail = (key) => {
|
|
|
37048
37426
|
const getAllDetails = () => RUNTIME_DETAILS;
|
|
37049
37427
|
// Events
|
|
37050
37428
|
const getEvents = () => EVENT_STORE;
|
|
37429
|
+
const addEvent = (event) => {
|
|
37430
|
+
EVENT_STORE.push(event);
|
|
37431
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
37432
|
+
};
|
|
37051
37433
|
const removeSentEvents = (numberOfEvents) => {
|
|
37052
37434
|
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
37053
37435
|
setItem(Store.EVENTS, EVENT_STORE);
|
|
@@ -37066,9 +37448,7 @@ const flattenProperties = (properties) => {
|
|
|
37066
37448
|
};
|
|
37067
37449
|
|
|
37068
37450
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37069
|
-
const SDK_VERSION = '1.5.
|
|
37070
|
-
let initialised = false;
|
|
37071
|
-
const isInitialised = () => initialised;
|
|
37451
|
+
const SDK_VERSION = '1.5.3-alpha.1';
|
|
37072
37452
|
const getReferrer = () => {
|
|
37073
37453
|
if (isNode()) {
|
|
37074
37454
|
return '';
|
|
@@ -37105,21 +37485,28 @@ const getRuntimeDetails = () => {
|
|
|
37105
37485
|
screen: `${window.screen.width}x${window.screen.height}`,
|
|
37106
37486
|
};
|
|
37107
37487
|
};
|
|
37488
|
+
let initialised = false;
|
|
37489
|
+
const isInitialised = () => initialised;
|
|
37108
37490
|
const initialise = async () => {
|
|
37109
|
-
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
37110
|
-
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
37111
|
-
const body = {
|
|
37112
|
-
version: 1,
|
|
37113
|
-
data: {
|
|
37114
|
-
runtimeDetails,
|
|
37115
|
-
runtimeId: existingRuntimeId,
|
|
37116
|
-
},
|
|
37117
|
-
};
|
|
37118
|
-
const response = await post('/v1/sdk/initialise', body);
|
|
37119
|
-
// Get runtimeId and store it
|
|
37120
|
-
const { runtimeId } = response;
|
|
37121
|
-
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
37122
37491
|
initialised = true;
|
|
37492
|
+
try {
|
|
37493
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
37494
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
37495
|
+
const body = {
|
|
37496
|
+
version: 1,
|
|
37497
|
+
data: {
|
|
37498
|
+
runtimeDetails,
|
|
37499
|
+
runtimeId: existingRuntimeId,
|
|
37500
|
+
},
|
|
37501
|
+
};
|
|
37502
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
37503
|
+
// Get runtimeId and store it
|
|
37504
|
+
const { runtimeId } = response;
|
|
37505
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
37506
|
+
}
|
|
37507
|
+
catch (error) {
|
|
37508
|
+
initialised = false;
|
|
37509
|
+
}
|
|
37123
37510
|
};
|
|
37124
37511
|
|
|
37125
37512
|
function errorBoundary(fn) {
|
|
@@ -37150,6 +37537,32 @@ function isTestEnvironment() {
|
|
|
37150
37537
|
// Just use process.env.CI for now.
|
|
37151
37538
|
return process.env.JEST_WORKER_ID !== undefined;
|
|
37152
37539
|
}
|
|
37540
|
+
|
|
37541
|
+
const GLOBALISE_KEY = 'imtbl__metrics';
|
|
37542
|
+
const MEMORISE_TIMEFRAME = 1000;
|
|
37543
|
+
const MEMORISE_MAX = 1000;
|
|
37544
|
+
const getGlobalisedValue = (key, value) => getGlobalisedValue_1(GLOBALISE_KEY, key, value);
|
|
37545
|
+
const getGlobalisedCachedFunction = (key, fn) => {
|
|
37546
|
+
// Some applications (esp backend, or frontends using the split bundles) can sometimes
|
|
37547
|
+
// initialise the same request multiple times. This will prevent multiple of the
|
|
37548
|
+
// same event,value from being reported in a 1 second period.
|
|
37549
|
+
const memorisedFn = lib$1.memorise(fn, {
|
|
37550
|
+
lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
|
|
37551
|
+
});
|
|
37552
|
+
return getGlobalisedValue_1(GLOBALISE_KEY, key, memorisedFn);
|
|
37553
|
+
};
|
|
37554
|
+
|
|
37555
|
+
const POLLING_FREQUENCY = 5000;
|
|
37556
|
+
// Store the event in the event store
|
|
37557
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
37558
|
+
const event = {
|
|
37559
|
+
event: `${moduleName}.${eventName}`,
|
|
37560
|
+
time: new Date().toISOString(),
|
|
37561
|
+
...(properties && { properties: flattenProperties(properties) }),
|
|
37562
|
+
};
|
|
37563
|
+
addEvent(event);
|
|
37564
|
+
};
|
|
37565
|
+
errorBoundary(getGlobalisedCachedFunction('track', trackFn));
|
|
37153
37566
|
// Sending events to the server
|
|
37154
37567
|
const flushFn = async () => {
|
|
37155
37568
|
// Don't flush if not initialised
|
|
@@ -37185,11 +37598,32 @@ const flushPoll = async () => {
|
|
|
37185
37598
|
await flush();
|
|
37186
37599
|
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
37187
37600
|
};
|
|
37601
|
+
let flushingStarted = false;
|
|
37602
|
+
const startFlushing = () => {
|
|
37603
|
+
if (flushingStarted) {
|
|
37604
|
+
return;
|
|
37605
|
+
}
|
|
37606
|
+
flushingStarted = true;
|
|
37607
|
+
flushPoll();
|
|
37608
|
+
};
|
|
37188
37609
|
// This will get initialised when module is imported.
|
|
37189
37610
|
if (!isTestEnvironment()) {
|
|
37190
|
-
errorBoundary(
|
|
37611
|
+
errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
|
|
37191
37612
|
}
|
|
37192
37613
|
|
|
37614
|
+
const setEnvironmentFn = (env) => {
|
|
37615
|
+
storeDetail(Detail.ENVIRONMENT, env);
|
|
37616
|
+
};
|
|
37617
|
+
errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
|
|
37618
|
+
const setPassportClientIdFn = (passportClientId) => {
|
|
37619
|
+
storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
|
|
37620
|
+
};
|
|
37621
|
+
errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
|
|
37622
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
37623
|
+
storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
37624
|
+
};
|
|
37625
|
+
errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
|
|
37626
|
+
|
|
37193
37627
|
var Environment;
|
|
37194
37628
|
(function (Environment) {
|
|
37195
37629
|
Environment["PRODUCTION"] = "production";
|
|
@@ -42181,7 +42615,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42181
42615
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
42182
42616
|
};
|
|
42183
42617
|
|
|
42184
|
-
const SDK_VERSION_MARKER = '1.5.
|
|
42618
|
+
const SDK_VERSION_MARKER = '1.5.3-alpha.1';
|
|
42185
42619
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42186
42620
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42187
42621
|
|