@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/orderbook.js
CHANGED
|
@@ -3,6 +3,266 @@ import FormData from 'form-data';
|
|
|
3
3
|
import { providers, BigNumber, constants as constants$1 } from 'ethers';
|
|
4
4
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
5
5
|
|
|
6
|
+
const isNode = () => typeof window === 'undefined';
|
|
7
|
+
const isBrowser = () => !isNode();
|
|
8
|
+
|
|
9
|
+
var Detail;
|
|
10
|
+
(function (Detail) {
|
|
11
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
12
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
13
|
+
Detail["ENVIRONMENT"] = "env";
|
|
14
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
15
|
+
Detail["IDENTITY"] = "uid";
|
|
16
|
+
Detail["DOMAIN"] = "domain";
|
|
17
|
+
})(Detail || (Detail = {}));
|
|
18
|
+
var Store;
|
|
19
|
+
(function (Store) {
|
|
20
|
+
Store["EVENTS"] = "events";
|
|
21
|
+
Store["RUNTIME"] = "runtime";
|
|
22
|
+
})(Store || (Store = {}));
|
|
23
|
+
const POLLING_FREQUENCY = 5000;
|
|
24
|
+
|
|
25
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
26
|
+
async function post(path, data) {
|
|
27
|
+
const client = axios.create({
|
|
28
|
+
baseURL: IMTBL_API,
|
|
29
|
+
});
|
|
30
|
+
const payload = JSON.stringify(data);
|
|
31
|
+
const body = {
|
|
32
|
+
payload: btoa(payload),
|
|
33
|
+
};
|
|
34
|
+
const response = await client.post(path, body);
|
|
35
|
+
return response.data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Abstraction on localstorage
|
|
40
|
+
*/
|
|
41
|
+
const localStoragePrefix = '__IMX-';
|
|
42
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
43
|
+
const parseItem = (payload) => {
|
|
44
|
+
// Try to parse, if can't be parsed assume string
|
|
45
|
+
// and return string
|
|
46
|
+
if (payload === null)
|
|
47
|
+
return undefined;
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(payload);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// Assumes it's a string.
|
|
53
|
+
return payload;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const serialiseItem = (payload) => {
|
|
57
|
+
if (typeof payload === 'string') {
|
|
58
|
+
return payload;
|
|
59
|
+
}
|
|
60
|
+
return JSON.stringify(payload);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* GenKey will take into account the namespace
|
|
64
|
+
* as well as if being run in the Link, it will tap into the link
|
|
65
|
+
* @param {string} key
|
|
66
|
+
* @returns key
|
|
67
|
+
*/
|
|
68
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
69
|
+
function getItem(key) {
|
|
70
|
+
if (hasLocalstorage()) {
|
|
71
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
const setItem = (key, payload) => {
|
|
76
|
+
if (hasLocalstorage()) {
|
|
77
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// In memory storage for events and other data
|
|
84
|
+
let EVENT_STORE;
|
|
85
|
+
let RUNTIME_DETAILS;
|
|
86
|
+
// Initialise store and runtime
|
|
87
|
+
const initialise$1 = () => {
|
|
88
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
89
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
90
|
+
};
|
|
91
|
+
initialise$1();
|
|
92
|
+
// Runtime Details
|
|
93
|
+
const storeDetail = (key, value) => {
|
|
94
|
+
RUNTIME_DETAILS = {
|
|
95
|
+
...RUNTIME_DETAILS,
|
|
96
|
+
[key]: value,
|
|
97
|
+
};
|
|
98
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
99
|
+
};
|
|
100
|
+
const getDetail = (key) => {
|
|
101
|
+
// Handle the scenario where detail is a falsy value
|
|
102
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return RUNTIME_DETAILS[key];
|
|
106
|
+
};
|
|
107
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
108
|
+
// Events
|
|
109
|
+
const getEvents = () => EVENT_STORE;
|
|
110
|
+
const addEvent = (event) => {
|
|
111
|
+
EVENT_STORE.push(event);
|
|
112
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
113
|
+
};
|
|
114
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
115
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
116
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
117
|
+
};
|
|
118
|
+
const flattenProperties = (properties) => {
|
|
119
|
+
const propertyMap = [];
|
|
120
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
121
|
+
if (typeof key === 'string'
|
|
122
|
+
|| typeof value === 'string'
|
|
123
|
+
|| typeof value === 'number'
|
|
124
|
+
|| typeof value === 'boolean') {
|
|
125
|
+
propertyMap.push([key, value.toString()]);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return propertyMap;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
let initialised = false;
|
|
132
|
+
const isInitialised = () => initialised;
|
|
133
|
+
const getReferrer = () => {
|
|
134
|
+
if (isNode()) {
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
if (window.location.ancestorOrigins
|
|
138
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
139
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
140
|
+
}
|
|
141
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
142
|
+
};
|
|
143
|
+
const runtimeHost = () => {
|
|
144
|
+
if (isNode()) {
|
|
145
|
+
return '';
|
|
146
|
+
}
|
|
147
|
+
if (window.opener || window.parent !== window) {
|
|
148
|
+
return getReferrer();
|
|
149
|
+
}
|
|
150
|
+
return new URL(window.location.href).hostname;
|
|
151
|
+
};
|
|
152
|
+
const getRuntimeDetails = () => {
|
|
153
|
+
if (isNode()) {
|
|
154
|
+
return { browser: 'nodejs' };
|
|
155
|
+
}
|
|
156
|
+
const domain = runtimeHost();
|
|
157
|
+
if (domain) {
|
|
158
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
browser: window.navigator.userAgent,
|
|
162
|
+
domain,
|
|
163
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
164
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
const initialise = async () => {
|
|
168
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
169
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
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
|
+
initialised = true;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
function errorBoundary(fn) {
|
|
186
|
+
const wrappedFunction = ((...args) => {
|
|
187
|
+
try {
|
|
188
|
+
// Execute the original function
|
|
189
|
+
const result = fn(...args);
|
|
190
|
+
if (result instanceof Promise) {
|
|
191
|
+
// Silent fail for now, in future
|
|
192
|
+
// we can send errors to a logging service
|
|
193
|
+
return result.catch(() => undefined);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
// As above, fail silently for now
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return wrappedFunction;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function isTestEnvironment() {
|
|
206
|
+
if (typeof process === 'undefined') {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Store the event in the event store
|
|
213
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
214
|
+
const event = {
|
|
215
|
+
event: `${moduleName}.${eventName}`,
|
|
216
|
+
time: new Date().toISOString(),
|
|
217
|
+
...(properties && { properties: flattenProperties(properties) }),
|
|
218
|
+
};
|
|
219
|
+
addEvent(event);
|
|
220
|
+
};
|
|
221
|
+
const track = errorBoundary(trackFn);
|
|
222
|
+
// Sending events to the server
|
|
223
|
+
const flushFn = async () => {
|
|
224
|
+
// Don't flush if not initialised
|
|
225
|
+
if (isInitialised() === false) {
|
|
226
|
+
await initialise();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const events = getEvents();
|
|
230
|
+
if (events.length === 0) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
// Track events length here, incase
|
|
234
|
+
const numEvents = events.length;
|
|
235
|
+
// Get details and send it with the track request
|
|
236
|
+
const details = getAllDetails();
|
|
237
|
+
const metricsPayload = {
|
|
238
|
+
version: 1,
|
|
239
|
+
data: {
|
|
240
|
+
events,
|
|
241
|
+
details,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
245
|
+
if (response instanceof Error) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// Clear events if successfully posted
|
|
249
|
+
removeSentEvents(numEvents);
|
|
250
|
+
};
|
|
251
|
+
const flush = errorBoundary(flushFn);
|
|
252
|
+
// Flush events every 5 seconds
|
|
253
|
+
const flushPoll = async () => {
|
|
254
|
+
await flush();
|
|
255
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
256
|
+
};
|
|
257
|
+
// This will get initialised when module is imported.
|
|
258
|
+
if (!isTestEnvironment()) {
|
|
259
|
+
errorBoundary(flushPoll)();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
track('metrics', 'sdk_version', {
|
|
263
|
+
version: '0.45.6',
|
|
264
|
+
});
|
|
265
|
+
|
|
6
266
|
var Environment;
|
|
7
267
|
(function (Environment) {
|
|
8
268
|
Environment["PRODUCTION"] = "production";
|
package/dist/passport.d.ts
CHANGED
|
@@ -9832,9 +9832,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
|
|
|
9832
9832
|
} ? Required<{
|
|
9833
9833
|
publishableKey: string;
|
|
9834
9834
|
}> : {});
|
|
9835
|
-
type ImmutableConfigurationWithOmitableFields<T> =
|
|
9835
|
+
type ImmutableConfigurationWithOmitableFields<T> = T extends {
|
|
9836
9836
|
apiKey: 'omit';
|
|
9837
|
-
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T
|
|
9837
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
|
|
9838
9838
|
interface ModuleConfiguration<T> {
|
|
9839
9839
|
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
9840
9840
|
overrides?: T;
|
package/dist/passport.js
CHANGED
|
@@ -8724,7 +8724,7 @@ class MultiRollupApiClients {
|
|
|
8724
8724
|
}
|
|
8725
8725
|
|
|
8726
8726
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8727
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.45.
|
|
8727
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.45.6' };
|
|
8728
8728
|
const createConfig = ({ basePath, headers, }) => {
|
|
8729
8729
|
if (!basePath.trim()) {
|
|
8730
8730
|
throw Error('basePath can not be empty');
|
|
@@ -8777,6 +8777,291 @@ const multiRollupConfig = {
|
|
|
8777
8777
|
}),
|
|
8778
8778
|
};
|
|
8779
8779
|
|
|
8780
|
+
const isNode = () => typeof window === 'undefined';
|
|
8781
|
+
const isBrowser = () => !isNode();
|
|
8782
|
+
|
|
8783
|
+
var Detail;
|
|
8784
|
+
(function (Detail) {
|
|
8785
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
8786
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
8787
|
+
Detail["ENVIRONMENT"] = "env";
|
|
8788
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
8789
|
+
Detail["IDENTITY"] = "uid";
|
|
8790
|
+
Detail["DOMAIN"] = "domain";
|
|
8791
|
+
})(Detail || (Detail = {}));
|
|
8792
|
+
var Store;
|
|
8793
|
+
(function (Store) {
|
|
8794
|
+
Store["EVENTS"] = "events";
|
|
8795
|
+
Store["RUNTIME"] = "runtime";
|
|
8796
|
+
})(Store || (Store = {}));
|
|
8797
|
+
const POLLING_FREQUENCY = 5000;
|
|
8798
|
+
|
|
8799
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
8800
|
+
async function post(path, data) {
|
|
8801
|
+
const client = globalAxios$1.create({
|
|
8802
|
+
baseURL: IMTBL_API,
|
|
8803
|
+
});
|
|
8804
|
+
const payload = JSON.stringify(data);
|
|
8805
|
+
const body = {
|
|
8806
|
+
payload: btoa(payload),
|
|
8807
|
+
};
|
|
8808
|
+
const response = await client.post(path, body);
|
|
8809
|
+
return response.data;
|
|
8810
|
+
}
|
|
8811
|
+
|
|
8812
|
+
/**
|
|
8813
|
+
* Abstraction on localstorage
|
|
8814
|
+
*/
|
|
8815
|
+
const localStoragePrefix = '__IMX-';
|
|
8816
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
8817
|
+
const parseItem = (payload) => {
|
|
8818
|
+
// Try to parse, if can't be parsed assume string
|
|
8819
|
+
// and return string
|
|
8820
|
+
if (payload === null)
|
|
8821
|
+
return undefined;
|
|
8822
|
+
try {
|
|
8823
|
+
return JSON.parse(payload);
|
|
8824
|
+
}
|
|
8825
|
+
catch (error) {
|
|
8826
|
+
// Assumes it's a string.
|
|
8827
|
+
return payload;
|
|
8828
|
+
}
|
|
8829
|
+
};
|
|
8830
|
+
const serialiseItem = (payload) => {
|
|
8831
|
+
if (typeof payload === 'string') {
|
|
8832
|
+
return payload;
|
|
8833
|
+
}
|
|
8834
|
+
return JSON.stringify(payload);
|
|
8835
|
+
};
|
|
8836
|
+
/**
|
|
8837
|
+
* GenKey will take into account the namespace
|
|
8838
|
+
* as well as if being run in the Link, it will tap into the link
|
|
8839
|
+
* @param {string} key
|
|
8840
|
+
* @returns key
|
|
8841
|
+
*/
|
|
8842
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
8843
|
+
function getItem(key) {
|
|
8844
|
+
if (hasLocalstorage()) {
|
|
8845
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
8846
|
+
}
|
|
8847
|
+
return undefined;
|
|
8848
|
+
}
|
|
8849
|
+
const setItem = (key, payload) => {
|
|
8850
|
+
if (hasLocalstorage()) {
|
|
8851
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
8852
|
+
return true;
|
|
8853
|
+
}
|
|
8854
|
+
return false;
|
|
8855
|
+
};
|
|
8856
|
+
|
|
8857
|
+
// In memory storage for events and other data
|
|
8858
|
+
let EVENT_STORE;
|
|
8859
|
+
let RUNTIME_DETAILS;
|
|
8860
|
+
// Initialise store and runtime
|
|
8861
|
+
const initialise$1 = () => {
|
|
8862
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
8863
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
8864
|
+
};
|
|
8865
|
+
initialise$1();
|
|
8866
|
+
// Runtime Details
|
|
8867
|
+
const storeDetail = (key, value) => {
|
|
8868
|
+
RUNTIME_DETAILS = {
|
|
8869
|
+
...RUNTIME_DETAILS,
|
|
8870
|
+
[key]: value,
|
|
8871
|
+
};
|
|
8872
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
8873
|
+
};
|
|
8874
|
+
const getDetail = (key) => {
|
|
8875
|
+
// Handle the scenario where detail is a falsy value
|
|
8876
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
8877
|
+
return undefined;
|
|
8878
|
+
}
|
|
8879
|
+
return RUNTIME_DETAILS[key];
|
|
8880
|
+
};
|
|
8881
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
8882
|
+
// Events
|
|
8883
|
+
const getEvents = () => EVENT_STORE;
|
|
8884
|
+
const addEvent = (event) => {
|
|
8885
|
+
EVENT_STORE.push(event);
|
|
8886
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
8887
|
+
};
|
|
8888
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
8889
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
8890
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
8891
|
+
};
|
|
8892
|
+
const flattenProperties = (properties) => {
|
|
8893
|
+
const propertyMap = [];
|
|
8894
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
8895
|
+
if (typeof key === 'string'
|
|
8896
|
+
|| typeof value === 'string'
|
|
8897
|
+
|| typeof value === 'number'
|
|
8898
|
+
|| typeof value === 'boolean') {
|
|
8899
|
+
propertyMap.push([key, value.toString()]);
|
|
8900
|
+
}
|
|
8901
|
+
});
|
|
8902
|
+
return propertyMap;
|
|
8903
|
+
};
|
|
8904
|
+
|
|
8905
|
+
let initialised = false;
|
|
8906
|
+
const isInitialised = () => initialised;
|
|
8907
|
+
const getReferrer = () => {
|
|
8908
|
+
if (isNode()) {
|
|
8909
|
+
return '';
|
|
8910
|
+
}
|
|
8911
|
+
if (window.location.ancestorOrigins
|
|
8912
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
8913
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
8914
|
+
}
|
|
8915
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
8916
|
+
};
|
|
8917
|
+
const runtimeHost = () => {
|
|
8918
|
+
if (isNode()) {
|
|
8919
|
+
return '';
|
|
8920
|
+
}
|
|
8921
|
+
if (window.opener || window.parent !== window) {
|
|
8922
|
+
return getReferrer();
|
|
8923
|
+
}
|
|
8924
|
+
return new URL(window.location.href).hostname;
|
|
8925
|
+
};
|
|
8926
|
+
const getRuntimeDetails = () => {
|
|
8927
|
+
if (isNode()) {
|
|
8928
|
+
return { browser: 'nodejs' };
|
|
8929
|
+
}
|
|
8930
|
+
const domain = runtimeHost();
|
|
8931
|
+
if (domain) {
|
|
8932
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
8933
|
+
}
|
|
8934
|
+
return {
|
|
8935
|
+
browser: window.navigator.userAgent,
|
|
8936
|
+
domain,
|
|
8937
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
8938
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
8939
|
+
};
|
|
8940
|
+
};
|
|
8941
|
+
const initialise = async () => {
|
|
8942
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
8943
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
8944
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
8945
|
+
const body = {
|
|
8946
|
+
version: 1,
|
|
8947
|
+
data: {
|
|
8948
|
+
runtimeDetails,
|
|
8949
|
+
runtimeId: existingRuntimeId,
|
|
8950
|
+
},
|
|
8951
|
+
};
|
|
8952
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
8953
|
+
// Get runtimeId and store it
|
|
8954
|
+
const { runtimeId } = response;
|
|
8955
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
8956
|
+
initialised = true;
|
|
8957
|
+
};
|
|
8958
|
+
|
|
8959
|
+
function errorBoundary(fn) {
|
|
8960
|
+
const wrappedFunction = ((...args) => {
|
|
8961
|
+
try {
|
|
8962
|
+
// Execute the original function
|
|
8963
|
+
const result = fn(...args);
|
|
8964
|
+
if (result instanceof Promise) {
|
|
8965
|
+
// Silent fail for now, in future
|
|
8966
|
+
// we can send errors to a logging service
|
|
8967
|
+
return result.catch(() => undefined);
|
|
8968
|
+
}
|
|
8969
|
+
return result;
|
|
8970
|
+
}
|
|
8971
|
+
catch (error) {
|
|
8972
|
+
// As above, fail silently for now
|
|
8973
|
+
return undefined;
|
|
8974
|
+
}
|
|
8975
|
+
});
|
|
8976
|
+
return wrappedFunction;
|
|
8977
|
+
}
|
|
8978
|
+
|
|
8979
|
+
function isTestEnvironment() {
|
|
8980
|
+
if (typeof process === 'undefined') {
|
|
8981
|
+
return false;
|
|
8982
|
+
}
|
|
8983
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
8984
|
+
}
|
|
8985
|
+
|
|
8986
|
+
// Store the event in the event store
|
|
8987
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
8988
|
+
const event = {
|
|
8989
|
+
event: `${moduleName}.${eventName}`,
|
|
8990
|
+
time: new Date().toISOString(),
|
|
8991
|
+
...(properties && { properties: flattenProperties(properties) }),
|
|
8992
|
+
};
|
|
8993
|
+
addEvent(event);
|
|
8994
|
+
};
|
|
8995
|
+
const track = errorBoundary(trackFn);
|
|
8996
|
+
// Sending events to the server
|
|
8997
|
+
const flushFn = async () => {
|
|
8998
|
+
// Don't flush if not initialised
|
|
8999
|
+
if (isInitialised() === false) {
|
|
9000
|
+
await initialise();
|
|
9001
|
+
return;
|
|
9002
|
+
}
|
|
9003
|
+
const events = getEvents();
|
|
9004
|
+
if (events.length === 0) {
|
|
9005
|
+
return;
|
|
9006
|
+
}
|
|
9007
|
+
// Track events length here, incase
|
|
9008
|
+
const numEvents = events.length;
|
|
9009
|
+
// Get details and send it with the track request
|
|
9010
|
+
const details = getAllDetails();
|
|
9011
|
+
const metricsPayload = {
|
|
9012
|
+
version: 1,
|
|
9013
|
+
data: {
|
|
9014
|
+
events,
|
|
9015
|
+
details,
|
|
9016
|
+
},
|
|
9017
|
+
};
|
|
9018
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
9019
|
+
if (response instanceof Error) {
|
|
9020
|
+
return;
|
|
9021
|
+
}
|
|
9022
|
+
// Clear events if successfully posted
|
|
9023
|
+
removeSentEvents(numEvents);
|
|
9024
|
+
};
|
|
9025
|
+
const flush = errorBoundary(flushFn);
|
|
9026
|
+
// Flush events every 5 seconds
|
|
9027
|
+
const flushPoll = async () => {
|
|
9028
|
+
await flush();
|
|
9029
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
9030
|
+
};
|
|
9031
|
+
// This will get initialised when module is imported.
|
|
9032
|
+
if (!isTestEnvironment()) {
|
|
9033
|
+
errorBoundary(flushPoll)();
|
|
9034
|
+
}
|
|
9035
|
+
|
|
9036
|
+
const parseIdentity = (params) => {
|
|
9037
|
+
if (params.passportId) {
|
|
9038
|
+
const key = `passport:${params.passportId.toLowerCase()}`;
|
|
9039
|
+
return key;
|
|
9040
|
+
}
|
|
9041
|
+
if (params.ethAddress) {
|
|
9042
|
+
const key = `ethAddress:${params.ethAddress.toLowerCase()}`;
|
|
9043
|
+
return key;
|
|
9044
|
+
}
|
|
9045
|
+
throw new Error('invalid_identity');
|
|
9046
|
+
};
|
|
9047
|
+
const identifyFn = (params) => {
|
|
9048
|
+
const identity = parseIdentity(params);
|
|
9049
|
+
if (!identity) {
|
|
9050
|
+
return;
|
|
9051
|
+
}
|
|
9052
|
+
storeDetail(Detail.IDENTITY, identity);
|
|
9053
|
+
track('metrics', 'identify', params.traits);
|
|
9054
|
+
};
|
|
9055
|
+
const identify = errorBoundary(identifyFn);
|
|
9056
|
+
const setPassportClientIdFn = (passportClientId) => {
|
|
9057
|
+
storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
|
|
9058
|
+
};
|
|
9059
|
+
const setPassportClientId = errorBoundary(setPassportClientIdFn);
|
|
9060
|
+
|
|
9061
|
+
track('metrics', 'sdk_version', {
|
|
9062
|
+
version: '0.45.6',
|
|
9063
|
+
});
|
|
9064
|
+
|
|
8780
9065
|
var Environment;
|
|
8781
9066
|
(function (Environment) {
|
|
8782
9067
|
Environment["PRODUCTION"] = "production";
|
|
@@ -8792,7 +9077,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
8792
9077
|
chainID,
|
|
8793
9078
|
coreContractAddress,
|
|
8794
9079
|
registrationContractAddress,
|
|
8795
|
-
sdkVersion: 'ts-immutable-sdk-0.45.
|
|
9080
|
+
sdkVersion: 'ts-immutable-sdk-0.45.6',
|
|
8796
9081
|
});
|
|
8797
9082
|
/**
|
|
8798
9083
|
* Sets `sdkVersion` at the time of build
|
|
@@ -15524,7 +15809,8 @@ class Passport {
|
|
|
15524
15809
|
this.multiRollupApiClients = new MultiRollupApiClients(this.config.multiRollupConfig);
|
|
15525
15810
|
this.passportEventEmitter = new TypedEventEmitter();
|
|
15526
15811
|
const imxClientConfig = this.config.baseConfig.environment === Environment.PRODUCTION
|
|
15527
|
-
? imxApiConfig.getProduction()
|
|
15812
|
+
? imxApiConfig.getProduction()
|
|
15813
|
+
: imxApiConfig.getSandbox();
|
|
15528
15814
|
const imxApiClients = passportModuleConfiguration.overrides?.imxApiClients
|
|
15529
15815
|
|| new ImxApiClients(imxClientConfig);
|
|
15530
15816
|
this.passportImxProviderFactory = new PassportImxProviderFactory({
|
|
@@ -15536,6 +15822,8 @@ class Passport {
|
|
|
15536
15822
|
passportEventEmitter: this.passportEventEmitter,
|
|
15537
15823
|
imxApiClients,
|
|
15538
15824
|
});
|
|
15825
|
+
setPassportClientId(passportModuleConfiguration.clientId);
|
|
15826
|
+
track('passport', 'initialised');
|
|
15539
15827
|
}
|
|
15540
15828
|
/**
|
|
15541
15829
|
* @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
|
|
@@ -15581,6 +15869,11 @@ class Passport {
|
|
|
15581
15869
|
if (!user && !useCachedSession) {
|
|
15582
15870
|
user = await this.authManager.login();
|
|
15583
15871
|
}
|
|
15872
|
+
if (user) {
|
|
15873
|
+
identify({
|
|
15874
|
+
passportId: user.profile.sub,
|
|
15875
|
+
});
|
|
15876
|
+
}
|
|
15584
15877
|
return user ? user.profile : null;
|
|
15585
15878
|
}
|
|
15586
15879
|
async loginCallback() {
|
package/dist/x.d.ts
CHANGED
|
@@ -9781,9 +9781,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
|
|
|
9781
9781
|
} ? Required<{
|
|
9782
9782
|
publishableKey: string;
|
|
9783
9783
|
}> : {});
|
|
9784
|
-
type ImmutableConfigurationWithOmitableFields<T> =
|
|
9784
|
+
type ImmutableConfigurationWithOmitableFields<T> = T extends {
|
|
9785
9785
|
apiKey: 'omit';
|
|
9786
|
-
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T
|
|
9786
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
|
|
9787
9787
|
interface ModuleConfiguration<T> {
|
|
9788
9788
|
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
9789
9789
|
overrides?: T;
|