@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/blockchain_data.js +81 -24
- package/dist/browser/checkout/sdk.js +22 -6
- package/dist/browser/checkout/widgets.js +77 -61
- 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/orderbook.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import FormData from 'form-data';
|
|
3
3
|
import { providers, BigNumber, constants as constants$1 } from 'ethers';
|
|
4
|
+
import { memorise } from 'lru-memorise';
|
|
5
|
+
import { getGlobalisedValue as getGlobalisedValue$1 } from 'global-const';
|
|
4
6
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
5
7
|
|
|
6
8
|
const isNode = () => typeof window === 'undefined';
|
|
@@ -16,12 +18,6 @@ var Detail;
|
|
|
16
18
|
Detail["DOMAIN"] = "domain";
|
|
17
19
|
Detail["SDK_VERSION"] = "sdkVersion";
|
|
18
20
|
})(Detail || (Detail = {}));
|
|
19
|
-
var Store;
|
|
20
|
-
(function (Store) {
|
|
21
|
-
Store["EVENTS"] = "events";
|
|
22
|
-
Store["RUNTIME"] = "runtime";
|
|
23
|
-
})(Store || (Store = {}));
|
|
24
|
-
const POLLING_FREQUENCY = 5000;
|
|
25
21
|
|
|
26
22
|
const IMTBL_API = 'https://api.x.immutable.com';
|
|
27
23
|
async function post(path, data) {
|
|
@@ -81,6 +77,11 @@ const setItem = (key, payload) => {
|
|
|
81
77
|
return false;
|
|
82
78
|
};
|
|
83
79
|
|
|
80
|
+
var Store;
|
|
81
|
+
(function (Store) {
|
|
82
|
+
Store["EVENTS"] = "events";
|
|
83
|
+
Store["RUNTIME"] = "runtime";
|
|
84
|
+
})(Store || (Store = {}));
|
|
84
85
|
// In memory storage for events and other data
|
|
85
86
|
let EVENT_STORE;
|
|
86
87
|
let RUNTIME_DETAILS;
|
|
@@ -108,6 +109,10 @@ const getDetail = (key) => {
|
|
|
108
109
|
const getAllDetails = () => RUNTIME_DETAILS;
|
|
109
110
|
// Events
|
|
110
111
|
const getEvents = () => EVENT_STORE;
|
|
112
|
+
const addEvent = (event) => {
|
|
113
|
+
EVENT_STORE.push(event);
|
|
114
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
115
|
+
};
|
|
111
116
|
const removeSentEvents = (numberOfEvents) => {
|
|
112
117
|
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
113
118
|
setItem(Store.EVENTS, EVENT_STORE);
|
|
@@ -126,9 +131,7 @@ const flattenProperties = (properties) => {
|
|
|
126
131
|
};
|
|
127
132
|
|
|
128
133
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
129
|
-
const SDK_VERSION = '1.5.
|
|
130
|
-
let initialised = false;
|
|
131
|
-
const isInitialised = () => initialised;
|
|
134
|
+
const SDK_VERSION = '1.5.3-alpha';
|
|
132
135
|
const getReferrer = () => {
|
|
133
136
|
if (isNode()) {
|
|
134
137
|
return '';
|
|
@@ -165,21 +168,28 @@ const getRuntimeDetails = () => {
|
|
|
165
168
|
screen: `${window.screen.width}x${window.screen.height}`,
|
|
166
169
|
};
|
|
167
170
|
};
|
|
171
|
+
let initialised = false;
|
|
172
|
+
const isInitialised = () => initialised;
|
|
168
173
|
const initialise = async () => {
|
|
169
|
-
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
170
|
-
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
171
|
-
const body = {
|
|
172
|
-
version: 1,
|
|
173
|
-
data: {
|
|
174
|
-
runtimeDetails,
|
|
175
|
-
runtimeId: existingRuntimeId,
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
const response = await post('/v1/sdk/initialise', body);
|
|
179
|
-
// Get runtimeId and store it
|
|
180
|
-
const { runtimeId } = response;
|
|
181
|
-
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
182
174
|
initialised = true;
|
|
175
|
+
try {
|
|
176
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
177
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
178
|
+
const body = {
|
|
179
|
+
version: 1,
|
|
180
|
+
data: {
|
|
181
|
+
runtimeDetails,
|
|
182
|
+
runtimeId: existingRuntimeId,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
186
|
+
// Get runtimeId and store it
|
|
187
|
+
const { runtimeId } = response;
|
|
188
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
initialised = false;
|
|
192
|
+
}
|
|
183
193
|
};
|
|
184
194
|
|
|
185
195
|
function errorBoundary(fn) {
|
|
@@ -210,6 +220,32 @@ function isTestEnvironment() {
|
|
|
210
220
|
// Just use process.env.CI for now.
|
|
211
221
|
return process.env.JEST_WORKER_ID !== undefined;
|
|
212
222
|
}
|
|
223
|
+
|
|
224
|
+
const GLOBALISE_KEY = 'imtbl__metrics';
|
|
225
|
+
const MEMORISE_TIMEFRAME = 1000;
|
|
226
|
+
const MEMORISE_MAX = 1000;
|
|
227
|
+
const getGlobalisedValue = (key, value) => getGlobalisedValue$1(GLOBALISE_KEY, key, value);
|
|
228
|
+
const getGlobalisedCachedFunction = (key, fn) => {
|
|
229
|
+
// Some applications (esp backend, or frontends using the split bundles) can sometimes
|
|
230
|
+
// initialise the same request multiple times. This will prevent multiple of the
|
|
231
|
+
// same event,value from being reported in a 1 second period.
|
|
232
|
+
const memorisedFn = memorise(fn, {
|
|
233
|
+
lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
|
|
234
|
+
});
|
|
235
|
+
return getGlobalisedValue$1(GLOBALISE_KEY, key, memorisedFn);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const POLLING_FREQUENCY = 5000;
|
|
239
|
+
// Store the event in the event store
|
|
240
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
241
|
+
const event = {
|
|
242
|
+
event: `${moduleName}.${eventName}`,
|
|
243
|
+
time: new Date().toISOString(),
|
|
244
|
+
...(properties && { properties: flattenProperties(properties) }),
|
|
245
|
+
};
|
|
246
|
+
addEvent(event);
|
|
247
|
+
};
|
|
248
|
+
errorBoundary(getGlobalisedCachedFunction('track', trackFn));
|
|
213
249
|
// Sending events to the server
|
|
214
250
|
const flushFn = async () => {
|
|
215
251
|
// Don't flush if not initialised
|
|
@@ -245,11 +281,32 @@ const flushPoll = async () => {
|
|
|
245
281
|
await flush();
|
|
246
282
|
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
247
283
|
};
|
|
284
|
+
let flushingStarted = false;
|
|
285
|
+
const startFlushing = () => {
|
|
286
|
+
if (flushingStarted) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
flushingStarted = true;
|
|
290
|
+
flushPoll();
|
|
291
|
+
};
|
|
248
292
|
// This will get initialised when module is imported.
|
|
249
293
|
if (!isTestEnvironment()) {
|
|
250
|
-
errorBoundary(
|
|
294
|
+
errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
|
|
251
295
|
}
|
|
252
296
|
|
|
297
|
+
const setEnvironmentFn = (env) => {
|
|
298
|
+
storeDetail(Detail.ENVIRONMENT, env);
|
|
299
|
+
};
|
|
300
|
+
errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
|
|
301
|
+
const setPassportClientIdFn = (passportClientId) => {
|
|
302
|
+
storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
|
|
303
|
+
};
|
|
304
|
+
errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
|
|
305
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
306
|
+
storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
307
|
+
};
|
|
308
|
+
errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
|
|
309
|
+
|
|
253
310
|
var Environment;
|
|
254
311
|
(function (Environment) {
|
|
255
312
|
Environment["PRODUCTION"] = "production";
|
package/dist/passport.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import globalAxios$1, { isAxiosError as isAxiosError$1 } from 'axios';
|
|
2
2
|
import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
|
|
3
|
+
import { memorise } from 'lru-memorise';
|
|
4
|
+
import { getGlobalisedValue as getGlobalisedValue$1 } from 'global-const';
|
|
3
5
|
import { UserManager, User, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
|
|
4
6
|
import jwt_decode from 'jwt-decode';
|
|
5
7
|
import * as crypto from 'crypto';
|
|
@@ -9136,7 +9138,7 @@ class MultiRollupApiClients {
|
|
|
9136
9138
|
}
|
|
9137
9139
|
|
|
9138
9140
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9139
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.5.
|
|
9141
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.5.3-alpha' };
|
|
9140
9142
|
const createConfig = ({ basePath, headers, }) => {
|
|
9141
9143
|
if (!basePath.trim()) {
|
|
9142
9144
|
throw Error('basePath can not be empty');
|
|
@@ -9202,12 +9204,6 @@ var Detail;
|
|
|
9202
9204
|
Detail["DOMAIN"] = "domain";
|
|
9203
9205
|
Detail["SDK_VERSION"] = "sdkVersion";
|
|
9204
9206
|
})(Detail || (Detail = {}));
|
|
9205
|
-
var Store;
|
|
9206
|
-
(function (Store) {
|
|
9207
|
-
Store["EVENTS"] = "events";
|
|
9208
|
-
Store["RUNTIME"] = "runtime";
|
|
9209
|
-
})(Store || (Store = {}));
|
|
9210
|
-
const POLLING_FREQUENCY = 5000;
|
|
9211
9207
|
|
|
9212
9208
|
const IMTBL_API = 'https://api.x.immutable.com';
|
|
9213
9209
|
async function post(path, data) {
|
|
@@ -9267,6 +9263,11 @@ const setItem = (key, payload) => {
|
|
|
9267
9263
|
return false;
|
|
9268
9264
|
};
|
|
9269
9265
|
|
|
9266
|
+
var Store;
|
|
9267
|
+
(function (Store) {
|
|
9268
|
+
Store["EVENTS"] = "events";
|
|
9269
|
+
Store["RUNTIME"] = "runtime";
|
|
9270
|
+
})(Store || (Store = {}));
|
|
9270
9271
|
// In memory storage for events and other data
|
|
9271
9272
|
let EVENT_STORE;
|
|
9272
9273
|
let RUNTIME_DETAILS;
|
|
@@ -9316,9 +9317,7 @@ const flattenProperties = (properties) => {
|
|
|
9316
9317
|
};
|
|
9317
9318
|
|
|
9318
9319
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
9319
|
-
const SDK_VERSION = '1.5.
|
|
9320
|
-
let initialised = false;
|
|
9321
|
-
const isInitialised = () => initialised;
|
|
9320
|
+
const SDK_VERSION = '1.5.3-alpha';
|
|
9322
9321
|
const getReferrer = () => {
|
|
9323
9322
|
if (isNode()) {
|
|
9324
9323
|
return '';
|
|
@@ -9355,21 +9354,28 @@ const getRuntimeDetails = () => {
|
|
|
9355
9354
|
screen: `${window.screen.width}x${window.screen.height}`,
|
|
9356
9355
|
};
|
|
9357
9356
|
};
|
|
9357
|
+
let initialised = false;
|
|
9358
|
+
const isInitialised = () => initialised;
|
|
9358
9359
|
const initialise = async () => {
|
|
9359
|
-
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
9360
|
-
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
9361
|
-
const body = {
|
|
9362
|
-
version: 1,
|
|
9363
|
-
data: {
|
|
9364
|
-
runtimeDetails,
|
|
9365
|
-
runtimeId: existingRuntimeId,
|
|
9366
|
-
},
|
|
9367
|
-
};
|
|
9368
|
-
const response = await post('/v1/sdk/initialise', body);
|
|
9369
|
-
// Get runtimeId and store it
|
|
9370
|
-
const { runtimeId } = response;
|
|
9371
|
-
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
9372
9360
|
initialised = true;
|
|
9361
|
+
try {
|
|
9362
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
9363
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
9364
|
+
const body = {
|
|
9365
|
+
version: 1,
|
|
9366
|
+
data: {
|
|
9367
|
+
runtimeDetails,
|
|
9368
|
+
runtimeId: existingRuntimeId,
|
|
9369
|
+
},
|
|
9370
|
+
};
|
|
9371
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
9372
|
+
// Get runtimeId and store it
|
|
9373
|
+
const { runtimeId } = response;
|
|
9374
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
9375
|
+
}
|
|
9376
|
+
catch (error) {
|
|
9377
|
+
initialised = false;
|
|
9378
|
+
}
|
|
9373
9379
|
};
|
|
9374
9380
|
|
|
9375
9381
|
function errorBoundary(fn) {
|
|
@@ -9401,6 +9407,21 @@ function isTestEnvironment() {
|
|
|
9401
9407
|
return process.env.JEST_WORKER_ID !== undefined;
|
|
9402
9408
|
}
|
|
9403
9409
|
|
|
9410
|
+
const GLOBALISE_KEY = 'imtbl__metrics';
|
|
9411
|
+
const MEMORISE_TIMEFRAME = 1000;
|
|
9412
|
+
const MEMORISE_MAX = 1000;
|
|
9413
|
+
const getGlobalisedValue = (key, value) => getGlobalisedValue$1(GLOBALISE_KEY, key, value);
|
|
9414
|
+
const getGlobalisedCachedFunction = (key, fn) => {
|
|
9415
|
+
// Some applications (esp backend, or frontends using the split bundles) can sometimes
|
|
9416
|
+
// initialise the same request multiple times. This will prevent multiple of the
|
|
9417
|
+
// same event,value from being reported in a 1 second period.
|
|
9418
|
+
const memorisedFn = memorise(fn, {
|
|
9419
|
+
lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
|
|
9420
|
+
});
|
|
9421
|
+
return getGlobalisedValue$1(GLOBALISE_KEY, key, memorisedFn);
|
|
9422
|
+
};
|
|
9423
|
+
|
|
9424
|
+
const POLLING_FREQUENCY = 5000;
|
|
9404
9425
|
// Store the event in the event store
|
|
9405
9426
|
const trackFn = (moduleName, eventName, properties) => {
|
|
9406
9427
|
const event = {
|
|
@@ -9410,7 +9431,7 @@ const trackFn = (moduleName, eventName, properties) => {
|
|
|
9410
9431
|
};
|
|
9411
9432
|
addEvent(event);
|
|
9412
9433
|
};
|
|
9413
|
-
const track = errorBoundary(trackFn);
|
|
9434
|
+
const track = errorBoundary(getGlobalisedCachedFunction('track', trackFn));
|
|
9414
9435
|
// Sending events to the server
|
|
9415
9436
|
const flushFn = async () => {
|
|
9416
9437
|
// Don't flush if not initialised
|
|
@@ -9446,9 +9467,17 @@ const flushPoll = async () => {
|
|
|
9446
9467
|
await flush();
|
|
9447
9468
|
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
9448
9469
|
};
|
|
9470
|
+
let flushingStarted = false;
|
|
9471
|
+
const startFlushing = () => {
|
|
9472
|
+
if (flushingStarted) {
|
|
9473
|
+
return;
|
|
9474
|
+
}
|
|
9475
|
+
flushingStarted = true;
|
|
9476
|
+
flushPoll();
|
|
9477
|
+
};
|
|
9449
9478
|
// This will get initialised when module is imported.
|
|
9450
9479
|
if (!isTestEnvironment()) {
|
|
9451
|
-
errorBoundary(
|
|
9480
|
+
errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
|
|
9452
9481
|
}
|
|
9453
9482
|
|
|
9454
9483
|
const parseIdentity = (params) => {
|
|
@@ -9471,10 +9500,19 @@ const identifyFn = (params) => {
|
|
|
9471
9500
|
track('metrics', 'identify', params.traits);
|
|
9472
9501
|
};
|
|
9473
9502
|
const identify = errorBoundary(identifyFn);
|
|
9503
|
+
|
|
9504
|
+
const setEnvironmentFn = (env) => {
|
|
9505
|
+
storeDetail(Detail.ENVIRONMENT, env);
|
|
9506
|
+
};
|
|
9507
|
+
errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
|
|
9474
9508
|
const setPassportClientIdFn = (passportClientId) => {
|
|
9475
9509
|
storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
|
|
9476
9510
|
};
|
|
9477
|
-
const setPassportClientId = errorBoundary(setPassportClientIdFn);
|
|
9511
|
+
const setPassportClientId = errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
|
|
9512
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
9513
|
+
storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
9514
|
+
};
|
|
9515
|
+
errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
|
|
9478
9516
|
|
|
9479
9517
|
var Environment;
|
|
9480
9518
|
(function (Environment) {
|
|
@@ -9491,7 +9529,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
9491
9529
|
chainID,
|
|
9492
9530
|
coreContractAddress,
|
|
9493
9531
|
registrationContractAddress,
|
|
9494
|
-
sdkVersion: 'ts-immutable-sdk-1.5.
|
|
9532
|
+
sdkVersion: 'ts-immutable-sdk-1.5.3-alpha',
|
|
9495
9533
|
});
|
|
9496
9534
|
/**
|
|
9497
9535
|
* Sets `sdkVersion` at the time of build
|
package/dist/x.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ImmutableX, Config, TransfersApi, OrdersApi, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi } from '@imtbl/core-sdk';
|
|
2
2
|
export { IMXError, createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey } from '@imtbl/core-sdk';
|
|
3
3
|
import axios, { AxiosError } from 'axios';
|
|
4
|
+
import { memorise } from 'lru-memorise';
|
|
5
|
+
import { getGlobalisedValue as getGlobalisedValue$1 } from 'global-const';
|
|
4
6
|
import BN from 'bn.js';
|
|
5
7
|
import * as encUtils from 'enc-utils';
|
|
6
8
|
import { parseUnits } from '@ethersproject/units';
|
|
@@ -21,12 +23,6 @@ var Detail;
|
|
|
21
23
|
Detail["DOMAIN"] = "domain";
|
|
22
24
|
Detail["SDK_VERSION"] = "sdkVersion";
|
|
23
25
|
})(Detail || (Detail = {}));
|
|
24
|
-
var Store;
|
|
25
|
-
(function (Store) {
|
|
26
|
-
Store["EVENTS"] = "events";
|
|
27
|
-
Store["RUNTIME"] = "runtime";
|
|
28
|
-
})(Store || (Store = {}));
|
|
29
|
-
const POLLING_FREQUENCY = 5000;
|
|
30
26
|
|
|
31
27
|
const IMTBL_API = 'https://api.x.immutable.com';
|
|
32
28
|
async function post(path, data) {
|
|
@@ -86,6 +82,11 @@ const setItem = (key, payload) => {
|
|
|
86
82
|
return false;
|
|
87
83
|
};
|
|
88
84
|
|
|
85
|
+
var Store;
|
|
86
|
+
(function (Store) {
|
|
87
|
+
Store["EVENTS"] = "events";
|
|
88
|
+
Store["RUNTIME"] = "runtime";
|
|
89
|
+
})(Store || (Store = {}));
|
|
89
90
|
// In memory storage for events and other data
|
|
90
91
|
let EVENT_STORE;
|
|
91
92
|
let RUNTIME_DETAILS;
|
|
@@ -113,6 +114,10 @@ const getDetail = (key) => {
|
|
|
113
114
|
const getAllDetails = () => RUNTIME_DETAILS;
|
|
114
115
|
// Events
|
|
115
116
|
const getEvents = () => EVENT_STORE;
|
|
117
|
+
const addEvent = (event) => {
|
|
118
|
+
EVENT_STORE.push(event);
|
|
119
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
120
|
+
};
|
|
116
121
|
const removeSentEvents = (numberOfEvents) => {
|
|
117
122
|
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
118
123
|
setItem(Store.EVENTS, EVENT_STORE);
|
|
@@ -131,9 +136,7 @@ const flattenProperties = (properties) => {
|
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
134
|
-
const SDK_VERSION = '1.5.
|
|
135
|
-
let initialised = false;
|
|
136
|
-
const isInitialised = () => initialised;
|
|
139
|
+
const SDK_VERSION = '1.5.3-alpha';
|
|
137
140
|
const getReferrer = () => {
|
|
138
141
|
if (isNode()) {
|
|
139
142
|
return '';
|
|
@@ -170,21 +173,28 @@ const getRuntimeDetails = () => {
|
|
|
170
173
|
screen: `${window.screen.width}x${window.screen.height}`,
|
|
171
174
|
};
|
|
172
175
|
};
|
|
176
|
+
let initialised = false;
|
|
177
|
+
const isInitialised = () => initialised;
|
|
173
178
|
const initialise = async () => {
|
|
174
|
-
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
175
|
-
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
176
|
-
const body = {
|
|
177
|
-
version: 1,
|
|
178
|
-
data: {
|
|
179
|
-
runtimeDetails,
|
|
180
|
-
runtimeId: existingRuntimeId,
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
const response = await post('/v1/sdk/initialise', body);
|
|
184
|
-
// Get runtimeId and store it
|
|
185
|
-
const { runtimeId } = response;
|
|
186
|
-
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
187
179
|
initialised = true;
|
|
180
|
+
try {
|
|
181
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
182
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
183
|
+
const body = {
|
|
184
|
+
version: 1,
|
|
185
|
+
data: {
|
|
186
|
+
runtimeDetails,
|
|
187
|
+
runtimeId: existingRuntimeId,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
191
|
+
// Get runtimeId and store it
|
|
192
|
+
const { runtimeId } = response;
|
|
193
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
initialised = false;
|
|
197
|
+
}
|
|
188
198
|
};
|
|
189
199
|
|
|
190
200
|
function errorBoundary(fn) {
|
|
@@ -215,6 +225,32 @@ function isTestEnvironment() {
|
|
|
215
225
|
// Just use process.env.CI for now.
|
|
216
226
|
return process.env.JEST_WORKER_ID !== undefined;
|
|
217
227
|
}
|
|
228
|
+
|
|
229
|
+
const GLOBALISE_KEY = 'imtbl__metrics';
|
|
230
|
+
const MEMORISE_TIMEFRAME = 1000;
|
|
231
|
+
const MEMORISE_MAX = 1000;
|
|
232
|
+
const getGlobalisedValue = (key, value) => getGlobalisedValue$1(GLOBALISE_KEY, key, value);
|
|
233
|
+
const getGlobalisedCachedFunction = (key, fn) => {
|
|
234
|
+
// Some applications (esp backend, or frontends using the split bundles) can sometimes
|
|
235
|
+
// initialise the same request multiple times. This will prevent multiple of the
|
|
236
|
+
// same event,value from being reported in a 1 second period.
|
|
237
|
+
const memorisedFn = memorise(fn, {
|
|
238
|
+
lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
|
|
239
|
+
});
|
|
240
|
+
return getGlobalisedValue$1(GLOBALISE_KEY, key, memorisedFn);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const POLLING_FREQUENCY = 5000;
|
|
244
|
+
// Store the event in the event store
|
|
245
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
246
|
+
const event = {
|
|
247
|
+
event: `${moduleName}.${eventName}`,
|
|
248
|
+
time: new Date().toISOString(),
|
|
249
|
+
...(properties && { properties: flattenProperties(properties) }),
|
|
250
|
+
};
|
|
251
|
+
addEvent(event);
|
|
252
|
+
};
|
|
253
|
+
errorBoundary(getGlobalisedCachedFunction('track', trackFn));
|
|
218
254
|
// Sending events to the server
|
|
219
255
|
const flushFn = async () => {
|
|
220
256
|
// Don't flush if not initialised
|
|
@@ -250,11 +286,32 @@ const flushPoll = async () => {
|
|
|
250
286
|
await flush();
|
|
251
287
|
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
252
288
|
};
|
|
289
|
+
let flushingStarted = false;
|
|
290
|
+
const startFlushing = () => {
|
|
291
|
+
if (flushingStarted) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
flushingStarted = true;
|
|
295
|
+
flushPoll();
|
|
296
|
+
};
|
|
253
297
|
// This will get initialised when module is imported.
|
|
254
298
|
if (!isTestEnvironment()) {
|
|
255
|
-
errorBoundary(
|
|
299
|
+
errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
|
|
256
300
|
}
|
|
257
301
|
|
|
302
|
+
const setEnvironmentFn = (env) => {
|
|
303
|
+
storeDetail(Detail.ENVIRONMENT, env);
|
|
304
|
+
};
|
|
305
|
+
errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
|
|
306
|
+
const setPassportClientIdFn = (passportClientId) => {
|
|
307
|
+
storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
|
|
308
|
+
};
|
|
309
|
+
errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
|
|
310
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
311
|
+
storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
312
|
+
};
|
|
313
|
+
errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
|
|
314
|
+
|
|
258
315
|
var Environment;
|
|
259
316
|
(function (Environment) {
|
|
260
317
|
Environment["PRODUCTION"] = "production";
|
|
@@ -270,7 +327,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
270
327
|
chainID,
|
|
271
328
|
coreContractAddress,
|
|
272
329
|
registrationContractAddress,
|
|
273
|
-
sdkVersion: 'ts-immutable-sdk-1.5.
|
|
330
|
+
sdkVersion: 'ts-immutable-sdk-1.5.3-alpha',
|
|
274
331
|
});
|
|
275
332
|
/**
|
|
276
333
|
* Sets `sdkVersion` at the time of build
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtbl/sdk",
|
|
3
3
|
"description": "Immutable Unified SDK",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.3-alpha",
|
|
5
5
|
"author": "Immutable",
|
|
6
6
|
"browser": "./dist/index.browser.js",
|
|
7
7
|
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
@@ -30,10 +30,12 @@
|
|
|
30
30
|
"crypto-browserify": "^3.12.0",
|
|
31
31
|
"enc-utils": "^3.0.0",
|
|
32
32
|
"ethers": "^5.7.2",
|
|
33
|
+
"global-const": "^0.1.2",
|
|
33
34
|
"https-browserify": "^1.0.0",
|
|
34
35
|
"i18next": "^23.7.6",
|
|
35
36
|
"i18next-browser-languagedetector": "^7.2.0",
|
|
36
37
|
"jwt-decode": "^3.1.2",
|
|
38
|
+
"lru-memorise": "^0.2.1",
|
|
37
39
|
"magic-sdk": "^21.2.0",
|
|
38
40
|
"oidc-client-ts": "2.2.1",
|
|
39
41
|
"os-browserify": "^0.3.0",
|