@audius/sdk 1.0.30 → 1.0.31

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/index.esm.js CHANGED
@@ -36930,9 +36930,9 @@ var ChatPermission;
36930
36930
  })(ChatPermission || (ChatPermission = {}));
36931
36931
 
36932
36932
  var name = "@audius/sdk";
36933
- var version = "1.0.30";
36933
+ var version = "1.0.31";
36934
36934
  var audius = {
36935
- releaseSHA: "7ce874a45ba7adba69a2f46056ce11392c38509e"
36935
+ releaseSHA: "6b9562b0bf229dc32799315990f7d160e1223367"
36936
36936
  };
36937
36937
  var description = "";
36938
36938
  var main = "dist/index.cjs.js";
@@ -62642,6 +62642,250 @@ var syncNodes = /*#__PURE__*/function () {
62642
62642
  };
62643
62643
  }();
62644
62644
 
62645
+ var THREE_SECONDS = 3000;
62646
+ var MAX_TRIES = 3;
62647
+ /** Check if the user's primary creator node is healthy */
62648
+
62649
+ var checkPrimaryHealthy = /*#__PURE__*/function () {
62650
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(libs, primary, tries) {
62651
+ var healthy;
62652
+ return regeneratorRuntime.wrap(function _callee$(_context) {
62653
+ while (1) {
62654
+ switch (_context.prev = _context.next) {
62655
+ case 0:
62656
+ _context.next = 2;
62657
+ return Utils.isHealthy(primary);
62658
+
62659
+ case 2:
62660
+ healthy = _context.sent;
62661
+
62662
+ if (!healthy) {
62663
+ _context.next = 7;
62664
+ break;
62665
+ }
62666
+
62667
+ return _context.abrupt("return", healthy);
62668
+
62669
+ case 7:
62670
+ if (!(tries === 0)) {
62671
+ _context.next = 9;
62672
+ break;
62673
+ }
62674
+
62675
+ return _context.abrupt("return", false);
62676
+
62677
+ case 9:
62678
+ _context.next = 11;
62679
+ return Utils.wait(THREE_SECONDS);
62680
+
62681
+ case 11:
62682
+ _context.next = 13;
62683
+ return checkPrimaryHealthy(libs, primary, tries - 1);
62684
+
62685
+ case 13:
62686
+ return _context.abrupt("return", _context.sent);
62687
+
62688
+ case 14:
62689
+ case "end":
62690
+ return _context.stop();
62691
+ }
62692
+ }
62693
+ }, _callee);
62694
+ }));
62695
+
62696
+ return function checkPrimaryHealthy(_x, _x2, _x3) {
62697
+ return _ref.apply(this, arguments);
62698
+ };
62699
+ }();
62700
+ /** Gets new endpoints from a user's secondaries */
62701
+
62702
+
62703
+ var getNewPrimary = /*#__PURE__*/function () {
62704
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(libs, secondaries) {
62705
+ var _iterator, _step, _libs$creatorNode, secondary, syncStatus;
62706
+
62707
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
62708
+ while (1) {
62709
+ switch (_context2.prev = _context2.next) {
62710
+ case 0:
62711
+ _iterator = _createForOfIteratorHelper(secondaries);
62712
+ _context2.prev = 1;
62713
+
62714
+ _iterator.s();
62715
+
62716
+ case 3:
62717
+ if ((_step = _iterator.n()).done) {
62718
+ _context2.next = 14;
62719
+ break;
62720
+ }
62721
+
62722
+ secondary = _step.value;
62723
+ _context2.next = 7;
62724
+ return (_libs$creatorNode = libs.creatorNode) === null || _libs$creatorNode === void 0 ? void 0 : _libs$creatorNode.getSyncStatus(secondary);
62725
+
62726
+ case 7:
62727
+ syncStatus = _context2.sent;
62728
+
62729
+ if (syncStatus) {
62730
+ _context2.next = 10;
62731
+ break;
62732
+ }
62733
+
62734
+ return _context2.abrupt("continue", 12);
62735
+
62736
+ case 10:
62737
+ if (syncStatus.isBehind) {
62738
+ _context2.next = 12;
62739
+ break;
62740
+ }
62741
+
62742
+ return _context2.abrupt("return", secondary);
62743
+
62744
+ case 12:
62745
+ _context2.next = 3;
62746
+ break;
62747
+
62748
+ case 14:
62749
+ _context2.next = 19;
62750
+ break;
62751
+
62752
+ case 16:
62753
+ _context2.prev = 16;
62754
+ _context2.t0 = _context2["catch"](1);
62755
+
62756
+ _iterator.e(_context2.t0);
62757
+
62758
+ case 19:
62759
+ _context2.prev = 19;
62760
+
62761
+ _iterator.f();
62762
+
62763
+ return _context2.finish(19);
62764
+
62765
+ case 22:
62766
+ throw new Error("Could not find valid secondaries for user ".concat(secondaries));
62767
+
62768
+ case 23:
62769
+ case "end":
62770
+ return _context2.stop();
62771
+ }
62772
+ }
62773
+ }, _callee2, null, [[1, 16, 19, 22]]);
62774
+ }));
62775
+
62776
+ return function getNewPrimary(_x4, _x5) {
62777
+ return _ref2.apply(this, arguments);
62778
+ };
62779
+ }();
62780
+
62781
+ var rolloverNodes = /*#__PURE__*/function () {
62782
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(libs, creatorNodeWhitelist) {
62783
+ var _libs$userStateManage;
62784
+
62785
+ var user, primary, healthy, secondaries, _libs$ServiceProvider, _libs$User, _libs$User2, _libs$creatorNode2, _libs$User3, newPrimary, index, newSecondaries, autoselect, newEndpoints, newMetadata;
62786
+
62787
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
62788
+ while (1) {
62789
+ switch (_context3.prev = _context3.next) {
62790
+ case 0:
62791
+ console.debug('Sanity Check - rolloverNodes');
62792
+ user = (_libs$userStateManage = libs.userStateManager) === null || _libs$userStateManage === void 0 ? void 0 : _libs$userStateManage.getCurrentUser();
62793
+
62794
+ if (user) {
62795
+ _context3.next = 4;
62796
+ break;
62797
+ }
62798
+
62799
+ return _context3.abrupt("return");
62800
+
62801
+ case 4:
62802
+ primary = CreatorNode.getPrimary(user.creator_node_endpoint);
62803
+
62804
+ if (primary) {
62805
+ _context3.next = 7;
62806
+ break;
62807
+ }
62808
+
62809
+ return _context3.abrupt("return");
62810
+
62811
+ case 7:
62812
+ _context3.next = 9;
62813
+ return checkPrimaryHealthy(libs, primary, MAX_TRIES);
62814
+
62815
+ case 9:
62816
+ healthy = _context3.sent;
62817
+
62818
+ if (!healthy) {
62819
+ _context3.next = 12;
62820
+ break;
62821
+ }
62822
+
62823
+ return _context3.abrupt("return");
62824
+
62825
+ case 12:
62826
+ secondaries = CreatorNode.getSecondaries(user.creator_node_endpoint);
62827
+ _context3.prev = 13;
62828
+ _context3.next = 16;
62829
+ return getNewPrimary(libs, secondaries);
62830
+
62831
+ case 16:
62832
+ newPrimary = _context3.sent;
62833
+ index = secondaries.indexOf(newPrimary); // Get new secondaries and backfill up to 2
62834
+
62835
+ newSecondaries = _toConsumableArray(secondaries);
62836
+ newSecondaries.splice(index, 1);
62837
+ _context3.next = 22;
62838
+ return (_libs$ServiceProvider = libs.ServiceProvider) === null || _libs$ServiceProvider === void 0 ? void 0 : _libs$ServiceProvider.autoSelectCreatorNodes({
62839
+ numberOfNodes: 2 - newSecondaries.length,
62840
+ whitelist: creatorNodeWhitelist,
62841
+ // Exclude ones we currently have
62842
+ blacklist: new Set([newPrimary].concat(_toConsumableArray(newSecondaries))),
62843
+ preferHigherPatchForPrimary: (_libs$User = libs.User) === null || _libs$User === void 0 ? void 0 : _libs$User.preferHigherPatchForPrimary,
62844
+ preferHigherPatchForSecondaries: (_libs$User2 = libs.User) === null || _libs$User2 === void 0 ? void 0 : _libs$User2.preferHigherPatchForSecondaries
62845
+ });
62846
+
62847
+ case 22:
62848
+ autoselect = _context3.sent;
62849
+
62850
+ if (autoselect) {
62851
+ newSecondaries = newSecondaries.concat([autoselect.primary].concat(_toConsumableArray(autoselect.secondaries)));
62852
+ } // Set the new endpoint and connect to it
62853
+
62854
+
62855
+ newEndpoints = [newPrimary].concat(_toConsumableArray(newSecondaries));
62856
+ _context3.next = 27;
62857
+ return (_libs$creatorNode2 = libs.creatorNode) === null || _libs$creatorNode2 === void 0 ? void 0 : _libs$creatorNode2.setEndpoint(newEndpoints[0]);
62858
+
62859
+ case 27:
62860
+ // Update the user
62861
+ newMetadata = _objectSpread2({}, user);
62862
+ newMetadata.creator_node_endpoint = newEndpoints.join(',');
62863
+ console.debug("Sanity Check - rolloverNodes - new nodes ".concat(newMetadata.creator_node_endpoint));
62864
+ _context3.next = 32;
62865
+ return (_libs$User3 = libs.User) === null || _libs$User3 === void 0 ? void 0 : _libs$User3.updateCreator(user.user_id, newMetadata);
62866
+
62867
+ case 32:
62868
+ _context3.next = 37;
62869
+ break;
62870
+
62871
+ case 34:
62872
+ _context3.prev = 34;
62873
+ _context3.t0 = _context3["catch"](13);
62874
+ console.error(_context3.t0);
62875
+
62876
+ case 37:
62877
+ case "end":
62878
+ return _context3.stop();
62879
+ }
62880
+ }
62881
+ }, _callee3, null, [[13, 34]]);
62882
+ }));
62883
+
62884
+ return function rolloverNodes(_x6, _x7) {
62885
+ return _ref3.apply(this, arguments);
62886
+ };
62887
+ }();
62888
+
62645
62889
  /**
62646
62890
  * Sanity check for whether a user needs a recovery email to be sent.
62647
62891
  * Users with accounts created before email recovery existed need
@@ -62735,9 +62979,14 @@ var assignReplicaSetIfNecessary = /*#__PURE__*/function () {
62735
62979
 
62736
62980
  var SanityChecks = /*#__PURE__*/function () {
62737
62981
  function SanityChecks(libsInstance) {
62982
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
62983
+ skipRollover: false
62984
+ };
62985
+
62738
62986
  _classCallCheck(this, SanityChecks);
62739
62987
 
62740
62988
  this.libs = libsInstance;
62989
+ this.options = options;
62741
62990
  }
62742
62991
  /**
62743
62992
  * Runs sanity checks
@@ -62748,26 +62997,38 @@ var SanityChecks = /*#__PURE__*/function () {
62748
62997
  key: "run",
62749
62998
  value: function () {
62750
62999
  var _run = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
63000
+ var creatorNodeWhitelist,
63001
+ _args = arguments;
62751
63002
  return regeneratorRuntime.wrap(function _callee$(_context) {
62752
63003
  while (1) {
62753
63004
  switch (_context.prev = _context.next) {
62754
63005
  case 0:
62755
- _context.next = 2;
63006
+ creatorNodeWhitelist = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
63007
+ _context.next = 3;
62756
63008
  return addSecondaries(this.libs);
62757
63009
 
62758
- case 2:
62759
- _context.next = 4;
63010
+ case 3:
63011
+ _context.next = 5;
62760
63012
  return assignReplicaSetIfNecessary(this.libs);
62761
63013
 
62762
- case 4:
62763
- _context.next = 6;
63014
+ case 5:
63015
+ _context.next = 7;
62764
63016
  return syncNodes(this.libs);
62765
63017
 
62766
- case 6:
62767
- _context.next = 8;
63018
+ case 7:
63019
+ if (this.options.skipRollover) {
63020
+ _context.next = 10;
63021
+ break;
63022
+ }
63023
+
63024
+ _context.next = 10;
63025
+ return rolloverNodes(this.libs, creatorNodeWhitelist);
63026
+
63027
+ case 10:
63028
+ _context.next = 12;
62768
63029
  return needsRecoveryEmail(this.libs);
62769
63030
 
62770
- case 8:
63031
+ case 12:
62771
63032
  case "end":
62772
63033
  return _context.stop();
62773
63034
  }