@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.cjs.js CHANGED
@@ -37172,9 +37172,9 @@ exports.ChatPermission = void 0;
37172
37172
  })(exports.ChatPermission || (exports.ChatPermission = {}));
37173
37173
 
37174
37174
  var name = "@audius/sdk";
37175
- var version = "1.0.30";
37175
+ var version = "1.0.31";
37176
37176
  var audius = {
37177
- releaseSHA: "7ce874a45ba7adba69a2f46056ce11392c38509e"
37177
+ releaseSHA: "6b9562b0bf229dc32799315990f7d160e1223367"
37178
37178
  };
37179
37179
  var description = "";
37180
37180
  var main = "dist/index.cjs.js";
@@ -62884,6 +62884,250 @@ var syncNodes = /*#__PURE__*/function () {
62884
62884
  };
62885
62885
  }();
62886
62886
 
62887
+ var THREE_SECONDS = 3000;
62888
+ var MAX_TRIES = 3;
62889
+ /** Check if the user's primary creator node is healthy */
62890
+
62891
+ var checkPrimaryHealthy = /*#__PURE__*/function () {
62892
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(libs, primary, tries) {
62893
+ var healthy;
62894
+ return regeneratorRuntime.wrap(function _callee$(_context) {
62895
+ while (1) {
62896
+ switch (_context.prev = _context.next) {
62897
+ case 0:
62898
+ _context.next = 2;
62899
+ return Utils.isHealthy(primary);
62900
+
62901
+ case 2:
62902
+ healthy = _context.sent;
62903
+
62904
+ if (!healthy) {
62905
+ _context.next = 7;
62906
+ break;
62907
+ }
62908
+
62909
+ return _context.abrupt("return", healthy);
62910
+
62911
+ case 7:
62912
+ if (!(tries === 0)) {
62913
+ _context.next = 9;
62914
+ break;
62915
+ }
62916
+
62917
+ return _context.abrupt("return", false);
62918
+
62919
+ case 9:
62920
+ _context.next = 11;
62921
+ return Utils.wait(THREE_SECONDS);
62922
+
62923
+ case 11:
62924
+ _context.next = 13;
62925
+ return checkPrimaryHealthy(libs, primary, tries - 1);
62926
+
62927
+ case 13:
62928
+ return _context.abrupt("return", _context.sent);
62929
+
62930
+ case 14:
62931
+ case "end":
62932
+ return _context.stop();
62933
+ }
62934
+ }
62935
+ }, _callee);
62936
+ }));
62937
+
62938
+ return function checkPrimaryHealthy(_x, _x2, _x3) {
62939
+ return _ref.apply(this, arguments);
62940
+ };
62941
+ }();
62942
+ /** Gets new endpoints from a user's secondaries */
62943
+
62944
+
62945
+ var getNewPrimary = /*#__PURE__*/function () {
62946
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(libs, secondaries) {
62947
+ var _iterator, _step, _libs$creatorNode, secondary, syncStatus;
62948
+
62949
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
62950
+ while (1) {
62951
+ switch (_context2.prev = _context2.next) {
62952
+ case 0:
62953
+ _iterator = _createForOfIteratorHelper(secondaries);
62954
+ _context2.prev = 1;
62955
+
62956
+ _iterator.s();
62957
+
62958
+ case 3:
62959
+ if ((_step = _iterator.n()).done) {
62960
+ _context2.next = 14;
62961
+ break;
62962
+ }
62963
+
62964
+ secondary = _step.value;
62965
+ _context2.next = 7;
62966
+ return (_libs$creatorNode = libs.creatorNode) === null || _libs$creatorNode === void 0 ? void 0 : _libs$creatorNode.getSyncStatus(secondary);
62967
+
62968
+ case 7:
62969
+ syncStatus = _context2.sent;
62970
+
62971
+ if (syncStatus) {
62972
+ _context2.next = 10;
62973
+ break;
62974
+ }
62975
+
62976
+ return _context2.abrupt("continue", 12);
62977
+
62978
+ case 10:
62979
+ if (syncStatus.isBehind) {
62980
+ _context2.next = 12;
62981
+ break;
62982
+ }
62983
+
62984
+ return _context2.abrupt("return", secondary);
62985
+
62986
+ case 12:
62987
+ _context2.next = 3;
62988
+ break;
62989
+
62990
+ case 14:
62991
+ _context2.next = 19;
62992
+ break;
62993
+
62994
+ case 16:
62995
+ _context2.prev = 16;
62996
+ _context2.t0 = _context2["catch"](1);
62997
+
62998
+ _iterator.e(_context2.t0);
62999
+
63000
+ case 19:
63001
+ _context2.prev = 19;
63002
+
63003
+ _iterator.f();
63004
+
63005
+ return _context2.finish(19);
63006
+
63007
+ case 22:
63008
+ throw new Error("Could not find valid secondaries for user ".concat(secondaries));
63009
+
63010
+ case 23:
63011
+ case "end":
63012
+ return _context2.stop();
63013
+ }
63014
+ }
63015
+ }, _callee2, null, [[1, 16, 19, 22]]);
63016
+ }));
63017
+
63018
+ return function getNewPrimary(_x4, _x5) {
63019
+ return _ref2.apply(this, arguments);
63020
+ };
63021
+ }();
63022
+
63023
+ var rolloverNodes = /*#__PURE__*/function () {
63024
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(libs, creatorNodeWhitelist) {
63025
+ var _libs$userStateManage;
63026
+
63027
+ var user, primary, healthy, secondaries, _libs$ServiceProvider, _libs$User, _libs$User2, _libs$creatorNode2, _libs$User3, newPrimary, index, newSecondaries, autoselect, newEndpoints, newMetadata;
63028
+
63029
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
63030
+ while (1) {
63031
+ switch (_context3.prev = _context3.next) {
63032
+ case 0:
63033
+ console.debug('Sanity Check - rolloverNodes');
63034
+ user = (_libs$userStateManage = libs.userStateManager) === null || _libs$userStateManage === void 0 ? void 0 : _libs$userStateManage.getCurrentUser();
63035
+
63036
+ if (user) {
63037
+ _context3.next = 4;
63038
+ break;
63039
+ }
63040
+
63041
+ return _context3.abrupt("return");
63042
+
63043
+ case 4:
63044
+ primary = CreatorNode.getPrimary(user.creator_node_endpoint);
63045
+
63046
+ if (primary) {
63047
+ _context3.next = 7;
63048
+ break;
63049
+ }
63050
+
63051
+ return _context3.abrupt("return");
63052
+
63053
+ case 7:
63054
+ _context3.next = 9;
63055
+ return checkPrimaryHealthy(libs, primary, MAX_TRIES);
63056
+
63057
+ case 9:
63058
+ healthy = _context3.sent;
63059
+
63060
+ if (!healthy) {
63061
+ _context3.next = 12;
63062
+ break;
63063
+ }
63064
+
63065
+ return _context3.abrupt("return");
63066
+
63067
+ case 12:
63068
+ secondaries = CreatorNode.getSecondaries(user.creator_node_endpoint);
63069
+ _context3.prev = 13;
63070
+ _context3.next = 16;
63071
+ return getNewPrimary(libs, secondaries);
63072
+
63073
+ case 16:
63074
+ newPrimary = _context3.sent;
63075
+ index = secondaries.indexOf(newPrimary); // Get new secondaries and backfill up to 2
63076
+
63077
+ newSecondaries = _toConsumableArray(secondaries);
63078
+ newSecondaries.splice(index, 1);
63079
+ _context3.next = 22;
63080
+ return (_libs$ServiceProvider = libs.ServiceProvider) === null || _libs$ServiceProvider === void 0 ? void 0 : _libs$ServiceProvider.autoSelectCreatorNodes({
63081
+ numberOfNodes: 2 - newSecondaries.length,
63082
+ whitelist: creatorNodeWhitelist,
63083
+ // Exclude ones we currently have
63084
+ blacklist: new Set([newPrimary].concat(_toConsumableArray(newSecondaries))),
63085
+ preferHigherPatchForPrimary: (_libs$User = libs.User) === null || _libs$User === void 0 ? void 0 : _libs$User.preferHigherPatchForPrimary,
63086
+ preferHigherPatchForSecondaries: (_libs$User2 = libs.User) === null || _libs$User2 === void 0 ? void 0 : _libs$User2.preferHigherPatchForSecondaries
63087
+ });
63088
+
63089
+ case 22:
63090
+ autoselect = _context3.sent;
63091
+
63092
+ if (autoselect) {
63093
+ newSecondaries = newSecondaries.concat([autoselect.primary].concat(_toConsumableArray(autoselect.secondaries)));
63094
+ } // Set the new endpoint and connect to it
63095
+
63096
+
63097
+ newEndpoints = [newPrimary].concat(_toConsumableArray(newSecondaries));
63098
+ _context3.next = 27;
63099
+ return (_libs$creatorNode2 = libs.creatorNode) === null || _libs$creatorNode2 === void 0 ? void 0 : _libs$creatorNode2.setEndpoint(newEndpoints[0]);
63100
+
63101
+ case 27:
63102
+ // Update the user
63103
+ newMetadata = _objectSpread2({}, user);
63104
+ newMetadata.creator_node_endpoint = newEndpoints.join(',');
63105
+ console.debug("Sanity Check - rolloverNodes - new nodes ".concat(newMetadata.creator_node_endpoint));
63106
+ _context3.next = 32;
63107
+ return (_libs$User3 = libs.User) === null || _libs$User3 === void 0 ? void 0 : _libs$User3.updateCreator(user.user_id, newMetadata);
63108
+
63109
+ case 32:
63110
+ _context3.next = 37;
63111
+ break;
63112
+
63113
+ case 34:
63114
+ _context3.prev = 34;
63115
+ _context3.t0 = _context3["catch"](13);
63116
+ console.error(_context3.t0);
63117
+
63118
+ case 37:
63119
+ case "end":
63120
+ return _context3.stop();
63121
+ }
63122
+ }
63123
+ }, _callee3, null, [[13, 34]]);
63124
+ }));
63125
+
63126
+ return function rolloverNodes(_x6, _x7) {
63127
+ return _ref3.apply(this, arguments);
63128
+ };
63129
+ }();
63130
+
62887
63131
  /**
62888
63132
  * Sanity check for whether a user needs a recovery email to be sent.
62889
63133
  * Users with accounts created before email recovery existed need
@@ -62977,9 +63221,14 @@ var assignReplicaSetIfNecessary = /*#__PURE__*/function () {
62977
63221
 
62978
63222
  var SanityChecks = /*#__PURE__*/function () {
62979
63223
  function SanityChecks(libsInstance) {
63224
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
63225
+ skipRollover: false
63226
+ };
63227
+
62980
63228
  _classCallCheck(this, SanityChecks);
62981
63229
 
62982
63230
  this.libs = libsInstance;
63231
+ this.options = options;
62983
63232
  }
62984
63233
  /**
62985
63234
  * Runs sanity checks
@@ -62990,26 +63239,38 @@ var SanityChecks = /*#__PURE__*/function () {
62990
63239
  key: "run",
62991
63240
  value: function () {
62992
63241
  var _run = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
63242
+ var creatorNodeWhitelist,
63243
+ _args = arguments;
62993
63244
  return regeneratorRuntime.wrap(function _callee$(_context) {
62994
63245
  while (1) {
62995
63246
  switch (_context.prev = _context.next) {
62996
63247
  case 0:
62997
- _context.next = 2;
63248
+ creatorNodeWhitelist = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
63249
+ _context.next = 3;
62998
63250
  return addSecondaries(this.libs);
62999
63251
 
63000
- case 2:
63001
- _context.next = 4;
63252
+ case 3:
63253
+ _context.next = 5;
63002
63254
  return assignReplicaSetIfNecessary(this.libs);
63003
63255
 
63004
- case 4:
63005
- _context.next = 6;
63256
+ case 5:
63257
+ _context.next = 7;
63006
63258
  return syncNodes(this.libs);
63007
63259
 
63008
- case 6:
63009
- _context.next = 8;
63260
+ case 7:
63261
+ if (this.options.skipRollover) {
63262
+ _context.next = 10;
63263
+ break;
63264
+ }
63265
+
63266
+ _context.next = 10;
63267
+ return rolloverNodes(this.libs, creatorNodeWhitelist);
63268
+
63269
+ case 10:
63270
+ _context.next = 12;
63010
63271
  return needsRecoveryEmail(this.libs);
63011
63272
 
63012
- case 8:
63273
+ case 12:
63013
63274
  case "end":
63014
63275
  return _context.stop();
63015
63276
  }