@infrab4a/connect-angular 5.0.0-beta.2 → 5.0.0-beta.20

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 (33) hide show
  1. package/angular-connect.module.d.ts +3 -1
  2. package/consts/index.d.ts +1 -0
  3. package/consts/persistence.const.d.ts +1 -0
  4. package/esm2022/angular-connect.module.mjs +4 -2
  5. package/esm2022/angular-firestore.module.mjs +15 -13
  6. package/esm2022/angular-hasura-graphql.module.mjs +24 -2
  7. package/esm2022/consts/index.mjs +2 -1
  8. package/esm2022/consts/persistence.const.mjs +2 -0
  9. package/esm2022/index.mjs +2 -1
  10. package/esm2022/persistence/cookie-data-persistence.mjs +22 -0
  11. package/esm2022/persistence/data-persistence.mjs +2 -0
  12. package/esm2022/persistence/index.mjs +3 -0
  13. package/esm2022/services/cart.service.mjs +3 -2
  14. package/esm2022/services/catalog/adapters/new-category-structure.adapter.mjs +6 -4
  15. package/esm2022/services/catalog/catalog.service.mjs +39 -12
  16. package/esm2022/services/catalog/category.service.mjs +4 -4
  17. package/esm2022/services/catalog/wishlist.service.mjs +14 -11
  18. package/esm2022/services/checkout-subscription.service.mjs +18 -21
  19. package/esm2022/services/checkout.service.mjs +13 -16
  20. package/esm2022/services/coupon.service.mjs +35 -10
  21. package/fesm2022/infrab4a-connect-angular.mjs +185 -87
  22. package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
  23. package/index.d.ts +1 -0
  24. package/package.json +3 -3
  25. package/persistence/cookie-data-persistence.d.ts +10 -0
  26. package/persistence/data-persistence.d.ts +6 -0
  27. package/persistence/index.d.ts +2 -0
  28. package/services/catalog/catalog.service.d.ts +9 -4
  29. package/services/catalog/category.service.d.ts +6 -1
  30. package/services/catalog/wishlist.service.d.ts +6 -5
  31. package/services/checkout-subscription.service.d.ts +5 -4
  32. package/services/checkout.service.d.ts +8 -4
  33. package/services/coupon.service.d.ts +6 -2
@@ -1,20 +1,20 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angular/core';
3
3
  import * as i1$4 from '@angular/fire/app';
