@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.cjs.js CHANGED
@@ -1859,9 +1859,6 @@ const promiseTracer = function ({ options, method, propertyKey, propertyDescript
1859
1859
  return function (...args) {
1860
1860
  return new Promise((resolve, reject) => {
1861
1861
  const debug = traceCall({ target: this, propertyDescriptor, propertyKey, args });
1862
- if (lodash.get(options, 'level', '') === 'log') {
1863
- debug.with('params').log(args);
1864
- }
1865
1862
  return method
1866
1863
  .apply(this, args)
1867
1864
  .then((result) => {
@@ -1869,17 +1866,13 @@ const promiseTracer = function ({ options, method, propertyKey, propertyDescript
1869
1866
  options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
1870
1867
  }
1871
1868
  if (lodash.get(options, 'level', '') === 'log') {
1872
- debug.with('returns').log(result === undefined ? 'void' : result);
1869
+ debug.log({ req: args, res: result === undefined ? 'void' : result });
1873
1870
  }
1874
1871
  return resolve(result);
1875
1872
  })
1876
1873
  .catch((error) => {
1877
- debug.error(error, ...args);
1878
- debug.with('stack').error(error.stack).pop();
1874
+ debug.error({ req: args, res: error, stack: error.stack });
1879
1875
  return reject(error);
1880
- })
1881
- .finally(() => {
1882
- return debug.trace('finally', { args }).pop();
1883
1876
  });
1884
1877
  });
1885
1878
  };
@@ -1887,26 +1880,21 @@ const promiseTracer = function ({ options, method, propertyKey, propertyDescript
1887
1880
  const functionTracer = function ({ options, target, method, propertyKey, propertyDescriptor, }) {
1888
1881
  return function (...args) {
1889
1882
  const debug = traceCall({ target: this || target, propertyDescriptor, propertyKey, args });
1890
- if (lodash.get(options, 'level', '') === 'log') {
1891
- debug.with('params').log(args);
1892
- }
1893
1883
  let result;
1894
1884
  try {
1895
1885
  result = method.apply(this, args);
1896
1886
  if (options.callbackFn)
1897
1887
  options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
1898
1888
  if (lodash.get(options, 'level', '') === 'log') {
1899
- debug.with('returns').log(result === undefined ? 'void' : result);
1889
+ debug.log({ req: args, res: result === undefined ? 'void' : result });
1900
1890
  }
1901
1891
  return result;
1902
1892
  }
1903
1893
  catch (error) {
1904
- debug.error(error, ...args).pop();
1894
+ if (error instanceof Error)
1895
+ debug.error({ req: args, res: error, stack: error.stack });
1905
1896
  throw error;
1906
1897
  }
1907
- finally {
1908
- debug.trace('finally', { args }).pop();
1909
- }
1910
1898
  };
1911
1899
  };
1912
1900
 
@@ -2249,6 +2237,9 @@ class UpdateUserImage {
2249
2237
  }
2250
2238
 
2251
2239
  class LineItem extends Product {
2240
+ get pricePaidWithDiscount() {
2241
+ return this.pricePaid - this.discount;
2242
+ }
2252
2243
  }
2253
2244
 
2254
2245
  class ShippingMethod extends BaseModel {
@@ -2509,28 +2500,34 @@ class DuplicatedResultsError extends tsCustomError.CustomError {
2509
2500
  class AxiosAdapter {
2510
2501
  constructor(config) {
2511
2502
  this.config = config;
2503
+ this.logger = DebugHelper.from(this);
2512
2504
  }
2513
2505
  async get(index, id) {
2506
+ const logger = this.logger.with('get');
2507
+ const req = {
2508
+ url: `${this.config.url}/${index}/_doc/${id}`,
2509
+ method: 'GET',
2510
+ responseType: 'json',
2511
+ headers: {
2512
+ 'Content-Type': 'application/json',
2513
+ Authorization: `ApiKey ${this.config.credential}`,
2514
+ },
2515
+ };
2514
2516
  try {
2515
- const { data } = await axios__default["default"]({
2516
- url: `${this.config.url}/${index}/_doc/${id}`,
2517
- method: 'GET',
2518
- responseType: 'json',
2519
- headers: {
2520
- 'Content-Type': 'application/json',
2521
- Authorization: `ApiKey ${this.config.credential}`,
2522
- },
2523
- });
2517
+ const { data } = await axios__default["default"](req);
2518
+ logger.log({ req, res: data });
2524
2519
  return data._source;
2525
2520
  }
2526
2521
  catch (error) {
2522
+ logger.error({ req, res: error });
2527
2523
  if (!(error instanceof Error))
2528
2524
  throw error;
2529
2525
  throw new NotFoundError(error.message);
2530
2526
  }
2531
2527
  }
2532
2528
  async query(index, query) {
2533
- const { data } = await axios__default["default"]({
2529
+ const logger = this.logger.with('query');
2530
+ const req = {
2534
2531
  url: `${this.config.url}/${index}/_search`,
2535
2532
  method: 'POST',
2536
2533
  responseType: 'json',
@@ -2540,34 +2537,70 @@ class AxiosAdapter {
2540
2537
  Authorization: `ApiKey ${this.config.credential}`,
2541
2538
  },
2542
2539
  data: query,
2543
- });
2544
- return {
2545
- total: data.hits.total.value,
2546
- hits: data.hits.hits,
2547
2540
  };
2541
+ try {
2542
+ const { data } = await axios__default["default"](req);
2543
+ const res = {
2544
+ total: data.hits.total.value,
2545
+ hits: data.hits.hits,
2546
+ };
2547
+ logger.log({ req, res });
2548
+ return res;
2549
+ }
2550
+ catch (error) {
2551
+ logger.error({ req, res: error });
2552
+ throw error;
2553
+ }
2548
2554
  }
2549
2555
  async save(index, data) {
2550
- await axios__default["default"]({
2556
+ const logger = this.logger.with('save');
2557
+ const req = {
2551
2558
  url: `${this.config.url}/${index}/_doc`,
2552
2559
  method: 'POST',
2553
2560
  headers: { Authorization: `ApiKey ${this.config.credential}` },
2554
2561
  data,
2555
- });
2562
+ };
2563
+ try {
2564
+ await axios__default["default"](req);
2565
+ logger.log({ req, res: undefined });
2566
+ }
2567
+ catch (error) {
2568
+ logger.error({ req, res: error });
2569
+ throw error;
2570
+ }
2556
2571
  }
2557
2572
  async update(index, id, data) {
2558
- await axios__default["default"]({
2573
+ const logger = this.logger.with('update');
2574
+ const req = {
2559
2575
  url: `${this.config.url}/${index}/_update/${id}`,
2560
2576
  method: 'PUT',
2561
2577
  headers: { Authorization: `ApiKey ${this.config.credential}` },
2562
2578
  data,
2563
- });
2579
+ };
2580
+ try {
2581
+ await axios__default["default"](req);
2582
+ logger.log({ req, res: undefined });
2583
+ }
2584
+ catch (error) {
2585
+ logger.error({ req, res: error });
2586
+ throw error;
2587
+ }
2564
2588
  }
2565
2589
  async delete(index, id) {
2566
- await axios__default["default"]({
2590
+ const logger = this.logger.with('delete');
2591
+ const req = {
2567
2592
  url: `${this.config.url}/${index}/_doc/${id}`,
2568
2593
  method: 'DELETE',
2569
2594
  headers: { Authorization: `ApiKey ${this.config.credential}` },
2570
- });
2595
+ };
2596
+ try {
2597
+ await axios__default["default"](req);
2598
+ logger.log({ req, res: undefined });
2599
+ }
2600
+ catch (error) {
2601
+ logger.error({ req, res: error });
2602
+ throw error;
2603
+ }
2571
2604
  }
2572
2605
  }
2573
2606
 
@@ -2791,6 +2824,7 @@ const withFirestore = (MixinBase) => {
2791
2824
  this.model = options.model;
2792
2825
  this.fields = options.fields;
2793
2826
  this.interceptors = options.interceptors;
2827
+ this.logger = DebugHelper.from(this);
2794
2828
  }
2795
2829
  collection(path) {
2796
2830
  return this.firestore.getCollection(path || this.collectionName).withConverter(this.buildModelInstance());
@@ -2841,16 +2875,28 @@ const withGetFirestore = (MixinBase) => {
2841
2875
  return class GetFirestore extends MixinBase {
2842
2876
  async get(identifiers) {
2843
2877
  var _a, _b, _c, _d;
2878
+ const logger = this.logger.with('get');
2879
+ const collectionName = this.buildCollectionPathForGet(identifiers);
2844
2880
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
2845
- 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 }));
2846
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
2847
- const docRef = await this.collection(this.buildCollectionPathForGet(identifiers))
2848
- .getDoc(Object.values(builded.identifier).shift().toString())
2849
- .get();
2850
- const data = docRef.data();
2851
- if (lodash.isNil(data))
2852
- throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
2853
- 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;
2881
+ const req = { collection: collectionName, data: identifiers };
2882
+ try {
2883
+ 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 }));
2884
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
2885
+ const docRef = await this.collection(collectionName)
2886
+ .getDoc(Object.values(builded.identifier).shift().toString())
2887
+ .get();
2888
+ const data = docRef.data();
2889
+ if (lodash.isNil(data))
2890
+ throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
2891
+ 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;
2892
+ logger.log({ req, res });
2893
+ return res;
2894
+ }
2895
+ catch (error) {
2896
+ if (error instanceof Error)
2897
+ logger.log({ req, res: error, stack: error.stack });
2898
+ throw error;
2899
+ }
2854
2900
  }
2855
2901
  buildCollectionPathForGet(identifiers) {
2856
2902
  return this.isSubCollection(this)
@@ -2933,21 +2979,33 @@ const withFindFirestore = (MixinBase) => {
2933
2979
  }
2934
2980
  async find(find = {}) {
2935
2981
  var _a, _b, _c, _d, _e, _f;
2936
- const collection = this.collection(this.buildCollectionPathForFind(find.filters));
2982
+ const logger = this.logger.with('find');
2983
+ const collectionName = this.buildCollectionPathForFind(find.filters);
2984
+ const collection = this.collection(collectionName);
2937
2985
  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;
2938
- 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 }));
2939
- const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2940
- const queries = this.makeFirestoreWhere(filters || {});
2941
- const ordination = this.makeFirestoreOrderBy(filters, orderBy);
2942
- const offsets = await this.defineLimits(filters, limits);
2943
- const docs = await queries
2944
- .reduce((collection, where) => collection.where(...where), ordination.reduce((collection, ordination) => collection.order(...ordination), offsets.reduce((collection, offset) => collection[offset[0]](offset[1]), collection)))
2945
- .getDocs();
2946
- const data = docs.docs.map((doc) => doc.data());
2947
- return {
2948
- 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,
2949
- count: enableCount ? this.calculateCount(data, limits) : Infinity,
2950
- };
2986
+ const req = { collection: collectionName, data: find };
2987
+ try {
2988
+ 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 }));
2989
+ const { filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
2990
+ const queries = this.makeFirestoreWhere(filters || {});
2991
+ const ordination = this.makeFirestoreOrderBy(filters, orderBy);
2992
+ const offsets = await this.defineLimits(filters, limits);
2993
+ const docs = await queries
2994
+ .reduce((collection, where) => collection.where(...where), ordination.reduce((collection, ordination) => collection.order(...ordination), offsets.reduce((collection, offset) => collection[offset[0]](offset[1]), collection)))
2995
+ .getDocs();
2996
+ const data = docs.docs.map((doc) => doc.data());
2997
+ const res = {
2998
+ 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,
2999
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
3000
+ };
3001
+ logger.log({ req, queries, ordination, offsets, res });
3002
+ return res;
3003
+ }
3004
+ catch (error) {
3005
+ if (error instanceof Error)
3006
+ logger.log({ req, res: error, stack: error.stack });
3007
+ throw error;
3008
+ }
2951
3009
  }
2952
3010
  buildCollectionPathForFind(filters) {
2953
3011
  if (!this.isSubCollection(this))
@@ -2988,13 +3046,23 @@ const withCreateFirestore = (MixinBase) => {
2988
3046
  return class CreateFirestore extends MixinBase {
2989
3047
  async create(data) {
2990
3048
  var _a, _b, _c, _d;
3049
+ const logger = this.logger.with('create');
2991
3050
  const instance = this.model.toInstance(data);
2992
3051
  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 }));
2993
3052
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
2994
- const docRef = await this.save(builded);
2995
- const doc = (await docRef.get()).data();
2996
- 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;
2997
- return docBuilded;
3053
+ const req = { collection: this.buildCollectionPathForAdd(builded), data };
3054
+ try {
3055
+ const docRef = await this.save(builded);
3056
+ const doc = (await docRef.get()).data();
3057
+ 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;
3058
+ logger.log({ req, res: docBuilded });
3059
+ return docBuilded;
3060
+ }
3061
+ catch (error) {
3062
+ if (error instanceof Error)
3063
+ logger.log({ req, res: error, stack: error.stack });
3064
+ throw error;
3065
+ }
2998
3066
  }
2999
3067
  async save(data) {
3000
3068
  const collectionPath = this.buildCollectionPathForAdd(data);
@@ -3034,15 +3102,28 @@ const withUpdateFirestore = (MixinBase) => {
3034
3102
  return class UpdateFirestore extends MixinBase {
3035
3103
  async update(data) {
3036
3104
  var _a, _b, _c, _d;
3105
+ const logger = this.logger.with('update');
3106
+ const collectionName = this.buildCollectionPathForUpdate(data);
3037
3107
  const model = new this.model();
3038
3108
  const keyField = model.identifiersFields.shift();
3039
- const docRef = this.collection(this.buildCollectionPathForUpdate(data)).getDoc(getValueFromParams(data, keyField).toString());
3040
- const plainFromData = this.model.toInstance(this.paramsToPlain(data));
3041
- 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 }));
3042
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
3043
- await docRef.save(builded.toPlain());
3044
- const docData = await docRef.get();
3045
- 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();
3109
+ const req = { collection: collectionName, data };
3110
+ try {
3111
+ const identifiers = getValueFromParams(data, keyField);
3112
+ const docRef = this.collection().getDoc(identifiers.toString());
3113
+ const plainFromData = this.model.toInstance(this.paramsToPlain(data));
3114
+ 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 }));
3115
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
3116
+ await docRef.save(builded.toPlain());
3117
+ const docData = await docRef.get();
3118
+ 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();
3119
+ logger.log({ req, res, identifiers });
3120
+ return res;
3121
+ }
3122
+ catch (error) {
3123
+ if (error instanceof Error)
3124
+ logger.log({ req, res: error, stack: error.stack });
3125
+ throw error;
3126
+ }
3046
3127
  }
