@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/legacy.js CHANGED
@@ -36979,9 +36979,9 @@ exports.ChatPermission = void 0;
36979
36979
  })(exports.ChatPermission || (exports.ChatPermission = {}));
36980
36980
 
36981
36981
  var name = "@audius/sdk";
36982
- var version = "1.0.30";
36982
+ var version = "1.0.31";
36983
36983
  var audius = {
36984
- releaseSHA: "7ce874a45ba7adba69a2f46056ce11392c38509e"
36984
+ releaseSHA: "6b9562b0bf229dc32799315990f7d160e1223367"
36985
36985
  };
36986
36986
  var description = "";
36987
36987
  var main = "dist/index.cjs.js";
@@ -62691,6 +62691,250 @@ var syncNodes = /*#__PURE__*/function () {
62691
62691
  };
62692
62692
  }();
62693
62693
 
62694
+ var THREE_SECONDS = 3000;
62695
+ var MAX_TRIES = 3;
62696
+ /** Check if the user's primary creator node is healthy */
62697
+
62698
+ var checkPrimaryHealthy = /*#__PURE__*/function () {
62699
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(libs, primary, tries) {
62700
+ var healthy;
62701
+ return regeneratorRuntime.wrap(function _callee$(_context) {
62702
+ while (1) {
62703
+ switch (_context.prev = _context.next) {
62704
+ case 0:
62705
+ _context.next = 2;
62706
+ return Utils.isHealthy(primary);
62707
+
62708
+ case 2:
62709
+ healthy = _context.sent;
62710
+
62711
+ if (!healthy) {
62712
+ _context.next = 7;
62713
+ break;
62714
+ }
62715
+
62716
+ return _context.abrupt("return", healthy);
62717
+
62718
+ case 7:
62719
+ if (!(tries === 0)) {
62720
+ _context.next = 9;
62721
+ break;
62722
+ }
62723
+
62724
+ return _context.abrupt("return", false);
62725
+
62726
+ case 9:
62727
+ _context.next = 11;
62728
+ return Utils.wait(THREE_SECONDS);
62729
+
62730
+ case 11:
62731
+ _context.next = 13;
62732
+ return checkPrimaryHealthy(libs, primary, tries - 1);
62733
+
62734
+ case 13:
62735
+ return _context.abrupt("return", _context.sent);
62736
+
62737
+ case 14:
62738
+ case "end":
62739
+ return _context.stop();
62740
+ }
62741
+ }
62742
+ }, _callee);
62743
+ }));
62744
+
62745
+ return function checkPrimaryHealthy(_x, _x2, _x3) {
62746
+ return _ref.apply(this, arguments);
62747
+ };
62748
+ }();
62749
+ /** Gets new endpoints from a user's secondaries */
62750
+
62751
+
62752
+ var getNewPrimary = /*#__PURE__*/function () {
62753
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(libs, secondaries) {
62754
+ var _iterator, _step, _libs$creatorNode, secondary, syncStatus;
62755
+
62756
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
62757
+ while (1) {
62758
+ switch (_context2.prev = _context2.next) {
62759
+ case 0:
62760
+ _iterator = _createForOfIteratorHelper(secondaries);
62761
+ _context2.prev = 1;
62762
+
62763
+ _iterator.s();
62764
+
62765
+ case 3:
62766
+ if ((_step = _iterator.n()).done) {
62767
+ _context2.next = 14;
62768
+ break;
62769
+ }
62770
+
62771
+ secondary = _step.value;
62772
+ _context2.next = 7;
62773
+ return (_libs$creatorNode = libs.creatorNode) === null || _libs$creatorNode === void 0 ? void 0 : _libs$creatorNode.getSyncStatus(secondary);
62774
+
62775
+ case 7:
62776
+ syncStatus = _context2.sent;
62777
+
62778
+ if (syncStatus) {
62779
+ _context2.next = 10;
62780
+ break;
62781
+ }
62782
+
62783
+ return _context2.abrupt("continue", 12);
62784
+
62785
+ case 10:
62786
+ if (syncStatus.isBehind) {
62787
+ _context2.next = 12;
62788
+ break;
62789
+ }
62790
+
62791
+ return _context2.abrupt("return", secondary);
62792
+
62793
+ case 12:
62794
+ _context2.next = 3;
62795
+ break;
62796
+
62797
+ case 14:
62798
+ _context2.next = 19;
62799
+ break;
62800
+
62801
+ case 16:
62802
+ _context2.prev = 16;
62803
+ _context2.t0 = _context2["catch"](1);
62804
+
62805
+ _iterator.e(_context2.t0);
62806
+
62807
+ case 19:
62808
+ _context2.prev = 19;
62809
+
62810
+ _iterator.f();
62811
+
62812
+ return _context2.finish(19);
62813
+
62814
+ case 22:
62815
+ throw new Error("Could not find valid secondaries for user ".concat(secondaries));
62816
+
62817
+ case 23:
62818
+ case "end":
62819
+ return _context2.stop();
62820
+ }
62821
+ }
62822
+ }, _callee2, null, [[1, 16, 19, 22]]);
62823
+ }));
62824
+
62825
+ return function getNewPrimary(_x4, _x5) {
62826
+ return _ref2.apply(this, arguments);
62827
+ };
62828
+ }();
62829
+
62830
+ var rolloverNodes = /*#__PURE__*/function () {
62831
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(libs, creatorNodeWhitelist) {
62832
+ var _libs$userStateManage;
62833
+
62834
+ var user, primary, healthy, secondaries, _libs$ServiceProvider, _libs$User, _libs$User2, _libs$creatorNode2, _libs$User3, newPrimary, index, newSecondaries, autoselect, newEndpoints, newMetadata;
62835
+
62836
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
62837
+ while (1) {
62838
+ switch (_context3.prev = _context3.next) {
62839
+ case 0:
62840
+ console.debug('Sanity Check - rolloverNodes');
62841
+ user = (_libs$userStateManage = libs.userStateManager) === null || _libs$userStateManage === void 0 ? void 0 : _libs$userStateManage.getCurrentUser();
62842
+
62843
+ if (user) {
62844
+ _context3.next = 4;
62845
+ break;
62846
+ }
62847
+
62848
+ return _context3.abrupt("return");
62849
+
62850
+ case 4:
62851
+ primary = CreatorNode.getPrimary(user.creator_node_endpoint);
62852
+
62853
+ if (primary) {
62854
+ _context3.next = 7;
62855
+ break;
62856
+ }
62857
+
62858
+ return _context3.abrupt("return");
62859
+
62860
+ case 7:
62861
+ _context3.next = 9;
62862
+ return checkPrimaryHealthy(libs, primary, MAX_TRIES);
62863
+
62864
+ case 9:
62865
+ healthy = _context3.sent;
62866
+
62867
+ if (!healthy) {
62868
+ _context3.next = 12;
62869
+ break;
62870
+ }
62871
+
62872
+ return _context3.abrupt("return");
62873
+
62874
+ case 12:
62875
+ secondaries = CreatorNode.getSecondaries(user.creator_node_endpoint);
62876
+ _context3.prev = 13;
62877
+ _context3.next = 16;
62878
+ return getNewPrimary(libs, secondaries);
62879
+
62880
+ case 16:
62881
+ newPrimary = _context3.sent;
62882
+ index = secondaries.indexOf(newPrimary); // Get new secondaries and backfill up to 2
62883
+
62884
+ newSecondaries = _toConsumableArray(secondaries);
62885
+ newSecondaries.splice(index, 1);
62886
+ _context3.next = 22;
62887
+ return (_libs$ServiceProvider = libs.ServiceProvider) === null || _libs$ServiceProvider === void 0 ? void 0 : _libs$ServiceProvider.autoSelectCreatorNodes({
62888
+ numberOfNodes: 2 - newSecondaries.length,
62889
+ whitelist: creatorNodeWhitelist,
62890
+ // Exclude ones we currently have
62891
+ blacklist: new Set([newPrimary].concat(_toConsumableArray(newSecondaries))),
62892
+ preferHigherPatchForPrimary: (_libs$User = libs.User) === null || _libs$User === void 0 ? void 0 : _libs$User.preferHigherPatchForPrimary,
62893
+ preferHigherPatchForSecondaries: (_libs$User2 = libs.User) === null || _libs$User2 === void 0 ? void 0 : _libs$User2.preferHigherPatchForSecondaries
62894
+ });
62895
+
62896
+ case 22:
62897
+ autoselect = _context3.sent;
62898
+
62899
+ if (autoselect) {
62900
+ newSecondaries = newSecondaries.concat([autoselect.primary].concat(_toConsumableArray(autoselect.secondaries)));
62901
+ } // Set the new endpoint and connect to it
62902
+
62903
+
62904
+ newEndpoints = [newPrimary].concat(_toConsumableArray(newSecondaries));
62905
+ _context3.next = 27;
62906
+ return (_libs$creatorNode2 = libs.creatorNode) === null || _libs$creatorNode2 === void 0 ? void 0 : _libs$creatorNode2.setEndpoint(newEndpoints[0]);
62907
+
62908
+ case 27:
62909
+ // Update the user
62910
+ newMetadata = _objectSpread2({}, user);
62911
+ newMetadata.creator_node_endpoint = newEndpoints.join(',');
62912
+ console.debug("Sanity Check - rolloverNodes - new nodes ".concat(newMetadata.creator_node_endpoint));
62913
+ _context3.next = 32;
62914
+ return (_libs$User3 = libs.User) === null || _libs$User3 === void 0 ? void 0 : _libs$User3.updateCreator(user.user_id, newMetadata);
62915
+
62916
+ case 32:
62917
+ _context3.next = 37;
62918
+ break;
62919
+
62920
+ case 34:
62921
+ _context3.prev = 34;
62922
+ _context3.t0 = _context3["catch"](13);
62923
+ console.error(_context3.t0);
62924
+
62925
+ case 37:
62926
+ case "end":
62927
+ return _context3.stop();
62928
+ }
62929
+ }
62930
+ }, _callee3, null, [[13, 34]]);
62931
+ }));
62932
+
62933
+ return function rolloverNodes(_x6, _x7) {
62934
+ return _ref3.apply(this, arguments);
62935
+ };
62936
+ }();
62937
+
62694
62938
  /**
62695
62939
  * Sanity check for whether a user needs a recovery email to be sent.
62696
62940
  * Users with accounts created before email recovery existed need
@@ -62784,9 +63028,14 @@ var assignReplicaSetIfNecessary = /*#__PURE__*/function () {
62784
63028
 
62785
63029
  var SanityChecks = /*#__PURE__*/function () {
62786
63030
  function SanityChecks(libsInstance) {
63031
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
63032
+ skipRollover: false
63033
+ };
63034
+
62787
63035
  _classCallCheck(this, SanityChecks);
62788
63036
 
62789
63037
  this.libs = libsInstance;
63038
+ this.options = options;
62790
63039
  }
62791
63040
  /**
62792
63041
  * Runs sanity checks
@@ -62797,26 +63046,38 @@ var SanityChecks = /*#__PURE__*/function () {
62797
63046
  key: "run",
62798
63047
  value: function () {
62799
63048
  var _run = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
63049
+ var creatorNodeWhitelist,
63050
+ _args = arguments;
62800
63051
  return regeneratorRuntime.wrap(function _callee$(_context) {
62801
63052
  while (1) {
62802
63053
  switch (_context.prev = _context.next) {
62803
63054
  case 0:
62804
- _context.next = 2;
63055
+ creatorNodeWhitelist = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
63056
+ _context.next = 3;
62805
63057
  return addSecondaries(this.libs);
62806
63058
 
62807
- case 2:
62808
- _context.next = 4;
63059
+ case 3:
63060
+ _context.next = 5;
62809
63061
  return assignReplicaSetIfNecessary(this.libs);
62810
63062
 
62811
- case 4:
62812
- _context.next = 6;
63063
+ case 5:
63064
+ _context.next = 7;
62813
63065
  return syncNodes(this.libs);
62814
63066
 
62815
- case 6:
62816
- _context.next = 8;
63067
+ case 7:
63068
+ if (this.options.skipRollover) {
63069
+ _context.next = 10;
63070
+ break;
63071
+ }
63072
+
63073
+ _context.next = 10;
63074
+ return rolloverNodes(this.libs, creatorNodeWhitelist);
63075
+
63076
+ case 10:
63077
+ _context.next = 12;
62817
63078
  return needsRecoveryEmail(this.libs);
62818
63079
 
62819
- case 8:
63080
+ case 12:
62820
63081
  case "end":
62821
63082
  return _context.stop();
62822
63083
  }