@infrab4a/connect-angular 5.0.0-beta.0 → 5.0.0-beta.10

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 (36) hide show
  1. package/angular-connect.module.d.ts +4 -1
  2. package/angular-firestore.module.d.ts +2 -1
  3. package/consts/index.d.ts +1 -0
  4. package/consts/persistence.const.d.ts +1 -0
  5. package/consts/storage-base-url.const.d.ts +1 -0
  6. package/esm2022/angular-connect.module.mjs +21 -3
  7. package/esm2022/angular-firestore.module.mjs +23 -4
  8. package/esm2022/consts/index.mjs +2 -1
  9. package/esm2022/consts/persistence.const.mjs +2 -0
  10. package/esm2022/consts/storage-base-url.const.mjs +2 -0
  11. package/esm2022/index.mjs +2 -1
  12. package/esm2022/persistence/cookie-data-persistence.mjs +23 -0
  13. package/esm2022/persistence/data-persistence.mjs +2 -0
  14. package/esm2022/persistence/index.mjs +3 -0
  15. package/esm2022/services/cart.service.mjs +2 -2
  16. package/esm2022/services/catalog/catalog.service.mjs +27 -12
  17. package/esm2022/services/catalog/category.service.mjs +4 -4
  18. package/esm2022/services/catalog/wishlist.service.mjs +7 -8
  19. package/esm2022/services/checkout-subscription.service.mjs +18 -21
  20. package/esm2022/services/checkout.service.mjs +13 -16
  21. package/esm2022/services/coupon.service.mjs +20 -3
  22. package/esm2022/services/home-shop.service.mjs +18 -8
  23. package/fesm2022/infrab4a-connect-angular.mjs +160 -67
  24. package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
  25. package/index.d.ts +1 -0
  26. package/package.json +4 -4
  27. package/persistence/cookie-data-persistence.d.ts +10 -0
  28. package/persistence/data-persistence.d.ts +6 -0
  29. package/persistence/index.d.ts +2 -0
  30. package/services/catalog/catalog.service.d.ts +7 -4
  31. package/services/catalog/category.service.d.ts +6 -1
  32. package/services/catalog/wishlist.service.d.ts +1 -2
  33. package/services/checkout-subscription.service.d.ts +5 -4
  34. package/services/checkout.service.d.ts +4 -3
  35. package/services/coupon.service.d.ts +1 -0
  36. package/services/home-shop.service.d.ts +1 -0
@@ -3,15 +3,17 @@ import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angu
3
3
  import * as i1$4 from '@angular/fire/app';
4
4
  import { FirebaseApp, getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
5
5
  import * as i1$2 from '@infrab4a/connect';
6
- import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, 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, 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 } from '@infrab4a/connect';
6
+ import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, 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
7
  import * as i1 from '@angular/fire/auth';
8
8
  import { Auth, getAuth, provideAuth, getIdToken, authState } from '@angular/fire/auth';
9
9
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
10
10
  import * as i1$1 from '@angular/fire/firestore';
11
11
  import { Firestore, getFirestore, memoryLocalCache, initializeFirestore, provideFirestore, doc, docSnapshots } from '@angular/fire/firestore';
12
- import { combineLatest, of, from, throwError, Subject, iif, forkJoin } from 'rxjs';
13
- import { map, catchError, mergeMap, concatMap, tap } from 'rxjs/operators';
12
+ import * as i2 from '@angular/fire/storage';
13
+ import { Storage, getStorage, provideStorage } from '@angular/fire/storage';
14
14
  import cookie from 'js-cookie';
15
+ import { of, from, combineLatest, throwError, Subject, iif, forkJoin } from 'rxjs';
16
+ import { map, catchError, mergeMap, concatMap, tap } from 'rxjs/operators';
15
17
  import { __metadata, __decorate } from 'tslib';
16
18
  import { Type } from 'class-transformer';
17
19
  import * as i1$3 from '@angular/common/http';
@@ -59,6 +61,8 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
59
61
 
60
62
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
61
63
 
