@infrab4a/connect 5.0.0-alpha.9 → 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.cjs.js CHANGED
@@ -124,25 +124,15 @@ class PaymentProviderFactory {
124
124
  }
125
125
  }
126
126
 
127
- /**
128
- * Este arquivo define funções para resolver dependências circulares
129
- * em ambiente ESM, onde não podemos usar require()
130
- */
131
- // Armazenamento global para classes registradas
132
127
  const registry = new Map();
133
- // Registrar uma classe na resolução de dependências circulares
134
128
  function registerClass(name, classConstructor) {
135
129
  registry.set(name, classConstructor);
136
130
  }
137
- // Obter uma classe registrada
138
131
  function getClass(name) {
139
132
  return registry.get(name);
140
133
  }
141
- // Função de resolução para class-transformer
142
134
  function resolveClass(name) {
143
135
  return () => {
144
- // Forçamos o retorno de uma função que retorna a classe
145
- // ao invés da classe diretamente para evitar problemas com o decorator
146
136
  return getClass(name);
147
137
  };
148
138
  }
@@ -216,7 +206,7 @@ class ReflectHelper {
216
206
  return Reflect.getMetadata(key, target, property) || null;
217
207
  }
218
208
  }
219
- catch (_a) {
209
+ catch {
220
210
  return null;
221
211
  }
222
212
  }
