@esfaenza/httpservice 15.2.3 → 15.2.5

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.
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9rZW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvaHR0cHNlcnZpY2Uvc3JjL2xpYi90b2tlbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUUvQzs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLGlCQUFpQixHQUE2QyxJQUFJLGNBQWMsQ0FBMkIsbUJBQW1CLENBQUMsQ0FBQztBQUU3STs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLHVCQUF1QixHQUEyQixJQUFJLGNBQWMsQ0FBUyx5QkFBeUIsQ0FBQyxDQUFDO0FBRXJIOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sV0FBVyx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tlbjxib29sZWFuPignREVCVUdfTU9ERScpOyJdfQ==
@@ -1,12 +1,13 @@
1
1
  import { __awaiter } from 'tslib';
2
- import * as i2 from '@angular/common/http';
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 i3 from '@esfaenza/preferences';
9
- import * as i4 from '@esfaenza/extensions';
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
- * Oggetto statico di localizzazione per i messaggi
117
- */
118
- const Loc = {
119
- "Result for": { "en-US": "Result for", "it-IT": "Risultato per", },
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,14 @@ class HTTPService {
158
133
  /**
159
134
  * @ignore
160
135
  */
161
- constructor(EXTENSION_CLASS, HTTP_INVALIDATION, LOCALE, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, http, localStorage, utisExts) {
162
- var _a, _b;
136
+ constructor(EXTENSION_CLASS, HTTP_INVALIDATION, APP_NAME, CLIENT_CACHE_DURATION_S, CACHE_BY_USER, DEBUG_MODE, bc, http, localStorage, utisExts) {
163
137
  this.EXTENSION_CLASS = EXTENSION_CLASS;
164
138
  this.HTTP_INVALIDATION = HTTP_INVALIDATION;
165
- this.LOCALE = LOCALE;
166
139
  this.APP_NAME = APP_NAME;
167
140
  this.CLIENT_CACHE_DURATION_S = CLIENT_CACHE_DURATION_S;
168
141
  this.CACHE_BY_USER = CACHE_BY_USER;
169
142
  this.DEBUG_MODE = DEBUG_MODE;
143
+ this.bc = bc;
170
144
  this.http = http;
171
145
  this.localStorage = localStorage;
172
146
  this.utisExts = utisExts;
@@ -188,8 +162,8 @@ class HTTPService {
188
162
  this.LastThreeCompletedCalls = [];
189
163
  this.ExtensionsImpl = this.EXTENSION_CLASS || new HttpServiceExtensions();
190
164
  this.me = this.ExtensionsImpl.retrieveIdentity();
191
- this.localStorageHttpCacheKey = ((_a = this.APP_NAME) !== null && _a !== void 0 ? _a : "APP").replace(/\s/g, '_') + "_HttpCache";
192
- this.localStorageHttpTimedCacheKey = ((_b = this.APP_NAME) !== null && _b !== void 0 ? _b : "APP").replace(/\s/g, '_') + "_HttpTimedCache";
165
+ this.localStorageHttpCacheKey = (this.APP_NAME).replace(/\s/g, '_') + "_HttpCache";
166
+ this.localStorageHttpTimedCacheKey = (this.APP_NAME).replace(/\s/g, '_') + "_HttpTimedCache";
193
167
  this.localStorageHttpCacheExpireKey = this.localStorageHttpCacheKey + "_Expire";
194
168
  this.adjustOldStorageSystem();
195
169
  if (this.untimedCacheExpired())
@@ -229,14 +203,16 @@ class HTTPService {
229
203
  * @returns {Observable<T>} Observable che contiene il risultato della chiamata
230
204
  */
231
205
  get(url, params = null, transaction = "", succesfulResultMandatory = true, errorCallback = null) {
232
- // TODO provare e testare
233
- return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
206
+ return forkJoin({
207
+ myGuid: from([this.defaultStartCall(url)]),
208
+ locale: this.bc.Locale
209
+ }).pipe(concatMap((ret) => {
234
210
  let cachedInfos = this.tryGetCacheInformations(url, params);
235
211
  if (cachedInfos.cache && cachedInfos.cacheItem) {
236
212
  this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
237
- return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
213
+ return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
238
214
  }
239
- var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
215
+ var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(ret.locale, transaction), params: params });
240
216
  return httpCall.pipe(map((res) => {
241
217
  let responseItem = res;
242
218
  if (cachedInfos.cache) {
@@ -247,8 +223,8 @@ class HTTPService {
247
223
  }), catchError((err, caught) => {
248
224
  if (errorCallback)
249
225
  errorCallback();
250
- return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
251
- }), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
226
+ return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
227
+ }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid, cachedInfos); }));
252
228
  }));
253
229
  }
254
230
  /**
@@ -267,13 +243,16 @@ class HTTPService {
267
243
  * @returns {Observable<Blob | ArrayBuffer>} Observable che contiene il risultato della chiamata
268
244
  */
269
245
  getRaw(url, params = null, type = "arraybuffer", transaction = "", succesfulResultMandatory = true, errorCallback = null) {
270
- return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
246
+ return forkJoin({
247
+ myGuid: from([this.defaultStartCall(url)]),
248
+ locale: this.bc.Locale
249
+ }).pipe(concatMap((ret) => {
271
250
  let cachedInfos = this.tryGetCacheInformations(url, params);
272
251
  if (cachedInfos.cache && cachedInfos.cacheItem) {
273
252
  this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
274
- return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
253
+ return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
275
254
  }
276
- var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
255
+ var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(ret.locale, transaction), params: params });
277
256
  return httpCall.pipe(map((blob) => {
278
257
  if (cachedInfos.cache) {
279
258
  this.cacheResponse(blob, cachedInfos);
@@ -283,8 +262,8 @@ class HTTPService {
283
262
  }), catchError((err, caught) => {
284
263
  if (errorCallback)
285
264
  errorCallback();
286
- return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
287
- }), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
265
+ return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
266
+ }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid, cachedInfos); }));
288
267
  }));
