@revenexx/cover 0.22.0 → 0.23.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 (113) hide show
  1. package/app/api/categories.ts +1 -0
  2. package/app/api/offers.ts +1 -0
  3. package/app/app.config.ts +13 -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 +20 -8
  20. package/app/components/cart/view/CartView.vue +4 -2
  21. package/app/components/checkout/onepage/CheckoutGate.vue +4 -2
  22. package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +2 -1
  23. package/app/components/checkout/onepage/CheckoutPaymentSection.vue +1 -1
  24. package/app/components/checkout/onepage/CheckoutSummarySection.vue +8 -0
  25. package/app/components/checkout/return/CheckoutPaymentReturn.vue +7 -0
  26. package/app/components/layout/footer/Footer.vue +21 -4
  27. package/app/components/layout/header/AppBar.vue +5 -2
  28. package/app/components/layout/header/LocaleSwitcher.vue +7 -9
  29. package/app/components/layout/header/MobileMenu.vue +4 -1
  30. package/app/components/product/detail/ProductDetailAddToCart.vue +17 -11
  31. package/app/components/product/detail/ProductDetailImageGallery.vue +101 -8
  32. package/app/components/product/detail/ProductDetailVariantRow.vue +84 -4
  33. package/app/components/product/detail/ProductDetailVariants.vue +75 -11
  34. package/app/components/product/detail/ProductDetailView.vue +64 -69
  35. package/app/components/punchout/action/PunchoutTransferAction.vue +4 -3
  36. package/app/composables/useAuthStore.ts +21 -4
  37. package/app/composables/useCategories.ts +24 -0
  38. package/app/composables/useCategoryAnswer.ts +30 -0
  39. package/app/composables/useCategorySeo.ts +62 -0
  40. package/app/composables/useDefaultUiLanguage.ts +14 -0
  41. package/app/composables/useOgImageReady.ts +16 -0
  42. package/app/composables/useProductAnswer.ts +121 -0
  43. package/app/composables/useProductLocales.ts +21 -10
  44. package/app/composables/useProductSeo.ts +145 -0
  45. package/app/composables/usePunchoutVisit.ts +36 -1
  46. package/app/composables/useRouteSubject.ts +23 -3
  47. package/app/composables/useSeoContext.ts +164 -0
  48. package/app/composables/useSeoHead.ts +189 -0
  49. package/app/composables/useSeoRules.ts +23 -0
  50. package/app/interfaces/punchout.ts +11 -0
  51. package/app/interfaces/seo.ts +48 -0
  52. package/app/layouts/default.vue +2 -8
  53. package/app/layouts/focus.vue +3 -1
  54. package/app/middleware/punchout-exits.global.ts +25 -0
  55. package/app/payments/psp/novalnet.ts +25 -3
  56. package/app/payments/psp/novalnetStyle.ts +186 -0
  57. package/app/plugins/punchout-links.client.ts +46 -0
  58. package/app/shared/categoryTree.ts +7 -0
  59. package/app/shared/locale.ts +8 -0
  60. package/app/shared/productLocales.ts +62 -1
  61. package/app/shared/punchoutExits.ts +156 -0
  62. package/app/shared/seoRules.ts +297 -0
  63. package/app/shared/structuredData.ts +104 -0
  64. package/i18n/locales/de/account.json +4 -0
  65. package/i18n/locales/de/common.json +6 -0
  66. package/i18n/locales/de/pages.json +109 -0
  67. package/i18n/locales/de/punchout.json +3 -0
  68. package/i18n/locales/en/account.json +4 -0
  69. package/i18n/locales/en/common.json +6 -0
  70. package/i18n/locales/en/pages.json +109 -0
  71. package/i18n/locales/en/punchout.json +3 -0
  72. package/nuxt.config.ts +140 -1
  73. package/package.json +10 -3
  74. package/server/api/auth/otp.post.ts +4 -8
  75. package/server/api/auth/otp.put.ts +20 -11
  76. package/server/api/categories/[slug]/exists.get.ts +28 -0
  77. package/server/api/offers/guest.get.ts +53 -0
  78. package/server/api/orders/index.post.ts +18 -11
  79. package/server/api/payment/methods.post.ts +2 -33
  80. package/server/api/product/[id]/locales.get.ts +9 -3
  81. package/server/data/product-detail.json +0 -20
  82. package/server/dev/errorHandler.ts +9 -5
  83. package/server/dev/typesense/autoSeed.ts +63 -0
  84. package/server/dev/typesense/seed.ts +4 -43
  85. package/server/dev/typesense/seedProducts.ts +87 -0
  86. package/server/interfaces/category.ts +5 -0
  87. package/server/interfaces/product.ts +13 -6
  88. package/server/interfaces/punchout.ts +20 -1
  89. package/server/middleware/missing-media.ts +2 -2
  90. package/server/middleware/punchout-exits.ts +45 -0
  91. package/server/middleware/punchout-visit-csp.ts +35 -0
  92. package/server/plugins/previewHostNoindex.ts +21 -0
  93. package/server/plugins/punchout-cookies.ts +48 -0
  94. package/server/plugins/seoSiteConfig.ts +62 -0
  95. package/server/routes/punchout/start.get.ts +7 -0
  96. package/server/routes/robots.txt.ts +21 -0
  97. package/server/services/ApiCategoryService.ts +6 -0
  98. package/server/services/ApiProductService.ts +2 -2
  99. package/server/services/LocalFileCategoryService.ts +6 -0
  100. package/server/utils/liveCatalog.ts +83 -18
  101. package/server/utils/livePrices.ts +12 -3
  102. package/server/utils/locale.ts +3 -8
  103. package/server/utils/offerService.ts +8 -3
  104. package/server/utils/paymentOptions.ts +49 -0
  105. package/server/utils/promotionsService.ts +25 -0
  106. package/server/utils/punchoutFrame.ts +131 -0
  107. package/server/utils/punchoutOrder.ts +40 -0
  108. package/server/utils/punchoutVisit.ts +41 -8
  109. package/server/utils/revenexxSdk.ts +7 -1
  110. package/server/utils/seoRequestHost.ts +21 -0
  111. package/server/utils/storefrontMessages.ts +5 -5
  112. package/server/utils/storefrontSeoRules.ts +298 -0
  113. package/server/middleware/punchout-hand-back-csp.ts +0 -17
