@shopbite-de/storefront 2.2.1 → 2.4.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 (69) hide show
  1. package/.github/workflows/build.yaml +2 -2
  2. package/.github/workflows/ci.yaml +11 -11
  3. package/.nuxtrc +1 -1
  4. package/CLAUDE.md +13 -7
  5. package/app/app.vue +10 -7
  6. package/app/components/Address/Fields.vue +1 -2
  7. package/app/components/Category/Breadcrumb.vue +9 -10
  8. package/app/components/Checkout/Summary.vue +27 -2
  9. package/app/components/Header.vue +6 -2
  10. package/app/components/Menu/BonCard.vue +1 -2
  11. package/app/components/Order/Confirmation.vue +1 -2
  12. package/app/components/Product/QuickView.vue +1 -2
  13. package/app/composables/useBusinessHours.ts +35 -14
  14. package/app/composables/useHolidays.ts +31 -11
  15. package/app/composables/useHomeMenuCategories.ts +6 -34
  16. package/app/composables/useLiveShopData.ts +17 -0
  17. package/app/composables/useNavigation.ts +14 -66
  18. package/app/composables/useNavigationSearch.ts +8 -31
  19. package/app/composables/useRestaurantSchema.ts +2 -13
  20. package/app/composables/useSeoUrlRoute.ts +21 -0
  21. package/app/composables/useShopBiteConfig.ts +50 -6
  22. package/app/composables/useTopSellers.ts +2 -43
  23. package/app/error.vue +4 -0
  24. package/docs/notes/2026-09-10-issue-275-accessibility.md +2 -2
  25. package/docs/notes/2026-09-12-issue-327-home-hero.md +1 -1
  26. package/docs/notes/2026-09-13-issue-332-home-info-cards.md +1 -3
  27. package/docs/notes/2026-09-21-issue-273-cache-and-demo-video.md +1 -1
  28. package/docs/notes/2026-09-21-issue-363-non-fatal-404.md +1 -1
  29. package/docs/notes/2026-09-23-issue-388-home-sections.md +2 -2
  30. package/docs/notes/2026-10-05-issue-401-restaurant-schema-ordering.md +1 -1
  31. package/docs/notes/2026-11-18-dependency-update.md +118 -0
  32. package/modules/theme.ts +1 -1
  33. package/node.dockerfile +7 -7
  34. package/nuxt.config.ts +22 -1
  35. package/package.json +40 -40
  36. package/pnpm-workspace.yaml +0 -2
  37. package/server/api/_cache/purge.post.ts +6 -3
  38. package/server/api/breadcrumb/[categoryId].get.ts +31 -0
  39. package/server/api/navigation/[type].get.ts +97 -0
  40. package/server/api/payment-methods.get.ts +29 -0
  41. package/server/api/seo-url/index.get.ts +17 -0
  42. package/server/api/seo-url/known.get.ts +33 -0
  43. package/server/api/shopbite/business-hours.get.ts +22 -0
  44. package/server/api/shopbite/config.get.ts +6 -0
  45. package/server/api/shopbite/holidays.get.ts +20 -0
  46. package/server/api/top-sellers.get.ts +59 -0
  47. package/server/plugins/ai-crawlers.ts +1 -1
  48. package/server/plugins/site-url.ts +2 -2
  49. package/server/routes/llms.txt.ts +6 -2
  50. package/server/utils/backoff.ts +67 -0
  51. package/server/utils/cachePurge.ts +45 -12
  52. package/server/utils/menuRoot.ts +24 -18
  53. package/server/utils/seoPaths.ts +130 -0
  54. package/server/utils/seoUrlCache.ts +98 -0
  55. package/server/utils/shopBiteConfig.ts +30 -0
  56. package/server/utils/storeApi.ts +25 -1
  57. package/test/a11y/presets.test.ts +3 -1
  58. package/test/layer/nuxt.config.ts +1 -1
  59. package/test/nuxt/CheckoutOnePage.test.ts +2 -0
  60. package/test/nuxt/CheckoutSummary.test.ts +38 -2
  61. package/test/nuxt/HeaderFooterPreset.test.ts +13 -4
  62. package/test/nuxt/liveShopData.test.ts +114 -0
  63. package/test/nuxt/useShopBiteConfig.test.ts +22 -0
  64. package/test/nuxt/useTopSellers.test.ts +10 -27
  65. package/test/unit/cachePurge.spec.ts +41 -0
  66. package/test/unit/layoutCacheRoutes.spec.ts +566 -0
  67. package/test/unit/nitroStubs.ts +99 -0
  68. package/test/unit/seoPaths.spec.ts +117 -0
  69. package/patches/@shopware__nuxt-module@1.5.2.patch +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopbite-de/storefront",
