@coveo/headless 3.28.4-pre.f565c74b85 → 3.28.4-pre.fac9a879d3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/case-assist/headless.cjs +1 -1
- package/dist/cjs/commerce/headless.cjs +1 -1
- package/dist/cjs/headless.cjs +1 -1
- package/dist/cjs/insight/headless.cjs +1 -1
- package/dist/cjs/recommendation/headless.cjs +1 -1
- package/dist/cjs/ssr/headless.cjs +1 -1
- package/dist/cjs/ssr-commerce/headless.cjs +1 -1
- package/dist/cjs/ssr-commerce-next/headless.cjs +1 -1
- package/dist/cjs/ssr-next/headless.cjs +1 -1
- package/dist/definitions/ssr-commerce-next.index.d.ts +1 -1
- package/dist/definitions/ssr-next/commerce/controller-utils.d.ts +6 -7
- package/dist/definitions/ssr-next/commerce/controllers/context/headless-context.ssr.d.ts +3 -1
- package/dist/definitions/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.d.ts +2 -1
- package/dist/definitions/ssr-next/commerce/types/controller-inference.d.ts +3 -2
- package/dist/definitions/ssr-next/common/builders/controller-builder.d.ts +17 -0
- package/dist/definitions/ssr-next/common/builders/static-controller-builder.d.ts +24 -0
- package/dist/definitions/ssr-next/common/controller-utils.d.ts +6 -6
- package/dist/definitions/ssr-next/common/types/controllers.d.ts +6 -0
- package/dist/definitions/ssr-next/common/types/inference.d.ts +3 -2
- package/dist/definitions/test/mock-controller.d.ts +9 -0
- package/dist/definitions/test/mock-ssr-controller-definitions.d.ts +38 -0
- package/dist/esm/ssr-next/commerce/controller-utils.js +6 -18
- package/dist/esm/ssr-next/commerce/controllers/cart/headless-cart.ssr.js +3 -5
- package/dist/esm/ssr-next/commerce/controllers/context/headless-context.ssr.js +1 -1
- package/dist/esm/ssr-next/common/builders/controller-builder.js +38 -0
- package/dist/esm/ssr-next/common/builders/static-controller-builder.js +46 -0
- package/dist/esm/ssr-next/common/controller-utils.js +7 -13
- package/dist/esm/test/mock-controller.js +13 -0
- package/dist/esm/test/mock-ssr-controller-definitions.js +43 -0
- package/dist/esm/utils/version.js +1 -1
- package/dist/quantic/case-assist/headless.js +1 -1
- package/dist/quantic/commerce/headless.js +1 -1
- package/dist/quantic/headless.js +1 -1
- package/dist/quantic/insight/headless.js +1 -1
- package/dist/quantic/recommendation/headless.js +1 -1
- package/package.json +1 -1
|
@@ -800,7 +800,7 @@ var import_bueno5 = require("@coveo/bueno");
|
|
|
800
800
|
var import_toolkit7 = require("@reduxjs/toolkit");
|
|
801
801
|
|
|
802
802
|
// src/utils/version.ts
|
|
803
|
-
var VERSION = "3.28.4-pre.
|
|
803
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
804
804
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
805
805
|
|
|
806
806
|
// src/features/configuration/configuration-actions.ts
|
|
@@ -1148,7 +1148,7 @@ var import_bueno6 = require("@coveo/bueno");
|
|
|
1148
1148
|
var import_toolkit4 = require("@reduxjs/toolkit");
|
|
1149
1149
|
|
|
1150
1150
|
// src/utils/version.ts
|
|
1151
|
-
var VERSION = "3.28.4-pre.
|
|
1151
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
1152
1152
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1153
1153
|
|
|
1154
1154
|
// src/features/configuration/configuration-actions.ts
|
package/dist/cjs/headless.cjs
CHANGED
|
@@ -1374,7 +1374,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
|
|
|
1374
1374
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
1375
1375
|
|
|
1376
1376
|
// src/utils/version.ts
|
|
1377
|
-
var VERSION = "3.28.4-pre.
|
|
1377
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
1378
1378
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1379
1379
|
|
|
1380
1380
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -1278,7 +1278,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
|
|
|
1278
1278
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
1279
1279
|
|
|
1280
1280
|
// src/utils/version.ts
|
|
1281
|
-
var VERSION = "3.28.4-pre.
|
|
1281
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
1282
1282
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1283
1283
|
|
|
1284
1284
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -881,7 +881,7 @@ var validateObject = (engine, schema, obj, validationMessage, errorMessage) => {
|
|
|
881
881
|
};
|
|
882
882
|
|
|
883
883
|
// src/utils/version.ts
|
|
884
|
-
var VERSION = "3.28.4-pre.
|
|
884
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
885
885
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
886
886
|
|
|
887
887
|
// src/features/configuration/configuration-actions.ts
|
|
@@ -1306,7 +1306,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
|
|
|
1306
1306
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
1307
1307
|
|
|
1308
1308
|
// src/utils/version.ts
|
|
1309
|
-
var VERSION = "3.28.4-pre.
|
|
1309
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
1310
1310
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1311
1311
|
|
|
1312
1312
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -468,7 +468,7 @@ var import_bueno8 = require("@coveo/bueno");
|
|
|
468
468
|
var import_toolkit3 = require("@reduxjs/toolkit");
|
|
469
469
|
|
|
470
470
|
// src/utils/version.ts
|
|
471
|
-
var VERSION = "3.28.4-pre.
|
|
471
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
472
472
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
473
473
|
|
|
474
474
|
// src/features/configuration/configuration-actions.ts
|
|
@@ -468,7 +468,7 @@ var import_bueno8 = require("@coveo/bueno");
|
|
|
468
468
|
var import_toolkit3 = require("@reduxjs/toolkit");
|
|
469
469
|
|
|
470
470
|
// src/utils/version.ts
|
|
471
|
-
var VERSION = "3.28.4-pre.
|
|
471
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
472
472
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
473
473
|
|
|
474
474
|
// src/features/configuration/configuration-actions.ts
|
|
@@ -1306,7 +1306,7 @@ var import_toolkit2 = require("@reduxjs/toolkit");
|
|
|
1306
1306
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
1307
1307
|
|
|
1308
1308
|
// src/utils/version.ts
|
|
1309
|
-
var VERSION = "3.28.4-pre.
|
|
1309
|
+
var VERSION = "3.28.4-pre.fac9a879d3";
|
|
1310
1310
|
var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
|
|
1311
1311
|
|
|
1312
1312
|
// src/api/analytics/analytics-selectors.ts
|
|
@@ -93,7 +93,7 @@ export type { InstantProducts, InstantProductsDefinition, InstantProductsOptions
|
|
|
93
93
|
export { defineInstantProducts } from './ssr-next/commerce/controllers/instant-products/headless-instant-products.ssr.js';
|
|
94
94
|
export type { CorePaginationOptions, Pagination, PaginationOptions, PaginationProps, PaginationState, } from './ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.js';
|
|
95
95
|
export { definePagination } from './ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.js';
|
|
96
|
-
export type { CommerceSearchParameters, ParameterManager, ParameterManagerProps, ParameterManagerState, Parameters, ProductListingParameters, SSRParameterManagerProps, } from './ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
96
|
+
export type { CommerceSearchParameters, ParameterManager, ParameterManagerDefinition, ParameterManagerProps, ParameterManagerState, Parameters, ProductListingParameters, SSRParameterManagerProps, } from './ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
97
97
|
export { defineParameterManager } from './ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.js';
|
|
98
98
|
export type { ProductList, ProductListing, ProductListState, Search, } from './ssr-next/commerce/controllers/product-list/headless-product-list.ssr.js';
|
|
99
99
|
export { defineProductList } from './ssr-next/commerce/controllers/product-list/headless-product-list.ssr.js';
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { Controller } from '../../controllers/controller/headless-controller.js';
|
|
3
|
-
import type { ControllersMap } from '../common/types/controllers.js';
|
|
4
3
|
import type { SSRCommerceEngine } from './factories/build-factory.js';
|
|
5
4
|
import type { SolutionType } from './types/controller-constants.js';
|
|
6
|
-
import type { ControllerDefinitionOption, ControllerDefinitionsMap
|
|
7
|
-
import type { InferControllerPropsMapFromDefinitions, InferControllersMapFromDefinition } from './types/controller-inference.js';
|
|
5
|
+
import type { ControllerDefinitionOption, ControllerDefinitionsMap } from './types/controller-definitions.js';
|
|
6
|
+
import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitionsWithSolutionType, InferControllersMapFromDefinition } from './types/controller-inference.js';
|
|
8
7
|
import type { EngineStaticState } from './types/engine.js';
|
|
9
|
-
export declare function createStaticState<TSearchAction extends UnknownAction
|
|
8
|
+
export declare function createStaticState<TSearchAction extends UnknownAction, TControllerDefinitions extends ControllerDefinitionsMap<Controller>>({ searchActions, controllers, }: {
|
|
10
9
|
searchActions: TSearchAction[];
|
|
11
|
-
controllers:
|
|
12
|
-
}): EngineStaticState<TSearchAction,
|
|
10
|
+
controllers: InferControllersMapFromDefinition<TControllerDefinitions, SolutionType>;
|
|
11
|
+
}): EngineStaticState<TSearchAction, InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllerDefinitions, SolutionType>>;
|
|
13
12
|
export declare function buildControllerDefinitions<TControllerDefinitionsMap extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType>({ definitionsMap, engine, solutionType, propsMap, }: {
|
|
14
13
|
definitionsMap: TControllerDefinitionsMap;
|
|
15
14
|
engine: SSRCommerceEngine;
|
|
16
15
|
solutionType: TSolutionType;
|
|
17
|
-
propsMap
|
|
16
|
+
propsMap?: InferControllerPropsMapFromDefinitions<TControllerDefinitionsMap>;
|
|
18
17
|
}): InferControllersMapFromDefinition<TControllerDefinitionsMap, TSolutionType>;
|
|
19
18
|
export declare function ensureAtLeastOneSolutionType(options?: ControllerDefinitionOption): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type Context, type ContextOptions, type ContextProps, type ContextState, type UserLocation, type View } from '../../../../controllers/commerce/context/headless-context.js';
|
|
2
2
|
import type { UniversalControllerDefinitionWithProps } from '../../types/controller-definitions.js';
|
|
3
3
|
export type { Context, ContextProps, ContextState, View, UserLocation, ContextOptions, };
|
|
4
|
-
export interface ContextDefinition extends UniversalControllerDefinitionWithProps<Context,
|
|
4
|
+
export interface ContextDefinition extends UniversalControllerDefinitionWithProps<Context, {
|
|
5
|
+
initialState: ContextOptions;
|
|
6
|
+
}> {
|
|
5
7
|
}
|
|
6
8
|
/**
|
|
7
9
|
* Defines a `Context` controller instance.
|
|
@@ -4,13 +4,14 @@ import type { ProductListingParameters } from '../../../../features/commerce/pro
|
|
|
4
4
|
import type { CommerceSearchParameters } from '../../../../features/commerce/search-parameters/search-parameters-actions.js';
|
|
5
5
|
import type { ControllerDefinitionOption, SubControllerDefinitionWithProps } from '../../types/controller-definitions.js';
|
|
6
6
|
export type { ParameterManager, ParameterManagerProps, ParameterManagerState, Parameters, ProductListingParameters, CommerceSearchParameters, };
|
|
7
|
+
export type ParameterManagerDefinition<TOptions extends ControllerDefinitionOption | undefined> = SubControllerDefinitionWithProps<ParameterManager<MappedParameterTypes<TOptions>>, TOptions, SSRParameterManagerProps<MappedParameterTypes<TOptions>>>;
|
|
7
8
|
/**
|
|
8
9
|
* Defines a `ParameterManager` controller instance.
|
|
9
10
|
* @group Definers
|
|
10
11
|
*
|
|
11
12
|
* @returns The `ParameterManager` controller definition.
|
|
12
13
|
*/
|
|
13
|
-
export declare function defineParameterManager<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions):
|
|
14
|
+
export declare function defineParameterManager<TOptions extends ControllerDefinitionOption | undefined>(options?: TOptions): ParameterManagerDefinition<TOptions>;
|
|
14
15
|
export interface SSRParameterManagerProps<T extends Parameters> extends Omit<ParameterManagerProps<T>, 'excludeDefaultParameters'> {
|
|
15
16
|
}
|
|
16
17
|
type MappedParameterTypes<TOptions extends ControllerDefinitionOption | undefined> = TOptions extends {
|
|
@@ -8,7 +8,7 @@ export type InferStaticState<T extends {
|
|
|
8
8
|
export type InferHydratedState<T extends {
|
|
9
9
|
hydrateStaticState(...args: unknown[]): Promise<unknown>;
|
|
10
10
|
}> = Awaited<ReturnType<T['hydrateStaticState']>>;
|
|
11
|
-
|
|
11
|
+
type InferControllerPropsFromDefinition<TController extends ControllerDefinition<Controller>> = TController extends ControllerDefinitionWithProps<Controller, infer Props> ? HasKey<TController, typeof recommendationInternalOptionKey> extends never ? Props : Props & RecommendationControllerSettings : TController extends ControllerDefinitionWithoutProps<Controller> ? HasKey<TController, typeof recommendationInternalOptionKey> extends never ? {} : RecommendationControllerSettings : unknown;
|
|
12
12
|
export type InferControllerPropsMapFromDefinitions<TControllers extends ControllerDefinitionsMap<Controller>> = {
|
|
13
13
|
[K in keyof TControllers as HasKeys<InferControllerPropsFromDefinition<TControllers[K]>> extends false ? never : K]: InferControllerPropsFromDefinition<TControllers[K]>;
|
|
14
14
|
};
|
|
@@ -17,5 +17,6 @@ export type InferControllersMapFromDefinition<TControllers extends ControllerDef
|
|
|
17
17
|
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerFromDefinition<TControllers[K]>;
|
|
18
18
|
};
|
|
19
19
|
export type InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = {
|
|
20
|
-
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]
|
|
20
|
+
[K in keyof TControllers as HasKey<TControllers[K], TSolutionType> extends never ? never : K]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]>> & InferControllerPropsFromDefinition<TControllers[K]>;
|
|
21
21
|
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CoreEngine, CoreEngineNext } from '../../../app/engine.js';
|
|
2
|
+
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { BaseControllerDefinitionWithoutProps, BaseControllerDefinitionWithProps } from '../types/controllers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Builder class for creating controllers from definitions
|
|
6
|
+
*/
|
|
7
|
+
export declare class ControllerBuilder<TDefinition extends Partial<BaseControllerDefinitionWithoutProps<TEngine, TController>> & Partial<BaseControllerDefinitionWithProps<TEngine, TController, TProps>>, TEngine extends CoreEngine | CoreEngineNext, TProps, TController extends Controller = Controller> {
|
|
8
|
+
private _definition;
|
|
9
|
+
private _engine;
|
|
10
|
+
private _props?;
|
|
11
|
+
private _additionalArgs;
|
|
12
|
+
constructor(definition: TDefinition, engine: TEngine, props?: TProps);
|
|
13
|
+
withAdditionalArgs(additionalArgs?: unknown[]): this;
|
|
14
|
+
build(): TController;
|
|
15
|
+
private buildWithoutProps;
|
|
16
|
+
private buildWithProps;
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
2
|
+
import type { ControllerWithKind } from '../../commerce/types/controller-definitions.js';
|
|
3
|
+
import type { Kind } from '../../commerce/types/kind.js';
|
|
4
|
+
export type StaticControllerState = {
|
|
5
|
+
initialState?: Controller['state'];
|
|
6
|
+
_kind?: Kind;
|
|
7
|
+
} & Pick<ControllerWithKind, 'state'>;
|
|
8
|
+
/**
|
|
9
|
+
* Builder class for creating static controller
|
|
10
|
+
*/
|
|
11
|
+
declare class StaticControllerBuilder {
|
|
12
|
+
private _state?;
|
|
13
|
+
private _kind?;
|
|
14
|
+
private _initialState?;
|
|
15
|
+
withState(state: StaticControllerState['state']): this;
|
|
16
|
+
withKind(kind: Kind): this;
|
|
17
|
+
withInitialState(initialState: StaticControllerState['initialState']): this;
|
|
18
|
+
/**
|
|
19
|
+
* Builds and returns the static controller state object
|
|
20
|
+
*/
|
|
21
|
+
build(): StaticControllerState;
|
|
22
|
+
}
|
|
23
|
+
export declare function createStaticControllerBuilder<TController extends Controller>(controller: TController): StaticControllerBuilder;
|
|
24
|
+
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { CoreEngine, CoreEngineNext } from '../../app/engine.js';
|
|
3
3
|
import type { Controller } from '../../controllers/controller/headless-controller.js';
|
|
4
|
-
import type { ControllerDefinitionsMap
|
|
4
|
+
import type { ControllerDefinitionsMap } from './types/controllers.js';
|
|
5
5
|
import type { EngineStaticState } from './types/engine.js';
|
|
6
|
-
import type { InferControllerPropsMapFromDefinitions,
|
|
6
|
+
import type { InferControllerPropsMapFromDefinitions, InferControllerStaticStateMapFromDefinitions, InferControllersMapFromDefinition } from './types/inference.js';
|
|
7
7
|
export declare function buildControllerDefinitions<TControllerDefinitionsMap extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>, TEngine extends CoreEngine | CoreEngineNext>({ definitionsMap, engine, propsMap, }: {
|
|
8
8
|
definitionsMap: TControllerDefinitionsMap;
|
|
9
9
|
engine: TEngine;
|
|
10
|
-
propsMap
|
|
10
|
+
propsMap?: InferControllerPropsMapFromDefinitions<TControllerDefinitionsMap>;
|
|
11
11
|
}): InferControllersMapFromDefinition<TControllerDefinitionsMap>;
|
|
12
|
-
export declare function createStaticState<TSearchAction extends UnknownAction
|
|
12
|
+
export declare function createStaticState<TSearchAction extends UnknownAction, TControllerDefinitions extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>>({ searchAction, controllers, }: {
|
|
13
13
|
searchAction: TSearchAction;
|
|
14
|
-
controllers:
|
|
15
|
-
}): EngineStaticState<TSearchAction,
|
|
14
|
+
controllers: InferControllersMapFromDefinition<TControllerDefinitions>;
|
|
15
|
+
}): EngineStaticState<TSearchAction, InferControllerStaticStateMapFromDefinitions<TControllerDefinitions>>;
|
|
@@ -9,6 +9,12 @@ export interface ControllerStaticState<TState> {
|
|
|
9
9
|
export interface ControllerStaticStateMap {
|
|
10
10
|
[customName: string]: ControllerStaticState<unknown>;
|
|
11
11
|
}
|
|
12
|
+
export interface BaseControllerDefinitionWithoutProps<TEngine, TController extends Controller> {
|
|
13
|
+
build(engine: TEngine, ...args: unknown[]): TController;
|
|
14
|
+
}
|
|
15
|
+
export interface BaseControllerDefinitionWithProps<TEngine, TController extends Controller, TProps> {
|
|
16
|
+
buildWithProps(engine: TEngine, props?: TProps, ...args: unknown[]): TController;
|
|
17
|
+
}
|
|
12
18
|
export interface ControllerDefinitionWithoutProps<TEngine extends CoreEngine | CoreEngineNext, TController extends Controller> {
|
|
13
19
|
/**
|
|
14
20
|
* Creates an instance of the given controller.
|
|
@@ -2,7 +2,7 @@ import type { CoreEngine, CoreEngineNext } from '../../../app/engine.js';
|
|
|
2
2
|
import type { Controller } from '../../../controllers/controller/headless-controller.js';
|
|
3
3
|
import type { ControllerDefinition, ControllerDefinitionsMap, ControllerDefinitionWithoutProps, ControllerDefinitionWithProps, ControllerStaticState, ControllersMap } from './controllers.js';
|
|
4
4
|
import type { HasKeys } from './utilities.js';
|
|
5
|
-
|
|
5
|
+
type InferControllerPropsFromDefinition<TController extends ControllerDefinition<CoreEngine | CoreEngineNext, Controller>> = TController extends ControllerDefinitionWithProps<CoreEngine | CoreEngineNext, Controller, infer Props> ? Props : TController extends ControllerDefinitionWithoutProps<CoreEngine | CoreEngineNext, Controller> ? {} : unknown;
|
|
6
6
|
export type InferControllerPropsMapFromDefinitions<TControllers extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>> = {
|
|
7
7
|
[K in keyof TControllers as HasKeys<InferControllerPropsFromDefinition<TControllers[K]>> extends false ? never : K]: InferControllerPropsFromDefinition<TControllers[K]>;
|
|
8
8
|
};
|
|
@@ -12,8 +12,9 @@ export type InferControllersMapFromDefinition<TControllers extends ControllerDef
|
|
|
12
12
|
};
|
|
13
13
|
export type InferControllerStaticStateFromController<TController extends Controller> = ControllerStaticState<TController['state']>;
|
|
14
14
|
export type InferControllerStaticStateMapFromDefinitions<TControllers extends ControllerDefinitionsMap<CoreEngine | CoreEngineNext, Controller>> = {
|
|
15
|
-
[K in keyof TControllers]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]
|
|
15
|
+
[K in keyof TControllers]: InferControllerStaticStateFromController<InferControllerFromDefinition<TControllers[K]>> & InferControllerPropsFromDefinition<TControllers[K]>;
|
|
16
16
|
};
|
|
17
17
|
export type InferControllerStaticStateMapFromControllers<TControllers extends ControllersMap> = {
|
|
18
18
|
[K in keyof TControllers]: InferControllerStaticStateFromController<TControllers[K]>;
|
|
19
19
|
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CoreEngine, CoreEngineNext } from '../app/engine.js';
|
|
2
|
+
import type { Controller } from '../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { SSRCommerceEngine } from '../ssr/commerce/factories/build-factory.js';
|
|
4
|
+
interface MockController {
|
|
5
|
+
initialState?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildMockController(): Controller;
|
|
8
|
+
export declare function buildMockControllerWithInitialState(_engine: CoreEngine | CoreEngineNext | SSRCommerceEngine, props: MockController): Controller;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SearchEngine } from '../app/search-engine/search-engine.js';
|
|
2
|
+
import type { Controller } from '../controllers/controller/headless-controller.js';
|
|
3
|
+
import type { Kind } from '../ssr/commerce/types/kind.js';
|
|
4
|
+
import type { ControllerDefinitionWithoutProps, ControllerDefinitionWithProps } from '../ssr-next/common/types/controllers.js';
|
|
5
|
+
interface MockController {
|
|
6
|
+
initialState?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
interface MockControllerDefinitionWithoutProps extends ControllerDefinitionWithoutProps<SearchEngine, Controller> {
|
|
9
|
+
}
|
|
10
|
+
interface MockControllerDefinitionWithProps extends ControllerDefinitionWithProps<SearchEngine, Controller, MockController> {
|
|
11
|
+
}
|
|
12
|
+
type SolutionTypeAvailabilities = {
|
|
13
|
+
listing?: boolean;
|
|
14
|
+
search?: boolean;
|
|
15
|
+
standalone?: boolean;
|
|
16
|
+
recommendation?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function defineMockController(): MockControllerDefinitionWithoutProps;
|
|
19
|
+
export declare function defineMockControllerWithProps(): MockControllerDefinitionWithProps;
|
|
20
|
+
export declare function defineMockCommerceController(options?: SolutionTypeAvailabilities): {
|
|
21
|
+
build: import("vitest").Mock<(_engine: any) => Controller>;
|
|
22
|
+
listing: boolean;
|
|
23
|
+
search: boolean;
|
|
24
|
+
standalone: boolean;
|
|
25
|
+
recommendation: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare function defineMockCommerceControllerWithProps(options?: SolutionTypeAvailabilities): {
|
|
28
|
+
buildWithProps: import("vitest").Mock<(engine: any, props: any) => {
|
|
29
|
+
state: {};
|
|
30
|
+
subscribe(listener: () => void): import("redux").Unsubscribe;
|
|
31
|
+
_kind: Kind;
|
|
32
|
+
}>;
|
|
33
|
+
listing: boolean;
|
|
34
|
+
search: boolean;
|
|
35
|
+
standalone: boolean;
|
|
36
|
+
recommendation: boolean;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { clone, filterObject, mapObject } from '../../utils/utils.js';
|
|
2
|
+
import { ControllerBuilder } from '../common/builders/controller-builder.js';
|
|
3
|
+
import { createStaticControllerBuilder } from '../common/builders/static-controller-builder.js';
|
|
2
4
|
import { InvalidControllerDefinition } from '../common/errors.js';
|
|
3
|
-
function hasKindProperty(controller) {
|
|
4
|
-
return '_kind' in controller;
|
|
5
|
-
}
|
|
6
5
|
export function createStaticState({ searchActions, controllers, }) {
|
|
7
6
|
return {
|
|
8
|
-
controllers: mapObject(controllers, (controller) => (
|
|
9
|
-
state: clone(controller.state),
|
|
10
|
-
...(hasKindProperty(controller) && { _kind: controller._kind }),
|
|
11
|
-
})),
|
|
7
|
+
controllers: mapObject(controllers, (controller) => createStaticControllerBuilder(controller).build()),
|
|
12
8
|
searchActions: searchActions.map((action) => clone(action)),
|
|
13
9
|
};
|
|
14
10
|
}
|
|
15
|
-
function buildControllerFromDefinition({ definition, engine, solutionType, props, }) {
|
|
16
|
-
return ('build' in definition
|
|
17
|
-
? definition.build(engine, solutionType)
|
|
18
|
-
: definition.buildWithProps(engine, props, solutionType));
|
|
19
|
-
}
|
|
20
11
|
export function buildControllerDefinitions({ definitionsMap, engine, solutionType, propsMap, }) {
|
|
21
12
|
const controllerMap = mapObject(definitionsMap, (definition, key) => {
|
|
22
13
|
const unavailableInSolutionType = () => !(solutionType in definition) ||
|
|
@@ -26,12 +17,9 @@ export function buildControllerDefinitions({ definitionsMap, engine, solutionTyp
|
|
|
26
17
|
if (unavailableInSolutionType()) {
|
|
27
18
|
return null;
|
|
28
19
|
}
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
solutionType,
|
|
33
|
-
props,
|
|
34
|
-
});
|
|
20
|
+
return new ControllerBuilder(definition, engine, props)
|
|
21
|
+
.withAdditionalArgs([solutionType])
|
|
22
|
+
.build();
|
|
35
23
|
});
|
|
36
24
|
return filterObject(controllerMap, (value) => value !== null);
|
|
37
25
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { buildCart, } from '../../../../controllers/commerce/context/cart/headless-cart.js';
|
|
2
|
-
import { MissingControllerProps } from '../../../common/errors.js';
|
|
3
2
|
import { createControllerWithKind, Kind } from '../../types/kind.js';
|
|
4
3
|
/**
|
|
5
4
|
* Defines a `Cart` controller instance.
|
|
@@ -14,10 +13,9 @@ export function defineCart() {
|
|
|
14
13
|
standalone: true,
|
|
15
14
|
recommendation: true,
|
|
16
15
|
buildWithProps: (engine, props) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
const controller = buildCart(engine, { initialState: props.initialState });
|
|
16
|
+
const controller = buildCart(engine, {
|
|
17
|
+
initialState: props ? props.initialState : {},
|
|
18
|
+
});
|
|
21
19
|
return createControllerWithKind(controller, Kind.Cart);
|
|
22
20
|
},
|
|
23
21
|
};
|
|
@@ -17,7 +17,7 @@ export function defineContext() {
|
|
|
17
17
|
if (props === undefined) {
|
|
18
18
|
throw new MissingControllerProps(Kind.Context);
|
|
19
19
|
}
|
|
20
|
-
const controller = buildContext(engine, { options: props });
|
|
20
|
+
const controller = buildContext(engine, { options: props.initialState });
|
|
21
21
|
return createControllerWithKind(controller, Kind.Context);
|
|
22
22
|
},
|
|
23
23
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder class for creating controllers from definitions
|
|
3
|
+
*/
|
|
4
|
+
export class ControllerBuilder {
|
|
5
|
+
_definition;
|
|
6
|
+
_engine;
|
|
7
|
+
_props;
|
|
8
|
+
_additionalArgs = [];
|
|
9
|
+
constructor(definition, engine, props) {
|
|
10
|
+
this._definition = definition;
|
|
11
|
+
this._engine = engine;
|
|
12
|
+
this._props = props;
|
|
13
|
+
}
|
|
14
|
+
withAdditionalArgs(additionalArgs = []) {
|
|
15
|
+
this._additionalArgs = additionalArgs;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
build() {
|
|
19
|
+
if ('build' in this._definition &&
|
|
20
|
+
typeof this._definition.build === 'function') {
|
|
21
|
+
return this.buildWithoutProps();
|
|
22
|
+
}
|
|
23
|
+
if ('buildWithProps' in this._definition &&
|
|
24
|
+
typeof this._definition.buildWithProps === 'function') {
|
|
25
|
+
return this.buildWithProps();
|
|
26
|
+
}
|
|
27
|
+
throw new Error('Controller definition must have a build or buildWithProps method.');
|
|
28
|
+
}
|
|
29
|
+
buildWithoutProps() {
|
|
30
|
+
const buildFn = this._definition.build;
|
|
31
|
+
return buildFn(this._engine, ...this._additionalArgs);
|
|
32
|
+
}
|
|
33
|
+
buildWithProps() {
|
|
34
|
+
const buildWithPropsFn = this._definition.buildWithProps;
|
|
35
|
+
const controller = buildWithPropsFn(this._engine, this._props, ...this._additionalArgs);
|
|
36
|
+
return { ...controller, initialState: controller.state };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { clone } from '../../../utils/utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builder class for creating static controller
|
|
4
|
+
*/
|
|
5
|
+
class StaticControllerBuilder {
|
|
6
|
+
_state;
|
|
7
|
+
_kind;
|
|
8
|
+
_initialState;
|
|
9
|
+
withState(state) {
|
|
10
|
+
this._state = clone(state);
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
withKind(kind) {
|
|
14
|
+
this._kind = kind;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
withInitialState(initialState) {
|
|
18
|
+
this._initialState = clone(initialState);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Builds and returns the static controller state object
|
|
23
|
+
*/
|
|
24
|
+
build() {
|
|
25
|
+
const result = {
|
|
26
|
+
state: this._state,
|
|
27
|
+
};
|
|
28
|
+
if (this._kind) {
|
|
29
|
+
result._kind = this._kind;
|
|
30
|
+
}
|
|
31
|
+
if (this._initialState) {
|
|
32
|
+
result.initialState = this._initialState;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function createStaticControllerBuilder(controller) {
|
|
38
|
+
const builder = new StaticControllerBuilder().withState(controller.state);
|
|
39
|
+
if ('_kind' in controller) {
|
|
40
|
+
builder.withKind(controller._kind);
|
|
41
|
+
}
|
|
42
|
+
if ('initialState' in controller) {
|
|
43
|
+
builder.withInitialState(controller.initialState);
|
|
44
|
+
}
|
|
45
|
+
return builder;
|
|
46
|
+
}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { clone, mapObject } from '../../utils/utils.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
? definition.build(engine)
|
|
5
|
-
: definition.buildWithProps(engine, props));
|
|
6
|
-
}
|
|
2
|
+
import { ControllerBuilder } from './builders/controller-builder.js';
|
|
3
|
+
import { createStaticControllerBuilder } from './builders/static-controller-builder.js';
|
|
7
4
|
export function buildControllerDefinitions({ definitionsMap, engine, propsMap, }) {
|
|
8
|
-
return mapObject(definitionsMap, (definition, key) =>
|
|
9
|
-
|
|
10
|
-
engine,
|
|
11
|
-
|
|
12
|
-
}));
|
|
5
|
+
return mapObject(definitionsMap, (definition, key) => {
|
|
6
|
+
const props = propsMap?.[key];
|
|
7
|
+
return new ControllerBuilder(definition, engine, props).build();
|
|
8
|
+
});
|
|
13
9
|
}
|
|
14
10
|
export function createStaticState({ searchAction, controllers, }) {
|
|
15
11
|
return {
|
|
16
|
-
controllers: mapObject(controllers, (controller) => (
|
|
17
|
-
state: clone(controller.state),
|
|
18
|
-
})),
|
|
12
|
+
controllers: mapObject(controllers, (controller) => createStaticControllerBuilder(controller).build()),
|
|
19
13
|
searchAction: clone(searchAction),
|
|
20
14
|
};
|
|
21
15
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
export function buildMockController() {
|
|
3
|
+
return {
|
|
4
|
+
subscribe: vi.fn(),
|
|
5
|
+
state: {},
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function buildMockControllerWithInitialState(_engine, props) {
|
|
9
|
+
return {
|
|
10
|
+
state: props.initialState,
|
|
11
|
+
subscribe: vi.fn(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import { buildMockController, buildMockControllerWithInitialState, } from './mock-controller.js';
|
|
3
|
+
export function defineMockController() {
|
|
4
|
+
return {
|
|
5
|
+
build: vi.fn((_engine) => {
|
|
6
|
+
return buildMockController();
|
|
7
|
+
}),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function defineMockControllerWithProps() {
|
|
11
|
+
return {
|
|
12
|
+
buildWithProps: vi.fn((engine, props) => {
|
|
13
|
+
return buildMockControllerWithInitialState(engine, {
|
|
14
|
+
initialState: props?.initialState,
|
|
15
|
+
});
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function defineMockCommerceController(options) {
|
|
20
|
+
return {
|
|
21
|
+
build: vi.fn((_engine) => {
|
|
22
|
+
return buildMockController();
|
|
23
|
+
}),
|
|
24
|
+
listing: options?.listing ?? true,
|
|
25
|
+
search: options?.search ?? true,
|
|
26
|
+
standalone: options?.standalone ?? true,
|
|
27
|
+
recommendation: options?.recommendation ?? true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function defineMockCommerceControllerWithProps(options) {
|
|
31
|
+
return {
|
|
32
|
+
buildWithProps: vi.fn((engine, props) => ({
|
|
33
|
+
_kind: 'some-kind',
|
|
34
|
+
...buildMockControllerWithInitialState(engine, {
|
|
35
|
+
initialState: props?.initialState,
|
|
36
|
+
}),
|
|
37
|
+
})),
|
|
38
|
+
listing: options?.listing ?? true,
|
|
39
|
+
search: options?.search ?? true,
|
|
40
|
+
standalone: options?.standalone ?? true,
|
|
41
|
+
recommendation: options?.recommendation ?? true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "3.28.4-pre.
|
|
1
|
+
export const VERSION = "3.28.4-pre.fac9a879d3" || 'Test version';
|
|
2
2
|
export const COVEO_FRAMEWORK = ['@coveo/atomic', '@coveo/quantic'];
|