@infrab4a/connect 4.0.0-beta.19 → 4.0.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 (32) hide show
  1. package/domain/catalog/models/category.d.ts +4 -0
  2. package/domain/catalog/models/product.d.ts +6 -1
  3. package/domain/catalog/models/types/index.d.ts +1 -0
  4. package/domain/catalog/models/types/product-evaluation.type.d.ts +6 -0
  5. package/domain/users/models/lead.d.ts +1 -0
  6. package/esm2020/domain/catalog/models/category.mjs +5 -1
  7. package/esm2020/domain/catalog/models/product.mjs +24 -1
  8. package/esm2020/domain/catalog/models/types/index.mjs +2 -1
  9. package/esm2020/domain/catalog/models/types/product-evaluation.type.mjs +2 -0
  10. package/esm2020/domain/users/models/lead.mjs +1 -1
  11. package/esm2020/infra/elasticsearch/adapters/axios.adapter.mjs +28 -11
  12. package/esm2020/infra/elasticsearch/adapters/elastic-search.adapter.mjs +1 -1
  13. package/esm2020/infra/elasticsearch/indexes/products-index.mjs +58 -52
  14. package/esm2020/infra/elasticsearch/types/elastic-search-result.mjs +1 -1
  15. package/esm2020/infra/hasura-graphql/mixins/helpers/graphql-field.helper.mjs +8 -5
  16. package/esm2020/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.mjs +2 -2
  17. package/esm2020/infra/hasura-graphql/models/product-hasura-graphql.mjs +1 -1
  18. package/esm2020/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.mjs +2 -1
  19. package/esm2020/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.mjs +12 -1
  20. package/esm2020/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.mjs +2 -1
  21. package/esm2020/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.mjs +2 -1
  22. package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +19 -11
  23. package/fesm2015/infrab4a-connect.mjs +152 -72
  24. package/fesm2015/infrab4a-connect.mjs.map +1 -1
  25. package/fesm2020/infrab4a-connect.mjs +149 -75
  26. package/fesm2020/infrab4a-connect.mjs.map +1 -1
  27. package/infra/elasticsearch/adapters/axios.adapter.d.ts +6 -4
  28. package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +3 -2
  29. package/infra/elasticsearch/indexes/products-index.d.ts +8 -10
  30. package/infra/elasticsearch/types/elastic-search-result.d.ts +2 -0
  31. package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +1 -0
  32. package/package.json +1 -1
@@ -771,6 +771,10 @@ class Category extends BaseModel {
771
771
  return ['id'];
772
772
  }
773
773
  }
