@infrab4a/connect-angular 4.3.14 → 4.4.0-beta.11

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.
@@ -3,7 +3,7 @@ import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angu
3
3
  import * as i1$4 from '@angular/fire/app';
4
4
  import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
5
5
  import * as i1$2 from '@infrab4a/connect';
6
- import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, FirebaseFileUploaderService, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage } from '@infrab4a/connect';
6
+ import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, FirebaseFileUploaderService, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, InvalidArgumentError, Category, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage } from '@infrab4a/connect';
7
7
  import * as i1 from '@angular/fire/auth';
8
8
  import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
9
9
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
@@ -11,9 +11,9 @@ import * as i1$1 from '@angular/fire/firestore';
11
11
  import { Firestore, provideFirestore, getFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
12
12
  import * as i2 from '@angular/fire/storage';
13
13
  import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
14
- import cookie from 'js-cookie';
15
- import { of, from, combineLatest, throwError, Subject, iif, forkJoin } from 'rxjs';
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,8 +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
64
  class AngularFirebaseAuthModule {
67
65
  static initializeApp(options, nameOrConfig) {
68
66
  return {
@@ -198,7 +196,7 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
198
196
  {
199
197
  provide: 'FirestoreOptions',
200
198
  useFactory: (firestore, platformId) => ({
201
- firestore,
199
+ firestore: new ConnectFirestoreService(firestore),
202
200
  interceptors: {
203
201
  request: (request) => {
204
202
  if (isPlatformBrowser(platformId))
@@ -450,7 +448,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
450
448
  {
451
449
  provide: 'FirestoreOptions',
452
450
  useFactory: (firestore, platformId) => ({
453
- firestore,
451
+ firestore: new ConnectFirestoreService(firestore),
454
452
  interceptors: {
455
453
  request: (request) => {
456
454
  if (isPlatformBrowser(platformId))
@@ -929,23 +927,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
929
927
  }]
930
928
  }] });
931
929
 
932
- class CookieDataPersistence {
933
- get(key) {
934
- return of(cookie.get(key));
935
- }
936
- remove(key) {
937
- return of(cookie.remove(key));
938
- }
939
- set(key, value) {
940
- return from(cookie.set(key, value)).pipe(map(() => { }));
941
- }
942
- }
943
- CookieDataPersistence.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
944
- CookieDataPersistence.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence });
945
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CookieDataPersistence, decorators: [{
946
- type: Injectable
947
- }] });
948
-
949
930
  class AuthService {
950
931
  constructor(angularFireAuth, userRepository) {
951
932
  this.angularFireAuth = angularFireAuth;
@@ -1206,17 +1187,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1206
1187
  }] }]; } });
1207
1188
 
1208
1189
  class CheckoutService {
1209
- constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence) {
1190
+ constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
1210
1191
  this.couponService = couponService;
1211
1192
  this.checkoutRepository = checkoutRepository;
1193
+ this.orderRepository = orderRepository;
1212
1194
  this.userRepository = userRepository;
1213
1195
  this.defaultShop = defaultShop;
1214
- this.dataPersistence = dataPersistence;
1215
1196
  }
1216
1197
  getCheckout(checkoutData) {
1217
- return this.dataPersistence
1218
- .get('checkoutId')
1219
- .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));
1220
1202
  }
1221
1203
  getUserByCheckout(checkoutId) {
1222
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'))));
@@ -1228,7 +1210,8 @@ class CheckoutService {
1228
1210
  return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
1229
1211
  }
1230
1212
  clearCheckoutFromSession() {
1231
- return this.dataPersistence.remove('checkoutId');
1213
+ cookie.remove('checkoutId');
1214
+ return of();
1232
1215
  }
1233
1216
  calcDiscount(coupon) {
1234
1217
  return this.getCheckout().pipe(concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)));
@@ -1242,26 +1225,26 @@ class CheckoutService {
1242
1225
  ...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1243
1226
  shop: checkoutData?.shop || this.defaultShop,
1244
1227
  });
1245
- await this.dataPersistence.set('checkoutId', checkout.id).toPromise();
1228
+ cookie.set('checkoutId', checkout.id);
1246
1229
  return checkout;
1247
1230
  }
1248
1231
  }
1249
- CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Injectable });
1232
+ CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
1250
1233
  CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
1251
1234
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
1252
1235
  type: Injectable
1253
1236
  }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
1254
1237
  type: Inject,
1255
1238
  args: ['CheckoutRepository']
1239
+ }] }, { type: undefined, decorators: [{
1240
+ type: Inject,
1241
+ args: ['OrderRepository']
1256
1242
  }] }, { type: undefined, decorators: [{
1257
1243
  type: Inject,
1258
1244
  args: ['UserRepository']
1259
1245
  }] }, { type: i1$2.Shops, decorators: [{
1260
1246
  type: Inject,
1261
1247
  args: [DEFAULT_SHOP]
1262
- }] }, { type: undefined, decorators: [{
1263
- type: Inject,
1264
- args: [PERSISTENCE_PROVIDER]
1265
1248
  }] }]; } });
1266
1249
 
