@shopbite-de/storefront 2.6.1 → 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.
Files changed (469) hide show
  1. package/.env.example +13 -0
  2. package/.github/workflows/ci.yaml +2 -0
  3. package/CLAUDE.md +54 -30
  4. package/GLOSSARY.md +327 -0
  5. package/README.md +5 -6
  6. package/app/app.vue +50 -40
  7. package/app/components/Address/Card.vue +2 -2
  8. package/app/components/Address/Detail.vue +17 -45
  9. package/app/components/Address/Form.vue +38 -26
  10. package/app/components/BranchSwitch.vue +40 -0
  11. package/app/components/Cart/Bar.vue +9 -9
  12. package/app/components/Cart/Item.vue +27 -36
  13. package/app/components/Cart/QuickView.vue +17 -16
  14. package/app/components/Cart/Upsell.vue +19 -27
  15. package/app/components/Category/Breadcrumb.vue +3 -8
  16. package/app/components/Category/FilterGroup.vue +6 -6
  17. package/app/components/Category/Listing.vue +44 -66
  18. package/app/components/Checkout/DeliveryTimeSelect.vue +21 -48
  19. package/app/components/Checkout/OrderMessage.vue +29 -0
  20. package/app/components/Checkout/OrdererAddress.vue +40 -0
  21. package/app/components/Checkout/PaymentAndDelivery.vue +40 -35
  22. package/app/components/Checkout/Summary.vue +89 -74
  23. package/app/components/Checkout/VoucherInput.vue +8 -8
  24. package/app/components/Contact/Form.vue +97 -13
  25. package/app/components/Footer.vue +2 -2
  26. package/app/components/Header.vue +9 -9
  27. package/app/components/Home/Categories.vue +13 -17
  28. package/app/components/Home/Facts.vue +6 -4
  29. package/app/components/Home/Hero.vue +1 -1
  30. package/app/components/Home/Highlights.vue +8 -8
  31. package/app/components/Home/Restaurant.vue +2 -2
  32. package/app/components/Menu/BonCard.vue +21 -37
  33. package/app/components/Menu/CartPanel.vue +2 -2
  34. package/app/components/Menu/CategoryIndex.vue +8 -12
  35. package/app/components/Menu/OrderMode.vue +2 -2
  36. package/app/components/Menu/SectionHeader.vue +6 -10
  37. package/app/components/Navigation/MobileTop.vue +12 -20
  38. package/app/components/Order/Confirmation.vue +10 -10
  39. package/app/components/Order/Detail.vue +47 -49
  40. package/app/components/Product/Configurator.vue +46 -30
  41. package/app/components/Product/CrossSelling.vue +56 -71
  42. package/app/components/Product/DeselectIngredient.vue +10 -11
  43. package/app/components/Product/Detail.vue +62 -55
  44. package/app/components/Product/FoodLabels.vue +4 -9
  45. package/app/components/Product/QuickView.vue +22 -30
  46. package/app/components/User/Detail.vue +20 -43
  47. package/app/components/User/LoginForm.vue +11 -17
  48. package/app/components/User/RegistrationForm.vue +3 -3
  49. package/app/components/Wishlist.vue +99 -106
  50. package/app/components/WishlistSaveButton.vue +17 -9
  51. package/app/composables/useAccountAddresses.ts +89 -0
  52. package/app/composables/useAccountOrders.ts +35 -0
  53. package/app/composables/useAddToCart.ts +63 -139
  54. package/app/composables/useCartData.ts +55 -0
  55. package/app/composables/useCartMutations.ts +93 -85
  56. package/app/composables/useCartUpsell.ts +27 -71
  57. package/app/composables/useCategoryListing.ts +36 -59
  58. package/app/composables/useCategorySeo.ts +11 -16
  59. package/app/composables/useCheckoutMethodGuard.ts +22 -46
  60. package/app/composables/useCheckoutMethods.ts +89 -0
  61. package/app/composables/useCheckoutOrderMessage.ts +19 -0
  62. package/app/composables/useCheckoutOrderer.ts +69 -0
  63. package/app/composables/useCommercePrice.ts +46 -9
  64. package/app/composables/useContactForm.ts +25 -32
  65. package/app/composables/useCustomer.ts +169 -0
  66. package/app/composables/useDeliveryTime.ts +112 -122
  67. package/app/composables/useHolidays.ts +12 -62
  68. package/app/composables/useHomeMenuCategories.ts +5 -5
  69. package/app/composables/useListingSearch.ts +9 -8
  70. package/app/composables/useLiveShopData.ts +15 -9
  71. package/app/composables/useMenuRootId.ts +3 -6
  72. package/app/composables/useMenuSection.ts +14 -0
  73. package/app/composables/useMenuSectionSchema.ts +23 -30
  74. package/app/composables/useNavigation.ts +24 -29
  75. package/app/composables/useOpeningHours.ts +21 -0
  76. package/app/composables/useOpeningHoursData.ts +9 -9
  77. package/app/composables/useOrder.ts +37 -0
  78. package/app/composables/useOrderMode.ts +18 -16
  79. package/app/composables/usePlaceOrder.ts +37 -0
  80. package/app/composables/useProductCartQuantity.ts +6 -6
  81. package/app/composables/useProductDetail.ts +28 -53
  82. package/app/composables/useProductEvents.ts +6 -5
  83. package/app/composables/useProductQuickView.ts +35 -68
  84. package/app/composables/useRegistrationForm.ts +85 -34
  85. package/app/composables/useRestaurantSchema.ts +7 -7
  86. package/app/composables/useSearchTracking.ts +6 -6
  87. package/app/composables/useSectionRoute.ts +48 -0
  88. package/app/composables/useServiceSchedule.ts +23 -0
  89. package/app/composables/useShippingLeadTime.ts +8 -6
  90. package/app/composables/useShippingMethodChoice.ts +13 -23
  91. package/app/composables/useShippingMethods.ts +31 -0
  92. package/app/composables/useShopConfig.ts +60 -0
  93. package/app/composables/useShopData.ts +20 -0
  94. package/app/composables/useSortingSelection.ts +5 -8
  95. package/app/composables/useStoreStatus.ts +13 -37
  96. package/app/composables/useTopSellers.ts +3 -3
  97. package/app/composables/useTrackEvent.ts +29 -24
  98. package/app/composables/useVoucherCode.ts +47 -12
  99. package/app/composables/useWishlistEntries.ts +233 -177
  100. package/app/error.vue +3 -2
  101. package/app/layouts/account.vue +4 -3
  102. package/app/pages/[...all].vue +6 -16
  103. package/app/pages/account/recover/password/index.vue +6 -14
  104. package/app/pages/anmelden.vue +1 -1
  105. package/app/pages/bestellung/[id]/erfolg.vue +3 -3
  106. package/app/pages/bestellung/[id]/fehler.vue +18 -29
  107. package/app/pages/bestellung/kasse.vue +24 -7
  108. package/app/pages/konto/adressen.vue +95 -40
  109. package/app/pages/konto/bestellungen.vue +10 -13
  110. package/app/pages/konto/index.vue +12 -2
  111. package/app/pages/konto/profil.vue +241 -42
  112. package/app/pages/passwort-vergessen.vue +5 -10
  113. package/app/pages/registrierung/bestaetigen.vue +9 -23
  114. package/app/pages/registrierung/index.vue +19 -11
  115. package/app/pages/suche.vue +29 -29
  116. package/app/plugins/shopware-layer-offline.ts +38 -0
  117. package/app/plugins/visitor-has-session.server.ts +19 -0
  118. package/app/utils/accountMessages.ts +74 -0
  119. package/app/utils/accountReads.ts +34 -0
  120. package/app/utils/bffWrite.ts +89 -0
  121. package/app/utils/dish.ts +121 -0
  122. package/app/utils/leadTime.ts +25 -29
  123. package/app/utils/media.ts +11 -17
  124. package/app/utils/menuGroups.ts +22 -35
  125. package/app/utils/money.ts +41 -0
  126. package/app/utils/openingHours.ts +30 -30
  127. package/app/utils/orderStatus.ts +17 -0
  128. package/app/utils/productUrl.ts +14 -31
  129. package/app/utils/restaurantTime.ts +326 -0
  130. package/app/utils/schema.ts +39 -42
  131. package/app/utils/wishlist.ts +139 -0
  132. package/docs/adr/0001-backend-agnostic-storefront.md +409 -0
  133. package/eslint.config.mjs +42 -2
  134. package/nuxt.config.ts +28 -0
  135. package/package.json +1 -1
  136. package/server/adapters/memory/cart.ts +370 -0
  137. package/server/adapters/memory/catalog.ts +367 -0
  138. package/server/adapters/memory/contact.ts +89 -0
  139. package/server/adapters/memory/customer.ts +458 -0
  140. package/server/adapters/memory/demo-menu.json +1190 -0
  141. package/server/adapters/memory/demoImages.ts +13 -0
  142. package/server/adapters/memory/demoMenu.ts +234 -0
  143. package/server/adapters/memory/demoNavigation.ts +71 -0
  144. package/server/adapters/memory/index.ts +122 -0
  145. package/server/adapters/memory/navigation.ts +168 -0
  146. package/server/adapters/memory/ordering.ts +379 -0
  147. package/server/adapters/memory/seed.ts +136 -0
  148. package/server/adapters/memory/wishlist.ts +166 -0
  149. package/server/adapters/notImplemented.ts +67 -0
  150. package/server/adapters/registry.ts +32 -0
  151. package/server/adapters/runtimeConfig.ts +14 -0
  152. package/server/adapters/shopware/cart.ts +792 -0
  153. package/server/adapters/shopware/catalog.ts +850 -0
  154. package/server/adapters/shopware/checkout.ts +138 -0
  155. package/server/adapters/shopware/contact.ts +255 -0
  156. package/server/adapters/shopware/customer.ts +460 -0
  157. package/server/adapters/shopware/index.ts +165 -0
  158. package/server/adapters/shopware/menuRoot.ts +24 -0
  159. package/server/adapters/shopware/navigation.ts +426 -0
  160. package/server/adapters/shopware/ordering.ts +1185 -0
  161. package/server/adapters/shopware/request.ts +67 -0
  162. package/server/adapters/shopware/shop.ts +249 -0
  163. package/server/adapters/shopware/storeApi.ts +62 -0
  164. package/server/adapters/shopware/wishlist.ts +473 -0
  165. package/server/api/__sitemap__/urls.get.ts +10 -38
  166. package/server/api/account/addresses/[addressId]/default.post.ts +13 -0
  167. package/server/api/account/addresses/[addressId].delete.ts +14 -0
  168. package/server/api/account/addresses/[addressId].patch.ts +15 -0
  169. package/server/api/account/addresses/index.get.ts +6 -0
  170. package/server/api/account/addresses/index.post.ts +9 -0
  171. package/server/api/account/email.post.ts +10 -0
  172. package/server/api/account/index.delete.ts +11 -0
  173. package/server/api/account/index.get.ts +9 -0
  174. package/server/api/account/login.post.ts +14 -0
  175. package/server/api/account/logout.post.ts +11 -0
  176. package/server/api/account/orders.get.ts +13 -0
  177. package/server/api/account/password-reset/confirm.post.ts +13 -0
  178. package/server/api/account/password-reset.post.ts +16 -0
  179. package/server/api/account/password.post.ts +18 -0
  180. package/server/api/account/profile.patch.ts +6 -0
  181. package/server/api/account/register/confirm.post.ts +13 -0
  182. package/server/api/account/register.post.ts +15 -0
  183. package/server/api/breadcrumb/[sectionId].get.ts +33 -0
  184. package/server/api/cart/index.get.ts +4 -0
  185. package/server/api/cart/lines/[lineId].delete.ts +6 -0
  186. package/server/api/cart/lines/[lineId].patch.ts +10 -0
  187. package/server/api/cart/lines.post.ts +10 -0
  188. package/server/api/cart/vouchers/[code].delete.ts +9 -0
  189. package/server/api/cart/vouchers.post.ts +12 -0
  190. package/server/api/checkout/guest.post.ts +13 -0
  191. package/server/api/checkout/orderer/addresses/[addressId].patch.ts +16 -0
  192. package/server/api/checkout/orderer.get.ts +10 -0
  193. package/server/api/checkout/orders.post.ts +60 -0
  194. package/server/api/checkout/payment-methods.get.ts +9 -0
  195. package/server/api/checkout/selection.get.ts +10 -0
  196. package/server/api/checkout/selection.post.ts +14 -0
  197. package/server/api/checkout/shipping-methods.get.ts +9 -0
  198. package/server/api/contact/form.get.ts +13 -0
  199. package/server/api/contact/index.post.ts +24 -0
  200. package/server/api/listing/[sectionId].get.ts +33 -0
  201. package/server/api/menu/dishes/[dishId]/variant.get.ts +29 -0
  202. package/server/api/menu/dishes/[dishId].get.ts +19 -0
  203. package/server/api/menu/dishes/index.get.ts +26 -0
  204. package/server/api/menu/media/[name].get.ts +18 -0
  205. package/server/api/menu/root.get.ts +12 -0
  206. package/server/api/menu/sections/[sectionId].get.ts +18 -0
  207. package/server/api/menu/upsell.get.ts +12 -0
  208. package/server/api/navigation/[kind].get.ts +75 -0
  209. package/server/api/orders/[orderId]/payment.post.ts +24 -0
  210. package/server/api/orders/[orderId].get.ts +13 -0
  211. package/server/api/payment-methods.get.ts +11 -15
  212. package/server/api/resolve-path.get.ts +20 -0
  213. package/server/api/search.get.ts +16 -80
  214. package/server/api/session.post.ts +18 -0
  215. package/server/api/shop/branches.get.ts +9 -0
  216. package/server/api/shop/config.get.ts +9 -0
  217. package/server/api/shop/holidays.get.ts +9 -0
  218. package/server/api/shop/opening-hours.get.ts +9 -0
  219. package/server/api/top-sellers.get.ts +14 -50
  220. package/server/api/wishlist/entries/[entryId].delete.ts +8 -0
  221. package/server/api/wishlist/entries.post.ts +13 -0
  222. package/server/api/wishlist/index.get.ts +13 -0
  223. package/server/api/wishlist/merge.post.ts +12 -0
  224. package/server/plugins/visitor-session.ts +35 -0
  225. package/server/ports/CartPort.ts +48 -0
  226. package/server/ports/CatalogPort.ts +66 -0
  227. package/server/ports/CheckoutPort.ts +128 -0
  228. package/server/ports/ContactPort.ts +38 -0
  229. package/server/ports/CustomerPort.ts +154 -0
  230. package/server/ports/NavigationPort.ts +58 -0
  231. package/server/ports/OrderPort.ts +31 -0
  232. package/server/ports/ShopPort.ts +29 -0
  233. package/server/ports/WishlistPort.ts +47 -0
  234. package/server/ports/index.ts +42 -0
  235. package/server/ports/session.ts +22 -0
  236. package/server/routes/llms.txt.ts +28 -154
  237. package/server/session/forwardedFor.ts +24 -0
  238. package/server/session/sameOrigin.ts +47 -0
  239. package/server/session/seal.ts +147 -0
  240. package/server/session/visitorSession.ts +288 -0
  241. package/server/utils/accountRoutes.ts +173 -0
  242. package/server/utils/backend.ts +21 -0
  243. package/server/utils/backoff.ts +18 -5
  244. package/server/utils/cacheKeys.ts +11 -0
  245. package/server/utils/cachePurge.ts +47 -27
  246. package/server/utils/cartRoutes.ts +124 -0
  247. package/server/utils/catalogData.ts +24 -0
  248. package/server/utils/checkoutRoutes.ts +326 -0
  249. package/server/utils/contactRoutes.ts +86 -0
  250. package/server/utils/domainHttp.ts +73 -0
  251. package/server/utils/listingParams.ts +49 -20
  252. package/server/utils/llmsTxt.ts +64 -19
  253. package/server/utils/navigationData.ts +14 -0
  254. package/server/utils/orderPlacement.ts +322 -0
  255. package/server/utils/outageBreaker.ts +126 -0
  256. package/server/utils/pathRoutes.ts +160 -0
  257. package/server/utils/requestBody.ts +43 -0
  258. package/server/utils/shopData.ts +132 -0
  259. package/server/utils/sitemap.ts +14 -36
  260. package/server/utils/storeApi.ts +71 -23
  261. package/server/utils/visitorSession.ts +209 -0
  262. package/server/utils/wishlistRoutes.ts +55 -0
  263. package/shared/domain/customer/index.ts +2 -0
  264. package/shared/domain/customer/types.ts +88 -0
  265. package/shared/domain/discoverability/index.ts +4 -0
  266. package/shared/domain/discoverability/paths.ts +93 -0
  267. package/shared/domain/discoverability/route.ts +32 -0
  268. package/shared/domain/discoverability/types.ts +75 -0
  269. package/shared/domain/index.ts +11 -0
  270. package/shared/domain/kernel/calendar.ts +88 -0
  271. package/shared/domain/kernel/errors.ts +100 -0
  272. package/shared/domain/kernel/freeze.ts +13 -0
  273. package/shared/domain/kernel/ids.ts +6 -0
  274. package/shared/domain/kernel/index.ts +8 -0
  275. package/shared/domain/kernel/media.ts +17 -0
  276. package/shared/domain/kernel/money.ts +104 -0
  277. package/shared/domain/kernel/timeOfDay.ts +39 -0
  278. package/shared/domain/menu/dishConfiguration.ts +72 -0
  279. package/shared/domain/menu/index.ts +3 -0
  280. package/shared/domain/menu/types.ts +185 -0
  281. package/shared/domain/ordering/index.ts +3 -0
  282. package/shared/domain/ordering/time.ts +114 -0
  283. package/shared/domain/ordering/types.ts +195 -0
  284. package/shared/domain/restaurant/holiday.ts +38 -0
  285. package/shared/domain/restaurant/index.ts +4 -0
  286. package/shared/domain/restaurant/openingInterval.ts +97 -0
  287. package/shared/domain/restaurant/types.ts +75 -0
  288. package/test/a11y/presets.test.ts +49 -31
  289. package/test/contract/cart.contract.ts +592 -0
  290. package/test/contract/cart.spec.ts +5 -0
  291. package/test/contract/cartFixtures.ts +573 -0
  292. package/test/contract/catalog.contract.ts +714 -0
  293. package/test/contract/catalog.spec.ts +5 -0
  294. package/test/contract/catalogFixtures.ts +572 -0
  295. package/test/contract/checkout.contract.ts +123 -0
  296. package/test/contract/checkout.spec.ts +5 -0
  297. package/test/contract/contact.contract.ts +149 -0
  298. package/test/contract/contact.spec.ts +4 -0
  299. package/test/contract/contactFixtures.ts +148 -0
  300. package/test/contract/customer.contract.ts +831 -0
  301. package/test/contract/customer.spec.ts +4 -0
  302. package/test/contract/customerFixtures.ts +468 -0
  303. package/test/contract/fixtures.ts +260 -0
  304. package/test/contract/harness.ts +45 -0
  305. package/test/contract/navigation.contract.ts +336 -0
  306. package/test/contract/navigation.spec.ts +5 -0
  307. package/test/contract/navigationFixtures.ts +311 -0
  308. package/test/contract/ordering.contract.ts +655 -0
  309. package/test/contract/ordering.spec.ts +4 -0
  310. package/test/contract/orderingFixtures.ts +498 -0
  311. package/test/contract/shop.contract.ts +164 -0
  312. package/test/contract/shop.spec.ts +5 -0
  313. package/test/contract/wishlist.contract.ts +375 -0
  314. package/test/contract/wishlist.spec.ts +4 -0
  315. package/test/contract/wishlistFixtures.ts +199 -0
  316. package/test/nuxt/AccountPagesPreset.test.ts +320 -83
  317. package/test/nuxt/AuthPagesPreset.test.ts +17 -24
  318. package/test/nuxt/CartBar.test.ts +12 -8
  319. package/test/nuxt/CartCheckoutPreset.test.ts +36 -33
  320. package/test/nuxt/CartItem.test.ts +39 -20
  321. package/test/nuxt/CartQuickView.test.ts +106 -0
  322. package/test/nuxt/CartUpsell.test.ts +37 -39
  323. package/test/nuxt/CategoryBreadcrumb.test.ts +26 -0
  324. package/test/nuxt/CheckoutFormsPreset.test.ts +92 -13
  325. package/test/nuxt/CheckoutOnePage.test.ts +28 -21
  326. package/test/nuxt/CheckoutPageMessage.test.ts +31 -0
  327. package/test/nuxt/CheckoutSummary.test.ts +163 -48
  328. package/test/nuxt/CheckoutVoucherInput.test.ts +77 -80
  329. package/test/nuxt/ContactFormPreset.test.ts +97 -36
  330. package/test/nuxt/DeliveryTimeSelect.test.ts +72 -45
  331. package/test/nuxt/FooterStoreStatus.test.ts +2 -2
  332. package/test/nuxt/HeaderFooterPreset.test.ts +11 -19
  333. package/test/nuxt/HomeCategories.test.ts +47 -0
  334. package/test/nuxt/HomeLeadTimes.test.ts +3 -3
  335. package/test/nuxt/MenuBonCard.test.ts +45 -32
  336. package/test/nuxt/NavigationMobileTop.test.ts +30 -28
  337. package/test/nuxt/OrderPagesPreset.test.ts +83 -52
  338. package/test/nuxt/PaymentAndDelivery.test.ts +25 -26
  339. package/test/nuxt/ProductConfigurator.test.ts +81 -0
  340. package/test/nuxt/ProductCrossSelling.test.ts +23 -20
  341. package/test/nuxt/ProductDeselectIngredient.test.ts +6 -9
  342. package/test/nuxt/ProductFoodLabels.test.ts +7 -24
  343. package/test/nuxt/ProductSheetPreset.test.ts +24 -24
  344. package/test/nuxt/RegisterConfirmPage.test.ts +26 -45
  345. package/test/nuxt/RegistrationForm.test.ts +57 -53
  346. package/test/nuxt/RegistrationPage.test.ts +37 -0
  347. package/test/nuxt/WishlistPage.test.ts +119 -43
  348. package/test/nuxt/WishlistSaveButton.test.ts +39 -12
  349. package/test/nuxt/accountSwitch.test.ts +106 -0
  350. package/test/nuxt/bffWrite.test.ts +41 -0
  351. package/test/nuxt/liveShopData.test.ts +36 -68
  352. package/test/nuxt/shopwareLayerOffline.test.ts +32 -0
  353. package/test/nuxt/useAddToCart.test.ts +116 -174
  354. package/test/nuxt/useCartMutations.test.ts +165 -113
  355. package/test/nuxt/useCartUpsell.test.ts +36 -63
  356. package/test/nuxt/useCategoryListing.test.ts +75 -118
  357. package/test/nuxt/useCheckoutMethodGuard.test.ts +54 -105
  358. package/test/nuxt/useCustomer.test.ts +127 -0
  359. package/test/nuxt/useDeliveryTime.test.ts +169 -157
  360. package/test/nuxt/useNavigation.test.ts +81 -0
  361. package/test/nuxt/useOpeningHoursData.test.ts +18 -18
  362. package/test/nuxt/useOrder.test.ts +38 -0
  363. package/test/nuxt/usePlaceOrder.test.ts +88 -0
  364. package/test/nuxt/useSearchTracking.test.ts +2 -2
  365. package/test/nuxt/useSectionRoute.test.ts +86 -0
  366. package/test/nuxt/useShippingLeadTime.test.ts +17 -17
  367. package/test/nuxt/useShippingMethodChoice.test.ts +22 -22
  368. package/test/nuxt/useShippingMethods.test.ts +71 -0
  369. package/test/nuxt/useShopConfig.test.ts +64 -0
  370. package/test/nuxt/useStoreStatus.test.ts +34 -50
  371. package/test/nuxt/useTopSellers.test.ts +6 -5
  372. package/test/nuxt/useTrackEvent.test.ts +68 -6
  373. package/test/nuxt/useWishlistEntries.test.ts +392 -128
  374. package/test/support/cart.ts +43 -0
  375. package/test/support/dishes.ts +116 -0
  376. package/test/support/navigation.ts +17 -0
  377. package/test/unit/accountMessages.spec.ts +53 -0
  378. package/test/unit/accountRoutes.spec.ts +637 -0
  379. package/test/unit/adapters/memoryCustomer.spec.ts +67 -0
  380. package/test/unit/adapters/memoryDemoMenu.spec.ts +174 -0
  381. package/test/unit/adapters/registry.spec.ts +100 -0
  382. package/test/unit/adapters/shopwareCart.spec.ts +636 -0
  383. package/test/unit/adapters/shopwareCatalog.spec.ts +486 -0
  384. package/test/unit/adapters/shopwareCheckout.spec.ts +197 -0
  385. package/test/unit/adapters/shopwareContact.spec.ts +296 -0
  386. package/test/unit/adapters/shopwareCustomer.spec.ts +256 -0
  387. package/test/unit/adapters/shopwareNavigation.spec.ts +594 -0
  388. package/test/unit/adapters/shopwareOrdering.spec.ts +620 -0
  389. package/test/unit/adapters/shopwareShop.spec.ts +259 -0
  390. package/test/unit/adapters/shopwareWishlist.spec.ts +306 -0
  391. package/test/unit/adapters/useBackend.spec.ts +41 -0
  392. package/test/unit/backoff.spec.ts +47 -0
  393. package/test/unit/boundedCache.spec.ts +59 -59
  394. package/test/unit/cacheKeys.spec.ts +44 -0
  395. package/test/unit/cachePurge.spec.ts +44 -19
  396. package/test/unit/cartRoutes.spec.ts +567 -0
  397. package/test/unit/catalogRoutes.spec.ts +287 -0
  398. package/test/unit/checkoutRoutes.spec.ts +545 -0
  399. package/test/unit/dish.spec.ts +128 -0
  400. package/test/unit/domain/discoverability.spec.ts +154 -0
  401. package/test/unit/domain/dishConfiguration.spec.ts +85 -0
  402. package/test/unit/domain/money.spec.ts +102 -0
  403. package/test/unit/domain/time.spec.ts +336 -0
  404. package/test/unit/domainHttp.spec.ts +74 -0
  405. package/test/unit/forwardedFor.spec.ts +24 -0
  406. package/test/unit/layoutCacheRoutes.spec.ts +47 -471
  407. package/test/unit/leadTime.spec.ts +28 -23
  408. package/test/unit/llmsTxt.spec.ts +120 -9
  409. package/test/unit/media.spec.ts +25 -26
  410. package/test/unit/menuGroups.spec.ts +31 -21
  411. package/test/unit/navigationRoutes.spec.ts +648 -0
  412. package/test/unit/nitroStubs.ts +6 -1
  413. package/test/unit/openingHours.spec.ts +57 -34
  414. package/test/unit/orderPlacement.spec.ts +362 -0
  415. package/test/unit/outageBreaker.spec.ts +213 -0
  416. package/test/unit/productUrl.spec.ts +10 -28
  417. package/test/unit/requestBody.spec.ts +56 -0
  418. package/test/unit/restaurantTime.spec.ts +295 -0
  419. package/test/unit/schema.spec.ts +58 -26
  420. package/test/unit/session/sameOrigin.spec.ts +76 -0
  421. package/test/unit/session/seal.spec.ts +128 -0
  422. package/test/unit/session/visitorSession.spec.ts +439 -0
  423. package/test/unit/shopRoutes.spec.ts +257 -0
  424. package/test/unit/sitemap.spec.ts +11 -47
  425. package/test/unit/storeApiForVisitor.spec.ts +109 -0
  426. package/test/unit/useCategorySeo.spec.ts +57 -31
  427. package/test/unit/wishlistContactRoutes.spec.ts +607 -0
  428. package/vitest.config.ts +5 -1
  429. package/app/components/SalesChannelSwitch.vue +0 -73
  430. package/app/composables/useBusinessHours.ts +0 -192
  431. package/app/composables/useCategoryById.ts +0 -10
  432. package/app/composables/useNavigationSearch.ts +0 -45
  433. package/app/composables/useProductConfigurator.ts +0 -70
  434. package/app/composables/useProductCrossSelling.ts +0 -42
  435. package/app/composables/useProductVariants.ts +0 -61
  436. package/app/composables/useProductVariantsZwei.ts +0 -62
  437. package/app/composables/useSeoUrlRoute.ts +0 -124
  438. package/app/composables/useShopBiteConfig.ts +0 -69
  439. package/app/composables/useSyncWishlist.ts +0 -119
  440. package/app/types/Association.d.ts +0 -14
  441. package/app/utils/product.ts +0 -139
  442. package/app/utils/seoPath.ts +0 -68
  443. package/app/utils/time.ts +0 -20
  444. package/server/api/breadcrumb/[categoryId].get.ts +0 -31
  445. package/server/api/category/[categoryId].get.ts +0 -37
  446. package/server/api/listing/[categoryId].get.ts +0 -102
  447. package/server/api/navigation/[type].get.ts +0 -97
  448. package/server/api/product/[productId]/cross-selling.get.ts +0 -26
  449. package/server/api/product/[productId].get.ts +0 -76
  450. package/server/api/product/variant.get.ts +0 -98
  451. package/server/api/seo-url/index.get.ts +0 -17
  452. package/server/api/seo-url/known.get.ts +0 -33
  453. package/server/api/shopbite/business-hours.get.ts +0 -22
  454. package/server/api/shopbite/config.get.ts +0 -6
  455. package/server/api/shopbite/holidays.get.ts +0 -20
  456. package/server/utils/menuRoot.ts +0 -31
  457. package/server/utils/seoPaths.ts +0 -130
  458. package/server/utils/seoUrlCache.ts +0 -98
  459. package/server/utils/shopBiteConfig.ts +0 -30
  460. package/test/nuxt/useBusinessHours.test.ts +0 -106
  461. package/test/nuxt/useProductConfigurator.test.ts +0 -87
  462. package/test/nuxt/useProductVariants.test.ts +0 -95
  463. package/test/nuxt/useProductVariantsZwei.test.ts +0 -52
  464. package/test/nuxt/useSeoUrlRoute.test.ts +0 -176
  465. package/test/nuxt/useShopBiteConfig.test.ts +0 -131
  466. package/test/nuxt/useSyncWishlist.test.ts +0 -85
  467. package/test/unit/product.spec.ts +0 -160
  468. package/test/unit/seoPath.spec.ts +0 -161
  469. 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
