@revenexx/cover 0.12.0 → 0.14.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.
- package/app/api/product.ts +1 -0
- package/app/components/cart/recommend/CartCrossSell.vue +2 -1
- package/app/components/layout/header/LocaleSwitcher.vue +18 -1
- package/app/components/listing/ListingFilterBar.vue +1 -0
- package/app/components/listing/ListingFilterDrawer.vue +1 -0
- package/app/components/listing/ListingFilterRail.vue +1 -0
- package/app/components/search/filter/SearchFacets.vue +10 -3
- package/app/components/search/filter/SearchFacetsBar.vue +7 -3
- package/app/components/search/filter/SearchFacetsDrawer.vue +7 -2
- package/app/components/ui/forms/SearchInput.vue +4 -1
- package/app/composables/useFacetMeta.ts +6 -6
- package/app/composables/useProductListing.ts +18 -2
- package/app/composables/useProductLocales.ts +56 -0
- package/app/composables/useSearchListing.ts +16 -0
- package/app/layouts/default.vue +10 -1
- package/app/shared/locale.ts +114 -0
- package/app/shared/productLocales.ts +109 -0
- package/i18n/locales/de/common.json +2 -1
- package/i18n/locales/en/common.json +2 -1
- package/nuxt.config.ts +22 -0
- package/package.json +1 -1
- package/server/api/account/quotes/[id]/order.post.ts +14 -3
- package/server/api/cart/calculate.post.ts +4 -0
- package/server/api/categories/[slug]/subcategories.get.ts +34 -31
- package/server/api/orders/index.post.ts +78 -31
- package/server/api/payment/psp-config.get.ts +11 -21
- package/server/api/product/[id]/locales.get.ts +57 -0
- package/server/api/quotes/request.post.ts +2 -2
- package/server/api/typesense/search.post.ts +61 -317
- package/server/api/typesense/suggest.post.ts +14 -9
- package/server/{api/typesense/drop.get.ts → dev/typesense/drop.ts} +2 -1
- package/server/{api/typesense/health.get.ts → dev/typesense/health.ts} +1 -0
- package/server/dev/typesense/seed.ts +59 -0
- package/server/dev/typesense/seedDocuments.ts +105 -0
- package/server/interfaces/product.ts +8 -0
- package/server/routes/punchout/start.get.ts +40 -3
- package/server/services/ApiBrandService.ts +28 -42
- package/server/services/ApiProductService.ts +14 -11
- package/server/utils/buyerIdentity.ts +11 -0
- package/server/utils/liveCatalog.ts +200 -48
- package/server/utils/liveListingSearch.ts +201 -0
- package/server/utils/livePrices.ts +24 -9
- package/server/utils/orderLinePrices.ts +72 -0
- package/server/utils/paymentFee.ts +59 -0
- package/server/utils/pspConfig.ts +42 -0
- package/server/utils/revenexxSdk.ts +25 -2
- package/server/utils/searchClient.ts +305 -0
- package/server/utils/searchMultiSearchFallback.ts +216 -0
- package/server/api/typesense/seed.get.ts +0 -111
package/app/api/product.ts
CHANGED
|
@@ -16,7 +16,7 @@ const props = defineProps<{
|
|
|
16
16
|
}>();
|
|
17
17
|
|
|
18
18
|
const { icon } = useIcons();
|
|
19
|
-
const { t } = useI18n();
|
|
19
|
+
const { locale, t } = useI18n();
|
|
20
20
|
const toast = useToast();
|
|
21
21
|
const cart = useCartStore();
|
|
22
22
|
|
|
@@ -33,6 +33,7 @@ const { data } = useFetch<{ products: ProductList[] }>(searchApi.search(), {
|
|
|
33
33
|
key: `cart-cross-sell:${props.popular ? "popular" : "category"}`,
|
|
34
34
|
method: "POST",
|
|
35
35
|
body: requestBody,
|
|
36
|
+
headers: computed(() => ({ "x-locale": locale.value })),
|
|
36
37
|
server: false,
|
|
37
38
|
lazy: true,
|
|
38
39
|
default: () => ({ products: [] }),
|
|
@@ -6,10 +6,16 @@
|
|
|
6
6
|
* carry region + currency; languages show their native full names (never
|
|
7
7
|
* flags or codes) and are limited to the locales the selected market
|
|
8
8
|
* offers. The trigger shows the current combination prominently.
|
|
9
|
+
*
|
|
10
|
+
* On a product page a language the product has no page in (PE-859 hides
|
|
11
|
+
* untranslated products) still switches the language, but lands on the
|
|
12
|
+
* product's category instead of a 404; a hint under the select says so.
|
|
9
13
|
*/
|
|
10
14
|
const { icon } = useIcons();
|
|
11
15
|
const { t, locale, locales } = useI18n();
|
|
12
16
|
const switchLocalePath = useSwitchLocalePath();
|
|
17
|
+
const localePath = useLocalePath();
|
|
18
|
+
const { hasPage, fallbackPath } = useProductLocales();
|
|
13
19
|
const { markets } = useMarkets();
|
|
14
20
|
const { market, setMarket, region, currencies, currency, currencySymbol, setCurrency } = useLocalePreferences(markets);
|
|
15
21
|
|
|
@@ -29,11 +35,16 @@ const languageItems = computed(() => {
|
|
|
29
35
|
code: entry.code,
|
|
30
36
|
/** Native full name ("Deutsch", "English") — never flags or codes. */
|
|
31
37
|
name: entry.name ?? entry.code,
|
|
32
|
-
to: switchLocalePath(entry.code),
|
|
38
|
+
to: hasPage(entry.code) ? switchLocalePath(entry.code) : localePath(fallbackPath.value, entry.code),
|
|
33
39
|
active: entry.code === locale.value,
|
|
40
|
+
hasPage: hasPage(entry.code),
|
|
34
41
|
}));
|
|
35
42
|
});
|
|
36
43
|
|
|
44
|
+
/** Languages the open product is missing in, by name — empty off a product page. */
|
|
45
|
+
const languagesWithoutProduct = computed(() =>
|
|
46
|
+
languageItems.value.filter(item => !item.hasPage && !item.active).map(item => item.name));
|
|
47
|
+
|
|
37
48
|
const currentLanguageName = computed(() =>
|
|
38
49
|
languageItems.value.find(item => item.active)?.name ?? locale.value);
|
|
39
50
|
|
|
@@ -121,6 +132,12 @@ const triggerLabel = computed(() =>
|
|
|
121
132
|
class="w-full"
|
|
122
133
|
@update:model-value="(code: string) => onLanguageChange(code)"
|
|
123
134
|
/>
|
|
135
|
+
<template
|
|
136
|
+
v-if="languagesWithoutProduct.length"
|
|
137
|
+
#help
|
|
138
|
+
>
|
|
139
|
+
{{ t('topbar.localePanel.productNotTranslated', { languages: languagesWithoutProduct.join(', ') }) }}
|
|
140
|
+
</template>
|
|
124
141
|
</UFormField>
|
|
125
142
|
|
|
126
143
|
<!-- Currency: chosen within the currencies the market trades in -->
|
|
@@ -55,6 +55,7 @@ const listing = props.listing;
|
|
|
55
55
|
v-model="listing.activeFilters.value"
|
|
56
56
|
v-model:price-range="listing.priceRange.value"
|
|
57
57
|
:facets="listing.facets.value"
|
|
58
|
+
:show-price="listing.priceFilter.value"
|
|
58
59
|
/>
|
|
59
60
|
</div>
|
|
60
61
|
<div class="border-t border-(--ui-border) p-4">
|
|
@@ -7,11 +7,15 @@ import type { PriceRange, SearchFacet } from "../../../interfaces/search-facets"
|
|
|
7
7
|
* shared facet logic (toggling, labels, debounced price) lives in
|
|
8
8
|
* useFacetFilters; this component owns the vertical accordion presentation.
|
|
9
9
|
*/
|
|
10
|
-
const props = defineProps<{
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
11
|
facets: SearchFacet[];
|
|
12
12
|
modelValue: Record<string, string[]>;
|
|
13
13
|
priceRange: PriceRange;
|
|
14
|
-
|
|
14
|
+
/** Offer the price range — off where the index carries no price. */
|
|
15
|
+
showPrice?: boolean;
|
|
16
|
+
}>(), {
|
|
17
|
+
showPrice: true,
|
|
18
|
+
});
|
|
15
19
|
|
|
16
20
|
const emit = defineEmits<{
|
|
17
21
|
"update:modelValue": [value: Record<string, string[]>];
|
|
@@ -108,7 +112,10 @@ function toggleGroup(field: string): void {
|
|
|
108
112
|
</section>
|
|
109
113
|
|
|
110
114
|
<!-- Price range -->
|
|
111
|
-
<section
|
|
115
|
+
<section
|
|
116
|
+
v-if="showPrice"
|
|
117
|
+
class="py-1"
|
|
118
|
+
>
|
|
112
119
|
<button
|
|
113
120
|
type="button"
|
|
114
121
|
tabindex="0"
|
|
@@ -7,11 +7,15 @@ import type { PriceRange, SearchFacet } from "../../../interfaces/search-facets"
|
|
|
7
7
|
* logic with the vertical SearchFacets via useFacetFilters; only the popover
|
|
8
8
|
* presentation differs.
|
|
9
9
|
*/
|
|
10
|
-
const props = defineProps<{
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
11
|
facets: SearchFacet[];
|
|
12
12
|
modelValue: Record<string, string[]>;
|
|
13
13
|
priceRange: PriceRange;
|
|
14
|
-
|
|
14
|
+
/** Offer the price range — off where the index carries no price. */
|
|
15
|
+
showPrice?: boolean;
|
|
16
|
+
}>(), {
|
|
17
|
+
showPrice: true,
|
|
18
|
+
});
|
|
15
19
|
|
|
16
20
|
const emit = defineEmits<{
|
|
17
21
|
"update:modelValue": [value: Record<string, string[]>];
|
|
@@ -94,7 +98,7 @@ const {
|
|
|
94
98
|
</UPopover>
|
|
95
99
|
|
|
96
100
|
<!-- Price -->
|
|
97
|
-
<UPopover>
|
|
101
|
+
<UPopover v-if="showPrice">
|
|
98
102
|
<UButton
|
|
99
103
|
color="neutral"
|
|
100
104
|
variant="outline"
|
|
@@ -3,11 +3,15 @@ import type { PriceRange, SearchFacet } from "../../../interfaces/search-facets"
|
|
|
3
3
|
|
|
4
4
|
const { icon } = useIcons();
|
|
5
5
|
|
|
6
|
-
const props = defineProps<{
|
|
6
|
+
const props = withDefaults(defineProps<{
|
|
7
7
|
facets: SearchFacet[];
|
|
8
8
|
modelValue: Record<string, string[]>;
|
|
9
9
|
priceRange: PriceRange;
|
|
10
|
-
|
|
10
|
+
/** Offer the price range — off where the index carries no price. */
|
|
11
|
+
showPrice?: boolean;
|
|
12
|
+
}>(), {
|
|
13
|
+
showPrice: true,
|
|
14
|
+
});
|
|
11
15
|
|
|
12
16
|
const emit = defineEmits<{
|
|
13
17
|
"update:modelValue": [value: Record<string, string[]>];
|
|
@@ -50,6 +54,7 @@ const priceRangeProxy = computed({
|
|
|
50
54
|
v-model="filtersProxy"
|
|
51
55
|
v-model:price-range="priceRangeProxy"
|
|
52
56
|
:facets="facets"
|
|
57
|
+
:show-price="showPrice"
|
|
53
58
|
/>
|
|
54
59
|
</div>
|
|
55
60
|
</template>
|
|
@@ -24,7 +24,7 @@ const props = withDefaults(defineProps<{
|
|
|
24
24
|
placeholder: undefined,
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
const { t } = useI18n();
|
|
27
|
+
const { locale, t } = useI18n();
|
|
28
28
|
|
|
29
29
|
const placeholder = computed(() => props.placeholder || t("search.input.placeholder"));
|
|
30
30
|
|
|
@@ -85,6 +85,9 @@ async function fetchSuggestions(q: string): Promise<void> {
|
|
|
85
85
|
const data = await $fetch<{ suggestions: Suggestion[] }>(searchApi.suggest(), {
|
|
86
86
|
method: "POST",
|
|
87
87
|
body: { q },
|
|
88
|
+
// The BFF filters the index by locale; without it, it guesses from the
|
|
89
|
+
// cookie or Accept-Language and may suggest the other language.
|
|
90
|
+
headers: { "x-locale": locale.value },
|
|
88
91
|
}).catch(() => ({ suggestions: [] }));
|
|
89
92
|
suggestions.value = data.suggestions;
|
|
90
93
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { productsApi } from "../api/products";
|
|
2
|
+
import { pickLocalizedLabel } from "../shared/locale";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Per-tenant Typesense facet metadata — the subset of product
|
|
@@ -52,13 +53,14 @@ export function useFacetMeta() {
|
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* Resolve a localized label for a facet whose Typesense field name
|
|
55
|
-
* is `attrs.<code>`.
|
|
56
|
-
*
|
|
56
|
+
* is `attrs.<code>`. Same chain the BFF uses for every catalogue label
|
|
57
|
+
* (requested → de → en, `de` and `de-DE` keys alike), then the raw code
|
|
58
|
+
* so the UI never renders an empty header.
|
|
57
59
|
*/
|
|
58
60
|
function label(code: string): string {
|
|
59
61
|
const entry = byCode.value.get(code);
|
|
60
62
|
if (!entry) return code;
|
|
61
|
-
return entry.labels
|
|
63
|
+
return pickLocalizedLabel(entry.labels, locale.value, code);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -71,9 +73,7 @@ export function useFacetMeta() {
|
|
|
71
73
|
function valueLabel(code: string, value: string): string {
|
|
72
74
|
const entry = byCode.value.get(code);
|
|
73
75
|
if (!entry) return value;
|
|
74
|
-
|
|
75
|
-
if (!optionLabels) return value;
|
|
76
|
-
return optionLabels[locale.value] ?? optionLabels.en ?? value;
|
|
76
|
+
return pickLocalizedLabel(entry.options[value], locale.value, value);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
return { codes, byCode, label, valueLabel, status, error };
|
|
@@ -52,6 +52,13 @@ export interface ListingResponse {
|
|
|
52
52
|
found: number;
|
|
53
53
|
page: number;
|
|
54
54
|
perPage: number;
|
|
55
|
+
/**
|
|
56
|
+
* Whether a price range filters anything on this index. Absent means yes
|
|
57
|
+
* (older BFFs); the live index answers false when it carries no price.
|
|
58
|
+
*/
|
|
59
|
+
priceFilter?: boolean;
|
|
60
|
+
/** Where curation sends this search instead of showing results. */
|
|
61
|
+
redirect?: string;
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
/**
|
|
@@ -289,9 +296,18 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
289
296
|
.filter((f): f is SearchFacet => Boolean(f && f.counts.length > 0));
|
|
290
297
|
});
|
|
291
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Whether the price filter is offered. The live index may carry no price
|
|
301
|
+
* field; a filter that does nothing is not shown at all.
|
|
302
|
+
*/
|
|
303
|
+
const priceFilter = computed(() => data.value?.priceFilter !== false);
|
|
304
|
+
|
|
305
|
+
/** A curated redirect for this query (search view only), or undefined. */
|
|
306
|
+
const redirect = computed(() => data.value?.redirect || undefined);
|
|
307
|
+
|
|
292
308
|
const activeFilterCount = computed(() =>
|
|
293
309
|
Object.values(activeFilters.value).reduce((sum, values) => sum + values.length, 0)
|
|
294
|
-
+ (priceRange.value.min !== undefined || priceRange.value.max !== undefined ? 1 : 0),
|
|
310
|
+
+ (priceFilter.value && (priceRange.value.min !== undefined || priceRange.value.max !== undefined) ? 1 : 0),
|
|
295
311
|
);
|
|
296
312
|
|
|
297
313
|
const chips = computed(() => {
|
|
@@ -326,7 +342,7 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
326
342
|
})));
|
|
327
343
|
|
|
328
344
|
return {
|
|
329
|
-
query, sort, sortOptions, page, activeFilters, priceRange,
|
|
345
|
+
query, sort, sortOptions, page, activeFilters, priceRange, priceFilter, redirect,
|
|
330
346
|
data, pending, error, execute,
|
|
331
347
|
products, facets, found, totalPages, isEmpty,
|
|
332
348
|
chips, activeFilterCount, removeChip, clearFilters,
|
|
@@ -0,0 +1,56 @@
|
|
|
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";
|
|
5
|
+
|
|
6
|
+
interface ProductLocalesResponse {
|
|
7
|
+
locales: string[] | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Which storefront locales the product on this page has a page in.
|
|
12
|
+
*
|
|
13
|
+
* With `search_untranslated=hide` (PE-859) a product exists only in the
|
|
14
|
+
* languages it is translated into, so the language switcher and the hreflang
|
|
15
|
+
* alternates must not link it into the others. Both call this; they share one
|
|
16
|
+
* request through the `product-locales:<id>` key, and the BFF caches the
|
|
17
|
+
* answer per product.
|
|
18
|
+
*
|
|
19
|
+
* `available` is `null` off a product page or when the lookup failed: every
|
|
20
|
+
* locale is linked then, exactly as before. Only a product page narrows.
|
|
21
|
+
*/
|
|
22
|
+
export function useProductLocales() {
|
|
23
|
+
const route = useRoute();
|
|
24
|
+
const { id } = useRouteProductSubject();
|
|
25
|
+
const { locales } = useI18n();
|
|
26
|
+
const requestFetch = useRequestFetch();
|
|
27
|
+
|
|
28
|
+
const codes = computed(() => locales.value.map(entry => entry.code).join(","));
|
|
29
|
+
|
|
30
|
+
const { data } = useAsyncData<ProductLocalesResponse | null>(
|
|
31
|
+
() => `product-locales:${id.value}`,
|
|
32
|
+
() => (id.value && codes.value
|
|
33
|
+
? requestFetch<ProductLocalesResponse>(productApi.locales(id.value), { query: { locales: codes.value } })
|
|
34
|
+
.catch(() => null)
|
|
35
|
+
: Promise.resolve(null)),
|
|
36
|
+
{ default: () => null },
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const available = computed<string[] | null>(() => {
|
|
40
|
+
const list = id.value ? data.value?.locales : null;
|
|
41
|
+
return list ? list.map(normalizeLocaleCode) : null;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** Whether the product has a page in this locale (always true off a product page). */
|
|
45
|
+
function hasPage(code: string): boolean {
|
|
46
|
+
return available.value?.includes(normalizeLocaleCode(code)) ?? true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 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
|
+
)));
|
|
54
|
+
|
|
55
|
+
return { available, hasPage, fallbackPath };
|
|
56
|
+
}
|
|
@@ -63,6 +63,20 @@ export const useSearchListing = (options: SearchListingOptions) => {
|
|
|
63
63
|
listEvent: () => ({ event: "search", listId: "search", term: query.value }),
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
// Curation can send a query somewhere else (a category, a landing page):
|
|
67
|
+
// the search answers with a redirect action instead of results to show.
|
|
68
|
+
// Followed on the client and only for a term the visitor actually searched
|
|
69
|
+
// (`?q`), so the editor canvas, which renders an authored sample, stays put.
|
|
70
|
+
// `replace` keeps the back button from bouncing straight back here.
|
|
71
|
+
const redirecting = computed(() => routeQuery.value !== undefined && Boolean(listing.redirect.value));
|
|
72
|
+
if (import.meta.client) {
|
|
73
|
+
watch(() => (routeQuery.value !== undefined ? listing.redirect.value : undefined), (target) => {
|
|
74
|
+
if (target) {
|
|
75
|
+
void navigateTo(target, { replace: true, external: /^https?:\/\//i.test(target) });
|
|
76
|
+
}
|
|
77
|
+
}, { immediate: true });
|
|
78
|
+
}
|
|
79
|
+
|
|
66
80
|
// `?q=*` is the match-all link (Typesense's native catch-all query): the
|
|
67
81
|
// full catalog, presented as such instead of as results for a "*" term.
|
|
68
82
|
const isCatalog = computed(() => query.value.trim() === "*");
|
|
@@ -93,6 +107,8 @@ export const useSearchListing = (options: SearchListingOptions) => {
|
|
|
93
107
|
category, subcategory, categorySlug, subcategorySlug,
|
|
94
108
|
title, breadcrumb,
|
|
95
109
|
q, searchInput, pushQuery,
|
|
110
|
+
/** True while the search is being sent to a curated redirect target. */
|
|
111
|
+
redirecting,
|
|
96
112
|
};
|
|
97
113
|
};
|
|
98
114
|
|
package/app/layouts/default.vue
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
|
|
2
|
+
import { filterLocaleHeadAlternates } from "../shared/productLocales";
|
|
3
|
+
|
|
4
|
+
const localeHead = useLocaleHead({ seo: true });
|
|
5
|
+
// A product page links only the languages the product has a page in
|
|
6
|
+
// (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
|
+
}));
|
|
3
12
|
const { navigateToSearch } = useSearch();
|
|
4
13
|
const route = useRoute();
|
|
5
14
|
const cart = useCartStore();
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale codes as the catalogue speaks them, next to the language the
|
|
3
|
+
* storefront speaks.
|
|
4
|
+
*
|
|
5
|
+
* The UI works in a bare language (`de`, `en`: the URL prefix, the i18n
|
|
6
|
+
* files). The catalogue does not agree with itself: search documents carry
|
|
7
|
+
* `locale: "de"` today and `locale: "de-DE"` after the full-code migration,
|
|
8
|
+
* and label maps from different PIMs are keyed either way. Everything here
|
|
9
|
+
* accepts both forms in both directions and prefers the full code, so the
|
|
10
|
+
* shop works before, during and after that migration.
|
|
11
|
+
*
|
|
12
|
+
* Pure functions, shared by the BFF (search filters, label picking) and the
|
|
13
|
+
* client (facet labels), so both resolve a label the same way.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The region a bare UI language stands for when a full code is needed. */
|
|
17
|
+
export const DEFAULT_LOCALE_REGIONS: Readonly<Record<string, string>> = {
|
|
18
|
+
de: "DE",
|
|
19
|
+
en: "US",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Languages a label falls back to, in order, after the requested one. */
|
|
23
|
+
export const LABEL_FALLBACK_LANGUAGES = ["de", "en"] as const;
|
|
24
|
+
|
|
25
|
+
/** `de_de` / `DE-de` / ` de-DE ` → `de-DE`; `DE` → `de`. */
|
|
26
|
+
export function normalizeLocaleCode(code: string): string {
|
|
27
|
+
const [language = "", region, ...rest] = code.trim().replace(/_/g, "-").split("-");
|
|
28
|
+
if (!region) {
|
|
29
|
+
return language.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
return [language.toLowerCase(), region.length === 2 ? region.toUpperCase() : region, ...rest].join("-");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The language subtag: `de-DE` → `de`, `de` → `de`. */
|
|
35
|
+
export function localeLanguage(code: string): string {
|
|
36
|
+
return normalizeLocaleCode(code).split("-")[0] ?? "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The full BCP-47 code for a locale: a full code is kept as it is, a bare
|
|
41
|
+
* language gets its default region (`de` → `de-DE`, `en` → `en-US`). A
|
|
42
|
+
* language without a known region stays bare.
|
|
43
|
+
*/
|
|
44
|
+
export function fullLocaleCode(code: string): string {
|
|
45
|
+
const normalized = normalizeLocaleCode(code);
|
|
46
|
+
if (normalized.includes("-")) {
|
|
47
|
+
return normalized;
|
|
48
|
+
}
|
|
49
|
+
const region = DEFAULT_LOCALE_REGIONS[normalized];
|
|
50
|
+
return region ? `${normalized}-${region}` : normalized;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The locale values a catalogue document may carry for this locale, most
|
|
55
|
+
* preferred first: the full code, then the bare language.
|
|
56
|
+
* `de` → `["de-DE", "de"]`, `de-AT` → `["de-AT", "de"]`.
|
|
57
|
+
*/
|
|
58
|
+
export function searchLocaleKeys(code: string): string[] {
|
|
59
|
+
const language = localeLanguage(code);
|
|
60
|
+
if (!language) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const full = fullLocaleCode(code);
|
|
64
|
+
return full === language ? [language] : [full, language];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A label map's value for one locale, whichever form its keys take.
|
|
69
|
+
*
|
|
70
|
+
* Tried in order: the locale's full code, its bare language, then any other
|
|
71
|
+
* region of the same language (in sorted key order, so a map carrying
|
|
72
|
+
* `de-AT` and `de-CH` always answers the same way). Keys are compared
|
|
73
|
+
* normalised (`de_DE`, `DE-de`). An empty string counts as no label: it
|
|
74
|
+
* renders as a blank name, which is worse than the fallback.
|
|
75
|
+
*/
|
|
76
|
+
export function labelForLocale(labels: Record<string, string>, locale: string): string | undefined {
|
|
77
|
+
const present = Object.keys(labels)
|
|
78
|
+
.filter(key => labels[key])
|
|
79
|
+
.sort()
|
|
80
|
+
.map(key => ({ key, code: normalizeLocaleCode(key) }));
|
|
81
|
+
|
|
82
|
+
for (const wanted of searchLocaleKeys(locale)) {
|
|
83
|
+
const hit = present.find(entry => entry.code === wanted);
|
|
84
|
+
if (hit) {
|
|
85
|
+
return labels[hit.key];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const language = localeLanguage(locale);
|
|
90
|
+
const sameLanguage = present.find(entry => entry.code.split("-")[0] === language);
|
|
91
|
+
return sameLanguage ? labels[sameLanguage.key] : undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Localised label with the catalogue's fallback chain: the requested locale,
|
|
96
|
+
* then German, then English, then `fallback` (usually the technical code).
|
|
97
|
+
* Every step matches full and short codes in both directions.
|
|
98
|
+
*/
|
|
99
|
+
export function pickLocalizedLabel(
|
|
100
|
+
labels: Record<string, string> | null | undefined,
|
|
101
|
+
locale: string,
|
|
102
|
+
fallback: string,
|
|
103
|
+
): string {
|
|
104
|
+
if (!labels) {
|
|
105
|
+
return fallback;
|
|
106
|
+
}
|
|
107
|
+
for (const candidate of [locale, ...LABEL_FALLBACK_LANGUAGES]) {
|
|
108
|
+
const label = labelForLocale(labels, candidate);
|
|
109
|
+
if (label) {
|
|
110
|
+
return label;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which storefront languages a product has a page in, and what that does to
|
|
3
|
+
* the links pointing at those pages.
|
|
4
|
+
*
|
|
5
|
+
* With `search_untranslated=hide` (baseline PE-859) a product only has search
|
|
6
|
+
* documents in the languages it is translated into; the tenant's main
|
|
7
|
+
* language is always there. The product page looks its document up under the
|
|
8
|
+
* request language's keys (`searchLocaleKeys`), so a language without such a
|
|
9
|
+
* document is a 404. The language switcher and the hreflang alternates must
|
|
10
|
+
* not send anyone there.
|
|
11
|
+
*
|
|
12
|
+
* Pure functions, shared by the BFF (which reads the documents) and the
|
|
13
|
+
* client (which filters the links), so both decide availability the same way.
|
|
14
|
+
*/
|
|
15
|
+
import { localeLanguage, normalizeLocaleCode, searchLocaleKeys } from "./locale";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The languages (of `languages`, in their order) that have a document among
|
|
19
|
+
* `docLocales`. A language counts as available exactly when the product page
|
|
20
|
+
* would find a document for it: one whose locale is one of the language's
|
|
21
|
+
* search keys (`de` → `de-DE` or `de`). Both spellings match in both
|
|
22
|
+
* directions, so this holds before, during and after the full-code migration
|
|
23
|
+
* (PE-851). A `de-AT` document does not make `de` available, because the
|
|
24
|
+
* page would not find it either.
|
|
25
|
+
*/
|
|
26
|
+
export function languagesWithDocuments(
|
|
27
|
+
docLocales: readonly string[],
|
|
28
|
+
languages: readonly string[],
|
|
29
|
+
): string[] {
|
|
30
|
+
const present = new Set(docLocales.filter(Boolean).map(normalizeLocaleCode));
|
|
31
|
+
return languages.filter(language =>
|
|
32
|
+
searchLocaleKeys(language).some(key => present.has(key)));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The listing a language without the product sends the buyer to: the
|
|
37
|
+
* product's own category, as deep as a listing URL goes
|
|
38
|
+
* (`/category/<category>/<subcategory>`). The `_` placeholder of an
|
|
39
|
+
* uncategorised product is not a category, so that case (and any URL without
|
|
40
|
+
* a category) goes to the home page instead. Category codes are not
|
|
41
|
+
* translated, so the same path exists in every language.
|
|
42
|
+
*/
|
|
43
|
+
export function productFallbackPath(categorySegments: readonly string[]): string {
|
|
44
|
+
const path = categorySegments.filter(segment => segment && segment !== "_").slice(0, 2);
|
|
45
|
+
return path.length ? `/category/${path.map(encodeURIComponent).join("/")}` : "/";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The category segments of a `/category/<…>/product/<slug>` route. */
|
|
49
|
+
export function productRouteCategorySegments(category: readonly string[], rest: readonly string[]): string[] {
|
|
50
|
+
const marker = rest.lastIndexOf("product");
|
|
51
|
+
return [...category, ...(marker >= 0 ? rest.slice(0, marker) : [])];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The parts of a `useLocaleHead()` result this module touches. */
|
|
55
|
+
export interface LocaleHeadLink {
|
|
56
|
+
id?: string;
|
|
57
|
+
rel?: string;
|
|
58
|
+
href?: string;
|
|
59
|
+
hreflang?: string;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface LocaleHeadMeta {
|
|
64
|
+
id?: string;
|
|
65
|
+
property?: string;
|
|
66
|
+
content?: string;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The locale head with alternates only for the languages that have the page.
|
|
72
|
+
*
|
|
73
|
+
* `available` is the list of available storefront locale codes, or `null`
|
|
74
|
+
* when it is not known (not a product page, or the lookup failed) — then the
|
|
75
|
+
* head is returned unchanged, which is what every other page gets.
|
|
76
|
+
*
|
|
77
|
+
* Dropped: `rel="alternate"` links whose hreflang names an unavailable
|
|
78
|
+
* language, `x-default` unless its URL is one of the alternates that stay
|
|
79
|
+
* (it points at the default locale's URL, which may be one of the dropped
|
|
80
|
+
* ones), and `og:locale:alternate` metas for unavailable languages. Canonical
|
|
81
|
+
* and `og:locale` describe the current page and stay. Matching is by language
|
|
82
|
+
* subtag, the same unit availability is decided in.
|
|
83
|
+
*/
|
|
84
|
+
export function filterLocaleHeadAlternates<L extends LocaleHeadLink, M extends LocaleHeadMeta>(
|
|
85
|
+
head: { link?: L[]; meta?: M[] },
|
|
86
|
+
available: readonly string[] | null,
|
|
87
|
+
): { link: L[]; meta: M[] } {
|
|
88
|
+
const link = head.link ?? [];
|
|
89
|
+
const meta = head.meta ?? [];
|
|
90
|
+
if (!available) {
|
|
91
|
+
return { link, meta };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const languages = new Set(available.map(localeLanguage));
|
|
95
|
+
const offered = (code: string): boolean => languages.has(localeLanguage(code));
|
|
96
|
+
const isAlternate = (entry: L): boolean => entry.rel === "alternate" && Boolean(entry.hreflang);
|
|
97
|
+
|
|
98
|
+
const kept = link.filter(entry =>
|
|
99
|
+
!isAlternate(entry) || entry.hreflang === "x-default" || offered(entry.hreflang as string));
|
|
100
|
+
const keptHrefs = new Set(kept
|
|
101
|
+
.filter(entry => isAlternate(entry) && entry.hreflang !== "x-default")
|
|
102
|
+
.map(entry => entry.href));
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
link: kept.filter(entry => !isAlternate(entry) || entry.hreflang !== "x-default" || keptHrefs.has(entry.href)),
|
|
106
|
+
meta: meta.filter(entry =>
|
|
107
|
+
entry.property !== "og:locale:alternate" || !entry.content || offered(entry.content)),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -81,7 +81,8 @@
|
|
|
81
81
|
"region": "Land",
|
|
82
82
|
"currency": "Währung",
|
|
83
83
|
"regionPlaceholder": "Land suchen …",
|
|
84
|
-
"hint": "Währung und Sortiment richten sich nach dem gewählten Land."
|
|
84
|
+
"hint": "Währung und Sortiment richten sich nach dem gewählten Land.",
|
|
85
|
+
"productNotTranslated": "Diesen Artikel gibt es nicht auf {languages}. Ein Wechsel dorthin führt zu seiner Kategorie oder, wenn er keine hat, zur Startseite."
|
|
85
86
|
}
|
|
86
87
|
},
|
|
87
88
|
"header": {
|
|
@@ -81,7 +81,8 @@
|
|
|
81
81
|
"region": "Country",
|
|
82
82
|
"currency": "Currency",
|
|
83
83
|
"regionPlaceholder": "Search country…",
|
|
84
|
-
"hint": "Currency and catalog follow the selected country."
|
|
84
|
+
"hint": "Currency and catalog follow the selected country.",
|
|
85
|
+
"productNotTranslated": "This product is not available in {languages}. Switching there takes you to its category, or to the home page if it has none."
|
|
85
86
|
}
|
|
86
87
|
},
|
|
87
88
|
"header": {
|
package/nuxt.config.ts
CHANGED
|
@@ -176,6 +176,28 @@ export default defineNuxtConfig({
|
|
|
176
176
|
},
|
|
177
177
|
|
|
178
178
|
hooks: {
|
|
179
|
+
/**
|
|
180
|
+
* Local Typesense maintenance (seed/drop/health), dev server only.
|
|
181
|
+
*
|
|
182
|
+
* They act on the local demo index without any auth, so they must not
|
|
183
|
+
* exist in a build: they live outside server/api and are only
|
|
184
|
+
* registered here when Nuxt runs in dev. A production build seeds via
|
|
185
|
+
* `pnpm typesense:seed` (scripts/seed-typesense.mjs) instead.
|
|
186
|
+
*/
|
|
187
|
+
"nitro:config": (nitroConfig) => {
|
|
188
|
+
if (!useNuxt().options.dev) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
nitroConfig.handlers = [
|
|
192
|
+
...(nitroConfig.handlers ?? []),
|
|
193
|
+
...["seed", "drop", "health"].map(name => ({
|
|
194
|
+
route: `/api/typesense/${name}`,
|
|
195
|
+
method: "get" as const,
|
|
196
|
+
handler: resolve(currentDir, `server/dev/typesense/${name}.ts`),
|
|
197
|
+
})),
|
|
198
|
+
];
|
|
199
|
+
},
|
|
200
|
+
|
|
179
201
|
/**
|
|
180
202
|
* Hand the consuming app's i18n routing strategy to the server.
|
|
181
203
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|