@se-faststore/components 0.0.0-stage → 0.12.1
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.
- package/LICENSE +21 -0
- package/README.md +129 -2
- package/dist/b2b/SeActionHubBulletinBoard/index.d.ts +2 -0
- package/dist/b2b/SeActionHubBulletinBoard/index.d.ts.map +1 -0
- package/dist/b2b/SeActionHubBulletinBoard/index.js +18 -0
- package/dist/b2b/SeActionHubBulletinBoard/index.js.map +1 -0
- package/dist/b2b/SeActionHubBulletinBoard/types.d.ts +24 -0
- package/dist/b2b/SeActionHubBulletinBoard/types.d.ts.map +1 -0
- package/dist/b2b/SeActionHubBulletinBoard/types.js +3 -0
- package/dist/b2b/SeActionHubBulletinBoard/types.js.map +1 -0
- package/dist/b2b/SeAddToPurchaseList/addToPurchaseListUtils.d.ts +24 -0
- package/dist/b2b/SeAddToPurchaseList/addToPurchaseListUtils.d.ts.map +1 -0
- package/dist/b2b/SeAddToPurchaseList/addToPurchaseListUtils.js +28 -0
- package/dist/b2b/SeAddToPurchaseList/addToPurchaseListUtils.js.map +1 -0
- package/dist/b2b/SeAddToPurchaseList/index.d.ts +3 -0
- package/dist/b2b/SeAddToPurchaseList/index.d.ts.map +1 -0
- package/dist/b2b/SeAddToPurchaseList/index.js +19 -0
- package/dist/b2b/SeAddToPurchaseList/index.js.map +1 -0
- package/dist/b2b/SeAddToPurchaseList/useAddToPurchaseList.d.ts +29 -0
- package/dist/b2b/SeAddToPurchaseList/useAddToPurchaseList.d.ts.map +1 -0
- package/dist/b2b/SeAddToPurchaseList/useAddToPurchaseList.js +86 -0
- package/dist/b2b/SeAddToPurchaseList/useAddToPurchaseList.js.map +1 -0
- package/dist/b2b/SeAddressSelector/index.d.ts +2 -0
- package/dist/b2b/SeAddressSelector/index.d.ts.map +1 -0
- package/dist/b2b/SeAddressSelector/index.js +18 -0
- package/dist/b2b/SeAddressSelector/index.js.map +1 -0
- package/dist/b2b/SeAddressSelector/useAddressSelector.d.ts +34 -0
- package/dist/b2b/SeAddressSelector/useAddressSelector.d.ts.map +1 -0
- package/dist/b2b/SeAddressSelector/useAddressSelector.js +127 -0
- package/dist/b2b/SeAddressSelector/useAddressSelector.js.map +1 -0
- package/dist/b2b/SeCategoryBanners/index.d.ts +2 -0
- package/dist/b2b/SeCategoryBanners/index.d.ts.map +1 -0
- package/dist/b2b/SeCategoryBanners/index.js +18 -0
- package/dist/b2b/SeCategoryBanners/index.js.map +1 -0
- package/dist/b2b/SeCategoryBanners/types.d.ts +9 -0
- package/dist/b2b/SeCategoryBanners/types.d.ts.map +1 -0
- package/dist/b2b/SeCategoryBanners/types.js +3 -0
- package/dist/b2b/SeCategoryBanners/types.js.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/checkStockAndPricingUtils.d.ts +114 -0
- package/dist/b2b/SeCheckStockAndPricing/checkStockAndPricingUtils.d.ts.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/checkStockAndPricingUtils.js +85 -0
- package/dist/b2b/SeCheckStockAndPricing/checkStockAndPricingUtils.js.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/index.d.ts +4 -0
- package/dist/b2b/SeCheckStockAndPricing/index.d.ts.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/index.js +20 -0
- package/dist/b2b/SeCheckStockAndPricing/index.js.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/stockCsv.d.ts +22 -0
- package/dist/b2b/SeCheckStockAndPricing/stockCsv.d.ts.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/stockCsv.js +79 -0
- package/dist/b2b/SeCheckStockAndPricing/stockCsv.js.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/useCheckStockAndPricing.d.ts +54 -0
- package/dist/b2b/SeCheckStockAndPricing/useCheckStockAndPricing.d.ts.map +1 -0
- package/dist/b2b/SeCheckStockAndPricing/useCheckStockAndPricing.js +209 -0
- package/dist/b2b/SeCheckStockAndPricing/useCheckStockAndPricing.js.map +1 -0
- package/dist/b2b/SeCustomCrossSellingShelf/index.d.ts +2 -0
- package/dist/b2b/SeCustomCrossSellingShelf/index.d.ts.map +1 -0
- package/dist/b2b/SeCustomCrossSellingShelf/index.js +18 -0
- package/dist/b2b/SeCustomCrossSellingShelf/index.js.map +1 -0
- package/dist/b2b/SeCustomCrossSellingShelf/useCrossSellingShelfOverride.d.ts +19 -0
- package/dist/b2b/SeCustomCrossSellingShelf/useCrossSellingShelfOverride.d.ts.map +1 -0
- package/dist/b2b/SeCustomCrossSellingShelf/useCrossSellingShelfOverride.js +21 -0
- package/dist/b2b/SeCustomCrossSellingShelf/useCrossSellingShelfOverride.js.map +1 -0
- package/dist/b2b/SeCustomProductCard/index.d.ts +3 -0
- package/dist/b2b/SeCustomProductCard/index.d.ts.map +1 -0
- package/dist/b2b/SeCustomProductCard/index.js +19 -0
- package/dist/b2b/SeCustomProductCard/index.js.map +1 -0
- package/dist/b2b/SeCustomProductCard/types.d.ts +30 -0
- package/dist/b2b/SeCustomProductCard/types.d.ts.map +1 -0
- package/dist/b2b/SeCustomProductCard/types.js +3 -0
- package/dist/b2b/SeCustomProductCard/types.js.map +1 -0
- package/dist/b2b/SeCustomProductCard/useB2bProductCard.d.ts +21 -0
- package/dist/b2b/SeCustomProductCard/useB2bProductCard.d.ts.map +1 -0
- package/dist/b2b/SeCustomProductCard/useB2bProductCard.js +33 -0
- package/dist/b2b/SeCustomProductCard/useB2bProductCard.js.map +1 -0
- package/dist/b2b/SeCustomShelfProduct/index.d.ts +3 -0
- package/dist/b2b/SeCustomShelfProduct/index.d.ts.map +1 -0
- package/dist/b2b/SeCustomShelfProduct/index.js +19 -0
- package/dist/b2b/SeCustomShelfProduct/index.js.map +1 -0
- package/dist/b2b/SeCustomShelfProduct/types.d.ts +6 -0
- package/dist/b2b/SeCustomShelfProduct/types.d.ts.map +1 -0
- package/dist/b2b/SeCustomShelfProduct/types.js +3 -0
- package/dist/b2b/SeCustomShelfProduct/types.js.map +1 -0
- package/dist/b2b/SeCustomShelfProduct/useB2bShelfProducts.d.ts +15 -0
- package/dist/b2b/SeCustomShelfProduct/useB2bShelfProducts.d.ts.map +1 -0
- package/dist/b2b/SeCustomShelfProduct/useB2bShelfProducts.js +19 -0
- package/dist/b2b/SeCustomShelfProduct/useB2bShelfProducts.js.map +1 -0
- package/dist/b2b/SeDashboards/index.d.ts +2 -0
- package/dist/b2b/SeDashboards/index.d.ts.map +1 -0
- package/dist/b2b/SeDashboards/index.js +18 -0
- package/dist/b2b/SeDashboards/index.js.map +1 -0
- package/dist/b2b/SeDashboards/useDashboards.d.ts +51 -0
- package/dist/b2b/SeDashboards/useDashboards.d.ts.map +1 -0
- package/dist/b2b/SeDashboards/useDashboards.js +172 -0
- package/dist/b2b/SeDashboards/useDashboards.js.map +1 -0
- package/dist/b2b/SeFooterB2B/index.d.ts +3 -0
- package/dist/b2b/SeFooterB2B/index.d.ts.map +1 -0
- package/dist/b2b/SeFooterB2B/index.js +19 -0
- package/dist/b2b/SeFooterB2B/index.js.map +1 -0
- package/dist/b2b/SeFooterB2B/types.d.ts +39 -0
- package/dist/b2b/SeFooterB2B/types.d.ts.map +1 -0
- package/dist/b2b/SeFooterB2B/types.js +3 -0
- package/dist/b2b/SeFooterB2B/types.js.map +1 -0
- package/dist/b2b/SeFooterB2B/useNewsletterSubscription.d.ts +16 -0
- package/dist/b2b/SeFooterB2B/useNewsletterSubscription.d.ts.map +1 -0
- package/dist/b2b/SeFooterB2B/useNewsletterSubscription.js +34 -0
- package/dist/b2b/SeFooterB2B/useNewsletterSubscription.js.map +1 -0
- package/dist/b2b/SeProductGalleryB2B/index.d.ts +2 -0
- package/dist/b2b/SeProductGalleryB2B/index.d.ts.map +1 -0
- package/dist/b2b/SeProductGalleryB2B/index.js +18 -0
- package/dist/b2b/SeProductGalleryB2B/index.js.map +1 -0
- package/dist/b2b/SeProductGalleryB2B/useProductGalleryB2B.d.ts +123 -0
- package/dist/b2b/SeProductGalleryB2B/useProductGalleryB2B.d.ts.map +1 -0
- package/dist/b2b/SeProductGalleryB2B/useProductGalleryB2B.js +159 -0
- package/dist/b2b/SeProductGalleryB2B/useProductGalleryB2B.js.map +1 -0
- package/dist/b2b/SePurchaseLists/index.d.ts +3 -0
- package/dist/b2b/SePurchaseLists/index.d.ts.map +1 -0
- package/dist/b2b/SePurchaseLists/index.js +19 -0
- package/dist/b2b/SePurchaseLists/index.js.map +1 -0
- package/dist/b2b/SePurchaseLists/purchaseListsUtils.d.ts +103 -0
- package/dist/b2b/SePurchaseLists/purchaseListsUtils.d.ts.map +1 -0
- package/dist/b2b/SePurchaseLists/purchaseListsUtils.js +69 -0
- package/dist/b2b/SePurchaseLists/purchaseListsUtils.js.map +1 -0
- package/dist/b2b/SePurchaseLists/usePurchaseLists.d.ts +57 -0
- package/dist/b2b/SePurchaseLists/usePurchaseLists.d.ts.map +1 -0
- package/dist/b2b/SePurchaseLists/usePurchaseLists.js +292 -0
- package/dist/b2b/SePurchaseLists/usePurchaseLists.js.map +1 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/index.d.ts +3 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/index.d.ts.map +1 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/index.js +19 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/index.js.map +1 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/recentOrdersSpendOverviewUtils.d.ts +58 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/recentOrdersSpendOverviewUtils.d.ts.map +1 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/recentOrdersSpendOverviewUtils.js +133 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/recentOrdersSpendOverviewUtils.js.map +1 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/useRecentOrdersSpendOverview.d.ts +21 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/useRecentOrdersSpendOverview.d.ts.map +1 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/useRecentOrdersSpendOverview.js +134 -0
- package/dist/b2b/SeRecentOrdersSpendOverview/useRecentOrdersSpendOverview.js.map +1 -0
- package/dist/b2b/SeRequestToBuy/index.d.ts +2 -0
- package/dist/b2b/SeRequestToBuy/index.d.ts.map +1 -0
- package/dist/b2b/SeRequestToBuy/index.js +18 -0
- package/dist/b2b/SeRequestToBuy/index.js.map +1 -0
- package/dist/b2b/SeRequestToBuy/useRequestToBuyForm.d.ts +23 -0
- package/dist/b2b/SeRequestToBuy/useRequestToBuyForm.d.ts.map +1 -0
- package/dist/b2b/SeRequestToBuy/useRequestToBuyForm.js +64 -0
- package/dist/b2b/SeRequestToBuy/useRequestToBuyForm.js.map +1 -0
- package/dist/b2b/SeWelcomeBackMessage/index.d.ts +2 -0
- package/dist/b2b/SeWelcomeBackMessage/index.d.ts.map +1 -0
- package/dist/b2b/SeWelcomeBackMessage/index.js +18 -0
- package/dist/b2b/SeWelcomeBackMessage/index.js.map +1 -0
- package/dist/b2b/SeWelcomeBackMessage/useB2bSession.d.ts +11 -0
- package/dist/b2b/SeWelcomeBackMessage/useB2bSession.d.ts.map +1 -0
- package/dist/b2b/SeWelcomeBackMessage/useB2bSession.js +15 -0
- package/dist/b2b/SeWelcomeBackMessage/useB2bSession.js.map +1 -0
- package/dist/b2b/index.d.ts +15 -0
- package/dist/b2b/index.d.ts.map +1 -0
- package/dist/b2b/index.js +31 -0
- package/dist/b2b/index.js.map +1 -0
- package/dist/b2c/SeAssemblySet/assemblySetUtils.d.ts +41 -0
- package/dist/b2c/SeAssemblySet/assemblySetUtils.d.ts.map +1 -0
- package/dist/b2c/SeAssemblySet/assemblySetUtils.js +57 -0
- package/dist/b2c/SeAssemblySet/assemblySetUtils.js.map +1 -0
- package/dist/b2c/SeAssemblySet/index.d.ts +4 -0
- package/dist/b2c/SeAssemblySet/index.d.ts.map +1 -0
- package/dist/b2c/SeAssemblySet/index.js +20 -0
- package/dist/b2c/SeAssemblySet/index.js.map +1 -0
- package/dist/b2c/SeAssemblySet/types.d.ts +52 -0
- package/dist/b2c/SeAssemblySet/types.d.ts.map +1 -0
- package/dist/b2c/SeAssemblySet/types.js +3 -0
- package/dist/b2c/SeAssemblySet/types.js.map +1 -0
- package/dist/b2c/SeAssemblySet/useAssemblySet.d.ts +38 -0
- package/dist/b2c/SeAssemblySet/useAssemblySet.d.ts.map +1 -0
- package/dist/b2c/SeAssemblySet/useAssemblySet.js +134 -0
- package/dist/b2c/SeAssemblySet/useAssemblySet.js.map +1 -0
- package/dist/b2c/SeBanner/buildResponsiveImage.d.ts +18 -0
- package/dist/b2c/SeBanner/buildResponsiveImage.d.ts.map +1 -0
- package/dist/b2c/SeBanner/buildResponsiveImage.js +32 -0
- package/dist/b2c/SeBanner/buildResponsiveImage.js.map +1 -0
- package/dist/b2c/SeBanner/getImageUrl.d.ts +3 -0
- package/dist/b2c/SeBanner/getImageUrl.d.ts.map +1 -0
- package/dist/b2c/SeBanner/getImageUrl.js +7 -0
- package/dist/b2c/SeBanner/getImageUrl.js.map +1 -0
- package/dist/b2c/SeBanner/index.d.ts +8 -0
- package/dist/b2c/SeBanner/index.d.ts.map +1 -0
- package/dist/b2c/SeBanner/index.js +24 -0
- package/dist/b2c/SeBanner/index.js.map +1 -0
- package/dist/b2c/SeBanner/types.d.ts +34 -0
- package/dist/b2c/SeBanner/types.d.ts.map +1 -0
- package/dist/b2c/SeBanner/types.js +27 -0
- package/dist/b2c/SeBanner/types.js.map +1 -0
- package/dist/b2c/SeBanner/useBannerContext.d.ts +4 -0
- package/dist/b2c/SeBanner/useBannerContext.d.ts.map +1 -0
- package/dist/b2c/SeBanner/useBannerContext.js +14 -0
- package/dist/b2c/SeBanner/useBannerContext.js.map +1 -0
- package/dist/b2c/SeBanner/useBannerStyles.d.ts +21 -0
- package/dist/b2c/SeBanner/useBannerStyles.d.ts.map +1 -0
- package/dist/b2c/SeBanner/useBannerStyles.js +87 -0
- package/dist/b2c/SeBanner/useBannerStyles.js.map +1 -0
- package/dist/b2c/SeBanner/useIsMobile.d.ts +4 -0
- package/dist/b2c/SeBanner/useIsMobile.d.ts.map +1 -0
- package/dist/b2c/SeBanner/useIsMobile.js +23 -0
- package/dist/b2c/SeBanner/useIsMobile.js.map +1 -0
- package/dist/b2c/SeBanner/useSanitizedHtml.d.ts +13 -0
- package/dist/b2c/SeBanner/useSanitizedHtml.d.ts.map +1 -0
- package/dist/b2c/SeBanner/useSanitizedHtml.js +45 -0
- package/dist/b2c/SeBanner/useSanitizedHtml.js.map +1 -0
- package/dist/b2c/SeBannerCarousel/index.d.ts +5 -0
- package/dist/b2c/SeBannerCarousel/index.d.ts.map +1 -0
- package/dist/b2c/SeBannerCarousel/index.js +21 -0
- package/dist/b2c/SeBannerCarousel/index.js.map +1 -0
- package/dist/b2c/SeBannerCarousel/types.d.ts +17 -0
- package/dist/b2c/SeBannerCarousel/types.d.ts.map +1 -0
- package/dist/b2c/SeBannerCarousel/types.js +3 -0
- package/dist/b2c/SeBannerCarousel/types.js.map +1 -0
- package/dist/b2c/SeBannerCarousel/useCarousel.d.ts +30 -0
- package/dist/b2c/SeBannerCarousel/useCarousel.d.ts.map +1 -0
- package/dist/b2c/SeBannerCarousel/useCarousel.js +53 -0
- package/dist/b2c/SeBannerCarousel/useCarousel.js.map +1 -0
- package/dist/b2c/SeBannerCarousel/useCarouselContext.d.ts +4 -0
- package/dist/b2c/SeBannerCarousel/useCarouselContext.d.ts.map +1 -0
- package/dist/b2c/SeBannerCarousel/useCarouselContext.js +14 -0
- package/dist/b2c/SeBannerCarousel/useCarouselContext.js.map +1 -0
- package/dist/b2c/SeBannerCarousel/useSwipeNavigation.d.ts +19 -0
- package/dist/b2c/SeBannerCarousel/useSwipeNavigation.d.ts.map +1 -0
- package/dist/b2c/SeBannerCarousel/useSwipeNavigation.js +37 -0
- package/dist/b2c/SeBannerCarousel/useSwipeNavigation.js.map +1 -0
- package/dist/b2c/SeCardsCarousel/index.d.ts +3 -0
- package/dist/b2c/SeCardsCarousel/index.d.ts.map +1 -0
- package/dist/b2c/SeCardsCarousel/index.js +19 -0
- package/dist/b2c/SeCardsCarousel/index.js.map +1 -0
- package/dist/b2c/SeCardsCarousel/types.d.ts +8 -0
- package/dist/b2c/SeCardsCarousel/types.d.ts.map +1 -0
- package/dist/b2c/SeCardsCarousel/types.js +3 -0
- package/dist/b2c/SeCardsCarousel/types.js.map +1 -0
- package/dist/b2c/SeCardsCarousel/useCardsCarouselLayout.d.ts +10 -0
- package/dist/b2c/SeCardsCarousel/useCardsCarouselLayout.d.ts.map +1 -0
- package/dist/b2c/SeCardsCarousel/useCardsCarouselLayout.js +13 -0
- package/dist/b2c/SeCardsCarousel/useCardsCarouselLayout.js.map +1 -0
- package/dist/b2c/SeEditorialSplit/index.d.ts +2 -0
- package/dist/b2c/SeEditorialSplit/index.d.ts.map +1 -0
- package/dist/b2c/SeEditorialSplit/index.js +18 -0
- package/dist/b2c/SeEditorialSplit/index.js.map +1 -0
- package/dist/b2c/SeEditorialSplit/types.d.ts +13 -0
- package/dist/b2c/SeEditorialSplit/types.d.ts.map +1 -0
- package/dist/b2c/SeEditorialSplit/types.js +3 -0
- package/dist/b2c/SeEditorialSplit/types.js.map +1 -0
- package/dist/b2c/SeFooter/index.d.ts +3 -0
- package/dist/b2c/SeFooter/index.d.ts.map +1 -0
- package/dist/b2c/SeFooter/index.js +19 -0
- package/dist/b2c/SeFooter/index.js.map +1 -0
- package/dist/b2c/SeFooter/types.d.ts +52 -0
- package/dist/b2c/SeFooter/types.d.ts.map +1 -0
- package/dist/b2c/SeFooter/types.js +3 -0
- package/dist/b2c/SeFooter/types.js.map +1 -0
- package/dist/b2c/SeFooter/utils.d.ts +6 -0
- package/dist/b2c/SeFooter/utils.d.ts.map +1 -0
- package/dist/b2c/SeFooter/utils.js +11 -0
- package/dist/b2c/SeFooter/utils.js.map +1 -0
- package/dist/b2c/SeGridContent/index.d.ts +2 -0
- package/dist/b2c/SeGridContent/index.d.ts.map +1 -0
- package/dist/b2c/SeGridContent/index.js +18 -0
- package/dist/b2c/SeGridContent/index.js.map +1 -0
- package/dist/b2c/SeGridContent/types.d.ts +20 -0
- package/dist/b2c/SeGridContent/types.d.ts.map +1 -0
- package/dist/b2c/SeGridContent/types.js +3 -0
- package/dist/b2c/SeGridContent/types.js.map +1 -0
- package/dist/b2c/SeHeader/index.d.ts +2 -0
- package/dist/b2c/SeHeader/index.d.ts.map +1 -0
- package/dist/b2c/SeHeader/index.js +18 -0
- package/dist/b2c/SeHeader/index.js.map +1 -0
- package/dist/b2c/SeHeader/types.d.ts +35 -0
- package/dist/b2c/SeHeader/types.d.ts.map +1 -0
- package/dist/b2c/SeHeader/types.js +3 -0
- package/dist/b2c/SeHeader/types.js.map +1 -0
- package/dist/b2c/SeHeroSection/index.d.ts +2 -0
- package/dist/b2c/SeHeroSection/index.d.ts.map +1 -0
- package/dist/b2c/SeHeroSection/index.js +18 -0
- package/dist/b2c/SeHeroSection/index.js.map +1 -0
- package/dist/b2c/SeHeroSection/types.d.ts +10 -0
- package/dist/b2c/SeHeroSection/types.d.ts.map +1 -0
- package/dist/b2c/SeHeroSection/types.js +3 -0
- package/dist/b2c/SeHeroSection/types.js.map +1 -0
- package/dist/b2c/SeImageTiles/index.d.ts +2 -0
- package/dist/b2c/SeImageTiles/index.d.ts.map +1 -0
- package/dist/b2c/SeImageTiles/index.js +18 -0
- package/dist/b2c/SeImageTiles/index.js.map +1 -0
- package/dist/b2c/SeImageTiles/types.d.ts +13 -0
- package/dist/b2c/SeImageTiles/types.d.ts.map +1 -0
- package/dist/b2c/SeImageTiles/types.js +3 -0
- package/dist/b2c/SeImageTiles/types.js.map +1 -0
- package/dist/b2c/SeLearnMoreSection/index.d.ts +2 -0
- package/dist/b2c/SeLearnMoreSection/index.d.ts.map +1 -0
- package/dist/b2c/SeLearnMoreSection/index.js +18 -0
- package/dist/b2c/SeLearnMoreSection/index.js.map +1 -0
- package/dist/b2c/SeLearnMoreSection/types.d.ts +10 -0
- package/dist/b2c/SeLearnMoreSection/types.d.ts.map +1 -0
- package/dist/b2c/SeLearnMoreSection/types.js +3 -0
- package/dist/b2c/SeLearnMoreSection/types.js.map +1 -0
- package/dist/b2c/SeMegaMenu/index.d.ts +6 -0
- package/dist/b2c/SeMegaMenu/index.d.ts.map +1 -0
- package/dist/b2c/SeMegaMenu/index.js +22 -0
- package/dist/b2c/SeMegaMenu/index.js.map +1 -0
- package/dist/b2c/SeMegaMenu/types.d.ts +27 -0
- package/dist/b2c/SeMegaMenu/types.d.ts.map +1 -0
- package/dist/b2c/SeMegaMenu/types.js +3 -0
- package/dist/b2c/SeMegaMenu/types.js.map +1 -0
- package/dist/b2c/SeMegaMenu/useCloseMenuOnEscape.d.ts +6 -0
- package/dist/b2c/SeMegaMenu/useCloseMenuOnEscape.d.ts.map +1 -0
- package/dist/b2c/SeMegaMenu/useCloseMenuOnEscape.js +21 -0
- package/dist/b2c/SeMegaMenu/useCloseMenuOnEscape.js.map +1 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuHoverState.d.ts +15 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuHoverState.d.ts.map +1 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuHoverState.js +21 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuHoverState.js.map +1 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuMobileNavigation.d.ts +29 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuMobileNavigation.d.ts.map +1 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuMobileNavigation.js +71 -0
- package/dist/b2c/SeMegaMenu/useMegaMenuMobileNavigation.js.map +1 -0
- package/dist/b2c/SeMegaMenu/useNavbarHamburgerTrigger.d.ts +12 -0
- package/dist/b2c/SeMegaMenu/useNavbarHamburgerTrigger.d.ts.map +1 -0
- package/dist/b2c/SeMegaMenu/useNavbarHamburgerTrigger.js +29 -0
- package/dist/b2c/SeMegaMenu/useNavbarHamburgerTrigger.js.map +1 -0
- package/dist/b2c/SeProductCardWithButton/index.d.ts +3 -0
- package/dist/b2c/SeProductCardWithButton/index.d.ts.map +1 -0
- package/dist/b2c/SeProductCardWithButton/index.js +19 -0
- package/dist/b2c/SeProductCardWithButton/index.js.map +1 -0
- package/dist/b2c/SeProductCardWithButton/types.d.ts +20 -0
- package/dist/b2c/SeProductCardWithButton/types.d.ts.map +1 -0
- package/dist/b2c/SeProductCardWithButton/types.js +3 -0
- package/dist/b2c/SeProductCardWithButton/types.js.map +1 -0
- package/dist/b2c/SeProductCardWithButton/useFormattedPrice.d.ts +13 -0
- package/dist/b2c/SeProductCardWithButton/useFormattedPrice.d.ts.map +1 -0
- package/dist/b2c/SeProductCardWithButton/useFormattedPrice.js +25 -0
- package/dist/b2c/SeProductCardWithButton/useFormattedPrice.js.map +1 -0
- package/dist/b2c/SeProductImageGrid/index.d.ts +2 -0
- package/dist/b2c/SeProductImageGrid/index.d.ts.map +1 -0
- package/dist/b2c/SeProductImageGrid/index.js +18 -0
- package/dist/b2c/SeProductImageGrid/index.js.map +1 -0
- package/dist/b2c/SeProductImageGrid/types.d.ts +15 -0
- package/dist/b2c/SeProductImageGrid/types.d.ts.map +1 -0
- package/dist/b2c/SeProductImageGrid/types.js +3 -0
- package/dist/b2c/SeProductImageGrid/types.js.map +1 -0
- package/dist/b2c/SeProductListing/index.d.ts +3 -0
- package/dist/b2c/SeProductListing/index.d.ts.map +1 -0
- package/dist/b2c/SeProductListing/index.js +19 -0
- package/dist/b2c/SeProductListing/index.js.map +1 -0
- package/dist/b2c/SeProductListing/types.d.ts +40 -0
- package/dist/b2c/SeProductListing/types.d.ts.map +1 -0
- package/dist/b2c/SeProductListing/types.js +3 -0
- package/dist/b2c/SeProductListing/types.js.map +1 -0
- package/dist/b2c/SeProductListing/useSeProductListing.d.ts +8 -0
- package/dist/b2c/SeProductListing/useSeProductListing.d.ts.map +1 -0
- package/dist/b2c/SeProductListing/useSeProductListing.js +27 -0
- package/dist/b2c/SeProductListing/useSeProductListing.js.map +1 -0
- package/dist/b2c/SeProductReviews/index.d.ts +3 -0
- package/dist/b2c/SeProductReviews/index.d.ts.map +1 -0
- package/dist/b2c/SeProductReviews/index.js +19 -0
- package/dist/b2c/SeProductReviews/index.js.map +1 -0
- package/dist/b2c/SeProductReviews/types.d.ts +30 -0
- package/dist/b2c/SeProductReviews/types.d.ts.map +1 -0
- package/dist/b2c/SeProductReviews/types.js +3 -0
- package/dist/b2c/SeProductReviews/types.js.map +1 -0
- package/dist/b2c/SeProductReviews/useSeProductReviews.d.ts +9 -0
- package/dist/b2c/SeProductReviews/useSeProductReviews.d.ts.map +1 -0
- package/dist/b2c/SeProductReviews/useSeProductReviews.js +34 -0
- package/dist/b2c/SeProductReviews/useSeProductReviews.js.map +1 -0
- package/dist/b2c/SeValuePropCards/index.d.ts +3 -0
- package/dist/b2c/SeValuePropCards/index.d.ts.map +1 -0
- package/dist/b2c/SeValuePropCards/index.js +19 -0
- package/dist/b2c/SeValuePropCards/index.js.map +1 -0
- package/dist/b2c/SeValuePropCards/types.d.ts +26 -0
- package/dist/b2c/SeValuePropCards/types.d.ts.map +1 -0
- package/dist/b2c/SeValuePropCards/types.js +3 -0
- package/dist/b2c/SeValuePropCards/types.js.map +1 -0
- package/dist/b2c/SeValuePropCards/useSeValuePropCardsFilter.d.ts +8 -0
- package/dist/b2c/SeValuePropCards/useSeValuePropCardsFilter.d.ts.map +1 -0
- package/dist/b2c/SeValuePropCards/useSeValuePropCardsFilter.js +36 -0
- package/dist/b2c/SeValuePropCards/useSeValuePropCardsFilter.js.map +1 -0
- package/dist/b2c/SeVideoHero/index.d.ts +4 -0
- package/dist/b2c/SeVideoHero/index.d.ts.map +1 -0
- package/dist/b2c/SeVideoHero/index.js +20 -0
- package/dist/b2c/SeVideoHero/index.js.map +1 -0
- package/dist/b2c/SeVideoHero/types.d.ts +19 -0
- package/dist/b2c/SeVideoHero/types.d.ts.map +1 -0
- package/dist/b2c/SeVideoHero/types.js +3 -0
- package/dist/b2c/SeVideoHero/types.js.map +1 -0
- package/dist/b2c/SeVideoHero/useSeVideoHeroPlayback.d.ts +40 -0
- package/dist/b2c/SeVideoHero/useSeVideoHeroPlayback.d.ts.map +1 -0
- package/dist/b2c/SeVideoHero/useSeVideoHeroPlayback.js +135 -0
- package/dist/b2c/SeVideoHero/useSeVideoHeroPlayback.js.map +1 -0
- package/dist/b2c/SeVideoHero/videoSource.d.ts +25 -0
- package/dist/b2c/SeVideoHero/videoSource.d.ts.map +1 -0
- package/dist/b2c/SeVideoHero/videoSource.js +78 -0
- package/dist/b2c/SeVideoHero/videoSource.js.map +1 -0
- package/dist/b2c/index.d.ts +19 -0
- package/dist/b2c/index.d.ts.map +1 -0
- package/dist/b2c/index.js +35 -0
- package/dist/b2c/index.js.map +1 -0
- package/dist/b2c/shared/filterItemsWithImage.d.ts +8 -0
- package/dist/b2c/shared/filterItemsWithImage.d.ts.map +1 -0
- package/dist/b2c/shared/filterItemsWithImage.js +11 -0
- package/dist/b2c/shared/filterItemsWithImage.js.map +1 -0
- package/dist/b2c/shared/index.d.ts +2 -0
- package/dist/b2c/shared/index.d.ts.map +1 -0
- package/dist/b2c/shared/index.js +18 -0
- package/dist/b2c/shared/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +93 -3
- package/src/b2b/SeActionHubBulletinBoard/index.ts +1 -0
- package/src/b2b/SeActionHubBulletinBoard/types.ts +27 -0
- package/src/b2b/SeAddToPurchaseList/addToPurchaseListUtils.ts +40 -0
- package/src/b2b/SeAddToPurchaseList/index.ts +2 -0
- package/src/b2b/SeAddToPurchaseList/useAddToPurchaseList.ts +130 -0
- package/src/b2b/SeAddressSelector/index.ts +1 -0
- package/src/b2b/SeAddressSelector/useAddressSelector.ts +157 -0
- package/src/b2b/SeCategoryBanners/index.ts +1 -0
- package/src/b2b/SeCategoryBanners/types.ts +8 -0
- package/src/b2b/SeCheckStockAndPricing/checkStockAndPricingUtils.ts +126 -0
- package/src/b2b/SeCheckStockAndPricing/index.ts +3 -0
- package/src/b2b/SeCheckStockAndPricing/stockCsv.ts +77 -0
- package/src/b2b/SeCheckStockAndPricing/useCheckStockAndPricing.ts +272 -0
- package/src/b2b/SeCustomCrossSellingShelf/index.ts +1 -0
- package/src/b2b/SeCustomCrossSellingShelf/useCrossSellingShelfOverride.ts +25 -0
- package/src/b2b/SeCustomProductCard/index.ts +2 -0
- package/src/b2b/SeCustomProductCard/types.ts +16 -0
- package/src/b2b/SeCustomProductCard/useB2bProductCard.ts +53 -0
- package/src/b2b/SeCustomShelfProduct/index.ts +2 -0
- package/src/b2b/SeCustomShelfProduct/types.ts +14 -0
- package/src/b2b/SeCustomShelfProduct/useB2bShelfProducts.ts +31 -0
- package/src/b2b/SeDashboards/index.ts +1 -0
- package/src/b2b/SeDashboards/useDashboards.ts +211 -0
- package/src/b2b/SeFooterB2B/index.ts +2 -0
- package/src/b2b/SeFooterB2B/types.ts +42 -0
- package/src/b2b/SeFooterB2B/useNewsletterSubscription.ts +41 -0
- package/src/b2b/SeProductGalleryB2B/index.ts +1 -0
- package/src/b2b/SeProductGalleryB2B/useProductGalleryB2B.ts +217 -0
- package/src/b2b/SePurchaseLists/index.ts +2 -0
- package/src/b2b/SePurchaseLists/purchaseListsUtils.ts +106 -0
- package/src/b2b/SePurchaseLists/usePurchaseLists.ts +401 -0
- package/src/b2b/SeRecentOrdersSpendOverview/index.ts +2 -0
- package/src/b2b/SeRecentOrdersSpendOverview/recentOrdersSpendOverviewUtils.ts +162 -0
- package/src/b2b/SeRecentOrdersSpendOverview/useRecentOrdersSpendOverview.ts +159 -0
- package/src/b2b/SeRequestToBuy/index.ts +1 -0
- package/src/b2b/SeRequestToBuy/useRequestToBuyForm.ts +96 -0
- package/src/b2b/SeWelcomeBackMessage/index.ts +1 -0
- package/src/b2b/SeWelcomeBackMessage/useB2bSession.ts +16 -0
- package/src/b2b/index.ts +14 -0
- package/src/b2c/SeAssemblySet/assemblySetUtils.ts +67 -0
- package/src/b2c/SeAssemblySet/index.ts +3 -0
- package/src/b2c/SeAssemblySet/types.ts +51 -0
- package/src/b2c/SeAssemblySet/useAssemblySet.ts +198 -0
- package/src/b2c/SeBanner/buildResponsiveImage.ts +44 -0
- package/src/b2c/SeBanner/getImageUrl.ts +9 -0
- package/src/b2c/SeBanner/index.ts +7 -0
- package/src/b2c/SeBanner/types.ts +40 -0
- package/src/b2c/SeBanner/useBannerContext.ts +12 -0
- package/src/b2c/SeBanner/useBannerStyles.ts +120 -0
- package/src/b2c/SeBanner/useIsMobile.ts +24 -0
- package/src/b2c/SeBanner/useSanitizedHtml.ts +49 -0
- package/src/b2c/SeBannerCarousel/index.ts +4 -0
- package/src/b2c/SeBannerCarousel/types.ts +17 -0
- package/src/b2c/SeBannerCarousel/useCarousel.ts +83 -0
- package/src/b2c/SeBannerCarousel/useCarouselContext.ts +12 -0
- package/src/b2c/SeBannerCarousel/useSwipeNavigation.ts +54 -0
- package/src/b2c/SeCardsCarousel/index.ts +2 -0
- package/src/b2c/SeCardsCarousel/types.ts +7 -0
- package/src/b2c/SeCardsCarousel/useCardsCarouselLayout.ts +9 -0
- package/src/b2c/SeEditorialSplit/index.ts +1 -0
- package/src/b2c/SeEditorialSplit/types.ts +15 -0
- package/src/b2c/SeFooter/index.ts +2 -0
- package/src/b2c/SeFooter/types.ts +54 -0
- package/src/b2c/SeFooter/utils.ts +10 -0
- package/src/b2c/SeGridContent/index.ts +1 -0
- package/src/b2c/SeGridContent/types.ts +22 -0
- package/src/b2c/SeHeader/index.ts +1 -0
- package/src/b2c/SeHeader/types.ts +40 -0
- package/src/b2c/SeHeroSection/index.ts +1 -0
- package/src/b2c/SeHeroSection/types.ts +10 -0
- package/src/b2c/SeImageTiles/index.ts +1 -0
- package/src/b2c/SeImageTiles/types.ts +15 -0
- package/src/b2c/SeLearnMoreSection/index.ts +1 -0
- package/src/b2c/SeLearnMoreSection/types.ts +10 -0
- package/src/b2c/SeMegaMenu/index.ts +5 -0
- package/src/b2c/SeMegaMenu/types.ts +31 -0
- package/src/b2c/SeMegaMenu/useCloseMenuOnEscape.ts +18 -0
- package/src/b2c/SeMegaMenu/useMegaMenuHoverState.ts +29 -0
- package/src/b2c/SeMegaMenu/useMegaMenuMobileNavigation.ts +96 -0
- package/src/b2c/SeMegaMenu/useNavbarHamburgerTrigger.ts +29 -0
- package/src/b2c/SeProductCardWithButton/index.ts +2 -0
- package/src/b2c/SeProductCardWithButton/types.ts +21 -0
- package/src/b2c/SeProductCardWithButton/useFormattedPrice.ts +31 -0
- package/src/b2c/SeProductImageGrid/index.ts +1 -0
- package/src/b2c/SeProductImageGrid/types.ts +15 -0
- package/src/b2c/SeProductListing/index.ts +2 -0
- package/src/b2c/SeProductListing/types.ts +44 -0
- package/src/b2c/SeProductListing/useSeProductListing.ts +26 -0
- package/src/b2c/SeProductReviews/index.ts +2 -0
- package/src/b2c/SeProductReviews/types.ts +34 -0
- package/src/b2c/SeProductReviews/useSeProductReviews.ts +52 -0
- package/src/b2c/SeValuePropCards/index.ts +2 -0
- package/src/b2c/SeValuePropCards/types.ts +27 -0
- package/src/b2c/SeValuePropCards/useSeValuePropCardsFilter.ts +44 -0
- package/src/b2c/SeVideoHero/index.ts +3 -0
- package/src/b2c/SeVideoHero/types.ts +22 -0
- package/src/b2c/SeVideoHero/useSeVideoHeroPlayback.ts +159 -0
- package/src/b2c/SeVideoHero/videoSource.ts +88 -0
- package/src/b2c/index.ts +18 -0
- package/src/b2c/shared/filterItemsWithImage.ts +9 -0
- package/src/b2c/shared/index.ts +1 -0
- package/src/global.d.ts +74 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import { gql } from '@faststore/core/api'
|
|
3
|
+
import { useBuyButton_unstable, useLazyQuery_unstable, useSession_unstable } from '@faststore/core/experimental'
|
|
4
|
+
import {
|
|
5
|
+
SE_PURCHASE_LIST_ADD_ITEMS_MUTATION,
|
|
6
|
+
SE_PURCHASE_LIST_CREATE_MUTATION,
|
|
7
|
+
SE_PURCHASE_LIST_DELETE_MUTATION,
|
|
8
|
+
SE_PURCHASE_LIST_PRODUCT_QUERY,
|
|
9
|
+
SE_PURCHASE_LIST_RENAME_MUTATION,
|
|
10
|
+
SE_PURCHASE_LIST_SEARCH_QUERY,
|
|
11
|
+
SE_PURCHASE_LIST_SET_ITEM_QUANTITY_MUTATION,
|
|
12
|
+
SE_PURCHASE_LIST_SET_VISIBILITY_MUTATION,
|
|
13
|
+
SE_PURCHASE_LISTS_QUERY,
|
|
14
|
+
} from '@se-faststore/resolvers/b2b'
|
|
15
|
+
import {
|
|
16
|
+
formatPurchaseListMoney,
|
|
17
|
+
matchPurchaseListSkus,
|
|
18
|
+
purchaseListCartItem,
|
|
19
|
+
type PurchaseList,
|
|
20
|
+
type PurchaseListError,
|
|
21
|
+
type PurchaseListItem,
|
|
22
|
+
type PurchaseListMoney,
|
|
23
|
+
type PurchaseListProduct,
|
|
24
|
+
type PurchaseListSku,
|
|
25
|
+
type PurchaseListVisibility,
|
|
26
|
+
} from './purchaseListsUtils'
|
|
27
|
+
|
|
28
|
+
const PURCHASE_LISTS_QUERY = gql(SE_PURCHASE_LISTS_QUERY)
|
|
29
|
+
const PURCHASE_LIST_CREATE_MUTATION = gql(SE_PURCHASE_LIST_CREATE_MUTATION)
|
|
30
|
+
const PURCHASE_LIST_ADD_ITEMS_MUTATION = gql(SE_PURCHASE_LIST_ADD_ITEMS_MUTATION)
|
|
31
|
+
const PURCHASE_LIST_SET_ITEM_QUANTITY_MUTATION = gql(SE_PURCHASE_LIST_SET_ITEM_QUANTITY_MUTATION)
|
|
32
|
+
const PURCHASE_LIST_RENAME_MUTATION = gql(SE_PURCHASE_LIST_RENAME_MUTATION)
|
|
33
|
+
const PURCHASE_LIST_SET_VISIBILITY_MUTATION = gql(SE_PURCHASE_LIST_SET_VISIBILITY_MUTATION)
|
|
34
|
+
const PURCHASE_LIST_DELETE_MUTATION = gql(SE_PURCHASE_LIST_DELETE_MUTATION)
|
|
35
|
+
const PURCHASE_LIST_PRODUCT_QUERY = gql(SE_PURCHASE_LIST_PRODUCT_QUERY)
|
|
36
|
+
const PURCHASE_LIST_SEARCH_QUERY = gql(SE_PURCHASE_LIST_SEARCH_QUERY)
|
|
37
|
+
|
|
38
|
+
const URL_PARAM = 'list'
|
|
39
|
+
const QUANTITY_SAVE_DELAY = 600
|
|
40
|
+
const PRODUCT_CONCURRENCY = 6
|
|
41
|
+
const SEARCH_RESULTS = 10
|
|
42
|
+
const MIN_SEARCH_LENGTH = 3
|
|
43
|
+
const SEARCH_DEBOUNCE = 300
|
|
44
|
+
|
|
45
|
+
type Result = { ok: boolean; error?: PurchaseListError | null; list?: PurchaseList | null }
|
|
46
|
+
type Session = { person?: { id?: string } | null; locale?: string; currency?: { code?: string } }
|
|
47
|
+
|
|
48
|
+
export type PurchaseListActionResult = { ok: true } | { ok: false; error: PurchaseListError }
|
|
49
|
+
|
|
50
|
+
/** The latest value behind a stable ref (FastStore's lazy `execute` changes every render). */
|
|
51
|
+
function useLatest<T>(value: T) {
|
|
52
|
+
const ref = useRef(value)
|
|
53
|
+
ref.current = value
|
|
54
|
+
return ref
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** One lazy operation whose single root field holds a `SePurchaseListResult`. */
|
|
58
|
+
function useListMutation<V>(query: unknown, field: string) {
|
|
59
|
+
const [execute] = useLazyQuery_unstable<Record<string, Result | null>, V>(query, {} as V)
|
|
60
|
+
const ref = useLatest(execute)
|
|
61
|
+
return useCallback(
|
|
62
|
+
async (variables: V): Promise<Result> => {
|
|
63
|
+
try {
|
|
64
|
+
const response: Record<string, Result | null> | null | undefined = await ref.current(variables)
|
|
65
|
+
return response?.[field] ?? { ok: false, error: 'FAILED' }
|
|
66
|
+
} catch {
|
|
67
|
+
return { ok: false, error: 'FAILED' }
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[ref, field],
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The list id in the page URL (`?list=...`), so a list can be linked to directly. Not the kit's
|
|
76
|
+
* `?id=`: too generic a name to own on a page other code also reads query parameters from.
|
|
77
|
+
*/
|
|
78
|
+
function urlListId(): string | null {
|
|
79
|
+
if (typeof window === 'undefined') return null
|
|
80
|
+
return new URLSearchParams(window.location.search).get(URL_PARAM)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function setUrlListId(id: string | null) {
|
|
84
|
+
if (typeof window === 'undefined') return
|
|
85
|
+
const url = new URL(window.location.href)
|
|
86
|
+
if (id) url.searchParams.set(URL_PARAM, id)
|
|
87
|
+
else url.searchParams.delete(URL_PARAM)
|
|
88
|
+
window.history.replaceState(window.history.state, '', url)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The buyer's purchase lists and every action on them. Each action applies the list the server
|
|
93
|
+
* returns (so what's shown is what's stored); quantity edits are debounced per SKU and saved
|
|
94
|
+
* on their own, with the optimistic value shown meanwhile.
|
|
95
|
+
*/
|
|
96
|
+
export function usePurchaseLists() {
|
|
97
|
+
const session = useSession_unstable() as Session
|
|
98
|
+
const isLoggedIn = Boolean(session?.person)
|
|
99
|
+
const money: PurchaseListMoney = { locale: session?.locale ?? 'en-US', currency: session?.currency?.code ?? 'USD' }
|
|
100
|
+
const [lists, setLists] = useState<PurchaseList[]>([])
|
|
101
|
+
const [state, setState] = useState<'loading' | 'ready' | 'error'>('loading')
|
|
102
|
+
const [selectedId, setSelectedId] = useState<string | null>(null)
|
|
103
|
+
|
|
104
|
+
const [fetchLists] = useLazyQuery_unstable<{ sePurchaseLists?: PurchaseList[] | null }, Record<string, never>>(
|
|
105
|
+
PURCHASE_LISTS_QUERY,
|
|
106
|
+
{},
|
|
107
|
+
)
|
|
108
|
+
const fetchRef = useLatest(fetchLists)
|
|
109
|
+
const createMutation = useListMutation<{ name: string; visibility: PurchaseListVisibility; items?: PurchaseListItem[] }>(
|
|
110
|
+
PURCHASE_LIST_CREATE_MUTATION,
|
|
111
|
+
'sePurchaseListCreate',
|
|
112
|
+
)
|
|
113
|
+
const addItemsMutation = useListMutation<{ documentId: string; items: PurchaseListItem[] }>(
|
|
114
|
+
PURCHASE_LIST_ADD_ITEMS_MUTATION,
|
|
115
|
+
'sePurchaseListAddItems',
|
|
116
|
+
)
|
|
117
|
+
const quantityMutation = useListMutation<{ documentId: string; skuId: string; quantity: number }>(
|
|
118
|
+
PURCHASE_LIST_SET_ITEM_QUANTITY_MUTATION,
|
|
119
|
+
'sePurchaseListSetItemQuantity',
|
|
120
|
+
)
|
|
121
|
+
const renameMutation = useListMutation<{ documentId: string; name: string }>(PURCHASE_LIST_RENAME_MUTATION, 'sePurchaseListRename')
|
|
122
|
+
const visibilityMutation = useListMutation<{ documentId: string; visibility: PurchaseListVisibility }>(
|
|
123
|
+
PURCHASE_LIST_SET_VISIBILITY_MUTATION,
|
|
124
|
+
'sePurchaseListSetVisibility',
|
|
125
|
+
)
|
|
126
|
+
const deleteMutation = useListMutation<{ documentId: string }>(PURCHASE_LIST_DELETE_MUTATION, 'sePurchaseListDelete')
|
|
127
|
+
|
|
128
|
+
const refresh = useCallback(async () => {
|
|
129
|
+
try {
|
|
130
|
+
const response: { sePurchaseLists?: PurchaseList[] | null } | null | undefined = await fetchRef.current({})
|
|
131
|
+
setLists(response?.sePurchaseLists ?? [])
|
|
132
|
+
setState('ready')
|
|
133
|
+
} catch {
|
|
134
|
+
setState('error')
|
|
135
|
+
}
|
|
136
|
+
}, [fetchRef])
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (!isLoggedIn) return
|
|
140
|
+
setSelectedId(urlListId())
|
|
141
|
+
void refresh()
|
|
142
|
+
}, [isLoggedIn, refresh])
|
|
143
|
+
|
|
144
|
+
const select = useCallback((id: string | null) => {
|
|
145
|
+
setSelectedId(id)
|
|
146
|
+
setUrlListId(id)
|
|
147
|
+
}, [])
|
|
148
|
+
|
|
149
|
+
const applyResult = useCallback((result: Result): PurchaseListActionResult => {
|
|
150
|
+
if (!result.ok) return { ok: false, error: result.error ?? 'FAILED' }
|
|
151
|
+
const updated = result.list
|
|
152
|
+
if (updated) {
|
|
153
|
+
setLists((current) =>
|
|
154
|
+
current.some((list) => list.documentId === updated.documentId)
|
|
155
|
+
? current.map((list) => (list.documentId === updated.documentId ? updated : list))
|
|
156
|
+
: [...current, updated],
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
return { ok: true }
|
|
160
|
+
}, [])
|
|
161
|
+
|
|
162
|
+
const create = useCallback(
|
|
163
|
+
async (name: string, visibility: PurchaseListVisibility, items: PurchaseListItem[] = []) => {
|
|
164
|
+
const result = await createMutation({ name, visibility, items })
|
|
165
|
+
const outcome = applyResult(result)
|
|
166
|
+
if (outcome.ok && result.list) select(result.list.documentId)
|
|
167
|
+
return outcome
|
|
168
|
+
},
|
|
169
|
+
[createMutation, applyResult, select],
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
const addItems = useCallback(
|
|
173
|
+
async (documentId: string, items: PurchaseListItem[]) => applyResult(await addItemsMutation({ documentId, items })),
|
|
174
|
+
[addItemsMutation, applyResult],
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
const rename = useCallback(
|
|
178
|
+
async (documentId: string, name: string) => applyResult(await renameMutation({ documentId, name })),
|
|
179
|
+
[renameMutation, applyResult],
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
const setVisibility = useCallback(
|
|
183
|
+
async (documentId: string, visibility: PurchaseListVisibility) =>
|
|
184
|
+
applyResult(await visibilityMutation({ documentId, visibility })),
|
|
185
|
+
[visibilityMutation, applyResult],
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
const remove = useCallback(
|
|
189
|
+
async (documentId: string): Promise<PurchaseListActionResult> => {
|
|
190
|
+
const result = await deleteMutation({ documentId })
|
|
191
|
+
if (!result.ok) return { ok: false, error: result.error ?? 'FAILED' }
|
|
192
|
+
setLists((current) => current.filter((list) => list.documentId !== documentId))
|
|
193
|
+
select(null)
|
|
194
|
+
return { ok: true }
|
|
195
|
+
},
|
|
196
|
+
[deleteMutation, select],
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
// Quantity edits: shown immediately, saved once the buyer stops clicking.
|
|
200
|
+
const timers = useRef(new Map<string, ReturnType<typeof setTimeout>>())
|
|
201
|
+
const [saveError, setSaveError] = useState<PurchaseListError | null>(null)
|
|
202
|
+
const setItemQuantity = useCallback(
|
|
203
|
+
(documentId: string, skuId: string, quantity: number) => {
|
|
204
|
+
const next = Math.max(0, Math.floor(Number.isFinite(quantity) ? quantity : 0))
|
|
205
|
+
setLists((current) =>
|
|
206
|
+
current.map((list) =>
|
|
207
|
+
list.documentId !== documentId
|
|
208
|
+
? list
|
|
209
|
+
: {
|
|
210
|
+
...list,
|
|
211
|
+
items:
|
|
212
|
+
next === 0
|
|
213
|
+
? list.items.filter((item) => item.skuId !== skuId)
|
|
214
|
+
: list.items.map((item) => (item.skuId === skuId ? { ...item, quantity: next } : item)),
|
|
215
|
+
},
|
|
216
|
+
),
|
|
217
|
+
)
|
|
218
|
+
const key = `${documentId}:${skuId}`
|
|
219
|
+
const pendingTimer = timers.current.get(key)
|
|
220
|
+
if (pendingTimer) clearTimeout(pendingTimer)
|
|
221
|
+
timers.current.set(
|
|
222
|
+
key,
|
|
223
|
+
setTimeout(
|
|
224
|
+
async () => {
|
|
225
|
+
timers.current.delete(key)
|
|
226
|
+
const result = await quantityMutation({ documentId, skuId, quantity: next })
|
|
227
|
+
if (!result.ok) {
|
|
228
|
+
setSaveError(result.error ?? 'FAILED')
|
|
229
|
+
void refresh()
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
next === 0 ? 0 : QUANTITY_SAVE_DELAY,
|
|
233
|
+
),
|
|
234
|
+
)
|
|
235
|
+
},
|
|
236
|
+
[quantityMutation, refresh],
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
const pending = timers.current
|
|
241
|
+
return () => pending.forEach((timer) => clearTimeout(timer))
|
|
242
|
+
}, [])
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
isLoggedIn,
|
|
246
|
+
money,
|
|
247
|
+
lists,
|
|
248
|
+
state,
|
|
249
|
+
selected: lists.find((list) => list.documentId === selectedId) ?? null,
|
|
250
|
+
select,
|
|
251
|
+
create,
|
|
252
|
+
addItems,
|
|
253
|
+
rename,
|
|
254
|
+
setVisibility,
|
|
255
|
+
remove,
|
|
256
|
+
setItemQuantity,
|
|
257
|
+
saveError,
|
|
258
|
+
clearSaveError: () => setSaveError(null),
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Runs `task` over `items` with at most `limit` in flight. */
|
|
263
|
+
async function mapWithConcurrency<T, R>(items: T[], limit: number, task: (item: T) => Promise<R>): Promise<R[]> {
|
|
264
|
+
const results: R[] = new Array(items.length)
|
|
265
|
+
let next = 0
|
|
266
|
+
await Promise.all(
|
|
267
|
+
Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
268
|
+
while (next < items.length) {
|
|
269
|
+
const index = next++
|
|
270
|
+
results[index] = await task(items[index] as T)
|
|
271
|
+
}
|
|
272
|
+
}),
|
|
273
|
+
)
|
|
274
|
+
return results
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export type PurchaseListLine = {
|
|
278
|
+
item: PurchaseListItem
|
|
279
|
+
product?: PurchaseListProduct
|
|
280
|
+
sku?: PurchaseListSku
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Product data for every SKU on `list` (looked up once per SKU and kept for the session), the
|
|
285
|
+
* list's lines with it, totals, and one add-to-cart for every line with a price.
|
|
286
|
+
*/
|
|
287
|
+
export function usePurchaseListLines(list: PurchaseList | null, money: PurchaseListMoney) {
|
|
288
|
+
const [catalog, setCatalog] = useState<Record<string, { product: PurchaseListProduct; sku: PurchaseListSku } | null>>({})
|
|
289
|
+
const catalogRef = useLatest(catalog)
|
|
290
|
+
const [fetchProduct] = useLazyQuery_unstable<
|
|
291
|
+
{ product?: PurchaseListProduct | null },
|
|
292
|
+
{ locator: Array<{ key: string; value: string }> }
|
|
293
|
+
>(PURCHASE_LIST_PRODUCT_QUERY, { locator: [] })
|
|
294
|
+
const fetchRef = useLatest(fetchProduct)
|
|
295
|
+
|
|
296
|
+
const skuIds = useMemo(() => (list?.items ?? []).map((item) => item.skuId), [list])
|
|
297
|
+
const missingKey = skuIds.filter((id) => !(id in catalog)).join(',')
|
|
298
|
+
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
const missing = missingKey ? missingKey.split(',') : []
|
|
301
|
+
if (missing.length === 0) return
|
|
302
|
+
let cancelled = false
|
|
303
|
+
|
|
304
|
+
void mapWithConcurrency(missing, PRODUCT_CONCURRENCY, async (skuId) => {
|
|
305
|
+
try {
|
|
306
|
+
const response: { product?: PurchaseListProduct | null } | null | undefined = await fetchRef.current({
|
|
307
|
+
locator: [{ key: 'id', value: skuId }],
|
|
308
|
+
})
|
|
309
|
+
const product = response?.product ?? undefined
|
|
310
|
+
const sku = product?.seSkus?.find((candidate) => candidate.itemId === skuId)
|
|
311
|
+
return [skuId, product && sku ? { product, sku } : null] as const
|
|
312
|
+
} catch {
|
|
313
|
+
return [skuId, null] as const
|
|
314
|
+
}
|
|
315
|
+
}).then((entries) => {
|
|
316
|
+
if (!cancelled) setCatalog((current) => ({ ...current, ...Object.fromEntries(entries) }))
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
return () => {
|
|
320
|
+
cancelled = true
|
|
321
|
+
}
|
|
322
|
+
}, [missingKey, fetchRef])
|
|
323
|
+
|
|
324
|
+
/** Lets a SKU found by search show immediately, without waiting for its own lookup. */
|
|
325
|
+
const remember = useCallback(
|
|
326
|
+
(product: PurchaseListProduct, sku: PurchaseListSku) => {
|
|
327
|
+
if (!catalogRef.current[sku.itemId]) setCatalog((current) => ({ ...current, [sku.itemId]: { product, sku } }))
|
|
328
|
+
},
|
|
329
|
+
[catalogRef],
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
const lines: PurchaseListLine[] = (list?.items ?? []).map((item) => {
|
|
333
|
+
const entry = catalog[item.skuId]
|
|
334
|
+
return { item, product: entry?.product, sku: entry?.sku }
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
const purchasable = lines.filter(
|
|
338
|
+
(line): line is Required<PurchaseListLine> =>
|
|
339
|
+
Boolean(line.product && line.sku && typeof line.sku.price === 'number' && line.sku.sellerId),
|
|
340
|
+
)
|
|
341
|
+
const cartItems = useMemo(
|
|
342
|
+
() => purchasable.map((line) => purchaseListCartItem(line.product, line.sku, line.item.quantity)),
|
|
343
|
+
[purchasable],
|
|
344
|
+
)
|
|
345
|
+
// `as never`: matches the store's generated CartItem shape, built field by field in purchaseListCartItem.
|
|
346
|
+
const buyButton = useBuyButton_unstable(cartItems as never)
|
|
347
|
+
const totalItems = purchasable.reduce((sum, line) => sum + line.item.quantity, 0)
|
|
348
|
+
const totalValue = purchasable.reduce((sum, line) => sum + line.item.quantity * (line.sku.price ?? 0), 0)
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
lines,
|
|
352
|
+
loadingProducts: missingKey !== '',
|
|
353
|
+
remember,
|
|
354
|
+
totalItems,
|
|
355
|
+
total: formatPurchaseListMoney(totalValue, money),
|
|
356
|
+
addAllToCart: buyButton.onClick,
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Debounced reference-code search for adding SKUs to a list (three characters minimum). */
|
|
361
|
+
export function usePurchaseListSearch(term: string) {
|
|
362
|
+
const [results, setResults] = useState<Array<{ product: PurchaseListProduct; sku: PurchaseListSku }>>([])
|
|
363
|
+
const [searching, setSearching] = useState(false)
|
|
364
|
+
const [execute] = useLazyQuery_unstable<
|
|
365
|
+
{ search?: { products?: { edges?: Array<{ node: PurchaseListProduct }> } } | null },
|
|
366
|
+
{ term: string; first: number }
|
|
367
|
+
>(PURCHASE_LIST_SEARCH_QUERY, { term: '', first: SEARCH_RESULTS })
|
|
368
|
+
const executeRef = useLatest(execute)
|
|
369
|
+
|
|
370
|
+
useEffect(() => {
|
|
371
|
+
const trimmed = term.trim()
|
|
372
|
+
if (trimmed.length < MIN_SEARCH_LENGTH) {
|
|
373
|
+
setResults([])
|
|
374
|
+
setSearching(false)
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
let cancelled = false
|
|
378
|
+
setSearching(true)
|
|
379
|
+
const timer = setTimeout(() => {
|
|
380
|
+
executeRef
|
|
381
|
+
.current({ term: trimmed, first: SEARCH_RESULTS })
|
|
382
|
+
.then((response: { search?: { products?: { edges?: Array<{ node: PurchaseListProduct }> } } | null } | null | undefined) => {
|
|
383
|
+
if (!cancelled) {
|
|
384
|
+
setResults(matchPurchaseListSkus(response?.search?.products?.edges?.map((edge) => edge.node) ?? [], trimmed))
|
|
385
|
+
}
|
|
386
|
+
})
|
|
387
|
+
.catch(() => {
|
|
388
|
+
if (!cancelled) setResults([])
|
|
389
|
+
})
|
|
390
|
+
.finally(() => {
|
|
391
|
+
if (!cancelled) setSearching(false)
|
|
392
|
+
})
|
|
393
|
+
}, SEARCH_DEBOUNCE)
|
|
394
|
+
return () => {
|
|
395
|
+
cancelled = true
|
|
396
|
+
clearTimeout(timer)
|
|
397
|
+
}
|
|
398
|
+
}, [term, executeRef])
|
|
399
|
+
|
|
400
|
+
return { results, searching, minLength: MIN_SEARCH_LENGTH }
|
|
401
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export type RecentOrder = {
|
|
2
|
+
orderId: string
|
|
3
|
+
creationDate: string
|
|
4
|
+
status: string
|
|
5
|
+
/** In cents. */
|
|
6
|
+
totalValue: number
|
|
7
|
+
isAllDelivered: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type MonthlySpend = {
|
|
11
|
+
month: string
|
|
12
|
+
/** In cents. */
|
|
13
|
+
totalValue: number
|
|
14
|
+
totalOrders: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type OrderBadge = 'Processing' | 'Shipped' | 'Delivered' | 'Canceled' | 'Unknown'
|
|
18
|
+
|
|
19
|
+
const STATUS_BADGES: Record<Exclude<OrderBadge, 'Unknown'>, string[]> = {
|
|
20
|
+
Processing: [
|
|
21
|
+
'order-created',
|
|
22
|
+
'order-accepted',
|
|
23
|
+
'payment-approved',
|
|
24
|
+
'ready-for-handling',
|
|
25
|
+
'handling',
|
|
26
|
+
'on-order-completed',
|
|
27
|
+
'on-order-completed-ffm',
|
|
28
|
+
'payment-pending',
|
|
29
|
+
'window-to-change-payment',
|
|
30
|
+
'window-to-change-seller',
|
|
31
|
+
'waiting-for-authorization',
|
|
32
|
+
'waiting-for-fulfillment',
|
|
33
|
+
'waiting-ffmt-authorization',
|
|
34
|
+
'waiting-for-manual-authorization',
|
|
35
|
+
'authorize-fulfillment',
|
|
36
|
+
'window-to-cancel',
|
|
37
|
+
'ready-for-invoicing',
|
|
38
|
+
'invoice',
|
|
39
|
+
'start-handling',
|
|
40
|
+
'request-cancel',
|
|
41
|
+
'cancellation-requested',
|
|
42
|
+
'waiting-for-mkt-authorization',
|
|
43
|
+
'waiting-seller-handling',
|
|
44
|
+
],
|
|
45
|
+
Shipped: ['invoiced'],
|
|
46
|
+
Delivered: ['delivered', 'handover'],
|
|
47
|
+
Canceled: ['canceling', 'canceled'],
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Groups OMS's ~30 workflow statuses into the four a buyer cares about. */
|
|
51
|
+
export function orderBadge(status: string, isAllDelivered: boolean): OrderBadge {
|
|
52
|
+
if (isAllDelivered) return 'Delivered'
|
|
53
|
+
|
|
54
|
+
for (const [badge, statuses] of Object.entries(STATUS_BADGES)) {
|
|
55
|
+
if (statuses.includes(status)) return badge as OrderBadge
|
|
56
|
+
}
|
|
57
|
+
return 'Unknown'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type MoneyFormat = { locale: string; currency: string }
|
|
61
|
+
|
|
62
|
+
/** `cents` as a currency string, e.g. 1234567 → "$12,345.67". */
|
|
63
|
+
export function formatCents(cents: number, { locale, currency }: MoneyFormat): string {
|
|
64
|
+
return (cents / 100).toLocaleString(locale, { style: 'currency', currency, currencyDisplay: 'narrowSymbol' })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `cents` as a short axis label, e.g. 1234567 → "$12.3K". */
|
|
68
|
+
export function formatCentsShort(cents: number, { locale, currency }: MoneyFormat): string {
|
|
69
|
+
const value = cents / 100
|
|
70
|
+
const [divisor, suffix] =
|
|
71
|
+
value >= 1e9 ? [1e9, 'B'] : value >= 1e6 ? [1e6, 'M'] : value >= 1e3 ? [1e3, 'K'] : [1, '']
|
|
72
|
+
const shortened = value / divisor
|
|
73
|
+
const digits = shortened % 1 === 0 ? 0 : 1
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
shortened.toLocaleString(locale, {
|
|
77
|
+
style: 'currency',
|
|
78
|
+
currency,
|
|
79
|
+
currencyDisplay: 'narrowSymbol',
|
|
80
|
+
minimumFractionDigits: digits,
|
|
81
|
+
maximumFractionDigits: digits,
|
|
82
|
+
}) + suffix
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const SPEND_CHART = { width: 600, height: 300, margin: { top: 8, right: 8, bottom: 24, left: 56 } } as const
|
|
87
|
+
|
|
88
|
+
const GRID_LINES = 4
|
|
89
|
+
const BAR_RADIUS = 8
|
|
90
|
+
|
|
91
|
+
function roundedTopBarPath(x: number, y: number, width: number, height: number): string {
|
|
92
|
+
if (height <= 0) return ''
|
|
93
|
+
const r = Math.min(BAR_RADIUS, width / 2, height)
|
|
94
|
+
return (
|
|
95
|
+
`M ${x},${y + height} L ${x},${y + r} Q ${x},${y} ${x + r},${y} ` +
|
|
96
|
+
`L ${x + width - r},${y} Q ${x + width},${y} ${x + width},${y + r} L ${x + width},${y + height} Z`
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type SpendChart = {
|
|
101
|
+
bars: Array<{ key: string; month: string; path: string; labelX: number }>
|
|
102
|
+
gridLines: Array<{ key: number; y: number; label: string }>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** SVG geometry for the monthly spend bar chart, in SPEND_CHART's viewBox coordinates. */
|
|
106
|
+
export function buildSpendChart(months: MonthlySpend[], money: MoneyFormat): SpendChart | null {
|
|
107
|
+
if (months.length === 0) return null
|
|
108
|
+
|
|
109
|
+
const { width, height, margin } = SPEND_CHART
|
|
110
|
+
const plotWidth = width - margin.left - margin.right
|
|
111
|
+
const plotHeight = height - margin.top - margin.bottom
|
|
112
|
+
const maxValue = (Math.max(...months.map((entry) => entry.totalValue)) || 1) * 1.1
|
|
113
|
+
const slotWidth = plotWidth / months.length
|
|
114
|
+
const barWidth = slotWidth * 0.5
|
|
115
|
+
|
|
116
|
+
const bars = months.map((entry, index) => {
|
|
117
|
+
const barHeight = (entry.totalValue / maxValue) * plotHeight
|
|
118
|
+
const x = margin.left + index * slotWidth + (slotWidth - barWidth) / 2
|
|
119
|
+
return {
|
|
120
|
+
key: `${entry.month}-${index}`,
|
|
121
|
+
month: entry.month,
|
|
122
|
+
path: roundedTopBarPath(x, margin.top + plotHeight - barHeight, barWidth, barHeight),
|
|
123
|
+
labelX: x + barWidth / 2,
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const gridLines = Array.from({ length: GRID_LINES + 1 }, (_, i) => ({
|
|
128
|
+
key: i,
|
|
129
|
+
y: margin.top + plotHeight * (1 - i / GRID_LINES),
|
|
130
|
+
label: formatCentsShort(maxValue * (i / GRID_LINES), money),
|
|
131
|
+
}))
|
|
132
|
+
|
|
133
|
+
return { bars, gridLines }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
type CacheEntry<T> = { data: T; timestamp: number; userEmail: string }
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Per-shopper localStorage cache, so every page view doesn't hit OMS (orders) or the
|
|
140
|
+
* spend-overview service. An entry for a different user, an expired entry, or anything
|
|
141
|
+
* unparseable (storage disabled, an older format) is treated as a miss.
|
|
142
|
+
*/
|
|
143
|
+
export function readShopperCache<T>(key: string, userEmail: string, maxAgeMs: number): T | undefined {
|
|
144
|
+
try {
|
|
145
|
+
const raw = window.localStorage.getItem(key)
|
|
146
|
+
if (!raw) return undefined
|
|
147
|
+
const entry = JSON.parse(raw) as CacheEntry<T>
|
|
148
|
+
if (entry.userEmail !== userEmail || Date.now() - entry.timestamp > maxAgeMs) return undefined
|
|
149
|
+
return entry.data
|
|
150
|
+
} catch {
|
|
151
|
+
return undefined
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function writeShopperCache<T>(key: string, userEmail: string, data: T): void {
|
|
156
|
+
try {
|
|
157
|
+
const entry: CacheEntry<T> = { data, timestamp: Date.now(), userEmail }
|
|
158
|
+
window.localStorage.setItem(key, JSON.stringify(entry))
|
|
159
|
+
} catch {
|
|
160
|
+
// Storage full or disabled: the widget still works, it just refetches next time.
|
|
161
|
+
}
|
|
162
|
+
}
|