@infrab4a/connect-angular 4.14.4-beta.1 → 4.15.0-beta.0

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.
@@ -5,7 +5,7 @@ import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular
5
5
  import * as i2 from '@angular/fire/storage';
6
6
  import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
7
7
  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, LogFirestoreRepository, 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, isEmpty, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } 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, LogFirestoreRepository, SequenceFirestoreRepository, 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, WishlistLogType, Wishlist, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
9
9
  import * as i1 from '@angular/fire/auth';
10
10
  import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
11
11
  import { isPlatformBrowser, isPlatformServer } from '@angular/common';
@@ -420,6 +420,13 @@ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
420
420
  },
421
421
  deps: ['FirestoreOptions'],
422
422
  },
423
+ {
424
+ provide: 'SequenceRepository',
425
+ useFactory: (options) => {
426
+ return new SequenceFirestoreRepository(options);
427
+ },
428
+ deps: ['FirestoreOptions'],
429
+ },
423
430
  ], imports: [AngularElasticSeachModule,
424
431
  provideFirestore((injector) => {
425
432
  const platformId = injector.get(PLATFORM_ID);
@@ -679,6 +686,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
679
686
  },
680
687
  deps: ['FirestoreOptions'],
681
688
  },
689
+ {
690
+ provide: 'SequenceRepository',
691
+ useFactory: (options) => {
692
+ return new SequenceFirestoreRepository(options);
693
+ },
694
+ deps: ['FirestoreOptions'],
695
+ },
682
696
  ],
683
697
  }]
684
698
  }] });
