@labdigital/commercetools-mock 1.7.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
+ }
89
+ const values = Array.isArray(input) ? input : [input];
90
+ if (values.length < 1) {
91
+ return void 0;
88
92
  }
89
- if (Array.isArray(input)) {
90
- 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];
91
99
  }
92
- return [input];
100
+ return void 0;
93
101
  };
94
102
  var cloneObject = (o) => JSON.parse(JSON.stringify(o));
95
103
 
@@ -1771,6 +1779,9 @@ var AssociateRoleRepository = class extends AbstractResourceRepository {
1771
1779
  setBuyerAssignable: (context, resource, { buyerAssignable }) => {
1772
1780
  resource.buyerAssignable = buyerAssignable;
1773
1781
  },
1782
+ changeBuyerAssignable: (context, resource, { buyerAssignable }) => {
1783
+ resource.buyerAssignable = buyerAssignable;
1784
+ },
1774
1785
  setCustomFields: (context, resource, { name, value }) => {
1775
1786
  if (!resource.custom) {
1776
1787
  return;
@@ -4219,25 +4230,36 @@ var ProductProjectionSearch = class {
4219
4230
  getFacets(params, products) {
4220
4231
  if (!params.facet)
4221
4232
  return {};
4222
- const staged = false;
4223
4233
  const result = {};
4224
- 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
+ }
4225
4241
  const expression = generateFacetFunc(facet);
4226
4242
  if (expression.type === "TermExpression") {
4227
- result[facet] = this.termFacet(expression.source, products);
4243
+ result[facet] = this.termFacet(
4244
+ expression.source,
4245
+ products,
4246
+ countProducts
4247
+ );
4228
4248
  }
4229
4249
  if (expression.type === "RangeExpression") {
4230
4250
  result[expression.source] = this.rangeFacet(
4231
4251
  expression.source,
4232
4252
  expression.children,
4233
- products
4253
+ products,
4254
+ countProducts
4234
4255
  );
4235
4256
  }
4236
4257
  if (expression.type === "FilterExpression") {
4237
4258
  result[expression.source] = this.filterFacet(
4238
4259
  expression.source,
4239
4260
  expression.children,
4240
- products
4261
+ products,
4262
+ countProducts
4241
4263
  );
4242
4264
  }
4243
4265
  }
@@ -4248,7 +4270,7 @@ var ProductProjectionSearch = class {
4248
4270
  * - counting products
4249
4271
  * - correct dataType
4250
4272
  */
4251
- termFacet(facet, products) {
4273
+ termFacet(facet, products, countProducts) {
4252
4274
  const result = {
4253
4275
  type: "terms",
4254
4276
  dataType: "text",
@@ -4293,7 +4315,7 @@ var ProductProjectionSearch = class {
4293
4315
  }
4294
4316
  return result;
4295
4317
  }
4296
- filterFacet(source, filters, products) {
4318
+ filterFacet(source, filters, products, countProducts) {
4297
4319
  let count = 0;
4298
4320
  if (source.startsWith("variants.")) {
4299
4321
  for (const p of products) {
@@ -4312,7 +4334,7 @@ var ProductProjectionSearch = class {
4312
4334
  count
4313
4335
  };
4314
4336
  }
4315
- rangeFacet(source, ranges, products) {
4337
+ rangeFacet(source, ranges, products, countProducts) {
4316
4338
  const counts = ranges?.map((range) => {
4317
4339
  if (source.startsWith("variants.")) {
4318
4340
  const values = [];
@@ -4434,16 +4456,7 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
4434
4456
  };
4435
4457
  }
4436
4458
  search(context, query) {
4437
- const results = this._searchService.search(context.projectKey, {
4438
- filter: QueryParamsAsArray(query.filter),
4439
- "filter.query": QueryParamsAsArray(query["filter.query"]),
4440
- facet: QueryParamsAsArray(query.facet),
4441
- offset: query.offset ? Number(query.offset) : void 0,
4442
- limit: query.limit ? Number(query.limit) : void 0,
4443
- expand: QueryParamsAsArray(query.expand),
4444
- staged: query.staged === "true"
4445
- });
4446
- return results;
4459
+ return this._searchService.search(context.projectKey, query);
4447
4460
  }
4448
4461
  actions = {};
4449
4462
  };
@@ -5448,12 +5461,7 @@ var AbstractService = class {
5448
5461
  }
5449
5462
  // No idea what i'm doing
5450
5463
  _parseParam(value) {
5451
- if (Array.isArray(value)) {
5452
- return value;
5453
- } else if (value !== void 0) {
5454
- return [`${value}`];
5455
- }
5456
- return void 0;
5464
+ return queryParamsArray(value);
5457
5465
  }
5458
5466
  };
5459
5467
 
@@ -5896,9 +5904,25 @@ var ProductProjectionService = class extends AbstractService {
5896
5904
  return response.status(200).send(result);
5897
5905
  }
5898
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
+ };
5899
5923
  const resource = this.repository.search(
5900
5924
  getRepositoryContext(request),
5901
- request.query
5925
+ searchParams
5902
5926
  );
5903
5927
  return response.status(200).send(resource);
5904
5928
  }