@shopbite-de/storefront 2.4.0 → 2.6.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 (104) hide show
  1. package/.env.example +13 -1
  2. package/CLAUDE.md +7 -4
  3. package/api-types/storeApiSchema.json +62 -6
  4. package/api-types/storeApiTypes.d.ts +23 -4
  5. package/app/components/Checkout/DeliveryTimeSelect.vue +39 -18
  6. package/app/components/Checkout/Summary.vue +5 -1
  7. package/app/components/Home/Categories.vue +2 -2
  8. package/app/components/Home/Facts.vue +9 -4
  9. package/app/components/Home/Hero.vue +8 -2
  10. package/app/components/Navigation/MobileTop.vue +1 -1
  11. package/app/components/Order/Detail.vue +3 -4
  12. package/app/composables/useAddressAutocomplete.ts +3 -11
  13. package/app/composables/useCheckoutMethodGuard.ts +1 -1
  14. package/app/composables/useDeliveryTime.ts +8 -5
  15. package/app/composables/useShippingLeadTime.ts +17 -0
  16. package/app/composables/useShippingMethodChoice.ts +2 -2
  17. package/app/composables/useShopBiteConfig.ts +10 -1
  18. package/app/composables/useTrackEvent.ts +4 -3
  19. package/app/pages/account/recover/password/index.vue +10 -0
  20. package/app/pages/registrierung/bestaetigen.vue +4 -0
  21. package/app/utils/leadTime.ts +97 -0
  22. package/app/utils/openingHours.ts +1 -1
  23. package/app/utils/schema.ts +2 -2
  24. package/app/utils/trackingUrl.ts +39 -0
  25. package/content/index.yml +16 -16
  26. package/content/zahlung-und-versand.md +3 -3
  27. package/content.config.ts +2 -2
  28. package/docs/notes/2026-07-04-issue-239-hydration-mismatches.md +1 -1
  29. package/docs/notes/2026-09-08-issue-244-category-url-trailing-slash.md +2 -2
  30. package/docs/notes/2026-09-10-issue-251-shop-data-in-base-layer.md +4 -4
  31. package/docs/notes/2026-09-10-issue-272-restaurant-schema.md +3 -3
  32. package/docs/notes/2026-09-10-issue-273-performance-media.md +4 -4
  33. package/docs/notes/2026-09-10-issue-274-seo-basics.md +6 -6
  34. package/docs/notes/2026-09-10-issue-275-accessibility.md +3 -3
  35. package/docs/notes/2026-09-10-issue-290-footer-nap.md +5 -5
  36. package/docs/notes/2026-09-10-issue-294-matomo-without-config.md +1 -1
  37. package/docs/notes/2026-09-10-issue-296-track-direct-search.md +1 -1
  38. package/docs/notes/2026-09-10-issue-312-store-api-criteria-post.md +3 -3
  39. package/docs/notes/2026-09-10-issue-313-wishlist-scoped-tailwind.md +1 -1
  40. package/docs/notes/2026-09-10-issue-314-mobile-js-cost.md +1 -1
  41. package/docs/notes/2026-09-12-issue-319-stylesheet-cost.md +1 -1
  42. package/docs/notes/2026-09-12-issue-325-product-card.md +2 -2
  43. package/docs/notes/2026-09-12-issue-327-home-hero.md +2 -2
  44. package/docs/notes/2026-09-13-issue-332-home-info-cards.md +1 -1
  45. package/docs/notes/2026-09-13-quick-view-flicker.md +1 -1
  46. package/docs/notes/2026-09-14-demo-noindex.md +2 -2
  47. package/docs/notes/2026-09-17-quick-view-compact-options.md +1 -1
  48. package/docs/notes/2026-09-21-issue-273-cache-and-demo-video.md +1 -1
  49. package/docs/notes/2026-09-21-issue-363-non-fatal-404.md +2 -2
  50. package/docs/notes/2026-09-21-issue-366-wishlist-404.md +1 -1
  51. package/docs/notes/2026-09-21-issue-378-dev-modules.md +1 -1
  52. package/docs/notes/2026-10-05-issue-289-product-deep-links.md +1 -1
  53. package/docs/notes/2026-10-05-issue-400-menu-item-ingredients-diet.md +1 -1
  54. package/docs/notes/2026-10-05-issue-401-restaurant-schema-ordering.md +1 -1
  55. package/docs/notes/2026-10-05-issue-402-llms-txt.md +1 -1
  56. package/docs/notes/2026-10-05-issue-403-ai-crawlers.md +1 -1
  57. package/docs/notes/2026-10-05-issue-404-faq.md +1 -1
  58. package/docs/notes/2026-10-06-old-seo-url-redirect.md +5 -5
  59. package/docs/notes/2026-10-07-issue-434-property-group-projection.md +1 -1
  60. package/nuxt.config.ts +56 -8
  61. package/package.json +3 -2
  62. package/server/api/address/autocomplete.get.ts +79 -14
  63. package/server/api/listing/[categoryId].get.ts +5 -28
  64. package/server/api/search.get.ts +4 -18
  65. package/server/api/shopbite/config.get.ts +1 -1
  66. package/server/plugins/bounded-cache.ts +28 -0
  67. package/server/plugins/security-headers.ts +54 -0
  68. package/server/routes/llms.txt.ts +6 -5
  69. package/server/utils/addressAutocomplete.ts +181 -0
  70. package/server/utils/listingParams.ts +117 -0
  71. package/server/utils/llmsTxt.ts +7 -3
  72. package/server/utils/securityHeaders.ts +165 -0
  73. package/server/utils/shopBiteConfig.ts +1 -1
  74. package/test/layer/nuxt.config.ts +2 -2
  75. package/test/nuxt/AccountPagesPreset.test.ts +10 -10
  76. package/test/nuxt/AuthPagesPreset.test.ts +3 -0
  77. package/test/nuxt/CheckoutFormsPreset.test.ts +5 -5
  78. package/test/nuxt/CheckoutOnePage.test.ts +4 -1
  79. package/test/nuxt/CheckoutSummary.test.ts +42 -3
  80. package/test/nuxt/DeliveryTimeSelect.test.ts +181 -0
  81. package/test/nuxt/HeaderFooterPreset.test.ts +10 -10
  82. package/test/nuxt/HomeFaq.test.ts +1 -1
  83. package/test/nuxt/HomeLeadTimes.test.ts +78 -0
  84. package/test/nuxt/NavigationMobileTop.test.ts +1 -1
  85. package/test/nuxt/OrderPagesPreset.test.ts +22 -2
  86. package/test/nuxt/RegisterConfirmPage.test.ts +12 -0
  87. package/test/nuxt/useAddressAutocomplete.test.ts +7 -22
  88. package/test/nuxt/useCheckoutMethodGuard.test.ts +1 -1
  89. package/test/nuxt/useDeliveryTime.test.ts +30 -6
  90. package/test/nuxt/useShippingLeadTime.test.ts +66 -0
  91. package/test/nuxt/useShippingMethodChoice.test.ts +1 -1
  92. package/test/nuxt/useShopBiteConfig.test.ts +57 -3
  93. package/test/nuxt/useTrackEvent.test.ts +16 -0
  94. package/test/unit/addressAutocomplete.spec.ts +247 -0
  95. package/test/unit/boundedCache.spec.ts +231 -0
  96. package/test/unit/highlight.spec.ts +2 -2
  97. package/test/unit/leadTime.spec.ts +86 -0
  98. package/test/unit/llmsTxt.spec.ts +30 -29
  99. package/test/unit/openingHours.spec.ts +3 -3
  100. package/test/unit/schema.spec.ts +29 -32
  101. package/test/unit/securityHeaders.spec.ts +254 -0
  102. package/test/unit/seo.spec.ts +23 -29
  103. package/test/unit/sitemap.spec.ts +1 -1
  104. package/test/unit/trackingUrl.spec.ts +48 -0
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ fulfillmentLeadTime,
4
+ parseWishedTime,
5
+ shippingLeadTime,
6
+ wishedTimeComment,
7
+ } from "../../app/utils/leadTime";
8
+
9
+ const DELIVERY = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5b";
10
+ const PICKUP = "0190a3b0c1d27e0f8a9b0c1d2e3f4a5c";
11
+
12
+ const config = {
13
+ shippingMethods: [
14
+ { id: DELIVERY, fulfillment: "delivery" as const, leadTimeMinutes: 45 },
15
+ { id: PICKUP, fulfillment: "pickup" as const, leadTimeMinutes: 20 },
16
+ ],
17
+ };
18
+
19
+ describe("shippingLeadTime", () => {
20
+ it("takes the lead time and fulfillment the plugin reports", () => {
21
+ expect(shippingLeadTime(config, { id: DELIVERY })).toEqual({
22
+ fulfillment: "delivery",
23
+ minutes: 45,
24
+ });
25
+ expect(shippingLeadTime(config, { id: PICKUP })).toEqual({
26
+ fulfillment: "pickup",
27
+ minutes: 20,
28
+ });
29
+ });
30
+
31
+ it("has no lead time for a method the plugin does not list", () => {
32
+ expect(shippingLeadTime(config, { id: "other" })).toEqual({
33
+ fulfillment: "delivery",
34
+ minutes: null,
35
+ });
36
+ expect(shippingLeadTime(null, undefined)).toEqual({
37
+ fulfillment: "delivery",
38
+ minutes: null,
39
+ });
40
+ });
41
+ });
42
+
43
+ describe("fulfillmentLeadTime", () => {
44
+ it("returns the lead time of the first method of the fulfillment", () => {
45
+ const many = {
46
+ shippingMethods: [
47
+ ...config.shippingMethods,
48
+ { id: "x", fulfillment: "delivery" as const, leadTimeMinutes: 60 },
49
+ ],
50
+ };
51
+ expect(fulfillmentLeadTime(many, "delivery")).toBe(45);
52
+ expect(fulfillmentLeadTime(many, "pickup")).toBe(20);
53
+ });
54
+
55
+ it("is null without a method of the fulfillment", () => {
56
+ expect(
57
+ fulfillmentLeadTime(
58
+ { shippingMethods: [config.shippingMethods[1]!] },
59
+ "delivery",
60
+ ),
61
+ ).toBeNull();
62
+ expect(fulfillmentLeadTime({ shippingMethods: [] }, "pickup")).toBeNull();
63
+ expect(fulfillmentLeadTime(undefined, "delivery")).toBeNull();
64
+ });
65
+ });
66
+
67
+ describe("wished time in the customer comment", () => {
68
+ it("writes the prefix of the fulfillment", () => {
69
+ expect(wishedTimeComment("delivery", "19:15")).toBe(
70
+ "Wunschlieferzeit: 19:15",
71
+ );
72
+ expect(wishedTimeComment("pickup", "19:15")).toBe("Wunschabholzeit: 19:15");
73
+ });
74
+
75
+ it("reads both prefixes", () => {
76
+ expect(parseWishedTime("Wunschlieferzeit: 19:15")).toBe("19:15");
77
+ expect(parseWishedTime("Wunschabholzeit: 18:40")).toBe("18:40");
78
+ expect(parseWishedTime(" Wunschabholzeit:18:40 ")).toBe("18:40");
79
+ });
80
+
81
+ it("keeps other comments", () => {
82
+ expect(parseWishedTime("Bitte klingeln")).toBe("Bitte klingeln");
83
+ expect(parseWishedTime(undefined)).toBeUndefined();
84
+ expect(parseWishedTime(null)).toBeUndefined();
85
+ });
86
+ });
@@ -6,17 +6,17 @@ const now = new Date("2026-10-05T12:00:00Z");
6
6
  describe("buildLlmsTxt", () => {
7
7
  it("renders shop, hours, ordering, menu and pages as Markdown", () => {
8
8
  const text = buildLlmsTxt({
9
- name: "Pizzeria La Fattoria",
9
+ name: "Pizzeria Esempio",
10
10
  description: "Italienisch-deutsche Küche seit 1997.",
11
- url: "https://www.pizzeria-lafattoria.de",
11
+ url: "https://www.pizzeria-esempio.example",
12
12
  cuisine: "Italienische Küche",
13
13
  address: {
14
- street: "Kantstraße 6",
15
- postalCode: "63179",
16
- city: "Obertshausen",
14
+ street: "Musterstraße 1",
15
+ postalCode: "12345",
16
+ city: "Musterstadt",
17
17
  },
18
- telephone: "+49 6104 71427",
19
- deliveryAreas: ["63179 Obertshausen", "63165 Lämmerspiel"],
18
+ telephone: "+49 123 456789",
19
+ deliveryAreas: ["12345 Musterstadt", "12346 Beispieldorf"],
20
20
  businessHours: [1, 2, 3, 4, 5].map((dayOfWeek) => ({
21
21
  dayOfWeek,
22
22
  openingTime: "11:30:00",
@@ -29,11 +29,12 @@ describe("buildLlmsTxt", () => {
29
29
  ],
30
30
  isCheckoutEnabled: true,
31
31
  deliveryTime: 30,
32
- menuUrl: "https://www.pizzeria-lafattoria.de/speisekarte",
32
+ pickupTime: 20,
33
+ menuUrl: "https://www.pizzeria-esempio.example/speisekarte",
33
34
  menu: [
34
35
  {
35
36
  name: "Pizza",
36
- url: "https://www.pizzeria-lafattoria.de/c/Pizza/",
37
+ url: "https://www.pizzeria-esempio.example/c/Pizza/",
37
38
  items: [
38
39
  {
39
40
  name: "Pizza Margherita",
@@ -45,7 +46,7 @@ describe("buildLlmsTxt", () => {
45
46
  {
46
47
  name: "Pizza Salami",
47
48
  price: 8.5,
48
- url: "https://www.pizzeria-lafattoria.de/c/Pizza/?produkt=22",
49
+ url: "https://www.pizzeria-esempio.example/c/Pizza/?produkt=22",
49
50
  },
50
51
  ],
51
52
  },
@@ -71,31 +72,31 @@ describe("buildLlmsTxt", () => {
71
72
  pages: [
72
73
  {
73
74
  title: "Zahlungs- und Lieferinformationen",
74
- url: "https://www.pizzeria-lafattoria.de/zahlung-und-versand",
75
+ url: "https://www.pizzeria-esempio.example/zahlung-und-versand",
75
76
  description: "Zahlungs- und Lieferinformationen",
76
77
  },
77
78
  ],
78
79
  faq: [
79
80
  {
80
81
  question: "Wohin liefern Sie?",
81
- answer: "Nach Obertshausen und Lämmerspiel.",
82
+ answer: "Nach Musterstadt und Beispieldorf.",
82
83
  },
83
84
  ],
84
85
  currency: "EUR",
85
86
  now,
86
87
  });
87
88
 
88
- expect(text).toBe(`# Pizzeria La Fattoria
89
+ expect(text).toBe(`# Pizzeria Esempio
89
90
 
90
- > Pizzeria La Fattoria: Italienische Küche in Obertshausen. Online bestellen zur Lieferung oder Abholung unter https://www.pizzeria-lafattoria.de.
91
+ > Pizzeria Esempio: Italienische Küche in Musterstadt. Online bestellen zur Lieferung oder Abholung unter https://www.pizzeria-esempio.example.
91
92
 
92
93
  Italienisch-deutsche Küche seit 1997.
93
94
 
94
95
  ## Kontakt
95
96
 
96
- - Adresse: Kantstraße 6, 63179 Obertshausen
97
- - Telefon: +49 6104 71427
98
- - Website: https://www.pizzeria-lafattoria.de
97
+ - Adresse: Musterstraße 1, 12345 Musterstadt
98
+ - Telefon: +49 123 456789
99
+ - Website: https://www.pizzeria-esempio.example
99
100
 
100
101
  ## Öffnungszeiten
101
102
 
@@ -105,23 +106,23 @@ Italienisch-deutsche Küche seit 1997.
105
106
 
106
107
  ## Bestellen
107
108
 
108
- - Online bestellen: https://www.pizzeria-lafattoria.de/speisekarte
109
- - Liefergebiet: 63179 Obertshausen, 63165 Lämmerspiel
109
+ - Online bestellen: https://www.pizzeria-esempio.example/speisekarte
110
+ - Liefergebiet: 12345 Musterstadt, 12346 Beispieldorf
110
111
  - Lieferzeit: ca. 30 Minuten
111
- - Abholung im Restaurant möglich
112
+ - Abholung im Restaurant möglich, abholbereit in ca. 20 Minuten
112
113
 
113
114
  ## Häufige Fragen
114
115
 
115
116
  ### Wohin liefern Sie?
116
117
 
117
- Nach Obertshausen und Lämmerspiel.
118
+ Nach Musterstadt und Beispieldorf.
118
119
 
119
120
  ## Speisekarte
120
121
 
121
- ### [Pizza](https://www.pizzeria-lafattoria.de/c/Pizza/)
122
+ ### [Pizza](https://www.pizzeria-esempio.example/c/Pizza/)
122
123
 
123
124
  - Pizza Margherita: ab 7,00 € (Tomatensoße, Mozzarella; vegetarisch)
124
- - [Pizza Salami](https://www.pizzeria-lafattoria.de/c/Pizza/?produkt=22): 8,50 €
125
+ - [Pizza Salami](https://www.pizzeria-esempio.example/c/Pizza/?produkt=22): 8,50 €
125
126
 
126
127
  ### Nudeln
127
128
 
@@ -131,22 +132,22 @@ Nach Obertshausen und Lämmerspiel.
131
132
 
132
133
  ## Weitere Informationen
133
134
 
134
- - [Zahlungs- und Lieferinformationen](https://www.pizzeria-lafattoria.de/zahlung-und-versand)
135
+ - [Zahlungs- und Lieferinformationen](https://www.pizzeria-esempio.example/zahlung-und-versand)
135
136
  `);
136
137
  });
137
138
 
138
139
  it("names other names of the shop under Kontakt", () => {
139
140
  expect(
140
141
  buildLlmsTxt({
141
- name: "Pizzeria La Fattoria",
142
- alternateNames: ["La Fattoria / Alte Schmiede", "Alte Schmiede"],
143
- url: "https://www.pizzeria-lafattoria.de",
142
+ name: "Pizzeria Esempio",
143
+ alternateNames: ["Esempio / Alter Hof", "Alter Hof"],
144
+ url: "https://www.pizzeria-esempio.example",
144
145
  now,
145
146
  }),
146
147
  ).toContain(`## Kontakt
147
148
 
148
- - Auch bekannt als: La Fattoria / Alte Schmiede, Alte Schmiede
149
- - Website: https://www.pizzeria-lafattoria.de
149
+ - Auch bekannt als: Esempio / Alter Hof, Alter Hof
150
+ - Website: https://www.pizzeria-esempio.example
150
151
  `);
151
152
  });
152
153
 
@@ -18,7 +18,7 @@ const dinner = (dayOfWeek: number) => ({
18
18
 
19
19
  describe("groupOpeningHours", () => {
20
20
  it("groups consecutive days with identical intervals", () => {
21
- // Pizzeria La Fattoria: closed on Tuesday, Saturday dinner only
21
+ // closed on Tuesday, Saturday dinner only
22
22
  const businessHours = [1, 3, 4, 5, 7].flatMap((day) => [
23
23
  dinner(day),
24
24
  lunch(day),
@@ -57,8 +57,8 @@ describe("groupOpeningHours", () => {
57
57
 
58
58
  describe("toTelHref", () => {
59
59
  it("strips formatting from the phone number", () => {
60
- expect(toTelHref("+49 6104 71427")).toBe("tel:+49610471427");
61
- expect(toTelHref("06104 / 71-427")).toBe("tel:0610471427");
60
+ expect(toTelHref("+49 123 456789")).toBe("tel:+49123456789");
61
+ expect(toTelHref("0123 / 456-789")).toBe("tel:0123456789");
62
62
  });
63
63
  });
64
64
 
@@ -81,19 +81,19 @@ describe("buildSpecialOpeningHoursSpecification", () => {
81
81
 
82
82
  describe("buildRestaurantSchema", () => {
83
83
  const site = {
84
- name: "Pizzeria La Fattoria",
85
- description: "Italienisch-deutsche Küche in Obertshausen seit 1997.",
86
- url: "https://www.pizzeria-lafattoria.de",
87
- image: "https://www.pizzeria-lafattoria.de/card.png",
88
- telephone: "+49 6104 71427",
84
+ name: "Pizzeria Esempio",
85
+ description: "Italienisch-deutsche Küche in Musterstadt seit 1997.",
86
+ url: "https://www.pizzeria-esempio.example",
87
+ image: "https://www.pizzeria-esempio.example/card.png",
88
+ telephone: "+49 123 456789",
89
89
  cuisine: "Italienisch",
90
90
  priceRange: "€€",
91
91
  googleBusinessProfileUrl: "https://maps.google.com/?cid=123",
92
92
  address: {
93
- street: "Kantstr. 6",
93
+ street: "Musterstr. 1",
94
94
  // a number: Nuxt parses a numeric env value
95
- postalCode: 63179 as unknown as string,
96
- city: "Obertshausen",
95
+ postalCode: 12345 as unknown as string,
96
+ city: "Musterstadt",
97
97
  country: "DE",
98
98
  },
99
99
  };
@@ -105,15 +105,15 @@ describe("buildRestaurantSchema", () => {
105
105
  holidays: [
106
106
  { start: "2026-07-12T21:00:00Z", end: "2026-08-05T22:00:00Z" },
107
107
  ],
108
- menuUrl: "https://www.pizzeria-lafattoria.de/speisekarte",
108
+ menuUrl: "https://www.pizzeria-esempio.example/speisekarte",
109
109
  menuSections: [
110
- { name: "Pizza", url: "https://www.pizzeria-lafattoria.de/c/Pizza/" },
110
+ { name: "Pizza", url: "https://www.pizzeria-esempio.example/c/Pizza/" },
111
111
  {
112
112
  name: "Nudeln",
113
113
  sections: [
114
114
  {
115
115
  name: "Spaghetti",
116
- url: "https://www.pizzeria-lafattoria.de/c/Nudeln/Spaghetti/",
116
+ url: "https://www.pizzeria-esempio.example/c/Nudeln/Spaghetti/",
117
117
  },
118
118
  ],
119
119
  },
@@ -123,7 +123,7 @@ describe("buildRestaurantSchema", () => {
123
123
  expect(schema).toEqual({
124
124
  "@context": "https://schema.org",
125
125
  "@type": "Restaurant",
126
- "@id": "https://www.pizzeria-lafattoria.de#restaurant",
126
+ "@id": "https://www.pizzeria-esempio.example#restaurant",
127
127
  name: site.name,
128
128
  description: site.description,
129
129
  url: site.url,
@@ -133,9 +133,9 @@ describe("buildRestaurantSchema", () => {
133
133
  priceRange: "€€",
134
134
  address: {
135
135
  "@type": "PostalAddress",
136
- streetAddress: "Kantstr. 6",
137
- postalCode: "63179",
138
- addressLocality: "Obertshausen",
136
+ streetAddress: "Musterstr. 1",
137
+ postalCode: "12345",
138
+ addressLocality: "Musterstadt",
139
139
  addressCountry: "DE",
140
140
  },
141
141
  sameAs: ["https://maps.google.com/?cid=123"],
@@ -158,14 +158,14 @@ describe("buildRestaurantSchema", () => {
158
158
  ],
159
159
  hasMenu: {
160
160
  "@type": "Menu",
161
- "@id": "https://www.pizzeria-lafattoria.de#menu",
161
+ "@id": "https://www.pizzeria-esempio.example#menu",
162
162
  name: "Speisekarte",
163
- url: "https://www.pizzeria-lafattoria.de/speisekarte",
163
+ url: "https://www.pizzeria-esempio.example/speisekarte",
164
164
  hasMenuSection: [
165
165
  {
166
166
  "@type": "MenuSection",
167
167
  name: "Pizza",
168
- url: "https://www.pizzeria-lafattoria.de/c/Pizza/",
168
+ url: "https://www.pizzeria-esempio.example/c/Pizza/",
169
169
  },
170
170
  {
171
171
  "@type": "MenuSection",
@@ -174,7 +174,7 @@ describe("buildRestaurantSchema", () => {
174
174
  {
175
175
  "@type": "MenuSection",
176
176
  name: "Spaghetti",
177
- url: "https://www.pizzeria-lafattoria.de/c/Nudeln/Spaghetti/",
177
+ url: "https://www.pizzeria-esempio.example/c/Nudeln/Spaghetti/",
178
178
  },
179
179
  ],
180
180
  },
@@ -187,19 +187,19 @@ describe("buildRestaurantSchema", () => {
187
187
  const schema = buildRestaurantSchema({
188
188
  site: {
189
189
  ...site,
190
- deliveryAreas: ["63179 Obertshausen", "63165 Lämmerspiel"],
190
+ deliveryAreas: ["12345 Musterstadt", "12346 Beispieldorf"],
191
191
  // strings: env values that are not plain numbers
192
192
  geo: { latitude: "50.0716", longitude: 8.8483 },
193
193
  acceptsReservations: "Nur telefonisch",
194
194
  },
195
- orderUrl: "https://www.pizzeria-lafattoria.de/speisekarte",
195
+ orderUrl: "https://www.pizzeria-esempio.example/speisekarte",
196
196
  paymentMethods: ["Barzahlung", "EC-Karte"],
197
197
  currency: "EUR",
198
198
  });
199
199
 
200
200
  expect(schema).toMatchObject({
201
201
  geo: { "@type": "GeoCoordinates", latitude: 50.0716, longitude: 8.8483 },
202
- areaServed: ["63179 Obertshausen", "63165 Lämmerspiel"],
202
+ areaServed: ["12345 Musterstadt", "12346 Beispieldorf"],
203
203
  acceptsReservations: "Nur telefonisch",
204
204
  paymentAccepted: "Barzahlung, EC-Karte",
205
205
  currenciesAccepted: "EUR",
@@ -207,7 +207,7 @@ describe("buildRestaurantSchema", () => {
207
207
  "@type": "OrderAction",
208
208
  target: {
209
209
  "@type": "EntryPoint",
210
- urlTemplate: "https://www.pizzeria-lafattoria.de/speisekarte",
210
+ urlTemplate: "https://www.pizzeria-esempio.example/speisekarte",
211
211
  actionPlatform: [
212
212
  "https://schema.org/DesktopWebPlatform",
213
213
  "https://schema.org/MobileWebPlatform",
@@ -246,16 +246,13 @@ describe("buildRestaurantSchema", () => {
246
246
  it("lists other names of the shop as alternateName", () => {
247
247
  const schema = buildRestaurantSchema({
248
248
  site: {
249
- name: "Pizzeria La Fattoria",
250
- url: "https://www.pizzeria-lafattoria.de",
251
- alternateNames: ["La Fattoria / Alte Schmiede", "Alte Schmiede"],
249
+ name: "Pizzeria Esempio",
250
+ url: "https://www.pizzeria-esempio.example",
251
+ alternateNames: ["Esempio / Alter Hof", "Alter Hof"],
252
252
  },
253
253
  });
254
254
 
255
- expect(schema.alternateName).toEqual([
256
- "La Fattoria / Alte Schmiede",
257
- "Alte Schmiede",
258
- ]);
255
+ expect(schema.alternateName).toEqual(["Esempio / Alter Hof", "Alter Hof"]);
259
256
  });
260
257
 
261
258
  it("leaves empty values out", () => {
@@ -365,7 +362,7 @@ describe("buildFaqPageSchema", () => {
365
362
  it("maps questions and answers", () => {
366
363
  expect(
367
364
  buildFaqPageSchema([
368
- { question: "Wohin liefern Sie?", answer: "Nach Obertshausen." },
365
+ { question: "Wohin liefern Sie?", answer: "Nach Musterstadt." },
369
366
  ]),
370
367
  ).toEqual({
371
368
  "@context": "https://schema.org",
@@ -374,7 +371,7 @@ describe("buildFaqPageSchema", () => {
374
371
  {
375
372
  "@type": "Question",
376
373
  name: "Wohin liefern Sie?",
377
- acceptedAnswer: { "@type": "Answer", text: "Nach Obertshausen." },
374
+ acceptedAnswer: { "@type": "Answer", text: "Nach Musterstadt." },
378
375
  },
379
376
  ],
380
377
  });
@@ -0,0 +1,254 @@
1
+ import { createHash } from "node:crypto";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import {
4
+ contentSecurityPolicyReportOnly,
5
+ inlineScriptHashes,
6
+ securityHeaders,
7
+ type SecurityHeadersConfig,
8
+ } from "../../server/utils/securityHeaders";
9
+
10
+ const CONFIG: SecurityHeadersConfig = {
11
+ strictTransportSecurity: "max-age=31536000; includeSubDomains",
12
+ contentTypeOptions: "nosniff",
13
+ frameOptions: "DENY",
14
+ frameAncestors: "'none'",
15
+ referrerPolicy: "strict-origin-when-cross-origin",
16
+ permissionsPolicy: "camera=(), microphone=(), geolocation=()",
17
+ htmlCacheControl: "private, no-store",
18
+ contentSecurityPolicyReportOnly: { enabled: true },
19
+ };
20
+
21
+ const sha = (content: string) =>
22
+ `'sha256-${createHash("sha256").update(content).digest("base64")}'`;
23
+
24
+ describe("securityHeaders", () => {
25
+ it("sends the hardening headers for an https shop", () => {
26
+ expect(securityHeaders(CONFIG, "https://shop.example.com")).toEqual({
27
+ "strict-transport-security": "max-age=31536000; includeSubDomains",
28
+ "x-content-type-options": "nosniff",
29
+ "x-frame-options": "DENY",
30
+ "content-security-policy": "frame-ancestors 'none'",
31
+ "referrer-policy": "strict-origin-when-cross-origin",
32
+ "permissions-policy": "camera=(), microphone=(), geolocation=()",
33
+ });
34
+ });
35
+
36
+ it("sends no HSTS when the store URL is not https", () => {
37
+ for (const url of ["http://localhost:3000", "", undefined, "nonsense"]) {
38
+ expect(securityHeaders(CONFIG, url)).not.toHaveProperty(
39
+ "strict-transport-security",
40
+ );
41
+ }
42
+ });
43
+
44
+ it("leaves a header out when its value is empty", () => {
45
+ const headers = securityHeaders(
46
+ {
47
+ ...CONFIG,
48
+ frameOptions: "",
49
+ frameAncestors: "https://partner.example",
50
+ },
51
+ "https://shop.example.com",
52
+ );
53
+
54
+ expect(headers).not.toHaveProperty("x-frame-options");
55
+ expect(headers["content-security-policy"]).toBe(
56
+ "frame-ancestors https://partner.example",
57
+ );
58
+ expect(securityHeaders({}, "https://shop.example.com")).toEqual({});
59
+ });
60
+ });
61
+
62
+ describe("inlineScriptHashes", () => {
63
+ it("hashes executable inline scripts only", () => {
64
+ const config = "window.__NUXT__={};window.__NUXT__.config={}";
65
+ const importMap = '{"imports":{"#entry":"/_nuxt/a.js"}}';
66
+ const html = [
67
+ `<script type="importmap">${importMap}</script>`,
68
+ `<script>${config}</script>`,
69
+ '<script type="module" src="/_nuxt/a.js" crossorigin></script>',
70
+ '<script type="application/json" id="__NUXT_DATA__">[1]</script>',
71
+ '<script type="application/ld+json">{"@type":"Restaurant"}</script>',
72
+ ].join("");
73
+
74
+ expect(inlineScriptHashes(html)).toEqual([sha(importMap), sha(config)]);
75
+ });
76
+ });
77
+
78
+ describe("contentSecurityPolicyReportOnly", () => {
79
+ const directives = (policy: string) =>
80
+ Object.fromEntries(
81
+ policy.split("; ").map((d) => {
82
+ const [name, ...values] = d.split(" ");
83
+ return [name, values];
84
+ }),
85
+ );
86
+
87
+ it("allows self, Shopware, Matomo, the configured hosts and the hashes", () => {
88
+ const policy = directives(
89
+ contentSecurityPolicyReportOnly({
90
+ config: {
91
+ enabled: true,
92
+ connectSrc: "https://rum.example.com",
93
+ scriptSrc: "https://cdn.example.com",
94
+ reportUri: "https://rum.example.com/csp",
95
+ },
96
+ scriptHashes: ["'sha256-abc'"],
97
+ shopwareEndpoint: "https://api.example.com/store-api",
98
+ matomoUrl: "https://stats.example.com/",
99
+ }),
100
+ );
101
+
102
+ expect(policy["default-src"]).toEqual(["'self'"]);
103
+ expect(policy["script-src"]).toEqual([
104
+ "'self'",
105
+ "'sha256-abc'",
106
+ "https://stats.example.com",
107
+ "https://cdn.example.com",
108
+ ]);
109
+ expect(policy["connect-src"]).toEqual([
110
+ "'self'",
111
+ "https://api.example.com",
112
+ "https://stats.example.com",
113
+ "https://rum.example.com",
114
+ ]);
115
+ expect(policy["object-src"]).toEqual(["'none'"]);
116
+ expect(policy["report-uri"]).toEqual(["https://rum.example.com/csp"]);
117
+ expect(policy["script-src"]).not.toContain("'unsafe-inline'");
118
+ });
119
+
120
+ it("leaves out unset hosts", () => {
121
+ const policy = directives(
122
+ contentSecurityPolicyReportOnly({
123
+ config: { enabled: true },
124
+ scriptHashes: [],
125
+ }),
126
+ );
127
+
128
+ expect(policy["script-src"]).toEqual(["'self'"]);
129
+ expect(policy["connect-src"]).toEqual(["'self'"]);
130
+ expect(policy).not.toHaveProperty("report-uri");
131
+ });
132
+ });
133
+
134
+ describe("security headers plugin", () => {
135
+ type Hook = (...args: unknown[]) => void;
136
+ let hooks: Record<string, Hook>;
137
+ let setResponseHeaders: ReturnType<typeof vi.fn>;
138
+
139
+ async function loadPlugin(config: SecurityHeadersConfig = CONFIG) {
140
+ vi.resetModules();
141
+ hooks = {};
142
+ setResponseHeaders = vi.fn();
143
+ const utils = await import("../../server/utils/securityHeaders");
144
+ vi.stubGlobal("defineNitroPlugin", (plugin: unknown) => plugin);
145
+ vi.stubGlobal("setResponseHeaders", setResponseHeaders);
146
+ vi.stubGlobal("useRuntimeConfig", () => ({
147
+ securityHeaders: config,
148
+ public: {
149
+ storeUrl: "https://shop.example.com",
150
+ shopware: { endpoint: "https://api.example.com/store-api" },
151
+ scripts: { matomoAnalytics: { matomoUrl: "", siteId: "" } },
152
+ },
153
+ }));
154
+ for (const [name, value] of Object.entries(utils)) {
155
+ vi.stubGlobal(name, value);
156
+ }
157
+ const plugin = (await import("../../server/plugins/security-headers"))
158
+ .default as unknown as (app: unknown) => void;
159
+ plugin({ hooks: { hook: (name: string, fn: Hook) => (hooks[name] = fn) } });
160
+ }
161
+
162
+ const render = (headers: Record<string, string>, body = "<html></html>") => {
163
+ const event = { node: { res: { removeHeader: vi.fn() } } };
164
+ const response = { body, headers };
165
+ hooks["render:response"]!(response, { event });
166
+ return { response, event };
167
+ };
168
+
169
+ beforeEach(() => loadPlugin());
170
+ afterEach(() => vi.unstubAllGlobals());
171
+
172
+ it("sets the headers on every request", () => {
173
+ const event = {};
174
+ hooks.request!(event);
175
+
176
+ expect(setResponseHeaders).toHaveBeenCalledWith(
177
+ event,
178
+ expect.objectContaining({
179
+ "strict-transport-security": "max-age=31536000; includeSubDomains",
180
+ "x-frame-options": "DENY",
181
+ }),
182
+ );
183
+ });
184
+
185
+ it("marks rendered HTML private and removes x-powered-by", () => {
186
+ const { response, event } = render({
187
+ "content-type": "text/html;charset=utf-8",
188
+ "x-powered-by": "Nuxt",
189
+ });
190
+
191
+ expect(response.headers["cache-control"]).toBe("private, no-store");
192
+ expect(response.headers).not.toHaveProperty("x-powered-by");
193
+ expect(event.node.res.removeHeader).toHaveBeenCalledWith("x-powered-by");
194
+ });
195
+
196
+ it("keeps a Cache-Control set by a route rule", () => {
197
+ const { response } = render({
198
+ "content-type": "text/html",
199
+ "cache-control": "public, max-age=60",
200
+ });
201
+
202
+ expect(response.headers["cache-control"]).toBe("public, max-age=60");
203
+ });
204
+
205
+ it("leaves non-HTML responses uncached by the rule", () => {
206
+ const { response } = render({ "content-type": "text/plain" });
207
+
208
+ expect(response.headers).not.toHaveProperty("cache-control");
209
+ expect(response.headers).not.toHaveProperty(
210
+ "content-security-policy-report-only",
211
+ );
212
+ });
213
+
214
+ it("adds a report-only policy with the hashes of the page's inline scripts", () => {
215
+ const script = "window.__NUXT__={}";
216
+ const { response } = render(
217
+ { "content-type": "text/html" },
218
+ `<html><script>${script}</script></html>`,
219
+ );
220
+
221
+ const policy = response.headers["content-security-policy-report-only"];
222
+ expect(policy).toContain(`script-src 'self' ${sha(script)}`);
223
+ expect(policy).toContain("connect-src 'self' https://api.example.com");
224
+ });
225
+
226
+ it("sends no report-only policy when it is disabled", async () => {
227
+ await loadPlugin({
228
+ ...CONFIG,
229
+ contentSecurityPolicyReportOnly: { enabled: false },
230
+ });
231
+ const { response } = render({ "content-type": "text/html" });
232
+
233
+ expect(response.headers).not.toHaveProperty(
234
+ "content-security-policy-report-only",
235
+ );
236
+ });
237
+ });
238
+
239
+ describe("nuxt.config", () => {
240
+ afterEach(() => vi.unstubAllGlobals());
241
+
242
+ it("lets the service worker cache no pages", async () => {
243
+ vi.stubGlobal("defineNuxtConfig", (config: unknown) => config);
244
+ const config = (await import("../../nuxt.config")).default as {
245
+ pwa: { generateSW: { runtimeCaching?: unknown[] } };
246
+ runtimeConfig: { securityHeaders: SecurityHeadersConfig };
247
+ };
248
+
249
+ expect(config.pwa.generateSW.runtimeCaching ?? []).toEqual([]);
250
+ expect(config.runtimeConfig.securityHeaders.htmlCacheControl).toBe(
251
+ "private, no-store",
252
+ );
253
+ });
254
+ });