@infrab4a/connect 4.0.0-beta.2 → 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 (184) hide show
  1. package/domain/catalog/models/category-filter.d.ts +11 -0
  2. package/domain/catalog/models/category.d.ts +7 -2
  3. package/domain/catalog/models/filter-option.d.ts +10 -0
  4. package/domain/catalog/models/filter.d.ts +13 -0
  5. package/domain/catalog/models/index.d.ts +3 -0
  6. package/domain/catalog/models/product.d.ts +7 -1
  7. package/domain/catalog/models/types/index.d.ts +1 -1
  8. package/domain/catalog/models/types/product-evaluation.type.d.ts +6 -0
  9. package/domain/catalog/repositories/category-filter.repository.d.ts +5 -0
  10. package/domain/catalog/repositories/category.repository.d.ts +3 -3
  11. package/domain/catalog/repositories/filter-option.repository.d.ts +4 -0
  12. package/domain/catalog/repositories/filter.repository.d.ts +4 -0
  13. package/domain/catalog/repositories/index.d.ts +3 -0
  14. package/domain/catalog/repositories/product.repository.d.ts +1 -0
  15. package/domain/generic/repository/find.repository.d.ts +3 -0
  16. package/domain/shop-settings/models/index.d.ts +1 -0
  17. package/domain/shop-settings/models/shop-settings.d.ts +9 -0
  18. package/domain/shop-settings/models/types/index.d.ts +6 -1
  19. package/domain/shop-settings/models/types/shop-banner.type.d.ts +12 -0
  20. package/domain/shop-settings/models/types/shop-brands.type.d.ts +10 -0
  21. package/domain/shop-settings/models/types/shop-carousel.type.d.ts +5 -0
  22. package/domain/shop-settings/models/types/shop-collection.type.d.ts +9 -0
  23. package/domain/shop-settings/models/types/shop-section.type.d.ts +9 -0
  24. package/domain/shop-settings/repositories/index.d.ts +1 -0
  25. package/domain/shop-settings/repositories/shop-settings.repository.d.ts +4 -0
  26. package/domain/shopping/models/buy-2-win.d.ts +3 -1
  27. package/domain/shopping/models/campaign-dashboard.d.ts +15 -0
  28. package/domain/shopping/models/campaign-hashtag.d.ts +18 -0
  29. package/domain/shopping/models/index.d.ts +5 -4
  30. package/domain/shopping/repositories/campaign-dashboard.repository.d.ts +4 -0
  31. package/domain/shopping/repositories/campaign-hashtag.repository.d.ts +4 -0
  32. package/domain/shopping/repositories/index.d.ts +4 -2
  33. package/domain/users/models/lead.d.ts +1 -0
  34. package/esm2020/domain/catalog/models/category-filter.mjs +14 -0
  35. package/esm2020/domain/catalog/models/category.mjs +12 -1
  36. package/esm2020/domain/catalog/models/filter-option.mjs +10 -0
  37. package/esm2020/domain/catalog/models/filter.mjs +10 -0
  38. package/esm2020/domain/catalog/models/index.mjs +4 -1
  39. package/esm2020/domain/catalog/models/product.mjs +24 -1
  40. package/esm2020/domain/catalog/models/types/index.mjs +2 -2
  41. package/esm2020/domain/catalog/models/types/product-evaluation.type.mjs +2 -0
  42. package/esm2020/domain/catalog/repositories/category-filter.repository.mjs +2 -0
  43. package/esm2020/domain/catalog/repositories/category.repository.mjs +1 -1
  44. package/esm2020/domain/catalog/repositories/filter-option.repository.mjs +2 -0
  45. package/esm2020/domain/catalog/repositories/filter.repository.mjs +2 -0
  46. package/esm2020/domain/catalog/repositories/index.mjs +4 -1
  47. package/esm2020/domain/catalog/repositories/product.repository.mjs +1 -1
  48. package/esm2020/domain/generic/repository/find.repository.mjs +1 -1
  49. package/esm2020/domain/shop-settings/models/index.mjs +2 -1
  50. package/esm2020/domain/shop-settings/models/shop-settings.mjs +7 -0
  51. package/esm2020/domain/shop-settings/models/types/index.mjs +7 -2
  52. package/esm2020/domain/shop-settings/models/types/shop-banner.type.mjs +2 -0
  53. package/esm2020/domain/shop-settings/models/types/shop-brands.type.mjs +2 -0
  54. package/esm2020/domain/shop-settings/models/types/shop-carousel.type.mjs +2 -0
  55. package/esm2020/domain/shop-settings/models/types/shop-collection.type.mjs +2 -0
  56. package/esm2020/domain/shop-settings/models/types/shop-section.type.mjs +2 -0
  57. package/esm2020/domain/shop-settings/repositories/index.mjs +2 -1
  58. package/esm2020/domain/shop-settings/repositories/shop-settings.repository.mjs +2 -0
  59. package/esm2020/domain/shopping/models/buy-2-win.mjs +2 -2
  60. package/esm2020/domain/shopping/models/campaign-dashboard.mjs +7 -0
  61. package/esm2020/domain/shopping/models/campaign-hashtag.mjs +7 -0
  62. package/esm2020/domain/shopping/models/index.mjs +6 -5
  63. package/esm2020/domain/shopping/repositories/campaign-dashboard.repository.mjs +2 -0
  64. package/esm2020/domain/shopping/repositories/campaign-hashtag.repository.mjs +2 -0
  65. package/esm2020/domain/shopping/repositories/index.mjs +5 -3
  66. package/esm2020/domain/users/models/lead.mjs +1 -1
  67. package/esm2020/domain/users/models/subscription/edition.mjs +1 -1
  68. package/esm2020/domain/users/models/subscription/payment.mjs +1 -1
  69. package/esm2020/domain/users/models/user-payment-method.mjs +1 -1
  70. package/esm2020/infra/elasticsearch/adapters/axios.adapter.mjs +28 -11
  71. package/esm2020/infra/elasticsearch/adapters/elastic-search.adapter.mjs +1 -1
  72. package/esm2020/infra/elasticsearch/indexes/products-index.mjs +58 -51
  73. package/esm2020/infra/elasticsearch/types/elastic-search-result.mjs +1 -1
  74. package/esm2020/infra/firebase/firestore/mixins/with-create-firestore.mixin.mjs +7 -3
  75. package/esm2020/infra/firebase/firestore/mixins/with-crud-firestore.mixin.mjs +1 -1
  76. package/esm2020/infra/firebase/firestore/mixins/with-delete-firestore.mixin.mjs +6 -2
  77. package/esm2020/infra/firebase/firestore/mixins/with-find-firestore.mixin.mjs +9 -6
  78. package/esm2020/infra/firebase/firestore/mixins/with-firestore.mixin.mjs +11 -3
  79. package/esm2020/infra/firebase/firestore/mixins/with-get-firestore.mixin.mjs +6 -3
  80. package/esm2020/infra/firebase/firestore/mixins/with-sub-collection.mixin.mjs +5 -3
  81. package/esm2020/infra/firebase/firestore/mixins/with-update-firestore.mixin.mjs +7 -4
  82. package/esm2020/infra/firebase/firestore/repositories/catalog/category-firestore.repository.mjs +12 -8
  83. package/esm2020/infra/firebase/firestore/repositories/catalog/product-firestore.repository.mjs +11 -6
  84. package/esm2020/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.mjs +10 -8
  85. package/esm2020/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.mjs +8 -6
  86. package/esm2020/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.mjs +8 -6
  87. package/esm2020/infra/firebase/firestore/repositories/shop-settings/index.mjs +2 -1
  88. package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.mjs +8 -6
  89. package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.mjs +14 -0
  90. package/esm2020/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.mjs +8 -6
  91. package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.mjs +14 -0
  92. package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.mjs +14 -0
  93. package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.mjs +8 -6
  94. package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.mjs +8 -6
  95. package/esm2020/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.mjs +8 -6
  96. package/esm2020/infra/firebase/firestore/repositories/shopping/index.mjs +6 -4
  97. package/esm2020/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.mjs +6 -4
  98. package/esm2020/infra/firebase/firestore/repositories/shopping/order-firestore.repository.mjs +11 -9
  99. package/esm2020/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.mjs +8 -6
  100. package/esm2020/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.mjs +8 -6
  101. package/esm2020/infra/firebase/firestore/repositories/users/lead-firestore.repository.mjs +8 -6
  102. package/esm2020/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.mjs +10 -8
  103. package/esm2020/infra/firebase/firestore/repositories/users/subscription-firestore.repository.mjs +8 -6
  104. package/esm2020/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.mjs +10 -8
  105. package/esm2020/infra/firebase/firestore/repositories/users/user-address-firestore.repository.mjs +10 -8
  106. package/esm2020/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.mjs +10 -8
  107. package/esm2020/infra/firebase/firestore/repositories/users/user-firestore.repository.mjs +8 -6
  108. package/esm2020/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.mjs +10 -8
  109. package/esm2020/infra/firebase/firestore/types/firestore-interceptors.type.mjs +2 -0
  110. package/esm2020/infra/firebase/firestore/types/firestore.repository.type.mjs +1 -1
  111. package/esm2020/infra/firebase/firestore/types/index.mjs +4 -3
  112. package/esm2020/infra/hasura-graphql/mixins/helpers/attribute-option.helper.mjs +2 -2
  113. package/esm2020/infra/hasura-graphql/mixins/helpers/graphql-field.helper.mjs +12 -6
  114. package/esm2020/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.mjs +2 -2
  115. package/esm2020/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.mjs +1 -1
  116. package/esm2020/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.mjs +16 -12
  117. package/esm2020/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.mjs +30 -21
  118. package/esm2020/infra/hasura-graphql/models/product-hasura-graphql.mjs +1 -1
  119. package/esm2020/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.mjs +56 -0
  120. package/esm2020/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.mjs +106 -12
  121. package/esm2020/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.mjs +105 -0
  122. package/esm2020/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.mjs +22 -0
  123. package/esm2020/infra/hasura-graphql/repositories/catalog/index.mjs +4 -1
  124. package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +41 -15
  125. package/esm2020/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.mjs +8 -7
  126. package/esm2020/infra/hasura-graphql/types/hasura-graphql-fields.type.mjs +1 -1
  127. package/esm2020/utils/index.mjs +2 -3
  128. package/fesm2015/infrab4a-connect.mjs +846 -298
  129. package/fesm2015/infrab4a-connect.mjs.map +1 -1
  130. package/fesm2020/infrab4a-connect.mjs +823 -303
  131. package/fesm2020/infrab4a-connect.mjs.map +1 -1
  132. package/infra/elasticsearch/adapters/axios.adapter.d.ts +6 -4
  133. package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +3 -2
  134. package/infra/elasticsearch/indexes/products-index.d.ts +8 -10
  135. package/infra/elasticsearch/types/elastic-search-result.d.ts +2 -0
  136. package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +2 -1
  137. package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +13 -4
  138. package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +6 -2
  139. package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +5 -5
  140. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +4 -4
  141. package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +3 -4
  142. package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +3 -4
  143. package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +4 -4
  144. package/infra/firebase/firestore/repositories/shop-settings/index.d.ts +1 -0
  145. package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +3 -4
  146. package/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +7 -0
  147. package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +3 -4
  148. package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +8 -0
  149. package/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +8 -0
  150. package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +3 -4
  151. package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +3 -4
  152. package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +4 -4
  153. package/infra/firebase/firestore/repositories/shopping/index.d.ts +5 -3
  154. package/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +3 -4
  155. package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +4 -4
  156. package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +3 -4
  157. package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +3 -4
  158. package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +3 -4
  159. package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +3 -4
  160. package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +3 -4
  161. package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +3 -4
  162. package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +3 -4
  163. package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +3 -4
  164. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +4 -4
  165. package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +3 -4
  166. package/infra/firebase/firestore/types/firestore-interceptors.type.d.ts +14 -0
  167. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +2 -0
  168. package/infra/firebase/firestore/types/index.d.ts +3 -2
  169. package/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.d.ts +2 -2
  170. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +4 -9
  171. package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +14 -3
  172. package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +1 -0
  173. package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +11 -0
  174. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +9 -5
  175. package/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +18 -0
  176. package/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +10 -0
  177. package/infra/hasura-graphql/repositories/catalog/index.d.ts +3 -0
  178. package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +4 -3
  179. package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +4 -4
  180. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
  181. package/package.json +1 -2
  182. package/utils/index.d.ts +1 -21
  183. package/domain/catalog/models/types/category-filter.type.d.ts +0 -4
  184. package/esm2020/domain/catalog/models/types/category-filter.type.mjs +0 -2
