@infrab4a/connect-angular 0.7.4 → 0.8.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 (35) hide show
  1. package/bundles/infrab4a-connect-angular.umd.js +980 -994
  2. package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
  3. package/esm2015/infrab4a-connect-angular.js +4 -4
  4. package/esm2015/lib/angular-connect.module.js +30 -30
  5. package/esm2015/lib/angular-firebase-auth.module.js +71 -71
  6. package/esm2015/lib/angular-firestore.module.js +309 -323
  7. package/esm2015/lib/consts/default-shop.const.js +2 -2
  8. package/esm2015/lib/consts/index.js +2 -2
  9. package/esm2015/lib/index.js +5 -5
  10. package/esm2015/lib/services/auth.service.js +33 -33
  11. package/esm2015/lib/services/cart.service.js +153 -153
  12. package/esm2015/lib/services/checkout.service.js +57 -57
  13. package/esm2015/lib/services/index.js +5 -5
  14. package/esm2015/lib/services/order.service.js +32 -32
  15. package/esm2015/lib/services/types/index.js +2 -2
  16. package/esm2015/lib/services/types/required-checkout-data.type.js +2 -2
  17. package/esm2015/public-api.js +2 -2
  18. package/fesm2015/infrab4a-connect-angular.js +623 -637
  19. package/fesm2015/infrab4a-connect-angular.js.map +1 -1
  20. package/infrab4a-connect-angular.d.ts +5 -5
  21. package/lib/angular-connect.module.d.ts +12 -12
  22. package/lib/angular-firebase-auth.module.d.ts +10 -10
  23. package/lib/angular-firestore.module.d.ts +10 -10
  24. package/lib/consts/default-shop.const.d.ts +1 -1
  25. package/lib/consts/index.d.ts +1 -1
  26. package/lib/index.d.ts +4 -4
  27. package/lib/services/auth.service.d.ts +16 -16
  28. package/lib/services/cart.service.d.ts +35 -35
  29. package/lib/services/checkout.service.d.ts +18 -18
  30. package/lib/services/index.d.ts +4 -4
  31. package/lib/services/order.service.d.ts +13 -13
  32. package/lib/services/types/index.d.ts +1 -1
  33. package/lib/services/types/required-checkout-data.type.d.ts +2 -2
  34. package/package.json +2 -2
  35. package/public-api.d.ts +1 -1
@@ -5,665 +5,651 @@ import { AngularFireAuth } from '@angular/fire/auth';
5
5
  import { throwError, from, of, Subject, iif } from 'rxjs';
6
6
  import { mergeMap, map, concatMap, tap, catchError } from 'rxjs/operators';
7
7
  import * as i1$1 from '@infrab4a/connect';
8
- import { isNil, NotFoundError, Checkout, pick, LineItem, CouponTypes, FinancialCoupon, CouponSubtypes, Order, Authentication, AuthenticationFirebaseAuthService, SignOut, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository } from '@infrab4a/connect';
8
+ import { isNil, NotFoundError, Checkout, pick, LineItem, CouponTypes, FinancialCoupon, CouponSubtypes, Order, Authentication, AuthenticationFirebaseAuthService, SignOut, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, ProductVariantFirestoreRepository } from '@infrab4a/connect';
9
9
  import { __awaiter } from 'tslib';
10
10
  import cookie from 'js-cookie';
11
11
  import * as i1$2 from '@angular/fire/firestore';
12
12
  import { AngularFirestore } from '@angular/fire/firestore';
13
13
  import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
14
14
 
15
- class AuthService {
16
- constructor(angularFireAuth, userRepository) {
17
- this.angularFireAuth = angularFireAuth;
18
- this.userRepository = userRepository;
19
- }
20
- getAuthstate() {
21
- return this.angularFireAuth.authState.pipe(mergeMap(() => this.getUser()));
22
- }
23
- getUser() {
24
- return this.getFireUser().pipe(map((user) => user.uid || throwError(() => new Error('Usuário não logado'))), mergeMap((id) => this.userRepository.get({ id })));
25
- }
26
- getTokenId() {
27
- return this.angularFireAuth.idToken;
28
- }
29
- getFireUser() {
30
- return this.angularFireAuth.user;
31
- }
32
- }
33
- 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 });
34
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
35
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
36
- type: Injectable
37
- }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
38
- type: Inject,
39
- args: ['UserRepository']
15
+ class AuthService {
16
+ constructor(angularFireAuth, userRepository) {
17
+ this.angularFireAuth = angularFireAuth;
18
+ this.userRepository = userRepository;
19
+ }
20
+ getAuthstate() {
21
+ return this.angularFireAuth.authState.pipe(mergeMap(() => this.getUser()));
22
+ }
23
+ getUser() {
24
+ return this.getFireUser().pipe(map((user) => user.uid || throwError(() => new Error('Usuário não logado'))), mergeMap((id) => this.userRepository.get({ id })));
25
+ }
26
+ getTokenId() {
27
+ return this.angularFireAuth.idToken;
28
+ }
29
+ getFireUser() {
30
+ return this.angularFireAuth.user;
31
+ }
32
+ }
33
+ 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 });
34
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
35
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
36
+ type: Injectable
37
+ }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
38
+ type: Inject,
39
+ args: ['UserRepository']
40
40
  }] }]; } });
41
41
 
42
42
  const DEFAULT_SHOP = 'DEFAULT_SHOP';
43
43
 
