@infrab4a/connect-angular 4.0.0-beta.28 → 4.0.0-beta.3

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 (48) hide show
  1. package/angular-connect.module.d.ts +0 -1
  2. package/angular-firestore.module.d.ts +1 -2
  3. package/consts/index.d.ts +0 -1
  4. package/esm2020/angular-connect.module.mjs +3 -6
  5. package/esm2020/angular-elastic-search.module.mjs +7 -3
  6. package/esm2020/angular-firestore.module.mjs +137 -226
  7. package/esm2020/angular-hasura-graphql.module.mjs +24 -105
  8. package/esm2020/consts/index.mjs +1 -2
  9. package/esm2020/index.mjs +3 -4
  10. package/esm2020/services/auth.service.mjs +3 -3
  11. package/esm2020/services/cart.service.mjs +23 -161
  12. package/esm2020/services/checkout-subscription.service.mjs +3 -5
  13. package/esm2020/services/checkout.service.mjs +2 -2
  14. package/esm2020/services/coupon.service.mjs +37 -21
  15. package/esm2020/services/index.mjs +3 -4
  16. package/fesm2015/infrab4a-connect-angular.mjs +884 -1307
  17. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
  18. package/fesm2020/infrab4a-connect-angular.mjs +880 -1315
  19. package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
  20. package/index.d.ts +2 -3
  21. package/package.json +3 -2
  22. package/services/cart.service.d.ts +2 -9
  23. package/services/coupon.service.d.ts +3 -2
  24. package/services/index.d.ts +2 -3
  25. package/catalog/catalog.service.d.ts +0 -16
  26. package/catalog/category.service.d.ts +0 -6
  27. package/catalog/enums/index.d.ts +0 -1
  28. package/catalog/enums/product-sorts.enum.d.ts +0 -8
  29. package/catalog/index.d.ts +0 -5
  30. package/catalog/models/category-with-tree.model.d.ts +0 -4
  31. package/catalog/models/index.d.ts +0 -1
  32. package/catalog/types/index.d.ts +0 -1
  33. package/catalog/types/product-sort.type.d.ts +0 -2
  34. package/consts/backend-url.const.d.ts +0 -1
  35. package/esm2020/catalog/catalog.service.mjs +0 -26
  36. package/esm2020/catalog/category.service.mjs +0 -9
  37. package/esm2020/catalog/enums/index.mjs +0 -2
  38. package/esm2020/catalog/enums/product-sorts.enum.mjs +0 -10
  39. package/esm2020/catalog/index.mjs +0 -6
  40. package/esm2020/catalog/models/category-with-tree.model.mjs +0 -10
  41. package/esm2020/catalog/models/index.mjs +0 -2
  42. package/esm2020/catalog/types/index.mjs +0 -2
  43. package/esm2020/catalog/types/product-sort.type.mjs +0 -2
  44. package/esm2020/consts/backend-url.const.mjs +0 -2
  45. package/esm2020/services/shipping.service.mjs +0 -96
  46. package/esm2020/services/types/shipping-methods.type.mjs +0 -2
  47. package/services/shipping.service.d.ts +0 -19
  48. package/services/types/shipping-methods.type.d.ts +0 -12
@@ -1,25 +1,51 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, NgModule, PLATFORM_ID, Injectable, Inject } from '@angular/core';
3
- import * as i3 from '@infrab4a/connect';
4
- import { Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
5
- import * as i1 from '@angular/fire/app';
6
- import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
7
- import * as i1$1 from '@angular/fire/auth';
8
- import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
9
- import { isPlatformBrowser } from '@angular/common';
10
- import * as i1$2 from '@angular/fire/firestore';
11
- import { Firestore, provideFirestore, docSnapshots, doc } from '@angular/fire/firestore';
12
- import { initializeApp as initializeApp$1 } from 'firebase/app';
13
- import { getFirestore } from 'firebase/firestore';
14
- import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
2
+ import { Injectable, Inject, InjectionToken, NgModule, PLATFORM_ID } from '@angular/core';
3
+ import * as i1 from '@angular/fire/auth';
4
+ import { getIdToken, authState, Auth, provideAuth, getAuth } from '@angular/fire/auth';
5
+ import { combineLatest, of, from, throwError, Subject, iif, forkJoin } from 'rxjs';
15
6
  import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
16
- import { __awaiter, __decorate, __metadata } from 'tslib';
7
+ import { __awaiter } from 'tslib';
8
+ import * as i2 from '@infrab4a/connect';
9
+ import { 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';
17
10
  import cookie from 'js-cookie';
18
11
  import { CustomError } from 'ts-custom-error';
19
- import * as i1$3 from '@angular/common/http';
20
- import { Type } from 'class-transformer';
12
+ import * as i1$1 from '@angular/fire/firestore';
13
+ import { docSnapshots, doc, Firestore, provideFirestore, getFirestore } from '@angular/fire/firestore';
14
+ import * as i1$2 from '@angular/fire/app';
15
+ import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
21
16
 
22
- const BACKEND_URL = 'BACKEND_URL';
17
+ class AuthService {
18
+ constructor(angularFireAuth, userRepository) {
19
+ this.angularFireAuth = angularFireAuth;
20
+ this.userRepository = userRepository;
21
+ }
22
+ getAuthstate() {
23
+ const observables = [this.getFireUser(), this.getUser()];
24
+ return combineLatest(observables).pipe(map(([fireUser, user]) => ({
25
+ user,
26
+ isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
27
+ })));
28
+ }
29
+ getUser() {
30
+ return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? this.userRepository.get({ id }) : of(null))), catchError(() => of(null)));
31
+ }
32
+ getTokenId() {
33
+ return from(getIdToken(this.angularFireAuth.currentUser));
34
+ }
35
+ getFireUser() {
36
+ return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
37
+ }
38
+ }
39
+ AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, deps: [{ token: i1.Auth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
40
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
41
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
42
+ type: Injectable
43
+ }], ctorParameters: function () {
44
+ return [{ type: i1.Auth }, { type: undefined, decorators: [{
45
+ type: Inject,
46
+ args: ['UserRepository']
47
+ }] }];
48
+ } });
23
49
 
24
50
  const DEFAULT_SHOP = 'DEFAULT_SHOP';
25
51
 
@@ -30,850 +56,33 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
30
56
 
31
57
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
32
58
 
33
- class AngularFirebaseAuthModule {
34
- static initializeApp(options, nameOrConfig) {
35
- return {
36
- ngModule: AngularFirebaseAuthModule,
37
- providers: [
38
- { provide: FIREBASE_OPTIONS, useValue: options },
39
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
40
- ],
41
- };
59
+ class InvalidCouponError extends CustomError {
60
+ constructor(message) {
61
+ super(message);
42
62
  }
43
63
  }
44
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
45
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1.FirebaseAppModule, i1$1.AuthModule] });
46
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
47
- {
48
- provide: 'Authentication',
49
- useFactory: (authenticationService, userRepository) => {
50
- return new Authentication(authenticationService, userRepository);
51
- },
52
- deps: ['AuthenticationService', 'UserRepository'],
53
- },
54
- {
55
- provide: 'AuthenticationService',
56
- useFactory: (angularFireAuth) => {
57
- return new AuthenticationFirebaseAuthService(angularFireAuth);
58
- },
59
- deps: [Auth],
60
- },
61
- {
62
- provide: 'Register',
63
- useFactory: (registerService, userRepository) => {
64
- return new Register(registerService, userRepository);
65
- },
66
- deps: ['RegisterService', 'UserRepository'],
67
- },
68
- {
69
- provide: 'RegisterService',
70
- useFactory: (angularFireAuth) => {
71
- return new RegisterFirebaseAuthService(angularFireAuth);
72
- },
73
- deps: [Auth],
74
- },
75
- {
76
- provide: 'SignOut',
77
- useFactory: (authenticationService) => {
78
- return new SignOut(authenticationService);
79
- },
80
- deps: ['AuthenticationService'],
81
- },
82
- {
83
- provide: 'RecoveryPassword',
84
- useFactory: (authenticationService) => {
85
- return new RecoveryPassword(authenticationService);
86
- },
87
- deps: ['AuthenticationService'],
88
- },
89
- ], imports: [provideFirebaseApp((injector) => {
90
- const appName = injector.get(FIREBASE_APP_NAME);
91
- return appName
92
- ? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
93
- : initializeApp(injector.get(FIREBASE_OPTIONS));
94
- }),
95
- provideAuth(() => getAuth())] });
96
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
97
- type: NgModule,
98
- args: [{
99
- imports: [
100
- provideFirebaseApp((injector) => {
101
- const appName = injector.get(FIREBASE_APP_NAME);
102
- return appName
103
- ? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
104
- : initializeApp(injector.get(FIREBASE_OPTIONS));
105
- }),
106
- provideAuth(() => getAuth()),
107
- ],
108
- providers: [
109
- {
110
- provide: 'Authentication',
111
- useFactory: (authenticationService, userRepository) => {
112
- return new Authentication(authenticationService, userRepository);
113
- },
114
- deps: ['AuthenticationService', 'UserRepository'],
115
- },
116
- {
117
- provide: 'AuthenticationService',
118
- useFactory: (angularFireAuth) => {
119
- return new AuthenticationFirebaseAuthService(angularFireAuth);
120
- },
121
- deps: [Auth],
122
- },
123
- {
124
- provide: 'Register',
125
- useFactory: (registerService, userRepository) => {
126
- return new Register(registerService, userRepository);
127
- },
128
- deps: ['RegisterService', 'UserRepository'],
129
- },
130
- {
131
- provide: 'RegisterService',
132
- useFactory: (angularFireAuth) => {
133
- return new RegisterFirebaseAuthService(angularFireAuth);
134
- },
135
- deps: [Auth],
136
- },
137
- {
138
- provide: 'SignOut',
139
- useFactory: (authenticationService) => {
140
- return new SignOut(authenticationService);
141
- },
142
- deps: ['AuthenticationService'],
143
- },
144
- {
145
- provide: 'RecoveryPassword',
146
- useFactory: (authenticationService) => {
147
- return new RecoveryPassword(authenticationService);
148
- },
149
- deps: ['AuthenticationService'],
150
- },
151
- ],
152
- }]
153
- }] });
154
64
 
155
- class AngularElasticSeachModule {
156
- static initializeApp(options) {
157
- return {
158
- ngModule: AngularElasticSeachModule,
159
- providers: [{ provide: ES_CONFIG, useValue: options }],
160
- };
65
+ class GroupInvalidCouponError extends CustomError {
66
+ constructor(errors) {
67
+ super('Many coupon errors throw');
68
+ this.errors = errors;
161
69
  }
162
70
  }
163
- AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
164
- AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
165
- AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
166
- {
167
- provide: ProductsIndex,
168
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
169
- deps: [ES_CONFIG],
170
- },
171
- ] });
172
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
173
- type: NgModule,
174
- args: [{
175
- providers: [
176
- {
177
- provide: ProductsIndex,
178
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
179
- deps: [ES_CONFIG],
180
- },
181
- ],
182
- }]
183
- }] });
184
71
 
