@infrab4a/connect-angular 4.14.4 → 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,6 +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) {
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();
1498
1520
  return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1499
1521
  .updateCheckoutLineItems(Checkout.toInstance({
1500
1522
  ...checkout.toPlain(),
@@ -1728,7 +1750,6 @@ class CatalogService {
1728
1750
  this.shop = shop;
1729
1751
  this.productSearch = productSearch;
1730
1752
  this.productsByTerm = {};
1731
- this.brandsList = {};
1732
1753
  this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1733
1754
  const filters = {};
1734
1755
  if (clubDiscount?.length)
@@ -1781,15 +1802,6 @@ class CatalogService {
1781
1802
  this.hasProfile = (options) => 'profile' in options;
1782
1803
  this.hasTerm = (options) => 'term' in options;
1783
1804
  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
- };
1793
1805
  }
1794
1806
  async fetchProducts(options) {
1795
1807
  const limits = this.buildLimitQuery(options);
@@ -1799,21 +1811,18 @@ class CatalogService {
1799
1811
  throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1800
1812
  if (this.hasTerm(options) && options.filters?.customOptions)
1801
1813
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
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
- },
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),
1813
1822
  },
1814
- brands: this.brandsList[this.buildIndexBrands(options)],
1815
- };
1816
- });
1823
+ },
1824
+ brands: distinct?.brand,
1825
+ }));
1817
1826
  }
1818
1827
  async addCustomerToStockNotification(shop, productId, name, email) {
1819
1828
  return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
@@ -1846,9 +1855,7 @@ class CatalogService {
1846
1855
  options: {
1847
1856
  minimal: ['price'],
1848
1857
  maximum: ['price'],
1849
- ...(!this.brandsList[this.buildIndexBrands(options)] && isEmpty(options.filters?.brands)
1850
- ? { distinct: ['brand'] }
1851
- : {}),
1858
+ ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1852
1859
  },
1853
1860
  };
1854
1861
  if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
@@ -1866,7 +1873,6 @@ class CatalogService {
1866
1873
  .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1867
1874
  }
1868
1875
  async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1869
- const brandsList = this.brandsList[this.buildIndexBrands(options)];
1870
1876
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1871
1877
  const totalResult = await this.productRepository.findCatalog({
1872
1878
  filters: {
@@ -1877,7 +1883,7 @@ class CatalogService {
1877
1883
  options: {
1878
1884
  minimal: ['price'],
1879
1885
  maximum: ['price'],
1880
- ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1886
+ distinct: ['brand'],
1881
1887
  },
1882
1888
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1883
1889
  const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
@@ -1889,20 +1895,15 @@ class CatalogService {
1889
1895
  .concat(mostRelevantWithouyStock);
1890
1896
  const categoryMostRelevants = firstProducts.concat(lastProducts);
1891
1897
  const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1892
- await this.setBrandsList(options, totalResult.distinct?.brand);
1893
1898
  return {
1894
1899
  data: resultFinal,
1895
1900
  count: totalResult.count,
1896
1901
  maximum: totalResult.maximum,
1897
1902
  minimal: totalResult.minimal,
1898
- distinct: {
1899
- ...totalResult.distinct,
1900
- brand: this.brandsList[this.buildIndexBrands(options)],
1901
- },
1903
+ distinct: totalResult.distinct,
1902
1904
  };
1903
1905
  }
1904
1906
  async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1905
- const brandsList = this.brandsList[this.buildIndexBrands(options)];
1906
1907
  const totalResult = await this.productRepository.findCatalog({
1907
1908
  fields: ['id', 'stock', 'gender'],
1908
1909
  filters: {
@@ -1913,7 +1914,7 @@ class CatalogService {
1913
1914
  options: {
1914
1915
  minimal: ['price'],
1915
1916
  maximum: ['price'],
1916
- ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1917
+ distinct: ['brand'],
1917
1918
  },
1918
1919
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1919
1920
  const defaultGender = options?.filters?.gender
@@ -1936,16 +1937,12 @@ class CatalogService {
1936
1937
  id: { operator: Where.IN, value: orderedId },
1937
1938
  },
1938
1939
  });
1939
- await this.setBrandsList(options, totalResult.distinct?.brand);
1940
1940
  return {
1941
1941
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1942
1942
  count: totalResult.count,
1943
1943
  maximum: totalResult.maximum,
1944
1944
  minimal: totalResult.minimal,
1945
- distinct: {
1946
- ...totalResult.distinct,
1947
- brand: this.brandsList[this.buildIndexBrands(options)],
1948
- },
1945
+ distinct: totalResult.distinct,
1949
1946
  };
1950
1947
  }
1951
1948
  async findCatalogIdsBySearch(term, preview = false) {
@@ -1955,35 +1952,6 @@ class CatalogService {
1955
1952
  .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1956
1953
  .then((products) => [...new Set(products.map((product) => product.id))]));
1957
1954
  }
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
- }
1987
1955
  }
1988
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 });
1989
1957
  CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });