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

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 (43) hide show
  1. package/index.cjs.js +530 -582
  2. package/index.esm.js +531 -580
  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/mercado-pago-payment-method.factory.d.ts +9 -0
  12. package/src/domain/shopping/factories/payment-provider.factory.d.ts +2 -0
  13. package/src/domain/shopping/models/order.d.ts +7 -0
  14. package/src/domain/shopping/models/payment-transaction.d.ts +2 -0
  15. package/src/domain/shopping/models/payment.d.ts +1 -0
  16. package/src/domain/shopping/services/antifraud-card.service.d.ts +2 -0
  17. package/src/domain/shopping/types/checkout-paylod-request.type.d.ts +2 -7
  18. package/src/domain/shopping/types/index.d.ts +2 -0
  19. package/src/domain/shopping/types/mercado-pago-card.type.d.ts +3 -0
  20. package/src/domain/shopping/types/mercado-pago-credentials.type.d.ts +5 -0
  21. package/src/domain/shopping/types/payment-card-info.type.d.ts +2 -0
  22. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  23. package/src/infra/firebase/firestore/repositories/catalog/category-brand-firestore.repository.d.ts +7 -0
  24. package/src/infra/firebase/firestore/repositories/catalog/index.d.ts +1 -0
  25. package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +0 -1
  26. package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +0 -1
  27. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +0 -1
  28. package/src/infra/index.d.ts +1 -0
  29. package/src/infra/mercado-pago/adapters/index.d.ts +2 -0
  30. package/src/infra/mercado-pago/adapters/mercado-pago-card-payment-axios.adapter.d.ts +19 -0
  31. package/src/infra/mercado-pago/adapters/mercado-pago-pix-payment-axios.adapter.d.ts +7 -0
  32. package/src/infra/mercado-pago/helpers/index.d.ts +2 -0
  33. package/src/infra/mercado-pago/helpers/mercado-pago-request.helper.d.ts +58 -0
  34. package/src/infra/mercado-pago/helpers/mercado-pago-response.helper.d.ts +8 -0
  35. package/src/infra/mercado-pago/index.d.ts +3 -0
  36. package/src/infra/mercado-pago/types/index.d.ts +2 -0
  37. package/src/infra/mercado-pago/types/mercado-pago-request.type.d.ts +1 -0
  38. package/src/infra/mercado-pago/types/mercado-pago-response.type.d.ts +180 -0
  39. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +1 -0
  40. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +1 -0
  41. package/src/utils/index.d.ts +2 -2
  42. package/src/domain/catalog/repositories/product-catalog.repository.d.ts +0 -13
  43. 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;
@@ -757,6 +758,30 @@ tslib.__decorate([
757
758
  ], Category.prototype, "filters", void 0);
758
759
  registerClass('Category', Category);
759
760
 
