@esfaenza/httpservice 13.3.0 → 14.2.0
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/esm2020/lib/httpservice.module.mjs +5 -5
- package/esm2020/lib/httpservice.service.mjs +89 -85
- package/fesm2015/esfaenza-httpservice.mjs +92 -88
- package/fesm2015/esfaenza-httpservice.mjs.map +1 -1
- package/fesm2020/esfaenza-httpservice.mjs +92 -88
- package/fesm2020/esfaenza-httpservice.mjs.map +1 -1
- package/{esfaenza-httpservice.d.ts → index.d.ts} +0 -0
- package/lib/httpservice.service.d.ts +5 -3
- package/package.json +7 -6
|
@@ -3,9 +3,10 @@ import * as i2 from '@angular/common/http';
|
|
|
3
3
|
import { HttpEventType, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
|
|
4
4
|
import * as i0 from '@angular/core';
|
|
5
5
|
import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
|
6
|
-
import { delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
7
|
-
import { forkJoin, of, throwError, Observable } from 'rxjs';
|
|
6
|
+
import { concatMap, delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
7
|
+
import { forkJoin, from, of, throwError, Observable } from 'rxjs';
|
|
8
8
|
import * as i3 from '@esfaenza/preferences';
|
|
9
|
+
import * as i4 from '@esfaenza/extensions';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Dizionario di invalidazioni delle chiamate HTTP
|
|
@@ -161,7 +162,7 @@ class HTTPService {
|
|
|
161
162
|
/**
|
|
162
163
|
* @ignore
|
|
163
164
|
*/
|
|
164
|
-
constructor(BACKEND_URL, EXTENSION_CLASS, HTTP_INVALIDATION, LOCALE, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, http, localStorage) {
|
|
165
|
+
constructor(BACKEND_URL, EXTENSION_CLASS, HTTP_INVALIDATION, LOCALE, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, http, localStorage, utisExts) {
|
|
165
166
|
var _a, _b;
|
|
166
167
|
this.BACKEND_URL = BACKEND_URL;
|
|
167
168
|
this.EXTENSION_CLASS = EXTENSION_CLASS;
|
|
@@ -173,6 +174,7 @@ class HTTPService {
|
|
|
173
174
|
this.DEBUG_MODE = DEBUG_MODE;
|
|
174
175
|
this.http = http;
|
|
175
176
|
this.localStorage = localStorage;
|
|
177
|
+
this.utisExts = utisExts;
|
|
176
178
|
/** Cache dello stato delle chiamate HTTP attualmente effettuate. Ogni chiamata è rappresentata da un GUID e lo status assume valore **false** solo sugli errori */
|
|
177
179
|
this.callStatus = {};
|
|
178
180
|
/** Nome della cache in cui vengono storicizzate le informazioni sulle risposte delle chiamate sotto forma di dictionary */
|
|
@@ -232,25 +234,27 @@ class HTTPService {
|
|
|
232
234
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
233
235
|
*/
|
|
234
236
|
get(url, params = null, transaction = "", succesfulResultMandatory = true, errorCallback = null) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
|
|
242
|
-
return httpCall.pipe(map((res) => {
|
|
243
|
-
let responseItem = res;
|
|
244
|
-
if (cachedInfos.cache) {
|
|
245
|
-
this.cacheResponse(responseItem, cachedInfos);
|
|
246
|
-
this.log(this.loc("Cached result for") + " " + url);
|
|
237
|
+
// TODO provare e testare
|
|
238
|
+
return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
|
|
239
|
+
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
240
|
+
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
241
|
+
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
242
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
247
243
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
244
|
+
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
|
|
245
|
+
return httpCall.pipe(map((res) => {
|
|
246
|
+
let responseItem = res;
|
|
247
|
+
if (cachedInfos.cache) {
|
|
248
|
+
this.cacheResponse(this.utisExts.deepClone(responseItem), cachedInfos);
|
|
249
|
+
this.log(this.loc("Cached result for") + " " + url);
|
|
250
|
+
}
|
|
251
|
+
return responseItem;
|
|
252
|
+
}), catchError((err, caught) => {
|
|
253
|
+
if (errorCallback)
|
|
254
|
+
errorCallback();
|
|
255
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
256
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
257
|
+
}));
|
|
254
258
|
}
|
|
255
259
|
/**
|
|
256
260
|
* Esecuzione di una GET HTTP con eventualmente la gestione della cache qualora la chiamata termini con la convenzione "#cache"
|
|
@@ -268,24 +272,25 @@ class HTTPService {
|
|
|
268
272
|
* @returns {Observable<Blob | ArrayBuffer>} Observable che contiene il risultato della chiamata
|
|
269
273
|
*/
|
|
270
274
|
getRaw(url, params = null, type = "arraybuffer", transaction = "", succesfulResultMandatory = true, errorCallback = null) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
|
|
278
|
-
return httpCall.pipe(map((blob) => {
|
|
279
|
-
if (cachedInfos.cache) {
|
|
280
|
-
this.cacheResponse(blob, cachedInfos);
|
|
281
|
-
this.log(this.loc("Cached result for") + " " + url);
|
|
275
|
+
return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
|
|
276
|
+
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
277
|
+
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
278
|
+
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
279
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
282
280
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
281
|
+
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
|
|
282
|
+
return httpCall.pipe(map((blob) => {
|
|
283
|
+
if (cachedInfos.cache) {
|
|
284
|
+
this.cacheResponse(blob, cachedInfos);
|
|
285
|
+
this.log(this.loc("Cached result for") + " " + url);
|
|
286
|
+
}
|
|
287
|
+
return blob;
|
|
288
|
+
}), catchError((err, caught) => {
|
|
289
|
+
if (errorCallback)
|
|
290
|
+
errorCallback();
|
|
291
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
292
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
293
|
+
}));
|
|
289
294
|
}
|
|
290
295
|
/**
|
|
291
296
|
* Esecuzione di una POST HTTP
|
|
@@ -300,14 +305,12 @@ class HTTPService {
|
|
|
300
305
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
301
306
|
*/
|
|
302
307
|
post(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
})
|
|
309
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
310
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
308
|
+
return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
|
|
309
|
+
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
310
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
311
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
312
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
313
|
+
}));
|
|
311
314
|
}
|
|
312
315
|
/**
|
|
313
316
|
* Esecuzione di una DELETE HTTP
|
|
@@ -321,14 +324,12 @@ class HTTPService {
|
|
|
321
324
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
322
325
|
*/
|
|
323
326
|
delete(url, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
})
|
|
330
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
331
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
327
|
+
return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
|
|
328
|
+
var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
|
|
329
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
330
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
331
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
332
|
+
}));
|
|
332
333
|
}
|
|
333
334
|
/**
|
|
334
335
|
* Esecuzione di una PUT HTTP
|
|
@@ -343,14 +344,12 @@ class HTTPService {
|
|
|
343
344
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
344
345
|
*/
|
|
345
346
|
put(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
})
|
|
352
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
353
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
347
|
+
return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
|
|
348
|
+
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
349
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
350
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
351
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
352
|
+
}));
|
|
354
353
|
}
|
|
355
354
|
/**
|
|
356
355
|
* Esecuzione di una POST HTTP
|
|
@@ -364,11 +363,12 @@ class HTTPService {
|
|
|
364
363
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
365
364
|
*/
|
|
366
365
|
postwithFiles(url, bodyData, fileArrayOrFile) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
366
|
+
return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
|
|
367
|
+
var formData = this.getFilesFormData(fileArrayOrFile);
|
|
368
|
+
formData.append("body", JSON.stringify(bodyData));
|
|
369
|
+
var httpCall = this.http.post(url, formData, { headers: this.getHeaders(null, true, null, null) });
|
|
370
|
+
return httpCall.pipe(catchError((err, caught) => { return this.registerErrorAndReturnEmptyObservable(err, myGuid); }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
371
|
+
}));
|
|
372
372
|
}
|
|
373
373
|
/**
|
|
374
374
|
* Esecuzione di una POST HTTP
|
|
@@ -532,17 +532,20 @@ class HTTPService {
|
|
|
532
532
|
*/
|
|
533
533
|
tryFinalizeByGuid(guid, cacheInfos) {
|
|
534
534
|
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
-
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (this.callStatus[guid].success ? this.loc('Success') : this.loc('Failure')));
|
|
536
|
-
//
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
this.LastThreeCompletedCalls.
|
|
544
|
-
|
|
545
|
-
|
|
535
|
+
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')));
|
|
536
|
+
// TODO: Perdere 3-4 ore per capire perché ogni tanto arriva null in casi pesanti di Observable spammati a random
|
|
537
|
+
if (this.callStatus[guid]) {
|
|
538
|
+
// Alla prima chiamata buona, significa che almeno il login ce l'ho. Posso mettermi in modalità redirectInProgress false
|
|
539
|
+
// e riiniziare a valutare errori di javashit
|
|
540
|
+
if (this.callStatus[guid].success && this.ExtensionsImpl.readRedirectionStatus())
|
|
541
|
+
this.ExtensionsImpl.writeRedirectionStatus(false);
|
|
542
|
+
// Aggiungo la chiamata alla lista delle ultime 3 completate
|
|
543
|
+
this.LastThreeCompletedCalls.unshift(this.callStatus[guid].url);
|
|
544
|
+
if (this.LastThreeCompletedCalls.length > 3)
|
|
545
|
+
this.LastThreeCompletedCalls.pop();
|
|
546
|
+
// In ogni caso questa posso rimuoverla
|
|
547
|
+
delete this.callStatus[guid];
|
|
548
|
+
}
|
|
546
549
|
// Se vengo da una chiamata che ha aggiornato la cache a timer o globale marco il fatto che quella cache dev'essere aggiornata
|
|
547
550
|
if (cacheInfos && cacheInfos.cache) {
|
|
548
551
|
this.PersistTimedCacheASAP = this.PersistTimedCacheASAP || !!cacheInfos.cacheTime;
|
|
@@ -762,7 +765,7 @@ class HTTPService {
|
|
|
762
765
|
* @returns {CacheInfos} Oggetto contenente le informazioni sulla cache per l'oggetto specificato
|
|
763
766
|
*/
|
|
764
767
|
tryGetCacheInformations(url, params) {
|
|
765
|
-
let cachingKey = null, cacheTime = null,
|
|
768
|
+
let cachingKey = null, cacheTime = null, item = null;
|
|
766
769
|
let useCaching = !!(/#cache/gi.exec(url));
|
|
767
770
|
if (useCaching) {
|
|
768
771
|
let tmp = /#cache(:?-(\d+))/gi.exec(url);
|
|
@@ -782,7 +785,8 @@ class HTTPService {
|
|
|
782
785
|
item = cache[cachingKey];
|
|
783
786
|
}
|
|
784
787
|
}
|
|
785
|
-
|
|
788
|
+
// Per assicurarmi che il rifeirmento degli oggetti sia diverso utilizzo il deepClone
|
|
789
|
+
return new CacheInfos(url, useCaching, cachingKey, cacheTime, this.utisExts.deepClone(item));
|
|
786
790
|
}
|
|
787
791
|
/**
|
|
788
792
|
* Inserisce un oggetto nella cache appropriata in base alle informazioni contenute nel parametro **cacheInfos**
|
|
@@ -884,9 +888,9 @@ class HTTPService {
|
|
|
884
888
|
return Loc[message][this.LOCALE];
|
|
885
889
|
}
|
|
886
890
|
}
|
|
887
|
-
HTTPService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
888
|
-
HTTPService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
889
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
891
|
+
HTTPService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: HTTPService, deps: [{ token: BACKEND_URL }, { token: HttpServiceExtensions }, { token: HTTP_INVALIDATION, optional: true }, { token: HTTP_LOCALE, optional: true }, { token: APP_NAME, optional: true }, { token: CLIENT_CACHE_DURATION_S, optional: true }, { token: CACHE_BY_USER, optional: true }, { token: DEBUG_MODE, optional: true }, { token: i2.HttpClient }, { token: i3.CacheService }, { token: i4.UtilityService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
892
|
+
HTTPService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: HTTPService });
|
|
893
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: HTTPService, decorators: [{
|
|
890
894
|
type: Injectable
|
|
891
895
|
}], ctorParameters: function () {
|
|
892
896
|
return [{ type: undefined, decorators: [{
|
|
@@ -922,7 +926,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.9", ngImpor
|
|
|
922
926
|
}, {
|
|
923
927
|
type: Inject,
|
|
924
928
|
args: [DEBUG_MODE]
|
|
925
|
-
}] }, { type: i2.HttpClient }, { type: i3.
|
|
929
|
+
}] }, { type: i2.HttpClient }, { type: i3.CacheService }, { type: i4.UtilityService }];
|
|
926
930
|
} });
|
|
927
931
|
|
|
928
932
|
class HttpserviceModule {
|
|
@@ -943,10 +947,10 @@ class HttpserviceModule {
|
|
|
943
947
|
};
|
|
944
948
|
}
|
|
945
949
|
}
|
|
946
|
-
HttpserviceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
947
|
-
HttpserviceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
948
|
-
HttpserviceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
949
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
950
|
+
HttpserviceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: HttpserviceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
951
|
+
HttpserviceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: HttpserviceModule });
|
|
952
|
+
HttpserviceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: HttpserviceModule });
|
|
953
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: HttpserviceModule, decorators: [{
|
|
950
954
|
type: NgModule
|
|
951
955
|
}] });
|
|
952
956
|
|