@infrab4a/connect-angular 4.10.0-beta.9 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/angular-connect.module.d.ts +27 -29
  2. package/angular-elastic-search.module.d.ts +9 -9
  3. package/angular-firebase-auth.module.d.ts +11 -11
  4. package/angular-firestore.module.d.ts +17 -17
  5. package/angular-hasura-graphql.module.d.ts +16 -16
  6. package/consts/backend-url.const.d.ts +1 -1
  7. package/consts/category-structure.d.ts +1 -1
  8. package/consts/default-shop.const.d.ts +1 -1
  9. package/consts/es-config.const.d.ts +1 -1
  10. package/consts/firebase-const.d.ts +3 -3
  11. package/consts/hasura-options.const.d.ts +1 -1
  12. package/consts/index.d.ts +7 -8
  13. package/consts/persistence.const.d.ts +1 -1
  14. package/consts/storage-base-url.const.d.ts +1 -1
  15. package/esm2020/angular-connect.module.mjs +133 -146
  16. package/esm2020/angular-elastic-search.module.mjs +34 -34
  17. package/esm2020/angular-firebase-auth.module.mjs +115 -115
  18. package/esm2020/angular-firestore.module.mjs +499 -499
  19. package/esm2020/angular-hasura-graphql.module.mjs +287 -287
  20. package/esm2020/consts/backend-url.const.mjs +1 -1
  21. package/esm2020/consts/category-structure.mjs +2 -2
  22. package/esm2020/consts/default-shop.const.mjs +2 -2
  23. package/esm2020/consts/es-config.const.mjs +2 -2
  24. package/esm2020/consts/firebase-const.mjs +4 -4
  25. package/esm2020/consts/hasura-options.const.mjs +2 -2
  26. package/esm2020/consts/index.mjs +8 -9
  27. package/esm2020/consts/persistence.const.mjs +2 -2
  28. package/esm2020/consts/storage-base-url.const.mjs +2 -2
  29. package/esm2020/helpers/index.mjs +2 -2
  30. package/esm2020/helpers/mobile-operation-system-checker.helper.mjs +7 -7
  31. package/esm2020/index.mjs +7 -7
  32. package/esm2020/infrab4a-connect-angular.mjs +4 -4
  33. package/esm2020/persistence/cookie-data-persistence.mjs +22 -22
  34. package/esm2020/persistence/data-persistence.mjs +2 -2
  35. package/esm2020/persistence/index.mjs +3 -3
  36. package/esm2020/services/auth.service.mjs +37 -37
  37. package/esm2020/services/cart.service.mjs +284 -282
  38. package/esm2020/services/catalog/adapters/category-structure.adapter.mjs +2 -2
  39. package/esm2020/services/catalog/adapters/index.mjs +4 -4
  40. package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +43 -43
  41. package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +23 -23
  42. package/esm2020/services/catalog/catalog.service.mjs +235 -275
  43. package/esm2020/services/catalog/category.service.mjs +51 -51
  44. package/esm2020/services/catalog/enums/index.mjs +2 -2
  45. package/esm2020/services/catalog/enums/product-sorts.enum.mjs +11 -11
  46. package/esm2020/services/catalog/index.mjs +8 -8
  47. package/esm2020/services/catalog/models/category-with-tree.model.mjs +10 -10
  48. package/esm2020/services/catalog/models/index.mjs +2 -2
  49. package/esm2020/services/catalog/types/index.mjs +2 -2
  50. package/esm2020/services/catalog/types/product-sort.type.mjs +2 -2
  51. package/esm2020/services/catalog/wishlist.service.mjs +129 -133
  52. package/esm2020/services/checkout-subscription.service.mjs +50 -50
  53. package/esm2020/services/checkout.service.mjs +68 -68
  54. package/esm2020/services/coupon.service.mjs +265 -260
  55. package/esm2020/services/helpers/index.mjs +2 -2
  56. package/esm2020/services/helpers/util.helper.mjs +18 -18
  57. package/esm2020/services/home-shop.service.mjs +125 -125
  58. package/esm2020/services/index.mjs +11 -11
  59. package/esm2020/services/order.service.mjs +30 -30
  60. package/esm2020/services/shipping.service.mjs +96 -96
  61. package/esm2020/services/types/index.mjs +3 -3
  62. package/esm2020/services/types/required-checkout-data.type.mjs +2 -2
  63. package/esm2020/services/types/required-checkout-subscription-data.type.mjs +2 -2
  64. package/esm2020/services/types/shipping-methods.type.mjs +2 -2
  65. package/esm2020/types/firebase-app-config.type.mjs +2 -2
  66. package/esm2020/types/index.mjs +2 -2
  67. package/fesm2015/infrab4a-connect-angular.mjs +2449 -2531
  68. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
  69. package/fesm2020/infrab4a-connect-angular.mjs +2393 -2474
  70. package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
  71. package/helpers/index.d.ts +1 -1
  72. package/helpers/mobile-operation-system-checker.helper.d.ts +3 -3
  73. package/index.d.ts +6 -6
  74. package/package.json +2 -2
  75. package/persistence/cookie-data-persistence.d.ts +10 -10
  76. package/persistence/data-persistence.d.ts +6 -6
  77. package/persistence/index.d.ts +2 -2
  78. package/services/auth.service.d.ts +18 -18
  79. package/services/cart.service.d.ts +42 -42
  80. package/services/catalog/adapters/category-structure.adapter.d.ts +4 -4
  81. package/services/catalog/adapters/index.d.ts +3 -3
  82. package/services/catalog/adapters/new-category-structure.adapter.d.ts +12 -12
  83. package/services/catalog/adapters/old-category-structure.adapter.d.ts +10 -10
  84. package/services/catalog/catalog.service.d.ts +89 -89
  85. package/services/catalog/category.service.d.ts +20 -20
  86. package/services/catalog/enums/index.d.ts +1 -1
  87. package/services/catalog/enums/product-sorts.enum.d.ts +9 -9
  88. package/services/catalog/index.d.ts +7 -7
  89. package/services/catalog/models/category-with-tree.model.d.ts +4 -4
  90. package/services/catalog/models/index.d.ts +1 -1
  91. package/services/catalog/types/index.d.ts +1 -1
  92. package/services/catalog/types/product-sort.type.d.ts +2 -2
  93. package/services/catalog/wishlist.service.d.ts +44 -45
  94. package/services/checkout-subscription.service.d.ts +19 -19
  95. package/services/checkout.service.d.ts +27 -27
  96. package/services/coupon.service.d.ts +33 -33
  97. package/services/helpers/index.d.ts +1 -1
  98. package/services/helpers/util.helper.d.ts +3 -3
  99. package/services/home-shop.service.d.ts +26 -26
  100. package/services/index.d.ts +10 -10
  101. package/services/order.service.d.ts +13 -13
  102. package/services/shipping.service.d.ts +19 -19
  103. package/services/types/index.d.ts +2 -2
  104. package/services/types/required-checkout-data.type.d.ts +2 -2
  105. package/services/types/required-checkout-subscription-data.type.d.ts +2 -2
  106. package/services/types/shipping-methods.type.d.ts +12 -12
  107. package/types/firebase-app-config.type.d.ts +1 -1
  108. package/types/index.d.ts +1 -1
  109. package/angular-vertex-search.module.d.ts +0 -9
  110. package/consts/vertex-config.const.d.ts +0 -1
  111. package/esm2020/angular-vertex-search.module.mjs +0 -34
  112. package/esm2020/consts/vertex-config.const.mjs +0 -2
@@ -5,7 +5,7 @@ import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular
5
5
  import * as i2 from '@angular/fire/storage';
6
6
  import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
7
7
  import * as i1$2 from '@infrab4a/connect';
8
- import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, PersonTypes, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
8
+ import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, PersonTypes, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
9
9
  import * as i1 from '@angular/fire/auth';
10
10
  import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
11
11
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
@@ -20,34 +20,34 @@ import * as i1$3 from '@angular/common/http';
20
20
 
21
21
  const ES_CONFIG = 'ES_CONFIG';
22
22
 
23
- class AngularElasticSeachModule {
24
- static initializeApp(options) {
25
- return {
26
- ngModule: AngularElasticSeachModule,
27
- providers: [{ provide: ES_CONFIG, useValue: options }],
28
- };
29
- }
30
- }
31
- AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
32
- AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
33
- AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
34
- {
35
- provide: ProductsIndex,
36
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
37
- deps: [ES_CONFIG],
38
- },
39
- ] });
40
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
41
- type: NgModule,
42
- args: [{
43
- providers: [
44
- {
45
- provide: ProductsIndex,
46
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
47
- deps: [ES_CONFIG],
48
- },
49
- ],
50
- }]
23
+ class AngularElasticSeachModule {
24
+ static initializeApp(options) {
25
+ return {
26
+ ngModule: AngularElasticSeachModule,
27
+ providers: [{ provide: ES_CONFIG, useValue: options }],
28
+ };
29
+ }
30
+ }
31
+ AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
32
+ AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule });
33
+ AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, providers: [
34
+ {
35
+ provide: ProductsIndex,
36
+ useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
37
+ deps: [ES_CONFIG],
38
+ },
39
+ ] });
40
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
41
+ type: NgModule,
42
+ args: [{
43
+ providers: [
44
+ {
45
+ provide: ProductsIndex,
46
+ useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
47
+ deps: [ES_CONFIG],
48
+ },
49
+ ],
50
+ }]
51
51
  }] });
52
52
 
53
53
  const BACKEND_URL = 'BACKEND_URL';
@@ -56,2501 +56,2420 @@ const CATEGORY_STRUCTURE = 'CATEGORY_STRUCTURE';
56
56
 
57
57
  const DEFAULT_SHOP = 'DEFAULT_SHOP';
58
58
 
59
- const FIREBASE_APP_NAME = new InjectionToken('firebaseAppName');
59
+ const FIREBASE_APP_NAME = new InjectionToken('firebaseAppName');
60
60
  const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
61
61
 
62
62
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
63
63
 
64
64
  const PERSISTENCE_PROVIDER = 'PERSISTENCE_PROVIDER';
65
65
 
66
- const VERTEX_CONFIG = 'VERTEX_CONFIG';
67
-
68
- class AngularFirebaseAuthModule {
69
- static initializeApp(options, nameOrConfig) {
70
- return {
71
- ngModule: AngularFirebaseAuthModule,
72
- providers: [
73
- { provide: FIREBASE_OPTIONS, useValue: options },
74
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
75
- ],
76
- };
77
- }
78
- }
79
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
80
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1.AuthModule] });
81
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
82
- {
83
- provide: 'Authentication',
84
- useFactory: (authenticationService, userRepository) => {
85
- return new Authentication(authenticationService, userRepository);
86
- },
87
- deps: ['AuthenticationService', 'UserRepository'],
88
- },
89
- {
90
- provide: 'AuthenticationService',
91
- useFactory: (angularFireAuth) => {
92
- return new AuthenticationFirebaseAuthService(angularFireAuth);
93
- },
94
- deps: [Auth],
95
- },
96
- {
97
- provide: 'Register',
98
- useFactory: (registerService, userRepository) => {
99
- return new Register(registerService, userRepository);
100
- },
101
- deps: ['RegisterService', 'UserRepository'],
102
- },
103
- {
104
- provide: 'RegisterService',
105
- useFactory: (angularFireAuth) => {
106
- return new RegisterFirebaseAuthService(angularFireAuth);
107
- },
108
- deps: [Auth],
109
- },
110
- {
111
- provide: 'SignOut',
112
- useFactory: (authenticationService) => {
113
- return new SignOut(authenticationService);
114
- },
115
- deps: ['AuthenticationService'],
116
- },
117
- {
118
- provide: 'RecoveryPassword',
119
- useFactory: (authenticationService) => {
120
- return new RecoveryPassword(authenticationService);
121
- },
122
- deps: ['AuthenticationService'],
123
- },
124
- ], imports: [provideAuth((injector) => getAuth(injector.get(FirebaseApp)))] });
125
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
126
- type: NgModule,
127
- args: [{
128
- imports: [provideAuth((injector) => getAuth(injector.get(FirebaseApp)))],
129
- providers: [
130
- {
131
- provide: 'Authentication',
132
- useFactory: (authenticationService, userRepository) => {
133
- return new Authentication(authenticationService, userRepository);
134
- },
135
- deps: ['AuthenticationService', 'UserRepository'],
136
- },
137
- {
138
- provide: 'AuthenticationService',
139
- useFactory: (angularFireAuth) => {
140
- return new AuthenticationFirebaseAuthService(angularFireAuth);
141
- },
142
- deps: [Auth],
143
- },
144
- {
145
- provide: 'Register',
146
- useFactory: (registerService, userRepository) => {
147
- return new Register(registerService, userRepository);
148
- },
149
- deps: ['RegisterService', 'UserRepository'],
150
- },
151
- {
152
- provide: 'RegisterService',
153
- useFactory: (angularFireAuth) => {
154
- return new RegisterFirebaseAuthService(angularFireAuth);
155
- },
156
- deps: [Auth],
157
- },
158
- {
159
- provide: 'SignOut',
160
- useFactory: (authenticationService) => {
161
- return new SignOut(authenticationService);
162
- },
163
- deps: ['AuthenticationService'],
164
- },
165
- {
166
- provide: 'RecoveryPassword',
167
- useFactory: (authenticationService) => {
168
- return new RecoveryPassword(authenticationService);
169
- },
170
- deps: ['AuthenticationService'],
171
- },
172
- ],
173
- }]
66
+ class AngularFirebaseAuthModule {
67
+ static initializeApp(options, nameOrConfig) {
68
+ return {
69
+ ngModule: AngularFirebaseAuthModule,
70
+ providers: [
71
+ { provide: FIREBASE_OPTIONS, useValue: options },
72
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
73
+ ],
74
+ };
75
+ }
76
+ }
77
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
78
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, imports: [i1.AuthModule] });
79
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
80
+ {
81
+ provide: 'Authentication',
82
+ useFactory: (authenticationService, userRepository) => {
83
+ return new Authentication(authenticationService, userRepository);
84
+ },
85
+ deps: ['AuthenticationService', 'UserRepository'],
86
+ },
87
+ {
88
+ provide: 'AuthenticationService',
89
+ useFactory: (angularFireAuth) => {
90
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
91
+ },
92
+ deps: [Auth],
93
+ },
94
+ {
95
+ provide: 'Register',
96
+ useFactory: (registerService, userRepository) => {
97
+ return new Register(registerService, userRepository);
98
+ },
99
+ deps: ['RegisterService', 'UserRepository'],
100
+ },
101
+ {
102
+ provide: 'RegisterService',
103
+ useFactory: (angularFireAuth) => {
104
+ return new RegisterFirebaseAuthService(angularFireAuth);
105
+ },
106
+ deps: [Auth],
107
+ },
108
+ {
109
+ provide: 'SignOut',
110
+ useFactory: (authenticationService) => {
111
+ return new SignOut(authenticationService);
112
+ },
113
+ deps: ['AuthenticationService'],
114
+ },
115
+ {
116
+ provide: 'RecoveryPassword',
117
+ useFactory: (authenticationService) => {
118
+ return new RecoveryPassword(authenticationService);
119
+ },
120
+ deps: ['AuthenticationService'],
121
+ },
122
+ ], imports: [provideAuth((injector) => getAuth(injector.get(FirebaseApp)))] });
123
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
124
+ type: NgModule,
125
+ args: [{
126
+ imports: [provideAuth((injector) => getAuth(injector.get(FirebaseApp)))],
127
+ providers: [
128
+ {
129
+ provide: 'Authentication',
130
+ useFactory: (authenticationService, userRepository) => {
131
+ return new Authentication(authenticationService, userRepository);
132
+ },
133
+ deps: ['AuthenticationService', 'UserRepository'],
134
+ },
135
+ {
136
+ provide: 'AuthenticationService',
137
+ useFactory: (angularFireAuth) => {
138
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
139
+ },
140
+ deps: [Auth],
141
+ },
142
+ {
143
+ provide: 'Register',
144
+ useFactory: (registerService, userRepository) => {
145
+ return new Register(registerService, userRepository);
146
+ },
147
+ deps: ['RegisterService', 'UserRepository'],
148
+ },
149
+ {
150
+ provide: 'RegisterService',
151
+ useFactory: (angularFireAuth) => {
152
+ return new RegisterFirebaseAuthService(angularFireAuth);
153
+ },
154
+ deps: [Auth],
155
+ },
156
+ {
157
+ provide: 'SignOut',
158
+ useFactory: (authenticationService) => {
159
+ return new SignOut(authenticationService);
160
+ },
161
+ deps: ['AuthenticationService'],
162
+ },
163
+ {
164
+ provide: 'RecoveryPassword',
165
+ useFactory: (authenticationService) => {
166
+ return new RecoveryPassword(authenticationService);
167
+ },
168
+ deps: ['AuthenticationService'],
169
+ },
170
+ ],
171
+ }]
174
172
  }] });
175
173
 
176
- class MobileOperationSystemCheckerHelper {
177
- static isAppleDevice() {
178
- return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
179
- (navigator?.userAgent?.includes?.('Mac') && 'ontouchend' in (document || {})));
180
- }
174
+ class MobileOperationSystemCheckerHelper {
175
+ static isAppleDevice() {
176
+ return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
177
+ (navigator?.userAgent?.includes?.('Mac') && 'ontouchend' in (document || {})));
178
+ }
181
179
  }
182
180
 
