@coveo/headless 3.28.4-pre.89652c491b → 3.28.4-pre.8e48fb2f29

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.
@@ -800,7 +800,7 @@ var import_bueno5 = require("@coveo/bueno");
800
800
  var import_toolkit7 = require("@reduxjs/toolkit");
801
801
 
802
802
  // src/utils/version.ts
803
- var VERSION = "3.28.4-pre.89652c491b";
803
+ var VERSION = "3.28.4-pre.8e48fb2f29";
804
804
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
805
805
 
806
806
  // src/features/configuration/configuration-actions.ts
@@ -1148,7 +1148,7 @@ var import_bueno6 = require("@coveo/bueno");
1148
1148
  var import_toolkit4 = require("@reduxjs/toolkit");
1149
1149
 
1150
1150
  // src/utils/version.ts
1151
- var VERSION = "3.28.4-pre.89652c491b";
1151
+ var VERSION = "3.28.4-pre.8e48fb2f29";
1152
1152
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
1153
1153
 
1154
1154
  // src/features/configuration/configuration-actions.ts
@@ -1374,7 +1374,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
1374
1374
  var import_toolkit = require("@reduxjs/toolkit");
1375
1375
 
1376
1376
  // src/utils/version.ts
1377
- var VERSION = "3.28.4-pre.89652c491b";
1377
+ var VERSION = "3.28.4-pre.8e48fb2f29";
1378
1378
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
1379
1379
 
1380
1380
  // src/api/analytics/analytics-selectors.ts
@@ -1278,7 +1278,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
1278
1278
  var import_toolkit = require("@reduxjs/toolkit");
1279
1279
 
1280
1280
  // src/utils/version.ts
1281
- var VERSION = "3.28.4-pre.89652c491b";
1281
+ var VERSION = "3.28.4-pre.8e48fb2f29";
1282
1282
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
1283
1283
 
1284
1284
  // src/api/analytics/analytics-selectors.ts
@@ -881,7 +881,7 @@ var validateObject = (engine, schema, obj, validationMessage, errorMessage) => {
881
881
  };
882
882
 
883
883
  // src/utils/version.ts
884
- var VERSION = "3.28.4-pre.89652c491b";
884
+ var VERSION = "3.28.4-pre.8e48fb2f29";
885
885
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
886
886
 
887
887
  // src/features/configuration/configuration-actions.ts
@@ -1306,7 +1306,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
1306
1306
  var import_toolkit = require("@reduxjs/toolkit");
1307
1307
 
1308
1308
  // src/utils/version.ts
1309
- var VERSION = "3.28.4-pre.89652c491b";
1309
+ var VERSION = "3.28.4-pre.8e48fb2f29";
1310
1310
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
1311
1311
 
1312
1312
  // src/api/analytics/analytics-selectors.ts
@@ -468,7 +468,7 @@ var import_bueno8 = require("@coveo/bueno");
468
468
  var import_toolkit3 = require("@reduxjs/toolkit");
469
469
 
470
470
  // src/utils/version.ts
471
- var VERSION = "3.28.4-pre.89652c491b";
471
+ var VERSION = "3.28.4-pre.8e48fb2f29";
472
472
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
473
473
 
474
474
  // src/features/configuration/configuration-actions.ts
@@ -468,7 +468,7 @@ var import_bueno8 = require("@coveo/bueno");
468
468
  var import_toolkit3 = require("@reduxjs/toolkit");
469
469
 
470
470
  // src/utils/version.ts
471
- var VERSION = "3.28.4-pre.89652c491b";
471
+ var VERSION = "3.28.4-pre.8e48fb2f29";
472
472
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
473
473
 
474
474
  // src/features/configuration/configuration-actions.ts
@@ -1306,7 +1306,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
1306
1306
  var import_toolkit = require("@reduxjs/toolkit");
1307
1307
 
1308
1308
  // src/utils/version.ts
1309
- var VERSION = "3.28.4-pre.89652c491b";
1309
+ var VERSION = "3.28.4-pre.8e48fb2f29";
1310
1310
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
1311
1311
 
1312
1312
  // src/api/analytics/analytics-selectors.ts
@@ -1,5 +1,5 @@
1
1
  import type { UnknownAction } from '@reduxjs/toolkit';
