@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.
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 -110
  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 +142 -115
  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,38 @@
1
+ import type { ContactForm, ContactMessage } from "../../shared/domain";
2
+
3
+ /** Who sent a contact message, for the backend's spam limits. */
4
+ export type ContactSender = Readonly<{
5
+ /**
6
+ * The visitor's `X-Forwarded-For` chain (the incoming one with the
7
+ * address the request came from), as `BackendSession.forwardedFor`.
8
+ */
9
+ forwardedFor?: string;
10
+ }>;
11
+
12
+ /**
13
+ * Restaurant operations: a message from the contact form to the restaurant
14
+ * (ADR 0001, step 7). Shop-wide: it needs no session. The BFF checks the
15
+ * fields and the honeypot before; the backend may still refuse a message
16
+ * (`validation_failed` with `details.fields`, e.g. a required field left
17
+ * empty) or limit messages per visitor
18
+ * address (`rate_limited` with `details.retryAfterSeconds`).
19
+ *
20
+ * Shopware: `/contact-form` (mail to the shop's address, its per-IP limit
21
+ * through `X-Forwarded-For`). Sylius: the contact request endpoint.
22
+ */
23
+ export interface ContactPort {
24
+ /**
25
+ * The fields the restaurant requires beside e-mail, subject and message
26
+ * (Shopware: `core.basicInformation.*FieldRequired`, learnt from the
27
+ * validation of an empty message, which sends nothing).
28
+ */
29
+ getForm(): Promise<ContactForm>;
30
+ /**
31
+ * Sends the message; answers the restaurant's own confirmation text, or
32
+ * null for the storefront's default.
33
+ */
34
+ send(
35
+ message: ContactMessage,
36
+ sender: ContactSender,
37
+ ): Promise<Readonly<{ confirmation: string | null }>>;
38
+ }
@@ -0,0 +1,154 @@
1
+ import type {
2
+ Address,
3
+ AddressInput,
4
+ Country,
5
+ Customer,
6
+ GuestDetails,
7
+ Id,
8
+ Salutation,
9
+ } from "../../shared/domain";
10
+ import type { BackendSession } from "./session";
11
+
12
+ /**
13
+ * Creating an account ("Registrierung"): the details a guest enters plus a
14
+ * password. The billing address carries the customer's names unless it
15
+ * has its own.
16
+ */
17
+ export type Registration = GuestDetails & Readonly<{ password: string }>;
18
+
19
+ export type RegistrationResult = Readonly<{
20
+ customer: Customer;
21
+ /**
22
+ * Double opt-in: the account waits for the confirmation of its e-mail,
23
+ * the session is not logged in.
24
+ */
25
+ confirmationRequired: boolean;
26
+ }>;
27
+
28
+ export type ProfileChange = Readonly<{
29
+ /** Null keeps the customer's salutation. */
30
+ salutation: Salutation | null;
31
+ firstName: string;
32
+ lastName: string;
33
+ }>;
34
+
35
+ /** An address of the account to save: a new one without id. */
36
+ export type AccountAddress = AddressInput & Readonly<{ id: Id | null }>;
37
+
38
+ /**
39
+ * Guest & Account: login, registration, profile and addresses of the
40
+ * session's customer (ADR 0001, step 6). Login, logout, registration and
41
+ * the confirmation replace the backend state of the session (Shopware
42
+ * issues a new context token; the old one no longer opens the account),
43
+ * which the adapter writes back through the session. The backend merges
44
+ * the visitor's cart into the customer's on login, as it does.
45
+ *
46
+ * Every method but `getCustomer`, `login`, `register`,
47
+ * `confirmRegistration`, the password reset and `listCountries` needs a
48
+ * logged-in customer: `unauthenticated` otherwise. Another customer's
49
+ * address is `not_found`, the same as one that does not exist. A guest's
50
+ * details are changed through `CheckoutPort` (`updateAddress`).
51
+ *
52
+ * Shopware: `/account/*`. Sylius: shop users and customers (JWT login,
53
+ * the token in the session like Shopware's context token), addresses of
54
+ * the address book.
55
+ */
56
+ export interface CustomerPort {
57
+ /** The logged-in customer or guest of the session, null for a visitor. */
58
+ getCustomer(session: BackendSession): Promise<Customer | null>;
59
+ /**
60
+ * Logs the session in. `invalid_credentials` (unknown e-mail and wrong
61
+ * password alike), `account_not_confirmed` (right password, double
62
+ * opt-in pending), `account_inactive` (locked by the shop), `rate_limited` (the backend's limit per e-mail and
63
+ * visitor address, `BackendSession.forwardedFor`).
64
+ */
65
+ login(
66
+ session: BackendSession,
67
+ email: string,
68
+ password: string,
69
+ ): Promise<Customer>;
70
+ /** Logs the session out; the cart stays with the customer. */
71
+ logout(session: BackendSession): Promise<void>;
72
+ /**
73
+ * Creates an account and logs the session in, unless the shop asks for
74
+ * a confirmation of the e-mail first. `storefrontUrl` is where links in
75
+ * the backend's e-mails point. `email_taken`, `validation_failed` with
76
+ * `details.fields`.
77
+ */
78
+ register(
79
+ session: BackendSession,
80
+ registration: Registration,
81
+ storefrontUrl: string,
82
+ ): Promise<RegistrationResult>;
83
+ /**
84
+ * Confirms a registration from the e-mail link and logs the session in.
85
+ * `token` is opaque: the link's query parameters as they came
86
+ * (Shopware: `em`, `hash`), passed on to the adapter that wrote the
87
+ * link. `not_found` for an unknown or broken link, `already_confirmed`.
88
+ */
89
+ confirmRegistration(
90
+ session: BackendSession,
91
+ token: Readonly<Record<string, string>>,
92
+ ): Promise<Customer>;
93
+ updateProfile(
94
+ session: BackendSession,
95
+ change: ProfileChange,
96
+ ): Promise<Customer>;
97
+ /** `invalid_credentials` for a wrong password, `email_taken`. */
98
+ changeEmail(
99
+ session: BackendSession,
100
+ email: string,
101
+ password: string,
102
+ ): Promise<Customer>;
103
+ /**
104
+ * `invalid_credentials` for a wrong current password. The password is
105
+ * changed once this answers; `loggedIn: false` when the session could not
106
+ * stay logged in with it (the customer logs in again).
107
+ */
108
+ changePassword(
109
+ session: BackendSession,
110
+ currentPassword: string,
111
+ newPassword: string,
112
+ ): Promise<Readonly<{ loggedIn: boolean }>>;
113
+ /**
114
+ * Sends a reset link to the e-mail when it has an account; answers the
115
+ * same when it has none and when the backend holds back (no account
116
+ * enumeration: a limit that only known e-mails reach would tell them).
117
+ */
118
+ requestPasswordReset(
119
+ session: BackendSession,
120
+ email: string,
121
+ storefrontUrl: string,
122
+ ): Promise<void>;
123
+ /**
124
+ * Sets a new password with the token of the reset link. `not_found` for
125
+ * an unknown, used or expired token.
126
+ */
127
+ resetPassword(
128
+ session: BackendSession,
129
+ token: string,
130
+ newPassword: string,
131
+ ): Promise<void>;
132
+ /** The account's addresses. */
133
+ listAddresses(session: BackendSession): Promise<readonly Address[]>;
134
+ /**
135
+ * Creates (id null) or changes an address of the account; a change
136
+ * without a salutation keeps the address's, without a country the
137
+ * address's (a new one is in the shop's country).
138
+ */
139
+ saveAddress(
140
+ session: BackendSession,
141
+ address: AccountAddress,
142
+ ): Promise<Address>;
143
+ /** `address_in_use` for a default address. */
144
+ deleteAddress(session: BackendSession, addressId: Id): Promise<void>;
145
+ setDefaultAddress(
146
+ session: BackendSession,
147
+ addressId: Id,
148
+ use: "billing" | "delivery",
149
+ ): Promise<Customer>;
150
+ /** Deletes the customer's account; the session is a new visitor's. */
151
+ deleteAccount(session: BackendSession): Promise<void>;
152
+ /** Countries an address may be in. */
153
+ listCountries(): Promise<readonly Country[]>;
154
+ }
@@ -0,0 +1,58 @@
1
+ import type {
2
+ BreadcrumbItem,
3
+ KnownPaths,
4
+ Id,
5
+ NavigationKind,
6
+ NavigationNode,
7
+ ResolvedRoute,
8
+ SitemapEntry,
9
+ } from "../../shared/domain";
10
+
11
+ /**
12
+ * Discoverability: navigations, paths and the sitemap. Shop-wide.
13
+ *
14
+ * Paths are storefront paths. A backend with SEO URLs (Shopware) answers
15
+ * from them, including old ones (redirects); a backend without them
16
+ * (Sylius: taxon slugs) builds paths from slugs. Content pages of the
17
+ * storefront itself (Nuxt Content) are not the backend's business.
18
+ */
19
+ export interface NavigationPort {
20
+ /**
21
+ * A navigation in its order: `main` (header), `footer` (columns of
22
+ * links), `menu` (the menu sections below the menu root, with their
23
+ * sub-sections) and `home` (the menu sections with their photo). For
24
+ * `menu` and `home`, `menuRootId` is the root the storefront resolved
25
+ * (`getMenuRootId`, cached), so key and tree never name two roots;
26
+ * without it the adapter asks for its root itself.
27
+ */
28
+ getNavigation(
29
+ kind: NavigationKind,
30
+ menuRootId?: Id,
31
+ ): Promise<readonly NavigationNode[]>;
32
+ /**
33
+ * The menu section the menu hangs from (its page lists every dish).
34
+ * Rejects when the backend cannot tell, never answers a guess.
35
+ */
36
+ getMenuRootId(): Promise<Id>;
37
+ /** The path to a menu section, outermost first. Throws `not_found`. */
38
+ getBreadcrumb(sectionId: Id): Promise<readonly BreadcrumbItem[]>;
39
+ /**
40
+ * What a path stands for: a section (with its canonical path) or a
41
+ * redirect for an old or differently spelled path (other case, toggled
42
+ * trailing slash), built with `routeTo()`. Null: no such path, also for
43
+ * a path no section can have (`isHostilePath`), which is rejected
44
+ * before any lookup. A path it resolves (other than under
45
+ * `KnownPaths.unlistedPrefixes`) is among the known paths up to case,
46
+ * accents and outer slashes (`pathKey`).
47
+ */
48
+ resolvePath(path: string): Promise<ResolvedRoute | null>;
49
+ /** Paths of all menu sections for the sitemap. */
50
+ listSitemapEntries(): Promise<readonly SitemapEntry[]>;
51
+ /**
52
+ * Every current and former path of a menu section, so the storefront can
53
+ * answer a path no section ever had with a 404 without asking further
54
+ * (requests of vulnerability scanners). Null when there are too many to
55
+ * list; then every path may be one.
56
+ */
57
+ listKnownPaths(): Promise<KnownPaths | null>;
58
+ }
@@ -0,0 +1,31 @@
1
+ import type { Id, Order } from "../../shared/domain";
2
+ import type { BackendSession } from "./session";
3
+
4
+ export type OrderPage = Readonly<{
5
+ orders: readonly Order[];
6
+ total: number;
7
+ page: number;
8
+ limit: number;
9
+ }>;
10
+
11
+ /**
12
+ * Ordering: placed orders of the session's customer (account) or guest
13
+ * (the orders placed in this session). Statuses are the storefront's own
14
+ * (`OrderStatus`, `PaymentStatus`); the adapter maps its backend's states.
15
+ * An order of another visitor is never readable: it is `not_found`, the
16
+ * same as one that does not exist.
17
+ *
18
+ * Shopware: `/order` with the visitor's context (a guest stays logged in
19
+ * as guest customer for the session) and state machine states. Sylius:
20
+ * orders with `state`, `paymentState`, `shippingState`.
21
+ */
22
+ export interface OrderPort {
23
+ /** Newest first. Throws `unauthenticated` without a guest or customer. */
24
+ listOrders(
25
+ session: BackendSession,
26
+ page?: number,
27
+ limit?: number,
28
+ ): Promise<OrderPage>;
29
+ /** An order of the session's customer or guest. Throws `not_found`. */
30
+ getOrder(session: BackendSession, orderId: Id): Promise<Order>;
31
+ }
@@ -0,0 +1,29 @@
1
+ import type {
2
+ Branch,
3
+ Holiday,
4
+ OpeningHours,
5
+ ShopConfig,
6
+ } from "../../shared/domain";
7
+
8
+ /**
9
+ * Restaurant operations: what the restaurant configured in its backend.
10
+ * Shop-wide, no visitor session. Whether the restaurant is open right now
11
+ * (store status) and which wished times are possible are computed by the
12
+ * storefront from these answers, not asked from the backend.
13
+ *
14
+ * Shopware: the ShopBite plugin's `/shopbite/config`, `/business-hour`,
15
+ * `/holiday` and `/multi-channel-group`. Sylius: channel settings plus a
16
+ * plugin for hours and holidays.
17
+ */
18
+ export interface ShopPort {
19
+ getConfig(): Promise<ShopConfig>;
20
+ getOpeningHours(): Promise<OpeningHours>;
21
+ /** Holidays as whole days; past ones may be left out. */
22
+ getHolidays(): Promise<readonly Holiday[]>;
23
+ /**
24
+ * The branches of the restaurant's branch group, this storefront's own
25
+ * marked `current`; branches without a URL are left out. Empty when the
26
+ * restaurant has no branch group.
27
+ */
28
+ listBranches(): Promise<readonly Branch[]>;
29
+ }
@@ -0,0 +1,47 @@
1
+ import type { DishConfiguration, Id, WishlistEntry } from "../../shared/domain";
2
+ import type { BackendSession } from "./session";
3
+
4
+ /**
5
+ * Guest & Account: the logged-in customer's wishlist of dish
6
+ * configurations (ADR 0001, step 7). A guest's wishlist stays in the
7
+ * browser (it outlives the session); on login the storefront merges it into
8
+ * the account (`merge`). Entries are newest first; the same dish can be
9
+ * kept twice with different configurations, an equal configuration once.
10
+ *
11
+ * Every method throws `unauthenticated` without a logged-in customer (a
12
+ * checkout guest included). An adapter whose backend keeps no wishlist
13
+ * throws `not_implemented`; the storefront then keeps the customer's
14
+ * entries in the browser too.
15
+ *
16
+ * Shopware: the ShopBite plugin's `/shopbite/wishlist` (configurations by
17
+ * product id, removed ingredients by name, extras by product number); a
18
+ * customer's Shopware wishlist of plain dishes moves into it on the first
19
+ * read. Sylius: a wishlist plugin.
20
+ */
21
+ export interface WishlistPort {
22
+ listEntries(session: BackendSession): Promise<readonly WishlistEntry[]>;
23
+ /**
24
+ * Adds a configuration and answers its entry; an equal one is answered
25
+ * as it is. A dish or variant the menu does not offer is
26
+ * `dish_unavailable`, a variant of another dish, an extra the dish does
27
+ * not offer or a removal it does not have `invalid_value`.
28
+ */
29
+ addEntry(
30
+ session: BackendSession,
31
+ configuration: DishConfiguration,
32
+ ): Promise<WishlistEntry>;
33
+ /** Another customer's or an unknown entry is `not_found`. */
34
+ removeEntry(session: BackendSession, entryId: Id): Promise<void>;
35
+ /**
36
+ * Takes over the guest's entries after login (at most `MERGE_LIMIT`, the
37
+ * first one newest), leaving out equal ones and configurations the menu
38
+ * no longer offers; answers the full list.
39
+ */
40
+ merge(
41
+ session: BackendSession,
42
+ configurations: readonly DishConfiguration[],
43
+ ): Promise<readonly WishlistEntry[]>;
44
+ }
45
+
46
+ /** Most configurations one merge takes over (the ShopBite plugin's limit). */
47
+ export const WISHLIST_MERGE_LIMIT = 100;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Ports (ADR 0001): what the storefront needs from a shop backend, in the
3
+ * storefront's own language (GLOSSARY.md). Adapters in `server/adapters/`
4
+ * implement them; server routes reach them through `useBackend(event)`.
5
+ */
6
+ import type { CartPort } from "./CartPort";
7
+ import type { CatalogPort } from "./CatalogPort";
8
+ import type { CheckoutPort } from "./CheckoutPort";
9
+ import type { ContactPort } from "./ContactPort";
10
+ import type { CustomerPort } from "./CustomerPort";
11
+ import type { NavigationPort } from "./NavigationPort";
12
+ import type { OrderPort } from "./OrderPort";
13
+ import type { ShopPort } from "./ShopPort";
14
+ import type { WishlistPort } from "./WishlistPort";
15
+
16
+ export type * from "./CartPort";
17
+ export type * from "./CatalogPort";
18
+ export type * from "./CheckoutPort";
19
+ export type * from "./ContactPort";
20
+ export type * from "./CustomerPort";
21
+ export type * from "./NavigationPort";
22
+ export type * from "./OrderPort";
23
+ export type * from "./session";
24
+ export type * from "./ShopPort";
25
+ export type * from "./WishlistPort";
26
+
27
+ /** One adapter's implementation of every port. */
28
+ export interface Backend {
29
+ /** Adapter name, e.g. `shopware`. */
30
+ readonly name: string;
31
+ readonly catalog: CatalogPort;
32
+ readonly navigation: NavigationPort;
33
+ readonly cart: CartPort;
34
+ readonly checkout: CheckoutPort;
35
+ readonly customer: CustomerPort;
36
+ readonly orders: OrderPort;
37
+ readonly shop: ShopPort;
38
+ readonly wishlist: WishlistPort;
39
+ readonly contact: ContactPort;
40
+ }
41
+
42
+ export type PortName = Exclude<keyof Backend, "name">;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The visitor's side of a request, handed to every port that acts for one
3
+ * visitor (cart, checkout, account, orders, wishlist). The browser only
4
+ * holds the storefront's own HttpOnly session cookie; whatever the backend
5
+ * needs to recognise the visitor (Shopware: the `sw-context-token`) lives
6
+ * server-side in that session and is read and written only by the adapter
7
+ * (ADR 0001, implemented in step 4).
8
+ */
9
+ export interface BackendSession {
10
+ /** The adapter's opaque state for this visitor, undefined for a new one. */
11
+ read(): Promise<string | undefined>;
12
+ /**
13
+ * Replaces the state, e.g. when the backend issues a new token on login
14
+ * or logout; undefined forgets it.
15
+ */
16
+ write(state: string | undefined): Promise<void>;
17
+ /**
18
+ * The visitor's `X-Forwarded-For` chain (the incoming one with the
19
+ * address the request came from), for a backend's per-IP rate limits.
20
+ */
21
+ readonly forwardedFor?: string;
22
+ }
@@ -1,52 +1,14 @@
1
1
  import { queryCollection } from "@nuxt/content/server";
