@coveo/headless 3.28.4-pre.f33fb697dc → 3.28.4-pre.f345a65b79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/cjs/case-assist/headless.cjs +1 -1
  2. package/dist/cjs/case-assist/node.cjs.stats.json +1 -1
  3. package/dist/cjs/commerce/headless.cjs +1 -1
  4. package/dist/cjs/commerce/node.cjs.stats.json +1 -1
  5. package/dist/cjs/headless.cjs +3 -3
  6. package/dist/cjs/insight/headless.cjs +1 -1
  7. package/dist/cjs/insight/node.cjs.stats.json +1 -1
  8. package/dist/cjs/node.cjs.stats.json +1 -1
  9. package/dist/cjs/recommendation/headless.cjs +1 -1
  10. package/dist/cjs/recommendation/node.cjs.stats.json +1 -1
  11. package/dist/cjs/ssr/headless.cjs +3 -3
  12. package/dist/cjs/ssr/node.cjs.stats.json +1 -1
  13. package/dist/cjs/ssr-commerce/headless.cjs +1 -1
  14. package/dist/cjs/ssr-commerce/node.cjs.stats.json +1 -1
  15. package/dist/cjs/ssr-commerce-next/headless.cjs +1 -1
  16. package/dist/cjs/ssr-commerce-next/node.cjs.stats.json +1 -1
  17. package/dist/cjs/ssr-next/headless.cjs +3 -3
  18. package/dist/cjs/ssr-next/node.cjs.stats.json +1 -1
  19. package/dist/definitions/controllers/core/facets/range-facet/date-facet/date-range.d.ts +2 -2
  20. package/dist/definitions/features/facets/range-facets/date-facet-set/interfaces/request.d.ts +2 -2
  21. package/dist/definitions/ssr-next/commerce/engine/commerce-engine.ssr.d.ts +5 -29
  22. package/dist/definitions/ssr-next/commerce/types/engine.d.ts +8 -0
  23. package/dist/definitions/ssr-next/commerce/types/fetch-static-state.d.ts +1 -34
  24. package/dist/definitions/ssr-next/common/types/engine.d.ts +8 -0
  25. package/dist/definitions/ssr-next/common/types/fetch-static-state.d.ts +1 -17
  26. package/dist/definitions/ssr-next/search/engine/search-engine.ssr.d.ts +20 -18
  27. package/dist/esm/controllers/relevance-inspector/headless-relevance-inspector.js +2 -2
  28. package/dist/esm/ssr-next/commerce/engine/commerce-engine.ssr.js +14 -33
  29. package/dist/esm/ssr-next/commerce/factories/static-state-factory.js +8 -22
  30. package/dist/esm/ssr-next/search/engine/search-engine.ssr.js +39 -56
  31. package/dist/esm/utils/version.js +1 -1
  32. package/dist/quantic/browser.cjs.stats.json +1 -1
  33. package/dist/quantic/case-assist/browser.cjs.stats.json +1 -1
  34. package/dist/quantic/case-assist/headless.js +1 -1
  35. package/dist/quantic/case-assist/headless.js.map +1 -1
  36. package/dist/quantic/commerce/browser.cjs.stats.json +1 -1
  37. package/dist/quantic/commerce/headless.js +1 -1
  38. package/dist/quantic/commerce/headless.js.map +1 -1
  39. package/dist/quantic/headless.js +3 -3
  40. package/dist/quantic/headless.js.map +2 -2
  41. package/dist/quantic/insight/browser.cjs.stats.json +1 -1
  42. package/dist/quantic/insight/headless.js +1 -1
  43. package/dist/quantic/insight/headless.js.map +1 -1
  44. package/dist/quantic/recommendation/browser.cjs.stats.json +1 -1
  45. package/dist/quantic/recommendation/headless.js +1 -1
  46. package/dist/quantic/recommendation/headless.js.map +1 -1
  47. package/package.json +1 -1
@@ -5,11 +5,11 @@ import type { DateRangeRequest } from '../../../../../features/facets/range-face
5
5
  export type DateRangeInput = AbsoluteDate | RelativeDate;
