@infrab4a/connect-angular 5.0.0-beta.5 → 5.0.0-beta.50

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 (67) hide show
  1. package/angular-connect.module.d.ts +9 -6
  2. package/angular-firestore.module.d.ts +1 -2
  3. package/consts/index.d.ts +1 -0
  4. package/consts/persistence.const.d.ts +1 -0
  5. package/esm2022/angular-connect.module.mjs +25 -5
  6. package/esm2022/angular-elastic-search.module.mjs +1 -1
  7. package/esm2022/angular-firebase-auth.module.mjs +1 -1
  8. package/esm2022/angular-firestore.module.mjs +17 -34
  9. package/esm2022/angular-hasura-graphql.module.mjs +32 -2
  10. package/esm2022/consts/category-structure.mjs +1 -1
  11. package/esm2022/consts/default-shop.const.mjs +1 -1
  12. package/esm2022/consts/es-config.const.mjs +1 -1
  13. package/esm2022/consts/firebase-const.mjs +1 -1
  14. package/esm2022/consts/hasura-options.const.mjs +1 -1
  15. package/esm2022/consts/index.mjs +2 -1
  16. package/esm2022/consts/persistence.const.mjs +2 -0
  17. package/esm2022/consts/storage-base-url.const.mjs +1 -1
  18. package/esm2022/helpers/index.mjs +1 -1
  19. package/esm2022/helpers/mobile-operation-system-checker.helper.mjs +1 -1
  20. package/esm2022/index.mjs +2 -1
  21. package/esm2022/persistence/cookie-data-persistence.mjs +22 -0
  22. package/esm2022/persistence/data-persistence.mjs +2 -0
  23. package/esm2022/persistence/index.mjs +3 -0
  24. package/esm2022/services/auth.service.mjs +1 -1
  25. package/esm2022/services/cart.service.mjs +11 -10
  26. package/esm2022/services/catalog/adapters/category-structure.adapter.mjs +1 -1
  27. package/esm2022/services/catalog/adapters/index.mjs +1 -1
  28. package/esm2022/services/catalog/adapters/new-category-structure.adapter.mjs +6 -4
  29. package/esm2022/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
  30. package/esm2022/services/catalog/catalog.service.mjs +59 -14
  31. package/esm2022/services/catalog/category.service.mjs +4 -4
  32. package/esm2022/services/catalog/enums/index.mjs +1 -1
  33. package/esm2022/services/catalog/enums/product-sorts.enum.mjs +1 -1
  34. package/esm2022/services/catalog/index.mjs +1 -1
  35. package/esm2022/services/catalog/models/category-with-tree.model.mjs +1 -1
  36. package/esm2022/services/catalog/models/index.mjs +1 -1
  37. package/esm2022/services/catalog/types/index.mjs +1 -1
  38. package/esm2022/services/catalog/types/product-sort.type.mjs +1 -1
  39. package/esm2022/services/catalog/wishlist.service.mjs +30 -16
  40. package/esm2022/services/checkout-subscription.service.mjs +18 -21
  41. package/esm2022/services/checkout.service.mjs +13 -16
  42. package/esm2022/services/coupon.service.mjs +35 -10
  43. package/esm2022/services/helpers/index.mjs +1 -1
  44. package/esm2022/services/helpers/util.helper.mjs +1 -1
  45. package/esm2022/services/home-shop.service.mjs +1 -1
  46. package/esm2022/services/index.mjs +1 -1
  47. package/esm2022/services/order.service.mjs +1 -1
  48. package/esm2022/services/shipping.service.mjs +1 -1
  49. package/esm2022/services/types/index.mjs +1 -1
  50. package/esm2022/services/types/required-checkout-data.type.mjs +1 -1
  51. package/esm2022/services/types/required-checkout-subscription-data.type.mjs +1 -1
  52. package/esm2022/services/types/shipping-methods.type.mjs +1 -1
  53. package/esm2022/types/firebase-app-config.type.mjs +1 -1
  54. package/esm2022/types/index.mjs +1 -1
  55. package/fesm2022/infrab4a-connect-angular.mjs +256 -121
  56. package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
  57. package/index.d.ts +1 -0
  58. package/package.json +5 -5
  59. package/persistence/cookie-data-persistence.d.ts +10 -0
  60. package/persistence/data-persistence.d.ts +6 -0
  61. package/persistence/index.d.ts +2 -0
  62. package/services/catalog/catalog.service.d.ts +5 -2
  63. package/services/catalog/category.service.d.ts +6 -1
  64. package/services/catalog/wishlist.service.d.ts +10 -4
  65. package/services/checkout-subscription.service.d.ts +5 -4
  66. package/services/checkout.service.d.ts +8 -4
  67. 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