2
2
  import { defineEventHandler } from "nuxt/server";
3
- import type { components } from "~~/api-types/storeApiTypes";
4
- import { getDiets, getMainIngredients } from "../../app/utils/product";
5
3
  import { fulfillmentLeadTime } from "../../app/utils/leadTime";
6
- import { productDeepLink } from "../../app/utils/productUrl";
7
4
  import { splitList, toAbsoluteUrl } from "../../app/utils/seo";
8
- import { buildLlmsTxt, type LlmsMenuSection } from "../utils/llmsTxt";
9
-
10
- type Schemas = components["schemas"];
11
-
12
- // Store API maximum per request.
13
- const PRODUCT_PAGE_SIZE = 100;
14
- // A menu has a few hundred products at most (a real menu: 390 incl. extras).
15
- const MAX_PRODUCT_PAGES = 10;
16
-
17
- const NAVIGATION_CRITERIA = {
18
- depth: 10,
19
- buildTree: true,
20
- includes: {
21
- category: ["id", "name", "translated", "seoUrl", "type", "children"],
22
- },
23
- };
24
-
25
- const PRODUCT_CRITERIA = {
26
- limit: PRODUCT_PAGE_SIZE,
27
- // Main products only; variants are summed up as "ab <cheapest price>".
28
- filter: [{ type: "equals", field: "parentId", value: null }],
29
- associations: { properties: { associations: { group: {} } } },
30
- includes: {
31
- product: [
32
- "id",
33
- "name",
34
- "translated",
35
- "categoryIds",
36
- "childCount",
37
- "calculatedPrice",
38
- "calculatedCheapestPrice",
39
- "sortedProperties",
40
- "productNumber",
41
- "seoUrls",
42
- ],
43
- seo_url: ["seoPathInfo", "isCanonical"],
44
- calculated_price: ["unitPrice"],
45
- calculated_cheapest_price: ["unitPrice"],
46
- property_group: ["name", "translated", "options"],
47
- property_group_option: ["name", "translated"],
48
- },
49
- };
5
+ import { buildLlmsTxt, toLlmsMenu } from "../utils/llmsTxt";
6
+ import {
7
+ holidaysData,
8
+ openingHoursData,
9
+ shippingMethodsData,
10
+ shopConfigData,
11
+ } from "../utils/shopData";
50
12
 