1267
1250
  class CartService {
@@ -1558,11 +1541,9 @@ class NewCategoryStructureAdapter {
1558
1541
  .then((categories) => categories.map((category) => category.id.toString()));
1559
1542
  }
1560
1543
  async getCategory(category) {
1561
- const collectionCategory = category.isCollection ||
1562
- (isNil(category.isCollection) && !category.products?.length) ||
1563
- category.isWishlist ||
1564
- category.brandCategory;
1565
- 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;
1566
1547
  }
1567
1548
  }
1568
1549
  NewCategoryStructureAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: NewCategoryStructureAdapter, deps: [{ token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -1627,22 +1608,17 @@ class CatalogService {
1627
1608
  if (!sort || sort === 'most-relevant')
1628
1609
  return {};
1629
1610
  if (sort === 'best-sellers')
1630
- return {
1631
- shoppingCount: 'desc',
1632
- rate: 'desc',
1633
- stock: 'desc',
1634
- name: 'asc',
1635
- };
1611
+ return { shoppingCount: 'desc' };
1636
1612
  if (sort === 'biggest-price')
1637
- return { subscriberPrice: 'desc', rate: 'desc', shoppingCount: 'desc' };
1613
+ return { subscriberPrice: 'desc' };
1638
1614
  if (sort === 'lowest-price')
1639
- return { subscriberPrice: 'asc', rate: 'desc', shoppingCount: 'desc' };
1615
+ return { subscriberPrice: 'asc' };
1640
1616
  if (sort === 'best-rating')
1641
- return { rate: 'desc', shoppingCount: 'desc', stock: 'desc', name: 'asc' };
1617
+ return { rate: 'desc' };
1642
1618
  if (sort === 'news')
1643
1619
  return { createdAt: 'desc' };
1644
1620
  if (sort === 'biggest-discount')
1645
- return { subscriberDiscountPercentage: 'desc', rate: 'desc', shoppingCount: 'desc' };
1621
+ return { subscriberDiscountPercentage: 'desc' };
1646
1622
  };
1647
1623
  this.buildLimitQuery = (options) => {
1648
1624
  const limit = options?.perPage || 20;
@@ -1682,13 +1658,9 @@ class CatalogService {
1682
1658
  return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1683
1659
  }
1684
1660
  if (this.hasCategory(options) && options.sort === 'most-relevant') {
1685
- const productsIds = await this.productRepository
1686
- .find({
1687
- filters: {
1688
- ...(await this.buildMainFilter(options)),
1689
- },
1690
- })
1691
- .then((products) => products.data.map((product) => product.id));
1661
+ const productsIds = options.category.products?.length
1662
+ ? options.category.products
1663
+ : await this.categoryRepository.get({ id: options.category.id }).then((categoryFound) => categoryFound.products);
1692
1664
  return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1693
1665
  }
1694
1666
  const repoParams = {
@@ -1955,18 +1927,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1955
1927
  }] }, { type: i1$2.ProductsIndex }]; } });
1956
1928
 
1957
1929
  class CheckoutSubscriptionService {
1958
- constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
1930
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
1959
1931
  this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
1960
- this.dataPersistence = dataPersistence;
1932
+ this.subscriptionRepository = subscriptionRepository;
1961
1933
  this.couponService = couponService;
1962
1934
  }
1963
1935
  getCheckoutSubscription(checkoutData) {
1964
- return this.dataPersistence
1965
- .get('checkoutSubscriptionId')
1966
- .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;
1967
1948
  }
1968
1949
  clearCheckoutSubscriptionFromSession() {
1969
- return this.dataPersistence.remove('checkoutSubscriptionId');
1950
+ cookie.remove('checkoutSubscriptionId');
1951
+ return of();
1970
1952
  }
1971
1953
  checkCoupon(nickname, userEmail) {
1972
1954
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
@@ -1976,16 +1958,8 @@ class CheckoutSubscriptionService {
1976
1958
  calcDiscountSubscription(coupon) {
1977
1959
  return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
1978
1960
  }
1979
- async createCheckoutSubscription(checkoutData) {
1980
- const checkout = await this.checkoutSubscriptionRepository.create({
1981
- createdAt: new Date(),
1982
- ...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
1983
- });
1984
- await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise();
1985
- return checkout;
1986
- }
1987
1961
  }
1988
- CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: PERSISTENCE_PROVIDER }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
1962
+ CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
1989
1963
  CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService });
1990
1964
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
1991
1965
  type: Injectable
@@ -1994,7 +1968,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1994
1968
  args: ['CheckoutSubscriptionRepository']
1995
1969
  }] }, { type: undefined, decorators: [{
1996
1970
  type: Inject,
1997
- args: [PERSISTENCE_PROVIDER]
1971
+ args: ['SubscriptionRepository']
1998
1972
  }] }, { type: CouponService }]; } });
1999
1973
 
2000
1974
  class UtilHelper {
@@ -2252,7 +2226,6 @@ class AngularConnectModule {
2252
2226
  ? OldCategoryStructureAdapter
2253
2227
  : NewCategoryStructureAdapter,
2254
2228
  },
2255
- { provide: PERSISTENCE_PROVIDER, useClass: options?.persistenceProvider || CookieDataPersistence },
2256
2229
  ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
2257
2230
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options?.firebase }]),
2258
2231
  ...(isNil(options?.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
@@ -2346,5 +2319,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
2346
2319
  * Generated bundle index. Do not edit.
2347
2320
  */
2348
2321
 
2349
- 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 };
2350
2323
  //# sourceMappingURL=infrab4a-connect-angular.mjs.map