@infrab4a/connect 2.0.0-beta.0 → 2.0.0

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.
@@ -289,7 +289,7 @@
289
289
  Status["CANCELLED"] = "Cancelado";
290
290
  })(exports.Status || (exports.Status = {}));
291
291
 
292
- /*! *****************************************************************************
292
+ /******************************************************************************
293
293
  Copyright (c) Microsoft Corporation.
294
294
 
295
295
  Permission to use, copy, modify, and/or distribute this software for any
@@ -387,7 +387,7 @@
387
387
  function step(op) {
388
388
  if (f)
389
389
  throw new TypeError("Generator is already executing.");
390
- while (_)
390
+ while (g && (g = 0, op[0] && (_ = 0)), _)
391
391
  try {
392
392
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
393
393
  return t;
@@ -451,7 +451,11 @@
451
451
  var __createBinding = Object.create ? (function (o, m, k, k2) {
452
452
  if (k2 === undefined)
453
453
  k2 = k;
454
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
454
+ var desc = Object.getOwnPropertyDescriptor(m, k);
455
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
456
+ desc = { enumerable: true, get: function () { return m[k]; } };
457
+ }
458
+ Object.defineProperty(o, k2, desc);
455
459
  }) : (function (o, m, k, k2) {
456
460
  if (k2 === undefined)
457
461
  k2 = k;
@@ -606,6 +610,11 @@
606
610
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
607
611
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
608
612
  }
613
+ function __classPrivateFieldIn(state, receiver) {
614
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
615
+ throw new TypeError("Cannot use 'in' operator on non-object");
616
+ return typeof state === "function" ? receiver === state : state.has(receiver);
617
+ }
609
618
 
610
619
  var Edition = /** @class */ (function (_super) {
611
620
  __extends(Edition, _super);
@@ -889,7 +898,7 @@
889
898
  Exclusivities[Exclusivities["NON_SUBSCRIBER"] = 6] = "NON_SUBSCRIBER";
890
899
  })(exports.Exclusivities || (exports.Exclusivities = {}));
891
900
 
892
- var COUPON_EXPIRATION = 60 * 60 * 24 * 30;
901
+ var COUPON_EXPIRATION = +1000 * 60 * 60 * 24 * 30;
893
902
  var Coupon = /** @class */ (function (_super) {
894
903
  __extends(Coupon, _super);
895
904
  function Coupon() {
@@ -1997,7 +2006,7 @@
1997
2006
  if (filtersKeysWithUnordered.length)
1998
2007
  filtersKeysWithUnordered.forEach(function (filterKey) {
1999
2008
  var _a;
2000
- return (orderBy = Object.assign((_a = {}, _a[filterKey] = 'asc', _a), orderBy));
2009
+ return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_a = {}, _a[filterKey] = 'asc', _a) : {})), orderBy));
2001
2010
  });
2002
2011
  Object.keys(orderBy).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
2003
2012
  }
@@ -3082,7 +3091,9 @@
3082
3091
  return false;
3083
3092
  var converter = fieldOption.to
3084
3093
  ? fieldOption.to
3085
- : function (value) { return (filter.operator === exports.Where.LIKE && value.indexOf('%') < 0 ? "%" + value + "%" : value); };
3094
+ : function (value) { return filter.operator === exports.Where.LIKE && !Array.isArray(filter.value) && value.indexOf('%') < 0
3095
+ ? "%" + value + "%"
3096
+ : value; };
3086
3097
  return Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
3087
3098
  ? filter.value.map(function (fieldValue) { return converter(fieldValue); })
3088
3099
  : converter(filter.value);
@@ -3663,10 +3674,9 @@
3663
3674
  type: HasuraGraphQLColumnType.Jsonb,
3664
3675
  from: function (tags, row) { return ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }); },
3665
3676
  bindPersistData: function (value) {
3666
- var _a, _b;
3667
3677
  return {
3668
3678
  brand_condition: value.brand,
3669
- tag_condition: "{\"" + (((_b = (_a = value === null || value === void 0 ? void 0 : value.tags) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '","')) || '') + "\"}",
3679
+ tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
3670
3680
  };
3671
3681
  },
3672
3682
  bindFindFilter: function (sentence) {
@@ -3698,34 +3708,34 @@
3698
3708
  });
3699
3709
  var _a;
