@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
@@ -0,0 +1,189 @@
1
+ import type { Ref, ShallowRef } from "vue";
2
+
3
+ import { CONTENT_LOCALE_COOKIE, localeLanguage, pickMarketLocale } from "../shared/locale";
4
+ import { filterLocaleHeadAlternates, localizeLocaleHeadAlternates } from "../shared/productLocales";
5
+ import { applySeoRulesToLocaleHead, marketHreflangAlternates, seoCanonicalUrl } from "../shared/seoRules";
6
+
7
+ /** What a page's useSeoContext() tells the layout about its canonical. */
8
+ export interface SeoPageCanonical {
9
+ /** False for a type the rules never index: no canonical at all. */
10
+ readonly indexable: () => boolean;
11
+ /** The page type, for the rules' canonical on the main domain. */
12
+ readonly pageType: () => string;
13
+ /** The path that names the subject; undefined for the URL served. */
14
+ readonly path: () => string | undefined;
15
+ }
16
+
17
+ /**
18
+ * The canonical of the page being shown, as its useSeoContext() states it;
19
+ * null for a page that says nothing about itself. One per app (per request on
20
+ * the server); not shared state, as it holds getters a payload cannot carry.
21
+ */
22
+ export function useSeoPageCanonical(): ShallowRef<SeoPageCanonical | null> {
23
+ const host = useNuxtApp() as unknown as { _coverSeoPageCanonical?: ShallowRef<SeoPageCanonical | null> };
24
+ host._coverSeoPageCanonical ??= shallowRef(null);
25
+ return host._coverSeoPageCanonical;
26
+ }
27
+
28
+ /**
29
+ * The document head a layout renders: html `lang`/`dir`, absolute hreflang
30
+ * alternates and `og:locale`, under the domain's SEO rules (PE-1235). It is
31
+ * also the one place the canonical is set: from the page's useSeoContext()
32
+ * where it has one (its subject's path, its type's rules, none for a type
33
+ * never indexed), from the URL served and the rules otherwise.
34
+ *
35
+ * `lang` and `og:locale` name the market locale the page's catalogue is read
36
+ * in (PE-1237) — `de-CH` in a Swiss market, where the i18n language alone
37
+ * would say `de-DE` — picked as the BFF picks it for search; the regional
38
+ * hreflang alternates name each language's market locale the same way. A crawler sends
39
+ * no cookies, so it gets the default market's locale for the page language.
40
+ *
41
+ * `productLocales` narrows the alternates to the languages a product has a
42
+ * page in (PE-859); null leaves every language.
43
+ *
44
+ * `localizePath` puts each alternate into its language's product slug
45
+ * (useProductLocales), so hreflang never points at an outdated-slug 301.
46
+ *
47
+ * `canonical: false` leaves the URL's canonical out for pages that say nothing
48
+ * about themselves, for layouts whose pages are never indexed and whose URLs
49
+ * carry one-time secrets or order ids (login links, password resets, the
50
+ * checkout): nothing there is to be consolidated. The module's fallback (the
51
+ * path and `page` only) stands there.
52
+ */
53
+ export function useSeoHead(
54
+ productLocales?: Ref<readonly string[] | null>,
55
+ options: {
56
+ readonly canonical?: boolean;
57
+ readonly localizePath?: (path: string, code: string) => string;
58
+ } = {},
59
+ ) {
60
+ const localeHead = useLocaleHead({ seo: true });
61
+ const lang = useMarketLanguageTag();
62
+ const rules = useSeoRules();
63
+ const siteConfig = useSiteConfig();
64
+ const requestUrl = useRequestURL();
65
+ const route = useRoute();
66
+ const error = useError();
67
+ const page = useSeoPageCanonical();
68
+ const withCanonical = options.canonical !== false;
69
+ const i18nConfig = useRuntimeConfig().public as { i18n?: { defaultLocale?: string } };
70
+ const defaultLocale = i18nConfig.i18n?.defaultLocale ?? "";
71
+
72
+ const origin = computed(() => new URL(siteConfig.url || requestUrl.origin).origin);
73
+
74
+ // nuxt-seo-utils sets `lang` too, from the site config's i18n locale, in a
75
+ // `low` entry. Unhead merges html attributes in priority order and the
76
+ // later entry wins (unhead 3, dedupeTags: sorted by weight, then each
77
+ // next entry's props override), so the layout's <Html :lang> at normal
78
+ // priority loses to the module's. A `low` entry made after the module's
79
+ // (a layout's setup runs after its plugin) is the one that wins.
80
+ useHead({ htmlAttrs: { lang: () => lang.value ?? undefined } }, { tagPriority: "low" });
81
+
82
+ // Into the payload on every server render, for client navigations to a
83
+ // page that generates a link preview card (useSeoContext).
84
+ if (import.meta.server) {
85
+ useOgImageReady();
86
+ }
87
+
88
+ // The business behind the site (PE-1103), from the domain's rules; the
89
+ // module's own WebSite and WebPage name it as publisher. Without
90
+ // organisation data there is none rather than one named after a host.
91
+ const organisation = rules.value.organisation;
92
+ if (organisation) {
93
+ useSchemaOrg([defineOrganization({
94
+ // The module drops what is undefined, as for a product's sku or brand.
95
+ name: organisation.name,
96
+ logo: organisation.logo || undefined,
97
+ sameAs: organisation.same_as.length ? [...organisation.same_as] : undefined,
98
+ })]);
99
+ }
100
+
101
+ const canonical = computed(() => {
102
+ const source = page.value;
103
+ if (error.value || (source ? !source.indexable() : !withCanonical)) {
104
+ return undefined;
105
+ }
106
+ const path = source?.path();
107
+ return seoCanonicalUrl({
108
+ origin: origin.value,
109
+ path: path ?? route.path,
110
+ query: path ? {} : route.query,
111
+ rules: rules.value,
112
+ pageType: source?.pageType(),
113
+ });
114
+ });
115
+
116
+ useHead({
117
+ link: () => (canonical.value ? [{ rel: "canonical", href: canonical.value }] : []),
118
+ });
119
+
120
+ return computed(() => {
121
+ const head = localeHead.value;
122
+ const localized = options.localizePath
123
+ ? localizeLocaleHeadAlternates(head, options.localizePath, defaultLocale)
124
+ : head;
125
+ const narrowed = filterLocaleHeadAlternates(localized, productLocales?.value ?? null);
126
+ const ruled = applySeoRulesToLocaleHead(narrowed, { origin: origin.value, rules: rules.value });
127
+ const tag = lang.value;
128
+ return {
129
+ ...head,
130
+ ...ruled,
131
+ link: marketHreflangAlternates(ruled.link, lang.forLanguage),
132
+ meta: ruled.meta.map((entry) => {
133
+ if (entry.property === "og:locale" && tag) {
134
+ return { ...entry, content: ogLocale(tag) };
135
+ }
136
+ if (entry.property === "og:locale:alternate" && entry.content) {
137
+ return { ...entry, content: ogLocale(lang.forLanguage(entry.content) ?? entry.content) };
138
+ }
139
+ return entry;
140
+ }),
141
+ };
142
+ });
143
+ }
144
+
145
+ /** A locale code as Open Graph writes it: `de_CH`, `zh_Hant_TW`. */
146
+ function ogLocale(code: string): string {
147
+ return code.replace(/-/g, "_");
148
+ }
149
+
150
+ /**
151
+ * The market locale the page speaks, or null while the shop's markets carry
152
+ * none (the i18n language then stands, as before markets had locales).
153
+ *
154
+ * The buyer's content locale counts only where it speaks the language the
155
+ * page chrome is written in: a French catalogue choice (`fr-CH`) on German
156
+ * UI strings leaves `lang` German, so a screen reader reads the interface
157
+ * as what it is. `forLanguage` answers the same for another UI language,
158
+ * for the og:locale alternates.
159
+ */
160
+ function useMarketLanguageTag() {
161
+ const { locale, locales } = useI18n();
162
+ const defaultUiLanguage = useDefaultUiLanguage();
163
+ const { markets } = useMarkets();
164
+ const { market } = useLocalePreferences(markets);
165
+ const contentLocale = useCookie<string>(CONTENT_LOCALE_COOKIE, { default: () => "", watch: true });
166
+
167
+ function pick(uiLanguage: string, chosen: string): string | null {
168
+ const marketLocales = market.value?.locales;
169
+ if (!marketLocales?.length) {
170
+ return null;
171
+ }
172
+ return pickMarketLocale({
173
+ locales: marketLocales,
174
+ chosen,
175
+ uiLanguage,
176
+ uiLanguages: locales.value.map(entry => entry.code),
177
+ defaultUiLanguage: defaultUiLanguage.value,
178
+ });
179
+ }
180
+
181
+ const tag = computed(() => {
182
+ const picked = pick(locale.value, contentLocale.value);
183
+ return picked && localeLanguage(picked) !== localeLanguage(locale.value) ? pick(locale.value, "") : picked;
184
+ });
185
+
186
+ return Object.assign(tag, {
187
+ forLanguage: (code: string): string | null => pick(localeLanguage(code), ""),
188
+ });
189
+ }
@@ -0,0 +1,23 @@
1
+ import type { ComputedRef } from "vue";
2
+
3
+ import type { SeoRules } from "../interfaces/seo";
4
+ import { defaultSeoRules } from "../shared/seoRules";
5
+
6
+ /**
7
+ * The SEO rules of the domain this page is served on, synchronous everywhere.
8
+ *
9
+ * The server read them before rendering began (server/plugins/seoSiteConfig.ts
10
+ * puts them on the request context); the shared state takes them from there
11
+ * and hands them to the client in the payload. A domain's rules do not change
12
+ * while a buyer navigates it, so the client never reads again.
13
+ *
14
+ * Without an answer (a page rendered outside a request, a test) they are the
15
+ * service's defaults for the host, the same thing the server falls back to:
16
+ * the host without its port and in lower case, as the server keys it.
17
+ */
18
+ export function useSeoRules(): ComputedRef<SeoRules> {
19
+ const state = useState<SeoRules | null>("cover:seo-rules", () =>
20
+ (import.meta.server ? useRequestEvent()?.context.seoRules as SeoRules | undefined : undefined) ?? null);
21
+ const host = useRequestURL().hostname.toLowerCase();
22
+ return computed(() => state.value ?? defaultSeoRules(host));
23
+ }
@@ -38,7 +38,7 @@ export default defineFormKitConfig({
38
38
  // Custom inputs: `datepicker` wraps Nuxt UI's UCalendar (ISO string value).
39
39
  inputs: {
40
40
  datepicker: createInput(FormKitDatePicker, {
41
- props: ["minDays", "maxDays", "disableWeekends"],
41
+ props: ["minDays", "maxDays", "disableWeekends", "clearable"],
42
42
  }),
43
43
  },
44
44
  rules: {
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A domain's SEO rules, as the seo service publishes them for storefronts
3
+ * (`GET /v1/seo/storefront/rules?host=…`, schema 1). The storefront applies
4
+ * them per request; it does not own them. Defaults are filled in by the
5
+ * service, so a domain nobody configured still gets a complete bundle.
6
+ */
7
+ export interface SeoPageTypeRules {
8
+ /** Pattern with placeholders such as `{name} | {site}`; indexed types only. */
9
+ readonly title?: string;
10
+ readonly description?: string | null;
11
+ /** `index,follow`, `noindex,follow`, … */
12
+ readonly robots: string;
13
+ }
14
+
15
+ export interface SeoRules {
16
+ readonly schema: number;
17
+ readonly host: string;
18
+ /**
19
+ * Whether the host is one of the tenant's (rules of its own, or announced
20
+ * by Console). A made-up host gets the defaults too, with `false`. Older
21
+ * services leave it out.
22
+ */
23
+ readonly known?: boolean;
24
+ /** The organisation's name, or the host. */
25
+ readonly site_name: string;
26
+ readonly canonical: {
27
+ /** The main domain product and category pages canonicalise to; null for this one. */
28
+ readonly host: string | null;
29
+ readonly cross_domain_page_types: readonly string[];
30
+ /** Query parameters a canonical leaves out; `utm_*` is a prefix. */
31
+ readonly strip_params: readonly string[];
32
+ };
33
+ readonly hreflang: {
34
+ readonly x_default: string | null;
35
+ /** null leaves the alternates to the storefront's own locales. */
36
+ readonly locales: readonly string[] | null;
37
+ };
38
+ readonly max_length: { readonly title: number; readonly description: number };
39
+ readonly page_types: Readonly<Record<string, SeoPageTypeRules>>;
40
+ readonly organisation: { readonly name: string; readonly logo: string | null; readonly same_as: readonly string[] } | null;
41
+ readonly structured_data: { readonly prices: boolean };
42
+ /**
43
+ * A product URL whose product cannot be found: a 301 to the category the
44
+ * URL names, or 410 Gone. Absent in bundles from before the field (the
45
+ * default then, `category`).
46
+ */
47
+ readonly removed_products?: "category" | "gone";
48
+ }
@@ -1,14 +1,8 @@
1
1
  <script setup lang="ts">
2
- import { filterLocaleHeadAlternates } from "../shared/productLocales";
3
-
4
- const localeHead = useLocaleHead({ seo: true });
5
2
  // A product page links only the languages the product has a page in
6
3
  // (PE-859 hides untranslated products); every other page is unchanged.
7
- const { available: productLocales } = useProductLocales();
8
- const head = computed(() => ({
9
- ...localeHead.value,
10
- ...filterLocaleHeadAlternates(localeHead.value, productLocales.value),
11
- }));
4
+ const { available: productLocales, localizePath } = useProductLocales();
5
+ const head = useSeoHead(productLocales, { localizePath });
12
6
  const { navigateToSearch } = useSearch();
13
7
  const route = useRoute();
14
8
  const cart = useCartStore();
@@ -13,7 +13,9 @@ const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopCo
13
13
  const legalLinks = computed(() => (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
14
14
  const { t } = useI18n();
15
15
  const localePath = useLocalePath();
16
- const head = useLocaleHead({ seo: true });
16
+ // Login, registration, recovery and the checkout are never indexed, and their
17
+ // URLs carry secrets and order ids that a canonical would repeat.
18
+ const head = useSeoHead(undefined, { canonical: false });
17
19
  const year = new Date().getFullYear();
18
20
 
19
21
  // Checkout gets a subtly tinted page background so the white section
@@ -1,3 +1,4 @@
1
+ import { type NovalnetIframeStyle, novalnetIframeStyle, readNovalnetFieldTokens } from "./novalnetStyle";
1
2
  import { type PspInstrument, PspInputError, type PspMountContext, type PspTokenizer } from "./types";
2
3
 
3
4
  /**
@@ -41,7 +42,7 @@ interface NovalnetFormConfig {
41
42
  on_show_overlay?: () => void;
42
43
  on_hide_overlay?: () => void;
43
44
  };
44
- iframe: { id: string; inline: number; style?: Record<string, string> };
45
+ iframe: { id: string; inline: number; style?: NovalnetIframeStyle };
45
46
  customer?: Record<string, unknown>;
46
47
  transaction?: Record<string, unknown>;
47
48
  custom?: { lang?: string };
@@ -96,13 +97,15 @@ export function novalnetFormConfig(
96
97
  ctx: Pick<PspMountContext, "testMode" | "locale" | "amount" | "currency" | "customer">,
97
98
  iframeId: string,
98
99
  callback: NovalnetFormConfig["callback"],
100
+ style?: NovalnetIframeStyle,
99
101
  ): NovalnetFormConfig {
100
102
  const customer = ctx.customer;
101
103
  const billing = customer?.billing;
102
104
  const amount = novalnetAmount(ctx.amount);
103
105
  const config: NovalnetFormConfig = {
104
106
  callback,
105
- iframe: { id: iframeId, inline: 1 },
107
+ // The shop's look (FE-6); without it the iframe draws Novalnet's own.
108
+ iframe: { id: iframeId, inline: 1, ...(style ? { style } : {}) },
106
109
  custom: { lang: (ctx.locale ?? "de").slice(0, 2).toUpperCase() },
107
110
  transaction: {
108
111
  ...(amount !== undefined ? { amount } : {}),
@@ -151,6 +154,7 @@ let instanceCounter = 0;
151
154
  export function createNovalnetTokenizer(): PspTokenizer {
152
155
  let utility: NovalnetUtilityApi | null = null;
153
156
  let iframe: HTMLIFrameElement | null = null;
157
+ let host: HTMLElement | null = null;
154
158
  let pending: { resolve: (v: PspInstrument) => void; reject: (e: Error) => void; timer: ReturnType<typeof setTimeout> } | null = null;
155
159
 
156
160
  function settle(fn: (p: NonNullable<typeof pending>) => void) {
@@ -191,6 +195,20 @@ export function createNovalnetTokenizer(): PspTokenizer {
191
195
  if (!utility.setClientKey(ctx.publishableKey)) {
192
196
  throw new Error("Novalnet client key was refused");
193
197
  }
198
+ // Read before the iframe goes in, so the probe measures the theme
199
+ // and nothing Novalnet adds. A theme that cannot be read still gets
200
+ // a working field, in Novalnet's own look.
201
+ let style: NovalnetIframeStyle | undefined;
202
+ try {
203
+ style = novalnetIframeStyle(readNovalnetFieldTokens(ctx.el));
204
+ }
205
+ catch {
206
+ style = undefined;
207
+ }
208
+ // The iframe draws a box around every field, so the mount element
209
+ // drops its own (the checkout styles `data-psp-fields="own"`).
210
+ host = ctx.el;
211
+ host.dataset.pspFields = "own";
194
212
  instanceCounter += 1;
195
213
  iframe = document.createElement("iframe");
196
214
  iframe.id = `novalnet-card-iframe-${instanceCounter}`;
@@ -222,7 +240,7 @@ export function createNovalnetTokenizer(): PspTokenizer {
222
240
  }
223
241
  frame.addEventListener("load", onload);
224
242
  // The library sets the iframe's src and its own onload handler.
225
- const created = utility!.createCreditCardForm(novalnetFormConfig(ctx, frame.id, callback));
243
+ const created = utility!.createCreditCardForm(novalnetFormConfig(ctx, frame.id, callback, style));
226
244
  if (created === false) {
227
245
  finish(new Error("Novalnet card form could not be created"));
228
246
  }
@@ -248,6 +266,10 @@ export function createNovalnetTokenizer(): PspTokenizer {
248
266
  settle(p => p.reject(new Error("card field was removed")));
249
267
  iframe?.remove();
250
268
  iframe = null;
269
+ if (host) {
270
+ delete host.dataset.pspFields;
271
+ host = null;
272
+ }
251
273
  utility = null;
252
274
  },
253
275
  };
@@ -0,0 +1,186 @@
1
+ /**
2
+ * The shop's look for Novalnet's card iframe (FE-6).
3
+ *
4
+ * The card form lives in an iframe on secure.novalnet.de, so none of the
5
+ * shop's CSS reaches it. `createCreditCardForm` takes the look as text instead,
6
+ * under `iframe.style`:
7
+ *
8
+ * - `container` — a style sheet the iframe adds to its own document
9
+ * (selectors allowed, so `:focus` and `::placeholder` work there);
10
+ * - `input` / `label` — inline styles put on every input and label.
11
+ *
12
+ * The values are not written per shop. They are read from the theme's design
13
+ * tokens at mount time (Nuxt UI's `--ui-*` variables and the body font), so
14
+ * every theme gets its own look. A theme that wants the card field to differ
15
+ * from its other inputs sets the `--cover-psp-field-*` variables below on the
16
+ * mount element or any ancestor.
17
+ */
18
+
19
+ /** Resolved values, as the browser computed them (`rgb(...)`, `px`). */
20
+ export interface NovalnetFieldTokens {
21
+ fontFamily: string;
22
+ fontSize: string;
23
+ text: string;
24
+ background: string;
25
+ border: string;
26
+ radius: string;
27
+ height: string;
28
+ paddingX: string;
29
+ focus: string;
30
+ placeholder: string;
31
+ label: string;
32
+ labelSize: string;
33
+ /** `@font-face` rules for `fontFamily`, with absolute URLs; may be empty. */
34
+ fontFaces?: string[];
35
+ }
36
+
37
+ export interface NovalnetIframeStyle {
38
+ container: string;
39
+ input: string;
40
+ label: string;
41
+ }
42
+
43
+ /**
44
+ * Each token, the CSS property the probe resolves it through, and the theme
45
+ * variable it defaults to. The defaults are Nuxt UI's own input (`UInput`, size
46
+ * md, variant outline): text-base/5, px-2.5, rounded-md, a 1px ring in the
47
+ * accented border colour, a 2px primary ring on focus, a dimmed placeholder.
48
+ */
49
+ const PROBE: Array<[keyof NovalnetFieldTokens, string, string]> = [
50
+ ["text", "color", "var(--cover-psp-field-text, var(--ui-text-highlighted, currentColor))"],
51
+ ["background", "background-color", "var(--cover-psp-field-bg, var(--ui-bg, transparent))"],
52
+ ["border", "border-top-color", "var(--cover-psp-field-border, var(--ui-border-accented, #d4d4d4))"],
53
+ ["focus", "border-right-color", "var(--cover-psp-field-focus, var(--ui-primary, #2563eb))"],
54
+ ["placeholder", "border-bottom-color", "var(--cover-psp-field-placeholder, var(--ui-text-dimmed, #a3a3a3))"],
55
+ ["label", "border-left-color", "var(--cover-psp-field-label, var(--ui-text, currentColor))"],
56
+ ["height", "height", "var(--cover-psp-field-height, 2rem)"],
57
+ ["paddingX", "padding-left", "var(--cover-psp-field-padding-x, 0.625rem)"],
58
+ ["radius", "border-top-left-radius", "var(--cover-psp-field-radius, calc(var(--ui-radius, 0.25rem) * 1.5))"],
59
+ ["fontSize", "font-size", "var(--cover-psp-field-font-size, 1rem)"],
60
+ ["labelSize", "width", "var(--cover-psp-field-label-size, 0.875rem)"],
61
+ ];
62
+
63
+ /** A value that cannot leave its declaration: no `;`, braces or markup. */
64
+ function clean(value: string | undefined): string {
65
+ return String(value ?? "").replace(/[;{}<>]/g, "").trim();
66
+ }
67
+
68
+ /**
69
+ * The `iframe.style` block for the tokens. Pure, so it can be tested.
70
+ *
71
+ * Focus and placeholder go into the style sheet, since an inline style cannot
72
+ * name a state. They are `!important` there because the inline `input` style
73
+ * would win over a rule without it.
74
+ */
75
+ export function novalnetIframeStyle(tokens: NovalnetFieldTokens): NovalnetIframeStyle {
76
+ const t = Object.fromEntries(
77
+ Object.entries(tokens).map(([k, v]) => [k, Array.isArray(v) ? v : clean(v as string)]),
78
+ ) as unknown as NovalnetFieldTokens;
79
+ const font = t.fontFamily ? `font-family:${t.fontFamily};` : "";
80
+ const input = [
81
+ font,
82
+ `font-size:${t.fontSize};`,
83
+ "line-height:1.25;",
84
+ `color:${t.text};`,
85
+ `background:${t.background};`,
86
+ `border:1px solid ${t.border};`,
87
+ `border-radius:${t.radius};`,
88
+ `height:${t.height};`,
89
+ `padding:0 ${t.paddingX};`,
90
+ "box-sizing:border-box;",
91
+ "width:100%;",
92
+ "box-shadow:none;",
93
+ "outline:0;",
94
+ "transition:border-color .15s,box-shadow .15s;",
95
+ ].join("");
96
+ const label = [
97
+ font,
98
+ `font-size:${t.labelSize};`,
99
+ "font-weight:500;",
100
+ `color:${t.label};`,
101
+ ].join("");
102
+ const container = [
103
+ ...(tokens.fontFaces ?? []),
104
+ `html,body{${font}margin:0;background:transparent;color:${t.text};}`,
105
+ `input:focus{border-color:${t.focus}!important;box-shadow:inset 0 0 0 1px ${t.focus}!important;}`,
106
+ `input::placeholder{color:${t.placeholder}!important;opacity:1;}`,
107
+ `.label-group{${label}}`,
108
+ ".form-group{margin:0 0 .75rem;}",
109
+ ].join("");
110
+ return { container, input, label };
111
+ }
112
+
113
+ /** `url(...)` in a rule, made absolute against the sheet the rule came from. */
114
+ function absoluteUrls(cssText: string, base: string): string {
115
+ return cssText.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g, (_m, quote: string, url: string) => {
116
+ try {
117
+ return `url(${quote}${new URL(url, base).href}${quote})`;
118
+ }
119
+ catch {
120
+ return _m;
121
+ }
122
+ });
123
+ }
124
+
125
+ /**
126
+ * The page's `@font-face` rules for the first family of `fontFamily`. The
127
+ * iframe is another origin, so it cannot see the shop's web font unless the
128
+ * rule travels along. Whether the browser then loads the file depends on the
129
+ * font being served with CORS; without it the fallback families apply.
130
+ */
131
+ export function pageFontFaces(fontFamily: string, doc: Document = document, limit = 6): string[] {
132
+ const family = fontFamily.split(",")[0]?.trim().replace(/^['"]|['"]$/g, "").toLowerCase();
133
+ if (!family) {
134
+ return [];
135
+ }
136
+ const out: string[] = [];
137
+ for (const sheet of Array.from(doc.styleSheets)) {
138
+ let rules: CSSRuleList;
139
+ try {
140
+ rules = sheet.cssRules;
141
+ }
142
+ catch {
143
+ continue; // a cross-origin sheet does not let its rules be read
144
+ }
145
+ for (const rule of Array.from(rules)) {
146
+ if (out.length >= limit) {
147
+ return out;
148
+ }
149
+ if (rule.constructor?.name !== "CSSFontFaceRule" && !rule.cssText.startsWith("@font-face")) {
150
+ continue;
151
+ }
152
+ const declared = (rule as CSSFontFaceRule).style?.getPropertyValue("font-family")?.trim().replace(/^['"]|['"]$/g, "").toLowerCase();
153
+ if (declared === family) {
154
+ out.push(absoluteUrls(rule.cssText, sheet.href ?? doc.baseURI));
155
+ }
156
+ }
157
+ }
158
+ return out;
159
+ }
160
+
161
+ /**
162
+ * The theme's tokens, resolved by the browser. A probe inside `el` carries
163
+ * each variable on a property of its own, so it inherits whatever `el` sits in
164
+ * (a theme, a dark section) and comes back as a plain colour or length.
165
+ */
166
+ export function readNovalnetFieldTokens(el: HTMLElement): NovalnetFieldTokens {
167
+ const probe = document.createElement("div");
168
+ probe.setAttribute("aria-hidden", "true");
169
+ probe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none;border:1px solid;";
170
+ for (const [, property, value] of PROBE) {
171
+ probe.style.setProperty(property, value);
172
+ }
173
+ el.appendChild(probe);
174
+ try {
175
+ const computed = getComputedStyle(probe);
176
+ const tokens = { fontFamily: getComputedStyle(el).fontFamily } as NovalnetFieldTokens;
177
+ for (const [key, property] of PROBE) {
178
+ (tokens as unknown as Record<string, string>)[key] = computed.getPropertyValue(property);
179
+ }
180
+ tokens.fontFaces = pageFontFaces(tokens.fontFamily);
181
+ return tokens;
182
+ }
183
+ finally {
184
+ probe.remove();
185
+ }
186
+ }
@@ -0,0 +1,7 @@
1
+ import type { ProductCategory } from "../config/navigation";
2
+
3
+ /** Whether a two-level category tree has the category, and the subcategory under it when one is named. */
4
+ export function treeHasCategory(categories: readonly ProductCategory[], slug: string | undefined, subcategory?: string): boolean {
5
+ const category = categories.find(c => c.slug === slug);
6
+ return !!category && (!subcategory || category.subcategories.some(s => s.slug === subcategory));
7
+ }
@@ -13,6 +13,14 @@
13
13
  * client (facet labels), so both resolve a label the same way.
14
14
  */
15
15
 
16
+ /**
17
+ * Cookie the language choice persists the chosen MARKET locale in (`de-CH`,
18
+ * `fr-FR`). The URL prefix only says which UI strings render; this says
19
+ * which catalogue language the buyer asked for, which differs when the
20
+ * market offers a language the storefront has no UI strings for (PE-866).
21
+ */
22
+ export const CONTENT_LOCALE_COOKIE = "cover-content-locale";
23
+
16
24
  /** The region a bare UI language stands for when a full code is needed. */
17
25
  export const DEFAULT_LOCALE_REGIONS: Readonly<Record<string, string>> = {
18
26
  de: "DE",
@@ -32,6 +32,44 @@ export function languagesWithDocuments(
32
32
  searchLocaleKeys(language).some(key => present.has(key)));
33
33
  }
34
34
 
35
+ /**
36
+ * The product's name in each language (of `languages`) it has a document in:
37
+ * the document the product page would find, under the first of the
38
+ * language's search keys that has one (PE-1236). A product's slug carries its
39
+ * name, so a link into another language needs that language's name, or it
40
+ * lands on the outdated-slug 301.
41
+ */
42
+ export function namesByLanguage(
43
+ docs: readonly { readonly locale: string; readonly name?: string }[],
44
+ languages: readonly string[],
45
+ ): Record<string, string> {
46
+ const byLocale = new Map(docs
47
+ .filter(doc => doc.locale && doc.name)
48
+ .map(doc => [normalizeLocaleCode(doc.locale), doc.name as string]));
49
+ const names: Record<string, string> = {};
50
+ for (const language of languages) {
51
+ const key = searchLocaleKeys(language).find(candidate => byLocale.has(candidate));
52
+ if (key) {
53
+ names[language] = byLocale.get(key) as string;
54
+ }
55
+ }
56
+ return names;
57
+ }
58
+
59
+ /**
60
+ * A product page's path with its slug swapped for another language's. The
61
+ * slug is the path's last segment; a path that does not end in `current` is
62
+ * returned as it is.
63
+ */
64
+ export function withProductSlug(path: string, current: string, target: string): string {
65
+ const [pathname = "", ...rest] = path.split(/(?=[?#])/);
66
+ const suffix = `/${encodeURIComponent(current)}`;
67
+ if (!current || !target || current === target || !pathname.endsWith(suffix)) {
68
+ return path;
69
+ }
70
+ return `${pathname.slice(0, -suffix.length)}/${encodeURIComponent(target)}${rest.join("")}`;
71
+ }
72
+
35
73
  /**
36
74
  * The listing a language without the product sends the buyer to: the
37
75
  * product's own category, as deep as a listing URL goes
@@ -41,10 +79,15 @@ export function languagesWithDocuments(
41
79
  * translated, so the same path exists in every language.
42
80
  */
43
81
  export function productFallbackPath(categorySegments: readonly string[]): string {
44
- const path = categorySegments.filter(segment => segment && segment !== "_").slice(0, 2);
82
+ const path = productListingSegments(categorySegments);
45
83
  return path.length ? `/category/${path.map(encodeURIComponent).join("/")}` : "/";
46
84
  }
47
85
 
86
+ /** The category and subcategory of productFallbackPath(), none for `_` or a URL without a category. */
87
+ export function productListingSegments(categorySegments: readonly string[]): string[] {
88
+ return categorySegments.filter(segment => segment && segment !== "_").slice(0, 2);
89
+ }
90
+
48
91
  /** The category segments of a `/category/<…>/product/<slug>` route. */
49
92
  export function productRouteCategorySegments(category: readonly string[], rest: readonly string[]): string[] {
50
93
  const marker = rest.lastIndexOf("product");
@@ -67,6 +110,24 @@ export interface LocaleHeadMeta {
67
110
  [key: string]: unknown;
68
111
  }
69
112
 
113
+ /**
114
+ * The locale head with each alternate's href put through `localize` for its
115
+ * language (`x-default` for `defaultLocale`): a product page's alternates
116
+ * carry the slug of the language they link (PE-1236).
117
+ */
118
+ export function localizeLocaleHeadAlternates<L extends LocaleHeadLink, M extends LocaleHeadMeta>(
119
+ head: { link?: L[]; meta?: M[] },
120
+ localize: (href: string, code: string) => string,
121
+ defaultLocale: string,
122
+ ): { link: L[]; meta: M[] } {
123
+ return {
124
+ link: (head.link ?? []).map(entry => (entry.rel === "alternate" && entry.hreflang && entry.href
125
+ ? { ...entry, href: localize(entry.href, entry.hreflang === "x-default" ? defaultLocale : entry.hreflang) }
126
+ : entry)),
127
+ meta: head.meta ?? [],
128
+ };
129
+ }
130
+
70
131
  /**
71
132
  * The locale head with alternates only for the languages that have the page.
72
133
  *