@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,62 @@
1
+ import type { MaybeRefOrGetter } from "vue";
2
+
3
+ import { hasListingFilters } from "../shared/seoRules";
4
+ import type { ListingResponse } from "./useProductListing";
5
+
6
+ /**
7
+ * The category page's SEO from the domain's rules (PE-1235), for every page
8
+ * that lists a category: the blökkli theme's template page and the demo shop's.
9
+ *
10
+ * The clean category URL and its pages are indexable, each page its own
11
+ * canonical. Facet, price and in-category search permutations are
12
+ * near-duplicates of it: they stay out of the index and name the clean
13
+ * category URL as their canonical, whatever page they are on. An empty
14
+ * category or a page beyond its last is thin content and stays out of the
15
+ * index too; sort and tracking parameters are stripped from the canonical.
16
+ * Emptiness is read from the listing the page already fetched
17
+ * (useCategoryListing, key `category`).
18
+ */
19
+ export function useCategorySeo(category: {
20
+ readonly name: MaybeRefOrGetter<string | undefined>;
21
+ /** The parent category's name, on a subcategory. */
22
+ readonly parent?: MaybeRefOrGetter<string | undefined>;
23
+ /** A preview or anything else that must not be indexed. */
24
+ readonly noindex?: MaybeRefOrGetter<boolean>;
25
+ /** A preview, whose links must not be followed either. */
26
+ readonly nofollow?: MaybeRefOrGetter<boolean>;
27
+ }): void {
28
+ const route = useRoute();
29
+ const rules = useSeoRules();
30
+ const { data: listing } = useNuxtData<ListingResponse | null>("listing:category");
31
+
32
+ const filtered = computed(() => hasListingFilters(route.query, rules.value));
33
+ /** Nothing listed: an empty category, or a page beyond its last (`?page=9999`). */
34
+ const empty = computed(() => listing.value?.products.length === 0);
35
+
36
+ useSeoContext({
37
+ type: "category",
38
+ values: () => ({ name: toValue(category.name), parent: toValue(category.parent) }),
39
+ title: () => toValue(category.name),
40
+ noindex: () => Boolean(toValue(category.noindex)) || filtered.value || empty.value,
41
+ nofollow: category.nofollow,
42
+ canonicalPath: () => (filtered.value ? route.path : undefined),
43
+ });
44
+
45
+ // The trail in the structured data (PE-1103), from the category routes'
46
+ // own params: /category/<category>[/<subcategory>].
47
+ const { t } = useI18n();
48
+ const localePath = useLocalePath();
49
+ useSchemaOrg([
50
+ defineBreadcrumb(computed(() => {
51
+ const parent = toValue(category.parent);
52
+ const parentSlug = route.params.subcategory ? String(route.params.category) : undefined;
53
+ return {
54
+ itemListElement: [
55
+ { name: t("nav.home"), item: localePath("/") },
56
+ ...(parentSlug && parent ? [{ name: parent, item: localePath(`/category/${parentSlug}`) }] : []),
57
+ { name: toValue(category.name) ?? "", item: route.path },
58
+ ],
59
+ };
60
+ })),
61
+ ]);
62
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The shop's default UI language: the i18n default locale, else its first
3
+ * locale. The language the pages render in for a content locale without UI
4
+ * strings of its own (PE-866). One rule for the language switcher and the
5
+ * document head, so `<html lang>` and the switcher never disagree.
6
+ */
7
+ export function useDefaultUiLanguage() {
8
+ const { locales } = useI18n();
9
+ const runtimeConfig = useRuntimeConfig();
10
+ return computed(() => {
11
+ const i18nConfig = runtimeConfig.public as { i18n?: { defaultLocale?: string }; defaultLocale?: string };
12
+ return i18nConfig.i18n?.defaultLocale || i18nConfig.defaultLocale || locales.value[0]?.code || "de";
13
+ });
14
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Whether this Site can serve generated link preview images (PE-1237).
3
+ *
4
+ * nuxt-og-image signs its image URLs with a key derived from the app secret,
5
+ * and in production a missing or short secret (`NUXT_APP_SECRET`, at least 32
6
+ * characters) makes every image request a 500 — a broken preview in every
7
+ * share. Without one a page names no generated image at all. Decided on the
8
+ * server, where the secret is, and carried to the client in the payload so a
9
+ * client navigation decides the same way: useSeoHead() reads it on every
10
+ * server render (every layout calls it), so the state is in the payload even
11
+ * when the first page served generated no card.
12
+ */
13
+ export function useOgImageReady() {
14
+ return useState("cover:og-image-ready", () =>
15
+ import.meta.server && (import.meta.dev || String(useRuntimeConfig().appSecret ?? "").length >= 32));
16
+ }
@@ -0,0 +1,121 @@
1
+ import type { Ref } from "vue";
2
+
3
+ import { productApi } from "../api/product";
4
+ import type { ProductDetailProduct } from "../interfaces/product-detail";
5
+ import { productFallbackPath, productListingSegments } from "../shared/productLocales";
6
+ import type { Product } from "./useProducts";
7
+
8
+ /**
9
+ * The HTTP answer of a product URL (PE-1236), decided on the server once the
10
+ * product fetch has settled. A page awaits it in place of setting a 404:
11
+ *
12
+ * - **Outdated slug.** The page finds the product by the id in front of the
13
+ * slug, so an old name still reached it with a 200 and a duplicate of the
14
+ * page (the gap ADR-0031 left). It now answers 301 to the product's current
15
+ * path, query kept. A shallower category path or the `_` placeholder keep
16
+ * their 200 and the canonical: internal links are built that way, and each
17
+ * would otherwise cost a hop.
18
+ * - **No answer.** A product fetch that failed for any reason but a 404 (the
19
+ * catalogue down, a timeout) says nothing about the product: 503 with a
20
+ * Retry-After, so crawlers come back instead of dropping or moving a live URL.
21
+ * - **No product.** The catalogue cannot tell a deleted product from one that
22
+ * never existed, so the domain's seo rules decide (`removed_products`):
23
+ * `category` sends the buyer to the category the URL names with a 301,
24
+ * `gone` answers 410. A URL that names no category, or one the catalogue
25
+ * does not have, or no product at all, is a 404: otherwise any made-up
26
+ * product URL would be a 301 to whatever it names. So is one whose
27
+ * category could not be checked.
28
+ * - **Not in this language.** A catalogue that hides untranslated products
29
+ * (`search_untranslated=hide`) has no document for a product in a language
30
+ * it is not translated into, and the fetch says 404 there too. When the
31
+ * product has a page in another language it is a 404, which crawlers ask
32
+ * again, never a 301 or 410 that writes the URL off before the translation
33
+ * comes. A lookup that fails or a catalogue that cannot tell treats the
34
+ * product as missing everywhere, as before.
35
+ *
36
+ * @returns Whether the page answers with itself (`true`), or this answered
37
+ * for it: a 301, 404, 410 or 503.
38
+ */
39
+ export async function useProductAnswer(product: {
40
+ /** The `<id>-<name>` segment as requested. */
41
+ readonly slug: Readonly<Ref<string>>;
42
+ /** The category segments the URL names before `product`. */
43
+ readonly requestedCategory: Readonly<Ref<readonly string[]>>;
44
+ readonly productInfo: Readonly<Ref<ProductDetailProduct | undefined>>;
45
+ /** The product fetch's error, if it failed. */
46
+ readonly error: Readonly<Ref<{ readonly statusCode?: number } | null | undefined>>;
47
+ readonly categorySlug: Readonly<Ref<string | undefined>>;
48
+ readonly subcategorySlug: Readonly<Ref<string | undefined>>;
49
+ }): Promise<boolean> {
50
+ if (!import.meta.server) {
51
+ return true;
52
+ }
53
+ const nuxtApp = useNuxtApp();
54
+ const event = useRequestEvent();
55
+ if (!event) {
56
+ return true;
57
+ }
58
+ const route = useRoute();
59
+ const localePath = useLocalePath();
60
+ const rules = useSeoRules();
61
+ // Before the first await, while the setup context is still current.
62
+ const categoryExists = useCategoryExists();
63
+ const requestFetch = useRequestFetch();
64
+ const { locales } = useI18n();
65
+
66
+ /** Whether the product has a page in any storefront language (this one has none). */
67
+ async function translatedElsewhere(): Promise<boolean> {
68
+ const id = parseProductIdFromSlug(product.slug.value);
69
+ const answer = await requestFetch<{ locales: string[] | null }>(productApi.locales(id), {
70
+ query: { locales: locales.value.map(entry => entry.code).join(",") },
71
+ }).catch(() => null);
72
+ return Boolean(answer?.locales?.length);
73
+ }
74
+
75
+ const info = product.productInfo.value as Product | undefined;
76
+ if (info) {
77
+ if (product.slug.value && product.slug.value !== slugify(info)) {
78
+ const path = categoryProductPath([product.categorySlug.value, product.subcategorySlug.value], info);
79
+ await navigateTo({ path: localePath(path), query: route.query }, { redirectCode: 301 });
80
+ return false;
81
+ }
82
+ return true;
83
+ }
84
+
85
+ const failure = product.error.value;
86
+ if (failure && failure.statusCode !== 404) {
87
+ setResponseStatus(event, 503);
88
+ setResponseHeader(event, "Retry-After", 120);
89
+ return false;
90
+ }
91
+
92
+ if (!product.slug.value) {
93
+ setResponseStatus(event, 404);
94
+ return false;
95
+ }
96
+ // The category first, also where removed products are gone: a URL under
97
+ // a category the catalogue lacks never named a product (AC-4).
98
+ const [category, subcategory] = productListingSegments(product.requestedCategory.value);
99
+ if (!category) {
100
+ setResponseStatus(event, 404);
101
+ return false;
102
+ }
103
+ if (await categoryExists(category, subcategory) !== true) {
104
+ setResponseStatus(event, 404);
105
+ return false;
106
+ }
107
+ if (await translatedElsewhere()) {
108
+ setResponseStatus(event, 404);
109
+ return false;
110
+ }
111
+ if (rules.value.removed_products === "gone") {
112
+ setResponseStatus(event, 410);
113
+ return false;
114
+ }
115
+ // The await above left the Nuxt context, which navigateTo needs.
116
+ await nuxtApp.runWithContext(() => navigateTo(
117
+ { path: localePath(productFallbackPath(product.requestedCategory.value)), query: route.query },
118
+ { redirectCode: 301 },
119
+ ));
120
+ return false;
121
+ }
@@ -1,10 +1,13 @@
1
1
  import { productApi } from "../api/product";
2
- import { normalizeLocaleCode } from "../shared/locale";
3
- import { productFallbackPath, productRouteCategorySegments } from "../shared/productLocales";
4
- import { routeSegments, useRouteProductSubject } from "./useRouteSubject";
2
+ import { localeLanguage, normalizeLocaleCode } from "../shared/locale";
3
+ import { productFallbackPath, withProductSlug } from "../shared/productLocales";
4
+ import { slugify } from "./useProducts";
5
+ import type { Product } from "./useProducts";
6
+ import { useRouteProductSubject } from "./useRouteSubject";
5
7
 
6
8
  interface ProductLocalesResponse {
7
9
  locales: string[] | null;
10
+ names?: Record<string, string> | null;
8
11
  }
9
12
 
10
13
  /**
@@ -20,8 +23,7 @@ interface ProductLocalesResponse {
20
23
  * locale is linked then, exactly as before. Only a product page narrows.
21
24
  */
22
25
  export function useProductLocales() {
23
- const route = useRoute();
24
- const { id } = useRouteProductSubject();
26
+ const { id, slug, categorySegments } = useRouteProductSubject();
25
27
  const { locales } = useI18n();
26
28
  const requestFetch = useRequestFetch();
27
29
 
@@ -46,11 +48,20 @@ export function useProductLocales() {
46
48
  return available.value?.includes(normalizeLocaleCode(code)) ?? true;
47
49
  }
48
50
 
51
+ /**
52
+ * A path of this page in another locale with the product's slug in that
53
+ * locale (PE-1236): its name, and so its slug, may be translated, and a
54
+ * link with this locale's slug would land on the outdated-slug 301. Off a
55
+ * product page, or without a name for the locale, the path stays as given.
56
+ */
57
+ function localizePath(path: string, code: string): string {
58
+ const names = id.value ? data.value?.names : undefined;
59
+ const name = names?.[code] ?? names?.[normalizeLocaleCode(code)] ?? names?.[localeLanguage(code)];
60
+ return name ? withProductSlug(path, slug.value, slugify({ id: id.value, name } as Product)) : path;
61
+ }
62
+
49
63
  /** Where a locale without the product goes instead: its category listing, or home. */
50
- const fallbackPath = computed(() => productFallbackPath(productRouteCategorySegments(
51
- routeSegments(route.params.category),
52
- routeSegments(route.params.rest),
53
- )));
64
+ const fallbackPath = computed(() => productFallbackPath(categorySegments.value));
54
65
 
55
- return { available, hasPage, fallbackPath };
66
+ return { available, hasPage, fallbackPath, localizePath };
56
67
  }
@@ -0,0 +1,145 @@
1
+ import type { MaybeRefOrGetter } from "vue";
2
+
3
+ import { offersApi } from "../api/offers";
4
+ import type { GuestOfferInput } from "../shared/structuredData";
5
+ import { plainText, structuredOffer, structuredProperties } from "../shared/structuredData";
6
+ import type { useProductDetail } from "./useProduct";
7
+
8
+ /** What useProductSeo reads of a product page's useProductDetail(). */
9
+ type ProductSeoDetail = Pick<ReturnType<typeof useProductDetail>,
10
+ "productInfo" | "productCategories" | "categorySlug" | "subcategorySlug" | "longDescription"
11
+ | "mainImages" | "getDetailImageUrl" | "attributes" | "taxRate">;
12
+
13
+ /**
14
+ * The product page's SEO from the domain's rules (PE-1235), for every page
15
+ * that renders a product: the blökkli theme's template page, the layer's
16
+ * ProductDetailView and the demo shop's own copy.
17
+ *
18
+ * Three URL shapes reach the same product — the real category path, a
19
+ * shallower one and the `_` placeholder — so the canonical names the real one,
20
+ * on the main domain when the rules canonicalise products there. The first
21
+ * main picture is the link preview's image (PE-1237).
22
+ *
23
+ * Its structured data (PE-1103) is a `Product` with a `BreadcrumbList`. The
24
+ * price in it is the guest's (K4), asked for during the render: the offer the
25
+ * page shows is the buyer's, loaded only in the browser.
26
+ */
27
+ export function useProductSeo(product: ProductSeoDetail, flags: {
28
+ /**
29
+ * Nothing to describe: a malformed URL, a finished fetch that found
30
+ * nothing, or a URL useProductAnswer() answered for itself (a 301).
31
+ */
32
+ readonly notFound: MaybeRefOrGetter<boolean>;
33
+ /** A preview or anything else that must not be indexed. */
34
+ readonly noindex?: MaybeRefOrGetter<boolean>;
35
+ /** A preview, whose links must not be followed either. */
36
+ readonly nofollow?: MaybeRefOrGetter<boolean>;
37
+ }): void {
38
+ const localePath = useLocalePath();
39
+
40
+ const canonicalPath = computed(() => {
41
+ const info = product.productInfo.value;
42
+ return info
43
+ ? localePath(categoryProductPath(
44
+ [product.categorySlug.value, product.subcategorySlug.value],
45
+ { id: info.id, name: info.name },
46
+ ))
47
+ : undefined;
48
+ });
49
+
50
+ const mainCategory = computed(() => product.productCategories.value.find(c => c.type === "main")?.name);
51
+ const subcategory = computed(() => product.productCategories.value.find(c => c.type === "subcategory")?.name);
52
+ /** The product's own category, deepest first, for the title pattern's `{category}`. */
53
+ const category = computed(() => subcategory.value ?? mainCategory.value);
54
+
55
+ /** The first main picture as a src: the link preview's image and the structured data's. */
56
+ const image = computed(() => {
57
+ const first = product.mainImages.value[0];
58
+ return first ? product.getDetailImageUrl(first.url) : undefined;
59
+ });
60
+
61
+ /** The long description is stored as HTML; meta tags need plain text. */
62
+ const description = computed(() => {
63
+ const html = product.longDescription.value;
64
+ return html ? plainText(html) || undefined : undefined;
65
+ });
66
+
67
+ useSeoContext({
68
+ type: "product",
69
+ values: () => ({
70
+ name: product.productInfo.value?.name,
71
+ brand: product.productInfo.value?.manufacturer || undefined,
72
+ category: category.value,
73
+ description: description.value,
74
+ }),
75
+ title: () => product.productInfo.value?.name,
76
+ noindex: () => toValue(flags.notFound) || Boolean(toValue(flags.noindex)),
77
+ nofollow: flags.nofollow,
78
+ canonicalPath,
79
+ image: () => image.value,
80
+ });
81
+
82
+ if (toValue(flags.notFound)) {
83
+ return;
84
+ }
85
+
86
+ const { t } = useI18n();
87
+ const rules = useSeoRules();
88
+ const { taxIncludedPrices } = useShopSettings();
89
+ const currency = useDisplayCurrency();
90
+ const pricesAllowed = rules.value.structured_data.prices;
91
+
92
+ // The guest's offer, within the server's time budget (api/offers/guest).
93
+ // Not asked for at all under the domain's opt-out, and only while
94
+ // rendering on the server: crawlers read the server's HTML, and the
95
+ // browser has no use for the structured data, so an in-app navigation does
96
+ // not ask again. Keyed by product, so hydration reads the server's answer
97
+ // from the payload.
98
+ const info = product.productInfo.value;
99
+ const { data: guest } = useFetch<{ offer: GuestOfferInput | null }>(offersApi.guest(), {
100
+ key: `offer-guest:${info?.id ?? ""}`,
101
+ query: { id: info?.id, ...(info?.sku ? { sku: info.sku } : {}) },
102
+ immediate: import.meta.server && pricesAllowed && Boolean(info?.id),
103
+ default: () => ({ offer: null }),
104
+ });
105
+
106
+ const offers = computed(() => structuredOffer({
107
+ offer: guest.value?.offer,
108
+ pricesAllowed,
109
+ currency: currency.value,
110
+ taxRate: product.taxRate.value,
111
+ taxIncludedPrices: taxIncludedPrices.value,
112
+ }));
113
+
114
+ useSchemaOrg([
115
+ defineProduct(computed(() => {
116
+ const current = product.productInfo.value;
117
+ const brand = current?.manufacturer;
118
+ return {
119
+ name: current?.name ?? "",
120
+ sku: current?.sku || undefined,
121
+ brand: brand ? { "@type": "Brand" as const, "name": brand } : undefined,
122
+ description: description.value,
123
+ // The module drops empty strings, so a product without a picture has no `image`.
124
+ image: image.value ?? "",
125
+ additionalProperty: structuredProperties(product.attributes.value),
126
+ offers: offers.value,
127
+ };
128
+ })),
129
+ defineBreadcrumb(computed(() => {
130
+ const categoryPath = `/category/${product.categorySlug.value}`;
131
+ return {
132
+ itemListElement: [
133
+ { name: t("nav.home"), item: localePath("/") },
134
+ ...(mainCategory.value && product.categorySlug.value
135
+ ? [{ name: mainCategory.value, item: localePath(categoryPath) }]
136
+ : []),
137
+ ...(subcategory.value && product.categorySlug.value && product.subcategorySlug.value
138
+ ? [{ name: subcategory.value, item: localePath(`${categoryPath}/${product.subcategorySlug.value}`) }]
139
+ : []),
140
+ { name: product.productInfo.value?.name ?? "", item: canonicalPath.value },
141
+ ],
142
+ };
143
+ })),
144
+ ]);
145
+ }
@@ -1,4 +1,5 @@
1
1
  import type { PunchoutVisitView } from "../interfaces/punchout";
2
+ import { punchoutExits } from "../shared/punchoutExits";
2
3
 
3
4
  const EMPTY: PunchoutVisitView = {
4
5
  active: false,
@@ -9,6 +10,8 @@ const EMPTY: PunchoutVisitView = {
9
10
  cartId: null,
10
11
  expiresAt: null,
11
12
  handedBack: false,
13
+ purchaseMode: "transfer",
14
+ ordered: false,
12
15
  };
13
16
 
14
17
  /**
@@ -51,5 +54,37 @@ export function usePunchoutVisit() {
51
54
  `punchout.transfer.action.${visit.value.protocol ?? "oci"}`,
52
55
  );
53
56
 
54
- return { visit, isPunchout, isReadOnly, protocol, transferLabelKey, refresh };
57
+ /**
58
+ * Punchout mode (RAD-226): a live visit offers only its own exits, and
59
+ * the shop hides every other way out — the account area, signing in or
60
+ * out, registering, links that leave the shop. Over once the cart was
61
+ * handed back.
62
+ */
63
+ const isRestricted = computed(() => visit.value.active && !visit.value.handedBack);
64
+ const exits = computed(() => punchoutExits(visit.value));
65
+ /** The checkout places this visit's order — `order`, or `order_and_transfer`. */
66
+ const offersCheckout = computed(() => isRestricted.value && exits.value.checkout);
67
+ /**
68
+ * The cart is handed back — `transfer`, or after the order in
69
+ * `order_and_transfer`, whose hand-back the punchout app refuses without
70
+ * the order. Still true once handed back, so the hand-back page can
71
+ * replay it.
72
+ */
73
+ const offersHandBack = computed(() => isPunchout.value && exits.value.handBack
74
+ && (visit.value.purchaseMode !== "order_and_transfer" || visit.value.ordered || visit.value.handedBack));
75
+ /** The checkout is followed by the hand-back, as one step. */
76
+ const ordersThenHandsBack = computed(() => isPunchout.value && visit.value.purchaseMode === "order_and_transfer");
77
+
78
+ return {
79
+ visit,
80
+ isPunchout,
81
+ isReadOnly,
82
+ isRestricted,
83
+ offersCheckout,
84
+ offersHandBack,
85
+ ordersThenHandsBack,
86
+ protocol,
87
+ transferLabelKey,
88
+ refresh,
89
+ };
55
90
  }
@@ -1,3 +1,4 @@
1
+ import { productRouteCategorySegments } from "../shared/productLocales";
1
2
  import { parseProductIdFromSlug } from "./useProducts";
2
3
 
3
4
  /**
@@ -29,14 +30,33 @@ export function productSlugFromSegments(segments: string[]): string {
29
30
  return marker >= 0 ? (segments[marker + 1] ?? "") : "";
30
31
  }
31
32
 
32
- /** The product a `category/[category]/[...rest]` URL points at. */
33
+ /**
34
+ * The part of a product URL behind `category/[category]`, as `[...rest]` holds
35
+ * it. The demo shop serves two-level product URLs from its own
36
+ * `[category]/[subcategory]/product/[slug]` route, which spells the same tail
37
+ * in two params; off a category URL there is no tail.
38
+ */
39
+ export function productRouteTail(params: Record<string, unknown>): string[] {
40
+ const rest = routeSegments(params.rest);
41
+ const slug = routeSegments(params.slug);
42
+ if (rest.length || !slug.length || !routeSegments(params.category).length) {
43
+ return rest;
44
+ }
45
+ return [...routeSegments(params.subcategory), "product", ...slug];
46
+ }
47
+
48
+ /** The product a `category/[category]/[...rest]` URL (or the demo shop's own route) points at. */
33
49
  export function useRouteProductSubject() {
34
50
  const route = useRoute();
35
51
 
36
- const slug = computed(() => productSlugFromSegments(routeSegments(route.params.rest)));
52
+ const tail = computed(() => productRouteTail(route.params));
53
+ const slug = computed(() => productSlugFromSegments(tail.value));
37
54
  const id = computed(() => parseProductIdFromSlug(slug.value));
55
+ /** The category path the URL names in front of `product` (display only; the product knows its own). */
56
+ const categorySegments = computed(() =>
57
+ productRouteCategorySegments(routeSegments(route.params.category), tail.value));
38
58
 
39
- return { slug, id };
59
+ return { slug, id, categorySegments };
40
60
  }
41
61
 
42
62
  /** The category (and optional subcategory) a `category/[category]/[[subcategory]]` URL points at. */
@@ -0,0 +1,164 @@
1
+ import type { MaybeRefOrGetter } from "vue";
2
+
3
+ import type { SeoPatternValues } from "../shared/seoRules";
4
+ import { defaultSeoRules, fillSeoPattern, isIndexableRobotsRule, seoPatternTitle, seoRobotsRule } from "../shared/seoRules";
5
+ import type { SeoPageCanonical } from "./useSeoHead";
6
+ import { useSeoPageCanonical } from "./useSeoHead";
7
+
8
+ /**
9
+ * What a page tells the SEO layer about itself (PE-1235).
10
+ *
11
+ * `type` is a page type of the domain's rules: `home`, `product`, `category`,
12
+ * `page` (a CMS page) are indexed and carry title and description patterns;
13
+ * `search`, `cart`, `checkout`, `checkout-confirmation`, `login`, `register`,
14
+ * `forgot-password`, `reset-password`, `account` and `preview` are fixed.
15
+ */
16
+ export interface SeoContextOptions {
17
+ readonly type: MaybeRefOrGetter<string>;
18
+ /** What the type's patterns are filled from. */
19
+ readonly values?: MaybeRefOrGetter<SeoPatternValues>;
20
+ /**
21
+ * The page's own title, for a type without a pattern, a subject without a
22
+ * name, or a pattern with no place for one (the home page's `{site}`).
23
+ */
24
+ readonly title?: MaybeRefOrGetter<string | undefined>;
25
+ /** The page's own description, for a type without a description pattern (a home page). */
26
+ readonly description?: MaybeRefOrGetter<string | undefined>;
27
+ /** This URL must not be indexed although its type may be: a preview, a filter, nothing found. */
28
+ readonly noindex?: MaybeRefOrGetter<boolean>;
29
+ /** Nor may its links be followed: a preview. */
30
+ readonly nofollow?: MaybeRefOrGetter<boolean>;
31
+ /** The path that names the subject canonically, when the URL served can differ from it. */
32
+ readonly canonicalPath?: MaybeRefOrGetter<string | undefined>;
33
+ /** The subject's own picture for link previews (a product photo): a src, made absolute here. */
34
+ readonly image?: MaybeRefOrGetter<string | undefined>;
35
+ }
36
+
37
+ /**
38
+ * The label a generated link preview card carries per page type. The home
39
+ * page and CMS pages carry none ("Page" says nothing), so they share a card.
40
+ */
41
+ const OG_IMAGE_LABELS: Readonly<Record<string, string>> = {
42
+ home: "",
43
+ page: "",
44
+ product: "seo.ogImage.product",
45
+ category: "seo.ogImage.category",
46
+ };
47
+
48
+ /**
49
+ * Title, description, robots and canonical of a page, from the domain's rules.
50
+ *
51
+ * Reactive throughout, so a page may call it before its data has arrived: the
52
+ * head is resolved when the render ends, and the `X-Robots-Tag` header is set
53
+ * then too, from the same rule as the meta tag. On a host that is not
54
+ * indexable (a preview, a dev server) the robots module's site-wide
55
+ * `noindex` stands and nothing here overrides it.
56
+ *
57
+ * A type the rules lack falls back to the service's defaults for it. A type
58
+ * the rules never index (cart, checkout, login, …) gets no canonical from the
59
+ * rules, only the module's fallback (the path and `page`): its URLs carry
60
+ * secrets and order ids, and nothing is to be consolidated. The canonical is
61
+ * set by the layout's useSeoHead() from what this hands it, so a page has one
62
+ * canonical whatever its layout. When the page
63
+ * ends in an error (a 404 thrown after this was called), robots and canonical
64
+ * are left to the error page.
65
+ */
66
+ export function useSeoContext(options: SeoContextOptions): void {
67
+ const rules = useSeoRules();
68
+ const siteConfig = useSiteConfig();
69
+ const error = useError();
70
+ const pageCanonical = useSeoPageCanonical();
71
+
72
+ const type = computed(() => toValue(options.type));
73
+ const typeRules = computed(() => rules.value.page_types[type.value]
74
+ ?? defaultSeoRules(rules.value.host).page_types[type.value]);
75
+ const patternValues = computed(() => ({ ...toValue(options.values), site: rules.value.site_name }));
76
+
77
+ const ownTitle = computed(() => toValue(options.title));
78
+ const patternTitle = computed(() =>
79
+ seoPatternTitle(typeRules.value?.title, patternValues.value, rules.value.max_length.title, ownTitle.value));
80
+ const title = computed(() => patternTitle.value ?? ownTitle.value);
81
+
82
+ const description = computed(() => {
83
+ const pattern = typeRules.value?.description;
84
+ return (pattern ? fillSeoPattern(pattern, patternValues.value, rules.value.max_length.description) : toValue(options.description))
85
+ || undefined;
86
+ });
87
+
88
+ const siteIndexable = computed(() => siteConfig.indexable !== undefined
89
+ ? String(siteConfig.indexable) === "true"
90
+ : siteConfig.env === "production");
91
+ const typeRule = computed(() => typeRules.value?.robots ?? "index,follow");
92
+ const robots = computed(() => (siteIndexable.value && !error.value
93
+ ? seoRobotsRule(typeRule.value, {
94
+ noindex: Boolean(toValue(options.noindex)),
95
+ nofollow: Boolean(toValue(options.nofollow)),
96
+ })
97
+ : undefined));
98
+
99
+ const canonical: SeoPageCanonical = {
100
+ indexable: () => isIndexableRobotsRule(typeRule.value),
101
+ pageType: () => type.value,
102
+ path: () => toValue(options.canonicalPath),
103
+ };
104
+ pageCanonical.value = canonical;
105
+ // Leaving, a page takes back only its own: on a client navigation the next
106
+ // page may have set its own already, in either order.
107
+ if (getCurrentScope()) {
108
+ onScopeDispose(() => {
109
+ if (pageCanonical.value === canonical) {
110
+ pageCanonical.value = null;
111
+ }
112
+ });
113
+ }
114
+
115
+ // A pattern carries the site name itself (`{site}`), so nuxt-seo-utils'
116
+ // `%s %separator %siteName` must not add it a second time. A page's own
117
+ // title gets that template spelled out: a template that resolves to
118
+ // undefined renders no title at all.
119
+ useHead({
120
+ title: () => title.value,
121
+ titleTemplate: () => (patternTitle.value ? "%s" : "%s %separator %siteName"),
122
+ meta: () => (robots.value ? [{ name: "robots", content: robots.value }] : []),
123
+ });
124
+ useSeoMeta({
125
+ description: () => description.value,
126
+ ogTitle: () => title.value,
127
+ ogDescription: () => description.value,
128
+ });
129
+
130
+ // Link previews (PE-1237): the subject's own picture where it has one, else
131
+ // a card generated for the page type and the site. The module puts the page
132
+ // path into every image URL, but the card shows only its props, so they are
133
+ // its cache key too: one render per type and site, shared by all its pages
134
+ // (and by any other tenant whose card would read the same). Photo or card
135
+ // is decided at setup, when a page has its data (product pages await it
136
+ // first); the photo itself follows the data. Only an indexed page gets a
137
+ // card: a missing product, a noindex URL, a preview host or a dev server
138
+ // would only make `/_og/` render one nobody shares.
139
+ const requestUrl = useRequestURL();
140
+ const origin = computed(() => new URL(siteConfig.url || requestUrl.origin).origin);
141
+ const image = computed(() => toValue(options.image));
142
+ const label = OG_IMAGE_LABELS[type.value];
143
+ const indexed = Boolean(robots.value && isIndexableRobotsRule(robots.value));
144
+ if (image.value) {
145
+ useSeoMeta({
146
+ ogImage: () => (image.value ? new URL(image.value, origin.value).href : undefined),
147
+ twitterCard: "summary_large_image",
148
+ });
149
+ }
150
+ else if (label !== undefined && indexed && useOgImageReady().value) {
151
+ const { t } = useI18n();
152
+ const props = { site: rules.value.site_name, label: label ? t(label) : "" };
153
+ defineOgImage("CoverPage", props, { cacheKey: JSON.stringify(["CoverPage", props.site, props.label]) });
154
+ }
155
+
156
+ if (import.meta.server) {
157
+ const header = useResponseHeader("X-Robots-Tag");
158
+ useNuxtApp().hooks.hook("app:rendered", () => {
159
+ if (robots.value) {
160
+ header.value = robots.value;
161
+ }
162
+ });
163
+ }
164
+ }