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