@coveo/headless 3.28.4-pre.f565c74b85 → 3.28.4-pre.fe2dbcea63
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-commerce-next.index.d.ts +1 -1
- package/dist/definitions/ssr-next/commerce/controller-utils.d.ts +6 -7
- package/dist/definitions/ssr-next/commerce/controllers/context/headless-context.ssr.d.ts +3 -1
- package/dist/definitions/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.d.ts +2 -1
- package/dist/definitions/ssr-next/commerce/engine/commerce-engine.ssr.d.ts +28 -3
- package/dist/definitions/ssr-next/commerce/types/controller-inference.d.ts +3 -2
- 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/builders/controller-builder.d.ts +17 -0
- package/dist/definitions/ssr-next/common/builders/static-controller-builder.d.ts +24 -0
- package/dist/definitions/ssr-next/common/controller-utils.d.ts +6 -6
- package/dist/definitions/ssr-next/common/navigator-context-utils.d.ts +16 -0
- package/dist/definitions/ssr-next/common/navigator-context-utils.spec.d.ts +1 -0
- package/dist/definitions/ssr-next/common/types/controllers.d.ts +6 -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/common/types/inference.d.ts +3 -2
- package/dist/definitions/ssr-next/search/engine/search-engine.ssr.d.ts +18 -20
- package/dist/definitions/test/mock-controller.d.ts +9 -0
- package/dist/definitions/test/mock-ssr-controller-definitions.d.ts +38 -0
- package/dist/esm/ssr-next/commerce/controller-utils.js +6 -18
- package/dist/esm/ssr-next/commerce/controllers/cart/headless-cart.ssr.js +3 -5
- package/dist/esm/ssr-next/commerce/controllers/context/headless-context.ssr.js +1 -1
- package/dist/esm/ssr-next/commerce/engine/commerce-engine.ssr.js +32 -12
- package/dist/esm/ssr-next/commerce/factories/static-state-factory.js +3 -10
- package/dist/esm/ssr-next/common/builders/controller-builder.js +38 -0
- package/dist/esm/ssr-next/common/builders/static-controller-builder.js +46 -0
- package/dist/esm/ssr-next/common/controller-utils.js +7 -13
- package/dist/esm/ssr-next/common/navigator-context-utils.js +27 -0
- package/dist/esm/ssr-next/search/engine/search-engine.ssr.js +34 -40
- package/dist/esm/test/mock-controller.js +13 -0
- package/dist/esm/test/mock-ssr-controller-definitions.js +43 -0
- 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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
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.fe2dbcea63";
|
|
1310
1310
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1311
1311
|
|
|
1312
1312
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -93,7 +93,7 @@ export type { InstantProducts, InstantProductsDefinition, InstantProductsOptions
|
|
|
93
93
|
export { defineInstantProducts } from './ssr-next/commerce/controllers/instant-products/headless-instant-products.ssr.js';
|
|
94
94
|
export type { CorePaginationOptions, Pagination, PaginationOptions, PaginationProps, PaginationState, } from './ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.js';
|
|
95
95
|
export { definePagination } from './ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.js';
|
|
96
|
-
export type { CommerceSearchParameters, ParameterManager, ParameterManagerProps, ParameterManagerState, Parameters, ProductListingParameters, SSRParameterManagerProps, } from './ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
96
|
+
export type { CommerceSearchParameters, ParameterManager, ParameterManagerDefinition, ParameterManagerProps, ParameterManagerState, Parameters, ProductListingParameters, SSRParameterManagerProps, } from './ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
97
97
|
export { defineParameterManager } from './ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
98
98
|
export type { ProductList, ProductListing, ProductListState, Search, } from './ssr-next/commerce/controllers/product-list/headless-product-list.ssr.js';
|
|
99
99
|
export { defineProductList } from './ssr-next/commerce/controllers/product-list/headless-product-list.ssr.js';
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { Controller } from '../../controllers/controller/headless-controller.js';
|
|
3
|
-
import type { ControllersMap } from '../common/types/controllers.js';
|
|
4
3
|
import type { SSRCommerceEngine } from './factories/build-factory.js';
|
|
5
4
|
import type { SolutionType } from './types/controller-constants.js';
|
|
6
|
-
import type { ControllerDefinitionOption, ControllerDefinitionsMap
|
|
7
|
-
import type { InferControllerPropsMapFromDefinitions, InferControllersMapFromDefinition } from './types/controller-inference.js';
|
|
5
|
+
import type { ControllerDefinitionOption, ControllerDefinitionsMap } from './types/controller-definitions.js';
|
|
6
|
+
import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitionsWithSolutionType, InferControllersMapFromDefinition } from './types/controller-inference.js';
|
|
8
7
|
import type { EngineStaticState } from './types/engine.js';
|
|
9
|
-
export declare function createStaticState<TSearchAction extends UnknownAction
|
|
8
|
+
export declare function createStaticState<TSearchAction extends UnknownAction, TControllerDefinitions extends ControllerDefinitionsMap<Controller>>({ searchActions, controllers, }: {
|
|
10
9
|
searchActions: TSearchAction[];
|
|
11
|
-
controllers:
|
|
12
|
-
}): EngineStaticState<TSearchAction,
|
|
10
|
+
controllers: InferControllersMapFromDefinition<TControllerDefinitions, SolutionType>;
|
|
11
|
+
}): EngineStaticState<TSearchAction, InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllerDefinitions, SolutionType>>;
|
|
13
12
|
export declare function buildControllerDefinitions<TControllerDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType>({ definitionsMap, engine, solutionType, propsMap, }: {
|
|
14
13
|
definitionsMap: TControllerDefinitionsMap;
|
|
15
14
|
engine: SSRCommerceEngine;
|
|
16
15
|
solutionType: TSolutionType;
|
|
17
|
-
propsMap
|
|
16
|
+
propsMap?: InferControllerPropsMapFromDefinitions<TControllerDefinitionsMap>;
|
|
18
17
|
}): InferControllersMapFromDefinition<TControllerDefinitionsMap, TSolutionType>;
|
|
19
18
|
export declare function ensureAtLeastOneSolutionType(options?: ControllerDefinitionOption): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type Context, type ContextOptions, type ContextProps, type ContextState, type UserLocation, type View } from '../../../../controllers/commerce/context/headless-context.js';
|
|
2
2
|
import type { UniversalControllerDefinitionWithProps } from '../../types/controller-definitions.js';
|
|
3
3
|
export type { Context, ContextProps, ContextState, View, UserLocation, ContextOptions, };
|
|
4
|
-
export interface ContextDefinition extends UniversalControllerDefinitionWithProps<Context,
|
|
4
|
+
export interface ContextDefinition extends UniversalControllerDefinitionWithProps<Context, {
|
|
5
|
+
initialState: ContextOptions;
|
|
6
|
+
}> {
|
|
5
7
|
}
|
|
6
8
|
/**
|
|
7
9
|
* Defines a `Context` controller instance.
|
|
@@ -4,13 +4,14 @@ import type { ProductListingParameters } from '../../../../features/commerce/pro
|
|
|
4
4
|
import type { CommerceSearchParameters } from '../../../../features/commerce/search-parameters/search-parameters-actions.js';
|
|
5
5
|
import type { ControllerDefinitionOption, SubControllerDefinitionWithProps } from '../../types/controller-definitions.js';
|
|
6
6
|
export type { ParameterManager, ParameterManagerProps, ParameterManagerState, Parameters, ProductListingParameters, CommerceSearchParameters, };
|
|
7
|
+
export type ParameterManagerDefinition<TOptions extends ControllerDefinitionOption | undefined> = SubControllerDefinitionWithProps<ParameterManager<MappedParameterTypes<TOptions>>, TOptions, SSRParameterManagerProps<MappedParameterTypes<TOptions>>>;
|
|
7
8
|
/**
|
|
8
9
|
* Defines a `ParameterManager` controller instance.
|
|
9
10
|
* @group Definers
|
|
10
11
|
*
|
|
11
12
|
* @returns The `ParameterManager` controller definition.
|
|
12
13
|
*/
|
|
13
|
-
export declare function defineParameterManager<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions):
|
|
14
|
+
export declare function defineParameterManager<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions): ParameterManagerDefinition<TOptions>;
|
|
14
15
|
export interface SSRParameterManagerProps<T extends Parameters> extends Omit<ParameterManagerProps<T>, 'excludeDefaultParameters'> {
|
|
15
16
|
}
|
|
16
17
|
type MappedParameterTypes<TOptions extends ControllerDefinitionOption | undefined> = TOptions extends {
|
|
@@ -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
|
|
@@ -8,7 +8,7 @@ export type InferStaticState<T extends {
|
|
|
8
8
|
export type InferHydratedState<T extends {
|
|
9
9
|
hydrateStaticState(...args: unknown[]): Promise<unknown>;
|
|
10
10
|
}> = Awaited<ReturnType<T['hydrateStaticState']>>;
|
|
11
|
-
|
|
11
|
+
type InferControllerPropsFromDefinition<TController extends ControllerDefinition<Controller>> = TController extends ControllerDefinitionWithProps<Controller, infer Props> ? HasKey<TController, typeof recommendationInternalOptionKey> extends never ? Props : Props & RecommendationControllerSettings : TController extends ControllerDefinitionWithoutProps<Controller> ? HasKey<TController, typeof recommendationInternalOptionKey> extends never ? {} : RecommendationControllerSettings : unknown;
|
|
12
12
|
export type InferControllerPropsMapFromDefinitions<TControllers extends ControllerDefinitionsMap<Controller>> = {
|
|
13
13
|
[K in keyof TControllers as HasKeys<InferControllerPropsFromDefinition<TControllers[K]>> extends false ? never : K]: InferControllerPropsFromDefinition<TControllers[K]>;
|
|
14
14
|
};
|
|
@@ -17,5 +17,6 @@ export type InferControllersMapFromDefinition<TControllers extends ControllerDef
|
|
|
17
17
|
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerFromDefinition<TControllers[K]>;
|
|
18
18
|
};
|
|
19
19
|
export type InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
20
|
-
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]
|
|
20
|
+
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]>> & InferControllerPropsFromDefinition<TControllers[K]>;
|
|
21
21
|
};
|
|
22
|
+
export {};
|
|
@@ -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,17 @@
|
|
|
1
|
+
import type { CoreEngine, CoreEngineNext } from '../../../app/engine.js';
|
|
2
|
+
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { BaseControllerDefinitionWithoutProps, BaseControllerDefinitionWithProps } from '../types/controllers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Builder class for creating controllers from definitions
|
|
6
|
+
*/
|
|
7
|
+
export declare class ControllerBuilder<TDefinition extends Partial<BaseControllerDefinitionWithoutProps<TEngine, TController>> & Partial<BaseControllerDefinitionWithProps<TEngine, TController, TProps>>, TEngine extends CoreEngine | CoreEngineNext, TProps, TController extends Controller = Controller> {
|
|
8
|
+
private _definition;
|
|
9
|
+
private _engine;
|
|
10
|
+
private _props?;
|
|
11
|
+
private _additionalArgs;
|
|
12
|
+
constructor(definition: TDefinition, engine: TEngine, props?: TProps);
|
|
13
|
+
withAdditionalArgs(additionalArgs?: unknown[]): this;
|
|
14
|
+
build(): TController;
|
|
15
|
+
private buildWithoutProps;
|
|
16
|
+
private buildWithProps;
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
2
|
+
import type { ControllerWithKind } from '../../commerce/types/controller-definitions.js';
|
|
3
|
+
import type { Kind } from '../../commerce/types/kind.js';
|
|
4
|
+
export type StaticControllerState = {
|
|
5
|
+
initialState?: Controller['state'];
|
|
6
|
+
_kind?: Kind;
|
|
7
|
+
} & Pick<ControllerWithKind, 'state'>;
|
|
8
|
+
/**
|
|
9
|
+
* Builder class for creating static controller
|
|
10
|
+
*/
|
|
11
|
+
declare class StaticControllerBuilder {
|
|
12
|
+
private _state?;
|
|
13
|
+
private _kind?;
|
|
14
|
+
private _initialState?;
|
|
15
|
+
withState(state: StaticControllerState['state']): this;
|
|
16
|
+
withKind(kind: Kind): this;
|
|
17
|
+
withInitialState(initialState: StaticControllerState['initialState']): this;
|
|
18
|
+
/**
|
|
19
|
+
* Builds and returns the static controller state object
|
|
20
|
+
*/
|
|
21
|
+
build(): StaticControllerState;
|
|
22
|
+
}
|
|
23
|
+
export declare function createStaticControllerBuilder<TController extends Controller>(controller: TController): StaticControllerBuilder;
|
|
24
|
+
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { CoreEngine, CoreEngineNext } from '../../app/engine.js';
|
|
3
3
|
import type { Controller } from '../../controllers/controller/headless-controller.js';
|
|
4
|
-
import type { ControllerDefinitionsMap
|
|
4
|
+
import type { ControllerDefinitionsMap } from './types/controllers.js';
|
|
5
5
|
import type { EngineStaticState } from './types/engine.js';
|
|
6
|
-
import type { InferControllerPropsMapFromDefinitions,
|
|
6
|
+
import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitions, InferControllersMapFromDefinition } from './types/inference.js';
|
|
7
7
|
export declare function buildControllerDefinitions<TControllerDefinitionsMap extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>, TEngine extends CoreEngine | CoreEngineNext>({ definitionsMap, engine, propsMap, }: {
|
|
8
8
|
definitionsMap: TControllerDefinitionsMap;
|
|
9
9
|
engine: TEngine;
|
|
10
|
-
propsMap
|
|
10
|
+
propsMap?: InferControllerPropsMapFromDefinitions<TControllerDefinitionsMap>;
|
|
11
11
|
}): InferControllersMapFromDefinition<TControllerDefinitionsMap>;
|
|
12
|
-
export declare function createStaticState<TSearchAction extends UnknownAction
|
|
12
|
+
export declare function createStaticState<TSearchAction extends UnknownAction, TControllerDefinitions extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>>({ searchAction, controllers, }: {
|
|
13
13
|
searchAction: TSearchAction;
|
|
14
|
-
controllers:
|
|
15
|
-
}): EngineStaticState<TSearchAction,
|
|
14
|
+
controllers: InferControllersMapFromDefinition<TControllerDefinitions>;
|
|
15
|
+
}): EngineStaticState<TSearchAction, InferControllerStaticStateMapFromDefinitions<TControllerDefinitions>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LoggerOptions } from '../../app/logger.js';
|
|
2
|
+
import type { NavigatorContext } from '../../app/navigator-context-provider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Processes fetchStaticState parameters and returns enhanced engine options with navigator context.
|
|
5
|
+
* This is the single function that handles all navigator context logic for both commerce and search engines.
|
|
6
|
+
*/
|
|
7
|
+
export declare function processNavigatorContext<TOptions extends {
|
|
8
|
+
configuration: object;
|
|
9
|
+
loggerOptions?: LoggerOptions;
|
|
10
|
+
}>(params: unknown[], baseOptions: TOptions): {
|
|
11
|
+
engineOptions: TOptions;
|
|
12
|
+
callOptions?: {
|
|
13
|
+
navigatorContext?: NavigatorContext;
|
|
14
|
+
controllers?: unknown;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,6 +9,12 @@ export interface ControllerStaticState<TState> {
|
|
|
9
9
|
export interface ControllerStaticStateMap {
|
|
10
10
|
[customName: string]: ControllerStaticState<unknown>;
|
|
11
11
|
}
|
|
12
|
+
export interface BaseControllerDefinitionWithoutProps<TEngine, TController extends Controller> {
|
|
13
|
+
build(engine: TEngine, ...args: unknown[]): TController;
|
|
14
|
+
}
|
|
15
|
+
export interface BaseControllerDefinitionWithProps<TEngine, TController extends Controller, TProps> {
|
|
16
|
+
buildWithProps(engine: TEngine, props?: TProps, ...args: unknown[]): TController;
|
|
17
|
+
}
|
|
12
18
|
export interface ControllerDefinitionWithoutProps<TEngine extends CoreEngine | CoreEngineNext, TController extends Controller> {
|
|
13
19
|
/**
|
|
14
20
|
* Creates an instance of the given controller.
|
|
@@ -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
|
*
|
|
@@ -2,7 +2,7 @@ import type { CoreEngine, CoreEngineNext } from '../../../app/engine.js';
|
|
|
2
2
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
3
|
import type { ControllerDefinition, ControllerDefinitionsMap, ControllerDefinitionWithoutProps, ControllerDefinitionWithProps, ControllerStaticState, ControllersMap } from './controllers.js';
|
|
4
4
|
import type { HasKeys } from './utilities.js';
|
|
5
|
-
|
|
5
|
+
type InferControllerPropsFromDefinition<TController extends ControllerDefinition<CoreEngine | CoreEngineNext, Controller>> = TController extends ControllerDefinitionWithProps<CoreEngine | CoreEngineNext, Controller, infer Props> ? Props : TController extends ControllerDefinitionWithoutProps<CoreEngine | CoreEngineNext, Controller> ? {} : unknown;
|
|
6
6
|
export type InferControllerPropsMapFromDefinitions<TControllers extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>> = {
|
|
7
7
|
[K in keyof TControllers as HasKeys<InferControllerPropsFromDefinition<TControllers[K]>> extends false ? never : K]: InferControllerPropsFromDefinition<TControllers[K]>;
|
|
8
8
|
};
|
|
@@ -12,8 +12,9 @@ export type InferControllersMapFromDefinition<TControllers extends ControllerDef
|
|
|
12
12
|
};
|
|
13
13
|
export type InferControllerStaticStateFromController<TController extends Controller> = ControllerStaticState<TController['state']>;
|
|
14
14
|
export type InferControllerStaticStateMapFromDefinitions<TControllers extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>> = {
|
|
15
|
-
[K in keyof TControllers]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]
|
|
15
|
+
[K in keyof TControllers]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]>> & InferControllerPropsFromDefinition<TControllers[K]>;
|
|
16
16
|
};
|
|
17
17
|
export type InferControllerStaticStateMapFromControllers<TControllers extends ControllersMap> = {
|
|
18
18
|
[K in keyof TControllers]: InferControllerStaticStateFromController<TControllers[K]>;
|
|
19
19
|
};
|
|
20
|
+
export {};
|
|
@@ -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>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CoreEngine, CoreEngineNext } from '../app/engine.js';
|
|
2
|
+
import type { Controller } from '../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { SSRCommerceEngine } from '../ssr/commerce/factories/build-factory.js';
|
|
4
|
+
interface MockController {
|
|
5
|
+
initialState?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildMockController(): Controller;
|
|
8
|
+
export declare function buildMockControllerWithInitialState(_engine: CoreEngine | CoreEngineNext | SSRCommerceEngine, props: MockController): Controller;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SearchEngine } from '../app/search-engine/search-engine.js';
|
|
2
|
+
import type { Controller } from '../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { Kind } from '../ssr/commerce/types/kind.js';
|
|
4
|
+
import type { ControllerDefinitionWithoutProps, ControllerDefinitionWithProps } from '../ssr-next/common/types/controllers.js';
|
|
5
|
+
interface MockController {
|
|
6
|
+
initialState?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
interface MockControllerDefinitionWithoutProps extends ControllerDefinitionWithoutProps<SearchEngine, Controller> {
|
|
9
|
+
}
|
|
10
|
+
interface MockControllerDefinitionWithProps extends ControllerDefinitionWithProps<SearchEngine, Controller, MockController> {
|
|
11
|
+
}
|
|
12
|
+
type SolutionTypeAvailabilities = {
|
|
13
|
+
listing?: boolean;
|
|
14
|
+
search?: boolean;
|
|
15
|
+
standalone?: boolean;
|
|
16
|
+
recommendation?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function defineMockController(): MockControllerDefinitionWithoutProps;
|
|
19
|
+
export declare function defineMockControllerWithProps(): MockControllerDefinitionWithProps;
|
|
20
|
+
export declare function defineMockCommerceController(options?: SolutionTypeAvailabilities): {
|
|
21
|
+
build: import("vitest").Mock<(_engine: any) => Controller>;
|
|
22
|
+
listing: boolean;
|
|
23
|
+
search: boolean;
|
|
24
|
+
standalone: boolean;
|
|
25
|
+
recommendation: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare function defineMockCommerceControllerWithProps(options?: SolutionTypeAvailabilities): {
|
|
28
|
+
buildWithProps: import("vitest").Mock<(engine: any, props: any) => {
|
|
29
|
+
state: {};
|
|
30
|
+
subscribe(listener: () => void): import("redux").Unsubscribe;
|
|
31
|
+
_kind: Kind;
|
|
32
|
+
}>;
|
|
33
|
+
listing: boolean;
|
|
34
|
+
search: boolean;
|
|
35
|
+
standalone: boolean;
|
|
36
|
+
recommendation: boolean;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { clone, filterObject, mapObject } from '../../utils/utils.js';
|
|
2
|
+
import { ControllerBuilder } from '../common/builders/controller-builder.js';
|
|
3
|
+
import { createStaticControllerBuilder } from '../common/builders/static-controller-builder.js';
|
|
2
4
|
import { InvalidControllerDefinition } from '../common/errors.js';
|
|
3
|
-
function hasKindProperty(controller) {
|
|
4
|
-
return '_kind' in controller;
|
|
5
|
-
}
|
|
6
5
|
export function createStaticState({ searchActions, controllers, }) {
|
|
7
6
|
return {
|
|
8
|
-
controllers: mapObject(controllers, (controller) => (
|
|
9
|
-
state: clone(controller.state),
|
|
10
|
-
...(hasKindProperty(controller) && { _kind: controller._kind }),
|
|
11
|
-
})),
|
|
7
|
+
controllers: mapObject(controllers, (controller) => createStaticControllerBuilder(controller).build()),
|
|
12
8
|
searchActions: searchActions.map((action) => clone(action)),
|
|
13
9
|
};
|
|
14
10
|
}
|
|
15
|
-
function buildControllerFromDefinition({ definition, engine, solutionType, props, }) {
|
|
16
|
-
return ('build' in definition
|
|
17
|
-
? definition.build(engine, solutionType)
|
|
18
|
-
: definition.buildWithProps(engine, props, solutionType));
|
|
19
|
-
}
|
|
20
11
|
export function buildControllerDefinitions({ definitionsMap, engine, solutionType, propsMap, }) {
|
|
21
12
|
const controllerMap = mapObject(definitionsMap, (definition, key) => {
|
|
22
13
|
const unavailableInSolutionType = () => !(solutionType in definition) ||
|
|
@@ -26,12 +17,9 @@ export function buildControllerDefinitions({ definitionsMap, engine, solutionTyp
|
|
|
26
17
|
if (unavailableInSolutionType()) {
|
|
27
18
|
return null;
|
|
28
19
|
}
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
solutionType,
|
|
33
|
-
props,
|
|
34
|
-
});
|
|
20
|
+
return new ControllerBuilder(definition, engine, props)
|
|
21
|
+
.withAdditionalArgs([solutionType])
|
|
22
|
+
.build();
|
|
35
23
|
});
|
|
36
24
|
return filterObject(controllerMap, (value) => value !== null);
|
|
37
25
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { buildCart, } from '../../../../controllers/commerce/context/cart/headless-cart.js';
|
|
2
|
-
import { MissingControllerProps } from '../../../common/errors.js';
|
|
3
2
|
import { createControllerWithKind, Kind } from '../../types/kind.js';
|
|
4
3
|
/**
|
|
5
4
|
* Defines a `Cart` controller instance.
|
|
@@ -14,10 +13,9 @@ export function defineCart() {
|
|
|
14
13
|
standalone: true,
|
|
15
14
|
recommendation: true,
|
|
16
15
|
buildWithProps: (engine, props) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
const controller = buildCart(engine, { initialState: props.initialState });
|
|
16
|
+
const controller = buildCart(engine, {
|
|
17
|
+
initialState: props ? props.initialState : {},
|
|
18
|
+
});
|
|
21
19
|
return createControllerWithKind(controller, Kind.Cart);
|
|
22
20
|
},
|
|
23
21
|
};
|