@infrab4a/connect-angular 5.0.0-beta.59 → 5.0.0-beta.6

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 (70) hide show
  1. package/angular-connect.module.d.ts +8 -13
  2. package/angular-firestore.module.d.ts +2 -1
  3. package/consts/index.d.ts +0 -2
  4. package/esm2022/angular-connect.module.mjs +5 -38
  5. package/esm2022/angular-elastic-search.module.mjs +1 -1
  6. package/esm2022/angular-firebase-auth.module.mjs +1 -1
  7. package/esm2022/angular-firestore.module.mjs +28 -25
  8. package/esm2022/angular-hasura-graphql.module.mjs +2 -24
  9. package/esm2022/consts/category-structure.mjs +1 -1
  10. package/esm2022/consts/default-shop.const.mjs +1 -1
  11. package/esm2022/consts/es-config.const.mjs +1 -1
  12. package/esm2022/consts/firebase-const.mjs +1 -1
  13. package/esm2022/consts/hasura-options.const.mjs +1 -1
  14. package/esm2022/consts/index.mjs +1 -3
  15. package/esm2022/consts/storage-base-url.const.mjs +1 -1
  16. package/esm2022/helpers/index.mjs +1 -1
  17. package/esm2022/helpers/mobile-operation-system-checker.helper.mjs +1 -1
  18. package/esm2022/index.mjs +1 -2
  19. package/esm2022/services/auth.service.mjs +1 -1
  20. package/esm2022/services/cart.service.mjs +11 -14
  21. package/esm2022/services/catalog/adapters/category-structure.adapter.mjs +1 -1
  22. package/esm2022/services/catalog/adapters/index.mjs +1 -1
  23. package/esm2022/services/catalog/adapters/new-category-structure.adapter.mjs +4 -6
  24. package/esm2022/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
  25. package/esm2022/services/catalog/catalog.service.mjs +33 -89
  26. package/esm2022/services/catalog/category.service.mjs +1 -1
  27. package/esm2022/services/catalog/enums/index.mjs +1 -1
  28. package/esm2022/services/catalog/enums/product-sorts.enum.mjs +1 -1
  29. package/esm2022/services/catalog/index.mjs +1 -1
  30. package/esm2022/services/catalog/models/category-with-tree.model.mjs +1 -1
  31. package/esm2022/services/catalog/models/index.mjs +1 -1
  32. package/esm2022/services/catalog/types/index.mjs +1 -1
  33. package/esm2022/services/catalog/types/product-sort.type.mjs +1 -1
  34. package/esm2022/services/catalog/wishlist.service.mjs +17 -50
  35. package/esm2022/services/checkout-subscription.service.mjs +21 -18
  36. package/esm2022/services/checkout.service.mjs +16 -13
  37. package/esm2022/services/coupon.service.mjs +19 -54
  38. package/esm2022/services/helpers/index.mjs +1 -1
  39. package/esm2022/services/helpers/util.helper.mjs +1 -1
  40. package/esm2022/services/home-shop.service.mjs +1 -1
  41. package/esm2022/services/index.mjs +1 -1
  42. package/esm2022/services/order.service.mjs +1 -1
  43. package/esm2022/services/shipping.service.mjs +1 -1
  44. package/esm2022/services/types/index.mjs +1 -1
  45. package/esm2022/services/types/required-checkout-data.type.mjs +1 -1
  46. package/esm2022/services/types/required-checkout-subscription-data.type.mjs +1 -1
  47. package/esm2022/services/types/shipping-methods.type.mjs +1 -1
  48. package/esm2022/types/firebase-app-config.type.mjs +1 -1
  49. package/esm2022/types/index.mjs +1 -1
  50. package/fesm2022/infrab4a-connect-angular.mjs +139 -366
  51. package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
  52. package/index.d.ts +0 -1
  53. package/package.json +5 -5
  54. package/services/catalog/catalog.service.d.ts +4 -7
  55. package/services/catalog/wishlist.service.d.ts +4 -11
  56. package/services/checkout-subscription.service.d.ts +4 -5
  57. package/services/checkout.service.d.ts +4 -8
  58. package/services/coupon.service.d.ts +2 -6
  59. package/angular-vertex-search.module.d.ts +0 -9
  60. package/consts/persistence.const.d.ts +0 -1
  61. package/consts/vertex-config.const.d.ts +0 -1
  62. package/esm2022/angular-vertex-search.module.mjs +0 -34
  63. package/esm2022/consts/persistence.const.mjs +0 -2
  64. package/esm2022/consts/vertex-config.const.mjs +0 -2
  65. package/esm2022/persistence/cookie-data-persistence.mjs +0 -22
  66. package/esm2022/persistence/data-persistence.mjs +0 -2
  67. package/esm2022/persistence/index.mjs +0 -3
  68. package/persistence/cookie-data-persistence.d.ts +0 -10
  69. package/persistence/data-persistence.d.ts +0 -6
  70. package/persistence/index.d.ts +0 -2
@@ -2,18 +2,18 @@ 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
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';
7
5
  import * as i1$2 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, OrderBlockedFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, PersonTypes, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } 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';
9
7
  import * as i1 from '@angular/fire/auth';
10
8
  import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
11
9
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
12
10
  import * as i1$1 from '@angular/fire/firestore';
