@infrab4a/connect 5.4.0-beta.16 → 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 (45) hide show
  1. package/index.cjs.js +546 -737
  2. package/index.esm.js +541 -736
  3. package/package.json +1 -1
  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-base.d.ts +0 -1
  7. package/src/domain/catalog/models/product-review.d.ts +0 -2
  8. package/src/domain/catalog/models/product.d.ts +0 -1
  9. package/src/domain/catalog/repositories/category-brand.repository.d.ts +4 -0
  10. package/src/domain/catalog/repositories/index.d.ts +1 -1
  11. package/src/domain/shopping/enums/payment-providers.enum.d.ts +2 -1
  12. package/src/domain/shopping/factories/mercado-pago-payment-method.factory.d.ts +9 -0
  13. package/src/domain/shopping/factories/payment-provider.factory.d.ts +2 -0
  14. package/src/domain/shopping/models/order.d.ts +1 -1
  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/models/index.d.ts +0 -1
  27. package/src/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +0 -7
  28. package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +0 -1
  29. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +0 -1
  30. package/src/infra/index.d.ts +1 -0
  31. package/src/infra/mercado-pago/adapters/index.d.ts +2 -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 +58 -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/domain/catalog/repositories/product-catalog.repository.d.ts +0 -17
  44. package/src/infra/hasura-graphql/models/product-catalog-hasura-graphql.d.ts +0 -16
  45. package/src/infra/hasura-graphql/repositories/catalog/product-catalog-hasura-graphql.repository.d.ts +0 -22
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'];
@@ -829,12 +854,7 @@ class ProductReview extends BaseModel {
829
854
  static get identifiersFields() {
830
855
  return ['id'];
831
856
  }
832
- }
833
- tslib.__decorate([
834
- classTransformer.Type(resolveClass('Product')),
835
- tslib.__metadata("design:type", Function)
836
- ], ProductReview.prototype, "product", void 0);
837
- registerClass('ProductReview', ProductReview);
857
+ }
838
858
 
839
859
  class ProductBase extends BaseModel {
840
860
  get evaluation() {
@@ -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
  });
@@ -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,
@@ -4768,6 +4829,17 @@ const withCrudFirestore = (MixinBase) => {
4768
4829
  };
4769
4830
  };