@@ -526,7 +516,7 @@ function Debug(opts) {
526
516
 
527
517
  const ASYNC_IDENTIFIER = 'async';
528
518
  function Log(options = {}) {
529
- return Trace(Object.assign({ level: 'log' }, options));
519
+ return Trace({ level: 'log', ...options });
530
520
  }
531
521
  function Trace(options = {}) {
532
522
  return function (target, propertyKey, propertyDescriptor) {
@@ -626,7 +616,7 @@ class BaseModel {
626
616
  get identifier() {
627
617
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
628
618
  const data = this;
629
- return fields.reduce((object, field) => (Object.assign(Object.assign({}, object), { [field]: data[field] })), {});
619
+ return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
630
620
  }
631
621
  get identifiersFields() {
632
622
  return this.constructor.identifiersFields;
@@ -691,8 +681,7 @@ class Category extends BaseModel {
691
681
  return ['id'];
692
682
  }
693
683
  get glamImages() {
694
- var _a;
695
- return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[exports.Shops.GLAMSHOP])
684
+ return this.images?.[exports.Shops.GLAMSHOP]
696
685
  ? this.images[exports.Shops.GLAMSHOP]
697
686
  : {
698
687
  brandBanner: null,
@@ -701,8 +690,7 @@ class Category extends BaseModel {
701
690
  };
702
691
  }
703
692
  get mensImages() {
704
- var _a;
705
- return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[exports.Shops.MENSMARKET])
693
+ return this.images?.[exports.Shops.MENSMARKET]
706
694
  ? this.images[exports.Shops.MENSMARKET]
707
695
  : {
708
696
  brandBanner: null,
@@ -717,8 +705,7 @@ class Category extends BaseModel {
717
705
  return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
718
706
  }
719
707
  getMostRelevantByShop(shop) {
720
- var _a;
721
- return ((_a = this.mostRelevants) === null || _a === void 0 ? void 0 : _a[shop]) || [];
708
+ return this.mostRelevants?.[shop] || [];
722
709
  }
723
710
  }
724
711
  tslib.__decorate([
@@ -1451,10 +1438,18 @@ class Authentication {
1451
1438
  return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
1452
1439
  }
1453
1440
  async createsUserByCredential(user) {
1454
- var _a, _b;
1455
- const [firstName, lastName] = (_b = (_a = user.displayName) === null || _a === void 0 ? void 0 : _a.split(/\s/)) !== null && _b !== void 0 ? _b : [];
1456
- const person = User.toInstance(Object.assign(Object.assign({}, user), { cpf: '', birthday: new Date(), firstName,
1457
- lastName, acceptsNewsletter: false, area: exports.Area.Transactional, officePosition: exports.OfficePosition.Intern, type: exports.UserType.Collaborator }));
1441
+ const [firstName, lastName] = user.displayName?.split(/\s/) ?? [];
1442
+ const person = User.toInstance({
1443
+ ...user,
1444
+ cpf: '',
1445
+ birthday: new Date(),
1446
+ firstName,
1447
+ lastName,
1448
+ acceptsNewsletter: false,
1449
+ area: exports.Area.Transactional,
1450
+ officePosition: exports.OfficePosition.Intern,
1451
+ type: exports.UserType.Collaborator,
1452
+ });
1458
1453
  return this.userRepository.create(person);
1459
1454
  }
1460
1455
  }
@@ -1503,8 +1498,15 @@ class Register {
1503
1498
  password: params.password,
1504
1499
  });
1505
1500
  delete params.password;
1506
- const user = await this.userRepository.create(Object.assign(Object.assign({}, params), { id: auth.id, email,
1507
- displayName, type: exports.UserType.B2C, dateCreated: new Date(), dateModified: new Date() }));
1501
+ const user = await this.userRepository.create({
1502
+ ...params,
1503
+ id: auth.id,
1504
+ email,
1505
+ displayName,
1506
+ type: exports.UserType.B2C,
1507
+ dateCreated: new Date(),
1508
+ dateModified: new Date(),
1509
+ });
1508
1510
  return user;
1509
1511
  }
1510
1512
  }
@@ -1698,8 +1700,7 @@ class AntifraudBankSlipService {
1698
1700
  this.MAX_ORDER_VALUE = 5000;
1699
1701
  }
1700
1702
  async validate(checkout) {
1701
- var _a, _b;
1702
- if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
1703
+ if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
1703
1704
  await this.orderBlockedRepository.createBlockedOrderOrPayment({
1704
1705
  checkout,
1705
1706
  blockType: 'Boleto not authorized',
@@ -1710,7 +1711,7 @@ class AntifraudBankSlipService {
1710
1711
  checkoutId: checkout.id,
1711
1712
  userEmail: checkout.user.email,
1712
1713
  info: {
1713
- isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
1714
+ isSubscriber: checkout.user?.isSubscriber,
1714
1715
  subtotal: checkout.subTotalPrice,
1715
1716
  total: checkout.totalPrice,
1716
1717
  },
@@ -1734,14 +1735,13 @@ class AntifraudCardService {
1734
1735
  return true;
1735
1736
  }
1736
1737
  async validateBlockedOrderAttempts(checkout, card) {
1737
- var _a;
1738
1738
  const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
1739
1739
  if (!isValid) {
1740
1740
  throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
1741
1741
  checkoutId: checkout.id,
1742
1742
  userEmail: checkout.user.email,
1743
1743
  info: {
1744
- isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
1744
+ isSubscriber: checkout.user?.isSubscriber,
1745
1745
  subtotal: checkout.subTotalPrice,
1746
1746
  total: checkout.totalPrice,
1747
1747
  },
@@ -1749,14 +1749,13 @@ class AntifraudCardService {
1749
1749
  }
1750
1750
  }
1751
1751
  async validateDayAndWeekOrderLimits(checkout, card) {
1752
- var _a;
1753
1752
  const isValid = await this.verifyDayAndWeekOrders(checkout, card);
1754
1753
  if (!isValid) {
1755
1754
  throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
1756
1755
  checkoutId: checkout.id,
1757
1756
  userEmail: checkout.user.email,
1758
1757
  info: {
1759
- isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
1758
+ isSubscriber: checkout.user?.isSubscriber,
1760
1759
  subtotal: checkout.subTotalPrice,
1761
1760
  total: checkout.totalPrice,
1762
1761
  },
@@ -1785,17 +1784,16 @@ class AntifraudCardService {
1785
1784
  return { day, endOfDay };
1786
1785
  }
1787
1786
  async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
1788
- var _a, _b, _c, _d;
1789
1787
  const { day, endOfDay } = dateRange;
1790
1788
  const dateFilter = [
1791
1789
  { operator: exports.Where.GTE, value: new Date(day) },
1792
1790
  { operator: exports.Where.LTE, value: new Date(endOfDay) },
1793
1791
  ];
1794
1792
  const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
1795
- this.getBlockedOrdersByCpf((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf, dateFilter),
1796
- this.getBlockedOrdersByEmail((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email, dateFilter),
1797
- this.getBlockedOrdersByZip((_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip, dateFilter),
1798
- this.getBlockedOrdersByPhone((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone, dateFilter),
1793
+ this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
1794
+ this.getBlockedOrdersByEmail(checkout.user?.email, dateFilter),
1795
+ this.getBlockedOrdersByZip(checkout.shippingAddress?.zip, dateFilter),
1796
+ this.getBlockedOrdersByPhone(checkout.user?.phone, dateFilter),
1799
1797
  ]);
1800
1798
  return {
1801
1799
  ordersBlockedWithCpf,
@@ -1852,18 +1850,15 @@ class AntifraudCardService {
1852
1850
  return ordersBlockedWithCpf.concat(blockedUniqueEmails).concat(blockedUniqueCeps).concat(blockedUniquePhone).length;
1853
1851
  }
1854
1852
  filterUniqueEmailBlocked(ordersBlockedWithEmail, checkout) {
1855
- return ordersBlockedWithEmail.filter((e) => { var _a; return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf); });
1853
+ return ordersBlockedWithEmail.filter((e) => e.customer.cpf !== checkout.user?.cpf);
1856
1854
  }
1857
1855
  filterUniqueZipBlocked(ordersBlockedWithCep, checkout) {
1858
- 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); });
1856
+ return ordersBlockedWithCep.filter((e) => e.customer.cpf !== checkout.user?.cpf && e.customer.email !== checkout.user?.email);
1859
1857
  }
1860
1858
  filterUniquePhoneBlocked(ordersBlockedWithPhone, checkout) {
1861
- return ordersBlockedWithPhone.filter((e) => {
1862
- var _a, _b, _c, _d, _e, _f;
1863
- return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
1864
- e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
1865
- ((_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());
1866
- });
1859
+ return ordersBlockedWithPhone.filter((e) => e.customer.cpf !== checkout.user?.cpf &&
1860
+ e.customer.email !== checkout.user?.email &&
1861
+ e.customer.shippingAddress?.zip?.toString() !== checkout.shippingAddress?.zip?.toString());
1867
1862
  }
1868
1863
  async createBlockedOrderRecord(params) {
1869
1864
  const { checkout, card, reason, key, period } = params;
@@ -1884,12 +1879,11 @@ class AntifraudCardService {
1884
1879
  return isWeekLimitValid;
1885
1880
  }
1886
1881
  buildValidationParams(checkout, card) {
1887
- var _a, _b, _c, _d;
1888
1882
  return {
1889
- cpf: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf,
1890
- email: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email,
1891
- phone: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.phone,
1892
- zip: (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.zip,
1883
+ cpf: checkout.user?.cpf,
1884
+ email: checkout.user?.email,
1885
+ phone: checkout.user?.phone,
1886
+ zip: checkout.shippingAddress?.zip,
1893
1887
  card,
1894
1888
  };
1895
1889
  }
@@ -1914,7 +1908,7 @@ class AntifraudCardService {
1914
1908
  async checkOrderLimitsAndBlock(params) {
1915
1909
  const { checkout, orderCounts, limit, period } = params;
1916
1910
  for (const key in orderCounts) {
1917
- if (orderCounts[key] > limit) {
1911
+ if (orderCounts[key] >= limit) {
1918
1912
  await this.createBlockedOrderRecord({
1919
1913
  checkout,
1920
1914
  card: null,
@@ -1928,18 +1922,20 @@ class AntifraudCardService {
1928
1922
  return true;
1929
1923
  }
1930
1924
  async validateOrdersByRange(params, range) {
1931
- const { cpf, email, phone, zip } = params;
1932
- const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip] = await Promise.all([
1925
+ const { cpf, email, phone, zip, card } = params;
1926
+ const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip, ordersByCard] = await Promise.all([
1933
1927
  this.countOrdersByField({ property: 'user', field: 'cpf', value: cpf, range }),
1934
1928
  this.countOrdersByField({ property: 'user', field: 'email', value: email, range }),
1935
1929
  this.countOrdersByField({ property: 'user', field: 'phone', value: phone, range }),
1936
1930
  this.countOrdersByField({ property: 'shippingAddress', field: 'zip', value: zip, range }),
1931
+ this.countOrdersByField({ property: 'payment', field: 'card.id', value: card.cardId, range }),
1937
1932
  ]);
1938
1933
  return {
1939
1934
  cpf: ordersCpf,
1940
1935
  email: ordersByEmail,
1941
1936
  phone: ordersByPhone,
1942
1937
  zip: ordersByZip,
1938
+ card: ordersByCard,
1943
1939
  };
1944
1940
  }
1945
1941
  async countOrdersByField(params) {
@@ -1953,8 +1949,8 @@ class AntifraudCardService {
1953
1949
  { operator: exports.Where.LTE, value: range.lastDate },
1954
1950
  ],
1955
1951
  };
1956
- const docs = await (await this.orderRepository.find({ filters })).count;
1957
- return docs;
1952
+ const { count } = await this.orderRepository.find({ filters });
1953
+ return count;
1958
1954
  }
1959
1955
  getDateRange(range = 'day') {
1960
1956
  switch (range) {
@@ -2025,10 +2021,9 @@ class GlampointsPaymentService {
2025
2021
  return payment;
2026
2022
  }
2027
2023
  async rewardByOrder(order, user) {
2028
- var _a;
2029
2024
  try {
2030
2025
  const points = order.lineItems.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
2031
- const hasGlambeauty = (_a = order.lineItems) === null || _a === void 0 ? void 0 : _a.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
2026
+ const hasGlambeauty = order.lineItems?.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
2032
2027
  const result = await axios__default["default"]({
2033
2028
  method: 'POST',
2034
2029
  url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
@@ -2289,7 +2284,7 @@ class AdyenPaymentFactoryHelper {
2289
2284
  checkoutId: checkout.id,
2290
2285
  totalPrice: checkout.totalPrice,
2291
2286
  paymentProvider: 'adyen',
2292
- transaction: Object.assign(Object.assign({}, adyenResponse), { status: 'paid' }),
2287
+ transaction: { ...adyenResponse, status: 'paid' },
2293
2288
  });
2294
2289
  return paymentRepository.create(paymentData);
2295
2290
  }
@@ -2300,7 +2295,7 @@ class AdyenPaymentOperationsHelper {
2300
2295
  return {
2301
2296
  amount: {
2302
2297
  currency: 'BRL',
2303
- value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2298
+ value: (checkout?.totalPrice || 0) * 100,
2304
2299
  },
2305
2300
  paymentMethod: {
2306
2301
  type: 'scheme',
@@ -2385,7 +2380,11 @@ class RestCacheAdapter {
2385
2380
  this.logger = new DebugHelper('RestCacheAdapter');
2386
2381
  this.client = axios__default["default"].create({
2387
2382
  baseURL: config.baseURL,
2388
- headers: Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (lodash.isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` })), (lodash.isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey })),
2383
+ headers: {
2384
+ 'Content-Type': 'application/json',
2385
+ ...(lodash.isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
2386
+ ...(lodash.isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey }),
2387
+ },
2389
2388
  });
2390
2389
  }
2391
2390
  async set(options) {
@@ -2641,7 +2640,10 @@ class ElasticSearchResultProcessorHelper {
2641
2640
  });
2642
2641
  }
2643
2642
  static transformHitsToProducts(hits) {
2644
- return hits.map((hit) => (Object.assign(Object.assign({}, hit._source), { stock: hit._source.stock.quantity })));
2643
+ return hits.map((hit) => ({
2644
+ ...hit._source,
2645
+ stock: hit._source.stock.quantity,
2646
+ }));
2645
2647
  }
2646
2648
  }
2647
2649
 
@@ -2784,11 +2786,11 @@ class FirestoreDataConverterHelper {
2784
2786
  return (data &&
2785
2787
  !Array.isArray(data) &&
2786
2788
  typeof data === 'object' &&
2787
- (data === null || data === void 0 ? void 0 : data.constructor.name) !== 'Timestamp' &&
2789
+ data?.constructor.name !== 'Timestamp' &&
2788
2790
  !('seconds' in data));
2789
2791
  }
2790
2792
  static convertToDate(data, keyName) {
2791
- if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'Timestamp')
2793
+ if (data?.constructor.name === 'Timestamp')
2792
2794
  return data.toDate();
2793
2795
  if (data && typeof data === 'object' && 'seconds' in data)
2794
2796
  return new Date(data.seconds * 1000);
@@ -2833,7 +2835,7 @@ class FirestoreModelConverterHelper {
2833
2835
  }
2834
2836
  buildToFirestoreConverter() {
2835
2837
  return (data) => {
2836
- const plain = (data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data;
2838
+ const plain = data?.toPlain ? data.toPlain() : data;
2837
2839
  return FirestoreModelConverterHelper.omitByRecursivelyInPlace(plain, (value) => value === undefined);
2838
2840
  };
2839
2841
  }
@@ -2843,7 +2845,7 @@ class FirestoreModelConverterHelper {
2843
2845
  const data = snap.data();
2844
2846
  const ids = { id: snap.id };
2845
2847
  const bindedData = FirestoreDataConverterHelper.bindAllDateFromObject(data);
2846
- return this.model.toInstance(Object.assign(Object.assign({}, bindedData), ids));
2848
+ return this.model.toInstance({ ...bindedData, ...ids });
2847
2849
  }
2848
2850
  catch (error) {
2849
2851
  this.handleConversionError(snap.id, snap.data(), error);
@@ -2911,18 +2913,17 @@ const withHelpers = (MixinBase) => {
2911
2913
  class AttributeOptionHelper {
2912
2914
  }
2913
2915
  AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
2914
- var _a;
2915
2916
  if (fields.includes(attributeName))
2916
2917
  return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
2917
2918
  const field = fields.find((columnOption) => lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
2918
- const fieldOption = (_a = is(field)) === null || _a === void 0 ? void 0 : _a[attributeName];
2919
+ const fieldOption = is(field)?.[attributeName];
2919
2920
  if (lodash.isNil(fieldOption))
2920
2921
  return { columnName: attributeName.toString(), attributeName };
2921
2922
  if (Array.isArray(fieldOption))
2922
2923
  return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
2923
- return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
2924
+ return { attributeName, columnName: attributeName.toString(), ...fieldOption };
2924
2925
  };
2925
- AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.columnName);
2926
+ AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
2926
2927
  AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
2927
2928
  if (fields.includes(columnName))
2928
2929
  return { columnName, attributeName: columnName };
@@ -2930,13 +2931,17 @@ AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
2930
2931
  if (!lodash.isObject(field))
2931
2932
  return false;
2932
2933
  const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
2933
- return AttributeOptionHelper.CheckIsColumnOption(columnOption) && (columnOption === null || columnOption === void 0 ? void 0 : columnOption.columnName) === columnName;
2934
+ return AttributeOptionHelper.CheckIsColumnOption(columnOption) && columnOption?.columnName === columnName;
2934
2935
  }) || {});
2935
2936
  const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
2936
- const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
2937
+ const fieldOption = field?.[attributeName];
2937
2938
  if (Array.isArray(fieldOption))
2938
2939
  return { attributeName: attributeName, fields: fieldOption };
2939
- return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
2940
+ return {
2941
+ attributeName: attributeName || columnName,
2942
+ columnName,
2943
+ ...fieldOption,
2944
+ };
2940
2945
  };
2941
2946
 
2942
2947
  var HasuraGraphQLWhere;
@@ -2974,7 +2979,7 @@ var HasuraGraphQLColumnType;
2974
2979
 
2975
2980
  class FilterOptionHelper {
2976
2981
  }
2977
- FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
2982
+ FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
2978
2983
  FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
2979
2984
  if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
2980
2985
  return filter;
@@ -3035,25 +3040,37 @@ class BindFilterQueryHelper {
3035
3040
  BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
3036
3041
  const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
3037
3042
  if (!columnOption.bindFindFilter)
3038
- return Object.assign(Object.assign({}, variables), {
3039
- [columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
3040
- });
3043
+ return {
3044
+ ...variables,
3045
+ ...{
3046
+ [columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
3047
+ },
3048
+ };
3041
3049
  const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
3042
- return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce((variablesList, columnName) => (Object.assign(Object.assign({}, variablesList), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields) })), {}));
3050
+ return {
3051
+ ...variables,
3052
+ ...Object.keys(builtFilter).reduce((variablesList, columnName) => ({
3053
+ ...variablesList,
3054
+ [columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields),
3055
+ }), {}),
3056
+ };
3043
3057
  }, {});
3044
3058
  BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
3045
3059
  const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
3046
3060
  const isNestedField = !Array.isArray(options) &&
3047
3061
  lodash.isObject(options) &&
3048
- lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) &&
3049
- lodash.isNil(options === null || options === void 0 ? void 0 : options.value) &&
3050
- lodash.isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to);
3062
+ lodash.isNil(options?.operator) &&
3063
+ lodash.isNil(options?.value) &&
3064
+ lodash.isNil(fieldSentenceOptions?.to);
3051
3065
  if (isNestedField)
3052
3066
  return Object.keys(options).reduce((variables, key) => {
3053
- const fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
3067
+ const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
3054
3068
  const columnName = fieldOptions.columnName;
3055
3069
  const columnFields = fieldOptions.fields;
3056
- 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) });
3070
+ return {
3071
+ ...variables,
3072
+ [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
3073
+ };
3057
3074
  }, {});
3058
3075
  if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
3059
3076
  return {
@@ -3062,7 +3079,10 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
3062
3079
  if (!Array.isArray(options) && lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
3063
3080
  options = Object.values(options)[0];
3064
3081
  return Array.isArray(options)
3065
- ? options.reduce((whereSentence, option) => (Object.assign(Object.assign({}, whereSentence), BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions))), {})
3082
+ ? options.reduce((whereSentence, option) => ({
3083
+ ...whereSentence,
3084
+ ...BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions),
3085
+ }), {})
3066
3086
  : BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
3067
3087
  };
3068
3088
  BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
@@ -3078,14 +3098,14 @@ BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOption
3078
3098
  : options.operator === exports.Where.LIKE && options.ignoreCase
3079
3099
  ? HasuraGraphQLWhere.ILIKE
3080
3100
  : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
3081
- Object.keys(exports.Where).find((operator) => exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))]
3101
+ Object.keys(exports.Where).find((operator) => exports.Where[operator] === options?.operator))]
3082
3102
  : HasuraGraphQLWhere.EQUALS;
3083
3103
  BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === exports.Where.IN
3084
3104
  ? HasuraGraphQLWhere.JSON_CONTAINS
3085
3105
  : options.operator === exports.Where.LIKE
3086
3106
  ? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
3087
3107
  : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
3088
- Object.keys(exports.Where).find((operator) => exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))];
3108
+ Object.keys(exports.Where).find((operator) => exports.Where[operator] === options?.operator))];
3089
3109
 
3090
3110
  class CacheKeyGeneratorHelper {
3091
3111
  static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
@@ -3100,7 +3120,8 @@ class GraphQLFieldHelper {
3100
3120
  }
3101
3121
  GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
3102
3122
  GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
3103
- return fields === null || fields === void 0 ? void 0 : fields.map((field) => {
3123
+ return fields
3124
+ ?.map((field) => {
3104
3125
  if (lodash.isString(field))
3105
3126
  return field.toString();
3106
3127
  if (field === 'affected_rows')
@@ -3115,41 +3136,55 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
3115
3136
  if (isNestedField)
3116
3137
  return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
3117
3138
  return fieldValue.columnName;
3118
- }).filter((field) => !!field);
3139
+ })
3140
+ .filter((field) => !!field);
3119
3141
  };
3120
3142
  GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
3121
3143
  const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
3122
3144
  if (!!attributeFields && Array.isArray(attributeFields)) {
3123
3145
  if (Array.isArray(data[columnName]))
3124
- return Object.assign(Object.assign({}, result), { [attributeName]: from
3146
+ return {
3147
+ ...result,
3148
+ [attributeName]: from
3125
3149
  ? from(data[columnName], data)
3126
- : is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)) });
3150
+ : is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)),
3151
+ };
3127
3152
  if (lodash.isObject(data[columnName]))
3128
- return Object.assign(Object.assign({}, result), { [attributeName]: from
3153
+ return {
3154
+ ...result,
3155
+ [attributeName]: from
3129
3156
  ? from(data[columnName])
3130
- : GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields) });
3157
+ : GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields),
3158
+ };
3131
3159
  }
3132
3160
  if (from)
3133
- return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
3134
- return Object.assign(Object.assign({}, result), { [attributeName]: lodash.isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName] });
3161
+ return { ...result, [attributeName]: from(data[columnName], data) };
3162
+ return {
3163
+ ...result,
3164
+ [attributeName]: lodash.isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
3165
+ };
3135
3166
  }, {});
3136
3167
  GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
3137
- var _a;
3138
- const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
3168
+ const data = instance.toPlain?.() || instance;
3139
3169
  return Object.keys(data).reduce((result, attributeName) => {
3140
3170
  const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
3141
3171
  if (bindPersistData)
3142
- return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
3172
+ return {
3173
+ ...result,
3174
+ ...bindPersistData(data[attributeName], instance),
3175
+ };
3143
3176
  if (lodash.isNil(columnName))
3144
3177
  return result;
3145
3178
  if (!!foreignKeyColumn &&
3146
3179
  !lodash.isEmpty(foreignKeyColumn) &&
3147
- !Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = is(data[attributeName])) === null || _a === void 0 ? void 0 : _a[key]); }).length)
3180
+ !Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
3148
3181
  return Object.keys(foreignKeyColumn).reduce((object, current) => {
3149
- var _a;
3150
3182
  const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
3151
- return Object.assign(Object.assign({}, object), { [foreignColumnName]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] });
3152
- }, Object.assign({}, result));
3183
+ return {
3184
+ ...object,
3185
+ [foreignColumnName]: data[attributeName]?.[current],
3186
+ };
3187
+ }, { ...result });
3153
3188
  if (update &&
3154
3189
  lodash.isObject(data[attributeName]) &&
3155
3190
  !lodash.isNil(attributeFields) &&
@@ -3161,19 +3196,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
3161
3196
  const converted = !lodash.isNil(columnName) && to
3162
3197
  ? to(instance[attributeName], instance)
3163
3198
  : data[attributeName];
3164
- return Object.assign(Object.assign({}, result), (converted !== undefined
3165
- ? {
3166
- [columnName]: {
3167
- data: instance[attributeName] instanceof BaseModel
3168
- ? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
3169
- : converted,
3170
- },
3171
- }
3172
- : {}));
3199
+ return {
3200
+ ...result,
3201
+ ...(converted !== undefined
3202
+ ? {
3203
+ [columnName]: {
3204
+ data: instance[attributeName] instanceof BaseModel
3205
+ ? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
3206
+ : converted,
3207
+ },
3208
+ }
3209
+ : {}),
3210
+ };
3173
3211
  }
3174
3212
  if (to)
3175
- return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
3176
- return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
3213
+ return {
3214
+ ...result,
3215
+ [columnName]: to(instance[attributeName], instance),
3216
+ };
3217
+ return { ...result, [columnName]: data[attributeName] };
3177
3218
  }, {});
3178
3219
  };
3179
3220
  GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
@@ -3231,13 +3272,17 @@ class MD5GeneratorHelper {
3231
3272
 
3232
3273
  class HasuraAuthHelper {
3233
3274
  static buildHeaders(authOptions) {
3234
- var _a;
3235
- return Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (lodash.isNil(authOptions === null || authOptions === void 0 ? void 0 : authOptions.authToken) ? {} : { Authorization: authOptions === null || authOptions === void 0 ? void 0 : authOptions.authToken })), (lodash.isNil(authOptions === null || authOptions === void 0 ? void 0 : authOptions.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions === null || authOptions === void 0 ? void 0 : authOptions.adminSecret })), (lodash.isNil(authOptions === null || authOptions === void 0 ? void 0 : authOptions.authRole)
3236
- ? {}
3237
- : {
3238
- 'X-Hasura-Role': authOptions.authRole.role,
3239
- 'X-Hasura-User-Id': (_a = authOptions === null || authOptions === void 0 ? void 0 : authOptions.authRole) === null || _a === void 0 ? void 0 : _a.userId,
3240
- }));
3275
+ return {
3276
+ 'Content-Type': 'application/json',
3277
+ ...(lodash.isNil(authOptions?.authToken) ? {} : { Authorization: authOptions?.authToken }),
3278
+ ...(lodash.isNil(authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions?.adminSecret }),
3279
+ ...(lodash.isNil(authOptions?.authRole)
3280
+ ? {}
3281
+ : {
3282
+ 'X-Hasura-Role': authOptions.authRole.role,
3283
+ 'X-Hasura-User-Id': authOptions?.authRole?.userId,
3284
+ }),
3285
+ };
3241
3286
  }
3242
3287
  }
3243
3288
 
@@ -3327,17 +3372,21 @@ class HasuraGraphQLOperationsHelper {
3327
3372
  return this.executeFetch({ query: resultQuery, operationParams });
3328
3373
  }
3329
3374
  static async executeQuery(params) {
3330
- var _a, _b, _c, _d;
3331
3375
  const { operation, fields, variables, operationParams, buildHasuraQueryFields } = params;
3332
3376
  const builded = buildHasuraQueryFields({ operation, fields, variables });
3333
- 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;
3377
+ const intercepted = (await operationParams.interceptors?.request?.(builded)) || builded;
3334
3378
  const resultQuery = HasuraQueryBuilderHelper.buildQuery(intercepted);
3335
3379
  const result = await this.executeFetch({ query: resultQuery, operationParams });
3336
- 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;
3380
+ return (await operationParams.interceptors?.response?.(result, intercepted)) || result;
3337
3381
  }
3338
3382
  static async executeFetch(params) {
3339
3383
  const { query, operationParams } = params;
3340
- return HasuraRequestHelper.fetch(Object.assign(Object.assign({}, query), { endpoint: operationParams.endpoint, headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions), logger: operationParams.logger }));
3384
+ return HasuraRequestHelper.fetch({
3385
+ ...query,
3386
+ endpoint: operationParams.endpoint,
3387
+ headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions),
3388
+ logger: operationParams.logger,
3389
+ });
3341
3390
  }
3342
3391
  }
3343
3392
 
@@ -3351,12 +3400,10 @@ class HasuraColumnHelper {
3351
3400
  const columnOptions = Object.values(field).shift();
3352
3401
  return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
3353
3402
  columnOptions.foreignKeyColumn && [
3354
- ...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => { var _a; return (_a = AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)) === null || _a === void 0 ? void 0 : _a.columnName; }),
3403
+ ...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)?.columnName),
3355
3404
  {
3356
- [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => {
3357
- var _a;
3358
- return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || foreignKeyField;
3359
- }),
3405
+ [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
3406
+ ?.columnName || foreignKeyField),
3360
3407
  },
3361
3408
  ]);
3362
3409
  })
@@ -3381,7 +3428,7 @@ class HasuraCreateOperationsHelper {
3381
3428
  const { model } = params;
3382
3429
  params.repository.logger = DebugHelper.from(params.repository, 'create');
3383
3430
  const instance = model.toInstance(data);
3384
- const newData = await this.executeSave(Object.assign(Object.assign({}, params), { data: instance }));
3431
+ const newData = await this.executeSave({ ...params, data: instance });
3385
3432
  return model.toInstance(newData);
3386
3433
  }
3387
3434
  static async executeSave(params) {
@@ -3395,14 +3442,14 @@ class HasuraCreateOperationsHelper {
3395
3442
  },
3396
3443
  });
3397
3444
  const convertedResult = repository.convertDataFromHasura(result[insertGraphQLOperation]);
3398
- return Object.assign(Object.assign({}, data.toPlain()), convertedResult.toPlain());
3445
+ return { ...data.toPlain(), ...convertedResult.toPlain() };
3399
3446
  }
3400
3447
  }
3401
3448
 
3402
3449
  class HasuraCacheOperationsHelper {
3403
3450
  static async removeCacheData(cache, params) {
3404
3451
  const { model, identifiers, logger } = params;
3405
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
3452
+ if (!cache?.cacheAdapter)
3406
3453
  return;
3407
3454
  const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
3408
3455
  await cache.cacheAdapter.remove(cacheKey);
@@ -3422,13 +3469,16 @@ class HasuraDeleteVariablesHelper {
3422
3469
  if (lodash.isNil(instance.identifier[identifierBinded]))
3423
3470
  return ids;
3424
3471
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3425
- const value = (columnOption === null || columnOption === void 0 ? void 0 : columnOption.to(identifiers[identifier], instance)) ||
3472
+ const value = columnOption?.to(identifiers[identifier], instance) ||
3426
3473
  identifiers[identifier];
3427
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
3474
+ return {
3475
+ ...ids,
3476
+ [columnOption.columnName]: {
3428
3477
  type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
3429
3478
  value,
3430
3479
  required: true,
3431
- } });
3480
+ },
3481
+ };
3432
3482
  }, {});
3433
3483
  }
3434
3484
  }
@@ -3466,16 +3516,15 @@ class HasuraFindBindingHelper {
3466
3516
  ], []);
3467
3517
  }
3468
3518
  static bindAggregateAttributes(aggregates, fields) {
3469
- var _a, _b;
3470
3519
  return [
3471
- ...(((_a = aggregates === null || aggregates === void 0 ? void 0 : aggregates.minimal) === null || _a === void 0 ? void 0 : _a.length)
3520
+ ...(aggregates?.minimal?.length
3472
3521
  ? [
3473
3522
  {
3474
3523
  min: this.bindAttributesToColumns(aggregates.minimal, fields),
3475
3524
  },
3476
3525
  ]
3477
3526
  : []),
3478
- ...(((_b = aggregates === null || aggregates === void 0 ? void 0 : aggregates.maximum) === null || _b === void 0 ? void 0 : _b.length)
3527
+ ...(aggregates?.maximum?.length
3479
3528
  ? [
3480
3529
  {
3481
3530
  max: this.bindAttributesToColumns(aggregates.maximum, fields),
@@ -3502,7 +3551,7 @@ class HasuraFindBindingHelper {
3502
3551
  });
3503
3552
  if (typeof fieldOption === 'object' && fieldOption !== null) {
3504
3553
  const columnOption = fieldOption[attributeName];
3505
- return (columnOption === null || columnOption === void 0 ? void 0 : columnOption.columnName) || attributeName;
3554
+ return columnOption?.columnName || attributeName;
3506
3555
  }
3507
3556
  return attributeName;
3508
3557
  }
@@ -3515,27 +3564,27 @@ class HasuraFindCacheHelper {
3515
3564
  }
3516
3565
  static async getCachedResult(params) {
3517
3566
  const { cache, model, findParams, cacheOptions, logger } = params;
3518
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || !(cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.enabled))
3567
+ if (!cache?.cacheAdapter || !cacheOptions?.enabled)
3519
3568
  return null;
3520
3569
  const cacheKey = this.generateCacheKey(model, findParams);
3521
3570
  const cachedData = await cache.cacheAdapter.get(cacheKey);
3522
3571
  if (cachedData) {
3523
- logger === null || logger === void 0 ? void 0 : logger.log(`Dados recuperados do cache: ${cacheKey}`);
3572
+ logger?.log(`Dados recuperados do cache: ${cacheKey}`);
3524
3573
  return deserialize(cachedData);
3525
3574
  }
3526
3575
  return null;
3527
3576
  }
3528
3577
  static async setCachedResult(params) {
3529
3578
  const { cache, model, findParams, cacheOptions, result, logger } = params;
3530
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter) || !(cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.enabled))
3579
+ if (!cache?.cacheAdapter || !cacheOptions?.enabled)
3531
3580
  return;
3532
3581
  const cacheKey = this.generateCacheKey(model, findParams);
3533
3582
  await cache.cacheAdapter.set({
3534
3583
  key: cacheKey,
3535
3584
  data: serialize(result),
3536
- expirationInSeconds: (cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.ttl) || cache.ttlDefault,
3585
+ expirationInSeconds: cacheOptions?.ttl || cache.ttlDefault,
3537
3586
  });
3538
- logger === null || logger === void 0 ? void 0 : logger.log(`Dados salvos no cache: ${cacheKey}`);
3587
+ logger?.log(`Dados salvos no cache: ${cacheKey}`);
3539
3588
  }
3540
3589
  }
3541
3590
 
@@ -3543,27 +3592,40 @@ class HasuraFindResultHelper {
3543
3592
  static processResult(params) {
3544
3593
  const { result, tableName, enableCount, findOptions, tableFiltersNamed, fields, convertDataFromHasura, lastDistinct, } = params;
3545
3594
  const data = result[tableName].map((row) => convertDataFromHasura(row));
3546
- 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 }));
3595
+ const findResult = {
3596
+ data,
3597
+ count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity,
3598
+ ...this.processMinimalAggregates({ result, tableName, findOptions, fields }),
3599
+ ...this.processMaximumAggregates({ result, tableName, findOptions, fields }),
3600
+ ...this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }),
3601
+ };
3547
3602
  return findResult;
3548
3603
  }
3549
3604
  static bindAggregateAttributes(params) {
3550
- var _a, _b;
3551
3605
  const { aggregates, fields } = params;
3552
3606
  const convertFieldName = (fieldName) => {
3553
- var _a, _b;
3554
3607
  const finalFieldName = fieldName.toString().split('.').pop();
3555
- const fieldOption = (_a = fields.find((fieldOption) => fieldOption === finalFieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === finalFieldName);
3556
- return fieldOption ? ((_b = Object.values(fieldOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || finalFieldName : finalFieldName;
3608
+ const fieldOption = fields.find((fieldOption) => {
3609
+ if (typeof fieldOption === 'string')
3610
+ return fieldOption === finalFieldName;
3611
+ const key = Object.keys(fieldOption)[0];
3612
+ return key === finalFieldName;
3613
+ });
3614
+ if (fieldOption && typeof fieldOption !== 'string') {
3615
+ const fieldValue = Object.values(fieldOption)[0];
3616
+ return fieldValue?.columnName || finalFieldName;
3617
+ }
3618
+ return finalFieldName;
3557
3619
  };
3558
3620
  return [
3559
- ...(((_a = aggregates === null || aggregates === void 0 ? void 0 : aggregates.minimal) === null || _a === void 0 ? void 0 : _a.length)
3621
+ ...(aggregates?.minimal?.length
3560
3622
  ? [
3561
3623
  {
3562
3624
  min: aggregates.minimal.map(convertFieldName),
3563
3625
  },
3564
3626
  ]
3565
3627
  : []),
3566
- ...(((_b = aggregates === null || aggregates === void 0 ? void 0 : aggregates.maximum) === null || _b === void 0 ? void 0 : _b.length)
3628
+ ...(aggregates?.maximum?.length
3567
3629
  ? [
3568
3630
  {
3569
3631
  max: aggregates.maximum.map(convertFieldName),
@@ -3573,48 +3635,52 @@ class HasuraFindResultHelper {
3573
3635
  ];
3574
3636
  }
3575
3637
  static processMinimalAggregates(params) {
3576
- var _a;
3577
3638
  const { result, tableName, findOptions, fields } = params;
3578
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
3639
+ return findOptions?.minimal?.length
3579
3640
  ? {
3580
3641
  minimal: findOptions.minimal.reduce((minimals, current) => {
3581
- var _a;
3582
- return (Object.assign(Object.assign({}, minimals), lodash.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])));
3642
+ const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
3643
+ return {
3644
+ ...minimals,
3645
+ ...lodash.set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[columnName]),
3646
+ };
3583
3647
  }, {}),
3584
3648
  }
3585
3649
  : {};
3586
3650
  }
3587
3651
  static processMaximumAggregates(params) {
3588
- var _a;
3589
3652
  const { result, tableName, findOptions, fields } = params;
3590
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _a === void 0 ? void 0 : _a.length)
3653
+ return findOptions?.maximum?.length
3591
3654
  ? {
3592
3655
  maximum: findOptions.maximum.reduce((maximums, current) => {
3593
- var _a;
3594
- return (Object.assign(Object.assign({}, maximums), lodash.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])));
3656
+ const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
3657
+ return {
3658
+ ...maximums,
3659
+ ...lodash.set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[columnName]),
3660
+ };
3595
3661
  }, {}),
3596
3662
  }
3597
3663
  : {};
3598
3664
  }
3599
3665
  static processDistinctResults(params) {
3600
- var _a, _b;
3601
3666
  const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
3602
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _a === void 0 ? void 0 : _a.length)
3667
+ return findOptions?.distinct?.length
3603
3668
  ? {
3604
- distinct: (_b = lastDistinct[tableFiltersNamed]) !== null && _b !== void 0 ? _b : (lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
3605
- var _a, _b;
3606
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3607
- const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
3608
- return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
3609
- }, {})),
3669
+ distinct: lastDistinct[tableFiltersNamed] ??
3670
+ (lastDistinct[tableFiltersNamed] = findOptions?.distinct.reduce((distinct, current) => {
3671
+ const distinctOption = fields.find((fieldOption) => fieldOption === current) ??
3672
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3673
+ const fieldName = Object.values(distinctOption).shift()?.columnName || current;
3674
+ return {
3675
+ ...distinct,
3676
+ [current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
3677
+ };
3678
+ }, {})),
3610
3679
  }
3611
3680
  : {};
3612
3681
  }
3613
3682
  static bindAttributesToColumns(attributes, fields) {
3614
- return attributes.map((attr) => {
3615
- var _a;
3616
- return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
3617
- });
3683
+ return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
3618
3684
  }
3619
3685
  }
3620
3686
 
@@ -3644,16 +3710,19 @@ class HasuraFindVariablesHelper {
3644
3710
  };
3645
3711
  }
3646
3712
  static buildDistinctVariables(params) {
3647
- var _a, _b;
3648
3713
  const { distinct, tableName, fields, filtersVariables } = params;
3649
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3650
- const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
3651
- return Object.assign(Object.assign({}, filtersVariables), { [`${tableName}_${fieldName}_distinct`]: {
3714
+ const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
3715
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3716
+ const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
3717
+ return {
3718
+ ...filtersVariables,
3719
+ [`${tableName}_${fieldName}_distinct`]: {
3652
3720
  type: `${tableName}_select_column!`,
3653
3721
  list: true,
3654
3722
  value: fieldName,
3655
3723
  name: 'distinct_on',
3656
- } });
3724
+ },
3725
+ };
3657
3726
  }
3658
3727
  static bindOrderByAttributes(orderBy, fields) {
3659
3728
  return Object.keys(orderBy).reduce((acc, current) => [
@@ -3673,11 +3742,17 @@ class HasuraFindQueryBuilderHelper {
3673
3742
  const { tableName, fields, params, lastDistinct } = queryParams;
3674
3743
  const { filters, limits, orderBy, options: findOptions } = params || {};
3675
3744
  const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
3676
- const countVariables = Object.assign(Object.assign({}, HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields })), filtersVariables);
3677
- const mainVariables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), countVariables);
3745
+ const countVariables = {
3746
+ ...HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields }),
3747
+ ...filtersVariables,
3748
+ };
3749
+ const mainVariables = {
3750
+ ...(lodash.isNil(limits) ? {} : limits),
3751
+ ...countVariables,
3752
+ };
3678
3753
  const queries = [
3679
3754
  this.buildMainQuery({ tableName, fields, params, mainVariables }),
3680
- ...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
3755
+ ...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
3681
3756
  ...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
3682
3757
  ];
3683
3758
  return queries.filter(Boolean);
@@ -3686,26 +3761,23 @@ class HasuraFindQueryBuilderHelper {
3686
3761
  const { tableName, fields, params: findParams, mainVariables } = params;
3687
3762
  return {
3688
3763
  operation: tableName,
3689
- fields: (findParams === null || findParams === void 0 ? void 0 : findParams.fields)
3764
+ fields: findParams?.fields
3690
3765
  ? findParams.fields
3691
- .map((fieldName) => {
3692
- var _a;
3693
- return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
3694
- })
3766
+ .map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
3767
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
3695
3768
  .filter(Boolean)
3696
3769
  : fields,
3697
3770
  variables: mainVariables,
3698
3771
  };
3699
3772
  }
3700
3773
  static buildAggregateQuery(params) {
3701
- var _a;
3702
3774
  const { tableName, findOptions, countVariables } = params;
3703
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
3775
+ const enableCount = findOptions?.enableCount ?? true;
3704
3776
  const aggregateFields = [
3705
3777
  ...(enableCount ? ['count'] : []),
3706
3778
  ...HasuraFindResultHelper.bindAggregateAttributes({
3707
- aggregates: { minimal: findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal, maximum: findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum },
3708
- fields: [], // será preenchido no contexto correto
3779
+ aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
3780
+ fields: params.fields,
3709
3781
  }),
3710
3782
  ];
3711
3783
  return aggregateFields.length > 0
@@ -3723,15 +3795,14 @@ class HasuraFindQueryBuilderHelper {
3723
3795
  : [];
3724
3796
  }
3725
3797
  static buildDistinctQueries(params) {
3726
- var _a;
3727
3798
  const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
3728
3799
  const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
3729
- if (!((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _a === void 0 ? void 0 : _a.length) || lastDistinct[tableFiltersNamed]) {
3800
+ if (!findOptions?.distinct?.length || lastDistinct[tableFiltersNamed]) {
3730
3801
  return [];
3731
3802
  }
3732
3803
  return findOptions.distinct.map((distinct) => {
3733
- var _a;
3734
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3804
+ const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
3805
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3735
3806
  return {
3736
3807
  operation: {
3737
3808
  name: tableName,
@@ -3751,18 +3822,16 @@ class HasuraFindQueryBuilderHelper {
3751
3822
 
3752
3823
  class HasuraFindOperationsHelper {
3753
3824
  static async executeFindOperation(operationParams) {
3754
- var _a;
3755
3825
  const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
3756
3826
  const logger = DebugHelper.from(operationParams, 'find');
3757
3827
  const { filters, options: findOptions } = params || {};
3758
3828
  const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
3759
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
3760
- // Verifica cache primeiro
3829
+ const enableCount = findOptions?.enableCount ?? true;
3761
3830
  const cachedResult = await HasuraFindCacheHelper.getCachedResult({
3762
3831
  cache,
3763
3832
  model,
3764
3833
  findParams: params,
3765
- cacheOptions: cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cache,
3834
+ cacheOptions: cacheOptions?.cache,
3766
3835
  logger,
3767
3836
  });
3768
3837
  if (cachedResult) {
@@ -3777,7 +3846,6 @@ class HasuraFindOperationsHelper {
3777
3846
  lastDistinct,
3778
3847
  });
3779
3848
  }
3780
- // Constrói e executa queries
3781
3849
  const queries = HasuraFindQueryBuilderHelper.buildCompleteQuery({
3782
3850
  tableName,
3783
3851
  fields,
@@ -3785,16 +3853,14 @@ class HasuraFindOperationsHelper {
3785
3853
  lastDistinct,
3786
3854
  });
3787
3855
  const result = await query(queries);
3788
- // Salva no cache se habilitado
3789
3856
  await HasuraFindCacheHelper.setCachedResult({
3790
3857
  cache,
3791
3858
  model,
3792
3859
  findParams: params,
3793
- cacheOptions: cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cache,
3860
+ cacheOptions: cacheOptions?.cache,
3794
3861
  result,
3795
3862
  logger,
3796
3863
  });
3797
- // Processa e retorna resultado
3798
3864
  return HasuraFindResultHelper.processResult({
3799
3865
  result,
3800
3866
  tableName,
@@ -3813,9 +3879,8 @@ class HasuraGetCacheHelper {
3813
3879
  return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
3814
3880
  }
3815
3881
  static async getCachedData(cache, params) {
3816
- var _a;
3817
3882
  const { identifiers, options, model, logger } = params;
3818
- 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))
3883
+ if (!cache?.cacheAdapter || !options?.cache?.enabled)
3819
3884
  return null;
3820
3885
  const cacheKey = this.generateCacheKey(model, identifiers);
3821
3886
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -3825,15 +3890,14 @@ class HasuraGetCacheHelper {
3825
3890
  return model.toInstance(deserialize(cachedData));
3826
3891
  }
3827
3892
  static async saveCacheData(cache, params) {
3828
- var _a, _b;
3829
3893
  const { identifiers, options, data, logger } = params;
3830
- 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))
3894
+ if (!cache?.cacheAdapter || !options?.cache?.enabled)
3831
3895
  return;
3832
3896
  const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
3833
3897
  await cache.cacheAdapter.set({
3834
3898
  key: cacheKey,
3835
3899
  data: serialize(data),
3836
- expirationInSeconds: ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.ttl) || cache.ttlDefault,
3900
+ expirationInSeconds: options?.cache?.ttl || cache.ttlDefault,
3837
3901
  });
3838
3902
  logger.log(`Dados salvos no cache: ${cacheKey}`);
3839
3903
  }
@@ -3844,18 +3908,20 @@ class HasuraGetVariablesHelper {
3844
3908
  const { model, fields, repository } = params;
3845
3909
  const instance = model.toInstance(identifiers);
3846
3910
  return model.identifiersFields.reduce((ids, identifier) => {
3847
- var _a;
3848
3911
  const identifierBinded = identifier;
3849
3912
  if (lodash.isNil(instance[identifierBinded]))
3850
3913
  return ids;
3851
3914
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3852
- const value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier], instance)) ||
3915
+ const value = columnOption?.to?.(identifiers[identifier], instance) ||
3853
3916
  identifiers[identifier];
3854
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
3917
+ return {
3918
+ ...ids,
3919
+ [columnOption.columnName]: {
3855
3920
  type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
3856
3921
  value,
3857
3922
  required: true,
3858
- } });
3923
+ },
3924
+ };
3859
3925
  }, {});
3860
3926
  }
3861
3927
  }
@@ -3912,7 +3978,7 @@ class HasuraUpdateDataHelper {
3912
3978
  static getValueByAction(options) {
3913
3979
  if (options instanceof BaseModel)
3914
3980
  return options.toPlain();
3915
- if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
3981
+ if (lodash.isNil(options?.action))
3916
3982
  return options;
3917
3983
  if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
3918
3984
  return null;
@@ -3921,9 +3987,12 @@ class HasuraUpdateDataHelper {
3921
3987
  static paramsToPlain(params, model) {
3922
3988
  if (model.isModel(params))
3923
3989
  return params.toPlain();
3924
- return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && {
3925
- [currentKey]: this.getValueByAction(is(params[currentKey])),
3926
- }))), {});
3990
+ return Object.keys(params).reduce((data, currentKey) => ({
3991
+ ...data,
3992
+ ...(params[currentKey] !== undefined && {
3993
+ [currentKey]: this.getValueByAction(is(params[currentKey])),
3994
+ }),
3995
+ }), {});
3927
3996
  }
3928
3997
  static getIdentifiersFromData(data, model) {
3929
3998
  const instance = model.toInstance(data);
@@ -3942,13 +4011,15 @@ class HasuraUpdateVariablesHelper {
3942
4011
  static getUpdateModelKeys(data, model, fields) {
3943
4012
  const instance = model.toInstance(data);
3944
4013
  return model.identifiersFields.reduce((ids, identifier) => {
3945
- var _a;
3946
4014
  const identifierBinded = identifier;
3947
4015
  if (lodash.isNil(instance.identifier[identifierBinded]))
3948
4016
  return ids;
3949
4017
  const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
3950
- 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];
3951
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: value });
4018
+ const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
4019
+ return {
4020
+ ...ids,
4021
+ [columnOption.columnName]: value,
4022
+ };
3952
4023
  }, {});
3953
4024
  }
3954
4025
  static getIdentifierFields(model, fields) {
@@ -3976,9 +4047,7 @@ class HasuraUpdateOperationsHelper {
3976
4047
  const { data, updateGraphQLOperation, updateGraphQLObjectType, updateGraphQLPKType, model, fields, cache, mutation, convertDataToHasura, } = params;
3977
4048
  const logger = DebugHelper.from(params, 'update');
3978
4049
  const plainData = HasuraUpdateDataHelper.paramsToPlain(data, model);
3979
- // Gerencia cache se disponível
3980
4050
  await this.handleCacheRemoval({ plainData, model, cache, logger });
3981
- // Executa mutation
3982
4051
  const identifierFields = HasuraUpdateVariablesHelper.getIdentifierFields(model, fields);
3983
4052
  const mutationVariables = HasuraUpdateVariablesHelper.buildMutationVariables({
3984
4053
  plainData,
@@ -3993,13 +4062,13 @@ class HasuraUpdateOperationsHelper {
3993
4062
  }
3994
4063
  static async handleCacheRemoval(params) {
3995
4064
  const { plainData, model, cache, logger } = params;
3996
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4065
+ if (!cache?.cacheAdapter)
3997
4066
  return;
3998
4067
  const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
3999
4068
  if (Object.keys(identifiers).length > 0) {
4000
4069
  const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
4001
4070
  await cache.cacheAdapter.remove(cacheKey);
4002
- logger === null || logger === void 0 ? void 0 : logger.log(`Cache removido: ${cacheKey}`);
4071
+ logger?.log(`Cache removido: ${cacheKey}`);
4003
4072
  }
4004
4073
  }
4005
4074
  }
@@ -4021,9 +4090,8 @@ class FirestoreCacheKeyGeneratorHelper {
4021
4090
 
4022
4091
  class FirestoreCacheHelper {
4023
4092
  static async getCachedData(cache, params) {
4024
- var _a;
4025
4093
  const { model, identifiers, options, logger, req } = params;
4026
- 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)
4094
+ if (!cache?.cacheAdapter || options?.cache?.enabled === false)
4027
4095
  return null;
4028
4096
  const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
4029
4097
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -4034,9 +4102,8 @@ class FirestoreCacheHelper {
4034
4102
  return null;
4035
4103
  }
4036
4104
  static async getCachedFindData(cache, params) {
4037
- var _a;
4038
4105
  const { model, find, options, logger } = params;
4039
- 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)
4106
+ if (!cache?.cacheAdapter || options?.cache?.enabled === false)
4040
4107
  return null;
4041
4108
  const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
4042
4109
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -4048,7 +4115,7 @@ class FirestoreCacheHelper {
4048
4115
  }
4049
4116
  static async saveCacheData(cache, params) {
4050
4117
  const { cacheKey, data, expirationInSeconds, logger, req } = params;
4051
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4118
+ if (!cache?.cacheAdapter)
4052
4119
  return;
4053
4120
  await cache.cacheAdapter.set({
4054
4121
  key: cacheKey,
@@ -4060,7 +4127,7 @@ class FirestoreCacheHelper {
4060
4127
  }
4061
4128
  static async removeCacheData(cache, params) {
4062
4129
  const { cacheKey, logger } = params;
4063
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4130
+ if (!cache?.cacheAdapter)
4064
4131
  return;
4065
4132
  await cache.cacheAdapter.remove(cacheKey);
4066
4133
  logger.log(`Cache removido: ${cacheKey}`);
@@ -4078,7 +4145,7 @@ class FirestoreOperationsHelper {
4078
4145
  this.model = model;
4079
4146
  }
4080
4147
  buildInstanceFromIdentifiers(identifiers) {
4081
- return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
4148
+ return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
4082
4149
  }
4083
4150
  async validateDocumentExists(docRef, collectionName, identifiers) {
4084
4151
  const docSnapshot = await docRef.get();
@@ -4100,7 +4167,7 @@ class FirestoreOperationsHelper {
4100
4167
  calculateCount(data, limits) {
4101
4168
  if (data.length <= 0)
4102
4169
  return 0;
4103
- if (data.length < (limits === null || limits === void 0 ? void 0 : limits.limit))
4170
+ if (data.length)
4104
4171
  return data.length;
4105
4172
  return Infinity;
4106
4173
  }
@@ -4113,8 +4180,8 @@ class FirestoreOperationsHelper {
4113
4180
  const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
4114
4181
  if (!isSubCollection)
4115
4182
  return collectionName;
4116
- const parentId = identifiers === null || identifiers === void 0 ? void 0 : identifiers[parentIdField];
4117
- return `${parentRepository === null || parentRepository === void 0 ? void 0 : parentRepository.collectionName}/${parentId}/${collectionName}`;
4183
+ const parentId = identifiers?.[parentIdField];
4184
+ return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
4118
4185
  }
4119
4186
  getKeyField() {
4120
4187
  const model = new this.model();
@@ -4165,27 +4232,25 @@ const createGetFirestoreClass = (MixinBase) => {
4165
4232
  }
4166
4233
  }
4167
4234
  async executeGet(params) {
4168
- var _a, _b, _c, _d;
4169
4235
  const { instance, collectionName, identifiers, logger, req } = params;
4170
- 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 }));
4171
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
4236
+ const intercepted = await this.interceptors?.request?.({ instance });
4237
+ const builded = intercepted?.instance || instance;
4172
4238
  const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
4173
4239
  const data = docRef.data();
4174
4240
  this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
4175
- 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;
4241
+ const result = (await this.interceptors?.response?.(data, intercepted)) || data;
4176
4242
  logger.log({ req, res: result });
4177
4243
  return result;
4178
4244
  }
4179
4245
  async saveCacheData(params) {
4180
- var _a, _b, _c;
4181
4246
  const { identifiers, options, result, logger, req } = params;
4182
- 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)
4247
+ if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
4183
4248
  return;
4184
4249
  const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
4185
4250
  await FirestoreCacheHelper.saveCacheData(this.cache, {
4186
4251
  cacheKey,
4187
4252
  data: result,
4188
- expirationInSeconds: (_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.ttl,
4253
+ expirationInSeconds: options?.cache?.ttl,
4189
4254
  logger,
4190
4255
  req,
4191
4256
  });
@@ -4216,14 +4281,13 @@ class FirestoreQueryBuilderHelper {
4216
4281
  this.config = config;
4217
4282
  }
4218
4283
  buildWhereSentence(fieldName, options) {
4219
- var _a, _b;
4220
- if (((_b = (_a = this.config).isSubCollection) === null || _b === void 0 ? void 0 : _b.call(_a, this)) && fieldName === this.config.parentIdField)
4284
+ if (this.config.isSubCollection?.(this) && fieldName === this.config.parentIdField)
4221
4285
  return [];
4222
4286
  const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
4223
4287
  return this.buildWhereConditions(firestoreFieldName, options, fieldName);
4224
4288
  }
4225
4289
  getFirestoreFieldName(fieldName, options) {
4226
- const value = (options === null || options === void 0 ? void 0 : options.value) || options;
4290
+ const value = options?.value || options;
4227
4291
  const object = {};
4228
4292
  lodash.set(object, fieldName.toString(), value);
4229
4293
  const plainInstance = new this.config.model(object).toPlain();
@@ -4232,19 +4296,19 @@ class FirestoreQueryBuilderHelper {
4232
4296
  : Object.keys(plainInstance).find((key) => plainInstance[key]);
4233
4297
  }
4234
4298
  buildWhereConditions(firestoreFieldName, options, fieldName) {
4235
- if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
4299
+ if (options?.operator === exports.Where.LIKE) {
4236
4300
  return this.buildLikeConditions(firestoreFieldName, options);
4237
4301
  }
4238
- if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4302
+ if (options?.operator === exports.Where.IN && Array.isArray(options?.value)) {
4239
4303
  return this.buildInConditions(firestoreFieldName, options);
4240
4304
  }
4241
4305
  if (this.isNestedObjectFilter(options)) {
4242
4306
  return this.buildNestedObjectConditions(fieldName, options);
4243
4307
  }
4244
- return [[firestoreFieldName, ((options === null || options === void 0 ? void 0 : options.operator) || '=='), (options === null || options === void 0 ? void 0 : options.value) || options]];
4308
+ return [[firestoreFieldName, (options?.operator || '=='), options?.value || options]];
4245
4309
  }
4246
4310
  buildLikeConditions(firestoreFieldName, options) {
4247
- if (this.isArrayField(firestoreFieldName) && Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4311
+ if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
4248
4312
  return [[firestoreFieldName, 'array-contains-any', options.value]];
4249
4313
  }
4250
4314
  return [
@@ -4261,17 +4325,16 @@ class FirestoreQueryBuilderHelper {
4261
4325
  buildNestedObjectConditions(fieldName, options) {
4262
4326
  return Object.keys(options).reduce((queries, key) => [
4263
4327
  ...queries,
4264
- ...this.buildWhereSentence(`${fieldName.toString()}.${key}`, is(options)[key]),
4328
+ ...this.buildWhereSentence(Array.isArray(options) ? fieldName : `${fieldName.toString()}.${key}`, is(options)[key]),
4265
4329
  ], []);
4266
4330
  }
4267
4331
  isArrayField(firestoreFieldName) {
4268
- var _a, _b;
4269
- return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
4332
+ return (this.config.fields?.[firestoreFieldName] ===
4270
4333
  FirestoreFieldType.Array ||
4271
- !((_b = this.config.fields) === null || _b === void 0 ? void 0 : _b[firestoreFieldName]));
4334
+ !this.config.fields?.[firestoreFieldName]);
4272
4335
  }
4273
4336
  isNestedObjectFilter(options) {
4274
- return lodash.isObject(options) && lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) && lodash.isNil(options === null || options === void 0 ? void 0 : options.value);
4337
+ return lodash.isObject(options) && lodash.isNil(options?.operator) && lodash.isNil(options?.value);
4275
4338
  }
4276
4339
  buildOrderBy(filters, fieldsToOrderBy) {
4277
4340
  const orderByKeys = Object.keys(fieldsToOrderBy || {});
@@ -4287,8 +4350,8 @@ class FirestoreQueryBuilderHelper {
4287
4350
  filtersKeysWithUnordered.forEach((filterKey) => {
4288
4351
  const filterValue = filters[filterKey];
4289
4352
  const filterOptions = is(filterValue);
4290
- if ((filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.operator) && ![exports.Where.EQUALS].includes(filterOptions.operator)) {
4291
- updatedOrderBy = Object.assign({ [filterKey]: 'asc' }, updatedOrderBy);
4353
+ if (filterOptions?.operator && ![exports.Where.EQUALS].includes(filterOptions.operator)) {
4354
+ updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
4292
4355
  }
4293
4356
  });
4294
4357
  return updatedOrderBy;
@@ -4302,21 +4365,21 @@ class FirestoreQueryBuilderHelper {
4302
4365
  async buildLimits(params) {
4303
4366
  const { filters, limits, collection, buildCollectionPath } = params;
4304
4367
  const queries = [];
4305
- if (limits === null || limits === void 0 ? void 0 : limits.offset) {
4368
+ if (limits?.offset) {
4306
4369
  await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
4307
4370
  }
4308
- if (limits === null || limits === void 0 ? void 0 : limits.limit) {
4371
+ if (limits?.limit) {
4309
4372
  queries.push(['limit', limits.limit]);
4310
4373
  }
4311
4374
  return queries;
4312
4375
  }
4313
4376
  async addOffsetQuery(params) {
4314
- var _a;
4315
4377
  const { queries, limits, filters, collection, buildCollectionPath } = params;
4316
4378
  if (this.config.model.isModel(limits.offset)) {
4317
4379
  const docSnapshot = await collection(buildCollectionPath(filters))
4318
- .getDoc((_a = Object.values(limits.offset.identifier)
4319
- .shift()) === null || _a === void 0 ? void 0 : _a.toString())
4380
+ .getDoc(Object.values(limits.offset.identifier)
4381
+ .shift()
4382
+ ?.toString())
4320
4383
  .get();
4321
4384
  queries.push(['fromStartAfter', docSnapshot]);
4322
4385
  }
@@ -4331,7 +4394,7 @@ class FirestoreQueryBuilderHelper {
4331
4394
  }
4332
4395
 
4333
4396
  const createFilterHelpers = () => {
4334
- const checkIfIsFilterOption = (filter) => !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
4397
+ const checkIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
4335
4398
  const getValueFromFilter = (filter) => {
4336
4399
  return checkIfIsFilterOption(filter) ? filter.value : filter;
4337
4400
  };
@@ -4389,20 +4452,19 @@ const withFindFirestore = (MixinBase) => {
4389
4452
  }
4390
4453
  }
4391
4454
  async executeFind(params) {
4392
- var _a, _b, _c, _d, _e, _f;
4393
4455
  const { find, collectionName, logger, req } = params;
4394
4456
  const collection = this.collection(collectionName);
4395
- 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;
4396
- 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 }));
4397
- const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
4457
+ const enableCount = find?.options?.enableCount ?? true;
4458
+ const intercepted = await this.interceptors?.request?.({ find });
4459
+ const { filters, limits, orderBy } = intercepted?.find || find;
4398
4460
  const queryData = await this.buildQueryData(filters, orderBy, limits);
4399
4461
  const docs = await this.executeQuery(collection, queryData);
4400
4462
  const data = docs.docs.map((doc) => doc.data());
4401
4463
  const result = {
4402
- 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,
4464
+ data: (await this.interceptors?.response?.(data, intercepted)) || data,
4403
4465
  count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
4404
4466
  };
4405
- logger.log(Object.assign(Object.assign({ req }, queryData), { res: result }));
4467
+ logger.log({ req, ...queryData, res: result });
4406
4468
  return result;
4407
4469
  }
4408
4470
  async buildQueryData(filters, orderBy, limits) {
@@ -4418,19 +4480,21 @@ const withFindFirestore = (MixinBase) => {
4418
4480
  }
4419
4481
  async executeQuery(collection, queryData) {
4420
4482
  return this.queryBuilder
4421
- .buildQuery(Object.assign({ collection }, queryData))
4483
+ .buildQuery({
4484
+ collection,
4485
+ ...queryData,
4486
+ })
4422
4487
  .getDocs();
4423
4488
  }
4424
4489
  async saveCacheData(params) {
4425
- var _a, _b, _c;
4426
4490
  const { find, options, result, logger } = params;
4427
- 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)
4491
+ if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
4428
4492
  return;
4429
4493
  const cacheKey = this.generateCacheKey(find);
4430
4494
  await FirestoreCacheHelper.saveCacheData(this.cache, {
4431
4495
  cacheKey,
4432
4496
  data: result,
4433
- expirationInSeconds: (_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.ttl,
4497
+ expirationInSeconds: options?.cache?.ttl,
4434
4498
  logger,
4435
4499
  });
4436
4500
  }
@@ -4438,7 +4502,7 @@ const withFindFirestore = (MixinBase) => {
4438
4502
  if (!this.isSubCollection(this))
4439
4503
  return this.collectionName;
4440
4504
  const parentIdField = this.parentIdField;
4441
- const parentId = getValueFromFilter(filters === null || filters === void 0 ? void 0 : filters[parentIdField]);
4505
+ const parentId = getValueFromFilter(filters?.[parentIdField]);
4442
4506
  return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
4443
4507
  }
4444
4508
  };
@@ -4447,16 +4511,15 @@ const withFindFirestore = (MixinBase) => {
4447
4511
  const withCreateFirestore = (MixinBase) => {
4448
4512
  return class CreateFirestore extends MixinBase {
4449
4513
  async create(data) {
4450
- var _a, _b, _c, _d;
4451
4514
  const logger = this.logger.with('create');
4452
4515
  const instance = this.model.toInstance(data);
4453
- 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 }));
4454
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
4516
+ const intercepted = await this.interceptors?.request?.({ instance });
4517
+ const builded = intercepted?.instance || instance;
4455
4518
  const req = { collection: this.buildCollectionPathForAdd(builded), data };
4456
4519
  try {
4457
4520
  const docRef = await this.save(builded);
4458
4521
  const doc = (await docRef.get()).data();
4459
- 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;
4522
+ const docBuilded = (await this.interceptors?.response?.(doc, intercepted)) || doc;
4460
4523
  logger.log({ req, res: docBuilded });
4461
4524
  return docBuilded;
4462
4525
  }
@@ -4467,10 +4530,9 @@ const withCreateFirestore = (MixinBase) => {
4467
4530
  }
4468
4531
  }
4469
4532
  async save(data) {
4470
- var _a, _b;
4471
4533
  const collectionPath = this.buildCollectionPathForAdd(data);
4472
4534
  const collection = this.collection(collectionPath);
4473
- 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));
4535
+ return collection.add(data, Object.values(data.identifier).shift()?.toString?.());
4474
4536
  }
4475
4537
  buildCollectionPathForAdd(identifiers) {
4476
4538
  return this.isSubCollection(this)
@@ -4481,26 +4543,23 @@ const withCreateFirestore = (MixinBase) => {
4481
4543
  };
4482
4544
 
4483
4545
  const createUpdateHelpers = () => {
4484
- const getValueFromParams = (params, field) => {
4485
- var _a;
4486
- return (lodash.isNil((_a = is(params[field])) === null || _a === void 0 ? void 0 : _a.value)
4487
- ? is(params[field])
4488
- : is(params[field]).value) || null;
4489
- };
4546
+ const getValueFromParams = (params, field) => (lodash.isNil(is(params[field])?.value)
4547
+ ? is(params[field])
4548
+ : is(params[field]).value) || null;
4490
4549
  const getValueByAction = (options) => {
4491
- if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
4550
+ if (lodash.isNil(options?.action))
4492
4551
  return options;
4493
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.REMOVE_FIELD)
4552
+ if (options?.action === exports.UpdateOptionActions.REMOVE_FIELD)
4494
4553
  return firestore.deleteField();
4495
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.NULL)
4554
+ if (options?.action === exports.UpdateOptionActions.NULL)
4496
4555
  return null;
4497
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4498
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.MERGE)
4556
+ if (Array.isArray(options?.value)) {
4557
+ if (options?.action === exports.UpdateOptionActions.MERGE)
4499
4558
  return firestore.arrayUnion(...options.value);
4500
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.REMOVE)
4559
+ if (options?.action === exports.UpdateOptionActions.REMOVE)
4501
4560
  return firestore.arrayRemove(...options.value);
4502
4561
  }
4503
- return options === null || options === void 0 ? void 0 : options.value;
4562
+ return options?.value;
4504
4563
  };
4505
4564
  return { getValueFromParams, getValueByAction };
4506
4565
  };
@@ -4551,14 +4610,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
4551
4610
  await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
4552
4611
  }
4553
4612
  async executeUpdate(params) {
4554
- var _a, _b, _c, _d;
4555
4613
  const { data, docRef, logger, req, identifiers } = params;
4556
4614
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
4557
- 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 }));
4558
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
4615
+ const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
4616
+ const builded = intercepted?.instance || plainFromData;
4559
4617
  await docRef.save(builded.toPlain());
4560
4618
  const docData = await docRef.get();
4561
- 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();
4619
+ const result = this.interceptors?.response?.(docData.data(), intercepted) || docData.data();
4562
4620
  logger.log({ req, res: result, identifiers });
4563
4621
  return result;
4564
4622
  }
@@ -4574,7 +4632,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
4574
4632
  return this.convertParamsToPlainObject(params);
4575
4633
  }
4576
4634
  convertParamsToPlainObject(params) {
4577
- return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), this.processParamValue(currentKey, params[currentKey]))), {});
4635
+ return Object.keys(params).reduce((data, currentKey) => ({
4636
+ ...data,
4637
+ ...this.processParamValue(currentKey, params[currentKey]),
4638
+ }), {});
4578
4639
  }
4579
4640
  processParamValue(key, value) {
4580
4641
  const processedValue = getValueByAction(value);
@@ -4615,12 +4676,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
4615
4676
  await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
4616
4677
  }
4617
4678
  async executeDeleteOperation(params) {
4618
- var _a, _b, _c, _d;
4619
4679
  const { instance, collectionName, logger, req } = params;
4620
- 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 }));
4621
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
4680
+ const intercepted = await this.interceptors?.request?.({ instance });
4681
+ const builded = intercepted?.instance || instance;
4622
4682
  await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
4623
- await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
4683
+ await this.interceptors?.response?.(instance, intercepted);
4624
4684
  logger.log({ req, res: undefined });
4625
4685
  }
4626
4686
  buildCollectionPathForRemove(identifiers) {
@@ -4700,15 +4760,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
4700
4760
  const products = [];
4701
4761
  const wheres = [];
4702
4762
  for (const productIds of chunks) {
4703
- if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
4763
+ if (options?.limit && products.length >= options?.limit)
4704
4764
  break;
4705
4765
  wheres.push(['published', '==', true], ['id', 'in', productIds]);
4706
- if (options === null || options === void 0 ? void 0 : options.hasStock)
4766
+ if (options?.hasStock)
4707
4767
  wheres.push(['stock.quantity', '>', 0]);
4708
- if (options === null || options === void 0 ? void 0 : options.gender)
4709
- wheres.push(['tags', 'array-contains', options === null || options === void 0 ? void 0 : options.gender]);
4768
+ if (options?.gender)
4769
+ wheres.push(['tags', 'array-contains', options?.gender]);
4710
4770
  const productSnap = await wheres
4711
- .reduce((collection, where) => collection.where(...where), (options === null || options === void 0 ? void 0 : options.limit)
4771
+ .reduce((collection, where) => collection.where(...where), options?.limit
4712
4772
  ? this.collection('productsErpVitrine').limit(options.limit)
4713
4773
  : this.collection('productsErpVitrine'))
4714
4774
  .getDocs();
@@ -4773,19 +4833,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4773
4833
  throw new Error('Method not implemented.');
4774
4834
  }
4775
4835
  async getBySlug(slug) {
4776
- var _a;
4777
4836
  const result = await this.find({
4778
4837
  filters: {
4779
4838
  slug: { operator: exports.Where.EQUALS, value: slug },
4780
4839
  },
4781
4840
  });
4782
- return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4841
+ return result?.data?.shift();
4783
4842
  }
4784
4843
  async fetchReviews(status) {
4785
4844
  const { data: products } = await this.find();
4786
4845
  products.forEach((product) => {
4787
- var _a;
4788
- if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
4846
+ if ([undefined, 0].includes(product.reviews?.length))
4789
4847
  return;
4790
4848
  const productInfo = {
4791
4849
  productId: product.id,
@@ -4797,11 +4855,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4797
4855
  this.reviews.rejected = [];
4798
4856
  product.reviews.forEach((review) => {
4799
4857
  if ([null, undefined].includes(review.status))
4800
- return this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
4858
+ return this.reviews.pending.push({ ...review, ...productInfo });
4801
4859
  if (review.status === false)
4802
- return this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
4860
+ return this.reviews.rejected.push({ ...review, ...productInfo });
4803
4861
  if (review.status)
4804
- return this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
4862
+ return this.reviews.approved.push({ ...review, ...productInfo });
4805
4863
  return review;
4806
4864
  });
4807
4865
  });
@@ -4888,22 +4946,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4888
4946
  interceptors,
4889
4947
  cache,
4890
4948
  });
4891
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4892
- var _a, _b, _c;
4893
- return ({
4894
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
4895
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
4896
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
4897
- 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)) || [],
4898
- });
4899
- };
4900
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
4901
- var _a;
4902
- return ({
4903
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
4904
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
4905
- });
4906
- };
4949
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
4950
+ category: homeCategoryGroup?.category?.toPlain
4951
+ ? homeCategoryGroup?.category?.toPlain()
4952
+ : homeCategoryGroup?.category,
4953
+ products: homeCategoryGroup?.products
4954
+ ?.map((product) => (product?.toPlain ? product?.toPlain() : product))
4955
+ .filter(Boolean) || [],
4956
+ });
4957
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
4958
+ category: Category.toInstance(homeCategoryGroup?.category),
4959
+ products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
4960
+ });
4907
4961
  }
4908
4962
  buildModelInstance() {
4909
4963
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -4919,17 +4973,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4919
4973
  };
4920
4974
  }
4921
4975
  homeToFirestore(home) {
4922
- var _a, _b, _c, _d;
4923
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4924
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
4925
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
4926
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
4976
+ if (home.data?.data) {
4977
+ home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
4978
+ home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
4979
+ home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
4927
4980
  }
4928
4981
  return home;
4929
4982
  }
4930
4983
  homeFromFirestore(home) {
4931
- var _a;
4932
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4984
+ if (home.data?.data) {
4933
4985
  home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
4934
4986
  home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
4935
4987
  home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
@@ -5068,8 +5120,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
5068
5120
  },
5069
5121
  });
5070
5122
  this.orderFromFirestore = (order) => {
5071
- var _a;
5072
- if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
5123
+ if (order?.lineItems?.length) {
5073
5124
  order.lineItems = order.lineItems.map((lineItem) => {
5074
5125
  const prices = !!lineItem.price;
5075
5126
  const shopPrice = prices[order.shop];
@@ -5084,7 +5135,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
5084
5135
  buildModelInstance() {
5085
5136
  const { fromFirestore, toFirestore } = super.buildModelInstance();
5086
5137
  return {
5087
- toFirestore: (data) => toFirestore((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data),
5138
+ toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
5088
5139
  fromFirestore: (snap) => {
5089
5140
  const instance = fromFirestore(snap);
5090
5141
  return this.orderFromFirestore(instance);
@@ -5115,18 +5166,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
5115
5166
  });
5116
5167
  }
5117
5168
  async createBlockedOrderOrPayment(params) {
5118
- var _a, _b, _c, _d, _e, _f, _g, _h;
5119
5169
  const { checkout, blockType, type, limiteRange, card = null } = params;
5120
5170
  return this.create(OrderBlocked.toInstance({
5121
5171
  customer: {
5122
- name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
5123
- cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
5124
- id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
5125
- email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
5126
- phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
5127
- isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
5128
- subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
5129
- shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
5172
+ name: checkout.user?.displayName || '',
5173
+ cpf: checkout.user?.cpf || '',
5174
+ id: checkout.user?.id,
5175
+ email: checkout.user?.email || '',
5176
+ phoneNumber: '+55' + checkout.user?.phone,
5177
+ isSubscriber: checkout.user?.isSubscriber,
5178
+ subscriptionPlan: checkout.user?.subscriptionPlan || '',
5179
+ shippingAddress: {
5180
+ ...checkout.shippingAddress,
5181
+ zip: this.formatZip(checkout.shippingAddress?.zip),
5182
+ },
5130
5183
  },
5131
5184
  blockType,
5132
5185
  limiteRange,
@@ -5374,7 +5427,7 @@ class ConnectDocumentService {
5374
5427
  this.reference = firestore.doc(this.firestore, this.path).withConverter({
5375
5428
  toFirestore: (data) => data,
5376
5429
  fromFirestore: (snapshot) => {
5377
- return Object.assign({ id: snapshot.id }, snapshot.data());
5430
+ return { id: snapshot.id, ...snapshot.data() };
5378
5431
  },
5379
5432
  });
5380
5433
  }
@@ -5412,7 +5465,7 @@ class ConnectCollectionService {
5412
5465
  this.reference = firestore.collection(firestore$1, path).withConverter({
5413
5466
  toFirestore: (data) => data,
5414
5467
  fromFirestore: (snapshot) => {
5415
- return Object.assign({ id: snapshot.id }, snapshot.data());
5468
+ return { id: snapshot.id, ...snapshot.data() };
5416
5469
  },
5417
5470
  });
5418
5471
  }
@@ -5507,10 +5560,10 @@ class FirebaseFileUploaderService {
5507
5560
  function createCreateHasuraGraphQLClass(MixinBase) {
5508
5561
  return class CreateHasuraGraphQLMixin extends MixinBase {
5509
5562
  constructor(...params) {
5510
- const options = params === null || params === void 0 ? void 0 : params[0];
5563
+ const options = params?.[0];
5511
5564
  super(...params);
5512
- this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.insertGraphQLOperation);
5513
- this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options === null || options === void 0 ? void 0 : options.insertGraphQLObjectType);
5565
+ this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options?.insertGraphQLOperation);
5566
+ this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options?.insertGraphQLObjectType);
5514
5567
  }
5515
5568
  async create(data) {
5516
5569
  return HasuraCreateOperationsHelper.executeCreate(data, {
@@ -5537,9 +5590,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
5537
5590
  function createDeleteHasuraGraphQLClass(MixinBase) {
5538
5591
  return class DeleteHasuraGraphQLMixin extends MixinBase {
5539
5592
  constructor(...params) {
5540
- const options = params === null || params === void 0 ? void 0 : params[0];
5593
+ const options = params?.[0];
5541
5594
  super(...params);
5542
- this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.deleteGraphQLOperation);
5595
+ this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
5543
5596
  }
5544
5597
  async delete(identifiers) {
5545
5598
  await HasuraDeleteOperationsHelper.executeDelete({
@@ -5585,9 +5638,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
5585
5638
  function createGetHasuraGraphQLClass(MixinBase) {
5586
5639
  return class GetHasuraGraphQLMixin extends MixinBase {
5587
5640
  constructor(...params) {
5588
- const options = params === null || params === void 0 ? void 0 : params[0];
5641
+ const options = params?.[0];
5589
5642
  super(...params);
5590
- this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.getGraphQLOperation);
5643
+ this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
5591
5644
  }
5592
5645
  generateCacheKey(identifiers) {
5593
5646
  return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
@@ -5663,11 +5716,11 @@ function createHasuraGraphQLClass(MixinBase) {
5663
5716
  function createUpdateHasuraGraphQLClass(MixinBase) {
5664
5717
  return class UpdateHasuraGraphQLMixin extends MixinBase {
5665
5718
  constructor(...params) {
5666
- const options = params === null || params === void 0 ? void 0 : params[0];
5719
+ const options = params?.[0];
5667
5720
  super(...params);
5668
- this.updateGraphQLOperation = (options === null || options === void 0 ? void 0 : options.updateGraphQLOperation) || `update_${this.tableName}_by_pk`;
5669
- this.updateGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.updateGraphQLObjectType) || `${this.tableName}_set_input`;
5670
- this.updateGraphQLPKType = (options === null || options === void 0 ? void 0 : options.updateGraphQLPKType) || `${this.tableName}_pk_columns_input`;
5721
+ this.updateGraphQLOperation = options?.updateGraphQLOperation || `update_${this.tableName}_by_pk`;
5722
+ this.updateGraphQLObjectType = options?.updateGraphQLObjectType || `${this.tableName}_set_input`;
5723
+ this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
5671
5724
  }
5672
5725
  getIdentifiersFromData(data) {
5673
5726
  return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
@@ -5857,7 +5910,7 @@ const fieldsConfiguration$5 = [
5857
5910
  categories: { data: value.map((category) => ({ category_id: +category })) },
5858
5911
  }),
5859
5912
  to: (categories) => categories.map((categoryId) => +categoryId),
5860
- 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(); })) || [],
5913
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
5861
5914
  },
5862
5915
  },
5863
5916
  ],
@@ -5938,8 +5991,7 @@ class CategoryCacheOperationsHelper {
5938
5991
  logger.log(`Dados salvos no cache: ${cacheKey}`);
5939
5992
  }
5940
5993
  static shouldUseCache(cacheAdapter, optionsCache) {
5941
- var _a;
5942
- return !!(cacheAdapter && ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.enabled));
5994
+ return !!(cacheAdapter && optionsCache?.cache?.enabled);
5943
5995
  }
5944
5996
  }
5945
5997
 
@@ -6107,19 +6159,25 @@ class CategoryProductOperationsHelper {
6107
6159
  }
6108
6160
  static buildProductQuery(params) {
6109
6161
  const { productIds, fields, hasStock, limit } = params;
6110
- return Object.assign(Object.assign({ filters: this.buildProductFilters(productIds, hasStock) }, (limit ? { limits: { limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
6162
+ return {
6163
+ filters: this.buildProductFilters(productIds, hasStock),
6164
+ ...(limit ? { limits: { limit } } : {}),
6165
+ fields,
6166
+ options: { enableCount: false },
6167
+ orderBy: {
6111
6168
  stock: 'desc',
6112
6169
  shoppingCount: 'desc',
6113
6170
  rate: 'desc',
6114
6171
  name: 'asc',
6115
- } });
6172
+ },
6173
+ };
6116
6174
  }
6117
6175
  static getGenderParam(shop) {
6118
6176
  return shop === exports.Shops.MENSMARKET ? 'male' : 'female';
6119
6177
  }
6120
6178
  static async fetchMostRelevantProducts(params) {
6121
6179
  const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
6122
- if (!(mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length))
6180
+ if (!mostRelevantsIds?.length)
6123
6181
  return [];
6124
6182
  const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
6125
6183
  const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
@@ -6148,9 +6206,8 @@ class CategoryProductOperationsHelper {
6148
6206
 
6149
6207
  class CategoryMountOperationsHelper {
6150
6208
  static async executeMount(params, dependencies) {
6151
- var _a;
6152
6209
  const { category, shop, options = {}, optionsCache } = params;
6153
- if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
6210
+ if (!category?.products?.length)
6154
6211
  return [];
6155
6212
  const cachedResult = await this.tryGetFromCache({
6156
6213
  category,
@@ -6171,7 +6228,7 @@ class CategoryMountOperationsHelper {
6171
6228
  optionsCache,
6172
6229
  dependencies,
6173
6230
  });
6174
- if (mostRelevantProducts.length >= mostRelevantsIds.length) {
6231
+ if (mostRelevantsIds.length && mostRelevantProducts.length >= mostRelevantsIds.length) {
6175
6232
  return this.finalizeMountWithMostRelevants({
6176
6233
  mostRelevantProducts,
6177
6234
  mostRelevantsIds,
@@ -6248,7 +6305,6 @@ class CategoryMountOperationsHelper {
6248
6305
  return result;
6249
6306
  }
6250
6307
  static async saveToCacheIfNeeded(params) {
6251
- var _a;
6252
6308
  const { category, shop, options, optionsCache, result, dependencies } = params;
6253
6309
  const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
6254
6310
  if (!shouldUseCache)
@@ -6258,7 +6314,7 @@ class CategoryMountOperationsHelper {
6258
6314
  cacheAdapter: dependencies.cacheAdapter,
6259
6315
  cacheKey,
6260
6316
  products: result,
6261
- ttl: ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.ttl) || dependencies.defaultCacheTtl,
6317
+ ttl: optionsCache?.cache?.ttl || dependencies.defaultCacheTtl,
6262
6318
  logger: dependencies.logger,
6263
6319
  });
6264
6320
  }
@@ -6284,7 +6340,12 @@ class ProductFetchReviewsHelper {
6284
6340
  ...reviews,
6285
6341
  ...product.reviews
6286
6342
  .filter((review) => this.matchesStatus(review, status))
6287
- .map((review) => (Object.assign(Object.assign({}, bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku }))),
6343
+ .map((review) => ({
6344
+ ...bindReviewToModel(review),
6345
+ productId: product.id,
6346
+ productName: product.name,
6347
+ productSku: product.sku,
6348
+ })),
6288
6349
  ], []);
6289
6350
  }
6290
6351
  static matchesStatus(review, status) {
@@ -6331,8 +6392,7 @@ class ProductReviewCacheHelper {
6331
6392
  dependencies.logger.log(`Dados salvos no cache: ${key}`);
6332
6393
  }
6333
6394
  static shouldUseCache(cacheAdapter, options) {
6334
- var _a;
6335
- return !!(cacheAdapter && ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled));
6395
+ return !!(cacheAdapter && options?.cache?.enabled);
6336
6396
  }
6337
6397
  }
6338
6398
 
@@ -6343,9 +6403,12 @@ class ProductReviewOperationsHelper {
6343
6403
  let count = 0;
6344
6404
  let offset = 0;
6345
6405
  do {
6346
- const result = await repository.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, (limit && {
6347
- limits: { offset, limit },
6348
- })));
6406
+ const result = await repository.find({
6407
+ fields: ['id', 'name', 'sku', 'reviews'],
6408
+ ...(limit && {
6409
+ limits: { offset, limit },
6410
+ }),
6411
+ });
6349
6412
  data = data.concat(result.data);
6350
6413
  count = result.data.length;
6351
6414
  offset += limit;
@@ -6356,7 +6419,13 @@ class ProductReviewOperationsHelper {
6356
6419
  const { data, getReviewStatus } = params;
6357
6420
  return data.reduce((reviews, product) => [
6358
6421
  ...reviews,
6359
- ...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
6422
+ ...product.reviews.map((review) => ({
6423
+ ...review,
6424
+ reviewStatus: getReviewStatus(review),
6425
+ productId: product.id,
6426
+ productName: product.name,
6427
+ productSku: product.sku,
6428
+ })),
6360
6429
  ], []);
6361
6430
  }
6362
6431
  static applyReviewFilters(params) {
@@ -6400,7 +6469,7 @@ class ProductReviewUpdateHelper {
6400
6469
  const { productId, reviews, dependencies } = params;
6401
6470
  const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
6402
6471
  const review = await dependencies.findReview(reviewData, productId);
6403
- return review === null || review === void 0 ? void 0 : review.id;
6472
+ return review?.id;
6404
6473
  }));
6405
6474
  await dependencies.mutation('delete_product_review', ['affected_rows'], {
6406
6475
  where: {
@@ -6439,7 +6508,7 @@ class ProductReviewUpdateHelper {
6439
6508
  static async insertNewReview(reviewData, productId, dependencies) {
6440
6509
  const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
6441
6510
  object: {
6442
- value: lodash.omit(Object.assign(Object.assign({}, dependencies.bindReviewToHasura(reviewData)), { product_id: productId.toString() }), ['id']),
6511
+ value: lodash.omit({ ...dependencies.bindReviewToHasura(reviewData), product_id: productId.toString() }, ['id']),
6443
6512
  type: 'product_review_insert_input',
6444
6513
  required: true,
6445
6514
  },
@@ -6532,11 +6601,14 @@ const fieldsConfiguration$4 = [
6532
6601
  bindPersistData: (value) => {
6533
6602
  return {
6534
6603
  brand_condition: value.brand,
6535
- tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
6604
+ tag_condition: value?.tags || [],
6536
6605
  };
6537
6606
  },
6538
6607
  bindFindFilter: (sentence) => {
6539
- return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
6608
+ return {
6609
+ ...(sentence.brand ? { brand_condition: sentence.brand } : {}),
6610
+ ...(sentence.tags ? { tag_condition: sentence.tags } : {}),
6611
+ };
6540
6612
  },
6541
6613
  },
6542
6614
  },
@@ -6548,7 +6620,7 @@ const fieldsConfiguration$4 = [
6548
6620
  bindPersistData: (value) => ({
6549
6621
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
6550
6622
  }),
6551
- 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)) || [],
6623
+ from: (filters) => filters?.map((filter) => filter?.filter).filter((filter) => filter.enabled) || [],
6552
6624
  },
6553
6625
  },
6554
6626
  { createdAt: { columnName: 'created_at' } },
@@ -6613,11 +6685,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6613
6685
  this.categoryFilterRepository = categoryFilterRepository;
6614
6686
  }
6615
6687
  async create(params) {
6616
- const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
6617
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadatas: metadatas || [{ shop: null, description: null, title: null }], mostRelevants: mostRelevants || {
6688
+ const { images, mostRelevants, metadatas, ...data } = params;
6689
+ return super.create({
6690
+ ...data,
6691
+ isWishlist: false,
6692
+ metadatas: metadatas || [{ shop: null, description: null, title: null }],
6693
+ mostRelevants: mostRelevants || {
6618
6694
  [exports.Shops.GLAMSHOP]: null,
6619
6695
  [exports.Shops.MENSMARKET]: null,
6620
- }, images: images || {
6696
+ },
6697
+ images: images || {
6621
6698
  [exports.Shops.GLAMSHOP]: {
6622
6699
  brandBanner: null,
6623
6700
  brandBannerMobile: null,
@@ -6628,17 +6705,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6628
6705
  brandBannerMobile: null,
6629
6706
  image: null,
6630
6707
  },
6631
- } }));
6708
+ },
6709
+ });
6632
6710
  }
6633
6711
  async get(identifiers, optionsCache) {
6634
6712
  const id = await this.getId(identifiers.id);
6635
6713
  return super.get({ id }, optionsCache);
6636
6714
  }
6637
6715
  async update(params) {
6638
- const { id, products, metadatas, filters } = params, data = tslib.__rest(params, ["id", "products", "metadatas", "filters"]);
6716
+ const { id, products, metadatas, filters, ...data } = params;
6639
6717
  const categoryId = +(await this.getId(id));
6640
6718
  const [category] = await Promise.all([
6641
- super.update(Object.assign({ id: categoryId === null || categoryId === void 0 ? void 0 : categoryId.toString() }, data)),
6719
+ super.update({ id: categoryId?.toString(), ...data }),
6642
6720
  ...(products ? [this.updateProducts(categoryId, { products })] : []),
6643
6721
  ...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
6644
6722
  ...(filters ? [this.updateFilters(categoryId, { filters })] : []),
@@ -6678,7 +6756,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6678
6756
  }
6679
6757
  async getCategoriesForHome(params) {
6680
6758
  const { categoryIds, shop, limit = 4, optionsCache } = params;
6681
- if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
6759
+ if (!categoryIds?.length)
6682
6760
  return [];
6683
6761
  const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
6684
6762
  const categories = [];
@@ -6699,11 +6777,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6699
6777
  });
6700
6778
  }
6701
6779
  async mountCategory(params) {
6702
- var _a, _b;
6703
6780
  return CategoryMountOperationsHelper.executeMount(params, {
6704
6781
  productRepository: this.productRepository,
6705
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
6706
- defaultCacheTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
6782
+ cacheAdapter: this.cache?.cacheAdapter,
6783
+ defaultCacheTtl: this.cache?.ttlDefault,
6707
6784
  logger: this.logger,
6708
6785
  });
6709
6786
  }
@@ -6722,12 +6799,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6722
6799
  return categoryTree.some((c) => c.id == id.toString());
6723
6800
  }
6724
6801
  async getId(id) {
6725
- var _a, _b;
6726
6802
  if (!Number.isNaN(+id))
6727
6803
  return id;
6728
6804
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
6729
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
6730
- return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
6805
+ if (data?.[0]?.id)
6806
+ return data?.[0]?.id;
6731
6807
  throw new NotFoundError(`Category with id ${id} not found`);
6732
6808
  }
6733
6809
  async updateProducts(categoryId, { products }) {
@@ -6781,7 +6857,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6781
6857
  objects: {
6782
6858
  type: '[category_metadata_insert_input!]',
6783
6859
  required: true,
6784
- value: metadatas.map((m) => (Object.assign({ category_id: categoryId }, m))),
6860
+ value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
6785
6861
  },
6786
6862
  });
6787
6863
  return metadatas;
@@ -6947,7 +7023,7 @@ const fieldsConfiguration$3 = [
6947
7023
  bindPersistData: (value) => ({
6948
7024
  categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
6949
7025
  }),
6950
- from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => category === null || category === void 0 ? void 0 : category.category)) || [],
7026
+ from: (categories) => categories?.map((category) => category?.category) || [],
6951
7027
  },
6952
7028
  },
6953
7029
  ];
@@ -6966,7 +7042,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6966
7042
  this.categoryFilterRepository = categoryFilterRepository;
6967
7043
  }
6968
7044
  async update(params) {
6969
- const { options } = params, data = tslib.__rest(params, ["options"]);
7045
+ const { options, ...data } = params;
6970
7046
  const filter = await super.update(data);
6971
7047
  filter.options = await this.updateOptions(+data.id, { options });
6972
7048
  return filter;
@@ -6988,8 +7064,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6988
7064
  if (hasFilter)
6989
7065
  filterOptions.push(hasFilter);
6990
7066
  }
6991
- catch (_a) {
6992
- const newOption = await this.filterOptionRepository.create(Object.assign(Object.assign({}, options.value[i]), { filterId }));
7067
+ catch {
7068
+ const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
6993
7069
  filterOptions.push(newOption);
6994
7070
  }
6995
7071
  }
@@ -7003,8 +7079,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
7003
7079
  if (hasFilter)
7004
7080
  filterOptions.push(hasFilter);
7005
7081
  }
7006
- catch (_b) {
7007
- const newOption = await this.filterOptionRepository.create(Object.assign(Object.assign({}, options[i]), { filterId }));
7082
+ catch {
7083
+ const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
7008
7084
  filterOptions.push(newOption);
7009
7085
  }
7010
7086
  }
@@ -7125,13 +7201,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7125
7201
  filters: {
7126
7202
  id: {
7127
7203
  operator: exports.Where.IN,
7128
- value: Array.from(new Set(variantsWithNoData.map((item) => { var _a; return (_a = item.product.productId) === null || _a === void 0 ? void 0 : _a.toString(); }))),
7204
+ value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
7129
7205
  },
7130
7206
  },
7131
7207
  });
7132
7208
  products.forEach((product) => {
7133
7209
  result.data
7134
- .filter((variant) => { var _a; return ((_a = variant.product.productId) === null || _a === void 0 ? void 0 : _a.toString()) === product.id.toString(); })
7210
+ .filter((variant) => variant.product.productId?.toString() === product.id.toString())
7135
7211
  .forEach((variant) => {
7136
7212
  variant.product.name = product.name;
7137
7213
  variant.product.group = product.group;
@@ -7164,21 +7240,37 @@ const commonFields = [
7164
7240
  purpose: data.purpose,
7165
7241
  }),
7166
7242
  bindFindFilter: (filters) => {
7167
- 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 && {
7168
- who_must_use: filters.whoMustUse,
7169
- })), (filters.howToUse && {
7170
- how_to_use: filters.howToUse,
7171
- })), (filters.brand && {
7172
- brand_description: filters.brand,
7173
- })), (filters.ingredients && {
7174
- ingredients: filters.ingredients,
7175
- })), (filters.purpose && {
7176
- purpose: filters.purpose,
7177
- }));
7243
+ return {
7244
+ ...(filters?.description && { description: filters.description }),
7245
+ ...(filters.differentials && { differentials: filters.differentials }),
7246
+ ...(filters.whoMustUse && {
7247
+ who_must_use: filters.whoMustUse,
7248
+ }),
7249
+ ...(filters.howToUse && {
7250
+ how_to_use: filters.howToUse,
7251
+ }),
7252
+ ...(filters.brand && {
7253
+ brand_description: filters.brand,
7254
+ }),
7255
+ ...(filters.ingredients && {
7256
+ ingredients: filters.ingredients,
7257
+ }),
7258
+ ...(filters.purpose && {
7259
+ purpose: filters.purpose,
7260
+ }),
7261
+ };
7178
7262
  },
7179
- 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 && {
7180
- who_must_use: descriptionData.whoMustUse,
7181
- })), (descriptionData.howToUse && { how_to_use: descriptionData.howToUse })), (descriptionData.brand && { brand_description: descriptionData.brand })), (descriptionData.ingredients && { ingredients: descriptionData.ingredients })), (descriptionData.purpose && { purpose: descriptionData.purpose }))),
7263
+ bindPersistData: (descriptionData) => ({
7264
+ ...(descriptionData?.description && { description: descriptionData.description }),
7265
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7266
+ ...(descriptionData.whoMustUse && {
7267
+ who_must_use: descriptionData.whoMustUse,
7268
+ }),
7269
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7270
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7271
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7272
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7273
+ }),
7182
7274
  },
7183
7275
  },
7184
7276
  { differentials: { columnName: 'differentials' } },
@@ -7191,13 +7283,13 @@ const commonFields = [
7191
7283
  {
7192
7284
  images: {
7193
7285
  columnName: 'images',
7194
- 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, '","')) || ''}"}` : '{}'); },
7286
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7195
7287
  },
7196
7288
  },
7197
7289
  {
7198
7290
  miniatures: {
7199
7291
  columnName: 'miniatures',
7200
- 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, '","')) || ''}"}` : '{}'); },
7292
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7201
7293
  },
7202
7294
  },
7203
7295
  'name',
@@ -7212,19 +7304,31 @@ const commonFields = [
7212
7304
  subscriberPrice: data.subscriber_price,
7213
7305
  }),
7214
7306
  bindFindFilter: (filters) => {
7215
- 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) && {
7216
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7217
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7218
- subscriber_price: filters.subscriberPrice,
7219
- })), ((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7220
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7221
- }));
7307
+ return {
7308
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7309
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7310
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7311
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7312
+ }),
7313
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7314
+ subscriber_price: filters.subscriberPrice,
7315
+ }),
7316
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7317
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7318
+ }),
7319
+ };
7222
7320
  },
7223
- 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 && {
7224
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7225
- })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice })), (priceData.fullPriceDiscountPercentage >= 0 && {
7226
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7227
- }))),
7321
+ bindPersistData: (priceData) => ({
7322
+ ...(priceData?.price >= 0 && { price: priceData.price }),
7323
+ ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7324
+ ...(priceData.subscriberDiscountPercentage >= 0 && {
7325
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7326
+ }),
7327
+ ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7328
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
7329
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7330
+ }),
7331
+ }),
7228
7332
  },
7229
7333
  },
7230
7334
  { fullPrice: { columnName: 'full_price' } },
@@ -7239,7 +7343,7 @@ const commonFields = [
7239
7343
  stock: {
7240
7344
  columnName: 'stock',
7241
7345
  from: (quantity) => ({ quantity }),
7242
- to: (value) => (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity),
7346
+ to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
7243
7347
  },
7244
7348
  },
7245
7349
  { hasStock: { columnName: 'has_stock' } },
@@ -7278,7 +7382,7 @@ const fieldsConfiguration$2 = [
7278
7382
  categories: { data: value.map((category) => ({ category_id: +category })) },
7279
7383
  }),
