@infrab4a/connect 1.0.0-beta.8 → 1.0.0-beta.9

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 (319) hide show
  1. package/bundles/infrab4a-connect.umd.js +1148 -182
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/catalog/models/category.d.ts +3 -2
  4. package/domain/catalog/models/product.d.ts +3 -2
  5. package/domain/catalog/models/variant.d.ts +4 -2
  6. package/domain/catalog/repositories/category.repository.d.ts +1 -1
  7. package/domain/catalog/repositories/product.repository.d.ts +1 -1
  8. package/domain/catalog/repositories/subscription-product.repository.d.ts +1 -1
  9. package/domain/catalog/repositories/variant.repository.d.ts +1 -1
  10. package/domain/generic/model/base.model.d.ts +10 -0
  11. package/domain/{general → generic}/model/index.d.ts +0 -1
  12. package/domain/generic/model/types/base-model-builder.type.d.ts +15 -0
  13. package/domain/generic/model/types/identifier-model.type.d.ts +7 -0
  14. package/domain/{general → generic}/model/types/index.d.ts +2 -0
  15. package/domain/generic/model/types/model-base-structure.type.d.ts +6 -0
  16. package/domain/generic/model/types/non-function-properties.type.d.ts +12 -0
  17. package/domain/generic/model/types/non-function-property-name.type.d.ts +4 -0
  18. package/domain/generic/repository/create.repository.d.ts +8 -0
  19. package/domain/generic/repository/crud.repository.d.ts +19 -0
  20. package/domain/generic/repository/delete.repository.d.ts +5 -0
  21. package/domain/{general → generic}/repository/enums/where.enum.d.ts +5 -2
  22. package/domain/generic/repository/find.repository.d.ts +10 -0
  23. package/domain/generic/repository/get.repository.d.ts +5 -0
  24. package/domain/generic/repository/read.repository.d.ts +14 -0
  25. package/domain/{general → generic}/repository/types/index.d.ts +1 -0
  26. package/domain/generic/repository/types/repository-find-filters.type.d.ts +13 -0
  27. package/domain/{general → generic}/repository/types/repository-update-params.type.d.ts +2 -2
  28. package/domain/generic/repository/types/where-options.type.d.ts +2 -0
  29. package/domain/generic/repository/update.repository.d.ts +6 -0
  30. package/domain/index.d.ts +1 -1
  31. package/domain/location/models/address.d.ts +3 -2
  32. package/domain/shop-settings/models/home.d.ts +3 -3
  33. package/domain/shop-settings/models/shop-menu.d.ts +3 -3
  34. package/domain/shop-settings/repositories/home.repository.d.ts +1 -1
  35. package/domain/shop-settings/repositories/shop-menu.repository.d.ts +1 -1
  36. package/domain/shopping/models/buy-2-win.d.ts +3 -5
  37. package/domain/shopping/models/checkout.d.ts +7 -9
  38. package/domain/shopping/models/coupons/coupon.d.ts +13 -15
  39. package/domain/shopping/models/coupons/enums/coupon-subtypes.enum.d.ts +4 -0
  40. package/domain/shopping/models/coupons/enums/coupon-types.enum.d.ts +6 -0
  41. package/domain/shopping/models/coupons/enums/index.d.ts +2 -1
  42. package/domain/shopping/models/coupons/financial-coupon.d.ts +9 -0
  43. package/domain/shopping/models/coupons/index.d.ts +1 -2
  44. package/domain/shopping/models/payment.d.ts +3 -5
  45. package/domain/shopping/models/shipping-method.d.ts +3 -5
  46. package/domain/shopping/models/subscription/checkout.d.ts +3 -5
  47. package/domain/shopping/models/subscription/plan.d.ts +3 -5
  48. package/domain/shopping/repositories/buy-2-win.repository.d.ts +1 -1
  49. package/domain/shopping/repositories/checkout.repository.d.ts +1 -1
  50. package/domain/shopping/repositories/coupon.repository.d.ts +1 -1
  51. package/domain/shopping/repositories/order.repository.d.ts +1 -1
  52. package/domain/shopping/repositories/payment.repository.d.ts +1 -1
  53. package/domain/shopping/repositories/subscription/checkout.repository.d.ts +1 -1
  54. package/domain/shopping/repositories/subscription/plan.repository.d.ts +1 -1
  55. package/domain/users/models/beauty-profile.d.ts +4 -5
  56. package/domain/users/models/lead.d.ts +3 -5
  57. package/domain/users/models/subscription/edition.d.ts +4 -5
  58. package/domain/users/models/subscription/payment.d.ts +4 -5
  59. package/domain/users/models/subscription/subscription.d.ts +3 -5
  60. package/domain/users/models/user-address.d.ts +3 -3
  61. package/domain/users/models/user-payment-method.d.ts +4 -4
  62. package/domain/users/models/user.d.ts +11 -10
  63. package/domain/users/repositories/beauty-profile.repository.d.ts +1 -1
  64. package/domain/users/repositories/edition.repository.d.ts +1 -1
  65. package/domain/users/repositories/lead.repository.d.ts +1 -1
  66. package/domain/users/repositories/subscription-payment.repository.d.ts +1 -1
  67. package/domain/users/repositories/subscription.repository.d.ts +1 -1
  68. package/domain/users/repositories/user-address.repository.d.ts +1 -1
  69. package/domain/users/repositories/user-payment-method.repository.d.ts +1 -1
  70. package/domain/users/repositories/user.repository.d.ts +2 -2
  71. package/esm2015/domain/catalog/models/category.js +5 -2
  72. package/esm2015/domain/catalog/models/product.js +5 -2
  73. package/esm2015/domain/catalog/models/variant.js +5 -2
  74. package/esm2015/domain/catalog/repositories/category.repository.js +1 -1
  75. package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
  76. package/esm2015/domain/catalog/repositories/subscription-product.repository.js +1 -1
  77. package/esm2015/domain/catalog/repositories/variant.repository.js +1 -1
  78. package/esm2015/domain/{general → generic}/index.js +1 -1
  79. package/esm2015/domain/generic/model/base.model.js +23 -0
  80. package/esm2015/domain/{general → generic}/model/identifier-fields.js +1 -1
  81. package/esm2015/domain/generic/model/index.js +4 -0
  82. package/esm2015/domain/generic/model/types/base-model-builder.type.js +2 -0
  83. package/esm2015/domain/generic/model/types/identifier-model.type.js +2 -0
  84. package/esm2015/domain/generic/model/types/index.js +6 -0
  85. package/esm2015/domain/generic/model/types/model-base-structure.type.js +2 -0
  86. package/esm2015/domain/generic/model/types/non-function-properties.type.js +2 -0
  87. package/esm2015/domain/generic/model/types/non-function-property-name.type.js +2 -0
  88. package/esm2015/domain/generic/repository/create.repository.js +2 -0
  89. package/esm2015/domain/generic/repository/crud.repository.js +2 -0
  90. package/esm2015/domain/generic/repository/delete.repository.js +2 -0
  91. package/esm2015/domain/{general → generic}/repository/enums/index.js +1 -1
  92. package/esm2015/domain/{general → generic}/repository/enums/update-option-actions.enum.js +1 -1
  93. package/esm2015/domain/generic/repository/enums/where.enum.js +15 -0
  94. package/esm2015/domain/generic/repository/find.repository.js +2 -0
  95. package/esm2015/domain/generic/repository/get.repository.js +2 -0
  96. package/esm2015/domain/{general → generic}/repository/index.js +1 -1
  97. package/esm2015/domain/generic/repository/read.repository.js +2 -0
  98. package/esm2015/domain/generic/repository/types/index.js +7 -0
  99. package/esm2015/domain/generic/repository/types/repository-find-filters.type.js +2 -0
  100. package/esm2015/domain/{general → generic}/repository/types/repository-find-result.type.js +1 -1
  101. package/esm2015/domain/{general → generic}/repository/types/repository-limit-options.type.js +1 -1
  102. package/esm2015/domain/{general → generic}/repository/types/repository-order-by-list.type.js +1 -1
  103. package/esm2015/domain/generic/repository/types/repository-update-params.type.js +2 -0
  104. package/esm2015/domain/generic/repository/types/where-options.type.js +2 -0
  105. package/esm2015/domain/generic/repository/update.repository.js +2 -0
  106. package/esm2015/domain/index.js +2 -2
  107. package/esm2015/domain/location/models/address.js +5 -2
  108. package/esm2015/domain/shop-settings/models/home.js +3 -3
  109. package/esm2015/domain/shop-settings/models/shop-menu.js +3 -3
  110. package/esm2015/domain/shop-settings/repositories/home.repository.js +1 -1
  111. package/esm2015/domain/shop-settings/repositories/shop-menu.repository.js +1 -1
  112. package/esm2015/domain/shopping/models/buy-2-win.js +3 -3
  113. package/esm2015/domain/shopping/models/checkout.js +6 -15
  114. package/esm2015/domain/shopping/models/coupons/coupon.js +4 -12
  115. package/esm2015/domain/shopping/models/coupons/enums/coupon-subtypes.enum.js +6 -0
  116. package/esm2015/domain/shopping/models/coupons/enums/coupon-types.enum.js +8 -0
  117. package/esm2015/domain/shopping/models/coupons/enums/index.js +3 -2
  118. package/esm2015/domain/shopping/models/coupons/financial-coupon.js +28 -0
  119. package/esm2015/domain/shopping/models/coupons/index.js +2 -3
  120. package/esm2015/domain/shopping/models/payment.js +3 -3
  121. package/esm2015/domain/shopping/models/shipping-method.js +3 -3
  122. package/esm2015/domain/shopping/models/subscription/checkout.js +3 -3
  123. package/esm2015/domain/shopping/models/subscription/plan.js +3 -3
  124. package/esm2015/domain/shopping/repositories/buy-2-win.repository.js +1 -1
  125. package/esm2015/domain/shopping/repositories/checkout.repository.js +1 -1
  126. package/esm2015/domain/shopping/repositories/coupon.repository.js +1 -1
  127. package/esm2015/domain/shopping/repositories/order.repository.js +1 -1
  128. package/esm2015/domain/shopping/repositories/payment.repository.js +1 -1
  129. package/esm2015/domain/shopping/repositories/subscription/checkout.repository.js +1 -1
  130. package/esm2015/domain/shopping/repositories/subscription/plan.repository.js +1 -1
  131. package/esm2015/domain/users/models/beauty-profile.js +4 -4
  132. package/esm2015/domain/users/models/lead.js +3 -3
  133. package/esm2015/domain/users/models/subscription/edition.js +4 -4
  134. package/esm2015/domain/users/models/subscription/payment.js +4 -4
  135. package/esm2015/domain/users/models/subscription/subscription.js +3 -3
  136. package/esm2015/domain/users/models/user-address.js +3 -3
  137. package/esm2015/domain/users/models/user-payment-method.js +4 -4
  138. package/esm2015/domain/users/models/user.js +5 -5
  139. package/esm2015/domain/users/repositories/beauty-profile.repository.js +1 -1
  140. package/esm2015/domain/users/repositories/edition.repository.js +1 -1
  141. package/esm2015/domain/users/repositories/lead.repository.js +1 -1
  142. package/esm2015/domain/users/repositories/subscription-payment.repository.js +1 -1
  143. package/esm2015/domain/users/repositories/subscription.repository.js +1 -1
  144. package/esm2015/domain/users/repositories/user-address.repository.js +1 -1
  145. package/esm2015/domain/users/repositories/user-payment-method.repository.js +1 -1
  146. package/esm2015/domain/users/repositories/user.repository.js +1 -1
  147. package/esm2015/infra/firebase/firestore/mixins/with-create-firestore.mixin.js +2 -2
  148. package/esm2015/infra/firebase/firestore/mixins/with-crud-firestore.mixin.js +1 -1
  149. package/esm2015/infra/firebase/firestore/mixins/with-delete-firestore.mixin.js +1 -1
  150. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +8 -9
  151. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +1 -4
  152. package/esm2015/infra/firebase/firestore/mixins/with-get-firestore.mixin.js +1 -1
  153. package/esm2015/infra/firebase/firestore/mixins/with-helpers.mixin.js +1 -1
  154. package/esm2015/infra/firebase/firestore/mixins/with-sub-collection.mixin.js +1 -1
  155. package/esm2015/infra/firebase/firestore/mixins/with-update-firestore.mixin.js +4 -4
  156. package/esm2015/infra/firebase/firestore/models/user-search.js +3 -3
  157. package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +7 -5
  158. package/esm2015/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.js +11 -21
  159. package/esm2015/infra/firebase/firestore/repositories/users/user-firestore.repository.js +2 -2
  160. package/esm2015/infra/firebase/firestore/types/firestore-sub.repository.type.js +1 -1
  161. package/esm2015/infra/firebase/firestore/types/firestore.helpers.type.js +1 -1
  162. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  163. package/esm2015/infra/hasura-graphql/enums/hasura-graphql-column-type.enum.js +13 -0
  164. package/esm2015/infra/hasura-graphql/enums/hasura-graphql-where.enum.js +15 -0
  165. package/esm2015/infra/hasura-graphql/enums/index.js +3 -0
  166. package/esm2015/infra/hasura-graphql/index.js +4 -0
  167. package/esm2015/infra/hasura-graphql/mixins/helpers/attribute-option.helper.js +15 -0
  168. package/esm2015/infra/hasura-graphql/mixins/helpers/index.js +2 -0
  169. package/esm2015/infra/hasura-graphql/mixins/index.js +8 -0
  170. package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +26 -0
  171. package/esm2015/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.js +10 -0
  172. package/esm2015/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.js +21 -0
  173. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +95 -0
  174. package/esm2015/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.js +31 -0
  175. package/esm2015/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.js +168 -0
  176. package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +45 -0
  177. package/esm2015/infra/hasura-graphql/models/category-hasura-graphql.js +4 -0
  178. package/esm2015/infra/hasura-graphql/models/index.js +2 -0
  179. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +104 -0
  180. package/esm2015/infra/hasura-graphql/repositories/catalog/index.js +3 -0
  181. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +86 -0
  182. package/esm2015/infra/hasura-graphql/repositories/index.js +2 -0
  183. package/esm2015/infra/hasura-graphql/types/fields.type.js +2 -0
  184. package/esm2015/infra/hasura-graphql/types/graphql.repository.type.js +2 -0
  185. package/esm2015/infra/hasura-graphql/types/hasura-graphql-auth-options.type.js +2 -0
  186. package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +2 -0
  187. package/esm2015/infra/hasura-graphql/types/index.js +8 -0
  188. package/esm2015/infra/hasura-graphql/types/nested-field.type.js +2 -0
  189. package/esm2015/infra/hasura-graphql/types/query-builder-options.type.js +2 -0
  190. package/esm2015/infra/hasura-graphql/types/variable-options.type.js +2 -0
  191. package/esm2015/infra/index.js +2 -1
  192. package/esm2015/utils/index.js +6 -4
  193. package/esm2015/utils/is-uuid.js +3 -0
  194. package/esm2015/utils/mixins/index.js +2 -1
  195. package/esm2015/utils/mixins/merge-constructor-params.type.js +2 -0
  196. package/esm2015/utils/mixins/mixin-ctor.type.js +1 -1
  197. package/esm2015/utils/parse-datetime.js +14 -0
  198. package/esm2015/utils/types/array-element.type.js +2 -0
  199. package/esm2015/utils/types/index.js +2 -1
  200. package/fesm2015/infrab4a-connect.js +729 -120
  201. package/fesm2015/infrab4a-connect.js.map +1 -1
  202. package/infra/firebase/firestore/mixins/with-create-firestore.mixin.d.ts +3 -16
  203. package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +3 -28
  204. package/infra/firebase/firestore/mixins/with-delete-firestore.mixin.d.ts +3 -14
  205. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +3 -19
  206. package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +3 -14
  207. package/infra/firebase/firestore/mixins/with-get-firestore.mixin.d.ts +3 -14
  208. package/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +5 -4
  209. package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +7 -14
  210. package/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +6 -15
  211. package/infra/firebase/firestore/models/user-search.d.ts +3 -3
  212. package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +1 -42
  213. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +1 -42
  214. package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +4 -51
  215. package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +1 -42
  216. package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +1 -42
  217. package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +1 -42
  218. package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +1 -42
  219. package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +1 -42
  220. package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +1 -42
  221. package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +1 -42
  222. package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +1 -42
  223. package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +1 -42
  224. package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +1 -42
  225. package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +1 -42
  226. package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +4 -51
  227. package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +1 -42
  228. package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +4 -51
  229. package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +4 -51
  230. package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +4 -51
  231. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -42
  232. package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +4 -51
  233. package/infra/firebase/firestore/repositories/users/user-search-firestore.repository.d.ts +1 -42
  234. package/infra/firebase/firestore/types/firestore-sub.repository.type.d.ts +3 -3
  235. package/infra/firebase/firestore/types/firestore.helpers.type.d.ts +3 -3
  236. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +7 -3
  237. package/infra/hasura-graphql/enums/hasura-graphql-column-type.enum.d.ts +11 -0
  238. package/infra/hasura-graphql/enums/hasura-graphql-where.enum.d.ts +13 -0
  239. package/infra/hasura-graphql/enums/index.d.ts +2 -0
  240. package/infra/hasura-graphql/index.d.ts +3 -0
  241. package/infra/hasura-graphql/mixins/helpers/attribute-option.helper.d.ts +10 -0
  242. package/infra/hasura-graphql/mixins/helpers/index.d.ts +1 -0
  243. package/infra/hasura-graphql/mixins/index.d.ts +7 -0
  244. package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +8 -0
  245. package/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.d.ts +11 -0
  246. package/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.d.ts +7 -0
  247. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +30 -0
  248. package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +24 -0
  249. package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +11 -0
  250. package/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.d.ts +14 -0
  251. package/infra/hasura-graphql/models/category-hasura-graphql.d.ts +4 -0
  252. package/infra/hasura-graphql/models/index.d.ts +1 -0
  253. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +22 -0
  254. package/infra/hasura-graphql/repositories/catalog/index.d.ts +2 -0
  255. package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +10 -0
  256. package/infra/hasura-graphql/repositories/index.d.ts +1 -0
  257. package/infra/hasura-graphql/types/fields.type.d.ts +2 -0
  258. package/infra/hasura-graphql/types/graphql.repository.type.d.ts +21 -0
  259. package/infra/hasura-graphql/types/hasura-graphql-auth-options.type.d.ts +8 -0
  260. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +40 -0
  261. package/infra/hasura-graphql/types/index.d.ts +7 -0
  262. package/infra/hasura-graphql/types/nested-field.type.d.ts +7 -0
  263. package/infra/hasura-graphql/types/query-builder-options.type.d.ts +7 -0
  264. package/infra/hasura-graphql/types/variable-options.type.d.ts +9 -0
  265. package/infra/index.d.ts +1 -0
  266. package/package.json +2 -1
  267. package/utils/index.d.ts +5 -4
  268. package/utils/is-uuid.d.ts +1 -0
  269. package/utils/mixins/index.d.ts +1 -0
  270. package/utils/mixins/merge-constructor-params.type.d.ts +3 -0
  271. package/utils/mixins/mixin-ctor.type.d.ts +1 -1
  272. package/utils/parse-datetime.d.ts +1 -0
  273. package/utils/types/array-element.type.d.ts +1 -0
  274. package/utils/types/index.d.ts +1 -0
  275. package/domain/general/model/base-model-with-identifier-fields.d.ts +0 -3
  276. package/domain/general/model/base.model.d.ts +0 -6
  277. package/domain/general/model/types/base-model-builder.type.d.ts +0 -5
  278. package/domain/general/model/types/non-function-properties.type.d.ts +0 -2
  279. package/domain/general/model/types/non-function-property-name.type.d.ts +0 -3
  280. package/domain/general/repository/create.repository.d.ts +0 -5
  281. package/domain/general/repository/crud.repository.d.ts +0 -7
  282. package/domain/general/repository/delete.repository.d.ts +0 -5
  283. package/domain/general/repository/find.repository.d.ts +0 -5
  284. package/domain/general/repository/get.repository.d.ts +0 -5
  285. package/domain/general/repository/read.repository.d.ts +0 -5
  286. package/domain/general/repository/types/repository-find-filters.type.d.ts +0 -14
  287. package/domain/general/repository/update.repository.d.ts +0 -5
  288. package/domain/shopping/models/coupons/club-coupon.d.ts +0 -7
  289. package/domain/shopping/models/coupons/enums/discount-type.enum.d.ts +0 -5
  290. package/domain/shopping/models/coupons/store-coupon.d.ts +0 -8
  291. package/esm2015/domain/general/model/base-model-with-identifier-fields.js +0 -2
  292. package/esm2015/domain/general/model/base.model.js +0 -13
  293. package/esm2015/domain/general/model/index.js +0 -5
  294. package/esm2015/domain/general/model/types/base-model-builder.type.js +0 -2
  295. package/esm2015/domain/general/model/types/index.js +0 -4
  296. package/esm2015/domain/general/model/types/non-function-properties.type.js +0 -2
  297. package/esm2015/domain/general/model/types/non-function-property-name.type.js +0 -2
  298. package/esm2015/domain/general/repository/create.repository.js +0 -2
  299. package/esm2015/domain/general/repository/crud.repository.js +0 -2
  300. package/esm2015/domain/general/repository/delete.repository.js +0 -2
  301. package/esm2015/domain/general/repository/enums/where.enum.js +0 -12
  302. package/esm2015/domain/general/repository/find.repository.js +0 -2
  303. package/esm2015/domain/general/repository/get.repository.js +0 -2
  304. package/esm2015/domain/general/repository/read.repository.js +0 -2
  305. package/esm2015/domain/general/repository/types/index.js +0 -6
  306. package/esm2015/domain/general/repository/types/repository-find-filters.type.js +0 -2
  307. package/esm2015/domain/general/repository/types/repository-update-params.type.js +0 -2
  308. package/esm2015/domain/general/repository/update.repository.js +0 -2
  309. package/esm2015/domain/shopping/models/coupons/club-coupon.js +0 -18
  310. package/esm2015/domain/shopping/models/coupons/enums/discount-type.enum.js +0 -7
  311. package/esm2015/domain/shopping/models/coupons/store-coupon.js +0 -23
  312. /package/domain/{general → generic}/index.d.ts +0 -0
  313. /package/domain/{general → generic}/model/identifier-fields.d.ts +0 -0
  314. /package/domain/{general → generic}/repository/enums/index.d.ts +0 -0
  315. /package/domain/{general → generic}/repository/enums/update-option-actions.enum.d.ts +0 -0
  316. /package/domain/{general → generic}/repository/index.d.ts +0 -0
  317. /package/domain/{general → generic}/repository/types/repository-find-result.type.d.ts +0 -0
  318. /package/domain/{general → generic}/repository/types/repository-limit-options.type.d.ts +0 -0
  319. /package/domain/{general → generic}/repository/types/repository-order-by-list.type.d.ts +0 -0
