@infrab4a/connect 5.4.0-alpha.3 → 5.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -20,7 +20,25 @@ var storage = require('firebase/storage');
20
20
 
21
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
22
 
23
- var serializeJavascript__default = /*#__PURE__*/_interopDefaultLegacy(serializeJavascript);
23
+ function _interopNamespace(e) {
24
+ if (e && e.__esModule) return e;
25
+ var n = Object.create(null);
26
+ if (e) {
27
+ Object.keys(e).forEach(function (k) {
28
+ if (k !== 'default') {
29
+ var d = Object.getOwnPropertyDescriptor(e, k);
30
+ Object.defineProperty(n, k, d.get ? d : {
31
+ enumerable: true,
32
+ get: function () { return e[k]; }
33
+ });
34
+ }
35
+ });
36
+ }
37
+ n["default"] = e;
38
+ return Object.freeze(n);
39
+ }
40
+
41
+ var serializeJavascript__namespace = /*#__PURE__*/_interopNamespace(serializeJavascript);
24
42
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
25
43
 
26
44
  exports.AntifraudProviders = void 0;
@@ -626,7 +644,7 @@ const deserialize = (data) => {
626
644
  return eval('(' + data + ')');
627
645
  };
628
646
  const serialize = (data) => {
629
- return serializeJavascript__default["default"](data);
647
+ return serializeJavascript__namespace(data);
630
648
  };
631
649
 
632
650
  class BaseModel {
@@ -853,7 +871,11 @@ class Variant extends ProductBase {
853
871
  static get identifiersFields() {
854
872
  return ['id', 'productId'];
855
873
  }
856
- }
874
+ }
875
+ tslib.__decorate([
876
+ classTransformer.Type(() => Product),
877
+ tslib.__metadata("design:type", Product)
878
+ ], Variant.prototype, "product", void 0);
857
879
 
858
880
  class Product extends ProductBase {
859
881
  }
