@infrab4a/connect-angular 3.11.0 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/angular-connect.module.d.ts +7 -9
  2. package/angular-firebase-auth.module.d.ts +6 -4
  3. package/angular-firestore.module.d.ts +7 -5
  4. package/consts/firebase-const.d.ts +3 -0
  5. package/consts/index.d.ts +1 -2
  6. package/esm2020/angular-connect.module.mjs +49 -0
  7. package/esm2020/angular-elastic-search.module.mjs +38 -0
  8. package/esm2020/angular-firebase-auth.module.mjs +130 -0
  9. package/esm2020/angular-firestore.module.mjs +358 -0
  10. package/esm2020/angular-hasura-graphql.module.mjs +90 -0
  11. package/esm2020/consts/firebase-const.mjs +4 -0
  12. package/esm2020/consts/index.mjs +5 -0
  13. package/esm2020/index.mjs +6 -0
  14. package/esm2020/services/auth.service.mjs +37 -0
  15. package/esm2020/services/cart.service.mjs +143 -0
  16. package/esm2020/services/checkout-subscription.service.mjs +51 -0
  17. package/esm2020/services/checkout.service.mjs +73 -0
  18. package/esm2020/services/coupon.service.mjs +226 -0
  19. package/esm2020/services/errors/group-invalid-coupon.error.mjs +8 -0
  20. package/esm2020/services/errors/index.mjs +3 -0
  21. package/esm2020/services/errors/invalid-coupon.error.mjs +7 -0
  22. package/esm2020/services/home-shop.service.mjs +114 -0
  23. package/esm2020/services/index.mjs +8 -0
  24. package/esm2020/services/order.service.mjs +30 -0
  25. package/esm2020/types/firebase-app-config.type.mjs +2 -0
  26. package/esm2020/types/index.mjs +2 -0
  27. package/fesm2015/infrab4a-connect-angular.mjs +1336 -0
  28. package/fesm2015/infrab4a-connect-angular.mjs.map +1 -0
  29. package/fesm2020/infrab4a-connect-angular.mjs +1291 -0
  30. package/fesm2020/infrab4a-connect-angular.mjs.map +1 -0
  31. package/index.d.ts +2 -2
  32. package/package.json +24 -12
  33. package/services/auth.service.d.ts +3 -4
  34. package/services/cart.service.d.ts +2 -9
  35. package/services/coupon.service.d.ts +10 -13
  36. package/services/errors/group-invalid-coupon.error.d.ts +6 -0
  37. package/services/errors/index.d.ts +2 -0
  38. package/services/errors/invalid-coupon.error.d.ts +4 -0
  39. package/services/index.d.ts +2 -5
  40. package/services/order.service.d.ts +2 -2
  41. package/types/firebase-app-config.type.d.ts +1 -0
  42. package/types/index.d.ts +1 -0
  43. package/bundles/infrab4a-connect-angular.umd.js +0 -2872
  44. package/bundles/infrab4a-connect-angular.umd.js.map +0 -1
  45. package/consts/backend-url.const.d.ts +0 -1
  46. package/consts/category-structure.d.ts +0 -1
  47. package/esm2015/angular-connect.module.js +0 -66
  48. package/esm2015/angular-elastic-search.module.js +0 -34
  49. package/esm2015/angular-firebase-auth.module.js +0 -113
  50. package/esm2015/angular-firestore.module.js +0 -394
  51. package/esm2015/angular-hasura-graphql.module.js +0 -196
  52. package/esm2015/consts/backend-url.const.js +0 -2
  53. package/esm2015/consts/category-structure.js +0 -2
  54. package/esm2015/consts/index.js +0 -6
  55. package/esm2015/index.js +0 -6
  56. package/esm2015/services/auth.service.js +0 -42
  57. package/esm2015/services/cart.service.js +0 -281
  58. package/esm2015/services/catalog/adapters/category-structure.adapter.js +0 -2
  59. package/esm2015/services/catalog/adapters/index.js +0 -4
  60. package/esm2015/services/catalog/adapters/new-category-structure.adapter.js +0 -51
  61. package/esm2015/services/catalog/adapters/old-category-structure.adapter.js +0 -27
  62. package/esm2015/services/catalog/catalog.service.js +0 -126
  63. package/esm2015/services/catalog/category.service.js +0 -56
  64. package/esm2015/services/catalog/enums/index.js +0 -2
  65. package/esm2015/services/catalog/enums/product-sorts.enum.js +0 -11
  66. package/esm2015/services/catalog/index.js +0 -7
  67. package/esm2015/services/catalog/models/category-with-tree.model.js +0 -10
  68. package/esm2015/services/catalog/models/index.js +0 -2
  69. package/esm2015/services/catalog/types/index.js +0 -2
  70. package/esm2015/services/catalog/types/product-sort.type.js +0 -2
  71. package/esm2015/services/catalog/wishlist.service.js +0 -112
  72. package/esm2015/services/checkout-subscription.service.js +0 -53
  73. package/esm2015/services/checkout.service.js +0 -70
  74. package/esm2015/services/coupon.service.js +0 -244
  75. package/esm2015/services/helpers/index.js +0 -2
  76. package/esm2015/services/helpers/util.helper.js +0 -18
  77. package/esm2015/services/home-shop.service.js +0 -116
  78. package/esm2015/services/index.js +0 -11
  79. package/esm2015/services/order.service.js +0 -32
  80. package/esm2015/services/shipping.service.js +0 -98
  81. package/esm2015/services/types/shipping-methods.type.js +0 -2
  82. package/fesm2015/infrab4a-connect-angular.js +0 -2048
  83. package/fesm2015/infrab4a-connect-angular.js.map +0 -1
  84. package/infrab4a-connect-angular.d.ts +0 -5
  85. package/services/catalog/adapters/category-structure.adapter.d.ts +0 -4
  86. package/services/catalog/adapters/index.d.ts +0 -3
  87. package/services/catalog/adapters/new-category-structure.adapter.d.ts +0 -14
  88. package/services/catalog/adapters/old-category-structure.adapter.d.ts +0 -10
  89. package/services/catalog/catalog.service.d.ts +0 -80
  90. package/services/catalog/category.service.d.ts +0 -15
  91. package/services/catalog/enums/index.d.ts +0 -1
  92. package/services/catalog/enums/product-sorts.enum.d.ts +0 -9
  93. package/services/catalog/index.d.ts +0 -6
  94. package/services/catalog/models/category-with-tree.model.d.ts +0 -4
  95. package/services/catalog/models/index.d.ts +0 -1
  96. package/services/catalog/types/index.d.ts +0 -1
  97. package/services/catalog/types/product-sort.type.d.ts +0 -2
  98. package/services/catalog/wishlist.service.d.ts +0 -22
  99. package/services/helpers/index.d.ts +0 -1
  100. package/services/helpers/util.helper.d.ts +0 -3
  101. package/services/shipping.service.d.ts +0 -19
  102. package/services/types/shipping-methods.type.d.ts +0 -12
  103. /package/{esm2015/consts/default-shop.const.js → esm2020/consts/default-shop.const.mjs} +0 -0
  104. /package/{esm2015/consts/es-config.const.js → esm2020/consts/es-config.const.mjs} +0 -0
  105. /package/{esm2015/consts/hasura-options.const.js → esm2020/consts/hasura-options.const.mjs} +0 -0
  106. /package/{esm2015/infrab4a-connect-angular.js → esm2020/infrab4a-connect-angular.mjs} +0 -0
  107. /package/{esm2015/services/types/index.js → esm2020/services/types/index.mjs} +0 -0
  108. /package/{esm2015/services/types/required-checkout-data.type.js → esm2020/services/types/required-checkout-data.type.mjs} +0 -0
  109. /package/{esm2015/services/types/required-checkout-subscription-data.type.js → esm2020/services/types/required-checkout-subscription-data.type.mjs} +0 -0
