@coveo/headless 3.29.1 → 3.29.2-pre.0e2721db97
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/controller-definitions.d.ts +3 -0
- package/dist/definitions/ssr-commerce-next.index.d.ts +11 -11
- package/dist/definitions/ssr-commerce.index.d.ts +1 -1
- package/dist/definitions/ssr-next/commerce/controller-utils.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.d.ts +3 -2
- package/dist/definitions/ssr-next/commerce/controllers/cart/headless-cart.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/context/headless-context.ssr.d.ts +2 -3
- package/dist/definitions/ssr-next/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.d.ts +2 -1
- package/dist/definitions/ssr-next/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/generator/headless-commerce-facet-generator.ssr.d.ts +3 -2
- package/dist/definitions/ssr-next/commerce/controllers/instant-products/headless-instant-products.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.d.ts +3 -2
- package/dist/definitions/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.d.ts +3 -13
- package/dist/definitions/ssr-next/commerce/controllers/product-list/headless-product-list.ssr.d.ts +3 -2
- package/dist/definitions/ssr-next/commerce/controllers/product-view/headless-product-view.ssr.d.ts +1 -3
- package/dist/definitions/ssr-next/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/recommendations/headless-recommendations.ssr.d.ts +8 -4
- package/dist/definitions/ssr-next/commerce/controllers/search-box/headless-search-box.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/sort/headless-core-commerce-sort.ssr.d.ts +3 -2
- package/dist/definitions/ssr-next/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/summary/headless-core-summary.ssr.d.ts +3 -2
- package/dist/definitions/ssr-next/commerce/controllers/triggers/headless-notify-trigger.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/triggers/headless-query-trigger.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/controllers/triggers/headless-redirection-trigger.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/engine/commerce-engine.ssr.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/factories/build-factory.d.ts +1 -5
- package/dist/definitions/ssr-next/commerce/factories/hydrated-state-factory.d.ts +3 -3
- package/dist/definitions/ssr-next/commerce/factories/recommendation-hydrated-state-factory.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/factories/recommendation-static-state-factory.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/factories/static-state-factory.d.ts +1 -2
- package/dist/definitions/ssr-next/commerce/types/build.d.ts +60 -16
- package/dist/definitions/ssr-next/commerce/types/controller-definitions.d.ts +10 -170
- package/dist/definitions/ssr-next/commerce/types/controller-inference.d.ts +5 -10
- package/dist/definitions/ssr-next/commerce/types/engine.d.ts +7 -5
- package/dist/definitions/ssr-next/commerce/types/fetch-static-state.d.ts +2 -2
- package/dist/definitions/ssr-next/commerce/types/hydrate-static-state.d.ts +5 -4
- package/dist/definitions/ssr-next/commerce/utils/controller-wiring.d.ts +29 -2
- package/dist/definitions/ssr-next/commerce/utils/engine-wiring.d.ts +2 -3
- package/dist/definitions/ssr-next/commerce/utils/recommendation-filter.d.ts +14 -1
- package/dist/definitions/ssr-next/common/types/controller-inference.d.ts +6 -0
- package/dist/definitions/ssr-next/common/types/controllers.d.ts +0 -24
- package/dist/definitions/ssr-next/common/types/engine.d.ts +2 -44
- package/dist/definitions/ssr-next/common/types/utilities.d.ts +0 -3
- package/dist/definitions/ssr-next/{common → search}/controller-utils.d.ts +3 -3
- package/dist/definitions/ssr-next/search/controllers/breadcrumb-manager/headless-breadcrumb-manager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/context/headless-context.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/dictionary-field-context/headless-dictionary-field-context.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/did-you-mean/headless-did-you-mean.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facet-manager/headless-facet-manager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/automatic-facet-generator/headless-automatic-facet-generator.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/category-facet/headless-category-facet.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/facet/headless-facet.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/range-facet/date-facet/headless-date-facet.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/range-facet/date-facet/headless-date-filter.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/range-facet/numeric-facet/headless-numeric-facet.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/facets/range-facet/numeric-facet/headless-numeric-filter.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/field-suggestions/category-facet/headless-category-field-suggestions.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/field-suggestions/facet/headless-field-suggestions.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/folded-result-list/headless-folded-result-list.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/history-manager/headless-history-manager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/instant-results/instant-results.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/pager/headless-pager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/query-error/headless-query-error.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/query-summary/headless-query-summary.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/quickview/headless-quickview.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/recent-queries-list/headless-recent-queries-list.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/recent-results-list/headless-recent-results-list.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/relevance-inspector/headless-relevance-inspector.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/result-list/headless-result-list.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/results-per-page/headless-results-per-page.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/search-box/headless-search-box.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/search-parameter-manager/headless-search-parameter-manager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/search-status/headless-search-status.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/smart-snippet/headless-smart-snippet.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/smart-snippet-questions-list/headless-smart-snippet-questions-list.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/sort/headless-sort.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/standalone-search-box/headless-standalone-search-box.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/static-filter/headless-static-filter.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/tab/headless-tab.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/tab-manager/headless-tab-manager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/triggers/headless-execute-trigger.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/triggers/headless-notify-trigger.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/triggers/headless-query-trigger.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/triggers/headless-redirection-trigger.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/controllers/url-manager/headless-url-manager.ssr.d.ts +1 -1
- package/dist/definitions/ssr-next/search/engine/search-engine.ssr.d.ts +6 -13
- package/dist/definitions/ssr-next/search/types/build.d.ts +12 -0
- package/dist/definitions/ssr-next/search/types/controller-definition.d.ts +28 -0
- package/dist/definitions/ssr-next/{common/types/inference.d.ts → search/types/controller-inference.d.ts} +3 -6
- package/dist/definitions/ssr-next/search/types/engine.d.ts +52 -0
- package/dist/definitions/ssr-next/{common → search}/types/fetch-static-state.d.ts +5 -4
- package/dist/definitions/ssr-next/{common → search}/types/hydrate-static-state.d.ts +5 -6
- package/dist/definitions/ssr-next.index.d.ts +6 -4
- package/dist/definitions/test/mock-ssr-controller-definitions.d.ts +13 -1
- package/dist/esm/ssr-next/commerce/controller-utils.js +0 -6
- package/dist/esm/ssr-next/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.js +1 -4
- package/dist/esm/ssr-next/commerce/controllers/generator/headless-commerce-facet-generator.ssr.js +1 -4
- package/dist/esm/ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.js +0 -2
- package/dist/esm/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js +1 -4
- package/dist/esm/ssr-next/commerce/controllers/product-list/headless-product-list.ssr.js +1 -4
- package/dist/esm/ssr-next/commerce/controllers/recommendations/headless-recommendations.ssr.js +1 -1
- package/dist/esm/ssr-next/commerce/controllers/sort/headless-core-commerce-sort.ssr.js +0 -2
- package/dist/esm/ssr-next/commerce/controllers/summary/headless-core-summary.ssr.js +1 -4
- package/dist/esm/ssr-next/commerce/factories/build-factory.js +4 -9
- package/dist/esm/ssr-next/commerce/factories/hydrated-state-factory.js +2 -4
- package/dist/esm/ssr-next/commerce/factories/recommendation-hydrated-state-factory.js +2 -4
- package/dist/esm/ssr-next/commerce/factories/recommendation-static-state-factory.js +7 -11
- package/dist/esm/ssr-next/commerce/factories/static-state-factory.js +5 -2
- package/dist/esm/ssr-next/commerce/utils/controller-wiring.js +161 -3
- package/dist/esm/ssr-next/commerce/utils/engine-wiring.js +9 -3
- package/dist/esm/ssr-next/commerce/utils/recommendation-filter.js +27 -8
- package/dist/esm/ssr-next/{common → search}/controller-utils.js +2 -2
- package/dist/esm/ssr-next/search/engine/search-engine.ssr.js +1 -1
- package/dist/esm/ssr-next/search/types/engine.js +1 -0
- package/dist/esm/ssr-next/search/types/fetch-static-state.js +1 -0
- package/dist/esm/ssr-next/search/types/hydrate-static-state.js +1 -0
- package/dist/esm/test/mock-ssr-controller-definitions.js +15 -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
- package/dist/definitions/ssr-next/common/types/build.d.ts +0 -12
- /package/dist/esm/ssr-next/common/types/{build.js → controller-inference.js} +0 -0
- /package/dist/esm/ssr-next/{common/types/fetch-static-state.js → search/types/build.js} +0 -0
- /package/dist/esm/ssr-next/{common/types/hydrate-static-state.js → search/types/controller-definition.js} +0 -0
- /package/dist/esm/ssr-next/{common/types/inference.js → search/types/controller-inference.js} +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { CoreEngine, CoreEngineNext } from '../../../app/engine.js';
|
|
3
|
-
import type { ControllersMap, ControllersPropsMap } from '
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
3
|
+
import type { ControllersMap, ControllersPropsMap } from '../../common/types/controllers.js';
|
|
4
|
+
import type { OptionsTuple } from '../../common/types/utilities.js';
|
|
5
|
+
import type { SearchEngineDefinitionBuildResult, SearchEngineDefinitionControllersPropsOption } from './engine.js';
|
|
6
|
+
export type HydratedState<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap> = SearchEngineDefinitionBuildResult<TEngine, TControllers>;
|
|
6
7
|
interface HydrateStaticStateOptions<TSearchAction> {
|
|
7
8
|
searchAction: TSearchAction;
|
|
8
9
|
}
|
|
9
|
-
export interface HydratedState<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap> extends EngineDefinitionBuildResult<TEngine, TControllers> {
|
|
10
|
-
}
|
|
11
10
|
/**
|
|
12
11
|
* Creates a new engine from the snapshot of the engine created in SSR with fetchStaticState.
|
|
13
12
|
*
|
|
14
13
|
* Useful when hydrating a server-side-rendered engine.
|
|
15
14
|
*/
|
|
16
|
-
export type HydrateStaticState<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<HydrateStaticStateOptions<TSearchAction> &
|
|
15
|
+
export type HydrateStaticState<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllersMap, TSearchAction extends UnknownAction, TControllersProps extends ControllersPropsMap> = (...params: OptionsTuple<HydrateStaticStateOptions<TSearchAction> & SearchEngineDefinitionControllersPropsOption<TControllersProps>>) => Promise<HydratedState<TEngine, TControllers>>;
|
|
17
16
|
export {};
|
|
@@ -58,9 +58,6 @@ export { getSampleSearchEngineConfiguration } from './app/search-engine/search-e
|
|
|
58
58
|
export type { ErrorPayload } from './controllers/controller/error-payload.js';
|
|
59
59
|
export type { Controller, Subscribable, } from './controllers/controller/headless-controller.js';
|
|
60
60
|
export type { InlineLink } from './controllers/smart-snippet/headless-smart-snippet-interactive-inline-links.js';
|
|
61
|
-
export type { ControllerDefinitionsMap, ControllerDefinitionWithoutProps, ControllerDefinitionWithProps, } from './ssr-next/common/types/controllers.js';
|
|
62
|
-
export type { EngineDefinition, InferHydratedState, InferStaticState, } from './ssr-next/common/types/engine.js';
|
|
63
|
-
export type { InferControllerFromDefinition, InferControllerStaticStateFromController, InferControllerStaticStateMapFromControllers, InferControllerStaticStateMapFromDefinitions, InferControllersMapFromDefinition, } from './ssr-next/common/types/inference.js';
|
|
64
61
|
export type { AutomaticFacetBreadcrumb, Breadcrumb, BreadcrumbManager, BreadcrumbManagerDefinition, BreadcrumbManagerState, BreadcrumbValue, CategoryFacetBreadcrumb, CoreBreadcrumbManager, CoreBreadcrumbManagerState, DateFacetBreadcrumb, DeselectableValue, FacetBreadcrumb, NumericFacetBreadcrumb, StaticFilterBreadcrumb, } from './ssr-next/search/controllers/breadcrumb-manager/headless-breadcrumb-manager.ssr.js';
|
|
65
62
|
export { defineBreadcrumbManager } from './ssr-next/search/controllers/breadcrumb-manager/headless-breadcrumb-manager.ssr.js';
|
|
66
63
|
export type { Context, ContextDefinition, ContextInitialState, ContextPayload, ContextProps, ContextState, ContextValue, } from './ssr-next/search/controllers/context/headless-context.ssr.js';
|
|
@@ -143,8 +140,13 @@ export type { RedirectionTrigger, RedirectionTriggerDefinition, RedirectionTrigg
|
|
|
143
140
|
export { defineRedirectionTrigger } from './ssr-next/search/controllers/triggers/headless-redirection-trigger.ssr.js';
|
|
144
141
|
export type { UrlManager, UrlManagerBuildProps, UrlManagerInitialState, UrlManagerProps, UrlManagerState, } from './ssr-next/search/controllers/url-manager/headless-url-manager.ssr.js';
|
|
145
142
|
export { defineUrlManager } from './ssr-next/search/controllers/url-manager/headless-url-manager.ssr.js';
|
|
146
|
-
export type { SearchCompletedAction,
|
|
143
|
+
export type { SearchCompletedAction, SSRSearchEngine as SearchEngine, } from './ssr-next/search/engine/search-engine.ssr.js';
|
|
147
144
|
export { defineSearchEngine } from './ssr-next/search/engine/search-engine.ssr.js';
|
|
145
|
+
export type { ControllerDefinitionsMap, InferControllerStaticStateFromController, InferControllerStaticStateMapFromControllers, InferHydratedState, InferStaticState, } from './ssr-next/search/types/controller-definition.js';
|
|
146
|
+
export type { InferControllerFromDefinition, InferControllerStaticStateMapFromDefinitions, InferControllersMapFromDefinition, } from './ssr-next/search/types/controller-inference.js';
|
|
147
|
+
export type { SearchEngineDefinition, SearchEngineDefinitionOptions, } from './ssr-next/search/types/engine.js';
|
|
148
|
+
export type { FetchStaticState } from './ssr-next/search/types/fetch-static-state.js';
|
|
149
|
+
export type { HydratedState, HydrateStaticState, } from './ssr-next/search/types/hydrate-static-state.js';
|
|
148
150
|
export type { SearchAppState, SearchParametersState, } from './state/search-app-state.js';
|
|
149
151
|
export { getAnalyticsNextApiBaseUrl, getOrganizationEndpoint, } from './api/platform-client.js';
|
|
150
152
|
export type { RelativeDate, RelativeDatePeriod, RelativeDateUnit, } from './api/search/date/relative-date.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { SearchEngine } from '../app/search-engine/search-engine.js';
|
|
2
2
|
import type { Controller } from '../controllers/controller/headless-controller.js';
|
|
3
3
|
import type { Kind } from '../ssr/commerce/types/kind.js';
|
|
4
|
-
import type { ControllerDefinitionWithoutProps, ControllerDefinitionWithProps } from '../ssr
|
|
4
|
+
import type { ControllerDefinitionWithoutProps, ControllerDefinitionWithProps } from '../ssr/common/types/controllers.js';
|
|
5
|
+
import { recommendationInternalOptionKey } from '../ssr-next/commerce/types/controller-constants.js';
|
|
5
6
|
interface MockController {
|
|
6
7
|
initialState?: Record<string, unknown>;
|
|
7
8
|
}
|
|
@@ -35,4 +36,15 @@ export declare function defineMockCommerceControllerWithProps(options?: Solution
|
|
|
35
36
|
standalone: boolean;
|
|
36
37
|
recommendation: boolean;
|
|
37
38
|
};
|
|
39
|
+
export declare function defineMockRecommendationDefinition(slotId: string): {
|
|
40
|
+
recommendation: boolean;
|
|
41
|
+
[recommendationInternalOptionKey]: {
|
|
42
|
+
slotId: string;
|
|
43
|
+
};
|
|
44
|
+
buildWithProps: import("vitest").Mock<(engine: any, props: any) => {
|
|
45
|
+
state: {};
|
|
46
|
+
subscribe(listener: () => void): import("redux").Unsubscribe;
|
|
47
|
+
_kind: Kind;
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
38
50
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { clone, filterObject, mapObject } from '../../utils/utils.js';
|
|
2
2
|
import { ControllerBuilder } from '../common/builders/controller-builder.js';
|
|
3
3
|
import { createStaticControllerBuilder } from '../common/builders/static-controller-builder.js';
|
|
4
|
-
import { InvalidControllerDefinition } from '../common/errors.js';
|
|
5
4
|
export function createStaticState({ searchActions, controllers, }) {
|
|
6
5
|
return {
|
|
7
6
|
controllers: mapObject(controllers, (controller) => createStaticControllerBuilder(controller).build()),
|
|
@@ -23,8 +22,3 @@ export function buildControllerDefinitions({ definitionsMap, engine, solutionTyp
|
|
|
23
22
|
});
|
|
24
23
|
return filterObject(controllerMap, (value) => value !== null);
|
|
25
24
|
}
|
|
26
|
-
export function ensureAtLeastOneSolutionType(options) {
|
|
27
|
-
if (options?.listing === false && options?.search === false) {
|
|
28
|
-
throw new InvalidControllerDefinition();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildProductListing } from '../../../../controllers/commerce/product-listing/headless-product-listing.js';
|
|
2
2
|
import { buildSearch } from '../../../../controllers/commerce/search/headless-search.js';
|
|
3
|
-
import { ensureAtLeastOneSolutionType } from '../../../../ssr/commerce/controller-utils.js';
|
|
4
3
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
5
4
|
/**
|
|
6
5
|
* Defines a `BreadcrumbManager` controller instance.
|
|
@@ -8,12 +7,10 @@ import { SolutionType } from '../../types/controller-constants.js';
|
|
|
8
7
|
*
|
|
9
8
|
* @returns The `BreadcrumbManager` controller definition.
|
|
10
9
|
*/
|
|
11
|
-
export function defineBreadcrumbManager(
|
|
12
|
-
ensureAtLeastOneSolutionType(options);
|
|
10
|
+
export function defineBreadcrumbManager() {
|
|
13
11
|
return {
|
|
14
12
|
listing: true,
|
|
15
13
|
search: true,
|
|
16
|
-
...options,
|
|
17
14
|
build: (engine, solutionType) => solutionType === SolutionType.listing
|
|
18
15
|
? buildProductListing(engine).breadcrumbManager()
|
|
19
16
|
: buildSearch(engine).breadcrumbManager(),
|
package/dist/esm/ssr-next/commerce/controllers/generator/headless-commerce-facet-generator.ssr.js
CHANGED
|
@@ -14,18 +14,15 @@ import { manualNumericFacetSelector } from '../../../../features/commerce/facets
|
|
|
14
14
|
import { manualNumericFacetReducer as manualNumericFacetSet } from '../../../../features/commerce/facets/numeric-facet/manual-numeric-facet-slice.js';
|
|
15
15
|
import { categoryFacetSearchStateSelector } from '../../../../features/facets/facet-search-set/category/category-facet-search-state-selector.js';
|
|
16
16
|
import { specificFacetSearchStateSelector } from '../../../../features/facets/facet-search-set/specific/specific-facet-search-state-selector.js';
|
|
17
|
-
import { ensureAtLeastOneSolutionType } from '../../../../ssr/commerce/controller-utils.js';
|
|
18
17
|
import { loadReducerError } from '../../../../utils/errors.js';
|
|
19
18
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
20
19
|
/**
|
|
21
20
|
* @group Definers
|
|
22
21
|
*/
|
|
23
|
-
export function defineFacetGenerator(
|
|
24
|
-
ensureAtLeastOneSolutionType(options);
|
|
22
|
+
export function defineFacetGenerator() {
|
|
25
23
|
return {
|
|
26
24
|
listing: true,
|
|
27
25
|
search: true,
|
|
28
|
-
...options,
|
|
29
26
|
build: (engine, solutionType) => buildFacetGenerator(engine, { props: { solutionType: solutionType } }),
|
|
30
27
|
};
|
|
31
28
|
}
|
package/dist/esm/ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildProductListing } from '../../../../controllers/commerce/product-listing/headless-product-listing.js';
|
|
2
2
|
import { buildSearch } from '../../../../controllers/commerce/search/headless-search.js';
|
|
3
|
-
import { ensureAtLeastOneSolutionType } from '../../../../ssr/commerce/controller-utils.js';
|
|
4
3
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
5
4
|
/**
|
|
6
5
|
* Defines a `Pagination` controller instance.
|
|
@@ -10,7 +9,6 @@ import { SolutionType } from '../../types/controller-constants.js';
|
|
|
10
9
|
* @returns The `Pagination` controller definition.
|
|
11
10
|
*/
|
|
12
11
|
export function definePagination(props) {
|
|
13
|
-
ensureAtLeastOneSolutionType(props);
|
|
14
12
|
return {
|
|
15
13
|
listing: true,
|
|
16
14
|
search: true,
|
|
@@ -8,7 +8,6 @@ import { queryReducer as query } from '../../../../features/commerce/query/query
|
|
|
8
8
|
import { sortReducer as commerceSort } from '../../../../features/commerce/sort/sort-slice.js';
|
|
9
9
|
import { facetOrderReducer as facetOrder } from '../../../../features/facets/facet-order/facet-order-slice.js';
|
|
10
10
|
import { querySetReducer as querySet } from '../../../../features/query-set/query-set-slice.js';
|
|
11
|
-
import { ensureAtLeastOneSolutionType } from '../../../../ssr/commerce/controller-utils.js';
|
|
12
11
|
import { loadReducerError } from '../../../../utils/errors.js';
|
|
13
12
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
14
13
|
import { createControllerWithKind, Kind } from '../../types/kind.js';
|
|
@@ -18,12 +17,10 @@ import { createControllerWithKind, Kind } from '../../types/kind.js';
|
|
|
18
17
|
*
|
|
19
18
|
* @returns The `ParameterManager` controller definition.
|
|
20
19
|
*/
|
|
21
|
-
export function defineParameterManager(
|
|
22
|
-
ensureAtLeastOneSolutionType(options);
|
|
20
|
+
export function defineParameterManager() {
|
|
23
21
|
return {
|
|
24
22
|
listing: true,
|
|
25
23
|
search: true,
|
|
26
|
-
...options,
|
|
27
24
|
buildWithProps: (engine, props, solutionType) => {
|
|
28
25
|
if (solutionType === SolutionType.listing) {
|
|
29
26
|
if (!loadCommerceProductListingParameterReducers(engine)) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildProductListing, } from '../../../../controllers/commerce/product-listing/headless-product-listing.js';
|
|
2
2
|
import { buildSearch, } from '../../../../controllers/commerce/search/headless-search.js';
|
|
3
|
-
import { ensureAtLeastOneSolutionType } from '../../controller-utils.js';
|
|
4
3
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
5
4
|
/**
|
|
6
5
|
* Defines a `ProductList` controller instance.
|
|
@@ -8,12 +7,10 @@ import { SolutionType } from '../../types/controller-constants.js';
|
|
|
8
7
|
*
|
|
9
8
|
* @returns The `ProductList` controller definition.
|
|
10
9
|
*/
|
|
11
|
-
export function defineProductList(
|
|
12
|
-
ensureAtLeastOneSolutionType(options);
|
|
10
|
+
export function defineProductList() {
|
|
13
11
|
return {
|
|
14
12
|
listing: true,
|
|
15
13
|
search: true,
|
|
16
|
-
...options,
|
|
17
14
|
build: (engine, solutionType) => solutionType === SolutionType.listing
|
|
18
15
|
? buildProductListing(engine)
|
|
19
16
|
: buildSearch(engine),
|
package/dist/esm/ssr-next/commerce/controllers/recommendations/headless-recommendations.ssr.js
CHANGED
|
@@ -17,7 +17,7 @@ export function defineRecommendations(props) {
|
|
|
17
17
|
buildWithProps: (engine, options) => {
|
|
18
18
|
const staticOptions = props.options;
|
|
19
19
|
const controller = buildRecommendations(engine, {
|
|
20
|
-
options: { ...staticOptions, ...options },
|
|
20
|
+
options: { ...staticOptions, ...options.initialState },
|
|
21
21
|
});
|
|
22
22
|
return createControllerWithKind(controller, Kind.Recommendations);
|
|
23
23
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildProductListing } from '../../../../controllers/commerce/product-listing/headless-product-listing.js';
|
|
2
2
|
import { buildSearch } from '../../../../controllers/commerce/search/headless-search.js';
|
|
3
|
-
import { ensureAtLeastOneSolutionType } from '../../../../ssr/commerce/controller-utils.js';
|
|
4
3
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
5
4
|
/**
|
|
6
5
|
* Defines a `Sort` controller instance.
|
|
@@ -10,7 +9,6 @@ import { SolutionType } from '../../types/controller-constants.js';
|
|
|
10
9
|
* @returns The `Sort` controller definition.
|
|
11
10
|
*/
|
|
12
11
|
export function defineSort(props) {
|
|
13
|
-
ensureAtLeastOneSolutionType(props);
|
|
14
12
|
return {
|
|
15
13
|
listing: true,
|
|
16
14
|
search: true,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildProductListing } from '../../../../controllers/commerce/product-listing/headless-product-listing.js';
|
|
2
2
|
import { buildSearch } from '../../../../controllers/commerce/search/headless-search.js';
|
|
3
|
-
import { ensureAtLeastOneSolutionType } from '../../../../ssr/commerce/controller-utils.js';
|
|
4
3
|
import { SolutionType } from '../../types/controller-constants.js';
|
|
5
4
|
/**
|
|
6
5
|
* Defines a `Summary` controller instance.
|
|
@@ -8,12 +7,10 @@ import { SolutionType } from '../../types/controller-constants.js';
|
|
|
8
7
|
*
|
|
9
8
|
* @returns The `Summary` controller definition.
|
|
10
9
|
*/
|
|
11
|
-
export function defineSummary(
|
|
12
|
-
ensureAtLeastOneSolutionType(options);
|
|
10
|
+
export function defineSummary() {
|
|
13
11
|
return {
|
|
14
12
|
listing: true,
|
|
15
13
|
search: true,
|
|
16
|
-
...options,
|
|
17
14
|
build: (engine, solutionType) => solutionType === SolutionType.listing
|
|
18
15
|
? buildProductListing(engine).summary()
|
|
19
16
|
: buildSearch(engine).summary(),
|
|
@@ -57,21 +57,16 @@ function buildSSRCommerceEngine(solutionType, options, recommendationCount) {
|
|
|
57
57
|
},
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
function fetchActiveRecommendationControllers(controllerProps, solutionType) {
|
|
61
|
-
return solutionType === SolutionType.recommendation
|
|
62
|
-
? Object.values(controllerProps).filter((controller) => controller &&
|
|
63
|
-
typeof controller === 'object' &&
|
|
64
|
-
'enabled' in controller &&
|
|
65
|
-
controller.enabled).length
|
|
66
|
-
: 0;
|
|
67
|
-
}
|
|
68
60
|
export const buildFactory = (controllerDefinitions, options) => (solutionType) => async (...[buildOptions]) => {
|
|
69
61
|
const controllerProps = wireControllerParams(solutionType, controllerDefinitions, buildOptions); // TODO: KIT-4754: remove non-null assertion operator
|
|
70
62
|
const logger = buildLogger(options.loggerOptions);
|
|
71
63
|
if (!options.navigatorContextProvider) {
|
|
72
64
|
logger.warn('[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()');
|
|
73
65
|
}
|
|
74
|
-
const enabledRecommendationControllers =
|
|
66
|
+
const enabledRecommendationControllers = buildOptions && 'recommendations' in buildOptions // TODO: KIT-4754: remove non-null assertion
|
|
67
|
+
? buildOptions
|
|
68
|
+
?.recommendations.length
|
|
69
|
+
: 0;
|
|
75
70
|
const engineOptions = {
|
|
76
71
|
...options,
|
|
77
72
|
configuration: extendEngineConfiguration(options.configuration, buildOptions), // TODO: KIT-4754: remove non-null assertion operator
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { buildFactory
|
|
1
|
+
import { buildFactory } from './build-factory.js';
|
|
2
2
|
export function hydratedStaticStateFactory(controllerDefinitions, options) {
|
|
3
3
|
return (solutionType) => async (...params) => {
|
|
4
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);
|
|
5
|
+
const { engine, controllers } = await solutionTypeBuild(...params);
|
|
8
6
|
params[0].searchActions.forEach((action) => {
|
|
9
7
|
engine.dispatch(action);
|
|
10
8
|
});
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { SolutionType } from '../types/controller-constants.js';
|
|
2
|
-
import { buildFactory
|
|
2
|
+
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(
|
|
7
|
-
// @ts-expect-error: TODO: KIT-4742: the wiring will fix also the type inconsistencies
|
|
8
|
-
...params));
|
|
6
|
+
const { engine, controllers } = (await solutionTypeBuild(...params));
|
|
9
7
|
params[0].searchActions.forEach((action) => {
|
|
10
8
|
engine.dispatch(action);
|
|
11
9
|
});
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { filterObject } from '../../../utils/utils.js';
|
|
2
1
|
import { createStaticState } from '../controller-utils.js';
|
|
3
2
|
import { SolutionType } from '../types/controller-constants.js';
|
|
4
3
|
import { filterRecommendationControllers } from '../utils/recommendation-filter.js';
|
|
5
|
-
import { buildFactory
|
|
4
|
+
import { buildFactory } from './build-factory.js';
|
|
6
5
|
export function fetchRecommendationStaticStateFactory(controllerDefinitions, options) {
|
|
7
|
-
const getAllowedRecommendationKeys = (props) => {
|
|
8
|
-
if (props && 'controllers' in props) {
|
|
9
|
-
const enabledRecommendationControllers = filterObject(props.controllers, (value) => Boolean(value.enabled));
|
|
10
|
-
return Object.keys(enabledRecommendationControllers);
|
|
11
|
-
}
|
|
12
|
-
return [];
|
|
13
|
-
};
|
|
14
6
|
return async (...params) => {
|
|
15
7
|
const [props] = params;
|
|
16
|
-
const allowedRecommendationKeys =
|
|
8
|
+
const allowedRecommendationKeys = props.recommendations;
|
|
17
9
|
const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(SolutionType.recommendation);
|
|
18
10
|
const { engine, controllers } = (await solutionTypeBuild(...params));
|
|
19
11
|
filterRecommendationControllers(controllers, controllerDefinitions ?? {}).refresh(allowedRecommendationKeys);
|
|
20
12
|
const searchActions = await Promise.all(engine.waitForRequestCompletedAction());
|
|
21
|
-
|
|
13
|
+
const staticState = createStaticState({
|
|
22
14
|
searchActions,
|
|
23
15
|
controllers,
|
|
24
16
|
});
|
|
17
|
+
return {
|
|
18
|
+
...params[0], // TODO: KIT-4754: remove index access after no longer relying on OptionTuple type
|
|
19
|
+
...staticState,
|
|
20
|
+
};
|
|
25
21
|
};
|
|
26
22
|
}
|
|
@@ -3,7 +3,7 @@ import { buildSearch } from '../../../controllers/commerce/search/headless-searc
|
|
|
3
3
|
import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
|
|
4
4
|
import { createStaticState } from '../controller-utils.js';
|
|
5
5
|
import { SolutionType } from '../types/controller-constants.js';
|
|
6
|
-
import { buildFactory
|
|
6
|
+
import { buildFactory } from './build-factory.js';
|
|
7
7
|
export function fetchStaticStateFactory(controllerDefinitions, options) {
|
|
8
8
|
return (solutionType) => async (...params) => {
|
|
9
9
|
const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(solutionType);
|
|
@@ -27,6 +27,9 @@ export function fetchStaticStateFactory(controllerDefinitions, options) {
|
|
|
27
27
|
searchActions,
|
|
28
28
|
controllers,
|
|
29
29
|
});
|
|
30
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
...params[0], // TODO: KIT-4754: remove index access after no longer relying on OptionTuple type
|
|
32
|
+
...staticState,
|
|
33
|
+
};
|
|
31
34
|
};
|
|
32
35
|
}
|
|
@@ -1,4 +1,162 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ArrayValue, RecordValue, Schema, StringValue } from '@coveo/bueno';
|
|
2
|
+
import { contextDefinition } from '../../../features/commerce/context/context-validation.js';
|
|
3
|
+
import { parametersDefinition } from '../../../features/commerce/parameters/parameters-schema.js';
|
|
4
|
+
import { nonEmptyString, requiredEmptyAllowedString, } from '../../../utils/validate-payload.js';
|
|
5
|
+
import { SolutionType } from '../types/controller-constants.js';
|
|
6
|
+
import { getRecommendationDefinitions, isRecommendationDefinition, } from './recommendation-filter.js';
|
|
7
|
+
const requiredDefinition = {
|
|
8
|
+
context: new RecordValue({
|
|
9
|
+
options: { required: true },
|
|
10
|
+
values: contextDefinition,
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
const listingDefinition = {
|
|
14
|
+
...requiredDefinition,
|
|
15
|
+
searchParams: new RecordValue({
|
|
16
|
+
values: parametersDefinition,
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
const standaloneDefinition = {
|
|
20
|
+
...requiredDefinition,
|
|
21
|
+
};
|
|
22
|
+
const searchDefinition = {
|
|
23
|
+
...requiredDefinition,
|
|
24
|
+
searchParams: new RecordValue({
|
|
25
|
+
options: { required: true },
|
|
26
|
+
values: { query: requiredEmptyAllowedString, ...parametersDefinition },
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
const recommendationsDefinition = (recommendationName) => ({
|
|
30
|
+
...requiredDefinition,
|
|
31
|
+
recommendations: new ArrayValue({
|
|
32
|
+
each: new StringValue({
|
|
33
|
+
required: true,
|
|
34
|
+
constrainTo: recommendationName,
|
|
35
|
+
emptyAllowed: false,
|
|
36
|
+
}),
|
|
37
|
+
required: true,
|
|
38
|
+
}),
|
|
39
|
+
productId: nonEmptyString,
|
|
40
|
+
});
|
|
41
|
+
export const listingDefinitionSchema = new Schema(listingDefinition);
|
|
42
|
+
export const searchDefinitionSchema = new Schema(searchDefinition);
|
|
43
|
+
export const standaloneDefinitionSchema = new Schema(standaloneDefinition);
|
|
44
|
+
export const recommendationsDefinitionSchema = (recommendationName) => new Schema(recommendationsDefinition(recommendationName));
|
|
45
|
+
/**
|
|
46
|
+
* Validates the build configuration based on the solution type.
|
|
47
|
+
*/
|
|
48
|
+
function validateBuildConfig(solutionType, controllerDefinitions, buildConfig) {
|
|
49
|
+
const validationMap = {
|
|
50
|
+
[SolutionType.listing]: listingDefinitionSchema,
|
|
51
|
+
[SolutionType.search]: searchDefinitionSchema,
|
|
52
|
+
[SolutionType.standalone]: standaloneDefinitionSchema,
|
|
53
|
+
[SolutionType.recommendation]: recommendationsDefinitionSchema(Object.keys(getRecommendationDefinitions(controllerDefinitions))),
|
|
54
|
+
};
|
|
55
|
+
const schema = validationMap[solutionType];
|
|
56
|
+
schema.validate(buildConfig);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Controller wiring class that handles the complete wiring process.
|
|
60
|
+
* Transforms simple user configuration into complex internal controller structures.
|
|
61
|
+
*/
|
|
62
|
+
class ControllerWirer {
|
|
63
|
+
buildConfig;
|
|
64
|
+
controllerDefinitions;
|
|
65
|
+
controllerProps;
|
|
66
|
+
constructor(buildConfig, controllerDefinitions, controllerProps) {
|
|
67
|
+
this.buildConfig = buildConfig;
|
|
68
|
+
this.controllerDefinitions = controllerDefinitions;
|
|
69
|
+
this.controllerProps = controllerProps;
|
|
70
|
+
}
|
|
71
|
+
wireParameterManager() {
|
|
72
|
+
if (!this.controllerDefinitions?.parameterManager)
|
|
73
|
+
return;
|
|
74
|
+
const { searchParams } = this.buildConfig;
|
|
75
|
+
const { query, ...rest } = searchParams || {};
|
|
76
|
+
const parameters = {
|
|
77
|
+
...(query && { q: query }),
|
|
78
|
+
...(rest && typeof rest === 'object' ? rest : {}),
|
|
79
|
+
};
|
|
80
|
+
this.controllerProps.parameterManager = {
|
|
81
|
+
initialState: { parameters },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
wireContext() {
|
|
85
|
+
if (!this.controllerDefinitions?.context)
|
|
86
|
+
return;
|
|
87
|
+
const { context } = this.buildConfig;
|
|
88
|
+
this.controllerProps.context = {
|
|
89
|
+
initialState: {
|
|
90
|
+
...context,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
wireCart() {
|
|
95
|
+
if (!this.controllerDefinitions?.cart || !this.buildConfig.cart)
|
|
96
|
+
return;
|
|
97
|
+
this.controllerProps.cart = {
|
|
98
|
+
initialState: this.buildConfig.cart,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
wireRecommendations() {
|
|
102
|
+
if (!('recommendations' in this.buildConfig)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const recController in this.controllerDefinitions) {
|
|
106
|
+
if (isRecommendationDefinition(this.controllerDefinitions[recController])) {
|
|
107
|
+
this.controllerProps[recController] = {
|
|
108
|
+
initialState: {
|
|
109
|
+
...('productId' in this.buildConfig && {
|
|
110
|
+
productId: this.buildConfig.productId,
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Wires all controllers based on solution type and controller definitions.
|
|
119
|
+
* Handles the complete wiring process in a sequential manner.
|
|
120
|
+
*/
|
|
121
|
+
wire(solutionType) {
|
|
122
|
+
// Wire common controllers that apply to all solution types
|
|
123
|
+
this.wireCart();
|
|
124
|
+
this.wireContext();
|
|
125
|
+
// Wire solution-specific controllers
|
|
126
|
+
switch (solutionType) {
|
|
127
|
+
case SolutionType.search:
|
|
128
|
+
case SolutionType.listing: {
|
|
129
|
+
this.wireParameterManager();
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case SolutionType.recommendation: {
|
|
133
|
+
this.wireRecommendations();
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case SolutionType.standalone:
|
|
137
|
+
// No additional wiring needed for standalone
|
|
138
|
+
break;
|
|
139
|
+
default: {
|
|
140
|
+
// Exhaustive check - TypeScript will error if we miss a case
|
|
141
|
+
const _exhaustiveCheck = solutionType;
|
|
142
|
+
throw new Error(`Unsupported solution type: ${_exhaustiveCheck}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Converts simple user configuration (URL, language, currency, query) into the
|
|
149
|
+
* nested structure required by the internal {@link Build} method. Automatically generates
|
|
150
|
+
* appropriate controllers (context, cart, parameterManager) transparently.
|
|
151
|
+
*
|
|
152
|
+
* @param solutionType - The type of solution (search, listing, recommendation, standalone)
|
|
153
|
+
* @param controllerDefinitions - Map of controller definitions to be initialized
|
|
154
|
+
* @param buildConfig - Simple configuration object with simplified controller properties
|
|
155
|
+
* @returns Formatted and validated controller properties map defined for the controller in the definition
|
|
156
|
+
*/
|
|
157
|
+
export function wireControllerParams(solutionType, controllerDefinitions, buildConfig) {
|
|
158
|
+
validateBuildConfig(solutionType, controllerDefinitions, buildConfig);
|
|
159
|
+
const controllerProps = buildConfig.controllers ?? {};
|
|
160
|
+
new ControllerWirer(buildConfig, controllerDefinitions, controllerProps).wire(solutionType);
|
|
161
|
+
return controllerProps;
|
|
4
162
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export function extendEngineConfiguration(
|
|
2
|
-
|
|
3
|
-
return {
|
|
1
|
+
export function extendEngineConfiguration(configuration, commonBuildOptions) {
|
|
2
|
+
const { cart, context } = commonBuildOptions;
|
|
3
|
+
return {
|
|
4
|
+
...configuration,
|
|
5
|
+
context: {
|
|
6
|
+
...context,
|
|
7
|
+
},
|
|
8
|
+
cart,
|
|
9
|
+
};
|
|
4
10
|
}
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import { MultipleRecommendationError } from '../../common/errors.js';
|
|
2
2
|
import { recommendationInternalOptionKey } from '../types/controller-constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a controller definition is a recommendation controller.
|
|
5
|
+
* A recommendation controller must have both the recommendation flag and a slotId.
|
|
6
|
+
*/
|
|
7
|
+
export function isRecommendationDefinition(controllerDefinition) {
|
|
8
|
+
const hasRecommendationFlag = 'recommendation' in controllerDefinition &&
|
|
9
|
+
controllerDefinition.recommendation === true;
|
|
10
|
+
const hasValidSlotId = recommendationInternalOptionKey in controllerDefinition &&
|
|
11
|
+
'slotId' in
|
|
12
|
+
controllerDefinition[recommendationInternalOptionKey];
|
|
13
|
+
return hasRecommendationFlag && hasValidSlotId;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extracts recommendation controller definitions from a controller definitions map.
|
|
17
|
+
*
|
|
18
|
+
* @param controllerDefinitions - Map of controller definitions
|
|
19
|
+
* @returns Object containing only the recommendation controller definitions
|
|
20
|
+
*/
|
|
21
|
+
export function getRecommendationDefinitions(controllerDefinitions) {
|
|
22
|
+
const recommendationMap = {};
|
|
23
|
+
for (const [name, definition] of Object.entries(controllerDefinitions)) {
|
|
24
|
+
if (isRecommendationDefinition(definition)) {
|
|
25
|
+
recommendationMap[name] = definition;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return recommendationMap;
|
|
29
|
+
}
|
|
3
30
|
export function filterRecommendationControllers(controllers, controllerDefinitions) {
|
|
4
31
|
const slotIdSet = new Set();
|
|
5
|
-
const isRecommendationDefinition = (controllerDefinition) => {
|
|
6
|
-
const isControllerRecommendation = 'recommendation' in controllerDefinition &&
|
|
7
|
-
controllerDefinition.recommendation === true;
|
|
8
|
-
const hasSlotId = recommendationInternalOptionKey in controllerDefinition &&
|
|
9
|
-
'slotId' in
|
|
10
|
-
controllerDefinition[recommendationInternalOptionKey];
|
|
11
|
-
return isControllerRecommendation && hasSlotId;
|
|
12
|
-
};
|
|
13
32
|
const ensureSingleRecommendationPerSlot = (slotId) => {
|
|
14
33
|
throw new MultipleRecommendationError(slotId);
|
|
15
34
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clone, mapObject } from '../../utils/utils.js';
|
|
2
|
-
import { ControllerBuilder } from '
|
|
3
|
-
import { createStaticControllerBuilder } from '
|
|
2
|
+
import { ControllerBuilder } from '../common/builders/controller-builder.js';
|
|
3
|
+
import { createStaticControllerBuilder } from '../common/builders/static-controller-builder.js';
|
|
4
4
|
export function buildControllerDefinitions({ definitionsMap, engine, propsMap, }) {
|
|
5
5
|
return mapObject(definitionsMap, (definition, key) => {
|
|
6
6
|
const props = propsMap?.[key];
|
|
@@ -2,7 +2,7 @@ import { buildLogger } from '../../../app/logger.js';
|
|
|
2
2
|
import { buildSearchEngine, } from '../../../app/search-engine/search-engine.js';
|
|
3
3
|
import { createWaitForActionMiddleware } from '../../../utils/utils.js';
|
|
4
4
|
import { augmentPreprocessRequestWithForwardedFor } from '../../common/augment-preprocess-request.js';
|
|
5
|
-
import { buildControllerDefinitions, createStaticState, } from '
|
|
5
|
+
import { buildControllerDefinitions, createStaticState, } from '../controller-utils.js';
|
|
6
6
|
function isSearchCompletedAction(action) {
|
|
7
7
|
return /^search\/executeSearch\/(fulfilled|rejected)$/.test(action.type);
|
|
8
8
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { vi } from 'vitest';
|
|
2
|
+
import { recommendationInternalOptionKey } from '../ssr-next/commerce/types/controller-constants.js';
|
|
2
3
|
import { buildMockController, buildMockControllerWithInitialState, } from './mock-controller.js';
|
|
3
4
|
export function defineMockController() {
|
|
4
5
|
return {
|
|
@@ -41,3 +42,17 @@ export function defineMockCommerceControllerWithProps(options) {
|
|
|
41
42
|
recommendation: options?.recommendation ?? true,
|
|
42
43
|
};
|
|
43
44
|
}
|
|
45
|
+
export function defineMockRecommendationDefinition(slotId) {
|
|
46
|
+
return {
|
|
47
|
+
recommendation: true,
|
|
48
|
+
[recommendationInternalOptionKey]: {
|
|
49
|
+
slotId,
|
|
50
|
+
},
|
|
51
|
+
buildWithProps: vi.fn((engine, props) => ({
|
|
52
|
+
_kind: 'some-kind',
|
|
53
|
+
...buildMockControllerWithInitialState(engine, {
|
|
54
|
+
initialState: props?.initialState,
|
|
55
|
+
}),
|
|
56
|
+
})),
|
|
57
|
+
};
|
|
58
|
+
}
|