3047
3128
  buildCollectionPathForUpdate(identifiers) {
3048
3129
  return this.isSubCollection(this)
@@ -3062,13 +3143,22 @@ const withDeleteFirestore = (MixinBase) => {
3062
3143
  return class DeleteFirestore extends MixinBase {
3063
3144
  async delete(identifiers) {
3064
3145
  var _a, _b, _c, _d;
3146
+ const logger = this.logger.with('delete');
3147
+ const collectionName = this.buildCollectionPathForRemove(identifiers);
3065
3148
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
3066
- 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 }));
3067
- const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3068
- await this.collection(this.buildCollectionPathForRemove(identifiers))
3069
- .getDoc(Object.values(builded.identifier).shift().toString())
3070
- .delete();
3071
- await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
3149
+ const req = { collection: collectionName, data: identifiers };
3150
+ try {
3151
+ 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 }));
3152
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3153
+ await this.collection(collectionName).getDoc(Object.values(builded.identifier).shift().toString()).delete();
3154
+ await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
3155
+ logger.log({ req, res: undefined });
3156
+ }
3157
+ catch (error) {
3158
+ if (error instanceof Error)
3159
+ logger.log({ req, res: error, stack: error.stack });
3160
+ throw error;
3161
+ }
3072
3162
  }
3073
3163
  buildCollectionPathForRemove(identifiers) {
3074
3164
  return this.isSubCollection(this)
@@ -3243,7 +3333,19 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
3243
3333
  fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3244
3334
  };
