/** * Service container for the Lime CRM platform that provides access to all platform services. * * The platform acts as a service locator for accessing repositories, the command bus, * HTTP client, and other services throughout the application. It is used by web components * (injected via Stencil's `@Prop` decorator), command handlers, and other parts of the system. * * The platform type indicates which Lime CRM client is hosting the component: * - `LimeCRMWebClient`: Standard web client * - `LimeCRMDesktopClient`: Desktop application client * - `LimeCRMWebAdminClient`: Administrative web interface * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * // Get core services * const http = platform.get(PlatformServiceName.Http); * const commandBus = platform.get(PlatformServiceName.CommandBus); * const limetypes = platform.get(PlatformServiceName.LimeTypeRepository); * * // Check the platform type for conditional logic * if (platform.type === 'LimeCRMDesktopClient') { * // Desktop-specific functionality * } * * // Check feature switches * if (platform.isFeatureEnabled('betaFeatures')) { * // Use the new feature * } * ``` * * @example Register a custom service (third-party plugins) * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * class AnalyticsService { * public track(event: string) { * return event; * } * } * * const SERVICE_NAME = 'myPlugin.analytics'; * * PlatformServiceName.MyAnalytics = SERVICE_NAME; * * declare module '@limetech/lime-web-components' { * interface PlatformServiceNameType { * MyAnalytics: typeof SERVICE_NAME; * } * * interface LimeWebComponentPlatform { * get(name: PlatformServiceNameType['MyAnalytics']): AnalyticsService; * } * } * * platform.register(PlatformServiceName.MyAnalytics, new AnalyticsService()); * * // The `get` overload above is what types this, so no type argument is needed * const analytics = platform.get(PlatformServiceName.MyAnalytics); * * analytics.track('page-view'); * ``` * * @public * @group Core */ export interface LimeWebComponentPlatform { /** * The type of Lime CRM client currently running. * Use this to conditionally enable features based on the client environment. */ type: 'LimeCRMWebClient' | 'LimeCRMDesktopClient' | 'LimeCRMWebAdminClient'; /** * Get a service from the platform container. * * Services are accessed through the `PlatformServiceName` enum, which can be extended * by third-party modules using module augmentation. * * @param name - The name of the service to retrieve * @returns The requested service instance * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const http = platform.get(PlatformServiceName.Http); * const commandBus = platform.get(PlatformServiceName.CommandBus); * const repository = platform.get(PlatformServiceName.LimeObjectRepository); * ``` */ get(name: string): T; /** * Check if a service is currently registered on the platform. * * Useful for optional dependencies or checking service availability. * * @param name - The name of the service to check * @returns `true` if the service is registered, `false` otherwise * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * // A plugin registers this one, so it is not always there * if (platform.has(PlatformServiceName.MyAnalytics)) { * const analytics = platform.get(PlatformServiceName.MyAnalytics); * * analytics.track('page-view'); * } * ``` */ has(name: string): boolean; /** * Register a service on the platform for use throughout the application. * * Service names are typically defined in the `PlatformServiceName` enum through module * augmentation. This ensures type safety and prevents naming conflicts. * * @param name - The name to register the service under * @param service - The service instance to register * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * class AnalyticsService { * public track(event: string) { * return event; * } * } * * const SERVICE_NAME = 'myPlugin.analytics'; * * PlatformServiceName.MyAnalytics = SERVICE_NAME; * * declare module '@limetech/lime-web-components' { * interface PlatformServiceNameType { * MyAnalytics: typeof SERVICE_NAME; * } * * interface LimeWebComponentPlatform { * get(name: PlatformServiceNameType['MyAnalytics']): AnalyticsService; * } * } * * platform.register(PlatformServiceName.MyAnalytics, new AnalyticsService()); * * // The `get` overload above is what types this, so no type argument is needed * const analytics = platform.get(PlatformServiceName.MyAnalytics); * * analytics.track('page-view'); * ``` */ register(name: string, service: unknown): void; /** * Check if a feature is enabled in the current environment. * * Feature switches allow gradual rollout of new functionality and * environment-specific behavior. Features can be enabled/disabled * at the application, user, or system level. * * @param name - Name of the feature switch to check * @returns `true` if the feature is enabled, `false` otherwise * * @example Use feature switches for gradual rollout * ```ts * import { ComponentDescriptor } from '@limetech/lime-web-components'; * * function searchComponent(): ComponentDescriptor { * if (platform.isFeatureEnabled('advancedSearch')) { * return { name: 'advanced-search' }; * } * * return { name: 'basic-search' }; * } * ``` */ isFeatureEnabled(name: keyof FeatureSwitches): boolean; } /** * Core platform service names for accessing built-in services via the platform. * * Use these strongly-typed keys to retrieve platform services. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const http = platform.get(PlatformServiceName.Http); * const commandBus = platform.get(PlatformServiceName.CommandBus); * const limeObjects = platform.get(PlatformServiceName.LimeObjectRepository); * const limeTypes = platform.get(PlatformServiceName.LimeTypeRepository); * const navigator = platform.get(PlatformServiceName.Navigator); * ``` * * @remarks * Available services include: * - `Http` - HTTP client for API requests * - `CommandBus` - Command pattern implementation for actions * - `LimeObjectRepository` - CRUD operations for business objects * - `LimeTypeRepository` - Schema and metadata access * - `Navigator` - Client-side routing * - `EventDispatcher` - Event pub/sub system * - `Translator` - Localization service * - And many more... * * @public * @group Core */ export declare const PlatformServiceName: PlatformServiceNameType; /** * Interface for platform service names that gets augmented by each service module. * * Each platform service extends this interface through module augmentation to add * its service name. This pattern provides compile-time type safety for service names. * * @example How services augment this interface, done internally by each service * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * // Stands in for the client type the real service module declares alongside this * interface ExampleClient { * fetch(id: string): Promise; * } * * const SERVICE_NAME = 'example'; * * PlatformServiceName.ExampleService = SERVICE_NAME; * * declare module '@limetech/lime-web-components' { * interface PlatformServiceNameType { * ExampleService: typeof SERVICE_NAME; * } * * interface LimeWebComponentPlatform { * get(name: PlatformServiceNameType['ExampleService']): ExampleClient; * } * } * ``` * * @public * @group Core */ export interface PlatformServiceNameType { } /** * Available feature switches for conditional functionality. * * Feature switches enable gradual rollout and A/B testing of new features. * This interface is augmented by feature modules to register their switches. * * @example How features augment this interface * ```ts * declare module '@limetech/lime-web-components' { * interface FeatureSwitches { * advancedSearch: boolean; * newUIDesign: boolean; * betaFeatures: boolean; * } * } * * // Needed so the file is a module, which is what makes the block above merge * // with the interface instead of replacing the package declaration. * export {}; * * if (platform.isFeatureEnabled('advancedSearch')) { * // Enable advanced search functionality * } * ``` * * @public * @group Core */ export interface FeatureSwitches { }