@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
package/dist/orderbook.d.ts
CHANGED
|
@@ -21,9 +21,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
|
|
|
21
21
|
} ? Required<{
|
|
22
22
|
publishableKey: string;
|
|
23
23
|
}> : {});
|
|
24
|
-
type ImmutableConfigurationWithOmitableFields<T> =
|
|
24
|
+
type ImmutableConfigurationWithOmitableFields<T> = T extends {
|
|
25
25
|
apiKey: 'omit';
|
|
26
|
-
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T
|
|
26
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
|
|
27
27
|
interface ModuleConfiguration<T> {
|
|
28
28
|
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
29
29
|
overrides?: T;
|
package/dist/orderbook.js
CHANGED
|
@@ -3,6 +3,244 @@ 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 removeSentEvents = (numberOfEvents) => {
|
|
111
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
112
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
113
|
+
};
|
|
114
|
+
const flattenProperties = (properties) => {
|
|
115
|
+
const propertyMap = [];
|
|
116
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
117
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
118
|
+
propertyMap.push([key, value.toString()]);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return propertyMap;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
let initialised = false;
|
|
125
|
+
const isInitialised = () => initialised;
|
|
126
|
+
const getReferrer = () => {
|
|
127
|
+
if (isNode()) {
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
if (window.location.ancestorOrigins
|
|
131
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
132
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
133
|
+
}
|
|
134
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
135
|
+
};
|
|
136
|
+
const runtimeHost = () => {
|
|
137
|
+
if (isNode()) {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
if (window.opener || window.parent !== window) {
|
|
141
|
+
return getReferrer();
|
|
142
|
+
}
|
|
143
|
+
return new URL(window.location.href).hostname;
|
|
144
|
+
};
|
|
145
|
+
const getRuntimeDetails = () => {
|
|
146
|
+
if (isNode()) {
|
|
147
|
+
return { browser: 'nodejs' };
|
|
148
|
+
}
|
|
149
|
+
const domain = runtimeHost();
|
|
150
|
+
if (domain) {
|
|
151
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
browser: window.navigator.userAgent,
|
|
155
|
+
domain,
|
|
156
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
157
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
const initialise = async () => {
|
|
161
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
162
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
163
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
164
|
+
const body = {
|
|
165
|
+
version: 1,
|
|
166
|
+
data: {
|
|
167
|
+
runtimeDetails,
|
|
168
|
+
runtimeId: existingRuntimeId,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
172
|
+
// Get runtimeId and store it
|
|
173
|
+
const { runtimeId } = response;
|
|
174
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
175
|
+
initialised = true;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function errorBoundary(fn) {
|
|
179
|
+
const wrappedFunction = ((...args) => {
|
|
180
|
+
try {
|
|
181
|
+
// Execute the original function
|
|
182
|
+
const result = fn(...args);
|
|
183
|
+
if (result instanceof Promise) {
|
|
184
|
+
// Silent fail for now, in future
|
|
185
|
+
// we can send errors to a logging service
|
|
186
|
+
return result.catch(() => undefined);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
// As above, fail silently for now
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return wrappedFunction;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function isTestEnvironment() {
|
|
199
|
+
if (typeof process === 'undefined') {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
203
|
+
}
|
|
204
|
+
// Sending events to the server
|
|
205
|
+
const flushFn = async () => {
|
|
206
|
+
// Don't flush if not initialised
|
|
207
|
+
if (isInitialised() === false) {
|
|
208
|
+
await initialise();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const events = getEvents();
|
|
212
|
+
if (events.length === 0) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// Track events length here, incase
|
|
216
|
+
const numEvents = events.length;
|
|
217
|
+
// Get details and send it with the track request
|
|
218
|
+
const details = getAllDetails();
|
|
219
|
+
const metricsPayload = {
|
|
220
|
+
version: 1,
|
|
221
|
+
data: {
|
|
222
|
+
events,
|
|
223
|
+
details,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
227
|
+
if (response instanceof Error) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// Clear events if successfully posted
|
|
231
|
+
removeSentEvents(numEvents);
|
|
232
|
+
};
|
|
233
|
+
const flush = errorBoundary(flushFn);
|
|
234
|
+
// Flush events every 5 seconds
|
|
235
|
+
const flushPoll = async () => {
|
|
236
|
+
await flush();
|
|
237
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
238
|
+
};
|
|
239
|
+
// This will get initialised when module is imported.
|
|
240
|
+
if (!isTestEnvironment()) {
|
|
241
|
+
errorBoundary(flushPoll)();
|
|
242
|
+
}
|
|
243
|
+
|
|
6
244
|
var Environment;
|
|
7
245
|
(function (Environment) {
|
|
8
246
|
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.3-alpha' };
|
|
8728
8728
|
const createConfig = ({ basePath, headers, }) => {
|
|
8729
8729
|
if (!basePath.trim()) {
|
|
8730
8730
|
throw Error('basePath can not be empty');
|
|
@@ -8777,6 +8777,244 @@ 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 removeSentEvents = (numberOfEvents) => {
|
|
8885
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
8886
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
8887
|
+
};
|
|
8888
|
+
const flattenProperties = (properties) => {
|
|
8889
|
+
const propertyMap = [];
|
|
8890
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
8891
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
8892
|
+
propertyMap.push([key, value.toString()]);
|
|
8893
|
+
}
|
|
8894
|
+
});
|
|
8895
|
+
return propertyMap;
|
|
8896
|
+
};
|
|
8897
|
+
|
|
8898
|
+
let initialised = false;
|
|
8899
|
+
const isInitialised = () => initialised;
|
|
8900
|
+
const getReferrer = () => {
|
|
8901
|
+
if (isNode()) {
|
|
8902
|
+
return '';
|
|
8903
|
+
}
|
|
8904
|
+
if (window.location.ancestorOrigins
|
|
8905
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
8906
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
8907
|
+
}
|
|
8908
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
8909
|
+
};
|
|
8910
|
+
const runtimeHost = () => {
|
|
8911
|
+
if (isNode()) {
|
|
8912
|
+
return '';
|
|
8913
|
+
}
|
|
8914
|
+
if (window.opener || window.parent !== window) {
|
|
8915
|
+
return getReferrer();
|
|
8916
|
+
}
|
|
8917
|
+
return new URL(window.location.href).hostname;
|
|
8918
|
+
};
|
|
8919
|
+
const getRuntimeDetails = () => {
|
|
8920
|
+
if (isNode()) {
|
|
8921
|
+
return { browser: 'nodejs' };
|
|
8922
|
+
}
|
|
8923
|
+
const domain = runtimeHost();
|
|
8924
|
+
if (domain) {
|
|
8925
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
8926
|
+
}
|
|
8927
|
+
return {
|
|
8928
|
+
browser: window.navigator.userAgent,
|
|
8929
|
+
domain,
|
|
8930
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
8931
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
8932
|
+
};
|
|
8933
|
+
};
|
|
8934
|
+
const initialise = async () => {
|
|
8935
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
8936
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
8937
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
8938
|
+
const body = {
|
|
8939
|
+
version: 1,
|
|
8940
|
+
data: {
|
|
8941
|
+
runtimeDetails,
|
|
8942
|
+
runtimeId: existingRuntimeId,
|
|
8943
|
+
},
|
|
8944
|
+
};
|
|
8945
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
8946
|
+
// Get runtimeId and store it
|
|
8947
|
+
const { runtimeId } = response;
|
|
8948
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
8949
|
+
initialised = true;
|
|
8950
|
+
};
|
|
8951
|
+
|
|
8952
|
+
function errorBoundary(fn) {
|
|
8953
|
+
const wrappedFunction = ((...args) => {
|
|
8954
|
+
try {
|
|
8955
|
+
// Execute the original function
|
|
8956
|
+
const result = fn(...args);
|
|
8957
|
+
if (result instanceof Promise) {
|
|
8958
|
+
// Silent fail for now, in future
|
|
8959
|
+
// we can send errors to a logging service
|
|
8960
|
+
return result.catch(() => undefined);
|
|
8961
|
+
}
|
|
8962
|
+
return result;
|
|
8963
|
+
}
|
|
8964
|
+
catch (error) {
|
|
8965
|
+
// As above, fail silently for now
|
|
8966
|
+
return undefined;
|
|
8967
|
+
}
|
|
8968
|
+
});
|
|
8969
|
+
return wrappedFunction;
|
|
8970
|
+
}
|
|
8971
|
+
|
|
8972
|
+
function isTestEnvironment() {
|
|
8973
|
+
if (typeof process === 'undefined') {
|
|
8974
|
+
return false;
|
|
8975
|
+
}
|
|
8976
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
8977
|
+
}
|
|
8978
|
+
// Sending events to the server
|
|
8979
|
+
const flushFn = async () => {
|
|
8980
|
+
// Don't flush if not initialised
|
|
8981
|
+
if (isInitialised() === false) {
|
|
8982
|
+
await initialise();
|
|
8983
|
+
return;
|
|
8984
|
+
}
|
|
8985
|
+
const events = getEvents();
|
|
8986
|
+
if (events.length === 0) {
|
|
8987
|
+
return;
|
|
8988
|
+
}
|
|
8989
|
+
// Track events length here, incase
|
|
8990
|
+
const numEvents = events.length;
|
|
8991
|
+
// Get details and send it with the track request
|
|
8992
|
+
const details = getAllDetails();
|
|
8993
|
+
const metricsPayload = {
|
|
8994
|
+
version: 1,
|
|
8995
|
+
data: {
|
|
8996
|
+
events,
|
|
8997
|
+
details,
|
|
8998
|
+
},
|
|
8999
|
+
};
|
|
9000
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
9001
|
+
if (response instanceof Error) {
|
|
9002
|
+
return;
|
|
9003
|
+
}
|
|
9004
|
+
// Clear events if successfully posted
|
|
9005
|
+
removeSentEvents(numEvents);
|
|
9006
|
+
};
|
|
9007
|
+
const flush = errorBoundary(flushFn);
|
|
9008
|
+
// Flush events every 5 seconds
|
|
9009
|
+
const flushPoll = async () => {
|
|
9010
|
+
await flush();
|
|
9011
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
9012
|
+
};
|
|
9013
|
+
// This will get initialised when module is imported.
|
|
9014
|
+
if (!isTestEnvironment()) {
|
|
9015
|
+
errorBoundary(flushPoll)();
|
|
9016
|
+
}
|
|
9017
|
+
|
|
8780
9018
|
var Environment;
|
|
8781
9019
|
(function (Environment) {
|
|
8782
9020
|
Environment["PRODUCTION"] = "production";
|
|
@@ -8792,7 +9030,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
8792
9030
|
chainID,
|
|
8793
9031
|
coreContractAddress,
|
|
8794
9032
|
registrationContractAddress,
|
|
8795
|
-
sdkVersion: 'ts-immutable-sdk-0.45.
|
|
9033
|
+
sdkVersion: 'ts-immutable-sdk-0.45.3-alpha',
|
|
8796
9034
|
});
|
|
8797
9035
|
/**
|
|
8798
9036
|
* Sets `sdkVersion` at the time of build
|
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;
|