44
- class CheckoutService {
45
- constructor(checkoutRepository, userRepository, defaultShop) {
46
- this.checkoutRepository = checkoutRepository;
47
- this.userRepository = userRepository;
48
- this.defaultShop = defaultShop;
49
- }
50
- getCheckout(checkoutData) {
51
- const checkoutId = cookie.get('checkoutId');
52
- if (!isNil(checkoutId))
53
- return from(this.checkoutRepository.get({ id: checkoutId }));
54
- return from(this.createCheckout(checkoutData));
55
- }
56
- getUserByCheckout(checkoutId) {
57
- 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'))));
58
- }
59
- updateCheckoutLineItems(checkout) {
60
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
61
- }
62
- updateCheckoutUser(checkout) {
63
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
64
- }
65
- clearCheckoutFromSession() {
66
- cookie.remove('checkoutId');
67
- return of();
68
- }
69
- createCheckout(checkoutData) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- 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 }));
72
- cookie.set('checkoutId', checkout.id);
73
- return checkout;
74
- });
75
- }
76
- }
77
- CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, deps: [{ token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
78
- CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
79
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
80
- type: Injectable
81
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
82
- type: Inject,
83
- args: ['CheckoutRepository']
84
- }] }, { type: undefined, decorators: [{
85
- type: Inject,
86
- args: ['UserRepository']
87
- }] }, { type: i1$1.Shops, decorators: [{
88
- type: Inject,
89
- args: [DEFAULT_SHOP]
44
+ class CheckoutService {
45
+ constructor(checkoutRepository, userRepository, defaultShop) {
46
+ this.checkoutRepository = checkoutRepository;
47
+ this.userRepository = userRepository;
48
+ this.defaultShop = defaultShop;
49
+ }
50
+ getCheckout(checkoutData) {
51
+ const checkoutId = cookie.get('checkoutId');
52
+ if (!isNil(checkoutId))
53
+ return from(this.checkoutRepository.get({ id: checkoutId }));
54
+ return from(this.createCheckout(checkoutData));
55
+ }
56
+ getUserByCheckout(checkoutId) {
57
+ 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'))));
58
+ }
59
+ updateCheckoutLineItems(checkout) {
60
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
61
+ }
62
+ updateCheckoutUser(checkout) {
63
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
64
+ }
65
+ clearCheckoutFromSession() {
66
+ cookie.remove('checkoutId');
67
+ return of();
68
+ }
69
+ createCheckout(checkoutData) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ 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 }));
72
+ cookie.set('checkoutId', checkout.id);
73
+ return checkout;
74
+ });
75
+ }
76
+ }
77
+ CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, deps: [{ token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
78
+ CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
79
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
80
+ type: Injectable
81
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
82
+ type: Inject,
83
+ args: ['CheckoutRepository']
84
+ }] }, { type: undefined, decorators: [{
85
+ type: Inject,
86
+ args: ['UserRepository']
87
+ }] }, { type: i1$1.Shops, decorators: [{
88
+ type: Inject,
89
+ args: [DEFAULT_SHOP]
90
90
  }] }]; } });
91
91
 
