@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,185 @@
|
|
|
1
|
+
import type { Id, Media, Money } from "../kernel";
|
|
2
|
+
|
|
3
|
+
/** How search engines see the page of a menu section (Discoverability). */
|
|
4
|
+
export type SectionSeo = Readonly<{
|
|
5
|
+
/** Page title, if the restaurant set one; else the section's name. */
|
|
6
|
+
title: string | null;
|
|
7
|
+
/** Meta description, if set; else the section's description. */
|
|
8
|
+
description: string | null;
|
|
9
|
+
/** False for a section taken off the menu that still has its page. */
|
|
10
|
+
indexable: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A section of the menu ("Pizza", "Nudeln"); sections may have
|
|
15
|
+
* sub-sections. German UI: "Kategorie" / section name.
|
|
16
|
+
*/
|
|
17
|
+
export type MenuSection = Readonly<{
|
|
18
|
+
id: Id;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string | null;
|
|
21
|
+
/** Icon name (icones.js.org, e.g. `i-lucide-pizza`). */
|
|
22
|
+
icon: string | null;
|
|
23
|
+
media: Media | null;
|
|
24
|
+
/** Storefront path of the section, e.g. `/Speisekarte/Pizza/`; null without one. */
|
|
25
|
+
path: string | null;
|
|
26
|
+
seo: SectionSeo;
|
|
27
|
+
/** Sub-sections in menu order. */
|
|
28
|
+
children: readonly MenuSection[];
|
|
29
|
+
}>;
|
|
30
|
+
|
|
31
|
+
export type Diet = "vegetarian" | "vegan";
|
|
32
|
+
|
|
33
|
+
/** An allergen (code A–R) or additive (code 1–12) of a dish. */
|
|
34
|
+
export type FoodLabel = Readonly<{ code: string; name: string }>;
|
|
35
|
+
|
|
36
|
+
export type FoodLabels = Readonly<{
|
|
37
|
+
/** In the order of the restaurant's list. */
|
|
38
|
+
allergens: readonly FoodLabel[];
|
|
39
|
+
additives: readonly FoodLabel[];
|
|
40
|
+
/** The lists were checked and are complete; otherwise say "ask us". */
|
|
41
|
+
checked: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A main ingredient of a dish. Each one is a removable ingredient
|
|
46
|
+
* ("ohne Zwiebeln"); the guest's removals name it (`name`), the id tells
|
|
47
|
+
* the backend's entries apart.
|
|
48
|
+
*/
|
|
49
|
+
export type Ingredient = Readonly<{ id: Id; name: string }>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Something on the menu that can be ordered, as a menu card shows it. A
|
|
53
|
+
* dish with variants is the parent: the guest has to choose a variant
|
|
54
|
+
* before it goes into the cart (`needsChoice`).
|
|
55
|
+
*/
|
|
56
|
+
export type Dish = Readonly<{
|
|
57
|
+
id: Id;
|
|
58
|
+
/** Menu number ("Nr. 21"), shown on the card and the receipt. */
|
|
59
|
+
number: string;
|
|
60
|
+
name: string;
|
|
61
|
+
description: string | null;
|
|
62
|
+
/** Price of the dish; for a parent the lowest variant price. */
|
|
63
|
+
price: Money;
|
|
64
|
+
/** The former price, struck through, if the restaurant set one. */
|
|
65
|
+
listPrice: Money | null;
|
|
66
|
+
/** The price is a "from" price (a parent with variants). */
|
|
67
|
+
priceFrom: boolean;
|
|
68
|
+
media: Media | null;
|
|
69
|
+
/** Main ingredients, in menu order; each one can be removed ("ohne"). */
|
|
70
|
+
ingredients: readonly Ingredient[];
|
|
71
|
+
diets: readonly Diet[];
|
|
72
|
+
/** Kitchen badge ("Italienisch"), if any. */
|
|
73
|
+
kitchen: string | null;
|
|
74
|
+
foodLabels: FoodLabels;
|
|
75
|
+
available: boolean;
|
|
76
|
+
/** A variant has to be chosen first (a parent with variants). */
|
|
77
|
+
needsChoice: boolean;
|
|
78
|
+
/** Ids of the menu sections the dish is listed in directly. */
|
|
79
|
+
sectionIds: readonly Id[];
|
|
80
|
+
/**
|
|
81
|
+
* The link of the dish (its sheet over a section, e.g.
|
|
82
|
+
* `/Speisekarte/Pizza/?produkt=21`) when the backend keeps one; null
|
|
83
|
+
* leaves it to the storefront, which links the dish under the section it
|
|
84
|
+
* is listed in.
|
|
85
|
+
*/
|
|
86
|
+
path: string | null;
|
|
87
|
+
}>;
|
|
88
|
+
|
|
89
|
+
/** A choice that tells variants apart ("Größe"), with its options. */
|
|
90
|
+
export type VariantGroup = Readonly<{
|
|
91
|
+
id: Id;
|
|
92
|
+
name: string;
|
|
93
|
+
/** In the order the dish sheet offers them. */
|
|
94
|
+
options: readonly Readonly<{ id: Id; name: string }>[];
|
|
95
|
+
}>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* One orderable form of a dish ("Groß 40 cm"), chosen by one option per
|
|
99
|
+
* variant group. Name, media and main ingredients are its own or the
|
|
100
|
+
* dish's.
|
|
101
|
+
*/
|
|
102
|
+
export type Variant = Readonly<{
|
|
103
|
+
id: Id;
|
|
104
|
+
number: string;
|
|
105
|
+
name: string;
|
|
106
|
+
/** One option per variant group. */
|
|
107
|
+
optionIds: readonly Id[];
|
|
108
|
+
price: Money;
|
|
109
|
+
listPrice: Money | null;
|
|
110
|
+
available: boolean;
|
|
111
|
+
media: Media | null;
|
|
112
|
+
ingredients: readonly Ingredient[];
|
|
113
|
+
}>;
|
|
114
|
+
|
|
115
|
+
/** An optional addition to a dish ("Extra Käse"), priced on its own. */
|
|
116
|
+
export type Extra = Readonly<{
|
|
117
|
+
id: Id;
|
|
118
|
+
number: string;
|
|
119
|
+
name: string;
|
|
120
|
+
price: Money;
|
|
121
|
+
available: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
|
|
124
|
+
/** A named list of extras for a dish ("Extras", "Beilagen"). */
|
|
125
|
+
export type ExtraGroup = Readonly<{
|
|
126
|
+
id: Id;
|
|
127
|
+
name: string;
|
|
128
|
+
extras: readonly Extra[];
|
|
129
|
+
}>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Everything the dish sheet needs to configure a dish. A variant asked for
|
|
133
|
+
* by id or menu number answers its dish with that variant selected.
|
|
134
|
+
*/
|
|
135
|
+
export type DishDetail = Dish &
|
|
136
|
+
Readonly<{
|
|
137
|
+
variantGroups: readonly VariantGroup[];
|
|
138
|
+
/** Every variant of the dish; empty for a dish without variants. */
|
|
139
|
+
variants: readonly Variant[];
|
|
140
|
+
/**
|
|
141
|
+
* The variant the sheet starts with: the one asked for, else the
|
|
142
|
+
* backend's default variant of the dish; null without variants.
|
|
143
|
+
*/
|
|
144
|
+
selectedVariantId: Id | null;
|
|
145
|
+
extraGroups: readonly ExtraGroup[];
|
|
146
|
+
/** Suggested on the order confirmation step. */
|
|
147
|
+
upsell: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
|
|
150
|
+
/** A filter of a menu listing (diet, ingredient …) with its options. */
|
|
151
|
+
export type ListingFilter = Readonly<{
|
|
152
|
+
id: Id;
|
|
153
|
+
name: string;
|
|
154
|
+
options: readonly Readonly<{ id: Id; name: string }>[];
|
|
155
|
+
}>;
|
|
156
|
+
|
|
157
|
+
export type ListingQuery = Readonly<{
|
|
158
|
+
/** 1-based. */
|
|
159
|
+
page?: number;
|
|
160
|
+
/** Key of one of `MenuListing.sortings`; else the backend's default. */
|
|
161
|
+
sorting?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Selected filter option ids: a dish matches one option of every filter
|
|
164
|
+
* that has a selected option.
|
|
165
|
+
*/
|
|
166
|
+
filterOptionIds?: readonly Id[];
|
|
167
|
+
}>;
|
|
168
|
+
|
|
169
|
+
/** One page of dishes of a section or a search. */
|
|
170
|
+
export type MenuListing = Readonly<{
|
|
171
|
+
dishes: readonly Dish[];
|
|
172
|
+
/**
|
|
173
|
+
* Dishes of all pages; on a page after the last one a backend may not
|
|
174
|
+
* know it and answers 0 (Shopware).
|
|
175
|
+
*/
|
|
176
|
+
total: number;
|
|
177
|
+
page: number;
|
|
178
|
+
limit: number;
|
|
179
|
+
filters: readonly ListingFilter[];
|
|
180
|
+
sortings: readonly Readonly<{ key: string; label: string }>[];
|
|
181
|
+
/** The sorting applied (the default one without a choice). */
|
|
182
|
+
sorting: string | null;
|
|
183
|
+
/** The filter option ids applied. */
|
|
184
|
+
filterOptionIds: readonly Id[];
|
|
185
|
+
}>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addDays,
|
|
3
|
+
calendarDate,
|
|
4
|
+
invalidValue,
|
|
5
|
+
MINUTES_PER_DAY,
|
|
6
|
+
timeOfDay,
|
|
7
|
+
weekdayOf,
|
|
8
|
+
zonedDateTime,
|
|
9
|
+
type CalendarDate,
|
|
10
|
+
type TimeOfDay,
|
|
11
|
+
type TimeZone,
|
|
12
|
+
} from "../kernel";
|
|
13
|
+
import {
|
|
14
|
+
intervalsOn,
|
|
15
|
+
isHoliday,
|
|
16
|
+
type Holiday,
|
|
17
|
+
type OpeningHours,
|
|
18
|
+
} from "../restaurant";
|
|
19
|
+
|
|
20
|
+
/** Minutes between two wished times the guest can choose. */
|
|
21
|
+
export const WISHED_TIME_STEP_MINUTES = 5;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* How long the kitchen needs before an order is delivered or ready for
|
|
25
|
+
* pickup, in whole minutes; set per shipping method.
|
|
26
|
+
*/
|
|
27
|
+
export type LeadTime = Readonly<{ minutes: number }>;
|
|
28
|
+
|
|
29
|
+
export function leadTime(minutes: number): LeadTime {
|
|
30
|
+
if (!Number.isInteger(minutes) || minutes < 0 || minutes >= MINUTES_PER_DAY) {
|
|
31
|
+
throw invalidValue("A lead time is 0 to 1439 whole minutes.", minutes);
|
|
32
|
+
}
|
|
33
|
+
return Object.freeze({ minutes });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* When the guest wants the order delivered or picked up
|
|
38
|
+
* ("Wunschlieferzeit"/"Wunschabholzeit"): a service date and a time on the
|
|
39
|
+
* 5-minute grid, in the restaurant's time zone. The date lets an order
|
|
40
|
+
* placed before midnight be wished for shortly after it.
|
|
41
|
+
*/
|
|
42
|
+
export type WishedTime = Readonly<{ date: CalendarDate; time: TimeOfDay }>;
|
|
43
|
+
|
|
44
|
+
export function isOnWishedTimeGrid(time: TimeOfDay): boolean {
|
|
45
|
+
return time.minutes % WISHED_TIME_STEP_MINUTES === 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function wishedTime(
|
|
49
|
+
date: string,
|
|
50
|
+
time: string | number | Readonly<{ minutes: number }>,
|
|
51
|
+
): WishedTime {
|
|
52
|
+
// a given TimeOfDay is checked again: it may come from JSON
|
|
53
|
+
const checked = timeOfDay(typeof time === "object" ? time.minutes : time);
|
|
54
|
+
if (!isOnWishedTimeGrid(checked)) {
|
|
55
|
+
throw invalidValue(
|
|
56
|
+
`A wished time is on the ${WISHED_TIME_STEP_MINUTES}-minute grid.`,
|
|
57
|
+
checked.minutes,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze({ date: calendarDate(date), time: checked });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** What decides when the restaurant can serve an order. */
|
|
64
|
+
export type ServiceSchedule = Readonly<{
|
|
65
|
+
timeZone: TimeZone;
|
|
66
|
+
openingHours: OpeningHours;
|
|
67
|
+
holidays: readonly Holiday[];
|
|
68
|
+
}>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The earliest wished time from now: now plus the lead time (real
|
|
72
|
+
* minutes), rounded up to the grid, within an opening interval of today or
|
|
73
|
+
* tomorrow that is not a holiday, and less than 24 hours ahead; null if
|
|
74
|
+
* there is none.
|
|
75
|
+
*/
|
|
76
|
+
export function earliestWishedTime(
|
|
77
|
+
now: Date,
|
|
78
|
+
lead: LeadTime,
|
|
79
|
+
schedule: ServiceSchedule,
|
|
80
|
+
): WishedTime | null {
|
|
81
|
+
const { timeZone, openingHours, holidays } = schedule;
|
|
82
|
+
const current = zonedDateTime(now, timeZone);
|
|
83
|
+
const today = current.date;
|
|
84
|
+
const ready = zonedDateTime(
|
|
85
|
+
new Date(now.getTime() + lead.minutes * 60_000),
|
|
86
|
+
timeZone,
|
|
87
|
+
);
|
|
88
|
+
// minutes since today's midnight; a time tomorrow counts on from 1440
|
|
89
|
+
const dayOffset = ready.date === today ? 0 : 1;
|
|
90
|
+
if (ready.date !== today && ready.date !== addDays(today, 1)) return null;
|
|
91
|
+
const earliest = dayOffset * MINUTES_PER_DAY + ready.time.minutes;
|
|
92
|
+
const limit = current.time.minutes + MINUTES_PER_DAY;
|
|
93
|
+
const step = WISHED_TIME_STEP_MINUTES;
|
|
94
|
+
|
|
95
|
+
for (const offset of [0, 1]) {
|
|
96
|
+
const date = addDays(today, offset);
|
|
97
|
+
if (isHoliday(holidays, date)) continue;
|
|
98
|
+
const base = offset * MINUTES_PER_DAY;
|
|
99
|
+
for (const interval of intervalsOn(openingHours, weekdayOf(date))) {
|
|
100
|
+
const start = base + interval.opens.minutes;
|
|
101
|
+
const end = base + interval.closes.minutes;
|
|
102
|
+
const candidate = Math.ceil(Math.max(earliest, start) / step) * step;
|
|
103
|
+
if (candidate > end || candidate >= limit) continue;
|
|
104
|
+
const serviceDate = addDays(
|
|
105
|
+
today,
|
|
106
|
+
Math.floor(candidate / MINUTES_PER_DAY),
|
|
107
|
+
);
|
|
108
|
+
// 24:00 is 00:00 of the next day, which may be a holiday
|
|
109
|
+
if (serviceDate !== date && isHoliday(holidays, serviceDate)) continue;
|
|
110
|
+
return wishedTime(serviceDate, candidate % MINUTES_PER_DAY);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { Address } from "../customer";
|
|
2
|
+
import type { Id, Media, Money } from "../kernel";
|
|
3
|
+
import type { DishConfiguration } from "../menu";
|
|
4
|
+
import type { LeadTime, WishedTime } from "./time";
|
|
5
|
+
|
|
6
|
+
/** How the order reaches the guest: "Lieferung" or "Abholung". */
|
|
7
|
+
export type Fulfillment = "delivery" | "pickup";
|
|
8
|
+
|
|
9
|
+
/** A way to get the order ("Lieferung", "Abholung"), with its lead time. */
|
|
10
|
+
export type ShippingMethod = Readonly<{
|
|
11
|
+
id: Id;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string | null;
|
|
14
|
+
fulfillment: Fulfillment;
|
|
15
|
+
/** Unknown lead time: the storefront assumes its default. */
|
|
16
|
+
leadTime: LeadTime | null;
|
|
17
|
+
media: Media | null;
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
/** A way to pay ("Barzahlung", "PayPal"). */
|
|
21
|
+
export type PaymentMethod = Readonly<{
|
|
22
|
+
id: Id;
|
|
23
|
+
name: string;
|
|
24
|
+
description: string | null;
|
|
25
|
+
media: Media | null;
|
|
26
|
+
/** Payment happens on another site after the order (redirect). */
|
|
27
|
+
redirects: boolean;
|
|
28
|
+
/** The shop's default, chosen when the selected one cannot be used. */
|
|
29
|
+
preferred: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The shipping and payment method the visitor's next order uses, also
|
|
34
|
+
* before anything is in the cart (null where the backend has none).
|
|
35
|
+
*/
|
|
36
|
+
export type CheckoutSelection = Readonly<{
|
|
37
|
+
shippingMethodId: Id | null;
|
|
38
|
+
paymentMethodId: Id | null;
|
|
39
|
+
}>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The wished times the guest can choose today: from the earliest wished
|
|
43
|
+
* time to the end of the current or next opening interval.
|
|
44
|
+
*/
|
|
45
|
+
export type OrderingWindow = Readonly<{
|
|
46
|
+
earliest: WishedTime;
|
|
47
|
+
latest: WishedTime;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
/** An extra on a cart line, as it was priced. */
|
|
51
|
+
export type CartLineExtra = Readonly<{
|
|
52
|
+
id: Id;
|
|
53
|
+
name: string;
|
|
54
|
+
/** For one dish. */
|
|
55
|
+
unitPrice: Money;
|
|
56
|
+
}>;
|
|
57
|
+
|
|
58
|
+
/** The chosen option of one variant group ("Größe: Groß 40 cm"). */
|
|
59
|
+
export type VariantChoice = Readonly<{ group: string; option: string }>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* One configured dish in the cart with its quantity: the dish (variant),
|
|
63
|
+
* its extras and its removed ingredients are one line, priced together.
|
|
64
|
+
* Two lines never hold the same configuration.
|
|
65
|
+
*/
|
|
66
|
+
export type CartLine = Readonly<{
|
|
67
|
+
id: Id;
|
|
68
|
+
configuration: DishConfiguration;
|
|
69
|
+
/** Menu number of the dish or the chosen variant. */
|
|
70
|
+
dishNumber: string;
|
|
71
|
+
/** The dish's name as ordered, without extras and removals. */
|
|
72
|
+
name: string;
|
|
73
|
+
/** The chosen variant's options, in the dish's group order. */
|
|
74
|
+
variant: readonly VariantChoice[];
|
|
75
|
+
/** In the order the guest chose them. */
|
|
76
|
+
extras: readonly CartLineExtra[];
|
|
77
|
+
/** Names of the removed main ingredients, in the guest's order. */
|
|
78
|
+
removedIngredients: readonly string[];
|
|
79
|
+
quantity: number;
|
|
80
|
+
/** Dish plus extras, for one. */
|
|
81
|
+
unitPrice: Money;
|
|
82
|
+
totalPrice: Money;
|
|
83
|
+
media: Media | null;
|
|
84
|
+
}>;
|
|
85
|
+
|
|
86
|
+
export type CartMessageCode =
|
|
87
|
+
| "dish_unavailable"
|
|
88
|
+
| "quantity_adjusted"
|
|
89
|
+
| "price_changed"
|
|
90
|
+
| "shipping_method_blocked"
|
|
91
|
+
| "payment_method_blocked"
|
|
92
|
+
| "voucher_invalid"
|
|
93
|
+
| "minimum_order_value"
|
|
94
|
+
| "ordering_closed"
|
|
95
|
+
| "other";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* What the backend says about the cart ("Pizza Hawaii ist nicht mehr
|
|
99
|
+
* verfügbar"). `error` messages block the order.
|
|
100
|
+
*/
|
|
101
|
+
export type CartMessage = Readonly<{
|
|
102
|
+
code: CartMessageCode;
|
|
103
|
+
severity: "info" | "warning" | "error";
|
|
104
|
+
/** The backend's text, shown when the storefront has none of its own. */
|
|
105
|
+
text: string;
|
|
106
|
+
/** Line, voucher code or method the message is about. */
|
|
107
|
+
subjectId: Id | null;
|
|
108
|
+
}>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A price reduction of the cart: from a voucher the guest entered (`code`)
|
|
112
|
+
* or applied automatically (`code` null). `amount` is negative.
|
|
113
|
+
*/
|
|
114
|
+
export type CartDiscount = Readonly<{
|
|
115
|
+
code: string | null;
|
|
116
|
+
name: string;
|
|
117
|
+
amount: Money;
|
|
118
|
+
}>;
|
|
119
|
+
|
|
120
|
+
/** The guest's cart ("Warenkorb"). */
|
|
121
|
+
export type Cart = Readonly<{
|
|
122
|
+
/** In the order they were added. */
|
|
123
|
+
lines: readonly CartLine[];
|
|
124
|
+
discounts: readonly CartDiscount[];
|
|
125
|
+
/** Sum of the lines and the discounts, before shipping. */
|
|
126
|
+
subtotal: Money;
|
|
127
|
+
shippingCosts: Money;
|
|
128
|
+
/** What the guest pays: subtotal plus shipping. */
|
|
129
|
+
total: Money;
|
|
130
|
+
/** Taxes included in the total, per rate (percent). */
|
|
131
|
+
taxes: readonly Readonly<{ rate: number; amount: Money }>[];
|
|
132
|
+
shippingMethodId: Id | null;
|
|
133
|
+
paymentMethodId: Id | null;
|
|
134
|
+
messages: readonly CartMessage[];
|
|
135
|
+
}>;
|
|
136
|
+
|
|
137
|
+
/** Our own order status; adapters map their backend states onto it. */
|
|
138
|
+
export type OrderStatus = "open" | "in_progress" | "completed" | "cancelled";
|
|
139
|
+
|
|
140
|
+
export type PaymentStatus =
|
|
141
|
+
"open" | "paid" | "failed" | "cancelled" | "refunded";
|
|
142
|
+
|
|
143
|
+
/** A line of a placed order: one dish configuration, as it was priced. */
|
|
144
|
+
export type OrderLine = Readonly<{
|
|
145
|
+
id: Id;
|
|
146
|
+
/** What was ordered, so the order can be repeated. */
|
|
147
|
+
configuration: DishConfiguration;
|
|
148
|
+
dishNumber: string;
|
|
149
|
+
name: string;
|
|
150
|
+
extras: readonly Readonly<{ name: string; unitPrice: Money }>[];
|
|
151
|
+
removedIngredients: readonly string[];
|
|
152
|
+
quantity: number;
|
|
153
|
+
unitPrice: Money;
|
|
154
|
+
totalPrice: Money;
|
|
155
|
+
}>;
|
|
156
|
+
|
|
157
|
+
/** A placed order ("Bestellung"). */
|
|
158
|
+
export type Order = Readonly<{
|
|
159
|
+
id: Id;
|
|
160
|
+
/** Order number shown to the guest. */
|
|
161
|
+
number: string;
|
|
162
|
+
/** ISO 8601 date-time. */
|
|
163
|
+
placedAt: string;
|
|
164
|
+
status: OrderStatus;
|
|
165
|
+
paymentStatus: PaymentStatus;
|
|
166
|
+
fulfillment: Fulfillment;
|
|
167
|
+
wishedTime: WishedTime | null;
|
|
168
|
+
shippingMethod: Readonly<{ id: Id; name: string }>;
|
|
169
|
+
paymentMethod: Readonly<{ id: Id; name: string }>;
|
|
170
|
+
lines: readonly OrderLine[];
|
|
171
|
+
discounts: readonly CartDiscount[];
|
|
172
|
+
/** Sum of the lines and the discounts, before shipping. */
|
|
173
|
+
subtotal: Money;
|
|
174
|
+
shippingCosts: Money;
|
|
175
|
+
total: Money;
|
|
176
|
+
/** Taxes per rate (percent): included in the total, or on top of it. */
|
|
177
|
+
taxes: readonly Readonly<{ rate: number; amount: Money }>[];
|
|
178
|
+
/** Gross prices (restaurants); false for a net (business) order. */
|
|
179
|
+
taxIncluded: boolean;
|
|
180
|
+
billingAddress: Address;
|
|
181
|
+
/** Null for pickup. */
|
|
182
|
+
deliveryAddress: Address | null;
|
|
183
|
+
email: string;
|
|
184
|
+
/** The guest's note to the restaurant, without the wished time. */
|
|
185
|
+
note: string | null;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
/** The answer to placing an order: the order and where to pay, if elsewhere. */
|
|
189
|
+
export type PlacedOrder = Readonly<{
|
|
190
|
+
order: Order;
|
|
191
|
+
/** A payment on another site: send the guest there. */
|
|
192
|
+
redirectUrl: string | null;
|
|
193
|
+
/** The order is placed, but its payment could not be started. */
|
|
194
|
+
paymentFailed: boolean;
|
|
195
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calendarDate,
|
|
3
|
+
invalidValue,
|
|
4
|
+
type CalendarDate,
|
|
5
|
+
type Id,
|
|
6
|
+
} from "../kernel";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whole days on which the restaurant stays closed although the weekly
|
|
10
|
+
* hours say open ("Betriebsferien"), in its time zone, both included.
|
|
11
|
+
*/
|
|
12
|
+
export type Holiday = Readonly<{
|
|
13
|
+
id: Id;
|
|
14
|
+
firstDay: CalendarDate;
|
|
15
|
+
lastDay: CalendarDate;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
export function holiday(input: {
|
|
19
|
+
id: Id;
|
|
20
|
+
firstDay: string;
|
|
21
|
+
lastDay: string;
|
|
22
|
+
}): Holiday {
|
|
23
|
+
const firstDay = calendarDate(input.firstDay);
|
|
24
|
+
const lastDay = calendarDate(input.lastDay);
|
|
25
|
+
if (lastDay < firstDay) {
|
|
26
|
+
throw invalidValue("A holiday does not end before it starts.", input);
|
|
27
|
+
}
|
|
28
|
+
return Object.freeze({ id: input.id, firstDay, lastDay });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isHoliday(
|
|
32
|
+
holidays: readonly Holiday[],
|
|
33
|
+
date: CalendarDate,
|
|
34
|
+
): boolean {
|
|
35
|
+
return holidays.some(
|
|
36
|
+
(entry) => entry.firstDay <= date && date <= entry.lastDay,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatTimeOfDay,
|
|
3
|
+
invalidValue,
|
|
4
|
+
MINUTES_PER_DAY,
|
|
5
|
+
timeOfDay,
|
|
6
|
+
type TimeOfDay,
|
|
7
|
+
type Weekday,
|
|
8
|
+
} from "../kernel";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* When an opening interval closes: minutes since midnight, 1 to 1440,
|
|
12
|
+
* where 1440 (`24:00`) is the end of the day.
|
|
13
|
+
*/
|
|
14
|
+
export type ClosingTime = Readonly<{ minutes: number }>;
|
|
15
|
+
|
|
16
|
+
export function closingTime(value: string | number): ClosingTime {
|
|
17
|
+
if (value === "24:00" || value === "24:00:00" || value === MINUTES_PER_DAY) {
|
|
18
|
+
return Object.freeze({ minutes: MINUTES_PER_DAY });
|
|
19
|
+
}
|
|
20
|
+
return timeOfDay(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A span of one day in which the restaurant is open and takes orders, e.g.
|
|
25
|
+
* 11:30–14:30, or 18:00–24:00 up to the end of the day. It does not cross
|
|
26
|
+
* midnight: a late-night opening is two intervals (18:00–24:00 and
|
|
27
|
+
* 00:00–02:00 of the next weekday).
|
|
28
|
+
*/
|
|
29
|
+
export type OpeningInterval = Readonly<{
|
|
30
|
+
opens: TimeOfDay;
|
|
31
|
+
closes: ClosingTime;
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
export function openingInterval(
|
|
35
|
+
opens: string | TimeOfDay,
|
|
36
|
+
closes: string | ClosingTime,
|
|
37
|
+
): OpeningInterval {
|
|
38
|
+
const from = typeof opens === "string" ? timeOfDay(opens) : opens;
|
|
39
|
+
const to = typeof closes === "string" ? closingTime(closes) : closes;
|
|
40
|
+
if (from.minutes >= to.minutes || to.minutes > MINUTES_PER_DAY) {
|
|
41
|
+
throw invalidValue(
|
|
42
|
+
"An opening interval opens before it closes, by 24:00 at the latest.",
|
|
43
|
+
`${formatTimeOfDay(from)}–${formatTimeOfDay(to)}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return Object.freeze({ opens: from, closes: to });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Whether the time lies in the interval, both ends included. */
|
|
50
|
+
export function intervalContains(
|
|
51
|
+
interval: OpeningInterval,
|
|
52
|
+
time: TimeOfDay,
|
|
53
|
+
): boolean {
|
|
54
|
+
return (
|
|
55
|
+
time.minutes >= interval.opens.minutes &&
|
|
56
|
+
time.minutes <= interval.closes.minutes
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type WeeklyOpeningInterval = Readonly<{
|
|
61
|
+
weekday: Weekday;
|
|
62
|
+
interval: OpeningInterval;
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The weekly opening hours ("Öffnungszeiten"). A weekday without intervals
|
|
67
|
+
* is a weekly closing day ("Ruhetag").
|
|
68
|
+
*/
|
|
69
|
+
export type OpeningHours = Readonly<{
|
|
70
|
+
intervals: readonly WeeklyOpeningInterval[];
|
|
71
|
+
}>;
|
|
72
|
+
|
|
73
|
+
/** Opening hours in weekday and opening time order, frozen. */
|
|
74
|
+
export function sortOpeningHours(
|
|
75
|
+
intervals: readonly WeeklyOpeningInterval[],
|
|
76
|
+
): OpeningHours {
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
intervals: Object.freeze(
|
|
79
|
+
[...intervals].sort(
|
|
80
|
+
(a, b) =>
|
|
81
|
+
a.weekday - b.weekday ||
|
|
82
|
+
a.interval.opens.minutes - b.interval.opens.minutes,
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The intervals of one weekday, in time order. */
|
|
89
|
+
export function intervalsOn(
|
|
90
|
+
hours: OpeningHours,
|
|
91
|
+
weekday: Weekday,
|
|
92
|
+
): OpeningInterval[] {
|
|
93
|
+
return hours.intervals
|
|
94
|
+
.filter((entry) => entry.weekday === weekday)
|
|
95
|
+
.map((entry) => entry.interval)
|
|
96
|
+
.sort((a, b) => a.opens.minutes - b.opens.minutes);
|
|
97
|
+
}
|