4
- import { FirebaseApp, getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
4
+ import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } 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, 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';
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, ProductStockNotificationHasuraGraphQLRepository, 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
- import { Auth, getAuth, provideAuth, getIdToken, authState } from '@angular/fire/auth';
8
+ import { Auth, provideAuth, getAuth, 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
- import { Firestore, getFirestore, memoryLocalCache, initializeFirestore, provideFirestore, doc, docSnapshots } from '@angular/fire/firestore';
11
+ import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
12
12
  import * as i2 from '@angular/fire/storage';
13
- import { Storage, getStorage, provideStorage } from '@angular/fire/storage';
14
- import { combineLatest, of, from, throwError, Subject, iif, forkJoin } from 'rxjs';
15
- import { map, catchError, mergeMap, concatMap, tap } from 'rxjs/operators';
13
+ import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
16
14
  import cookie from 'js-cookie';
17
- import { __metadata, __decorate } from 'tslib';
15
+ import { of, from, combineLatest, throwError, Subject, iif, forkJoin } from 'rxjs';
16
+ import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
17
+ import { __decorate, __metadata } from 'tslib';
18
18
  import { Type } from 'class-transformer';
19
19
  import * as i1$3 from '@angular/common/http';
20
20
 
@@ -61,6 +61,8 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
61
61
 
62
62
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
63
63
 
64
+ const PERSISTENCE_PROVIDER = 'PERSISTENCE_PROVIDER';
65
+
64
66
  class AngularFirebaseAuthModule {
65
67
  static initializeApp(options, nameOrConfig) {
66
68
  return {
@@ -195,7 +197,7 @@ class AngularFirestoreModule {
195
197
  {
196
198
  provide: 'FirestoreOptions',
197
199
  useFactory: (firestore, platformId) => ({
198
- firestore,
200
+ firestore: new ConnectFirestoreService(firestore),
199
201
  interceptors: {
200
202
  request: (request) => {
201
203
  if (isPlatformBrowser(platformId))
@@ -413,12 +415,13 @@ class AngularFirestoreModule {
413
415
  ], imports: [AngularElasticSeachModule,
414
416
  provideFirestore((injector) => {
415
417
  const platformId = injector.get(PLATFORM_ID);
416
- if (isPlatformServer(platformId))
417
- return getFirestore(injector.get(FirebaseApp));
418
- if (!MobileOperationSystemCheckerHelper.isAppleDevice())
419
- return getFirestore(injector.get(FirebaseApp));
418
+ if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
419
+ return initializeFirestore(injector.get(FirebaseApp), {
420
+ ignoreUndefinedProperties: true,
421
+ });
420
422
  const firestore = initializeFirestore(injector.get(FirebaseApp), {
421
423
  experimentalForceLongPolling: true,
424
+ ignoreUndefinedProperties: true,
422
425
  localCache: memoryLocalCache(),
423
426
  });
424
427
  return firestore;
@@ -432,12 +435,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
432
435
  AngularElasticSeachModule,
433
436
  provideFirestore((injector) => {
434
437
  const platformId = injector.get(PLATFORM_ID);
435
- if (isPlatformServer(platformId))
436
- return getFirestore(injector.get(FirebaseApp));
437
- if (!MobileOperationSystemCheckerHelper.isAppleDevice())
438
- return getFirestore(injector.get(FirebaseApp));
438
+ if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
439
+ return initializeFirestore(injector.get(FirebaseApp), {
440
+ ignoreUndefinedProperties: true,
441
+ });
439
442
  const firestore = initializeFirestore(injector.get(FirebaseApp), {
440
443
  experimentalForceLongPolling: true,
444
+ ignoreUndefinedProperties: true,
441
445
  localCache: memoryLocalCache(),
442
446
  });
443
447
  return firestore;
@@ -448,7 +452,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
448
452
  {
449
453
  provide: 'FirestoreOptions',
450
454
  useFactory: (firestore, platformId) => ({
451
- firestore,
455
+ firestore: new ConnectFirestoreService(firestore),
452
456
  interceptors: {
453
457
  request: (request) => {
454
458
  if (isPlatformBrowser(platformId))
@@ -744,6 +748,17 @@ class AngularHasuraGraphQLModule {
744
748
  },
745
749
  deps: ['HasuraConfig'],
746
750
  },
751
+ {
752
+ provide: 'ProductStockNotificationRepository',
753
+ useExisting: ProductStockNotificationHasuraGraphQLRepository,
754
+ },
755
+ {
756
+ provide: ProductStockNotificationHasuraGraphQLRepository,
757
+ useFactory: (hasuraConfig) => {
758
+ return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
759
+ },
760
+ deps: ['HasuraConfig'],
761
+ },
747
762
  {
748
763
  provide: 'CategoryFilterRepository',
749
764
  useExisting: CategoryFilterHasuraGraphQLRepository,
@@ -870,6 +885,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
870
885
  },
871
886
  deps: ['HasuraConfig'],
872
887
  },
888
+ {
889
+ provide: 'ProductStockNotificationRepository',
890
+ useExisting: ProductStockNotificationHasuraGraphQLRepository,
891
+ },
892
+ {
893
+ provide: ProductStockNotificationHasuraGraphQLRepository,
894
+ useFactory: (hasuraConfig) => {
895
+ return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
896
+ },
897
+ deps: ['HasuraConfig'],
898
+ },
873
899
  {
874
900
  provide: 'CategoryFilterRepository',
875
901
  useExisting: CategoryFilterHasuraGraphQLRepository,
@@ -927,6 +953,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
927
953
  }]
928
954
  }] });
929
955
 
956
+ class CookieDataPersistence {
957
+ get(key) {
958
+ return of(cookie.get(key));
959
+ }
960
+ remove(key) {
961
+ return of(cookie.remove(key));
962
+ }
963
+ set(key, value) {
964
+ return from(cookie.set(key, value)).pipe(map(() => { }));
965
+ }
966
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
967
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence }); }
968
+ }
969
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, decorators: [{
970
+ type: Injectable
971
+ }] });
972
+
930
973
  class AuthService {
931
974
  constructor(angularFireAuth, userRepository) {
932
975
  this.angularFireAuth = angularFireAuth;
@@ -1033,32 +1076,33 @@ class CouponService {
1033
1076
  return of(discount);
1034
1077
  }
1035
1078
  async calcDiscountShopping(coupon, checkout) {
1036
- let discount = 0;
1079
+ let discountInfo = null;
1037
1080
  if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
1038
- discount = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1081
+ discountInfo = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1039
1082
  }
1040
1083
  else {
1041
- discount = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1084
+ discountInfo = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1042
1085
  }
1043
- return discount;
1086
+ return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
1044
1087
  }
1045
1088
  async calcDiscountByType(type, value, categories, checkout) {
1046
1089
  let discount = 0;
1047
- let lineItensDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1048
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
1090
+ let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1091
+ const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
1049
1092
  if (type == CouponTypes.ABSOLUTE) {
1050
1093
  discount = value > subTotal ? subTotal : value;
1051
1094
  }
1052
1095
  else {
1053
1096
  discount = subTotal * (value / 100);
1054
1097
  }
1055
- return discount;
1098
+ const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1099
+ return { discount, lineItems };
1056
1100
  }
1057
1101
  async hasMinSubTotal(coupon, checkout) {
1058
1102
  if (!coupon.minSubTotalValue)
1059
1103
  return true;
1060
1104
  let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1061
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
1105
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
1062
1106
  if (coupon.minSubTotalValue <= subTotal)
1063
1107
  return true;
1064
1108
  return false;
@@ -1126,7 +1170,7 @@ class CouponService {
1126
1170
  }
1127
1171
  return lineItensDiscount;
1128
1172
  }
1129
- calcCheckoutSubtotal(lineItens, user, shop) {
1173
+ calcCheckoutSubtotal(lineItens, user) {
1130
1174
  return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1131
1175
  ? acc + curr.price?.subscriberPrice * curr.quantity
1132
1176
  : acc + curr.pricePaid * curr.quantity, 0) || 0);
@@ -1164,6 +1208,30 @@ class CouponService {
1164
1208
  }
1165
1209
  return couponUseLimits;
1166
1210
  }
1211
+ calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
1212
+ let lineItemsDiscount = [];
1213
+ if (type === CouponTypes.ABSOLUTE) {
1214
+ const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
1215
+ lineItemsDiscount = lineItems.map((item) => {
1216
+ const totalItemPercentage = item.pricePaid / subTotal;
1217
+ const discountItem = couponDiscountMax * totalItemPercentage;
1218
+ return {
1219
+ ...item,
1220
+ discount: Number(discountItem.toFixed(2)),
1221
+ };
1222
+ });
1223
+ }
1224
+ else {
1225
+ lineItemsDiscount = lineItems.map((item) => {
1226
+ const discountItem = item.pricePaid * (couponDiscount / 100);
1227
+ return {
1228
+ ...item,
1229
+ discount: Number(discountItem.toFixed(2)),
1230
+ };
1231
+ });
1232
+ }
1233
+ return lineItemsDiscount;
1234
+ }
1167
1235
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
1168
1236
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
1169
1237
  }
@@ -1187,18 +1255,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1187
1255
  }] }] });
