@esfaenza/httpservice 11.2.46 → 11.2.48
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/bundles/esfaenza-httpservice.umd.js +62 -64
- package/bundles/esfaenza-httpservice.umd.js.map +1 -1
- package/bundles/esfaenza-httpservice.umd.min.js +2 -2
- package/bundles/esfaenza-httpservice.umd.min.js.map +1 -1
- package/esm2015/lib/httpservice.service.js +65 -67
- package/fesm2015/esfaenza-httpservice.js +64 -66
- package/fesm2015/esfaenza-httpservice.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common/http"),require("@angular/core"),require("@esfaenza/preferences"),require("@esfaenza/extensions"),require("rxjs/operators"),require("rxjs")):"function"==typeof define&&define.amd?define("@esfaenza/httpservice",["exports","@angular/common/http","@angular/core","@esfaenza/preferences","@esfaenza/extensions","rxjs/operators","rxjs"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).esfaenza=e.esfaenza||{},e.esfaenza.httpservice={}),e.ng.common.http,e.ng.core,e.preferences,e.extensions,e.rxjs.operators,e.rxjs)}(this,(function(e,t,r,i,o,n,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common/http"),require("@angular/core"),require("@esfaenza/preferences"),require("@esfaenza/extensions"),require("rxjs/operators"),require("rxjs")):"function"==typeof define&&define.amd?define("@esfaenza/httpservice",["exports","@angular/common/http","@angular/core","@esfaenza/preferences","@esfaenza/extensions","rxjs/operators","rxjs"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).esfaenza=e.esfaenza||{},e.esfaenza.httpservice={}),e.ng.common.http,e.ng.core,e.preferences,e.extensions,e.rxjs.operators,e.rxjs)}(this,(function(e,t,r,i,o,n,a){"use strict";
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function a(e,t,r,i){return new(r||(r=Promise))((function(o,n){function s(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}l((i=i.apply(e,t||[])).next())}))}function l(e,t){var r,i,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function a(n){return function(a){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(o=2&n[0]?i.return:n[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,n[1])).done)return o;switch(i=0,o&&(n=[2&n[0],o.value]),n[0]){case 0:case 1:o=n;break;case 4:return s.label++,{value:n[1],done:!1};case 5:s.label++,i=n[1],n=[0];continue;case 7:n=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==n[0]&&2!==n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1],o=n;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(n);break}o[2]&&s.ops.pop(),s.trys.pop();continue}n=t.call(e,s)}catch(e){n=[6,e],i=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}}Object.create;Object.create;var c=new r.InjectionToken("HTTP_INVALIDATION"),h=new r.InjectionToken("CLIENT_CACHE_DURATION_S"),p=new r.InjectionToken("BACKEND_URL"),u=new r.InjectionToken("HTTP_LOCALE"),d=new r.InjectionToken("APP_NAME"),g=new r.InjectionToken("CACHE_BY_USER"),f=new r.InjectionToken("DEBUG_MODE"),y=function(){function e(){}return e.prototype.retrieveAccessToken=function(){return""},e.prototype.retrieveIdentity=function(){return null},e.prototype.readRedirectingToLogin=function(){return!1},e.prototype.writeRedirectingToLogin=function(e){},e.prototype.redirectToLogin=function(){},e.prototype.readHandlingErrorStatus=function(){return!1},e.prototype.writeHandlingErrorStatus=function(e){},e.prototype.readRedirectionStatus=function(){return!1},e.prototype.writeRedirectionStatus=function(e){},e.prototype.handleNotConfiguredException=function(){return!1},e.prototype.handleBlockingException=function(e,t){console.error("ESHttpError Blocking Exception "+e+" "+t)},e.prototype.handleException=function(e,t){console.error("ESHttpError "+e+" "+t)},e}(),v={"Result for":{"en-US":"Result for","it-IT":"Risultato per"},"retrieved from cache":{"en-US":"retrieved from cache","it-IT":"recuperato dalla cache"},"Cached result for":{"en-US":"Cached result for","it-IT":"Messo in cache risultato per"},"Starting call":{"en-US":"Starting call","it-IT":"Inizio la chiamata"},"at URL":{"en-US":"at URL","it-IT":"all'URL"},"Invlalidating cache element":{"en-US":"Invlalidating cache element","it-IT":"Invalido elemento della cache"},"Finalizing call":{"en-US":"Finalizing call","it-IT":"Finalizzo chiamata"},"with status":{"en-US":"with status","it-IT":"con stato"},Success:{"en-US":"Success","it-IT":"Successso"},Failure:{"en-US":"Failure","it-IT":"Fallimento"},"Error 401 on call":{"en-US":"Error 401 on call","it-IT":"Errore 401 su chiamata"},"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"},"redirecting to login":{"en-US":"redirecting to login","it-IT":"redireziono al login"},"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"},"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"},"Error 444 on call":{"en-US":"Error 444 on call","it-IT":"Errore 444 su chiamata"},"Resource not found":{"en-US":"Resource not found","it-IT":"Risorsa non trovata"},"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"},"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"},"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"},"Caches succesfully persisted":{"en-US":"Caches succesfully persisted","it-IT":"Le cache sono state persistite con successo"},"Errors persisting modified caches":{"en-US":"Errors persisting modified caches","it-IT":"Errori nella persistizione delle cache (esiste persistizione? boh...)"}},m=function(e,t,r,i,o){this.finalUrl=e,this.cache=t,this.cacheKey=r,this.cacheTime=i,this.cacheItem=o},S=function(){function e(e,t,r,i,o,n,s,a,l,c,h){var p,u;this.BACKEND_URL=e,this.EXTENSION_CLASS=t,this.HTTP_INVALIDATION=r,this.LOCALE=i,this.APP_NAME=o,this.CLIENT_CACHE_DURATION_S=n,this.CACHE_BY_USER=s,this.DEBUG_MODE=a,this.http=l,this.localStorage=c,this.utisExts=h,this.callStatus={},this.localStorageHttpCacheKey=null,this.localStorageHttpTimedCacheKey=null,this.localStorageHttpCacheExpireKey=null,this.me=null,this.PersistTimedCacheASAP=!1,this.PersistUntimedCacheASAP=!1,this.LastThreeCompletedCalls=[],this.ExtensionsImpl=this.EXTENSION_CLASS||new y,this.me=this.ExtensionsImpl.retrieveIdentity(),this.localStorageHttpCacheKey=(null!==(p=this.APP_NAME)&&void 0!==p?p:"APP").replace(/\s/g,"_")+"_HttpCache",this.localStorageHttpTimedCacheKey=(null!==(u=this.APP_NAME)&&void 0!==u?u:"APP").replace(/\s/g,"_")+"_HttpTimedCache",this.localStorageHttpCacheExpireKey=this.localStorageHttpCacheKey+"_Expire",this.adjustOldStorageSystem(),this.untimedCacheExpired()&&this.resetHttpUntimedCacheStorage()}return e.prototype.adjustOldStorageSystem=function(){return a(this,void 0,void 0,(function(){var e,t;return l(this,(function(r){switch(r.label){case 0:return e=localStorage.getItem(this.localStorageHttpTimedCacheKey),t=localStorage.getItem(this.localStorageHttpCacheKey),e||t?(localStorage.removeItem(this.localStorageHttpTimedCacheKey),localStorage.removeItem(this.localStorageHttpCacheKey),e=e?JSON.parse(e):{},t=t?JSON.parse(t):{},[4,s.forkJoin([this.localStorage.setItem(this.localStorageHttpTimedCacheKey,e),this.localStorage.setItem(this.localStorageHttpCacheKey,t)]).toPromise()]):[2];case 1:return r.sent(),this.log(this.loc("Converted old storage system to new one")),[2]}}))}))},e.prototype.get=function(e,t,r,i,o){var a=this;void 0===t&&(t=null),void 0===r&&(r=""),void 0===i&&(i=!0),void 0===o&&(o=null);var l=this.defaultStartCall(e),c=this.tryGetCacheInformations(e,t);return c.cache&&c.cacheItem?(this.log(this.loc("Result for")+" "+e+" "+this.loc("retrieved from cache")),s.of(c.cacheItem).pipe(n.delay(0),n.finalize((function(){a.tryFinalizeByGuid(l)})))):this.http.get(c.finalUrl,{headers:this.getHeaders(r),params:t}).pipe(n.map((function(t){var r=t;return c.cache&&(a.cacheResponse(a.utisExts.deepClone(r),c),a.log(a.loc("Cached result for")+" "+e)),r})),n.catchError((function(e,t){return o&&o(),i?a.registerErrorAndReturnEmptyObservable(e,l):s.throwError(e)})),n.finalize((function(){a.tryFinalizeByGuid(l,c)})))},e.prototype.getRaw=function(e,t,r,i,o,a){var l=this;void 0===t&&(t=null),void 0===r&&(r="arraybuffer"),void 0===i&&(i=""),void 0===o&&(o=!0),void 0===a&&(a=null);var c=this.defaultStartCall(e),h=this.tryGetCacheInformations(e,t);return h.cache&&h.cacheItem?(this.log(this.loc("Result for")+" "+e+" "+this.loc("retrieved from cache")),s.of(h.cacheItem).pipe(n.delay(0),n.finalize((function(){l.tryFinalizeByGuid(c)})))):this.http.get(h.finalUrl,{responseType:r,headers:this.getHeaders(i),params:t}).pipe(n.map((function(t){return h.cache&&(l.cacheResponse(t,h),l.log(l.loc("Cached result for")+" "+e)),t})),n.catchError((function(e,t){return a&&a(),o?l.registerErrorAndReturnEmptyObservable(e,c):s.throwError(e)})),n.finalize((function(){l.tryFinalizeByGuid(c,h)})))},e.prototype.post=function(e,t,r,i,o){var a=this;void 0===r&&(r=null),void 0===i&&(i=""),void 0===o&&(o=!0);var l=this.defaultStartCall(e);return this.http.post(e,t,{headers:this.getHeaders(i),params:r}).pipe(n.map((function(e){return e})),n.catchError((function(e,t){return o?a.registerErrorAndReturnEmptyObservable(e,l):s.throwError(e)})),n.finalize((function(){a.tryFinalizeByGuid(l)})))},e.prototype.delete=function(e,t,r,i){var o=this;void 0===t&&(t=null),void 0===r&&(r=""),void 0===i&&(i=!0);var a=this.defaultStartCall(e);return this.http.delete(e,{headers:this.getHeaders(r),params:t}).pipe(n.map((function(e){return e})),n.catchError((function(e,t){return i?o.registerErrorAndReturnEmptyObservable(e,a):s.throwError(e)})),n.finalize((function(){o.tryFinalizeByGuid(a)})))},e.prototype.put=function(e,t,r,i,o){var a=this;void 0===r&&(r=null),void 0===i&&(i=""),void 0===o&&(o=!0);var l=this.defaultStartCall(e);return this.http.put(e,t,{headers:this.getHeaders(i),params:r}).pipe(n.map((function(e){return e})),n.catchError((function(e,t){return o?a.registerErrorAndReturnEmptyObservable(e,l):s.throwError(e)})),n.finalize((function(){a.tryFinalizeByGuid(l)})))},e.prototype.postwithFiles=function(e,t,r){var i=this,o=this.defaultStartCall(e),s=this.getFilesFormData(r);return s.append("body",JSON.stringify(t)),this.http.post(e,s,{headers:this.getHeaders(null,!0,null,null)}).pipe(n.catchError((function(e,t){return i.registerErrorAndReturnEmptyObservable(e,o)})),n.finalize((function(){i.tryFinalizeByGuid(o)})))},e.prototype.postGetFile=function(e,t,r,i,o,s,a){var l=this;void 0===o&&(o=null),void 0===s&&(s=!0);var c=this.defaultStartCall(e);this.http.post(e,t,{params:a,headers:this.getHeaders(),observe:"response",responseType:"blob"}).pipe(n.catchError((function(e,t){return o&&!s&&o(),l.registerErrorAndReturnEmptyObservable(e,c,s)})),n.finalize((function(){l.tryFinalizeByGuid(c)}))).subscribe((function(e){var t,n,s,a,l=window.URL.createObjectURL(e.body),c=null===(a=null===(s=null===(n=null===(t=e.headers.get("content-disposition"))||void 0===t?void 0:t.split(";")[1])||void 0===n?void 0:n.split("filename")[1])||void 0===s?void 0:s.split("=")[1])||void 0===a?void 0:a.trim().replace(/\"/g,"");i(l,r||c),o&&o()}))},e.prototype.getFile=function(e,t,r,i,o,s){var a=this;void 0===t&&(t=null),void 0===o&&(o=null),void 0===s&&(s=!0);var l=this.defaultStartCall(e);this.http.get(e,{params:t,headers:this.getHeaders(),observe:"response",responseType:"blob"}).pipe(n.catchError((function(e,t){return o&&!s&&o(),a.registerErrorAndReturnEmptyObservable(e,l,s)})),n.finalize((function(){a.tryFinalizeByGuid(l)}))).subscribe((function(e){var t,n,s,a,l=window.URL.createObjectURL(e.body),c=null===(a=null===(s=null===(n=null===(t=e.headers.get("content-disposition"))||void 0===t?void 0:t.split(";")[1])||void 0===n?void 0:n.split("filename")[1])||void 0===s?void 0:s.split("=")[1])||void 0===a?void 0:a.trim().replace(/\"/g,"");i(l,r||c),o&&o()}))},e.prototype.getFileNative=function(e,t){void 0===t&&(t=null);var r=e+(t?"?"+t.toString():"");window.location.href=r},e.prototype.getFileWithProgress=function(e,t,r){var i=this;void 0===t&&(t=null);var o=this.defaultStartCall(e);return this.http.get(e,{responseType:"blob",headers:this.getHeaders(),params:t,observe:"events",reportProgress:!0}).pipe(n.scan((function(e,t){if(i.isHttpProgressEvent(t))return{progress:t.total?t.loaded>t.total?100:Math.round(100*t.loaded/t.total):e.progress,state:"IN_PROGRESS",content:null};if(i.isHttpResponse(t)){if(t.body){var o=t.headers.get("content-disposition").split(";")[1].split("filename")[1].split("=")[1].trim().replace(/\"/g,""),n=window.URL.createObjectURL(t.body);r(n,o)}return{progress:100,state:"DONE",content:t.body}}return e}),{state:"PENDING",progress:0,content:null}),n.catchError((function(e,t){return i.registerErrorAndReturnEmptyObservable(e,o)})),n.finalize((function(){i.tryFinalizeByGuid(o)})))},e.prototype.isHttpResponse=function(e){return e.type===t.HttpEventType.Response},e.prototype.isHttpProgressEvent=function(e){return e.type===t.HttpEventType.DownloadProgress||e.type===t.HttpEventType.UploadProgress},e.prototype.defaultStartCall=function(e){var t=this.getGUID();return this.checkCacheInvalidation(e),this.callStatus[t]={url:e,success:!0},this.log(this.loc("Starting call")+" "+t+" "+this.loc("at URL")+": "+e),t},e.prototype.checkCacheInvalidation=function(e){var t=this,r=this.localStorage.getLocalItem(this.localStorageHttpCacheKey),i=/#cache(:?-(\d+))/gi.exec(e),o=i?i[2]:null,n=e.replace("#cache"+(o?"-"+o:""),"").replace(this.BACKEND_URL,"");if(r&&this.HTTP_INVALIDATION&&this.HTTP_INVALIDATION[n]){var s=this.HTTP_INVALIDATION[n];if(s&&0!=s.length){var a=[];s.forEach((function(e){var i=t.makeCacheKey(e,null);for(var o in r)-1!=o.indexOf(i)&&a.push(o)}));for(var l=0;l<a.length;l++){var c=a[l];this.log(this.loc("Invlalidating cache element")+" "+c),delete r[c]}this.localStorage.setLocalItem(this.localStorageHttpCacheKey,r)}}},e.prototype.tryFinalizeByGuid=function(e,t){return a(this,void 0,void 0,(function(){var r,i;return l(this,(function(o){switch(o.label){case 0:return this.log(this.loc("Finalizing call")+" "+e+" "+this.loc("with status")+": "+(this.callStatus[e]?this.callStatus[e].success?this.loc("Success"):this.loc("Failure"):"Unknown")),this.callStatus[e]&&(this.callStatus[e].success&&this.ExtensionsImpl.readRedirectionStatus()&&this.ExtensionsImpl.writeRedirectionStatus(!1),this.LastThreeCompletedCalls.unshift(this.callStatus[e].url),this.LastThreeCompletedCalls.length>3&&this.LastThreeCompletedCalls.pop(),delete this.callStatus[e]),t&&t.cache&&(this.PersistTimedCacheASAP=this.PersistTimedCacheASAP||!!t.cacheTime,this.PersistUntimedCacheASAP=this.PersistTimedCacheASAP||!t.cacheTime,this.log(this.loc("Marking cache to be persisted as soon as possible"))),!this.PersistTimedCacheASAP&&!this.PersistUntimedCacheASAP||0!=Object.keys(this.callStatus).length?[3,2]:(r=[],i="",this.PersistTimedCacheASAP&&(i=this.localStorageHttpTimedCacheKey,r.push(this.localStorage.setItem(i,this.localStorage.getLocalItem(i)))),this.PersistUntimedCacheASAP&&(i=this.localStorageHttpCacheKey,r.push(this.localStorage.setItem(i,this.localStorage.getLocalItem(i)))),this.log(this.loc("No more HTTP calls to be executed, entering idle state and persisting modified caches")+"..."),[4,s.forkJoin(r).toPromise()]);case 1:o.sent()?this.log(this.loc("Caches succesfully persisted")):this.log(this.loc("Errors persisting modified caches")),this.PersistTimedCacheASAP=!1,this.PersistUntimedCacheASAP=!1,o.label=2;case 2:return[2]}}))}))},e.prototype.getFilesFormData=function(e){var t=new FormData;return e&&(e.length?e.forEach((function(e){t.append("file",e,e.name)})):e.name&&t.append("files",e,e.name)),t},e.prototype.getHeaders=function(e,r,i,o){var n;void 0===e&&(e=""),void 0===r&&(r=!0),void 0===i&&(i="application/json"),void 0===o&&(o="application/json");var s=new t.HttpHeaders,a=this.ExtensionsImpl.retrieveAccessToken();return i&&(s=s.append("Content-Type",i)),e&&(s=s.append("X-TX-ID",e)),a&&r&&(s=s.append("Authorization","Bearer "+a)),o&&(s=s.append("Accept",o)),s=s.append("Accept-Language",null!==(n=this.LOCALE)&&void 0!==n?n:"it-IT")},e.prototype.onError=function(e,t){return a(this,void 0,void 0,(function(){var r,i;return l(this,(function(o){switch(o.label){case 0:return this.callStatus[t]&&(this.callStatus[t].success=!1),this.ExtensionsImpl.readRedirectingToLogin()?(this.log(this.loc("Redirecting to Login, ignoring HTTP error on call")+" "+t),[2]):this.ExtensionsImpl.readHandlingErrorStatus()?(this.log(this.loc("Already Handling an error, ignoring HTTP error on call")+" "+t),[2]):(this.ExtensionsImpl.writeHandlingErrorStatus(!0),r="",i="",this.isTypeError(e)?(r=e.message,i="HTTP Service Internal Error",[3,3]):[3,1]);case 1:return this.isHttpErrorResponse(e)?[4,this.getHttpErrorText(e.error)]:[3,3];case 2:switch(r=o.sent(),i=e.status.toString(),e.status){case 401:return this.ExtensionsImpl.readRedirectionStatus()?(this.log(this.loc("Error 401 on call")+" "+t+" "+this.loc("with redirect already in progress. Ignoring this event")),[2]):(this.log(this.loc("Error 401 on call")+" "+t+" "+this.loc("redirecting to login.")),this.ExtensionsImpl.writeRedirectionStatus(!0),this.ExtensionsImpl.writeRedirectingToLogin(!0),this.ExtensionsImpl.redirectToLogin(),[2]);case 400:case 403:return this.ExtensionsImpl.handleBlockingException(e.status,r),[2];case 404:return this.ExtensionsImpl.handleBlockingException(e.status,this.loc("Resource not found")),[2];case 444:return this.ExtensionsImpl.readRedirectionStatus()?this.log(this.loc("Error 444 on call")+" "+t+" "+this.loc("with redirect already in progress. Ignoring this event")):this.ExtensionsImpl.handleNotConfiguredException()||this.ExtensionsImpl.handleBlockingException(e.status,r),[2];case 0:r="Server might be offline"+(e.statusText?" ("+e.statusText+") ":"")}o.label=3;case 3:return this.ExtensionsImpl.handleException(i,r),[2]}}))}))},e.prototype.getHttpErrorText=function(e){var t=this;return new Promise((function(r){if(!(e instanceof Blob))return t.isCallResult(e)?r(e.error.message):r(null==e?void 0:e.toString());var i=new FileReader;i.onload=function(e){var i,o=e.target.result;try{i=JSON.parse(o)}catch(e){}return r(i&&t.isCallResult(i)?i.error.message:o)},i.readAsText(e)}))},e.prototype.isCallResult=function(e){var t;return!!(null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.message)},e.prototype.isHttpErrorResponse=function(e){return e instanceof t.HttpErrorResponse},e.prototype.isTypeError=function(e){return"TypeError"==e.name},e.prototype.registerErrorAndReturnEmptyObservable=function(e,t,r){return void 0===r&&(r=!0),r&&this.onError(e,t),new s.Observable((function(){}))},e.prototype.tryGetCacheInformations=function(e,t){var r=null,i=null,o=null,n=!!/#cache/gi.exec(e);if(n){var s=/#cache(:?-(\d+))/gi.exec(e);i=s?s[2]:null,e=e.replace("#cache"+(i?"-"+i:""),""),this.untimedCacheExpired()&&!i&&this.resetHttpUntimedCacheStorage(),r=this.makeCacheKey(e,t);var a=i?this.localStorageHttpTimedCacheKey:this.localStorageHttpCacheKey,l=this.localStorage.getLocalItem(a),c=l||{};c&&c[r]&&!this.timedCacheItemExpired(c[r])&&(i&&delete c[r].__expire,o=c[r])}return new m(e,n,r,i,this.utisExts.deepClone(o))},e.prototype.cacheResponse=function(e,t){var r=t.cacheTime?this.localStorageHttpTimedCacheKey:this.localStorageHttpCacheKey,i=this.localStorage.getLocalItem(r),o=i||{};o[t.cacheKey]=e,t.cacheTime&&(o[t.cacheKey].__expire=dayjs().add(t.cacheTime,"seconds")),this.localStorage.setLocalItem(r,o)},e.prototype.untimedCacheExpired=function(){var e=JSON.parse(localStorage.getItem(this.localStorageHttpCacheExpireKey));return!e||e&&dayjs(e)<dayjs()},e.prototype.timedCacheItemExpired=function(e){return dayjs(e.__expire)<dayjs()},e.prototype.resetHttpUntimedCacheStorage=function(){var e;return a(this,void 0,void 0,(function(){return l(this,(function(t){switch(t.label){case 0:return[4,this.localStorage.setItem(this.localStorageHttpCacheKey,{}).toPromise()];case 1:return t.sent(),localStorage.setItem(this.localStorageHttpCacheExpireKey,JSON.stringify(dayjs().add(null!==(e=this.CLIENT_CACHE_DURATION_S)&&void 0!==e?e:3600,"second"))),[2]}}))}))},e.prototype.resetHttpTimedCacheStorage=function(){return a(this,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,this.localStorage.setItem(this.localStorageHttpTimedCacheKey,{}).toPromise()];case 1:return e.sent(),[2]}}))}))},e.prototype.makeCacheKey=function(e,t){var r=(this.me?this.me.Idtenant:"")+(this.me&&this.CACHE_BY_USER?this.me.IdUser:""),i=t&&t.keys().length>0?t.keys().reduce((function(e,r){return e+","+r+"="+t.get(r)}),""):"";return r+"_"+e.substring(e.indexOf("api")+4)+"?"+i},e.prototype.getGUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},e.prototype.log=function(e){this.DEBUG_MODE&&console.log("@httpservice: "+e)},e.prototype.loc=function(e){return v[e]?v[e][this.LOCALE]:(console.warn("Untranslated message: "+e),"")},e}();S.decorators=[{type:r.Injectable}],S.ctorParameters=function(){return[{type:void 0,decorators:[{type:r.Inject,args:[p]}]},{type:y},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[c]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[u]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[d]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[h]}]},{type:Boolean,decorators:[{type:r.Optional},{type:r.Inject,args:[g]}]},{type:Boolean,decorators:[{type:r.Optional},{type:r.Inject,args:[f]}]},{type:t.HttpClient},{type:i.CacheService},{type:o.UtilityService}]};var E=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[S,y,{provide:c,useValue:null==t?void 0:t.httpInvalidation},{provide:h,useValue:null==t?void 0:t.clientCacheDurationS},{provide:p,useValue:null==t?void 0:t.backendUrl},{provide:u,useValue:(null==t?void 0:t.httpLocale)||"it-IT"},{provide:d,useValue:null==t?void 0:t.appName},{provide:g,useValue:null==t?void 0:t.cacheByUser},{provide:f,useValue:null==t?void 0:t.debugMode}]}},e}();E.decorators=[{type:r.NgModule}];var T=function(){},I=function(){};e.Download=I,e.HTTPService=S,e.HttpServiceExtensions=y,e.HttpServiceModuleConfig=T,e.HttpserviceModule=E,e["ɵa"]=c,e["ɵb"]=h,e["ɵc"]=p,e["ɵd"]=u,e["ɵe"]=d,e["ɵf"]=g,e["ɵg"]=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */function s(e,t,r,i){return new(r||(r=Promise))((function(o,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function s(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}l((i=i.apply(e,t||[])).next())}))}function l(e,t){var r,i,o,n,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(n){return function(s){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,i&&(o=2&n[0]?i.return:n[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,n[1])).done)return o;switch(i=0,o&&(n=[2&n[0],o.value]),n[0]){case 0:case 1:o=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,i=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==n[0]&&2!==n[0])){a=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){a.label=n[1];break}if(6===n[0]&&a.label<o[1]){a.label=o[1],o=n;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(n);break}o[2]&&a.ops.pop(),a.trys.pop();continue}n=t.call(e,a)}catch(e){n=[6,e],i=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,s])}}}Object.create;Object.create;var c=new r.InjectionToken("HTTP_INVALIDATION"),p=new r.InjectionToken("CLIENT_CACHE_DURATION_S"),u=new r.InjectionToken("BACKEND_URL"),h=new r.InjectionToken("HTTP_LOCALE"),d=new r.InjectionToken("APP_NAME"),g=new r.InjectionToken("CACHE_BY_USER"),f=new r.InjectionToken("DEBUG_MODE"),y=function(){function e(){}return e.prototype.retrieveAccessToken=function(){return""},e.prototype.retrieveIdentity=function(){return null},e.prototype.readRedirectingToLogin=function(){return!1},e.prototype.writeRedirectingToLogin=function(e){},e.prototype.redirectToLogin=function(){},e.prototype.readHandlingErrorStatus=function(){return!1},e.prototype.writeHandlingErrorStatus=function(e){},e.prototype.readRedirectionStatus=function(){return!1},e.prototype.writeRedirectionStatus=function(e){},e.prototype.handleNotConfiguredException=function(){return!1},e.prototype.handleBlockingException=function(e,t){console.error("ESHttpError Blocking Exception "+e+" "+t)},e.prototype.handleException=function(e,t){console.error("ESHttpError "+e+" "+t)},e}(),v={"Result for":{"en-US":"Result for","it-IT":"Risultato per"},"retrieved from cache":{"en-US":"retrieved from cache","it-IT":"recuperato dalla cache"},"Cached result for":{"en-US":"Cached result for","it-IT":"Messo in cache risultato per"},"Starting call":{"en-US":"Starting call","it-IT":"Inizio la chiamata"},"at URL":{"en-US":"at URL","it-IT":"all'URL"},"Invlalidating cache element":{"en-US":"Invlalidating cache element","it-IT":"Invalido elemento della cache"},"Finalizing call":{"en-US":"Finalizing call","it-IT":"Finalizzo chiamata"},"with status":{"en-US":"with status","it-IT":"con stato"},Success:{"en-US":"Success","it-IT":"Successso"},Failure:{"en-US":"Failure","it-IT":"Fallimento"},"Error 401 on call":{"en-US":"Error 401 on call","it-IT":"Errore 401 su chiamata"},"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"},"redirecting to login":{"en-US":"redirecting to login","it-IT":"redireziono al login"},"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"},"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"},"Error 444 on call":{"en-US":"Error 444 on call","it-IT":"Errore 444 su chiamata"},"Resource not found":{"en-US":"Resource not found","it-IT":"Risorsa non trovata"},"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"},"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"},"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"},"Caches succesfully persisted":{"en-US":"Caches succesfully persisted","it-IT":"Le cache sono state persistite con successo"},"Errors persisting modified caches":{"en-US":"Errors persisting modified caches","it-IT":"Errori nella persistizione delle cache (esiste persistizione? boh...)"}},m=function(e,t,r,i,o){this.finalUrl=e,this.cache=t,this.cacheKey=r,this.cacheTime=i,this.cacheItem=o},S=function(){function e(e,t,r,i,o,n,a,s,l,c,p){var u,h;this.BACKEND_URL=e,this.EXTENSION_CLASS=t,this.HTTP_INVALIDATION=r,this.LOCALE=i,this.APP_NAME=o,this.CLIENT_CACHE_DURATION_S=n,this.CACHE_BY_USER=a,this.DEBUG_MODE=s,this.http=l,this.localStorage=c,this.utisExts=p,this.callStatus={},this.localStorageHttpCacheKey=null,this.localStorageHttpTimedCacheKey=null,this.localStorageHttpCacheExpireKey=null,this.me=null,this.PersistTimedCacheASAP=!1,this.PersistUntimedCacheASAP=!1,this.LastThreeCompletedCalls=[],this.ExtensionsImpl=this.EXTENSION_CLASS||new y,this.me=this.ExtensionsImpl.retrieveIdentity(),this.localStorageHttpCacheKey=(null!==(u=this.APP_NAME)&&void 0!==u?u:"APP").replace(/\s/g,"_")+"_HttpCache",this.localStorageHttpTimedCacheKey=(null!==(h=this.APP_NAME)&&void 0!==h?h:"APP").replace(/\s/g,"_")+"_HttpTimedCache",this.localStorageHttpCacheExpireKey=this.localStorageHttpCacheKey+"_Expire",this.adjustOldStorageSystem(),this.untimedCacheExpired()&&this.resetHttpUntimedCacheStorage()}return e.prototype.adjustOldStorageSystem=function(){return s(this,void 0,void 0,(function(){var e,t;return l(this,(function(r){switch(r.label){case 0:return e=localStorage.getItem(this.localStorageHttpTimedCacheKey),t=localStorage.getItem(this.localStorageHttpCacheKey),e||t?(localStorage.removeItem(this.localStorageHttpTimedCacheKey),localStorage.removeItem(this.localStorageHttpCacheKey),e=e?JSON.parse(e):{},t=t?JSON.parse(t):{},[4,a.forkJoin([this.localStorage.setItem(this.localStorageHttpTimedCacheKey,e),this.localStorage.setItem(this.localStorageHttpCacheKey,t)]).toPromise()]):[2];case 1:return r.sent(),this.log(this.loc("Converted old storage system to new one")),[2]}}))}))},e.prototype.get=function(e,t,r,i,o){var s=this;return void 0===t&&(t=null),void 0===r&&(r=""),void 0===i&&(i=!0),void 0===o&&(o=null),a.from([this.defaultStartCall(e)]).pipe(n.concatMap((function(l){var c=s.tryGetCacheInformations(e,t);return c.cache&&c.cacheItem?(s.log(s.loc("Result for")+" "+e+" "+s.loc("retrieved from cache")),a.of(c.cacheItem).pipe(n.delay(0),n.finalize((function(){s.tryFinalizeByGuid(l)})))):s.http.get(c.finalUrl,{headers:s.getHeaders(r),params:t}).pipe(n.map((function(t){var r=t;return c.cache&&(s.cacheResponse(s.utisExts.deepClone(r),c),s.log(s.loc("Cached result for")+" "+e)),r})),n.catchError((function(e,t){return o&&o(),i?s.registerErrorAndReturnEmptyObservable(e,l):a.throwError(e)})),n.finalize((function(){s.tryFinalizeByGuid(l,c)})))})))},e.prototype.getRaw=function(e,t,r,i,o,s){var l=this;return void 0===t&&(t=null),void 0===r&&(r="arraybuffer"),void 0===i&&(i=""),void 0===o&&(o=!0),void 0===s&&(s=null),a.from([this.defaultStartCall(e)]).pipe(n.concatMap((function(c){var p=l.tryGetCacheInformations(e,t);return p.cache&&p.cacheItem?(l.log(l.loc("Result for")+" "+e+" "+l.loc("retrieved from cache")),a.of(p.cacheItem).pipe(n.delay(0),n.finalize((function(){l.tryFinalizeByGuid(c)})))):l.http.get(p.finalUrl,{responseType:r,headers:l.getHeaders(i),params:t}).pipe(n.map((function(t){return p.cache&&(l.cacheResponse(t,p),l.log(l.loc("Cached result for")+" "+e)),t})),n.catchError((function(e,t){return s&&s(),o?l.registerErrorAndReturnEmptyObservable(e,c):a.throwError(e)})),n.finalize((function(){l.tryFinalizeByGuid(c,p)})))})))},e.prototype.post=function(e,t,r,i,o){var s=this;return void 0===r&&(r=null),void 0===i&&(i=""),void 0===o&&(o=!0),a.from([this.defaultStartCall(e)]).pipe(n.concatMap((function(l){return s.http.post(e,t,{headers:s.getHeaders(i),params:r}).pipe(n.catchError((function(e,t){return o?s.registerErrorAndReturnEmptyObservable(e,l):a.throwError(e)})),n.finalize((function(){s.tryFinalizeByGuid(l)})))})))},e.prototype.delete=function(e,t,r,i){var o=this;return void 0===t&&(t=null),void 0===r&&(r=""),void 0===i&&(i=!0),a.from([this.defaultStartCall(e)]).pipe(n.concatMap((function(s){return o.http.delete(e,{headers:o.getHeaders(r),params:t}).pipe(n.catchError((function(e,t){return i?o.registerErrorAndReturnEmptyObservable(e,s):a.throwError(e)})),n.finalize((function(){o.tryFinalizeByGuid(s)})))})))},e.prototype.put=function(e,t,r,i,o){var s=this;return void 0===r&&(r=null),void 0===i&&(i=""),void 0===o&&(o=!0),a.from([this.defaultStartCall(e)]).pipe(n.concatMap((function(l){return s.http.put(e,t,{headers:s.getHeaders(i),params:r}).pipe(n.catchError((function(e,t){return o?s.registerErrorAndReturnEmptyObservable(e,l):a.throwError(e)})),n.finalize((function(){s.tryFinalizeByGuid(l)})))})))},e.prototype.postwithFiles=function(e,t,r){var i=this;return a.from([this.defaultStartCall(e)]).pipe(n.concatMap((function(o){var a=i.getFilesFormData(r);return a.append("body",JSON.stringify(t)),i.http.post(e,a,{headers:i.getHeaders(null,!0,null,null)}).pipe(n.catchError((function(e,t){return i.registerErrorAndReturnEmptyObservable(e,o)})),n.finalize((function(){i.tryFinalizeByGuid(o)})))})))},e.prototype.postGetFile=function(e,t,r,i,o,a,s){var l=this;void 0===o&&(o=null),void 0===a&&(a=!0);var c=this.defaultStartCall(e);this.http.post(e,t,{params:s,headers:this.getHeaders(),observe:"response",responseType:"blob"}).pipe(n.catchError((function(e,t){return o&&!a&&o(),l.registerErrorAndReturnEmptyObservable(e,c,a)})),n.finalize((function(){l.tryFinalizeByGuid(c)}))).subscribe((function(e){var t,n,a,s,l=window.URL.createObjectURL(e.body),c=null===(s=null===(a=null===(n=null===(t=e.headers.get("content-disposition"))||void 0===t?void 0:t.split(";")[1])||void 0===n?void 0:n.split("filename")[1])||void 0===a?void 0:a.split("=")[1])||void 0===s?void 0:s.trim().replace(/\"/g,"");i(l,r||c),o&&o()}))},e.prototype.getFile=function(e,t,r,i,o,a){var s=this;void 0===t&&(t=null),void 0===o&&(o=null),void 0===a&&(a=!0);var l=this.defaultStartCall(e);this.http.get(e,{params:t,headers:this.getHeaders(),observe:"response",responseType:"blob"}).pipe(n.catchError((function(e,t){return o&&!a&&o(),s.registerErrorAndReturnEmptyObservable(e,l,a)})),n.finalize((function(){s.tryFinalizeByGuid(l)}))).subscribe((function(e){var t,n,a,s,l=window.URL.createObjectURL(e.body),c=null===(s=null===(a=null===(n=null===(t=e.headers.get("content-disposition"))||void 0===t?void 0:t.split(";")[1])||void 0===n?void 0:n.split("filename")[1])||void 0===a?void 0:a.split("=")[1])||void 0===s?void 0:s.trim().replace(/\"/g,"");i(l,r||c),o&&o()}))},e.prototype.getFileNative=function(e,t){void 0===t&&(t=null);var r=e+(t?"?"+t.toString():"");window.location.href=r},e.prototype.getFileWithProgress=function(e,t,r){var i=this;void 0===t&&(t=null);var o=this.defaultStartCall(e);return this.http.get(e,{responseType:"blob",headers:this.getHeaders(),params:t,observe:"events",reportProgress:!0}).pipe(n.scan((function(e,t){if(i.isHttpProgressEvent(t))return{progress:t.total?t.loaded>t.total?100:Math.round(100*t.loaded/t.total):e.progress,state:"IN_PROGRESS",content:null};if(i.isHttpResponse(t)){if(t.body){var o=t.headers.get("content-disposition").split(";")[1].split("filename")[1].split("=")[1].trim().replace(/\"/g,""),n=window.URL.createObjectURL(t.body);r(n,o)}return{progress:100,state:"DONE",content:t.body}}return e}),{state:"PENDING",progress:0,content:null}),n.catchError((function(e,t){return i.registerErrorAndReturnEmptyObservable(e,o)})),n.finalize((function(){i.tryFinalizeByGuid(o)})))},e.prototype.isHttpResponse=function(e){return e.type===t.HttpEventType.Response},e.prototype.isHttpProgressEvent=function(e){return e.type===t.HttpEventType.DownloadProgress||e.type===t.HttpEventType.UploadProgress},e.prototype.defaultStartCall=function(e){var t=this.getGUID();return this.checkCacheInvalidation(e),this.callStatus[t]={url:e,success:!0},this.log(this.loc("Starting call")+" "+t+" "+this.loc("at URL")+": "+e),t},e.prototype.checkCacheInvalidation=function(e){var t=this,r=this.localStorage.getLocalItem(this.localStorageHttpCacheKey),i=/#cache(:?-(\d+))/gi.exec(e),o=i?i[2]:null,n=e.replace("#cache"+(o?"-"+o:""),"").replace(this.BACKEND_URL,"");if(r&&this.HTTP_INVALIDATION&&this.HTTP_INVALIDATION[n]){var a=this.HTTP_INVALIDATION[n];if(a&&0!=a.length){var s=[];a.forEach((function(e){var i=t.makeCacheKey(e,null);for(var o in r)-1!=o.indexOf(i)&&s.push(o)}));for(var l=0;l<s.length;l++){var c=s[l];this.log(this.loc("Invlalidating cache element")+" "+c),delete r[c]}this.localStorage.setLocalItem(this.localStorageHttpCacheKey,r)}}},e.prototype.tryFinalizeByGuid=function(e,t){return s(this,void 0,void 0,(function(){var r,i;return l(this,(function(o){switch(o.label){case 0:return this.log(this.loc("Finalizing call")+" "+e+" "+this.loc("with status")+": "+(this.callStatus[e]?this.callStatus[e].success?this.loc("Success"):this.loc("Failure"):"Unknown")),this.callStatus[e]&&(this.callStatus[e].success&&this.ExtensionsImpl.readRedirectionStatus()&&this.ExtensionsImpl.writeRedirectionStatus(!1),this.LastThreeCompletedCalls.unshift(this.callStatus[e].url),this.LastThreeCompletedCalls.length>3&&this.LastThreeCompletedCalls.pop(),delete this.callStatus[e]),t&&t.cache&&(this.PersistTimedCacheASAP=this.PersistTimedCacheASAP||!!t.cacheTime,this.PersistUntimedCacheASAP=this.PersistTimedCacheASAP||!t.cacheTime,this.log(this.loc("Marking cache to be persisted as soon as possible"))),!this.PersistTimedCacheASAP&&!this.PersistUntimedCacheASAP||0!=Object.keys(this.callStatus).length?[3,2]:(r=[],i="",this.PersistTimedCacheASAP&&(i=this.localStorageHttpTimedCacheKey,r.push(this.localStorage.setItem(i,this.localStorage.getLocalItem(i)))),this.PersistUntimedCacheASAP&&(i=this.localStorageHttpCacheKey,r.push(this.localStorage.setItem(i,this.localStorage.getLocalItem(i)))),this.log(this.loc("No more HTTP calls to be executed, entering idle state and persisting modified caches")+"..."),[4,a.forkJoin(r).toPromise()]);case 1:o.sent()?this.log(this.loc("Caches succesfully persisted")):this.log(this.loc("Errors persisting modified caches")),this.PersistTimedCacheASAP=!1,this.PersistUntimedCacheASAP=!1,o.label=2;case 2:return[2]}}))}))},e.prototype.getFilesFormData=function(e){var t=new FormData;return e&&(e.length?e.forEach((function(e){t.append("file",e,e.name)})):e.name&&t.append("files",e,e.name)),t},e.prototype.getHeaders=function(e,r,i,o){var n;void 0===e&&(e=""),void 0===r&&(r=!0),void 0===i&&(i="application/json"),void 0===o&&(o="application/json");var a=new t.HttpHeaders,s=this.ExtensionsImpl.retrieveAccessToken();return i&&(a=a.append("Content-Type",i)),e&&(a=a.append("X-TX-ID",e)),s&&r&&(a=a.append("Authorization","Bearer "+s)),o&&(a=a.append("Accept",o)),a=a.append("Accept-Language",null!==(n=this.LOCALE)&&void 0!==n?n:"it-IT")},e.prototype.onError=function(e,t){return s(this,void 0,void 0,(function(){var r,i;return l(this,(function(o){switch(o.label){case 0:return this.callStatus[t]&&(this.callStatus[t].success=!1),this.ExtensionsImpl.readRedirectingToLogin()?(this.log(this.loc("Redirecting to Login, ignoring HTTP error on call")+" "+t),[2]):this.ExtensionsImpl.readHandlingErrorStatus()?(this.log(this.loc("Already Handling an error, ignoring HTTP error on call")+" "+t),[2]):(this.ExtensionsImpl.writeHandlingErrorStatus(!0),r="",i="",this.isTypeError(e)?(r=e.message,i="HTTP Service Internal Error",[3,3]):[3,1]);case 1:return this.isHttpErrorResponse(e)?[4,this.getHttpErrorText(e.error)]:[3,3];case 2:switch(r=o.sent(),i=e.status.toString(),e.status){case 401:return this.ExtensionsImpl.readRedirectionStatus()?(this.log(this.loc("Error 401 on call")+" "+t+" "+this.loc("with redirect already in progress. Ignoring this event")),[2]):(this.log(this.loc("Error 401 on call")+" "+t+" "+this.loc("redirecting to login.")),this.ExtensionsImpl.writeRedirectionStatus(!0),this.ExtensionsImpl.writeRedirectingToLogin(!0),this.ExtensionsImpl.redirectToLogin(),[2]);case 400:case 403:return this.ExtensionsImpl.handleBlockingException(e.status,r),[2];case 404:return this.ExtensionsImpl.handleBlockingException(e.status,this.loc("Resource not found")),[2];case 444:return this.ExtensionsImpl.readRedirectionStatus()?this.log(this.loc("Error 444 on call")+" "+t+" "+this.loc("with redirect already in progress. Ignoring this event")):this.ExtensionsImpl.handleNotConfiguredException()||this.ExtensionsImpl.handleBlockingException(e.status,r),[2];case 0:r="Server might be offline"+(e.statusText?" ("+e.statusText+") ":"")}o.label=3;case 3:return this.ExtensionsImpl.handleException(i,r),[2]}}))}))},e.prototype.getHttpErrorText=function(e){var t=this;return new Promise((function(r){if(!(e instanceof Blob))return t.isCallResult(e)?r(e.error.message):r(null==e?void 0:e.toString());var i=new FileReader;i.onload=function(e){var i,o=e.target.result;try{i=JSON.parse(o)}catch(e){}return r(i&&t.isCallResult(i)?i.error.message:o)},i.readAsText(e)}))},e.prototype.isCallResult=function(e){var t;return!!(null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.message)},e.prototype.isHttpErrorResponse=function(e){return e instanceof t.HttpErrorResponse},e.prototype.isTypeError=function(e){return"TypeError"==e.name},e.prototype.registerErrorAndReturnEmptyObservable=function(e,t,r){return void 0===r&&(r=!0),r&&this.onError(e,t),new a.Observable((function(){}))},e.prototype.tryGetCacheInformations=function(e,t){var r=null,i=null,o=null,n=!!/#cache/gi.exec(e);if(n){var a=/#cache(:?-(\d+))/gi.exec(e);i=a?a[2]:null,e=e.replace("#cache"+(i?"-"+i:""),""),this.untimedCacheExpired()&&!i&&this.resetHttpUntimedCacheStorage(),r=this.makeCacheKey(e,t);var s=i?this.localStorageHttpTimedCacheKey:this.localStorageHttpCacheKey,l=this.localStorage.getLocalItem(s),c=l||{};c&&c[r]&&!this.timedCacheItemExpired(c[r])&&(i&&delete c[r].__expire,o=c[r])}return new m(e,n,r,i,this.utisExts.deepClone(o))},e.prototype.cacheResponse=function(e,t){var r=t.cacheTime?this.localStorageHttpTimedCacheKey:this.localStorageHttpCacheKey,i=this.localStorage.getLocalItem(r),o=i||{};o[t.cacheKey]=e,t.cacheTime&&(o[t.cacheKey].__expire=dayjs().add(t.cacheTime,"seconds")),this.localStorage.setLocalItem(r,o)},e.prototype.untimedCacheExpired=function(){var e=JSON.parse(localStorage.getItem(this.localStorageHttpCacheExpireKey));return!e||e&&dayjs(e)<dayjs()},e.prototype.timedCacheItemExpired=function(e){return dayjs(e.__expire)<dayjs()},e.prototype.resetHttpUntimedCacheStorage=function(){var e;return s(this,void 0,void 0,(function(){return l(this,(function(t){switch(t.label){case 0:return[4,this.localStorage.setItem(this.localStorageHttpCacheKey,{}).toPromise()];case 1:return t.sent(),localStorage.setItem(this.localStorageHttpCacheExpireKey,JSON.stringify(dayjs().add(null!==(e=this.CLIENT_CACHE_DURATION_S)&&void 0!==e?e:3600,"second"))),[2]}}))}))},e.prototype.resetHttpTimedCacheStorage=function(){return s(this,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,this.localStorage.setItem(this.localStorageHttpTimedCacheKey,{}).toPromise()];case 1:return e.sent(),[2]}}))}))},e.prototype.makeCacheKey=function(e,t){var r=(this.me?this.me.Idtenant:"")+(this.me&&this.CACHE_BY_USER?this.me.IdUser:""),i=t&&t.keys().length>0?t.keys().reduce((function(e,r){return e+","+r+"="+t.get(r)}),""):"";return r+"_"+e.substring(e.indexOf("api")+4)+"?"+i},e.prototype.getGUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},e.prototype.log=function(e){this.DEBUG_MODE&&console.log("@httpservice: "+e)},e.prototype.loc=function(e){return v[e]?v[e][this.LOCALE]:(console.warn("Untranslated message: "+e),"")},e}();S.decorators=[{type:r.Injectable}],S.ctorParameters=function(){return[{type:void 0,decorators:[{type:r.Inject,args:[u]}]},{type:y},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[c]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[h]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[d]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[p]}]},{type:Boolean,decorators:[{type:r.Optional},{type:r.Inject,args:[g]}]},{type:Boolean,decorators:[{type:r.Optional},{type:r.Inject,args:[f]}]},{type:t.HttpClient},{type:i.CacheService},{type:o.UtilityService}]};var E=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[S,y,{provide:c,useValue:null==t?void 0:t.httpInvalidation},{provide:p,useValue:null==t?void 0:t.clientCacheDurationS},{provide:u,useValue:null==t?void 0:t.backendUrl},{provide:h,useValue:(null==t?void 0:t.httpLocale)||"it-IT"},{provide:d,useValue:null==t?void 0:t.appName},{provide:g,useValue:null==t?void 0:t.cacheByUser},{provide:f,useValue:null==t?void 0:t.debugMode}]}},e}();E.decorators=[{type:r.NgModule}];var T=function(){},I=function(){};e.Download=I,e.HTTPService=S,e.HttpServiceExtensions=y,e.HttpServiceModuleConfig=T,e.HttpserviceModule=E,e["ɵa"]=c,e["ɵb"]=p,e["ɵc"]=u,e["ɵd"]=h,e["ɵe"]=d,e["ɵf"]=g,e["ɵg"]=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
16
16
|
//# sourceMappingURL=esfaenza-httpservice.umd.min.js.map
|