+ import * as i2 from '@angular/fire/storage';
6
+ import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
5
7
  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';
8
+ 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, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, OrderBlockedFirestoreRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, PersonTypes, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
7
9
  import * as i1 from '@angular/fire/auth';
8
- import { Auth, getAuth, provideAuth, getIdToken, authState } from '@angular/fire/auth';
10
+ import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
9
11
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
10
12
  import * as i1$1 from '@angular/fire/firestore';
11
- import { Firestore, getFirestore, memoryLocalCache, initializeFirestore, provideFirestore, doc, docSnapshots } from '@angular/fire/firestore';
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 { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
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 {
@@ -169,8 +171,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
169
171
  }]
170
172
  }] });
171
173
 
172
- const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
173
-
174
174
  class MobileOperationSystemCheckerHelper {
175
175
  static isAppleDevice() {
176
176
  return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
@@ -190,12 +190,12 @@ class AngularFirestoreModule {
190
190
  };
191
191
  }
192
192
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
193
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule, i2.StorageModule] }); }
193
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] }); }
194
194
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, providers: [
195
195
  {
196
196
  provide: 'FirestoreOptions',
197
197
  useFactory: (firestore, platformId) => ({
198
- firestore,
198
+ firestore: new ConnectFirestoreService(firestore),
199
199
  interceptors: {
200
200
  request: (request) => {
201
201
  if (isPlatformBrowser(platformId))
@@ -403,27 +403,20 @@ class AngularFirestoreModule {
403
403
  },
404
404
  deps: ['FirestoreOptions', ProductFirestoreRepository],
405
405
  },
406
- {
407
- provide: 'FileUploaderService',
408
- useFactory: (storage, baseUrl) => {
409
- return new FirebaseFileUploaderService(storage, baseUrl);
410
- },
411
- deps: [Storage, STORAGE_BASE_URL],
412
- },
413
406
  ], imports: [AngularElasticSeachModule,
414
407
  provideFirestore((injector) => {
415
408
  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));
409
+ if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
410
+ return initializeFirestore(injector.get(FirebaseApp), {
411
+ ignoreUndefinedProperties: true,
412
+ });
420
413
  const firestore = initializeFirestore(injector.get(FirebaseApp), {
421
414
  experimentalForceLongPolling: true,
415
+ ignoreUndefinedProperties: true,
422
416
  localCache: memoryLocalCache(),
423
417
  });
424
418
  return firestore;
425
- }),
426
- provideStorage(() => getStorage())] }); }
419
+ })] }); }
427
420
  }
428
421
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, decorators: [{
429
422
  type: NgModule,
@@ -432,23 +425,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
432
425
  AngularElasticSeachModule,
433
426
  provideFirestore((injector) => {
434
427
  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));
428
+ if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
429
+ return initializeFirestore(injector.get(FirebaseApp), {
430
+ ignoreUndefinedProperties: true,
431
+ });
439
432
  const firestore = initializeFirestore(injector.get(FirebaseApp), {
440
433
  experimentalForceLongPolling: true,
434
+ ignoreUndefinedProperties: true,
441
435
  localCache: memoryLocalCache(),
442
436
  });
443
437
  return firestore;
444
438
  }),
445
- provideStorage(() => getStorage()),
446
439
  ],
447
440
  providers: [
448
441
  {
449
442
  provide: 'FirestoreOptions',
450
443
  useFactory: (firestore, platformId) => ({
451
- firestore,
444
+ firestore: new ConnectFirestoreService(firestore),
452
445
  interceptors: {
453
446
  request: (request) => {
454
447
  if (isPlatformBrowser(platformId))
@@ -656,13 +649,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
656
649
  },
657
650
  deps: ['FirestoreOptions', ProductFirestoreRepository],
658
651
  },
659
- {
660
- provide: 'FileUploaderService',
661
- useFactory: (storage, baseUrl) => {
662
- return new FirebaseFileUploaderService(storage, baseUrl);
663
- },
664
- deps: [Storage, STORAGE_BASE_URL],
665
- },
666
652
  ],
667
653
  }]
668
654
  }] });