1188
1256
 
1189
1257
  class CheckoutService {
1190
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
1258
+ constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1191
1259
  this.couponService = couponService;
1192
1260
  this.checkoutRepository = checkoutRepository;
1193
- this.orderRepository = orderRepository;
1194
1261
  this.userRepository = userRepository;
1195
1262
  this.defaultShop = defaultShop;
1263
+ this.dataPersistence = dataPersistence;
1196
1264
  }
1197
1265
  getCheckout(checkoutData) {
1198
- const checkoutId = cookie.get('checkoutId');
1199
- if (!isNil(checkoutId))
1200
- return from(this.checkoutRepository.get({ id: checkoutId }));
1201
- return from(this.createCheckout(checkoutData));
1266
+ return this.dataPersistence
1267
+ .get('checkoutId')
1268
+ .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
1202
1269
  }
1203
1270
  getUserByCheckout(checkoutId) {
1204
1271
  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'))));
@@ -1210,8 +1277,7 @@ class CheckoutService {
1210
1277
  return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1211
1278
  }
1212
1279
  clearCheckoutFromSession() {
1213
- cookie.remove('checkoutId');
1214
- return of();
1280
+ return this.dataPersistence.remove('checkoutId');
1215
1281
  }
1216
1282
  calcDiscount(coupon) {
1217
1283
  return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
@@ -1225,10 +1291,10 @@ class CheckoutService {
1225
1291
  ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1226
1292
  shop: checkoutData?.shop || this.defaultShop,
1227
1293
  });
1228
- cookie.set('checkoutId', checkout.id);
1294
+ await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1229
1295
  return checkout;
1230
1296
  }
1231
- 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 }); }
1297
+ 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 }); }
1232
1298
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService }); }
1233
1299
  }
1234
1300
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, decorators: [{
@@ -1236,15 +1302,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1236
1302
  }], ctorParameters: () => [{ type: CouponService }, { type: undefined, decorators: [{
1237
1303
  type: Inject,
1238
1304
  args: ['CheckoutRepository']
1239
- }] }, { type: undefined, decorators: [{
1240
- type: Inject,
1241
- args: ['OrderRepository']
1242
1305
  }] }, { type: undefined, decorators: [{
1243
1306
  type: Inject,
1244
1307
  args: ['UserRepository']
1245
1308
  }] }, { type: i1$2.Shops, decorators: [{
1246
1309
  type: Inject,
1247
1310
  args: [DEFAULT_SHOP]
1311
+ }] }, { type: undefined, decorators: [{
1312
+ type: Inject,
1313
+ args: [PERSISTENCE_PROVIDER]
1248
1314
  }] }] });
1249
1315
 
1250
1316
  class CartService {
@@ -1306,6 +1372,7 @@ class CartService {
1306
1372
  weight: weight ?? product.weight,
1307
1373
  quantity: (item.quantity || 0) + (quantity || 0),
1308
1374
  pricePaid,
1375
+ discount: 0,
1309
1376
  categories: product.categories ?? [],
1310
1377
  isGift: isGift ?? null,
1311
1378
  costPrice: product.costPrice ?? 0,
@@ -1357,7 +1424,7 @@ class CartService {
1357
1424
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1358
1425
  }
1359
1426
  updateUserCart(user) {
1360
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
1427
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1361
1428
  .updateCheckoutLineItems(Checkout.toInstance({
1362
1429
  ...checkout.toPlain(),
1363
1430
  lineItems: checkout.lineItems?.length
@@ -1541,9 +1608,11 @@ class NewCategoryStructureAdapter {
1541
1608
  .then((categories) => categories.map((category) => category.id.toString()));
1542
1609
  }
1543
1610
  async getCategory(category) {
1544
- return isNil(category.isCollection) || (category.isCollection && !category.products?.length)
1545
- ? this.categoryRepository.get({ id: category.id })
1546
- : category;
1611
+ const collectionCategory = category.isCollection ||
1612
+ (isNil(category.isCollection) && !category.products?.length) ||
1613
+ category.isWishlist ||
1614
+ category.brandCategory;
1615
+ return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1547
1616
  }
1548
1617
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
1549
1618
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter }); }
@@ -1576,8 +1645,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1576
1645
  }] }] });
1577
1646
 
1578
1647
  class CatalogService {
1579
- constructor(productRepository, categoryStructureAdapter, shop, productIndex) {
1648
+ constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1580
1649
  this.productRepository = productRepository;
1650
+ this.productStockNotificationRepository = productStockNotificationRepository;
1651
+ this.categoryRepository = categoryRepository;
1581
1652
  this.categoryStructureAdapter = categoryStructureAdapter;
1582
1653
  this.shop = shop;
1583
1654
  this.productIndex = productIndex;
@@ -1607,17 +1678,22 @@ class CatalogService {
1607
1678
  if (!sort || sort === 'most-relevant')
1608
1679
  return {};
1609
1680
  if (sort === 'best-sellers')
1610
- return { shoppingCount: 'desc' };
1681
+ return {
1682
+ shoppingCount: 'desc',
1683
+ rate: 'desc',
1684
+ stock: 'desc',
1685
+ name: 'asc',
1686
+ };
1611
1687
  if (sort === 'biggest-price')
1612
- return { subscriberPrice: 'desc' };
1688
+ return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1613
1689
  if (sort === 'lowest-price')
1614
- return { subscriberPrice: 'asc' };
1690
+ return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1615
1691
  if (sort === 'best-rating')
1616
- return { rate: 'desc' };
1692
+ return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1617
1693
  if (sort === 'news')
1618
1694
  return { createdAt: 'desc' };
1619
1695
  if (sort === 'biggest-discount')
1620
- return { subscriberDiscountPercentage: 'desc' };
1696
+ return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1621
1697
  };
1622
1698
  this.buildLimitQuery = (options) => {
1623
1699
  const limit = options?.perPage || 20;
@@ -1651,9 +1727,24 @@ class CatalogService {
1651
1727
  brands: distinct?.brand,
1652
1728
  }));
1653
1729
  }
