/** * Represents an active user session in Lime CRM. * * The Session object contains comprehensive information about the current user's * authenticated session, including login details, enabled features, administrative * privileges, and session timing. This information is crucial for security, * feature availability, and session management. * * @example Read login details and warn before the session expires * ```ts * import { * createLogger, * PlatformServiceName, * } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const logger = createLogger('my-component'); * const session = repository.getSession(); * * if (session?.active) { * logger.info(`Logged in at: ${session.loginTime}`); * logger.info(`Admin privileges: ${session.admin}`); * } * * if (session?.expirationTime) { * const expiresAt = new Date(session.expirationTime); * const minutesRemaining = (expiresAt.getTime() - Date.now()) / 60_000; * * if (minutesRemaining < 5) { * logger.warn('Session expires in less than 5 minutes'); * } * } * ``` * * @example Check enabled features and addons * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const session = repository.getSession(); * * const advancedReporting = session?.features['advancedReporting'] === true; * const salesAutomation = session?.addons['salesAutomation'] !== undefined; * ``` * * @public * @group Application */ export interface Session { /** * Indicates whether the session is currently active. * * An active session means the user is authenticated and can perform operations. * Sessions become inactive after logout or timeout. */ active: boolean; /** * Configuration and state of enabled addons/plugins. * * Contains a key-value map of addon names to their configuration objects. * The structure of each addon's configuration depends on the addon itself. */ addons: Record; /** * Indicates whether the user has administrative privileges. * * Admin users typically have access to system configuration, user management, * and other administrative features not available to regular users. */ admin: boolean; /** * Application Performance Monitoring (APM) configuration. * * Contains settings for performance tracking and monitoring tools. * The exact structure depends on the APM provider being used. */ apm: Record; /** * The name of the Lime CRM application. * * Identifies which application/database the user is connected to. */ application: string; /** * The name of the underlying database. * * Technical database identifier, usually matching the application name * but may differ in some configurations. */ database: string; /** * User-friendly display name for the application. * * This is the name shown in the UI, which may be different from the * technical application name. Often includes company or department name. */ displayName: string; /** * ISO 8601 timestamp when the session will expire. * * After this time, the session becomes invalid and the user must * re-authenticate. */ expirationTime?: string; /** * Feature flags controlling available functionality. * * A key-value map where keys are feature names and values indicate whether * the feature is enabled. */ features: Record; /** * Unique identifier for this session. * * Used for session tracking, logging, and debugging. Each login creates * a new session with a unique ID. */ id: string; /** * ISO 8601 timestamp when the user logged in. * * Marks the start of the session. */ loginTime: string; /** * ISO 8601 timestamp when the user logged out. * * Only present after the user has explicitly logged out. Not set for * sessions that timeout. */ logoutTime?: string; /** * Application service instance number. */ serviceNumber?: number; /** * Session timeout duration in seconds. * * Indicates how long a session can be idle before it automatically expires. * The actual expiration time is calculated from the last activity. */ sessionTimeout: number; /** * The ID of the authenticated user. * * References the User.id property. Used to identify which user owns * this session. */ userId: number; /** * Name or identifier of the user's workstation. * * Typically the computer name or IP address from which the user logged in. */ workstation: string; }