# IContextProvider

The context available to each widget or UI. Provides the ability to get information about the environment the widget is running in and communicate with Lucy

## Definition

```tsx
export interface IContextProvider extends Omit<IPartialContextProvider, "environment"> {
    environment: Environment,
    direction?: 'ltr' | 'rtl'

    getUserDetails: (updateContext?: boolean) => Promise<UserDetails>;

    /**
     *
     * localisation wrapper
     */
    $L: (code: string, params?: any) => string
    /**
     * Execute a Lucy model action. Specify the model name, action name and any parameters as a dictionary.
     * The result of the execution is returned as a promise
     */
    executeAction: (model: string, action: string, parameters: any, options?: ExecutionOptions) => Promise<any>;

    /**
     * Execute a service. Specify the app name, service name and any parameters as a dictionary.
     * The result of the execution is returned as a promise
     */
    executeService: (app: string, service: string, parameters: any, options?: ExecutionOptions) => Promise<any>;
    /**
     * This will return a function that can be passed into DataList, DataTable, DynamicList
     * (max: number, lastPageToken: string, args?: any) => Promise<{ items: Array<any>, pageToken: string }>
     * this function will return a paginated set of documents for the given filter in args
     *
     * pass the Lucy modal name & collection name
     */
    fromLucyDataCollection(model: string, collection: string): IDataFunction

    /**
     * @deprecated Use executeMicroServiceSafe instead. Kept for backward compatibility.
     * Execute a component REST API call (throws on error)
     */
    executeComponent: (component: string, route: string, method: 'get' | 'post' | 'put' | 'patch' | 'delete', params: any, body?: any, additionalHeaders?: { [key: string]: string }, additionalConfigurations?: any) => Promise<any>;

    /**
     * Execute a Lucy query by key, id, or name (legacy version - throws on error)
     */
    executeQuery: (params: QueryParams) => Promise<any>;

    /**
     * Execute a Lucy model action (safe version - returns ExecutionResult)
     * No need for try/catch - check result.error instead
     */
    executeActionSafe: <T = any>(model: string, action: string, parameters: any, options?: ExecutionOptions) => Promise<ExecutionResult<T>>;

    /**
     * Execute a service (safe version - returns ExecutionResult)
     * No need for try/catch - check result.error instead
     */
    executeServiceSafe: <T = any>(app: string, service: string, parameters: any, options?: ExecutionOptions) => Promise<ExecutionResult<T>>;

    /**
     * Execute a model collection service (safe version - returns ExecutionResult)
     * No need for try/catch - check result.error instead
     */
    executeModelCollectionServiceSafe: <T = any>(model: string, collection: string, parameters: any, options?: ExecutionOptions) => Promise<ExecutionResult<T>>;

    /**
     * Execute a microservice REST API call. Supports caching.
     * Returns ExecutionResult - no need for try/catch
     */
    executeMicroServiceSafe: <T = any>(config: ExecuteMicroserviceConfig, options?: CachingOptions) => Promise<ExecutionResult<T>>;

    /**
     * Execute a Lucy query by key, id, or name (safe version - returns ExecutionResult)
     * No need for try/catch - check result.error instead
     */
    executeQuerySafe: <T = any>(params: QueryParams) => Promise<ExecutionResult<LucyQueryResult<T>>>;

    /**
     * Generic HTTP API executor with caching support
     * Automatically normalizes URLs and adds authorization headers
     * No need for try/catch - check result.error instead
     */
    executeAPISafe: <T = any>(config: any, options?: CachingOptions) => Promise<ExecutionResult<T>>;

    /**
     * Checks if the current user has to required app role. Use this to check permissions when executing or rendering content
     */
    hasAppRole: (app: string, role: string) => boolean;
    /**
     * Checks if the current user has to required model role. Use this to check permissions when executing or rendering content
     */
    hasModelRole: (model: string, role: string) => boolean;

    refreshViewOverrides: () => Promise<void>
}
```

## Usage

```tsx
import { IContextProvider } from 'uxp/components';
```

## Related Types

* [IPartialContextProvider](https://help.iviva.com/uxp/v5/additional-resources/types/ipartialcontextprovider)
* [Language](https://help.iviva.com/uxp/v5/additional-resources/types/language)
* [ICustomThemes](https://help.iviva.com/uxp/v5/additional-resources/types/icustomthemes)
* [IThemeProps](https://help.iviva.com/uxp/v5/additional-resources/types/ithemeprops)
* [ThemeType](https://help.iviva.com/uxp/v5/additional-resources/types/themetype)
* [UserDetails](https://help.iviva.com/uxp/v5/additional-resources/types/userdetails)
* [NavigationLink](https://help.iviva.com/uxp/v5/additional-resources/types/navigationlink)
* [Routes](https://help.iviva.com/uxp/v5/additional-resources/types/routes)
* [ConfiguredPage](https://help.iviva.com/uxp/v5/additional-resources/types/configuredpage)
* [ComponentType](https://help.iviva.com/uxp/v5/additional-resources/types/componenttype)
* [IUXPFunctions](https://help.iviva.com/uxp/v5/additional-resources/types/iuxpfunctions)
* [ViewOverride](https://help.iviva.com/uxp/v5/additional-resources/types/viewoverride)
* [Environment](https://help.iviva.com/uxp/v5/additional-resources/types/environment)
* [ExecutionOptions](https://help.iviva.com/uxp/v5/additional-resources/types/executionoptions)
* [CachingOptions](https://help.iviva.com/uxp/v5/additional-resources/types/cachingoptions)
* [IDataFunction](https://help.iviva.com/uxp/v5/additional-resources/types/idatafunction)
* [QueryParams](https://help.iviva.com/uxp/v5/additional-resources/types/queryparams)
* [ExecutionResult](https://help.iviva.com/uxp/v5/additional-resources/types/executionresult)
* [ExecuteMicroserviceConfig](https://help.iviva.com/uxp/v5/additional-resources/types/executemicroserviceconfig)
* [ExecuteConfigBase](https://help.iviva.com/uxp/v5/additional-resources/types/executeconfigbase)
* [LucyQueryResult](https://help.iviva.com/uxp/v5/additional-resources/types/lucyqueryresult)
