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.es.js CHANGED
@@ -1299,6 +1299,10 @@ var AbstractClient = /*#__PURE__*/function () {
1299
1299
  if (accessTokenExpiresIn !== null && accessTokenExpiresIn <= EXPIRE_LIMIT_SECONDS) {
1300
1300
  return _classPrivateFieldGet(_this3, _tokenStorage).refreshToken().then(function (refreshedTokenObject) {
1301
1301
  return refreshedTokenObject.access_token;
1302
+ })["catch"](function (e) {
1303
+ _this3._handleRefreshTokenFailure(e);
1304
+
1305
+ throw e;
1302
1306
  });
1303
1307
  }
1304
1308
 
@@ -1327,13 +1331,7 @@ var AbstractClient = /*#__PURE__*/function () {
1327
1331
 
1328
1332
  return _this4._fetchWithToken(input, updatedRequestParams);
1329
1333
  })["catch"](function (e) {
1330
- if (e instanceof OauthError) {
1331
- _classPrivateFieldGet(_this4, _tokenStorage).logout().then(function () {
1332
- if (_this4.sdk.config.onRefreshTokenFailure) {
1333
- _this4.sdk.config.onRefreshTokenFailure(e);
1334
- }
1335
- });
1336
- }
1334
+ _this4._handleRefreshTokenFailure(e);
1337
1335
 
1338
1336
  throw e;
1339
1337
  });
@@ -1441,6 +1439,19 @@ var AbstractClient = /*#__PURE__*/function () {
1441
1439
 
1442
1440
  return object[idKey];
1443
1441
  }
1442
+ }, {
1443
+ key: "_handleRefreshTokenFailure",
1444
+ value: function _handleRefreshTokenFailure(error) {
1445
+ var _this7 = this;
1446
+
1447
+ if (error instanceof OauthError) {
1448
+ _classPrivateFieldGet(this, _tokenStorage).logout().then(function () {
1449
+ if (_this7.sdk.config.onRefreshTokenFailure) {
1450
+ _this7.sdk.config.onRefreshTokenFailure(error);
1451
+ }
1452
+ });
1453
+ }
1454
+ }
1444
1455
  }]);
1445
1456
 
1446
1457
  return AbstractClient;
@@ -2105,6 +2116,54 @@ var JsSerializer = /*#__PURE__*/function (_Serializer) {
2105
2116
  return JsSerializer;
2106
2117
  }(Serializer);
2107
2118
 
2119
+ function levenshteinDistance(a, b) {
2120
+ var matrix = []; // Increment along the first column of each row
2121
+
2122
+ for (var i = 0; i <= b.length; i += 1) {
2123
+ matrix[i] = [i];
2124
+ } // Increment each column in the first row
2125
+
2126
+
2127
+ for (var j = 0; j <= a.length; j += 1) {
2128
+ matrix[0][j] = j;
2129
+ } // Fill in the rest of the matrix
2130
+
2131
+
2132
+ for (var _i = 1; _i <= b.length; _i += 1) {
2133
+ for (var _j = 1; _j <= a.length; _j += 1) {
2134
+ if (b.charAt(_i - 1) === a.charAt(_j - 1)) {
2135
+ matrix[_i][_j] = matrix[_i - 1][_j - 1];
2136
+ } else {
2137
+ matrix[_i][_j] = Math.min(matrix[_i - 1][_j - 1] + 1, // substitution
2138
+ matrix[_i][_j - 1] + 1, // insertion
2139
+ matrix[_i - 1][_j] + 1 // deletion
2140
+ );
2141
+ }
2142
+ }
2143
+ }
2144
+
2145
+ return matrix[b.length][a.length];
2146
+ } // eslint-disable-next-line import/prefer-default-export
2147
+
2148
+
2149
+ function findClosestWord(word, list) {
2150
+ var maxDistance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
2151
+ var closestWord = null;
2152
+ var minDistance = Infinity; // eslint-disable-next-line no-plusplus
2153
+
2154
+ for (var i = 0; i < list.length; i += 1) {
2155
+ var candidate = list[i];
2156
+ var distance = levenshteinDistance(word, candidate);
2157
+
2158
+ if (distance < minDistance && distance <= maxDistance) {
2159
+ minDistance = distance;
2160
+ closestWord = candidate;
2161
+ }
2162
+ }
2163
+
2164
+ return closestWord;
2165
+ }
2166
+
2108
2167
  var generateId = function generateId() {
2109
2168
  return "rest-client-sdk|".concat(Date.now(), "-").concat(Math.floor(Math.random() * (9e12 - 1)) + 1e12);
2110
2169
  };
@@ -2254,7 +2313,9 @@ var RestClientSdk = /*#__PURE__*/function () {
2254
2313
  var metadata = this.mapping.getClassMetadataByKey(key);
2255
2314
 
2256
2315
  if (!metadata) {
2257
- throw new Error("Unable to get metadata for repository ".concat(key));
2316
+ var closeKey = findClosestWord(key, this.mapping.getMappingKeys(), 5);
2317
+ var suggestions = closeKey ? " Did you mean \"".concat(closeKey, "\"?") : '';
2318
+ throw new Error("Unable to get metadata for repository \"".concat(key, "\".").concat(suggestions));
2258
2319
  } // eslint-disable-next-line new-cap
2259
2320
 
2260
2321