@coveo/headless 3.29.0-pre.fd6894b6df → 3.29.0
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/case-assist/node.cjs.stats.json +1 -1
- package/dist/cjs/commerce/headless.cjs +1 -1
- package/dist/cjs/commerce/node.cjs.stats.json +1 -1
- package/dist/cjs/headless.cjs +1 -1
- package/dist/cjs/insight/headless.cjs +1 -1
- package/dist/cjs/insight/node.cjs.stats.json +1 -1
- package/dist/cjs/node.cjs.stats.json +1 -1
- package/dist/cjs/recommendation/headless.cjs +1 -1
- package/dist/cjs/recommendation/node.cjs.stats.json +1 -1
- package/dist/cjs/ssr/headless.cjs +1 -1
- package/dist/cjs/ssr/node.cjs.stats.json +1 -1
- package/dist/cjs/ssr-commerce/headless.cjs +1 -1
- package/dist/cjs/ssr-commerce/node.cjs.stats.json +1 -1
- package/dist/cjs/ssr-commerce-next/headless.cjs +1 -1
- package/dist/cjs/ssr-commerce-next/node.cjs.stats.json +1 -1
- package/dist/cjs/ssr-next/headless.cjs +1 -1
- package/dist/cjs/ssr-next/node.cjs.stats.json +1 -1
- package/dist/definitions/ssr/commerce/types/fetch-static-state.d.ts +4 -0
- package/dist/definitions/ssr/common/types/build.d.ts +3 -0
- package/dist/definitions/ssr/common/types/engine.d.ts +3 -0
- package/dist/definitions/ssr-commerce-next.index.d.ts +3 -3
- package/dist/definitions/ssr-next/commerce/factories/build-factory.d.ts +4 -3
- package/dist/definitions/ssr-next/commerce/factories/hydrated-state-factory.d.ts +1 -1
- package/dist/definitions/ssr-next/commerce/factories/recommendation-hydrated-state-factory.d.ts +1 -1
- package/dist/definitions/ssr-next/commerce/factories/recommendation-static-state-factory.d.ts +2 -1
- package/dist/definitions/ssr-next/commerce/factories/static-state-factory.d.ts +2 -1
- package/dist/definitions/ssr-next/commerce/types/build.d.ts +38 -7
- package/dist/definitions/ssr-next/commerce/types/controller-definitions.d.ts +40 -2
- package/dist/definitions/ssr-next/commerce/types/engine.d.ts +15 -8
- package/dist/definitions/ssr-next/commerce/types/fetch-static-state.d.ts +3 -3
- package/dist/definitions/ssr-next/commerce/types/utilities.d.ts +6 -0
- package/dist/definitions/ssr-next/commerce/utils/controller-wiring.d.ts +8 -0
- package/dist/definitions/ssr-next/commerce/utils/engine-wiring.d.ts +5 -0
- package/dist/definitions/ssr-next/commerce/validation/controller-validation.d.ts +1 -0
- package/dist/definitions/ssr-next/common/types/fetch-static-state.d.ts +1 -3
- package/dist/esm/ssr/commerce/types/kind.js +1 -0
- package/dist/esm/ssr-next/commerce/engine/commerce-engine.ssr.js +15 -4
- package/dist/esm/ssr-next/commerce/factories/build-factory.js +9 -9
- package/dist/esm/ssr-next/commerce/factories/hydrated-state-factory.js +4 -4
- package/dist/esm/ssr-next/commerce/factories/recommendation-hydrated-state-factory.js +3 -1
- package/dist/esm/ssr-next/commerce/factories/static-state-factory.js +1 -3
- package/dist/esm/ssr-next/commerce/types/utilities.js +1 -0
- package/dist/esm/ssr-next/commerce/utils/controller-wiring.js +4 -0
- package/dist/esm/ssr-next/commerce/utils/engine-wiring.js +4 -0
- package/dist/esm/ssr-next/commerce/validation/controller-validation.js +7 -0
- package/dist/esm/utils/version.js +1 -1
- package/dist/quantic/browser.cjs.stats.json +1 -1
- package/dist/quantic/case-assist/browser.cjs.stats.json +1 -1
- package/dist/quantic/case-assist/headless.js +1 -1
- package/dist/quantic/case-assist/headless.js.map +1 -1
- package/dist/quantic/commerce/browser.cjs.stats.json +1 -1
- package/dist/quantic/commerce/headless.js +1 -1
- package/dist/quantic/commerce/headless.js.map +1 -1
- package/dist/quantic/headless.js +1 -1
- package/dist/quantic/headless.js.map +1 -1
- package/dist/quantic/insight/browser.cjs.stats.json +1 -1
- package/dist/quantic/insight/headless.js +1 -1
- package/dist/quantic/insight/headless.js.map +1 -1
- package/dist/quantic/recommendation/browser.cjs.stats.json +1 -1
- package/dist/quantic/recommendation/headless.js +1 -1
- package/dist/quantic/recommendation/headless.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,10 @@ import type { SolutionType } from './controller-constants.js';
|
|
|
5
5
|
import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, OptionsTuple } from './controller-definitions.js';
|
|
6
6
|
import type { EngineStaticState } from './engine.js';
|
|
7
7
|
import type { FromBuildResult } from './from-build-result.js';
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated This interface will be remove on the next major version.
|
|
10
|
+
* Use BuildConfig interface instead
|
|
11
|
+
*/
|
|
8
12
|
export type FetchStaticStateOptions = {};
|
|
9
13
|
export type FetchStaticState<TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
10
14
|
/**
|
|
@@ -3,6 +3,9 @@ import type { ControllersMap, ControllersPropsMap } from './controllers.js';
|
|
|
3
3
|
import type { EngineDefinitionBuildResult, EngineDefinitionControllersPropsOption } from './engine.js';
|
|
4
4
|
import type { OptionsExtender, OptionsTuple } from './utilities.js';
|
|
5
5
|
interface BuildOptions<TEngineOptions> {
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated This option will be removed in the next major version.
|
|
8
|
+
*/
|
|
6
9
|
extend?: OptionsExtender<TEngineOptions>;
|
|
7
10
|
}
|
|
8
11
|
export type Build<TEngine extends CoreEngine | CoreEngineNext, TEngineOptions, TControllersMap extends ControllersMap, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<BuildOptions<TEngineOptions> & EngineDefinitionControllersPropsOption<TControllersProps>>) => Promise<EngineDefinitionBuildResult<TEngine, TControllersMap>>;
|
|
@@ -38,6 +38,9 @@ export interface EngineDefinition<TEngine extends CoreEngine | CoreEngineNext, T
|
|
|
38
38
|
*/
|
|
39
39
|
build: Build<TEngine, TEngineOptions, InferControllersMapFromDefinition<TControllers>, InferControllerPropsMapFromDefinitions<TControllers>>;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use SearchEngineDefinitionBuildResult or CommerceEngineDefinitionBuildResult instead
|
|
43
|
+
*/
|
|
41
44
|
export interface EngineDefinitionBuildResult<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap> {
|
|
42
45
|
engine: TEngine;
|
|
43
46
|
controllers: TControllers;
|
|
@@ -68,7 +68,6 @@
|
|
|
68
68
|
*/
|
|
69
69
|
export type { Relay } from '@coveo/relay';
|
|
70
70
|
export type { Middleware, Unsubscribe } from '@reduxjs/toolkit';
|
|
71
|
-
export type { CommerceEngineOptions } from './app/commerce-engine/commerce-engine.js';
|
|
72
71
|
export type { CommerceEngineConfiguration } from './app/commerce-engine/commerce-engine-configuration.js';
|
|
73
72
|
export { getSampleCommerceEngineConfiguration } from './app/commerce-engine/commerce-engine-configuration.js';
|
|
74
73
|
export type { CoreEngineNext, ExternalEngineOptions } from './app/engine.js';
|
|
@@ -119,10 +118,11 @@ export type { RedirectionTrigger, RedirectionTriggerDefinition, RedirectionTrigg
|
|
|
119
118
|
export { defineRedirectionTrigger } from './ssr-next/commerce/controllers/triggers/headless-redirection-trigger.ssr.js';
|
|
120
119
|
export { defineCommerceEngine } from './ssr-next/commerce/engine/commerce-engine.ssr.js';
|
|
121
120
|
export type { CommerceEngineDefinitionOptions, SSRCommerceEngine as CommerceEngine, } from './ssr-next/commerce/factories/build-factory.js';
|
|
121
|
+
export type { BuildConfig, SSRCommerceEngineOptions, } from './ssr-next/commerce/types/build.js';
|
|
122
122
|
export { SolutionType } from './ssr-next/commerce/types/controller-constants.js';
|
|
123
|
-
export type { ControllerDefinition, ControllerDefinitionsMap, ControllerWithKind,
|
|
123
|
+
export type { ControllerDefinition, ControllerDefinitionsMap, ControllerWithKind, EngineDefinitionControllersPropsOption, HydratedState, InferControllerStaticStateFromController, InferControllerStaticStateMapFromControllers, OptionsTuple, } from './ssr-next/commerce/types/controller-definitions.js';
|
|
124
124
|
export type { InferControllerFromDefinition, InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitionsWithSolutionType, InferControllersMapFromDefinition, InferHydratedState, InferStaticState, } from './ssr-next/commerce/types/controller-inference.js';
|
|
125
|
-
export type { CommerceEngineDefinition, EngineStaticState, FetchStaticState,
|
|
125
|
+
export type { CommerceEngineDefinition, CommerceEngineDefinitionBuildResult, EngineStaticState, FetchStaticState, HydrateStaticState, HydrateStaticStateOptions, } from './ssr-next/commerce/types/engine.js';
|
|
126
126
|
export { Kind } from './ssr-next/commerce/types/kind.js';
|
|
127
127
|
export type { CommerceAppState, CommerceProductListingParametersState, CommerceSearchParametersState, } from './state/commerce-app-state.js';
|
|
128
128
|
export * from './features/commerce/configuration/configuration-actions-loader.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Action } from '@reduxjs/toolkit';
|
|
2
|
-
import { type CommerceEngine
|
|
2
|
+
import { type CommerceEngine } from '../../../app/commerce-engine/commerce-engine.js';
|
|
3
3
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
4
|
+
import type { SSRCommerceEngineOptions } from '../types/build.js';
|
|
4
5
|
import { SolutionType } from '../types/controller-constants.js';
|
|
5
6
|
import type { ControllerDefinitionsMap } from '../types/controller-definitions.js';
|
|
6
7
|
import type { BuildParameters, CommerceControllerDefinitionsMap, EngineDefinitionOptions } from '../types/engine.js';
|
|
@@ -15,8 +16,8 @@ export interface SSRCommerceEngine extends CommerceEngine {
|
|
|
15
16
|
*/
|
|
16
17
|
waitForRequestCompletedAction(): Promise<Action>[];
|
|
17
18
|
}
|
|
18
|
-
export type CommerceEngineDefinitionOptions<TControllers extends ControllerDefinitionsMap<Controller> = ControllerDefinitionsMap<Controller>> = EngineDefinitionOptions<
|
|
19
|
-
export declare const buildFactory: <TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions
|
|
19
|
+
export type CommerceEngineDefinitionOptions<TControllers extends ControllerDefinitionsMap<Controller> = ControllerDefinitionsMap<Controller>> = EngineDefinitionOptions<SSRCommerceEngineOptions, TControllers>;
|
|
20
|
+
export declare const buildFactory: <TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions, options: CommerceEngineDefinitionOptions<TControllerDefinitions>) => <T extends SolutionType>(solutionType: T) => (...[buildOptions]: BuildParameters<TControllerDefinitions>) => Promise<{
|
|
20
21
|
engine: SSRCommerceEngine;
|
|
21
22
|
controllers: import("../types/controller-inference.js").InferControllersMapFromDefinition<TControllerDefinitions, T>;
|
|
22
23
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { SolutionType } from '../types/controller-constants.js';
|
|
2
2
|
import type { CommerceControllerDefinitionsMap, HydrateStaticStateFunction } from '../types/engine.js';
|
|
3
3
|
import { type CommerceEngineDefinitionOptions } from './build-factory.js';
|
|
4
|
-
export declare function hydratedStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions
|
|
4
|
+
export declare function hydratedStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions, options: CommerceEngineDefinitionOptions<TControllerDefinitions>): (solutionType: SolutionType) => HydrateStaticStateFunction<TControllerDefinitions>;
|
package/dist/definitions/ssr-next/commerce/factories/recommendation-hydrated-state-factory.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { CommerceControllerDefinitionsMap, HydrateStaticStateFunction } from '../types/engine.js';
|
|
2
2
|
import { type CommerceEngineDefinitionOptions } from './build-factory.js';
|
|
3
|
-
export declare function hydratedRecommendationStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions
|
|
3
|
+
export declare function hydratedRecommendationStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions, options: CommerceEngineDefinitionOptions<TControllerDefinitions>): HydrateStaticStateFunction<TControllerDefinitions>;
|
package/dist/definitions/ssr-next/commerce/factories/recommendation-static-state-factory.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AugmentedControllerDefinition } from '../types/controller-definitions.js';
|
|
1
2
|
import type { CommerceControllerDefinitionsMap, FetchStaticStateFunction } from '../types/engine.js';
|
|
2
3
|
import { type CommerceEngineDefinitionOptions } from './build-factory.js';
|
|
3
|
-
export declare function fetchRecommendationStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions
|
|
4
|
+
export declare function fetchRecommendationStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: AugmentedControllerDefinition<TControllerDefinitions>, options: CommerceEngineDefinitionOptions<TControllerDefinitions>): FetchStaticStateFunction<TControllerDefinitions>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SolutionType } from '../types/controller-constants.js';
|
|
2
|
+
import type { AugmentedControllerDefinition } from '../types/controller-definitions.js';
|
|
2
3
|
import type { CommerceControllerDefinitionsMap, FetchStaticStateFunction } from '../types/engine.js';
|
|
3
4
|
import { type CommerceEngineDefinitionOptions } from './build-factory.js';
|
|
4
|
-
export declare function fetchStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: TControllerDefinitions
|
|
5
|
+
export declare function fetchStaticStateFactory<TControllerDefinitions extends CommerceControllerDefinitionsMap>(controllerDefinitions: AugmentedControllerDefinition<TControllerDefinitions>, options: CommerceEngineDefinitionOptions<TControllerDefinitions>): (solutionType: SolutionType) => FetchStaticStateFunction<TControllerDefinitions>;
|
|
@@ -1,14 +1,45 @@
|
|
|
1
|
+
import type { CurrencyCodeISO4217 } from '@coveo/relay-event-types';
|
|
2
|
+
import type { CommerceEngineOptions } from '../../../app/commerce-engine/commerce-engine.js';
|
|
1
3
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
2
4
|
import type { ControllersMap, ControllersPropsMap } from '../../common/types/controllers.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
+
import type { OptionsTuple } from '../../common/types/utilities.js';
|
|
6
|
+
import type { CartInitialState } from '../controllers/cart/headless-cart.ssr.js';
|
|
7
|
+
import type { UserLocation } from '../controllers/context/headless-context.ssr.js';
|
|
8
|
+
import type { ParameterManagerState, Parameters } from '../controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
5
9
|
import type { SolutionType } from './controller-constants.js';
|
|
6
|
-
import type { ControllerDefinitionsMap,
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption } from './controller-definitions.js';
|
|
11
|
+
import type { CommerceEngineDefinitionBuildResult } from './engine.js';
|
|
12
|
+
export interface SearchBuildConfig extends CommonBuildConfig {
|
|
13
|
+
searchParams: ParameterManagerState<Parameters & {
|
|
14
|
+
query: string;
|
|
15
|
+
}>['parameters'];
|
|
9
16
|
}
|
|
17
|
+
export interface RecommendationBuildConfig extends CommonBuildConfig {
|
|
18
|
+
recommendations?: [];
|
|
19
|
+
}
|
|
20
|
+
export interface ListingBuildConfig extends CommonBuildConfig {
|
|
21
|
+
}
|
|
22
|
+
export interface StandaloneBuildConfig extends CommonBuildConfig {
|
|
23
|
+
}
|
|
24
|
+
export interface CommonBuildConfig {
|
|
25
|
+
context: {
|
|
26
|
+
url: string;
|
|
27
|
+
language: string;
|
|
28
|
+
country: string;
|
|
29
|
+
currency: CurrencyCodeISO4217;
|
|
30
|
+
location?: UserLocation;
|
|
31
|
+
};
|
|
32
|
+
searchParams?: ParameterManagerState<Parameters>['parameters'];
|
|
33
|
+
cart?: CartInitialState;
|
|
34
|
+
}
|
|
35
|
+
export type BuildConfig<TSolutionType extends SolutionType> = TSolutionType extends SolutionType.search ? SearchBuildConfig : TSolutionType extends SolutionType.listing ? ListingBuildConfig : TSolutionType extends SolutionType.recommendation ? RecommendationBuildConfig : TSolutionType extends SolutionType.standalone ? CommonBuildConfig : never;
|
|
36
|
+
/**
|
|
37
|
+
* Commerce engine options for SSR scenarios where context is defined when fetching static state.
|
|
38
|
+
*/
|
|
39
|
+
export type SSRCommerceEngineOptions = Omit<CommerceEngineOptions, 'configuration'> & {
|
|
40
|
+
configuration: Omit<CommerceEngineOptions['configuration'], 'context'>;
|
|
41
|
+
};
|
|
10
42
|
/**
|
|
11
43
|
* @internal
|
|
12
44
|
*/
|
|
13
|
-
export type Build<
|
|
14
|
-
export {};
|
|
45
|
+
export type Build<TControllersMap extends ControllersMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = (...params: OptionsTuple<BuildConfig<TSolutionType> & EngineDefinitionControllersPropsOption<TControllersDefinitionsMap, TControllersProps, TSolutionType>>) => Promise<CommerceEngineDefinitionBuildResult<TControllersMap>>;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
2
2
|
import type { InvalidControllerDefinition } from '../../common/errors.js';
|
|
3
3
|
import type { ControllersPropsMap } from '../../common/types/controllers.js';
|
|
4
|
-
import type { EngineDefinitionBuildResult } from '../../common/types/engine.js';
|
|
5
4
|
import type { HydratedState } from '../../common/types/hydrate-static-state.js';
|
|
6
5
|
import type { InferControllerStaticStateFromController, InferControllerStaticStateMapFromControllers } from '../../common/types/inference.js';
|
|
7
6
|
import type { HasKey, HasOptionalKeys, HasRequiredKeys, OptionsTuple } from '../../common/types/utilities.js';
|
|
7
|
+
import type { CartDefinition } from '../controllers/cart/headless-cart.ssr.js';
|
|
8
|
+
import type { ContextDefinition } from '../controllers/context/headless-context.ssr.js';
|
|
9
|
+
import type { ParameterManagerDefinition } from '../controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
8
10
|
import type { SSRCommerceEngine } from '../factories/build-factory.js';
|
|
9
11
|
import { type recommendationInternalOptionKey, SolutionType } from './controller-constants.js';
|
|
10
12
|
import type { ListingAndStandaloneController, ListingOnlyController, NonRecommendationController, RecommendationOnlyController, SearchAndListingController, SearchOnlyController, UniversalController } from './controller-scopes.js';
|
|
11
13
|
import type { Kind } from './kind.js';
|
|
12
|
-
|
|
14
|
+
import type { HasSolutionType } from './utilities.js';
|
|
15
|
+
export type { HydratedState, OptionsTuple, InferControllerStaticStateFromController, InferControllerStaticStateMapFromControllers, };
|
|
13
16
|
export type RecommendationControllerSettings = {
|
|
14
17
|
/**
|
|
15
18
|
* Toggle to enable or disable the recommendation controller.
|
|
@@ -53,6 +56,41 @@ export type ControllerDefinition<TController extends Controller> = SolutionTypeA
|
|
|
53
56
|
export interface ControllerDefinitionsMap<TController extends Controller> {
|
|
54
57
|
[customName: string]: ControllerDefinition<TController>;
|
|
55
58
|
}
|
|
59
|
+
type BakedInControllerDefinitions = {
|
|
60
|
+
parameterManager: ParameterManagerDefinition<{
|
|
61
|
+
listing: true;
|
|
62
|
+
search: true;
|
|
63
|
+
}>;
|
|
64
|
+
context: ContextDefinition;
|
|
65
|
+
cart: CartDefinition;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Map of baked-in controllers
|
|
69
|
+
*/
|
|
70
|
+
export type BakedInControllers = {
|
|
71
|
+
[K in keyof BakedInControllerDefinitions]: BakedInControllerDefinitions[K]['buildWithProps'];
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A dynamically filtered map of baked-in controller definitions based on solution type compatibility.
|
|
75
|
+
*
|
|
76
|
+
* This type automatically includes only the baked-in controllers that are available for the specified
|
|
77
|
+
* solution type by checking each controller's `SolutionTypeAvailability` configuration. Controllers
|
|
78
|
+
* that don't support the given solution type are excluded from the resulting type.
|
|
79
|
+
*
|
|
80
|
+
* @template TSolutionType - The target solution type to filter controllers for
|
|
81
|
+
*/
|
|
82
|
+
export type FilteredBakedInControllers<TSolutionType extends SolutionType> = {
|
|
83
|
+
[K in keyof BakedInControllers as HasSolutionType<BakedInControllerDefinitions[K], TSolutionType> extends true ? K : never]: BakedInControllers[K];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Map of controller definitions available to the commerce engine definition.
|
|
87
|
+
*
|
|
88
|
+
* This type combines user-defined controllers with the system's baked-in controllers
|
|
89
|
+
* (parameterManager, context, and cart).
|
|
90
|
+
*
|
|
91
|
+
* @template TControllerDefinitions - The controller definitions map
|
|
92
|
+
*/
|
|
93
|
+
export type AugmentedControllerDefinition<TControllerDefinitions extends ControllerDefinitionsMap<Controller>> = TControllerDefinitions & BakedInControllerDefinitions;
|
|
56
94
|
/**
|
|
57
95
|
* This type defines the required and optional controller props for the engine definition.
|
|
58
96
|
*/
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
-
import type { CommerceEngineOptions } from '../../../app/commerce-engine/commerce-engine.js';
|
|
3
2
|
import type { EngineConfiguration } from '../../../app/engine-configuration.js';
|
|
4
3
|
import type { NavigatorContextProvider } from '../../../app/navigator-context-provider.js';
|
|
5
4
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
6
|
-
import type { ControllerStaticStateMap } from '../../common/types/controllers.js';
|
|
5
|
+
import type { ControllerStaticStateMap, ControllersMap } from '../../common/types/controllers.js';
|
|
7
6
|
import type { SSRCommerceEngine } from '../factories/build-factory.js';
|
|
8
7
|
import type { Build } from './build.js';
|
|
9
8
|
import type { SolutionType } from './controller-constants.js';
|
|
10
|
-
import type { ControllerDefinitionsMap } from './controller-definitions.js';
|
|
9
|
+
import type { BakedInControllers, ControllerDefinitionsMap } from './controller-definitions.js';
|
|
11
10
|
import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitionsWithSolutionType, InferControllersMapFromDefinition } from './controller-inference.js';
|
|
12
|
-
import type { FetchStaticState
|
|
11
|
+
import type { FetchStaticState } from './fetch-static-state.js';
|
|
13
12
|
import type { HydrateStaticState, HydrateStaticStateOptions } from './hydrate-static-state.js';
|
|
14
|
-
export type { HydrateStaticState, HydrateStaticStateOptions, FetchStaticState
|
|
13
|
+
export type { HydrateStaticState, HydrateStaticStateOptions, FetchStaticState };
|
|
15
14
|
export interface EngineStaticState<TSearchAction extends UnknownAction, TControllers extends ControllerStaticStateMap> {
|
|
16
15
|
searchActions: TSearchAction[];
|
|
17
16
|
controllers: TControllers;
|
|
18
17
|
}
|
|
18
|
+
type ReservedControllerNames = 'context' | 'parameterManager' | 'cart';
|
|
19
|
+
type ValidateControllerNames<T extends ControllerDefinitionsMap<Controller>> = {
|
|
20
|
+
[K in keyof T]: K extends ReservedControllerNames ? `ERROR: Controller name "${K & string}" is reserved and cannot be used. Reserved names are: context, parameterManager, cart. Please choose a different controller name.` : T[K];
|
|
21
|
+
};
|
|
19
22
|
export type EngineDefinitionOptions<TOptions extends {
|
|
20
23
|
configuration: EngineConfiguration;
|
|
21
24
|
}, TControllers extends ControllerDefinitionsMap<Controller>> = TOptions & {
|
|
22
25
|
/**
|
|
23
26
|
* The controllers to initialize with the commerce engine.
|
|
24
27
|
*/
|
|
25
|
-
controllers?: TControllers
|
|
28
|
+
controllers?: ValidateControllerNames<TControllers>;
|
|
26
29
|
};
|
|
27
30
|
export interface CommerceEngineDefinition<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> {
|
|
28
31
|
/**
|
|
@@ -50,15 +53,19 @@ export interface CommerceEngineDefinition<TControllers extends ControllerDefinit
|
|
|
50
53
|
*/
|
|
51
54
|
setAccessToken: (accessToken: string) => void;
|
|
52
55
|
}
|
|
56
|
+
export interface CommerceEngineDefinitionBuildResult<TControllers extends ControllersMap> {
|
|
57
|
+
engine: SSRCommerceEngine;
|
|
58
|
+
controllers: TControllers & BakedInControllers;
|
|
59
|
+
}
|
|
53
60
|
export type CommerceControllerDefinitionsMap = ControllerDefinitionsMap<Controller>;
|
|
54
61
|
type Definition<TControllerDefinitions extends CommerceControllerDefinitionsMap> = CommerceEngineDefinition<TControllerDefinitions, SolutionType>;
|
|
55
62
|
export type FetchStaticStateFunction<TControllerDefinitions extends CommerceControllerDefinitionsMap> = Definition<TControllerDefinitions>['fetchStaticState'];
|
|
56
63
|
export type HydrateStaticStateFunction<TControllerDefinitions extends CommerceControllerDefinitionsMap> = Definition<TControllerDefinitions>['hydrateStaticState'];
|
|
57
|
-
export type BuildParameters<TControllerDefinitions extends CommerceControllerDefinitionsMap> = Parameters<Build<
|
|
64
|
+
export type BuildParameters<TControllerDefinitions extends CommerceControllerDefinitionsMap> = Parameters<Build<InferControllersMapFromDefinition<TControllerDefinitions, SolutionType>, InferControllerPropsMapFromDefinitions<TControllerDefinitions>, TControllerDefinitions, SolutionType>>;
|
|
58
65
|
export type FetchStaticStateParameters<TControllerDefinitions extends CommerceControllerDefinitionsMap> = Parameters<FetchStaticStateFunction<TControllerDefinitions>>;
|
|
59
66
|
export type HydrateStaticStateParameters<TControllerDefinitions extends CommerceControllerDefinitionsMap> = Parameters<HydrateStaticStateFunction<TControllerDefinitions>>;
|
|
60
67
|
type Controllers<TControllerDefinitions extends CommerceControllerDefinitionsMap> = InferControllersMapFromDefinition<TControllerDefinitions, SolutionType>;
|
|
61
68
|
export type BuildResult<TControllerDefinitions extends CommerceControllerDefinitionsMap> = {
|
|
62
69
|
engine: SSRCommerceEngine;
|
|
63
|
-
controllers: Controllers<TControllerDefinitions
|
|
70
|
+
controllers: Controllers<TControllerDefinitions> & BakedInControllers;
|
|
64
71
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
3
|
import type { ControllerStaticStateMap, ControllersPropsMap } from '../../common/types/controllers.js';
|
|
4
|
+
import type { BuildConfig } from './build.js';
|
|
4
5
|
import type { SolutionType } from './controller-constants.js';
|
|
5
|
-
import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, OptionsTuple } from './controller-definitions.js';
|
|
6
|
+
import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, FilteredBakedInControllers, OptionsTuple } from './controller-definitions.js';
|
|
6
7
|
import type { EngineStaticState } from './engine.js';
|
|
7
|
-
export type FetchStaticStateOptions = {};
|
|
8
8
|
/**
|
|
9
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.
|
|
10
10
|
*
|
|
11
11
|
* Useful for static generation and server-side rendering.
|
|
12
12
|
*/
|
|
13
|
-
export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = (...params: OptionsTuple<
|
|
13
|
+
export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = (...params: OptionsTuple<BuildConfig<TSolutionType> & EngineDefinitionControllersPropsOption<TControllersDefinitionsMap, TControllersProps, TSolutionType>>) => Promise<EngineStaticState<TSearchAction, TControllersStaticState & FilteredBakedInControllers<TSolutionType>>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SolutionType } from './controller-constants.js';
|
|
2
|
+
export type HasSolutionType<TDefinition, TSolutionType extends SolutionType> = TDefinition extends {
|
|
3
|
+
[K in TSolutionType]: true;
|
|
4
|
+
} ? true : TDefinition extends {
|
|
5
|
+
[K in TSolutionType]: false;
|
|
6
|
+
} ? false : false;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ControllersPropsMap } from '../../common/types/controllers.js';
|
|
2
|
+
import type { BuildConfig } from '../types/build.js';
|
|
3
|
+
import type { SolutionType } from '../types/controller-constants.js';
|
|
4
|
+
import type { InferControllerPropsMapFromDefinitions } from '../types/controller-inference.js';
|
|
5
|
+
import type { CommerceControllerDefinitionsMap } from '../types/engine.js';
|
|
6
|
+
export declare function wireControllerParams<TControllerDefinitions extends CommerceControllerDefinitionsMap>(_solutionType: SolutionType, _controllerDefinitions: TControllerDefinitions, _paramsObject: BuildConfig<SolutionType> & {
|
|
7
|
+
controllers?: ControllersPropsMap;
|
|
8
|
+
}): InferControllerPropsMapFromDefinitions<TControllerDefinitions>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CommerceEngineConfiguration } from '../../../app/commerce-engine/commerce-engine.js';
|
|
2
|
+
import type { CommerceEngineDefinitionOptions } from '../factories/build-factory.js';
|
|
3
|
+
import type { CommonBuildConfig } from '../types/build.js';
|
|
4
|
+
import type { CommerceControllerDefinitionsMap } from '../types/engine.js';
|
|
5
|
+
export declare function extendEngineConfiguration<TControllerDefinitions extends CommerceControllerDefinitionsMap>(_configuration: CommerceEngineDefinitionOptions<TControllerDefinitions>['configuration'], _commonBuildOptions: CommonBuildConfig): CommerceEngineConfiguration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateControllerNames: (controllers: Record<string, unknown>) => void;
|
|
@@ -2,11 +2,9 @@ import type { UnknownAction } from '@reduxjs/toolkit';
|
|
|
2
2
|
import type { ControllerStaticStateMap, ControllersPropsMap } from './controllers.js';
|
|
3
3
|
import type { EngineDefinitionControllersPropsOption, EngineStaticState } from './engine.js';
|
|
4
4
|
import type { OptionsTuple } from './utilities.js';
|
|
5
|
-
type FetchStaticStateOptions = {};
|
|
6
5
|
/**
|
|
7
6
|
* 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
7
|
*
|
|
9
8
|
* Useful for static generation and server-side rendering.
|
|
10
9
|
*/
|
|
11
|
-
export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<
|
|
12
|
-
export {};
|
|
10
|
+
export type FetchStaticState<TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<EngineDefinitionControllersPropsOption<TControllersProps>>) => Promise<EngineStaticState<TSearchAction, TControllersStaticState>>;
|
|
@@ -5,6 +5,7 @@ export var Kind;
|
|
|
5
5
|
Kind["ParameterManager"] = "PARAMETER_MANAGER";
|
|
6
6
|
Kind["Recommendations"] = "RECOMMENDATIONS";
|
|
7
7
|
})(Kind || (Kind = {}));
|
|
8
|
+
// TODO: KIT-4742: There is no point for this now that the wiring is happening in headless
|
|
8
9
|
export function createControllerWithKind(controller, kind) {
|
|
9
10
|
const copy = Object.defineProperties({}, Object.getOwnPropertyDescriptors(controller));
|
|
10
11
|
Object.defineProperty(copy, '_kind', {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utility functions to be used for Commerce Server Side Rendering.
|
|
3
3
|
*/
|
|
4
|
+
import { defineCart } from '../controllers/cart/headless-cart.ssr.js';
|
|
5
|
+
import { defineContext } from '../controllers/context/headless-context.ssr.js';
|
|
6
|
+
import { defineParameterManager } from '../controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
4
7
|
import { hydratedStaticStateFactory } from '../factories/hydrated-state-factory.js';
|
|
5
8
|
import { hydratedRecommendationStaticStateFactory } from '../factories/recommendation-hydrated-state-factory.js';
|
|
6
9
|
import { fetchRecommendationStaticStateFactory } from '../factories/recommendation-static-state-factory.js';
|
|
7
10
|
import { fetchStaticStateFactory } from '../factories/static-state-factory.js';
|
|
8
11
|
import { SolutionType } from '../types/controller-constants.js';
|
|
12
|
+
import { validateControllerNames } from '../validation/controller-validation.js';
|
|
9
13
|
/**
|
|
10
14
|
* Initializes a Commerce engine definition in SSR with given controllers definitions and commerce engine config.
|
|
11
15
|
* @param options - The commerce engine definition
|
|
@@ -35,10 +39,17 @@ export function defineCommerceEngine(options) {
|
|
|
35
39
|
const setAccessToken = (accessToken) => {
|
|
36
40
|
engineOptions.configuration.accessToken = accessToken;
|
|
37
41
|
};
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
controllerDefinitions && validateControllerNames(controllerDefinitions);
|
|
43
|
+
const augmentedControllerDefinition = {
|
|
44
|
+
...controllerDefinitions,
|
|
45
|
+
parameterManager: defineParameterManager(),
|
|
46
|
+
context: defineContext(),
|
|
47
|
+
cart: defineCart(),
|
|
48
|
+
};
|
|
49
|
+
const fetchStaticState = fetchStaticStateFactory(augmentedControllerDefinition, getOptions());
|
|
50
|
+
const hydrateStaticState = hydratedStaticStateFactory(augmentedControllerDefinition, getOptions());
|
|
51
|
+
const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(augmentedControllerDefinition, getOptions());
|
|
52
|
+
const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(augmentedControllerDefinition, getOptions());
|
|
42
53
|
const commonMethods = {
|
|
43
54
|
setNavigatorContextProvider,
|
|
44
55
|
getAccessToken,
|
|
@@ -4,6 +4,8 @@ import { stateKey } from '../../../app/state-key.js';
|
|
|
4
4
|
import { createWaitForActionMiddleware, createWaitForActionMiddlewareForRecommendation, } from '../../../utils/utils.js';
|
|
5
5
|
import { buildControllerDefinitions } from '../controller-utils.js';
|
|
6
6
|
import { SolutionType } from '../types/controller-constants.js';
|
|
7
|
+
import { wireControllerParams } from '../utils/controller-wiring.js';
|
|
8
|
+
import { extendEngineConfiguration } from '../utils/engine-wiring.js';
|
|
7
9
|
function isListingFetchCompletedAction(action) {
|
|
8
10
|
return /^commerce\/productListing\/fetch\/(fulfilled|rejected)$/.test(action.type);
|
|
9
11
|
}
|
|
@@ -64,24 +66,22 @@ function fetchActiveRecommendationControllers(controllerProps, solutionType) {
|
|
|
64
66
|
: 0;
|
|
65
67
|
}
|
|
66
68
|
export const buildFactory = (controllerDefinitions, options) => (solutionType) => async (...[buildOptions]) => {
|
|
69
|
+
const controllerProps = wireControllerParams(solutionType, controllerDefinitions, buildOptions); // TODO: KIT-4754: remove non-null assertion operator
|
|
67
70
|
const logger = buildLogger(options.loggerOptions);
|
|
68
71
|
if (!options.navigatorContextProvider) {
|
|
69
72
|
logger.warn('[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()');
|
|
70
73
|
}
|
|
71
|
-
const controllerProps = buildOptions && 'controllers' in buildOptions
|
|
72
|
-
? buildOptions.controllers
|
|
73
|
-
: {};
|
|
74
74
|
const enabledRecommendationControllers = fetchActiveRecommendationControllers(controllerProps, solutionType);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
: options,
|
|
75
|
+
const engineOptions = {
|
|
76
|
+
...options,
|
|
77
|
+
configuration: extendEngineConfiguration(options.configuration, buildOptions), // TODO: KIT-4754: remove non-null assertion operator
|
|
78
|
+
};
|
|
79
|
+
const engine = buildSSRCommerceEngine(solutionType, engineOptions, enabledRecommendationControllers);
|
|
78
80
|
const controllers = buildControllerDefinitions({
|
|
79
81
|
definitionsMap: (controllerDefinitions ?? {}),
|
|
80
82
|
engine,
|
|
81
83
|
solutionType,
|
|
82
|
-
propsMap:
|
|
83
|
-
? buildOptions.controllers
|
|
84
|
-
: {}),
|
|
84
|
+
propsMap: controllerProps,
|
|
85
85
|
});
|
|
86
86
|
return {
|
|
87
87
|
engine,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { buildFactory, } from './build-factory.js';
|
|
2
2
|
export function hydratedStaticStateFactory(controllerDefinitions, options) {
|
|
3
3
|
return (solutionType) => async (...params) => {
|
|
4
|
-
const solutionTypeBuild = await buildFactory(controllerDefinitions,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(solutionType);
|
|
5
|
+
const { engine, controllers } = await solutionTypeBuild(
|
|
6
|
+
// @ts-expect-error: TODO: KIT-4742: the wiring will fix also the type inconsistencies
|
|
7
|
+
...params);
|
|
8
8
|
params[0].searchActions.forEach((action) => {
|
|
9
9
|
engine.dispatch(action);
|
|
10
10
|
});
|
|
@@ -3,7 +3,9 @@ import { buildFactory, } from './build-factory.js';
|
|
|
3
3
|
export function hydratedRecommendationStaticStateFactory(controllerDefinitions, options) {
|
|
4
4
|
return async (...params) => {
|
|
5
5
|
const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(SolutionType.recommendation);
|
|
6
|
-
const { engine, controllers } = (await solutionTypeBuild(
|
|
6
|
+
const { engine, controllers } = (await solutionTypeBuild(
|
|
7
|
+
// @ts-expect-error: TODO: KIT-4742: the wiring will fix also the type inconsistencies
|
|
8
|
+
...params));
|
|
7
9
|
params[0].searchActions.forEach((action) => {
|
|
8
10
|
engine.dispatch(action);
|
|
9
11
|
});
|
|
@@ -6,9 +6,7 @@ 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 solutionTypeBuild = await buildFactory(controllerDefinitions,
|
|
10
|
-
...options,
|
|
11
|
-
})(solutionType);
|
|
9
|
+
const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(solutionType);
|
|
12
10
|
const { engine, controllers } = await solutionTypeBuild(...params);
|
|
13
11
|
options.configuration.preprocessRequest =
|
|
14
12
|
augmentPreprocessRequestWithForwardedFor({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const validateControllerNames = (controllers) => {
|
|
2
|
+
const reservedNames = ['context', 'cart', 'parameterManager'];
|
|
3
|
+
const invalidNames = Object.keys(controllers).filter((name) => reservedNames.includes(name));
|
|
4
|
+
if (invalidNames.length > 0) {
|
|
5
|
+
throw new Error(`Reserved controller names found: ${invalidNames.join(', ')}. Please use different controller names than ${reservedNames.join(', ')}.`);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "3.29.0
|
|
1
|
+
export const VERSION = "3.29.0" || 'Test version';
|
|
2
2
|
export const COVEO_FRAMEWORK = ['@coveo/atomic', '@coveo/quantic'];
|