@infrab4a/connect-angular 4.0.0 → 4.0.1-beta.0

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 (126) hide show
  1. package/angular-connect.module.d.ts +19 -22
  2. package/angular-elastic-search.module.d.ts +9 -9
  3. package/angular-firebase-auth.module.d.ts +10 -12
  4. package/angular-firestore.module.d.ts +15 -18
  5. package/angular-hasura-graphql.module.d.ts +16 -16
  6. package/bundles/infrab4a-connect-angular.umd.js +1978 -0
  7. package/bundles/infrab4a-connect-angular.umd.js.map +1 -0
  8. package/consts/backend-url.const.d.ts +1 -1
  9. package/consts/default-shop.const.d.ts +1 -1
  10. package/consts/es-config.const.d.ts +1 -1
  11. package/consts/hasura-options.const.d.ts +1 -1
  12. package/consts/index.d.ts +4 -6
  13. package/esm2015/angular-connect.module.js +52 -0
  14. package/esm2015/angular-elastic-search.module.js +38 -0
  15. package/esm2015/angular-firebase-auth.module.js +113 -0
  16. package/esm2015/angular-firestore.module.js +366 -0
  17. package/esm2015/angular-hasura-graphql.module.js +90 -0
  18. package/{esm2020/consts/backend-url.const.mjs → esm2015/consts/backend-url.const.js} +1 -1
  19. package/{esm2020/consts/default-shop.const.mjs → esm2015/consts/default-shop.const.js} +2 -2
  20. package/{esm2020/consts/es-config.const.mjs → esm2015/consts/es-config.const.js} +2 -2
  21. package/{esm2020/consts/hasura-options.const.mjs → esm2015/consts/hasura-options.const.js} +2 -2
  22. package/esm2015/consts/index.js +5 -0
  23. package/esm2015/index.js +6 -0
  24. package/{esm2020/infrab4a-connect-angular.mjs → esm2015/infrab4a-connect-angular.js} +4 -4
  25. package/esm2015/services/auth.service.js +42 -0
  26. package/esm2015/services/cart.service.js +148 -0
  27. package/esm2015/services/checkout-subscription.service.js +51 -0
  28. package/esm2015/services/checkout.service.js +75 -0
  29. package/esm2015/services/coupon.service.js +266 -0
  30. package/esm2015/services/errors/group-invalid-coupon.error.js +8 -0
  31. package/esm2015/services/errors/index.js +3 -0
  32. package/esm2015/services/errors/invalid-coupon.error.js +8 -0
  33. package/esm2015/services/home-shop.service.js +116 -0
  34. package/esm2015/services/index.js +9 -0
  35. package/esm2015/services/order.service.js +32 -0
  36. package/esm2015/services/shipping.service.js +99 -0
  37. package/{esm2020/services/types/index.mjs → esm2015/services/types/index.js} +3 -3
  38. package/{esm2020/services/types/required-checkout-data.type.mjs → esm2015/services/types/required-checkout-data.type.js} +2 -2
  39. package/{esm2020/services/types/required-checkout-subscription-data.type.mjs → esm2015/services/types/required-checkout-subscription-data.type.js} +2 -2
  40. package/esm2015/services/types/shipping-methods.type.js +2 -0
  41. package/fesm2015/infrab4a-connect-angular.js +1432 -0
  42. package/fesm2015/infrab4a-connect-angular.js.map +1 -0
  43. package/index.d.ts +5 -5
  44. package/infrab4a-connect-angular.d.ts +5 -0
  45. package/package.json +13 -25
  46. package/services/auth.service.d.ts +19 -18
  47. package/services/cart.service.d.ts +35 -42
  48. package/services/checkout-subscription.service.d.ts +18 -18
  49. package/services/checkout.service.d.ts +23 -23
  50. package/services/coupon.service.d.ts +26 -28
  51. package/services/errors/group-invalid-coupon.error.d.ts +6 -0
  52. package/services/errors/index.d.ts +2 -0
  53. package/services/errors/invalid-coupon.error.d.ts +5 -0
  54. package/services/home-shop.service.d.ts +25 -25
  55. package/services/index.d.ts +8 -10
  56. package/services/order.service.d.ts +13 -13
  57. package/services/shipping.service.d.ts +19 -19
  58. package/services/types/index.d.ts +2 -2
  59. package/services/types/required-checkout-data.type.d.ts +2 -2
  60. package/services/types/required-checkout-subscription-data.type.d.ts +2 -2
  61. package/services/types/shipping-methods.type.d.ts +12 -12
  62. package/consts/category-structure.d.ts +0 -1
  63. package/consts/firebase-const.d.ts +0 -3
  64. package/esm2020/angular-connect.module.mjs +0 -66
  65. package/esm2020/angular-elastic-search.module.mjs +0 -34
  66. package/esm2020/angular-firebase-auth.module.mjs +0 -130
  67. package/esm2020/angular-firestore.module.mjs +0 -459
  68. package/esm2020/angular-hasura-graphql.module.mjs +0 -243
  69. package/esm2020/consts/category-structure.mjs +0 -2
  70. package/esm2020/consts/firebase-const.mjs +0 -4
  71. package/esm2020/consts/index.mjs +0 -7
  72. package/esm2020/helpers/index.mjs +0 -2
  73. package/esm2020/helpers/mobile-operation-system-checker.helper.mjs +0 -7
  74. package/esm2020/index.mjs +0 -6
  75. package/esm2020/services/auth.service.mjs +0 -37
  76. package/esm2020/services/cart.service.mjs +0 -281
  77. package/esm2020/services/catalog/adapters/category-structure.adapter.mjs +0 -2
  78. package/esm2020/services/catalog/adapters/index.mjs +0 -4
  79. package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +0 -42
  80. package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +0 -23
  81. package/esm2020/services/catalog/catalog.service.mjs +0 -122
  82. package/esm2020/services/catalog/category.service.mjs +0 -51
  83. package/esm2020/services/catalog/enums/index.mjs +0 -2
  84. package/esm2020/services/catalog/enums/product-sorts.enum.mjs +0 -11
  85. package/esm2020/services/catalog/index.mjs +0 -7
  86. package/esm2020/services/catalog/models/category-with-tree.model.mjs +0 -10
  87. package/esm2020/services/catalog/models/index.mjs +0 -2
  88. package/esm2020/services/catalog/types/index.mjs +0 -2
  89. package/esm2020/services/catalog/types/product-sort.type.mjs +0 -2
  90. package/esm2020/services/catalog/wishlist.service.mjs +0 -105
  91. package/esm2020/services/checkout-subscription.service.mjs +0 -53
  92. package/esm2020/services/checkout.service.mjs +0 -71
  93. package/esm2020/services/coupon.service.mjs +0 -218
  94. package/esm2020/services/helpers/index.mjs +0 -2
  95. package/esm2020/services/helpers/util.helper.mjs +0 -18
  96. package/esm2020/services/home-shop.service.mjs +0 -114
  97. package/esm2020/services/index.mjs +0 -11
  98. package/esm2020/services/order.service.mjs +0 -30
  99. package/esm2020/services/shipping.service.mjs +0 -96
  100. package/esm2020/services/types/shipping-methods.type.mjs +0 -2
  101. package/esm2020/types/firebase-app-config.type.mjs +0 -2
  102. package/esm2020/types/index.mjs +0 -2
  103. package/fesm2015/infrab4a-connect-angular.mjs +0 -2193
  104. package/fesm2015/infrab4a-connect-angular.mjs.map +0 -1
  105. package/fesm2020/infrab4a-connect-angular.mjs +0 -2125
  106. package/fesm2020/infrab4a-connect-angular.mjs.map +0 -1
  107. package/helpers/index.d.ts +0 -1
  108. package/helpers/mobile-operation-system-checker.helper.d.ts +0 -3
  109. package/services/catalog/adapters/category-structure.adapter.d.ts +0 -4
  110. package/services/catalog/adapters/index.d.ts +0 -3
  111. package/services/catalog/adapters/new-category-structure.adapter.d.ts +0 -14
  112. package/services/catalog/adapters/old-category-structure.adapter.d.ts +0 -10
  113. package/services/catalog/catalog.service.d.ts +0 -80
  114. package/services/catalog/category.service.d.ts +0 -15
  115. package/services/catalog/enums/index.d.ts +0 -1
  116. package/services/catalog/enums/product-sorts.enum.d.ts +0 -9
  117. package/services/catalog/index.d.ts +0 -6
  118. package/services/catalog/models/category-with-tree.model.d.ts +0 -4
  119. package/services/catalog/models/index.d.ts +0 -1
  120. package/services/catalog/types/index.d.ts +0 -1
  121. package/services/catalog/types/product-sort.type.d.ts +0 -2
  122. package/services/catalog/wishlist.service.d.ts +0 -22
  123. package/services/helpers/index.d.ts +0 -1
  124. package/services/helpers/util.helper.d.ts +0 -3
  125. package/types/firebase-app-config.type.d.ts +0 -1
  126. package/types/index.d.ts +0 -1
