import type { Relay } from '@coveo/relay'; import type { Dispatch, Middleware, Reducer, ReducersMapObject, StateFromReducersMapObject, ThunkDispatch, UnknownAction, Unsubscribe } from '@reduxjs/toolkit'; import type { Logger } from 'pino'; import type { ConfigurationState, CoreConfigurationState } from '../features/configuration/configuration-state.js'; import type { SearchParametersState } from '../state/search-app-state.js'; import type { EngineConfiguration } from './engine-configuration.js'; import type { LoggerOptions } from './logger.js'; import { type NavigatorContext, type NavigatorContextProvider } from './navigator-context-provider.js'; import { stateKey } from './state-key.js'; import { type CoreExtraArguments, type Store } from './store.js'; import type { ThunkExtraArguments } from './thunk-extra-arguments.js'; export type CoreState = { configuration: Configuration; version: string; } & Partial; type EngineDispatch = ThunkDispatch & Dispatch; export interface CoreEngine { /** * Dispatches an action directly. This is the only way to trigger a state change. * Each headless controller dispatches its own actions. * * @param action An action supported by the headless engine. * * @returns For convenience, the action object that was just dispatched. */ dispatch: EngineDispatch, ExtraArguments>; /** * Adds a change listener. It will be called any time an action is * dispatched, and some part of the state tree may potentially have changed. * You may then access the new `state`. * * @param listener A callback to be invoked on every dispatch. * @returns A function to remove this change listener. */ subscribe(listener: () => void): Unsubscribe; /** * The complete headless state tree. */ state: State & CoreState; /** * The Relay instance used by Headless. */ relay: Relay; /** * The redux store. */ store: Store; /** * The logger instance used by headless. * */ logger: Logger; /** * Adds the specified reducers to the store. * * @param reducers - An object containing the reducers to attach to the engine. */ addReducers(reducers: ReducersMapObject): void; /** * Enable analytics tracking */ enableAnalytics(): void; /** * Disable analytics tracking */ disableAnalytics(): void; /** * The navigator context (referer, location, UserAgent) */ navigatorContext: NavigatorContext; } export type CoreEngineNext = Omit, 'state' | 'store'> & { /** * The readonly internal state of the headless engine. * * @internal */ readonly [stateKey]: State & CoreState; /** * The readonly global headless engine configuration */ readonly configuration: Configuration; }; export interface EngineOptions extends ExternalEngineOptions> { /** * Map object of reducers. * A reducer is a pure function that takes the previous state and an action, and returns the next state. * ``` * (previousState, action) => nextState * ``` * [Redux documentation on reducers.](https://redux.js.org/glossary#reducer) */ reducers: Reducers; /** * An optional cross reducer (aka: root reducer) that can be combined with the slice reducers. * * [Redux documentation on root reducers.](https://redux.js.org/usage/structuring-reducers/beyond-combinereducers) */ crossReducer?: Reducer; } export interface ExternalEngineOptions { /** * The global headless engine configuration options. */ configuration: EngineConfiguration; /** * The initial headless state. * You may optionally specify it to hydrate the state * from the server in universal apps, or to restore a previously serialized * user session. */ preloadedState?: State; /** * List of additional middlewares. * A middleware is a higher-order function that composes a dispatch function to return a new dispatch function. * It is useful for logging actions, performing side effects like routing, or turning an asynchronous API call into a series of synchronous actions. * * @example * ``` * type MiddlewareAPI = { dispatch: Dispatch, getState: () => State } * type Middleware = (api: MiddlewareAPI) => (next: Dispatch) => Dispatch * ``` * [Redux documentation on middlewares.](https://redux.js.org/glossary#middleware) */ middlewares?: Middleware<{}, State>[]; /** * The logger options. */ loggerOptions?: LoggerOptions; /** * An optional function returning navigation context. (referer, location, UserAgent) */ navigatorContextProvider?: NavigatorContextProvider; } export declare function buildEngine(options: EngineOptions, thunkExtraArguments: ExtraArguments): CoreEngine, CoreExtraArguments & ExtraArguments, ConfigurationState>; export declare function buildCoreEngine(options: EngineOptions, thunkExtraArguments: ExtraArguments, configurationReducer: Reducer): CoreEngine, ExtraArguments, Configuration>; export declare const nextAnalyticsUsageWithServiceFeatureWarning: string; export declare function warnIfUsingNextAnalyticsModeForServiceFeature(analyticsMode: 'next' | 'legacy'): void; export {};