@infrab4a/connect 5.0.0-alpha.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.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,26 +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
- const fieldOption = (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
3555
- return fieldOption ? ((_b = Object.values(fieldOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || fieldName : fieldName;
3607
+ const finalFieldName = fieldName.toString().split('.').pop();
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;
3556
3619
  };
3557
3620
  return [
3558
- ...(((_a = aggregates === null || aggregates === void 0 ? void 0 : aggregates.minimal) === null || _a === void 0 ? void 0 : _a.length)
3621
+ ...(aggregates?.minimal?.length
3559
3622
  ? [
3560
3623
  {
3561
3624
  min: aggregates.minimal.map(convertFieldName),
3562
3625
  },
3563
3626
  ]
3564
3627
  : []),
3565
- ...(((_b = aggregates === null || aggregates === void 0 ? void 0 : aggregates.maximum) === null || _b === void 0 ? void 0 : _b.length)
3628
+ ...(aggregates?.maximum?.length
3566
3629
  ? [
3567
3630
  {
3568
3631
  max: aggregates.maximum.map(convertFieldName),
@@ -3572,48 +3635,52 @@ class HasuraFindResultHelper {
3572
3635
  ];
3573
3636
  }
3574
3637
  static processMinimalAggregates(params) {
3575
- var _a;
3576
3638
  const { result, tableName, findOptions, fields } = params;
3577
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
3639
+ return findOptions?.minimal?.length
3578
3640
  ? {
3579
3641
  minimal: findOptions.minimal.reduce((minimals, current) => {
3580
- var _a;
3581
- 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
+ };
3582
3647
  }, {}),
3583
3648
  }
3584
3649
  : {};
3585
3650
  }
3586
3651
  static processMaximumAggregates(params) {
3587
- var _a;
3588
3652
  const { result, tableName, findOptions, fields } = params;
3589
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _a === void 0 ? void 0 : _a.length)
3653
+ return findOptions?.maximum?.length
3590
3654
  ? {
3591
3655
  maximum: findOptions.maximum.reduce((maximums, current) => {
3592
- var _a;
3593
- 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
+ };
3594
3661
  }, {}),
3595
3662
  }
3596
3663
  : {};
3597
3664
  }
3598
3665
  static processDistinctResults(params) {
3599
- var _a, _b;
3600
3666
  const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
3601
- return ((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _a === void 0 ? void 0 : _a.length)
3667
+ return findOptions?.distinct?.length
3602
3668
  ? {
3603
- distinct: (_b = lastDistinct[tableFiltersNamed]) !== null && _b !== void 0 ? _b : (lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
3604
- var _a, _b;
3605
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3606
- const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
3607
- return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
3608
- }, {})),
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
+ }, {})),
3609
3679
  }
3610
3680
  : {};
3611
3681
  }
3612
3682
  static bindAttributesToColumns(attributes, fields) {
3613
- return attributes.map((attr) => {
3614
- var _a;
3615
- return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
3616
- });
3683
+ return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
3617
3684
  }
3618
3685
  }
3619
3686
 
@@ -3643,16 +3710,19 @@ class HasuraFindVariablesHelper {
3643
3710
  };
3644
3711
  }
