@esfaenza/httpservice 19.2.11 → 19.2.13
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/fesm2022/esfaenza-httpservice.mjs +112 -33
- package/fesm2022/esfaenza-httpservice.mjs.map +1 -1
- package/index.d.ts +588 -3
- package/package.json +2 -6
- package/lib/config/HttpServiceExtensions.d.ts +0 -65
- package/lib/config/HttpServiceModuleConfig.d.ts +0 -25
- package/lib/config/IHttpServiceExtensions.d.ts +0 -61
- package/lib/httpservice.module.d.ts +0 -9
- package/lib/httpservice.service.d.ts +0 -380
- package/lib/models/CacheInfos.d.ts +0 -8
- package/lib/models/Download.d.ts +0 -5
- package/lib/tokens.d.ts +0 -21
- package/public-api.d.ts +0 -7
|
@@ -6,7 +6,6 @@ import { first, concatMap, delay, finalize, map, catchError, scan } from 'rxjs/o
|
|
|
6
6
|
import { Subject, forkJoin, of, from, throwError, Observable } from 'rxjs';
|
|
7
7
|
import * as i2 from '@esfaenza/localizations';
|
|
8
8
|
import * as i4 from '@esfaenza/preferences';
|
|
9
|
-
import * as i5 from '@esfaenza/extensions';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Dizionario di invalidazioni delle chiamate HTTP
|
|
@@ -106,10 +105,10 @@ class HttpServiceExtensions {
|
|
|
106
105
|
handleException(status, text) {
|
|
107
106
|
console.error("ESHttpError " + status + " " + text);
|
|
108
107
|
}
|
|
109
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
110
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
108
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HttpServiceExtensions, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
109
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HttpServiceExtensions, providedIn: 'root' }); }
|
|
111
110
|
}
|
|
112
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
111
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HttpServiceExtensions, decorators: [{
|
|
113
112
|
type: Injectable,
|
|
114
113
|
args: [{ providedIn: 'root' }]
|
|
115
114
|
}] });
|
|
@@ -133,7 +132,7 @@ class HTTPService {
|
|
|
133
132
|
/**
|
|
134
133
|
* @ignore
|
|
135
134
|
*/
|
|
136
|
-
constructor(EXTENSION_CLASS, HTTP_INVALIDATION, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, HTTP_DEBUG_MODE, bc, http, localStorage
|
|
135
|
+
constructor(EXTENSION_CLASS, HTTP_INVALIDATION, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, HTTP_DEBUG_MODE, bc, http, localStorage) {
|
|
137
136
|
this.EXTENSION_CLASS = EXTENSION_CLASS;
|
|
138
137
|
this.HTTP_INVALIDATION = HTTP_INVALIDATION;
|
|
139
138
|
this.CLIENT_CACHE_DURATION_S = CLIENT_CACHE_DURATION_S;
|
|
@@ -142,8 +141,6 @@ class HTTPService {
|
|
|
142
141
|
this.bc = bc;
|
|
143
142
|
this.http = http;
|
|
144
143
|
this.localStorage = localStorage;
|
|
145
|
-
this.hash = hash;
|
|
146
|
-
this.utisExts = utisExts;
|
|
147
144
|
/** Cache dello stato delle chiamate HTTP attualmente effettuate. Ogni chiamata è rappresentata da un GUID e lo status assume valore **false** solo sugli errori */
|
|
148
145
|
this.callStatus = {};
|
|
149
146
|
/** Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary */
|
|
@@ -169,6 +166,17 @@ class HTTPService {
|
|
|
169
166
|
this.GET_Trans_BeginTrans = "/api/Trans/BeginTrans";
|
|
170
167
|
this.GET_Trans_CheckExecution = "/api/Trans/CheckExecution";
|
|
171
168
|
this.GET_Trans_EndTrans = "/api/Trans/EndTrans";
|
|
169
|
+
/*****************************************************************************************************************************************
|
|
170
|
+
***************************************************** ROBA PER HASHING ******************************************************************
|
|
171
|
+
*****************************************************************************************************************************************/
|
|
172
|
+
/**
|
|
173
|
+
* Blacklist dei tipi da ignorare quando si effettua l'hashing degli oggetti
|
|
174
|
+
*/
|
|
175
|
+
this.objBlacklist = {
|
|
176
|
+
"NgForm": true, "ElementRef": true, "ExtensionsService": true, "ToastrService": true, "LocaleService": true, "AppState": true, "Router": true,
|
|
177
|
+
"ActivatedRoute": true, "HTTPService": true, "Location": true, "CanvasComponent": true, "ModalDirective": true, "ChangeDetectorRef": true,
|
|
178
|
+
"DateService": true, "EventEmitter": true, "ViewRef_": true, "Subscriber": true, "ItemLocalization": true
|
|
179
|
+
};
|
|
172
180
|
this.ExtensionsImpl = this.EXTENSION_CLASS || new HttpServiceExtensions();
|
|
173
181
|
}
|
|
174
182
|
setAppConfig(myconfig) {
|
|
@@ -227,7 +235,7 @@ class HTTPService {
|
|
|
227
235
|
return httpCall.pipe(map((res) => {
|
|
228
236
|
let responseItem = res;
|
|
229
237
|
if (cachedInfos.cache) {
|
|
230
|
-
let toCache =
|
|
238
|
+
let toCache = JSON.parse(JSON.stringify(responseItem));
|
|
231
239
|
this.cacheResponse(toCache, cachedInfos);
|
|
232
240
|
this.log(this.loc("Cached result for") + " " + url);
|
|
233
241
|
}
|
|
@@ -699,7 +707,7 @@ class HTTPService {
|
|
|
699
707
|
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
700
708
|
return;
|
|
701
709
|
case 0:
|
|
702
|
-
finalError = `Generic connection error while calling '[${guid}] - ${this.callStatus[guid].url}' at ${
|
|
710
|
+
finalError = `Generic connection error while calling '[${guid}] - ${this.callStatus[guid].url}' at ${new Date().toISOString()}. Response: ${JSON.stringify(res)}`;
|
|
703
711
|
}
|
|
704
712
|
}
|
|
705
713
|
this.ExtensionsImpl.handleException(finalStatus, finalError);
|
|
@@ -793,7 +801,7 @@ class HTTPService {
|
|
|
793
801
|
let cacheKey = cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
794
802
|
let cacheLs = this.localStorage?.getLocalItem?.(cacheKey);
|
|
795
803
|
let cache = cacheLs ? cacheLs : {};
|
|
796
|
-
if (cache && cache[cachingKey] && !this.timedCacheItemExpired(cache[cachingKey])) {
|
|
804
|
+
if (cache && cache[cachingKey] && !this.timedCacheItemExpired(cache[cachingKey].__expire)) {
|
|
797
805
|
// Se gestisco il tempo esatto della cache prima di restituire l'oggetto cachato lo ripulisco
|
|
798
806
|
// dalle proprietà interne che gli ho aggiunto per controllarne la scadenza
|
|
799
807
|
if (cacheTime)
|
|
@@ -802,7 +810,7 @@ class HTTPService {
|
|
|
802
810
|
}
|
|
803
811
|
}
|
|
804
812
|
// Per assicurarmi che il rifeirmento degli oggetti sia diverso utilizzo il deepClone
|
|
805
|
-
let toCache =
|
|
813
|
+
let toCache = JSON.parse(JSON.stringify(item));
|
|
806
814
|
return new CacheInfos(url, useCaching && this.CacheInitialized, cachingKey, cacheTime, toCache);
|
|
807
815
|
}
|
|
808
816
|
/**
|
|
@@ -816,8 +824,11 @@ class HTTPService {
|
|
|
816
824
|
let cacheLs = this.localStorage?.getLocalItem?.(cacheKey);
|
|
817
825
|
let cache = cacheLs ? cacheLs : {};
|
|
818
826
|
cache[cacheInfos.cacheKey] = item;
|
|
819
|
-
if (cacheInfos.cacheTime)
|
|
820
|
-
|
|
827
|
+
if (cacheInfos.cacheTime) {
|
|
828
|
+
let date = new Date();
|
|
829
|
+
date.setSeconds(date.getSeconds() + parseInt(cacheInfos.cacheTime));
|
|
830
|
+
cache[cacheInfos.cacheKey].__expire = date;
|
|
831
|
+
}
|
|
821
832
|
this.localStorage?.setLocalItem?.(cacheKey, cache);
|
|
822
833
|
}
|
|
823
834
|
/**
|
|
@@ -827,7 +838,7 @@ class HTTPService {
|
|
|
827
838
|
*/
|
|
828
839
|
untimedCacheExpired() {
|
|
829
840
|
let expire = JSON.parse(localStorage.getItem(this.localStorageHttpCacheExpireKey));
|
|
830
|
-
return !expire || expire &&
|
|
841
|
+
return !expire || (expire && this.timedCacheItemExpired(expire));
|
|
831
842
|
}
|
|
832
843
|
/**
|
|
833
844
|
* Controlla se la cache per una chiamata che ha un tempo di vita ben definito è scaduta o meno
|
|
@@ -836,8 +847,8 @@ class HTTPService {
|
|
|
836
847
|
*
|
|
837
848
|
* @returns {boolean} **true** se la cache è scaduta e dev'essere ripulita, **false** altrimenti
|
|
838
849
|
*/
|
|
839
|
-
timedCacheItemExpired(
|
|
840
|
-
return
|
|
850
|
+
timedCacheItemExpired(dtCheck) {
|
|
851
|
+
return new Date(dtCheck) < new Date();
|
|
841
852
|
}
|
|
842
853
|
/**
|
|
843
854
|
* Ripulisce la cache e imposta la prossima scadenza ad adesso + **CLIENT_CACHE_DURATION_S** (token valorizzato in fase di configurazione dalla proprietà **clientCacheDurationS** della classe **HttpServiceModuleConfig**)
|
|
@@ -846,7 +857,9 @@ class HTTPService {
|
|
|
846
857
|
if (!this.CacheInitialized || !this.localStorage)
|
|
847
858
|
return;
|
|
848
859
|
await this.localStorage.setItem(this.localStorageHttpCacheKey, {}).toPromise();
|
|
849
|
-
|
|
860
|
+
let date = new Date();
|
|
861
|
+
date.setSeconds(date.getSeconds() + (this.CLIENT_CACHE_DURATION_S ?? 3600));
|
|
862
|
+
localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(date));
|
|
850
863
|
}
|
|
851
864
|
/**
|
|
852
865
|
* Ripulisce la cache delle chiamate con un tempo di expire definito
|
|
@@ -907,19 +920,22 @@ class HTTPService {
|
|
|
907
920
|
getAll(view, api, pars, transaction) {
|
|
908
921
|
if (!view.selection.all)
|
|
909
922
|
return of(view.selection.items);
|
|
910
|
-
|
|
911
|
-
throw "[@esfaenza/httpservice] to use getAll, you need a Hasing service. WTF are you doing? this should be configured by @esfaenza core";
|
|
912
|
-
var jsonView = this.utisExts ? this.utisExts.deepClone(view) : JSON.parse(JSON.stringify(view));
|
|
923
|
+
var jsonView = JSON.parse(JSON.stringify(view));
|
|
913
924
|
jsonView.page = 1;
|
|
914
925
|
jsonView.itemsperpageoverride = 999999;
|
|
915
926
|
return this.post(api, jsonView, pars, transaction).pipe(map(res => {
|
|
916
927
|
let items = res.items;
|
|
917
|
-
items.forEach(t => t.hash = this.
|
|
928
|
+
items.forEach(t => t.hash = this.hashObject(t));
|
|
918
929
|
if (res.selection.exclusions?.length > 0)
|
|
919
|
-
items = items.filter((t) => !res.selection.exclusions.find((e) => this.
|
|
930
|
+
items = items.filter((t) => !res.selection.exclusions.find((e) => this.hashObject(e) == t.hash));
|
|
920
931
|
return items;
|
|
921
932
|
}));
|
|
922
933
|
}
|
|
934
|
+
hashObject(o, level = 0) {
|
|
935
|
+
var strDef = this.stringify(o, level);
|
|
936
|
+
var hash = this.simpleHash(strDef);
|
|
937
|
+
return hash;
|
|
938
|
+
}
|
|
923
939
|
beginTransaction(executionKey, secondsTimeout) {
|
|
924
940
|
this.log("beginTransaction call received: " + executionKey);
|
|
925
941
|
var pars = new HttpParams().set("executionKey", executionKey);
|
|
@@ -936,10 +952,77 @@ class HTTPService {
|
|
|
936
952
|
let pars = new HttpParams().set("idtrans", transactionKey).set("success", transactionResult.toString());
|
|
937
953
|
return this.get(this.GET_Trans_EndTrans, pars);
|
|
938
954
|
}
|
|
939
|
-
|
|
940
|
-
|
|
955
|
+
/**
|
|
956
|
+
* Hash più semplice e più veloce dell'md5, ma meno sicuro
|
|
957
|
+
*
|
|
958
|
+
* Vedi https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
|
|
959
|
+
*
|
|
960
|
+
* @param {string} str Stringa di cui calcolare l'hash
|
|
961
|
+
*/
|
|
962
|
+
simpleHash(str, seed = 0) {
|
|
963
|
+
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
964
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
965
|
+
ch = str.charCodeAt(i);
|
|
966
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
967
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
968
|
+
}
|
|
969
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
970
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
971
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString();
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Genera una stringa che identifica univocamente l'oggetto in questione
|
|
975
|
+
*
|
|
976
|
+
* @param {any} o Oggetto di cui calcolare la stringa univoca
|
|
977
|
+
* @param {number} level Livello di ricorsione nel caso venga effettuato l'hash di un oggetto che contiene altri oggetti
|
|
978
|
+
* @param {boolean} navigateFullDepth Indica se navigare l'oggetto per l'intera lunghezza. In caso contrario si ferma al secondo livello
|
|
979
|
+
*/
|
|
980
|
+
stringify(o, level) {
|
|
981
|
+
var i, r;
|
|
982
|
+
if (o === null)
|
|
983
|
+
return "n";
|
|
984
|
+
if (o === true)
|
|
985
|
+
return "t";
|
|
986
|
+
if (o === false)
|
|
987
|
+
return "f";
|
|
988
|
+
if (o instanceof Date)
|
|
989
|
+
return 'd:' + o.valueOf().toString();
|
|
990
|
+
i = typeof o;
|
|
991
|
+
if (i === "string")
|
|
992
|
+
return "s:" + o;
|
|
993
|
+
if (i === "number")
|
|
994
|
+
return "n:" + o;
|
|
995
|
+
if (o instanceof Function)
|
|
996
|
+
return "m:" + o.toString();
|
|
997
|
+
if (o instanceof Array) {
|
|
998
|
+
r = [];
|
|
999
|
+
for (i = 0; i < o.length; i++) {
|
|
1000
|
+
let res = this.stringify(o[i], level);
|
|
1001
|
+
if (res)
|
|
1002
|
+
r.push(res);
|
|
1003
|
+
}
|
|
1004
|
+
return r.length > 0 ? "a:" + r.join(";") : "";
|
|
1005
|
+
}
|
|
1006
|
+
r = [];
|
|
1007
|
+
//Se è oggetto, escludo tutti quelli di sistema/inutili
|
|
1008
|
+
if (o) {
|
|
1009
|
+
var name = o.__proto__.constructor.name;
|
|
1010
|
+
if (!this.objBlacklist[name]) {
|
|
1011
|
+
for (i in o) {
|
|
1012
|
+
if (o.hasOwnProperty(i) && (level <= 2)) {
|
|
1013
|
+
let res = this.stringify(o[i], level + 1);
|
|
1014
|
+
if (res)
|
|
1015
|
+
r.push(i + ":" + res);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return r.length > 0 ? "o:" + r.join(";") : "";
|
|
1021
|
+
}
|
|
1022
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HTTPService, deps: [{ token: HttpServiceExtensions }, { token: HTTP_INVALIDATION, optional: true }, { token: CLIENT_CACHE_DURATION_S, optional: true }, { token: CACHE_BY_USER, optional: true }, { token: HTTP_DEBUG_MODE, optional: true }, { token: i2.BaseLocalization, optional: true }, { token: i3.HttpClient }, { token: i4.CacheService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1023
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HTTPService, providedIn: 'root' }); }
|
|
941
1024
|
}
|
|
942
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1025
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HTTPService, decorators: [{
|
|
943
1026
|
type: Injectable,
|
|
944
1027
|
args: [{ providedIn: 'root' }]
|
|
945
1028
|
}], ctorParameters: () => [{ type: HttpServiceExtensions }, { type: undefined, decorators: [{
|
|
@@ -966,10 +1049,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
|
|
|
966
1049
|
type: Optional
|
|
967
1050
|
}] }, { type: i3.HttpClient }, { type: i4.CacheService, decorators: [{
|
|
968
1051
|
type: Optional
|
|
969
|
-
}] }, { type: i5.HashingService, decorators: [{
|
|
970
|
-
type: Optional
|
|
971
|
-
}] }, { type: i5.UtilityService, decorators: [{
|
|
972
|
-
type: Optional
|
|
973
1052
|
}] }] });
|
|
974
1053
|
|
|
975
1054
|
class HttpserviceModule {
|
|
@@ -984,11 +1063,11 @@ class HttpserviceModule {
|
|
|
984
1063
|
]
|
|
985
1064
|
};
|
|
986
1065
|
}
|
|
987
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
988
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
989
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
1066
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HttpserviceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1067
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.2", ngImport: i0, type: HttpserviceModule }); }
|
|
1068
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HttpserviceModule }); }
|
|
990
1069
|
}
|
|
991
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1070
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: HttpserviceModule, decorators: [{
|
|
992
1071
|
type: NgModule
|
|
993
1072
|
}] });
|
|
994
1073
|
|