3245
3335
  }
3246
- }
3336
+ }
3337
+ tslib_1.__decorate([
3338
+ Log(),
3339
+ tslib_1.__metadata("design:type", Function),
3340
+ tslib_1.__metadata("design:paramtypes", [Object]),
3341
+ tslib_1.__metadata("design:returntype", Promise)
3342
+ ], UserFirestoreRepository.prototype, "get", null);
3343
+ tslib_1.__decorate([
3344
+ Log(),
3345
+ tslib_1.__metadata("design:type", Function),
3346
+ tslib_1.__metadata("design:paramtypes", [String, String]),
3347
+ tslib_1.__metadata("design:returntype", Promise)
3348
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3247
3349
 
3248
3350
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3249
3351
  constructor({ firestore, interceptors }, parentRepository) {
@@ -3327,7 +3429,25 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3327
3429
  isChild(id, parentId) {
3328
3430
  return;
3329
3431
  }
3330
- }
3432
+ }
3433
+ tslib_1.__decorate([
3434
+ Log(),
3435
+ tslib_1.__metadata("design:type", Function),
3436
+ tslib_1.__metadata("design:paramtypes", [String, String]),
3437
+ tslib_1.__metadata("design:returntype", Promise)
3438
+ ], CategoryFirestoreRepository.prototype, "getCategoryBySlug", null);
3439
+ tslib_1.__decorate([
3440
+ Log(),
3441
+ tslib_1.__metadata("design:type", Function),
3442
+ tslib_1.__metadata("design:paramtypes", [Array, Object, String]),
3443
+ tslib_1.__metadata("design:returntype", Promise)
3444
+ ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3445
+ tslib_1.__decorate([
3446
+ Log(),
3447
+ tslib_1.__metadata("design:type", Function),
3448
+ tslib_1.__metadata("design:paramtypes", [Category, Object]),
3449
+ tslib_1.__metadata("design:returntype", Promise)
3450
+ ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3331
3451
 
3332
3452
  class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3333
3453
  constructor({ firestore, interceptors }) {
@@ -3386,7 +3506,19 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
3386
3506
  async fetchPaginatedReviews() {
3387
3507
  return Promise.resolve([]);
3388
3508
  }
3389
- }
3509
+ }
3510
+ tslib_1.__decorate([
3511
+ Log(),
3512
+ tslib_1.__metadata("design:type", Function),
3513
+ tslib_1.__metadata("design:paramtypes", [String]),
3514
+ tslib_1.__metadata("design:returntype", Promise)
3515
+ ], ProductFirestoreRepository.prototype, "getBySlug", null);
3516
+ tslib_1.__decorate([
3517
+ Log(),
3518
+ tslib_1.__metadata("design:type", Function),
3519
+ tslib_1.__metadata("design:paramtypes", [String]),
3520
+ tslib_1.__metadata("design:returntype", Promise)
3521
+ ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3390
3522
 
3391
3523
  class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3392
3524
  constructor({ firestore, interceptors }, parentRepository) {
@@ -4185,18 +4317,20 @@ const withHasuraGraphQL = (MixinBase) => {
4185
4317
  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;
4186
4318
  }
4187
4319
  async fetch(params) {
4188
- this.logger.with('params').log(params);
4189
4320
  const headers = this.headers;
4190
- const { data: result } = await axios__default["default"]({
4321
+ const request = {
4191
4322
  url: `${this.endpoint}`,
4192
4323
  method: 'POST',
4193
4324
  data: params,
4194
4325
  headers,
4195
- });
4196
- if (!lodash.isNil(result.errors))
4197
- throw new Error(JSON.stringify(result.errors));
4198
- this.logger.with('returns').log(result);
4199
- return result.data;
4326
+ };
4327
+ const response = await axios__default["default"](request);
4328
+ if (!lodash.isNil(response.data.errors)) {
4329
+ this.logger.error({ req: request, res: response.data.errors });
4330
+ throw new Error(response.data.errors);
4331
+ }
4332
+ this.logger.log({ req: request, res: response.data });
4333
+ return response.data.data;
4200
4334
  }
4201
4335
  getAttributeGraphQLTypeOf(value) {
4202
4336
  if (isUUID(value))
@@ -4643,7 +4777,19 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
4643
4777
  },
4644
4778
  });
4645
4779
  }
4646
- }
4780
+ }
4781
+ tslib_1.__decorate([
4782
+ Log(),
4783
+ tslib_1.__metadata("design:type", Function),
4784
+ tslib_1.__metadata("design:paramtypes", [Number]),
4785
+ tslib_1.__metadata("design:returntype", Promise)
4786
+ ], CategoryFilterHasuraGraphQLRepository.prototype, "deleteByCategory", null);
4787
+ tslib_1.__decorate([
4788
+ Log(),
4789
+ tslib_1.__metadata("design:type", Function),
4790
+ tslib_1.__metadata("design:paramtypes", [Number, Number]),
4791
+ tslib_1.__metadata("design:returntype", Promise)
4792
+ ], CategoryFilterHasuraGraphQLRepository.prototype, "deleteByCategoryAndFilter", null);
4647
4793
 
4648
4794
  class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
4649
4795
  constructor({ endpoint, authOptions, interceptors, }, productRepository, categoryFilterRepository) {
@@ -4849,6 +4995,20 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4849
4995
  products.push(...productsData);
4850
4996
  return products;
4851
4997
  }
4998
+ async getChildren(parentId) {
4999
+ const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference'], {
5000
+ args: {
5001
+ type: 'category_tree_args',
5002
+ value: { parentid: parentId },
5003
+ required: true,
5004
+ },
5005
+ });
5006
+ return category_tree.map((category) => Category.toInstance(category));
5007
+ }
5008
+ async isChild(id, parentId) {
5009
+ const categoryTree = await this.getChildren(parentId);
5010
+ return categoryTree.some((c) => c.id == id.toString());
5011
+ }
4852
5012
  async getId(id) {
4853
5013
  var _a, _b;
4854
5014
  if (!Number.isNaN(+id))
@@ -4978,21 +5138,43 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4978
5138
  return filters;
4979
5139
  }
