opensea-js 6.0.2 → 6.0.4

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/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  <p align="center">
2
- <img src="https://storage.googleapis.com/opensea-static/opensea-js-logo-updated.png" />
2
+ <img src="./img/banner.png" />
3
3
  </p>
4
4
 
5
- # OpenSea.js <!-- omit in toc -->
6
-
7
5
  [![Version][version-badge]][version-link]
8
6
  [![npm][npm-badge]][npm-link]
9
7
  [![Test CI][ci-badge]][ci-link]
@@ -12,6 +10,8 @@
12
10
  [![Docs][docs-badge]][docs-link]
13
11
  [![Discussions][discussions-badge]][discussions-link]
14
12
 
13
+ # OpenSea.js <!-- omit in toc -->
14
+
15
15
  A JavaScript library for crypto-native e-commerce: buying, selling, and bidding on NFTs (non-fungible tokens). With OpenSea.js, you can easily build your own native marketplace. These can be ERC-721 or ERC-1155 (semi-fungible) items. You don't have to deploy your own smart contracts or manage backend orderbooks.
16
16
 
17
17
  - [Synopsis](#synopsis)
package/lib/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "isomorphic-unfetch";
1
+ import { ethers } from "ethers";
2
2
  import { BuildOfferResponse, FulfillmentDataResponse, OrderAPIOptions, OrderSide, OrdersQueryOptions, OrderV2, PostOfferResponse, ProtocolData, QueryCursors } from "./orders/types";
3
3
  import { OpenSeaAPIConfig, OpenSeaAsset, OpenSeaAssetBundle, OpenSeaAssetBundleQuery, OpenSeaAssetQuery, OpenSeaCollection, OpenSeaFungibleToken, OpenSeaFungibleTokenQuery } from "./types";
4
4
  export declare class OpenSeaAPI {
@@ -113,16 +113,14 @@ export declare class OpenSeaAPI {
113
113
  * POST JSON data to API, sending auth token in headers
114
114
  * @param apiPath Path to URL endpoint under API
115
115
  * @param body Data to send. Will be JSON.stringified
116
- * @param opts RequestInit opts, similar to Fetch API. If it contains
117
- * a body, it won't be stringified.
116
+ * @param opts ethers ConnectionInfo, similar to Fetch API.
118
117
  */
119
- post<T>(apiPath: string, body?: object, opts?: RequestInit): Promise<T>;
118
+ post<T>(apiPath: string, body?: object, opts?: ethers.utils.ConnectionInfo): Promise<T>;
120
119
  private objectToSearchParams;
121
120
  /**
122
121
  * Get from an API Endpoint, sending auth token in headers
123
- * @param apiPath Path to URL endpoint under API
124
- * @param opts RequestInit opts, similar to Fetch API
122
+ * @param opts ethers ConnectionInfo, similar to Fetch API
123
+ * @param body Optional body to send. If set, will POST, otherwise GET
125
124
  */
126
125
  private _fetch;
127
- private _handleApiResponse;
128
126
  }
package/lib/api.js CHANGED
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.OpenSeaAPI = void 0;
24
- require("isomorphic-unfetch");
24
+ const ethers_1 = require("ethers");
25
25
  const constants_1 = require("./constants");
26
26
  const utils_1 = require("./orders/utils");
27
27
  const types_1 = require("./types");
@@ -241,26 +241,20 @@ class OpenSeaAPI {
241
241
  get(apiPath, query = {}) {
242
242
  return __awaiter(this, void 0, void 0, function* () {
243
243
  const qs = this.objectToSearchParams(query);
244
- const url = `${apiPath}?${qs}`;
245
- const response = yield this._fetch(url);
246
- return response.json();
244
+ const url = `${this.apiBaseUrl}${apiPath}?${qs}`;
245
+ return yield this._fetch({ url });
247
246
  });
248
247
  }
249
248
  /**
250
249
  * POST JSON data to API, sending auth token in headers
251
250
  * @param apiPath Path to URL endpoint under API
252
251
  * @param body Data to send. Will be JSON.stringified
253
- * @param opts RequestInit opts, similar to Fetch API. If it contains
254
- * a body, it won't be stringified.
252
+ * @param opts ethers ConnectionInfo, similar to Fetch API.
255
253
  */
256
- post(apiPath, body, opts = {}) {
254
+ post(apiPath, body, opts) {
257
255
  return __awaiter(this, void 0, void 0, function* () {
258
- const fetchOpts = Object.assign({ method: "POST", body: body ? JSON.stringify(body) : undefined, headers: {
259
- Accept: "application/json",
260
- "Content-Type": "application/json",
261
- } }, opts);
262
- const response = yield this._fetch(apiPath, fetchOpts);
263
- return response.json();
256
+ const options = Object.assign({ url: `${this.apiBaseUrl}${apiPath}` }, opts);
257
+ return yield this._fetch(options, body);
264
258
  });
265
259
  }
266
260
  objectToSearchParams(params = {}) {
@@ -277,61 +271,15 @@ class OpenSeaAPI {
277
271
  }
278
272
  /**
279
273
  * Get from an API Endpoint, sending auth token in headers
280
- * @param apiPath Path to URL endpoint under API
281
- * @param opts RequestInit opts, similar to Fetch API
274
+ * @param opts ethers ConnectionInfo, similar to Fetch API
275
+ * @param body Optional body to send. If set, will POST, otherwise GET
282
276
  */
283
- _fetch(apiPath, opts = {}) {
284
- var _a;
277
+ _fetch(opts, body) {
285
278
  return __awaiter(this, void 0, void 0, function* () {
286
- const apiBase = this.apiBaseUrl;
287
- const apiKey = this.apiKey;
288
- const finalUrl = apiBase + apiPath;
289
- const finalOpts = Object.assign(Object.assign({}, opts), { headers: Object.assign(Object.assign(Object.assign({}, (apiKey ? { "X-API-KEY": apiKey } : {})), { "x-app-id": "opensea-js" }), ((_a = opts.headers) !== null && _a !== void 0 ? _a : {})) });
290
- this.logger(`Sending request: ${finalUrl} ${JSON.stringify(finalOpts).substr(0, 100)}...`);
291
- return fetch(finalUrl, finalOpts).then((res) => __awaiter(this, void 0, void 0, function* () { return this._handleApiResponse(res); }));
292
- });
293
- }
294
- _handleApiResponse(response) {
295
- return __awaiter(this, void 0, void 0, function* () {
296
- if (response.ok) {
297
- this.logger(`Got success: ${response.status}`);
298
- return response;
299
- }
300
- let result;
301
- let errorMessage;
302
- try {
303
- result = yield response.text();
304
- result = JSON.parse(result);
305
- }
306
- catch (_a) {
307
- // Result will be undefined or text
308
- }
309
- this.logger(`Got error ${response.status}: ${JSON.stringify(result)}`);
310
- switch (response.status) {
311
- case 400:
312
- errorMessage =
313
- result && result.errors
314
- ? result.errors.join(", ")
315
- : `Invalid request: ${JSON.stringify(result)}`;
316
- break;
317
- case 401:
318
- case 403:
319
- errorMessage = `Unauthorized. Full message was '${JSON.stringify(result)}'`;
320
- break;
321
- case 404:
322
- errorMessage = `Not found. Full message was '${JSON.stringify(result)}'`;
323
- break;
324
- case 500:
325
- errorMessage = `Internal server error. OpenSea has been alerted, but if the problem persists please contact us via Discord: https://discord.gg/opensea - full message was ${JSON.stringify(result)}`;
326
- break;
327
- case 503:
328
- errorMessage = `Service unavailable. Please try again in a few minutes. If the problem persists please contact us via Discord: https://discord.gg/opensea - full message was ${JSON.stringify(result)}`;
329
- break;
330
- default:
331
- errorMessage = `Message: ${JSON.stringify(result)}`;
332
- break;
333
- }
334
- throw new Error(`API Error ${response.status}: ${errorMessage}`);
279
+ const headers = Object.assign(Object.assign({ "x-app-id": "opensea-js" }, (this.apiKey ? { "X-API-KEY": this.apiKey } : {})), opts.headers);
280
+ const req = Object.assign(Object.assign({}, opts), { headers });
281
+ this.logger(`Sending request: ${opts.url} ${JSON.stringify(req).slice(0, 200)}...`);
282
+ return yield ethers_1.ethers.utils.fetchJson(req, body ? JSON.stringify(body) : undefined);
335
283
  });
336
284
  }
337
285
  }
package/lib/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA4B;AAC5B,2CAA2E;AAe3E,0CAYwB;AACxB,mCAUiB;AACjB,yCAMuB;AAEvB,MAAa,UAAU;IAkBrB;;;;OAIG;IACH,YAAY,MAAwB,EAAE,MAA8B;;QAlBpE;;WAEG;QACI,aAAQ,GAAG,EAAE,CAAC;QAQb,eAAU,GAAG,IAAI,CAAC;QAQxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,MAAA,MAAM,CAAC,KAAK,mCAAI,aAAK,CAAC,OAAO,CAAC;QAE3C,QAAQ,MAAM,CAAC,KAAK,EAAE;YACpB,KAAK,aAAK,CAAC,MAAM;gBACf,IAAI,CAAC,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AC,CAAC,EAAE,GAAG,CAAC,KAAK,CACvE,CAAC;YAEF,OAAO,MAAM,eAAM,CAAC,KAAK,CAAC,SAAS,CACjC,GAAG,EACH,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CACxC,CAAC;QACJ,CAAC;KAAA;CACF;AA9YD,gCA8YC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,OAAe;IACvD,MAAM,aAAa,GACjB,KAAK,YAAY,KAAK;QACtB,CAAC,CAAC,KAAK,CAAC,OAAO;QACf,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnE,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;QAClC,MAAM,KAAK,CAAC;KACb;AACH,CAAC"}
package/lib/bundle.js CHANGED
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.OpenSeaAPI = void 0;
25
- require("isomorphic-unfetch");
25
+ const ethers_1 = require("ethers");
26
26
  const constants_1 = require("./constants");
27
27
  const utils_1 = require("./orders/utils");
28
28
  const types_1 = require("./types");
@@ -242,26 +242,20 @@ class OpenSeaAPI {
242
242
  get(apiPath, query = {}) {
243
243
  return __awaiter(this, void 0, void 0, function* () {
244
244
  const qs = this.objectToSearchParams(query);
245
- const url = `${apiPath}?${qs}`;
246
- const response = yield this._fetch(url);
247
- return response.json();
245
+ const url = `${this.apiBaseUrl}${apiPath}?${qs}`;
246
+ return yield this._fetch({ url });
248
247
  });
249
248
  }
250
249
  /**
251
250
  * POST JSON data to API, sending auth token in headers
252
251
  * @param apiPath Path to URL endpoint under API
253
252
  * @param body Data to send. Will be JSON.stringified
254
- * @param opts RequestInit opts, similar to Fetch API. If it contains
255
- * a body, it won't be stringified.
253
+ * @param opts ethers ConnectionInfo, similar to Fetch API.
256
254
  */
257
- post(apiPath, body, opts = {}) {
255
+ post(apiPath, body, opts) {
258
256
  return __awaiter(this, void 0, void 0, function* () {
259
- const fetchOpts = Object.assign({ method: "POST", body: body ? JSON.stringify(body) : undefined, headers: {
260
- Accept: "application/json",
261
- "Content-Type": "application/json",
262
- } }, opts);
263
- const response = yield this._fetch(apiPath, fetchOpts);
264
- return response.json();
257
+ const options = Object.assign({ url: `${this.apiBaseUrl}${apiPath}` }, opts);
258
+ return yield this._fetch(options, body);
265
259
  });
266
260
  }
267
261
  objectToSearchParams(params = {}) {
@@ -278,61 +272,15 @@ class OpenSeaAPI {
278
272
  }
279
273
  /**
280
274
  * Get from an API Endpoint, sending auth token in headers
281
- * @param apiPath Path to URL endpoint under API
282
- * @param opts RequestInit opts, similar to Fetch API
275
+ * @param opts ethers ConnectionInfo, similar to Fetch API
276
+ * @param body Optional body to send. If set, will POST, otherwise GET
283
277
  */
284
- _fetch(apiPath, opts = {}) {
285
- var _a;
278
+ _fetch(opts, body) {
286
279
  return __awaiter(this, void 0, void 0, function* () {
287
- const apiBase = this.apiBaseUrl;
288
- const apiKey = this.apiKey;
289
- const finalUrl = apiBase + apiPath;
290
- const finalOpts = Object.assign(Object.assign({}, opts), { headers: Object.assign(Object.assign(Object.assign({}, (apiKey ? { "X-API-KEY": apiKey } : {})), { "x-app-id": "opensea-js" }), ((_a = opts.headers) !== null && _a !== void 0 ? _a : {})) });
291
- this.logger(`Sending request: ${finalUrl} ${JSON.stringify(finalOpts).substr(0, 100)}...`);
292
- return fetch(finalUrl, finalOpts).then((res) => __awaiter(this, void 0, void 0, function* () { return this._handleApiResponse(res); }));
293
- });
294
- }
295
- _handleApiResponse(response) {
296
- return __awaiter(this, void 0, void 0, function* () {
297
- if (response.ok) {
298
- this.logger(`Got success: ${response.status}`);
299
- return response;
300
- }
301
- let result;
302
- let errorMessage;
303
- try {
304
- result = yield response.text();
305
- result = JSON.parse(result);
306
- }
307
- catch (_a) {
308
- // Result will be undefined or text
309
- }
310
- this.logger(`Got error ${response.status}: ${JSON.stringify(result)}`);
311
- switch (response.status) {
312
- case 400:
313
- errorMessage =
314
- result && result.errors
315
- ? result.errors.join(", ")
316
- : `Invalid request: ${JSON.stringify(result)}`;
317
- break;
318
- case 401:
319
- case 403:
320
- errorMessage = `Unauthorized. Full message was '${JSON.stringify(result)}'`;
321
- break;
322
- case 404:
323
- errorMessage = `Not found. Full message was '${JSON.stringify(result)}'`;
324
- break;
325
- case 500:
326
- errorMessage = `Internal server error. OpenSea has been alerted, but if the problem persists please contact us via Discord: https://discord.gg/opensea - full message was ${JSON.stringify(result)}`;
327
- break;
328
- case 503:
329
- errorMessage = `Service unavailable. Please try again in a few minutes. If the problem persists please contact us via Discord: https://discord.gg/opensea - full message was ${JSON.stringify(result)}`;
330
- break;
331
- default:
332
- errorMessage = `Message: ${JSON.stringify(result)}`;
333
- break;
334
- }
335
- throw new Error(`API Error ${response.status}: ${errorMessage}`);
280
+ const headers = Object.assign(Object.assign({ "x-app-id": "opensea-js" }, (this.apiKey ? { "X-API-KEY": this.apiKey } : {})), opts.headers);
281
+ const req = Object.assign(Object.assign({}, opts), { headers });
282
+ this.logger(`Sending request: ${opts.url} ${JSON.stringify(req).slice(0, 200)}...`);
283
+ return yield ethers_1.ethers.utils.fetchJson(req, body ? JSON.stringify(body) : undefined);
336
284
  });
337
285
  }
338
286
  }
@@ -346,7 +294,7 @@ function _throwOrContinue(error, retries) {
346
294
  }
347
295
  }
348
296
 
349
- },{"./constants":2,"./orders/utils":5,"./types":12,"./utils/utils":17,"isomorphic-unfetch":255}],2:[function(require,module,exports){
297
+ },{"./constants":2,"./orders/utils":5,"./types":12,"./utils/utils":17,"ethers":237}],2:[function(require,module,exports){
350
298
  "use strict";
351
299
  Object.defineProperty(exports, "__esModule", { value: true });
352
300
  exports.SHARED_STOREFRONT_LAZY_MINT_ADAPTER_CROSS_CHAIN_ADDRESS = exports.SHARED_STOREFRONT_ADDRESS_GOERLI = exports.SHARED_STOREFRONT_ADDRESS_MAINNET = exports.DEFAULT_ZONE_BY_NETWORK = exports.WETH_ADDRESS_BY_NETWORK = exports.MERKLE_VALIDATOR_MAINNET = exports.API_PATH = exports.API_BASE_TESTNET = exports.API_BASE_MAINNET = exports.MAX_EXPIRATION_MONTHS = exports.INVERSE_BASIS_POINT = void 0;
@@ -5573,7 +5521,7 @@ if (process.env.NODE_ENV === "production") {
5573
5521
  }
5574
5522
 
5575
5523
  }).call(this)}).call(this,require('_process'))
5576
- },{"./0xsequence-abi.cjs.dev.js":18,"./0xsequence-abi.cjs.prod.js":20,"_process":266}],20:[function(require,module,exports){
5524
+ },{"./0xsequence-abi.cjs.dev.js":18,"./0xsequence-abi.cjs.prod.js":20,"_process":265}],20:[function(require,module,exports){
5577
5525
  arguments[4][18][0].apply(exports,arguments)
5578
5526
  },{"dup":18}],21:[function(require,module,exports){
5579
5527
  'use strict';
@@ -6021,7 +5969,7 @@ if (process.env.NODE_ENV === "production") {
6021
5969
  }
6022
5970
 
6023
5971
  }).call(this)}).call(this,require('_process'))