7280
7384
  to: (categories) => categories.map((categoryId) => +categoryId),
7281
- 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(); })) || [],
7385
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
7282
7386
  },
7283
7387
  },
7284
7388
  {
@@ -7354,12 +7458,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7354
7458
  fields: fieldsConfiguration$2,
7355
7459
  cache,
7356
7460
  });
7357
- this.bindReviewToModel = (plain) => ProductReview.toInstance(Object.assign(Object.assign({}, is(lodash.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 }));
7358
- this.bindReviewToHasura = (review) => (Object.assign(Object.assign({}, is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId']))), { person_id: review.personId, order_id: review.orderId }));
7461
+ this.bindReviewToModel = (plain) => ProductReview.toInstance({
7462
+ ...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
7463
+ createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
7464
+ updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
7465
+ personId: plain.person_id,
7466
+ orderId: plain.order_id,
7467
+ });
7468
+ this.bindReviewToHasura = (review) => ({
7469
+ ...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
7470
+ person_id: review.personId,
7471
+ order_id: review.orderId,
7472
+ });
7359
7473
  }
7360
7474
  async create(params) {
7361
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
7362
- const product = await super.create(lodash.omit(Object.assign(Object.assign({}, data), { metadata: metadata || { description: null, title: null } }), ['reviews']));
7475
+ const { metadata, ...data } = params;
7476
+ const product = await super.create(lodash.omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
7363
7477
  try {
7364
7478
  product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
7365
7479
  }
@@ -7370,10 +7484,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7370
7484
  return product;
7371
7485
  }
7372
7486
  async get(identifiers, options) {
7373
- var _a;
7374
7487
  const product = Number.isNaN(+identifiers.id)
7375
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7376
- .data) === null || _a === void 0 ? void 0 : _a[0]
7488
+ ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7489
+ .data?.[0]
7377
7490
  : await super.get(identifiers, options);
7378
7491
  if (product.productId)
7379
7492
  throw new NotFoundError('Product not found, it is a variant');
@@ -7381,19 +7494,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7381
7494
  return product;
7382
7495
  }
7383
7496
  async find(params, optionsParams) {
7384
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
7385
- const _o = params || {}, { filters, fields } = _o, options = tslib.__rest(_o, ["filters", "fields"]);
7497
+ const { filters, fields, ...options } = params || {};
7386
7498
  const bindFields = fields ||
7387
7499
  this.fields
7388
7500
  .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7389
7501
  .filter((field) => field !== 'reviews' && field !== 'categories');
7390
- if ((_b = (_a = options.options) === null || _a === void 0 ? void 0 : _a.minimal) === null || _b === void 0 ? void 0 : _b.includes('price'))
7391
- (_c = options.options) === null || _c === void 0 ? void 0 : _c.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7392
- if ((_e = (_d = options.options) === null || _d === void 0 ? void 0 : _d.maximum) === null || _e === void 0 ? void 0 : _e.includes('price'))
7393
- (_f = options.options) === null || _f === void 0 ? void 0 : _f.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7394
- (_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);
7395
- (_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);
7396
- return super.find(Object.assign(Object.assign({}, options), { filters: Object.assign(Object.assign({}, filters), { productId: { operator: exports.Where.ISNULL } }), fields: [
7502
+ if (options.options?.minimal?.includes('price'))
7503
+ options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7504
+ if (options.options?.maximum?.includes('price'))
7505
+ options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7506
+ options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7507
+ options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7508
+ return super.find({
7509
+ ...options,
7510
+ filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
7511
+ fields: [
7397
7512
  ...bindFields,
7398
7513
  ...(bindFields.includes('price')
7399
7514
  ? [
@@ -7402,11 +7517,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7402
7517
  'fullPrice',
7403
7518
  ]
7404
7519
  : []),
7405
- ] }), optionsParams);
7520
+ ],
7521
+ }, optionsParams);
7406
7522
  }
7407
7523
  async getBySlug(slug, options) {
7408
- var _a, _b, _c, _d, _e, _f;
7409
- 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)) {
7524
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7410
7525
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
7411
7526
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7412
7527
  if (cachedData) {
@@ -7425,70 +7540,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7425
7540
  });
7426
7541
  if (!result.data.length)
7427
7542
  return null;
7428
- const product = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.shift();
7543
+ const product = result?.data?.shift();
7429
7544
  RoundProductPricesHelper.roundProductPrices(product);
7430
- 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) {
7545
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7431
7546
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
7432
7547
  await this.cache.cacheAdapter.set({
7433
7548
  key: cacheKey,
7434
7549
  data: serialize(product),
7435
- expirationInSeconds: ((_f = options === null || options === void 0 ? void 0 : options.cache) === null || _f === void 0 ? void 0 : _f.ttl) || this.cache.ttlDefault,
7550
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7436
7551
  });
7437
7552
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7438
7553
  }
7439
7554
  return product;
7440
7555
  }