64
+ const PERSISTENCE_PROVIDER = 'PERSISTENCE_PROVIDER';
65
+
62
66
  class AngularFirebaseAuthModule {
63
67
  static initializeApp(options, nameOrConfig) {
64
68
  return {
@@ -167,6 +171,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
167
171
  }]
168
172
  }] });
169
173
 
174
+ const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
175
+
170
176
  class MobileOperationSystemCheckerHelper {
171
177
  static isAppleDevice() {
172
178
  return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
@@ -186,7 +192,7 @@ class AngularFirestoreModule {
186
192
  };
187
193
  }
188
194
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
189
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] }); }
195
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule, i2.StorageModule] }); }
190
196
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, providers: [
191
197
  {
192
198
  provide: 'FirestoreOptions',
@@ -399,6 +405,13 @@ class AngularFirestoreModule {
399
405
  },
400
406
  deps: ['FirestoreOptions', ProductFirestoreRepository],
401
407
  },
408
+ {
409
+ provide: 'FileUploaderService',
410
+ useFactory: (storage, baseUrl) => {
411
+ return new FirebaseFileUploaderService(storage, baseUrl);
412
+ },
413
+ deps: [Storage, STORAGE_BASE_URL],
414
+ },
402
415
  ], imports: [AngularElasticSeachModule,
403
416
  provideFirestore((injector) => {
404
417
  const platformId = injector.get(PLATFORM_ID);
@@ -411,7 +424,8 @@ class AngularFirestoreModule {
411
424
  localCache: memoryLocalCache(),
412
425
  });
413
426
  return firestore;
414
- })] }); }
427
+ }),
428
+ provideStorage(() => getStorage())] }); }
415
429
  }
416
430
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, decorators: [{
417
431
  type: NgModule,
@@ -430,6 +444,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
430
444
  });
431
445
  return firestore;
432
446
  }),
447
+ provideStorage(() => getStorage()),
433
448
  ],
434
449
  providers: [
435
450
  {
@@ -643,6 +658,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
643
658
  },
644
659
  deps: ['FirestoreOptions', ProductFirestoreRepository],
645
660
  },
661
+ {
662
+ provide: 'FileUploaderService',
663
+ useFactory: (storage, baseUrl) => {
664
+ return new FirebaseFileUploaderService(storage, baseUrl);
665
+ },
666
+ deps: [Storage, STORAGE_BASE_URL],
667
+ },
646
668
  ],
647
669
  }]
648
670
  }] });
@@ -907,6 +929,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
907
929
  }]
908
930
  }] });
909
931
 
932
+ class CookieDataPersistence {
933
+ get(key) {
934
+ return of(cookie.get(key));
935
+ }
936
+ remove(key) {
937
+ cookie.remove(key);
938
+ return;
939
+ }
940
+ set(key, value) {
941
+ return from(cookie.set(key, value)).pipe(map(() => { }));
942
+ }
943
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
944
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence }); }
945
+ }
946
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, decorators: [{
947
+ type: Injectable
948
+ }] });
949
+
910
950
  class AuthService {
911
951
  constructor(angularFireAuth, userRepository) {
912
952
  this.angularFireAuth = angularFireAuth;
@@ -981,6 +1021,11 @@ class CouponService {
981
1021
  if (!validUser)
982
1022
  throw 'Usuário não elegível.';
983
1023
  const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
1024
+ if (couponUseLimits.firstOrder) {
1025
+ const ordersUser = await this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
1026
+ if (couponUseLimits.firstOrder && ordersUser.length >= 1)
1027
+ throw 'Limite de uso atingido';
1028
+ }
984
1029
  if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
985
1030
  const orders = await this.getOrdersWithCoupon(coupon);
986
1031
  if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
@@ -1054,9 +1099,11 @@ class CouponService {
1054
1099
  if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
1055
1100
  return true;
1056
1101
  let userTypes = [];
1057
- if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) && this.emailIsFromCollaborator(user.email))
1102
+ if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
1103
+ this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
1058
1104
  userTypes.push(Exclusivities.COLLABORATORS);
1059
- if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) && coupon.userExclusiveEmail.includes(user.email))
1105
+ if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
1106
+ coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
1060
1107
  userTypes.push(Exclusivities.SPECIFIC_USER);
