@evenicanpm/storefront-core 1.0.0-alpha
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/README.md +40 -0
- package/package.json +36 -0
- package/src/api-manager/README.md +38 -0
- package/src/api-manager/api-manager.config.json +12 -0
- package/src/api-manager/datasources/README.md +17 -0
- package/src/api-manager/datasources/d365/d365-address.datasource.ts +141 -0
- package/src/api-manager/datasources/d365/d365-base.datasource.ts +8 -0
- package/src/api-manager/datasources/d365/d365-cart.datasource.ts +374 -0
- package/src/api-manager/datasources/d365/d365-categories.datasource.ts +40 -0
- package/src/api-manager/datasources/d365/d365-order.datasource.ts +69 -0
- package/src/api-manager/datasources/d365/d365-organization.datasource.ts +92 -0
- package/src/api-manager/datasources/d365/d365-product.datasource.ts +272 -0
- package/src/api-manager/datasources/d365/d365-session.datasource.ts +25 -0
- package/src/api-manager/datasources/d365/d365-user.datasource.ts +132 -0
- package/src/api-manager/datasources/d365/d365.datasource.ts +45 -0
- package/src/api-manager/datasources/d365/index.ts +4 -0
- package/src/api-manager/datasources/d365/test-context.ts +30 -0
- package/src/api-manager/datasources/d365/utils/create-search-criteria.ts +17 -0
- package/src/api-manager/datasources/d365/utils/decode-jwt.ts +11 -0
- package/src/api-manager/datasources/d365/utils/get-context-cookie.ts +37 -0
- package/src/api-manager/datasources/d365/utils/parse-object.ts +9 -0
- package/src/api-manager/datasources/d365/utils/product-images-utils.ts +43 -0
- package/src/api-manager/datasources/d365/utils/product-inventory-utils.ts +37 -0
- package/src/api-manager/datasources/e4/e4-address.datasource.ts +107 -0
- package/src/api-manager/datasources/e4/e4-cart.datasource.ts +248 -0
- package/src/api-manager/datasources/e4/e4-order.datasource.ts +43 -0
- package/src/api-manager/datasources/e4/e4-organization.datasource.ts +19 -0
- package/src/api-manager/datasources/e4/e4-product.datasource.ts +157 -0
- package/src/api-manager/datasources/e4/e4-session.datasource.ts +43 -0
- package/src/api-manager/datasources/e4/e4-user.datasource.ts +118 -0
- package/src/api-manager/datasources/e4/e4.datasource.ts +55 -0
- package/src/api-manager/datasources/e4/e4.remaps.ts +331 -0
- package/src/api-manager/datasources/e4/e4.translator.test.ts +202 -0
- package/src/api-manager/datasources/e4/e4.translator.ts +648 -0
- package/src/api-manager/datasources/e4/graphqlRequestSdk.ts +43515 -0
- package/src/api-manager/datasources/e4/utils/unwrap-e4-variants.ts +65 -0
- package/src/api-manager/index.ts +71 -0
- package/src/api-manager/lib/cart-cookie-handler.ts +14 -0
- package/src/api-manager/lib/category-helpers.ts +113 -0
- package/src/api-manager/lib/get-dynamics-context.ts +34 -0
- package/src/api-manager/lib/get-graphql-client.test.ts +106 -0
- package/src/api-manager/lib/get-graphql-client.ts +53 -0
- package/src/api-manager/schemas/README.md +12 -0
- package/src/api-manager/schemas/address.schema.ts +46 -0
- package/src/api-manager/schemas/cart.schema.ts +92 -0
- package/src/api-manager/schemas/d365.schema.ts +7727 -0
- package/src/api-manager/schemas/order.schema.ts +30 -0
- package/src/api-manager/schemas/organization.schema.ts +32 -0
- package/src/api-manager/schemas/product.schema.ts +140 -0
- package/src/api-manager/schemas/session.schema.ts +17 -0
- package/src/api-manager/schemas/user.schema.ts +14 -0
- package/src/api-manager/services/address/mutations/create-address.ts +22 -0
- package/src/api-manager/services/address/mutations/delete-address.ts +21 -0
- package/src/api-manager/services/address/mutations/get-delivery-options.ts +22 -0
- package/src/api-manager/services/address/mutations/update-address.ts +21 -0
- package/src/api-manager/services/address/queries/get-countries.ts +16 -0
- package/src/api-manager/services/address/queries/get-states.ts +16 -0
- package/src/api-manager/services/cart/mutations/add-discount-code.ts +21 -0
- package/src/api-manager/services/cart/mutations/add-to-cart.ts +53 -0
- package/src/api-manager/services/cart/mutations/checkout.ts +11 -0
- package/src/api-manager/services/cart/mutations/delete-cart-line.ts +18 -0
- package/src/api-manager/services/cart/mutations/get-payment-accept-result.ts +20 -0
- package/src/api-manager/services/cart/mutations/remove-cart-line-delivery-mode.ts +24 -0
- package/src/api-manager/services/cart/mutations/remove-discount-code.ts +21 -0
- package/src/api-manager/services/cart/mutations/update-cart-line-delivery-mode.ts +24 -0
- package/src/api-manager/services/cart/mutations/update-cart-lines.ts +21 -0
- package/src/api-manager/services/cart/mutations/update-cart.ts +21 -0
- package/src/api-manager/services/cart/queries/get-cart.ts +12 -0
- package/src/api-manager/services/cart/queries/get-payment-accept-point.ts +18 -0
- package/src/api-manager/services/categories/queries/get-categories.ts +8 -0
- package/src/api-manager/services/create-mutation.ts +65 -0
- package/src/api-manager/services/create-query.ts +305 -0
- package/src/api-manager/services/get-query-client.ts +40 -0
- package/src/api-manager/services/order/queries/get-order-details.ts +17 -0
- package/src/api-manager/services/order/queries/get-orders.ts +14 -0
- package/src/api-manager/services/organization/queries/get-channel-configuration.ts +14 -0
- package/src/api-manager/services/organization/queries/get-stores.ts +17 -0
- package/src/api-manager/services/product/mutations/search-products.ts +23 -0
- package/src/api-manager/services/product/queries/get-product-availability.ts +15 -0
- package/src/api-manager/services/product/queries/get-product-by-id.ts +17 -0
- package/src/api-manager/services/product/queries/get-product-by-ids.ts +14 -0
- package/src/api-manager/services/product/queries/get-product-list.ts +16 -0
- package/src/api-manager/services/product/queries/get-related-products.ts +14 -0
- package/src/api-manager/services/product/queries/search-products.ts +10 -0
- package/src/api-manager/services/product/server/product.server.ts +13 -0
- package/src/api-manager/services/session/mutations/session-init.ts +22 -0
- package/src/api-manager/services/session/mutations/session-logout.ts +18 -0
- package/src/api-manager/services/session/queries/get-session.ts +10 -0
- package/src/api-manager/services/user/mutations/create-wishlist.ts +21 -0
- package/src/api-manager/services/user/mutations/delete-wishlist.ts +17 -0
- package/src/api-manager/services/user/mutations/update-user.ts +18 -0
- package/src/api-manager/services/user/queries/get-user-counts.ts +10 -0
- package/src/api-manager/services/user/queries/get-user.ts +10 -0
- package/src/api-manager/services/user/queries/get-wishlist-details.ts +10 -0
- package/src/api-manager/services/user/queries/get-wishlists.ts +10 -0
- package/src/api-manager/types/Datasource.ts +197 -0
- package/src/auth/auth-options.test.ts +127 -0
- package/src/auth/auth-options.ts +68 -0
- package/src/auth/msal.ts +65 -0
- package/src/auth/next-auth-cookie-manager.ts +86 -0
- package/src/auth/providers/aadb2c-provider.ts +33 -0
- package/src/auth/providers/authentik-provider.ts +24 -0
- package/src/auth/providers/index.ts +9 -0
- package/src/auth/providers/keycloak-provider.ts +22 -0
- package/src/auth/refresh-token-url-keys.ts +6 -0
- package/src/auth/refresh-token.ts +134 -0
- package/src/auth/signout.ts +46 -0
- package/src/auth/types/next-auth.d.ts +38 -0
- package/src/cms/blog.ts +229 -0
- package/src/cms/endpoints.ts +76 -0
- package/src/cms/interfaces/navigation.ts +52 -0
- package/src/cms/interfaces/productData.ts +83 -0
- package/src/cms/pages.ts +149 -0
- package/src/components/Blocks/BlockManager.tsx +67 -0
- package/src/components/Blocks/Components/BrandLogosScroller.tsx +72 -0
- package/src/components/Blocks/Components/CategoryCard.tsx +47 -0
- package/src/components/Blocks/Components/CategoryCarousel/index.tsx +60 -0
- package/src/components/Blocks/Components/FeaturePill.tsx +99 -0
- package/src/components/Blocks/Components/FeaturedCategories.tsx +41 -0
- package/src/components/Blocks/Components/FeaturedProducts.tsx +41 -0
- package/src/components/Blocks/Components/Footer.tsx +77 -0
- package/src/components/Blocks/Components/Hero.tsx +73 -0
- package/src/components/Blocks/Components/HeroCarousel/index.tsx +42 -0
- package/src/components/Blocks/Components/Image.tsx +39 -0
- package/src/components/Blocks/Components/MediaCard.tsx +41 -0
- package/src/components/Blocks/Components/ProductCarousel/index.tsx +82 -0
- package/src/components/Blocks/Components/ProductSectionFullWidth/index.tsx +103 -0
- package/src/components/Blocks/Components/RichText.tsx +19 -0
- package/src/components/Blocks/Components/Seo/index.tsx +48 -0
- package/src/components/Blocks/Components/Services/index.tsx +21 -0
- package/src/components/Blocks/Components/Services/service-card.tsx +70 -0
- package/src/components/Blocks/Components/shared/featured-product-card.tsx +29 -0
- package/src/components/Blocks/Components/shared/product-category-item.tsx +49 -0
- package/src/components/Blocks/Components/shared/product-grid.tsx +48 -0
- package/src/components/Blocks/Components/shared/top-categories-card.tsx +66 -0
- package/src/components/Blocks/Components/shared/top-rating-product-card.tsx +63 -0
- package/src/components/Blocks/Icons/Components/Category.tsx +14 -0
- package/src/components/Blocks/Icons/Components/DottedStar.tsx +40 -0
- package/src/components/Blocks/Icons/Components/FallbackIcon.tsx +33 -0
- package/src/components/Blocks/Icons/Components/GiftBox.tsx +18 -0
- package/src/components/Blocks/Icons/Components/Light.tsx +13 -0
- package/src/components/Blocks/Icons/Components/NewArrival.tsx +18 -0
- package/src/components/Blocks/Icons/Components/RankBadge.tsx +39 -0
- package/src/components/Blocks/Icons/index.ts +32 -0
- package/src/components/Blocks/index.tsx +16 -0
- package/src/components/Blocks/interfaces.ts +240 -0
- package/src/components/BoxShadowCard.tsx +16 -0
- package/src/components/Footer/data/index.ts +32 -0
- package/src/components/Footer/index.tsx +88 -0
- package/src/components/Footer/interfaces.ts +37 -0
- package/src/components/Footer/sections/FooterAppStore.tsx +45 -0
- package/src/components/Footer/sections/FooterContact.tsx +36 -0
- package/src/components/Footer/sections/FooterLinks.tsx +30 -0
- package/src/components/Footer/sections/FooterLogo.tsx +26 -0
- package/src/components/Footer/sections/FooterSocialLinks.tsx +70 -0
- package/src/components/Footer/styles/index.ts +39 -0
- package/src/components/GlobalLoading/index.tsx +102 -0
- package/src/components/ImageWithFallback.tsx +51 -0
- package/src/components/Loading/index.tsx +36 -0
- package/src/components/NavProvider/index.tsx +59 -0
- package/src/components/NavProvider/utils/createLink.ts +15 -0
- package/src/components/Notifications/README.md +15 -0
- package/src/components/Notifications/notification-context.tsx +82 -0
- package/src/components/Notifications/use-notification.ts +12 -0
- package/src/components/README.md +9 -0
- package/src/components/ReactQueryProvider/index.tsx +12 -0
- package/src/components/Shared/Image.tsx +5 -0
- package/src/components/T/index.tsx +15 -0
- package/src/components/_components/BazaarCard.tsx +21 -0
- package/src/components/_components/BazaarImage.tsx +12 -0
- package/src/components/_components/BazaarMenu.tsx +47 -0
- package/src/components/_components/BazaarSwitch.tsx +37 -0
- package/src/components/_components/BazaarTextField.tsx +73 -0
- package/src/components/_components/DropZone.tsx +86 -0
- package/src/components/_components/HoverBox.tsx +22 -0
- package/src/components/_components/LazyImage.tsx +9 -0
- package/src/components/_components/MiniCartClient.tsx +65 -0
- package/src/components/_components/SearchInput.tsx +28 -0
- package/src/components/_components/SnackbarProvider.tsx +32 -0
- package/src/components/_components/Typography.tsx +227 -0
- package/src/components/_components/WhiteButton.tsx +20 -0
- package/src/components/_components/accordion/accordion-header.tsx +43 -0
- package/src/components/_components/accordion/index.ts +1 -0
- package/src/components/_components/bazaar-types.ts +84 -0
- package/src/components/_components/carousel/carousel.tsx +72 -0
- package/src/components/_components/carousel/components/carousel-arrows.tsx +60 -0
- package/src/components/_components/carousel/components/carousel-dots.tsx +21 -0
- package/src/components/_components/carousel/index.ts +3 -0
- package/src/components/_components/carousel/styles/index.ts +93 -0
- package/src/components/_components/carousel-cards/carousel-card-1/carousel-card-1.tsx +64 -0
- package/src/components/_components/carousel-cards/carousel-card-1/index.ts +1 -0
- package/src/components/_components/carousel-cards/carousel-card-1/styles.ts +34 -0
- package/src/components/_components/carousel-cards/carousel-card-2/carousel-card-2.tsx +73 -0
- package/src/components/_components/carousel-cards/carousel-card-2/index.ts +1 -0
- package/src/components/_components/carousel-cards/carousel-card-2/styles.ts +26 -0
- package/src/components/_components/carousel-cards/carousel-card-3/carousel-card-3.tsx +34 -0
- package/src/components/_components/carousel-cards/carousel-card-3/index.ts +1 -0
- package/src/components/_components/carousel-cards/carousel-card-3/styles.ts +28 -0
- package/src/components/_components/carousel-cards/carousel-card-4/carousel-card-4.tsx +76 -0
- package/src/components/_components/carousel-cards/carousel-card-4/index.ts +1 -0
- package/src/components/_components/carousel-cards/carousel-card-4/styles.ts +27 -0
- package/src/components/_components/categories/category-list/category-list.tsx +59 -0
- package/src/components/_components/categories/category-list/index.ts +1 -0
- package/src/components/_components/categories/category-list/styles.ts +29 -0
- package/src/components/_components/categories/category-list/types.ts +4 -0
- package/src/components/_components/categories/category-list-item/category-menu-item.tsx +37 -0
- package/src/components/_components/categories/category-list-item/index.ts +1 -0
- package/src/components/_components/categories/category-list-item/styles.ts +35 -0
- package/src/components/_components/categories/category-menu.tsx +51 -0
- package/src/components/_components/categories/mega-menu/banner.tsx +56 -0
- package/src/components/_components/categories/mega-menu/column-list.tsx +70 -0
- package/src/components/_components/categories/mega-menu/mega-menu-1.tsx +37 -0
- package/src/components/_components/categories/mega-menu/mega-menu-2.tsx +37 -0
- package/src/components/_components/categories/mega-menu/styles.ts +25 -0
- package/src/components/_components/categories/types.ts +16 -0
- package/src/components/_components/category-cards/category-card-1/category-card-1.tsx +21 -0
- package/src/components/_components/category-cards/category-card-1/index.ts +1 -0
- package/src/components/_components/category-cards/category-card-1/styles.ts +37 -0
- package/src/components/_components/countdown/count-box.tsx +16 -0
- package/src/components/_components/countdown/count-down.tsx +24 -0
- package/src/components/_components/countdown/index.tsx +2 -0
- package/src/components/_components/countdown/useCountDown.ts +41 -0
- package/src/components/_components/data-table/index.ts +2 -0
- package/src/components/_components/data-table/table-header.tsx +91 -0
- package/src/components/_components/data-table/table-pagination.tsx +36 -0
- package/src/components/_components/flex-box/flex-between.tsx +14 -0
- package/src/components/_components/flex-box/flex-box.tsx +9 -0
- package/src/components/_components/flex-box/flex-row-center.tsx +9 -0
- package/src/components/_components/flex-box/index.ts +5 -0
- package/src/components/_components/footer/components/about-links.tsx +23 -0
- package/src/components/_components/footer/components/app-store.tsx +38 -0
- package/src/components/_components/footer/components/customer-care-links.tsx +21 -0
- package/src/components/_components/footer/components/logo.tsx +23 -0
- package/src/components/_components/footer/components/social-links.tsx +43 -0
- package/src/components/_components/footer/data/index.ts +54 -0
- package/src/components/_components/footer/footer-1.tsx +62 -0
- package/src/components/_components/footer/footer-2.tsx +57 -0
- package/src/components/_components/footer/footer-3.tsx +53 -0
- package/src/components/_components/footer/footer-4.tsx +71 -0
- package/src/components/_components/footer/index.ts +4 -0
- package/src/components/_components/footer/styles/index.ts +42 -0
- package/src/components/_components/header/components/categories-menu.tsx +23 -0
- package/src/components/_components/header/components/mobile-header.tsx +72 -0
- package/src/components/_components/header/components/user.test.tsx +200 -0
- package/src/components/_components/header/components/user.tsx +205 -0
- package/src/components/_components/header/header.tsx +63 -0
- package/src/components/_components/header/hooks/use-header.ts +13 -0
- package/src/components/_components/header/index.ts +1 -0
- package/src/components/_components/header/sticky-header.tsx +17 -0
- package/src/components/_components/header/styles/index.ts +24 -0
- package/src/components/_components/hooks/useOverflowDetect.ts +34 -0
- package/src/components/_components/hooks/useSettings.ts +16 -0
- package/src/components/_components/icons/cart-bag.tsx +13 -0
- package/src/components/_components/icons/category-outline.tsx +29 -0
- package/src/components/_components/icons/category.tsx +12 -0
- package/src/components/_components/icons/home.tsx +19 -0
- package/src/components/_components/icons/search.tsx +13 -0
- package/src/components/_components/icons/shopping-bag-outlined.tsx +13 -0
- package/src/components/_components/icons/up-down.tsx +21 -0
- package/src/components/_components/icons/user.tsx +13 -0
- package/src/components/_components/icons/user2.tsx +14 -0
- package/src/components/_components/mini-cart/__tests__/cart-item.test.tsx +174 -0
- package/src/components/_components/mini-cart/__tests__/mini-cart.test.tsx +121 -0
- package/src/components/_components/mini-cart/__tests__/test-cart-empty.json +84 -0
- package/src/components/_components/mini-cart/__tests__/test-cart-with-item.json +244 -0
- package/src/components/_components/mini-cart/components/bottom-actions.tsx +27 -0
- package/src/components/_components/mini-cart/components/cart-item.tsx +144 -0
- package/src/components/_components/mini-cart/components/empty-view.tsx +29 -0
- package/src/components/_components/mini-cart/components/top-header.tsx +34 -0
- package/src/components/_components/mini-cart/index.ts +1 -0
- package/src/components/_components/mini-cart/mini-cart.tsx +107 -0
- package/src/components/_components/mobile-navigation/index.ts +3 -0
- package/src/components/_components/mobile-navigation/mobile-navigation-bar.tsx +73 -0
- package/src/components/_components/mobile-navigation/styles/index.ts +63 -0
- package/src/components/_components/nav-link/index.ts +5 -0
- package/src/components/_components/nav-link/nav-link-2.tsx +32 -0
- package/src/components/_components/nav-link/nav-link-3.tsx +67 -0
- package/src/components/_components/nav-link/nav-link.tsx +53 -0
- package/src/components/_components/navbar/categories.tsx +27 -0
- package/src/components/_components/navbar/category-based-menu/category-based-menu.tsx +52 -0
- package/src/components/_components/navbar/category-based-menu/components/categories.tsx +44 -0
- package/src/components/_components/navbar/category-based-menu/components/category-item.tsx +31 -0
- package/src/components/_components/navbar/category-based-menu/components/child-categories.tsx +38 -0
- package/src/components/_components/navbar/category-based-menu/index.ts +1 -0
- package/src/components/_components/navbar/category-based-menu/styles.ts +81 -0
- package/src/components/_components/navbar/category-based-menu/types.ts +18 -0
- package/src/components/_components/navbar/index.ts +1 -0
- package/src/components/_components/navbar/mega-menu/category-list.tsx +29 -0
- package/src/components/_components/navbar/mega-menu/index.ts +1 -0
- package/src/components/_components/navbar/mega-menu/mega-menu.tsx +71 -0
- package/src/components/_components/navbar/mega-menu/styles.ts +43 -0
- package/src/components/_components/navbar/mobile-menu/index.ts +1 -0
- package/src/components/_components/navbar/mobile-menu/mobile-menu.tsx +70 -0
- package/src/components/_components/navbar/mobile-menu/render-levels.test.tsx +71 -0
- package/src/components/_components/navbar/mobile-menu/render-levels.tsx +62 -0
- package/src/components/_components/navbar/nav-list/cms-nav.test.tsx +84 -0
- package/src/components/_components/navbar/nav-list/index.ts +1 -0
- package/src/components/_components/navbar/nav-list/nav-item-child.tsx +66 -0
- package/src/components/_components/navbar/nav-list/nav-list.tsx +119 -0
- package/src/components/_components/navbar/navbar.tsx +43 -0
- package/src/components/_components/navbar/styles.ts +90 -0
- package/src/components/_components/navbar/utils/transform-nav.test.ts +209 -0
- package/src/components/_components/navbar/utils/transform-nav.ts +43 -0
- package/src/components/_components/newsletter/index.ts +1 -0
- package/src/components/_components/newsletter/newsletter.tsx +108 -0
- package/src/components/_components/newsletter/social-icons.tsx +35 -0
- package/src/components/_components/newsletter/styles.ts +65 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/components/link-item.tsx +21 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/components/list-item.tsx +27 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/components/nav-accordion.tsx +36 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/components/render-child.tsx +26 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/grocery-side-nav.tsx +32 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/index.ts +1 -0
- package/src/components/_components/page-sidenav/grocery-side-nav/styles/index.ts +11 -0
- package/src/components/_components/page-sidenav/health-beauty-side-nav/components/list-item.tsx +27 -0
- package/src/components/_components/page-sidenav/health-beauty-side-nav/components/nav-accordion.tsx +44 -0
- package/src/components/_components/page-sidenav/health-beauty-side-nav/components/render-child.tsx +20 -0
- package/src/components/_components/page-sidenav/health-beauty-side-nav/health-beauty-side-nav.tsx +43 -0
- package/src/components/_components/page-sidenav/health-beauty-side-nav/index.ts +1 -0
- package/src/components/_components/page-sidenav/health-beauty-side-nav/styles/index.ts +27 -0
- package/src/components/_components/page-sidenav/side-navbar/components/list-item.tsx +25 -0
- package/src/components/_components/page-sidenav/side-navbar/components/nav-accordion.tsx +46 -0
- package/src/components/_components/page-sidenav/side-navbar/components/render-child.tsx +20 -0
- package/src/components/_components/page-sidenav/side-navbar/index.ts +1 -0
- package/src/components/_components/page-sidenav/side-navbar/side-nav-bar.tsx +77 -0
- package/src/components/_components/page-sidenav/side-navbar/styles/index.ts +73 -0
- package/src/components/_components/page-sidenav/side-navbar-2/components/button-content.tsx +32 -0
- package/src/components/_components/page-sidenav/side-navbar-2/components/sidebar-accordion.tsx +66 -0
- package/src/components/_components/page-sidenav/side-navbar-2/index.ts +1 -0
- package/src/components/_components/page-sidenav/side-navbar-2/side-navbar-2.tsx +63 -0
- package/src/components/_components/page-sidenav/side-navbar-2/styles/index.ts +68 -0
- package/src/components/_components/product-cards/discount-chip.tsx +43 -0
- package/src/components/_components/product-cards/product-card-1/components/hover-actions.tsx +37 -0
- package/src/components/_components/product-cards/product-card-1/components/quantity-buttons.tsx +56 -0
- package/src/components/_components/product-cards/product-card-1/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-1/product-card.tsx +146 -0
- package/src/components/_components/product-cards/product-card-1/styles/index.ts +46 -0
- package/src/components/_components/product-cards/product-card-10/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-10/product-card.tsx +124 -0
- package/src/components/_components/product-cards/product-card-10/styles/index.ts +38 -0
- package/src/components/_components/product-cards/product-card-11/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-11/product-card.tsx +63 -0
- package/src/components/_components/product-cards/product-card-11/styles/index.ts +16 -0
- package/src/components/_components/product-cards/product-card-12/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-12/product-card.tsx +42 -0
- package/src/components/_components/product-cards/product-card-12/styles/index.ts +16 -0
- package/src/components/_components/product-cards/product-card-13/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-13/product-card.tsx +45 -0
- package/src/components/_components/product-cards/product-card-13/styles/index.ts +25 -0
- package/src/components/_components/product-cards/product-card-14/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-14/product-card.tsx +122 -0
- package/src/components/_components/product-cards/product-card-14/styles/index.ts +40 -0
- package/src/components/_components/product-cards/product-card-15/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-15/product-card.tsx +118 -0
- package/src/components/_components/product-cards/product-card-15/styles/index.ts +57 -0
- package/src/components/_components/product-cards/product-card-16/components/quantity-buttons.tsx +56 -0
- package/src/components/_components/product-cards/product-card-16/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-16/product-card.tsx +114 -0
- package/src/components/_components/product-cards/product-card-16/styles/index.ts +18 -0
- package/src/components/_components/product-cards/product-card-2/components/favorite-button.tsx +29 -0
- package/src/components/_components/product-cards/product-card-2/components/product-price.tsx +26 -0
- package/src/components/_components/product-cards/product-card-2/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-2/product-card.tsx +70 -0
- package/src/components/_components/product-cards/product-card-3/components/hover-actions.tsx +83 -0
- package/src/components/_components/product-cards/product-card-3/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-3/product-card.tsx +110 -0
- package/src/components/_components/product-cards/product-card-3/styles/index.ts +89 -0
- package/src/components/_components/product-cards/product-card-4/components/hover-actions.tsx +50 -0
- package/src/components/_components/product-cards/product-card-4/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-4/product-card.tsx +128 -0
- package/src/components/_components/product-cards/product-card-4/styles/index.ts +66 -0
- package/src/components/_components/product-cards/product-card-5/components/button-actions.tsx +49 -0
- package/src/components/_components/product-cards/product-card-5/components/hover-actions.tsx +50 -0
- package/src/components/_components/product-cards/product-card-5/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-5/product-card.tsx +137 -0
- package/src/components/_components/product-cards/product-card-5/styles/index.ts +94 -0
- package/src/components/_components/product-cards/product-card-6/components/hover-actions.tsx +50 -0
- package/src/components/_components/product-cards/product-card-6/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-6/product-card.tsx +121 -0
- package/src/components/_components/product-cards/product-card-6/styles/index.ts +63 -0
- package/src/components/_components/product-cards/product-card-7/components/product-status.tsx +18 -0
- package/src/components/_components/product-cards/product-card-7/components/quantity-buttons.tsx +47 -0
- package/src/components/_components/product-cards/product-card-7/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-7/product-card.tsx +136 -0
- package/src/components/_components/product-cards/product-card-7/styles/index.ts +98 -0
- package/src/components/_components/product-cards/product-card-8/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-8/product-card.tsx +133 -0
- package/src/components/_components/product-cards/product-card-8/styles/index.ts +51 -0
- package/src/components/_components/product-cards/product-card-9/components/add-to-cart.tsx +60 -0
- package/src/components/_components/product-cards/product-card-9/components/favorite-button.tsx +27 -0
- package/src/components/_components/product-cards/product-card-9/components/tags.tsx +33 -0
- package/src/components/_components/product-cards/product-card-9/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-9/product-card.tsx +169 -0
- package/src/components/_components/product-cards/product-price.tsx +26 -0
- package/src/components/_components/product-cards/product-rating.tsx +28 -0
- package/src/components/_components/product-cards/product-title.tsx +24 -0
- package/src/components/_components/product-cards/use-product.ts +35 -0
- package/src/components/_components/products-view/product-view-dialog.tsx +180 -0
- package/src/components/_components/products-view/products-grid-view.tsx +39 -0
- package/src/components/_components/products-view/products-list-view.tsx +35 -0
- package/src/components/_components/progress/index.ts +1 -0
- package/src/components/_components/progress/progress.tsx +77 -0
- package/src/components/_components/scrollbar/index.ts +1 -0
- package/src/components/_components/scrollbar/scrollbar.tsx +27 -0
- package/src/components/_components/scrollbar/styles.ts +15 -0
- package/src/components/_components/search-box/components/category-dropdown.tsx +61 -0
- package/src/components/_components/search-box/components/search-result.tsx +29 -0
- package/src/components/_components/search-box/hooks/use-search.ts +63 -0
- package/src/components/_components/search-box/index.ts +2 -0
- package/src/components/_components/search-box/search-input-category.test.tsx +110 -0
- package/src/components/_components/search-box/search-input-category.tsx +104 -0
- package/src/components/_components/search-box/search-input.test.tsx +41 -0
- package/src/components/_components/search-box/search-input.tsx +64 -0
- package/src/components/_components/search-box/styles/index.ts +45 -0
- package/src/components/_components/section-header/index.ts +2 -0
- package/src/components/_components/section-header/section-creator.tsx +28 -0
- package/src/components/_components/section-header/section-header.tsx +44 -0
- package/src/components/_components/service-cards/icon-component.tsx +18 -0
- package/src/components/_components/service-cards/service-card-1/index.ts +1 -0
- package/src/components/_components/service-cards/service-card-1/service-card-1.tsx +39 -0
- package/src/components/_components/service-cards/service-card-2/index.ts +1 -0
- package/src/components/_components/service-cards/service-card-2/service-card-2.tsx +34 -0
- package/src/components/_components/service-cards/service-card-3/index.ts +1 -0
- package/src/components/_components/service-cards/service-card-3/service-card-3.tsx +25 -0
- package/src/components/_components/service-cards/service-card-3/styles.ts +23 -0
- package/src/components/_components/settings/index.ts +1 -0
- package/src/components/_components/settings/setting.tsx +141 -0
- package/src/components/_components/settings/styles.ts +57 -0
- package/src/components/_components/shop-card/index.ts +1 -0
- package/src/components/_components/shop-card/shop-card.tsx +152 -0
- package/src/components/_components/shop-card/styles.ts +33 -0
- package/src/components/_components/side-nav/index.ts +1 -0
- package/src/components/_components/side-nav/side-nav.tsx +49 -0
- package/src/components/_components/site-logo.tsx +17 -0
- package/src/components/_components/sticky/Sticky.tsx +62 -0
- package/src/components/_components/sticky/index.ts +1 -0
- package/src/components/_components/sticky/styles.ts +38 -0
- package/src/components/_components/sticky-wrapper/index.ts +1 -0
- package/src/components/_components/sticky-wrapper/sticky-wrapper.tsx +21 -0
- package/src/components/_components/sticky-wrapper/styles.ts +25 -0
- package/src/components/_components/stories/story-content/index.ts +1 -0
- package/src/components/_components/stories/story-content/story-content.tsx +28 -0
- package/src/components/_components/stories/story-content/styles.ts +22 -0
- package/src/components/_components/stories/story-item/index.ts +1 -0
- package/src/components/_components/stories/story-item/story-item.tsx +24 -0
- package/src/components/_components/stories/story-item/styles.ts +11 -0
- package/src/components/_components/stories/story-viewer/index.ts +1 -0
- package/src/components/_components/stories/story-viewer/story-viewer.tsx +44 -0
- package/src/components/_components/stories/story-viewer/styles.ts +15 -0
- package/src/components/_components/subscribe-input/index.ts +1 -0
- package/src/components/_components/subscribe-input/styles.ts +14 -0
- package/src/components/_components/subscribe-input/subscribe-input.tsx +43 -0
- package/src/components/_components/topbar/index.ts +1 -0
- package/src/components/_components/topbar/styles.ts +55 -0
- package/src/components/_components/topbar/top-bar.tsx +112 -0
- package/src/components/_components/utils/constants.ts +8 -0
- package/src/components/countries-input.tsx +78 -0
- package/src/config.ts +47 -0
- package/src/lib/build-detail-url.ts +8 -0
- package/src/lib/build-product-detail-url.ts +12 -0
- package/src/lib/cart-cookie-client-handler.ts +12 -0
- package/src/lib/cart-cookie-handler.ts +14 -0
- package/src/lib/category-helpers.ts +113 -0
- package/src/lib/create-graphql-client.ts +32 -0
- package/src/lib/currency-formatter.ts +31 -0
- package/src/lib/get-palette-color.ts +50 -0
- package/src/lib/graphqlRequestSdk.ts +41234 -0
- package/src/lib/hexToLuma.ts +55 -0
- package/src/lib/lib.ts +61 -0
- package/src/lib/map-helper.ts +71 -0
- package/src/lib/page-slugs.ts +10 -0
- package/src/lib/refiner-utils.ts +32 -0
- package/src/lib/store-hours-helper.ts +274 -0
- package/src/lib/test-media.ts +23 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
// Schemas
|
|
2
|
+
import { extendedCartSchema, Cart } from "@/api-manager/schemas/cart.schema";
|
|
3
|
+
import {
|
|
4
|
+
productSchema,
|
|
5
|
+
ProductDetails,
|
|
6
|
+
SearchByCriteriaInput,
|
|
7
|
+
} from "@/api-manager/schemas/product.schema";
|
|
8
|
+
import { Address } from "@/api-manager/schemas/address.schema";
|
|
9
|
+
import { User } from "@/api-manager/schemas/user.schema";
|
|
10
|
+
import { Session } from "@/api-manager/schemas/session.schema";
|
|
11
|
+
import { merge } from "object-mapper";
|
|
12
|
+
import getGraphqlClient from "../../lib/get-graphql-client";
|
|
13
|
+
// Interfaces
|
|
14
|
+
import {
|
|
15
|
+
UserInput,
|
|
16
|
+
AddressInput,
|
|
17
|
+
Attribute,
|
|
18
|
+
Category as E4Category,
|
|
19
|
+
Country,
|
|
20
|
+
Shipping,
|
|
21
|
+
Cart as E4Cart,
|
|
22
|
+
Product,
|
|
23
|
+
Session as E4Session,
|
|
24
|
+
} from "./graphqlRequestSdk";
|
|
25
|
+
import {
|
|
26
|
+
Category,
|
|
27
|
+
ProductRefinerValue,
|
|
28
|
+
ProductSearchResult,
|
|
29
|
+
} from "@msdyn365-commerce/retail-proxy";
|
|
30
|
+
import {
|
|
31
|
+
cartMap,
|
|
32
|
+
productDetailsMap,
|
|
33
|
+
productMap,
|
|
34
|
+
addressReverseMap,
|
|
35
|
+
countriesMap,
|
|
36
|
+
countryMap,
|
|
37
|
+
deliveryOptionsMap,
|
|
38
|
+
} from "./e4.remaps";
|
|
39
|
+
import { CategoryHierarchy } from "@/lib/category-helpers";
|
|
40
|
+
|
|
41
|
+
interface TransformedRefinerValue {
|
|
42
|
+
RefinerRecordId: number;
|
|
43
|
+
DataTypeValue: number;
|
|
44
|
+
LeftValueBoundString: string;
|
|
45
|
+
RightValueBoundString: string;
|
|
46
|
+
UnitText: string;
|
|
47
|
+
RowNumber: number;
|
|
48
|
+
Count: number;
|
|
49
|
+
LeftValueBoundLocalizedString: string;
|
|
50
|
+
RightValueBoundLocalizedString: string;
|
|
51
|
+
ExtensionProperties: [];
|
|
52
|
+
RefinerSourceValue: number;
|
|
53
|
+
SwatchImageUrl: string;
|
|
54
|
+
SwatchColorHexCode: string;
|
|
55
|
+
"@odata.type": string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface TransformedRefiner {
|
|
59
|
+
RecordId: number;
|
|
60
|
+
KeyName: string;
|
|
61
|
+
DataTypeValue: number;
|
|
62
|
+
RefinerTypeValue: number;
|
|
63
|
+
DisplayTemplateValue: number;
|
|
64
|
+
ExtensionProperties: [];
|
|
65
|
+
SourceValue: number;
|
|
66
|
+
Values: TransformedRefinerValue[];
|
|
67
|
+
IsDimension: boolean;
|
|
68
|
+
"@odata.type": string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class RecordIdMapper {
|
|
72
|
+
private recordToAttr: Record<number, string> = {};
|
|
73
|
+
|
|
74
|
+
public add(recordId: number, attributeId: string) {
|
|
75
|
+
this.recordToAttr[recordId] = attributeId;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public getAttributeId(recordId: number): string | undefined {
|
|
79
|
+
return this.recordToAttr[recordId];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const RECORD_ID_MAPPER = new RecordIdMapper();
|
|
84
|
+
|
|
85
|
+
export const generateCategoryFilterString = async (
|
|
86
|
+
targetCategoryIdNum: string | number,
|
|
87
|
+
): Promise<string> => {
|
|
88
|
+
const e4Api = await getGraphqlClient();
|
|
89
|
+
|
|
90
|
+
let e4Categories: E4Category[] = [];
|
|
91
|
+
try {
|
|
92
|
+
const { data, errors: catErrors } = await e4Api.categories();
|
|
93
|
+
if (catErrors) {
|
|
94
|
+
console.error("Error fetching categories:", catErrors);
|
|
95
|
+
}
|
|
96
|
+
e4Categories = (data?.categories.category ?? []).filter(
|
|
97
|
+
(category) => category !== null,
|
|
98
|
+
) as E4Category[];
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("Exception fetching categories:", error);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const targetCategoryIdStr = String(targetCategoryIdNum);
|
|
104
|
+
|
|
105
|
+
const categoryMap = new Map<string, E4Category>();
|
|
106
|
+
e4Categories.forEach((cat) => {
|
|
107
|
+
if (cat && cat.id) {
|
|
108
|
+
categoryMap.set(cat.id, cat);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const targetCategory = categoryMap.get(targetCategoryIdStr);
|
|
113
|
+
|
|
114
|
+
if (!targetCategory) {
|
|
115
|
+
console.warn(
|
|
116
|
+
`Target category ID ${targetCategoryIdStr} not found in category list.`,
|
|
117
|
+
);
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const parentId = targetCategory.parentId;
|
|
122
|
+
|
|
123
|
+
if (parentId == null || targetCategory.id === "1") {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (parentId === "1") {
|
|
128
|
+
const childSeoCrumbs: string[] = [];
|
|
129
|
+
categoryMap.forEach((cat) => {
|
|
130
|
+
if (cat.parentId === targetCategoryIdStr && cat.seoCrumb) {
|
|
131
|
+
childSeoCrumbs.push(cat.seoCrumb);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const filterString = childSeoCrumbs.join("|");
|
|
135
|
+
return filterString;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const filterString = targetCategory.seoCrumb ?? "";
|
|
139
|
+
if (!targetCategory.seoCrumb) {
|
|
140
|
+
console.warn(
|
|
141
|
+
`Target category ${targetCategoryIdStr} is missing seoCrumb, filter might not work as expected.`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return filterString;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const productListInputTransform = async (
|
|
148
|
+
input: SearchByCriteriaInput,
|
|
149
|
+
) => {
|
|
150
|
+
const categoryFilter = await generateCategoryFilterString(
|
|
151
|
+
input.categoryId ?? "",
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const grouped = input?.searchState?.refinement?.reduce(
|
|
155
|
+
(acc: Record<string, string[]>, ref: ProductRefinerValue) => {
|
|
156
|
+
const key = RECORD_ID_MAPPER.getAttributeId(ref?.RefinerRecordId ?? 0);
|
|
157
|
+
if (!key) return acc;
|
|
158
|
+
|
|
159
|
+
if (!acc[key]) {
|
|
160
|
+
acc[key] = [];
|
|
161
|
+
}
|
|
162
|
+
acc[key].push(ref?.LeftValueBoundString ?? "");
|
|
163
|
+
return acc;
|
|
164
|
+
},
|
|
165
|
+
{} as Record<string, string[]>,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const filters = Object.entries(grouped).map(([key, values]) => ({
|
|
169
|
+
key,
|
|
170
|
+
value: (values as string[]).join(","),
|
|
171
|
+
}));
|
|
172
|
+
|
|
173
|
+
const sortDesc =
|
|
174
|
+
!!input?.searchState?.queryResultSettings.Sorting?.Columns?.[0]
|
|
175
|
+
?.IsDescending;
|
|
176
|
+
let sortName =
|
|
177
|
+
input?.searchState?.queryResultSettings?.Sorting?.Columns?.[0]?.ColumnName?.toLowerCase();
|
|
178
|
+
// No relevance sort in e4 API.
|
|
179
|
+
sortName =
|
|
180
|
+
sortName === "relevance"
|
|
181
|
+
? ""
|
|
182
|
+
: sortDesc
|
|
183
|
+
? `${sortName}-hl`
|
|
184
|
+
: `${sortName}-lh`;
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
categoryId: input?.categoryId ? String(input?.categoryId) : "1",
|
|
188
|
+
categoryFilter,
|
|
189
|
+
top: input?.searchState?.queryResultSettings?.Paging?.Top || 20,
|
|
190
|
+
skip: input?.searchState?.queryResultSettings?.Paging?.Skip || 0,
|
|
191
|
+
sort: sortName ? sortName : null,
|
|
192
|
+
sortDesc,
|
|
193
|
+
filters: filters && filters.length ? filters : [],
|
|
194
|
+
search: input?.searchState?.searchTerm,
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const refinersTransformValidate = (
|
|
199
|
+
rawFilters: Attribute[],
|
|
200
|
+
): TransformedRefiner[] => {
|
|
201
|
+
if (!rawFilters || !Array.isArray(rawFilters)) {
|
|
202
|
+
console.warn(
|
|
203
|
+
"Invalid input received by refinersTransformValidate: must be an array.",
|
|
204
|
+
rawFilters,
|
|
205
|
+
);
|
|
206
|
+
return [];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const DATA_TYPE_VALUE_STRING = 5;
|
|
210
|
+
const REFINER_TYPE_VALUE_DISCRETE = 1;
|
|
211
|
+
const DISPLAY_TEMPLATE_VALUE_DEFAULT = 0;
|
|
212
|
+
const SOURCE_VALUE_ATTRIBUTE = 2;
|
|
213
|
+
const ODATA_TYPE_REFINER =
|
|
214
|
+
"#Microsoft.Dynamics.Commerce.Runtime.DataModel.ProductRefiner";
|
|
215
|
+
const ODATA_TYPE_REFINER_VALUE =
|
|
216
|
+
"#Microsoft.Dynamics.Commerce.Runtime.DataModel.ProductRefinerValue";
|
|
217
|
+
const DIMENSION_ATTRIBUTE_IDS = ["size", "color", "style"];
|
|
218
|
+
|
|
219
|
+
// Treat price filter as list filter (DisplayTemplateValue as 0) for now, until e4 API supports price bar filtering.
|
|
220
|
+
return rawFilters
|
|
221
|
+
.map((rawRefiner): TransformedRefiner | null => {
|
|
222
|
+
if (
|
|
223
|
+
!rawRefiner ||
|
|
224
|
+
typeof rawRefiner !== "object" ||
|
|
225
|
+
!rawRefiner.AttributeName ||
|
|
226
|
+
!Array.isArray(rawRefiner.value)
|
|
227
|
+
) {
|
|
228
|
+
console.warn("Skipping invalid raw refiner object:", rawRefiner);
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const transformedValues: TransformedRefinerValue[] = rawRefiner.value
|
|
233
|
+
.map((rawValue): TransformedRefinerValue | null => {
|
|
234
|
+
if (
|
|
235
|
+
!rawValue ||
|
|
236
|
+
typeof rawValue !== "object" ||
|
|
237
|
+
!rawValue.AttributeValue ||
|
|
238
|
+
typeof rawValue.Count !== "number"
|
|
239
|
+
) {
|
|
240
|
+
console.warn(
|
|
241
|
+
"Skipping invalid raw refiner value object:",
|
|
242
|
+
rawValue,
|
|
243
|
+
);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
RECORD_ID_MAPPER.add(
|
|
248
|
+
Number(rawValue?.id),
|
|
249
|
+
rawValue?.AttributeId ?? "",
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
RefinerRecordId: Number(rawValue?.id),
|
|
254
|
+
DataTypeValue: DATA_TYPE_VALUE_STRING,
|
|
255
|
+
LeftValueBoundString: rawValue.AttributeValue,
|
|
256
|
+
RightValueBoundString: rawValue.AttributeValue,
|
|
257
|
+
UnitText: "",
|
|
258
|
+
RowNumber: 0,
|
|
259
|
+
Count: rawValue.Count,
|
|
260
|
+
LeftValueBoundLocalizedString: "",
|
|
261
|
+
RightValueBoundLocalizedString: "",
|
|
262
|
+
ExtensionProperties: [],
|
|
263
|
+
RefinerSourceValue: SOURCE_VALUE_ATTRIBUTE,
|
|
264
|
+
SwatchImageUrl: "",
|
|
265
|
+
SwatchColorHexCode:
|
|
266
|
+
rawValue?.AttributeId === "color" ? rawValue.AttributeValue : "",
|
|
267
|
+
"@odata.type": ODATA_TYPE_REFINER_VALUE,
|
|
268
|
+
};
|
|
269
|
+
})
|
|
270
|
+
.filter((value): value is TransformedRefinerValue => value !== null);
|
|
271
|
+
|
|
272
|
+
const isDimension = DIMENSION_ATTRIBUTE_IDS.includes(
|
|
273
|
+
rawRefiner.AttributeId?.toLowerCase() ?? "",
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
RecordId: Number(rawRefiner?.id),
|
|
278
|
+
KeyName: rawRefiner?.displayName ?? "",
|
|
279
|
+
DataTypeValue: DATA_TYPE_VALUE_STRING,
|
|
280
|
+
RefinerTypeValue: REFINER_TYPE_VALUE_DISCRETE,
|
|
281
|
+
DisplayTemplateValue: DISPLAY_TEMPLATE_VALUE_DEFAULT,
|
|
282
|
+
ExtensionProperties: [],
|
|
283
|
+
SourceValue: SOURCE_VALUE_ATTRIBUTE,
|
|
284
|
+
Values: transformedValues,
|
|
285
|
+
IsDimension: isDimension,
|
|
286
|
+
"@odata.type": ODATA_TYPE_REFINER,
|
|
287
|
+
};
|
|
288
|
+
})
|
|
289
|
+
.filter((refiner): refiner is TransformedRefiner => refiner !== null);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Note: Try to use retail-server schema first, if it has too many
|
|
294
|
+
* required fields, create a custom schema with only frontend required fields
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Note: Try to use retail-server schema first, if it has too many
|
|
299
|
+
* required fields, create a custom schema with only frontend required fields
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Transforms the E4 AddToCart response to a Cart retail-proxy object
|
|
304
|
+
* Add parameters to transform model as needed
|
|
305
|
+
*
|
|
306
|
+
* @param data the E4 Cart object
|
|
307
|
+
* @returns the transformed cart object
|
|
308
|
+
*/
|
|
309
|
+
export const cartTransformValidate = (cart: E4Cart): Cart => {
|
|
310
|
+
if (!(cart && cart?.id)) throw new Error("Not a valid cart");
|
|
311
|
+
const transformedData = merge(cart, cartMap);
|
|
312
|
+
try {
|
|
313
|
+
extendedCartSchema.parse(transformedData);
|
|
314
|
+
} catch (e) {
|
|
315
|
+
console.warn("Cart data does not match retail-proxy schema", e);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return transformedData as Cart;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Transforms the E4 Product response to a Product retail-proxy object
|
|
323
|
+
* @param productData the E4 Product object
|
|
324
|
+
* @returns the transformed product object
|
|
325
|
+
*/
|
|
326
|
+
export const productTransformValidate = (
|
|
327
|
+
productData: Product,
|
|
328
|
+
): ProductDetails => {
|
|
329
|
+
const translatedData = merge(
|
|
330
|
+
productData,
|
|
331
|
+
productDetailsMap,
|
|
332
|
+
) as ProductDetails;
|
|
333
|
+
try {
|
|
334
|
+
productSchema.parse(translatedData);
|
|
335
|
+
} catch (e) {
|
|
336
|
+
console.warn("Product data does not match retail-proxy schema", e);
|
|
337
|
+
}
|
|
338
|
+
return translatedData;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const productWithCategoryTransformValidate = (
|
|
342
|
+
productData: Product,
|
|
343
|
+
): ProductSearchResult => {
|
|
344
|
+
const productTransform = merge(
|
|
345
|
+
productData,
|
|
346
|
+
productMap,
|
|
347
|
+
) as ProductSearchResult;
|
|
348
|
+
|
|
349
|
+
// const productWithCategory = {
|
|
350
|
+
// ...productTransform,
|
|
351
|
+
// // Category: categoryTransformValidate([
|
|
352
|
+
// // productData?.category?.[0],
|
|
353
|
+
// // ] as E4Category[]),
|
|
354
|
+
// } as unknown as ProductSearchResult;
|
|
355
|
+
|
|
356
|
+
// try {
|
|
357
|
+
// productWCategorySchema.parse(productWithCategory);
|
|
358
|
+
// } catch (e) {
|
|
359
|
+
// console.warn(
|
|
360
|
+
// "Product data with category does not match retail-proxy schema",
|
|
361
|
+
// e
|
|
362
|
+
// );
|
|
363
|
+
// throw e;
|
|
364
|
+
// }
|
|
365
|
+
|
|
366
|
+
return productTransform;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
export const userTransformInput = (user: User): UserInput => {
|
|
370
|
+
let formattedUser = {};
|
|
371
|
+
|
|
372
|
+
if (user.FirstName && user.LastName) {
|
|
373
|
+
formattedUser = {
|
|
374
|
+
firstName: user?.FirstName,
|
|
375
|
+
lastName: user?.LastName,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (user?.DefaultShippingAddressId) {
|
|
380
|
+
const shippingInfo = {
|
|
381
|
+
defaultShippingAddressId: user?.DefaultShippingAddressId,
|
|
382
|
+
};
|
|
383
|
+
formattedUser = { ...formattedUser, ...shippingInfo };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return formattedUser;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Transforms the e4 API session data to Session schema.
|
|
391
|
+
*/
|
|
392
|
+
export const sessionTransformValidate = (data: E4Session): Session => {
|
|
393
|
+
const formattedSession: Session = {
|
|
394
|
+
Id: data?.id,
|
|
395
|
+
User: {
|
|
396
|
+
AccountNumber: data?.user?.accountId ?? "",
|
|
397
|
+
FirstName: data?.user?.firstName ?? "",
|
|
398
|
+
LastName: data?.user?.lastName ?? "",
|
|
399
|
+
Email: data?.user?.email ?? "",
|
|
400
|
+
// Add other required fields with defaults if needed
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
return formattedSession;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Transforms the Address schema to e4 API address
|
|
408
|
+
*/
|
|
409
|
+
export const addressTransform = async (address: Address) => {
|
|
410
|
+
const countryId = await getCountryId(address?.ThreeLetterISORegionName ?? "");
|
|
411
|
+
const stateId = await getStateId(address?.State ?? "", countryId ?? "");
|
|
412
|
+
|
|
413
|
+
const formattedAddress: AddressInput = merge(address, addressReverseMap);
|
|
414
|
+
formattedAddress.firstName = "";
|
|
415
|
+
formattedAddress.lastName = "";
|
|
416
|
+
formattedAddress.address2 = "";
|
|
417
|
+
formattedAddress.stateId = stateId;
|
|
418
|
+
formattedAddress.countryId = countryId;
|
|
419
|
+
formattedAddress.addressTypeId = 1; // We only create and update shipping addresses.
|
|
420
|
+
|
|
421
|
+
return formattedAddress;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
export const countriesTransformValidate = (countries: Country[]) => {
|
|
425
|
+
if (Array.isArray(countries) && countries.length) {
|
|
426
|
+
return countries.map((country) => merge(country, countriesMap));
|
|
427
|
+
}
|
|
428
|
+
return [];
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
export const countryTransformValidate = (country: Country) => {
|
|
432
|
+
if (country?.state && country?.state.length) {
|
|
433
|
+
return merge(country, countryMap);
|
|
434
|
+
}
|
|
435
|
+
return [];
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const countriesCache = new Map<string, Country[]>();
|
|
439
|
+
const countryCache = new Map<string, Country>();
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* For d365 country id and value are 'USA' but for e4 it is '80175021088166' and 'USA'.
|
|
443
|
+
* So use countryId, to map the codes back to ids before API calls.
|
|
444
|
+
*/
|
|
445
|
+
export const getCountryId = async (code: string) => {
|
|
446
|
+
const cacheKey = "countries";
|
|
447
|
+
let countries: Country[] = [];
|
|
448
|
+
|
|
449
|
+
if (countriesCache.has(cacheKey)) {
|
|
450
|
+
countries = countriesCache.get(cacheKey) ?? countries;
|
|
451
|
+
} else {
|
|
452
|
+
const e4Api = await getGraphqlClient();
|
|
453
|
+
const { data } = await e4Api.e4CountryList();
|
|
454
|
+
countriesCache.set(cacheKey, data?.countries as Country[]);
|
|
455
|
+
countries = data?.countries as Country[];
|
|
456
|
+
}
|
|
457
|
+
const country = countries.find(
|
|
458
|
+
(c: { isoAlpha3Code: string }) => c?.isoAlpha3Code === code,
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
return country?.id;
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const getStateId = async (stateCode: string, countryId: string) => {
|
|
465
|
+
const cacheKey = `states-${countryId}`;
|
|
466
|
+
let country: Country = {
|
|
467
|
+
id: "",
|
|
468
|
+
isoAlpha2Code: "",
|
|
469
|
+
isoAlpha3Code: "",
|
|
470
|
+
name: "",
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
if (countryCache.has(cacheKey)) {
|
|
474
|
+
country = countryCache.get(cacheKey) ?? country;
|
|
475
|
+
} else {
|
|
476
|
+
const e4Api = await getGraphqlClient();
|
|
477
|
+
const { data } = await e4Api.e4Country({ id: countryId });
|
|
478
|
+
countryCache.set(cacheKey, data?.country as Country);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const state = country?.state?.find((s) => s?.code === stateCode);
|
|
482
|
+
|
|
483
|
+
return state?.id;
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
export const deliveryOptionsTransformValidate = (options: Shipping[]) => {
|
|
487
|
+
if (Array.isArray(options) && options.length) {
|
|
488
|
+
return options.map((option) => merge(option, deliveryOptionsMap));
|
|
489
|
+
}
|
|
490
|
+
return [];
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
interface TransformedCategoryNode extends Category {
|
|
494
|
+
Slug: string;
|
|
495
|
+
Url: string;
|
|
496
|
+
NeutralizedName: string;
|
|
497
|
+
Children?: TransformedCategoryNode[];
|
|
498
|
+
ParentCategory?: number;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export const categoryTransformValidate = (
|
|
502
|
+
rawCategories: E4Category[],
|
|
503
|
+
rootParentId = 1,
|
|
504
|
+
urlPrefix = "e4",
|
|
505
|
+
): CategoryHierarchy[] => {
|
|
506
|
+
function generateSlug(name: string): string {
|
|
507
|
+
if (!name) return "";
|
|
508
|
+
return name
|
|
509
|
+
.toLowerCase()
|
|
510
|
+
.replace(/\s+/g, "-")
|
|
511
|
+
.replace(/[^\w-]+/g, "")
|
|
512
|
+
.replace(/--+/g, "-")
|
|
513
|
+
.replace(/^-+/, "")
|
|
514
|
+
.replace(/-+$/, "");
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function createTransformedNode(
|
|
518
|
+
rawCategory: E4Category,
|
|
519
|
+
): TransformedCategoryNode | null {
|
|
520
|
+
let recordIdNum: number;
|
|
521
|
+
try {
|
|
522
|
+
recordIdNum = parseInt(String(rawCategory.id), 10);
|
|
523
|
+
if (isNaN(recordIdNum)) throw new Error("Invalid RecordId");
|
|
524
|
+
} catch (e) {
|
|
525
|
+
console.warn(`Skipping category due to invalid id:`, rawCategory);
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const categoryName = rawCategory.name || "Unnamed Category";
|
|
530
|
+
const slug = generateSlug(categoryName);
|
|
531
|
+
let parentIdNum: number | undefined = undefined;
|
|
532
|
+
if (rawCategory.parentId != null) {
|
|
533
|
+
const parsedParentId = parseInt(String(rawCategory.parentId), 10);
|
|
534
|
+
if (!isNaN(parsedParentId)) parentIdNum = parsedParentId;
|
|
535
|
+
else
|
|
536
|
+
console.warn(
|
|
537
|
+
`Invalid parentId format for id ${recordIdNum}:`,
|
|
538
|
+
rawCategory.parentId,
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const node: TransformedCategoryNode = {
|
|
543
|
+
RecordId: recordIdNum,
|
|
544
|
+
Name: categoryName,
|
|
545
|
+
ParentCategory: parentIdNum,
|
|
546
|
+
DisplayOrder: 0,
|
|
547
|
+
LocalizedDescription: categoryName,
|
|
548
|
+
Images: [
|
|
549
|
+
{
|
|
550
|
+
Uri: `Categories/${categoryName}.png`,
|
|
551
|
+
IsDefault: false,
|
|
552
|
+
IsSelfHosted: false,
|
|
553
|
+
Priority: 0,
|
|
554
|
+
IsAdditionalMedia: false,
|
|
555
|
+
MediaTypeValue: 0,
|
|
556
|
+
DisplayOrder: 0,
|
|
557
|
+
IsApplicableForChildEntities: false,
|
|
558
|
+
ExtensionProperties: [],
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
NameTranslations: [
|
|
562
|
+
{ Language: "en-us", Text: categoryName, ExtensionProperties: [] },
|
|
563
|
+
],
|
|
564
|
+
ExtensionProperties: [],
|
|
565
|
+
NeutralizedName: categoryName,
|
|
566
|
+
Slug: slug,
|
|
567
|
+
Url: "",
|
|
568
|
+
Children: [],
|
|
569
|
+
};
|
|
570
|
+
return node;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function calculateUrls(
|
|
574
|
+
categoryNode: TransformedCategoryNode,
|
|
575
|
+
basePath: string,
|
|
576
|
+
prefix: string,
|
|
577
|
+
): void {
|
|
578
|
+
const currentPath = basePath
|
|
579
|
+
? `${basePath}/${categoryNode.Slug}`
|
|
580
|
+
: `${prefix}/${categoryNode.Slug}`;
|
|
581
|
+
categoryNode.Url = `${currentPath}/${categoryNode.RecordId}`;
|
|
582
|
+
// Check if Children exists before iterating
|
|
583
|
+
if (categoryNode?.Children && categoryNode?.Children?.length > 0) {
|
|
584
|
+
categoryNode.Children.forEach((child: TransformedCategoryNode) =>
|
|
585
|
+
calculateUrls(child, currentPath, prefix),
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function removeEmptyChildren(node: TransformedCategoryNode): void {
|
|
591
|
+
if (node.Children) {
|
|
592
|
+
if (node.Children.length === 0) {
|
|
593
|
+
delete node.Children;
|
|
594
|
+
} else {
|
|
595
|
+
node.Children.forEach(removeEmptyChildren);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (!rawCategories || !Array.isArray(rawCategories)) {
|
|
601
|
+
console.error(
|
|
602
|
+
"Invalid input received by categoryTransformValidate: must be an array.",
|
|
603
|
+
rawCategories,
|
|
604
|
+
);
|
|
605
|
+
return [];
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const categoryMap = new Map<number, TransformedCategoryNode>();
|
|
609
|
+
const rootNodes: TransformedCategoryNode[] = [];
|
|
610
|
+
|
|
611
|
+
rawCategories.forEach((rawCat: E4Category) => {
|
|
612
|
+
const transformedNode = createTransformedNode(rawCat);
|
|
613
|
+
if (transformedNode)
|
|
614
|
+
categoryMap.set(transformedNode.RecordId, transformedNode);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
categoryMap.forEach((node: TransformedCategoryNode) => {
|
|
618
|
+
const parentId = node.ParentCategory;
|
|
619
|
+
if (parentId === rootParentId) rootNodes.push(node);
|
|
620
|
+
else if (parentId !== undefined && categoryMap.has(parentId)) {
|
|
621
|
+
const parentNode = categoryMap.get(parentId);
|
|
622
|
+
if (parentNode) {
|
|
623
|
+
if (!parentNode.Children) {
|
|
624
|
+
parentNode.Children = [];
|
|
625
|
+
}
|
|
626
|
+
parentNode.Children.push(node);
|
|
627
|
+
parentNode.Children.sort(
|
|
628
|
+
(a, b) =>
|
|
629
|
+
(a.DisplayOrder ?? 0) - (b.DisplayOrder ?? 0) ||
|
|
630
|
+
(a.Name ?? "").localeCompare(b.Name ?? ""),
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
rootNodes.forEach((rootNode: TransformedCategoryNode) =>
|
|
637
|
+
calculateUrls(rootNode, "", urlPrefix),
|
|
638
|
+
);
|
|
639
|
+
rootNodes.sort(
|
|
640
|
+
(a, b) =>
|
|
641
|
+
(a.DisplayOrder ?? 0) - (b.DisplayOrder ?? 0) ||
|
|
642
|
+
(a.Name ?? "").localeCompare(b.Name ?? ""),
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
rootNodes.forEach(removeEmptyChildren);
|
|
646
|
+
|
|
647
|
+
return rootNodes as CategoryHierarchy[];
|
|
648
|
+
};
|