7441
7556
  async update(params) {
7442
- const _a = lodash.omit(params, ['categories', 'rate']), { kitProducts, reviews, id: checkId, metadata } = _a, data = tslib.__rest(_a, ["kitProducts", "reviews", "id", "metadata"]);
7557
+ const { kitProducts, reviews, id: checkId, metadata, ...data } = lodash.omit(params, ['categories', 'rate']);
7443
7558
  const plainData = this.paramsToPlain({ id: checkId });
7444
7559
  const id = await this.getId(plainData.id);
7445
- const product = await super.update(Object.assign({ id }, data));
7560
+ const product = await super.update({ id, ...data });
7446
7561
  product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
7447
7562
  product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
7448
7563
  product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
7449
7564
  return product;
7450
7565
  }
7451
7566
  async fetchProductReviews(filters, options) {
7452
- var _a, _b, _c, _d, _e;
7453
7567
  const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
7454
7568
  const dependencies = {
7455
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
7569
+ cacheAdapter: this.cache?.cacheAdapter,
7456
7570
  logger: this.logger,
7457
7571
  modelName: this.model.name,
7458
- defaultTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
7572
+ defaultTtl: this.cache?.ttlDefault,
7459
7573
  };
7460
- if (ProductReviewCacheHelper.shouldUseCache((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter, options)) {
7574
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7461
7575
  const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
7462
7576
  if (cachedData)
7463
7577
  return cachedData;
7464
7578
  }
7465
- const limit = (filters === null || filters === void 0 ? void 0 : filters.limit) || 500;
7579
+ const limit = filters?.limit || 500;
7466
7580
  const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
7467
7581
  const reviews = ProductReviewOperationsHelper.processProductsToReviews({
7468
7582
  data,
7469
7583
  getReviewStatus: this.getReviewStatus.bind(this),
7470
7584
  });
7471
7585
  const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
7472
- if (ProductReviewCacheHelper.shouldUseCache((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter, options)) {
7586
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7473
7587
  await ProductReviewCacheHelper.saveToCache({
7474
7588
  key: cacheKey,
7475
7589
  data: filteredReviews,
7476
- ttl: (_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl,
7590
+ ttl: options?.cache?.ttl,
7477
7591
  dependencies,
7478
7592
  });
7479
7593
  }
7480
7594
  return filteredReviews;
7481
7595
  }
7482
7596
  async fetchReviews(status, options) {
7483
- var _a, _b, _c, _d, _e;
7484
7597
  const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
7485
7598
  const dependencies = {
7486
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
7599
+ cacheAdapter: this.cache?.cacheAdapter,
7487
7600
  logger: this.logger,
7488
7601
  modelName: this.model.name,
7489
- defaultTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
7602
+ defaultTtl: this.cache?.ttlDefault,
7490
7603
  };
7491
- if (ProductReviewCacheHelper.shouldUseCache((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter, options)) {
7604
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7492
7605
  const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
7493
7606
  if (cachedData)
7494
7607
  return cachedData;
@@ -7499,18 +7612,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7499
7612
  reviewsFields: this.reviewsFields,
7500
7613
  };
7501
7614
  const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
7502
- if (ProductReviewCacheHelper.shouldUseCache((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter, options)) {
7615
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7503
7616
  await ProductReviewCacheHelper.saveToCache({
7504
7617
  key: cacheKey,
7505
7618
  data: reviews,
7506
- ttl: (_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl,
7619
+ ttl: options?.cache?.ttl,
7507
7620
  dependencies,
7508
7621
  });
7509
7622
  }
7510
7623
  return reviews;
7511
7624
  }
7512
7625
  async findCatalog(params, mainGender, options) {
7513
- 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' })), lodash.omit(params.orderBy, ['hasStock', 'intGender'])) }), options);
7626
+ const result = await this.find({
7627
+ ...params,
7628
+ filters: { ...params.filters, published: true },
7629
+ orderBy: {
7630
+ hasStock: 'desc',
7631
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7632
+ ...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
7633
+ },
7634
+ }, options);
7514
7635
  return result;
7515
7636
  }
7516
7637
  async cleanShoppingCountFromIds(ids) {
@@ -7581,17 +7702,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7581
7702
  return plainData.metadata;
7582
7703
  }
7583
7704
  async getId(id) {
7584
- var _a, _b;
7585
7705
  if (!Number.isNaN(+id))
7586
7706
  return id;
7587
7707
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
7588
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
7589
- return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
7708
+ if (data?.[0]?.id)
7709
+ return data?.[0]?.id;
7590
7710
  throw new NotFoundError(`Product with id ${id} not found`);
7591
7711
  }
7592
7712
  async findReviewsByProduct(productId, options) {
7593
- var _a, _b, _c, _d, _e;
7594
- 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)) {
7713
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7595
7714
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7596
7715
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7597
7716
  if (cachedData) {
@@ -7608,13 +7727,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7608
7727
  required: true,
7609
7728
  },
7610
7729
  });
7611
- const reviews = data === null || data === void 0 ? void 0 : data.map((review) => this.bindReviewToModel(review));
7612
- 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) {
7730
+ const reviews = data?.map((review) => this.bindReviewToModel(review));
7731
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
7613
7732
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7614
7733
  await this.cache.cacheAdapter.set({
7615
7734
  key: cacheKey,
7616
7735
  data: serialize(reviews),
7617
- expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
7736
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7618
7737
  });
7619
7738
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7620
7739
  }
@@ -7638,23 +7757,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7638
7757
  async getReviewByPersonId(personId, productId, orderId) {
7639
7758
  const { product_review: data } = await this.query('product_review', this.reviewsFields, {
7640
7759
  where: {
7641
- value: Object.assign({ product_id: { _eq: productId }, person_id: { _eq: personId } }, (orderId && { order_id: { _eq: orderId } })),
7760
+ value: {
7761
+ product_id: { _eq: productId },
7762
+ person_id: { _eq: personId },
7763
+ ...(orderId && { order_id: { _eq: orderId } }),
7764
+ },
7642
7765
  type: 'product_review_bool_exp',
7643
7766
  required: true,
7644
7767
  },
7645
7768
  });
7646
- return (data === null || data === void 0 ? void 0 : data[0]) && this.bindReviewToModel(data[0]);
7769
+ return data?.[0] && this.bindReviewToModel(data[0]);
7647
7770
  }
7648
7771
  async getReviewByAuthorAndEmail(params) {
7649
7772
  const { author, email, productId, orderId } = params;
7650
7773
  const { product_review: data } = await this.query('product_review', this.reviewsFields, {
7651
7774
  where: {
7652
- value: Object.assign({ product_id: { _eq: productId }, author: { _eq: author }, email: { _eq: email } }, (orderId && { order_id: { _eq: orderId } })),
7775
+ value: {
7776
+ product_id: { _eq: productId },
7777
+ author: { _eq: author },
7778
+ email: { _eq: email },
7779
+ ...(orderId && { order_id: { _eq: orderId } }),
7780
+ },
7653
7781
  type: 'product_review_bool_exp',
7654
7782
  required: true,
7655
7783
  },
7656
7784
  });
7657
- return (data === null || data === void 0 ? void 0 : data[0]) && this.bindReviewToModel(data[0]);
7785
+ return data?.[0] && this.bindReviewToModel(data[0]);
7658
7786
  }
7659
7787
  async productVariantFullReport() {
7660
7788
  const dependencies = {
@@ -7803,7 +7931,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
7803
7931
  });
7804
7932
  }
7805
7933
  async getNotificationsReport(params, orderBy, pagination) {
7806
- 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 } }));
7934
+ const query = {
7935
+ ...(params.productId && { product_id: { _eq: params.productId } }),
7936
+ ...(params.ean && { ean: { _eq: params.ean } }),
7937
+ ...(params.sku && { sku: { _eq: params.sku } }),
7938
+ ...(params.name && { name: { _iregex: params.name } }),
7939
+ ...(params.categoryId && { category_id: { _eq: params.categoryId } }),
7940
+ ...(params.category && { category: { _iregex: params.category } }),
7941
+ ...(params.reference && { category_reference: { _eq: params.reference } }),
7942
+ ...(params.emailsCount && { emails_registered: { _eq: params.emailsCount } }),
7943
+ };
7807
7944
  const orderByField = {
7808
7945
  [orderBy.field]: orderBy.direction,
7809
7946
  };