4980
5140
  }
4981
- async getChildren(parentId) {
4982
- const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference'], {
4983
- args: {
4984
- type: 'category_tree_args',
4985
- value: { parentid: parentId },
4986
- required: true,
4987
- },
4988
- });
4989
- return category_tree.map((category) => Category.toInstance(category));
4990
- }
4991
- async isChild(id, parentId) {
4992
- const categoryTree = await this.getChildren(parentId);
4993
- return categoryTree.some((c) => c.id == id.toString());
4994
- }
4995
- }
5141
+ }
5142
+ tslib_1.__decorate([
5143
+ Log(),
5144
+ tslib_1.__metadata("design:type", Function),
5145
+ tslib_1.__metadata("design:paramtypes", [String, String]),
5146
+ tslib_1.__metadata("design:returntype", Promise)
5147
+ ], CategoryHasuraGraphQLRepository.prototype, "getCategoryBySlug", null);
5148
+ tslib_1.__decorate([
5149
+ Log(),
5150
+ tslib_1.__metadata("design:type", Function),
5151
+ tslib_1.__metadata("design:paramtypes", [String]),
5152
+ tslib_1.__metadata("design:returntype", Promise)
5153
+ ], CategoryHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5154
+ tslib_1.__decorate([
5155
+ Log(),
5156
+ tslib_1.__metadata("design:type", Function),
5157
+ tslib_1.__metadata("design:paramtypes", [Array, Object, String]),
5158
+ tslib_1.__metadata("design:returntype", Promise)
5159
+ ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5160
+ tslib_1.__decorate([
5161
+ Log(),
5162
+ tslib_1.__metadata("design:type", Function),
5163
+ tslib_1.__metadata("design:paramtypes", [Category, Object]),
5164
+ tslib_1.__metadata("design:returntype", Promise)
5165
+ ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5166
+ tslib_1.__decorate([
5167
+ Log(),
5168
+ tslib_1.__metadata("design:type", Function),
5169
+ tslib_1.__metadata("design:paramtypes", [Number]),
5170
+ tslib_1.__metadata("design:returntype", Promise)
5171
+ ], CategoryHasuraGraphQLRepository.prototype, "getChildren", null);
5172
+ tslib_1.__decorate([
5173
+ Log(),
5174
+ tslib_1.__metadata("design:type", Function),
5175
+ tslib_1.__metadata("design:paramtypes", [Number, Number]),
5176
+ tslib_1.__metadata("design:returntype", Promise)
5177
+ ], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
4996
5178
 
4997
5179
  class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
4998
5180
  constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
@@ -5094,7 +5276,19 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
5094
5276
  },
5095
5277
  });
5096
5278
  }
5097
- }
5279
+ }
5280
+ tslib_1.__decorate([
5281
+ Log(),
5282
+ tslib_1.__metadata("design:type", Function),
5283
+ tslib_1.__metadata("design:paramtypes", [Number, Object]),
5284
+ tslib_1.__metadata("design:returntype", Promise)
5285
+ ], FilterHasuraGraphQLRepository.prototype, "updateOptions", null);
5286
+ tslib_1.__decorate([
5287
+ Log(),
5288
+ tslib_1.__metadata("design:type", Function),
5289
+ tslib_1.__metadata("design:paramtypes", [Number]),
5290
+ tslib_1.__metadata("design:returntype", Promise)
5291
+ ], FilterHasuraGraphQLRepository.prototype, "deleteOptions", null);
5098
5292
 