13
- import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
14
- import cookie from 'js-cookie';
15
- import { of, from, combineLatest, throwError, Subject, iif, forkJoin } from 'rxjs';
11
+ import { Firestore, provideFirestore, getFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
12
+ import * as i2 from '@angular/fire/storage';
13
+ import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
14
+ import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
16
15
  import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
16
+ import cookie from 'js-cookie';
17
17
  import { __decorate, __metadata } from 'tslib';
18
18
  import { Type } from 'class-transformer';
19
19
  import * as i1$3 from '@angular/common/http';
@@ -61,10 +61,6 @@ const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
61
61
 
62
62
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
63
63
 
64
- const PERSISTENCE_PROVIDER = 'PERSISTENCE_PROVIDER';
65
-
66
- const VERTEX_CONFIG = 'VERTEX_CONFIG';
67
-
68
64
  class AngularFirebaseAuthModule {
69
65
  static initializeApp(options, nameOrConfig) {
70
66
  return {
@@ -173,6 +169,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
173
169
  }]
174
170
  }] });
175
171
 
172
+ const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
173
+
176
174
  class MobileOperationSystemCheckerHelper {
177
175
  static isAppleDevice() {
178
176
  return (['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator?.platform) ||
@@ -192,12 +190,12 @@ class AngularFirestoreModule {
192
190
  };
193
191
  }
194
192
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
195
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, imports: [AngularElasticSeachModule, i1$1.FirestoreModule] }); }
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] }); }
196
194
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, providers: [
197
195
  {
198
196
  provide: 'FirestoreOptions',
199
197
  useFactory: (firestore, platformId) => ({
200
- firestore: new ConnectFirestoreService(firestore),
198
+ firestore,
201
199
  interceptors: {
202
200
  request: (request) => {
203
201
  if (isPlatformBrowser(platformId))
@@ -406,26 +404,26 @@ class AngularFirestoreModule {
406
404
  deps: ['FirestoreOptions', ProductFirestoreRepository],
407
405
  },
408
406
  {
409
- provide: 'OrderBlockedRepository',
410
- useFactory: (options) => {
411
- return new OrderBlockedFirestoreRepository(options);
407
+ provide: 'FileUploaderService',
408
+ useFactory: (storage, baseUrl) => {
409
+ return new FirebaseFileUploaderService(storage, baseUrl);
412
410
  },
413
- deps: ['FirestoreOptions'],
411
+ deps: [Storage, STORAGE_BASE_URL],
414
412
  },
415
413
  ], imports: [AngularElasticSeachModule,
416
414
  provideFirestore((injector) => {
417
415
  const platformId = injector.get(PLATFORM_ID);
418
- if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
419
- return initializeFirestore(injector.get(FirebaseApp), {
420
- ignoreUndefinedProperties: true,
421
- });
416
+ if (isPlatformServer(platformId))
417
+ return getFirestore(injector.get(FirebaseApp));
418
+ if (!MobileOperationSystemCheckerHelper.isAppleDevice())
419
+ return getFirestore(injector.get(FirebaseApp));
422
420
  const firestore = initializeFirestore(injector.get(FirebaseApp), {
423
421
  experimentalForceLongPolling: true,
424
- ignoreUndefinedProperties: true,
425
422
  localCache: memoryLocalCache(),
426
423
  });
427
424
  return firestore;
428
- })] }); }
425
+ }),
426
+ provideStorage(() => getStorage())] }); }
429
427
  }
430
428
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularFirestoreModule, decorators: [{
431
429
  type: NgModule,
@@ -434,23 +432,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
434
432
  AngularElasticSeachModule,
435
433
  provideFirestore((injector) => {
436
434
  const platformId = injector.get(PLATFORM_ID);
437
- if (isPlatformServer(platformId) || !MobileOperationSystemCheckerHelper.isAppleDevice())
438
- return initializeFirestore(injector.get(FirebaseApp), {
439
- ignoreUndefinedProperties: true,
440
- });
435
+ if (isPlatformServer(platformId))
436
+ return getFirestore(injector.get(FirebaseApp));
437
+ if (!MobileOperationSystemCheckerHelper.isAppleDevice())
438
+ return getFirestore(injector.get(FirebaseApp));
441
439
  const firestore = initializeFirestore(injector.get(FirebaseApp), {
442
440
  experimentalForceLongPolling: true,
443
- ignoreUndefinedProperties: true,
444
441
  localCache: memoryLocalCache(),
445
442
  });
446
443
  return firestore;
447
444
  }),
445
+ provideStorage(() => getStorage()),
448
446
  ],
449
447
  providers: [
450
448
  {
451
449
  provide: 'FirestoreOptions',
452
450
  useFactory: (firestore, platformId) => ({
453
- firestore: new ConnectFirestoreService(firestore),
451
+ firestore,
454
452
  interceptors: {
455
453
  request: (request) => {
456
454
  if (isPlatformBrowser(platformId))
@@ -659,11 +657,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
659
657
  deps: ['FirestoreOptions', ProductFirestoreRepository],
660
658
  },
661
659
  {
662
- provide: 'OrderBlockedRepository',
663
- useFactory: (options) => {
664
- return new OrderBlockedFirestoreRepository(options);
660
+ provide: 'FileUploaderService',
661
+ useFactory: (storage, baseUrl) => {
662
+ return new FirebaseFileUploaderService(storage, baseUrl);
665
663
  },
666
- deps: ['FirestoreOptions'],
664
+ deps: [Storage, STORAGE_BASE_URL],
667
665
  },
668
666
  ],
669
667
  }]
@@ -746,17 +744,6 @@ class AngularHasuraGraphQLModule {
746
744
  },
747
745
  deps: ['HasuraConfig'],
748
746
  },
749
- {
750
- provide: 'ProductStockNotificationRepository',
751
- useExisting: ProductStockNotificationHasuraGraphQLRepository,
752
- },
753
- {
754
- provide: ProductStockNotificationHasuraGraphQLRepository,
755
- useFactory: (hasuraConfig) => {
756
- return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
757
- },
758
- deps: ['HasuraConfig'],
759
- },
760
747
  {
761
748
  provide: 'CategoryFilterRepository',
762
749
  useExisting: CategoryFilterHasuraGraphQLRepository,
@@ -883,17 +870,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
883
870
  },
884
871
  deps: ['HasuraConfig'],
885
872
  },
886
- {
887
- provide: 'ProductStockNotificationRepository',
888
- useExisting: ProductStockNotificationHasuraGraphQLRepository,
889
- },
890
- {
891
- provide: ProductStockNotificationHasuraGraphQLRepository,
892
- useFactory: (hasuraConfig) => {
893
- return new ProductStockNotificationHasuraGraphQLRepository(hasuraConfig);
894
- },
895
- deps: ['HasuraConfig'],
896
- },
897
873
  {
898
874
  provide: 'CategoryFilterRepository',
899
875
  useExisting: CategoryFilterHasuraGraphQLRepository,
@@ -951,55 +927,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
951
927
  }]
952
928
  }] });
