/** * Represents a user in the Lime CRM system. * * The User object contains all relevant information about an authenticated user, * including their identity, contact details, group memberships, and associated * business object (coworker) if applicable. This information is used throughout * the platform for authentication, authorization, and personalization. * * @example Read identity and group membership * ```ts * import { * createLogger, * PlatformServiceName, * } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const logger = createLogger('my-component'); * const user = repository.getCurrentUser(); * * if (user) { * logger.info(`Logged in as: ${user.fullname} (${user.username})`); * logger.info(`Email: ${user.email}`); * logger.info(`Member of ${user.groups.length} groups`); * } * * const isAdmin = user?.groups.some((group) => group.name === 'Administrators'); * const isSales = user?.groups.some((group) => group.name === 'Sales'); * ``` * * @example Load the user's coworker record * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const application = platform.get(PlatformServiceName.Application); * const objects = platform.get(PlatformServiceName.LimeObjectRepository); * * const user = application.getCurrentUser(); * * if (user?.coworker) { * const coworker = await objects.loadObject( * user.coworker.limetype, * user.coworker.id * ); * * const coworkerName = coworker?.getValue('name'); * } * ``` * * @public * @group Application */ export interface User { /** * The unique username used for authentication. * * This is the login identifier for the user, typically in a format like * "john.doe" or "jdoe". It must be unique across the system. */ username: string; /** * The user's full display name. * * This is the human-readable name shown in the UI, typically in the format * "First Last" (e.g., "John Doe"). Used for display purposes throughout * the application. */ fullname: string; /** * The unique numeric identifier for the user. */ id: number; /** * The user's email address. */ email: string; /** * Indicates whether the user account is currently active. * * Inactive users cannot log in to the system. Useful for temporarily * disabling accounts without deletion. */ active: boolean; /** * List of security groups the user belongs to. * * Groups control access permissions and feature availability. A user can * belong to multiple groups, inheriting permissions from all of them. */ groups: UserGroup[]; /** * The user's primary group assignment. * * When a user belongs to multiple groups, this indicates their main group * affiliation. Used for default permissions and organizational structure. */ defaultGroup: UserGroup; /** * Reference to the user's associated coworker business object. * * Many Lime CRM systems have a coworker limetype that stores additional * employee information beyond the user account (phone, department, manager, etc.). * This property links to that record if it exists. */ coworker: UserCoworker; } /** * Represents a security group in Lime CRM. * * Groups are used to organize users and control their access permissions. * Users inherit permissions from all groups they belong to. Groups typically * represent departments, roles, or permission levels within the organization. * * @example Check if the user belongs to a group * ```ts * import { * createLogger, * PlatformServiceName, * } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.Application); * const logger = createLogger('my-component'); * const user = repository.getCurrentUser(); * * const adminGroup = user?.groups.find( * (group) => group.name === 'Administrators' * ); * * if (adminGroup) { * logger.info(`User is admin (group id: ${adminGroup.id})`); * logger.info(`Description: ${adminGroup.description}`); * } * ``` * * @public * @group Application */ export interface UserGroup { /** * The unique name identifier for the group. * * Group names are used throughout the system for permission checks * and access control. */ name: string; /** * The numeric identifier for the group. * * Used internally for group references in the database. */ id: number; /** * Human-readable description of the group's purpose. * * Provides additional context about what the group represents * and what permissions it typically grants. */ description: string; } /** * Reference to a user's associated coworker business object. * * In Lime CRM, user accounts (for authentication) are often separate from * coworker/employee records (business objects with additional data). This * interface provides the link between the two, allowing you to load the * full coworker record when needed. * * @example Load the full coworker record * ```ts * import { * createLogger, * PlatformServiceName, * } from '@limetech/lime-web-components'; * * const application = platform.get(PlatformServiceName.Application); * const objects = platform.get(PlatformServiceName.LimeObjectRepository); * const logger = createLogger('my-component'); * * const user = application.getCurrentUser(); * * if (user?.coworker) { * // Usually 'coworker' or 'employee' * const coworker = await objects.loadObject( * user.coworker.limetype, * user.coworker.id, * { properties: ['phone', 'department'] } * ); * * logger.info(`Phone: ${coworker?.getValue('phone')}`); * logger.info(`Department: ${coworker?.getValue('department')}`); * } * ``` * * @public * @group Application */ export interface UserCoworker { /** * The ID of the coworker LimeObject. * * Use this with {@link LimeObjectRepository} to load the full coworker record. */ id: number; /** * The name of the Limetype used for coworker records. * * Typically "coworker" or "employee", but can vary by configuration. * Use this as the limetype parameter when loading the object. */ limetype: string; }