@infrab4a/connect-angular 5.0.0-beta.67 → 5.0.0-beta.68

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 (56) hide show
  1. package/esm2022/angular-connect.module.mjs +1 -1
  2. package/esm2022/angular-elastic-search.module.mjs +1 -1
  3. package/esm2022/angular-firebase-auth.module.mjs +1 -1
  4. package/esm2022/angular-firestore.module.mjs +1 -1
  5. package/esm2022/angular-hasura-graphql.module.mjs +1 -1
  6. package/esm2022/angular-vertex-search.module.mjs +1 -1
  7. package/esm2022/consts/category-structure.mjs +1 -1
  8. package/esm2022/consts/default-shop.const.mjs +1 -1
  9. package/esm2022/consts/es-config.const.mjs +1 -1
  10. package/esm2022/consts/firebase-const.mjs +1 -1
  11. package/esm2022/consts/hasura-options.const.mjs +1 -1
  12. package/esm2022/consts/index.mjs +1 -1
  13. package/esm2022/consts/persistence.const.mjs +1 -1
  14. package/esm2022/consts/storage-base-url.const.mjs +1 -1
  15. package/esm2022/consts/vertex-config.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 -1
  19. package/esm2022/persistence/cookie-data-persistence.mjs +1 -1
  20. package/esm2022/persistence/data-persistence.mjs +1 -1
  21. package/esm2022/persistence/index.mjs +1 -1
  22. package/esm2022/services/auth.service.mjs +1 -1
  23. package/esm2022/services/cart.service.mjs +1 -5
  24. package/esm2022/services/catalog/adapters/category-structure.adapter.mjs +1 -1
  25. package/esm2022/services/catalog/adapters/index.mjs +1 -1
  26. package/esm2022/services/catalog/adapters/new-category-structure.adapter.mjs +1 -1
  27. package/esm2022/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
  28. package/esm2022/services/catalog/catalog.service.mjs +72 -18
  29. package/esm2022/services/catalog/category.service.mjs +1 -1
  30. package/esm2022/services/catalog/enums/index.mjs +1 -1
  31. package/esm2022/services/catalog/enums/product-sorts.enum.mjs +1 -1
  32. package/esm2022/services/catalog/index.mjs +1 -1
  33. package/esm2022/services/catalog/models/category-with-tree.model.mjs +1 -1
  34. package/esm2022/services/catalog/models/index.mjs +1 -1
  35. package/esm2022/services/catalog/types/index.mjs +1 -1
  36. package/esm2022/services/catalog/types/product-sort.type.mjs +1 -1
  37. package/esm2022/services/catalog/wishlist.service.mjs +1 -1
  38. package/esm2022/services/checkout-subscription.service.mjs +1 -1
  39. package/esm2022/services/checkout.service.mjs +1 -1
  40. package/esm2022/services/coupon.service.mjs +17 -11
  41. package/esm2022/services/helpers/index.mjs +1 -1
  42. package/esm2022/services/helpers/util.helper.mjs +1 -1
  43. package/esm2022/services/home-shop.service.mjs +1 -1
  44. package/esm2022/services/index.mjs +1 -1
  45. package/esm2022/services/order.service.mjs +1 -1
  46. package/esm2022/services/shipping.service.mjs +1 -1
  47. package/esm2022/services/types/index.mjs +1 -1
  48. package/esm2022/services/types/required-checkout-data.type.mjs +1 -1
  49. package/esm2022/services/types/required-checkout-subscription-data.type.mjs +1 -1
  50. package/esm2022/services/types/shipping-methods.type.mjs +1 -1
  51. package/esm2022/types/firebase-app-config.type.mjs +1 -1
  52. package/esm2022/types/index.mjs +1 -1
  53. package/fesm2022/infrab4a-connect-angular.mjs +87 -31
  54. package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
  55. package/package.json +2 -2
  56. package/services/catalog/catalog.service.d.ts +4 -0
