@esfaenza/httpservice 15.2.3 → 15.2.4
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/config/HttpServiceExtensions.mjs +9 -1
- package/esm2020/lib/config/HttpServiceModuleConfig.mjs +1 -1
- package/esm2020/lib/httpservice.module.mjs +2 -7
- package/esm2020/lib/httpservice.service.mjs +88 -72
- package/esm2020/lib/tokens.mjs +1 -5
- package/fesm2015/esfaenza-httpservice.mjs +117 -126
- package/fesm2015/esfaenza-httpservice.mjs.map +1 -1
- package/fesm2020/esfaenza-httpservice.mjs +93 -105
- package/fesm2020/esfaenza-httpservice.mjs.map +1 -1
- package/lib/config/HttpServiceExtensions.d.ts +3 -0
- package/lib/config/HttpServiceModuleConfig.d.ts +0 -4
- package/lib/httpservice.service.d.ts +6 -5
- package/lib/tokens.d.ts +0 -4
- package/package.json +2 -1
- package/esm2020/lib/httpservice.service.loc.mjs +0 -28
- package/lib/httpservice.service.loc.d.ts +0 -93
package/esm2020/lib/tokens.mjs
CHANGED
|
@@ -7,10 +7,6 @@ export const HTTP_INVALIDATION = new InjectionToken('HTTP_INVALIDATION');
|
|
|
7
7
|
* Durata della cache lato libreria dopo il quale la cache verrà ripulita
|
|
8
8
|
*/
|
|
9
9
|
export const CLIENT_CACHE_DURATION_S = new InjectionToken('CLIENT_CACHE_DURATION_S');
|
|
10
|
-
/**
|
|
11
|
-
* Locale della libreria per messaggi d'errore ed Header di default "Accept-Language". Sono supportati "it-IT" ed "en-US"
|
|
12
|
-
*/
|
|
13
|
-
export const HTTP_LOCALE = new InjectionToken('HTTP_LOCALE');
|
|
14
10
|
/**
|
|
15
11
|
* Nome dell'APP utilizzato per creare le chiavi delle cache specifiche per l'applicazione corrente
|
|
16
12
|
*/
|
|
@@ -23,4 +19,4 @@ export const CACHE_BY_USER = new InjectionToken('CACHE_BY_USER');
|
|
|
23
19
|
* Indica se fare log nella console ad ogni azione significativa
|
|
24
20
|
*/
|
|
25
21
|
export const DEBUG_MODE = new InjectionToken('DEBUG_MODE');
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
22
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9rZW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvaHR0cHNlcnZpY2Uvc3JjL2xpYi90b2tlbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUUvQzs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLGlCQUFpQixHQUE2QyxJQUFJLGNBQWMsQ0FBMkIsbUJBQW1CLENBQUMsQ0FBQztBQUU3STs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLHVCQUF1QixHQUEyQixJQUFJLGNBQWMsQ0FBUyx5QkFBeUIsQ0FBQyxDQUFDO0FBRXJIOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sUUFBUSxHQUEyQixJQUFJLGNBQWMsQ0FBUyxVQUFVLENBQUMsQ0FBQztBQUV2Rjs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLGFBQWEsR0FBNEIsSUFBSSxjQUFjLENBQVUsZUFBZSxDQUFDLENBQUM7QUFFbkc7O0dBRUc7QUFDSCxNQUFNLENBQUMsTUFBTSxVQUFVLEdBQTRCLElBQUksY0FBYyxDQUFVLFlBQVksQ0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgSW5qZWN0aW9uVG9rZW4gfSBmcm9tICdAYW5ndWxhci9jb3JlJztcclxuXHJcbi8qKlxyXG4gKiBEaXppb25hcmlvIGRpIGludmFsaWRhemlvbmkgZGVsbGUgY2hpYW1hdGUgSFRUUFxyXG4gKi9cclxuZXhwb3J0IGNvbnN0IEhUVFBfSU5WQUxJREFUSU9OOiBJbmplY3Rpb25Ub2tlbjxSZWNvcmQ8c3RyaW5nLCBzdHJpbmdbXT4+ID0gbmV3IEluamVjdGlvblRva2VuPFJlY29yZDxzdHJpbmcsIHN0cmluZ1tdPj4oJ0hUVFBfSU5WQUxJREFUSU9OJyk7XHJcblxyXG4vKipcclxuICogRHVyYXRhIGRlbGxhIGNhY2hlIGxhdG8gbGlicmVyaWEgZG9wbyBpbCBxdWFsZSBsYSBjYWNoZSB2ZXJyw6AgcmlwdWxpdGFcclxuICovXHJcbmV4cG9ydCBjb25zdCBDTElFTlRfQ0FDSEVfRFVSQVRJT05fUzogSW5qZWN0aW9uVG9rZW48bnVtYmVyPiA9IG5ldyBJbmplY3Rpb25Ub2tlbjxudW1iZXI+KCdDTElFTlRfQ0FDSEVfRFVSQVRJT05fUycpO1xyXG5cclxuLyoqXHJcbiAqIE5vbWUgZGVsbCdBUFAgdXRpbGl6emF0byBwZXIgY3JlYXJlIGxlIGNoaWF2aSBkZWxsZSBjYWNoZSBzcGVjaWZpY2hlIHBlciBsJ2FwcGxpY2F6aW9uZSBjb3JyZW50ZVxyXG4gKi9cclxuZXhwb3J0IGNvbnN0IEFQUF9OQU1FOiBJbmplY3Rpb25Ub2tlbjxzdHJpbmc+ID0gbmV3IEluamVjdGlvblRva2VuPHN0cmluZz4oJ0FQUF9OQU1FJyk7XHJcblxyXG4vKipcclxuICogSW5kaWNhIHNlIHV0aWxpenphcmUgbCdpZGVudGlmaWNhdGl2byB1dGVudGUgbmVsbGEgY2FjaGVcclxuICovXHJcbmV4cG9ydCBjb25zdCBDQUNIRV9CWV9VU0VSOiBJbmplY3Rpb25Ub2tlbjxib29sZWFuPiA9IG5ldyBJbmplY3Rpb25Ub2tlbjxib29sZWFuPignQ0FDSEVfQllfVVNFUicpO1xyXG5cclxuLyoqXHJcbiAqIEluZGljYSBzZSBmYXJlIGxvZyBuZWxsYSBjb25zb2xlIGFkIG9nbmkgYXppb25lIHNpZ25pZmljYXRpdmFcclxuICovXHJcbmV4cG9ydCBjb25zdCBERUJVR19NT0RFOiBJbmplY3Rpb25Ub2tlbjxib29sZWFuPiA9IG5ldyBJbmplY3Rpb25Ub2tlbjxib29sZWFuPignREVCVUdfTU9ERScpOyJdfQ==
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import * as
|
|
2
|
+
import * as i3 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, Optional, Inject, NgModule } from '@angular/core';
|
|
6
|
-
import { concatMap, delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
6
|
+
import { concatMap, delay, finalize, map, catchError, first, scan } from 'rxjs/operators';
|
|
7
7
|
import { forkJoin, from, of, throwError, Observable } from 'rxjs';
|
|
8
|
-
import * as
|
|
9
|
-
import * as i4 from '@esfaenza/
|
|
8
|
+
import * as i2 from '@esfaenza/localizations';
|
|
9
|
+
import * as i4 from '@esfaenza/preferences';
|
|
10
|
+
import * as i5 from '@esfaenza/extensions';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Dizionario di invalidazioni delle chiamate HTTP
|
|
@@ -16,10 +17,6 @@ const HTTP_INVALIDATION = new InjectionToken('HTTP_INVALIDATION');
|
|
|
16
17
|
* Durata della cache lato libreria dopo il quale la cache verrà ripulita
|
|
17
18
|
*/
|
|
18
19
|
const CLIENT_CACHE_DURATION_S = new InjectionToken('CLIENT_CACHE_DURATION_S');
|
|
19
|
-
/**
|
|
20
|
-
* Locale della libreria per messaggi d'errore ed Header di default "Accept-Language". Sono supportati "it-IT" ed "en-US"
|
|
21
|
-
*/
|
|
22
|
-
const HTTP_LOCALE = new InjectionToken('HTTP_LOCALE');
|
|
23
20
|
/**
|
|
24
21
|
* Nome dell'APP utilizzato per creare le chiavi delle cache specifiche per l'applicazione corrente
|
|
25
22
|
*/
|
|
@@ -110,35 +107,13 @@ class HttpServiceExtensions {
|
|
|
110
107
|
handleException(status, text) {
|
|
111
108
|
console.error("ESHttpError " + status + " " + text);
|
|
112
109
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"retrieved from cache": { "en-US": "retrieved from cache", "it-IT": "recuperato dalla cache", },
|
|
121
|
-
"Cached result for": { "en-US": "Cached result for", "it-IT": "Messo in cache risultato per", },
|
|
122
|
-
"Starting call": { "en-US": "Starting call", "it-IT": "Inizio la chiamata", },
|
|
123
|
-
"at URL": { "en-US": "at URL", "it-IT": "all'URL", },
|
|
124
|
-
"Invlalidating cache element": { "en-US": "Invlalidating cache element", "it-IT": "Invalido elemento della cache", },
|
|
125
|
-
"Finalizing call": { "en-US": "Finalizing call", "it-IT": "Finalizzo chiamata", },
|
|
126
|
-
"with status": { "en-US": "with status", "it-IT": "con stato", },
|
|
127
|
-
"Success": { "en-US": "Success", "it-IT": "Successso", },
|
|
128
|
-
"Failure": { "en-US": "Failure", "it-IT": "Fallimento", },
|
|
129
|
-
"Error 401 on call": { "en-US": "Error 401 on call", "it-IT": "Errore 401 su chiamata", },
|
|
130
|
-
"with redirect already in progress. Ignoring this event": { "en-US": "with redirect already in progress. Ignoring this event", "it-IT": "con redirezione già in corso. Ignoro l'evento", },
|
|
131
|
-
"redirecting to login": { "en-US": "redirecting to login", "it-IT": "redireziono al login", },
|
|
132
|
-
"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", },
|
|
133
|
-
"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", },
|
|
134
|
-
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata" },
|
|
135
|
-
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" },
|
|
136
|
-
"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" },
|
|
137
|
-
"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" },
|
|
138
|
-
"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" },
|
|
139
|
-
"Caches succesfully persisted": { "en-US": "Caches succesfully persisted", "it-IT": "Le cache sono state persistite con successo" },
|
|
140
|
-
"Errors persisting modified caches": { "en-US": "Errors persisting modified caches", "it-IT": "Errori nella persistizione delle cache (esiste persistizione? boh...)" },
|
|
141
|
-
};
|
|
110
|
+
}
|
|
111
|
+
HttpServiceExtensions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HttpServiceExtensions, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
112
|
+
HttpServiceExtensions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HttpServiceExtensions, providedIn: 'root' });
|
|
113
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HttpServiceExtensions, decorators: [{
|
|
114
|
+
type: Injectable,
|
|
115
|
+
args: [{ providedIn: 'root' }]
|
|
116
|
+
}] });
|
|
142
117
|
|
|
143
118
|
class CacheInfos {
|
|
144
119
|
constructor(finalUrl, cache, cacheKey, cacheTime, cacheItem) {
|
|
@@ -158,15 +133,15 @@ class HTTPService {
|
|
|
158
133
|
/**
|
|
159
134
|
* @ignore
|
|
160
135
|
*/
|
|
161
|
-
constructor(EXTENSION_CLASS, HTTP_INVALIDATION,
|
|
136
|
+
constructor(EXTENSION_CLASS, HTTP_INVALIDATION, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, bc, http, localStorage, utisExts) {
|
|
162
137
|
var _a, _b;
|
|
163
138
|
this.EXTENSION_CLASS = EXTENSION_CLASS;
|
|
164
139
|
this.HTTP_INVALIDATION = HTTP_INVALIDATION;
|
|
165
|
-
this.LOCALE = LOCALE;
|
|
166
140
|
this.APP_NAME = APP_NAME;
|
|
167
141
|
this.CLIENT_CACHE_DURATION_S = CLIENT_CACHE_DURATION_S;
|
|
168
142
|
this.CACHE_BY_USER = CACHE_BY_USER;
|
|
169
143
|
this.DEBUG_MODE = DEBUG_MODE;
|
|
144
|
+
this.bc = bc;
|
|
170
145
|
this.http = http;
|
|
171
146
|
this.localStorage = localStorage;
|
|
172
147
|
this.utisExts = utisExts;
|
|
@@ -229,14 +204,16 @@ class HTTPService {
|
|
|
229
204
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
230
205
|
*/
|
|
231
206
|
get(url, params = null, transaction = "", succesfulResultMandatory = true, errorCallback = null) {
|
|
232
|
-
|
|
233
|
-
|
|
207
|
+
return forkJoin({
|
|
208
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
209
|
+
locale: this.bc.Locale
|
|
210
|
+
}).pipe(concatMap((ret) => {
|
|
234
211
|
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
235
212
|
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
236
213
|
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
237
|
-
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
214
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
238
215
|
}
|
|
239
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
|
|
216
|
+
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
240
217
|
return httpCall.pipe(map((res) => {
|
|
241
218
|
let responseItem = res;
|
|
242
219
|
if (cachedInfos.cache) {
|
|
@@ -247,8 +224,8 @@ class HTTPService {
|
|
|
247
224
|
}), catchError((err, caught) => {
|
|
248
225
|
if (errorCallback)
|
|
249
226
|
errorCallback();
|
|
250
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
251
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
227
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
228
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid, cachedInfos); }));
|
|
252
229
|
}));
|
|
253
230
|
}
|
|
254
231
|
/**
|
|
@@ -267,13 +244,16 @@ class HTTPService {
|
|
|
267
244
|
* @returns {Observable<Blob | ArrayBuffer>} Observable che contiene il risultato della chiamata
|
|
268
245
|
*/
|
|
269
246
|
getRaw(url, params = null, type = "arraybuffer", transaction = "", succesfulResultMandatory = true, errorCallback = null) {
|
|
270
|
-
return
|
|
247
|
+
return forkJoin({
|
|
248
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
249
|
+
locale: this.bc.Locale
|
|
250
|
+
}).pipe(concatMap((ret) => {
|
|
271
251
|
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
272
252
|
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
273
253
|
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
274
|
-
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
254
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
275
255
|
}
|
|
276
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
|
|
256
|
+
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
277
257
|
return httpCall.pipe(map((blob) => {
|
|
278
258
|
if (cachedInfos.cache) {
|
|
279
259
|
this.cacheResponse(blob, cachedInfos);
|
|
@@ -283,8 +263,8 @@ class HTTPService {
|
|
|
283
263
|
}), catchError((err, caught) => {
|
|
284
264
|
if (errorCallback)
|
|
285
265
|
errorCallback();
|
|
286
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
287
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
266
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
267
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid, cachedInfos); }));
|
|
288
268
|
}));
|
|
289
269
|
}
|
|
290
270
|
/**
|
|
@@ -300,11 +280,14 @@ class HTTPService {
|
|
|
300
280
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
301
281
|
*/
|
|
302
282
|
post(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
303
|
-
return
|
|
304
|
-
|
|
283
|
+
return forkJoin({
|
|
284
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
285
|
+
locale: this.bc.Locale
|
|
286
|
+
}).pipe(concatMap((ret) => {
|
|
287
|
+
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
305
288
|
return httpCall.pipe(catchError((err, caught) => {
|
|
306
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
307
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
289
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
290
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
308
291
|
}));
|
|
309
292
|
}
|
|
310
293
|
/**
|
|
@@ -319,11 +302,14 @@ class HTTPService {
|
|
|
319
302
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
320
303
|
*/
|
|
321
304
|
delete(url, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
322
|
-
return
|
|
323
|
-
|
|
305
|
+
return forkJoin({
|
|
306
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
307
|
+
locale: this.bc.Locale
|
|
308
|
+
}).pipe(concatMap((ret) => {
|
|
309
|
+
var httpCall = this.http.delete(url, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
324
310
|
return httpCall.pipe(catchError((err, caught) => {
|
|
325
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
326
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
311
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
312
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
327
313
|
}));
|
|
328
314
|
}
|
|
329
315
|
/**
|
|
@@ -339,11 +325,14 @@ class HTTPService {
|
|
|
339
325
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
340
326
|
*/
|
|
341
327
|
put(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
342
|
-
return
|
|
343
|
-
|
|
328
|
+
return forkJoin({
|
|
329
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
330
|
+
locale: this.bc.Locale
|
|
331
|
+
}).pipe(concatMap((ret) => {
|
|
332
|
+
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(ret.locale, transaction), params: params });
|
|
344
333
|
return httpCall.pipe(catchError((err, caught) => {
|
|
345
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
346
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
334
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
|
|
335
|
+
}), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
347
336
|
}));
|
|
348
337
|
}
|
|
349
338
|
/**
|
|
@@ -358,11 +347,14 @@ class HTTPService {
|
|
|
358
347
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
359
348
|
*/
|
|
360
349
|
postwithFiles(url, bodyData, fileArrayOrFile, params = null) {
|
|
361
|
-
return
|
|
350
|
+
return forkJoin({
|
|
351
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
352
|
+
locale: this.bc.Locale
|
|
353
|
+
}).pipe(concatMap((ret) => {
|
|
362
354
|
var formData = this.getFilesFormData(fileArrayOrFile);
|
|
363
355
|
formData.append("body", JSON.stringify(bodyData));
|
|
364
|
-
var httpCall = this.http.post(url, formData, { params: params, headers: this.getHeaders(null, true, null, null) });
|
|
365
|
-
return httpCall.pipe(catchError((err, caught) => { return this.registerErrorAndReturnEmptyObservable(err, myGuid); }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
356
|
+
var httpCall = this.http.post(url, formData, { params: params, headers: this.getHeaders(ret.locale, null, true, null, null) });
|
|
357
|
+
return httpCall.pipe(catchError((err, caught) => { return this.registerErrorAndReturnEmptyObservable(err, ret.myGuid); }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
366
358
|
}));
|
|
367
359
|
}
|
|
368
360
|
/**
|
|
@@ -379,18 +371,21 @@ class HTTPService {
|
|
|
379
371
|
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
380
372
|
*/
|
|
381
373
|
postGetFile(url, bodyData, filename, getFileCallback, afterGetFile = null, handleError = true, pars) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
374
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
375
|
+
let myGuid = this.defaultStartCall(url);
|
|
376
|
+
let locale = yield this.bc.Locale.pipe(first()).toPromise();
|
|
377
|
+
this.http.post(url, bodyData, { params: pars, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
|
|
378
|
+
if (afterGetFile && !handleError)
|
|
379
|
+
afterGetFile();
|
|
380
|
+
return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
381
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
|
|
382
|
+
var _a, _b, _c, _d;
|
|
383
|
+
let retUrl = window.URL.createObjectURL(response.body);
|
|
384
|
+
let fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
385
|
+
getFileCallback(retUrl, filename || fn);
|
|
386
|
+
if (afterGetFile)
|
|
387
|
+
afterGetFile();
|
|
388
|
+
});
|
|
394
389
|
});
|
|
395
390
|
}
|
|
396
391
|
/**
|
|
@@ -407,18 +402,21 @@ class HTTPService {
|
|
|
407
402
|
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
408
403
|
*/
|
|
409
404
|
getFile(url, params = null, filename, getFileCallback, afterGetFile = null, handleError = true) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
405
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
406
|
+
let myGuid = this.defaultStartCall(url);
|
|
407
|
+
let locale = yield this.bc.Locale.pipe(first()).toPromise();
|
|
408
|
+
this.http.get(url, { params: params, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
|
|
409
|
+
if (afterGetFile && !handleError)
|
|
410
|
+
afterGetFile();
|
|
411
|
+
return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
412
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
|
|
413
|
+
var _a, _b, _c, _d;
|
|
414
|
+
let retUrl = window.URL.createObjectURL(response.body);
|
|
415
|
+
let fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
416
|
+
getFileCallback(retUrl, filename || fn);
|
|
417
|
+
if (afterGetFile)
|
|
418
|
+
afterGetFile();
|
|
419
|
+
});
|
|
422
420
|
});
|
|
423
421
|
}
|
|
424
422
|
/**
|
|
@@ -449,24 +447,28 @@ class HTTPService {
|
|
|
449
447
|
* @returns {Observable<Download>} Observable dei vari step di progresso del download
|
|
450
448
|
*/
|
|
451
449
|
getFileWithProgress(url, params = null, getFileCallback) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
let cdisp = event.headers.get('content-disposition');
|
|
462
|
-
let cdispFilename = cdisp.split(';')[1].split('filename')[1].split('=')[1].trim().replace(/\"/g, '');
|
|
463
|
-
let retUrl = window.URL.createObjectURL(event.body);
|
|
464
|
-
getFileCallback(retUrl, cdispFilename);
|
|
450
|
+
return forkJoin({
|
|
451
|
+
myGuid: from([this.defaultStartCall(url)]),
|
|
452
|
+
locale: this.bc.Locale
|
|
453
|
+
}).pipe(concatMap((ret) => {
|
|
454
|
+
return this.http.get(url, { responseType: 'blob', headers: this.getHeaders(ret.locale), params: params, observe: 'events', reportProgress: true })
|
|
455
|
+
.pipe(scan((previous, event) => {
|
|
456
|
+
if (this.isHttpProgressEvent(event)) {
|
|
457
|
+
let progress = event.total ? (event.loaded > event.total ? 100 : Math.round((100 * event.loaded) / event.total)) : previous.progress;
|
|
458
|
+
return { progress: progress, state: 'IN_PROGRESS', content: null };
|
|
465
459
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
460
|
+
if (this.isHttpResponse(event)) {
|
|
461
|
+
if (event.body) {
|
|
462
|
+
let cdisp = event.headers.get('content-disposition');
|
|
463
|
+
let cdispFilename = cdisp.split(';')[1].split('filename')[1].split('=')[1].trim().replace(/\"/g, '');
|
|
464
|
+
let retUrl = window.URL.createObjectURL(event.body);
|
|
465
|
+
getFileCallback(retUrl, cdispFilename);
|
|
466
|
+
}
|
|
467
|
+
return { progress: 100, state: 'DONE', content: event.body };
|
|
468
|
+
}
|
|
469
|
+
return previous;
|
|
470
|
+
}, { state: 'PENDING', progress: 0, content: null }), catchError((err, _) => { return this.registerErrorAndReturnEmptyObservable(err, ret.myGuid); }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
|
|
471
|
+
}));
|
|
470
472
|
}
|
|
471
473
|
/**
|
|
472
474
|
* Riconosce se l'evento HTTP è di tipo **HttpResponse** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
@@ -606,8 +608,7 @@ class HTTPService {
|
|
|
606
608
|
*
|
|
607
609
|
* @returns {HttpHeaders} Header generati in base ai parametri
|
|
608
610
|
*/
|
|
609
|
-
getHeaders(transactionId = "", includeAuth = true, contentType = "application/json", accept = "application/json") {
|
|
610
|
-
var _a;
|
|
611
|
+
getHeaders(locale = 'it-IT', transactionId = "", includeAuth = true, contentType = "application/json", accept = "application/json") {
|
|
611
612
|
var headers = new HttpHeaders();
|
|
612
613
|
var authtoken = this.ExtensionsImpl.retrieveAccessToken();
|
|
613
614
|
if (contentType)
|
|
@@ -618,7 +619,7 @@ class HTTPService {
|
|
|
618
619
|
headers = headers.append("Authorization", "Bearer " + authtoken);
|
|
619
620
|
if (accept)
|
|
620
621
|
headers = headers.append("Accept", accept);
|
|
621
|
-
headers = headers.append("Accept-Language",
|
|
622
|
+
headers = headers.append("Accept-Language", locale);
|
|
622
623
|
return headers;
|
|
623
624
|
}
|
|
624
625
|
/**
|
|
@@ -882,17 +883,15 @@ class HTTPService {
|
|
|
882
883
|
* @returns {string} Messaggio localizzato
|
|
883
884
|
*/
|
|
884
885
|
loc(message) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
return "";
|
|
888
|
-
}
|
|
889
|
-
return Loc[message][this.LOCALE];
|
|
886
|
+
// Togliamo velocemente ste localizzazioni inutili....
|
|
887
|
+
return message;
|
|
890
888
|
}
|
|
891
889
|
}
|
|
892
|
-
HTTPService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService, deps: [{ token: HttpServiceExtensions }, { token: HTTP_INVALIDATION, optional: true }, { token:
|
|
893
|
-
HTTPService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService });
|
|
890
|
+
HTTPService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService, deps: [{ token: HttpServiceExtensions }, { token: HTTP_INVALIDATION, 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.BaseLocalization }, { token: i3.HttpClient }, { token: i4.CacheService }, { token: i5.UtilityService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
891
|
+
HTTPService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService, providedIn: 'root' });
|
|
894
892
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService, decorators: [{
|
|
895
|
-
type: Injectable
|
|
893
|
+
type: Injectable,
|
|
894
|
+
args: [{ providedIn: 'root' }]
|
|
896
895
|
}], ctorParameters: function () {
|
|
897
896
|
return [{ type: HttpServiceExtensions }, { type: undefined, decorators: [{
|
|
898
897
|
type: Optional
|
|
@@ -901,11 +900,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
901
900
|
args: [HTTP_INVALIDATION]
|
|
902
901
|
}] }, { type: undefined, decorators: [{
|
|
903
902
|
type: Optional
|
|
904
|
-
}, {
|
|
905
|
-
type: Inject,
|
|
906
|
-
args: [HTTP_LOCALE]
|
|
907
|
-
}] }, { type: undefined, decorators: [{
|
|
908
|
-
type: Optional
|
|
909
903
|
}, {
|
|
910
904
|
type: Inject,
|
|
911
905
|
args: [APP_NAME]
|
|
@@ -924,7 +918,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
924
918
|
}, {
|
|
925
919
|
type: Inject,
|
|
926
920
|
args: [DEBUG_MODE]
|
|
927
|
-
}] }, { type: i2.
|
|
921
|
+
}] }, { type: i2.BaseLocalization }, { type: i3.HttpClient }, { type: i4.CacheService }, { type: i5.UtilityService }];
|
|
928
922
|
} });
|
|
929
923
|
|
|
930
924
|
class HttpserviceModule {
|
|
@@ -932,11 +926,8 @@ class HttpserviceModule {
|
|
|
932
926
|
return {
|
|
933
927
|
ngModule: HttpserviceModule,
|
|
934
928
|
providers: [
|
|
935
|
-
HTTPService,
|
|
936
|
-
HttpServiceExtensions,
|
|
937
929
|
{ provide: HTTP_INVALIDATION, useValue: config === null || config === void 0 ? void 0 : config.httpInvalidation },
|
|
938
930
|
{ provide: CLIENT_CACHE_DURATION_S, useValue: config === null || config === void 0 ? void 0 : config.clientCacheDurationS },
|
|
939
|
-
{ provide: HTTP_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.httpLocale) || 'it-IT' },
|
|
940
931
|
{ provide: APP_NAME, useValue: config === null || config === void 0 ? void 0 : config.appName },
|
|
941
932
|
{ provide: CACHE_BY_USER, useValue: config === null || config === void 0 ? void 0 : config.cacheByUser },
|
|
942
933
|
{ provide: DEBUG_MODE, useValue: config === null || config === void 0 ? void 0 : config.debugMode }
|