@@ -1,35 +1,52 @@
1
1
  import 'reflect-metadata';
2
2
  import { plainToClass, classToPlain, Expose, Type } from 'class-transformer';
3
3
  import { __decorate, __metadata, __awaiter } from 'tslib';
4
- export { add, sub } from 'date-fns';
5
- import { isNil, isNumber, isString, isDate, set, isObject, isEmpty, chunk } from 'lodash';
6
- export { chunk, get, isDate, isEmpty, isNil, isNumber, isObject, isString, pick, set } from 'lodash';
4
+ import { parseISO } from 'date-fns';
5
+ export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
6
+ import { isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1 } from 'lodash';
7
+ export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
8
+ import { Md5 } from 'ts-md5';
7
9
  import axios from 'axios';
8
10
  import firebase from 'firebase';
9
11
  import firebase$1 from 'firebase/app';
12
+ import { mutation, query } from 'gql-query-builder';
13
+ import fetch from 'node-fetch';
10
14
 
11
15
  class BaseModel {
16
+ get identifier() {
17
+ const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
18
+ return fields.reduce((object, field) => (Object.assign(Object.assign({}, object), { [field]: this[field] })), {});
19
+ }
20
+ get identifiersFields() {
21
+ return this.constructor.identifiersFields;
22
+ }
12
23
  constructor(args) {
13
24
  Object.assign(this, args);
14
25
  }
15
26
  static toInstance(data) {
16
- return plainToClass(this, data);
27
+ return plainToClass(this, data || {});
28
+ }
29
+ static isModel(value) {
30
+ return value instanceof this;
17
31
  }
18
32
  toPlain() {
19
- return classToPlain(this, { exposeUnsetFields: false });
33
+ return classToPlain(this);
20
34
  }
21
35
  }
