@coveo/headless 4.0.0-pre.c6ea281e26 → 4.0.0-pre.caa7dfc47b

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 = "4.0.0-pre.c6ea281e26";
470
+ var VERSION = "4.0.0-pre.caa7dfc47b";
472
471
  var COVEO_FRAMEWORK = ["@coveo/atomic", "@coveo/quantic"];
473
472
 
474
473
  // src/features/configuration/configuration-actions.ts
@@ -14055,7 +14054,7 @@ function loadBaseSearchReducers(engine) {
14055
14054
  return true;
14056
14055
  }
14057
14056
 
14058
- // src/ssr/commerce/types/controller-constants.ts
14057
+ // src/ssr-next/commerce/types/controller-constants.ts
14059
14058
  var SolutionType = /* @__PURE__ */ ((SolutionType2) => {
14060
14059
  SolutionType2["search"] = "search";
14061
14060
  SolutionType2["listing"] = "listing";
@@ -14068,92 +14067,11 @@ var recommendationInternalOptionKey = Symbol.for(
14068
14067
  recommendationOptionKey
14069
14068
  );
14070
14069
 
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);
14070
+ // src/ssr-next/commerce/controllers/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.ts
14071
+ function defineBreadcrumbManager() {
14153
14072
  return {
14154
14073
  listing: true,
14155
14074
  search: true,
14156
- ...options,
14157
14075
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine).breadcrumbManager() : buildSearch(engine).breadcrumbManager()
14158
14076
  };
14159
14077
  }
@@ -14369,26 +14287,7 @@ function loadBaseCartReducers(engine) {
14369
14287
  return true;
14370
14288
  }
14371
14289
 
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
14290
+ // src/ssr-next/commerce/controllers/cart/headless-cart.ssr.ts
14392
14291
  function defineCart() {
14393
14292
  return {
14394
14293
  listing: true,
@@ -14396,11 +14295,9 @@ function defineCart() {
14396
14295
  standalone: true,
14397
14296
  recommendation: true,
14398
14297
  buildWithProps: (engine, props) => {
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 */);
14298
+ return buildCart(engine, {
14299
+ initialState: props ? props.initialState : {}
14300
+ });
14404
14301
  }
14405
14302
  };
14406
14303
  }
@@ -14449,7 +14346,23 @@ function loadBaseContextReducers(engine) {
14449
14346
  return true;
14450
14347
  }
14451
14348
 