1730
+ async addCustomerToStockNotification(shop, productId, name, email) {
1731
+ return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1732
+ }
1654
1733
  async findCatalog(options, limits) {
1655
- if (this.hasTerm(options) && options.sort === 'most-relevant')
1656
- return this.findCatalogByTermAndSortByMostRevelant(options, limits);
1734
+ if (this.hasTerm(options) && options.sort === 'most-relevant') {
1735
+ const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
1736
+ return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1737
+ }
1738
+ if (this.hasCategory(options) && options.sort === 'most-relevant') {
1739
+ const productsIds = await this.productRepository
1740
+ .find({
1741
+ filters: {
1742
+ ...(await this.buildMainFilter(options)),
1743
+ },
1744
+ })
1745
+ .then((products) => products.data.map((product) => product.id));
1746
+ return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1747
+ }
1657
1748
  const repoParams = {
1658
1749
  filters: {
1659
1750
  ...(await this.buildMainFilter(options)),
@@ -1681,8 +1772,7 @@ class CatalogService {
1681
1772
  .search(term, 999, this.shop)
1682
1773
  .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1683
1774
  }
1684
- async findCatalogByTermAndSortByMostRevelant(options, limits) {
1685
- const productIds = await this.findCatalogIdsByElasticSearch(options.term);
1775
+ async findCatalogAndSortByMostRevelant(productIds, options, limits) {
1686
1776
  const totalResult = await this.productRepository.findCatalog({
1687
1777
  fields: ['id', 'stock'],
1688
1778
  filters: {
@@ -1728,7 +1818,7 @@ class CatalogService {
1728
1818
  return [...new Set(sorted.map(({ _source }) => _source.id))];
1729
1819
  }));
1730
1820
  }
1731
- 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 }); }
1821
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
1732
1822
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
1733
1823
  }
1734
1824
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, decorators: [{
@@ -1736,6 +1826,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1736
1826
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1737
1827
  type: Inject,
1738
1828
  args: ['ProductRepository']
1829
+ }] }, { type: undefined, decorators: [{
1830
+ type: Inject,
1831
+ args: ['ProductStockNotificationRepository']
1832
+ }] }, { type: undefined, decorators: [{
1833
+ type: Inject,
1834
+ args: ['CategoryRepository']
1739
1835
  }] }, { type: undefined, decorators: [{
1740
1836
  type: Inject,
1741
1837
  args: [CATEGORY_STRUCTURE]
@@ -1752,15 +1848,15 @@ class CategoryService {
1752
1848
  this.categoryStructureAdapter = categoryStructureAdapter;
1753
1849
  this.shop = shop;
1754
1850
  }
1755
- async fetchBrands(category, mainGender) {
1851
+ async fetchBrands(category, options) {
1756
1852
  const brands = await this.productRepository
1757
1853
  .findCatalog({
1758
1854
  filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1759
1855
  fields: ['brand'],
1760
- }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1856
+ }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1761
1857
  .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1762
1858
  return this.categoryRepository
1763
- .find({ filters: { brandCategory: true, shop: this.shop }, orderBy: { name: 'asc' } })
1859
+ .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } })
1764
1860
  .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1765
1861
  }
1766
1862
  async fetchFilterOptions(category) {
@@ -1809,12 +1905,11 @@ __decorate([
1809
1905
  ], CategoryWithTree.prototype, "children", void 0);
1810
1906
 
1811
1907
  class WishlistService {
1812
- constructor(wishlistRepository, categoryRepository, shop, productRepository, categoryFilterRepository, productIndex) {
1908
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productIndex) {
1813
1909
  this.wishlistRepository = wishlistRepository;
1814
- this.categoryRepository = categoryRepository;
1815
1910
  this.shop = shop;
1816
1911
  const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1817
- this.catalogService = new CatalogService(productRepository, categoryStructureAdapter, shop, productIndex);
1912
+ this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1818
1913
  this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1819
1914
  }
1820
1915
  getCatalogService() {
@@ -1823,7 +1918,7 @@ class WishlistService {
1823
1918
  getCategoryService() {
1824
1919
  return this.categoryService;
1825
1920
  }
1826
- async create({ personId, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
1921
+ async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, }) {
1827
1922
  const data = {
1828
1923
  slug: '',
1829
1924
  name: title,
@@ -1838,7 +1933,7 @@ class WishlistService {
1838
1933
  personName: userFullName,
1839
1934
  personPhoto: userPhoto,
1840
1935
  brandCategory: false,
1841
- published: true,
1936
+ published,
1842
1937
  theme,
1843
1938
  bannerUrl,
1844
1939
  };
@@ -1846,11 +1941,12 @@ class WishlistService {
1846
1941
  await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
1847
1942
  return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
1848
1943
  }
1849
- update({ id, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
1944
+ update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, }) {
1850
1945
  const data = {
1851
1946
  id,
1852
1947
  name: title,
1853
1948
  description,
1949
+ published,
1854
1950
  metadata: {
1855
1951
  title: `${userFullName} - ${title}`,
1856
1952
  description: `${userFullName} - ${description}`,
@@ -1894,7 +1990,7 @@ class WishlistService {
1894
1990
  }
1895
1991
  return wishlist;
1896
1992
  }
1897
- 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 }); }
1993
+ 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: 'ProductStockNotificationRepository' }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable }); }
1898
1994
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService }); }
1899
1995
  }
