@infrab4a/connect 5.0.0-alpha.8 → 5.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.
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { __decorate, __metadata, __rest } from 'tslib';
2
+ import { __decorate, __metadata } from 'tslib';
3
3
  import { plainToInstance, instanceToPlain, Type } from 'class-transformer';
4
4
  import { parseISO, format, startOfDay, endOfDay, subDays, addDays } from 'date-fns';
5
5
  export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub, subDays } from 'date-fns';
@@ -99,25 +99,15 @@ class PaymentProviderFactory {
99
99
  }
100
100
  }
101
101
 
102
- /**
103
- * Este arquivo define funções para resolver dependências circulares
104
- * em ambiente ESM, onde não podemos usar require()
105
- */
106
- // Armazenamento global para classes registradas
107
102
  const registry = new Map();
108
- // Registrar uma classe na resolução de dependências circulares
109
103
  function registerClass(name, classConstructor) {
110
104
  registry.set(name, classConstructor);
111
105
  }
112
- // Obter uma classe registrada
113
106
  function getClass(name) {
114
107
  return registry.get(name);
115
108
  }
116
- // Função de resolução para class-transformer
117
109
  function resolveClass(name) {
118
110
  return () => {
119
- // Forçamos o retorno de uma função que retorna a classe
120
- // ao invés da classe diretamente para evitar problemas com o decorator
121
111
  return getClass(name);
122
112
  };
123
113
  }
@@ -191,7 +181,7 @@ class ReflectHelper {
191
181
  return Reflect.getMetadata(key, target, property) || null;
192
182
  }
193
183
  }
194
- catch (_a) {
184
+ catch {
195
185
  return null;
196
186
  }
197
187
  }
@@ -501,7 +491,7 @@ function Debug(opts) {
501
491
 
502
492
  const ASYNC_IDENTIFIER = 'async';
503
493
  function Log(options = {}) {
504
- return Trace(Object.assign({ level: 'log' }, options));
494
+ return Trace({ level: 'log', ...options });
505
495
  }
506
496
  function Trace(options = {}) {
507
497
  return function (target, propertyKey, propertyDescriptor) {
@@ -601,7 +591,7 @@ class BaseModel {
601
591
  get identifier() {
602
592
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
603
593
  const data = this;
604
- return fields.reduce((object, field) => (Object.assign(Object.assign({}, object), { [field]: data[field] })), {});
594
+ return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
605
595
  }
606
596
  get identifiersFields() {
607
597
  return this.constructor.identifiersFields;
@@ -666,8 +656,7 @@ class Category extends BaseModel {
666
656
  return ['id'];
667
657
  }
668
658
  get glamImages() {
669
- var _a;
670
- return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[Shops.GLAMSHOP])
659
+ return this.images?.[Shops.GLAMSHOP]
671
660
  ? this.images[Shops.GLAMSHOP]
672
661
  : {
673
662
  brandBanner: null,
@@ -676,8 +665,7 @@ class Category extends BaseModel {
676
665
  };
677
666
  }
678
667
  get mensImages() {
679
- var _a;
680
- return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[Shops.MENSMARKET])
668
+ return this.images?.[Shops.MENSMARKET]
681
669
  ? this.images[Shops.MENSMARKET]
682
670
  : {
683
671
  brandBanner: null,
@@ -692,8 +680,7 @@ class Category extends BaseModel {
692
680
  return this.metadatas.find((metadata) => metadata.shop === Shops.MENSMARKET);
693
681
  }
694
682
  getMostRelevantByShop(shop) {
695
- var _a;
696
- return ((_a = this.mostRelevants) === null || _a === void 0 ? void 0 : _a[shop]) || [];
683
+ return this.mostRelevants?.[shop] || [];
697
684
  }
698
685
  }
699
686
  __decorate([
@@ -1426,10 +1413,18 @@ class Authentication {
1426
1413
  return signInMethod === SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
1427
1414
  }
1428
1415
  async createsUserByCredential(user) {
1429
- var _a, _b;
1430
- const [firstName, lastName] = (_b = (_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/)) !== null && _b !== void 0 ? _b : [];
1431
- const person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName,
1432
- lastName, acceptsNewsletter: false, area: Area.Transactional, officePosition: OfficePosition.Intern, type: UserType.Collaborator }));
1416
+ const [firstName, lastName] = user.displayName?.split(/\s/) ?? [];
1417
+ const person = User.toInstance({
1418
+ ...user,
1419
+ cpf: '',
1420
+ birthday: new Date(),
1421
+ firstName,
1422
+ lastName,
1423
+ acceptsNewsletter: false,
1424
+ area: Area.Transactional,
1425
+ officePosition: OfficePosition.Intern,
1426
+ type: UserType.Collaborator,
1427
+ });
1433
1428
  return this.userRepository.create(person);
1434
1429
  }
1435
1430
  }
@@ -1478,8 +1473,15 @@ class Register {
1478
1473
  password: params.password,
1479
1474
  });
1480
1475
  delete params.password;
1481
- const user = await this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email,
1482
- displayName, type: UserType.B2C, dateCreated: new Date(), dateModified: new Date() }));
1476
+ const user = await this.userRepository.create({
1477
+ ...params,
1478
+ id: auth.id,
1479
+ email,
1480
+ displayName,
1481
+ type: UserType.B2C,
1482
+ dateCreated: new Date(),
1483
+ dateModified: new Date(),
1484
+ });
1483
1485
  return user;
1484
1486
  }
1485
1487
  }
@@ -1673,8 +1675,7 @@ class AntifraudBankSlipService {
1673
1675
  this.MAX_ORDER_VALUE = 5000;
1674
1676
  }