185
- class AngularFirestoreModule {
186
- static initializeApp(options, nameOrConfig) {
187
- return {
188
- ngModule: AngularFirestoreModule,
189
- providers: [
190
- { provide: FIREBASE_OPTIONS, useValue: options.firebase },
191
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
192
- { provide: ES_CONFIG, useValue: options.elasticSearch },
193
- ],
194
- };
72
+ class CouponService {
73
+ constructor(couponRepository, defaultShop, orderRepository, subscriptionRepository, categoryRepository) {
74
+ this.couponRepository = couponRepository;
75
+ this.defaultShop = defaultShop;
76
+ this.orderRepository = orderRepository;
77
+ this.subscriptionRepository = subscriptionRepository;
78
+ this.categoryRepository = categoryRepository;
79
+ this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
195
80
  }
196
- }
197
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
198
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1.FirebaseAppModule, i1$2.FirestoreModule] });
199
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
200
- {
201
- provide: 'FirestoreOptions',
202
- useFactory: (firestore, platformId) => ({
203
- firestore,
204
- interceptors: {
205
- request: (request) => {
206
- if (isPlatformBrowser(platformId))
207
- return request;
208
- const interval = setInterval(() => { }, 100);
209
- request.interval = interval;
210
- return request;
211
- },
212
- response: (response, request) => {
213
- if (isPlatformBrowser(platformId))
214
- return response;
215
- clearInterval(request.interval);
216
- return response;
217
- },
218
- },
219
- }),
220
- deps: [Firestore, PLATFORM_ID],
221
- },
222
- {
223
- provide: 'BeautyProfileRepository',
224
- useFactory: (config, userRepository) => {
225
- return new UserBeautyProfileFirestoreRepository(config, userRepository);
226
- },
227
- deps: ['FirestoreOptions', 'UserRepository'],
228
- },
229
- {
230
- provide: 'Buy2WinRepository',
231
- useFactory: (options) => {
232
- return new Buy2WinFirestoreRepository(options);
233
- },
234
- deps: ['FirestoreOptions'],
235
- },
236
- {
237
- provide: CategoryFirestoreRepository,
238
- useFactory: (options) => {
239
- return new CategoryFirestoreRepository(options);
240
- },
241
- deps: ['FirestoreOptions'],
242
- },
243
- {
244
- provide: 'CheckoutRepository',
245
- useFactory: (options) => {
246
- return new CheckoutFirestoreRepository(options);
247
- },
248
- deps: ['FirestoreOptions'],
249
- },
250
- {
251
- provide: 'CheckoutSubscriptionRepository',
252
- useFactory: (options) => {
253
- return new CheckoutSubscriptionFirestoreRepository(options);
254
- },
255
- deps: ['FirestoreOptions'],
256
- },
257
- {
258
- provide: 'CouponRepository',
259
- useFactory: (options) => {
260
- return new CouponFirestoreRepository(options);
261
- },
262
- deps: ['FirestoreOptions'],
263
- },
264
- {
265
- provide: 'CampaignHashtagRepository',
266
- useFactory: (options) => {
267
- return new CampaignHashtagFirestoreRepository(options);
268
- },
269
- deps: ['FirestoreOptions'],
270
- },
271
- {
272
- provide: 'CampaignDashboardRepository',
273
- useFactory: (options) => {
274
- return new CampaignDashboardFirestoreRepository(options);
275
- },
276
- deps: ['FirestoreOptions'],
277
- },
278
- {
279
- provide: 'EditionRepository',
280
- useFactory: (options, subscriptionRepository) => {
281
- return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
282
- },
283
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
284
- },
285
- {
286
- provide: 'HomeRepository',
287
- useFactory: (options) => {
288
- return new HomeFirestoreRepository(options);
289
- },
290
- deps: ['FirestoreOptions'],
291
- },
292
- {
293
- provide: 'LeadRepository',
294
- useFactory: (options) => {
295
- return new LeadFirestoreRepository(options);
296
- },
297
- deps: ['FirestoreOptions'],
298
- },
299
- {
300
- provide: 'LegacyOrderRepository',
301
- useFactory: (options) => {
302
- return new LegacyOrderFirestoreRepository(options);
303
- },
304
- deps: ['FirestoreOptions'],
305
- },
306
- {
307
- provide: 'ShopMenuRepository',
308
- useFactory: (options) => {
309
- return new ShopMenuFirestoreRepository(options);
310
- },
311
- deps: ['FirestoreOptions'],
312
- },
313
- {
314
- provide: 'OrderRepository',
315
- useFactory: (options) => {
316
- return new OrderFirestoreRepository(options);
317
- },
318
- deps: ['FirestoreOptions'],
319
- },
320
- {
321
- provide: 'PaymentRepository',
322
- useFactory: (options) => {
323
- return new PaymentFirestoreRepository(options);
324
- },
325
- deps: ['FirestoreOptions'],
326
- },
327
- {
328
- provide: ProductFirestoreRepository,
329
- useFactory: (options) => {
330
- return new ProductFirestoreRepository(options);
331
- },
332
- deps: ['FirestoreOptions'],
333
- },
334
- {
335
- provide: 'ShopSettingsRepository',
336
- useFactory: (options) => {
337
- return new ShopSettingsFirestoreRepository(options);
338
- },
339
- deps: ['FirestoreOptions'],
340
- },
341
- {
342
- provide: 'SubscriptionPaymentRepository',
343
- useFactory: (options, subscriptionRepository) => {
344
- return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
345
- },
346
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
347
- },
348
- {
349
- provide: 'SubscriptionPlanRepository',
350
- useFactory: (options) => {
351
- return new SubscriptionPlanFirestoreRepository(options);
352
- },
353
- deps: ['FirestoreOptions'],
354
- },
355
- {
356
- provide: 'SubscriptionProductRepository',
357
- useFactory: (options) => {
358
- return new SubscriptionProductFirestoreRepository(options);
359
- },
360
- deps: ['FirestoreOptions'],
361
- },
362
- {
363
- provide: 'SubscriptionRepository',
364
- useFactory: (options) => {
365
- return new SubscriptionFirestoreRepository(options);
366
- },
367
- deps: ['FirestoreOptions'],
368
- },
369
- {
370
- provide: 'UserRepository',
371
- useFactory: (options) => {
372
- return new UserFirestoreRepository(options);
373
- },
374
- deps: ['FirestoreOptions'],
375
- },
376
- {
377
- provide: 'UserAddressRepository',
378
- useFactory: (options, userRepository) => {
379
- return new UserAddressFirestoreRepository(options, userRepository);
380
- },
381
- deps: ['FirestoreOptions', 'UserRepository'],
382
- },
383
- {
384
- provide: 'UserPaymentMethodRepository',
385
- useFactory: (options, userRepository) => {
386
- return new UserPaymentMethodFirestoreRepository(options, userRepository);
387
- },
388
- deps: ['FirestoreOptions', 'UserRepository'],
389
- },
390
- {
391
- provide: ProductVariantFirestoreRepository,
392
- useFactory: (options, productRepository) => {
393
- return new ProductVariantFirestoreRepository(options, productRepository);
394
- },
395
- deps: ['FirestoreOptions', ProductFirestoreRepository],
396
- },
397
- ], imports: [AngularElasticSeachModule,
398
- provideFirebaseApp((injector) => {
399
- const appName = injector.get(FIREBASE_APP_NAME);
400
- return appName
401
- ? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
402
- : initializeApp$1(injector.get(FIREBASE_OPTIONS));
403
- }),
404
- provideFirestore(() => getFirestore())] });
405
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, decorators: [{
406
- type: NgModule,
407
- args: [{
408
- imports: [
409
- AngularElasticSeachModule,
410
- provideFirebaseApp((injector) => {
411
- const appName = injector.get(FIREBASE_APP_NAME);
412
- return appName
413
- ? initializeApp$1(injector.get(FIREBASE_OPTIONS), appName)
414
- : initializeApp$1(injector.get(FIREBASE_OPTIONS));
415
- }),
416
- provideFirestore(() => getFirestore()),
417
- ],
418
- providers: [
419
- {
420
- provide: 'FirestoreOptions',
421
- useFactory: (firestore, platformId) => ({
422
- firestore,
423
- interceptors: {
424
- request: (request) => {
425
- if (isPlatformBrowser(platformId))
426
- return request;
427
- const interval = setInterval(() => { }, 100);
428
- request.interval = interval;
429
- return request;
430
- },
431
- response: (response, request) => {
432
- if (isPlatformBrowser(platformId))
433
- return response;
434
- clearInterval(request.interval);
435
- return response;
436
- },
437
- },
438
- }),
439
- deps: [Firestore, PLATFORM_ID],
440
- },
441
- {
442
- provide: 'BeautyProfileRepository',
443
- useFactory: (config, userRepository) => {
444
- return new UserBeautyProfileFirestoreRepository(config, userRepository);
445
- },
446
- deps: ['FirestoreOptions', 'UserRepository'],
447
- },
448
- {
449
- provide: 'Buy2WinRepository',
450
- useFactory: (options) => {
451
- return new Buy2WinFirestoreRepository(options);
452
- },
453
- deps: ['FirestoreOptions'],
454
- },
455
- {
456
- provide: CategoryFirestoreRepository,
457
- useFactory: (options) => {
458
- return new CategoryFirestoreRepository(options);
459
- },
460
- deps: ['FirestoreOptions'],
461
- },
462
- {
463
- provide: 'CheckoutRepository',
464
- useFactory: (options) => {
465
- return new CheckoutFirestoreRepository(options);
466
- },
467
- deps: ['FirestoreOptions'],
468
- },
469
- {
470
- provide: 'CheckoutSubscriptionRepository',
471
- useFactory: (options) => {
472
- return new CheckoutSubscriptionFirestoreRepository(options);
473
- },
474
- deps: ['FirestoreOptions'],
475
- },
476
- {
477
- provide: 'CouponRepository',
478
- useFactory: (options) => {
479
- return new CouponFirestoreRepository(options);
480
- },
481
- deps: ['FirestoreOptions'],
482
- },
483
- {
484
- provide: 'CampaignHashtagRepository',
485
- useFactory: (options) => {
486
- return new CampaignHashtagFirestoreRepository(options);
487
- },
488
- deps: ['FirestoreOptions'],
489
- },
490
- {
491
- provide: 'CampaignDashboardRepository',
492
- useFactory: (options) => {
493
- return new CampaignDashboardFirestoreRepository(options);
494
- },
495
- deps: ['FirestoreOptions'],
496
- },
497
- {
498
- provide: 'EditionRepository',
499
- useFactory: (options, subscriptionRepository) => {
500
- return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
501
- },
502
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
503
- },
504
- {
505
- provide: 'HomeRepository',
506
- useFactory: (options) => {
507
- return new HomeFirestoreRepository(options);
508
- },
509
- deps: ['FirestoreOptions'],
510
- },
511
- {
512
- provide: 'LeadRepository',
513
- useFactory: (options) => {
514
- return new LeadFirestoreRepository(options);
515
- },
516
- deps: ['FirestoreOptions'],
517
- },
518
- {
519
- provide: 'LegacyOrderRepository',
520
- useFactory: (options) => {
521
- return new LegacyOrderFirestoreRepository(options);
522
- },
523
- deps: ['FirestoreOptions'],
524
- },
525
- {
526
- provide: 'ShopMenuRepository',
527
- useFactory: (options) => {
528
- return new ShopMenuFirestoreRepository(options);
529
- },
530
- deps: ['FirestoreOptions'],
531
- },
532
- {
533
- provide: 'OrderRepository',
534
- useFactory: (options) => {
535
- return new OrderFirestoreRepository(options);
536
- },
537
- deps: ['FirestoreOptions'],
538
- },
539
- {
540
- provide: 'PaymentRepository',
541
- useFactory: (options) => {
542
- return new PaymentFirestoreRepository(options);
543
- },
544
- deps: ['FirestoreOptions'],
545
- },
546
- {
547
- provide: ProductFirestoreRepository,
548
- useFactory: (options) => {
549
- return new ProductFirestoreRepository(options);
550
- },
551
- deps: ['FirestoreOptions'],
552
- },
553
- {
554
- provide: 'ShopSettingsRepository',
555
- useFactory: (options) => {
556
- return new ShopSettingsFirestoreRepository(options);
557
- },
558
- deps: ['FirestoreOptions'],
559
- },
560
- {
561
- provide: 'SubscriptionPaymentRepository',
562
- useFactory: (options, subscriptionRepository) => {
563
- return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
564
- },
565
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
566
- },
567
- {
568
- provide: 'SubscriptionPlanRepository',
569
- useFactory: (options) => {
570
- return new SubscriptionPlanFirestoreRepository(options);
571
- },
572
- deps: ['FirestoreOptions'],
573
- },
574
- {
575
- provide: 'SubscriptionProductRepository',
576
- useFactory: (options) => {
577
- return new SubscriptionProductFirestoreRepository(options);
578
- },
579
- deps: ['FirestoreOptions'],
580
- },
581
- {
582
- provide: 'SubscriptionRepository',
583
- useFactory: (options) => {
584
- return new SubscriptionFirestoreRepository(options);
585
- },
586
- deps: ['FirestoreOptions'],
587
- },
588
- {
589
- provide: 'UserRepository',
590
- useFactory: (options) => {
591
- return new UserFirestoreRepository(options);
592
- },
593
- deps: ['FirestoreOptions'],
594
- },
595
- {
596
- provide: 'UserAddressRepository',
597
- useFactory: (options, userRepository) => {
598
- return new UserAddressFirestoreRepository(options, userRepository);
599
- },
600
- deps: ['FirestoreOptions', 'UserRepository'],
601
- },
602
- {
603
- provide: 'UserPaymentMethodRepository',
604
- useFactory: (options, userRepository) => {
605
- return new UserPaymentMethodFirestoreRepository(options, userRepository);
606
- },
607
- deps: ['FirestoreOptions', 'UserRepository'],
608
- },
609
- {
610
- provide: ProductVariantFirestoreRepository,
611
- useFactory: (options, productRepository) => {
612
- return new ProductVariantFirestoreRepository(options, productRepository);
613
- },
614
- deps: ['FirestoreOptions', ProductFirestoreRepository],
615
- },
616
- ],
617
- }]
618
- }] });
619
-
620
- class AngularHasuraGraphQLModule {
621
- static initializeApp(options) {
622
- return {
623
- ngModule: AngularHasuraGraphQLModule,
624
- providers: [{ provide: HASURA_OPTIONS, useValue: options }],
625
- };
626
- }
627
- }
628
- AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
629
- AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule });
630
- AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
631
- {
632
- provide: 'HasuraConfig',
633
- useFactory: (options, platformId) => ({
634
- endpoint: options.endpoint,
635
- authOptions: options.credentials,
636
- interceptors: {
637
- request: (request) => {
638
- if (isPlatformBrowser(platformId))
639
- return request;
640
- const interval = setInterval(() => { }, 100);
641
- request.interval = interval;
642
- return request;
643
- },
644
- response: (response, request) => {
645
- if (isPlatformBrowser(platformId))
646
- return response;
647
- clearInterval(request.interval);
648
- return response;
649
- },
650
- },
651
- }),
652
- deps: [HASURA_OPTIONS, PLATFORM_ID],
653
- },
654
- {
655
- provide: 'CategoryRepository',
656
- useExisting: CategoryHasuraGraphQLRepository,
657
- },
658
- {
659
- provide: CategoryHasuraGraphQLRepository,
660
- useFactory: (options, productRepository, categoryFilterRepository) => {
661
- return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
662
- },
663
- deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
664
- },
665
- {
666
- provide: 'ProductRepository',
667
- useExisting: ProductHasuraGraphQLRepository,
668
- },
669
- {
670
- provide: ProductHasuraGraphQLRepository,
671
- useFactory: (hasuraConfig) => {
672
- return new ProductHasuraGraphQLRepository(hasuraConfig);
673
- },
674
- deps: ['HasuraConfig'],
675
- },
676
- {
677
- provide: 'VariantRepository',
678
- useExisting: VariantHasuraGraphQLRepository,
679
- },
680
- {
681
- provide: VariantHasuraGraphQLRepository,
682
- useFactory: (hasuraConfig) => {
683
- return new VariantHasuraGraphQLRepository(hasuraConfig);
684
- },
685
- deps: ['HasuraConfig'],
686
- },
687
- {
688
- provide: 'CategoryFilterRepository',
689
- useExisting: CategoryFilterHasuraGraphQLRepository,
690
- },
691
- {
692
- provide: CategoryFilterHasuraGraphQLRepository,
693
- useFactory: (options) => {
694
- return new CategoryFilterHasuraGraphQLRepository(options);
695
- },
696
- deps: ['HasuraConfig'],
697
- },
698
- {
699
- provide: 'FilterOptionRepository',
700
- useExisting: FilterOptionHasuraGraphQLRepository,
701
- },
702
- {
703
- provide: FilterOptionHasuraGraphQLRepository,
704
- useFactory: (options) => {
705
- return new FilterOptionHasuraGraphQLRepository(options);
706
- },
707
- deps: ['HasuraConfig'],
708
- },
709
- {
710
- provide: 'FilterRepository',
711
- useExisting: FilterHasuraGraphQLRepository,
712
- },
713
- {
714
- provide: FilterHasuraGraphQLRepository,
715
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
716
- return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
717
- },
718
- deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
719
- },
720
- ] });
721
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
722
- type: NgModule,
723
- args: [{
724
- providers: [
725
- {
726
- provide: 'HasuraConfig',
727
- useFactory: (options, platformId) => ({
728
- endpoint: options.endpoint,
729
- authOptions: options.credentials,
730
- interceptors: {
731
- request: (request) => {
732
- if (isPlatformBrowser(platformId))
733
- return request;
734
- const interval = setInterval(() => { }, 100);
735
- request.interval = interval;
736
- return request;
737
- },
738
- response: (response, request) => {
739
- if (isPlatformBrowser(platformId))
740
- return response;
741
- clearInterval(request.interval);
742
- return response;
743
- },
744
- },
745
- }),
746
- deps: [HASURA_OPTIONS, PLATFORM_ID],
747
- },
748
- {
749
- provide: 'CategoryRepository',
750
- useExisting: CategoryHasuraGraphQLRepository,
751
- },
752
- {
753
- provide: CategoryHasuraGraphQLRepository,
754
- useFactory: (options, productRepository, categoryFilterRepository) => {
755
- return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
756
- },
757
- deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
758
- },
759
- {
760
- provide: 'ProductRepository',
761
- useExisting: ProductHasuraGraphQLRepository,
762
- },
763
- {
764
- provide: ProductHasuraGraphQLRepository,
765
- useFactory: (hasuraConfig) => {
766
- return new ProductHasuraGraphQLRepository(hasuraConfig);
767
- },
768
- deps: ['HasuraConfig'],
769
- },
770
- {
771
- provide: 'VariantRepository',
772
- useExisting: VariantHasuraGraphQLRepository,
773
- },
774
- {
775
- provide: VariantHasuraGraphQLRepository,
776
- useFactory: (hasuraConfig) => {
777
- return new VariantHasuraGraphQLRepository(hasuraConfig);
778
- },
779
- deps: ['HasuraConfig'],
780
- },
781
- {
782
- provide: 'CategoryFilterRepository',
783
- useExisting: CategoryFilterHasuraGraphQLRepository,
784
- },
785
- {
786
- provide: CategoryFilterHasuraGraphQLRepository,
787
- useFactory: (options) => {
788
- return new CategoryFilterHasuraGraphQLRepository(options);
789
- },
790
- deps: ['HasuraConfig'],
791
- },
792
- {
793
- provide: 'FilterOptionRepository',
794
- useExisting: FilterOptionHasuraGraphQLRepository,
795
- },
796
- {
797
- provide: FilterOptionHasuraGraphQLRepository,
798
- useFactory: (options) => {
799
- return new FilterOptionHasuraGraphQLRepository(options);
800
- },
801
- deps: ['HasuraConfig'],
802
- },
803
- {
804
- provide: 'FilterRepository',
805
- useExisting: FilterHasuraGraphQLRepository,
806
- },
807
- {
808
- provide: FilterHasuraGraphQLRepository,
809
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
810
- return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
811
- },
812
- deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
813
- },
814
- ],
815
- }]
816
- }] });
817
-
818
- class AuthService {
819
- constructor(angularFireAuth, userRepository) {
820
- this.angularFireAuth = angularFireAuth;
821
- this.userRepository = userRepository;
822
- }
823
- getAuthstate() {
824
- const observables = [this.getFireUser(), this.getUser()];
825
- return combineLatest(observables).pipe(map(([fireUser, user]) => ({
826
- user,
827
- isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
828
- })));
829
- }
830
- getUser() {
831
- return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
832
- }
833
- getTokenId() {
834
- return from(getIdToken(this.angularFireAuth.currentUser));
835
- }
836
- getFireUser() {
837
- return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
838
- }
839
- }
840
- AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, deps: [{ token: i1$1.Auth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
841
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
842
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
843
- type: Injectable
844
- }], ctorParameters: function () {
845
- return [{ type: i1$1.Auth }, { type: undefined, decorators: [{
846
- type: Inject,
847
- args: ['UserRepository']
848
- }] }];
849
- } });
850
-
851
- class InvalidCouponError extends CustomError {
852
- constructor(message) {
853
- super(message);
854
- }
855
- }
856
-
857
- class GroupInvalidCouponError extends CustomError {
858
- constructor(errors) {
859
- super('Many coupon errors throw');
860
- this.errors = errors;
861
- }
862
- }
863
-
864
- class CouponService {
865
- constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
866
- this.couponRepository = couponRepository;
867
- this.defaultShop = defaultShop;
868
- this.orderRepository = orderRepository;
869
- this.categoryRepository = categoryRepository;
870
- this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
871
- }
872
- checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
873
- return from(this.couponRepository.find({
874
- filters: {
875
- nickname: { operator: Where.EQUALS, value: nickname },
876
- active: { operator: Where.EQUALS, value: true },
81
+ checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
82
+ return from(this.couponRepository.find({
83
+ filters: {
84
+ nickname: { operator: Where.EQUALS, value: nickname },
85
+ active: { operator: Where.EQUALS, value: true },
877
86
  },
878
87
  })).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail, checkout)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
879
88
  }
@@ -906,7 +115,7 @@ class CouponService {
906
115
  const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
907
116
  // Se não tem valor mínimo atingido, retorna erro
908
117
  if (!hasMinSubTotal)
909
- return throwError(`Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`);
118
+ return throwError('Valor mínimo não atingido');
910
119
  return of(coupon);
911
120
  }
912
121
  isValidCoupon(coupon, userEmail) {
@@ -921,7 +130,10 @@ class CouponService {
921
130
  checkCouponUseAndLimit(coupon, userEmail, checkout) {
922
131
  return __awaiter(this, void 0, void 0, function* () {
923
132
  const orders = yield this.orderRepository.find({
924
- filters: Object.assign({ coupon: { id: coupon.id }, payment: { status: 'paid' } }, (coupon.influencerEmail ? { user: { email: userEmail } } : {})),
133
+ filters: {
134
+ coupon: { id: coupon.id },
135
+ payment: { status: 'paid' },
136
+ },
925
137
  });
926
138
  // orders que usuario ja fez com o cupom
927
139
  const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
@@ -931,7 +143,7 @@ class CouponService {
931
143
  // Verifica o limite de uso geral por usuario
932
144
  if (coupon.useLimit && orders.data.length >= coupon.useLimit)
933
145
  throw new InvalidCouponError('Limite de uso atingido.');
934
- const validUser = this.userValidationAndSubscriptionStatus(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
146
+ const validUser = yield this.userValidationAndSubscriptionStatus(coupon, userEmail);
935
147
  if (!validUser)
936
148
  throw new InvalidCouponError('Usuário não elegível.');
937
149
  const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
@@ -1025,26 +237,41 @@ class CouponService {
1025
237
  return hasCategories.length ? true : false;
1026
238
  });
1027
239
  }
1028
- userValidationAndSubscriptionStatus(coupon, user) {
1029
- if (coupon.exclusivityType === Exclusivities.ALL_USERS)
1030
- return true;
1031
- if (!user)
240
+ userValidationAndSubscriptionStatus(coupon, userEmail) {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ // Verifica se o email do usuário é coorporativo
243
+ if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
244
+ throw new InvalidCouponError('Você não é colaborador.');
245
+ // Verifica se o email do usuário é associado ao cupom de uso por usuario
246
+ if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
247
+ throw new InvalidCouponError('Cupom não é válido para este usuário.');
248
+ const couponRuleSubscription = coupon.exclusivityType === Exclusivities.ACTIVE_SUBSCRIBER ||
249
+ coupon.exclusivityType === Exclusivities.INACTIVE_SUBSCRIBER ||
250
+ coupon.exclusivityType === Exclusivities.NON_SUBSCRIBER;
251
+ if (couponRuleSubscription && userEmail) {
252
+ const sub = yield this.subscriptionRepository
253
+ .find({
254
+ filters: {
255
+ user: {
256
+ email: { operator: Where.EQUALS, value: userEmail },
257
+ },
258
+ },
259
+ })
260
+ .then((sub) => sub.data);
261
+ const activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter((s) => s.status === Status.ACTIVE);
262
+ switch (coupon.exclusivityType) {
263
+ case Exclusivities.ACTIVE_SUBSCRIBER:
264
+ return activeSubs.length > 0;
265
+ case Exclusivities.INACTIVE_SUBSCRIBER:
266
+ return activeSubs.length === 0;
267
+ case Exclusivities.NON_SUBSCRIBER:
268
+ return sub.length === 0;
269
+ default:
270
+ return false;
271
+ }
272
+ }
1032
273
  return true;
1033
- // Verifica se o email do usuário é coorporativo
1034
- if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
1035
- throw new InvalidCouponError('Você não é colaborador.');
1036
- // Verifica se o email do usuário é associado ao cupom de uso por usuario
1037
- if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
1038
- throw new InvalidCouponError('Cupom não é válido para este usuário.');
1039
- switch (coupon.exclusivityType) {
1040
- case Exclusivities.ACTIVE_SUBSCRIBER:
1041
- return user.isSubscriber ? true : false;
1042
- case Exclusivities.INACTIVE_SUBSCRIBER:
1043
- return user.isSubscriber ? false : true;
1044
- case Exclusivities.NON_SUBSCRIBER:
1045
- return user.isSubscriber ? false : true;
1046
- }
1047
- return true;
274
+ });
1048
275
  }
1049
276
  getCouponCategoriesId(coupon) {
1050
277
  return __awaiter(this, void 0, void 0, function* () {
@@ -1059,7 +286,7 @@ class CouponService {
1059
286
  });
1060
287
  }
1061
288
  }
1062
- CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
289
+ CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'SubscriptionRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1063
290
  CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
1064
291
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
1065
292
  type: Injectable,
@@ -1070,12 +297,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1070
297
  return [{ type: undefined, decorators: [{
1071
298
  type: Inject,
1072
299
  args: ['CouponRepository']
1073
- }] }, { type: i3.Shops, decorators: [{
300
+ }] }, { type: i2.Shops, decorators: [{
1074
301
  type: Inject,
1075
302
  args: [DEFAULT_SHOP]
1076
303
  }] }, { type: undefined, decorators: [{
1077
304
  type: Inject,
1078
305
  args: ['OrderRepository']
306
+ }] }, { type: undefined, decorators: [{
307
+ type: Inject,
308
+ args: ['SubscriptionRepository']
1079
309
  }] }, { type: undefined, decorators: [{
1080
310
  type: Inject,
1081
311
  args: ['CategoryRepository']
@@ -1142,26 +372,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1142
372
  }] }, { type: undefined, decorators: [{
1143
373
  type: Inject,
1144
374
  args: ['UserRepository']
1145
- }] }, { type: i3.Shops, decorators: [{
375
+ }] }, { type: i2.Shops, decorators: [{
1146
376
  type: Inject,
1147
377
  args: [DEFAULT_SHOP]
1148
378
  }] }];
1149
379
  } });
1150
380
 
1151
381
  class CartService {
1152
- constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
382
+ constructor(authService, checkoutService, defaultShop, productRepository) {
1153
383
  this.authService = authService;
1154
384
  this.checkoutService = checkoutService;
1155
385
  this.defaultShop = defaultShop;
1156
386
  this.productRepository = productRepository;
1157
- this.categoryRepository = categoryRepository;
1158
- this.variantRepository = variantRepository;
1159
- this.buy2WinRepository = buy2WinRepository;
1160
387
  this.cartSubject = new Subject();
1161
388
  this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
1162
389
  var _a;
1163
390
  const items = [];
1164
- const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
391
+ const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
1165
392
  if (index > -1) {
1166
393
  checkoutLoaded.lineItems[index].quantity += quantity;
1167
394
  checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
@@ -1172,25 +399,28 @@ class CartService {
1172
399
  .updateCheckoutLineItems(checkoutLoaded)
1173
400
  .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
1174
401
  }));
1175
- this.generateCartObject = (items) => (items === null || items === void 0 ? void 0 : items.reduce((cart, item) => {
1176
- var _a;
1177
- return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
1178
- }, {})) || {};
402
+ this.generateCartObject = (items) => {
403
+ const cart = {};
404
+ items === null || items === void 0 ? void 0 : items.forEach((item) => {
405
+ var _a;
406
+ 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) })));
407
+ });
408
+ return cart;
409
+ };
1179
410
  this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