@@ -1137,16 +1151,16 @@ class CouponService {
1137
1151
  let discount = 0;
1138
1152
  if (type == CouponTypes.SHIPPING) {
1139
1153
  const subTotal = checkout.shipping.ShippingPrice;
1140
- const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
1154
+ const discount = subTotal * ((value > 100 ? 100 : value) / 100);
1141
1155
  return { discount, lineItems: checkout.lineItems };
1142
1156
  }
1143
- let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1157
+ const lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
1144
1158
  const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
1145
1159
  if (type == CouponTypes.ABSOLUTE) {
1146
1160
  discount = value > subTotal ? subTotal : value;
1147
1161
  }
1148
1162
  else {
1149
- discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
1163
+ discount = subTotal * ((value > 100 ? 100 : value) / 100);
1150
1164
  }
1151
1165
  const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1152
1166
  return { discount, lineItems };
@@ -1154,7 +1168,7 @@ class CouponService {
1154
1168
  async hasMinSubTotal(coupon, checkout) {
1155
1169
  if (!coupon.minSubTotalValue)
1156
1170
  return true;
1157
- let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1171
+ const lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
1158
1172
  const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
1159
1173
  if (coupon.minSubTotalValue <= subTotal)
1160
1174
  return true;
@@ -1277,6 +1291,8 @@ class CouponService {
1277
1291
  if (type === CouponTypes.ABSOLUTE) {
1278
1292
  const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
1279
1293
  lineItemsDiscount = lineItems.map((item) => {
1294
+ if (item.isGift)
1295
+ return item;
1280
1296
  const totalItemPercentage = item.pricePaid / subTotal;
1281
1297
  const discountItem = couponDiscountMax * totalItemPercentage;
1282
1298
  return {
@@ -1287,6 +1303,8 @@ class CouponService {
1287
1303
  }
1288
1304
  else {
1289
1305
  lineItemsDiscount = lineItems.map((item) => {
1306
+ if (item.isGift)
1307
+ return item;
1290
1308
  const discountItem = item.pricePaid * (couponDiscount / 100);
1291
1309
  return {
1292
1310
  ...item,
@@ -1495,9 +1513,10 @@ class CartService {
1495
1513
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1496
1514
  }
1497
1515
  updateUserCart(user) {
1498
- // const isSameUserId = !user?.id || this.user?.id === user?.id
1499
- // const isSameUser = isSameUserId && !!this.user?.isSubscriber === !!user?.isSubscriber
1500
- // if (isSameUser) return this.getCart()
1516
+ const isSameUserId = !user?.id || this.user?.id === user?.id;
1517
+ const isSameUser = isSameUserId && !!this.user?.isSubscriber === !!user?.isSubscriber;
1518
+ if (isSameUser)
1519
+ return this.getCart();
1501
1520
  return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1502
1521
  .updateCheckoutLineItems(Checkout.toInstance({
1503
1522
  ...checkout.toPlain(),
@@ -1731,7 +1750,6 @@ class CatalogService {
1731
1750
  this.shop = shop;
1732
1751
  this.productSearch = productSearch;
1733
1752
  this.productsByTerm = {};
1734
- this.brandsList = {};
1735
1753
  this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1736
1754
  const filters = {};
1737
1755
  if (clubDiscount?.length)
@@ -1784,15 +1802,6 @@ class CatalogService {
1784
1802
  this.hasProfile = (options) => 'profile' in options;
1785
1803
  this.hasTerm = (options) => 'term' in options;
1786
1804
  this.hasCategory = (options) => 'category' in options;
1787
- this.buildIndexBrands = (options) => {
1788
- if (this.hasCategory(options))
1789
- return `category-${options.category.id}`;
1790
- if (this.hasTerm(options))
1791
- return `term-${options.term}`;
1792
- if (this.hasProfile(options))
1793
- return `profile-${options.profile.join(',')}`;
1794
- return '';
1795
- };
1796
1805
  }
1797
1806
  async fetchProducts(options) {
1798
1807
  const limits = this.buildLimitQuery(options);
@@ -1802,21 +1811,18 @@ class CatalogService {
1802
1811
  throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1803
1812
  if (this.hasTerm(options) && options.filters?.customOptions)
1804
1813
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1805
- return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
1806
- await this.setBrandsList(options, distinct?.brand);
1807
- return {
1808
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1809
- pages: Math.ceil(total / limits.limit),
1810
- prices: {
1811
- price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1812
- subscriberPrice: {
1813
- min: +minimal?.price?.subscriberPrice?.toFixed(2),
1814
- max: +maximum?.price?.subscriberPrice?.toFixed(2),
1815
- },
1814
+ return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1815
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1816
+ pages: Math.ceil(total / limits.limit),
1817
+ prices: {
1818
+ price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1819
+ subscriberPrice: {
1820
+ min: +minimal?.price?.subscriberPrice?.toFixed(2),
1821
+ max: +maximum?.price?.subscriberPrice?.toFixed(2),
1816
1822
  },
1817
- brands: this.brandsList[this.buildIndexBrands(options)],
1818
- };
1819
- });
1823
+ },
1824
+ brands: distinct?.brand,
1825
+ }));
1820
1826
  }
1821
1827
  async addCustomerToStockNotification(shop, productId, name, email) {
1822
1828
  return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
@@ -1849,9 +1855,7 @@ class CatalogService {
1849
1855
  options: {
1850
1856
  minimal: ['price'],
1851
1857
  maximum: ['price'],
1852
- ...(!this.brandsList[this.buildIndexBrands(options)] && isEmpty(options.filters?.brands)
1853
- ? { distinct: ['brand'] }
1854
- : {}),
1858
+ ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1855
1859
  },
1856
1860
  };
1857
1861
  if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
@@ -1869,7 +1873,6 @@ class CatalogService {
1869
1873
  .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1870
1874
  }
1871
1875
  async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1872
- const brandsList = this.brandsList[this.buildIndexBrands(options)];
1873
1876
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1874
1877
  const totalResult = await this.productRepository.findCatalog({
1875
1878
  filters: {
@@ -1880,7 +1883,7 @@ class CatalogService {
1880
1883
  options: {
1881
1884
  minimal: ['price'],
1882
1885
  maximum: ['price'],
1883
- ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1886
+ distinct: ['brand'],
1884
1887
  },
1885
1888
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1886
1889
  const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
@@ -1892,20 +1895,15 @@ class CatalogService {
1892
1895
  .concat(mostRelevantWithouyStock);
1893
1896
  const categoryMostRelevants = firstProducts.concat(lastProducts);
1894
1897
  const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1895
- await this.setBrandsList(options, totalResult.distinct?.brand);
1896
1898
  return {
1897
1899
  data: resultFinal,
1898
1900
  count: totalResult.count,
1899
1901
  maximum: totalResult.maximum,
1900
1902
  minimal: totalResult.minimal,
1901
- distinct: {
1902
- ...totalResult.distinct,
1903
- brand: this.brandsList[this.buildIndexBrands(options)],
1904
- },
1903
+ distinct: totalResult.distinct,
1905
1904
  };
1906
1905
  }
1907
1906
  async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1908
- const brandsList = this.brandsList[this.buildIndexBrands(options)];
1909
1907
  const totalResult = await this.productRepository.findCatalog({
1910
1908
  fields: ['id', 'stock', 'gender'],
1911
1909
  filters: {
@@ -1916,7 +1914,7 @@ class CatalogService {
1916
1914
  options: {
1917
1915
  minimal: ['price'],
1918
1916
  maximum: ['price'],
1919
- ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1917
+ distinct: ['brand'],
1920
1918
  },
1921
1919
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1922
1920
  const defaultGender = options?.filters?.gender
@@ -1939,16 +1937,12 @@ class CatalogService {
1939
1937
  id: { operator: Where.IN, value: orderedId },
1940
1938
  },
1941
1939
  });
1942
- await this.setBrandsList(options, totalResult.distinct?.brand);
1943
1940
  return {
1944
1941
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1945
1942
  count: totalResult.count,
1946
1943
  maximum: totalResult.maximum,
1947
1944
  minimal: totalResult.minimal,
1948
- distinct: {
1949
- ...totalResult.distinct,
1950
- brand: this.brandsList[this.buildIndexBrands(options)],
1951
- },
1945
+ distinct: totalResult.distinct,
1952
1946
  };
1953
1947
  }
1954
1948
  async findCatalogIdsBySearch(term, preview = false) {
@@ -1958,35 +1952,6 @@ class CatalogService {
1958
1952
  .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1959
1953
  .then((products) => [...new Set(products.map((product) => product.id))]));
1960
1954
  }
1961
- async fetchBrandsOnly(options, productIds = []) {
1962
- return this.productRepository
1963
- .findCatalog({
1964
- fields: ['id'],
1965
- filters: {
1966
- ...(!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {}),
1967
- published: { operator: Where.EQUALS, value: true },
1968
- ...this.buildFilterQuery(options?.filters || {}),
1969
- },
1970
- options: {
1971
- distinct: ['brand'],
1972
- },
1973
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1974
- .then((result) => {
1975
- return result.distinct.brand;
1976
- });
1977
- }
1978
- async setBrandsList(options, brands) {
1979
- const filterBrands = options.filters?.brands;
1980
- if (isEmpty(brands))
1981
- delete options.filters?.brands;
1982
- this.brandsList[this.buildIndexBrands(options)] =
1983
- this.brandsList[this.buildIndexBrands(options)] || brands || (await this.fetchBrandsOnly(options));
1984
- this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
1985
- options.filters = {
1986
- ...options.filters,
1987
- brands: filterBrands,
1988
- };
1989
- }
1990
1955
  }
1991
1956
  CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
1992
1957
  CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });