@audius/sdk 1.0.17 → 1.0.18

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.
@@ -514,9 +514,9 @@ if (typeof window !== 'undefined' && window && window.Web3) {
514
514
  var LibsWeb3 = Web3;
515
515
 
516
516
  var name = "@audius/sdk";
517
- var version = "1.0.17";
517
+ var version = "1.0.18";
518
518
  var audius = {
519
- releaseSHA: "9dc55f08221648a366e060d1f8ad53cd21a651a1"
519
+ releaseSHA: "cc52bcb636e5a70a3e50f6fe3b7eccc8f1f0c479"
520
520
  };
521
521
  var description = "";
522
522
  var main = "dist/index.cjs.js";
@@ -48139,17 +48139,18 @@ var File = /*#__PURE__*/function (_Base) {
48139
48139
 
48140
48140
  var _super = _createSuper(File);
48141
48141
 
48142
- function File(user) {
48142
+ function File(user, serviceProvider) {
48143
48143
  var _this;
48144
48144
 
48145
48145
  _classCallCheck(this, File);
48146
48146
 
48147
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
48148
- args[_key - 1] = arguments[_key];
48147
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
48148
+ args[_key - 2] = arguments[_key];
48149
48149
  }
48150
48150
 
48151
48151
  _this = _super.call.apply(_super, [this].concat(args));
48152
48152
  _this.User = user;
48153
+ _this.ServiceProvider = serviceProvider;
48153
48154
  return _this;
48154
48155
  }
48155
48156
  /**
@@ -48165,21 +48166,86 @@ var File = /*#__PURE__*/function (_Base) {
48165
48166
  _createClass(File, [{
48166
48167
  key: "fetchCID",
48167
48168
  value: function () {
48168
- var _fetchCID = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(cid, creatorNodeGateways) {
48169
+ var _fetchCID = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(cid, creatorNodeGateways) {
48170
+ var callback,
48171
+ responseType,
48172
+ trackId,
48173
+ premiumContentHeaders,
48174
+ replicaSetAttempt,
48175
+ allCreatorNodes,
48176
+ allCreatorNodeEndpoints,
48177
+ allNodesAttempt,
48178
+ _args = arguments;
48179
+ return regeneratorRuntime.wrap(function _callee$(_context) {
48180
+ while (1) {
48181
+ switch (_context.prev = _context.next) {
48182
+ case 0:
48183
+ callback = _args.length > 2 && _args[2] !== undefined ? _args[2] : null;
48184
+ responseType = _args.length > 3 && _args[3] !== undefined ? _args[3] : 'blob';
48185
+ trackId = _args.length > 4 && _args[4] !== undefined ? _args[4] : null;
48186
+ premiumContentHeaders = _args.length > 5 && _args[5] !== undefined ? _args[5] : {};
48187
+ _context.prev = 4;
48188
+ _context.next = 7;
48189
+ return this.fetchCIDInternal(cid, creatorNodeGateways, callback, responseType, trackId, premiumContentHeaders);
48190
+
48191
+ case 7:
48192
+ replicaSetAttempt = _context.sent;
48193
+ return _context.abrupt("return", replicaSetAttempt);
48194
+
48195
+ case 11:
48196
+ _context.prev = 11;
48197
+ _context.t0 = _context["catch"](4);
48198
+ // In the case we can't find the CID from anywhere in the user's replica set,
48199
+ // retry the whole network
48200
+ console.error(_context.t0);
48201
+ _context.next = 16;
48202
+ return this.ServiceProvider.listCreatorNodes();
48203
+
48204
+ case 16:
48205
+ allCreatorNodes = _context.sent;
48206
+ allCreatorNodeEndpoints = allCreatorNodes.map(function (node) {
48207
+ return urlJoin(node.endpoint, 'ipfs');
48208
+ }); // Re-throw whatever error might happen here
48209
+
48210
+ _context.next = 20;
48211
+ return this.fetchCIDInternal(cid, allCreatorNodeEndpoints, callback, responseType, trackId, premiumContentHeaders);
48212
+
48213
+ case 20:
48214
+ allNodesAttempt = _context.sent;
48215
+ return _context.abrupt("return", allNodesAttempt);
48216
+
48217
+ case 22:
48218
+ case "end":
48219
+ return _context.stop();
48220
+ }
48221
+ }
48222
+ }, _callee, this, [[4, 11]]);
48223
+ }));
48224
+
48225
+ function fetchCID(_x, _x2) {
48226
+ return _fetchCID.apply(this, arguments);
48227
+ }
48228
+
48229
+ return fetchCID;
48230
+ }()
48231
+ }, {
48232
+ key: "fetchCIDInternal",
48233
+ value: function () {
48234
+ var _fetchCIDInternal = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(cid, creatorNodeGateways) {
48169
48235
  var callback,
48170
48236
  responseType,
48171
48237
  trackId,
48172
48238
  premiumContentHeaders,
48173
48239
  urls,
48174
- _args2 = arguments;
48175
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
48240
+ _args3 = arguments;
48241
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
48176
48242
  while (1) {
48177
- switch (_context2.prev = _context2.next) {
48243
+ switch (_context3.prev = _context3.next) {
48178
48244
  case 0:
48179
- callback = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : null;
48180
- responseType = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : 'blob';
48181
- trackId = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : null;
48182
- premiumContentHeaders = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : {};
48245
+ callback = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : null;
48246
+ responseType = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : 'blob';
48247
+ trackId = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : null;
48248
+ premiumContentHeaders = _args3.length > 5 && _args3[5] !== undefined ? _args3[5] : {};
48183
48249
  urls = [];
48184
48250
  creatorNodeGateways.forEach(function (gateway) {
48185
48251
  var gatewayWithCid = urlJoin(gateway, cid);
@@ -48190,17 +48256,17 @@ var File = /*#__PURE__*/function (_Base) {
48190
48256
  });
48191
48257
  urls.push(gatewayWithCid);
48192
48258
  });
48193
- _context2.next = 8;
48259
+ _context3.next = 8;
48194
48260
  return retry( /*#__PURE__*/function () {
48195
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(bail) {
48261
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(bail) {
48196
48262
  var _yield$raceRequests, response, errored, allForbidden, legacyUrls, _yield$raceRequests2, _response;
48197
48263
 
48198
- return regeneratorRuntime.wrap(function _callee$(_context) {
48264
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
48199
48265
  while (1) {
48200
- switch (_context.prev = _context.next) {
48266
+ switch (_context2.prev = _context2.next) {
48201
48267
  case 0:
48202
- _context.prev = 0;
48203
- _context.next = 3;
48268
+ _context2.prev = 0;
48269
+ _context2.next = 3;
48204
48270
  return raceRequests(urls, callback, _objectSpread2({
48205
48271
  method: 'get',
48206
48272
  responseType: responseType
@@ -48209,12 +48275,12 @@ var File = /*#__PURE__*/function (_Base) {
48209
48275
  null);
48210
48276
 
48211
48277
  case 3:
48212
- _yield$raceRequests = _context.sent;
48278
+ _yield$raceRequests = _context2.sent;
48213
48279
  response = _yield$raceRequests.response;
48214
48280
  errored = _yield$raceRequests.errored;
48215
48281
 
48216
48282
  if (response) {
48217
- _context.next = 12;
48283
+ _context2.next = 12;
48218
48284
  break;
48219
48285
  }
48220
48286
 
@@ -48224,26 +48290,26 @@ var File = /*#__PURE__*/function (_Base) {
48224
48290
  });
48225
48291
 
48226
48292
  if (!allForbidden) {
48227
- _context.next = 11;
48293
+ _context2.next = 11;
48228
48294
  break;
48229
48295
  }
48230
48296
 
48231
48297
  // In the case for a 403, do not retry fetching
48232
48298
  bail(new Error('Forbidden'));
48233
- return _context.abrupt("return");
48299
+ return _context2.abrupt("return");
48234
48300
 
48235
48301
  case 11:
48236
48302
  throw new Error("Could not fetch ".concat(cid));
48237
48303
 
48238
48304
  case 12:
48239
- return _context.abrupt("return", response);
48305
+ return _context2.abrupt("return", response);
48240
48306
 
48241
48307
  case 15:
48242
- _context.prev = 15;
48243
- _context.t0 = _context["catch"](0);
48308
+ _context2.prev = 15;
48309
+ _context2.t0 = _context2["catch"](0);
48244
48310
 
48245
48311
  if (!cid.includes('/')) {
48246
- _context.next = 33;
48312
+ _context2.next = 33;
48247
48313
  break;
48248
48314
  }
48249
48315
 
@@ -48256,8 +48322,8 @@ var File = /*#__PURE__*/function (_Base) {
48256
48322
  legacyUrls = creatorNodeGateways.map(function (gateway) {
48257
48323
  return urlJoin(gateway, cid.split('/')[0]);
48258
48324
  });
48259
- _context.prev = 20;
48260
- _context.next = 23;
48325
+ _context2.prev = 20;
48326
+ _context2.next = 23;
48261
48327
  return raceRequests(legacyUrls, callback, _objectSpread2({
48262
48328
  method: 'get',
48263
48329
  responseType: responseType
@@ -48266,22 +48332,22 @@ var File = /*#__PURE__*/function (_Base) {
48266
48332
  null);
48267
48333
 
48268
48334
  case 23:
48269
- _yield$raceRequests2 = _context.sent;
48335
+ _yield$raceRequests2 = _context2.sent;
48270
48336
  _response = _yield$raceRequests2.response;
48271
48337
 
48272
48338
  if (_response) {
48273
- _context.next = 27;
48339
+ _context2.next = 27;
48274
48340
  break;
48275
48341
  }
48276
48342
 
48277
48343
  throw new Error("Could not fetch ".concat(cid, " via legacy method"));
48278
48344
 
48279
48345
  case 27:
48280
- return _context.abrupt("return", _response);
48346
+ return _context2.abrupt("return", _response);
48281
48347
 
48282
48348
  case 30:
48283
- _context.prev = 30;
48284
- _context.t1 = _context["catch"](20);
48349
+ _context2.prev = 30;
48350
+ _context2.t1 = _context2["catch"](20);
48285
48351
  throw new Error("Failed to retrieve ".concat(cid, " by legacy method"));
48286
48352
 
48287
48353
  case 33:
@@ -48289,20 +48355,20 @@ var File = /*#__PURE__*/function (_Base) {
48289
48355
 
48290
48356
  case 34:
48291
48357
  case "end":
48292
- return _context.stop();
48358
+ return _context2.stop();
48293
48359
  }
48294
48360
  }
48295
- }, _callee, null, [[0, 15], [20, 30]]);
48361
+ }, _callee2, null, [[0, 15], [20, 30]]);
48296
48362
  }));
48297
48363
 
48298
- return function (_x3) {
48364
+ return function (_x5) {
48299
48365
  return _ref.apply(this, arguments);
48300
48366
  };
48301
48367
  }(), {
48302
48368
  minTimeout: 500,
48303
48369
  maxTimeout: 4000,
48304
48370
  factor: 3,
48305
- retries: 5,
48371
+ retries: 3,
48306
48372
  onRetry: function onRetry(err, i) {
48307
48373
  // eslint-disable-next-line no-console
48308
48374
  console.log("FetchCID attempt ".concat(i, " error: ").concat(err));
@@ -48310,21 +48376,21 @@ var File = /*#__PURE__*/function (_Base) {
48310
48376
  });
48311
48377
 
48312
48378
  case 8:
48313
- return _context2.abrupt("return", _context2.sent);
48379
+ return _context3.abrupt("return", _context3.sent);
48314
48380
 
48315
48381
  case 9:
48316
48382
  case "end":
48317
- return _context2.stop();
48383
+ return _context3.stop();
48318
48384
  }
48319
48385
  }
48320
- }, _callee2);
48386
+ }, _callee3);
48321
48387
  }));
48322
48388
 
48323
- function fetchCID(_x, _x2) {
48324
- return _fetchCID.apply(this, arguments);
48389
+ function fetchCIDInternal(_x3, _x4) {
48390
+ return _fetchCIDInternal.apply(this, arguments);
48325
48391
  }
48326
48392
 
48327
- return fetchCID;
48393
+ return fetchCIDInternal;
48328
48394
  }()
48329
48395
  /**
48330
48396
  * Fetches a file from Content Node with a given CID. Follows the same pattern
@@ -48338,12 +48404,12 @@ var File = /*#__PURE__*/function (_Base) {
48338
48404
  }, {
48339
48405
  key: "downloadCID",
48340
48406
  value: function () {
48341
- var _downloadCID = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(cid, creatorNodeGateways, filename) {
48407
+ var _downloadCID = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(cid, creatorNodeGateways, filename) {
48342
48408
  var urls, _yield$raceRequests3, response;
48343
48409
 
48344
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
48410
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
48345
48411
  while (1) {
48346
- switch (_context3.prev = _context3.next) {
48412
+ switch (_context4.prev = _context4.next) {
48347
48413
  case 0:
48348
48414
  urls = creatorNodeGateways.map(function (gateway) {
48349
48415
  return urlJoin(gateway, cid, {
@@ -48352,8 +48418,8 @@ var File = /*#__PURE__*/function (_Base) {
48352
48418
  }
48353
48419
  });
48354
48420
  });
48355
- _context3.prev = 1;
48356
- _context3.next = 4;
48421
+ _context4.prev = 1;
48422
+ _context4.next = 4;
48357
48423
  return raceRequests(urls, function (url) {
48358
48424
  return downloadURL(url, filename);
48359
48425
  }, {
@@ -48363,24 +48429,24 @@ var File = /*#__PURE__*/function (_Base) {
48363
48429
  10000);
48364
48430
 
48365
48431
  case 4:
48366
- _yield$raceRequests3 = _context3.sent;
48432
+ _yield$raceRequests3 = _context4.sent;
48367
48433
  response = _yield$raceRequests3.response;
48368
- return _context3.abrupt("return", response);
48434
+ return _context4.abrupt("return", response);
48369
48435
 
48370
48436
  case 9:
48371
- _context3.prev = 9;
48372
- _context3.t0 = _context3["catch"](1);
48437
+ _context4.prev = 9;
48438
+ _context4.t0 = _context4["catch"](1);
48373
48439
  throw new Error("Failed to retrieve ".concat(cid));
48374
48440
 
48375
48441
  case 12:
48376
48442
  case "end":
48377
- return _context3.stop();
48443
+ return _context4.stop();
48378
48444
  }
48379
48445
  }
48380
- }, _callee3, null, [[1, 9]]);
48446
+ }, _callee4, null, [[1, 9]]);
48381
48447
  }));
48382
48448
 
48383
- function downloadCID(_x4, _x5, _x6) {
48449
+ function downloadCID(_x6, _x7, _x8) {
48384
48450
  return _downloadCID.apply(this, arguments);
48385
48451
  }
48386
48452
 
@@ -48396,66 +48462,66 @@ var File = /*#__PURE__*/function (_Base) {
48396
48462
  }, {
48397
48463
  key: "checkIfCidAvailable",
48398
48464
  value: function () {
48399
- var _checkIfCidAvailable = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(cid, creatorNodeGateways) {
48465
+ var _checkIfCidAvailable = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(cid, creatorNodeGateways) {
48400
48466
  var exists;
48401
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
48467
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
48402
48468
  while (1) {
48403
- switch (_context5.prev = _context5.next) {
48469
+ switch (_context6.prev = _context6.next) {
48404
48470
  case 0:
48405
48471
  exists = {};
48406
- _context5.next = 3;
48472
+ _context6.next = 3;
48407
48473
  return Promise.all(creatorNodeGateways.map( /*#__PURE__*/function () {
48408
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(gateway) {
48474
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(gateway) {
48409
48475
  var _yield$axios, status;
48410
48476
 
48411
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
48477
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
48412
48478
  while (1) {
48413
- switch (_context4.prev = _context4.next) {
48479
+ switch (_context5.prev = _context5.next) {
48414
48480
  case 0:
48415
- _context4.prev = 0;
48416
- _context4.next = 3;
48481
+ _context5.prev = 0;
48482
+ _context5.next = 3;
48417
48483
  return axios({
48418
48484
  url: urlJoin(gateway, cid),
48419
48485
  method: 'head'
48420
48486
  });
48421
48487
 
48422
48488
  case 3:
48423
- _yield$axios = _context4.sent;
48489
+ _yield$axios = _context5.sent;
48424
48490
  status = _yield$axios.status;
48425
48491
  exists[gateway] = status === 200;
48426
- _context4.next = 11;
48492
+ _context5.next = 11;
48427
48493
  break;
48428
48494
 
48429
48495
  case 8:
48430
- _context4.prev = 8;
48431
- _context4.t0 = _context4["catch"](0);
48496
+ _context5.prev = 8;
48497
+ _context5.t0 = _context5["catch"](0);
48432
48498
  exists[gateway] = false;
48433
48499
 
48434
48500
  case 11:
48435
48501
  case "end":
48436
- return _context4.stop();
48502
+ return _context5.stop();
48437
48503
  }
48438
48504
  }
48439
- }, _callee4, null, [[0, 8]]);
48505
+ }, _callee5, null, [[0, 8]]);
48440
48506
  }));
48441
48507
 
48442
- return function (_x9) {
48508
+ return function (_x11) {
48443
48509
  return _ref2.apply(this, arguments);
48444
48510
  };
48445
48511
  }()));
48446
48512
 
48447
48513
  case 3:
48448
- return _context5.abrupt("return", exists);
48514
+ return _context6.abrupt("return", exists);
48449
48515
 
48450
48516
  case 4:
48451
48517
  case "end":
48452
- return _context5.stop();
48518
+ return _context6.stop();
48453
48519
  }
48454
48520
  }
48455
- }, _callee5);
48521
+ }, _callee6);
48456
48522
  }));
48457
48523
 
48458
- function checkIfCidAvailable(_x7, _x8) {
48524
+ function checkIfCidAvailable(_x9, _x10) {
48459
48525
  return _checkIfCidAvailable.apply(this, arguments);
48460
48526
  }
48461
48527
 
@@ -48469,40 +48535,40 @@ var File = /*#__PURE__*/function (_Base) {
48469
48535
  }, {
48470
48536
  key: "uploadImage",
48471
48537
  value: function () {
48472
- var _uploadImage = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(file, square) {
48538
+ var _uploadImage = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(file, square) {
48473
48539
  var timeoutMs,
48474
48540
  resp,
48475
- _args6 = arguments;
48476
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
48541
+ _args7 = arguments;
48542
+ return regeneratorRuntime.wrap(function _callee7$(_context7) {
48477
48543
  while (1) {
48478
- switch (_context6.prev = _context6.next) {
48544
+ switch (_context7.prev = _context7.next) {
48479
48545
  case 0:
48480
- timeoutMs = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : null;
48546
+ timeoutMs = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
48481
48547
  this.REQUIRES(Services.CREATOR_NODE);
48482
48548
  this.FILE_IS_VALID(file); // Assign a creator_node_endpoint to the user if necessary
48483
48549
 
48484
- _context6.next = 5;
48550
+ _context7.next = 5;
48485
48551
  return this.User.assignReplicaSetIfNecessary();
48486
48552
 
48487
48553
  case 5:
48488
- _context6.next = 7;
48554
+ _context7.next = 7;
48489
48555
  return this.creatorNode.uploadImage(file, square,
48490
48556
  /* onProgress */
48491
48557
  undefined, timeoutMs);
48492
48558
 
48493
48559
  case 7:
48494
- resp = _context6.sent;
48495
- return _context6.abrupt("return", resp);
48560
+ resp = _context7.sent;
48561
+ return _context7.abrupt("return", resp);
48496
48562
 
48497
48563
  case 9:
48498
48564
  case "end":
48499
- return _context6.stop();
48565
+ return _context7.stop();
48500
48566
  }
48501
48567
  }
48502
- }, _callee6, this);
48568
+ }, _callee7, this);
48503
48569
  }));
48504
48570
 
48505
- function uploadImage(_x10, _x11) {
48571
+ function uploadImage(_x12, _x13) {
48506
48572
  return _uploadImage.apply(this, arguments);
48507
48573
  }
48508
48574
 
@@ -50023,7 +50089,7 @@ var AudiusLibs = /*#__PURE__*/function () {
50023
50089
  this.Account = _construct(Account, [this.User].concat(services));
50024
50090
  this.Track = _construct(Track, services);
50025
50091
  this.Playlist = _construct(Playlists, services);
50026
- this.File = _construct(File, [this.User].concat(services));
50092
+ this.File = _construct(File, [this.User, this.ServiceProvider].concat(services));
50027
50093
  this.Rewards = _construct(Rewards, [this.ServiceProvider].concat(services));
50028
50094
  this.Reactions = _construct(Reactions, services);
50029
50095
  this.EntityManager = _construct(EntityManager, services);