51
13
  /**
52
14
  * `/llms.txt` (#402): the shop, its hours, ordering and the menu as Markdown
@@ -57,39 +19,21 @@ const PRODUCT_CRITERIA = {
57
19
  * `getPathRobotConfig()` of @nuxtjs/robots 7 reads.
58
20
  */
59
21
  export default defineEventHandler(async (event) => {
60
- const { shopware, site } = useRuntimeConfig().public;
22
+ const { site } = useRuntimeConfig().public;
61
23
  const siteUrl = getSiteConfig(event).url;
62
- const headers = { "sw-access-key": shopware.accessToken };
63
- const menuRoot = await menuRootId();
64
-
65
- const storeApi = <T>(path: string, body?: Record<string, unknown>) =>
66
- $fetch<T>(`${shopware.endpoint}${path}`, {
67
- method: body ? "POST" : "GET",
68
- headers: { ...headers, "sw-include-seo-urls": "true" },
69
- body,
70
- });
24
+ const { catalog } = useBackend();
71
25
 
72
- const [navigation, products, hours, holidays, config, context, pages, home] =
26
+ const [menu, dishes, hours, holidays, config, shippingMethods, pages, home] =
73
27
  await Promise.allSettled([
74
- storeApi<Schemas["Category"][]>(
75
- `/navigation/${menuRoot}/${menuRoot}`,
76
- NAVIGATION_CRITERIA,
77
- ),
78
- loadProducts((page) =>
79
- storeApiPost<{ elements?: Schemas["Product"][] }>(
80
- "/product",
81
- { ...PRODUCT_CRITERIA, page },
82
- { headers: { "sw-include-seo-urls": "true" } },
83
- ),
84
- ),
85
- storeApi<{ businessHours?: Schemas["ShopbiteBusinessHour"][] }>(
86
- "/shopbite/business-hour",
87
- ),
88
- storeApi<{ holidays?: { start?: string; end?: string }[] }>(
89
- "/shopbite/holiday",
90
- ),
91
- storeApi<Schemas["ShopBiteConfig"]>("/shopbite/config"),
92
- storeApi<Schemas["SalesChannelContext"]>("/context"),
28
+ // the menu through the catalog (ADR 0001, step 2); the route's `swr`
29
+ // caches the file
30
+ catalog.getMenu(),
31
+ catalog.listMenuDishes(),
32
+ // restaurant operations through the ports (ADR 0001), cached
33
+ openingHoursData.cached(),
34
+ holidaysData.cached(),
35
+ shopConfigData.cached(),
36
+ shippingMethodsData.cached(),
93
37
  queryCollection(event, "landingpages")
94
38
  .select("path", "title", "description")
95
39
  .all(),
@@ -99,22 +43,7 @@ export default defineEventHandler(async (event) => {
99
43
  const value = <T>(result: PromiseSettledResult<T>) =>
100
44
  result.status === "fulfilled" ? result.value : undefined;
101
45
 
102
- const productsByCategory = groupByCategory(value(products) ?? []);
103
- const toSection = (category: Schemas["Category"]): LlmsMenuSection => ({
104
- name: category.translated?.name ?? category.name,
105
- url: category.seoUrl ? toAbsoluteUrl(siteUrl, category.seoUrl) : undefined,
106
- items: (productsByCategory.get(category.id) ?? []).map((product) => {
107
- const deepLink = productDeepLink(product, category.seoUrl);
108
- return {
109
- ...toMenuItem(product),
110
- url: deepLink ? toAbsoluteUrl(siteUrl, deepLink) : undefined,
111
- };
112
- }),
113
- sections: (category.children ?? [])
114
- .filter((child) => child.type === "page")
115
- .map(toSection),
116
- });
117
-
46
+ const menuDishes = value(dishes) ?? [];
118
47
  const body = buildLlmsTxt({
119
48
  name: site.name,
120
49
  alternateNames: splitList(site.alternateNames),
@@ -131,16 +60,14 @@ export default defineEventHandler(async (event) => {
131
60
  telephone: site.telephone,
132
61
  googleBusinessProfileUrl: site.googleBusinessProfileUrl,
133
62
  deliveryAreas: splitList(site.deliveryAreas),
134
- businessHours: value(hours)?.businessHours,
135
- holidays: value(holidays)?.holidays,
136
- isCheckoutEnabled: value(config)?.isCheckoutEnabled,
63
+ openingHours: value(hours),
64
+ holidays: value(holidays),
65
+ acceptsOrders: value(config)?.acceptsOrders,
137
66
  // lead times of the delivery and pickup methods (shopbite#6)
138
- deliveryTime: fulfillmentLeadTime(value(config), "delivery"),
139
- pickupTime: fulfillmentLeadTime(value(config), "pickup"),
67
+ deliveryTime: fulfillmentLeadTime(value(shippingMethods), "delivery"),
68
+ pickupTime: fulfillmentLeadTime(value(shippingMethods), "pickup"),
140
69
  menuUrl: toAbsoluteUrl(siteUrl, "/speisekarte"),
141
- menu: (value(navigation) ?? [])
142
- .filter((category) => category.type === "page")
143
- .map(toSection),
70
+ menu: toLlmsMenu(value(menu) ?? [], menuDishes, siteUrl),
144
71
  pages: (value(pages) ?? [])
145
72
  // Pages the shop keeps out of robots.txt (legal pages) stay out here.
146
73
  .filter(
@@ -156,64 +83,11 @@ export default defineEventHandler(async (event) => {
156
83
  description: page.description,
157
84
  })),
158
85
  faq: value(home)?.faq?.items,
159
- currency: value(context)?.currency?.isoCode,
86
+ currency: menuDishes[0]?.price.currency,
160
87
  now: new Date(),
88
+ timeZone: value(config)?.timeZone ?? useRuntimeConfig().shopBite.timeZone,
161
89
  });
162
90
 
163
91
  event.res.headers.set("Content-Type", "text/markdown; charset=utf-8");
164
92
  return body;
165
93
  });
166
-
167
- async function loadProducts(
168
- loadPage: (page: number) => Promise<{ elements?: Schemas["Product"][] }>,
169
- ) {
170
- const products: Schemas["Product"][] = [];
171
- for (let page = 1; page <= MAX_PRODUCT_PAGES; page++) {
172
- const elements = (await loadPage(page)).elements ?? [];
173
- products.push(...elements);
174
- if (elements.length < PRODUCT_PAGE_SIZE) break;
175
- }
176
- return products;
177
- }
178
-
179
- /** Products by the categories they are assigned to directly. */
180
- function groupByCategory(products: Schemas["Product"][]) {
181
- const byCategory = new Map<string, Schemas["Product"][]>();
182
- for (const product of products) {
183
- for (const categoryId of product.categoryIds ?? []) {
184
- byCategory.set(categoryId, [
185
- ...(byCategory.get(categoryId) ?? []),
186
- product,
187
- ]);
188
- }
189
- }
190
- // Alphabetical, numbers in natural order ("Pizza 9" before "Pizza 10").
191
- for (const items of byCategory.values()) {
192
- items.sort((a, b) =>
193
- (a.translated?.name ?? a.name).localeCompare(
194
- b.translated?.name ?? b.name,
195
- "de",
196
- { numeric: true },
197
- ),
198
- );
199
- }
200
- return byCategory;
201
- }
202
-
203
- function toMenuItem(product: Schemas["Product"]) {
204
- const properties = product.sortedProperties as
205
- Schemas["PropertyGroup"][] | undefined;
206
- const hasVariants = (product.childCount ?? 0) > 0;
207
- return {
208
- name: product.translated?.name ?? product.name,
209
- price: hasVariants
210
- ? (product.calculatedCheapestPrice?.unitPrice ??
211
- product.calculatedPrice?.unitPrice)
212
- : product.calculatedPrice?.unitPrice,
213
- fromPrice: hasVariants,
214
- ingredients: getMainIngredients(properties).map(
215
- (option) => option.translated?.name ?? option.name,
216
- ),
217
- diets: getDiets(properties),
218
- };
219
- }
@@ -0,0 +1,24 @@
1
+ /** Most entries of a forwarded chain; the nearest ones are kept. */
2
+ const MAX_FORWARDED = 20;
3
+
4
+ /**
5
+ * The `X-Forwarded-For` a proxy sends on (ADR 0001, step 4): the chain the
6
+ * request brought with the socket address appended, for a backend's
7
+ * per-IP limits (login, password reset, contact form, cart). Shopware takes
8
+ * the rightmost address it does not trust, so with `TRUSTED_PROXIES`
9
+ * listing the storefront and the proxies in front of it (and nothing
10
+ * else), an entry a visitor forged on the left is never taken. The proxy
11
+ * in front of the storefront must overwrite a client-sent header. Without
12
+ * a socket address nothing is sent.
13
+ */
14
+ export function forwardedFor(
15
+ incoming: string | undefined,
16
+ remoteAddress: string | undefined,
17
+ ): string | undefined {
18
+ if (!remoteAddress) return undefined;
19
+ const chain = (incoming ?? "")
20
+ .split(",")
21
+ .map((entry) => entry.trim())
22
+ .filter(Boolean);
23
+ return [...chain, remoteAddress].slice(-MAX_FORWARDED).join(", ");
24
+ }