2
- import type { NavigatorContext, NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
2
+ import type { NavigatorContext } from '../../../app/navigator-context-provider.js';
3
3
  import type { Controller } from '../../../controllers/controller/headless-controller.js';
4
4
  import type { ControllerStaticStateMap, ControllersPropsMap } from '../../common/types/controllers.js';
5
5
  import type { SolutionType } from './controller-constants.js';
@@ -24,25 +24,11 @@ export interface FetchStaticStateOptions {
24
24
  * });
25
25
  * ```
26
26
  */
27
- navigatorContext?: NavigatorContext | NavigatorContextProvider;
27
+ navigatorContext?: NavigatorContext;
28
28
  }
29
29
  /**
30
30
  * Executes only the initial search for a given configuration, then returns a resumable snapshot of engine state along with the state of the controllers.
31
31
  *
32
32
  * Useful for static generation and server-side rendering.
33
- *
34
- * @example
35
- * ```ts
36
- * // Pass navigator context directly in the options
37
- * const staticState = await engineDefinition.fetchStaticState({
38
- * navigatorContext: {
39
- * forwardedFor: request.ip,
40
- * referrer: request.headers.referer,
41
- * userAgent: request.headers['user-agent'],
42
- * location: request.url,
43
- * clientId: 'session-123'
44
- * }
45
- * });
46
- * ```
47
33
  */
48
34
  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>>;
@@ -0,0 +1,24 @@
1
+ import type { PreprocessRequest } from '../../api/preprocess-request.js';
2
+ import type { LoggerOptions } from '../../app/logger.js';
3
+ import type { NavigatorContext, NavigatorContextProvider } from '../../app/navigator-context-provider.js';
4
+ /**
5
+ * Extracts navigator context from fetchStaticState parameters and creates the necessary configuration.
6
+ * This is the single entry point for all navigator context processing.
7
+ */
8
+ export declare function extractNavigatorContextConfig(params: unknown[]): {
9
+ navigatorContextProvider?: NavigatorContextProvider;
10
+ callOptions?: {
11
+ navigatorContext?: NavigatorContext;
12
+ controllers?: unknown;
13
+ };
14
+ };
15
+ /**
16
+ * Creates engine options with navigator context configuration applied.
17
+ * This eliminates duplication between commerce and search engines.
18
+ */
19
+ export declare function createEngineOptionsWithNavigatorContext<TOptions extends {
20
+ configuration: {
21
+ preprocessRequest?: PreprocessRequest;
22
+ };
23
+ loggerOptions?: LoggerOptions;
24
+ }>(baseOptions: TOptions, navigatorContextProvider?: NavigatorContextProvider): TOptions;
@@ -1,28 +1,15 @@
1
1
  import type { UnknownAction } from '@reduxjs/toolkit';
2
- import type { NavigatorContext, NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
2
+ import type { NavigatorContext } from '../../../app/navigator-context-provider.js';
3
3
  import type { ControllerStaticStateMap, ControllersPropsMap } from './controllers.js';
4
4
  import type { EngineDefinitionControllersPropsOption, EngineStaticState } from './engine.js';
5
5
  import type { OptionsTuple } from './utilities.js';
6
6
  type FetchStaticStateOptions = {
7
- navigatorContext?: NavigatorContext | NavigatorContextProvider;
7
+ navigatorContext?: NavigatorContext;
8
8
  };
9
9
  /**
10
10
  * 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
11
  *
12
12
  * 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
13
  */
27
14
  export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<FetchStaticStateOptions & EngineDefinitionControllersPropsOption<TControllersProps>>) => Promise<EngineStaticState<TSearchAction, TControllersStaticState>>;
28
15
  export {};
@@ -1,33 +1,14 @@
1
1
  import { buildProductListing } from '../../../controllers/commerce/product-listing/headless-product-listing.js';
2
2
  import { buildSearch } from '../../../controllers/commerce/search/headless-search.js';
3
- import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
3
+ import { createEngineOptionsWithNavigatorContext, extractNavigatorContextConfig, } from '../../common/navigator-context-utils.js';
4
4
  import { createStaticState } from '../controller-utils.js';
5
5
  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;
9
+ const { navigatorContextProvider } = extractNavigatorContextConfig(params);
16
10
  // Create options for this call with navigator context
17
- const callSpecificOptions = {
18
- ...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
- };
11
+ const callSpecificOptions = createEngineOptionsWithNavigatorContext(options, navigatorContextProvider);
31
12
  const solutionTypeBuild = await buildFactory(controllerDefinitions, callSpecificOptions)(solutionType);
32
13
  const { engine, controllers } = await solutionTypeBuild(...params);
33
14
  switch (solutionType) {
@@ -0,0 +1,36 @@
1
+ import { augmentPreprocessRequestWithForwardedFor } from './augment-preprocess-request.js';
2
+ /**
3
+ * Extracts navigator context from fetchStaticState parameters and creates the necessary configuration.
4
+ * This is the single entry point for all navigator context processing.
5
+ */
6
+ export function extractNavigatorContextConfig(params) {
7
+ const [callOptions] = params;
8
+ if (!callOptions?.navigatorContext) {
9
+ return { callOptions };
10
+ }
11
+ return {
12
+ callOptions,
13
+ navigatorContextProvider: () => callOptions.navigatorContext,
14
+ };
15
+ }
16
+ /**
17
+ * Creates engine options with navigator context configuration applied.
18
+ * This eliminates duplication between commerce and search engines.
19
+ */
20
+ export function createEngineOptionsWithNavigatorContext(baseOptions, navigatorContextProvider) {
21
+ if (!navigatorContextProvider) {
22
+ return baseOptions;
23
+ }
24
+ return {
25
+ ...baseOptions,
26
+ navigatorContextProvider,
27
+ configuration: {
28
+ ...baseOptions.configuration,
29
+ preprocessRequest: augmentPreprocessRequestWithForwardedFor({
30
+ preprocessRequest: baseOptions.configuration.preprocessRequest,
31
+ navigatorContextProvider,
32
+ loggerOptions: baseOptions.loggerOptions,
33
+ }),
34
+ },
35
+ };
36
+ }
@@ -1,7 +1,7 @@
1
1
  import { buildSearchEngine, } from '../../../app/search-engine/search-engine.js';
2
2
  import { createWaitForActionMiddleware } from '../../../utils/utils.js';
3
- import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
4
3
  import { buildControllerDefinitions, createStaticState, } from '../../common/controller-utils.js';
4
+ import { createEngineOptionsWithNavigatorContext, extractNavigatorContextConfig, } from '../../common/navigator-context-utils.js';
5
5
  function isSearchCompletedAction(action) {
6
6
  return /^search\/executeSearch\/(fulfilled|rejected)$/.test(action.type);
7
7
  }
@@ -46,7 +46,6 @@ function buildSSRSearchEngine(options) {
46
46
  */
47
47
  export function defineSearchEngine(options) {
48
48
  const { controllers: controllerDefinitions, ...engineOptions } = options;
49
- // biome-ignore lint/suspicious/noExplicitAny: Complex parameter typing would require extensive refactoring
50
49
  const hydrateStaticState = async (...params) => {
51
50
  const engine = buildSSRSearchEngine(engineOptions);
52
51
  const controllers = buildControllerDefinitions({
@@ -59,30 +58,10 @@ export function defineSearchEngine(options) {
59
58
  await engine.waitForSearchCompletedAction();
60
59
  return { engine, controllers };
61
60
  };
62
- // biome-ignore lint/suspicious/noExplicitAny: Parameter typing matches the interface contract
63
61
  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;
62
+ const { callOptions, navigatorContextProvider } = extractNavigatorContextConfig(params);
71
63
  // 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
- };
64
+ const callSpecificOptions = createEngineOptionsWithNavigatorContext(options, navigatorContextProvider);
86
65
  const engine = buildSSRSearchEngine(callSpecificOptions);
87
66
  const controllers = buildControllerDefinitions({
88
67
  definitionsMap: (controllerDefinitions ?? {}),
@@ -1,2 +1,2 @@
1
- export const VERSION = "3.28.4-pre.89652c491b" || 'Test version';
1
+ export const VERSION = "3.28.4-pre.8e48fb2f29" || 'Test version';
2
2
  export const COVEO_FRAMEWORK = ['@coveo/atomic', '@coveo/quantic'];