22
36
 
23
37
  var Where;
24
38
  (function (Where) {
25
39
  Where["EQUALS"] = "==";
26
- Where["NOTEQUALS"] = "!=";
27
40
  Where["GT"] = ">";
28
41
  Where["GTE"] = ">=";
29
42
  Where["IN"] = "in";
43
+ Where["NOTIN"] = "not in";
30
44
  Where["LT"] = "<";
31
45
  Where["LTE"] = "<=";
32
46
  Where["LIKE"] = "like";
47
+ Where["NOTLIKE"] = "not like";
48
+ Where["ISNULL"] = "is null";
49
+ Where["ISNOTNULL"] = "is not null";
33
50
  })(Where || (Where = {}));
34
51
 
35
52
  var UpdateOptionActions;
@@ -262,13 +279,13 @@ var Status;
262
279
  })(Status || (Status = {}));
263
280
 
264
281
  class Edition extends BaseModel {
265
- identifierFields() {
266
- return ['id'];
282
+ static get identifiersFields() {
283
+ return ['id', 'subscriptionId'];
267
284
  }
268
285
  }
269
286
 
270
287
  class Payment extends BaseModel {
271
- identifierFields() {
288
+ static get identifiersFields() {
272
289
  return ['id'];
273
290
  }
274
291
  }
@@ -434,8 +451,8 @@ __decorate([
434
451
  ], Payment.prototype, "pixExpirationDate", void 0);
435
452
 
436
453
  class SubscriptionPayment extends BaseModel {
437
- identifierFields() {
438
- return ['id'];
454
+ static get identifiersFields() {
455
+ return ['id', 'subscriptionId'];
439
456
  }
440
457
  }
441
458
  __decorate([
@@ -444,6 +461,9 @@ __decorate([
444
461
  ], SubscriptionPayment.prototype, "payment", void 0);
445
462
 
446
463
  class Address extends BaseModel {
464
+ static get identifiersFields() {
465
+ return ['id'];
466
+ }
447
467
  }
448
468
 
449
469
  var CheckoutTypes;
@@ -458,12 +478,33 @@ class Base {
458
478
  }
459
479
  }
460
480
 
461
- var DiscountType;
462
- (function (DiscountType) {
463
- DiscountType[DiscountType["ABSOLUTE"] = 1] = "ABSOLUTE";
464
- DiscountType[DiscountType["PERCENTAGE"] = 2] = "PERCENTAGE";
465
- DiscountType[DiscountType["FREE_SHIPPING"] = 3] = "FREE_SHIPPING";
466
- })(DiscountType || (DiscountType = {}));
481
+ 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);
482
+
483
+ const parseDateTime = (value) => {
484
+ if (!isString(value))
485
+ return value;
486
+ if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(value) &&
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))
488
+ return value;
489
+ const date = parseISO(value);
490
+ if (isNaN(date.getTime()))
491
+ return value;
492
+ return date;
493
+ };
494
+
495
+ var CouponTypes;
496
+ (function (CouponTypes) {
497
+ CouponTypes[CouponTypes["FINANCIAL"] = 1] = "FINANCIAL";
498
+ CouponTypes[CouponTypes["PRODUCT"] = 2] = "PRODUCT";
499
+ CouponTypes[CouponTypes["GIFTCARD"] = 3] = "GIFTCARD";
500
+ CouponTypes[CouponTypes["VOUCHER"] = 4] = "VOUCHER";
501
+ })(CouponTypes || (CouponTypes = {}));
502
+
503
+ var CouponSubtypes;
504
+ (function (CouponSubtypes) {
505
+ CouponSubtypes[CouponSubtypes["ABSOLUTE"] = 1] = "ABSOLUTE";
506
+ CouponSubtypes[CouponSubtypes["PERCENTAGE"] = 2] = "PERCENTAGE";
507
+ })(CouponSubtypes || (CouponSubtypes = {}));
467
508
 
468
509
  var Exclusivities;
469
510
  (function (Exclusivities) {
@@ -476,17 +517,9 @@ class Coupon extends BaseModel {
476
517
  get isInfluencer() {
477
518
  return !isNil(this.influencerEmail);
478
519
  }
479
- identifierFields() {
520
+ static get identifiersFields() {
480
521
  return ['id'];
481
522
  }
482
- calculeDiscount(amount) {
483
- switch (this.discountType) {
484
- case DiscountType.ABSOLUTE:
485
- return this.discount < amount ? this.discount : amount;
486
- case DiscountType.PERCENTAGE:
487
- return this.discount * 0.01 * amount;
488
- }
489
- }
490
523
  }
491
524
  __decorate([
492
525
  Expose({ name: 'checkout_type' }),
@@ -498,7 +531,7 @@ __decorate([
498
531
  ], Coupon.prototype, "exclusivityType", void 0);
499
532
 
500
533
  class SubscriptionPlan extends BaseModel {
501
- identifierFields() {
534
+ static get identifiersFields() {
502
535
  return ['id'];
503
536
  }
504
537
  }
@@ -509,8 +542,8 @@ class BeautyProfile extends BaseModel {
509
542
  delete plain.id;
510
543
  return plain;
511
544
  }
512
- identifierFields() {
513
- return ['id'];
545
+ static get identifiersFields() {
546
+ return ['id', 'userId'];
514
547
  }
515
548
  }
516
549
 
@@ -521,14 +554,14 @@ class User extends BaseModel {
521
554
  instance.displayName = `${data.firstName}${!isNil(data.lastName) ? ` ${data.lastName}` : ''}`;
522
555
  return instance;
523
556
  }
524
- identifierFields() {
525
- return ['id'];
526
- }
527
557
  toPlain() {
528
558
  const plain = super.toPlain();
529
559
  delete plain.beautyProfile;
530
560
  return plain;
531
561
  }
562
+ static get identifiersFields() {
563
+ return ['id'];
564
+ }
532
565
  }
533
566
  __decorate([
534
567
  Type(() => BeautyProfile),
@@ -536,7 +569,7 @@ __decorate([
536
569
  ], User.prototype, "beautyProfile", void 0);
537
570
 
538
571
  class Subscription extends BaseModel {
539
- identifierFields() {
572
+ static get identifiersFields() {
540
573
  return ['id'];
541
574
  }
542
575
  }
@@ -570,19 +603,19 @@ __decorate([
570
603
  ], Subscription.prototype, "payment", void 0);
571
604
 
572
605
  class UserAddress extends Address {
573
- identifierFields() {
574
- return ['id'];
606
+ static get identifiersFields() {
607
+ return ['id', 'userId'];
575
608
  }
576
609
  }
577
610
 
578
611
  class UserPaymentMethod extends BaseModel {
579
- identifierFields() {
580
- return ['id'];
612
+ static get identifiersFields() {
613
+ return ['id', 'userId'];
581
614
  }
582
615
  }
583
616
 
584
617
  class Lead extends BaseModel {
585
- identifierFields() {
618
+ static get identifiersFields() {
586
619
  return ['id'];
587
620
  }
588
621
  }
@@ -708,6 +741,9 @@ class Category extends BaseModel {
708
741
  identifierFields() {
709
742
  return ['id'];
710
743
  }
744
+ static get identifiersFields() {
745
+ return ['id'];
746
+ }
711
747
  }
712
748
 
713
749
  class Product extends BaseModel {
@@ -718,45 +754,43 @@ class Product extends BaseModel {
718
754
  var _a, _b, _c, _d, _e, _f;
719
755
  return Object.assign(Object.assign(Object.assign({}, (((_b = (_a = this.description) === null || _a === void 0 ? void 0 : _a[shop]) === null || _b === void 0 ? void 0 : _b.description) ? { description: (_d = (_c = this.description) === null || _c === void 0 ? void 0 : _c[shop]) === null || _d === void 0 ? void 0 : _d.description } : {})), (((_e = this.price) === null || _e === void 0 ? void 0 : _e[shop]) || {})), (((_f = this.stock) === null || _f === void 0 ? void 0 : _f[shop]) || {}));
720
756
  }
757
+ static get identifiersFields() {
758
+ return ['id'];
759
+ }
721
760
  }
722
761
 
723
762
  class Variant extends BaseModel {
724
763
  identifierFields() {
725
764
  return ['id'];
726
765
  }
727
- }
728
-
729
- class ClubCoupon extends Coupon {
730
- constructor() {
731
- super(...arguments);
732
- this.checkoutType = CheckoutTypes.SUBSCRIPTION;
733
- }
734
- static isClubCoupon(coupon) {
735
- return coupon instanceof ClubCoupon;
766
+ static get identifiersFields() {
767
+ return ['id', 'productId'];
736
768
  }
737
769
  }
738
- __decorate([
739
- Expose({ name: 'checkout_type' }),
740
- __metadata("design:type", Object)
741
- ], ClubCoupon.prototype, "checkoutType", void 0);
742
770
 
743
- class StoreCoupon extends Coupon {
771
+ const COUPON_EXPIRATION = 60 * 60 * 24 * 30;
772
+ class FinancialCoupon extends Coupon {
744
773
  constructor() {
745
774
  super(...arguments);
746
- this.checkoutType = CheckoutTypes.ECOMMERCE;
747
- }
748
- static isStoreCoupon(coupon) {
749
- return coupon instanceof StoreCoupon;
775
+ this.type = CouponTypes.FINANCIAL;
776
+ }
777
+ static isFinancialCoupon(coupon) {
778
+ return coupon.type === CouponTypes.FINANCIAL && !!coupon.subtype;
779
+ }
780
+ static createCoupon(userId) {
781
+ return this.toInstance({
782
+ name: Md5.hashStr(`${userId}_${Date.now}`).toString(),
783
+ nickname: `${Date.now()}`,
784
+ type: CouponTypes.FINANCIAL,
785
+ subtype: CouponSubtypes.PERCENTAGE,
786
+ checkoutType: CheckoutTypes.ECOMMERCE,
787
+ discount: 30,
788
+ user: userId,
789
+ createdAt: new Date(Date.now()),
790
+ expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
791
+ });
750
792
  }
751
793
  }
752
- __decorate([
753
- Expose({ name: 'checkout_type' }),
754
- __metadata("design:type", Object)
755
- ], StoreCoupon.prototype, "checkoutType", void 0);
756
- __decorate([
757
- Type(() => Category),
758
- __metadata("design:type", Array)
759
- ], StoreCoupon.prototype, "categories", void 0);
760
794
 
761
795
  var OrderStatus;
762
796
  (function (OrderStatus) {
@@ -774,22 +808,13 @@ class LineItem extends Product {
774
808
  }
775
809
 
776
810
  class ShippingMethod extends BaseModel {
777
- identifierFields() {
811
+ static get identifiersFields() {
778
812
  return ['id'];
779
813
  }
780
814
  }
781
815
 
782
816
  class Checkout extends BaseModel {
783
- get subTotalPrice() {
784
- return this.lineItems.reduce((total, item) => {
785
- return total + item.pricePaid;
786
- }, 0);
787
- }
788
- get totalPrice() {
789
- var _a;
790
- return this.subTotalPrice + ((_a = this.shipping) === null || _a === void 0 ? void 0 : _a.ShippingPrice) - this.discount;
791
- }
792
- identifierFields() {
817
+ static get identifiersFields() {
793
818
  return ['id'];
794
819
  }
795
820
  }
@@ -814,8 +839,8 @@ __decorate([
814
839
  __metadata("design:type", ShippingMethod)
815
840
  ], Checkout.prototype, "shipping", void 0);
816
841
  __decorate([
817
- Type(() => StoreCoupon),
818
- __metadata("design:type", StoreCoupon)
842
+ Type(() => Coupon),
843
+ __metadata("design:type", Coupon)
819
844
  ], Checkout.prototype, "coupon", void 0);
820
845
 
821
846
  class Order extends Checkout {
@@ -826,7 +851,7 @@ __decorate([
826
851
  ], Order.prototype, "payment", void 0);
827
852
 
828
853
  class CheckoutSubscription extends BaseModel {
829
- identifierFields() {
854
+ static get identifiersFields() {
830
855
  return ['id'];
831
856
  }
832
857
  }
@@ -848,7 +873,7 @@ __decorate([
848
873
  ], CheckoutSubscription.prototype, "coupon", void 0);
849
874
 
850
875
  class Buy2Win extends BaseModel {
851
- identifierFields() {
876
+ static get identifiersFields() {
852
877
  return ['id'];
853
878
  }
854
879
  }
@@ -944,13 +969,13 @@ class BeautyQuestionsHelper {
944
969
  }
945
970
 
946
971
  class Home extends BaseModel {
947
- identifierFields() {
972
+ static get identifiersFields() {
948
973
  return ['id'];
949
974
  }
950
975
  }
951
976
 
952
977
  class ShopMenu extends BaseModel {
953
- identifierFields() {
978
+ static get identifiersFields() {
954
979
  return ['id'];
955
980
  }
956
981
  }
@@ -1063,9 +1088,6 @@ class ProductsIndex {
1063
1088
 
1064
1089
  const withFirestore = (MixinBase) => {
1065
1090
  return class extends MixinBase {
1066
- constructor(...args) {
1067
- super(args);
1068
- }
1069
1091
  collection(path) {
1070
1092
  return this.firestore.collection(path || this.collectionName).withConverter(this.buildModelInstance());
1071
1093
  }
@@ -1155,16 +1177,16 @@ const withFindFirestore = (MixinBase) => {
1155
1177
  if ((options === null || options === void 0 ? void 0 : options.operator) === Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
1156
1178
  return queryReference.where(firestoreFieldName, 'array-contains', options.value);
1157
1179
  if (isObject(options) && isNil(options === null || options === void 0 ? void 0 : options.operator) && isNil(options === null || options === void 0 ? void 0 : options.value)) {
1158
- return Object.keys(options).reduce((queryReferenceWithWhere, key) => this.buildWhereSentence(queryReferenceWithWhere, `${fieldName}.${key}`, options[key]), queryReference);
1180
+ return Object.keys(options).reduce((queryReferenceWithWhere, key) => this.buildWhereSentence(queryReferenceWithWhere, `${fieldName.toString()}.${key}`, options[key]), queryReference);
1159
1181
  }
1160
1182
  return queryReference.where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
1161
1183
  };
1162
1184
  }
1163
- find(filters, limits, orderBy) {
1185
+ find({ filters, limits, orderBy, }) {
1164
1186
  return __awaiter(this, void 0, void 0, function* () {
1165
1187
  let query = this.collection(this.buildCollectionPathForFind(filters));
1166
- filters === null || filters === void 0 ? void 0 : filters.forEach((filterer) => (query = this.makeFirestoreWhere(query, filterer)));
1167
- orderBy === null || orderBy === void 0 ? void 0 : orderBy.forEach((orderer) => Object.keys(orderer).forEach((fieldName) => (query = query.orderBy(fieldName, orderer[fieldName]))));
1188
+ query = this.makeFirestoreWhere(query, filters);
1189
+ Object.keys(orderBy).forEach((fieldName) => (query = query.orderBy(fieldName, orderBy[fieldName])));
1168
1190
  query = yield this.defineLimits(query, filters, limits);
1169
1191
  const docs = yield query.get();
1170
1192
  const data = docs.docs.map((doc) => doc.data());
@@ -1175,19 +1197,18 @@ const withFindFirestore = (MixinBase) => {
1175
1197
  });
1176
1198
  }
1177
1199
  buildCollectionPathForFind(filters) {
1178
- var _a;
1179
1200
  if (!this.isSubCollection(this))
1180
1201
  return this.collectionName;
1181
1202
  const parentIdField = this.parentIdField;
1182
- const parentId = getValueFromFilter((_a = filters.find((groupFilter) => Boolean(getValueFromFilter(groupFilter[parentIdField])))) === null || _a === void 0 ? void 0 : _a[parentIdField]);
1203
+ const parentId = getValueFromFilter(filters === null || filters === void 0 ? void 0 : filters[parentIdField]);
1183
1204
  return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
1184
1205
  }
1185
1206
  defineLimits(query, filters, limits) {
1186
1207
  return __awaiter(this, void 0, void 0, function* () {
1187
1208
  if (limits === null || limits === void 0 ? void 0 : limits.offset) {
1188
- if (limits.offset instanceof this.model)
1209
+ if (this.model.isModel(limits.offset))
1189
1210
  query = query.startAfter(yield this.collection(this.buildCollectionPathForFind(filters))
1190
- .doc(limits.offset[limits.offset.identifierFields().shift()])
1211
+ .doc(limits.offset[limits.offset.identifiersFields.shift()])
1191
1212
  .get());
1192
1213
  else if (isNumber(limits.offset) || isString(limits.offset))
1193
1214
  query = query.startAt(limits.offset);
@@ -1219,7 +1240,7 @@ const withCreateFirestore = (MixinBase) => {
1219
1240
  save(data) {
1220
1241
  var _a;
1221
1242
  return __awaiter(this, void 0, void 0, function* () {
1222
- const id = (_a = data[data.identifierFields().shift()]) === null || _a === void 0 ? void 0 : _a.toString();
1243
+ const id = (_a = data[data.identifiersFields.shift()]) === null || _a === void 0 ? void 0 : _a.toString();
1223
1244
  const collectionPath = this.buildCollectionPathForAdd(data);
1224
1245
  if (isEmpty(id))
1225
1246
  return this.collection(collectionPath).add(data);
@@ -1256,7 +1277,7 @@ const withUpdateFirestore = (MixinBase) => {
1256
1277
  update(data) {
1257
1278
  return __awaiter(this, void 0, void 0, function* () {
1258
1279
  const model = new this.model();
1259
- const keyField = model.identifierFields().shift();
1280
+ const keyField = model.identifiersFields.shift();
1260
1281
  const docRef = this.collection(this.buildCollectionPathForUpdate(data)).doc(getValueFromParams(data, keyField).toString());
1261
1282
  yield docRef.set(this.paramsToPlain(data), { merge: true });
1262
1283
  const doc = yield docRef.get();
@@ -1270,8 +1291,8 @@ const withUpdateFirestore = (MixinBase) => {
1270
1291
  }
1271
1292
  paramsToPlain(params) {
1272
1293
  const model = this.model;
1273
- if (params instanceof model)
1274
- return params;
1294
+ if (model.isModel(params))
1295
+ return params.toPlain();
1275
1296
  return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), { [currentKey]: getValueByAction(params[currentKey]) })), {});
1276
1297
  }
1277
1298
  };
@@ -1320,7 +1341,7 @@ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(with
1320
1341
  }
1321
1342
 
1322
1343
  class UserSearch extends BaseModel {
1323
- identifierFields() {
1344
+ static get identifiersFields() {
1324
1345
  return ['id'];
1325
1346
  }
1326
1347
  }
@@ -1355,7 +1376,7 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1355
1376
  }
1356
1377
  checkIfExistsByField(field, value) {
1357
1378
  return __awaiter(this, void 0, void 0, function* () {
1358
- const result = yield this.userSearchFirestoreRepository.find([{ [field]: { operator: Where.EQUALS, value } }]);
1379
+ const result = yield this.userSearchFirestoreRepository.find({ [field]: { operator: Where.EQUALS, value } });
1359
1380
  return result.count > 0;
1360
1381
  });
1361
1382
  }
@@ -1538,10 +1559,12 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
1538
1559
  getBySlug(slug, shop) {
1539
1560
  var _a;
1540
1561
  return __awaiter(this, void 0, void 0, function* () {
1541
- const result = yield this.find([
1542
- { slug: { operator: Where.EQUALS, value: slug } },
1543
- { shopAvailability: { operator: Where.IN, value: [shop] } },
1544
- ]);
1562
+ const result = yield this.find({
1563
+ filters: {
1564
+ slug: { operator: Where.EQUALS, value: slug },
1565
+ shopAvailability: { operator: Where.IN, value: [shop] },
1566
+ },
1567
+ });
1545
1568
  return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
1546
1569
  });
1547
1570
  }
@@ -1584,28 +1607,19 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
1584
1607
  this.model = Coupon;
1585
1608
  }
1586
1609
  buildModelInstance() {
1610
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
1587
1611
  return {
1588
1612
  toFirestore: (data) => {
1589
- var _a;
1590
- const plain = (data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data;
1591
- if (!!plain.categories)
1592
- plain.categories = (_a = plain === null || plain === void 0 ? void 0 : plain.categories) === null || _a === void 0 ? void 0 : _a.map((category) => category.id);
1613
+ const plain = toFirestore(data);
1614
+ if (!!data.expiresIn)
1615
+ plain.expiresIn = data.expiresIn.getTime();
1593
1616
  return plain;
1594
1617
  },
1595
1618
  fromFirestore: (snap) => {
1596
- var _a;
1597
- const data = snap.data();
1598
- Object.keys(data).forEach((key) => {
1599
- if (data[key] instanceof firebase.firestore.Timestamp) {
1600
- data[key] = data[key].toDate();
1601
- }
1602
- });
1603
- data.categories = (_a = data === null || data === void 0 ? void 0 : data.categories) === null || _a === void 0 ? void 0 : _a.map((category) => ({ id: category }));
1604
- if (data.checkout_type === CheckoutTypes.SUBSCRIPTION)
1605
- return ClubCoupon.toInstance(Object.assign({ id: snap.id }, data));
1606
- if (data.checkout_type === CheckoutTypes.ECOMMERCE)
1607
- return StoreCoupon.toInstance(Object.assign({ id: snap.id }, data));
1608
- return this.model.toInstance(Object.assign({ id: snap.id }, data));
1619
+ const instance = fromFirestore(snap);
1620
+ if (!isNil(instance.expiresIn))
1621
+ instance.expiresIn = new Date(snap.data().expiresIn);
1622
+ return instance;
1609
1623
  },
1610
1624
  };
1611
1625
  }
@@ -1799,9 +1813,604 @@ class RegisterFirebaseAuthService {
1799
1813
  }
1800
1814
  }
1801
1815
 
1816
+ const withCreateHasuraGraphQL = (MixinBase) => {
1817
+ return class CreateHasuraGraphQLMixin extends MixinBase {
1818
+ constructor(...params) {
1819
+ const options = params === null || params === void 0 ? void 0 : params[0];
1820
+ super(...params);
1821
+ this.insertGraphQLOperation = (options === null || options === void 0 ? void 0 : options.insertGraphQLOperation) || `insert_${this.tableName}_one`;
1822
+ this.insertGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.insertGraphQLObjectType) || `${this.tableName}_insert_input`;
1823
+ }
1824
+ create(data) {
1825
+ return __awaiter(this, void 0, void 0, function* () {
1826
+ const newData = yield this.save(this.model.toInstance(data));
1827
+ return this.model.toInstance(newData);
1828
+ });
1829
+ }
1830
+ save(data) {
1831
+ return __awaiter(this, void 0, void 0, function* () {
1832
+ const result = yield this.mutation(this.insertGraphQLOperation, this.model.identifiersFields, {
1833
+ object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
1834
+ });
1835
+ return Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain());
1836
+ });
1837
+ }
1838
+ };
1839
+ };
1840
+
1841
+ const withDeleteHasuraGraphQL = (MixinBase) => {
1842
+ return class DeleteHasuraGraphQLMixin extends MixinBase {
1843
+ constructor(...params) {
1844
+ const options = params === null || params === void 0 ? void 0 : params[0];
1845
+ super(...params);
1846
+ this.deleteGraphQLOperation = (options === null || options === void 0 ? void 0 : options.deleteGraphQLOperation) || `delete_${this.tableName}_by_pk`;
1847
+ }
1848
+ delete(identifiers) {
1849
+ return __awaiter(this, void 0, void 0, function* () {
1850
+ const instance = this.model.toInstance(identifiers);
1851
+ yield this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields, Object.keys(instance.identifier).reduce((variables, key) => (Object.assign(Object.assign({}, variables), { [key]: {
1852
+ type: this.getAttributeGraphQLTypeOf(instance[key]),
1853
+ required: true,
1854
+ value: instance.identifier[key],
1855
+ } })), {}));
1856
+ });
1857
+ }
1858
+ };
1859
+ };
1860
+
1861
+ class AttributeOptionHelper {
1862
+ }
1863
+ AttributeOptionHelper.findByAttribute = (attributeName, fields) => {
1864
+ if (fields.includes(attributeName))
1865
+ return { columnName: attributeName.toString(), attributeName };
1866
+ const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
1867
+ const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
1868
+ if (isNil(fieldOption))
1869
+ return { columnName: attributeName.toString(), attributeName };
1870
+ if (Array.isArray(fieldOption))
1871
+ return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
1872
+ return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
1873
+ };
1874
+
1875
+ const withHasuraGraphQL = (MixinBase) => {
1876
+ const checkIsGraphQLParams = (params) => !isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
1877
+ const checkIsColumnModelOption = (fieldValue) => !!fieldValue.columnName && !!fieldValue.fields;
1878
+ const checkIsColumnOption = (fieldValue) => checkIsColumnModelOption(fieldValue) || !!fieldValue.columnName;
1879
+ const convertModelFieldsToGraphQLFields = (fields) => {
1880
+ return fields
1881
+ .map((field) => {
1882
+ if (isString(field))
1883
+ return field.toString();
1884
+ const fieldName = Object.keys(field).shift();
1885
+ const fieldValue = field[fieldName];
1886
+ if (Array.isArray(fieldValue))
1887
+ return { [fieldName]: convertModelFieldsToGraphQLFields(fieldValue) };
1888
+ if (checkIsColumnModelOption(fieldValue))
1889
+ return { [fieldValue.columnName || fieldName]: convertModelFieldsToGraphQLFields(fieldValue.fields) };
1890
+ if (checkIsColumnOption(fieldValue))
1891
+ return fieldValue.columnName;
1892
+ return;
1893
+ })
1894
+ .filter((field) => !!field);
1895
+ };
1896
+ const findColumnOptionFromList = (columnName, fields) => {
1897
+ if (fields.includes(columnName))
1898
+ return { columnName, attributeName: columnName };
1899
+ const field = fields.find((columnOption) => {
1900
+ var _a;
1901
+ return isObject(columnOption) &&
1902
+ ((_a = Object.values(columnOption).find((option) => checkIsColumnOption(option) && option.columnName === columnName)) === null || _a === void 0 ? void 0 : _a.columnName) === columnName;
1903
+ }) || {};
1904
+ const attributeName = Object.keys(field).find((fieldOption) => checkIsColumnOption(field[fieldOption]) || Array.isArray(field[fieldOption]));
1905
+ const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
1906
+ if (Array.isArray(fieldOption))
1907
+ return { attributeName: attributeName, fields: fieldOption };
1908
+ return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
1909
+ };
1910
+ const convertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
1911
+ const { attributeName, fields: attributeFields, from } = findColumnOptionFromList(columnName, fields);
1912
+ if (!!attributeFields && Array.isArray(attributeFields)) {
1913
+ if (Array.isArray(data[columnName]))
1914
+ return Object.assign(Object.assign({}, result), { [attributeName]: from
1915
+ ? from(data[columnName], data)
1916
+ : data[columnName].map((value) => convertFieldValueFrom(value, attributeFields)) });
1917
+ if (isObject(data[columnName]))
1918
+ return Object.assign(Object.assign({}, result), { [attributeName]: convertFieldValueFrom(data[columnName], attributeFields) });
1919
+ }
1920
+ if (!!from)
1921
+ return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
1922
+ return Object.assign(Object.assign({}, result), { [attributeName]: parseDateTime(data[columnName]) });
1923
+ }, {});
1924
+ const convertFieldValueTo = (instance, fields, update = false) => {
1925
+ var _a;
1926
+ const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
1927
+ return Object.keys(data)
1928
+ .filter((key) => !isNil(data[key]))
1929
+ .reduce((result, attributeName) => {
1930
+ const { columnName, fields: attributeFields, foreignKeyColumn, to, } = AttributeOptionHelper.findByAttribute(attributeName, fields);
1931
+ if (isNil(columnName))
1932
+ return result;
1933
+ if (!!foreignKeyColumn &&
1934
+ !isEmpty(foreignKeyColumn) &&
1935
+ !Object.keys(foreignKeyColumn).filter((key) => !data[attributeName][key]).length)
1936
+ return Object.keys(foreignKeyColumn).reduce((object, current) => (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: data[attributeName][current] })), Object.assign({}, result));
1937
+ if (update && isObject(data[attributeName]) && !isDate(data[attributeName]))
1938
+ return result;
1939
+ if (!!columnName && Array.isArray(attributeFields) && isObject(data[attributeName])) {
1940
+ const converted = !isNil(columnName) ? to(instance[attributeName], instance) : data[attributeName];
1941
+ return Object.assign(Object.assign({}, result), (converted !== undefined
1942
+ ? { [columnName]: { data: convertFieldValueTo(data[attributeName], attributeFields) } }
1943
+ : {}));
1944
+ }
1945
+ if (!!to)
1946
+ return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
1947
+ return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
1948
+ }, {});
1949
+ };
1950
+ return class HasuraGraphQLMixin extends MixinBase {
1951
+ constructor(...params) {
1952
+ const options = params[0];
1953
+ super(...params);
1954
+ this.tableName = options.tableName;
1955
+ this.endpoint = options.endpoint;
1956
+ this.authOptions = options.authOptions;
1957
+ this.model = options.model;
1958
+ this.fields = options.fields || this.model.identifiersFields;
1959
+ }
1960
+ get headers() {
1961
+ 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)
1962
+ ? {}
1963
+ : { 'X-Hasura-Role': this.authOptions.authRole.role, 'X-Hasura-User-Id': this.authOptions.authRole.userId }));
1964
+ }
1965
+ mutation(operation, fields, variables) {
1966
+ return __awaiter(this, void 0, void 0, function* () {
1967
+ const resultQuery = mutation({
1968
+ operation,
1969
+ variables,
1970
+ fields: convertModelFieldsToGraphQLFields(fields),
1971
+ });
1972
+ return this.fetch(resultQuery);
1973
+ });
1974
+ }
1975
+ query(operation, fields, variables) {
1976
+ return __awaiter(this, void 0, void 0, function* () {
1977
+ const resultQuery = checkIsGraphQLParams(operation)
1978
+ ? query(operation.map((option) => ({
1979
+ operation: option.operation,
1980
+ variables: option.variables,
1981
+ fields: convertModelFieldsToGraphQLFields(option.fields),
1982
+ })))
1983
+ : query({
1984
+ operation,
1985
+ variables,
1986
+ fields: convertModelFieldsToGraphQLFields(fields),
1987
+ });
1988
+ return this.fetch(resultQuery);
1989
+ });
1990
+ }
1991
+ fetch(params) {
1992
+ return __awaiter(this, void 0, void 0, function* () {
1993
+ const headers = this.headers;
1994
+ const response = yield fetch(`${this.endpoint}`, {
1995
+ method: 'POST',
1996
+ body: JSON.stringify(params),
1997
+ headers,
1998
+ });
1999
+ const result = yield response.json();
2000
+ if (!isNil(result.errors))
2001
+ throw new Error(JSON.stringify(result.errors));
2002
+ return result.data;
2003
+ });
2004
+ }
2005
+ getAttributeGraphQLTypeOf(value) {
2006
+ if (isUUID(value))
2007
+ return 'uuid';
2008
+ if (isString(value))
2009
+ return 'String';
2010
+ if (isBoolean(value))
2011
+ return 'Boolean';
2012
+ if (value instanceof Date)
2013
+ return 'timestamptz';
2014
+ if (isInteger(value))
2015
+ return 'Int';
2016
+ if (isNumber(value))
2017
+ return 'numeric';
2018
+ throw new Error('Type not implemented yet');
2019
+ }
2020
+ checkIfIsDateTimeAndParse(value) {
2021
+ if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(value))
2022
+ return value;
2023
+ const date = parseISO(value);
2024
+ if (isNaN$1(date.getTime()))
2025
+ return value;
2026
+ return date;
2027
+ }
2028
+ convertDataFromHasura(data) {
2029
+ const plain = convertFieldValueFrom(data, this.fields);
2030
+ return this.model.toInstance(plain);
2031
+ }
2032
+ convertDataToHasura(instance, update = false) {
2033
+ return convertFieldValueTo(instance, this.fields, update);
2034
+ }
2035
+ };
2036
+ };
2037
+
2038
+ const withUpdateHasuraGraphQL = (MixinBase) => {
2039
+ const getValueByAction = (options) => {
2040
+ if (isNil(options.action))
2041
+ return options;
2042
+ if (options.action === UpdateOptionActions.REMOVE_FIELD)
2043
+ return null;
2044
+ return options.value;
2045
+ };
2046
+ return class UpdateHasuraGraphQLMixin extends MixinBase {
2047
+ constructor(...params) {
2048
+ const options = params === null || params === void 0 ? void 0 : params[0];
2049
+ super(...params);
2050
+ this.updateGraphQLOperation = (options === null || options === void 0 ? void 0 : options.updateGraphQLOperation) || `update_${this.tableName}_by_pk`;
2051
+ this.updateGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.updateGraphQLObjectType) || `${this.tableName}_set_input`;
2052
+ this.updateGraphQLPKType = (options === null || options === void 0 ? void 0 : options.updateGraphQLPKType) || `${this.tableName}_pk_columns_input`;
2053
+ }
2054
+ update(data) {
2055
+ return __awaiter(this, void 0, void 0, function* () {
2056
+ const plainData = this.paramsToPlain(data);
2057
+ yield this.mutation(this.updateGraphQLOperation, this.model.identifiersFields, {
2058
+ _set: {
2059
+ type: this.updateGraphQLObjectType,
2060
+ value: this.convertDataToHasura(this.model.toInstance(plainData), true),
2061
+ required: true,
2062
+ },
2063
+ pk_columns: { type: this.updateGraphQLPKType, value: this.getUpdateModelKeys(plainData), required: true },
2064
+ });
2065
+ return this.model.toInstance(plainData);
2066
+ });
2067
+ }
2068
+ paramsToPlain(params) {
2069
+ const model = this.model;
2070
+ if (model.isModel(params))
2071
+ return params.toPlain();
2072
+ return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), { [currentKey]: getValueByAction(params[currentKey]) })), {});
2073
+ }
2074
+ getUpdateModelKeys(data) {
2075
+ return this.model.identifiersFields.reduce((columns, key) => (Object.assign(Object.assign({}, columns), { [key]: data[key] })), {});
2076
+ }
2077
+ };
2078
+ };
2079
+
2080
+ const withGetHasuraGraphQL = (MixinBase) => {
2081
+ return class GetHasuraGraphQLMixin extends MixinBase {
2082
+ constructor(...params) {
2083
+ const options = params === null || params === void 0 ? void 0 : params[0];
2084
+ super(...params);
2085
+ this.getGraphQLOperation = (options === null || options === void 0 ? void 0 : options.getGraphQLOperation) || `${this.tableName}_by_pk`;
2086
+ }
2087
+ get(identifiers) {
2088
+ return __awaiter(this, void 0, void 0, function* () {
2089
+ const instance = this.model.toInstance(identifiers);
2090
+ const result = yield this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => (Object.assign(Object.assign({}, ids), (instance[identifier] === undefined
2091
+ ? {}
2092
+ : {
2093
+ [identifier]: {
2094
+ type: this.getAttributeGraphQLTypeOf(instance[identifier]),
2095
+ value: identifiers[identifier],
2096
+ required: true,
2097
+ },
2098
+ }))), {}));
2099
+ const data = result[this.getGraphQLOperation];
2100
+ if (isNil(data))
2101
+ throw new NotFoundError(`${instance.constructor.name} not found`);
2102
+ return this.convertDataFromHasura(result[this.getGraphQLOperation]);
2103
+ });
2104
+ }
2105
+ };
2106
+ };
2107
+
2108
+ var HasuraGraphQLWhere;
2109
+ (function (HasuraGraphQLWhere) {
2110
+ HasuraGraphQLWhere["EQUALS"] = "_eq";
2111
+ HasuraGraphQLWhere["GT"] = "_gt";
2112
+ HasuraGraphQLWhere["GTE"] = "_gte";
2113
+ HasuraGraphQLWhere["IN"] = "_in";
2114
+ HasuraGraphQLWhere["NOTIN"] = "_nin";
2115
+ HasuraGraphQLWhere["LT"] = "_lt";
2116
+ HasuraGraphQLWhere["LTE"] = "_lte";
2117
+ HasuraGraphQLWhere["LIKE"] = "_like";
2118
+ HasuraGraphQLWhere["NOTLIKE"] = "_nlike";
2119
+ HasuraGraphQLWhere["ISNULL"] = "_is_null";
2120
+ HasuraGraphQLWhere["ISNOTNULL"] = "_is_null";
2121
+ })(HasuraGraphQLWhere || (HasuraGraphQLWhere = {}));
2122
+
2123
+ var HasuraGraphQLColumnType;
2124
+ (function (HasuraGraphQLColumnType) {
2125
+ HasuraGraphQLColumnType["Int"] = "Int";
2126
+ HasuraGraphQLColumnType["Float"] = "Float";
2127
+ HasuraGraphQLColumnType["Boolean"] = "Boolean";
2128
+ HasuraGraphQLColumnType["String"] = "String";
2129
+ HasuraGraphQLColumnType["DateTime"] = "timestampz";
2130
+ HasuraGraphQLColumnType["Json"] = "json";
2131
+ HasuraGraphQLColumnType["Jsonb"] = "jsonb";
2132
+ HasuraGraphQLColumnType["Enum"] = "enum";
2133
+ HasuraGraphQLColumnType["Uuid"] = "uuid";
2134
+ })(HasuraGraphQLColumnType || (HasuraGraphQLColumnType = {}));
2135
+
2136
+ const withFindHasuraGraphQL = (MixinBase) => {
2137
+ const checkIfIsFilterOption = (filter) => !isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
2138
+ const getValueFromFilter = (filter, fieldOption) => {
2139
+ if (!checkIfIsFilterOption(filter))
2140
+ return filter;
2141
+ if (filter.operator === Where.ISNULL)
2142
+ return true;
2143
+ if (filter.operator === Where.ISNOTNULL)
2144
+ return false;
2145
+ const converter = fieldOption.to ? fieldOption.to : (value) => value;
2146
+ return Array.isArray(filter.value) && [Where.IN, Where.NOTIN].includes(filter.operator)
2147
+ ? filter.value.map((fieldValue) => converter(fieldValue))
2148
+ : converter(filter.value);
2149
+ };
2150
+ return class FindHasuraGraphQLMixin extends MixinBase {
2151
+ constructor() {
2152
+ super(...arguments);
2153
+ this.makeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => (Object.assign(Object.assign({}, variables), { [AttributeOptionHelper.findByAttribute(fieldName, fields)
2154
+ .columnName]: this.buildWhereSentence(fieldName, filter[fieldName], fields) })), {});
2155
+ this.buildWhereSentence = (field, options, fields) => {
2156
+ const fieldSentenceOptions = AttributeOptionHelper.findByAttribute(field, fields);
2157
+ if (!Array.isArray(options) &&
2158
+ isObject(options) &&
2159
+ isNil(options === null || options === void 0 ? void 0 : options.operator) &&
2160
+ isNil(options === null || options === void 0 ? void 0 : options.value) &&
2161
+ isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to))
2162
+ return Object.keys(options).reduce((variables, key) => {
2163
+ const fieldOptions = AttributeOptionHelper.findByAttribute(key, fields);
2164
+ const columnName = fieldOptions.columnName;
2165
+ const columnFields = fieldOptions.fields;
2166
+ return Object.assign(Object.assign({}, variables), { [columnName]: this.buildWhereSentence(key, options[key], columnFields || []) });
2167
+ }, {});
2168
+ if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
2169
+ return {
2170
+ [fieldSentenceOptions.fields[0]]: this.buildOperatorSentence(options, fieldSentenceOptions),
2171
+ };
2172
+ if (isObject(options) && !checkIfIsFilterOption(options))
2173
+ options = Object.values(options)[0];
2174
+ return Array.isArray(options)
2175
+ ? options.reduce((whereSentence, option) => (Object.assign(Object.assign({}, whereSentence), this.buildOperatorSentence(option, fieldSentenceOptions))), {})
2176
+ : this.buildOperatorSentence(options, fieldSentenceOptions);
2177
+ };
2178
+ this.buildOperatorSentence = (options, fieldOption) => ({
2179
+ [this.getHasuraOperator(options, fieldOption)]: getValueFromFilter(options, fieldOption),
2180
+ });
2181
+ this.getHasuraOperator = (options, fieldOption) => checkIfIsFilterOption(options)
2182
+ ? fieldOption.type === HasuraGraphQLColumnType.Jsonb
2183
+ ? this.getHasuraJsonbOperator(options)
2184
+ : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator === Object.keys(Where).find((operator) => Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))]
2185
+ : HasuraGraphQLWhere.EQUALS;
2186
+ this.getHasuraJsonbOperator = (options) => options.operator === Where.IN
2187
+ ? '_contains'
2188
+ : options.operator === Where.LIKE
2189
+ ? '_has_keys_any'
2190
+ : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator === Object.keys(Where).find((operator) => Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))];
2191
+ }
2192
+ find(options) {
2193
+ return __awaiter(this, void 0, void 0, function* () {
2194
+ const { filters, limits, orderBy } = options || {};
2195
+ const variablesCount = Object.assign(Object.assign({}, (isNil(orderBy) ? {} : { order_by: { type: `${this.tableName}_order_by!`, list: true, value: orderBy } })), (isNil(filters)
2196
+ ? {}
2197
+ : {
2198
+ where: {
2199
+ value: this.makeGraphQLWhere(filters, this.fields),
2200
+ type: `${this.tableName}_bool_exp`,
2201
+ required: true,
2202
+ },
2203
+ }));
2204
+ const variables = Object.assign(Object.assign({}, (isNil(limits) ? {} : limits)), variablesCount);
2205
+ console.log(JSON.stringify(variables));
2206
+ const result = yield this.query([
2207
+ {
2208
+ operation: this.tableName,
2209
+ fields: this.fields,
2210
+ variables,
2211
+ },
2212
+ {
2213
+ operation: `${this.tableName}_aggregate`,
2214
+ fields: [{ aggregate: ['count'] }],
2215
+ variables: variablesCount,
2216
+ },
2217
+ ]);
2218
+ const data = result[this.tableName].map((data) => this.convertDataFromHasura(data));
2219
+ const count = result[`${this.tableName}_aggregate`].aggregate.count;
2220
+ return { count, data };
2221
+ });
2222
+ }
2223
+ };
2224
+ };
2225
+
2226
+ const withCrudHasuraGraphQL = (MixinBase) => {
2227
+ return class CrudHasuraGraphQLMixin extends withUpdateHasuraGraphQL(withGetHasuraGraphQL(withFindHasuraGraphQL(withDeleteHasuraGraphQL(withCreateHasuraGraphQL(MixinBase))))) {
2228
+ };
2229
+ };
2230
+
2231
+ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
2232
+ constructor(endpoint, authOptions, productRepository) {
2233
+ super({
2234
+ tableName: 'category',
2235
+ model: Category,
2236
+ endpoint,
2237
+ authOptions,
2238
+ fields: [
2239
+ { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
2240
+ 'firestore_id',
2241
+ 'name',
2242
+ 'description',
2243
+ 'image',
2244
+ 'published',
2245
+ 'shop',
2246
+ 'slug',
2247
+ { brandCategory: { columnName: 'brand_category' } },
2248
+ { brandCategoryBanner: { columnName: 'brand_banner' } },
2249
+ { brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
2250
+ { brandLogo: { columnName: 'brand_logo' } },
2251
+ { conditions: { columnName: 'brand_condition' } },
2252
+ {
2253
+ conditions: {
2254
+ columnName: 'tag_condition',
2255
+ from: (tags, row) => ({ brand: row.brand_condition, tags }),
2256
+ },
2257
+ },
2258
+ 'filters',
2259
+ { createdAt: { columnName: 'created_at' } },
2260
+ { updatedAt: { columnName: 'updated_at' } },
2261
+ {
2262
+ products: {
2263
+ columnName: 'products',
2264
+ fields: ['product_id'],
2265
+ from: (value) => value.map((product) => product.product_id.toString()),
2266
+ },
2267
+ },
2268
+ ],
2269
+ });
2270
+ this.productRepository = productRepository;
2271
+ }
2272
+ get(identifiers) {
2273
+ const _super = Object.create(null, {
2274
+ get: { get: () => super.get }
2275
+ });
2276
+ var _a;
2277
+ return __awaiter(this, void 0, void 0, function* () {
2278
+ return Number.isNaN(+identifiers.id)
2279
+ ? (_a = (yield this.find({ filters: { firestore_id: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
2280
+ : _super.get.call(this, identifiers);
2281
+ });
2282
+ }
2283
+ getCategoryBySlug(slug, shop) {
2284
+ return __awaiter(this, void 0, void 0, function* () {
2285
+ if (!slug)
2286
+ return;
2287
+ const { data, count } = yield this.find({ filters: { slug, shop, published: true } });
2288
+ if (count > 1)
2289
+ throw new DuplicatedResultsError('Query returned duplicated values');
2290
+ if (!count)
2291
+ throw new NotFoundError(`Category with slug ${slug} not found`);
2292
+ return data.shift();
2293
+ });
2294
+ }
2295
+ getCategoriesForHome(categoryIds, limit = 4) {
2296
+ return __awaiter(this, void 0, void 0, function* () {
2297
+ const { data: categories, count } = yield this.find({
2298
+ filters: { firestore_id: { operator: Where.IN, value: categoryIds.filter(Boolean) }, published: true },
2299
+ });
2300
+ if (!count)
2301
+ throw new NotFoundError('Categories not found');
2302
+ const homeSections = yield Promise.all(categories.map((category) => __awaiter(this, void 0, void 0, function* () {
2303
+ return ({
2304
+ category,
2305
+ products: yield this.mountCategory(category, { limit, hasStock: true }),
2306
+ });
2307
+ })));
2308
+ return homeSections;
2309
+ });
2310
+ }
2311
+ mountCategory(category, options) {
2312
+ return __awaiter(this, void 0, void 0, function* () {
2313
+ if (!category.products)
2314
+ throw new RequiredArgumentError(['Category products is empty']);
2315
+ console.log(category);
2316
+ console.log(category.products);
2317
+ const products = [];
2318
+ const publishedField = category.shop === Shops.GLAMSHOP ? 'publishedGlam' : 'published';
2319
+ const { data: productsData } = yield this.productRepository.find(Object.assign({ filters: {
2320
+ id: { operator: Where.IN, value: category.products },
2321
+ [publishedField]: true,
2322
+ ///...(options?.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {}),
2323
+ } }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})));
2324
+ products.push(...productsData);
2325
+ return products;
2326
+ });
2327
+ }
2328
+ }
2329
+
2330
+ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
2331
+ constructor(endpoint, authOptions) {
2332
+ super({
2333
+ tableName: 'product',
2334
+ model: Product,
2335
+ endpoint,
2336
+ authOptions,
2337
+ fields: [
2338
+ { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
2339
+ { CEST: { columnName: 'cest' } },
2340
+ { EAN: { columnName: 'ean' } },
2341
+ { NCM: { columnName: 'ncm' } },
2342
+ 'brand',
2343
+ { costPrice: { columnName: 'cost_price' } },
2344
+ 'description',
2345
+ { hasVariants: { columnName: 'has_variants' } },
2346
+ 'images',
2347
+ 'miniatures',
2348
+ 'name',
2349
+ { price: { columnName: 'full_price' } },
2350
+ { price: { columnName: 'subscriber_discount_percentage' } },
2351
+ { price: { columnName: 'subscriber_price' } },
2352
+ {
2353
+ price: {
2354
+ columnName: 'price',
2355
+ from: (price, data) => Object.values(Shops).reduce((prices, shop) => (Object.assign(Object.assign({}, prices), { [shop]: {
2356
+ price,
2357
+ fullPrice: data.full_price,
2358
+ subscriberDiscountPercentage: data.subscriber_discount_percentage,
2359
+ subscriberPrice: data.subscriber_price,
2360
+ } })), {}),
2361
+ },
2362
+ },
2363
+ 'published',
2364
+ { publishedGlam: { columnName: 'published_glam' } },
2365
+ 'sku',
2366
+ {
2367
+ stock: {
2368
+ columnName: 'stock',
2369
+ from: (quantity) => ({ quantity }),
2370
+ to: (value) => (value === null || value === void 0 ? void 0 : value.quantity) || value,
2371
+ },
2372
+ },
2373
+ 'type',
2374
+ 'video',
2375
+ 'weight',
2376
+ {
2377
+ categories: {
2378
+ columnName: 'categories',
2379
+ fields: ['category_id'],
2380
+ to: (category_id) => +category_id,
2381
+ from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
2382
+ },
2383
+ },
2384
+ {
2385
+ shopAvailability: {
2386
+ columnName: 'shop_availabilities',
2387
+ fields: ['shop'],
2388
+ from: (shop) => (Array.isArray(shop) ? shop.map((row) => row.shop) : []),
2389
+ },
2390
+ },
2391
+ { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
2392
+ { createdAt: { columnName: 'created_at' } },
2393
+ { updatedAt: { columnName: 'updated_at' } },
2394
+ ],
2395
+ });
2396
+ }
2397
+ getBySlug(slug, shop) {
2398
+ var _a;
2399
+ return __awaiter(this, void 0, void 0, function* () {
2400
+ const result = yield this.find({
2401
+ filters: {
2402
+ slug: { operator: Where.EQUALS, value: slug },
2403
+ shopAvailability: { operator: Where.IN, value: [shop] },
2404
+ },
2405
+ });
2406
+ return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
2407
+ });
2408
+ }
2409
+ }
2410
+
1802
2411
  /**
1803
2412
  * Generated bundle index. Do not edit.
1804
2413
  */
1805
2414
 
1806
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClubCoupon, Coupon, CouponFirestoreRepository, DiscountType, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, StoreCoupon, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserSearchFirestoreRepository, UserType, Variant, WeakPasswordError, Where, withCreateFirestore, withCrudFirestore, withDeleteFirestore, withFindFirestore, withFirestore, withGetFirestore, withHelpers, withSubCollection, withUpdateFirestore };
2415
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FinancialCoupon, FragranceImportances, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, 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, UserSearchFirestoreRepository, UserType, Variant, WeakPasswordError, Where, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
1807
2416
  //# sourceMappingURL=infrab4a-connect.js.map