289
268
  }
290
269
  /**
@@ -300,11 +279,14 @@ class HTTPService {
300
279
  * @returns {Observable<T>} Observable che contiene il risultato della chiamata
301
280
  */
302
281
  post(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
303
- return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
304
- var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
282
+ return forkJoin({
283
+ myGuid: from([this.defaultStartCall(url)]),
284
+ locale: this.bc.Locale
285
+ }).pipe(concatMap((ret) => {
286
+ var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(ret.locale, transaction), params: params });
305
287
  return httpCall.pipe(catchError((err, caught) => {
306
- return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
307
- }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
288
+ return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
289
+ }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
308
290
  }));
309
291
  }
310
292
  /**
@@ -319,11 +301,14 @@ class HTTPService {
319
301
  * @returns {Observable<T>} Observable che contiene il risultato della chiamata
320
302
  */
321
303
  delete(url, params = null, transaction = "", succesfulResultMandatory = true) {
322
- return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
323
- var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
304
+ return forkJoin({
305
+ myGuid: from([this.defaultStartCall(url)]),
306
+ locale: this.bc.Locale
307
+ }).pipe(concatMap((ret) => {
308
+ var httpCall = this.http.delete(url, { headers: this.getHeaders(ret.locale, transaction), params: params });
324
309
  return httpCall.pipe(catchError((err, caught) => {
325
- return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
326
- }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
310
+ return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
311
+ }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
327
312
  }));
328
313
  }
329
314
  /**
@@ -339,11 +324,14 @@ class HTTPService {
339
324
  * @returns {Observable<T>} Observable che contiene il risultato della chiamata
340
325
  */
341
326
  put(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
342
- return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
343
- var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
327
+ return forkJoin({
328
+ myGuid: from([this.defaultStartCall(url)]),
329
+ locale: this.bc.Locale
330
+ }).pipe(concatMap((ret) => {
331
+ var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(ret.locale, transaction), params: params });
344
332
  return httpCall.pipe(catchError((err, caught) => {
345
- return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
346
- }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
333
+ return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, ret.myGuid);
334
+ }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
347
335
  }));