183
- class AngularFirestoreModule {
184
- static initializeApp(options, nameOrConfig) {
185
- return {
186
- ngModule: AngularFirestoreModule,
187
- providers: [
188
- { provide: FIREBASE_OPTIONS, useValue: options.firebase },
189
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
190
- { provide: ES_CONFIG, useValue: options.elasticSearch },
191
- ],
192
- };
193
- }
194
- }
195
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
196
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] });
197
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
198
- {
199
- provide: 'FirestoreOptions',
200
- useFactory: (firestore, platformId) => ({
201
- firestore: new ConnectFirestoreService(firestore),
202
- interceptors: {
203
- request: (request) => {
204
- if (isPlatformBrowser(platformId))
205
- return request;
206
- const interval = setInterval(() => { }, 100);
207
- request.interval = interval;
208
- return request;
209
- },
210
- response: (response, request) => {
211
- if (isPlatformBrowser(platformId))
212
- return response;
213
- clearInterval(request.interval);
214
- return response;
215
- },
216
- },
217
- }),
218
- deps: [Firestore, PLATFORM_ID],
219
- },
220
- {
221
- provide: 'BeautyProfileRepository',
222
- useFactory: (config, userRepository) => {
223
- return new UserBeautyProfileFirestoreRepository(config, userRepository);
224
- },
225
- deps: ['FirestoreOptions', 'UserRepository'],
226
- },
227
- {
228
- provide: 'Buy2WinRepository',
229
- useFactory: (options) => {
230
- return new Buy2WinFirestoreRepository(options);
231
- },
232
- deps: ['FirestoreOptions'],
233
- },
234
- {
235
- provide: CategoryFirestoreRepository,
236
- useFactory: (options) => {
237
- return new CategoryFirestoreRepository(options);
238
- },
239
- deps: ['FirestoreOptions'],
240
- },
241
- {
242
- provide: 'CheckoutRepository',
243
- useFactory: (options) => {
244
- return new CheckoutFirestoreRepository(options);
245
- },
246
- deps: ['FirestoreOptions'],
247
- },
248
- {
249
- provide: 'CheckoutSubscriptionRepository',
250
- useFactory: (options) => {
251
- return new CheckoutSubscriptionFirestoreRepository(options);
252
- },
253
- deps: ['FirestoreOptions'],
254
- },
255
- {
256
- provide: 'CouponRepository',
257
- useFactory: (options) => {
258
- return new CouponFirestoreRepository(options);
259
- },
260
- deps: ['FirestoreOptions'],
261
- },
262
- {
263
- provide: 'CampaignHashtagRepository',
264
- useFactory: (options) => {
265
- return new CampaignHashtagFirestoreRepository(options);
266
- },
267
- deps: ['FirestoreOptions'],
268
- },
269
- {
270
- provide: 'CampaignDashboardRepository',
271
- useFactory: (options) => {
272
- return new CampaignDashboardFirestoreRepository(options);
273
- },
274
- deps: ['FirestoreOptions'],
275
- },
276
- {
277
- provide: 'EditionRepository',
278
- useFactory: (options, subscriptionRepository) => {
279
- return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
280
- },
281
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
282
- },
283
- {
284
- provide: 'HomeRepository',
285
- useFactory: (options) => {
286
- return new HomeFirestoreRepository(options);
287
- },
288
- deps: ['FirestoreOptions'],
289
- },
290
- {
291
- provide: 'LeadRepository',
292
- useFactory: (options) => {
293
- return new LeadFirestoreRepository(options);
294
- },
295
- deps: ['FirestoreOptions'],
296
- },
297
- {
298
- provide: 'LegacyOrderRepository',
299
- useFactory: (options) => {
300
- return new LegacyOrderFirestoreRepository(options);
301
- },
302
- deps: ['FirestoreOptions'],
303
- },
304
- {
305
- provide: 'ShopMenuRepository',
306
- useFactory: (options) => {
307
- return new ShopMenuFirestoreRepository(options);
308
- },
309
- deps: ['FirestoreOptions'],
310
- },
311
- {
312
- provide: 'OrderRepository',
313
- useFactory: (options) => {
314
- return new OrderFirestoreRepository(options);
315
- },
316
- deps: ['FirestoreOptions'],
317
- },
318
- {
319
- provide: 'PaymentRepository',
320
- useFactory: (options) => {
321
- return new PaymentFirestoreRepository(options);
322
- },
323
- deps: ['FirestoreOptions'],
324
- },
325
- {
326
- provide: ProductFirestoreRepository,
327
- useFactory: (options) => {
328
- return new ProductFirestoreRepository(options);
329
- },
330
- deps: ['FirestoreOptions'],
331
- },
332
- {
333
- provide: 'ShopSettingsRepository',
334
- useFactory: (options) => {
335
- return new ShopSettingsFirestoreRepository(options);
336
- },
337
- deps: ['FirestoreOptions'],
338
- },
339
- {
340
- provide: 'SubscriptionPaymentRepository',
341
- useFactory: (options, subscriptionRepository) => {
342
- return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
343
- },
344
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
345
- },
346
- {
347
- provide: 'SubscriptionPlanRepository',
348
- useFactory: (options) => {
349
- return new SubscriptionPlanFirestoreRepository(options);
350
- },
351
- deps: ['FirestoreOptions'],
352
- },
353
- {
354
- provide: 'SubscriptionProductRepository',
355
- useFactory: (options) => {
356
- return new SubscriptionProductFirestoreRepository(options);
357
- },
358
- deps: ['FirestoreOptions'],
359
- },
360
- {
361
- provide: 'SubscriptionRepository',
362
- useFactory: (options) => {
363
- return new SubscriptionFirestoreRepository(options);
364
- },
365
- deps: ['FirestoreOptions'],
366
- },
367
- {
368
- provide: 'UserRepository',
369
- useFactory: (options) => {
370
- return new UserFirestoreRepository(options);
371
- },
372
- deps: ['FirestoreOptions'],
373
- },
374
- {
375
- provide: 'UserAddressRepository',
376
- useFactory: (options, userRepository) => {
377
- return new UserAddressFirestoreRepository(options, userRepository);
378
- },
379
- deps: ['FirestoreOptions', 'UserRepository'],
380
- },
381
- {
382
- provide: 'UserPaymentMethodRepository',
383
- useFactory: (options, userRepository) => {
384
- return new UserPaymentMethodFirestoreRepository(options, userRepository);
385
- },
386
- deps: ['FirestoreOptions', 'UserRepository'],
387
- },
388
- {
389
- provide: 'SubscriptionMaterializationRepository',
390
- useFactory: (options) => {
391
- return new SubscriptionMaterializationFirestoreRepository(options);
392
- },
393
- deps: ['FirestoreOptions'],
394
- },
395
- {
396
- provide: 'SubscriptionSummaryRepository',
397
- useFactory: (options) => {
398
- return new SubscriptionSummaryFirestoreRepository(options);
399
- },
400
- deps: ['FirestoreOptions'],
401
- },
402
- {
403
- provide: ProductVariantFirestoreRepository,
404
- useFactory: (options, productRepository) => {
405
- return new ProductVariantFirestoreRepository(options, productRepository);
406
- },
407
- deps: ['FirestoreOptions', ProductFirestoreRepository],
408
- },
409
- {
410
- provide: 'OrderBlockedRepository',
411
- useFactory: (options) => {
412
- return new OrderBlockedFirestoreRepository(options);
413
- },
414
- deps: ['FirestoreOptions'],
415
- },
416
- ], imports: [AngularElasticSeachModule,
417
- provideFirestore((injector) => {
418
- const platformId = injector.get(PLATFORM_ID);
419
- if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
420
- return initializeFirestore(injector.get(FirebaseApp), {
421
- ignoreUndefinedProperties: true,
422
- });
423
- const firestore = initializeFirestore(injector.get(FirebaseApp), {
424
- experimentalForceLongPolling: true,
425
- ignoreUndefinedProperties: true,
426
- localCache: memoryLocalCache(),
427
- });
428
- return firestore;
429
- })] });
430
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, decorators: [{
431
- type: NgModule,
432
- args: [{
433
- imports: [
434
- AngularElasticSeachModule,
435
- provideFirestore((injector) => {
436
- const platformId = injector.get(PLATFORM_ID);
437
- if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
438
- return initializeFirestore(injector.get(FirebaseApp), {
439
- ignoreUndefinedProperties: true,
440
- });
441
- const firestore = initializeFirestore(injector.get(FirebaseApp), {
442
- experimentalForceLongPolling: true,
443
- ignoreUndefinedProperties: true,
444
- localCache: memoryLocalCache(),
445
- });
446
- return firestore;
447
- }),
448
- ],
449
- providers: [
450
- {
451
- provide: 'FirestoreOptions',
452
- useFactory: (firestore, platformId) => ({
453
- firestore: new ConnectFirestoreService(firestore),
454
- interceptors: {
455
- request: (request) => {
456
- if (isPlatformBrowser(platformId))
457
- return request;
458
- const interval = setInterval(() => { }, 100);
459
- request.interval = interval;
460
- return request;
461
- },
462
- response: (response, request) => {
463
- if (isPlatformBrowser(platformId))
464
- return response;
465
- clearInterval(request.interval);
466
- return response;
467
- },
468
- },
469
- }),
470
- deps: [Firestore, PLATFORM_ID],
471
- },
472
- {
473
- provide: 'BeautyProfileRepository',
474
- useFactory: (config, userRepository) => {
475
- return new UserBeautyProfileFirestoreRepository(config, userRepository);
476
- },
477
- deps: ['FirestoreOptions', 'UserRepository'],
478
- },
479
- {
480
- provide: 'Buy2WinRepository',
481
- useFactory: (options) => {
482
- return new Buy2WinFirestoreRepository(options);
483
- },
484
- deps: ['FirestoreOptions'],
485
- },
486
- {
487
- provide: CategoryFirestoreRepository,
488
- useFactory: (options) => {
489
- return new CategoryFirestoreRepository(options);
490
- },
491
- deps: ['FirestoreOptions'],
492
- },
493
- {
494
- provide: 'CheckoutRepository',
495
- useFactory: (options) => {
496
- return new CheckoutFirestoreRepository(options);
497
- },
498
- deps: ['FirestoreOptions'],
499
- },
500
- {
501
- provide: 'CheckoutSubscriptionRepository',
502
- useFactory: (options) => {
503
- return new CheckoutSubscriptionFirestoreRepository(options);
504
- },
505
- deps: ['FirestoreOptions'],
506
- },
507
- {
508
- provide: 'CouponRepository',
509
- useFactory: (options) => {
510
- return new CouponFirestoreRepository(options);
511
- },
512
- deps: ['FirestoreOptions'],
513
- },
514
- {
515
- provide: 'CampaignHashtagRepository',
516
- useFactory: (options) => {
517
- return new CampaignHashtagFirestoreRepository(options);
518
- },
519
- deps: ['FirestoreOptions'],
520
- },
521
- {
522
- provide: 'CampaignDashboardRepository',
523
- useFactory: (options) => {
524
- return new CampaignDashboardFirestoreRepository(options);
525
- },
526
- deps: ['FirestoreOptions'],
527
- },
528
- {
529
- provide: 'EditionRepository',
530
- useFactory: (options, subscriptionRepository) => {
531
- return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
532
- },
533
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
534
- },
535
- {
536
- provide: 'HomeRepository',
537
- useFactory: (options) => {
538
- return new HomeFirestoreRepository(options);
539
- },
540
- deps: ['FirestoreOptions'],
541
- },
542
- {
543
- provide: 'LeadRepository',
544
- useFactory: (options) => {
545
- return new LeadFirestoreRepository(options);
546
- },
547
- deps: ['FirestoreOptions'],
548
- },
549
- {
550
- provide: 'LegacyOrderRepository',
551
- useFactory: (options) => {
552
- return new LegacyOrderFirestoreRepository(options);
553
- },
554
- deps: ['FirestoreOptions'],
555
- },
556
- {
557
- provide: 'ShopMenuRepository',
558
- useFactory: (options) => {
559
- return new ShopMenuFirestoreRepository(options);
560
- },
561
- deps: ['FirestoreOptions'],
562
- },
563
- {
564
- provide: 'OrderRepository',
565
- useFactory: (options) => {
566
- return new OrderFirestoreRepository(options);
567
- },
568
- deps: ['FirestoreOptions'],
569
- },
570
- {
571
- provide: 'PaymentRepository',
572
- useFactory: (options) => {
573
- return new PaymentFirestoreRepository(options);
574
- },
575
- deps: ['FirestoreOptions'],
576
- },
577
- {
578
- provide: ProductFirestoreRepository,
579
- useFactory: (options) => {
580
- return new ProductFirestoreRepository(options);
581
- },
582
- deps: ['FirestoreOptions'],
583
- },
584
- {
585
- provide: 'ShopSettingsRepository',
586
- useFactory: (options) => {
587
- return new ShopSettingsFirestoreRepository(options);
588
- },
589
- deps: ['FirestoreOptions'],
590
- },
591
- {
592
- provide: 'SubscriptionPaymentRepository',
593
- useFactory: (options, subscriptionRepository) => {
594
- return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
595
- },
596
- deps: ['FirestoreOptions', 'SubscriptionRepository'],
597
- },
598
- {
599
- provide: 'SubscriptionPlanRepository',
600
- useFactory: (options) => {
601
- return new SubscriptionPlanFirestoreRepository(options);
602
- },
603
- deps: ['FirestoreOptions'],
604
- },
605
- {
606
- provide: 'SubscriptionProductRepository',
607
- useFactory: (options) => {
608
- return new SubscriptionProductFirestoreRepository(options);
609
- },
610
- deps: ['FirestoreOptions'],
611
- },
612
- {
613
- provide: 'SubscriptionRepository',
614
- useFactory: (options) => {
615
- return new SubscriptionFirestoreRepository(options);
616
- },
617
- deps: ['FirestoreOptions'],
618
- },
619
- {
620
- provide: 'UserRepository',
621
- useFactory: (options) => {
622
- return new UserFirestoreRepository(options);
623
- },
624
- deps: ['FirestoreOptions'],
625
- },
626
- {
627
- provide: 'UserAddressRepository',
628
- useFactory: (options, userRepository) => {
629
- return new UserAddressFirestoreRepository(options, userRepository);
630
- },
631
- deps: ['FirestoreOptions', 'UserRepository'],
632
- },
633
- {
634
- provide: 'UserPaymentMethodRepository',
635
- useFactory: (options, userRepository) => {
636
- return new UserPaymentMethodFirestoreRepository(options, userRepository);
637
- },
638
- deps: ['FirestoreOptions', 'UserRepository'],
639
- },
640
- {
641
- provide: 'SubscriptionMaterializationRepository',
642
- useFactory: (options) => {
643
- return new SubscriptionMaterializationFirestoreRepository(options);
644
- },
645
- deps: ['FirestoreOptions'],
646
- },
647
- {
648
- provide: 'SubscriptionSummaryRepository',
649
- useFactory: (options) => {
650
- return new SubscriptionSummaryFirestoreRepository(options);
651
- },
652
- deps: ['FirestoreOptions'],
653
- },
654
- {
655
- provide: ProductVariantFirestoreRepository,
656
- useFactory: (options, productRepository) => {
657
- return new ProductVariantFirestoreRepository(options, productRepository);
658
- },
659
- deps: ['FirestoreOptions', ProductFirestoreRepository],
660
- },
661
- {
662
- provide: 'OrderBlockedRepository',
663
- useFactory: (options) => {
664
- return new OrderBlockedFirestoreRepository(options);
665
- },
666
- deps: ['FirestoreOptions'],
667
- },
668
- ],
669
- }]
670
- }] });
671
-
672
- class AngularHasuraGraphQLModule {
673
- static initializeApp(options) {
674
- return {
675
- ngModule: AngularHasuraGraphQLModule,
676
- providers: [{ provide: HASURA_OPTIONS, useValue: options }],
677
- };
678
- }
679
- }
680
- AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
681
- AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule });
682
- AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
683
- {
684
- provide: 'HasuraConfig',
685
- useFactory: (options, platformId) => ({
686
- endpoint: options.endpoint,
687
- authOptions: options.credentials,
688
- interceptors: {
689
- request: (request) => {
690
- if (isPlatformBrowser(platformId))
691
- return request;
692
- const interval = setInterval(() => { }, 100);
693
- request.interval = interval;
694
- return request;
695
- },
696
- response: (response, request) => {
697
- if (isPlatformBrowser(platformId))
698
- return response;
699
- clearInterval(request.interval);
700
- return response;
701
- },
702
- },
703
- }),
704
- deps: [HASURA_OPTIONS, PLATFORM_ID],
705
- },
706
- {
707
- provide: 'CategoryRepository',
708
- useExisting: CategoryHasuraGraphQLRepository,
709
- },
710
- {
711
- provide: CategoryHasuraGraphQLRepository,
712
- useFactory: (options, productRepository, categoryFilterRepository) => {
713
- return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
714
- },
715
- deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
716
- },
717
- {
718
- provide: 'ProductRepository',
719
- useExisting: ProductHasuraGraphQLRepository,
720
- },
721
- {
722
- provide: ProductHasuraGraphQLRepository,
723
- useFactory: (hasuraConfig) => {
724
- return new ProductHasuraGraphQLRepository(hasuraConfig);
725
- },
726
- deps: ['HasuraConfig'],
727
- },
728
- {
729
- provide: 'ProductReviewsRepository',
730
- useExisting: ProductReviewsHasuraGraphQLRepository,
731
- },
732
- {
733
- provide: ProductReviewsHasuraGraphQLRepository,
734
- useFactory: (hasuraConfig) => {
735
- return new ProductReviewsHasuraGraphQLRepository(hasuraConfig);
736
- },
737
- deps: ['HasuraConfig'],
738
- },
739
- {
740
- provide: 'VariantRepository',
741
- useExisting: VariantHasuraGraphQLRepository,
742
- },
743
- {
744
- provide: VariantHasuraGraphQLRepository,
745
- useFactory: (hasuraConfig) => {
746
- return new VariantHasuraGraphQLRepository(hasuraConfig);
747
- },
748
- deps: ['HasuraConfig'],
749
- },
750
- {
751
- provide: 'ProductStockNotificationRepository',
752
- useExisting: ProductStockNotificationHasuraGraphQLRepository,
753
- },
754
- {
755
- provide: ProductStockNotificationHasuraGraphQLRepository,
756
- useFactory: (hasuraConfig) => {
757
- return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
758
- },
759
- deps: ['HasuraConfig'],
760
- },
761
- {
762
- provide: 'CategoryFilterRepository',
763
- useExisting: CategoryFilterHasuraGraphQLRepository,
764
- },
765
- {
766
- provide: CategoryFilterHasuraGraphQLRepository,
767
- useFactory: (options) => {
768
- return new CategoryFilterHasuraGraphQLRepository(options);
769
- },
770
- deps: ['HasuraConfig'],
771
- },
772
- {
773
- provide: 'FilterOptionRepository',
774
- useExisting: FilterOptionHasuraGraphQLRepository,
775
- },
776
- {
777
- provide: FilterOptionHasuraGraphQLRepository,
778
- useFactory: (options) => {
779
- return new FilterOptionHasuraGraphQLRepository(options);
780
- },
781
- deps: ['HasuraConfig'],
782
- },
783
- {
784
- provide: 'FilterRepository',
785
- useExisting: FilterHasuraGraphQLRepository,
786
- },
787
- {
788
- provide: FilterHasuraGraphQLRepository,
789
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
790
- return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
791
- },
792
- deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
793
- },
794
- {
795
- provide: CategoryCollectionChildrenHasuraGraphQLRepository,
796
- useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options),
797
- deps: ['HasuraConfig'],
798
- },
799
- {
800
- provide: 'CategoryCollectionChildrenRepository',
801
- useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
802
- },
803
- {
804
- provide: WishlistHasuraGraphQLRepository,
805
- useFactory: (options, categoryFilterRepository) => {
806
- return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
807
- },
808
- deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
809
- },
810
- {
811
- provide: 'WishlistRepository',
812
- useExisting: WishlistHasuraGraphQLRepository,
813
- },
814
- ] });
815
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
816
- type: NgModule,
817
- args: [{
818
- providers: [
819
- {
820
- provide: 'HasuraConfig',
821
- useFactory: (options, platformId) => ({
822
- endpoint: options.endpoint,
823
- authOptions: options.credentials,
824
- interceptors: {
825
- request: (request) => {
826
- if (isPlatformBrowser(platformId))
827
- return request;
828
- const interval = setInterval(() => { }, 100);
829
- request.interval = interval;
830
- return request;
831
- },
832
- response: (response, request) => {
833
- if (isPlatformBrowser(platformId))
834
- return response;
835
- clearInterval(request.interval);
836
- return response;
837
- },
838
- },
839
- }),
840
- deps: [HASURA_OPTIONS, PLATFORM_ID],
841
- },
842
- {
843
- provide: 'CategoryRepository',
844
- useExisting: CategoryHasuraGraphQLRepository,
845
- },
846
- {
847
- provide: CategoryHasuraGraphQLRepository,
848
- useFactory: (options, productRepository, categoryFilterRepository) => {
849
- return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
850
- },
851
- deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
852
- },
853
- {
854
- provide: 'ProductRepository',
855
- useExisting: ProductHasuraGraphQLRepository,
856
- },
857
- {
858
- provide: ProductHasuraGraphQLRepository,
859
- useFactory: (hasuraConfig) => {
860
- return new ProductHasuraGraphQLRepository(hasuraConfig);
861
- },
862
- deps: ['HasuraConfig'],
863
- },
864
- {
865
- provide: 'ProductReviewsRepository',
866
- useExisting: ProductReviewsHasuraGraphQLRepository,
867
- },
868
- {
869
- provide: ProductReviewsHasuraGraphQLRepository,
870
- useFactory: (hasuraConfig) => {
871
- return new ProductReviewsHasuraGraphQLRepository(hasuraConfig);
872
- },
873
- deps: ['HasuraConfig'],
874
- },
875
- {
876
- provide: 'VariantRepository',
877
- useExisting: VariantHasuraGraphQLRepository,
878
- },
879
- {
880
- provide: VariantHasuraGraphQLRepository,
881
- useFactory: (hasuraConfig) => {
882
- return new VariantHasuraGraphQLRepository(hasuraConfig);
883
- },
884
- deps: ['HasuraConfig'],
885
- },
886
- {
887
- provide: 'ProductStockNotificationRepository',
888
- useExisting: ProductStockNotificationHasuraGraphQLRepository,
889
- },
890
- {
891
- provide: ProductStockNotificationHasuraGraphQLRepository,
892
- useFactory: (hasuraConfig) => {
893
- return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
894
- },
895
- deps: ['HasuraConfig'],
896
- },
897
- {
898
- provide: 'CategoryFilterRepository',
899
- useExisting: CategoryFilterHasuraGraphQLRepository,
900
- },
901
- {
902
- provide: CategoryFilterHasuraGraphQLRepository,
903
- useFactory: (options) => {
904
- return new CategoryFilterHasuraGraphQLRepository(options);
905
- },
906
- deps: ['HasuraConfig'],
907
- },
908
- {
909
- provide: 'FilterOptionRepository',
910
- useExisting: FilterOptionHasuraGraphQLRepository,
911
- },
912
- {
913
- provide: FilterOptionHasuraGraphQLRepository,
914
- useFactory: (options) => {
915
- return new FilterOptionHasuraGraphQLRepository(options);
916
- },
917
- deps: ['HasuraConfig'],
918
- },
919
- {
920
- provide: 'FilterRepository',
921
- useExisting: FilterHasuraGraphQLRepository,
922
- },
923
- {
924
- provide: FilterHasuraGraphQLRepository,
925
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
926
- return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
927
- },
928
- deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
929
- },
930
- {
931
- provide: CategoryCollectionChildrenHasuraGraphQLRepository,
932
- useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options),
933
- deps: ['HasuraConfig'],
934
- },
935
- {
936
- provide: 'CategoryCollectionChildrenRepository',
937
- useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
938
- },
939
- {
940
- provide: WishlistHasuraGraphQLRepository,
941
- useFactory: (options, categoryFilterRepository) => {
942
- return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
943
- },
944
- deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
945
- },
946
- {
947
- provide: 'WishlistRepository',
948
- useExisting: WishlistHasuraGraphQLRepository,
949
- },
950
- ],
951
- }]
181
+ class AngularFirestoreModule {
182
+ static initializeApp(options, nameOrConfig) {
183
+ return {
184
+ ngModule: AngularFirestoreModule,
185
+ providers: [
186
+ { provide: FIREBASE_OPTIONS, useValue: options.firebase },
187
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
188
+ { provide: ES_CONFIG, useValue: options.elasticSearch },
189
+ ],
190
+ };
191
+ }
192
+ }
193
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
194
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] });
195
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, providers: [
196
+ {
197
+ provide: 'FirestoreOptions',
198
+ useFactory: (firestore, platformId) => ({
199
+ firestore: new ConnectFirestoreService(firestore),
200
+ interceptors: {
201
+ request: (request) => {
202
+ if (isPlatformBrowser(platformId))
203
+ return request;
204
+ const interval = setInterval(() => { }, 100);
205
+ request.interval = interval;
206
+ return request;
207
+ },
208
+ response: (response, request) => {
209
+ if (isPlatformBrowser(platformId))
210
+ return response;
211
+ clearInterval(request.interval);
212
+ return response;
213
+ },
214
+ },
215
+ }),
216
+ deps: [Firestore, PLATFORM_ID],
217
+ },
218
+ {
219
+ provide: 'BeautyProfileRepository',
220
+ useFactory: (config, userRepository) => {
221
+ return new UserBeautyProfileFirestoreRepository(config, userRepository);
222
+ },
223
+ deps: ['FirestoreOptions', 'UserRepository'],
224
+ },
225
+ {
226
+ provide: 'Buy2WinRepository',
227
+ useFactory: (options) => {
228
+ return new Buy2WinFirestoreRepository(options);
229
+ },
230
+ deps: ['FirestoreOptions'],
231
+ },
232
+ {
233
+ provide: CategoryFirestoreRepository,
234
+ useFactory: (options) => {
235
+ return new CategoryFirestoreRepository(options);
236
+ },
237
+ deps: ['FirestoreOptions'],
238
+ },
239
+ {
240
+ provide: 'CheckoutRepository',
241
+ useFactory: (options) => {
242
+ return new CheckoutFirestoreRepository(options);
243
+ },
244
+ deps: ['FirestoreOptions'],
245
+ },
246
+ {
247
+ provide: 'CheckoutSubscriptionRepository',
248
+ useFactory: (options) => {
249
+ return new CheckoutSubscriptionFirestoreRepository(options);
250
+ },
251
+ deps: ['FirestoreOptions'],
252
+ },
253
+ {
254
+ provide: 'CouponRepository',
255
+ useFactory: (options) => {
256
+ return new CouponFirestoreRepository(options);
257
+ },
258
+ deps: ['FirestoreOptions'],
259
+ },
260
+ {
261
+ provide: 'CampaignHashtagRepository',
262
+ useFactory: (options) => {
263
+ return new CampaignHashtagFirestoreRepository(options);
264
+ },
265
+ deps: ['FirestoreOptions'],
266
+ },
267
+ {
268
+ provide: 'CampaignDashboardRepository',
269
+ useFactory: (options) => {
270
+ return new CampaignDashboardFirestoreRepository(options);
271
+ },
272
+ deps: ['FirestoreOptions'],
273
+ },
274
+ {
275
+ provide: 'EditionRepository',
276
+ useFactory: (options, subscriptionRepository) => {
277
+ return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
278
+ },
279
+ deps: ['FirestoreOptions', 'SubscriptionRepository'],
280
+ },
281
+ {
282
+ provide: 'HomeRepository',
283
+ useFactory: (options) => {
284
+ return new HomeFirestoreRepository(options);
285
+ },
286
+ deps: ['FirestoreOptions'],
287
+ },
288
+ {
289
+ provide: 'LeadRepository',
290
+ useFactory: (options) => {
291
+ return new LeadFirestoreRepository(options);
292
+ },
293
+ deps: ['FirestoreOptions'],
294
+ },
295
+ {
296
+ provide: 'LegacyOrderRepository',
297
+ useFactory: (options) => {
298
+ return new LegacyOrderFirestoreRepository(options);
299
+ },
300
+ deps: ['FirestoreOptions'],
301
+ },
302
+ {
303
+ provide: 'ShopMenuRepository',
304
+ useFactory: (options) => {
305
+ return new ShopMenuFirestoreRepository(options);
306
+ },
307
+ deps: ['FirestoreOptions'],
308
+ },
309
+ {
310
+ provide: 'OrderRepository',
311
+ useFactory: (options) => {
312
+ return new OrderFirestoreRepository(options);
313
+ },
314
+ deps: ['FirestoreOptions'],
315
+ },
316
+ {
317
+ provide: 'PaymentRepository',
318
+ useFactory: (options) => {
319
+ return new PaymentFirestoreRepository(options);
320
+ },
321
+ deps: ['FirestoreOptions'],
322
+ },
323
+ {
324
+ provide: ProductFirestoreRepository,
325
+ useFactory: (options) => {
326
+ return new ProductFirestoreRepository(options);
327
+ },
328
+ deps: ['FirestoreOptions'],
329
+ },
330
+ {
331
+ provide: 'ShopSettingsRepository',
332
+ useFactory: (options) => {
333
+ return new ShopSettingsFirestoreRepository(options);
334
+ },
335
+ deps: ['FirestoreOptions'],
336
+ },
337
+ {
338
+ provide: 'SubscriptionPaymentRepository',
339
+ useFactory: (options, subscriptionRepository) => {
340
+ return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
341
+ },
342
+ deps: ['FirestoreOptions', 'SubscriptionRepository'],
343
+ },
344
+ {
345
+ provide: 'SubscriptionPlanRepository',
346
+ useFactory: (options) => {
347
+ return new SubscriptionPlanFirestoreRepository(options);
348
+ },
349
+ deps: ['FirestoreOptions'],
350
+ },
351
+ {
352
+ provide: 'SubscriptionProductRepository',
353
+ useFactory: (options) => {
354
+ return new SubscriptionProductFirestoreRepository(options);
355
+ },
356
+ deps: ['FirestoreOptions'],
357
+ },
358
+ {
359
+ provide: 'SubscriptionRepository',
360
+ useFactory: (options) => {
361
+ return new SubscriptionFirestoreRepository(options);
362
+ },
363
+ deps: ['FirestoreOptions'],
364
+ },
365
+ {
366
+ provide: 'UserRepository',
367
+ useFactory: (options) => {
368
+ return new UserFirestoreRepository(options);
369
+ },
370
+ deps: ['FirestoreOptions'],
371
+ },
372
+ {
373
+ provide: 'UserAddressRepository',
374
+ useFactory: (options, userRepository) => {
375
+ return new UserAddressFirestoreRepository(options, userRepository);
376
+ },
377
+ deps: ['FirestoreOptions', 'UserRepository'],
378
+ },
379
+ {
380
+ provide: 'UserPaymentMethodRepository',
381
+ useFactory: (options, userRepository) => {
382
+ return new UserPaymentMethodFirestoreRepository(options, userRepository);
383
+ },
384
+ deps: ['FirestoreOptions', 'UserRepository'],
385
+ },
386
+ {
387
+ provide: 'SubscriptionMaterializationRepository',
388
+ useFactory: (options) => {
389
+ return new SubscriptionMaterializationFirestoreRepository(options);
390
+ },
391
+ deps: ['FirestoreOptions'],
392
+ },
393
+ {
394
+ provide: 'SubscriptionSummaryRepository',
395
+ useFactory: (options) => {
396
+ return new SubscriptionSummaryFirestoreRepository(options);
397
+ },
398
+ deps: ['FirestoreOptions'],
399
+ },
400
+ {
401
+ provide: ProductVariantFirestoreRepository,
402
+ useFactory: (options, productRepository) => {
403
+ return new ProductVariantFirestoreRepository(options, productRepository);
404
+ },
405
+ deps: ['FirestoreOptions', ProductFirestoreRepository],
406
+ },
407
+ {
408
+ provide: 'OrderBlockedRepository',
409
+ useFactory: (options) => {
410
+ return new OrderBlockedFirestoreRepository(options);
411
+ },
412
+ deps: ['FirestoreOptions'],
413
+ },
414
+ ], imports: [AngularElasticSeachModule,
415
+ provideFirestore((injector) => {
416
+ const platformId = injector.get(PLATFORM_ID);
417
+ if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
418
+ return initializeFirestore(injector.get(FirebaseApp), {
419
+ ignoreUndefinedProperties: true,
420
+ });
421
+ const firestore = initializeFirestore(injector.get(FirebaseApp), {
422
+ experimentalForceLongPolling: true,
423
+ ignoreUndefinedProperties: true,
424
+ localCache: memoryLocalCache(),
425
+ });
426
+ return firestore;
427
+ })] });
428
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirestoreModule, decorators: [{
429
+ type: NgModule,
430
+ args: [{
431
+ imports: [
432
+ AngularElasticSeachModule,
433
+ provideFirestore((injector) => {
434
+ const platformId = injector.get(PLATFORM_ID);
435
+ if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
436
+ return initializeFirestore(injector.get(FirebaseApp), {
437
+ ignoreUndefinedProperties: true,
438
+ });
439
+ const firestore = initializeFirestore(injector.get(FirebaseApp), {
440
+ experimentalForceLongPolling: true,
441
+ ignoreUndefinedProperties: true,
442
+ localCache: memoryLocalCache(),
443
+ });
444
+ return firestore;
445
+ }),
446
+ ],
447
+ providers: [
448
+ {
449
+ provide: 'FirestoreOptions',
450
+ useFactory: (firestore, platformId) => ({
451
+ firestore: new ConnectFirestoreService(firestore),
452
+ interceptors: {
453
+ request: (request) => {
454
+ if (isPlatformBrowser(platformId))
455
+ return request;
456
+ const interval = setInterval(() => { }, 100);
457
+ request.interval = interval;
458
+ return request;
459
+ },
460
+ response: (response, request) => {
461
+ if (isPlatformBrowser(platformId))
462
+ return response;
463
+ clearInterval(request.interval);
464
+ return response;
465
+ },
466
+ },
467
+ }),
468
+ deps: [Firestore, PLATFORM_ID],
469
+ },
470
+ {
471
+ provide: 'BeautyProfileRepository',
472
+ useFactory: (config, userRepository) => {
473
+ return new UserBeautyProfileFirestoreRepository(config, userRepository);
474
+ },
475
+ deps: ['FirestoreOptions', 'UserRepository'],
476
+ },
477
+ {
478
+ provide: 'Buy2WinRepository',
479
+ useFactory: (options) => {
480
+ return new Buy2WinFirestoreRepository(options);
481
+ },
482
+ deps: ['FirestoreOptions'],
483
+ },
484
+ {
485
+ provide: CategoryFirestoreRepository,
486
+ useFactory: (options) => {
487
+ return new CategoryFirestoreRepository(options);
488
+ },
489
+ deps: ['FirestoreOptions'],
490
+ },
491
+ {
492
+ provide: 'CheckoutRepository',
493
+ useFactory: (options) => {
494
+ return new CheckoutFirestoreRepository(options);
495
+ },
496
+ deps: ['FirestoreOptions'],
497
+ },
498
+ {
499
+ provide: 'CheckoutSubscriptionRepository',
500
+ useFactory: (options) => {
501
+ return new CheckoutSubscriptionFirestoreRepository(options);
502
+ },
503
+ deps: ['FirestoreOptions'],
504
+ },
505
+ {
506
+ provide: 'CouponRepository',
507
+ useFactory: (options) => {
508
+ return new CouponFirestoreRepository(options);
509
+ },
510
+ deps: ['FirestoreOptions'],
511
+ },
512
+ {
513
+ provide: 'CampaignHashtagRepository',
514
+ useFactory: (options) => {
515
+ return new CampaignHashtagFirestoreRepository(options);
516
+ },
517
+ deps: ['FirestoreOptions'],
518
+ },
519
+ {
520
+ provide: 'CampaignDashboardRepository',
521
+ useFactory: (options) => {
522
+ return new CampaignDashboardFirestoreRepository(options);
523
+ },
524
+ deps: ['FirestoreOptions'],
525
+ },
526
+ {
527
+ provide: 'EditionRepository',
528
+ useFactory: (options, subscriptionRepository) => {
529
+ return new SubscriptionEditionFirestoreRepository(options, subscriptionRepository);
530
+ },
531
+ deps: ['FirestoreOptions', 'SubscriptionRepository'],
532
+ },
533
+ {
534
+ provide: 'HomeRepository',
535
+ useFactory: (options) => {
536
+ return new HomeFirestoreRepository(options);
537
+ },
538
+ deps: ['FirestoreOptions'],
539
+ },
540
+ {
541
+ provide: 'LeadRepository',
542
+ useFactory: (options) => {
543
+ return new LeadFirestoreRepository(options);
544
+ },
545
+ deps: ['FirestoreOptions'],
546
+ },
547
+ {
548
+ provide: 'LegacyOrderRepository',
549
+ useFactory: (options) => {
550
+ return new LegacyOrderFirestoreRepository(options);
551
+ },
552
+ deps: ['FirestoreOptions'],
553
+ },
554
+ {
555
+ provide: 'ShopMenuRepository',
556
+ useFactory: (options) => {
557
+ return new ShopMenuFirestoreRepository(options);
558
+ },
559
+ deps: ['FirestoreOptions'],
560
+ },
561
+ {
562
+ provide: 'OrderRepository',
563
+ useFactory: (options) => {
564
+ return new OrderFirestoreRepository(options);
565
+ },
566
+ deps: ['FirestoreOptions'],
567
+ },
568
+ {
569
+ provide: 'PaymentRepository',
570
+ useFactory: (options) => {
571
+ return new PaymentFirestoreRepository(options);
572
+ },
573
+ deps: ['FirestoreOptions'],
574
+ },
575
+ {
576
+ provide: ProductFirestoreRepository,
577
+ useFactory: (options) => {
578
+ return new ProductFirestoreRepository(options);
579
+ },
580
+ deps: ['FirestoreOptions'],
581
+ },
582
+ {
583
+ provide: 'ShopSettingsRepository',
584
+ useFactory: (options) => {
585
+ return new ShopSettingsFirestoreRepository(options);
586
+ },
587
+ deps: ['FirestoreOptions'],
588
+ },
589
+ {
590
+ provide: 'SubscriptionPaymentRepository',
591
+ useFactory: (options, subscriptionRepository) => {
592
+ return new SubscriptionPaymentFirestoreRepository(options, subscriptionRepository);
593
+ },
594
+ deps: ['FirestoreOptions', 'SubscriptionRepository'],
595
+ },
596
+ {
597
+ provide: 'SubscriptionPlanRepository',
598
+ useFactory: (options) => {
599
+ return new SubscriptionPlanFirestoreRepository(options);
600
+ },
601
+ deps: ['FirestoreOptions'],
602
+ },
603
+ {
604
+ provide: 'SubscriptionProductRepository',
605
+ useFactory: (options) => {
606
+ return new SubscriptionProductFirestoreRepository(options);
607
+ },
608
+ deps: ['FirestoreOptions'],
609
+ },
610
+ {
611
+ provide: 'SubscriptionRepository',
612
+ useFactory: (options) => {
613
+ return new SubscriptionFirestoreRepository(options);
614
+ },
615
+ deps: ['FirestoreOptions'],
616
+ },
617
+ {
618
+ provide: 'UserRepository',
619
+ useFactory: (options) => {
620
+ return new UserFirestoreRepository(options);
621
+ },
622
+ deps: ['FirestoreOptions'],
623
+ },
624
+ {
625
+ provide: 'UserAddressRepository',
626
+ useFactory: (options, userRepository) => {
627
+ return new UserAddressFirestoreRepository(options, userRepository);
628
+ },
629
+ deps: ['FirestoreOptions', 'UserRepository'],
630
+ },
631
+ {
632
+ provide: 'UserPaymentMethodRepository',
633
+ useFactory: (options, userRepository) => {
634
+ return new UserPaymentMethodFirestoreRepository(options, userRepository);
635
+ },
636
+ deps: ['FirestoreOptions', 'UserRepository'],
637
+ },
638
+ {
639
+ provide: 'SubscriptionMaterializationRepository',
640
+ useFactory: (options) => {
641
+ return new SubscriptionMaterializationFirestoreRepository(options);
642
+ },
643
+ deps: ['FirestoreOptions'],
644
+ },
645
+ {
646
+ provide: 'SubscriptionSummaryRepository',
647
+ useFactory: (options) => {
648
+ return new SubscriptionSummaryFirestoreRepository(options);
649
+ },
650
+ deps: ['FirestoreOptions'],
651
+ },
652
+ {
653
+ provide: ProductVariantFirestoreRepository,
654
+ useFactory: (options, productRepository) => {
655
+ return new ProductVariantFirestoreRepository(options, productRepository);
656
+ },
657
+ deps: ['FirestoreOptions', ProductFirestoreRepository],
658
+ },
659
+ {
660
+ provide: 'OrderBlockedRepository',
661
+ useFactory: (options) => {
662
+ return new OrderBlockedFirestoreRepository(options);
663
+ },
664
+ deps: ['FirestoreOptions'],
665
+ },
666
+ ],
667
+ }]
952
668
  }] });