@@ -0,0 +1,1432 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, Inject, NgModule, APP_INITIALIZER } from '@angular/core';
3
+ import * as i1 from '@angular/fire/auth';
4
+ import { AngularFireAuth } from '@angular/fire/auth';
5
+ import { of, combineLatest, from, throwError, Subject, iif, forkJoin } from 'rxjs';
6
+ import { catchError, map, mergeMap, concatMap, tap } from 'rxjs/operators';
7
+ import { __awaiter } from 'tslib';
8
+ import * as i1$1 from '@infrab4a/connect';
9
+ import { Coupon, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, Status, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, VariantHasuraGraphQLRepository } from '@infrab4a/connect';
10
+ import cookie from 'js-cookie';
11
+ import { CustomError } from 'ts-custom-error';
12
+ import * as i1$2 from '@angular/fire/firestore';
13
+ import { AngularFirestore } from '@angular/fire/firestore';
14
+ import * as i1$3 from '@angular/common/http';
15
+ import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
16
+
17
+ class AuthService {
18
+ constructor(angularFireAuth, userRepository) {
19
+ this.angularFireAuth = angularFireAuth;
20
+ this.userRepository = userRepository;
21
+ }
22
+ getAuthstate() {
23
+ const observables = [
24
+ this.angularFireAuth.authState.pipe(catchError(() => of(null))),
25
+ this.getUser().pipe(catchError(() => of(null))),
26
+ ];
27
+ return combineLatest(observables).pipe(map(([fireUser, user]) => {
28
+ return {
29
+ user,
30
+ isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
31
+ };
32
+ }));
33
+ }
34
+ getUser() {
35
+ return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? this.userRepository.get({ id }) : of(null))));
36
+ }
37
+ getTokenId() {
38
+ return this.angularFireAuth.idToken;
39
+ }
40
+ getFireUser() {
41
+ return this.angularFireAuth.user.pipe(catchError(() => of(null)));
42
+ }
43
+ }
44
+ AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, deps: [{ token: i1.AngularFireAuth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
45
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
46
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
47
+ type: Injectable
48
+ }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
49
+ type: Inject,
50
+ args: ['UserRepository']
51
+ }] }]; } });
52
+
53
+ const BACKEND_URL = 'BACKEND_URL';
54
+
55
+ const DEFAULT_SHOP = 'DEFAULT_SHOP';
56
+
57
+ const ES_CONFIG = 'ES_CONFIG';
58
+
59
+ const HASURA_OPTIONS = 'HASURA_OPTIONS';
60
+
61
+ class InvalidCouponError extends CustomError {
62
+ constructor(message) {
63
+ super(message);
64
+ this.message = message;
65
+ }
66
+ }
67
+
68
+ class GroupInvalidCouponError extends CustomError {
69
+ constructor(errors) {
70
+ super('Many coupon errors throw');
71
+ this.errors = errors;
72
+ }
73
+ }
74
+
75
+ class CouponService {
76
+ constructor(couponRepository, defaultShop, orderRepository, subscriptionRepository, categoryRepository) {
77
+ this.couponRepository = couponRepository;
78
+ this.defaultShop = defaultShop;
79
+ this.orderRepository = orderRepository;
80
+ this.subscriptionRepository = subscriptionRepository;
81
+ this.categoryRepository = categoryRepository;
82
+ this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
83
+ this.separateValidCoupons = (coupons, userEmail) => coupons
84
+ .map((coupon) => {
85
+ try {
86
+ if (!(coupon instanceof Coupon))
87
+ throw new InvalidCouponError('Cupom inválido.');
88
+ if (this.isValidCoupon(coupon, userEmail))
89
+ return coupon;
90
+ }
91
+ catch (error) {
92
+ return error;
93
+ }
94
+ })
95
+ .reduce((current, coupon) => (Object.assign(Object.assign({}, current), (coupon instanceof Coupon
96
+ ? { valids: [...current.valids, coupon] }
97
+ : { invalids: [...current.invalids, coupon] }))), {
98
+ valids: [],
99
+ invalids: [],
100
+ });
101
+ }
102
+ checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
103
+ return from(this.couponRepository.find({
104
+ filters: {
105
+ nickname: { operator: Where.EQUALS, value: nickname },
106
+ active: { operator: Where.EQUALS, value: true },
107
+ },
108
+ })).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail, checkout)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
109
+ }
110
+ checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription) {
111
+ // Caso não ache nenhum cupom, retorna erro
112
+ if (coupons.count < 1) {
113
+ return throwError('Cupom inválido.');
114
+ }
115
+ // Get Primeiro Cupom (o find do repository retorna um array)
116
+ const coupon = coupons.data.shift();
117
+ // Verifica se o cupom é aplicavel na loja
118
+ const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
119
+ // Cupon não aplicavel a loja retorna erro
120
+ if (!isInShop)
121
+ return throwError('Cupom inválido para loja.');
122
+ // Verifica se o coupon é aplicado no checkout que está sendo realizado
123
+ const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
124
+ // Cupon não aplicavel ao checkout retorna erro
125
+ if (!isCheckoutType)
126
+ return throwError('Cupom inválido. Erro de checkout.');
127
+ // Verifica se o cupom é ou pode ser aplicado para subscription
128
+ if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
129
+ // Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
130
+ if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
131
+ return throwError('Cupom inválido para sua assinatura.');
132
+ }
133
+ if (isSubscription)
134
+ return of(coupon);
135
+ // Verifica se possui o valor minimo de compra para utilização do cupom
136
+ const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
137
+ // Se não tem valor mínimo atingido, retorna erro
138
+ if (!hasMinSubTotal)
139
+ return throwError('Valor mínimo não atingido');
140
+ return of(coupon);
141
+ }
142
+ isValidCoupon(coupon, userEmail) {
143
+ // Verifica a data de inicio de validade do cupom
144
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
145
+ throw new InvalidCouponError('Cupom ainda não liberado.');
146
+ // Verifica a data de validade do cupom
147
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
148
+ throw new InvalidCouponError('Cupom expirado.');
149
+ return coupon;
150
+ }
151
+ checkCouponUseAndLimit(coupon, userEmail, checkout) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ const orders = yield this.orderRepository.find({
154
+ filters: {
155
+ coupon: { id: coupon.id },
156
+ payment: { status: 'paid' },
157
+ },
158
+ });
159
+ // orders que usuario ja fez com o cupom
160
+ const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
161
+ // Verifica o limite de uso de cupom por usuario
162
+ if (coupon.useLimitPerUser && ordersUserCoupon.length)
163
+ throw new InvalidCouponError('Limite de uso por usuário atingido.');
164
+ // Verifica o limite de uso geral por usuario
165
+ if (coupon.useLimit && orders.data.length >= coupon.useLimit)
166
+ throw new InvalidCouponError('Limite de uso atingido.');
167
+ const validUser = yield this.userValidationAndSubscriptionStatus(coupon, userEmail);
168
+ if (!validUser)
169
+ throw new InvalidCouponError('Usuário não elegível.');
170
+ const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
171
+ if (!hasProductCategories)
172
+ throw 'Seu carrinho não possui produtos elegíveis para desconto.';
173
+ return coupon;
174
+ });
175
+ }
176
+ calcDiscountSubscription(coupon, checkout) {
177
+ //
178
+ let discount = 0;
179
+ if (coupon.type === CouponTypes.ABSOLUTE)
180
+ discount = coupon.discount;
181
+ else if (coupon.type === CouponTypes.PERCENTAGE)
182
+ discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount / 100);
183
+ return of(discount);
184
+ }
185
+ calcDiscountShopping(coupon, checkout) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ let discount = 0;
188
+ switch (coupon.type) {
189
+ case CouponTypes.ABSOLUTE: {
190
+ discount = coupon.discount;
191
+ break;
192
+ }
193
+ case CouponTypes.PERCENTAGE: {
194
+ discount = yield this.calcShoppingPercentageDiscount(coupon, checkout);
195
+ break;
196
+ }
197
+ }
198
+ return discount;
199
+ });
200
+ }
201
+ calcShoppingPercentageDiscount(coupon, checkout) {
202
+ var _a;
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ let discount = 0;
205
+ const shop = checkout.shop;
206
+ let lineItensDiscount = [];
207
+ const couponCategories = yield this.getCouponCategoriesId(coupon);
208
+ if (coupon.productsCategories && coupon.productsCategories.length) {
209
+ lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
210
+ var _a;
211
+ if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
212
+ return i.categories.some((c) => couponCategories.some(cat => (cat.id == c || cat.firestoreId == c)));
213
+ }
214
+ return true;
215
+ });
216
+ }
217
+ else {
218
+ lineItensDiscount = checkout.lineItems;
219
+ }
220
+ const subTotal = lineItensDiscount.reduce((acc, curr) => {
221
+ var _a, _b, _c;
222
+ return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
223
+ ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
224
+ : acc + curr.pricePaid * curr.quantity;
225
+ }, 0) || 0;
226
+ discount = subTotal * (coupon.discount / 100);
227
+ return discount;
228
+ });
229
+ }
230
+ hasMinSubTotal(coupon, checkout) {
231
+ var _a;
232
+ if (!coupon.minSubTotalValue)
233
+ return true;
234
+ const shop = checkout.shop;
235
+ let subTotal = ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => {
236
+ var _a, _b, _c;
237
+ return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
238
+ ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
239
+ : acc + curr.pricePaid * curr.quantity;
240
+ }, 0)) || 0;
241
+ if (coupon.minSubTotalValue <= subTotal)
242
+ return true;
243
+ return false;
244
+ }
245
+ hasProductCategories(coupon, checkout) {
246
+ var _a;
247
+ return __awaiter(this, void 0, void 0, function* () {
248
+ if (!coupon.productsCategories || !coupon.productsCategories.length) {
249
+ return true;
250
+ }
251
+ const couponCategories = yield this.getCouponCategoriesId(coupon);
252
+ const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(i => {
253
+ var _a;
254
+ if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
255
+ return true;
256
+ return i.categories.some((c) => couponCategories.some(cat => (cat.id == c || cat.firestoreId == c)));
257
+ });
258
+ return hasCategories.length ? true : false;
259
+ });
260
+ }
261
+ userValidationAndSubscriptionStatus(coupon, userEmail) {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ // Verifica se o email do usuário é coorporativo
264
+ if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
265
+ throw new InvalidCouponError('Você não é colaborador.');
266
+ // Verifica se o email do usuário é associado ao cupom de uso por usuario
267
+ if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
268
+ throw new InvalidCouponError('Cupom não é válido para este usuário.');
269
+ const couponRuleSubscription = coupon.exclusivityType === Exclusivities.ACTIVE_SUBSCRIBER ||
270
+ coupon.exclusivityType === Exclusivities.INACTIVE_SUBSCRIBER ||
271
+ coupon.exclusivityType === Exclusivities.NON_SUBSCRIBER;
272
+ if (couponRuleSubscription && userEmail) {
273
+ const sub = yield this.subscriptionRepository
274
+ .find({
275
+ filters: {
276
+ user: {
277
+ email: { operator: Where.EQUALS, value: userEmail },
278
+ },
279
+ },
280
+ })
281
+ .then((sub) => sub.data);
282
+ const activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter((s) => s.status === Status.ACTIVE);
283
+ switch (coupon.exclusivityType) {
284
+ case Exclusivities.ACTIVE_SUBSCRIBER:
285
+ return activeSubs.length > 0;
286
+ case Exclusivities.INACTIVE_SUBSCRIBER:
287
+ return activeSubs.length === 0;
288
+ case Exclusivities.NON_SUBSCRIBER:
289
+ return sub.length === 0;
290
+ default:
291
+ return false;
292
+ }
293
+ }
294
+ return true;
295
+ });
296
+ }
297
+ getCouponCategoriesId(coupon) {
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ let couponCategories = [];
300
+ for (let index = 0; index < coupon.productsCategories.length; index++) {
301
+ let c = yield this.categoryRepository.get({ id: coupon.productsCategories[index] });
302
+ couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
303
+ }
304
+ return couponCategories;
305
+ });
306
+ }
307
+ }
308
+ CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'SubscriptionRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
309
+ CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
310
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
311
+ type: Injectable,
312
+ args: [{
313
+ providedIn: 'root',
314
+ }]
315
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
316
+ type: Inject,
317
+ args: ['CouponRepository']
318
+ }] }, { type: i1$1.Shops, decorators: [{
319
+ type: Inject,
320
+ args: [DEFAULT_SHOP]
321
+ }] }, { type: undefined, decorators: [{
322
+ type: Inject,
323
+ args: ['OrderRepository']
324
+ }] }, { type: undefined, decorators: [{
325
+ type: Inject,
326
+ args: ['SubscriptionRepository']
327
+ }] }, { type: undefined, decorators: [{
328
+ type: Inject,
329
+ args: ['CategoryRepository']
330
+ }] }]; } });
331
+
332
+ class CheckoutService {
333
+ constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
334
+ this.couponService = couponService;
335
+ this.checkoutRepository = checkoutRepository;
336
+ this.orderRepository = orderRepository;
337
+ this.userRepository = userRepository;
338
+ this.defaultShop = defaultShop;
339
+ }
340
+ getCheckout(checkoutData) {
341
+ const checkoutId = cookie.get('checkoutId');
342
+ if (!isNil(checkoutId))
343
+ return from(this.checkoutRepository.get({ id: checkoutId }));
344
+ return from(this.createCheckout(checkoutData));
345
+ }
346
+ getUserByCheckout(checkoutId) {
347
+ return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => { var _a; return ((_a = checkout === null || checkout === void 0 ? void 0 : checkout.user) === null || _a === void 0 ? void 0 : _a.id) ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id })); }), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
348
+ }
349
+ updateCheckoutLineItems(checkout) {
350
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
351
+ }
352
+ updateCheckoutUser(checkout) {
353
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
354
+ }
355
+ clearCheckoutFromSession() {
356
+ cookie.remove('checkoutId');
357
+ return of();
358
+ }
359
+ calcDiscount(coupon) {
360
+ return this.getCheckout().pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.couponService.calcDiscountShopping(coupon, checkout); })));
361
+ }
362
+ checkCoupon(nickname, checkoutType) {
363
+ return this.getCheckout().pipe(concatMap((checkout) => {
364
+ var _a;
365
+ return this.couponService
366
+ .checkCoupon(nickname, (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
367
+ .pipe();
368
+ }));
369
+ }
370
+ createCheckout(checkoutData) {
371
+ return __awaiter(this, void 0, void 0, function* () {
372
+ const checkout = yield this.checkoutRepository.create(Object.assign(Object.assign({ createdAt: new Date() }, Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()), { shop: (checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.shop) || this.defaultShop }));
373
+ cookie.set('checkoutId', checkout.id);
374
+ return checkout;
375
+ });
376
+ }
377
+ }
378
+ CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
379
+ CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
380
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
381
+ type: Injectable
382
+ }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
383
+ type: Inject,
384
+ args: ['CheckoutRepository']
385
+ }] }, { type: undefined, decorators: [{
386
+ type: Inject,
387
+ args: ['OrderRepository']
388
+ }] }, { type: undefined, decorators: [{
389
+ type: Inject,
390
+ args: ['UserRepository']
391
+ }] }, { type: i1$1.Shops, decorators: [{
392
+ type: Inject,
393
+ args: [DEFAULT_SHOP]
394
+ }] }]; } });
395
+
396
+ class CartService {
397
+ constructor(authService, checkoutService, defaultShop, productRepository) {
398
+ this.authService = authService;
399
+ this.checkoutService = checkoutService;
400
+ this.defaultShop = defaultShop;
401
+ this.productRepository = productRepository;
402
+ this.cartSubject = new Subject();
403
+ this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
404
+ var _a;
405
+ const items = [];
406
+ const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
407
+ if (index > -1) {
408
+ checkoutLoaded.lineItems[index].quantity += quantity;
409
+ checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
410
+ }
411
+ else
412
+ checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
413
+ return this.checkoutService
414
+ .updateCheckoutLineItems(checkoutLoaded)
415
+ .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
416
+ }));
417
+ this.generateCartObject = (items) => {
418
+ const cart = {};
419
+ items === null || items === void 0 ? void 0 : items.forEach((item) => {
420
+ var _a;
421
+ return (cart[item.sku] = LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.sku] || item)), { quantity: (((_a = cart[item.sku]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })));
422
+ });
423
+ return cart;
424
+ };
425
+ this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
426
+ var _a, _b, _c, _d, _e, _f, _g;
427
+ const product = yield this.productRepository.get({ id: item.id });
428
+ item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
429
+ if (this.checkMaxStock(item, quantity || 0))
430
+ throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
431
+ const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
432
+ const { id, name, EAN, brand, slug, stock, price, weight, categories, sku, type } = item;
433
+ const isGift = item.isGift || null;
434
+ const pricePaid = this.getProductPrice({
435
+ product: item,
436
+ shop: checkout.shop || this.defaultShop,
437
+ isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
438
+ });
439
+ return {
440
+ checkout,
441
+ lineItem: LineItem.toInstance({
442
+ id,
443
+ name: name !== null && name !== void 0 ? name : product.name,
444
+ EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
445
+ brand: product.brand,
446
+ slug: slug !== null && slug !== void 0 ? slug : product.slug,
447
+ sku: sku !== null && sku !== void 0 ? sku : product.sku,
448
+ stock,
449
+ price,
450
+ image,
451
+ weight: weight !== null && weight !== void 0 ? weight : product.weight,
452
+ quantity: (item.quantity || 0) + (quantity || 0),
453
+ pricePaid,
454
+ categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
455
+ isGift: isGift !== null && isGift !== void 0 ? isGift : null,
456
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
457
+ type,
458
+ }),
459
+ };
460
+ });
461
+ this.getProductPrice = ({ product, isSubscriber, }) => {
462
+ const info = product.price;
463
+ if (product.isGift)
464
+ return 0;
465
+ return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
466
+ };
467
+ this.checkMaxStock = (item, quantity) => {
468
+ var _a;
469
+ const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
470
+ const currentItemAmount = item.quantity || 0;
471
+ return currentItemAmount + quantity > maxStock;
472
+ };
473
+ }
474
+ addItem(item, quantity = 1) {
475
+ return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
476
+ }
477
+ decreaseItem(item) {
478
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
479
+ var _a;
480
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
481
+ if (!isNil(checkoutItem))
482
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
483
+ return checkout;
484
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
485
+ }
486
+ getCart(checkout) {
487
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
488
+ return this.cartSubject;
489
+ }
490
+ /**
491
+ * @deprecated The method should not be used
492
+ */
493
+ getVariantPriceDiscount(item) {
494
+ return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.price.subscriberPrice, of(item.price.subscriberPrice), of(item.price.price))), catchError(() => of(item.price.price)));
495
+ }
496
+ removeItem(item) {
497
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
498
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
499
+ if (index >= 0)
500
+ checkout.lineItems.splice(index, 1);
501
+ return checkout;
502
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
503
+ }
504
+ updateUserCart(user) {
505
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => __awaiter(this, void 0, void 0, function* () {
506
+ var _a, _b;
507
+ return this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length) ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; }))) : [] }))).toPromise();
508
+ })), map(checkout => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
509
+ }
510
+ clearCart() {
511
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
512
+ this.checkoutService.clearCheckoutFromSession();
513
+ return checkout;
514
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
515
+ }
516
+ buildCartFromCheckout(checkoutData) {
517
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
518
+ }
519
+ }
520
+ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
521
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
522
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
523
+ type: Injectable
524
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.Shops, decorators: [{
525
+ type: Inject,
526
+ args: [DEFAULT_SHOP]
527
+ }] }, { type: undefined, decorators: [{
528
+ type: Inject,
529
+ args: ['ProductRepository']
530
+ }] }]; } });
531
+
532
+ class CheckoutSubscriptionService {
533
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
534
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
535
+ this.subscriptionRepository = subscriptionRepository;
536
+ this.couponService = couponService;
537
+ }
538
+ getCheckoutSubscription(checkoutData) {
539
+ const checkoutId = cookie.get('checkoutSubscriptionId');
540
+ if (!isNil(checkoutId))
541
+ return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
542
+ return from(this.createCheckoutSubscription(checkoutData));
543
+ }
544
+ createCheckoutSubscription(checkoutData) {
545
+ return __awaiter(this, void 0, void 0, function* () {
546
+ const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
547
+ cookie.set('checkoutSubscriptionId', checkout.id);
548
+ return checkout;
549
+ });
550
+ }
551
+ clearCheckoutSubscriptionFromSession() {
552
+ cookie.remove('checkoutSubscriptionId');
553
+ return of();
554
+ }
555
+ checkCoupon(nickname, userEmail) {
556
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, null, true).pipe()));
557
+ }
558
+ calcDiscountSubscription(coupon) {
559
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
560
+ }
561
+ }
562
+ CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
563
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
564
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
565
+ type: Injectable
566
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
567
+ type: Inject,
568
+ args: ['CheckoutSubscriptionRepository']
569
+ }] }, { type: undefined, decorators: [{
570
+ type: Inject,
571
+ args: ['SubscriptionRepository']
572
+ }] }, { type: CouponService }]; } });
573
+
574
+ class HomeShopService {
575
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
576
+ this.categoryRepository = categoryRepository;
577
+ this.homeRepository = homeRepository;
578
+ this.productRepository = productRepository;
579
+ this.defaultShop = defaultShop;
580
+ this.buildCategoryGroupWithRequiredData = (group) => {
581
+ var _a, _b;
582
+ return ({
583
+ category: Category.toInstance(pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
584
+ products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map((product) => Product.toInstance(pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
585
+ 'id',
586
+ 'price',
587
+ 'reviews',
588
+ 'hasVariants',
589
+ 'slug',
590
+ 'sku',
591
+ 'stock',
592
+ 'costPrice',
593
+ 'images',
594
+ 'miniatures',
595
+ 'name',
596
+ 'weight',
597
+ 'rate',
598
+ 'type',
599
+ ])))) || [],
600
+ });
601
+ };
602
+ }
603
+ get homeId() {
604
+ if (this.defaultShop === Shops.GLAMSHOP)
605
+ return 'glamshop';
606
+ if (this.defaultShop === Shops.MENSMARKET)
607
+ return 'mens_market';
608
+ return null;
609
+ }
610
+ getHomeData() {
611
+ return this.getHomeConfiguration().pipe(map((home) => { var _a; return (((_a = home === null || home === void 0 ? void 0 : home.data) === null || _a === void 0 ? void 0 : _a.expiresAt) > new Date() ? home : null); }), concatMap((home) => home
612
+ ? of(home)
613
+ : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
614
+ discoverProducts,
615
+ featuredProducts,
616
+ verticalProducts,
617
+ })), concatMap((data) => this.saveHomeData(data)))));
618
+ }
619
+ getBanners(type) {
620
+ return this.getHomeConfiguration().pipe(map((home) => {
621
+ if (type === 'brand')
622
+ return home.brandsCarousel;
623
+ if (type === 'buyToWin')
624
+ return [home.buyToWinBanner];
625
+ if (type === 'block')
626
+ return home.blockBanners;
627
+ if (type === 'blog')
628
+ return [home.blogBanner];
629
+ }));
630
+ }
631
+ getMinValueForFreeShipping() {
632
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
633
+ }
634
+ getDiscoverProducts() {
635
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
636
+ }
637
+ getFeaturedProducts() {
638
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
639
+ }
640
+ getVerticalProducts() {
641
+ return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.productRepository.find({
642
+ filters: { categories: { operator: Where.IN, value: [category.id] } },
643
+ limits: { limit: 12 },
644
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
645
+ }
646
+ getHomeConfiguration() {
647
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
648
+ ? of(home)
649
+ : !this.homeId
650
+ ? throwError(new RequiredArgumentError(['homeId']))
651
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
652
+ }
653
+ saveHomeData(homeData) {
654
+ const data = {
655
+ createdAt: new Date(),
656
+ expiresAt: add(new Date(), { hours: 1 }),
657
+ data: homeData,
658
+ };
659
+ return from(this.homeRepository.update({
660
+ id: this.homeId,
661
+ data,
662
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
663
+ }
664
+ }
665
+ HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
666
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
667
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
668
+ type: Injectable
669
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
670
+ type: Inject,
671
+ args: ['CategoryRepository']
672
+ }] }, { type: undefined, decorators: [{
673
+ type: Inject,
674
+ args: ['HomeRepository']
675
+ }] }, { type: undefined, decorators: [{
676
+ type: Inject,
677
+ args: ['ProductRepository']
678
+ }] }, { type: i1$1.Shops, decorators: [{
679
+ type: Inject,
680
+ args: [DEFAULT_SHOP]
681
+ }] }]; } });
682
+
683
+ class OrderService {
684
+ constructor(angularFirestore, orderRepository) {
685
+ this.angularFirestore = angularFirestore;
686
+ this.orderRepository = orderRepository;
687
+ this.orderSubject = new Subject();
688
+ }
689
+ getOrder(id) {
690
+ this.angularFirestore
691
+ .doc(`${this.orderRepository.collectionName}/${id}`)
692
+ .valueChanges()
693
+ .pipe(map((doc) => Order.toInstance(doc)))
694
+ .subscribe((doc) => this.orderSubject.next(doc));
695
+ return this.orderSubject;
696
+ }
697
+ }
698
+ OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$2.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
699
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
700
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
701
+ type: Injectable
702
+ }], ctorParameters: function () { return [{ type: i1$2.AngularFirestore }, { type: i1$1.OrderFirestoreRepository, decorators: [{
703
+ type: Inject,
704
+ args: ['OrderRepository']
705
+ }] }]; } });
706
+
707
+ class ShippingService {
708
+ constructor(http, apiUrl, homeService) {
709
+ this.http = http;
710
+ this.apiUrl = apiUrl;
711
+ this.homeService = homeService;
712
+ }
713
+ getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
714
+ return combineLatest([
715
+ this.homeService.getHomeData(),
716
+ this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`)
717
+ ])
718
+ .pipe(map(([datas, shippingMethodsResponse]) => {
719
+ let shippingMethods = shippingMethodsResponse.result;
720
+ if (!shippingMethods.length)
721
+ return [];
722
+ shippingMethods = shippingMethods.map(s => {
723
+ if (s.ShippingCompanyName == 'Same Day EG')
724
+ s.ShippingCompanyName = 'Same Day';
725
+ else
726
+ return s;
727
+ });
728
+ const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
729
+ if (this.isHolidays(datasSameDayNotAvaliable)) {
730
+ shippingMethods = shippingMethods.filter((method) => method.ShippingCompanyName !== 'Same Day');
731
+ }
732
+ if (totalPrice >= 200) {
733
+ shippingMethods = shippingMethods.map(s => {
734
+ if (s.serviceName !== 'Same Day')
735
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
736
+ else
737
+ return s;
738
+ });
739
+ }
740
+ if (shop == Shops.GLAMSHOP)
741
+ return shippingMethods;
742
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
743
+ shippingMethods = shippingMethods.map(s => {
744
+ if (s.serviceName == 'Same Day')
745
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
746
+ else
747
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
748
+ });
749
+ }
750
+ if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
751
+ shippingMethods = shippingMethods.map(s => {
752
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
753
+ });
754
+ }
755
+ return shippingMethods;
756
+ }));
757
+ }
758
+ isFreeShippingBySubscription(shop, subscriptionPlan) {
759
+ if (!subscriptionPlan)
760
+ return false;
761
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
762
+ return true;
763
+ }
764
+ return false;
765
+ }
766
+ isHalfShippingBySubscription(shop, subscriptionPlan) {
767
+ if (!subscriptionPlan)
768
+ return false;
769
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
770
+ return true;
771
+ }
772
+ return false;
773
+ }
774
+ isHolidays(datas) {
775
+ const today = new Date();
776
+ for (const key in datas) {
777
+ let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
778
+ let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
779
+ if (start > end)
780
+ end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
781
+ if (today >= start && today <= end)
782
+ return true;
783
+ }
784
+ return false;
785
+ }
786
+ }
787
+ ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, deps: [{ token: i1$3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
788
+ ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
789
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
790
+ type: Injectable
791
+ }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
792
+ type: Inject,
793
+ args: [BACKEND_URL]
794
+ }] }, { type: HomeShopService }]; } });
795
+
796
+ class AngularFirebaseAuthModule {
797
+ static initializeApp(options, nameOrConfig) {
798
+ return {
799
+ ngModule: AngularFirebaseAuthModule,
800
+ providers: [
801
+ { provide: FIREBASE_OPTIONS, useValue: options },
802
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
803
+ ],
804
+ };
805
+ }
806
+ }
807
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
808
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
809
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
810
+ {
811
+ provide: 'Authentication',
812
+ useFactory: (authenticationService, userRepository) => {
813
+ return new Authentication(authenticationService, userRepository);
814
+ },
815
+ deps: ['AuthenticationService', 'UserRepository'],
816
+ },
817
+ {
818
+ provide: 'AuthenticationService',
819
+ useFactory: (angularFireAuth) => {
820
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
821
+ },
822
+ deps: [AngularFireAuth],
823
+ },
824
+ {
825
+ provide: 'Register',
826
+ useFactory: (registerService, userRepository) => {
827
+ return new Register(registerService, userRepository);
828
+ },
829
+ deps: ['RegisterService', 'UserRepository'],
830
+ },
831
+ {
832
+ provide: 'RegisterService',
833
+ useFactory: (angularFireAuth) => {
834
+ return new RegisterFirebaseAuthService(angularFireAuth);
835
+ },
836
+ deps: [AngularFireAuth],
837
+ },
838
+ {
839
+ provide: 'SignOut',
840
+ useFactory: (authenticationService) => {
841
+ return new SignOut(authenticationService);
842
+ },
843
+ deps: ['AuthenticationService'],
844
+ },
845
+ {
846
+ provide: 'RecoveryPassword',
847
+ useFactory: (authenticationService) => {
848
+ return new RecoveryPassword(authenticationService);
849
+ },
850
+ deps: ['AuthenticationService'],
851
+ },
852
+ ], imports: [[AngularFireModule]] });
853
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
854
+ type: NgModule,
855
+ args: [{
856
+ imports: [AngularFireModule],
857
+ providers: [
858
+ {
859
+ provide: 'Authentication',
860
+ useFactory: (authenticationService, userRepository) => {
861
+ return new Authentication(authenticationService, userRepository);
862
+ },
863
+ deps: ['AuthenticationService', 'UserRepository'],
864
+ },
865
+ {
866
+ provide: 'AuthenticationService',
867
+ useFactory: (angularFireAuth) => {
868
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
869
+ },
870
+ deps: [AngularFireAuth],
871
+ },
872
+ {
873
+ provide: 'Register',
874
+ useFactory: (registerService, userRepository) => {
875
+ return new Register(registerService, userRepository);
876
+ },
877
+ deps: ['RegisterService', 'UserRepository'],
878
+ },
879
+ {
880
+ provide: 'RegisterService',
881
+ useFactory: (angularFireAuth) => {
882
+ return new RegisterFirebaseAuthService(angularFireAuth);
883
+ },
884
+ deps: [AngularFireAuth],
885
+ },
886
+ {
887
+ provide: 'SignOut',
888
+ useFactory: (authenticationService) => {
889
+ return new SignOut(authenticationService);
890
+ },
891
+ deps: ['AuthenticationService'],
892
+ },
893
+ {
894
+ provide: 'RecoveryPassword',
895
+ useFactory: (authenticationService) => {
896
+ return new RecoveryPassword(authenticationService);
897
+ },
898
+ deps: ['AuthenticationService'],
899
+ },
900
+ ],
901
+ }]
902
+ }] });
903
+
904
+ class AngularElasticSeachModule {
905
+ static initializeApp(options) {
906
+ return {
907
+ ngModule: AngularElasticSeachModule,
908
+ providers: [{ provide: ES_CONFIG, useValue: options }],
909
+ };
910
+ }
911
+ }
912
+ AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
913
+ AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
914
+ AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
915
+ {
916
+ provide: ProductsIndex,
917
+ useFactory: (configuration) => {
918
+ return new ProductsIndex(new AxiosAdapter(configuration));
919
+ },
920
+ deps: [ES_CONFIG],
921
+ },
922
+ ] });
923
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
924
+ type: NgModule,
925
+ args: [{
926
+ providers: [
927
+ {
928
+ provide: ProductsIndex,
929
+ useFactory: (configuration) => {
930
+ return new ProductsIndex(new AxiosAdapter(configuration));
931
+ },
932
+ deps: [ES_CONFIG],
933
+ },
934
+ ],
935
+ }]
936
+ }] });
937
+
938
+ class AngularFirestoreModule {
939
+ static initializeApp(options, nameOrConfig) {
940
+ return {
941
+ ngModule: AngularFirestoreModule,
942
+ providers: [
943
+ { provide: FIREBASE_OPTIONS, useValue: options.firebase },
944
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
945
+ { provide: ES_CONFIG, useValue: options.elasticSearch },
946
+ ],
947
+ };
948
+ }
949
+ }
950
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
951
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
952
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
953
+ {
954
+ provide: 'BeautyProfileRepository',
955
+ useFactory: (firestore, userRepository) => {
956
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
957
+ },
958
+ deps: [AngularFirestore, 'UserRepository'],
959
+ },
960
+ {
961
+ provide: 'Buy2WinRepository',
962
+ useFactory: (firestore) => {
963
+ return new Buy2WinFirestoreRepository(firestore.firestore);
964
+ },
965
+ deps: [AngularFirestore],
966
+ },
967
+ {
968
+ provide: CategoryFirestoreRepository,
969
+ useFactory: (firestore) => {
970
+ return new CategoryFirestoreRepository(firestore.firestore);
971
+ },
972
+ deps: [AngularFirestore],
973
+ },
974
+ {
975
+ provide: 'CheckoutRepository',
976
+ useFactory: (firestore) => {
977
+ return new CheckoutFirestoreRepository(firestore.firestore);
978
+ },
979
+ deps: [AngularFirestore],
980
+ },
981
+ {
982
+ provide: 'CheckoutSubscriptionRepository',
983
+ useFactory: (firestore) => {
984
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
985
+ },
986
+ deps: [AngularFirestore],
987
+ },
988
+ {
989
+ provide: 'CouponRepository',
990
+ useFactory: (firestore) => {
991
+ return new CouponFirestoreRepository(firestore.firestore);
992
+ },
993
+ deps: [AngularFirestore],
994
+ },
995
+ {
996
+ provide: 'EditionRepository',
997
+ useFactory: (firestore, subscriptionRepository) => {
998
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
999
+ },
1000
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1001
+ },
1002
+ {
1003
+ provide: 'HomeRepository',
1004
+ useFactory: (firestore) => {
1005
+ return new HomeFirestoreRepository(firestore.firestore);
1006
+ },
1007
+ deps: [AngularFirestore],
1008
+ },
1009
+ {
1010
+ provide: 'LeadRepository',
1011
+ useFactory: (firestore) => {
1012
+ return new LeadFirestoreRepository(firestore.firestore);
1013
+ },
1014
+ deps: [AngularFirestore],
1015
+ },
1016
+ {
1017
+ provide: 'LegacyOrderRepository',
1018
+ useFactory: (firestore) => {
1019
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1020
+ },
1021
+ deps: [AngularFirestore],
1022
+ },
1023
+ {
1024
+ provide: 'ShopMenuRepository',
1025
+ useFactory: (firestore) => {
1026
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1027
+ },
1028
+ deps: [AngularFirestore],
1029
+ },
1030
+ {
1031
+ provide: 'OrderRepository',
1032
+ useFactory: (firestore) => {
1033
+ return new OrderFirestoreRepository(firestore.firestore);
1034
+ },
1035
+ deps: [AngularFirestore],
1036
+ },
1037
+ {
1038
+ provide: 'PaymentRepository',
1039
+ useFactory: (firestore) => {
1040
+ return new PaymentFirestoreRepository(firestore.firestore);
1041
+ },
1042
+ deps: [AngularFirestore],
1043
+ },
1044
+ {
1045
+ provide: ProductFirestoreRepository,
1046
+ useFactory: (firestore) => {
1047
+ return new ProductFirestoreRepository(firestore.firestore);
1048
+ },
1049
+ deps: [AngularFirestore],
1050
+ },
1051
+ {
1052
+ provide: 'ShopSettingsRepository',
1053
+ useFactory: (firestore) => {
1054
+ return new ShopSettingsFirestoreRepository(firestore.firestore);
1055
+ },
1056
+ deps: [AngularFirestore],
1057
+ },
1058
+ {
1059
+ provide: 'SubscriptionPaymentRepository',
1060
+ useFactory: (firestore, subscriptionRepository) => {
1061
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1062
+ },
1063
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1064
+ },
1065
+ {
1066
+ provide: 'SubscriptionPlanRepository',
1067
+ useFactory: (firestore) => {
1068
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1069
+ },
1070
+ deps: [AngularFirestore],
1071
+ },
1072
+ {
1073
+ provide: 'SubscriptionProductRepository',
1074
+ useFactory: (firestore) => {
1075
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1076
+ },
1077
+ deps: [AngularFirestore],
1078
+ },
1079
+ {
1080
+ provide: 'SubscriptionRepository',
1081
+ useFactory: (firestore) => {
1082
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1083
+ },
1084
+ deps: [AngularFirestore],
1085
+ },
1086
+ {
1087
+ provide: 'UserRepository',
1088
+ useFactory: (firestore) => {
1089
+ return new UserFirestoreRepository(firestore.firestore);
1090
+ },
1091
+ deps: [AngularFirestore],
1092
+ },
1093
+ {
1094
+ provide: 'UserAddressRepository',
1095
+ useFactory: (firestore, userRepository) => {
1096
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1097
+ },
1098
+ deps: [AngularFirestore, 'UserRepository'],
1099
+ },
1100
+ {
1101
+ provide: 'UserPaymentMethodRepository',
1102
+ useFactory: (firestore, userRepository) => {
1103
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1104
+ },
1105
+ deps: [AngularFirestore, 'UserRepository'],
1106
+ },
1107
+ {
1108
+ provide: ProductVariantFirestoreRepository,
1109
+ useFactory: (firestore, productRepository) => {
1110
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1111
+ },
1112
+ deps: [AngularFirestore, ProductFirestoreRepository],
1113
+ },
1114
+ {
1115
+ provide: APP_INITIALIZER,
1116
+ useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1117
+ deps: [AngularFirestore],
1118
+ multi: true,
1119
+ },
1120
+ ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
1121
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1122
+ type: NgModule,
1123
+ args: [{
1124
+ imports: [AngularFireModule, AngularElasticSeachModule],
1125
+ providers: [
1126
+ {
1127
+ provide: 'BeautyProfileRepository',
1128
+ useFactory: (firestore, userRepository) => {
1129
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1130
+ },
1131
+ deps: [AngularFirestore, 'UserRepository'],
1132
+ },
1133
+ {
1134
+ provide: 'Buy2WinRepository',
1135
+ useFactory: (firestore) => {
1136
+ return new Buy2WinFirestoreRepository(firestore.firestore);
1137
+ },
1138
+ deps: [AngularFirestore],
1139
+ },
1140
+ {
1141
+ provide: CategoryFirestoreRepository,
1142
+ useFactory: (firestore) => {
1143
+ return new CategoryFirestoreRepository(firestore.firestore);
1144
+ },
1145
+ deps: [AngularFirestore],
1146
+ },
1147
+ {
1148
+ provide: 'CheckoutRepository',
1149
+ useFactory: (firestore) => {
1150
+ return new CheckoutFirestoreRepository(firestore.firestore);
1151
+ },
1152
+ deps: [AngularFirestore],
1153
+ },
1154
+ {
1155
+ provide: 'CheckoutSubscriptionRepository',
1156
+ useFactory: (firestore) => {
1157
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1158
+ },
1159
+ deps: [AngularFirestore],
1160
+ },
1161
+ {
1162
+ provide: 'CouponRepository',
1163
+ useFactory: (firestore) => {
1164
+ return new CouponFirestoreRepository(firestore.firestore);
1165
+ },
1166
+ deps: [AngularFirestore],
1167
+ },
1168
+ {
1169
+ provide: 'EditionRepository',
1170
+ useFactory: (firestore, subscriptionRepository) => {
1171
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1172
+ },
1173
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1174
+ },
1175
+ {
1176
+ provide: 'HomeRepository',
1177
+ useFactory: (firestore) => {
1178
+ return new HomeFirestoreRepository(firestore.firestore);
1179
+ },
1180
+ deps: [AngularFirestore],
1181
+ },
1182
+ {
1183
+ provide: 'LeadRepository',
1184
+ useFactory: (firestore) => {
1185
+ return new LeadFirestoreRepository(firestore.firestore);
1186
+ },
1187
+ deps: [AngularFirestore],
1188
+ },
1189
+ {
1190
+ provide: 'LegacyOrderRepository',
1191
+ useFactory: (firestore) => {
1192
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1193
+ },
1194
+ deps: [AngularFirestore],
1195
+ },
1196
+ {
1197
+ provide: 'ShopMenuRepository',
1198
+ useFactory: (firestore) => {
1199
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1200
+ },
1201
+ deps: [AngularFirestore],
1202
+ },
1203
+ {
1204
+ provide: 'OrderRepository',
1205
+ useFactory: (firestore) => {
1206
+ return new OrderFirestoreRepository(firestore.firestore);
1207
+ },
1208
+ deps: [AngularFirestore],
1209
+ },
1210
+ {
1211
+ provide: 'PaymentRepository',
1212
+ useFactory: (firestore) => {
1213
+ return new PaymentFirestoreRepository(firestore.firestore);
1214
+ },
1215
+ deps: [AngularFirestore],
1216
+ },
1217
+ {
1218
+ provide: ProductFirestoreRepository,
1219
+ useFactory: (firestore) => {
1220
+ return new ProductFirestoreRepository(firestore.firestore);
1221
+ },
1222
+ deps: [AngularFirestore],
1223
+ },
1224
+ {
1225
+ provide: 'ShopSettingsRepository',
1226
+ useFactory: (firestore) => {
1227
+ return new ShopSettingsFirestoreRepository(firestore.firestore);
1228
+ },
1229
+ deps: [AngularFirestore],
1230
+ },
1231
+ {
1232
+ provide: 'SubscriptionPaymentRepository',
1233
+ useFactory: (firestore, subscriptionRepository) => {
1234
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1235
+ },
1236
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1237
+ },
1238
+ {
1239
+ provide: 'SubscriptionPlanRepository',
1240
+ useFactory: (firestore) => {
1241
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1242
+ },
1243
+ deps: [AngularFirestore],
1244
+ },
1245
+ {
1246
+ provide: 'SubscriptionProductRepository',
1247
+ useFactory: (firestore) => {
1248
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1249
+ },
1250
+ deps: [AngularFirestore],
1251
+ },
1252
+ {
1253
+ provide: 'SubscriptionRepository',
1254
+ useFactory: (firestore) => {
1255
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1256
+ },
1257
+ deps: [AngularFirestore],
1258
+ },
1259
+ {
1260
+ provide: 'UserRepository',
1261
+ useFactory: (firestore) => {
1262
+ return new UserFirestoreRepository(firestore.firestore);
1263
+ },
1264
+ deps: [AngularFirestore],
1265
+ },
1266
+ {
1267
+ provide: 'UserAddressRepository',
1268
+ useFactory: (firestore, userRepository) => {
1269
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1270
+ },
1271
+ deps: [AngularFirestore, 'UserRepository'],
1272
+ },
1273
+ {
1274
+ provide: 'UserPaymentMethodRepository',
1275
+ useFactory: (firestore, userRepository) => {
1276
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1277
+ },
1278
+ deps: [AngularFirestore, 'UserRepository'],
1279
+ },
1280
+ {
1281
+ provide: ProductVariantFirestoreRepository,
1282
+ useFactory: (firestore, productRepository) => {
1283
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1284
+ },
1285
+ deps: [AngularFirestore, ProductFirestoreRepository],
1286
+ },
1287
+ {
1288
+ provide: APP_INITIALIZER,
1289
+ useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1290
+ deps: [AngularFirestore],
1291
+ multi: true,
1292
+ },
1293
+ ],
1294
+ }]
1295
+ }] });
1296
+
1297
+ class AngularHasuraGraphQLModule {
1298
+ static initializeApp(options) {
1299
+ return {
1300
+ ngModule: AngularHasuraGraphQLModule,
1301
+ providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1302
+ };
1303
+ }
1304
+ }
1305
+ AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1306
+ AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1307
+ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1308
+ {
1309
+ provide: 'CategoryRepository',
1310
+ useExisting: CategoryHasuraGraphQLRepository,
1311
+ },
1312
+ {
1313
+ provide: CategoryHasuraGraphQLRepository,
1314
+ useFactory: (options, productRepository) => {
1315
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1316
+ },
1317
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1318
+ },
1319
+ {
1320
+ provide: 'ProductRepository',
1321
+ useExisting: ProductHasuraGraphQLRepository,
1322
+ },
1323
+ {
1324
+ provide: ProductHasuraGraphQLRepository,
1325
+ useFactory: (options) => {
1326
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1327
+ },
1328
+ deps: [HASURA_OPTIONS],
1329
+ },
1330
+ {
1331
+ provide: 'VariantRepository',
1332
+ useExisting: VariantHasuraGraphQLRepository,
1333
+ },
1334
+ {
1335
+ provide: VariantHasuraGraphQLRepository,
1336
+ useFactory: (options) => {
1337
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1338
+ },
1339
+ deps: [HASURA_OPTIONS],
1340
+ },
1341
+ ] });
1342
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1343
+ type: NgModule,
1344
+ args: [{
1345
+ providers: [
1346
+ {
1347
+ provide: 'CategoryRepository',
1348
+ useExisting: CategoryHasuraGraphQLRepository,
1349
+ },
1350
+ {
1351
+ provide: CategoryHasuraGraphQLRepository,
1352
+ useFactory: (options, productRepository) => {
1353
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1354
+ },
1355
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1356
+ },
1357
+ {
1358
+ provide: 'ProductRepository',
1359
+ useExisting: ProductHasuraGraphQLRepository,
1360
+ },
1361
+ {
1362
+ provide: ProductHasuraGraphQLRepository,
1363
+ useFactory: (options) => {
1364
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1365
+ },
1366
+ deps: [HASURA_OPTIONS],
1367
+ },
1368
+ {
1369
+ provide: 'VariantRepository',
1370
+ useExisting: VariantHasuraGraphQLRepository,
1371
+ },
1372
+ {
1373
+ provide: VariantHasuraGraphQLRepository,
1374
+ useFactory: (options) => {
1375
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1376
+ },
1377
+ deps: [HASURA_OPTIONS],
1378
+ },
1379
+ ],
1380
+ }]
1381
+ }] });
1382
+
1383
+ class AngularConnectModule {
1384
+ static initializeApp(defaultShop, options, nameOrConfig) {
1385
+ return {
1386
+ ngModule: AngularConnectModule,
1387
+ providers: [
1388
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1389
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1390
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1391
+ ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1392
+ ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1393
+ ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1394
+ ],
1395
+ };
1396
+ }
1397
+ }
1398
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1399
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1400
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1401
+ AuthService,
1402
+ CartService,
1403
+ CheckoutService,
1404
+ CheckoutSubscriptionService,
1405
+ CouponService,
1406
+ HomeShopService,
1407
+ OrderService,
1408
+ ShippingService
1409
+ ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1410
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1411
+ type: NgModule,
1412
+ args: [{
1413
+ imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1414
+ providers: [
1415
+ AuthService,
1416
+ CartService,
1417
+ CheckoutService,
1418
+ CheckoutSubscriptionService,
1419
+ CouponService,
1420
+ HomeShopService,
1421
+ OrderService,
1422
+ ShippingService
1423
+ ],
1424
+ }]
1425
+ }] });
1426
+
1427
+ /**
1428
+ * Generated bundle index. Do not edit.
1429
+ */
1430
+
1431
+ export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ShippingService };
1432
+ //# sourceMappingURL=infrab4a-connect-angular.js.map