14452
- // src/ssr/commerce/controllers/context/headless-context.ssr.ts
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
14453
14366
  function defineContext() {
14454
14367
  return {
14455
14368
  listing: true,
@@ -14458,15 +14371,14 @@ function defineContext() {
14458
14371
  recommendation: true,
14459
14372
  buildWithProps: (engine, props) => {
14460
14373
  if (props === void 0) {
14461
- throw new MissingControllerProps("CONTEXT" /* Context */);
14374
+ throw new MissingControllerProps("Context");
14462
14375
  }
14463
- const controller = buildContext(engine, { options: props });
14464
- return createControllerWithKind(controller, "CONTEXT" /* Context */);
14376
+ return buildContext(engine, { options: props.initialState });
14465
14377
  }
14466
14378
  };
14467
14379
  }
14468
14380
 
14469
- // src/ssr/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.ts
14381
+ // src/ssr-next/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.ts
14470
14382
  function defineDidYouMean() {
14471
14383
  return {
14472
14384
  search: true,
@@ -14699,7 +14611,7 @@ function loadFilterSuggestionsGeneratorReducers(engine) {
14699
14611
  return true;
14700
14612
  }
14701
14613
 
14702
- // src/ssr/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.ts
14614
+ // src/ssr-next/commerce/controllers/filter-suggestions/headless-filter-suggestions-generator.ssr.ts
14703
14615
  function defineFilterSuggestionsGenerator() {
14704
14616
  return {
14705
14617
  search: true,
@@ -14709,13 +14621,11 @@ function defineFilterSuggestionsGenerator() {
14709
14621
  };
14710
14622
  }
14711
14623
 
14712
- // src/ssr/commerce/controllers/generator/headless-commerce-facet-generator.ssr.ts
14713
- function defineFacetGenerator(options) {
14714
- ensureAtLeastOneSolutionType(options);
14624
+ // src/ssr-next/commerce/controllers/generator/headless-commerce-facet-generator.ssr.ts
14625
+ function defineFacetGenerator() {
14715
14626
  return {
14716
14627
  listing: true,
14717
14628
  search: true,
14718
- ...options,
14719
14629
  build: (engine, solutionType) => buildFacetGenerator2(engine, { props: { solutionType } })
14720
14630
  };
14721
14631
  }
@@ -15111,7 +15021,7 @@ function loadInstantProductsReducers(engine) {
15111
15021
  return true;
15112
15022
  }
15113
15023
 
15114
- // src/ssr/commerce/controllers/instant-products/headless-instant-products.ssr.ts
15024
+ // src/ssr-next/commerce/controllers/instant-products/headless-instant-products.ssr.ts
15115
15025
  function defineInstantProducts(props = { options: {} }) {
15116
15026
  return {
15117
15027
  listing: true,
@@ -15121,9 +15031,8 @@ function defineInstantProducts(props = { options: {} }) {
15121
15031
  };
15122
15032
  }
15123
15033
 
15124
- // src/ssr/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.ts
15034
+ // src/ssr-next/commerce/controllers/pagination/headless-core-commerce-pagination.ssr.ts
15125
15035
  function definePagination(props) {
15126
- ensureAtLeastOneSolutionType(props);
15127
15036
  return {
15128
15037
  listing: true,
15129
15038
  search: true,
@@ -15309,32 +15218,28 @@ var registerQuery = (state, actionPayload) => {
15309
15218
  state[id2] = query2;
15310
15219
  };
15311
15220
 
15312
- // src/ssr/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.ts
15313
- function defineParameterManager(options) {
15314
- ensureAtLeastOneSolutionType(options);
15221
+ // src/ssr-next/commerce/controllers/parameter-manager/headless-core-parameter-manager.ssr.ts
15222
+ function defineParameterManager() {
15315
15223
  return {
15316
15224
  listing: true,
15317
15225
  search: true,
15318
- ...options,
15319
15226
  buildWithProps: (engine, props, solutionType) => {
15320
15227
  if (solutionType === "listing" /* listing */) {
15321
15228
  if (!loadCommerceProductListingParameterReducers(engine)) {
15322
15229
  throw loadReducerError;
15323
15230
  }
15324
- const controller = buildProductListing(engine).parameterManager({
15231
+ return buildProductListing(engine).parameterManager({
15325
15232
  ...props,
15326
15233
  excludeDefaultParameters: true
15327
15234
  });
15328
- return createControllerWithKind(controller, "PARAMETER_MANAGER" /* ParameterManager */);
15329
15235
  } else {
15330
15236
  if (!loadCommerceSearchParameterReducers(engine)) {
15331
15237
  throw loadReducerError;
15332
15238
  }
15333
- const controller = buildSearch(engine).parameterManager({
15239
+ return buildSearch(engine).parameterManager({
15334
15240
  ...props,
15335
15241
  excludeDefaultParameters: true
15336
15242
  });
15337
- return createControllerWithKind(controller, "PARAMETER_MANAGER" /* ParameterManager */);
15338
15243
  }
15339
15244
  }
15340
15245
  };
@@ -15360,13 +15265,11 @@ function loadCommerceProductListingParameterReducers(engine) {
15360
15265
  return true;
15361
15266
  }
15362
15267
 
15363
- // src/ssr/commerce/controllers/product-list/headless-product-list.ssr.ts
15364
- function defineProductList(options) {
15365
- ensureAtLeastOneSolutionType(options);
15268
+ // src/ssr-next/commerce/controllers/product-list/headless-product-list.ssr.ts
15269
+ function defineProductList() {
15366
15270
  return {
15367
15271
  listing: true,
15368
15272
  search: true,
15369
- ...options,
15370
15273
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine) : buildSearch(engine)
15371
15274
  };
15372
15275
  }
@@ -15380,7 +15283,7 @@ function buildProductView(engine) {
15380
15283
  };
15381
15284
  }
15382
15285
 
15383
- // src/ssr/commerce/controllers/product-view/headless-product-view.ssr.ts
15286
+ // src/ssr-next/commerce/controllers/product-view/headless-product-view.ssr.ts
15384
15287
  function defineProductView() {
15385
15288
  return {
15386
15289
  listing: true,
@@ -15600,7 +15503,7 @@ function loadRecentQueriesListReducer(engine) {
15600
15503
  return true;
15601
15504
  }
15602
15505
 
15603
- // src/ssr/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.ts
15506
+ // src/ssr-next/commerce/controllers/recent-queries-list/headless-recent-queries-list.ssr.ts
15604
15507
  function defineRecentQueriesList(props = {}) {
15605
15508
  return {
15606
15509
  search: true,
@@ -15827,7 +15730,7 @@ function loadBaseRecommendationsReducers(engine) {
15827
15730
  return true;
15828
15731
  }
15829
15732
 
15830
- // src/ssr/commerce/controllers/recommendations/headless-recommendations.ssr.ts
15733
+ // src/ssr-next/commerce/controllers/recommendations/headless-recommendations.ssr.ts
15831
15734
  function defineRecommendations(props) {
15832
15735
  return {
15833
15736
  recommendation: true,
@@ -15836,10 +15739,9 @@ function defineRecommendations(props) {
15836
15739
  },
15837
15740
  buildWithProps: (engine, options) => {
15838
15741
  const staticOptions = props.options;
15839
- const controller = buildRecommendations(engine, {
15742
+ return buildRecommendations(engine, {
15840
15743
  options: { ...staticOptions, ...options }
15841
15744
  });
15842
- return createControllerWithKind(controller, "RECOMMENDATIONS" /* Recommendations */);
15843
15745
  }
15844
15746
  };
15845
15747
  }
@@ -16151,7 +16053,7 @@ function loadSearchBoxReducers(engine) {
16151
16053
  return true;
16152
16054
  }
16153
16055
 
16154
- // src/ssr/commerce/controllers/search-box/headless-search-box.ssr.ts
16056
+ // src/ssr-next/commerce/controllers/search-box/headless-search-box.ssr.ts
16155
16057
  function defineSearchBox(props = {}) {
16156
16058
  return {
16157
16059
  search: true,
@@ -16159,9 +16061,8 @@ function defineSearchBox(props = {}) {
16159
16061
  };
16160
16062
  }
16161
16063
 
16162
- // src/ssr/commerce/controllers/sort/headless-core-commerce-sort.ssr.ts
16064
+ // src/ssr-next/commerce/controllers/sort/headless-core-commerce-sort.ssr.ts
16163
16065
  function defineSort(props) {
16164
- ensureAtLeastOneSolutionType(props);
16165
16066
  return {
16166
16067
  listing: true,
16167
16068
  search: true,
@@ -16381,7 +16282,7 @@ function loadStandaloneSearchBoxReducers(engine) {
16381
16282
  return true;
16382
16283
  }
16383
16284
 
16384
- // src/ssr/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.ts
16285
+ // src/ssr-next/commerce/controllers/standalone-search-box/headless-standalone-search-box.ssr.ts
16385
16286
  function defineStandaloneSearchBox(props) {
16386
16287
  return {
16387
16288
  listing: true,
@@ -16390,13 +16291,11 @@ function defineStandaloneSearchBox(props) {
16390
16291
  };
16391
16292
  }
16392
16293
 
16393
- // src/ssr/commerce/controllers/summary/headless-core-summary.ssr.ts
16394
- function defineSummary(options) {
16395
- ensureAtLeastOneSolutionType(options);
16294
+ // src/ssr-next/commerce/controllers/summary/headless-core-summary.ssr.ts
16295
+ function defineSummary() {
16396
16296
  return {
16397
16297
  listing: true,
16398
16298
  search: true,
16399
- ...options,
16400
16299
  build: (engine, solutionType) => solutionType === "listing" /* listing */ ? buildProductListing(engine).summary() : buildSearch(engine).summary()
16401
16300
  };
16402
16301
  }
@@ -16516,7 +16415,7 @@ function loadNotifyTriggerReducers(engine) {
16516
16415
  return true;
16517
16416
  }
16518
16417
 
16519
- // src/ssr/commerce/controllers/triggers/headless-notify-trigger.ssr.ts
16418
+ // src/ssr-next/commerce/controllers/triggers/headless-notify-trigger.ssr.ts
16520
16419
  function defineNotifyTrigger() {
16521
16420
  return {
16522
16421
  listing: true,
@@ -16556,7 +16455,7 @@ function loadQueryTriggerReducers(engine) {
16556
16455
  return true;
16557
16456
  }
16558
16457
 
16559
- // src/ssr/commerce/controllers/triggers/headless-query-trigger.ssr.ts
16458
+ // src/ssr-next/commerce/controllers/triggers/headless-query-trigger.ssr.ts
16560
16459
  function defineQueryTrigger() {
16561
16460
  return {
16562
16461
  search: true,
@@ -16597,7 +16496,7 @@ function loadRedirectionReducers(engine) {
16597
16496
  return true;
16598
16497
  }
16599
16498
 
16600
- // src/ssr/commerce/controllers/triggers/headless-redirection-trigger.ssr.ts
16499
+ // src/ssr-next/commerce/controllers/triggers/headless-redirection-trigger.ssr.ts
16601
16500
  function defineRedirectionTrigger() {
16602
16501
  return {
16603
16502
  search: true,
@@ -17889,7 +17788,325 @@ function createCommerceAPIClient(configuration2, logger) {
17889
17788
  });
17890
17789
  }
17891
17790
 
17892
- // src/ssr/commerce/factories/build-factory.ts
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
17893
18110
  function isListingFetchCompletedAction(action) {
17894
18111
  return /^commerce\/productListing\/fetch\/(fulfilled|rejected)$/.test(
17895
18112
  action.type
@@ -17961,222 +18178,102 @@ function buildSSRCommerceEngine(solutionType, options, recommendationCount) {
17961
18178
  }
17962
18179
  };
17963
18180
  }
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
- }
17969
18181
  var buildFactory = (controllerDefinitions, options) => (solutionType) => async (...[buildOptions]) => {
18182
+ const controllerProps = wireControllerParams(
18183
+ solutionType,
18184
+ controllerDefinitions,
18185
+ buildOptions
18186
+ );
17970
18187
  const logger = buildLogger(options.loggerOptions);
17971
18188
  if (!options.navigatorContextProvider) {
17972
18189
  logger.warn(
17973
18190
  "[WARNING] Missing navigator context in server-side code. Make sure to set it with `setNavigatorContextProvider` before calling fetchStaticState()"
17974
18191
  );
17975
18192
  }
17976
- const controllerProps = buildOptions && "controllers" in buildOptions ? buildOptions.controllers : {};
17977
- const enabledRecommendationControllers = fetchActiveRecommendationControllers(controllerProps, solutionType);
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
+ };
17978
18202
  const engine = buildSSRCommerceEngine(
17979
18203
  solutionType,
17980
- buildOptions && "extend" in buildOptions && buildOptions?.extend ? await buildOptions.extend(options) : options,
18204
+ engineOptions,
17981
18205
  enabledRecommendationControllers
17982
18206
  );
17983
18207
  const controllers = buildControllerDefinitions({
17984
18208
  definitionsMap: controllerDefinitions ?? {},
17985
18209
  engine,
17986
18210
  solutionType,
17987
- propsMap: buildOptions && "controllers" in buildOptions ? buildOptions.controllers : {}
18211
+ propsMap: controllerProps
17988
18212
  });
18213
+ if (buildOptions && "searchActions" in buildOptions) {
18214
+ buildOptions.searchActions.forEach((action) => {
18215
+ engine.dispatch(action);
18216
+ });
18217
+ }
17989
18218
  return {
17990
18219
  engine,
17991
18220
  controllers
17992
18221
  };
17993
18222
  };
17994
18223
 
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(
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(
18014
18228
  controllerDefinitions,
18015
18229
  options
18016
18230
  )(solutionType);
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
- );
18039
-
18040
- // src/ssr/commerce/factories/recommendation-hydrated-state-factory.ts
18041
- function hydratedRecommendationStaticStateFactory(controllerDefinitions, options) {
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
- );
18231
+ const { engine, controllers } = await solutionTypeBuild(...params);
18232
+ await engine.waitForRequestCompletedAction();
18233
+ return { engine, controllers };
18234
+ };
18076
18235
  }
18077
18236
 
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
- }
18237
+ // src/ssr-next/commerce/factories/recommendation-hydrated-state-factory.ts
18238
+ 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 };
18123
18247
  };
18124
18248
  }
18125
18249
 
18126
- // src/ssr/commerce/factories/recommendation-static-state-factory.ts
18250
+ // src/ssr-next/commerce/factories/recommendation-static-state-factory.ts
18127
18251
  function fetchRecommendationStaticStateFactory(controllerDefinitions, options) {
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 [];
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
+ };
18137
18276
  };
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
- );
18180
18277
  }
18181
18278
 
18182
18279
  // src/utils/runtime.ts
@@ -18184,7 +18281,7 @@ function isBrowser2() {
18184
18281
  return typeof window !== "undefined" && typeof document !== "undefined";
18185
18282
  }
18186
18283
 
18187
- // src/ssr/common/augment-preprocess-request.ts
18284
+ // src/ssr-next/common/augment-preprocess-request.ts
18188
18285
  function augmentPreprocessRequestWithForwardedFor(options) {
18189
18286
  const originalPreprocessRequest = options.preprocessRequest;
18190
18287
  return async (request, clientOrigin, metadata) => {
@@ -18208,54 +18305,56 @@ function augmentPreprocessRequestWithForwardedFor(options) {
18208
18305
  };
18209
18306
  }
18210
18307
 
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);
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);
18218
18316
  options.configuration.preprocessRequest = augmentPreprocessRequestWithForwardedFor({
18219
18317
  preprocessRequest: options.configuration.preprocessRequest,
18220
18318
  navigatorContextProvider: options.navigatorContextProvider,
18221
18319
  loggerOptions: options.loggerOptions
18222
18320
  });
18223
- const staticStateBuild = await fetchStaticStateFactory(
18224
- controllerDefinitions,
18225
- options
18226
- )(solutionType);
18227
- const staticState = await staticStateBuild.fromBuildResult({
18228
- buildResult
18229
- });
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
- });
18321
+ switch (solutionType) {
18322
+ case "listing" /* listing */:
18323
+ buildProductListing(engine).executeFirstRequest();
18324
+ break;
18325
+ case "search" /* search */:
18326
+ buildSearch(engine).executeFirstSearch();
18327
+ break;
18254
18328
  }
18329
+ const searchActions = await Promise.all(
18330
+ engine.waitForRequestCompletedAction()
18331
+ );
18332
+ const staticState = createStaticState({
18333
+ searchActions,
18334
+ controllers
18335
+ });
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
+ );
18255
18354
  }
18256
- );
18355
+ };
18257
18356
 
18258
- // src/ssr/commerce/engine/commerce-engine.ssr.ts
18357
+ // src/ssr-next/commerce/engine/commerce-engine.ssr.ts
18259
18358
  function defineCommerceEngine(options) {
18260
18359
  const { controllers: controllerDefinitions, ...engineOptions } = options;
18261
18360
  const getOptions = () => engineOptions;
@@ -18266,59 +18365,55 @@ function defineCommerceEngine(options) {
18266
18365
  const setAccessToken = (accessToken) => {
18267
18366
  engineOptions.configuration.accessToken = accessToken;
18268
18367
  };
18269
- const build = buildFactory(
18270
- controllerDefinitions,
18271
- getOptions()
18272
- );
18368
+ controllerDefinitions && validateControllerNames(controllerDefinitions);
18369
+ const augmentedControllerDefinition = {
18370
+ ...controllerDefinitions,
18371
+ parameterManager: defineParameterManager(),
18372
+ context: defineContext(),
18373
+ cart: defineCart()
18374
+ };
18273
18375
  const fetchStaticState = fetchStaticStateFactory(
18274
- controllerDefinitions,
18376
+ augmentedControllerDefinition,
18275
18377
  getOptions()
18276
18378
  );
18277
18379
  const hydrateStaticState = hydratedStaticStateFactory(
18278
- controllerDefinitions,
18380
+ augmentedControllerDefinition,
18279
18381
  getOptions()
18280
18382
  );
18281
18383
  const fetchRecommendationStaticState = fetchRecommendationStaticStateFactory(
18282
- controllerDefinitions,
18384
+ augmentedControllerDefinition,
18283
18385
  getOptions()
18284
18386
  );
18285
18387
  const hydrateRecommendationStaticState = hydratedRecommendationStaticStateFactory(
18286
- controllerDefinitions,
18388
+ augmentedControllerDefinition,
18287
18389
  getOptions()
18288
18390
  );
18391
+ const commonMethods = {
18392
+ setNavigatorContextProvider,
18393
+ getAccessToken,
18394
+ setAccessToken
18395
+ };
18289
18396
  return {
18290
18397
  listingEngineDefinition: {
18291
- build: build("listing" /* listing */),
18292
18398
  fetchStaticState: fetchStaticState("listing" /* listing */),
18293
18399
  hydrateStaticState: hydrateStaticState("listing" /* listing */),
18294
- setNavigatorContextProvider,
18295
- getAccessToken,
18296
- setAccessToken
18400
+ ...commonMethods
18297
18401
  },
18298
18402
  searchEngineDefinition: {
18299
- build: build("search" /* search */),
18300
18403
  fetchStaticState: fetchStaticState("search" /* search */),
18301
18404
  hydrateStaticState: hydrateStaticState("search" /* search */),
18302
- setNavigatorContextProvider,
18303
- getAccessToken,
18304
- setAccessToken
18405
+ ...commonMethods
18305
18406
  },
18306
18407
  recommendationEngineDefinition: {
18307
- build: build("recommendation" /* recommendation */),
18308
18408
  fetchStaticState: fetchRecommendationStaticState,
18309
18409
  hydrateStaticState: hydrateRecommendationStaticState,
18310
- setNavigatorContextProvider,
18311
- getAccessToken,
18312
- setAccessToken
18410
+ ...commonMethods
18313
18411
  },
18314
18412
  // TODO KIT-3738 : The standaloneEngineDefinition should not be async since no request is sent to the API
18315
18413
  standaloneEngineDefinition: {
18316
- build: build("standalone" /* standalone */),
18317
18414
  fetchStaticState: fetchStaticState("standalone" /* standalone */),
18318
18415
  hydrateStaticState: hydrateStaticState("standalone" /* standalone */),
18319
- setNavigatorContextProvider,
18320
- getAccessToken,
18321
- setAccessToken
18416
+ ...commonMethods
18322
18417
  }
18323
18418
  };
18324
18419
  }
@@ -18549,7 +18644,7 @@ function loadSortActions(engine) {
18549
18644
  var import_toolkit126 = require("@reduxjs/toolkit");
18550
18645
 
18551
18646
  // src/features/standalone-search-box-set/standalone-search-box-set-actions.ts
18552
- var import_bueno90 = require("@coveo/bueno");
18647
+ var import_bueno91 = require("@coveo/bueno");
18553
18648
  var import_toolkit125 = require("@reduxjs/toolkit");
18554
18649
 
18555
18650
  // src/api/search/plan/plan-endpoint.ts
@@ -18586,7 +18681,7 @@ var registerStandaloneSearchBox2 = (0, import_toolkit125.createAction)(
18586
18681
  (payload) => validatePayload(payload, {
18587
18682
  id: requiredNonEmptyString,
18588
18683
  redirectionUrl: requiredNonEmptyString,
18589
- overwrite: new import_bueno90.BooleanValue({ required: false })
18684
+ overwrite: new import_bueno91.BooleanValue({ required: false })
18590
18685
  })
18591
18686
  );
18592
18687
  var updateStandaloneSearchBoxRedirectionUrl2 = (0, import_toolkit125.createAction)(
@@ -18617,7 +18712,7 @@ var fetchRedirectUrl2 = (0, import_toolkit125.createAsyncThunk)(
18617
18712
  rejectWithValue,
18618
18713
  extra: { apiClient, validatePayload: validatePayload2, navigatorContext }
18619
18714
  }) => {
18620
- validatePayload2(payload, { id: new import_bueno90.StringValue({ emptyAllowed: false }) });
18715
+ validatePayload2(payload, { id: new import_bueno91.StringValue({ emptyAllowed: false }) });
18621
18716
  const request = await buildPlanRequest2(getState(), navigatorContext);
18622
18717
  const response = await apiClient.plan(request);
18623
18718
  if (isErrorResponse(response)) {
@@ -18760,13 +18855,13 @@ function loadTriggersActions(engine) {
18760
18855
  var import_toolkit129 = require("@reduxjs/toolkit");
18761
18856
 
18762
18857
  // src/features/folding/folding-actions.ts
18763
- var import_bueno91 = require("@coveo/bueno");
18858
+ var import_bueno92 = require("@coveo/bueno");
18764
18859
  var import_toolkit127 = require("@reduxjs/toolkit");
18765
18860
  var foldingOptionsSchemaDefinition = {
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 })
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 })
18770
18865
  };
18771
18866
  var registerFolding = (0, import_toolkit127.createAction)(
18772
18867
  "folding/register",
@@ -18904,12 +18999,12 @@ var fieldsReducer = (0, import_toolkit129.createReducer)(
18904
18999
  );
18905
19000
 
18906
19001
  // src/features/templates/templates-manager.ts
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({
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({
18913
19008
  required: false,
18914
19009
  each: requiredNonEmptyString
18915
19010
  })
@@ -18922,7 +19017,7 @@ function buildTemplatesManager() {
18922
19017
  (condition) => condition instanceof Function
18923
19018
  );
18924
19019
  if (!areConditionsValid) {
18925
- throw new import_bueno92.SchemaValidationError(
19020
+ throw new import_bueno93.SchemaValidationError(
18926
19021
  "Each template condition should be a function that takes a Result or Product as an argument and returns a boolean"
18927
19022
  );
18928
19023
  }
@@ -18983,10 +19078,10 @@ function loadResultTemplatesManagerReducers(engine) {
18983
19078
  }
18984
19079
 
18985
19080
  // src/features/commerce/parameters/parameters-serializer.ssr.ts
18986
- var import_bueno94 = require("@coveo/bueno");
19081
+ var import_bueno95 = require("@coveo/bueno");
18987
19082
 
18988
19083
  // src/features/search-parameters/search-parameter-utils.ts
18989
- var import_bueno93 = require("@coveo/bueno");
19084
+ var import_bueno94 = require("@coveo/bueno");
18990
19085
  function toArray(value) {
18991
19086
  return Array.isArray(value) ? value : [value];
18992
19087
  }
@@ -19031,7 +19126,7 @@ function wipeSearchParamsFromUrl(urlSearchParams) {
19031
19126
  return previousSearchParams;
19032
19127
  }
19033
19128
  function applyToUrlSearchParam(urlSearchParams, previousState, pair) {
19034
- if ((0, import_bueno94.isNullOrUndefined)(pair[1])) {
19129
+ if ((0, import_bueno95.isNullOrUndefined)(pair[1])) {
19035
19130
  return;
19036
19131
  }
19037
19132
  if (isSortPair(pair)) {
@@ -19089,7 +19184,7 @@ function isValidBasicKey3(key) {
19089
19184
  return key in supportedBasicParameters;
19090
19185
  }
19091
19186
  function extendSearchParams(commerceSearchParams, key, value) {
19092
- if ((0, import_bueno94.isNullOrUndefined)(value)) {
19187
+ if ((0, import_bueno95.isNullOrUndefined)(value)) {
19093
19188
  return;
19094
19189
  }
19095
19190
  if (key === "sortCriteria") {
@@ -19196,13 +19291,13 @@ function addFacetValuesToSearchParams(facetId2, paramKey) {
19196
19291
  }
19197
19292
 
19198
19293
  // src/features/commerce/product-templates/product-templates-helpers.ts
19199
- var import_bueno95 = require("@coveo/bueno");
19294
+ var import_bueno96 = require("@coveo/bueno");
19200
19295
  var getProductProperty = (product, property) => {
19201
19296
  const anyProduct = product;
19202
- if (!(0, import_bueno95.isNullOrUndefined)(anyProduct[property])) {
19297
+ if (!(0, import_bueno96.isNullOrUndefined)(anyProduct[property])) {
19203
19298
  return anyProduct[property];
19204
19299
  }
19205
- if (!(0, import_bueno95.isNullOrUndefined)(product.additionalFields[property])) {
19300
+ if (!(0, import_bueno96.isNullOrUndefined)(product.additionalFields[property])) {
19206
19301
  return product.additionalFields[property];
19207
19302
  }
19208
19303
  return null;
@@ -19210,14 +19305,14 @@ var getProductProperty = (product, property) => {
19210
19305
  var fieldsMustBeDefined = (fieldNames) => {
19211
19306
  return (product) => {
19212
19307
  return fieldNames.every(
19213
- (fieldName) => !(0, import_bueno95.isNullOrUndefined)(getProductProperty(product, fieldName))
19308
+ (fieldName) => !(0, import_bueno96.isNullOrUndefined)(getProductProperty(product, fieldName))
19214
19309
  );
19215
19310
  };
19216
19311
  };
19217
19312
  var fieldsMustNotBeDefined = (fieldNames) => {
19218
19313
  return (product) => {
19219
19314
  return fieldNames.every(
19220
- (fieldName) => (0, import_bueno95.isNullOrUndefined)(getProductProperty(product, fieldName))
19315
+ (fieldName) => (0, import_bueno96.isNullOrUndefined)(getProductProperty(product, fieldName))
19221
19316
  );
19222
19317
  };
19223
19318
  };
@@ -19243,7 +19338,7 @@ var fieldMustNotMatch = (fieldName, disallowedValues) => {
19243
19338
  };
19244
19339
  var getFieldValuesFromProduct = (fieldName, product) => {
19245
19340
  const rawValue = getProductProperty(product, fieldName);
19246
- return (0, import_bueno95.isArray)(rawValue) ? rawValue : [rawValue];
19341
+ return (0, import_bueno96.isArray)(rawValue) ? rawValue : [rawValue];
19247
19342
  };
19248
19343
  var ProductTemplatesHelpers = {
19249
19344
  getProductProperty,
@@ -19545,7 +19640,6 @@ function getBooleanOperatorSymbol(operator) {
19545
19640
  }
19546
19641
  // Annotate the CommonJS export names for ESM import in node:
19547
19642
  0 && (module.exports = {
19548
- Kind,
19549
19643
  ProductTemplatesHelpers,
19550
19644
  SolutionType,
19551
19645
  SortBy,