@@ -7819,8 +7956,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
7819
7956
  required: true,
7820
7957
  },
7821
7958
  });
7822
- const data = (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
7823
- ? 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))
7959
+ const data = pagination?.limit
7960
+ ? reportStockNotification.slice(pagination?.offset, pagination?.offset + pagination?.limit)
7824
7961
  : reportStockNotification;
7825
7962
  return {
7826
7963
  data,
@@ -7836,7 +7973,7 @@ const fieldsConfiguration$1 = [
7836
7973
  productId: {
7837
7974
  columnName: 'main_product_id',
7838
7975
  to: (value) => +value,
7839
- from: (value) => value === null || value === void 0 ? void 0 : value.toString(),
7976
+ from: (value) => value?.toString(),
7840
7977
  },
7841
7978
  },
7842
7979
  { EAN: { columnName: 'ean' } },
@@ -7853,19 +7990,31 @@ const fieldsConfiguration$1 = [
7853
7990
  }),
7854
7991
  bindFindFilter: (sentence) => {
7855
7992
  const filters = Object.values(sentence).shift();
7856
- 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) && {
7857
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7858
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7859
- subscriber_price: filters.subscriberPrice,
7860
- })), ((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7861
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7862
- }));
7993
+ return {
7994
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7995
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7996
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7997
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7998
+ }),
7999
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
8000
+ subscriber_price: filters.subscriberPrice,
8001
+ }),
8002
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
8003
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
8004
+ }),
8005
+ };
7863
8006
  },
