DamienFontaine/angular-lunarc-core

View on GitHub
dist/bundles/angular-lunarc-core.umd.js

Summary

Maintainability
A
0 mins
Test Coverage
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("rxjs/Observable")):"function"==typeof define&&define.amd?define("@lunarc/core",["exports","@angular/core","@angular/common/http","rxjs/Observable"],t):t(e["angular-lunarc-core"]={},e.core,e.http,e.Observable)}(this,function(e,t,r,n){"use strict";var o=function(){return function(e){this.Id=e.Id,this.Username=e.Username,this.Email=e.Email}}(),i=function(){function e(){}return e.prototype.create=function(e){return new o(e)},e}(),u=function(){function e(e){this.http=e}return e.prototype.get=function(e){return this.http.get("/user/"+e.Id)},e.prototype.query=function(){return this.http.get("/user")},e.prototype.save=function(e){return this.http.post("/user",e)},e.prototype.update=function(e){return this.http.put("/user/"+e.Id,e)},e.prototype.delete=function(e){return this.http.delete("/user/"+e.Id)},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:r.HttpClient}]},e}(),s=function(){function e(){}return e.prototype.urlBase64Decode=function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("Illegal base64url string!")}return this.b64DecodeUnicode(t)},e.prototype.decodeToken=function(e){var t=e.split(".");if(3!==t.length)throw new Error("JWT must have 3 parts");var r=this.urlBase64Decode(t[1]);if(!r)throw new Error("Cannot decode the token");return JSON.parse(r)},e.prototype.getTokenExpirationDate=function(e){var t;if(!(t=this.decodeToken(e)).hasOwnProperty("exp"))return null;var r=new Date(0);return r.setUTCSeconds(t.exp),r},e.prototype.isTokenExpired=function(e,t){var r=this.getTokenExpirationDate(e);return t=t||0,null!=r&&!(r.valueOf()>(new Date).valueOf()+1e3*t)},e.prototype.b64DecodeUnicode=function(e){return decodeURIComponent(Array.prototype.map.call(atob(e),function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""))},e}(),c=function(){function e(e){this.userFactory=e,this.jwtHelper=new s}return e.prototype.setCredentials=function(){var e=localStorage.getItem("id_token"),t=this.jwtHelper.decodeToken(e);this.user=this.userFactory.create({Email:t.email,Id:t.id,Username:t.username})},e.prototype.storeToken=function(e){localStorage.setItem("id_token",e),this.setCredentials()},e.prototype.isAuthenticated=function(){var e=localStorage.getItem("id_token");try{this.jwtHelper.decodeToken(e);if(this.jwtHelper.isTokenExpired(e))return delete this.user,!1;this.setCredentials()}catch(e){return!1}return!0},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:i}]},e}(),a=function(){function e(){this.queue=[],this.currentMessage=""}return e.prototype.set=function(e){this.queue.push(e)},e.prototype.get=function(){return this.queue.length>0&&(this.currentMessage=this.queue.shift()),this.currentMessage},e.prototype.clear=function(){this.currentMessage=""},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[]},e}(),p=function(){return function(e){this.message=e.message,this.to=e.to,this.from=e.from||""}}(),l=function(){function e(){}return e.prototype.create=function(e){return new p(e)},e}(),f=function(){function e(e){this.http=e}return e.prototype.send=function(e){return this.http.post("/mail",e)},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:r.HttpClient}]},e}(),h=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[r.HttpClientModule],providers:[u,i,f,l,a,c]}]}],e.ctorParameters=function(){return[]},e}();e.CoreModule=h,e.UserService=u,e.User=o,e.UserFactory=i,e.MailService=f,e.MailFactory=l,e.Mail=p,e.FlashService=a,e.AuthService=c,Object.defineProperty(e,"__esModule",{value:!0})});