953
669
 
954
- class AngularVertexSeachModule {
955
- static initializeApp(options) {
956
- return {
957
- ngModule: AngularVertexSeachModule,
958
- providers: [{ provide: VERTEX_CONFIG, useValue: options }],
959
- };
960
- }
961
- }
962
- AngularVertexSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularVertexSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
963
- AngularVertexSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularVertexSeachModule });
964
- AngularVertexSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularVertexSeachModule, providers: [
965
- {
966
- provide: ProductsVertexSearch,
967
- useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
968
- deps: [VERTEX_CONFIG],
969
- },
970
- ] });
971
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularVertexSeachModule, decorators: [{
972
- type: NgModule,
973
- args: [{
974
- providers: [
975
- {
976
- provide: ProductsVertexSearch,
977
- useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
978
- deps: [VERTEX_CONFIG],
979
- },
980
- ],
981
- }]
670
+ class AngularHasuraGraphQLModule {
671
+ static initializeApp(options) {
672
+ return {
673
+ ngModule: AngularHasuraGraphQLModule,
674
+ providers: [{ provide: HASURA_OPTIONS, useValue: options }],
675
+ };
676
+ }
677
+ }
678
+ AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
679
+ AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule });
680
+ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
681
+ {
682
+ provide: 'HasuraConfig',
683
+ useFactory: (options, platformId) => ({
684
+ endpoint: options.endpoint,
685
+ authOptions: options.credentials,
686
+ interceptors: {
687
+ request: (request) => {
688
+ if (isPlatformBrowser(platformId))
689
+ return request;
690
+ const interval = setInterval(() => { }, 100);
691
+ request.interval = interval;
692
+ return request;
693
+ },
694
+ response: (response, request) => {
695
+ if (isPlatformBrowser(platformId))
696
+ return response;
697
+ clearInterval(request.interval);
698
+ return response;
699
+ },
700
+ },
701
+ }),
702
+ deps: [HASURA_OPTIONS, PLATFORM_ID],
703
+ },
704
+ {
705
+ provide: 'CategoryRepository',
706
+ useExisting: CategoryHasuraGraphQLRepository,
707
+ },
708
+ {
709
+ provide: CategoryHasuraGraphQLRepository,
710
+ useFactory: (options, productRepository, categoryFilterRepository) => {
711
+ return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
712
+ },
713
+ deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
714
+ },
715
+ {
716
+ provide: 'ProductRepository',
717
+ useExisting: ProductHasuraGraphQLRepository,
718
+ },
719
+ {
720
+ provide: ProductHasuraGraphQLRepository,
721
+ useFactory: (hasuraConfig) => {
722
+ return new ProductHasuraGraphQLRepository(hasuraConfig);
723
+ },
724
+ deps: ['HasuraConfig'],
725
+ },
726
+ {
727
+ provide: 'ProductReviewsRepository',
728
+ useExisting: ProductReviewsHasuraGraphQLRepository,
729
+ },
730
+ {
731
+ provide: ProductReviewsHasuraGraphQLRepository,
732
+ useFactory: (hasuraConfig) => {
733
+ return new ProductReviewsHasuraGraphQLRepository(hasuraConfig);
734
+ },
735
+ deps: ['HasuraConfig'],
736
+ },
737
+ {
738
+ provide: 'VariantRepository',
739
+ useExisting: VariantHasuraGraphQLRepository,
740
+ },
741
+ {
742
+ provide: VariantHasuraGraphQLRepository,
743
+ useFactory: (hasuraConfig) => {
744
+ return new VariantHasuraGraphQLRepository(hasuraConfig);
745
+ },
746
+ deps: ['HasuraConfig'],
747
+ },
748
+ {
749
+ provide: 'ProductStockNotificationRepository',
750
+ useExisting: ProductStockNotificationHasuraGraphQLRepository,
751
+ },
752
+ {
753
+ provide: ProductStockNotificationHasuraGraphQLRepository,
754
+ useFactory: (hasuraConfig) => {
755
+ return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
756
+ },
757
+ deps: ['HasuraConfig'],
758
+ },
759
+ {
760
+ provide: 'CategoryFilterRepository',
761
+ useExisting: CategoryFilterHasuraGraphQLRepository,
762
+ },
763
+ {
764
+ provide: CategoryFilterHasuraGraphQLRepository,
765
+ useFactory: (options) => {
766
+ return new CategoryFilterHasuraGraphQLRepository(options);
767
+ },
768
+ deps: ['HasuraConfig'],
769
+ },
770
+ {
771
+ provide: 'FilterOptionRepository',
772
+ useExisting: FilterOptionHasuraGraphQLRepository,
773
+ },
774
+ {
775
+ provide: FilterOptionHasuraGraphQLRepository,
776
+ useFactory: (options) => {
777
+ return new FilterOptionHasuraGraphQLRepository(options);
778
+ },
779
+ deps: ['HasuraConfig'],
780
+ },
781
+ {
782
+ provide: 'FilterRepository',
783
+ useExisting: FilterHasuraGraphQLRepository,
784
+ },
785
+ {
786
+ provide: FilterHasuraGraphQLRepository,
787
+ useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
788
+ return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
789
+ },
790
+ deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
791
+ },
792
+ {
793
+ provide: CategoryCollectionChildrenHasuraGraphQLRepository,
794
+ useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options),
795
+ deps: ['HasuraConfig'],
796
+ },
797
+ {
798
+ provide: 'CategoryCollectionChildrenRepository',
799
+ useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
800
+ },
801
+ {
802
+ provide: WishlistHasuraGraphQLRepository,
803
+ useFactory: (options, categoryFilterRepository) => {
804
+ return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
805
+ },
806
+ deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
807
+ },
808
+ {
809
+ provide: 'WishlistRepository',
810
+ useExisting: WishlistHasuraGraphQLRepository,
811
+ },
812
+ ] });
813
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
814
+ type: NgModule,
815
+ args: [{
816
+ providers: [
817
+ {
818
+ provide: 'HasuraConfig',
819
+ useFactory: (options, platformId) => ({
820
+ endpoint: options.endpoint,
821
+ authOptions: options.credentials,
822
+ interceptors: {
823
+ request: (request) => {
824
+ if (isPlatformBrowser(platformId))
825
+ return request;
826
+ const interval = setInterval(() => { }, 100);
827
+ request.interval = interval;
828
+ return request;
829
+ },
830
+ response: (response, request) => {
831
+ if (isPlatformBrowser(platformId))
832
+ return response;
833
+ clearInterval(request.interval);
834
+ return response;
835
+ },
836
+ },
837
+ }),
838
+ deps: [HASURA_OPTIONS, PLATFORM_ID],
839
+ },
840
+ {
841
+ provide: 'CategoryRepository',
842
+ useExisting: CategoryHasuraGraphQLRepository,
843
+ },
844
+ {
845
+ provide: CategoryHasuraGraphQLRepository,
846
+ useFactory: (options, productRepository, categoryFilterRepository) => {
847
+ return new CategoryHasuraGraphQLRepository(options, productRepository, categoryFilterRepository);
848
+ },
849
+ deps: ['HasuraConfig', ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
850
+ },
851
+ {
852
+ provide: 'ProductRepository',
853
+ useExisting: ProductHasuraGraphQLRepository,
854
+ },
855
+ {
856
+ provide: ProductHasuraGraphQLRepository,
857
+ useFactory: (hasuraConfig) => {
858
+ return new ProductHasuraGraphQLRepository(hasuraConfig);
859
+ },
860
+ deps: ['HasuraConfig'],
861
+ },
862
+ {
863
+ provide: 'ProductReviewsRepository',
864
+ useExisting: ProductReviewsHasuraGraphQLRepository,
865
+ },
866
+ {
867
+ provide: ProductReviewsHasuraGraphQLRepository,
868
+ useFactory: (hasuraConfig) => {
869
+ return new ProductReviewsHasuraGraphQLRepository(hasuraConfig);
870
+ },
871
+ deps: ['HasuraConfig'],
872
+ },
873
+ {
874
+ provide: 'VariantRepository',
875
+ useExisting: VariantHasuraGraphQLRepository,
876
+ },
877
+ {
878
+ provide: VariantHasuraGraphQLRepository,
879
+ useFactory: (hasuraConfig) => {
880
+ return new VariantHasuraGraphQLRepository(hasuraConfig);
881
+ },
882
+ deps: ['HasuraConfig'],
883
+ },
884
+ {
885
+ provide: 'ProductStockNotificationRepository',
886
+ useExisting: ProductStockNotificationHasuraGraphQLRepository,
887
+ },
888
+ {
889
+ provide: ProductStockNotificationHasuraGraphQLRepository,
890
+ useFactory: (hasuraConfig) => {
891
+ return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
892
+ },
893
+ deps: ['HasuraConfig'],
894
+ },
895
+ {
896
+ provide: 'CategoryFilterRepository',
897
+ useExisting: CategoryFilterHasuraGraphQLRepository,
898
+ },
899
+ {
900
+ provide: CategoryFilterHasuraGraphQLRepository,
901
+ useFactory: (options) => {
902
+ return new CategoryFilterHasuraGraphQLRepository(options);
903
+ },
904
+ deps: ['HasuraConfig'],
905
+ },
906
+ {
907
+ provide: 'FilterOptionRepository',
908
+ useExisting: FilterOptionHasuraGraphQLRepository,
909
+ },
910
+ {
911
+ provide: FilterOptionHasuraGraphQLRepository,
912
+ useFactory: (options) => {
913
+ return new FilterOptionHasuraGraphQLRepository(options);
914
+ },
915
+ deps: ['HasuraConfig'],
916
+ },
917
+ {
918
+ provide: 'FilterRepository',
919
+ useExisting: FilterHasuraGraphQLRepository,
920
+ },
921
+ {
922
+ provide: FilterHasuraGraphQLRepository,
923
+ useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
924
+ return new FilterHasuraGraphQLRepository(options, filterOptionRepository, categoryFilterRepository);
925
+ },
926
+ deps: ['HasuraConfig', FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
927
+ },
928
+ {
929
+ provide: CategoryCollectionChildrenHasuraGraphQLRepository,
930
+ useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options),
931
+ deps: ['HasuraConfig'],
932
+ },
933
+ {
934
+ provide: 'CategoryCollectionChildrenRepository',
935
+ useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
936
+ },
937
+ {
938
+ provide: WishlistHasuraGraphQLRepository,
939
+ useFactory: (options, categoryFilterRepository) => {
940
+ return new WishlistHasuraGraphQLRepository(options, categoryFilterRepository);
941
+ },
942
+ deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
943
+ },
944
+ {
945
+ provide: 'WishlistRepository',
946
+ useExisting: WishlistHasuraGraphQLRepository,
947
+ },
948
+ ],
949
+ }]
982
950
  }] });