6
6
  export interface DateRangeOptions {
7
7
  /**
8
- * The starting value for the date range. A date range can be either absolute or [relative](https://docs.coveo.com/en/headless/latest/reference/search/controllers/date-facet/relative-date-format/).
8
+ * The starting value for the date range. A date range can be either absolute or [relative](https://docs.coveo.com/en/headless/latest/reference/documents/Search.DateFacet.relative-date-format.html).
9
9
  */
10
10
  start: DateRangeInput;
11
11
  /**
12
- * The ending value for the date range. A date range can be either absolute or [relative](https://docs.coveo.com/en/headless/latest/reference/search/controllers/date-facet/relative-date-format/).
12
+ * The ending value for the date range. A date range can be either absolute or [relative](https://docs.coveo.com/en/headless/latest/reference/documents/Search.DateFacet.relative-date-format.html).
13
13
  */
14
14
  end: DateRangeInput;
15
15
  /**
@@ -7,11 +7,11 @@ import type { BaseRangeFacetRequest } from '../../generic/interfaces/request.js'
7
7
  */
8
8
  export interface DateRangeRequest {
9
9
  /**
10
- * The starting value for the date range, formatted as `YYYY/MM/DD@HH:mm:ss` or the [Relative Date](https://docs.coveo.com/en/headless/latest/reference/search/controllers/date-facet/relative-date-format/) format "period-amount-unit".
10
+ * The starting value for the date range, formatted as `YYYY/MM/DD@HH:mm:ss` or the [Relative Date](https://docs.coveo.com/en/headless/latest/reference/documents/Search.DateFacet.relative-date-format.html) format "period-amount-unit".
11
11
  */
12
12
  start: string;
13
13
  /**
14
- * The ending value for the date range, formatted as `YYYY/MM/DD@HH:mm:ss` or the [Relative Date](https://docs.coveo.com/en/headless/latest/reference/search/controllers/date-facet/relative-date-format/) format "period-amount-unit".
14
+ * The ending value for the date range, formatted as `YYYY/MM/DD@HH:mm:ss` or the [Relative Date](https://docs.coveo.com/en/headless/latest/reference/documents/Search.DateFacet.relative-date-format.html) format "period-amount-unit".
15
15
  */
16
16
  end: string;
17
17
  /**
@@ -9,7 +9,8 @@ import type { CommerceEngineDefinition } from '../types/engine.js';
9
9
  /**
10
10
  * Initializes a Commerce engine definition in SSR with given controllers definitions and commerce engine config.
11
11
  * @param options - The commerce engine definition
12
- * @returns Engine definitions for different solution types that support per-call navigator context.
12
+ * @returns Three utility functions to fetch the initial state of the engine in SSR, hydrate the state in CSR,
13
+ * and a build function that can be used for edge cases requiring more control.
13
14
  *
14
15
  * @remarks
15
16
  * You can use the {@link InferStaticState} and {@link InferHydratedState} utility types with the returned engine definitions
@@ -17,34 +18,9 @@ import type { CommerceEngineDefinition } from '../types/engine.js';
17
18
  *
18
19
  * @example
19
20
  * ```ts
20
- * const { listingEngineDefinition } = defineCommerceEngine(engineConfig);
21
- *
22
- * // Pass navigator context directly to fetchStaticState
23
- * const staticState = await listingEngineDefinition.fetchStaticState({
24
- * navigatorContext: {
25
- * forwardedFor: req.ip,
26
- * referrer: req.headers.referer || null,
27
- * userAgent: req.headers['user-agent'] || null,
28
- * clientId: 'unique-session-id'
29
- * }
30
- * });
31
- *
32
- * // Framework examples:
33
- * // Express.js
34
- * app.get('/api/listing', async (req, res) => {
35
- * const state = await listingEngineDefinition.fetchStaticState({
36
- * navigatorContext: {
37
- * forwardedFor: req.ip,
38
- * referrer: req.headers.referer || null,
39
- * userAgent: req.headers['user-agent'] || null,
40
- * clientId: req.sessionID
41
- * }
42
- * });
43
- * res.json(state);
44
- * });
45
- *
46
- * type SearchStaticState = InferStaticState<typeof listingEngineDefinition>;
47
- * type SearchHydratedState = InferHydratedState<typeof listingEngineDefinition>;
21
+ * const engineDefinition = defineCommerceEngine(engineConfig);
22
+ * type SearchStaticState = InferStaticState<typeof engineDefinition>;
23
+ * type SearchHydratedState = InferHydratedState<typeof engineDefinition>;
48
24
  * ```
49
25
  *
50
26
  * @group Engine
@@ -1,6 +1,7 @@
1
1
  import type { UnknownAction } from '@reduxjs/toolkit';
2
2
  import type { CommerceEngineOptions } from '../../../app/commerce-engine/commerce-engine.js';
3
3
  import type { EngineConfiguration } from '../../../app/engine-configuration.js';
4
+ import type { NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
4
5
  import type { Controller } from '../../../controllers/controller/headless-controller.js';
5
6
  import type { ControllerStaticStateMap } from '../../common/types/controllers.js';
6
7
  import type { SSRCommerceEngine } from '../factories/build-factory.js';
@@ -32,6 +33,13 @@ export interface CommerceEngineDefinition<TControllers extends ControllerDefinit
32
33
  * Fetches the hydrated state on the client side using your engine definition and the static state.
33
34
  */
34
35
  hydrateStaticState: HydrateStaticState<InferControllersMapFromDefinition<TControllers, TSolutionType>, UnknownAction, InferControllerPropsMapFromDefinitions<TControllers>, TControllers, TSolutionType>;
36
+ /**
37
+ * Sets the navigator context provider.
38
+ * This provider is essential for retrieving navigation-related data such as referrer, userAgent, location, and clientId, which are crucial for handling both server-side and client-side API requests effectively.
39
+ *
40
+ * Note: The implementation specifics of the navigator context provider depend on the Node.js framework being utilized. It is the developer's responsibility to appropriately define and implement the navigator context provider to ensure accurate navigation context is available throughout the application. If the user fails to provide a navigator context provider, a warning will be logged either on the server or the browser console.
41
+ */
42
+ setNavigatorContextProvider: (navigatorContextProvider: NavigatorContextProvider) => void;
35
43
  /**
36
44
  * Returns the access token.
37
45
  */
@@ -1,46 +1,13 @@
1
1
  import type { UnknownAction } from '@reduxjs/toolkit';
2
- import type { NavigatorContext, NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
3
2
  import type { Controller } from '../../../controllers/controller/headless-controller.js';
4
3
  import type { ControllerStaticStateMap, ControllersPropsMap } from '../../common/types/controllers.js';
5
4
  import type { SolutionType } from './controller-constants.js';
6
5
  import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, OptionsTuple } from './controller-definitions.js';
7
6
  import type { EngineStaticState } from './engine.js';
8
- export interface FetchStaticStateOptions {
9
- /**
10
- * Navigator context for this request. Used to set headers like x-forwarded-for during SSR.
11
- *
12
- * @example
13
- * ```ts
14
- * // In your server route handler
15
- * const staticState = await listingEngineDefinition.fetchStaticState({
16
- * navigatorContext: {
17
- * forwardedFor: req.ip,
18
- * referrer: req.headers.referer || null,
19
- * userAgent: req.headers['user-agent'] || null,
20
- * clientId: req.sessionID || 'anonymous'
21
- * }
22
- * });
23
- * ```
24
- */
25
- navigatorContext?: NavigatorContext | NavigatorContextProvider;
26
- }
7
+ export type FetchStaticStateOptions = {};
27
8
  /**
28
9
  * Executes only the initial search for a given configuration, then returns a resumable snapshot of engine state along with the state of the controllers.
29
10
  *
30
11
  * Useful for static generation and server-side rendering.
31
- *
32
- * @example
33
- * ```ts
34
- * // Pass navigator context directly in the options
35
- * const staticState = await engineDefinition.fetchStaticState({
36
- * navigatorContext: {
37
- * forwardedFor: request.ip,
38
- * referrer: request.headers.referer,
39
- * userAgent: request.headers['user-agent'],
40
- * location: request.url,
41
- * clientId: 'session-123'
42
- * }
43
- * });
44
- * ```
45
12
  */
46
13
  export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = (...params: OptionsTuple<FetchStaticStateOptions & EngineDefinitionControllersPropsOption<TControllersDefinitionsMap, TControllersProps, TSolutionType>>) => Promise<EngineStaticState<TSearchAction, TControllersStaticState>>;
@@ -1,6 +1,7 @@
1
1
  import type { AnyAction, UnknownAction } from '@reduxjs/toolkit';
2
2
  import type { CoreEngine, CoreEngineNext } from '../../../app/engine.js';
3
3
  import type { EngineConfiguration } from '../../../app/engine-configuration.js';
4
+ import type { NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
4
5
  import type { Controller } from '../../../controllers/controller/headless-controller.js';
5
6
  import type { Build } from './build.js';
6
7
  import type { ControllerDefinitionsMap, ControllerStaticStateMap, ControllersMap, ControllersPropsMap } from './controllers.js';
@@ -26,6 +27,13 @@ export interface EngineDefinition<TEngine extends CoreEngine | CoreEngineNext, T
26
27
  * Fetches the hydrated state on the client side using your engine definition and the static state.
27
28
  */
28
29
  hydrateStaticState: HydrateStaticState<TEngine, InferControllersMapFromDefinition<TControllers>, AnyAction, InferControllerPropsMapFromDefinitions<TControllers>>;
30
+ /**
31
+ * Sets the navigator context provider.
32
+ * This provider is essential for retrieving navigation-related data such as referrer, userAgent, location, and clientId, which are crucial for handling both server-side and client-side API requests effectively.
33
+ *
34
+ * Note: The implementation specifics of the navigator context provider depend on the Node.js framework being utilized. It is the developer's responsibility to appropriately define and implement the navigator context provider to ensure accurate navigation context is available throughout the application. If the user fails to provide a navigator context provider, a warning will be logged either on the server or the browser console.
35
+ */
36
+ setNavigatorContextProvider: (navigatorContextProvider: NavigatorContextProvider) => void;
29
37
  }
30
38
  export interface EngineDefinitionBuildResult<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap> {
31
39
  engine: TEngine;
@@ -1,28 +1,12 @@
1
1
  import type { UnknownAction } from '@reduxjs/toolkit';
2
- import type { NavigatorContext, NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
3
2
  import type { ControllerStaticStateMap, ControllersPropsMap } from './controllers.js';
4
3
  import type { EngineDefinitionControllersPropsOption, EngineStaticState } from './engine.js';
5
4
  import type { OptionsTuple } from './utilities.js';
6
- type FetchStaticStateOptions = {
7
- navigatorContext?: NavigatorContext | NavigatorContextProvider;
8
- };
5
+ type FetchStaticStateOptions = {};
9
6
  /**
10
7
  * Executes only the initial search for a given configuration, then returns a resumable snapshot of engine state along with the state of the controllers.
11
8
  *
12
9
  * Useful for static generation and server-side rendering.
13
- *
14
- * @example
15
- * ```ts
16
- * // Pass navigator context directly in the options
17
- * const staticState = await engineDefinition.fetchStaticState({
18
- * navigatorContext: {
19
- * forwardedFor: request.ip,
20
- * referrer: request.headers.referer || null,
21
- * userAgent: request.headers['user-agent'] || null,
22
- * clientId: 'session-123'
23
- * }
24
- * });
25
- * ```
26
10
  */
27
11
  export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<FetchStaticStateOptions & EngineDefinitionControllersPropsOption<TControllersProps>>) => Promise<EngineStaticState<TSearchAction, TControllersStaticState>>;
28
12
  export {};
@@ -1,38 +1,40 @@
1
+ import type { NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
1
2
  import { type SearchEngine, type SearchEngineOptions } from '../../../app/search-engine/search-engine.js';
2
3
  import type { Controller } from '../../../controllers/controller/headless-controller.js';
3
4
  import type { LegacySearchAction } from '../../../features/analytics/analytics-utils.js';
4
5
  import type { ControllerDefinitionsMap } from '../../common/types/controllers.js';
5
6
  import type { EngineDefinition, EngineDefinitionOptions } from '../../common/types/engine.js';
7
+ import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitions } from '../../common/types/inference.js';
6
8
  /**
7
9
  * The SSR search engine.
10
+ *
11
+ * @group Engine
8
12
  */
9
13
  export interface SSRSearchEngine extends SearchEngine {
14
+ /**
15
+ * Waits for the search to be completed and returns a promise that resolves to a `SearchCompletedAction`.
16
+ */
10
17
  waitForSearchCompletedAction(): Promise<SearchCompletedAction>;
11
18
  }
19
+ /**
20
+ * The options to create a search engine definition in SSR.
21
+ *
22
+ * @group Engine
23
+ */
12
24
  export type SearchEngineDefinitionOptions<TControllers extends ControllerDefinitionsMap<SSRSearchEngine, Controller>> = EngineDefinitionOptions<SearchEngineOptions, TControllers>;
13
25
  export type SearchCompletedAction = ReturnType<LegacySearchAction['fulfilled' | 'rejected']>;
14
26
  export type SearchEngineDefinition<TControllers extends ControllerDefinitionsMap<SSRSearchEngine, Controller>> = EngineDefinition<SSRSearchEngine, TControllers>;
15
27
  /**
16
- * Initializes a Search engine definition in SSR with per-call navigator context support.
28
+ * Initializes a Search engine definition in SSR with given controllers definitions and search engine config.
17
29
  *
18
30
  * @param options - The search engine definition
19
- * @returns Engine definition with support for per-call navigator context.
20
- *
21
- * @example
22
- * ```ts
23
- * const searchEngine = defineSearchEngine(config);
24
- *
25
- * // Pass navigator context directly to fetchStaticState
26
- * const staticState = await searchEngine.fetchStaticState({
27
- * navigatorContext: {
28
- * forwardedFor: req.ip,
29
- * referrer: req.headers.referer || null,
30
- * userAgent: req.headers['user-agent'] || null,
31
- * clientId: 'abc123'
32
- * }
33
- * });
34
- * ```
31
+ * @returns Three utility functions to fetch the initial state of the engine in SSR, hydrate the state in CSR,
32
+ * and a build function that can be used for edge cases requiring more control.
35
33
  *
36
34
  * @group Engine
37
35
  */
38
- export declare function defineSearchEngine<TControllerDefinitions extends ControllerDefinitionsMap<SearchEngine, Controller>>(options: SearchEngineDefinitionOptions<TControllerDefinitions>): EngineDefinition<SSRSearchEngine, TControllerDefinitions>;
36
+ export declare function defineSearchEngine<TControllerDefinitions extends ControllerDefinitionsMap<SearchEngine, Controller>>(options: SearchEngineDefinitionOptions<TControllerDefinitions>): {
37
+ fetchStaticState: import("../../common/types/fetch-static-state.js").FetchStaticState<import("redux").AnyAction, InferControllerStaticStateMapFromDefinitions<TControllerDefinitions>, InferControllerPropsMapFromDefinitions<TControllerDefinitions>>;
38
+ hydrateStaticState: import("../../common/types/hydrate-static-state.js").HydrateStaticState<SSRSearchEngine, import("../../common/types/inference.js").InferControllersMapFromDefinition<TControllerDefinitions>, import("redux").AnyAction, InferControllerPropsMapFromDefinitions<TControllerDefinitions>>;
39
+ setNavigatorContextProvider: (navigatorContextProvider: NavigatorContextProvider) => void;
40
+ };
@@ -82,8 +82,8 @@ export function buildRelevanceInspector(engine, props = {}) {
82
82
  warnProductionEnvironment('fieldsDescription');
83
83
  engine.logger.warn(`For production environment, please specify the necessary fields either when instantiating a ResultList controller, or by dispatching a registerFieldsToInclude action.
84
84
 
85
- https://docs.coveo.com/en/headless/latest/reference/search/controllers/result-list/#resultlistoptions
86
- https://docs.coveo.com/en/headless/latest/reference/search/actions/field/#registerfieldstoinclude`);
85
+ hhttps://docs.coveo.com/en/headless/latest/reference/interfaces/Search.ResultListOptions.html
86
+ https://docs.coveo.com/en/headless/latest/reference/interfaces/Search.FieldActionCreators.html#registerfieldstoinclude`);
87
87
  },
88
88
  };
89
89
  }
@@ -9,7 +9,8 @@ import { SolutionType } from '../types/controller-constants.js';
9
9
  /**
10
10
  * Initializes a Commerce engine definition in SSR with given controllers definitions and commerce engine config.
11
11
  * @param options - The commerce engine definition
12
- * @returns Engine definitions for different solution types that support per-call navigator context.
12
+ * @returns Three utility functions to fetch the initial state of the engine in SSR, hydrate the state in CSR,
13
+ * and a build function that can be used for edge cases requiring more control.
13
14
  *
14
15
  * @remarks
15
16
  * You can use the {@link InferStaticState} and {@link InferHydratedState} utility types with the returned engine definitions
@@ -17,49 +18,29 @@ import { SolutionType } from '../types/controller-constants.js';
17
18
  *
18
19
  * @example
19
20
  * ```ts
20
- * const { listingEngineDefinition } = defineCommerceEngine(engineConfig);
21
- *
22
- * // Pass navigator context directly to fetchStaticState
23
- * const staticState = await listingEngineDefinition.fetchStaticState({
24
- * navigatorContext: {
25
- * forwardedFor: req.ip,
26
- * referrer: req.headers.referer || null,
27
- * userAgent: req.headers['user-agent'] || null,
28
- * clientId: 'unique-session-id'
29
- * }
30
- * });
31
- *
32
- * // Framework examples:
33
- * // Express.js
34
- * app.get('/api/listing', async (req, res) => {
35
- * const state = await listingEngineDefinition.fetchStaticState({
36
- * navigatorContext: {
37
- * forwardedFor: req.ip,
38
- * referrer: req.headers.referer || null,
39
- * userAgent: req.headers['user-agent'] || null,
40
- * clientId: req.sessionID
41
- * }
42
- * });
43
- * res.json(state);
44
- * });
45
- *
46
- * type SearchStaticState = InferStaticState<typeof listingEngineDefinition>;
47
- * type SearchHydratedState = InferHydratedState<typeof listingEngineDefinition>;
21
+ * const engineDefinition = defineCommerceEngine(engineConfig);
22
+ * type SearchStaticState = InferStaticState<typeof engineDefinition>;
23
+ * type SearchHydratedState = InferHydratedState<typeof engineDefinition>;
48
24
  * ```
49
25
  *
50
26
  * @group Engine
51
27
  */
52
28
  export function defineCommerceEngine(options) {
53
29
  const { controllers: controllerDefinitions, ...engineOptions } = options;
30
+ const getOptions = () => engineOptions;
31
+ const setNavigatorContextProvider = (navigatorContextProvider) => {
32
+ engineOptions.navigatorContextProvider = navigatorContextProvider;
33
+ };
54
34
  const getAccessToken = () => engineOptions.configuration.accessToken;
55
35
  const setAccessToken = (accessToken) => {
56
36
  engineOptions.configuration.accessToken = accessToken;
57
37
  };
58
- const fetchStaticState = fetchStaticStateFactory(controllerDefinitions, engineOptions);
59
- const hydrateStaticState = hydratedStaticStateFactory(controllerDefinitions, engineOptions);
60
- const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(controllerDefinitions, engineOptions);
61
- const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(controllerDefinitions, engineOptions);
38
+ const fetchStaticState = fetchStaticStateFactory(controllerDefinitions, getOptions());
39
+ const hydrateStaticState = hydratedStaticStateFactory(controllerDefinitions, getOptions());
40
+ const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(controllerDefinitions, getOptions());
41
+ const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(controllerDefinitions, getOptions());
62
42
  const commonMethods = {
43
+ setNavigatorContextProvider,
63
44
  getAccessToken,
64
45
  setAccessToken,
65
46
  };
@@ -6,30 +6,16 @@ import { SolutionType } from '../types/controller-constants.js';
6
6
  import { buildFactory, } from './build-factory.js';
7
7
  export function fetchStaticStateFactory(controllerDefinitions, options) {
8
8
  return (solutionType) => async (...params) => {
9
- const [callOptions] = params;
10
- // Convert per-call navigator context to provider function
11
- const navigatorContextProvider = callOptions?.navigatorContext
12
- ? typeof callOptions.navigatorContext === 'function'
13
- ? callOptions.navigatorContext
14
- : () => callOptions.navigatorContext
15
- : undefined;
16
- // Create options for this call with navigator context
17
- const callSpecificOptions = {
9
+ const solutionTypeBuild = await buildFactory(controllerDefinitions, {
18
10
  ...options,
19
- navigatorContextProvider,
20
- configuration: {
21
- ...options.configuration,
22
- preprocessRequest: navigatorContextProvider
23
- ? augmentPreprocessRequestWithForwardedFor({
24
- preprocessRequest: options.configuration.preprocessRequest,
25
- navigatorContextProvider,
26
- loggerOptions: options.loggerOptions,
27
- })
28
- : options.configuration.preprocessRequest,
29
- },
30
- };
31
- const solutionTypeBuild = await buildFactory(controllerDefinitions, callSpecificOptions)(solutionType);
11
+ })(solutionType);
32
12
  const { engine, controllers } = await solutionTypeBuild(...params);
13
+ options.configuration.preprocessRequest =
14
+ augmentPreprocessRequestWithForwardedFor({
15
+ preprocessRequest: options.configuration.preprocessRequest,
16
+ navigatorContextProvider: options.navigatorContextProvider,
17
+ loggerOptions: options.loggerOptions,
18
+ });
33
19
  switch (solutionType) {
34
20
  case SolutionType.listing:
35
21
  buildProductListing(engine).executeFirstRequest();
@@ -1,3 +1,4 @@
1
+ import { buildLogger } from '../../../app/logger.js';
1
2
  import { buildSearchEngine, } from '../../../app/search-engine/search-engine.js';
2
3
  import { createWaitForActionMiddleware } from '../../../utils/utils.js';
3
4
  import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
@@ -22,75 +23,50 @@ function buildSSRSearchEngine(options) {
22
23
  };
23
24
  }
24
25
  /**
25
- * Initializes a Search engine definition in SSR with per-call navigator context support.
26
+ * Initializes a Search engine definition in SSR with given controllers definitions and search engine config.
26
27
  *
27
28
  * @param options - The search engine definition
28
- * @returns Engine definition with support for per-call navigator context.
29
- *
30
- * @example
31
- * ```ts
32
- * const searchEngine = defineSearchEngine(config);
33
- *
34
- * // Pass navigator context directly to fetchStaticState
35
- * const staticState = await searchEngine.fetchStaticState({
36
- * navigatorContext: {
37
- * forwardedFor: req.ip,
38
- * referrer: req.headers.referer || null,
39
- * userAgent: req.headers['user-agent'] || null,
40
- * clientId: 'abc123'
41
- * }
42
- * });
43
- * ```
29
+ * @returns Three utility functions to fetch the initial state of the engine in SSR, hydrate the state in CSR,
30
+ * and a build function that can be used for edge cases requiring more control.
44
31
  *
45
32
  * @group Engine
46
33
  */
47
34
  export function defineSearchEngine(options) {
48
35
  const { controllers: controllerDefinitions, ...engineOptions } = options;
49
- // biome-ignore lint/suspicious/noExplicitAny: Complex parameter typing would require extensive refactoring
50
- const hydrateStaticState = async (...params) => {
51
- const engine = buildSSRSearchEngine(engineOptions);
52
- const controllers = buildControllerDefinitions({
53
- definitionsMap: (controllerDefinitions ?? {}),
54
- engine,
55
- propsMap: {},
56
- });
57
- const [staticState] = params;
58
- engine.dispatch(staticState.searchAction);
59
- await engine.waitForSearchCompletedAction();
60
- return { engine, controllers };
36
+ const getOptions = () => {
37
+ return engineOptions;
61
38
  };
62
- // biome-ignore lint/suspicious/noExplicitAny: Parameter typing matches the interface contract
63
- const fetchStaticState = async (...params) => {
64
- const [callOptions] = params;
65
- // Convert per-call navigator context to provider function
66
- const navigatorContextProvider = callOptions?.navigatorContext
67
- ? typeof callOptions.navigatorContext === 'function'
68
- ? callOptions.navigatorContext
69
- : () => callOptions.navigatorContext
70
- : undefined;
71
- // Create options for this call with navigator context
72
- const callSpecificOptions = {
73
- ...options,
74
- navigatorContextProvider,
75
- configuration: {
76
- ...options.configuration,
77
- preprocessRequest: navigatorContextProvider
78
- ? augmentPreprocessRequestWithForwardedFor({
79
- preprocessRequest: options.configuration.preprocessRequest,
80
- navigatorContextProvider,
81
- loggerOptions: options.loggerOptions,
82
- })
83
- : options.configuration.preprocessRequest,
84
- },
85
- };
86
- const engine = buildSSRSearchEngine(callSpecificOptions);
39
+ const setNavigatorContextProvider = (navigatorContextProvider) => {
40
+ engineOptions.navigatorContextProvider = navigatorContextProvider;
41
+ };
42
+ const build = async (...[buildOptions]) => {
43
+ const logger = buildLogger(options.loggerOptions);
44
+ if (!getOptions().navigatorContextProvider) {
45
+ logger.warn('[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()');
46
+ }
47
+ const engine = buildSSRSearchEngine(buildOptions?.extend
48
+ ? await buildOptions.extend(getOptions())
49
+ : getOptions());
87
50
  const controllers = buildControllerDefinitions({
88
51
  definitionsMap: (controllerDefinitions ?? {}),
89
52
  engine,
90
- propsMap: (callOptions && 'controllers' in callOptions
91
- ? callOptions.controllers
53
+ propsMap: (buildOptions && 'controllers' in buildOptions
54
+ ? buildOptions.controllers
92
55
  : {}),
93
56
  });
57
+ return {
58
+ engine,
59
+ controllers,
60
+ };
61
+ };
62
+ const fetchStaticState = async (...params) => {
63
+ const { engine, controllers } = await build(...params);
64
+ options.configuration.preprocessRequest =
65
+ augmentPreprocessRequestWithForwardedFor({
66
+ preprocessRequest: options.configuration.preprocessRequest,
67
+ navigatorContextProvider: options.navigatorContextProvider,
68
+ loggerOptions: options.loggerOptions,
69
+ });
94
70
  engine.executeFirstSearch();
95
71
  const staticState = createStaticState({
96
72
  searchAction: await engine.waitForSearchCompletedAction(),
@@ -98,8 +74,15 @@ export function defineSearchEngine(options) {
98
74
  });
99
75
  return staticState;
100
76
  };
77
+ const hydrateStaticState = async (...params) => {
78
+ const { engine, controllers } = await build(...params);
79
+ engine.dispatch(params[0].searchAction);
80
+ await engine.waitForSearchCompletedAction();
81
+ return { engine, controllers };
82
+ };
101
83
  return {
102
84
  fetchStaticState,
103
85
  hydrateStaticState,
86
+ setNavigatorContextProvider,
104
87
  };
105
88
  }
@@ -1,2 +1,2 @@
1
- export const VERSION = "3.28.4-pre.f33fb697dc" || 'Test version';
1
+ export const VERSION = "3.28.4-pre.f345a65b79" || 'Test version';
2
2
  export const COVEO_FRAMEWORK = ['@coveo/atomic', '@coveo/quantic'];