1061
1108
  if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
1062
1109
  user.isSubscriber &&
@@ -1114,6 +1161,16 @@ class CouponService {
1114
1161
  })
1115
1162
  .then((result) => result.data);
1116
1163
  }
1164
+ async getOrdersFromUser(email) {
1165
+ return await this.orderRepository
1166
+ .find({
1167
+ filters: {
1168
+ user: { email: { operator: Where.EQUALS, value: email } },
1169
+ payment: { status: 'paid' },
1170
+ },
1171
+ })
1172
+ .then((result) => result.data);
1173
+ }
1117
1174
  countOrdersWithUser(orders, email) {
1118
1175
  return orders.filter((o) => o.user.email == email).length;
1119
1176
  }
@@ -1150,18 +1207,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1150
1207
  }] }] });
1151
1208
 
1152
1209
  class CheckoutService {
1153
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
1210
+ constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1154
1211
  this.couponService = couponService;
1155
1212
  this.checkoutRepository = checkoutRepository;
1156
- this.orderRepository = orderRepository;
1157
1213
  this.userRepository = userRepository;
1158
1214
  this.defaultShop = defaultShop;
1215
+ this.dataPersistence = dataPersistence;
1159
1216
  }
1160
1217
  getCheckout(checkoutData) {
1161
- const checkoutId = cookie.get('checkoutId');
1162
- if (!isNil(checkoutId))
1163
- return from(this.checkoutRepository.get({ id: checkoutId }));
1164
- return from(this.createCheckout(checkoutData));
1218
+ return this.dataPersistence
1219
+ .get('checkoutId')
1220
+ .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
1165
1221
  }
1166
1222
  getUserByCheckout(checkoutId) {
1167
1223
  return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => checkout?.user?.id ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id }))), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
@@ -1173,8 +1229,7 @@ class CheckoutService {
1173
1229
  return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1174
1230
  }
1175
1231
  clearCheckoutFromSession() {
1176
- cookie.remove('checkoutId');
1177
- return of();
1232
+ return this.dataPersistence.remove('checkoutId');
1178
1233
  }
1179
1234
  calcDiscount(coupon) {
1180
1235
  return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
@@ -1188,10 +1243,10 @@ class CheckoutService {
1188
1243
  ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1189
1244
  shop: checkoutData?.shop || this.defaultShop,
1190
1245
  });
1191
- cookie.set('checkoutId', checkout.id);
1246
+ await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1192
1247
  return checkout;
1193
1248
  }
1194
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable }); }
1249
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Injectable }); }
1195
1250
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService }); }
1196
1251
  }
1197
1252
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, decorators: [{
@@ -1199,15 +1254,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1199
1254
  }], ctorParameters: () => [{ type: CouponService }, { type: undefined, decorators: [{
1200
1255
  type: Inject,
1201
1256
  args: ['CheckoutRepository']
1202
- }] }, { type: undefined, decorators: [{
1203
- type: Inject,
1204
- args: ['OrderRepository']
1205
1257
  }] }, { type: undefined, decorators: [{
1206
1258
  type: Inject,
1207
1259
  args: ['UserRepository']
1208
1260
  }] }, { type: i1$2.Shops, decorators: [{
1209
1261
  type: Inject,
1210
1262
  args: [DEFAULT_SHOP]
1263
+ }] }, { type: undefined, decorators: [{
1264
+ type: Inject,
1265
+ args: [PERSISTENCE_PROVIDER]
1211
1266
  }] }] });
1212
1267
 
1213
1268
  class CartService {
@@ -1320,7 +1375,7 @@ class CartService {
1320
1375
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1321
1376
  }
1322
1377
  updateUserCart(user) {
1323
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
1378
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1324
1379
  .updateCheckoutLineItems(Checkout.toInstance({
1325
1380
  ...checkout.toPlain(),
1326
1381
  lineItems: checkout.lineItems?.length
@@ -1539,8 +1594,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1539
1594
  }] }] });
1540
1595
 