7864
- 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 && {
7865
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7866
- })), (((priceData === null || priceData === void 0 ? void 0 : priceData.subscriberPrice) || 0) >= 0 && { subscriber_price: priceData.subscriberPrice })), (priceData.fullPriceDiscountPercentage >= 0 && {
7867
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7868
- }))),
8007
+ bindPersistData: (priceData) => ({
8008
+ ...((priceData?.price || 0) >= 0 && { price: priceData.price }),
8009
+ ...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
8010
+ ...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
8011
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
8012
+ }),
8013
+ ...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
8014
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
8015
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
8016
+ }),
8017
+ }),
7869
8018
  },
7870
8019
  },
7871
8020
  { fullPrice: { columnName: 'full_price' } },
@@ -7877,7 +8026,7 @@ const fieldsConfiguration$1 = [
7877
8026
  stock: {
7878
8027
  columnName: 'stock',
7879
8028
  from: (quantity) => ({ quantity }),
7880
- to: (value) => (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity),
8029
+ to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
7881
8030
  },
7882
8031
  },
7883
8032
  { hasStock: { columnName: 'has_stock' } },
@@ -7910,41 +8059,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7910
8059
  });
7911
8060
  }
7912
8061
  async get(identifiers) {
7913
- var _a;
7914
8062
  if (!identifiers.id) {
7915
8063
  throw new NotFoundError('Variant ID is required');
7916
8064
  }
7917
8065
  const variant = Number.isNaN(+identifiers.id)
7918
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
8066
+ ? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
7919
8067
  : await super.get(identifiers);
7920
8068
  if (!variant.productId)
7921
8069
  throw new NotFoundError('Variant not found, it is a product');
7922
8070
  return variant;
7923
8071
  }
