@infrab4a/connect 4.9.0-beta.0 → 4.9.0-beta.2

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
@@ -1835,9 +1835,6 @@ const promiseTracer = function ({ options, method, propertyKey, propertyDescript
1835
1835
  return function (...args) {
1836
1836
  return new Promise((resolve, reject) => {
1837
1837
  const debug = traceCall({ target: this, propertyDescriptor, propertyKey, args });
1838
- if (get(options, 'level', '') === 'log') {
1839
- debug.with('params').log(args);
1840
- }
1841
1838
  return method
1842
1839
  .apply(this, args)
1843
1840
  .then((result) => {
@@ -1845,17 +1842,13 @@ const promiseTracer = function ({ options, method, propertyKey, propertyDescript
1845
1842
  options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
1846
1843
  }
1847
1844
  if (get(options, 'level', '') === 'log') {
1848
- debug.with('returns').log(result === undefined ? 'void' : result);
1845
+ debug.log({ req: args, res: result === undefined ? 'void' : result });
1849
1846
  }
1850
1847
  return resolve(result);
1851
1848
  })
1852
1849
  .catch((error) => {
1853
- debug.error(error, ...args);
1854
- debug.with('stack').error(error.stack).pop();
1850
+ debug.error({ req: args, res: error, stack: error.stack });
1855
1851
  return reject(error);
1856
- })
1857
- .finally(() => {
1858
- return debug.trace('finally', { args }).pop();
1859
1852
  });
1860
1853
  });
1861
1854
  };
@@ -1863,26 +1856,21 @@ const promiseTracer = function ({ options, method, propertyKey, propertyDescript
1863
1856
  const functionTracer = function ({ options, target, method, propertyKey, propertyDescriptor, }) {
1864
1857
  return function (...args) {
1865
1858
  const debug = traceCall({ target: this || target, propertyDescriptor, propertyKey, args });
1866
- if (get(options, 'level', '') === 'log') {
1867
- debug.with('params').log(args);
1868
- }
1869
1859
  let result;
1870
1860
  try {
1871
1861
  result = method.apply(this, args);
1872
1862
  if (options.callbackFn)
1873
1863
  options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
1874
1864
  if (get(options, 'level', '') === 'log') {
1875
- debug.with('returns').log(result === undefined ? 'void' : result);
1865
+ debug.log({ req: args, res: result === undefined ? 'void' : result });
1876
1866
  }
1877
1867
  return result;
1878
1868
  }
1879
1869
  catch (error) {
1880
- debug.error(error, ...args).pop();
1870
+ if (error instanceof Error)
1871
+ debug.error({ req: args, res: error, stack: error.stack });
1881
1872
  throw error;
1882
1873
  }
1883
- finally {
1884
- debug.trace('finally', { args }).pop();
1885
- }
1886
1874
  };
1887
1875
  };
1888
1876
 
@@ -2225,6 +2213,9 @@ class UpdateUserImage {
2225
2213
  }
2226
2214
 
2227
2215
  class LineItem extends Product {
2216
+ get pricePaidWithDiscount() {
2217
+ return this.pricePaid - this.discount;
2218
+ }
2228
2219
  }
2229
2220
 
2230
2221
  class ShippingMethod extends BaseModel {
@@ -2485,28 +2476,34 @@ class DuplicatedResultsError extends CustomError {
2485
2476
  class AxiosAdapter {
2486
2477
  constructor(config) {
2487
2478
  this.config = config;
2479
+ this.logger = DebugHelper.from(this);
2488
2480
  }
2489
2481
  async get(index, id) {
2482
+ const logger = this.logger.with('get');
2483
+ const req = {
2484
+ url: `${this.config.url}/${index}/_doc/${id}`,
2485
+ method: 'GET',
2486
+ responseType: 'json',
2487
+ headers: {
2488
+ 'Content-Type': 'application/json',
2489
+ Authorization: `ApiKey ${this.config.credential}`,
2490
+ },
2491
+ };
2490
2492
  try {
2491
- const { data } = await axios({
2492
- url: `${this.config.url}/${index}/_doc/${id}`,
2493
- method: 'GET',
2494
- responseType: 'json',
2495
- headers: {
2496
- 'Content-Type': 'application/json',
2497
- Authorization: `ApiKey ${this.config.credential}`,
2498
- },
2499
- });
2493
+ const { data } = await axios(req);
2494
+ logger.log({ req, res: data });
2500
2495
  return data._source;
2501
2496
  }
2502
2497
  catch (error) {
2498
+ logger.error({ req, res: error });
2503
2499
  if (!(error instanceof Error))
2504
2500
  throw error;
2505
2501
  throw new NotFoundError(error.message);
2506
2502
  }
2507
2503
  }
2508
2504
  async query(index, query) {
2509
- const { data } = await axios({
2505
+ const logger = this.logger.with('query');
2506
+ const req = {
2510
2507
  url: `${this.config.url}/${index}/_search`,
2511
2508
  method: 'POST',
2512
2509
  responseType: 'json',
@@ -2516,34 +2513,70 @@ class AxiosAdapter {
2516
2513
  Authorization: `ApiKey ${this.config.credential}`,
2517
2514
  },
2518
2515
  data: query,
2519
- });
2520
- return {
2521
- total: data.hits.total.value,
2522
- hits: data.hits.hits,
2523
2516
  };
2517
+ try {
2518
+ const { data } = await axios(req);
2519
+ const res = {
2520
+ total: data.hits.total.value,
2521
+ hits: data.hits.hits,
2522
+ };
2523
+ logger.log({ req, res });
2524
+ return res;
2525
+ }
2526
+ catch (error) {
2527
+ logger.error({ req, res: error });
2528
+ throw error;
2529
+ }
2524
2530
  }
2525
2531
  async save(index, data) {
2526
- await axios({
2532
+ const logger = this.logger.with('save');
2533
+ const req = {
2527
2534
  url: `${this.config.url}/${index}/_doc`,
2528
2535
  method: 'POST',
2529
2536
  headers: { Authorization: `ApiKey ${this.config.credential}` },
2530
2537
  data,
2531
- });
2538
+ };
2539
+ try {
2540
+ await axios(req);
2541
+ logger.log({ req, res: undefined });
2542
+ }
2543
+ catch (error) {
2544
+ logger.error({ req, res: error });
2545
+ throw error;
2546
+ }
2532
2547
  }
2533
2548
  async update(index, id, data) {
2534
- await axios({
2549
+ const logger = this.logger.with('update');
2550
+ const req = {
2535
2551
  url: `${this.config.url}/${index}/_update/${id}`,
2536
2552
  method: 'PUT',
2537
2553
  headers: { Authorization: `ApiKey ${this.config.credential}` },
2538
2554
  data,
2539
- });
2555
+ };
2556
+ try {
2557
+ await axios(req);
2558
+ logger.log({ req, res: undefined });
2559
+ }
2560
+ catch (error) {
2561
+ logger.error({ req, res: error });
2562
+ throw error;
2563
+ }
2540
2564
  }
2541
2565
  async delete(index, id) {
2542
- await axios({
2566
+ const logger = this.logger.with('delete');
2567
+ const req = {
2543
2568
  url: `${this.config.url}/${index}/_doc/${id}`,
2544
2569
  method: 'DELETE',
2545
2570
  headers: { Authorization: `ApiKey ${this.config.credential}` },
2546
- });
2571
+ };
2572
+ try {
2573
+ await axios(req);
2574
+ logger.log({ req, res: undefined });
2575
+ }
2576
+ catch (error) {
2577
+ logger.error({ req, res: error });
2578
+ throw error;
2579
+ }
2547
2580
  }
2548
2581
  }
2549
2582
 
@@ -2767,6 +2800,7 @@ const withFirestore = (MixinBase) => {
2767
2800
  this.model = options.model;
2768
2801
  this.fields = options.fields;
2769
2802
  this.interceptors = options.interceptors;
2803
+ this.logger = DebugHelper.from(this);
2770
2804
  }
2771
2805
  collection(path) {
2772
2806
  return this.firestore.getCollection(path || this.collectionName).withConverter(this.buildModelInstance());
@@ -2817,16 +2851,28 @@ const withGetFirestore = (MixinBase) => {
2817
2851
  return class GetFirestore extends MixinBase {
2818
2852
  async get(identifiers) {
2819
2853
  var _a, _b, _c, _d;
2854
+ const logger = this.logger.with('get');
2855
+ const collectionName = this.buildCollectionPathForGet(identifiers);
2820
2856
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
2821
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
2822
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
2823
- const docRef = await this.collection(this.buildCollectionPathForGet(identifiers))
2824
- .getDoc(Object.values(builded.identifier).shift().toString())
2825
- .get();
2826
- const data = docRef.data();
2827
- if (isNil(data))
2828
- throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
2829
- return ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, data, intercepted)) || data;
2857
+ const req = { collection: collectionName, data: identifiers };
2858
+ try {
2859
+ const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
2860
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
2861
+ const docRef = await this.collection(collectionName)
2862
+ .getDoc(Object.values(builded.identifier).shift().toString())
2863
+ .get();
2864
+ const data = docRef.data();
2865
+ if (isNil(data))
2866
+ throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
2867
+ const res = ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, data, intercepted)) || data;
2868
+ logger.log({ req, res });
2869
+ return res;
2870
+ }
2871
+ catch (error) {
2872
+ if (error instanceof Error)
2873
+ logger.log({ req, res: error, stack: error.stack });
2874
+ throw error;
2875
+ }
2830
2876
  }
2831
2877
  buildCollectionPathForGet(identifiers) {
2832
2878
  return this.isSubCollection(this)
@@ -2909,21 +2955,33 @@ const withFindFirestore = (MixinBase) => {
2909
2955
  }
2910
2956
  async find(find = {}) {
2911
2957
  var _a, _b, _c, _d, _e, _f;
2912
- const collection = this.collection(this.buildCollectionPathForFind(find.filters));
2958
+ const logger = this.logger.with('find');
2959
+ const collectionName = this.buildCollectionPathForFind(find.filters);
2960
+ const collection = this.collection(collectionName);
2913
2961
  const enableCount = (_b = (_a = find === null || find === void 0 ? void 0 : find.options) === null || _a === void 0 ? void 0 : _a.enableCount) !== null && _b !== void 0 ? _b : true;
2914
- const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
2915
- const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2916
- const queries = this.makeFirestoreWhere(filters || {});
2917
- const ordination = this.makeFirestoreOrderBy(filters, orderBy);
2918
- const offsets = await this.defineLimits(filters, limits);
2919
- const docs = await queries
2920
- .reduce((collection, where) => collection.where(...where), ordination.reduce((collection, ordination) => collection.order(...ordination), offsets.reduce((collection, offset) => collection[offset[0]](offset[1]), collection)))
2921
- .getDocs();
2922
- const data = docs.docs.map((doc) => doc.data());
2923
- return {
2924
- data: (await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data,
2925
- count: enableCount ? this.calculateCount(data, limits) : Infinity,
2926
- };
2962
+ const req = { collection: collectionName, data: find };
2963
+ try {
2964
+ const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
2965
+ const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2966
+ const queries = this.makeFirestoreWhere(filters || {});
2967
+ const ordination = this.makeFirestoreOrderBy(filters, orderBy);
2968
+ const offsets = await this.defineLimits(filters, limits);
2969
+ const docs = await queries
2970
+ .reduce((collection, where) => collection.where(...where), ordination.reduce((collection, ordination) => collection.order(...ordination), offsets.reduce((collection, offset) => collection[offset[0]](offset[1]), collection)))
2971
+ .getDocs();
2972
+ const data = docs.docs.map((doc) => doc.data());
2973
+ const res = {
2974
+ data: (await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data,
2975
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
2976
+ };
2977
+ logger.log({ req, queries, ordination, offsets, res });
2978
+ return res;
2979
+ }
2980
+ catch (error) {
2981
+ if (error instanceof Error)
2982
+ logger.log({ req, res: error, stack: error.stack });
2983
+ throw error;
2984
+ }
2927
2985
  }
2928
2986
  buildCollectionPathForFind(filters) {
2929
2987
  if (!this.isSubCollection(this))
@@ -2964,13 +3022,23 @@ const withCreateFirestore = (MixinBase) => {
2964
3022
  return class CreateFirestore extends MixinBase {
2965
3023
  async create(data) {
2966
3024
  var _a, _b, _c, _d;
3025
+ const logger = this.logger.with('create');
2967
3026
  const instance = this.model.toInstance(data);
2968
3027
  const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
2969
3028
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
2970
- const docRef = await this.save(builded);
2971
- const doc = (await docRef.get()).data();
2972
- const docBuilded = (await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, doc, intercepted))) || doc;
2973
- return docBuilded;
3029
+ const req = { collection: this.buildCollectionPathForAdd(builded), data };
3030
+ try {
3031
+ const docRef = await this.save(builded);
3032
+ const doc = (await docRef.get()).data();
3033
+ const docBuilded = (await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, doc, intercepted))) || doc;
3034
+ logger.log({ req, res: docBuilded });
3035
+ return docBuilded;
3036
+ }
3037
+ catch (error) {
3038
+ if (error instanceof Error)
3039
+ logger.log({ req, res: error, stack: error.stack });
3040
+ throw error;
3041
+ }
2974
3042
  }
2975
3043
  async save(data) {
2976
3044
  const collectionPath = this.buildCollectionPathForAdd(data);
@@ -3010,15 +3078,28 @@ const withUpdateFirestore = (MixinBase) => {
3010
3078
  return class UpdateFirestore extends MixinBase {
3011
3079
  async update(data) {
3012
3080
  var _a, _b, _c, _d;
3081
+ const logger = this.logger.with('update');
3082
+ const collectionName = this.buildCollectionPathForUpdate(data);
3013
3083
  const model = new this.model();
3014
3084
  const keyField = model.identifiersFields.shift();
3015
- const docRef = this.collection(this.buildCollectionPathForUpdate(data)).getDoc(getValueFromParams(data, keyField).toString());
3016
- const plainFromData = this.model.toInstance(this.paramsToPlain(data));
3017
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
3018
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
3019
- await docRef.save(builded.toPlain());
3020
- const docData = await docRef.get();
3021
- return ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, docData.data(), intercepted)) || docData.data();
3085
+ const req = { collection: collectionName, data };
3086
+ try {
3087
+ const identifiers = getValueFromParams(data, keyField);
3088
+ const docRef = this.collection().getDoc(identifiers.toString());
3089
+ const plainFromData = this.model.toInstance(this.paramsToPlain(data));
3090
+ const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
3091
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
3092
+ await docRef.save(builded.toPlain());
3093
+ const docData = await docRef.get();
3094
+ const res = ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, docData.data(), intercepted)) || docData.data();
3095
+ logger.log({ req, res, identifiers });
3096
+ return res;
3097
+ }
3098
+ catch (error) {
3099
+ if (error instanceof Error)
3100
+ logger.log({ req, res: error, stack: error.stack });
3101
+ throw error;
3102
+ }
3022
3103
  }
3023
3104
  buildCollectionPathForUpdate(identifiers) {
3024
3105
  return this.isSubCollection(this)
@@ -3038,13 +3119,22 @@ const withDeleteFirestore = (MixinBase) => {
3038
3119
  return class DeleteFirestore extends MixinBase {
3039
3120
  async delete(identifiers) {
3040
3121
  var _a, _b, _c, _d;
3122
+ const logger = this.logger.with('delete');
3123
+ const collectionName = this.buildCollectionPathForRemove(identifiers);
3041
3124
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
3042
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
3043
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3044
- await this.collection(this.buildCollectionPathForRemove(identifiers))
3045
- .getDoc(Object.values(builded.identifier).shift().toString())
3046
- .delete();
3047
- await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
3125
+ const req = { collection: collectionName, data: identifiers };
3126
+ try {
3127
+ const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
3128
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3129
+ await this.collection(collectionName).getDoc(Object.values(builded.identifier).shift().toString()).delete();
3130
+ await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
3131
+ logger.log({ req, res: undefined });
3132
+ }
3133
+ catch (error) {
3134
+ if (error instanceof Error)
3135
+ logger.log({ req, res: error, stack: error.stack });
3136
+ throw error;
3137
+ }
3048
3138
  }
3049
3139
  buildCollectionPathForRemove(identifiers) {
3050
3140
  return this.isSubCollection(this)
@@ -3219,7 +3309,19 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
3219
3309
  fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3220
3310
  };
3221
3311
  }
3222
- }
3312
+ }
3313
+ __decorate([
3314
+ Log(),
3315
+ __metadata("design:type", Function),
3316
+ __metadata("design:paramtypes", [Object]),
3317
+ __metadata("design:returntype", Promise)
3318
+ ], UserFirestoreRepository.prototype, "get", null);
3319
+ __decorate([
3320
+ Log(),
3321
+ __metadata("design:type", Function),
3322
+ __metadata("design:paramtypes", [String, String]),
3323
+ __metadata("design:returntype", Promise)
3324
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3223
3325
 
3224
3326
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3225
3327
  constructor({ firestore, interceptors }, parentRepository) {
@@ -3303,7 +3405,25 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3303
3405
  isChild(id, parentId) {
3304
3406
  return;
3305
3407
  }
3306
- }
3408
+ }
3409
+ __decorate([
3410
+ Log(),
3411
+ __metadata("design:type", Function),
3412
+ __metadata("design:paramtypes", [String, String]),
3413
+ __metadata("design:returntype", Promise)
3414
+ ], CategoryFirestoreRepository.prototype, "getCategoryBySlug", null);
3415
+ __decorate([
3416
+ Log(),
3417
+ __metadata("design:type", Function),
3418
+ __metadata("design:paramtypes", [Array, Object, String]),
3419
+ __metadata("design:returntype", Promise)
3420
+ ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3421
+ __decorate([
3422
+ Log(),
3423
+ __metadata("design:type", Function),
3424
+ __metadata("design:paramtypes", [Category, Object]),
3425
+ __metadata("design:returntype", Promise)
3426
+ ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3307
3427
 
3308
3428
  class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3309
3429
  constructor({ firestore, interceptors }) {
@@ -3362,7 +3482,19 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
3362
3482
  async fetchPaginatedReviews() {
3363
3483
  return Promise.resolve([]);
3364
3484
  }
3365
- }
3485
+ }
3486
+ __decorate([
3487
+ Log(),
3488
+ __metadata("design:type", Function),
3489
+ __metadata("design:paramtypes", [String]),
3490
+ __metadata("design:returntype", Promise)
3491
+ ], ProductFirestoreRepository.prototype, "getBySlug", null);
3492
+ __decorate([
3493
+ Log(),
3494
+ __metadata("design:type", Function),
3495
+ __metadata("design:paramtypes", [String]),
3496
+ __metadata("design:returntype", Promise)
3497
+ ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3366
3498
 
3367
3499
  class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3368
3500
  constructor({ firestore, interceptors }, parentRepository) {
@@ -4161,18 +4293,20 @@ const withHasuraGraphQL = (MixinBase) => {
4161
4293
  return (await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, result, interpected))) || result;
4162
4294
  }
4163
4295
  async fetch(params) {
4164
- this.logger.with('params').log(params);
4165
4296
  const headers = this.headers;
4166
- const { data: result } = await axios({
4297
+ const request = {
4167
4298
  url: `${this.endpoint}`,
4168
4299
  method: 'POST',
4169
4300
  data: params,
4170
4301
  headers,
4171
- });
4172
- if (!isNil(result.errors))
4173
- throw new Error(JSON.stringify(result.errors));
4174
- this.logger.with('returns').log(result);
4175
- return result.data;
4302
+ };
4303
+ const response = await axios(request);
4304
+ if (!isNil(response.data.errors)) {
4305
+ this.logger.error({ req: request, res: response.data.errors });
4306
+ throw new Error(response.data.errors);
4307
+ }
4308
+ this.logger.log({ req: request, res: response.data });
4309
+ return response.data.data;
4176
4310
  }
4177
4311
  getAttributeGraphQLTypeOf(value) {
4178
4312
  if (isUUID(value))
@@ -4619,7 +4753,19 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
4619
4753
  },
4620
4754
  });
4621
4755
  }
4622
- }
4756
+ }
4757
+ __decorate([
4758
+ Log(),
4759
+ __metadata("design:type", Function),
4760
+ __metadata("design:paramtypes", [Number]),
4761
+ __metadata("design:returntype", Promise)
4762
+ ], CategoryFilterHasuraGraphQLRepository.prototype, "deleteByCategory", null);
4763
+ __decorate([
4764
+ Log(),
4765
+ __metadata("design:type", Function),
4766
+ __metadata("design:paramtypes", [Number, Number]),
4767
+ __metadata("design:returntype", Promise)
4768
+ ], CategoryFilterHasuraGraphQLRepository.prototype, "deleteByCategoryAndFilter", null);
4623
4769
 
4624
4770
  class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
4625
4771
  constructor({ endpoint, authOptions, interceptors, }, productRepository, categoryFilterRepository) {
@@ -4825,6 +4971,20 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4825
4971
  products.push(...productsData);
4826
4972
  return products;
4827
4973
  }
4974
+ async getChildren(parentId) {
4975
+ const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference'], {
4976
+ args: {
4977
+ type: 'category_tree_args',
4978
+ value: { parentid: parentId },
4979
+ required: true,
4980
+ },
4981
+ });
4982
+ return category_tree.map((category) => Category.toInstance(category));
4983
+ }
4984
+ async isChild(id, parentId) {
4985
+ const categoryTree = await this.getChildren(parentId);
4986
+ return categoryTree.some((c) => c.id == id.toString());
4987
+ }
4828
4988
  async getId(id) {
4829
4989
  var _a, _b;
4830
4990
  if (!Number.isNaN(+id))
@@ -4954,21 +5114,43 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4954
5114
  return filters;
4955
5115
  }
4956
5116
  }
4957
- async getChildren(parentId) {
4958
- const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference'], {
4959
- args: {
4960
- type: 'category_tree_args',
4961
- value: { parentid: parentId },
4962
- required: true,
4963
- },
4964
- });
4965
- return category_tree.map((category) => Category.toInstance(category));
4966
- }
4967
- async isChild(id, parentId) {
4968
- const categoryTree = await this.getChildren(parentId);
4969
- return categoryTree.some((c) => c.id == id.toString());
4970
- }
4971
- }
5117
+ }
5118
+ __decorate([
5119
+ Log(),
5120
+ __metadata("design:type", Function),
5121
+ __metadata("design:paramtypes", [String, String]),
5122
+ __metadata("design:returntype", Promise)
5123
+ ], CategoryHasuraGraphQLRepository.prototype, "getCategoryBySlug", null);
5124
+ __decorate([
5125
+ Log(),
5126
+ __metadata("design:type", Function),
5127
+ __metadata("design:paramtypes", [String]),
5128
+ __metadata("design:returntype", Promise)
5129
+ ], CategoryHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5130
+ __decorate([
5131
+ Log(),
5132
+ __metadata("design:type", Function),
5133
+ __metadata("design:paramtypes", [Array, Object, String]),
5134
+ __metadata("design:returntype", Promise)
5135
+ ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5136
+ __decorate([
5137
+ Log(),
5138
+ __metadata("design:type", Function),
5139
+ __metadata("design:paramtypes", [Category, Object]),
5140
+ __metadata("design:returntype", Promise)
5141
+ ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5142
+ __decorate([
5143
+ Log(),
5144
+ __metadata("design:type", Function),
5145
+ __metadata("design:paramtypes", [Number]),
5146
+ __metadata("design:returntype", Promise)
5147
+ ], CategoryHasuraGraphQLRepository.prototype, "getChildren", null);
5148
+ __decorate([
5149
+ Log(),
5150
+ __metadata("design:type", Function),
5151
+ __metadata("design:paramtypes", [Number, Number]),
5152
+ __metadata("design:returntype", Promise)
5153
+ ], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
4972
5154
 
4973
5155
  class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
4974
5156
  constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
@@ -5070,7 +5252,19 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
5070
5252
  },
5071
5253
  });
5072
5254
  }
5073
- }
5255
+ }
5256
+ __decorate([
5257
+ Log(),
5258
+ __metadata("design:type", Function),
5259
+ __metadata("design:paramtypes", [Number, Object]),
5260
+ __metadata("design:returntype", Promise)
5261
+ ], FilterHasuraGraphQLRepository.prototype, "updateOptions", null);
5262
+ __decorate([
5263
+ Log(),
5264
+ __metadata("design:type", Function),
5265
+ __metadata("design:paramtypes", [Number]),
5266
+ __metadata("design:returntype", Promise)
5267
+ ], FilterHasuraGraphQLRepository.prototype, "deleteOptions", null);
5074
5268
 
5075
5269
  class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5076
5270
  constructor({ endpoint, authOptions, interceptors, }) {
@@ -5380,9 +5574,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5380
5574
  ...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: this.getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
5381
5575
  ], []);
