@infrab4a/connect 5.4.0-beta.2 → 5.4.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/index.cjs.js +638 -619
  2. package/index.esm.js +637 -617
  3. package/package.json +3 -3
  4. package/src/domain/catalog/models/category-brand.d.ts +17 -0
  5. package/src/domain/catalog/models/index.d.ts +1 -0
  6. package/src/domain/catalog/models/product.d.ts +0 -1
  7. package/src/domain/catalog/models/variant.d.ts +0 -2
  8. package/src/domain/catalog/repositories/category-brand.repository.d.ts +4 -0
  9. package/src/domain/catalog/repositories/index.d.ts +1 -1
  10. package/src/domain/shopping/enums/payment-providers.enum.d.ts +2 -1
  11. package/src/domain/shopping/factories/index.d.ts +1 -0
  12. package/src/domain/shopping/factories/mercado-pago-payment-method.factory.d.ts +10 -0
  13. package/src/domain/shopping/factories/payment-provider.factory.d.ts +2 -0
  14. package/src/domain/shopping/models/order.d.ts +7 -0
  15. package/src/domain/shopping/models/payment-transaction.d.ts +2 -0
  16. package/src/domain/shopping/models/payment.d.ts +1 -0
  17. package/src/domain/shopping/services/antifraud-card.service.d.ts +2 -0
  18. package/src/domain/shopping/types/checkout-paylod-request.type.d.ts +2 -7
  19. package/src/domain/shopping/types/index.d.ts +2 -0
  20. package/src/domain/shopping/types/mercado-pago-card.type.d.ts +3 -0
  21. package/src/domain/shopping/types/mercado-pago-credentials.type.d.ts +5 -0
  22. package/src/domain/shopping/types/payment-card-info.type.d.ts +2 -0
  23. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  24. package/src/infra/firebase/firestore/repositories/catalog/category-brand-firestore.repository.d.ts +7 -0
  25. package/src/infra/firebase/firestore/repositories/catalog/index.d.ts +1 -0
  26. package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +0 -1
  27. package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +0 -1
  28. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +0 -1
  29. package/src/infra/index.d.ts +1 -0
  30. package/src/infra/mercado-pago/adapters/index.d.ts +3 -0
  31. package/src/infra/mercado-pago/adapters/mercado-pago-boleto-payment-axios.adapter.d.ts +8 -0
  32. package/src/infra/mercado-pago/adapters/mercado-pago-card-payment-axios.adapter.d.ts +19 -0
  33. package/src/infra/mercado-pago/adapters/mercado-pago-pix-payment-axios.adapter.d.ts +7 -0
  34. package/src/infra/mercado-pago/helpers/index.d.ts +2 -0
  35. package/src/infra/mercado-pago/helpers/mercado-pago-request.helper.d.ts +69 -0
  36. package/src/infra/mercado-pago/helpers/mercado-pago-response.helper.d.ts +8 -0
  37. package/src/infra/mercado-pago/index.d.ts +3 -0
  38. package/src/infra/mercado-pago/types/index.d.ts +2 -0
  39. package/src/infra/mercado-pago/types/mercado-pago-request.type.d.ts +1 -0
  40. package/src/infra/mercado-pago/types/mercado-pago-response.type.d.ts +180 -0
  41. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +1 -0
  42. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +1 -0
  43. package/src/utils/index.d.ts +2 -2
  44. package/src/domain/catalog/repositories/product-catalog.repository.d.ts +0 -13
  45. package/src/infra/hasura-graphql/repositories/catalog/product-catalog-hasura-graphql.repository.d.ts +0 -20
package/index.cjs.js CHANGED
@@ -114,6 +114,7 @@ exports.PaymentProviders = void 0;
114
114
  PaymentProviders["PAGARME"] = "pagarMe";
115
115
  PaymentProviders["ADYEN"] = "adyen";
116
116
  PaymentProviders["GLAMPOINTS"] = "glampoints";
117
+ PaymentProviders["MERCADOPAGO"] = "mercadoPago";
117
118
  })(exports.PaymentProviders || (exports.PaymentProviders = {}));
118
119
 
119
120
  exports.TransactionPaymentMethods = void 0;
@@ -147,6 +148,9 @@ class AntifraudProviderFactory {
147
148
  class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
148
149
  }
149
150
 
151
+ class MercadoPagoPaymentMethodFactory extends BasePaymentMethodFactory {
152
+ }
153
+
150
154
  class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
151
155
  }
152
156
 
@@ -757,6 +761,30 @@ tslib.__decorate([
757
761
  ], Category.prototype, "filters", void 0);
758
762
  registerClass('Category', Category);
759
763
 
