@imtbl/sdk 0.45.4 → 0.45.5

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.
@@ -10117,9 +10117,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
10117
10117
  } ? Required<{
10118
10118
  publishableKey: string;
10119
10119
  }> : {});
10120
- type ImmutableConfigurationWithOmitableFields<T> = (T extends {
10120
+ type ImmutableConfigurationWithOmitableFields<T> = T extends {
10121
10121
  apiKey: 'omit';
10122
- } ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
10122
+ } ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
10123
10123
  interface ModuleConfiguration<T> {
10124
10124
  baseConfig: ImmutableConfigurationWithOmitableFields<T>;
10125
10125
  overrides?: T;
package/dist/checkout.js CHANGED
@@ -11,6 +11,264 @@ import { SwapRouter, PaymentsExtended } from '@uniswap/router-sdk';
11
11
  import FormData$2 from 'form-data';
12
12
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
13
13
 
14
+ const isNode$1 = () => typeof window === 'undefined';
15
+ const isBrowser$1 = () => !isNode$1();
16
+
17
+ var Detail$1;
18
+ (function (Detail) {
19
+ Detail["RUNTIME_ID"] = "rid";
20
+ Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
21
+ Detail["ENVIRONMENT"] = "env";
22
+ Detail["PUBLISHABLE_API_KEY"] = "pak";
23
+ Detail["IDENTITY"] = "uid";
24
+ Detail["DOMAIN"] = "domain";
25
+ })(Detail$1 || (Detail$1 = {}));
26
+ var Store$1;
27
+ (function (Store) {
28
+ Store["EVENTS"] = "events";
29
+ Store["RUNTIME"] = "runtime";
30
+ })(Store$1 || (Store$1 = {}));
31
+ const POLLING_FREQUENCY$1 = 5000;
32
+
33
+ const IMTBL_API$1 = 'https://api.x.immutable.com';
34
+ async function post$1(path, data) {
35
+ const client = globalAxios.create({
36
+ baseURL: IMTBL_API$1,
37
+ });
38
+ const payload = JSON.stringify(data);
39
+ const body = {
40
+ payload: btoa(payload),
41
+ };
42
+ const response = await client.post(path, body);
43
+ return response.data;
44
+ }
45
+
46
+ /**
47
+ * Abstraction on localstorage
48
+ */
49
+ const localStoragePrefix$1 = '__IMX-';
50
+ const hasLocalstorage$1 = () => isBrowser$1() && window.localStorage;
51
+ const parseItem$1 = (payload) => {
52
+ // Try to parse, if can't be parsed assume string
53
+ // and return string
54
+ if (payload === null)
55
+ return undefined;
56
+ try {
57
+ return JSON.parse(payload);
58
+ }
59
+ catch (error) {
60
+ // Assumes it's a string.
61
+ return payload;
62
+ }
63
+ };
64
+ const serialiseItem$1 = (payload) => {
65
+ if (typeof payload === 'string') {
66
+ return payload;
67
+ }
68
+ return JSON.stringify(payload);
69
+ };
70
+ /**
71
+ * GenKey will take into account the namespace
72
+ * as well as if being run in the Link, it will tap into the link
73
+ * @param {string} key
74
+ * @returns key
75
+ */
76
+ const genKey$1 = (key) => `${localStoragePrefix$1}${key}`;
77
+ function getItem$1(key) {
78
+ if (hasLocalstorage$1()) {
79
+ return parseItem$1(window.localStorage.getItem(genKey$1(key)));
80
+ }
81
+ return undefined;
82
+ }
83
+ const setItem$1 = (key, payload) => {
84
+ if (hasLocalstorage$1()) {
85
+ window.localStorage.setItem(genKey$1(key), serialiseItem$1(payload));
86
+ return true;
87
+ }
88
+ return false;
89
+ };
90
+
91
+ // In memory storage for events and other data
92
+ let EVENT_STORE$1;
93
+ let RUNTIME_DETAILS$1;
94
+ // Initialise store and runtime
95
+ const initialise$1$1 = () => {
96
+ EVENT_STORE$1 = getItem$1(Store$1.EVENTS) || [];
97
+ RUNTIME_DETAILS$1 = getItem$1(Store$1.RUNTIME) || {};
98
+ };
99
+ initialise$1$1();
100
+ // Runtime Details
101
+ const storeDetail$1 = (key, value) => {
102
+ RUNTIME_DETAILS$1 = {
103
+ ...RUNTIME_DETAILS$1,
104
+ [key]: value,
105
+ };
106
+ setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
107
+ };
108
+ const getDetail$1 = (key) => {
109
+ // Handle the scenario where detail is a falsy value
110
+ if (RUNTIME_DETAILS$1[key] === undefined) {
111
+ return undefined;
112
+ }
113
+ return RUNTIME_DETAILS$1[key];
114
+ };
115
+ const getAllDetails$1 = () => RUNTIME_DETAILS$1;
116
+ // Events
117
+ const getEvents$1 = () => EVENT_STORE$1;
118
+ const addEvent = (event) => {
119
+ EVENT_STORE$1.push(event);
120
+ setItem$1(Store$1.EVENTS, EVENT_STORE$1);
121
+ };
122
+ const removeSentEvents$1 = (numberOfEvents) => {
123
+ EVENT_STORE$1 = EVENT_STORE$1.slice(numberOfEvents);
124
+ setItem$1(Store$1.EVENTS, EVENT_STORE$1);
125
+ };
126
+ const flattenProperties$1 = (properties) => {
127
+ const propertyMap = [];
128
+ Object.entries(properties).forEach(([key, value]) => {
129
+ if (typeof value === 'string' || typeof value === 'number') {
130
+ propertyMap.push([key, value.toString()]);
131
+ }
132
+ });
133
+ return propertyMap;
134
+ };
135
+
136
+ let initialised$1 = false;
137
+ const isInitialised$1 = () => initialised$1;
138
+ const getReferrer$1 = () => {
139
+ if (isNode$1()) {
140
+ return '';
141
+ }
142
+ if (window.location.ancestorOrigins
143
+ && window.location.ancestorOrigins.length > 0) {
144
+ return new URL(window.location.ancestorOrigins[0]).hostname;
145
+ }
146
+ return document.referrer ? new URL(window.document.referrer).hostname : '';
147
+ };
148
+ const runtimeHost$1 = () => {
149
+ if (isNode$1()) {
150
+ return '';
151
+ }
152
+ if (window.opener || window.parent !== window) {
153
+ return getReferrer$1();
154
+ }
155
+ return new URL(window.location.href).hostname;
156
+ };
157
+ const getRuntimeDetails$1 = () => {
158
+ if (isNode$1()) {
159
+ return { browser: 'nodejs' };
160
+ }
161
+ const domain = runtimeHost$1();
162
+ if (domain) {
163
+ storeDetail$1(Detail$1.DOMAIN, domain);
164
+ }
165
+ return {
166
+ browser: window.navigator.userAgent,
167
+ domain,
168
+ tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
169
+ screen: `${window.screen.width}x${window.screen.height}`,
170
+ };
171
+ };
172
+ const initialise$2 = async () => {
173
+ const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
174
+ // Get any existing runtimeId and send it along with the initialise
175
+ const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
176
+ const body = {
177
+ version: 1,
178
+ data: {
179
+ runtimeDetails,
180
+ runtimeId: existingRuntimeId,
181
+ },
182
+ };
183
+ const response = await post$1('/v1/sdk/initialise', body);
184
+ // Get runtimeId and store it
185
+ const { runtimeId } = response;
186
+ storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
187
+ initialised$1 = true;
188
+ };
189
+
190
+ function errorBoundary$1(fn) {
191
+ const wrappedFunction = ((...args) => {
192
+ try {
193
+ // Execute the original function
194
+ const result = fn(...args);
195
+ if (result instanceof Promise) {
196
+ // Silent fail for now, in future
197
+ // we can send errors to a logging service
198
+ return result.catch(() => undefined);
199
+ }
200
+ return result;
201
+ }
202
+ catch (error) {
203
+ // As above, fail silently for now
204
+ return undefined;
205
+ }
206
+ });
207
+ return wrappedFunction;
208
+ }
209
+
210
+ function isTestEnvironment$1() {
211
+ if (typeof process === 'undefined') {
212
+ return false;
213
+ }
214
+ return process.env.JEST_WORKER_ID !== undefined;
215
+ }
216
+
217
+ // Store the event in the event store
218
+ const trackFn = (moduleName, eventName, properties) => {
219
+ const event = {
220
+ event: `${moduleName}.${eventName}`,
221
+ time: new Date().toISOString(),
222
+ ...(properties && { properties: flattenProperties$1(properties) }),
223
+ };
224
+ addEvent(event);
225
+ };
226
+ const track = errorBoundary$1(trackFn);
227
+ // Sending events to the server
228
+ const flushFn$1 = async () => {
229
+ // Don't flush if not initialised
230
+ if (isInitialised$1() === false) {
231
+ await initialise$2();
232
+ return;
233
+ }
234
+ const events = getEvents$1();
235
+ if (events.length === 0) {
236
+ return;
237
+ }
238
+ // Track events length here, incase
239
+ const numEvents = events.length;
240
+ // Get details and send it with the track request
241
+ const details = getAllDetails$1();
242
+ const metricsPayload = {
243
+ version: 1,
244
+ data: {
245
+ events,
246
+ details,
247
+ },
248
+ };
249
+ const response = await post$1('/v1/sdk/metrics', metricsPayload);
250
+ if (response instanceof Error) {
251
+ return;
252
+ }
253
+ // Clear events if successfully posted
254
+ removeSentEvents$1(numEvents);
255
+ };
256
+ const flush$1 = errorBoundary$1(flushFn$1);
257
+ // Flush events every 5 seconds
258
+ const flushPoll$1 = async () => {
259
+ await flush$1();
260
+ setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
261
+ };
262
+ // This will get initialised when module is imported.
263
+ if (!isTestEnvironment$1()) {
264
+ errorBoundary$1(flushPoll$1)();
265
+ }
266
+
267
+ const setEnvironmentFn = (env) => {
268
+ storeDetail$1(Detail$1.ENVIRONMENT, env);
269
+ };
270
+ const setEnvironment = errorBoundary$1(setEnvironmentFn);
271
+
14
272
  var Environment$1;
15
273
  (function (Environment) {
16
274
  Environment["PRODUCTION"] = "production";
@@ -23,6 +281,8 @@ class ImmutableConfiguration {
23
281
  publishableKey;
24
282
  constructor(options) {
25
283
  this.environment = options.environment;
284
+ setEnvironment(options.environment);
285
+ track('config', 'load_imtbl_config');
26
286
  }
27
287
  }
28
288
 
@@ -16695,6 +16955,244 @@ class TokenBridge {
16695
16955
  }
16696
16956
  }
16697
16957
 
16958
+ const isNode = () => typeof window === 'undefined';
16959
+ const isBrowser = () => !isNode();
16960
+
16961
+ var Detail;
16962
+ (function (Detail) {
16963
+ Detail["RUNTIME_ID"] = "rid";
16964
+ Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
16965
+ Detail["ENVIRONMENT"] = "env";
16966
+ Detail["PUBLISHABLE_API_KEY"] = "pak";
16967
+ Detail["IDENTITY"] = "uid";
16968
+ Detail["DOMAIN"] = "domain";
16969
+ })(Detail || (Detail = {}));
16970
+ var Store;
16971
+ (function (Store) {
16972
+ Store["EVENTS"] = "events";
16973
+ Store["RUNTIME"] = "runtime";
16974
+ })(Store || (Store = {}));
16975
+ const POLLING_FREQUENCY = 5000;
16976
+
16977
+ const IMTBL_API = 'https://api.x.immutable.com';
16978
+ async function post(path, data) {
16979
+ const client = axios$1.create({
16980
+ baseURL: IMTBL_API,
16981
+ });
16982
+ const payload = JSON.stringify(data);
16983
+ const body = {
16984
+ payload: btoa(payload),
16985
+ };
16986
+ const response = await client.post(path, body);
16987
+ return response.data;
16988
+ }
16989
+
16990
+ /**
16991
+ * Abstraction on localstorage
16992
+ */
16993
+ const localStoragePrefix = '__IMX-';
16994
+ const hasLocalstorage = () => isBrowser() && window.localStorage;
16995
+ const parseItem = (payload) => {
16996
+ // Try to parse, if can't be parsed assume string
16997
+ // and return string
16998
+ if (payload === null)
16999
+ return undefined;
17000
+ try {
17001
+ return JSON.parse(payload);
17002
+ }
17003
+ catch (error) {
17004
+ // Assumes it's a string.
17005
+ return payload;
17006
+ }
17007
+ };
17008
+ const serialiseItem = (payload) => {
17009
+ if (typeof payload === 'string') {
17010
+ return payload;
17011
+ }
17012
+ return JSON.stringify(payload);
17013
+ };
17014
+ /**
17015
+ * GenKey will take into account the namespace
17016
+ * as well as if being run in the Link, it will tap into the link
17017
+ * @param {string} key
17018
+ * @returns key
17019
+ */
17020
+ const genKey = (key) => `${localStoragePrefix}${key}`;
17021
+ function getItem(key) {
17022
+ if (hasLocalstorage()) {
17023
+ return parseItem(window.localStorage.getItem(genKey(key)));
17024
+ }
17025
+ return undefined;
17026
+ }
17027
+ const setItem = (key, payload) => {
17028
+ if (hasLocalstorage()) {
17029
+ window.localStorage.setItem(genKey(key), serialiseItem(payload));
17030
+ return true;
17031
+ }
17032
+ return false;
17033
+ };
17034
+
17035
+ // In memory storage for events and other data
17036
+ let EVENT_STORE;
17037
+ let RUNTIME_DETAILS;
17038
+ // Initialise store and runtime
17039
+ const initialise$1 = () => {
17040
+ EVENT_STORE = getItem(Store.EVENTS) || [];
17041
+ RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
17042
+ };
17043
+ initialise$1();
17044
+ // Runtime Details
17045
+ const storeDetail = (key, value) => {
17046
+ RUNTIME_DETAILS = {
17047
+ ...RUNTIME_DETAILS,
17048
+ [key]: value,
17049
+ };
17050
+ setItem(Store.RUNTIME, RUNTIME_DETAILS);
17051
+ };
17052
+ const getDetail = (key) => {
17053
+ // Handle the scenario where detail is a falsy value
17054
+ if (RUNTIME_DETAILS[key] === undefined) {
17055
+ return undefined;
17056
+ }
17057
+ return RUNTIME_DETAILS[key];
17058
+ };
17059
+ const getAllDetails = () => RUNTIME_DETAILS;
17060
+ // Events
17061
+ const getEvents = () => EVENT_STORE;
17062
+ const removeSentEvents = (numberOfEvents) => {
17063
+ EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
17064
+ setItem(Store.EVENTS, EVENT_STORE);
17065
+ };
17066
+ const flattenProperties = (properties) => {
17067
+ const propertyMap = [];
17068
+ Object.entries(properties).forEach(([key, value]) => {
17069
+ if (typeof value === 'string' || typeof value === 'number') {
17070
+ propertyMap.push([key, value.toString()]);
17071
+ }
17072
+ });
17073
+ return propertyMap;
17074
+ };
17075
+
17076
+ let initialised = false;
17077
+ const isInitialised = () => initialised;
17078
+ const getReferrer = () => {
17079
+ if (isNode()) {
17080
+ return '';
17081
+ }
17082
+ if (window.location.ancestorOrigins
17083
+ && window.location.ancestorOrigins.length > 0) {
17084
+ return new URL(window.location.ancestorOrigins[0]).hostname;
17085
+ }
17086
+ return document.referrer ? new URL(window.document.referrer).hostname : '';
17087
+ };
17088
+ const runtimeHost = () => {
17089
+ if (isNode()) {
17090
+ return '';
17091
+ }
17092
+ if (window.opener || window.parent !== window) {
17093
+ return getReferrer();
17094
+ }
17095
+ return new URL(window.location.href).hostname;
17096
+ };
17097
+ const getRuntimeDetails = () => {
17098
+ if (isNode()) {
17099
+ return { browser: 'nodejs' };
17100
+ }
17101
+ const domain = runtimeHost();
17102
+ if (domain) {
17103
+ storeDetail(Detail.DOMAIN, domain);
17104
+ }
17105
+ return {
17106
+ browser: window.navigator.userAgent,
17107
+ domain,
17108
+ tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
17109
+ screen: `${window.screen.width}x${window.screen.height}`,
17110
+ };
17111
+ };
17112
+ const initialise = async () => {
17113
+ const runtimeDetails = flattenProperties(getRuntimeDetails());
17114
+ // Get any existing runtimeId and send it along with the initialise
17115
+ const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
17116
+ const body = {
17117
+ version: 1,
17118
+ data: {
17119
+ runtimeDetails,
17120
+ runtimeId: existingRuntimeId,
17121
+ },
17122
+ };
17123
+ const response = await post('/v1/sdk/initialise', body);
17124
+ // Get runtimeId and store it
17125
+ const { runtimeId } = response;
17126
+ storeDetail(Detail.RUNTIME_ID, runtimeId);
17127
+ initialised = true;
17128
+ };
17129
+
17130
+ function errorBoundary(fn) {
17131
+ const wrappedFunction = ((...args) => {
17132
+ try {
17133
+ // Execute the original function
17134
+ const result = fn(...args);
17135
+ if (result instanceof Promise) {
17136
+ // Silent fail for now, in future
17137
+ // we can send errors to a logging service
17138
+ return result.catch(() => undefined);
17139
+ }
17140
+ return result;
17141
+ }
17142
+ catch (error) {
17143
+ // As above, fail silently for now
17144
+ return undefined;
17145
+ }
17146
+ });
17147
+ return wrappedFunction;
17148
+ }
17149
+
17150
+ function isTestEnvironment() {
17151
+ if (typeof process === 'undefined') {
17152
+ return false;
17153
+ }
17154
+ return process.env.JEST_WORKER_ID !== undefined;
17155
+ }
17156
+ // Sending events to the server
17157
+ const flushFn = async () => {
17158
+ // Don't flush if not initialised
17159
+ if (isInitialised() === false) {
17160
+ await initialise();
17161
+ return;
17162
+ }
17163
+ const events = getEvents();
17164
+ if (events.length === 0) {
17165
+ return;
17166
+ }
17167
+ // Track events length here, incase
17168
+ const numEvents = events.length;
17169
+ // Get details and send it with the track request
17170
+ const details = getAllDetails();
17171
+ const metricsPayload = {
17172
+ version: 1,
17173
+ data: {
17174
+ events,
17175
+ details,
17176
+ },
17177
+ };
17178
+ const response = await post('/v1/sdk/metrics', metricsPayload);
17179
+ if (response instanceof Error) {
17180
+ return;
17181
+ }
17182
+ // Clear events if successfully posted
17183
+ removeSentEvents(numEvents);
17184
+ };
17185
+ const flush = errorBoundary(flushFn);
17186
+ // Flush events every 5 seconds
17187
+ const flushPoll = async () => {
17188
+ await flush();
17189
+ setTimeout(flushPoll, POLLING_FREQUENCY);
17190
+ };
17191
+ // This will get initialised when module is imported.
17192
+ if (!isTestEnvironment()) {
17193
+ errorBoundary(flushPoll)();
17194
+ }
17195
+
16698
17196
  var Environment;
16699
17197
  (function (Environment) {
16700
17198
  Environment["PRODUCTION"] = "production";
@@ -26336,7 +26834,7 @@ class APIError extends Error {
26336
26834
 
26337
26835
  /* eslint-disable implicit-arrow-linebreak */
26338
26836
  const defaultHeaders = {
26339
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.4',
26837
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.5',
26340
26838
  };
26341
26839
  /**
26342
26840
  * createAPIConfiguration to create a custom Configuration
@@ -27698,7 +28196,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
27698
28196
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
27699
28197
  };
27700
28198
 
27701
- const SDK_VERSION_MARKER = '0.45.4';
28199
+ const SDK_VERSION_MARKER = '0.45.5';
27702
28200
  // This SDK version is replaced by the `yarn build` command ran on the root level
27703
28201
  const globalPackageVersion = () => SDK_VERSION_MARKER;
27704
28202
 
@@ -27903,7 +28401,7 @@ async function getERC20TokenInfo(web3Provider, tokenAddress) {
27903
28401
  }, { type: CheckoutErrorType.GET_ERC20_INFO_ERROR });
27904
28402
  }
27905
28403
 
27906
- const CACHE_DATA_TTL = 60; // seconds
28404
+ const CACHE_DATA_TTL = 5; // seconds
27907
28405
  /**
27908
28406
  * Blockscout class provides a client abstraction for the Immutable 3rd party indexer.
27909
28407
  */
package/dist/config.d.ts CHANGED
@@ -23,9 +23,9 @@ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (
23
23
  } ? Required<{
24
24
  publishableKey: string;
25
25
  }> : {});
26
- type ImmutableConfigurationWithOmitableFields<T> = (T extends {
26
+ type ImmutableConfigurationWithOmitableFields<T> = T extends {
27
27
  apiKey: 'omit';
28
- } ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
28
+ } ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
29
29
  interface ModuleConfiguration<T> {
30
30
  baseConfig: ImmutableConfigurationWithOmitableFields<T>;
31
31
  overrides?: T;