@revenexx/cover 0.21.2 → 0.22.1

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 (98) hide show
  1. package/app/api/categories.ts +1 -0
  2. package/app/api/offers.ts +1 -0
  3. package/app/app.config.ts +18 -0
  4. package/app/components/OgImage/CoverPage.takumi.vue +37 -0
  5. package/app/components/RevenexxForm.vue +21 -6
  6. package/app/components/account/approvals/AccountPendingApprovals.vue +19 -1
  7. package/app/components/account/approvals/AccountPendingOrderDetail.vue +3 -0
  8. package/app/components/account/carts/AccountCartsTable.vue +11 -1
  9. package/app/components/account/orderlists/AccountOrderListDetail.vue +32 -3
  10. package/app/components/account/organization/AccountOrganization.vue +1 -1
  11. package/app/components/auth/AuthForgotPasswordPanel.vue +7 -2
  12. package/app/components/auth/AuthLoginPanel.vue +23 -8
  13. package/app/components/auth/AuthRegisterTeaser.vue +1 -1
  14. package/app/components/cart/position/CartPosition.vue +11 -4
  15. package/app/components/cart/quickadd/CartQuickAdd.vue +4 -2
  16. package/app/components/cart/recommend/CartRecommendCard.vue +1 -0
  17. package/app/components/cart/switcher/CartSwitcher.vue +1 -0
  18. package/app/components/cart/view/CartListHeader.vue +5 -0
  19. package/app/components/cart/view/CartSummaryPanel.vue +7 -2
  20. package/app/components/cart/view/CartView.vue +4 -2
  21. package/app/components/checkout/onepage/CheckoutDeliverySection.vue +3 -0
  22. package/app/components/checkout/onepage/CheckoutGate.vue +4 -2
  23. package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +2 -1
  24. package/app/components/checkout/onepage/CheckoutPaymentSection.vue +1 -1
  25. package/app/components/layout/header/LocaleSwitcher.vue +7 -9
  26. package/app/components/product/detail/ProductDetailAddToCart.vue +17 -11
  27. package/app/components/product/detail/ProductDetailImageGallery.vue +101 -8
  28. package/app/components/product/detail/ProductDetailVariantRow.vue +84 -4
  29. package/app/components/product/detail/ProductDetailVariants.vue +75 -11
  30. package/app/components/product/detail/ProductDetailView.vue +64 -69
  31. package/app/components/ui/forms/FormKitDatePicker.vue +8 -2
  32. package/app/composables/useAuthStore.ts +21 -4
  33. package/app/composables/useCategories.ts +24 -0
  34. package/app/composables/useCategoryAnswer.ts +30 -0
  35. package/app/composables/useCategorySeo.ts +62 -0
  36. package/app/composables/useCheckoutOnePage.ts +15 -4
  37. package/app/composables/useDefaultUiLanguage.ts +14 -0
  38. package/app/composables/useOgImageReady.ts +16 -0
  39. package/app/composables/useProductAnswer.ts +121 -0
  40. package/app/composables/useProductLocales.ts +21 -10
  41. package/app/composables/useProductSeo.ts +145 -0
  42. package/app/composables/useRouteSubject.ts +23 -3
  43. package/app/composables/useSeoContext.ts +164 -0
  44. package/app/composables/useSeoHead.ts +189 -0
  45. package/app/composables/useSeoRules.ts +23 -0
  46. package/app/formkit.config.ts +1 -1
  47. package/app/interfaces/seo.ts +48 -0
  48. package/app/layouts/default.vue +2 -8
  49. package/app/layouts/focus.vue +3 -1
  50. package/app/payments/psp/novalnet.ts +25 -3
  51. package/app/payments/psp/novalnetStyle.ts +186 -0
  52. package/app/shared/categoryTree.ts +7 -0
  53. package/app/shared/locale.ts +8 -0
  54. package/app/shared/productLocales.ts +62 -1
  55. package/app/shared/requestedDate.ts +49 -0
  56. package/app/shared/seoRules.ts +297 -0
  57. package/app/shared/structuredData.ts +104 -0
  58. package/i18n/locales/de/account.json +4 -0
  59. package/i18n/locales/de/checkout.json +1 -0
  60. package/i18n/locales/de/common.json +6 -0
  61. package/i18n/locales/de/pages.json +109 -0
  62. package/i18n/locales/en/account.json +4 -0
  63. package/i18n/locales/en/checkout.json +1 -0
  64. package/i18n/locales/en/common.json +6 -0
  65. package/i18n/locales/en/pages.json +109 -0
  66. package/nuxt.config.ts +140 -1
  67. package/package.json +10 -3
  68. package/server/api/auth/otp.post.ts +4 -8
  69. package/server/api/auth/otp.put.ts +20 -11
  70. package/server/api/categories/[slug]/exists.get.ts +28 -0
  71. package/server/api/offers/guest.get.ts +53 -0
  72. package/server/api/orders/index.post.ts +18 -12
  73. package/server/api/payment/methods.post.ts +2 -33
  74. package/server/api/product/[id]/locales.get.ts +9 -3
  75. package/server/data/product-detail.json +0 -20
  76. package/server/dev/errorHandler.ts +9 -5
  77. package/server/dev/typesense/autoSeed.ts +63 -0
  78. package/server/dev/typesense/seed.ts +4 -43
  79. package/server/dev/typesense/seedProducts.ts +87 -0
  80. package/server/interfaces/category.ts +5 -0
  81. package/server/interfaces/product.ts +13 -6
  82. package/server/middleware/missing-media.ts +2 -2
  83. package/server/plugins/previewHostNoindex.ts +21 -0
  84. package/server/plugins/seoSiteConfig.ts +62 -0
  85. package/server/routes/robots.txt.ts +21 -0
  86. package/server/services/ApiCategoryService.ts +6 -0
  87. package/server/services/ApiProductService.ts +2 -2
  88. package/server/services/LocalFileCategoryService.ts +6 -0
  89. package/server/utils/liveCatalog.ts +83 -18
  90. package/server/utils/livePrices.ts +12 -3
  91. package/server/utils/locale.ts +3 -8
  92. package/server/utils/offerService.ts +8 -3
  93. package/server/utils/paymentOptions.ts +49 -0
  94. package/server/utils/promotionsService.ts +25 -0
  95. package/server/utils/revenexxSdk.ts +7 -1
  96. package/server/utils/seoRequestHost.ts +21 -0
  97. package/server/utils/storefrontMessages.ts +5 -5
  98. package/server/utils/storefrontSeoRules.ts +298 -0