953
929
 
954
- class AngularVertexSeachModule {
955
- static initializeApp(options) {
956
- return {
957
- ngModule: AngularVertexSeachModule,
958
- providers: [{ provide: VERTEX_CONFIG, useValue: options }],
959
- };
960
- }
961
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
962
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule }); }
963
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, providers: [
964
- {
965
- provide: ProductsVertexSearch,
966
- useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
967
- deps: [VERTEX_CONFIG],
968
- },
969
- ] }); }
970
- }
971
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularVertexSeachModule, decorators: [{
972
- type: NgModule,
973
- args: [{
974
- providers: [
975
- {
976
- provide: ProductsVertexSearch,
977
- useFactory: (configuration) => new ProductsVertexSearch(new VertexAxiosAdapter(configuration)),
978
- deps: [VERTEX_CONFIG],
979
- },
980
- ],
981
- }]
982
- }] });
983
-
984
- const STORAGE_BASE_URL = 'STORAGE_BASE_URL';
985
-
986
- class CookieDataPersistence {
987
- get(key) {
988
- return of(cookie.get(key));
989
- }
990
- remove(key) {
991
- return of(cookie.remove(key));
992
- }
993
- set(key, value) {
994
- return from(cookie.set(key, value)).pipe(map(() => { }));
995
- }
996
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
997
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence }); }
998
- }
999
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CookieDataPersistence, decorators: [{
1000
- type: Injectable
1001
- }] });
1002
-
1003
930
  class AuthService {
1004
931
  constructor(angularFireAuth, userRepository) {
1005
932
  this.angularFireAuth = angularFireAuth;
@@ -1080,11 +1007,11 @@ class CouponService {
1080
1007
  throw 'Limite de uso atingido';
1081
1008
  }
1082
1009
  if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
1083
- const ordersCoupon = await this.getOrdersWithCoupon(coupon);
1084
- if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
1010
+ const orders = await this.getOrdersWithCoupon(coupon);
1011
+ if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
1085
1012
  throw 'Limite de uso atingido.';
1086
1013
  if (couponUseLimits.limitedPerUser) {
1087
- const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
1014
+ const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
1088
1015
  if (ordersWithUser > 0)
1089
1016
  throw 'Limite de uso por usuário atingido.';
1090
1017
  }
@@ -1106,44 +1033,38 @@ class CouponService {
1106
1033
  return of(discount);
1107
1034
  }
1108
1035
  async calcDiscountShopping(coupon, checkout) {
1109
- let discountInfo = null;
1036
+ let discount = 0;
1110
1037
  if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
1111
- discountInfo = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1038
+ discount = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
1112
1039
  }
1113
1040
  else {
1114
- discountInfo = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1041
+ discount = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
1115
1042
  }
1116
- return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
1043
+ return discount;
1117
1044
  }
1118
1045
  async calcDiscountByType(type, value, categories, checkout) {
1119
1046
  let discount = 0;
1120
- if (type == CouponTypes.SHIPPING) {
1121
- const subTotal = checkout.shipping.ShippingPrice;
1122
- const discount = subTotal * ((value > 100 ? 100 : value) / 100);
1123
- return { discount, lineItems: checkout.lineItems };
1124
- }
1125
- let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1126
- const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
1047
+ let lineItensDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1048
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
1127
1049
  if (type == CouponTypes.ABSOLUTE) {
1128
1050
  discount = value > subTotal ? subTotal : value;
1129
1051
  }
1130
1052
  else {
1131
- discount = subTotal * ((value > 100 ? 100 : value) / 100);
1053
+ discount = subTotal * (value / 100);
1132
1054
  }
1133
- const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1134
- return { discount, lineItems };
1055
+ return discount;
1135
1056
  }
1136
1057
  async hasMinSubTotal(coupon, checkout) {
1137
1058
  if (!coupon.minSubTotalValue)
1138
1059
  return true;
1139
1060
  let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1140
- const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
1061
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
1141
1062
  if (coupon.minSubTotalValue <= subTotal)
1142
1063
  return true;
1143
1064
  return false;
1144
1065
  }
1145
1066
  async hasProductCategories(coupon, checkout) {
1146
- if (!coupon.productsCategories || !coupon.productsCategories?.length) {
1067
+ if (!coupon.productsCategories || !coupon.productsCategories.length) {
1147
1068
  return true;
1148
1069
  }
1149
1070
  const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
@@ -1205,7 +1126,7 @@ class CouponService {
1205
1126
  }
1206
1127
  return lineItensDiscount;
1207
1128
  }
1208
- calcCheckoutSubtotal(lineItens, user) {
1129
+ calcCheckoutSubtotal(lineItens, user, shop) {
1209
1130
  return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1210
1131
  ? acc + curr.price?.subscriberPrice * curr.quantity
1211
1132
  : acc + curr.pricePaid * curr.quantity, 0) || 0);
@@ -1215,7 +1136,7 @@ class CouponService {
1215
1136
  .find({
1216
1137
  filters: {
1217
1138
  coupon: { id: coupon.id },
1218
- status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
1139
+ payment: { status: 'paid' },
1219
1140
  },
1220
1141
  })
1221
1142
  .then((result) => result.data);
@@ -1225,7 +1146,7 @@ class CouponService {
1225
1146
  .find({
1226
1147
  filters: {
1227
1148
  user: { email: { operator: Where.EQUALS, value: email } },
1228
- status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
1149
+ payment: { status: 'paid' },
1229
1150
  },
1230
1151
  })
1231
1152
  .then((result) => result.data);
@@ -1236,42 +1157,13 @@ class CouponService {
1236
1157
  getCouponUseLimits(coupon, checkoutType, user) {
1237
1158
  let couponUseLimits;
1238
1159
  if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
1239
- if (coupon.exclusivityType.length === 1 &&
1240
- (coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
1241
- coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
1242
- couponUseLimits = coupon.useLimits.non_subscriber;
1243
- else
1244
- couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
1160
+ couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
1245
1161
  }
1246
1162
  else {
1247
1163
  couponUseLimits = coupon.useLimits.subscription;
1248
1164
  }
1249
1165
  return couponUseLimits;
1250
1166
  }
1251
- calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
1252
- let lineItemsDiscount = [];
1253
- if (type === CouponTypes.ABSOLUTE) {
1254
- const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
1255
- lineItemsDiscount = lineItems.map((item) => {
1256
- const totalItemPercentage = item.pricePaid / subTotal;
1257
- const discountItem = couponDiscountMax * totalItemPercentage;
1258
- return {
1259
- ...item,
1260
- discount: Number(discountItem.toFixed(2)),
1261
- };
1262
- });
1263
- }
1264
- else {
1265
- lineItemsDiscount = lineItems.map((item) => {
1266
- const discountItem = item.pricePaid * (couponDiscount / 100);
1267
- return {
1268
- ...item,
1269
- discount: Number(discountItem.toFixed(2)),
1270
- };
1271
- });
1272
- }
1273
- return lineItemsDiscount;
1274
- }
1275
1167
  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 }); }
1276
1168
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CouponService, providedIn: 'root' }); }
1277
1169
  }