1541
1596
  class CatalogService {
1542
- constructor(productRepository, categoryStructureAdapter, shop, productIndex) {
1597
+ constructor(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1543
1598
  this.productRepository = productRepository;
1599
+ this.categoryRepository = categoryRepository;
1544
1600
  this.categoryStructureAdapter = categoryStructureAdapter;
1545
1601
  this.shop = shop;
1546
1602
  this.productIndex = productIndex;
@@ -1615,8 +1671,16 @@ class CatalogService {
1615
1671
  }));
1616
1672
  }
1617
1673
  async findCatalog(options, limits) {
1618
- if (this.hasTerm(options) && options.sort === 'most-relevant')
1619
- return this.findCatalogByTermAndSortByMostRevelant(options, limits);
1674
+ if (this.hasTerm(options) && options.sort === 'most-relevant') {
1675
+ const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
1676
+ return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1677
+ }
1678
+ if (this.hasCategory(options) && options.sort === 'most-relevant') {
1679
+ const productsIds = options.category.products?.length
1680
+ ? options.category.products
1681
+ : await this.categoryRepository.get({ id: options.category.id }).then((categoryFound) => categoryFound.products);
1682
+ return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1683
+ }
1620
1684
  const repoParams = {
1621
1685
  filters: {
1622
1686
  ...(await this.buildMainFilter(options)),
@@ -1644,10 +1708,9 @@ class CatalogService {
1644
1708
  .search(term, 999, this.shop)
1645
1709
  .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1646
1710
  }
1647
- async findCatalogByTermAndSortByMostRevelant(options, limits) {
1648
- const productIds = await this.findCatalogIdsByElasticSearch(options.term);
1711
+ async findCatalogAndSortByMostRevelant(productIds, options, limits) {
1649
1712
  const totalResult = await this.productRepository.findCatalog({
1650
- fields: ['id'],
1713
+ fields: ['id', 'stock'],
1651
1714
  filters: {
1652
1715
  id: { operator: Where.IN, value: productIds },
1653
1716
  ...this.buildFilterQuery(options?.filters || {}),
@@ -1658,9 +1721,13 @@ class CatalogService {
1658
1721
  distinct: ['brand'],
1659
1722
  },
1660
1723
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1661
- const limitedProductId = totalResult.data
1662
- .slice(limits.offset, limits.offset + limits.limit)
1663
- .map((product) => product.id);
1724
+ const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1725
+ const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1726
+ const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1727
+ const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
1728
+ const limitedProductId = productIdsStock
1729
+ .concat(productIdsStockOut)
1730
+ .slice(limits.offset, limits.offset + limits.limit);
1664
1731
  const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1665
1732
  const productResult = await this.productRepository.findCatalog({
1666
1733
  filters: {
@@ -1687,7 +1754,7 @@ class CatalogService {
1687
1754
  return [...new Set(sorted.map(({ _source }) => _source.id))];
1688
1755
  }));
1689
1756
  }
1690
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
1757
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
1691
1758
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
1692
1759
  }
1693
1760
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, decorators: [{
@@ -1695,6 +1762,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1695
1762
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1696
1763
  type: Inject,
1697
1764
  args: ['ProductRepository']
1765
+ }] }, { type: undefined, decorators: [{
1766
+ type: Inject,
1767
+ args: ['CategoryRepository']
1698
1768
  }] }, { type: undefined, decorators: [{
1699
1769
  type: Inject,
1700
1770
  args: [CATEGORY_STRUCTURE]
@@ -1711,15 +1781,15 @@ class CategoryService {
1711
1781
  this.categoryStructureAdapter = categoryStructureAdapter;
1712
1782
  this.shop = shop;
1713
1783
  }
1714
- async fetchBrands(category, mainGender) {
1784
+ async fetchBrands(category, options) {
1715
1785
  const brands = await this.productRepository
1716
1786
  .findCatalog({
1717
1787
  filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1718
1788
  fields: ['brand'],
1719
- }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1789
+ }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1720
1790
  .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1721
1791
  return this.categoryRepository
1722
- .find({ filters: { brandCategory: true, shop: this.shop }, orderBy: { name: 'asc' } })
1792
+ .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } })
1723
1793
  .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1724
1794
  }
1725
1795
  async fetchFilterOptions(category) {
@@ -1768,12 +1838,11 @@ __decorate([
1768
1838
  ], CategoryWithTree.prototype, "children", void 0);
1769
1839
 
1770
1840
  class WishlistService {
1771
- constructor(wishlistRepository, categoryRepository, shop, productRepository, categoryFilterRepository, productIndex) {
1841
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productIndex) {
1772
1842
  this.wishlistRepository = wishlistRepository;
1773
- this.categoryRepository = categoryRepository;
1774
1843
  this.shop = shop;
1775
1844
  const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1776
- this.catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop, productIndex);
1845
+ this.catalogService = new CatalogService(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1777
1846
  this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1778
1847
  }
1779
1848
  getCatalogService() {
@@ -1853,7 +1922,7 @@ class WishlistService {
1853
1922
  }
1854
1923
  return wishlist;
1855
1924
  }
1856
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: 'CategoryRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
1925
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
1857
1926
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService }); }
1858
1927
  }
1859
1928
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, decorators: [{
@@ -1861,9 +1930,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1861
1930
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1862
1931
  type: Inject,
1863
1932
  args: ['WishlistRepository']
1864
- }] }, { type: undefined, decorators: [{
1865
- type: Inject,
1866
- args: ['CategoryRepository']
1867
1933
  }] }, { type: i1$2.Shops, decorators: [{
1868
1934
  type: Inject,
1869
1935
  args: [DEFAULT_SHOP]
@@ -1873,31 +1939,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1873
1939
  }] }, { type: undefined, decorators: [{
1874
1940
  type: Inject,
1875
1941
  args: ['CategoryFilterRepository']
1942
+ }] }, { type: undefined, decorators: [{
1943
+ type: Inject,
1944
+ args: ['CategoryRepository']
1876
1945
  }] }, { type: i1$2.ProductsIndex }] });
1877
1946
 
1878
1947
  class CheckoutSubscriptionService {
1879
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
1948
+ constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
1880
1949
  this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1881
- this.subscriptionRepository = subscriptionRepository;
1950
+ this.dataPersistence = dataPersistence;
1882
1951
  this.couponService = couponService;
1883
1952
  }
1884
1953
  getCheckoutSubscription(checkoutData) {
1885
- const checkoutId = cookie.get('checkoutSubscriptionId');
1886
- if (!isNil(checkoutId))
1887
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
1888
- return from(this.createCheckoutSubscription(checkoutData));
1889
- }
1890
- async createCheckoutSubscription(checkoutData) {
1891
- const checkout = await this.checkoutSubscriptionRepository.create({
1892
- createdAt: new Date(),
1893
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1894
- });
1895
- cookie.set('checkoutSubscriptionId', checkout.id);
1896
- return checkout;
1954
+ return this.dataPersistence
1955
+ .get('checkoutSubscriptionId')
1956
+ .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
1897
1957
  }
1898
1958
  clearCheckoutSubscriptionFromSession() {
1899
- cookie.remove('checkoutSubscriptionId');
1900
- return of();
1959
+ return this.dataPersistence.remove('checkoutSubscriptionId');
1901
1960
  }
1902
1961
  checkCoupon(nickname, userEmail) {
1903
1962
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
@@ -1907,7 +1966,15 @@ class CheckoutSubscriptionService {
1907
1966
  calcDiscountSubscription(coupon) {
1908
1967
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1909
1968
  }
1910
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1969
+ async createCheckoutSubscription(checkoutData) {
1970
+ const checkout = await this.checkoutSubscriptionRepository.create({
1971
+ createdAt: new Date(),
1972
+ ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1973
+ });
1974
+ await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
1975
+ return checkout;
1976
+ }
1977
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1911
1978
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
1912
1979
  }
1913
1980
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
@@ -1917,7 +1984,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1917
1984
  args: ['CheckoutSubscriptionRepository']
1918
1985
  }] }, { type: undefined, decorators: [{
1919
1986
  type: Inject,
1920
- args: ['SubscriptionRepository']
1987
+ args: [PERSISTENCE_PROVIDER]
1921
1988
  }] }, { type: CouponService }] });