@@ -12,9 +12,13 @@ import { getRequestHeader, send, setResponseHeader, setResponseStatus } from "h3
12
12
  * is also the point where the parser starts failing with `unreachable`).
13
13
  *
14
14
  * So no error is run through the source maps. Client errors are answered with
15
- * a bare status; server errors (5xx) keep their raw stack in the log and in the
16
- * JSON body, which is what Nitro's default handler would print minus the
17
- * source-mapped code frame.
15
+ * their status, message and `data`; server errors (5xx) also keep their raw
16
+ * stack in the log and in the JSON body, which is what Nitro's default handler
17
+ * would print minus the source-mapped code frame.
18
+ *
19
+ * `data` must survive: the client tells errors apart by it (`data.type` maps a
20
+ * failed sign-in to "wrong password", `data.message` explains a refused
21
+ * approval). Dropping it turned every such error into a generic one in dev.
18
22
  */
19
23
  const handler: NitroErrorHandler = async function devErrorHandler(error, event) {
20
24
  const statusCode = error.statusCode || 500;
@@ -30,7 +34,7 @@ const handler: NitroErrorHandler = async function devErrorHandler(error, event)
30
34
  event,
31
35
  wantsHtml
32
36
  ? `<!doctype html><title>${statusCode} ${statusMessage}</title><h1>${statusCode} ${statusMessage}</h1>`
33
- : JSON.stringify({ error: true, statusCode, statusMessage }),
37
+ : JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, data: error.data }),
34
38
  );
35
39
  }
36
40
 
@@ -40,7 +44,7 @@ const handler: NitroErrorHandler = async function devErrorHandler(error, event)
40
44
  event,
41
45
  wantsHtml
42
46
  ? `<!doctype html><title>${statusCode} ${statusMessage}</title><h1>${statusCode} ${statusMessage}</h1><pre>${(error.stack ?? error.message).replace(/</g, "&lt;")}</pre>`
43
- : JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, stack }, null, 2),
47
+ : JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, data: error.data, stack }, null, 2),
44
48
  );
45
49
  };
46
50
 