1180
411
  var _a, _b, _c, _d, _e, _f, _g;
1181
- const product = yield this.getProductData(item.id);
1182
- 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.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
412
+ const product = yield this.productRepository.get({ id: item.id });
413
+ 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;
1183
414
  if (this.checkMaxStock(item, quantity || 0))
1184
415
  throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
1185
416
  const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
1186
- const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
417
+ const { id, name, EAN, brand, slug, stock, price, weight, categories, sku, type } = item;
1187
418
  const isGift = item.isGift || null;
1188
419
  const pricePaid = this.getProductPrice({
1189
420
  product: item,
1190
421
  shop: checkout.shop || this.defaultShop,
1191
422
  isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
1192
423
  });
1193
- RoundProductPricesHelper.roundProductPrices(item);
1194
424
  return {
1195
425
  checkout,
1196
426
  lineItem: LineItem.toInstance({
@@ -1201,7 +431,7 @@ class CartService {
1201
431
  slug: slug !== null && slug !== void 0 ? slug : product.slug,
1202
432
  sku: sku !== null && sku !== void 0 ? sku : product.sku,
1203
433
  stock,
1204
- price: this.roundPrice(price),
434
+ price,
1205
435
  image,
1206
436
  weight: weight !== null && weight !== void 0 ? weight : product.weight,
1207
437
  quantity: (item.quantity || 0) + (quantity || 0),
@@ -1217,9 +447,7 @@ class CartService {
1217
447
  const info = product.price;
1218
448
  if (product.isGift)
1219
449
  return 0;
1220
- return isSubscriber && info.subscriberPrice > 0
1221
- ? Number(info.subscriberPrice.toFixed(2))
1222
- : Number(info.price.toFixed(2));
450
+ return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
1223
451
  };
1224
452
  this.checkMaxStock = (item, quantity) => {
1225
453
  var _a;
@@ -1234,7 +462,7 @@ class CartService {
1234
462
  decreaseItem(item) {
1235
463
  return this.checkoutService.getCheckout().pipe(map((checkout) => {
1236
464
  var _a;
1237
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
465
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
1238
466
  if (!isNil(checkoutItem))
1239
467
  checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
1240
468
  return checkout;
@@ -1252,7 +480,7 @@ class CartService {
1252
480
  }
1253
481
  removeItem(item) {
1254
482
  return this.checkoutService.getCheckout().pipe(map((checkout) => {
1255
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
483
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
1256
484
  if (index >= 0)
1257
485
  checkout.lineItems.splice(index, 1);
1258
486
  return checkout;
@@ -1261,12 +489,8 @@ class CartService {
1261
489
  updateUserCart(user) {
1262
490
  return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => __awaiter(this, void 0, void 0, function* () {
1263
491
  var _a, _b;
1264
- return this.checkoutService
1265
- .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
1266
- ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; })))
1267
- : [] })))
1268
- .toPromise();
1269
- })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
492
+ return this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length) ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; }))) : [] }))).toPromise();
493
+ })), map(checkout => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1270
494
  }