@@ -1295,17 +1187,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1295
1187
  }] }] });
1296
1188
 
1297
1189
  class CheckoutService {
1298
- constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1190
+ constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
1299
1191
  this.couponService = couponService;
1300
1192
  this.checkoutRepository = checkoutRepository;
1193
+ this.orderRepository = orderRepository;
1301
1194
  this.userRepository = userRepository;
1302
1195
  this.defaultShop = defaultShop;
1303
- this.dataPersistence = dataPersistence;
1304
1196
  }
1305
1197
  getCheckout(checkoutData) {
1306
- return this.dataPersistence
1307
- .get('checkoutId')
1308
- .pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(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));
1309
1202
  }
1310
1203
  getUserByCheckout(checkoutId) {
1311
1204
  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'))));
@@ -1317,7 +1210,8 @@ class CheckoutService {
1317
1210
  return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1318
1211
  }
1319
1212
  clearCheckoutFromSession() {
1320
- return this.dataPersistence.remove('checkoutId');
1213
+ cookie.remove('checkoutId');
1214
+ return of();
1321
1215
  }
1322
1216
  calcDiscount(coupon) {
1323
1217
  return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
@@ -1331,10 +1225,10 @@ class CheckoutService {
1331
1225
  ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1332
1226
  shop: checkoutData?.shop || this.defaultShop,
1333
1227
  });
1334
- await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1228
+ cookie.set('checkoutId', checkout.id);
1335
1229
  return checkout;
1336
1230
  }
1337
- 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 }); }
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 }); }
1338
1232
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService }); }
1339
1233
  }
1340
1234
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutService, decorators: [{
@@ -1342,15 +1236,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1342
1236
  }], ctorParameters: () => [{ type: CouponService }, { type: undefined, decorators: [{
1343
1237
  type: Inject,
1344
1238
  args: ['CheckoutRepository']
1239
+ }] }, { type: undefined, decorators: [{
1240
+ type: Inject,
1241
+ args: ['OrderRepository']
1345
1242
  }] }, { type: undefined, decorators: [{
1346
1243
  type: Inject,
1347
1244
  args: ['UserRepository']
1348
1245
  }] }, { type: i1$2.Shops, decorators: [{
1349
1246
  type: Inject,
1350
1247
  args: [DEFAULT_SHOP]
1351
- }] }, { type: undefined, decorators: [{
1352
- type: Inject,
1353
- args: [PERSISTENCE_PROVIDER]
1354
1248
  }] }] });
1355
1249
 
