@imtbl/sdk 0.45.2 → 0.45.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.d.ts +2 -2
- package/dist/blockchain_data.js +239 -1
- package/dist/browser/checkout/sdk.js +6 -6
- package/dist/browser/checkout/widgets.js +61 -61
- package/dist/checkout.d.ts +5 -3
- package/dist/checkout.js +913 -19
- package/dist/config.d.ts +2 -2
- package/dist/config.js +265 -0
- package/dist/index.browser.js +12 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +920 -21
- package/dist/index.d.ts +5 -3
- package/dist/index.js +920 -21
- package/dist/orderbook.d.ts +2 -2
- package/dist/orderbook.js +238 -0
- package/dist/passport.d.ts +2 -2
- package/dist/passport.js +240 -2
- package/dist/x.d.ts +2 -2
- package/dist/x.js +240 -2
- package/package.json +1 -1
|
@@ -4309,9 +4309,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
|
|
|
4309
4309
|
} ? Required<{
|
|
4310
4310
|
publishableKey: string;
|
|
4311
4311
|
}> : {});
|
|
4312
|
-
type ImmutableConfigurationWithOmitableFields<T> =
|
|
4312
|
+
type ImmutableConfigurationWithOmitableFields<T> = T extends {
|
|
4313
4313
|
apiKey: 'omit';
|
|
4314
|
-
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T
|
|
4314
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
|
|
4315
4315
|
interface ModuleConfiguration<T> {
|
|
4316
4316
|
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
4317
4317
|
overrides?: T;
|
package/dist/blockchain_data.js
CHANGED
|
@@ -4128,6 +4128,244 @@ var tokensApiTypes = /*#__PURE__*/Object.freeze({
|
|
|
4128
4128
|
__proto__: null
|
|
4129
4129
|
});
|
|
4130
4130
|
|
|
4131
|
+
const isNode = () => typeof window === 'undefined';
|
|
4132
|
+
const isBrowser = () => !isNode();
|
|
4133
|
+
|
|
4134
|
+
var Detail;
|
|
4135
|
+
(function (Detail) {
|
|
4136
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
4137
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
4138
|
+
Detail["ENVIRONMENT"] = "env";
|
|
4139
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
4140
|
+
Detail["IDENTITY"] = "uid";
|
|
4141
|
+
Detail["DOMAIN"] = "domain";
|
|
4142
|
+
})(Detail || (Detail = {}));
|
|
4143
|
+
var Store;
|
|
4144
|
+
(function (Store) {
|
|
4145
|
+
Store["EVENTS"] = "events";
|
|
4146
|
+
Store["RUNTIME"] = "runtime";
|
|
4147
|
+
})(Store || (Store = {}));
|
|
4148
|
+
const POLLING_FREQUENCY = 5000;
|
|
4149
|
+
|
|
4150
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
4151
|
+
async function post(path, data) {
|
|
4152
|
+
const client = globalAxios.create({
|
|
4153
|
+
baseURL: IMTBL_API,
|
|
4154
|
+
});
|
|
4155
|
+
const payload = JSON.stringify(data);
|
|
4156
|
+
const body = {
|
|
4157
|
+
payload: btoa(payload),
|
|
4158
|
+
};
|
|
4159
|
+
const response = await client.post(path, body);
|
|
4160
|
+
return response.data;
|
|
4161
|
+
}
|
|
4162
|
+
|
|
4163
|
+
/**
|
|
4164
|
+
* Abstraction on localstorage
|
|
4165
|
+
*/
|
|
4166
|
+
const localStoragePrefix = '__IMX-';
|
|
4167
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
4168
|
+
const parseItem = (payload) => {
|
|
4169
|
+
// Try to parse, if can't be parsed assume string
|
|
4170
|
+
// and return string
|
|
4171
|
+
if (payload === null)
|
|
4172
|
+
return undefined;
|
|
4173
|
+
try {
|
|
4174
|
+
return JSON.parse(payload);
|
|
4175
|
+
}
|
|
4176
|
+
catch (error) {
|
|
4177
|
+
// Assumes it's a string.
|
|
4178
|
+
return payload;
|
|
4179
|
+
}
|
|
4180
|
+
};
|
|
4181
|
+
const serialiseItem = (payload) => {
|
|
4182
|
+
if (typeof payload === 'string') {
|
|
4183
|
+
return payload;
|
|
4184
|
+
}
|
|
4185
|
+
return JSON.stringify(payload);
|
|
4186
|
+
};
|
|
4187
|
+
/**
|
|
4188
|
+
* GenKey will take into account the namespace
|
|
4189
|
+
* as well as if being run in the Link, it will tap into the link
|
|
4190
|
+
* @param {string} key
|
|
4191
|
+
* @returns key
|
|
4192
|
+
*/
|
|
4193
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
4194
|
+
function getItem(key) {
|
|
4195
|
+
if (hasLocalstorage()) {
|
|
4196
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
4197
|
+
}
|
|
4198
|
+
return undefined;
|
|
4199
|
+
}
|
|
4200
|
+
const setItem = (key, payload) => {
|
|
4201
|
+
if (hasLocalstorage()) {
|
|
4202
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
4203
|
+
return true;
|
|
4204
|
+
}
|
|
4205
|
+
return false;
|
|
4206
|
+
};
|
|
4207
|
+
|
|
4208
|
+
// In memory storage for events and other data
|
|
4209
|
+
let EVENT_STORE;
|
|
4210
|
+
let RUNTIME_DETAILS;
|
|
4211
|
+
// Initialise store and runtime
|
|
4212
|
+
const initialise$1 = () => {
|
|
4213
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
4214
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
4215
|
+
};
|
|
4216
|
+
initialise$1();
|
|
4217
|
+
// Runtime Details
|
|
4218
|
+
const storeDetail = (key, value) => {
|
|
4219
|
+
RUNTIME_DETAILS = {
|
|
4220
|
+
...RUNTIME_DETAILS,
|
|
4221
|
+
[key]: value,
|
|
4222
|
+
};
|
|
4223
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
4224
|
+
};
|
|
4225
|
+
const getDetail = (key) => {
|
|
4226
|
+
// Handle the scenario where detail is a falsy value
|
|
4227
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
4228
|
+
return undefined;
|
|
4229
|
+
}
|
|
4230
|
+
return RUNTIME_DETAILS[key];
|
|
4231
|
+
};
|
|
4232
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
4233
|
+
// Events
|
|
4234
|
+
const getEvents = () => EVENT_STORE;
|
|
4235
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
4236
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
4237
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
4238
|
+
};
|
|
4239
|
+
const flattenProperties = (properties) => {
|
|
4240
|
+
const propertyMap = [];
|
|
4241
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
4242
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
4243
|
+
propertyMap.push([key, value.toString()]);
|
|
4244
|
+
}
|
|
4245
|
+
});
|
|
4246
|
+
return propertyMap;
|
|
4247
|
+
};
|
|
4248
|
+
|
|
4249
|
+
let initialised = false;
|
|
4250
|
+
const isInitialised = () => initialised;
|
|
4251
|
+
const getReferrer = () => {
|
|
4252
|
+
if (isNode()) {
|
|
4253
|
+
return '';
|
|
4254
|
+
}
|
|
4255
|
+
if (window.location.ancestorOrigins
|
|
4256
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
4257
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
4258
|
+
}
|
|
4259
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
4260
|
+
};
|
|
4261
|
+
const runtimeHost = () => {
|
|
4262
|
+
if (isNode()) {
|
|
4263
|
+
return '';
|
|
4264
|
+
}
|
|
4265
|
+
if (window.opener || window.parent !== window) {
|
|
4266
|
+
return getReferrer();
|
|
4267
|
+
}
|
|
4268
|
+
return new URL(window.location.href).hostname;
|
|
4269
|
+
};
|
|
4270
|
+
const getRuntimeDetails = () => {
|
|
4271
|
+
if (isNode()) {
|
|
4272
|
+
return { browser: 'nodejs' };
|
|
4273
|
+
}
|
|
4274
|
+
const domain = runtimeHost();
|
|
4275
|
+
if (domain) {
|
|
4276
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
4277
|
+
}
|
|
4278
|
+
return {
|
|
4279
|
+
browser: window.navigator.userAgent,
|
|
4280
|
+
domain,
|
|
4281
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
4282
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
4283
|
+
};
|
|
4284
|
+
};
|
|
4285
|
+
const initialise = async () => {
|
|
4286
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
4287
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
4288
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
4289
|
+
const body = {
|
|
4290
|
+
version: 1,
|
|
4291
|
+
data: {
|
|
4292
|
+
runtimeDetails,
|
|
4293
|
+
runtimeId: existingRuntimeId,
|
|
4294
|
+
},
|
|
4295
|
+
};
|
|
4296
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
4297
|
+
// Get runtimeId and store it
|
|
4298
|
+
const { runtimeId } = response;
|
|
4299
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
4300
|
+
initialised = true;
|
|
4301
|
+
};
|
|
4302
|
+
|
|
4303
|
+
function errorBoundary(fn) {
|
|
4304
|
+
const wrappedFunction = ((...args) => {
|
|
4305
|
+
try {
|
|
4306
|
+
// Execute the original function
|
|
4307
|
+
const result = fn(...args);
|
|
4308
|
+
if (result instanceof Promise) {
|
|
4309
|
+
// Silent fail for now, in future
|
|
4310
|
+
// we can send errors to a logging service
|
|
4311
|
+
return result.catch(() => undefined);
|
|
4312
|
+
}
|
|
4313
|
+
return result;
|
|
4314
|
+
}
|
|
4315
|
+
catch (error) {
|
|
4316
|
+
// As above, fail silently for now
|
|
4317
|
+
return undefined;
|
|
4318
|
+
}
|
|
4319
|
+
});
|
|
4320
|
+
return wrappedFunction;
|
|
4321
|
+
}
|
|
4322
|
+
|
|
4323
|
+
function isTestEnvironment() {
|
|
4324
|
+
if (typeof process === 'undefined') {
|
|
4325
|
+
return false;
|
|
4326
|
+
}
|
|
4327
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
4328
|
+
}
|
|
4329
|
+
// Sending events to the server
|
|
4330
|
+
const flushFn = async () => {
|
|
4331
|
+
// Don't flush if not initialised
|
|
4332
|
+
if (isInitialised() === false) {
|
|
4333
|
+
await initialise();
|
|
4334
|
+
return;
|
|
4335
|
+
}
|
|
4336
|
+
const events = getEvents();
|
|
4337
|
+
if (events.length === 0) {
|
|
4338
|
+
return;
|
|
4339
|
+
}
|
|
4340
|
+
// Track events length here, incase
|
|
4341
|
+
const numEvents = events.length;
|
|
4342
|
+
// Get details and send it with the track request
|
|
4343
|
+
const details = getAllDetails();
|
|
4344
|
+
const metricsPayload = {
|
|
4345
|
+
version: 1,
|
|
4346
|
+
data: {
|
|
4347
|
+
events,
|
|
4348
|
+
details,
|
|
4349
|
+
},
|
|
4350
|
+
};
|
|
4351
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
4352
|
+
if (response instanceof Error) {
|
|
4353
|
+
return;
|
|
4354
|
+
}
|
|
4355
|
+
// Clear events if successfully posted
|
|
4356
|
+
removeSentEvents(numEvents);
|
|
4357
|
+
};
|
|
4358
|
+
const flush = errorBoundary(flushFn);
|
|
4359
|
+
// Flush events every 5 seconds
|
|
4360
|
+
const flushPoll = async () => {
|
|
4361
|
+
await flush();
|
|
4362
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
4363
|
+
};
|
|
4364
|
+
// This will get initialised when module is imported.
|
|
4365
|
+
if (!isTestEnvironment()) {
|
|
4366
|
+
errorBoundary(flushPoll)();
|
|
4367
|
+
}
|
|
4368
|
+
|
|
4131
4369
|
var Environment;
|
|
4132
4370
|
(function (Environment) {
|
|
4133
4371
|
Environment["PRODUCTION"] = "production";
|
|
@@ -4153,7 +4391,7 @@ class APIError extends Error {
|
|
|
4153
4391
|
|
|
4154
4392
|
/* eslint-disable implicit-arrow-linebreak */
|
|
4155
4393
|
const defaultHeaders = {
|
|
4156
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.
|
|
4394
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.3-alpha',
|
|
4157
4395
|
};
|
|
4158
4396
|
/**
|
|
4159
4397
|
* createAPIConfiguration to create a custom Configuration
|