3645
3712
  static buildDistinctVariables(params) {
3646
- var _a, _b;
3647
3713
  const { distinct, tableName, fields, filtersVariables } = params;
3648
- const distinctOption = (_a = fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3649
- const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
3650
- 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`]: {
3651
3720
  type: `${tableName}_select_column!`,
3652
3721
  list: true,
3653
3722
  value: fieldName,
3654
3723
  name: 'distinct_on',
3655
- } });
3724
+ },
3725
+ };
3656
3726
  }
3657
3727
  static bindOrderByAttributes(orderBy, fields) {
3658
3728
  return Object.keys(orderBy).reduce((acc, current) => [
@@ -3672,11 +3742,17 @@ class HasuraFindQueryBuilderHelper {
3672
3742
  const { tableName, fields, params, lastDistinct } = queryParams;
3673
3743
  const { filters, limits, orderBy, options: findOptions } = params || {};
3674
3744
  const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
3675
- const countVariables = Object.assign(Object.assign({}, HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields })), filtersVariables);
3676
- 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
+ };
3677
3753
  const queries = [
3678
3754
  this.buildMainQuery({ tableName, fields, params, mainVariables }),
3679
- ...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
3755
+ ...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
3680
3756
  ...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
3681
3757
  ];
3682
3758
  return queries.filter(Boolean);
@@ -3685,26 +3761,23 @@ class HasuraFindQueryBuilderHelper {
3685
3761
  const { tableName, fields, params: findParams, mainVariables } = params;
3686
3762
  return {
3687
3763
  operation: tableName,
3688
- fields: (findParams === null || findParams === void 0 ? void 0 : findParams.fields)
3764
+ fields: findParams?.fields
3689
3765
  ? findParams.fields
3690
- .map((fieldName) => {
3691
- var _a;
3692
- return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
3693
- })
3766
+ .map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
3767
+ fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
3694
3768
  .filter(Boolean)
3695
3769
  : fields,
3696
3770
  variables: mainVariables,
3697
3771
  };
3698
3772
  }
3699
3773
  static buildAggregateQuery(params) {
3700
- var _a;
3701
3774
  const { tableName, findOptions, countVariables } = params;
3702
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
3775
+ const enableCount = findOptions?.enableCount ?? true;
3703
3776
  const aggregateFields = [
3704
3777
  ...(enableCount ? ['count'] : []),
3705
3778
  ...HasuraFindResultHelper.bindAggregateAttributes({
3706
- aggregates: { minimal: findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal, maximum: findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum },
3707
- fields: [], // será preenchido no contexto correto
3779
+ aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
3780
+ fields: params.fields,
3708
3781
  }),
3709
3782
  ];
3710
3783
  return aggregateFields.length > 0
@@ -3722,15 +3795,14 @@ class HasuraFindQueryBuilderHelper {
3722
3795
  : [];
3723
3796
  }
3724
3797
  static buildDistinctQueries(params) {
3725
- var _a;
3726
3798
  const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
3727
3799
  const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
3728
- 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]) {
3729
3801
  return [];
3730
3802
  }
3731
3803
  return findOptions.distinct.map((distinct) => {
3732
- var _a;
3733
- 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);
3734
3806
  return {
3735
3807
  operation: {
3736
3808
  name: tableName,
@@ -3750,18 +3822,16 @@ class HasuraFindQueryBuilderHelper {
3750
3822
 
3751
3823
  class HasuraFindOperationsHelper {
3752
3824
  static async executeFindOperation(operationParams) {
3753
- var _a;
3754
3825
  const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
3755
3826
  const logger = DebugHelper.from(operationParams, 'find');
3756
3827
  const { filters, options: findOptions } = params || {};
3757
3828
  const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
3758
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
3759
- // Verifica cache primeiro
3829
+ const enableCount = findOptions?.enableCount ?? true;
3760
3830
  const cachedResult = await HasuraFindCacheHelper.getCachedResult({
3761
3831
  cache,
3762
3832
  model,
3763
3833
  findParams: params,
3764
- cacheOptions: cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cache,
3834
+ cacheOptions: cacheOptions?.cache,
3765
3835
  logger,
3766
3836
  });
3767
3837
  if (cachedResult) {
@@ -3776,7 +3846,6 @@ class HasuraFindOperationsHelper {
3776
3846
  lastDistinct,
3777
3847
  });
3778
3848
  }
3779
- // Constrói e executa queries
3780
3849
  const queries = HasuraFindQueryBuilderHelper.buildCompleteQuery({
3781
3850
  tableName,
3782
3851
  fields,
@@ -3784,16 +3853,14 @@ class HasuraFindOperationsHelper {
3784
3853
  lastDistinct,
3785
3854
  });
3786
3855
  const result = await query(queries);
3787
- // Salva no cache se habilitado
3788
3856
  await HasuraFindCacheHelper.setCachedResult({
3789
3857
  cache,
3790
3858
  model,
3791
3859
  findParams: params,
3792
- cacheOptions: cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cache,
3860
+ cacheOptions: cacheOptions?.cache,
3793
3861
  result,
3794
3862
  logger,
3795
3863
  });
3796
- // Processa e retorna resultado
3797
3864
  return HasuraFindResultHelper.processResult({
3798
3865
  result,
3799
3866
  tableName,
@@ -3812,9 +3879,8 @@ class HasuraGetCacheHelper {
3812
3879
  return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
3813
3880
  }
3814
3881
  static async getCachedData(cache, params) {
3815
- var _a;
3816
3882
  const { identifiers, options, model, logger } = params;
3817
- 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)
3818
3884
  return null;
3819
3885
  const cacheKey = this.generateCacheKey(model, identifiers);
3820
3886
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -3824,15 +3890,14 @@ class HasuraGetCacheHelper {
3824
3890
  return model.toInstance(deserialize(cachedData));
3825
3891
  }
3826
3892
  static async saveCacheData(cache, params) {
3827
- var _a, _b;
3828
3893
  const { identifiers, options, data, logger } = params;
3829
- 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)
3830
3895
  return;
3831
3896
  const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
3832
3897
  await cache.cacheAdapter.set({
3833
3898
  key: cacheKey,
3834
3899
  data: serialize(data),
3835
- 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,
3836
3901
  });
3837
3902
  logger.log(`Dados salvos no cache: ${cacheKey}`);
3838
3903
  }
@@ -3843,18 +3908,20 @@ class HasuraGetVariablesHelper {
3843
3908
  const { model, fields, repository } = params;
3844
3909
  const instance = model.toInstance(identifiers);
3845
3910
  return model.identifiersFields.reduce((ids, identifier) => {
3846
- var _a;
3847
3911
  const identifierBinded = identifier;
3848
3912
  if (lodash.isNil(instance[identifierBinded]))
3849
3913
  return ids;
3850
3914
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3851
- 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) ||
3852
3916
  identifiers[identifier];
3853
- return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
3917
+ return {
3918
+ ...ids,
3919
+ [columnOption.columnName]: {
3854
3920
  type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
3855
3921
  value,
3856
3922
  required: true,
3857
- } });
3923
+ },
3924
+ };
3858
3925
  }, {});
3859
3926
  }
3860
3927
  }
@@ -3911,7 +3978,7 @@ class HasuraUpdateDataHelper {
3911
3978
  static getValueByAction(options) {
3912
3979
  if (options instanceof BaseModel)
3913
3980
  return options.toPlain();
3914
- if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
3981
+ if (lodash.isNil(options?.action))
3915
3982
  return options;
3916
3983
  if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
3917
3984
  return null;
@@ -3920,9 +3987,12 @@ class HasuraUpdateDataHelper {
3920
3987
  static paramsToPlain(params, model) {
3921
3988
  if (model.isModel(params))
3922
3989
  return params.toPlain();
3923
- return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && {
3924
- [currentKey]: this.getValueByAction(is(params[currentKey])),
3925
- }))), {});
3990
+ return Object.keys(params).reduce((data, currentKey) => ({
3991
+ ...data,
3992
+ ...(params[currentKey] !== undefined && {
3993
+ [currentKey]: this.getValueByAction(is(params[currentKey])),
3994
+ }),
3995
+ }), {});
3926
3996
  }
3927
3997
  static getIdentifiersFromData(data, model) {
3928
3998
  const instance = model.toInstance(data);
@@ -3941,13 +4011,15 @@ class HasuraUpdateVariablesHelper {
3941
4011
  static getUpdateModelKeys(data, model, fields) {
3942
4012
  const instance = model.toInstance(data);
3943
4013
  return model.identifiersFields.reduce((ids, identifier) => {
3944
- var _a;
3945
4014
  const identifierBinded = identifier;
3946
4015
  if (lodash.isNil(instance.identifier[identifierBinded]))
3947
4016
  return ids;
3948
4017
  const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
3949
- 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];
3950
- 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
+ };
3951
4023
  }, {});
3952
4024
  }
3953
4025
  static getIdentifierFields(model, fields) {
@@ -3975,9 +4047,7 @@ class HasuraUpdateOperationsHelper {
3975
4047
  const { data, updateGraphQLOperation, updateGraphQLObjectType, updateGraphQLPKType, model, fields, cache, mutation, convertDataToHasura, } = params;
3976
4048
  const logger = DebugHelper.from(params, 'update');
3977
4049
  const plainData = HasuraUpdateDataHelper.paramsToPlain(data, model);
3978
- // Gerencia cache se disponível
3979
4050
  await this.handleCacheRemoval({ plainData, model, cache, logger });
3980
- // Executa mutation
3981
4051
  const identifierFields = HasuraUpdateVariablesHelper.getIdentifierFields(model, fields);
3982
4052
  const mutationVariables = HasuraUpdateVariablesHelper.buildMutationVariables({
3983
4053
  plainData,
@@ -3992,13 +4062,13 @@ class HasuraUpdateOperationsHelper {
3992
4062
  }
3993
4063
  static async handleCacheRemoval(params) {
3994
4064
  const { plainData, model, cache, logger } = params;
3995
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4065
+ if (!cache?.cacheAdapter)
3996
4066
  return;
3997
4067
  const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
3998
4068
  if (Object.keys(identifiers).length > 0) {
3999
4069
  const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
4000
4070
  await cache.cacheAdapter.remove(cacheKey);
4001
- logger === null || logger === void 0 ? void 0 : logger.log(`Cache removido: ${cacheKey}`);
4071
+ logger?.log(`Cache removido: ${cacheKey}`);
4002
4072
  }
4003
4073
  }
4004
4074
  }
@@ -4020,9 +4090,8 @@ class FirestoreCacheKeyGeneratorHelper {
4020
4090
 
4021
4091
  class FirestoreCacheHelper {
4022
4092
  static async getCachedData(cache, params) {
4023
- var _a;
4024
4093
  const { model, identifiers, options, logger, req } = params;
4025
- 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)
4026
4095
  return null;
4027
4096
  const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
4028
4097
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -4033,9 +4102,8 @@ class FirestoreCacheHelper {
4033
4102
  return null;
4034
4103
  }
4035
4104
  static async getCachedFindData(cache, params) {
4036
- var _a;
4037
4105
  const { model, find, options, logger } = params;
4038
- 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)
4039
4107
  return null;
4040
4108
  const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
4041
4109
  const cachedData = await cache.cacheAdapter.get(cacheKey);
@@ -4047,7 +4115,7 @@ class FirestoreCacheHelper {
4047
4115
  }
4048
4116
  static async saveCacheData(cache, params) {
4049
4117
  const { cacheKey, data, expirationInSeconds, logger, req } = params;
4050
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4118
+ if (!cache?.cacheAdapter)
4051
4119
  return;
4052
4120
  await cache.cacheAdapter.set({
4053
4121
  key: cacheKey,
@@ -4059,7 +4127,7 @@ class FirestoreCacheHelper {
4059
4127
  }
4060
4128
  static async removeCacheData(cache, params) {
4061
4129
  const { cacheKey, logger } = params;
4062
- if (!(cache === null || cache === void 0 ? void 0 : cache.cacheAdapter))
4130
+ if (!cache?.cacheAdapter)
4063
4131
  return;
4064
4132
  await cache.cacheAdapter.remove(cacheKey);
4065
4133
  logger.log(`Cache removido: ${cacheKey}`);
@@ -4077,7 +4145,7 @@ class FirestoreOperationsHelper {
4077
4145
  this.model = model;
4078
4146
  }
4079
4147
  buildInstanceFromIdentifiers(identifiers) {
4080
- 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] }), {}));
4081
4149
  }
4082
4150
  async validateDocumentExists(docRef, collectionName, identifiers) {
4083
4151
  const docSnapshot = await docRef.get();
@@ -4099,7 +4167,7 @@ class FirestoreOperationsHelper {
4099
4167
  calculateCount(data, limits) {
4100
4168
  if (data.length <= 0)
4101
4169
  return 0;
4102
- if (data.length < (limits === null || limits === void 0 ? void 0 : limits.limit))
4170
+ if (data.length)
4103
4171
  return data.length;
4104
4172
  return Infinity;
4105
4173
  }
@@ -4112,8 +4180,8 @@ class FirestoreOperationsHelper {
4112
4180
  const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
4113
4181
  if (!isSubCollection)
4114
4182
  return collectionName;
4115
- const parentId = identifiers === null || identifiers === void 0 ? void 0 : identifiers[parentIdField];
4116
- return `${parentRepository === null || parentRepository === void 0 ? void 0 : parentRepository.collectionName}/${parentId}/${collectionName}`;
4183
+ const parentId = identifiers?.[parentIdField];
4184
+ return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
4117
4185
  }
4118
4186
  getKeyField() {
4119
4187
  const model = new this.model();
@@ -4164,27 +4232,25 @@ const createGetFirestoreClass = (MixinBase) => {
4164
4232
  }
4165
4233
  }
4166
4234
  async executeGet(params) {
4167
- var _a, _b, _c, _d;
4168
4235
  const { instance, collectionName, identifiers, logger, req } = params;
4169
- 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 }));
4170
- 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;
4171
4238
  const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
4172
4239
  const data = docRef.data();
4173
4240
  this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
4174
- 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;
4175
4242
  logger.log({ req, res: result });
4176
4243
  return result;
4177
4244
  }
4178
4245
  async saveCacheData(params) {
4179
- var _a, _b, _c;
4180
4246
  const { identifiers, options, result, logger, req } = params;
4181
- 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)
4182
4248
  return;
4183
4249
  const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
4184
4250
  await FirestoreCacheHelper.saveCacheData(this.cache, {
4185
4251
  cacheKey,
4186
4252
  data: result,
4187
- expirationInSeconds: (_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.ttl,
4253
+ expirationInSeconds: options?.cache?.ttl,
4188
4254
  logger,
4189
4255
  req,
4190
4256
  });
@@ -4215,14 +4281,13 @@ class FirestoreQueryBuilderHelper {
4215
4281
  this.config = config;
4216
4282
  }
4217
4283
  buildWhereSentence(fieldName, options) {
4218
- var _a, _b;
4219
- 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)
4220
4285
  return [];
4221
4286
  const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
4222
4287
  return this.buildWhereConditions(firestoreFieldName, options, fieldName);
4223
4288
  }
4224
4289
  getFirestoreFieldName(fieldName, options) {
4225
- const value = (options === null || options === void 0 ? void 0 : options.value) || options;
4290
+ const value = options?.value || options;
4226
4291
  const object = {};
4227
4292
  lodash.set(object, fieldName.toString(), value);
4228
4293
  const plainInstance = new this.config.model(object).toPlain();
@@ -4231,19 +4296,19 @@ class FirestoreQueryBuilderHelper {
4231
4296
  : Object.keys(plainInstance).find((key) => plainInstance[key]);
4232
4297
  }
4233
4298
  buildWhereConditions(firestoreFieldName, options, fieldName) {
4234
- if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
4299
+ if (options?.operator === exports.Where.LIKE) {
4235
4300
  return this.buildLikeConditions(firestoreFieldName, options);
4236
4301
  }
4237
- 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)) {
4238
4303
  return this.buildInConditions(firestoreFieldName, options);
4239
4304
  }
4240
4305
  if (this.isNestedObjectFilter(options)) {
4241
4306
  return this.buildNestedObjectConditions(fieldName, options);
4242
4307
  }
4243
- 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]];
4244
4309
  }
4245
4310
  buildLikeConditions(firestoreFieldName, options) {
4246
- if (this.isArrayField(firestoreFieldName) && Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4311
+ if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
4247
4312
  return [[firestoreFieldName, 'array-contains-any', options.value]];
4248
4313
  }
4249
4314
  return [
@@ -4260,17 +4325,16 @@ class FirestoreQueryBuilderHelper {
4260
4325
  buildNestedObjectConditions(fieldName, options) {
4261
4326
  return Object.keys(options).reduce((queries, key) => [
4262
4327
  ...queries,
4263
- ...this.buildWhereSentence(`${fieldName.toString()}.${key}`, is(options)[key]),
4328
+ ...this.buildWhereSentence(Array.isArray(options) ? fieldName : `${fieldName.toString()}.${key}`, is(options)[key]),
4264
4329
  ], []);
4265
4330
  }
4266
4331
  isArrayField(firestoreFieldName) {
4267
- var _a, _b;
4268
- return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
4332
+ return (this.config.fields?.[firestoreFieldName] ===
4269
4333
  FirestoreFieldType.Array ||
4270
- !((_b = this.config.fields) === null || _b === void 0 ? void 0 : _b[firestoreFieldName]));
4334
+ !this.config.fields?.[firestoreFieldName]);
4271
4335
  }
4272
4336
  isNestedObjectFilter(options) {
4273
- 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);
4274
4338
  }
4275
4339
  buildOrderBy(filters, fieldsToOrderBy) {
4276
4340
  const orderByKeys = Object.keys(fieldsToOrderBy || {});
@@ -4286,8 +4350,8 @@ class FirestoreQueryBuilderHelper {
4286
4350
  filtersKeysWithUnordered.forEach((filterKey) => {
4287
4351
  const filterValue = filters[filterKey];
4288
4352
  const filterOptions = is(filterValue);
4289
- if ((filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.operator) && ![exports.Where.EQUALS].includes(filterOptions.operator)) {
4290
- updatedOrderBy = Object.assign({ [filterKey]: 'asc' }, updatedOrderBy);
4353
+ if (filterOptions?.operator && ![exports.Where.EQUALS].includes(filterOptions.operator)) {
4354
+ updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
4291
4355
  }
4292
4356
  });
4293
4357
  return updatedOrderBy;
@@ -4301,21 +4365,21 @@ class FirestoreQueryBuilderHelper {
4301
4365
  async buildLimits(params) {
4302
4366
  const { filters, limits, collection, buildCollectionPath } = params;
4303
4367
  const queries = [];
4304
- if (limits === null || limits === void 0 ? void 0 : limits.offset) {
4368
+ if (limits?.offset) {
4305
4369
  await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
4306
4370
  }
4307
- if (limits === null || limits === void 0 ? void 0 : limits.limit) {
4371
+ if (limits?.limit) {
4308
4372
  queries.push(['limit', limits.limit]);
4309
4373
  }
4310
4374
  return queries;
4311
4375
  }
4312
4376
  async addOffsetQuery(params) {
4313
- var _a;
4314
4377
  const { queries, limits, filters, collection, buildCollectionPath } = params;
4315
4378
  if (this.config.model.isModel(limits.offset)) {
4316
4379
  const docSnapshot = await collection(buildCollectionPath(filters))
4317
- .getDoc((_a = Object.values(limits.offset.identifier)
4318
- .shift()) === null || _a === void 0 ? void 0 : _a.toString())
4380
+ .getDoc(Object.values(limits.offset.identifier)
4381
+ .shift()
4382
+ ?.toString())
4319
4383
  .get();
4320
4384
  queries.push(['fromStartAfter', docSnapshot]);
4321
4385
  }
@@ -4330,7 +4394,7 @@ class FirestoreQueryBuilderHelper {
4330
4394
  }
4331
4395
 
4332
4396
  const createFilterHelpers = () => {
4333
- const checkIfIsFilterOption = (filter) => !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
4397
+ const checkIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
4334
4398
  const getValueFromFilter = (filter) => {
4335
4399
  return checkIfIsFilterOption(filter) ? filter.value : filter;
4336
4400
  };
@@ -4388,20 +4452,19 @@ const withFindFirestore = (MixinBase) => {
4388
4452
  }
4389
4453
  }
4390
4454
  async executeFind(params) {
4391
- var _a, _b, _c, _d, _e, _f;
4392
4455
  const { find, collectionName, logger, req } = params;
4393
4456
  const collection = this.collection(collectionName);
4394
- 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;
4395
- 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 }));
4396
- 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;
4397
4460
  const queryData = await this.buildQueryData(filters, orderBy, limits);
4398
4461
  const docs = await this.executeQuery(collection, queryData);
4399
4462
  const data = docs.docs.map((doc) => doc.data());
4400
4463
  const result = {
4401
- 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,
4402
4465
  count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
4403
4466
  };
4404
- logger.log(Object.assign(Object.assign({ req }, queryData), { res: result }));
4467
+ logger.log({ req, ...queryData, res: result });
4405
4468
  return result;
4406
4469
  }
4407
4470
  async buildQueryData(filters, orderBy, limits) {
@@ -4417,19 +4480,21 @@ const withFindFirestore = (MixinBase) => {
4417
4480
  }
4418
4481
  async executeQuery(collection, queryData) {
4419
4482
  return this.queryBuilder
4420
- .buildQuery(Object.assign({ collection }, queryData))
4483
+ .buildQuery({
4484
+ collection,
4485
+ ...queryData,
4486
+ })
4421
4487
  .getDocs();
4422
4488
  }
4423
4489
  async saveCacheData(params) {
4424
- var _a, _b, _c;
4425
4490
  const { find, options, result, logger } = params;
4426
- 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)
4427
4492
  return;
4428
4493
  const cacheKey = this.generateCacheKey(find);
4429
4494
  await FirestoreCacheHelper.saveCacheData(this.cache, {
4430
4495
  cacheKey,
4431
4496
  data: result,
4432
- expirationInSeconds: (_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.ttl,
4497
+ expirationInSeconds: options?.cache?.ttl,
4433
4498
  logger,
4434
4499
  });
4435
4500
  }
@@ -4437,7 +4502,7 @@ const withFindFirestore = (MixinBase) => {
4437
4502
  if (!this.isSubCollection(this))
4438
4503
  return this.collectionName;
4439
4504
  const parentIdField = this.parentIdField;
4440
- const parentId = getValueFromFilter(filters === null || filters === void 0 ? void 0 : filters[parentIdField]);
4505
+ const parentId = getValueFromFilter(filters?.[parentIdField]);
4441
4506
  return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
4442
4507
  }
4443
4508
  };
@@ -4446,16 +4511,15 @@ const withFindFirestore = (MixinBase) => {
4446
4511
  const withCreateFirestore = (MixinBase) => {
4447
4512
  return class CreateFirestore extends MixinBase {
4448
4513
  async create(data) {
4449
- var _a, _b, _c, _d;
4450
4514
  const logger = this.logger.with('create');
4451
4515
  const instance = this.model.toInstance(data);
4452
- 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 }));
4453
- 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;
4454
4518
  const req = { collection: this.buildCollectionPathForAdd(builded), data };
4455
4519
  try {
4456
4520
  const docRef = await this.save(builded);
4457
4521
  const doc = (await docRef.get()).data();
4458
- 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;
4459
4523
  logger.log({ req, res: docBuilded });
4460
4524
  return docBuilded;
4461
4525
  }
@@ -4466,10 +4530,9 @@ const withCreateFirestore = (MixinBase) => {
4466
4530
  }
4467
4531
  }
4468
4532
  async save(data) {
4469
- var _a, _b;
4470
4533
  const collectionPath = this.buildCollectionPathForAdd(data);
4471
4534
  const collection = this.collection(collectionPath);
4472
- 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?.());
4473
4536
  }
4474
4537
  buildCollectionPathForAdd(identifiers) {
4475
4538
  return this.isSubCollection(this)
@@ -4480,26 +4543,23 @@ const withCreateFirestore = (MixinBase) => {
4480
4543
  };
4481
4544
 
4482
4545
  const createUpdateHelpers = () => {
4483
- const getValueFromParams = (params, field) => {
4484
- var _a;
4485
- return (lodash.isNil((_a = is(params[field])) === null || _a === void 0 ? void 0 : _a.value)
4486
- ? is(params[field])
4487
- : is(params[field]).value) || null;
4488
- };
4546
+ const getValueFromParams = (params, field) => (lodash.isNil(is(params[field])?.value)
4547
+ ? is(params[field])
4548
+ : is(params[field]).value) || null;
4489
4549
  const getValueByAction = (options) => {
4490
- if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
4550
+ if (lodash.isNil(options?.action))
4491
4551
  return options;
4492
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.REMOVE_FIELD)
4552
+ if (options?.action === exports.UpdateOptionActions.REMOVE_FIELD)
4493
4553
  return firestore.deleteField();
4494
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.NULL)
4554
+ if (options?.action === exports.UpdateOptionActions.NULL)
4495
4555
  return null;
4496
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value)) {
4497
- 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)
4498
4558
  return firestore.arrayUnion(...options.value);
4499
- if ((options === null || options === void 0 ? void 0 : options.action) === exports.UpdateOptionActions.REMOVE)
4559
+ if (options?.action === exports.UpdateOptionActions.REMOVE)
4500
4560
  return firestore.arrayRemove(...options.value);
4501
4561
  }
4502
- return options === null || options === void 0 ? void 0 : options.value;
4562
+ return options?.value;
4503
4563
  };
4504
4564
  return { getValueFromParams, getValueByAction };
4505
4565
  };
@@ -4550,14 +4610,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
4550
4610
  await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
4551
4611
  }
4552
4612
  async executeUpdate(params) {
4553
- var _a, _b, _c, _d;
4554
4613
  const { data, docRef, logger, req, identifiers } = params;
4555
4614
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
4556
- 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 }));
4557
- 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;
4558
4617
  await docRef.save(builded.toPlain());
4559
4618
  const docData = await docRef.get();
4560
- 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();
4561
4620
  logger.log({ req, res: result, identifiers });
4562
4621
  return result;
4563
4622
  }
@@ -4573,7 +4632,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
4573
4632
  return this.convertParamsToPlainObject(params);
4574
4633
  }
4575
4634
  convertParamsToPlainObject(params) {
4576
- 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
+ }), {});
4577
4639
  }
4578
4640
  processParamValue(key, value) {
4579
4641
  const processedValue = getValueByAction(value);
@@ -4614,12 +4676,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
4614
4676
  await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
4615
4677
  }
4616
4678
  async executeDeleteOperation(params) {
4617
- var _a, _b, _c, _d;
4618
4679
  const { instance, collectionName, logger, req } = params;
4619
- 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 }));
4620
- 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;
4621
4682
  await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
4622
- 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);
4623
4684
  logger.log({ req, res: undefined });
4624
4685
  }
4625
4686
  buildCollectionPathForRemove(identifiers) {
@@ -4699,15 +4760,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
4699
4760
  const products = [];
4700
4761
  const wheres = [];
4701
4762
  for (const productIds of chunks) {
4702
- 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)
4703
4764
  break;
4704
4765
  wheres.push(['published', '==', true], ['id', 'in', productIds]);
4705
- if (options === null || options === void 0 ? void 0 : options.hasStock)
4766
+ if (options?.hasStock)
4706
4767
  wheres.push(['stock.quantity', '>', 0]);
4707
- if (options === null || options === void 0 ? void 0 : options.gender)
4708
- 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]);
4709
4770
  const productSnap = await wheres
4710
- .reduce((collection, where) => collection.where(...where), (options === null || options === void 0 ? void 0 : options.limit)
4771
+ .reduce((collection, where) => collection.where(...where), options?.limit
4711
4772
  ? this.collection('productsErpVitrine').limit(options.limit)
4712
4773
  : this.collection('productsErpVitrine'))
4713
4774
  .getDocs();
@@ -4772,19 +4833,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4772
4833
  throw new Error('Method not implemented.');
4773
4834
  }
4774
4835
  async getBySlug(slug) {
4775
- var _a;
4776
4836
  const result = await this.find({
4777
4837
  filters: {
4778
4838
  slug: { operator: exports.Where.EQUALS, value: slug },
4779
4839
  },
4780
4840
  });
4781
- return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4841
+ return result?.data?.shift();
4782
4842
  }
4783
4843
  async fetchReviews(status) {
4784
4844
  const { data: products } = await this.find();
4785
4845
  products.forEach((product) => {
4786
- var _a;
4787
- if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
4846
+ if ([undefined, 0].includes(product.reviews?.length))
4788
4847
  return;
4789
4848
  const productInfo = {
4790
4849
  productId: product.id,
@@ -4796,11 +4855,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4796
4855
  this.reviews.rejected = [];
4797
4856
  product.reviews.forEach((review) => {
4798
4857
  if ([null, undefined].includes(review.status))
4799
- return this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
4858
+ return this.reviews.pending.push({ ...review, ...productInfo });
4800
4859
  if (review.status === false)
4801
- return this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
4860
+ return this.reviews.rejected.push({ ...review, ...productInfo });
4802
4861
  if (review.status)
4803
- return this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
4862
+ return this.reviews.approved.push({ ...review, ...productInfo });
4804
4863
  return review;
4805
4864
  });
4806
4865
  });
@@ -4887,22 +4946,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4887
4946
  interceptors,
4888
4947
  cache,
4889
4948
  });
4890
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4891
- var _a, _b, _c;
4892
- return ({
4893
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
4894
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
4895
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
4896
- 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)) || [],
4897
- });
4898
- };
4899
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
4900
- var _a;
4901
- return ({
4902
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
4903
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
4904
- });
4905
- };
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
+ });
4906
4961
  }
4907
4962
  buildModelInstance() {
4908
4963
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -4918,17 +4973,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4918
4973
  };
4919
4974
  }
4920
4975
  homeToFirestore(home) {
4921
- var _a, _b, _c, _d;
4922
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4923
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
4924
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
4925
- 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) || [];
4926
4980
  }
4927
4981
  return home;
4928
4982
  }
4929
4983
  homeFromFirestore(home) {
4930
- var _a;
4931
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4984
+ if (home.data?.data) {
4932
4985
  home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
4933
4986
  home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
4934
4987
  home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
@@ -5067,8 +5120,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
5067
5120
  },
5068
5121
  });
5069
5122
  this.orderFromFirestore = (order) => {
5070
- var _a;
5071
- if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
5123
+ if (order?.lineItems?.length) {
5072
5124
  order.lineItems = order.lineItems.map((lineItem) => {
5073
5125
  const prices = !!lineItem.price;
5074
5126
  const shopPrice = prices[order.shop];
@@ -5083,7 +5135,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
5083
5135
  buildModelInstance() {
5084
5136
  const { fromFirestore, toFirestore } = super.buildModelInstance();
5085
5137
  return {
5086
- toFirestore: (data) => toFirestore((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data),
5138
+ toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
5087
5139
  fromFirestore: (snap) => {
5088
5140
  const instance = fromFirestore(snap);
5089
5141
  return this.orderFromFirestore(instance);
@@ -5114,18 +5166,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
5114
5166
  });
5115
5167
  }
5116
5168
  async createBlockedOrderOrPayment(params) {
5117
- var _a, _b, _c, _d, _e, _f, _g, _h;
5118
5169
  const { checkout, blockType, type, limiteRange, card = null } = params;
5119
5170
  return this.create(OrderBlocked.toInstance({
5120
5171
  customer: {
5121
- name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
5122
- cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
5123
- id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
5124
- email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
5125
- phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
5126
- isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
5127
- subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
5128
- 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
+ },
5129
5183
  },
5130
5184
  blockType,
5131
5185
  limiteRange,
@@ -5373,7 +5427,7 @@ class ConnectDocumentService {
5373
5427
  this.reference = firestore.doc(this.firestore, this.path).withConverter({
5374
5428
  toFirestore: (data) => data,
5375
5429
  fromFirestore: (snapshot) => {
5376
- return Object.assign({ id: snapshot.id }, snapshot.data());
5430
+ return { id: snapshot.id, ...snapshot.data() };
5377
5431
  },
5378
5432
  });
5379
5433
  }
@@ -5411,7 +5465,7 @@ class ConnectCollectionService {
5411
5465
  this.reference = firestore.collection(firestore$1, path).withConverter({
5412
5466
  toFirestore: (data) => data,
5413
5467
  fromFirestore: (snapshot) => {
5414
- return Object.assign({ id: snapshot.id }, snapshot.data());
5468
+ return { id: snapshot.id, ...snapshot.data() };
5415
5469
  },
5416
5470
  });
5417
5471
  }
@@ -5506,10 +5560,10 @@ class FirebaseFileUploaderService {
5506
5560
  function createCreateHasuraGraphQLClass(MixinBase) {
5507
5561
  return class CreateHasuraGraphQLMixin extends MixinBase {
5508
5562
  constructor(...params) {
5509
- const options = params === null || params === void 0 ? void 0 : params[0];
5563
+ const options = params?.[0];
5510
5564
  super(...params);
5511
- this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.insertGraphQLOperation);
5512
- 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);
5513
5567
  }
5514
5568
  async create(data) {
5515
5569
  return HasuraCreateOperationsHelper.executeCreate(data, {
@@ -5536,9 +5590,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
5536
5590
  function createDeleteHasuraGraphQLClass(MixinBase) {
5537
5591
  return class DeleteHasuraGraphQLMixin extends MixinBase {
5538
5592
  constructor(...params) {
5539
- const options = params === null || params === void 0 ? void 0 : params[0];
5593
+ const options = params?.[0];
5540
5594
  super(...params);
5541
- this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.deleteGraphQLOperation);
5595
+ this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
5542
5596
  }
5543
5597
  async delete(identifiers) {
5544
5598
  await HasuraDeleteOperationsHelper.executeDelete({
@@ -5584,9 +5638,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
5584
5638
  function createGetHasuraGraphQLClass(MixinBase) {
5585
5639
  return class GetHasuraGraphQLMixin extends MixinBase {
5586
5640
  constructor(...params) {
5587
- const options = params === null || params === void 0 ? void 0 : params[0];
5641
+ const options = params?.[0];
5588
5642
  super(...params);
5589
- this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options === null || options === void 0 ? void 0 : options.getGraphQLOperation);
5643
+ this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
5590
5644
  }
5591
5645
  generateCacheKey(identifiers) {
5592
5646
  return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
@@ -5662,11 +5716,11 @@ function createHasuraGraphQLClass(MixinBase) {
5662
5716
  function createUpdateHasuraGraphQLClass(MixinBase) {
5663
5717
  return class UpdateHasuraGraphQLMixin extends MixinBase {
5664
5718
  constructor(...params) {
5665
- const options = params === null || params === void 0 ? void 0 : params[0];
5719
+ const options = params?.[0];
5666
5720
  super(...params);
5667
- this.updateGraphQLOperation = (options === null || options === void 0 ? void 0 : options.updateGraphQLOperation) || `update_${this.tableName}_by_pk`;
5668
- this.updateGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.updateGraphQLObjectType) || `${this.tableName}_set_input`;
5669
- 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`;
5670
5724
  }
5671
5725
  getIdentifiersFromData(data) {
5672
5726
  return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
@@ -5856,7 +5910,7 @@ const fieldsConfiguration$5 = [
5856
5910
  categories: { data: value.map((category) => ({ category_id: +category })) },
5857
5911
  }),
5858
5912
  to: (categories) => categories.map((categoryId) => +categoryId),
5859
- 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()) || [],
5860
5914
  },