@@ -744,6 +730,17 @@ class AngularHasuraGraphQLModule {
744
730
  },
745
731
  deps: ['HasuraConfig'],
746
732
  },
733
+ {
734
+ provide: 'ProductStockNotificationRepository',
735
+ useExisting: ProductStockNotificationHasuraGraphQLRepository,
736
+ },
737
+ {
738
+ provide: ProductStockNotificationHasuraGraphQLRepository,
739
+ useFactory: (hasuraConfig) => {
740
+ return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
741
+ },
742
+ deps: ['HasuraConfig'],
743
+ },
747
744
  {
748
745
  provide: 'CategoryFilterRepository',
749
746
  useExisting: CategoryFilterHasuraGraphQLRepository,
@@ -797,6 +794,10 @@ class AngularHasuraGraphQLModule {
797
794
  provide: 'WishlistRepository',
798
795
  useExisting: WishlistHasuraGraphQLRepository,
799
796
  },
797
+ {
798
+ provide: 'OrderBlockedRepository',
799
+ useExisting: OrderBlockedFirestoreRepository,
800
+ },
800
801
  ] }); }
801
802
  }
802
803
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
@@ -870,6 +871,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
870
871
  },
871
872
  deps: ['HasuraConfig'],
872
873
  },
874
+ {
875
+ provide: 'ProductStockNotificationRepository',
876
+ useExisting: ProductStockNotificationHasuraGraphQLRepository,
877
+ },
878
+ {
879
+ provide: ProductStockNotificationHasuraGraphQLRepository,
880
+ useFactory: (hasuraConfig) => {
881
+ return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
882
+ },
883
+ deps: ['HasuraConfig'],
884
+ },
873
885
  {
874
886
  provide: 'CategoryFilterRepository',
875
887
  useExisting: CategoryFilterHasuraGraphQLRepository,
@@ -923,10 +935,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
923
935
  provide: 'WishlistRepository',
924
936
  useExisting: WishlistHasuraGraphQLRepository,
925
937
  },
938
+ {
939
+ provide: 'OrderBlockedRepository',
940
+ useExisting: OrderBlockedFirestoreRepository,
941
+ },
926
942
  ],
927
943
  }]
928
944
  }] });
929
945
 
946
+ const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
947
+
948
+ class CookieDataPersistence {
949
+ get(key) {
950
+ return of(cookie.get(key));
951
+ }
952
+ remove(key) {
953
+ return of(cookie.remove(key));
954
+ }
955
+ set(key, value) {
956
+ return from(cookie.set(key, value)).pipe(map(() => { }));
957
+ }
958
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
959
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence }); }
960
+ }
961
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, decorators: [{
962
+ type: Injectable
963
+ }] });
964
+
930
965
  class AuthService {
931
966
  constructor(angularFireAuth, userRepository) {
932
967
  this.angularFireAuth = angularFireAuth;
@@ -1033,32 +1068,33 @@ class CouponService {
1033
1068
  return of(discount);
1034
1069
  }
1035
1070
  async calcDiscountShopping(coupon, checkout) {
1036
- let discount = 0;
1071
+ let discountInfo = null;
1037
1072
  if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
1038
- discount = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1073
+ discountInfo = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1039
1074
  }
1040
1075
  else {
1041
- discount = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1076
+ discountInfo = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1042
1077
  }
1043
- return discount;
1078
+ return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
1044
1079
  }
1045
1080
  async calcDiscountByType(type, value, categories, checkout) {
1046
1081
  let discount = 0;
1047
- let lineItensDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1048
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
1082
+ let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1083
+ const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
1049
1084
  if (type == CouponTypes.ABSOLUTE) {
1050
1085
  discount = value > subTotal ? subTotal : value;
1051
1086
  }
1052
1087
  else {
1053
1088
  discount = subTotal * (value / 100);
1054
1089
  }
1055
- return discount;
1090
+ const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1091
+ return { discount, lineItems };
1056
1092
  }
1057
1093
  async hasMinSubTotal(coupon, checkout) {
1058
1094
  if (!coupon.minSubTotalValue)
1059
1095
  return true;
1060
1096
  let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1061
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
1097
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
1062
1098
  if (coupon.minSubTotalValue <= subTotal)
1063
1099
  return true;
1064
1100
  return false;
@@ -1126,7 +1162,7 @@ class CouponService {
1126
1162
  }
1127
1163
  return lineItensDiscount;
1128
1164
  }
1129
- calcCheckoutSubtotal(lineItens, user, shop) {
1165
+ calcCheckoutSubtotal(lineItens, user) {
1130
1166
  return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1131
1167
  ? acc + curr.price?.subscriberPrice * curr.quantity
1132
1168
  : acc + curr.pricePaid * curr.quantity, 0) || 0);
@@ -1164,6 +1200,30 @@ class CouponService {
1164
1200
  }
1165
1201
  return couponUseLimits;
1166
1202
  }