@@ -3374,6 +3396,8 @@ class HasuraQueryBuilderHelper {
3374
3396
  class HasuraRequestHelper {
3375
3397
  static async fetch(params) {
3376
3398
  const { variables, query, endpoint, headers, logger } = params;
3399
+ console.warn('variables', variables);
3400
+ console.warn('query', query);
3377
3401
  const request = {
3378
3402
  url: endpoint,
3379
3403
  method: 'POST',
@@ -7198,6 +7222,251 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
7198
7222
  }
7199
7223
  }
7200
7224
 
7225
+ const commonFields$1 = [
7226
+ {
7227
+ id: {
7228
+ columnName: 'id',
7229
+ to: (value) => +value,
7230
+ from: (value) => value.toString(),
7231
+ },
7232
+ },
7233
+ { firestoreId: { columnName: 'firestore_id' } },
7234
+ { productId: { columnName: 'main_product_id' } },
7235
+ { CEST: { columnName: 'cest' } },
7236
+ { EAN: { columnName: 'ean' } },
7237
+ { NCM: { columnName: 'ncm' } },
7238
+ 'brand',
7239
+ { costPrice: { columnName: 'cost_price' } },
7240
+ {
7241
+ description: {
7242
+ columnName: 'description',
7243
+ from: (description, data) => ({
7244
+ description,
7245
+ differentials: data.differentials,
7246
+ whoMustUse: data.who_must_use,
7247
+ howToUse: data.how_to_use,
7248
+ brand: data.brand_description,
7249
+ ingredients: data.ingredients,
7250
+ purpose: data.purpose,
7251
+ }),
7252
+ bindFindFilter: (filters) => {
7253
+ return {
7254
+ ...(filters?.description && { description: filters.description }),
7255
+ ...(filters.differentials && { differentials: filters.differentials }),
7256
+ ...(filters.whoMustUse && {
7257
+ who_must_use: filters.whoMustUse,
7258
+ }),
7259
+ ...(filters.howToUse && {
7260
+ how_to_use: filters.howToUse,
7261
+ }),
7262
+ ...(filters.brand && {
7263
+ brand_description: filters.brand,
7264
+ }),
7265
+ ...(filters.ingredients && {
7266
+ ingredients: filters.ingredients,
7267
+ }),
7268
+ ...(filters.purpose && {
7269
+ purpose: filters.purpose,
7270
+ }),
7271
+ };
7272
+ },
7273
+ bindPersistData: (descriptionData) => ({
7274
+ ...(descriptionData?.description && { description: descriptionData.description }),
7275
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7276
+ ...(descriptionData.whoMustUse && {
7277
+ who_must_use: descriptionData.whoMustUse,
7278
+ }),
7279
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7280
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7281
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7282
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7283
+ }),
7284
+ },
7285
+ },
7286
+ { differentials: { columnName: 'differentials' } },
7287
+ { whoMustUse: { columnName: 'who_must_use' } },
7288
+ { howToUse: { columnName: 'how_to_use' } },
7289
+ { brandDescription: { columnName: 'brand_description' } },
7290
+ { ingredients: { columnName: 'ingredients' } },
7291
+ { purpose: { columnName: 'purpose' } },
7292
+ { hasVariants: { columnName: 'has_variants' } },
7293
+ {
7294
+ images: {
7295
+ columnName: 'images',
7296
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7297
+ },
7298
+ },
7299
+ {
7300
+ miniatures: {
7301
+ columnName: 'miniatures',
7302
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7303
+ },
7304
+ },
7305
+ {
7306
+ imagesCard: {
7307
+ columnName: 'images_card',
7308
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7309
+ },
7310
+ },
7311
+ 'name',
7312
+ {
7313
+ price: {
7314
+ columnName: 'price',
7315
+ from: (price, data) => ({
7316
+ price,
7317
+ fullPrice: data.full_price,
7318
+ subscriberDiscountPercentage: data.subscriber_discount_percentage,
7319
+ fullPriceDiscountPercentage: data.full_price_discount_percentage,
7320
+ subscriberPrice: data.subscriber_price,
7321
+ }),
7322
+ bindFindFilter: (filters) => {
7323
+ return {
7324
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7325
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7326
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7327
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7328
+ }),
7329
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7330
+ subscriber_price: filters.subscriberPrice,
7331
+ }),
7332
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7333
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7334
+ }),
7335
+ };
7336
+ },
7337
+ bindPersistData: (priceData) => ({
7338
+ ...(priceData?.price >= 0 && { price: priceData.price }),
7339
+ ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7340
+ ...(priceData.subscriberDiscountPercentage >= 0 && {
7341
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7342
+ }),
7343
+ ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7344
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
7345
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7346
+ }),
7347
+ }),
7348
+ },
7349
+ },
7350
+ { fullPrice: { columnName: 'full_price' } },
7351
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7352
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7353
+ { subscriberPrice: { columnName: 'subscriber_price' } },
7354
+ 'published',
7355
+ 'outlet',
7356
+ 'label',
7357
+ 'sku',
7358
+ {
7359
+ stock: {
7360
+ columnName: 'stock',
7361
+ from: (quantity) => ({ quantity }),
7362
+ to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
7363
+ },
7364
+ },
7365
+ { hasStock: { columnName: 'has_stock' } },
7366
+ 'slug',
7367
+ 'type',
7368
+ 'video',
7369
+ 'weight',
7370
+ 'gender',
7371
+ { intGender: { columnName: 'int_gender' } },
7372
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7373
+ { isKit: { columnName: 'is_kit' } },
7374
+ { createdAt: { columnName: 'created_at' } },
7375
+ { updatedAt: { columnName: 'updated_at' } },
7376
+ { rate: { columnName: 'rating' } },
7377
+ { reviewsTotal: { columnName: 'reviews_total' } },
7378
+ { shoppingCount: { columnName: 'shopping_count' } },
7379
+ { categoryId: { columnName: 'category_id' } },
7380
+ 'group',
7381
+ 'validity',
7382
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7383
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7384
+ { daysOfUse: { columnName: 'days_of_use' } },
7385
+ { showVariants: { columnName: 'show_variants' } },
7386
+ ];
7387
+ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7388
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
7389
+ super({
7390
+ tableName: 'product_catalog',
7391
+ model: ProductHasuraGraphQL,
7392
+ endpoint,
7393
+ authOptions,
7394
+ interceptors,
7395
+ fields: commonFields$1,
7396
+ cache,
7397
+ });
7398
+ }
7399
+ async get({ id }) {
7400
+ return super
7401
+ .find({
7402
+ filters: {
7403
+ id,
7404
+ },
7405
+ limits: {
7406
+ limit: 1,
7407
+ },
7408
+ })
7409
+ .then((res) => res.data.at(0));
7410
+ }
7411
+ async getByEAN(EAN, options) {
7412
+ return super
7413
+ .find({
7414
+ filters: {
7415
+ EAN,
7416
+ },
7417
+ limits: {
7418
+ limit: 1,
7419
+ },
7420
+ })
7421
+ .then((res) => res.data.at(0));
7422
+ }
7423
+ async find(params, optionsParams) {
7424
+ const { filters, fields, ...options } = params || {};
7425
+ const bindFields = fields ||
7426
+ this.fields
7427
+ .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7428
+ .filter((field) => field !== 'reviews' && field !== 'categories');
7429
+ if (options.options?.minimal?.includes('price'))
7430
+ options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7431
+ if (options.options?.maximum?.includes('price'))
7432
+ options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7433
+ options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7434
+ options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7435
+ return super.find({
7436
+ ...options,
7437
+ filters: { ...filters },
7438
+ fields: [
7439
+ ...bindFields,
7440
+ ...(bindFields.includes('price')
7441
+ ? [
7442
+ 'subscriberPrice',
7443
+ 'subscriberDiscountPercentage',
7444
+ 'fullPrice',
7445
+ ]
7446
+ : []),
7447
+ ],
7448
+ }, optionsParams);
7449
+ }
7450
+ async findCatalog(params, mainGender, options) {
7451
+ const result = await this.find({
7452
+ ...params,
7453
+ filters: { ...params.filters, published: true },
7454
+ orderBy: {
7455
+ hasStock: 'desc',
7456
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7457
+ ...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
7458
+ },
7459
+ }, options);
7460
+ return result;
7461
+ }
7462
+ }
7463
+ tslib.__decorate([
7464
+ Log(),
7465
+ tslib.__metadata("design:type", Function),
7466
+ tslib.__metadata("design:paramtypes", [Object, Object, Object]),
7467
+ tslib.__metadata("design:returntype", Promise)
7468
+ ], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
7469
+
7201
7470
  class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7202
7471
  constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7203
7472
  super({
@@ -7354,6 +7623,12 @@ const commonFields = [
7354
7623
  to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7355
7624
  },
7356
7625
  },
7626
+ {
7627
+ imagesCard: {
7628
+ columnName: 'images_card',
7629
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7630
+ },
7631
+ },
7357
7632
  'name',
7358
7633
  {
7359
7634
  price: {
@@ -7435,6 +7710,7 @@ const commonFields = [
7435
7710
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7436
7711
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7437
7712
  { daysOfUse: { columnName: 'days_of_use' } },
7713
+ { showVariants: { columnName: 'show_variants' } },
7438
7714
  ];
7439
7715
  const fieldsConfiguration$2 = [
7440
7716
  ...commonFields,
@@ -7498,7 +7774,61 @@ const fieldsConfiguration$2 = [
7498
7774
  foreignKeyColumn: { product_id: 'id' },
7499
7775
  fields: [
7500
7776
  'id',
7777
+ 'name',
7501
7778
  'ean',
7779
+ 'sku',
7780
+ {
7781
+ description: {
7782
+ columnName: 'description',
7783
+ from: (description, data) => ({
7784
+ description,
7785
+ differentials: data.differentials,
7786
+ whoMustUse: data.who_must_use,
7787
+ howToUse: data.how_to_use,
7788
+ brand: data.brand_description,
7789
+ ingredients: data.ingredients,
7790
+ purpose: data.purpose,
7791
+ }),
7792
+ bindFindFilter: (filters) => {
7793
+ return {
7794
+ ...(filters?.description && { description: filters.description }),
7795
+ ...(filters.differentials && { differentials: filters.differentials }),
7796
+ ...(filters.whoMustUse && {
7797
+ who_must_use: filters.whoMustUse,
7798
+ }),
7799
+ ...(filters.howToUse && {
7800
+ how_to_use: filters.howToUse,
7801
+ }),
7802
+ ...(filters.brand && {
7803
+ brand_description: filters.brand,
7804
+ }),
7805
+ ...(filters.ingredients && {
7806
+ ingredients: filters.ingredients,
7807
+ }),
7808
+ ...(filters.purpose && {
7809
+ purpose: filters.purpose,
7810
+ }),
7811
+ };
7812
+ },
7813
+ bindPersistData: (descriptionData) => ({
7814
+ ...(descriptionData?.description && { description: descriptionData.description }),
7815
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7816
+ ...(descriptionData.whoMustUse && {
7817
+ who_must_use: descriptionData.whoMustUse,
7818
+ }),
7819
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7820
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7821
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7822
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7823
+ }),
7824
+ },
7825
+ },
7826
+ { differentials: { columnName: 'differentials' } },
7827
+ { whoMustUse: { columnName: 'who_must_use' } },
7828
+ { howToUse: { columnName: 'how_to_use' } },
7829
+ { brandDescription: { columnName: 'brand_description' } },
7830
+ { ingredients: { columnName: 'ingredients' } },
7831
+ { purpose: { columnName: 'purpose' } },
7502
7832
  {
7503
7833
  grade: {
7504
7834
  columnName: 'grade',
@@ -7552,9 +7882,24 @@ const fieldsConfiguration$2 = [
7552
7882
  to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
7553
7883
  },
7554
7884
  },
7555
- 'description',
7556
- 'images',
7557
- 'miniatures',
7885
+ {
7886
+ images: {
7887
+ columnName: 'images',
7888
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7889
+ },
7890
+ },
7891
+ {
7892
+ miniatures: {
7893
+ columnName: 'miniatures',
7894
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7895
+ },
7896
+ },
7897
+ {
7898
+ imagesCard: {
7899
+ columnName: 'images_card',
7900
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7901
+ },
7902
+ },
7558
7903
  { tagsProfile: { columnName: 'tags_profile' } },
7559
7904
  { tagsCollection: { columnName: 'tags_collection' } },
7560
7905
  ],
@@ -7620,9 +7965,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7620
7965
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7621
7966
  .data?.[0]
7622
7967
  : await super.get(identifiers, options);
7623
- if (product.productId)
7624
- throw new NotFoundError('Product not found, it is a variant');
7625
- product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
7968
+ // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7969
+ product.reviews =
7970
+ product.reviews ||
7971
+ (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
7626
7972
  return product;
7627
7973
  }
7628
7974
  async find(params, optionsParams) {
@@ -7639,7 +7985,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7639
7985
  options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7640
7986
  return super.find({
7641
7987
  ...options,
7642
- filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
7988
+ filters: { ...filters },
7989
+ // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7990
+ // filters: { ...filters, productId: { operator: Where.ISNULL } },
7643
7991
  fields: [
7644
7992
  ...bindFields,
7645
7993
  ...(bindFields.includes('price')
@@ -7673,6 +8021,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7673
8021
  if (!result.data.length)
7674
8022
  return null;
7675
8023
  const product = result?.data?.shift();
8024
+ if (product.productId) ;
8025
+ console.warn('product getBySlug', product);
8026
+ console.warn('vai entrar', !product.reviews.length && product.rate > 0);
8027
+ if (!product.reviews.length && product.rate > 0) {
8028
+ console.warn('entrou');
8029
+ product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8030
+ }
7676
8031
  RoundProductPricesHelper.roundProductPrices(product);
7677
8032
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7678
8033
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
@@ -7685,6 +8040,18 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7685
8040
  }
7686
8041
  return product;
7687
8042
  }
8043
+ async getBySlugVariantData(product) {
8044
+ if (!product.reviews.length && product.rate > 0) {
8045
+ product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8046
+ }
8047
+ // if (!product.metadata) {
8048
+ // product.metadata = await this.findReviewsByProduct(
8049
+ // (product.productId ? product.productId : product.id) as number,
8050
+ // true,
8051
+ // )
8052
+ // }
8053
+ return product;
8054
+ }
7688
8055
  async getByEAN(EAN, options) {
7689
8056
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7690
8057
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -7874,7 +8241,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7874
8241
  return data?.[0]?.id;
7875
8242
  throw new NotFoundError(`Product with id ${id} not found`);
7876
8243
  }
7877
- async findReviewsByProduct(productId, options) {
8244
+ async findReviewsByProduct(productId, onlyApproved, options) {
7878
8245
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7879
8246
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7880
8247
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
@@ -7887,6 +8254,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7887
8254
  where: {
7888
8255
  value: {
7889
8256
  product_id: { _eq: productId },
8257
+ ...(onlyApproved && { status: { _eq: true } }),
7890
8258
  },
7891
8259
  type: 'product_review_bool_exp',
7892
8260
  required: true,
@@ -7995,7 +8363,7 @@ tslib.__decorate([
7995
8363
  tslib.__decorate([
7996
8364
  Log(),
7997
8365
  tslib.__metadata("design:type", Function),
7998
- tslib.__metadata("design:paramtypes", [Number, Object]),
8366
+ tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
7999
8367
  tslib.__metadata("design:returntype", Promise)
8000
8368
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
8001
8369
 
@@ -8225,8 +8593,101 @@ const fieldsConfiguration$1 = [
8225
8593
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8226
8594
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8227
8595
  { daysOfUse: { columnName: 'days_of_use' } },
8228
- 'images',
8229
- 'miniatures',
8596
+ {
8597
+ images: {
8598
+ columnName: 'images',
8599
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8600
+ },
8601
+ },
8602
+ {
8603
+ miniatures: {
8604
+ columnName: 'miniatures',
8605
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8606
+ },
8607
+ },
8608
+ {
8609
+ imagesCard: {
8610
+ columnName: 'images_card',
8611
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8612
+ },
8613
+ },
8614
+ 'slug',
8615
+ 'brand',
8616
+ 'name',
8617
+ 'sku',
8618
+ { NCM: { columnName: 'ncm' } },
8619
+ { CEST: { columnName: 'cest' } },
8620
+ {
8621
+ description: {
8622
+ columnName: 'description',
8623
+ from: (description, data) => ({
8624
+ description,
8625
+ differentials: data.differentials,
8626
+ whoMustUse: data.who_must_use,
8627
+ howToUse: data.how_to_use,
8628
+ brand: data.brand_description,
8629
+ ingredients: data.ingredients,
8630
+ purpose: data.purpose,
8631
+ }),
8632
+ bindFindFilter: (filters) => {
8633
+ return {
8634
+ ...(filters?.description && { description: filters.description }),
8635
+ ...(filters.differentials && { differentials: filters.differentials }),
8636
+ ...(filters.whoMustUse && {
8637
+ who_must_use: filters.whoMustUse,
8638
+ }),
8639
+ ...(filters.howToUse && {
8640
+ how_to_use: filters.howToUse,
8641
+ }),
8642
+ ...(filters.brand && {
8643
+ brand_description: filters.brand,
8644
+ }),
8645
+ ...(filters.ingredients && {
8646
+ ingredients: filters.ingredients,
8647
+ }),
8648
+ ...(filters.purpose && {
8649
+ purpose: filters.purpose,
8650
+ }),
8651
+ };
8652
+ },
8653
+ bindPersistData: (descriptionData) => ({
8654
+ ...(descriptionData?.description && { description: descriptionData.description }),
8655
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
8656
+ ...(descriptionData.whoMustUse && {
8657
+ who_must_use: descriptionData.whoMustUse,
8658
+ }),
8659
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
8660
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
8661
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
8662
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
8663
+ }),
8664
+ },
8665
+ },
8666
+ { differentials: { columnName: 'differentials' } },
8667
+ { whoMustUse: { columnName: 'who_must_use' } },
8668
+ { howToUse: { columnName: 'how_to_use' } },
8669
+ { brandDescription: { columnName: 'brand_description' } },
8670
+ { ingredients: { columnName: 'ingredients' } },
8671
+ { purpose: { columnName: 'purpose' } },
8672
+ 'gender',
8673
+ { intGender: { columnName: 'int_gender' } },
8674
+ 'label',
8675
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
8676
+ { rate: { columnName: 'rating' } },
8677
+ { reviewsTotal: { columnName: 'reviews_total' } },
8678
+ { shoppingCount: { columnName: 'shopping_count' } },
8679
+ { categoryId: { columnName: 'category_id' } },
8680
+ {
8681
+ metadata: {
8682
+ columnName: 'metadata',
8683
+ fields: ['title', 'description'],
8684
+ bindPersistData: (value) => ({
8685
+ metadata: { data: value },
8686
+ }),
8687
+ },
8688
+ },
8689
+ { createdAt: { columnName: 'created_at' } },
8690
+ { updatedAt: { columnName: 'updated_at' } },
8230
8691
  ];
8231
8692
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8232
8693
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8267,18 +8728,37 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8267
8728
  return data.at(0);
8268
8729
  }
8269
8730
  async update(params) {
8270
- const { productId, id: checkId, ...data } = params;
8731
+ const { productId, id: checkId, metadata, ...data } = params;
8271
8732
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
8272
8733
  if (!dataWithProductId.id) {
8273
8734
  throw new NotFoundError('Variant ID is required for update');
8274
8735
  }
8275
8736
  const id = await this.getId(dataWithProductId.id);
8276
8737
  const product = await super.update({ id, ...data });
8738
+ product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
8277
8739
  if (dataWithProductId.productId) {
8278
8740
  product.productId = dataWithProductId.productId;
8279
8741
  }
8280
8742
  return product;
8281
8743
  }
8744
+ async updateMetadata(productId, { metadata }) {
8745
+ const plainData = this.paramsToPlain({ metadata });
8746
+ if (!plainData.metadata)
8747
+ return null;
8748
+ await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8749
+ pk_columns: {
8750
+ value: { product_id: productId },
8751
+ type: 'product_metadata_pk_columns_input',
8752
+ required: true,
8753
+ },
8754
+ _set: {
8755
+ value: lodash.omit(metadata, ['product_id']),
8756
+ type: 'product_metadata_set_input',
8757
+ required: true,
8758
+ },
8759
+ });
8760
+ return plainData.metadata;
8761
+ }
8282
8762
  async getId(id) {
8283
8763
  if (!Number.isNaN(+id))
8284
8764
  return id;
@@ -9830,6 +10310,7 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
9830
10310
  exports.PaymentProviderFactory = PaymentProviderFactory;
9831
10311
  exports.PaymentTransaction = PaymentTransaction;
9832
10312
  exports.Product = Product;
10313
+ exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
9833
10314
  exports.ProductErrors = ProductErrors;
9834
10315
  exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
9835
10316
  exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;