@coveo/headless 3.30.0-pre.402acfe52c → 3.30.0-pre.ea0fa3a1da

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,10 +46,9 @@ 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.index.ts
50
- var ssr_commerce_index_exports = {};
51
- __export(ssr_commerce_index_exports, {
52
- Kind: () => Kind,
49
+ // src/ssr-commerce-next.index.ts
50
+ var ssr_commerce_next_index_exports = {};
51
+ __export(ssr_commerce_next_index_exports, {
53
52
  ProductTemplatesHelpers: () => ProductTemplatesHelpers,
54
53
  SolutionType: () => SolutionType,
55
54
  SortBy: () => SortBy,
@@ -116,7 +115,7 @@ __export(ssr_commerce_index_exports, {
116
115
  parseCriterionExpression: () => parseCriterionExpression,
117
116
  validateRelativeDate: () => validateRelativeDate
118
117
  });
119
- module.exports = __toCommonJS(ssr_commerce_index_exports);
118
+ module.exports = __toCommonJS(ssr_commerce_next_index_exports);
120
119
 
121
120
  // src/app/commerce-engine/commerce-engine-configuration.ts
122
121
  var import_bueno5 = require("@coveo/bueno");
@@ -468,7 +467,7 @@ var import_bueno8 = require("@coveo/bueno");
468
467
  var import_toolkit3 = require("@reduxjs/toolkit");
469
468
 
470
469
  // src/utils/version.ts
471
- var VERSION = "3.30.0-pre.402acfe52c";
470
+ var VERSION = "3.30.0-pre.ea0fa3a1da";
472
471
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
473
472
 
474
473
  // src/features/configuration/configuration-actions.ts
@@ -14056,7 +14055,7 @@ function loadBaseSearchReducers(engine) {
14056
14055
  return true;
14057
14056
  }
14058
14057
 
14059
- // src/ssr/commerce/types/controller-constants.ts
14058
+ // src/ssr-next/commerce/types/controller-constants.ts
14060
14059
  var SolutionType = /* @__PURE__ */ ((SolutionType2) => {
14061
14060
  SolutionType2["search"] = "search";
14062
14061
  SolutionType2["listing"] = "listing";
@@ -14069,92 +14068,11 @@ var recommendationInternalOptionKey = Symbol.for(
14069
14068
  recommendationOptionKey
14070
14069
  );
14071
14070
 
14072
- // src/ssr/common/errors.ts
14073
- var InvalidControllerDefinition = class extends Error {
14074
- constructor() {
14075
- super();
14076
- this.name = "InvalidControllerDefinition";
14077
- this.message = `A controller must be defined for at least one solution type: ${Object.keys(
14078
- SolutionType
14079
- ).map((s) => s.toLowerCase()).join(", ")}`;
14080
- }
14081
- };
14082
- var MissingControllerProps = class extends Error {
14083
- constructor(controller) {
14084
- super();
14085
- this.name = "MissingControllerProps";
14086
- this.message = `${controller} props are required but were undefined. Ensure they are included when calling \`fetchStaticState\` or \`hydrateStaticState\`.`;
14087
- }
14088
- };
14089
- var MultipleRecommendationError = class extends Error {
14090
- constructor(slotId) {
14091
- super();
14092
- this.name = "MultipleRecommendationError";
14093
- this.message = `Multiple recommendation controllers found for the same slotId: ${slotId}. Only one recommendation controller per slotId is supported.`;
14094
- }
14095
- };
14096
-
14097
- // src/ssr/commerce/controller-utils.ts
14098
- function hasKindProperty(controller) {
14099
- return "_kind" in controller;
14100
- }
14101
- function createStaticState({
14102
- searchActions,
14103
- controllers
14104
- }) {
14105
- return {
14106
- controllers: mapObject(controllers, (controller) => ({
14107
- state: clone(controller.state),
14108
- ...hasKindProperty(controller) && { _kind: controller._kind }
14109
- })),
14110
- searchActions: searchActions.map((action) => clone(action))
14111
- };
14112
- }
14113
- function buildControllerFromDefinition({
14114
- definition: definition3,
14115
- engine,
14116
- solutionType,
14117
- props
14118
- }) {
14119
- return "build" in definition3 ? definition3.build(engine, solutionType) : definition3.buildWithProps(engine, props, solutionType);
14120
- }
14121
- function buildControllerDefinitions({
14122
- definitionsMap,
14123
- engine,
14124
- solutionType,
14125
- propsMap
14126
- }) {
14127
- const controllerMap = mapObject(definitionsMap, (definition3, key) => {
14128
- const unavailableInSolutionType = () => !(solutionType in definition3) || solutionType in definition3 && definition3[solutionType] === false;
14129
- const props = propsMap?.[key];
14130
- if (unavailableInSolutionType()) {
14131
- return null;
14132
- }
14133
- return buildControllerFromDefinition({
14134
- definition: definition3,
14135
- engine,
14136
- solutionType,
14137
- props
14138
- });
14139
- });
14140
- return filterObject(
14141
- controllerMap,
14142
- (value) => value !== null
14143
- );
14144
- }
14145
- function ensureAtLeastOneSolutionType(options) {
14146
- if (options?.listing === false && options?.search === false) {
14147
- throw new InvalidControllerDefinition();
14148
- }
14149
- }
14150
-
14151
- // src/ssr/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.ts
14152
- function defineBreadcrumbManager(options) {
14153
- ensureAtLeastOneSolutionType(options);
14071
+ // src/ssr-next/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.ts
14072
+ function defineBreadcrumbManager() {
14154
14073
  return {
14155
14074
  listing: true,
14156
14075
  search: true,
14157
- ...options,
14158
14076
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine).breadcrumbManager() : buildSearch(engine).breadcrumbManager()
14159
14077
  };
14160
14078
  }
@@ -14370,26 +14288,7 @@ function loadBaseCartReducers(engine) {
14370
14288
  return true;
14371
14289
  }
14372
14290
 
14373
- // src/ssr/commerce/types/kind.ts
14374
- var Kind = /* @__PURE__ */ ((Kind2) => {
14375
- Kind2["Cart"] = "CART";
14376
- Kind2["Context"] = "CONTEXT";
14377
- Kind2["ParameterManager"] = "PARAMETER_MANAGER";
14378
- Kind2["Recommendations"] = "RECOMMENDATIONS";
14379
- return Kind2;
14380
- })(Kind || {});
14381
- function createControllerWithKind(controller, kind) {
14382
- const copy = Object.defineProperties(
14383
- {},
14384
- Object.getOwnPropertyDescriptors(controller)
14385
- );
14386
- Object.defineProperty(copy, "_kind", {
14387
- value: kind
14388
- });
14389
- return copy;
14390
- }
14391
-
14392
- // src/ssr/commerce/controllers/cart/headless-cart.ssr.ts
14291
+ // src/ssr-next/commerce/controllers/cart/headless-cart.ssr.ts
14393
14292
  function defineCart() {
14394
14293
  return {
14395
14294
  listing: true,
@@ -14397,11 +14296,9 @@ function defineCart() {
14397
14296
  standalone: true,
14398
14297
  recommendation: true,
14399
14298
  buildWithProps: (engine, props) => {
14400
- if (props === void 0) {
14401
- throw new MissingControllerProps("CART" /* Cart */);
14402
- }
14403
- const controller = buildCart(engine, { initialState: props.initialState });
14404
- return createControllerWithKind(controller, "CART" /* Cart */);
14299
+ return buildCart(engine, {
14300
+ initialState: props ? props.initialState : {}
14301
+ });
14405
14302
  }
14406
14303
  };
14407
14304
  }
@@ -14450,7 +14347,23 @@ function loadBaseContextReducers(engine) {
14450
14347
  return true;
14451
14348
  }
14452
14349
 
14453
- // src/ssr/commerce/controllers/context/headless-context.ssr.ts
14350
+ // src/ssr-next/common/errors.ts
14351
+ var MissingControllerProps = class extends Error {
14352
+ constructor(controller) {
14353
+ super();
14354
+ this.name = "MissingControllerProps";
14355
+ this.message = `${controller} props are required but were undefined. Ensure they are included when calling \`fetchStaticState\` or \`hydrateStaticState\`.`;
14356
+ }
14357
+ };
14358
+ var MultipleRecommendationError = class extends Error {
14359
+ constructor(slotId) {
14360
+ super();
14361
+ this.name = "MultipleRecommendationError";
14362
+ this.message = `Multiple recommendation controllers found for the same slotId: ${slotId}. Only one recommendation controller per slotId is supported.`;
14363
+ }
14364
+ };
14365
+
14366
+ // src/ssr-next/commerce/controllers/context/headless-context.ssr.ts
14454
14367
  function defineContext() {
14455
14368
  return {
14456
14369
  listing: true,
@@ -14459,15 +14372,14 @@ function defineContext() {
14459
14372
  recommendation: true,
14460
14373
  buildWithProps: (engine, props) => {
14461
14374
  if (props === void 0) {
14462
- throw new MissingControllerProps("CONTEXT" /* Context */);
14375
+ throw new MissingControllerProps("Context");
14463
14376
  }
14464
- const controller = buildContext(engine, { options: props });
14465
- return createControllerWithKind(controller, "CONTEXT" /* Context */);
14377
+ return buildContext(engine, { options: props.initialState });
14466
14378
  }
14467
14379
  };
14468
14380
  }
14469
14381
 
14470
- // src/ssr/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.ts
14382
+ // src/ssr-next/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.ts
14471
14383
  function defineDidYouMean() {
14472
14384
  return {
14473
14385
  search: true,
@@ -14700,7 +14612,7 @@ function loadFilterSuggestionsGeneratorReducers(engine) {
14700
14612
  return true;
14701
14613
  }
14702
14614
 
14703
- // src/ssr/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.ts
14615
+ // src/ssr-next/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.ts
14704
14616
  function defineFilterSuggestionsGenerator() {
14705
14617
  return {
14706
14618
  search: true,
@@ -14710,13 +14622,11 @@ function defineFilterSuggestionsGenerator() {
14710
14622
  };
14711
14623
  }
14712
14624
 
14713
- // src/ssr/commerce/controllers/generator/headless-commerce-facet-generator.ssr.ts
14714
- function defineFacetGenerator(options) {
14715
- ensureAtLeastOneSolutionType(options);
14625
+ // src/ssr-next/commerce/controllers/generator/headless-commerce-facet-generator.ssr.ts
14626
+ function defineFacetGenerator() {
14716
14627
  return {
14717
14628
  listing: true,
14718
14629
  search: true,
14719
- ...options,
14720
14630
  build: (engine, solutionType) => buildFacetGenerator2(engine, { props: { solutionType } })
14721
14631
  };
14722
14632
  }
@@ -15112,7 +15022,7 @@ function loadInstantProductsReducers(engine) {
15112
15022
  return true;
15113
15023
  }
15114
15024
 
15115
- // src/ssr/commerce/controllers/instant-products/headless-instant-products.ssr.ts
15025
+ // src/ssr-next/commerce/controllers/instant-products/headless-instant-products.ssr.ts
15116
15026
  function defineInstantProducts(props = { options: {} }) {
15117
15027
  return {
15118
15028
  listing: true,
@@ -15122,9 +15032,8 @@ function defineInstantProducts(props = { options: {} }) {
15122
15032
  };
15123
15033
  }
15124
15034
 
15125
- // src/ssr/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.ts
15035
+ // src/ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.ts
15126
15036
  function definePagination(props) {
15127
- ensureAtLeastOneSolutionType(props);
15128
15037
  return {
15129
15038
  listing: true,
15130
15039
  search: true,
@@ -15310,32 +15219,28 @@ var registerQuery = (state, actionPayload) => {
15310
15219
  state[id2] = query2;
15311
15220
  };
15312
15221
 
15313
- // src/ssr/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.ts
15314
- function defineParameterManager(options) {
15315
- ensureAtLeastOneSolutionType(options);
15222
+ // src/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.ts
15223
+ function defineParameterManager() {
15316
15224
  return {
15317
15225
  listing: true,
15318
15226
  search: true,
15319
- ...options,
15320
15227
  buildWithProps: (engine, props, solutionType) => {
15321
15228
  if (solutionType === "listing" /* listing */) {
15322
15229
  if (!loadCommerceProductListingParameterReducers(engine)) {
15323
15230
  throw loadReducerError;
15324
15231
  }
15325
- const controller = buildProductListing(engine).parameterManager({
15232
+ return buildProductListing(engine).parameterManager({
15326
15233
  ...props,
15327
15234
  excludeDefaultParameters: true
15328
15235
  });
15329
- return createControllerWithKind(controller, "PARAMETER_MANAGER" /* ParameterManager */);
15330
15236
  } else {
15331
15237
  if (!loadCommerceSearchParameterReducers(engine)) {
15332
15238
  throw loadReducerError;
15333
15239
  }
15334
- const controller = buildSearch(engine).parameterManager({
15240
+ return buildSearch(engine).parameterManager({
15335
15241
  ...props,
15336
15242
  excludeDefaultParameters: true
15337
15243
  });
15338
- return createControllerWithKind(controller, "PARAMETER_MANAGER" /* ParameterManager */);
15339
15244
  }
15340
15245
  }
15341
15246
  };
@@ -15361,13 +15266,11 @@ function loadCommerceProductListingParameterReducers(engine) {
15361
15266
  return true;
15362
15267
  }
15363
15268
 
15364
- // src/ssr/commerce/controllers/product-list/headless-product-list.ssr.ts
15365
- function defineProductList(options) {
15366
- ensureAtLeastOneSolutionType(options);
15269
+ // src/ssr-next/commerce/controllers/product-list/headless-product-list.ssr.ts
15270
+ function defineProductList() {
15367
15271
  return {
15368
15272
  listing: true,
15369
15273
  search: true,
15370
- ...options,
15371
15274
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine) : buildSearch(engine)
15372
15275
  };
15373
15276
  }
@@ -15381,7 +15284,7 @@ function buildProductView(engine) {
15381
15284
  };
15382
15285
  }
15383
15286
 
15384
- // src/ssr/commerce/controllers/product-view/headless-product-view.ssr.ts
15287
+ // src/ssr-next/commerce/controllers/product-view/headless-product-view.ssr.ts
15385
15288
  function defineProductView() {
15386
15289
  return {
15387
15290
  listing: true,
@@ -15601,7 +15504,7 @@ function loadRecentQueriesListReducer(engine) {
15601
15504
  return true;
15602
15505
  }
15603
15506
 
15604
- // src/ssr/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.ts
15507
+ // src/ssr-next/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.ts
15605
15508
  function defineRecentQueriesList(props = {}) {
15606
15509
  return {
15607
15510
  search: true,
@@ -15828,7 +15731,7 @@ function loadBaseRecommendationsReducers(engine) {
15828
15731
  return true;
15829
15732
  }
15830
15733
 
15831
- // src/ssr/commerce/controllers/recommendations/headless-recommendations.ssr.ts
15734
+ // src/ssr-next/commerce/controllers/recommendations/headless-recommendations.ssr.ts
15832
15735
  function defineRecommendations(props) {
15833
15736
  return {
15834
15737
  recommendation: true,
@@ -15837,10 +15740,9 @@ function defineRecommendations(props) {
15837
15740
  },
15838
15741
  buildWithProps: (engine, options) => {
15839
15742
  const staticOptions = props.options;
15840
- const controller = buildRecommendations(engine, {
15743
+ return buildRecommendations(engine, {
15841
15744
  options: { ...staticOptions, ...options }
15842
15745
  });
15843
- return createControllerWithKind(controller, "RECOMMENDATIONS" /* Recommendations */);
15844
15746
  }
15845
15747
  };
15846
15748
  }
@@ -16152,7 +16054,7 @@ function loadSearchBoxReducers(engine) {
16152
16054
  return true;
16153
16055
  }
16154
16056
 
16155
- // src/ssr/commerce/controllers/search-box/headless-search-box.ssr.ts
16057
+ // src/ssr-next/commerce/controllers/search-box/headless-search-box.ssr.ts
16156
16058
  function defineSearchBox(props = {}) {
16157
16059
  return {
16158
16060
  search: true,
@@ -16160,9 +16062,8 @@ function defineSearchBox(props = {}) {
16160
16062
  };
16161
16063
  }
16162
16064
 
16163
- // src/ssr/commerce/controllers/sort/headless-core-commerce-sort.ssr.ts
16065
+ // src/ssr-next/commerce/controllers/sort/headless-core-commerce-sort.ssr.ts
16164
16066
  function defineSort(props) {
16165
- ensureAtLeastOneSolutionType(props);
16166
16067
  return {
16167
16068
  listing: true,
16168
16069
  search: true,
@@ -16382,7 +16283,7 @@ function loadStandaloneSearchBoxReducers(engine) {
16382
16283
  return true;
16383
16284
  }
16384
16285
 
16385
- // src/ssr/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.ts
16286
+ // src/ssr-next/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.ts
16386
16287
  function defineStandaloneSearchBox(props) {
16387
16288
  return {
16388
16289
  listing: true,
@@ -16391,13 +16292,11 @@ function defineStandaloneSearchBox(props) {
16391
16292
  };
16392
16293
  }
16393
16294
 
16394
- // src/ssr/commerce/controllers/summary/headless-core-summary.ssr.ts
16395
- function defineSummary(options) {
16396
- ensureAtLeastOneSolutionType(options);
16295
+ // src/ssr-next/commerce/controllers/summary/headless-core-summary.ssr.ts
16296
+ function defineSummary() {
16397
16297
  return {
16398
16298
  listing: true,
16399
16299
  search: true,
16400
- ...options,
16401
16300
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine).summary() : buildSearch(engine).summary()
16402
16301
  };
16403
16302
  }
@@ -16517,7 +16416,7 @@ function loadNotifyTriggerReducers(engine) {
16517
16416
  return true;
16518
16417
  }
16519
16418
 
16520
- // src/ssr/commerce/controllers/triggers/headless-notify-trigger.ssr.ts
16419
+ // src/ssr-next/commerce/controllers/triggers/headless-notify-trigger.ssr.ts
16521
16420
  function defineNotifyTrigger() {
16522
16421
  return {
16523
16422
  listing: true,
@@ -16557,7 +16456,7 @@ function loadQueryTriggerReducers(engine) {
16557
16456
  return true;
16558
16457
  }
16559
16458
 
16560
- // src/ssr/commerce/controllers/triggers/headless-query-trigger.ssr.ts
16459
+ // src/ssr-next/commerce/controllers/triggers/headless-query-trigger.ssr.ts
16561
16460
  function defineQueryTrigger() {
16562
16461
  return {
16563
16462
  search: true,
@@ -16598,7 +16497,7 @@ function loadRedirectionReducers(engine) {
16598
16497
  return true;
16599
16498
  }
16600
16499
 
16601
- // src/ssr/commerce/controllers/triggers/headless-redirection-trigger.ssr.ts
16500
+ // src/ssr-next/commerce/controllers/triggers/headless-redirection-trigger.ssr.ts
16602
16501
  function defineRedirectionTrigger() {
16603
16502
  return {
16604
16503
  search: true,
@@ -17995,7 +17894,325 @@ function createCommerceAPIClient(configuration2, logger) {
17995
17894
  });
17996
17895
  }
17997
17896
 
17998
- // src/ssr/commerce/factories/build-factory.ts
17897
+ // src/ssr-next/common/builders/controller-builder.ts
17898
+ var ControllerBuilder = class {
17899
+ constructor(definition3, engine, props) {
17900
+ __publicField(this, "_definition");
17901
+ __publicField(this, "_engine");
17902
+ __publicField(this, "_props");
17903
+ __publicField(this, "_additionalArgs", []);
17904
+ this._definition = definition3;
17905
+ this._engine = engine;
17906
+ this._props = props;
17907
+ }
17908
+ withAdditionalArgs(additionalArgs = []) {
17909
+ this._additionalArgs = additionalArgs;
17910
+ return this;
17911
+ }
17912
+ build() {
17913
+ if ("build" in this._definition && typeof this._definition.build === "function") {
17914
+ return this.buildWithoutProps();
17915
+ }
17916
+ if ("buildWithProps" in this._definition && typeof this._definition.buildWithProps === "function") {
17917
+ return this.buildWithProps();
17918
+ }
17919
+ throw new Error(
17920
+ "Controller definition must have a build or buildWithProps method."
17921
+ );
17922
+ }
17923
+ buildWithoutProps() {
17924
+ const buildFn = this._definition.build;
17925
+ return buildFn(this._engine, ...this._additionalArgs);
17926
+ }
17927
+ buildWithProps() {
17928
+ const buildWithPropsFn = this._definition.buildWithProps;
17929
+ const controller = buildWithPropsFn(
17930
+ this._engine,
17931
+ this._props,
17932
+ ...this._additionalArgs
17933
+ );
17934
+ return { ...controller, initialState: controller.state };
17935
+ }
17936
+ };
17937
+
17938
+ // src/ssr-next/common/builders/static-controller-builder.ts
17939
+ var StaticControllerBuilder = class {
17940
+ constructor() {
17941
+ __publicField(this, "_state");
17942
+ __publicField(this, "_initialState");
17943
+ }
17944
+ withState(state) {
17945
+ this._state = clone(state);
17946
+ return this;
17947
+ }
17948
+ withInitialState(initialState) {
17949
+ this._initialState = clone(initialState);
17950
+ return this;
17951
+ }
17952
+ /**
17953
+ * Builds and returns the static controller state object
17954
+ */
17955
+ build() {
17956
+ const result = {
17957
+ state: this._state
17958
+ };
17959
+ if (this._initialState) {
17960
+ result.initialState = this._initialState;
17961
+ }
17962
+ return result;
17963
+ }
17964
+ };
17965
+ function createStaticControllerBuilder(controller) {
17966
+ const builder = new StaticControllerBuilder().withState(controller.state);
17967
+ if ("initialState" in controller) {
17968
+ builder.withInitialState(
17969
+ controller.initialState
17970
+ );
17971
+ }
17972
+ return builder;
17973
+ }
17974
+
17975
+ // src/ssr-next/commerce/controller-utils.ts
17976
+ function createStaticState({
17977
+ searchActions,
17978
+ controllers
17979
+ }) {
17980
+ return {
17981
+ controllers: mapObject(
17982
+ controllers,
17983
+ (controller) => createStaticControllerBuilder(controller).build()
17984
+ ),
17985
+ searchActions: searchActions.map((action) => clone(action))
17986
+ };
17987
+ }
17988
+ function buildControllerDefinitions({
17989
+ definitionsMap,
17990
+ engine,
17991
+ solutionType,
17992
+ propsMap
17993
+ }) {
17994
+ const controllerMap = mapObject(definitionsMap, (definition3, key) => {
17995
+ const unavailableInSolutionType = () => !(solutionType in definition3) || solutionType in definition3 && definition3[solutionType] === false;
17996
+ const props = propsMap?.[key];
17997
+ if (unavailableInSolutionType()) {
17998
+ return null;
17999
+ }
18000
+ return new ControllerBuilder(definition3, engine, props).withAdditionalArgs([solutionType]).build();
18001
+ });
18002
+ return filterObject(
18003
+ controllerMap,
18004
+ (value) => value !== null
18005
+ );
18006
+ }
18007
+
18008
+ // src/ssr-next/commerce/utils/controller-wiring.ts
18009
+ var import_bueno90 = require("@coveo/bueno");
18010
+
18011
+ // src/ssr-next/commerce/utils/recommendation-filter.ts
18012
+ function isRecommendationDefinition(controllerDefinition) {
18013
+ const hasRecommendationFlag = "recommendation" in controllerDefinition && controllerDefinition.recommendation === true;
18014
+ const hasValidSlotId = recommendationInternalOptionKey in controllerDefinition && "slotId" in controllerDefinition[recommendationInternalOptionKey];
18015
+ return hasRecommendationFlag && hasValidSlotId;
18016
+ }
18017
+ function getRecommendationDefinitions(controllerDefinitions) {
18018
+ const recommendationMap = {};
18019
+ for (const [name, definition3] of Object.entries(controllerDefinitions)) {
18020
+ if (isRecommendationDefinition(definition3)) {
18021
+ recommendationMap[name] = definition3;
18022
+ }
18023
+ }
18024
+ return recommendationMap;
18025
+ }
18026
+ function filterRecommendationControllers(controllers, controllerDefinitions) {
18027
+ const slotIdSet = /* @__PURE__ */ new Set();
18028
+ const ensureSingleRecommendationPerSlot = (slotId) => {
18029
+ throw new MultipleRecommendationError(slotId);
18030
+ };
18031
+ const filtered = Object.entries(controllerDefinitions).filter(
18032
+ ([_, value]) => {
18033
+ if (!isRecommendationDefinition(value)) {
18034
+ return false;
18035
+ }
18036
+ const { slotId } = value[recommendationInternalOptionKey];
18037
+ const key = slotId;
18038
+ if (slotIdSet.has(slotId)) {
18039
+ ensureSingleRecommendationPerSlot(slotId);
18040
+ return false;
18041
+ }
18042
+ slotIdSet.add(key);
18043
+ return true;
18044
+ }
18045
+ );
18046
+ const name = filtered.map(([name2, _]) => name2);
18047
+ return {
18048
+ /**
18049
+ * Go through all the controllers passed in argument and only refresh recommendation controllers.
18050
+ *
18051
+ * @param controllers - A record of all controllers where the key is the controller name and the value is the controller instance.
18052
+ * @param controllerNames - A list of all recommendation controllers to refresh
18053
+ */
18054
+ refresh(whitelist) {
18055
+ if (whitelist === void 0) {
18056
+ return;
18057
+ }
18058
+ const isRecommendationController = (key) => name.includes(key) && whitelist.includes(key);
18059
+ for (const [key, controller] of Object.entries(controllers)) {
18060
+ if (isRecommendationController(key)) {
18061
+ controller.refresh?.();
18062
+ }
18063
+ }
18064
+ }
18065
+ };
18066
+ }
18067
+
18068
+ // src/ssr-next/commerce/utils/controller-wiring.ts
18069
+ var requiredDefinition = {
18070
+ context: new import_bueno90.RecordValue({
18071
+ options: { required: true },
18072
+ values: contextDefinition
18073
+ })
18074
+ };
18075
+ var listingDefinition = {
18076
+ ...requiredDefinition,
18077
+ searchParams: new import_bueno90.RecordValue({
18078
+ values: parametersDefinition
18079
+ })
18080
+ };
18081
+ var standaloneDefinition = {
18082
+ ...requiredDefinition
18083
+ };
18084
+ var searchDefinition = {
18085
+ ...requiredDefinition,
18086
+ searchParams: new import_bueno90.RecordValue({
18087
+ options: { required: true },
18088
+ values: { query: requiredEmptyAllowedString, ...parametersDefinition }
18089
+ })
18090
+ };
18091
+ var recommendationsDefinition = (recommendationName) => ({
18092
+ ...requiredDefinition,
18093
+ recommendations: new import_bueno90.ArrayValue({
18094
+ each: new import_bueno90.StringValue({
18095
+ required: true,
18096
+ constrainTo: recommendationName,
18097
+ emptyAllowed: false
18098
+ }),
18099
+ required: true
18100
+ }),
18101
+ productId: nonEmptyString
18102
+ });
18103
+ var listingDefinitionSchema = new import_bueno90.Schema(listingDefinition);
18104
+ var searchDefinitionSchema = new import_bueno90.Schema(searchDefinition);
18105
+ var standaloneDefinitionSchema = new import_bueno90.Schema(standaloneDefinition);
18106
+ var recommendationsDefinitionSchema = (recommendationName) => new import_bueno90.Schema(recommendationsDefinition(recommendationName));
18107
+ function validateBuildConfig(solutionType, controllerDefinitions, buildConfig) {
18108
+ const validationMap = {
18109
+ ["listing" /* listing */]: listingDefinitionSchema,
18110
+ ["search" /* search */]: searchDefinitionSchema,
18111
+ ["standalone" /* standalone */]: standaloneDefinitionSchema,
18112
+ ["recommendation" /* recommendation */]: recommendationsDefinitionSchema(
18113
+ Object.keys(getRecommendationDefinitions(controllerDefinitions))
18114
+ )
18115
+ };
18116
+ const schema = validationMap[solutionType];
18117
+ schema.validate(buildConfig);
18118
+ }
18119
+ var ControllerWirer = class {
18120
+ constructor(buildConfig, controllerDefinitions, controllerProps) {
18121
+ this.buildConfig = buildConfig;
18122
+ this.controllerDefinitions = controllerDefinitions;
18123
+ this.controllerProps = controllerProps;
18124
+ }
18125
+ wireParameterManager() {
18126
+ if (!this.controllerDefinitions?.parameterManager) return;
18127
+ const { searchParams } = this.buildConfig;
18128
+ const { query: query2, ...rest } = searchParams || {};
18129
+ const parameters = {
18130
+ ...query2 && { q: query2 },
18131
+ ...rest && typeof rest === "object" ? rest : {}
18132
+ };
18133
+ this.controllerProps.parameterManager = {
18134
+ initialState: { parameters }
18135
+ };
18136
+ }
18137
+ wireContext() {
18138
+ if (!this.controllerDefinitions?.context) return;
18139
+ const { context } = this.buildConfig;
18140
+ this.controllerProps.context = {
18141
+ initialState: {
18142
+ ...context
18143
+ }
18144
+ };
18145
+ }
18146
+ wireCart() {
18147
+ if (!this.controllerDefinitions?.cart || !this.buildConfig.cart) return;
18148
+ this.controllerProps.cart = {
18149
+ initialState: this.buildConfig.cart
18150
+ };
18151
+ }
18152
+ wireRecommendations() {
18153
+ if (!("recommendations" in this.buildConfig)) {
18154
+ return;
18155
+ }
18156
+ for (const recController in this.controllerDefinitions) {
18157
+ if (isRecommendationDefinition(this.controllerDefinitions[recController])) {
18158
+ this.controllerProps[recController] = {
18159
+ initialState: {
18160
+ ..."productId" in this.buildConfig && {
18161
+ productId: this.buildConfig.productId
18162
+ }
18163
+ }
18164
+ };
18165
+ }
18166
+ }
18167
+ }
18168
+ /**
18169
+ * Wires all controllers based on solution type and controller definitions.
18170
+ * Handles the complete wiring process in a sequential manner.
18171
+ */
18172
+ wire(solutionType) {
18173
+ this.wireCart();
18174
+ this.wireContext();
18175
+ switch (solutionType) {
18176
+ case "search" /* search */:
18177
+ case "listing" /* listing */: {
18178
+ this.wireParameterManager();
18179
+ break;
18180
+ }
18181
+ case "recommendation" /* recommendation */: {
18182
+ this.wireRecommendations();
18183
+ break;
18184
+ }
18185
+ case "standalone" /* standalone */:
18186
+ break;
18187
+ default: {
18188
+ const _exhaustiveCheck = solutionType;
18189
+ throw new Error(`Unsupported solution type: ${_exhaustiveCheck}`);
18190
+ }
18191
+ }
18192
+ }
18193
+ };
18194
+ function wireControllerParams(solutionType, controllerDefinitions, buildConfig) {
18195
+ validateBuildConfig(solutionType, controllerDefinitions, buildConfig);
18196
+ const controllerProps = buildConfig.controllers ?? {};
18197
+ new ControllerWirer(buildConfig, controllerDefinitions, controllerProps).wire(
18198
+ solutionType
18199
+ );
18200
+ return controllerProps;
18201
+ }
18202
+
18203
+ // src/ssr-next/commerce/utils/engine-wiring.ts
18204
+ function extendEngineConfiguration(configuration2, commonBuildOptions) {
18205
+ const { cart, context } = commonBuildOptions;
18206
+ return {
18207
+ ...configuration2,
18208
+ context: {
18209
+ ...context
18210
+ },
18211
+ cart
18212
+ };
18213
+ }
18214
+
18215
+ // src/ssr-next/commerce/factories/build-factory.ts
17999
18216
  function isListingFetchCompletedAction(action) {
18000
18217
  return /^commerce\/productListing\/fetch\/(fulfilled|rejected)$/.test(
18001
18218
  action.type
@@ -18067,222 +18284,102 @@ function buildSSRCommerceEngine(solutionType, options, recommendationCount) {
18067
18284
  }
18068
18285
  };
18069
18286
  }
18070
- function fetchActiveRecommendationControllers(controllerProps, solutionType) {
18071
- return solutionType === "recommendation" /* recommendation */ ? Object.values(controllerProps).filter(
18072
- (controller) => controller && typeof controller === "object" && "enabled" in controller && controller.enabled
18073
- ).length : 0;
18074
- }
18075
18287
  var buildFactory = (controllerDefinitions, options) => (solutionType) => async (...[buildOptions]) => {
18288
+ const controllerProps = wireControllerParams(
18289
+ solutionType,
18290
+ controllerDefinitions,
18291
+ buildOptions
18292
+ );
18076
18293
  const logger = buildLogger(options.loggerOptions);
18077
18294
  if (!options.navigatorContextProvider) {
18078
18295
  logger.warn(
18079
18296
  "[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()"
18080
18297
  );
18081
18298
  }
18082
- const controllerProps = buildOptions && "controllers" in buildOptions ? buildOptions.controllers : {};
18083
- const enabledRecommendationControllers = fetchActiveRecommendationControllers(controllerProps, solutionType);
18299
+ const enabledRecommendationControllers = buildOptions && "recommendations" in buildOptions ? buildOptions?.recommendations.length : 0;
18300
+ const engineOptions = {
18301
+ ...options,
18302
+ configuration: extendEngineConfiguration(
18303
+ options.configuration,
18304
+ buildOptions
18305
+ )
18306
+ // TODO: KIT-4754: remove non-null assertion operator
18307
+ };
18084
18308
  const engine = buildSSRCommerceEngine(
18085
18309
  solutionType,
18086
- buildOptions && "extend" in buildOptions && buildOptions?.extend ? await buildOptions.extend(options) : options,
18310
+ engineOptions,
18087
18311
  enabledRecommendationControllers
18088
18312
  );
18089
18313
  const controllers = buildControllerDefinitions({
18090
18314
  definitionsMap: controllerDefinitions ?? {},
18091
18315
  engine,
18092
18316
  solutionType,
18093
- propsMap: buildOptions && "controllers" in buildOptions ? buildOptions.controllers : {}
18317
+ propsMap: controllerProps
18094
18318
  });
18319
+ if (buildOptions && "searchActions" in buildOptions) {
18320
+ buildOptions.searchActions.forEach((action) => {
18321
+ engine.dispatch(action);
18322
+ });
18323
+ }
18095
18324
  return {
18096
18325
  engine,
18097
18326
  controllers
18098
18327
  };
18099
18328
  };
18100
18329
 
18101
- // src/ssr/common/controller-utils.ts
18102
- function composeFunction(parentFunction, children) {
18103
- const newFunction = (...params) => parentFunction(...params);
18104
- for (const [key, value] of Object.entries(children)) {
18105
- newFunction[key] = value;
18106
- }
18107
- return newFunction;
18108
- }
18109
-
18110
- // src/ssr/commerce/factories/hydrated-state-factory.ts
18111
- var hydratedStaticStateFactory = (controllerDefinitions, options) => (solutionType) => composeFunction(
18112
- async (...params) => {
18113
- const solutionTypeBuild = await buildFactory(controllerDefinitions, {
18114
- ...options
18115
- })(solutionType);
18116
- const buildResult = await solutionTypeBuild(
18117
- ...params
18118
- );
18119
- const staticStateBuild = await hydratedStaticStateFactory(
18330
+ // src/ssr-next/commerce/factories/hydrated-state-factory.ts
18331
+ function hydratedStaticStateFactory(controllerDefinitions, options) {
18332
+ return (solutionType) => async (...params) => {
18333
+ const solutionTypeBuild = await buildFactory(
18120
18334
  controllerDefinitions,
18121
18335
  options
18122
18336
  )(solutionType);
18123
- const staticState = await staticStateBuild.fromBuildResult({
18124
- buildResult,
18125
- searchActions: params[0].searchActions
18126
- });
18127
- return staticState;
18128
- },
18129
- {
18130
- fromBuildResult: async (...params) => {
18131
- const [
18132
- {
18133
- buildResult: { engine, controllers },
18134
- searchActions
18135
- }
18136
- ] = params;
18137
- searchActions.forEach((action) => {
18138
- engine.dispatch(action);
18139
- });
18140
- await engine.waitForRequestCompletedAction();
18141
- return { engine, controllers };
18142
- }
18143
- }
18144
- );
18145
-
18146
- // src/ssr/commerce/factories/recommendation-hydrated-state-factory.ts
18147
- function hydratedRecommendationStaticStateFactory(controllerDefinitions, options) {
18148
- return composeFunction(
18149
- async (...params) => {
18150
- const solutionTypeBuild = await buildFactory(
18151
- controllerDefinitions,
18152
- options
18153
- )("recommendation" /* recommendation */);
18154
- const buildResult = await solutionTypeBuild(
18155
- ...params
18156
- );
18157
- const staticState = await hydratedRecommendationStaticStateFactory(
18158
- controllerDefinitions,
18159
- options
18160
- ).fromBuildResult({
18161
- buildResult,
18162
- searchActions: params[0].searchActions
18163
- });
18164
- return staticState;
18165
- },
18166
- {
18167
- fromBuildResult: async (...params) => {
18168
- const [
18169
- {
18170
- buildResult: { engine, controllers },
18171
- searchActions
18172
- }
18173
- ] = params;
18174
- searchActions.forEach((action) => {
18175
- engine.dispatch(action);
18176
- });
18177
- await engine.waitForRequestCompletedAction();
18178
- return { engine, controllers };
18179
- }
18180
- }
18181
- );
18337
+ const { engine, controllers } = await solutionTypeBuild(...params);
18338
+ await engine.waitForRequestCompletedAction();
18339
+ return { engine, controllers };
18340
+ };
18182
18341
  }
18183
18342
 
18184
- // src/ssr/commerce/utils/recommendation-filter.ts
18185
- function filterRecommendationControllers(controllers, controllerDefinitions) {
18186
- const slotIdSet = /* @__PURE__ */ new Set();
18187
- const isRecommendationDefinition = (controllerDefinition) => {
18188
- const isControllerRecommendation = "recommendation" in controllerDefinition && controllerDefinition.recommendation === true;
18189
- const hasSlotId = recommendationInternalOptionKey in controllerDefinition && "slotId" in controllerDefinition[recommendationInternalOptionKey];
18190
- return isControllerRecommendation && hasSlotId;
18191
- };
18192
- const ensureSingleRecommendationPerSlot = (slotId) => {
18193
- throw new MultipleRecommendationError(slotId);
18194
- };
18195
- const filtered = Object.entries(controllerDefinitions).filter(
18196
- ([_, value]) => {
18197
- if (!isRecommendationDefinition(value)) {
18198
- return false;
18199
- }
18200
- const { slotId } = value[recommendationInternalOptionKey];
18201
- const key = slotId;
18202
- if (slotIdSet.has(slotId)) {
18203
- ensureSingleRecommendationPerSlot(slotId);
18204
- return false;
18205
- }
18206
- slotIdSet.add(key);
18207
- return true;
18208
- }
18209
- );
18210
- const name = filtered.map(([name2, _]) => name2);
18211
- return {
18212
- /**
18213
- * Go through all the controllers passed in argument and only refresh recommendation controllers.
18214
- *
18215
- * @param controllers - A record of all controllers where the key is the controller name and the value is the controller instance.
18216
- * @param controllerNames - A list of all recommendation controllers to refresh
18217
- */
18218
- refresh(whitelist) {
18219
- if (whitelist === void 0) {
18220
- return;
18221
- }
18222
- const isRecommendationController = (key) => name.includes(key) && whitelist.includes(key);
18223
- for (const [key, controller] of Object.entries(controllers)) {
18224
- if (isRecommendationController(key)) {
18225
- controller.refresh?.();
18226
- }
18227
- }
18228
- }
18343
+ // src/ssr-next/commerce/factories/recommendation-hydrated-state-factory.ts
18344
+ function hydratedRecommendationStaticStateFactory(controllerDefinitions, options) {
18345
+ return async (...params) => {
18346
+ const solutionTypeBuild = await buildFactory(
18347
+ controllerDefinitions,
18348
+ options
18349
+ )("recommendation" /* recommendation */);
18350
+ const { engine, controllers } = await solutionTypeBuild(...params);
18351
+ await engine.waitForRequestCompletedAction();
18352
+ return { engine, controllers };
18229
18353
  };
18230
18354
  }
18231
18355
 
18232
- // src/ssr/commerce/factories/recommendation-static-state-factory.ts
18356
+ // src/ssr-next/commerce/factories/recommendation-static-state-factory.ts
18233
18357
  function fetchRecommendationStaticStateFactory(controllerDefinitions, options) {
18234
- const getAllowedRecommendationKeys = (props) => {
18235
- if (props && "controllers" in props) {
18236
- const enabledRecommendationControllers = filterObject(
18237
- props.controllers,
18238
- (value) => Boolean(value.enabled)
18239
- );
18240
- return Object.keys(enabledRecommendationControllers);
18241
- }
18242
- return [];
18358
+ return async (...params) => {
18359
+ const [props] = params;
18360
+ const allowedRecommendationKeys = props?.recommendations;
18361
+ const solutionTypeBuild = await buildFactory(
18362
+ controllerDefinitions,
18363
+ options
18364
+ )("recommendation" /* recommendation */);
18365
+ const { engine, controllers } = await solutionTypeBuild(...params);
18366
+ filterRecommendationControllers(
18367
+ controllers,
18368
+ controllerDefinitions ?? {}
18369
+ ).refresh(allowedRecommendationKeys);
18370
+ const searchActions = await Promise.all(
18371
+ engine.waitForRequestCompletedAction()
18372
+ );
18373
+ const staticState = createStaticState({
18374
+ searchActions,
18375
+ controllers
18376
+ });
18377
+ return {
18378
+ ...params[0],
18379
+ // TODO: KIT-4754: remove index access after no longer relying on OptionTuple type
18380
+ ...staticState
18381
+ };
18243
18382
  };
18244
- return composeFunction(
18245
- async (...params) => {
18246
- const [props] = params;
18247
- const allowedRecommendationKeys = getAllowedRecommendationKeys(props);
18248
- const solutionTypeBuild = await buildFactory(
18249
- controllerDefinitions,
18250
- options
18251
- )("recommendation" /* recommendation */);
18252
- const buildResult = await solutionTypeBuild(
18253
- ...params
18254
- );
18255
- const staticState = await fetchRecommendationStaticStateFactory(
18256
- controllerDefinitions,
18257
- options
18258
- ).fromBuildResult({
18259
- buildResult,
18260
- allowedRecommendationKeys
18261
- });
18262
- return staticState;
18263
- },
18264
- {
18265
- fromBuildResult: async (...params) => {
18266
- const [
18267
- {
18268
- buildResult: { engine, controllers },
18269
- allowedRecommendationKeys
18270
- }
18271
- ] = params;
18272
- filterRecommendationControllers(
18273
- controllers,
18274
- controllerDefinitions ?? {}
18275
- ).refresh(allowedRecommendationKeys);
18276
- const searchActions = await Promise.all(
18277
- engine.waitForRequestCompletedAction()
18278
- );
18279
- return createStaticState({
18280
- searchActions,
18281
- controllers
18282
- });
18283
- }
18284
- }
18285
- );
18286
18383
  }
18287
18384
 
18288
18385
  // src/utils/runtime.ts
@@ -18290,7 +18387,7 @@ function isBrowser2() {
18290
18387
  return typeof window !== "undefined" && typeof document !== "undefined";
18291
18388
  }
18292
18389
 
18293
- // src/ssr/common/augment-preprocess-request.ts
18390
+ // src/ssr-next/common/augment-preprocess-request.ts
18294
18391
  function augmentPreprocessRequestWithForwardedFor(options) {
18295
18392
  const originalPreprocessRequest = options.preprocessRequest;
18296
18393
  return async (request, clientOrigin, metadata) => {
@@ -18314,54 +18411,56 @@ function augmentPreprocessRequestWithForwardedFor(options) {
18314
18411
  };
18315
18412
  }
18316
18413
 
18317
- // src/ssr/commerce/factories/static-state-factory.ts
18318
- var fetchStaticStateFactory = (controllerDefinitions, options) => (solutionType) => composeFunction(
18319
- async (...params) => {
18320
- const solutionTypeBuild = await buildFactory(controllerDefinitions, {
18321
- ...options
18322
- })(solutionType);
18323
- const buildResult = await solutionTypeBuild(...params);
18414
+ // src/ssr-next/commerce/factories/static-state-factory.ts
18415
+ function fetchStaticStateFactory(controllerDefinitions, options) {
18416
+ return (solutionType) => async (...params) => {
18417
+ const solutionTypeBuild = await buildFactory(
18418
+ controllerDefinitions,
18419
+ options
18420
+ )(solutionType);
18421
+ const { engine, controllers } = await solutionTypeBuild(...params);
18324
18422
  options.configuration.preprocessRequest = augmentPreprocessRequestWithForwardedFor({
18325
18423
  preprocessRequest: options.configuration.preprocessRequest,
18326
18424
  navigatorContextProvider: options.navigatorContextProvider,
18327
18425
  loggerOptions: options.loggerOptions
18328
18426
  });
18329
- const staticStateBuild = await fetchStaticStateFactory(
18330
- controllerDefinitions,
18331
- options
18332
- )(solutionType);
18333
- const staticState = await staticStateBuild.fromBuildResult({
18334
- buildResult
18335
- });
18336
- return staticState;
18337
- },
18338
- {
18339
- fromBuildResult: async (...params) => {
18340
- const [
18341
- {
18342
- buildResult: { engine, controllers }
18343
- }
18344
- ] = params;
18345
- switch (solutionType) {
18346
- case "listing" /* listing */:
18347
- buildProductListing(engine).executeFirstRequest();
18348
- break;
18349
- case "search" /* search */:
18350
- buildSearch(engine).executeFirstSearch();
18351
- break;
18352
- }
18353
- const searchActions = await Promise.all(
18354
- engine.waitForRequestCompletedAction()
18355
- );
18356
- return createStaticState({
18357
- searchActions,
18358
- controllers
18359
- });
18427
+ switch (solutionType) {
18428
+ case "listing" /* listing */:
18429
+ buildProductListing(engine).executeFirstRequest();
18430
+ break;
18431
+ case "search" /* search */:
18432
+ buildSearch(engine).executeFirstSearch();
18433
+ break;
18360
18434
  }
18435
+ const searchActions = await Promise.all(
18436
+ engine.waitForRequestCompletedAction()
18437
+ );
18438
+ const staticState = createStaticState({
18439
+ searchActions,
18440
+ controllers
18441
+ });
18442
+ return {
18443
+ ...params[0],
18444
+ // TODO: KIT-4754: remove index access after no longer relying on OptionTuple type
18445
+ ...staticState
18446
+ };
18447
+ };
18448
+ }
18449
+
18450
+ // src/ssr-next/commerce/validation/controller-validation.ts
18451
+ var validateControllerNames = (controllers) => {
18452
+ const reservedNames = ["context", "cart", "parameterManager"];
18453
+ const invalidNames = Object.keys(controllers).filter(
18454
+ (name) => reservedNames.includes(name)
18455
+ );
18456
+ if (invalidNames.length > 0) {
18457
+ throw new Error(
18458
+ `Reserved controller names found: ${invalidNames.join(", ")}. Please use different controller names than ${reservedNames.join(", ")}.`
18459
+ );
18361
18460
  }
18362
- );
18461
+ };
18363
18462
 
18364
- // src/ssr/commerce/engine/commerce-engine.ssr.ts
18463
+ // src/ssr-next/commerce/engine/commerce-engine.ssr.ts
18365
18464
  function defineCommerceEngine(options) {
18366
18465
  const { controllers: controllerDefinitions, ...engineOptions } = options;
18367
18466
  const getOptions = () => engineOptions;
@@ -18372,59 +18471,55 @@ function defineCommerceEngine(options) {
18372
18471
  const setAccessToken = (accessToken) => {
18373
18472
  engineOptions.configuration.accessToken = accessToken;
18374
18473
  };
18375
- const build = buildFactory(
18376
- controllerDefinitions,
18377
- getOptions()
18378
- );
18474
+ controllerDefinitions && validateControllerNames(controllerDefinitions);
18475
+ const augmentedControllerDefinition = {
18476
+ ...controllerDefinitions,
18477
+ parameterManager: defineParameterManager(),
18478
+ context: defineContext(),
18479
+ cart: defineCart()
18480
+ };
18379
18481
  const fetchStaticState = fetchStaticStateFactory(
18380
- controllerDefinitions,
18482
+ augmentedControllerDefinition,
18381
18483
  getOptions()
18382
18484
  );
18383
18485
  const hydrateStaticState = hydratedStaticStateFactory(
18384
- controllerDefinitions,
18486
+ augmentedControllerDefinition,
18385
18487
  getOptions()
18386
18488
  );
18387
18489
  const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(
18388
- controllerDefinitions,
18490
+ augmentedControllerDefinition,
18389
18491
  getOptions()
18390
18492
  );
18391
18493
  const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(
18392
- controllerDefinitions,
18494
+ augmentedControllerDefinition,
18393
18495
  getOptions()
18394
18496
  );
18497
+ const commonMethods = {
18498
+ setNavigatorContextProvider,
18499
+ getAccessToken,
18500
+ setAccessToken
18501
+ };
18395
18502
  return {
18396
18503
  listingEngineDefinition: {
18397
- build: build("listing" /* listing */),
18398
18504
  fetchStaticState: fetchStaticState("listing" /* listing */),
18399
18505
  hydrateStaticState: hydrateStaticState("listing" /* listing */),
18400
- setNavigatorContextProvider,
18401
- getAccessToken,
18402
- setAccessToken
18506
+ ...commonMethods
18403
18507
  },
18404
18508
  searchEngineDefinition: {
18405
- build: build("search" /* search */),
18406
18509
  fetchStaticState: fetchStaticState("search" /* search */),
18407
18510
  hydrateStaticState: hydrateStaticState("search" /* search */),
18408
- setNavigatorContextProvider,
18409
- getAccessToken,
18410
- setAccessToken
18511
+ ...commonMethods
18411
18512
  },
18412
18513
  recommendationEngineDefinition: {
18413
- build: build("recommendation" /* recommendation */),
18414
18514
  fetchStaticState: fetchRecommendationStaticState,
18415
18515
  hydrateStaticState: hydrateRecommendationStaticState,
18416
- setNavigatorContextProvider,
18417
- getAccessToken,
18418
- setAccessToken
18516
+ ...commonMethods
18419
18517
  },
18420
18518
  // TODO KIT-3738 : The standaloneEngineDefinition should not be async since no request is sent to the API
18421
18519
  standaloneEngineDefinition: {
18422
- build: build("standalone" /* standalone */),
18423
18520
  fetchStaticState: fetchStaticState("standalone" /* standalone */),
18424
18521
  hydrateStaticState: hydrateStaticState("standalone" /* standalone */),
18425
- setNavigatorContextProvider,
18426
- getAccessToken,
18427
- setAccessToken
18522
+ ...commonMethods
18428
18523
  }
18429
18524
  };
18430
18525
  }
@@ -18655,7 +18750,7 @@ function loadSortActions(engine) {
18655
18750
  var import_toolkit126 = require("@reduxjs/toolkit");
18656
18751
 
18657
18752
  // src/features/standalone-search-box-set/standalone-search-box-set-actions.ts
18658
- var import_bueno90 = require("@coveo/bueno");
18753
+ var import_bueno91 = require("@coveo/bueno");
18659
18754
  var import_toolkit125 = require("@reduxjs/toolkit");
18660
18755
 
18661
18756
  // src/api/search/plan/plan-endpoint.ts
@@ -18692,7 +18787,7 @@ var registerStandaloneSearchBox2 = (0, import_toolkit125.createAction)(
18692
18787
  (payload) => validatePayload(payload, {
18693
18788
  id: requiredNonEmptyString,
18694
18789
  redirectionUrl: requiredNonEmptyString,
18695
- overwrite: new import_bueno90.BooleanValue({ required: false })
18790
+ overwrite: new import_bueno91.BooleanValue({ required: false })
18696
18791
  })
18697
18792
  );
18698
18793
  var updateStandaloneSearchBoxRedirectionUrl2 = (0, import_toolkit125.createAction)(
@@ -18723,7 +18818,7 @@ var fetchRedirectUrl2 = (0, import_toolkit125.createAsyncThunk)(
18723
18818
  rejectWithValue,
18724
18819
  extra: { apiClient, validatePayload: validatePayload2, navigatorContext }
18725
18820
  }) => {
18726
- validatePayload2(payload, { id: new import_bueno90.StringValue({ emptyAllowed: false }) });
18821
+ validatePayload2(payload, { id: new import_bueno91.StringValue({ emptyAllowed: false }) });
18727
18822
  const request = await buildPlanRequest2(getState(), navigatorContext);
18728
18823
  const response = await apiClient.plan(request);
18729
18824
  if (isErrorResponse(response)) {
@@ -18866,13 +18961,13 @@ function loadTriggersActions(engine) {
18866
18961
  var import_toolkit129 = require("@reduxjs/toolkit");
18867
18962
 
18868
18963
  // src/features/folding/folding-actions.ts
18869
- var import_bueno91 = require("@coveo/bueno");
18964
+ var import_bueno92 = require("@coveo/bueno");
18870
18965
  var import_toolkit127 = require("@reduxjs/toolkit");
18871
18966
  var foldingOptionsSchemaDefinition = {
18872
- collectionField: new import_bueno91.StringValue({ emptyAllowed: false, required: false }),
18873
- parentField: new import_bueno91.StringValue({ emptyAllowed: false, required: false }),
18874
- childField: new import_bueno91.StringValue({ emptyAllowed: false, required: false }),
18875
- numberOfFoldedResults: new import_bueno91.NumberValue({ min: 0, required: false })
18967
+ collectionField: new import_bueno92.StringValue({ emptyAllowed: false, required: false }),
18968
+ parentField: new import_bueno92.StringValue({ emptyAllowed: false, required: false }),
18969
+ childField: new import_bueno92.StringValue({ emptyAllowed: false, required: false }),
18970
+ numberOfFoldedResults: new import_bueno92.NumberValue({ min: 0, required: false })
18876
18971
  };
18877
18972
  var registerFolding = (0, import_toolkit127.createAction)(
18878
18973
  "folding/register",
@@ -19010,12 +19105,12 @@ var fieldsReducer = (0, import_toolkit129.createReducer)(
19010
19105
  );
19011
19106
 
19012
19107
  // src/features/templates/templates-manager.ts
19013
- var import_bueno92 = require("@coveo/bueno");
19014
- var templateSchema = new import_bueno92.Schema({
19015
- content: new import_bueno92.Value({ required: true }),
19016
- conditions: new import_bueno92.Value({ required: true }),
19017
- priority: new import_bueno92.NumberValue({ required: false, default: 0, min: 0 }),
19018
- fields: new import_bueno92.ArrayValue({
19108
+ var import_bueno93 = require("@coveo/bueno");
19109
+ var templateSchema = new import_bueno93.Schema({
19110
+ content: new import_bueno93.Value({ required: true }),
19111
+ conditions: new import_bueno93.Value({ required: true }),
19112
+ priority: new import_bueno93.NumberValue({ required: false, default: 0, min: 0 }),
19113
+ fields: new import_bueno93.ArrayValue({
19019
19114
  required: false,
19020
19115
  each: requiredNonEmptyString
19021
19116
  })
@@ -19028,7 +19123,7 @@ function buildTemplatesManager() {
19028
19123
  (condition) => condition instanceof Function
19029
19124
  );
19030
19125
  if (!areConditionsValid) {
19031
- throw new import_bueno92.SchemaValidationError(
19126
+ throw new import_bueno93.SchemaValidationError(
19032
19127
  "Each template condition should be a function that takes a Result or Product as an argument and returns a boolean"
19033
19128
  );
19034
19129
  }
@@ -19089,10 +19184,10 @@ function loadResultTemplatesManagerReducers(engine) {
19089
19184
  }
19090
19185
 
19091
19186
  // src/features/commerce/parameters/parameters-serializer.ssr.ts
19092
- var import_bueno94 = require("@coveo/bueno");
19187
+ var import_bueno95 = require("@coveo/bueno");
19093
19188
 
19094
19189
  // src/features/search-parameters/search-parameter-utils.ts
19095
- var import_bueno93 = require("@coveo/bueno");
19190
+ var import_bueno94 = require("@coveo/bueno");
19096
19191
  function toArray(value) {
19097
19192
  return Array.isArray(value) ? value : [value];
19098
19193
  }
@@ -19137,7 +19232,7 @@ function wipeSearchParamsFromUrl(urlSearchParams) {
19137
19232
  return previousSearchParams;
19138
19233
  }
19139
19234
  function applyToUrlSearchParam(urlSearchParams, previousState, pair) {
19140
- if ((0, import_bueno94.isNullOrUndefined)(pair[1])) {
19235
+ if ((0, import_bueno95.isNullOrUndefined)(pair[1])) {
19141
19236
  return;
19142
19237
  }
19143
19238
  if (isSortPair(pair)) {
@@ -19195,7 +19290,7 @@ function isValidBasicKey3(key) {
19195
19290
  return key in supportedBasicParameters;
19196
19291
  }
19197
19292
  function extendSearchParams(commerceSearchParams, key, value) {
19198
- if ((0, import_bueno94.isNullOrUndefined)(value)) {
19293
+ if ((0, import_bueno95.isNullOrUndefined)(value)) {
19199
19294
  return;
19200
19295
  }
19201
19296
  if (key === "sortCriteria") {
@@ -19302,13 +19397,13 @@ function addFacetValuesToSearchParams(facetId2, paramKey) {
19302
19397
  }
19303
19398
 
19304
19399
  // src/features/commerce/product-templates/product-templates-helpers.ts
19305
- var import_bueno95 = require("@coveo/bueno");
19400
+ var import_bueno96 = require("@coveo/bueno");
19306
19401
  var getProductProperty = (product, property) => {
19307
19402
  const anyProduct = product;
19308
- if (!(0, import_bueno95.isNullOrUndefined)(anyProduct[property])) {
19403
+ if (!(0, import_bueno96.isNullOrUndefined)(anyProduct[property])) {
19309
19404
  return anyProduct[property];
19310
19405
  }
19311
- if (!(0, import_bueno95.isNullOrUndefined)(product.additionalFields[property])) {
19406
+ if (!(0, import_bueno96.isNullOrUndefined)(product.additionalFields[property])) {
19312
19407
  return product.additionalFields[property];
19313
19408
  }
19314
19409
  return null;
@@ -19316,14 +19411,14 @@ var getProductProperty = (product, property) => {
19316
19411
  var fieldsMustBeDefined = (fieldNames) => {
19317
19412
  return (product) => {
19318
19413
  return fieldNames.every(
19319
- (fieldName) => !(0, import_bueno95.isNullOrUndefined)(getProductProperty(product, fieldName))
19414
+ (fieldName) => !(0, import_bueno96.isNullOrUndefined)(getProductProperty(product, fieldName))
19320
19415
  );
19321
19416
  };
19322
19417
  };
19323
19418
  var fieldsMustNotBeDefined = (fieldNames) => {
19324
19419
  return (product) => {
19325
19420
  return fieldNames.every(
19326
- (fieldName) => (0, import_bueno95.isNullOrUndefined)(getProductProperty(product, fieldName))
19421
+ (fieldName) => (0, import_bueno96.isNullOrUndefined)(getProductProperty(product, fieldName))
19327
19422
  );
19328
19423
  };
19329
19424
  };
@@ -19349,7 +19444,7 @@ var fieldMustNotMatch = (fieldName, disallowedValues) => {
19349
19444
  };
19350
19445
  var getFieldValuesFromProduct = (fieldName, product) => {
19351
19446
  const rawValue = getProductProperty(product, fieldName);
19352
- return (0, import_bueno95.isArray)(rawValue) ? rawValue : [rawValue];
19447
+ return (0, import_bueno96.isArray)(rawValue) ? rawValue : [rawValue];
19353
19448
  };
19354
19449
  var ProductTemplatesHelpers = {
19355
19450
  getProductProperty,
@@ -19651,7 +19746,6 @@ function getBooleanOperatorSymbol(operator) {
19651
19746
  }
19652
19747
  // Annotate the CommonJS export names for ESM import in node:
19653
19748
  0 && (module.exports = {
19654
- Kind,
19655
19749
  ProductTemplatesHelpers,
19656
19750
  SolutionType,
19657
19751
  SortBy,