92
- class CartService {
93
- constructor(authService, checkoutService, defaultShop) {
94
- this.authService = authService;
95
- this.checkoutService = checkoutService;
96
- this.defaultShop = defaultShop;
97
- this.cartSubject = new Subject();
98
- this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
99
- var _a;
100
- const items = [];
101
- const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
102
- if (index > -1) {
103
- checkoutLoaded.lineItems[index].quantity += quantity;
104
- checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
105
- }
106
- else
107
- checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
108
- return this.checkoutService
109
- .updateCheckoutLineItems(checkoutLoaded)
110
- .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
111
- }));
112
- this.generateCartObject = (items) => {
113
- const cart = {};
114
- items === null || items === void 0 ? void 0 : items.forEach((item) => {
115
- var _a;
116
- 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) })));
117
- });
118
- return cart;
119
- };
120
- this.buildLineItem = ({ checkout, item, quantity, }) => {
121
- var _a, _b, _c, _d, _e;
122
- 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;
123
- if (this.checkMaxStock(item, quantity || 0))
124
- throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
125
- const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
126
- const { id, name, brand, slug, stock, price, weight, categories, sku } = item;
127
- const isGift = item.isGift || null;
128
- const pricePaid = this.getProductPrice({
129
- product: item,
130
- shop: checkout.shop || this.defaultShop,
131
- isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
132
- });
133
- return LineItem.toInstance({
134
- id,
135
- name,
136
- brand,
137
- slug,
138
- sku,
139
- stock,
140
- price,
141
- image,
142
- weight,
143
- quantity: (item.quantity || 0) + (quantity || 0),
144
- pricePaid,
145
- categories,
146
- isGift,
147
- });
148
- };
149
- this.getProductPrice = ({ product, shop, isSubscriber, }) => {
150
- const info = product.getInfoByShop(shop);
151
- if (product.isGift)
152
- return 0;
153
- return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
154
- };
155
- this.checkMaxStock = (item, quantity) => {
156
- var _a;
157
- const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
158
- const currentItemAmount = item.quantity || 0;
159
- return currentItemAmount + quantity > maxStock;
160
- };
161
- }
162
- addItem(item, quantity = 1) {
163
- return this.checkoutService.getCheckout().pipe(map((checkout) => ({ checkout, lineItem: this.buildLineItem({ checkout, item, quantity: quantity || 1 }) })), concatMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
164
- }
165
- decreaseItem(item) {
166
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
167
- var _a;
168
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
169
- if (!isNil(checkoutItem))
170
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
171
- return checkout;
172
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
173
- }
174
- getCart(checkout) {
175
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
176
- return this.cartSubject;
177
- }
178
- getDiscount(coupon) {
179
- switch (coupon.type) {
180
- case CouponTypes.FINANCIAL:
181
- return this.getFinancialDiscount(coupon);
182
- case CouponTypes.PRODUCT:
183
- return (subTotalPrice) => subTotalPrice;
184
- case CouponTypes.GIFTCARD:
185
- return this.getFinancialDiscount(coupon);
186
- case CouponTypes.VOUCHER:
187
- return (subTotalPrice) => subTotalPrice;
188
- }
189
- }
190
- getVariantPriceDiscount(item, shop) {
191
- 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)));
192
- }
193
- removeItem(item) {
194
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
195
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
196
- if (index >= 0)
197
- checkout.lineItems.splice(index, 1);
198
- return checkout;
199
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
200
- }
201
- updateUserCart(user) {
202
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: checkout.lineItems.map((item) => this.buildLineItem({ checkout, item })) })))), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
203
- }
204
- clearCart() {
205
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
206
- this.checkoutService.clearCheckoutFromSession();
207
- return checkout;
208
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
209
- }
210
- buildCartFromCheckout(checkoutData) {
211
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
212
- }
213
- getFinancialDiscount(coupon) {
214
- return (subTotalPrice) => {
215
- if (FinancialCoupon.isFinancialCoupon(coupon))
216
- switch (coupon.subtype) {
217
- case CouponSubtypes.ABSOLUTE:
218
- return subTotalPrice - coupon.discount * 100;
219
- case CouponSubtypes.PERCENTAGE:
220
- return subTotalPrice * (1 - coupon.discount / 100);
221
- }
222
- };
223
- }
224
- }
225
- CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
226
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
227
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
228
- type: Injectable
229
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.Shops, decorators: [{
230
- type: Inject,
231
- args: [DEFAULT_SHOP]
92
+ class CartService {
93
+ constructor(authService, checkoutService, defaultShop) {
94
+ this.authService = authService;
95
+ this.checkoutService = checkoutService;
96
+ this.defaultShop = defaultShop;
97
+ this.cartSubject = new Subject();
98
+ this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
99
+ var _a;
100
+ const items = [];
101
+ const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
102
+ if (index > -1) {
103
+ checkoutLoaded.lineItems[index].quantity += quantity;
104
+ checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
105
+ }
106
+ else
107
+ checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
108
+ return this.checkoutService
109
+ .updateCheckoutLineItems(checkoutLoaded)
110
+ .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
111
+ }));
112
+ this.generateCartObject = (items) => {
113
+ const cart = {};
114
+ items === null || items === void 0 ? void 0 : items.forEach((item) => {
115
+ var _a;
116
+ 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) })));
117
+ });
118
+ return cart;
119
+ };
120
+ this.buildLineItem = ({ checkout, item, quantity, }) => {
121
+ var _a, _b, _c, _d, _e;
122
+ 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;
123
+ if (this.checkMaxStock(item, quantity || 0))
124
+ throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
125
+ const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
126
+ const { id, name, brand, slug, stock, price, weight, categories, sku } = item;
127
+ const isGift = item.isGift || null;
128
+ const pricePaid = this.getProductPrice({
129
+ product: item,
130
+ shop: checkout.shop || this.defaultShop,
131
+ isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
132
+ });
133
+ return LineItem.toInstance({
134
+ id,
135
+ name,
136
+ brand,
137
+ slug,
138
+ sku,
139
+ stock,
140
+ price,
141
+ image,
142
+ weight,
143
+ quantity: (item.quantity || 0) + (quantity || 0),
144
+ pricePaid,
145
+ categories,
146
+ isGift,
147
+ });
148
+ };
149
+ this.getProductPrice = ({ product, shop, isSubscriber, }) => {
150
+ const info = product.getInfoByShop(shop);
151
+ if (product.isGift)
152
+ return 0;
153
+ return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
154
+ };
155
+ this.checkMaxStock = (item, quantity) => {
156
+ var _a;
157
+ const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
158
+ const currentItemAmount = item.quantity || 0;
159
+ return currentItemAmount + quantity > maxStock;
160
+ };
161
+ }
162
+ addItem(item, quantity = 1) {
163
+ return this.checkoutService.getCheckout().pipe(map((checkout) => ({ checkout, lineItem: this.buildLineItem({ checkout, item, quantity: quantity || 1 }) })), concatMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
164
+ }
165
+ decreaseItem(item) {
166
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
167
+ var _a;
168
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
169
+ if (!isNil(checkoutItem))
170
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
171
+ return checkout;
172
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
173
+ }
174
+ getCart(checkout) {
175
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
176
+ return this.cartSubject;
177
+ }
178
+ getDiscount(coupon) {
179
+ switch (coupon.type) {
180
+ case CouponTypes.FINANCIAL:
181
+ return this.getFinancialDiscount(coupon);
182
+ case CouponTypes.PRODUCT:
183
+ return (subTotalPrice) => subTotalPrice;
184
+ case CouponTypes.GIFTCARD:
185
+ return this.getFinancialDiscount(coupon);
186
+ case CouponTypes.VOUCHER:
187
+ return (subTotalPrice) => subTotalPrice;
188
+ }
189
+ }
190
+ getVariantPriceDiscount(item, shop) {
191
+ 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)));
192
+ }
193
+ removeItem(item) {
194
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
195
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
196
+ if (index >= 0)
197
+ checkout.lineItems.splice(index, 1);
198
+ return checkout;
199
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
200
+ }
201
+ updateUserCart(user) {
202
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: checkout.lineItems.map((item) => this.buildLineItem({ checkout, item })) })))), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
203
+ }
204
+ clearCart() {
205
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
206
+ this.checkoutService.clearCheckoutFromSession();
207
+ return checkout;
208
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
209
+ }
210
+ buildCartFromCheckout(checkoutData) {
211
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
212
+ }
213
+ getFinancialDiscount(coupon) {
214
+ return (subTotalPrice) => {
215
+ if (FinancialCoupon.isFinancialCoupon(coupon))
216
+ switch (coupon.subtype) {
217
+ case CouponSubtypes.ABSOLUTE:
218
+ return subTotalPrice - coupon.discount * 100;
219
+ case CouponSubtypes.PERCENTAGE:
220
+ return subTotalPrice * (1 - coupon.discount / 100);
221
+ }
222
+ };
223
+ }
224
+ }
225
+ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
226
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
227
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
228
+ type: Injectable
229
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.Shops, decorators: [{
230
+ type: Inject,
231
+ args: [DEFAULT_SHOP]
232
232
  }] }]; } });
