UNPKG

@isaiahiroko/ng-interceptors

Version:

Angular interceptors for token authorization, local and remote store synchronization and global notification

2 lines 2.45 kB
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core"),require("@isaiahiroko/ng-utils"),require("rxjs/operators"),require("rxjs"),require("@angular/common/http")):"function"==typeof define&&define.amd?define("@isaiahiroko/ng-interceptors",["exports","@angular/core","@isaiahiroko/ng-utils","rxjs/operators","rxjs","@angular/common/http"],r):r((t.isaiahiroko=t.isaiahiroko||{},t.isaiahiroko["ng-interceptors"]={}),t.ng.core,null,t.rxjs.operators,t.rxjs,t.ng.common.http)}(this,function(t,r,e,o,i,n){"use strict";var a=function(){function t(t){this.auth=t}return t.prototype.intercept=function(t,r){var e=t.clone({headers:t.headers.set("Authorization",this.auth.token())});return r.handle(e)},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[{type:e.AuthService}]},t}();var u=function(){function t(){}return t.prototype.start=function(t){},t.prototype.stop=function(){},t.prototype.notify=function(t,r){},t.prototype.toast=function(t,r){},t}(),s=function(){function t(t){this.notif=t}return t.prototype.intercept=function(t,r){var n=this;return this.notif.start(),r.handle(t).pipe(o.retryWhen(function(t){return t.pipe(o.zip(i.range(1,4)),o.mergeMap(function(t){var r=function s(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var o,n,i=e.call(t),a=[];try{for(;(void 0===r||0<r--)&&!(o=i.next()).done;)a.push(o.value)}catch(u){n={error:u}}finally{try{o&&!o.done&&(e=i["return"])&&e.call(i)}finally{if(n)throw n.error}}return a}(t,2),e=r[0],o=r[1];return n.notif.start("query"),2<o?i.throwError(e):i.timer(1e3*o)}))}),o.catchError(function(t){var r,e;return n.notif.start("buffer"),e=t.error instanceof ErrorEvent?(r="Client Error",t.error.message):(r="Network Info",t.statusText+" ("+t.status+")"),t.status,console.error({title:r,message:e}),i.throwError({title:r,message:e})}),o.finalize(function(){n.notif.stop()}))},t.decorators=[{type:r.Injectable}],t.ctorParameters=function(){return[{type:u}]},t}(),c=function(){function t(){}return t.prototype.intercept=function(t,r){return r.handle(t)},t.decorators=[{type:r.Injectable}],t}(),f=[{provide:n.HTTP_INTERCEPTORS,useClass:a,multi:!0},{provide:n.HTTP_INTERCEPTORS,useClass:s,multi:!0}];t.INTERCEPTORS=f,t.StoreSyncInterceptor=c,t.AuthInterceptor=a,t.LoaderServiceContract=u,t.NotifInterceptor=s,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=isaiahiroko-ng-interceptors.umd.min.js.map