+ }
@@ -1,48 +1,26 @@
1
1
  import { parseURL, withTrailingSlash } from "ufo";
2
2
  import type { SitemapUrl } from "#sitemap/types";
3
- import type { components } from "~~/api-types/storeApiTypes";
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 Shopware
10
- * category SEO URLs (`/c/Pizza/`) 404 without it; the
11
- * `sitemap-trailing-slash` server plugin restores them.
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
- /** Maps navigation categories to sitemap entries (pages with an SEO URL only). */
16
- export function categoriesToSitemapUrls(
17
- categories: Category[],
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
- const urls = new Map<string, StorefrontSitemapUrl>();
20
-
21
- for (const category of categories) {
22
- const path = category.seoUrl;
23
- // Technical /navigation/<id> URLs have no storefront route.
24
- if (
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. */
@@ -1,15 +1,12 @@
1
+ import { guardedRequest } from "./outageBreaker";
1
2
  import type { NitroFetchOptions } from "nitropack";
2
3
 
3
4
  /**
4
- * Field projection for media entities, shared by the routes that return
5
- * category or product images: the URL plus the thumbnails and intrinsic size
6
- * the storefront needs for `srcset` and `width`/`height` (#273).
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
- export const MEDIA_INCLUDES = {
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 $fetch<T>(`${endpoint}${path}`, {
32
- method: "POST",
33
- headers: { "sw-access-key": accessToken, ...options.headers },
34
- body,
35
- // a failing request reaches Shopware once (the cached routes back off
36
- // instead)
37
- retry: 0,
38
- }) as Promise<T>;
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 $fetch<T>(`${endpoint}${path}`, {
52
- headers: { "sw-access-key": accessToken, ...options.headers },
53
- query: options.query,
54
- // ofetch retries a GET once by default; during an outage that doubles
55
- // every request
56
- retry: 0,
57
- }) as Promise<T>;
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,2 @@
1
+ // Guest & Account: who orders (ADR 0001).
2
+ export * from "./types";
@@ -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
+ }>;
@@ -0,0 +1,4 @@
1
+ // Discoverability: routing, SEO, sitemap, llms.txt (ADR 0001).
2
+ export * from "./paths";
3
+ export * from "./route";
4
+ export * from "./types";