6024
- },{"./0xsequence-multicall.cjs.dev.js":21,"./0xsequence-multicall.cjs.prod.js":23,"_process":266}],23:[function(require,module,exports){
5972
+ },{"./0xsequence-multicall.cjs.dev.js":21,"./0xsequence-multicall.cjs.prod.js":23,"_process":265}],23:[function(require,module,exports){
6025
5973
  arguments[4][21][0].apply(exports,arguments)
6026
5974
  },{"@0xsequence/abi":19,"@0xsequence/network":25,"@0xsequence/utils":28,"dup":21,"ethers":237}],24:[function(require,module,exports){
6027
5975
  'use strict';
@@ -7256,7 +7204,7 @@ if (process.env.NODE_ENV === "production") {
7256
7204
  }
7257
7205
 
7258
7206
  }).call(this)}).call(this,require('_process'))
7259
- },{"./0xsequence-network.cjs.dev.js":24,"./0xsequence-network.cjs.prod.js":26,"_process":266}],26:[function(require,module,exports){
7207
+ },{"./0xsequence-network.cjs.dev.js":24,"./0xsequence-network.cjs.prod.js":26,"_process":265}],26:[function(require,module,exports){
7260
7208
  arguments[4][24][0].apply(exports,arguments)
7261
7209
  },{"@0xsequence/utils":28,"dup":24,"ethers":237}],27:[function(require,module,exports){
7262
7210
  (function (process){(function (){
@@ -7550,7 +7498,7 @@ exports.subDigestOf = subDigestOf;
7550
7498
  exports.urlClean = urlClean;
7551
7499
 
7552
7500
  }).call(this)}).call(this,require('_process'))
7553
- },{"_process":266,"ethers":237,"js-base64":256}],28:[function(require,module,exports){
7501
+ },{"_process":265,"ethers":237,"js-base64":255}],28:[function(require,module,exports){
7554
7502
  (function (process){(function (){
7555
7503
  'use strict';
7556
7504
 
@@ -7561,9 +7509,9 @@ if (process.env.NODE_ENV === "production") {
7561
7509
  }
7562
7510
 
7563
7511
  }).call(this)}).call(this,require('_process'))
7564
- },{"./0xsequence-utils.cjs.dev.js":27,"./0xsequence-utils.cjs.prod.js":29,"_process":266}],29:[function(require,module,exports){
7512
+ },{"./0xsequence-utils.cjs.dev.js":27,"./0xsequence-utils.cjs.prod.js":29,"_process":265}],29:[function(require,module,exports){
7565
7513
  arguments[4][27][0].apply(exports,arguments)
7566
- },{"_process":266,"dup":27,"ethers":237,"js-base64":256}],30:[function(require,module,exports){
7514
+ },{"_process":265,"dup":27,"ethers":237,"js-base64":255}],30:[function(require,module,exports){
7567
7515
  "use strict";
7568
7516
  Object.defineProperty(exports, "__esModule", { value: true });
7569
7517
  exports.version = void 0;
@@ -15483,7 +15431,7 @@ function encrypt(account, password, options, progressCallback) {
15483
15431
  }
15484
15432
  exports.encrypt = encrypt;
15485
15433
 
15486
- },{"./_version":79,"./utils":84,"@ethersproject/address":51,"@ethersproject/bytes":60,"@ethersproject/hdnode":78,"@ethersproject/keccak256":85,"@ethersproject/logger":87,"@ethersproject/pbkdf2":91,"@ethersproject/properties":93,"@ethersproject/random":115,"@ethersproject/transactions":134,"aes-js":176,"scrypt-js":267}],84:[function(require,module,exports){
15434
+ },{"./_version":79,"./utils":84,"@ethersproject/address":51,"@ethersproject/bytes":60,"@ethersproject/hdnode":78,"@ethersproject/keccak256":85,"@ethersproject/logger":87,"@ethersproject/pbkdf2":91,"@ethersproject/properties":93,"@ethersproject/random":115,"@ethersproject/transactions":134,"aes-js":176,"scrypt-js":266}],84:[function(require,module,exports){
15487
15435
  "use strict";
15488
15436
  Object.defineProperty(exports, "__esModule", { value: true });
15489
15437
  exports.uuidV4 = exports.searchPath = exports.getPassword = exports.zpad = exports.looseArrayify = void 0;
@@ -15568,7 +15516,7 @@ function keccak256(data) {
15568
15516
  }
15569
15517
  exports.keccak256 = keccak256;
15570
15518
 
15571
- },{"@ethersproject/bytes":60,"js-sha3":257}],86:[function(require,module,exports){
15519
+ },{"@ethersproject/bytes":60,"js-sha3":256}],86:[function(require,module,exports){
15572
15520
  "use strict";
15573
15521
  Object.defineProperty(exports, "__esModule", { value: true });
15574
15522
  exports.version = void 0;
@@ -31446,7 +31394,7 @@ class Eip712MerkleTree {
31446
31394
  }
31447
31395
  exports.Eip712MerkleTree = Eip712MerkleTree;
31448
31396
 
31449
- },{"./defaults":168,"./utils":169,"@ethersproject/hash":73,"ethers/lib/utils":238,"merkletreejs":263}],167:[function(require,module,exports){
31397
+ },{"./defaults":168,"./utils":169,"@ethersproject/hash":73,"ethers/lib/utils":238,"merkletreejs":262}],167:[function(require,module,exports){
31450
31398
  "use strict";
31451
31399
  Object.defineProperty(exports, "__esModule", { value: true });
31452
31400
  exports.getBulkOrderTypeHashes = exports.getBulkOrderTypeHash = exports.getBulkOrderTree = exports.getBulkOrderTreeHeight = void 0;
@@ -32184,7 +32132,7 @@ class MerkleTree {
32184
32132
  exports.MerkleTree = MerkleTree;
32185
32133
 
32186
32134
  }).call(this)}).call(this,require("buffer").Buffer)