5382
5576
  }
5383
- getReviewStatus(review) {
5384
- return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
5385
- }
5386
5577
  async fetchReviews(status) {
5387
5578
  const reviewsExpression = {
5388
5579
  status: status === 'pending'
@@ -5404,6 +5595,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5404
5595
  async findCatalog(params, mainGender) {
5405
5596
  return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign(Object.assign({ hasStock: 'desc' }, (!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' })), omit(params.orderBy, ['hasStock', 'intGender'])) }));
5406
5597
  }
5598
+ async cleanShoppingCountFromIds(ids) {
5599
+ return await this.mutation('update_product', ['affected_rows'], {
5600
+ where: {
5601
+ value: { id: { _nin: ids } },
5602
+ type: 'product_bool_exp',
5603
+ required: true,
5604
+ },
5605
+ _set: {
5606
+ value: { shopping_count: 0 },
5607
+ type: 'product_set_input',
5608
+ },
5609
+ });
5610
+ }
5611
+ getReviewStatus(review) {
5612
+ return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
5613
+ }
5407
5614
  async updateCategories(productId, { categories }) {
5408
5615
  if ('action' in categories && categories.action === 'remove') {
5409
5616
  await this.mutation('delete_category_product', ['affected_rows'], {
@@ -5571,20 +5778,37 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5571
5778
  });
5572
5779
  return data && data[0] && this.bindReviewToModel(data[0]);
5573
5780
  }
5574
- async cleanShoppingCountFromIds(ids) {
5575
- return await this.mutation('update_product', ['affected_rows'], {
5576
- where: {
5577
- value: { id: { _nin: ids } },
5578
- type: 'product_bool_exp',
5579
- required: true,
5580
- },
5581
- _set: {
5582
- value: { shopping_count: 0 },
5583
- type: 'product_set_input',
5584
- },
5585
- });
5586
- }
5587
- }
5781
+ }
5782
+ __decorate([
5783
+ Log(),
5784
+ __metadata("design:type", Function),
5785
+ __metadata("design:paramtypes", [String]),
5786
+ __metadata("design:returntype", Promise)
5787
+ ], ProductHasuraGraphQLRepository.prototype, "getBySlug", null);
5788
+ __decorate([
5789
+ Log(),
5790
+ __metadata("design:type", Function),
5791
+ __metadata("design:paramtypes", []),
5792
+ __metadata("design:returntype", Promise)
5793
+ ], ProductHasuraGraphQLRepository.prototype, "fetchProductReviews", null);
5794
+ __decorate([
5795
+ Log(),
5796
+ __metadata("design:type", Function),
5797
+ __metadata("design:paramtypes", [String]),
5798
+ __metadata("design:returntype", Promise)
5799
+ ], ProductHasuraGraphQLRepository.prototype, "fetchReviews", null);
5800
+ __decorate([
5801
+ Log(),
5802
+ __metadata("design:type", Function),
5803
+ __metadata("design:paramtypes", [Object, Object]),
5804
+ __metadata("design:returntype", Promise)
5805
+ ], ProductHasuraGraphQLRepository.prototype, "findCatalog", null);
5806
+ __decorate([
5807
+ Log(),
5808
+ __metadata("design:type", Function),
5809
+ __metadata("design:paramtypes", [Array]),
5810
+ __metadata("design:returntype", Promise)
5811
+ ], ProductHasuraGraphQLRepository.prototype, "cleanShoppingCountFromIds", null);
5588
5812
 
5589
5813
  class ProductReviewsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5590
5814
  constructor({ endpoint, authOptions, interceptors, }) {
@@ -5619,7 +5843,19 @@ class ProductReviewsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
5619
5843
  disaproveReview(id) {
5620
5844
  return this.update({ id, status: false });
5621
5845
  }
5622
- }
5846
+ }
5847
+ __decorate([
5848
+ Log(),
5849
+ __metadata("design:type", Function),
5850
+ __metadata("design:paramtypes", [Number]),
5851
+ __metadata("design:returntype", void 0)
5852
+ ], ProductReviewsHasuraGraphQLRepository.prototype, "aproveReview", null);
5853
+ __decorate([
5854
+ Log(),
5855
+ __metadata("design:type", Function),
5856
+ __metadata("design:paramtypes", [Number]),
5857
+ __metadata("design:returntype", void 0)
5858
+ ], ProductReviewsHasuraGraphQLRepository.prototype, "disaproveReview", null);
5623
5859
 
5624
5860
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5625
5861
  constructor({ endpoint, authOptions, interceptors, }) {
@@ -5869,6 +6105,36 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5869
6105
  throw new NotFoundError(`Wishlists from person ${personId} not found`);
5870
6106
  return data;
5871
6107
  }
6108
+ getCategoryBySlug(slug, _shop) {
6109
+ return this.getWishlistBySlug(slug);
6110
+ }
6111
+ async getCategoryByShop(shop) {
6112
+ if (!shop)
6113
+ return;
6114
+ const { data } = await this.find({
6115
+ filters: {
6116
+ shops: { operator: Where.IN, value: [shop] },
6117
+ published: { operator: Where.EQUALS, value: true },
6118
+ isWishlist: { operator: Where.EQUALS, value: true },
6119
+ },
6120
+ options: {
6121
+ enableCount: false,
6122
+ },
6123
+ });
6124
+ return data;
6125
+ }
6126
+ getCategoriesForHome(categoryIds, limit, gender) {
6127
+ return;
6128
+ }
6129
+ mountCategory(category, options) {
6130
+ return;
6131
+ }
6132
+ getChildren(parentId) {
6133
+ return;
6134
+ }
6135
+ isChild(id, parentId) {
6136
+ return;
6137
+ }
5872
6138
  async updateProducts(categoryId, { products }) {
5873
6139
  if ('action' in products && products.action === 'remove') {
5874
6140
  await this.mutation('delete_category_product', ['affected_rows'], {
@@ -5925,36 +6191,24 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5925
6191
  });
5926
6192
  return plainData.metadata;
5927
6193
  }
5928
- getCategoryBySlug(slug, _shop) {
5929
- return this.getWishlistBySlug(slug);
5930
- }
5931
- async getCategoryByShop(shop) {
5932
- if (!shop)
5933
- return;
5934
- const { data } = await this.find({
5935
- filters: {
5936
- shops: { operator: Where.IN, value: [shop] },
5937
- published: { operator: Where.EQUALS, value: true },
5938
- isWishlist: { operator: Where.EQUALS, value: true },
5939
- },
5940
- options: {
5941
- enableCount: false,
5942
- },
5943
- });
5944
- return data;
5945
- }
5946
- getCategoriesForHome(categoryIds, limit, gender) {
5947
- return;
5948
- }
5949
- mountCategory(category, options) {
5950
- return;
5951
- }
5952
- getChildren(parentId) {
5953
- return;
5954
- }
5955
- isChild(id, parentId) {
5956
- return;
5957
- }
5958
- }
6194
+ }
6195
+ __decorate([
6196
+ Log(),
6197
+ __metadata("design:type", Function),
6198
+ __metadata("design:paramtypes", [String]),
6199
+ __metadata("design:returntype", Promise)
6200
+ ], WishlistHasuraGraphQLRepository.prototype, "getWishlistBySlug", null);
6201
+ __decorate([
6202
+ Log(),
6203
+ __metadata("design:type", Function),
6204
+ __metadata("design:paramtypes", [String]),
6205
+ __metadata("design:returntype", Promise)
6206
+ ], WishlistHasuraGraphQLRepository.prototype, "getWishlistByPerson", null);
6207
+ __decorate([
6208
+ Log(),
6209
+ __metadata("design:type", Function),
6210
+ __metadata("design:paramtypes", [String]),
6211
+ __metadata("design:returntype", Promise)
6212
+ ], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5959
6213
 
5960
6214
  export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };