@imtbl/sdk 0.1.7-alpha.3 → 0.1.8-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 +83 -3
- package/dist/blockchain-data.js +19 -19
- package/dist/browser/checkout.js +2 -2
- package/dist/immutablex_client.js +1 -1
- package/dist/index.cjs +54 -60
- package/dist/index.d.ts +66 -3
- package/dist/index.js +56 -63
- package/dist/orderbook.js +37 -43
- package/dist/passport.js +1 -1
- package/package.json +1 -1
package/dist/orderbook.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ItemType, SEAPORT_CONTRACT_NAME, SEAPORT_CONTRACT_VERSION_V1_4, EIP_712_ORDER_TYPE, OrderType } from '@opensea/seaport-js/lib/constants';
|
|
2
|
+
import axios from 'axios';
|
|
2
3
|
import FormData from 'form-data';
|
|
3
|
-
import fetch, { Headers } from 'node-fetch';
|
|
4
4
|
import { utils, Contract, BigNumber, constants } from 'ethers';
|
|
5
5
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
6
6
|
|
|
@@ -147,6 +147,9 @@ const isBlob = (value) => {
|
|
|
147
147
|
const isFormData = (value) => {
|
|
148
148
|
return value instanceof FormData;
|
|
149
149
|
};
|
|
150
|
+
const isSuccess = (status) => {
|
|
151
|
+
return status >= 200 && status < 300;
|
|
152
|
+
};
|
|
150
153
|
const base64 = (str) => {
|
|
151
154
|
try {
|
|
152
155
|
return btoa(str);
|
|
@@ -233,15 +236,17 @@ const resolve = async (options, resolver) => {
|
|
|
233
236
|
}
|
|
234
237
|
return resolver;
|
|
235
238
|
};
|
|
236
|
-
const getHeaders = async (config, options) => {
|
|
239
|
+
const getHeaders = async (config, options, formData) => {
|
|
237
240
|
const token = await resolve(options, config.TOKEN);
|
|
238
241
|
const username = await resolve(options, config.USERNAME);
|
|
239
242
|
const password = await resolve(options, config.PASSWORD);
|
|
240
243
|
const additionalHeaders = await resolve(options, config.HEADERS);
|
|
244
|
+
const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {};
|
|
241
245
|
const headers = Object.entries({
|
|
242
246
|
Accept: 'application/json',
|
|
243
247
|
...additionalHeaders,
|
|
244
248
|
...options.headers,
|
|
249
|
+
...formHeaders,
|
|
245
250
|
})
|
|
246
251
|
.filter(([_, value]) => isDefined(value))
|
|
247
252
|
.reduce((headers, [key, value]) => ({
|
|
@@ -260,7 +265,7 @@ const getHeaders = async (config, options) => {
|
|
|
260
265
|
headers['Content-Type'] = options.mediaType;
|
|
261
266
|
}
|
|
262
267
|
else if (isBlob(options.body)) {
|
|
263
|
-
headers['Content-Type'] = 'application/octet-stream';
|
|
268
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
264
269
|
}
|
|
265
270
|
else if (isString(options.body)) {
|
|
266
271
|
headers['Content-Type'] = 'text/plain';
|
|
@@ -269,59 +274,48 @@ const getHeaders = async (config, options) => {
|
|
|
269
274
|
headers['Content-Type'] = 'application/json';
|
|
270
275
|
}
|
|
271
276
|
}
|
|
272
|
-
return
|
|
277
|
+
return headers;
|
|
273
278
|
};
|
|
274
279
|
const getRequestBody = (options) => {
|
|
275
280
|
if (options.body) {
|
|
276
|
-
|
|
277
|
-
return JSON.stringify(options.body);
|
|
278
|
-
}
|
|
279
|
-
else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
280
|
-
return options.body;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
return JSON.stringify(options.body);
|
|
284
|
-
}
|
|
281
|
+
return options.body;
|
|
285
282
|
}
|
|
286
283
|
return undefined;
|
|
287
284
|
};
|
|
288
|
-
const sendRequest = async (options, url, body, formData, headers, onCancel) => {
|
|
289
|
-
const
|
|
290
|
-
const
|
|
285
|
+
const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
|
|
286
|
+
const source = axios.CancelToken.source();
|
|
287
|
+
const requestConfig = {
|
|
288
|
+
url,
|
|
291
289
|
headers,
|
|
290
|
+
data: body ?? formData,
|
|
292
291
|
method: options.method,
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
withCredentials: config.WITH_CREDENTIALS,
|
|
293
|
+
cancelToken: source.token,
|
|
295
294
|
};
|
|
296
|
-
onCancel(() =>
|
|
297
|
-
|
|
295
|
+
onCancel(() => source.cancel('The user aborted a request.'));
|
|
296
|
+
try {
|
|
297
|
+
return await axios.request(requestConfig);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
const axiosError = error;
|
|
301
|
+
if (axiosError.response) {
|
|
302
|
+
return axiosError.response;
|
|
303
|
+
}
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
298
306
|
};
|
|
299
307
|
const getResponseHeader = (response, responseHeader) => {
|
|
300
308
|
if (responseHeader) {
|
|
301
|
-
const content = response.headers
|
|
309
|
+
const content = response.headers[responseHeader];
|
|
302
310
|
if (isString(content)) {
|
|
303
311
|
return content;
|
|
304
312
|
}
|
|
305
313
|
}
|
|
306
314
|
return undefined;
|
|
307
315
|
};
|
|
308
|
-
const getResponseBody =
|
|
316
|
+
const getResponseBody = (response) => {
|
|
309
317
|
if (response.status !== 204) {
|
|
310
|
-
|
|
311
|
-
const contentType = response.headers.get('Content-Type');
|
|
312
|
-
if (contentType) {
|
|
313
|
-
const isJSON = contentType.toLowerCase().startsWith('application/json');
|
|
314
|
-
if (isJSON) {
|
|
315
|
-
return await response.json();
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
return await response.text();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
catch (error) {
|
|
323
|
-
console.error(error);
|
|
324
|
-
}
|
|
318
|
+
return response.data;
|
|
325
319
|
}
|
|
326
320
|
return undefined;
|
|
327
321
|
};
|
|
@@ -357,14 +351,14 @@ const request = (config, options) => {
|
|
|
357
351
|
const url = getUrl(config, options);
|
|
358
352
|
const formData = getFormData(options);
|
|
359
353
|
const body = getRequestBody(options);
|
|
360
|
-
const headers = await getHeaders(config, options);
|
|
354
|
+
const headers = await getHeaders(config, options, formData);
|
|
361
355
|
if (!onCancel.isCancelled) {
|
|
362
|
-
const response = await sendRequest(options, url, body, formData, headers, onCancel);
|
|
363
|
-
const responseBody =
|
|
356
|
+
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
357
|
+
const responseBody = getResponseBody(response);
|
|
364
358
|
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
365
359
|
const result = {
|
|
366
360
|
url,
|
|
367
|
-
ok: response.
|
|
361
|
+
ok: isSuccess(response.status),
|
|
368
362
|
status: response.status,
|
|
369
363
|
statusText: response.statusText,
|
|
370
364
|
body: responseHeader ?? responseBody,
|
|
@@ -379,7 +373,7 @@ const request = (config, options) => {
|
|
|
379
373
|
});
|
|
380
374
|
};
|
|
381
375
|
|
|
382
|
-
class
|
|
376
|
+
class AxiosHttpRequest extends BaseHttpRequest {
|
|
383
377
|
constructor(config) {
|
|
384
378
|
super(config);
|
|
385
379
|
}
|
|
@@ -476,7 +470,7 @@ class OrdersService {
|
|
|
476
470
|
class OrderBookClient {
|
|
477
471
|
orders;
|
|
478
472
|
request;
|
|
479
|
-
constructor(config, HttpRequest =
|
|
473
|
+
constructor(config, HttpRequest = AxiosHttpRequest) {
|
|
480
474
|
this.request = new HttpRequest({
|
|
481
475
|
BASE: config?.BASE ?? 'https://order-book-mr.dev.imtbl.com',
|
|
482
476
|
VERSION: config?.VERSION ?? '1.0.0',
|
package/dist/passport.js
CHANGED
|
@@ -21,7 +21,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
21
21
|
chainID,
|
|
22
22
|
coreContractAddress,
|
|
23
23
|
registrationContractAddress,
|
|
24
|
-
sdkVersion: 'ts-immutable-sdk-0.1.
|
|
24
|
+
sdkVersion: 'ts-immutable-sdk-0.1.8-alpha',
|
|
25
25
|
});
|
|
26
26
|
/**
|
|
27
27
|
* Sets `sdkVersion` at the time of build
|