@@ -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, 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, 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';
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';
@@ -1137,7 +1137,7 @@ class CouponService {
1137
1137
  let discount = 0;
1138
1138
  if (type == CouponTypes.SHIPPING) {
1139
1139
  const subTotal = checkout.shipping.ShippingPrice;
1140
- const discount = subTotal * ((value > 100 ? 100 : value) / 100);
1140
+ const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
1141
1141
  return { discount, lineItems: checkout.lineItems };
1142
1142
  }
1143
1143
  let lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
@@ -1146,7 +1146,7 @@ class CouponService {
1146
1146
  discount = value > subTotal ? subTotal : value;
1147
1147
  }
1148
1148
  else {
1149
- discount = subTotal * ((value > 100 ? 100 : value) / 100);
1149
+ discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
1150
1150
  }
1151
1151
  const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
1152
1152
  return { discount, lineItems };
@@ -1165,10 +1165,12 @@ class CouponService {
1165
1165
  return true;
1166
1166
  }
1167
1167
  const couponCategories = await this.getCouponCategoriesId(coupon.productsCategories);
1168
- const hasCategories = checkout.lineItems?.filter((i) => {
1169
- if (!i.categories || !i.categories?.length)
1168
+ const hasCategories = checkout.lineItems?.filter((item) => {
1169
+ if (item.isGift)
1170
+ return false;
1171
+ if (!item.categories || !item.categories?.length)
1170
1172
  return true;
1171
- return i.categories.some((c) => couponCategories.some((cat) => cat == c));
1173
+ return item.categories.some((c) => couponCategories.some((cat) => cat == c));
1172
1174
  });
1173
1175
  return hasCategories.length ? true : false;
1174
1176
  }
@@ -1211,20 +1213,24 @@ class CouponService {
1211
1213
  let lineItensDiscount = [];
1212
1214
  const couponCategories = await this.getCouponCategoriesId(productsCategories);
1213
1215
  if (productsCategories && productsCategories.length) {
1214
- lineItensDiscount = checkout.lineItems?.filter((i) => {
1215
- if (i.categories?.length) {
1216
- return i.categories.some((c) => couponCategories.some((cat) => cat == c));
1216
+ lineItensDiscount = checkout.lineItems?.filter((item) => {
1217
+ if (item.isGift)
1218
+ return false;
1219
+ if (item.categories?.length) {
1220
+ return item.categories.some((c) => couponCategories.some((cat) => cat == c));
1217
1221
  }
1218
1222
  return true;
1219
1223
  });
1220
1224
  }
1221
1225
  else {
1222
- lineItensDiscount = checkout.lineItems;
1226
+ lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
1223
1227
  }
1224
1228
  return lineItensDiscount;
1225
1229
  }
1226
1230
  calcCheckoutSubtotal(lineItens, user) {
1227
- return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1231
+ return (lineItens
1232
+ ?.filter((item) => !item.isGift)
1233
+ .reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
1228
1234
  ? acc + curr.price?.subscriberPrice * curr.quantity
1229
1235
  : acc + curr.pricePaid * curr.quantity, 0) || 0);
1230
1236
  }
@@ -1489,10 +1495,6 @@ class CartService {
1489
1495
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1490
1496
  }
1491
1497
  updateUserCart(user) {
1492
- const isSameUserId = !user?.id || this.user?.id === user?.id;
1493
- const isSameUser = isSameUserId && !!this.user?.isSubscriber === !!user?.isSubscriber;
1494
- if (isSameUser)
1495
- return this.getCart();
1496
1498
  return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1497
1499
  .updateCheckoutLineItems(Checkout.toInstance({
1498
1500
  ...checkout.toPlain(),
@@ -1726,6 +1728,7 @@ class CatalogService {
1726
1728
  this.shop = shop;
1727
1729
  this.productSearch = productSearch;
1728
1730
  this.productsByTerm = {};
1731
+ this.brandsList = {};
1729
1732
  this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1730
1733
  const filters = {};
1731
1734
  if (clubDiscount?.length)
@@ -1778,6 +1781,15 @@ class CatalogService {
1778
1781
  this.hasProfile = (options) => 'profile' in options;
1779
1782
  this.hasTerm = (options) => 'term' in options;
1780
1783
  this.hasCategory = (options) => 'category' in options;
1784
+ this.buildIndexBrands = (options) => {
1785
+ if (this.hasCategory(options))
1786
+ return `category-${options.category.id}`;
1787
+ if (this.hasTerm(options))
1788
+ return `term-${options.term}`;
1789
+ if (this.hasProfile(options))
1790
+ return `profile-${options.profile.join(',')}`;
1791
+ return '';
1792
+ };
1781
1793
  }
1782
1794
  async fetchProducts(options) {
1783
1795
  const limits = this.buildLimitQuery(options);
@@ -1787,18 +1799,21 @@ class CatalogService {
1787
1799
  throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1788
1800
  if (this.hasTerm(options) && options.filters?.customOptions)
1789
1801
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1790
- return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1791
- products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1792
- pages: Math.ceil(total / limits.limit),
1793
- prices: {
1794
- price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1795
- subscriberPrice: {
1796
- min: +minimal?.price?.subscriberPrice?.toFixed(2),
1797
- max: +maximum?.price?.subscriberPrice?.toFixed(2),
1802
+ return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
1803
+ await this.setBrandsList(options, distinct?.brand);
1804
+ return {
1805
+ products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1806
+ pages: Math.ceil(total / limits.limit),
1807
+ prices: {
1808
+ price: { min: +minimal?.price?.price?.toFixed(2), max: +maximum?.price?.price?.toFixed(2) },
1809
+ subscriberPrice: {
1810
+ min: +minimal?.price?.subscriberPrice?.toFixed(2),
1811
+ max: +maximum?.price?.subscriberPrice?.toFixed(2),
1812
+ },
1798
1813
  },
1799
- },
1800
- brands: distinct?.brand,
1801
- }));
1814
+ brands: this.brandsList[this.buildIndexBrands(options)],
1815
+ };
1816
+ });
1802
1817
  }
1803
1818
  async addCustomerToStockNotification(shop, productId, name, email) {
1804
1819
  return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
@@ -1831,7 +1846,9 @@ class CatalogService {
1831
1846
  options: {
1832
1847
  minimal: ['price'],
1833
1848
  maximum: ['price'],
1834
- ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1849
+ ...(!this.brandsList[this.buildIndexBrands(options)] && isEmpty(options.filters?.brands)
1850
+ ? { distinct: ['brand'] }
1851
+ : {}),
1835
1852
  },
1836
1853
  };
1837
1854
  if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
@@ -1849,6 +1866,7 @@ class CatalogService {
1849
1866
  .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1850
1867
  }
1851
1868
  async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1869
+ const brandsList = this.brandsList[this.buildIndexBrands(options)];
1852
1870
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1853
1871
  const totalResult = await this.productRepository.findCatalog({
1854
1872
  filters: {
@@ -1859,7 +1877,7 @@ class CatalogService {
1859
1877
  options: {
1860
1878
  minimal: ['price'],
1861
1879
  maximum: ['price'],
1862
- distinct: ['brand'],
1880
+ ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1863
1881
  },
1864
1882
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1865
1883
  const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
@@ -1871,15 +1889,20 @@ class CatalogService {
1871
1889
  .concat(mostRelevantWithouyStock);
1872
1890
  const categoryMostRelevants = firstProducts.concat(lastProducts);
1873
1891
  const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1892
+ await this.setBrandsList(options, totalResult.distinct?.brand);
1874
1893
  return {
1875
1894
  data: resultFinal,
1876
1895
  count: totalResult.count,
1877
1896
  maximum: totalResult.maximum,
1878
1897
  minimal: totalResult.minimal,
1879
- distinct: totalResult.distinct,
1898
+ distinct: {
1899
+ ...totalResult.distinct,
1900
+ brand: this.brandsList[this.buildIndexBrands(options)],
1901
+ },
1880
1902
  };
1881
1903
  }
1882
1904
  async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1905
+ const brandsList = this.brandsList[this.buildIndexBrands(options)];
1883
1906
  const totalResult = await this.productRepository.findCatalog({
1884
1907
  fields: ['id', 'stock', 'gender'],
1885
1908
  filters: {
@@ -1890,7 +1913,7 @@ class CatalogService {
1890
1913
  options: {
1891
1914
  minimal: ['price'],
1892
1915
  maximum: ['price'],
1893
- distinct: ['brand'],
1916
+ ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1894
1917
  },
1895
1918
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1896
1919
  const defaultGender = options?.filters?.gender
@@ -1913,12 +1936,16 @@ class CatalogService {
1913
1936
  id: { operator: Where.IN, value: orderedId },
1914
1937
  },
1915
1938
  });
1939
+ await this.setBrandsList(options, totalResult.distinct?.brand);
1916
1940
  return {
1917
1941
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1918
1942
  count: totalResult.count,
1919
1943
  maximum: totalResult.maximum,
1920
1944
  minimal: totalResult.minimal,
1921
- distinct: totalResult.distinct,
1945
+ distinct: {
1946
+ ...totalResult.distinct,
1947
+ brand: this.brandsList[this.buildIndexBrands(options)],
1948
+ },
1922
1949
  };
1923
1950
  }
1924
1951
  async findCatalogIdsBySearch(term, preview = false) {
@@ -1928,6 +1955,35 @@ class CatalogService {
1928
1955
  .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1929
1956
  .then((products) => [...new Set(products.map((product) => product.id))]));
1930
1957
  }
1958
+ async fetchBrandsOnly(options, productIds = []) {
1959
+ return this.productRepository
1960
+ .findCatalog({
1961
+ fields: ['id'],
1962
+ filters: {
1963
+ ...(!isEmpty(productIds) ? { id: { operator: Where.IN, value: productIds } } : {}),
1964
+ published: { operator: Where.EQUALS, value: true },
1965
+ ...this.buildFilterQuery(options?.filters || {}),
1966
+ },
1967
+ options: {
1968
+ distinct: ['brand'],
1969
+ },
1970
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female')
1971
+ .then((result) => {
1972
+ return result.distinct.brand;
1973
+ });
1974
+ }
1975
+ async setBrandsList(options, brands) {
1976
+ const filterBrands = options.filters?.brands;
1977
+ if (isEmpty(brands))
1978
+ delete options.filters?.brands;
1979
+ this.brandsList[this.buildIndexBrands(options)] =
1980
+ this.brandsList[this.buildIndexBrands(options)] || brands || (await this.fetchBrandsOnly(options));
1981
+ this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
1982
+ options.filters = {
1983
+ ...options.filters,
1984
+ brands: filterBrands,
1985
+ };
1986
+ }
1931
1987
  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 }); }
1932
1988
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.3", ngImport: i0, type: CatalogService }); }
1933
1989
  }