@sambath999/localize-token 12.4.3 → 12.4.5
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/bundles/sambath999-localize-token.umd.js +53 -63
- package/bundles/sambath999-localize-token.umd.js.map +1 -1
- package/esm2015/localize-token/helpers/interfaces.js +8 -1
- package/esm2015/localize-token/helpers/loccalize.api.helper.js +6 -19
- package/esm2015/localize-token/localize.api.service.js +13 -7
- package/fesm2015/sambath999-localize-token.js +26 -25
- package/fesm2015/sambath999-localize-token.js.map +1 -1
- package/localize-token/helpers/interfaces.d.ts +3 -9
- package/localize-token/helpers/loccalize.api.helper.d.ts +4 -5
- package/package.json +1 -1
- package/sambath999-localize-token.metadata.json +1 -1
|
@@ -932,7 +932,14 @@
|
|
|
932
932
|
EMethod["PUT"] = "put";
|
|
933
933
|
EMethod["DELETE"] = "delete";
|
|
934
934
|
EMethod["PATCH"] = "patch";
|
|
935
|
-
})(exports.EMethod || (exports.EMethod = {}));
|
|
935
|
+
})(exports.EMethod || (exports.EMethod = {}));
|
|
936
|
+
// export interface INormalizedError {
|
|
937
|
+
// error: any;
|
|
938
|
+
// code: string;
|
|
939
|
+
// message: string;
|
|
940
|
+
// details?: any;
|
|
941
|
+
// status: number;
|
|
942
|
+
// }
|
|
936
943
|
|
|
937
944
|
var LocalizeApiHelper = /** @class */ (function () {
|
|
938
945
|
function LocalizeApiHelper() {
|
|
@@ -947,26 +954,26 @@
|
|
|
947
954
|
LocalizeApiHelper.prototype.performRetry = function (options) {
|
|
948
955
|
return __awaiter(this, void 0, void 0, function () {
|
|
949
956
|
var attempts, lastError, consoleCount, styleElement, result, error_1;
|
|
950
|
-
return __generator(this, function (
|
|
951
|
-
switch (
|
|
957
|
+
return __generator(this, function (_f) {
|
|
958
|
+
switch (_f.label) {
|
|
952
959
|
case 0:
|
|
953
960
|
attempts = 0;
|
|
954
961
|
consoleCount = 0;
|
|
955
962
|
// Merge default retry options with provided options
|
|
956
963
|
options = Object.assign(Object.assign({}, this.defaultRetryOptions), options);
|
|
957
|
-
|
|
964
|
+
_f.label = 1;
|
|
958
965
|
case 1:
|
|
959
966
|
if (!(attempts < options.maxRetries())) return [3 /*break*/, 10];
|
|
960
|
-
|
|
967
|
+
_f.label = 2;
|
|
961
968
|
case 2:
|
|
962
|
-
|
|
969
|
+
_f.trys.push([2, 4, , 9]);
|
|
963
970
|
return [4 /*yield*/, options.callback()];
|
|
964
971
|
case 3:
|
|
965
|
-
result =
|
|
972
|
+
result = _f.sent();
|
|
966
973
|
this.removeBlocker(styleElement);
|
|
967
974
|
return [2 /*return*/, result];
|
|
968
975
|
case 4:
|
|
969
|
-
error_1 =
|
|
976
|
+
error_1 = _f.sent();
|
|
970
977
|
lastError = error_1;
|
|
971
978
|
if (consoleCount >= 7) {
|
|
972
979
|
console.clear();
|
|
@@ -977,12 +984,12 @@
|
|
|
977
984
|
return [4 /*yield*/, this.onConnectionError(options, error_1)];
|
|
978
985
|
case 5:
|
|
979
986
|
// Handle connection error
|
|
980
|
-
styleElement =
|
|
987
|
+
styleElement = _f.sent();
|
|
981
988
|
if (!options.onError) return [3 /*break*/, 7];
|
|
982
989
|
return [4 /*yield*/, this.invokeHook(options.onError.bind(this, error_1))];
|
|
983
990
|
case 6:
|
|
984
|
-
|
|
985
|
-
|
|
991
|
+
_f.sent();
|
|
992
|
+
_f.label = 7;
|
|
986
993
|
case 7:
|
|
987
994
|
if (attempts >= options.maxRetries() - 1)
|
|
988
995
|
throw error_1;
|
|
@@ -991,7 +998,7 @@
|
|
|
991
998
|
console.warn("Attempt " + attempts + " failed. Retrying...", error_1);
|
|
992
999
|
return [4 /*yield*/, waitFor(options.delay)];
|
|
993
1000
|
case 8:
|
|
994
|
-
|
|
1001
|
+
_f.sent();
|
|
995
1002
|
return [3 /*break*/, 9];
|
|
996
1003
|
case 9: return [3 /*break*/, 1];
|
|
997
1004
|
case 10:
|
|
@@ -1005,8 +1012,8 @@
|
|
|
1005
1012
|
var _a, _b, _c, _d;
|
|
1006
1013
|
return __awaiter(this, void 0, void 0, function () {
|
|
1007
1014
|
var retryUnless;
|
|
1008
|
-
return __generator(this, function (
|
|
1009
|
-
switch (
|
|
1015
|
+
return __generator(this, function (_f) {
|
|
1016
|
+
switch (_f.label) {
|
|
1010
1017
|
case 0:
|
|
1011
1018
|
retryUnless = ((_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.retryFunction)
|
|
1012
1019
|
|| this.isConnectionError;
|
|
@@ -1017,7 +1024,7 @@
|
|
|
1017
1024
|
callback: function () { return performRequest(options); },
|
|
1018
1025
|
retryUnless: retryUnless,
|
|
1019
1026
|
})];
|
|
1020
|
-
case 1: return [2 /*return*/,
|
|
1027
|
+
case 1: return [2 /*return*/, _f.sent()];
|
|
1021
1028
|
}
|
|
1022
1029
|
});
|
|
1023
1030
|
});
|
|
@@ -1028,21 +1035,11 @@
|
|
|
1028
1035
|
? normalizedUrl.slice(0, -1)
|
|
1029
1036
|
: normalizedUrl;
|
|
1030
1037
|
};
|
|
1031
|
-
LocalizeApiHelper.prototype.normalizeError = function (error) {
|
|
1032
|
-
var _a, _b, _c;
|
|
1033
|
-
return {
|
|
1034
|
-
error: error.error || {},
|
|
1035
|
-
code: ((_a = error.error) === null || _a === void 0 ? void 0 : _a.code) || "HTTP_" + error.status,
|
|
1036
|
-
message: ((_b = error.error) === null || _b === void 0 ? void 0 : _b.message) || error.message,
|
|
1037
|
-
details: (_c = error.error) === null || _c === void 0 ? void 0 : _c.details,
|
|
1038
|
-
status: error.status
|
|
1039
|
-
};
|
|
1040
|
-
};
|
|
1041
1038
|
LocalizeApiHelper.prototype.invokeHook = function (callback) {
|
|
1042
1039
|
return __awaiter(this, void 0, void 0, function () {
|
|
1043
1040
|
var result;
|
|
1044
|
-
return __generator(this, function (
|
|
1045
|
-
switch (
|
|
1041
|
+
return __generator(this, function (_f) {
|
|
1042
|
+
switch (_f.label) {
|
|
1046
1043
|
case 0:
|
|
1047
1044
|
if (!callback)
|
|
1048
1045
|
return [2 /*return*/];
|
|
@@ -1050,18 +1047,17 @@
|
|
|
1050
1047
|
if (!(result instanceof Promise)) return [3 /*break*/, 2];
|
|
1051
1048
|
return [4 /*yield*/, result];
|
|
1052
1049
|
case 1:
|
|
1053
|
-
|
|
1054
|
-
|
|
1050
|
+
_f.sent();
|
|
1051
|
+
_f.label = 2;
|
|
1055
1052
|
case 2: return [2 /*return*/];
|
|
1056
1053
|
}
|
|
1057
1054
|
});
|
|
1058
1055
|
});
|
|
1059
1056
|
};
|
|
1060
1057
|
LocalizeApiHelper.prototype.createRequest = function (instance, method, url, body, options) {
|
|
1061
|
-
var _this = this;
|
|
1062
1058
|
var request$ = instance.client.request(method, url, Object.assign(Object.assign({}, options), { body: body, observe: 'response' })).pipe(rxjs.takeUntil(instance.destroy$()), rxjs.catchError(function (error) {
|
|
1063
1059
|
// Convert to a non-observable error to handle in the promise
|
|
1064
|
-
return rxjs.throwError(function () { return
|
|
1060
|
+
return rxjs.throwError(function () { return error; });
|
|
1065
1061
|
}));
|
|
1066
1062
|
return request$;
|
|
1067
1063
|
};
|
|
@@ -1080,8 +1076,8 @@
|
|
|
1080
1076
|
var _a;
|
|
1081
1077
|
return __awaiter(this, void 0, void 0, function () {
|
|
1082
1078
|
var styleElement;
|
|
1083
|
-
return __generator(this, function (
|
|
1084
|
-
switch (
|
|
1079
|
+
return __generator(this, function (_f) {
|
|
1080
|
+
switch (_f.label) {
|
|
1085
1081
|
case 0:
|
|
1086
1082
|
if (!options.connectionError)
|
|
1087
1083
|
return [2 /*return*/];
|
|
@@ -1089,12 +1085,12 @@
|
|
|
1089
1085
|
styleElement = this.screenBlocker(options, error, true);
|
|
1090
1086
|
return [4 /*yield*/, this.invokeHook((_a = options.connectionError.callback) === null || _a === void 0 ? void 0 : _a.bind(this, error))];
|
|
1091
1087
|
case 1:
|
|
1092
|
-
|
|
1088
|
+
_f.sent();
|
|
1093
1089
|
return [2 /*return*/, styleElement];
|
|
1094
1090
|
case 2:
|
|
1095
1091
|
this.screenBlocker(options, error, false);
|
|
1096
1092
|
styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
|
|
1097
|
-
|
|
1093
|
+
_f.label = 3;
|
|
1098
1094
|
case 3: return [2 /*return*/];
|
|
1099
1095
|
}
|
|
1100
1096
|
});
|
|
@@ -1102,17 +1098,15 @@
|
|
|
1102
1098
|
};
|
|
1103
1099
|
LocalizeApiHelper.prototype.screenBlocker = function (optons, error, add) {
|
|
1104
1100
|
if (add === void 0) { add = true; }
|
|
1105
|
-
var _a, _b, _c, _d;
|
|
1101
|
+
var _a, _b, _c, _d, _e;
|
|
1106
1102
|
if (!((_a = optons.connectionError) === null || _a === void 0 ? void 0 : _a.blockScreen))
|
|
1107
1103
|
return;
|
|
1108
|
-
if (error instanceof i1.HttpErrorResponse)
|
|
1109
|
-
error = this.normalizeError(error);
|
|
1110
1104
|
var message = ((_b = optons.connectionError) === null || _b === void 0 ? void 0 : _b.message)
|
|
1111
1105
|
|| 'Connection error occurred. Please wait';
|
|
1112
|
-
var errorMessage = (error === null || error === void 0 ? void 0 : error.message) || 'An error occurred';
|
|
1113
|
-
var suggestinMessage = ((
|
|
1106
|
+
var errorMessage = ((_c = error === null || error === void 0 ? void 0 : error.error) === null || _c === void 0 ? void 0 : _c.message) || 'An error occurred';
|
|
1107
|
+
var suggestinMessage = ((_d = optons.connectionError) === null || _d === void 0 ? void 0 : _d.suggestionMessage)
|
|
1114
1108
|
|| 'Please check your internet connection or the server status.';
|
|
1115
|
-
var zIndex = ((
|
|
1109
|
+
var zIndex = ((_e = optons.connectionError) === null || _e === void 0 ? void 0 : _e.blockScreenZIndex) || 10000;
|
|
1116
1110
|
var body = document.body;
|
|
1117
1111
|
var blcokerHtml = "\n <div class=\"lze-blocker\">\n " + LOCALIZE_API_ASSETS.network.noConnection + "\n <div class=\"lze-blocker__message\">\n " + message + "\n <span class=\"lze-blocker__dotting\">\n <span class=\"lze-blocker__dot\"></span>\n <span class=\"lze-blocker__dot\"></span>\n <span class=\"lze-blocker__dot\"></span>\n </span>\n </div>\n <div class=\"lze-blocker__error\">" + errorMessage + "</div>\n <div class=\"lze-blocker__error_suggestion\">" + suggestinMessage + "</div>\n </div>\n ";
|
|
1118
1112
|
var style = "\n div.lze-blocker {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.85) !important;\n z-index: " + zIndex + ";\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n color: #fff !important;\n font-family: Arial, sans-serif;\n text-align: center;\n padding: 20px;\n box-sizing: border-box;\n overflow: hidden;\n user-select: none;\n }\n\n svg#lze-no-connection {\n width: 75px;\n height: 75px;\n margin-bottom: 20px;\n }\n \n div.lze-blocker__message {\n color: #fff !important;\n font-size: 18px !important;\n margin-bottom: 10px;\n }\n \n .lze-blocker__dotting {\n display: inline-block;\n vertical-align: middle;\n }\n span.lze-blocker__dot {\n display: inline-block;\n width: 7px;\n height: 7px;\n background-color: #ffffff !important;\n border-radius: 50%;\n margin-left: 3px;\n opacity: 0.3;\n animation: dotting 1s infinite;\n }\n .lze-blocker__dot:nth-child(1) {\n animation-delay: 0s;\n opacity: 1;\n }\n .lze-blocker__dot:nth-child(2) {\n animation-delay: 0.2s;\n }\n .lze-blocker__dot:nth-child(3) {\n animation-delay: 0.4s;\n }\n\n @keyframes dotting {\n 0%, 80%, 100% { opacity: 0.3; }\n 40% { opacity: 1; }\n }\n\n div.lze-blocker__error {\n color: #f00;\n font-size: 14px !important;\n margin-bottom: 10px;\n text-shadow: 0 0 1px #ff5f5f !important;\n }\n\n div.lze-blocker__error_suggestion {\n color: #ccc !important;\n font-size: 14px !important;\n margin-top: 10px;\n }\n \n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n ";
|
|
@@ -1274,12 +1268,12 @@
|
|
|
1274
1268
|
case 0:
|
|
1275
1269
|
if (error.status !== 401)
|
|
1276
1270
|
throw error;
|
|
1277
|
-
return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; },
|
|
1271
|
+
return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 50)];
|
|
1278
1272
|
case 1:
|
|
1279
1273
|
_e.sent();
|
|
1280
1274
|
return [4 /*yield*/, ApiHelper.performRetry({
|
|
1281
1275
|
maxRetries: function () { return 1000; },
|
|
1282
|
-
delay:
|
|
1276
|
+
delay: 10,
|
|
1283
1277
|
retryUnless: function (error) { return error.status === 401 || ApiHelper.isConnectionError(error); },
|
|
1284
1278
|
callback: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1285
1279
|
return __generator(this, function (_e) {
|
|
@@ -1382,32 +1376,28 @@
|
|
|
1382
1376
|
LocalizeApiService.prototype.toWaitForPreviousRequest = function () {
|
|
1383
1377
|
var _a;
|
|
1384
1378
|
return __awaiter(this, void 0, void 0, function () {
|
|
1385
|
-
var
|
|
1379
|
+
var waitMilliseconds;
|
|
1386
1380
|
var _this = this;
|
|
1387
|
-
return __generator(this, function (
|
|
1388
|
-
switch (
|
|
1381
|
+
return __generator(this, function (_e) {
|
|
1382
|
+
switch (_e.label) {
|
|
1389
1383
|
case 0:
|
|
1390
|
-
|
|
1391
|
-
|
|
1384
|
+
if (!this.isRevokingToken) return [3 /*break*/, 2];
|
|
1385
|
+
// console.warn('A token refresh is in progress. Request is waiting.');
|
|
1392
1386
|
return [4 /*yield*/, waitUntil(function () { return !_this.isRevokingToken; })];
|
|
1393
1387
|
case 1:
|
|
1394
|
-
|
|
1395
|
-
|
|
1388
|
+
// console.warn('A token refresh is in progress. Request is waiting.');
|
|
1389
|
+
_e.sent();
|
|
1390
|
+
_e.label = 2;
|
|
1396
1391
|
case 2:
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
// to wait for each request in 50ms, even if the request is not completed
|
|
1402
|
-
return [3 /*break*/, 4];
|
|
1403
|
-
return [4 /*yield*/, waitFor(this.config.waitEachRequest.milliseconds, this.isRequesting)];
|
|
1392
|
+
waitMilliseconds = (_a = this.config.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds;
|
|
1393
|
+
if (!(waitMilliseconds && this.isRequesting)) return [3 /*break*/, 4];
|
|
1394
|
+
// console.warn(`Request throttling: Another request is in progress. Waiting for ${waitMilliseconds}ms.`);
|
|
1395
|
+
return [4 /*yield*/, waitFor(waitMilliseconds, this.isRequesting)];
|
|
1404
1396
|
case 3:
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
_f;
|
|
1410
|
-
return [2 /*return*/];
|
|
1397
|
+
// console.warn(`Request throttling: Another request is in progress. Waiting for ${waitMilliseconds}ms.`);
|
|
1398
|
+
_e.sent();
|
|
1399
|
+
_e.label = 4;
|
|
1400
|
+
case 4: return [2 /*return*/];
|
|
1411
1401
|
}
|
|
1412
1402
|
});
|
|
1413
1403
|
});
|