@shopbite-de/storefront 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +13 -0
- package/.github/workflows/ci.yaml +2 -0
- package/CLAUDE.md +54 -30
- package/GLOSSARY.md +327 -0
- package/README.md +5 -6
- package/app/app.vue +50 -40
- package/app/components/Address/Card.vue +2 -2
- package/app/components/Address/Detail.vue +17 -45
- package/app/components/Address/Form.vue +38 -26
- package/app/components/BranchSwitch.vue +40 -0
- package/app/components/Cart/Bar.vue +9 -9
- package/app/components/Cart/Item.vue +27 -36
- package/app/components/Cart/QuickView.vue +17 -16
- package/app/components/Cart/Upsell.vue +19 -27
- package/app/components/Category/Breadcrumb.vue +3 -8
- package/app/components/Category/FilterGroup.vue +6 -6
- package/app/components/Category/Listing.vue +44 -66
- package/app/components/Checkout/DeliveryTimeSelect.vue +21 -48
- package/app/components/Checkout/OrderMessage.vue +29 -0
- package/app/components/Checkout/OrdererAddress.vue +40 -0
- package/app/components/Checkout/PaymentAndDelivery.vue +40 -35
- package/app/components/Checkout/Summary.vue +89 -74
- package/app/components/Checkout/VoucherInput.vue +8 -8
- package/app/components/Contact/Form.vue +97 -13
- package/app/components/Footer.vue +2 -2
- package/app/components/Header.vue +9 -9
- package/app/components/Home/Categories.vue +13 -17
- package/app/components/Home/Facts.vue +6 -4
- package/app/components/Home/Hero.vue +1 -1
- package/app/components/Home/Highlights.vue +8 -8
- package/app/components/Home/Restaurant.vue +2 -2
- package/app/components/Menu/BonCard.vue +21 -37
- package/app/components/Menu/CartPanel.vue +2 -2
- package/app/components/Menu/CategoryIndex.vue +8 -12
- package/app/components/Menu/OrderMode.vue +2 -2
- package/app/components/Menu/SectionHeader.vue +6 -10
- package/app/components/Navigation/MobileTop.vue +12 -20
- package/app/components/Order/Confirmation.vue +10 -10
- package/app/components/Order/Detail.vue +47 -49
- package/app/components/Product/Configurator.vue +46 -30
- package/app/components/Product/CrossSelling.vue +56 -71
- package/app/components/Product/DeselectIngredient.vue +10 -11
- package/app/components/Product/Detail.vue +62 -55
- package/app/components/Product/FoodLabels.vue +4 -9
- package/app/components/Product/QuickView.vue +22 -30
- package/app/components/User/Detail.vue +20 -43
- package/app/components/User/LoginForm.vue +11 -17
- package/app/components/User/RegistrationForm.vue +3 -3
- package/app/components/Wishlist.vue +99 -106
- package/app/components/WishlistSaveButton.vue +17 -9
- package/app/composables/useAccountAddresses.ts +89 -0
- package/app/composables/useAccountOrders.ts +35 -0
- package/app/composables/useAddToCart.ts +63 -110
- package/app/composables/useCartData.ts +55 -0
- package/app/composables/useCartMutations.ts +93 -85
- package/app/composables/useCartUpsell.ts +27 -71
- package/app/composables/useCategoryListing.ts +36 -59
- package/app/composables/useCategorySeo.ts +11 -16
- package/app/composables/useCheckoutMethodGuard.ts +22 -46
- package/app/composables/useCheckoutMethods.ts +89 -0
- package/app/composables/useCheckoutOrderMessage.ts +19 -0
- package/app/composables/useCheckoutOrderer.ts +69 -0
- package/app/composables/useCommercePrice.ts +46 -9
- package/app/composables/useContactForm.ts +25 -32
- package/app/composables/useCustomer.ts +169 -0
- package/app/composables/useDeliveryTime.ts +112 -122
- package/app/composables/useHolidays.ts +12 -62
- package/app/composables/useHomeMenuCategories.ts +5 -5
- package/app/composables/useListingSearch.ts +9 -8
- package/app/composables/useLiveShopData.ts +15 -9
- package/app/composables/useMenuRootId.ts +3 -6
- package/app/composables/useMenuSection.ts +14 -0
- package/app/composables/useMenuSectionSchema.ts +23 -30
- package/app/composables/useNavigation.ts +24 -29
- package/app/composables/useOpeningHours.ts +21 -0
- package/app/composables/useOpeningHoursData.ts +9 -9
- package/app/composables/useOrder.ts +37 -0
- package/app/composables/useOrderMode.ts +18 -16
- package/app/composables/usePlaceOrder.ts +37 -0
- package/app/composables/useProductCartQuantity.ts +6 -6
- package/app/composables/useProductDetail.ts +28 -53
- package/app/composables/useProductEvents.ts +6 -5
- package/app/composables/useProductQuickView.ts +35 -68
- package/app/composables/useRegistrationForm.ts +85 -34
- package/app/composables/useRestaurantSchema.ts +7 -7
- package/app/composables/useSearchTracking.ts +6 -6
- package/app/composables/useSectionRoute.ts +48 -0
- package/app/composables/useServiceSchedule.ts +23 -0
- package/app/composables/useShippingLeadTime.ts +8 -6
- package/app/composables/useShippingMethodChoice.ts +13 -23
- package/app/composables/useShippingMethods.ts +31 -0
- package/app/composables/useShopConfig.ts +60 -0
- package/app/composables/useShopData.ts +20 -0
- package/app/composables/useSortingSelection.ts +5 -8
- package/app/composables/useStoreStatus.ts +13 -37
- package/app/composables/useTopSellers.ts +3 -3
- package/app/composables/useTrackEvent.ts +29 -24
- package/app/composables/useVoucherCode.ts +47 -12
- package/app/composables/useWishlistEntries.ts +233 -177
- package/app/error.vue +3 -2
- package/app/layouts/account.vue +4 -3
- package/app/pages/[...all].vue +6 -16
- package/app/pages/account/recover/password/index.vue +6 -14
- package/app/pages/anmelden.vue +1 -1
- package/app/pages/bestellung/[id]/erfolg.vue +3 -3
- package/app/pages/bestellung/[id]/fehler.vue +18 -29
- package/app/pages/bestellung/kasse.vue +24 -7
- package/app/pages/konto/adressen.vue +95 -40
- package/app/pages/konto/bestellungen.vue +10 -13
- package/app/pages/konto/index.vue +12 -2
- package/app/pages/konto/profil.vue +241 -42
- package/app/pages/passwort-vergessen.vue +5 -10
- package/app/pages/registrierung/bestaetigen.vue +9 -23
- package/app/pages/registrierung/index.vue +19 -11
- package/app/pages/suche.vue +29 -29
- package/app/plugins/shopware-layer-offline.ts +38 -0
- package/app/plugins/visitor-has-session.server.ts +19 -0
- package/app/utils/accountMessages.ts +74 -0
- package/app/utils/accountReads.ts +34 -0
- package/app/utils/bffWrite.ts +89 -0
- package/app/utils/dish.ts +121 -0
- package/app/utils/leadTime.ts +25 -29
- package/app/utils/media.ts +11 -17
- package/app/utils/menuGroups.ts +22 -35
- package/app/utils/money.ts +41 -0
- package/app/utils/openingHours.ts +30 -30
- package/app/utils/orderStatus.ts +17 -0
- package/app/utils/productUrl.ts +14 -31
- package/app/utils/restaurantTime.ts +326 -0
- package/app/utils/schema.ts +39 -42
- package/app/utils/wishlist.ts +139 -0
- package/docs/adr/0001-backend-agnostic-storefront.md +409 -0
- package/eslint.config.mjs +42 -2
- package/nuxt.config.ts +28 -0
- package/package.json +1 -1
- package/server/adapters/memory/cart.ts +370 -0
- package/server/adapters/memory/catalog.ts +367 -0
- package/server/adapters/memory/contact.ts +89 -0
- package/server/adapters/memory/customer.ts +458 -0
- package/server/adapters/memory/demo-menu.json +1190 -0
- package/server/adapters/memory/demoImages.ts +13 -0
- package/server/adapters/memory/demoMenu.ts +234 -0
- package/server/adapters/memory/demoNavigation.ts +71 -0
- package/server/adapters/memory/index.ts +122 -0
- package/server/adapters/memory/navigation.ts +168 -0
- package/server/adapters/memory/ordering.ts +379 -0
- package/server/adapters/memory/seed.ts +136 -0
- package/server/adapters/memory/wishlist.ts +166 -0
- package/server/adapters/notImplemented.ts +67 -0
- package/server/adapters/registry.ts +32 -0
- package/server/adapters/runtimeConfig.ts +14 -0
- package/server/adapters/shopware/cart.ts +792 -0
- package/server/adapters/shopware/catalog.ts +850 -0
- package/server/adapters/shopware/checkout.ts +138 -0
- package/server/adapters/shopware/contact.ts +255 -0
- package/server/adapters/shopware/customer.ts +460 -0
- package/server/adapters/shopware/index.ts +165 -0
- package/server/adapters/shopware/menuRoot.ts +24 -0
- package/server/adapters/shopware/navigation.ts +426 -0
- package/server/adapters/shopware/ordering.ts +1185 -0
- package/server/adapters/shopware/request.ts +67 -0
- package/server/adapters/shopware/shop.ts +249 -0
- package/server/adapters/shopware/storeApi.ts +62 -0
- package/server/adapters/shopware/wishlist.ts +473 -0
- package/server/api/__sitemap__/urls.get.ts +10 -38
- package/server/api/account/addresses/[addressId]/default.post.ts +13 -0
- package/server/api/account/addresses/[addressId].delete.ts +14 -0
- package/server/api/account/addresses/[addressId].patch.ts +15 -0
- package/server/api/account/addresses/index.get.ts +6 -0
- package/server/api/account/addresses/index.post.ts +9 -0
- package/server/api/account/email.post.ts +10 -0
- package/server/api/account/index.delete.ts +11 -0
- package/server/api/account/index.get.ts +9 -0
- package/server/api/account/login.post.ts +14 -0
- package/server/api/account/logout.post.ts +11 -0
- package/server/api/account/orders.get.ts +13 -0
- package/server/api/account/password-reset/confirm.post.ts +13 -0
- package/server/api/account/password-reset.post.ts +16 -0
- package/server/api/account/password.post.ts +18 -0
- package/server/api/account/profile.patch.ts +6 -0
- package/server/api/account/register/confirm.post.ts +13 -0
- package/server/api/account/register.post.ts +15 -0
- package/server/api/breadcrumb/[sectionId].get.ts +33 -0
- package/server/api/cart/index.get.ts +4 -0
- package/server/api/cart/lines/[lineId].delete.ts +6 -0
- package/server/api/cart/lines/[lineId].patch.ts +10 -0
- package/server/api/cart/lines.post.ts +10 -0
- package/server/api/cart/vouchers/[code].delete.ts +9 -0
- package/server/api/cart/vouchers.post.ts +12 -0
- package/server/api/checkout/guest.post.ts +13 -0
- package/server/api/checkout/orderer/addresses/[addressId].patch.ts +16 -0
- package/server/api/checkout/orderer.get.ts +10 -0
- package/server/api/checkout/orders.post.ts +60 -0
- package/server/api/checkout/payment-methods.get.ts +9 -0
- package/server/api/checkout/selection.get.ts +10 -0
- package/server/api/checkout/selection.post.ts +14 -0
- package/server/api/checkout/shipping-methods.get.ts +9 -0
- package/server/api/contact/form.get.ts +13 -0
- package/server/api/contact/index.post.ts +24 -0
- package/server/api/listing/[sectionId].get.ts +33 -0
- package/server/api/menu/dishes/[dishId]/variant.get.ts +29 -0
- package/server/api/menu/dishes/[dishId].get.ts +19 -0
- package/server/api/menu/dishes/index.get.ts +26 -0
- package/server/api/menu/media/[name].get.ts +18 -0
- package/server/api/menu/root.get.ts +12 -0
- package/server/api/menu/sections/[sectionId].get.ts +18 -0
- package/server/api/menu/upsell.get.ts +12 -0
- package/server/api/navigation/[kind].get.ts +75 -0
- package/server/api/orders/[orderId]/payment.post.ts +24 -0
- package/server/api/orders/[orderId].get.ts +13 -0
- package/server/api/payment-methods.get.ts +11 -15
- package/server/api/resolve-path.get.ts +20 -0
- package/server/api/search.get.ts +16 -80
- package/server/api/session.post.ts +18 -0
- package/server/api/shop/branches.get.ts +9 -0
- package/server/api/shop/config.get.ts +9 -0
- package/server/api/shop/holidays.get.ts +9 -0
- package/server/api/shop/opening-hours.get.ts +9 -0
- package/server/api/top-sellers.get.ts +14 -50
- package/server/api/wishlist/entries/[entryId].delete.ts +8 -0
- package/server/api/wishlist/entries.post.ts +13 -0
- package/server/api/wishlist/index.get.ts +13 -0
- package/server/api/wishlist/merge.post.ts +12 -0
- package/server/plugins/visitor-session.ts +35 -0
- package/server/ports/CartPort.ts +48 -0
- package/server/ports/CatalogPort.ts +66 -0
- package/server/ports/CheckoutPort.ts +128 -0
- package/server/ports/ContactPort.ts +38 -0
- package/server/ports/CustomerPort.ts +154 -0
- package/server/ports/NavigationPort.ts +58 -0
- package/server/ports/OrderPort.ts +31 -0
- package/server/ports/ShopPort.ts +29 -0
- package/server/ports/WishlistPort.ts +47 -0
- package/server/ports/index.ts +42 -0
- package/server/ports/session.ts +22 -0
- package/server/routes/llms.txt.ts +28 -154
- package/server/session/forwardedFor.ts +24 -0
- package/server/session/sameOrigin.ts +47 -0
- package/server/session/seal.ts +147 -0
- package/server/session/visitorSession.ts +288 -0
- package/server/utils/accountRoutes.ts +173 -0
- package/server/utils/backend.ts +21 -0
- package/server/utils/backoff.ts +18 -5
- package/server/utils/cacheKeys.ts +11 -0
- package/server/utils/cachePurge.ts +47 -27
- package/server/utils/cartRoutes.ts +124 -0
- package/server/utils/catalogData.ts +24 -0
- package/server/utils/checkoutRoutes.ts +326 -0
- package/server/utils/contactRoutes.ts +86 -0
- package/server/utils/domainHttp.ts +73 -0
- package/server/utils/listingParams.ts +49 -20
- package/server/utils/llmsTxt.ts +64 -19
- package/server/utils/navigationData.ts +14 -0
- package/server/utils/orderPlacement.ts +322 -0
- package/server/utils/outageBreaker.ts +126 -0
- package/server/utils/pathRoutes.ts +160 -0
- package/server/utils/requestBody.ts +43 -0
- package/server/utils/shopData.ts +132 -0
- package/server/utils/sitemap.ts +14 -36
- package/server/utils/storeApi.ts +71 -23
- package/server/utils/visitorSession.ts +209 -0
- package/server/utils/wishlistRoutes.ts +55 -0
- package/shared/domain/customer/index.ts +2 -0
- package/shared/domain/customer/types.ts +88 -0
- package/shared/domain/discoverability/index.ts +4 -0
- package/shared/domain/discoverability/paths.ts +93 -0
- package/shared/domain/discoverability/route.ts +32 -0
- package/shared/domain/discoverability/types.ts +75 -0
- package/shared/domain/index.ts +11 -0
- package/shared/domain/kernel/calendar.ts +88 -0
- package/shared/domain/kernel/errors.ts +100 -0
- package/shared/domain/kernel/freeze.ts +13 -0
- package/shared/domain/kernel/ids.ts +6 -0
- package/shared/domain/kernel/index.ts +8 -0
- package/shared/domain/kernel/media.ts +17 -0
- package/shared/domain/kernel/money.ts +104 -0
- package/shared/domain/kernel/timeOfDay.ts +39 -0
- package/shared/domain/menu/dishConfiguration.ts +72 -0
- package/shared/domain/menu/index.ts +3 -0
- package/shared/domain/menu/types.ts +185 -0
- package/shared/domain/ordering/index.ts +3 -0
- package/shared/domain/ordering/time.ts +114 -0
- package/shared/domain/ordering/types.ts +195 -0
- package/shared/domain/restaurant/holiday.ts +38 -0
- package/shared/domain/restaurant/index.ts +4 -0
- package/shared/domain/restaurant/openingInterval.ts +97 -0
- package/shared/domain/restaurant/types.ts +75 -0
- package/test/a11y/presets.test.ts +49 -31
- package/test/contract/cart.contract.ts +592 -0
- package/test/contract/cart.spec.ts +5 -0
- package/test/contract/cartFixtures.ts +573 -0
- package/test/contract/catalog.contract.ts +714 -0
- package/test/contract/catalog.spec.ts +5 -0
- package/test/contract/catalogFixtures.ts +572 -0
- package/test/contract/checkout.contract.ts +123 -0
- package/test/contract/checkout.spec.ts +5 -0
- package/test/contract/contact.contract.ts +149 -0
- package/test/contract/contact.spec.ts +4 -0
- package/test/contract/contactFixtures.ts +148 -0
- package/test/contract/customer.contract.ts +831 -0
- package/test/contract/customer.spec.ts +4 -0
- package/test/contract/customerFixtures.ts +468 -0
- package/test/contract/fixtures.ts +260 -0
- package/test/contract/harness.ts +45 -0
- package/test/contract/navigation.contract.ts +336 -0
- package/test/contract/navigation.spec.ts +5 -0
- package/test/contract/navigationFixtures.ts +311 -0
- package/test/contract/ordering.contract.ts +655 -0
- package/test/contract/ordering.spec.ts +4 -0
- package/test/contract/orderingFixtures.ts +498 -0
- package/test/contract/shop.contract.ts +164 -0
- package/test/contract/shop.spec.ts +5 -0
- package/test/contract/wishlist.contract.ts +375 -0
- package/test/contract/wishlist.spec.ts +4 -0
- package/test/contract/wishlistFixtures.ts +199 -0
- package/test/nuxt/AccountPagesPreset.test.ts +320 -83
- package/test/nuxt/AuthPagesPreset.test.ts +17 -24
- package/test/nuxt/CartBar.test.ts +12 -8
- package/test/nuxt/CartCheckoutPreset.test.ts +36 -33
- package/test/nuxt/CartItem.test.ts +39 -20
- package/test/nuxt/CartQuickView.test.ts +106 -0
- package/test/nuxt/CartUpsell.test.ts +37 -39
- package/test/nuxt/CategoryBreadcrumb.test.ts +26 -0
- package/test/nuxt/CheckoutFormsPreset.test.ts +92 -13
- package/test/nuxt/CheckoutOnePage.test.ts +28 -21
- package/test/nuxt/CheckoutPageMessage.test.ts +31 -0
- package/test/nuxt/CheckoutSummary.test.ts +163 -48
- package/test/nuxt/CheckoutVoucherInput.test.ts +77 -80
- package/test/nuxt/ContactFormPreset.test.ts +97 -36
- package/test/nuxt/DeliveryTimeSelect.test.ts +72 -45
- package/test/nuxt/FooterStoreStatus.test.ts +2 -2
- package/test/nuxt/HeaderFooterPreset.test.ts +11 -19
- package/test/nuxt/HomeCategories.test.ts +47 -0
- package/test/nuxt/HomeLeadTimes.test.ts +3 -3
- package/test/nuxt/MenuBonCard.test.ts +45 -32
- package/test/nuxt/NavigationMobileTop.test.ts +30 -28
- package/test/nuxt/OrderPagesPreset.test.ts +83 -52
- package/test/nuxt/PaymentAndDelivery.test.ts +25 -26
- package/test/nuxt/ProductConfigurator.test.ts +81 -0
- package/test/nuxt/ProductCrossSelling.test.ts +23 -20
- package/test/nuxt/ProductDeselectIngredient.test.ts +6 -9
- package/test/nuxt/ProductFoodLabels.test.ts +7 -24
- package/test/nuxt/ProductSheetPreset.test.ts +24 -24
- package/test/nuxt/RegisterConfirmPage.test.ts +26 -45
- package/test/nuxt/RegistrationForm.test.ts +57 -53
- package/test/nuxt/RegistrationPage.test.ts +37 -0
- package/test/nuxt/WishlistPage.test.ts +119 -43
- package/test/nuxt/WishlistSaveButton.test.ts +39 -12
- package/test/nuxt/accountSwitch.test.ts +106 -0
- package/test/nuxt/bffWrite.test.ts +41 -0
- package/test/nuxt/liveShopData.test.ts +36 -68
- package/test/nuxt/shopwareLayerOffline.test.ts +32 -0
- package/test/nuxt/useAddToCart.test.ts +142 -115
- package/test/nuxt/useCartMutations.test.ts +165 -113
- package/test/nuxt/useCartUpsell.test.ts +36 -63
- package/test/nuxt/useCategoryListing.test.ts +75 -118
- package/test/nuxt/useCheckoutMethodGuard.test.ts +54 -105
- package/test/nuxt/useCustomer.test.ts +127 -0
- package/test/nuxt/useDeliveryTime.test.ts +169 -157
- package/test/nuxt/useNavigation.test.ts +81 -0
- package/test/nuxt/useOpeningHoursData.test.ts +18 -18
- package/test/nuxt/useOrder.test.ts +38 -0
- package/test/nuxt/usePlaceOrder.test.ts +88 -0
- package/test/nuxt/useSearchTracking.test.ts +2 -2
- package/test/nuxt/useSectionRoute.test.ts +86 -0
- package/test/nuxt/useShippingLeadTime.test.ts +17 -17
- package/test/nuxt/useShippingMethodChoice.test.ts +22 -22
- package/test/nuxt/useShippingMethods.test.ts +71 -0
- package/test/nuxt/useShopConfig.test.ts +64 -0
- package/test/nuxt/useStoreStatus.test.ts +34 -50
- package/test/nuxt/useTopSellers.test.ts +6 -5
- package/test/nuxt/useTrackEvent.test.ts +68 -6
- package/test/nuxt/useWishlistEntries.test.ts +392 -128
- package/test/support/cart.ts +43 -0
- package/test/support/dishes.ts +116 -0
- package/test/support/navigation.ts +17 -0
- package/test/unit/accountMessages.spec.ts +53 -0
- package/test/unit/accountRoutes.spec.ts +637 -0
- package/test/unit/adapters/memoryCustomer.spec.ts +67 -0
- package/test/unit/adapters/memoryDemoMenu.spec.ts +174 -0
- package/test/unit/adapters/registry.spec.ts +100 -0
- package/test/unit/adapters/shopwareCart.spec.ts +636 -0
- package/test/unit/adapters/shopwareCatalog.spec.ts +486 -0
- package/test/unit/adapters/shopwareCheckout.spec.ts +197 -0
- package/test/unit/adapters/shopwareContact.spec.ts +296 -0
- package/test/unit/adapters/shopwareCustomer.spec.ts +256 -0
- package/test/unit/adapters/shopwareNavigation.spec.ts +594 -0
- package/test/unit/adapters/shopwareOrdering.spec.ts +620 -0
- package/test/unit/adapters/shopwareShop.spec.ts +259 -0
- package/test/unit/adapters/shopwareWishlist.spec.ts +306 -0
- package/test/unit/adapters/useBackend.spec.ts +41 -0
- package/test/unit/backoff.spec.ts +47 -0
- package/test/unit/boundedCache.spec.ts +59 -59
- package/test/unit/cacheKeys.spec.ts +44 -0
- package/test/unit/cachePurge.spec.ts +44 -19
- package/test/unit/cartRoutes.spec.ts +567 -0
- package/test/unit/catalogRoutes.spec.ts +287 -0
- package/test/unit/checkoutRoutes.spec.ts +545 -0
- package/test/unit/dish.spec.ts +128 -0
- package/test/unit/domain/discoverability.spec.ts +154 -0
- package/test/unit/domain/dishConfiguration.spec.ts +85 -0
- package/test/unit/domain/money.spec.ts +102 -0
- package/test/unit/domain/time.spec.ts +336 -0
- package/test/unit/domainHttp.spec.ts +74 -0
- package/test/unit/forwardedFor.spec.ts +24 -0
- package/test/unit/layoutCacheRoutes.spec.ts +47 -471
- package/test/unit/leadTime.spec.ts +28 -23
- package/test/unit/llmsTxt.spec.ts +120 -9
- package/test/unit/media.spec.ts +25 -26
- package/test/unit/menuGroups.spec.ts +31 -21
- package/test/unit/navigationRoutes.spec.ts +648 -0
- package/test/unit/nitroStubs.ts +6 -1
- package/test/unit/openingHours.spec.ts +57 -34
- package/test/unit/orderPlacement.spec.ts +362 -0
- package/test/unit/outageBreaker.spec.ts +213 -0
- package/test/unit/productUrl.spec.ts +10 -28
- package/test/unit/requestBody.spec.ts +56 -0
- package/test/unit/restaurantTime.spec.ts +295 -0
- package/test/unit/schema.spec.ts +58 -26
- package/test/unit/session/sameOrigin.spec.ts +76 -0
- package/test/unit/session/seal.spec.ts +128 -0
- package/test/unit/session/visitorSession.spec.ts +439 -0
- package/test/unit/shopRoutes.spec.ts +257 -0
- package/test/unit/sitemap.spec.ts +11 -47
- package/test/unit/storeApiForVisitor.spec.ts +109 -0
- package/test/unit/useCategorySeo.spec.ts +57 -31
- package/test/unit/wishlistContactRoutes.spec.ts +607 -0
- package/vitest.config.ts +5 -1
- package/app/components/SalesChannelSwitch.vue +0 -73
- package/app/composables/useBusinessHours.ts +0 -192
- package/app/composables/useCategoryById.ts +0 -10
- package/app/composables/useNavigationSearch.ts +0 -45
- package/app/composables/useProductConfigurator.ts +0 -70
- package/app/composables/useProductCrossSelling.ts +0 -42
- package/app/composables/useProductVariants.ts +0 -61
- package/app/composables/useProductVariantsZwei.ts +0 -62
- package/app/composables/useSeoUrlRoute.ts +0 -124
- package/app/composables/useShopBiteConfig.ts +0 -69
- package/app/composables/useSyncWishlist.ts +0 -119
- package/app/types/Association.d.ts +0 -14
- package/app/utils/product.ts +0 -139
- package/app/utils/seoPath.ts +0 -68
- package/app/utils/time.ts +0 -20
- package/server/api/breadcrumb/[categoryId].get.ts +0 -31
- package/server/api/category/[categoryId].get.ts +0 -37
- package/server/api/listing/[categoryId].get.ts +0 -102
- package/server/api/navigation/[type].get.ts +0 -97
- package/server/api/product/[productId]/cross-selling.get.ts +0 -26
- package/server/api/product/[productId].get.ts +0 -76
- package/server/api/product/variant.get.ts +0 -98
- package/server/api/seo-url/index.get.ts +0 -17
- package/server/api/seo-url/known.get.ts +0 -33
- package/server/api/shopbite/business-hours.get.ts +0 -22
- package/server/api/shopbite/config.get.ts +0 -6
- package/server/api/shopbite/holidays.get.ts +0 -20
- package/server/utils/menuRoot.ts +0 -31
- package/server/utils/seoPaths.ts +0 -130
- package/server/utils/seoUrlCache.ts +0 -98
- package/server/utils/shopBiteConfig.ts +0 -30
- package/test/nuxt/useBusinessHours.test.ts +0 -106
- package/test/nuxt/useProductConfigurator.test.ts +0 -87
- package/test/nuxt/useProductVariants.test.ts +0 -95
- package/test/nuxt/useProductVariantsZwei.test.ts +0 -52
- package/test/nuxt/useSeoUrlRoute.test.ts +0 -176
- package/test/nuxt/useShopBiteConfig.test.ts +0 -131
- package/test/nuxt/useSyncWishlist.test.ts +0 -85
- package/test/unit/product.spec.ts +0 -160
- package/test/unit/seoPath.spec.ts +0 -161
- package/test/unit/seoPaths.spec.ts +0 -117
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
import { DomainError } from "../../shared/domain";
|
|
3
|
+
import type { Backend } from "../ports";
|
|
4
|
+
import { createBackoff, createResilientLoader, isOutage } from "./backoff";
|
|
5
|
+
import { answerDomain } from "./domainHttp";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Restaurant operations behind the BFF (ADR 0001, step 1): what every page
|
|
9
|
+
* renders (configuration, opening hours, holidays, branches, shipping
|
|
10
|
+
* methods with their lead times) as the ports answer it.
|
|
11
|
+
*
|
|
12
|
+
* - `cached()` for server-side rendering and llms.txt: a cached function
|
|
13
|
+
* per value (`swr: false`, so never older than its TTL) behind a
|
|
14
|
+
* resilient loader that serves the last good answer during an outage and
|
|
15
|
+
* pauses the backend after a failure.
|
|
16
|
+
* - `fresh()` for the browser's live values (`?fresh=1`): straight from the
|
|
17
|
+
* port, never from a cache or an old answer. The checkout asks it right
|
|
18
|
+
* before an order whether the restaurant accepts orders (the ShopBite
|
|
19
|
+
* plugin refuses a paused order too; this is defence in depth and gives
|
|
20
|
+
* the guest a clear message). While the backend is paused after a
|
|
21
|
+
* failure, a fresh request fails fast instead of reaching it.
|
|
22
|
+
*
|
|
23
|
+
* Every failure is a DomainError (`backend_unavailable` during an
|
|
24
|
+
* outage), so the routes answer `{ data: { code } }` like every BFF route.
|
|
25
|
+
*
|
|
26
|
+
* The cache purge (`server/utils/cachePurge.ts`) empties them by name.
|
|
27
|
+
*/
|
|
28
|
+
export type BackendData<T> = Readonly<{
|
|
29
|
+
name: string;
|
|
30
|
+
cached: () => Promise<T>;
|
|
31
|
+
fresh: () => Promise<T>;
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
export function defineBackendData<T>(
|
|
35
|
+
name: string,
|
|
36
|
+
maxAge: number,
|
|
37
|
+
read: (backend: Backend) => Promise<T>,
|
|
38
|
+
): BackendData<T> {
|
|
39
|
+
const cached = defineCachedFunction(async () => read(useBackend()), {
|
|
40
|
+
name,
|
|
41
|
+
maxAge,
|
|
42
|
+
swr: false,
|
|
43
|
+
getKey: () => name,
|
|
44
|
+
});
|
|
45
|
+
// one pause per value for its cached and its fresh reads
|
|
46
|
+
const backoff = createBackoff();
|
|
47
|
+
const load = createResilientLoader<T>(undefined, backoff);
|
|
48
|
+
const unavailable = () =>
|
|
49
|
+
new DomainError(
|
|
50
|
+
"backend_unavailable",
|
|
51
|
+
`The backend is paused after a failure (${name}).`,
|
|
52
|
+
);
|
|
53
|
+
return {
|
|
54
|
+
name,
|
|
55
|
+
// the loader answers a pause without a last good answer as
|
|
56
|
+
// `backend_unavailable` itself
|
|
57
|
+
cached: () => load(name, () => cached()),
|
|
58
|
+
fresh: async () => {
|
|
59
|
+
if (backoff.active()) throw unavailable();
|
|
60
|
+
try {
|
|
61
|
+
return await read(useBackend());
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (isOutage(error)) backoff.trip();
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { cacheTtl } = useRuntimeConfig().public.shopBite;
|
|
71
|
+
|
|
72
|
+
/** `ShopConfig`; carries the switch that accepts orders, so short-lived. */
|
|
73
|
+
export const shopConfigData = defineBackendData(
|
|
74
|
+
"shop-config",
|
|
75
|
+
cacheTtl.config,
|
|
76
|
+
(backend) => backend.shop.getConfig(),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export const openingHoursData = defineBackendData(
|
|
80
|
+
"shop-opening-hours",
|
|
81
|
+
cacheTtl.businessHours,
|
|
82
|
+
(backend) => backend.shop.getOpeningHours(),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export const holidaysData = defineBackendData(
|
|
86
|
+
"shop-holidays",
|
|
87
|
+
cacheTtl.holidays,
|
|
88
|
+
(backend) => backend.shop.getHolidays(),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export const branchesData = defineBackendData(
|
|
92
|
+
"shop-branches",
|
|
93
|
+
cacheTtl.config,
|
|
94
|
+
(backend) => backend.shop.listBranches(),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/** Lead times decide the earliest wished time, so short-lived. */
|
|
98
|
+
export const shippingMethodsData = defineBackendData(
|
|
99
|
+
"shipping-methods",
|
|
100
|
+
cacheTtl.config,
|
|
101
|
+
(backend) => backend.checkout.listShippingMethods(),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
/** The contact form's required fields (Shopware's settings change rarely). */
|
|
105
|
+
export const contactFormData = defineBackendData(
|
|
106
|
+
"contact-form",
|
|
107
|
+
cacheTtl.config,
|
|
108
|
+
(backend) => backend.contact.getForm(),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
/** Names of the cached functions above, for the cache purge. */
|
|
112
|
+
export const BACKEND_DATA_NAMES = [
|
|
113
|
+
shopConfigData,
|
|
114
|
+
openingHoursData,
|
|
115
|
+
holidaysData,
|
|
116
|
+
branchesData,
|
|
117
|
+
shippingMethodsData,
|
|
118
|
+
contactFormData,
|
|
119
|
+
].map((data) => data.name);
|
|
120
|
+
|
|
121
|
+
/** `?fresh=1`: the browser asks for the live value. */
|
|
122
|
+
export function wantsFresh(event: H3Event): boolean {
|
|
123
|
+
return getQuery(event).fresh === "1";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The route answer: cached, or fresh on request; DomainErrors as HTTP. */
|
|
127
|
+
export function answerBackendData<T>(
|
|
128
|
+
event: H3Event,
|
|
129
|
+
data: BackendData<T>,
|
|
130
|
+
): Promise<T> {
|
|
131
|
+
return answerDomain(() => (wantsFresh(event) ? data.fresh() : data.cached()));
|
|
132
|
+
}
|
package/server/utils/sitemap.ts
CHANGED
|
@@ -1,48 +1,26 @@
|
|
|
1
1
|
import { parseURL, withTrailingSlash } from "ufo";
|
|
2
2
|
import type { SitemapUrl } from "#sitemap/types";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type Category = components["schemas"]["Category"];
|
|
3
|
+
import type { SitemapEntry } from "../../shared/domain";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* `_trailingSlash` marks URLs whose path must keep its trailing slash. The
|
|
9
|
-
* sitemap module strips trailing slashes from every URL, but
|
|
10
|
-
*
|
|
11
|
-
* `sitemap-trailing-slash` server plugin
|
|
7
|
+
* sitemap module strips trailing slashes from every URL, but section paths
|
|
8
|
+
* such as `/Speisekarte/Pizza/` 404 without it at a backend whose paths
|
|
9
|
+
* end in a slash (Shopware); the `sitemap-trailing-slash` server plugin
|
|
10
|
+
* restores them.
|
|
12
11
|
*/
|
|
13
12
|
export type StorefrontSitemapUrl = SitemapUrl & { _trailingSlash?: boolean };
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
export function
|
|
17
|
-
|
|
14
|
+
/** The sitemap URLs of the sections' paths, with change date and photo. */
|
|
15
|
+
export function toSitemapUrls(
|
|
16
|
+
entries: readonly SitemapEntry[],
|
|
18
17
|
): StorefrontSitemapUrl[] {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
category.type !== "page" ||
|
|
26
|
-
!path?.startsWith("/") ||
|
|
27
|
-
path.startsWith("//") ||
|
|
28
|
-
path.startsWith("/navigation/") ||
|
|
29
|
-
urls.has(path)
|
|
30
|
-
) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const lastmod = category.updatedAt ?? category.createdAt;
|
|
35
|
-
const image = category.media?.url;
|
|
36
|
-
|
|
37
|
-
urls.set(path, {
|
|
38
|
-
loc: path,
|
|
39
|
-
...(lastmod && { lastmod }),
|
|
40
|
-
...(image && { images: [{ loc: image }] }),
|
|
41
|
-
...(path.endsWith("/") && { _trailingSlash: true }),
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return [...urls.values()];
|
|
18
|
+
return entries.map((entry) => ({
|
|
19
|
+
loc: entry.path,
|
|
20
|
+
...(entry.lastModified && { lastmod: entry.lastModified }),
|
|
21
|
+
...(entry.image && { images: [{ loc: entry.image }] }),
|
|
22
|
+
...(entry.path.endsWith("/") && { _trailingSlash: true }),
|
|
23
|
+
}));
|
|
46
24
|
}
|
|
47
25
|
|
|
48
26
|
/** Re-appends the trailing slash to `<loc>` entries whose path is listed. */
|
package/server/utils/storeApi.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
+
import { guardedRequest } from "./outageBreaker";
|
|
1
2
|
import type { NitroFetchOptions } from "nitropack";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* No Store API request waits longer: the cached routes back off after a
|
|
6
|
+
* failure, the cart answers `backend_unavailable` instead of holding the
|
|
7
|
+
* visitor's next write (undici's own limit is 300 s).
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
media: ["url", "alt", "thumbnails", "metaData"],
|
|
10
|
-
media_thumbnail: ["url", "width", "height"],
|
|
11
|
-
product_media: ["media"],
|
|
12
|
-
};
|
|
9
|
+
const STORE_API_TIMEOUT_MS = 10_000;
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Calls the Shopware Store API with a criteria in the request body.
|
|
@@ -28,14 +25,18 @@ export function storeApiPost<T>(
|
|
|
28
25
|
|
|
29
26
|
// Nitro's typed $fetch resolves the response type per internal route; for
|
|
30
27
|
// a generic T on an external URL it cannot, so the type is asserted.
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
return guardedRequest(
|
|
29
|
+
() =>
|
|
30
|
+
$fetch<T>(`${endpoint}${path}`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: { "sw-access-key": accessToken, ...options.headers },
|
|
33
|
+
body,
|
|
34
|
+
// a failing request reaches Shopware once (the cached routes back
|
|
35
|
+
// off instead)
|
|
36
|
+
retry: 0,
|
|
37
|
+
timeout: STORE_API_TIMEOUT_MS,
|
|
38
|
+
}) as Promise<T>,
|
|
39
|
+
);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -48,11 +49,58 @@ export function storeApiGet<T>(
|
|
|
48
49
|
): Promise<T> {
|
|
49
50
|
const { endpoint, accessToken } = useRuntimeConfig().public.shopware;
|
|
50
51
|
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
return guardedRequest(
|
|
53
|
+
() =>
|
|
54
|
+
$fetch<T>(`${endpoint}${path}`, {
|
|
55
|
+
headers: { "sw-access-key": accessToken, ...options.headers },
|
|
56
|
+
query: options.query,
|
|
57
|
+
// ofetch retries a GET once by default; during an outage that
|
|
58
|
+
// doubles every request
|
|
59
|
+
retry: 0,
|
|
60
|
+
timeout: STORE_API_TIMEOUT_MS,
|
|
61
|
+
}) as Promise<T>,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A Store API request for one visitor (the Shopware adapter's cart,
|
|
67
|
+
* checkout, account and wishlist): with the visitor's context token and
|
|
68
|
+
* address chain, answering the token Shopware holds the context under.
|
|
69
|
+
* The server's endpoint, with a timeout: a paused Shopware
|
|
70
|
+
* answers `backend_unavailable` instead of holding the visitor's writes.
|
|
71
|
+
*/
|
|
72
|
+
export async function storeApiForVisitor<T>(request: {
|
|
73
|
+
method: "GET" | "POST" | "PATCH" | "DELETE";
|
|
74
|
+
path: string;
|
|
75
|
+
body?: Record<string, unknown>;
|
|
76
|
+
contextToken?: string;
|
|
77
|
+
forwardedFor?: string;
|
|
78
|
+
/** ms this request may take (the order: 60 s); default 10 s. */
|
|
79
|
+
timeoutMs?: number;
|
|
80
|
+
}): Promise<{ data: T; contextToken: string | null }> {
|
|
81
|
+
const config = useRuntimeConfig();
|
|
82
|
+
const { endpoint, accessToken } = config.public.shopware;
|
|
83
|
+
const serverEndpoint = (config.shopware as { endpoint?: string } | undefined)
|
|
84
|
+
?.endpoint;
|
|
85
|
+
const response = await guardedRequest(() =>
|
|
86
|
+
$fetch.raw<T>(`${serverEndpoint || endpoint}${request.path}`, {
|
|
87
|
+
method: request.method,
|
|
88
|
+
headers: {
|
|
89
|
+
"sw-access-key": accessToken,
|
|
90
|
+
...(request.contextToken
|
|
91
|
+
? { "sw-context-token": request.contextToken }
|
|
92
|
+
: {}),
|
|
93
|
+
...(request.forwardedFor
|
|
94
|
+
? { "x-forwarded-for": request.forwardedFor }
|
|
95
|
+
: {}),
|
|
96
|
+
},
|
|
97
|
+
body: request.body,
|
|
98
|
+
retry: 0,
|
|
99
|
+
timeout: request.timeoutMs ?? STORE_API_TIMEOUT_MS,
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
return {
|
|
103
|
+
data: response._data as T,
|
|
104
|
+
contextToken: response.headers.get("sw-context-token"),
|
|
105
|
+
};
|
|
58
106
|
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
import type { BackendSession } from "../ports";
|
|
3
|
+
import { forwardedFor } from "../session/forwardedFor";
|
|
4
|
+
import { isCrossSiteWrite } from "../session/sameOrigin";
|
|
5
|
+
import { createSealer, sessionPasswords, type Sealer } from "../session/seal";
|
|
6
|
+
import {
|
|
7
|
+
createSessionRegistry,
|
|
8
|
+
createVisitorSession,
|
|
9
|
+
type ScopeOptions,
|
|
10
|
+
type SessionRegistry,
|
|
11
|
+
type VisitorSession,
|
|
12
|
+
} from "../session/visitorSession";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The storefront session (ADR 0001, step 4): an HttpOnly, SameSite=Lax
|
|
16
|
+
* cookie (Secure and `__Host-` prefixed when `public.storeUrl` is https)
|
|
17
|
+
* that carries the backends' states sealed with the shop's password
|
|
18
|
+
* (`visitorSession.password`, NUXT_VISITOR_SESSION_PASSWORD; previous
|
|
19
|
+
* passwords for a rotation in `previousPasswords`). No server-side
|
|
20
|
+
* storage. Server routes hand adapters `backendSession(event, …)`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** The cookie the Shopware layer of storefronts before 2.7 kept the token in. */
|
|
24
|
+
export const LEGACY_CONTEXT_COOKIE = "sw-context-token";
|
|
25
|
+
|
|
26
|
+
/** Sessions whose newest version the process remembers. */
|
|
27
|
+
const REGISTRY_ENTRIES = 50_000;
|
|
28
|
+
|
|
29
|
+
type SessionConfig = {
|
|
30
|
+
maxAgeDays?: number | string;
|
|
31
|
+
allowedOrigins?: string;
|
|
32
|
+
password?: string;
|
|
33
|
+
previousPasswords?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const positive = (value: unknown, fallback: number) => {
|
|
37
|
+
const number = Number(value);
|
|
38
|
+
return Number.isFinite(number) && number > 0 ? number : fallback;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let settings: { maxAgeSeconds: number; passwords: string[] } | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `visitorSession` of the runtime config, validated once per process:
|
|
45
|
+
* days a session lives after the last visit (30) and the passwords. In
|
|
46
|
+
* production a missing or short password stops the server
|
|
47
|
+
* (`server/plugins/visitor-session.ts` asks at startup); development
|
|
48
|
+
* generates one and warns, so sessions end with the dev server.
|
|
49
|
+
*/
|
|
50
|
+
export function sessionSettings(): {
|
|
51
|
+
maxAgeSeconds: number;
|
|
52
|
+
passwords: string[];
|
|
53
|
+
} {
|
|
54
|
+
if (!settings) {
|
|
55
|
+
const config =
|
|
56
|
+
(useRuntimeConfig() as { visitorSession?: SessionConfig })
|
|
57
|
+
.visitorSession ?? {};
|
|
58
|
+
const { passwords, generated } = sessionPasswords({
|
|
59
|
+
password: String(config.password ?? ""),
|
|
60
|
+
previousPasswords: String(config.previousPasswords ?? ""),
|
|
61
|
+
production: !import.meta.dev,
|
|
62
|
+
});
|
|
63
|
+
if (generated) {
|
|
64
|
+
console.warn(
|
|
65
|
+
"[session] No NUXT_VISITOR_SESSION_PASSWORD: using a random one, sessions end with this process.",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
settings = {
|
|
69
|
+
maxAgeSeconds: Math.round(positive(config.maxAgeDays, 30) * 86_400),
|
|
70
|
+
passwords,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return settings;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let sealer: { name: string; sealer: Sealer } | undefined;
|
|
77
|
+
let registry: SessionRegistry | undefined;
|
|
78
|
+
|
|
79
|
+
function sealerFor(name: string): Sealer {
|
|
80
|
+
if (sealer?.name !== name) {
|
|
81
|
+
sealer = {
|
|
82
|
+
name,
|
|
83
|
+
sealer: createSealer({ passwords: sessionSettings().passwords, name }),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return sealer.sealer;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isSecure(): boolean {
|
|
90
|
+
return /^https:/i.test(useRuntimeConfig().public.storeUrl ?? "");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** `__Host-` binds the cookie to this host: no subdomain can plant it. */
|
|
94
|
+
export function sessionCookieName(): string {
|
|
95
|
+
return isSecure() ? "__Host-shopbite-session" : "shopbite-session";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const CONTEXT_KEY = "shopbiteVisitorSession";
|
|
99
|
+
|
|
100
|
+
/** The visitor's session for this request (one per request). */
|
|
101
|
+
export function useVisitorSession(event: H3Event): VisitorSession {
|
|
102
|
+
const context = event.context as Record<string, unknown>;
|
|
103
|
+
const existing = context[CONTEXT_KEY] as VisitorSession | undefined;
|
|
104
|
+
if (existing) return existing;
|
|
105
|
+
const secure = isSecure();
|
|
106
|
+
const cookieName = sessionCookieName();
|
|
107
|
+
const session = createVisitorSession({
|
|
108
|
+
sealer: sealerFor(cookieName),
|
|
109
|
+
registry: (registry ??= createSessionRegistry({
|
|
110
|
+
maxEntries: REGISTRY_ENTRIES,
|
|
111
|
+
})),
|
|
112
|
+
cookieName,
|
|
113
|
+
maxAgeSeconds: sessionSettings().maxAgeSeconds,
|
|
114
|
+
cookies: {
|
|
115
|
+
get: (name) => getCookie(event, name),
|
|
116
|
+
write: (name, value, maxAge) =>
|
|
117
|
+
setCookie(event, name, value, {
|
|
118
|
+
httpOnly: true,
|
|
119
|
+
secure,
|
|
120
|
+
sameSite: "lax",
|
|
121
|
+
path: "/",
|
|
122
|
+
maxAge,
|
|
123
|
+
}),
|
|
124
|
+
// a `__Host-` cookie is only deleted by a Secure Set-Cookie
|
|
125
|
+
remove: (name) =>
|
|
126
|
+
deleteCookie(event, name, {
|
|
127
|
+
path: "/",
|
|
128
|
+
...(name.startsWith("__Host-") ? { secure: true } : {}),
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
context[CONTEXT_KEY] = session;
|
|
133
|
+
return session;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The adapter's view of the visitor's session. Read-only routes pass
|
|
138
|
+
* `create: false`: a visitor without a session gets none from a read. The
|
|
139
|
+
* context token cookie of the old Shopware layer is taken over first.
|
|
140
|
+
*/
|
|
141
|
+
export async function backendSession(
|
|
142
|
+
event: H3Event,
|
|
143
|
+
adapter: string,
|
|
144
|
+
options: ScopeOptions,
|
|
145
|
+
): Promise<BackendSession> {
|
|
146
|
+
const visitor = useVisitorSession(event);
|
|
147
|
+
await visitor.migrateLegacyCookie(LEGACY_CONTEXT_COOKIE, "shopware");
|
|
148
|
+
const scope = visitor.scope(adapter, options);
|
|
149
|
+
return {
|
|
150
|
+
read: () => scope.read(),
|
|
151
|
+
write: (state) => scope.write(state),
|
|
152
|
+
forwardedFor: forwardedFor(
|
|
153
|
+
getRequestHeader(event, "x-forwarded-for"),
|
|
154
|
+
event.node?.req?.socket?.remoteAddress,
|
|
155
|
+
),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Refuses a state-changing request that a page of another site made the
|
|
161
|
+
* browser send (CSRF, `server/session/sameOrigin.ts`): 403 with
|
|
162
|
+
* `data.code` `cross_site_request`.
|
|
163
|
+
*/
|
|
164
|
+
export function assertSameOriginWrite(event: H3Event): void {
|
|
165
|
+
const host = getRequestHeader(event, "host");
|
|
166
|
+
const scheme = (
|
|
167
|
+
event.node?.req?.socket as { encrypted?: boolean } | undefined
|
|
168
|
+
)?.encrypted
|
|
169
|
+
? "https"
|
|
170
|
+
: "http";
|
|
171
|
+
const crossSite = isCrossSiteWrite({
|
|
172
|
+
method: event.method,
|
|
173
|
+
// forwarded headers are the client's to choose: not trusted here; a
|
|
174
|
+
// shop with several https hosts behind a proxy lists them
|
|
175
|
+
origins: [
|
|
176
|
+
useRuntimeConfig().public.storeUrl,
|
|
177
|
+
host ? `${scheme}://${host}` : undefined,
|
|
178
|
+
...allowedOrigins(),
|
|
179
|
+
],
|
|
180
|
+
origin: getRequestHeader(event, "origin"),
|
|
181
|
+
secFetchSite: getRequestHeader(event, "sec-fetch-site"),
|
|
182
|
+
});
|
|
183
|
+
if (crossSite) {
|
|
184
|
+
throw createError({
|
|
185
|
+
statusCode: 403,
|
|
186
|
+
statusMessage: "Forbidden",
|
|
187
|
+
data: { code: "cross_site_request" },
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* `visitorSession.allowedOrigins` (NUXT_VISITOR_SESSION_ALLOWED_ORIGINS,
|
|
194
|
+
* comma-separated, e.g. `https://www.shop.example`): further origins the
|
|
195
|
+
* storefront is reached under, next to `public.storeUrl`.
|
|
196
|
+
*/
|
|
197
|
+
function allowedOrigins(): string[] {
|
|
198
|
+
const config = (useRuntimeConfig() as { visitorSession?: SessionConfig })
|
|
199
|
+
.visitorSession;
|
|
200
|
+
return String(config?.allowedOrigins ?? "")
|
|
201
|
+
.split(",")
|
|
202
|
+
.map((entry) => entry.trim())
|
|
203
|
+
.filter(Boolean);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Visitor-specific answers are never stored by a browser or proxy. */
|
|
207
|
+
export function answerPrivately(event: H3Event): void {
|
|
208
|
+
setResponseHeader(event, "cache-control", "private, no-store");
|
|
209
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
import { DomainError, type DishConfiguration } from "../../shared/domain";
|
|
3
|
+
import { WISHLIST_MERGE_LIMIT } from "../ports/WishlistPort";
|
|
4
|
+
import { configurationBody } from "./cartRoutes";
|
|
5
|
+
import { opaqueId } from "./checkoutRoutes";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* The customer's wishlist behind the BFF (ADR 0001, step 7): routes under
|
|
9
|
+
* `/api/wishlist/**` answer `WishlistEntry` values privately through
|
|
10
|
+
* `answerVisitor` (CSRF, writes one after the other per visitor, 409
|
|
11
|
+
* `stale_session`); 401 `unauthenticated` without a logged-in customer
|
|
12
|
+
* (a guest's wishlist stays in the browser), 501 `not_implemented` when
|
|
13
|
+
* the backend keeps no wishlist (the browser keeps it then).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const invalid = (field: string): never => {
|
|
17
|
+
throw new DomainError("invalid_value", `Invalid ${field}.`, { field });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const asObject = (body: unknown): Record<string, unknown> => {
|
|
21
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
22
|
+
invalid("body");
|
|
23
|
+
}
|
|
24
|
+
return body as Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** `POST /api/wishlist/entries`: a dish configuration. */
|
|
28
|
+
export function wishlistEntryBody(body: unknown): DishConfiguration {
|
|
29
|
+
return configurationBody(asObject(body));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** More configurations are no guest wishlist of the storefront. */
|
|
33
|
+
const MAX_MERGE_BODY = 1000;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `POST /api/wishlist/merge`: `{ configurations }`, the guest's entries
|
|
37
|
+
* newest first; the newest `WISHLIST_MERGE_LIMIT` are taken over (the
|
|
38
|
+
* port's limit), the rest are left out.
|
|
39
|
+
*/
|
|
40
|
+
export function wishlistMergeBody(body: unknown): DishConfiguration[] {
|
|
41
|
+
const configurations = asObject(body).configurations;
|
|
42
|
+
if (
|
|
43
|
+
!Array.isArray(configurations) ||
|
|
44
|
+
configurations.length > MAX_MERGE_BODY
|
|
45
|
+
) {
|
|
46
|
+
invalid("configurations");
|
|
47
|
+
}
|
|
48
|
+
return (configurations as unknown[])
|
|
49
|
+
.slice(0, WISHLIST_MERGE_LIMIT)
|
|
50
|
+
.map((entry) => configurationBody(asObject(entry)));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function entryIdParam(event: H3Event): string {
|
|
54
|
+
return opaqueId(getRouterParam(event, "entryId"), "entryId");
|
|
55
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Id } from "../kernel";
|
|
2
|
+
import type { DishConfiguration } from "../menu";
|
|
3
|
+
|
|
4
|
+
/** ISO 3166-1 alpha-2, e.g. `DE`. */
|
|
5
|
+
export type CountryCode = string;
|
|
6
|
+
|
|
7
|
+
export type Salutation = "mr" | "mrs" | "not_specified";
|
|
8
|
+
|
|
9
|
+
/** A postal address of a guest or customer (billing or delivery). */
|
|
10
|
+
export type Address = Readonly<{
|
|
11
|
+
/** Null for an address not stored in an account. */
|
|
12
|
+
id: Id | null;
|
|
13
|
+
salutation: Salutation | null;
|
|
14
|
+
firstName: string;
|
|
15
|
+
lastName: string;
|
|
16
|
+
company: string | null;
|
|
17
|
+
/** Of a business address, with the company. */
|
|
18
|
+
department: string | null;
|
|
19
|
+
street: string;
|
|
20
|
+
/** Floor, door, "Hinterhaus". */
|
|
21
|
+
additionalLine: string | null;
|
|
22
|
+
postalCode: string;
|
|
23
|
+
city: string;
|
|
24
|
+
country: CountryCode;
|
|
25
|
+
phone: string | null;
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An address as the guest enters it: without an id, and without a country
|
|
30
|
+
* when the storefront asks for none (the shop's own country then).
|
|
31
|
+
*/
|
|
32
|
+
export type AddressInput = Omit<Address, "id" | "country"> &
|
|
33
|
+
Readonly<{ country: CountryCode | null }>;
|
|
34
|
+
|
|
35
|
+
/** What a guest enters to order without an account ("Als Gast bestellen"). */
|
|
36
|
+
export type GuestDetails = Readonly<{
|
|
37
|
+
email: string;
|
|
38
|
+
salutation: Salutation | null;
|
|
39
|
+
firstName: string;
|
|
40
|
+
lastName: string;
|
|
41
|
+
/** Orders as a business ("Geschäftskunde"); the address has a company. */
|
|
42
|
+
business: boolean;
|
|
43
|
+
billingAddress: AddressInput;
|
|
44
|
+
/** Null: delivered to the billing address. */
|
|
45
|
+
deliveryAddress: AddressInput | null;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The person ordering, logged in with an account ("Kundenkonto") or as a
|
|
50
|
+
* guest for the current session.
|
|
51
|
+
*/
|
|
52
|
+
export type Customer = Readonly<{
|
|
53
|
+
id: Id;
|
|
54
|
+
/** Ordered without an account; no login, no saved addresses. */
|
|
55
|
+
guest: boolean;
|
|
56
|
+
email: string;
|
|
57
|
+
salutation: Salutation | null;
|
|
58
|
+
firstName: string;
|
|
59
|
+
lastName: string;
|
|
60
|
+
phone: string | null;
|
|
61
|
+
defaultBillingAddressId: Id | null;
|
|
62
|
+
defaultDeliveryAddressId: Id | null;
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
export type Country = Readonly<{ code: CountryCode; name: string }>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Who orders in this session: a guest after entering their details, or the
|
|
69
|
+
* logged-in customer, with the addresses an order would use now (the
|
|
70
|
+
* delivery address is the billing address unless the guest gave another).
|
|
71
|
+
*/
|
|
72
|
+
export type Orderer = Readonly<{
|
|
73
|
+
customer: Customer;
|
|
74
|
+
billingAddress: Address;
|
|
75
|
+
deliveryAddress: Address;
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A configured dish the guest keeps for later ("Merkliste"); the same dish
|
|
80
|
+
* can be kept twice with different configurations.
|
|
81
|
+
*/
|
|
82
|
+
export type WishlistEntry = Readonly<{
|
|
83
|
+
id: Id;
|
|
84
|
+
configuration: DishConfiguration;
|
|
85
|
+
dishNumber: string;
|
|
86
|
+
/** ISO 8601 date-time. */
|
|
87
|
+
addedAt: string;
|
|
88
|
+
}>;
|