UNPKG

@stardyn/angular-auth

Version:

Angular Authentication Service - Lightweight, configurable authentication service for Angular applications with token management and role-based access control

1 lines 52.2 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@angular/core"),require("rxjs"),require("@stardyn/angular-data-source"),require("@stardyn/angular-helpers"),require("@angular/router"),require("@stardyn/angular-console")):"function"==typeof define&&define.amd?define(["@angular/core","rxjs","@stardyn/angular-data-source","@stardyn/angular-helpers","@angular/router","@stardyn/angular-console"],t):"object"==typeof exports?exports.StardynAngularAuth=t(require("@angular/core"),require("rxjs"),require("@stardyn/angular-data-source"),require("@stardyn/angular-helpers"),require("@angular/router"),require("@stardyn/angular-console")):e.StardynAngularAuth=t(e["ng.core"],e.rxjs,e.StardynAngularDataSource,e.StardynAngularHelpers,e["ng.router"],e.StardynAngularConsole)}(this,(e,t,r,n,o,i)=>(()=>{"use strict";var s={70:e=>{e.exports=i},186:e=>{e.exports=n},205:e=>{e.exports=r},274:e=>{e.exports=o},330:e=>{e.exports={a:"2.0.9"}},730:t=>{t.exports=e},968:e=>{e.exports=t}},a={};function u(e){var t=a[e];if(void 0!==t)return t.exports;var r=a[e]={exports:{}};return s[e](r,r.exports,u),r.exports}u.d=(e,t)=>{for(var r in t)u.o(t,r)&&!u.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},u.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),u.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var c={};u.r(c),u.d(c,{AuthGuard:()=>Ke,AuthRoleGuard:()=>Fe,AuthService:()=>U,LoginGuard:()=>He,StandardAuthResponseParser:()=>P,XConUserUtils:()=>ze,XconAuthIfRoleDirective:()=>Xe,XconPasswordHashType:()=>E,provideXconAuth:()=>ot,provideXconAuthStandard:()=>tt,provideXconAuthWithRefresh:()=>nt,withPermissions:()=>Ve,withPermissionsAndRedirect:()=>Be});var l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},l(e,t)};function h(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function d(e,t,r,n){var o,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,r,s):o(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}function f(e,t){return function(r,n){t(r,n,e)}}function p(e,t,r,n){return new(r||(r=Promise))(function(o,i){function s(e){try{u(n.next(e))}catch(t){i(t)}}function a(e){try{u(n.throw(e))}catch(t){i(t)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,a)}u((n=n.apply(e,t||[])).next())})}function g(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(u){a=[6,u],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}Object.create;function v(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(a){o={error:a}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function b(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function m(e){return this instanceof m?(this.v=e,this):new m(e)}function S(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(e,t||[]),i=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,c)}}),n[Symbol.asyncIterator]=function(){return this},n;function s(e,t){o[e]&&(n[e]=function(t){return new Promise(function(r,n){i.push([e,t,r,n])>1||a(e,t)})},t&&(n[e]=t(n[e])))}function a(e,t){try{(r=o[e](t)).value instanceof m?Promise.resolve(r.value.v).then(u,c):l(i[0][2],r)}catch(n){l(i[0][3],n)}var r}function u(e){a("next",e)}function c(e){a("throw",e)}function l(e,t){e(t),i.shift(),i.length&&a(i[0][0],i[0][1])}}function w(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=v(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise(function(n,o){(function(e,t,r,n){Promise.resolve(n).then(function(t){e({value:t,done:r})},t)})(n,o,(t=e[r](t)).done,t.value)})}}}Object.create;"function"==typeof SuppressedError&&SuppressedError;var E,_=u(730),A=u(968),T=u(205);!function(e){e.NONE="NONE",e.MD5_UPPER="MD5_UPPER",e.SHA256="SHA256"}(E||(E={}));class R{constructor(e){this.dconsole=e,this.config={authSiteKey:"",authSiteName:"",debugMode:!0,useRefreshToken:!1,passwordHashType:E.MD5_UPPER,loginEmailEndpoint:"/auth/login-by-email",loginGmailEndpoint:"/auth/google",loginMicrosoftEndpoint:"/auth/microsoft",logoutEndpoint:"/auth/logout",refreshTokenEndpoint:"/auth/refresh-token",redirectLoginUrl:"/login",redirectLogoutUrl:null}}configure(e){this.config={...this.config,...e},this.dconsole.debug("AuthConfigManager configured",this.config),this.config.passwordHashType||(this.config.passwordHashType=E.MD5_UPPER)}getConfig(){return{...this.config}}getLoginEndpoint(){return this.config.loginEmailEndpoint||"/auth/login-by-email"}getGoogleLoginEndpoint(){return this.config.loginGmailEndpoint||"/auth/google"}getMicrosoftLoginEndpoint(){return this.config.loginMicrosoftEndpoint||"/auth/microsoft"}getLogoutEndpoint(){return this.config.logoutEndpoint||"/auth/logout"}getRefreshTokenEndpoint(){return this.config.refreshTokenEndpoint||"/auth/refresh-token"}getUserInfoEndpoint(){return"/api/auth/user"}getEndpoints(){return{login:this.getLoginEndpoint(),google:this.getGoogleLoginEndpoint(),microsoft:this.getMicrosoftLoginEndpoint(),logout:this.getLogoutEndpoint(),refresh:this.getRefreshTokenEndpoint()}}getRedirectLoginUrl(){return this.config.redirectLoginUrl||"/login"}getRedirectLogoutUrl(){return this.config.redirectLogoutUrl||this.getRedirectLoginUrl()}getPasswordHashType(){return this.config.passwordHashType||E.MD5_UPPER}getAuthSiteKey(){return this.config.authSiteKey||""}getAuthSiteName(){return this.config.authSiteName||""}}class k{constructor(e,t){this.storageService=e,this.dconsole=t,this.TOKEN_KEY="auth_token",this.USER_KEY="user_data",this.TOKEN_EXPIRES_KEY="token_expires_in",this.TOKEN_TYPE_KEY="token_type"}storeTokens(e){this.dconsole.debug("Storing authentication tokens"),this.storageService.set(this.TOKEN_KEY,e.token),this.storageService.set(this.TOKEN_EXPIRES_KEY,this.calculateExpirationTime(e.expires_in)),this.storageService.set(this.TOKEN_TYPE_KEY,e.token_type),this.dconsole.debug("Tokens stored successfully")}calculateExpirationTime(e){return Math.floor(Date.now()/1e3)+e}storeUser(e){this.dconsole.debug("Storing user data"),this.storageService.set(this.USER_KEY,e)}getToken(){return this.storageService.get(this.TOKEN_KEY,null)}getTokenExpiration(){return this.storageService.get(this.TOKEN_EXPIRES_KEY,null)}getStoredUser(){return this.storageService.get(this.USER_KEY,null)}clearTokens(){this.dconsole.debug("Clearing authentication tokens"),this.storageService.set(this.TOKEN_KEY,null),this.storageService.set(this.TOKEN_EXPIRES_KEY,null),this.storageService.set(this.TOKEN_TYPE_KEY,null),this.storageService.clear(),this.dconsole.debug("Tokens cleared successfully")}clearUser(){this.dconsole.debug("Clearing user data"),this.storageService.set(this.USER_KEY,null)}clearAll(){this.dconsole.debug("Clearing all authentication data"),this.clearTokens(),this.clearUser()}}class x{constructor(e,t,r,n,o){this.dconsole=e,this.dataSource=t,this.dataSourceApi=r,this.dataSourceWithRefresh=n,this.dataSourceWithRefreshApi=o}validateDependencies(e){if(e.useRefreshToken){if(!this.dataSourceWithRefresh||!this.dataSourceWithRefreshApi)throw new Error("DataSourceWithRefresh and DataSourceWithRefreshApi must be provided when useRefreshToken is true")}else if(!this.dataSource||!this.dataSourceApi)throw new Error("DataSource and DataSourceApi must be provided when useRefreshToken is false");this.dconsole.debug("DataSource dependencies validated successfully")}getDataSource(){if(this.dataSourceWithRefresh)return this.dataSourceWithRefresh;if(this.dataSource)return this.dataSource;throw new Error("No DataSource available")}getDataSourceApi(){if(this.dataSourceWithRefreshApi)return this.dataSourceWithRefreshApi;if(this.dataSourceApi)return this.dataSourceApi;throw new Error("No DataSourceApi available")}setToken(e){this.dconsole.debug("Setting token in DataSource",{tokenPreview:e?.substring(0,20)+"...",tokenLength:e?.length,dataSourceType:this.getDataSourceType()});try{const t=this.getDataSource();t.tokenSet(e);const r=t.tokenGet(),n=r===e;if(this.dconsole.debug("Token set verification:",{success:n,tokenMatches:r===e,dataSourceType:this.getDataSourceType(),setTokenLength:e?.length,getTokenLength:r?.length}),n)this.dconsole.debug("Token set successfully in DataSource");else{this.dconsole.error("Token was not set correctly!",{expectedTokenPreview:e?.substring(0,20)+"...",actualTokenPreview:r?.substring(0,20)+"..."}),this.dconsole.warn("Attempting to force set token again..."),t.tokenSet(e);const n=t.tokenGet();this.dconsole.debug("Second verification:",{success:n===e,tokenLength:n?.length})}}catch(t){throw this.dconsole.error("Error setting token in DataSource:",t),t}}clearToken(){try{this.getDataSource().tokenClear(),this.dconsole.debug("Token cleared from DataSource")}catch(e){this.dconsole.warn("Failed to clear token from DataSource:",e)}}getDataSourceType(){return this.dataSourceWithRefresh?"Standard DataSource with Refresh":this.dataSource?"Standard DataSource":"No DataSource"}}var I=u(186);class P{static parseLoginResponse(e){return{token:e.data.token,refresh_token:e.data.refresh_token||null,expires_in:e.data.expires_in||3600,token_type:e.data.token_type||"Bearer",user:e.data.user}}static parseRefreshResponse(e,t){return{token:e.data.token,refresh_token:e.data.refresh_token,expires_in:e.data.expires_in||3600,token_type:e.data.token_type||"Bearer",user:t}}}class O{constructor(e,t,r){this.configManager=e,this.dataSourceManager=t,this.dconsole=r}async performLogin(e){try{return await this.performStandardLogin(e)}catch(t){throw this.dconsole?.error("Login error:",t),t}}async performStandardLogin(e){const t=this.configManager.getLoginEndpoint(),r={email:e.email,password:this.hashPassword(e.password)};this.dconsole?.debug("Performing standard login request",{endpoint:t,email:e.email});const n=await this.dataSourceManager.getDataSourceApi().post(t,r);if(n.success)return this.parseLoginResponse(n);throw new Error(n.message||"Login failed")}parseLoginResponse(e){return P.parseLoginResponse(e)}parseRefreshResponse(e,t){return P.parseRefreshResponse(e,t)}hashPassword(e){const t=this.configManager.getPasswordHashType(),r=this.configManager.getAuthSiteKey(),n=this.configManager.getAuthSiteName();switch(t){case E.SHA256:return I.SecureUtil.createCaptchaHash(e,r,n);case E.MD5_UPPER:return I.SecureUtil.Md5Upper(e);case E.NONE:return e;default:return this.dconsole?.warn(`Unknown password hash type: ${t}, using MD5_UPPER`),I.SecureUtil.Md5Upper(e)}}}let U=class{constructor(e,t,r,n,o,i,s){this.router=e,this.storageService=t,this.currentUserSubject=new A.BehaviorSubject(null),this.currentUser$=this.currentUserSubject.asObservable(),this.isAuthenticatedSubject=new A.BehaviorSubject(!1),this.isAuthenticated$=this.isAuthenticatedSubject.asObservable(),this.dconsole=r,this.dconsole.debug("AuthService initialized"),this.configManager=new R(this.dconsole),this.tokenManager=new k(this.storageService,this.dconsole),this.dataSourceManager=new x(this.dconsole,n,o,i,s),this.loginHandler=new O(this.configManager,this.dataSourceManager,this.dconsole)}configure(e){this.configManager.configure(e),this.dataSourceManager.validateDependencies(this.configManager.getConfig())}async initialize(){this.dconsole.info("AuthService Initializing with endpoints:",this.configManager.getEndpoints()),this.loadStoredAuth()}login(e){return new A.Observable(t=>{this.loginHandler.performLogin(e).then(e=>{this.handleAuthSuccess(e),t.next(e),t.complete()}).catch(e=>{t.error(this.handleAuthError(e))})})}loginWithEmail(e){return new A.Observable(t=>{this.loginHandler.performLogin(e).then(e=>{this.handleAuthSuccess(e),t.next(e),t.complete()}).catch(e=>{t.error(this.handleAuthError(e))})})}loginWithGoogle(){return new A.Observable(e=>{const t=this.configManager.getGoogleLoginEndpoint();this.dconsole?.debug("Performing Google login request",{endpoint:t}),this.dataSourceManager.getDataSourceApi().post(t,{}).then(t=>{if(t.success){const r=this.loginHandler.parseLoginResponse(t);this.handleAuthSuccess(r),e.next(r),e.complete()}else e.error(new Error(t.message||"Google login failed"))}).catch(t=>{e.error(this.handleAuthError(t))})})}loginWithMicrosoft(e){return new A.Observable(t=>{const r=this.configManager.getMicrosoftLoginEndpoint();this.dconsole?.debug("Performing Microsoft login request",{endpoint:r}),this.dataSourceManager.getDataSourceApi().post(r,e).then(e=>{if(e.success){const r=this.loginHandler.parseLoginResponse(e);this.handleAuthSuccess(r),t.next(r),t.complete()}else t.error(new Error(e.message||"Microsoft login failed"))}).catch(e=>{t.error(this.handleAuthError(e))})})}async logout(){console.log("🔴 LOGOUT: Starting logout process...");try{const e={},t=this.configManager.getLogoutEndpoint();console.log("🔴 LOGOUT: Making API call to:",t),this.dconsole?.debug("Performing logout request",{endpoint:t});const r=await this.dataSourceManager.getDataSourceApi().post(t,e);console.log("🔴 LOGOUT: API response:",r)}catch(e){console.error("🔴 LOGOUT: API call failed:",e),this.dconsole?.error("Logout API call failed:",e)}console.log("🔴 LOGOUT: Clearing auth data..."),this.clearAuthData(),console.log("🔴 LOGOUT: Performing redirect..."),await this.performLogoutRedirect()}async logoutLocal(){console.log("🔴 LOCAL LOGOUT: Starting local logout..."),this.dconsole?.debug("Performing local logout (no API call)"),this.clearAuthData(),await this.performLogoutRedirect()}async performLogoutRedirect(){try{const e=this.configManager.getRedirectLoginUrl();console.log("🔴 REDIRECT: Redirecting to login page:",e),console.log("🔴 REDIRECT: Current URL:",this.router.url),this.dconsole?.debug("Redirecting after logout to login page:",e);const t=await this.router.navigate([e],{replaceUrl:!0});console.log("🔴 REDIRECT: Navigation result:",t),t||(console.warn("🔴 REDIRECT: Angular router failed, using window.location"),window.location.href=e)}catch(e){console.error("🔴 REDIRECT: Redirect failed:",e),this.dconsole?.error("Logout redirect failed:",e);const t="/login";console.log("🔴 REDIRECT: Using fallback URL:",t),window.location.href=t}}async redirectLogout(){console.log("🔴 REDIRECT_LOGOUT: Called (legacy method)"),await this.performLogoutRedirect()}async refreshToken(){if(!this.configManager.getConfig().useRefreshToken)return this.dconsole?.warn("Refresh token is disabled in configuration"),T.ApiResponse.create({success:!1,message:"Refresh token not supported"});try{const e={refresh_token:""},t=this.configManager.getRefreshTokenEndpoint();this.dconsole?.debug("Performing token refresh request",{endpoint:t});const r=await this.dataSourceManager.getDataSourceApi().post(t,e);if(r.success){const e=this.loginHandler.parseRefreshResponse(r,this.getCurrentUser());return this.handleRefreshSuccess(e),r}return this.clearAuthData(),r}catch(e){return this.dconsole?.error("Token refresh failed:",e),this.clearAuthData(),T.ApiResponse.create({success:!1,message:"Token refresh failed"})}}getCurrentUser(){return this.currentUserSubject.value}getConfiguration(){return this.configManager.getConfig()}handleAuthSuccess(e){this.tokenManager.storeTokens(e),this.tokenManager.storeUser(e.user),this.dataSourceManager.setToken(e.token),this.currentUserSubject.next(e.user),this.setAuthState(!0);this.configManager.getConfig().useRefreshToken&&this.scheduleTokenRefresh(),this.dconsole?.log("Auth success handled, user:",e.user)}handleRefreshSuccess(e){this.tokenManager.storeTokens(e),this.dataSourceManager.setToken(e.token),this.scheduleTokenRefresh(),this.dconsole?.log("Token refresh successful, new token set")}handleAuthError(e){if(this.dconsole?.error("Authentication error:",e),this.clearAuthData(),e.response)switch(e.response.status){case 401:return new Error("Invalid credentials");case 403:return new Error("Access forbidden");case 422:return new Error("Invalid input data");case 500:return new Error("Server error");default:return new Error("Authentication failed")}return"NETWORK_ERROR"===e.code?new Error("Network connection failed"):new Error(e.message||"Authentication failed")}clearAuthData(){this.tokenManager.clearAll(),this.dataSourceManager.clearToken(),this.currentUserSubject.next(null),this.clearTokenRefreshTimer(),this.setAuthState(!1)}loadStoredAuth(){const e=this.tokenManager.getStoredUser(),t=this.tokenManager.getToken(),r=this.tokenManager.getTokenExpiration();if(this.dconsole.info("AuthService loadStoredAuth:",t,r),e&&t&&r)try{const n=Math.floor(Date.now()/1e3);this.dconsole.info("AuthService loadStoredAuth:",n,r),n<r?(this.currentUserSubject.next(e),this.setAuthState(!0),this.dataSourceManager.setToken(t),this.dconsole?.log("Stored auth loaded successfully, user:",e)):(this.dconsole?.log("Stored token expired, clearing auth data"),this.clearAuthData())}catch(n){this.dconsole?.error("Error parsing stored user data:",n),this.clearAuthData()}else this.dconsole?.log("No valid stored auth found")}setAuthState(e){e?this.scheduleTokenRefresh():this.clearTokenRefreshTimer(),this.isAuthenticatedSubject.next(e)}scheduleTokenRefresh(){if(!this.configManager.getConfig().useRefreshToken)return void this.dconsole.info("AuthService refresh token disabled.");const e=this.tokenManager.getTokenExpiration();if(!e)return void this.dconsole.info("AuthService scheduleTokenRefresh expiresIn:",e);const t=Math.floor(Date.now()/1e3),r=e-t,n=Math.max(r-300,60);this.dconsole.info("AuthService scheduleTokenRefresh :",t,r,n),n>0?(this.dconsole?.log(`Token refresh scheduled in ${n} seconds`),this.tokenExpirationTimer=setTimeout(()=>{this.dconsole?.log("Attempting scheduled token refresh..."),this.refreshToken()},1e3*n)):(this.dconsole?.log("Token will expire soon, refreshing immediately"),this.refreshToken())}clearTokenRefreshTimer(){this.tokenExpirationTimer&&(clearTimeout(this.tokenExpirationTimer),this.tokenExpirationTimer=null)}};function M(e){return"function"==typeof e}function D(e){return M(null==e?void 0:e.lift)}function N(e){return function(t){if(D(t))return t.lift(function(t){try{return e(t,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}U=d([(0,_.Injectable)(),f(3,(0,_.Optional)()),f(4,(0,_.Optional)()),f(5,(0,_.Optional)()),f(6,(0,_.Optional)())],U);var C=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function L(e){return M(null==e?void 0:e.then)}function j(e){var t=e(function(e){Error.call(e),e.stack=(new Error).stack});return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var W=j(function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}});function G(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var $=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,r,n,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=v(i),a=s.next();!a.done;a=s.next()){a.value.remove(this)}}catch(f){e={error:f}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var u=this.initialTeardown;if(M(u))try{u()}catch(p){o=p instanceof W?p.errors:[p]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var l=v(c),h=l.next();!h.done;h=l.next()){var d=h.value;try{H(d)}catch(g){o=null!=o?o:[],g instanceof W?o=b(b([],y(o)),y(g.errors)):o.push(g)}}}catch(m){r={error:m}}finally{try{h&&!h.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}}if(o)throw new W(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)H(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&G(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&G(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),q=$.EMPTY;function K(e){return e instanceof $||e&&"closed"in e&&M(e.remove)&&M(e.add)&&M(e.unsubscribe)}function H(e){M(e)?e():e.unsubscribe()}var Y={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},z={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var o=z.delegate;return(null==o?void 0:o.setTimeout)?o.setTimeout.apply(o,b([e,t],y(r))):setTimeout.apply(void 0,b([e,t],y(r)))},clearTimeout:function(e){var t=z.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function F(e){z.setTimeout(function(){var t=Y.onUnhandledError;if(!t)throw e;t(e)})}function V(){}var B=X("C",void 0,void 0);function X(e,t,r){return{kind:e,value:t,error:r}}var J=null;function Q(e){if(Y.useDeprecatedSynchronousErrorHandling){var t=!J;if(t&&(J={errorThrown:!1,error:null}),e(),t){var r=J,n=r.errorThrown,o=r.error;if(J=null,n)throw o}}else e()}var Z=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,K(t)&&t.add(r)):r.destination=se,r}return h(t,e),t.create=function(e,t,r){return new ne(e,t,r)},t.prototype.next=function(e){this.isStopped?ie(function(e){return X("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ie(X("E",void 0,e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ie(B,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}($),ee=Function.prototype.bind;function te(e,t){return ee.call(e,t)}var re=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(r){oe(r)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){oe(r)}else oe(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){oe(t)}},e}(),ne=function(e){function t(t,r,n){var o,i,s=e.call(this)||this;M(t)||!t?o={next:null!=t?t:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:s&&Y.useDeprecatedNextContext?((i=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},o={next:t.next&&te(t.next,i),error:t.error&&te(t.error,i),complete:t.complete&&te(t.complete,i)}):o=t;return s.destination=new re(o),s}return h(t,e),t}(Z);function oe(e){var t;Y.useDeprecatedSynchronousErrorHandling?(t=e,Y.useDeprecatedSynchronousErrorHandling&&J&&(J.errorThrown=!0,J.error=t)):F(e)}function ie(e,t){var r=Y.onStoppedNotification;r&&z.setTimeout(function(){return r(e,t)})}var se={closed:!0,next:V,error:function(e){throw e},complete:V},ae="function"==typeof Symbol&&Symbol.observable||"@@observable";function ue(e){return e}function ce(e){return 0===e.length?ue:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)}}var le=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n,o=this,i=(n=e)&&n instanceof Z||function(e){return e&&M(e.next)&&M(e.error)&&M(e.complete)}(n)&&K(n)?e:new ne(e,t,r);return Q(function(){var e=o,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?o._subscribe(i):o._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var r=this;return new(t=he(t))(function(t,n){var o=new ne({next:function(t){try{e(t)}catch(r){n(r),o.unsubscribe()}},error:n,complete:t});r.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[ae]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ce(e)(this)},e.prototype.toPromise=function(e){var t=this;return new(e=he(e))(function(e,r){var n;t.subscribe(function(e){return n=e},function(e){return r(e)},function(){return e(n)})})},e.create=function(t){return new e(t)},e}();function he(e){var t;return null!==(t=null!=e?e:Y.Promise)&&void 0!==t?t:Promise}function de(e){return M(e[ae])}function fe(e){return Symbol.asyncIterator&&M(null==e?void 0:e[Symbol.asyncIterator])}function pe(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var ge="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ve(e){return M(null==e?void 0:e[ge])}function ye(e){return S(this,arguments,function(){var t,r,n;return g(this,function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,m(t.read())];case 3:return r=o.sent(),n=r.value,r.done?[4,m(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,m(n)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function be(e){return M(null==e?void 0:e.getReader)}function me(e){if(e instanceof le)return e;if(null!=e){if(de(e))return o=e,new le(function(e){var t=o[ae]();if(M(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")});if(C(e))return n=e,new le(function(e){for(var t=0;t<n.length&&!e.closed;t++)e.next(n[t]);e.complete()});if(L(e))return r=e,new le(function(e){r.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,F)});if(fe(e))return Se(e);if(ve(e))return t=e,new le(function(e){var r,n;try{for(var o=v(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(a){r={error:a}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}e.complete()});if(be(e))return Se(ye(e))}var t,r,n,o;throw pe(e)}function Se(e){return new le(function(t){(function(e,t){var r,n,o,i;return p(this,void 0,void 0,function(){var s,a;return g(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),r=w(e),u.label=1;case 1:return[4,r.next()];case 2:if((n=u.sent()).done)return[3,4];if(s=n.value,t.next(s),t.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=u.sent(),o={error:a},[3,11];case 6:return u.trys.push([6,,9,10]),n&&!n.done&&(i=r.return)?[4,i.call(r)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})})(e,t).catch(function(e){return t.error(e)})})}function we(e,t,r,n,o){return new Ee(e,t,r,n,o)}var Ee=function(e){function t(t,r,n,o,i,s){var a=e.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=s,a._next=r?function(e){try{r(e)}catch(n){t.error(n)}}:e.prototype._next,a._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=n?function(){try{n()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return h(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(Z);var _e=function(e){function t(t,r){return e.call(this)||this}return h(t,e),t.prototype.schedule=function(e,t){return void 0===t&&(t=0),this},t}($),Ae={setInterval:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var o=Ae.delegate;return(null==o?void 0:o.setInterval)?o.setInterval.apply(o,b([e,t],y(r))):setInterval.apply(void 0,b([e,t],y(r)))},clearInterval:function(e){var t=Ae.delegate;return((null==t?void 0:t.clearInterval)||clearInterval)(e)},delegate:void 0},Te=function(e){function t(t,r){var n=e.call(this,t,r)||this;return n.scheduler=t,n.work=r,n.pending=!1,n}return h(t,e),t.prototype.schedule=function(e,t){var r;if(void 0===t&&(t=0),this.closed)return this;this.state=e;var n=this.id,o=this.scheduler;return null!=n&&(this.id=this.recycleAsyncId(o,n,t)),this.pending=!0,this.delay=t,this.id=null!==(r=this.id)&&void 0!==r?r:this.requestAsyncId(o,this.id,t),this},t.prototype.requestAsyncId=function(e,t,r){return void 0===r&&(r=0),Ae.setInterval(e.flush.bind(e,this),r)},t.prototype.recycleAsyncId=function(e,t,r){if(void 0===r&&(r=0),null!=r&&this.delay===r&&!1===this.pending)return t;null!=t&&Ae.clearInterval(t)},t.prototype.execute=function(e,t){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var r=this._execute(e,t);if(r)return r;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,t){var r,n=!1;try{this.work(e)}catch(o){n=!0,r=o||new Error("Scheduled action threw falsy error")}if(n)return this.unsubscribe(),r},t.prototype.unsubscribe=function(){if(!this.closed){var t=this.id,r=this.scheduler,n=r.actions;this.work=this.state=this.scheduler=null,this.pending=!1,G(n,this),null!=t&&(this.id=this.recycleAsyncId(r,t,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t}(_e),Re={now:function(){return(Re.delegate||Date).now()},delegate:void 0},ke=function(){function e(t,r){void 0===r&&(r=e.now),this.schedulerActionCtor=t,this.now=r}return e.prototype.schedule=function(e,t,r){return void 0===t&&(t=0),new this.schedulerActionCtor(this,e).schedule(r,t)},e.now=Re.now,e}();new(function(e){function t(t,r){void 0===r&&(r=ke.now);var n=e.call(this,t,r)||this;return n.actions=[],n._active=!1,n}return h(t,e),t.prototype.flush=function(e){var t=this.actions;if(this._active)t.push(e);else{var r;this._active=!0;do{if(r=e.execute(e.state,e.delay))break}while(e=t.shift());if(this._active=!1,r){for(;e=t.shift();)e.unsubscribe();throw r}}},t}(ke))(Te);function xe(e){return e[e.length-1]}function Ie(e){return(t=xe(e))&&M(t.schedule)?e.pop():void 0;var t}function Pe(e,t,r,n,o){void 0===n&&(n=0),void 0===o&&(o=!1);var i=t.schedule(function(){r(),o?e.add(this.schedule(null,n)):this.unsubscribe()},n);if(e.add(i),!o)return i}Array.isArray,Object.getPrototypeOf,Object.prototype,Object.keys;function Oe(e,t){return void 0===t&&(t=0),N(function(r,n){r.subscribe(we(n,function(r){return Pe(n,e,function(){return n.next(r)},t)},function(){return Pe(n,e,function(){return n.complete()},t)},function(r){return Pe(n,e,function(){return n.error(r)},t)}))})}function Ue(e,t){return void 0===t&&(t=0),N(function(r,n){n.add(e.schedule(function(){return r.subscribe(n)},t))})}function Me(e,t){if(!e)throw new Error("Iterable cannot be null");return new le(function(r){Pe(r,t,function(){var n=e[Symbol.asyncIterator]();Pe(r,t,function(){n.next().then(function(e){e.done?r.complete():r.next(e.value)})},0,!0)})})}function De(e,t){if(null!=e){if(de(e))return function(e,t){return me(e).pipe(Ue(t),Oe(t))}(e,t);if(C(e))return function(e,t){return new le(function(r){var n=0;return t.schedule(function(){n===e.length?r.complete():(r.next(e[n++]),r.closed||this.schedule())})})}(e,t);if(L(e))return function(e,t){return me(e).pipe(Ue(t),Oe(t))}(e,t);if(fe(e))return Me(e,t);if(ve(e))return function(e,t){return new le(function(r){var n;return Pe(r,t,function(){n=e[ge](),Pe(r,t,function(){var e,t,o;try{t=(e=n.next()).value,o=e.done}catch(i){return void r.error(i)}o?r.complete():r.next(t)},0,!0)}),function(){return M(null==n?void 0:n.return)&&n.return()}})}(e,t);if(be(e))return function(e,t){return Me(ye(e),t)}(e,t)}throw pe(e)}function Ne(e,t){return N(function(r,n){var o=0;r.subscribe(we(n,function(r){n.next(e.call(t,r,o++))}))})}Array.isArray;Array.isArray;var Ce=j(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Le=function(e){function t(){var t=e.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return h(t,e),t.prototype.lift=function(e){var t=new je(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new Ce},t.prototype.next=function(e){var t=this;Q(function(){var r,n;if(t._throwIfClosed(),!t.isStopped){t.currentObservers||(t.currentObservers=Array.from(t.observers));try{for(var o=v(t.currentObservers),i=o.next();!i.done;i=o.next()){i.value.next(e)}}catch(s){r={error:s}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}})},t.prototype.error=function(e){var t=this;Q(function(){if(t._throwIfClosed(),!t.isStopped){t.hasError=t.isStopped=!0,t.thrownError=e;for(var r=t.observers;r.length;)r.shift().error(e)}})},t.prototype.complete=function(){var e=this;Q(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,r=this,n=r.hasError,o=r.isStopped,i=r.observers;return n||o?q:(this.currentObservers=null,i.push(e),new $(function(){t.currentObservers=null,G(i,e)}))},t.prototype._checkFinalizedStatuses=function(e){var t=this,r=t.hasError,n=t.thrownError,o=t.isStopped;r?e.error(n):o&&e.complete()},t.prototype.asObservable=function(){var e=new le;return e.source=this,e},t.create=function(e,t){return new je(e,t)},t}(le),je=function(e){function t(t,r){var n=e.call(this)||this;return n.destination=t,n.source=r,n}return h(t,e),t.prototype.next=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===r||r.call(t,e)},t.prototype.error=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===r||r.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,r;return null!==(r=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==r?r:q},t}(Le);var We,Ge=new le(function(e){return e.complete()});function $e(e){return e<=0?function(){return Ge}:N(function(t,r){var n=0;t.subscribe(we(r,function(t){++n<=e&&(r.next(t),e<=n&&r.complete())}))})}function qe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(e,t){return t?De(e,t):me(e)}(e,Ie(e))}!function(e){e.NEXT="N",e.ERROR="E",e.COMPLETE="C"}(We||(We={}));!function(){function e(e,t,r){this.kind=e,this.value=t,this.error=r,this.hasValue="N"===e}e.prototype.observe=function(e){return function(e,t){var r,n,o,i=e,s=i.kind,a=i.value,u=i.error;if("string"!=typeof s)throw new TypeError('Invalid notification, missing "kind"');"N"===s?null===(r=t.next)||void 0===r||r.call(t,a):"E"===s?null===(n=t.error)||void 0===n||n.call(t,u):null===(o=t.complete)||void 0===o||o.call(t)}(this,e)},e.prototype.do=function(e,t,r){var n=this,o=n.kind,i=n.value,s=n.error;return"N"===o?null==e?void 0:e(i):"E"===o?null==t?void 0:t(s):null==r?void 0:r()},e.prototype.accept=function(e,t,r){var n;return M(null===(n=e)||void 0===n?void 0:n.next)?this.observe(e):this.do(e,t,r)},e.prototype.toObservable=function(){var e,t,r,n,o=this,i=o.kind,s=o.value,a=o.error,u="N"===i?qe(s):"E"===i?(r=M(e=function(){return a})?e:function(){return e},n=function(e){return e.error(r())},new le(t?function(e){return t.schedule(n,0,e)}:n)):"C"===i?Ge:0;if(!u)throw new TypeError("Unexpected notification kind "+i);return u},e.createNext=function(t){return new e("N",t)},e.createError=function(t){return new e("E",void 0,t)},e.createComplete=function(){return e.completeNotification},e.completeNotification=new e("C")}();j(function(e){return function(){e(this),this.name="ArgumentOutOfRangeError",this.message="argument out of range"}});j(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});!function(e){function t(t,r){var n=e.call(this)||this;return n.source=t,n.subjectFactory=r,n._subject=null,n._refCount=0,n._connection=null,D(t)&&(n.lift=t.lift),n}h(t,e),t.prototype._subscribe=function(e){return this.getSubject().subscribe(e)},t.prototype.getSubject=function(){var e=this._subject;return e&&!e.isStopped||(this._subject=this.subjectFactory()),this._subject},t.prototype._teardown=function(){this._refCount=0;var e=this._connection;this._subject=this._connection=null,null==e||e.unsubscribe()},t.prototype.connect=function(){var e=this,t=this._connection;if(!t){t=this._connection=new $;var r=this.getSubject();t.add(this.source.subscribe(we(r,void 0,function(){e._teardown(),r.complete()},function(t){e._teardown(),r.error(t)},function(){return e._teardown()}))),t.closed&&(this._connection=null,t=$.EMPTY)}return t},t.prototype.refCount=function(){return N(function(e,t){var r=null;e._refCount++;var n=we(t,void 0,void 0,void 0,function(){if(!e||e._refCount<=0||0<--e._refCount)r=null;else{var n=e._connection,o=r;r=null,!n||o&&n!==o||n.unsubscribe(),t.unsubscribe()}});e.subscribe(n),n.closed||(r=e.connect())})(this)}}(le);!function(e){function t(t){var r=e.call(this)||this;return r._value=t,r}h(t,e),Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(t){var r=e.prototype._subscribe.call(this,t);return!r.closed&&t.next(this._value),r},t.prototype.getValue=function(){var e=this,t=e.hasError,r=e.thrownError,n=e._value;if(t)throw r;return this._throwIfClosed(),n},t.prototype.next=function(t){e.prototype.next.call(this,this._value=t)}}(Le);!function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._value=null,t._hasValue=!1,t._isComplete=!1,t}h(t,e),t.prototype._checkFinalizedStatuses=function(e){var t=this,r=t.hasError,n=t._hasValue,o=t._value,i=t.thrownError,s=t.isStopped,a=t._isComplete;r?e.error(i):(s||a)&&(n&&e.next(o),e.complete())},t.prototype.next=function(e){this.isStopped||(this._value=e,this._hasValue=!0)},t.prototype.complete=function(){var t=this,r=t._hasValue,n=t._value;t._isComplete||(this._isComplete=!0,r&&e.prototype.next.call(this,n),e.prototype.complete.call(this))}}(Le);!function(e){function t(t,r,n){void 0===t&&(t=1/0),void 0===r&&(r=1/0),void 0===n&&(n=Re);var o=e.call(this)||this;return o._bufferSize=t,o._windowTime=r,o._timestampProvider=n,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,t),o._windowTime=Math.max(1,r),o}h(t,e),t.prototype.next=function(t){var r=this,n=r.isStopped,o=r._buffer,i=r._infiniteTimeWindow,s=r._timestampProvider,a=r._windowTime;n||(o.push(t),!i&&o.push(s.now()+a)),this._trimBuffer(),e.prototype.next.call(this,t)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var t=this._innerSubscribe(e),r=this._infiniteTimeWindow,n=this._buffer.slice(),o=0;o<n.length&&!e.closed;o+=r?1:2)e.next(n[o]);return this._checkFinalizedStatuses(e),t},t.prototype._trimBuffer=function(){var e=this,t=e._bufferSize,r=e._timestampProvider,n=e._buffer,o=e._infiniteTimeWindow,i=(o?1:2)*t;if(t<1/0&&i<n.length&&n.splice(0,n.length-i),!o){for(var s=r.now(),a=0,u=1;u<n.length&&n[u]<=s;u+=2)a=u;a&&n.splice(0,a+1)}}}(Le);j(function(e){return function(t){e(this),this.name="SequenceError",this.message=t}}),j(function(e){return function(t){e(this),this.name="NotFoundError",this.message=t}});j(function(e){return function(t){void 0===t&&(t=null),e(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=t}});let Ke=class{constructor(e,t){this.authService=e,this.router=t}canActivate(e,t){return this.checkAuth(t.url)}canActivateChild(e,t){return this.checkAuth(t.url)}checkAuth(e){return this.authService.isAuthenticated$.pipe($e(1),Ne(t=>{if(t)return!0;{const t=this.authService.getConfiguration(),r=t?.redirectLoginUrl||"/login";if(e===r||e.startsWith(`${r}?`)||e.startsWith(`${r}/`))return console.warn("AuthGuard: Already on login page, preventing redirect loop"),!1;const n=this.router.url;return n===r||n.startsWith(`${r}?`)||n.startsWith(`${r}/`)?(console.warn("AuthGuard: Browser already on login page, preventing redirect loop"),!1):(console.log("AuthGuard: Redirecting unauthenticated user from",e,"to",r),this.router.navigate([r],{queryParams:{returnUrl:e},replaceUrl:!0}).catch(e=>{console.error("AuthGuard: Navigation error:",e)}),!1)}}))}};Ke=d([(0,_.Injectable)({providedIn:"root"})],Ke);let He=class{constructor(e,t){this.authService=e,this.router=t}canActivate(e,t){return this.authService.isAuthenticated$.pipe($e(1),Ne(e=>{if(e){const e=this.authService.getConfiguration(),r=e?.redirectLoginUrl||"/dashboard",n=t.url;if(n===r||n.startsWith(`${r}?`)||n.startsWith(`${r}/`))return console.warn("LoginGuard: Already on dashboard page, preventing redirect loop"),!0;const o=this.router.url;return o===r||o.startsWith(`${r}?`)||o.startsWith(`${r}/`)?(console.warn("LoginGuard: Browser already on dashboard page, preventing redirect loop"),!0):(console.log("LoginGuard: Redirecting authenticated user from",n,"to",r),this.router.navigate([r],{replaceUrl:!0}).catch(e=>{console.error("LoginGuard: Navigation error:",e)}),!1)}return!0}))}};var Ye;He=d([(0,_.Injectable)({providedIn:"root"})],He),function(e){e.ADMIN="ADMIN",e.USER="USER",e.MODERATOR="MODERATOR",e.SYS_ADMIN="SYS_ADMIN",e.TENANT_ADMIN="TENANT_ADMIN",e.CUSTOMER_USER="CUSTOMER_USER"}(Ye||(Ye={}));class ze{static getFullName(e){return e.firstName&&e.lastName?`${e.firstName} ${e.lastName}`:e.additionalInfo?.full_name?e.additionalInfo.full_name:e.name||e.email}static getDisplayName(e){return e.additionalInfo?.display_name?e.additionalInfo.display_name:e.firstName?e.firstName:e.name||e.email}static getInitials(e){return this.getFullName(e).split(" ").map(e=>e[0]).join("").toUpperCase().substring(0,2)}static isAdmin(e){return e.authority===Ye.ADMIN||e.authority===Ye.SYS_ADMIN||e.authority===Ye.TENANT_ADMIN}static isSysAdmin(e){return e.authority===Ye.SYS_ADMIN}static isTenantAdmin(e){return e.authority===Ye.TENANT_ADMIN}static isCustomerUser(e){return e.authority===Ye.CUSTOMER_USER}static hasAuthority(e,t){return e.authority===t}static hasPermission(e,t){if(!e||!e.permissions)return!1;return e.permissions.includes(t)}static hasAnyPermission(e,t){return!(!e||!t||0===t.length)&&t.some(t=>this.hasPermission(e,t))}static hasAllPermissions(e,t){return!(!e||!t||0===t.length)&&t.every(t=>this.hasPermission(e,t))}static isActive(e){return e.is_active}static isVerified(e){return e.is_verified}static getDefaultDashboardId(e){return e.additionalInfo?.default_dashboard_id||null}static getTheme(e){return e.additionalInfo?.theme||"light"}static getLanguage(e){return e.additionalInfo?.lang||e.additionalInfo?.language||"en"}static getAvatar(e){return e.additionalInfo?.avatar||e.additionalInfo?.profile_picture||null}static getAvatarUrl(e,t){const r=this.getAvatar(e);if(r)return r.startsWith("http")?r:t?`${t}${r}`:r;return`https://ui-avatars.com/api/?name=${this.getInitials(e)}&background=random`}}let Fe=class{constructor(e,t){this.authService=e,this.router=t}canActivate(e,t){return this.checkPermissions(e,t.url)}canActivateChild(e,t){return this.checkPermissions(e,t.url)}checkPermissions(e,t){return this.authService.isAuthenticated$.pipe($e(1),Ne(r=>{if(!r)return console.error("🔒 AUTH_ERROR: User not authenticated for route:",t),this.handleUnauthenticated(e,t),!1;const n=e.data?.permissions,o=e.data?.permissionRedirectTo;if(!n)return!0;const i=this.authService.getCurrentUser();if(!i)return console.error("🔒 AUTH_ERROR: No current user found"),this.handleUnauthenticated(e,t),!1;const s=this.parsePermissions(n);if(!ze.hasAnyPermission(i,s)){if(console.error("🔒 PERMISSION_ERROR:",{url:t,requiredPermissions:s,userPermissions:i.permissions||[],userId:i.user_id,userEmail:i.email}),o){if(t===o||t.startsWith(`${o}?`)||t.startsWith(`${o}/`))return console.warn("AuthRoleGuard: Already on redirect target page, preventing redirect loop"),!1;const e=this.router.url;if(e===o||e.startsWith(`${o}?`)||e.startsWith(`${o}/`))return console.warn("AuthRoleGuard: Browser already on redirect target page, preventing redirect loop"),!1;console.log("🔀 PERMISSION_REDIRECT:",`Redirecting to ${o} due to insufficient permissions`),this.router.navigate([o],{replaceUrl:!0,queryParams:{reason:"insufficient_permissions",required:s.join(",")}}).catch(e=>{console.error("AuthRoleGuard: Navigation error:",e)})}else this.throwUnauthorizedError(`Access denied. Required permissions: ${s.join(" OR ")}`);return!1}return console.log("✅ ACCESS_GRANTED:",{url:t,requiredPermissions:s,userId:i.user_id}),!0}))}parsePermissions(e){return"string"==typeof e?e.includes("|")?e.split("|").map(e=>e.trim()).filter(e=>e.length>0):[e.trim()]:e}handleUnauthenticated(e,t){const r=e.data?.permissionRedirectTo;if(r){if(t===r||t.startsWith(`${r}?`)||t.startsWith(`${r}/`))return void console.warn("AuthRoleGuard: Already on redirect target page (unauthenticated), preventing redirect loop");const e=this.router.url;if(e===r||e.startsWith(`${r}?`)||e.startsWith(`${r}/`))return void console.warn("AuthRoleGuard: Browser already on redirect target page (unauthenticated), preventing redirect loop");console.log("🔀 AUTH_REDIRECT:",`Redirecting to ${r} due to unauthenticated user`),this.router.navigate([r],{replaceUrl:!0,queryParams:{reason:"unauthenticated",returnUrl:t}}).catch(e=>{console.error("AuthRoleGuard: Navigation error:",e)})}else{const e=this.authService.getConfiguration(),r=e?.redirectLoginUrl||"/login";if(t===r||t.startsWith(`${r}?`)||t.startsWith(`${r}/`))return void console.warn("AuthRoleGuard: Already on login page, preventing redirect loop");const n=this.router.url;if(n===r||n.startsWith(`${n}?`)||n.startsWith(`${r}/`))return void console.warn("AuthRoleGuard: Browser already on login page, preventing redirect loop");console.log("🔀 LOGIN_REDIRECT:",`Redirecting to ${r}`),this.router.navigate([r],{queryParams:{returnUrl:t},replaceUrl:!0}).catch(e=>{console.error("AuthRoleGuard: Navigation error:",e)})}}throwUnauthorizedError(e){const t=new Error(e);throw t.name="UnauthorizedError",t.status=403,t.code="INSUFFICIENT_PERMISSIONS",t}};function Ve(e,t){return{data:{permissions:e,...t},canActivate:[Fe],canActivateChild:[Fe]}}function Be(e,t,r){return{data:{permissions:e,permissionRedirectTo:t,...r},canActivate:[Fe],canActivateChild:[Fe]}}Fe=d([(0,_.Injectable)({providedIn:"root"})],Fe);Error;let Xe=class{set xconAuthIfRole(e){"string"==typeof e?e.includes("|")?this._requiredPermissions=e.split("|").map(e=>e.trim()).filter(e=>e.length>0):this._requiredPermissions=[e.trim()]:this._requiredPermissions=e,this.updateView()}constructor(e,t,r){this.templateRef=e,this.viewContainer=t,this.authService=r,this.hasView=!1,this.subscription=new A.Subscription,this._