@sambath999/localize-token 12.4.4 → 12.4.6

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.
@@ -521,36 +521,51 @@
521
521
  function waitUntil(when, intervalNumber) {
522
522
  if (intervalNumber === void 0) { intervalNumber = 50; }
523
523
  return __awaiter(this, void 0, void 0, function () {
524
+ function isConditionMet() {
525
+ return __awaiter(this, void 0, void 0, function () {
526
+ var cond, result, _a;
527
+ return __generator(this, function (_b) {
528
+ switch (_b.label) {
529
+ case 0:
530
+ cond = when();
531
+ if (!(cond instanceof Promise)) return [3 /*break*/, 2];
532
+ return [4 /*yield*/, cond];
533
+ case 1:
534
+ _a = _b.sent();
535
+ return [3 /*break*/, 3];
536
+ case 2:
537
+ _a = cond;
538
+ _b.label = 3;
539
+ case 3:
540
+ result = _a;
541
+ return [2 /*return*/, result];
542
+ }
543
+ });
544
+ });
545
+ }
524
546
  var _this = this;
525
547
  return __generator(this, function (_a) {
526
548
  switch (_a.label) {
527
- case 0: return [4 /*yield*/, new Promise(function (resolve) {
528
- var interval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
529
- var cond, result, _a;
530
- return __generator(this, function (_b) {
531
- switch (_b.label) {
532
- case 0:
533
- cond = when();
534
- if (!(cond instanceof Promise)) return [3 /*break*/, 2];
535
- return [4 /*yield*/, cond];
536
- case 1:
537
- _a = _b.sent();
538
- return [3 /*break*/, 3];
539
- case 2:
540
- _a = cond;
541
- _b.label = 3;
542
- case 3:
543
- result = _a;
544
- if (result) {
545
- clearInterval(interval);
546
- resolve(true);
547
- }
548
- return [2 /*return*/];
549
- }
550
- });
551
- }); }, intervalNumber);
552
- })];
549
+ case 0: return [4 /*yield*/, isConditionMet()];
553
550
  case 1:
551
+ if (_a.sent())
552
+ return [2 /*return*/];
553
+ return [4 /*yield*/, new Promise(function (resolve) {
554
+ var interval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
555
+ return __generator(this, function (_a) {
556
+ switch (_a.label) {
557
+ case 0: return [4 /*yield*/, isConditionMet()];
558
+ case 1:
559
+ if (_a.sent()) {
560
+ clearInterval(interval);
561
+ resolve(true);
562
+ }
563
+ return [2 /*return*/];
564
+ }
565
+ });
566
+ }); }, intervalNumber);
567
+ })];
568
+ case 2:
554
569
  _a.sent();
555
570
  return [2 /*return*/];
556
571
  }
@@ -1035,15 +1050,6 @@
1035
1050
  ? normalizedUrl.slice(0, -1)
1036
1051
  : normalizedUrl;
1037
1052
  };
1038
- // normalizeError(error: HttpErrorResponse): INormalizedError {
1039
- // return {
1040
- // error: error.error || {},
1041
- // code: error.error?.code || `HTTP_${error.status}`,
1042
- // message: error.error?.message || error.message,
1043
- // details: error.error?.details,
1044
- // status: error.status
1045
- // };
1046
- // }
1047
1053
  LocalizeApiHelper.prototype.invokeHook = function (callback) {
1048
1054
  return __awaiter(this, void 0, void 0, function () {
1049
1055
  var result;
@@ -1245,7 +1251,7 @@
1245
1251
  var _this = this;
1246
1252
  return __generator(this, function (_e) {
1247
1253
  switch (_e.label) {
1248
- case 0: return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 500)];
1254
+ case 0: return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 100)];
1249
1255
  case 1:
1250
1256
  _e.sent();
1251
1257
  return [4 /*yield*/, ApiHelper.invokeHook(this.config.onPrepareRequest)];
@@ -1277,12 +1283,12 @@
1277
1283
  case 0:
1278
1284
  if (error.status !== 401)
1279
1285
  throw error;
1280
- return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 500)];
1286
+ return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 50)];
1281
1287
  case 1:
1282
1288
  _e.sent();
1283
1289
  return [4 /*yield*/, ApiHelper.performRetry({
1284
1290
  maxRetries: function () { return 1000; },
1285
- delay: 500,
1291
+ delay: 10,
1286
1292
  retryUnless: function (error) { return error.status === 401 || ApiHelper.isConnectionError(error); },
1287
1293
  callback: function () { return __awaiter(_this, void 0, void 0, function () {
1288
1294
  return __generator(this, function (_e) {
@@ -1385,32 +1391,28 @@
1385
1391
  LocalizeApiService.prototype.toWaitForPreviousRequest = function () {
1386
1392
  var _a;
1387
1393
  return __awaiter(this, void 0, void 0, function () {
1388
- var _e, _f;
1394
+ var waitMilliseconds;
1389
1395
  var _this = this;
1390
- return __generator(this, function (_g) {
1391
- switch (_g.label) {
1396
+ return __generator(this, function (_e) {
1397
+ switch (_e.label) {
1392
1398
  case 0:
1393
- _e = this.isRevokingToken;
1394
- if (!_e) return [3 /*break*/, 2];
1399
+ if (!this.isRevokingToken) return [3 /*break*/, 2];
1400
+ // console.warn('A token refresh is in progress. Request is waiting.');
1395
1401
  return [4 /*yield*/, waitUntil(function () { return !_this.isRevokingToken; })];
1396
1402
  case 1:
1397
- _e = (_g.sent());
1398
- _g.label = 2;
1403
+ // console.warn('A token refresh is in progress. Request is waiting.');
1404
+ _e.sent();
1405
+ _e.label = 2;
1399
1406
  case 2:
1400
- _e;
1401
- // to wait for each request in 50ms, even if the request is not completed
1402
- _f = ((_a = this.config.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds);
1403
- if (!_f)
1404
- // to wait for each request in 50ms, even if the request is not completed
1405
- return [3 /*break*/, 4];
1406
- return [4 /*yield*/, waitFor(this.config.waitEachRequest.milliseconds, this.isRequesting)];
1407
+ waitMilliseconds = (_a = this.config.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds;
1408
+ if (!(waitMilliseconds && this.isRequesting)) return [3 /*break*/, 4];
1409
+ // console.warn(`Request throttling: Another request is in progress. Waiting for ${waitMilliseconds}ms.`);
1410
+ return [4 /*yield*/, waitFor(waitMilliseconds, this.isRequesting)];
1407
1411
  case 3:
1408
- _f = (_g.sent());
1409
- _g.label = 4;
1410
- case 4:
1411
- // to wait for each request in 50ms, even if the request is not completed
1412
- _f;
1413
- return [2 /*return*/];
1412
+ // console.warn(`Request throttling: Another request is in progress. Waiting for ${waitMilliseconds}ms.`);
1413
+ _e.sent();
1414
+ _e.label = 4;
1415
+ case 4: return [2 /*return*/];
1414
1416
  }
1415
1417
  });
1416
1418
  });