5861
5915
  },
5862
5916
  ],
@@ -5937,8 +5991,7 @@ class CategoryCacheOperationsHelper {
5937
5991
  logger.log(`Dados salvos no cache: ${cacheKey}`);
5938
5992
  }
5939
5993
  static shouldUseCache(cacheAdapter, optionsCache) {
5940
- var _a;
5941
- 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);
5942
5995
  }
5943
5996
  }
5944
5997
 
@@ -6106,19 +6159,25 @@ class CategoryProductOperationsHelper {
6106
6159
  }
6107
6160
  static buildProductQuery(params) {
6108
6161
  const { productIds, fields, hasStock, limit } = params;
6109
- 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: {
6110
6168
  stock: 'desc',
6111
6169
  shoppingCount: 'desc',
6112
6170
  rate: 'desc',
6113
6171
  name: 'asc',
6114
- } });
6172
+ },
6173
+ };
6115
6174
  }
6116
6175
  static getGenderParam(shop) {
6117
6176
  return shop === exports.Shops.MENSMARKET ? 'male' : 'female';
6118
6177
  }
6119
6178
  static async fetchMostRelevantProducts(params) {
6120
6179
  const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
6121
- if (!(mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length))
6180
+ if (!mostRelevantsIds?.length)
6122
6181
  return [];
6123
6182
  const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
6124
6183
  const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
@@ -6147,9 +6206,8 @@ class CategoryProductOperationsHelper {
6147
6206
 
6148
6207
  class CategoryMountOperationsHelper {
6149
6208
  static async executeMount(params, dependencies) {
6150
- var _a;
6151
6209
  const { category, shop, options = {}, optionsCache } = params;
6152
- if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
6210
+ if (!category?.products?.length)
6153
6211
  return [];
6154
6212
  const cachedResult = await this.tryGetFromCache({
6155
6213
  category,
@@ -6170,7 +6228,7 @@ class CategoryMountOperationsHelper {
6170
6228
  optionsCache,
6171
6229
  dependencies,
6172
6230
  });
6173
- if (mostRelevantProducts.length >= mostRelevantsIds.length) {
6231
+ if (mostRelevantsIds.length && mostRelevantProducts.length >= mostRelevantsIds.length) {
6174
6232
  return this.finalizeMountWithMostRelevants({
6175
6233
  mostRelevantProducts,
6176
6234
  mostRelevantsIds,
@@ -6247,7 +6305,6 @@ class CategoryMountOperationsHelper {
6247
6305
  return result;
6248
6306
  }
6249
6307
  static async saveToCacheIfNeeded(params) {
6250
- var _a;
6251
6308
  const { category, shop, options, optionsCache, result, dependencies } = params;
6252
6309
  const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
6253
6310
  if (!shouldUseCache)
@@ -6257,7 +6314,7 @@ class CategoryMountOperationsHelper {
6257
6314
  cacheAdapter: dependencies.cacheAdapter,
6258
6315
  cacheKey,
6259
6316
  products: result,
6260
- 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,
6261
6318
  logger: dependencies.logger,
6262
6319
  });
6263
6320
  }
@@ -6283,7 +6340,12 @@ class ProductFetchReviewsHelper {
6283
6340
  ...reviews,
6284
6341
  ...product.reviews
6285
6342
  .filter((review) => this.matchesStatus(review, status))
6286
- .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
+ })),
6287
6349
  ], []);
6288
6350
  }
6289
6351
  static matchesStatus(review, status) {
@@ -6330,8 +6392,7 @@ class ProductReviewCacheHelper {
6330
6392
  dependencies.logger.log(`Dados salvos no cache: ${key}`);
6331
6393
  }
6332
6394
  static shouldUseCache(cacheAdapter, options) {
6333
- var _a;
6334
- 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);
6335
6396
  }
6336
6397
  }
6337
6398
 
@@ -6342,9 +6403,12 @@ class ProductReviewOperationsHelper {
6342
6403
  let count = 0;
6343
6404
  let offset = 0;
6344
6405
  do {
6345
- const result = await repository.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, (limit && {
6346
- limits: { offset, limit },
6347
- })));
6406
+ const result = await repository.find({
6407
+ fields: ['id', 'name', 'sku', 'reviews'],
6408
+ ...(limit && {
6409
+ limits: { offset, limit },
6410
+ }),
6411
+ });
6348
6412
  data = data.concat(result.data);
6349
6413
  count = result.data.length;
6350
6414
  offset += limit;
@@ -6355,7 +6419,13 @@ class ProductReviewOperationsHelper {
6355
6419
  const { data, getReviewStatus } = params;
6356
6420
  return data.reduce((reviews, product) => [
6357
6421
  ...reviews,
6358
- ...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
+ })),
6359
6429
  ], []);