1203
+ calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
1204
+ let lineItemsDiscount = [];
1205
+ if (type === CouponTypes.ABSOLUTE) {
1206
+ const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
1207
+ lineItemsDiscount = lineItems.map((item) => {
1208
+ const totalItemPercentage = item.pricePaid / subTotal;
1209
+ const discountItem = couponDiscountMax * totalItemPercentage;
1210
+ return {
1211
+ ...item,
1212
+ discount: Number(discountItem.toFixed(2)),
1213
+ };
1214
+ });
1215
+ }
1216
+ else {
1217
+ lineItemsDiscount = lineItems.map((item) => {
1218
+ const discountItem = item.pricePaid * (couponDiscount / 100);
1219
+ return {
1220
+ ...item,
1221
+ discount: Number(discountItem.toFixed(2)),
1222
+ };
1223
+ });
1224
+ }
1225
+ return lineItemsDiscount;
1226
+ }
1167
1227
  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
1228
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
1169
1229
  }
@@ -1187,18 +1247,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1187
1247
  }] }] });
1188
1248
 
1189
1249
  class CheckoutService {
1190
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
1250
+ constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1191
1251
  this.couponService = couponService;
1192
1252
  this.checkoutRepository = checkoutRepository;
1193
- this.orderRepository = orderRepository;
1194
1253
  this.userRepository = userRepository;
1195
1254
  this.defaultShop = defaultShop;
1255
+ this.dataPersistence = dataPersistence;
1196
1256
  }
1197
1257
  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));
1258
+ return this.dataPersistence
1259
+ .get('checkoutId')
1260
+ .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
1202
1261
  }
1203
1262
  getUserByCheckout(checkoutId) {
1204
1263
  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 +1269,7 @@ class CheckoutService {
1210
1269
  return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1211
1270
  }
1212
1271
  clearCheckoutFromSession() {
1213
- cookie.remove('checkoutId');
1214
- return of();
1272
+ return this.dataPersistence.remove('checkoutId');
1215
1273
  }
1216
1274
  calcDiscount(coupon) {
1217
1275
  return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
@@ -1225,10 +1283,10 @@ class CheckoutService {
1225
1283
  ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1226
1284
  shop: checkoutData?.shop || this.defaultShop,
1227
1285
  });
1228
- cookie.set('checkoutId', checkout.id);
1286
+ await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1229
1287
  return checkout;
1230
1288
  }
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 }); }
1289
+ 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
1290
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService }); }
1233
1291
  }
1234
1292
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, decorators: [{
@@ -1236,15 +1294,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1236
1294
  }], ctorParameters: () => [{ type: CouponService }, { type: undefined, decorators: [{
1237
1295
  type: Inject,
1238
1296
  args: ['CheckoutRepository']
1239
- }] }, { type: undefined, decorators: [{
1240
- type: Inject,
1241
- args: ['OrderRepository']
1242
1297
  }] }, { type: undefined, decorators: [{
1243
1298
  type: Inject,
1244
1299
  args: ['UserRepository']
1245
1300
  }] }, { type: i1$2.Shops, decorators: [{
1246
1301
  type: Inject,
1247
1302
  args: [DEFAULT_SHOP]
1303
+ }] }, { type: undefined, decorators: [{
1304
+ type: Inject,
1305
+ args: [PERSISTENCE_PROVIDER]
1248
1306
  }] }] });
1249
1307
 