1356
1250
  class CartService {
@@ -1369,7 +1263,6 @@ class CartService {
1369
1263
  if (index > -1) {
1370
1264
  checkoutLoaded.lineItems[index].quantity += quantity;
1371
1265
  checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
1372
- checkoutLoaded.lineItems[index].price = lineItem.price;
1373
1266
  }
1374
1267
  else
1375
1268
  checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
@@ -1387,18 +1280,17 @@ class CartService {
1387
1280
  this.buildLineItem = async ({ checkout, item, quantity, }) => {
1388
1281
  const product = await this.getProductData(item.id);
1389
1282
  item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
1390
- if (this.checkMaxStock(product.stock.quantity, item.quantity || 0, quantity || 0))
1391
- throw new Error('Desculpe! Temos apenas ' + product.stock?.quantity + ' em estoque.');
1283
+ if (this.checkMaxStock(item, quantity || 0))
1284
+ throw new Error('Desculpe! Temos apenas ' + item.stock?.quantity + ' em estoque.');
1392
1285
  const image = item.image || item.images?.shift();
1393
- const { id, name, EAN, slug, weight, sku, type } = item;
1286
+ const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
1394
1287
  const isGift = item.isGift || null;
1395
1288
  const pricePaid = this.getProductPrice({
1396
- product: LineItem.toInstance(product),
1289
+ product: item,
1397
1290
  shop: checkout.shop || this.defaultShop,
1398
1291
  isSubscriber: checkout.user?.isSubscriber,
1399
1292
  });
1400
1293
  RoundProductPricesHelper.roundProductPrices(item);
1401
- RoundProductPricesHelper.roundProductPrices(product);
1402
1294
  return {
1403
1295
  checkout,
1404
1296
  lineItem: LineItem.toInstance({
@@ -1408,13 +1300,12 @@ class CartService {
1408
1300
  brand: product.brand,
1409
1301
  slug: slug ?? product.slug,
1410
1302
  sku: sku ?? product.sku,
1411
- stock: product.stock,
1412
- price: this.roundPrice(product.price),
1303
+ stock,
1304
+ price: this.roundPrice(price),
1413
1305
  image,
1414
1306
  weight: weight ?? product.weight,
1415
1307
  quantity: (item.quantity || 0) + (quantity || 0),
1416
1308
  pricePaid,
1417
- discount: 0,
1418
1309
  categories: product.categories ?? [],
1419
1310
  isGift: isGift ?? null,
1420
1311
  costPrice: product.costPrice ?? 0,
@@ -1430,10 +1321,10 @@ class CartService {
1430
1321
  ? Number(info.subscriberPrice.toFixed(2))
1431
1322
  : Number(info.price.toFixed(2));
1432
1323
  };
1433
- this.checkMaxStock = (currentStock, currentItemQtd, quantityToAdd) => {
1434
- const maxStock = currentStock || 0;
1435
- const currentItemAmount = currentItemQtd || 0;
1436
- return currentItemAmount + quantityToAdd > maxStock;
1324
+ this.checkMaxStock = (item, quantity) => {
1325
+ const maxStock = item.stock?.quantity || 0;
1326
+ const currentItemAmount = item.quantity || 0;
1327
+ return currentItemAmount + quantity > maxStock;
1437
1328
  };
1438
1329
  }
1439
1330
  addItem(item, quantity = 1) {
@@ -1650,11 +1541,9 @@ class NewCategoryStructureAdapter {
1650
1541
  .then((categories) => categories.map((category) => category.id.toString()));
1651
1542
  }
1652
1543
  async getCategory(category) {
1653
- const collectionCategory = category.isCollection ||
1654
- (isNil(category.isCollection) && !category.products?.length) ||
1655
- category.isWishlist ||
1656
- category.brandCategory;
1657
- return collectionCategory ? this.categoryRepository.get({ id: category.id }) : category;
1544
+ return isNil(category.isCollection) || (category.isCollection && !category.products?.length)
1545
+ ? this.categoryRepository.get({ id: category.id })
1546
+ : category;
1658
1547
  }
1659
1548
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable }); }
1660
1549
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: NewCategoryStructureAdapter }); }
@@ -1687,13 +1576,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1687
1576
  }] }] });
1688
1577
 