764
+ class BrandCategory extends BaseModel {
765
+ get glamImages() {
766
+ return this.images?.[exports.Shops.GLAMSHOP]
767
+ ? this.images[exports.Shops.GLAMSHOP]
768
+ : {
769
+ brandBanner: null,
770
+ brandBannerMobile: null,
771
+ image: null,
772
+ };
773
+ }
774
+ get mensImages() {
775
+ return this.images?.[exports.Shops.MENSMARKET]
776
+ ? this.images[exports.Shops.MENSMARKET]
777
+ : {
778
+ brandBanner: null,
779
+ brandBannerMobile: null,
780
+ image: null,
781
+ };
782
+ }
783
+ static get identifiersFields() {
784
+ return ['id'];
785
+ }
786
+ }
787
+
760
788
  class CategoryCollectionChildren extends BaseModel {
761
789
  static get identifiersFields() {
762
790
  return ['collectionId', 'categoryId'];
@@ -871,12 +899,7 @@ class Variant extends ProductBase {
871
899
  static get identifiersFields() {
872
900
  return ['id', 'productId'];
873
901
  }
874
- }
875
- tslib.__decorate([
876
- classTransformer.Type(() => Product),
877
- tslib.__metadata("design:type", Product)
878
- ], Variant.prototype, "product", void 0);
879
- registerClass('Product', Product);
902
+ }
880
903
 
881
904
  class Product extends ProductBase {
882
905
  }
@@ -1765,19 +1788,58 @@ class AntifraudCardService {
1765
1788
  constructor(orderRepository, orderBlockedRepository) {
1766
1789
  this.orderRepository = orderRepository;
1767
1790
  this.orderBlockedRepository = orderBlockedRepository;
1768
- this.LIMIT_ORDERS_DAY = 2;
1769
- this.LIMIT_ORDERS_WEEK = 7;
1770
- this.LIMIT_BLOCKED_ORDERS_DAY = 5;
1791
+ this.LIMIT_ORDERS_DAY = null;
1792
+ this.LIMIT_ORDERS_WEEK = null;
1771
1793
  }
1772
1794
  async validate(checkout, card) {
1795
+ this.setLimitsByUserType(checkout.user.isSubscriber);
1773
1796
  await this.validateBlockedOrderAttempts(checkout, card);
1774
1797
  await this.validateDayAndWeekOrderLimits(checkout, card);
1775
1798
  return true;
1776
1799
  }
1800
+ setLimitsByUserType(isSubscriber) {
1801
+ this.LIMIT_ORDERS_DAY = {
1802
+ subscriber: {
1803
+ cpf: 4,
1804
+ email: 4,
1805
+ phone: 4,
1806
+ card: 4,
1807
+ zip: 4,
1808
+ },
1809
+ nonSubscriber: {
1810
+ cpf: 2,
1811
+ email: 2,
1812
+ phone: 2,
1813
+ card: 2,
1814
+ zip: 2,
1815
+ },
1816
+ };
1817
+ this.LIMIT_ORDERS_WEEK = {
1818
+ subscriber: {
1819
+ cpf: 12,
1820
+ email: 12,
1821
+ phone: 12,
1822
+ card: 12,
1823
+ zip: Infinity,
1824
+ },
1825
+ nonSubscriber: {
1826
+ cpf: 7,
1827
+ email: 7,
1828
+ phone: 7,
1829
+ card: 7,
1830
+ zip: Infinity,
1831
+ },
1832
+ };
1833
+ this.LIMIT_BLOCKED_ORDERS_DAY = isSubscriber ? 7 : 5;
1834
+ }
1835
+ getLimitsByUserType(type, isSubscriber) {
1836
+ const limits = type === 'day' ? this.LIMIT_ORDERS_DAY : this.LIMIT_ORDERS_WEEK;
1837
+ return isSubscriber ? limits['subscriber'] : limits['nonSubscriber'];
1838
+ }
1777
1839
  async validateBlockedOrderAttempts(checkout, card) {
1778
1840
  const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
1779
1841
  if (!isValid) {
1780
- throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
1842
+ throw new FraudValidationError(`Cliente com mais de ${this.LIMIT_BLOCKED_ORDERS_DAY} compras negadas/bloqueadas no dia`, {
1781
1843
  checkoutId: checkout.id,
1782
1844
  userEmail: checkout.user.email,
1783
1845
  info: {
@@ -1791,7 +1853,7 @@ class AntifraudCardService {
1791
1853
  async validateDayAndWeekOrderLimits(checkout, card) {
1792
1854
  const isValid = await this.verifyDayAndWeekOrders(checkout, card);
1793
1855
  if (!isValid) {
1794
- throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
1856
+ throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', {
1795
1857
  checkoutId: checkout.id,
1796
1858
  userEmail: checkout.user.email,
1797
1859
  info: {
@@ -1810,7 +1872,7 @@ class AntifraudCardService {
1810
1872
  await this.createBlockedOrderRecord({
1811
1873
  checkout,
1812
1874
  card,
1813
- reason: 'More than 5 attempts have failed',
1875
+ reason: `More than ${this.LIMIT_BLOCKED_ORDERS_DAY} attempts have failed`,
1814
1876
  key: 'Failed attempts',
1815
1877
  period: 'day',
1816
1878
  });
@@ -1820,7 +1882,7 @@ class AntifraudCardService {
1820
1882
  }
1821
1883
  getTodayDateRange() {
1822
1884
  const timeZone = 'America/Sao_Paulo';
1823
- const today = dateFnsTz.toZonedTime(new Date(), timeZone);
1885
+ const today = dateFnsTz.utcToZonedTime(new Date(), timeZone);
1824
1886
  const day = dateFns.startOfDay(today);
1825
1887
  const endOfDay = dateFns.endOfDay(today);
1826
1888
  return { day: dateFns.addHours(day, 3), endOfDay: dateFns.addHours(endOfDay, 3) };
@@ -1931,26 +1993,28 @@ class AntifraudCardService {
1931
1993
  }
1932
1994
  async validateDayOrderLimits(checkout, params) {
1933
1995
  const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
1996
+ const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
1934
1997
  return this.checkOrderLimitsAndBlock({
1935
1998
  checkout,
1936
1999
  orderCounts: ordersPerDay,
1937
- limit: this.LIMIT_ORDERS_DAY,
2000
+ limit: limits,
1938
2001
  period: 'day',
1939
2002
  });
1940
2003
  }
1941
2004
  async validateWeekOrderLimits(checkout, params) {
1942
2005
  const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
2006
+ const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
1943
2007
  return this.checkOrderLimitsAndBlock({
1944
2008
  checkout,
1945
2009
  orderCounts: ordersPerWeek,
1946
- limit: this.LIMIT_ORDERS_WEEK,
2010
+ limit: limits,
1947
2011
  period: 'week',
1948
2012
  });
1949
2013
  }
1950
2014
  async checkOrderLimitsAndBlock(params) {
1951
2015
  const { checkout, orderCounts, limit, period } = params;
1952
2016
  for (const key in orderCounts) {
1953
- if (orderCounts[key] >= limit) {
2017
+ if (orderCounts[key] >= limit[key]) {
1954
2018
  await this.createBlockedOrderRecord({
1955
2019
  checkout,
1956
2020
  card: null,
@@ -3397,8 +3461,6 @@ class HasuraQueryBuilderHelper {
3397
3461
  class HasuraRequestHelper {
3398
3462
  static async fetch(params) {
3399
3463
  const { variables, query, endpoint, headers, logger } = params;
3400
- console.warn('variables', variables);
3401
- console.warn('query', query);
3402
3464
  const request = {
3403
3465
  url: endpoint,
3404
3466
  method: 'POST',
@@ -4770,6 +4832,17 @@ const withCrudFirestore = (MixinBase) => {
4770
4832
  };
4771
4833
  };
4772
4834
 
4835
+ class BrandCategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4836
+ constructor({ firestore, interceptors, }) {
4837
+ super({
4838
+ firestore,
4839
+ collectionName: 'brandsCategory',
4840
+ model: BrandCategory,
4841
+ interceptors,
4842
+ });
4843
+ }
4844
+ }
4845
+
4773
4846
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4774
4847
  constructor({ firestore, interceptors }) {
4775
4848
  super({
@@ -7223,7 +7296,83 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
7223
7296
  }
7224
7297
  }
7225
7298
 
7226
- const commonFields$1 = [
7299
+ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7300
+ constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7301
+ super({
7302
+ tableName: 'product_errors',
7303
+ model: ProductErrorsHasuraGraphQL,
7304
+ endpoint,
7305
+ authOptions,
7306
+ interceptors,
7307
+ cache,
7308
+ fields: [
7309
+ {
7310
+ productId: {
7311
+ columnName: 'product_id',
7312
+ to: (value) => +value,
7313
+ from: (value) => value.toString(),
7314
+ },
7315
+ },
7316
+ 'source',
7317
+ 'error',
7318
+ { createdAt: { columnName: 'created_at' } },
7319
+ { updatedAt: { columnName: 'updated_at' } },
7320
+ {
7321
+ product: {
7322
+ columnName: 'product',
7323
+ foreignKeyColumn: { id: 'productId' },
7324
+ fields: [
7325
+ { id: { columnName: 'id', from: (value) => value.toString() } },
7326
+ { productId: { columnName: 'main_product_id' } },
7327
+ 'name',
7328
+ 'published',
7329
+ 'group',
7330
+ 'validity',
7331
+ { createdAt: { columnName: 'created_at' } },
7332
+ { updatedAt: { columnName: 'updated_at' } },
7333
+ ],
7334
+ },
7335
+ },
7336
+ ],
7337
+ });
7338
+ this.productRepository = productRepository;
7339
+ }
7340
+ async get(params) {
7341
+ const result = await super.get(params);
7342
+ if (result instanceof VariantHasuraGraphQL) {
7343
+ const product = await this.productRepository.get({ id: result.productId.toString() });
7344
+ result.product.name = product.name;
7345
+ result.product.group = product.group;
7346
+ }
7347
+ return result;
7348
+ }
7349
+ async find(params) {
7350
+ const result = await super.find(params);
7351
+ const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
7352
+ (lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
7353
+ if (variantsWithNoData.length > 0) {
7354
+ const { data: products } = await this.productRepository.find({
7355
+ filters: {
7356
+ id: {
7357
+ operator: exports.Where.IN,
7358
+ value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
7359
+ },
7360
+ },
7361
+ });
7362
+ products.forEach((product) => {
7363
+ result.data
7364
+ .filter((variant) => variant.product.productId?.toString() === product.id.toString())
7365
+ .forEach((variant) => {
7366
+ variant.product.name = product.name;
7367
+ variant.product.group = product.group;
7368
+ });
7369
+ });
7370
+ }
7371
+ return result;
7372
+ }
7373
+ }
7374
+
7375
+ const commonFields = [
7227
7376
  {
7228
7377
  id: {
7229
7378
  columnName: 'id',
@@ -7378,370 +7527,48 @@ const commonFields$1 = [
7378
7527
  { reviewsTotal: { columnName: 'reviews_total' } },
7379
7528
  { shoppingCount: { columnName: 'shopping_count' } },
7380
7529
  { categoryId: { columnName: 'category_id' } },
7530
+ {
7531
+ category: {
7532
+ columnName: 'category',
7533
+ foreignKeyColumn: { id: 'categoryId' },
7534
+ fields: ['id', 'name', 'reference', 'slug'],
7535
+ },
7536
+ },
7381
7537
  'group',
7382
7538
  'validity',
7383
7539
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7384
7540
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7385
7541
  { daysOfUse: { columnName: 'days_of_use' } },
7386
- { showVariants: { columnName: 'show_variants' } },
7387
7542
  ];
7388
- class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7389
- constructor({ endpoint, authOptions, interceptors, cache, }) {
7390
- super({
7391
- tableName: 'product_catalog',
7392
- model: ProductHasuraGraphQL,
7393
- endpoint,
7394
- authOptions,
7395
- interceptors,
7396
- fields: commonFields$1,
7397
- cache,
7398
- });
7399
- }
7400
- async get({ id }) {
7401
- return super
7402
- .find({
7403
- filters: {
7404
- id,
7405
- },
7406
- limits: {
7407
- limit: 1,
7408
- },
7409
- })
7410
- .then((res) => res.data.at(0));
7411
- }
7412
- async getByEAN(EAN, options) {
7413
- return super
7414
- .find({
7415
- filters: {
7416
- EAN,
7417
- },
7418
- limits: {
7419
- limit: 1,
7420
- },
7421
- })
7422
- .then((res) => res.data.at(0));
7423
- }
7424
- async find(params, optionsParams) {
7425
- const { filters, fields, ...options } = params || {};
7426
- const bindFields = fields ||
7427
- this.fields
7428
- .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7429
- .filter((field) => field !== 'reviews' && field !== 'categories');
7430
- if (options.options?.minimal?.includes('price'))
7431
- options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7432
- if (options.options?.maximum?.includes('price'))
7433
- options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7434
- options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7435
- options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7436
- return super.find({
7437
- ...options,
7438
- filters: { ...filters },
7543
+ const fieldsConfiguration$2 = [
7544
+ ...commonFields,
7545
+ {
7546
+ categories: {
7547
+ columnName: 'categories',
7548
+ fields: ['category_id'],
7549
+ bindPersistData: (value) => ({
7550
+ categories: { data: value.map((category) => ({ category_id: +category })) },
7551
+ }),
7552
+ to: (categories) => categories.map((categoryId) => +categoryId),
7553
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
7554
+ },
7555
+ },
7556
+ {
7557
+ kitProducts: {
7558
+ columnName: 'kit_products',
7559
+ foreignKeyColumn: { productId: 'id' },
7439
7560
  fields: [
7440
- ...bindFields,
7441
- ...(bindFields.includes('price')
7442
- ? [
7443
- 'subscriberPrice',
7444
- 'subscriberDiscountPercentage',
7445
- 'fullPrice',
7446
- ]
7447
- : []),
7561
+ { productId: { columnName: 'product_id' } },
7562
+ { kitProductId: { columnName: 'kit_product_id' } },
7563
+ 'quantity',
7564
+ { product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
7448
7565
  ],
7449
- }, optionsParams);
7450
- }
7451
- async findCatalog(params, mainGender, options) {
7452
- const result = await this.find({
7453
- ...params,
7454
- filters: { ...params.filters, published: true },
7455
- orderBy: {
7456
- hasStock: 'desc',
7457
- ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7458
- ...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
7459
- },
7460
- }, options);
7461
- return result;
7462
- }
7463
- }
7464
- tslib.__decorate([
7465
- Log(),
7466
- tslib.__metadata("design:type", Function),
7467
- tslib.__metadata("design:paramtypes", [Object, Object, Object]),
7468
- tslib.__metadata("design:returntype", Promise)
7469
- ], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
7470
-
7471
- class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7472
- constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7473
- super({
7474
- tableName: 'product_errors',
7475
- model: ProductErrorsHasuraGraphQL,
7476
- endpoint,
7477
- authOptions,
7478
- interceptors,
7479
- cache,
7480
- fields: [
7481
- {
7482
- productId: {
7483
- columnName: 'product_id',
7484
- to: (value) => +value,
7485
- from: (value) => value.toString(),
7486
- },
7487
- },
7488
- 'source',
7489
- 'error',
7490
- { createdAt: { columnName: 'created_at' } },
7491
- { updatedAt: { columnName: 'updated_at' } },
7492
- {
7493
- product: {
7494
- columnName: 'product',
7495
- foreignKeyColumn: { id: 'productId' },
7496
- fields: [
7497
- { id: { columnName: 'id', from: (value) => value.toString() } },
7498
- { productId: { columnName: 'main_product_id' } },
7499
- 'name',
7500
- 'published',
7501
- 'group',
7502
- 'validity',
7503
- { createdAt: { columnName: 'created_at' } },
7504
- { updatedAt: { columnName: 'updated_at' } },
7505
- ],
7506
- },
7507
- },
7508
- ],
7509
- });
7510
- this.productRepository = productRepository;
7511
- }
7512
- async get(params) {
7513
- const result = await super.get(params);
7514
- if (result instanceof VariantHasuraGraphQL) {
7515
- const product = await this.productRepository.get({ id: result.productId.toString() });
7516
- result.product.name = product.name;
7517
- result.product.group = product.group;
7518
- }
7519
- return result;
7520
- }
7521
- async find(params) {
7522
- const result = await super.find(params);
7523
- const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
7524
- (lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
7525
- if (variantsWithNoData.length > 0) {
7526
- const { data: products } = await this.productRepository.find({
7527
- filters: {
7528
- id: {
7529
- operator: exports.Where.IN,
7530
- value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
7531
- },
7532
- },
7533
- });
7534
- products.forEach((product) => {
7535
- result.data
7536
- .filter((variant) => variant.product.productId?.toString() === product.id.toString())
7537
- .forEach((variant) => {
7538
- variant.product.name = product.name;
7539
- variant.product.group = product.group;
7540
- });
7541
- });
7542
- }
7543
- return result;
7544
- }
7545
- }
7546
-
7547
- const commonFields = [
7548
- {
7549
- id: {
7550
- columnName: 'id',
7551
- to: (value) => +value,
7552
- from: (value) => value.toString(),
7553
- },
7554
- },
7555
- { firestoreId: { columnName: 'firestore_id' } },
7556
- { productId: { columnName: 'main_product_id' } },
7557
- { CEST: { columnName: 'cest' } },
7558
- { EAN: { columnName: 'ean' } },
7559
- { NCM: { columnName: 'ncm' } },
7560
- 'brand',
7561
- { costPrice: { columnName: 'cost_price' } },
7562
- {
7563
- description: {
7564
- columnName: 'description',
7565
- from: (description, data) => ({
7566
- description,
7567
- differentials: data.differentials,
7568
- whoMustUse: data.who_must_use,
7569
- howToUse: data.how_to_use,
7570
- brand: data.brand_description,
7571
- ingredients: data.ingredients,
7572
- purpose: data.purpose,
7573
- }),
7574
- bindFindFilter: (filters) => {
7575
- return {
7576
- ...(filters?.description && { description: filters.description }),
7577
- ...(filters.differentials && { differentials: filters.differentials }),
7578
- ...(filters.whoMustUse && {
7579
- who_must_use: filters.whoMustUse,
7580
- }),
7581
- ...(filters.howToUse && {
7582
- how_to_use: filters.howToUse,
7583
- }),
7584
- ...(filters.brand && {
7585
- brand_description: filters.brand,
7586
- }),
7587
- ...(filters.ingredients && {
7588
- ingredients: filters.ingredients,
7589
- }),
7590
- ...(filters.purpose && {
7591
- purpose: filters.purpose,
7592
- }),
7593
- };
7594
- },
7595
- bindPersistData: (descriptionData) => ({
7596
- ...(descriptionData?.description && { description: descriptionData.description }),
7597
- ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7598
- ...(descriptionData.whoMustUse && {
7599
- who_must_use: descriptionData.whoMustUse,
7600
- }),
7601
- ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7602
- ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7603
- ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7604
- ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7605
- }),
7606
- },
7607
- },
7608
- { differentials: { columnName: 'differentials' } },
7609
- { whoMustUse: { columnName: 'who_must_use' } },
7610
- { howToUse: { columnName: 'how_to_use' } },
7611
- { brandDescription: { columnName: 'brand_description' } },
7612
- { ingredients: { columnName: 'ingredients' } },
7613
- { purpose: { columnName: 'purpose' } },
7614
- { hasVariants: { columnName: 'has_variants' } },
7615
- {
7616
- images: {
7617
- columnName: 'images',
7618
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7619
- },
7620
- },
7621
- {
7622
- miniatures: {
7623
- columnName: 'miniatures',
7624
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7625
- },
7626
- },
7627
- {
7628
- imagesCard: {
7629
- columnName: 'images_card',
7630
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7631
- },
7632
- },
7633
- 'name',
7634
- {
7635
- price: {
7636
- columnName: 'price',
7637
- from: (price, data) => ({
7638
- price,
7639
- fullPrice: data.full_price,
7640
- subscriberDiscountPercentage: data.subscriber_discount_percentage,
7641
- fullPriceDiscountPercentage: data.full_price_discount_percentage,
7642
- subscriberPrice: data.subscriber_price,
7643
- }),
7644
- bindFindFilter: (filters) => {
7645
- return {
7646
- ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7647
- ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7648
- ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7649
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7650
- }),
7651
- ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7652
- subscriber_price: filters.subscriberPrice,
7653
- }),
7654
- ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7655
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7656
- }),
7657
- };
7658
- },
7659
- bindPersistData: (priceData) => ({
7660
- ...(priceData?.price >= 0 && { price: priceData.price }),
7661
- ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7662
- ...(priceData.subscriberDiscountPercentage >= 0 && {
7663
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7664
- }),
7665
- ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7666
- ...(priceData.fullPriceDiscountPercentage >= 0 && {
7667
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7668
- }),
7669
- }),
7670
- },
7671
- },
7672
- { fullPrice: { columnName: 'full_price' } },
7673
- { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7674
- { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7675
- { subscriberPrice: { columnName: 'subscriber_price' } },
7676
- 'published',
7677
- 'outlet',
7678
- 'label',
7679
- 'sku',
7680
- {
7681
- stock: {
7682
- columnName: 'stock',
7683
- from: (quantity) => ({ quantity }),
7684
- to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
7685
- },
7686
- },
7687
- { hasStock: { columnName: 'has_stock' } },
7688
- 'slug',
7689
- 'type',
7690
- 'video',
7691
- 'weight',
7692
- 'gender',
7693
- { intGender: { columnName: 'int_gender' } },
7694
- { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7695
- { isKit: { columnName: 'is_kit' } },
7696
- { createdAt: { columnName: 'created_at' } },
7697
- { updatedAt: { columnName: 'updated_at' } },
7698
- { rate: { columnName: 'rating' } },
7699
- { reviewsTotal: { columnName: 'reviews_total' } },
7700
- { shoppingCount: { columnName: 'shopping_count' } },
7701
- { categoryId: { columnName: 'category_id' } },
7702
- {
7703
- category: {
7704
- columnName: 'category',
7705
- foreignKeyColumn: { id: 'categoryId' },
7706
- fields: ['id', 'name', 'reference', 'slug'],
7707
- },
7708
- },
7709
- 'group',
7710
- 'validity',
7711
- { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7712
- { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7713
- { daysOfUse: { columnName: 'days_of_use' } },
7714
- { showVariants: { columnName: 'show_variants' } },
7715
- ];
7716
- const fieldsConfiguration$2 = [
7717
- ...commonFields,
7718
- {
7719
- categories: {
7720
- columnName: 'categories',
7721
- fields: ['category_id'],
7722
- bindPersistData: (value) => ({
7723
- categories: { data: value.map((category) => ({ category_id: +category })) },
7724
- }),
7725
- to: (categories) => categories.map((categoryId) => +categoryId),
7726
- from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
7727
- },
7728
- },
7729
- {
7730
- kitProducts: {
7731
- columnName: 'kit_products',
7732
- foreignKeyColumn: { productId: 'id' },
7733
- fields: [
7734
- { productId: { columnName: 'product_id' } },
7735
- { kitProductId: { columnName: 'kit_product_id' } },
7736
- 'quantity',
7737
- { product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
7738
- ],
7739
- },
7740
- },
7741
- {
7742
- reviews: {
7743
- columnName: 'reviews',
7744
- foreignKeyColumn: { product_id: 'id' },
7566
+ },
7567
+ },
7568
+ {
7569
+ reviews: {
7570
+ columnName: 'reviews',
7571
+ foreignKeyColumn: { product_id: 'id' },
7745
7572
  fields: [
7746
7573
  'id',
7747
7574
  'shop',
@@ -7775,61 +7602,9 @@ const fieldsConfiguration$2 = [
7775
7602
  foreignKeyColumn: { product_id: 'id' },
7776
7603
  fields: [
7777
7604
  'id',
7778
- 'name',
7779
7605
  'ean',
7780
7606
  'sku',
7781
- {
7782
- description: {
7783
- columnName: 'description',
7784
- from: (description, data) => ({
7785
- description,
7786
- differentials: data.differentials,
7787
- whoMustUse: data.who_must_use,
7788
- howToUse: data.how_to_use,
7789
- brand: data.brand_description,
7790
- ingredients: data.ingredients,
7791
- purpose: data.purpose,
7792
- }),
7793
- bindFindFilter: (filters) => {
7794
- return {
7795
- ...(filters?.description && { description: filters.description }),
7796
- ...(filters.differentials && { differentials: filters.differentials }),
7797
- ...(filters.whoMustUse && {
7798
- who_must_use: filters.whoMustUse,
7799
- }),
7800
- ...(filters.howToUse && {
7801
- how_to_use: filters.howToUse,
7802
- }),
7803
- ...(filters.brand && {
7804
- brand_description: filters.brand,
7805
- }),
7806
- ...(filters.ingredients && {
7807
- ingredients: filters.ingredients,
7808
- }),
7809
- ...(filters.purpose && {
7810
- purpose: filters.purpose,
7811
- }),
7812
- };
7813
- },
7814
- bindPersistData: (descriptionData) => ({
7815
- ...(descriptionData?.description && { description: descriptionData.description }),
7816
- ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7817
- ...(descriptionData.whoMustUse && {
7818
- who_must_use: descriptionData.whoMustUse,
7819
- }),
7820
- ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7821
- ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7822
- ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7823
- ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7824
- }),
7825
- },
7826
- },
7827
- { differentials: { columnName: 'differentials' } },
7828
- { whoMustUse: { columnName: 'who_must_use' } },
7829
- { howToUse: { columnName: 'how_to_use' } },
7830
- { brandDescription: { columnName: 'brand_description' } },
7831
- { ingredients: { columnName: 'ingredients' } },
7832
- { purpose: { columnName: 'purpose' } },
7607
+ 'description',
7833
7608
  {
7834
7609
  grade: {
7835
7610
  columnName: 'grade',
@@ -7875,6 +7650,10 @@ const fieldsConfiguration$2 = [
7875
7650
  }),
7876
7651
  },
7877
7652
  },
7653
+ { fullPrice: { columnName: 'full_price' } },
7654
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7655
+ { subscriberPrice: { columnName: 'subscriber_price' } },
7656
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7878
7657
  'published',
7879
7658
  {
7880
7659
  stock: {
@@ -7966,10 +7745,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7966
7745
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7967
7746
  .data?.[0]
7968
7747
  : await super.get(identifiers, options);
7969
- // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7970
- product.reviews =
7971
- product.reviews ||
7972
- (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
7748
+ if (product.productId)
7749
+ throw new NotFoundError('Product not found, it is a variant');
7750
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
7973
7751
  return product;
7974
7752
  }
7975
7753
  async find(params, optionsParams) {
@@ -7986,9 +7764,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7986
7764
  options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7987
7765
  return super.find({
7988
7766
  ...options,
7989
- filters: { ...filters },
7990
- // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7991
- // filters: { ...filters, productId: { operator: Where.ISNULL } },
7767
+ filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
7992
7768
  fields: [
7993
7769
  ...bindFields,
7994
7770
  ...(bindFields.includes('price')
@@ -8022,13 +7798,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8022
7798
  if (!result.data.length)
8023
7799
  return null;
8024
7800
  const product = result?.data?.shift();
8025
- if (product.productId) ;
8026
- console.warn('product getBySlug', product);
8027
- console.warn('vai entrar', !product.reviews.length && product.rate > 0);
8028
- if (!product.reviews.length && product.rate > 0) {
8029
- console.warn('entrou');
8030
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8031
- }
8032
7801
  RoundProductPricesHelper.roundProductPrices(product);
8033
7802
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
8034
7803
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
@@ -8041,18 +7810,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8041
7810
  }
8042
7811
  return product;
8043
7812
  }
8044
- async getBySlugVariantData(product) {
8045
- if (!product.reviews.length && product.rate > 0) {
8046
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8047
- }
8048
- // if (!product.metadata) {
8049
- // product.metadata = await this.findReviewsByProduct(
8050
- // (product.productId ? product.productId : product.id) as number,
8051
- // true,
8052
- // )
8053
- // }
8054
- return product;
8055
- }
8056
7813
  async getByEAN(EAN, options) {
8057
7814
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8058
7815
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -8242,7 +7999,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8242
7999
  return data?.[0]?.id;
8243
8000
  throw new NotFoundError(`Product with id ${id} not found`);
8244
8001
  }
8245
- async findReviewsByProduct(productId, onlyApproved, options) {
8002
+ async findReviewsByProduct(productId, options) {
8246
8003
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8247
8004
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
8248
8005
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
@@ -8255,7 +8012,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8255
8012
  where: {
8256
8013
  value: {
8257
8014
  product_id: { _eq: productId },
8258
- ...(onlyApproved && { status: { _eq: true } }),
8259
8015
  },
8260
8016
  type: 'product_review_bool_exp',
8261
8017
  required: true,
@@ -8364,7 +8120,7 @@ tslib.__decorate([
8364
8120
  tslib.__decorate([
8365
8121
  Log(),
8366
8122
  tslib.__metadata("design:type", Function),
8367
- tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
8123
+ tslib.__metadata("design:paramtypes", [Number, Object]),
8368
8124
  tslib.__metadata("design:returntype", Promise)
8369
8125
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
8370
8126
 
@@ -8552,143 +8308,66 @@ const fieldsConfiguration$1 = [
8552
8308
  };
8553
8309
  },
8554
8310
  bindPersistData: (priceData) => ({
8555
- ...((priceData?.price || 0) >= 0 && { price: priceData.price }),
8556
- ...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
8557
- ...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
8558
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
8559
- }),
8560
- ...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
8561
- ...(priceData.fullPriceDiscountPercentage >= 0 && {
8562
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
8563
- }),
8564
- }),
8565
- },
8566
- },
8567
- { fullPrice: { columnName: 'full_price' } },
8568
- { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
8569
- { subscriberPrice: { columnName: 'subscriber_price' } },
8570
- { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
8571
- 'sku',
8572
- {
8573
- stock: {
8574
- columnName: 'stock',
8575
- from: (quantity) => ({ quantity }),
8576
- to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
8577
- },
8578
- },
8579
- { hasStock: { columnName: 'has_stock' } },
8580
- 'weight',
8581
- { name: { to: () => '', from: () => undefined } },
8582
- { hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
8583
- { createdAt: { columnName: 'created_at' } },
8584
- { updatedAt: { columnName: 'updated_at' } },
8585
- {
8586
- grade: {
8587
- columnName: 'grade',
8588
- type: HasuraGraphQLColumnType.Jsonb,
8589
- },
8590
- },
8591
- 'group',
8592
- 'validity',
8593
- 'published',
8594
- { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8595
- { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8596
- { daysOfUse: { columnName: 'days_of_use' } },
8597
- {
8598
- images: {
8599
- columnName: 'images',
8600
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8601
- },
8602
- },
8603
- {
8604
- miniatures: {
8605
- columnName: 'miniatures',
8606
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8607
- },
8608
- },
8609
- {
8610
- imagesCard: {
8611
- columnName: 'images_card',
8612
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8613
- },
8614
- },
8615
- 'slug',
8616
- 'brand',
8617
- 'name',
8618
- 'sku',
8619
- { NCM: { columnName: 'ncm' } },
8620
- { CEST: { columnName: 'cest' } },
8621
- {
8622
- description: {
8623
- columnName: 'description',
8624
- from: (description, data) => ({
8625
- description,
8626
- differentials: data.differentials,
8627
- whoMustUse: data.who_must_use,
8628
- howToUse: data.how_to_use,
8629
- brand: data.brand_description,
8630
- ingredients: data.ingredients,
8631
- purpose: data.purpose,
8632
- }),
8633
- bindFindFilter: (filters) => {
8634
- return {
8635
- ...(filters?.description && { description: filters.description }),
8636
- ...(filters.differentials && { differentials: filters.differentials }),
8637
- ...(filters.whoMustUse && {
8638
- who_must_use: filters.whoMustUse,
8639
- }),
8640
- ...(filters.howToUse && {
8641
- how_to_use: filters.howToUse,
8642
- }),
8643
- ...(filters.brand && {
8644
- brand_description: filters.brand,
8645
- }),
8646
- ...(filters.ingredients && {
8647
- ingredients: filters.ingredients,
8648
- }),
8649
- ...(filters.purpose && {
8650
- purpose: filters.purpose,
8651
- }),
8652
- };
8653
- },
8654
- bindPersistData: (descriptionData) => ({
8655
- ...(descriptionData?.description && { description: descriptionData.description }),
8656
- ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
8657
- ...(descriptionData.whoMustUse && {
8658
- who_must_use: descriptionData.whoMustUse,
8659
- }),
8660
- ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
8661
- ...(descriptionData.brand && { brand_description: descriptionData.brand }),
8662
- ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
8663
- ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
8664
- }),
8665
- },
8666
- },
8667
- { differentials: { columnName: 'differentials' } },
8668
- { whoMustUse: { columnName: 'who_must_use' } },
8669
- { howToUse: { columnName: 'how_to_use' } },
8670
- { brandDescription: { columnName: 'brand_description' } },
8671
- { ingredients: { columnName: 'ingredients' } },
8672
- { purpose: { columnName: 'purpose' } },
8673
- 'gender',
8674
- { intGender: { columnName: 'int_gender' } },
8675
- 'label',
8676
- { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
8677
- { rate: { columnName: 'rating' } },
8678
- { reviewsTotal: { columnName: 'reviews_total' } },
8679
- { shoppingCount: { columnName: 'shopping_count' } },
8680
- { categoryId: { columnName: 'category_id' } },
8681
- {
8682
- metadata: {
8683
- columnName: 'metadata',
8684
- fields: ['title', 'description'],
8685
- bindPersistData: (value) => ({
8686
- metadata: { data: value },
8311
+ ...((priceData?.price || 0) >= 0 && { price: priceData.price }),
8312
+ ...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
8313
+ ...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
8314
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
8315
+ }),
8316
+ ...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
8317
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
8318
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
8319
+ }),
8687
8320
  }),
8688
8321
  },
8689
8322
  },
8323
+ { fullPrice: { columnName: 'full_price' } },
8324
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
8325
+ { subscriberPrice: { columnName: 'subscriber_price' } },
8326
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
8327
+ 'sku',
8328
+ {
8329
+ stock: {
8330
+ columnName: 'stock',
8331
+ from: (quantity) => ({ quantity }),
8332
+ to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
8333
+ },
8334
+ },
8335
+ { hasStock: { columnName: 'has_stock' } },
8336
+ 'weight',
8337
+ { name: { to: () => '', from: () => undefined } },
8338
+ { hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
8690
8339
  { createdAt: { columnName: 'created_at' } },
8691
8340
  { updatedAt: { columnName: 'updated_at' } },
8341
+ {
8342
+ grade: {
8343
+ columnName: 'grade',
8344
+ type: HasuraGraphQLColumnType.Jsonb,
8345
+ },
8346
+ },
8347
+ 'group',
8348
+ 'validity',
8349
+ 'published',
8350
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8351
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8352
+ { daysOfUse: { columnName: 'days_of_use' } },
8353
+ {
8354
+ images: {
8355
+ columnName: 'images',
8356
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8357
+ },
8358
+ },
8359
+ {
8360
+ miniatures: {
8361
+ columnName: 'miniatures',
8362
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8363
+ },
8364
+ },
8365
+ {
8366
+ imagesCard: {
8367
+ columnName: 'images_card',
8368
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8369
+ },
8370
+ },
8692
8371
  ];
8693
8372
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8694
8373
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8729,37 +8408,18 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8729
8408
  return data.at(0);
8730
8409
  }
8731
8410
  async update(params) {
8732
- const { productId, id: checkId, metadata, ...data } = params;
8411
+ const { productId, id: checkId, ...data } = params;
8733
8412
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
8734
8413
  if (!dataWithProductId.id) {
8735
8414
  throw new NotFoundError('Variant ID is required for update');
8736
8415
  }
8737
8416
  const id = await this.getId(dataWithProductId.id);
8738
8417
  const product = await super.update({ id, ...data });
8739
- product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
8740
8418
  if (dataWithProductId.productId) {
8741
8419
  product.productId = dataWithProductId.productId;
8742
8420
  }
8743
8421
  return product;
8744
8422
  }
8745
- async updateMetadata(productId, { metadata }) {
8746
- const plainData = this.paramsToPlain({ metadata });
8747
- if (!plainData.metadata)
8748
- return null;
8749
- await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8750
- pk_columns: {
8751
- value: { product_id: productId },
8752
- type: 'product_metadata_pk_columns_input',
8753
- required: true,
8754
- },
8755
- _set: {
8756
- value: lodash.omit(metadata, ['product_id']),
8757
- type: 'product_metadata_set_input',
8758
- required: true,
8759
- },
8760
- });
8761
- return plainData.metadata;
8762
- }
8763
8423
  async getId(id) {
8764
8424
  if (!Number.isNaN(+id))
8765
8425
  return id;
@@ -9103,6 +8763,356 @@ tslib.__decorate([
9103
8763
  tslib.__metadata("design:returntype", Promise)
9104
8764
  ], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
9105
8765
 
8766
+ class MercadoPagoRequestHelper {
8767
+ static build(data) {
8768
+ const { checkout, method, postback, card } = data;
8769
+ return {
8770
+ transaction_amount: +checkout.totalPrice.toFixed(2),
8771
+ notification_url: postback,
8772
+ metadata: {
8773
+ checkoutId: checkout.id,
8774
+ },
8775
+ payer: this.buildPayer(checkout),
8776
+ statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
8777
+ additional_info: {
8778
+ items: this.buildItems(checkout),
8779
+ payer: this.buildFullPayer(checkout),
8780
+ },
8781
+ ...(method === 'credit_card' && this.buildCardPayment(card)),
8782
+ ...(method === 'pix' && this.buildPixPayment()),
8783
+ ...(method === 'boleto' && this.buildBoletoPayment(checkout)),
8784
+ };
8785
+ }
8786
+ static buildItems(checkout) {
8787
+ return checkout.lineItems
8788
+ .filter((item) => !item.isGift)
8789
+ .map((item) => {
8790
+ return {
8791
+ id: item.EAN,
8792
+ title: item.name,
8793
+ description: item.name,
8794
+ picture_url: item.image ?? null,
8795
+ category_id: item.category?.id ?? null,
8796
+ quantity: item.quantity,
8797
+ unit_price: +item.pricePaid.toFixed(2),
8798
+ };
8799
+ });
8800
+ }
8801
+ static buildPayer(checkout) {
8802
+ return {
8803
+ first_name: checkout.user.firstName,
8804
+ last_name: checkout.user.lastName,
8805
+ email: checkout.user.email,
8806
+ identification: {
8807
+ type: 'CPF',
8808
+ number: checkout.user.cpf.replace(/\D/g, ''),
8809
+ },
8810
+ };
8811
+ }
8812
+ static buildFullPayer(checkout) {
8813
+ return {
8814
+ first_name: checkout.user.firstName,
8815
+ last_name: checkout.user.lastName,
8816
+ phone: {
8817
+ area_code: checkout.user.phone.substring(0, 2),
8818
+ number: checkout.user.phone.substring(2),
8819
+ },
8820
+ address: {
8821
+ zip_code: checkout.shippingAddress.zip,
8822
+ street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8823
+ street_number: checkout.shippingAddress.number,
8824
+ neighborhood: checkout.shippingAddress.district,
8825
+ city: checkout.shippingAddress.city,
8826
+ federal_unit: checkout.shippingAddress.state,
8827
+ },
8828
+ };
8829
+ }
8830
+ static buildCardPayment(card) {
8831
+ return {
8832
+ installments: card.installments,
8833
+ token: card.cardId,
8834
+ };
8835
+ }
8836
+ static buildPixPayment() {
8837
+ return {
8838
+ payment_method_id: 'pix',
8839
+ date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
8840
+ };
8841
+ }
8842
+ static buildBoletoPayment(checkout) {
8843
+ return {
8844
+ payment_method_id: 'bolbradesco',
8845
+ date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
8846
+ payer: {
8847
+ first_name: checkout.user.firstName,
8848
+ last_name: checkout.user.lastName,
8849
+ phone: {
8850
+ area_code: checkout.user.phone.substring(0, 2),
8851
+ number: checkout.user.phone.substring(2),
8852
+ },
8853
+ address: {
8854
+ zip_code: checkout.shippingAddress.zip,
8855
+ street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8856
+ street_number: checkout.shippingAddress.number,
8857
+ neighborhood: checkout.shippingAddress.district,
8858
+ city: checkout.shippingAddress.city,
8859
+ federal_unit: checkout.shippingAddress.state,
8860
+ },
8861
+ },
8862
+ };
8863
+ }
8864
+ }
8865
+
8866
+ class MercadoPagoResponseHelper {
8867
+ static build(method, checkout, response) {
8868
+ return Payment.toInstance({
8869
+ createdAt: new Date(),
8870
+ updatedAt: new Date(),
8871
+ userId: checkout.user.id,
8872
+ checkoutId: checkout.id,
8873
+ totalPrice: checkout.totalPrice,
8874
+ paymentProvider: exports.PaymentProviders.MERCADOPAGO,
8875
+ mercadoPagoId: response.id,
8876
+ transaction: this.buildPaymentTransaction(method, response),
8877
+ });
8878
+ }
8879
+ static buildPaymentTransaction(method, response) {
8880
+ return PaymentTransaction.toInstance({
8881
+ id: response.id.toString(),
8882
+ acquirer_name: exports.PaymentProviders.MERCADOPAGO,
8883
+ amount: response.transaction_amount,
8884
+ status: response.status,
8885
+ status_reason: response.status_detail?.toString(),
8886
+ payment_method: method,
8887
+ currency: response.currency_id?.toString(),
8888
+ paid_amount: response.transaction_details?.total_paid_amount ?? null,
8889
+ paid_at: response.date_approved ?? null,
8890
+ charger_id: response.charges_details?.at(0)?.id?.toString() ?? null,
8891
+ ...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(response)),
8892
+ ...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(response)),
8893
+ });
8894
+ }
8895
+ // private static getBoletoReponse(transaction: MercadoPagoResponse): Partial<PaymentTransaction> {
8896
+ // return {
8897
+ // boleto_url: transaction.url?.toString(),
8898
+ // boleto_barcode: transaction.line?.toString(),
8899
+ // boleto_qr_code: transaction.qr_code?.toString(),
8900
+ // boleto_expiration_date: transaction.due_at?.toString(),
8901
+ // boleto_instructions: transaction.instructions?.toString(),
8902
+ // boleto_nosso_numero: transaction.nosso_numero?.toString(),
8903
+ // boleto_type: transaction.type?.toString(),
8904
+ // boleto_document_number: transaction.document_number?.toString(),
8905
+ // }
8906
+ // }
8907
+ static getPixReponse(response) {
8908
+ return {
8909
+ pix_qr_code: response.point_of_interaction?.transaction_data?.qr_code,
8910
+ pix_expiration_date: response.date_of_expiration?.toString(),
8911
+ };
8912
+ }
8913
+ static getCardReponse(response) {
8914
+ return {
8915
+ soft_descriptor: response.statement_descriptor?.toString(),
8916
+ installments: response.installments,
8917
+ card_brand: response.payment_method_id?.toString(),
8918
+ card_first_digits: response.card?.first_six_digits?.toString(),
8919
+ card_last_digits: response.card?.last_four_digits?.toString(),
8920
+ card_id: response.card?.id?.toString(),
8921
+ card_holder_name: response.card?.cardholder?.name?.toString(),
8922
+ card_expiration_month: response.card?.expiration_month?.toString(),
8923
+ card_expiration_year: response.card?.expiration_year?.toString(),
8924
+ capture_method: response.payment_type_id?.toString(),
8925
+ authorization_code: response.authorization_code?.toString(),
8926
+ };
8927
+ }
8928
+ }
8929
+
8930
+ class MercadoPagoBankSlipAxiosAdapter {
8931
+ constructor(credentials, paymentRepository) {
8932
+ this.credentials = credentials;
8933
+ this.paymentRepository = paymentRepository;
8934
+ }
8935
+ async pay(checkout) {
8936
+ try {
8937
+ const payload = MercadoPagoRequestHelper.build({
8938
+ checkout,
8939
+ method: 'boleto',
8940
+ postback: this.credentials.postback,
8941
+ });
8942
+ console.warn('[MERCADO PAGO BOLETO DATA TO SEND]', JSON.stringify(payload));
8943
+ const { data } = await axios__default["default"]({
8944
+ method: 'POST',
8945
+ url: `${this.credentials.url}/v1/payments`,
8946
+ headers: {
8947
+ 'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
8948
+ Authorization: `Bearer ${this.credentials.api_key}`,
8949
+ 'Content-Type': 'application/json',
8950
+ },
8951
+ data: payload,
8952
+ });
8953
+ console.warn('[MERCADO PAGO RESPONSE BOLETO DATA]', JSON.stringify(data));
8954
+ const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
8955
+ return payment;
8956
+ }
8957
+ catch (error) {
8958
+ if (error instanceof axios.AxiosError) {
8959
+ console.warn(error.response);
8960
+ console.warn(error.response.data);
8961
+ console.warn(error.response.data.cause);
8962
+ }
8963
+ }
8964
+ }
8965
+ getBoletoTransaction(paymentId) {
8966
+ throw new Error('Method not implemented.');
8967
+ }
8968
+ }
8969
+
8970
+ class MercadoPagoCardAxiosAdapter {
8971
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
8972
+ this.credentials = credentials;
8973
+ this.paymentRepository = paymentRepository;
8974
+ this.orderBlockedRepository = orderBlockedRepository;
8975
+ }
8976
+ async pay(checkout, card) {
8977
+ const payload = MercadoPagoRequestHelper.build({
8978
+ checkout,
8979
+ method: 'credit_card',
8980
+ postback: this.credentials.postback,
8981
+ card,
8982
+ });
8983
+ console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
8984
+ const { data } = await axios__default["default"]({
8985
+ method: 'POST',
8986
+ url: `${this.credentials.url}/v1/payments`,
8987
+ headers: {
8988
+ 'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
8989
+ Authorization: `Bearer ${this.credentials.api_key}`,
8990
+ 'Content-Type': 'application/json',
8991
+ },
8992
+ data: payload,
8993
+ });
8994
+ console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
8995
+ if ((data.status !== 'approved' && data.status_detail !== 'accredited') || data.status !== 'authorized') {
8996
+ await this.orderBlockedRepository.createBlockedOrderOrPayment({
8997
+ checkout,
8998
+ blockType: 'Card not authorized',
8999
+ type: 'Card',
9000
+ limiteRange: 'day',
9001
+ card,
9002
+ });
9003
+ throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
9004
+ checkoutId: checkout.id,
9005
+ userEmail: checkout.user.email,
9006
+ info: data,
9007
+ });
9008
+ }
9009
+ const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9010
+ return payment;
9011
+ }
9012
+ async addCard(card, customer) {
9013
+ const { data } = await axios__default["default"]({
9014
+ method: 'POST',
9015
+ url: `${this.credentials.url}/v1/payments`,
9016
+ headers: {
9017
+ Authorization: `Bearer ${this.credentials.api_key}`,
9018
+ 'Content-Type': 'application/json',
9019
+ },
9020
+ data: {
9021
+ email: customer.email,
9022
+ first_name: customer.firstName,
9023
+ last_name: customer.lastName,
9024
+ phone: {
9025
+ area_code: '55',
9026
+ number: '991234567',
9027
+ },
9028
+ identification: {
9029
+ type: 'CPF',
9030
+ number: '12345678900',
9031
+ },
9032
+ default_address: 'Home',
9033
+ address: {
9034
+ id: '123123',
9035
+ zip_code: '01234567',
9036
+ street_name: 'Rua Exemplo',
9037
+ street_number: 123,
9038
+ city: {},
9039
+ },
9040
+ },
9041
+ });
9042
+ return data;
9043
+ }
9044
+ getCardByToken(customerId, token) {
9045
+ return;
9046
+ }
9047
+ createCardHash(bu, shop, card) {
9048
+ return;
9049
+ }
9050
+ createTransaction(info) {
9051
+ return;
9052
+ }
9053
+ async createOrUpdateCustomer(customer) {
9054
+ const { data } = await axios__default["default"]({
9055
+ method: 'POST',
9056
+ url: `${this.credentials.url}/v1/customers`,
9057
+ headers: {
9058
+ Authorization: `Bearer ${this.credentials.api_key}`,
9059
+ 'Content-Type': 'application/json',
9060
+ },
9061
+ data: {
9062
+ email: customer.email,
9063
+ first_name: customer.firstName,
9064
+ last_name: customer.lastName,
9065
+ phone: {
9066
+ area_code: customer.phone.substring(0, 2),
9067
+ number: customer.phone.substring(2),
9068
+ },
9069
+ identification: {
9070
+ type: 'CPF',
9071
+ number: customer.cpf.replace(/\D/g, ''),
9072
+ },
9073
+ },
9074
+ });
9075
+ return data;
9076
+ }
9077
+ }
9078
+
9079
+ class MercadoPagoPixAxiosAdapter {
9080
+ constructor(credentials, paymentRepository) {
9081
+ this.credentials = credentials;
9082
+ this.paymentRepository = paymentRepository;
9083
+ }
9084
+ async pay(checkout) {
9085
+ try {
9086
+ const payload = MercadoPagoRequestHelper.build({
9087
+ checkout,
9088
+ method: 'pix',
9089
+ postback: this.credentials.postback,
9090
+ });
9091
+ console.warn('[MERCADO PAGO PIX DATA TO SEND]', JSON.stringify(payload));
9092
+ const { data } = await axios__default["default"]({
9093
+ method: 'POST',
9094
+ url: `${this.credentials.url}/v1/payments`,
9095
+ headers: {
9096
+ 'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
9097
+ Authorization: `Bearer ${this.credentials.api_key}`,
9098
+ 'Content-Type': 'application/json',
9099
+ },
9100
+ data: payload,
9101
+ });
9102
+ console.warn('[MERCADO PAGO RESPONSE PIX DATA]', JSON.stringify(data));
9103
+ const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9104
+ return payment;
9105
+ }
9106
+ catch (error) {
9107
+ if (error instanceof axios.AxiosError) {
9108
+ console.warn(error.response);
9109
+ console.warn(error.response.data);
9110
+ console.warn(error.response.data.cause);
9111
+ }
9112
+ }
9113
+ }
9114
+ }
9115
+
9106
9116
  class PagarmeBankSlipAxiosAdapter {
9107
9117
  constructor(credentials, paymentRepository) {
9108
9118
  this.credentials = credentials;
@@ -9250,15 +9260,17 @@ class PagarMeV5RequestHelper {
9250
9260
  customer: this.buildCustomer(checkout),
9251
9261
  shipping: this.buildShipping(checkout),
9252
9262
  payments: this.buildPayment(checkout, method, card),
9263
+ ...this.buildAdditionalInfo(checkout),
9253
9264
  };
9254
9265
  }
9255
9266
  static buildItems(checkout) {
9267
+ const isSubscriber = checkout.user?.isSubscriber ?? false;
9256
9268
  return checkout.lineItems
9257
9269
  .filter((item) => !item.isGift)
9258
9270
  .map((item) => {
9259
9271
  return {
9260
9272
  amount: Math.floor(item.pricePaid * 100),
9261
- description: item.name,
9273
+ description: isSubscriber ? `${item.name} - ASSINANTE` : item.name,
9262
9274
  quantity: item.quantity,
9263
9275
  code: item.EAN,
9264
9276
  };
@@ -9355,6 +9367,14 @@ class PagarMeV5RequestHelper {
9355
9367
  },
9356
9368
  };
9357
9369
  }
9370
+ static buildAdditionalInfo(checkout) {
9371
+ const isSubscriber = checkout.user?.isSubscriber ?? false;
9372
+ if (isSubscriber)
9373
+ return {
9374
+ antifraude_enabled: false,
9375
+ };
9376
+ return {};
9377
+ }
9358
9378
  }
9359
9379
 
9360
9380
  class PagarMeV5ResponseHelper {
@@ -10139,14 +10159,6 @@ Object.defineProperty(exports, 'formatInTimeZone', {
10139
10159
  enumerable: true,
10140
10160
  get: function () { return dateFnsTz.formatInTimeZone; }
10141
10161
  });
10142
- Object.defineProperty(exports, 'fromZonedTime', {
10143
- enumerable: true,
10144
- get: function () { return dateFnsTz.fromZonedTime; }
10145
- });
10146
- Object.defineProperty(exports, 'toZonedTime', {
10147
- enumerable: true,
10148
- get: function () { return dateFnsTz.toZonedTime; }
10149
- });
10150
10162
  Object.defineProperty(exports, 'chunk', {
10151
10163
  enumerable: true,
10152
10164
  get: function () { return lodash.chunk; }
@@ -10234,6 +10246,8 @@ exports.Base = Base;
10234
10246
  exports.BaseModel = BaseModel;
10235
10247
  exports.BeautyProfile = BeautyProfile;
10236
10248
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
10249
+ exports.BrandCategory = BrandCategory;
10250
+ exports.BrandCategoryFirestoreRepository = BrandCategoryFirestoreRepository;
10237
10251
  exports.BusinessError = BusinessError;
10238
10252
  exports.Buy2Win = Buy2Win;
10239
10253
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
@@ -10292,6 +10306,12 @@ exports.Log = Log;
10292
10306
  exports.LogDocument = LogDocument;
10293
10307
  exports.LogFirestoreRepository = LogFirestoreRepository;
10294
10308
  exports.Logger = Logger;
10309
+ exports.MercadoPagoBankSlipAxiosAdapter = MercadoPagoBankSlipAxiosAdapter;
10310
+ exports.MercadoPagoCardAxiosAdapter = MercadoPagoCardAxiosAdapter;
10311
+ exports.MercadoPagoPaymentMethodFactory = MercadoPagoPaymentMethodFactory;
10312
+ exports.MercadoPagoPixAxiosAdapter = MercadoPagoPixAxiosAdapter;
10313
+ exports.MercadoPagoRequestHelper = MercadoPagoRequestHelper;
10314
+ exports.MercadoPagoResponseHelper = MercadoPagoResponseHelper;
10295
10315
  exports.NotFoundError = NotFoundError;
10296
10316
  exports.ObsEmitter = ObsEmitter;
10297
10317
  exports.Order = Order;
@@ -10311,7 +10331,6 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
10311
10331
  exports.PaymentProviderFactory = PaymentProviderFactory;
10312
10332
  exports.PaymentTransaction = PaymentTransaction;
10313
10333
  exports.Product = Product;
10314
- exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
10315
10334
  exports.ProductErrors = ProductErrors;
10316
10335
  exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
10317
10336
  exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;