@coveo/quantic 3.33.4 → 3.33.6
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/force-app/main/default/lwc/quanticHeadlessLoader/quanticHeadlessLoader.js +4 -1
- package/force-app/main/default/lwc/quanticSmartSnippet/e2e/quanticSmartSnippet.e2e.ts +4 -28
- package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +8 -8
- package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts +2 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/facets/generator/headless-commerce-facet-generator.d.ts +0 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr/common/types/engine.d.ts +9 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/commerce/types/build.d.ts +75 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/commerce/types/engine.d.ts +52 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/common/types/engine.d.ts +53 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/search/engine/search-engine.ssr.d.ts +17 -5
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/search/factories/standalone-static-state-factory.d.ts +9 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/search/types/engine.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -10
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +9 -9
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +7 -7
- package/package.json +2 -2
package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Coveo Headless Commerce sub-package exposes
|
|
2
|
+
* The Coveo Headless Commerce sub-package exposes the engine, controllers, actions, and utility functions to
|
|
3
|
+
* build a [commerce search experience](https://docs.coveo.com/en/o6r70022/).
|
|
3
4
|
*
|
|
4
5
|
* @example
|
|
5
6
|
* ```typescript
|
|
@@ -29,7 +29,6 @@ export interface FacetGenerator extends Controller {
|
|
|
29
29
|
state: string[];
|
|
30
30
|
/**
|
|
31
31
|
* The facet sub-controllers created by the facet generator.
|
|
32
|
-
* Array of [RegularFacet](./regular-facet), [DateRangeFacet](./date-range-facet), [NumericFacet](./numeric-facet), [CategoryFacet](./category-facet), and [LocationFacet](./location-facet).
|
|
33
32
|
*/
|
|
34
33
|
facets: GeneratedFacetControllers;
|
|
35
34
|
/**
|
|
@@ -41,6 +41,15 @@ export interface EngineDefinition<TEngine extends CoreEngine | CoreEngineNext, T
|
|
|
41
41
|
* Builds an engine and its controllers from an engine definition.
|
|
42
42
|
*/
|
|
43
43
|
build: Build<TEngine, TEngineOptions, InferControllersMapFromDefinition<TControllers>, InferControllerPropsMapFromDefinitions<TControllers>>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the access token.
|
|
46
|
+
*/
|
|
47
|
+
getAccessToken: () => string;
|
|
48
|
+
/**
|
|
49
|
+
* Updates the access token.
|
|
50
|
+
* @param accessToken - The access token to update.
|
|
51
|
+
*/
|
|
52
|
+
setAccessToken: (accessToken: string) => void;
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
46
55
|
* @deprecated Use SearchEngineDefinitionBuildResult or CommerceEngineDefinitionBuildResult instead
|
|
@@ -75,9 +75,84 @@ export interface ListingBuildConfig extends CommonBuildConfig {
|
|
|
75
75
|
export interface StandaloneBuildConfig extends CommonBuildConfig {
|
|
76
76
|
}
|
|
77
77
|
export interface CommonBuildConfig {
|
|
78
|
+
/**
|
|
79
|
+
* The `NavigatorContext` interface represents the context of the browser client.
|
|
80
|
+
* See {@link NavigatorContext}
|
|
81
|
+
*/
|
|
78
82
|
navigatorContext: NavigatorContext;
|
|
83
|
+
/**
|
|
84
|
+
* The initial context options passed to the engine when fetching the static state.
|
|
85
|
+
*
|
|
86
|
+
* This property is used to configure the commerce context (e.g., currency, language, country)
|
|
87
|
+
* when calling `fetchStaticState()`.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* To access the context after engine creation, use the context controller.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Setting context during static state fetch
|
|
95
|
+
* const staticState = await engineDefinition.fetchStaticState({
|
|
96
|
+
* context: { currency: 'USD', language: 'en', country: 'US' },
|
|
97
|
+
* // ...other config
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Reading context from the static state
|
|
101
|
+
* const {context} = staticState.controllers;
|
|
102
|
+
* console.log(context.state.currency); // 'USD'
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
79
105
|
context: ContextOptions;
|
|
106
|
+
/**
|
|
107
|
+
* The initial search parameters to apply when fetching the static state.
|
|
108
|
+
*
|
|
109
|
+
* This property allows you to set initial search parameters (filters, facets, query, etc.)
|
|
110
|
+
* that will be applied during the server-side search execution.
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* To access search parameters after engine creation, use the parameter manager controller.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Setting search parameters during static state fetch
|
|
118
|
+
* const staticState = await engineDefinition.fetchStaticState({
|
|
119
|
+
* searchParams: {
|
|
120
|
+
* q: 'shoes',
|
|
121
|
+
* },
|
|
122
|
+
* // ...other config
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* // Reading search parameters from the static state
|
|
126
|
+
* const {parameterManager} = staticState.controllers;
|
|
127
|
+
* console.log(parameterManager.state.parameters.q); // 'shoes'
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
80
130
|
searchParams?: ParameterManagerState<Parameters>['parameters'];
|
|
131
|
+
/**
|
|
132
|
+
* The initial cart state to apply when fetching the static state.
|
|
133
|
+
*
|
|
134
|
+
* This property allows you to set an initial cart state that will be used during
|
|
135
|
+
* server-side rendering.
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* To access cart state after engine creation, use the cart controller.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Setting cart state during static state fetch
|
|
143
|
+
* const staticState = await engineDefinition.fetchStaticState({
|
|
144
|
+
* cart: {
|
|
145
|
+
* // This is a simplified example. The actual item structure may require additional properties.
|
|
146
|
+
* items: [{ productId: 'abc123', quantity: 1 }]
|
|
147
|
+
* },
|
|
148
|
+
* // ...other config
|
|
149
|
+
* });
|
|
150
|
+
*
|
|
151
|
+
* // Reading cart state from the static state
|
|
152
|
+
* const {cart} = staticState.controllers;
|
|
153
|
+
* console.log(cart.state.items.length); // 1
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
81
156
|
cart?: CartInitialState;
|
|
82
157
|
}
|
|
83
158
|
export type BuildConfig<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> = TSolutionType extends SolutionType.search ? SearchBuildConfig : TSolutionType extends SolutionType.listing ? ListingBuildConfig : TSolutionType extends SolutionType.recommendation ? RecommendationBuildConfig<TControllers> : TSolutionType extends SolutionType.standalone ? CommonBuildConfig : never;
|
|
@@ -29,11 +29,61 @@ export type CommerceEngineDefinitionOptions<TControllers extends ControllerDefin
|
|
|
29
29
|
};
|
|
30
30
|
export interface CommerceEngineDefinition<TControllers extends ControllerDefinitionsMap<Controller>, TSolutionType extends SolutionType> {
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Executes a commerce search/listing/recommendation request on the server side and returns the static state.
|
|
33
|
+
*
|
|
34
|
+
* This method performs the initial commerce request based on the solution type, captures the response,
|
|
35
|
+
* and returns a serializable state snapshot that can be transferred to the client for hydration.
|
|
36
|
+
*
|
|
37
|
+
* The returned static state includes controller states (facets, products, pagination, etc.)
|
|
38
|
+
*
|
|
39
|
+
* @param params - A configuration object containing navigation context, search parameters,
|
|
40
|
+
* cart state, and controller-specific props
|
|
41
|
+
* @returns A Promise that resolves to the static state containing controller states
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // For a search page
|
|
46
|
+
* const staticState = await searchEngineDefinition.fetchStaticState({
|
|
47
|
+
* navigatorContext: { ... },
|
|
48
|
+
* context: { ... },
|
|
49
|
+
* searchParams: { q: 'running shoes' }
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // For recommendations
|
|
53
|
+
* const staticState = await recommendationEngineDefinition.fetchStaticState({
|
|
54
|
+
* navigatorContext: { ... },
|
|
55
|
+
* context: { ... },
|
|
56
|
+
* recommendations: ['popularProducts'],
|
|
57
|
+
* productId: 'abc123'
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
33
60
|
*/
|
|
34
61
|
fetchStaticState: FetchStaticState<UnknownAction, InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, TSolutionType>, InferControllerPropsMapFromDefinitions<TControllers>, TControllers, TSolutionType>;
|
|
35
62
|
/**
|
|
36
|
-
*
|
|
63
|
+
* Creates a commerce engine on the client side from the server-side static state.
|
|
64
|
+
*
|
|
65
|
+
* This method is used for client-side hydration in SSR scenarios. It takes the static state
|
|
66
|
+
* generated by `fetchStaticState()` on the server and reconstructs a live commerce engine
|
|
67
|
+
* with all controllers in the exact same state as they were on the server.
|
|
68
|
+
*
|
|
69
|
+
* The hydration process:
|
|
70
|
+
* - Recreates the engine with the same configuration
|
|
71
|
+
* - Restores all controller states from the static state
|
|
72
|
+
* - Replays search/listing/recommendation actions to synchronize the state
|
|
73
|
+
* - Returns live, interactive controllers ready for user interaction
|
|
74
|
+
*
|
|
75
|
+
* @param params - A configuration object containing the static state, navigation context,
|
|
76
|
+
* and any controller-specific props needed for hydration
|
|
77
|
+
* @returns A Promise that resolves to the hydrated engine and interactive controllers
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Client-side hydration
|
|
82
|
+
* const result = await engineDefinition.hydrateStaticState(staticState);
|
|
83
|
+
*
|
|
84
|
+
* // Controllers are now interactive
|
|
85
|
+
* result.controllers.productListing.sort({ criterion: 'price' });
|
|
86
|
+
* ```
|
|
37
87
|
*/
|
|
38
88
|
hydrateStaticState: HydrateStaticState<InferControllersMapFromDefinition<TControllers, TSolutionType>, UnknownAction, InferControllerPropsMapFromDefinitions<TControllers>, TControllers, TSolutionType>;
|
|
39
89
|
/**
|
|
@@ -1,12 +1,65 @@
|
|
|
1
1
|
import type { UnknownAction } from '@reduxjs/toolkit';
|
|
2
2
|
import type { ControllerStaticStateMap } from './controllers.js';
|
|
3
3
|
export interface EngineStaticState<TSearchAction extends UnknownAction, TControllers extends ControllerStaticStateMap> {
|
|
4
|
+
/**
|
|
5
|
+
* An array of Redux actions representing completed search operations that were executed when the static state was fetched.
|
|
6
|
+
*
|
|
7
|
+
* These actions capture the results of search requests (both successful and failed) performed on the server side.
|
|
8
|
+
* During client-side hydration, these actions are replayed to restore the engine to the exact same state
|
|
9
|
+
* it was in on the server, ensuring consistency between server-rendered and client-rendered content.
|
|
10
|
+
*
|
|
11
|
+
* Each action contains the search results, metadata, and any error information from the Search API responses.
|
|
12
|
+
*/
|
|
4
13
|
searchActions: TSearchAction[];
|
|
14
|
+
/**
|
|
15
|
+
* A map of controller static states, where each key is the controller name and
|
|
16
|
+
* each value contains the serializable state of that controller.
|
|
17
|
+
*/
|
|
5
18
|
controllers: TControllers;
|
|
6
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Utility type to infer the static state type from an engine definition's `fetchStaticState` method.
|
|
22
|
+
*
|
|
23
|
+
* This type extracts the resolved type from the Promise returned by `fetchStaticState`,
|
|
24
|
+
* allowing you to work with the static state type without manually specifying it.
|
|
25
|
+
*
|
|
26
|
+
* @template T - An object with a `fetchStaticState` method that returns a Promise
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const searchEngineDefinition = defineSearchEngine({
|
|
31
|
+
* configuration: { organizationId: 'myorg', accessToken: 'token' },
|
|
32
|
+
* controllers: { searchBox: defineSearchBox() }
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* type StaticState = InferStaticState<typeof searchEngineDefinition>;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @group Engine
|
|
39
|
+
*/
|
|
7
40
|
export type InferStaticState<T extends {
|
|
8
41
|
fetchStaticState(...args: unknown[]): Promise<unknown>;
|
|
9
42
|
}> = Awaited<ReturnType<T['fetchStaticState']>>;
|
|
43
|
+
/**
|
|
44
|
+
* Utility type to infer the hydrated state type from an engine definition's `hydrateStaticState` method.
|
|
45
|
+
*
|
|
46
|
+
* This type extracts the resolved type from the Promise returned by `hydrateStaticState`,
|
|
47
|
+
* allowing you to work with the hydrated state type without manually specifying it.
|
|
48
|
+
*
|
|
49
|
+
* @template T - An object with a `hydrateStaticState` method that returns a Promise
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const searchEngineDefinition = defineSearchEngine({
|
|
54
|
+
* configuration: { organizationId: 'myorg', accessToken: 'token' },
|
|
55
|
+
* controllers: { searchBox: defineSearchBox() }
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* type HydratedState = InferHydratedState<typeof searchEngineDefinition>;
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @group Engine
|
|
62
|
+
*/
|
|
10
63
|
export type InferHydratedState<T extends {
|
|
11
64
|
hydrateStaticState(...args: unknown[]): Promise<unknown>;
|
|
12
65
|
}> = Awaited<ReturnType<T['hydrateStaticState']>>;
|
|
@@ -4,17 +4,26 @@ import type { SearchControllerDefinitionsMap, SearchEngineDefinition, SearchEngi
|
|
|
4
4
|
* Initializes a Search engine definition in SSR with given controllers definitions and search engine config.
|
|
5
5
|
*
|
|
6
6
|
* @param options - The search engine definition
|
|
7
|
-
* @returns
|
|
7
|
+
* @returns An object containing two engine definitions:
|
|
8
|
+
* - `searchEngineDefinition`: For pages with search results (executes server-side search)
|
|
9
|
+
* - `standaloneEngineDefinition`: For pages with standalone components only (no server-side search execution)
|
|
8
10
|
*
|
|
9
11
|
* @remarks
|
|
10
|
-
* You can use the {@link InferStaticState} and {@link InferHydratedState} utility types with the returned engine
|
|
12
|
+
* You can use the {@link InferStaticState} and {@link InferHydratedState} utility types with the returned engine definitions
|
|
11
13
|
* to infer the types of static and hydrated state for your controllers.
|
|
12
14
|
*
|
|
13
15
|
* @example
|
|
14
16
|
* ```ts
|
|
15
|
-
* const searchEngineDefinition = defineSearchEngine(config);
|
|
17
|
+
* const {searchEngineDefinition, standaloneEngineDefinition} = defineSearchEngine(config);
|
|
16
18
|
*
|
|
17
|
-
*
|
|
19
|
+
* // For search results pages
|
|
20
|
+
* const searchState = await searchEngineDefinition.fetchStaticState({
|
|
21
|
+
* navigatorContext: {/*...* /},
|
|
22
|
+
* searchParams: {q: 'query'}
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // For pages with standalone search box only (e.g., homepage)
|
|
26
|
+
* const standaloneState = await standaloneEngineDefinition.fetchStaticState({
|
|
18
27
|
* navigatorContext: {/*...* /},
|
|
19
28
|
* });
|
|
20
29
|
*
|
|
@@ -24,4 +33,7 @@ import type { SearchControllerDefinitionsMap, SearchEngineDefinition, SearchEngi
|
|
|
24
33
|
*
|
|
25
34
|
* @group Engine
|
|
26
35
|
*/
|
|
27
|
-
export declare function defineSearchEngine<TControllerDefinitions extends SearchControllerDefinitionsMap = {}>(options: SearchEngineDefinitionOptions<TControllerDefinitions>):
|
|
36
|
+
export declare function defineSearchEngine<TControllerDefinitions extends SearchControllerDefinitionsMap = {}>(options: SearchEngineDefinitionOptions<TControllerDefinitions>): {
|
|
37
|
+
searchEngineDefinition: SearchEngineDefinition<SSRSearchEngine, TControllerDefinitions>;
|
|
38
|
+
standaloneEngineDefinition: SearchEngineDefinition<SSRSearchEngine, TControllerDefinitions>;
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AugmentedControllerDefinition } from '../types/controller-definition.js';
|
|
2
|
+
import type { FetchStaticStateFunction, SearchControllerDefinitionsMap, SearchEngineDefinitionOptions } from '../types/engine.js';
|
|
3
|
+
/**
|
|
4
|
+
* Factory function for creating a standalone static state fetcher.
|
|
5
|
+
* Unlike the regular static state factory, this does not execute a search on the server.
|
|
6
|
+
* This is useful for pages with standalone components (like search boxes) that only need
|
|
7
|
+
* controller initialization without server-side search execution.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fetchStandaloneStaticStateFactory<TControllerDefinitions extends SearchControllerDefinitionsMap>(controllerDefinitions: AugmentedControllerDefinition<TControllerDefinitions>, options: SearchEngineDefinitionOptions<TControllerDefinitions>): FetchStaticStateFunction<TControllerDefinitions>;
|
|
@@ -23,6 +23,10 @@ export type SearchEngineDefinitionOptions<TControllers extends SearchControllerD
|
|
|
23
23
|
* The controllers to initialize with the search engine.
|
|
24
24
|
*/
|
|
25
25
|
controllers?: ValidateControllerNames<TControllers>;
|
|
26
|
+
/**
|
|
27
|
+
* Callback invoked when the access token changes.
|
|
28
|
+
*/
|
|
29
|
+
onAccessTokenUpdate?: (updateCallback: (token: string) => void) => void;
|
|
26
30
|
};
|
|
27
31
|
export interface SearchEngineDefinition<TEngine extends CoreEngine | CoreEngineNext, TControllers extends ControllerDefinitionsMap<TEngine, Controller>> {
|
|
28
32
|
/**
|