1271
495
  clearCart() {
1272
496
  return this.checkoutService.getCheckout().pipe(map((checkout) => {
@@ -1274,146 +498,21 @@ class CartService {
1274
498
  return checkout;
1275
499
  }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1276
500
  }
1277
- buildCartFromCheckout(checkoutData) {
1278
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1279
- }
1280
- roundPrice(productPrice) {
1281
- const { price, fullPrice, subscriberPrice } = productPrice;
1282
- return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
1283
- }
1284
- getProductData(productId) {
1285
- return __awaiter(this, void 0, void 0, function* () {
1286
- let product;
1287
- let variant;
1288
- try {
1289
- product = yield this.productRepository.get({ id: productId });
1290
- }
1291
- catch (error) {
1292
- if (!(error instanceof NotFoundError))
1293
- throw error;
1294
- const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
1295
- variant = variants.shift();
1296
- if (!variant)
1297
- throw error;
1298
- product = yield this.productRepository.get({ id: variant.productId });
1299
- }
1300
- return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
1301
- });
1302
- }
1303
- getGifts() {
1304
- return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
1305
- const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
1306
- if (!notGiftItems.length)
1307
- return Object.assign(Object.assign({}, checkout), { lineItems: [] });
1308
- const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1309
- const campaigns = yield this.buy2WinRepository
1310
- .find({
1311
- filters: {
1312
- active: { operator: Where.EQUALS, value: true },
1313
- shop: { operator: Where.EQUALS, value: this.defaultShop },
1314
- },
1315
- })
1316
- .then((data) => data.data);
1317
- if (!campaigns.length)
1318
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1319
- const elegibleCampaigns = [];
1320
- for (const campaign of campaigns) {
1321
- const today = new Date();
1322
- if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
1323
- continue;
1324
- if (campaign.activeCategory) {
1325
- const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
1326
- const categoriesCampaingFullTree = [];
1327
- for (const id of categoriesCampaing) {
1328
- const children = yield this.categoryRepository.getChildren(parseInt(id));
1329
- categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
1330
- }
1331
- const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
1332
- const filterProductsCategories = checkout.lineItems.filter((l) => {
1333
- var _a;
1334
- if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
1335
- return true;
1336
- return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
1337
- });
1338
- if (filterProductsCategories.length) {
1339
- const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1340
- if (cartTotalCategories >= campaign.cartValueMin)
1341
- elegibleCampaigns.push(campaign);
1342
- }
1343
- }
1344
- else {
1345
- if (campaign.cartValue && campaign.cartValue > 0) {
1346
- if (campaign.cartValue <= cartTotal)
1347
- elegibleCampaigns.push(campaign);
1348
- }
1349
- }
1350
- }
1351
- if (!elegibleCampaigns.length)
1352
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1353
- const campaingnProducts = [];
1354
- for (const campaign of elegibleCampaigns) {
1355
- let elegibleProducts = [];
1356
- for (const product of campaign.products) {
1357
- const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
1358
- if (!productData.length)
1359
- continue;
1360
- const gift = productData.shift();
1361
- if (gift.stock.quantity < 1)
1362
- continue;
1363
- elegibleProducts.push(gift);
1364
- }
1365
- campaingnProducts.push(elegibleProducts);
1366
- }
1367
- if (!campaingnProducts.length)
1368
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1369
- const gifts = this.giftToLineItems([].concat(...campaingnProducts));
1370
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
1371
- })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1372
- }
1373
- giftToLineItems(items) {
1374
- return items.map((item) => {
1375
- var _a;
1376
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1377
- const image = ((_a = item === null || item === void 0 ? void 0 : item.miniatures) === null || _a === void 0 ? void 0 : _a.length) ? item.miniatures[0] : item.images[0];
1378
- return LineItem.toInstance({
1379
- brand,
1380
- categories,
1381
- id: id.toString(),
1382
- name,
1383
- price,
1384
- sku,
1385
- slug,
1386
- stock,
1387
- weight,
1388
- EAN,
1389
- image,
1390
- pricePaid: 0,
1391
- quantity: 1,
1392
- isGift: true,
1393
- });
1394
- });
1395
- }
501
+ buildCartFromCheckout(checkoutData) {
502
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
503
+ }
1396
504
  }