983
951
 
984
952
  const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
985
953
 
986
- class CookieDataPersistence {
987
- get(key) {
988
- return of(cookie.get(key));
989
- }
990
- remove(key) {
991
- return of(cookie.remove(key));
992
- }
993
- set(key, value) {
994
- return from(cookie.set(key, value)).pipe(map(() => { }));
995
- }
996
- }
997
- CookieDataPersistence.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
998
- CookieDataPersistence.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence });
999
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence, decorators: [{
1000
- type: Injectable
954
+ class CookieDataPersistence {
955
+ get(key) {
956
+ return of(cookie.get(key));
957
+ }
958
+ remove(key) {
959
+ return of(cookie.remove(key));
960
+ }
961
+ set(key, value) {
962
+ return from(cookie.set(key, value)).pipe(map(() => { }));
963
+ }
964
+ }
965
+ CookieDataPersistence.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
966
+ CookieDataPersistence.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence });
967
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence, decorators: [{
968
+ type: Injectable
1001
969
  }] });
1002
970
 
1003
- class AuthService {
1004
- constructor(angularFireAuth, userRepository) {
1005
- this.angularFireAuth = angularFireAuth;
1006
- this.userRepository = userRepository;
1007
- }
1008
- getAuthstate() {
1009
- const observables = [this.getFireUser(), this.getUser()];
1010
- return combineLatest(observables).pipe(map(([fireUser, user]) => ({
1011
- user,
1012
- isAnonymous: fireUser?.isAnonymous,
1013
- })));
1014
- }
1015
- getUser() {
1016
- return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
1017
- }
1018
- getTokenId() {
1019
- return from(getIdToken(this.angularFireAuth.currentUser));
1020
- }
1021
- getFireUser() {
1022
- return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
1023
- }
1024
- }
1025
- 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 });
1026
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
1027
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
1028
- type: Injectable
1029
- }], ctorParameters: function () { return [{ type: i1.Auth }, { type: undefined, decorators: [{
1030
- type: Inject,
1031
- args: ['UserRepository']
971
+ class AuthService {
972
+ constructor(angularFireAuth, userRepository) {
973
+ this.angularFireAuth = angularFireAuth;
974
+ this.userRepository = userRepository;
975
+ }
976
+ getAuthstate() {
977
+ const observables = [this.getFireUser(), this.getUser()];
978
+ return combineLatest(observables).pipe(map(([fireUser, user]) => ({
979
+ user,
980
+ isAnonymous: fireUser?.isAnonymous,
981
+ })));
982
+ }
983
+ getUser() {
984
+ return this.getFireUser().pipe(map((user) => user?.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
985
+ }
986
+ getTokenId() {
987
+ return from(getIdToken(this.angularFireAuth.currentUser));
988
+ }
989
+ getFireUser() {
990
+ return authState(this.angularFireAuth).pipe(catchError(() => of(null)));
991
+ }
992
+ }
993
+ 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 });
994
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService });
995
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AuthService, decorators: [{
996
+ type: Injectable
997
+ }], ctorParameters: function () { return [{ type: i1.Auth }, { type: undefined, decorators: [{
998
+ type: Inject,
999
+ args: ['UserRepository']
1032
1000
  }] }]; } });
1033
1001
 
1034
- class CouponService {
1035
- constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
1036
- this.couponRepository = couponRepository;
1037
- this.defaultShop = defaultShop;
1038
- this.orderRepository = orderRepository;
1039
- this.categoryRepository = categoryRepository;
1040
- this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
1041
- }
1042
- checkCoupon(nickname, checkoutType, checkout, plan) {
1043
- return from(this.couponRepository
1044
- .find({
1045
- filters: {
1046
- nickname: { operator: Where.EQUALS, value: nickname },
1047
- active: { operator: Where.EQUALS, value: true },
1048
- },
1049
- })
1050
- .then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
1051
- }
1052
- async couponValidation(coupon, checkoutType) {
1053
- if (!coupon)
1054
- throw 'Cupom inválido.';
1055
- if (coupon?.beginAt && coupon?.beginAt.getTime() > new Date().getTime())
1056
- throw 'Cupom inválido.';
1057
- if (coupon?.expiresIn && coupon?.expiresIn.getTime() < new Date().getTime())
1058
- throw 'Cupom expirado.';
1059
- const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
1060
- if (!isInShop)
1061
- throw 'Cupom inválido para loja.';
1062
- const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
1063
- if (!isCheckoutType)
1064
- throw 'Cupom inválido. Erro de checkout.';
1065
- return coupon;
1066
- }
1067
- async couponRulesValidation(coupon, checkoutType, checkout, plan) {
1068
- if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
1069
- if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
1070
- throw 'Cupom inválido para sua assinatura.';
1071
- return coupon;
1072
- }
1073
- const validUser = this.coupomUserValidation(coupon, checkout?.user);
1074
- if (!validUser)
1075
- throw 'Usuário não elegível.';
1076
- const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
1077
- if (couponUseLimits.firstOrder) {
1078
- const ordersUser = await this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
1079
- if (couponUseLimits.firstOrder && ordersUser.length >= 1)
1080
- throw 'Limite de uso atingido';
1081
- }
1082
- if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
1083
- const orders = await this.getOrdersWithCoupon(coupon);
1084
- if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
1085
- throw 'Limite de uso atingido.';
1086
- if (couponUseLimits.limitedPerUser) {
1087
- const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
1088
- if (ordersWithUser > 0)
1089
- throw 'Limite de uso por usuário atingido.';
1090
- }
1091
- }
1092
- const hasProductCategories = await this.hasProductCategories(coupon, checkout);
1093
- if (!hasProductCategories)
1094
- throw 'Seu carrinho não possui produtos elegíveis para desconto.';
1095
- const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
1096
- if (!hasMinSubTotal)
1097
- throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`;
1098
- return coupon;
1099
- }
1100
- calcDiscountSubscription(coupon, checkout) {
1101
- let discount = 0;
1102
- if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
1103
- discount = coupon.discount.subscription.value;
1104
- else
1105
- discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
1106
- return of(discount);
1107
- }
1108
- async calcDiscountShopping(coupon, checkout) {
1109
- let discountInfo = null;
1110
- if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
1111
- discountInfo = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1112
- }
1113
- else {
1114
- discountInfo = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1115
- }
1116
- return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
1117
- }
1118
- async calcDiscountByType(type, value, categories, checkout) {
1119
- let discount = 0;
1120
- let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1121
- const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
1122
- if (type == CouponTypes.ABSOLUTE) {
1123
- discount = value > subTotal ? subTotal : value;
1124
- }
1125
- else {
1126
- discount = subTotal * (value / 100);
1127
- }
1128
- const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1129
- return { discount, lineItems };
1130
- }
1131
- async hasMinSubTotal(coupon, checkout) {
1132
- if (!coupon.minSubTotalValue)
1133
- return true;
1134
- let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1135
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
1136
- if (coupon.minSubTotalValue <= subTotal)
1137
- return true;
1138
- return false;
1139
- }
1140
- async hasProductCategories(coupon, checkout) {
1141
- if (!coupon.productsCategories || !coupon.productsCategories.length) {
1142
- return true;
1143
- }
1144
- const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
1145
- const hasCategories = checkout.lineItems?.filter((i) => {
1146
- if (!i.categories || !i.categories?.length)
1147
- return true;
1148
- return i.categories.some((c) => couponCategories.some((cat) => cat == c));
1149
- });
1150
- return hasCategories.length ? true : false;
1151
- }
1152
- coupomUserValidation(coupon, user) {
1153
- if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
1154
- return true;
1155
- let userTypes = [];
1156
- if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
1157
- this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
1158
- userTypes.push(Exclusivities.COLLABORATORS);
1159
- if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
1160
- coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
1161
- userTypes.push(Exclusivities.SPECIFIC_USER);
1162
- if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
1163
- user.isSubscriber &&
1164
- user.subscriptionPlan != '')
1165
- userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
1166
- if (user.isSubscriber &&
1167
- user.subscriptionPlan == '' &&
1168
- coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
1169
- userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
1170
- if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
1171
- userTypes.push(Exclusivities.NON_SUBSCRIBER);
1172
- return coupon.exclusivityType.some((r) => userTypes.includes(r));
1173
- }
1174
- async getCouponCategoriesId(productsCategories) {
1175
- const couponCategories = [];
1176
- for (let index = 0; index < productsCategories.length; index++) {
1177
- const category = await this.categoryRepository.get({
1178
- id: productsCategories[index],
1179
- });
1180
- if (category) {
1181
- const children = await this.categoryRepository.getChildren(parseInt(productsCategories[index]));
1182
- couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
1183
- }
1184
- }
1185
- return [...new Set(couponCategories)];
1186
- }
1187
- async getLineItensEligebleForDiscount(productsCategories, checkout) {
1188
- let lineItensDiscount = [];
1189
- const couponCategories = await this.getCouponCategoriesId(productsCategories);
1190
- if (productsCategories && productsCategories.length) {
1191
- lineItensDiscount = checkout.lineItems?.filter((i) => {
1192
- if (i.categories?.length) {
1193
- return i.categories.some((c) => couponCategories.some((cat) => cat == c));
1194
- }
1195
- return true;
1196
- });
1197
- }
1198
- else {
1199
- lineItensDiscount = checkout.lineItems;
1200
- }
1201
- return lineItensDiscount;
1202
- }
1203
- calcCheckoutSubtotal(lineItens, user) {
1204
- return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1205
- ? acc + curr.price?.subscriberPrice * curr.quantity
1206
- : acc + curr.pricePaid * curr.quantity, 0) || 0);
1207
- }
1208
- async getOrdersWithCoupon(coupon) {
1209
- return await this.orderRepository
1210
- .find({
1211
- filters: {
1212
- coupon: { id: coupon.id },
1213
- payment: { status: 'paid' },
1214
- },
1215
- })
1216
- .then((result) => result.data);
1217
- }
1218
- async getOrdersFromUser(email) {
1219
- return await this.orderRepository
1220
- .find({
1221
- filters: {
1222
- user: { email: { operator: Where.EQUALS, value: email } },
1223
- payment: { status: 'paid' },
1224
- },
1225
- })
1226
- .then((result) => result.data);
1227
- }
1228
- countOrdersWithUser(orders, email) {
1229
- return orders.filter((o) => o.user.email == email).length;
1230
- }
1231
- getCouponUseLimits(coupon, checkoutType, user) {
1232
- let couponUseLimits;
1233
- if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
1234
- couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
1235
- }
1236
- else {
1237
- couponUseLimits = coupon.useLimits.subscription;
1238
- }
1239
- return couponUseLimits;
1240
- }
1241
- calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
1242
- let lineItemsDiscount = [];
1243
- if (type === CouponTypes.ABSOLUTE) {
1244
- const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
1245
- lineItemsDiscount = lineItems.map((item) => {
1246
- const totalItemPercentage = item.pricePaid / subTotal;
1247
- const discountItem = couponDiscountMax * totalItemPercentage;
1248
- return {
1249
- ...item,
1250
- discount: Number(discountItem.toFixed(2)),
1251
- };
1252
- });
1253
- }
1254
- else {
1255
- lineItemsDiscount = lineItems.map((item) => {
1256
- const discountItem = item.pricePaid * (couponDiscount / 100);
1257
- return {
1258
- ...item,
1259
- discount: Number(discountItem.toFixed(2)),
1260
- };
1261
- });
1262
- }
1263
- return lineItemsDiscount;
1264
- }
1265
- }
1266
- 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 });
1267
- CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
1268
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
1269
- type: Injectable,
1270
- args: [{
1271
- providedIn: 'root',
1272
- }]
1273
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1274
- type: Inject,
1275
- args: ['CouponRepository']
1276
- }] }, { type: i1$2.Shops, decorators: [{
1277
- type: Inject,
1278
- args: [DEFAULT_SHOP]
1279
- }] }, { type: undefined, decorators: [{
1280
- type: Inject,
1281
- args: ['OrderRepository']
1282
- }] }, { type: undefined, decorators: [{
1283
- type: Inject,
1284
- args: ['CategoryRepository']
1002
+ class CouponService {
1003
+ constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
1004
+ this.couponRepository = couponRepository;
1005
+ this.defaultShop = defaultShop;
1006
+ this.orderRepository = orderRepository;
1007
+ this.categoryRepository = categoryRepository;
1008
+ this.emailIsFromCollaborator = (userEmail) => !!userEmail?.match(/@b4a.com.br/g);
1009
+ }
1010
+ checkCoupon(nickname, checkoutType, checkout, plan) {
1011
+ return from(this.couponRepository
1012
+ .find({
1013
+ filters: {
1014
+ nickname: { operator: Where.EQUALS, value: nickname },
1015
+ active: { operator: Where.EQUALS, value: true },
1016
+ },
1017
+ })
1018
+ .then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
1019
+ }
1020
+ async couponValidation(coupon, checkoutType) {
1021
+ if (!coupon)
1022
+ throw 'Cupom inválido.';
1023
+ if (coupon?.beginAt && coupon?.beginAt.getTime() > new Date().getTime())
1024
+ throw 'Cupom inválido.';
1025
+ if (coupon?.expiresIn && coupon?.expiresIn.getTime() < new Date().getTime())
1026
+ throw 'Cupom expirado.';
1027
+ const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
1028
+ if (!isInShop)
1029
+ throw 'Cupom inválido para loja.';
1030
+ const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
1031
+ if (!isCheckoutType)
1032
+ throw 'Cupom inválido. Erro de checkout.';
1033
+ return coupon;
1034
+ }
1035
+ async couponRulesValidation(coupon, checkoutType, checkout, plan) {
1036
+ if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
1037
+ if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
1038
+ throw 'Cupom inválido para sua assinatura.';
1039
+ return coupon;
1040
+ }
1041
+ const validUser = this.coupomUserValidation(coupon, checkout?.user);
1042
+ if (!validUser)
1043
+ throw 'Usuário não elegível.';
1044
+ const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
1045
+ if (couponUseLimits.firstOrder) {
1046
+ const ordersUser = await this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
1047
+ if (couponUseLimits.firstOrder && ordersUser.length >= 1)
1048
+ throw 'Limite de uso atingido';
1049
+ }
1050
+ if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
1051
+ const ordersCoupon = await this.getOrdersWithCoupon(coupon);
1052
+ if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
1053
+ throw 'Limite de uso atingido.';
1054
+ if (couponUseLimits.limitedPerUser) {
1055
+ const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
1056
+ if (ordersWithUser > 0)
1057
+ throw 'Limite de uso por usuário atingido.';
1058
+ }
1059
+ }
1060
+ const hasProductCategories = await this.hasProductCategories(coupon, checkout);
1061
+ if (!hasProductCategories)
1062
+ throw 'Seu carrinho não possui produtos elegíveis para desconto.';
1063
+ const hasMinSubTotal = await this.hasMinSubTotal(coupon, checkout);
1064
+ if (!hasMinSubTotal)
1065
+ throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`;
1066
+ return coupon;
1067
+ }
1068
+ calcDiscountSubscription(coupon, checkout) {
1069
+ let discount = 0;
1070
+ if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
1071
+ discount = coupon.discount.subscription.value;
1072
+ else
1073
+ discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
1074
+ return of(discount);
1075
+ }
1076
+ async calcDiscountShopping(coupon, checkout) {
1077
+ let discountInfo = null;
1078
+ if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
1079
+ discountInfo = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1080
+ }
1081
+ else {
1082
+ discountInfo = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1083
+ }
1084
+ return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
1085
+ }
1086
+ async calcDiscountByType(type, value, categories, checkout) {
1087
+ let discount = 0;
1088
+ let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1089
+ const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
1090
+ if (type == CouponTypes.ABSOLUTE) {
1091
+ discount = value > subTotal ? subTotal : value;
1092
+ }
1093
+ else {
1094
+ discount = subTotal * (value / 100);
1095
+ }
1096
+ const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1097
+ return { discount, lineItems };
1098
+ }
1099
+ async hasMinSubTotal(coupon, checkout) {
1100
+ if (!coupon.minSubTotalValue)
1101
+ return true;
1102
+ let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1103
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
1104
+ if (coupon.minSubTotalValue <= subTotal)
1105
+ return true;
1106
+ return false;
1107
+ }
1108
+ async hasProductCategories(coupon, checkout) {
1109
+ if (!coupon.productsCategories || !coupon.productsCategories.length) {
1110
+ return true;
1111
+ }
1112
+ const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
1113
+ const hasCategories = checkout.lineItems?.filter((i) => {
1114
+ if (!i.categories || !i.categories?.length)
1115
+ return true;
1116
+ return i.categories.some((c) => couponCategories.some((cat) => cat == c));
1117
+ });
1118
+ return hasCategories.length ? true : false;
1119
+ }
1120
+ coupomUserValidation(coupon, user) {
1121
+ if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
1122
+ return true;
1123
+ let userTypes = [];
1124
+ if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
1125
+ this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
1126
+ userTypes.push(Exclusivities.COLLABORATORS);
1127
+ if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
1128
+ coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
1129
+ userTypes.push(Exclusivities.SPECIFIC_USER);
1130
+ if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
1131
+ user.isSubscriber &&
1132
+ user.subscriptionPlan != '')
1133
+ userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
1134
+ if (user.isSubscriber &&
1135
+ user.subscriptionPlan == '' &&
1136
+ coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
1137
+ userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
1138
+ if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
1139
+ userTypes.push(Exclusivities.NON_SUBSCRIBER);
1140
+ return coupon.exclusivityType.some((r) => userTypes.includes(r));
1141
+ }
1142
+ async getCouponCategoriesId(productsCategories) {
1143
+ const couponCategories = [];
1144
+ for (let index = 0; index < productsCategories.length; index++) {
1145
+ const category = await this.categoryRepository.get({
1146
+ id: productsCategories[index],
1147
+ });
1148
+ if (category) {
1149
+ const children = await this.categoryRepository.getChildren(parseInt(productsCategories[index]));
1150
+ couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
1151
+ }
1152
+ }
1153
+ return [...new Set(couponCategories)];
1154
+ }
1155
+ async getLineItensEligebleForDiscount(productsCategories, checkout) {
1156
+ let lineItensDiscount = [];
1157
+ const couponCategories = await this.getCouponCategoriesId(productsCategories);
1158
+ if (productsCategories && productsCategories.length) {
1159
+ lineItensDiscount = checkout.lineItems?.filter((i) => {
1160
+ if (i.categories?.length) {
1161
+ return i.categories.some((c) => couponCategories.some((cat) => cat == c));
1162
+ }
1163
+ return true;
1164
+ });
1165
+ }
1166
+ else {
1167
+ lineItensDiscount = checkout.lineItems;
1168
+ }
1169
+ return lineItensDiscount;
1170
+ }
1171
+ calcCheckoutSubtotal(lineItens, user) {
1172
+ return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1173
+ ? acc + curr.price?.subscriberPrice * curr.quantity
1174
+ : acc + curr.pricePaid * curr.quantity, 0) || 0);
1175
+ }
1176
+ async getOrdersWithCoupon(coupon) {
1177
+ return await this.orderRepository
1178
+ .find({
1179
+ filters: {
1180
+ coupon: { id: coupon.id },
1181
+ status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
1182
+ },
1183
+ })
1184
+ .then((result) => result.data);
1185
+ }
1186
+ async getOrdersFromUser(email) {
1187
+ return await this.orderRepository
1188
+ .find({
1189
+ filters: {
1190
+ user: { email: { operator: Where.EQUALS, value: email } },
1191
+ status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
1192
+ },
1193
+ })
1194
+ .then((result) => result.data);
1195
+ }
1196
+ countOrdersWithUser(orders, email) {
1197
+ return orders.filter((o) => o.user.email == email).length;
1198
+ }
1199
+ getCouponUseLimits(coupon, checkoutType, user) {
1200
+ let couponUseLimits;
1201
+ if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
1202
+ if (coupon.exclusivityType.length === 1 &&
1203
+ (coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
1204
+ coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
1205
+ couponUseLimits = coupon.useLimits.non_subscriber;
1206
+ else
1207
+ couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
1208
+ }
1209
+ else {
1210
+ couponUseLimits = coupon.useLimits.subscription;
1211
+ }
1212
+ return couponUseLimits;
1213
+ }
1214
+ calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
1215
+ let lineItemsDiscount = [];
1216
+ if (type === CouponTypes.ABSOLUTE) {
1217
+ const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
1218
+ lineItemsDiscount = lineItems.map((item) => {
1219
+ const totalItemPercentage = item.pricePaid / subTotal;
1220
+ const discountItem = couponDiscountMax * totalItemPercentage;
1221
+ return {
1222
+ ...item,
1223
+ discount: Number(discountItem.toFixed(2)),
1224
+ };
1225
+ });
1226
+ }
1227
+ else {
1228
+ lineItemsDiscount = lineItems.map((item) => {
1229
+ const discountItem = item.pricePaid * (couponDiscount / 100);
1230
+ return {
1231
+ ...item,
1232
+ discount: Number(discountItem.toFixed(2)),
1233
+ };
1234
+ });
1235
+ }
1236
+ return lineItemsDiscount;
1237
+ }
1238
+ }
1239
+ 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 });
1240
+ CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
1241
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
1242
+ type: Injectable,
1243
+ args: [{
1244
+ providedIn: 'root',
1245
+ }]
1246
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1247
+ type: Inject,
1248
+ args: ['CouponRepository']
1249
+ }] }, { type: i1$2.Shops, decorators: [{
1250
+ type: Inject,
1251
+ args: [DEFAULT_SHOP]
1252
+ }] }, { type: undefined, decorators: [{
1253
+ type: Inject,
1254
+ args: ['OrderRepository']
1255
+ }] }, { type: undefined, decorators: [{
1256
+ type: Inject,
1257
+ args: ['CategoryRepository']
1285
1258
  }] }]; } });