@@ -1,2048 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { NgModule, APP_INITIALIZER, Injectable, Inject } from '@angular/core';
3
- import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
4
- import * as i1$1 from '@infrab4a/connect';
5
- import { ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword } from '@infrab4a/connect';
6
- import * as i1$2 from '@angular/fire/firestore';
7
- import { AngularFirestore } from '@angular/fire/firestore';
8
- import * as i1 from '@angular/fire/auth';
9
- import { AngularFireAuth } from '@angular/fire/auth';
10
- import { of, combineLatest, from, throwError, Subject, iif, forkJoin } from 'rxjs';
11
- import { catchError, map, mergeMap, concatMap, tap } from 'rxjs/operators';
12
- import { __awaiter, __decorate, __metadata } from 'tslib';
13
- import cookie from 'js-cookie';
14
- import { Type } from 'class-transformer';
15
- import * as i1$3 from '@angular/common/http';
16
-
17
- const ES_CONFIG = 'ES_CONFIG';
18
-
19
- class AngularElasticSeachModule {
20
- static initializeApp(options) {
21
- return {
22
- ngModule: AngularElasticSeachModule,
23
- providers: [{ provide: ES_CONFIG, useValue: options }],
24
- };
25
- }
26
- }
27
- AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
28
- AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
29
- AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
30
- {
31
- provide: ProductsIndex,
32
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
33
- deps: [ES_CONFIG],
34
- },
35
- ] });
36
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
37
- type: NgModule,
38
- args: [{
39
- providers: [
40
- {
41
- provide: ProductsIndex,
42
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
43
- deps: [ES_CONFIG],
44
- },
45
- ],
46
- }]
47
- }] });
48
-
49
- class AngularFirestoreModule {
50
- static initializeApp(options, nameOrConfig) {
51
- return {
52
- ngModule: AngularFirestoreModule,
53
- providers: [
54
- { provide: FIREBASE_OPTIONS, useValue: options.firebase },
55
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
56
- { provide: ES_CONFIG, useValue: options.elasticSearch },
57
- ],
58
- };
59
- }
60
- }
61
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
62
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
63
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
64
- {
65
- provide: 'BeautyProfileRepository',
66
- useFactory: (firestore, userRepository) => {
67
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
68
- },
69
- deps: [AngularFirestore, 'UserRepository'],
70
- },
71
- {
72
- provide: 'Buy2WinRepository',
73
- useFactory: (firestore) => {
74
- return new Buy2WinFirestoreRepository(firestore.firestore);
75
- },
76
- deps: [AngularFirestore],
77
- },
78
- {
79
- provide: CategoryFirestoreRepository,
80
- useFactory: (firestore) => {
81
- return new CategoryFirestoreRepository(firestore.firestore);
82
- },
83
- deps: [AngularFirestore],
84
- },
85
- {
86
- provide: 'CheckoutRepository',
87
- useFactory: (firestore) => {
88
- return new CheckoutFirestoreRepository(firestore.firestore);
89
- },
90
- deps: [AngularFirestore],
91
- },
92
- {
93
- provide: 'CheckoutSubscriptionRepository',
94
- useFactory: (firestore) => {
95
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
96
- },
97
- deps: [AngularFirestore],
98
- },
99
- {
100
- provide: 'CouponRepository',
101
- useFactory: (firestore) => {
102
- return new CouponFirestoreRepository(firestore.firestore);
103
- },
104
- deps: [AngularFirestore],
105
- },
106
- {
107
- provide: 'CampaignHashtagRepository',
108
- useFactory: (firestore) => {
109
- return new CampaignHashtagFirestoreRepository(firestore.firestore);
110
- },
111
- deps: [AngularFirestore],
112
- },
113
- {
114
- provide: 'CampaignDashboardRepository',
115
- useFactory: (firestore) => {
116
- return new CampaignDashboardFirestoreRepository(firestore.firestore);
117
- },
118
- deps: [AngularFirestore],
119
- },
120
- {
121
- provide: 'EditionRepository',
122
- useFactory: (firestore, subscriptionRepository) => {
123
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
124
- },
125
- deps: [AngularFirestore, 'SubscriptionRepository'],
126
- },
127
- {
128
- provide: 'HomeRepository',
129
- useFactory: (firestore) => {
130
- return new HomeFirestoreRepository(firestore.firestore);
131
- },
132
- deps: [AngularFirestore],
133
- },
134
- {
135
- provide: 'LeadRepository',
136
- useFactory: (firestore) => {
137
- return new LeadFirestoreRepository(firestore.firestore);
138
- },
139
- deps: [AngularFirestore],
140
- },
141
- {
142
- provide: 'LegacyOrderRepository',
143
- useFactory: (firestore) => {
144
- return new LegacyOrderFirestoreRepository(firestore.firestore);
145
- },
146
- deps: [AngularFirestore],
147
- },
148
- {
149
- provide: 'ShopMenuRepository',
150
- useFactory: (firestore) => {
151
- return new ShopMenuFirestoreRepository(firestore.firestore);
152
- },
153
- deps: [AngularFirestore],
154
- },
155
- {
156
- provide: 'OrderRepository',
157
- useFactory: (firestore) => {
158
- return new OrderFirestoreRepository(firestore.firestore);
159
- },
160
- deps: [AngularFirestore],
161
- },
162
- {
163
- provide: 'PaymentRepository',
164
- useFactory: (firestore) => {
165
- return new PaymentFirestoreRepository(firestore.firestore);
166
- },
167
- deps: [AngularFirestore],
168
- },
169
- {
170
- provide: ProductFirestoreRepository,
171
- useFactory: (firestore) => {
172
- return new ProductFirestoreRepository(firestore.firestore);
173
- },
174
- deps: [AngularFirestore],
175
- },
176
- {
177
- provide: 'ShopSettingsRepository',
178
- useFactory: (firestore) => {
179
- return new ShopSettingsFirestoreRepository(firestore.firestore);
180
- },
181
- deps: [AngularFirestore],
182
- },
183
- {
184
- provide: 'SubscriptionPaymentRepository',
185
- useFactory: (firestore, subscriptionRepository) => {
186
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
187
- },
188
- deps: [AngularFirestore, 'SubscriptionRepository'],
189
- },
190
- {
191
- provide: 'SubscriptionPlanRepository',
192
- useFactory: (firestore) => {
193
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
194
- },
195
- deps: [AngularFirestore],
196
- },
197
- {
198
- provide: 'SubscriptionProductRepository',
199
- useFactory: (firestore) => {
200
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
201
- },
202
- deps: [AngularFirestore],
203
- },
204
- {
205
- provide: 'SubscriptionRepository',
206
- useFactory: (firestore) => {
207
- return new SubscriptionFirestoreRepository(firestore.firestore);
208
- },
209
- deps: [AngularFirestore],
210
- },
211
- {
212
- provide: 'UserRepository',
213
- useFactory: (firestore) => {
214
- return new UserFirestoreRepository(firestore.firestore);
215
- },
216
- deps: [AngularFirestore],
217
- },
218
- {
219
- provide: 'UserAddressRepository',
220
- useFactory: (firestore, userRepository) => {
221
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
222
- },
223
- deps: [AngularFirestore, 'UserRepository'],
224
- },
225
- {
226
- provide: 'UserPaymentMethodRepository',
227
- useFactory: (firestore, userRepository) => {
228
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
229
- },
230
- deps: [AngularFirestore, 'UserRepository'],
231
- },
232
- {
233
- provide: ProductVariantFirestoreRepository,
234
- useFactory: (firestore, productRepository) => {
235
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
236
- },
237
- deps: [AngularFirestore, ProductFirestoreRepository],
238
- },
239
- {
240
- provide: APP_INITIALIZER,
241
- useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
242
- deps: [AngularFirestore],
243
- multi: true,
244
- },
245
- ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
246
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
247
- type: NgModule,
248
- args: [{
249
- imports: [AngularFireModule, AngularElasticSeachModule],
250
- providers: [
251
- {
252
- provide: 'BeautyProfileRepository',
253
- useFactory: (firestore, userRepository) => {
254
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
255
- },
256
- deps: [AngularFirestore, 'UserRepository'],
257
- },
258
- {
259
- provide: 'Buy2WinRepository',
260
- useFactory: (firestore) => {
261
- return new Buy2WinFirestoreRepository(firestore.firestore);
262
- },
263
- deps: [AngularFirestore],
264
- },
265
- {
266
- provide: CategoryFirestoreRepository,
267
- useFactory: (firestore) => {
268
- return new CategoryFirestoreRepository(firestore.firestore);
269
- },
270
- deps: [AngularFirestore],
271
- },
272
- {
273
- provide: 'CheckoutRepository',
274
- useFactory: (firestore) => {
275
- return new CheckoutFirestoreRepository(firestore.firestore);
276
- },
277
- deps: [AngularFirestore],
278
- },
279
- {
280
- provide: 'CheckoutSubscriptionRepository',
281
- useFactory: (firestore) => {
282
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
283
- },
284
- deps: [AngularFirestore],
285
- },
286
- {
287
- provide: 'CouponRepository',
288
- useFactory: (firestore) => {
289
- return new CouponFirestoreRepository(firestore.firestore);
290
- },
291
- deps: [AngularFirestore],
292
- },
293
- {
294
- provide: 'CampaignHashtagRepository',
295
- useFactory: (firestore) => {
296
- return new CampaignHashtagFirestoreRepository(firestore.firestore);
297
- },
298
- deps: [AngularFirestore],
299
- },
300
- {
301
- provide: 'CampaignDashboardRepository',
302
- useFactory: (firestore) => {
303
- return new CampaignDashboardFirestoreRepository(firestore.firestore);
304
- },
305
- deps: [AngularFirestore],
306
- },
307
- {
308
- provide: 'EditionRepository',
309
- useFactory: (firestore, subscriptionRepository) => {
310
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
311
- },
312
- deps: [AngularFirestore, 'SubscriptionRepository'],
313
- },
314
- {
315
- provide: 'HomeRepository',
316
- useFactory: (firestore) => {
317
- return new HomeFirestoreRepository(firestore.firestore);
318
- },
319
- deps: [AngularFirestore],
320
- },
321
- {
322
- provide: 'LeadRepository',
323
- useFactory: (firestore) => {
324
- return new LeadFirestoreRepository(firestore.firestore);
325
- },
326
- deps: [AngularFirestore],
327
- },
328
- {
329
- provide: 'LegacyOrderRepository',
330
- useFactory: (firestore) => {
331
- return new LegacyOrderFirestoreRepository(firestore.firestore);
332
- },
333
- deps: [AngularFirestore],
334
- },
335
- {
336
- provide: 'ShopMenuRepository',
337
- useFactory: (firestore) => {
338
- return new ShopMenuFirestoreRepository(firestore.firestore);
339
- },
340
- deps: [AngularFirestore],
341
- },
342
- {
343
- provide: 'OrderRepository',
344
- useFactory: (firestore) => {
345
- return new OrderFirestoreRepository(firestore.firestore);
346
- },
347
- deps: [AngularFirestore],
348
- },
349
- {
350
- provide: 'PaymentRepository',
351
- useFactory: (firestore) => {
352
- return new PaymentFirestoreRepository(firestore.firestore);
353
- },
354
- deps: [AngularFirestore],
355
- },
356
- {
357
- provide: ProductFirestoreRepository,
358
- useFactory: (firestore) => {
359
- return new ProductFirestoreRepository(firestore.firestore);
360
- },
361
- deps: [AngularFirestore],
362
- },
363
- {
364
- provide: 'ShopSettingsRepository',
365
- useFactory: (firestore) => {
366
- return new ShopSettingsFirestoreRepository(firestore.firestore);
367
- },
368
- deps: [AngularFirestore],
369
- },
370
- {
371
- provide: 'SubscriptionPaymentRepository',
372
- useFactory: (firestore, subscriptionRepository) => {
373
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
374
- },
375
- deps: [AngularFirestore, 'SubscriptionRepository'],
376
- },
377
- {
378
- provide: 'SubscriptionPlanRepository',
379
- useFactory: (firestore) => {
380
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
381
- },
382
- deps: [AngularFirestore],
383
- },
384
- {
385
- provide: 'SubscriptionProductRepository',
386
- useFactory: (firestore) => {
387
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
388
- },
389
- deps: [AngularFirestore],
390
- },
391
- {
392
- provide: 'SubscriptionRepository',
393
- useFactory: (firestore) => {
394
- return new SubscriptionFirestoreRepository(firestore.firestore);
395
- },
396
- deps: [AngularFirestore],
397
- },
398
- {
399
- provide: 'UserRepository',
400
- useFactory: (firestore) => {
401
- return new UserFirestoreRepository(firestore.firestore);
402
- },
403
- deps: [AngularFirestore],
404
- },
405
- {
406
- provide: 'UserAddressRepository',
407
- useFactory: (firestore, userRepository) => {
408
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
409
- },
410
- deps: [AngularFirestore, 'UserRepository'],
411
- },
412
- {
413
- provide: 'UserPaymentMethodRepository',
414
- useFactory: (firestore, userRepository) => {
415
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
416
- },
417
- deps: [AngularFirestore, 'UserRepository'],
418
- },
419
- {
420
- provide: ProductVariantFirestoreRepository,
421
- useFactory: (firestore, productRepository) => {
422
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
423
- },
424
- deps: [AngularFirestore, ProductFirestoreRepository],
425
- },
426
- {
427
- provide: APP_INITIALIZER,
428
- useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
429
- deps: [AngularFirestore],
430
- multi: true,
431
- },
432
- ],
433
- }]
434
- }] });
435
-
436
- const BACKEND_URL = 'BACKEND_URL';
437
-
438
- const CATEGORY_STRUCTURE = 'CATEGORY_STRUCTURE';
439
-
440
- const DEFAULT_SHOP = 'DEFAULT_SHOP';
441
-
442
- const HASURA_OPTIONS = 'HASURA_OPTIONS';
443
-
444
- class AngularHasuraGraphQLModule {
445
- static initializeApp(options) {
446
- return {
447
- ngModule: AngularHasuraGraphQLModule,
448
- providers: [{ provide: HASURA_OPTIONS, useValue: options }],
449
- };
450
- }
451
- }
452
- AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
453
- AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
454
- AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
455
- {
456
- provide: 'CategoryRepository',
457
- useExisting: CategoryHasuraGraphQLRepository,
458
- },
459
- {
460
- provide: CategoryHasuraGraphQLRepository,
461
- useFactory: (options, productRepository, categoryFilterRepository) => {
462
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
463
- },
464
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
465
- },
466
- {
467
- provide: 'ProductRepository',
468
- useExisting: ProductHasuraGraphQLRepository,
469
- },
470
- {
471
- provide: ProductHasuraGraphQLRepository,
472
- useFactory: (options) => {
473
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
474
- },
475
- deps: [HASURA_OPTIONS],
476
- },
477
- {
478
- provide: 'VariantRepository',
479
- useExisting: VariantHasuraGraphQLRepository,
480
- },
481
- {
482
- provide: VariantHasuraGraphQLRepository,
483
- useFactory: (options) => {
484
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
485
- },
486
- deps: [HASURA_OPTIONS],
487
- },
488
- {
489
- provide: 'CategoryFilterRepository',
490
- useExisting: CategoryFilterHasuraGraphQLRepository,
491
- },
492
- {
493
- provide: CategoryFilterHasuraGraphQLRepository,
494
- useFactory: (options) => {
495
- return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
496
- },
497
- deps: [HASURA_OPTIONS],
498
- },
499
- {
500
- provide: 'FilterOptionRepository',
501
- useExisting: FilterOptionHasuraGraphQLRepository,
502
- },
503
- {
504
- provide: FilterOptionHasuraGraphQLRepository,
505
- useFactory: (options) => {
506
- return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
507
- },
508
- deps: [HASURA_OPTIONS],
509
- },
510
- {
511
- provide: 'FilterRepository',
512
- useExisting: FilterHasuraGraphQLRepository,
513
- },
514
- {
515
- provide: FilterHasuraGraphQLRepository,
516
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
517
- return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
518
- },
519
- deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
520
- },
521
- {
522
- provide: CategoryCollectionChildrenHasuraGraphQLRepository,
523
- useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials),
524
- deps: ['HasuraConfig'],
525
- },
526
- {
527
- provide: 'CategoryCollectionChildrenRepository',
528
- useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
529
- },
530
- {
531
- provide: WishlistHasuraGraphQLRepository,
532
- useFactory: (options, categoryFilterRepository) => {
533
- return new WishlistHasuraGraphQLRepository(options.endpoint, options.credentials, categoryFilterRepository);
534
- },
535
- deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
536
- },
537
- {
538
- provide: 'WishlistRepository',
539
- useExisting: WishlistHasuraGraphQLRepository,
540
- },
541
- ] });
542
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
543
- type: NgModule,
544
- args: [{
545
- providers: [
546
- {
547
- provide: 'CategoryRepository',
548
- useExisting: CategoryHasuraGraphQLRepository,
549
- },
550
- {
551
- provide: CategoryHasuraGraphQLRepository,
552
- useFactory: (options, productRepository, categoryFilterRepository) => {
553
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
554
- },
555
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
556
- },
557
- {
558
- provide: 'ProductRepository',
559
- useExisting: ProductHasuraGraphQLRepository,
560
- },
561
- {
562
- provide: ProductHasuraGraphQLRepository,
563
- useFactory: (options) => {
564
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
565
- },
566
- deps: [HASURA_OPTIONS],
567
- },
568
- {
569
- provide: 'VariantRepository',
570
- useExisting: VariantHasuraGraphQLRepository,
571
- },
572
- {
573
- provide: VariantHasuraGraphQLRepository,
574
- useFactory: (options) => {
575
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
576
- },
577
- deps: [HASURA_OPTIONS],
578
- },
579
- {
580
- provide: 'CategoryFilterRepository',
581
- useExisting: CategoryFilterHasuraGraphQLRepository,
582
- },
583
- {
584
- provide: CategoryFilterHasuraGraphQLRepository,
585
- useFactory: (options) => {
586
- return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
587
- },
588
- deps: [HASURA_OPTIONS],
589
- },
590
- {
591
- provide: 'FilterOptionRepository',
592
- useExisting: FilterOptionHasuraGraphQLRepository,
593
- },
594
- {
595
- provide: FilterOptionHasuraGraphQLRepository,
596
- useFactory: (options) => {
597
- return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
598
- },
599
- deps: [HASURA_OPTIONS],
600
- },
601
- {
602
- provide: 'FilterRepository',
603
- useExisting: FilterHasuraGraphQLRepository,
604
- },
605
- {
606
- provide: FilterHasuraGraphQLRepository,
607
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
608
- return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
609
- },
610
- deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
611
- },
612
- {
613
- provide: CategoryCollectionChildrenHasuraGraphQLRepository,
614
- useFactory: (options) => new CategoryCollectionChildrenHasuraGraphQLRepository(options.endpoint, options.credentials),
615
- deps: ['HasuraConfig'],
616
- },
617
- {
618
- provide: 'CategoryCollectionChildrenRepository',
619
- useExisting: CategoryCollectionChildrenHasuraGraphQLRepository,
620
- },
621
- {
622
- provide: WishlistHasuraGraphQLRepository,
623
- useFactory: (options, categoryFilterRepository) => {
624
- return new WishlistHasuraGraphQLRepository(options.endpoint, options.credentials, categoryFilterRepository);
625
- },
626
- deps: ['HasuraConfig', CategoryFilterHasuraGraphQLRepository],
627
- },
628
- {
629
- provide: 'WishlistRepository',
630
- useExisting: WishlistHasuraGraphQLRepository,
631
- },
632
- ],
633
- }]
634
- }] });
635
-
636
- class AuthService {
637
- constructor(angularFireAuth, userRepository) {
638
- this.angularFireAuth = angularFireAuth;
639
- this.userRepository = userRepository;
640
- }
641
- getAuthstate() {
642
- const observables = [
643
- this.angularFireAuth.authState.pipe(catchError(() => of(null))),
644
- this.getUser().pipe(catchError(() => of(null))),
645
- ];
646
- return combineLatest(observables).pipe(map(([fireUser, user]) => {
647
- return {
648
- user,
649
- isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
650
- };
651
- }));
652
- }
653
- getUser() {
654
- 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))));
655
- }
656
- getTokenId() {
657
- return this.angularFireAuth.idToken;
658
- }
659
- getFireUser() {
660
- return this.angularFireAuth.user.pipe(catchError(() => of(null)));
661
- }
662
- }
663
- AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, deps: [{ token: i1.AngularFireAuth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
664
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
665
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
666
- type: Injectable
667
- }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
668
- type: Inject,
669
- args: ['UserRepository']
670
- }] }]; } });
671
-
672
- class CouponService {
673
- constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
674
- this.couponRepository = couponRepository;
675
- this.defaultShop = defaultShop;
676
- this.orderRepository = orderRepository;
677
- this.categoryRepository = categoryRepository;
678
- this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
679
- }
680
- checkCoupon(nickname, checkoutType, checkout, plan) {
681
- return from(this.couponRepository
682
- .find({
683
- filters: {
684
- nickname: { operator: Where.EQUALS, value: nickname },
685
- active: { operator: Where.EQUALS, value: true },
686
- },
687
- })
688
- .then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
689
- }
690
- couponValidation(coupon, checkoutType) {
691
- return __awaiter(this, void 0, void 0, function* () {
692
- if (!coupon)
693
- throw 'Cupom inválido.';
694
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
695
- throw 'Cupom inválido.';
696
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn.getTime()) < new Date().getTime())
697
- throw 'Cupom expirado.';
698
- const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
699
- if (!isInShop)
700
- throw 'Cupom inválido para loja.';
701
- const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
702
- if (!isCheckoutType)
703
- throw 'Cupom inválido. Erro de checkout.';
704
- return coupon;
705
- });
706
- }
707
- couponRulesValidation(coupon, checkoutType, checkout, plan) {
708
- return __awaiter(this, void 0, void 0, function* () {
709
- if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
710
- if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
711
- throw 'Cupom inválido para sua assinatura.';
712
- return coupon;
713
- }
714
- const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
715
- if (!validUser)
716
- throw 'Usuário não elegível.';
717
- const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
718
- if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
719
- const orders = yield this.getOrdersWithCoupon(coupon);
720
- if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
721
- throw 'Limite de uso atingido.';
722
- if (couponUseLimits.limitedPerUser) {
723
- const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
724
- if (ordersWithUser > 0)
725
- throw 'Limite de uso por usuário atingido.';
726
- }
727
- }
728
- const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
729
- if (!hasProductCategories)
730
- throw 'Seu carrinho não possui produtos elegíveis para desconto.';
731
- const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
732
- if (!hasMinSubTotal)
733
- throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`;
734
- return coupon;
735
- });
736
- }
737
- calcDiscountSubscription(coupon, checkout) {
738
- let discount = 0;
739
- if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
740
- discount = coupon.discount.subscription.value;
741
- else
742
- discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
743
- return of(discount);
744
- }
745
- calcDiscountShopping(coupon, checkout) {
746
- return __awaiter(this, void 0, void 0, function* () {
747
- let discount = 0;
748
- if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
749
- discount = yield this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
750
- }
751
- else {
752
- discount = yield this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
753
- }
754
- return discount;
755
- });
756
- }
757
- calcDiscountByType(type, value, categories, checkout) {
758
- return __awaiter(this, void 0, void 0, function* () {
759
- let discount = 0;
760
- let lineItensDiscount = yield this.getLineItensEligebleForDiscount(categories, checkout);
761
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
762
- if (type == CouponTypes.ABSOLUTE) {
763
- discount = value > subTotal ? subTotal : value;
764
- }
765
- else {
766
- discount = subTotal * (value / 100);
767
- }
768
- return discount;
769
- });
770
- }
771
- hasMinSubTotal(coupon, checkout) {
772
- return __awaiter(this, void 0, void 0, function* () {
773
- if (!coupon.minSubTotalValue)
774
- return true;
775
- let lineItensDiscount = yield this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
776
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
777
- if (coupon.minSubTotalValue <= subTotal)
778
- return true;
779
- return false;
780
- });
781
- }
782
- hasProductCategories(coupon, checkout) {
783
- var _a;
784
- return __awaiter(this, void 0, void 0, function* () {
785
- if (!coupon.productsCategories || !coupon.productsCategories.length) {
786
- return true;
787
- }
788
- const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
789
- const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
790
- var _a;
791
- if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
792
- return true;
793
- return i.categories.some((c) => couponCategories.some((cat) => cat == c));
794
- });
795
- return hasCategories.length ? true : false;
796
- });
797
- }
798
- coupomUserValidation(coupon, user) {
799
- if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
800
- return true;
801
- let userTypes = [];
802
- if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) && this.emailIsFromCollaborator(user.email))
803
- userTypes.push(Exclusivities.COLLABORATORS);
804
- if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) && coupon.userExclusiveEmail.includes(user.email))
805
- userTypes.push(Exclusivities.SPECIFIC_USER);
806
- if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
807
- user.isSubscriber &&
808
- user.subscriptionPlan != '')
809
- userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
810
- if (user.isSubscriber &&
811
- user.subscriptionPlan == '' &&
812
- coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
813
- userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
814
- if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
815
- userTypes.push(Exclusivities.NON_SUBSCRIBER);
816
- return coupon.exclusivityType.some((r) => userTypes.includes(r));
817
- }
818
- getCouponCategoriesId(productsCategories) {
819
- return __awaiter(this, void 0, void 0, function* () {
820
- const couponCategories = [];
821
- for (let index = 0; index < productsCategories.length; index++) {
822
- const category = yield this.categoryRepository.get({
823
- id: productsCategories[index],
824
- });
825
- if (category) {
826
- const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
827
- couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
828
- }
829
- }
830
- return [...new Set(couponCategories)];
831
- });
832
- }
833
- getLineItensEligebleForDiscount(productsCategories, checkout) {
834
- var _a;
835
- return __awaiter(this, void 0, void 0, function* () {
836
- let lineItensDiscount = [];
837
- const couponCategories = yield this.getCouponCategoriesId(productsCategories);
838
- if (productsCategories && productsCategories.length) {
839
- lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
840
- var _a;
841
- if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
842
- return i.categories.some((c) => couponCategories.some((cat) => cat == c));
843
- }
844
- return true;
845
- });
846
- }
847
- else {
848
- lineItensDiscount = checkout.lineItems;
849
- }
850
- return lineItensDiscount;
851
- });
852
- }
853
- calcCheckoutSubtotal(lineItens, user, shop) {
854
- return ((lineItens === null || lineItens === void 0 ? void 0 : lineItens.reduce((acc, curr) => {
855
- var _a, _b;
856
- return (user === null || user === void 0 ? void 0 : user.isSubscriber) && ((_a = curr.price[shop]) === null || _a === void 0 ? void 0 : _a.subscriberPrice)
857
- ? acc + ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice) * curr.quantity
858
- : acc + curr.pricePaid * curr.quantity;
859
- }, 0)) || 0);
860
- }
861
- getOrdersWithCoupon(coupon) {
862
- return __awaiter(this, void 0, void 0, function* () {
863
- return yield this.orderRepository
864
- .find({
865
- filters: {
866
- coupon: { id: coupon.id },
867
- payment: { status: 'paid' },
868
- },
869
- })
870
- .then((result) => result.data);
871
- });
872
- }
873
- countOrdersWithUser(orders, email) {
874
- return orders.filter((o) => o.user.email == email).length;
875
- }
876
- getCouponUseLimits(coupon, checkoutType, user) {
877
- let couponUseLimits;
878
- if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
879
- couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
880
- }
881
- else {
882
- couponUseLimits = coupon.useLimits.subscription;
883
- }
884
- return couponUseLimits;
885
- }
886
- }
887
- CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
888
- CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
889
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
890
- type: Injectable,
891
- args: [{
892
- providedIn: 'root',
893
- }]
894
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
895
- type: Inject,
896
- args: ['CouponRepository']
897
- }] }, { type: i1$1.Shops, decorators: [{
898
- type: Inject,
899
- args: [DEFAULT_SHOP]
900
- }] }, { type: undefined, decorators: [{
901
- type: Inject,
902
- args: ['OrderRepository']
903
- }] }, { type: undefined, decorators: [{
904
- type: Inject,
905
- args: ['CategoryRepository']
906
- }] }]; } });
907
-
908
- class CheckoutService {
909
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
910
- this.couponService = couponService;
911
- this.checkoutRepository = checkoutRepository;
912
- this.orderRepository = orderRepository;
913
- this.userRepository = userRepository;
914
- this.defaultShop = defaultShop;
915
- }
916
- getCheckout(checkoutData) {
917
- const checkoutId = cookie.get('checkoutId');
918
- if (!isNil(checkoutId))
919
- return from(this.checkoutRepository.get({ id: checkoutId }));
920
- return from(this.createCheckout(checkoutData));
921
- }
922
- getUserByCheckout(checkoutId) {
923
- 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'))));
924
- }
925
- updateCheckoutLineItems(checkout) {
926
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
927
- }
928
- updateCheckoutUser(checkout) {
929
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
930
- }
931
- clearCheckoutFromSession() {
932
- cookie.remove('checkoutId');
933
- return of();
934
- }
935
- calcDiscount(coupon) {
936
- return this.getCheckout().pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.couponService.calcDiscountShopping(coupon, checkout); })));
937
- }
938
- checkCoupon(nickname, checkoutType) {
939
- return this.getCheckout().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, CheckoutTypes.ECOMMERCE, checkout, null).pipe()));
940
- }
941
- createCheckout(checkoutData) {
942
- return __awaiter(this, void 0, void 0, function* () {
943
- 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 }));
944
- cookie.set('checkoutId', checkout.id);
945
- return checkout;
946
- });
947
- }
948
- }
949
- CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
950
- CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
951
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
952
- type: Injectable
953
- }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
954
- type: Inject,
955
- args: ['CheckoutRepository']
956
- }] }, { type: undefined, decorators: [{
957
- type: Inject,
958
- args: ['OrderRepository']
959
- }] }, { type: undefined, decorators: [{
960
- type: Inject,
961
- args: ['UserRepository']
962
- }] }, { type: i1$1.Shops, decorators: [{
963
- type: Inject,
964
- args: [DEFAULT_SHOP]
965
- }] }]; } });
966
-
967
- class CartService {
968
- constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
969
- this.authService = authService;
970
- this.checkoutService = checkoutService;
971
- this.defaultShop = defaultShop;
972
- this.productRepository = productRepository;
973
- this.categoryRepository = categoryRepository;
974
- this.variantRepository = variantRepository;
975
- this.buy2WinRepository = buy2WinRepository;
976
- this.cartSubject = new Subject();
977
- this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
978
- var _a;
979
- const items = [];
980
- const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
981
- if (index > -1) {
982
- checkoutLoaded.lineItems[index].quantity += quantity;
983
- checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
984
- }
985
- else
986
- checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
987
- return this.checkoutService
988
- .updateCheckoutLineItems(checkoutLoaded)
989
- .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
990
- }));
991
- this.generateCartObject = (items) => items
992
- ? items.reduce((cart, item) => {
993
- var _a;
994
- 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) })) }));
995
- }, {})
996
- : [];
997
- this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
998
- var _a, _b, _c, _d, _e, _f, _g;
999
- const product = yield this.getProductData(item.id);
1000
- 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;
1001
- if (this.checkMaxStock(item, quantity || 0))
1002
- throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
1003
- const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
1004
- const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
1005
- const isGift = item.isGift || null;
1006
- const pricePaid = this.getProductPrice({
1007
- product: item,
1008
- shop: checkout.shop || this.defaultShop,
1009
- isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
1010
- });
1011
- RoundProductPricesHelper.roundProductPrices(item);
1012
- return {
1013
- checkout,
1014
- lineItem: LineItem.toInstance({
1015
- id,
1016
- name: name !== null && name !== void 0 ? name : product.name,
1017
- EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
1018
- brand: product.brand,
1019
- slug: slug !== null && slug !== void 0 ? slug : product.slug,
1020
- sku: sku !== null && sku !== void 0 ? sku : product.sku,
1021
- stock,
1022
- price: this.roundPrice(price),
1023
- image,
1024
- weight: weight !== null && weight !== void 0 ? weight : product.weight,
1025
- quantity: (item.quantity || 0) + (quantity || 0),
1026
- pricePaid,
1027
- categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
1028
- isGift: isGift !== null && isGift !== void 0 ? isGift : null,
1029
- costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
1030
- type,
1031
- }),
1032
- };
1033
- });
1034
- this.getProductPrice = ({ product, isSubscriber, }) => {
1035
- const info = product.price;
1036
- if (product.isGift)
1037
- return 0;
1038
- return isSubscriber && info.subscriberPrice > 0
1039
- ? Number(info.subscriberPrice.toFixed(2))
1040
- : Number(info.price.toFixed(2));
1041
- };
1042
- this.checkMaxStock = (item, quantity) => {
1043
- var _a;
1044
- const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
1045
- const currentItemAmount = item.quantity || 0;
1046
- return currentItemAmount + quantity > maxStock;
1047
- };
1048
- }
1049
- addItem(item, quantity = 1) {
1050
- 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)));
1051
- }
1052
- decreaseItem(item) {
1053
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1054
- var _a;
1055
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
1056
- if (!isNil(checkoutItem))
1057
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
1058
- return checkout;
1059
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1060
- }
1061
- getCart(checkout) {
1062
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
1063
- return this.cartSubject;
1064
- }
1065
- /**
1066
- * @deprecated The method should not be used
1067
- */
1068
- getVariantPriceDiscount(item) {
1069
- 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)));
1070
- }
1071
- removeItem(item) {
1072
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1073
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
1074
- if (index >= 0)
1075
- checkout.lineItems.splice(index, 1);
1076
- return checkout;
1077
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1078
- }
1079
- updateUserCart(user) {
1080
- 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* () {
1081
- var _a, _b;
1082
- return this.checkoutService
1083
- .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
1084
- ? 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; })))
1085
- : [] })))
1086
- .toPromise();
1087
- })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1088
- }
1089
- clearCart() {
1090
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
1091
- this.checkoutService.clearCheckoutFromSession();
1092
- return checkout;
1093
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
1094
- }
1095
- buildCartFromCheckout(checkoutData) {
1096
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1097
- }
1098
- roundPrice(productPrice) {
1099
- const { price, fullPrice, subscriberPrice } = productPrice;
1100
- return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
1101
- }
1102
- getProductData(productId) {
1103
- return __awaiter(this, void 0, void 0, function* () {
1104
- let product;
1105
- let variant;
1106
- try {
1107
- product = yield this.productRepository.get({ id: productId });
1108
- }
1109
- catch (error) {
1110
- if (!(error instanceof NotFoundError))
1111
- throw error;
1112
- const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
1113
- variant = variants.shift();
1114
- if (!variant)
1115
- throw error;
1116
- product = yield this.productRepository.get({ id: variant.productId });
1117
- }
1118
- return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
1119
- });
1120
- }
1121
- getGifts() {
1122
- return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
1123
- const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
1124
- if (!notGiftItems.length)
1125
- return Object.assign(Object.assign({}, checkout), { lineItems: [] });
1126
- const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1127
- const campaigns = yield this.buy2WinRepository
1128
- .find({
1129
- filters: {
1130
- active: { operator: Where.EQUALS, value: true },
1131
- shop: { operator: Where.EQUALS, value: this.defaultShop },
1132
- },
1133
- })
1134
- .then((data) => data.data);
1135
- if (!campaigns.length)
1136
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1137
- const elegibleCampaigns = [];
1138
- for (const campaign of campaigns) {
1139
- const today = new Date().getDate();
1140
- if (!(campaign.startDate.getDate() <= today) && !(campaign.endDate.getDate() >= today))
1141
- continue;
1142
- if (campaign.activeCategory) {
1143
- const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
1144
- const categoriesCampaingFullTree = [];
1145
- for (const id of categoriesCampaing) {
1146
- const children = yield this.categoryRepository.getChildren(parseInt(id));
1147
- categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
1148
- }
1149
- const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
1150
- const filterProductsCategories = checkout.lineItems.filter((l) => {
1151
- var _a;
1152
- if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
1153
- return true;
1154
- return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
1155
- });
1156
- if (filterProductsCategories.length) {
1157
- const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
1158
- if (cartTotalCategories >= campaign.cartValueMin)
1159
- elegibleCampaigns.push(campaign);
1160
- }
1161
- }
1162
- else {
1163
- if (campaign.cartValue && campaign.cartValue > 0) {
1164
- if (campaign.cartValue <= cartTotal)
1165
- elegibleCampaigns.push(campaign);
1166
- }
1167
- }
1168
- }
1169
- if (!elegibleCampaigns.length)
1170
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1171
- const campaingnProducts = [];
1172
- for (const campaign of elegibleCampaigns) {
1173
- let elegibleProducts = [];
1174
- for (const product of campaign.products) {
1175
- const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
1176
- if (!productData.length)
1177
- continue;
1178
- const gift = productData.shift();
1179
- if (gift.stock.quantity < 1)
1180
- continue;
1181
- elegibleProducts.push(gift);
1182
- }
1183
- campaingnProducts.push(elegibleProducts);
1184
- }
1185
- if (!campaingnProducts.length)
1186
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
1187
- const gifts = this.giftToLineItems([].concat(...campaingnProducts));
1188
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
1189
- })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1190
- }
1191
- giftToLineItems(items) {
1192
- return items.map((item) => {
1193
- var _a;
1194
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1195
- 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];
1196
- return LineItem.toInstance({
1197
- brand,
1198
- categories,
1199
- id: id.toString(),
1200
- name,
1201
- price,
1202
- sku,
1203
- slug,
1204
- stock,
1205
- weight,
1206
- EAN,
1207
- image,
1208
- pricePaid: 0,
1209
- quantity: 1,
1210
- isGift: true,
1211
- });
1212
- });
1213
- }
1214
- }
1215
- CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1216
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
1217
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
1218
- type: Injectable
1219
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.Shops, decorators: [{
1220
- type: Inject,
1221
- args: [DEFAULT_SHOP]
1222
- }] }, { type: undefined, decorators: [{
1223
- type: Inject,
1224
- args: ['ProductRepository']
1225
- }] }, { type: undefined, decorators: [{
1226
- type: Inject,
1227
- args: ['CategoryRepository']
1228
- }] }, { type: undefined, decorators: [{
1229
- type: Inject,
1230
- args: ['VariantRepository']
1231
- }] }, { type: i1$1.Buy2WinFirestoreRepository, decorators: [{
1232
- type: Inject,
1233
- args: ['Buy2WinRepository']
1234
- }] }]; } });
1235
-
1236
- class CatalogService {
1237
- constructor(productRepository, categoryStructureAdapter, shop, productIndex) {
1238
- this.productRepository = productRepository;
1239
- this.categoryStructureAdapter = categoryStructureAdapter;
1240
- this.shop = shop;
1241
- this.productIndex = productIndex;
1242
- this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1243
- const filters = {};
1244
- if (clubDiscount === null || clubDiscount === void 0 ? void 0 : clubDiscount.length)
1245
- set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1246
- if (brands === null || brands === void 0 ? void 0 : brands.length)
1247
- filters.brand = { operator: Where.IN, value: brands };
1248
- if (gender === null || gender === void 0 ? void 0 : gender.length)
1249
- filters.tags = {
1250
- operator: Where.IN,
1251
- value: gender
1252
- .map((genderOptions) => genderOptions === 'female' ? 'feminino' : genderOptions === 'male' ? 'masculino' : null)
1253
- .filter(Boolean),
1254
- };
1255
- if ((prices === null || prices === void 0 ? void 0 : prices.min) || (prices === null || prices === void 0 ? void 0 : prices.max))
1256
- set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1257
- ...(prices.min ? [{ operator: Where.GTE, value: Math.round(prices.min) }] : []),
1258
- ...(prices.max ? [{ operator: Where.LTE, value: Math.ceil(prices.max) }] : []),
1259
- ]);
1260
- if (rate)
1261
- filters.rate = { operator: Where.GTE, value: rate };
1262
- if (tags === null || tags === void 0 ? void 0 : tags.length)
1263
- filters.tags = { operator: Where.LIKE, value: tags };
1264
- if (customOptions === null || customOptions === void 0 ? void 0 : customOptions.length)
1265
- filters.filters = { operator: Where.LIKE, value: customOptions };
1266
- return filters;
1267
- };
1268
- this.buildSortQuery = (sort) => {
1269
- if (!sort || sort === 'most-relevant')
1270
- return {};
1271
- if (sort === 'best-sellers')
1272
- return { shoppingCount: 'desc' };
1273
- if (sort === 'biggest-price')
1274
- return { price: 'desc' };
1275
- if (sort === 'lowest-price')
1276
- return { price: 'asc' };
1277
- if (sort === 'best-rating')
1278
- return { rate: 'desc' };
1279
- if (sort === 'news')
1280
- return { createdAt: 'desc' };
1281
- };
1282
- this.buildLimitQuery = (options) => {
1283
- const limit = (options === null || options === void 0 ? void 0 : options.perPage) || 20;
1284
- return {
1285
- limit,
1286
- offset: (((options === null || options === void 0 ? void 0 : options.page) || 1) - 1) * limit,
1287
- };
1288
- };
1289
- this.hasProfile = (options) => 'profile' in options;
1290
- this.hasTerm = (options) => 'term' in options;
1291
- this.hasCategory = (options) => 'category' in options;
1292
- }
1293
- fetchProducts(options) {
1294
- var _a, _b, _c;
1295
- return __awaiter(this, void 0, void 0, function* () {
1296
- const limits = this.buildLimitQuery(options);
1297
- if (this.hasProfile(options) && ((_a = options.filters) === null || _a === void 0 ? void 0 : _a.customOptions))
1298
- throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
1299
- if (this.hasProfile(options) && ((_b = options.filters) === null || _b === void 0 ? void 0 : _b.tags))
1300
- throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1301
- if (this.hasTerm(options) && ((_c = options.filters) === null || _c === void 0 ? void 0 : _c.customOptions))
1302
- throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1303
- return yield this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => {
1304
- var _a, _b, _c, _d, _e, _f, _g, _h;
1305
- return ({
1306
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1307
- pages: Math.ceil(total / limits.limit),
1308
- prices: {
1309
- 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)) },
1310
- subscriberPrice: {
1311
- 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)),
1312
- 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)),
1313
- },
1314
- },
1315
- brands: distinct === null || distinct === void 0 ? void 0 : distinct.brand,
1316
- });
1317
- });
1318
- });
1319
- }
1320
- findCatalog(options, limits) {
1321
- return __awaiter(this, void 0, void 0, function* () {
1322
- 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'] } : {})) });
1323
- if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1324
- return this.productRepository.findCatalog(repoParams);
1325
- return this.productRepository.findCatalog(repoParams, (options === null || options === void 0 ? void 0 : options.mainGender) || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1326
- });
1327
- }
1328
- buildMainFilter({ category, profile, term, }) {
1329
- return __awaiter(this, void 0, void 0, function* () {
1330
- if (category)
1331
- return this.categoryStructureAdapter.buildProductFilterByCategory(category);
1332
- if (profile)
1333
- return { tags: { operator: Where.LIKE, value: profile } };
1334
- if (term)
1335
- return this.productIndex
1336
- .search(term, 9999, this.shop)
1337
- .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1338
- });
1339
- }
1340
- }
1341
- CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$1.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });
1342
- CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CatalogService });
1343
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CatalogService, decorators: [{
1344
- type: Injectable
1345
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1346
- type: Inject,
1347
- args: ['ProductRepository']
1348
- }] }, { type: undefined, decorators: [{
1349
- type: Inject,
1350
- args: [CATEGORY_STRUCTURE]
1351
- }] }, { type: i1$1.Shops, decorators: [{
1352
- type: Inject,
1353
- args: [DEFAULT_SHOP]
1354
- }] }, { type: i1$1.ProductsIndex }]; } });
1355
-
1356
- class CategoryService {
1357
- constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
1358
- this.productRepository = productRepository;
1359
- this.categoryRepository = categoryRepository;
1360
- this.categoryFilterRepository = categoryFilterRepository;
1361
- this.categoryStructureAdapter = categoryStructureAdapter;
1362
- this.shop = shop;
1363
- }
1364
- fetchBrands(category, mainGender) {
1365
- return __awaiter(this, void 0, void 0, function* () {
1366
- const brands = yield this.productRepository
1367
- .findCatalog({
1368
- filters: yield this.categoryStructureAdapter.buildProductFilterByCategory(category),
1369
- fields: ['brand'],
1370
- }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1371
- .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => (Object.assign(Object.assign({}, brands), { [brand]: true })), {})));
1372
- return this.categoryRepository
1373
- .find({ filters: { brandCategory: true }, orderBy: { name: 'asc' } })
1374
- .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1375
- });
1376
- }
1377
- fetchFilterOptions(category, filters) {
1378
- return __awaiter(this, void 0, void 0, function* () {
1379
- return yield this.categoryFilterRepository
1380
- .find({ filters: { categoryId: +category.id } })
1381
- .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1382
- });
1383
- }
1384
- }
1385
- CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1386
- CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CategoryService });
1387
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CategoryService, decorators: [{
1388
- type: Injectable
1389
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1390
- type: Inject,
1391
- args: ['ProductRepository']
1392
- }] }, { type: undefined, decorators: [{
1393
- type: Inject,
1394
- args: ['CategoryRepository']
1395
- }] }, { type: undefined, decorators: [{
1396
- type: Inject,
1397
- args: ['CategoryFilterRepository']
1398
- }] }, { type: undefined, decorators: [{
1399
- type: Inject,
1400
- args: [CATEGORY_STRUCTURE]
1401
- }] }, { type: i1$1.Shops, decorators: [{
1402
- type: Inject,
1403
- args: [DEFAULT_SHOP]
1404
- }] }]; } });
1405
-
1406
- var ProductSorts;
1407
- (function (ProductSorts) {
1408
- ProductSorts["MOST_RELEVANT"] = "most-relevant";
1409
- ProductSorts["BEST_SELLER"] = "best-sellers";
1410
- ProductSorts["BIGGEST_PRICE"] = "biggest-price";
1411
- ProductSorts["LOWEST_PRICE"] = "lowest-price";
1412
- ProductSorts["BIGGEST_DISCOUNT"] = "biggest-discount";
1413
- ProductSorts["BEST_RATING"] = "best-rating";
1414
- ProductSorts["NEWS"] = "news";
1415
- })(ProductSorts || (ProductSorts = {}));
1416
-
1417
- class CategoryWithTree extends Category {
1418
- }
1419
- __decorate([
1420
- Type(() => CategoryWithTree),
1421
- __metadata("design:type", Array)
1422
- ], CategoryWithTree.prototype, "children", void 0);
1423
-
1424
- class UtilHelper {
1425
- static createSlug(name) {
1426
- return name
1427
- .toLowerCase()
1428
- .replace(/\s+/g, '-') // Replace spaces with -
1429
- .replace(/[ãàáäâ]/g, 'a') // Replace spaces with -
1430
- .replace(/[ẽèéëê]/g, 'e') // Replace spaces with -
1431
- .replace(/[ìíïî]/g, 'i') // Replace spaces with -
1432
- .replace(/[õòóöô]/g, 'o') // Replace spaces with -
1433
- .replace(/[ùúüû]/g, 'u') // Replace spaces with -
1434
- .replace(/[ñ]/g, 'n') // Replace spaces with -
1435
- .replace(/[ç]/g, 'c') // Replace spaces with -
1436
- .replace(/[&]/g, 'and') // Replace spaces with -
1437
- .replace(/[^\w\-]+/g, '') // Remove all non-word chars
1438
- .replace(/\-\-+/g, '-'); // Replace multiple - with single -
1439
- }
1440
- }
1441
-
1442
- class NewCategoryStructureAdapter {
1443
- constructor(categoryRepository, categoryCollectionChildrenRepository) {
1444
- this.categoryRepository = categoryRepository;
1445
- this.categoryCollectionChildrenRepository = categoryCollectionChildrenRepository;
1446
- }
1447
- buildProductFilterByCategory(category) {
1448
- return __awaiter(this, void 0, void 0, function* () {
1449
- const categoriesIds = (yield this.isCollection(category))
1450
- ? yield this.getAllCategoriesIdFromCollection(category)
1451
- : [...(yield this.getAllCategoriesIdFromCategory(category)), category.id.toString()];
1452
- return { category: { id: { operator: Where.IN, value: categoriesIds } } };
1453
- });
1454
- }
1455
- getAllCategoriesIdFromCategory(category) {
1456
- return __awaiter(this, void 0, void 0, function* () {
1457
- return this.categoryRepository
1458
- .getChildren(+category.id)
1459
- .then((categories) => categories.map((category) => category.id.toString()));
1460
- });
1461
- }
1462
- getAllCategoriesIdFromCollection(category) {
1463
- return __awaiter(this, void 0, void 0, function* () {
1464
- return this.categoryCollectionChildrenRepository
1465
- .find({ filters: { collectionId: +category.id } })
1466
- .then(({ data }) => data.map((categoryCollection) => categoryCollection.categoryId.toString()));
1467
- });
1468
- }
1469
- isCollection(category) {
1470
- return __awaiter(this, void 0, void 0, function* () {
1471
- return !isNil(category.isCollection)
1472
- ? category.isCollection
1473
- : this.categoryRepository.get({ id: category.id }).then((category) => category.isCollection);
1474
- });
1475
- }
1476
- }
1477
- NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }, { token: 'CategoryCollectionChildrenRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1478
- NewCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: NewCategoryStructureAdapter });
1479
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: NewCategoryStructureAdapter, decorators: [{
1480
- type: Injectable
1481
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1482
- type: Inject,
1483
- args: ['CategoryRepository']
1484
- }] }, { type: undefined, decorators: [{
1485
- type: Inject,
1486
- args: ['CategoryCollectionChildrenRepository']
1487
- }] }]; } });
1488
-
1489
- class OldCategoryStructureAdapter {
1490
- constructor(categoryRepository) {
1491
- this.categoryRepository = categoryRepository;
1492
- }
1493
- buildProductFilterByCategory(category) {
1494
- var _a;
1495
- return __awaiter(this, void 0, void 0, function* () {
1496
- const productsIds = ((_a = category.products) === null || _a === void 0 ? void 0 : _a.length)
1497
- ? category.products
1498
- : yield this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1499
- return { id: { operator: Where.IN, value: productsIds } };
1500
- });
1501
- }
1502
- }
1503
- OldCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OldCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1504
- OldCategoryStructureAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OldCategoryStructureAdapter });
1505
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OldCategoryStructureAdapter, decorators: [{
1506
- type: Injectable
1507
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1508
- type: Inject,
1509
- args: ['CategoryRepository']
1510
- }] }]; } });
1511
-
1512
- class WishlistService {
1513
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryCollectionChildrenRepository, productIndex) {
1514
- this.wishlistRepository = wishlistRepository;
1515
- this.shop = shop;
1516
- const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository, categoryCollectionChildrenRepository);
1517
- this.catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop, productIndex);
1518
- this.categoryService = new CategoryService(productRepository, wishlistRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1519
- }
1520
- getCatalogService() {
1521
- return this.catalogService;
1522
- }
1523
- getCategoryService() {
1524
- return this.categoryService;
1525
- }
1526
- create(personId, title, description, userFullName) {
1527
- return __awaiter(this, void 0, void 0, function* () {
1528
- const data = {
1529
- slug: UtilHelper.createSlug(`favoritos ${userFullName} ${title}`),
1530
- name: title,
1531
- description,
1532
- metadata: {
1533
- title: `${userFullName} - ${title}`,
1534
- description: `${userFullName} - ${description}`,
1535
- },
1536
- shop: this.shop,
1537
- shops: [this.shop],
1538
- personId,
1539
- brandCategory: false,
1540
- published: true,
1541
- };
1542
- const newWishlist = yield this.wishlistRepository.create(data);
1543
- return this.wishlistRepository.update({ id: newWishlist.id, slug: `${newWishlist.id}-${newWishlist.slug}` });
1544
- });
1545
- }
1546
- update(id, title, description, userFullName) {
1547
- const data = {
1548
- id,
1549
- slug: UtilHelper.createSlug(`${id}-favoritos ${userFullName} ${title}`),
1550
- name: title,
1551
- description,
1552
- metadata: {
1553
- title: `${userFullName} - ${title}`,
1554
- description: `${userFullName} - ${description}`,
1555
- },
1556
- };
1557
- return this.wishlistRepository.update(data);
1558
- }
1559
- delete(wishlistId) {
1560
- return this.wishlistRepository.delete({ id: wishlistId });
1561
- }
1562
- getWishlistBySlug(slug) {
1563
- return this.wishlistRepository.getWishlistBySlug(slug);
1564
- }
1565
- getWishlistsByPerson(personId) {
1566
- return this.wishlistRepository.getWishlistByPerson(personId);
1567
- }
1568
- addProduct(wishlistId, productId) {
1569
- return __awaiter(this, void 0, void 0, function* () {
1570
- const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
1571
- const hasProduct = wishlist.products.some((p) => p == productId);
1572
- if (!hasProduct) {
1573
- wishlist.products = [...wishlist.products, productId];
1574
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
1575
- }
1576
- return wishlist;
1577
- });
1578
- }
1579
- removeProduct(wishlistId, productId) {
1580
- return __awaiter(this, void 0, void 0, function* () {
1581
- const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
1582
- const productIndex = wishlist.products.findIndex((p) => p == productId);
1583
- if (productIndex != -1) {
1584
- wishlist.products.splice(productIndex, 1);
1585
- if (!wishlist.products.length)
1586
- return this.wishlistRepository.update({ id: wishlistId, products: { action: 'remove' } });
1587
- return this.wishlistRepository.update({ id: wishlistId, products: wishlist.products });
1588
- }
1589
- return wishlist;
1590
- });
1591
- }
1592
- }
1593
- WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryCollectionChildrenRepository' }, { token: i1$1.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });
1594
- WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: WishlistService });
1595
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: WishlistService, decorators: [{
1596
- type: Injectable
1597
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1598
- type: Inject,
1599
- args: ['WishlistRepository']
1600
- }] }, { type: i1$1.Shops, decorators: [{
1601
- type: Inject,
1602
- args: [DEFAULT_SHOP]
1603
- }] }, { type: undefined, decorators: [{
1604
- type: Inject,
1605
- args: ['ProductRepository']
1606
- }] }, { type: undefined, decorators: [{
1607
- type: Inject,
1608
- args: ['CategoryFilterRepository']
1609
- }] }, { type: undefined, decorators: [{
1610
- type: Inject,
1611
- args: ['CategoryCollectionChildrenRepository']
1612
- }] }, { type: i1$1.ProductsIndex }]; } });
1613
-
1614
- class CheckoutSubscriptionService {
1615
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
1616
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1617
- this.subscriptionRepository = subscriptionRepository;
1618
- this.couponService = couponService;
1619
- }
1620
- getCheckoutSubscription(checkoutData) {
1621
- const checkoutId = cookie.get('checkoutSubscriptionId');
1622
- if (!isNil(checkoutId))
1623
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
1624
- return from(this.createCheckoutSubscription(checkoutData));
1625
- }
1626
- createCheckoutSubscription(checkoutData) {
1627
- return __awaiter(this, void 0, void 0, function* () {
1628
- const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
1629
- cookie.set('checkoutSubscriptionId', checkout.id);
1630
- return checkout;
1631
- });
1632
- }
1633
- clearCheckoutSubscriptionFromSession() {
1634
- cookie.remove('checkoutSubscriptionId');
1635
- return of();
1636
- }
1637
- checkCoupon(nickname, userEmail) {
1638
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
1639
- .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
1640
- .pipe()));
1641
- }
1642
- calcDiscountSubscription(coupon) {
1643
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1644
- }
1645
- }
1646
- CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
1647
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
1648
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
1649
- type: Injectable
1650
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1651
- type: Inject,
1652
- args: ['CheckoutSubscriptionRepository']
1653
- }] }, { type: undefined, decorators: [{
1654
- type: Inject,
1655
- args: ['SubscriptionRepository']
1656
- }] }, { type: CouponService }]; } });
1657
-
1658
- class HomeShopService {
1659
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
1660
- this.categoryRepository = categoryRepository;
1661
- this.homeRepository = homeRepository;
1662
- this.productRepository = productRepository;
1663
- this.defaultShop = defaultShop;
1664
- this.buildCategoryGroupWithRequiredData = (group) => {
1665
- var _a, _b;
1666
- return ({
1667
- 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'])),
1668
- 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()) || {}, [
1669
- 'id',
1670
- 'price',
1671
- 'reviews',
1672
- 'hasVariants',
1673
- 'slug',
1674
- 'sku',
1675
- 'stock',
1676
- 'costPrice',
1677
- 'images',
1678
- 'miniatures',
1679
- 'name',
1680
- 'weight',
1681
- 'rate',
1682
- 'type',
1683
- ])))) || [],
1684
- });
1685
- };
1686
- }
1687
- get homeId() {
1688
- if (this.defaultShop === Shops.GLAMSHOP)
1689
- return 'glamshop';
1690
- if (this.defaultShop === Shops.MENSMARKET)
1691
- return 'mens_market';
1692
- return null;
1693
- }
1694
- getHomeData() {
1695
- 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
1696
- ? of(home)
1697
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
1698
- discoverProducts,
1699
- featuredProducts,
1700
- verticalProducts,
1701
- })), concatMap((data) => this.saveHomeData(data)))));
1702
- }
1703
- getBanners(type) {
1704
- return this.getHomeConfiguration().pipe(map((home) => {
1705
- if (type === 'brand')
1706
- return home.brandsCarousel;
1707
- if (type === 'buyToWin')
1708
- return [home.buyToWinBanner];
1709
- if (type === 'block')
1710
- return home.blockBanners;
1711
- if (type === 'blog')
1712
- return [home.blogBanner];
1713
- }));
1714
- }
1715
- getMinValueForFreeShipping() {
1716
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
1717
- }
1718
- getDiscoverProducts() {
1719
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1720
- }
1721
- getFeaturedProducts() {
1722
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
1723
- }
1724
- getVerticalProducts() {
1725
- 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({
1726
- filters: { categories: { operator: Where.IN, value: [category.id] } },
1727
- limits: { limit: 12 },
1728
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
1729
- }
1730
- getHomeConfiguration() {
1731
- return of(this.homeConfiguration).pipe(concatMap((home) => home
1732
- ? of(home)
1733
- : !this.homeId
1734
- ? throwError(new RequiredArgumentError(['homeId']))
1735
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
1736
- }
1737
- saveHomeData(homeData) {
1738
- const data = {
1739
- createdAt: new Date(),
1740
- expiresAt: add(new Date(), { hours: 1 }),
1741
- data: homeData,
1742
- };
1743
- return from(this.homeRepository.update({
1744
- id: this.homeId,
1745
- data,
1746
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
1747
- }
1748
- }
1749
- HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1750
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
1751
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
1752
- type: Injectable
1753
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1754
- type: Inject,
1755
- args: ['CategoryRepository']
1756
- }] }, { type: undefined, decorators: [{
1757
- type: Inject,
1758
- args: ['HomeRepository']
1759
- }] }, { type: undefined, decorators: [{
1760
- type: Inject,
1761
- args: ['ProductRepository']
1762
- }] }, { type: i1$1.Shops, decorators: [{
1763
- type: Inject,
1764
- args: [DEFAULT_SHOP]
1765
- }] }]; } });
1766
-
1767
- class OrderService {
1768
- constructor(angularFirestore, orderRepository) {
1769
- this.angularFirestore = angularFirestore;
1770
- this.orderRepository = orderRepository;
1771
- this.orderSubject = new Subject();
1772
- }
1773
- getOrder(id) {
1774
- this.angularFirestore
1775
- .doc(`${this.orderRepository.collectionName}/${id}`)
1776
- .valueChanges()
1777
- .pipe(map((doc) => Order.toInstance(doc)))
1778
- .subscribe((doc) => this.orderSubject.next(doc));
1779
- return this.orderSubject;
1780
- }
1781
- }
1782
- OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$2.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1783
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
1784
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
1785
- type: Injectable
1786
- }], ctorParameters: function () { return [{ type: i1$2.AngularFirestore }, { type: i1$1.OrderFirestoreRepository, decorators: [{
1787
- type: Inject,
1788
- args: ['OrderRepository']
1789
- }] }]; } });
1790
-
1791
- class ShippingService {
1792
- constructor(http, apiUrl, homeService) {
1793
- this.http = http;
1794
- this.apiUrl = apiUrl;
1795
- this.homeService = homeService;
1796
- }
1797
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
1798
- return combineLatest([
1799
- this.homeService.getHomeData(),
1800
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
1801
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
1802
- let shippingMethods = shippingMethodsResponse.result;
1803
- if (!shippingMethods.length)
1804
- return [];
1805
- shippingMethods = shippingMethods.map((s) => {
1806
- if (s.ShippingCompanyName == 'Same Day EG')
1807
- s.ShippingCompanyName = 'Same Day';
1808
- else
1809
- return s;
1810
- });
1811
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
1812
- if (this.isHolidays(datasSameDayNotAvaliable)) {
1813
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
1814
- }
1815
- if (totalPrice >= 200) {
1816
- shippingMethods = shippingMethods.map((s) => {
1817
- if (s.serviceName !== 'Same Day')
1818
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1819
- else
1820
- return s;
1821
- });
1822
- }
1823
- if (shop == Shops.GLAMSHOP)
1824
- return shippingMethods;
1825
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
1826
- shippingMethods = shippingMethods.map((s) => {
1827
- if (s.serviceName == 'Same Day')
1828
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
1829
- else
1830
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1831
- });
1832
- }
1833
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
1834
- shippingMethods = shippingMethods.map((s) => {
1835
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
1836
- });
1837
- }
1838
- return shippingMethods;
1839
- }));
1840
- }
1841
- isFreeShippingBySubscription(shop, subscriptionPlan) {
1842
- if (!subscriptionPlan)
1843
- return false;
1844
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
1845
- return true;
1846
- }
1847
- return false;
1848
- }
1849
- isHalfShippingBySubscription(shop, subscriptionPlan) {
1850
- if (!subscriptionPlan)
1851
- return false;
1852
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
1853
- return true;
1854
- }
1855
- return false;
1856
- }
1857
- isHolidays(datas) {
1858
- const today = new Date();
1859
- for (const key in datas) {
1860
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
1861
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
1862
- if (start > end)
1863
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
1864
- if (today >= start && today <= end)
1865
- return true;
1866
- }
1867
- return false;
1868
- }
1869
- }
1870
- ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, deps: [{ token: i1$3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
1871
- ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
1872
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
1873
- type: Injectable
1874
- }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: undefined, decorators: [{
1875
- type: Inject,
1876
- args: [BACKEND_URL]
1877
- }] }, { type: HomeShopService }]; } });
1878
-
1879
- class AngularConnectModule {
1880
- static initializeApp(defaultShop, options, nameOrConfig) {
1881
- return {
1882
- ngModule: AngularConnectModule,
1883
- providers: [
1884
- {
1885
- provide: CATEGORY_STRUCTURE,
1886
- useClass: isNil(options === null || options === void 0 ? void 0 : options.oldCategoryStructure) || (options === null || options === void 0 ? void 0 : options.oldCategoryStructure)
1887
- ? OldCategoryStructureAdapter
1888
- : NewCategoryStructureAdapter,
1889
- },
1890
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1891
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1892
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1893
- ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1894
- ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1895
- ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1896
- ],
1897
- };
1898
- }
1899
- }
1900
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1901
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularElasticSeachModule, AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1902
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1903
- AuthService,
1904
- CartService,
1905
- CatalogService,
1906
- CategoryService,
1907
- CheckoutService,
1908
- CheckoutSubscriptionService,
1909
- CouponService,
1910
- HomeShopService,
1911
- OrderService,
1912
- ShippingService,
1913
- WishlistService,
1914
- ], imports: [[AngularElasticSeachModule, AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1915
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1916
- type: NgModule,
1917
- args: [{
1918
- imports: [AngularElasticSeachModule, AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1919
- providers: [
1920
- AuthService,
1921
- CartService,
1922
- CatalogService,
1923
- CategoryService,
1924
- CheckoutService,
1925
- CheckoutSubscriptionService,
1926
- CouponService,
1927
- HomeShopService,
1928
- OrderService,
1929
- ShippingService,
1930
- WishlistService,
1931
- ],
1932
- }]
1933
- }] });
1934
-
1935
- class AngularFirebaseAuthModule {
1936
- static initializeApp(options, nameOrConfig) {
1937
- return {
1938
- ngModule: AngularFirebaseAuthModule,
1939
- providers: [
1940
- { provide: FIREBASE_OPTIONS, useValue: options },
1941
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
1942
- ],
1943
- };
1944
- }
1945
- }
1946
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1947
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
1948
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
1949
- {
1950
- provide: 'Authentication',
1951
- useFactory: (authenticationService, userRepository) => {
1952
- return new Authentication(authenticationService, userRepository);
1953
- },
1954
- deps: ['AuthenticationService', 'UserRepository'],
1955
- },
1956
- {
1957
- provide: 'AuthenticationService',
1958
- useFactory: (angularFireAuth) => {
1959
- return new AuthenticationFirebaseAuthService(angularFireAuth);
1960
- },
1961
- deps: [AngularFireAuth],
1962
- },
1963
- {
1964
- provide: 'Register',
1965
- useFactory: (registerService, userRepository) => {
1966
- return new Register(registerService, userRepository);
1967
- },
1968
- deps: ['RegisterService', 'UserRepository'],
1969
- },
1970
- {
1971
- provide: 'RegisterService',
1972
- useFactory: (angularFireAuth) => {
1973
- return new RegisterFirebaseAuthService(angularFireAuth);
1974
- },
1975
- deps: [AngularFireAuth],
1976
- },
1977
- {
1978
- provide: 'SignOut',
1979
- useFactory: (authenticationService) => {
1980
- return new SignOut(authenticationService);
1981
- },
1982
- deps: ['AuthenticationService'],
1983
- },
1984
- {
1985
- provide: 'RecoveryPassword',
1986
- useFactory: (authenticationService) => {
1987
- return new RecoveryPassword(authenticationService);
1988
- },
1989
- deps: ['AuthenticationService'],
1990
- },
1991
- ], imports: [[AngularFireModule]] });
1992
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
1993
- type: NgModule,
1994
- args: [{
1995
- imports: [AngularFireModule],
1996
- providers: [
1997
- {
1998
- provide: 'Authentication',
1999
- useFactory: (authenticationService, userRepository) => {
2000
- return new Authentication(authenticationService, userRepository);
2001
- },
2002
- deps: ['AuthenticationService', 'UserRepository'],
2003
- },
2004
- {
2005
- provide: 'AuthenticationService',
2006
- useFactory: (angularFireAuth) => {
2007
- return new AuthenticationFirebaseAuthService(angularFireAuth);
2008
- },
2009
- deps: [AngularFireAuth],
2010
- },
2011
- {
2012
- provide: 'Register',
2013
- useFactory: (registerService, userRepository) => {
2014
- return new Register(registerService, userRepository);
2015
- },
2016
- deps: ['RegisterService', 'UserRepository'],
2017
- },
2018
- {
2019
- provide: 'RegisterService',
2020
- useFactory: (angularFireAuth) => {
2021
- return new RegisterFirebaseAuthService(angularFireAuth);
2022
- },
2023
- deps: [AngularFireAuth],
2024
- },
2025
- {
2026
- provide: 'SignOut',
2027
- useFactory: (authenticationService) => {
2028
- return new SignOut(authenticationService);
2029
- },
2030
- deps: ['AuthenticationService'],
2031
- },
2032
- {
2033
- provide: 'RecoveryPassword',
2034
- useFactory: (authenticationService) => {
2035
- return new RecoveryPassword(authenticationService);
2036
- },
2037
- deps: ['AuthenticationService'],
2038
- },
2039
- ],
2040
- }]
2041
- }] });
2042
-
2043
- /**
2044
- * Generated bundle index. Do not edit.
2045
- */
2046
-
2047
- export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2048
- //# sourceMappingURL=infrab4a-connect-angular.js.map