1397
- CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
505
+ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1398
506
  CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1399
507
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1400
508
  type: Injectable
1401
509
  }], ctorParameters: function () {
1402
- return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
510
+ return [{ type: AuthService }, { type: CheckoutService }, { type: i2.Shops, decorators: [{
1403
511
  type: Inject,
1404
512
  args: [DEFAULT_SHOP]
1405
513
  }] }, { type: undefined, decorators: [{
1406
514
  type: Inject,
1407
515
  args: ['ProductRepository']
1408
- }] }, { type: undefined, decorators: [{
1409
- type: Inject,
1410
- args: ['CategoryRepository']
1411
- }] }, { type: undefined, decorators: [{
1412
- type: Inject,
1413
- args: ['VariantRepository']
1414
- }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
1415
- type: Inject,
1416
- args: ['Buy2WinRepository']
1417
516
  }] }];
1418
517
  } });
1419
518
 
@@ -1441,9 +540,7 @@ class CheckoutSubscriptionService {
1441
540
  return of();
1442
541
  }
1443
542
  checkCoupon(nickname, userEmail) {
1444
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
1445
- .checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
1446
- .pipe()));
543
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, null, true).pipe()));
1447
544
  }
1448
545
  calcDiscountSubscription(coupon) {
1449
546
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
@@ -1463,229 +560,764 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1463
560
  }] }, { type: CouponService }];
1464
561
  } });
1465
562
 
