@coveo/headless 3.28.4-pre.c534c63a6d → 3.28.4-pre.c9b699efbb
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.
- package/dist/cjs/case-assist/headless.cjs +1 -1
- package/dist/cjs/commerce/headless.cjs +1 -1
- package/dist/cjs/headless.cjs +1 -1
- package/dist/cjs/insight/headless.cjs +1 -1
- package/dist/cjs/recommendation/headless.cjs +1 -1
- package/dist/cjs/ssr/headless.cjs +1 -1
- package/dist/cjs/ssr-commerce/headless.cjs +1 -1
- package/dist/cjs/ssr-commerce-next/headless.cjs +1 -1
- package/dist/cjs/ssr-next/headless.cjs +1 -1
- package/dist/definitions/ssr-next/commerce/engine/commerce-engine.ssr.d.ts +28 -3
- package/dist/definitions/ssr-next/commerce/types/engine.d.ts +0 -8
- package/dist/definitions/ssr-next/commerce/types/fetch-static-state.d.ts +22 -1
- package/dist/definitions/ssr-next/common/navigator-context-utils.d.ts +22 -0
- package/dist/definitions/ssr-next/common/types/engine.d.ts +0 -8
- package/dist/definitions/ssr-next/common/types/fetch-static-state.d.ts +4 -1
- package/dist/definitions/ssr-next/search/engine/search-engine.ssr.d.ts +18 -20
- package/dist/esm/ssr-next/commerce/engine/commerce-engine.ssr.js +32 -12
- package/dist/esm/ssr-next/commerce/factories/static-state-factory.js +17 -8
- package/dist/esm/ssr-next/common/navigator-context-utils.js +28 -0
- package/dist/esm/ssr-next/search/engine/search-engine.ssr.js +49 -39
- package/dist/esm/utils/version.js +1 -1
- package/dist/quantic/case-assist/headless.js +1 -1
- package/dist/quantic/commerce/headless.js +1 -1
- package/dist/quantic/headless.js +1 -1
- package/dist/quantic/insight/headless.js +1 -1
- package/dist/quantic/recommendation/headless.js +1 -1
- package/package.json +1 -1
|
@@ -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.
|
|
803
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
1151
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
1152
1152
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1153
1153
|
|
|
1154
1154
|
// src/features/configuration/configuration-actions.ts
|
package/dist/cjs/headless.cjs
CHANGED
|
@@ -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.
|
|
1377
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
1281
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
884
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
1309
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
471
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
471
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
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.
|
|
1309
|
+
var VERSION = "3.28.4-pre.c9b699efbb";
|
|
1310
1310
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1311
1311
|
|
|
1312
1312
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -18,9 +18,34 @@ import type { CommerceEngineDefinition } from '../types/engine.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* const { listingEngineDefinition } = defineCommerceEngine(engineConfig);
|
|
22
|
+
*
|
|
23
|
+
* // Pass navigator context directly to fetchStaticState
|
|
24
|
+
* const staticState = await listingEngineDefinition.fetchStaticState({
|
|
25
|
+
* navigatorContext: {
|
|
26
|
+
* forwardedFor: req.ip,
|
|
27
|
+
* referrer: req.headers.referer || null,
|
|
28
|
+
* userAgent: req.headers['user-agent'] || null,
|
|
29
|
+
* clientId: 'unique-session-id'
|
|
30
|
+
* }
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Framework examples:
|
|
34
|
+
* // Express.js
|
|
35
|
+
* app.get('/api/listing', async (req, res) => {
|
|
36
|
+
* const state = await listingEngineDefinition.fetchStaticState({
|
|
37
|
+
* navigatorContext: {
|
|
38
|
+
* forwardedFor: req.ip,
|
|
39
|
+
* referrer: req.headers.referer || null,
|
|
40
|
+
* userAgent: req.headers['user-agent'] || null,
|
|
41
|
+
* clientId: req.sessionID
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
* res.json(state);
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* type SearchStaticState = InferStaticState<typeof listingEngineDefinition>;
|
|
48
|
+
* type SearchHydratedState = InferHydratedState<typeof listingEngineDefinition>;
|
|
24
49
|
* ```
|
|
25
50
|
*
|
|
26
51
|
* @group Engine
|
|
@@ -1,7 +1,6 @@
|
|
|
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';
|
|
5
4
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
6
5
|
import type { ControllerStaticStateMap } from '../../common/types/controllers.js';
|
|
7
6
|
import type { SSRCommerceEngine } from '../factories/build-factory.js';
|
|
@@ -33,13 +32,6 @@ export interface CommerceEngineDefinition<TControllers extends ControllerDefinit
|
|
|
33
32
|
* Fetches the hydrated state on the client side using your engine definition and the static state.
|
|
34
33
|
*/
|
|
35
34
|
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;
|
|
43
35
|
/**
|
|
44
36
|
* Returns the access token.
|
|
45
37
|
*/
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
+
import type { NavigatorContext } from '../../../app/navigator-context-provider.js';
|
|
2
3
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
4
|
import type { ControllerStaticStateMap, ControllersPropsMap } from '../../common/types/controllers.js';
|
|
4
5
|
import type { SolutionType } from './controller-constants.js';
|
|
5
6
|
import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, OptionsTuple } from './controller-definitions.js';
|
|
6
7
|
import type { EngineStaticState } from './engine.js';
|
|
7
|
-
export
|
|
8
|
+
export interface FetchStaticStateOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The navigator context for this request.
|
|
11
|
+
*
|
|
12
|
+
* Used to pass required client information when making server-side requests.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // In your server route handler
|
|
17
|
+
* const staticState = await listingEngineDefinition.fetchStaticState({
|
|
18
|
+
* navigatorContext: {
|
|
19
|
+
* forwardedFor: req.ip,
|
|
20
|
+
* referrer: req.headers.referer || null,
|
|
21
|
+
* userAgent: req.headers['user-agent'] || null,
|
|
22
|
+
* clientId: req.sessionID || 'anonymous'
|
|
23
|
+
* }
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
navigatorContext?: NavigatorContext;
|
|
28
|
+
}
|
|
8
29
|
/**
|
|
9
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.
|
|
10
31
|
*
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NavigatorContext, NavigatorContextProvider } from '../../app/navigator-context-provider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a navigator context object to a provider function.
|
|
4
|
+
* Wraps the context object in a function that returns the object.
|
|
5
|
+
*/
|
|
6
|
+
export declare function convertNavigatorContextToProvider(navigatorContext: NavigatorContext): NavigatorContextProvider;
|
|
7
|
+
/**
|
|
8
|
+
* Extracts navigator context from fetchStaticState parameters and converts it to a provider function.
|
|
9
|
+
* This handles the common pattern of extracting the first parameter and converting the navigator context.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractNavigatorContextProvider(params: unknown[]): NavigatorContextProvider | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts call options and navigator context provider from fetchStaticState parameters.
|
|
14
|
+
* Returns both the original call options and the converted navigator context provider.
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractCallOptionsAndNavigatorContextProvider(params: unknown[]): {
|
|
17
|
+
callOptions: {
|
|
18
|
+
navigatorContext?: NavigatorContext;
|
|
19
|
+
controllers?: unknown;
|
|
20
|
+
} | undefined;
|
|
21
|
+
navigatorContextProvider: NavigatorContextProvider | undefined;
|
|
22
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
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';
|
|
5
4
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
6
5
|
import type { Build } from './build.js';
|
|
7
6
|
import type { ControllerDefinitionsMap, ControllerStaticStateMap, ControllersMap, ControllersPropsMap } from './controllers.js';
|
|
@@ -27,13 +26,6 @@ export interface EngineDefinition<TEngine extends CoreEngine | CoreEngineNext, T
|
|
|
27
26
|
* Fetches the hydrated state on the client side using your engine definition and the static state.
|
|
28
27
|
*/
|
|
29
28
|
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;
|
|
37
29
|
}
|
|
38
30
|
export interface EngineDefinitionBuildResult<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap> {
|
|
39
31
|
engine: TEngine;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
+
import type { NavigatorContext } from '../../../app/navigator-context-provider.js';
|
|
2
3
|
import type { ControllerStaticStateMap, ControllersPropsMap } from './controllers.js';
|
|
3
4
|
import type { EngineDefinitionControllersPropsOption, EngineStaticState } from './engine.js';
|
|
4
5
|
import type { OptionsTuple } from './utilities.js';
|
|
5
|
-
type FetchStaticStateOptions = {
|
|
6
|
+
type FetchStaticStateOptions = {
|
|
7
|
+
navigatorContext?: NavigatorContext;
|
|
8
|
+
};
|
|
6
9
|
/**
|
|
7
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.
|
|
8
11
|
*
|
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
import type { NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
|
|
2
1
|
import { type SearchEngine, type SearchEngineOptions } from '../../../app/search-engine/search-engine.js';
|
|
3
2
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
4
3
|
import type { LegacySearchAction } from '../../../features/analytics/analytics-utils.js';
|
|
5
4
|
import type { ControllerDefinitionsMap } from '../../common/types/controllers.js';
|
|
6
5
|
import type { EngineDefinition, EngineDefinitionOptions } from '../../common/types/engine.js';
|
|
7
|
-
import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitions } from '../../common/types/inference.js';
|
|
8
6
|
/**
|
|
9
7
|
* The SSR search engine.
|
|
10
|
-
*
|
|
11
|
-
* @group Engine
|
|
12
8
|
*/
|
|
13
9
|
export interface SSRSearchEngine extends SearchEngine {
|
|
14
|
-
/**
|
|
15
|
-
* Waits for the search to be completed and returns a promise that resolves to a `SearchCompletedAction`.
|
|
16
|
-
*/
|
|
17
10
|
waitForSearchCompletedAction(): Promise<SearchCompletedAction>;
|
|
18
11
|
}
|
|
19
|
-
/**
|
|
20
|
-
* The options to create a search engine definition in SSR.
|
|
21
|
-
*
|
|
22
|
-
* @group Engine
|
|
23
|
-
*/
|
|
24
12
|
export type SearchEngineDefinitionOptions<TControllers extends ControllerDefinitionsMap<SSRSearchEngine, Controller>> = EngineDefinitionOptions<SearchEngineOptions, TControllers>;
|
|
25
13
|
export type SearchCompletedAction = ReturnType<LegacySearchAction['fulfilled' | 'rejected']>;
|
|
26
14
|
export type SearchEngineDefinition<TControllers extends ControllerDefinitionsMap<SSRSearchEngine, Controller>> = EngineDefinition<SSRSearchEngine, TControllers>;
|
|
27
15
|
/**
|
|
28
|
-
* Initializes a Search engine definition in SSR with
|
|
16
|
+
* Initializes a Search engine definition in SSR with per-call navigator context support.
|
|
29
17
|
*
|
|
30
18
|
* @param options - The search engine definition
|
|
31
|
-
* @returns
|
|
32
|
-
*
|
|
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
|
+
* ```
|
|
33
35
|
*
|
|
34
36
|
* @group Engine
|
|
35
37
|
*/
|
|
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
|
-
};
|
|
38
|
+
export declare function defineSearchEngine<TControllerDefinitions extends ControllerDefinitionsMap<SearchEngine, Controller>>(options: SearchEngineDefinitionOptions<TControllerDefinitions>): EngineDefinition<SSRSearchEngine, TControllerDefinitions>;
|
|
@@ -18,29 +18,49 @@ import { SolutionType } from '../types/controller-constants.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* const { listingEngineDefinition } = defineCommerceEngine(engineConfig);
|
|
22
|
+
*
|
|
23
|
+
* // Pass navigator context directly to fetchStaticState
|
|
24
|
+
* const staticState = await listingEngineDefinition.fetchStaticState({
|
|
25
|
+
* navigatorContext: {
|
|
26
|
+
* forwardedFor: req.ip,
|
|
27
|
+
* referrer: req.headers.referer || null,
|
|
28
|
+
* userAgent: req.headers['user-agent'] || null,
|
|
29
|
+
* clientId: 'unique-session-id'
|
|
30
|
+
* }
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Framework examples:
|
|
34
|
+
* // Express.js
|
|
35
|
+
* app.get('/api/listing', async (req, res) => {
|
|
36
|
+
* const state = await listingEngineDefinition.fetchStaticState({
|
|
37
|
+
* navigatorContext: {
|
|
38
|
+
* forwardedFor: req.ip,
|
|
39
|
+
* referrer: req.headers.referer || null,
|
|
40
|
+
* userAgent: req.headers['user-agent'] || null,
|
|
41
|
+
* clientId: req.sessionID
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
* res.json(state);
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* type SearchStaticState = InferStaticState<typeof listingEngineDefinition>;
|
|
48
|
+
* type SearchHydratedState = InferHydratedState<typeof listingEngineDefinition>;
|
|
24
49
|
* ```
|
|
25
50
|
*
|
|
26
51
|
* @group Engine
|
|
27
52
|
*/
|
|
28
53
|
export function defineCommerceEngine(options) {
|
|
29
54
|
const { controllers: controllerDefinitions, ...engineOptions } = options;
|
|
30
|
-
const getOptions = () => engineOptions;
|
|
31
|
-
const setNavigatorContextProvider = (navigatorContextProvider) => {
|
|
32
|
-
engineOptions.navigatorContextProvider = navigatorContextProvider;
|
|
33
|
-
};
|
|
34
55
|
const getAccessToken = () => engineOptions.configuration.accessToken;
|
|
35
56
|
const setAccessToken = (accessToken) => {
|
|
36
57
|
engineOptions.configuration.accessToken = accessToken;
|
|
37
58
|
};
|
|
38
|
-
const fetchStaticState = fetchStaticStateFactory(controllerDefinitions,
|
|
39
|
-
const hydrateStaticState = hydratedStaticStateFactory(controllerDefinitions,
|
|
40
|
-
const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(controllerDefinitions,
|
|
41
|
-
const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(controllerDefinitions,
|
|
59
|
+
const fetchStaticState = fetchStaticStateFactory(controllerDefinitions, engineOptions);
|
|
60
|
+
const hydrateStaticState = hydratedStaticStateFactory(controllerDefinitions, engineOptions);
|
|
61
|
+
const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(controllerDefinitions, engineOptions);
|
|
62
|
+
const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(controllerDefinitions, engineOptions);
|
|
42
63
|
const commonMethods = {
|
|
43
|
-
setNavigatorContextProvider,
|
|
44
64
|
getAccessToken,
|
|
45
65
|
setAccessToken,
|
|
46
66
|
};
|
|
@@ -1,21 +1,30 @@
|
|
|
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
3
|
import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
|
|
4
|
+
import { extractNavigatorContextProvider } from '../../common/navigator-context-utils.js';
|
|
4
5
|
import { createStaticState } from '../controller-utils.js';
|
|
5
6
|
import { SolutionType } from '../types/controller-constants.js';
|
|
6
7
|
import { buildFactory, } from './build-factory.js';
|
|
7
8
|
export function fetchStaticStateFactory(controllerDefinitions, options) {
|
|
8
9
|
return (solutionType) => async (...params) => {
|
|
9
|
-
const
|
|
10
|
+
const navigatorContextProvider = extractNavigatorContextProvider(params);
|
|
11
|
+
// Create options for this call with navigator context
|
|
12
|
+
const callSpecificOptions = {
|
|
10
13
|
...options,
|
|
11
|
-
|
|
14
|
+
navigatorContextProvider,
|
|
15
|
+
configuration: {
|
|
16
|
+
...options.configuration,
|
|
17
|
+
preprocessRequest: navigatorContextProvider
|
|
18
|
+
? augmentPreprocessRequestWithForwardedFor({
|
|
19
|
+
preprocessRequest: options.configuration.preprocessRequest,
|
|
20
|
+
navigatorContextProvider,
|
|
21
|
+
loggerOptions: options.loggerOptions,
|
|
22
|
+
})
|
|
23
|
+
: options.configuration.preprocessRequest,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const solutionTypeBuild = await buildFactory(controllerDefinitions, callSpecificOptions)(solutionType);
|
|
12
27
|
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
|
-
});
|
|
19
28
|
switch (solutionType) {
|
|
20
29
|
case SolutionType.listing:
|
|
21
30
|
buildProductListing(engine).executeFirstRequest();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a navigator context object to a provider function.
|
|
3
|
+
* Wraps the context object in a function that returns the object.
|
|
4
|
+
*/
|
|
5
|
+
export function convertNavigatorContextToProvider(navigatorContext) {
|
|
6
|
+
return () => navigatorContext;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Extracts navigator context from fetchStaticState parameters and converts it to a provider function.
|
|
10
|
+
* This handles the common pattern of extracting the first parameter and converting the navigator context.
|
|
11
|
+
*/
|
|
12
|
+
export function extractNavigatorContextProvider(params) {
|
|
13
|
+
const [callOptions] = params;
|
|
14
|
+
return callOptions?.navigatorContext
|
|
15
|
+
? convertNavigatorContextToProvider(callOptions.navigatorContext)
|
|
16
|
+
: undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extracts call options and navigator context provider from fetchStaticState parameters.
|
|
20
|
+
* Returns both the original call options and the converted navigator context provider.
|
|
21
|
+
*/
|
|
22
|
+
export function extractCallOptionsAndNavigatorContextProvider(params) {
|
|
23
|
+
const [callOptions] = params;
|
|
24
|
+
const navigatorContextProvider = callOptions?.navigatorContext
|
|
25
|
+
? convertNavigatorContextToProvider(callOptions.navigatorContext)
|
|
26
|
+
: undefined;
|
|
27
|
+
return { callOptions, navigatorContextProvider };
|
|
28
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { buildLogger } from '../../../app/logger.js';
|
|
2
1
|
import { buildSearchEngine, } from '../../../app/search-engine/search-engine.js';
|
|
3
2
|
import { createWaitForActionMiddleware } from '../../../utils/utils.js';
|
|
4
3
|
import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
|
|
5
4
|
import { buildControllerDefinitions, createStaticState, } from '../../common/controller-utils.js';
|
|
5
|
+
import { extractCallOptionsAndNavigatorContextProvider } from '../../common/navigator-context-utils.js';
|
|
6
6
|
function isSearchCompletedAction(action) {
|
|
7
7
|
return /^search\/executeSearch\/(fulfilled|rejected)$/.test(action.type);
|
|
8
8
|
}
|
|
@@ -23,50 +23,67 @@ function buildSSRSearchEngine(options) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Initializes a Search engine definition in SSR with
|
|
26
|
+
* Initializes a Search engine definition in SSR with per-call navigator context support.
|
|
27
27
|
*
|
|
28
28
|
* @param options - The search engine definition
|
|
29
|
-
* @returns
|
|
30
|
-
*
|
|
29
|
+
* @returns Engine definition with support for per-call navigator context.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const searchEngine = defineSearchEngine(config);
|
|
34
|
+
*
|
|
35
|
+
* // Pass navigator context directly to fetchStaticState
|
|
36
|
+
* const staticState = await searchEngine.fetchStaticState({
|
|
37
|
+
* navigatorContext: {
|
|
38
|
+
* forwardedFor: req.ip,
|
|
39
|
+
* referrer: req.headers.referer || null,
|
|
40
|
+
* userAgent: req.headers['user-agent'] || null,
|
|
41
|
+
* clientId: 'abc123'
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
31
45
|
*
|
|
32
46
|
* @group Engine
|
|
33
47
|
*/
|
|
34
48
|
export function defineSearchEngine(options) {
|
|
35
49
|
const { controllers: controllerDefinitions, ...engineOptions } = options;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
};
|
|
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());
|
|
50
|
+
const hydrateStaticState = async (...params) => {
|
|
51
|
+
const engine = buildSSRSearchEngine(engineOptions);
|
|
50
52
|
const controllers = buildControllerDefinitions({
|
|
51
53
|
definitionsMap: (controllerDefinitions ?? {}),
|
|
52
54
|
engine,
|
|
53
|
-
propsMap:
|
|
54
|
-
? buildOptions.controllers
|
|
55
|
-
: {}),
|
|
55
|
+
propsMap: {},
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
57
|
+
const [staticState] = params;
|
|
58
|
+
engine.dispatch(staticState.searchAction);
|
|
59
|
+
await engine.waitForSearchCompletedAction();
|
|
60
|
+
return { engine, controllers };
|
|
61
61
|
};
|
|
62
62
|
const fetchStaticState = async (...params) => {
|
|
63
|
-
const {
|
|
64
|
-
options
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const { callOptions, navigatorContextProvider } = extractCallOptionsAndNavigatorContextProvider(params);
|
|
64
|
+
// Create options for this call with navigator context
|
|
65
|
+
const callSpecificOptions = {
|
|
66
|
+
...options,
|
|
67
|
+
navigatorContextProvider,
|
|
68
|
+
configuration: {
|
|
69
|
+
...options.configuration,
|
|
70
|
+
preprocessRequest: navigatorContextProvider
|
|
71
|
+
? augmentPreprocessRequestWithForwardedFor({
|
|
72
|
+
preprocessRequest: options.configuration.preprocessRequest,
|
|
73
|
+
navigatorContextProvider,
|
|
74
|
+
loggerOptions: options.loggerOptions,
|
|
75
|
+
})
|
|
76
|
+
: options.configuration.preprocessRequest,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
const engine = buildSSRSearchEngine(callSpecificOptions);
|
|
80
|
+
const controllers = buildControllerDefinitions({
|
|
81
|
+
definitionsMap: (controllerDefinitions ?? {}),
|
|
82
|
+
engine,
|
|
83
|
+
propsMap: (callOptions && 'controllers' in callOptions
|
|
84
|
+
? callOptions.controllers
|
|
85
|
+
: {}),
|
|
86
|
+
});
|
|
70
87
|
engine.executeFirstSearch();
|
|
71
88
|
const staticState = createStaticState({
|
|
72
89
|
searchAction: await engine.waitForSearchCompletedAction(),
|
|
@@ -74,15 +91,8 @@ export function defineSearchEngine(options) {
|
|
|
74
91
|
});
|
|
75
92
|
return staticState;
|
|
76
93
|
};
|
|
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
|
-
};
|
|
83
94
|
return {
|
|
84
95
|
fetchStaticState,
|
|
85
96
|
hydrateStaticState,
|
|
86
|
-
setNavigatorContextProvider,
|
|
87
97
|
};
|
|
88
98
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "3.28.4-pre.
|
|
1
|
+
export const VERSION = "3.28.4-pre.c9b699efbb" || 'Test version';
|
|
2
2
|
export const COVEO_FRAMEWORK = ['@coveo/atomic', '@coveo/quantic'];
|