@coveo/headless 4.0.0-pre.ff258cf819 → 4.0.1-pre.3f9b368bf2

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.
@@ -46,9 +46,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
46
46
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
47
47
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
48
48
 
49
- // src/ssr-commerce-next.index.ts
50
- var ssr_commerce_next_index_exports = {};
51
- __export(ssr_commerce_next_index_exports, {
49
+ // src/ssr-commerce.index.ts
50
+ var ssr_commerce_index_exports = {};
51
+ __export(ssr_commerce_index_exports, {
52
+ Kind: () => Kind,
52
53
  ProductTemplatesHelpers: () => ProductTemplatesHelpers,
53
54
  SolutionType: () => SolutionType,
54
55
  SortBy: () => SortBy,
@@ -115,7 +116,7 @@ __export(ssr_commerce_next_index_exports, {
115
116
  parseCriterionExpression: () => parseCriterionExpression,
116
117
  validateRelativeDate: () => validateRelativeDate
117
118
  });
118
- module.exports = __toCommonJS(ssr_commerce_next_index_exports);
119
+ module.exports = __toCommonJS(ssr_commerce_index_exports);
119
120
 
120
121
  // src/app/commerce-engine/commerce-engine-configuration.ts
121
122
  var import_bueno5 = require("@coveo/bueno");
@@ -467,7 +468,7 @@ var import_bueno8 = require("@coveo/bueno");
467
468
  var import_toolkit3 = require("@reduxjs/toolkit");
468
469
 
469
470
  // src/utils/version.ts
470
- var VERSION = "4.0.0-pre.ff258cf819";
471
+ var VERSION = "4.0.1-pre.3f9b368bf2";
471
472
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
472
473
 
473
474
  // src/features/configuration/configuration-actions.ts
@@ -14054,7 +14055,7 @@ function loadBaseSearchReducers(engine) {
14054
14055
  return true;
14055
14056
  }
14056
14057
 
14057
- // src/ssr-next/commerce/types/controller-constants.ts
14058
+ // src/ssr/commerce/types/controller-constants.ts
14058
14059
  var SolutionType = /* @__PURE__ */ ((SolutionType2) => {
14059
14060
  SolutionType2["search"] = "search";
14060
14061
  SolutionType2["listing"] = "listing";
@@ -14067,11 +14068,92 @@ var recommendationInternalOptionKey = Symbol.for(
14067
14068
  recommendationOptionKey
14068
14069
  );
14069
14070
 
14070
- // src/ssr-next/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.ts
14071
- function defineBreadcrumbManager() {
14071
+ // src/ssr/common/errors.ts
14072
+ var InvalidControllerDefinition = class extends Error {
14073
+ constructor() {
14074
+ super();
14075
+ this.name = "InvalidControllerDefinition";
14076
+ this.message = `A controller must be defined for at least one solution type: ${Object.keys(
14077
+ SolutionType
14078
+ ).map((s) => s.toLowerCase()).join(", ")}`;
14079
+ }
14080
+ };
14081
+ var MissingControllerProps = class extends Error {
14082
+ constructor(controller) {
14083
+ super();
14084
+ this.name = "MissingControllerProps";
14085
+ this.message = `${controller} props are required but were undefined. Ensure they are included when calling \`fetchStaticState\` or \`hydrateStaticState\`.`;
14086
+ }
14087
+ };
14088
+ var MultipleRecommendationError = class extends Error {
14089
+ constructor(slotId) {
14090
+ super();
14091
+ this.name = "MultipleRecommendationError";
14092
+ this.message = `Multiple recommendation controllers found for the same slotId: ${slotId}. Only one recommendation controller per slotId is supported.`;
14093
+ }
14094
+ };
14095
+
14096
+ // src/ssr/commerce/controller-utils.ts
14097
+ function hasKindProperty(controller) {
14098
+ return "_kind" in controller;
14099
+ }
14100
+ function createStaticState({
14101
+ searchActions,
14102
+ controllers
14103
+ }) {
14104
+ return {
14105
+ controllers: mapObject(controllers, (controller) => ({
14106
+ state: clone(controller.state),
14107
+ ...hasKindProperty(controller) && { _kind: controller._kind }
14108
+ })),
14109
+ searchActions: searchActions.map((action) => clone(action))
14110
+ };
14111
+ }
14112
+ function buildControllerFromDefinition({
14113
+ definition: definition3,
14114
+ engine,
14115
+ solutionType,
14116
+ props
14117
+ }) {
14118
+ return "build" in definition3 ? definition3.build(engine, solutionType) : definition3.buildWithProps(engine, props, solutionType);
14119
+ }
14120
+ function buildControllerDefinitions({
14121
+ definitionsMap,
14122
+ engine,
14123
+ solutionType,
14124
+ propsMap
14125
+ }) {
14126
+ const controllerMap = mapObject(definitionsMap, (definition3, key) => {
14127
+ const unavailableInSolutionType = () => !(solutionType in definition3) || solutionType in definition3 && definition3[solutionType] === false;
14128
+ const props = propsMap?.[key];
14129
+ if (unavailableInSolutionType()) {
14130
+ return null;
14131
+ }
14132
+ return buildControllerFromDefinition({
14133
+ definition: definition3,
14134
+ engine,
14135
+ solutionType,
14136
+ props
14137
+ });
14138
+ });
14139
+ return filterObject(
14140
+ controllerMap,
14141
+ (value) => value !== null
14142
+ );
14143
+ }
14144
+ function ensureAtLeastOneSolutionType(options) {
14145
+ if (options?.listing === false && options?.search === false) {
14146
+ throw new InvalidControllerDefinition();
14147
+ }
14148
+ }
14149
+
14150
+ // src/ssr/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.ts
14151
+ function defineBreadcrumbManager(options) {
14152
+ ensureAtLeastOneSolutionType(options);
14072
14153
  return {
14073
14154
  listing: true,
14074
14155
  search: true,
14156
+ ...options,
14075
14157
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine).breadcrumbManager() : buildSearch(engine).breadcrumbManager()
14076
14158
  };
14077
14159
  }
@@ -14287,7 +14369,26 @@ function loadBaseCartReducers(engine) {
14287
14369
  return true;
14288
14370
  }
14289
14371
 
14290
- // src/ssr-next/commerce/controllers/cart/headless-cart.ssr.ts
14372
+ // src/ssr/commerce/types/kind.ts
14373
+ var Kind = /* @__PURE__ */ ((Kind2) => {
14374
+ Kind2["Cart"] = "CART";
14375
+ Kind2["Context"] = "CONTEXT";
14376
+ Kind2["ParameterManager"] = "PARAMETER_MANAGER";
14377
+ Kind2["Recommendations"] = "RECOMMENDATIONS";
14378
+ return Kind2;
14379
+ })(Kind || {});
14380
+ function createControllerWithKind(controller, kind) {
14381
+ const copy = Object.defineProperties(
14382
+ {},
14383
+ Object.getOwnPropertyDescriptors(controller)
14384
+ );
14385
+ Object.defineProperty(copy, "_kind", {
14386
+ value: kind
14387
+ });
14388
+ return copy;
14389
+ }
14390
+
14391
+ // src/ssr/commerce/controllers/cart/headless-cart.ssr.ts
14291
14392
  function defineCart() {
14292
14393
  return {
14293
14394
  listing: true,
@@ -14295,9 +14396,11 @@ function defineCart() {
14295
14396
  standalone: true,
14296
14397
  recommendation: true,
14297
14398
  buildWithProps: (engine, props) => {
14298
- return buildCart(engine, {
14299
- initialState: props ? props.initialState : {}
14300
- });
14399
+ if (props === void 0) {
14400
+ throw new MissingControllerProps("CART" /* Cart */);
14401
+ }
14402
+ const controller = buildCart(engine, { initialState: props.initialState });
14403
+ return createControllerWithKind(controller, "CART" /* Cart */);
14301
14404
  }
14302
14405
  };
14303
14406
  }
@@ -14346,23 +14449,7 @@ function loadBaseContextReducers(engine) {
14346
14449
  return true;
14347
14450
  }
14348
14451
 
14349
- // src/ssr-next/common/errors.ts
14350
- var MissingControllerProps = class extends Error {
14351
- constructor(controller) {
14352
- super();
14353
- this.name = "MissingControllerProps";
14354
- this.message = `${controller} props are required but were undefined. Ensure they are included when calling \`fetchStaticState\` or \`hydrateStaticState\`.`;
14355
- }
14356
- };
14357
- var MultipleRecommendationError = class extends Error {
14358
- constructor(slotId) {
14359
- super();
14360
- this.name = "MultipleRecommendationError";
14361
- this.message = `Multiple recommendation controllers found for the same slotId: ${slotId}. Only one recommendation controller per slotId is supported.`;
14362
- }
14363
- };
14364
-
14365
- // src/ssr-next/commerce/controllers/context/headless-context.ssr.ts
14452
+ // src/ssr/commerce/controllers/context/headless-context.ssr.ts
14366
14453
  function defineContext() {
14367
14454
  return {
14368
14455
  listing: true,
@@ -14371,14 +14458,15 @@ function defineContext() {
14371
14458
  recommendation: true,
14372
14459
  buildWithProps: (engine, props) => {
14373
14460
  if (props === void 0) {
14374
- throw new MissingControllerProps("Context");
14461
+ throw new MissingControllerProps("CONTEXT" /* Context */);
14375
14462
  }
14376
- return buildContext(engine, { options: props.initialState });
14463
+ const controller = buildContext(engine, { options: props });
14464
+ return createControllerWithKind(controller, "CONTEXT" /* Context */);
14377
14465
  }
14378
14466
  };
14379
14467
  }
14380
14468
 
14381
- // src/ssr-next/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.ts
14469
+ // src/ssr/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.ts
14382
14470
  function defineDidYouMean() {
14383
14471
  return {
14384
14472
  search: true,
@@ -14611,7 +14699,7 @@ function loadFilterSuggestionsGeneratorReducers(engine) {
14611
14699
  return true;
14612
14700
  }
14613
14701
 
14614
- // src/ssr-next/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.ts
14702
+ // src/ssr/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.ts
14615
14703
  function defineFilterSuggestionsGenerator() {
14616
14704
  return {
14617
14705
  search: true,
@@ -14621,11 +14709,13 @@ function defineFilterSuggestionsGenerator() {
14621
14709
  };
14622
14710
  }
14623
14711
 
14624
- // src/ssr-next/commerce/controllers/generator/headless-commerce-facet-generator.ssr.ts
14625
- function defineFacetGenerator() {
14712
+ // src/ssr/commerce/controllers/generator/headless-commerce-facet-generator.ssr.ts
14713
+ function defineFacetGenerator(options) {
14714
+ ensureAtLeastOneSolutionType(options);
14626
14715
  return {
14627
14716
  listing: true,
14628
14717
  search: true,
14718
+ ...options,
14629
14719
  build: (engine, solutionType) => buildFacetGenerator2(engine, { props: { solutionType } })
14630
14720
  };
14631
14721
  }
@@ -15021,7 +15111,7 @@ function loadInstantProductsReducers(engine) {
15021
15111
  return true;
15022
15112
  }
15023
15113
 
15024
- // src/ssr-next/commerce/controllers/instant-products/headless-instant-products.ssr.ts
15114
+ // src/ssr/commerce/controllers/instant-products/headless-instant-products.ssr.ts
15025
15115
  function defineInstantProducts(props = { options: {} }) {
15026
15116
  return {
15027
15117
  listing: true,
@@ -15031,8 +15121,9 @@ function defineInstantProducts(props = { options: {} }) {
15031
15121
  };
15032
15122
  }
15033
15123
 
15034
- // src/ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.ts
15124
+ // src/ssr/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.ts
15035
15125
  function definePagination(props) {
15126
+ ensureAtLeastOneSolutionType(props);
15036
15127
  return {
15037
15128
  listing: true,
15038
15129
  search: true,
@@ -15218,28 +15309,32 @@ var registerQuery = (state, actionPayload) => {
15218
15309
  state[id2] = query2;
15219
15310
  };
15220
15311
 
15221
- // src/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.ts
15222
- function defineParameterManager() {
15312
+ // src/ssr/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.ts
15313
+ function defineParameterManager(options) {
15314
+ ensureAtLeastOneSolutionType(options);
15223
15315
  return {
15224
15316
  listing: true,
15225
15317
  search: true,
15318
+ ...options,
15226
15319
  buildWithProps: (engine, props, solutionType) => {
15227
15320
  if (solutionType === "listing" /* listing */) {
15228
15321
  if (!loadCommerceProductListingParameterReducers(engine)) {
15229
15322
  throw loadReducerError;
15230
15323
  }
15231
- return buildProductListing(engine).parameterManager({
15324
+ const controller = buildProductListing(engine).parameterManager({
15232
15325
  ...props,
15233
15326
  excludeDefaultParameters: true
15234
15327
  });
15328
+ return createControllerWithKind(controller, "PARAMETER_MANAGER" /* ParameterManager */);
15235
15329
  } else {
15236
15330
  if (!loadCommerceSearchParameterReducers(engine)) {
15237
15331
  throw loadReducerError;
15238
15332
  }
15239
- return buildSearch(engine).parameterManager({
15333
+ const controller = buildSearch(engine).parameterManager({
15240
15334
  ...props,
15241
15335
  excludeDefaultParameters: true
15242
15336
  });
15337
+ return createControllerWithKind(controller, "PARAMETER_MANAGER" /* ParameterManager */);
15243
15338
  }
15244
15339
  }
15245
15340
  };
@@ -15265,11 +15360,13 @@ function loadCommerceProductListingParameterReducers(engine) {
15265
15360
  return true;
15266
15361
  }
15267
15362
 
15268
- // src/ssr-next/commerce/controllers/product-list/headless-product-list.ssr.ts
15269
- function defineProductList() {
15363
+ // src/ssr/commerce/controllers/product-list/headless-product-list.ssr.ts
15364
+ function defineProductList(options) {
15365
+ ensureAtLeastOneSolutionType(options);
15270
15366
  return {
15271
15367
  listing: true,
15272
15368
  search: true,
15369
+ ...options,
15273
15370
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine) : buildSearch(engine)
15274
15371
  };
15275
15372
  }
@@ -15283,7 +15380,7 @@ function buildProductView(engine) {
15283
15380
  };
15284
15381
  }
15285
15382
 
15286
- // src/ssr-next/commerce/controllers/product-view/headless-product-view.ssr.ts
15383
+ // src/ssr/commerce/controllers/product-view/headless-product-view.ssr.ts
15287
15384
  function defineProductView() {
15288
15385
  return {
15289
15386
  listing: true,
@@ -15503,7 +15600,7 @@ function loadRecentQueriesListReducer(engine) {
15503
15600
  return true;
15504
15601
  }
15505
15602
 
15506
- // src/ssr-next/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.ts
15603
+ // src/ssr/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.ts
15507
15604
  function defineRecentQueriesList(props = {}) {
15508
15605
  return {
15509
15606
  search: true,
@@ -15730,7 +15827,7 @@ function loadBaseRecommendationsReducers(engine) {
15730
15827
  return true;
15731
15828
  }
15732
15829
 
15733
- // src/ssr-next/commerce/controllers/recommendations/headless-recommendations.ssr.ts
15830
+ // src/ssr/commerce/controllers/recommendations/headless-recommendations.ssr.ts
15734
15831
  function defineRecommendations(props) {
15735
15832
  return {
15736
15833
  recommendation: true,
@@ -15739,9 +15836,10 @@ function defineRecommendations(props) {
15739
15836
  },
15740
15837
  buildWithProps: (engine, options) => {
15741
15838
  const staticOptions = props.options;
15742
- return buildRecommendations(engine, {
15839
+ const controller = buildRecommendations(engine, {
15743
15840
  options: { ...staticOptions, ...options }
15744
15841
  });
15842
+ return createControllerWithKind(controller, "RECOMMENDATIONS" /* Recommendations */);
15745
15843
  }
15746
15844
  };
15747
15845
  }
@@ -16053,7 +16151,7 @@ function loadSearchBoxReducers(engine) {
16053
16151
  return true;
16054
16152
  }
16055
16153
 
16056
- // src/ssr-next/commerce/controllers/search-box/headless-search-box.ssr.ts
16154
+ // src/ssr/commerce/controllers/search-box/headless-search-box.ssr.ts
16057
16155
  function defineSearchBox(props = {}) {
16058
16156
  return {
16059
16157
  search: true,
@@ -16061,8 +16159,9 @@ function defineSearchBox(props = {}) {
16061
16159
  };
16062
16160
  }
16063
16161
 
16064
- // src/ssr-next/commerce/controllers/sort/headless-core-commerce-sort.ssr.ts
16162
+ // src/ssr/commerce/controllers/sort/headless-core-commerce-sort.ssr.ts
16065
16163
  function defineSort(props) {
16164
+ ensureAtLeastOneSolutionType(props);
16066
16165
  return {
16067
16166
  listing: true,
16068
16167
  search: true,
@@ -16282,7 +16381,7 @@ function loadStandaloneSearchBoxReducers(engine) {
16282
16381
  return true;
16283
16382
  }
16284
16383
 
16285
- // src/ssr-next/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.ts
16384
+ // src/ssr/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.ts
16286
16385
  function defineStandaloneSearchBox(props) {
16287
16386
  return {
16288
16387
  listing: true,
@@ -16291,11 +16390,13 @@ function defineStandaloneSearchBox(props) {
16291
16390
  };
16292
16391
  }
16293
16392
 
16294
- // src/ssr-next/commerce/controllers/summary/headless-core-summary.ssr.ts
16295
- function defineSummary() {
16393
+ // src/ssr/commerce/controllers/summary/headless-core-summary.ssr.ts
16394
+ function defineSummary(options) {
16395
+ ensureAtLeastOneSolutionType(options);
16296
16396
  return {
16297
16397
  listing: true,
16298
16398
  search: true,
16399
+ ...options,
16299
16400
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine).summary() : buildSearch(engine).summary()
16300
16401
  };
16301
16402
  }
@@ -16415,7 +16516,7 @@ function loadNotifyTriggerReducers(engine) {
16415
16516
  return true;
16416
16517
  }
16417
16518
 
16418
- // src/ssr-next/commerce/controllers/triggers/headless-notify-trigger.ssr.ts
16519
+ // src/ssr/commerce/controllers/triggers/headless-notify-trigger.ssr.ts
16419
16520
  function defineNotifyTrigger() {
16420
16521
  return {
16421
16522
  listing: true,
@@ -16455,7 +16556,7 @@ function loadQueryTriggerReducers(engine) {
16455
16556
  return true;
16456
16557
  }
16457
16558
 
16458
- // src/ssr-next/commerce/controllers/triggers/headless-query-trigger.ssr.ts
16559
+ // src/ssr/commerce/controllers/triggers/headless-query-trigger.ssr.ts
16459
16560
  function defineQueryTrigger() {
16460
16561
  return {
16461
16562
  search: true,
@@ -16496,7 +16597,7 @@ function loadRedirectionReducers(engine) {
16496
16597
  return true;
16497
16598
  }
16498
16599
 
16499
- // src/ssr-next/commerce/controllers/triggers/headless-redirection-trigger.ssr.ts
16600
+ // src/ssr/commerce/controllers/triggers/headless-redirection-trigger.ssr.ts
16500
16601
  function defineRedirectionTrigger() {
16501
16602
  return {
16502
16603
  search: true,
@@ -17788,325 +17889,7 @@ function createCommerceAPIClient(configuration2, logger) {
17788
17889
  });
17789
17890
  }
17790
17891
 
17791
- // src/ssr-next/common/builders/controller-builder.ts
17792
- var ControllerBuilder = class {
17793
- constructor(definition3, engine, props) {
17794
- __publicField(this, "_definition");
17795
- __publicField(this, "_engine");
17796
- __publicField(this, "_props");
17797
- __publicField(this, "_additionalArgs", []);
17798
- this._definition = definition3;
17799
- this._engine = engine;
17800
- this._props = props;
17801
- }
17802
- withAdditionalArgs(additionalArgs = []) {
17803
- this._additionalArgs = additionalArgs;
17804
- return this;
17805
- }
17806
- build() {
17807
- if ("build" in this._definition && typeof this._definition.build === "function") {
17808
- return this.buildWithoutProps();
17809
- }
17810
- if ("buildWithProps" in this._definition && typeof this._definition.buildWithProps === "function") {
17811
- return this.buildWithProps();
17812
- }
17813
- throw new Error(
17814
- "Controller definition must have a build or buildWithProps method."
17815
- );
17816
- }
17817
- buildWithoutProps() {
17818
- const buildFn = this._definition.build;
17819
- return buildFn(this._engine, ...this._additionalArgs);
17820
- }
17821
- buildWithProps() {
17822
- const buildWithPropsFn = this._definition.buildWithProps;
17823
- const controller = buildWithPropsFn(
17824
- this._engine,
17825
- this._props,
17826
- ...this._additionalArgs
17827
- );
17828
- return { ...controller, initialState: controller.state };
17829
- }
17830
- };
17831
-
17832
- // src/ssr-next/common/builders/static-controller-builder.ts
17833
- var StaticControllerBuilder = class {
17834
- constructor() {
17835
- __publicField(this, "_state");
17836
- __publicField(this, "_initialState");
17837
- }
17838
- withState(state) {
17839
- this._state = clone(state);
17840
- return this;
17841
- }
17842
- withInitialState(initialState) {
17843
- this._initialState = clone(initialState);
17844
- return this;
17845
- }
17846
- /**
17847
- * Builds and returns the static controller state object
17848
- */
17849
- build() {
17850
- const result = {
17851
- state: this._state
17852
- };
17853
- if (this._initialState) {
17854
- result.initialState = this._initialState;
17855
- }
17856
- return result;
17857
- }
17858
- };
17859
- function createStaticControllerBuilder(controller) {
17860
- const builder = new StaticControllerBuilder().withState(controller.state);
17861
- if ("initialState" in controller) {
17862
- builder.withInitialState(
17863
- controller.initialState
17864
- );
17865
- }
17866
- return builder;
17867
- }
17868
-
17869
- // src/ssr-next/commerce/controller-utils.ts
17870
- function createStaticState({
17871
- searchActions,
17872
- controllers
17873
- }) {
17874
- return {
17875
- controllers: mapObject(
17876
- controllers,
17877
- (controller) => createStaticControllerBuilder(controller).build()
17878
- ),
17879
- searchActions: searchActions.map((action) => clone(action))
17880
- };
17881
- }
17882
- function buildControllerDefinitions({
17883
- definitionsMap,
17884
- engine,
17885
- solutionType,
17886
- propsMap
17887
- }) {
17888
- const controllerMap = mapObject(definitionsMap, (definition3, key) => {
17889
- const unavailableInSolutionType = () => !(solutionType in definition3) || solutionType in definition3 && definition3[solutionType] === false;
17890
- const props = propsMap?.[key];
17891
- if (unavailableInSolutionType()) {
17892
- return null;
17893
- }
17894
- return new ControllerBuilder(definition3, engine, props).withAdditionalArgs([solutionType]).build();
17895
- });
17896
- return filterObject(
17897
- controllerMap,
17898
- (value) => value !== null
17899
- );
17900
- }
17901
-
17902
- // src/ssr-next/commerce/utils/controller-wiring.ts
17903
- var import_bueno90 = require("@coveo/bueno");
17904
-
17905
- // src/ssr-next/commerce/utils/recommendation-filter.ts
17906
- function isRecommendationDefinition(controllerDefinition) {
17907
- const hasRecommendationFlag = "recommendation" in controllerDefinition && controllerDefinition.recommendation === true;
17908
- const hasValidSlotId = recommendationInternalOptionKey in controllerDefinition && "slotId" in controllerDefinition[recommendationInternalOptionKey];
17909
- return hasRecommendationFlag && hasValidSlotId;
17910
- }
17911
- function getRecommendationDefinitions(controllerDefinitions) {
17912
- const recommendationMap = {};
17913
- for (const [name, definition3] of Object.entries(controllerDefinitions)) {
17914
- if (isRecommendationDefinition(definition3)) {
17915
- recommendationMap[name] = definition3;
17916
- }
17917
- }
17918
- return recommendationMap;
17919
- }
17920
- function filterRecommendationControllers(controllers, controllerDefinitions) {
17921
- const slotIdSet = /* @__PURE__ */ new Set();
17922
- const ensureSingleRecommendationPerSlot = (slotId) => {
17923
- throw new MultipleRecommendationError(slotId);
17924
- };
17925
- const filtered = Object.entries(controllerDefinitions).filter(
17926
- ([_, value]) => {
17927
- if (!isRecommendationDefinition(value)) {
17928
- return false;
17929
- }
17930
- const { slotId } = value[recommendationInternalOptionKey];
17931
- const key = slotId;
17932
- if (slotIdSet.has(slotId)) {
17933
- ensureSingleRecommendationPerSlot(slotId);
17934
- return false;
17935
- }
17936
- slotIdSet.add(key);
17937
- return true;
17938
- }
17939
- );
17940
- const name = filtered.map(([name2, _]) => name2);
17941
- return {
17942
- /**
17943
- * Go through all the controllers passed in argument and only refresh recommendation controllers.
17944
- *
17945
- * @param controllers - A record of all controllers where the key is the controller name and the value is the controller instance.
17946
- * @param controllerNames - A list of all recommendation controllers to refresh
17947
- */
17948
- refresh(whitelist) {
17949
- if (whitelist === void 0) {
17950
- return;
17951
- }
17952
- const isRecommendationController = (key) => name.includes(key) && whitelist.includes(key);
17953
- for (const [key, controller] of Object.entries(controllers)) {
17954
- if (isRecommendationController(key)) {
17955
- controller.refresh?.();
17956
- }
17957
- }
17958
- }
17959
- };
17960
- }
17961
-
17962
- // src/ssr-next/commerce/utils/controller-wiring.ts
17963
- var requiredDefinition = {
17964
- context: new import_bueno90.RecordValue({
17965
- options: { required: true },
17966
- values: contextDefinition
17967
- })
17968
- };
17969
- var listingDefinition = {
17970
- ...requiredDefinition,
17971
- searchParams: new import_bueno90.RecordValue({
17972
- values: parametersDefinition
17973
- })
17974
- };
17975
- var standaloneDefinition = {
17976
- ...requiredDefinition
17977
- };
17978
- var searchDefinition = {
17979
- ...requiredDefinition,
17980
- searchParams: new import_bueno90.RecordValue({
17981
- options: { required: true },
17982
- values: { query: requiredEmptyAllowedString, ...parametersDefinition }
17983
- })
17984
- };
17985
- var recommendationsDefinition = (recommendationName) => ({
17986
- ...requiredDefinition,
17987
- recommendations: new import_bueno90.ArrayValue({
17988
- each: new import_bueno90.StringValue({
17989
- required: true,
17990
- constrainTo: recommendationName,
17991
- emptyAllowed: false
17992
- }),
17993
- required: true
17994
- }),
17995
- productId: nonEmptyString
17996
- });
17997
- var listingDefinitionSchema = new import_bueno90.Schema(listingDefinition);
17998
- var searchDefinitionSchema = new import_bueno90.Schema(searchDefinition);
17999
- var standaloneDefinitionSchema = new import_bueno90.Schema(standaloneDefinition);
18000
- var recommendationsDefinitionSchema = (recommendationName) => new import_bueno90.Schema(recommendationsDefinition(recommendationName));
18001
- function validateBuildConfig(solutionType, controllerDefinitions, buildConfig) {
18002
- const validationMap = {
18003
- ["listing" /* listing */]: listingDefinitionSchema,
18004
- ["search" /* search */]: searchDefinitionSchema,
18005
- ["standalone" /* standalone */]: standaloneDefinitionSchema,
18006
- ["recommendation" /* recommendation */]: recommendationsDefinitionSchema(
18007
- Object.keys(getRecommendationDefinitions(controllerDefinitions))
18008
- )
18009
- };
18010
- const schema = validationMap[solutionType];
18011
- schema.validate(buildConfig);
18012
- }
18013
- var ControllerWirer = class {
18014
- constructor(buildConfig, controllerDefinitions, controllerProps) {
18015
- this.buildConfig = buildConfig;
18016
- this.controllerDefinitions = controllerDefinitions;
18017
- this.controllerProps = controllerProps;
18018
- }
18019
- wireParameterManager() {
18020
- if (!this.controllerDefinitions?.parameterManager) return;
18021
- const { searchParams } = this.buildConfig;
18022
- const { query: query2, ...rest } = searchParams || {};
18023
- const parameters = {
18024
- ...query2 && { q: query2 },
18025
- ...rest && typeof rest === "object" ? rest : {}
18026
- };
18027
- this.controllerProps.parameterManager = {
18028
- initialState: { parameters }
18029
- };
18030
- }
18031
- wireContext() {
18032
- if (!this.controllerDefinitions?.context) return;
18033
- const { context } = this.buildConfig;
18034
- this.controllerProps.context = {
18035
- initialState: {
18036
- ...context
18037
- }
18038
- };
18039
- }
18040
- wireCart() {
18041
- if (!this.controllerDefinitions?.cart || !this.buildConfig.cart) return;
18042
- this.controllerProps.cart = {
18043
- initialState: this.buildConfig.cart
18044
- };
18045
- }
18046
- wireRecommendations() {
18047
- if (!("recommendations" in this.buildConfig)) {
18048
- return;
18049
- }
18050
- for (const recController in this.controllerDefinitions) {
18051
- if (isRecommendationDefinition(this.controllerDefinitions[recController])) {
18052
- this.controllerProps[recController] = {
18053
- initialState: {
18054
- ..."productId" in this.buildConfig && {
18055
- productId: this.buildConfig.productId
18056
- }
18057
- }
18058
- };
18059
- }
18060
- }
18061
- }
18062
- /**
18063
- * Wires all controllers based on solution type and controller definitions.
18064
- * Handles the complete wiring process in a sequential manner.
18065
- */
18066
- wire(solutionType) {
18067
- this.wireCart();
18068
- this.wireContext();
18069
- switch (solutionType) {
18070
- case "search" /* search */:
18071
- case "listing" /* listing */: {
18072
- this.wireParameterManager();
18073
- break;
18074
- }
18075
- case "recommendation" /* recommendation */: {
18076
- this.wireRecommendations();
18077
- break;
18078
- }
18079
- case "standalone" /* standalone */:
18080
- break;
18081
- default: {
18082
- const _exhaustiveCheck = solutionType;
18083
- throw new Error(`Unsupported solution type: ${_exhaustiveCheck}`);
18084
- }
18085
- }
18086
- }
18087
- };
18088
- function wireControllerParams(solutionType, controllerDefinitions, buildConfig) {
18089
- validateBuildConfig(solutionType, controllerDefinitions, buildConfig);
18090
- const controllerProps = buildConfig.controllers ?? {};
18091
- new ControllerWirer(buildConfig, controllerDefinitions, controllerProps).wire(
18092
- solutionType
18093
- );
18094
- return controllerProps;
18095
- }
18096
-
18097
- // src/ssr-next/commerce/utils/engine-wiring.ts
18098
- function extendEngineConfiguration(configuration2, commonBuildOptions) {
18099
- const { cart, context } = commonBuildOptions;
18100
- return {
18101
- ...configuration2,
18102
- context: {
18103
- ...context
18104
- },
18105
- cart
18106
- };
18107
- }
18108
-
18109
- // src/ssr-next/commerce/factories/build-factory.ts
17892
+ // src/ssr/commerce/factories/build-factory.ts
18110
17893
  function isListingFetchCompletedAction(action) {
18111
17894
  return /^commerce\/productListing\/fetch\/(fulfilled|rejected)$/.test(
18112
17895
  action.type
@@ -18178,102 +17961,222 @@ function buildSSRCommerceEngine(solutionType, options, recommendationCount) {
18178
17961
  }
18179
17962
  };
18180
17963
  }
17964
+ function fetchActiveRecommendationControllers(controllerProps, solutionType) {
17965
+ return solutionType === "recommendation" /* recommendation */ ? Object.values(controllerProps).filter(
17966
+ (controller) => controller && typeof controller === "object" && "enabled" in controller && controller.enabled
17967
+ ).length : 0;
17968
+ }
18181
17969
  var buildFactory = (controllerDefinitions, options) => (solutionType) => async (...[buildOptions]) => {
18182
- const controllerProps = wireControllerParams(
18183
- solutionType,
18184
- controllerDefinitions,
18185
- buildOptions
18186
- );
18187
17970
  const logger = buildLogger(options.loggerOptions);
18188
17971
  if (!options.navigatorContextProvider) {
18189
17972
  logger.warn(
18190
17973
  "[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()"
18191
17974
  );
18192
17975
  }
18193
- const enabledRecommendationControllers = buildOptions && "recommendations" in buildOptions ? buildOptions?.recommendations.length : 0;
18194
- const engineOptions = {
18195
- ...options,
18196
- configuration: extendEngineConfiguration(
18197
- options.configuration,
18198
- buildOptions
18199
- )
18200
- // TODO: KIT-4754: remove non-null assertion operator
18201
- };
17976
+ const controllerProps = buildOptions && "controllers" in buildOptions ? buildOptions.controllers : {};
17977
+ const enabledRecommendationControllers = fetchActiveRecommendationControllers(controllerProps, solutionType);
18202
17978
  const engine = buildSSRCommerceEngine(
18203
17979
  solutionType,
18204
- engineOptions,
17980
+ buildOptions && "extend" in buildOptions && buildOptions?.extend ? await buildOptions.extend(options) : options,
18205
17981
  enabledRecommendationControllers
18206
17982
  );
18207
17983
  const controllers = buildControllerDefinitions({
18208
17984
  definitionsMap: controllerDefinitions ?? {},
18209
17985
  engine,
18210
17986
  solutionType,
18211
- propsMap: controllerProps
17987
+ propsMap: buildOptions && "controllers" in buildOptions ? buildOptions.controllers : {}
18212
17988
  });
18213
- if (buildOptions && "searchActions" in buildOptions) {
18214
- buildOptions.searchActions.forEach((action) => {
18215
- engine.dispatch(action);
18216
- });
18217
- }
18218
17989
  return {
18219
17990
  engine,
18220
17991
  controllers
18221
17992
  };
18222
17993
  };
18223
17994
 
18224
- // src/ssr-next/commerce/factories/hydrated-state-factory.ts
18225
- function hydratedStaticStateFactory(controllerDefinitions, options) {
18226
- return (solutionType) => async (...params) => {
18227
- const solutionTypeBuild = await buildFactory(
17995
+ // src/ssr/common/controller-utils.ts
17996
+ function composeFunction(parentFunction, children) {
17997
+ const newFunction = (...params) => parentFunction(...params);
17998
+ for (const [key, value] of Object.entries(children)) {
17999
+ newFunction[key] = value;
18000
+ }
18001
+ return newFunction;
18002
+ }
18003
+
18004
+ // src/ssr/commerce/factories/hydrated-state-factory.ts
18005
+ var hydratedStaticStateFactory = (controllerDefinitions, options) => (solutionType) => composeFunction(
18006
+ async (...params) => {
18007
+ const solutionTypeBuild = await buildFactory(controllerDefinitions, {
18008
+ ...options
18009
+ })(solutionType);
18010
+ const buildResult = await solutionTypeBuild(
18011
+ ...params
18012
+ );
18013
+ const staticStateBuild = await hydratedStaticStateFactory(
18228
18014
  controllerDefinitions,
18229
18015
  options
18230
18016
  )(solutionType);
18231
- const { engine, controllers } = await solutionTypeBuild(...params);
18232
- await engine.waitForRequestCompletedAction();
18233
- return { engine, controllers };
18234
- };
18235
- }
18017
+ const staticState = await staticStateBuild.fromBuildResult({
18018
+ buildResult,
18019
+ searchActions: params[0].searchActions
18020
+ });
18021
+ return staticState;
18022
+ },
18023
+ {
18024
+ fromBuildResult: async (...params) => {
18025
+ const [
18026
+ {
18027
+ buildResult: { engine, controllers },
18028
+ searchActions
18029
+ }
18030
+ ] = params;
18031
+ searchActions.forEach((action) => {
18032
+ engine.dispatch(action);
18033
+ });
18034
+ await engine.waitForRequestCompletedAction();
18035
+ return { engine, controllers };
18036
+ }
18037
+ }
18038
+ );
18236
18039
 
18237
- // src/ssr-next/commerce/factories/recommendation-hydrated-state-factory.ts
18040
+ // src/ssr/commerce/factories/recommendation-hydrated-state-factory.ts
18238
18041
  function hydratedRecommendationStaticStateFactory(controllerDefinitions, options) {
18239
- return async (...params) => {
18240
- const solutionTypeBuild = await buildFactory(
18241
- controllerDefinitions,
18242
- options
18243
- )("recommendation" /* recommendation */);
18244
- const { engine, controllers } = await solutionTypeBuild(...params);
18245
- await engine.waitForRequestCompletedAction();
18246
- return { engine, controllers };
18042
+ return composeFunction(
18043
+ async (...params) => {
18044
+ const solutionTypeBuild = await buildFactory(
18045
+ controllerDefinitions,
18046
+ options
18047
+ )("recommendation" /* recommendation */);
18048
+ const buildResult = await solutionTypeBuild(
18049
+ ...params
18050
+ );
18051
+ const staticState = await hydratedRecommendationStaticStateFactory(
18052
+ controllerDefinitions,
18053
+ options
18054
+ ).fromBuildResult({
18055
+ buildResult,
18056
+ searchActions: params[0].searchActions
18057
+ });
18058
+ return staticState;
18059
+ },
18060
+ {
18061
+ fromBuildResult: async (...params) => {
18062
+ const [
18063
+ {
18064
+ buildResult: { engine, controllers },
18065
+ searchActions
18066
+ }
18067
+ ] = params;
18068
+ searchActions.forEach((action) => {
18069
+ engine.dispatch(action);
18070
+ });
18071
+ await engine.waitForRequestCompletedAction();
18072
+ return { engine, controllers };
18073
+ }
18074
+ }
18075
+ );
18076
+ }
18077
+
18078
+ // src/ssr/commerce/utils/recommendation-filter.ts
18079
+ function filterRecommendationControllers(controllers, controllerDefinitions) {
18080
+ const slotIdSet = /* @__PURE__ */ new Set();
18081
+ const isRecommendationDefinition = (controllerDefinition) => {
18082
+ const isControllerRecommendation = "recommendation" in controllerDefinition && controllerDefinition.recommendation === true;
18083
+ const hasSlotId = recommendationInternalOptionKey in controllerDefinition && "slotId" in controllerDefinition[recommendationInternalOptionKey];
18084
+ return isControllerRecommendation && hasSlotId;
18085
+ };
18086
+ const ensureSingleRecommendationPerSlot = (slotId) => {
18087
+ throw new MultipleRecommendationError(slotId);
18088
+ };
18089
+ const filtered = Object.entries(controllerDefinitions).filter(
18090
+ ([_, value]) => {
18091
+ if (!isRecommendationDefinition(value)) {
18092
+ return false;
18093
+ }
18094
+ const { slotId } = value[recommendationInternalOptionKey];
18095
+ const key = slotId;
18096
+ if (slotIdSet.has(slotId)) {
18097
+ ensureSingleRecommendationPerSlot(slotId);
18098
+ return false;
18099
+ }
18100
+ slotIdSet.add(key);
18101
+ return true;
18102
+ }
18103
+ );
18104
+ const name = filtered.map(([name2, _]) => name2);
18105
+ return {
18106
+ /**
18107
+ * Go through all the controllers passed in argument and only refresh recommendation controllers.
18108
+ *
18109
+ * @param controllers - A record of all controllers where the key is the controller name and the value is the controller instance.
18110
+ * @param controllerNames - A list of all recommendation controllers to refresh
18111
+ */
18112
+ refresh(whitelist) {
18113
+ if (whitelist === void 0) {
18114
+ return;
18115
+ }
18116
+ const isRecommendationController = (key) => name.includes(key) && whitelist.includes(key);
18117
+ for (const [key, controller] of Object.entries(controllers)) {
18118
+ if (isRecommendationController(key)) {
18119
+ controller.refresh?.();
18120
+ }
18121
+ }
18122
+ }
18247
18123
  };
18248
18124
  }
18249
18125
 
18250
- // src/ssr-next/commerce/factories/recommendation-static-state-factory.ts
18126
+ // src/ssr/commerce/factories/recommendation-static-state-factory.ts
18251
18127
  function fetchRecommendationStaticStateFactory(controllerDefinitions, options) {
18252
- return async (...params) => {
18253
- const [props] = params;
18254
- const allowedRecommendationKeys = props?.recommendations;
18255
- const solutionTypeBuild = await buildFactory(
18256
- controllerDefinitions,
18257
- options
18258
- )("recommendation" /* recommendation */);
18259
- const { engine, controllers } = await solutionTypeBuild(...params);
18260
- filterRecommendationControllers(
18261
- controllers,
18262
- controllerDefinitions ?? {}
18263
- ).refresh(allowedRecommendationKeys);
18264
- const searchActions = await Promise.all(
18265
- engine.waitForRequestCompletedAction()
18266
- );
18267
- const staticState = createStaticState({
18268
- searchActions,
18269
- controllers
18270
- });
18271
- return {
18272
- ...params[0],
18273
- // TODO: KIT-4754: remove index access after no longer relying on OptionTuple type
18274
- ...staticState
18275
- };
18128
+ const getAllowedRecommendationKeys = (props) => {
18129
+ if (props && "controllers" in props) {
18130
+ const enabledRecommendationControllers = filterObject(
18131
+ props.controllers,
18132
+ (value) => Boolean(value.enabled)
18133
+ );
18134
+ return Object.keys(enabledRecommendationControllers);
18135
+ }
18136
+ return [];
18276
18137
  };
18138
+ return composeFunction(
18139
+ async (...params) => {
18140
+ const [props] = params;
18141
+ const allowedRecommendationKeys = getAllowedRecommendationKeys(props);
18142
+ const solutionTypeBuild = await buildFactory(
18143
+ controllerDefinitions,
18144
+ options
18145
+ )("recommendation" /* recommendation */);
18146
+ const buildResult = await solutionTypeBuild(
18147
+ ...params
18148
+ );
18149
+ const staticState = await fetchRecommendationStaticStateFactory(
18150
+ controllerDefinitions,
18151
+ options
18152
+ ).fromBuildResult({
18153
+ buildResult,
18154
+ allowedRecommendationKeys
18155
+ });
18156
+ return staticState;
18157
+ },
18158
+ {
18159
+ fromBuildResult: async (...params) => {
18160
+ const [
18161
+ {
18162
+ buildResult: { engine, controllers },
18163
+ allowedRecommendationKeys
18164
+ }
18165
+ ] = params;
18166
+ filterRecommendationControllers(
18167
+ controllers,
18168
+ controllerDefinitions ?? {}
18169
+ ).refresh(allowedRecommendationKeys);
18170
+ const searchActions = await Promise.all(
18171
+ engine.waitForRequestCompletedAction()
18172
+ );
18173
+ return createStaticState({
18174
+ searchActions,
18175
+ controllers
18176
+ });
18177
+ }
18178
+ }
18179
+ );
18277
18180
  }
18278
18181
 
18279
18182
  // src/utils/runtime.ts
@@ -18281,7 +18184,7 @@ function isBrowser2() {
18281
18184
  return typeof window !== "undefined" && typeof document !== "undefined";
18282
18185
  }
18283
18186
 
18284
- // src/ssr-next/common/augment-preprocess-request.ts
18187
+ // src/ssr/common/augment-preprocess-request.ts
18285
18188
  function augmentPreprocessRequestWithForwardedFor(options) {
18286
18189
  const originalPreprocessRequest = options.preprocessRequest;
18287
18190
  return async (request, clientOrigin, metadata) => {
@@ -18305,56 +18208,54 @@ function augmentPreprocessRequestWithForwardedFor(options) {
18305
18208
  };
18306
18209
  }
18307
18210
 
18308
- // src/ssr-next/commerce/factories/static-state-factory.ts
18309
- function fetchStaticStateFactory(controllerDefinitions, options) {
18310
- return (solutionType) => async (...params) => {
18311
- const solutionTypeBuild = await buildFactory(
18312
- controllerDefinitions,
18313
- options
18314
- )(solutionType);
18315
- const { engine, controllers } = await solutionTypeBuild(...params);
18211
+ // src/ssr/commerce/factories/static-state-factory.ts
18212
+ var fetchStaticStateFactory = (controllerDefinitions, options) => (solutionType) => composeFunction(
18213
+ async (...params) => {
18214
+ const solutionTypeBuild = await buildFactory(controllerDefinitions, {
18215
+ ...options
18216
+ })(solutionType);
18217
+ const buildResult = await solutionTypeBuild(...params);
18316
18218
  options.configuration.preprocessRequest = augmentPreprocessRequestWithForwardedFor({
18317
18219
  preprocessRequest: options.configuration.preprocessRequest,
18318
18220
  navigatorContextProvider: options.navigatorContextProvider,
18319
18221
  loggerOptions: options.loggerOptions
18320
18222
  });
18321
- switch (solutionType) {
18322
- case "listing" /* listing */:
18323
- buildProductListing(engine).executeFirstRequest();
18324
- break;
18325
- case "search" /* search */:
18326
- buildSearch(engine).executeFirstSearch();
18327
- break;
18328
- }
18329
- const searchActions = await Promise.all(
18330
- engine.waitForRequestCompletedAction()
18331
- );
18332
- const staticState = createStaticState({
18333
- searchActions,
18334
- controllers
18223
+ const staticStateBuild = await fetchStaticStateFactory(
18224
+ controllerDefinitions,
18225
+ options
18226
+ )(solutionType);
18227
+ const staticState = await staticStateBuild.fromBuildResult({
18228
+ buildResult
18335
18229
  });
18336
- return {
18337
- ...params[0],
18338
- // TODO: KIT-4754: remove index access after no longer relying on OptionTuple type
18339
- ...staticState
18340
- };
18341
- };
18342
- }
18343
-
18344
- // src/ssr-next/commerce/validation/controller-validation.ts
18345
- var validateControllerNames = (controllers) => {
18346
- const reservedNames = ["context", "cart", "parameterManager"];
18347
- const invalidNames = Object.keys(controllers).filter(
18348
- (name) => reservedNames.includes(name)
18349
- );
18350
- if (invalidNames.length > 0) {
18351
- throw new Error(
18352
- `Reserved controller names found: ${invalidNames.join(", ")}. Please use different controller names than ${reservedNames.join(", ")}.`
18353
- );
18230
+ return staticState;
18231
+ },
18232
+ {
18233
+ fromBuildResult: async (...params) => {
18234
+ const [
18235
+ {
18236
+ buildResult: { engine, controllers }
18237
+ }
18238
+ ] = params;
18239
+ switch (solutionType) {
18240
+ case "listing" /* listing */:
18241
+ buildProductListing(engine).executeFirstRequest();
18242
+ break;
18243
+ case "search" /* search */:
18244
+ buildSearch(engine).executeFirstSearch();
18245
+ break;
18246
+ }
18247
+ const searchActions = await Promise.all(
18248
+ engine.waitForRequestCompletedAction()
18249
+ );
18250
+ return createStaticState({
18251
+ searchActions,
18252
+ controllers
18253
+ });
18254
+ }
18354
18255
  }
18355
- };
18256
+ );
18356
18257
 
18357
- // src/ssr-next/commerce/engine/commerce-engine.ssr.ts
18258
+ // src/ssr/commerce/engine/commerce-engine.ssr.ts
18358
18259
  function defineCommerceEngine(options) {
18359
18260
  const { controllers: controllerDefinitions, ...engineOptions } = options;
18360
18261
  const getOptions = () => engineOptions;
@@ -18365,55 +18266,59 @@ function defineCommerceEngine(options) {
18365
18266
  const setAccessToken = (accessToken) => {
18366
18267
  engineOptions.configuration.accessToken = accessToken;
18367
18268
  };
18368
- controllerDefinitions && validateControllerNames(controllerDefinitions);
18369
- const augmentedControllerDefinition = {
18370
- ...controllerDefinitions,
18371
- parameterManager: defineParameterManager(),
18372
- context: defineContext(),
18373
- cart: defineCart()
18374
- };
18269
+ const build = buildFactory(
18270
+ controllerDefinitions,
18271
+ getOptions()
18272
+ );
18375
18273
  const fetchStaticState = fetchStaticStateFactory(
18376
- augmentedControllerDefinition,
18274
+ controllerDefinitions,
18377
18275
  getOptions()
18378
18276
  );
18379
18277
  const hydrateStaticState = hydratedStaticStateFactory(
18380
- augmentedControllerDefinition,
18278
+ controllerDefinitions,
18381
18279
  getOptions()
18382
18280
  );
18383
18281
  const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(
18384
- augmentedControllerDefinition,
18282
+ controllerDefinitions,
18385
18283
  getOptions()
18386
18284
  );
18387
18285
  const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(
18388
- augmentedControllerDefinition,
18286
+ controllerDefinitions,
18389
18287
  getOptions()
18390
18288
  );
18391
- const commonMethods = {
18392
- setNavigatorContextProvider,
18393
- getAccessToken,
18394
- setAccessToken
18395
- };
18396
18289
  return {
18397
18290
  listingEngineDefinition: {
18291
+ build: build("listing" /* listing */),
18398
18292
  fetchStaticState: fetchStaticState("listing" /* listing */),
18399
18293
  hydrateStaticState: hydrateStaticState("listing" /* listing */),
18400
- ...commonMethods
18294
+ setNavigatorContextProvider,
18295
+ getAccessToken,
18296
+ setAccessToken
18401
18297
  },
18402
18298
  searchEngineDefinition: {
18299
+ build: build("search" /* search */),
18403
18300
  fetchStaticState: fetchStaticState("search" /* search */),
18404
18301
  hydrateStaticState: hydrateStaticState("search" /* search */),
18405
- ...commonMethods
18302
+ setNavigatorContextProvider,
18303
+ getAccessToken,
18304
+ setAccessToken
18406
18305
  },
18407
18306
  recommendationEngineDefinition: {
18307
+ build: build("recommendation" /* recommendation */),
18408
18308
  fetchStaticState: fetchRecommendationStaticState,
18409
18309
  hydrateStaticState: hydrateRecommendationStaticState,
18410
- ...commonMethods
18310
+ setNavigatorContextProvider,
18311
+ getAccessToken,
18312
+ setAccessToken
18411
18313
  },
18412
18314
  // TODO KIT-3738 : The standaloneEngineDefinition should not be async since no request is sent to the API
18413
18315
  standaloneEngineDefinition: {
18316
+ build: build("standalone" /* standalone */),
18414
18317
  fetchStaticState: fetchStaticState("standalone" /* standalone */),
18415
18318
  hydrateStaticState: hydrateStaticState("standalone" /* standalone */),
18416
- ...commonMethods
18319
+ setNavigatorContextProvider,
18320
+ getAccessToken,
18321
+ setAccessToken
18417
18322
  }
18418
18323
  };
18419
18324
  }
@@ -18644,7 +18549,7 @@ function loadSortActions(engine) {
18644
18549
  var import_toolkit126 = require("@reduxjs/toolkit");
18645
18550
 
18646
18551
  // src/features/standalone-search-box-set/standalone-search-box-set-actions.ts
18647
- var import_bueno91 = require("@coveo/bueno");
18552
+ var import_bueno90 = require("@coveo/bueno");
18648
18553
  var import_toolkit125 = require("@reduxjs/toolkit");
18649
18554
 
18650
18555
  // src/api/search/plan/plan-endpoint.ts
@@ -18681,7 +18586,7 @@ var registerStandaloneSearchBox2 = (0, import_toolkit125.createAction)(
18681
18586
  (payload) => validatePayload(payload, {
18682
18587
  id: requiredNonEmptyString,
18683
18588
  redirectionUrl: requiredNonEmptyString,
18684
- overwrite: new import_bueno91.BooleanValue({ required: false })
18589
+ overwrite: new import_bueno90.BooleanValue({ required: false })
18685
18590
  })
18686
18591
  );
18687
18592
  var updateStandaloneSearchBoxRedirectionUrl2 = (0, import_toolkit125.createAction)(
@@ -18712,7 +18617,7 @@ var fetchRedirectUrl2 = (0, import_toolkit125.createAsyncThunk)(
18712
18617
  rejectWithValue,
18713
18618
  extra: { apiClient, validatePayload: validatePayload2, navigatorContext }
18714
18619
  }) => {
18715
- validatePayload2(payload, { id: new import_bueno91.StringValue({ emptyAllowed: false }) });
18620
+ validatePayload2(payload, { id: new import_bueno90.StringValue({ emptyAllowed: false }) });
18716
18621
  const request = await buildPlanRequest2(getState(), navigatorContext);
18717
18622
  const response = await apiClient.plan(request);
18718
18623
  if (isErrorResponse(response)) {
@@ -18855,13 +18760,13 @@ function loadTriggersActions(engine) {
18855
18760
  var import_toolkit129 = require("@reduxjs/toolkit");
18856
18761
 
18857
18762
  // src/features/folding/folding-actions.ts
18858
- var import_bueno92 = require("@coveo/bueno");
18763
+ var import_bueno91 = require("@coveo/bueno");
18859
18764
  var import_toolkit127 = require("@reduxjs/toolkit");
18860
18765
  var foldingOptionsSchemaDefinition = {
18861
- collectionField: new import_bueno92.StringValue({ emptyAllowed: false, required: false }),
18862
- parentField: new import_bueno92.StringValue({ emptyAllowed: false, required: false }),
18863
- childField: new import_bueno92.StringValue({ emptyAllowed: false, required: false }),
18864
- numberOfFoldedResults: new import_bueno92.NumberValue({ min: 0, required: false })
18766
+ collectionField: new import_bueno91.StringValue({ emptyAllowed: false, required: false }),
18767
+ parentField: new import_bueno91.StringValue({ emptyAllowed: false, required: false }),
18768
+ childField: new import_bueno91.StringValue({ emptyAllowed: false, required: false }),
18769
+ numberOfFoldedResults: new import_bueno91.NumberValue({ min: 0, required: false })
18865
18770
  };
18866
18771
  var registerFolding = (0, import_toolkit127.createAction)(
18867
18772
  "folding/register",
@@ -18999,12 +18904,12 @@ var fieldsReducer = (0, import_toolkit129.createReducer)(
18999
18904
  );
19000
18905
 
19001
18906
  // src/features/templates/templates-manager.ts
19002
- var import_bueno93 = require("@coveo/bueno");
19003
- var templateSchema = new import_bueno93.Schema({
19004
- content: new import_bueno93.Value({ required: true }),
19005
- conditions: new import_bueno93.Value({ required: true }),
19006
- priority: new import_bueno93.NumberValue({ required: false, default: 0, min: 0 }),
19007
- fields: new import_bueno93.ArrayValue({
18907
+ var import_bueno92 = require("@coveo/bueno");
18908
+ var templateSchema = new import_bueno92.Schema({
18909
+ content: new import_bueno92.Value({ required: true }),
18910
+ conditions: new import_bueno92.Value({ required: true }),
18911
+ priority: new import_bueno92.NumberValue({ required: false, default: 0, min: 0 }),
18912
+ fields: new import_bueno92.ArrayValue({
19008
18913
  required: false,
19009
18914
  each: requiredNonEmptyString
19010
18915
  })
@@ -19017,7 +18922,7 @@ function buildTemplatesManager() {
19017
18922
  (condition) => condition instanceof Function
19018
18923
  );
19019
18924
  if (!areConditionsValid) {
19020
- throw new import_bueno93.SchemaValidationError(
18925
+ throw new import_bueno92.SchemaValidationError(
19021
18926
  "Each template condition should be a function that takes a Result or Product as an argument and returns a boolean"
19022
18927
  );
19023
18928
  }
@@ -19078,10 +18983,10 @@ function loadResultTemplatesManagerReducers(engine) {
19078
18983
  }
19079
18984
 
19080
18985
  // src/features/commerce/parameters/parameters-serializer.ssr.ts
19081
- var import_bueno95 = require("@coveo/bueno");
18986
+ var import_bueno94 = require("@coveo/bueno");
19082
18987
 
19083
18988
  // src/features/search-parameters/search-parameter-utils.ts
19084
- var import_bueno94 = require("@coveo/bueno");
18989
+ var import_bueno93 = require("@coveo/bueno");
19085
18990
  function toArray(value) {
19086
18991
  return Array.isArray(value) ? value : [value];
19087
18992
  }
@@ -19126,7 +19031,7 @@ function wipeSearchParamsFromUrl(urlSearchParams) {
19126
19031
  return previousSearchParams;
19127
19032
  }
19128
19033
  function applyToUrlSearchParam(urlSearchParams, previousState, pair) {
19129
- if ((0, import_bueno95.isNullOrUndefined)(pair[1])) {
19034
+ if ((0, import_bueno94.isNullOrUndefined)(pair[1])) {
19130
19035
  return;
19131
19036
  }
19132
19037
  if (isSortPair(pair)) {
@@ -19184,7 +19089,7 @@ function isValidBasicKey3(key) {
19184
19089
  return key in supportedBasicParameters;
19185
19090
  }
19186
19091
  function extendSearchParams(commerceSearchParams, key, value) {
19187
- if ((0, import_bueno95.isNullOrUndefined)(value)) {
19092
+ if ((0, import_bueno94.isNullOrUndefined)(value)) {
19188
19093
  return;
19189
19094
  }
19190
19095
  if (key === "sortCriteria") {
@@ -19291,13 +19196,13 @@ function addFacetValuesToSearchParams(facetId2, paramKey) {
19291
19196
  }
19292
19197
 
19293
19198
  // src/features/commerce/product-templates/product-templates-helpers.ts
19294
- var import_bueno96 = require("@coveo/bueno");
19199
+ var import_bueno95 = require("@coveo/bueno");
19295
19200
  var getProductProperty = (product, property) => {
19296
19201
  const anyProduct = product;
19297
- if (!(0, import_bueno96.isNullOrUndefined)(anyProduct[property])) {
19202
+ if (!(0, import_bueno95.isNullOrUndefined)(anyProduct[property])) {
19298
19203
  return anyProduct[property];
19299
19204
  }
19300
- if (!(0, import_bueno96.isNullOrUndefined)(product.additionalFields[property])) {
19205
+ if (!(0, import_bueno95.isNullOrUndefined)(product.additionalFields[property])) {
19301
19206
  return product.additionalFields[property];
19302
19207
  }
19303
19208
  return null;
@@ -19305,14 +19210,14 @@ var getProductProperty = (product, property) => {
19305
19210
  var fieldsMustBeDefined = (fieldNames) => {
19306
19211
  return (product) => {
19307
19212
  return fieldNames.every(
19308
- (fieldName) => !(0, import_bueno96.isNullOrUndefined)(getProductProperty(product, fieldName))
19213
+ (fieldName) => !(0, import_bueno95.isNullOrUndefined)(getProductProperty(product, fieldName))
19309
19214
  );
19310
19215
  };
19311
19216
  };
19312
19217
  var fieldsMustNotBeDefined = (fieldNames) => {
19313
19218
  return (product) => {
19314
19219
  return fieldNames.every(
19315
- (fieldName) => (0, import_bueno96.isNullOrUndefined)(getProductProperty(product, fieldName))
19220
+ (fieldName) => (0, import_bueno95.isNullOrUndefined)(getProductProperty(product, fieldName))
19316
19221
  );
19317
19222
  };
19318
19223
  };
@@ -19338,7 +19243,7 @@ var fieldMustNotMatch = (fieldName, disallowedValues) => {
19338
19243
  };
19339
19244
  var getFieldValuesFromProduct = (fieldName, product) => {
19340
19245
  const rawValue = getProductProperty(product, fieldName);
19341
- return (0, import_bueno96.isArray)(rawValue) ? rawValue : [rawValue];
19246
+ return (0, import_bueno95.isArray)(rawValue) ? rawValue : [rawValue];
19342
19247
  };
19343
19248
  var ProductTemplatesHelpers = {
19344
19249
  getProductProperty,
@@ -19640,6 +19545,7 @@ function getBooleanOperatorSymbol(operator) {
19640
19545
  }
19641
19546
  // Annotate the CommonJS export names for ESM import in node:
19642
19547
  0 && (module.exports = {
19548
+ Kind,
19643
19549
  ProductTemplatesHelpers,
19644
19550
  SolutionType,
19645
19551
  SortBy,