1250
1308
  class CartService {
@@ -1280,8 +1338,8 @@ class CartService {
1280
1338
  this.buildLineItem = async ({ checkout, item, quantity, }) => {
1281
1339
  const product = await this.getProductData(item.id);
1282
1340
  item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
1283
- if (this.checkMaxStock(item, quantity || 0))
1284
- throw new Error('Desculpe! Temos apenas ' + item.stock?.quantity + ' em estoque.');
1341
+ if (this.checkMaxStock(product.stock.quantity, item.quantity || 0, quantity || 0))
1342
+ throw new Error('Desculpe! Temos apenas ' + product.stock?.quantity + ' em estoque.');
1285
1343
  const image = item.image || item.images?.shift();
1286
1344
  const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
1287
1345
  const isGift = item.isGift || null;
@@ -1306,6 +1364,7 @@ class CartService {
1306
1364
  weight: weight ?? product.weight,
1307
1365
  quantity: (item.quantity || 0) + (quantity || 0),
1308
1366
  pricePaid,
1367
+ discount: 0,
1309
1368
  categories: product.categories ?? [],
1310
1369
  isGift: isGift ?? null,
1311
1370
  costPrice: product.costPrice ?? 0,
@@ -1321,10 +1380,10 @@ class CartService {
1321
1380
  ? Number(info.subscriberPrice.toFixed(2))
1322
1381
  : Number(info.price.toFixed(2));
1323
1382
  };
1324
- this.checkMaxStock = (item, quantity) => {
1325
- const maxStock = item.stock?.quantity || 0;
1326
- const currentItemAmount = item.quantity || 0;
1327
- return currentItemAmount + quantity > maxStock;
1383
+ this.checkMaxStock = (currentStock, currentItemQtd, quantityToAdd) => {
1384
+ const maxStock = currentStock || 0;
1385
+ const currentItemAmount = currentItemQtd || 0;
1386
+ return currentItemAmount + quantityToAdd > maxStock;
1328
1387
  };
1329
1388
  }
1330
1389
  addItem(item, quantity = 1) {
@@ -1357,7 +1416,7 @@ class CartService {
1357
1416
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1358
1417
  }
1359
1418
  updateUserCart(user) {
1360
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => this.checkoutService
1419
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1361
1420
  .updateCheckoutLineItems(Checkout.toInstance({
1362
1421
  ...checkout.toPlain(),
1363
1422
  lineItems: checkout.lineItems?.length
@@ -1541,9 +1600,11 @@ class NewCategoryStructureAdapter {
1541
1600
  .then((categories) => categories.map((category) => category.id.toString()));
1542
1601
  }
1543
1602
  async getCategory(category) {
1544
- return isNil(category.isCollection) || (category.isCollection && !category.products?.length)
1545
- ? this.categoryRepository.get({ id: category.id })
1546
- : category;
1603
+ const collectionCategory = category.isCollection ||
1604
+ (isNil(category.isCollection) && !category.products?.length) ||
1605
+ category.isWishlist ||
1606
+ category.brandCategory;
1607
+ return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1547
1608
  }
1548
1609
  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
1610
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter }); }
@@ -1576,8 +1637,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1576
1637
  }] }] });
1577
1638
 
1578
1639
  class CatalogService {
1579
- constructor(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1640
+ constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1580
1641
  this.productRepository = productRepository;
1642
+ this.productStockNotificationRepository = productStockNotificationRepository;
1581
1643
  this.categoryRepository = categoryRepository;
1582
1644
  this.categoryStructureAdapter = categoryStructureAdapter;
1583
1645
  this.shop = shop;
@@ -1608,17 +1670,22 @@ class CatalogService {
1608
1670
  if (!sort || sort === 'most-relevant')
1609
1671
  return {};
1610
1672
  if (sort === 'best-sellers')
1611
- return { shoppingCount: 'desc' };
1673
+ return {
1674
+ shoppingCount: 'desc',
1675
+ rate: 'desc',
1676
+ stock: 'desc',
1677
+ name: 'asc',
1678
+ };
1612
1679
  if (sort === 'biggest-price')
1613
- return { subscriberPrice: 'desc' };
1680
+ return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1614
1681
  if (sort === 'lowest-price')
1615
- return { subscriberPrice: 'asc' };
1682
+ return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1616
1683
  if (sort === 'best-rating')
1617
- return { rate: 'desc' };
1684
+ return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1618
1685
  if (sort === 'news')
1619
1686
  return { createdAt: 'desc' };
1620
1687
  if (sort === 'biggest-discount')
1621
- return { subscriberDiscountPercentage: 'desc' };
1688
+ return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1622
1689
  };
1623
1690
  this.buildLimitQuery = (options) => {
1624
1691
  const limit = options?.perPage || 20;
@@ -1652,16 +1719,26 @@ class CatalogService {
1652
1719
  brands: distinct?.brand,
1653
1720
  }));
1654
1721
  }