6360
6430
  }
6361
6431
  static applyReviewFilters(params) {
@@ -6399,7 +6469,7 @@ class ProductReviewUpdateHelper {
6399
6469
  const { productId, reviews, dependencies } = params;
6400
6470
  const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
6401
6471
  const review = await dependencies.findReview(reviewData, productId);
6402
- return review === null || review === void 0 ? void 0 : review.id;
6472
+ return review?.id;
6403
6473
  }));
6404
6474
  await dependencies.mutation('delete_product_review', ['affected_rows'], {
6405
6475
  where: {
@@ -6438,7 +6508,7 @@ class ProductReviewUpdateHelper {
6438
6508
  static async insertNewReview(reviewData, productId, dependencies) {
6439
6509
  const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
6440
6510
  object: {
6441
- 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']),
6442
6512
  type: 'product_review_insert_input',
6443
6513
  required: true,
6444
6514
  },
@@ -6531,11 +6601,14 @@ const fieldsConfiguration$4 = [
6531
6601
  bindPersistData: (value) => {
6532
6602
  return {
6533
6603
  brand_condition: value.brand,
6534
- tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
6604
+ tag_condition: value?.tags || [],
6535
6605
  };
6536
6606
  },
6537
6607
  bindFindFilter: (sentence) => {
6538
- 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
+ };
6539
6612
  },
6540
6613
  },
6541
6614
  },
@@ -6547,7 +6620,7 @@ const fieldsConfiguration$4 = [
6547
6620
  bindPersistData: (value) => ({
6548
6621
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
6549
6622
  }),
6550
- 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) || [],
6551
6624
  },
6552
6625
  },
6553
6626
  { createdAt: { columnName: 'created_at' } },
@@ -6612,11 +6685,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6612
6685
  this.categoryFilterRepository = categoryFilterRepository;
6613
6686
  }