1689
1578
  class CatalogService {
1690
- constructor(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch) {
1579
+ constructor(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex) {
1691
1580
  this.productRepository = productRepository;
1692
- this.productStockNotificationRepository = productStockNotificationRepository;
1693
1581
  this.categoryRepository = categoryRepository;
1694
1582
  this.categoryStructureAdapter = categoryStructureAdapter;
1695
1583
  this.shop = shop;
1696
- this.productSearch = productSearch;
1584
+ this.productIndex = productIndex;
1697
1585
  this.productsByTerm = {};
1698
1586
  this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1699
1587
  const filters = {};
@@ -1720,22 +1608,17 @@ class CatalogService {
1720
1608
  if (!sort || sort === 'most-relevant')
1721
1609
  return {};
1722
1610
  if (sort === 'best-sellers')
1723
- return {
1724
- shoppingCount: 'desc',
1725
- rate: 'desc',
1726
- stock: 'desc',
1727
- name: 'asc',
1728
- };
1611
+ return { shoppingCount: 'desc' };
1729
1612
  if (sort === 'biggest-price')
1730
- return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1613
+ return { subscriberPrice: 'desc' };
1731
1614
  if (sort === 'lowest-price')
1732
- return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1615
+ return { subscriberPrice: 'asc' };
1733
1616
  if (sort === 'best-rating')
1734
- return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1617
+ return { rate: 'desc' };
1735
1618
  if (sort === 'news')
1736
1619
  return { createdAt: 'desc' };
1737
1620
  if (sort === 'biggest-discount')
1738
- return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1621
+ return { subscriberDiscountPercentage: 'desc' };
1739
1622
  };
1740
1623
  this.buildLimitQuery = (options) => {
1741
1624
  const limit = options?.perPage || 20;
@@ -1769,26 +1652,16 @@ class CatalogService {
1769
1652
  brands: distinct?.brand,
1770
1653
  }));
1771
1654
  }
1772
- async addCustomerToStockNotification(shop, productId, name, email) {
1773
- return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1774
- }
1775
1655
  async findCatalog(options, limits) {
1776
1656
  if (this.hasTerm(options) && options.sort === 'most-relevant') {
1777
- const productsIds = await this.findCatalogIdsBySearch(options.term);
1778
- return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1657
+ const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
1658
+ return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1779
1659
  }
1780
1660
  if (this.hasCategory(options) && options.sort === 'most-relevant') {
1781
- const mostRelevant = options.category.isWishlist ? [] : options.category.getMostRelevantByShop(this.shop);
1782
- const productsIds = await this.productRepository
1783
- .findCatalog({
1784
- fields: ['id'],
1785
- filters: {
1786
- ...(await this.buildMainFilter(options)),
1787
- ...this.buildFilterQuery(options?.filters || {}),
1788
- },
1789
- })
1790
- .then((products) => products.data.map((product) => product.id));
1791
- return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
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);
1792
1665
  }
1793
1666
  const repoParams = {
1794
1667
  filters: {
@@ -1813,47 +1686,15 @@ class CatalogService {
1813
1686
  if (profile)
1814
1687
  return { tags: { operator: Where.LIKE, value: profile } };
1815
1688
  if (term)
1816
- return this.productSearch
1817
- .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1818
- .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1819
- }
1820
- async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1821
- const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1822
- const totalResult = await this.productRepository.findCatalog({
1823
- filters: {
1824
- id: { operator: Where.IN, value: mostRelevantProductsIds },
1825
- ...this.buildFilterQuery(options?.filters || {}),
1826
- },
1827
- orderBy: this.buildSortQuery('best-sellers'),
1828
- options: {
1829
- minimal: ['price'],
1830
- maximum: ['price'],
1831
- distinct: ['brand'],
1832
- },
1833
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1834
- const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
1835
- const firstProducts = totalResult.data
1836
- .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
1837
- .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
1838
- const lastProducts = totalResult.data
1839
- .filter((product) => !mostRelevants.includes(product.id))
1840
- .concat(mostRelevantWithouyStock);
1841
- const categoryMostRelevants = firstProducts.concat(lastProducts);
1842
- const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1843
- return {
1844
- data: resultFinal,
1845
- count: totalResult.count,
1846
- maximum: totalResult.maximum,
1847
- minimal: totalResult.minimal,
1848
- distinct: totalResult.distinct,
1849
- };
1689
+ return this.productIndex
1690
+ .search(term, 999, this.shop)
1691
+ .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1850
1692
  }
1851
- async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1693
+ async findCatalogAndSortByMostRevelant(productIds, options, limits) {
1852
1694
  const totalResult = await this.productRepository.findCatalog({
1853
- fields: ['id', 'stock', 'gender'],
1695
+ fields: ['id', 'stock'],
1854
1696
  filters: {
1855
1697
  id: { operator: Where.IN, value: productIds },
1856
- published: { operator: Where.EQUALS, value: true },
1857
1698
  ...this.buildFilterQuery(options?.filters || {}),
1858
1699
  },
1859
1700
  options: {
@@ -1862,17 +1703,10 @@ class CatalogService {
1862
1703
  distinct: ['brand'],
1863
1704
  },
1864
1705
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1865
- const defaultGender = options?.filters?.gender
1866
- ? options?.filters?.gender.at(0)
1867
- : this.shop === Shops.GLAMSHOP
1868
- ? 'female'
1869
- : 'male';
1870
1706
  const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1871
1707
  const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1872
- const productIdsStockGender = productIds.filter((product) => stockData.some((result) => result.id === product && (result.gender?.includes(defaultGender) || result.gender?.includes('unisex'))));
1873
- const productIdsStockNotGender = productIds.filter((product) => stockData.some((result) => result.id === product && !result.gender?.includes(defaultGender) && !result.gender?.includes('unisex')));
1874
- const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
1875
- const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
1708
+ const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1709
+ const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
1876
1710
  const limitedProductId = productIdsStock
1877
1711
  .concat(productIdsStockOut)
1878
1712
  .slice(limits.offset, limits.offset + limits.limit);
@@ -1890,14 +1724,19 @@ class CatalogService {
1890
1724
  distinct: totalResult.distinct,
1891
1725
  };
1892
1726
  }
1893
- async findCatalogIdsBySearch(term, preview = false) {
1727
+ async findCatalogIdsByElasticSearch(term) {
1894
1728
  if (this.productsByTerm[term])
1895
1729
  return this.productsByTerm[term];
1896
- return (this.productsByTerm[term] = await this.productSearch
1897
- .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1898
- .then((products) => [...new Set(products.map((product) => product.id))]));
1730
+ return (this.productsByTerm[term] = await this.productIndex
1731
+ .search(term, 999, this.shop)
1732
+ .then(({ hits: products }) => {
1733
+ const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1734
+ const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1735
+ const sorted = [...withStock, ...withOutStock];
1736
+ return [...new Set(sorted.map(({ _source }) => _source.id))];
1737
+ }));
1899
1738
  }
1900
- 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: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable }); }
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 }); }
1901
1740
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
1902
1741
  }
1903
1742
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService, decorators: [{
@@ -1905,9 +1744,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1905
1744
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1906
1745
  type: Inject,
1907
1746
  args: ['ProductRepository']
1908
- }] }, { type: undefined, decorators: [{
1909
- type: Inject,
1910
- args: ['ProductStockNotificationRepository']
1911
1747
  }] }, { type: undefined, decorators: [{
1912
1748
  type: Inject,
1913
1749
  args: ['CategoryRepository']
@@ -1917,10 +1753,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
1917
1753
  }] }, { type: i1$2.Shops, decorators: [{
1918
1754
  type: Inject,
1919
1755
  args: [DEFAULT_SHOP]
1920
- }] }, { type: undefined, decorators: [{
1921
- type: Inject,
1922
- args: ['ProductSearch']
1923
- }] }] });
1756
+ }] }, { type: i1$2.ProductsIndex }] });
1924
1757
 