348
336
  }
349
337
  /**
@@ -358,11 +346,14 @@ class HTTPService {
358
346
  * @returns {Observable<T>} Observable che contiene il risultato della chiamata
359
347
  */
360
348
  postwithFiles(url, bodyData, fileArrayOrFile, params = null) {
361
- return from([this.defaultStartCall(url)]).pipe(concatMap((myGuid) => {
349
+ return forkJoin({
350
+ myGuid: from([this.defaultStartCall(url)]),
351
+ locale: this.bc.Locale
352
+ }).pipe(concatMap((ret) => {
362
353
  var formData = this.getFilesFormData(fileArrayOrFile);
363
354
  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); }));
355
+ var httpCall = this.http.post(url, formData, { params: params, headers: this.getHeaders(ret.locale, null, true, null, null) });
356
+ return httpCall.pipe(catchError((err, caught) => { return this.registerErrorAndReturnEmptyObservable(err, ret.myGuid); }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
366
357
  }));
367
358
  }
368
359
  /**
@@ -379,18 +370,21 @@ class HTTPService {
379
370
  * @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
380
371
  */
381
372
  postGetFile(url, bodyData, filename, getFileCallback, afterGetFile = null, handleError = true, pars) {
382
- let myGuid = this.defaultStartCall(url);
383
- this.http.post(url, bodyData, { params: pars, headers: this.getHeaders(), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
384
- if (afterGetFile && !handleError)
385
- afterGetFile();
386
- return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
387
- }), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
388
- var _a, _b, _c, _d;
389
- let retUrl = window.URL.createObjectURL(response.body);
390
- 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, '');
391
- getFileCallback(retUrl, filename || fn);
392
- if (afterGetFile)
393
- afterGetFile();
373
+ return __awaiter(this, void 0, void 0, function* () {
374
+ let myGuid = this.defaultStartCall(url);
375
+ let locale = yield this.bc.Locale.pipe(first()).toPromise();
376
+ this.http.post(url, bodyData, { params: pars, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
377
+ if (afterGetFile && !handleError)
378
+ afterGetFile();
379
+ return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
380
+ }), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
381
+ var _a, _b, _c, _d;
382
+ let retUrl = window.URL.createObjectURL(response.body);
383
+ 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, '');
384
+ getFileCallback(retUrl, filename || fn);
385
+ if (afterGetFile)
386
+ afterGetFile();
387
+ });
394
388
  });
395
389
  }
396
390
  /**
@@ -407,18 +401,21 @@ class HTTPService {
407
401
  * @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
408
402
  */
409
403
  getFile(url, params = null, filename, getFileCallback, afterGetFile = null, handleError = true) {
410
- let myGuid = this.defaultStartCall(url);
411
- this.http.get(url, { params: params, headers: this.getHeaders(), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
412
- if (afterGetFile && !handleError)
413
- afterGetFile();
414
- return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
415
- }), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
416
- var _a, _b, _c, _d;
417
- let retUrl = window.URL.createObjectURL(response.body);
418
- 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, '');
419
- getFileCallback(retUrl, filename || fn);
420
- if (afterGetFile)
421
- afterGetFile();
404
+ return __awaiter(this, void 0, void 0, function* () {
405
+ let myGuid = this.defaultStartCall(url);
406
+ let locale = yield this.bc.Locale.pipe(first()).toPromise();
407
+ this.http.get(url, { params: params, headers: this.getHeaders(locale), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
408
+ if (afterGetFile && !handleError)
409
+ afterGetFile();
410
+ return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
411
+ }), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
412
+ var _a, _b, _c, _d;
413
+ let retUrl = window.URL.createObjectURL(response.body);
414
+ 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, '');
415
+ getFileCallback(retUrl, filename || fn);
416
+ if (afterGetFile)
417
+ afterGetFile();
418
+ });
422
419
  });
423
420
  }