@@ -0,0 +1,63 @@
1
+ import { dropProductsCollection, productsDocumentCount, seedProductsCollection } from "./seedProducts";
2
+
3
+ /**
4
+ * Seeds the local Typesense index when the dev server starts and the
5
+ * `products` collection is missing — dev server only (registered in the
6
+ * layer's nuxt.config).
7
+ *
8
+ * Category pages and search read every product from that index, so a fresh
9
+ * or reset `typesense-data` volume left the demo shop without products until
10
+ * someone called GET /api/typesense/seed by hand. A collection that holds
11
+ * documents is never touched, so a re-seeded or inflated index survives
12
+ * restarts. An EMPTY one counts as missing: it is what a seed that failed
13
+ * halfway leaves behind (the import timed out, or the server stopped between
14
+ * creating the collection and filling it), and it would otherwise keep the
15
+ * shop empty across every later restart.
16
+ *
17
+ * Typesense may still be starting when Nuxt is up (both start together in
18
+ * docker-compose.dev.yml), so the check is retried for a while. Startup is
19
+ * never blocked or failed by it. Set NUXT_TYPESENSE_AUTO_SEED=false to turn
20
+ * it off, e.g. when the dev server points at a shared Typesense.
21
+ */
22
+ const MAX_ATTEMPTS = 10;
23
+ const RETRY_DELAY_MS = 3000;
24
+
25
+ async function seedWhenMissing(): Promise<void> {
26
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
27
+ try {
28
+ const count = await productsDocumentCount();
29
+ if (count !== null && count > 0) {
30
+ return;
31
+ }
32
+ if (count === 0) {
33
+ await dropProductsCollection();
34
+ }
35
+ const result = await seedProductsCollection(0);
36
+ if (result.indexed === 0) {
37
+ // Every document failed: the collection is empty again, which the
38
+ // next attempt drops and seeds anew.
39
+ throw new Error(`Typesense import indexed none of ${result.total} documents`);
40
+ }
41
+ getLogService().warn(`Typesense: products collection was ${count === 0 ? "empty" : "missing"}, seeded the demo catalogue`, {
42
+ indexed: result.indexed,
43
+ failed: result.failed,
44
+ });
45
+ return;
46
+ }
47
+ catch (err) {
48
+ if (attempt === MAX_ATTEMPTS) {
49
+ getLogService().warn("Typesense: auto-seed gave up, call GET /api/typesense/seed once Typesense is up", toErrorContext(err));
50
+ return;
51
+ }
52
+ await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS));
53
+ }
54
+ }
55
+ }
56
+
57
+ export default defineNitroPlugin(() => {
58
+ if (!import.meta.dev || useRuntimeConfig().typesenseAutoSeed === false) {
59
+ return;
60
+ }
61
+ // Fire and forget on purpose: seeding must not delay or fail startup.
62
+ void seedWhenMissing();
63
+ });
@@ -1,7 +1,4 @@
1
- import productsData from "../../data/product-list.json";
2
- import { PRODUCTS_COLLECTION, productsSchema } from "../../utils/productsSchema";
3
- import type { SeedEntry } from "./seedDocuments";
4
- import { buildSeedDocuments } from "./seedDocuments";
1
+ import { dropProductsCollection, seedProductsCollection } from "./seedProducts";
5
2
 
