import type { CurrencyCodeISO4217 } from '@coveo/relay-event-types'; import type { CommerceEngine } from '../../../app/commerce-engine/commerce-engine.js'; import { type Controller } from '../../controller/headless-controller.js'; export interface ContextOptions { language: string; country: string; currency: CurrencyCodeISO4217; view: View; location?: UserLocation; custom?: CustomContext; } export interface View { url: string; } export interface UserLocation { latitude: number; longitude: number; } /** * Custom context that accepts JSON-serializable values. * Values should be primitives (string, number, boolean, null) or nested objects/arrays of primitives. * Detailed validation is performed by the backend. */ export interface CustomContext { [key: string]: unknown; } export interface ContextProps { /** * The initial options that should be applied to this `Context` controller. */ options?: ContextOptions; } /** * The `Context` controller exposes methods for managing the global context in a commerce interface. * * @group Buildable controllers * @category Context */ export interface Context extends Controller { /** * Sets the language. * @param language - The new language. */ setLanguage(language: string): void; /** * Sets the country. * @param country - The new country. */ setCountry(country: string): void; /** * Sets the currency. * @param currency - The new currency. */ setCurrency(currency: CurrencyCodeISO4217): void; /** * Sets the view. * @param view - The new view. */ setView(view: View): void; /** * Sets the location. * @param location - The new location. */ setLocation(location: UserLocation): void; /** * Sets custom context values. * @param custom - An object containing custom key-value pairs. */ setCustom(custom: CustomContext): void; /** * A scoped and simplified part of the headless state that is relevant to the `Context` controller. */ state: ContextState; } /** * The state of the `Context` controller. * * @group Buildable controllers * @category Context */ export interface ContextState { language: string; country: string; currency: CurrencyCodeISO4217; view: View; location?: UserLocation; custom?: CustomContext; } /** * Creates a `Context` controller instance. * * @param engine - The headless commerce engine. * @param props - The configurable `Context` properties. * @returns A `Context` controller instance. * * @group Buildable controllers * @category Context */ export declare function buildContext(engine: CommerceEngine, props?: ContextProps): Context;