32187
- },{"buffer":182,"ethers":237,"ethers/lib/utils":238,"merkletreejs":263}],174:[function(require,module,exports){
32135
+ },{"buffer":182,"ethers":237,"ethers/lib/utils":238,"merkletreejs":262}],174:[function(require,module,exports){
32188
32136
  (function (Buffer){(function (){
32189
32137
  "use strict";
32190
32138
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -49504,7 +49452,7 @@ function intFromLE(bytes) {
49504
49452
  utils.intFromLE = intFromLE;
49505
49453
 
49506
49454
 
49507
- },{"bn.js":233,"minimalistic-assert":264,"minimalistic-crypto-utils":265}],233:[function(require,module,exports){
49455
+ },{"bn.js":233,"minimalistic-assert":263,"minimalistic-crypto-utils":264}],233:[function(require,module,exports){
49508
49456
  (function (module, exports) {
49509
49457
  'use strict';
49510
49458
 
@@ -53885,7 +53833,7 @@ BlockHash.prototype._pad = function pad() {
53885
53833
  return res;
53886
53834
  };
53887
53835
 
53888
- },{"./utils":251,"minimalistic-assert":264}],242:[function(require,module,exports){
53836
+ },{"./utils":251,"minimalistic-assert":263}],242:[function(require,module,exports){
53889
53837
  'use strict';
53890
53838
 
53891
53839
  var utils = require('./utils');
@@ -53934,7 +53882,7 @@ Hmac.prototype.digest = function digest(enc) {
53934
53882
  return this.outer.digest(enc);
53935
53883
  };
53936
53884
 
53937
- },{"./utils":251,"minimalistic-assert":264}],243:[function(require,module,exports){
53885
+ },{"./utils":251,"minimalistic-assert":263}],243:[function(require,module,exports){
53938
53886
  'use strict';
53939
53887
 
53940
53888
  var utils = require('./utils');
@@ -54306,7 +54254,7 @@ SHA256.prototype._digest = function digest(enc) {
54306
54254
  return utils.split32(this.h, 'big');
54307
54255
  };
54308
54256
 
54309
- },{"../common":241,"../utils":251,"./common":250,"minimalistic-assert":264}],248:[function(require,module,exports){
54257
+ },{"../common":241,"../utils":251,"./common":250,"minimalistic-assert":263}],248:[function(require,module,exports){
54310
54258
  'use strict';
54311
54259
 
54312
54260
  var utils = require('../utils');
@@ -54675,7 +54623,7 @@ function g1_512_lo(xh, xl) {
54675
54623
  return r;
54676
54624
  }
54677
54625
 
54678
- },{"../common":241,"../utils":251,"minimalistic-assert":264}],250:[function(require,module,exports){
54626
+ },{"../common":241,"../utils":251,"minimalistic-assert":263}],250:[function(require,module,exports){
54679
54627
  'use strict';
54680
54628
 
54681
54629
  var utils = require('../utils');
@@ -55006,7 +54954,7 @@ function shr64_lo(ah, al, num) {
55006
54954
  }
55007
54955
  exports.shr64_lo = shr64_lo;
55008
54956
 
55009
- },{"inherits":254,"minimalistic-assert":264}],252:[function(require,module,exports){
54957
+ },{"inherits":254,"minimalistic-assert":263}],252:[function(require,module,exports){
55010
54958
  'use strict';
55011
54959
 
55012
54960
  var hash = require('hash.js');
@@ -55121,7 +55069,7 @@ HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
55121
55069
  return utils.encode(res, enc);
55122
55070
  };
55123
55071
 
55124
- },{"hash.js":240,"minimalistic-assert":264,"minimalistic-crypto-utils":265}],253:[function(require,module,exports){
55072
+ },{"hash.js":240,"minimalistic-assert":263,"minimalistic-crypto-utils":264}],253:[function(require,module,exports){
55125
55073
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
55126
55074
  exports.read = function (buffer, offset, isLE, mLen, nBytes) {
55127
55075
  var e, m
@@ -55238,9 +55186,6 @@ if (typeof Object.create === 'function') {
55238
55186
  }
55239
55187
 
55240
55188
  },{}],255:[function(require,module,exports){
55241
- module.exports = self.fetch || (self.fetch = require('unfetch').default || require('unfetch'));
55242
-
55243
- },{"unfetch":270}],256:[function(require,module,exports){
55244
55189
  (function (global,Buffer){(function (){
55245
55190
  //
55246
55191
  // THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND!
@@ -55560,7 +55505,7 @@ module.exports = self.fetch || (self.fetch = require('unfetch').default || requi
55560
55505
  }));
55561
55506
 
55562
55507
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
55563
- },{"buffer":182}],257:[function(require,module,exports){
55508
+ },{"buffer":182}],256:[function(require,module,exports){
55564
55509
  (function (process,global){(function (){
55565
55510
  /**
55566
55511
  * [js-sha3]{@link https://github.com/emn178/js-sha3}
@@ -56220,7 +56165,7 @@ module.exports = self.fetch || (self.fetch = require('unfetch').default || requi
56220
56165
  })();
56221
56166
 
56222
56167
  }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
56223
- },{"_process":266}],258:[function(require,module,exports){
56168
+ },{"_process":265}],257:[function(require,module,exports){
56224
56169
  "use strict";
56225
56170
  var __importDefault = (this && this.__importDefault) || function (mod) {
56226
56171
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -56566,7 +56511,7 @@ class Base {
56566
56511
  exports.Base = Base;
56567
56512
  exports.default = Base;
56568
56513
 
56569
- },{"buffer":182,"crypto-js":192}],259:[function(require,module,exports){
56514
+ },{"buffer":182,"crypto-js":192}],258:[function(require,module,exports){
56570
56515
  "use strict";
56571
56516
  var __importDefault = (this && this.__importDefault) || function (mod) {
56572
56517
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -56820,7 +56765,7 @@ if (typeof window !== 'undefined') {
56820
56765
  }
56821
56766
  exports.default = IncrementalMerkleTree;
56822
56767
 
56823
- },{"./Base":258,"treeify":269}],260:[function(require,module,exports){
56768
+ },{"./Base":257,"treeify":268}],259:[function(require,module,exports){
56824
56769
  "use strict";
56825
56770
  var __importDefault = (this && this.__importDefault) || function (mod) {
56826
56771
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -57258,7 +57203,7 @@ if (typeof window !== 'undefined') {
57258
57203
  }
57259
57204
  exports.default = MerkleMountainRange;
57260
57205
 
57261
- },{"./Base":258,"buffer":182,"crypto-js/sha256":212}],261:[function(require,module,exports){
57206
+ },{"./Base":257,"buffer":182,"crypto-js/sha256":212}],260:[function(require,module,exports){
57262
57207
  (function (Buffer){(function (){
57263
57208
  "use strict";
57264
57209
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -57400,7 +57345,7 @@ if (typeof window !== 'undefined') {
57400
57345
  exports.default = MerkleSumTree;
57401
57346
 
57402
57347
  }).call(this)}).call(this,require("buffer").Buffer)
57403
- },{"./Base":258,"buffer":182}],262:[function(require,module,exports){
57348
+ },{"./Base":257,"buffer":182}],261:[function(require,module,exports){
57404
57349
  "use strict";
57405
57350
  var __importDefault = (this && this.__importDefault) || function (mod) {
57406
57351
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -58690,7 +58635,7 @@ if (typeof window !== 'undefined') {
58690
58635
  }
58691
58636
  exports.default = MerkleTree;
58692
58637
 
58693
- },{"./Base":258,"buffer":182,"buffer-reverse":183,"crypto-js/sha256":212,"treeify":269}],263:[function(require,module,exports){
58638
+ },{"./Base":257,"buffer":182,"buffer-reverse":183,"crypto-js/sha256":212,"treeify":268}],262:[function(require,module,exports){
58694
58639
  "use strict";
58695
58640
  var __importDefault = (this && this.__importDefault) || function (mod) {
58696
58641
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -58707,7 +58652,7 @@ var MerkleSumTree_1 = require("./MerkleSumTree");
58707
58652
  Object.defineProperty(exports, "MerkleSumTree", { enumerable: true, get: function () { return MerkleSumTree_1.MerkleSumTree; } });
58708
58653
  exports.default = MerkleTree_1.default;
58709
58654
 
58710
- },{"./IncrementalMerkleTree":259,"./MerkleMountainRange":260,"./MerkleSumTree":261,"./MerkleTree":262}],264:[function(require,module,exports){
58655
+ },{"./IncrementalMerkleTree":258,"./MerkleMountainRange":259,"./MerkleSumTree":260,"./MerkleTree":261}],263:[function(require,module,exports){
58711
58656
  module.exports = assert;
58712
58657
 
58713
58658
  function assert(val, msg) {
@@ -58720,7 +58665,7 @@ assert.equal = function assertEqual(l, r, msg) {
58720
58665
  throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
58721
58666
  };
58722
58667
 
58723
- },{}],265:[function(require,module,exports){
58668
+ },{}],264:[function(require,module,exports){
58724
58669
  'use strict';
58725
58670
 
58726
58671
  var utils = exports;
@@ -58780,7 +58725,7 @@ utils.encode = function encode(arr, enc) {
58780
58725
  return arr;
58781
58726
  };
58782
58727
 
58783
- },{}],266:[function(require,module,exports){
58728
+ },{}],265:[function(require,module,exports){
58784
58729
  // shim for using process in browser
58785
58730
  var process = module.exports = {};
58786
58731
 
@@ -58966,7 +58911,7 @@ process.chdir = function (dir) {
58966
58911
  };
58967
58912
  process.umask = function() { return 0; };
58968
58913
 
58969
- },{}],267:[function(require,module,exports){
58914
+ },{}],266:[function(require,module,exports){
58970
58915
  (function (setImmediate){(function (){
58971
58916
  "use strict";
58972
58917
 
@@ -59458,7 +59403,7 @@ process.umask = function() { return 0; };
59458
59403
  })(this);
59459
59404
 
59460
59405
  }).call(this)}).call(this,require("timers").setImmediate)
59461
- },{"timers":268}],268:[function(require,module,exports){
59406
+ },{"timers":267}],267:[function(require,module,exports){
59462
59407
  (function (setImmediate,clearImmediate){(function (){
59463
59408
  var nextTick = require('process/browser.js').nextTick;
59464
59409
  var apply = Function.prototype.apply;
@@ -59537,7 +59482,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
59537
59482
  delete immediateIds[id];
59538
59483
  };
59539
59484
  }).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
59540
- },{"process/browser.js":266,"timers":268}],269:[function(require,module,exports){
59485
+ },{"process/browser.js":265,"timers":267}],268:[function(require,module,exports){
59541
59486
  // treeify.js
59542
59487
  // Luke Plaster <notatestuser@gmail.com>
59543
59488
  // https://github.com/notatestuser/treeify.js
@@ -59652,8 +59597,4 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
59652
59597
 
59653
59598
  }));
59654
59599
 
59655
- },{}],270:[function(require,module,exports){
59656
- module.exports=function(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u={},a=function e(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:e,headers:{keys:function(){return o},entries:function(){return o.map(function(e){return[e,s.getResponseHeader(e)]})},get:function(e){return s.getResponseHeader(e)},has:function(e){return null!=s.getResponseHeader(e)}}}};for(var i in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm,function(e,n){u[n]||o.push(u[n]=n)}),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(i,n.headers[i]);s.send(n.body||null)})};
59657
-
59658
-
59659
59600
  },{}]},{},[3]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opensea-js",
3
- "version": "6.0.2",
3
+ "version": "6.0.4",
4
4
  "description": "JavaScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data!",
5
5
  "license": "MIT",
6
6
  "author": "OpenSea Developers",
@@ -18,13 +18,13 @@
18
18
  "src"
19
19
  ],
20
20
  "scripts": {
21
- "postinstall": "husky install || true",
21
+ "postinstall": "husky install || exit 0",
22
22
  "prepare": "npm run build",
23
23
  "build": "npm run abi-type-gen && tsc -p tsconfig.build.json && npm run bundle",
24
24
  "bundle": "browserify lib/index.js -o lib/bundle.js",
25
25
  "abi-type-gen": "typechain --target=ethers-v5 src/abi/*.json --out-dir=src/typechain/contracts",
26
26
  "check-types": "tsc --noEmit --project tsconfig.json",
27
- "coverage-report": "nyc report --reporter=text-lcov | coveralls",
27
+ "coverage-report": "nyc report --reporter=lcov",
28
28
  "docs-build": "typedoc --out docs src/index.ts",
29
29
  "lint": "concurrently \"npm run check-types\" \"npm run prettier:check\" \"npm run eslint:check\"",
30
30
  "eslint:check": "eslint . --max-warnings 0 --ext .js,.ts",
@@ -38,8 +38,7 @@
38
38
  "types": "lib/index.d.ts",
39
39
  "dependencies": {
40
40
  "@opensea/seaport-js": "^2.0.0",
41
- "ethers": "^5.7.2",
42
- "isomorphic-unfetch": "^4.0.2"
41
+ "ethers": "^5.7.2"
43
42
  },
44
43
  "devDependencies": {
45
44
  "@typechain/ethers-v5": "^11.0.0",
@@ -52,9 +51,8 @@
52
51
  "browserify": "^17.0.0",
53
52
  "chai": "4.3.7",
54
53
  "chai-as-promised": "^7.1.1",
55
- "concurrently": "8.0.1",
54
+ "concurrently": "8.1.0",
56
55
  "confusing-browser-globals": "^1.0.11",
57
- "coveralls": "^3.1.1",
58
56
  "dotenv": "^16.0.3",
59
57
  "eslint": "^8.4.1",
60
58
  "eslint-config-prettier": "^8.3.0",
package/src/api.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "isomorphic-unfetch";
1
+ import { ethers } from "ethers";
2
2
  import { API_BASE_MAINNET, API_BASE_TESTNET, API_PATH } from "./constants";
3
3
  import {
4
4
  BuildOfferResponse,
@@ -382,36 +382,27 @@ export class OpenSeaAPI {
382
382
  */
383
383
  public async get<T>(apiPath: string, query: object = {}): Promise<T> {
384
384
  const qs = this.objectToSearchParams(query);
385
- const url = `${apiPath}?${qs}`;
386
-
387
- const response = await this._fetch(url);
388
- return response.json();
385
+ const url = `${this.apiBaseUrl}${apiPath}?${qs}`;
386
+ return await this._fetch({ url });
389
387
  }
390
388
 
391
389
  /**
392
390
  * POST JSON data to API, sending auth token in headers
393
391
  * @param apiPath Path to URL endpoint under API
394
392
  * @param body Data to send. Will be JSON.stringified
395
- * @param opts RequestInit opts, similar to Fetch API. If it contains
396
- * a body, it won't be stringified.
393
+ * @param opts ethers ConnectionInfo, similar to Fetch API.
397
394
  */
398
395
  public async post<T>(
399
396
  apiPath: string,
400
397
  body?: object,
401
- opts: RequestInit = {}
398
+ opts?: ethers.utils.ConnectionInfo
402
399
  ): Promise<T> {
403
- const fetchOpts = {
404
- method: "POST",
405
- body: body ? JSON.stringify(body) : undefined,
406
- headers: {
407
- Accept: "application/json",
408
- "Content-Type": "application/json",
409
- },
400
+ const options = {
401
+ url: `${this.apiBaseUrl}${apiPath}`,
410
402
  ...opts,
411
403
  };
412
404
 
413
- const response = await this._fetch(apiPath, fetchOpts);
414
- return response.json();
405
+ return await this._fetch(options, body);
415
406
  }
416
407
 
417
408
  private objectToSearchParams(params: object = {}) {
@@ -430,86 +421,29 @@ export class OpenSeaAPI {
430
421
 
431
422
  /**
432
423
  * Get from an API Endpoint, sending auth token in headers
433
- * @param apiPath Path to URL endpoint under API
434
- * @param opts RequestInit opts, similar to Fetch API
424
+ * @param opts ethers ConnectionInfo, similar to Fetch API
425
+ * @param body Optional body to send. If set, will POST, otherwise GET
435
426
  */
436
- private async _fetch(apiPath: string, opts: RequestInit = {}) {
437
- const apiBase = this.apiBaseUrl;
438
- const apiKey = this.apiKey;
439
- const finalUrl = apiBase + apiPath;
440
- const finalOpts = {
427
+ private async _fetch(opts: ethers.utils.ConnectionInfo, body?: object) {
428
+ const headers = {
429
+ "x-app-id": "opensea-js",
430
+ ...(this.apiKey ? { "X-API-KEY": this.apiKey } : {}),
431
+ ...opts.headers,
432
+ };
433
+ const req = {
441
434
  ...opts,
442
- headers: {
443
- ...(apiKey ? { "X-API-KEY": apiKey } : {}),
444
- "x-app-id": "opensea-js",
445
- ...(opts.headers ?? {}),
446
- },
435
+ headers,
447
436
  };
448
437
 
449
438
  this.logger(
450
- `Sending request: ${finalUrl} ${JSON.stringify(finalOpts).substr(
451
- 0,
452
- 100
453
- )}...`
439
+ `Sending request: ${opts.url} ${JSON.stringify(req).slice(0, 200)}...`
454
440
  );
455
441
 
456
- return fetch(finalUrl, finalOpts).then(async (res) =>
457
- this._handleApiResponse(res)
442
+ return await ethers.utils.fetchJson(
443
+ req,
444
+ body ? JSON.stringify(body) : undefined
458
445
  );
459
446
  }
460
-
461
- private async _handleApiResponse(response: Response) {
462
- if (response.ok) {
463
- this.logger(`Got success: ${response.status}`);
464
- return response;
465
- }
466
-
467
- let result;
468
- let errorMessage;
469
- try {
470
- result = await response.text();
471
- result = JSON.parse(result);
472
- } catch {
473
- // Result will be undefined or text
474
- }
475
-
476
- this.logger(`Got error ${response.status}: ${JSON.stringify(result)}`);
477
-
478
- switch (response.status) {
479
- case 400:
480
- errorMessage =
481
- result && result.errors
482
- ? result.errors.join(", ")
483
- : `Invalid request: ${JSON.stringify(result)}`;
484
- break;
485
- case 401:
486
- case 403:
487
- errorMessage = `Unauthorized. Full message was '${JSON.stringify(
488
- result
489
- )}'`;
490
- break;
491
- case 404:
492
- errorMessage = `Not found. Full message was '${JSON.stringify(
493
- result
494
- )}'`;
495
- break;
496
- case 500:
497
- errorMessage = `Internal server error. OpenSea has been alerted, but if the problem persists please contact us via Discord: https://discord.gg/opensea - full message was ${JSON.stringify(
498
- result
499
- )}`;
500
- break;
501
- case 503:
502
- errorMessage = `Service unavailable. Please try again in a few minutes. If the problem persists please contact us via Discord: https://discord.gg/opensea - full message was ${JSON.stringify(
503
- result
504
- )}`;
505
- break;
506
- default:
507
- errorMessage = `Message: ${JSON.stringify(result)}`;
508
- break;
509
- }
510
-
511
- throw new Error(`API Error ${response.status}: ${errorMessage}`);
512
- }
513
447
  }
514
448
 
515
449
  function _throwOrContinue(error: unknown, retries: number) {