1675
1677
  async validate(checkout) {
1676
- var _a, _b;
1677
- if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
1678
+ if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
1678
1679
  await this.orderBlockedRepository.createBlockedOrderOrPayment({
1679
1680
  checkout,
1680
1681
  blockType: 'Boleto not authorized',
@@ -1685,7 +1686,7 @@ class AntifraudBankSlipService {
1685
1686
  checkoutId: checkout.id,
1686
1687
  userEmail: checkout.user.email,
1687
1688
  info: {
1688
- isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
1689
+ isSubscriber: checkout.user?.isSubscriber,
1689
1690
  subtotal: checkout.subTotalPrice,
1690
1691
  total: checkout.totalPrice,
1691
1692
  },
@@ -1709,14 +1710,13 @@ class AntifraudCardService {
1709
1710
  return true;
1710
1711
  }
1711
1712
  async validateBlockedOrderAttempts(checkout, card) {
1712
- var _a;
1713
1713
  const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
1714
1714
  if (!isValid) {
1715
1715
  throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
1716
1716
  checkoutId: checkout.id,
1717
1717
  userEmail: checkout.user.email,
1718
1718
  info: {
1719
- isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
1719
+ isSubscriber: checkout.user?.isSubscriber,
1720
1720
  subtotal: checkout.subTotalPrice,
1721
1721
  total: checkout.totalPrice,
1722
1722
  },
@@ -1724,14 +1724,13 @@ class AntifraudCardService {
1724
1724
  }
1725
1725
  }
1726
1726
  async validateDayAndWeekOrderLimits(checkout, card) {
1727
- var _a;
1728
1727
  const isValid = await this.verifyDayAndWeekOrders(checkout, card);
1729
1728
  if (!isValid) {
1730
1729
  throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
1731
1730
  checkoutId: checkout.id,
1732
1731
  userEmail: checkout.user.email,
1733
1732
  info: {
1734
- isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
1733
+ isSubscriber: checkout.user?.isSubscriber,
1735
1734
  subtotal: checkout.subTotalPrice,
1736
1735
  total: checkout.totalPrice,
1737
1736
  },
@@ -1760,17 +1759,16 @@ class AntifraudCardService {
1760
1759
  return { day, endOfDay };
1761
1760
  }
1762
1761
  async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
1763
- var _a, _b, _c, _d;
1764
1762
  const { day, endOfDay } = dateRange;
1765
1763
  const dateFilter = [
1766
1764
  { operator: Where.GTE, value: new Date(day) },
1767
1765
  { operator: Where.LTE, value: new Date(endOfDay) },
1768
1766
  ];
1769
1767
  const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
1770
- this.getBlockedOrdersByCpf((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf, dateFilter),
1771
- this.getBlockedOrdersByEmail((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email, dateFilter),
1772
- this.getBlockedOrdersByZip((_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip, dateFilter),
1773
- this.getBlockedOrdersByPhone((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone, dateFilter),
1768
+ this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
1769
+ this.getBlockedOrdersByEmail(checkout.user?.email, dateFilter),
1770
+ this.getBlockedOrdersByZip(checkout.shippingAddress?.zip, dateFilter),
1771
+ this.getBlockedOrdersByPhone(checkout.user?.phone, dateFilter),
1774
1772
  ]);
1775
1773
  return {
1776
1774
  ordersBlockedWithCpf,
@@ -1827,18 +1825,15 @@ class AntifraudCardService {
1827
1825
  return ordersBlockedWithCpf.concat(blockedUniqueEmails).concat(blockedUniqueCeps).concat(blockedUniquePhone).length;
1828
1826
  }
1829
1827
  filterUniqueEmailBlocked(ordersBlockedWithEmail, checkout) {
1830
- return ordersBlockedWithEmail.filter((e) => { var _a; return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf); });
1828
+ return ordersBlockedWithEmail.filter((e) => e.customer.cpf !== checkout.user?.cpf);
1831
1829
  }
1832
1830
  filterUniqueZipBlocked(ordersBlockedWithCep, checkout) {
1833
- return ordersBlockedWithCep.filter((e) => { var _a, _b; return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) && e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email); });
1831
+ return ordersBlockedWithCep.filter((e) => e.customer.cpf !== checkout.user?.cpf && e.customer.email !== checkout.user?.email);
1834
1832
  }
1835
1833
  filterUniquePhoneBlocked(ordersBlockedWithPhone, checkout) {
1836
- return ordersBlockedWithPhone.filter((e) => {
1837
- var _a, _b, _c, _d, _e, _f;
1838
- return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
1839
- e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
1840
- ((_d = (_c = e.customer.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip) === null || _d === void 0 ? void 0 : _d.toString()) !== ((_f = (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.zip) === null || _f === void 0 ? void 0 : _f.toString());
1841
- });
1834
+ return ordersBlockedWithPhone.filter((e) => e.customer.cpf !== checkout.user?.cpf &&
1835
+ e.customer.email !== checkout.user?.email &&
1836
+ e.customer.shippingAddress?.zip?.toString() !== checkout.shippingAddress?.zip?.toString());
1842
1837
  }
1843
1838
  async createBlockedOrderRecord(params) {
1844
1839
  const { checkout, card, reason, key, period } = params;
@@ -1859,12 +1854,11 @@ class AntifraudCardService {
1859
1854
  return isWeekLimitValid;
1860
1855
  }
1861
1856
  buildValidationParams(checkout, card) {
1862
- var _a, _b, _c, _d;
1863
1857
  return {
1864
- cpf: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf,
1865
- email: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email,
1866
- phone: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.phone,
1867
- zip: (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.zip,
1858
+ cpf: checkout.user?.cpf,
1859
+ email: checkout.user?.email,
1860
+ phone: checkout.user?.phone,
1861
+ zip: checkout.shippingAddress?.zip,
1868
1862
  card,
1869
1863
  };
1870
1864
  }
@@ -1889,7 +1883,7 @@ class AntifraudCardService {
1889
1883
  async checkOrderLimitsAndBlock(params) {
1890
1884
  const { checkout, orderCounts, limit, period } = params;
1891
1885
  for (const key in orderCounts) {
1892
- if (orderCounts[key] > limit) {
1886
+ if (orderCounts[key] >= limit) {
1893
1887
  await this.createBlockedOrderRecord({
1894
1888
  checkout,
1895
1889
  card: null,
@@ -1903,18 +1897,20 @@ class AntifraudCardService {
1903
1897
  return true;
1904
1898
  }
1905
1899
  async validateOrdersByRange(params, range) {
1906
- const { cpf, email, phone, zip } = params;
1907
- const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip] = await Promise.all([
1900
+ const { cpf, email, phone, zip, card } = params;
1901
+ const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip, ordersByCard] = await Promise.all([
1908
1902
  this.countOrdersByField({ property: 'user', field: 'cpf', value: cpf, range }),
1909
1903
  this.countOrdersByField({ property: 'user', field: 'email', value: email, range }),
1910
1904
  this.countOrdersByField({ property: 'user', field: 'phone', value: phone, range }),
1911
1905
  this.countOrdersByField({ property: 'shippingAddress', field: 'zip', value: zip, range }),
1906
+ this.countOrdersByField({ property: 'payment', field: 'card.id', value: card.cardId, range }),
1912
1907
  ]);
1913
1908
  return {
1914
1909
  cpf: ordersCpf,
1915
1910
  email: ordersByEmail,
1916
1911
  phone: ordersByPhone,
1917
1912
  zip: ordersByZip,
1913
+ card: ordersByCard,
1918
1914
  };
1919
1915
  }
1920
1916
  async countOrdersByField(params) {
@@ -1928,8 +1924,8 @@ class AntifraudCardService {
1928
1924
  { operator: Where.LTE, value: range.lastDate },
1929
1925
  ],
1930
1926
  };
1931
- const docs = await (await this.orderRepository.find({ filters })).count;
1932
- return docs;
1927
+ const { count } = await this.orderRepository.find({ filters });
1928
+ return count;
1933
1929
  }
1934
1930
  getDateRange(range = 'day') {
1935
1931
  switch (range) {
@@ -2000,10 +1996,9 @@ class GlampointsPaymentService {
2000
1996
  return payment;
2001
1997
  }
2002
1998
  async rewardByOrder(order, user) {
2003
- var _a;
2004
1999
  try {
2005
2000
  const points = order.lineItems.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
2006
- const hasGlambeauty = (_a = order.lineItems) === null || _a === void 0 ? void 0 : _a.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
2001
+ const hasGlambeauty = order.lineItems?.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
2007
2002
  const result = await axios({
2008
2003
  method: 'POST',
2009
2004
  url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
@@ -2264,7 +2259,7 @@ class AdyenPaymentFactoryHelper {
2264
2259
  checkoutId: checkout.id,
2265
2260
  totalPrice: checkout.totalPrice,
2266
2261
  paymentProvider: 'adyen',
2267
- transaction: Object.assign(Object.assign({}, adyenResponse), { status: 'paid' }),
2262
+ transaction: { ...adyenResponse, status: 'paid' },
2268
2263
  });
2269
2264
  return paymentRepository.create(paymentData);
2270
2265
  }
@@ -2275,7 +2270,7 @@ class AdyenPaymentOperationsHelper {
2275
2270
  return {
2276
2271
  amount: {
2277
2272
  currency: 'BRL',
2278
- value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2273
+ value: (checkout?.totalPrice || 0) * 100,
2279
2274
  },
2280
2275
  paymentMethod: {
2281
2276
  type: 'scheme',
@@ -2360,7 +2355,11 @@ class RestCacheAdapter {
2360
2355
  this.logger = new DebugHelper('RestCacheAdapter');
2361
2356
  this.client = axios.create({
2362
2357
  baseURL: config.baseURL,
2363
- headers: Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` })), (isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey })),
2358
+ headers: {
2359
+ 'Content-Type': 'application/json',
2360
+ ...(isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
2361
+ ...(isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey }),
2362
+ },
2364
2363
  });
2365
2364
  }
2366
2365
  async set(options) {
@@ -2616,7 +2615,10 @@ class ElasticSearchResultProcessorHelper {
2616
2615
  });
2617
2616
  }
2618
2617
  static transformHitsToProducts(hits) {
2619
- return hits.map((hit) => (Object.assign(Object.assign({}, hit._source), { stock: hit._source.stock.quantity })));
2618
+ return hits.map((hit) => ({
2619
+ ...hit._source,
2620
+ stock: hit._source.stock.quantity,
2621
+ }));
2620
2622
  }
2621
2623
  }
2622
2624
 
@@ -2759,11 +2761,11 @@ class FirestoreDataConverterHelper {
2759
2761
  return (data &&
2760
2762
  !Array.isArray(data) &&
2761
2763
  typeof data === 'object' &&
2762
- (data === null || data === void 0 ? void 0 : data.constructor.name) !== 'Timestamp' &&
2764
+ data?.constructor.name !== 'Timestamp' &&
2763
2765
  !('seconds' in data));
2764
2766
  }
2765
2767
  static convertToDate(data, keyName) {
2766
- if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'Timestamp')
2768
+ if (data?.constructor.name === 'Timestamp')
2767
2769
  return data.toDate();
2768
2770
  if (data && typeof data === 'object' && 'seconds' in data)
2769
2771
  return new Date(data.seconds * 1000);
@@ -2808,7 +2810,7 @@ class FirestoreModelConverterHelper {
2808
2810
  }
2809
2811
  buildToFirestoreConverter() {
2810
2812
  return (data) => {
2811
- const plain = (data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data;
2813
+ const plain = data?.toPlain ? data.toPlain() : data;
2812
2814
  return FirestoreModelConverterHelper.omitByRecursivelyInPlace(plain, (value) => value === undefined);
2813
2815
  };
2814
2816
  }
@@ -2818,7 +2820,7 @@ class FirestoreModelConverterHelper {
2818
2820
  const data = snap.data();
2819
2821
  const ids = { id: snap.id };
2820
2822
  const bindedData = FirestoreDataConverterHelper.bindAllDateFromObject(data);
2821
- return this.model.toInstance(Object.assign(Object.assign({}, bindedData), ids));
2823
+ return this.model.toInstance({ ...bindedData, ...ids });
2822
2824
  }
2823
2825
  catch (error) {
2824
2826
  this.handleConversionError(snap.id, snap.data(), error);
@@ -2886,18 +2888,17 @@ const withHelpers = (MixinBase) => {
2886
2888
  class AttributeOptionHelper {
2887
2889
  }
2888
2890
  AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
2889
- var _a;
2890
2891
  if (fields.includes(attributeName))
2891
2892
  return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
2892
2893
  const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
2893
- const fieldOption = (_a = is(field)) === null || _a === void 0 ? void 0 : _a[attributeName];
2894
+ const fieldOption = is(field)?.[attributeName];
2894
2895
  if (isNil(fieldOption))
2895
2896
  return { columnName: attributeName.toString(), attributeName };
2896
2897
  if (Array.isArray(fieldOption))
2897
2898
  return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
2898
- return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
2899
+ return { attributeName, columnName: attributeName.toString(), ...fieldOption };
2899
2900
  };
2900
- AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.columnName);
2901
+ AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
2901
2902
  AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
2902
2903
  if (fields.includes(columnName))
2903
2904
  return { columnName, attributeName: columnName };
@@ -2905,13 +2906,17 @@ AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
2905
2906
  if (!isObject(field))
2906
2907
  return false;
2907
2908
  const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
2908
- return AttributeOptionHelper.CheckIsColumnOption(columnOption) && (columnOption === null || columnOption === void 0 ? void 0 : columnOption.columnName) === columnName;
2909
+ return AttributeOptionHelper.CheckIsColumnOption(columnOption) && columnOption?.columnName === columnName;
2909
2910
  }) || {});
2910
2911
  const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
2911
- const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
2912
+ const fieldOption = field?.[attributeName];
2912
2913
  if (Array.isArray(fieldOption))
2913
2914
  return { attributeName: attributeName, fields: fieldOption };
2914
- return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
2915
+ return {
2916
+ attributeName: attributeName || columnName,
2917
+ columnName,
2918
+ ...fieldOption,
2919
+ };
2915
2920
  };
2916
2921
 
2917
2922
  var HasuraGraphQLWhere;
@@ -2949,7 +2954,7 @@ var HasuraGraphQLColumnType;
2949
2954
 
2950
2955
  class FilterOptionHelper {
2951
2956
  }
2952
- FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
2957
+ FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter?.operator);
2953
2958
  FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
2954
2959
  if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
2955
2960
  return filter;
@@ -3010,25 +3015,37 @@ class BindFilterQueryHelper {
3010
3015
  BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
3011
3016
  const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
3012
3017
  if (!columnOption.bindFindFilter)
3013
- return Object.assign(Object.assign({}, variables), {
3014
- [columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
3015
- });
3018
+ return {
3019
+ ...variables,
3020
+ ...{
3021
+ [columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
3022
+ },
3023
+ };
3016
3024
  const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
3017
- return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce((variablesList, columnName) => (Object.assign(Object.assign({}, variablesList), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields) })), {}));
3025
+ return {
3026
+ ...variables,
3027
+ ...Object.keys(builtFilter).reduce((variablesList, columnName) => ({
3028
+ ...variablesList,
3029
+ [columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields),
3030
+ }), {}),
3031
+ };
3018
3032
  }, {});
3019
3033
  BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
3020
3034
  const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
3021
3035
  const isNestedField = !Array.isArray(options) &&
3022
3036
  isObject(options) &&
3023
- isNil(options === null || options === void 0 ? void 0 : options.operator) &&
3024
- isNil(options === null || options === void 0 ? void 0 : options.value) &&
3025
- isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to);
3037
+ isNil(options?.operator) &&
3038
+ isNil(options?.value) &&
3039
+ isNil(fieldSentenceOptions?.to);
3026
3040
  if (isNestedField)
3027
3041
  return Object.keys(options).reduce((variables, key) => {
3028
- const fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
3042
+ const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
3029
3043
  const columnName = fieldOptions.columnName;
3030
3044
  const columnFields = fieldOptions.fields;
3031
- return Object.assign(Object.assign({}, variables), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || columnFields || fields) });
3045
+ return {
3046
+ ...variables,
3047
+ [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
3048
+ };
3032
3049
  }, {});
3033
3050
  if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
3034
3051
  return {
@@ -3037,7 +3054,10 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
3037
3054
  if (!Array.isArray(options) && isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
3038
3055
  options = Object.values(options)[0];
3039
3056
  return Array.isArray(options)
3040
- ? options.reduce((whereSentence, option) => (Object.assign(Object.assign({}, whereSentence), BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions))), {})
3057
+ ? options.reduce((whereSentence, option) => ({
3058
+ ...whereSentence,
3059
+ ...BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions),
3060
+ }), {})
3041
3061
  : BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
3042
3062
  };
3043
3063
  BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
@@ -3053,14 +3073,14 @@ BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOption
3053
3073
  : options.operator === Where.LIKE && options.ignoreCase
3054
3074
  ? HasuraGraphQLWhere.ILIKE
3055
3075
  : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
3056
- Object.keys(Where).find((operator) => Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))]
3076
+ Object.keys(Where).find((operator) => Where[operator] === options?.operator))]
3057
3077
  : HasuraGraphQLWhere.EQUALS;
3058
3078
  BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === Where.IN
3059
3079
  ? HasuraGraphQLWhere.JSON_CONTAINS
3060
3080
  : options.operator === Where.LIKE
3061
3081
  ? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
3062
3082
  : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
3063
- Object.keys(Where).find((operator) => Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))];
3083
+ Object.keys(Where).find((operator) => Where[operator] === options?.operator))];
3064
3084
 
3065
3085
  class CacheKeyGeneratorHelper {
3066
3086
  static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
@@ -3075,7 +3095,8 @@ class GraphQLFieldHelper {
3075
3095
  }
3076
3096
  GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
3077
3097
  GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
3078
- return fields === null || fields === void 0 ? void 0 : fields.map((field) => {
3098
+ return fields
3099
+ ?.map((field) => {
3079
3100
  if (isString(field))
3080
3101
  return field.toString();
3081
3102
  if (field === 'affected_rows')
@@ -3090,41 +3111,55 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
3090
3111
  if (isNestedField)
3091
3112
  return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
3092
3113
  return fieldValue.columnName;
3093
- }).filter((field) => !!field);
3114
+ })
3115
+ .filter((field) => !!field);
3094
3116
  };
3095
3117
  GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
3096
3118
  const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
3097
3119
  if (!!attributeFields && Array.isArray(attributeFields)) {
3098
3120
  if (Array.isArray(data[columnName]))
3099
- return Object.assign(Object.assign({}, result), { [attributeName]: from
3121
+ return {
3122
+ ...result,
3123
+ [attributeName]: from
3100
3124
  ? from(data[columnName], data)
3101
- : is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)) });
3125
+ : is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)),
3126
+ };
3102
3127
  if (isObject(data[columnName]))
3103
- return Object.assign(Object.assign({}, result), { [attributeName]: from
3128
+ return {
3129
+ ...result,
3130
+ [attributeName]: from
3104
3131
  ? from(data[columnName])
3105
- : GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields) });
3132
+ : GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields),
3133
+ };
3106
3134
  }
3107
3135
  if (from)
3108
- return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
3109
- return Object.assign(Object.assign({}, result), { [attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName] });
3136
+ return { ...result, [attributeName]: from(data[columnName], data) };
3137
+ return {
3138
+ ...result,
3139
+ [attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
3140
+ };
3110
3141
  }, {});
3111
3142
  GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
3112
- var _a;
3113
- const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
3143
+ const data = instance.toPlain?.() || instance;
3114
3144
  return Object.keys(data).reduce((result, attributeName) => {
3115
3145
  const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
3116
3146
  if (bindPersistData)
3117
- return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
3147
+ return {
3148
+ ...result,
3149
+ ...bindPersistData(data[attributeName], instance),
3150
+ };
3118
3151
  if (isNil(columnName))
3119
3152
  return result;
3120
3153
  if (!!foreignKeyColumn &&
3121
3154
  !isEmpty(foreignKeyColumn) &&
3122
- !Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = is(data[attributeName])) === null || _a === void 0 ? void 0 : _a[key]); }).length)
3155
+ !Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
3123
3156
  return Object.keys(foreignKeyColumn).reduce((object, current) => {
3124
- var _a;
3125
3157
  const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
3126
- return Object.assign(Object.assign({}, object), { [foreignColumnName]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] });
3127
- }, Object.assign({}, result));
3158
+ return {
3159
+ ...object,
3160
+ [foreignColumnName]: data[attributeName]?.[current],
3161
+ };
3162
+ }, { ...result });
3128
3163
  if (update &&
3129
3164
  isObject(data[attributeName]) &&
3130
3165
  !isNil(attributeFields) &&
@@ -3136,19 +3171,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
3136
3171
  const converted = !isNil(columnName) && to
3137
3172
  ? to(instance[attributeName], instance)
3138
3173
  : data[attributeName];
3139
- return Object.assign(Object.assign({}, result), (converted !== undefined
3140
- ? {
3141
- [columnName]: {
3142
- data: instance[attributeName] instanceof BaseModel
3143
- ? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
3144
- : converted,
3145
- },
3146
- }
3147
- : {}));
3174
+ return {
3175
+ ...result,
3176
+ ...(converted !== undefined
3177
+ ? {
3178
+ [columnName]: {
3179
+ data: instance[attributeName] instanceof BaseModel
3180
+ ? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
3181
+ : converted,
3182
+ },
3183
+ }
3184
+ : {}),
3185
+ };
3148
3186
  }
3149
3187
  if (to)
3150
- return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
3151
- return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
3188
+ return {
3189
+ ...result,
3190
+ [columnName]: to(instance[attributeName], instance),
3191
+ };
3192
+ return { ...result, [columnName]: data[attributeName] };
3152
3193
  }, {});
3153
3194
  };
3154
3195
  GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
@@ -3206,13 +3247,17 @@ class MD5GeneratorHelper {
3206
3247
 
3207
3248
  class HasuraAuthHelper {
3208
3249
  static buildHeaders(authOptions) {
3209
- var _a;
3210
- return Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (isNil(authOptions === null || authOptions === void 0 ? void 0 : authOptions.authToken) ? {} : { Authorization: authOptions === null || authOptions === void 0 ? void 0 : authOptions.authToken })), (isNil(authOptions === null || authOptions === void 0 ? void 0 : authOptions.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions === null || authOptions === void 0 ? void 0 : authOptions.adminSecret })), (isNil(authOptions === null || authOptions === void 0 ? void 0 : authOptions.authRole)
3211
- ? {}
3212
- : {
3213
- 'X-Hasura-Role': authOptions.authRole.role,
3214
- 'X-Hasura-User-Id': (_a = authOptions === null || authOptions === void 0 ? void 0 : authOptions.authRole) === null || _a === void 0 ? void 0 : _a.userId,
3215
- }));
3250
+ return {
3251
+ 'Content-Type': 'application/json',
3252
+ ...(isNil(authOptions?.authToken) ? {} : { Authorization: authOptions?.authToken }),
3253
+ ...(isNil(authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions?.adminSecret }),
3254
+ ...(isNil(authOptions?.authRole)
3255
+ ? {}
3256
+ : {
3257
+ 'X-Hasura-Role': authOptions.authRole.role,
3258
+ 'X-Hasura-User-Id': authOptions?.authRole?.userId,
3259
+ }),
3260
+ };
3216
3261
  }
3217
3262
  }
3218
3263
 
@@ -3302,17 +3347,21 @@ class HasuraGraphQLOperationsHelper {
3302
3347
  return this.executeFetch({ query: resultQuery, operationParams });
3303
3348
  }
3304
3349
  static async executeQuery(params) {
3305
- var _a, _b, _c, _d;
3306
3350
  const { operation, fields, variables, operationParams, buildHasuraQueryFields } = params;
3307
3351
  const builded = buildHasuraQueryFields({ operation, fields, variables });
3308
- const intercepted = (await ((_b = (_a = operationParams.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, builded))) || builded;
3352
+ const intercepted = (await operationParams.interceptors?.request?.(builded)) || builded;
3309
3353
  const resultQuery = HasuraQueryBuilderHelper.buildQuery(intercepted);
3310
3354
  const result = await this.executeFetch({ query: resultQuery, operationParams });
3311
- return (await ((_d = (_c = operationParams.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, result, intercepted))) || result;
3355
+ return (await operationParams.interceptors?.response?.(result, intercepted)) || result;
3312
3356
  }
3313
3357
  static async executeFetch(params) {
3314
3358
  const { query, operationParams } = params;
3315
- return HasuraRequestHelper.fetch(Object.assign(Object.assign({}, query), { endpoint: operationParams.endpoint, headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions), logger: operationParams.logger }));
3359
+ return HasuraRequestHelper.fetch({
3360
+ ...query,
3361
+ endpoint: operationParams.endpoint,
3362
+ headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions),
3363
+ logger: operationParams.logger,
3364
+ });
3316
3365
  }
3317
3366
  }
3318
3367
 
@@ -3326,12 +3375,10 @@ class HasuraColumnHelper {
3326
3375
  const columnOptions = Object.values(field).shift();
3327
3376
  return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
3328
3377
  columnOptions.foreignKeyColumn && [
3329
- ...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => { var _a; return (_a = AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)) === null || _a === void 0 ? void 0 : _a.columnName; }),
3378
+ ...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)?.columnName),
3330
3379
  {
3331
- [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => {
3332
- var _a;
3333
- return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || foreignKeyField;
3334
- }),
3380
+ [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
3381
+ ?.columnName || foreignKeyField),
3335
3382
  },
3336
3383
  ]);
3337
3384
  })
@@ -3356,7 +3403,7 @@ class HasuraCreateOperationsHelper {
3356
3403
  const { model } = params;
3357
3404
  params.repository.logger = DebugHelper.from(params.repository, 'create');
3358
3405
  const instance = model.toInstance(data);
3359
- const newData = await this.executeSave(Object.assign(Object.assign({}, params), { data: instance }));
3406
+ const newData = await this.executeSave({ ...params, data: instance });
3360
3407
  return model.toInstance(newData);
3361
3408
  }
3362
3409
  static async executeSave(params) {
@@ -3370,14 +3417,14 @@ class HasuraCreateOperationsHelper {
3370
3417
  },
3371
3418
  });
3372
3419
  const convertedResult = repository.convertDataFromHasura(result[insertGraphQLOperation]);
3373
- return Object.assign(Object.assign({}, data.toPlain()), convertedResult.toPlain());
3420
+ return { ...data.toPlain(), ...convertedResult.toPlain() };
3374
3421
  }
3375
3422
  }
3376
3423
 
3377
3424
  class HasuraCacheOperationsHelper {
3378
3425
  static async removeCacheData(cache, params) {
3379
3426
  const { model, identifiers, logger } = params;
3380
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
3427
+ if (!cache?.cacheAdapter)
3381
3428
  return;
3382
3429
  const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
3383
3430
  await cache.cacheAdapter.remove(cacheKey);
@@ -3397,13 +3444,16 @@ class HasuraDeleteVariablesHelper {
3397
3444
  if (isNil(instance.identifier[identifierBinded]))
3398
3445
  return ids;
3399
3446
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3400
- const value = (columnOption === null || columnOption === void 0 ? void 0 : columnOption.to(identifiers[identifier], instance)) ||
3447
+ const value = columnOption?.to(identifiers[identifier], instance) ||
3401
3448
  identifiers[identifier];
3402
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
3449
+ return {
3450
+ ...ids,
3451
+ [columnOption.columnName]: {
3403
3452
  type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
3404
3453
  value,
3405
3454
  required: true,
3406
- } });
3455
+ },
3456
+ };
3407
3457
  }, {});
3408
3458
  }
3409
3459
  }
@@ -3441,16 +3491,15 @@ class HasuraFindBindingHelper {
3441
3491
  ], []);
3442
3492
  }
3443
3493
  static bindAggregateAttributes(aggregates, fields) {
3444
- var _a, _b;
3445
3494
  return [
3446
- ...(((_a = aggregates === null || aggregates === void 0 ? void 0 : aggregates.minimal) === null || _a === void 0 ? void 0 : _a.length)
3495
+ ...(aggregates?.minimal?.length
3447
3496
  ? [
3448
3497
  {
3449
3498
  min: this.bindAttributesToColumns(aggregates.minimal, fields),
3450
3499
  },
3451
3500
  ]
3452
3501
  : []),
3453
- ...(((_b = aggregates === null || aggregates === void 0 ? void 0 : aggregates.maximum) === null || _b === void 0 ? void 0 : _b.length)
3502
+ ...(aggregates?.maximum?.length
3454
3503
  ? [
3455
3504
  {
3456
3505
  max: this.bindAttributesToColumns(aggregates.maximum, fields),
@@ -3477,7 +3526,7 @@ class HasuraFindBindingHelper {
3477
3526
  });
3478
3527
  if (typeof fieldOption === 'object' && fieldOption !== null) {
3479
3528
  const columnOption = fieldOption[attributeName];
3480
- return (columnOption === null || columnOption === void 0 ? void 0 : columnOption.columnName) || attributeName;
3529
+ return columnOption?.columnName || attributeName;
3481
3530
  }
3482
3531
  return attributeName;
3483
3532
  }
@@ -3490,27 +3539,27 @@ class HasuraFindCacheHelper {
3490
3539
  }
3491
3540
  static async getCachedResult(params) {
3492
3541
  const { cache, model, findParams, cacheOptions, logger } = params;
3493
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || !(cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.enabled))
3542
+ if (!cache?.cacheAdapter || !cacheOptions?.enabled)
3494
3543
  return null;
3495
3544
  const cacheKey = this.generateCacheKey(model, findParams);
3496
3545
  const cachedData = await cache.cacheAdapter.get(cacheKey);
3497
3546
  if (cachedData) {
3498
- logger === null || logger === void 0 ? void 0 : logger.log(`Dados recuperados do cache: ${cacheKey}`);
3547
+ logger?.log(`Dados recuperados do cache: ${cacheKey}`);
3499
3548
  return deserialize(cachedData);
3500
3549
  }
3501
3550
  return null;
3502
3551
  }
3503
3552
  static async setCachedResult(params) {
3504
3553
  const { cache, model, findParams, cacheOptions, result, logger } = params;
3505
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || !(cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.enabled))
3554
+ if (!cache?.cacheAdapter || !cacheOptions?.enabled)
3506
3555
  return;
3507
3556
  const cacheKey = this.generateCacheKey(model, findParams);
3508
3557
  await cache.cacheAdapter.set({
3509
3558
  key: cacheKey,
3510
3559
  data: serialize(result),
3511
- expirationInSeconds: (cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.ttl) || cache.ttlDefault,
3560
+ expirationInSeconds: cacheOptions?.ttl || cache.ttlDefault,
3512
3561
  });
3513
- logger === null || logger === void 0 ? void 0 : logger.log(`Dados salvos no cache: ${cacheKey}`);
3562
+ logger?.log(`Dados salvos no cache: ${cacheKey}`);
3514
3563
  }
3515
3564
  }
3516
3565
 
@@ -3518,26 +3567,40 @@ class HasuraFindResultHelper {
3518
3567
  static processResult(params) {
3519
3568
  const { result, tableName, enableCount, findOptions, tableFiltersNamed, fields, convertDataFromHasura, lastDistinct, } = params;
3520
3569
  const data = result[tableName].map((row) => convertDataFromHasura(row));
3521
- const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity }, this.processMinimalAggregates({ result, tableName, findOptions, fields })), this.processMaximumAggregates({ result, tableName, findOptions, fields })), this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }));
3570
+ const findResult = {
3571
+ data,
3572
+ count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity,
3573
+ ...this.processMinimalAggregates({ result, tableName, findOptions, fields }),
3574
+ ...this.processMaximumAggregates({ result, tableName, findOptions, fields }),
3575
+ ...this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }),
3576
+ };
3522
3577
  return findResult;
3523
3578
  }
3524
3579
  static bindAggregateAttributes(params) {
3525
- var _a, _b;
3526
3580
  const { aggregates, fields } = params;
3527
3581
  const convertFieldName = (fieldName) => {
3528
- var _a, _b;
3529
- const fieldOption = (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
3530
- return fieldOption ? ((_b = Object.values(fieldOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || fieldName : fieldName;
3582
+ const finalFieldName = fieldName.toString().split('.').pop();
3583
+ const fieldOption = fields.find((fieldOption) => {
3584
+ if (typeof fieldOption === 'string')
3585
+ return fieldOption === finalFieldName;
3586
+ const key = Object.keys(fieldOption)[0];
3587
+ return key === finalFieldName;
3588
+ });
3589
+ if (fieldOption && typeof fieldOption !== 'string') {
3590
+ const fieldValue = Object.values(fieldOption)[0];
3591
+ return fieldValue?.columnName || finalFieldName;
3592
+ }
3593
+ return finalFieldName;
3531
3594
  };
3532
3595
  return [
3533
- ...(((_a = aggregates === null || aggregates === void 0 ? void 0 : aggregates.minimal) === null || _a === void 0 ? void 0 : _a.length)
3596
+ ...(aggregates?.minimal?.length
3534
3597
  ? [
3535
3598
  {
3536
3599
  min: aggregates.minimal.map(convertFieldName),
3537
3600
  },
3538
3601
  ]
3539
3602
  : []),
3540
- ...(((_b = aggregates === null || aggregates === void 0 ? void 0 : aggregates.maximum) === null || _b === void 0 ? void 0 : _b.length)
3603
+ ...(aggregates?.maximum?.length
3541
3604
  ? [
3542
3605
  {
3543
3606
  max: aggregates.maximum.map(convertFieldName),
@@ -3547,48 +3610,52 @@ class HasuraFindResultHelper {
3547
3610
  ];
3548
3611
  }
3549
3612
  static processMinimalAggregates(params) {
3550
- var _a;
3551
3613
  const { result, tableName, findOptions, fields } = params;
3552
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
3614
+ return findOptions?.minimal?.length
3553
3615
  ? {
3554
3616
  minimal: findOptions.minimal.reduce((minimals, current) => {
3555
- var _a;
3556
- return (Object.assign(Object.assign({}, minimals), set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
3617
+ const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
3618
+ return {
3619
+ ...minimals,
3620
+ ...set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[columnName]),
3621
+ };
3557
3622
  }, {}),
3558
3623
  }
3559
3624
  : {};
3560
3625
  }
3561
3626
  static processMaximumAggregates(params) {
3562
- var _a;
3563
3627
  const { result, tableName, findOptions, fields } = params;
3564
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _a === void 0 ? void 0 : _a.length)
3628
+ return findOptions?.maximum?.length
3565
3629
  ? {
3566
3630
  maximum: findOptions.maximum.reduce((maximums, current) => {
3567
- var _a;
3568
- return (Object.assign(Object.assign({}, maximums), set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
3631
+ const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
3632
+ return {
3633
+ ...maximums,
3634
+ ...set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[columnName]),
3635
+ };
3569
3636
  }, {}),
3570
3637
  }
3571
3638
  : {};
3572
3639
  }
3573
3640
  static processDistinctResults(params) {
3574
- var _a, _b;
3575
3641
  const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
3576
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _a === void 0 ? void 0 : _a.length)
3642
+ return findOptions?.distinct?.length
3577
3643
  ? {
3578
- distinct: (_b = lastDistinct[tableFiltersNamed]) !== null && _b !== void 0 ? _b : (lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
3579
- var _a, _b;
3580
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3581
- const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
3582
- return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
3583
- }, {})),
3644
+ distinct: lastDistinct[tableFiltersNamed] ??
3645
+ (lastDistinct[tableFiltersNamed] = findOptions?.distinct.reduce((distinct, current) => {
3646
+ const distinctOption = fields.find((fieldOption) => fieldOption === current) ??
3647
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3648
+ const fieldName = Object.values(distinctOption).shift()?.columnName || current;
3649
+ return {
3650
+ ...distinct,
3651
+ [current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
3652
+ };
3653
+ }, {})),
3584
3654
  }
3585
3655
  : {};
3586
3656
  }
3587
3657
  static bindAttributesToColumns(attributes, fields) {
3588
- return attributes.map((attr) => {
3589
- var _a;
3590
- return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
3591
- });
3658
+ return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
3592
3659
  }
3593
3660
  }
3594
3661
 
@@ -3618,16 +3685,19 @@ class HasuraFindVariablesHelper {
3618
3685
  };
3619
3686
  }
3620
3687
  static buildDistinctVariables(params) {
3621
- var _a, _b;
3622
3688
  const { distinct, tableName, fields, filtersVariables } = params;
3623
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3624
- const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
3625
- return Object.assign(Object.assign({}, filtersVariables), { [`${tableName}_${fieldName}_distinct`]: {
3689
+ const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
3690
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3691
+ const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
3692
+ return {
3693
+ ...filtersVariables,
3694
+ [`${tableName}_${fieldName}_distinct`]: {
3626
3695
  type: `${tableName}_select_column!`,
3627
3696
  list: true,
3628
3697
  value: fieldName,
3629
3698
  name: 'distinct_on',
3630
- } });
3699
+ },
3700
+ };
3631
3701
  }
3632
3702
  static bindOrderByAttributes(orderBy, fields) {
3633
3703
  return Object.keys(orderBy).reduce((acc, current) => [
@@ -3647,11 +3717,17 @@ class HasuraFindQueryBuilderHelper {
3647
3717
  const { tableName, fields, params, lastDistinct } = queryParams;
3648
3718
  const { filters, limits, orderBy, options: findOptions } = params || {};
3649
3719
  const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
3650
- const countVariables = Object.assign(Object.assign({}, HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields })), filtersVariables);
3651
- const mainVariables = Object.assign(Object.assign({}, (isNil(limits) ? {} : limits)), countVariables);
3720
+ const countVariables = {
3721
+ ...HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields }),
3722
+ ...filtersVariables,
3723
+ };
3724
+ const mainVariables = {
3725
+ ...(isNil(limits) ? {} : limits),
3726
+ ...countVariables,
3727
+ };
3652
3728
  const queries = [
3653
3729
  this.buildMainQuery({ tableName, fields, params, mainVariables }),
3654
- ...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
3730
+ ...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
3655
3731
  ...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
3656
3732
  ];
3657
3733
  return queries.filter(Boolean);
@@ -3660,26 +3736,23 @@ class HasuraFindQueryBuilderHelper {
3660
3736
  const { tableName, fields, params: findParams, mainVariables } = params;
3661
3737
  return {
3662
3738
  operation: tableName,
3663
- fields: (findParams === null || findParams === void 0 ? void 0 : findParams.fields)
3739
+ fields: findParams?.fields
3664
3740
  ? findParams.fields
3665
- .map((fieldName) => {
3666
- var _a;
3667
- return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
3668
- })
3741
+ .map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
3742
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
3669
3743
  .filter(Boolean)
3670
3744
  : fields,
3671
3745
  variables: mainVariables,
3672
3746
  };
3673
3747
  }
3674
3748
  static buildAggregateQuery(params) {
3675
- var _a;
3676
3749
  const { tableName, findOptions, countVariables } = params;
3677
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
3750
+ const enableCount = findOptions?.enableCount ?? true;
3678
3751
  const aggregateFields = [
3679
3752
  ...(enableCount ? ['count'] : []),
3680
3753
  ...HasuraFindResultHelper.bindAggregateAttributes({
3681
- aggregates: { minimal: findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal, maximum: findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum },
3682
- fields: [], // será preenchido no contexto correto
3754
+ aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
3755
+ fields: params.fields,
3683
3756
  }),
3684
3757
  ];
3685
3758
  return aggregateFields.length > 0
@@ -3697,15 +3770,14 @@ class HasuraFindQueryBuilderHelper {
3697
3770
  : [];
3698
3771
  }
3699
3772
  static buildDistinctQueries(params) {
3700
- var _a;
3701
3773
  const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
3702
3774
  const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
3703
- if (!((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _a === void 0 ? void 0 : _a.length) || lastDistinct[tableFiltersNamed]) {
3775
+ if (!findOptions?.distinct?.length || lastDistinct[tableFiltersNamed]) {
3704
3776
  return [];
3705
3777
  }
3706
3778
  return findOptions.distinct.map((distinct) => {
3707
- var _a;
3708
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3779
+ const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
3780
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3709
3781
  return {
3710
3782
  operation: {
3711
3783
  name: tableName,
@@ -3725,18 +3797,16 @@ class HasuraFindQueryBuilderHelper {
3725
3797
 
3726
3798
  class HasuraFindOperationsHelper {
3727
3799
  static async executeFindOperation(operationParams) {
3728
- var _a;
3729
3800
  const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
3730
3801
  const logger = DebugHelper.from(operationParams, 'find');
3731
3802
  const { filters, options: findOptions } = params || {};
3732
3803
  const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
3733
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
3734
- // Verifica cache primeiro
3804
+ const enableCount = findOptions?.enableCount ?? true;
3735
3805
  const cachedResult = await HasuraFindCacheHelper.getCachedResult({
3736
3806
  cache,
3737
3807
  model,
3738
3808
  findParams: params,
3739
- cacheOptions: cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cache,
3809
+ cacheOptions: cacheOptions?.cache,
3740
3810
  logger,
3741
3811
  });
3742
3812
  if (cachedResult) {
@@ -3751,7 +3821,6 @@ class HasuraFindOperationsHelper {
3751
3821
  lastDistinct,
3752
3822
  });
3753
3823
  }
3754
- // Constrói e executa queries
3755
3824
  const queries = HasuraFindQueryBuilderHelper.buildCompleteQuery({
3756
3825
  tableName,
3757
3826
  fields,
@@ -3759,16 +3828,14 @@ class HasuraFindOperationsHelper {
3759
3828
  lastDistinct,
3760
3829
  });
3761
3830
  const result = await query(queries);
3762
- // Salva no cache se habilitado
3763
3831
  await HasuraFindCacheHelper.setCachedResult({
3764
3832
  cache,
3765
3833
  model,
3766
3834
  findParams: params,
3767
- cacheOptions: cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cache,
3835
+ cacheOptions: cacheOptions?.cache,
3768
3836
  result,
3769
3837
  logger,
3770
3838
  });
3771
- // Processa e retorna resultado
3772
3839
  return HasuraFindResultHelper.processResult({
3773
3840
  result,
3774
3841
  tableName,
@@ -3787,9 +3854,8 @@ class HasuraGetCacheHelper {
3787
3854
  return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
3788
3855
  }
3789
3856
  static async getCachedData(cache, params) {
3790
- var _a;
3791
3857
  const { identifiers, options, model, logger } = params;
3792
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || !((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled))
3858
+ if (!cache?.cacheAdapter || !options?.cache?.enabled)
3793
3859
  return null;
3794
3860
  const cacheKey = this.generateCacheKey(model, identifiers);
3795
3861
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -3799,15 +3865,14 @@ class HasuraGetCacheHelper {
3799
3865
  return model.toInstance(deserialize(cachedData));
3800
3866
  }
3801
3867
  static async saveCacheData(cache, params) {
3802
- var _a, _b;
3803
3868
  const { identifiers, options, data, logger } = params;
3804
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || !((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled))
3869
+ if (!cache?.cacheAdapter || !options?.cache?.enabled)
3805
3870
  return;
3806
3871
  const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
3807
3872
  await cache.cacheAdapter.set({
3808
3873
  key: cacheKey,
3809
3874
  data: serialize(data),
3810
- expirationInSeconds: ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.ttl) || cache.ttlDefault,
3875
+ expirationInSeconds: options?.cache?.ttl || cache.ttlDefault,
3811
3876
  });
3812
3877
  logger.log(`Dados salvos no cache: ${cacheKey}`);
3813
3878
  }
@@ -3818,18 +3883,20 @@ class HasuraGetVariablesHelper {
3818
3883
  const { model, fields, repository } = params;
3819
3884
  const instance = model.toInstance(identifiers);
3820
3885
  return model.identifiersFields.reduce((ids, identifier) => {
3821
- var _a;
3822
3886
  const identifierBinded = identifier;
3823
3887
  if (isNil(instance[identifierBinded]))
3824
3888
  return ids;
3825
3889
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3826
- const value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier], instance)) ||
3890
+ const value = columnOption?.to?.(identifiers[identifier], instance) ||
3827
3891
  identifiers[identifier];
3828
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
3892
+ return {
3893
+ ...ids,
3894
+ [columnOption.columnName]: {
3829
3895
  type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
3830
3896
  value,
3831
3897
  required: true,
3832
- } });
3898
+ },
3899
+ };
3833
3900
  }, {});
3834
3901
  }
3835
3902
  }
@@ -3886,7 +3953,7 @@ class HasuraUpdateDataHelper {
3886
3953
  static getValueByAction(options) {
3887
3954
  if (options instanceof BaseModel)
3888
3955
  return options.toPlain();
3889
- if (isNil(options === null || options === void 0 ? void 0 : options.action))
3956
+ if (isNil(options?.action))
3890
3957
  return options;
3891
3958
  if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
3892
3959
  return null;
@@ -3895,9 +3962,12 @@ class HasuraUpdateDataHelper {
3895
3962
  static paramsToPlain(params, model) {
3896
3963
  if (model.isModel(params))
3897
3964
  return params.toPlain();
3898
- return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && {
3899
- [currentKey]: this.getValueByAction(is(params[currentKey])),
3900
- }))), {});
3965
+ return Object.keys(params).reduce((data, currentKey) => ({
3966
+ ...data,
3967
+ ...(params[currentKey] !== undefined && {
3968
+ [currentKey]: this.getValueByAction(is(params[currentKey])),
3969
+ }),
3970
+ }), {});
3901
3971
  }
3902
3972
  static getIdentifiersFromData(data, model) {
3903
3973
  const instance = model.toInstance(data);
@@ -3916,13 +3986,15 @@ class HasuraUpdateVariablesHelper {
3916
3986
  static getUpdateModelKeys(data, model, fields) {
3917
3987
  const instance = model.toInstance(data);
3918
3988
  return model.identifiersFields.reduce((ids, identifier) => {
3919
- var _a;
3920
3989
  const identifierBinded = identifier;
3921
3990
  if (isNil(instance.identifier[identifierBinded]))
3922
3991
  return ids;
3923
3992
  const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
3924
- const value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, data[identifierBinded], instance)) || data[columnOption.attributeName];
3925
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: value });
3993
+ const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
3994
+ return {
3995
+ ...ids,
3996
+ [columnOption.columnName]: value,
3997
+ };
3926
3998
  }, {});
3927
3999
  }
3928
4000
  static getIdentifierFields(model, fields) {
@@ -3950,9 +4022,7 @@ class HasuraUpdateOperationsHelper {
3950
4022
  const { data, updateGraphQLOperation, updateGraphQLObjectType, updateGraphQLPKType, model, fields, cache, mutation, convertDataToHasura, } = params;
3951
4023
  const logger = DebugHelper.from(params, 'update');
3952
4024
  const plainData = HasuraUpdateDataHelper.paramsToPlain(data, model);
3953
- // Gerencia cache se disponível
3954
4025
  await this.handleCacheRemoval({ plainData, model, cache, logger });
3955
- // Executa mutation
3956
4026
  const identifierFields = HasuraUpdateVariablesHelper.getIdentifierFields(model, fields);
3957
4027
  const mutationVariables = HasuraUpdateVariablesHelper.buildMutationVariables({
3958
4028
  plainData,
@@ -3967,13 +4037,13 @@ class HasuraUpdateOperationsHelper {
3967
4037
  }
3968
4038
  static async handleCacheRemoval(params) {
3969
4039
  const { plainData, model, cache, logger } = params;
3970
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4040
+ if (!cache?.cacheAdapter)
3971
4041
  return;
3972
4042
  const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
3973
4043
  if (Object.keys(identifiers).length > 0) {
3974
4044
  const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
3975
4045
  await cache.cacheAdapter.remove(cacheKey);
3976
- logger === null || logger === void 0 ? void 0 : logger.log(`Cache removido: ${cacheKey}`);
4046
+ logger?.log(`Cache removido: ${cacheKey}`);
3977
4047
  }
3978
4048
  }
3979
4049
  }
@@ -3995,9 +4065,8 @@ class FirestoreCacheKeyGeneratorHelper {
3995
4065
 
3996
4066
  class FirestoreCacheHelper {
3997
4067
  static async getCachedData(cache, params) {
3998
- var _a;
3999
4068
  const { model, identifiers, options, logger, req } = params;
4000
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled) === false)
4069
+ if (!cache?.cacheAdapter || options?.cache?.enabled === false)
4001
4070
  return null;
4002
4071
  const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
4003
4072
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -4008,9 +4077,8 @@ class FirestoreCacheHelper {
4008
4077
  return null;
4009
4078
  }
4010
4079
  static async getCachedFindData(cache, params) {
4011
- var _a;
4012
4080
  const { model, find, options, logger } = params;
4013
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled) === false)
4081
+ if (!cache?.cacheAdapter || options?.cache?.enabled === false)
4014
4082
  return null;
4015
4083
  const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
4016
4084
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -4022,7 +4090,7 @@ class FirestoreCacheHelper {
4022
4090
  }
4023
4091
  static async saveCacheData(cache, params) {
4024
4092
  const { cacheKey, data, expirationInSeconds, logger, req } = params;
4025
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4093
+ if (!cache?.cacheAdapter)
4026
4094
  return;
4027
4095
  await cache.cacheAdapter.set({
4028
4096
  key: cacheKey,
@@ -4034,7 +4102,7 @@ class FirestoreCacheHelper {
4034
4102
  }
4035
4103
  static async removeCacheData(cache, params) {
4036
4104
  const { cacheKey, logger } = params;
4037
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4105
+ if (!cache?.cacheAdapter)
4038
4106
  return;
4039
4107
  await cache.cacheAdapter.remove(cacheKey);
4040
4108
  logger.log(`Cache removido: ${cacheKey}`);
@@ -4052,7 +4120,7 @@ class FirestoreOperationsHelper {
4052
4120
  this.model = model;
4053
4121
  }
4054
4122
  buildInstanceFromIdentifiers(identifiers) {
4055
- return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
4123
+ return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
4056
4124
  }
4057
4125
  async validateDocumentExists(docRef, collectionName, identifiers) {
4058
4126
  const docSnapshot = await docRef.get();
@@ -4074,7 +4142,7 @@ class FirestoreOperationsHelper {
4074
4142
  calculateCount(data, limits) {
4075
4143
  if (data.length <= 0)
4076
4144
  return 0;
4077
- if (data.length < (limits === null || limits === void 0 ? void 0 : limits.limit))
4145
+ if (data.length)
4078
4146
  return data.length;
4079
4147
  return Infinity;
4080
4148
  }
@@ -4087,8 +4155,8 @@ class FirestoreOperationsHelper {
4087
4155
  const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
4088
4156
  if (!isSubCollection)
4089
4157
  return collectionName;
4090
- const parentId = identifiers === null || identifiers === void 0 ? void 0 : identifiers[parentIdField];
4091
- return `${parentRepository === null || parentRepository === void 0 ? void 0 : parentRepository.collectionName}/${parentId}/${collectionName}`;
4158
+ const parentId = identifiers?.[parentIdField];
4159
+ return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
4092
4160
  }
4093
4161
  getKeyField() {
4094
4162
  const model = new this.model();
@@ -4139,27 +4207,25 @@ const createGetFirestoreClass = (MixinBase) => {
4139
4207
  }
4140
4208
  }
4141
4209
  async executeGet(params) {
4142
- var _a, _b, _c, _d;
4143
4210
  const { instance, collectionName, identifiers, logger, req } = params;
4144
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
4145
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
4211
+ const intercepted = await this.interceptors?.request?.({ instance });
4212
+ const builded = intercepted?.instance || instance;
4146
4213
  const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
4147
4214
  const data = docRef.data();
4148
4215
  this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
4149
- const result = (await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, data, intercepted))) || data;
4216
+ const result = (await this.interceptors?.response?.(data, intercepted)) || data;
4150
4217
  logger.log({ req, res: result });
4151
4218
  return result;
4152
4219
  }
4153
4220
  async saveCacheData(params) {
4154
- var _a, _b, _c;
4155
4221
  const { identifiers, options, result, logger, req } = params;
4156
- if (!((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) || ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled) === false)
4222
+ if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
4157
4223
  return;
4158
4224
  const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
4159
4225
  await FirestoreCacheHelper.saveCacheData(this.cache, {
4160
4226
  cacheKey,
4161
4227
  data: result,
4162
- expirationInSeconds: (_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.ttl,
4228
+ expirationInSeconds: options?.cache?.ttl,
4163
4229
  logger,
4164
4230
  req,
4165
4231
  });
@@ -4190,14 +4256,13 @@ class FirestoreQueryBuilderHelper {
4190
4256
  this.config = config;
4191
4257
  }
4192
4258
  buildWhereSentence(fieldName, options) {
4193
- var _a, _b;
4194
- if (((_b = (_a = this.config).isSubCollection) === null || _b === void 0 ? void 0 : _b.call(_a, this)) && fieldName === this.config.parentIdField)
4259
+ if (this.config.isSubCollection?.(this) && fieldName === this.config.parentIdField)
4195
4260
  return [];
4196
4261
  const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
4197
4262
  return this.buildWhereConditions(firestoreFieldName, options, fieldName);
4198
4263
  }
4199
4264
  getFirestoreFieldName(fieldName, options) {
4200
- const value = (options === null || options === void 0 ? void 0 : options.value) || options;
4265
+ const value = options?.value || options;
4201
4266
  const object = {};
4202
4267
  set(object, fieldName.toString(), value);
4203
4268
  const plainInstance = new this.config.model(object).toPlain();
@@ -4206,19 +4271,19 @@ class FirestoreQueryBuilderHelper {
4206
4271
  : Object.keys(plainInstance).find((key) => plainInstance[key]);
4207
4272
  }
4208
4273
  buildWhereConditions(firestoreFieldName, options, fieldName) {
4209
- if ((options === null || options === void 0 ? void 0 : options.operator) === Where.LIKE) {
4274
+ if (options?.operator === Where.LIKE) {
4210
4275
  return this.buildLikeConditions(firestoreFieldName, options);
4211
4276
  }
4212
- if ((options === null || options === void 0 ? void 0 : options.operator) === Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4277
+ if (options?.operator === Where.IN && Array.isArray(options?.value)) {
4213
4278
  return this.buildInConditions(firestoreFieldName, options);
4214
4279
  }
4215
4280
  if (this.isNestedObjectFilter(options)) {
4216
4281
  return this.buildNestedObjectConditions(fieldName, options);
4217
4282
  }
4218
- return [[firestoreFieldName, ((options === null || options === void 0 ? void 0 : options.operator) || '=='), (options === null || options === void 0 ? void 0 : options.value) || options]];
4283
+ return [[firestoreFieldName, (options?.operator || '=='), options?.value || options]];
4219
4284
  }
4220
4285
  buildLikeConditions(firestoreFieldName, options) {
4221
- if (this.isArrayField(firestoreFieldName) && Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4286
+ if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
4222
4287
  return [[firestoreFieldName, 'array-contains-any', options.value]];
4223
4288
  }
4224
4289
  return [
@@ -4235,17 +4300,16 @@ class FirestoreQueryBuilderHelper {
4235
4300
  buildNestedObjectConditions(fieldName, options) {
4236
4301
  return Object.keys(options).reduce((queries, key) => [
4237
4302
  ...queries,
4238
- ...this.buildWhereSentence(`${fieldName.toString()}.${key}`, is(options)[key]),
4303
+ ...this.buildWhereSentence(Array.isArray(options) ? fieldName : `${fieldName.toString()}.${key}`, is(options)[key]),
4239
4304
  ], []);
4240
4305
  }
4241
4306
  isArrayField(firestoreFieldName) {
4242
- var _a, _b;
4243
- return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
4307
+ return (this.config.fields?.[firestoreFieldName] ===
4244
4308
  FirestoreFieldType.Array ||
4245
- !((_b = this.config.fields) === null || _b === void 0 ? void 0 : _b[firestoreFieldName]));
4309
+ !this.config.fields?.[firestoreFieldName]);
4246
4310
  }
4247
4311
  isNestedObjectFilter(options) {
4248
- return isObject(options) && isNil(options === null || options === void 0 ? void 0 : options.operator) && isNil(options === null || options === void 0 ? void 0 : options.value);
4312
+ return isObject(options) && isNil(options?.operator) && isNil(options?.value);
4249
4313
  }
4250
4314
  buildOrderBy(filters, fieldsToOrderBy) {
4251
4315
  const orderByKeys = Object.keys(fieldsToOrderBy || {});
@@ -4261,8 +4325,8 @@ class FirestoreQueryBuilderHelper {
4261
4325
  filtersKeysWithUnordered.forEach((filterKey) => {
4262
4326
  const filterValue = filters[filterKey];
4263
4327
  const filterOptions = is(filterValue);
4264
- if ((filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.operator) && ![Where.EQUALS].includes(filterOptions.operator)) {
4265
- updatedOrderBy = Object.assign({ [filterKey]: 'asc' }, updatedOrderBy);
4328
+ if (filterOptions?.operator && ![Where.EQUALS].includes(filterOptions.operator)) {
4329
+ updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
4266
4330
  }
4267
4331
  });
4268
4332
  return updatedOrderBy;
@@ -4276,21 +4340,21 @@ class FirestoreQueryBuilderHelper {
4276
4340
  async buildLimits(params) {
4277
4341
  const { filters, limits, collection, buildCollectionPath } = params;
4278
4342
  const queries = [];
4279
- if (limits === null || limits === void 0 ? void 0 : limits.offset) {
4343
+ if (limits?.offset) {
4280
4344
  await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
4281
4345
  }
4282
- if (limits === null || limits === void 0 ? void 0 : limits.limit) {
4346
+ if (limits?.limit) {
4283
4347
  queries.push(['limit', limits.limit]);
4284
4348
  }
4285
4349
  return queries;
4286
4350
  }
4287
4351
  async addOffsetQuery(params) {
4288
- var _a;
4289
4352
  const { queries, limits, filters, collection, buildCollectionPath } = params;
4290
4353
  if (this.config.model.isModel(limits.offset)) {
4291
4354
  const docSnapshot = await collection(buildCollectionPath(filters))
4292
- .getDoc((_a = Object.values(limits.offset.identifier)
4293
- .shift()) === null || _a === void 0 ? void 0 : _a.toString())
4355
+ .getDoc(Object.values(limits.offset.identifier)
4356
+ .shift()
4357
+ ?.toString())
4294
4358
  .get();
4295
4359
  queries.push(['fromStartAfter', docSnapshot]);
4296
4360
  }
@@ -4305,7 +4369,7 @@ class FirestoreQueryBuilderHelper {
4305
4369
  }
4306
4370
 
4307
4371
  const createFilterHelpers = () => {
4308
- const checkIfIsFilterOption = (filter) => !isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
4372
+ const checkIfIsFilterOption = (filter) => !isNil(filter?.operator);
4309
4373
  const getValueFromFilter = (filter) => {
4310
4374
  return checkIfIsFilterOption(filter) ? filter.value : filter;
4311
4375
  };
@@ -4363,20 +4427,19 @@ const withFindFirestore = (MixinBase) => {
4363
4427
  }
4364
4428
  }
4365
4429
  async executeFind(params) {
4366
- var _a, _b, _c, _d, _e, _f;
4367
4430
  const { find, collectionName, logger, req } = params;
4368
4431
  const collection = this.collection(collectionName);
4369
- const enableCount = (_b = (_a = find === null || find === void 0 ? void 0 : find.options) === null || _a === void 0 ? void 0 : _a.enableCount) !== null && _b !== void 0 ? _b : true;
4370
- const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
4371
- const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
4432
+ const enableCount = find?.options?.enableCount ?? true;
4433
+ const intercepted = await this.interceptors?.request?.({ find });
4434
+ const { filters, limits, orderBy } = intercepted?.find || find;
4372
4435
  const queryData = await this.buildQueryData(filters, orderBy, limits);
4373
4436
  const docs = await this.executeQuery(collection, queryData);
4374
4437
  const data = docs.docs.map((doc) => doc.data());
4375
4438
  const result = {
4376
- data: (await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data,
4439
+ data: (await this.interceptors?.response?.(data, intercepted)) || data,
4377
4440
  count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
4378
4441
  };
4379
- logger.log(Object.assign(Object.assign({ req }, queryData), { res: result }));
4442
+ logger.log({ req, ...queryData, res: result });
4380
4443
  return result;
4381
4444
  }
4382
4445
  async buildQueryData(filters, orderBy, limits) {
@@ -4392,19 +4455,21 @@ const withFindFirestore = (MixinBase) => {
4392
4455
  }
4393
4456
  async executeQuery(collection, queryData) {
4394
4457
  return this.queryBuilder
4395
- .buildQuery(Object.assign({ collection }, queryData))
4458
+ .buildQuery({
4459
+ collection,
4460
+ ...queryData,
4461
+ })
4396
4462
  .getDocs();
4397
4463
  }
4398
4464
  async saveCacheData(params) {
4399
- var _a, _b, _c;
4400
4465
  const { find, options, result, logger } = params;
4401
- if (!((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) || ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled) === false)
4466
+ if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
4402
4467
  return;
4403
4468
  const cacheKey = this.generateCacheKey(find);
4404
4469
  await FirestoreCacheHelper.saveCacheData(this.cache, {
4405
4470
  cacheKey,
4406
4471
  data: result,
4407
- expirationInSeconds: (_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.ttl,
4472
+ expirationInSeconds: options?.cache?.ttl,
4408
4473
  logger,
4409
4474
  });
4410
4475
  }
@@ -4412,7 +4477,7 @@ const withFindFirestore = (MixinBase) => {
4412
4477
  if (!this.isSubCollection(this))
4413
4478
  return this.collectionName;
4414
4479
  const parentIdField = this.parentIdField;
4415
- const parentId = getValueFromFilter(filters === null || filters === void 0 ? void 0 : filters[parentIdField]);
4480
+ const parentId = getValueFromFilter(filters?.[parentIdField]);
4416
4481
  return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
4417
4482
  }
4418
4483
  };
@@ -4421,16 +4486,15 @@ const withFindFirestore = (MixinBase) => {
4421
4486
  const withCreateFirestore = (MixinBase) => {
4422
4487
  return class CreateFirestore extends MixinBase {
4423
4488
  async create(data) {
4424
- var _a, _b, _c, _d;
4425
4489
  const logger = this.logger.with('create');
4426
4490
  const instance = this.model.toInstance(data);
4427
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
4428
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
4491
+ const intercepted = await this.interceptors?.request?.({ instance });
4492
+ const builded = intercepted?.instance || instance;
4429
4493
  const req = { collection: this.buildCollectionPathForAdd(builded), data };
4430
4494
  try {
4431
4495
  const docRef = await this.save(builded);
4432
4496
  const doc = (await docRef.get()).data();
4433
- const docBuilded = (await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, doc, intercepted))) || doc;
4497
+ const docBuilded = (await this.interceptors?.response?.(doc, intercepted)) || doc;
4434
4498
  logger.log({ req, res: docBuilded });
4435
4499
  return docBuilded;
4436
4500
  }
@@ -4441,10 +4505,9 @@ const withCreateFirestore = (MixinBase) => {
4441
4505
  }
4442
4506
  }
4443
4507
  async save(data) {
4444
- var _a, _b;
4445
4508
  const collectionPath = this.buildCollectionPathForAdd(data);
4446
4509
  const collection = this.collection(collectionPath);
4447
- return collection.add(data, (_b = (_a = Object.values(data.identifier).shift()) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a));
4510
+ return collection.add(data, Object.values(data.identifier).shift()?.toString?.());
4448
4511
  }
4449
4512
  buildCollectionPathForAdd(identifiers) {
4450
4513
  return this.isSubCollection(this)
@@ -4455,26 +4518,23 @@ const withCreateFirestore = (MixinBase) => {
4455
4518
  };
4456
4519
 
4457
4520
  const createUpdateHelpers = () => {
4458
- const getValueFromParams = (params, field) => {
4459
- var _a;
4460
- return (isNil((_a = is(params[field])) === null || _a === void 0 ? void 0 : _a.value)
4461
- ? is(params[field])
4462
- : is(params[field]).value) || null;
4463
- };
4521
+ const getValueFromParams = (params, field) => (isNil(is(params[field])?.value)
4522
+ ? is(params[field])
4523
+ : is(params[field]).value) || null;
4464
4524
  const getValueByAction = (options) => {
4465
- if (isNil(options === null || options === void 0 ? void 0 : options.action))
4525
+ if (isNil(options?.action))
4466
4526
  return options;
4467
- if ((options === null || options === void 0 ? void 0 : options.action) === UpdateOptionActions.REMOVE_FIELD)
4527
+ if (options?.action === UpdateOptionActions.REMOVE_FIELD)
4468
4528
  return deleteField();
4469
- if ((options === null || options === void 0 ? void 0 : options.action) === UpdateOptionActions.NULL)
4529
+ if (options?.action === UpdateOptionActions.NULL)
4470
4530
  return null;
4471
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4472
- if ((options === null || options === void 0 ? void 0 : options.action) === UpdateOptionActions.MERGE)
4531
+ if (Array.isArray(options?.value)) {
4532
+ if (options?.action === UpdateOptionActions.MERGE)
4473
4533
  return arrayUnion(...options.value);
4474
- if ((options === null || options === void 0 ? void 0 : options.action) === UpdateOptionActions.REMOVE)
4534
+ if (options?.action === UpdateOptionActions.REMOVE)
4475
4535
  return arrayRemove(...options.value);
4476
4536
  }
4477
- return options === null || options === void 0 ? void 0 : options.value;
4537
+ return options?.value;
4478
4538
  };
4479
4539
  return { getValueFromParams, getValueByAction };
4480
4540
  };
@@ -4525,14 +4585,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
4525
4585
  await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
4526
4586
  }
4527
4587
  async executeUpdate(params) {
4528
- var _a, _b, _c, _d;
4529
4588
  const { data, docRef, logger, req, identifiers } = params;
4530
4589
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
4531
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
4532
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
4590
+ const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
4591
+ const builded = intercepted?.instance || plainFromData;
4533
4592
  await docRef.save(builded.toPlain());
4534
4593
  const docData = await docRef.get();
4535
- const result = ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, docData.data(), intercepted)) || docData.data();
4594
+ const result = this.interceptors?.response?.(docData.data(), intercepted) || docData.data();
4536
4595
  logger.log({ req, res: result, identifiers });
4537
4596
  return result;
4538
4597
  }
@@ -4548,7 +4607,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
4548
4607
  return this.convertParamsToPlainObject(params);
4549
4608
  }
4550
4609
  convertParamsToPlainObject(params) {
4551
- return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), this.processParamValue(currentKey, params[currentKey]))), {});
4610
+ return Object.keys(params).reduce((data, currentKey) => ({
4611
+ ...data,
4612
+ ...this.processParamValue(currentKey, params[currentKey]),
4613
+ }), {});
4552
4614
  }
4553
4615
  processParamValue(key, value) {
4554
4616
  const processedValue = getValueByAction(value);
@@ -4589,12 +4651,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
4589
4651
  await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
4590
4652
  }
4591
4653
  async executeDeleteOperation(params) {
4592
- var _a, _b, _c, _d;
4593
4654
  const { instance, collectionName, logger, req } = params;
4594
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
4595
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
4655
+ const intercepted = await this.interceptors?.request?.({ instance });
4656
+ const builded = intercepted?.instance || instance;
4596
4657
  await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
4597
- await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
4658
+ await this.interceptors?.response?.(instance, intercepted);
4598
4659
  logger.log({ req, res: undefined });
4599
4660
  }
4600
4661
  buildCollectionPathForRemove(identifiers) {
@@ -4674,15 +4735,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
4674
4735
  const products = [];
4675
4736
  const wheres = [];
4676
4737
  for (const productIds of chunks) {
4677
- if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
4738
+ if (options?.limit && products.length >= options?.limit)
4678
4739
  break;
4679
4740
  wheres.push(['published', '==', true], ['id', 'in', productIds]);
4680
- if (options === null || options === void 0 ? void 0 : options.hasStock)
4741
+ if (options?.hasStock)
4681
4742
  wheres.push(['stock.quantity', '>', 0]);
4682
- if (options === null || options === void 0 ? void 0 : options.gender)
4683
- wheres.push(['tags', 'array-contains', options === null || options === void 0 ? void 0 : options.gender]);
4743
+ if (options?.gender)
4744
+ wheres.push(['tags', 'array-contains', options?.gender]);
4684
4745
  const productSnap = await wheres
4685
- .reduce((collection, where) => collection.where(...where), (options === null || options === void 0 ? void 0 : options.limit)
4746
+ .reduce((collection, where) => collection.where(...where), options?.limit
4686
4747
  ? this.collection('productsErpVitrine').limit(options.limit)
4687
4748
  : this.collection('productsErpVitrine'))
4688
4749
  .getDocs();
@@ -4747,19 +4808,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4747
4808
  throw new Error('Method not implemented.');
4748
4809
  }
4749
4810
  async getBySlug(slug) {
4750
- var _a;
4751
4811
  const result = await this.find({
4752
4812
  filters: {
4753
4813
  slug: { operator: Where.EQUALS, value: slug },
4754
4814
  },
4755
4815
  });
4756
- return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4816
+ return result?.data?.shift();
4757
4817
  }
4758
4818
  async fetchReviews(status) {
4759
4819
  const { data: products } = await this.find();
4760
4820
  products.forEach((product) => {
4761
- var _a;
4762
- if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
4821
+ if ([undefined, 0].includes(product.reviews?.length))
4763
4822
  return;
4764
4823
  const productInfo = {
4765
4824
  productId: product.id,
@@ -4771,11 +4830,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4771
4830
  this.reviews.rejected = [];
4772
4831
  product.reviews.forEach((review) => {
4773
4832
  if ([null, undefined].includes(review.status))
4774
- return this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
4833
+ return this.reviews.pending.push({ ...review, ...productInfo });
4775
4834
  if (review.status === false)
4776
- return this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
4835
+ return this.reviews.rejected.push({ ...review, ...productInfo });
4777
4836
  if (review.status)
4778
- return this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
4837
+ return this.reviews.approved.push({ ...review, ...productInfo });
4779
4838
  return review;
4780
4839
  });
4781
4840
  });
@@ -4862,22 +4921,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4862
4921
  interceptors,
4863
4922
  cache,
4864
4923
  });
4865
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4866
- var _a, _b, _c;
4867
- return ({
4868
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
4869
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
4870
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
4871
- products: ((_c = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.products) === null || _c === void 0 ? void 0 : _c.map((product) => ((product === null || product === void 0 ? void 0 : product.toPlain) ? product === null || product === void 0 ? void 0 : product.toPlain() : product)).filter(Boolean)) || [],
4872
- });
4873
- };
4874
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
4875
- var _a;
4876
- return ({
4877
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
4878
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
4879
- });
4880
- };
4924
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
4925
+ category: homeCategoryGroup?.category?.toPlain
4926
+ ? homeCategoryGroup?.category?.toPlain()
4927
+ : homeCategoryGroup?.category,
4928
+ products: homeCategoryGroup?.products
4929
+ ?.map((product) => (product?.toPlain ? product?.toPlain() : product))
4930
+ .filter(Boolean) || [],
4931
+ });
4932
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
4933
+ category: Category.toInstance(homeCategoryGroup?.category),
4934
+ products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
4935
+ });
4881
4936
  }
4882
4937
  buildModelInstance() {
4883
4938
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -4893,17 +4948,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4893
4948
  };
4894
4949
  }
4895
4950
  homeToFirestore(home) {
4896
- var _a, _b, _c, _d;
4897
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4898
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
4899
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
4900
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
4951
+ if (home.data?.data) {
4952
+ home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
4953
+ home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
4954
+ home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
4901
4955
  }
4902
4956
  return home;
4903
4957
  }
4904
4958
  homeFromFirestore(home) {
4905
- var _a;
4906
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4959
+ if (home.data?.data) {
4907
4960
  home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
4908
4961
  home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
4909
4962
  home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
@@ -5042,8 +5095,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
5042
5095
  },
5043
5096
  });
5044
5097
  this.orderFromFirestore = (order) => {
5045
- var _a;
5046
- if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
5098
+ if (order?.lineItems?.length) {
5047
5099
  order.lineItems = order.lineItems.map((lineItem) => {
5048
5100
  const prices = !!lineItem.price;
5049
5101
  const shopPrice = prices[order.shop];
@@ -5058,7 +5110,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
5058
5110
  buildModelInstance() {
5059
5111
  const { fromFirestore, toFirestore } = super.buildModelInstance();
5060
5112
  return {
5061
- toFirestore: (data) => toFirestore((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data),
5113
+ toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
5062
5114
  fromFirestore: (snap) => {
5063
5115
  const instance = fromFirestore(snap);
5064
5116
  return this.orderFromFirestore(instance);
@@ -5089,18 +5141,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
5089
5141
  });
5090
5142
  }
5091
5143
  async createBlockedOrderOrPayment(params) {
5092
- var _a, _b, _c, _d, _e, _f, _g, _h;
5093
5144
  const { checkout, blockType, type, limiteRange, card = null } = params;
5094
5145
  return this.create(OrderBlocked.toInstance({
5095
5146
  customer: {
5096
- name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
5097
- cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
5098
- id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
5099
- email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
5100
- phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
5101
- isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
5102
- subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
5103
- shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
5147
+ name: checkout.user?.displayName || '',
5148
+ cpf: checkout.user?.cpf || '',
5149
+ id: checkout.user?.id,
5150
+ email: checkout.user?.email || '',
5151
+ phoneNumber: '+55' + checkout.user?.phone,
5152
+ isSubscriber: checkout.user?.isSubscriber,
5153
+ subscriptionPlan: checkout.user?.subscriptionPlan || '',
5154
+ shippingAddress: {
5155
+ ...checkout.shippingAddress,
5156
+ zip: this.formatZip(checkout.shippingAddress?.zip),
5157
+ },
5104
5158
  },
5105
5159
  blockType,
5106
5160
  limiteRange,
@@ -5348,7 +5402,7 @@ class ConnectDocumentService {
5348
5402
  this.reference = doc(this.firestore, this.path).withConverter({
5349
5403
  toFirestore: (data) => data,
5350
5404
  fromFirestore: (snapshot) => {
5351
- return Object.assign({ id: snapshot.id }, snapshot.data());
5405
+ return { id: snapshot.id, ...snapshot.data() };
5352
5406
  },
5353
5407
  });
5354
5408
  }
@@ -5386,7 +5440,7 @@ class ConnectCollectionService {
5386
5440
  this.reference = collection(firestore, path).withConverter({
5387
5441
  toFirestore: (data) => data,
5388
5442
  fromFirestore: (snapshot) => {
5389
- return Object.assign({ id: snapshot.id }, snapshot.data());
5443
+ return { id: snapshot.id, ...snapshot.data() };
5390
5444
  },
5391
5445
  });
5392
5446
  }
@@ -5481,10 +5535,10 @@ class FirebaseFileUploaderService {
5481
5535
  function createCreateHasuraGraphQLClass(MixinBase) {
5482
5536
  return class CreateHasuraGraphQLMixin extends MixinBase {
5483
5537
  constructor(...params) {
5484
- const options = params === null || params === void 0 ? void 0 : params[0];
5538
+ const options = params?.[0];
5485
5539
  super(...params);
5486
- this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.insertGraphQLOperation);
5487
- this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options === null || options === void 0 ? void 0 : options.insertGraphQLObjectType);
5540
+ this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options?.insertGraphQLOperation);
5541
+ this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options?.insertGraphQLObjectType);
5488
5542
  }
5489
5543
  async create(data) {
5490
5544
  return HasuraCreateOperationsHelper.executeCreate(data, {
@@ -5511,9 +5565,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
5511
5565
  function createDeleteHasuraGraphQLClass(MixinBase) {
5512
5566
  return class DeleteHasuraGraphQLMixin extends MixinBase {
5513
5567
  constructor(...params) {
5514
- const options = params === null || params === void 0 ? void 0 : params[0];
5568
+ const options = params?.[0];
5515
5569
  super(...params);
5516
- this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.deleteGraphQLOperation);
5570
+ this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
5517
5571
  }
5518
5572
  async delete(identifiers) {
5519
5573
  await HasuraDeleteOperationsHelper.executeDelete({
@@ -5559,9 +5613,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
5559
5613
  function createGetHasuraGraphQLClass(MixinBase) {
5560
5614
  return class GetHasuraGraphQLMixin extends MixinBase {
5561
5615
  constructor(...params) {
5562
- const options = params === null || params === void 0 ? void 0 : params[0];
5616
+ const options = params?.[0];
5563
5617
  super(...params);
5564
- this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.getGraphQLOperation);
5618
+ this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
5565
5619
  }
5566
5620
  generateCacheKey(identifiers) {
5567
5621
  return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
@@ -5637,11 +5691,11 @@ function createHasuraGraphQLClass(MixinBase) {
5637
5691
  function createUpdateHasuraGraphQLClass(MixinBase) {
5638
5692
  return class UpdateHasuraGraphQLMixin extends MixinBase {
5639
5693
  constructor(...params) {
5640
- const options = params === null || params === void 0 ? void 0 : params[0];
5694
+ const options = params?.[0];
5641
5695
  super(...params);
5642
- this.updateGraphQLOperation = (options === null || options === void 0 ? void 0 : options.updateGraphQLOperation) || `update_${this.tableName}_by_pk`;
5643
- this.updateGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.updateGraphQLObjectType) || `${this.tableName}_set_input`;
5644
- this.updateGraphQLPKType = (options === null || options === void 0 ? void 0 : options.updateGraphQLPKType) || `${this.tableName}_pk_columns_input`;
5696
+ this.updateGraphQLOperation = options?.updateGraphQLOperation || `update_${this.tableName}_by_pk`;
5697
+ this.updateGraphQLObjectType = options?.updateGraphQLObjectType || `${this.tableName}_set_input`;
5698
+ this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
5645
5699
  }
5646
5700
  getIdentifiersFromData(data) {
5647
5701
  return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
@@ -5831,7 +5885,7 @@ const fieldsConfiguration$5 = [
5831
5885
  categories: { data: value.map((category) => ({ category_id: +category })) },
5832
5886
  }),
5833
5887
  to: (categories) => categories.map((categoryId) => +categoryId),
5834
- from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
5888
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
5835
5889
  },
5836
5890
  },
5837
5891
  ],
@@ -5912,8 +5966,7 @@ class CategoryCacheOperationsHelper {
5912
5966
  logger.log(`Dados salvos no cache: ${cacheKey}`);
5913
5967
  }
5914
5968
  static shouldUseCache(cacheAdapter, optionsCache) {
5915
- var _a;
5916
- return !!(cacheAdapter && ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.enabled));
5969
+ return !!(cacheAdapter && optionsCache?.cache?.enabled);
5917
5970
  }
5918
5971
  }
5919
5972
 
@@ -6081,19 +6134,25 @@ class CategoryProductOperationsHelper {
6081
6134
  }
6082
6135
  static buildProductQuery(params) {
6083
6136
  const { productIds, fields, hasStock, limit } = params;
6084
- return Object.assign(Object.assign({ filters: this.buildProductFilters(productIds, hasStock) }, (limit ? { limits: { limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
6137
+ return {
6138
+ filters: this.buildProductFilters(productIds, hasStock),
6139
+ ...(limit ? { limits: { limit } } : {}),
6140
+ fields,
6141
+ options: { enableCount: false },
6142
+ orderBy: {
6085
6143
  stock: 'desc',
6086
6144
  shoppingCount: 'desc',
6087
6145
  rate: 'desc',
6088
6146
  name: 'asc',
6089
- } });
6147
+ },
6148
+ };
6090
6149
  }
6091
6150
  static getGenderParam(shop) {
6092
6151
  return shop === Shops.MENSMARKET ? 'male' : 'female';
6093
6152
  }
6094
6153
  static async fetchMostRelevantProducts(params) {
6095
6154
  const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
6096
- if (!(mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length))
6155
+ if (!mostRelevantsIds?.length)
6097
6156
  return [];
6098
6157
  const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
6099
6158
  const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
@@ -6122,9 +6181,8 @@ class CategoryProductOperationsHelper {
6122
6181
 
6123
6182
  class CategoryMountOperationsHelper {
6124
6183
  static async executeMount(params, dependencies) {
6125
- var _a;
6126
6184
  const { category, shop, options = {}, optionsCache } = params;
6127
- if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
6185
+ if (!category?.products?.length)
6128
6186
  return [];
6129
6187
  const cachedResult = await this.tryGetFromCache({
6130
6188
  category,
@@ -6145,7 +6203,7 @@ class CategoryMountOperationsHelper {
6145
6203
  optionsCache,
6146
6204
  dependencies,
6147
6205
  });
6148
- if (mostRelevantProducts.length >= mostRelevantsIds.length) {
6206
+ if (mostRelevantsIds.length && mostRelevantProducts.length >= mostRelevantsIds.length) {
6149
6207
  return this.finalizeMountWithMostRelevants({
6150
6208
  mostRelevantProducts,
6151
6209
  mostRelevantsIds,
@@ -6222,7 +6280,6 @@ class CategoryMountOperationsHelper {
6222
6280
  return result;
6223
6281
  }
6224
6282
  static async saveToCacheIfNeeded(params) {
6225
- var _a;
6226
6283
  const { category, shop, options, optionsCache, result, dependencies } = params;
6227
6284
  const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
6228
6285
  if (!shouldUseCache)
@@ -6232,7 +6289,7 @@ class CategoryMountOperationsHelper {
6232
6289
  cacheAdapter: dependencies.cacheAdapter,
6233
6290
  cacheKey,
6234
6291
  products: result,
6235
- ttl: ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.ttl) || dependencies.defaultCacheTtl,
6292
+ ttl: optionsCache?.cache?.ttl || dependencies.defaultCacheTtl,
6236
6293
  logger: dependencies.logger,
6237
6294
  });
6238
6295
  }
@@ -6258,7 +6315,12 @@ class ProductFetchReviewsHelper {
6258
6315
  ...reviews,
6259
6316
  ...product.reviews
6260
6317
  .filter((review) => this.matchesStatus(review, status))
6261
- .map((review) => (Object.assign(Object.assign({}, bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku }))),
6318
+ .map((review) => ({
6319
+ ...bindReviewToModel(review),
6320
+ productId: product.id,
6321
+ productName: product.name,
6322
+ productSku: product.sku,
6323
+ })),
6262
6324
  ], []);
6263
6325
  }
6264
6326
  static matchesStatus(review, status) {
@@ -6305,8 +6367,7 @@ class ProductReviewCacheHelper {
6305
6367
  dependencies.logger.log(`Dados salvos no cache: ${key}`);
6306
6368
  }
6307
6369
  static shouldUseCache(cacheAdapter, options) {
6308
- var _a;
6309
- return !!(cacheAdapter && ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled));
6370
+ return !!(cacheAdapter && options?.cache?.enabled);
6310
6371
  }
6311
6372
  }
6312
6373
 
@@ -6317,9 +6378,12 @@ class ProductReviewOperationsHelper {
6317
6378
  let count = 0;
6318
6379
  let offset = 0;
6319
6380
  do {
6320
- const result = await repository.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, (limit && {
6321
- limits: { offset, limit },
6322
- })));
6381
+ const result = await repository.find({
6382
+ fields: ['id', 'name', 'sku', 'reviews'],
6383
+ ...(limit && {
6384
+ limits: { offset, limit },
6385
+ }),
6386
+ });
6323
6387
  data = data.concat(result.data);
6324
6388
  count = result.data.length;
6325
6389
  offset += limit;
@@ -6330,7 +6394,13 @@ class ProductReviewOperationsHelper {
6330
6394
  const { data, getReviewStatus } = params;
6331
6395
  return data.reduce((reviews, product) => [
6332
6396
  ...reviews,
6333
- ...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
6397
+ ...product.reviews.map((review) => ({
6398
+ ...review,
6399
+ reviewStatus: getReviewStatus(review),
6400
+ productId: product.id,
6401
+ productName: product.name,
6402
+ productSku: product.sku,
6403
+ })),
6334
6404
  ], []);
6335
6405
  }
6336
6406
  static applyReviewFilters(params) {
@@ -6374,7 +6444,7 @@ class ProductReviewUpdateHelper {
6374
6444
  const { productId, reviews, dependencies } = params;
6375
6445
  const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
6376
6446
  const review = await dependencies.findReview(reviewData, productId);
6377
- return review === null || review === void 0 ? void 0 : review.id;
6447
+ return review?.id;
6378
6448
  }));
6379
6449
  await dependencies.mutation('delete_product_review', ['affected_rows'], {
6380
6450
  where: {
@@ -6413,7 +6483,7 @@ class ProductReviewUpdateHelper {
6413
6483
  static async insertNewReview(reviewData, productId, dependencies) {
6414
6484
  const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
6415
6485
  object: {
6416
- value: omit(Object.assign(Object.assign({}, dependencies.bindReviewToHasura(reviewData)), { product_id: productId.toString() }), ['id']),
6486
+ value: omit({ ...dependencies.bindReviewToHasura(reviewData), product_id: productId.toString() }, ['id']),
6417
6487
  type: 'product_review_insert_input',
6418
6488
  required: true,
6419
6489
  },
@@ -6506,11 +6576,14 @@ const fieldsConfiguration$4 = [
6506
6576
  bindPersistData: (value) => {
6507
6577
  return {
6508
6578
  brand_condition: value.brand,
6509
- tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
6579
+ tag_condition: value?.tags || [],
6510
6580
  };
6511
6581
  },
6512
6582
  bindFindFilter: (sentence) => {
6513
- return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
6583
+ return {
6584
+ ...(sentence.brand ? { brand_condition: sentence.brand } : {}),
6585
+ ...(sentence.tags ? { tag_condition: sentence.tags } : {}),
6586
+ };
6514
6587
  },
6515
6588
  },
6516
6589
  },
@@ -6522,7 +6595,7 @@ const fieldsConfiguration$4 = [
6522
6595
  bindPersistData: (value) => ({
6523
6596
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
6524
6597
  }),
6525
- from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter).filter((filter) => filter.enabled)) || [],
6598
+ from: (filters) => filters?.map((filter) => filter?.filter).filter((filter) => filter.enabled) || [],
6526
6599
  },
6527
6600
  },
6528
6601
  { createdAt: { columnName: 'created_at' } },
@@ -6587,11 +6660,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6587
6660
  this.categoryFilterRepository = categoryFilterRepository;
6588
6661
  }
6589
6662
  async create(params) {
6590
- const { images, mostRelevants, metadatas } = params, data = __rest(params, ["images", "mostRelevants", "metadatas"]);
6591
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadatas: metadatas || [{ shop: null, description: null, title: null }], mostRelevants: mostRelevants || {
6663
+ const { images, mostRelevants, metadatas, ...data } = params;
6664
+ return super.create({
6665
+ ...data,
6666
+ isWishlist: false,
6667
+ metadatas: metadatas || [{ shop: null, description: null, title: null }],
6668
+ mostRelevants: mostRelevants || {
6592
6669
  [Shops.GLAMSHOP]: null,
6593
6670
  [Shops.MENSMARKET]: null,
6594
- }, images: images || {
6671
+ },
6672
+ images: images || {
6595
6673
  [Shops.GLAMSHOP]: {
6596
6674
  brandBanner: null,
6597
6675
  brandBannerMobile: null,
@@ -6602,17 +6680,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6602
6680
  brandBannerMobile: null,
6603
6681
  image: null,
6604
6682
  },
6605
- } }));
6683
+ },
6684
+ });
6606
6685
  }
6607
6686
  async get(identifiers, optionsCache) {
6608
6687
  const id = await this.getId(identifiers.id);
6609
6688
  return super.get({ id }, optionsCache);
6610
6689
  }
6611
6690
  async update(params) {
6612
- const { id, products, metadatas, filters } = params, data = __rest(params, ["id", "products", "metadatas", "filters"]);
6691
+ const { id, products, metadatas, filters, ...data } = params;
6613
6692
  const categoryId = +(await this.getId(id));
6614
6693
  const [category] = await Promise.all([
6615
- super.update(Object.assign({ id: categoryId === null || categoryId === void 0 ? void 0 : categoryId.toString() }, data)),
6694
+ super.update({ id: categoryId?.toString(), ...data }),
6616
6695
  ...(products ? [this.updateProducts(categoryId, { products })] : []),
6617
6696
  ...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
6618
6697
  ...(filters ? [this.updateFilters(categoryId, { filters })] : []),
@@ -6652,7 +6731,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6652
6731
  }
6653
6732
  async getCategoriesForHome(params) {
6654
6733
  const { categoryIds, shop, limit = 4, optionsCache } = params;
6655
- if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
6734
+ if (!categoryIds?.length)
6656
6735
  return [];
6657
6736
  const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
6658
6737
  const categories = [];
@@ -6673,11 +6752,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6673
6752
  });
6674
6753
  }
6675
6754
  async mountCategory(params) {
6676
- var _a, _b;
6677
6755
  return CategoryMountOperationsHelper.executeMount(params, {
6678
6756
  productRepository: this.productRepository,
6679
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
6680
- defaultCacheTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
6757
+ cacheAdapter: this.cache?.cacheAdapter,
6758
+ defaultCacheTtl: this.cache?.ttlDefault,
6681
6759
  logger: this.logger,
6682
6760
  });
6683
6761
  }
@@ -6696,12 +6774,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6696
6774
  return categoryTree.some((c) => c.id == id.toString());
6697
6775
  }
6698
6776
  async getId(id) {
6699
- var _a, _b;
6700
6777
  if (!Number.isNaN(+id))
6701
6778
  return id;
6702
6779
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
6703
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
6704
- return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
6780
+ if (data?.[0]?.id)
6781
+ return data?.[0]?.id;
6705
6782
  throw new NotFoundError(`Category with id ${id} not found`);
6706
6783
  }
6707
6784
  async updateProducts(categoryId, { products }) {
@@ -6755,7 +6832,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6755
6832
  objects: {
6756
6833
  type: '[category_metadata_insert_input!]',
6757
6834
  required: true,
6758
- value: metadatas.map((m) => (Object.assign({ category_id: categoryId }, m))),
6835
+ value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
6759
6836
  },
6760
6837
  });
6761
6838
  return metadatas;
@@ -6921,7 +6998,7 @@ const fieldsConfiguration$3 = [
6921
6998
  bindPersistData: (value) => ({
6922
6999
  categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
6923
7000
  }),
6924
- from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => category === null || category === void 0 ? void 0 : category.category)) || [],
7001
+ from: (categories) => categories?.map((category) => category?.category) || [],
6925
7002
  },
6926
7003
  },
6927
7004
  ];
@@ -6940,7 +7017,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6940
7017
  this.categoryFilterRepository = categoryFilterRepository;
6941
7018
  }
6942
7019
  async update(params) {
6943
- const { options } = params, data = __rest(params, ["options"]);
7020
+ const { options, ...data } = params;
6944
7021
  const filter = await super.update(data);
6945
7022
  filter.options = await this.updateOptions(+data.id, { options });
6946
7023
  return filter;
@@ -6962,8 +7039,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6962
7039
  if (hasFilter)
6963
7040
  filterOptions.push(hasFilter);
6964
7041
  }
6965
- catch (_a) {
6966
- const newOption = await this.filterOptionRepository.create(Object.assign(Object.assign({}, options.value[i]), { filterId }));
7042
+ catch {
7043
+ const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
6967
7044
  filterOptions.push(newOption);
6968
7045
  }
6969
7046
  }
@@ -6977,8 +7054,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6977
7054
  if (hasFilter)
6978
7055
  filterOptions.push(hasFilter);
6979
7056
  }
6980
- catch (_b) {
6981
- const newOption = await this.filterOptionRepository.create(Object.assign(Object.assign({}, options[i]), { filterId }));
7057
+ catch {
7058
+ const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
6982
7059
  filterOptions.push(newOption);
6983
7060
  }
6984
7061
  }
@@ -7099,13 +7176,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7099
7176
  filters: {
7100
7177
  id: {
7101
7178
  operator: Where.IN,
7102
- value: Array.from(new Set(variantsWithNoData.map((item) => { var _a; return (_a = item.product.productId) === null || _a === void 0 ? void 0 : _a.toString(); }))),
7179
+ value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
7103
7180
  },
7104
7181
  },
7105
7182
  });
7106
7183
  products.forEach((product) => {
7107
7184
  result.data
7108
- .filter((variant) => { var _a; return ((_a = variant.product.productId) === null || _a === void 0 ? void 0 : _a.toString()) === product.id.toString(); })
7185
+ .filter((variant) => variant.product.productId?.toString() === product.id.toString())
7109
7186
  .forEach((variant) => {
7110
7187
  variant.product.name = product.name;
7111
7188
  variant.product.group = product.group;
@@ -7138,21 +7215,37 @@ const commonFields = [
7138
7215
  purpose: data.purpose,
7139
7216
  }),
7140
7217
  bindFindFilter: (filters) => {
7141
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((filters === null || filters === void 0 ? void 0 : filters.description) && { description: filters.description })), (filters.differentials && { differentials: filters.differentials })), (filters.whoMustUse && {
7142
- who_must_use: filters.whoMustUse,
7143
- })), (filters.howToUse && {
7144
- how_to_use: filters.howToUse,
7145
- })), (filters.brand && {
7146
- brand_description: filters.brand,
7147
- })), (filters.ingredients && {
7148
- ingredients: filters.ingredients,
7149
- })), (filters.purpose && {
7150
- purpose: filters.purpose,
7151
- }));
7218
+ return {
7219
+ ...(filters?.description && { description: filters.description }),
7220
+ ...(filters.differentials && { differentials: filters.differentials }),
7221
+ ...(filters.whoMustUse && {
7222
+ who_must_use: filters.whoMustUse,
7223
+ }),
7224
+ ...(filters.howToUse && {
7225
+ how_to_use: filters.howToUse,
7226
+ }),
7227
+ ...(filters.brand && {
7228
+ brand_description: filters.brand,
7229
+ }),
7230
+ ...(filters.ingredients && {
7231
+ ingredients: filters.ingredients,
7232
+ }),
7233
+ ...(filters.purpose && {
7234
+ purpose: filters.purpose,
7235
+ }),
7236
+ };
7152
7237
  },
7153
- bindPersistData: (descriptionData) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((descriptionData === null || descriptionData === void 0 ? void 0 : descriptionData.description) && { description: descriptionData.description })), (descriptionData.differentials && { differentials: descriptionData.differentials })), (descriptionData.whoMustUse && {
7154
- who_must_use: descriptionData.whoMustUse,
7155
- })), (descriptionData.howToUse && { how_to_use: descriptionData.howToUse })), (descriptionData.brand && { brand_description: descriptionData.brand })), (descriptionData.ingredients && { ingredients: descriptionData.ingredients })), (descriptionData.purpose && { purpose: descriptionData.purpose }))),
7238
+ bindPersistData: (descriptionData) => ({
7239
+ ...(descriptionData?.description && { description: descriptionData.description }),
7240
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7241
+ ...(descriptionData.whoMustUse && {
7242
+ who_must_use: descriptionData.whoMustUse,
7243
+ }),
7244
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7245
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7246
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7247
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7248
+ }),
7156
7249
  },
7157
7250
  },
7158
7251
  { differentials: { columnName: 'differentials' } },
@@ -7165,13 +7258,13 @@ const commonFields = [
7165
7258
  {
7166
7259
  images: {
7167
7260
  columnName: 'images',
7168
- to: (value) => { var _a; return ((value === null || value === void 0 ? void 0 : value.length) > 0 ? `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, '","')) || ''}"}` : '{}'); },
7261
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7169
7262
  },
7170
7263
  },
7171
7264
  {
7172
7265
  miniatures: {
7173
7266
  columnName: 'miniatures',
7174
- to: (value) => { var _a; return ((value === null || value === void 0 ? void 0 : value.length) > 0 ? `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, '","')) || ''}"}` : '{}'); },
7267
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7175
7268
  },
7176
7269
  },
7177
7270
  'name',
@@ -7186,19 +7279,31 @@ const commonFields = [
7186
7279
  subscriberPrice: data.subscriber_price,
7187
7280
  }),
7188
7281
  bindFindFilter: (filters) => {
7189
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7190
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7191
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7192
- subscriber_price: filters.subscriberPrice,
7193
- })), ((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7194
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7195
- }));
7282
+ return {
7283
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7284
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7285
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7286
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7287
+ }),
7288
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7289
+ subscriber_price: filters.subscriberPrice,
7290
+ }),
7291
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7292
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7293
+ }),
7294
+ };
7196
7295
  },
7197
- bindPersistData: (priceData) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
7198
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7199
- })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice })), (priceData.fullPriceDiscountPercentage >= 0 && {
7200
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7201
- }))),
7296
+ bindPersistData: (priceData) => ({
7297
+ ...(priceData?.price >= 0 && { price: priceData.price }),
7298
+ ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7299
+ ...(priceData.subscriberDiscountPercentage >= 0 && {
7300
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7301
+ }),
7302
+ ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7303
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
7304
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7305
+ }),
7306
+ }),
7202
7307
  },
7203
7308
  },