5099
5293
  class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5100
5294
  constructor({ endpoint, authOptions, interceptors, }) {
@@ -5404,9 +5598,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5404
5598
  ...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: this.getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
5405
5599
  ], []);
5406
5600
  }
5407
- getReviewStatus(review) {
5408
- return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
5409
- }
5410
5601
  async fetchReviews(status) {
5411
5602
  const reviewsExpression = {
5412
5603
  status: status === 'pending'
@@ -5428,6 +5619,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5428
5619
  async findCatalog(params, mainGender) {
5429
5620
  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' })), lodash.omit(params.orderBy, ['hasStock', 'intGender'])) }));
5430
5621
  }
5622
+ async cleanShoppingCountFromIds(ids) {
5623
+ return await this.mutation('update_product', ['affected_rows'], {
5624
+ where: {
5625
+ value: { id: { _nin: ids } },
5626
+ type: 'product_bool_exp',
5627
+ required: true,
5628
+ },
5629
+ _set: {
5630
+ value: { shopping_count: 0 },
5631
+ type: 'product_set_input',
5632
+ },
5633
+ });
5634
+ }
5635
+ getReviewStatus(review) {
5636
+ return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
5637
+ }
5431
5638
  async updateCategories(productId, { categories }) {
5432
5639
  if ('action' in categories && categories.action === 'remove') {
5433
5640
  await this.mutation('delete_category_product', ['affected_rows'], {
@@ -5595,20 +5802,37 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5595
5802
  });
5596
5803
  return data && data[0] && this.bindReviewToModel(data[0]);
5597
5804
  }
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
- }
5805
+ }
5806
+ tslib_1.__decorate([
5807
+ Log(),
5808
+ tslib_1.__metadata("design:type", Function),
5809
+ tslib_1.__metadata("design:paramtypes", [String]),
5810
+ tslib_1.__metadata("design:returntype", Promise)
5811
+ ], ProductHasuraGraphQLRepository.prototype, "getBySlug", null);
5812
+ tslib_1.__decorate([
5813
+ Log(),
5814
+ tslib_1.__metadata("design:type", Function),
5815
+ tslib_1.__metadata("design:paramtypes", []),
5816
+ tslib_1.__metadata("design:returntype", Promise)
5817
+ ], ProductHasuraGraphQLRepository.prototype, "fetchProductReviews", null);
5818
+ tslib_1.__decorate([
5819
+ Log(),
5820
+ tslib_1.__metadata("design:type", Function),
5821
+ tslib_1.__metadata("design:paramtypes", [String]),
5822
+ tslib_1.__metadata("design:returntype", Promise)
5823
+ ], ProductHasuraGraphQLRepository.prototype, "fetchReviews", null);
5824
+ tslib_1.__decorate([
5825
+ Log(),
5826
+ tslib_1.__metadata("design:type", Function),
5827
+ tslib_1.__metadata("design:paramtypes", [Object, Object]),
5828
+ tslib_1.__metadata("design:returntype", Promise)
5829
+ ], ProductHasuraGraphQLRepository.prototype, "findCatalog", null);
5830
+ tslib_1.__decorate([
5831
+ Log(),
5832
+ tslib_1.__metadata("design:type", Function),
5833
+ tslib_1.__metadata("design:paramtypes", [Array]),
5834
+ tslib_1.__metadata("design:returntype", Promise)
5835
+ ], ProductHasuraGraphQLRepository.prototype, "cleanShoppingCountFromIds", null);
5612
5836
 
5613
5837
  class ProductReviewsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5614
5838
  constructor({ endpoint, authOptions, interceptors, }) {
@@ -5643,7 +5867,19 @@ class ProductReviewsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
5643
5867
  disaproveReview(id) {
5644
5868
  return this.update({ id, status: false });
5645
5869
  }
5646
- }
5870
+ }
5871
+ tslib_1.__decorate([
5872
+ Log(),
5873
+ tslib_1.__metadata("design:type", Function),
5874
+ tslib_1.__metadata("design:paramtypes", [Number]),
5875
+ tslib_1.__metadata("design:returntype", void 0)
5876
+ ], ProductReviewsHasuraGraphQLRepository.prototype, "aproveReview", null);
5877
+ tslib_1.__decorate([
5878
+ Log(),
5879
+ tslib_1.__metadata("design:type", Function),
5880
+ tslib_1.__metadata("design:paramtypes", [Number]),
5881
+ tslib_1.__metadata("design:returntype", void 0)
5882
+ ], ProductReviewsHasuraGraphQLRepository.prototype, "disaproveReview", null);
5647
5883
 