@@ -3,14 +3,13 @@ import { plainToInstance, instanceToPlain, Expose, Type } from 'class-transforme
3
3
  import { __decorate, __metadata, __awaiter, __rest } from 'tslib';
4
4
  import { parseISO } from 'date-fns';
5
5
  export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
6
- import * as lodash from 'lodash';
7
- import { get as get$1, isString as isString$1 } from 'lodash';
6
+ import { get as get$1, isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
7
+ export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
8
8
  import { CustomError } from 'ts-custom-error';
9
9
  import axios from 'axios';
10
10
  import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
11
11
  import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
12
12
  import { mutation, query as query$1 } from 'gql-query-builder';
13
- import fetch from 'node-fetch';
14
13
 
15
14
  class BaseModel {
16
15
  get identifier() {
@@ -473,7 +472,7 @@ function is(value) {
473
472
  return value;
474
473
  }
475
474
 
476
- const isUUID = (value) => isString$1(value) && /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value);
475
+ const isUUID = (value) => isString(value) && /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value);
477
476
 
478
477
  class Base {
479
478
  constructor(...args) {
@@ -482,7 +481,7 @@ class Base {
482
481
  }
483
482
 
484
483
  const parseDateTime = (value) => {
485
- if (!isString$1(value))
484
+ if (!isString(value))
486
485
  return value;
487
486
  if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(value) &&
488
487
  !/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T\d{2}:\d{2}:\d{2}/.test(value))
@@ -493,8 +492,6 @@ const parseDateTime = (value) => {
493
492
  return date;
494
493
  };
495
494
 
496
- const { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN: isNaN$1, isNil, isNumber, isObject, isString, now, omit, pick, set, } = lodash;
497
-
498
495
  var CheckoutTypes;
499
496
  (function (CheckoutTypes) {
500
497
  CheckoutTypes[CheckoutTypes["ECOMMERCE"] = 1] = "ECOMMERCE";
@@ -757,6 +754,15 @@ class RecoveryPassword {
757
754
  }
758
755
  }
759
756
 
757
+ class Filter extends BaseModel {
758
+ identifierFields() {
759
+ return ['id'];
760
+ }
761
+ static get identifiersFields() {
762
+ return ['id'];
763
+ }
764
+ }
765
+
760
766
  class Category extends BaseModel {
761
767
  identifierFields() {
762
768
  return ['id'];
@@ -765,6 +771,24 @@ class Category extends BaseModel {
765
771
  return ['id'];
766
772
  }
767
773
  }
774
+ __decorate([
775
+ Type(() => Category),
776
+ __metadata("design:type", Category)
777
+ ], Category.prototype, "parent", void 0);
778
+ __decorate([
779
+ Type(() => Filter),
780
+ __metadata("design:type", Array)
781
+ ], Category.prototype, "filters", void 0);
782
+
783
+ class CategoryFilter extends BaseModel {
784
+ static get identifiersFields() {
785
+ return ['id'];
786
+ }
787
+ }
788
+ __decorate([
789
+ Type(() => Filter),
790
+ __metadata("design:type", Filter)
791
+ ], CategoryFilter.prototype, "filter", void 0);
768
792
 
769
793
  var GenderDestination;
770
794
  (function (GenderDestination) {
@@ -781,7 +805,34 @@ var Shops;
781
805
  Shops["ALL"] = "ALL";
782
806
  })(Shops || (Shops = {}));
783
807
 
808
+ class FilterOption extends BaseModel {
809
+ identifierFields() {
810
+ return ['id'];
811
+ }
812
+ static get identifiersFields() {
813
+ return ['id'];
814
+ }
815
+ }
816
+
784
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
+ }
785
836
  identifierFields() {
786
837
  return ['id'];
787
838
  }
@@ -789,6 +840,10 @@ class Product extends BaseModel {
789
840
  return ['id'];
790
841
  }
791
842
  }
843
+ __decorate([
844
+ Type(() => Category),
845
+ __metadata("design:type", Category)
846
+ ], Product.prototype, "category", void 0);
792
847
  __decorate([
793
848
  Type(() => KitProduct),
794
849
  __metadata("design:type", Array)
@@ -817,17 +872,27 @@ class Variant extends BaseModel {
817
872
  }
818
873
  }
819
874
 
820
- var OrderStatus;
821
- (function (OrderStatus) {
822
- OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
823
- OrderStatus["EM_PREPARO"] = "Preparando pedido";
824
- OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
825
- OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
826
- OrderStatus["ENVIADO"] = "Enviado";
827
- OrderStatus["ENTREGUE"] = "Entregue";
828
- OrderStatus["CANCELADO"] = "Cancelado";
829
- OrderStatus["CREDIT_CARD"] = "credit_card";
830
- })(OrderStatus || (OrderStatus = {}));
875
+ class Buy2Win extends BaseModel {
876
+ static get identifiersFields() {
877
+ return ['id'];
878
+ }
879
+ }
880
+ __decorate([
881
+ Type(() => Category),
882
+ __metadata("design:type", Array)
883
+ ], Buy2Win.prototype, "categories", void 0);
884
+
885
+ class CampaignDashboard extends BaseModel {
886
+ static get identifiersFields() {
887
+ return ['id'];
888
+ }
889
+ }
890
+
891
+ class CampaignHashtag extends BaseModel {
892
+ static get identifiersFields() {
893
+ return ['id'];
894
+ }
895
+ }
831
896
 
832
897
  class LineItem extends Product {
833
898
  }
@@ -868,6 +933,18 @@ __decorate([
868
933
  __metadata("design:type", Coupon)
869
934
  ], Checkout.prototype, "coupon", void 0);
870
935
 
936
+ var OrderStatus;
937
+ (function (OrderStatus) {
938
+ OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
939
+ OrderStatus["EM_PREPARO"] = "Preparando pedido";
940
+ OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
941
+ OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
942
+ OrderStatus["ENVIADO"] = "Enviado";
943
+ OrderStatus["ENTREGUE"] = "Entregue";
944
+ OrderStatus["CANCELADO"] = "Cancelado";
945
+ OrderStatus["CREDIT_CARD"] = "credit_card";
946
+ })(OrderStatus || (OrderStatus = {}));
947
+
871
948
  class Order extends Checkout {
872
949
  }
873
950
  __decorate([
@@ -897,16 +974,6 @@ __decorate([
897
974
  __metadata("design:type", Coupon)
898
975
  ], CheckoutSubscription.prototype, "coupon", void 0);
899
976
 
900
- class Buy2Win extends BaseModel {
901
- static get identifiersFields() {
902
- return ['id'];
903
- }
904
- }
905
- __decorate([
906
- Type(() => Category),
907
- __metadata("design:type", Array)
908
- ], Buy2Win.prototype, "categories", void 0);
909
-
910
977
  var FilterType;
911
978
  (function (FilterType) {
912
979
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -1006,6 +1073,12 @@ class ShopMenu extends BaseModel {
1006
1073
  }
1007
1074
  }
1008
1075
 
1076
+ class ShopSettings extends BaseModel {
1077
+ static get identifiersFields() {
1078
+ return ['id'];
1079
+ }
1080
+ }
1081
+
1009
1082
  class InvalidArgumentError extends CustomError {
1010
1083
  constructor(message) {
1011
1084
  super(message);
@@ -1036,13 +1109,17 @@ class AxiosAdapter {
1036
1109
  constructor(config) {
1037
1110
  this.config = config;
1038
1111
  }
1039
- get(index) {
1112
+ get(index, id) {
1040
1113
  return __awaiter(this, void 0, void 0, function* () {
1041
1114
  try {
1042
1115
  const { data } = yield axios({
1043
- url: `${this.config.url}/${index}`,
1116
+ url: `${this.config.url}/${index}/_doc/${id}`,
1044
1117
  method: 'GET',
1045
- headers: { Authorization: `Basic ${this.config.credential}` },
1118
+ responseType: 'json',
1119
+ headers: {
1120
+ 'Content-Type': 'application/json',
1121
+ Authorization: `ApiKey ${this.config.credential}`,
1122
+ },
1046
1123
  });
1047
1124
  return data._source;
1048
1125
  }
@@ -1056,9 +1133,14 @@ class AxiosAdapter {
1056
1133
  query(index, query) {
1057
1134
  return __awaiter(this, void 0, void 0, function* () {
1058
1135
  const { data } = yield axios({
1059
- url: `${this.config.url}/${index}`,
1136
+ url: `${this.config.url}/${index}/_search`,
1060
1137
  method: 'POST',
1061
- 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
+ },
1062
1144
  data: query,
1063
1145
  });
1064
1146
  return {
@@ -1070,19 +1152,29 @@ class AxiosAdapter {
1070
1152
  save(index, data) {
1071
1153
  return __awaiter(this, void 0, void 0, function* () {
1072
1154
  yield axios({
1073
- 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}`,
1074
1166
  method: 'PUT',
1075
- headers: { Authorization: `Basic ${this.config.credential}` },
1167
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1076
1168
  data,
1077
1169
  });
1078
1170
  });
1079
1171
  }
1080
- delete(index) {
1172
+ delete(index, id) {
1081
1173
  return __awaiter(this, void 0, void 0, function* () {
1082
1174
  yield axios({
1083
- url: `${this.config.url}/${index}`,
1175
+ url: `${this.config.url}/${index}/_doc/${id}`,
1084
1176
  method: 'DELETE',
1085
- headers: { Authorization: `Basic ${this.config.credential}` },
1177
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1086
1178
  });
1087
1179
  });
1088
1180
  }
@@ -1091,16 +1183,19 @@ class AxiosAdapter {
1091
1183
  class ProductsIndex {
1092
1184
  constructor(adapter) {
1093
1185
  this.adapter = adapter;
1186
+ this.index = `products`;
1094
1187
  }
1095
- get(id) {
1188
+ getById(id) {
1096
1189
  return __awaiter(this, void 0, void 0, function* () {
1097
- const data = yield this.adapter.get(`products/_doc/${id}`);
1190
+ const data = yield this.adapter.get(this.index, id);
1098
1191
  return Product.toInstance(data);
1099
1192
  });
1100
1193
  }
1101
- findById(ids, options) {
1194
+ search(searchTerm, total, shop) {
1102
1195
  return __awaiter(this, void 0, void 0, function* () {
1196
+ const size = total >= 10 ? 500 : 9;
1103
1197
  const fields = [
1198
+ 'EAN',
1104
1199
  'brand',
1105
1200
  'id',
1106
1201
  'images',
@@ -1111,73 +1206,83 @@ class ProductsIndex {
1111
1206
  'stock',
1112
1207
  'slug',
1113
1208
  'reviews',
1114
- 'pricePaid',
1115
- 'isGift',
1116
- 'stock',
1117
- 'weight',
1118
- 'tags',
1119
1209
  'hasVariants',
1120
- 'type',
1210
+ 'rate',
1121
1211
  ];
1122
- 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: {
1123
1223
  bool: {
1124
- filter: [
1125
- {
1126
- terms: {
1127
- _id: ids,
1128
- },
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,
1129
1240
  },
1130
- {
1131
- term: {
1132
- published: true,
1241
+ },
1242
+ should: {
1243
+ match_phrase_prefix: {
1244
+ 'name.search': {
1245
+ query: `${searchTerm}`,
1246
+ slop: 10,
1133
1247
  },
1134
1248
  },
1135
- ...((options === null || options === void 0 ? void 0 : options.hasStock)
1136
- ? [
1137
- {
1138
- range: {
1139
- 'stock.quantity': {
1140
- gt: 0,
1141
- },
1142
- },
1143
- },
1144
- ]
1145
- : []),
1146
- ],
1249
+ },
1250
+ filter,
1147
1251
  },
1148
- } }, ((options === null || options === void 0 ? void 0 : options.size) ? { size: options === null || options === void 0 ? void 0 : options.size } : {})));
1149
- return hits.map((hit) => Product.toInstance(hit._source));
1252
+ },
1253
+ });
1254
+ search.hits = search.hits.filter((e) => e._source.name !== '');
1255
+ return search;
1150
1256
  });
1151
1257
  }
1152
1258
  save(product) {
1153
1259
  return __awaiter(this, void 0, void 0, function* () {
1154
- delete product.createdAt;
1155
- delete product.updatedAt;
1156
- delete product.kitProducts;
1157
1260
  try {
1158
- if (!product.firestoreId)
1159
- throw new Error('Is not a product from firestore');
1160
- yield this.get(product.firestoreId);
1161
- 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);
1162
1263
  }
1163
1264
  catch (error) {
1164
- if (!(error instanceof Error))
1165
- throw error;
1166
- console.error(error.message);
1167
- yield this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
1265
+ console.error(error);
1168
1266
  }
1169
1267
  });
1170
1268
  }
1171
- delete(product) {
1269
+ update(product) {
1172
1270
  return __awaiter(this, void 0, void 0, function* () {
1173
- if (!product.firestoreId)
1174
- return;
1175
1271
  try {
1176
- yield this.get(product.firestoreId);
1177
- yield this.adapter.delete(`products/_doc/${product.firestoreId}`);
1272
+ yield this.adapter.update(this.index, product.id, product);
1178
1273
  }
1179
1274
  catch (error) {
1180
- yield this.adapter.delete(`products/_doc/${product.id}`);
1275
+ console.error(error);
1276
+ }
1277
+ });
1278
+ }
1279
+ delete(id) {
1280
+ return __awaiter(this, void 0, void 0, function* () {
1281
+ try {
1282
+ yield this.adapter.delete(this.index, id);
1283
+ }
1284
+ catch (error) {
1285
+ console.error(error);
1181
1286
  }
1182
1287
  });
1183
1288
  }
@@ -1206,9 +1311,17 @@ const withFirestore = (MixinBase) => {
1206
1311
  : bindDate(data[key], key) })), {});
1207
1312
  };
1208
1313
  return class extends MixinBase {
1209
- constructor() {
1210
- super(...arguments);
1314
+ constructor(...params) {
1315
+ const options = params[0];
1316
+ super(...params);
1317
+ this.fields = {};
1318
+ this.interceptors = {};
1211
1319
  this.collectionName = '';
1320
+ this.firestore = options.firestore;
1321
+ this.collectionName = options.collectionName;
1322
+ this.model = options.model;
1323
+ this.fields = options.fields;
1324
+ this.interceptors = options.interceptors;
1212
1325
  }
1213
1326
  collection(path) {
1214
1327
  return collection(this.firestore, path || this.collectionName).withConverter(this.buildModelInstance());
@@ -1255,12 +1368,16 @@ const withHelpers = (MixinBase) => {
1255
1368
  const withGetFirestore = (MixinBase) => {
1256
1369
  return class GetFirestore extends MixinBase {
1257
1370
  get(identifiers) {
1371
+ var _a, _b, _c, _d;
1258
1372
  return __awaiter(this, void 0, void 0, function* () {
1259
- const docRef = yield getDoc(doc(yield this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(identifiers).shift().toString()));
1373
+ const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
1374
+ const intercepted = yield ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
1375
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
1376
+ const docRef = yield getDoc(doc(yield this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(builded.identifier).shift().toString()));
1260
1377
  const data = docRef.data();
1261
1378
  if (isNil(data))
1262
1379
  throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
1263
- return data;
1380
+ 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;
1264
1381
  });
1265
1382
  }
1266
1383
  buildCollectionPathForGet(identifiers) {
@@ -1339,9 +1456,13 @@ const withFindFirestore = (MixinBase) => {
1339
1456
  return Object.keys(fieldsToOrderBy).map((fieldName) => orderBy(fieldName, fieldsToOrderBy[fieldName]));
1340
1457
  };
1341
1458
  }
1342
- find({ filters, limits, orderBy, } = {}) {
1459
+ find(find = {}) {
1460
+ var _a, _b, _c, _d, _e, _f;
1343
1461
  return __awaiter(this, void 0, void 0, function* () {
1344
- const collection = this.collection(this.buildCollectionPathForFind(filters));
1462
+ const collection = this.collection(this.buildCollectionPathForFind(find.filters));
1463
+ 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;
1464
+ const intercepted = yield ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
1465
+ const { filters, limits, orderBy } = intercepted.find || find;
1345
1466
  const queries = this.makeFirestoreWhere(filters || {});
1346
1467
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
1347
1468
  const offsets = yield this.defineLimits(filters, limits);
@@ -1349,8 +1470,8 @@ const withFindFirestore = (MixinBase) => {
1349
1470
  const docs = yield getDocs(query(collection, ...queryArgumments));
1350
1471
  const data = docs.docs.map((doc) => doc.data());
1351
1472
  return {
1352
- data,
1353
- count: this.calculateCount(data, limits),
1473
+ data: (yield ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data,
1474
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
1354
1475
  };
1355
1476
  });
1356
1477
  }
@@ -1362,11 +1483,12 @@ const withFindFirestore = (MixinBase) => {
1362
1483
  return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
1363
1484
  }
1364
1485
  defineLimits(filters, limits) {
1486
+ var _a;
1365
1487
  return __awaiter(this, void 0, void 0, function* () {
1366
1488
  const queries = [];
1367
1489
  if (limits === null || limits === void 0 ? void 0 : limits.offset) {
1368
1490
  if (this.model.isModel(limits.offset))
1369
- queries.push(startAfter(yield getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), limits.offset.identifier.shift()))));
1491
+ queries.push(startAfter(yield getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), limits.offset.identifier[(_a = limits.offset.identifiersFields) === null || _a === void 0 ? void 0 : _a.shift()]))));
1370
1492
  else if (isNumber(limits.offset) || isString(limits.offset))
1371
1493
  queries.push(startAt(limits.offset));
1372
1494
  }
@@ -1388,10 +1510,15 @@ const withFindFirestore = (MixinBase) => {
1388
1510
  const withCreateFirestore = (MixinBase) => {
1389
1511
  return class CreateFirestore extends MixinBase {
1390
1512
  create(data) {
1513
+ var _a, _b, _c, _d;
1391
1514
  return __awaiter(this, void 0, void 0, function* () {
1392
- const docRef = yield this.save(this.model.toInstance(data));
1515
+ const instance = this.model.toInstance(data);
1516
+ const intercepted = yield ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
1517
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
1518
+ const docRef = yield this.save(builded);
1393
1519
  const doc = yield getDoc(docRef);
1394
- return doc.data();
1520
+ const docBuilded = (yield ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, doc.data(), intercepted))) || doc.data();
1521
+ return docBuilded;
1395
1522
  });
1396
1523
  }
1397
1524
  save(data) {
@@ -1439,13 +1566,17 @@ const withUpdateFirestore = (MixinBase) => {
1439
1566
  };
1440
1567
  return class UpdateFirestore extends MixinBase {
1441
1568
  update(data) {
1569
+ var _a, _b, _c, _d;
1442
1570
  return __awaiter(this, void 0, void 0, function* () {
1443
1571
  const model = new this.model();
1444
1572
  const keyField = model.identifiersFields.shift();
1445
1573
  const docRef = doc(this.collection(this.buildCollectionPathForUpdate(data)), getValueFromParams(data, keyField).toString());
1446
- yield setDoc(docRef, this.paramsToPlain(data), { merge: true });
1447
- const docData = yield getDoc(docRef);
1448
- return docData.data();
1574
+ const plainFromData = this.model.toInstance(this.paramsToPlain(data));
1575
+ const intercepted = yield ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
1576
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
1577
+ yield setDoc(docRef, builded.toPlain(), { merge: true });
1578
+ const docData = yield getDoc(docRef).then((doc) => doc.data());
1579
+ return ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, docData, intercepted)) || docData;
1449
1580
  });
1450
1581
  }
1451
1582
  buildCollectionPathForUpdate(identifiers) {
@@ -1465,8 +1596,13 @@ const withUpdateFirestore = (MixinBase) => {
1465
1596
  const withDeleteFirestore = (MixinBase) => {
1466
1597
  return class DeleteFirestore extends MixinBase {
1467
1598
  delete(identifiers) {
1599
+ var _a, _b, _c, _d;
1468
1600
  return __awaiter(this, void 0, void 0, function* () {
1469
- yield deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(identifiers).shift().toString()));
1601
+ const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
1602
+ const intercepted = yield ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
1603
+ const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
1604
+ yield deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(builded.identifier).shift().toString()));
1605
+ yield ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
1470
1606
  });
1471
1607
  }
1472
1608
  buildCollectionPathForRemove(identifiers) {
@@ -1479,8 +1615,10 @@ const withDeleteFirestore = (MixinBase) => {
1479
1615
 
1480
1616
  const withSubCollection = (MixinBase, ParentModel) => {
1481
1617
  return class SubCollectionMix extends MixinBase {
1482
- constructor(...args) {
1483
- super(args);
1618
+ constructor(...params) {
1619
+ const options = params[0];
1620
+ super(...params);
1621
+ this.parentIdField = options.parentIdField;
1484
1622
  }
1485
1623
  collection(path) {
1486
1624
  return super.collection(path);
@@ -1494,73 +1632,87 @@ const withCrudFirestore = (MixinBase) => {
1494
1632
  };
1495
1633
 
1496
1634
  class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1497
- constructor(firestore) {
1498
- super();
1499
- this.firestore = firestore;
1500
- this.collectionName = 'leads';
1501
- this.model = Lead;
1635
+ constructor({ firestore, interceptors }) {
1636
+ super({
1637
+ firestore,
1638
+ collectionName: 'leads',
1639
+ model: Lead,
1640
+ interceptors,
1641
+ });
1502
1642
  }
1503
1643
  }
1504
1644
 
1505
1645
  class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
1506
- constructor(firestore, parentRepository) {
1507
- super();
1508
- this.firestore = firestore;
1646
+ constructor({ firestore, interceptors }, parentRepository) {
1647
+ super({
1648
+ firestore,
1649
+ collectionName: 'editions',
1650
+ parentIdField: 'subscriptionId',
1651
+ model: Edition,
1652
+ interceptors,
1653
+ });
1509
1654
  this.parentRepository = parentRepository;
1510
- this.collectionName = 'editions';
1511
- this.parentIdField = 'subscriptionId';
1512
- this.model = Edition;
1513
1655
  }
1514
1656
  }
1515
1657
 
1516
1658
  class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1517
- constructor(firestore) {
1518
- super();
1519
- this.firestore = firestore;
1520
- this.collectionName = 'subscription';
1521
- this.model = Subscription;
1659
+ constructor({ firestore, interceptors, }) {
1660
+ super({
1661
+ firestore,
1662
+ collectionName: 'subscription',
1663
+ model: Subscription,
1664
+ interceptors,
1665
+ });
1522
1666
  }
1523
1667
  }
1524
1668
 
1525
1669
  class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
1526
- constructor(firestore, parentRepository) {
1527
- super();
1528
- this.firestore = firestore;
1670
+ constructor({ firestore, interceptors }, parentRepository) {
1671
+ super({
1672
+ firestore,
1673
+ collectionName: 'payments',
1674
+ parentIdField: 'subscriptionId',
1675
+ model: SubscriptionPayment,
1676
+ interceptors,
1677
+ });
1529
1678
  this.parentRepository = parentRepository;
1530
- this.collectionName = 'payments';
1531
- this.parentIdField = 'subscriptionId';
1532
- this.model = SubscriptionPayment;
1533
1679
  }
1534
1680
  }
1535
1681
 
1536
1682
  class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1537
- constructor(firestore, parentRepository) {
1538
- super();
1539
- this.firestore = firestore;
1683
+ constructor({ firestore, interceptors }, parentRepository) {
1684
+ super({
1685
+ firestore,
1686
+ collectionName: 'address',
1687
+ parentIdField: 'userId',
1688
+ model: UserAddress,
1689
+ interceptors,
1690
+ });
1540
1691
  this.parentRepository = parentRepository;
1541
- this.collectionName = 'address';
1542
- this.parentIdField = 'userId';
1543
- this.model = UserAddress;
1544
1692
  }
1545
1693
  }
1546
1694
 
1547
1695
  class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1548
- constructor(firestore, parentRepository) {
1549
- super();
1550
- this.firestore = firestore;
1696
+ constructor({ firestore, interceptors }, parentRepository) {
1697
+ super({
1698
+ firestore,
1699
+ collectionName: 'CX',
1700
+ parentIdField: 'userId',
1701
+ model: BeautyProfile,
1702
+ interceptors,
1703
+ });
1551
1704
  this.parentRepository = parentRepository;
1552
- this.collectionName = 'CX';
1553
- this.parentIdField = 'userId';
1554
- this.model = BeautyProfile;
1555
1705
  }
1556
1706
  }
1557
1707
 
1558
1708
  class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1559
- constructor(firestore) {
1560
- super();
1561
- this.firestore = firestore;
1562
- this.collectionName = 'users';
1563
- this.model = User;
1709
+ constructor({ firestore, interceptors }) {
1710
+ super({
1711
+ firestore,
1712
+ collectionName: 'users',
1713
+ model: User,
1714
+ interceptors,
1715
+ });
1564
1716
  }
1565
1717
  get(identifiers) {
1566
1718
  const _super = Object.create(null, {
@@ -1611,22 +1763,26 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1611
1763
  }
1612
1764
 
1613
1765
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1614
- constructor(firestore, parentRepository) {
1615
- super();
1616
- this.firestore = firestore;
1766
+ constructor({ firestore, interceptors }, parentRepository) {
1767
+ super({
1768
+ firestore,
1769
+ collectionName: 'payment_method',
1770
+ parentIdField: 'userId',
1771
+ model: UserPaymentMethod,
1772
+ interceptors,
1773
+ });
1617
1774
  this.parentRepository = parentRepository;
1618
- this.collectionName = 'payment_method';
1619
- this.parentIdField = 'userId';
1620
- this.model = UserPaymentMethod;
1621
1775
  }
1622
1776
  }
1623
1777
 
1624
1778
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1625
- constructor(firestore) {
1626
- super();
1627
- this.firestore = firestore;
1628
- this.collectionName = 'categories';
1629
- this.model = Category;
1779
+ constructor({ firestore, interceptors }) {
1780
+ super({
1781
+ firestore,
1782
+ collectionName: 'categories',
1783
+ model: Category,
1784
+ interceptors,
1785
+ });
1630
1786
  }
1631
1787
  getCategoryBySlug(slug, shop) {
1632
1788
  return __awaiter(this, void 0, void 0, function* () {
@@ -1638,7 +1794,7 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1638
1794
  return categoryDocs.docs[0].data();
1639
1795
  });
1640
1796
  }
1641
- getCategoriesForHome(categoryIds, limit = 4) {
1797
+ getCategoriesForHome(categoryIds, limit = 4, gender) {
1642
1798
  return __awaiter(this, void 0, void 0, function* () {
1643
1799
  const categorySnap = yield getDocs(query(this.collection(this.collectionName), where('id', 'in', categoryIds.filter(Boolean)), where('published', '==', true)));
1644
1800
  if (categorySnap.empty)
@@ -1647,7 +1803,7 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1647
1803
  const homeSections = yield Promise.all(categories.map((category) => __awaiter(this, void 0, void 0, function* () {
1648
1804
  return ({
1649
1805
  category,
1650
- products: yield this.mountCategory(category, { limit, hasStock: true }),
1806
+ products: yield this.mountCategory(category, { limit, hasStock: true, gender }),
1651
1807
  });
1652
1808
  })));
1653
1809
  return homeSections;
@@ -1666,6 +1822,8 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1666
1822
  wheres.push(where('published', '==', true), where('id', 'in', productIds));
1667
1823
  if (options === null || options === void 0 ? void 0 : options.hasStock)
1668
1824
  wheres.push(where('stock.quantity', '>', 0));
1825
+ if (options === null || options === void 0 ? void 0 : options.gender)
1826
+ wheres.push(where('tags', 'array-contains', options === null || options === void 0 ? void 0 : options.gender));
1669
1827
  if (options === null || options === void 0 ? void 0 : options.limit)
1670
1828
  wheres.push(limit(options === null || options === void 0 ? void 0 : options.limit));
1671
1829
  const productSnap = yield getDocs(query(this.collection('productsErpVitrine'), ...wheres));
@@ -1679,12 +1837,14 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1679
1837
  }
1680
1838
 
1681
1839
  class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1682
- constructor(firestore) {
1683
- super();
1684
- this.firestore = firestore;
1840
+ constructor({ firestore, interceptors }) {
1841
+ super({
1842
+ firestore,
1843
+ collectionName: 'productsErpVitrine',
1844
+ model: Product,
1845
+ interceptors,
1846
+ });
1685
1847
  this.reviews = {};
1686
- this.collectionName = 'productsErpVitrine';
1687
- this.model = Product;
1688
1848
  }
1689
1849
  getBySlug(slug) {
1690
1850
  var _a;
@@ -1725,43 +1885,98 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
1725
1885
  return this.reviews[status];
1726
1886
  });
1727
1887
  }
1888
+ cleanShoppingCountFromIds() {
1889
+ return;
1890
+ }
1728
1891
  }
1729
1892
 
1730
1893
  class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
1731
- constructor(firestore, parentRepository) {
1732
- super();
1733
- this.firestore = firestore;
1894
+ constructor({ firestore, interceptors }, parentRepository) {
1895
+ super({
1896
+ firestore,
1897
+ collectionName: 'variants',
1898
+ parentIdField: 'productId',
1899
+ model: Variant,
1900
+ interceptors,
1901
+ });
1734
1902
  this.parentRepository = parentRepository;
1735
- this.collectionName = 'variants';
1736
- this.parentIdField = 'productId';
1737
- this.model = Variant;
1738
1903
  }
1739
1904
  }
1740
1905
 
1741
1906
  class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1742
- constructor(firestore) {
1743
- super();
1744
- this.firestore = firestore;
1745
- this.collectionName = 'subscriptionProducts';
1746
- this.model = Product;
1907
+ constructor({ firestore, interceptors }) {
1908
+ super({
1909
+ firestore,
1910
+ collectionName: 'subscriptionProducts',
1911
+ model: Product,
1912
+ interceptors,
1913
+ });
1914
+ }
1915
+ }
1916
+
1917
+ class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1918
+ constructor({ firestore, interceptors }) {
1919
+ super({
1920
+ firestore,
1921
+ collectionName: 'buy2win',
1922
+ model: Buy2Win,
1923
+ interceptors,
1924
+ });
1925
+ }
1926
+ }
1927
+
1928
+ class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1929
+ constructor({ firestore, interceptors, }) {
1930
+ super({
1931
+ firestore,
1932
+ collectionName: 'dashboardCampaignsAuto',
1933
+ model: CampaignDashboard,
1934
+ interceptors,
1935
+ });
1936
+ }
1937
+ }
1938
+
1939
+ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1940
+ constructor({ firestore, interceptors, }) {
1941
+ super({
1942
+ firestore,
1943
+ collectionName: 'hashtagCampaignsAuto',
1944
+ model: CampaignHashtag,
1945
+ interceptors,
1946
+ });
1747
1947
  }
1748
1948
  }
1749
1949
 
1750
1950
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1751
- constructor(firestore) {
1752
- super();
1753
- this.firestore = firestore;
1754
- this.collectionName = 'checkouts';
1755
- this.model = Checkout;
1951
+ constructor({ firestore, interceptors }) {
1952
+ super({
1953
+ firestore,
1954
+ collectionName: 'checkouts',
1955
+ model: Checkout,
1956
+ interceptors,
1957
+ });
1958
+ }
1959
+ }
1960
+
1961
+ class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1962
+ constructor({ firestore, interceptors, }) {
1963
+ super({
1964
+ firestore,
1965
+ collectionName: 'checkoutsSubscription',
1966
+ model: CheckoutSubscription,
1967
+ interceptors,
1968
+ });
1756
1969
  }
1757
1970
  }
1758
1971
 
1759
1972
  class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1760
- constructor(firestore) {
1761
- super();
1762
- this.firestore = firestore;
1763
- this.collectionName = 'coupons';
1764
- this.model = Coupon;
1973
+ constructor({ firestore, interceptors }) {
1974
+ super({
1975
+ firestore,
1976
+ collectionName: 'coupons',
1977
+ model: Coupon,
1978
+ interceptors,
1979
+ });
1765
1980
  }
1766
1981
  buildModelInstance() {
1767
1982
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1783,9 +1998,16 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
1783
1998
  }
1784
1999
 
1785
2000
  class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1786
- constructor(firestore) {
1787
- super();
1788
- this.firestore = firestore;
2001
+ constructor({ firestore, interceptors }) {
2002
+ super({
2003
+ firestore,
2004
+ collectionName: 'orders',
2005
+ model: Order,
2006
+ interceptors,
2007
+ fields: {
2008
+ status: FirestoreFieldType.String,
2009
+ },
2010
+ });
1789
2011
  this.orderFromFirestore = (order) => {
1790
2012
  var _a;
1791
2013
  if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
@@ -1799,11 +2021,6 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1799
2021
  }
1800
2022
  return order;
1801
2023
  };
1802
- this.collectionName = 'orders';
1803
- this.model = Order;
1804
- this.fields = {
1805
- status: FirestoreFieldType.String,
1806
- };
1807
2024
  }
1808
2025
  buildModelInstance() {
1809
2026
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1817,54 +2034,46 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1817
2034
  }
1818
2035
  }
1819
2036
 
1820
- class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1821
- constructor(firestore) {
1822
- super();
1823
- this.firestore = firestore;
1824
- this.collectionName = 'payments';
1825
- this.model = Payment;
2037
+ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
2038
+ constructor({ firestore, interceptors }) {
2039
+ super({
2040
+ firestore,
2041
+ interceptors,
2042
+ });
2043
+ this.collectionName = 'legacyOrders';
1826
2044
  }
1827
2045
  }
1828
2046
 
1829
- class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1830
- constructor(firestore) {
1831
- super();
1832
- this.firestore = firestore;
1833
- this.collectionName = 'checkoutsSubscription';
1834
- this.model = CheckoutSubscription;
2047
+ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2048
+ constructor({ firestore, interceptors }) {
2049
+ super({
2050
+ firestore,
2051
+ collectionName: 'payments',
2052
+ model: Payment,
2053
+ interceptors,
2054
+ });
1835
2055
  }
1836
2056
  }
1837
2057
 
1838
2058
  class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1839
- constructor(firestore) {
1840
- super();
1841
- this.firestore = firestore;
1842
- this.collectionName = 'subscriptionPlans';
1843
- this.model = SubscriptionPlan;
1844
- }
1845
- }
1846
-
1847
- class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1848
- constructor(firestore) {
1849
- super();
1850
- this.firestore = firestore;
1851
- this.collectionName = 'buy2win';
1852
- this.model = Buy2Win;
1853
- }
1854
- }
1855
-
1856
- class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
1857
- constructor(firestore) {
1858
- super(firestore);
1859
- this.firestore = firestore;
1860
- this.collectionName = 'legacyOrders';
2059
+ constructor({ firestore, interceptors, }) {
2060
+ super({
2061
+ firestore,
2062
+ collectionName: 'subscriptionPlans',
2063
+ model: SubscriptionPlan,
2064
+ interceptors,
2065
+ });
1861
2066
  }
1862
2067
  }
1863
2068
 
1864
2069
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1865
- constructor(firestore) {
1866
- super();
1867
- this.firestore = firestore;
2070
+ constructor({ firestore, interceptors }) {
2071
+ super({
2072
+ firestore,
2073
+ collectionName: 'dms',
2074
+ model: Home,
2075
+ interceptors,
2076
+ });
1868
2077
  this.homeToFirestore = (home) => {
1869
2078
  var _a;
1870
2079
  if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
@@ -1895,8 +2104,6 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1895
2104
  category: Category.toInstance(homeCategoryGroup.category),
1896
2105
  products: homeCategoryGroup.products.map((product) => Product.toInstance(product)),
1897
2106
  });
1898
- this.collectionName = 'dms';
1899
- this.model = Home;
1900
2107
  }
1901
2108
  buildModelInstance() {
1902
2109
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1914,11 +2121,24 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1914
2121
  }
1915
2122
 
1916
2123
  class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1917
- constructor(firestore) {
1918
- super();
1919
- this.firestore = firestore;
1920
- this.collectionName = 'shopMenus';
1921
- this.model = ShopMenu;
2124
+ constructor({ firestore, interceptors }) {
2125
+ super({
2126
+ firestore,
2127
+ collectionName: 'shopMenus',
2128
+ model: ShopMenu,
2129
+ interceptors,
2130
+ });
2131
+ }
2132
+ }
2133
+
2134
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2135
+ constructor({ firestore, interceptors, }) {
2136
+ super({
2137
+ firestore,
2138
+ collectionName: 'shopSettings',
2139
+ model: ShopSettings,
2140
+ interceptors,
2141
+ });
1922
2142
  }
1923
2143
  }
1924
2144
 
@@ -2008,7 +2228,7 @@ class AttributeOptionHelper {
2008
2228
  AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
2009
2229
  var _a;
2010
2230
  if (fields.includes(attributeName))
2011
- return { columnName: attributeName.toString(), attributeName };
2231
+ return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
2012
2232
  const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
2013
2233
  const fieldOption = (_a = is(field)) === null || _a === void 0 ? void 0 : _a[attributeName];
2014
2234
  if (isNil(fieldOption))
@@ -2183,7 +2403,7 @@ GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).r
2183
2403
  }
2184
2404
  if (!!from)
2185
2405
  return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
2186
- return Object.assign(Object.assign({}, result), { [attributeName]: parseDateTime(data[columnName].toString()) });
2406
+ return Object.assign(Object.assign({}, result), { [attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName] });
2187
2407
  }, {});
2188
2408
  GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
2189
2409
  var _a;
@@ -2199,7 +2419,8 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
2199
2419
  !Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = is(data[attributeName])) === null || _a === void 0 ? void 0 : _a[key]); }).length)
2200
2420
  return Object.keys(foreignKeyColumn).reduce((object, current) => {
2201
2421
  var _a;
2202
- 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] });
2203
2424
  }, Object.assign({}, result));
2204
2425
  if (update &&
2205
2426
  isObject(data[attributeName]) &&
@@ -2250,7 +2471,7 @@ const withCreateHasuraGraphQL = (MixinBase) => {
2250
2471
  const columnOptions = Object.values(field).shift();
2251
2472
  return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
2252
2473
  columnOptions.foreignKeyColumn && [
2253
- ...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; }),
2254
2475
  {
2255
2476
  [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => {
2256
2477
  var _a;
@@ -2309,9 +2530,13 @@ const withHasuraGraphQL = (MixinBase) => {
2309
2530
  this.fields = options.fields || this.model.identifiersFields;
2310
2531
  }
2311
2532
  get headers() {
2312
- return Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (isNil(this.authOptions.authToken) ? {} : { Authorization: this.authOptions.authToken })), (isNil(this.authOptions.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': this.authOptions.adminSecret })), (isNil(this.authOptions.authRole)
2533
+ var _a, _b, _c, _d, _e, _f, _g;
2534
+ return Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (isNil((_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.authToken) ? {} : { Authorization: (_b = this.authOptions) === null || _b === void 0 ? void 0 : _b.authToken })), (isNil((_c = this.authOptions) === null || _c === void 0 ? void 0 : _c.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': (_d = this.authOptions) === null || _d === void 0 ? void 0 : _d.adminSecret })), (isNil((_e = this.authOptions) === null || _e === void 0 ? void 0 : _e.authRole)
2313
2535
  ? {}
2314
- : { 'X-Hasura-Role': this.authOptions.authRole.role, 'X-Hasura-User-Id': this.authOptions.authRole.userId }));
2536
+ : {
2537
+ 'X-Hasura-Role': this.authOptions.authRole.role,
2538
+ 'X-Hasura-User-Id': (_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.authRole) === null || _g === void 0 ? void 0 : _g.userId,
2539
+ }));
2315
2540
  }
2316
2541
  mutation(operation, fields, variables) {
2317
2542
  return __awaiter(this, void 0, void 0, function* () {
@@ -2324,30 +2549,24 @@ const withHasuraGraphQL = (MixinBase) => {
2324
2549
  });
2325
2550
  }
2326
2551
  query(operation, fields, variables) {
2552
+ var _a, _b, _c, _d;
2327
2553
  return __awaiter(this, void 0, void 0, function* () {
2328
- const resultQuery = GraphQLFieldHelper.CheckIsGraphQLParams(operation)
2329
- ? query$1(operation.map((option) => ({
2330
- operation: option.operation,
2331
- variables: option.variables,
2332
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
2333
- })))
2334
- : query$1({
2335
- operation,
2336
- variables,
2337
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
2338
- });
2339
- return this.fetch(resultQuery);
2554
+ const builded = this.buildHasuraQueryFields({ operation, fields, variables });
2555
+ const interpected = (yield ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, builded))) || builded;
2556
+ const resultQuery = query$1(interpected);
2557
+ const result = yield this.fetch(resultQuery);
2558
+ return (yield ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, result, interpected))) || result;
2340
2559
  });
2341
2560
  }
2342
2561
  fetch(params) {
2343
2562
  return __awaiter(this, void 0, void 0, function* () {
2344
2563
  const headers = this.headers;
2345
- const response = yield fetch(`${this.endpoint}`, {
2564
+ const { data: result } = yield axios({
2565
+ url: `${this.endpoint}`,
2346
2566
  method: 'POST',
2347
- body: JSON.stringify(params),
2567
+ data: params,
2348
2568
  headers,
2349
2569
  });
2350
- const result = yield response.json();
2351
2570
  if (!isNil(result.errors))
2352
2571
  throw new Error(JSON.stringify(result.errors));
2353
2572
  return result.data;
@@ -2383,6 +2602,19 @@ const withHasuraGraphQL = (MixinBase) => {
2383
2602
  convertDataToHasura(instance, update = false) {
2384
2603
  return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
2385
2604
  }
2605
+ buildHasuraQueryFields({ operation, fields, variables, }) {
2606
+ return GraphQLFieldHelper.CheckIsGraphQLParams(operation)
2607
+ ? operation.map((option) => ({
2608
+ operation: option.operation,
2609
+ variables: option.variables,
2610
+ fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
2611
+ }))
2612
+ : {
2613
+ operation,
2614
+ variables,
2615
+ fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
2616
+ };
2617
+ }
2386
2618
  };
2387
2619
  };
2388
2620
 
@@ -2474,9 +2706,11 @@ const withGetHasuraGraphQL = (MixinBase) => {
2474
2706
 
2475
2707
  const withFindHasuraGraphQL = (MixinBase) => {
2476
2708
  return class FindHasuraGraphQLMixin extends MixinBase {
2477
- find(options) {
2709
+ find(params) {
2710
+ var _a;
2478
2711
  return __awaiter(this, void 0, void 0, function* () {
2479
- const { filters, limits, orderBy } = options || {};
2712
+ const { filters, limits, orderBy, options } = params || {};
2713
+ const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
2480
2714
  const variablesCount = Object.assign(Object.assign({}, (isNil(orderBy) ? {} : { order_by: { type: `${this.tableName}_order_by!`, list: true, value: orderBy } })), (isNil(filters)
2481
2715
  ? {}
2482
2716
  : {
@@ -2490,8 +2724,8 @@ const withFindHasuraGraphQL = (MixinBase) => {
2490
2724
  const result = yield this.query([
2491
2725
  {
2492
2726
  operation: this.tableName,
2493
- fields: options.fields
2494
- ? options.fields
2727
+ fields: params.fields
2728
+ ? params.fields
2495
2729
  .map((fieldName) => {
2496
2730
  var _a;
2497
2731
  return (_a = this.fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
@@ -2500,15 +2734,18 @@ const withFindHasuraGraphQL = (MixinBase) => {
2500
2734
  : this.fields,
2501
2735
  variables,
2502
2736
  },
2503
- {
2504
- operation: `${this.tableName}_aggregate`,
2505
- fields: [{ aggregate: ['count'] }],
2506
- variables: variablesCount,
2507
- },
2737
+ ...(enableCount
2738
+ ? [
2739
+ {
2740
+ operation: `${this.tableName}_aggregate`,
2741
+ fields: [{ aggregate: ['count'] }],
2742
+ variables: variablesCount,
2743
+ },
2744
+ ]
2745
+ : []),
2508
2746
  ]);
2509
2747
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
2510
- const count = result[`${this.tableName}_aggregate`].aggregate.count;
2511
- return { count, data };
2748
+ return { data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity };
2512
2749
  });
2513
2750
  }
2514
2751
  };
@@ -2548,13 +2785,67 @@ class VariantHasuraGraphQL extends Variant {
2548
2785
  }
2549
2786
  }
2550
2787
 
2788
+ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
2789
+ constructor({ endpoint, authOptions, interceptors, }) {
2790
+ super({
2791
+ tableName: 'category_filter',
2792
+ model: CategoryFilter,
2793
+ endpoint,
2794
+ authOptions,
2795
+ interceptors,
2796
+ fields: [
2797
+ 'id',
2798
+ { filterId: { columnName: 'filter_id' } },
2799
+ { categoryId: { columnName: 'category_id' } },
2800
+ {
2801
+ filter: {
2802
+ columnName: 'filter',
2803
+ foreignKeyColumn: { id: 'filterId' },
2804
+ fields: [
2805
+ 'id',
2806
+ 'description',
2807
+ 'slug',
2808
+ 'enabled',
2809
+ { createdAt: { columnName: 'created_at' } },
2810
+ { updatedAt: { columnName: 'updated_at' } },
2811
+ {
2812
+ options: {
2813
+ columnName: 'options',
2814
+ foreignKeyColumn: { filterId: 'id' },
2815
+ fields: [
2816
+ 'id',
2817
+ { filterId: { columnName: 'filter_id' } },
2818
+ 'description',
2819
+ { createdAt: { columnName: 'created_at' } },
2820
+ { updatedAt: { columnName: 'updated_at' } },
2821
+ ],
2822
+ },
2823
+ },
2824
+ ],
2825
+ },
2826
+ },
2827
+ ],
2828
+ });
2829
+ }
2830
+ deleteByCategoryAndFilter(categoryId, filterId) {
2831
+ return this.mutation('delete_category_filter', ['affected_rows'], {
2832
+ where: {
2833
+ type: 'category_filter_bool_exp',
2834
+ required: true,
2835
+ value: { category_id: { _eq: categoryId }, filter_id: { _eq: filterId } },
2836
+ },
2837
+ });
2838
+ }
2839
+ }
2840
+
2551
2841
  class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
2552
- constructor(endpoint, authOptions, productRepository) {
2842
+ constructor({ endpoint, authOptions, interceptors, }, productRepository, categoryFilterRepository) {
2553
2843
  super({
2554
2844
  tableName: 'category',
2555
2845
  model: Category,
2556
2846
  endpoint,
2557
2847
  authOptions,
2848
+ interceptors,
2558
2849
  fields: [
2559
2850
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
2560
2851
  { firestoreId: { columnName: 'firestore_id' } },
@@ -2588,7 +2879,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2588
2879
  },
2589
2880
  },
2590
2881
  },
2591
- 'filters',
2882
+ {
2883
+ filters: {
2884
+ columnName: 'filters',
2885
+ foreignKeyColumn: { filter_id: 'id' },
2886
+ fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
2887
+ bindPersistData: (value) => ({
2888
+ filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
2889
+ }),
2890
+ from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter)) || [],
2891
+ },
2892
+ },
2592
2893
  { createdAt: { columnName: 'created_at' } },
2593
2894
  { updatedAt: { columnName: 'updated_at' } },
2594
2895
  {
@@ -2610,9 +2911,20 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2610
2911
  }),
2611
2912
  },
2612
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
+ },
2613
2924
  ],
2614
2925
  });
2615
2926
  this.productRepository = productRepository;
2927
+ this.categoryFilterRepository = categoryFilterRepository;
2616
2928
  }
2617
2929
  create(params) {
2618
2930
  const _super = Object.create(null, {
@@ -2630,7 +2942,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2630
2942
  var _a;
2631
2943
  return __awaiter(this, void 0, void 0, function* () {
2632
2944
  return Number.isNaN(+identifiers.id)
2633
- ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
2945
+ ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data) === null || _a === void 0 ? void 0 : _a[0]
2634
2946
  : _super.get.call(this, identifiers);
2635
2947
  });
2636
2948
  }
@@ -2639,12 +2951,13 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2639
2951
  update: { get: () => super.update }
2640
2952
  });
2641
2953
  return __awaiter(this, void 0, void 0, function* () {
2642
- const { products, id: checkId, metadata } = params, data = __rest(params, ["products", "id", "metadata"]);
2954
+ const { products, id: checkId, metadata, filters } = params, data = __rest(params, ["products", "id", "metadata", "filters"]);
2643
2955
  const plainData = this.paramsToPlain({ id: checkId });
2644
2956
  const id = yield this.getId(plainData.id);
2645
2957
  const category = yield _super.update.call(this, Object.assign({ id }, data));
2646
2958
  category.products = products && (yield this.updateProducts(+id, { products }));
2647
2959
  category.metadata = metadata && (yield this.updateMetadata(+id, { metadata }));
2960
+ category.filters = filters && (yield this.updateFilters(+id, { filters }));
2648
2961
  return category;
2649
2962
  });
2650
2963
  }
@@ -2652,15 +2965,15 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2652
2965
  return __awaiter(this, void 0, void 0, function* () {
2653
2966
  if (!slug)
2654
2967
  return null;
2655
- const { data, count } = yield this.find({ filters: { slug, shop, published: true } });
2656
- if (count > 1)
2657
- throw new DuplicatedResultsError('Query returned duplicated values');
2658
- if (!count)
2968
+ const { data } = yield this.find({ filters: { slug, shop, published: true }, options: { enableCount: false } });
2969
+ if (!data.length)
2659
2970
  throw new NotFoundError(`Category with slug ${slug} not found`);
2971
+ if (data.length > 1)
2972
+ throw new DuplicatedResultsError('Query returned duplicated values');
2660
2973
  return data.shift();
2661
2974
  });
2662
2975
  }
2663
- getCategoriesForHome(categoryIds, limit = 4) {
2976
+ getCategoriesForHome(categoryIds, limit = 4, gender) {
2664
2977
  return __awaiter(this, void 0, void 0, function* () {
2665
2978
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
2666
2979
  return [];
@@ -2680,7 +2993,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2680
2993
  const homeSections = yield Promise.all(categories.map((category) => __awaiter(this, void 0, void 0, function* () {
2681
2994
  return ({
2682
2995
  category,
2683
- products: yield this.mountCategory(category, { limit, hasStock: true }),
2996
+ products: yield this.mountCategory(category, { limit, hasStock: true, gender }),
2684
2997
  });
2685
2998
  })));
2686
2999
  return homeSections;
@@ -2692,7 +3005,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2692
3005
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
2693
3006
  return [];
2694
3007
  const products = [];
2695
- const { data: productsData } = yield this.productRepository.find(Object.assign({ filters: Object.assign({ id: { operator: Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), fields: [
3008
+ const { data: productsData } = yield this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign(Object.assign({ id: { operator: Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), ((options === null || options === void 0 ? void 0 : options.gender) ? { tags: { operator: Where.IN, value: [options === null || options === void 0 ? void 0 : options.gender] } } : {})), fields: [
2696
3009
  'id',
2697
3010
  'name',
2698
3011
  'slug',
@@ -2716,7 +3029,9 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2716
3029
  'tags',
2717
3030
  'type',
2718
3031
  'shoppingCount',
2719
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})));
3032
+ 'gender',
3033
+ 'createdAt',
3034
+ ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
2720
3035
  products.push(...productsData);
2721
3036
  return products;
2722
3037
  });
@@ -2726,7 +3041,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2726
3041
  return __awaiter(this, void 0, void 0, function* () {
2727
3042
  if (!Number.isNaN(+id))
2728
3043
  return id;
2729
- const { data } = yield this.find({ filters: { firestoreId: id } });
3044
+ const { data } = yield this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
2730
3045
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
2731
3046
  return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
2732
3047
  throw new NotFoundError(`Category with id ${id} not found`);
@@ -2784,15 +3099,220 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2784
3099
  return plainData.metadata;
2785
3100
  });
2786
3101
  }
3102
+ updateFilters(categoryId, { filters }) {
3103
+ return __awaiter(this, void 0, void 0, function* () {
3104
+ if ('action' in filters && filters.action === 'remove' && filters.value.length) {
3105
+ for (let i = 0; i < filters.value.length; i++) {
3106
+ yield this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filters.value[i].id);
3107
+ }
3108
+ return [];
3109
+ }
3110
+ if ('action' in filters && filters.action === 'merge' && filters.value.length) {
3111
+ let filtersList = [];
3112
+ for (let i = 0; i < filters.value.length; i++) {
3113
+ try {
3114
+ const hasFilter = yield this.categoryFilterRepository
3115
+ .find({
3116
+ filters: {
3117
+ categoryId,
3118
+ filterId: filters.value[i].id,
3119
+ },
3120
+ })
3121
+ .then((data) => { var _a; return (_a = data.data.shift()) === null || _a === void 0 ? void 0 : _a.filter; });
3122
+ if (hasFilter) {
3123
+ filtersList.push(hasFilter);
3124
+ }
3125
+ else {
3126
+ yield this.categoryFilterRepository.create({
3127
+ filterId: filters.value[i].id,
3128
+ categoryId,
3129
+ });
3130
+ filtersList.push(filters.value[i]);
3131
+ }
3132
+ }
3133
+ catch (error) {
3134
+ console.log('catch error: ', error);
3135
+ }
3136
+ }
3137
+ return filtersList;
3138
+ }
3139
+ if (Array.isArray(filters) && filters.length) {
3140
+ let filtersList = [];
3141
+ for (let i = 0; i < filters.length; i++) {
3142
+ try {
3143
+ const hasFilter = yield this.categoryFilterRepository
3144
+ .find({
3145
+ filters: {
3146
+ categoryId,
3147
+ filterId: filters[i].id,
3148
+ },
3149
+ })
3150
+ .then((data) => { var _a; return (_a = data.data.shift()) === null || _a === void 0 ? void 0 : _a.filter; });
3151
+ if (hasFilter) {
3152
+ filtersList.push(hasFilter);
3153
+ }
3154
+ else {
3155
+ yield this.categoryFilterRepository.create({
3156
+ filterId: filters[i].id,
3157
+ categoryId,
3158
+ });
3159
+ filtersList.push(filters[i]);
3160
+ }
3161
+ }
3162
+ catch (error) {
3163
+ console.log('catch error: ', error);
3164
+ }
3165
+ }
3166
+ return filtersList;
3167
+ }
3168
+ return [];
3169
+ });
3170
+ }
3171
+ }
3172
+
3173
+ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3174
+ constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
3175
+ super({
3176
+ tableName: 'filter',
3177
+ model: Filter,
3178
+ endpoint,
3179
+ authOptions,
3180
+ interceptors,
3181
+ fields: [
3182
+ 'id',
3183
+ 'description',
3184
+ 'slug',
3185
+ 'enabled',
3186
+ { createdAt: { columnName: 'created_at' } },
3187
+ { updatedAt: { columnName: 'updated_at' } },
3188
+ {
3189
+ options: {
3190
+ columnName: 'options',
3191
+ foreignKeyColumn: { filterId: 'id' },
3192
+ fields: [
3193
+ 'id',
3194
+ { filterId: { columnName: 'filter_id' } },
3195
+ 'description',
3196
+ { createdAt: { columnName: 'created_at' } },
3197
+ { updatedAt: { columnName: 'updated_at' } },
3198
+ ],
3199
+ },
3200
+ },
3201
+ ],
3202
+ });
3203
+ this.filterOptionRepository = filterOptionRepository;
3204
+ this.categoryFilterRepository = categoryFilterRepository;
3205
+ }
3206
+ update(params) {
3207
+ const _super = Object.create(null, {
3208
+ update: { get: () => super.update }
3209
+ });
3210
+ return __awaiter(this, void 0, void 0, function* () {
3211
+ const { options } = params, data = __rest(params, ["options"]);
3212
+ const filter = yield _super.update.call(this, data);
3213
+ filter.options = yield this.updateOptions(+data.id, { options });
3214
+ return filter;
3215
+ });
3216
+ }
3217
+ updateOptions(filterId, { options }) {
3218
+ return __awaiter(this, void 0, void 0, function* () {
3219
+ if (!options)
3220
+ return [];
3221
+ if ('action' in options && options.action === 'remove' && options.value.length) {
3222
+ for (let i = 0; i < options.value.length; i++) {
3223
+ yield this.filterOptionRepository.delete({ id: options.value[i].id });
3224
+ }
3225
+ return [];
3226
+ }
3227
+ if ('action' in options && options.action === 'merge' && options.value.length) {
3228
+ let filterOptions = [];
3229
+ for (let i = 0; i < options.value.length; i++) {
3230
+ try {
3231
+ const hasFilter = yield this.filterOptionRepository.get({ id: options.value[i].id });
3232
+ if (hasFilter)
3233
+ filterOptions.push(hasFilter);
3234
+ }
3235
+ catch (error) {
3236
+ const newOption = yield this.filterOptionRepository.create(Object.assign(Object.assign({}, options.value[i]), { filterId }));
3237
+ filterOptions.push(newOption);
3238
+ }
3239
+ }
3240
+ return filterOptions;
3241
+ }
3242
+ if (Array.isArray(options) && options.length) {
3243
+ let filterOptions = [];
3244
+ for (let i = 0; i < options.length; i++) {
3245
+ try {
3246
+ const hasFilter = yield this.filterOptionRepository.get({ id: options[i].id });
3247
+ if (hasFilter)
3248
+ filterOptions.push(hasFilter);
3249
+ }
3250
+ catch (error) {
3251
+ const newOption = yield this.filterOptionRepository.create(Object.assign(Object.assign({}, options[i]), { filterId }));
3252
+ filterOptions.push(newOption);
3253
+ }
3254
+ }
3255
+ }
3256
+ return [];
3257
+ });
3258
+ }
3259
+ delete(params) {
3260
+ const _super = Object.create(null, {
3261
+ delete: { get: () => super.delete }
3262
+ });
3263
+ return __awaiter(this, void 0, void 0, function* () {
3264
+ const { data: categoryFilters } = yield this.categoryFilterRepository.find({
3265
+ filters: {
3266
+ filterId: params.id,
3267
+ },
3268
+ });
3269
+ if (categoryFilters.length)
3270
+ throw new Error('Erro: o filtro está associado a uma ou mais categoria(s)');
3271
+ yield this.deleteOptions(+params.id);
3272
+ yield _super.delete.call(this, { id: +params.id });
3273
+ return;
3274
+ });
3275
+ }
3276
+ deleteOptions(filterId) {
3277
+ return __awaiter(this, void 0, void 0, function* () {
3278
+ yield this.mutation('delete_filter_option', ['affected_rows'], {
3279
+ where: {
3280
+ type: 'filter_option_bool_exp',
3281
+ required: true,
3282
+ value: { filter_id: { _eq: filterId } },
3283
+ },
3284
+ });
3285
+ });
3286
+ }
3287
+ }
3288
+
3289
+ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3290
+ constructor({ endpoint, authOptions, interceptors, }) {
3291
+ super({
3292
+ tableName: 'filter_option',
3293
+ model: FilterOption,
3294
+ endpoint,
3295
+ authOptions,
3296
+ interceptors,
3297
+ fields: [
3298
+ 'id',
3299
+ 'description',
3300
+ { filterId: { columnName: 'filter_id' } },
3301
+ { createdAt: { columnName: 'created_at' } },
3302
+ { updatedAt: { columnName: 'updated_at' } },
3303
+ ],
3304
+ });
3305
+ }
2787
3306
  }
2788
3307
 
2789
3308
  class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
2790
- constructor(endpoint, authOptions) {
3309
+ constructor({ endpoint, authOptions, interceptors, }) {
2791
3310
  super({
2792
3311
  tableName: 'product',
2793
3312
  model: ProductHasuraGraphQL,
2794
3313
  endpoint,
2795
3314
  authOptions,
3315
+ interceptors,
2796
3316
  fields: [],
2797
3317
  });
2798
3318
  this.bindReviewToModel = (plain) => (Object.assign(Object.assign({}, is(omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id']))), { createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at, updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at, personId: plain.person_id, orderId: plain.order_id }));
@@ -2889,21 +3409,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2889
3409
  'weight',
2890
3410
  'gender',
2891
3411
  { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
3412
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
2892
3413
  { isKit: { columnName: 'is_kit' } },
2893
3414
  { createdAt: { columnName: 'created_at' } },
2894
3415
  { updatedAt: { columnName: 'updated_at' } },
3416
+ { rate: { columnName: 'rating' } },
3417
+ { reviewsTotal: { columnName: 'reviews_total' } },
3418
+ { shoppingCount: { columnName: 'shopping_count' } },
3419
+ { categoryId: { columnName: 'category_id' } },
2895
3420
  {
2896
- rate: {
2897
- columnName: 'reviews_aggregate',
2898
- filters: {
2899
- filters: { status: true },
2900
- filterType: 'product_review_bool_exp',
2901
- },
2902
- fields: [{ aggregate: [{ avg: ['rate'] }] }],
2903
- from: (value) => value.aggregate.avg.rate,
3421
+ category: {
3422
+ columnName: 'category',
3423
+ foreignKeyColumn: { id: 'categoryId' },
3424
+ fields: ['id', 'name', 'reference', 'slug'],
2904
3425
  },
2905
3426
  },
2906
- { shoppingCount: { columnName: 'shopping_count' } },
2907
3427
  ];
2908
3428
  this.fields = [
2909
3429
  ...commonFields,
@@ -2990,7 +3510,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2990
3510
  var _a;
2991
3511
  return __awaiter(this, void 0, void 0, function* () {
2992
3512
  const product = Number.isNaN(+identifiers.id)
2993
- ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
3513
+ ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data) === null || _a === void 0 ? void 0 : _a[0]
2994
3514
  : yield _super.get.call(this, identifiers);
2995
3515
  if (product.productId)
2996
3516
  throw new NotFoundError('Product not found, it is a variant');
@@ -3008,7 +3528,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3008
3528
  this.fields
3009
3529
  .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
3010
3530
  .filter((field) => field !== 'reviews');
3011
- 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
+ ] }));
3012
3541
  });
3013
3542
  }
3014
3543
  getBySlug(slug) {
@@ -3018,9 +3547,12 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3018
3547
  filters: {
3019
3548
  slug,
3020
3549
  },
3550
+ fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
3551
+ options: {
3552
+ enableCount: false,
3553
+ },
3021
3554
  });
3022
3555
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
3023
- product.reviews = yield this.findReviewsByProduct(+product.id);
3024
3556
  return product;
3025
3557
  });
3026
3558
  }
@@ -3183,7 +3715,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3183
3715
  return __awaiter(this, void 0, void 0, function* () {
3184
3716
  if (!Number.isNaN(+id))
3185
3717
  return id;
3186
- const { data } = yield this.find({ filters: { firestoreId: id } });
3718
+ const { data } = yield this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3187
3719
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3188
3720
  return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
3189
3721
  throw new NotFoundError(`Product with id ${id} not found`);
@@ -3239,15 +3771,31 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3239
3771
  return data && data[0] && this.bindReviewToModel(data[0]);
3240
3772
  });
3241
3773
  }
3774
+ cleanShoppingCountFromIds(ids) {
3775
+ return __awaiter(this, void 0, void 0, function* () {
3776
+ return yield this.mutation('update_product', ['affected_rows'], {
3777
+ where: {
3778
+ value: { id: { _nin: ids } },
3779
+ type: 'product_bool_exp',
3780
+ required: true,
3781
+ },
3782
+ _set: {
3783
+ value: { shopping_count: 0 },
3784
+ type: 'product_set_input',
3785
+ },
3786
+ });
3787
+ });
3788
+ }
3242
3789
  }
3243
3790
 
3244
3791
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3245
- constructor(endpoint, authOptions) {
3792
+ constructor({ endpoint, authOptions, interceptors, }) {
3246
3793
  super({
3247
3794
  tableName: 'product',
3248
3795
  model: VariantHasuraGraphQL,
3249
3796
  endpoint,
3250
3797
  authOptions,
3798
+ interceptors,
3251
3799
  fields: [
3252
3800
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
3253
3801
  { firestoreId: { columnName: 'firestore_id' } },
@@ -3277,9 +3825,9 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3277
3825
  subscriber_price: filters.subscriberPrice,
3278
3826
  }));
3279
3827
  },
3280
- bindPersistData: (priceData) => (Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
3828
+ bindPersistData: (priceData) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (((priceData === null || priceData === void 0 ? void 0 : priceData.price) || 0) >= 0 && { price: priceData.price })), (((priceData === null || priceData === void 0 ? void 0 : priceData.fullPrice) || 0) >= 0 && { full_price: priceData.fullPrice })), (((priceData === null || priceData === void 0 ? void 0 : priceData.subscriberDiscountPercentage) || 0) >= 0 && {
3281
3829
  subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
3282
- })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }))),
3830
+ })), (((priceData === null || priceData === void 0 ? void 0 : priceData.subscriberPrice) || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }))),
3283
3831
  },
3284
3832
  },
3285
3833
  { fullPrice: { columnName: 'full_price' } },
@@ -3348,7 +3896,7 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3348
3896
  return __awaiter(this, void 0, void 0, function* () {
3349
3897
  if (!Number.isNaN(+id))
3350
3898
  return id;
3351
- const { data } = yield this.find({ filters: { firestoreId: id } });
3899
+ const { data } = yield this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3352
3900
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3353
3901
  return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
3354
3902
  throw new NotFoundError(`Product with id ${id} not found`);
@@ -3360,5 +3908,5 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3360
3908
  * Generated bundle index. Do not edit.
3361
3909
  */
3362
3910
 
3363
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, chunk, get, is, isBoolean, isDate, isEmpty, isInteger, isNaN$1 as isNaN, isNil, isNumber, isObject, isString, isUUID, now, omit, parseDateTime, pick, set, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
3911
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, get, is, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
3364
3912
  //# sourceMappingURL=infrab4a-connect.mjs.map