7204
7309
  { fullPrice: { columnName: 'full_price' } },
@@ -7213,7 +7318,7 @@ const commonFields = [
7213
7318
  stock: {
7214
7319
  columnName: 'stock',
7215
7320
  from: (quantity) => ({ quantity }),
7216
- to: (value) => (isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity),
7321
+ to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
7217
7322
  },
7218
7323
  },
7219
7324
  { hasStock: { columnName: 'has_stock' } },
@@ -7252,7 +7357,7 @@ const fieldsConfiguration$2 = [
7252
7357
  categories: { data: value.map((category) => ({ category_id: +category })) },
7253
7358
  }),
7254
7359
  to: (categories) => categories.map((categoryId) => +categoryId),
7255
- from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
7360
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
7256
7361
  },
7257
7362
  },
7258
7363
  {
@@ -7328,12 +7433,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7328
7433
  fields: fieldsConfiguration$2,
7329
7434
  cache,
7330
7435
  });
7331
- this.bindReviewToModel = (plain) => ProductReview.toInstance(Object.assign(Object.assign({}, is(omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id']))), { createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at, updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at, personId: plain.person_id, orderId: plain.order_id }));
7332
- this.bindReviewToHasura = (review) => (Object.assign(Object.assign({}, is(omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId']))), { person_id: review.personId, order_id: review.orderId }));
7436
+ this.bindReviewToModel = (plain) => ProductReview.toInstance({
7437
+ ...is(omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
7438
+ createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
7439
+ updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
7440
+ personId: plain.person_id,
7441
+ orderId: plain.order_id,
7442
+ });
7443
+ this.bindReviewToHasura = (review) => ({
7444
+ ...is(omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
7445
+ person_id: review.personId,
7446
+ order_id: review.orderId,
7447
+ });
7333
7448
  }
7334
7449
  async create(params) {
7335
- const { metadata } = params, data = __rest(params, ["metadata"]);
7336
- const product = await super.create(omit(Object.assign(Object.assign({}, data), { metadata: metadata || { description: null, title: null } }), ['reviews']));
7450
+ const { metadata, ...data } = params;
7451
+ const product = await super.create(omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
7337
7452
  try {
7338
7453
  product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
7339
7454
  }
@@ -7344,10 +7459,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7344
7459
  return product;
7345
7460
  }
7346
7461
  async get(identifiers, options) {
7347
- var _a;
7348
7462
  const product = Number.isNaN(+identifiers.id)
7349
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7350
- .data) === null || _a === void 0 ? void 0 : _a[0]
7463
+ ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7464
+ .data?.[0]
7351
7465
  : await super.get(identifiers, options);
7352
7466
  if (product.productId)
7353
7467
  throw new NotFoundError('Product not found, it is a variant');
@@ -7355,19 +7469,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7355
7469
  return product;
7356
7470
  }
7357
7471
  async find(params, optionsParams) {
7358
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
7359
- const _o = params || {}, { filters, fields } = _o, options = __rest(_o, ["filters", "fields"]);
7472
+ const { filters, fields, ...options } = params || {};
7360
7473
  const bindFields = fields ||
7361
7474
  this.fields
7362
7475
  .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7363
7476
  .filter((field) => field !== 'reviews' && field !== 'categories');
7364
- if ((_b = (_a = options.options) === null || _a === void 0 ? void 0 : _a.minimal) === null || _b === void 0 ? void 0 : _b.includes('price'))
7365
- (_c = options.options) === null || _c === void 0 ? void 0 : _c.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7366
- if ((_e = (_d = options.options) === null || _d === void 0 ? void 0 : _d.maximum) === null || _e === void 0 ? void 0 : _e.includes('price'))
7367
- (_f = options.options) === null || _f === void 0 ? void 0 : _f.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7368
- (_h = (_g = options.options) === null || _g === void 0 ? void 0 : _g.minimal) === null || _h === void 0 ? void 0 : _h.splice((_j = options.options) === null || _j === void 0 ? void 0 : _j.minimal.indexOf('price'), 1);
7369
- (_l = (_k = options.options) === null || _k === void 0 ? void 0 : _k.maximum) === null || _l === void 0 ? void 0 : _l.splice((_m = options.options) === null || _m === void 0 ? void 0 : _m.maximum.indexOf('price'), 1);
7370
- return super.find(Object.assign(Object.assign({}, options), { filters: Object.assign(Object.assign({}, filters), { productId: { operator: Where.ISNULL } }), fields: [
7477
+ if (options.options?.minimal?.includes('price'))
7478
+ options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7479
+ if (options.options?.maximum?.includes('price'))
7480
+ options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7481
+ options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7482
+ options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7483
+ return super.find({
7484
+ ...options,
7485
+ filters: { ...filters, productId: { operator: Where.ISNULL } },
7486
+ fields: [
7371
7487
  ...bindFields,
7372
7488
  ...(bindFields.includes('price')
7373
7489
  ? [
@@ -7376,11 +7492,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7376
7492
  'fullPrice',
7377
7493
  ]
7378
7494
  : []),
7379
- ] }), optionsParams);
7495
+ ],
7496
+ }, optionsParams);
7380
7497
  }
7381
7498
  async getBySlug(slug, options) {
7382
- var _a, _b, _c, _d, _e, _f;
7383
- if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
7499
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7384
7500
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
7385
7501
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7386
7502
  if (cachedData) {
@@ -7399,70 +7515,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7399
7515
  });
7400
7516
  if (!result.data.length)
7401
7517
  return null;
7402
- const product = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.shift();
7518
+ const product = result?.data?.shift();
7403
7519
  RoundProductPricesHelper.roundProductPrices(product);
7404
- if (((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter) && ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.enabled) && product) {
7520
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7405
7521
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
7406
7522
  await this.cache.cacheAdapter.set({
7407
7523
  key: cacheKey,
7408
7524
  data: serialize(product),
7409
- expirationInSeconds: ((_f = options === null || options === void 0 ? void 0 : options.cache) === null || _f === void 0 ? void 0 : _f.ttl) || this.cache.ttlDefault,
7525
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7410
7526
  });
7411
7527
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7412
7528
  }
7413
7529
  return product;
7414
7530
  }
7415
7531
  async update(params) {
7416
- const _a = omit(params, ['categories', 'rate']), { kitProducts, reviews, id: checkId, metadata } = _a, data = __rest(_a, ["kitProducts", "reviews", "id", "metadata"]);
7532
+ const { kitProducts, reviews, id: checkId, metadata, ...data } = omit(params, ['categories', 'rate']);
7417
7533
  const plainData = this.paramsToPlain({ id: checkId });
7418
7534
  const id = await this.getId(plainData.id);
7419
- const product = await super.update(Object.assign({ id }, data));
7535
+ const product = await super.update({ id, ...data });
7420
7536
  product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
7421
7537
  product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
7422
7538
  product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
7423
7539
  return product;
7424
7540
  }
7425
7541
  async fetchProductReviews(filters, options) {
7426
- var _a, _b, _c, _d, _e;
7427
7542
  const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
7428
7543
  const dependencies = {
7429
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
7544
+ cacheAdapter: this.cache?.cacheAdapter,
7430
7545
  logger: this.logger,
7431
7546
  modelName: this.model.name,
7432
- defaultTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
7547
+ defaultTtl: this.cache?.ttlDefault,
7433
7548
  };
7434
- if (ProductReviewCacheHelper.shouldUseCache((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter, options)) {
7549
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7435
7550
  const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
7436
7551
  if (cachedData)
7437
7552
  return cachedData;
7438
7553
  }
7439
- const limit = (filters === null || filters === void 0 ? void 0 : filters.limit) || 500;
7554
+ const limit = filters?.limit || 500;
7440
7555
  const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
7441
7556
  const reviews = ProductReviewOperationsHelper.processProductsToReviews({
7442
7557
  data,
7443
7558
  getReviewStatus: this.getReviewStatus.bind(this),
7444
7559
  });
7445
7560
  const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
7446
- if (ProductReviewCacheHelper.shouldUseCache((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter, options)) {
7561
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7447
7562
  await ProductReviewCacheHelper.saveToCache({
7448
7563
  key: cacheKey,
7449
7564
  data: filteredReviews,
7450
- ttl: (_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl,
7565
+ ttl: options?.cache?.ttl,
7451
7566
  dependencies,
7452
7567
  });
7453
7568
  }
7454
7569
  return filteredReviews;
7455
7570
  }
7456
7571
  async fetchReviews(status, options) {
7457
- var _a, _b, _c, _d, _e;
7458
7572
  const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
7459
7573
  const dependencies = {
7460
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
7574
+ cacheAdapter: this.cache?.cacheAdapter,
7461
7575
  logger: this.logger,
7462
7576
  modelName: this.model.name,
7463
- defaultTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
7577
+ defaultTtl: this.cache?.ttlDefault,
7464
7578
  };
7465
- if (ProductReviewCacheHelper.shouldUseCache((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter, options)) {
7579
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7466
7580
  const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
7467
7581
  if (cachedData)
7468
7582
  return cachedData;
@@ -7473,18 +7587,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7473
7587
  reviewsFields: this.reviewsFields,
7474
7588
  };
7475
7589
  const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
7476
- if (ProductReviewCacheHelper.shouldUseCache((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter, options)) {
7590
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7477
7591
  await ProductReviewCacheHelper.saveToCache({
7478
7592
  key: cacheKey,
7479
7593
  data: reviews,
7480
- ttl: (_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl,
7594
+ ttl: options?.cache?.ttl,
7481
7595
  dependencies,
7482
7596
  });
7483
7597
  }
7484
7598
  return reviews;
7485
7599
  }
7486
7600
  async findCatalog(params, mainGender, options) {
7487
- const result = await this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign(Object.assign({ hasStock: 'desc' }, (!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' })), omit(params.orderBy, ['hasStock', 'intGender'])) }), options);
7601
+ const result = await this.find({
7602
+ ...params,
7603
+ filters: { ...params.filters, published: true },
7604
+ orderBy: {
7605
+ hasStock: 'desc',
7606
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7607
+ ...omit(params.orderBy, ['hasStock', 'intGender']),
7608
+ },
7609
+ }, options);
7488
7610
  return result;
7489
7611
  }
7490
7612
  async cleanShoppingCountFromIds(ids) {
@@ -7555,17 +7677,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7555
7677
  return plainData.metadata;
7556
7678
  }
7557
7679
  async getId(id) {
7558
- var _a, _b;
7559
7680
  if (!Number.isNaN(+id))
7560
7681
  return id;
7561
7682
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
7562
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
7563
- return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
7683
+ if (data?.[0]?.id)
7684
+ return data?.[0]?.id;
7564
7685
  throw new NotFoundError(`Product with id ${id} not found`);
7565
7686
  }
7566
7687
  async findReviewsByProduct(productId, options) {
7567
- var _a, _b, _c, _d, _e;
7568
- if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
7688
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7569
7689
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7570
7690
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7571
7691
  if (cachedData) {
@@ -7582,13 +7702,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7582
7702
  required: true,
7583
7703
  },
7584
7704
  });
7585
- const reviews = data === null || data === void 0 ? void 0 : data.map((review) => this.bindReviewToModel(review));
7586
- if (((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter) && ((_d = options === null || options === void 0 ? void 0 : options.cache) === null || _d === void 0 ? void 0 : _d.enabled) && reviews) {
7705
+ const reviews = data?.map((review) => this.bindReviewToModel(review));
7706
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
7587
7707
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7588
7708
  await this.cache.cacheAdapter.set({
7589
7709
  key: cacheKey,
7590
7710
  data: serialize(reviews),
7591
- expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
7711
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7592
7712
  });
7593
7713
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7594
7714
  }
@@ -7612,23 +7732,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7612
7732
  async getReviewByPersonId(personId, productId, orderId) {
7613
7733
  const { product_review: data } = await this.query('product_review', this.reviewsFields, {
7614
7734
  where: {
7615
- value: Object.assign({ product_id: { _eq: productId }, person_id: { _eq: personId } }, (orderId && { order_id: { _eq: orderId } })),
7735
+ value: {
7736
+ product_id: { _eq: productId },
7737
+ person_id: { _eq: personId },
7738
+ ...(orderId && { order_id: { _eq: orderId } }),
7739
+ },
7616
7740
  type: 'product_review_bool_exp',
7617
7741
  required: true,
7618
7742
  },
7619
7743
  });
7620
- return (data === null || data === void 0 ? void 0 : data[0]) && this.bindReviewToModel(data[0]);
7744
+ return data?.[0] && this.bindReviewToModel(data[0]);
7621
7745
  }
7622
7746
  async getReviewByAuthorAndEmail(params) {
7623
7747
  const { author, email, productId, orderId } = params;
7624
7748
  const { product_review: data } = await this.query('product_review', this.reviewsFields, {
7625
7749
  where: {
7626
- value: Object.assign({ product_id: { _eq: productId }, author: { _eq: author }, email: { _eq: email } }, (orderId && { order_id: { _eq: orderId } })),
7750
+ value: {
7751
+ product_id: { _eq: productId },
7752
+ author: { _eq: author },
7753
+ email: { _eq: email },
7754
+ ...(orderId && { order_id: { _eq: orderId } }),
7755
+ },
7627
7756
  type: 'product_review_bool_exp',
7628
7757
  required: true,
7629
7758
  },
7630
7759
  });
7631
- return (data === null || data === void 0 ? void 0 : data[0]) && this.bindReviewToModel(data[0]);
7760
+ return data?.[0] && this.bindReviewToModel(data[0]);
7632
7761
  }
7633
7762
  async productVariantFullReport() {
7634
7763
  const dependencies = {
@@ -7777,7 +7906,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
7777
7906
  });
7778
7907
  }
7779
7908
  async getNotificationsReport(params, orderBy, pagination) {
7780
- const query = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.productId && { product_id: { _eq: params.productId } })), (params.ean && { ean: { _eq: params.ean } })), (params.sku && { sku: { _eq: params.sku } })), (params.name && { name: { _iregex: params.name } })), (params.categoryId && { category_id: { _eq: params.categoryId } })), (params.category && { category: { _iregex: params.category } })), (params.reference && { category_reference: { _eq: params.reference } })), (params.emailsCount && { emails_registered: { _eq: params.emailsCount } }));
7909
+ const query = {
7910
+ ...(params.productId && { product_id: { _eq: params.productId } }),
7911
+ ...(params.ean && { ean: { _eq: params.ean } }),
7912
+ ...(params.sku && { sku: { _eq: params.sku } }),
7913
+ ...(params.name && { name: { _iregex: params.name } }),
7914
+ ...(params.categoryId && { category_id: { _eq: params.categoryId } }),
7915
+ ...(params.category && { category: { _iregex: params.category } }),
7916
+ ...(params.reference && { category_reference: { _eq: params.reference } }),
7917
+ ...(params.emailsCount && { emails_registered: { _eq: params.emailsCount } }),
7918
+ };
7781
7919
  const orderByField = {
7782
7920
  [orderBy.field]: orderBy.direction,
7783
7921
  };
@@ -7793,8 +7931,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
7793
7931
  required: true,
7794
7932
  },
7795
7933
  });
7796
- const data = (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
7797
- ? reportStockNotification.slice(pagination === null || pagination === void 0 ? void 0 : pagination.offset, (pagination === null || pagination === void 0 ? void 0 : pagination.offset) + (pagination === null || pagination === void 0 ? void 0 : pagination.limit))
7934
+ const data = pagination?.limit
7935
+ ? reportStockNotification.slice(pagination?.offset, pagination?.offset + pagination?.limit)
7798
7936
  : reportStockNotification;
7799
7937
  return {
7800
7938
  data,
@@ -7810,7 +7948,7 @@ const fieldsConfiguration$1 = [
7810
7948
  productId: {
7811
7949
  columnName: 'main_product_id',
7812
7950
  to: (value) => +value,
7813
- from: (value) => value === null || value === void 0 ? void 0 : value.toString(),
7951
+ from: (value) => value?.toString(),
7814
7952
  },
7815
7953
  },
7816
7954
  { EAN: { columnName: 'ean' } },
@@ -7827,19 +7965,31 @@ const fieldsConfiguration$1 = [
7827
7965
  }),
7828
7966
  bindFindFilter: (sentence) => {
7829
7967
  const filters = Object.values(sentence).shift();
7830
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7831
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7832
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7833
- subscriber_price: filters.subscriberPrice,
7834
- })), ((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7835
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7836
- }));
7968
+ return {
7969
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7970
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7971
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7972
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7973
+ }),
7974
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7975
+ subscriber_price: filters.subscriberPrice,
7976
+ }),
7977
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7978
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7979
+ }),
7980
+ };
7837
7981
  },