1466
- class HomeShopService {
1467
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
1468
- this.categoryRepository = categoryRepository;
1469
- this.homeRepository = homeRepository;
1470
- this.productRepository = productRepository;
1471
- this.defaultShop = defaultShop;
1472
- this.buildCategoryGroupWithRequiredData = (group) => {
1473
- var _a, _b;
1474
- return ({
1475
- category: Category.toInstance(pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
1476
- products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map((product) => Product.toInstance(pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
1477
- 'id',
1478
- 'price',
1479
- 'reviews',
1480
- 'hasVariants',
1481
- 'slug',
1482
- 'sku',
1483
- 'stock',
1484
- 'costPrice',
1485
- 'images',
1486
- 'miniatures',
1487
- 'name',
1488
- 'weight',
1489
- 'rate',
1490
- 'type',
1491
- ])))) || [],
1492
- });
1493
- };
1494
- }
1495
- get homeId() {
1496
- if (this.defaultShop === Shops.GLAMSHOP)
1497
- return 'glamshop';
1498
- if (this.defaultShop === Shops.MENSMARKET)
1499
- return 'mens_market';
1500
- return null;
1501
- }
1502
- getHomeData() {
1503
- 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
1504
- ? of(home)
1505
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
1506
- discoverProducts,
1507
- featuredProducts,
1508
- verticalProducts,
1509
- })), concatMap((data) => this.saveHomeData(data)))));
1510
- }
1511
- getBanners(type) {
1512
- return this.getHomeConfiguration().pipe(map((home) => {
1513
- if (type === 'brand')
1514
- return home.brandsCarousel;
1515
- if (type === 'buyToWin')
1516
- return [home.buyToWinBanner];
1517
- if (type === 'block')
1518
- return home.blockBanners;
1519
- if (type === 'blog')
1520
- return [home.blogBanner];
1521
- return [];
1522
- }));
1523
- }
1524
- getMinValueForFreeShipping() {
1525
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
1526
- }
1527
- getDiscoverProducts() {
1528
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1529
- }
1530
- getFeaturedProducts() {
1531
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1532
- }
1533
- getVerticalProducts() {
1534
- 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({
1535
- filters: { categories: { operator: Where.IN, value: [category.id] } },
1536
- limits: { limit: 12 },
1537
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
1538
- }
1539
- getHomeConfiguration() {
1540
- return of(this.homeConfiguration).pipe(concatMap((home) => home
1541
- ? of(home)
1542
- : !this.homeId
1543
- ? throwError(new RequiredArgumentError(['homeId']))
1544
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
1545
- }
1546
- saveHomeData(homeData) {
1547
- const data = {
1548
- createdAt: new Date(),
1549
- expiresAt: add(new Date(), { hours: 1 }),
1550
- data: homeData,
563
+ class OrderService {
564
+ constructor(angularFirestore, orderRepository) {
565
+ this.angularFirestore = angularFirestore;
566
+ this.orderRepository = orderRepository;
567
+ this.orderSubject = new Subject();
568
+ }
569
+ getOrder(id) {
570
+ docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
571
+ .pipe(map((doc) => Order.toInstance(doc.data())))
572
+ .subscribe((doc) => this.orderSubject.next(doc));
573
+ return this.orderSubject;
574
+ }
575
+ }
576
+ OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, deps: [{ token: i1$1.Firestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
577
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
578
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
579
+ type: Injectable
580
+ }], ctorParameters: function () {
581
+ return [{ type: i1$1.Firestore }, { type: i2.OrderFirestoreRepository, decorators: [{
582
+ type: Inject,
583
+ args: ['OrderRepository']
584
+ }] }];
585
+ } });
586
+
587
+ class HomeShopService {
588
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
589
+ this.categoryRepository = categoryRepository;
590
+ this.homeRepository = homeRepository;
591
+ this.productRepository = productRepository;
592
+ this.defaultShop = defaultShop;
593
+ this.buildCategoryGroupWithRequiredData = (group) => {
594
+ var _a, _b;
595
+ return ({
596
+ category: Category.toInstance(pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
597
+ products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map((product) => Product.toInstance(pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
598
+ 'id',
599
+ 'price',
600
+ 'reviews',
601
+ 'hasVariants',
602
+ 'slug',
603
+ 'sku',
604
+ 'stock',
605
+ 'costPrice',
606
+ 'images',
607
+ 'miniatures',
608
+ 'name',
609
+ 'weight',
610
+ 'rate',
611
+ 'type',
612
+ ])))) || [],
613
+ });
614
+ };
615
+ }
616
+ get homeId() {
617
+ if (this.defaultShop === Shops.GLAMSHOP)
618
+ return 'glamshop';
619
+ if (this.defaultShop === Shops.MENSMARKET)
620
+ return 'mens_market';
621
+ return null;
622
+ }
623
+ getHomeData() {
624
+ 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
625
+ ? of(home)
626
+ : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
627
+ discoverProducts,
628
+ featuredProducts,
629
+ verticalProducts,
630
+ })), concatMap((data) => this.saveHomeData(data)))));
631
+ }
632
+ getBanners(type) {
633
+ return this.getHomeConfiguration().pipe(map((home) => {
634
+ if (type === 'brand')
635
+ return home.brandsCarousel;
636
+ if (type === 'buyToWin')
637
+ return [home.buyToWinBanner];
638
+ if (type === 'block')
639
+ return home.blockBanners;
640
+ if (type === 'blog')
641
+ return [home.blogBanner];
642
+ return [];
643
+ }));
644
+ }
645
+ getMinValueForFreeShipping() {
646
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
647
+ }
648
+ getDiscoverProducts() {
649
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
650
+ }
651
+ getFeaturedProducts() {
652
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
653
+ }
654
+ getVerticalProducts() {
655
+ 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({
656
+ filters: { categories: { operator: Where.IN, value: [category.id] } },
657
+ limits: { limit: 12 },
658
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
659
+ }
660
+ getHomeConfiguration() {
661
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
662
+ ? of(home)
663
+ : !this.homeId
664
+ ? throwError(new RequiredArgumentError(['homeId']))
665
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
666
+ }
667
+ saveHomeData(homeData) {
668
+ const data = {
669
+ createdAt: new Date(),
670
+ expiresAt: add(new Date(), { hours: 1 }),
671
+ data: homeData,
672
+ };
673
+ return from(this.homeRepository.update({
674
+ id: this.homeId,
675
+ data,
676
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
677
+ }
678
+ }
679
+ HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
680
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
681
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
682
+ type: Injectable
683
+ }], ctorParameters: function () {
684
+ return [{ type: undefined, decorators: [{
685
+ type: Inject,
686
+ args: ['CategoryRepository']
687
+ }] }, { type: undefined, decorators: [{
688
+ type: Inject,
689
+ args: ['HomeRepository']
690
+ }] }, { type: undefined, decorators: [{
691
+ type: Inject,
692
+ args: ['ProductRepository']
693
+ }] }, { type: i2.Shops, decorators: [{
694
+ type: Inject,
695
+ args: [DEFAULT_SHOP]
696
+ }] }];
697
+ } });
698
+
699
+ class AngularFirebaseAuthModule {
700
+ static initializeApp(options, nameOrConfig) {
701
+ return {
702
+ ngModule: AngularFirebaseAuthModule,
703
+ providers: [
704
+ { provide: FIREBASE_OPTIONS, useValue: options },
705
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
706
+ ],
707
+ };
708
+ }
709
+ }
710
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
711
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1$2.FirebaseAppModule, i1.AuthModule] });
712
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
713
+ {
714
+ provide: 'Authentication',
715
+ useFactory: (authenticationService, userRepository) => {
716
+ return new Authentication(authenticationService, userRepository);
717
+ },
718
+ deps: ['AuthenticationService', 'UserRepository'],
719
+ },
720
+ {
721
+ provide: 'AuthenticationService',
722
+ useFactory: (angularFireAuth) => {
723
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
724
+ },
725
+ deps: [Auth],
726
+ },
727
+ {
728
+ provide: 'Register',
729
+ useFactory: (registerService, userRepository) => {
730
+ return new Register(registerService, userRepository);
731
+ },
732
+ deps: ['RegisterService', 'UserRepository'],
733
+ },
734
+ {
735
+ provide: 'RegisterService',
736
+ useFactory: (angularFireAuth) => {
737
+ return new RegisterFirebaseAuthService(angularFireAuth);
738
+ },
739
+ deps: [Auth],
740
+ },
741
+ {
742
+ provide: 'SignOut',
743
+ useFactory: (authenticationService) => {
744
+ return new SignOut(authenticationService);
745
+ },
746
+ deps: ['AuthenticationService'],
747
+ },
748
+ {
749
+ provide: 'RecoveryPassword',
750
+ useFactory: (authenticationService) => {
751
+ return new RecoveryPassword(authenticationService);
752
+ },
753
+ deps: ['AuthenticationService'],
754
+ },
755
+ ], imports: [provideFirebaseApp((injector) => {
756
+ const appName = injector.get(FIREBASE_APP_NAME);
757
+ return appName
758
+ ? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
759
+ : initializeApp(injector.get(FIREBASE_OPTIONS));
760
+ }),
761
+ provideAuth(() => getAuth())] });
762
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
763
+ type: NgModule,
764
+ args: [{
765
+ imports: [
766
+ provideFirebaseApp((injector) => {
767
+ const appName = injector.get(FIREBASE_APP_NAME);
768
+ return appName
769
+ ? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
770
+ : initializeApp(injector.get(FIREBASE_OPTIONS));
771
+ }),
772
+ provideAuth(() => getAuth()),
773
+ ],
774
+ providers: [
775
+ {
776
+ provide: 'Authentication',
777
+ useFactory: (authenticationService, userRepository) => {
778
+ return new Authentication(authenticationService, userRepository);
779
+ },
780
+ deps: ['AuthenticationService', 'UserRepository'],
781
+ },
782
+ {
783
+ provide: 'AuthenticationService',
784
+ useFactory: (angularFireAuth) => {
785
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
786
+ },
787
+ deps: [Auth],
788
+ },
789
+ {
790
+ provide: 'Register',
791
+ useFactory: (registerService, userRepository) => {
792
+ return new Register(registerService, userRepository);
793
+ },
794
+ deps: ['RegisterService', 'UserRepository'],
795
+ },
796
+ {
797
+ provide: 'RegisterService',
798
+ useFactory: (angularFireAuth) => {
799
+ return new RegisterFirebaseAuthService(angularFireAuth);
800
+ },
801
+ deps: [Auth],
802
+ },
803
+ {
804
+ provide: 'SignOut',
805
+ useFactory: (authenticationService) => {
806
+ return new SignOut(authenticationService);
807
+ },
808
+ deps: ['AuthenticationService'],
809
+ },
810
+ {
811
+ provide: 'RecoveryPassword',
812
+ useFactory: (authenticationService) => {
813
+ return new RecoveryPassword(authenticationService);
814
+ },
815
+ deps: ['AuthenticationService'],
816
+ },
817
+ ],
818
+ }]
819
+ }] });
820
+
821
+ class AngularElasticSeachModule {
822
+ static initializeApp(options) {
823
+ return {
824
+ ngModule: AngularElasticSeachModule,
825
+ providers: [{ provide: ES_CONFIG, useValue: options }],
1551
826
  };
1552
- return from(this.homeRepository.update({
1553
- id: this.homeId,
1554
- data,
1555
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
1556
827
  }
1557
828
  }
1558
- HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1559
- HomeShopServiceprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
1560
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
1561
- type: Injectable
1562
- }], ctorParameters: function () {
1563
- return [{ type: undefined, decorators: [{
1564
- type: Inject,
1565
- args: ['CategoryRepository']
1566
- }] }, { type: undefined, decorators: [{
1567
- type: Inject,
1568
- args: ['HomeRepository']
1569
- }] }, { type: undefined, decorators: [{
1570
- type: Inject,
1571
- args: ['ProductRepository']
1572
- }] }, { type: i3.Shops, decorators: [{
1573
- type: Inject,
1574
- args: [DEFAULT_SHOP]
1575
- }] }];
1576
- } });
829
+ AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
830
+ AngularElasticSeachModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
831
+ AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
832
+ {
833
+ provide: ProductsIndex,
834
+ useFactory: (configuration) => {
835
+ return new ProductsIndex(new AxiosAdapter(configuration));
836
+ },
837
+ deps: [ES_CONFIG],
838
+ },
839
+ ] });
840
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
841
+ type: NgModule,
842
+ args: [{
843
+ providers: [
844
+ {
845
+ provide: ProductsIndex,
846
+ useFactory: (configuration) => {
847
+ return new ProductsIndex(new AxiosAdapter(configuration));
848
+ },
849
+ deps: [ES_CONFIG],
850
+ },
851
+ ],
852
+ }]
853
+ }] });
1577
854
 
