@infrab4a/connect 3.5.0-beta.0 → 3.5.0-beta.2

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.
Files changed (42) hide show
  1. package/bundles/infrab4a-connect.umd.js +282 -141
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/generic/repository/find.repository.d.ts +3 -0
  4. package/domain/shopping/models/campaign-dashboard.d.ts +15 -0
  5. package/domain/shopping/models/campaign-hashtag.d.ts +18 -0
  6. package/domain/shopping/models/enums/order-status.enum.d.ts +2 -2
  7. package/domain/shopping/models/index.d.ts +5 -4
  8. package/domain/shopping/repositories/campaign-dashboard.repository.d.ts +4 -0
  9. package/domain/shopping/repositories/campaign-hashtag.repository.d.ts +4 -0
  10. package/domain/shopping/repositories/index.d.ts +4 -2
  11. package/esm2015/domain/generic/repository/find.repository.js +1 -1
  12. package/esm2015/domain/shopping/models/campaign-dashboard.js +7 -0
  13. package/esm2015/domain/shopping/models/campaign-hashtag.js +7 -0
  14. package/esm2015/domain/shopping/models/enums/order-status.enum.js +3 -3
  15. package/esm2015/domain/shopping/models/index.js +6 -5
  16. package/esm2015/domain/shopping/repositories/campaign-dashboard.repository.js +2 -0
  17. package/esm2015/domain/shopping/repositories/campaign-hashtag.repository.js +2 -0
  18. package/esm2015/domain/shopping/repositories/index.js +5 -3
  19. package/esm2015/infra/firebase/firestore/enums/firestore-field-type.enum.js +10 -0
  20. package/esm2015/infra/firebase/firestore/enums/index.js +2 -0
  21. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +11 -5
  22. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +34 -7
  23. package/esm2015/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.js +12 -0
  24. package/esm2015/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.js +12 -0
  25. package/esm2015/infra/firebase/firestore/repositories/shopping/index.js +6 -4
  26. package/esm2015/infra/firebase/firestore/repositories/shopping/order-firestore.repository.js +7 -2
  27. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  28. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +17 -12
  29. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +28 -17
  30. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +7 -4
  31. package/esm2015/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.js +2 -2
  32. package/fesm2015/infrab4a-connect.js +182 -87
  33. package/fesm2015/infrab4a-connect.js.map +1 -1
  34. package/infra/firebase/firestore/enums/firestore-field-type.enum.d.ts +8 -0
  35. package/infra/firebase/firestore/enums/index.d.ts +1 -0
  36. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +2 -2
  37. package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +9 -0
  38. package/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +9 -0
  39. package/infra/firebase/firestore/repositories/shopping/index.d.ts +5 -3
  40. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +3 -1
  41. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +4 -9
  42. package/package.json +2 -2
@@ -1348,17 +1348,54 @@
1348
1348
  return Variant;
1349
1349
  }(BaseModel));
1350
1350
 
1351
- exports.OrderStatus = void 0;
1352
- (function (OrderStatus) {
1353
- OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
1354
- OrderStatus["EM_PREPARO"] = "Preparando pedido";
1355
- OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
1356
- OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
1357
- OrderStatus["ENVIADO"] = "Pedido Enviado";
1358
- OrderStatus["ENTREGUE"] = "Pedido entregue";
1359
- OrderStatus["CANCELADO"] = "Cancelado";
1360
- OrderStatus["CREDIT_CARD"] = "credit_card";
1361
- })(exports.OrderStatus || (exports.OrderStatus = {}));
1351
+ var Buy2Win = /** @class */ (function (_super) {
1352
+ __extends(Buy2Win, _super);
1353
+ function Buy2Win() {
1354
+ return _super !== null && _super.apply(this, arguments) || this;
1355
+ }
1356
+ Object.defineProperty(Buy2Win, "identifiersFields", {
1357
+ get: function () {
1358
+ return ['id'];
1359
+ },
1360
+ enumerable: false,
1361
+ configurable: true
1362
+ });
1363
+ return Buy2Win;
1364
+ }(BaseModel));
1365
+ __decorate([
1366
+ classTransformer.Type(function () { return Category; }),
1367
+ __metadata("design:type", Array)
1368
+ ], Buy2Win.prototype, "categories", void 0);
1369
+
1370
+ var CampaignDashboard = /** @class */ (function (_super) {
1371
+ __extends(CampaignDashboard, _super);
1372
+ function CampaignDashboard() {
1373
+ return _super !== null && _super.apply(this, arguments) || this;
1374
+ }
1375
+ Object.defineProperty(CampaignDashboard, "identifiersFields", {
1376
+ get: function () {
1377
+ return ['id'];
1378
+ },
1379
+ enumerable: false,
1380
+ configurable: true
1381
+ });
1382
+ return CampaignDashboard;
1383
+ }(BaseModel));
1384
+
1385
+ var CampaignHashtag = /** @class */ (function (_super) {
1386
+ __extends(CampaignHashtag, _super);
1387
+ function CampaignHashtag() {
1388
+ return _super !== null && _super.apply(this, arguments) || this;
1389
+ }
1390
+ Object.defineProperty(CampaignHashtag, "identifiersFields", {
1391
+ get: function () {
1392
+ return ['id'];
1393
+ },
1394
+ enumerable: false,
1395
+ configurable: true
1396
+ });
1397
+ return CampaignHashtag;
1398
+ }(BaseModel));
1362
1399
 