7924
8072
  async find(params) {
7925
- const _a = params || {}, { filters } = _a, options = tslib.__rest(_a, ["filters"]);
7926
- return super.find(Object.assign(Object.assign({}, options), { filters: Object.assign({ productId: { operator: exports.Where.ISNOTNULL } }, filters) }));
8073
+ const { filters, ...options } = params || {};
8074
+ return super.find({ ...options, filters: { productId: { operator: exports.Where.ISNOTNULL }, ...filters } });
7927
8075
  }
7928
8076
  async update(params) {
7929
- const { productId, id: checkId } = params, data = tslib.__rest(params, ["productId", "id"]);
8077
+ const { productId, id: checkId, ...data } = params;
7930
8078
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
7931
8079
  if (!dataWithProductId.id) {
7932
8080
  throw new NotFoundError('Variant ID is required for update');
7933
8081
  }
7934
8082
  const id = await this.getId(dataWithProductId.id);
7935
- const product = await super.update(Object.assign({ id }, data));
8083
+ const product = await super.update({ id, ...data });
7936
8084
  if (dataWithProductId.productId) {
7937
8085
  product.productId = dataWithProductId.productId;
7938
8086
  }
7939
8087
  return product;
7940
8088
  }
7941
8089
  async getId(id) {
7942
- var _a, _b;
7943
8090
  if (!Number.isNaN(+id))
7944
8091
  return id;
7945
8092
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
7946
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
7947
- return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
8093
+ if (data?.[0]?.id)
8094
+ return data?.[0]?.id;
7948
8095
  throw new NotFoundError(`Product with id ${id} not found`);
7949
8096
  }