1722
+ async addCustomerToStockNotification(shop, productId, name, email) {
1723
+ return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1724
+ }
1655
1725
  async findCatalog(options, limits) {
1656
1726
  if (this.hasTerm(options) && options.sort === 'most-relevant') {
1657
1727
  const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
1658
- return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1728
+ return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1659
1729
  }
1660
1730
  if (this.hasCategory(options) && options.sort === 'most-relevant') {
1661
- const productsIds = options.category.products?.length
1662
- ? options.category.products
1663
- : await this.categoryRepository.get({ id: options.category.id }).then((categoryFound) => categoryFound.products);
1664
- return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1731
+ const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
1732
+ const productsIds = await this.productRepository
1733
+ .findCatalog({
1734
+ fields: ['id'],
1735
+ filters: {
1736
+ ...(await this.buildMainFilter(options)),
1737
+ ...this.buildFilterQuery(options?.filters || {}),
1738
+ },
1739
+ })
1740
+ .then((products) => products.data.map((product) => product.id));
1741
+ return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1665
1742
  }
1666
1743
  const repoParams = {
1667
1744
  filters: {
@@ -1690,7 +1767,33 @@ class CatalogService {
1690
1767
  .search(term, 999, this.shop)
1691
1768
  .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1692
1769
  }
1693
- async findCatalogAndSortByMostRevelant(productIds, options, limits) {
1770
+ async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1771
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1772
+ const totalResult = await this.productRepository.findCatalog({
1773
+ filters: {
1774
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
1775
+ ...this.buildFilterQuery(options?.filters || {}),
1776
+ },
1777
+ orderBy: this.buildSortQuery('news'),
1778
+ options: {
1779
+ minimal: ['price'],
1780
+ maximum: ['price'],
1781
+ distinct: ['brand'],
1782
+ },
1783
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1784
+ const firstProducts = totalResult.data.filter((product) => mostRelevants.includes(product.id));
1785
+ const lastProducts = totalResult.data.filter((product) => !mostRelevants.includes(product.id));
1786
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
1787
+ const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1788
+ return {
1789
+ data: resultFinal,
1790
+ count: totalResult.count,
1791
+ maximum: totalResult.maximum,
1792
+ minimal: totalResult.minimal,
1793
+ distinct: totalResult.distinct,
1794
+ };
1795
+ }
1796
+ async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1694
1797
  const totalResult = await this.productRepository.findCatalog({
1695
1798
  fields: ['id', 'stock'],
1696
1799
  filters: {
@@ -1736,7 +1839,7 @@ class CatalogService {
1736
1839
  return [...new Set(sorted.map(({ _source }) => _source.id))];
1737
1840
  }));
1738
1841
  }
1739
- 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 }); }
1842
+ 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 }); }
1740
1843
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
1741
1844
  }
