@esfaenza/httpservice 11.2.34 → 11.2.38
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/esfaenza-httpservice.umd.js +46 -21
- package/bundles/esfaenza-httpservice.umd.js.map +1 -1
- package/bundles/esfaenza-httpservice.umd.min.js +1 -1
- package/bundles/esfaenza-httpservice.umd.min.js.map +1 -1
- package/esfaenza-httpservice.metadata.json +1 -1
- package/esm2015/lib/httpservice.service.js +33 -22
- package/fesm2015/esfaenza-httpservice.js +32 -21
- package/fesm2015/esfaenza-httpservice.js.map +1 -1
- package/lib/httpservice.service.d.ts +4 -2
- package/package.json +2 -2
|
@@ -497,6 +497,8 @@
|
|
|
497
497
|
this.PersistTimedCacheASAP = false;
|
|
498
498
|
/** Indica che la cache senza limiti di tempo dev'essere persistita il prima possibile */
|
|
499
499
|
this.PersistUntimedCacheASAP = false;
|
|
500
|
+
/** Lista delle ultime 3 chiamate completate con successo in ordine di completamento (in posizione 0 c'è l'ultima completata eccetera...) */
|
|
501
|
+
this.LastThreeCompletedCalls = [];
|
|
500
502
|
this.ExtensionsImpl = this.EXTENSION_CLASS || new HttpServiceExtensions();
|
|
501
503
|
this.me = this.ExtensionsImpl.retrieveIdentity();
|
|
502
504
|
this.localStorageHttpCacheKey = ((_a = this.APP_NAME) !== null && _a !== void 0 ? _a : "APP").replace(/\s/g, '_') + "_HttpCache";
|
|
@@ -525,8 +527,8 @@
|
|
|
525
527
|
lsTimed = lsTimed ? JSON.parse(lsTimed) : {};
|
|
526
528
|
lsUntimed = lsUntimed ? JSON.parse(lsUntimed) : {};
|
|
527
529
|
return [4 /*yield*/, rxjs.forkJoin([
|
|
528
|
-
this.localStorage.
|
|
529
|
-
this.localStorage.
|
|
530
|
+
this.localStorage.setItem(this.localStorageHttpTimedCacheKey, lsTimed),
|
|
531
|
+
this.localStorage.setItem(this.localStorageHttpCacheKey, lsUntimed)
|
|
530
532
|
]).toPromise()];
|
|
531
533
|
case 1:
|
|
532
534
|
_e.sent();
|
|
@@ -841,7 +843,7 @@
|
|
|
841
843
|
HTTPService.prototype.defaultStartCall = function (url) {
|
|
842
844
|
var myGuid = this.getGUID();
|
|
843
845
|
this.checkCacheInvalidation(url);
|
|
844
|
-
this.callStatus[myGuid] = true;
|
|
846
|
+
this.callStatus[myGuid] = { url: url, success: true };
|
|
845
847
|
this.log(this.loc("Starting call") + " " + myGuid + " " + this.loc("at URL") + ": " + url);
|
|
846
848
|
return myGuid;
|
|
847
849
|
};
|
|
@@ -852,7 +854,7 @@
|
|
|
852
854
|
*/
|
|
853
855
|
HTTPService.prototype.checkCacheInvalidation = function (url) {
|
|
854
856
|
var _this = this;
|
|
855
|
-
var cache = this.localStorage.
|
|
857
|
+
var cache = this.localStorage.getLocalItem(this.localStorageHttpCacheKey);
|
|
856
858
|
var tmp = /#cache(:?-(\d+))/gi.exec(url);
|
|
857
859
|
var cacheTime = tmp ? tmp[2] : null;
|
|
858
860
|
var normalizedUrl = url.replace("#cache" + (cacheTime ? "-" + cacheTime : ""), "").replace(this.BACKEND_URL, "");
|
|
@@ -873,7 +875,7 @@
|
|
|
873
875
|
this.log(this.loc("Invlalidating cache element") + " " + k);
|
|
874
876
|
delete cache[k];
|
|
875
877
|
}
|
|
876
|
-
this.localStorage.
|
|
878
|
+
this.localStorage.setLocalItem(this.localStorageHttpCacheKey, cache);
|
|
877
879
|
};
|
|
878
880
|
/**
|
|
879
881
|
* Finalizzazione di una chiamata
|
|
@@ -888,12 +890,16 @@
|
|
|
888
890
|
return __generator(this, function (_e) {
|
|
889
891
|
switch (_e.label) {
|
|
890
892
|
case 0:
|
|
891
|
-
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (this.callStatus[guid] ? this.loc('Success') : this.loc('Failure')));
|
|
892
|
-
//Alla prima chiamata buona, significa che almeno il login ce l'ho. Posso mettermi in modalità redirectInProgress false
|
|
893
|
-
//e riiniziare a valutare errori di javashit
|
|
894
|
-
if (this.callStatus[guid] && this.ExtensionsImpl.readRedirectionStatus())
|
|
893
|
+
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (this.callStatus[guid].success ? this.loc('Success') : this.loc('Failure')));
|
|
894
|
+
// Alla prima chiamata buona, significa che almeno il login ce l'ho. Posso mettermi in modalità redirectInProgress false
|
|
895
|
+
// e riiniziare a valutare errori di javashit
|
|
896
|
+
if (this.callStatus[guid].success && this.ExtensionsImpl.readRedirectionStatus())
|
|
895
897
|
this.ExtensionsImpl.writeRedirectionStatus(false);
|
|
896
|
-
//
|
|
898
|
+
// Aggiungo la chiamata alla lista delle ultime 3 completate
|
|
899
|
+
this.LastThreeCompletedCalls.unshift(this.callStatus[guid].url);
|
|
900
|
+
if (this.LastThreeCompletedCalls.length > 3)
|
|
901
|
+
this.LastThreeCompletedCalls.pop();
|
|
902
|
+
// In ogni caso questa posso rimuoverla
|
|
897
903
|
delete this.callStatus[guid];
|
|
898
904
|
// Se vengo da una chiamata che ha aggiornato la cache a timer o globale marco il fatto che quella cache dev'essere aggiornata
|
|
899
905
|
if (cacheInfos && cacheInfos.cache) {
|
|
@@ -906,13 +912,13 @@
|
|
|
906
912
|
tmpKey = "";
|
|
907
913
|
if (this.PersistTimedCacheASAP) {
|
|
908
914
|
tmpKey = this.localStorageHttpTimedCacheKey;
|
|
909
|
-
toCall.push(this.localStorage.
|
|
915
|
+
toCall.push(this.localStorage.setItem(tmpKey, this.localStorage.getLocalItem(tmpKey)));
|
|
910
916
|
}
|
|
911
917
|
if (this.PersistUntimedCacheASAP) {
|
|
912
918
|
tmpKey = this.localStorageHttpCacheKey;
|
|
913
|
-
toCall.push(this.localStorage.
|
|
919
|
+
toCall.push(this.localStorage.setItem(tmpKey, this.localStorage.getLocalItem(tmpKey)));
|
|
914
920
|
}
|
|
915
|
-
this.log(this.loc("No more HTTP calls to be executed, entering idle state and persisting modified caches...")
|
|
921
|
+
this.log(this.loc("No more HTTP calls to be executed, entering idle state and persisting modified caches") + "...");
|
|
916
922
|
return [4 /*yield*/, rxjs.forkJoin(toCall).toPromise()];
|
|
917
923
|
case 1:
|
|
918
924
|
ret = _e.sent();
|
|
@@ -972,7 +978,7 @@
|
|
|
972
978
|
if (authtoken && includeAuth)
|
|
973
979
|
headers = headers.append("Authorization", "Bearer " + authtoken);
|
|
974
980
|
if (accept)
|
|
975
|
-
headers = headers.append("Accept",
|
|
981
|
+
headers = headers.append("Accept", accept);
|
|
976
982
|
headers = headers.append("Accept-Language", (_a = this.LOCALE) !== null && _a !== void 0 ? _a : 'it-IT');
|
|
977
983
|
return headers;
|
|
978
984
|
};
|
|
@@ -988,7 +994,8 @@
|
|
|
988
994
|
return __generator(this, function (_e) {
|
|
989
995
|
switch (_e.label) {
|
|
990
996
|
case 0:
|
|
991
|
-
this.callStatus[guid]
|
|
997
|
+
if (this.callStatus[guid])
|
|
998
|
+
this.callStatus[guid].success = false;
|
|
992
999
|
//Mi assicuro che tutti gli errori durante il redirect al login vengano ignorati
|
|
993
1000
|
if (this.ExtensionsImpl.readRedirectingToLogin()) {
|
|
994
1001
|
this.log(this.loc("Redirecting to Login, ignoring HTTP error on call") + " " + guid);
|
|
@@ -1143,7 +1150,7 @@
|
|
|
1143
1150
|
this.resetHttpUntimedCacheStorage();
|
|
1144
1151
|
cachingKey = this.makeCacheKey(url, params);
|
|
1145
1152
|
var cacheKey = cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
1146
|
-
var cacheLs = this.localStorage.
|
|
1153
|
+
var cacheLs = this.localStorage.getLocalItem(cacheKey);
|
|
1147
1154
|
var cache_1 = cacheLs ? cacheLs : {};
|
|
1148
1155
|
if (cache_1 && cache_1[cachingKey] && !this.timedCacheItemExpired(cache_1[cachingKey])) {
|
|
1149
1156
|
// Se gestisco il tempo esatto della cache prima di restituire l'oggetto cachato lo ripulisco
|
|
@@ -1163,12 +1170,12 @@
|
|
|
1163
1170
|
*/
|
|
1164
1171
|
HTTPService.prototype.cacheResponse = function (item, cacheInfos) {
|
|
1165
1172
|
var cacheKey = cacheInfos.cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
1166
|
-
var cacheLs = this.localStorage.
|
|
1173
|
+
var cacheLs = this.localStorage.getLocalItem(cacheKey);
|
|
1167
1174
|
var cache = cacheLs ? cacheLs : {};
|
|
1168
1175
|
cache[cacheInfos.cacheKey] = item;
|
|
1169
1176
|
if (cacheInfos.cacheTime)
|
|
1170
1177
|
cache[cacheInfos.cacheKey].__expire = dayjs().add(cacheInfos.cacheTime, "seconds");
|
|
1171
|
-
this.localStorage.
|
|
1178
|
+
this.localStorage.setLocalItem(cacheKey, cache);
|
|
1172
1179
|
};
|
|
1173
1180
|
/**
|
|
1174
1181
|
* Controlla se la cache per le chiamate senza expire time è scaduta
|
|
@@ -1194,14 +1201,32 @@
|
|
|
1194
1201
|
*/
|
|
1195
1202
|
HTTPService.prototype.resetHttpUntimedCacheStorage = function () {
|
|
1196
1203
|
var _a;
|
|
1197
|
-
|
|
1198
|
-
|
|
1204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1205
|
+
return __generator(this, function (_e) {
|
|
1206
|
+
switch (_e.label) {
|
|
1207
|
+
case 0: return [4 /*yield*/, this.localStorage.setItem(this.localStorageHttpCacheKey, {}).toPromise()];
|
|
1208
|
+
case 1:
|
|
1209
|
+
_e.sent();
|
|
1210
|
+
localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(dayjs().add((_a = this.CLIENT_CACHE_DURATION_S) !== null && _a !== void 0 ? _a : 3600, "second")));
|
|
1211
|
+
return [2 /*return*/];
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1199
1215
|
};
|
|
1200
1216
|
/**
|
|
1201
1217
|
* Ripulisce la cache delle chiamate con un tempo di expire definito
|
|
1202
1218
|
*/
|
|
1203
1219
|
HTTPService.prototype.resetHttpTimedCacheStorage = function () {
|
|
1204
|
-
|
|
1220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1221
|
+
return __generator(this, function (_e) {
|
|
1222
|
+
switch (_e.label) {
|
|
1223
|
+
case 0: return [4 /*yield*/, this.localStorage.setItem(this.localStorageHttpTimedCacheKey, {}).toPromise()];
|
|
1224
|
+
case 1:
|
|
1225
|
+
_e.sent();
|
|
1226
|
+
return [2 /*return*/];
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1205
1230
|
};
|
|
1206
1231
|
/**
|
|
1207
1232
|
* Genera una chiave per la cache delle chiamate in base ad URL e Parametri HTTP
|