7838
- bindPersistData: (priceData) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (((priceData === null || priceData === void 0 ? void 0 : priceData.price) || 0) >= 0 && { price: priceData.price })), (((priceData === null || priceData === void 0 ? void 0 : priceData.fullPrice) || 0) >= 0 && { full_price: priceData.fullPrice })), (((priceData === null || priceData === void 0 ? void 0 : priceData.subscriberDiscountPercentage) || 0) >= 0 && {
7839
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7840
- })), (((priceData === null || priceData === void 0 ? void 0 : priceData.subscriberPrice) || 0) >= 0 && { subscriber_price: priceData.subscriberPrice })), (priceData.fullPriceDiscountPercentage >= 0 && {
7841
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7842
- }))),
7982
+ bindPersistData: (priceData) => ({
7983
+ ...((priceData?.price || 0) >= 0 && { price: priceData.price }),
7984
+ ...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
7985
+ ...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
7986
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7987
+ }),
7988
+ ...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
7989
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
7990
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7991
+ }),
7992
+ }),
7843
7993
  },
7844
7994
  },
7845
7995
  { fullPrice: { columnName: 'full_price' } },
@@ -7851,7 +8001,7 @@ const fieldsConfiguration$1 = [
7851
8001
  stock: {
7852
8002
  columnName: 'stock',
7853
8003
  from: (quantity) => ({ quantity }),
7854
- to: (value) => (isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity),
8004
+ to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
7855
8005
  },
7856
8006
  },
