// Copyright © 2022-2026 Partium, Inc. DBA Partium import { BehaviorSubject, Observable } from 'rxjs'; import { AuthenticationConfig } from '../../models/auth-config'; import { PartiumConfig } from '../../models/partium-config'; import { User } from '../../models/user'; import { BaseLoginInitService } from '../base-login-init.service'; import { BaseService } from '../base.service'; import { ServiceProvider } from '../service-provider'; import { EventContext } from '../../models/log'; import { Organization } from '../organization/models/organization'; export declare enum SESSION_STATUS_EVENT { SESSION_STARTED = 0, SESSION_ENDED = 1 } /** * Login-Configuration, such as username and password, or api-key */ export declare class LoginConfig { } export declare class LogoutConfig { postLogoutRedirectUri?: string; constructor(init?: Partial); } export interface SessionEventContext extends EventContext { languageUi?: string; } /** * Defines the structure of a session-service implementation. * It contains functions that are required for handling user sessions and * authentication-mechanisms. * The implementations of this interface will be based on the chosen * authentication method and platform that is used in the application, * * An implementation of this service is required and has to be configured during * the initialization phase of Partium. * * This class file is called interface, even though it is not an interface, * but we need it to be a concrete class for the serviceProvider. */ export declare class SessionService extends BaseService { private organizationService; private localStorageService; private user; protected authenticationConfig: AuthenticationConfig; private partiumConfig; protected sessionStatus$: BehaviorSubject; private currentOrganization$; private servicesToInitDuringLogin; constructor(serviceProvider: ServiceProvider); /** * Called by HttpsService to pass config info * * @param config the Partium configuration */ init(config: PartiumConfig): Observable; /** * Login user based on the given configuration. * * Method should be overridden by child-class * * @param config the login configuration, which differs per authentication-method */ login(config: LoginConfig): Observable; /** * Logout currently logged in user * * Method should be overridden by child-class */ logout(config?: LogoutConfig): Observable; /** * Returns an Observable that always emits an event when a session has just * started or ended. */ getSessionStatusEvents(): Observable; /** * Get the currently configured authentication configuration * * @returns the authentication configuration */ getAuthConfig(): AuthenticationConfig; /** * Set the user-object of the currently logged in user. * This class should be called by any of the deriving classes. * * @param user the currently logged in user */ protected setUser(user: User): void; /** * Retrieve the currently logged in user * * @returns the currently logged in user */ getUser(): User; /** * Set organization with the given partiumId as the current organization to be used in the session. * * @param organizationPartiumId organization-id * @returns void if organization is found, otherwise throws an error */ useOrganizationById(organizationPartiumId: string): Promise; /** * Set organization with the given name as the current organization to be used in the session. * * @param organizationName organization-name * @returns void if organization is found, otherwise throws an error */ useOrganizationByName(organizationName: string): Promise; /** * Get an observable that always emits when the currently selected organization changed. * * @returns Observable, emitting the currently used organization. */ getCurrentOrganization$(): Observable; /** * Register a service to be initialized during login-process. * The passed service must extend the BaseLoginInitService and implement an init-function, * that returns an Observable, that resolves, when the initialization was finished successfully * * @param service the service to init during login * @param priority services with lower prio will be initialized first. Services with the same prio will be initialized in parallel. Can be used if there are dependencies between the services. */ registerLoginInitService(service: BaseLoginInitService, priority?: number): void; /** * Needs to be called during the login-process, after the user is authenticated, * to download and prepare all the data needed in the session. * * @param eventContext (optional) additional event context for event logs emitted during session setup */ protected sessionSetup(eventContext?: SessionEventContext): Observable; private logUserSessionInfoEvent; /** * Returns the passed languageUiCandidate if it is valid for the organization config. * Returns null if invalid. */ private getValidLanguageUiForEvent; /** * Needs to be called when a session ended, * to notify other services that need to tear down. */ protected sessionEnded(): void; /** * Initializes all services, which are registered for initialization during login. * First all services with priority 1 will be registered in parallel, then all services with priority 2, and so on. * * @returns Observable that resolves once all services have been initialized. */ private initializeRegisteredServices; /** * Set the given organization as the sessions current organization and store the partiumId in the localStorage. * * @param organization the new current organization */ private setCurrentOrganization; }