1742
1845
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, decorators: [{
@@ -1744,6 +1847,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1744
1847
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1745
1848
  type: Inject,
1746
1849
  args: ['ProductRepository']
1850
+ }] }, { type: undefined, decorators: [{
1851
+ type: Inject,
1852
+ args: ['ProductStockNotificationRepository']
1747
1853
  }] }, { type: undefined, decorators: [{
1748
1854
  type: Inject,
1749
1855
  args: ['CategoryRepository']
@@ -1763,15 +1869,15 @@ class CategoryService {
1763
1869
  this.categoryStructureAdapter = categoryStructureAdapter;
1764
1870
  this.shop = shop;
1765
1871
  }
1766
- async fetchBrands(category, mainGender) {
1872
+ async fetchBrands(category, options) {
1767
1873
  const brands = await this.productRepository
1768
1874
  .findCatalog({
1769
1875
  filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1770
1876
  fields: ['brand'],
1771
- }, mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1877
+ }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1772
1878
  .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1773
1879
  return this.categoryRepository
1774
- .find({ filters: { brandCategory: true, shop: this.shop }, orderBy: { name: 'asc' } })
1880
+ .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } })
1775
1881
  .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1776
1882
  }
1777
1883
  async fetchFilterOptions(category) {
@@ -1820,11 +1926,11 @@ __decorate([
1820
1926
  ], CategoryWithTree.prototype, "children", void 0);
1821
1927
 
1822
1928
  class WishlistService {
1823
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productIndex) {
1929
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productIndex) {
1824
1930
  this.wishlistRepository = wishlistRepository;
1825
1931
  this.shop = shop;
1826
1932
  const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1827
- this.catalogService = new CatalogService(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1933
+ this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1828
1934
  this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1829
1935
  }
1830
1936
  getCatalogService() {
@@ -1833,42 +1939,53 @@ class WishlistService {
1833
1939
  getCategoryService() {
1834
1940
  return this.categoryService;
1835
1941
  }
1836
- async create({ personId, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
1942
+ async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1837
1943
  const data = {
1838
1944
  slug: '',
1839
1945
  name: title,
1840
1946
  description,
1841
- metadata: {
1842
- title: `${userFullName} - ${title}`,
1843
- description: `${userFullName} - ${description}`,
1844
- },
1947
+ metadatas: [
1948
+ {
1949
+ shop: this.shop,
1950
+ title: `${userFullName} - ${title}`,
1951
+ description: `${userFullName} - ${description}`,
1952
+ },
1953
+ ],
1845
1954
  shop: this.shop,
1846
1955
  shops: [this.shop],
1847
1956
  personId,
1848
1957
  personName: userFullName,
1849
1958
  personPhoto: userPhoto,
1850
1959
  brandCategory: false,
1851
- published: true,
1960
+ published,
1852
1961
  theme,
1853
1962
  bannerUrl,
1963
+ personType: personType ?? PersonTypes.NONE,
1964
+ personIsSubscriber: personIsSubscriber ?? false,
1854
1965
  };
1855
1966
  const newWishlist = await this.wishlistRepository.create(data);
1856
1967
  await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
1857
1968
  return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
1858
1969
  }
1859
- update({ id, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
1970
+ update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1860
1971
  const data = {
1861
1972
  id,
1862
1973
  name: title,
1863
1974
  description,
1864
- metadata: {
1865
- title: `${userFullName} - ${title}`,
1866
- description: `${userFullName} - ${description}`,
1867
- },
1975
+ published,
1976
+ metadatas: [
1977
+ {
1978
+ shop: this.shop,
1979
+ title: `${userFullName} - ${title}`,
1980
+ description: `${userFullName} - ${description}`,
1981
+ },
1982
+ ],
1868
1983
  personName: userFullName,
1869
1984
  personPhoto: userPhoto,
1870
1985
  theme,
1871
1986
  bannerUrl,
1987
+ personType: personType ?? PersonTypes.NONE,
1988
+ personIsSubscriber: personIsSubscriber ?? false,
1872
1989
  };
1873
1990
  return this.wishlistRepository.update(data);
1874
1991
  }
@@ -1904,7 +2021,7 @@ class WishlistService {
1904
2021
  }
1905
2022
  return wishlist;
1906
2023
  }
1907
- 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 }); }
2024
+ 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 }); }
1908
2025
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService }); }
1909
2026
  }
1910
2027
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, decorators: [{
@@ -1924,31 +2041,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1924
2041
  }] }, { type: undefined, decorators: [{
1925
2042
  type: Inject,
1926
2043
  args: ['CategoryRepository']
2044
+ }] }, { type: undefined, decorators: [{
2045
+ type: Inject,
2046
+ args: ['ProductStockNotificationRepository']
1927
2047
  }] }, { type: i1$2.ProductsIndex }] });
1928
2048
 
1929
2049
  class CheckoutSubscriptionService {
1930
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
2050
+ constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
1931
2051
  this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1932
- this.subscriptionRepository = subscriptionRepository;
2052
+ this.dataPersistence = dataPersistence;
1933
2053
  this.couponService = couponService;
1934
2054
  }
1935
2055
  getCheckoutSubscription(checkoutData) {
1936
- const checkoutId = cookie.get('checkoutSubscriptionId');
1937
- if (!isNil(checkoutId))
1938
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
1939
- return from(this.createCheckoutSubscription(checkoutData));
1940
- }
1941
- async createCheckoutSubscription(checkoutData) {
1942
- const checkout = await this.checkoutSubscriptionRepository.create({
1943
- createdAt: new Date(),
1944
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1945
- });
1946
- cookie.set('checkoutSubscriptionId', checkout.id);
1947
- return checkout;
2056
+ return this.dataPersistence
2057
+ .get('checkoutSubscriptionId')
2058
+ .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData)));
1948
2059
  }
