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