1925
1758
  class CategoryService {
1926
1759
  constructor(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop) {
@@ -1987,12 +1820,11 @@ __decorate([
1987
1820
  ], CategoryWithTree.prototype, "children", void 0);
1988
1821
 
1989
1822
  class WishlistService {
1990
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productSearch) {
1823
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productIndex) {
1991
1824
  this.wishlistRepository = wishlistRepository;
1992
1825
  this.shop = shop;
1993
- this.productSearch = productSearch;
1994
1826
  const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1995
- this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch);
1827
+ this.catalogService = new CatalogService(productRepository, categoryRepository, categoryStructureAdapter, shop, productIndex);
1996
1828
  this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1997
1829
  }
1998
1830
  getCatalogService() {
@@ -2001,68 +1833,42 @@ class WishlistService {
2001
1833
  getCategoryService() {
2002
1834
  return this.categoryService;
2003
1835
  }
2004
- async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1836
+ async create({ personId, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
2005
1837
  const data = {
2006
1838
  slug: '',
2007
1839
  name: title,
2008
1840
  description,
2009
- metadatas: [
2010
- {
2011
- shop: this.shop,
2012
- title: `${userFullName} - ${title}`,
2013
- description: `${userFullName} - ${description}`,
2014
- },
2015
- ],
1841
+ metadata: {
1842
+ title: `${userFullName} - ${title}`,
1843
+ description: `${userFullName} - ${description}`,
1844
+ },
2016
1845
  shop: this.shop,
2017
1846
  shops: [this.shop],
2018
1847
  personId,
2019
1848
  personName: userFullName,
2020
1849
  personPhoto: userPhoto,
2021
1850
  brandCategory: false,
2022
- published,
1851
+ published: true,
2023
1852
  theme,
2024
1853
  bannerUrl,
2025
- personType: personType ?? PersonTypes.NONE,
2026
- personIsSubscriber: personIsSubscriber ?? false,
2027
1854
  };
2028
- const hasWishlist = await this.wishlistRepository
2029
- .find({
2030
- filters: {
2031
- personId,
2032
- },
2033
- options: {
2034
- enableCount: false,
2035
- },
2036
- orderBy: {
2037
- id: 'asc',
2038
- },
2039
- })
2040
- .then((res) => res.data);
2041
- if (hasWishlist.length)
2042
- return hasWishlist.at(0);
2043
1855
  const newWishlist = await this.wishlistRepository.create(data);
2044
1856
  await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
2045
1857
  return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
2046
1858
  }
2047
- update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, personType, personIsSubscriber, }) {
1859
+ update({ id, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
2048
1860
  const data = {
2049
1861
  id,
2050
1862
  name: title,
2051
1863
  description,
2052
- published,
2053
- metadatas: [
2054
- {
2055
- shop: this.shop,
2056
- title: `${userFullName} - ${title}`,
2057
- description: `${userFullName} - ${description}`,
2058
- },
2059
- ],
1864
+ metadata: {
1865
+ title: `${userFullName} - ${title}`,
1866
+ description: `${userFullName} - ${description}`,
1867
+ },
2060
1868
  personName: userFullName,
2061
1869
  personPhoto: userPhoto,
2062
1870
  theme,
2063
1871
  bannerUrl,
2064
- personType: personType ?? PersonTypes.NONE,
2065
- personIsSubscriber: personIsSubscriber ?? false,
2066
1872
  };
2067
1873
  return this.wishlistRepository.update(data);
2068
1874
  }
@@ -2098,7 +1904,7 @@ class WishlistService {
2098
1904
  }
2099
1905
  return wishlist;
2100
1906
  }
2101
- 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: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable }); }
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 }); }
2102
1908
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService }); }
2103
1909
  }
2104
1910
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: WishlistService, decorators: [{
@@ -2118,27 +1924,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2118
1924
  }] }, { type: undefined, decorators: [{
2119
1925
  type: Inject,
2120
1926
  args: ['CategoryRepository']
2121
- }] }, { type: undefined, decorators: [{
2122
- type: Inject,
2123
- args: ['ProductStockNotificationRepository']
2124
- }] }, { type: undefined, decorators: [{
2125
- type: Inject,
2126
- args: ['ProductSearch']
2127
- }] }] });
1927
+ }] }, { type: i1$2.ProductsIndex }] });
2128
1928
 
