@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.
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.32";
36983
36983
  var audius = {
36984
- releaseSHA: "7ce874a45ba7adba69a2f46056ce11392c38509e"
36984
+ releaseSHA: "4a054eaea012fe2486864db78f64558101523e33"
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, creatorNodeBlacklist) {
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 && !(creatorNodeBlacklist !== null && creatorNodeBlacklist !== void 0 && creatorNodeBlacklist.has(primary)))) {
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, _x8) {
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,40 @@ 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
+ creatorNodeBlacklist,
63051
+ _args = arguments;
62800
63052
  return regeneratorRuntime.wrap(function _callee$(_context) {
62801
63053
  while (1) {
62802
63054
  switch (_context.prev = _context.next) {
62803
63055
  case 0:
62804
- _context.next = 2;
62805
- return addSecondaries(this.libs);
62806
-
62807
- case 2:
63056
+ creatorNodeWhitelist = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
63057
+ creatorNodeBlacklist = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
62808
63058
  _context.next = 4;
62809
- return assignReplicaSetIfNecessary(this.libs);
63059
+ return addSecondaries(this.libs);
62810
63060
 
62811
63061
  case 4:
62812
63062
  _context.next = 6;
62813
- return syncNodes(this.libs);
63063
+ return assignReplicaSetIfNecessary(this.libs);
62814
63064
 
62815
63065
  case 6:
62816
63066
  _context.next = 8;
62817
- return needsRecoveryEmail(this.libs);
63067
+ return syncNodes(this.libs);
62818
63068
 
62819
63069
  case 8:
63070
+ if (this.options.skipRollover) {
63071
+ _context.next = 11;
63072
+ break;
63073
+ }
63074
+
63075
+ _context.next = 11;
63076
+ return rolloverNodes(this.libs, creatorNodeWhitelist, creatorNodeBlacklist);
63077
+
63078
+ case 11:
63079
+ _context.next = 13;
63080
+ return needsRecoveryEmail(this.libs);
63081
+
63082
+ case 13:
62820
63083
  case "end":
62821
63084
  return _context.stop();
62822
63085
  }