@imtbl/sdk 0.45.4 → 0.45.6
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.d.ts +2 -2
- package/dist/blockchain_data.js +261 -1
- package/dist/browser/checkout/sdk.js +6 -6
- package/dist/browser/checkout/widgets.js +61 -61
- package/dist/checkout.d.ts +2 -2
- package/dist/checkout.js +530 -3
- package/dist/config.d.ts +2 -2
- package/dist/config.js +272 -0
- package/dist/index.browser.js +12 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +571 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +571 -6
- package/dist/orderbook.d.ts +2 -2
- package/dist/orderbook.js +260 -0
- package/dist/passport.d.ts +2 -2
- package/dist/passport.js +296 -3
- package/dist/x.d.ts +2 -2
- package/dist/x.js +262 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,300 @@ var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
|
46
46
|
var encUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(encUtils);
|
|
47
47
|
var Uniswap__namespace = /*#__PURE__*/_interopNamespaceDefault(Uniswap);
|
|
48
48
|
|
|
49
|
+
const isNode$1 = () => typeof window === 'undefined';
|
|
50
|
+
const isBrowser$1 = () => !isNode$1();
|
|
51
|
+
|
|
52
|
+
var Detail$1;
|
|
53
|
+
(function (Detail) {
|
|
54
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
55
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
56
|
+
Detail["ENVIRONMENT"] = "env";
|
|
57
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
58
|
+
Detail["IDENTITY"] = "uid";
|
|
59
|
+
Detail["DOMAIN"] = "domain";
|
|
60
|
+
})(Detail$1 || (Detail$1 = {}));
|
|
61
|
+
var Store$1;
|
|
62
|
+
(function (Store) {
|
|
63
|
+
Store["EVENTS"] = "events";
|
|
64
|
+
Store["RUNTIME"] = "runtime";
|
|
65
|
+
})(Store$1 || (Store$1 = {}));
|
|
66
|
+
const POLLING_FREQUENCY$1 = 5000;
|
|
67
|
+
|
|
68
|
+
const IMTBL_API$1 = 'https://api.x.immutable.com';
|
|
69
|
+
async function post$1(path, data) {
|
|
70
|
+
const client = globalAxios$1.create({
|
|
71
|
+
baseURL: IMTBL_API$1,
|
|
72
|
+
});
|
|
73
|
+
const payload = JSON.stringify(data);
|
|
74
|
+
const body = {
|
|
75
|
+
payload: btoa(payload),
|
|
76
|
+
};
|
|
77
|
+
const response = await client.post(path, body);
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Abstraction on localstorage
|
|
83
|
+
*/
|
|
84
|
+
const localStoragePrefix$1 = '__IMX-';
|
|
85
|
+
const hasLocalstorage$1 = () => isBrowser$1() && window.localStorage;
|
|
86
|
+
const parseItem$1 = (payload) => {
|
|
87
|
+
// Try to parse, if can't be parsed assume string
|
|
88
|
+
// and return string
|
|
89
|
+
if (payload === null)
|
|
90
|
+
return undefined;
|
|
91
|
+
try {
|
|
92
|
+
return JSON.parse(payload);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// Assumes it's a string.
|
|
96
|
+
return payload;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const serialiseItem$1 = (payload) => {
|
|
100
|
+
if (typeof payload === 'string') {
|
|
101
|
+
return payload;
|
|
102
|
+
}
|
|
103
|
+
return JSON.stringify(payload);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* GenKey will take into account the namespace
|
|
107
|
+
* as well as if being run in the Link, it will tap into the link
|
|
108
|
+
* @param {string} key
|
|
109
|
+
* @returns key
|
|
110
|
+
*/
|
|
111
|
+
const genKey$1 = (key) => `${localStoragePrefix$1}${key}`;
|
|
112
|
+
function getItem$1(key) {
|
|
113
|
+
if (hasLocalstorage$1()) {
|
|
114
|
+
return parseItem$1(window.localStorage.getItem(genKey$1(key)));
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
const setItem$1 = (key, payload) => {
|
|
119
|
+
if (hasLocalstorage$1()) {
|
|
120
|
+
window.localStorage.setItem(genKey$1(key), serialiseItem$1(payload));
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// In memory storage for events and other data
|
|
127
|
+
let EVENT_STORE$1;
|
|
128
|
+
let RUNTIME_DETAILS$1;
|
|
129
|
+
// Initialise store and runtime
|
|
130
|
+
const initialise$1$1 = () => {
|
|
131
|
+
EVENT_STORE$1 = getItem$1(Store$1.EVENTS) || [];
|
|
132
|
+
RUNTIME_DETAILS$1 = getItem$1(Store$1.RUNTIME) || {};
|
|
133
|
+
};
|
|
134
|
+
initialise$1$1();
|
|
135
|
+
// Runtime Details
|
|
136
|
+
const storeDetail$1 = (key, value) => {
|
|
137
|
+
RUNTIME_DETAILS$1 = {
|
|
138
|
+
...RUNTIME_DETAILS$1,
|
|
139
|
+
[key]: value,
|
|
140
|
+
};
|
|
141
|
+
setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
|
|
142
|
+
};
|
|
143
|
+
const getDetail$1 = (key) => {
|
|
144
|
+
// Handle the scenario where detail is a falsy value
|
|
145
|
+
if (RUNTIME_DETAILS$1[key] === undefined) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
return RUNTIME_DETAILS$1[key];
|
|
149
|
+
};
|
|
150
|
+
const getAllDetails$1 = () => RUNTIME_DETAILS$1;
|
|
151
|
+
// Events
|
|
152
|
+
const getEvents$1 = () => EVENT_STORE$1;
|
|
153
|
+
const addEvent$1 = (event) => {
|
|
154
|
+
EVENT_STORE$1.push(event);
|
|
155
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
156
|
+
};
|
|
157
|
+
const removeSentEvents$1 = (numberOfEvents) => {
|
|
158
|
+
EVENT_STORE$1 = EVENT_STORE$1.slice(numberOfEvents);
|
|
159
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
160
|
+
};
|
|
161
|
+
const flattenProperties$1 = (properties) => {
|
|
162
|
+
const propertyMap = [];
|
|
163
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
164
|
+
if (typeof key === 'string'
|
|
165
|
+
|| typeof value === 'string'
|
|
166
|
+
|| typeof value === 'number'
|
|
167
|
+
|| typeof value === 'boolean') {
|
|
168
|
+
propertyMap.push([key, value.toString()]);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return propertyMap;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
let initialised$1 = false;
|
|
175
|
+
const isInitialised$1 = () => initialised$1;
|
|
176
|
+
const getReferrer$1 = () => {
|
|
177
|
+
if (isNode$1()) {
|
|
178
|
+
return '';
|
|
179
|
+
}
|
|
180
|
+
if (window.location.ancestorOrigins
|
|
181
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
182
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
183
|
+
}
|
|
184
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
185
|
+
};
|
|
186
|
+
const runtimeHost$1 = () => {
|
|
187
|
+
if (isNode$1()) {
|
|
188
|
+
return '';
|
|
189
|
+
}
|
|
190
|
+
if (window.opener || window.parent !== window) {
|
|
191
|
+
return getReferrer$1();
|
|
192
|
+
}
|
|
193
|
+
return new URL(window.location.href).hostname;
|
|
194
|
+
};
|
|
195
|
+
const getRuntimeDetails$1 = () => {
|
|
196
|
+
if (isNode$1()) {
|
|
197
|
+
return { browser: 'nodejs' };
|
|
198
|
+
}
|
|
199
|
+
const domain = runtimeHost$1();
|
|
200
|
+
if (domain) {
|
|
201
|
+
storeDetail$1(Detail$1.DOMAIN, domain);
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
browser: window.navigator.userAgent,
|
|
205
|
+
domain,
|
|
206
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
207
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
const initialise$2 = async () => {
|
|
211
|
+
const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
|
|
212
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
213
|
+
const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
|
|
214
|
+
const body = {
|
|
215
|
+
version: 1,
|
|
216
|
+
data: {
|
|
217
|
+
runtimeDetails,
|
|
218
|
+
runtimeId: existingRuntimeId,
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
const response = await post$1('/v1/sdk/initialise', body);
|
|
222
|
+
// Get runtimeId and store it
|
|
223
|
+
const { runtimeId } = response;
|
|
224
|
+
storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
|
|
225
|
+
initialised$1 = true;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
function errorBoundary$1(fn) {
|
|
229
|
+
const wrappedFunction = ((...args) => {
|
|
230
|
+
try {
|
|
231
|
+
// Execute the original function
|
|
232
|
+
const result = fn(...args);
|
|
233
|
+
if (result instanceof Promise) {
|
|
234
|
+
// Silent fail for now, in future
|
|
235
|
+
// we can send errors to a logging service
|
|
236
|
+
return result.catch(() => undefined);
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
// As above, fail silently for now
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return wrappedFunction;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isTestEnvironment$1() {
|
|
249
|
+
if (typeof process === 'undefined') {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Store the event in the event store
|
|
256
|
+
const trackFn$1 = (moduleName, eventName, properties) => {
|
|
257
|
+
const event = {
|
|
258
|
+
event: `${moduleName}.${eventName}`,
|
|
259
|
+
time: new Date().toISOString(),
|
|
260
|
+
...(properties && { properties: flattenProperties$1(properties) }),
|
|
261
|
+
};
|
|
262
|
+
addEvent$1(event);
|
|
263
|
+
};
|
|
264
|
+
const track$1 = errorBoundary$1(trackFn$1);
|
|
265
|
+
// Sending events to the server
|
|
266
|
+
const flushFn$1 = async () => {
|
|
267
|
+
// Don't flush if not initialised
|
|
268
|
+
if (isInitialised$1() === false) {
|
|
269
|
+
await initialise$2();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const events = getEvents$1();
|
|
273
|
+
if (events.length === 0) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
// Track events length here, incase
|
|
277
|
+
const numEvents = events.length;
|
|
278
|
+
// Get details and send it with the track request
|
|
279
|
+
const details = getAllDetails$1();
|
|
280
|
+
const metricsPayload = {
|
|
281
|
+
version: 1,
|
|
282
|
+
data: {
|
|
283
|
+
events,
|
|
284
|
+
details,
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
const response = await post$1('/v1/sdk/metrics', metricsPayload);
|
|
288
|
+
if (response instanceof Error) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
// Clear events if successfully posted
|
|
292
|
+
removeSentEvents$1(numEvents);
|
|
293
|
+
};
|
|
294
|
+
const flush$1 = errorBoundary$1(flushFn$1);
|
|
295
|
+
// Flush events every 5 seconds
|
|
296
|
+
const flushPoll$1 = async () => {
|
|
297
|
+
await flush$1();
|
|
298
|
+
setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
|
|
299
|
+
};
|
|
300
|
+
// This will get initialised when module is imported.
|
|
301
|
+
if (!isTestEnvironment$1()) {
|
|
302
|
+
errorBoundary$1(flushPoll$1)();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const parseIdentity = (params) => {
|
|
306
|
+
if (params.passportId) {
|
|
307
|
+
const key = `passport:${params.passportId.toLowerCase()}`;
|
|
308
|
+
return key;
|
|
309
|
+
}
|
|
310
|
+
if (params.ethAddress) {
|
|
311
|
+
const key = `ethAddress:${params.ethAddress.toLowerCase()}`;
|
|
312
|
+
return key;
|
|
313
|
+
}
|
|
314
|
+
throw new Error('invalid_identity');
|
|
315
|
+
};
|
|
316
|
+
const identifyFn = (params) => {
|
|
317
|
+
const identity = parseIdentity(params);
|
|
318
|
+
if (!identity) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
storeDetail$1(Detail$1.IDENTITY, identity);
|
|
322
|
+
track$1('metrics', 'identify', params.traits);
|
|
323
|
+
};
|
|
324
|
+
const identify = errorBoundary$1(identifyFn);
|
|
325
|
+
|
|
326
|
+
const setEnvironmentFn = (env) => {
|
|
327
|
+
storeDetail$1(Detail$1.ENVIRONMENT, env);
|
|
328
|
+
};
|
|
329
|
+
const setEnvironment = errorBoundary$1(setEnvironmentFn);
|
|
330
|
+
const setPassportClientIdFn = (passportClientId) => {
|
|
331
|
+
storeDetail$1(Detail$1.PASSPORT_CLIENT_ID, passportClientId);
|
|
332
|
+
};
|
|
333
|
+
const setPassportClientId = errorBoundary$1(setPassportClientIdFn);
|
|
334
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
335
|
+
storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
336
|
+
};
|
|
337
|
+
const setPublishableApiKey = errorBoundary$1(setPublishableApiKeyFn);
|
|
338
|
+
|
|
339
|
+
track$1('metrics', 'sdk_version', {
|
|
340
|
+
version: '0.45.6',
|
|
341
|
+
});
|
|
342
|
+
|
|
49
343
|
var Environment$1;
|
|
50
344
|
(function (Environment) {
|
|
51
345
|
Environment["PRODUCTION"] = "production";
|
|
@@ -58,6 +352,8 @@ class ImmutableConfiguration {
|
|
|
58
352
|
publishableKey;
|
|
59
353
|
constructor(options) {
|
|
60
354
|
this.environment = options.environment;
|
|
355
|
+
setEnvironment(options.environment);
|
|
356
|
+
track$1('config', 'created_imtbl_config');
|
|
61
357
|
}
|
|
62
358
|
}
|
|
63
359
|
const API_KEY_PREFIX = 'sk_imapik-';
|
|
@@ -73,6 +369,7 @@ const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
|
73
369
|
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
74
370
|
+ ' https://hub.immutable.com');
|
|
75
371
|
}
|
|
372
|
+
setPublishableApiKey(publishableKey);
|
|
76
373
|
globalAxios$1.defaults.headers.common['x-immutable-publishable-key'] = publishableKey;
|
|
77
374
|
};
|
|
78
375
|
const addRateLimitingKeyToAxiosHeader = (rateLimitingKey) => {
|
|
@@ -10641,7 +10938,7 @@ class MultiRollupApiClients {
|
|
|
10641
10938
|
}
|
|
10642
10939
|
|
|
10643
10940
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10644
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.45.
|
|
10941
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.45.6' };
|
|
10645
10942
|
const createConfig = ({ basePath, headers, }) => {
|
|
10646
10943
|
if (!basePath.trim()) {
|
|
10647
10944
|
throw Error('basePath can not be empty');
|
|
@@ -10713,7 +11010,7 @@ class APIError extends Error {
|
|
|
10713
11010
|
|
|
10714
11011
|
/* eslint-disable implicit-arrow-linebreak */
|
|
10715
11012
|
const defaultHeaders = {
|
|
10716
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.
|
|
11013
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.6',
|
|
10717
11014
|
};
|
|
10718
11015
|
/**
|
|
10719
11016
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11152,7 +11449,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11152
11449
|
chainID,
|
|
11153
11450
|
coreContractAddress,
|
|
11154
11451
|
registrationContractAddress,
|
|
11155
|
-
sdkVersion: 'ts-immutable-sdk-0.45.
|
|
11452
|
+
sdkVersion: 'ts-immutable-sdk-0.45.6',
|
|
11156
11453
|
});
|
|
11157
11454
|
/**
|
|
11158
11455
|
* Sets `sdkVersion` at the time of build
|
|
@@ -17893,7 +18190,8 @@ class Passport {
|
|
|
17893
18190
|
this.multiRollupApiClients = new MultiRollupApiClients(this.config.multiRollupConfig);
|
|
17894
18191
|
this.passportEventEmitter = new TypedEventEmitter();
|
|
17895
18192
|
const imxClientConfig = this.config.baseConfig.environment === Environment$1.PRODUCTION
|
|
17896
|
-
? imxApiConfig.getProduction()
|
|
18193
|
+
? imxApiConfig.getProduction()
|
|
18194
|
+
: imxApiConfig.getSandbox();
|
|
17897
18195
|
const imxApiClients = passportModuleConfiguration.overrides?.imxApiClients
|
|
17898
18196
|
|| new ImxApiClients(imxClientConfig);
|
|
17899
18197
|
this.passportImxProviderFactory = new PassportImxProviderFactory({
|
|
@@ -17905,6 +18203,8 @@ class Passport {
|
|
|
17905
18203
|
passportEventEmitter: this.passportEventEmitter,
|
|
17906
18204
|
imxApiClients,
|
|
17907
18205
|
});
|
|
18206
|
+
setPassportClientId(passportModuleConfiguration.clientId);
|
|
18207
|
+
track$1('passport', 'initialised');
|
|
17908
18208
|
}
|
|
17909
18209
|
/**
|
|
17910
18210
|
* @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
|
|
@@ -17950,6 +18250,11 @@ class Passport {
|
|
|
17950
18250
|
if (!user && !useCachedSession) {
|
|
17951
18251
|
user = await this.authManager.login();
|
|
17952
18252
|
}
|
|
18253
|
+
if (user) {
|
|
18254
|
+
identify({
|
|
18255
|
+
passportId: user.profile.sub,
|
|
18256
|
+
});
|
|
18257
|
+
}
|
|
17953
18258
|
return user ? user.profile : null;
|
|
17954
18259
|
}
|
|
17955
18260
|
async loginCallback() {
|
|
@@ -36306,6 +36611,266 @@ class TokenBridge {
|
|
|
36306
36611
|
}
|
|
36307
36612
|
}
|
|
36308
36613
|
|
|
36614
|
+
const isNode = () => typeof window === 'undefined';
|
|
36615
|
+
const isBrowser = () => !isNode();
|
|
36616
|
+
|
|
36617
|
+
var Detail;
|
|
36618
|
+
(function (Detail) {
|
|
36619
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
36620
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
36621
|
+
Detail["ENVIRONMENT"] = "env";
|
|
36622
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
36623
|
+
Detail["IDENTITY"] = "uid";
|
|
36624
|
+
Detail["DOMAIN"] = "domain";
|
|
36625
|
+
})(Detail || (Detail = {}));
|
|
36626
|
+
var Store;
|
|
36627
|
+
(function (Store) {
|
|
36628
|
+
Store["EVENTS"] = "events";
|
|
36629
|
+
Store["RUNTIME"] = "runtime";
|
|
36630
|
+
})(Store || (Store = {}));
|
|
36631
|
+
const POLLING_FREQUENCY = 5000;
|
|
36632
|
+
|
|
36633
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
36634
|
+
async function post(path, data) {
|
|
36635
|
+
const client = axios$1.create({
|
|
36636
|
+
baseURL: IMTBL_API,
|
|
36637
|
+
});
|
|
36638
|
+
const payload = JSON.stringify(data);
|
|
36639
|
+
const body = {
|
|
36640
|
+
payload: btoa(payload),
|
|
36641
|
+
};
|
|
36642
|
+
const response = await client.post(path, body);
|
|
36643
|
+
return response.data;
|
|
36644
|
+
}
|
|
36645
|
+
|
|
36646
|
+
/**
|
|
36647
|
+
* Abstraction on localstorage
|
|
36648
|
+
*/
|
|
36649
|
+
const localStoragePrefix = '__IMX-';
|
|
36650
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
36651
|
+
const parseItem = (payload) => {
|
|
36652
|
+
// Try to parse, if can't be parsed assume string
|
|
36653
|
+
// and return string
|
|
36654
|
+
if (payload === null)
|
|
36655
|
+
return undefined;
|
|
36656
|
+
try {
|
|
36657
|
+
return JSON.parse(payload);
|
|
36658
|
+
}
|
|
36659
|
+
catch (error) {
|
|
36660
|
+
// Assumes it's a string.
|
|
36661
|
+
return payload;
|
|
36662
|
+
}
|
|
36663
|
+
};
|
|
36664
|
+
const serialiseItem = (payload) => {
|
|
36665
|
+
if (typeof payload === 'string') {
|
|
36666
|
+
return payload;
|
|
36667
|
+
}
|
|
36668
|
+
return JSON.stringify(payload);
|
|
36669
|
+
};
|
|
36670
|
+
/**
|
|
36671
|
+
* GenKey will take into account the namespace
|
|
36672
|
+
* as well as if being run in the Link, it will tap into the link
|
|
36673
|
+
* @param {string} key
|
|
36674
|
+
* @returns key
|
|
36675
|
+
*/
|
|
36676
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
36677
|
+
function getItem(key) {
|
|
36678
|
+
if (hasLocalstorage()) {
|
|
36679
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
36680
|
+
}
|
|
36681
|
+
return undefined;
|
|
36682
|
+
}
|
|
36683
|
+
const setItem = (key, payload) => {
|
|
36684
|
+
if (hasLocalstorage()) {
|
|
36685
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
36686
|
+
return true;
|
|
36687
|
+
}
|
|
36688
|
+
return false;
|
|
36689
|
+
};
|
|
36690
|
+
|
|
36691
|
+
// In memory storage for events and other data
|
|
36692
|
+
let EVENT_STORE;
|
|
36693
|
+
let RUNTIME_DETAILS;
|
|
36694
|
+
// Initialise store and runtime
|
|
36695
|
+
const initialise$1 = () => {
|
|
36696
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
36697
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
36698
|
+
};
|
|
36699
|
+
initialise$1();
|
|
36700
|
+
// Runtime Details
|
|
36701
|
+
const storeDetail = (key, value) => {
|
|
36702
|
+
RUNTIME_DETAILS = {
|
|
36703
|
+
...RUNTIME_DETAILS,
|
|
36704
|
+
[key]: value,
|
|
36705
|
+
};
|
|
36706
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
36707
|
+
};
|
|
36708
|
+
const getDetail = (key) => {
|
|
36709
|
+
// Handle the scenario where detail is a falsy value
|
|
36710
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
36711
|
+
return undefined;
|
|
36712
|
+
}
|
|
36713
|
+
return RUNTIME_DETAILS[key];
|
|
36714
|
+
};
|
|
36715
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
36716
|
+
// Events
|
|
36717
|
+
const getEvents = () => EVENT_STORE;
|
|
36718
|
+
const addEvent = (event) => {
|
|
36719
|
+
EVENT_STORE.push(event);
|
|
36720
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
36721
|
+
};
|
|
36722
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
36723
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
36724
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
36725
|
+
};
|
|
36726
|
+
const flattenProperties = (properties) => {
|
|
36727
|
+
const propertyMap = [];
|
|
36728
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
36729
|
+
if (typeof key === 'string'
|
|
36730
|
+
|| typeof value === 'string'
|
|
36731
|
+
|| typeof value === 'number'
|
|
36732
|
+
|| typeof value === 'boolean') {
|
|
36733
|
+
propertyMap.push([key, value.toString()]);
|
|
36734
|
+
}
|
|
36735
|
+
});
|
|
36736
|
+
return propertyMap;
|
|
36737
|
+
};
|
|
36738
|
+
|
|
36739
|
+
let initialised = false;
|
|
36740
|
+
const isInitialised = () => initialised;
|
|
36741
|
+
const getReferrer = () => {
|
|
36742
|
+
if (isNode()) {
|
|
36743
|
+
return '';
|
|
36744
|
+
}
|
|
36745
|
+
if (window.location.ancestorOrigins
|
|
36746
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
36747
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
36748
|
+
}
|
|
36749
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
36750
|
+
};
|
|
36751
|
+
const runtimeHost = () => {
|
|
36752
|
+
if (isNode()) {
|
|
36753
|
+
return '';
|
|
36754
|
+
}
|
|
36755
|
+
if (window.opener || window.parent !== window) {
|
|
36756
|
+
return getReferrer();
|
|
36757
|
+
}
|
|
36758
|
+
return new URL(window.location.href).hostname;
|
|
36759
|
+
};
|
|
36760
|
+
const getRuntimeDetails = () => {
|
|
36761
|
+
if (isNode()) {
|
|
36762
|
+
return { browser: 'nodejs' };
|
|
36763
|
+
}
|
|
36764
|
+
const domain = runtimeHost();
|
|
36765
|
+
if (domain) {
|
|
36766
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
36767
|
+
}
|
|
36768
|
+
return {
|
|
36769
|
+
browser: window.navigator.userAgent,
|
|
36770
|
+
domain,
|
|
36771
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
36772
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
36773
|
+
};
|
|
36774
|
+
};
|
|
36775
|
+
const initialise = async () => {
|
|
36776
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
36777
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
36778
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
36779
|
+
const body = {
|
|
36780
|
+
version: 1,
|
|
36781
|
+
data: {
|
|
36782
|
+
runtimeDetails,
|
|
36783
|
+
runtimeId: existingRuntimeId,
|
|
36784
|
+
},
|
|
36785
|
+
};
|
|
36786
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
36787
|
+
// Get runtimeId and store it
|
|
36788
|
+
const { runtimeId } = response;
|
|
36789
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
36790
|
+
initialised = true;
|
|
36791
|
+
};
|
|
36792
|
+
|
|
36793
|
+
function errorBoundary(fn) {
|
|
36794
|
+
const wrappedFunction = ((...args) => {
|
|
36795
|
+
try {
|
|
36796
|
+
// Execute the original function
|
|
36797
|
+
const result = fn(...args);
|
|
36798
|
+
if (result instanceof Promise) {
|
|
36799
|
+
// Silent fail for now, in future
|
|
36800
|
+
// we can send errors to a logging service
|
|
36801
|
+
return result.catch(() => undefined);
|
|
36802
|
+
}
|
|
36803
|
+
return result;
|
|
36804
|
+
}
|
|
36805
|
+
catch (error) {
|
|
36806
|
+
// As above, fail silently for now
|
|
36807
|
+
return undefined;
|
|
36808
|
+
}
|
|
36809
|
+
});
|
|
36810
|
+
return wrappedFunction;
|
|
36811
|
+
}
|
|
36812
|
+
|
|
36813
|
+
function isTestEnvironment() {
|
|
36814
|
+
if (typeof process === 'undefined') {
|
|
36815
|
+
return false;
|
|
36816
|
+
}
|
|
36817
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
36818
|
+
}
|
|
36819
|
+
|
|
36820
|
+
// Store the event in the event store
|
|
36821
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
36822
|
+
const event = {
|
|
36823
|
+
event: `${moduleName}.${eventName}`,
|
|
36824
|
+
time: new Date().toISOString(),
|
|
36825
|
+
...(properties && { properties: flattenProperties(properties) }),
|
|
36826
|
+
};
|
|
36827
|
+
addEvent(event);
|
|
36828
|
+
};
|
|
36829
|
+
const track = errorBoundary(trackFn);
|
|
36830
|
+
// Sending events to the server
|
|
36831
|
+
const flushFn = async () => {
|
|
36832
|
+
// Don't flush if not initialised
|
|
36833
|
+
if (isInitialised() === false) {
|
|
36834
|
+
await initialise();
|
|
36835
|
+
return;
|
|
36836
|
+
}
|
|
36837
|
+
const events = getEvents();
|
|
36838
|
+
if (events.length === 0) {
|
|
36839
|
+
return;
|
|
36840
|
+
}
|
|
36841
|
+
// Track events length here, incase
|
|
36842
|
+
const numEvents = events.length;
|
|
36843
|
+
// Get details and send it with the track request
|
|
36844
|
+
const details = getAllDetails();
|
|
36845
|
+
const metricsPayload = {
|
|
36846
|
+
version: 1,
|
|
36847
|
+
data: {
|
|
36848
|
+
events,
|
|
36849
|
+
details,
|
|
36850
|
+
},
|
|
36851
|
+
};
|
|
36852
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
36853
|
+
if (response instanceof Error) {
|
|
36854
|
+
return;
|
|
36855
|
+
}
|
|
36856
|
+
// Clear events if successfully posted
|
|
36857
|
+
removeSentEvents(numEvents);
|
|
36858
|
+
};
|
|
36859
|
+
const flush = errorBoundary(flushFn);
|
|
36860
|
+
// Flush events every 5 seconds
|
|
36861
|
+
const flushPoll = async () => {
|
|
36862
|
+
await flush();
|
|
36863
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
36864
|
+
};
|
|
36865
|
+
// This will get initialised when module is imported.
|
|
36866
|
+
if (!isTestEnvironment()) {
|
|
36867
|
+
errorBoundary(flushPoll)();
|
|
36868
|
+
}
|
|
36869
|
+
|
|
36870
|
+
track('metrics', 'sdk_version', {
|
|
36871
|
+
version: '0.45.6',
|
|
36872
|
+
});
|
|
36873
|
+
|
|
36309
36874
|
var Environment;
|
|
36310
36875
|
(function (Environment) {
|
|
36311
36876
|
Environment["PRODUCTION"] = "production";
|
|
@@ -41285,7 +41850,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
41285
41850
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
41286
41851
|
};
|
|
41287
41852
|
|
|
41288
|
-
const SDK_VERSION_MARKER = '0.45.
|
|
41853
|
+
const SDK_VERSION_MARKER = '0.45.6';
|
|
41289
41854
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
41290
41855
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
41291
41856
|
|
|
@@ -41490,7 +42055,7 @@ async function getERC20TokenInfo(web3Provider, tokenAddress) {
|
|
|
41490
42055
|
}, { type: CheckoutErrorType.GET_ERC20_INFO_ERROR });
|
|
41491
42056
|
}
|
|
41492
42057
|
|
|
41493
|
-
const CACHE_DATA_TTL =
|
|
42058
|
+
const CACHE_DATA_TTL = 5; // seconds
|
|
41494
42059
|
/**
|
|
41495
42060
|
* Blockscout class provides a client abstraction for the Immutable 3rd party indexer.
|
|
41496
42061
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
|
|
|
24
24
|
} ? Required<{
|
|
25
25
|
publishableKey: string;
|
|
26
26
|
}> : {});
|
|
27
|
-
type ImmutableConfigurationWithOmitableFields<T> =
|
|
27
|
+
type ImmutableConfigurationWithOmitableFields<T> = T extends {
|
|
28
28
|
apiKey: 'omit';
|
|
29
|
-
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T
|
|
29
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
|
|
30
30
|
interface ModuleConfiguration<T> {
|
|
31
31
|
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
32
32
|
overrides?: T;
|