1363
1400
  var LineItem = /** @class */ (function (_super) {
1364
1401
  __extends(LineItem, _super);
@@ -1422,6 +1459,18 @@
1422
1459
  __metadata("design:type", Coupon)
1423
1460
  ], Checkout.prototype, "coupon", void 0);
1424
1461
 
1462
+ exports.OrderStatus = void 0;
1463
+ (function (OrderStatus) {
1464
+ OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
1465
+ OrderStatus["EM_PREPARO"] = "Preparando pedido";
1466
+ OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
1467
+ OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
1468
+ OrderStatus["ENVIADO"] = "Enviado";
1469
+ OrderStatus["ENTREGUE"] = "Entregue";
1470
+ OrderStatus["CANCELADO"] = "Cancelado";
1471
+ OrderStatus["CREDIT_CARD"] = "credit_card";
1472
+ })(exports.OrderStatus || (exports.OrderStatus = {}));
1473
+
1425
1474
  var Order = /** @class */ (function (_super) {
1426
1475
  __extends(Order, _super);
1427
1476
  function Order() {
@@ -1465,25 +1514,6 @@
1465
1514
  __metadata("design:type", Coupon)
1466
1515
  ], CheckoutSubscription.prototype, "coupon", void 0);
1467
1516
 
1468
- var Buy2Win = /** @class */ (function (_super) {
1469
- __extends(Buy2Win, _super);
1470
- function Buy2Win() {
1471
- return _super !== null && _super.apply(this, arguments) || this;
1472
- }
1473
- Object.defineProperty(Buy2Win, "identifiersFields", {
1474
- get: function () {
1475
- return ['id'];
1476
- },
1477
- enumerable: false,
1478
- configurable: true
1479
- });
1480
- return Buy2Win;
1481
- }(BaseModel));
1482
- __decorate([
1483
- classTransformer.Type(function () { return Category; }),
1484
- __metadata("design:type", Array)
1485
- ], Buy2Win.prototype, "categories", void 0);
1486
-
1487
1517
  exports.FilterType = void 0;
1488
1518
  (function (FilterType) {
1489
1519
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -1865,6 +1895,30 @@
1865
1895
  }());
1866
1896
 
1867
1897
  var withFirestore = function (MixinBase) {
1898
+ var isObjectsAndNoDate = function (data) { return data &&
1899
+ !Array.isArray(data) &&
1900
+ typeof data === 'object' &&
1901
+ (data === null || data === void 0 ? void 0 : data.constructor.name) !== 'Timestamp' &&
1902
+ !('seconds' in data); };
1903
+ var bindDate = function (data, keyName) {
1904
+ if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'Timestamp')
1905
+ return data.toDate();
1906
+ if (data && typeof data === 'object' && 'seconds' in data)
1907
+ return new Date(data.seconds * 1000);
1908
+ if (typeof data === 'number' && ['createdAt', 'updatedAt'].includes(keyName))
1909
+ return new Date(data);
1910
+ return data;
1911
+ };
1912
+ var bindAllDateFromObject = function (data) {
1913
+ return Object.keys(data).reduce(function (object, key) {
1914
+ var _a;
1915
+ return (Object.assign(Object.assign({}, object), (_a = {}, _a[key] = isObjectsAndNoDate(data[key])
1916
+ ? bindAllDateFromObject(data[key])
1917
+ : Array.isArray(data[key])
1918
+ ? data[key].map(function (element) { return (isObjectsAndNoDate(element) ? bindAllDateFromObject(element) : element); })
1919
+ : bindDate(data[key], key), _a)));
1920
+ }, {});
1921
+ };
1868
1922
  return /** @class */ (function (_super) {
1869
1923
  __extends(class_1, _super);
1870
1924
  function class_1() {
@@ -1879,12 +1933,18 @@
1879
1933
  toFirestore: function (data) { return ((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data); },
1880
1934
  fromFirestore: function (snap) {
1881
1935
  var data = snap.data();
1882
- Object.keys(data).forEach(function (key) {
1883
- if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
1884
- data[key] = data[key].toDate();
1885
- }
1886
- });
1887
- return _this.model.toInstance(Object.assign(Object.assign({}, data), { id: snap.id }));
1936
+ var bindedData;
1937
+ try {
1938
+ var ids = { id: snap.id };
1939
+ bindedData = bindAllDateFromObject(data);
1940
+ return _this.model.toInstance(Object.assign(Object.assign({}, bindedData), ids));
1941
+ }
1942
+ catch (error) {
1943
+ console.info('id', snap.id);
1944
+ console.info('data', JSON.stringify(bindedData));
1945
+ console.error(error);
1946
+ throw error;
1947
+ }
1888
1948
  },
1889
1949
  };
1890
1950
  };
@@ -1946,6 +2006,16 @@
1946
2006
  }(MixinBase));
