@audius/sdk 1.0.30 → 1.0.32

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.
@@ -513,9 +513,9 @@ if (typeof window !== 'undefined' && window && window.Web3) {
513
513
  var LibsWeb3 = Web3;
514
514
 
515
515
  var name = "@audius/sdk";
516
- var version = "1.0.30";
516
+ var version = "1.0.32";
517
517
  var audius = {
518
- releaseSHA: "7ce874a45ba7adba69a2f46056ce11392c38509e"
518
+ releaseSHA: "4a054eaea012fe2486864db78f64558101523e33"
519
519
  };
520
520
  var description = "";
521
521
  var main = "dist/index.cjs.js";
@@ -50649,6 +50649,250 @@ var syncNodes = /*#__PURE__*/function () {
50649
50649
  };
50650
50650
  }();
50651
50651
 
50652
+ var THREE_SECONDS = 3000;
50653
+ var MAX_TRIES = 3;
50654
+ /** Check if the user's primary creator node is healthy */
50655
+
50656
+ var checkPrimaryHealthy = /*#__PURE__*/function () {
50657
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(libs, primary, tries) {
50658
+ var healthy;
50659
+ return regeneratorRuntime.wrap(function _callee$(_context) {
50660
+ while (1) {
50661
+ switch (_context.prev = _context.next) {
50662
+ case 0:
50663
+ _context.next = 2;
50664
+ return Utils.isHealthy(primary);
50665
+
50666
+ case 2:
50667
+ healthy = _context.sent;
50668
+
50669
+ if (!healthy) {
50670
+ _context.next = 7;
50671
+ break;
50672
+ }
50673
+
50674
+ return _context.abrupt("return", healthy);
50675
+
50676
+ case 7:
50677
+ if (!(tries === 0)) {
50678
+ _context.next = 9;
50679
+ break;
50680
+ }
50681
+
50682
+ return _context.abrupt("return", false);
50683
+
50684
+ case 9:
50685
+ _context.next = 11;
50686
+ return Utils.wait(THREE_SECONDS);
50687
+
50688
+ case 11:
50689
+ _context.next = 13;
50690
+ return checkPrimaryHealthy(libs, primary, tries - 1);
50691
+
50692
+ case 13:
50693
+ return _context.abrupt("return", _context.sent);
50694
+
50695
+ case 14:
50696
+ case "end":
50697
+ return _context.stop();
50698
+ }
50699
+ }
50700
+ }, _callee);
50701
+ }));
50702
+
50703
+ return function checkPrimaryHealthy(_x, _x2, _x3) {
50704
+ return _ref.apply(this, arguments);
50705
+ };
50706
+ }();
50707
+ /** Gets new endpoints from a user's secondaries */
50708
+
50709
+
50710
+ var getNewPrimary = /*#__PURE__*/function () {
50711
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(libs, secondaries) {
50712
+ var _iterator, _step, _libs$creatorNode, secondary, syncStatus;
50713
+
50714
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
50715
+ while (1) {
50716
+ switch (_context2.prev = _context2.next) {
50717
+ case 0:
50718
+ _iterator = _createForOfIteratorHelper(secondaries);
50719
+ _context2.prev = 1;
50720
+
50721
+ _iterator.s();
50722
+
50723
+ case 3:
50724
+ if ((_step = _iterator.n()).done) {
50725
+ _context2.next = 14;
50726
+ break;
50727
+ }
50728
+
50729
+ secondary = _step.value;
50730
+ _context2.next = 7;
50731
+ return (_libs$creatorNode = libs.creatorNode) === null || _libs$creatorNode === void 0 ? void 0 : _libs$creatorNode.getSyncStatus(secondary);
50732
+
50733
+ case 7:
50734
+ syncStatus = _context2.sent;
50735
+
50736
+ if (syncStatus) {
50737
+ _context2.next = 10;
50738
+ break;
50739
+ }
50740
+
50741
+ return _context2.abrupt("continue", 12);
50742
+
50743
+ case 10:
50744
+ if (syncStatus.isBehind) {
50745
+ _context2.next = 12;
50746
+ break;
50747
+ }
50748
+
50749
+ return _context2.abrupt("return", secondary);
50750
+
50751
+ case 12:
50752
+ _context2.next = 3;
50753
+ break;
50754
+
50755
+ case 14:
50756
+ _context2.next = 19;
50757
+ break;
50758
+
50759
+ case 16:
50760
+ _context2.prev = 16;
50761
+ _context2.t0 = _context2["catch"](1);
50762
+
50763
+ _iterator.e(_context2.t0);
50764
+
50765
+ case 19:
50766
+ _context2.prev = 19;
50767
+
50768
+ _iterator.f();
50769
+
50770
+ return _context2.finish(19);
50771
+
50772
+ case 22:
50773
+ throw new Error("Could not find valid secondaries for user ".concat(secondaries));
50774
+
50775
+ case 23:
50776
+ case "end":
50777
+ return _context2.stop();
50778
+ }
50779
+ }
50780
+ }, _callee2, null, [[1, 16, 19, 22]]);
50781
+ }));
50782
+
50783
+ return function getNewPrimary(_x4, _x5) {
50784
+ return _ref2.apply(this, arguments);
50785
+ };
50786
+ }();
50787
+
50788
+ var rolloverNodes = /*#__PURE__*/function () {
50789
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(libs, creatorNodeWhitelist, creatorNodeBlacklist) {
50790
+ var _libs$userStateManage;
50791
+
50792
+ var user, primary, healthy, secondaries, _libs$ServiceProvider, _libs$User, _libs$User2, _libs$creatorNode2, _libs$User3, newPrimary, index, newSecondaries, autoselect, newEndpoints, newMetadata;
50793
+
50794
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
50795
+ while (1) {
50796
+ switch (_context3.prev = _context3.next) {
50797
+ case 0:
50798
+ console.debug('Sanity Check - rolloverNodes');
50799
+ user = (_libs$userStateManage = libs.userStateManager) === null || _libs$userStateManage === void 0 ? void 0 : _libs$userStateManage.getCurrentUser();
50800
+
50801
+ if (user) {
50802
+ _context3.next = 4;
50803
+ break;
50804
+ }
50805
+
50806
+ return _context3.abrupt("return");
50807
+
50808
+ case 4:
50809
+ primary = CreatorNode.getPrimary(user.creator_node_endpoint);
50810
+
50811
+ if (primary) {
50812
+ _context3.next = 7;
50813
+ break;
50814
+ }
50815
+
50816
+ return _context3.abrupt("return");
50817
+
50818
+ case 7:
50819
+ _context3.next = 9;
50820
+ return checkPrimaryHealthy(libs, primary, MAX_TRIES);
50821
+
50822
+ case 9:
50823
+ healthy = _context3.sent;
50824
+
50825
+ if (!(healthy && !(creatorNodeBlacklist !== null && creatorNodeBlacklist !== void 0 && creatorNodeBlacklist.has(primary)))) {
50826
+ _context3.next = 12;
50827
+ break;
50828
+ }
50829
+
50830
+ return _context3.abrupt("return");
50831
+
50832
+ case 12:
50833
+ secondaries = CreatorNode.getSecondaries(user.creator_node_endpoint);
50834
+ _context3.prev = 13;
50835
+ _context3.next = 16;
50836
+ return getNewPrimary(libs, secondaries);
50837
+
50838
+ case 16:
50839
+ newPrimary = _context3.sent;
50840
+ index = secondaries.indexOf(newPrimary); // Get new secondaries and backfill up to 2
50841
+
50842
+ newSecondaries = _toConsumableArray(secondaries);
50843
+ newSecondaries.splice(index, 1);
50844
+ _context3.next = 22;
50845
+ return (_libs$ServiceProvider = libs.ServiceProvider) === null || _libs$ServiceProvider === void 0 ? void 0 : _libs$ServiceProvider.autoSelectCreatorNodes({
50846
+ numberOfNodes: 2 - newSecondaries.length,
50847
+ whitelist: creatorNodeWhitelist,
50848
+ // Exclude ones we currently have
50849
+ blacklist: new Set([newPrimary].concat(_toConsumableArray(newSecondaries))),
50850
+ preferHigherPatchForPrimary: (_libs$User = libs.User) === null || _libs$User === void 0 ? void 0 : _libs$User.preferHigherPatchForPrimary,
50851
+ preferHigherPatchForSecondaries: (_libs$User2 = libs.User) === null || _libs$User2 === void 0 ? void 0 : _libs$User2.preferHigherPatchForSecondaries
50852
+ });
50853
+
50854
+ case 22:
50855
+ autoselect = _context3.sent;
50856
+
50857
+ if (autoselect) {
50858
+ newSecondaries = newSecondaries.concat([autoselect.primary].concat(_toConsumableArray(autoselect.secondaries)));
50859
+ } // Set the new endpoint and connect to it
50860
+
50861
+
50862
+ newEndpoints = [newPrimary].concat(_toConsumableArray(newSecondaries));
50863
+ _context3.next = 27;
50864
+ return (_libs$creatorNode2 = libs.creatorNode) === null || _libs$creatorNode2 === void 0 ? void 0 : _libs$creatorNode2.setEndpoint(newEndpoints[0]);
50865
+
50866
+ case 27:
50867
+ // Update the user
50868
+ newMetadata = _objectSpread2({}, user);
50869
+ newMetadata.creator_node_endpoint = newEndpoints.join(',');
50870
+ console.debug("Sanity Check - rolloverNodes - new nodes ".concat(newMetadata.creator_node_endpoint));
50871
+ _context3.next = 32;
50872
+ return (_libs$User3 = libs.User) === null || _libs$User3 === void 0 ? void 0 : _libs$User3.updateCreator(user.user_id, newMetadata);
50873
+
50874
+ case 32:
50875
+ _context3.next = 37;
50876
+ break;
50877
+
50878
+ case 34:
50879
+ _context3.prev = 34;
50880
+ _context3.t0 = _context3["catch"](13);
50881
+ console.error(_context3.t0);
50882
+
50883
+ case 37:
50884
+ case "end":
50885
+ return _context3.stop();
50886
+ }
50887
+ }
50888
+ }, _callee3, null, [[13, 34]]);
50889
+ }));
50890
+
50891
+ return function rolloverNodes(_x6, _x7, _x8) {
50892
+ return _ref3.apply(this, arguments);
50893
+ };
50894
+ }();
50895
+
50652
50896
  /**
50653
50897
  * Sanity check for whether a user needs a recovery email to be sent.
50654
50898
  * Users with accounts created before email recovery existed need
@@ -50742,9 +50986,14 @@ var assignReplicaSetIfNecessary = /*#__PURE__*/function () {
50742
50986
 
50743
50987
  var SanityChecks = /*#__PURE__*/function () {
50744
50988
  function SanityChecks(libsInstance) {
50989
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
50990
+ skipRollover: false
50991
+ };
50992
+
50745
50993
  _classCallCheck(this, SanityChecks);
50746
50994
 
50747
50995
  this.libs = libsInstance;
50996
+ this.options = options;
50748
50997
  }
50749
50998
  /**
50750
50999
  * Runs sanity checks
@@ -50755,26 +51004,40 @@ var SanityChecks = /*#__PURE__*/function () {
50755
51004
  key: "run",
50756
51005
  value: function () {
50757
51006
  var _run = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
51007
+ var creatorNodeWhitelist,
51008
+ creatorNodeBlacklist,
51009
+ _args = arguments;
50758
51010
  return regeneratorRuntime.wrap(function _callee$(_context) {
50759
51011
  while (1) {
50760
51012
  switch (_context.prev = _context.next) {
50761
51013
  case 0:
50762
- _context.next = 2;
50763
- return addSecondaries(this.libs);
50764
-
50765
- case 2:
51014
+ creatorNodeWhitelist = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
51015
+ creatorNodeBlacklist = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
50766
51016
  _context.next = 4;
50767
- return assignReplicaSetIfNecessary(this.libs);
51017
+ return addSecondaries(this.libs);
50768
51018
 
50769
51019
  case 4:
50770
51020
  _context.next = 6;
50771
- return syncNodes(this.libs);
51021
+ return assignReplicaSetIfNecessary(this.libs);
50772
51022
 
50773
51023
  case 6:
50774
51024
  _context.next = 8;
50775
- return needsRecoveryEmail(this.libs);
51025
+ return syncNodes(this.libs);
50776
51026
 
50777
51027
  case 8:
51028
+ if (this.options.skipRollover) {
51029
+ _context.next = 11;
51030
+ break;
51031
+ }
51032
+
51033
+ _context.next = 11;
51034
+ return rolloverNodes(this.libs, creatorNodeWhitelist, creatorNodeBlacklist);
51035
+
51036
+ case 11:
51037
+ _context.next = 13;
51038
+ return needsRecoveryEmail(this.libs);
51039
+
51040
+ case 13:
50778
51041
  case "end":
50779
51042
  return _context.stop();
50780
51043
  }