6614
6687
  async create(params) {
6615
- const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
6616
- 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 || {
6617
6694
  [exports.Shops.GLAMSHOP]: null,
6618
6695
  [exports.Shops.MENSMARKET]: null,
6619
- }, images: images || {
6696
+ },
6697
+ images: images || {
6620
6698
  [exports.Shops.GLAMSHOP]: {
6621
6699
  brandBanner: null,
6622
6700
  brandBannerMobile: null,
@@ -6627,17 +6705,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6627
6705
  brandBannerMobile: null,
6628
6706
  image: null,
6629
6707
  },
6630
- } }));
6708
+ },
6709
+ });
6631
6710
  }
6632
6711
  async get(identifiers, optionsCache) {
6633
6712
  const id = await this.getId(identifiers.id);
6634
6713
  return super.get({ id }, optionsCache);
6635
6714
  }
6636
6715
  async update(params) {
6637
- const { id, products, metadatas, filters } = params, data = tslib.__rest(params, ["id", "products", "metadatas", "filters"]);
6716
+ const { id, products, metadatas, filters, ...data } = params;
6638
6717
  const categoryId = +(await this.getId(id));
6639
6718
  const [category] = await Promise.all([
6640
- super.update(Object.assign({ id: categoryId === null || categoryId === void 0 ? void 0 : categoryId.toString() }, data)),
6719
+ super.update({ id: categoryId?.toString(), ...data }),
6641
6720
  ...(products ? [this.updateProducts(categoryId, { products })] : []),
6642
6721
  ...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
6643
6722
  ...(filters ? [this.updateFilters(categoryId, { filters })] : []),
@@ -6677,7 +6756,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6677
6756
  }
6678
6757
  async getCategoriesForHome(params) {
6679
6758
  const { categoryIds, shop, limit = 4, optionsCache } = params;
6680
- if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
6759
+ if (!categoryIds?.length)
6681
6760
  return [];
6682
6761
  const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
6683
6762
  const categories = [];
@@ -6698,11 +6777,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6698
6777
  });
6699
6778
  }