6
3
  /**
7
4
  * GET /api/typesense/seed — dev server only (registered in the layer's
@@ -12,48 +9,12 @@ export default defineEventHandler(async (event) => {
12
9
  const query = getQuery(event);
13
10
  const requestedCount = parseInt(String(query.count ?? "0"), 10);
14
11
 
15
- const ts = useTypesense();
16
-
17
12
  try {
18
- const collections = await ts.collections().retrieve();
19
- const exists = collections.some(c => c.name === PRODUCTS_COLLECTION);
20
- if (exists) {
21
- await ts.collections(PRODUCTS_COLLECTION).delete();
22
- }
23
-
24
- await ts.collections().create(productsSchema);
13
+ await dropProductsCollection();
14
+ return await seedProductsCollection(requestedCount);
25
15
  }
26
16
  catch (err) {
27
- getLogService().error("Typesense error: seed collection setup", toErrorContext(err));
17
+ getLogService().error("Typesense error: seed", toErrorContext(err));
28
18
  throw createError({ statusCode: 503, message: "Search service unavailable" });
29
19
  }
30
-
31
- const documents = buildSeedDocuments(productsData as SeedEntry[], requestedCount);
32
-
33
- let result: { success: boolean; error?: string; document?: unknown }[] = [];
34
-
35
- try {
36
- result = await ts.collections(PRODUCTS_COLLECTION).documents().import(
37
- documents,
38
- { action: "upsert" },
39
- );
40
- }
41
- catch (e: unknown) {
42
- if (e && typeof e === "object" && "importResults" in e) {
43
- result = (e as { importResults: typeof result }).importResults;
44
- }
45
- else {
46
- getLogService().error("Typesense error: seed import", toErrorContext(e));
47
- throw e;
48
- }
49
- }
50
-
51
- const failed = result.filter(r => !r.success);
52
-
53
- return {
54
- total: documents.length,
55
- indexed: documents.length - failed.length,
56
- failed: failed.length,
57
- errors: failed,
58
- };
59
20
  });
@@ -0,0 +1,87 @@
1
+ import productsData from "../../data/product-list.json";
2
+ import { PRODUCTS_COLLECTION, productsSchema } from "../../utils/productsSchema";
3
+ import type { SeedEntry } from "./seedDocuments";
4
+ import { buildSeedDocuments } from "./seedDocuments";
5
+
6
+ export interface SeedResult {
7
+ readonly total: number;
8
+ readonly indexed: number;
9
+ readonly failed: number;
10
+ readonly errors: readonly ImportResult[];
11
+ }
12
+
13
+ interface ImportResult {
14
+ success: boolean;
15
+ error?: string;
16
+ document?: unknown;
17
+ }
18
+
19
+ /** Whether the local index already has the `products` collection. */
20
+ export async function hasProductsCollection(): Promise<boolean> {
21
+ return (await productsDocumentCount()) !== null;
22
+ }
23
+
24
+ /**
25
+ * How many documents the local `products` collection holds, or null where it
26
+ * does not exist. An empty collection is what a seed that failed halfway
27
+ * leaves behind, so callers that only seed a missing index must treat 0 like
28
+ * null.
29
+ */
30
+ export async function productsDocumentCount(): Promise<number | null> {
31
+ const collections = await useTypesense().collections().retrieve();
32
+ const products = collections.find(c => c.name === PRODUCTS_COLLECTION);
33
+ return products ? products.num_documents : null;
34
+ }
35
+
36
+ /** Drops the local `products` collection; a missing one is not an error. */
37
+ export async function dropProductsCollection(): Promise<void> {
38
+ if (await hasProductsCollection()) {
39
+ await useTypesense().collections(PRODUCTS_COLLECTION).delete();
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Creates the `products` collection and imports the demo catalogue into it.
45
+ * The collection must not exist yet. Shared by the dev seed route (which drops
46
+ * it first) and the dev startup plugin (which only runs when it is missing).
47
+ *
48
+ * The collection is created before the import, so an import that fails outright
49
+ * (a timeout while Typesense is still starting) would leave it empty — and an
50
+ * empty collection looks like a seeded one to everything that only checks for
51
+ * its existence. It is dropped again before the error goes on.
52
+ */
53
+ export async function seedProductsCollection(requestedCount: number): Promise<SeedResult> {
54
+ const ts = useTypesense();
55
+ await ts.collections().create(productsSchema);
56
+
57
+ const documents = buildSeedDocuments(productsData as SeedEntry[], requestedCount);
58
+
59
+ let result: ImportResult[] = [];
60
+ try {
61
+ result = await ts.collections(PRODUCTS_COLLECTION).documents().import(
62
+ documents,
63
+ { action: "upsert" },
64
+ );
65
+ }
66
+ catch (e: unknown) {
67
+ // A partial failure throws, but still carries the per-document results.
68
+ if (e && typeof e === "object" && "importResults" in e) {
69
+ result = (e as { importResults: ImportResult[] }).importResults;
70
+ }
71
+ else {
72
+ await dropProductsCollection().catch(() => {
73
+ // Typesense is unreachable: the next seed treats the empty
74
+ // collection as missing anyway.
75
+ });
76
+ throw e;
77
+ }
78
+ }
79
+
80
+ const failed = result.filter(r => !r.success);
81
+ return {
82
+ total: documents.length,
83
+ indexed: documents.length - failed.length,
84
+ failed: failed.length,
85
+ errors: failed,
86
+ };
87
+ }
@@ -9,4 +9,9 @@ import type { Locale } from "../utils/locale";
9
9
  export interface ICategoryService {
10
10
  listCategories(locale?: Locale): Promise<ProductCategory[]>;
11
11
  getCategoryBySlug(slug: string, locale?: Locale): Promise<ProductCategory | null>;
12
+ /**
13
+ * Whether a category URL names a category the catalogue has, and the
14
+ * subcategory below it when one is named (PE-1236: else a 404).
15
+ */
16
+ hasCategory(slug: string, subcategory?: string): Promise<boolean>;
12
17
  }
@@ -4,6 +4,12 @@ import type { ProductDetail } from "../../app/interfaces/product-detail";
4
4
  import type { ProductVariants } from "../../app/interfaces/product-variants";
5
5
  import type { Locale } from "../utils/locale";
6
6
 
7
+ /** The languages a product has a page in, and its name in each (for the slug). */
8
+ export interface ProductLanguages {
9
+ readonly languages: string[];
10
+ readonly names: Readonly<Record<string, string>>;
11
+ }
12
+
7
13
  export interface ProductListFilter {
8
14
  category?: string;
9
15
  subcategory?: string;
@@ -38,11 +44,12 @@ export interface IProductService {
38
44
  */
39
45
  getProductAssociations(id: string, locale?: Locale): Promise<ProductAssociations | null>;
40
46
  /**
41
- * The storefront languages (of `languages`) this product has a page in. A
42
- * catalogue that hides untranslated products (`search_untranslated=hide`)
43
- * has none in a language the product is not translated into. Optional: a
44
- * service without it has the product in every language, which is what the
45
- * storefront assumes when it is missing.
47
+ * The storefront languages (of `languages`) this product has a page in,
48
+ * and its name in each. A catalogue that hides untranslated products
49
+ * (`search_untranslated=hide`) has none in a language the product is not
50
+ * translated into. Optional: a service without it has the product in every
51
+ * language under one name, which is what the storefront assumes when it is
52
+ * missing.
46
53
  */
47
- getProductLanguages?(id: string, languages: readonly string[]): Promise<string[]>;
54
+ getProductLanguages?(id: string, languages: readonly string[]): Promise<ProductLanguages>;
48
55
  }
@@ -3,9 +3,9 @@ import { getMethod } from "h3";
3
3
  /**
4
4
  * Paths that own their own 404 handling, or that Vite serves in dev.
5
5
  * `/_nuxt` and `/@` are the dev bundler's, `/api` and `/cdn` answer for
6
- * themselves, `/_ipx` is @nuxt/image.
6
+ * themselves, `/_ipx` is @nuxt/image, `/_og` is nuxt-og-image (PE-1048).
7
7
  */
8
- const OWN_NOT_FOUND = ["/api/", "/cdn/", "/_nuxt/", "/_ipx/", "/@", "/node_modules/"];
8
+ const OWN_NOT_FOUND = ["/api/", "/cdn/", "/_nuxt/", "/_ipx/", "/_og/", "/@", "/node_modules/"];
9
9
 
10
10
  const MEDIA_EXTENSION = /\.(?:png|jpe?g|gif|webp|avif|svg|ico)$/i;
11
11
 
@@ -0,0 +1,21 @@
1
+ import { setResponseHeader } from "h3";
2
+
3
+ import { isPreviewHost } from "../../app/shared/seoRules";
4
+ import { seoRequestHost } from "../utils/seoRequestHost";
5
+
6
+ /**
7
+ * Nothing a preview host answers may be indexed (PE-1237): pages, but also
8
+ * images, PDFs and API answers, which carry no meta robots. Set before any
9
+ * handler runs, so static files get it too; a page's own robots rule sets the
10
+ * same value again (the site is not indexable there, see seoSiteConfig.ts).
11
+ *
12
+ * The host is the request's `Host` (seoRequestHost), so a cache keyed by host
13
+ * keeps a preview's `noindex` apart from the production domain.
14
+ */
15
+ export default defineNitroPlugin((nitroApp) => {
16
+ nitroApp.hooks.hook("request", (event) => {
17
+ if (isPreviewHost(seoRequestHost(event))) {
18
+ setResponseHeader(event, "X-Robots-Tag", "noindex, nofollow");
19
+ }
20
+ });
21
+ });
@@ -0,0 +1,62 @@
1
+ import type { H3Event } from "h3";
2
+
3
+ import { isPreviewHost } from "../../app/shared/seoRules";
4
+ import { readStorefrontSeoRules } from "../utils/storefrontSeoRules";
5
+ import { seoRequestHost, seoRequestOrigin } from "../utils/seoRequestHost";
6
+
7
+ /**
8
+ * Nuxt SEO's site config per request, from the domain's seo rules (PE-1235).
9
+ *
10
+ * One build serves many tenants and domains (ADR-0062), so nothing about the
11
+ * site can be fixed at build time. nuxt-site-config keeps one config stack per
12
+ * request and calls `site-config:init` from Nitro's `request` hook — before any
13
+ * middleware or render reads it — and awaits it, so the rules can be read here.
14
+ * What this pushes wins over the build's config.
15
+ *
16
+ * The rules also go on `event.context.seoRules`, from where the app takes them
17
+ * into the payload (app/composables/useSeoRules.ts).
18
+ *
19
+ * The host is the request's `Host` (seoRequestHost), and the same host goes
20
+ * into the site's `url`, from which canonical, hreflang and `og:url` take
21
+ * their origin: nuxt-site-config would otherwise set it from
22
+ * `X-Forwarded-Host`, and a page would render the rules of one host under the
23
+ * URLs of another. Prerendering is the exception: there the host is the
24
+ * prerenderer's own (`localhost`), so the `url` stays the build's (`site.url` /
25
+ * `NUXT_PUBLIC_SITE_URL`), as nuxt-site-config does too.
26
+ *
27
+ * BFF calls and build assets render nothing and skip the read, so an expired
28
+ * bundle never holds them up. Everything else may render or read the site
29
+ * config: pages, robots, sitemaps, link previews and islands (`/__…`).
30
+ */
31
+ const SKIPPED_PREFIXES: readonly string[] = ["/api/", "/_nuxt/"];
32
+
33
+ interface SiteConfigInit {
34
+ event: unknown;
35
+ siteConfig: { push: (input: Record<string, unknown>) => void };
36
+ }
37
+
38
+ /** The `site-config:init` handler; `prerender` keeps the request's host out of `url`. */
39
+ export function siteConfigFromRules({ prerender }: { prerender: boolean }) {
40
+ return async ({ event: siteEvent, siteConfig }: SiteConfigInit): Promise<void> => {
41
+ // Typed as the context alone; it is the request's H3 event.
42
+ const event = siteEvent as H3Event;
43
+ if (SKIPPED_PREFIXES.some(prefix => event.path.startsWith(prefix))) {
44
+ return;
45
+ }
46
+ const host = seoRequestHost(event);
47
+ const rules = await readStorefrontSeoRules(event, host);
48
+ event.context.seoRules = rules;
49
+ siteConfig.push({
50
+ _context: "cover:seo-rules",
51
+ name: rules.site_name,
52
+ ...(prerender ? {} : { url: seoRequestOrigin(event) }),
53
+ // Only ever switches indexing off: whether a site is indexable at all
54
+ // stays with its environment (a dev server never is).
55
+ ...(isPreviewHost(host) ? { indexable: false } : {}),
56
+ });
57
+ };
58
+ }
59
+
60
+ export default defineNitroPlugin((nitroApp) => {
61
+ nitroApp.hooks.hook("site-config:init", siteConfigFromRules({ prerender: Boolean(import.meta.prerender) }));
62
+ });
@@ -0,0 +1,21 @@
1
+ import { createError, setResponseHeader } from "h3";
2
+
3
+ import { isPreviewHost } from "../../app/shared/seoRules";
4
+ import { seoRequestHost } from "../utils/seoRequestHost";
5
+
6
+ /**
7
+ * robots.txt of a preview host only (PE-1237): `<tenant>.theme.rvnxx.site`
8
+ * shows drafts and unreleased themes, so it shuts every crawler out.
9
+ *
10
+ * Every other host's robots.txt is the seo service's, which the edge serves
11
+ * (ADR-0116); this answers 404 there, as the shop did before — a theme that
12
+ * ships its own `public/robots.txt` is served before any route.
13
+ */
14
+ export default defineEventHandler((event) => {
15
+ if (!isPreviewHost(seoRequestHost(event))) {
16
+ throw createError({ statusCode: 404, statusMessage: "Not Found" });
17
+ }
18
+ setResponseHeader(event, "Content-Type", "text/plain; charset=utf-8");
19
+ setResponseHeader(event, "Cache-Control", "public, max-age=3600");
20
+ return "User-agent: *\nDisallow: /\n";
21
+ });
@@ -1,5 +1,6 @@
1
1
  import type { ProductCategory } from "../../app/config/navigation";
2
2
  import type { ICategoryService } from "../interfaces/category";
3
+ import { liveCategoryExists } from "../utils/liveCatalog";
3
4
  import type { Locale } from "../utils/locale";
4
5
 
5
6
  /**
@@ -22,4 +23,9 @@ export class ApiCategoryService implements ICategoryService {
22
23
  const parent = categories.find(c => c.subcategories.some(s => s.slug === slug));
23
24
  return parent ?? null;
24
25
  }
26
+
27
+ /** Any code of the catalogue, at any depth; a subcategory anywhere below the category. */
28
+ async hasCategory(slug: string, subcategory?: string): Promise<boolean> {
29
+ return liveCategoryExists(slug, subcategory);
30
+ }
25
31
  }
@@ -4,7 +4,7 @@ import type { ProductDetail } from "../../app/interfaces/product-detail";
4
4
  import type { ProductVariants } from "../../app/interfaces/product-variants";
5
5
  import type { Locale } from "../utils/locale";
6
6
 
7
- import type { IProductService, ProductListFilter } from "../interfaces/product";
7
+ import type { IProductService, ProductLanguages, ProductListFilter } from "../interfaces/product";
8
8
 
9
9
  /** Listing cap for the stub — the live index holds tens of thousands of products. */
10
10
  const LIST_PAGE_SIZE = 48;
@@ -74,7 +74,7 @@ export class ApiProductService implements IProductService {
74
74
  }
75
75
  }
76
76
 
77
- async getProductLanguages(id: string, languages: readonly string[]): Promise<string[]> {
77
+ async getProductLanguages(id: string, languages: readonly string[]): Promise<ProductLanguages> {
78
78
  return getLiveProductLanguages(id, languages);
79
79
  }
80
80
 
@@ -1,4 +1,5 @@
1
1
  import type { ProductCategory } from "../../app/config/navigation";
2
+ import { treeHasCategory } from "../../app/shared/categoryTree";
2
3
  import type { ICategoryService } from "../interfaces/category";
3
4
 
4
5
  /**
@@ -20,4 +21,9 @@ export class LocalFileCategoryService implements ICategoryService {
20
21
  const categories = await this.listCategories();
21
22
  return categories.find(c => c.slug === slug) ?? null;
22
23
  }
24
+
25
+ /** The demo data is the two-level tree itself: a category, and a subcategory directly under it. */
26
+ async hasCategory(slug: string, subcategory?: string): Promise<boolean> {
27
+ return treeHasCategory(await this.listCategories(), slug, subcategory);
28
+ }
23
29
  }
@@ -14,7 +14,8 @@ import type {
14
14
  ProductVariants,
15
15
  } from "../../app/interfaces/product-variants";
16
16
  import { pickLocalizedLabel, searchLocaleKeys } from "../../app/shared/locale";
17
- import { languagesWithDocuments } from "../../app/shared/productLocales";
17
+ import { languagesWithDocuments, namesByLanguage } from "../../app/shared/productLocales";
18
+ import type { ProductLanguages } from "../interfaces/product";
18
19
  import type { Locale } from "./locale";
19
20
 
20
21
  /**
@@ -705,7 +706,7 @@ const PRODUCT_LANGUAGES_MAX_ENTRIES = 5000;
705
706
  // Partitioned by tenant like the category cache. Translations change rarely
706
707
  // and every product page asks (switcher and hreflang), so a short TTL keeps
707
708
  // it to one search per product and tenant every few minutes.
708
- const productLanguagesCache = new Map<string, { languages: string[]; loadedAt: number }>();
709
+ const productLanguagesCache = new Map<string, { value: ProductLanguages; loadedAt: number }>();
709
710
 
710
711
  /** Clears the per-product language cache — tests only. */
711
712
  export function resetProductLanguagesCache(): void {
@@ -713,22 +714,23 @@ export function resetProductLanguagesCache(): void {
713
714
  }
714
715
 
715
716
  /**
716
- * The storefront languages (of `languages`) this product has a page in.
717
+ * The storefront languages (of `languages`) this product has a page in, and
718
+ * its name in each (a link into another language needs that language's slug).
717
719
  *
718
720
  * ONE request across every language: a lookup by document id over all their
719
721
  * keys. It goes through multi_search, which does not pin a locale (the query
720
722
  * endpoint does, via X-Revenexx-Locale, and so could only answer for one
721
- * language per request). Only `id` and `locale` come back.
723
+ * language per request). Only `id`, `locale` and `name` come back.
722
724
  */
723
- export async function getLiveProductLanguages(entityId: string, languages: readonly string[]): Promise<string[]> {
725
+ export async function getLiveProductLanguages(entityId: string, languages: readonly string[]): Promise<ProductLanguages> {
724
726
  if (!entityId || !languages.length) {
725
- return [];
727
+ return { languages: [], names: {} };
726
728
  }
727
729
 
728
730
  const cacheKey = `${revenexxTenantKey()}|${entityId}|${languages.join(",")}`;
729
731
  const cached = productLanguagesCache.get(cacheKey);
730
732
  if (cached && Date.now() - cached.loadedAt < PRODUCT_LANGUAGES_TTL_MS) {
731
- return cached.languages;
733
+ return cached.value;
732
734
  }
733
735
 
734
736
  const keyCount = new Set(languages.flatMap(language => searchLocaleKeys(language))).size;
@@ -736,12 +738,15 @@ export async function getLiveProductLanguages(entityId: string, languages: reado
736
738
  q: "*",
737
739
  queryBy: "name",
738
740
  filterBy: liveDocIdClauseForLocales(entityId, languages),
739
- includeFields: "id,locale",
741
+ includeFields: "id,locale,name",
740
742
  perPage: keyCount,
741
743
  });
742
- const docLocales = (result.hits ?? []).map(({ document }) =>
743
- document.locale || document.id.slice(document.id.lastIndexOf(":") + 1));
744
- const available = languagesWithDocuments(docLocales, languages);
744
+ const docs = (result.hits ?? []).map(({ document }) => ({
745
+ locale: document.locale || document.id.slice(document.id.lastIndexOf(":") + 1),
746
+ name: typeof document.name === "string" ? document.name : undefined,
747
+ }));
748
+ const available = languagesWithDocuments(docs.map(doc => doc.locale), languages);
749
+ const value: ProductLanguages = { languages: available, names: namesByLanguage(docs, available) };
745
750
 
746
751
  if (productLanguagesCache.size >= PRODUCT_LANGUAGES_MAX_ENTRIES) {
747
752
  // Oldest first (insertion order) — a bound, not an LRU.
@@ -750,8 +755,8 @@ export async function getLiveProductLanguages(entityId: string, languages: reado
750
755
  productLanguagesCache.delete(oldest);
751
756
  }
752
757
  }
753
- productLanguagesCache.set(cacheKey, { languages: available, loadedAt: Date.now() });
754
- return available;
758
+ productLanguagesCache.set(cacheKey, { value, loadedAt: Date.now() });
759
+ return value;
755
760
  }
756
761
 
757
762
  // ---------------------------------------------------------------------------
@@ -800,38 +805,52 @@ interface LiveCategoryPage {
800
805
 
801
806
  const CATEGORY_CACHE_TTL_MS = 5 * 60 * 1000;
802
807
  const CATEGORY_PAGE_LIMIT = 200;
808
+ const CATEGORY_MAX_PAGES = 25;
809
+
810
+ export interface LiveCategoryRows {
811
+ rows: LiveCategoryRow[];
812
+ /** Reading stopped after CATEGORY_MAX_PAGES with more to come: `rows` lacks codes. */
813
+ truncated: boolean;
814
+ }
803
815
 
804
816
  // Partitioned by tenant — a multi-tenant theme must never serve one
805
817
  // tenant's category tree to another (see revenexxTenantKey()).
806
- const categoryCache = new Map<string, { rows: LiveCategoryRow[]; loadedAt: number }>();
818
+ const categoryCache = new Map<string, LiveCategoryRows & { loadedAt: number }>();
807
819
 
808
820
  async function loadLiveCategoryRows(): Promise<LiveCategoryRow[]> {
821
+ return (await loadLiveCategoryCatalogue()).rows;
822
+ }
823
+
824
+ async function loadLiveCategoryCatalogue(): Promise<LiveCategoryRows> {
809
825
  const tenantKey = revenexxTenantKey();
810
826
  const cached = categoryCache.get(tenantKey);
811
827
  if (cached && Date.now() - cached.loadedAt < CATEGORY_CACHE_TTL_MS) {
812
- return cached.rows;
828
+ return cached;
813
829
  }
814
830
 
815
831
  const sdk = useRevenexxSdk();
816
832
  const rows: LiveCategoryRow[] = [];
817
833
  let offset = 0;
834
+ let truncated = false;
818
835
  // Paginate defensively — the demo tenant has a few hundred categories.
819
836
  // Typed list (products.categories.list declares limit/offset/order —
820
837
  // @revenexx/sdk >= 0.0.11).
821
- for (let pageIndex = 0; pageIndex < 25; pageIndex++) {
838
+ for (let pageIndex = 0; pageIndex < CATEGORY_MAX_PAGES; pageIndex++) {
822
839
  const page = await sdk.productsCategories.productsCategoriesList({
823
840
  limit: CATEGORY_PAGE_LIMIT,
824
841
  offset,
825
842
  }) as unknown as LiveCategoryPage;
826
843
  rows.push(...page.items);
844
+ truncated = page.page.hasMore;
827
845
  if (!page.page.hasMore) {
828
846
  break;
829
847
  }
830
848
  offset += page.page.returned;
831
849
  }
832
850
 
833
- categoryCache.set(tenantKey, { rows, loadedAt: Date.now() });
834
- return rows;
851
+ const catalogue = { rows, truncated, loadedAt: Date.now() };
852
+ categoryCache.set(tenantKey, catalogue);
853
+ return catalogue;
835
854
  }
836
855
 
837
856
  function categoryLabel(row: LiveCategoryRow, locale: Locale): string {
@@ -902,6 +921,52 @@ export async function liveCategorySubtreeCodes(codes: string[]): Promise<string[
902
921
  return subtreeCodes(await loadLiveCategoryRows(), codes);
903
922
  }
904
923
 
924
+ /**
925
+ * Whether the live catalogue has a category URL's codes (PE-1236): the
926
+ * category, and the subcategory somewhere below it when one is named.
927
+ *
928
+ * Read from the RAW rows, not getLiveCategories(): products hang at their
929
+ * LEAF category, and `/category/<leaf>` (the product breadcrumb, the
930
+ * language switch's fallback) names a code the two-level tree keeps only as a
931
+ * subcategory, or not at all on a deeper catalogue.
932
+ *
933
+ * A catalogue read only in part answers a code it did not find with `true`:
934
+ * the code may sit beyond the pages read, and a 404 would take a real
935
+ * category page down. The page then shows what the listing finds.
936
+ */
937
+ export async function liveCategoryExists(category: string, subcategory?: string): Promise<boolean> {
938
+ const catalogue = await loadLiveCategoryCatalogue();
939
+ const answer = liveCategoryAnswer(catalogue, category, subcategory);
940
+ if (answer === "assumed") {
941
+ getLogService().warn("Live categories read only in part; an unknown category URL counts as existing", {
942
+ category,
943
+ subcategory,
944
+ rows: catalogue.rows.length,
945
+ });
946
+ }
947
+ return answer !== "missing";
948
+ }
949
+
950
+ /** Pure core of liveCategoryExists(), exported for tests: `assumed` is not found in a catalogue read only in part. */
951
+ export function liveCategoryAnswer(
952
+ catalogue: LiveCategoryRows,
953
+ category: string,
954
+ subcategory?: string,
955
+ ): "found" | "assumed" | "missing" {
956
+ if (hasLiveCategory(catalogue.rows, category, subcategory)) {
957
+ return "found";
958
+ }
959
+ return catalogue.truncated ? "assumed" : "missing";
960
+ }
961
+
962
+ /** Pure core of liveCategoryExists(), exported for tests. */
963
+ export function hasLiveCategory(rows: LiveCategoryRow[], category: string, subcategory?: string): boolean {
964
+ if (!rows.some(row => row.code === category)) {
965
+ return false;
966
+ }
967
+ return !subcategory || (subcategory !== category && subtreeCodes(rows, [category]).includes(subcategory));
968
+ }
969
+
905
970
  /** `parent_id` → its rows, the shape both tree walks below need. */
906
971
  function groupByParent(rows: LiveCategoryRow[]): Map<string | null, LiveCategoryRow[]> {
907
972
  const byParent = new Map<string | null, LiveCategoryRow[]>();