1286
1259
 
1287
- class CheckoutService {
1288
- constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1289
- this.couponService = couponService;
1290
- this.checkoutRepository = checkoutRepository;
1291
- this.userRepository = userRepository;
1292
- this.defaultShop = defaultShop;
1293
- this.dataPersistence = dataPersistence;
1294
- }
1295
- getCheckout(checkoutData) {
1296
- return this.dataPersistence
1297
- .get('checkoutId')
1298
- .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
1299
- }
1300
- getUserByCheckout(checkoutId) {
1301
- return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id }))), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
1302
- }
1303
- updateCheckoutLineItems(checkout) {
1304
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
1305
- }
1306
- updateCheckoutUser(checkout) {
1307
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1308
- }
1309
- clearCheckoutFromSession() {
1310
- return this.dataPersistence.remove('checkoutId');
1311
- }
1312
- calcDiscount(coupon) {
1313
- return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
1314
- }
1315
- checkCoupon(nickname, checkoutType) {
1316
- return this.getCheckout().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, CheckoutTypes.ECOMMERCE, checkout, null).pipe()));
1317
- }
1318
- async createCheckout(checkoutData) {
1319
- const checkout = await this.checkoutRepository.create({
1320
- createdAt: new Date(),
1321
- ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1322
- shop: checkoutData?.shop || this.defaultShop,
1323
- });
1324
- await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1325
- return checkout;
1326
- }
1327
- }
1328
- CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Injectable });
1329
- CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
1330
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
1331
- type: Injectable
1332
- }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
1333
- type: Inject,
1334
- args: ['CheckoutRepository']
1335
- }] }, { type: undefined, decorators: [{
1336
- type: Inject,
1337
- args: ['UserRepository']
1338
- }] }, { type: i1$2.Shops, decorators: [{
1339
- type: Inject,
1340
- args: [DEFAULT_SHOP]
1341
- }] }, { type: undefined, decorators: [{
1342
- type: Inject,
1343
- args: [PERSISTENCE_PROVIDER]
1260
+ class CheckoutService {
1261
+ constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1262
+ this.couponService = couponService;
1263
+ this.checkoutRepository = checkoutRepository;
1264
+ this.userRepository = userRepository;
1265
+ this.defaultShop = defaultShop;
1266
+ this.dataPersistence = dataPersistence;
1267
+ }
1268
+ getCheckout(checkoutData) {
1269
+ return this.dataPersistence
1270
+ .get('checkoutId')
1271
+ .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
1272
+ }
1273
+ getUserByCheckout(checkoutId) {
1274
+ return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id }))), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
1275
+ }
1276
+ updateCheckoutLineItems(checkout) {
1277
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
1278
+ }
1279
+ updateCheckoutUser(checkout) {
1280
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1281
+ }
1282
+ clearCheckoutFromSession() {
1283
+ return this.dataPersistence.remove('checkoutId');
1284
+ }
1285
+ calcDiscount(coupon) {
1286
+ return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
1287
+ }
1288
+ checkCoupon(nickname, checkoutType) {
1289
+ return this.getCheckout().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, CheckoutTypes.ECOMMERCE, checkout, null).pipe()));
1290
+ }
1291
+ async createCheckout(checkoutData) {
1292
+ const checkout = await this.checkoutRepository.create({
1293
+ createdAt: new Date(),
1294
+ ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1295
+ shop: checkoutData?.shop || this.defaultShop,
1296
+ });
1297
+ await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1298
+ return checkout;
1299
+ }
1300
+ }
1301
+ CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Injectable });
1302
+ CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
1303
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
1304
+ type: Injectable
1305
+ }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
1306
+ type: Inject,
1307
+ args: ['CheckoutRepository']
1308
+ }] }, { type: undefined, decorators: [{
1309
+ type: Inject,
1310
+ args: ['UserRepository']
1311
+ }] }, { type: i1$2.Shops, decorators: [{
1312
+ type: Inject,
1313
+ args: [DEFAULT_SHOP]
1314
+ }] }, { type: undefined, decorators: [{
1315
+ type: Inject,
1316
+ args: [PERSISTENCE_PROVIDER]
1344
1317
  }] }]; } });
1345
1318
 
1346
- class CartService {
1347
- constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
1348
- this.authService = authService;
1349
- this.checkoutService = checkoutService;
1350
- this.defaultShop = defaultShop;
1351
- this.productRepository = productRepository;
1352
- this.categoryRepository = categoryRepository;
1353
- this.variantRepository = variantRepository;
1354
- this.buy2WinRepository = buy2WinRepository;
1355
- this.cartSubject = new Subject();
1356
- this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
1357
- const items = [];
1358
- const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
1359
- if (index > -1) {
1360
- checkoutLoaded.lineItems[index].quantity += quantity;
1361
- checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
1362
- }
1363
- else
1364
- checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
1365
- return this.checkoutService
1366
- .updateCheckoutLineItems(checkoutLoaded)
1367
- .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
1368
- }));
1369
- this.generateCartObject = (items) => items?.reduce((cart, item) => ({
1370
- ...cart,
1371
- [item.id]: LineItem.toInstance({
1372
- ...(cart[item.id] || item),
1373
- quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
1374
- }),
1375
- }), {}) || {};
1376
- this.buildLineItem = async ({ checkout, item, quantity, }) => {
1377
- const product = await this.getProductData(item.id);
1378
- item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
1379
- if (this.checkMaxStock(product.stock.quantity, item.quantity || 0, quantity || 0))
1380
- throw new Error('Desculpe! Temos apenas ' + product.stock?.quantity + ' em estoque.');
1381
- const image = item.image || item.images?.shift();
1382
- const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
1383
- const isGift = item.isGift || null;
1384
- const pricePaid = this.getProductPrice({
1385
- product: item,
1386
- shop: checkout.shop || this.defaultShop,
1387
- isSubscriber: checkout.user?.isSubscriber,
1388
- });
1389
- RoundProductPricesHelper.roundProductPrices(item);
1390
- return {
1391
- checkout,
1392
- lineItem: LineItem.toInstance({
1393
- id,
1394
- name: name ?? product.name,
1395
- EAN: EAN ?? product.EAN,
1396
- brand: product.brand,
1397
- slug: slug ?? product.slug,
1398
- sku: sku ?? product.sku,
1399
- stock,
1400
- price: this.roundPrice(price),
1401
- image,
1402
- weight: weight ?? product.weight,
1403
- quantity: (item.quantity || 0) + (quantity || 0),
1404
- pricePaid,
1405
- discount: 0,
1406
- categories: product.categories ?? [],
1407
- isGift: isGift ?? null,
1408
- costPrice: product.costPrice ?? 0,
1409
- type,
1410
- }),
1411
- };
1412
- };
1413
- this.getProductPrice = ({ product, isSubscriber, }) => {
1414
- const info = product.price;
1415
- if (product.isGift)
1416
- return 0;
1417
- return isSubscriber && info.subscriberPrice > 0
1418
- ? Number(info.subscriberPrice.toFixed(2))
1419
- : Number(info.price.toFixed(2));
1420
- };
1421
- this.checkMaxStock = (currentStock, currentItemQtd, quantityToAdd) => {
1422
- const maxStock = currentStock || 0;
1423
- const currentItemAmount = currentItemQtd || 0;
1424
- return currentItemAmount + quantityToAdd > maxStock;
1425
- };
1426
- }
1427
- addItem(item, quantity = 1) {
1428
- return from(this.checkoutService.getCheckout()).pipe(concatMap(async (checkout) => await this.buildLineItem({ checkout, item, quantity: quantity || 1 })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
1429
- }
1430
- decreaseItem(item) {
1431
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1432
- const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id);
1433
- if (!isNil(checkoutItem))
1434
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
1435
- return checkout;
1436
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1437
- }
1438
- getCart(checkout) {
1439
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
1440
- return this.cartSubject;
1441
- }
1442
- /**
1443
- * @deprecated The method should not be used
1444
- */
1445
- getVariantPriceDiscount(item) {
1446
- return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.price.subscriberPrice, of(item.price.subscriberPrice), of(item.price.price))), catchError(() => of(item.price.price)));
1447
- }
1448
- removeItem(item) {
1449
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1450
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
1451
- if (index >= 0)
1452
- checkout.lineItems.splice(index, 1);
1453
- return checkout;
1454
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1455
- }
1456
- updateUserCart(user) {
1457
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1458
- .updateCheckoutLineItems(Checkout.toInstance({
1459
- ...checkout.toPlain(),
1460
- lineItems: checkout.lineItems?.length
1461
- ? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
1462
- : [],
1463
- }))
1464
- .toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1465
- }
1466
- clearCart() {
1467
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1468
- this.checkoutService.clearCheckoutFromSession();
1469
- return checkout;
1470
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1471
- }
1472
- buildCartFromCheckout(checkoutData) {
1473
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1474
- }
1475
- roundPrice(productPrice) {
1476
- const { price, fullPrice, subscriberPrice } = productPrice;
1477
- return {
1478
- ...productPrice,
1479
- price: Number(price.toFixed(2)),
1480
- fullPrice: Number(fullPrice.toFixed(2)),
1481
- ...(subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }),
1482
- };
1483
- }
1484
- async getProductData(productId) {
1485
- let product;
1486
- let variant;
1487
- try {
1488
- product = await this.productRepository.get({ id: productId });
1489
- }
1490
- catch (error) {
1491
- if (!(error instanceof NotFoundError))
1492
- throw error;
1493
- const { data: variants } = await this.variantRepository.find({ filters: { id: productId } });
1494
- variant = variants.shift();
1495
- if (!variant)
1496
- throw error;
1497
- product = await this.productRepository.get({ id: variant.productId });
1498
- }
1499
- return {
1500
- ...product.toPlain(),
1501
- ...(variant && { ...variant.toPlain() }),
1502
- };
1503
- }
1504
- getGifts() {
1505
- return this.checkoutService.getCheckout().pipe(mergeMap(async (checkout) => {
1506
- const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
1507
- if (!notGiftItems.length)
1508
- return { ...checkout, lineItems: [] };
1509
- const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1510
- const campaigns = await this.buy2WinRepository
1511
- .find({
1512
- filters: {
1513
- active: { operator: Where.EQUALS, value: true },
1514
- shop: { operator: Where.EQUALS, value: this.defaultShop },
1515
- },
1516
- })
1517
- .then((data) => data.data);
1518
- if (!campaigns.length)
1519
- return { ...checkout, lineItems: notGiftItems };
1520
- const elegibleCampaigns = [];
1521
- for (const campaign of campaigns) {
1522
- const today = new Date().getTime();
1523
- if (!(campaign.startDate.getTime() <= today) && !(campaign.endDate.getTime() >= today))
1524
- continue;
1525
- if (campaign.activeCategory) {
1526
- const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
1527
- const categoriesCampaingFullTree = [];
1528
- for (const id of categoriesCampaing) {
1529
- const children = await this.categoryRepository.getChildren(parseInt(id));
1530
- categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
1531
- }
1532
- const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
1533
- const filterProductsCategories = checkout.lineItems.filter((l) => {
1534
- if (!l.categories || !l.categories?.length)
1535
- return true;
1536
- return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
1537
- });
1538
- if (filterProductsCategories.length) {
1539
- const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1540
- if (cartTotalCategories >= campaign.cartValueMin)
1541
- elegibleCampaigns.push(campaign);
1542
- }
1543
- }
1544
- else {
1545
- if (campaign.cartValue && campaign.cartValue > 0) {
1546
- if (campaign.cartValue <= cartTotal)
1547
- elegibleCampaigns.push(campaign);
1548
- }
1549
- }
1550
- }
1551
- if (!elegibleCampaigns.length)
1552
- return { ...checkout, lineItems: notGiftItems };
1553
- const campaingnProducts = [];
1554
- for (const campaign of elegibleCampaigns) {
1555
- let elegibleProducts = [];
1556
- for (const product of campaign.products) {
1557
- const { data: productData } = await this.productRepository.find({ filters: { sku: product } });
1558
- if (!productData.length)
1559
- continue;
1560
- const gift = productData.shift();
1561
- if (gift.stock.quantity < 1)
1562
- continue;
1563
- elegibleProducts.push(gift);
1564
- }
1565
- campaingnProducts.push(elegibleProducts);
1566
- }
1567
- if (!campaingnProducts.length)
1568
- return { ...checkout, lineItems: notGiftItems };
1569
- const gifts = this.giftToLineItems([].concat(...campaingnProducts));
1570
- return { ...checkout, lineItems: notGiftItems.concat(gifts) };
1571
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1572
- }
1573
- giftToLineItems(items) {
1574
- return items.map((item) => {
1575
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1576
- const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
1577
- return LineItem.toInstance({
1578
- brand,
1579
- categories,
1580
- id: id.toString(),
1581
- name,
1582
- price,
1583
- sku,
1584
- slug,
1585
- stock,
1586
- weight,
1587
- EAN,
1588
- image,
1589
- pricePaid: 0,
1590
- quantity: 1,
1591
- isGift: true,
1592
- });
1593
- });
1594
- }
1595
- }
1596
- 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 });
1597
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1598
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1599
- type: Injectable
1600
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.Shops, decorators: [{
1601
- type: Inject,
1602
- args: [DEFAULT_SHOP]
1603
- }] }, { type: undefined, decorators: [{
1604
- type: Inject,
1605
- args: ['ProductRepository']
1606
- }] }, { type: undefined, decorators: [{
1607
- type: Inject,
1608
- args: ['CategoryRepository']
1609
- }] }, { type: undefined, decorators: [{
1610
- type: Inject,
1611
- args: ['VariantRepository']
1612
- }] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
1613
- type: Inject,
1614
- args: ['Buy2WinRepository']
1319
+ class CartService {
1320
+ constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
1321
+ this.authService = authService;
1322
+ this.checkoutService = checkoutService;
1323
+ this.defaultShop = defaultShop;
1324
+ this.productRepository = productRepository;
1325
+ this.categoryRepository = categoryRepository;
1326
+ this.variantRepository = variantRepository;
1327
+ this.buy2WinRepository = buy2WinRepository;
1328
+ this.cartSubject = new Subject();
1329
+ this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
1330
+ const items = [];
1331
+ const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
1332
+ if (index > -1) {
1333
+ checkoutLoaded.lineItems[index].quantity += quantity;
1334
+ checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
1335
+ checkoutLoaded.lineItems[index].price = lineItem.price;
1336
+ }
1337
+ else
1338
+ checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
1339
+ return this.checkoutService
1340
+ .updateCheckoutLineItems(checkoutLoaded)
1341
+ .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
1342
+ }));
1343
+ this.generateCartObject = (items) => items?.reduce((cart, item) => ({
1344
+ ...cart,
1345
+ [item.id]: LineItem.toInstance({
1346
+ ...(cart[item.id] || item),
1347
+ quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
1348
+ }),
1349
+ }), {}) || {};
1350
+ this.buildLineItem = async ({ checkout, item, quantity, }) => {
1351
+ const product = await this.getProductData(item.id);
1352
+ item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
1353
+ if (this.checkMaxStock(product.stock.quantity, item.quantity || 0, quantity || 0))
1354
+ throw new Error('Desculpe! Temos apenas ' + product.stock?.quantity + ' em estoque.');
1355
+ const image = item.image || item.images?.shift();
1356
+ const { id, name, EAN, slug, weight, sku, type } = item;
1357
+ const isGift = item.isGift || null;
1358
+ const pricePaid = this.getProductPrice({
1359
+ product: LineItem.toInstance(product),
1360
+ shop: checkout.shop || this.defaultShop,
1361
+ isSubscriber: checkout.user?.isSubscriber,
1362
+ });
1363
+ RoundProductPricesHelper.roundProductPrices(item);
1364
+ RoundProductPricesHelper.roundProductPrices(product);
1365
+ return {
1366
+ checkout,
1367
+ lineItem: LineItem.toInstance({
1368
+ id,
1369
+ name: name ?? product.name,
1370
+ EAN: EAN ?? product.EAN,
1371
+ brand: product.brand,
1372
+ slug: slug ?? product.slug,
1373
+ sku: sku ?? product.sku,
1374
+ stock: product.stock,
1375
+ price: this.roundPrice(product.price),
1376
+ image,
1377
+ weight: weight ?? product.weight,
1378
+ quantity: (item.quantity || 0) + (quantity || 0),
1379
+ pricePaid,
1380
+ discount: 0,
1381
+ categories: product.categories ?? [],
1382
+ isGift: isGift ?? null,
1383
+ costPrice: product.costPrice ?? 0,
1384
+ type,
1385
+ }),
1386
+ };
1387
+ };
1388
+ this.getProductPrice = ({ product, isSubscriber, }) => {
1389
+ const info = product.price;
1390
+ if (product.isGift)
1391
+ return 0;
1392
+ return isSubscriber && info.subscriberPrice > 0
1393
+ ? Number(info.subscriberPrice.toFixed(2))
1394
+ : Number(info.price.toFixed(2));
1395
+ };
1396
+ this.checkMaxStock = (currentStock, currentItemQtd, quantityToAdd) => {
1397
+ const maxStock = currentStock || 0;
1398
+ const currentItemAmount = currentItemQtd || 0;
1399
+ return currentItemAmount + quantityToAdd > maxStock;
1400
+ };
1401
+ }
1402
+ addItem(item, quantity = 1) {
1403
+ return from(this.checkoutService.getCheckout()).pipe(concatMap(async (checkout) => await this.buildLineItem({ checkout, item, quantity: quantity || 1 })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
1404
+ }
1405
+ decreaseItem(item) {
1406
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
1407
+ const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id);
1408
+ if (!isNil(checkoutItem))
1409
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
1410
+ return checkout;
1411
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1412
+ }
1413
+ getCart(checkout) {
1414
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
1415
+ return this.cartSubject;
1416
+ }
1417
+ /**
1418
+ * @deprecated The method should not be used
1419
+ */
1420
+ getVariantPriceDiscount(item) {
1421
+ return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.price.subscriberPrice, of(item.price.subscriberPrice), of(item.price.price))), catchError(() => of(item.price.price)));
1422
+ }
1423
+ removeItem(item) {
1424
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
1425
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
1426
+ if (index >= 0)
1427
+ checkout.lineItems.splice(index, 1);
1428
+ return checkout;
1429
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1430
+ }
1431
+ updateUserCart(user) {
1432
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1433
+ .updateCheckoutLineItems(Checkout.toInstance({
1434
+ ...checkout.toPlain(),
1435
+ lineItems: checkout.lineItems?.length
1436
+ ? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
1437
+ : [],
1438
+ }))
1439
+ .toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1440
+ }
1441
+ clearCart() {
1442
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
1443
+ this.checkoutService.clearCheckoutFromSession();
1444
+ return checkout;
1445
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1446
+ }
1447
+ buildCartFromCheckout(checkoutData) {
1448
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1449
+ }
1450
+ roundPrice(productPrice) {
1451
+ const { price, fullPrice, subscriberPrice } = productPrice;
1452
+ return {
1453
+ ...productPrice,
1454
+ price: Number(price.toFixed(2)),
1455
+ fullPrice: Number(fullPrice.toFixed(2)),
1456
+ ...(subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }),
1457
+ };
1458
+ }
1459
+ async getProductData(productId) {
1460
+ let product;
1461
+ let variant;
1462
+ try {
1463
+ product = await this.productRepository.get({ id: productId });
1464
+ }
1465
+ catch (error) {
1466
+ if (!(error instanceof NotFoundError))
1467
+ throw error;
1468
+ const { data: variants } = await this.variantRepository.find({ filters: { id: productId } });
1469
+ variant = variants.shift();
1470
+ if (!variant)
1471
+ throw error;
1472
+ product = await this.productRepository.get({ id: variant.productId });
1473
+ }
1474
+ return {
1475
+ ...product.toPlain(),
1476
+ ...(variant && { ...variant.toPlain() }),
1477
+ };
1478
+ }
1479
+ getGifts() {
1480
+ return this.checkoutService.getCheckout().pipe(mergeMap(async (checkout) => {
1481
+ const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
1482
+ if (!notGiftItems.length)
1483
+ return { ...checkout, lineItems: [] };
1484
+ const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1485
+ const campaigns = await this.buy2WinRepository
1486
+ .find({
1487
+ filters: {
1488
+ active: { operator: Where.EQUALS, value: true },
1489
+ shop: { operator: Where.EQUALS, value: this.defaultShop },
1490
+ },
1491
+ })
1492
+ .then((data) => data.data);
1493
+ if (!campaigns.length)
1494
+ return { ...checkout, lineItems: notGiftItems };
1495
+ const elegibleCampaigns = [];
1496
+ for (const campaign of campaigns) {
1497
+ const today = new Date().getTime();
1498
+ if (!(campaign.startDate.getTime() <= today) && !(campaign.endDate.getTime() >= today))
1499
+ continue;
1500
+ if (campaign.activeCategory) {
1501
+ const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
1502
+ const categoriesCampaingFullTree = [];
1503
+ for (const id of categoriesCampaing) {
1504
+ const children = await this.categoryRepository.getChildren(parseInt(id));
1505
+ categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
1506
+ }
1507
+ const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
1508
+ const filterProductsCategories = checkout.lineItems.filter((l) => {
1509
+ if (!l.categories || !l.categories?.length)
1510
+ return true;
1511
+ return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
1512
+ });
1513
+ if (filterProductsCategories.length) {
1514
+ const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1515
+ if (cartTotalCategories >= campaign.cartValueMin)
1516
+ elegibleCampaigns.push(campaign);
1517
+ }
1518
+ }
1519
+ else {
1520
+ if (campaign.cartValue && campaign.cartValue > 0) {
1521
+ if (campaign.cartValue <= cartTotal)
1522
+ elegibleCampaigns.push(campaign);
1523
+ }
1524
+ }
1525
+ }
1526
+ if (!elegibleCampaigns.length)
1527
+ return { ...checkout, lineItems: notGiftItems };
1528
+ const campaingnProducts = [];
1529
+ for (const campaign of elegibleCampaigns) {
1530
+ let elegibleProducts = [];
1531
+ for (const product of campaign.products) {
1532
+ const { data: productData } = await this.productRepository.find({ filters: { sku: product } });
1533
+ if (!productData.length)
1534
+ continue;
1535
+ const gift = productData.shift();
1536
+ if (gift.stock.quantity < 1)
1537
+ continue;
1538
+ elegibleProducts.push(gift);
1539
+ }
1540
+ campaingnProducts.push(elegibleProducts);
1541
+ }
1542
+ if (!campaingnProducts.length)
1543
+ return { ...checkout, lineItems: notGiftItems };
1544
+ const gifts = this.giftToLineItems([].concat(...campaingnProducts));
1545
+ return { ...checkout, lineItems: notGiftItems.concat(gifts) };
1546
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1547
+ }
1548
+ giftToLineItems(items) {
1549
+ return items.map((item) => {
1550
+ const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1551
+ const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
1552
+ return LineItem.toInstance({
1553
+ brand,
1554
+ categories,
1555
+ id: id.toString(),
1556
+ name,
1557
+ price,
1558
+ sku,
1559
+ slug,
1560
+ stock,
1561
+ weight,
1562
+ EAN,
1563
+ image,
1564
+ pricePaid: 0,
1565
+ quantity: 1,
1566
+ isGift: true,
1567
+ });
1568
+ });
1569
+ }
1570
+ }
1571
+ 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 });
1572
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
1573
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
1574
+ type: Injectable
1575
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.Shops, decorators: [{
1576
+ type: Inject,
1577
+ args: [DEFAULT_SHOP]
1578
+ }] }, { type: undefined, decorators: [{
1579
+ type: Inject,
1580
+ args: ['ProductRepository']
1581
+ }] }, { type: undefined, decorators: [{
1582
+ type: Inject,
1583
+ args: ['CategoryRepository']
1584
+ }] }, { type: undefined, decorators: [{
1585
+ type: Inject,
1586
+ args: ['VariantRepository']
1587
+ }] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
1588
+ type: Inject,
1589
+ args: ['Buy2WinRepository']
1615
1590
  }] }]; } });