6700
6779
  async mountCategory(params) {
6701
- var _a, _b;
6702
6780
  return CategoryMountOperationsHelper.executeMount(params, {
6703
6781
  productRepository: this.productRepository,
6704
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
6705
- defaultCacheTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
6782
+ cacheAdapter: this.cache?.cacheAdapter,
6783
+ defaultCacheTtl: this.cache?.ttlDefault,
6706
6784
  logger: this.logger,
6707
6785
  });
6708
6786
  }
@@ -6721,12 +6799,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6721
6799
  return categoryTree.some((c) => c.id == id.toString());
6722
6800
  }
6723
6801
  async getId(id) {
6724
- var _a, _b;
6725
6802
  if (!Number.isNaN(+id))
6726
6803
  return id;
6727
6804
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
6728
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
6729
- 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;
6730
6807
  throw new NotFoundError(`Category with id ${id} not found`);
6731
6808
  }
6732
6809
  async updateProducts(categoryId, { products }) {
@@ -6780,7 +6857,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6780
6857
  objects: {
6781
6858
  type: '[category_metadata_insert_input!]',
6782
6859
  required: true,
6783
- value: metadatas.map((m) => (Object.assign({ category_id: categoryId }, m))),
6860
+ value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
6784
6861
  },
6785
6862
  });
6786
6863
  return metadatas;
@@ -6946,7 +7023,7 @@ const fieldsConfiguration$3 = [
6946
7023
  bindPersistData: (value) => ({
6947
7024
  categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
6948
7025
  }),
6949
- 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) || [],
6950
7027
  },
6951
7028
  },
6952
7029
  ];
@@ -6965,7 +7042,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6965
7042
  this.categoryFilterRepository = categoryFilterRepository;
6966
7043
  }
6967
7044
  async update(params) {
6968
- const { options } = params, data = tslib.__rest(params, ["options"]);
7045
+ const { options, ...data } = params;
6969
7046
  const filter = await super.update(data);
6970
7047
  filter.options = await this.updateOptions(+data.id, { options });
6971
7048
  return filter;
@@ -6987,8 +7064,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6987
7064
  if (hasFilter)
6988
7065
  filterOptions.push(hasFilter);
6989
7066
  }
6990
- catch (_a) {
6991
- 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 });
6992
7069
  filterOptions.push(newOption);
6993
7070
  }
6994
7071
  }
@@ -7002,8 +7079,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
7002
7079
  if (hasFilter)
7003
7080
  filterOptions.push(hasFilter);
7004
7081
  }
7005
- catch (_b) {
7006
- 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 });
7007
7084
  filterOptions.push(newOption);
7008
7085
  }
7009
7086
  }
@@ -7124,13 +7201,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7124
7201
  filters: {
7125
7202
  id: {
7126
7203
  operator: exports.Where.IN,
7127
- 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()))),
7128
7205
  },
7129
7206
  },
7130
7207
  });
7131
7208
  products.forEach((product) => {
7132
7209
  result.data
7133
- .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())
7134
7211
  .forEach((variant) => {
7135
7212
  variant.product.name = product.name;
7136
7213
  variant.product.group = product.group;
@@ -7163,21 +7240,37 @@ const commonFields = [
7163
7240
  purpose: data.purpose,
7164
7241
  }),
7165
7242
  bindFindFilter: (filters) => {
7166
- 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 && {
7167
- who_must_use: filters.whoMustUse,
7168
- })), (filters.howToUse && {
7169
- how_to_use: filters.howToUse,
7170
- })), (filters.brand && {
7171
- brand_description: filters.brand,
7172
- })), (filters.ingredients && {
7173
- ingredients: filters.ingredients,
7174
- })), (filters.purpose && {
7175
- purpose: filters.purpose,
7176
- }));
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
+ };
7177
7262
  },
7178
- 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 && {
7179
- who_must_use: descriptionData.whoMustUse,
7180
- })), (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
+ }),
7181
7274
  },
7182
7275
  },
7183
7276
  { differentials: { columnName: 'differentials' } },
@@ -7190,13 +7283,13 @@ const commonFields = [
7190
7283
  {
7191
7284
  images: {
7192
7285
  columnName: 'images',
7193
- 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?.('","') || ''}"}` : '{}'),
7194
7287
  },
7195
7288
  },
7196
7289
  {
7197
7290
  miniatures: {
7198
7291
  columnName: 'miniatures',
7199
- 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?.('","') || ''}"}` : '{}'),
7200
7293
  },
7201
7294
  },
7202
7295
  'name',
@@ -7211,19 +7304,31 @@ const commonFields = [
7211
7304
  subscriberPrice: data.subscriber_price,
7212
7305
  }),
7213
7306
  bindFindFilter: (filters) => {
7214
- 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) && {
7215
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7216
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7217
- subscriber_price: filters.subscriberPrice,
7218
- })), ((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7219
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7220
- }));
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
+ };
7221
7320
  },
7222
- 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 && {
7223
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7224
- })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice })), (priceData.fullPriceDiscountPercentage >= 0 && {
7225
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7226
- }))),
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
+ }),
7227
7332
  },
7228
7333
  },
7229
7334
  { fullPrice: { columnName: 'full_price' } },
@@ -7238,7 +7343,7 @@ const commonFields = [
7238
7343
  stock: {
7239
7344
  columnName: 'stock',
7240
7345
  from: (quantity) => ({ quantity }),
7241
- 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),
7242
7347
  },
7243
7348
  },
7244
7349
  { hasStock: { columnName: 'has_stock' } },
@@ -7277,7 +7382,7 @@ const fieldsConfiguration$2 = [
7277
7382
  categories: { data: value.map((category) => ({ category_id: +category })) },
7278
7383
  }),
7279
7384
  to: (categories) => categories.map((categoryId) => +categoryId),
7280
- 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()) || [],
7281
7386
  },
7282
7387
  },
7283
7388
  {
@@ -7353,12 +7458,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7353
7458
  fields: fieldsConfiguration$2,
7354
7459
  cache,
7355
7460
  });
7356
- 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 }));
7357
- 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
+ });
7358
7473
  }
7359
7474
  async create(params) {
7360
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
7361
- 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']));
7362
7477
  try {
7363
7478
  product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
7364
7479
  }
@@ -7369,10 +7484,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7369
7484
  return product;
7370
7485
  }
7371
7486
  async get(identifiers, options) {
7372
- var _a;
7373
7487
  const product = Number.isNaN(+identifiers.id)
7374
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7375
- .data) === null || _a === void 0 ? void 0 : _a[0]
7488
+ ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7489
+ .data?.[0]
7376
7490
  : await super.get(identifiers, options);
7377
7491
  if (product.productId)
7378
7492
  throw new NotFoundError('Product not found, it is a variant');
@@ -7380,19 +7494,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7380
7494
  return product;