1949
2060
  clearCheckoutSubscriptionFromSession() {
1950
- cookie.remove('checkoutSubscriptionId');
1951
- return of();
2061
+ return this.dataPersistence.remove('checkoutSubscriptionId');
1952
2062
  }
1953
2063
  checkCoupon(nickname, userEmail) {
1954
2064
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
@@ -1958,7 +2068,15 @@ class CheckoutSubscriptionService {
1958
2068
  calcDiscountSubscription(coupon) {
1959
2069
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1960
2070
  }
1961
- 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 }); }
2071
+ async createCheckoutSubscription(checkoutData) {
2072
+ const checkout = await this.checkoutSubscriptionRepository.create({
2073
+ createdAt: new Date(),
2074
+ ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
2075
+ });
2076
+ await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2077
+ return checkout;
2078
+ }
2079
+ 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 }); }
1962
2080
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
1963
2081
  }
1964
2082
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
@@ -1968,7 +2086,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1968
2086
  args: ['CheckoutSubscriptionRepository']
1969
2087
  }] }, { type: undefined, decorators: [{
1970
2088
  type: Inject,
1971
- args: ['SubscriptionRepository']
2089
+ args: [PERSISTENCE_PROVIDER]
1972
2090
  }] }, { type: CouponService }] });
1973
2091
 
1974
2092
  class UtilHelper {
@@ -2226,6 +2344,7 @@ class AngularConnectModule {
2226
2344
  ? OldCategoryStructureAdapter
2227
2345
  : NewCategoryStructureAdapter,
2228
2346
  },
2347
+ { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2229
2348
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2230
2349
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2231
2350
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
@@ -2237,7 +2356,7 @@ class AngularConnectModule {
2237
2356
  };
2238
2357
  }
2239
2358
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
2240
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, AngularElasticSeachModule,
2359
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
2241
2360
  AngularFirebaseAuthModule,
2242
2361
  AngularFirestoreModule,
2243
2362
  AngularHasuraGraphQLModule] }); }
@@ -2260,6 +2379,13 @@ class AngularConnectModule {
2260
2379
  },
2261
2380
  deps: ['UserRepository', 'FileUploaderService'],
2262
2381
  },
2382
+ {
2383
+ provide: 'FileUploaderService',
2384
+ useFactory: (storage, baseUrl) => {
2385
+ return new FirebaseFileUploaderService(storage, baseUrl);
2386
+ },
2387
+ deps: [Storage, STORAGE_BASE_URL],
2388
+ },
2263
2389
  ], imports: [provideFirebaseApp((injector) => {
2264
2390
  const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2265
2391
  try {
@@ -2269,6 +2395,7 @@ class AngularConnectModule {
2269
2395
  return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2270
2396
  }
2271
2397
  }),
2398
+ provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2272
2399
  AngularElasticSeachModule,
2273
2400
  AngularFirebaseAuthModule,
2274
2401
  AngularFirestoreModule,
@@ -2287,6 +2414,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2287
2414
  return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2288
2415
  }
2289
2416
  }),
2417
+ provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2290
2418
  AngularElasticSeachModule,
2291
2419
  AngularFirebaseAuthModule,
2292
2420
  AngularFirestoreModule,
@@ -2311,6 +2439,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2311
2439
  },
2312
2440
  deps: ['UserRepository', 'FileUploaderService'],
2313
2441
  },
2442
+ {
2443
+ provide: 'FileUploaderService',
2444
+ useFactory: (storage, baseUrl) => {
2445
+ return new FirebaseFileUploaderService(storage, baseUrl);
2446
+ },
2447
+ deps: [Storage, STORAGE_BASE_URL],
2448
+ },
2314
2449
  ],
2315
2450
  }]
2316
2451
  }] });
@@ -2319,5 +2454,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2319
2454
  * Generated bundle index. Do not edit.
2320
2455
  */
2321
2456
 
2322
- export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2457
+ export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2323
2458
  //# sourceMappingURL=infrab4a-connect-angular.mjs.map