5648
5884
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5649
5885
  constructor({ endpoint, authOptions, interceptors, }) {
@@ -5893,6 +6129,36 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5893
6129
  throw new NotFoundError(`Wishlists from person ${personId} not found`);
5894
6130
  return data;
5895
6131
  }
6132
+ getCategoryBySlug(slug, _shop) {
6133
+ return this.getWishlistBySlug(slug);
6134
+ }
6135
+ async getCategoryByShop(shop) {
6136
+ if (!shop)
6137
+ return;
6138
+ const { data } = await this.find({
6139
+ filters: {
6140
+ shops: { operator: exports.Where.IN, value: [shop] },
6141
+ published: { operator: exports.Where.EQUALS, value: true },
6142
+ isWishlist: { operator: exports.Where.EQUALS, value: true },
6143
+ },
6144
+ options: {
6145
+ enableCount: false,
6146
+ },
6147
+ });
6148
+ return data;
6149
+ }
6150
+ getCategoriesForHome(categoryIds, limit, gender) {
6151
+ return;
6152
+ }
6153
+ mountCategory(category, options) {
6154
+ return;
6155
+ }
6156
+ getChildren(parentId) {
6157
+ return;
6158
+ }
6159
+ isChild(id, parentId) {
6160
+ return;
6161
+ }
5896
6162
  async updateProducts(categoryId, { products }) {
5897
6163
  if ('action' in products && products.action === 'remove') {
5898
6164
  await this.mutation('delete_category_product', ['affected_rows'], {
@@ -5949,37 +6215,25 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5949
6215
  });
5950
6216
  return plainData.metadata;
5951
6217
  }
5952
- getCategoryBySlug(slug, _shop) {
5953
- return this.getWishlistBySlug(slug);
5954
- }
5955
- async getCategoryByShop(shop) {
5956
- if (!shop)
5957
- return;
5958
- const { data } = await this.find({
5959
- filters: {
5960
- shops: { operator: exports.Where.IN, value: [shop] },
5961
- published: { operator: exports.Where.EQUALS, value: true },
5962
- isWishlist: { operator: exports.Where.EQUALS, value: true },
5963
- },
5964
- options: {
5965
- enableCount: false,
5966
- },
5967
- });
5968
- return data;
5969
- }
5970
- getCategoriesForHome(categoryIds, limit, gender) {
5971
- return;
5972
- }
5973
- mountCategory(category, options) {
5974
- return;
5975
- }
5976
- getChildren(parentId) {
5977
- return;
5978
- }
5979
- isChild(id, parentId) {
5980
- return;
5981
- }
5982
- }
6218
+ }
6219
+ tslib_1.__decorate([
6220
+ Log(),
6221
+ tslib_1.__metadata("design:type", Function),
6222
+ tslib_1.__metadata("design:paramtypes", [String]),
6223
+ tslib_1.__metadata("design:returntype", Promise)
6224
+ ], WishlistHasuraGraphQLRepository.prototype, "getWishlistBySlug", null);
6225
+ tslib_1.__decorate([
6226
+ Log(),
6227
+ tslib_1.__metadata("design:type", Function),
6228
+ tslib_1.__metadata("design:paramtypes", [String]),
6229
+ tslib_1.__metadata("design:returntype", Promise)
6230
+ ], WishlistHasuraGraphQLRepository.prototype, "getWishlistByPerson", null);
6231
+ tslib_1.__decorate([
6232
+ Log(),
6233
+ tslib_1.__metadata("design:type", Function),
6234
+ tslib_1.__metadata("design:paramtypes", [String]),
6235
+ tslib_1.__metadata("design:returntype", Promise)
6236
+ ], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5983
6237
 
5984
6238
  Object.defineProperty(exports, 'add', {
5985
6239
  enumerable: true,