1947
2007
  };
1948
2008
 
2009
+ var FirestoreFieldType;
2010
+ (function (FirestoreFieldType) {
2011
+ FirestoreFieldType["String"] = "string";
2012
+ FirestoreFieldType["Number"] = "number";
2013
+ FirestoreFieldType["Boolean"] = "boolean";
2014
+ FirestoreFieldType["Timestamp"] = "timestamp";
2015
+ FirestoreFieldType["Array"] = "array";
2016
+ FirestoreFieldType["Map"] = "map";
2017
+ })(FirestoreFieldType || (FirestoreFieldType = {}));
2018
+
1949
2019
  var withFindFirestore = function (MixinBase) {
1950
2020
  var checkIfIsFilterOption = function (filter) { return !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator); };
1951
2021
  var getValueFromFilter = function (filter) {
@@ -1970,13 +2040,16 @@
1970
2040
  ? fieldName.toString()
1971
2041
  : Object.keys(plainInstance).find(function (key) { return plainInstance[key]; });
1972
2042
  if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
1973
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value))
2043
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
2044
+ (_this.fields[firestoreFieldName] === FirestoreFieldType.Array || !_this.fields[firestoreFieldName]))
1974
2045
  return queryReference.where(firestoreFieldName, 'array-contains-any', options.value);
1975
2046
  queryReference = queryReference.where(firestoreFieldName, '>=', options.value);
1976
2047
  queryReference = queryReference.where(firestoreFieldName, '<=', options.value + "~");
1977
2048
  return queryReference;
1978
2049
  }
1979
- if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
2050
+ if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN &&
2051
+ Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
2052
+ (_this.fields[firestoreFieldName] === FirestoreFieldType.Array || !_this.fields[firestoreFieldName]))
1980
2053
  return queryReference.where(firestoreFieldName, 'array-contains', options.value);
1981
2054
  if (lodash.isObject(options) && lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) && lodash.isNil(options === null || options === void 0 ? void 0 : options.value)) {
1982
2055
  return Object.keys(options).reduce(function (queryReferenceWithWhere, key) { return _this.buildWhereSentence(queryReferenceWithWhere, fieldName.toString() + "." + key, options[key]); }, queryReference);
@@ -1985,35 +2058,37 @@
1985
2058
  };
1986
2059
  return _this;
1987
2060
  }