1616
1591
 
1617
- class NewCategoryStructureAdapter {
1618
- constructor(categoryRepository) {
1619
- this.categoryRepository = categoryRepository;
1620
- }
1621
- async buildProductFilterByCategory(category) {
1622
- const loadedCategory = await this.getCategory(category);
1623
- if (loadedCategory.isCollection)
1624
- return { id: { operator: Where.IN, value: loadedCategory.products } };
1625
- const categoryIds = [...(await this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1626
- return {
1627
- category: {
1628
- id: {
1629
- operator: Where.IN,
1630
- value: categoryIds,
1631
- },
1632
- },
1633
- };
1634
- }
1635
- async getAllCategoriesIdFromCategory(category) {
1636
- return this.categoryRepository
1637
- .getChildren(+category.id)
1638
- .then((categories) => categories.map((category) => category.id.toString()));
1639
- }
1640
- async getCategory(category) {
1641
- const collectionCategory = category.isCollection ||
1642
- (isNil(category.isCollection) && !category.products?.length) ||
1643
- category.isWishlist ||
1644
- category.brandCategory;
1645
- return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1646
- }
1647
- }
1648
- NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1649
- NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1650
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1651
- type: Injectable
1652
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1653
- type: Inject,
1654
- args: ['CategoryRepository']
1592
+ class NewCategoryStructureAdapter {
1593
+ constructor(categoryRepository) {
1594
+ this.categoryRepository = categoryRepository;
1595
+ }
1596
+ async buildProductFilterByCategory(category) {
1597
+ const loadedCategory = await this.getCategory(category);
1598
+ if (loadedCategory.isCollection)
1599
+ return { id: { operator: Where.IN, value: loadedCategory.products } };
1600
+ const categoryIds = [...(await this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1601
+ return {
1602
+ category: {
1603
+ id: {
1604
+ operator: Where.IN,
1605
+ value: categoryIds,
1606
+ },
1607
+ },
1608
+ };
1609
+ }
1610
+ async getAllCategoriesIdFromCategory(category) {
1611
+ return this.categoryRepository
1612
+ .getChildren(+category.id)
1613
+ .then((categories) => categories.map((category) => category.id.toString()));
1614
+ }
1615
+ async getCategory(category) {
1616
+ const collectionCategory = category.isCollection ||
1617
+ (isNil(category.isCollection) && !category.products?.length) ||
1618
+ category.isWishlist ||
1619
+ category.brandCategory;
1620
+ return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1621
+ }
1622
+ }
1623
+ NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1624
+ NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter });
1625
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1626
+ type: Injectable
1627
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1628
+ type: Inject,
1629
+ args: ['CategoryRepository']
1655
1630
  }] }]; } });
1656
1631
 
1657
- class OldCategoryStructureAdapter {
1658
- constructor(categoryRepository) {
1659
- this.categoryRepository = categoryRepository;
1660
- }
1661
- async buildProductFilterByCategory(category) {
1662
- const productsIds = category.products?.length
1663
- ? category.products
1664
- : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1665
- return { id: { operator: Where.IN, value: productsIds } };
1666
- }
1667
- }
1668
- OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1669
- OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1670
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1671
- type: Injectable
1672
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1673
- type: Inject,
1674
- args: ['CategoryRepository']
1632
+ class OldCategoryStructureAdapter {
1633
+ constructor(categoryRepository) {
1634
+ this.categoryRepository = categoryRepository;
1635
+ }
1636
+ async buildProductFilterByCategory(category) {
1637
+ const productsIds = category.products?.length
1638
+ ? category.products
1639
+ : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1640
+ return { id: { operator: Where.IN, value: productsIds } };
1641
+ }
1642
+ }
1643
+ OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1644
+ OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter });
1645
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1646
+ type: Injectable
1647
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1648
+ type: Inject,
1649
+ args: ['CategoryRepository']
1675
1650
  }] }]; } });
1676
1651
 
1677
- class CatalogService {
1678
- constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch) {
1679
- this.productRepository = productRepository;
1680
- this.productStockNotificationRepository = productStockNotificationRepository;
1681
- this.categoryRepository = categoryRepository;
1682
- this.categoryStructureAdapter = categoryStructureAdapter;
1683
- this.shop = shop;
1684
- this.productSearch = productSearch;
1685
- this.productsByTerm = {};
1686
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1687
- const filters = {};
1688
- if (clubDiscount?.length)
1689
- set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1690
- if (brands?.length)
1691
- filters.brand = { operator: Where.IN, value: brands };
1692
- if (gender?.length)
1693
- filters.gender = { operator: Where.IN, value: gender };
1694
- if (prices?.min || prices?.max)
1695
- set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1696
- ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1697
- ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1698
- ]);
1699
- if (rate)
1700
- filters.rate = { operator: Where.GTE, value: rate };
1701
- if (tags?.length)
1702
- filters.tags = { operator: Where.LIKE, value: tags };
1703
- if (customOptions?.length)
1704
- filters.filters = { operator: Where.LIKE, value: customOptions };
1705
- return filters;
1706
- };
1707
- this.buildSortQuery = (sort) => {
1708
- if (!sort || sort === 'most-relevant')
1709
- return {};
1710
- if (sort === 'best-sellers')
1711
- return {
1712
- shoppingCount: 'desc',
1713
- rate: 'desc',
1714
- stock: 'desc',
1715
- name: 'asc',
1716
- };
1717
- if (sort === 'biggest-price')
1718
- return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1719
- if (sort === 'lowest-price')
1720
- return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1721
- if (sort === 'best-rating')
1722
- return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1723
- if (sort === 'news')
1724
- return { createdAt: 'desc' };
1725
- if (sort === 'biggest-discount')
1726
- return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1727
- };
1728
- this.buildLimitQuery = (options) => {
1729
- const limit = options?.perPage || 20;
1730
- return {
1731
- limit,
1732
- offset: ((options?.page || 1) - 1) * limit,
1733
- };
1734
- };
1735
- this.hasProfile = (options) => 'profile' in options;
1736
- this.hasTerm = (options) => 'term' in options;
1737
- this.hasCategory = (options) => 'category' in options;
1738
- }
1739
- async fetchProducts(options) {
1740
- const limits = this.buildLimitQuery(options);
1741
- if (this.hasProfile(options) && options.filters?.customOptions)
1742
- throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1743
- if (this.hasProfile(options) && options.filters?.tags)
1744
- throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1745
- if (this.hasTerm(options) && options.filters?.customOptions)
1746
- throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1747
- console.log('fetchProducts', options);
1748
- return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1749
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1750
- pages: Math.ceil(total / limits.limit),
1751
- prices: {
1752
- price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1753
- subscriberPrice: {
1754
- min: +minimal?.price?.subscriberPrice?.toFixed(2),
1755
- max: +maximum?.price?.subscriberPrice?.toFixed(2),
1756
- },
1757
- },
1758
- brands: distinct?.brand,
1759
- }));
1760
- }
1761
- async addCustomerToStockNotification(shop, productId, name, email) {
1762
- return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1763
- }
1764
- async findCatalog(options, limits) {
1765
- if (this.hasTerm(options) && options.sort === 'most-relevant') {
1766
- // console.log('Step 1')
1767
- const productsIds = await this.findCatalogIdsBySearch(options.term);
1768
- return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1769
- }
1770
- if (this.hasCategory(options) && options.sort === 'most-relevant') {
1771
- const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
1772
- const productsIds = await this.productRepository
1773
- .findCatalog({
1774
- fields: ['id'],
1775
- filters: {
1776
- ...(await this.buildMainFilter(options)),
1777
- ...this.buildFilterQuery(options?.filters || {}),
1778
- },
1779
- })
1780
- .then((products) => products.data.map((product) => product.id));
1781
- return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1782
- }
1783
- const repoParams = {
1784
- filters: {
1785
- ...(await this.buildMainFilter(options)),
1786
- ...this.buildFilterQuery(options?.filters || {}),
1787
- },
1788
- ...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
1789
- limits,
1790
- options: {
1791
- minimal: ['price'],
1792
- maximum: ['price'],
1793
- ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1794
- },
1795
- };
1796
- if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1797
- return this.productRepository.findCatalog(repoParams);
1798
- return this.productRepository.findCatalog(repoParams, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1799
- }
1800
- async buildMainFilter({ category, profile, term, }) {
1801
- if (category)
1802
- return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1803
- if (profile)
1804
- return { tags: { operator: Where.LIKE, value: profile } };
1805
- if (term)
1806
- return this.productSearch
1807
- .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1808
- .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1809
- }
1810
- async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1811
- const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1812
- const totalResult = await this.productRepository.findCatalog({
1813
- filters: {
1814
- id: { operator: Where.IN, value: mostRelevantProductsIds },
1815
- ...this.buildFilterQuery(options?.filters || {}),
1816
- },
1817
- orderBy: this.buildSortQuery('best-sellers'),
1818
- options: {
1819
- minimal: ['price'],
1820
- maximum: ['price'],
1821
- distinct: ['brand'],
1822
- },
1823
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1824
- const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
1825
- const firstProducts = totalResult.data
1826
- .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
1827
- .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
1828
- const lastProducts = totalResult.data
1829
- .filter((product) => !mostRelevants.includes(product.id))
1830
- .concat(mostRelevantWithouyStock);
1831
- const categoryMostRelevants = firstProducts.concat(lastProducts);
1832
- const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1833
- return {
1834
- data: resultFinal,
1835
- count: totalResult.count,
1836
- maximum: totalResult.maximum,
1837
- minimal: totalResult.minimal,
1838
- distinct: totalResult.distinct,
1839
- };
1840
- }
1841
- async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1842
- console.log('findCatalogAndSortByMostRevelantByTerm', this.shop, options, limits);
1843
- // console.log(
1844
- // 'productIds from search',
1845
- // productIds.length,
1846
- // 'preview -> ',
1847
- // productIds.slice(limits.offset, limits.offset + limits.limit),
1848
- // )
1849
- const totalResult = await this.productRepository.findCatalog({
1850
- fields: ['id', 'stock', 'gender'],
1851
- filters: {
1852
- id: { operator: Where.IN, value: productIds },
1853
- published: { operator: Where.EQUALS, value: true },
1854
- ...this.buildFilterQuery(options?.filters || {}),
1855
- },
1856
- options: {
1857
- minimal: ['price'],
1858
- maximum: ['price'],
1859
- distinct: ['brand'],
1860
- },
1861
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1862
- // const productsTotalResult = totalResult.data.slice(limits.offset, limits.offset + limits.limit)
1863
- // console.log(
1864
- // 'productsTotalResult',
1865
- // productsTotalResult.map((p) => {
1866
- // return {
1867
- // id: p.id,
1868
- // stock: p.stock.quantity,
1869
- // }
1870
- // }),
1871
- // )
1872
- const defaultGender = options?.filters?.gender
1873
- ? options?.filters?.gender.at(0)
1874
- : this.shop === Shops.GLAMSHOP
1875
- ? 'female'
1876
- : 'male';
1877
- const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1878
- const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1879
- const productIdsStockGender = productIds.filter((product) => stockData.some((result) => result.id === product && (result.gender.includes(defaultGender) || result.gender.includes('unisex'))));
1880
- const productIdsStockNotGender = productIds.filter((product) => stockData.some((result) => result.id === product && !result.gender.includes(defaultGender) && !result.gender.includes('unisex')));
1881
- const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
1882
- const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
1883
- const limitedProductId = productIdsStock
1884
- .concat(productIdsStockOut)
1885
- .slice(limits.offset, limits.offset + limits.limit);
1886
- // console.log('limitedProductId', limitedProductId)
1887
- const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1888
- const productResult = await this.productRepository.findCatalog({
1889
- filters: {
1890
- id: { operator: Where.IN, value: orderedId },
1891
- },
1892
- });
1893
- const finalResult = limitedProductId
1894
- .map((id) => productResult.data.find((product) => product.id === id))
1895
- .filter(Boolean);
1896
- // console.log(
1897
- // 'finalResult',
1898
- // finalResult.map((p) => {
1899
- // return {
1900
- // id: p.id,
1901
- // name: p.name,
1902
- // brand: p.brand,
1903
- // }
1904
- // }),
1905
- // )
1906
- return {
1907
- data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1908
- count: totalResult.count,
1909
- maximum: totalResult.maximum,
1910
- minimal: totalResult.minimal,
1911
- distinct: totalResult.distinct,
1912
- };
1913
- }
1914
- async findCatalogIdsBySearch(term, preview = false) {
1915
- console.log('this.productsByTerm[term]', this.productsByTerm[term]?.length);
1916
- if (this.productsByTerm[term])
1917
- return this.productsByTerm[term];
1918
- return (this.productsByTerm[term] = await this.productSearch
1919
- .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1920
- .then((products) => [...new Set(products.map((product) => product.id))]));
1921
- }
1922
- }
1923
- CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
1924
- CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1925
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1926
- type: Injectable
1927
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1928
- type: Inject,
1929
- args: ['ProductRepository']
1930
- }] }, { type: undefined, decorators: [{
1931
- type: Inject,
1932
- args: ['ProductStockNotificationRepository']
1933
- }] }, { type: undefined, decorators: [{
1934
- type: Inject,
1935
- args: ['CategoryRepository']
1936
- }] }, { type: undefined, decorators: [{
1937
- type: Inject,
1938
- args: [CATEGORY_STRUCTURE]
1939
- }] }, { type: i1$2.Shops, decorators: [{
1940
- type: Inject,
1941
- args: [DEFAULT_SHOP]
1942
- }] }, { type: undefined, decorators: [{
1943
- type: Inject,
1944
- args: ['ProductSearch']
1945
- }] }]; } });
1652
+ class CatalogService {
1653
+ constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1654
+ this.productRepository = productRepository;
1655
+ this.productStockNotificationRepository = productStockNotificationRepository;
1656
+ this.categoryRepository = categoryRepository;
1657
+ this.categoryStructureAdapter = categoryStructureAdapter;
1658
+ this.shop = shop;
1659
+ this.productIndex = productIndex;
1660
+ this.productsByTerm = {};
1661
+ this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1662
+ const filters = {};
1663
+ if (clubDiscount?.length)
1664
+ set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1665
+ if (brands?.length)
1666
+ filters.brand = { operator: Where.IN, value: brands };
1667
+ if (gender?.length)
1668
+ filters.gender = { operator: Where.IN, value: gender };
1669
+ if (prices?.min || prices?.max)
1670
+ set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1671
+ ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1672
+ ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1673
+ ]);
1674
+ if (rate)
1675
+ filters.rate = { operator: Where.GTE, value: rate };
1676
+ if (tags?.length)
1677
+ filters.tags = { operator: Where.LIKE, value: tags };
1678
+ if (customOptions?.length)
1679
+ filters.filters = { operator: Where.LIKE, value: customOptions };
1680
+ return filters;
1681
+ };
1682
+ this.buildSortQuery = (sort) => {
1683
+ if (!sort || sort === 'most-relevant')
1684
+ return {};
1685
+ if (sort === 'best-sellers')
1686
+ return {
1687
+ shoppingCount: 'desc',
1688
+ rate: 'desc',
1689
+ stock: 'desc',
1690
+ name: 'asc',
1691
+ };
1692
+ if (sort === 'biggest-price')
1693
+ return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1694
+ if (sort === 'lowest-price')
1695
+ return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1696
+ if (sort === 'best-rating')
1697
+ return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1698
+ if (sort === 'news')
1699
+ return { createdAt: 'desc' };
1700
+ if (sort === 'biggest-discount')
1701
+ return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1702
+ };
1703
+ this.buildLimitQuery = (options) => {
1704
+ const limit = options?.perPage || 20;
1705
+ return {
1706
+ limit,
1707
+ offset: ((options?.page || 1) - 1) * limit,
1708
+ };
1709
+ };
1710
+ this.hasProfile = (options) => 'profile' in options;
1711
+ this.hasTerm = (options) => 'term' in options;
1712
+ this.hasCategory = (options) => 'category' in options;
1713
+ }
1714
+ async fetchProducts(options) {
1715
+ const limits = this.buildLimitQuery(options);
1716
+ if (this.hasProfile(options) && options.filters?.customOptions)
1717
+ throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1718
+ if (this.hasProfile(options) && options.filters?.tags)
1719
+ throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1720
+ if (this.hasTerm(options) && options.filters?.customOptions)
1721
+ throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1722
+ return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1723
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1724
+ pages: Math.ceil(total / limits.limit),
1725
+ prices: {
1726
+ price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1727
+ subscriberPrice: {
1728
+ min: +minimal?.price?.subscriberPrice?.toFixed(2),
1729
+ max: +maximum?.price?.subscriberPrice?.toFixed(2),
1730
+ },
1731
+ },
1732
+ brands: distinct?.brand,
1733
+ }));
1734
+ }
1735
+ async addCustomerToStockNotification(shop, productId, name, email) {
1736
+ return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1737
+ }
1738
+ async findCatalog(options, limits) {
1739
+ if (this.hasTerm(options) && options.sort === 'most-relevant') {
1740
+ const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
1741
+ return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1742
+ }
1743
+ if (this.hasCategory(options) && options.sort === 'most-relevant') {
1744
+ const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
1745
+ const productsIds = await this.productRepository
1746
+ .findCatalog({
1747
+ fields: ['id'],
1748
+ filters: {
1749
+ ...(await this.buildMainFilter(options)),
1750
+ ...this.buildFilterQuery(options?.filters || {}),
1751
+ },
1752
+ })
1753
+ .then((products) => products.data.map((product) => product.id));
1754
+ return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1755
+ }
1756
+ const repoParams = {
1757
+ filters: {
1758
+ ...(await this.buildMainFilter(options)),
1759
+ ...this.buildFilterQuery(options?.filters || {}),
1760
+ },
1761
+ ...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
1762
+ limits,
1763
+ options: {
1764
+ minimal: ['price'],
1765
+ maximum: ['price'],
1766
+ ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1767
+ },
1768
+ };
1769
+ if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1770
+ return this.productRepository.findCatalog(repoParams);
1771
+ return this.productRepository.findCatalog(repoParams, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1772
+ }
1773
+ async buildMainFilter({ category, profile, term, }) {
1774
+ if (category)
1775
+ return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1776
+ if (profile)
1777
+ return { tags: { operator: Where.LIKE, value: profile } };
1778
+ if (term)
1779
+ return this.productIndex
1780
+ .search(term, 999, this.shop)
1781
+ .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1782
+ }
1783
+ async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1784
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1785
+ const totalResult = await this.productRepository.findCatalog({
1786
+ filters: {
1787
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
1788
+ ...this.buildFilterQuery(options?.filters || {}),
1789
+ },
1790
+ orderBy: this.buildSortQuery('best-sellers'),
1791
+ options: {
1792
+ minimal: ['price'],
1793
+ maximum: ['price'],
1794
+ distinct: ['brand'],
1795
+ },
1796
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1797
+ const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
1798
+ const firstProducts = totalResult.data
1799
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
1800
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
1801
+ const lastProducts = totalResult.data
1802
+ .filter((product) => !mostRelevants.includes(product.id))
1803
+ .concat(mostRelevantWithouyStock);
1804
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
1805
+ const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1806
+ return {
1807
+ data: resultFinal,
1808
+ count: totalResult.count,
1809
+ maximum: totalResult.maximum,
1810
+ minimal: totalResult.minimal,
1811
+ distinct: totalResult.distinct,
1812
+ };
1813
+ }
1814
+ async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1815
+ const totalResult = await this.productRepository.findCatalog({
1816
+ fields: ['id', 'stock'],
1817
+ filters: {
1818
+ id: { operator: Where.IN, value: productIds },
1819
+ ...this.buildFilterQuery(options?.filters || {}),
1820
+ },
1821
+ options: {
1822
+ minimal: ['price'],
1823
+ maximum: ['price'],
1824
+ distinct: ['brand'],
1825
+ },
1826
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1827
+ const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1828
+ const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1829
+ const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1830
+ const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
1831
+ const limitedProductId = productIdsStock
1832
+ .concat(productIdsStockOut)
1833
+ .slice(limits.offset, limits.offset + limits.limit);
1834
+ const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1835
+ const productResult = await this.productRepository.findCatalog({
1836
+ filters: {
1837
+ id: { operator: Where.IN, value: orderedId },
1838
+ },
1839
+ });
1840
+ return {
1841
+ data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1842
+ count: totalResult.count,
1843
+ maximum: totalResult.maximum,
1844
+ minimal: totalResult.minimal,
1845
+ distinct: totalResult.distinct,
1846
+ };
1847
+ }
1848
+ async findCatalogIdsByElasticSearch(term) {
1849
+ if (this.productsByTerm[term])
1850
+ return this.productsByTerm[term];
1851
+ return (this.productsByTerm[term] = await this.productIndex
1852
+ .search(term, 999, this.shop)
1853
+ .then(({ hits: products }) => {
1854
+ const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1855
+ const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1856
+ const sorted = [...withStock, ...withOutStock];
1857
+ return [...new Set(sorted.map(({ _source }) => _source.id))];
1858
+ }));
1859
+ }
1860
+ }
1861
+ CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });
1862
+ CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
1863
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, decorators: [{
1864
+ type: Injectable
1865
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1866
+ type: Inject,
1867
+ args: ['ProductRepository']
1868
+ }] }, { type: undefined, decorators: [{
1869
+ type: Inject,
1870
+ args: ['ProductStockNotificationRepository']
1871
+ }] }, { type: undefined, decorators: [{
1872
+ type: Inject,
1873
+ args: ['CategoryRepository']
1874
+ }] }, { type: undefined, decorators: [{
1875
+ type: Inject,
1876
+ args: [CATEGORY_STRUCTURE]
1877
+ }] }, { type: i1$2.Shops, decorators: [{
1878
+ type: Inject,
1879
+ args: [DEFAULT_SHOP]
1880
+ }] }, { type: i1$2.ProductsIndex }]; } });
1946
1881
 