7857
8007
  { hasStock: { columnName: 'has_stock' } },
@@ -7884,41 +8034,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7884
8034
  });
7885
8035
  }
7886
8036
  async get(identifiers) {
7887
- var _a;
7888
8037
  if (!identifiers.id) {
7889
8038
  throw new NotFoundError('Variant ID is required');
7890
8039
  }
7891
8040
  const variant = Number.isNaN(+identifiers.id)
7892
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
8041
+ ? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
7893
8042
  : await super.get(identifiers);
7894
8043
  if (!variant.productId)
7895
8044
  throw new NotFoundError('Variant not found, it is a product');
7896
8045
  return variant;
7897
8046
  }
7898
8047
  async find(params) {
7899
- const _a = params || {}, { filters } = _a, options = __rest(_a, ["filters"]);
7900
- return super.find(Object.assign(Object.assign({}, options), { filters: Object.assign({ productId: { operator: Where.ISNOTNULL } }, filters) }));
8048
+ const { filters, ...options } = params || {};
8049
+ return super.find({ ...options, filters: { productId: { operator: Where.ISNOTNULL }, ...filters } });
7901
8050
  }
7902
8051
  async update(params) {
7903
- const { productId, id: checkId } = params, data = __rest(params, ["productId", "id"]);
8052
+ const { productId, id: checkId, ...data } = params;
7904
8053
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
7905
8054
  if (!dataWithProductId.id) {
7906
8055
  throw new NotFoundError('Variant ID is required for update');
7907
8056
  }
7908
8057
  const id = await this.getId(dataWithProductId.id);
7909
- const product = await super.update(Object.assign({ id }, data));
8058
+ const product = await super.update({ id, ...data });
7910
8059
  if (dataWithProductId.productId) {
7911
8060
  product.productId = dataWithProductId.productId;
7912
8061
  }
7913
8062
  return product;
7914
8063
  }