@@ -0,0 +1,48 @@
1
+ import { getCookie } from "h3";
2
+
3
+ import { PUNCHOUT_COOKIE_NAME } from "../utils/punchoutVisit";
4
+ import { isFramedNavigation, punchoutCookieModeOf, punchoutCookies } from "../utils/punchoutFrame";
5
+ import type { PunchoutCookieMode } from "../utils/punchoutFrame";
6
+
7
+ /**
8
+ * During a punchout visit every cookie the shop sets is `SameSite=None;
9
+ * Secure` — and `Partitioned` when the visit is framed — so the visit keeps its
10
+ * session inside the procurement system's iframe (RAD-226). See
11
+ * punchoutFrame.ts for why, and why only then.
12
+ *
13
+ * Applied where a cookie is written rather than in each setter, because a
14
+ * visit page sets cookies from a dozen places (the session, the cart, the
15
+ * market, the locale, modules the layer does not own), and the one a setter
16
+ * forgot is the one that signs the buyer out inside the frame.
17
+ *
18
+ * Which requests: those carrying the visit cookie, and `/punchout/start`,
19
+ * which sets it — there the request itself says whether it is framed.
20
+ * Skipped in development, where the shop is served over plain http and a
21
+ * `Secure` cookie would not be stored.
22
+ */
23
+ const START_PATH = /(?:^|\/)punchout\/start\/?(?:\?|$)/;
24
+
25
+ export default defineNitroPlugin((nitroApp) => {
26
+ if (import.meta.dev) {
27
+ return;
28
+ }
29
+ nitroApp.hooks.hook("request", (event) => {
30
+ const mode: PunchoutCookieMode | null = START_PATH.test(event.path)
31
+ ? { partitioned: isFramedNavigation(event) }
32
+ : punchoutCookieModeOf(getCookie(event, PUNCHOUT_COOKIE_NAME));
33
+ if (!mode) {
34
+ return;
35
+ }
36
+ event.context.punchoutCookieMode = mode;
37
+
38
+ const res = event.node.res;
39
+ const setHeader = res.setHeader.bind(res);
40
+ res.setHeader = ((name: string, value: number | string | readonly string[]) =>
41
+ setHeader(name, name.toLowerCase() === "set-cookie" ? punchoutCookies(value, mode) : value)) as typeof res.setHeader;
42
+ if (typeof res.appendHeader === "function") {
43
+ const appendHeader = res.appendHeader.bind(res);
44
+ res.appendHeader = ((name: string, value: string | readonly string[]) =>
45
+ appendHeader(name, name.toLowerCase() === "set-cookie" ? punchoutCookies(value, mode) as string | string[] : value)) as typeof res.appendHeader;
46
+ }
47
+ });
48
+ });
@@ -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
+ });
@@ -10,6 +10,7 @@ import {
10
10
 
11
11
  import type { StoredSession } from "../../../app/interfaces/auth";
12
12
  import type { PunchoutClaim, PunchoutVisit } from "../../interfaces/punchout";
13
+ import { purchaseModeOf } from "../../../app/shared/punchoutExits";
13
14
 
14
15
  /**
15
16
  * `/punchout/start?pSid=…` — where the entry redirect lands the buyer.
@@ -131,6 +132,12 @@ export default defineEventHandler(async (event) => {
131
132
  expiresAt: claim.expires_at,
132
133
  readOnly: claim.entry_intent?.read_only === true,
133
134
  handedBack: false,
135
+ // Punchout mode (RAD-226): the exits the shop offers, the parents that
136
+ // may frame it, and whether it was opened in a frame — which decides
137
+ // whether its cookies are partitioned.
138
+ purchaseMode: purchaseModeOf(claim.purchase_mode),
139
+ frameAncestors: frameAncestorsOf(claim.frame_ancestors),
140
+ framed: isFramedNavigation(event),
134
141
  };
135
142
  setPunchoutVisit(event, visit);
136
143
 
@@ -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[]>();
@@ -71,10 +71,15 @@ function toPriceMap(resolved: ResolvedPrice): { [key: string]: number }[] {
71
71
  /**
72
72
  * Batch-resolve live price tiers for the given items, keyed by product id.
73
73
  * Missing items map to `[]` (price on request). Drives the Offer provider.
74
+ *
75
+ * `guest` prices for nobody whoever is signed in: the public price a crawler
76
+ * sees, which the structured data publishes (PE-1103) and which must never be
77
+ * a buyer's contract price.
74
78
  */
75
79
  export async function resolveLivePriceMap(
76
80
  event: H3Event,
77
81
  items: OfferRequestItem[],
82
+ { guest = false }: { guest?: boolean } = {},
78
83
  ): Promise<Map<string, Offer["prices"]>> {
79
84
  const out = new Map<string, Offer["prices"]>();
80
85
  if (items.length === 0) {
@@ -85,7 +90,7 @@ export async function resolveLivePriceMap(
85
90
  // a price, which is the same "price on request" the UI already renders for an
86
91
  // article the merchant quotes individually. Asking anyway would turn a
87
92
  // deliberate policy into an error page.
88
- if (!pricesForBuyer(event)) {
93
+ if (guest || !pricesForBuyer(event)) {
89
94
  const { prices: priceTerms } = await getShopSettings(event);
90
95
  if (!priceTerms.anonymousAllowed) {
91
96
  for (const item of items) {
@@ -96,9 +101,13 @@ export async function resolveLivePriceMap(
96
101
  }
97
102
 
98
103
  const currency = resolveSelectedCurrency(event);
99
- const { prices } = await useRevenexxSdk().prices.pricesResolve({
104
+ // An empty principal sends no `X-Revenexx-Principal`, so the prices app
105
+ // prices for nobody even on a signed-in buyer's request; an empty channel
106
+ // keeps a punchout visit's channel price list out of the public price.
107
+ const sdk = guest ? useRevenexxSdk({ principal: "", channel: "" }) : useRevenexxSdk();
108
+ const { prices } = await sdk.prices.pricesResolve({
100
109
  items: items.map(i => ({ product_id: i.id, sku: i.sku, quantity: 1 })) as Models.PriceResolveItem[],
101
- ...priceBuyerContext(event),
110
+ ...(guest ? {} : priceBuyerContext(event)),
102
111
  ...(currency ? { currency } : {}),
103
112
  }) as unknown as { prices: ResolvedPrice[] };
104
113
 
@@ -1,14 +1,9 @@
1
1
  import { getCookie, getHeader, type H3Event } from "h3";
2
2
 
3
- import { pickMarketLocale } from "../../app/shared/locale";
3
+ import { CONTENT_LOCALE_COOKIE, pickMarketLocale } from "../../app/shared/locale";
4
4
 
5
- /**
6
- * Cookie the language choice persists the chosen MARKET locale in (`de-CH`,
7
- * `fr-FR`). The URL prefix only says which UI strings render; this says
8
- * which catalogue language the buyer asked for, which differs when the
9
- * market offers a language the storefront has no UI strings for (PE-866).
10
- */
11
- export const CONTENT_LOCALE_COOKIE_NAME = "cover-content-locale";
5
+ /** The content-locale cookie (app/shared/locale.ts), under the name the server uses. */
6
+ export const CONTENT_LOCALE_COOKIE_NAME = CONTENT_LOCALE_COOKIE;
12
7
 
13
8
  // Update when adding/removing locale subdirectories in i18n/locales/
14
9
  const SUPPORTED = new Set(["de", "en"] as const);
@@ -11,9 +11,14 @@ import { mockOfferService } from "../services/MockOfferService";
11
11
  *
12
12
  * This is the ONLY place price + availability are fetched. Catalog and search
13
13
  * never call it — they return the shell; the client hydrates offers via
14
- * POST /api/offers after first paint.
14
+ * POST /api/offers after first paint. `guest` prices for nobody (see
15
+ * resolveLivePriceMap); the demo prices are everyone's anyway.
15
16
  */
16
- export async function getOffers(event: H3Event, items: OfferRequestItem[]): Promise<Map<string, Offer>> {
17
+ export async function getOffers(
18
+ event: H3Event,
19
+ items: OfferRequestItem[],
20
+ { guest = false }: { guest?: boolean } = {},
21
+ ): Promise<Map<string, Offer>> {
17
22
  const seen = new Set<string>();
18
23
  const unique: OfferRequestItem[] = [];
19
24
  for (const item of items) {
@@ -31,7 +36,7 @@ export async function getOffers(event: H3Event, items: OfferRequestItem[]): Prom
31
36
  const stockLive = resolveInventoryServiceKey(event) === "api";
32
37
 
33
38
  const [livePrices, liveAvailability, mock] = await Promise.all([
34
- priceLive ? resolveLivePriceMap(event, unique) : null,
39
+ priceLive ? resolveLivePriceMap(event, unique, { guest }) : null,
35
40
  stockLive ? resolveLiveAvailabilityMap(unique) : null,
36
41
  priceLive && stockLive ? null : Promise.resolve(mockOfferService.resolve(unique)),
37
42
  ]);
@@ -0,0 +1,49 @@
1
+ import type { PaymentOption } from "../../app/interfaces/payment";
2
+ import type { Locale } from "./locale";
3
+ import { type ApiMethodCheckout, paymentCheckoutOf } from "./pspConfig";
4
+
5
+ /** Eligible method row of the payments app. */
6
+ export interface ApiEligibleMethod {
7
+ code: string;
8
+ name: string;
9
+ labels: Record<string, string> | null;
10
+ description: string | null;
11
+ /** The description per language (payments 5.1.0, RAD-383); null when only the plain one was written. */
12
+ descriptions?: Record<string, string> | null;
13
+ kind: string;
14
+ provider: string | null;
15
+ fee: number;
16
+ fee_type: "none" | "fixed" | "percent";
17
+ currency: string;
18
+ position: number;
19
+ /** How a PSP method takes the instrument (RAD-364); null for self-managed ones. */
20
+ checkout?: ApiMethodCheckout | null;
21
+ }
22
+
23
+ /** A per-language value for `locale`, if the merchant wrote a non-empty one. */
24
+ function inLocale(values: Record<string, string> | null | undefined, locale: Locale): string | undefined {
25
+ const value = values?.[locale];
26
+ return typeof value === "string" && value.trim() ? value : undefined;
27
+ }
28
+
29
+ /**
30
+ * One eligible method as the checkout renders it, in the shop's language: the
31
+ * label and the description of `locale`, else the merchant's plain ones.
32
+ */
33
+ export function paymentOptionOf(m: ApiEligibleMethod, locale: Locale): PaymentOption {
34
+ const checkout = paymentCheckoutOf(m.checkout);
35
+ // The checkout block names the provider the payment would actually go
36
+ // to (method → default → fallback provider); it wins over the row's.
37
+ const provider = checkout?.provider ?? m.provider;
38
+ const description = inLocale(m.descriptions, locale) ?? (m.description || undefined);
39
+ return {
40
+ method: m.code,
41
+ label: m.labels?.[locale] ?? m.name,
42
+ ...(description ? { description } : {}),
43
+ fee: m.fee,
44
+ feeType: m.fee_type,
45
+ kind: m.kind,
46
+ ...(provider ? { provider } : {}),
47
+ ...(checkout ? { checkout } : {}),
48
+ };
49
+ }
@@ -179,6 +179,31 @@ function heldPromotions(applied: PromotionEvaluation["applied"]) {
179
179
  }));
180
180
  }
181
181
 
182
+ /**
183
+ * The promotions as the order carries them, in the orders app's own shape.
184
+ *
185
+ * The same list goes to procurement when spending is approved first, and
186
+ * procurement records the promotions' use itself for the order an approval
187
+ * places (procurement 3.15.0). That record counts a voucher's uses by
188
+ * `voucher_id` — the code alone moves the promotion's budget and leaves the
189
+ * voucher's usage count where it was, so a single-use code stayed usable
190
+ * (RAD-424). The orders app keeps only the code and ignores the id.
191
+ */
192
+ export function orderDiscounts(applied: PromotionEvaluation["applied"]) {
193
+ return applied.map(a => ({
194
+ promotion_id: a.promotion_id,
195
+ promotion_name: a.promotion_name,
196
+ ...(a.voucher_id ? { voucher_id: a.voucher_id } : {}),
197
+ ...(a.voucher_code ? { voucher_code: a.voucher_code } : {}),
198
+ ...(a.value_type ? { value_type: a.value_type } : {}),
199
+ ...(a.percent != null ? { percent: a.percent } : {}),
200
+ ...(a.line_position != null
201
+ ? { placement: "line" as const, line_position: a.line_position }
202
+ : { placement: "head" as const }),
203
+ amount: a.amount,
204
+ }));
205
+ }
206
+
182
207
  export async function reserveRedemption(
183
208
  event: H3Event,
184
209
  input: {