1947
- class CategoryService {
1948
- constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1949
- this.productRepository = productRepository;
1950
- this.categoryRepository = categoryRepository;
1951
- this.categoryFilterRepository = categoryFilterRepository;
1952
- this.categoryStructureAdapter = categoryStructureAdapter;
1953
- this.shop = shop;
1954
- }
1955
- async fetchBrands(category, options) {
1956
- const brands = await this.productRepository
1957
- .findCatalog({
1958
- filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1959
- fields: ['brand'],
1960
- }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1961
- .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1962
- return this.categoryRepository
1963
- .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } })
1964
- .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1965
- }
1966
- async fetchFilterOptions(category) {
1967
- return await this.categoryFilterRepository
1968
- .find({ filters: { categoryId: +category.id } })
1969
- .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1970
- }
1971
- }
1972
- CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1973
- CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1974
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1975
- type: Injectable
1976
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1977
- type: Inject,
1978
- args: ['ProductRepository']
1979
- }] }, { type: undefined, decorators: [{
1980
- type: Inject,
1981
- args: ['CategoryRepository']
1982
- }] }, { type: undefined, decorators: [{
1983
- type: Inject,
1984
- args: ['CategoryFilterRepository']
1985
- }] }, { type: undefined, decorators: [{
1986
- type: Inject,
1987
- args: [CATEGORY_STRUCTURE]
1988
- }] }, { type: i1$2.Shops, decorators: [{
1989
- type: Inject,
1990
- args: [DEFAULT_SHOP]
1882
+ class CategoryService {
1883
+ constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1884
+ this.productRepository = productRepository;
1885
+ this.categoryRepository = categoryRepository;
1886
+ this.categoryFilterRepository = categoryFilterRepository;
1887
+ this.categoryStructureAdapter = categoryStructureAdapter;
1888
+ this.shop = shop;
1889
+ }
1890
+ async fetchBrands(category, options) {
1891
+ const brands = await this.productRepository
1892
+ .findCatalog({
1893
+ filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1894
+ fields: ['brand'],
1895
+ }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1896
+ .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1897
+ return this.categoryRepository
1898
+ .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } })
1899
+ .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1900
+ }
1901
+ async fetchFilterOptions(category) {
1902
+ return await this.categoryFilterRepository
1903
+ .find({ filters: { categoryId: +category.id } })
1904
+ .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1905
+ }
1906
+ }
1907
+ CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1908
+ CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1909
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1910
+ type: Injectable
1911
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1912
+ type: Inject,
1913
+ args: ['ProductRepository']
1914
+ }] }, { type: undefined, decorators: [{
1915
+ type: Inject,
1916
+ args: ['CategoryRepository']
1917
+ }] }, { type: undefined, decorators: [{
1918
+ type: Inject,
1919
+ args: ['CategoryFilterRepository']
1920
+ }] }, { type: undefined, decorators: [{
1921
+ type: Inject,
1922
+ args: [CATEGORY_STRUCTURE]
1923
+ }] }, { type: i1$2.Shops, decorators: [{
1924
+ type: Inject,
1925
+ args: [DEFAULT_SHOP]
1991
1926
  }] }]; } });
1992
1927
 
1993
- var ProductSorts;
1994
- (function (ProductSorts) {
1995
- ProductSorts["MOST_RELEVANT"] = "most-relevant";
1996
- ProductSorts["BEST_SELLER"] = "best-sellers";
1997
- ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1998
- ProductSorts["LOWEST_PRICE"] = "lowest-price";
1999
- ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
2000
- ProductSorts["BEST_RATING"] = "best-rating";
2001
- ProductSorts["NEWS"] = "news";
1928
+ var ProductSorts;
1929
+ (function (ProductSorts) {
1930
+ ProductSorts["MOST_RELEVANT"] = "most-relevant";
1931
+ ProductSorts["BEST_SELLER"] = "best-sellers";
1932
+ ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1933
+ ProductSorts["LOWEST_PRICE"] = "lowest-price";
1934
+ ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1935
+ ProductSorts["BEST_RATING"] = "best-rating";
1936
+ ProductSorts["NEWS"] = "news";
2002
1937
  })(ProductSorts || (ProductSorts = {}));
2003
1938
 
2004
- class CategoryWithTree extends Category {
2005
- }
2006
- __decorate([
2007
- Type(() => CategoryWithTree),
2008
- __metadata("design:type", Array)
1939
+ class CategoryWithTree extends Category {
1940
+ }
1941
+ __decorate([
1942
+ Type(() => CategoryWithTree),
1943
+ __metadata("design:type", Array)
2009
1944
  ], CategoryWithTree.prototype, "children", void 0);
2010
1945
 
2011
- class WishlistService {
2012
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productSearch) {
2013
- this.wishlistRepository = wishlistRepository;
2014
- this.shop = shop;
2015
- this.productSearch = productSearch;
2016
- const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
2017
- this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch);
2018
- this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
2019
- }
2020
- getCatalogService() {
2021
- return this.catalogService;
2022
- }
2023
- getCategoryService() {
2024
- return this.categoryService;
2025
- }
2026
- async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
2027
- const data = {
2028
- slug: '',
2029
- name: title,
2030
- description,
2031
- metadatas: [
2032
- {
2033
- shop: this.shop,
2034
- title: `${userFullName} - ${title}`,
2035
- description: `${userFullName} - ${description}`,
2036
- },
2037
- ],
2038
- shop: this.shop,
2039
- shops: [this.shop],
2040
- personId,
2041
- personName: userFullName,
2042
- personPhoto: userPhoto,
2043
- brandCategory: false,
2044
- published,
2045
- theme,
2046
- bannerUrl,
2047
- personType: personType ?? PersonTypes.NONE,
2048
- personIsSubscriber: personIsSubscriber ?? false,
2049
- };
2050
- const newWishlist = await this.wishlistRepository.create(data);
2051
- await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
2052
- return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
2053
- }
2054
- update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
2055
- const data = {
2056
- id,
2057
- name: title,
2058
- description,
2059
- published,
2060
- metadatas: [
2061
- {
2062
- shop: this.shop,
2063
- title: `${userFullName} - ${title}`,
2064
- description: `${userFullName} - ${description}`,
2065
- },
2066
- ],
2067
- personName: userFullName,
2068
- personPhoto: userPhoto,
2069
- theme,
2070
- bannerUrl,
2071
- personType: personType ?? PersonTypes.NONE,
2072
- personIsSubscriber: personIsSubscriber ?? false,
2073
- };
2074
- return this.wishlistRepository.update(data);
2075
- }
2076
- delete(wishlistId) {
2077
- return this.wishlistRepository.delete({ id: wishlistId });
2078
- }
2079
- getWishlistBySlug(slug) {
2080
- const [id] = slug.split('-');
2081
- if (+id)
2082
- return this.wishlistRepository.get({ id });
2083
- return this.wishlistRepository.getWishlistBySlug(slug);
2084
- }
2085
- getWishlistsByPerson(personId) {
2086
- return this.wishlistRepository.getWishlistByPerson(personId);
2087
- }
2088
- async addProduct(wishlistId, productId) {
2089
- const wishlist = await this.wishlistRepository.get({ id: wishlistId });
2090
- const hasProduct = wishlist.products.some((p) => p == productId);
2091
- if (!hasProduct) {
2092
- wishlist.products = [...wishlist.products, productId];
2093
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2094
- }
2095
- return wishlist;
2096
- }
2097
- async removeProduct(wishlistId, productId) {
2098
- const wishlist = await this.wishlistRepository.get({ id: wishlistId });
2099
- const productIndex = wishlist.products.findIndex((p) => p == productId);
2100
- if (productIndex != -1) {
2101
- wishlist.products.splice(productIndex, 1);
2102
- if (!wishlist.products.length)
2103
- return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
2104
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2105
- }
2106
- return wishlist;
2107
- }
2108
- }
2109
- WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
2110
- WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
2111
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
2112
- type: Injectable
2113
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2114
- type: Inject,
2115
- args: ['WishlistRepository']
2116
- }] }, { type: i1$2.Shops, decorators: [{
2117
- type: Inject,
2118
- args: [DEFAULT_SHOP]
2119
- }] }, { type: undefined, decorators: [{
2120
- type: Inject,
2121
- args: ['ProductRepository']
2122
- }] }, { type: undefined, decorators: [{
2123
- type: Inject,
2124
- args: ['CategoryFilterRepository']
2125
- }] }, { type: undefined, decorators: [{
2126
- type: Inject,
2127
- args: ['CategoryRepository']
2128
- }] }, { type: undefined, decorators: [{
2129
- type: Inject,
2130
- args: ['ProductStockNotificationRepository']
2131
- }] }, { type: undefined, decorators: [{
2132
- type: Inject,
2133
- args: ['ProductSearch']
2134
- }] }]; } });
1946
+ class WishlistService {
1947
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productIndex) {
1948
+ this.wishlistRepository = wishlistRepository;
1949
+ this.shop = shop;
1950
+ const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1951
+ this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1952
+ this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1953
+ }
1954
+ getCatalogService() {
1955
+ return this.catalogService;
1956
+ }
1957
+ getCategoryService() {
1958
+ return this.categoryService;
1959
+ }
1960
+ async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1961
+ const data = {
1962
+ slug: '',
1963
+ name: title,
1964
+ description,
1965
+ metadatas: [
1966
+ {
1967
+ shop: this.shop,
1968
+ title: `${userFullName} - ${title}`,
1969
+ description: `${userFullName} - ${description}`,
1970
+ },
1971
+ ],
1972
+ shop: this.shop,
1973
+ shops: [this.shop],
1974
+ personId,
1975
+ personName: userFullName,
1976
+ personPhoto: userPhoto,
1977
+ brandCategory: false,
1978
+ published,
1979
+ theme,
1980
+ bannerUrl,
1981
+ personType: personType ?? PersonTypes.NONE,
1982
+ personIsSubscriber: personIsSubscriber ?? false,
1983
+ };
1984
+ const newWishlist = await this.wishlistRepository.create(data);
1985
+ await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
1986
+ return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
1987
+ }
1988
+ update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1989
+ const data = {
1990
+ id,
1991
+ name: title,
1992
+ description,
1993
+ published,
1994
+ metadatas: [
1995
+ {
1996
+ shop: this.shop,
1997
+ title: `${userFullName} - ${title}`,
1998
+ description: `${userFullName} - ${description}`,
1999
+ },
2000
+ ],
2001
+ personName: userFullName,
2002
+ personPhoto: userPhoto,
2003
+ theme,
2004
+ bannerUrl,
2005
+ personType: personType ?? PersonTypes.NONE,
2006
+ personIsSubscriber: personIsSubscriber ?? false,
2007
+ };
2008
+ return this.wishlistRepository.update(data);
2009
+ }
2010
+ delete(wishlistId) {
2011
+ return this.wishlistRepository.delete({ id: wishlistId });
2012
+ }
2013
+ getWishlistBySlug(slug) {
2014
+ const [id] = slug.split('-');
2015
+ if (+id)
2016
+ return this.wishlistRepository.get({ id });
2017
+ return this.wishlistRepository.getWishlistBySlug(slug);
2018
+ }
2019
+ getWishlistsByPerson(personId) {
2020
+ return this.wishlistRepository.getWishlistByPerson(personId);
2021
+ }
2022
+ async addProduct(wishlistId, productId) {
2023
+ const wishlist = await this.wishlistRepository.get({ id: wishlistId });
2024
+ const hasProduct = wishlist.products.some((p) => p == productId);
2025
+ if (!hasProduct) {
2026
+ wishlist.products = [...wishlist.products, productId];
2027
+ return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2028
+ }
2029
+ return wishlist;
2030
+ }
2031
+ async removeProduct(wishlistId, productId) {
2032
+ const wishlist = await this.wishlistRepository.get({ id: wishlistId });
2033
+ const productIndex = wishlist.products.findIndex((p) => p == productId);
2034
+ if (productIndex != -1) {
2035
+ wishlist.products.splice(productIndex, 1);
2036
+ if (!wishlist.products.length)
2037
+ return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
2038
+ return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
2039
+ }
2040
+ return wishlist;
2041
+ }
2042
+ }
2043
+ WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });
2044
+ WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
2045
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
2046
+ type: Injectable
2047
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2048
+ type: Inject,
2049
+ args: ['WishlistRepository']
2050
+ }] }, { type: i1$2.Shops, decorators: [{
2051
+ type: Inject,
2052
+ args: [DEFAULT_SHOP]
2053
+ }] }, { type: undefined, decorators: [{
2054
+ type: Inject,
2055
+ args: ['ProductRepository']
2056
+ }] }, { type: undefined, decorators: [{
2057
+ type: Inject,
2058
+ args: ['CategoryFilterRepository']
2059
+ }] }, { type: undefined, decorators: [{
2060
+ type: Inject,
2061
+ args: ['CategoryRepository']
2062
+ }] }, { type: undefined, decorators: [{
2063
+ type: Inject,
2064
+ args: ['ProductStockNotificationRepository']
2065
+ }] }, { type: i1$2.ProductsIndex }]; } });
2135
2066
 
2136
- class CheckoutSubscriptionService {
2137
- constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
2138
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
2139
- this.dataPersistence = dataPersistence;
2140
- this.couponService = couponService;
2141
- }
2142
- getCheckoutSubscription(checkoutData) {
2143
- return this.dataPersistence
2144
- .get('checkoutSubscriptionId')
2145
- .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
2146
- }
2147
- clearCheckoutSubscriptionFromSession() {
2148
- return this.dataPersistence.remove('checkoutSubscriptionId');
2149
- }
2150
- checkCoupon(nickname, userEmail) {
2151
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
2152
- .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
2153
- .pipe()));
2154
- }
2155
- calcDiscountSubscription(coupon) {
2156
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
2157
- }
2158
- async createCheckoutSubscription(checkoutData) {
2159
- const checkout = await this.checkoutSubscriptionRepository.create({
2160
- createdAt: new Date(),
2161
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
2162
- });
2163
- await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2164
- return checkout;
2165
- }
2166
- }
2167
- CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
2168
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
2169
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
2170
- type: Injectable
2171
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2172
- type: Inject,
2173
- args: ['CheckoutSubscriptionRepository']
2174
- }] }, { type: undefined, decorators: [{
2175
- type: Inject,
2176
- args: [PERSISTENCE_PROVIDER]
2067
+ class CheckoutSubscriptionService {
2068
+ constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
2069
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
2070
+ this.dataPersistence = dataPersistence;
2071
+ this.couponService = couponService;
2072
+ }
2073
+ getCheckoutSubscription(checkoutData) {
2074
+ return this.dataPersistence
2075
+ .get('checkoutSubscriptionId')
2076
+ .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
2077
+ }
2078
+ clearCheckoutSubscriptionFromSession() {
2079
+ return this.dataPersistence.remove('checkoutSubscriptionId');
2080
+ }
2081
+ checkCoupon(nickname, userEmail) {
2082
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
2083
+ .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
2084
+ .pipe()));
2085
+ }
2086
+ calcDiscountSubscription(coupon) {
2087
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
2088
+ }
2089
+ async createCheckoutSubscription(checkoutData) {
2090
+ const checkout = await this.checkoutSubscriptionRepository.create({
2091
+ createdAt: new Date(),
2092
+ ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
2093
+ });
2094
+ await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2095
+ return checkout;
2096
+ }
2097
+ }
2098
+ CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
2099
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
2100
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
2101
+ type: Injectable
2102
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2103
+ type: Inject,
2104
+ args: ['CheckoutSubscriptionRepository']
2105
+ }] }, { type: undefined, decorators: [{
2106
+ type: Inject,
2107
+ args: [PERSISTENCE_PROVIDER]
2177
2108
  }] }, { type: CouponService }]; } });
2178
2109
 