3700
3710
  return __awaiter(this, void 0, void 0, function () {
3701
- var _c;
3702
- return __generator(this, function (_d) {
3703
- switch (_d.label) {
3711
+ var _b;
3712
+ return __generator(this, function (_c) {
3713
+ switch (_c.label) {
3704
3714
  case 0:
3705
3715
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3706
3716
  return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3707
3717
  case 1:
3708
- _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3718
+ _b = (_a = (_c.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3709
3719
  return [3 /*break*/, 3];
3710
3720
  case 2:
3711
- _c = _super.get.call(this, identifiers);
3712
- _d.label = 3;
3713
- case 3: return [2 /*return*/, _c];
3721
+ _b = _super.get.call(this, identifiers);
3722
+ _c.label = 3;
3723
+ case 3: return [2 /*return*/, _b];
3714
3724
  }
3715
3725
  });
3716
3726
  });
3717
3727
  };
3718
3728
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3719
3729
  return __awaiter(this, void 0, void 0, function () {
3720
- var _c, data, count;
3721
- return __generator(this, function (_d) {
3722
- switch (_d.label) {
3730
+ var _b, data, count;
3731
+ return __generator(this, function (_c) {
3732
+ switch (_c.label) {
3723
3733
  case 0:
3724
3734
  if (!slug)
3725
3735
  return [2 /*return*/];
3726
3736
  return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3727
3737
  case 1:
3728
- _c = _d.sent(), data = _c.data, count = _c.count;
3738
+ _b = _c.sent(), data = _b.data, count = _b.count;
3729
3739
  if (count > 1)
3730
3740
  throw new DuplicatedResultsError('Query returned duplicated values');
3731
3741
  if (!count)
@@ -3738,33 +3748,33 @@
3738
3748
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3739
3749
  if (limit === void 0) { limit = 4; }
3740
3750
  return __awaiter(this, void 0, void 0, function () {
3741
- var _c, categories, count, homeSections;
3751
+ var _b, categories, count, homeSections;
3742
3752
  var _this = this;
3743
- return __generator(this, function (_d) {
3744
- switch (_d.label) {
3753
+ return __generator(this, function (_c) {
3754
+ switch (_c.label) {
3745
3755
  case 0: return [4 /*yield*/, this.find({
3746
3756
  filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3747
3757
  })];
3748
3758
  case 1:
3749
- _c = _d.sent(), categories = _c.data, count = _c.count;
3759
+ _b = _c.sent(), categories = _b.data, count = _b.count;
3750
3760
  if (!count)
3751
3761
  throw new NotFoundError('Categories not found');
3752
3762
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3753
- var _c;
3754
- return __generator(this, function (_d) {
3755
- switch (_d.label) {
3763
+ var _b;
3764
+ return __generator(this, function (_c) {
3765
+ switch (_c.label) {
3756
3766
  case 0:
3757
- _c = {
3767
+ _b = {
3758
3768
  category: category
3759
3769
  };
3760
3770
  return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
3761
- case 1: return [2 /*return*/, (_c.products = _d.sent(),
3762
- _c)];
3771
+ case 1: return [2 /*return*/, (_b.products = _c.sent(),
3772
+ _b)];
3763
3773
  }
3764
3774
  });
3765
3775
  }); }))];
3766
3776
  case 2:
3767
- homeSections = _d.sent();
3777
+ homeSections = _c.sent();
3768
3778
  return [2 /*return*/, homeSections];
3769
3779
  }
3770
3780
  });
@@ -3773,15 +3783,15 @@
3773
3783
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3774
3784
  return __awaiter(this, void 0, void 0, function () {
3775
3785
  var products, publishedField, productsData;
3776
- var _c;
3777
- return __generator(this, function (_d) {
3778
- switch (_d.label) {
3786
+ var _b;
3787
+ return __generator(this, function (_c) {
3788
+ switch (_c.label) {
3779
3789
  case 0:
3780
3790
  if (!category.products)
3781
3791
  throw new RequiredArgumentError(['Category products is empty']);
3782
3792
  products = [];
3783
3793
  publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
3784
- return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_c = { id: { operator: exports.Where.IN, value: category.products } }, _c[publishedField] = true, _c), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3794
+ return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_b = { id: { operator: exports.Where.IN, value: category.products } }, _b[publishedField] = true, _b), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3785
3795
  'id',
3786
3796
  'name',
3787
3797
  'slug',
@@ -3806,7 +3816,7 @@
3806
3816
  'rate',
3807
3817
  ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
3808
3818
  case 1:
3809
- productsData = (_d.sent()).data;
3819
+ productsData = (_c.sent()).data;
3810
3820
  products.push.apply(products, __spreadArray([], __read(productsData)));
3811
3821
  return [2 /*return*/, products];
3812
3822
  }
@@ -4016,6 +4026,8 @@
4016
4026
  _e.label = 4;
4017
4027
  case 4:
4018
4028
  product = _c;
4029
+ if (product.productId)
4030
+ throw new NotFoundError('Product not found, it is a variant');
4019
4031
  _d = product;
4020
4032
  return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4021
4033
  case 5:
@@ -4458,7 +4470,7 @@
4458
4470
  });
4459
4471
  var _a;
4460
4472
  return __awaiter(this, void 0, void 0, function () {
4461
- var _c;
4473
+ var variant, _c;
4462
4474
  return __generator(this, function (_d) {
4463
4475
  switch (_d.label) {
4464
4476
  case 0:
@@ -4466,11 +4478,16 @@
4466
4478
  return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4467
4479
  case 1:
4468
4480
  _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4469
- return [3 /*break*/, 3];
4470
- case 2:
4471
- _c = _super.get.call(this, identifiers);
4472
- _d.label = 3;
4473
- case 3: return [2 /*return*/, _c];
4481
+ return [3 /*break*/, 4];
4482
+ case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
4483
+ case 3:
4484
+ _c = _d.sent();
4485
+ _d.label = 4;
4486
+ case 4:
4487
+ variant = _c;
4488
+ if (!variant.productId)
4489
+ throw new NotFoundError("Variant not found, it is a product");
4490
+ return [2 /*return*/, variant];
4474
4491
  }
4475
4492
  });
4476
4493
  });