import { StateRepository } from '../core'; import { User } from './user'; import { Session } from './session'; /** * Repository for accessing application-level state and metadata. * * The ApplicationRepository provides access to global application information including * the current user, session details, application name, and language settings. It extends * {@link StateRepository} to provide reactive subscriptions to these values, allowing components * to automatically update when application state changes. * * This repository is typically available immediately when a component loads and provides * essential context about the running application and the authenticated user. * * @example Use decorators for reactive state management * ```ts * import { State } from '@stencil/core'; * import { * SelectApplicationName, * SelectCurrentUser, * User, * } from '@limetech/lime-web-components'; * * class MyComponent { * @State() * @SelectCurrentUser() * private user: User; * * @State() * @SelectApplicationName() * private appName: string; * } * ``` * * @example Direct repository access, useful for one-time reads * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * * const session = repository.getSession(); * const hasAdminAccess = session?.admin === true; * * const user = repository.getCurrentUser(); * const isAdministrator = user?.groups.some( * (group) => group.name === 'Administrators' * ); * ``` * * @public * @group Application */ export interface ApplicationRepository extends StateRepository { /** * Get the name of the current Lime CRM application. * * The application name identifies which Lime CRM database/application the user * is currently connected to. * * @returns The application name * * @example Read the application name * ```ts * import { * createLogger, * PlatformServiceName, * } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const logger = createLogger('my-component'); * * const appName = repository.getApplicationName(); * * logger.info(`Connected to: ${appName}`); // "Connected to: CustomerCRM" * ``` */ getApplicationName(): string | undefined; /** * Get the currently logged in user. * * Returns the User object containing information about the authenticated user, * including their username, full name, email, groups, and associated coworker * record if applicable. * * @returns The current User object, or undefined if not authenticated * * @example Check the user's group membership * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const user = repository.getCurrentUser(); * * const showAdminFeatures = user?.groups.some( * (group) => group.name === 'Administrators' * ); * ``` */ getCurrentUser(): User | undefined; /** * Get the current session information. * * The session contains detailed information about the current user session including * login time, session timeout, enabled features, database connection details, and * whether the user has administrative privileges. * * @returns The current Session object, or undefined if no active session * * @example Check admin privileges and when the session expires * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const session = repository.getSession(); * * const showAdminFeatures = session?.admin === true; * * // `expirationTime` is optional, so a session without one never counts as * // expiring soon. * let expiresSoon = false; * * if (session?.expirationTime) { * const expiresAt = new Date(session.expirationTime); * const minutesLeft = (expiresAt.getTime() - Date.now()) / 60_000; * * expiresSoon = minutesLeft < 5; * } * ``` */ getSession(): Session | undefined; /** * Get the current interface language. * * Returns the two-letter ISO 639-1 language code for the current user interface * language. This should be used for localizing component text and formatting * locale-specific data like dates and numbers. * * @returns A two-letter language code (e.g., "en", "sv", "de", "fi") * * @example Format a date for the current language * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const language = repository.getLanguage(); * * const locale = language === 'sv' ? 'sv-SE' : 'en-US'; * const formatted = new Date().toLocaleDateString(locale); * ``` */ getLanguage(): string; }