2179
- class UtilHelper {
2180
- static createSlug(name) {
2181
- return name
2182
- .toLowerCase()
2183
- .replace(/\s+/g, '-') // Replace spaces with -
2184
- .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
2185
- .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
2186
- .replace(/[ìíïî]/g, 'i') // Replace spaces with -
2187
- .replace(/[õòóöô]/g, 'o') // Replace spaces with -
2188
- .replace(/[ùúüû]/g, 'u') // Replace spaces with -
2189
- .replace(/[ñ]/g, 'n') // Replace spaces with -
2190
- .replace(/[ç]/g, 'c') // Replace spaces with -
2191
- .replace(/[&]/g, 'and') // Replace spaces with -
2192
- .replace(/[^\w\-]+/g, '') // Remove all non-word chars
2193
- .replace(/\-\-+/g, '-'); // Replace multiple - with single -
2194
- }
2110
+ class UtilHelper {
2111
+ static createSlug(name) {
2112
+ return name
2113
+ .toLowerCase()
2114
+ .replace(/\s+/g, '-') // Replace spaces with -
2115
+ .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
2116
+ .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
2117
+ .replace(/[ìíïî]/g, 'i') // Replace spaces with -
2118
+ .replace(/[õòóöô]/g, 'o') // Replace spaces with -
2119
+ .replace(/[ùúüû]/g, 'u') // Replace spaces with -
2120
+ .replace(/[ñ]/g, 'n') // Replace spaces with -
2121
+ .replace(/[ç]/g, 'c') // Replace spaces with -
2122
+ .replace(/[&]/g, 'and') // Replace spaces with -
2123
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
2124
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
2125
+ }
2195
2126
  }
2196
2127
 
2197
- class HomeShopService {
2198
- get homeId() {
2199
- if (this.defaultShop === Shops.GLAMSHOP)
2200
- return 'glamshop';
2201
- if (this.defaultShop === Shops.MENSMARKET)
2202
- return 'mens_market';
2203
- return null;
2204
- }
2205
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
2206
- this.categoryRepository = categoryRepository;
2207
- this.homeRepository = homeRepository;
2208
- this.productRepository = productRepository;
2209
- this.defaultShop = defaultShop;
2210
- this.buildCategoryGroupWithRequiredData = (group) => ({
2211
- category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
2212
- products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
2213
- 'id',
2214
- 'price',
2215
- 'reviews',
2216
- 'hasVariants',
2217
- 'slug',
2218
- 'sku',
2219
- 'stock',
2220
- 'costPrice',
2221
- 'images',
2222
- 'miniatures',
2223
- 'name',
2224
- 'weight',
2225
- 'rate',
2226
- 'type',
2227
- 'brand',
2228
- ]))) || [],
2229
- });
2230
- }
2231
- getHomeData() {
2232
- return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
2233
- ? of(home)
2234
- : forkJoin([
2235
- this.getDiscoverProducts(this.gender),
2236
- this.getFeaturedProducts(this.gender),
2237
- this.getVerticalProducts(this.gender),
2238
- ]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
2239
- discoverProducts,
2240
- featuredProducts,
2241
- verticalProducts,
2242
- })), concatMap((data) => this.saveHomeData(data)))));
2243
- }
2244
- getBanners(type) {
2245
- return this.getHomeConfiguration().pipe(map((home) => {
2246
- if (type === 'brand')
2247
- return home.brandsCarousel;
2248
- if (type === 'buyToWin')
2249
- return [home.buyToWinBanner];
2250
- if (type === 'block')
2251
- return home.blockBanners;
2252
- if (type === 'blog')
2253
- return [home.blogBanner];
2254
- return [];
2255
- }));
2256
- }
2257
- getMinValueForFreeShipping() {
2258
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
2259
- }
2260
- getDiscoverProducts(gender) {
2261
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2262
- }
2263
- getFeaturedProducts(gender) {
2264
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2265
- }
2266
- getVerticalProducts(gender) {
2267
- 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({
2268
- filters: {
2269
- categories: { operator: Where.IN, value: [category.id] },
2270
- ...(gender ? { tags: { operator: Where.IN, value: [gender] } } : {}),
2271
- },
2272
- limits: { limit: 12 },
2273
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
2274
- }
2275
- getHomeConfiguration() {
2276
- return of(this.homeConfiguration).pipe(concatMap((home) => home
2277
- ? of(home)
2278
- : !this.homeId
2279
- ? throwError(new RequiredArgumentError(['homeId']))
2280
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
2281
- }
2282
- saveHomeData(homeData) {
2283
- const data = {
2284
- createdAt: new Date(),
2285
- expiresAt: add(new Date(), { hours: 1 }),
2286
- data: homeData,
2287
- };
2288
- return from(this.homeRepository.update({
2289
- id: this.homeId,
2290
- data,
2291
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
2292
- }
2293
- get gender() {
2294
- return this.homeId === 'mens_market' ? 'masculino' : undefined;
2295
- }
2296
- }
2297
- 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 });
2298
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
2299
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
2300
- type: Injectable
2301
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2302
- type: Inject,
2303
- args: ['CategoryRepository']
2304
- }] }, { type: undefined, decorators: [{
2305
- type: Inject,
2306
- args: ['HomeRepository']
2307
- }] }, { type: undefined, decorators: [{
2308
- type: Inject,
2309
- args: ['ProductRepository']
2310
- }] }, { type: i1$2.Shops, decorators: [{
2311
- type: Inject,
2312
- args: [DEFAULT_SHOP]
2128
+ class HomeShopService {
2129
+ get homeId() {
2130
+ if (this.defaultShop === Shops.GLAMSHOP)
2131
+ return 'glamshop';
2132
+ if (this.defaultShop === Shops.MENSMARKET)
2133
+ return 'mens_market';
2134
+ return null;
2135
+ }
2136
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
2137
+ this.categoryRepository = categoryRepository;
2138
+ this.homeRepository = homeRepository;
2139
+ this.productRepository = productRepository;
2140
+ this.defaultShop = defaultShop;
2141
+ this.buildCategoryGroupWithRequiredData = (group) => ({
2142
+ category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
2143
+ products: group?.products?.map((product) => Product.toInstance(pick(product?.toPlain() || {}, [
2144
+ 'id',
2145
+ 'price',
2146
+ 'reviews',
2147
+ 'hasVariants',
2148
+ 'slug',
2149
+ 'sku',
2150
+ 'stock',
2151
+ 'costPrice',
2152
+ 'images',
2153
+ 'miniatures',
2154
+ 'name',
2155
+ 'weight',
2156
+ 'rate',
2157
+ 'type',
2158
+ 'brand',
2159
+ ]))) || [],
2160
+ });
2161
+ }
2162
+ getHomeData() {
2163
+ return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
2164
+ ? of(home)
2165
+ : forkJoin([
2166
+ this.getDiscoverProducts(this.gender),
2167
+ this.getFeaturedProducts(this.gender),
2168
+ this.getVerticalProducts(this.gender),
2169
+ ]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
2170
+ discoverProducts,
2171
+ featuredProducts,
2172
+ verticalProducts,
2173
+ })), concatMap((data) => this.saveHomeData(data)))));
2174
+ }
2175
+ getBanners(type) {
2176
+ return this.getHomeConfiguration().pipe(map((home) => {
2177
+ if (type === 'brand')
2178
+ return home.brandsCarousel;
2179
+ if (type === 'buyToWin')
2180
+ return [home.buyToWinBanner];
2181
+ if (type === 'block')
2182
+ return home.blockBanners;
2183
+ if (type === 'blog')
2184
+ return [home.blogBanner];
2185
+ return [];
2186
+ }));
2187
+ }
2188
+ getMinValueForFreeShipping() {
2189
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
2190
+ }
2191
+ getDiscoverProducts(gender) {
2192
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2193
+ }
2194
+ getFeaturedProducts(gender) {
2195
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2196
+ }
2197
+ getVerticalProducts(gender) {
2198
+ 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({
2199
+ filters: {
2200
+ categories: { operator: Where.IN, value: [category.id] },
2201
+ ...(gender ? { tags: { operator: Where.IN, value: [gender] } } : {}),
2202
+ },
2203
+ limits: { limit: 12 },
2204
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
2205
+ }
2206
+ getHomeConfiguration() {
2207
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
2208
+ ? of(home)
2209
+ : !this.homeId
2210
+ ? throwError(new RequiredArgumentError(['homeId']))
2211
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
2212
+ }
2213
+ saveHomeData(homeData) {
2214
+ const data = {
2215
+ createdAt: new Date(),
2216
+ expiresAt: add(new Date(), { hours: 1 }),
2217
+ data: homeData,
2218
+ };
2219
+ return from(this.homeRepository.update({
2220
+ id: this.homeId,
2221
+ data,
2222
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
2223
+ }
2224
+ get gender() {
2225
+ return this.homeId === 'mens_market' ? 'masculino' : undefined;
2226
+ }
2227
+ }
2228
+ 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 });
2229
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService });
2230
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: HomeShopService, decorators: [{
2231
+ type: Injectable
2232
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2233
+ type: Inject,
2234
+ args: ['CategoryRepository']
2235
+ }] }, { type: undefined, decorators: [{
2236
+ type: Inject,
2237
+ args: ['HomeRepository']
2238
+ }] }, { type: undefined, decorators: [{
2239
+ type: Inject,
2240
+ args: ['ProductRepository']
2241
+ }] }, { type: i1$2.Shops, decorators: [{
2242
+ type: Inject,
2243
+ args: [DEFAULT_SHOP]
2313
2244
  }] }]; } });
2314
2245
 
2315
- class OrderService {
2316
- constructor(angularFirestore, orderRepository) {
2317
- this.angularFirestore = angularFirestore;
2318
- this.orderRepository = orderRepository;
2319
- this.orderSubject = new Subject();
2320
- }
2321
- getOrder(id) {
2322
- docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
2323
- .pipe(map((doc) => Order.toInstance(doc.data())))
2324
- .subscribe((doc) => this.orderSubject.next(doc));
2325
- return this.orderSubject;
2326
- }
2327
- }
2328
- 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 });
2329
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
2330
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
2331
- type: Injectable
2332
- }], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type: i1$2.OrderFirestoreRepository, decorators: [{
2333
- type: Inject,
2334
- args: ['OrderRepository']
2246
+ class OrderService {
2247
+ constructor(angularFirestore, orderRepository) {
2248
+ this.angularFirestore = angularFirestore;
2249
+ this.orderRepository = orderRepository;
2250
+ this.orderSubject = new Subject();
2251
+ }
2252
+ getOrder(id) {
2253
+ docSnapshots(doc(this.angularFirestore, `${this.orderRepository.collectionName}/${id}`))
2254
+ .pipe(map((doc) => Order.toInstance(doc.data())))
2255
+ .subscribe((doc) => this.orderSubject.next(doc));
2256
+ return this.orderSubject;
2257
+ }
2258
+ }
2259
+ 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 });
2260
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService });
2261
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
2262
+ type: Injectable
2263
+ }], ctorParameters: function () { return [{ type: i1$1.Firestore }, { type: i1$2.OrderFirestoreRepository, decorators: [{
2264
+ type: Inject,
2265
+ args: ['OrderRepository']
2335
2266
  }] }]; } });
2336
2267
 
2337
- class ShippingService {
2338
- constructor(http, apiUrl, homeService) {
2339
- this.http = http;
2340
- this.apiUrl = apiUrl;
2341
- this.homeService = homeService;
2342
- }
2343
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
2344
- return combineLatest([
2345
- this.homeService.getHomeData(),
2346
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
2347
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
2348
- let shippingMethods = shippingMethodsResponse.result;
2349
- if (!shippingMethods.length)
2350
- return [];
2351
- shippingMethods = shippingMethods.map((shippingMethod) => {
2352
- if (shippingMethod.ShippingCompanyName == 'Same Day EG')
2353
- shippingMethod.ShippingCompanyName = 'Same Day';
2354
- return shippingMethod;
2355
- });
2356
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
2357
- if (this.isHolidays(datasSameDayNotAvaliable)) {
2358
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
2359
- }
2360
- if (totalPrice >= 200) {
2361
- shippingMethods = shippingMethods.map((s) => {
2362
- if (s.serviceName !== 'Same Day')
2363
- return { ...s, totalPrice: 0 };
2364
- else
2365
- return s;
2366
- });
2367
- }
2368
- if (shop == Shops.GLAMSHOP)
2369
- return shippingMethods;
2370
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
2371
- shippingMethods = shippingMethods.map((s) => {
2372
- if (s.serviceName == 'Same Day')
2373
- return { ...s, totalPrice: s.totalPrice / 2 };
2374
- else
2375
- return { ...s, totalPrice: 0 };
2376
- });
2377
- }
2378
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
2379
- shippingMethods = shippingMethods.map((s) => {
2380
- return { ...s, totalPrice: s.totalPrice / 2 };
2381
- });
2382
- }
2383
- return shippingMethods;
2384
- }));
2385
- }
2386
- isFreeShippingBySubscription(shop, subscriptionPlan) {
2387
- if (!subscriptionPlan)
2388
- return false;
2389
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
2390
- return true;
2391
- return false;
2392
- }
2393
- isHalfShippingBySubscription(shop, subscriptionPlan) {
2394
- if (!subscriptionPlan)
2395
- return false;
2396
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
2397
- return true;
2398
- }
2399
- return false;
2400
- }
2401
- isHolidays(datas) {
2402
- const today = new Date();
2403
- for (const key in datas) {
2404
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
2405
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
2406
- if (start > end)
2407
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
2408
- if (today >= start && today <= end)
2409
- return true;
2410
- }
2411
- return false;
2412
- }
2413
- }
2414
- 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 });
2415
- ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
2416
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
2417
- type: Injectable
2418
- }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
2419
- type: Inject,
2420
- args: [BACKEND_URL]
2268
+ class ShippingService {
2269
+ constructor(http, apiUrl, homeService) {
2270
+ this.http = http;
2271
+ this.apiUrl = apiUrl;
2272
+ this.homeService = homeService;
2273
+ }
2274
+ getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
2275
+ return combineLatest([
2276
+ this.homeService.getHomeData(),
2277
+ this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
2278
+ ]).pipe(map(([datas, shippingMethodsResponse]) => {
2279
+ let shippingMethods = shippingMethodsResponse.result;
2280
+ if (!shippingMethods.length)
2281
+ return [];
2282
+ shippingMethods = shippingMethods.map((shippingMethod) => {
2283
+ if (shippingMethod.ShippingCompanyName == 'Same Day EG')
2284
+ shippingMethod.ShippingCompanyName = 'Same Day';
2285
+ return shippingMethod;
2286
+ });
2287
+ const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
2288
+ if (this.isHolidays(datasSameDayNotAvaliable)) {
2289
+ shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
2290
+ }
2291
+ if (totalPrice >= 200) {
2292
+ shippingMethods = shippingMethods.map((s) => {
2293
+ if (s.serviceName !== 'Same Day')
2294
+ return { ...s, totalPrice: 0 };
2295
+ else
2296
+ return s;
2297
+ });
2298
+ }
2299
+ if (shop == Shops.GLAMSHOP)
2300
+ return shippingMethods;
2301
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
2302
+ shippingMethods = shippingMethods.map((s) => {
2303
+ if (s.serviceName == 'Same Day')
2304
+ return { ...s, totalPrice: s.totalPrice / 2 };
2305
+ else
2306
+ return { ...s, totalPrice: 0 };
2307
+ });
2308
+ }
2309
+ if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
2310
+ shippingMethods = shippingMethods.map((s) => {
2311
+ return { ...s, totalPrice: s.totalPrice / 2 };
2312
+ });
2313
+ }
2314
+ return shippingMethods;
2315
+ }));
2316
+ }
2317
+ isFreeShippingBySubscription(shop, subscriptionPlan) {
2318
+ if (!subscriptionPlan)
2319
+ return false;
2320
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
2321
+ return true;
2322
+ return false;
2323
+ }
2324
+ isHalfShippingBySubscription(shop, subscriptionPlan) {
2325
+ if (!subscriptionPlan)
2326
+ return false;
2327
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
2328
+ return true;
2329
+ }
2330
+ return false;
2331
+ }
2332
+ isHolidays(datas) {
2333
+ const today = new Date();
2334
+ for (const key in datas) {
2335
+ let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
2336
+ let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
2337
+ if (start > end)
2338
+ end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
2339
+ if (today >= start && today <= end)
2340
+ return true;
2341
+ }
2342
+ return false;
2343
+ }
2344
+ }
2345
+ 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 });
2346
+ ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
2347
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
2348
+ type: Injectable
2349
+ }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
2350
+ type: Inject,
2351
+ args: [BACKEND_URL]
2421
2352
  }] }, { type: HomeShopService }]; } });
2422
2353
 
2423
- class AngularConnectModule {
2424
- static initializeApp(defaultShop, options, nameOrConfig) {
2425
- return {
2426
- ngModule: AngularConnectModule,
2427
- providers: [
2428
- {
2429
- provide: CATEGORY_STRUCTURE,
2430
- useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
2431
- ? OldCategoryStructureAdapter
2432
- : NewCategoryStructureAdapter,
2433
- },
2434
- { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2435
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2436
- ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2437
- ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2438
- ...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2439
- ...(isNil(options?.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
2440
- ...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2441
- ...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2442
- ...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
2443
- ],
2444
- };
2445
- }
2446
- }
2447
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2448
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
2449
- AngularVertexSeachModule,
2450
- AngularFirebaseAuthModule,
2451
- AngularFirestoreModule,
2452
- AngularHasuraGraphQLModule] });
2453
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
2454
- AuthService,
2455
- CartService,
2456
- CatalogService,
2457
- CategoryService,
2458
- CheckoutService,
2459
- CheckoutSubscriptionService,
2460
- CouponService,
2461
- HomeShopService,
2462
- OrderService,
2463
- ShippingService,
2464
- WishlistService,
2465
- {
2466
- provide: UpdateUserImage,
2467
- useFactory: (userRepository, fileUploader) => {
2468
- return new UpdateUserImage(userRepository, fileUploader);
2469
- },
2470
- deps: ['UserRepository', 'FileUploaderService'],
2471
- },
2472
- {
2473
- provide: 'FileUploaderService',
2474
- useFactory: (storage, baseUrl) => {
2475
- return new FirebaseFileUploaderService(storage, baseUrl);
2476
- },
2477
- deps: [Storage, STORAGE_BASE_URL],
2478
- },
2479
- {
2480
- provide: 'ProductSearch',
2481
- useExisting: ProductsVertexSearch,
2482
- },
2483
- ], imports: [provideFirebaseApp((injector) => {
2484
- const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2485
- try {
2486
- return getApp(appName);
2487
- }
2488
- catch (error) {
2489
- return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2490
- }
2491
- }),
2492
- provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2493
- AngularElasticSeachModule,
2494
- AngularVertexSeachModule,
2495
- AngularFirebaseAuthModule,
2496
- AngularFirestoreModule,
2497
- AngularHasuraGraphQLModule] });
2498
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
2499
- type: NgModule,
2500
- args: [{
2501
- imports: [
2502
- provideFirebaseApp((injector) => {
2503
- const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2504
- try {
2505
- return getApp(appName);
2506
- }
2507
- catch (error) {
2508
- return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2509
- }
2510
- }),
2511
- provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2512
- AngularElasticSeachModule,
2513
- AngularVertexSeachModule,
2514
- AngularFirebaseAuthModule,
2515
- AngularFirestoreModule,
2516
- AngularHasuraGraphQLModule,
2517
- ],
2518
- providers: [
2519
- AuthService,
2520
- CartService,
2521
- CatalogService,
2522
- CategoryService,
2523
- CheckoutService,
2524
- CheckoutSubscriptionService,
2525
- CouponService,
2526
- HomeShopService,
2527
- OrderService,
2528
- ShippingService,
2529
- WishlistService,
2530
- {
2531
- provide: UpdateUserImage,
2532
- useFactory: (userRepository, fileUploader) => {
2533
- return new UpdateUserImage(userRepository, fileUploader);
2534
- },
2535
- deps: ['UserRepository', 'FileUploaderService'],
2536
- },
2537
- {
2538
- provide: 'FileUploaderService',
2539
- useFactory: (storage, baseUrl) => {
2540
- return new FirebaseFileUploaderService(storage, baseUrl);
2541
- },
2542
- deps: [Storage, STORAGE_BASE_URL],
2543
- },
2544
- {
2545
- provide: 'ProductSearch',
2546
- useExisting: ProductsVertexSearch,
2547
- },
2548
- ],
2549
- }]
2354
+ class AngularConnectModule {
2355
+ static initializeApp(defaultShop, options, nameOrConfig) {
2356
+ return {
2357
+ ngModule: AngularConnectModule,
2358
+ providers: [
2359
+ {
2360
+ provide: CATEGORY_STRUCTURE,
2361
+ useClass: isNil(options?.oldCategoryStructure) || options?.oldCategoryStructure
2362
+ ? OldCategoryStructureAdapter
2363
+ : NewCategoryStructureAdapter,
2364
+ },
2365
+ { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2366
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2367
+ ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2368
+ ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2369
+ ...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2370
+ ...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2371
+ ...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2372
+ ...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
2373
+ ],
2374
+ };
2375
+ }
2376
+ }
2377
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2378
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
2379
+ AngularFirebaseAuthModule,
2380
+ AngularFirestoreModule,
2381
+ AngularHasuraGraphQLModule] });
2382
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, providers: [
2383
+ AuthService,
2384
+ CartService,
2385
+ CatalogService,
2386
+ CategoryService,
2387
+ CheckoutService,
2388
+ CheckoutSubscriptionService,
2389
+ CouponService,
2390
+ HomeShopService,
2391
+ OrderService,
2392
+ ShippingService,
2393
+ WishlistService,
2394
+ {
2395
+ provide: UpdateUserImage,
2396
+ useFactory: (userRepository, fileUploader) => {
2397
+ return new UpdateUserImage(userRepository, fileUploader);
2398
+ },
2399
+ deps: ['UserRepository', 'FileUploaderService'],
2400
+ },
2401
+ {
2402
+ provide: 'FileUploaderService',
2403
+ useFactory: (storage, baseUrl) => {
2404
+ return new FirebaseFileUploaderService(storage, baseUrl);
2405
+ },
2406
+ deps: [Storage, STORAGE_BASE_URL],
2407
+ },
2408
+ ], imports: [provideFirebaseApp((injector) => {
2409
+ const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2410
+ try {
2411
+ return getApp(appName);
2412
+ }
2413
+ catch (error) {
2414
+ return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2415
+ }
2416
+ }),
2417
+ provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2418
+ AngularElasticSeachModule,
2419
+ AngularFirebaseAuthModule,
2420
+ AngularFirestoreModule,
2421
+ AngularHasuraGraphQLModule] });
2422
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, decorators: [{
2423
+ type: NgModule,
2424
+ args: [{
2425
+ imports: [
2426
+ provideFirebaseApp((injector) => {
2427
+ const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2428
+ try {
2429
+ return getApp(appName);
2430
+ }
2431
+ catch (error) {
2432
+ return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2433
+ }
2434
+ }),
2435
+ provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2436
+ AngularElasticSeachModule,
2437
+ AngularFirebaseAuthModule,
2438
+ AngularFirestoreModule,
2439
+ AngularHasuraGraphQLModule,
2440
+ ],
2441
+ providers: [
2442
+ AuthService,
2443
+ CartService,
2444
+ CatalogService,
2445
+ CategoryService,
2446
+ CheckoutService,
2447
+ CheckoutSubscriptionService,
2448
+ CouponService,
2449
+ HomeShopService,
2450
+ OrderService,
2451
+ ShippingService,
2452
+ WishlistService,
2453
+ {
2454
+ provide: UpdateUserImage,
2455
+ useFactory: (userRepository, fileUploader) => {
2456
+ return new UpdateUserImage(userRepository, fileUploader);
2457
+ },
2458
+ deps: ['UserRepository', 'FileUploaderService'],
2459
+ },
2460
+ {
2461
+ provide: 'FileUploaderService',
2462
+ useFactory: (storage, baseUrl) => {
2463
+ return new FirebaseFileUploaderService(storage, baseUrl);
2464
+ },
2465
+ deps: [Storage, STORAGE_BASE_URL],
2466
+ },
2467
+ ],
2468
+ }]
2550
2469
  }] });
2551
2470
 
2552
- /**
2553
- * Generated bundle index. Do not edit.
2471
+ /**
2472
+ * Generated bundle index. Do not edit.
2554
2473
  */
2555
2474
 
2556
2475
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };