@esfaenza/httpservice 11.2.30 → 11.2.34
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 +184 -50
- package/bundles/esfaenza-httpservice.umd.js.map +1 -1
- package/bundles/esfaenza-httpservice.umd.min.js +2 -2
- package/bundles/esfaenza-httpservice.umd.min.js.map +1 -1
- package/esfaenza-httpservice.metadata.json +1 -1
- package/esm2015/lib/httpservice.service.js +143 -47
- package/esm2015/lib/httpservice.service.loc.js +7 -2
- package/esm2015/lib/models/CacheInfos.js +10 -0
- package/fesm2015/esfaenza-httpservice.js +156 -47
- package/fesm2015/esfaenza-httpservice.js.map +1 -1
- package/lib/httpservice.service.d.ts +49 -21
- package/lib/httpservice.service.loc.d.ts +20 -0
- package/lib/models/CacheInfos.d.ts +8 -0
- package/package.json +3 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('rxjs/operators'), require('rxjs')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@esfaenza/httpservice', ['exports', '@angular/common/http', '@angular/core', 'rxjs/operators', 'rxjs'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.httpservice = {}), global.ng.common.http, global.ng.core, global.rxjs.operators, global.rxjs));
|
|
5
|
-
})(this, (function (exports, http, core, operators, rxjs) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('@esfaenza/preferences'), require('rxjs/operators'), require('rxjs')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@esfaenza/httpservice', ['exports', '@angular/common/http', '@angular/core', '@esfaenza/preferences', 'rxjs/operators', 'rxjs'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.httpservice = {}), global.ng.common.http, global.ng.core, global.preferences, global.rxjs.operators, global.rxjs));
|
|
5
|
+
})(this, (function (exports, http, core, preferences, operators, rxjs) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
8
8
|
Copyright (c) Microsoft Corporation.
|
|
@@ -444,9 +444,25 @@
|
|
|
444
444
|
"Redirecting to Login, ignoring HTTP error on call": { "en-US": "Redirecting to Login, ignoring HTTP error on call", "it-IT": "Redireziono al login ignorando errori sulla chiamata", },
|
|
445
445
|
"Already Handling an error, ignoring HTTP error on call": { "en-US": "Already Handling an error, ignoring HTTP error on call", "it-IT": "sto già gestendo un errore, ignoro quello corrente per la chiamata HTTP", },
|
|
446
446
|
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata" },
|
|
447
|
-
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" }
|
|
447
|
+
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" },
|
|
448
|
+
"Converted old storage system to new one": { "en-US": "Converted old storage system to new one", "it-IT": "Convertito il vecchio sistema di storicizzazione al nuovo" },
|
|
449
|
+
"Marking cache to be persisted as soon as possible": { "en-US": "Marking cache to be persisted as soon as possible", "it-IT": "Marco cache da persistere il prima possibile" },
|
|
450
|
+
"No more HTTP calls to be executed, entering idle state and persisting modified caches": { "en-US": "No more HTTP calls to be executed, entering idle state and persisting modified caches", "it-IT": "Nessun'altra chiamata HTTP dev'essere eseguita, entro in stato IDLE e persisto le cache modificate" },
|
|
451
|
+
"Caches succesfully persisted": { "en-US": "Caches succesfully persisted", "it-IT": "Le cache sono state persistite con successo" },
|
|
452
|
+
"Errors persisting modified caches": { "en-US": "Errors persisting modified caches", "it-IT": "Errori nella persistizione delle cache (esiste persistizione? boh...)" },
|
|
448
453
|
};
|
|
449
454
|
|
|
455
|
+
var CacheInfos = /** @class */ (function () {
|
|
456
|
+
function CacheInfos(finalUrl, cache, cacheKey, cacheTime, cacheItem) {
|
|
457
|
+
this.finalUrl = finalUrl;
|
|
458
|
+
this.cache = cache;
|
|
459
|
+
this.cacheKey = cacheKey;
|
|
460
|
+
this.cacheTime = cacheTime;
|
|
461
|
+
this.cacheItem = cacheItem;
|
|
462
|
+
}
|
|
463
|
+
return CacheInfos;
|
|
464
|
+
}());
|
|
465
|
+
|
|
450
466
|
/**
|
|
451
467
|
* Servizio utilizzato per effettuare qualsiasi tipo di chiamata HTTP dall'applicazione, gestisce errori e cache delle risposte nativamente e ne può essere
|
|
452
468
|
* esteso/modificato il comportamento implementando la classe di "hook" **IHttpServiceExtensions** e registrandola nel provider della classe **HttpServiceExtensions**
|
|
@@ -455,7 +471,7 @@
|
|
|
455
471
|
/**
|
|
456
472
|
* @ignore
|
|
457
473
|
*/
|
|
458
|
-
function HTTPService(BACKEND_URL, EXTENSION_CLASS, HTTP_INVALIDATION, LOCALE, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, http) {
|
|
474
|
+
function HTTPService(BACKEND_URL, EXTENSION_CLASS, HTTP_INVALIDATION, LOCALE, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, http, localStorage) {
|
|
459
475
|
var _a, _b;
|
|
460
476
|
this.BACKEND_URL = BACKEND_URL;
|
|
461
477
|
this.EXTENSION_CLASS = EXTENSION_CLASS;
|
|
@@ -466,34 +482,60 @@
|
|
|
466
482
|
this.CACHE_BY_USER = CACHE_BY_USER;
|
|
467
483
|
this.DEBUG_MODE = DEBUG_MODE;
|
|
468
484
|
this.http = http;
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
*/
|
|
485
|
+
this.localStorage = localStorage;
|
|
486
|
+
/** Cache dello stato delle chiamate HTTP attualmente effettuate. Ogni chiamata è rappresentata da un GUID e lo status assume valore **false** solo sugli errori */
|
|
472
487
|
this.callStatus = {};
|
|
473
|
-
/**
|
|
474
|
-
* Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary
|
|
475
|
-
*/
|
|
488
|
+
/** Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary */
|
|
476
489
|
this.localStorageHttpCacheKey = null;
|
|
477
|
-
/**
|
|
478
|
-
* Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary, solo per le chiamate con un tempo definito di caching
|
|
479
|
-
*/
|
|
490
|
+
/** Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary, solo per le chiamate con un tempo definito di caching */
|
|
480
491
|
this.localStorageHttpTimedCacheKey = null;
|
|
481
|
-
/**
|
|
482
|
-
* Nome della cache in cui vengono storicizzate le informazioni sullo scadere della cache stessa
|
|
483
|
-
*/
|
|
492
|
+
/** Nome della cache in cui vengono storicizzate le informazioni sullo scadere della cache stessa */
|
|
484
493
|
this.localStorageHttpCacheExpireKey = null;
|
|
485
|
-
/**
|
|
486
|
-
* Identità collegata al token di autenticazione da usare, richiesta al programma che utilizza la libreria attraverso l'hook **retrieveIdentity** della **HttpServiceExtensions**
|
|
487
|
-
*/
|
|
494
|
+
/** Identità collegata al token di autenticazione da usare, richiesta al programma che utilizza la libreria attraverso l'hook **retrieveIdentity** della **HttpServiceExtensions** */
|
|
488
495
|
this.me = null;
|
|
496
|
+
/** Indica che la cache a tempo dev'essere persistita il prima possibile */
|
|
497
|
+
this.PersistTimedCacheASAP = false;
|
|
498
|
+
/** Indica che la cache senza limiti di tempo dev'essere persistita il prima possibile */
|
|
499
|
+
this.PersistUntimedCacheASAP = false;
|
|
489
500
|
this.ExtensionsImpl = this.EXTENSION_CLASS || new HttpServiceExtensions();
|
|
490
501
|
this.me = this.ExtensionsImpl.retrieveIdentity();
|
|
491
502
|
this.localStorageHttpCacheKey = ((_a = this.APP_NAME) !== null && _a !== void 0 ? _a : "APP").replace(/\s/g, '_') + "_HttpCache";
|
|
492
503
|
this.localStorageHttpTimedCacheKey = ((_b = this.APP_NAME) !== null && _b !== void 0 ? _b : "APP").replace(/\s/g, '_') + "_HttpTimedCache";
|
|
493
504
|
this.localStorageHttpCacheExpireKey = this.localStorageHttpCacheKey + "_Expire";
|
|
505
|
+
this.adjustOldStorageSystem();
|
|
494
506
|
if (this.untimedCacheExpired())
|
|
495
507
|
this.resetHttpUntimedCacheStorage();
|
|
496
508
|
}
|
|
509
|
+
/**
|
|
510
|
+
* Se vedo che ci sono elementi salvati nel localStorage provo a toglierli e a risalvarli via preference.
|
|
511
|
+
* Nel caso migliore li sposto dal localStorage al DB di preference, nel caso peggiore li tolgo e li risalvo nel localStorage
|
|
512
|
+
*/
|
|
513
|
+
HTTPService.prototype.adjustOldStorageSystem = function () {
|
|
514
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
+
var lsTimed, lsUntimed;
|
|
516
|
+
return __generator(this, function (_e) {
|
|
517
|
+
switch (_e.label) {
|
|
518
|
+
case 0:
|
|
519
|
+
lsTimed = localStorage.getItem(this.localStorageHttpTimedCacheKey);
|
|
520
|
+
lsUntimed = localStorage.getItem(this.localStorageHttpCacheKey);
|
|
521
|
+
if (!lsTimed && !lsUntimed)
|
|
522
|
+
return [2 /*return*/];
|
|
523
|
+
localStorage.removeItem(this.localStorageHttpTimedCacheKey);
|
|
524
|
+
localStorage.removeItem(this.localStorageHttpCacheKey);
|
|
525
|
+
lsTimed = lsTimed ? JSON.parse(lsTimed) : {};
|
|
526
|
+
lsUntimed = lsUntimed ? JSON.parse(lsUntimed) : {};
|
|
527
|
+
return [4 /*yield*/, rxjs.forkJoin([
|
|
528
|
+
this.localStorage.store(this.localStorageHttpTimedCacheKey, lsTimed),
|
|
529
|
+
this.localStorage.store(this.localStorageHttpCacheKey, lsUntimed)
|
|
530
|
+
]).toPromise()];
|
|
531
|
+
case 1:
|
|
532
|
+
_e.sent();
|
|
533
|
+
this.log(this.loc("Converted old storage system to new one"));
|
|
534
|
+
return [2 /*return*/];
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
};
|
|
497
539
|
/**
|
|
498
540
|
* Esecuzione di una GET HTTP con eventualmente la gestione della cache qualora la chiamata termini con la convenzione "#cache"
|
|
499
541
|
*
|
|
@@ -530,7 +572,7 @@
|
|
|
530
572
|
if (errorCallback)
|
|
531
573
|
errorCallback();
|
|
532
574
|
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
533
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
575
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
534
576
|
};
|
|
535
577
|
/**
|
|
536
578
|
* Esecuzione di una GET HTTP con eventualmente la gestione della cache qualora la chiamata termini con la convenzione "#cache"
|
|
@@ -571,26 +613,78 @@
|
|
|
571
613
|
if (errorCallback)
|
|
572
614
|
errorCallback();
|
|
573
615
|
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
574
|
-
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
616
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
575
617
|
};
|
|
576
618
|
/**
|
|
577
|
-
* Esecuzione di una POST HTTP
|
|
578
|
-
*
|
|
619
|
+
* Esecuzione di una POST HTTP
|
|
579
620
|
*
|
|
580
621
|
* @param {string} url URL su cui effettuare la chiamata
|
|
581
622
|
* @param {any} bodyData DTO per la chiamata
|
|
623
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
624
|
+
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
625
|
+
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
626
|
+
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
627
|
+
*
|
|
628
|
+
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
629
|
+
*/
|
|
630
|
+
HTTPService.prototype.post = function (url, bodyData, params, transaction, succesfulResultMandatory) {
|
|
631
|
+
var _this = this;
|
|
632
|
+
if (params === void 0) { params = null; }
|
|
633
|
+
if (transaction === void 0) { transaction = ""; }
|
|
634
|
+
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
635
|
+
var myGuid = this.defaultStartCall(url);
|
|
636
|
+
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
637
|
+
return httpCall.pipe(operators.map(function (res) {
|
|
638
|
+
var responseItem = res;
|
|
639
|
+
return responseItem;
|
|
640
|
+
}), operators.catchError(function (err, caught) {
|
|
641
|
+
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
642
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
643
|
+
};
|
|
644
|
+
/**
|
|
645
|
+
* Esecuzione di una DELETE HTTP
|
|
646
|
+
*
|
|
647
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
648
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
582
649
|
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
583
650
|
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
584
651
|
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
585
652
|
*
|
|
586
653
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
587
654
|
*/
|
|
588
|
-
HTTPService.prototype.
|
|
655
|
+
HTTPService.prototype.delete = function (url, params, transaction, succesfulResultMandatory) {
|
|
656
|
+
var _this = this;
|
|
657
|
+
if (params === void 0) { params = null; }
|
|
658
|
+
if (transaction === void 0) { transaction = ""; }
|
|
659
|
+
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
660
|
+
var myGuid = this.defaultStartCall(url);
|
|
661
|
+
var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
|
|
662
|
+
return httpCall.pipe(operators.map(function (res) {
|
|
663
|
+
var responseItem = res;
|
|
664
|
+
return responseItem;
|
|
665
|
+
}), operators.catchError(function (err, caught) {
|
|
666
|
+
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
667
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Esecuzione di una PUT HTTP
|
|
671
|
+
*
|
|
672
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
673
|
+
* @param {any} bodyData DTO per la chiamata
|
|
674
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
675
|
+
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
676
|
+
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
677
|
+
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
678
|
+
*
|
|
679
|
+
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
680
|
+
*/
|
|
681
|
+
HTTPService.prototype.put = function (url, bodyData, params, transaction, succesfulResultMandatory) {
|
|
589
682
|
var _this = this;
|
|
683
|
+
if (params === void 0) { params = null; }
|
|
590
684
|
if (transaction === void 0) { transaction = ""; }
|
|
591
685
|
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
592
686
|
var myGuid = this.defaultStartCall(url);
|
|
593
|
-
var httpCall = this.http.
|
|
687
|
+
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
594
688
|
return httpCall.pipe(operators.map(function (res) {
|
|
595
689
|
var responseItem = res;
|
|
596
690
|
return responseItem;
|
|
@@ -758,7 +852,7 @@
|
|
|
758
852
|
*/
|
|
759
853
|
HTTPService.prototype.checkCacheInvalidation = function (url) {
|
|
760
854
|
var _this = this;
|
|
761
|
-
var cache =
|
|
855
|
+
var cache = this.localStorage.retrieveLocal(this.localStorageHttpCacheKey);
|
|
762
856
|
var tmp = /#cache(:?-(\d+))/gi.exec(url);
|
|
763
857
|
var cacheTime = tmp ? tmp[2] : null;
|
|
764
858
|
var normalizedUrl = url.replace("#cache" + (cacheTime ? "-" + cacheTime : ""), "").replace(this.BACKEND_URL, "");
|
|
@@ -779,21 +873,60 @@
|
|
|
779
873
|
this.log(this.loc("Invlalidating cache element") + " " + k);
|
|
780
874
|
delete cache[k];
|
|
781
875
|
}
|
|
782
|
-
localStorage.
|
|
876
|
+
this.localStorage.storeLocal(this.localStorageHttpCacheKey, cache);
|
|
783
877
|
};
|
|
784
878
|
/**
|
|
785
879
|
* Finalizzazione di una chiamata
|
|
786
880
|
*
|
|
787
881
|
* @param {string} guid GUID collegato alla chiamata appena terminata
|
|
882
|
+
* @param {boolean} persistCacheIfIdle Effettua il persist della cache HTTP solo se non ci sono altre chiamate in corso, per evitare
|
|
883
|
+
* che mi cambi sotto l'oggetto di cache mentre sto salvando le informazioni
|
|
788
884
|
*/
|
|
789
|
-
HTTPService.prototype.tryFinalizeByGuid = function (guid) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
885
|
+
HTTPService.prototype.tryFinalizeByGuid = function (guid, cacheInfos) {
|
|
886
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
887
|
+
var toCall, tmpKey, ret;
|
|
888
|
+
return __generator(this, function (_e) {
|
|
889
|
+
switch (_e.label) {
|
|
890
|
+
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())
|
|
895
|
+
this.ExtensionsImpl.writeRedirectionStatus(false);
|
|
896
|
+
//In ogni caso questa posso rimuoverla
|
|
897
|
+
delete this.callStatus[guid];
|
|
898
|
+
// Se vengo da una chiamata che ha aggiornato la cache a timer o globale marco il fatto che quella cache dev'essere aggiornata
|
|
899
|
+
if (cacheInfos && cacheInfos.cache) {
|
|
900
|
+
this.PersistTimedCacheASAP = this.PersistTimedCacheASAP || !!cacheInfos.cacheTime;
|
|
901
|
+
this.PersistUntimedCacheASAP = this.PersistTimedCacheASAP || !cacheInfos.cacheTime;
|
|
902
|
+
this.log(this.loc("Marking cache to be persisted as soon as possible"));
|
|
903
|
+
}
|
|
904
|
+
if (!((this.PersistTimedCacheASAP || this.PersistUntimedCacheASAP) && Object.keys(this.callStatus).length == 0)) return [3 /*break*/, 2];
|
|
905
|
+
toCall = [];
|
|
906
|
+
tmpKey = "";
|
|
907
|
+
if (this.PersistTimedCacheASAP) {
|
|
908
|
+
tmpKey = this.localStorageHttpTimedCacheKey;
|
|
909
|
+
toCall.push(this.localStorage.store(tmpKey, this.localStorage.retrieveLocal(tmpKey)));
|
|
910
|
+
}
|
|
911
|
+
if (this.PersistUntimedCacheASAP) {
|
|
912
|
+
tmpKey = this.localStorageHttpCacheKey;
|
|
913
|
+
toCall.push(this.localStorage.store(tmpKey, this.localStorage.retrieveLocal(tmpKey)));
|
|
914
|
+
}
|
|
915
|
+
this.log(this.loc("No more HTTP calls to be executed, entering idle state and persisting modified caches..."));
|
|
916
|
+
return [4 /*yield*/, rxjs.forkJoin(toCall).toPromise()];
|
|
917
|
+
case 1:
|
|
918
|
+
ret = _e.sent();
|
|
919
|
+
if (ret)
|
|
920
|
+
this.log(this.loc("Caches succesfully persisted"));
|
|
921
|
+
else
|
|
922
|
+
this.log(this.loc("Errors persisting modified caches"));
|
|
923
|
+
this.PersistTimedCacheASAP = false;
|
|
924
|
+
this.PersistUntimedCacheASAP = false;
|
|
925
|
+
_e.label = 2;
|
|
926
|
+
case 2: return [2 /*return*/];
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
});
|
|
797
930
|
};
|
|
798
931
|
/**
|
|
799
932
|
* Helper che dato un unico File o una lista di File crea un oggetto FormData che può essere inviato comodamente
|
|
@@ -997,7 +1130,7 @@
|
|
|
997
1130
|
* @param {string} url URL su cui effettuare la chiamata
|
|
998
1131
|
* @param {HttpParams} params Parametri della chiamata (nulli in caso di POST)
|
|
999
1132
|
*
|
|
1000
|
-
* @returns {
|
|
1133
|
+
* @returns {CacheInfos} Oggetto contenente le informazioni sulla cache per l'oggetto specificato
|
|
1001
1134
|
*/
|
|
1002
1135
|
HTTPService.prototype.tryGetCacheInformations = function (url, params) {
|
|
1003
1136
|
var cachingKey = null, cacheTime = null, cache = null, item = null;
|
|
@@ -1010,8 +1143,8 @@
|
|
|
1010
1143
|
this.resetHttpUntimedCacheStorage();
|
|
1011
1144
|
cachingKey = this.makeCacheKey(url, params);
|
|
1012
1145
|
var cacheKey = cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
1013
|
-
var cacheLs = localStorage.
|
|
1014
|
-
var cache_1 = cacheLs ?
|
|
1146
|
+
var cacheLs = this.localStorage.retrieveLocal(cacheKey);
|
|
1147
|
+
var cache_1 = cacheLs ? cacheLs : {};
|
|
1015
1148
|
if (cache_1 && cache_1[cachingKey] && !this.timedCacheItemExpired(cache_1[cachingKey])) {
|
|
1016
1149
|
// Se gestisco il tempo esatto della cache prima di restituire l'oggetto cachato lo ripulisco
|
|
1017
1150
|
// dalle proprietà interne che gli ho aggiunto per controllarne la scadenza
|
|
@@ -1020,22 +1153,22 @@
|
|
|
1020
1153
|
item = cache_1[cachingKey];
|
|
1021
1154
|
}
|
|
1022
1155
|
}
|
|
1023
|
-
return
|
|
1156
|
+
return new CacheInfos(url, useCaching, cachingKey, cacheTime, item);
|
|
1024
1157
|
};
|
|
1025
1158
|
/**
|
|
1026
1159
|
* Inserisce un oggetto nella cache appropriata in base alle informazioni contenute nel parametro **cacheInfos**
|
|
1027
1160
|
*
|
|
1028
1161
|
* @param {T} item Oggetto da inserire nella cache
|
|
1029
|
-
* @param {
|
|
1162
|
+
* @param {CacheInfos} cacheInfos Informazioni sulla cache recuperate da una chiamata precedente a **tryGetCacheInformations**
|
|
1030
1163
|
*/
|
|
1031
1164
|
HTTPService.prototype.cacheResponse = function (item, cacheInfos) {
|
|
1032
1165
|
var cacheKey = cacheInfos.cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
1033
|
-
var cacheLs = localStorage.
|
|
1034
|
-
var cache = cacheLs ?
|
|
1166
|
+
var cacheLs = this.localStorage.retrieveLocal(cacheKey);
|
|
1167
|
+
var cache = cacheLs ? cacheLs : {};
|
|
1035
1168
|
cache[cacheInfos.cacheKey] = item;
|
|
1036
1169
|
if (cacheInfos.cacheTime)
|
|
1037
1170
|
cache[cacheInfos.cacheKey].__expire = dayjs().add(cacheInfos.cacheTime, "seconds");
|
|
1038
|
-
localStorage.
|
|
1171
|
+
this.localStorage.storeLocal(cacheKey, cache);
|
|
1039
1172
|
};
|
|
1040
1173
|
/**
|
|
1041
1174
|
* Controlla se la cache per le chiamate senza expire time è scaduta
|
|
@@ -1061,14 +1194,14 @@
|
|
|
1061
1194
|
*/
|
|
1062
1195
|
HTTPService.prototype.resetHttpUntimedCacheStorage = function () {
|
|
1063
1196
|
var _a;
|
|
1064
|
-
localStorage.
|
|
1197
|
+
this.localStorage.store(this.localStorageHttpCacheKey, {}).subscribe();
|
|
1065
1198
|
localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(dayjs().add((_a = this.CLIENT_CACHE_DURATION_S) !== null && _a !== void 0 ? _a : 3600, "second")));
|
|
1066
1199
|
};
|
|
1067
1200
|
/**
|
|
1068
1201
|
* Ripulisce la cache delle chiamate con un tempo di expire definito
|
|
1069
1202
|
*/
|
|
1070
1203
|
HTTPService.prototype.resetHttpTimedCacheStorage = function () {
|
|
1071
|
-
localStorage.
|
|
1204
|
+
this.localStorage.store(this.localStorageHttpTimedCacheKey, {});
|
|
1072
1205
|
};
|
|
1073
1206
|
/**
|
|
1074
1207
|
* Genera una chiave per la cache delle chiamate in base ad URL e Parametri HTTP
|
|
@@ -1080,8 +1213,8 @@
|
|
|
1080
1213
|
*/
|
|
1081
1214
|
HTTPService.prototype.makeCacheKey = function (url, params) {
|
|
1082
1215
|
var authKeyPart = (this.me ? this.me.Idtenant : "") + (this.me && this.CACHE_BY_USER ? this.me.IdUser : "");
|
|
1083
|
-
var paramsKeyPart = params && params.keys().length > 0 ? params.keys().reduce(function (prev, next) { return prev + next + '=' + params.get(next); }, "") : "";
|
|
1084
|
-
return authKeyPart + url + paramsKeyPart;
|
|
1216
|
+
var paramsKeyPart = params && params.keys().length > 0 ? params.keys().reduce(function (prev, next) { return prev + "," + next + '=' + params.get(next); }, "") : "";
|
|
1217
|
+
return authKeyPart + "_" + url.substring(url.indexOf("api") + 4) + "?" + paramsKeyPart;
|
|
1085
1218
|
};
|
|
1086
1219
|
/**
|
|
1087
1220
|
* Generazione GUID
|
|
@@ -1131,7 +1264,8 @@
|
|
|
1131
1264
|
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CLIENT_CACHE_DURATION_S,] }] },
|
|
1132
1265
|
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CACHE_BY_USER,] }] },
|
|
1133
1266
|
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [DEBUG_MODE,] }] },
|
|
1134
|
-
{ type: http.HttpClient }
|
|
1267
|
+
{ type: http.HttpClient },
|
|
1268
|
+
{ type: preferences.PreferencesService }
|
|
1135
1269
|
]; };
|
|
1136
1270
|
|
|
1137
1271
|
var HttpserviceModule = /** @class */ (function () {
|