7381
7495
  }
7382
7496
  async find(params, optionsParams) {
7383
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
7384
- const _o = params || {}, { filters, fields } = _o, options = tslib.__rest(_o, ["filters", "fields"]);
7497
+ const { filters, fields, ...options } = params || {};
7385
7498
  const bindFields = fields ||
7386
7499
  this.fields
7387
7500
  .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7388
7501
  .filter((field) => field !== 'reviews' && field !== 'categories');
7389
- if ((_b = (_a = options.options) === null || _a === void 0 ? void 0 : _a.minimal) === null || _b === void 0 ? void 0 : _b.includes('price'))
7390
- (_c = options.options) === null || _c === void 0 ? void 0 : _c.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7391
- if ((_e = (_d = options.options) === null || _d === void 0 ? void 0 : _d.maximum) === null || _e === void 0 ? void 0 : _e.includes('price'))
7392
- (_f = options.options) === null || _f === void 0 ? void 0 : _f.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7393
- (_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);
7394
- (_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);
7395
- 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: [
7396
7512
  ...bindFields,
7397
7513
  ...(bindFields.includes('price')
7398
7514
  ? [
@@ -7401,11 +7517,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7401
7517
  'fullPrice',
7402
7518
  ]
7403
7519
  : []),
7404
- ] }), optionsParams);
7520
+ ],
7521
+ }, optionsParams);
7405
7522
  }
7406
7523
  async getBySlug(slug, options) {
7407
- var _a, _b, _c, _d, _e, _f;
7408
- 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) {
7409
7525
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
7410
7526
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7411
7527
  if (cachedData) {
@@ -7424,70 +7540,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7424
7540
  });
7425
7541
  if (!result.data.length)
7426
7542
  return null;
7427
- 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();
7428
7544
  RoundProductPricesHelper.roundProductPrices(product);
7429
- 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) {
7430
7546
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
7431
7547
  await this.cache.cacheAdapter.set({
7432
7548
  key: cacheKey,
7433
7549
  data: serialize(product),
7434
- 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,
7435
7551
  });
7436
7552
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7437
7553
  }
7438
7554
  return product;
7439
7555
  }
7440
7556
  async update(params) {
7441
- 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']);
7442
7558
  const plainData = this.paramsToPlain({ id: checkId });
7443
7559
  const id = await this.getId(plainData.id);
7444
- const product = await super.update(Object.assign({ id }, data));
7560
+ const product = await super.update({ id, ...data });
7445
7561
  product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
7446
7562
  product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
7447
7563
  product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
7448
7564
  return product;
7449
7565
  }
7450
7566
  async fetchProductReviews(filters, options) {
7451
- var _a, _b, _c, _d, _e;
7452
7567
  const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
7453
7568
  const dependencies = {
7454
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
7569
+ cacheAdapter: this.cache?.cacheAdapter,
7455
7570
  logger: this.logger,
7456
7571
  modelName: this.model.name,
7457
- defaultTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
7572
+ defaultTtl: this.cache?.ttlDefault,
7458
7573
  };
7459
- if (ProductReviewCacheHelper.shouldUseCache((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter, options)) {
7574
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7460
7575
  const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
7461
7576
  if (cachedData)
7462
7577
  return cachedData;
7463
7578
  }
7464
- const limit = (filters === null || filters === void 0 ? void 0 : filters.limit) || 500;
7579
+ const limit = filters?.limit || 500;
7465
7580
  const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
7466
7581
  const reviews = ProductReviewOperationsHelper.processProductsToReviews({
7467
7582
  data,
7468
7583
  getReviewStatus: this.getReviewStatus.bind(this),
7469
7584
  });
7470
7585
  const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
7471
- if (ProductReviewCacheHelper.shouldUseCache((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter, options)) {
7586
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7472
7587
  await ProductReviewCacheHelper.saveToCache({
7473
7588
  key: cacheKey,
7474
7589
  data: filteredReviews,
7475
- ttl: (_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl,
7590
+ ttl: options?.cache?.ttl,
7476
7591
  dependencies,
7477
7592
  });
7478
7593
  }
7479
7594
  return filteredReviews;
7480
7595
  }
7481
7596
  async fetchReviews(status, options) {
7482
- var _a, _b, _c, _d, _e;
7483
7597
  const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
7484
7598
  const dependencies = {
7485
- cacheAdapter: (_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter,
7599
+ cacheAdapter: this.cache?.cacheAdapter,
7486
7600
  logger: this.logger,
7487
7601
  modelName: this.model.name,
7488
- defaultTtl: (_b = this.cache) === null || _b === void 0 ? void 0 : _b.ttlDefault,
7602
+ defaultTtl: this.cache?.ttlDefault,
7489
7603
  };
7490
- if (ProductReviewCacheHelper.shouldUseCache((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter, options)) {
7604
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7491
7605
  const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
7492
7606
  if (cachedData)
7493
7607
  return cachedData;
@@ -7498,18 +7612,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7498
7612
  reviewsFields: this.reviewsFields,
7499
7613
  };
7500
7614
  const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
7501
- if (ProductReviewCacheHelper.shouldUseCache((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter, options)) {
7615
+ if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
7502
7616
  await ProductReviewCacheHelper.saveToCache({
7503
7617
  key: cacheKey,
7504
7618
  data: reviews,
7505
- ttl: (_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl,
7619
+ ttl: options?.cache?.ttl,
7506
7620
  dependencies,
7507
7621
  });
7508
7622
  }
7509
7623
  return reviews;
7510
7624
  }
7511
7625
  async findCatalog(params, mainGender, options) {
7512
- 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);
7513
7635
  return result;
7514
7636
  }
7515
7637
  async cleanShoppingCountFromIds(ids) {
@@ -7580,17 +7702,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7580
7702
  return plainData.metadata;
7581
7703
  }
7582
7704
  async getId(id) {
7583
- var _a, _b;
7584
7705
  if (!Number.isNaN(+id))
7585
7706
  return id;
7586
7707
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
7587
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
7588
- 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;
7589
7710
  throw new NotFoundError(`Product with id ${id} not found`);
7590
7711
  }
7591
7712
  async findReviewsByProduct(productId, options) {
7592
- var _a, _b, _c, _d, _e;
7593
- 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) {
7594
7714
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7595
7715
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7596
7716
  if (cachedData) {
@@ -7607,13 +7727,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7607
7727
  required: true,
7608
7728
  },
7609
7729
  });
7610
- const reviews = data === null || data === void 0 ? void 0 : data.map((review) => this.bindReviewToModel(review));
7611
- 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) {
7612
7732
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7613
7733
  await this.cache.cacheAdapter.set({
7614
7734
  key: cacheKey,
7615
7735
  data: serialize(reviews),
7616
- 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,
7617
7737
  });
7618
7738
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7619
7739
  }
@@ -7637,23 +7757,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7637
7757
  async getReviewByPersonId(personId, productId, orderId) {
7638
7758
  const { product_review: data } = await this.query('product_review', this.reviewsFields, {
7639
7759
  where: {
7640
- 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
+ },
7641
7765
  type: 'product_review_bool_exp',
7642
7766
  required: true,
7643
7767
  },
7644
7768
  });
7645
- return (data === null || data === void 0 ? void 0 : data[0]) && this.bindReviewToModel(data[0]);
7769
+ return data?.[0] && this.bindReviewToModel(data[0]);
7646
7770
  }
7647
7771
  async getReviewByAuthorAndEmail(params) {
7648
7772
  const { author, email, productId, orderId } = params;
7649
7773
  const { product_review: data } = await this.query('product_review', this.reviewsFields, {
7650
7774
  where: {
7651
- 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
+ },
7652
7781
  type: 'product_review_bool_exp',
7653
7782
  required: true,
7654
7783
  },
7655
7784
  });
7656
- return (data === null || data === void 0 ? void 0 : data[0]) && this.bindReviewToModel(data[0]);
7785
+ return data?.[0] && this.bindReviewToModel(data[0]);
7657
7786
  }
7658
7787
  async productVariantFullReport() {
7659
7788
  const dependencies = {
@@ -7802,7 +7931,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
7802
7931
  });
7803
7932
  }
7804
7933
  async getNotificationsReport(params, orderBy, pagination) {
7805
- 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
+ };
7806
7944
  const orderByField = {
7807
7945
  [orderBy.field]: orderBy.direction,
7808
7946
  };
@@ -7818,8 +7956,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
7818
7956
  required: true,
7819
7957
  },
7820
7958
  });
7821
- const data = (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
7822
- ? 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)
7823
7961
  : reportStockNotification;
7824
7962
  return {
7825
7963
  data,
@@ -7835,7 +7973,7 @@ const fieldsConfiguration$1 = [
7835
7973
  productId: {
7836
7974
  columnName: 'main_product_id',
7837
7975
  to: (value) => +value,
7838
- from: (value) => value === null || value === void 0 ? void 0 : value.toString(),
7976
+ from: (value) => value?.toString(),
7839
7977
  },
7840
7978
  },
7841
7979
  { EAN: { columnName: 'ean' } },
@@ -7852,19 +7990,31 @@ const fieldsConfiguration$1 = [
7852
7990
  }),
