@imtbl/sdk 1.36.2 → 1.36.3-alpha.1

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/orderbook.js CHANGED
@@ -132,7 +132,7 @@ const flattenProperties = (properties) => {
132
132
  };
133
133
 
134
134
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
135
- const SDK_VERSION = '1.36.2';
135
+ const SDK_VERSION = '1.36.3-alpha.1';
136
136
  const getFrameParentDomain = () => {
137
137
  if (isNode()) {
138
138
  return '';
@@ -1710,8 +1710,6 @@ function getOrderbookConfig(config) {
1710
1710
  case Environment.SANDBOX:
1711
1711
  return {
1712
1712
  seaportContractAddress: '0x7d117aA8BD6D31c4fa91722f246388f38ab1942c',
1713
- // eslint-disable-next-line max-len
1714
- // zoneContractAddress: '0x8831867E347AB87FA30199C5B695F0A31604Bb52', // ImmutableSignedZoneV1
1715
1713
  zoneContractAddress: '0x1004f9615E79462c711Ff05a386BdbA91a7628C3',
1716
1714
  apiEndpoint: 'https://api.sandbox.immutable.com',
1717
1715
  chainName: TESTNET_CHAIN_NAME,
@@ -1721,10 +1719,7 @@ function getOrderbookConfig(config) {
1721
1719
  case Environment.PRODUCTION:
1722
1720
  return {
1723
1721
  seaportContractAddress: '0x6c12aD6F0bD274191075Eb2E78D7dA5ba6453424',
1724
- // eslint-disable-next-line max-len
1725
- zoneContractAddress: '0x00338b92Bec262078B3e49BF12bbEA058916BF91',
1726
- // eslint-disable-next-line max-len
1727
- // zoneContractAddress: '0x1004f9615E79462c711Ff05a386BdbA91a7628C3', // ImmutableSignedZoneV2
1722
+ zoneContractAddress: '0x1004f9615E79462c711Ff05a386BdbA91a7628C3',
1728
1723
  apiEndpoint: 'https://api.immutable.com',
1729
1724
  chainName: MAINNET_CHAIN_NAME,
1730
1725
  provider: getConfiguredProvider('https://rpc.immutable.com', config.baseConfig.rateLimitingKey),
package/dist/passport.js CHANGED
@@ -11459,7 +11459,7 @@ class MultiRollupApiClients {
11459
11459
  }
11460
11460
 
11461
11461
  // eslint-disable-next-line @typescript-eslint/naming-convention
11462
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.36.2' };
11462
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.36.3-alpha.1' };
11463
11463
  const createConfig$1 = ({ basePath, headers, }) => {
11464
11464
  if (!basePath.trim()) {
11465
11465
  throw Error('basePath can not be empty');
@@ -11638,7 +11638,7 @@ const flattenProperties = (properties) => {
11638
11638
  };
11639
11639
 
11640
11640
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
11641
- const SDK_VERSION = '1.36.2';
11641
+ const SDK_VERSION = '1.36.3-alpha.1';
11642
11642
  const getFrameParentDomain = () => {
11643
11643
  if (isNode()) {
11644
11644
  return '';
@@ -12028,7 +12028,7 @@ const addKeysToHeadersOverride = (baseConfig, overrides) => {
12028
12028
  /* eslint-disable @typescript-eslint/naming-convention */
12029
12029
  class ApiConfiguration extends index$2.Configuration {
12030
12030
  }
12031
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.36.2' };
12031
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.36.3-alpha.1' };
12032
12032
  /**
12033
12033
  * @dev use createImmutableXConfiguration instead
12034
12034
  */
@@ -12067,7 +12067,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
12067
12067
  chainID,
12068
12068
  coreContractAddress,
12069
12069
  registrationContractAddress,
12070
- sdkVersion: 'ts-immutable-sdk-1.36.2',
12070
+ sdkVersion: 'ts-immutable-sdk-1.36.3-alpha.1',
12071
12071
  baseConfig,
12072
12072
  });
12073
12073
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -0,0 +1,11 @@
1
+ declare enum Environment {
2
+ PRODUCTION = "production",
3
+ SANDBOX = "sandbox"
4
+ }
5
+
6
+ declare const init: (body: string | Record<string, unknown>, env: Environment, handlers: {
7
+ zkevmMintRequestUpdated: (event: any) => Promise<void>;
8
+ others?: ((event: any) => Promise<void>) | undefined;
9
+ }) => Promise<void>;
10
+
11
+ export { init };
@@ -0,0 +1,388 @@
1
+ import MessageValidator from 'sns-validator';
2
+ import axios from 'axios';
3
+ import { memorise } from 'lru-memorise';
4
+ import { getGlobalisedValue as getGlobalisedValue$1 } from 'global-const';
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["SDK_VERSION"] = "sdkVersion";
18
+ })(Detail || (Detail = {}));
19
+
20
+ const IMTBL_API = 'https://api.immutable.com';
21
+ async function post(path, data) {
22
+ const client = axios.create({
23
+ baseURL: IMTBL_API,
24
+ });
25
+ const payload = JSON.stringify(data);
26
+ const body = {
27
+ payload: Buffer.from(payload).toString('base64'),
28
+ };
29
+ const response = await client.post(path, body);
30
+ return response.data;
31
+ }
32
+
33
+ /**
34
+ * Abstraction on localstorage
35
+ */
36
+ const localStoragePrefix = '__IMX-';
37
+ const hasLocalstorage = () => isBrowser() && window.localStorage;
38
+ const parseItem = (payload) => {
39
+ // Try to parse, if can't be parsed assume string
40
+ // and return string
41
+ if (payload === null)
42
+ return undefined;
43
+ try {
44
+ return JSON.parse(payload);
45
+ }
46
+ catch (error) {
47
+ // Assumes it's a string.
48
+ return payload;
49
+ }
50
+ };
51
+ const serialiseItem = (payload) => {
52
+ if (typeof payload === 'string') {
53
+ return payload;
54
+ }
55
+ return JSON.stringify(payload);
56
+ };
57
+ /**
58
+ * GenKey will take into account the namespace
59
+ * as well as if being run in the Link, it will tap into the link
60
+ * @param {string} key
61
+ * @returns key
62
+ */
63
+ const genKey = (key) => `${localStoragePrefix}${key}`;
64
+ function getItem(key) {
65
+ if (hasLocalstorage()) {
66
+ return parseItem(window.localStorage.getItem(genKey(key)));
67
+ }
68
+ return undefined;
69
+ }
70
+ const setItem = (key, payload) => {
71
+ if (hasLocalstorage()) {
72
+ window.localStorage.setItem(genKey(key), serialiseItem(payload));
73
+ return true;
74
+ }
75
+ return false;
76
+ };
77
+
78
+ var Store;
79
+ (function (Store) {
80
+ Store["EVENTS"] = "events";
81
+ Store["RUNTIME"] = "runtime";
82
+ })(Store || (Store = {}));
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$1 = (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
+ // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
132
+ const SDK_VERSION = '1.36.3-alpha.1';
133
+ const getFrameParentDomain = () => {
134
+ if (isNode()) {
135
+ return '';
136
+ }
137
+ // If available for supported browsers (all except Firefox)
138
+ if (window.location.ancestorOrigins
139
+ && window.location.ancestorOrigins.length > 0) {
140
+ return new URL(window.location.ancestorOrigins[0]).hostname;
141
+ }
142
+ // Fallback to using the referrer
143
+ return document.referrer ? new URL(window.document.referrer).hostname : '';
144
+ };
145
+ const runtimeHost = () => {
146
+ if (isNode()) {
147
+ return '';
148
+ }
149
+ let domain;
150
+ try {
151
+ if (window.self !== window.top) {
152
+ domain = getFrameParentDomain();
153
+ }
154
+ }
155
+ catch (error) {
156
+ // Do nothing
157
+ }
158
+ // Fallback to current domain if can't detect parent domain
159
+ if (!domain) {
160
+ domain = window.location.hostname;
161
+ }
162
+ return domain;
163
+ };
164
+ const getRuntimeDetails = () => {
165
+ storeDetail(Detail.SDK_VERSION, SDK_VERSION);
166
+ if (isNode()) {
167
+ return { browser: 'nodejs', sdkVersion: SDK_VERSION };
168
+ }
169
+ const domain = runtimeHost();
170
+ if (domain) {
171
+ storeDetail(Detail.DOMAIN, domain);
172
+ }
173
+ return {
174
+ sdkVersion: SDK_VERSION,
175
+ browser: window.navigator.userAgent,
176
+ domain,
177
+ tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
178
+ screen: `${window.screen.width}x${window.screen.height}`,
179
+ };
180
+ };
181
+ let initialised = false;
182
+ const isInitialised = () => initialised;
183
+ const initialise = async () => {
184
+ initialised = true;
185
+ try {
186
+ const runtimeDetails = flattenProperties(getRuntimeDetails());
187
+ const existingRuntimeId = getDetail$1(Detail.RUNTIME_ID);
188
+ const body = {
189
+ version: 1,
190
+ data: {
191
+ runtimeDetails,
192
+ runtimeId: existingRuntimeId,
193
+ },
194
+ };
195
+ const response = await post('/v1/sdk/initialise', body);
196
+ // Get runtimeId and store it
197
+ const { runtimeId } = response;
198
+ storeDetail(Detail.RUNTIME_ID, runtimeId);
199
+ }
200
+ catch (error) {
201
+ initialised = false;
202
+ }
203
+ };
204
+
205
+ function errorBoundary(fn, fallbackResult) {
206
+ return (...args) => {
207
+ try {
208
+ // Execute the original function
209
+ const result = fn(...args);
210
+ if (result instanceof Promise) {
211
+ // Silent fail for now, in future
212
+ // we can send errors to a logging service
213
+ return result.catch(() => fallbackResult);
214
+ }
215
+ return result;
216
+ }
217
+ catch (error) {
218
+ // As above, fail silently for now
219
+ return fallbackResult;
220
+ }
221
+ };
222
+ }
223
+
224
+ function isTestEnvironmentFn() {
225
+ if (isBrowser()) {
226
+ return false;
227
+ }
228
+ if (typeof process === 'undefined') {
229
+ return false;
230
+ }
231
+ // Consider using `ci-info` package for better results, though might fail as not browser safe.
232
+ // Just use process.env.CI for now.
233
+ return process.env.JEST_WORKER_ID !== undefined;
234
+ }
235
+ const isTestEnvironment = errorBoundary(isTestEnvironmentFn, false);
236
+
237
+ const GLOBALISE_KEY = 'imtbl__metrics';
238
+ const MEMORISE_TIMEFRAME = 5000;
239
+ const MEMORISE_MAX = 1000;
240
+ const getGlobalisedValue = (key, value) => getGlobalisedValue$1(GLOBALISE_KEY, key, value);
241
+ const getGlobalisedCachedFunction = (key, fn) => {
242
+ // Some applications (esp backend, or frontends using the split bundles) can sometimes
243
+ // initialise the same request multiple times. This will prevent multiple of the
244
+ // same event,value from being reported in a 1 second period.
245
+ const memorisedFn = memorise(fn, {
246
+ lruOptions: { ttl: MEMORISE_TIMEFRAME, max: MEMORISE_MAX },
247
+ });
248
+ return getGlobalisedValue$1(GLOBALISE_KEY, key, memorisedFn);
249
+ };
250
+
251
+ const POLLING_FREQUENCY = 5000;
252
+ const trackFn = (moduleName, eventName, properties) => {
253
+ const event = {
254
+ event: `${moduleName}.${eventName}`,
255
+ time: new Date().toISOString(),
256
+ ...(properties && { properties: flattenProperties(properties) }),
257
+ };
258
+ addEvent(event);
259
+ };
260
+ /**
261
+ * Track an event completion.
262
+ * @param moduleName Name of the module being tracked (for namespacing purposes), e.g. `passport`
263
+ * @param eventName Name of the event, use camelCase e.g. `clickItem`
264
+ * @param properties Other properties to be sent with the event
265
+ *
266
+ * e.g.
267
+ *
268
+ * ```ts
269
+ * track("passport", "performTransaction");
270
+ * track("passport", "performTransaction", { transationType: "transfer" });
271
+ * ```
272
+ */
273
+ errorBoundary(getGlobalisedCachedFunction('track', trackFn));
274
+ // Sending events to the server
275
+ const flushFn = async () => {
276
+ // Don't flush if not initialised
277
+ if (isInitialised() === false) {
278
+ await initialise();
279
+ return;
280
+ }
281
+ const events = getEvents();
282
+ if (events.length === 0) {
283
+ return;
284
+ }
285
+ // Track events length here, incase
286
+ const numEvents = events.length;
287
+ // Get details and send it with the track request
288
+ const details = getAllDetails();
289
+ const metricsPayload = {
290
+ version: 1,
291
+ data: {
292
+ events,
293
+ details,
294
+ },
295
+ };
296
+ const response = await post('/v1/sdk/metrics', metricsPayload);
297
+ if (response instanceof Error) {
298
+ return;
299
+ }
300
+ // Clear events if successfully posted
301
+ removeSentEvents(numEvents);
302
+ };
303
+ const flush = errorBoundary(flushFn);
304
+ // Flush events every 5 seconds
305
+ const flushPoll = async () => {
306
+ await flush();
307
+ setTimeout(flushPoll, POLLING_FREQUENCY);
308
+ };
309
+ let flushingStarted = false;
310
+ const startFlushing = () => {
311
+ if (flushingStarted) {
312
+ return;
313
+ }
314
+ flushingStarted = true;
315
+ flushPoll();
316
+ };
317
+ // This will get initialised when module is imported.
318
+ if (!isTestEnvironment()) {
319
+ errorBoundary(getGlobalisedValue('startFlushing', startFlushing))();
320
+ }
321
+
322
+ const setEnvironmentFn = (env) => {
323
+ storeDetail(Detail.ENVIRONMENT, env);
324
+ };
325
+ errorBoundary(getGlobalisedValue('setEnvironment', setEnvironmentFn));
326
+ const setPassportClientIdFn = (passportClientId) => {
327
+ storeDetail(Detail.PASSPORT_CLIENT_ID, passportClientId);
328
+ };
329
+ errorBoundary(getGlobalisedValue('setPassportClientId', setPassportClientIdFn));
330
+ const setPublishableApiKeyFn = (publishableApiKey) => {
331
+ storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
332
+ };
333
+ errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
334
+ errorBoundary(getGlobalisedValue('getDetail', getDetail$1));
335
+
336
+ var Environment;
337
+ (function (Environment) {
338
+ Environment["PRODUCTION"] = "production";
339
+ Environment["SANDBOX"] = "sandbox";
340
+ })(Environment || (Environment = {}));
341
+ var KeyHeaders;
342
+ (function (KeyHeaders) {
343
+ KeyHeaders["API_KEY"] = "x-immutable-api-key";
344
+ KeyHeaders["PUBLISHABLE_KEY"] = "x-immutable-publishable-key";
345
+ KeyHeaders["RATE_LIMITING_KEY"] = "x-api-key";
346
+ })(KeyHeaders || (KeyHeaders = {}));
347
+
348
+ const validator = new MessageValidator();
349
+ const allowedTopicArnPrefix = {
350
+ [Environment.PRODUCTION]: 'arn:aws:sns:us-east-2:362750628221:',
351
+ [Environment.SANDBOX]: 'arn:aws:sns:us-east-2:783421985614:'
352
+ };
353
+ const init = async (body, env, handlers) => {
354
+ const msg = await new Promise((resolve, reject) => {
355
+ validator.validate(body, (err, message) => {
356
+ if (err) {
357
+ return reject(err);
358
+ }
359
+ // check for topic arn prefix
360
+ if (!message.TopicArn.startsWith(allowedTopicArnPrefix[env])) {
361
+ throw new Error('Invalid topic arn');
362
+ }
363
+ if (message?.Type === 'SubscriptionConfirmation') {
364
+ fetch(message.SubscribeURL).then(() => {
365
+ resolve(message);
366
+ }).catch((e) => {
367
+ reject(e);
368
+ });
369
+ }
370
+ return resolve(message);
371
+ });
372
+ });
373
+ if (msg.Type === 'Notification') {
374
+ const event = JSON.parse(msg.Message);
375
+ switch (event.event_name) {
376
+ case 'imtbl_zkevm_mint_request_updated':
377
+ await handlers.zkevmMintRequestUpdated(event);
378
+ break;
379
+ default:
380
+ if (handlers.others) {
381
+ await handlers.others(event);
382
+ }
383
+ break;
384
+ }
385
+ }
386
+ };
387
+
388
+ export { init };
package/dist/x.js CHANGED
@@ -9003,7 +9003,7 @@ const flattenProperties = (properties) => {
9003
9003
  };
9004
9004
 
9005
9005
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
9006
- const SDK_VERSION = '1.36.2';
9006
+ const SDK_VERSION = '1.36.3-alpha.1';
9007
9007
  const getFrameParentDomain = () => {
9008
9008
  if (isNode()) {
9009
9009
  return '';
@@ -9269,7 +9269,7 @@ const addKeysToHeadersOverride = (baseConfig, overrides) => {
9269
9269
  /* eslint-disable @typescript-eslint/naming-convention */
9270
9270
  class ApiConfiguration extends index$2.Configuration {
9271
9271
  }
9272
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.36.2' };
9272
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.36.3-alpha.1' };
9273
9273
  /**
9274
9274
  * @dev use createImmutableXConfiguration instead
9275
9275
  */
@@ -9308,7 +9308,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
9308
9308
  chainID,
9309
9309
  coreContractAddress,
9310
9310
  registrationContractAddress,
9311
- sdkVersion: 'ts-immutable-sdk-1.36.2',
9311
+ sdkVersion: 'ts-immutable-sdk-1.36.3-alpha.1',
9312
9312
  baseConfig,
9313
9313
  });
9314
9314
  const production = ({ baseConfig }) => createImmutableXConfiguration({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "1.36.2",
4
+ "version": "1.36.3-alpha.1",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
@@ -122,6 +122,14 @@
122
122
  "./x": {
123
123
  "types": "./dist/x.d.ts",
124
124
  "import": "./dist/x.js"
125
+ },
126
+ "./webhook": {
127
+ "types": "./dist/webhook.d.ts",
128
+ "import": "./dist/webhook.js"
129
+ },
130
+ "./minting_backend": {
131
+ "types": "./dist/minting_backend.d.ts",
132
+ "import": "./dist/minting_backend.js"
125
133
  }
126
134
  },
127
135
  "files": [