1922
1989
 
1923
1990
  class UtilHelper {
@@ -1975,7 +2042,11 @@ class HomeShopService {
1975
2042
  getHomeData() {
1976
2043
  return this.getHomeConfiguration().pipe(map((home) => (home?.data?.expiresAt > new Date() ? home : null)), concatMap((home) => home
1977
2044
  ? of(home)
1978
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
2045
+ : forkJoin([
2046
+ this.getDiscoverProducts(this.gender),
2047
+ this.getFeaturedProducts(this.gender),
2048
+ this.getVerticalProducts(this.gender),
2049
+ ]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
1979
2050
  discoverProducts,
1980
2051
  featuredProducts,
1981
2052
  verticalProducts,
@@ -1997,15 +2068,18 @@ class HomeShopService {
1997
2068
  getMinValueForFreeShipping() {
1998
2069
  return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
1999
2070
  }
2000
- getDiscoverProducts() {
2001
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2071
+ getDiscoverProducts(gender) {
2072
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2002
2073
  }
2003
- getFeaturedProducts() {
2004
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2074
+ getFeaturedProducts(gender) {
2075
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories, undefined, gender)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
2005
2076
  }
2006
- getVerticalProducts() {
2077
+ getVerticalProducts(gender) {
2007
2078
  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({
2008
- filters: { categories: { operator: Where.IN, value: [category.id] } },
2079
+ filters: {
2080
+ categories: { operator: Where.IN, value: [category.id] },
2081
+ ...(gender ? { tags: { operator: Where.IN, value: [gender] } } : {}),
2082
+ },
2009
2083
  limits: { limit: 12 },
2010
2084
  })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
2011
2085
  }
@@ -2027,6 +2101,9 @@ class HomeShopService {
2027
2101
  data,
2028
2102
  })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
2029
2103
  }
2104
+ get gender() {
2105
+ return this.homeId === 'mens_market' ? 'masculino' : undefined;
2106
+ }
2030
2107
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable }); }
2031
2108
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: HomeShopService }); }
2032
2109
  }