774
+ __decorate([
775
+ Type(() => Category),
776
+ __metadata("design:type", Category)
777
+ ], Category.prototype, "parent", void 0);
774
778
  __decorate([
775
779
  Type(() => Filter),
776
780
  __metadata("design:type", Array)
@@ -811,6 +815,24 @@ class FilterOption extends BaseModel {
811
815
  }
812
816
 
813
817
  class Product extends BaseModel {
818
+ get evaluation() {
819
+ return {
820
+ reviews: this.reviews,
821
+ count: this.reviewsTotal,
822
+ rating: this.rate,
823
+ };
824
+ }
825
+ set evaluation(evaluation) {
826
+ if (!evaluation) {
827
+ this.reviews = null;
828
+ this.reviewsTotal = null;
829
+ this.rate = null;
830
+ return;
831
+ }
832
+ this.reviews = evaluation.reviews || this.reviews;
833
+ this.reviewsTotal = evaluation.count || this.reviewsTotal;
834
+ this.rate = evaluation.rating || this.rate;
835
+ }
814
836
  identifierFields() {
815
837
  return ['id'];
816
838
  }
@@ -818,6 +840,10 @@ class Product extends BaseModel {
818
840
  return ['id'];
819
841
  }
820
842
  }
843
+ __decorate([
844
+ Type(() => Category),
845
+ __metadata("design:type", Category)
846
+ ], Product.prototype, "category", void 0);
821
847
  __decorate([
822
848
  Type(() => KitProduct),
823
849
  __metadata("design:type", Array)
@@ -1083,13 +1109,17 @@ class AxiosAdapter {
1083
1109
  constructor(config) {
1084
1110
  this.config = config;
1085
1111
  }
1086
- get(index) {
1112
+ get(index, id) {
1087
1113
  return __awaiter(this, void 0, void 0, function* () {
1088
1114
  try {
1089
1115
  const { data } = yield axios({
1090
- url: `${this.config.url}/${index}`,
1116
+ url: `${this.config.url}/${index}/_doc/${id}`,
1091
1117
  method: 'GET',
1092
- headers: { Authorization: `Basic ${this.config.credential}` },
1118
+ responseType: 'json',
1119
+ headers: {
1120
+ 'Content-Type': 'application/json',
1121
+ Authorization: `ApiKey ${this.config.credential}`,
1122
+ },
1093
1123
  });
1094
1124
  return data._source;
1095
1125
  }
@@ -1103,9 +1133,14 @@ class AxiosAdapter {
1103
1133
  query(index, query) {
1104
1134
  return __awaiter(this, void 0, void 0, function* () {
1105
1135
  const { data } = yield axios({
1106
- url: `${this.config.url}/${index}`,
1136
+ url: `${this.config.url}/${index}/_search`,
1107
1137
  method: 'POST',
1108
- headers: { Authorization: `Basic ${this.config.credential}` },
1138
+ responseType: 'json',
1139
+ headers: {
1140
+ Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
1141
+ 'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
1142
+ Authorization: `ApiKey ${this.config.credential}`,
1143
+ },
1109
1144
  data: query,
1110
1145
  });
1111
1146
  return {
@@ -1117,19 +1152,29 @@ class AxiosAdapter {
1117
1152
  save(index, data) {
1118
1153
  return __awaiter(this, void 0, void 0, function* () {
1119
1154
  yield axios({
1120
- url: `${this.config.url}/${index}`,
1155
+ url: `${this.config.url}/${index}/_doc`,
1156
+ method: 'POST',
1157
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1158
+ data,
1159
+ });
1160
+ });
1161
+ }
1162
+ update(index, id, data) {
1163
+ return __awaiter(this, void 0, void 0, function* () {
1164
+ yield axios({
1165
+ url: `${this.config.url}/${index}/_update/${id}`,
1121
1166
  method: 'PUT',
1122
- headers: { Authorization: `Basic ${this.config.credential}` },
1167
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1123
1168
  data,
1124
1169
  });
1125
1170
  });
1126
1171
  }
1127
- delete(index) {
1172
+ delete(index, id) {
1128
1173
  return __awaiter(this, void 0, void 0, function* () {
1129
1174
  yield axios({
1130
- url: `${this.config.url}/${index}`,
1175
+ url: `${this.config.url}/${index}/_doc/${id}`,
1131
1176
  method: 'DELETE',
1132
- headers: { Authorization: `Basic ${this.config.credential}` },
1177
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1133
1178
  });
1134
1179
  });
1135
1180
  }
@@ -1138,16 +1183,19 @@ class AxiosAdapter {
1138
1183
  class ProductsIndex {
1139
1184
  constructor(adapter) {
1140
1185
  this.adapter = adapter;
1186
+ this.index = `products`;
1141
1187
  }
1142
- get(id) {
1188
+ getById(id) {
1143
1189
  return __awaiter(this, void 0, void 0, function* () {
1144
- const data = yield this.adapter.get(`products/_doc/${id}`);
1190
+ const data = yield this.adapter.get(this.index, id);
1145
1191
  return Product.toInstance(data);
1146
1192
  });
1147
1193
  }
1148
- findById(ids, options) {
1194
+ search(searchTerm, total, shop) {
1149
1195
  return __awaiter(this, void 0, void 0, function* () {
1196
+ const size = total >= 10 ? 500 : 9;
1150
1197
  const fields = [
1198
+ 'EAN',
1151
1199
  'brand',
1152
1200
  'id',
1153
1201
  'images',
@@ -1158,74 +1206,83 @@ class ProductsIndex {
1158
1206
  'stock',
1159
1207
  'slug',
1160
1208
  'reviews',
1161
- 'pricePaid',
1162
- 'isGift',
1163
- 'stock',
1164
- 'weight',
1165
- 'tags',
1166
- 'filters',
1167
1209
  'hasVariants',
1168
- 'type',
1210
+ 'rate',
1169
1211
  ];
1170
- const { hits } = yield this.adapter.query('products/_search', Object.assign({ _source: fields, query: {
1212
+ const filter = [{ term: { published: true } }];
1213
+ if (size > 9) {
1214
+ fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
1215
+ }
1216
+ else {
1217
+ filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
1218
+ }
1219
+ const search = yield this.adapter.query(this.index, {
1220
+ size,
1221
+ _source: fields,
1222
+ query: {
1171
1223
  bool: {
1172
- filter: [
1173
- {
1174
- terms: {
1175
- _id: ids,
1176
- },
1224
+ must: {
1225
+ multi_match: {
1226
+ query: `${searchTerm}`,
1227
+ type: 'bool_prefix',
1228
+ fields: [
1229
+ 'name',
1230
+ 'name.folded',
1231
+ 'name.search',
1232
+ 'description',
1233
+ 'description.search',
1234
+ 'description.folded',
1235
+ 'brand',
1236
+ 'brand.search',
1237
+ 'brand.folded',
1238
+ ],
1239
+ fuzziness: 2,
1177
1240
  },
1178
- {
1179
- term: {
1180
- published: true,
1241
+ },
1242
+ should: {
1243
+ match_phrase_prefix: {
1244
+ 'name.search': {
1245
+ query: `${searchTerm}`,
1246
+ slop: 10,
1181
1247
  },
1182
1248
  },
1183
- ...((options === null || options === void 0 ? void 0 : options.hasStock)
1184
- ? [
1185
- {
1186
- range: {
1187
- 'stock.quantity': {
1188
- gt: 0,
1189
- },
1190
- },
1191
- },
1192
- ]
1193
- : []),
1194
- ],
1249
+ },
1250
+ filter,
1195
1251
  },
1196
- } }, ((options === null || options === void 0 ? void 0 : options.size) ? { size: options === null || options === void 0 ? void 0 : options.size } : {})));
1197
- return hits.map((hit) => Product.toInstance(hit._source));
1252
+ },
1253
+ });
1254
+ search.hits = search.hits.filter((e) => e._source.name !== '');
1255
+ return search;
1198
1256
  });
1199
1257
  }
1200
1258
  save(product) {
1201
1259
  return __awaiter(this, void 0, void 0, function* () {
1202
- delete product.createdAt;
1203
- delete product.updatedAt;
1204
- delete product.kitProducts;
1205
1260
  try {
1206
- if (!product.firestoreId)
1207
- throw new Error('Is not a product from firestore');
1208
- yield this.get(product.firestoreId);
1209
- yield this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
1261
+ const { createdAt, updatedAt, kitProducts } = product, data = __rest(product, ["createdAt", "updatedAt", "kitProducts"]);
1262
+ this.adapter.save(this.index, data);
1210
1263
  }
1211
1264
  catch (error) {
1212
- if (!(error instanceof Error))
1213
- throw error;
1214
- console.error(error.message);
1215
- yield this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
1265
+ console.error(error);
1266
+ }
1267
+ });
1268
+ }
1269
+ update(product) {
1270
+ return __awaiter(this, void 0, void 0, function* () {
1271
+ try {
1272
+ yield this.adapter.update(this.index, product.id, product);
1273
+ }
1274
+ catch (error) {
1275
+ console.error(error);
1216
1276
  }
1217
1277
  });
1218
1278
  }
1219
- delete(product) {
1279
+ delete(id) {
1220
1280
  return __awaiter(this, void 0, void 0, function* () {
1221
- if (!product.firestoreId)
1222
- return;
1223
1281
  try {
1224
- yield this.get(product.firestoreId);
1225
- yield this.adapter.delete(`products/_doc/${product.firestoreId}`);
1282
+ yield this.adapter.delete(this.index, id);
1226
1283
  }
1227
1284
  catch (error) {
1228
- yield this.adapter.delete(`products/_doc/${product.id}`);
1285
+ console.error(error);
1229
1286
  }
1230
1287
  });
1231
1288
  }
@@ -2362,7 +2419,8 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
2362
2419
  !Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = is(data[attributeName])) === null || _a === void 0 ? void 0 : _a[key]); }).length)
2363
2420
  return Object.keys(foreignKeyColumn).reduce((object, current) => {
2364
2421
  var _a;
2365
- return (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] }));
2422
+ const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
2423
+ return Object.assign(Object.assign({}, object), { [foreignColumnName]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] });
2366
2424
  }, Object.assign({}, result));
2367
2425
  if (update &&
2368
2426
  isObject(data[attributeName]) &&
@@ -2413,7 +2471,7 @@ const withCreateHasuraGraphQL = (MixinBase) => {
2413
2471
  const columnOptions = Object.values(field).shift();
2414
2472
  return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
2415
2473
  columnOptions.foreignKeyColumn && [
2416
- ...Object.values(columnOptions.foreignKeyColumn),
2474
+ ...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => { var _a; return (_a = AttributeOptionHelper.FindByAttribute(foreignKeyName, this.fields)) === null || _a === void 0 ? void 0 : _a.columnName; }),
2417
2475
  {
2418
2476
  [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => {
2419
2477
  var _a;
@@ -2734,6 +2792,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
2734
2792
  model: CategoryFilter,
2735
2793
  endpoint,
2736
2794
  authOptions,
2795
+ interceptors,
2737
2796
  fields: [
2738
2797
  'id',
2739
2798
  { filterId: { columnName: 'filter_id' } },
@@ -2852,6 +2911,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2852
2911
  }),
2853
2912
  },
2854
2913
  },
2914
+ { isCollection: { columnName: 'is_collection' } },
2915
+ 'reference',
2916
+ { parentId: { columnName: 'parent_id' } },
2917
+ {
2918
+ parent: {
2919
+ columnName: 'parent',
2920
+ foreignKeyColumn: { id: 'parentId' },
2921
+ fields: ['id', 'name', 'reference', 'slug'],
2922
+ },
2923
+ },
2855
2924
  ],
2856
2925
  });
2857
2926
  this.productRepository = productRepository;
@@ -2961,6 +3030,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2961
3030
  'type',
2962
3031
  'shoppingCount',
2963
3032
  'gender',
3033
+ 'createdAt',
2964
3034
  ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
2965
3035
  products.push(...productsData);
2966
3036
  return products;
@@ -3107,6 +3177,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
3107
3177
  model: Filter,
3108
3178
  endpoint,
3109
3179
  authOptions,
3180
+ interceptors,
3110
3181
  fields: [
3111
3182
  'id',
3112
3183
  'description',
@@ -3222,6 +3293,7 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
3222
3293
  model: FilterOption,
3223
3294
  endpoint,
3224
3295
  authOptions,
3296
+ interceptors,
3225
3297
  fields: [
3226
3298
  'id',
3227
3299
  'description',
@@ -3341,18 +3413,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3341
3413
  { isKit: { columnName: 'is_kit' } },
3342
3414
  { createdAt: { columnName: 'created_at' } },
3343
3415
  { updatedAt: { columnName: 'updated_at' } },
3416
+ { rate: { columnName: 'rating' } },
3417
+ { reviewsTotal: { columnName: 'reviews_total' } },
3418
+ { shoppingCount: { columnName: 'shopping_count' } },
3419
+ { categoryId: { columnName: 'category_id' } },
3344
3420
  {
3345
- rate: {
3346
- columnName: 'reviews_aggregate',
3347
- filters: {
3348
- filters: { status: true },
3349
- filterType: 'product_review_bool_exp',
3350
- },
3351
- fields: [{ aggregate: [{ avg: ['rate'] }] }],
3352
- from: (value) => value.aggregate.avg.rate,
3421
+ category: {
3422
+ columnName: 'category',
3423
+ foreignKeyColumn: { id: 'categoryId' },
3424
+ fields: ['id', 'name', 'reference', 'slug'],
3353
3425
  },
3354
3426
  },
3355
- { shoppingCount: { columnName: 'shopping_count' } },
3356
3427
  ];
3357
3428
  this.fields = [
3358
3429
  ...commonFields,
@@ -3457,7 +3528,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3457
3528
  this.fields
3458
3529
  .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
3459
3530
  .filter((field) => field !== 'reviews');
3460
- return _super.find.call(this, Object.assign(Object.assign({}, options), { filters: Object.assign(Object.assign({}, filters), { productId: { operator: Where.ISNULL } }), fields: bindFields }));
3531
+ return _super.find.call(this, Object.assign(Object.assign({}, options), { filters: Object.assign(Object.assign({}, filters), { productId: { operator: Where.ISNULL } }), fields: [
3532
+ ...bindFields,
3533
+ ...(bindFields.includes('price')
3534
+ ? [
3535
+ 'subscriberPrice',
3536
+ 'subscriberDiscountPercentage',
3537
+ 'fullPrice',
3538
+ ]
3539
+ : []),
3540
+ ] }));
3461
3541
  });
3462
3542
  }
3463
3543
  getBySlug(slug) {