@infrab4a/connect-angular 4.4.2-beta.2 → 4.4.2

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