761
+ class BrandCategory extends BaseModel {
762
+ get glamImages() {
763
+ return this.images?.[exports.Shops.GLAMSHOP]
764
+ ? this.images[exports.Shops.GLAMSHOP]
765
+ : {
766
+ brandBanner: null,
767
+ brandBannerMobile: null,
768
+ image: null,
769
+ };
770
+ }
771
+ get mensImages() {
772
+ return this.images?.[exports.Shops.MENSMARKET]
773
+ ? this.images[exports.Shops.MENSMARKET]
774
+ : {
775
+ brandBanner: null,
776
+ brandBannerMobile: null,
777
+ image: null,
778
+ };
779
+ }
780
+ static get identifiersFields() {
781
+ return ['id'];
782
+ }
783
+ }
784
+
760
785
  class CategoryCollectionChildren extends BaseModel {
761
786
  static get identifiersFields() {
762
787
  return ['collectionId', 'categoryId'];
@@ -871,12 +896,7 @@ class Variant extends ProductBase {
871
896
  static get identifiersFields() {
872
897
  return ['id', 'productId'];
873
898
  }
874
- }
875
- tslib.__decorate([
876
- classTransformer.Type(() => Product),
877
- tslib.__metadata("design:type", Product)
878
- ], Variant.prototype, "product", void 0);
879
- registerClass('Product', Product);
899
+ }
880
900
 
881
901
  class Product extends ProductBase {
882
902
  }
@@ -1765,19 +1785,58 @@ class AntifraudCardService {
1765
1785
  constructor(orderRepository, orderBlockedRepository) {
1766
1786
  this.orderRepository = orderRepository;
1767
1787
  this.orderBlockedRepository = orderBlockedRepository;
1768
- this.LIMIT_ORDERS_DAY = 2;
1769
- this.LIMIT_ORDERS_WEEK = 7;
1770
- this.LIMIT_BLOCKED_ORDERS_DAY = 5;
1788
+ this.LIMIT_ORDERS_DAY = null;
1789
+ this.LIMIT_ORDERS_WEEK = null;
1771
1790
  }
1772
1791
  async validate(checkout, card) {
1792
+ this.setLimitsByUserType(checkout.user.isSubscriber);
1773
1793
  await this.validateBlockedOrderAttempts(checkout, card);
1774
1794
  await this.validateDayAndWeekOrderLimits(checkout, card);
1775
1795
  return true;
1776
1796
  }
1797
+ setLimitsByUserType(isSubscriber) {
1798
+ this.LIMIT_ORDERS_DAY = {
1799
+ subscriber: {
1800
+ cpf: 4,
1801
+ email: 4,
1802
+ phone: 4,
1803
+ card: 4,
1804
+ zip: 4,
1805
+ },
1806
+ nonSubscriber: {
1807
+ cpf: 2,
1808
+ email: 2,
1809
+ phone: 2,
1810
+ card: 2,
1811
+ zip: 2,
1812
+ },
1813
+ };
1814
+ this.LIMIT_ORDERS_WEEK = {
1815
+ subscriber: {
1816
+ cpf: 12,
1817
+ email: 12,
1818
+ phone: 12,
1819
+ card: 12,
1820
+ zip: Infinity,
1821
+ },
1822
+ nonSubscriber: {
1823
+ cpf: 7,
1824
+ email: 7,
1825
+ phone: 7,
1826
+ card: 7,
1827
+ zip: Infinity,
1828
+ },
1829
+ };
1830
+ this.LIMIT_BLOCKED_ORDERS_DAY = isSubscriber ? 7 : 5;
1831
+ }
1832
+ getLimitsByUserType(type, isSubscriber) {
1833
+ const limits = type === 'day' ? this.LIMIT_ORDERS_DAY : this.LIMIT_ORDERS_WEEK;
1834
+ return isSubscriber ? limits['subscriber'] : limits['nonSubscriber'];
1835
+ }
1777
1836
  async validateBlockedOrderAttempts(checkout, card) {
1778
1837
  const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
1779
1838
  if (!isValid) {
1780
- throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
1839
+ throw new FraudValidationError(`Cliente com mais de ${this.LIMIT_BLOCKED_ORDERS_DAY} compras negadas/bloqueadas no dia`, {
1781
1840
  checkoutId: checkout.id,
1782
1841
  userEmail: checkout.user.email,
1783
1842
  info: {
@@ -1791,7 +1850,7 @@ class AntifraudCardService {
1791
1850
  async validateDayAndWeekOrderLimits(checkout, card) {
1792
1851
  const isValid = await this.verifyDayAndWeekOrders(checkout, card);
1793
1852
  if (!isValid) {
1794
- throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
1853
+ throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', {
1795
1854
  checkoutId: checkout.id,
1796
1855
  userEmail: checkout.user.email,
1797
1856
  info: {
@@ -1810,7 +1869,7 @@ class AntifraudCardService {
1810
1869
  await this.createBlockedOrderRecord({
1811
1870
  checkout,
1812
1871
  card,
1813
- reason: 'More than 5 attempts have failed',
1872
+ reason: `More than ${this.LIMIT_BLOCKED_ORDERS_DAY} attempts have failed`,
1814
1873
  key: 'Failed attempts',
1815
1874
  period: 'day',
1816
1875
  });
@@ -1820,7 +1879,7 @@ class AntifraudCardService {
1820
1879
  }
1821
1880
  getTodayDateRange() {
1822
1881
  const timeZone = 'America/Sao_Paulo';
1823
- const today = dateFnsTz.toZonedTime(new Date(), timeZone);
1882
+ const today = dateFnsTz.utcToZonedTime(new Date(), timeZone);
1824
1883
  const day = dateFns.startOfDay(today);
1825
1884
  const endOfDay = dateFns.endOfDay(today);
1826
1885
  return { day: dateFns.addHours(day, 3), endOfDay: dateFns.addHours(endOfDay, 3) };
@@ -1931,26 +1990,28 @@ class AntifraudCardService {
1931
1990
  }
1932
1991
  async validateDayOrderLimits(checkout, params) {
1933
1992
  const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
1993
+ const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
1934
1994
  return this.checkOrderLimitsAndBlock({
1935
1995
  checkout,
1936
1996
  orderCounts: ordersPerDay,
1937
- limit: this.LIMIT_ORDERS_DAY,
1997
+ limit: limits,
1938
1998
  period: 'day',
1939
1999
  });
1940
2000
  }
1941
2001
  async validateWeekOrderLimits(checkout, params) {
1942
2002
  const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
2003
+ const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
1943
2004
  return this.checkOrderLimitsAndBlock({
1944
2005
  checkout,
1945
2006
  orderCounts: ordersPerWeek,
1946
- limit: this.LIMIT_ORDERS_WEEK,
2007
+ limit: limits,
1947
2008
  period: 'week',
1948
2009
  });
1949
2010
  }
1950
2011
  async checkOrderLimitsAndBlock(params) {
1951
2012
  const { checkout, orderCounts, limit, period } = params;
1952
2013
  for (const key in orderCounts) {
1953
- if (orderCounts[key] >= limit) {
2014
+ if (orderCounts[key] >= limit[key]) {
1954
2015
  await this.createBlockedOrderRecord({
1955
2016
  checkout,
1956
2017
  card: null,
@@ -3397,8 +3458,6 @@ class HasuraQueryBuilderHelper {
3397
3458
  class HasuraRequestHelper {
3398
3459
  static async fetch(params) {
3399
3460
  const { variables, query, endpoint, headers, logger } = params;
3400
- console.warn('variables', variables);
3401
- console.warn('query', query);
3402
3461
  const request = {
3403
3462
  url: endpoint,
3404
3463
  method: 'POST',
@@ -4770,6 +4829,17 @@ const withCrudFirestore = (MixinBase) => {
4770
4829
  };
4771
4830
  };
4772
4831
 
4832
+ class BrandCategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4833
+ constructor({ firestore, interceptors, }) {
4834
+ super({
4835
+ firestore,
4836
+ collectionName: 'brandsCategory',
4837
+ model: BrandCategory,
4838
+ interceptors,
4839
+ });
4840
+ }
4841
+ }
4842
+
4773
4843
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4774
4844
  constructor({ firestore, interceptors }) {
4775
4845
  super({
@@ -7223,7 +7293,83 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
7223
7293
  }
7224
7294
  }
7225
7295
 
7226
- const commonFields$1 = [
7296
+ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7297
+ constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7298
+ super({
7299
+ tableName: 'product_errors',
7300
+ model: ProductErrorsHasuraGraphQL,
7301
+ endpoint,
7302
+ authOptions,
7303
+ interceptors,
7304
+ cache,
7305
+ fields: [
7306
+ {
7307
+ productId: {
7308
+ columnName: 'product_id',
7309
+ to: (value) => +value,
7310
+ from: (value) => value.toString(),
7311
+ },
7312
+ },
7313
+ 'source',
7314
+ 'error',
7315
+ { createdAt: { columnName: 'created_at' } },
7316
+ { updatedAt: { columnName: 'updated_at' } },
7317
+ {
7318
+ product: {
7319
+ columnName: 'product',
7320
+ foreignKeyColumn: { id: 'productId' },
7321
+ fields: [
7322
+ { id: { columnName: 'id', from: (value) => value.toString() } },
7323
+ { productId: { columnName: 'main_product_id' } },
7324
+ 'name',
7325
+ 'published',
7326
+ 'group',
7327
+ 'validity',
7328
+ { createdAt: { columnName: 'created_at' } },
7329
+ { updatedAt: { columnName: 'updated_at' } },
7330
+ ],
7331
+ },
7332
+ },
7333
+ ],
7334
+ });
7335
+ this.productRepository = productRepository;
7336
+ }
7337
+ async get(params) {
7338
+ const result = await super.get(params);
7339
+ if (result instanceof VariantHasuraGraphQL) {
7340
+ const product = await this.productRepository.get({ id: result.productId.toString() });
7341
+ result.product.name = product.name;
7342
+ result.product.group = product.group;
7343
+ }
7344
+ return result;
7345
+ }
7346
+ async find(params) {
7347
+ const result = await super.find(params);
7348
+ const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
7349
+ (lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
7350
+ if (variantsWithNoData.length > 0) {
7351
+ const { data: products } = await this.productRepository.find({
7352
+ filters: {
7353
+ id: {
7354
+ operator: exports.Where.IN,
7355
+ value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
7356
+ },
7357
+ },
7358
+ });
7359
+ products.forEach((product) => {
7360
+ result.data
7361
+ .filter((variant) => variant.product.productId?.toString() === product.id.toString())
7362
+ .forEach((variant) => {
7363
+ variant.product.name = product.name;
7364
+ variant.product.group = product.group;
7365
+ });
7366
+ });
7367
+ }
7368
+ return result;
7369
+ }
7370
+ }
7371
+
7372
+ const commonFields = [
7227
7373
  {
7228
7374
  id: {
7229
7375
  columnName: 'id',
@@ -7378,383 +7524,61 @@ const commonFields$1 = [
7378
7524
  { reviewsTotal: { columnName: 'reviews_total' } },
7379
7525
  { shoppingCount: { columnName: 'shopping_count' } },
7380
7526
  { categoryId: { columnName: 'category_id' } },
7527
+ {
7528
+ category: {
7529
+ columnName: 'category',
7530
+ foreignKeyColumn: { id: 'categoryId' },
7531
+ fields: ['id', 'name', 'reference', 'slug'],
7532
+ },
7533
+ },
7381
7534
  'group',
7382
7535
  'validity',
7383
7536
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7384
7537
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7385
7538
  { daysOfUse: { columnName: 'days_of_use' } },
7386
- { showVariants: { columnName: 'show_variants' } },
7387
7539
  ];
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 },
7540
+ const fieldsConfiguration$2 = [
7541
+ ...commonFields,
7542
+ {
7543
+ categories: {
7544
+ columnName: 'categories',
7545
+ fields: ['category_id'],
7546
+ bindPersistData: (value) => ({
7547
+ categories: { data: value.map((category) => ({ category_id: +category })) },
7548
+ }),
7549
+ to: (categories) => categories.map((categoryId) => +categoryId),
7550
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
7551
+ },
7552
+ },
7553
+ {
7554
+ kitProducts: {
7555
+ columnName: 'kit_products',
7556
+ foreignKeyColumn: { productId: 'id' },
7439
7557
  fields: [
7440
- ...bindFields,
7441
- ...(bindFields.includes('price')
7442
- ? [
7443
- 'subscriberPrice',
7444
- 'subscriberDiscountPercentage',
7445
- 'fullPrice',
7446
- ]
7447
- : []),
7558
+ { productId: { columnName: 'product_id' } },
7559
+ { kitProductId: { columnName: 'kit_product_id' } },
7560
+ 'quantity',
7561
+ { product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
7448
7562
  ],
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,
7563
+ },
7564
+ },
7565
+ {
7566
+ reviews: {
7567
+ columnName: 'reviews',
7568
+ foreignKeyColumn: { product_id: 'id' },
7480
7569
  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' },
7745
- fields: [
7746
- 'id',
7747
- 'shop',
7748
- 'rate',
7749
- 'author',
7750
- 'email',
7751
- 'location',
7752
- 'review',
7753
- 'status',
7754
- 'title',
7755
- { personId: { columnName: 'person_id' } },
7756
- 'points',
7757
- { orderId: { columnName: 'order_id' } },
7570
+ 'id',
7571
+ 'shop',
7572
+ 'rate',
7573
+ 'author',
7574
+ 'email',
7575
+ 'location',
7576
+ 'review',
7577
+ 'status',
7578
+ 'title',
7579
+ { personId: { columnName: 'person_id' } },
7580
+ 'points',
7581
+ { orderId: { columnName: 'order_id' } },
7758
7582
  { createdAt: { columnName: 'created_at' } },
7759
7583
  { updatedAt: { columnName: 'updated_at' } },
7760
7584
  ],
@@ -7771,65 +7595,13 @@ const fieldsConfiguration$2 = [
7771
7595
  },
7772
7596
  {
7773
7597
  variants: {
7774
- columnName: 'variants',
7775
- foreignKeyColumn: { product_id: 'id' },
7776
- fields: [
7777
- 'id',
7778
- 'name',
7779
- 'ean',
7780
- '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' } },
7598
+ columnName: 'variants',
7599
+ foreignKeyColumn: { product_id: 'id' },
7600
+ fields: [
7601
+ 'id',
7602
+ 'ean',
7603
+ 'sku',
7604
+ 'description',
7833
7605
  {
7834
7606
  grade: {
7835
7607
  columnName: 'grade',
@@ -7875,6 +7647,10 @@ const fieldsConfiguration$2 = [
7875
7647
  }),
7876
7648
  },
7877
7649
  },
7650
+ { fullPrice: { columnName: 'full_price' } },
7651
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7652
+ { subscriberPrice: { columnName: 'subscriber_price' } },
7653
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7878
7654
  'published',
7879
7655
  {
7880
7656
  stock: {
@@ -7966,10 +7742,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7966
7742
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7967
7743
  .data?.[0]
7968
7744
  : 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));
7745
+ if (product.productId)
7746
+ throw new NotFoundError('Product not found, it is a variant');
7747
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
7973
7748
  return product;
7974
7749
  }
7975
7750
  async find(params, optionsParams) {
@@ -7986,9 +7761,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7986
7761
  options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7987
7762
  return super.find({
7988
7763
  ...options,
7989
- filters: { ...filters },
7990
- // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7991
- // filters: { ...filters, productId: { operator: Where.ISNULL } },
7764
+ filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
7992
7765
  fields: [
7993
7766
  ...bindFields,
7994
7767
  ...(bindFields.includes('price')
@@ -8022,13 +7795,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8022
7795
  if (!result.data.length)
8023
7796
  return null;
8024
7797
  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
7798
  RoundProductPricesHelper.roundProductPrices(product);
8033
7799
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
8034
7800
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
@@ -8041,18 +7807,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8041
7807
  }
8042
7808
  return product;
8043
7809
  }
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
7810
  async getByEAN(EAN, options) {
8057
7811
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8058
7812
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -8242,7 +7996,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8242
7996
  return data?.[0]?.id;
8243
7997
  throw new NotFoundError(`Product with id ${id} not found`);
8244
7998
  }
8245
- async findReviewsByProduct(productId, onlyApproved, options) {
7999
+ async findReviewsByProduct(productId, options) {
8246
8000
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8247
8001
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
8248
8002
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
@@ -8255,7 +8009,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8255
8009
  where: {
8256
8010
  value: {
8257
8011
  product_id: { _eq: productId },
8258
- ...(onlyApproved && { status: { _eq: true } }),
8259
8012
  },
8260
8013
  type: 'product_review_bool_exp',
8261
8014
  required: true,
@@ -8364,7 +8117,7 @@ tslib.__decorate([
8364
8117
  tslib.__decorate([
8365
8118
  Log(),
8366
8119
  tslib.__metadata("design:type", Function),
8367
- tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
8120
+ tslib.__metadata("design:paramtypes", [Number, Object]),
8368
8121
  tslib.__metadata("design:returntype", Promise)
8369
8122
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
8370
8123
 
@@ -8612,83 +8365,6 @@ const fieldsConfiguration$1 = [
8612
8365
  to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8613
8366
  },
8614
8367
  },
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 },
8687
- }),
8688
- },
8689
- },
8690
- { createdAt: { columnName: 'created_at' } },
8691
- { updatedAt: { columnName: 'updated_at' } },
8692
8368
  ];
8693
8369
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8694
8370
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8729,37 +8405,18 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8729
8405
  return data.at(0);
8730
8406
  }
8731
8407
  async update(params) {
8732
- const { productId, id: checkId, metadata, ...data } = params;
8408
+ const { productId, id: checkId, ...data } = params;
8733
8409
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
8734
8410
  if (!dataWithProductId.id) {
8735
8411
  throw new NotFoundError('Variant ID is required for update');
8736
8412
  }
8737
8413
  const id = await this.getId(dataWithProductId.id);
8738
8414
  const product = await super.update({ id, ...data });
8739
- product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
8740
8415
  if (dataWithProductId.productId) {
8741
8416
  product.productId = dataWithProductId.productId;
8742
8417
  }
8743
8418
  return product;
8744
8419
  }
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
8420
  async getId(id) {
8764
8421
  if (!Number.isNaN(+id))
8765
8422
  return id;
@@ -9103,6 +8760,290 @@ tslib.__decorate([
9103
8760
  tslib.__metadata("design:returntype", Promise)
9104
8761
  ], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
9105
8762
 
8763
+ class MercadoPagoRequestHelper {
8764
+ static build(data) {
8765
+ const { checkout, method, postback, card } = data;
8766
+ return {
8767
+ transaction_amount: +checkout.totalPrice.toFixed(2),
8768
+ notification_url: postback,
8769
+ metadata: {
8770
+ checkoutId: checkout.id,
8771
+ },
8772
+ payer: this.buildPayer(checkout),
8773
+ statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
8774
+ additional_info: {
8775
+ items: this.buildItems(checkout),
8776
+ payer: this.buildFullPayer(checkout),
8777
+ },
8778
+ ...(method === 'credit_card' && this.buildCardPayment(card)),
8779
+ ...(method === 'pix' && this.buildPixPayment()),
8780
+ };
8781
+ }
8782
+ static buildItems(checkout) {
8783
+ return checkout.lineItems
8784
+ .filter((item) => !item.isGift)
8785
+ .map((item) => {
8786
+ return {
8787
+ id: item.EAN,
8788
+ title: item.name,
8789
+ description: item.name,
8790
+ picture_url: item.image ?? null,
8791
+ category_id: item.category?.id ?? null,
8792
+ quantity: item.quantity,
8793
+ unit_price: +item.pricePaid.toFixed(2),
8794
+ };
8795
+ });
8796
+ }
8797
+ static buildPayer(checkout) {
8798
+ return {
8799
+ first_name: checkout.user.firstName,
8800
+ last_name: checkout.user.lastName,
8801
+ email: checkout.user.email,
8802
+ identification: {
8803
+ type: 'CPF',
8804
+ number: checkout.user.cpf.replace(/\D/g, ''),
8805
+ },
8806
+ };
8807
+ }
8808
+ static buildFullPayer(checkout) {
8809
+ return {
8810
+ first_name: checkout.user.firstName,
8811
+ last_name: checkout.user.lastName,
8812
+ phone: {
8813
+ area_code: checkout.user.phone.substring(0, 2),
8814
+ number: checkout.user.phone.substring(2),
8815
+ },
8816
+ address: {
8817
+ zip_code: checkout.shippingAddress.zip,
8818
+ street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8819
+ street_number: checkout.shippingAddress.number,
8820
+ },
8821
+ };
8822
+ }
8823
+ static buildCardPayment(card) {
8824
+ return {
8825
+ installments: card.installments,
8826
+ token: card.cardId,
8827
+ };
8828
+ }
8829
+ static buildPixPayment() {
8830
+ return {
8831
+ payment_method_id: 'pix',
8832
+ date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
8833
+ };
8834
+ }
8835
+ }
8836
+
8837
+ class MercadoPagoResponseHelper {
8838
+ static build(method, checkout, response) {
8839
+ return Payment.toInstance({
8840
+ createdAt: new Date(),
8841
+ updatedAt: new Date(),
8842
+ userId: checkout.user.id,
8843
+ checkoutId: checkout.id,
8844
+ totalPrice: checkout.totalPrice,
8845
+ paymentProvider: exports.PaymentProviders.MERCADOPAGO,
8846
+ mercadoPagoId: response.id,
8847
+ transaction: this.buildPaymentTransaction(method, response),
8848
+ });
8849
+ }
8850
+ static buildPaymentTransaction(method, response) {
8851
+ return PaymentTransaction.toInstance({
8852
+ id: response.id.toString(),
8853
+ acquirer_name: exports.PaymentProviders.MERCADOPAGO,
8854
+ amount: response.transaction_amount,
8855
+ status: response.status,
8856
+ status_reason: response.status_detail?.toString(),
8857
+ payment_method: method,
8858
+ currency: response.currency_id?.toString(),
8859
+ paid_amount: response.transaction_details?.total_paid_amount ?? null,
8860
+ paid_at: response.date_approved ?? null,
8861
+ charger_id: response.charges_details?.at(0)?.id?.toString() ?? null,
8862
+ ...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(response)),
8863
+ ...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(response)),
8864
+ });
8865
+ }
8866
+ // private static getBoletoReponse(transaction: MercadoPagoResponse): Partial<PaymentTransaction> {
8867
+ // return {
8868
+ // boleto_url: transaction.url?.toString(),
8869
+ // boleto_barcode: transaction.line?.toString(),
8870
+ // boleto_qr_code: transaction.qr_code?.toString(),
8871
+ // boleto_expiration_date: transaction.due_at?.toString(),
8872
+ // boleto_instructions: transaction.instructions?.toString(),
8873
+ // boleto_nosso_numero: transaction.nosso_numero?.toString(),
8874
+ // boleto_type: transaction.type?.toString(),
8875
+ // boleto_document_number: transaction.document_number?.toString(),
8876
+ // }
8877
+ // }
8878
+ static getPixReponse(response) {
8879
+ return {
8880
+ pix_qr_code: response.point_of_interaction?.transaction_data?.qr_code,
8881
+ pix_expiration_date: response.date_of_expiration?.toString(),
8882
+ };
8883
+ }
8884
+ static getCardReponse(response) {
8885
+ return {
8886
+ soft_descriptor: response.statement_descriptor?.toString(),
8887
+ installments: response.installments,
8888
+ card_brand: response.payment_method_id?.toString(),
8889
+ card_first_digits: response.card?.first_six_digits?.toString(),
8890
+ card_last_digits: response.card?.last_four_digits?.toString(),
8891
+ card_id: response.card?.id?.toString(),
8892
+ card_holder_name: response.card?.cardholder?.name?.toString(),
8893
+ card_expiration_month: response.card?.expiration_month?.toString(),
8894
+ card_expiration_year: response.card?.expiration_year?.toString(),
8895
+ capture_method: response.payment_type_id?.toString(),
8896
+ authorization_code: response.authorization_code?.toString(),
8897
+ };
8898
+ }
8899
+ }
8900
+
8901
+ class MercadoPagoCardAxiosAdapter {
8902
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
8903
+ this.credentials = credentials;
8904
+ this.paymentRepository = paymentRepository;
8905
+ this.orderBlockedRepository = orderBlockedRepository;
8906
+ }
8907
+ async pay(checkout, card) {
8908
+ const payload = MercadoPagoRequestHelper.build({
8909
+ checkout,
8910
+ method: 'credit_card',
8911
+ postback: this.credentials.postback,
8912
+ card,
8913
+ });
8914
+ console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
8915
+ const { data } = await axios__default["default"]({
8916
+ method: 'POST',
8917
+ url: `${this.credentials.url}/v1/payments`,
8918
+ headers: {
8919
+ 'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
8920
+ Authorization: `Bearer ${this.credentials.api_key}`,
8921
+ 'Content-Type': 'application/json',
8922
+ },
8923
+ data: payload,
8924
+ });
8925
+ console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
8926
+ if ((data.status !== 'approved' && data.status_detail !== 'accredited') || data.status !== 'authorized') {
8927
+ await this.orderBlockedRepository.createBlockedOrderOrPayment({
8928
+ checkout,
8929
+ blockType: 'Card not authorized',
8930
+ type: 'Card',
8931
+ limiteRange: 'day',
8932
+ card,
8933
+ });
8934
+ 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', {
8935
+ checkoutId: checkout.id,
8936
+ userEmail: checkout.user.email,
8937
+ info: data,
8938
+ });
8939
+ }
8940
+ const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
8941
+ return payment;
8942
+ }
8943
+ async addCard(card, customer) {
8944
+ const { data } = await axios__default["default"]({
8945
+ method: 'POST',
8946
+ url: `${this.credentials.url}/v1/payments`,
8947
+ headers: {
8948
+ Authorization: `Bearer ${this.credentials.api_key}`,
8949
+ 'Content-Type': 'application/json',
8950
+ },
8951
+ data: {
8952
+ email: customer.email,
8953
+ first_name: customer.firstName,
8954
+ last_name: customer.lastName,
8955
+ phone: {
8956
+ area_code: '55',
8957
+ number: '991234567',
8958
+ },
8959
+ identification: {
8960
+ type: 'CPF',
8961
+ number: '12345678900',
8962
+ },
8963
+ default_address: 'Home',
8964
+ address: {
8965
+ id: '123123',
8966
+ zip_code: '01234567',
8967
+ street_name: 'Rua Exemplo',
8968
+ street_number: 123,
8969
+ city: {},
8970
+ },
8971
+ },
8972
+ });
8973
+ return data;
8974
+ }
8975
+ getCardByToken(customerId, token) {
8976
+ return;
8977
+ }
8978
+ createCardHash(bu, shop, card) {
8979
+ return;
8980
+ }
8981
+ createTransaction(info) {
8982
+ return;
8983
+ }
8984
+ async createOrUpdateCustomer(customer) {
8985
+ const { data } = await axios__default["default"]({
8986
+ method: 'POST',
8987
+ url: `${this.credentials.url}/v1/customers`,
8988
+ headers: {
8989
+ Authorization: `Bearer ${this.credentials.api_key}`,
8990
+ 'Content-Type': 'application/json',
8991
+ },
8992
+ data: {
8993
+ email: customer.email,
8994
+ first_name: customer.firstName,
8995
+ last_name: customer.lastName,
8996
+ phone: {
8997
+ area_code: customer.phone.substring(0, 2),
8998
+ number: customer.phone.substring(2),
8999
+ },
9000
+ identification: {
9001
+ type: 'CPF',
9002
+ number: customer.cpf.replace(/\D/g, ''),
9003
+ },
9004
+ },
9005
+ });
9006
+ return data;
9007
+ }
9008
+ }
9009
+
9010
+ class MercadoPagoPixAxiosAdapter {
9011
+ constructor(credentials, paymentRepository) {
9012
+ this.credentials = credentials;
9013
+ this.paymentRepository = paymentRepository;
9014
+ }
9015
+ async pay(checkout) {
9016
+ try {
9017
+ const payload = MercadoPagoRequestHelper.build({
9018
+ checkout,
9019
+ method: 'pix',
9020
+ postback: this.credentials.postback,
9021
+ });
9022
+ console.warn('[MERCADO PAGO PIX DATA TO SEND]', JSON.stringify(payload));
9023
+ const { data } = await axios__default["default"]({
9024
+ method: 'POST',
9025
+ url: `${this.credentials.url}/v1/payments`,
9026
+ headers: {
9027
+ 'X-Idempotency-Key': checkout.id,
9028
+ Authorization: `Bearer ${this.credentials.api_key}`,
9029
+ 'Content-Type': 'application/json',
9030
+ },
9031
+ data: payload,
9032
+ });
9033
+ console.warn('[MERCADO PAGO RESPONSE PIX DATA]', JSON.stringify(data));
9034
+ const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9035
+ return payment;
9036
+ }
9037
+ catch (error) {
9038
+ if (error instanceof axios.AxiosError) {
9039
+ console.warn(error.response);
9040
+ console.warn(error.response.data);
9041
+ console.warn(error.response.data.cause);
9042
+ }
9043
+ }
9044
+ }
9045
+ }
9046
+
9106
9047
  class PagarmeBankSlipAxiosAdapter {
9107
9048
  constructor(credentials, paymentRepository) {
9108
9049
  this.credentials = credentials;
@@ -9250,15 +9191,17 @@ class PagarMeV5RequestHelper {
9250
9191
  customer: this.buildCustomer(checkout),
9251
9192
  shipping: this.buildShipping(checkout),
9252
9193
  payments: this.buildPayment(checkout, method, card),
9194
+ ...this.buildAdditionalInfo(checkout),
9253
9195
  };
9254
9196
  }
9255
9197
  static buildItems(checkout) {
9198
+ const isSubscriber = checkout.user?.isSubscriber ?? false;
9256
9199
  return checkout.lineItems
9257
9200
  .filter((item) => !item.isGift)
9258
9201
  .map((item) => {
9259
9202
  return {
9260
9203
  amount: Math.floor(item.pricePaid * 100),
9261
- description: item.name,
9204
+ description: isSubscriber ? `${item.name} - ASSINANTE` : item.name,
9262
9205
  quantity: item.quantity,
9263
9206
  code: item.EAN,
9264
9207
  };
@@ -9355,6 +9298,14 @@ class PagarMeV5RequestHelper {
9355
9298
  },
9356
9299
  };
9357
9300
  }
9301
+ static buildAdditionalInfo(checkout) {
9302
+ const isSubscriber = checkout.user?.isSubscriber ?? false;
9303
+ if (isSubscriber)
9304
+ return {
9305
+ antifraude_enabled: false,
9306
+ };
9307
+ return {};
9308
+ }
9358
9309
  }
9359
9310
 
9360
9311
  class PagarMeV5ResponseHelper {
@@ -10139,14 +10090,6 @@ Object.defineProperty(exports, 'formatInTimeZone', {
10139
10090
  enumerable: true,
10140
10091
  get: function () { return dateFnsTz.formatInTimeZone; }
10141
10092
  });
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
10093
  Object.defineProperty(exports, 'chunk', {
10151
10094
  enumerable: true,
10152
10095
  get: function () { return lodash.chunk; }
@@ -10234,6 +10177,8 @@ exports.Base = Base;
10234
10177
  exports.BaseModel = BaseModel;
10235
10178
  exports.BeautyProfile = BeautyProfile;
10236
10179
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
10180
+ exports.BrandCategory = BrandCategory;
10181
+ exports.BrandCategoryFirestoreRepository = BrandCategoryFirestoreRepository;
10237
10182
  exports.BusinessError = BusinessError;
10238
10183
  exports.Buy2Win = Buy2Win;
10239
10184
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
@@ -10292,6 +10237,10 @@ exports.Log = Log;
10292
10237
  exports.LogDocument = LogDocument;
10293
10238
  exports.LogFirestoreRepository = LogFirestoreRepository;
10294
10239
  exports.Logger = Logger;
10240
+ exports.MercadoPagoCardAxiosAdapter = MercadoPagoCardAxiosAdapter;
10241
+ exports.MercadoPagoPixAxiosAdapter = MercadoPagoPixAxiosAdapter;
10242
+ exports.MercadoPagoRequestHelper = MercadoPagoRequestHelper;
10243
+ exports.MercadoPagoResponseHelper = MercadoPagoResponseHelper;
10295
10244
  exports.NotFoundError = NotFoundError;
10296
10245
  exports.ObsEmitter = ObsEmitter;
10297
10246
  exports.Order = Order;
@@ -10311,7 +10260,6 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
10311
10260
  exports.PaymentProviderFactory = PaymentProviderFactory;
10312
10261
  exports.PaymentTransaction = PaymentTransaction;
10313
10262
  exports.Product = Product;
10314
- exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
10315
10263
  exports.ProductErrors = ProductErrors;
10316
10264
  exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
10317
10265
  exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;