1578
- class OrderService {
1579
- constructor(angularFirestore, orderRepository) {
1580
- this.angularFirestore = angularFirestore;
1581
- this.orderRepository = orderRepository;
1582
- this.orderSubject = new Subject();
1583
- }
1584
- getOrder(id) {
1585
- docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
1586
- .pipe(map((doc) => Order.toInstance(doc.data())))
1587
- .subscribe((doc) => this.orderSubject.next(doc));
1588
- return this.orderSubject;
855
+ class AngularFirestoreModule {
856
+ static initializeApp(options, nameOrConfig) {
857
+ return {
858
+ ngModule: AngularFirestoreModule,
859
+ providers: [
860
+ { provide: FIREBASE_OPTIONS, useValue: options.firebase },
861
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
862
+ { provide: ES_CONFIG, useValue: options.elasticSearch },
863
+ ],
864
+ };
1589
865
  }
1590
866
  }
1591
- OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, deps: [{ token: i1$2.Firestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1592
- OrderServiceprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
1593
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
1594
- type: Injectable
1595
- }], ctorParameters: function () {
1596
- return [{ type: i1$2.Firestore }, { type: i3.OrderFirestoreRepository, decorators: [{
1597
- type: Inject,
1598
- args: ['OrderRepository']
1599
- }] }];
1600
- } });
867
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
868
+ AngularFirestoreModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$2.FirebaseAppModule, i1$1.FirestoreModule] });
869
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
870
+ {
871
+ provide: 'BeautyProfileRepository',
872
+ useFactory: (firestore, userRepository) => {
873
+ return new UserBeautyProfileFirestoreRepository(firestore, userRepository);
874
+ },
875
+ deps: [Firestore, 'UserRepository'],
876
+ },
877
+ {
878
+ provide: 'Buy2WinRepository',
879
+ useFactory: (firestore) => {
880
+ return new Buy2WinFirestoreRepository(firestore);
881
+ },
882
+ deps: [Firestore],
883
+ },
884
+ {
885
+ provide: CategoryFirestoreRepository,
886
+ useFactory: (firestore) => {
887
+ return new CategoryFirestoreRepository(firestore);
888
+ },
889
+ deps: [Firestore],
890
+ },
891
+ {
892
+ provide: 'CheckoutRepository',
893
+ useFactory: (firestore) => {
894
+ return new CheckoutFirestoreRepository(firestore);
895
+ },
896
+ deps: [Firestore],
897
+ },
898
+ {
899
+ provide: 'CheckoutSubscriptionRepository',
900
+ useFactory: (firestore) => {
901
+ return new CheckoutSubscriptionFirestoreRepository(firestore);
902
+ },
903
+ deps: [Firestore],
904
+ },
905
+ {
906
+ provide: 'CouponRepository',
907
+ useFactory: (firestore) => {
908
+ return new CouponFirestoreRepository(firestore);
909
+ },
910
+ deps: [Firestore],
911
+ },
912
+ {
913
+ provide: 'EditionRepository',
914
+ useFactory: (firestore, subscriptionRepository) => {
915
+ return new SubscriptionEditionFirestoreRepository(firestore, subscriptionRepository);
916
+ },
917
+ deps: [Firestore, 'SubscriptionRepository'],
918
+ },
919
+ {
920
+ provide: 'HomeRepository',
921
+ useFactory: (firestore) => {
922
+ return new HomeFirestoreRepository(firestore);
923
+ },
924
+ deps: [Firestore],
925
+ },
926
+ {
927
+ provide: 'LeadRepository',
928
+ useFactory: (firestore) => {
929
+ return new LeadFirestoreRepository(firestore);
930
+ },
931
+ deps: [Firestore],
932
+ },
933
+ {
934
+ provide: 'LegacyOrderRepository',
935
+ useFactory: (firestore) => {
936
+ return new LegacyOrderFirestoreRepository(firestore);
937
+ },
938
+ deps: [Firestore],
939
+ },
940
+ {
941
+ provide: 'ShopMenuRepository',
942
+ useFactory: (firestore) => {
943
+ return new ShopMenuFirestoreRepository(firestore);
944
+ },
945
+ deps: [Firestore],
946
+ },
947
+ {
948
+ provide: 'OrderRepository',
949
+ useFactory: (firestore) => {
950
+ return new OrderFirestoreRepository(firestore);
951
+ },
952
+ deps: [Firestore],
953
+ },
954
+ {
955
+ provide: 'PaymentRepository',
956
+ useFactory: (firestore) => {
957
+ return new PaymentFirestoreRepository(firestore);
958
+ },
959
+ deps: [Firestore],
960
+ },
961
+ {
962
+ provide: ProductFirestoreRepository,
963
+ useFactory: (firestore) => {
964
+ return new ProductFirestoreRepository(firestore);
965
+ },
966
+ deps: [Firestore],
967
+ },
968
+ {
969
+ provide: 'SubscriptionPaymentRepository',
970
+ useFactory: (firestore, subscriptionRepository) => {
971
+ return new SubscriptionPaymentFirestoreRepository(firestore, subscriptionRepository);
972
+ },
973
+ deps: [Firestore, 'SubscriptionRepository'],
974
+ },
975
+ {
976
+ provide: 'SubscriptionPlanRepository',
977
+ useFactory: (firestore) => {
978
+ return new SubscriptionPlanFirestoreRepository(firestore);
979
+ },
980
+ deps: [Firestore],
981
+ },
982
+ {
983
+ provide: 'SubscriptionProductRepository',
984
+ useFactory: (firestore) => {
985
+ return new SubscriptionProductFirestoreRepository(firestore);
986
+ },
987
+ deps: [Firestore],
988
+ },
989
+ {
990
+ provide: 'SubscriptionRepository',
991
+ useFactory: (firestore) => {
992
+ return new SubscriptionFirestoreRepository(firestore);
993
+ },
994
+ deps: [Firestore],
995
+ },
996
+ {
997
+ provide: 'UserRepository',
998
+ useFactory: (firestore) => {
999
+ return new UserFirestoreRepository(firestore);
1000
+ },
1001
+ deps: [Firestore],
1002
+ },
1003
+ {
1004
+ provide: 'UserAddressRepository',
1005
+ useFactory: (firestore, userRepository) => {
1006
+ return new UserAddressFirestoreRepository(firestore, userRepository);
1007
+ },
1008
+ deps: [Firestore, 'UserRepository'],
1009
+ },
1010
+ {
1011
+ provide: 'UserPaymentMethodRepository',
1012
+ useFactory: (firestore, userRepository) => {
1013
+ return new UserPaymentMethodFirestoreRepository(firestore, userRepository);
1014
+ },
1015
+ deps: [Firestore, 'UserRepository'],
1016
+ },
1017
+ {
1018
+ provide: ProductVariantFirestoreRepository,
1019
+ useFactory: (firestore, productRepository) => {
1020
+ return new ProductVariantFirestoreRepository(firestore, productRepository);
1021
+ },
1022
+ deps: [Firestore, ProductFirestoreRepository],
1023
+ },
1024
+ ], imports: [AngularElasticSeachModule,
1025
+ provideFirebaseApp((injector) => {
1026
+ const appName = injector.get(FIREBASE_APP_NAME);
1027
+ return appName
1028
+ ? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
1029
+ : initializeApp(injector.get(FIREBASE_OPTIONS));
1030
+ }),
1031
+ provideFirestore(() => getFirestore())] });
1032
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1033
+ type: NgModule,
1034
+ args: [{
1035
+ imports: [
1036
+ AngularElasticSeachModule,
1037
+ provideFirebaseApp((injector) => {
1038
+ const appName = injector.get(FIREBASE_APP_NAME);
1039
+ return appName
1040
+ ? initializeApp(injector.get(FIREBASE_OPTIONS), appName)
1041
+ : initializeApp(injector.get(FIREBASE_OPTIONS));
1042
+ }),
1043
+ provideFirestore(() => getFirestore()),
1044
+ ],
1045
+ providers: [
1046
+ {
1047
+ provide: 'BeautyProfileRepository',
1048
+ useFactory: (firestore, userRepository) => {
1049
+ return new UserBeautyProfileFirestoreRepository(firestore, userRepository);
1050
+ },
1051
+ deps: [Firestore, 'UserRepository'],
1052
+ },
1053
+ {
1054
+ provide: 'Buy2WinRepository',
1055
+ useFactory: (firestore) => {
1056
+ return new Buy2WinFirestoreRepository(firestore);
1057
+ },
1058
+ deps: [Firestore],
1059
+ },
1060
+ {
1061
+ provide: CategoryFirestoreRepository,
1062
+ useFactory: (firestore) => {
1063
+ return new CategoryFirestoreRepository(firestore);
1064
+ },
1065
+ deps: [Firestore],
1066
+ },
1067
+ {
1068
+ provide: 'CheckoutRepository',
1069
+ useFactory: (firestore) => {
1070
+ return new CheckoutFirestoreRepository(firestore);
1071
+ },
1072
+ deps: [Firestore],
1073
+ },
1074
+ {
1075
+ provide: 'CheckoutSubscriptionRepository',
1076
+ useFactory: (firestore) => {
1077
+ return new CheckoutSubscriptionFirestoreRepository(firestore);
1078
+ },
1079
+ deps: [Firestore],
1080
+ },
1081
+ {
1082
+ provide: 'CouponRepository',
1083
+ useFactory: (firestore) => {
1084
+ return new CouponFirestoreRepository(firestore);
1085
+ },
1086
+ deps: [Firestore],
1087
+ },
1088
+ {
1089
+ provide: 'EditionRepository',
1090
+ useFactory: (firestore, subscriptionRepository) => {
1091
+ return new SubscriptionEditionFirestoreRepository(firestore, subscriptionRepository);
1092
+ },
1093
+ deps: [Firestore, 'SubscriptionRepository'],
1094
+ },
1095
+ {
1096
+ provide: 'HomeRepository',
1097
+ useFactory: (firestore) => {
1098
+ return new HomeFirestoreRepository(firestore);
1099
+ },
1100
+ deps: [Firestore],
1101
+ },
1102
+ {
1103
+ provide: 'LeadRepository',
1104
+ useFactory: (firestore) => {
1105
+ return new LeadFirestoreRepository(firestore);
1106
+ },
1107
+ deps: [Firestore],
1108
+ },
1109
+ {
1110
+ provide: 'LegacyOrderRepository',
1111
+ useFactory: (firestore) => {
1112
+ return new LegacyOrderFirestoreRepository(firestore);
1113
+ },
1114
+ deps: [Firestore],
1115
+ },
1116
+ {
1117
+ provide: 'ShopMenuRepository',
1118
+ useFactory: (firestore) => {
1119
+ return new ShopMenuFirestoreRepository(firestore);
1120
+ },
1121
+ deps: [Firestore],
1122
+ },
1123
+ {
1124
+ provide: 'OrderRepository',
1125
+ useFactory: (firestore) => {
1126
+ return new OrderFirestoreRepository(firestore);
1127
+ },
1128
+ deps: [Firestore],
1129
+ },
1130
+ {
1131
+ provide: 'PaymentRepository',
1132
+ useFactory: (firestore) => {
1133
+ return new PaymentFirestoreRepository(firestore);
1134
+ },
1135
+ deps: [Firestore],
1136
+ },
1137
+ {
1138
+ provide: ProductFirestoreRepository,
1139
+ useFactory: (firestore) => {
1140
+ return new ProductFirestoreRepository(firestore);
1141
+ },
1142
+ deps: [Firestore],
1143
+ },
1144
+ {
1145
+ provide: 'SubscriptionPaymentRepository',
1146
+ useFactory: (firestore, subscriptionRepository) => {
1147
+ return new SubscriptionPaymentFirestoreRepository(firestore, subscriptionRepository);
1148
+ },
1149
+ deps: [Firestore, 'SubscriptionRepository'],
1150
+ },
1151
+ {
1152
+ provide: 'SubscriptionPlanRepository',
1153
+ useFactory: (firestore) => {
1154
+ return new SubscriptionPlanFirestoreRepository(firestore);
1155
+ },
1156
+ deps: [Firestore],
1157
+ },
1158
+ {
1159
+ provide: 'SubscriptionProductRepository',
1160
+ useFactory: (firestore) => {
1161
+ return new SubscriptionProductFirestoreRepository(firestore);
1162
+ },
1163
+ deps: [Firestore],
1164
+ },
1165
+ {
1166
+ provide: 'SubscriptionRepository',
1167
+ useFactory: (firestore) => {
1168
+ return new SubscriptionFirestoreRepository(firestore);
1169
+ },
1170
+ deps: [Firestore],
1171
+ },
1172
+ {
1173
+ provide: 'UserRepository',
1174
+ useFactory: (firestore) => {
1175
+ return new UserFirestoreRepository(firestore);
1176
+ },
1177
+ deps: [Firestore],
1178
+ },
1179
+ {
1180
+ provide: 'UserAddressRepository',
1181
+ useFactory: (firestore, userRepository) => {
1182
+ return new UserAddressFirestoreRepository(firestore, userRepository);
1183
+ },
1184
+ deps: [Firestore, 'UserRepository'],
1185
+ },
1186
+ {
1187
+ provide: 'UserPaymentMethodRepository',
1188
+ useFactory: (firestore, userRepository) => {
1189
+ return new UserPaymentMethodFirestoreRepository(firestore, userRepository);
1190
+ },
1191
+ deps: [Firestore, 'UserRepository'],
1192
+ },
1193
+ {
1194
+ provide: ProductVariantFirestoreRepository,
1195
+ useFactory: (firestore, productRepository) => {
1196
+ return new ProductVariantFirestoreRepository(firestore, productRepository);
1197
+ },
1198
+ deps: [Firestore, ProductFirestoreRepository],
1199
+ },
1200
+ ],
1201
+ }]
1202
+ }] });
1601
1203
 