233
233
 
234
- class OrderService {
235
- constructor(angularFirestore, orderRepository) {
236
- this.angularFirestore = angularFirestore;
237
- this.orderRepository = orderRepository;
238
- this.orderSubject = new Subject();
239
- }
240
- getOrder(id) {
241
- this.angularFirestore
242
- .doc(`${this.orderRepository.collectionName}/${id}`)
243
- .valueChanges()
244
- .pipe(map((doc) => Order.toInstance(doc)))
245
- .subscribe((doc) => this.orderSubject.next(doc));
246
- return this.orderSubject;
247
- }
248
- }
249
- OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$2.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
250
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
251
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
252
- type: Injectable
253
- }], ctorParameters: function () { return [{ type: i1$2.AngularFirestore }, { type: i1$1.OrderFirestoreRepository, decorators: [{
254
- type: Inject,
255
- args: ['OrderRepository']
234
+ class OrderService {
235
+ constructor(angularFirestore, orderRepository) {
236
+ this.angularFirestore = angularFirestore;
237
+ this.orderRepository = orderRepository;
238
+ this.orderSubject = new Subject();
239
+ }
240
+ getOrder(id) {
241
+ this.angularFirestore
242
+ .doc(`${this.orderRepository.collectionName}/${id}`)
243
+ .valueChanges()
244
+ .pipe(map((doc) => Order.toInstance(doc)))
245
+ .subscribe((doc) => this.orderSubject.next(doc));
246
+ return this.orderSubject;
247
+ }
248
+ }
249
+ OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$2.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
250
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
252
+ type: Injectable
253
+ }], ctorParameters: function () { return [{ type: i1$2.AngularFirestore }, { type: i1$1.OrderFirestoreRepository, decorators: [{
254
+ type: Inject,
255
+ args: ['OrderRepository']
256
256
  }] }]; } });
257
257
 
258
- class AngularFirebaseAuthModule {
259
- static initializeApp(options, nameOrConfig) {
260
- return {
261
- ngModule: AngularFirebaseAuthModule,
262
- providers: [
263
- { provide: FIREBASE_OPTIONS, useValue: options },
264
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
265
- ],
266
- };
267
- }
268
- }
269
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
270
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
271
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
272
- {
273
- provide: 'Authentication',
274
- useFactory: (authenticationService, userRepository) => {
275
- return new Authentication(authenticationService, userRepository);
276
- },
277
- deps: ['AuthenticationService', 'UserRepository'],
278
- },
279
- {
280
- provide: 'AuthenticationService',
281
- useFactory: (angularFireAuth) => {
282
- return new AuthenticationFirebaseAuthService(angularFireAuth);
283
- },
284
- deps: [AngularFireAuth],
285
- },
286
- {
287
- provide: 'SignOut',
288
- useFactory: (authenticationService) => {
289
- return new SignOut(authenticationService);
290
- },
291
- deps: ['AuthenticationService'],
292
- },
293
- ], imports: [[AngularFireModule]] });
294
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
295
- type: NgModule,
296
- args: [{
297
- imports: [AngularFireModule],
298
- providers: [
299
- {
300
- provide: 'Authentication',
301
- useFactory: (authenticationService, userRepository) => {
302
- return new Authentication(authenticationService, userRepository);
303
- },
304
- deps: ['AuthenticationService', 'UserRepository'],
305
- },
306
- {
307
- provide: 'AuthenticationService',
308
- useFactory: (angularFireAuth) => {
309
- return new AuthenticationFirebaseAuthService(angularFireAuth);
310
- },
311
- deps: [AngularFireAuth],
312
- },
313
- {
314
- provide: 'SignOut',
315
- useFactory: (authenticationService) => {
316
- return new SignOut(authenticationService);
317
- },
318
- deps: ['AuthenticationService'],
319
- },
320
- ],
321
- }]
258
+ class AngularFirebaseAuthModule {
259
+ static initializeApp(options, nameOrConfig) {
260
+ return {
261
+ ngModule: AngularFirebaseAuthModule,
262
+ providers: [
263
+ { provide: FIREBASE_OPTIONS, useValue: options },
264
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
265
+ ],
266
+ };
267
+ }
268
+ }
269
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
270
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
271
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
272
+ {
273
+ provide: 'Authentication',
274
+ useFactory: (authenticationService, userRepository) => {
275
+ return new Authentication(authenticationService, userRepository);
276
+ },
277
+ deps: ['AuthenticationService', 'UserRepository'],
278
+ },
279
+ {
280
+ provide: 'AuthenticationService',
281
+ useFactory: (angularFireAuth) => {
282
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
283
+ },
284
+ deps: [AngularFireAuth],
285
+ },
286
+ {
287
+ provide: 'SignOut',
288
+ useFactory: (authenticationService) => {
289
+ return new SignOut(authenticationService);
290
+ },
291
+ deps: ['AuthenticationService'],
292
+ },
293
+ ], imports: [[AngularFireModule]] });
294
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
295
+ type: NgModule,
296
+ args: [{
297
+ imports: [AngularFireModule],
298
+ providers: [
299
+ {
300
+ provide: 'Authentication',
301
+ useFactory: (authenticationService, userRepository) => {
302
+ return new Authentication(authenticationService, userRepository);
303
+ },
304
+ deps: ['AuthenticationService', 'UserRepository'],
305
+ },
306
+ {
307
+ provide: 'AuthenticationService',
308
+ useFactory: (angularFireAuth) => {
309
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
310
+ },
311
+ deps: [AngularFireAuth],
312
+ },
313
+ {
314
+ provide: 'SignOut',
315
+ useFactory: (authenticationService) => {
316
+ return new SignOut(authenticationService);
317
+ },
318
+ deps: ['AuthenticationService'],
319
+ },
320
+ ],
321
+ }]
322
322
  }] });