1988
- FindFirestore.prototype.find = function (_a) {
1989
- var _b = _a === void 0 ? {} : _a, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
2061
+ FindFirestore.prototype.find = function (_b) {
2062
+ var _c = _b === void 0 ? {} : _b, filters = _c.filters, limits = _c.limits, orderBy = _c.orderBy, options = _c.options;
2063
+ var _a;
1990
2064
  return __awaiter(this, void 0, void 0, function () {
1991
- var orderByKeys, query, filtersKeysWithUnordered, docs, data;
1992
- return __generator(this, function (_a) {
1993
- switch (_a.label) {
2065
+ var orderByKeys, enableCount, query, filtersKeysWithUnordered, docs, data;
2066
+ return __generator(this, function (_b) {
2067
+ switch (_b.label) {
1994
2068
  case 0:
1995
2069
  orderByKeys = Object.keys(orderBy || {});
2070
+ enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
1996
2071
  query = this.collection(this.buildCollectionPathForFind(filters || {}));
1997
2072
  query = this.makeFirestoreWhere(query, filters || {});
1998
2073
  if (orderByKeys.length) {
1999
2074
  filtersKeysWithUnordered = Object.keys(filters || {}).filter(function (filterKey) { return !orderByKeys.includes(filterKey); });
2000
2075
  if (filtersKeysWithUnordered.length)
2001
2076
  filtersKeysWithUnordered.forEach(function (filterKey) {
2002
- var _a;
2003
- return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_a = {}, _a[filterKey] = 'asc', _a) : {})), orderBy));
2077
+ var _b;
2078
+ return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_b = {}, _b[filterKey] = 'asc', _b) : {})), orderBy));
2004
2079
  });
2005
2080
  Object.keys(orderBy).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
2006
2081
  }
2007
2082
  return [4 /*yield*/, this.defineLimits(query, filters, limits)];
2008
2083
  case 1:
2009
- query = _a.sent();
2084
+ query = _b.sent();
2010
2085
  return [4 /*yield*/, query.get()];
2011
2086
  case 2:
2012
- docs = _a.sent();
2087
+ docs = _b.sent();
2013
2088
  data = docs.docs.map(function (doc) { return doc.data(); });
2014
2089
  return [2 /*return*/, {
2015
2090
  data: data,
2016
- count: this.calculateCount(data, limits),
2091
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
2017
2092
  }];
2018
2093
  }
2019
2094
  });
@@ -2028,23 +2103,23 @@
2028
2103
  };