424
421
  /**
@@ -449,24 +446,28 @@ class HTTPService {
449
446
  * @returns {Observable<Download>} Observable dei vari step di progresso del download
450
447
  */
451
448
  getFileWithProgress(url, params = null, getFileCallback) {
452
- let myGuid = this.defaultStartCall(url);
453
- return this.http.get(url, { responseType: 'blob', headers: this.getHeaders(), params: params, observe: 'events', reportProgress: true })
454
- .pipe(scan((previous, event) => {
455
- if (this.isHttpProgressEvent(event)) {
456
- let progress = event.total ? (event.loaded > event.total ? 100 : Math.round((100 * event.loaded) / event.total)) : previous.progress;
457
- return { progress: progress, state: 'IN_PROGRESS', content: null };
458
- }
459
- if (this.isHttpResponse(event)) {
460
- if (event.body) {
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);
449
+ return forkJoin({
450
+ myGuid: from([this.defaultStartCall(url)]),
451
+ locale: this.bc.Locale
452
+ }).pipe(concatMap((ret) => {
453
+ return this.http.get(url, { responseType: 'blob', headers: this.getHeaders(ret.locale), params: params, observe: 'events', reportProgress: true })
454
+ .pipe(scan((previous, event) => {
455
+ if (this.isHttpProgressEvent(event)) {
456
+ let progress = event.total ? (event.loaded > event.total ? 100 : Math.round((100 * event.loaded) / event.total)) : previous.progress;
457
+ return { progress: progress, state: 'IN_PROGRESS', content: null };
465
458
  }
466
- return { progress: 100, state: 'DONE', content: event.body };
467
- }
468
- return previous;
469
- }, { state: 'PENDING', progress: 0, content: null }), catchError((err, _) => { return this.registerErrorAndReturnEmptyObservable(err, myGuid); }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
459
+ if (this.isHttpResponse(event)) {
460
+ if (event.body) {
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);
465
+ }
466
+ return { progress: 100, state: 'DONE', content: event.body };
467
+ }
468
+ return previous;
469
+ }, { state: 'PENDING', progress: 0, content: null }), catchError((err, _) => { return this.registerErrorAndReturnEmptyObservable(err, ret.myGuid); }), finalize(() => { this.tryFinalizeByGuid(ret.myGuid); }));
470
+ }));
470
471
  }
471
472
  /**
472
473
  * 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 +607,7 @@ class HTTPService {
606
607
  *
607
608
  * @returns {HttpHeaders} Header generati in base ai parametri
608
609
  */
609
- getHeaders(transactionId = "", includeAuth = true, contentType = "application/json", accept = "application/json") {
610
- var _a;
610
+ getHeaders(locale = 'it-IT', transactionId = "", includeAuth = true, contentType = "application/json", accept = "application/json") {
611
611
  var headers = new HttpHeaders();
612
612
  var authtoken = this.ExtensionsImpl.retrieveAccessToken();
613
613
  if (contentType)
@@ -618,7 +618,7 @@ class HTTPService {
618
618
  headers = headers.append("Authorization", "Bearer " + authtoken);
619
619
  if (accept)
620
620
  headers = headers.append("Accept", accept);
621
- headers = headers.append("Accept-Language", (_a = this.LOCALE) !== null && _a !== void 0 ? _a : 'it-IT');
621
+ headers = headers.append("Accept-Language", locale);
622
622
  return headers;
623
623
  }
624
624
  /**
@@ -827,10 +827,9 @@ class HTTPService {
827
827
  * 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**)
828
828
  */
829
829
  resetHttpUntimedCacheStorage() {
830
- var _a;
831
830
  return __awaiter(this, void 0, void 0, function* () {
832
831
  yield this.localStorage.setItem(this.localStorageHttpCacheKey, {}).toPromise();
833
- localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(dayjs().add((_a = this.CLIENT_CACHE_DURATION_S) !== null && _a !== void 0 ? _a : 3600, "second")));
832
+ localStorage.setItem(this.localStorageHttpCacheExpireKey, JSON.stringify(dayjs().add(this.CLIENT_CACHE_DURATION_S, "second")));
834
833
  });
835
834
  }
836
835
  /**
@@ -882,17 +881,15 @@ class HTTPService {
882
881
  * @returns {string} Messaggio localizzato
883
882
  */
884
883
  loc(message) {
885
- if (!Loc[message]) {
886
- console.warn("Untranslated message: " + message);
887
- return "";
888
- }
889
- return Loc[message][this.LOCALE];
884
+ // Togliamo velocemente ste localizzazioni inutili....
885
+ return message;
890
886
  }
891
887
  }
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: 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 });
893
- HTTPService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService });
888
+ 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 }, { token: CLIENT_CACHE_DURATION_S }, { token: CACHE_BY_USER }, { token: DEBUG_MODE }, { token: i2.BaseLocalization }, { token: i3.HttpClient }, { token: i4.CacheService }, { token: i5.UtilityService }], target: i0.ɵɵFactoryTarget.Injectable });
889
+ HTTPService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService, providedIn: 'root' });
894
890
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: HTTPService, decorators: [{
895
- type: Injectable
891
+ type: Injectable,
892
+ args: [{ providedIn: 'root' }]
896
893
  }], ctorParameters: function () {
897
894
  return [{ type: HttpServiceExtensions }, { type: undefined, decorators: [{
898
895
  type: Optional
@@ -900,31 +897,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
900
897
  type: Inject,
901
898
  args: [HTTP_INVALIDATION]
902
899
  }] }, { type: undefined, decorators: [{
903
- type: Optional
904
- }, {
905
- type: Inject,
906
- args: [HTTP_LOCALE]
907
- }] }, { type: undefined, decorators: [{
908
- type: Optional
909
- }, {
910
900
  type: Inject,
911
901
  args: [APP_NAME]
912
902
  }] }, { type: undefined, decorators: [{
913
- type: Optional
914
- }, {
915
903
  type: Inject,
916
904
  args: [CLIENT_CACHE_DURATION_S]
917
905
  }] }, { type: undefined, decorators: [{
918
- type: Optional
919
- }, {
920
906
  type: Inject,
921
907
  args: [CACHE_BY_USER]
922
908
  }] }, { type: undefined, decorators: [{
923
- type: Optional
924
- }, {
925
909
  type: Inject,
926
910
  args: [DEBUG_MODE]
927
- }] }, { type: i2.HttpClient }, { type: i3.CacheService }, { type: i4.UtilityService }];
911
+ }] }, { type: i2.BaseLocalization }, { type: i3.HttpClient }, { type: i4.CacheService }, { type: i5.UtilityService }];
928
912
  } });