@@ -2165,12 +2242,14 @@ class AngularConnectModule {
2165
2242
  ? OldCategoryStructureAdapter
2166
2243
  : NewCategoryStructureAdapter,
2167
2244
  },
2245
+ { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2168
2246
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2169
2247
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2170
2248
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2171
2249
  ...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2172
2250
  ...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2173
2251
  ...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2252
+ ...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
2174
2253
  ],
2175
2254
  };
2176
2255
  }
@@ -2191,6 +2270,13 @@ class AngularConnectModule {
2191
2270
  OrderService,
2192
2271
  ShippingService,
2193
2272
  WishlistService,
2273
+ {
2274
+ provide: UpdateUserImage,
2275
+ useFactory: (userRepository, fileUploader) => {
2276
+ return new UpdateUserImage(userRepository, fileUploader);
2277
+ },
2278
+ deps: ['UserRepository', 'FileUploaderService'],
2279
+ },
2194
2280
  ], imports: [provideFirebaseApp((injector) => {
2195
2281
  const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2196
2282
  try {
@@ -2235,6 +2321,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2235
2321
  OrderService,
2236
2322
  ShippingService,
2237
2323
  WishlistService,
2324
+ {
2325
+ provide: UpdateUserImage,
2326
+ useFactory: (userRepository, fileUploader) => {
2327
+ return new UpdateUserImage(userRepository, fileUploader);
2328
+ },
2329
+ deps: ['UserRepository', 'FileUploaderService'],
2330
+ },
2238
2331
  ],
2239
2332
  }]
2240
2333
  }] });
@@ -2243,5 +2336,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2243
2336
  * Generated bundle index. Do not edit.
2244
2337
  */
2245
2338
 
2246
- export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2339
+ export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2247
2340
  //# sourceMappingURL=infrab4a-connect-angular.mjs.map