3
- "version": "2.2.1",
3
+ "version": "2.4.0",
4
4
  "main": "nuxt.config.ts",
5
5
  "description": "Shopware storefront for food delivery shops",
6
6
  "keywords": [
@@ -18,55 +18,55 @@
18
18
  "license": "MIT",
19
19
  "type": "module",
20
20
  "dependencies": {
21
- "@nuxt/content": "3.16.1",
22
- "@nuxt/fonts": "^0.14.0",
23
- "@nuxt/image": "^2.1.0",
21
+ "@nuxt/content": "3.17.0",
22
+ "@nuxt/fonts": "^1.2.0",
23
+ "@nuxt/image": "^2.2.1",
24
24
  "@nuxt/scripts": "1.3.12",
25
- "@nuxtjs/robots": "^6.2.3",
26
- "@nuxtjs/sitemap": "^8.5.1",
27
- "@shopware/api-client": "^1.6.0",
28
- "@shopware/api-gen": "^1.5.2",
29
- "@shopware/composables": "^1.13.0",
30
- "@shopware/helpers": "^1.8.0",
31
- "@shopware/nuxt-module": "^1.5.2",
32
- "@tailwindcss/vite": "^4.3.3",
33
- "@unhead/vue": "^3.4.1",
34
- "@vite-pwa/nuxt": "^1.1.1",
25
+ "@nuxtjs/robots": "^7.0.2",
26
+ "@nuxtjs/sitemap": "^9.1.0",
27
+ "@shopware/api-client": "^1.8.0",
28
+ "@shopware/api-gen": "^1.6.0",
29
+ "@shopware/composables": "^1.15.0",
30
+ "@shopware/helpers": "^1.9.0",
31
+ "@shopware/nuxt-module": "^1.6.1",
32
+ "@tailwindcss/vite": "^4.3.5",
33
+ "@unhead/vue": "^3.4.3",
34
+ "@vite-pwa/nuxt": "^2.0.1",
35
35
  "@vueuse/core": "^15.0.0",
36
- "dotenv": "^18.0.3",
36
+ "dotenv": "^18.0.10",
37
37
  "fflate": "^0.8.3",
38
- "nuxt": "^4.5.2",
39
- "nuxt-vitalizer": "3.0.0",
40
- "reka-ui": "^2.10.5",
41
- "uuid": "^14.0.2"
38
+ "nuxt": "^4.6.4",
39
+ "nuxt-vitalizer": "4.0.0",
40
+ "reka-ui": "^2.11.0",
41
+ "uuid": "^14.0.3"
42
42
  },
43
43
  "devDependencies": {
44
- "@axe-core/playwright": "^4.13.0",
45
- "@nuxt/devtools-kit": "^3.4.2",
44
+ "@axe-core/playwright": "^4.14.0",
45
+ "@nuxt/devtools-kit": "^3.4.4",
46
46
  "@nuxt/eslint": "^1.17.0",
47
47
  "@nuxt/hints": "1.1.5",
48
- "@nuxt/test-utils": "^4.3.2",
49
- "@playwright/test": "^1.63.0",
48
+ "@nuxt/test-utils": "^4.4.0",
49
+ "@playwright/test": "^1.65.1",
50
50
  "@types/js-cookie": "^3.0.6",
51
- "@types/node": "^26.6.2",
52
- "@typescript-eslint/eslint-plugin": "^8.70.1",
53
- "@typescript-eslint/parser": "^8.70.1",
54
- "@vitejs/plugin-vue": "^6.0.9",
55
- "@vitest/ui": "5.0.3",
56
- "@vue/compiler-dom": "^3.5.43",
57
- "@vue/server-renderer": "^3.5.43",
58
- "@vue/test-utils": "^2.5.1",
59
- "@vue/typescript-plugin": "^3.3.11",
60
- "eslint": "^10.11.0",
51
+ "@types/node": "^26.6.6",
52
+ "@typescript-eslint/eslint-plugin": "^8.73.0",
53
+ "@typescript-eslint/parser": "^8.73.0",
54
+ "@vitejs/plugin-vue": "^6.0.11",
55
+ "@vitest/ui": "5.1.0",
56
+ "@vue/compiler-dom": "^3.5.45",
57
+ "@vue/server-renderer": "^3.5.45",
58
+ "@vue/test-utils": "^2.6.0",
59
+ "@vue/typescript-plugin": "^3.3.14",
60
+ "eslint": "^10.15.0",
61
61
  "eslint-config-prettier": "^10.1.8",
62
- "happy-dom": "^20.14.5",
63
- "jsdom": "^30.1.1",
64
- "playwright-core": "^1.63.0",
65
- "prettier": "^3.9.9",
66
- "tailwindcss": "^4.3.3",
62
+ "happy-dom": "^21.0.4",
63
+ "jsdom": "^31.0.1",
64
+ "playwright-core": "^1.65.1",
65
+ "prettier": "^3.10.1",
66
+ "tailwindcss": "^4.3.5",
67
67
  "typescript": "^6.0.3",
68
- "vitest": "^5.0.1",
69
- "vue-tsc": "3.3.12"
68
+ "vitest": "^5.1.0",
69
+ "vue-tsc": "3.3.14"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "nuxt build",
@@ -7,5 +7,3 @@ allowBuilds:
7
7
  sharp: true
8
8
  unrs-resolver: true
9
9
  vue-demi: true
10
- patchedDependencies:
11
- '@shopware/nuxt-module@1.5.2': patches/@shopware__nuxt-module@1.5.2.patch
@@ -5,13 +5,16 @@ const Body = z
5
5
  .object({
6
6
  products: z.array(Id).max(1000).optional(),
7
7
  categories: z.array(Id).max(1000).optional(),
8
+ // only the layout data (hours, closing days, checkout switch, ...)
9
+ layout: z.boolean().optional(),
8
10
  })
9
11
  .default({});
10
12
 
11
13
  /**
12
- * Empties the Store API caches after the backoffice changed the menu (#484).
13
- * Protected by NUXT_CACHE_PURGE_SECRET; without the variable the route is
14
- * off. An empty body purges everything.
14
+ * Empties the Store API caches after the backoffice changed the menu (#484)
15
+ * or the shop settings (`{ "layout": true }`). Protected by
16
+ * NUXT_CACHE_PURGE_SECRET; without the variable the route is off. An empty
17
+ * body purges everything.
15
18
  */
16
19
  export default defineEventHandler(async (event) => {
17
20
  const secret = useRuntimeConfig(event).cachePurgeSecret;
@@ -0,0 +1,31 @@
1
+ import type { components } from "~~/api-types/storeApiTypes";
2
+ import { createResilientLoader } from "../../utils/backoff";
3
+
4
+ const Id = /^[0-9a-f]{32}$/i;
5
+ type Breadcrumb = components["schemas"]["BreadcrumbCollection"];
6
+
7
+ // only real breadcrumbs are remembered, not the empty list of random ids
8
+ const load = createResilientLoader<Breadcrumb>((crumbs) => crumbs.length > 0);
9
+
10
+ /** Breadcrumb of a menu section (Category/Breadcrumb.vue). */
11
+ export default defineCachedEventHandler(
12
+ async (event): Promise<components["schemas"]["BreadcrumbCollection"]> => {
13
+ const categoryId = getRouterParam(event, "categoryId") ?? "";
14
+ if (!Id.test(categoryId)) throw createError({ statusCode: 400 });
15
+
16
+ const breadcrumb = await load(categoryId, () =>
17
+ storeApiGet<Breadcrumb>(`/breadcrumb/${categoryId}`, {
18
+ query: { type: "category" },
19
+ }),
20
+ );
21
+ // Shopware answers an unknown id with an empty list; a 404 is not
22
+ // cached, so random ids cannot fill the cache.
23
+ if (!breadcrumb?.length) throw createError({ statusCode: 404 });
24
+ return breadcrumb;
25
+ },
26
+ {
27
+ maxAge: useRuntimeConfig().public.shopBite.cacheTtl.category,
28
+ name: "breadcrumb",
29
+ getKey: (event) => `breadcrumb-${getRouterParam(event, "categoryId")}`,
30
+ },
31
+ );
@@ -0,0 +1,97 @@
1
+ import type { components } from "~~/api-types/storeApiTypes";
2
+ import { createResilientLoader } from "../../utils/backoff";
3
+ type Schemas = components["schemas"];
4
+
5
+ // What the header, footer and menu navigation read (useNavigation).
6
+ const NAVIGATION_CRITERIA = {
7
+ includes: {
8
+ category: [
9
+ "id",
10
+ "name",
11
+ "translated",
12
+ "seoUrl",
13
+ "customFields",
14
+ "children",
15
+ "linkNewTab",
16
+ ],
17
+ },
18
+ };
19
+
20
+ // The menu sections of the home page with their photo (useHomeMenuCategories).
21
+ const HOME_CRITERIA = {
22
+ depth: 1,
23
+ includes: {
24
+ category: ["id", "name", "translated", "seoUrl", "customFields", "media"],
25
+ media: ["url", "thumbnails", "metaData"],
26
+ media_thumbnail: ["url", "width"],
27
+ },
28
+ };
29
+
30
+ const NAVIGATIONS = {
31
+ main: { activeId: "main-navigation", root: "main-navigation" },
32
+ footer: { activeId: "footer-navigation", root: "footer-navigation" },
33
+ menu: { activeId: "main-navigation", root: "menu" },
34
+ home: { activeId: "main-navigation", root: "menu" },
35
+ } as const;
36
+
37
+ type NavigationType = keyof typeof NAVIGATIONS;
38
+
39
+ const load = createResilientLoader<Schemas["Category"][]>();
40
+
41
+ function navigationOf(type: string | undefined) {
42
+ if (!type || !Object.hasOwn(NAVIGATIONS, type)) return null;
43
+ return NAVIGATIONS[type as NavigationType];
44
+ }
45
+
46
+ type RootContext = { context?: Record<string, unknown> };
47
+
48
+ /**
49
+ * The root of a navigation, resolved once per request (key and request
50
+ * share `event.context`): the plugin config may expire in between, and a
51
+ * second answer would cache one root's sections under the other's key.
52
+ */
53
+ async function rootIdOf(
54
+ event: RootContext,
55
+ type: string | undefined,
56
+ ): Promise<string> {
57
+ const context = (event.context ??= {});
58
+ if (typeof context.navigationRoot === "string") return context.navigationRoot;
59
+ const navigation = navigationOf(type);
60
+ if (!navigation) return "";
61
+ const root =
62
+ navigation.root === "menu" ? await menuRootIdStrict() : navigation.root;
63
+ context.navigationRoot = root;
64
+ return root;
65
+ }
66
+
67
+ /**
68
+ * The navigations every page renders: `main` (header), `footer`, `menu` (the
69
+ * menu sections below the menu root, #486) and `home` (the sections with
70
+ * their photo). Shared by all visitors, so the server keeps them instead of
71
+ * asking Shopware on each request; the key carries the menu root, which the
72
+ * plugin configuration may change. Without the plugin configuration the
73
+ * request fails rather than caching a menu of the fallback root.
74
+ */
75
+ export default defineCachedEventHandler(
76
+ async (event): Promise<Schemas["Category"][]> => {
77
+ const type = getRouterParam(event, "type");
78
+ const navigation = navigationOf(type);
79
+ if (!navigation) throw createError({ statusCode: 404 });
80
+
81
+ const root = await rootIdOf(event, type);
82
+ return await load(`${type}-${root}`, () =>
83
+ storeApiPost(
84
+ `/navigation/${navigation.activeId}/${root}`,
85
+ type === "home" ? HOME_CRITERIA : NAVIGATION_CRITERIA,
86
+ ),
87
+ );
88
+ },
89
+ {
90
+ maxAge: useRuntimeConfig().public.shopBite.cacheTtl.navigation,
91
+ name: "navigation",
92
+ getKey: async (event) => {
93
+ const type = getRouterParam(event, "type");
94
+ return `navigation-${type}-${await rootIdOf(event, type)}`;
95
+ },
96
+ },
97
+ );
@@ -0,0 +1,29 @@
1
+ import type { components } from "~~/api-types/storeApiTypes";
2
+ import { createResilientLoader } from "../utils/backoff";
3
+
4
+ const load = createResilientLoader<string[]>();
5
+
6
+ /**
7
+ * Names of the payment methods for the Restaurant schema of the home page
8
+ * (useRestaurantSchema). Asked without a visitor's context, so it lists what
9
+ * a new guest can pay with.
10
+ */
11
+ export default defineCachedEventHandler(
12
+ (): Promise<string[]> =>
13
+ load("payment-methods", async () => {
14
+ const result = await storeApiPost<{
15
+ elements?: components["schemas"]["PaymentMethod"][];
16
+ }>("/payment-method", {
17
+ onlyAvailable: true,
18
+ includes: { payment_method: ["name", "translated"] },
19
+ });
20
+ return (result.elements ?? []).map(
21
+ (method) => method.translated?.name ?? method.name,
22
+ );
23
+ }),
24
+ {
25
+ maxAge: useRuntimeConfig().public.shopBite.cacheTtl.paymentMethods,
26
+ name: "payment-methods",
27
+ getKey: () => "payment-methods",
28
+ },
29
+ );
@@ -0,0 +1,17 @@
1
+ import { isHostilePath } from "../../utils/seoPaths";
2
+
3
+ /**
4
+ * The canonical SEO URL of a path (useNavigationSearch); matches are cached
5
+ * (findSeoUrl). `{ seoUrl: null }` for an unknown path: not an error (see
6
+ * content/page).
7
+ */
8
+ export default defineEventHandler(async (event) => {
9
+ const { path } = getQuery(event);
10
+ if (typeof path !== "string" || !path.startsWith("/")) {
11
+ throw createError({ statusCode: 400, statusMessage: "Invalid path" });
12
+ }
13
+ // longer than Shopware stores a SEO path, or a probe no SEO URL can match
14
+ if (path.length > 750 || isHostilePath(path)) return { seoUrl: null };
15
+
16
+ return { seoUrl: await findSeoUrl(path) };
17
+ });
@@ -0,0 +1,33 @@
1
+ import { createBackoff } from "../../utils/backoff";
2
+ import { isHostilePath, mayBeSeoPath } from "../../utils/seoPaths";
3
+
4
+ /** After a failed load, let every path through for the backoff. */
5
+ const backoff = createBackoff();
6
+ let memo: { loadedAt: number; known: Set<string> } | null = null;
7
+
8
+ /**
9
+ * Whether a path may be a category SEO URL (useSeoUrlRoute asks before its
10
+ * lookups on the server): `false` for a hostile path (isHostilePath) and
11
+ * for one no category ever had. When the list is too long or Shopware
12
+ * fails, every other path may.
13
+ */
14
+ export default defineEventHandler(async (event) => {
15
+ const { path } = getQuery(event);
16
+ if (typeof path !== "string" || !path.startsWith("/")) {
17
+ throw createError({ statusCode: 400, statusMessage: "Invalid path" });
18
+ }
19
+ // before the branches that let every path through
20
+ if (isHostilePath(path)) return { known: false };
21
+ if (backoff.active()) return { known: true };
22
+
23
+ try {
24
+ const { paths, loadedAt } = await knownSeoPaths();
25
+ if (!paths) return { known: true };
26
+ if (memo?.loadedAt !== loadedAt) memo = { loadedAt, known: new Set(paths) };
27
+ return { known: mayBeSeoPath(path, memo.known) };
28
+ } catch (error) {
29
+ backoff.trip();
30
+ console.error("Failed to load the SEO paths", error);
31
+ return { known: true };
32
+ }
33
+ });
@@ -0,0 +1,22 @@
1
+ import type { components } from "~~/api-types/storeApiTypes";
2
+ import { createResilientLoader } from "../../utils/backoff";
3
+
4
+ const load =
5
+ createResilientLoader<components["schemas"]["BusinessHourStruct"]>();
6
+
7
+ /**
8
+ * Weekly opening hours for server-side rendering (footer, home page,
9
+ * Restaurant schema); the browser loads them from Shopware again after
10
+ * hydration (useLiveShopData).
11
+ */
12
+ export default defineCachedEventHandler(
13
+ (): Promise<components["schemas"]["BusinessHourStruct"]> =>
14
+ load("business-hours", () => storeApiGet("/shopbite/business-hour")),
15
+ {
16
+ maxAge: useRuntimeConfig().public.shopBite.cacheTtl.businessHours,
17
+ // never older than the TTL (default swr would serve a stale answer once)
18
+ swr: false,
19
+ name: "business-hours",
20
+ getKey: () => "business-hours",
21
+ },
22
+ );
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ShopBite plugin configuration (delivery time, checkout switch, menu root)
3
+ * for server-side rendering, cached `cacheTtl.config` (shopBiteConfig). The
4
+ * browser loads it from Shopware again after hydration (useLiveShopData).
5
+ */
6
+ export default defineEventHandler(() => shopBiteConfig());
@@ -0,0 +1,20 @@
1
+ import type { components } from "~~/api-types/storeApiTypes";
2
+ import { createResilientLoader } from "../../utils/backoff";
3
+
4
+ const load = createResilientLoader<components["schemas"]["HolidayStruct"]>();
5
+
6
+ /**
7
+ * Closing days for server-side rendering (home page, Restaurant schema); the
8
+ * browser loads them from Shopware again after hydration (useLiveShopData).
9
+ */
10
+ export default defineCachedEventHandler(
11
+ (): Promise<components["schemas"]["HolidayStruct"]> =>
12
+ load("holidays", () => storeApiGet("/shopbite/holiday")),
13
+ {
14
+ maxAge: useRuntimeConfig().public.shopBite.cacheTtl.holidays,
15
+ // never older than the TTL (default swr would serve a stale answer once)
16
+ swr: false,
17
+ name: "holidays",
18
+ getKey: () => "holidays",
19
+ },
20
+ );
@@ -0,0 +1,59 @@
1
+ import type { components } from "~~/api-types/storeApiTypes";
2
+ import { createResilientLoader } from "../utils/backoff";
3
+
4
+ const TOP_SELLERS_LIMIT = 8;
5
+
6
+ const criteria = {
7
+ filter: [{ type: "equals", field: "markAsTopseller", value: true }],
8
+ limit: TOP_SELLERS_LIMIT,
9
+ // What the compact card and the quick view need (#327).
10
+ includes: {
11
+ product: [
12
+ "id",
13
+ "productNumber",
14
+ "name",
15
+ "translated",
16
+ "description",
17
+ "calculatedPrice",
18
+ "available",
19
+ "cover",
20
+ "sortedProperties",
21
+ // Allergens checked (#485); includes filter `translated` as well,
22
+ // so custom fields only come back when listed here.
23
+ "customFields",
24
+ // Card link to the quick view deep link (#289).
25
+ "seoUrls",
26
+ ],
27
+ seo_url: ["seoPathInfo", "isCanonical"],
28
+ product_media: ["media"],
29
+ media: ["url", "thumbnails"],
30
+ media_thumbnail: ["width", "url"],
31
+ property_group: ["id", "name", "translated", "options"],
32
+ property_group_option: ["id", "name", "translated", "customFields"],
33
+ },
34
+ associations: {
35
+ cover: { associations: { media: {} } },
36
+ properties: { associations: { group: {} } },
37
+ },
38
+ };
39
+
40
+ const load = createResilientLoader<components["schemas"]["Product"][]>();
41
+
42
+ /** The dishes marked as top sellers, for the home page (useTopSellers). */
43
+ export default defineCachedEventHandler(
44
+ (): Promise<components["schemas"]["Product"][]> =>
45
+ load("top-sellers", async () => {
46
+ const result = await storeApiPost<{
47
+ elements?: components["schemas"]["Product"][];
48
+ }>("/product", criteria, {
49
+ // Variants marked as top sellers inherit name, cover and properties.
50
+ headers: { "sw-inheritance": "true", "sw-include-seo-urls": "true" },
51
+ });
52
+ return result.elements ?? [];
53
+ }),
54
+ {
55
+ maxAge: useRuntimeConfig().public.shopBite.cacheTtl.listing,
56
+ name: "top-sellers",
57
+ getKey: () => "top-sellers",
58
+ },
59
+ );
@@ -8,7 +8,7 @@ import { buildAiCrawlerGroups } from "../utils/aiCrawlers";
8
8
  */
9
9
  export default defineNitroPlugin((nitroApp) => {
10
10
  nitroApp.hooks.hook("robots:config", (ctx) => {
11
- const { aiCrawlers } = useRuntimeConfig(ctx.event);
11
+ const { aiCrawlers } = useRuntimeConfig();
12
12
  const wildcard = ctx.groups.find((group) =>
13
13
  [group.userAgent ?? "*"].flat().includes("*"),
14
14
  );
@@ -4,8 +4,8 @@
4
4
  * the request origin (which is internal behind a reverse proxy).
5
5
  */
6
6
  export default defineNitroPlugin((nitroApp) => {
7
- nitroApp.hooks.hook("site-config:init", ({ event, siteConfig }) => {
8
- const { storeUrl } = useRuntimeConfig(event).public;
7
+ nitroApp.hooks.hook("site-config:init", ({ siteConfig }) => {
8
+ const { storeUrl } = useRuntimeConfig().public;
9
9
  if (storeUrl) {
10
10
  siteConfig.push({ _context: "storeUrl", url: storeUrl });
11
11
  }
@@ -1,4 +1,5 @@
1
1
  import { queryCollection } from "@nuxt/content/server";
2
+ import { defineEventHandler } from "nuxt/server";
2
3
  import type { components } from "~~/api-types/storeApiTypes";
3
4
  import { getDiets, getMainIngredients } from "../../app/utils/product";
4
5
  import { productDeepLink } from "../../app/utils/productUrl";
@@ -50,9 +51,12 @@ const PRODUCT_CRITERIA = {
50
51
  * `/llms.txt` (#402): the shop, its hours, ordering and the menu as Markdown
51
52
  * for language models. Every source is optional; a failing request leaves
52
53
  * its section out instead of failing the file.
54
+ *
55
+ * A `nuxt/server` handler: its event has the web-standard shape that
56
+ * `getPathRobotConfig()` of @nuxtjs/robots 7 reads.
53
57
  */
54
58
  export default defineEventHandler(async (event) => {
55
- const { shopware, site } = useRuntimeConfig(event).public;
59
+ const { shopware, site } = useRuntimeConfig().public;
56
60
  const siteUrl = getSiteConfig(event).url;
57
61
  const headers = { "sw-access-key": shopware.accessToken };
58
62
  const menuRoot = await menuRootId();
@@ -155,7 +159,7 @@ export default defineEventHandler(async (event) => {
155
159
  now: new Date(),
156
160
  });
157
161
 
158
- setResponseHeader(event, "Content-Type", "text/markdown; charset=utf-8");
162
+ event.res.headers.set("Content-Type", "text/markdown; charset=utf-8");
159
163
  return body;
160
164
  });
161
165
 
@@ -0,0 +1,67 @@
1
+ /** How long a failed Shopware request pauses the next ones. */
2
+ export const FAILURE_BACKOFF_MS = 30_000;
3
+
4
+ /** Remembers a failure for `ms`, so an outage is not asked on every request. */
5
+ export function createBackoff(
6
+ ms: number = FAILURE_BACKOFF_MS,
7
+ now: () => number = () => Date.now(),
8
+ ) {
9
+ let until = 0;
10
+ return {
11
+ active: () => now() < until,
12
+ trip: () => {
13
+ until = now() + ms;
14
+ },
15
+ };
16
+ }
17
+
18
+ function statusOf(error: unknown): number | undefined {
19
+ const { statusCode, status } = (error ?? {}) as {
20
+ statusCode?: number;
21
+ status?: number;
22
+ };
23
+ return statusCode ?? status;
24
+ }
25
+
26
+ /**
27
+ * A 5xx, or a fetch error without a response (network, timeout). A 4xx is
28
+ * an answer, and a programming error (TypeError) is no outage either.
29
+ */
30
+ export function isOutage(error: unknown): boolean {
31
+ const status = statusOf(error);
32
+ if (status !== undefined) return status >= 500;
33
+ return (error as { name?: string } | null)?.name === "FetchError";
34
+ }
35
+
36
+ /**
37
+ * Shields Shopware from a cache's misses during an outage (one loader per
38
+ * cached handler): the last good answer per key is served when a request
39
+ * fails, and after a failure Shopware is asked again only after the
40
+ * backoff; without a last good answer the request fails fast with 503.
41
+ * `keep` decides which answers are remembered (keeps the memory bounded).
42
+ */
43
+ export function createResilientLoader<T>(
44
+ keep: (value: T) => boolean = () => true,
45
+ backoff = createBackoff(),
46
+ ) {
47
+ const lastGood = new Map<string, T>();
48
+ const unavailable = () =>
49
+ Object.assign(new Error("Shopware unavailable"), { statusCode: 503 });
50
+
51
+ return async (key: string, load: () => Promise<T>): Promise<T> => {
52
+ if (backoff.active()) {
53
+ if (lastGood.has(key)) return lastGood.get(key)!;
54
+ throw unavailable();
55
+ }
56
+ try {
57
+ const value = await load();
58
+ if (keep(value)) lastGood.set(key, value);
59
+ return value;
60
+ } catch (error) {
61
+ if (!isOutage(error)) throw error;
62
+ backoff.trip();
63
+ if (lastGood.has(key)) return lastGood.get(key)!;
64
+ throw Object.assign(unavailable(), { cause: error });
65
+ }
66
+ };
67
+ }