@labdigital/commercetools-mock 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -82,14 +82,22 @@ var nestedLookup = (obj, path) => {
82
82
  }
83
83
  return val;
84
84
  };
85
- var QueryParamsAsArray = (input) => {
85
+ var queryParamsArray = (input) => {
86
86
  if (input == void 0) {
87
- return [];
87
+ return void 0;
88
88
  }
89
- if (Array.isArray(input)) {
90
- return input;
89
+ const values = Array.isArray(input) ? input : [input];
90
+ if (values.length < 1) {
91
+ return void 0;
91
92
  }
92
- return [input];
93
+ return values;
94
+ };
95
+ var queryParamsValue = (value) => {
96
+ const values = queryParamsArray(value);
97
+ if (values && values.length > 0) {
98
+ return values[0];
99
+ }
100
+ return void 0;
93
101
  };
94
102
  var cloneObject = (o) => JSON.parse(JSON.stringify(o));
95
103
 
@@ -4222,25 +4230,36 @@ var ProductProjectionSearch = class {
4222
4230
  getFacets(params, products) {
4223
4231
  if (!params.facet)
4224
4232
  return {};
4225
- const staged = false;
4226
4233
  const result = {};
4227
- for (const facet of params.facet) {
4234
+ const regexp = new RegExp(/ counting products$/);
4235
+ for (let facet of params.facet) {
4236
+ let countProducts = false;
4237
+ if (facet.endsWith(" counting products")) {
4238
+ facet = facet.replace(regexp, "");
4239
+ countProducts = true;
4240
+ }
4228
4241
  const expression = generateFacetFunc(facet);
4229
4242
  if (expression.type === "TermExpression") {
4230
- result[facet] = this.termFacet(expression.source, products);
4243
+ result[facet] = this.termFacet(
4244
+ expression.source,
4245
+ products,
4246
+ countProducts
4247
+ );
4231
4248
  }
4232
4249
  if (expression.type === "RangeExpression") {
4233
4250
  result[expression.source] = this.rangeFacet(
4234
4251
  expression.source,
4235
4252
  expression.children,
4236
- products
4253
+ products,
4254
+ countProducts
4237
4255
  );
4238
4256
  }
4239
4257
  if (expression.type === "FilterExpression") {
4240
4258
  result[expression.source] = this.filterFacet(
4241
4259
  expression.source,
4242
4260
  expression.children,
4243
- products
4261
+ products,
4262
+ countProducts
4244
4263
  );
4245
4264
  }
4246
4265
  }
@@ -4251,7 +4270,7 @@ var ProductProjectionSearch = class {
4251
4270
  * - counting products
4252
4271
  * - correct dataType
4253
4272
  */
4254
- termFacet(facet, products) {
4273
+ termFacet(facet, products, countProducts) {
4255
4274
  const result = {
4256
4275
  type: "terms",
4257
4276
  dataType: "text",
@@ -4296,7 +4315,7 @@ var ProductProjectionSearch = class {
4296
4315
  }
4297
4316
  return result;
4298
4317
  }
4299
- filterFacet(source, filters, products) {
4318
+ filterFacet(source, filters, products, countProducts) {
4300
4319
  let count = 0;
4301
4320
  if (source.startsWith("variants.")) {
4302
4321
  for (const p of products) {
@@ -4315,7 +4334,7 @@ var ProductProjectionSearch = class {
4315
4334
  count
4316
4335
  };
4317
4336
  }
4318
- rangeFacet(source, ranges, products) {
4337
+ rangeFacet(source, ranges, products, countProducts) {
4319
4338
  const counts = ranges?.map((range) => {
4320
4339
  if (source.startsWith("variants.")) {
4321
4340
  const values = [];
@@ -4437,16 +4456,7 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
4437
4456
  };
4438
4457
  }
4439
4458
  search(context, query) {
4440
- const results = this._searchService.search(context.projectKey, {
4441
- filter: QueryParamsAsArray(query.filter),
4442
- "filter.query": QueryParamsAsArray(query["filter.query"]),
4443
- facet: QueryParamsAsArray(query.facet),
4444
- offset: query.offset ? Number(query.offset) : void 0,
4445
- limit: query.limit ? Number(query.limit) : void 0,
4446
- expand: QueryParamsAsArray(query.expand),
4447
- staged: query.staged === "true"
4448
- });
4449
- return results;
4459
+ return this._searchService.search(context.projectKey, query);
4450
4460
  }
4451
4461
  actions = {};
4452
4462
  };
@@ -5451,12 +5461,7 @@ var AbstractService = class {
5451
5461
  }
5452
5462
  // No idea what i'm doing
5453
5463
  _parseParam(value) {
5454
- if (Array.isArray(value)) {
5455
- return value;
5456
- } else if (value !== void 0) {
5457
- return [`${value}`];
5458
- }
5459
- return void 0;
5464
+ return queryParamsArray(value);
5460
5465
  }
5461
5466
  };
5462
5467
 
@@ -5899,9 +5904,25 @@ var ProductProjectionService = class extends AbstractService {
5899
5904
  return response.status(200).send(result);
5900
5905
  }
5901
5906
  search(request, response) {
5907
+ const query = request.query;
5908
+ const searchParams = {
5909
+ filter: queryParamsArray(query.filter),
5910
+ "filter.query": queryParamsArray(query["filter.query"]),
5911
+ facet: queryParamsArray(query.facet),
5912
+ expand: queryParamsArray(query.expand),
5913
+ staged: queryParamsValue(query.staged) === "true",
5914
+ localeProjection: queryParamsValue(query.localeProjection),
5915
+ storeProjection: queryParamsValue(query.storeProjection),
5916
+ priceChannel: queryParamsValue(query.priceChannel),
5917
+ priceCountry: queryParamsValue(query.priceCountry),
5918
+ priceCurrency: queryParamsValue(query.priceCurrency),
5919
+ priceCustomerGroup: queryParamsValue(query.priceCustomerGroup),
5920
+ offset: query.offset ? Number(queryParamsValue(query.offset)) : void 0,
5921
+ limit: query.limit ? Number(queryParamsValue(query.limit)) : void 0
5922
+ };
5902
5923
  const resource = this.repository.search(
5903
5924
  getRepositoryContext(request),
5904
- request.query
5925
+ searchParams
5905
5926
  );
5906
5927
  return response.status(200).send(resource);
5907
5928
  }