7950
8097
  }
@@ -7975,11 +8122,14 @@ const fieldsConfiguration = [
7975
8122
  bindPersistData: (value) => {
7976
8123
  return {
7977
8124
  brand_condition: value.brand,
7978
- tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
8125
+ tag_condition: value?.tags || [],
7979
8126
  };
7980
8127
  },
7981
8128
  bindFindFilter: (sentence) => {
7982
- return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
8129
+ return {
8130
+ ...(sentence.brand ? { brand_condition: sentence.brand } : {}),
8131
+ ...(sentence.tags ? { tag_condition: sentence.tags } : {}),
8132
+ };
7983
8133
  },
7984
8134
  },
7985
8135
  },
@@ -7991,7 +8141,7 @@ const fieldsConfiguration = [
7991
8141
  bindPersistData: (value) => ({
7992
8142
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
7993
8143
  }),
7994
- from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter)) || [],
8144
+ from: (filters) => filters?.map((filter) => filter?.filter) || [],
7995
8145
  },
7996
8146
  },
7997
8147
  { createdAt: { columnName: 'created_at' } },
@@ -8059,12 +8209,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8059
8209
  this.categoryProductRepository = categoryProductRepository;
8060
8210
  }
8061
8211
  async create(params) {
8062
- var _a;
8063
- const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
8064
- 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 || {
8212
+ const { images, mostRelevants, metadatas, ...data } = params;
8213
+ return super.create({
8214
+ ...data,
8215
+ isWishlist: true,
8216
+ isCollection: true,
8217
+ brandCategory: false,
8218
+ metadatas: metadatas || [{ shop: data.shop ?? null, description: data.description, title: data.name }],
8219
+ mostRelevants: mostRelevants || {
8065
8220
  [exports.Shops.GLAMSHOP]: null,
8066
8221
  [exports.Shops.MENSMARKET]: null,
8067
- }, images: images || {
8222
+ },
8223
+ images: images || {
8068
8224
  [exports.Shops.GLAMSHOP]: {
8069
8225
  brandBanner: null,
8070
8226
  brandBannerMobile: null,
@@ -8075,7 +8231,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8075
8231
  brandBannerMobile: null,
8076
8232
  image: null,
8077
8233
  },
8078
- } }));
8234
+ },
8235
+ });
8079
8236
  }
8080
8237
  async get(identifiers) {
8081
8238
  const data = await super.get(identifiers);
@@ -8084,14 +8241,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8084
8241
  return data;
8085
8242
  }
8086
8243
  async find(params) {
8087
- const { filters } = params, rest = tslib.__rest(params, ["filters"]);
8088
- return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: exports.Where.EQUALS, value: true } }) }));
8244
+ const { filters, ...rest } = params;
8245
+ return await super.find({
8246
+ ...rest,
8247
+ filters: {
8248
+ ...filters,
8249
+ isWishlist: { operator: exports.Where.EQUALS, value: true },
8250
+ },
8251
+ });
8089
8252
  }
8090
8253
  async update(params) {
8091
- const _a = lodash.omit(params, ['products', 'filters']), { id: checkId, metadatas } = _a, data = tslib.__rest(_a, ["id", "metadatas"]);
8254
+ const { id: checkId, metadatas, ...data } = lodash.omit(params, ['products', 'filters']);
8092
8255
  const plainData = this.paramsToPlain({ id: checkId });
8093
8256
  const id = plainData.id;
8094
- const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
8257
+ const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
8095
8258
  category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
8096
8259
  return category;
8097
8260
  }
@@ -8154,11 +8317,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8154
8317
  return data;
8155
8318
  }
8156
8319
  async findBfluOrGlamgirlWishlists(params, shops) {
8157
- var _a, _b;
8158
- return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true, shops: { operator: exports.Where.LIKE, value: shops }, personType: (_b = (_a = params.filters) === null || _a === void 0 ? void 0 : _a.personType) !== null && _b !== void 0 ? _b : {
8320
+ return this.find({
8321
+ ...params,
8322
+ filters: {
8323
+ ...params.filters,
8324
+ published: true,
8325
+ shops: { operator: exports.Where.LIKE, value: shops },
8326
+ personType: params.filters?.personType ?? {
8159
8327
  operator: exports.Where.IN,
8160
8328
  value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
8161
- } }), orderBy: Object.assign({ personHasPhoto: 'desc' }, lodash.omit(params.orderBy, ['personHasPhoto'])) }));
8329
+ },
8330
+ },
8331
+ orderBy: {
8332
+ personHasPhoto: 'desc',
8333
+ ...lodash.omit(params.orderBy, ['personHasPhoto']),
8334
+ },
8335
+ });
8162
8336
  }
8163
8337
  getCategoriesForHome() {
8164
8338
  return;
@@ -8366,7 +8540,7 @@ class PagarmePaymentFactoryHelper {
8366
8540
  checkoutId: checkout.id,
8367
8541
  totalPrice: checkout.totalPrice,
8368
8542
  paymentProvider: exports.PaymentProviders.PAGARME,
8369
- transaction: Object.assign(Object.assign({}, resultData), { paidAt: new Date() }),
8543
+ transaction: { ...resultData, paidAt: new Date() },
8370
8544
  });
8371
8545
  return payment;
8372
8546
  }
@@ -8393,7 +8567,6 @@ class PagarmeCardAxiosAdapter {
8393
8567
  this.orderBlockedRepository = orderBlockedRepository;
8394
8568
  }
8395
8569
  async pay(checkout, card) {
8396
- var _a;
8397
8570
  try {
8398
8571
  const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
8399
8572
  checkout,
@@ -8419,7 +8592,7 @@ class PagarmeCardAxiosAdapter {
8419
8592
  if (error instanceof PaymentError) {
8420
8593
  throw error;
8421
8594
  }
8422
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, (_a = error.response) === null || _a === void 0 ? void 0 : _a.data);
8595
+ throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
8423
8596
  }
8424
8597
  }
8425
8598
  async addCard(card) {
@@ -8486,7 +8659,10 @@ class PagarmeCardAxiosAdapter {
8486
8659
  const { data } = await axios__default["default"]({
8487
8660
  method: 'POST',
8488
8661
  url: `${this.credentials.URL}/transactions`,
8489
- data: Object.assign(Object.assign({}, info), { api_key: this.credentials.API_KEY }),
8662
+ data: {
8663
+ ...info,
8664
+ api_key: this.credentials.API_KEY,
8665
+ },
8490
8666
  });
8491
8667
  return data;
8492
8668
  }
@@ -8497,7 +8673,6 @@ class PagarmeCardAxiosAdapter {
8497
8673
  }
8498
8674
  }
8499
8675
  createCardPayment(checkout, card) {
8500
- var _a, _b, _c, _d, _e, _f;
8501
8676
  return {
8502
8677
  api_key: this.credentials.API_KEY,
8503
8678
  amount: Math.floor(checkout.totalPrice * 100),
@@ -8524,14 +8699,14 @@ class PagarmeCardAxiosAdapter {
8524
8699
  name: checkout.user.displayName,
8525
8700
  address: {
8526
8701
  country: 'br',
8527
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
8528
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
8529
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
8530
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
8531
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
8702
+ state: checkout.billingAddress ? checkout.billingAddress.state : checkout.shippingAddress?.state,
8703
+ city: checkout.billingAddress ? checkout.billingAddress.city : checkout.shippingAddress?.city,
8704
+ neighborhood: checkout.billingAddress ? checkout.billingAddress.district : checkout.shippingAddress?.district,
8705
+ street: checkout.billingAddress ? checkout.billingAddress.street : checkout.shippingAddress?.street,
8706
+ street_number: checkout.billingAddress ? checkout.billingAddress.number : checkout.shippingAddress?.number,
8532
8707
  zipcode: checkout.billingAddress
8533
8708
  ? checkout.billingAddress.zip.replace('-', '')
8534
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
8709
+ : checkout.shippingAddress?.zip.replace('-', ''),
8535
8710
  },
8536
8711
  },
8537
8712
  items: checkout.lineItems.map((item) => {
@@ -8553,7 +8728,6 @@ class PagarmePixAxiosAdapter {
8553
8728
  this.paymentRepository = paymentRepository;
8554
8729
  }
8555
8730
  async pay(checkout) {
8556
- var _a;
8557
8731
  try {
8558
8732
  const payload = this.createPixPayment(checkout);
8559
8733
  const result = await axios__default["default"]({
@@ -8577,7 +8751,7 @@ class PagarmePixAxiosAdapter {
8577
8751
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
8578
8752
  checkoutId: checkout.id,
8579
8753
  userEmail: checkout.user.email,
8580
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
8754
+ info: error.response?.data,
8581
8755
  });
8582
8756
  }
8583
8757
  }