@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.esm.js CHANGED
@@ -8,7 +8,7 @@ export { formatInTimeZone, fromZonedTime, toZonedTime } from 'date-fns-tz';
8
8
  import { compact, get, isNil, isArray, first, last, flatten, isString, omit, each, unset, isObject, isEmpty, isDate, isBoolean, isInteger, isNumber, isNaN as isNaN$1, set, chunk, sortBy } from 'lodash';
9
9
  export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set, sortBy, unset } from 'lodash';
10
10
  import { debug } from 'debug';
11
- import serializeJavascript from 'serialize-javascript';
11
+ import * as serializeJavascript from 'serialize-javascript';
12
12
  import { CustomError } from 'ts-custom-error';
13
13
  import axios, { AxiosError } from 'axios';
14
14
  import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, browserPopupRedirectResolver, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
@@ -847,7 +847,11 @@ class Variant extends ProductBase {
847
847
  static get identifiersFields() {
848
848
  return ['id', 'productId'];
849
849
  }
850
- }
850
+ }
851
+ __decorate([
852
+ Type(() => Product),
853
+ __metadata("design:type", Product)
854
+ ], Variant.prototype, "product", void 0);
851
855
 
852
856
  class Product extends ProductBase {
853
857
  }
@@ -3368,6 +3372,8 @@ class HasuraQueryBuilderHelper {
3368
3372
  class HasuraRequestHelper {
3369
3373
  static async fetch(params) {
3370
3374
  const { variables, query, endpoint, headers, logger } = params;
3375
+ console.warn('variables', variables);
3376
+ console.warn('query', query);
3371
3377
  const request = {
3372
3378
  url: endpoint,
3373
3379
  method: 'POST',
@@ -7192,6 +7198,251 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
7192
7198
  }
7193
7199
  }
7194
7200
 
7201
+ const commonFields$1 = [
7202
+ {
7203
+ id: {
7204
+ columnName: 'id',
7205
+ to: (value) => +value,
7206
+ from: (value) => value.toString(),
7207
+ },
7208
+ },
7209
+ { firestoreId: { columnName: 'firestore_id' } },
7210
+ { productId: { columnName: 'main_product_id' } },
7211
+ { CEST: { columnName: 'cest' } },
7212
+ { EAN: { columnName: 'ean' } },
7213
+ { NCM: { columnName: 'ncm' } },
7214
+ 'brand',
7215
+ { costPrice: { columnName: 'cost_price' } },
7216
+ {
7217
+ description: {
7218
+ columnName: 'description',
7219
+ from: (description, data) => ({
7220
+ description,
7221
+ differentials: data.differentials,
7222
+ whoMustUse: data.who_must_use,
7223
+ howToUse: data.how_to_use,
7224
+ brand: data.brand_description,
7225
+ ingredients: data.ingredients,
7226
+ purpose: data.purpose,
7227
+ }),
7228
+ bindFindFilter: (filters) => {
7229
+ return {
7230
+ ...(filters?.description && { description: filters.description }),
7231
+ ...(filters.differentials && { differentials: filters.differentials }),
7232
+ ...(filters.whoMustUse && {
7233
+ who_must_use: filters.whoMustUse,
7234
+ }),
7235
+ ...(filters.howToUse && {
7236
+ how_to_use: filters.howToUse,
7237
+ }),
7238
+ ...(filters.brand && {
7239
+ brand_description: filters.brand,
7240
+ }),
7241
+ ...(filters.ingredients && {
7242
+ ingredients: filters.ingredients,
7243
+ }),
7244
+ ...(filters.purpose && {
7245
+ purpose: filters.purpose,
7246
+ }),
7247
+ };
7248
+ },
7249
+ bindPersistData: (descriptionData) => ({
7250
+ ...(descriptionData?.description && { description: descriptionData.description }),
7251
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7252
+ ...(descriptionData.whoMustUse && {
7253
+ who_must_use: descriptionData.whoMustUse,
7254
+ }),
7255
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7256
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7257
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7258
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7259
+ }),
7260
+ },
7261
+ },
7262
+ { differentials: { columnName: 'differentials' } },
7263
+ { whoMustUse: { columnName: 'who_must_use' } },
7264
+ { howToUse: { columnName: 'how_to_use' } },
7265
+ { brandDescription: { columnName: 'brand_description' } },
7266
+ { ingredients: { columnName: 'ingredients' } },
7267
+ { purpose: { columnName: 'purpose' } },
7268
+ { hasVariants: { columnName: 'has_variants' } },
7269
+ {
7270
+ images: {
7271
+ columnName: 'images',
7272
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7273
+ },
7274
+ },
7275
+ {
7276
+ miniatures: {
7277
+ columnName: 'miniatures',
7278
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7279
+ },
7280
+ },
7281
+ {
7282
+ imagesCard: {
7283
+ columnName: 'images_card',
7284
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7285
+ },
7286
+ },
7287
+ 'name',
7288
+ {
7289
+ price: {
7290
+ columnName: 'price',
7291
+ from: (price, data) => ({
7292
+ price,
7293
+ fullPrice: data.full_price,
7294
+ subscriberDiscountPercentage: data.subscriber_discount_percentage,
7295
+ fullPriceDiscountPercentage: data.full_price_discount_percentage,
7296
+ subscriberPrice: data.subscriber_price,
7297
+ }),
7298
+ bindFindFilter: (filters) => {
7299
+ return {
7300
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7301
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7302
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7303
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7304
+ }),
7305
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7306
+ subscriber_price: filters.subscriberPrice,
7307
+ }),
7308
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7309
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7310
+ }),
7311
+ };
7312
+ },
7313
+ bindPersistData: (priceData) => ({
7314
+ ...(priceData?.price >= 0 && { price: priceData.price }),
7315
+ ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7316
+ ...(priceData.subscriberDiscountPercentage >= 0 && {
7317
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7318
+ }),
7319
+ ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7320
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
7321
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7322
+ }),
7323
+ }),
7324
+ },
7325
+ },
7326
+ { fullPrice: { columnName: 'full_price' } },
7327
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7328
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7329
+ { subscriberPrice: { columnName: 'subscriber_price' } },
7330
+ 'published',
7331
+ 'outlet',
7332
+ 'label',
7333
+ 'sku',
7334
+ {
7335
+ stock: {
7336
+ columnName: 'stock',
7337
+ from: (quantity) => ({ quantity }),
7338
+ to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
7339
+ },
7340
+ },
7341
+ { hasStock: { columnName: 'has_stock' } },
7342
+ 'slug',
7343
+ 'type',
7344
+ 'video',
7345
+ 'weight',
7346
+ 'gender',
7347
+ { intGender: { columnName: 'int_gender' } },
7348
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7349
+ { isKit: { columnName: 'is_kit' } },
7350
+ { createdAt: { columnName: 'created_at' } },
7351
+ { updatedAt: { columnName: 'updated_at' } },
7352
+ { rate: { columnName: 'rating' } },
7353
+ { reviewsTotal: { columnName: 'reviews_total' } },
7354
+ { shoppingCount: { columnName: 'shopping_count' } },
7355
+ { categoryId: { columnName: 'category_id' } },
7356
+ 'group',
7357
+ 'validity',
7358
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7359
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7360
+ { daysOfUse: { columnName: 'days_of_use' } },
7361
+ { showVariants: { columnName: 'show_variants' } },
7362
+ ];
7363
+ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7364
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
7365
+ super({
7366
+ tableName: 'product_catalog',
7367
+ model: ProductHasuraGraphQL,
7368
+ endpoint,
7369
+ authOptions,
7370
+ interceptors,
7371
+ fields: commonFields$1,
7372
+ cache,
7373
+ });
7374
+ }
7375
+ async get({ id }) {
7376
+ return super
7377
+ .find({
7378
+ filters: {
7379
+ id,
7380
+ },
7381
+ limits: {
7382
+ limit: 1,
7383
+ },
7384
+ })
7385
+ .then((res) => res.data.at(0));
7386
+ }
7387
+ async getByEAN(EAN, options) {
7388
+ return super
7389
+ .find({
7390
+ filters: {
7391
+ EAN,
7392
+ },
7393
+ limits: {
7394
+ limit: 1,
7395
+ },
7396
+ })
7397
+ .then((res) => res.data.at(0));
7398
+ }
7399
+ async find(params, optionsParams) {
7400
+ const { filters, fields, ...options } = params || {};
7401
+ const bindFields = fields ||
7402
+ this.fields
7403
+ .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7404
+ .filter((field) => field !== 'reviews' && field !== 'categories');
7405
+ if (options.options?.minimal?.includes('price'))
7406
+ options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7407
+ if (options.options?.maximum?.includes('price'))
7408
+ options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7409
+ options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7410
+ options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7411
+ return super.find({
7412
+ ...options,
7413
+ filters: { ...filters },
7414
+ fields: [
7415
+ ...bindFields,
7416
+ ...(bindFields.includes('price')
7417
+ ? [
7418
+ 'subscriberPrice',
7419
+ 'subscriberDiscountPercentage',
7420
+ 'fullPrice',
7421
+ ]
7422
+ : []),
7423
+ ],
7424
+ }, optionsParams);
7425
+ }
7426
+ async findCatalog(params, mainGender, options) {
7427
+ const result = await this.find({
7428
+ ...params,
7429
+ filters: { ...params.filters, published: true },
7430
+ orderBy: {
7431
+ hasStock: 'desc',
7432
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7433
+ ...omit(params.orderBy, ['hasStock', 'intGender']),
7434
+ },
7435
+ }, options);
7436
+ return result;
7437
+ }
7438
+ }
7439
+ __decorate([
7440
+ Log(),
7441
+ __metadata("design:type", Function),
7442
+ __metadata("design:paramtypes", [Object, Object, Object]),
7443
+ __metadata("design:returntype", Promise)
7444
+ ], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
7445
+
7195
7446
  class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7196
7447
  constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7197
7448
  super({
@@ -7348,6 +7599,12 @@ const commonFields = [
7348
7599
  to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7349
7600
  },
7350
7601
  },
7602
+ {
7603
+ imagesCard: {
7604
+ columnName: 'images_card',
7605
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7606
+ },
7607
+ },
7351
7608
  'name',
7352
7609
  {
7353
7610
  price: {
@@ -7429,6 +7686,7 @@ const commonFields = [
7429
7686
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7430
7687
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7431
7688
  { daysOfUse: { columnName: 'days_of_use' } },
7689
+ { showVariants: { columnName: 'show_variants' } },
7432
7690
  ];
7433
7691
  const fieldsConfiguration$2 = [
7434
7692
  ...commonFields,
@@ -7492,7 +7750,61 @@ const fieldsConfiguration$2 = [
7492
7750
  foreignKeyColumn: { product_id: 'id' },
7493
7751
  fields: [
7494
7752
  'id',
7753
+ 'name',
7495
7754
  'ean',
7755
+ 'sku',
7756
+ {
7757
+ description: {
7758
+ columnName: 'description',
7759
+ from: (description, data) => ({
7760
+ description,
7761
+ differentials: data.differentials,
7762
+ whoMustUse: data.who_must_use,
7763
+ howToUse: data.how_to_use,
7764
+ brand: data.brand_description,
7765
+ ingredients: data.ingredients,
7766
+ purpose: data.purpose,
7767
+ }),
7768
+ bindFindFilter: (filters) => {
7769
+ return {
7770
+ ...(filters?.description && { description: filters.description }),
7771
+ ...(filters.differentials && { differentials: filters.differentials }),
7772
+ ...(filters.whoMustUse && {
7773
+ who_must_use: filters.whoMustUse,
7774
+ }),
7775
+ ...(filters.howToUse && {
7776
+ how_to_use: filters.howToUse,
7777
+ }),
7778
+ ...(filters.brand && {
7779
+ brand_description: filters.brand,
7780
+ }),
7781
+ ...(filters.ingredients && {
7782
+ ingredients: filters.ingredients,
7783
+ }),
7784
+ ...(filters.purpose && {
7785
+ purpose: filters.purpose,
7786
+ }),
7787
+ };
7788
+ },
7789
+ bindPersistData: (descriptionData) => ({
7790
+ ...(descriptionData?.description && { description: descriptionData.description }),
7791
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7792
+ ...(descriptionData.whoMustUse && {
7793
+ who_must_use: descriptionData.whoMustUse,
7794
+ }),
7795
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7796
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7797
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7798
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7799
+ }),
7800
+ },
7801
+ },
7802
+ { differentials: { columnName: 'differentials' } },
7803
+ { whoMustUse: { columnName: 'who_must_use' } },
7804
+ { howToUse: { columnName: 'how_to_use' } },
7805
+ { brandDescription: { columnName: 'brand_description' } },
7806
+ { ingredients: { columnName: 'ingredients' } },
7807
+ { purpose: { columnName: 'purpose' } },
7496
7808
  {
7497
7809
  grade: {
7498
7810
  columnName: 'grade',
@@ -7546,9 +7858,24 @@ const fieldsConfiguration$2 = [
7546
7858
  to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
7547
7859
  },
7548
7860
  },
7549
- 'description',
7550
- 'images',
7551
- 'miniatures',
7861
+ {
7862
+ images: {
7863
+ columnName: 'images',
7864
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7865
+ },
7866
+ },
7867
+ {
7868
+ miniatures: {
7869
+ columnName: 'miniatures',
7870
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7871
+ },
7872
+ },
7873
+ {
7874
+ imagesCard: {
7875
+ columnName: 'images_card',
7876
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7877
+ },
7878
+ },
7552
7879
  { tagsProfile: { columnName: 'tags_profile' } },
7553
7880
  { tagsCollection: { columnName: 'tags_collection' } },
7554
7881
  ],
@@ -7614,9 +7941,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7614
7941
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7615
7942
  .data?.[0]
7616
7943
  : await super.get(identifiers, options);
7617
- if (product.productId)
7618
- throw new NotFoundError('Product not found, it is a variant');
7619
- product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
7944
+ // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7945
+ product.reviews =
7946
+ product.reviews ||
7947
+ (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
7620
7948
  return product;
7621
7949
  }
7622
7950
  async find(params, optionsParams) {
@@ -7633,7 +7961,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7633
7961
  options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7634
7962
  return super.find({
7635
7963
  ...options,
7636
- filters: { ...filters, productId: { operator: Where.ISNULL } },
7964
+ filters: { ...filters },
7965
+ // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7966
+ // filters: { ...filters, productId: { operator: Where.ISNULL } },
7637
7967
  fields: [
7638
7968
  ...bindFields,
7639
7969
  ...(bindFields.includes('price')
@@ -7667,6 +7997,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7667
7997
  if (!result.data.length)
7668
7998
  return null;
7669
7999
  const product = result?.data?.shift();
8000
+ if (product.productId) ;
8001
+ console.warn('product getBySlug', product);
8002
+ console.warn('vai entrar', !product.reviews.length && product.rate > 0);
8003
+ if (!product.reviews.length && product.rate > 0) {
8004
+ console.warn('entrou');
8005
+ product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8006
+ }
7670
8007
  RoundProductPricesHelper.roundProductPrices(product);
7671
8008
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7672
8009
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
@@ -7679,6 +8016,18 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7679
8016
  }
7680
8017
  return product;
7681
8018
  }
8019
+ async getBySlugVariantData(product) {
8020
+ if (!product.reviews.length && product.rate > 0) {
8021
+ product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8022
+ }
8023
+ // if (!product.metadata) {
8024
+ // product.metadata = await this.findReviewsByProduct(
8025
+ // (product.productId ? product.productId : product.id) as number,
8026
+ // true,
8027
+ // )
8028
+ // }
8029
+ return product;
8030
+ }
7682
8031
  async getByEAN(EAN, options) {
7683
8032
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7684
8033
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -7868,7 +8217,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7868
8217
  return data?.[0]?.id;
7869
8218
  throw new NotFoundError(`Product with id ${id} not found`);
7870
8219
  }
7871
- async findReviewsByProduct(productId, options) {
8220
+ async findReviewsByProduct(productId, onlyApproved, options) {
7872
8221
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7873
8222
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7874
8223
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
@@ -7881,6 +8230,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7881
8230
  where: {
7882
8231
  value: {
7883
8232
  product_id: { _eq: productId },
8233
+ ...(onlyApproved && { status: { _eq: true } }),
7884
8234
  },
7885
8235
  type: 'product_review_bool_exp',
7886
8236
  required: true,
@@ -7989,7 +8339,7 @@ __decorate([
7989
8339
  __decorate([
7990
8340
  Log(),
7991
8341
  __metadata("design:type", Function),
7992
- __metadata("design:paramtypes", [Number, Object]),
8342
+ __metadata("design:paramtypes", [Number, Boolean, Object]),
7993
8343
  __metadata("design:returntype", Promise)
7994
8344
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
7995
8345
 
@@ -8219,8 +8569,101 @@ const fieldsConfiguration$1 = [
8219
8569
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8220
8570
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8221
8571
  { daysOfUse: { columnName: 'days_of_use' } },
8222
- 'images',
8223
- 'miniatures',
8572
+ {
8573
+ images: {
8574
+ columnName: 'images',
8575
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8576
+ },
8577
+ },
8578
+ {
8579
+ miniatures: {
8580
+ columnName: 'miniatures',
8581
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8582
+ },
8583
+ },
8584
+ {
8585
+ imagesCard: {
8586
+ columnName: 'images_card',
8587
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8588
+ },
8589
+ },
8590
+ 'slug',
8591
+ 'brand',
8592
+ 'name',
8593
+ 'sku',
8594
+ { NCM: { columnName: 'ncm' } },
8595
+ { CEST: { columnName: 'cest' } },
8596
+ {
8597
+ description: {
8598
+ columnName: 'description',
8599
+ from: (description, data) => ({
8600
+ description,
8601
+ differentials: data.differentials,
8602
+ whoMustUse: data.who_must_use,
8603
+ howToUse: data.how_to_use,
8604
+ brand: data.brand_description,
8605
+ ingredients: data.ingredients,
8606
+ purpose: data.purpose,
8607
+ }),
8608
+ bindFindFilter: (filters) => {
8609
+ return {
8610
+ ...(filters?.description && { description: filters.description }),
8611
+ ...(filters.differentials && { differentials: filters.differentials }),
8612
+ ...(filters.whoMustUse && {
8613
+ who_must_use: filters.whoMustUse,
8614
+ }),
8615
+ ...(filters.howToUse && {
8616
+ how_to_use: filters.howToUse,
8617
+ }),
8618
+ ...(filters.brand && {
8619
+ brand_description: filters.brand,
8620
+ }),
8621
+ ...(filters.ingredients && {
8622
+ ingredients: filters.ingredients,
8623
+ }),
8624
+ ...(filters.purpose && {
8625
+ purpose: filters.purpose,
8626
+ }),
8627
+ };
8628
+ },
8629
+ bindPersistData: (descriptionData) => ({
8630
+ ...(descriptionData?.description && { description: descriptionData.description }),
8631
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
8632
+ ...(descriptionData.whoMustUse && {
8633
+ who_must_use: descriptionData.whoMustUse,
8634
+ }),
8635
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
8636
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
8637
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
8638
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
8639
+ }),
8640
+ },
8641
+ },
8642
+ { differentials: { columnName: 'differentials' } },
8643
+ { whoMustUse: { columnName: 'who_must_use' } },
8644
+ { howToUse: { columnName: 'how_to_use' } },
8645
+ { brandDescription: { columnName: 'brand_description' } },
8646
+ { ingredients: { columnName: 'ingredients' } },
8647
+ { purpose: { columnName: 'purpose' } },
8648
+ 'gender',
8649
+ { intGender: { columnName: 'int_gender' } },
8650
+ 'label',
8651
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
8652
+ { rate: { columnName: 'rating' } },
8653
+ { reviewsTotal: { columnName: 'reviews_total' } },
8654
+ { shoppingCount: { columnName: 'shopping_count' } },
8655
+ { categoryId: { columnName: 'category_id' } },
8656
+ {
8657
+ metadata: {
8658
+ columnName: 'metadata',
8659
+ fields: ['title', 'description'],
8660
+ bindPersistData: (value) => ({
8661
+ metadata: { data: value },
8662
+ }),
8663
+ },
8664
+ },
8665
+ { createdAt: { columnName: 'created_at' } },
8666
+ { updatedAt: { columnName: 'updated_at' } },
8224
8667
  ];
8225
8668
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8226
8669
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8261,18 +8704,37 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8261
8704
  return data.at(0);
8262
8705
  }
8263
8706
  async update(params) {
8264
- const { productId, id: checkId, ...data } = params;
8707
+ const { productId, id: checkId, metadata, ...data } = params;
8265
8708
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
8266
8709
  if (!dataWithProductId.id) {
8267
8710
  throw new NotFoundError('Variant ID is required for update');
8268
8711
  }
8269
8712
  const id = await this.getId(dataWithProductId.id);
8270
8713
  const product = await super.update({ id, ...data });
8714
+ product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
8271
8715
  if (dataWithProductId.productId) {
8272
8716
  product.productId = dataWithProductId.productId;
8273
8717
  }
8274
8718
  return product;
8275
8719
  }
8720
+ async updateMetadata(productId, { metadata }) {
8721
+ const plainData = this.paramsToPlain({ metadata });
8722
+ if (!plainData.metadata)
8723
+ return null;
8724
+ await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8725
+ pk_columns: {
8726
+ value: { product_id: productId },
8727
+ type: 'product_metadata_pk_columns_input',
8728
+ required: true,
8729
+ },
8730
+ _set: {
8731
+ value: omit(metadata, ['product_id']),
8732
+ type: 'product_metadata_set_input',
8733
+ required: true,
8734
+ },
8735
+ });
8736
+ return plainData.metadata;
8737
+ }
8276
8738
  async getId(id) {
8277
8739
  if (!Number.isNaN(+id))
8278
8740
  return id;
@@ -9600,4 +10062,4 @@ class ProductsVertexSearch {
9600
10062
  }
9601
10063
  }
9602
10064
 
9603
- export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
10065
+ export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductCatalogHasuraGraphQLRepository, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.4.0-alpha.3",
3
+ "version": "5.4.0-beta.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -19,6 +19,7 @@ export declare class ProductBase<T extends ProductBase<T, I>, I = ProductIdentif
19
19
  costPrice: number;
20
20
  images?: string[];
21
21
  miniatures?: string[];
22
+ imagesCard?: string[];
22
23
  published: boolean;
23
24
  createdAt?: Date;
24
25
  updatedAt?: Date;
@@ -2,5 +2,6 @@ import { ProductBase } from './product-base';
2
2
  import { Variant } from './variant';
3
3
  export declare class Product extends ProductBase<Product> {
4
4
  hasVariants: boolean;
5
+ showVariants: boolean;
5
6
  variants?: Variant[];
6
7
  }
@@ -1,8 +1,10 @@
1
+ import { Product } from './product';
1
2
  import { ProductBase } from './product-base';
2
3
  import { VariantGrade } from './types';
3
4
  export type ProductVariantIdentifiers = 'id' | 'productId';
4
5
  export declare class Variant extends ProductBase<Variant, ProductVariantIdentifiers> {
5
6
  productId: string;
6
7
  grade?: VariantGrade[];
8
+ product?: Product;
7
9
  static get identifiersFields(): ProductVariantIdentifiers[];
8
10
  }