2029
2104
  FindFirestore.prototype.defineLimits = function (query, filters, limits) {
2030
2105
  return __awaiter(this, void 0, void 0, function () {
2031
- var _a, _b;
2032
- return __generator(this, function (_c) {
2033
- switch (_c.label) {
2106
+ var _b, _c;
2107
+ return __generator(this, function (_d) {
2108
+ switch (_d.label) {
2034
2109
  case 0:
2035
2110
  if (!(limits === null || limits === void 0 ? void 0 : limits.offset)) return [3 /*break*/, 3];
2036
2111
  if (!this.model.isModel(limits.offset)) return [3 /*break*/, 2];
2037
- _b = (_a = query).startAfter;
2112
+ _c = (_b = query).startAfter;
2038
2113
  return [4 /*yield*/, this.collection(this.buildCollectionPathForFind(filters))
2039
2114
  .doc(limits.offset[limits.offset.identifiersFields.shift()])
2040
2115
  .get()];
2041
2116
  case 1:
2042
- query = _b.apply(_a, [_c.sent()]);
2117
+ query = _c.apply(_b, [_d.sent()]);
2043
2118
  return [3 /*break*/, 3];
2044
2119
  case 2:
2045
2120
  if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset))
2046
2121
  query = query.startAt(limits.offset);
2047
- _c.label = 3;
2122
+ _d.label = 3;
2048
2123
  case 3:
2049
2124
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2050
2125
  query = query.limit(limits.limit);
@@ -2638,6 +2713,42 @@
2638
2713
  return SubscriptionProductFirestoreRepository;
2639
2714
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2640
2715
 
2716
+ var Buy2WinFirestoreRepository = /** @class */ (function (_super) {
2717
+ __extends(Buy2WinFirestoreRepository, _super);
2718
+ function Buy2WinFirestoreRepository(firestore) {
2719
+ var _this = _super.call(this) || this;
2720
+ _this.firestore = firestore;
2721
+ _this.collectionName = 'buy2win';
2722
+ _this.model = Buy2Win;
2723
+ return _this;
2724
+ }
2725
+ return Buy2WinFirestoreRepository;
2726
+ }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2727
+
2728
+ var CampaignDashboardFirestoreRepository = /** @class */ (function (_super) {
2729
+ __extends(CampaignDashboardFirestoreRepository, _super);
2730
+ function CampaignDashboardFirestoreRepository(firestore) {
2731
+ var _this = _super.call(this) || this;
2732
+ _this.firestore = firestore;
2733
+ _this.collectionName = 'dashboardCampaignsAuto';
2734
+ _this.model = CampaignDashboard;
2735
+ return _this;
2736
+ }
2737
+ return CampaignDashboardFirestoreRepository;
2738
+ }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2739
+
2740
+ var CampaignHashtagFirestoreRepository = /** @class */ (function (_super) {
2741
+ __extends(CampaignHashtagFirestoreRepository, _super);
2742
+ function CampaignHashtagFirestoreRepository(firestore) {
2743
+ var _this = _super.call(this) || this;
2744
+ _this.firestore = firestore;
2745
+ _this.collectionName = 'hashtagCampaignsAuto';
2746
+ _this.model = CampaignHashtag;
2747
+ return _this;
2748
+ }
2749
+ return CampaignHashtagFirestoreRepository;
2750
+ }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2751
+
2641
2752
  var CheckoutFirestoreRepository = /** @class */ (function (_super) {
2642
2753
  __extends(CheckoutFirestoreRepository, _super);
2643
2754
  function CheckoutFirestoreRepository(firestore) {
@@ -2650,6 +2761,18 @@
2650
2761
  return CheckoutFirestoreRepository;
2651
2762
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2652
2763
 
2764
+ var CheckoutSubscriptionFirestoreRepository = /** @class */ (function (_super) {
2765
+ __extends(CheckoutSubscriptionFirestoreRepository, _super);
2766
+ function CheckoutSubscriptionFirestoreRepository(firestore) {
2767
+ var _this = _super.call(this) || this;
2768
+ _this.firestore = firestore;
2769
+ _this.collectionName = 'checkoutsSubscription';
2770
+ _this.model = CheckoutSubscription;
2771
+ return _this;
2772
+ }
2773
+ return CheckoutSubscriptionFirestoreRepository;
2774
+ }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2775
+
2653
2776
  var CouponFirestoreRepository = /** @class */ (function (_super) {
2654
2777
  __extends(CouponFirestoreRepository, _super);
2655
2778
  function CouponFirestoreRepository(firestore) {
@@ -2688,7 +2811,8 @@
2688
2811
  var _a;
2689
2812
  if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
2690
2813
  order.lineItems = order.lineItems.map(function (lineItem) {
2691
- if (!!lineItem.price[order.shop]) {
2814
+ var _a;
2815
+ if (!!((_a = lineItem.price) === null || _a === void 0 ? void 0 : _a[order.shop])) {
2692
2816
  var shopPrice = lineItem['price'][order.shop];
2693
2817
  lineItem['price'] = shopPrice;
2694
2818
  }
@@ -2699,6 +2823,9 @@
2699
2823
  };
2700
2824
  _this.collectionName = 'orders';
2701
2825
  _this.model = Order;
2826
+ _this.fields = {
2827
+ status: FirestoreFieldType.String,
2828
+ };
2702
2829
  return _this;
2703
2830
  }
2704
2831
  OrderFirestoreRepository.prototype.buildModelInstance = function () {
@@ -2715,6 +2842,17 @@
2715
2842
  return OrderFirestoreRepository;
2716
2843
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2717
2844
 
2845
+ var LegacyOrderFirestoreRepository = /** @class */ (function (_super) {
2846
+ __extends(LegacyOrderFirestoreRepository, _super);
2847
+ function LegacyOrderFirestoreRepository(firestore) {
2848
+ var _this = _super.call(this, firestore) || this;
2849
+ _this.firestore = firestore;
2850
+ _this.collectionName = 'legacyOrders';
2851
+ return _this;
2852
+ }
2853
+ return LegacyOrderFirestoreRepository;
2854
+ }(OrderFirestoreRepository));
2855
+
2718
2856
  var PaymentFirestoreRepository = /** @class */ (function (_super) {
2719
2857
  __extends(PaymentFirestoreRepository, _super);
2720
2858
  function PaymentFirestoreRepository(firestore) {
@@ -2727,18 +2865,6 @@
2727
2865
  return PaymentFirestoreRepository;
2728
2866
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2729
2867
 
2730
- var CheckoutSubscriptionFirestoreRepository = /** @class */ (function (_super) {
2731
- __extends(CheckoutSubscriptionFirestoreRepository, _super);
2732
- function CheckoutSubscriptionFirestoreRepository(firestore) {
2733
- var _this = _super.call(this) || this;
2734
- _this.firestore = firestore;
2735
- _this.collectionName = 'checkoutsSubscription';
2736
- _this.model = CheckoutSubscription;
2737
- return _this;
2738
- }
2739
- return CheckoutSubscriptionFirestoreRepository;
2740
- }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2741
-
2742
2868
  var SubscriptionPlanFirestoreRepository = /** @class */ (function (_super) {
2743
2869
  __extends(SubscriptionPlanFirestoreRepository, _super);
2744
2870
  function SubscriptionPlanFirestoreRepository(firestore) {
@@ -2751,29 +2877,6 @@
2751
2877
  return SubscriptionPlanFirestoreRepository;
2752
2878
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2753
2879
 
2754
- var Buy2WinFirestoreRepository = /** @class */ (function (_super) {
2755
- __extends(Buy2WinFirestoreRepository, _super);
2756
- function Buy2WinFirestoreRepository(firestore) {
2757
- var _this = _super.call(this) || this;
2758
- _this.firestore = firestore;
2759
- _this.collectionName = 'buy2win';
2760
- _this.model = Buy2Win;
2761
- return _this;
2762
- }
2763
- return Buy2WinFirestoreRepository;
2764
- }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2765
-
2766
- var LegacyOrderFirestoreRepository = /** @class */ (function (_super) {
2767
- __extends(LegacyOrderFirestoreRepository, _super);
2768
- function LegacyOrderFirestoreRepository(firestore) {
2769
- var _this = _super.call(this, firestore) || this;
2770
- _this.firestore = firestore;
2771
- _this.collectionName = 'legacyOrders';
2772
- return _this;
2773
- }
2774
- return LegacyOrderFirestoreRepository;
2775
- }(OrderFirestoreRepository));
2776
-
2777
2880
  var HomeFirestoreRepository = /** @class */ (function (_super) {
2778
2881
  __extends(HomeFirestoreRepository, _super);
2779
2882
  function HomeFirestoreRepository(firestore) {
@@ -3546,14 +3649,16 @@
3546
3649
  function FindHasuraGraphQLMixin() {
3547
3650
  return _super !== null && _super.apply(this, arguments) || this;
3548
3651
  }
3549
- FindHasuraGraphQLMixin.prototype.find = function (options) {
3652
+ FindHasuraGraphQLMixin.prototype.find = function (params) {
3653
+ var _a;
3550
3654
  return __awaiter(this, void 0, void 0, function () {
3551
- var _b, filters, limits, orderBy, variablesCount, variables, result, data, count;
3655
+ var _b, filters, limits, orderBy, options, enableCount, variablesCount, variables, result, data;
3552
3656
  var _this = this;
3553
3657
  return __generator(this, function (_c) {
3554
3658
  switch (_c.label) {
3555
3659
  case 0:
3556
- _b = options || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
3660
+ _b = params || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy, options = _b.options;
3661
+ enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
3557
3662
  variablesCount = Object.assign(Object.assign({}, (lodash.isNil(orderBy) ? {} : { order_by: { type: this.tableName + "_order_by!", list: true, value: orderBy } })), (lodash.isNil(filters)
3558
3663
  ? {}
3559
3664
  : {
@@ -3564,11 +3669,11 @@
3564
3669
  },
3565
3670
  }));
3566
3671
  variables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), variablesCount);
3567
- return [4 /*yield*/, this.query([
3672
+ return [4 /*yield*/, this.query(__spreadArray([
3568
3673
  {
3569
3674
  operation: this.tableName,
3570
- fields: options.fields
3571
- ? options.fields
3675
+ fields: params.fields
3676
+ ? params.fields
3572
3677
  .map(function (fieldName) {
3573
3678
  var _a;
3574
3679
  return (_a = _this.fields.find(function (fieldOption) { return fieldOption === fieldName; })) !== null && _a !== void 0 ? _a : _this.fields.find(function (fieldOption) { return Object.keys(fieldOption).shift() === fieldName; });
@@ -3576,18 +3681,20 @@
3576
3681
  .filter(Boolean)
3577
3682
  : this.fields,
3578
3683
  variables: variables,
3579
- },
3580
- {
3581
- operation: this.tableName + "_aggregate",
3582
- fields: [{ aggregate: ['count'] }],
3583
- variables: variablesCount,
3584
- },
3585
- ])];
3684
+ }
3685
+ ], __read((enableCount
3686
+ ? [
3687
+ {
3688
+ operation: this.tableName + "_aggregate",
3689
+ fields: [{ aggregate: ['count'] }],
3690
+ variables: variablesCount,
3691
+ },
3692
+ ]
3693
+ : []))))];
3586
3694
  case 1:
3587
3695
  result = _c.sent();
3588
3696
  data = result[this.tableName].map(function (row) { return _this.convertDataFromHasura(row); });
3589
- count = result[this.tableName + "_aggregate"].aggregate.count;
3590
- return [2 /*return*/, { count: count, data: data }];
3697
+ return [2 /*return*/, { data: data, count: enableCount ? result[this.tableName + "_aggregate"].aggregate.count : Infinity }];
3591
3698
  }
3592
3699
  });
3593
3700
  });
@@ -3741,7 +3848,7 @@
3741
3848
  switch (_d.label) {
3742
3849
  case 0:
3743
3850
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3744
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3851
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })];
3745
3852
  case 1:
3746
3853
  _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3747
3854
  return [3 /*break*/, 3];
@@ -3795,19 +3902,19 @@
3795
3902
  };
3796
3903
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3797
3904
  return __awaiter(this, void 0, void 0, function () {
3798
- var _c, data, count;
3799
- return __generator(this, function (_d) {
3800
- switch (_d.label) {
3905
+ var data;
3906
+ return __generator(this, function (_c) {
3907
+ switch (_c.label) {
3801
3908
  case 0:
3802
3909
  if (!slug)
3803
3910
  return [2 /*return*/];
3804
- return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3911
+ return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true }, options: { enableCount: false } })];
3805
3912
  case 1:
3806
- _c = _d.sent(), data = _c.data, count = _c.count;
3807
- if (count > 1)
3808
- throw new DuplicatedResultsError('Query returned duplicated values');
3809
- if (!count)
3913
+ data = (_c.sent()).data;
3914
+ if (!data.length)
3810
3915
  throw new NotFoundError("Category with slug " + slug + " not found");
3916
+ if (data.length > 1)
3917
+ throw new DuplicatedResultsError('Query returned duplicated values');
3811
3918
  return [2 /*return*/, data.shift()];
3812
3919
  }
3813
3920
  });
@@ -3816,17 +3923,46 @@
3816
3923
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3817
3924
  if (limit === void 0) { limit = 4; }
3818
3925
  return __awaiter(this, void 0, void 0, function () {
3819
- var _c, categories, count, homeSections;
3926
+ var categoriesFirestore, categoriesHasura, categories, _c, _d, _e, _f, _g, _h, _j, _k, homeSections;
3820
3927
  var _this = this;
3821
- return __generator(this, function (_d) {
3822
- switch (_d.label) {
3823
- case 0: return [4 /*yield*/, this.find({
3824
- filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3825
- })];
3928
+ return __generator(this, function (_l) {
3929
+ switch (_l.label) {
3930
+ case 0:
3931
+ if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
3932
+ return [2 /*return*/, []];
3933
+ categoriesFirestore = categoryIds.filter(function (categoryId) { return Number.isNaN(+categoryId); });
3934
+ categoriesHasura = categoryIds.filter(function (categoryId) { return +categoryId > 0; });
3935
+ categories = [];
3936
+ if (!categoriesFirestore.length) return [3 /*break*/, 2];
3937
+ _d = (_c = categories.push).apply;
3938
+ _e = [categories];
3939
+ _f = [[]];
3940
+ return [4 /*yield*/, this.find({
3941
+ filters: { firestoreId: { operator: exports.Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
3942
+ }).then(function (_c) {
3943
+ var data = _c.data;
3944
+ return data;
3945
+ })];
3826
3946
  case 1:
3827
- _c = _d.sent(), categories = _c.data, count = _c.count;
3828
- if (!count)
3829
- throw new NotFoundError('Categories not found');
3947
+ _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_l.sent())])]))]));
3948
+ _l.label = 2;
3949
+ case 2:
3950
+ if (!categoriesHasura.length) return [3 /*break*/, 4];
3951
+ _h = (_g = categories.push).apply;
3952
+ _j = [categories];
3953
+ _k = [[]];
3954
+ return [4 /*yield*/, this.find({
3955
+ filters: { id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
3956
+ }).then(function (_c) {
3957
+ var data = _c.data;
3958
+ return data;
3959
+ })];
3960
+ case 3:
3961
+ _h.apply(_g, _j.concat([__spreadArray.apply(void 0, _k.concat([__read.apply(void 0, [(_l.sent())])]))]));
3962
+ _l.label = 4;
3963
+ case 4:
3964
+ if (!categories.length)
3965
+ return [2 /*return*/, []];
3830
3966
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3831
3967
  var _c;
3832
3968
  return __generator(this, function (_d) {
@@ -3841,23 +3977,24 @@
3841
3977
  }
3842
3978
  });
3843
3979
  }); }))];
3844
- case 2:
3845
- homeSections = _d.sent();
3980
+ case 5:
3981
+ homeSections = _l.sent();
3846
3982
  return [2 /*return*/, homeSections];
3847
3983
  }
3848
3984
  });
3849
3985
  });
3850
3986
  };
3851
3987
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3988
+ var _a;
3852
3989
  return __awaiter(this, void 0, void 0, function () {
3853
3990
  var products, productsData;
3854
3991
  return __generator(this, function (_c) {
3855
3992
  switch (_c.label) {
3856
3993
  case 0:
3857
- if (!category.products)
3858
- throw new RequiredArgumentError(['Category products is empty']);
3994
+ if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
3995
+ return [2 /*return*/, []];
3859
3996
  products = [];
3860
- return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign({ id: { operator: exports.Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3997
+ return [4 /*yield*/, this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign({ id: { operator: exports.Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3861
3998
  'id',
3862
3999
  'name',
3863
4000
  'slug',
@@ -3881,7 +4018,7 @@
3881
4018
  'tags',
3882
4019
  'type',
3883
4020
  'shoppingCount',
3884
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
4021
+ ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }))];
3885
4022
  case 1:
3886
4023
  productsData = (_c.sent()).data;
3887
4024
  products.push.apply(products, __spreadArray([], __read(productsData)));
@@ -3899,7 +4036,7 @@
3899
4036
  case 0:
3900
4037
  if (!Number.isNaN(+id))
3901
4038
  return [2 /*return*/, id];
3902
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4039
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
3903
4040
  case 1:
3904
4041
  data = (_c.sent()).data;
3905
4042
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4219,7 +4356,7 @@
4219
4356
  switch (_f.label) {
4220
4357
  case 0:
4221
4358
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
4222
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4359
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })];
4223
4360
  case 1:
4224
4361
  _c = (_a = (_f.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4225
4362
  return [3 /*break*/, 4];
@@ -4264,21 +4401,21 @@
4264
4401
  ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug) {
4265
4402
  var _a;
4266
4403
  return __awaiter(this, void 0, void 0, function () {
4267
- var result, product, _c;
4268
- return __generator(this, function (_d) {
4269
- switch (_d.label) {
4404
+ var result, product;
4405
+ return __generator(this, function (_c) {
4406
+ switch (_c.label) {
4270
4407
  case 0: return [4 /*yield*/, this.find({
4271
4408
  filters: {
4272
4409
  slug: slug,
4273
4410
  },
4411
+ fields: this.fields.map(function (field) { return typeof field === 'string' ? field : Object.keys(field).shift(); }),
4412
+ options: {
4413
+ enableCount: false,
4414
+ },
4274
4415
  })];
4275
4416
  case 1:
4276
- result = _d.sent();
4417
+ result = _c.sent();
4277
4418
  product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4278
- _c = product;
4279
- return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4280
- case 2:
4281
- _c.reviews = _d.sent();
4282
4419
  return [2 /*return*/, product];
4283
4420
  }
4284
4421
  });
@@ -4559,7 +4696,7 @@
4559
4696
  case 0:
4560
4697
  if (!Number.isNaN(+id))
4561
4698
  return [2 /*return*/, id];
4562
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4699
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
4563
4700
  case 1:
4564
4701
  data = (_c.sent()).data;
4565
4702
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4789,7 +4926,7 @@
4789
4926
  case 0:
4790
4927
  if (!Number.isNaN(+id))
4791
4928
  return [2 /*return*/, id];
4792
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4929
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
4793
4930
  case 1:
4794
4931
  data = (_c.sent()).data;
4795
4932
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4916,6 +5053,10 @@
4916
5053
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
4917
5054
  exports.Buy2Win = Buy2Win;
4918
5055
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
5056
+ exports.CampaignDashboard = CampaignDashboard;
5057
+ exports.CampaignDashboardFirestoreRepository = CampaignDashboardFirestoreRepository;
5058
+ exports.CampaignHashtag = CampaignHashtag;
5059
+ exports.CampaignHashtagFirestoreRepository = CampaignHashtagFirestoreRepository;
4919
5060
  exports.Category = Category;
4920
5061
  exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
4921
5062
  exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;