7915
8064
  async getId(id) {
7916
- var _a, _b;
7917
8065
  if (!Number.isNaN(+id))
7918
8066
  return id;
7919
8067
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
7920
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
7921
- return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
8068
+ if (data?.[0]?.id)
8069
+ return data?.[0]?.id;
7922
8070
  throw new NotFoundError(`Product with id ${id} not found`);
7923
8071
  }
7924
8072
  }
@@ -7949,11 +8097,14 @@ const fieldsConfiguration = [
7949
8097
  bindPersistData: (value) => {
7950
8098
  return {
7951
8099
  brand_condition: value.brand,
7952
- tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
8100
+ tag_condition: value?.tags || [],
7953
8101
  };
7954
8102
  },
7955
8103
  bindFindFilter: (sentence) => {
7956
- return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
8104
+ return {
8105
+ ...(sentence.brand ? { brand_condition: sentence.brand } : {}),
8106
+ ...(sentence.tags ? { tag_condition: sentence.tags } : {}),
8107
+ };
7957
8108
  },
7958
8109
  },
7959
8110
  },
@@ -7965,7 +8116,7 @@ const fieldsConfiguration = [
7965
8116
  bindPersistData: (value) => ({
7966
8117
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
7967
8118
  }),
7968
- from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter)) || [],
8119
+ from: (filters) => filters?.map((filter) => filter?.filter) || [],
7969
8120
  },