323
323
 
324
- class AngularFirestoreModule {
325
- static initializeApp(options, nameOrConfig) {
326
- return {
327
- ngModule: AngularFirestoreModule,
328
- providers: [
329
- { provide: FIREBASE_OPTIONS, useValue: options },
330
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
331
- ],
332
- };
333
- }
334
- }
335
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
336
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule] });
337
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
338
- {
339
- provide: 'BeautyProfileRepository',
340
- useFactory: (firestore, userRepository) => {
341
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
342
- },
343
- deps: [AngularFirestore, 'UserRepository'],
344
- },
345
- {
346
- provide: 'Buy2WinRepository',
347
- useFactory: (firestore) => {
348
- return new Buy2WinFirestoreRepository(firestore.firestore);
349
- },
350
- deps: [AngularFirestore],
351
- },
352
- {
353
- provide: 'CategoryRepository',
354
- useFactory: (firestore) => {
355
- return new CategoryFirestoreRepository(firestore.firestore);
356
- },
357
- deps: [AngularFirestore],
358
- },
359
- {
360
- provide: 'CheckoutRepository',
361
- useFactory: (firestore) => {
362
- return new CheckoutFirestoreRepository(firestore.firestore);
363
- },
364
- deps: [AngularFirestore],
365
- },
366
- {
367
- provide: 'CheckoutSubscriptionRepository',
368
- useFactory: (firestore) => {
369
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
370
- },
371
- deps: [AngularFirestore],
372
- },
373
- {
374
- provide: 'CouponRepository',
375
- useFactory: (firestore) => {
376
- return new CouponFirestoreRepository(firestore.firestore);
377
- },
378
- deps: [AngularFirestore],
379
- },
380
- {
381
- provide: 'EditionRepository',
382
- useFactory: (firestore, subscriptionRepository) => {
383
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
384
- },
385
- deps: [AngularFirestore, 'SubscriptionRepository'],
386
- },
387
- {
388
- provide: 'HomeRepository',
389
- useFactory: (firestore) => {
390
- return new HomeFirestoreRepository(firestore.firestore);
391
- },
392
- deps: [AngularFirestore],
393
- },
394
- {
395
- provide: 'LeadRepository',
396
- useFactory: (firestore) => {
397
- return new LeadFirestoreRepository(firestore.firestore);
398
- },
399
- deps: [AngularFirestore],
400
- },
401
- {
402
- provide: 'LegacyOrderRepository',
403
- useFactory: (firestore) => {
404
- return new LegacyOrderFirestoreRepository(firestore.firestore);
405
- },
406
- deps: [AngularFirestore],
407
- },
408
- {
409
- provide: 'ShopMenuRepository',
410
- useFactory: (firestore) => {
411
- return new ShopMenuFirestoreRepository(firestore.firestore);
412
- },
413
- deps: [AngularFirestore],
414
- },
415
- {
416
- provide: 'OrderRepository',
417
- useFactory: (firestore) => {
418
- return new OrderFirestoreRepository(firestore.firestore);
419
- },
420
- deps: [AngularFirestore],
421
- },
422
- {
423
- provide: 'PaymentRepository',
424
- useFactory: (firestore) => {
425
- return new PaymentFirestoreRepository(firestore.firestore);
426
- },
427
- deps: [AngularFirestore],
428
- },
429
- {
430
- provide: 'ProductRepository',
431
- useFactory: (firestore) => {
432
- return new ProductFirestoreRepository(firestore.firestore);
433
- },
434
- deps: [AngularFirestore],
435
- },
436
- {
437
- provide: 'SubscriptionPaymentRepository',
438
- useFactory: (firestore, subscriptionRepository) => {
439
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
440
- },
441
- deps: [AngularFirestore, 'SubscriptionRepository'],
442
- },
443
- {
444
- provide: 'SubscriptionPlanRepository',
445
- useFactory: (firestore) => {
446
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
447
- },
448
- deps: [AngularFirestore],
449
- },
450
- {
451
- provide: 'SubscriptionRepository',
452
- useFactory: (firestore) => {
453
- return new SubscriptionFirestoreRepository(firestore.firestore);
454
- },
455
- deps: [AngularFirestore],
456
- },
457
- {
458
- provide: 'UserRepository',
459
- useFactory: (firestore) => {
460
- return new UserFirestoreRepository(firestore.firestore);
461
- },
462
- deps: [AngularFirestore],
463
- },
464
- {
465
- provide: 'UserAddressRepository',
466
- useFactory: (firestore, userRepository) => {
467
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
468
- },
469
- deps: [AngularFirestore, 'UserRepository'],
470
- },
471
- {
472
- provide: 'UserPaymentMethodRepository',
473
- useFactory: (firestore, userRepository) => {
474
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
475
- },
476
- deps: [AngularFirestore, 'UserRepository'],
477
- },
478
- {
479
- provide: 'VariantRepository',
480
- useFactory: (firestore, productRepository) => {
481
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
482
- },
483
- deps: [AngularFirestore, 'ProductRepository'],
484
- },
485
- ], imports: [[AngularFireModule]] });
486
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
487
- type: NgModule,
488
- args: [{
489
- imports: [AngularFireModule],
490
- providers: [
491
- {
492
- provide: 'BeautyProfileRepository',
493
- useFactory: (firestore, userRepository) => {
494
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
495
- },
496
- deps: [AngularFirestore, 'UserRepository'],
497
- },
498
- {
499
- provide: 'Buy2WinRepository',
500
- useFactory: (firestore) => {
501
- return new Buy2WinFirestoreRepository(firestore.firestore);
502
- },
503
- deps: [AngularFirestore],
504
- },
505
- {
506
- provide: 'CategoryRepository',
507
- useFactory: (firestore) => {
508
- return new CategoryFirestoreRepository(firestore.firestore);
509
- },
510
- deps: [AngularFirestore],
511
- },
512
- {
513
- provide: 'CheckoutRepository',
514
- useFactory: (firestore) => {
515
- return new CheckoutFirestoreRepository(firestore.firestore);
516
- },
517
- deps: [AngularFirestore],
518
- },
519
- {
520
- provide: 'CheckoutSubscriptionRepository',
521
- useFactory: (firestore) => {
522
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
523
- },
524
- deps: [AngularFirestore],
525
- },
526
- {
527
- provide: 'CouponRepository',
528
- useFactory: (firestore) => {
529
- return new CouponFirestoreRepository(firestore.firestore);
530
- },
531
- deps: [AngularFirestore],
532
- },
533
- {
534
- provide: 'EditionRepository',
535
- useFactory: (firestore, subscriptionRepository) => {
536
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
537
- },
538
- deps: [AngularFirestore, 'SubscriptionRepository'],
539
- },
540
- {
541
- provide: 'HomeRepository',
542
- useFactory: (firestore) => {
543
- return new HomeFirestoreRepository(firestore.firestore);
544
- },
545
- deps: [AngularFirestore],
546
- },
547
- {
548
- provide: 'LeadRepository',
549
- useFactory: (firestore) => {
550
- return new LeadFirestoreRepository(firestore.firestore);
551
- },
552
- deps: [AngularFirestore],
553
- },
554
- {
555
- provide: 'LegacyOrderRepository',
556
- useFactory: (firestore) => {
557
- return new LegacyOrderFirestoreRepository(firestore.firestore);
558
- },
559
- deps: [AngularFirestore],
560
- },
561
- {
562
- provide: 'ShopMenuRepository',
563
- useFactory: (firestore) => {
564
- return new ShopMenuFirestoreRepository(firestore.firestore);
565
- },
566
- deps: [AngularFirestore],
567
- },
568
- {
569
- provide: 'OrderRepository',
570
- useFactory: (firestore) => {
571
- return new OrderFirestoreRepository(firestore.firestore);
572
- },
573
- deps: [AngularFirestore],
574
- },
575
- {
576
- provide: 'PaymentRepository',
577
- useFactory: (firestore) => {
578
- return new PaymentFirestoreRepository(firestore.firestore);
579
- },
580
- deps: [AngularFirestore],
581
- },
582
- {
583
- provide: 'ProductRepository',
584
- useFactory: (firestore) => {
585
- return new ProductFirestoreRepository(firestore.firestore);
586
- },
587
- deps: [AngularFirestore],
588
- },
589
- {
590
- provide: 'SubscriptionPaymentRepository',
591
- useFactory: (firestore, subscriptionRepository) => {
592
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
593
- },
594
- deps: [AngularFirestore, 'SubscriptionRepository'],
595
- },
596
- {
597
- provide: 'SubscriptionPlanRepository',
598
- useFactory: (firestore) => {
599
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
600
- },
601
- deps: [AngularFirestore],
602
- },
603
- {
604
- provide: 'SubscriptionRepository',
605
- useFactory: (firestore) => {
606
- return new SubscriptionFirestoreRepository(firestore.firestore);
607
- },
608
- deps: [AngularFirestore],
609
- },
610
- {
611
- provide: 'UserRepository',
612
- useFactory: (firestore) => {
613
- return new UserFirestoreRepository(firestore.firestore);
614
- },
615
- deps: [AngularFirestore],
616
- },
617
- {
618
- provide: 'UserAddressRepository',
619
- useFactory: (firestore, userRepository) => {
620
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
621
- },
622
- deps: [AngularFirestore, 'UserRepository'],
623
- },
624
- {
625
- provide: 'UserPaymentMethodRepository',
626
- useFactory: (firestore, userRepository) => {
627
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
628
- },
629
- deps: [AngularFirestore, 'UserRepository'],
630
- },
631
- {
632
- provide: 'VariantRepository',
633
- useFactory: (firestore, productRepository) => {
634
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
635
- },
636
- deps: [AngularFirestore, 'ProductRepository'],
637
- },
638
- ],
639
- }]
324
+ class AngularFirestoreModule {
325
+ static initializeApp(options, nameOrConfig) {
326
+ return {
327
+ ngModule: AngularFirestoreModule,
328
+ providers: [
329
+ { provide: FIREBASE_OPTIONS, useValue: options },
330
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
331
+ ],
332
+ };
333
+ }
334
+ }
335
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
336
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule] });
337
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
338
+ {
339
+ provide: 'BeautyProfileRepository',
340
+ useFactory: (firestore, userRepository) => {
341
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
342
+ },
343
+ deps: [AngularFirestore, 'UserRepository'],
344
+ },
345
+ {
346
+ provide: 'Buy2WinRepository',
347
+ useFactory: (firestore) => {
348
+ return new Buy2WinFirestoreRepository(firestore.firestore);
349
+ },
350
+ deps: [AngularFirestore],
351
+ },
352
+ {
353
+ provide: 'CategoryRepository',
354
+ useFactory: (firestore) => {
355
+ return new CategoryFirestoreRepository(firestore.firestore);
356
+ },
357
+ deps: [AngularFirestore],
358
+ },
359
+ {
360
+ provide: 'CheckoutRepository',
361
+ useFactory: (firestore) => {
362
+ return new CheckoutFirestoreRepository(firestore.firestore);
363
+ },
364
+ deps: [AngularFirestore],
365
+ },
366
+ {
367
+ provide: 'CheckoutSubscriptionRepository',
368
+ useFactory: (firestore) => {
369
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
370
+ },
371
+ deps: [AngularFirestore],
372
+ },
373
+ {
374
+ provide: 'CouponRepository',
375
+ useFactory: (firestore) => {
376
+ return new CouponFirestoreRepository(firestore.firestore);
377
+ },
378
+ deps: [AngularFirestore],
379
+ },
380
+ {
381
+ provide: 'EditionRepository',
382
+ useFactory: (firestore, subscriptionRepository) => {
383
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
384
+ },
385
+ deps: [AngularFirestore, 'SubscriptionRepository'],
386
+ },
387
+ {
388
+ provide: 'HomeRepository',
389
+ useFactory: (firestore) => {
390
+ return new HomeFirestoreRepository(firestore.firestore);
391
+ },
392
+ deps: [AngularFirestore],
393
+ },
394
+ {
395
+ provide: 'LeadRepository',
396
+ useFactory: (firestore) => {
397
+ return new LeadFirestoreRepository(firestore.firestore);
398
+ },
399
+ deps: [AngularFirestore],
400
+ },
401
+ {
402
+ provide: 'LegacyOrderRepository',
403
+ useFactory: (firestore) => {
404
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
405
+ },
406
+ deps: [AngularFirestore],
407
+ },
408
+ {
409
+ provide: 'ShopMenuRepository',
410
+ useFactory: (firestore) => {
411
+ return new ShopMenuFirestoreRepository(firestore.firestore);
412
+ },
413
+ deps: [AngularFirestore],
414
+ },
415
+ {
416
+ provide: 'OrderRepository',
417
+ useFactory: (firestore) => {
418
+ return new OrderFirestoreRepository(firestore.firestore);
419
+ },
420
+ deps: [AngularFirestore],
421
+ },
422
+ {
423
+ provide: 'PaymentRepository',
424
+ useFactory: (firestore) => {
425
+ return new PaymentFirestoreRepository(firestore.firestore);
426
+ },
427
+ deps: [AngularFirestore],
428
+ },
429
+ {
430
+ provide: 'ProductRepository',
431
+ useFactory: (firestore) => {
432
+ return new ProductFirestoreRepository(firestore.firestore);
433
+ },
434
+ deps: [AngularFirestore],
435
+ },
436
+ {
437
+ provide: 'SubscriptionPaymentRepository',
438
+ useFactory: (firestore, subscriptionRepository) => {
439
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
440
+ },
441
+ deps: [AngularFirestore, 'SubscriptionRepository'],
442
+ },
443
+ {
444
+ provide: 'SubscriptionPlanRepository',
445
+ useFactory: (firestore) => {
446
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
447
+ },
448
+ deps: [AngularFirestore],
449
+ },
450
+ {
451
+ provide: 'SubscriptionRepository',
452
+ useFactory: (firestore) => {
453
+ return new SubscriptionFirestoreRepository(firestore.firestore);
454
+ },
455
+ deps: [AngularFirestore],
456
+ },
457
+ {
458
+ provide: 'UserRepository',
459
+ useFactory: (firestore) => {
460
+ return new UserFirestoreRepository(firestore.firestore);
461
+ },
462
+ deps: [AngularFirestore],
463
+ },
464
+ {
465
+ provide: 'UserAddressRepository',
466
+ useFactory: (firestore, userRepository) => {
467
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
468
+ },
469
+ deps: [AngularFirestore, 'UserRepository'],
470
+ },
471
+ {
472
+ provide: 'VariantRepository',
473
+ useFactory: (firestore, productRepository) => {
474
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
475
+ },
476
+ deps: [AngularFirestore, 'ProductRepository'],
477
+ },
478
+ ], imports: [[AngularFireModule]] });
479
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
480
+ type: NgModule,
481
+ args: [{
482
+ imports: [AngularFireModule],
483
+ providers: [
484
+ {
485
+ provide: 'BeautyProfileRepository',
486
+ useFactory: (firestore, userRepository) => {
487
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
488
+ },
489
+ deps: [AngularFirestore, 'UserRepository'],
490
+ },
491
+ {
492
+ provide: 'Buy2WinRepository',
493
+ useFactory: (firestore) => {
494
+ return new Buy2WinFirestoreRepository(firestore.firestore);
495
+ },
496
+ deps: [AngularFirestore],
497
+ },
498
+ {
499
+ provide: 'CategoryRepository',
500
+ useFactory: (firestore) => {
501
+ return new CategoryFirestoreRepository(firestore.firestore);
502
+ },
503
+ deps: [AngularFirestore],
504
+ },
505
+ {
506
+ provide: 'CheckoutRepository',
507
+ useFactory: (firestore) => {
508
+ return new CheckoutFirestoreRepository(firestore.firestore);
509
+ },
510
+ deps: [AngularFirestore],
511
+ },
512
+ {
513
+ provide: 'CheckoutSubscriptionRepository',
514
+ useFactory: (firestore) => {
515
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
516
+ },
517
+ deps: [AngularFirestore],
518
+ },
519
+ {
520
+ provide: 'CouponRepository',
521
+ useFactory: (firestore) => {
522
+ return new CouponFirestoreRepository(firestore.firestore);
523
+ },
524
+ deps: [AngularFirestore],
525
+ },
526
+ {
527
+ provide: 'EditionRepository',
528
+ useFactory: (firestore, subscriptionRepository) => {
529
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
530
+ },
531
+ deps: [AngularFirestore, 'SubscriptionRepository'],
532
+ },
533
+ {
534
+ provide: 'HomeRepository',
535
+ useFactory: (firestore) => {
536
+ return new HomeFirestoreRepository(firestore.firestore);
537
+ },
538
+ deps: [AngularFirestore],
539
+ },
540
+ {
541
+ provide: 'LeadRepository',
542
+ useFactory: (firestore) => {
543
+ return new LeadFirestoreRepository(firestore.firestore);
544
+ },
545
+ deps: [AngularFirestore],
546
+ },
547
+ {
548
+ provide: 'LegacyOrderRepository',
549
+ useFactory: (firestore) => {
550
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
551
+ },
552
+ deps: [AngularFirestore],
553
+ },
554
+ {
555
+ provide: 'ShopMenuRepository',
556
+ useFactory: (firestore) => {
557
+ return new ShopMenuFirestoreRepository(firestore.firestore);
558
+ },
559
+ deps: [AngularFirestore],
560
+ },
561
+ {
562
+ provide: 'OrderRepository',
563
+ useFactory: (firestore) => {
564
+ return new OrderFirestoreRepository(firestore.firestore);
565
+ },
566
+ deps: [AngularFirestore],
567
+ },
568
+ {
569
+ provide: 'PaymentRepository',
570
+ useFactory: (firestore) => {
571
+ return new PaymentFirestoreRepository(firestore.firestore);
572
+ },
573
+ deps: [AngularFirestore],
574
+ },
575
+ {
576
+ provide: 'ProductRepository',
577
+ useFactory: (firestore) => {
578
+ return new ProductFirestoreRepository(firestore.firestore);
579
+ },
580
+ deps: [AngularFirestore],
581
+ },
582
+ {
583
+ provide: 'SubscriptionPaymentRepository',
584
+ useFactory: (firestore, subscriptionRepository) => {
585
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
586
+ },
587
+ deps: [AngularFirestore, 'SubscriptionRepository'],
588
+ },
589
+ {
590
+ provide: 'SubscriptionPlanRepository',
591
+ useFactory: (firestore) => {
592
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
593
+ },
594
+ deps: [AngularFirestore],
595
+ },
596
+ {
597
+ provide: 'SubscriptionRepository',
598
+ useFactory: (firestore) => {
599
+ return new SubscriptionFirestoreRepository(firestore.firestore);
600
+ },
601
+ deps: [AngularFirestore],
602
+ },
603
+ {
604
+ provide: 'UserRepository',
605
+ useFactory: (firestore) => {
606
+ return new UserFirestoreRepository(firestore.firestore);
607
+ },
608
+ deps: [AngularFirestore],
609
+ },
610
+ {
611
+ provide: 'UserAddressRepository',
612
+ useFactory: (firestore, userRepository) => {
613
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
614
+ },
615
+ deps: [AngularFirestore, 'UserRepository'],
616
+ },
617
+ {
618
+ provide: 'VariantRepository',
619
+ useFactory: (firestore, productRepository) => {
620
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
621
+ },
622
+ deps: [AngularFirestore, 'ProductRepository'],
623
+ },
624
+ ],
625
+ }]
640
626
  }] });
