@esfaenza/httpservice 19.2.23 → 20.3.1
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 +53 -141
- package/fesm2022/esfaenza-httpservice.mjs.map +1 -1
- package/index.d.ts +567 -3
- package/package.json +6 -5
- 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 -405
- 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
|
@@ -2,10 +2,11 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { InjectionToken, Injectable, Optional, Inject, NgModule } from '@angular/core';
|
|
3
3
|
import * as i3 from '@angular/common/http';
|
|
4
4
|
import { HttpEventType, HttpHeaders, HttpErrorResponse, HttpParams } from '@angular/common/http';
|
|
5
|
-
import { first, concatMap, delay,
|
|
5
|
+
import { first, concatMap, delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
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';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Dizionario di invalidazioni delle chiamate HTTP
|
|
@@ -105,10 +106,10 @@ class HttpServiceExtensions {
|
|
|
105
106
|
handleException(status, text) {
|
|
106
107
|
console.error("ESHttpError " + status + " " + text);
|
|
107
108
|
}
|
|
108
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
109
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
109
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HttpServiceExtensions, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
110
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HttpServiceExtensions, providedIn: 'root' }); }
|
|
110
111
|
}
|
|
111
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
112
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HttpServiceExtensions, decorators: [{
|
|
112
113
|
type: Injectable,
|
|
113
114
|
args: [{ providedIn: 'root' }]
|
|
114
115
|
}] });
|
|
@@ -132,7 +133,7 @@ class HTTPService {
|
|
|
132
133
|
/**
|
|
133
134
|
* @ignore
|
|
134
135
|
*/
|
|
135
|
-
constructor(EXTENSION_CLASS, HTTP_INVALIDATION, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, HTTP_DEBUG_MODE, bc, http, localStorage) {
|
|
136
|
+
constructor(EXTENSION_CLASS, HTTP_INVALIDATION, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, HTTP_DEBUG_MODE, bc, http, localStorage, hash, utisExts) {
|
|
136
137
|
this.EXTENSION_CLASS = EXTENSION_CLASS;
|
|
137
138
|
this.HTTP_INVALIDATION = HTTP_INVALIDATION;
|
|
138
139
|
this.CLIENT_CACHE_DURATION_S = CLIENT_CACHE_DURATION_S;
|
|
@@ -141,6 +142,8 @@ class HTTPService {
|
|
|
141
142
|
this.bc = bc;
|
|
142
143
|
this.http = http;
|
|
143
144
|
this.localStorage = localStorage;
|
|
145
|
+
this.hash = hash;
|
|
146
|
+
this.utisExts = utisExts;
|
|
144
147
|
/** Cache dello stato delle chiamate HTTP attualmente effettuate. Ogni chiamata è rappresentata da un GUID e lo status assume valore **false** solo sugli errori */
|
|
145
148
|
this.callStatus = {};
|
|
146
149
|
/** Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary */
|
|
@@ -166,17 +169,6 @@ class HTTPService {
|
|
|
166
169
|
this.GET_Trans_BeginTrans = "/api/Trans/BeginTrans";
|
|
167
170
|
this.GET_Trans_CheckExecution = "/api/Trans/CheckExecution";
|
|
168
171
|
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
|
-
};
|
|
180
172
|
this.ExtensionsImpl = this.EXTENSION_CLASS || new HttpServiceExtensions();
|
|
181
173
|
}
|
|
182
174
|
setAppConfig(myconfig) {
|
|
@@ -229,13 +221,13 @@ class HTTPService {
|
|
|
229
221
|
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
230
222
|
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
231
223
|
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
232
|
-
return of(cachedInfos.cacheItem).pipe(delay(0),
|
|
224
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
233
225
|
}
|
|
234
226
|
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
235
227
|
return httpCall.pipe(map((res) => {
|
|
236
228
|
let responseItem = res;
|
|
237
229
|
if (cachedInfos.cache) {
|
|
238
|
-
let toCache = JSON.parse(JSON.stringify(responseItem));
|
|
230
|
+
let toCache = this.utisExts ? this.utisExts.deepClone(responseItem) : JSON.parse(JSON.stringify(responseItem));
|
|
239
231
|
this.cacheResponse(toCache, cachedInfos);
|
|
240
232
|
this.log(this.loc("Cached result for") + " " + url);
|
|
241
233
|
}
|
|
@@ -244,7 +236,7 @@ class HTTPService {
|
|
|
244
236
|
if (errorCallback)
|
|
245
237
|
errorCallback();
|
|
246
238
|
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
247
|
-
}),
|
|
239
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid, cachedInfos); }));
|
|
248
240
|
}));
|
|
249
241
|
}
|
|
250
242
|
/**
|
|
@@ -270,7 +262,7 @@ class HTTPService {
|
|
|
270
262
|
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
271
263
|
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
272
264
|
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
273
|
-
return of(cachedInfos.cacheItem).pipe(delay(0),
|
|
265
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
274
266
|
}
|
|
275
267
|
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
276
268
|
return httpCall.pipe(map((blob) => {
|
|
@@ -283,7 +275,7 @@ class HTTPService {
|
|
|
283
275
|
if (errorCallback)
|
|
284
276
|
errorCallback();
|
|
285
277
|
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
286
|
-
}),
|
|
278
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid, cachedInfos); }));
|
|
287
279
|
}));
|
|
288
280
|
}
|
|
289
281
|
/**
|
|
@@ -311,17 +303,7 @@ class HTTPService {
|
|
|
311
303
|
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
312
304
|
return httpCall.pipe(catchError((err, _) => {
|
|
313
305
|
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
314
|
-
}),
|
|
315
|
-
// Secco gli items dalle ricerche paginate lato richiesta
|
|
316
|
-
let request = JSON.parse(JSON.stringify(bodyData));
|
|
317
|
-
if (request.items && request.itemsperpageoverride)
|
|
318
|
-
delete request.items;
|
|
319
|
-
// Secco gli items dalle ricerche paginate lato risposta
|
|
320
|
-
let response = JSON.parse(JSON.stringify(res));
|
|
321
|
-
if (response.items && response.itemsperpageoverride)
|
|
322
|
-
delete response.items;
|
|
323
|
-
this.tryFinalizeByGuid(ret.myGuid, params?.toString() + (params?.toString() ? " § " : "") + JSON.stringify(request), JSON.stringify(response));
|
|
324
|
-
}));
|
|
306
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
325
307
|
}));
|
|
326
308
|
}
|
|
327
309
|
/**
|
|
@@ -341,9 +323,9 @@ class HTTPService {
|
|
|
341
323
|
locale: this.getlocaleObservable()
|
|
342
324
|
}).pipe(concatMap((ret) => {
|
|
343
325
|
var httpCall = this.http.delete(url, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
344
|
-
return httpCall.pipe(catchError((err,
|
|
326
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
345
327
|
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
346
|
-
}),
|
|
328
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
347
329
|
}));
|
|
348
330
|
}
|
|
349
331
|
/**
|
|
@@ -364,9 +346,9 @@ class HTTPService {
|
|
|
364
346
|
locale: this.getlocaleObservable()
|
|
365
347
|
}).pipe(concatMap((ret) => {
|
|
366
348
|
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
367
|
-
return httpCall.pipe(catchError((err,
|
|
349
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
368
350
|
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
369
|
-
}),
|
|
351
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
370
352
|
}));
|
|
371
353
|
}
|
|
372
354
|
/**
|
|
@@ -391,7 +373,7 @@ class HTTPService {
|
|
|
391
373
|
return httpCall.pipe(catchError((err, caught) => {
|
|
392
374
|
onError?.();
|
|
393
375
|
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
394
|
-
}),
|
|
376
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
395
377
|
}));
|
|
396
378
|
}
|
|
397
379
|
/**
|
|
@@ -410,11 +392,11 @@ class HTTPService {
|
|
|
410
392
|
async postGetFile(url, bodyData, filename, getFileCallback, afterGetFile = null, handleError = true, pars) {
|
|
411
393
|
let myGuid = this.defaultStartCall(url);
|
|
412
394
|
let locale = await this.getlocaleObservable().toPromise();
|
|
413
|
-
this.http.post(url, bodyData, { params: pars, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err,
|
|
395
|
+
this.http.post(url, bodyData, { params: pars, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
|
|
414
396
|
if (afterGetFile && !handleError)
|
|
415
397
|
afterGetFile();
|
|
416
398
|
return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
417
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid
|
|
399
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
|
|
418
400
|
let retUrl = window.URL.createObjectURL(response.body);
|
|
419
401
|
let fn = response.headers.get('content-disposition')?.split(';')[1]?.split('filename')[1]?.split('=')[1]?.trim().replace(/\"/g, '');
|
|
420
402
|
getFileCallback(retUrl, filename || fn);
|
|
@@ -438,11 +420,11 @@ class HTTPService {
|
|
|
438
420
|
async getFile(url, params = null, filename, getFileCallback, afterGetFile = null, handleError = true) {
|
|
439
421
|
let myGuid = this.defaultStartCall(url);
|
|
440
422
|
let locale = await this.getlocaleObservable().toPromise();
|
|
441
|
-
this.http.get(url, { params: params, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err,
|
|
423
|
+
this.http.get(url, { params: params, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
|
|
442
424
|
if (afterGetFile && !handleError)
|
|
443
425
|
afterGetFile();
|
|
444
426
|
return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
445
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid
|
|
427
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
|
|
446
428
|
let retUrl = window.URL.createObjectURL(response.body);
|
|
447
429
|
let fn = response.headers.get('content-disposition')?.split(';')[1]?.split('filename')[1]?.split('=')[1]?.trim().replace(/\"/g, '');
|
|
448
430
|
getFileCallback(retUrl, filename || fn);
|
|
@@ -462,7 +444,7 @@ class HTTPService {
|
|
|
462
444
|
// let parKeys = params.keys();
|
|
463
445
|
// for (let i = 0; i < parKeys.length; i++)
|
|
464
446
|
// encodedParams = encodedParams.set(parKeys[i], encodeURIComponent(params.get(parKeys[i])));
|
|
465
|
-
let finalUrl = url + (params ? "?" + params
|
|
447
|
+
let finalUrl = url + (params ? "?" + params.toString().replace(/\+/g, '%2b') : "");
|
|
466
448
|
window.location.href = finalUrl;
|
|
467
449
|
}
|
|
468
450
|
/**
|
|
@@ -498,7 +480,7 @@ class HTTPService {
|
|
|
498
480
|
return { progress: 100, state: 'DONE', content: event.body };
|
|
499
481
|
}
|
|
500
482
|
return previous;
|
|
501
|
-
}, { state: 'PENDING', progress: 0, content: null }), catchError((err, _) => { return this.registerErrorAndReturnEmptyObservable(err, ret.myGuid); }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid
|
|
483
|
+
}, { state: 'PENDING', progress: 0, content: null }), catchError((err, _) => { return this.registerErrorAndReturnEmptyObservable(err, ret.myGuid); }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
502
484
|
}));
|
|
503
485
|
}
|
|
504
486
|
/**
|
|
@@ -566,15 +548,16 @@ class HTTPService {
|
|
|
566
548
|
* @param {boolean} persistCacheIfIdle Effettua il persist della cache HTTP solo se non ci sono altre chiamate in corso, per evitare
|
|
567
549
|
* che mi cambi sotto l'oggetto di cache mentre sto salvando le informazioni
|
|
568
550
|
*/
|
|
569
|
-
async tryFinalizeByGuid(guid,
|
|
551
|
+
async tryFinalizeByGuid(guid, cacheInfos) {
|
|
570
552
|
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (!this.callStatus[guid] ? 'Unknown' : this.callStatus[guid].success ? this.loc('Success') : this.loc('Failure')));
|
|
553
|
+
// TODO: Perdere 3-4 ore per capire perché ogni tanto arriva null in casi pesanti di Observable spammati a random
|
|
571
554
|
if (this.callStatus[guid]) {
|
|
572
555
|
// Alla prima chiamata buona, significa che almeno il login ce l'ho. Posso mettermi in modalità redirectInProgress false
|
|
573
556
|
// e riiniziare a valutare errori di javashit
|
|
574
557
|
if (this.callStatus[guid].success && this.ExtensionsImpl.readRedirectionStatus())
|
|
575
558
|
this.ExtensionsImpl.writeRedirectionStatus(false);
|
|
576
559
|
// Aggiungo la chiamata alla lista delle ultime 3 completate
|
|
577
|
-
this.LastThreeCompletedCalls.unshift(
|
|
560
|
+
this.LastThreeCompletedCalls.unshift(this.callStatus[guid].url);
|
|
578
561
|
if (this.LastThreeCompletedCalls.length > 3)
|
|
579
562
|
this.LastThreeCompletedCalls.pop();
|
|
580
563
|
// In ogni caso questa posso rimuoverla
|
|
@@ -716,7 +699,7 @@ class HTTPService {
|
|
|
716
699
|
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
717
700
|
return;
|
|
718
701
|
case 0:
|
|
719
|
-
finalError = `Generic connection error while calling '[${guid}] - ${this.callStatus[guid].url}' at ${
|
|
702
|
+
finalError = `Generic connection error while calling '[${guid}] - ${this.callStatus[guid].url}' at ${dayjs().format()}. Response: ${JSON.stringify(res)}`;
|
|
720
703
|
}
|
|
721
704
|
}
|
|
722
705
|
this.ExtensionsImpl.handleException(finalStatus, finalError);
|
|
@@ -810,7 +793,7 @@ class HTTPService {
|
|
|
810
793
|
let cacheKey = cacheTime ? this.localStorageHttpTimedCacheKey : this.localStorageHttpCacheKey;
|
|
811
794
|
let cacheLs = this.localStorage?.getLocalItem?.(cacheKey);
|
|
812
795
|
let cache = cacheLs ? cacheLs : {};
|
|
813
|
-
if (cache && cache[cachingKey] && !this.timedCacheItemExpired(cache[cachingKey]
|
|
796
|
+
if (cache && cache[cachingKey] && !this.timedCacheItemExpired(cache[cachingKey])) {
|
|
814
797
|
// Se gestisco il tempo esatto della cache prima di restituire l'oggetto cachato lo ripulisco
|
|
815
798
|
// dalle proprietà interne che gli ho aggiunto per controllarne la scadenza
|
|
816
799
|
if (cacheTime)
|
|
@@ -819,7 +802,7 @@ class HTTPService {
|
|
|
819
802
|
}
|
|
820
803
|
}
|
|
821
804
|
// Per assicurarmi che il rifeirmento degli oggetti sia diverso utilizzo il deepClone
|
|
822
|
-
let toCache = JSON.parse(JSON.stringify(item));
|
|
805
|
+
let toCache = this.utisExts ? this.utisExts.deepClone(item) : JSON.parse(JSON.stringify(item));
|
|
823
806
|
return new CacheInfos(url, useCaching && this.CacheInitialized, cachingKey, cacheTime, toCache);
|
|
824
807
|
}
|
|
825
808
|
/**
|
|
@@ -833,11 +816,8 @@ class HTTPService {
|
|
|
833
816
|
let cacheLs = this.localStorage?.getLocalItem?.(cacheKey);
|
|
834
817
|
let cache = cacheLs ? cacheLs : {};
|
|
835
818
|
cache[cacheInfos.cacheKey] = item;
|
|
836
|
-
if (cacheInfos.cacheTime)
|
|
837
|
-
|
|
838
|
-
date.setSeconds(date.getSeconds() + parseInt(cacheInfos.cacheTime));
|
|
839
|
-
cache[cacheInfos.cacheKey].__expire = date;
|
|
840
|
-
}
|
|
819
|
+
if (cacheInfos.cacheTime)
|
|
820
|
+
cache[cacheInfos.cacheKey].__expire = dayjs().add(cacheInfos.cacheTime, "seconds");
|
|
841
821
|
this.localStorage?.setLocalItem?.(cacheKey, cache);
|
|
842
822
|
}
|
|
843
823
|
/**
|
|
@@ -847,7 +827,7 @@ class HTTPService {
|
|
|
847
827
|
*/
|
|
848
828
|
untimedCacheExpired() {
|
|
849
829
|
let expire = JSON.parse(localStorage.getItem(this.localStorageHttpCacheExpireKey));
|
|
850
|
-
return !expire ||
|
|
830
|
+
return !expire || expire && dayjs(expire) < dayjs();
|
|
851
831
|
}
|
|
852
832
|
/**
|
|
853
833
|
* Controlla se la cache per una chiamata che ha un tempo di vita ben definito è scaduta o meno
|
|
@@ -856,8 +836,8 @@ class HTTPService {
|
|
|
856
836
|
*
|
|
857
837
|
* @returns {boolean} **true** se la cache è scaduta e dev'essere ripulita, **false** altrimenti
|
|
858
838
|
*/
|
|
859
|
-
timedCacheItemExpired(
|
|
860
|
-
return
|
|
839
|
+
timedCacheItemExpired(item) {
|
|
840
|
+
return dayjs(item.__expire) < dayjs();
|
|
861
841
|
}
|
|
862
842
|
/**
|
|
863
843
|
* 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**)
|
|
@@ -866,9 +846,7 @@ class HTTPService {
|
|
|
866
846
|
if (!this.CacheInitialized || !this.localStorage)
|
|
867
847
|
return;
|
|
868
848
|
await this.localStorage.setItem(this.localStorageHttpCacheKey, {}).toPromise();
|
|
869
|
-
|
|
870
|
-
date.setSeconds(date.getSeconds() + (this.CLIENT_CACHE_DURATION_S ?? 3600));
|
|
871
|
-
localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(date));
|
|
849
|
+
localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(dayjs().add(this.CLIENT_CACHE_DURATION_S ?? 3600, "second")));
|
|
872
850
|
}
|
|
873
851
|
/**
|
|
874
852
|
* Ripulisce la cache delle chiamate con un tempo di expire definito
|
|
@@ -929,22 +907,19 @@ class HTTPService {
|
|
|
929
907
|
getAll(view, api, pars, transaction) {
|
|
930
908
|
if (!view.selection.all)
|
|
931
909
|
return of(view.selection.items);
|
|
932
|
-
|
|
910
|
+
if (!this.hash)
|
|
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));
|
|
933
913
|
jsonView.page = 1;
|
|
934
914
|
jsonView.itemsperpageoverride = 999999;
|
|
935
915
|
return this.post(api, jsonView, pars, transaction).pipe(map(res => {
|
|
936
916
|
let items = res.items;
|
|
937
|
-
items.forEach(t => t.hash = this.hashObject(t));
|
|
917
|
+
items.forEach(t => t.hash = this.hash.hashObject(t, null, false));
|
|
938
918
|
if (res.selection.exclusions?.length > 0)
|
|
939
|
-
items = items.filter((t) => !res.selection.exclusions.find((e) => this.hashObject(e) == t.hash));
|
|
919
|
+
items = items.filter((t) => !res.selection.exclusions.find((e) => this.hash.hashObject(e, null, false) == t.hash));
|
|
940
920
|
return items;
|
|
941
921
|
}));
|
|
942
922
|
}
|
|
943
|
-
hashObject(o, level = 0) {
|
|
944
|
-
var strDef = this.stringify(o, level);
|
|
945
|
-
var hash = this.simpleHash(strDef);
|
|
946
|
-
return hash;
|
|
947
|
-
}
|
|
948
923
|
beginTransaction(executionKey, secondsTimeout) {
|
|
949
924
|
this.log("beginTransaction call received: " + executionKey);
|
|
950
925
|
var pars = new HttpParams().set("executionKey", executionKey);
|
|
@@ -961,77 +936,10 @@ class HTTPService {
|
|
|
961
936
|
let pars = new HttpParams().set("idtrans", transactionKey).set("success", transactionResult.toString());
|
|
962
937
|
return this.get(this.GET_Trans_EndTrans, pars);
|
|
963
938
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
*
|
|
967
|
-
* Vedi https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
|
|
968
|
-
*
|
|
969
|
-
* @param {string} str Stringa di cui calcolare l'hash
|
|
970
|
-
*/
|
|
971
|
-
simpleHash(str, seed = 0) {
|
|
972
|
-
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
973
|
-
for (let i = 0, ch; i < str.length; i++) {
|
|
974
|
-
ch = str.charCodeAt(i);
|
|
975
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
976
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
977
|
-
}
|
|
978
|
-
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
979
|
-
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
980
|
-
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString();
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Genera una stringa che identifica univocamente l'oggetto in questione
|
|
984
|
-
*
|
|
985
|
-
* @param {any} o Oggetto di cui calcolare la stringa univoca
|
|
986
|
-
* @param {number} level Livello di ricorsione nel caso venga effettuato l'hash di un oggetto che contiene altri oggetti
|
|
987
|
-
* @param {boolean} navigateFullDepth Indica se navigare l'oggetto per l'intera lunghezza. In caso contrario si ferma al secondo livello
|
|
988
|
-
*/
|
|
989
|
-
stringify(o, level) {
|
|
990
|
-
var i, r;
|
|
991
|
-
if (o === null)
|
|
992
|
-
return "n";
|
|
993
|
-
if (o === true)
|
|
994
|
-
return "t";
|
|
995
|
-
if (o === false)
|
|
996
|
-
return "f";
|
|
997
|
-
if (o instanceof Date)
|
|
998
|
-
return 'd:' + o.valueOf().toString();
|
|
999
|
-
i = typeof o;
|
|
1000
|
-
if (i === "string")
|
|
1001
|
-
return "s:" + o;
|
|
1002
|
-
if (i === "number")
|
|
1003
|
-
return "n:" + o;
|
|
1004
|
-
if (o instanceof Function)
|
|
1005
|
-
return "m:" + o.toString();
|
|
1006
|
-
if (o instanceof Array) {
|
|
1007
|
-
r = [];
|
|
1008
|
-
for (i = 0; i < o.length; i++) {
|
|
1009
|
-
let res = this.stringify(o[i], level);
|
|
1010
|
-
if (res)
|
|
1011
|
-
r.push(res);
|
|
1012
|
-
}
|
|
1013
|
-
return r.length > 0 ? "a:" + r.join(";") : "";
|
|
1014
|
-
}
|
|
1015
|
-
r = [];
|
|
1016
|
-
//Se è oggetto, escludo tutti quelli di sistema/inutili
|
|
1017
|
-
if (o) {
|
|
1018
|
-
var name = o.__proto__.constructor.name;
|
|
1019
|
-
if (!this.objBlacklist[name]) {
|
|
1020
|
-
for (i in o) {
|
|
1021
|
-
if (o.hasOwnProperty(i) && (level <= 2)) {
|
|
1022
|
-
let res = this.stringify(o[i], level + 1);
|
|
1023
|
-
if (res)
|
|
1024
|
-
r.push(i + ":" + res);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
return r.length > 0 ? "o:" + r.join(";") : "";
|
|
1030
|
-
}
|
|
1031
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", 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 }); }
|
|
1032
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: HTTPService, providedIn: 'root' }); }
|
|
939
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", 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 }, { token: i5.HashingService, optional: true }, { token: i5.UtilityService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
940
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HTTPService, providedIn: 'root' }); }
|
|
1033
941
|
}
|
|
1034
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
942
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HTTPService, decorators: [{
|
|
1035
943
|
type: Injectable,
|
|
1036
944
|
args: [{ providedIn: 'root' }]
|
|
1037
945
|
}], ctorParameters: () => [{ type: HttpServiceExtensions }, { type: undefined, decorators: [{
|
|
@@ -1058,6 +966,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
|
|
|
1058
966
|
type: Optional
|
|
1059
967
|
}] }, { type: i3.HttpClient }, { type: i4.CacheService, decorators: [{
|
|
1060
968
|
type: Optional
|
|
969
|
+
}] }, { type: i5.HashingService, decorators: [{
|
|
970
|
+
type: Optional
|
|
971
|
+
}] }, { type: i5.UtilityService, decorators: [{
|
|
972
|
+
type: Optional
|
|
1061
973
|
}] }] });
|
|
1062
974
|
|
|
1063
975
|
class HttpserviceModule {
|
|
@@ -1072,11 +984,11 @@ class HttpserviceModule {
|
|
|
1072
984
|
]
|
|
1073
985
|
};
|
|
1074
986
|
}
|
|
1075
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1076
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
1077
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
987
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HttpserviceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
988
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.13", ngImport: i0, type: HttpserviceModule }); }
|
|
989
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HttpserviceModule }); }
|
|
1078
990
|
}
|
|
1079
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
991
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: HttpserviceModule, decorators: [{
|
|
1080
992
|
type: NgModule
|
|
1081
993
|
}] });
|
|
1082
994
|
|