import { EventEmitter } from "@angular/core"; import { Client, CompanyAccount, PersonAccount } from "@salaxy/core"; import { Token } from "../api/Token"; /** Session that manages current session and provides information about the user, account and roles. */ export declare class SessionService { private client; private token; /** * Primary role of the current user. * This is more restricted system role than the ones in isInRole() function. * @readonly - Use switchRole: This field is considered readonly and may be changed later. */ role: "worker" | "household" | "company"; /** * Gets an array of custom roles. * @readonly - Use addCustomRole: This array is considered readonly and may be changed later. */ customRoles: string[]; /** Avatar to show in the login screen */ avatarState: any; /** Called when the session is changed: Typically from not checked to authenticated or anonymous */ sessionChanged: EventEmitter; /** If true, the user is authenticated */ private isAuthenticatedState; /** If true, the session has been checked from the server */ private isSessionCheckedState; /** The full session objcet */ private sessionState; constructor(client: Client, token: Token); /** If true, the user is authenticated */ readonly isAuthenticated: boolean; /** * Returns true if the current user is in the given role. * * Supports the following role strings: * * - Primary Salaxy roles: "worker" | "household" | "company" * - "employer" for Employer, which can be either "household" or "company" * - "auth" for Authenticated user (isAuthenticated) * - "anon" for Anonymous user (isSessionChecked AND !isAuthenticated) * - "unknown" for Session check in progress (!isSessionChecked) * * We will probably add new roles here: "expired", "partner" etc. * Also Consider adding possibility for application specific roles that could utilize this same structure. * * @param role Role that is being checked. */ isInRole(role: "worker" | "household" | "company" | "employer" | "auth" | "anon" | "unknown"): string | boolean; /** * More relaxed version of isInRole() that takes either any string or array of strings without the strongly typing of isInRole. * @param roles See isInRole() for possible roles. However, any string is fine as an input. */ isInRoles(roles: string[]): boolean; /** If true, the session has been checked from the server */ readonly isSessionChecked: boolean; /** Avatar to show in the login screen */ readonly avatar: any; /** The full session objcet */ readonly session: any; /** * The company account object if the currently selected account is a company. * Null if the current account is a person or anonymous. */ readonly companyAccount: CompanyAccount; /** * The Person account object if the currently selected account is a person. * Null if the current account is a company or anonymous. */ readonly personAccount: PersonAccount; /** Gets the address for the API server where the session is connected */ getServerAddress(): string; /** * Gets / sets the current token. * Note that setting this property will not refresh the session * so typically, you would use setToken method instead. */ currentToken: string; /** Check the status of the current session */ checkSession(callback?: any): void; /** * Show the Login screen * @param redirectUrl - Redirect URL after the login. Defaults to root of the current site. * @param role - Default role if the user is going to Onboarding wizard for new users. * @param partnerSite - Identifier for the partenr site. */ signIn(redirectUrl?: string, role?: string, partnerSite?: string): void; /** * Opens the login dialog with signUp / register functionality * * @param redirectUrl - The URL where the user is taken after a successfull login * @param role - Optional role (household, worker or company) for * the situations where it is known - mainly for new users */ register(redirectUrl?: string, role?: string, partnerSite?: string): void; /** * Sends the user to the Sign-out page * @param redirectUrl - URL where user is redirected after log out. * Must be absolute URL. Default is the root of the current server. */ signOut(redirectUrl?: string): void; /** * Switches the current web site usage role and refreshes the session. * @param role - household or worker. * @param callback - Callback after switch, contains new role. */ switchRole(role: "worker" | "household" | "company", callback?: any): void; /** * Adds an application-specific custom role to the roles collection. * Any future system role may later throw an exception, so use strings that are clearly application specific (e.g. "myapp-authenticated"). * @param role An application-specific role. */ addCustomRole(role: string): void; }