641
627
 
642
- class AngularConnectModule {
643
- static initializeApp(defaultShop, options, nameOrConfig) {
644
- return {
645
- ngModule: AngularConnectModule,
646
- providers: [
647
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
648
- ...(isNil(options) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options }]),
649
- ...(isNil(options) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
650
- ],
651
- };
652
- }
653
- }
654
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
655
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule] });
656
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [AuthService, CartService, CheckoutService, OrderService], imports: [[AngularFireModule, AngularFirestoreModule]] });
657
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
658
- type: NgModule,
659
- args: [{
660
- imports: [AngularFireModule, AngularFirestoreModule],
661
- providers: [AuthService, CartService, CheckoutService, OrderService],
662
- }]
628
+ class AngularConnectModule {
629
+ static initializeApp(defaultShop, options, nameOrConfig) {
630
+ return {
631
+ ngModule: AngularConnectModule,
632
+ providers: [
633
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
634
+ ...(isNil(options) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options }]),
635
+ ...(isNil(options) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
636
+ ],
637
+ };
638
+ }
639
+ }
640
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
641
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule] });
642
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [AuthService, CartService, CheckoutService, OrderService], imports: [[AngularFireModule, AngularFirestoreModule]] });
643
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
644
+ type: NgModule,
645
+ args: [{
646
+ imports: [AngularFireModule, AngularFirestoreModule],
647
+ providers: [AuthService, CartService, CheckoutService, OrderService],
648
+ }]
663
649
  }] });
664
650
 
665
- /**
666
- * Generated bundle index. Do not edit.
651
+ /**
652
+ * Generated bundle index. Do not edit.
667
653
  */
668
654
 
669
655
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AuthService, CartService, CheckoutService, OrderService };