@coveo/headless 3.28.4-pre.e9817a9757 → 3.28.4-pre.ea13b3b94e
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 +3 -28
- package/dist/definitions/ssr-next/commerce/types/engine.d.ts +8 -0
- package/dist/definitions/ssr-next/commerce/types/fetch-static-state.d.ts +1 -22
- package/dist/definitions/ssr-next/common/types/engine.d.ts +8 -0
- package/dist/definitions/ssr-next/common/types/fetch-static-state.d.ts +1 -4
- package/dist/definitions/ssr-next/search/engine/search-engine.ssr.d.ts +20 -18
- package/dist/definitions/ssr-next.index.d.ts +5 -11
- package/dist/esm/ssr-next/commerce/engine/commerce-engine.ssr.js +12 -32
- package/dist/esm/ssr-next/commerce/factories/build-factory.js +1 -1
- package/dist/esm/ssr-next/commerce/factories/static-state-factory.js +10 -3
- package/dist/esm/ssr-next/search/engine/search-engine.ssr.js +40 -34
- package/dist/esm/ssr-next.index.js +5 -11
- 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
- package/dist/definitions/ssr-next/common/navigator-context-utils.d.ts +0 -16
- package/dist/definitions/ssr-next/common/navigator-context-utils.spec.d.ts +0 -1
- package/dist/esm/ssr-next/common/navigator-context-utils.js +0 -27
|
@@ -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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
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.ea13b3b94e";
|
|
1310
1310
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1311
1311
|
|
|
1312
1312
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -18,34 +18,9 @@ import type { CommerceEngineDefinition } from '../types/engine.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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>;
|
|
21
|
+
* const engineDefinition = defineCommerceEngine(engineConfig);
|
|
22
|
+
* type SearchStaticState = InferStaticState<typeof engineDefinition>;
|
|
23
|
+
* type SearchHydratedState = InferHydratedState<typeof engineDefinition>;
|
|
49
24
|
* ```
|
|
50
25
|
*
|
|
51
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,31 +1,10 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
-
import type { NavigatorContext } 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
|
|
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
|
-
}
|
|
7
|
+
export type FetchStaticStateOptions = {};
|
|
29
8
|
/**
|
|
30
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.
|
|
31
10
|
*
|
|
@@ -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,11 +1,8 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
-
import type { NavigatorContext } 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;
|
|
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
|
*
|
|
@@ -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
|
|
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
|
|
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>):
|
|
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
|
+
};
|
|
@@ -36,17 +36,11 @@
|
|
|
36
36
|
* export type SearchStaticState = InferStaticState<typeof engineDefinition>;
|
|
37
37
|
* export type SearchHydratedState = InferHydratedState<typeof engineDefinition>;
|
|
38
38
|
*
|
|
39
|
-
* export const {
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* forwardedFor: req.ip,
|
|
45
|
-
* referrer: req.headers.referer || null,
|
|
46
|
-
* userAgent: req.headers['user-agent'] || null,
|
|
47
|
-
* clientId: req.sessionID || 'anonymous',
|
|
48
|
-
* },
|
|
49
|
-
* });
|
|
39
|
+
* export const {
|
|
40
|
+
* fetchStaticState,
|
|
41
|
+
* hydrateStaticState,
|
|
42
|
+
* setNavigatorContextProvider,
|
|
43
|
+
* } = engineDefinition;
|
|
50
44
|
|
|
51
45
|
* ```
|
|
52
46
|
* @module SSR Search
|
|
@@ -18,49 +18,29 @@ import { SolutionType } from '../types/controller-constants.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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>;
|
|
21
|
+
* const engineDefinition = defineCommerceEngine(engineConfig);
|
|
22
|
+
* type SearchStaticState = InferStaticState<typeof engineDefinition>;
|
|
23
|
+
* type SearchHydratedState = InferHydratedState<typeof engineDefinition>;
|
|
49
24
|
* ```
|
|
50
25
|
*
|
|
51
26
|
* @group Engine
|
|
52
27
|
*/
|
|
53
28
|
export function defineCommerceEngine(options) {
|
|
54
29
|
const { controllers: controllerDefinitions, ...engineOptions } = options;
|
|
30
|
+
const getOptions = () => engineOptions;
|
|
31
|
+
const setNavigatorContextProvider = (navigatorContextProvider) => {
|
|
32
|
+
engineOptions.navigatorContextProvider = navigatorContextProvider;
|
|
33
|
+
};
|
|
55
34
|
const getAccessToken = () => engineOptions.configuration.accessToken;
|
|
56
35
|
const setAccessToken = (accessToken) => {
|
|
57
36
|
engineOptions.configuration.accessToken = accessToken;
|
|
58
37
|
};
|
|
59
|
-
const fetchStaticState = fetchStaticStateFactory(controllerDefinitions,
|
|
60
|
-
const hydrateStaticState = hydratedStaticStateFactory(controllerDefinitions,
|
|
61
|
-
const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(controllerDefinitions,
|
|
62
|
-
const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(controllerDefinitions,
|
|
38
|
+
const fetchStaticState = fetchStaticStateFactory(controllerDefinitions, getOptions());
|
|
39
|
+
const hydrateStaticState = hydratedStaticStateFactory(controllerDefinitions, getOptions());
|
|
40
|
+
const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(controllerDefinitions, getOptions());
|
|
41
|
+
const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(controllerDefinitions, getOptions());
|
|
63
42
|
const commonMethods = {
|
|
43
|
+
setNavigatorContextProvider,
|
|
64
44
|
getAccessToken,
|
|
65
45
|
setAccessToken,
|
|
66
46
|
};
|
|
@@ -66,7 +66,7 @@ function fetchActiveRecommendationControllers(controllerProps, solutionType) {
|
|
|
66
66
|
export const buildFactory = (controllerDefinitions, options) => (solutionType) => async (...[buildOptions]) => {
|
|
67
67
|
const logger = buildLogger(options.loggerOptions);
|
|
68
68
|
if (!options.navigatorContextProvider) {
|
|
69
|
-
logger.warn('[WARNING] Missing navigator context in server-side code.
|
|
69
|
+
logger.warn('[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()');
|
|
70
70
|
}
|
|
71
71
|
const controllerProps = buildOptions && 'controllers' in buildOptions
|
|
72
72
|
? buildOptions.controllers
|
|
@@ -1,14 +1,21 @@
|
|
|
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 {
|
|
3
|
+
import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.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
|
|
10
|
-
|
|
9
|
+
const solutionTypeBuild = await buildFactory(controllerDefinitions, {
|
|
10
|
+
...options,
|
|
11
|
+
})(solutionType);
|
|
11
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
|
+
});
|
|
12
19
|
switch (solutionType) {
|
|
13
20
|
case SolutionType.listing:
|
|
14
21
|
buildProductListing(engine).executeFirstRequest();
|
|
@@ -1,7 +1,8 @@
|
|
|
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';
|
|
4
|
+
import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
|
|
3
5
|
import { buildControllerDefinitions, createStaticState, } from '../../common/controller-utils.js';
|
|
4
|
-
import { processNavigatorContext } from '../../common/navigator-context-utils.js';
|
|
5
6
|
function isSearchCompletedAction(action) {
|
|
6
7
|
return /^search\/executeSearch\/(fulfilled|rejected)$/.test(action.type);
|
|
7
8
|
}
|
|
@@ -22,52 +23,50 @@ function buildSSRSearchEngine(options) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
|
-
* Initializes a Search engine definition in SSR with
|
|
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
|
|
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
|
-
const
|
|
50
|
-
|
|
51
|
-
const controllers = buildControllerDefinitions({
|
|
52
|
-
definitionsMap: (controllerDefinitions ?? {}),
|
|
53
|
-
engine,
|
|
54
|
-
propsMap: {},
|
|
55
|
-
});
|
|
56
|
-
const [staticState] = params;
|
|
57
|
-
engine.dispatch(staticState.searchAction);
|
|
58
|
-
await engine.waitForSearchCompletedAction();
|
|
59
|
-
return { engine, controllers };
|
|
36
|
+
const getOptions = () => {
|
|
37
|
+
return engineOptions;
|
|
60
38
|
};
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
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());
|
|
64
50
|
const controllers = buildControllerDefinitions({
|
|
65
51
|
definitionsMap: (controllerDefinitions ?? {}),
|
|
66
52
|
engine,
|
|
67
|
-
propsMap: (
|
|
68
|
-
?
|
|
53
|
+
propsMap: (buildOptions && 'controllers' in buildOptions
|
|
54
|
+
? buildOptions.controllers
|
|
69
55
|
: {}),
|
|
70
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
|
+
});
|
|
71
70
|
engine.executeFirstSearch();
|
|
72
71
|
const staticState = createStaticState({
|
|
73
72
|
searchAction: await engine.waitForSearchCompletedAction(),
|
|
@@ -75,8 +74,15 @@ export function defineSearchEngine(options) {
|
|
|
75
74
|
});
|
|
76
75
|
return staticState;
|
|
77
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
|
+
};
|
|
78
83
|
return {
|
|
79
84
|
fetchStaticState,
|
|
80
85
|
hydrateStaticState,
|
|
86
|
+
setNavigatorContextProvider,
|
|
81
87
|
};
|
|
82
88
|
}
|
|
@@ -36,17 +36,11 @@
|
|
|
36
36
|
* export type SearchStaticState = InferStaticState<typeof engineDefinition>;
|
|
37
37
|
* export type SearchHydratedState = InferHydratedState<typeof engineDefinition>;
|
|
38
38
|
*
|
|
39
|
-
* export const {
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* forwardedFor: req.ip,
|
|
45
|
-
* referrer: req.headers.referer || null,
|
|
46
|
-
* userAgent: req.headers['user-agent'] || null,
|
|
47
|
-
* clientId: req.sessionID || 'anonymous',
|
|
48
|
-
* },
|
|
49
|
-
* });
|
|
39
|
+
* export const {
|
|
40
|
+
* fetchStaticState,
|
|
41
|
+
* hydrateStaticState,
|
|
42
|
+
* setNavigatorContextProvider,
|
|
43
|
+
* } = engineDefinition;
|
|
50
44
|
|
|
51
45
|
* ```
|
|
52
46
|
* @module SSR Search
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "3.28.4-pre.
|
|
1
|
+
export const VERSION = "3.28.4-pre.ea13b3b94e" || 'Test version';
|
|
2
2
|
export const COVEO_FRAMEWORK = ['@coveo/atomic', '@coveo/quantic'];
|