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 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

class MyComponent {
@State()
@SelectCurrentUser()
private user: User;

@State()
@SelectApplicationName()
private appName: string;
}

Example

Direct repository access (useful for one-time reads)

const repository = platform.get(PlatformServiceName.Application);

const session = repository.getSession();
const hasAdminAccess = session?.admin || false;

const user = repository.getCurrentUser();
if (user?.groups.some(g => g.name === 'Administrators')) {
// User is an administrator
}

Hierarchy

Methods

  • 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

    const appName = appRepo.getApplicationName();
    console.log(`Connected to: ${appName}`); // "Connected to: CustomerCRM"

    Returns string

  • 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

    const user = appRepo.getCurrentUser();
    if (user?.groups.some(g => g.name === 'Administrators')) {
    // Show admin features
    }

    Returns User

  • 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

    const language = appRepo.getLanguage();

    // Format dates according to language
    const locale = language === 'sv' ? 'sv-SE' : 'en-US';
    const formatted = new Date().toLocaleDateString(locale);

    Returns string

  • 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

    const session = appRepo.getSession();

    // Check if session is about to expire
    const expirationTime = new Date(session?.expirationTime);
    const minutesLeft = (expirationTime.getTime() - Date.now()) / 60000;
    if (minutesLeft < 5) {
    // Warn user about session expiration
    }

    // Check for admin privileges
    if (session?.admin) {
    // Enable admin features
    }

    Returns Session

  • Subscribe to state changes with optional transformation and filtering.

    The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.

    Returns

    Unsubscribe function - call this to stop receiving updates

    Remarks

    • Map functions are applied sequentially to transform the state
    • Filter functions must all return true for the callback to be invoked
    • Functions in map/filter arrays are bound to the component instance
    • Always store and call the unsubscribe function when component is destroyed

    Example

    // Basic subscription
    const unsubscribe = repository.subscribe((state) => {
    console.log('State updated:', state);
    });

    // With transformations
    const unsubscribe = repository.subscribe(
    (userName) => console.log('User:', userName),
    { map: [(state) => state.user?.name] }
    );

    Parameters

    • callback: ((...args: unknown[]) => void)

      Function called with state updates (after map/filter applied)

        • (...args: unknown[]): void
        • Parameters

          • Rest ...args: unknown[]

          Returns void

    • Optional options: StateOptions

      Optional transformations and filters for the subscription

    Returns (() => void)

      • (): void
      • Subscribe to state changes with optional transformation and filtering.

        The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.

        Returns

        Unsubscribe function - call this to stop receiving updates

        Remarks

        • Map functions are applied sequentially to transform the state
        • Filter functions must all return true for the callback to be invoked
        • Functions in map/filter arrays are bound to the component instance
        • Always store and call the unsubscribe function when component is destroyed

        Example

        // Basic subscription
        const unsubscribe = repository.subscribe((state) => {
        console.log('State updated:', state);
        });

        // With transformations
        const unsubscribe = repository.subscribe(
        (userName) => console.log('User:', userName),
        { map: [(state) => state.user?.name] }
        );

        Returns void