1602
- class ShippingService {
1603
- constructor(http, apiUrl, homeService) {
1604
- this.http = http;
1605
- this.apiUrl = apiUrl;
1606
- this.homeService = homeService;
1607
- }
1608
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
1609
- return combineLatest([
1610
- this.homeService.getHomeData(),
1611
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
1612
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
1613
- let shippingMethods = shippingMethodsResponse.result;
1614
- if (!shippingMethods.length)
1615
- return [];
1616
- shippingMethods = shippingMethods.map((shippingMethod) => {
1617
- if (shippingMethod.ShippingCompanyName == 'Same Day EG')
1618
- shippingMethod.ShippingCompanyName = 'Same Day';
1619
- return shippingMethod;
1620
- });
1621
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
1622
- if (this.isHolidays(datasSameDayNotAvaliable)) {
1623
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
1624
- }
1625
- if (totalPrice >= 200) {
1626
- shippingMethods = shippingMethods.map((s) => {
1627
- if (s.serviceName !== 'Same Day')
1628
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1629
- else
1630
- return s;
1631
- });
1632
- }
1633
- if (shop == Shops.GLAMSHOP)
1634
- return shippingMethods;
1635
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
1636
- shippingMethods = shippingMethods.map((s) => {
1637
- if (s.serviceName == 'Same Day')
1638
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
1639
- else
1640
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1641
- });
1642
- }
1643
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
1644
- shippingMethods = shippingMethods.map((s) => {
1645
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
1646
- });
1647
- }
1648
- return shippingMethods;
1649
- }));
1650
- }
1651
- isFreeShippingBySubscription(shop, subscriptionPlan) {
1652
- if (!subscriptionPlan)
1653
- return false;
1654
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
1655
- return true;
1656
- return false;
1657
- }
1658
- isHalfShippingBySubscription(shop, subscriptionPlan) {
1659
- if (!subscriptionPlan)
1660
- return false;
1661
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
1662
- return true;
1663
- }
1664
- return false;
1665
- }
1666
- isHolidays(datas) {
1667
- const today = new Date();
1668
- for (const key in datas) {
1669
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
1670
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
1671
- if (start > end)
1672
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
1673
- if (today >= start && today <= end)
1674
- return true;
1675
- }
1676
- return false;
1204
+ class AngularHasuraGraphQLModule {
1205
+ static initializeApp(options) {
1206
+ return {
1207
+ ngModule: AngularHasuraGraphQLModule,
1208
+ providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1209
+ };
1677
1210
  }
1678
1211
  }
1679
- ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i1$3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
1680
- ShippingServiceprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
1681
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
1682
- type: Injectable
1683
- }], ctorParameters: function () {
1684
- return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
1685
- type: Inject,
1686
- args: [BACKEND_URL]
1687
- }] }, { type: HomeShopService }];
1688
- } });
1212
+ AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1213
+ AngularHasuraGraphQLModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule });
1214
+ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1215
+ {
1216
+ provide: 'HasuraConfig',
1217
+ useFactory: (options, platformId) => ({
1218
+ endpoint: options.endpoint,
1219
+ authOptions: options.credentials,
1220
+ interceptors: {
1221
+ request: (request) => {
1222
+ console.log('request', request);
1223
+ },
1224
+ response: (response) => {
1225
+ console.log('response', response);
1226
+ },
1227
+ },
1228
+ }),
1229
+ deps: [HASURA_OPTIONS, PLATFORM_ID],
1230
+ },
1231
+ {
1232
+ provide: 'CategoryRepository',
1233
+ useExisting: CategoryHasuraGraphQLRepository,
1234
+ },
1235
+ {
1236
+ provide: CategoryHasuraGraphQLRepository,
1237
+ useFactory: (options, productRepository) => {
1238
+ return new CategoryHasuraGraphQLRepository({ endpoint: options.endpoint, authOptions: options.credentials }, productRepository);
1239
+ },
1240
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1241
+ },
1242
+ {
1243
+ provide: 'ProductRepository',
1244
+ useExisting: ProductHasuraGraphQLRepository,
1245
+ },
1246
+ {
1247
+ provide: ProductHasuraGraphQLRepository,
1248
+ useFactory: (options) => {
1249
+ return new ProductHasuraGraphQLRepository({ endpoint: options.endpoint, authOptions: options.credentials });
1250
+ },
1251
+ deps: [HASURA_OPTIONS],
1252
+ },
1253
+ {
1254
+ provide: 'VariantRepository',
1255
+ useExisting: VariantHasuraGraphQLRepository,
1256
+ },
1257
+ {
1258
+ provide: VariantHasuraGraphQLRepository,
1259
+ useFactory: (options) => {
1260
+ return new VariantHasuraGraphQLRepository({ endpoint: options.endpoint, authOptions: options.credentials });
1261
+ },
1262
+ deps: [HASURA_OPTIONS],
1263
+ },
1264
+ ] });
1265
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1266
+ type: NgModule,
1267
+ args: [{
1268
+ providers: [
1269
+ {
1270
+ provide: 'HasuraConfig',
1271
+ useFactory: (options, platformId) => ({
1272
+ endpoint: options.endpoint,
1273
+ authOptions: options.credentials,
1274
+ interceptors: {
1275
+ request: (request) => {
1276
+ console.log('request', request);
1277
+ },
1278
+ response: (response) => {
1279
+ console.log('response', response);
1280
+ },
1281
+ },
1282
+ }),
1283
+ deps: [HASURA_OPTIONS, PLATFORM_ID],
1284
+ },
1285
+ {
1286
+ provide: 'CategoryRepository',
1287
+ useExisting: CategoryHasuraGraphQLRepository,
1288
+ },
1289
+ {
1290
+ provide: CategoryHasuraGraphQLRepository,
1291
+ useFactory: (options, productRepository) => {
1292
+ return new CategoryHasuraGraphQLRepository({ endpoint: options.endpoint, authOptions: options.credentials }, productRepository);
1293
+ },
1294
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1295
+ },
1296
+ {
1297
+ provide: 'ProductRepository',
1298
+ useExisting: ProductHasuraGraphQLRepository,
1299
+ },
1300
+ {
1301
+ provide: ProductHasuraGraphQLRepository,
1302
+ useFactory: (options) => {
1303
+ return new ProductHasuraGraphQLRepository({ endpoint: options.endpoint, authOptions: options.credentials });
1304
+ },
1305
+ deps: [HASURA_OPTIONS],
1306
+ },
1307
+ {
1308
+ provide: 'VariantRepository',
1309
+ useExisting: VariantHasuraGraphQLRepository,
1310
+ },
1311
+ {
1312
+ provide: VariantHasuraGraphQLRepository,
1313
+ useFactory: (options) => {
1314
+ return new VariantHasuraGraphQLRepository({ endpoint: options.endpoint, authOptions: options.credentials });
1315
+ },
1316
+ deps: [HASURA_OPTIONS],
1317
+ },
1318
+ ],
1319
+ }]
1320
+ }] });
1689
1321
 
1690
1322
  class AngularConnectModule {
1691
1323
  static initializeApp(defaultShop, options, nameOrConfig) {
@@ -1697,7 +1329,6 @@ class AngularConnectModule {
1697
1329
  ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1698
1330
  ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1699
1331
  ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1700
- ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1701
1332
  ],
1702
1333
  };
1703
1334
  }
@@ -1712,7 +1343,6 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
1712
1343
  CouponService,
1713
1344
  HomeShopService,
1714
1345
  OrderService,
1715
- ShippingService,
1716
1346
  ], imports: [AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1717
1347
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
1718
1348
  type: NgModule,
@@ -1726,66 +1356,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1726
1356
  CouponService,
1727
1357
  HomeShopService,
1728
1358
  OrderService,
1729
- ShippingService,
1730
1359
  ],
1731
1360
  }]
1732
1361
  }] });
1733
1362
 
1734
- class CatalogService {
1735
- constructor() {
1736
- this.buildFilterQuery = (category, filters) => { };
1737
- this.buildSortQuery = (sort) => {
1738
- const query = {
1739
- stock: 'desc',
1740
- gender: 'asc',
1741
- };
1742
- return query;
1743
- };
1744
- this.buildLimitQuery = (options) => {
1745
- const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
1746
- return {
1747
- limit,
1748
- offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
1749
- };
1750
- };
1751
- }
1752
- fetchProducts(category, options) {
1753
- return {
1754
- products: [],
1755
- pages: 1,
1756
- };
1757
- }
1758
- }
1759
-
1760
- class CategoryService {
1761
- fetchSubCategories(category) {
1762
- return [];
1763
- }
1764
- fetchFilterOptions(category, filters) {
1765
- return [];
1766
- }
1767
- }
1768
-
1769
- var ProductSorts;
1770
- (function (ProductSorts) {
1771
- ProductSorts["MOST_RELEVANT"] = "most-relevant";
1772
- ProductSorts["BEST_SELLER"] = "best-sellers";
1773
- ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1774
- ProductSorts["LOWEST_PRICE"] = "lowest-price";
1775
- ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1776
- ProductSorts["BEST_RATING"] = "best-rating";
1777
- })(ProductSorts || (ProductSorts = {}));
1778
-
1779
- class CategoryWithTree extends Category {
1780
- }
1781
- __decorate([
1782
- Type(() => CategoryWithTree),
1783
- __metadata("design:type", Array)
1784
- ], CategoryWithTree.prototype, "children", void 0);
1785
-
1786
1363
  /**
1787
1364
  * Generated bundle index. Do not edit.
1788
1365
  */
1789
1366
 
1790
- export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ProductSorts, ShippingService };
1367
+ export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService };
1791
1368
  //# sourceMappingURL=infrab4a-connect-angular.mjs.map