7853
7991
  bindFindFilter: (sentence) => {
7854
7992
  const filters = Object.values(sentence).shift();
7855
- 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) && {
7856
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7857
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7858
- subscriber_price: filters.subscriberPrice,
7859
- })), ((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7860
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7861
- }));
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
+ };
7862
8006
  },
7863
- 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 && {
7864
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7865
- })), (((priceData === null || priceData === void 0 ? void 0 : priceData.subscriberPrice) || 0) >= 0 && { subscriber_price: priceData.subscriberPrice })), (priceData.fullPriceDiscountPercentage >= 0 && {
7866
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7867
- }))),
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
+ }),
7868
8018
  },
7869
8019
  },
7870
8020
  { fullPrice: { columnName: 'full_price' } },
@@ -7876,7 +8026,7 @@ const fieldsConfiguration$1 = [
7876
8026
  stock: {
7877
8027
  columnName: 'stock',
7878
8028
  from: (quantity) => ({ quantity }),
7879
- 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),
7880
8030
  },
7881
8031
  },
7882
8032
  { hasStock: { columnName: 'has_stock' } },
@@ -7909,41 +8059,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7909
8059
  });
7910
8060
  }
7911
8061
  async get(identifiers) {
7912
- var _a;
7913
8062
  if (!identifiers.id) {
7914
8063
  throw new NotFoundError('Variant ID is required');
7915
8064
  }
7916
8065
  const variant = Number.isNaN(+identifiers.id)
7917
- ? (_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]
7918
8067
  : await super.get(identifiers);
7919
8068
  if (!variant.productId)
7920
8069
  throw new NotFoundError('Variant not found, it is a product');
7921
8070
  return variant;
7922
8071
  }
7923
8072
  async find(params) {
7924
- const _a = params || {}, { filters } = _a, options = tslib.__rest(_a, ["filters"]);
7925
- 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 } });
7926
8075
  }
7927
8076
  async update(params) {
7928
- const { productId, id: checkId } = params, data = tslib.__rest(params, ["productId", "id"]);
8077
+ const { productId, id: checkId, ...data } = params;
7929
8078
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
7930
8079
  if (!dataWithProductId.id) {
7931
8080
  throw new NotFoundError('Variant ID is required for update');
7932
8081
  }
7933
8082
  const id = await this.getId(dataWithProductId.id);
7934
- const product = await super.update(Object.assign({ id }, data));
8083
+ const product = await super.update({ id, ...data });
7935
8084
  if (dataWithProductId.productId) {
7936
8085
  product.productId = dataWithProductId.productId;
7937
8086
  }
7938
8087
  return product;
7939
8088
  }
7940
8089
  async getId(id) {
7941
- var _a, _b;
7942
8090
  if (!Number.isNaN(+id))
7943
8091
  return id;
7944
8092
  const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
7945
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
7946
- 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;
7947
8095
  throw new NotFoundError(`Product with id ${id} not found`);
7948
8096
  }
7949
8097
  }
@@ -7974,11 +8122,14 @@ const fieldsConfiguration = [
7974
8122
  bindPersistData: (value) => {
7975
8123
  return {
7976
8124
  brand_condition: value.brand,
7977
- tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
8125
+ tag_condition: value?.tags || [],
7978
8126
  };
7979
8127
  },
7980
8128
  bindFindFilter: (sentence) => {
7981
- 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
+ };
7982
8133
  },
7983
8134
  },
7984
8135
  },
@@ -7990,7 +8141,7 @@ const fieldsConfiguration = [
7990
8141
  bindPersistData: (value) => ({
7991
8142
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
7992
8143
  }),
7993
- 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) || [],
7994
8145
  },
7995
8146
  },
7996
8147
  { createdAt: { columnName: 'created_at' } },
@@ -8058,12 +8209,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8058
8209
  this.categoryProductRepository = categoryProductRepository;
8059
8210
  }
8060
8211
  async create(params) {
8061
- var _a;
8062
- const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
8063
- 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 || {
8064
8220
  [exports.Shops.GLAMSHOP]: null,
8065
8221
  [exports.Shops.MENSMARKET]: null,
8066
- }, images: images || {
8222
+ },
8223
+ images: images || {
8067
8224
  [exports.Shops.GLAMSHOP]: {
8068
8225
  brandBanner: null,
8069
8226
  brandBannerMobile: null,
@@ -8074,7 +8231,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8074
8231
  brandBannerMobile: null,
8075
8232
  image: null,
8076
8233
  },
8077
- } }));
8234
+ },
8235
+ });
8078
8236
  }
8079
8237
  async get(identifiers) {
8080
8238
  const data = await super.get(identifiers);
@@ -8083,14 +8241,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8083
8241
  return data;
8084
8242
  }
8085
8243
  async find(params) {
8086
- const { filters } = params, rest = tslib.__rest(params, ["filters"]);
8087
- 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
+ });
8088
8252
  }
8089
8253
  async update(params) {
8090
- 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']);
8091
8255
  const plainData = this.paramsToPlain({ id: checkId });
8092
8256
  const id = plainData.id;
8093
- 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 });
8094
8258
  category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
8095
8259
  return category;
8096
8260
  }
@@ -8153,11 +8317,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
8153
8317
  return data;
8154
8318
  }
8155
8319
  async findBfluOrGlamgirlWishlists(params, shops) {
8156
- var _a, _b;
8157
- 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 ?? {
8158
8327
  operator: exports.Where.IN,
8159
8328
  value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
8160
- } }), 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
+ });
8161
8336
  }
8162
8337
  getCategoriesForHome() {
8163
8338
  return;
@@ -8365,7 +8540,7 @@ class PagarmePaymentFactoryHelper {
8365
8540
  checkoutId: checkout.id,
8366
8541
  totalPrice: checkout.totalPrice,
8367
8542
  paymentProvider: exports.PaymentProviders.PAGARME,
8368
- transaction: Object.assign(Object.assign({}, resultData), { paidAt: new Date() }),
8543
+ transaction: { ...resultData, paidAt: new Date() },
8369
8544
  });
8370
8545
  return payment;
8371
8546
  }
@@ -8392,7 +8567,6 @@ class PagarmeCardAxiosAdapter {
8392
8567
  this.orderBlockedRepository = orderBlockedRepository;
8393
8568
  }
8394
8569
  async pay(checkout, card) {
8395
- var _a;
8396
8570
  try {
8397
8571
  const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
8398
8572
  checkout,
@@ -8418,7 +8592,7 @@ class PagarmeCardAxiosAdapter {
8418
8592
  if (error instanceof PaymentError) {
8419
8593
  throw error;
8420
8594
  }
8421
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, (_a = error.response) === null || _a === void 0 ? void 0 : _a.data);
8595
+ throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
8422
8596
  }
8423
8597
  }
8424
8598
  async addCard(card) {
@@ -8485,7 +8659,10 @@ class PagarmeCardAxiosAdapter {
8485
8659
  const { data } = await axios__default["default"]({
8486
8660
  method: 'POST',
8487
8661
  url: `${this.credentials.URL}/transactions`,
8488
- data: Object.assign(Object.assign({}, info), { api_key: this.credentials.API_KEY }),
8662
+ data: {
8663
+ ...info,
8664
+ api_key: this.credentials.API_KEY,
8665
+ },
8489
8666
  });
8490
8667
  return data;
8491
8668
  }
@@ -8496,7 +8673,6 @@ class PagarmeCardAxiosAdapter {
8496
8673
  }
8497
8674
  }
8498
8675
  createCardPayment(checkout, card) {
8499
- var _a, _b, _c, _d, _e, _f;
8500
8676
  return {
8501
8677
  api_key: this.credentials.API_KEY,
8502
8678
  amount: Math.floor(checkout.totalPrice * 100),
@@ -8523,14 +8699,14 @@ class PagarmeCardAxiosAdapter {
8523
8699
  name: checkout.user.displayName,
8524
8700
  address: {
8525
8701
  country: 'br',
8526
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
8527
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
8528
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
8529
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
8530
- 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,
8531
8707
  zipcode: checkout.billingAddress
8532
8708
  ? checkout.billingAddress.zip.replace('-', '')
8533
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
8709
+ : checkout.shippingAddress?.zip.replace('-', ''),
8534
8710
  },
8535
8711
  },
8536
8712
  items: checkout.lineItems.map((item) => {
@@ -8552,7 +8728,6 @@ class PagarmePixAxiosAdapter {
8552
8728
  this.paymentRepository = paymentRepository;
8553
8729
  }
8554
8730
  async pay(checkout) {
8555
- var _a;
8556
8731
  try {
8557
8732
  const payload = this.createPixPayment(checkout);
8558
8733
  const result = await axios__default["default"]({
@@ -8576,7 +8751,7 @@ class PagarmePixAxiosAdapter {
8576
8751
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
8577
8752
  checkoutId: checkout.id,
8578
8753
  userEmail: checkout.user.email,
8579
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
8754
+ info: error.response?.data,
8580
8755
  });
8581
8756
  }
8582
8757
  }