1900
1996
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, decorators: [{
@@ -1902,9 +1998,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1902
1998
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1903
1999
  type: Inject,
1904
2000
  args: ['WishlistRepository']
1905
- }] }, { type: undefined, decorators: [{
1906
- type: Inject,
1907
- args: ['CategoryRepository']
1908
2001
  }] }, { type: i1$2.Shops, decorators: [{
1909
2002
  type: Inject,
1910
2003
  args: [DEFAULT_SHOP]
@@ -1914,31 +2007,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1914
2007
  }] }, { type: undefined, decorators: [{
1915
2008
  type: Inject,
1916
2009
  args: ['CategoryFilterRepository']
2010
+ }] }, { type: undefined, decorators: [{
2011
+ type: Inject,
2012
+ args: ['CategoryRepository']
2013
+ }] }, { type: undefined, decorators: [{
2014
+ type: Inject,
2015
+ args: ['ProductStockNotificationRepository']
1917
2016
  }] }, { type: i1$2.ProductsIndex }] });
1918
2017
 
1919
2018
  class CheckoutSubscriptionService {
1920
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
2019
+ constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
1921
2020
  this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1922
- this.subscriptionRepository = subscriptionRepository;
2021
+ this.dataPersistence = dataPersistence;
1923
2022
  this.couponService = couponService;
1924
2023
  }
1925
2024
  getCheckoutSubscription(checkoutData) {
1926
- const checkoutId = cookie.get('checkoutSubscriptionId');
1927
- if (!isNil(checkoutId))
1928
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
1929
- return from(this.createCheckoutSubscription(checkoutData));
1930
- }
1931
- async createCheckoutSubscription(checkoutData) {
1932
- const checkout = await this.checkoutSubscriptionRepository.create({
1933
- createdAt: new Date(),
1934
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1935
- });
1936
- cookie.set('checkoutSubscriptionId', checkout.id);
1937
- return checkout;
2025
+ return this.dataPersistence
2026
+ .get('checkoutSubscriptionId')
2027
+ .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
1938
2028
  }
1939
2029
  clearCheckoutSubscriptionFromSession() {
1940
- cookie.remove('checkoutSubscriptionId');
1941
- return of();
2030
+ return this.dataPersistence.remove('checkoutSubscriptionId');
1942
2031
  }
1943
2032
  checkCoupon(nickname, userEmail) {
1944
2033
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
@@ -1948,7 +2037,15 @@ class CheckoutSubscriptionService {
1948
2037
  calcDiscountSubscription(coupon) {
1949
2038
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1950
2039
  }
1951
- 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 }); }
2040
+ async createCheckoutSubscription(checkoutData) {
2041
+ const checkout = await this.checkoutSubscriptionRepository.create({
2042
+ createdAt: new Date(),
2043
+ ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
2044
+ });
2045
+ await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2046
+ return checkout;
2047
+ }
2048
+ 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 }); }
1952
2049
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
1953
2050
  }
1954
2051
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
@@ -1958,7 +2055,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1958
2055
  args: ['CheckoutSubscriptionRepository']
1959
2056
  }] }, { type: undefined, decorators: [{
1960
2057
  type: Inject,
1961
- args: ['SubscriptionRepository']
2058
+ args: [PERSISTENCE_PROVIDER]
1962
2059
  }] }, { type: CouponService }] });
1963
2060
 
1964
2061
  class UtilHelper {
@@ -2216,6 +2313,7 @@ class AngularConnectModule {
2216
2313
  ? OldCategoryStructureAdapter
2217
2314
  : NewCategoryStructureAdapter,
2218
2315
  },
2316
+ { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2219
2317
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2220
2318
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2221
2319
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
@@ -2309,5 +2407,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2309
2407
  * Generated bundle index. Do not edit.
2310
2408
  */
2311
2409
 
2312
- export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2410
+ export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2313
2411
  //# sourceMappingURL=infrab4a-connect-angular.mjs.map