7970
8121
  },
7971
8122
  { createdAt: { columnName: 'created_at' } },
@@ -8033,12 +8184,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8033
8184
  this.categoryProductRepository = categoryProductRepository;
8034
8185
  }
8035
8186
  async create(params) {
8036
- var _a;
8037
- const { images, mostRelevants, metadatas } = params, data = __rest(params, ["images", "mostRelevants", "metadatas"]);
8038
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadatas: metadatas || [{ shop: (_a = data.shop) !== null && _a !== void 0 ? _a : null, description: data.description, title: data.name }], mostRelevants: mostRelevants || {
8187
+ const { images, mostRelevants, metadatas, ...data } = params;
8188
+ return super.create({
8189
+ ...data,
8190
+ isWishlist: true,
8191
+ isCollection: true,
8192
+ brandCategory: false,
8193
+ metadatas: metadatas || [{ shop: data.shop ?? null, description: data.description, title: data.name }],
8194
+ mostRelevants: mostRelevants || {
8039
8195
  [Shops.GLAMSHOP]: null,
8040
8196
  [Shops.MENSMARKET]: null,
8041
- }, images: images || {
8197
+ },
8198
+ images: images || {
8042
8199
  [Shops.GLAMSHOP]: {
8043
8200
  brandBanner: null,
8044
8201
  brandBannerMobile: null,
@@ -8049,7 +8206,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8049
8206
  brandBannerMobile: null,
8050
8207
  image: null,
8051
8208
  },
8052
- } }));
8209
+ },
8210
+ });
8053
8211
  }