929
913
 
930
914
  class HttpserviceModule {
@@ -932,14 +916,11 @@ class HttpserviceModule {
932
916
  return {
933
917
  ngModule: HttpserviceModule,
934
918
  providers: [
935
- HTTPService,
936
- HttpServiceExtensions,
937
919
  { provide: HTTP_INVALIDATION, useValue: config === null || config === void 0 ? void 0 : config.httpInvalidation },
938
- { 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
- { provide: APP_NAME, useValue: config === null || config === void 0 ? void 0 : config.appName },
941
- { provide: CACHE_BY_USER, useValue: config === null || config === void 0 ? void 0 : config.cacheByUser },
942
- { provide: DEBUG_MODE, useValue: config === null || config === void 0 ? void 0 : config.debugMode }
920
+ { provide: CLIENT_CACHE_DURATION_S, useValue: (config === null || config === void 0 ? void 0 : config.clientCacheDurationS) || 3600 },
921
+ { provide: APP_NAME, useValue: (config === null || config === void 0 ? void 0 : config.appName) || 'APP' },
922
+ { provide: CACHE_BY_USER, useValue: (config === null || config === void 0 ? void 0 : config.cacheByUser) || false },
923
+ { provide: DEBUG_MODE, useValue: (config === null || config === void 0 ? void 0 : config.debugMode) || false }
943
924
  ]
944
925
  };
945
926
  }