2129
1929
  class CheckoutSubscriptionService {
2130
- constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
1930
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
2131
1931
  this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
2132
- this.dataPersistence = dataPersistence;
1932
+ this.subscriptionRepository = subscriptionRepository;
2133
1933
  this.couponService = couponService;
2134
1934
  }
2135
1935
  getCheckoutSubscription(checkoutData) {
2136
- return this.dataPersistence
2137
- .get('checkoutSubscriptionId')
2138
- .pipe(concatMap((id) => !isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(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;
2139
1948
  }
2140
1949
  clearCheckoutSubscriptionFromSession() {
2141
- return this.dataPersistence.remove('checkoutSubscriptionId');
1950
+ cookie.remove('checkoutSubscriptionId');
1951
+ return of();
2142
1952
  }
2143
1953
  checkCoupon(nickname, userEmail) {
2144
1954
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
@@ -2148,15 +1958,7 @@ class CheckoutSubscriptionService {
2148
1958
  calcDiscountSubscription(coupon) {
2149
1959
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
2150
1960
  }
2151
- async createCheckoutSubscription(checkoutData) {
2152
- const checkout = await this.checkoutSubscriptionRepository.create({
2153
- createdAt: new Date(),
2154
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
2155
- });
2156
- await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
2157
- return checkout;
2158
- }
2159
- 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 }); }
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 }); }
2160
1962
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService }); }
2161
1963
  }
2162
1964
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
@@ -2166,7 +1968,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2166
1968
  args: ['CheckoutSubscriptionRepository']
2167
1969
  }] }, { type: undefined, decorators: [{
2168
1970
  type: Inject,
2169
- args: [PERSISTENCE_PROVIDER]
1971
+ args: ['SubscriptionRepository']
2170
1972
  }] }, { type: CouponService }] });
2171
1973
 
2172
1974
  class UtilHelper {
@@ -2424,12 +2226,10 @@ class AngularConnectModule {
2424
2226
  ? OldCategoryStructureAdapter
2425
2227
  : NewCategoryStructureAdapter,
2426
2228
  },
2427
- { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2428
2229
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2429
2230
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2430
2231
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
2431
2232
  ...(isNil(options?.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
2432
- ...(isNil(options?.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
2433
2233
  ...(isNil(options?.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
2434
2234
  ...(isNil(options?.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
2435
2235
  ...(isNil(options?.storageBaseUrl) ? [] : [{ provide: STORAGE_BASE_URL, useValue: options.storageBaseUrl }]),
@@ -2437,8 +2237,7 @@ class AngularConnectModule {
2437
2237
  };
2438
2238
  }
2439
2239
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
2440
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
2441
- AngularVertexSeachModule,
2240
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.3", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, AngularElasticSeachModule,
2442
2241
  AngularFirebaseAuthModule,
2443
2242
  AngularFirestoreModule,
2444
2243
  AngularHasuraGraphQLModule] }); }
@@ -2461,17 +2260,6 @@ class AngularConnectModule {
2461
2260
  },
2462
2261
  deps: ['UserRepository', 'FileUploaderService'],
2463
2262
  },
2464
- {
2465
- provide: 'FileUploaderService',
2466
- useFactory: (storage, baseUrl) => {
2467
- return new FirebaseFileUploaderService(storage, baseUrl);
2468
- },
2469
- deps: [Storage, STORAGE_BASE_URL],
2470
- },
2471
- {
2472
- provide: 'ProductSearch',
2473
- useExisting: ProductsVertexSearch,
2474
- },
2475
2263
  ], imports: [provideFirebaseApp((injector) => {
2476
2264
  const appName = injector.get(FIREBASE_APP_NAME) || '[DEFAULT]';
2477
2265
  try {
@@ -2481,9 +2269,7 @@ class AngularConnectModule {
2481
2269
  return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2482
2270
  }
2483
2271
  }),
2484
- provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2485
2272
  AngularElasticSeachModule,
2486
- AngularVertexSeachModule,
2487
2273
  AngularFirebaseAuthModule,
2488
2274
  AngularFirestoreModule,
2489
2275
  AngularHasuraGraphQLModule] }); }
@@ -2501,9 +2287,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2501
2287
  return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
2502
2288
  }
2503
2289
  }),
2504
- provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
2505
2290
  AngularElasticSeachModule,
2506
- AngularVertexSeachModule,
2507
2291
  AngularFirebaseAuthModule,
2508
2292
  AngularFirestoreModule,
2509
2293
  AngularHasuraGraphQLModule,
@@ -2527,17 +2311,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2527
2311
  },
2528
2312
  deps: ['UserRepository', 'FileUploaderService'],
2529
2313
  },
2530
- {
2531
- provide: 'FileUploaderService',
2532
- useFactory: (storage, baseUrl) => {
2533
- return new FirebaseFileUploaderService(storage, baseUrl);
2534
- },
2535
- deps: [Storage, STORAGE_BASE_URL],
2536
- },
2537
- {
2538
- provide: 'ProductSearch',
2539
- useExisting: ProductsVertexSearch,
2540
- },
2541
2314
  ],
2542
2315
  }]
2543
2316
  }] });
@@ -2546,5 +2319,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.3", ngImpor
2546
2319
  * Generated bundle index. Do not edit.
2547
2320
  */
2548
2321
 
2549
- export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2322
+ export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, ShippingService, UtilHelper, WishlistService };
2550
2323
  //# sourceMappingURL=infrab4a-connect-angular.mjs.map