@coveo/quantic 3.10.0 → 3.11.1
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/README.md +52 -12
- package/docs/out/quantic-docs.json +27 -0
- package/force-app/main/default/labels/CustomLabels.labels-meta.xml +7 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/__tests__/quanticBreadcrumbManager.test.js +341 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/quanticBreadcrumbManager.html +8 -8
- package/force-app/main/default/lwc/quanticBreadcrumbManager/quanticBreadcrumbManager.js +8 -8
- package/force-app/main/default/lwc/quanticFeedbackModalQna/templates/quanticFeedbackModalQna.html +1 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +538 -21
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/data.ts +56 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/fixture.ts +87 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/pageObject.ts +279 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/quanticGeneratedAnswer.e2e.ts +178 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/generatedAnswer.html +24 -10
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/retryPrompt.html +2 -2
- package/force-app/main/default/lwc/quanticGeneratedAnswerToggle/quanticGeneratedAnswerToggle.html +1 -1
- package/force-app/main/default/lwc/quanticNotifications/__tests__/quanticNotifications.test.js +112 -4
- package/force-app/main/default/lwc/quanticNotifications/quanticNotifications.css +8 -0
- package/force-app/main/default/lwc/quanticNotifications/quanticNotifications.html +20 -7
- package/force-app/main/default/lwc/quanticNotifications/quanticNotifications.js +57 -18
- package/force-app/main/default/lwc/quanticPager/e2e/pagerObject.ts +1 -1
- package/force-app/main/default/lwc/quanticUserActionsToggle/__tests__/quanticUserActionsToggle.test.js +18 -0
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/data.ts +32 -0
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/fixture.ts +32 -0
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/pageObject.ts +71 -0
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/quanticUserActionsToggle.e2e.ts +39 -0
- package/force-app/main/default/lwc/quanticUserActionsToggle/quanticUserActionsToggle.js +4 -0
- package/force-app/main/default/staticresources/coveobueno/browser/bueno.js +4 -4
- package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +8 -10
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/analytics/instant-result-analytics.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/analytics/search-analytics.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/knowledge/stream-answer-api.d.ts +3 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-engine/commerce-engine.ssr.d.ts +2 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/factories/build-factory.d.ts +2 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/factories/utils/recommendation-filter.d.ts +11 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/build.d.ts +4 -8
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/common.d.ts +178 -7
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/core-engine.d.ts +3 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/fetch-static-state.d.ts +4 -12
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/from-build-result.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/hydrate-static-state.d.ts +4 -11
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/kind.d.ts +6 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/ssr-engine/types/common.d.ts +6 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/context/cart/headless-cart.ssr.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/context/headless-context.ssr.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/facets/generator/headless-commerce-facet-generator.ssr.d.ts +3 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/parameter-manager/headless-core-parameter-manager.d.ts +8 -7
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/parameter-manager/headless-core-parameter-manager.ssr.d.ts +3 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/sub-controller/headless-sub-controller.d.ts +1 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/url-manager/headless-core-url-manager.d.ts +11 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/product-list/headless-product-list.ssr.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/product-view/headless-product-view.ssr.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recommendations/headless-recommendations.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recommendations/headless-recommendations.ssr.d.ts +4 -4
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/standalone-search-box/headless-standalone-search-box.ssr.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-actions.d.ts +22 -6
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-schema.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-selectors.d.ts +0 -11
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-serializer.d.ts +6 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-serializer.ssr.d.ts +44 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-slice.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-state.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/recommendations/recommendations-actions.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/recommendations/recommendations-state.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/search/search-selectors.d.ts +0 -12
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/debug/debug-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/question-answering/question-answering-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/search-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-parameters/search-parameter-serializer.d.ts +5 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-commerce.index.d.ts +4 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/state/commerce-app-state.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/state/state-sections.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/utils/errors.d.ts +3 -0
- package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -12
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +9 -11
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +8 -10
- package/force-app/main/default/staticresources/dompurify/purify.min.js +2 -1339
- package/package.json +23 -19
|
@@ -6,7 +6,7 @@ export declare class InstantResultsAnalyticsProvider extends SearchAnalyticsProv
|
|
|
6
6
|
constructor(getState: () => StateNeededByInstantResultsAnalyticsProvider);
|
|
7
7
|
private get activeInstantResultQuery();
|
|
8
8
|
private get activeInstantResultCache();
|
|
9
|
-
protected get results(): import("../../
|
|
9
|
+
protected get results(): import("../../ssr.index.js").Result[] | undefined;
|
|
10
10
|
protected get queryText(): string;
|
|
11
11
|
protected get responseTime(): number;
|
|
12
12
|
protected get numberOfResults(): number;
|
|
@@ -85,7 +85,7 @@ export declare class SearchAnalyticsProvider extends BaseAnalyticsProvider<State
|
|
|
85
85
|
};
|
|
86
86
|
getGeneratedAnswerMetadata(): Record<string, string | boolean>;
|
|
87
87
|
private get resultURIs();
|
|
88
|
-
protected get results(): import("../../
|
|
88
|
+
protected get results(): import("../../ssr.index.js").Result[] | undefined;
|
|
89
89
|
protected get queryText(): string;
|
|
90
90
|
protected get responseTime(): number;
|
|
91
91
|
protected get numberOfResults(): number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventSourceMessage } from '@microsoft/fetch-event-source';
|
|
2
|
+
import { ThunkDispatch, UnknownAction } from '@reduxjs/toolkit';
|
|
2
3
|
import { GeneratedContentFormat } from '../../features/generated-answer/generated-response-format.js';
|
|
3
4
|
import { SearchAppState } from '../../state/search-app-state.js';
|
|
4
5
|
import { ConfigurationSection, GeneratedAnswerSection, InsightConfigurationSection } from '../../state/state-sections.js';
|
|
@@ -22,6 +23,7 @@ export interface GeneratedAnswerStream {
|
|
|
22
23
|
code: number;
|
|
23
24
|
};
|
|
24
25
|
}
|
|
26
|
+
export declare const updateCacheWithEvent: (event: EventSourceMessage, draft: GeneratedAnswerStream, dispatch: ThunkDispatch<StateNeededByAnswerAPI, unknown, UnknownAction>) => void;
|
|
25
27
|
export declare const answerApi: import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {} & import("@reduxjs/toolkit/query").RetryOptions, {}>, {
|
|
26
28
|
getAnswer: import("@reduxjs/toolkit/query").QueryDefinition<Partial<SearchRequest>, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {} & import("@reduxjs/toolkit/query").RetryOptions, {}>, never, GeneratedAnswerStream, "answer">;
|
|
27
29
|
}, "answer", never, typeof import("@reduxjs/toolkit/query").coreModuleName>;
|
|
@@ -13,6 +13,8 @@ export interface CommerceEngineDefinition<TControllers extends ControllerDefinit
|
|
|
13
13
|
* @param options - The commerce engine definition
|
|
14
14
|
* @returns Three utility functions to fetch the initial state of the engine in SSR, hydrate the state in CSR,
|
|
15
15
|
* and a build function that can be used for edge cases requiring more control.
|
|
16
|
+
*
|
|
17
|
+
* @group Engine
|
|
16
18
|
*/
|
|
17
19
|
export declare function defineCommerceEngine<TControllerDefinitions extends ControllerDefinitionsMap<Controller>>(options: CommerceEngineDefinitionOptions<TControllerDefinitions>): {
|
|
18
20
|
listingEngineDefinition: CommerceEngineDefinition<TControllerDefinitions, SolutionType.listing>;
|
|
@@ -5,6 +5,8 @@ import { ControllerDefinitionsMap, SolutionType } from '../types/common.js';
|
|
|
5
5
|
import { BuildParameters, CommerceControllerDefinitionsMap, EngineDefinitionOptions } from '../types/core-engine.js';
|
|
6
6
|
/**
|
|
7
7
|
* The SSR commerce engine.
|
|
8
|
+
*
|
|
9
|
+
* @group Engine
|
|
8
10
|
*/
|
|
9
11
|
export interface SSRCommerceEngine extends CommerceEngine {
|
|
10
12
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Controller } from '../../../../controllers/controller/headless-controller.js';
|
|
2
|
+
import { ControllerDefinitionsMap } from '../../types/common.js';
|
|
3
|
+
export declare function filterRecommendationControllers<TControllerDefinitions extends ControllerDefinitionsMap<Controller>>(controllers: Record<string, Controller>, controllerDefinitions: TControllerDefinitions): {
|
|
4
|
+
/**
|
|
5
|
+
* Go through all the controllers passed in argument and only refresh recommendation controllers.
|
|
6
|
+
*
|
|
7
|
+
* @param controllers - A record of all controllers where the key is the controller name and the value is the controller instance.
|
|
8
|
+
* @param controllerNames - A list of all recommendation controllers to refresh
|
|
9
|
+
*/
|
|
10
|
+
refresh(whitelist?: string[]): void;
|
|
11
|
+
};
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
+
import { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
1
2
|
import type { ControllersMap, ControllersPropsMap, EngineDefinitionBuildResult, OptionsExtender, OptionsTuple } from '../../ssr-engine/types/common.js';
|
|
2
3
|
import { SSRCommerceEngine } from '../factories/build-factory.js';
|
|
3
|
-
import { EngineDefinitionControllersPropsOption, SolutionType } from './common.js';
|
|
4
|
+
import { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, SolutionType } from './common.js';
|
|
4
5
|
export interface BuildOptions<TEngineOptions> {
|
|
5
6
|
extend?: OptionsExtender<TEngineOptions>;
|
|
6
7
|
}
|
|
7
|
-
export type Build<TEngineOptions, TControllersMap extends ControllersMap, TControllersProps extends ControllersPropsMap,
|
|
8
|
+
export type Build<TEngineOptions, TControllersMap extends ControllersMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
8
9
|
/**
|
|
9
10
|
* Initializes an engine and controllers from the definition.
|
|
10
11
|
*/
|
|
11
|
-
(
|
|
12
|
-
} : {
|
|
13
|
-
/**
|
|
14
|
-
* Initializes an engine and controllers from the definition.
|
|
15
|
-
*/
|
|
16
|
-
(...params: OptionsTuple<BuildOptions<TEngineOptions> & EngineDefinitionControllersPropsOption<TControllersProps>>): Promise<EngineDefinitionBuildResult<SSRCommerceEngine, TControllersMap>>;
|
|
12
|
+
(...params: OptionsTuple<BuildOptions<TEngineOptions> & EngineDefinitionControllersPropsOption<TControllersDefinitionsMap, TControllersProps, TSolutionType>>): Promise<EngineDefinitionBuildResult<SSRCommerceEngine, TControllersMap>>;
|
|
17
13
|
};
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
3
|
import type { InvalidControllerDefinition } from '../../../utils/errors.js';
|
|
4
|
-
import type { HasKey, InferControllerStaticStateMapFromControllers, InferControllerStaticStateFromController,
|
|
4
|
+
import type { HasKey, InferControllerStaticStateMapFromControllers, InferControllerStaticStateFromController, ControllerStaticStateMap, EngineDefinitionBuildResult, HydratedState, OptionsTuple, ControllersPropsMap, HasKeys, HasRequiredKeys, HasOptionalKeys } from '../../ssr-engine/types/common.js';
|
|
5
5
|
import { SSRCommerceEngine } from '../factories/build-factory.js';
|
|
6
|
-
|
|
6
|
+
import { Kind } from './kind.js';
|
|
7
|
+
export type { EngineDefinitionBuildResult, HydratedState, OptionsTuple, InferControllerStaticStateFromController, InferControllerStaticStateMapFromControllers, };
|
|
7
8
|
export declare enum SolutionType {
|
|
8
9
|
search = "search",
|
|
9
10
|
listing = "listing",
|
|
10
11
|
standalone = "standalone",
|
|
11
12
|
recommendation = "recommendation"
|
|
12
13
|
}
|
|
14
|
+
export declare const recommendationInternalOptionKey: unique symbol;
|
|
15
|
+
export type RecommendationControllerSettings = {
|
|
16
|
+
/**
|
|
17
|
+
* Toggle to enable or disable the recommendation controller.
|
|
18
|
+
* When set to `true`, the controller will perform a recommendation request server-side.
|
|
19
|
+
*
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
};
|
|
13
24
|
export interface ControllerDefinitionWithoutProps<TController extends Controller> {
|
|
14
25
|
/**
|
|
15
26
|
* Creates an instance of the given controller.
|
|
@@ -20,6 +31,9 @@ export interface ControllerDefinitionWithoutProps<TController extends Controller
|
|
|
20
31
|
*/
|
|
21
32
|
build(engine: SSRCommerceEngine, solutionType?: SolutionType): TController;
|
|
22
33
|
}
|
|
34
|
+
export interface ControllerWithKind extends Controller {
|
|
35
|
+
_kind: Kind;
|
|
36
|
+
}
|
|
23
37
|
export interface ControllerDefinitionWithProps<TController extends Controller, TProps> {
|
|
24
38
|
/**
|
|
25
39
|
* Creates an instance of the given controller.
|
|
@@ -29,17 +43,26 @@ export interface ControllerDefinitionWithProps<TController extends Controller, T
|
|
|
29
43
|
* @param solutionType - The type of solution for which the controller should be built (e.g. search or listing). This option only applies to sub-controllers.
|
|
30
44
|
* @returns The created controller instance.
|
|
31
45
|
*/
|
|
32
|
-
buildWithProps(engine: SSRCommerceEngine, props: TProps, solutionType?: SolutionType): TController;
|
|
46
|
+
buildWithProps(engine: SSRCommerceEngine, props: TProps, solutionType?: SolutionType): TController & ControllerWithKind;
|
|
33
47
|
}
|
|
34
48
|
export interface EngineStaticState<TSearchAction extends UnknownAction, TControllers extends ControllerStaticStateMap> {
|
|
35
49
|
searchActions: TSearchAction[];
|
|
36
50
|
controllers: TControllers;
|
|
37
51
|
}
|
|
38
|
-
export
|
|
52
|
+
export interface SolutionTypeAvailability {
|
|
53
|
+
[SolutionType.search]?: boolean;
|
|
54
|
+
[SolutionType.listing]?: boolean;
|
|
55
|
+
[SolutionType.standalone]?: boolean;
|
|
56
|
+
[SolutionType.recommendation]?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export type ControllerDefinition<TController extends Controller> = SolutionTypeAvailability & (ControllerDefinitionWithoutProps<TController> | ControllerDefinitionWithProps<TController, unknown>);
|
|
39
59
|
export interface ControllerDefinitionsMap<TController extends Controller> {
|
|
40
60
|
[customName: string]: ControllerDefinition<TController>;
|
|
41
61
|
}
|
|
42
|
-
export type InferControllerPropsFromDefinition<TController extends ControllerDefinition<Controller>> = TController extends ControllerDefinitionWithProps<Controller, infer Props> ? Props : TController extends ControllerDefinitionWithoutProps<Controller> ? {} : unknown;
|
|
62
|
+
export 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;
|
|
63
|
+
export type InferControllerPropsMapFromDefinitions<TControllers extends ControllerDefinitionsMap<Controller>> = {
|
|
64
|
+
[K in keyof TControllers as HasKeys<InferControllerPropsFromDefinition<TControllers[K]>> extends false ? never : K]: InferControllerPropsFromDefinition<TControllers[K]>;
|
|
65
|
+
};
|
|
43
66
|
export type InferControllerFromDefinition<TDefinition extends ControllerDefinition<Controller>> = TDefinition extends ControllerDefinition<infer TController> ? TController : never;
|
|
44
67
|
export type InferControllersMapFromDefinition<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
45
68
|
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerFromDefinition<TControllers[K]>;
|
|
@@ -47,6 +70,123 @@ export type InferControllersMapFromDefinition<TControllers extends ControllerDef
|
|
|
47
70
|
export type InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
48
71
|
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]>>;
|
|
49
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* This type defines the required and optional controller props for the engine definition.
|
|
75
|
+
*/
|
|
76
|
+
export type EngineDefinitionControllersPropsOption<TControllers extends ControllerDefinitionsMap<Controller>, TControllersPropsMap extends ControllersPropsMap, TSolutionType extends SolutionType> = OptionalEngineDefinitionControllersPropsOption<TControllers, TControllersPropsMap, TSolutionType> & RequiredEngineDefinitionControllersPropsOption<TControllers, TControllersPropsMap, TSolutionType>;
|
|
77
|
+
/**
|
|
78
|
+
* Represents an optional engine definition for controller properties.
|
|
79
|
+
*
|
|
80
|
+
* This type is used to define a map of optional controller properties based on the provided
|
|
81
|
+
* controller definitions, controller properties map, and solution type.
|
|
82
|
+
*
|
|
83
|
+
* @template TControllers - A map of controller definitions.
|
|
84
|
+
* @template TControllersPropsMap - A map of controller properties.
|
|
85
|
+
* @template TSolutionType - The type of solution.
|
|
86
|
+
*
|
|
87
|
+
* The type iterates over the controller keys (defined in the engine definition) and includes only those keys where:
|
|
88
|
+
* 1. The controller can be used for a specific solution type (HasKey<TControllers[K], TSolutionType> is not 'never').
|
|
89
|
+
* 2. The controller properties have optional options (HasOptionalKeys<ConditionalControllerProps<...>> is true).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* Given the following controller definitions:
|
|
93
|
+
* ```
|
|
94
|
+
* const {recommendationEngineDefinition} = defineCommerceEngine({
|
|
95
|
+
* controllers: {
|
|
96
|
+
* popularViewed: defineRecommendations({
|
|
97
|
+
* options: {slotId: 'slot-id'}
|
|
98
|
+
* })
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* The following code will not throw an error since the 'popularViewed' controller props are optional
|
|
104
|
+
* ```
|
|
105
|
+
* recommendationEngineDefinition.fetchStaticState({
|
|
106
|
+
* controllers: {
|
|
107
|
+
* popularViewed: {enabled: true, productId: 'some-product-id'} // This is optional
|
|
108
|
+
* }
|
|
109
|
+
* })
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* The following code (with no arguments) is also valid because the 'popularViewed' controller props are optional, and there are no other required controller props in the engine definition.
|
|
113
|
+
* ```
|
|
114
|
+
* recommendationEngineDefinition.fetchStaticState()
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export type OptionalEngineDefinitionControllersPropsOption<TControllers extends ControllerDefinitionsMap<Controller>, TControllersPropsMap extends ControllersPropsMap, TSolutionType extends SolutionType> = {
|
|
118
|
+
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : HasOptionalKeys<ConditionalControllerProps<TControllers, TControllersPropsMap, TSolutionType, K>> extends false ? never : 'controllers']?: ConditionalControllerProps<TControllers, TControllersPropsMap, TSolutionType, K>;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Represents a type that defines the required controller properties for engine definition controllers.
|
|
122
|
+
*
|
|
123
|
+
* @template TControllers - A map of controller definitions.
|
|
124
|
+
* @template TControllersPropsMap - A map of controller properties.
|
|
125
|
+
* @template TSolutionType - The type of solution being used.
|
|
126
|
+
*
|
|
127
|
+
* The type iterates over the controller keys (defined in the engine definition) and includes only those keys where:
|
|
128
|
+
* 1. The controller can be used for a specific solution type (HasKey<TControllers[K], TSolutionType> is not 'never').
|
|
129
|
+
* 2. The controller properties have required options (HasRequiredKeys<ConditionalControllerProps<...>> is true).
|
|
130
|
+
*
|
|
131
|
+
* The resulting type maps the valid keys to their corresponding conditional controller properties.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* Given the following controller definitions:
|
|
135
|
+
* ```
|
|
136
|
+
* const {standaloneEngineDefinition} = defineCommerceEngine({
|
|
137
|
+
* controllers: {cart: defineCart()},
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* The following code will not throw an error since the 'cart' controller props are required for the standalone engine definition:
|
|
142
|
+
* ```
|
|
143
|
+
* standaloneEngineDefinition.fetchStaticState({
|
|
144
|
+
* controllers: {
|
|
145
|
+
* cart: {initialState: {items: []}},
|
|
146
|
+
* },
|
|
147
|
+
* })
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
export type RequiredEngineDefinitionControllersPropsOption<TControllers extends ControllerDefinitionsMap<Controller>, TControllersPropsMap extends ControllersPropsMap, TSolutionType extends SolutionType> = {
|
|
152
|
+
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : HasRequiredKeys<ConditionalControllerProps<TControllers, TControllersPropsMap, TSolutionType, K>> extends false ? never : 'controllers']: ConditionalControllerProps<TControllers, TControllersPropsMap, TSolutionType, K>;
|
|
153
|
+
};
|
|
154
|
+
type IsRecommendationController<TController extends ControllerDefinition<Controller>> = HasKey<TController, typeof recommendationInternalOptionKey>;
|
|
155
|
+
/**
|
|
156
|
+
* This type ensures that recommendation controller props are optional, while other controller props remain required.
|
|
157
|
+
*
|
|
158
|
+
* It works by checking if the controller definition includes the `recommendationInternalOptionKey`.
|
|
159
|
+
*
|
|
160
|
+
* - If the key is present, the controller props are made optional.
|
|
161
|
+
* - If the key is absent, the controller props are required.
|
|
162
|
+
*
|
|
163
|
+
* Example:
|
|
164
|
+
*
|
|
165
|
+
* ```typescript
|
|
166
|
+
* type ControllerProps = InferControllerPropsFromDefinition<{
|
|
167
|
+
* recommendation: defineRecommendation({}),
|
|
168
|
+
* cart: defineCart(),
|
|
169
|
+
* }>;
|
|
170
|
+
*
|
|
171
|
+
* // In this example:
|
|
172
|
+
* // - The `recommendation` controller props are optional.
|
|
173
|
+
* // - The `cart` controller props are required.
|
|
174
|
+
*
|
|
175
|
+
* const props: ControllerProps = {
|
|
176
|
+
* cart: {initialState: {items: []}},
|
|
177
|
+
* // recommendation props can be omitted
|
|
178
|
+
* };
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
type RecommendationControllerProps<TControllers extends ControllerDefinitionsMap<Controller>, TControllersPropsMap extends ControllersPropsMap, K extends keyof TControllers> = {
|
|
182
|
+
[I in keyof TControllersPropsMap as I extends K ? IsRecommendationController<TControllers[I]> extends never ? never : I : never]?: TControllersPropsMap[I];
|
|
183
|
+
} & {
|
|
184
|
+
[I in keyof TControllersPropsMap as I extends K ? IsRecommendationController<TControllers[I]> extends never ? I : never : never]: TControllersPropsMap[I];
|
|
185
|
+
};
|
|
186
|
+
type DefaultControllerProps<TControllers extends ControllerDefinitionsMap<Controller>, TControllersPropsMap extends ControllersPropsMap, K extends keyof TControllers> = {
|
|
187
|
+
[I in keyof TControllersPropsMap as I extends K ? I : never]: TControllersPropsMap[I];
|
|
188
|
+
};
|
|
189
|
+
type ConditionalControllerProps<TControllers extends ControllerDefinitionsMap<Controller>, TControllersPropsMap extends ControllersPropsMap, TSolutionType extends SolutionType, K extends keyof TControllers> = TSolutionType extends SolutionType.recommendation ? RecommendationControllerProps<TControllers, TControllersPropsMap, K> : DefaultControllerProps<TControllers, TControllersPropsMap, K>;
|
|
50
190
|
export interface ControllerDefinitionOption {
|
|
51
191
|
/**
|
|
52
192
|
* Whether the controller will be used in a product listing context.
|
|
@@ -59,6 +199,20 @@ export interface ControllerDefinitionOption {
|
|
|
59
199
|
*/
|
|
60
200
|
search?: boolean;
|
|
61
201
|
}
|
|
202
|
+
interface NonRecommendationController {
|
|
203
|
+
/**
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
[SolutionType.search]: true;
|
|
207
|
+
/**
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
[SolutionType.listing]: true;
|
|
211
|
+
/**
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
[SolutionType.standalone]: true;
|
|
215
|
+
}
|
|
62
216
|
interface UniversalController {
|
|
63
217
|
/**
|
|
64
218
|
* @internal
|
|
@@ -72,6 +226,10 @@ interface UniversalController {
|
|
|
72
226
|
* @internal
|
|
73
227
|
*/
|
|
74
228
|
[SolutionType.standalone]: true;
|
|
229
|
+
/**
|
|
230
|
+
* @internal
|
|
231
|
+
*/
|
|
232
|
+
[SolutionType.recommendation]: true;
|
|
75
233
|
}
|
|
76
234
|
interface SearchOnlyController {
|
|
77
235
|
/**
|
|
@@ -101,14 +259,27 @@ interface SearchAndListingController {
|
|
|
101
259
|
*/
|
|
102
260
|
[SolutionType.listing]: true;
|
|
103
261
|
}
|
|
262
|
+
interface ListingAndStandaloneController {
|
|
263
|
+
/**
|
|
264
|
+
* @internal
|
|
265
|
+
*/
|
|
266
|
+
[SolutionType.listing]: true;
|
|
267
|
+
/**
|
|
268
|
+
* @internal
|
|
269
|
+
*/
|
|
270
|
+
[SolutionType.standalone]: true;
|
|
271
|
+
}
|
|
104
272
|
export type SearchOnlyControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & SearchOnlyController;
|
|
105
273
|
export type SearchOnlyControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> & SearchOnlyController;
|
|
274
|
+
export type ListingAndStandaloneControllerWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & ListingAndStandaloneController;
|
|
106
275
|
export type ListingOnlyControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & ListingOnlyController;
|
|
107
276
|
export type ListingOnlyControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> & ListingOnlyController;
|
|
108
277
|
export type RecommendationOnlyControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & RecommendationOnlyController;
|
|
109
278
|
export type RecommendationOnlyControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> & RecommendationOnlyController;
|
|
110
|
-
export type NonRecommendationControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> &
|
|
111
|
-
export type NonRecommendationControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> &
|
|
279
|
+
export type NonRecommendationControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & NonRecommendationController;
|
|
280
|
+
export type NonRecommendationControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> & NonRecommendationController;
|
|
281
|
+
export type UniversalControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & UniversalController;
|
|
282
|
+
export type UniversalControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> & UniversalController;
|
|
112
283
|
export type SearchAndListingControllerDefinitionWithoutProps<TController extends Controller> = ControllerDefinitionWithoutProps<TController> & SearchAndListingController;
|
|
113
284
|
export type SearchAndListingControllerDefinitionWithProps<TController extends Controller, TProps> = ControllerDefinitionWithProps<TController, TProps> & SearchAndListingController;
|
|
114
285
|
export type SubControllerDefinitionWithoutProps<TController extends Controller, TDefinition extends ControllerDefinitionOption | undefined> = TDefinition extends {
|
|
@@ -23,15 +23,15 @@ export interface EngineDefinition<TControllers extends ControllerDefinitionsMap<
|
|
|
23
23
|
/**
|
|
24
24
|
* Fetches the static state on the server side using your engine definition.
|
|
25
25
|
*/
|
|
26
|
-
fetchStaticState: FetchStaticState<InferControllersMapFromDefinition<TControllers, TSolutionType>, UnknownAction, InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>, InferControllerPropsMapFromDefinitions<TControllers>, TSolutionType>;
|
|
26
|
+
fetchStaticState: FetchStaticState<InferControllersMapFromDefinition<TControllers, TSolutionType>, UnknownAction, InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>, InferControllerPropsMapFromDefinitions<TControllers>, TControllers, TSolutionType>;
|
|
27
27
|
/**
|
|
28
28
|
* Fetches the hydrated state on the client side using your engine definition and the static state.
|
|
29
29
|
*/
|
|
30
|
-
hydrateStaticState: HydrateStaticState<InferControllersMapFromDefinition<TControllers, TSolutionType>, UnknownAction, InferControllerPropsMapFromDefinitions<TControllers>, TSolutionType>;
|
|
30
|
+
hydrateStaticState: HydrateStaticState<InferControllersMapFromDefinition<TControllers, TSolutionType>, UnknownAction, InferControllerPropsMapFromDefinitions<TControllers>, TControllers, TSolutionType>;
|
|
31
31
|
/**
|
|
32
32
|
* Builds an engine and its controllers from an engine definition.
|
|
33
33
|
*/
|
|
34
|
-
build: Build<TEngineOptions, InferControllersMapFromDefinition<TControllers, TSolutionType>, InferControllerPropsMapFromDefinitions<TControllers>, TSolutionType>;
|
|
34
|
+
build: Build<TEngineOptions, InferControllersMapFromDefinition<TControllers, TSolutionType>, InferControllerPropsMapFromDefinitions<TControllers>, TControllers, TSolutionType>;
|
|
35
35
|
/**
|
|
36
36
|
* Sets the navigator context provider.
|
|
37
37
|
* 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.
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
-
import {
|
|
3
|
-
import type { EngineDefinitionControllersPropsOption, EngineStaticState } from '../../commerce-ssr-engine/types/common.js';
|
|
2
|
+
import { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, EngineStaticState, SolutionType } from '../../commerce-ssr-engine/types/common.js';
|
|
4
4
|
import type { ControllersMap, ControllersPropsMap, ControllerStaticStateMap, OptionsTuple } from '../../ssr-engine/types/common.js';
|
|
5
5
|
import { FromBuildResult } from './from-build-result.js';
|
|
6
6
|
export type FetchStaticStateOptions = {};
|
|
7
|
-
export type FetchStaticState<TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap,
|
|
7
|
+
export type FetchStaticState<TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersStaticState extends ControllerStaticStateMap, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
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
|
-
(
|
|
14
|
-
fromBuildResult: FromBuildResult<TControllers, FetchStaticStateOptions, EngineStaticState<TSearchAction, TControllersStaticState>>;
|
|
15
|
-
} : {
|
|
16
|
-
/**
|
|
17
|
-
* Executes only the initial search for a given configuration, then returns a resumable snapshot of engine state along with the state of the controllers.
|
|
18
|
-
*
|
|
19
|
-
* Useful for static generation and server-side rendering.
|
|
20
|
-
*/
|
|
21
|
-
(...params: OptionsTuple<FetchStaticStateOptions & EngineDefinitionControllersPropsOption<TControllersProps>>): Promise<EngineStaticState<TSearchAction, TControllersStaticState>>;
|
|
13
|
+
(...params: OptionsTuple<FetchStaticStateOptions & EngineDefinitionControllersPropsOption<TControllersDefinitionsMap, TControllersProps, TSolutionType>>): Promise<EngineStaticState<TSearchAction, TControllersStaticState>>;
|
|
22
14
|
fromBuildResult: FromBuildResult<TControllers, FetchStaticStateOptions, EngineStaticState<TSearchAction, TControllersStaticState>>;
|
|
23
15
|
};
|
|
@@ -13,7 +13,7 @@ export interface FromBuildResultOptions<TControllers extends ControllersMap> {
|
|
|
13
13
|
*
|
|
14
14
|
* This is applicable only if the engine is a recommendation engine.
|
|
15
15
|
*/
|
|
16
|
-
allowedRecommendationKeys?:
|
|
16
|
+
allowedRecommendationKeys?: string[];
|
|
17
17
|
}
|
|
18
18
|
export interface FromBuildResult<TControllers extends ControllersMap, TOptions, TReturn> {
|
|
19
19
|
(options: FromBuildResultOptions<TControllers> & TOptions): Promise<TReturn>;
|
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
|
+
import { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
2
3
|
import type { ControllersMap, ControllersPropsMap, HydratedState, OptionsTuple } from '../../ssr-engine/types/common.js';
|
|
3
4
|
import { SSRCommerceEngine } from '../factories/build-factory.js';
|
|
4
|
-
import { EngineDefinitionControllersPropsOption, SolutionType } from './common.js';
|
|
5
|
+
import { ControllerDefinitionsMap, EngineDefinitionControllersPropsOption, SolutionType } from './common.js';
|
|
5
6
|
import { FromBuildResult } from './from-build-result.js';
|
|
6
7
|
export interface HydrateStaticStateOptions<TSearchAction> {
|
|
7
8
|
searchActions: TSearchAction[];
|
|
8
9
|
}
|
|
9
|
-
export type HydrateStaticState<TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersProps extends ControllersPropsMap,
|
|
10
|
+
export type HydrateStaticState<TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersProps extends ControllersPropsMap, TControllersDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
10
11
|
/**
|
|
11
12
|
* Creates a new engine from the snapshot of the engine created in SSR with fetchStaticState.
|
|
12
13
|
*
|
|
13
14
|
* Useful when hydrating a server-side-rendered engine.
|
|
14
15
|
*/
|
|
15
|
-
(...params: OptionsTuple<HydrateStaticStateOptions<TSearchAction>>): Promise<HydratedState<SSRCommerceEngine, TControllers>>;
|
|
16
|
-
fromBuildResult: FromBuildResult<TControllers, HydrateStaticStateOptions<TSearchAction>, HydratedState<SSRCommerceEngine, TControllers>>;
|
|
17
|
-
} : {
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new engine from the snapshot of the engine created in SSR with fetchStaticState.
|
|
20
|
-
*
|
|
21
|
-
* Useful when hydrating a server-side-rendered engine.
|
|
22
|
-
*/
|
|
23
|
-
(...params: OptionsTuple<HydrateStaticStateOptions<TSearchAction> & EngineDefinitionControllersPropsOption<TControllersProps>>): Promise<HydratedState<SSRCommerceEngine, TControllers>>;
|
|
16
|
+
(...params: OptionsTuple<HydrateStaticStateOptions<TSearchAction> & EngineDefinitionControllersPropsOption<TControllersDefinitionsMap, TControllersProps, TSolutionType>>): Promise<HydratedState<SSRCommerceEngine, TControllers>>;
|
|
24
17
|
fromBuildResult: FromBuildResult<TControllers, HydrateStaticStateOptions<TSearchAction>, HydratedState<SSRCommerceEngine, TControllers>>;
|
|
25
18
|
};
|
|
@@ -3,6 +3,12 @@ import type { Controller } from '../../../controllers/controller/headless-contro
|
|
|
3
3
|
import { CoreEngine, CoreEngineNext } from '../../engine.js';
|
|
4
4
|
export type HasKey<T, K extends PropertyKey> = T extends unknown ? K extends keyof T ? T[K] extends never ? never : true : never : never;
|
|
5
5
|
export type HasKeys<TObject> = TObject extends {} ? keyof TObject extends never ? false : true : boolean;
|
|
6
|
+
export type HasRequiredKeys<TObject> = TObject extends {} ? {
|
|
7
|
+
[K in keyof TObject]-?: {} extends Pick<TObject, K> ? never : K;
|
|
8
|
+
}[keyof TObject] extends never ? false : true : boolean;
|
|
9
|
+
export type HasOptionalKeys<TObject> = TObject extends {} ? {
|
|
10
|
+
[K in keyof TObject]-?: {} extends Pick<TObject, K> ? K : never;
|
|
11
|
+
}[keyof TObject] extends never ? false : true : boolean;
|
|
6
12
|
export type ExtractRequiredOptions<TOptions> = {
|
|
7
13
|
[TKey in keyof TOptions as Pick<TOptions, TKey> extends Required<Pick<TOptions, TKey>> ? TKey : never]: TOptions[TKey];
|
|
8
14
|
};
|
package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts
CHANGED
|
@@ -102,7 +102,7 @@ export type { InstantProducts, InstantProductsState, InstantProductsOptions, Ins
|
|
|
102
102
|
export { buildStandaloneSearchBox } from './controllers/commerce/standalone-search-box/headless-standalone-search-box.js';
|
|
103
103
|
export type { StandaloneSearchBox, StandaloneSearchBoxState, } from './controllers/commerce/standalone-search-box/headless-standalone-search-box.js';
|
|
104
104
|
export type { StandaloneSearchBoxProps, StandaloneSearchBoxOptions, } from './controllers/standalone-search-box/headless-standalone-search-box.ts';
|
|
105
|
-
export type { UrlManagerProps, UrlManagerInitialState, UrlManagerState, UrlManager, } from './controllers/commerce/core/url-manager/headless-core-url-manager.js';
|
|
105
|
+
export type { BaseUrlManagerProps, UrlManagerProps, UrlManagerInitialState, UrlManagerState, UrlManager, } from './controllers/commerce/core/url-manager/headless-core-url-manager.js';
|
|
106
106
|
export type { Template } from './features/templates/templates-manager.ts';
|
|
107
107
|
export type { ProductTemplate, ProductTemplateCondition, ProductTemplatesManager, } from './features/commerce/product-templates/product-templates-manager.js';
|
|
108
108
|
export { buildProductTemplatesManager } from './features/commerce/product-templates/product-templates-manager.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UniversalControllerDefinitionWithProps } from '../../../../app/commerce-ssr-engine/types/common.js';
|
|
2
2
|
import { Cart, CartInitialState } from './headless-cart.js';
|
|
3
3
|
export type { CartState, CartItem, CartProps } from './headless-cart.js';
|
|
4
4
|
export type { Cart, CartInitialState };
|
|
5
5
|
export interface CartBuildProps {
|
|
6
6
|
initialState: CartInitialState;
|
|
7
7
|
}
|
|
8
|
-
export interface CartDefinition extends
|
|
8
|
+
export interface CartDefinition extends UniversalControllerDefinitionWithProps<Cart, CartBuildProps> {
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Defines a `Cart` controller instance.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UniversalControllerDefinitionWithProps } from '../../../app/commerce-ssr-engine/types/common.js';
|
|
2
2
|
import { Context, ContextOptions, View, UserLocation } from './headless-context.js';
|
|
3
3
|
export type { ContextState, Context, ContextProps } from './headless-context.js';
|
|
4
4
|
export type { View, UserLocation, ContextOptions };
|
|
5
|
-
export interface ContextDefinition extends
|
|
5
|
+
export interface ContextDefinition extends UniversalControllerDefinitionWithProps<Context, ContextOptions> {
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Defines a `Context` controller instance.
|
|
@@ -3,6 +3,7 @@ import { BreadcrumbManager, BreadcrumbManagerState } from './headless-core-bread
|
|
|
3
3
|
export type { BreadcrumbManager, BreadcrumbManagerState };
|
|
4
4
|
/**
|
|
5
5
|
* Defines a `BreadcrumbManager` controller instance.
|
|
6
|
+
* @group Definers
|
|
6
7
|
*
|
|
7
8
|
* @returns The `BreadcrumbManager` controller definition.
|
|
8
9
|
*
|
|
@@ -17,6 +17,9 @@ export type { FacetType };
|
|
|
17
17
|
export type MappedFacetState = {
|
|
18
18
|
[T in FacetType]: T extends 'numericalRange' ? NumericFacetState : T extends 'regular' ? RegularFacetState : T extends 'dateRange' ? DateFacetState : T extends 'hierarchical' ? CategoryFacetState : T extends 'location' ? LocationFacetState : never;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* @group Definers
|
|
22
|
+
*/
|
|
20
23
|
export declare function defineFacetGenerator<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions): SubControllerDefinitionWithoutProps<FacetGenerator, TOptions>;
|
|
21
24
|
/**
|
|
22
25
|
* The `FacetGenerator` headless sub-controller creates commerce facet sub-controllers from the Commerce API search or
|
|
@@ -9,7 +9,14 @@ export interface ParameterManagerProps<T extends Parameters> {
|
|
|
9
9
|
/**
|
|
10
10
|
* The initial state that should be applied to the `ParameterManager` sub-controller.
|
|
11
11
|
*/
|
|
12
|
-
initialState
|
|
12
|
+
initialState?: ParameterManagerInitialState<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the controller's state should exclude the default parameters returned by the Commerce API, and only include
|
|
15
|
+
* the parameters that were set explicitly set through dispatched actions.
|
|
16
|
+
*
|
|
17
|
+
* Defaults to `false`.
|
|
18
|
+
*/
|
|
19
|
+
excludeDefaultParameters?: boolean;
|
|
13
20
|
}
|
|
14
21
|
export interface CoreParameterManagerProps<T extends Parameters> extends ParameterManagerProps<T> {
|
|
15
22
|
/**
|
|
@@ -28,12 +35,6 @@ export interface CoreParameterManagerProps<T extends Parameters> extends Paramet
|
|
|
28
35
|
* The action to dispatch to fetch more results.
|
|
29
36
|
*/
|
|
30
37
|
fetchProductsActionCreator: FetchProductsActionCreator;
|
|
31
|
-
/**
|
|
32
|
-
* Enriches the parameters with the active parameters.
|
|
33
|
-
* @param state
|
|
34
|
-
* @param activeParams
|
|
35
|
-
*/
|
|
36
|
-
enrichParameters(state: CommerceEngine[typeof stateKey], activeParams: T): Required<T>;
|
|
37
38
|
}
|
|
38
39
|
export interface ParameterManagerInitialState<T> {
|
|
39
40
|
/**
|
|
@@ -12,7 +12,9 @@ export type { ParameterManager, ParameterManagerProps, ParameterManagerState, Pa
|
|
|
12
12
|
*
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
15
|
-
export declare function defineParameterManager<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions): SubControllerDefinitionWithProps<ParameterManager<
|
|
15
|
+
export declare function defineParameterManager<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions): SubControllerDefinitionWithProps<ParameterManager<MappedParameterTypes<TOptions>>, TOptions, SSRParameterManagerProps<MappedParameterTypes<TOptions>>>;
|
|
16
|
+
export interface SSRParameterManagerProps<T extends Parameters> extends Omit<ParameterManagerProps<T>, 'excludeDefaultParameters'> {
|
|
17
|
+
}
|
|
16
18
|
type MappedParameterTypes<TOptions extends ControllerDefinitionOption | undefined> = TOptions extends {
|
|
17
19
|
listing: true;
|
|
18
20
|
search: true;
|
|
@@ -68,7 +68,7 @@ export interface SearchAndListingSubControllers<P extends Parameters, S extends
|
|
|
68
68
|
* @param props - Properties for the `ParameterManager` sub-controller.
|
|
69
69
|
* @returns A `ParameterManager` sub-controller.
|
|
70
70
|
*/
|
|
71
|
-
parameterManager(props
|
|
71
|
+
parameterManager(props?: ParameterManagerProps<P>): ParameterManager<P>;
|
|
72
72
|
}
|
|
73
73
|
export interface SearchSubControllers extends SearchAndListingSubControllers<CommerceSearchParameters, SearchSummaryState> {
|
|
74
74
|
/**
|
|
@@ -98,7 +98,6 @@ export interface SearchAndListingSubControllerProps<P extends Parameters, S exte
|
|
|
98
98
|
parametersDefinition: SchemaDefinition<Required<P>>;
|
|
99
99
|
activeParametersSelector: (state: CommerceEngine[typeof stateKey]) => P;
|
|
100
100
|
restoreActionCreator: (parameters: P) => UnknownAction;
|
|
101
|
-
enrichParameters: (state: CommerceEngine[typeof stateKey], activeParams: P) => Required<P>;
|
|
102
101
|
facetSearchType: FacetSearchType;
|
|
103
102
|
}
|
|
104
103
|
/**
|
|
@@ -2,9 +2,18 @@ import { CommerceEngine } from '../../../../app/commerce-engine/commerce-engine.
|
|
|
2
2
|
import { stateKey } from '../../../../app/state-key.js';
|
|
3
3
|
import { Parameters } from '../../../../features/commerce/parameters/parameters-actions.js';
|
|
4
4
|
import { Serializer } from '../../../../features/commerce/parameters/parameters-serializer.js';
|
|
5
|
-
import { UrlManager, UrlManagerInitialState, type UrlManagerProps, UrlManagerState } from '../../../url-manager/headless-url-manager.js';
|
|
5
|
+
import { UrlManager, UrlManagerInitialState, type UrlManagerProps as BaseUrlManagerProps, UrlManagerState } from '../../../url-manager/headless-url-manager.js';
|
|
6
6
|
import { ParameterManager, ParameterManagerProps } from '../parameter-manager/headless-core-parameter-manager.js';
|
|
7
|
-
export type {
|
|
7
|
+
export type { UrlManager, UrlManagerInitialState, UrlManagerState, BaseUrlManagerProps, };
|
|
8
|
+
export interface UrlManagerProps extends BaseUrlManagerProps {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the controller's state should exclude the default parameters returned by the Commerce API, and only include
|
|
11
|
+
* the parameters that were set explicitly set through dispatched actions.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to `false`.
|
|
14
|
+
*/
|
|
15
|
+
excludeDefaultParameters?: boolean;
|
|
16
|
+
}
|
|
8
17
|
interface CoreUrlManagerProps<T extends Parameters> extends UrlManagerProps {
|
|
9
18
|
requestIdSelector: (state: CommerceEngine[typeof stateKey]) => string;
|
|
10
19
|
parameterManagerBuilder: (engine: CommerceEngine, props: ParameterManagerProps<T>) => ParameterManager<T>;
|
|
@@ -2,7 +2,7 @@ import { ControllerDefinitionOption, SubControllerDefinitionWithoutProps } from
|
|
|
2
2
|
import { ProductListing } from '../product-listing/headless-product-listing.js';
|
|
3
3
|
import { Search } from '../search/headless-search.js';
|
|
4
4
|
export type { ProductListingState as ProductListState } from '../product-listing/headless-product-listing.js';
|
|
5
|
-
export type ProductList = Pick<ProductListing | Search, 'state' | 'subscribe' | 'interactiveProduct'>;
|
|
5
|
+
export type ProductList = Pick<ProductListing | Search, 'state' | 'subscribe' | 'interactiveProduct' | 'promoteChildToParent'>;
|
|
6
6
|
/**
|
|
7
7
|
* Defines a `ProductList` controller instance.
|
|
8
8
|
* @group Definers
|