4770
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
+
4771
4843
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4772
4844
  constructor({ firestore, interceptors }) {
4773
4845
  super({
@@ -5856,9 +5928,6 @@ tslib.__decorate([
5856
5928
  tslib.__metadata("design:type", Product)
5857
5929
  ], KitProductHasuraGraphQL.prototype, "product", void 0);
5858
5930
 
5859
- class ProductCatalogHasuraGraphQL extends Product {
5860
- }
5861
-
5862
5931
  class ProductHasuraGraphQL extends Product {
5863
5932
  }
5864
5933
  tslib.__decorate([
@@ -7224,7 +7293,83 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
7224
7293
  }
7225
7294
  }
7226
7295
 
7227
- 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 = [
7228
7373
  {
7229
7374
  id: {
7230
7375
  columnName: 'id',
@@ -7391,401 +7536,29 @@ const commonFields$1 = [
7391
7536
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7392
7537
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7393
7538
  { daysOfUse: { columnName: 'days_of_use' } },
7394
- { showVariants: { columnName: 'show_variants' } },
7395
- { variantSlug: { columnName: 'variant_slug' } },
7396
7539
  ];
7397
- class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7398
- constructor({ endpoint, authOptions, interceptors, cache, }) {
7399
- super({
7400
- tableName: 'product_catalog',
7401
- model: ProductCatalogHasuraGraphQL,
7402
- endpoint,
7403
- authOptions,
7404
- interceptors,
7405
- fields: commonFields$1,
7406
- cache,
7407
- });
7408
- }
7409
- async get({ id }, options) {
7410
- if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7411
- const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7412
- const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7413
- if (cachedData) {
7414
- this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7415
- return this.model.toInstance(deserialize(cachedData));
7416
- }
7417
- }
7418
- const product = await super
7419
- .find({
7420
- filters: {
7421
- id,
7422
- },
7423
- limits: {
7424
- limit: 1,
7425
- },
7426
- })
7427
- .then((res) => res.data.at(0));
7428
- if (!product)
7429
- throw new NotFoundError(`Product not found`);
7430
- if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7431
- const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7432
- await this.cache.cacheAdapter.set({
7433
- key: cacheKey,
7434
- data: serialize(product),
7435
- expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7436
- });
7437
- this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7438
- }
7439
- return product;
7440
- }
7441
- async getByEAN(EAN, options) {
7442
- if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7443
- const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7444
- const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7445
- if (cachedData) {
7446
- this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7447
- return this.model.toInstance(deserialize(cachedData));
7448
- }
7449
- }
7450
- const product = await super
7451
- .find({
7452
- filters: {
7453
- EAN,
7454
- },
7455
- limits: {
7456
- limit: 1,
7457
- },
7458
- })
7459
- .then((res) => res.data.at(0));
7460
- if (!product)
7461
- return null;
7462
- RoundProductPricesHelper.roundProductPrices(product);
7463
- if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7464
- const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7465
- await this.cache.cacheAdapter.set({
7466
- key: cacheKey,
7467
- data: serialize(product),
7468
- expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7469
- });
7470
- this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7471
- }
7472
- return product;
7473
- }
7474
- async find(params, optionsParams) {
7475
- const { filters, fields, ...options } = params || {};
7476
- const bindFields = fields ||
7477
- this.fields
7478
- .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7479
- .filter((field) => field !== 'reviews' && field !== 'categories');
7480
- if (options.options?.minimal?.includes('price'))
7481
- options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7482
- if (options.options?.maximum?.includes('price'))
7483
- options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7484
- options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7485
- options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7486
- return super.find({
7487
- ...options,
7488
- 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' },
7489
7557
  fields: [
7490
- ...bindFields,
7491
- ...(bindFields.includes('price')
7492
- ? [
7493
- 'subscriberPrice',
7494
- 'subscriberDiscountPercentage',
7495
- 'fullPrice',
7496
- ]
7497
- : []),
7498
- ],
7499
- }, optionsParams);
7500
- }
7501
- async findCatalog(params, mainGender, options) {
7502
- const result = await this.find({
7503
- ...params,
7504
- filters: { ...params.filters, published: true },
7505
- orderBy: {
7506
- hasStock: 'desc',
7507
- ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7508
- ...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
7509
- },
7510
- }, options);
7511
- return result;
7512
- }
7513
- }
7514
- tslib.__decorate([
7515
- Log(),
7516
- tslib.__metadata("design:type", Function),
7517
- tslib.__metadata("design:paramtypes", [Object, Object, Object]),
7518
- tslib.__metadata("design:returntype", Promise)
7519
- ], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
7520
-
7521
- class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7522
- constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7523
- super({
7524
- tableName: 'product_errors',
7525
- model: ProductErrorsHasuraGraphQL,
7526
- endpoint,
7527
- authOptions,
7528
- interceptors,
7529
- cache,
7530
- fields: [
7531
- {
7532
- productId: {
7533
- columnName: 'product_id',
7534
- to: (value) => +value,
7535
- from: (value) => value.toString(),
7536
- },
7537
- },
7538
- 'source',
7539
- 'error',
7540
- { createdAt: { columnName: 'created_at' } },
7541
- { updatedAt: { columnName: 'updated_at' } },
7542
- {
7543
- product: {
7544
- columnName: 'product',
7545
- foreignKeyColumn: { id: 'productId' },
7546
- fields: [
7547
- { id: { columnName: 'id', from: (value) => value.toString() } },
7548
- { productId: { columnName: 'main_product_id' } },
7549
- 'name',
7550
- 'published',
7551
- 'group',
7552
- 'validity',
7553
- { createdAt: { columnName: 'created_at' } },
7554
- { updatedAt: { columnName: 'updated_at' } },
7555
- ],
7556
- },
7557
- },
7558
- ],
7559
- });
7560
- this.productRepository = productRepository;
7561
- }
7562
- async get(params) {
7563
- const result = await super.get(params);
7564
- if (result instanceof VariantHasuraGraphQL) {
7565
- const product = await this.productRepository.get({ id: result.productId.toString() });
7566
- result.product.name = product.name;
7567
- result.product.group = product.group;
7568
- }
7569
- return result;
7570
- }
7571
- async find(params) {
7572
- const result = await super.find(params);
7573
- const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
7574
- (lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
7575
- if (variantsWithNoData.length > 0) {
7576
- const { data: products } = await this.productRepository.find({
7577
- filters: {
7578
- id: {
7579
- operator: exports.Where.IN,
7580
- value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
7581
- },
7582
- },
7583
- });
7584
- products.forEach((product) => {
7585
- result.data
7586
- .filter((variant) => variant.product.productId?.toString() === product.id.toString())
7587
- .forEach((variant) => {
7588
- variant.product.name = product.name;
7589
- variant.product.group = product.group;
7590
- });
7591
- });
7592
- }
7593
- return result;
7594
- }
7595
- }
7596
-
7597
- const commonFields = [
7598
- {
7599
- id: {
7600
- columnName: 'id',
7601
- to: (value) => +value,
7602
- from: (value) => value.toString(),
7603
- },
7604
- },
7605
- { firestoreId: { columnName: 'firestore_id' } },
7606
- { productId: { columnName: 'main_product_id' } },
7607
- { CEST: { columnName: 'cest' } },
7608
- { EAN: { columnName: 'ean' } },
7609
- { NCM: { columnName: 'ncm' } },
7610
- 'brand',
7611
- { costPrice: { columnName: 'cost_price' } },
7612
- {
7613
- description: {
7614
- columnName: 'description',
7615
- from: (description, data) => ({
7616
- description,
7617
- differentials: data.differentials,
7618
- whoMustUse: data.who_must_use,
7619
- howToUse: data.how_to_use,
7620
- brand: data.brand_description,
7621
- ingredients: data.ingredients,
7622
- purpose: data.purpose,
7623
- }),
7624
- bindFindFilter: (filters) => {
7625
- return {
7626
- ...(filters?.description && { description: filters.description }),
7627
- ...(filters.differentials && { differentials: filters.differentials }),
7628
- ...(filters.whoMustUse && {
7629
- who_must_use: filters.whoMustUse,
7630
- }),
7631
- ...(filters.howToUse && {
7632
- how_to_use: filters.howToUse,
7633
- }),
7634
- ...(filters.brand && {
7635
- brand_description: filters.brand,
7636
- }),
7637
- ...(filters.ingredients && {
7638
- ingredients: filters.ingredients,
7639
- }),
7640
- ...(filters.purpose && {
7641
- purpose: filters.purpose,
7642
- }),
7643
- };
7644
- },
7645
- bindPersistData: (descriptionData) => ({
7646
- ...(descriptionData?.description && { description: descriptionData.description }),
7647
- ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7648
- ...(descriptionData.whoMustUse && {
7649
- who_must_use: descriptionData.whoMustUse,
7650
- }),
7651
- ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7652
- ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7653
- ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7654
- ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7655
- }),
7656
- },
7657
- },
7658
- { differentials: { columnName: 'differentials' } },
7659
- { whoMustUse: { columnName: 'who_must_use' } },
7660
- { howToUse: { columnName: 'how_to_use' } },
7661
- { brandDescription: { columnName: 'brand_description' } },
7662
- { ingredients: { columnName: 'ingredients' } },
7663
- { purpose: { columnName: 'purpose' } },
7664
- { hasVariants: { columnName: 'has_variants' } },
7665
- {
7666
- images: {
7667
- columnName: 'images',
7668
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7669
- },
7670
- },
7671
- {
7672
- miniatures: {
7673
- columnName: 'miniatures',
7674
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7675
- },
7676
- },
7677
- {
7678
- imagesCard: {
7679
- columnName: 'images_card',
7680
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7681
- },
7682
- },
7683
- 'name',
7684
- {
7685
- price: {
7686
- columnName: 'price',
7687
- from: (price, data) => ({
7688
- price,
7689
- fullPrice: data.full_price,
7690
- subscriberDiscountPercentage: data.subscriber_discount_percentage,
7691
- fullPriceDiscountPercentage: data.full_price_discount_percentage,
7692
- subscriberPrice: data.subscriber_price,
7693
- }),
7694
- bindFindFilter: (filters) => {
7695
- return {
7696
- ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7697
- ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7698
- ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7699
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7700
- }),
7701
- ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7702
- subscriber_price: filters.subscriberPrice,
7703
- }),
7704
- ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7705
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7706
- }),
7707
- };
7708
- },
7709
- bindPersistData: (priceData) => ({
7710
- ...(priceData?.price >= 0 && { price: priceData.price }),
7711
- ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7712
- ...(priceData.subscriberDiscountPercentage >= 0 && {
7713
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7714
- }),
7715
- ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7716
- ...(priceData.fullPriceDiscountPercentage >= 0 && {
7717
- full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7718
- }),
7719
- }),
7720
- },
7721
- },
7722
- { fullPrice: { columnName: 'full_price' } },
7723
- { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7724
- { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7725
- { subscriberPrice: { columnName: 'subscriber_price' } },
7726
- 'published',
7727
- 'outlet',
7728
- 'label',
7729
- 'sku',
7730
- {
7731
- stock: {
7732
- columnName: 'stock',
7733
- from: (quantity) => ({ quantity }),
7734
- to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
7735
- },
7736
- },
7737
- { hasStock: { columnName: 'has_stock' } },
7738
- 'slug',
7739
- 'type',
7740
- 'video',
7741
- 'weight',
7742
- 'gender',
7743
- { intGender: { columnName: 'int_gender' } },
7744
- { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7745
- { isKit: { columnName: 'is_kit' } },
7746
- { createdAt: { columnName: 'created_at' } },
7747
- { updatedAt: { columnName: 'updated_at' } },
7748
- { rate: { columnName: 'rating' } },
7749
- { reviewsTotal: { columnName: 'reviews_total' } },
7750
- { shoppingCount: { columnName: 'shopping_count' } },
7751
- { categoryId: { columnName: 'category_id' } },
7752
- {
7753
- category: {
7754
- columnName: 'category',
7755
- foreignKeyColumn: { id: 'categoryId' },
7756
- fields: ['id', 'name', 'reference', 'slug'],
7757
- },
7758
- },
7759
- 'group',
7760
- 'validity',
7761
- { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7762
- { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7763
- { daysOfUse: { columnName: 'days_of_use' } },
7764
- { showVariants: { columnName: 'show_variants' } },
7765
- { variantSlug: { columnName: 'variant_slug' } },
7766
- ];
7767
- const fieldsConfiguration$2 = [
7768
- ...commonFields,
7769
- {
7770
- categories: {
7771
- columnName: 'categories',
7772
- fields: ['category_id'],
7773
- bindPersistData: (value) => ({
7774
- categories: { data: value.map((category) => ({ category_id: +category })) },
7775
- }),
7776
- to: (categories) => categories.map((categoryId) => +categoryId),
7777
- from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
7778
- },
7779
- },
7780
- {
7781
- kitProducts: {
7782
- columnName: 'kit_products',
7783
- foreignKeyColumn: { productId: 'id' },
7784
- fields: [
7785
- { productId: { columnName: 'product_id' } },
7786
- { kitProductId: { columnName: 'kit_product_id' } },
7787
- 'quantity',
7788
- { product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
7558
+ { productId: { columnName: 'product_id' } },
7559
+ { kitProductId: { columnName: 'kit_product_id' } },
7560
+ 'quantity',
7561
+ { product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
7789
7562
  ],
7790
7563
  },
7791
7564
  },
@@ -7826,61 +7599,9 @@ const fieldsConfiguration$2 = [
7826
7599
  foreignKeyColumn: { product_id: 'id' },
7827
7600
  fields: [
7828
7601
  'id',
7829
- 'name',
7830
7602
  'ean',
7831
7603
  'sku',
7832
- {
7833
- description: {
7834
- columnName: 'description',
7835
- from: (description, data) => ({
7836
- description,
7837
- differentials: data.differentials,
7838
- whoMustUse: data.who_must_use,
7839
- howToUse: data.how_to_use,
7840
- brand: data.brand_description,
7841
- ingredients: data.ingredients,
7842
- purpose: data.purpose,
7843
- }),
7844
- bindFindFilter: (filters) => {
7845
- return {
7846
- ...(filters?.description && { description: filters.description }),
7847
- ...(filters.differentials && { differentials: filters.differentials }),
7848
- ...(filters.whoMustUse && {
7849
- who_must_use: filters.whoMustUse,
7850
- }),
7851
- ...(filters.howToUse && {
7852
- how_to_use: filters.howToUse,
7853
- }),
7854
- ...(filters.brand && {
7855
- brand_description: filters.brand,
7856
- }),
7857
- ...(filters.ingredients && {
7858
- ingredients: filters.ingredients,
7859
- }),
7860
- ...(filters.purpose && {
7861
- purpose: filters.purpose,
7862
- }),
7863
- };
7864
- },
7865
- bindPersistData: (descriptionData) => ({
7866
- ...(descriptionData?.description && { description: descriptionData.description }),
7867
- ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7868
- ...(descriptionData.whoMustUse && {
7869
- who_must_use: descriptionData.whoMustUse,
7870
- }),
7871
- ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7872
- ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7873
- ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7874
- ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7875
- }),
7876
- },
7877
- },
7878
- { differentials: { columnName: 'differentials' } },
7879
- { whoMustUse: { columnName: 'who_must_use' } },
7880
- { howToUse: { columnName: 'how_to_use' } },
7881
- { brandDescription: { columnName: 'brand_description' } },
7882
- { ingredients: { columnName: 'ingredients' } },
7883
- { purpose: { columnName: 'purpose' } },
7604
+ 'description',
7884
7605
  {
7885
7606
  grade: {
7886
7607
  columnName: 'grade',
@@ -7897,6 +7618,22 @@ const fieldsConfiguration$2 = [
7897
7618
  subscriberPrice: data.subscriber_price,
7898
7619
  fullPriceDiscountPercentage: data.full_price_discount_percentage,
7899
7620
  }),
7621
+ bindFindFilter: (sentence) => {
7622
+ const filters = Object.values(sentence).shift();
7623
+ return {
7624
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7625
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7626
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7627
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7628
+ }),
7629
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7630
+ subscriber_price: filters.subscriberPrice,
7631
+ }),
7632
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7633
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7634
+ }),
7635
+ };
7636
+ },
7900
7637
  bindPersistData: (priceData) => ({
7901
7638
  ...((priceData?.price || 0) >= 0 && { price: priceData.price }),
7902
7639
  ...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
@@ -7942,39 +7679,6 @@ const fieldsConfiguration$2 = [
7942
7679
  },
7943
7680
  { tagsProfile: { columnName: 'tags_profile' } },
7944
7681
  { tagsCollection: { columnName: 'tags_collection' } },
7945
- { variantSlug: { columnName: 'variant_slug' } },
7946
- {
7947
- reviews: {
7948
- columnName: 'reviews',
7949
- foreignKeyColumn: { product_id: 'id' },
7950
- fields: [
7951
- 'id',
7952
- 'shop',
7953
- 'rate',
7954
- 'author',
7955
- 'email',
7956
- 'location',
7957
- 'review',
7958
- 'status',
7959
- 'title',
7960
- { personId: { columnName: 'person_id' } },
7961
- 'points',
7962
- { orderId: { columnName: 'order_id' } },
7963
- { createdAt: { columnName: 'created_at' } },
7964
- { updatedAt: { columnName: 'updated_at' } },
7965
- ],
7966
- },
7967
- },
7968
- { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7969
- {
7970
- metadata: {
7971
- columnName: 'metadata',
7972
- fields: ['title', 'description'],
7973
- bindPersistData: (value) => ({
7974
- metadata: { data: value },
7975
- }),
7976
- },
7977
- },
7978
7682
  ],
7979
7683
  },
7980
7684
  },
@@ -8040,12 +7744,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8040
7744
  : await super.get(identifiers, options);
8041
7745
  if (product.productId)
8042
7746
  throw new NotFoundError('Product not found, it is a variant');
8043
- product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
8044
- if (!product.variants?.length) {
8045
- for (const [index, variant] of product.variants.entries()) {
8046
- product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8047
- }
8048
- }
7747
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
8049
7748
  return product;
8050
7749
  }
8051
7750
  async find(params, optionsParams) {
@@ -8087,9 +7786,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8087
7786
  const result = await this.find({
8088
7787
  filters: {
8089
7788
  slug,
8090
- productId: {
8091
- operator: exports.Where.ISNULL,
8092
- },
8093
7789
  },
8094
7790
  fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
8095
7791
  options: {
@@ -8099,11 +7795,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8099
7795
  if (!result.data.length)
8100
7796
  return null;
8101
7797
  const product = result?.data?.shift();
8102
- if (!product.variants?.length) {
8103
- for (const [index, variant] of product.variants.entries()) {
8104
- product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8105
- }
8106
- }
8107
7798
  RoundProductPricesHelper.roundProductPrices(product);
8108
7799
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
8109
7800
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
@@ -8283,8 +7974,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8283
7974
  const plainData = this.paramsToPlain({ metadata });
8284
7975
  if (!plainData.metadata)
8285
7976
  return null;
8286
- // eslint-disable-next-line @typescript-eslint/naming-convention
8287
- const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
7977
+ await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8288
7978
  pk_columns: {
8289
7979
  value: { product_id: productId },
8290
7980
  type: 'product_metadata_pk_columns_input',
@@ -8296,14 +7986,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8296
7986
  required: true,
8297
7987
  },
8298
7988
  });
8299
- if (!update_product_metadata_by_pk) {
8300
- await this.mutation('insert_product_metadata', ['affected_rows'], {
8301
- objects: {
8302
- type: '[product_metadata_insert_input!]!',
8303
- value: [{ product_id: productId, ...metadata }],
8304
- },
8305
- });
8306
- }
8307
7989
  return plainData.metadata;
8308
7990
  }
8309
7991
  async getId(id) {
@@ -8314,7 +7996,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8314
7996
  return data?.[0]?.id;
8315
7997
  throw new NotFoundError(`Product with id ${id} not found`);
8316
7998
  }
8317
- async findReviewsByProduct(productId, onlyApproved, options) {
7999
+ async findReviewsByProduct(productId, options) {
8318
8000
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8319
8001
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
8320
8002
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
@@ -8327,16 +8009,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8327
8009
  where: {
8328
8010
  value: {
8329
8011
  product_id: { _eq: productId },
8330
- ...(onlyApproved && { status: { _eq: true } }),
8331
8012
  },
8332
8013
  type: 'product_review_bool_exp',
8333
8014
  required: true,
8334
8015
  },
8335
- order_by: {
8336
- type: '[product_review_order_by]',
8337
- value: [{ createdAt: 'desc' }],
8338
- required: true,
8339
- },
8340
8016
  });
8341
8017
  const reviews = data?.map((review) => this.bindReviewToModel(review));
8342
8018
  if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
@@ -8441,7 +8117,7 @@ tslib.__decorate([
8441
8117
  tslib.__decorate([
8442
8118
  Log(),
8443
8119
  tslib.__metadata("design:type", Function),
8444
- tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
8120
+ tslib.__metadata("design:paramtypes", [Number, Object]),
8445
8121
  tslib.__metadata("design:returntype", Promise)
8446
8122
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
8447
8123
 
@@ -8473,25 +8149,7 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
8473
8149
  product: {
8474
8150
  columnName: 'product',
8475
8151
  foreignKeyColumn: { id: 'productId' },
8476
- fields: [
8477
- 'id',
8478
- {
8479
- productId: {
8480
- columnName: 'main_product_id',
8481
- to: (value) => +value,
8482
- from: (value) => value?.toString(),
8483
- },
8484
- },
8485
- 'ean',
8486
- 'sku',
8487
- 'name',
8488
- 'brand',
8489
- 'slug',
8490
- 'images',
8491
- 'grade',
8492
- 'gender',
8493
- '',
8494
- ],
8152
+ fields: ['id', 'ean', 'sku', 'name', 'brand', 'slug', 'images', 'grade', 'gender'],
8495
8153
  },
8496
8154
  },
8497
8155
  ],
@@ -8655,177 +8313,58 @@ const fieldsConfiguration$1 = [
8655
8313
  ...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
8656
8314
  ...(priceData.fullPriceDiscountPercentage >= 0 && {
8657
8315
  full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
8658
- }),
8659
- }),
8660
- },
8661
- },
8662
- { fullPrice: { columnName: 'full_price' } },
8663
- { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
8664
- { subscriberPrice: { columnName: 'subscriber_price' } },
8665
- { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
8666
- 'sku',
8667
- {
8668
- stock: {
8669
- columnName: 'stock',
8670
- from: (quantity) => ({ quantity }),
8671
- to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
8672
- },
8673
- },
8674
- { hasStock: { columnName: 'has_stock' } },
8675
- 'weight',
8676
- { name: { to: () => '', from: () => undefined } },
8677
- { hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
8678
- { createdAt: { columnName: 'created_at' } },
8679
- { updatedAt: { columnName: 'updated_at' } },
8680
- {
8681
- grade: {
8682
- columnName: 'grade',
8683
- type: HasuraGraphQLColumnType.Jsonb,
8684
- },
8685
- },
8686
- 'group',
8687
- 'type',
8688
- 'validity',
8689
- 'published',
8690
- { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8691
- { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8692
- { daysOfUse: { columnName: 'days_of_use' } },
8693
- {
8694
- images: {
8695
- columnName: 'images',
8696
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8697
- },
8698
- },
8699
- {
8700
- miniatures: {
8701
- columnName: 'miniatures',
8702
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8703
- },
8704
- },
8705
- {
8706
- imagesCard: {
8707
- columnName: 'images_card',
8708
- to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8709
- },
8710
- },
8711
- 'slug',
8712
- 'brand',
8713
- 'name',
8714
- 'sku',
8715
- { NCM: { columnName: 'ncm' } },
8716
- { CEST: { columnName: 'cest' } },
8717
- {
8718
- description: {
8719
- columnName: 'description',
8720
- from: (description, data) => ({
8721
- description,
8722
- differentials: data.differentials,
8723
- whoMustUse: data.who_must_use,
8724
- howToUse: data.how_to_use,
8725
- brand: data.brand_description,
8726
- ingredients: data.ingredients,
8727
- purpose: data.purpose,
8728
- }),
8729
- bindFindFilter: (filters) => {
8730
- return {
8731
- ...(filters?.description && { description: filters.description }),
8732
- ...(filters.differentials && { differentials: filters.differentials }),
8733
- ...(filters.whoMustUse && {
8734
- who_must_use: filters.whoMustUse,
8735
- }),
8736
- ...(filters.howToUse && {
8737
- how_to_use: filters.howToUse,
8738
- }),
8739
- ...(filters.brand && {
8740
- brand_description: filters.brand,
8741
- }),
8742
- ...(filters.ingredients && {
8743
- ingredients: filters.ingredients,
8744
- }),
8745
- ...(filters.purpose && {
8746
- purpose: filters.purpose,
8747
- }),
8748
- };
8749
- },
8750
- bindPersistData: (descriptionData) => ({
8751
- ...(descriptionData?.description && { description: descriptionData.description }),
8752
- ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
8753
- ...(descriptionData.whoMustUse && {
8754
- who_must_use: descriptionData.whoMustUse,
8755
- }),
8756
- ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
8757
- ...(descriptionData.brand && { brand_description: descriptionData.brand }),
8758
- ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
8759
- ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
8316
+ }),
8760
8317
  }),
8761
8318
  },
8762
8319
  },
8763
- { differentials: { columnName: 'differentials' } },
8764
- { whoMustUse: { columnName: 'who_must_use' } },
8765
- { howToUse: { columnName: 'how_to_use' } },
8766
- { brandDescription: { columnName: 'brand_description' } },
8767
- { ingredients: { columnName: 'ingredients' } },
8768
- { purpose: { columnName: 'purpose' } },
8769
- 'gender',
8770
- { intGender: { columnName: 'int_gender' } },
8771
- 'label',
8772
- { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
8773
- { rate: { columnName: 'rating' } },
8774
- { reviewsTotal: { columnName: 'reviews_total' } },
8775
- { shoppingCount: { columnName: 'shopping_count' } },
8776
- { categoryId: { columnName: 'category_id' } },
8320
+ { fullPrice: { columnName: 'full_price' } },
8321
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
8322
+ { subscriberPrice: { columnName: 'subscriber_price' } },
8323
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
8324
+ 'sku',
8777
8325
  {
8778
- category: {
8779
- columnName: 'category',
8780
- foreignKeyColumn: { id: 'categoryId' },
8781
- fields: ['id', 'name', 'reference', 'slug'],
8326
+ stock: {
8327
+ columnName: 'stock',
8328
+ from: (quantity) => ({ quantity }),
8329
+ to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
8782
8330
  },
8783
8331
  },
8332
+ { hasStock: { columnName: 'has_stock' } },
8333
+ 'weight',
8334
+ { name: { to: () => '', from: () => undefined } },
8335
+ { hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
8336
+ { createdAt: { columnName: 'created_at' } },
8337
+ { updatedAt: { columnName: 'updated_at' } },
8784
8338
  {
8785
- categories: {
8786
- columnName: 'categories',
8787
- fields: ['category_id'],
8788
- bindPersistData: (value) => ({
8789
- categories: { data: value.map((category) => ({ category_id: +category })) },
8790
- }),
8791
- to: (categories) => categories.map((categoryId) => +categoryId),
8792
- from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
8339
+ grade: {
8340
+ columnName: 'grade',
8341
+ type: HasuraGraphQLColumnType.Jsonb,
8793
8342
  },
8794
8343
  },
8344
+ 'group',
8345
+ 'validity',
8346
+ 'published',
8347
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8348
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8349
+ { daysOfUse: { columnName: 'days_of_use' } },
8795
8350
  {
8796
- metadata: {
8797
- columnName: 'metadata',
8798
- fields: ['title', 'description'],
8799
- bindPersistData: (value) => ({
8800
- metadata: { data: value },
8801
- }),
8351
+ images: {
8352
+ columnName: 'images',
8353
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8802
8354
  },
8803
8355
  },
8804
8356
  {
8805
- reviews: {
8806
- columnName: 'reviews',
8807
- foreignKeyColumn: { product_id: 'id' },
8808
- fields: [
8809
- 'id',
8810
- 'shop',
8811
- 'rate',
8812
- 'author',
8813
- 'email',
8814
- 'location',
8815
- 'review',
8816
- 'status',
8817
- 'title',
8818
- { personId: { columnName: 'person_id' } },
8819
- 'points',
8820
- { orderId: { columnName: 'order_id' } },
8821
- { createdAt: { columnName: 'created_at' } },
8822
- { updatedAt: { columnName: 'updated_at' } },
8823
- ],
8357
+ miniatures: {
8358
+ columnName: 'miniatures',
8359
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8360
+ },
8361
+ },
8362
+ {
8363
+ imagesCard: {
8364
+ columnName: 'images_card',
8365
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8824
8366
  },
8825
8367
  },
8826
- { variantSlug: { columnName: 'variant_slug' } },
8827
- { createdAt: { columnName: 'created_at' } },
8828
- { updatedAt: { columnName: 'updated_at' } },
8829
8368
  ];
8830
8369
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8831
8370
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8866,46 +8405,18 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8866
8405
  return data.at(0);
8867
8406
  }
8868
8407
  async update(params) {
8869
- const { productId, id: checkId, metadata, ...data } = params;
8408
+ const { productId, id: checkId, ...data } = params;
8870
8409
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
8871
8410
  if (!dataWithProductId.id) {
8872
8411
  throw new NotFoundError('Variant ID is required for update');
8873
8412
  }
8874
8413
  const id = await this.getId(dataWithProductId.id);
8875
8414
  const product = await super.update({ id, ...data });
8876
- product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
8877
8415
  if (dataWithProductId.productId) {
8878
8416
  product.productId = dataWithProductId.productId;
8879
8417
  }
8880
8418
  return product;
8881
8419
  }
8882
- async updateMetadata(productId, { metadata }) {
8883
- const plainData = this.paramsToPlain({ metadata });
8884
- if (!plainData.metadata)
8885
- return null;
8886
- // eslint-disable-next-line @typescript-eslint/naming-convention
8887
- const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8888
- pk_columns: {
8889
- value: { product_id: productId },
8890
- type: 'product_metadata_pk_columns_input',
8891
- required: true,
8892
- },
8893
- _set: {
8894
- value: lodash.omit(metadata, ['product_id']),
8895
- type: 'product_metadata_set_input',
8896
- required: true,
8897
- },
8898
- });
8899
- if (!update_product_metadata_by_pk) {
8900
- await this.mutation('insert_product_metadata', ['affected_rows'], {
8901
- objects: {
8902
- type: '[product_metadata_insert_input!]!',
8903
- value: [{ product_id: productId, ...metadata }],
8904
- },
8905
- });
8906
- }
8907
- return plainData.metadata;
8908
- }
8909
8420
  async getId(id) {
8910
8421
  if (!Number.isNaN(+id))
8911
8422
  return id;
@@ -9249,6 +8760,290 @@ tslib.__decorate([
9249
8760
  tslib.__metadata("design:returntype", Promise)
9250
8761
  ], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
9251
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
+
9252
9047
  class PagarmeBankSlipAxiosAdapter {
9253
9048
  constructor(credentials, paymentRepository) {
9254
9049
  this.credentials = credentials;
@@ -9396,15 +9191,17 @@ class PagarMeV5RequestHelper {
9396
9191
  customer: this.buildCustomer(checkout),
9397
9192
  shipping: this.buildShipping(checkout),
9398
9193
  payments: this.buildPayment(checkout, method, card),
9194
+ ...this.buildAdditionalInfo(checkout),
9399
9195
  };
9400
9196
  }
9401
9197
  static buildItems(checkout) {
9198
+ const isSubscriber = checkout.user?.isSubscriber ?? false;
9402
9199
  return checkout.lineItems
9403
9200
  .filter((item) => !item.isGift)
9404
9201
  .map((item) => {
9405
9202
  return {
9406
9203
  amount: Math.floor(item.pricePaid * 100),
9407
- description: item.name,
9204
+ description: isSubscriber ? `${item.name} - ASSINANTE` : item.name,
9408
9205
  quantity: item.quantity,
9409
9206
  code: item.EAN,
9410
9207
  };
@@ -9501,6 +9298,14 @@ class PagarMeV5RequestHelper {
9501
9298
  },
9502
9299
  };
9503
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
+ }
9504
9309
  }
9505
9310
 
9506
9311
  class PagarMeV5ResponseHelper {
@@ -10372,6 +10177,8 @@ exports.Base = Base;
10372
10177
  exports.BaseModel = BaseModel;
10373
10178
  exports.BeautyProfile = BeautyProfile;
10374
10179
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
10180
+ exports.BrandCategory = BrandCategory;
10181
+ exports.BrandCategoryFirestoreRepository = BrandCategoryFirestoreRepository;
10375
10182
  exports.BusinessError = BusinessError;
10376
10183
  exports.Buy2Win = Buy2Win;
10377
10184
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
@@ -10430,6 +10237,10 @@ exports.Log = Log;
10430
10237
  exports.LogDocument = LogDocument;
10431
10238
  exports.LogFirestoreRepository = LogFirestoreRepository;
10432
10239
  exports.Logger = Logger;
10240
+ exports.MercadoPagoCardAxiosAdapter = MercadoPagoCardAxiosAdapter;
10241
+ exports.MercadoPagoPixAxiosAdapter = MercadoPagoPixAxiosAdapter;
10242
+ exports.MercadoPagoRequestHelper = MercadoPagoRequestHelper;
10243
+ exports.MercadoPagoResponseHelper = MercadoPagoResponseHelper;
10433
10244
  exports.NotFoundError = NotFoundError;
10434
10245
  exports.ObsEmitter = ObsEmitter;
10435
10246
  exports.Order = Order;
@@ -10449,8 +10260,6 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
10449
10260
  exports.PaymentProviderFactory = PaymentProviderFactory;
10450
10261
  exports.PaymentTransaction = PaymentTransaction;
10451
10262
  exports.Product = Product;
10452
- exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
10453
- exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
10454
10263
  exports.ProductErrors = ProductErrors;
10455
10264
  exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
10456
10265
  exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;