rest-client-sdk 7.1.0 → 7.2.0

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.js CHANGED
@@ -1305,6 +1305,10 @@
1305
1305
  if (accessTokenExpiresIn !== null && accessTokenExpiresIn <= EXPIRE_LIMIT_SECONDS) {
1306
1306
  return _classPrivateFieldGet(_this3, _tokenStorage).refreshToken().then(function (refreshedTokenObject) {
1307
1307
  return refreshedTokenObject.access_token;
1308
+ })["catch"](function (e) {
1309
+ _this3._handleRefreshTokenFailure(e);
1310
+
1311
+ throw e;
1308
1312
  });
1309
1313
  }
1310
1314
 
@@ -1333,13 +1337,7 @@
1333
1337
 
1334
1338
  return _this4._fetchWithToken(input, updatedRequestParams);
1335
1339
  })["catch"](function (e) {
1336
- if (e instanceof OauthError) {
1337
- _classPrivateFieldGet(_this4, _tokenStorage).logout().then(function () {
1338
- if (_this4.sdk.config.onRefreshTokenFailure) {
1339
- _this4.sdk.config.onRefreshTokenFailure(e);
1340
- }
1341
- });
1342
- }
1340
+ _this4._handleRefreshTokenFailure(e);
1343
1341
 
1344
1342
  throw e;
1345
1343
  });
@@ -1447,6 +1445,19 @@
1447
1445
 
1448
1446
  return object[idKey];
1449
1447
  }
1448
+ }, {
1449
+ key: "_handleRefreshTokenFailure",
1450
+ value: function _handleRefreshTokenFailure(error) {
1451
+ var _this7 = this;
1452
+
1453
+ if (error instanceof OauthError) {
1454
+ _classPrivateFieldGet(this, _tokenStorage).logout().then(function () {
1455
+ if (_this7.sdk.config.onRefreshTokenFailure) {
1456
+ _this7.sdk.config.onRefreshTokenFailure(error);
1457
+ }
1458
+ });
1459
+ }
1460
+ }
1450
1461
  }]);
1451
1462
 
1452
1463
  return AbstractClient;
@@ -2111,6 +2122,54 @@
2111
2122
  return JsSerializer;
2112
2123
  }(Serializer);
2113
2124
 
2125
+ function levenshteinDistance(a, b) {
2126
+ var matrix = []; // Increment along the first column of each row
2127
+
2128
+ for (var i = 0; i <= b.length; i += 1) {
2129
+ matrix[i] = [i];
2130
+ } // Increment each column in the first row
2131
+
2132
+
2133
+ for (var j = 0; j <= a.length; j += 1) {
2134
+ matrix[0][j] = j;
2135
+ } // Fill in the rest of the matrix
2136
+
2137
+
2138
+ for (var _i = 1; _i <= b.length; _i += 1) {
2139
+ for (var _j = 1; _j <= a.length; _j += 1) {
2140
+ if (b.charAt(_i - 1) === a.charAt(_j - 1)) {
2141
+ matrix[_i][_j] = matrix[_i - 1][_j - 1];
2142
+ } else {
2143
+ matrix[_i][_j] = Math.min(matrix[_i - 1][_j - 1] + 1, // substitution
2144
+ matrix[_i][_j - 1] + 1, // insertion
2145
+ matrix[_i - 1][_j] + 1 // deletion
2146
+ );
2147
+ }
2148
+ }
2149
+ }
2150
+
2151
+ return matrix[b.length][a.length];
2152
+ } // eslint-disable-next-line import/prefer-default-export
2153
+
2154
+
2155
+ function findClosestWord(word, list) {
2156
+ var maxDistance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
2157
+ var closestWord = null;
2158
+ var minDistance = Infinity; // eslint-disable-next-line no-plusplus
2159
+
2160
+ for (var i = 0; i < list.length; i += 1) {
2161
+ var candidate = list[i];
2162
+ var distance = levenshteinDistance(word, candidate);
2163
+
2164
+ if (distance < minDistance && distance <= maxDistance) {
2165
+ minDistance = distance;
2166
+ closestWord = candidate;
2167
+ }
2168
+ }
2169
+
2170
+ return closestWord;
2171
+ }
2172
+
2114
2173
  var generateId = function generateId() {
2115
2174
  return "rest-client-sdk|".concat(Date.now(), "-").concat(Math.floor(Math.random() * (9e12 - 1)) + 1e12);
2116
2175
  };
@@ -2260,7 +2319,9 @@
2260
2319
  var metadata = this.mapping.getClassMetadataByKey(key);
2261
2320
 
2262
2321
  if (!metadata) {
2263
- throw new Error("Unable to get metadata for repository ".concat(key));
2322
+ var closeKey = findClosestWord(key, this.mapping.getMappingKeys(), 5);
2323
+ var suggestions = closeKey ? " Did you mean \"".concat(closeKey, "\"?") : '';
2324
+ throw new Error("Unable to get metadata for repository \"".concat(key, "\".").concat(suggestions));
2264
2325
  } // eslint-disable-next-line new-cap
2265
2326
 
2266
2327