8054
8212
  async get(identifiers) {
8055
8213
  const data = await super.get(identifiers);
@@ -8058,14 +8216,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8058
8216
  return data;
8059
8217
  }
8060
8218
  async find(params) {
8061
- const { filters } = params, rest = __rest(params, ["filters"]);
8062
- return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: Where.EQUALS, value: true } }) }));
8219
+ const { filters, ...rest } = params;
8220
+ return await super.find({
8221
+ ...rest,
8222
+ filters: {
8223
+ ...filters,
8224
+ isWishlist: { operator: Where.EQUALS, value: true },
8225
+ },
8226
+ });
8063
8227
  }
8064
8228
  async update(params) {
8065
- const _a = omit(params, ['products', 'filters']), { id: checkId, metadatas } = _a, data = __rest(_a, ["id", "metadatas"]);
8229
+ const { id: checkId, metadatas, ...data } = omit(params, ['products', 'filters']);
8066
8230
  const plainData = this.paramsToPlain({ id: checkId });
8067
8231
  const id = plainData.id;
8068
- const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
8232
+ const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
8069
8233
  category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
8070
8234
  return category;
8071
8235
  }
@@ -8128,11 +8292,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8128
8292
  return data;
8129
8293
  }
8130
8294
  async findBfluOrGlamgirlWishlists(params, shops) {
8131
- var _a, _b;
8132
- return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true, shops: { operator: Where.LIKE, value: shops }, personType: (_b = (_a = params.filters) === null || _a === void 0 ? void 0 : _a.personType) !== null && _b !== void 0 ? _b : {
8295
+ return this.find({
8296
+ ...params,
8297
+ filters: {
8298
+ ...params.filters,
8299
+ published: true,
8300
+ shops: { operator: Where.LIKE, value: shops },
8301
+ personType: params.filters?.personType ?? {
8133
8302
  operator: Where.IN,
8134
8303
  value: [PersonTypes.BFLU, PersonTypes.GLAMGIRL],
8135
- } }), orderBy: Object.assign({ personHasPhoto: 'desc' }, omit(params.orderBy, ['personHasPhoto'])) }));
8304
+ },
8305
+ },
8306
+ orderBy: {
8307
+ personHasPhoto: 'desc',
8308
+ ...omit(params.orderBy, ['personHasPhoto']),
8309
+ },
8310
+ });
8136
8311
  }
8137
8312
  getCategoriesForHome() {
8138
8313
  return;
@@ -8340,7 +8515,7 @@ class PagarmePaymentFactoryHelper {
8340
8515
  checkoutId: checkout.id,
8341
8516
  totalPrice: checkout.totalPrice,
8342
8517
  paymentProvider: PaymentProviders.PAGARME,
8343
- transaction: Object.assign(Object.assign({}, resultData), { paidAt: new Date() }),
8518
+ transaction: { ...resultData, paidAt: new Date() },
8344
8519
  });
8345
8520
  return payment;
8346
8521
  }
@@ -8367,7 +8542,6 @@ class PagarmeCardAxiosAdapter {
8367
8542
  this.orderBlockedRepository = orderBlockedRepository;
8368
8543
  }
8369
8544
  async pay(checkout, card) {
8370
- var _a;
8371
8545
  try {
8372
8546
  const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
8373
8547
  checkout,
@@ -8393,7 +8567,7 @@ class PagarmeCardAxiosAdapter {
8393
8567
  if (error instanceof PaymentError) {
8394
8568
  throw error;
8395
8569
  }
8396
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, (_a = error.response) === null || _a === void 0 ? void 0 : _a.data);
8570
+ throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
8397
8571
  }
8398
8572
  }
8399
8573
  async addCard(card) {
@@ -8460,7 +8634,10 @@ class PagarmeCardAxiosAdapter {
8460
8634
  const { data } = await axios({
8461
8635
  method: 'POST',
8462
8636
  url: `${this.credentials.URL}/transactions`,
8463
- data: Object.assign(Object.assign({}, info), { api_key: this.credentials.API_KEY }),
8637
+ data: {
8638
+ ...info,
8639
+ api_key: this.credentials.API_KEY,
8640
+ },
8464
8641
  });
8465
8642
  return data;
8466
8643
  }
@@ -8471,7 +8648,6 @@ class PagarmeCardAxiosAdapter {
8471
8648
  }
8472
8649
  }
8473
8650
  createCardPayment(checkout, card) {
8474
- var _a, _b, _c, _d, _e, _f;
8475
8651
  return {
8476
8652
  api_key: this.credentials.API_KEY,
8477
8653
  amount: Math.floor(checkout.totalPrice * 100),
@@ -8498,14 +8674,14 @@ class PagarmeCardAxiosAdapter {
8498
8674
  name: checkout.user.displayName,
8499
8675
  address: {
8500
8676
  country: 'br',
8501
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
8502
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
8503
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
8504
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
8505
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
8677
+ state: checkout.billingAddress ? checkout.billingAddress.state : checkout.shippingAddress?.state,
8678
+ city: checkout.billingAddress ? checkout.billingAddress.city : checkout.shippingAddress?.city,
8679
+ neighborhood: checkout.billingAddress ? checkout.billingAddress.district : checkout.shippingAddress?.district,
8680
+ street: checkout.billingAddress ? checkout.billingAddress.street : checkout.shippingAddress?.street,
8681
+ street_number: checkout.billingAddress ? checkout.billingAddress.number : checkout.shippingAddress?.number,
8506
8682
  zipcode: checkout.billingAddress
8507
8683
  ? checkout.billingAddress.zip.replace('-', '')
8508
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
8684
+ : checkout.shippingAddress?.zip.replace('-', ''),
8509
8685
  },
8510
8686
  },
8511
8687
  items: checkout.lineItems.map((item) => {
@@ -8527,7 +8703,6 @@ class PagarmePixAxiosAdapter {
8527
8703
  this.paymentRepository = paymentRepository;
8528
8704
  }
8529
8705
  async pay(checkout) {
8530
- var _a;
8531
8706
  try {
8532
8707
  const payload = this.createPixPayment(checkout);
8533
8708
  const result = await axios({
@@ -8551,7 +8726,7 @@ class PagarmePixAxiosAdapter {
8551
8726
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
8552
8727
  checkoutId: checkout.id,
8553
8728
  userEmail: checkout.user.email,
8554
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
8729
+ info: error.response?.data,
8555
8730
  });
8556
8731
  }
8557
8732
  }