@revenexx/cover 0.22.0 → 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.
- package/app/api/categories.ts +1 -0
- package/app/api/offers.ts +1 -0
- package/app/app.config.ts +13 -0
- package/app/components/OgImage/CoverPage.takumi.vue +37 -0
- package/app/components/RevenexxForm.vue +21 -6
- package/app/components/account/approvals/AccountPendingApprovals.vue +19 -1
- package/app/components/account/approvals/AccountPendingOrderDetail.vue +3 -0
- package/app/components/account/carts/AccountCartsTable.vue +11 -1
- package/app/components/account/orderlists/AccountOrderListDetail.vue +32 -3
- package/app/components/account/organization/AccountOrganization.vue +1 -1
- package/app/components/auth/AuthForgotPasswordPanel.vue +7 -2
- package/app/components/auth/AuthLoginPanel.vue +23 -8
- package/app/components/auth/AuthRegisterTeaser.vue +1 -1
- package/app/components/cart/position/CartPosition.vue +11 -4
- package/app/components/cart/quickadd/CartQuickAdd.vue +4 -2
- package/app/components/cart/recommend/CartRecommendCard.vue +1 -0
- package/app/components/cart/switcher/CartSwitcher.vue +1 -0
- package/app/components/cart/view/CartListHeader.vue +5 -0
- package/app/components/cart/view/CartSummaryPanel.vue +7 -2
- package/app/components/cart/view/CartView.vue +4 -2
- package/app/components/checkout/onepage/CheckoutGate.vue +4 -2
- package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +2 -1
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +1 -1
- package/app/components/layout/header/LocaleSwitcher.vue +7 -9
- package/app/components/product/detail/ProductDetailAddToCart.vue +17 -11
- package/app/components/product/detail/ProductDetailImageGallery.vue +101 -8
- package/app/components/product/detail/ProductDetailVariantRow.vue +84 -4
- package/app/components/product/detail/ProductDetailVariants.vue +75 -11
- package/app/components/product/detail/ProductDetailView.vue +64 -69
- package/app/composables/useAuthStore.ts +21 -4
- package/app/composables/useCategories.ts +24 -0
- package/app/composables/useCategoryAnswer.ts +30 -0
- package/app/composables/useCategorySeo.ts +62 -0
- package/app/composables/useDefaultUiLanguage.ts +14 -0
- package/app/composables/useOgImageReady.ts +16 -0
- package/app/composables/useProductAnswer.ts +121 -0
- package/app/composables/useProductLocales.ts +21 -10
- package/app/composables/useProductSeo.ts +145 -0
- package/app/composables/useRouteSubject.ts +23 -3
- package/app/composables/useSeoContext.ts +164 -0
- package/app/composables/useSeoHead.ts +189 -0
- package/app/composables/useSeoRules.ts +23 -0
- package/app/interfaces/seo.ts +48 -0
- package/app/layouts/default.vue +2 -8
- package/app/layouts/focus.vue +3 -1
- package/app/payments/psp/novalnet.ts +25 -3
- package/app/payments/psp/novalnetStyle.ts +186 -0
- package/app/shared/categoryTree.ts +7 -0
- package/app/shared/locale.ts +8 -0
- package/app/shared/productLocales.ts +62 -1
- package/app/shared/seoRules.ts +297 -0
- package/app/shared/structuredData.ts +104 -0
- package/i18n/locales/de/account.json +4 -0
- package/i18n/locales/de/common.json +6 -0
- package/i18n/locales/de/pages.json +109 -0
- package/i18n/locales/en/account.json +4 -0
- package/i18n/locales/en/common.json +6 -0
- package/i18n/locales/en/pages.json +109 -0
- package/nuxt.config.ts +140 -1
- package/package.json +10 -3
- package/server/api/auth/otp.post.ts +4 -8
- package/server/api/auth/otp.put.ts +20 -11
- package/server/api/categories/[slug]/exists.get.ts +28 -0
- package/server/api/offers/guest.get.ts +53 -0
- package/server/api/orders/index.post.ts +1 -11
- package/server/api/payment/methods.post.ts +2 -33
- package/server/api/product/[id]/locales.get.ts +9 -3
- package/server/data/product-detail.json +0 -20
- package/server/dev/errorHandler.ts +9 -5
- package/server/dev/typesense/autoSeed.ts +63 -0
- package/server/dev/typesense/seed.ts +4 -43
- package/server/dev/typesense/seedProducts.ts +87 -0
- package/server/interfaces/category.ts +5 -0
- package/server/interfaces/product.ts +13 -6
- package/server/middleware/missing-media.ts +2 -2
- package/server/plugins/previewHostNoindex.ts +21 -0
- package/server/plugins/seoSiteConfig.ts +62 -0
- package/server/routes/robots.txt.ts +21 -0
- package/server/services/ApiCategoryService.ts +6 -0
- package/server/services/ApiProductService.ts +2 -2
- package/server/services/LocalFileCategoryService.ts +6 -0
- package/server/utils/liveCatalog.ts +83 -18
- package/server/utils/livePrices.ts +12 -3
- package/server/utils/locale.ts +3 -8
- package/server/utils/offerService.ts +8 -3
- package/server/utils/paymentOptions.ts +49 -0
- package/server/utils/promotionsService.ts +25 -0
- package/server/utils/revenexxSdk.ts +7 -1
- package/server/utils/seoRequestHost.ts +21 -0
- package/server/utils/storefrontMessages.ts +5 -5
- package/server/utils/storefrontSeoRules.ts +298 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { SeoRules } from "../../app/interfaces/seo";
|
|
4
|
+
import { defaultSeoRules } from "../../app/shared/seoRules";
|
|
5
|
+
import { gatewayEndpoint, gatewayHeaders } from "./storefrontMessages";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The domain's SEO rules from the seo service (PE-1235):
|
|
9
|
+
*
|
|
10
|
+
* GET {revenexxApiUrl}/v1/seo/storefront/rules?host=<host>
|
|
11
|
+
* Authorization: Bearer <brokered tenant JWT> X-Revenexx-Tenant: <slug>
|
|
12
|
+
* If-None-Match: "<etag held>"
|
|
13
|
+
* → 200 { data: <bundle> } with Cache-Control: max-age | 304
|
|
14
|
+
*
|
|
15
|
+
* One bundle per host, applied per request (canonical, robots, hreflang, title
|
|
16
|
+
* patterns). Per tenant AND host, because one build serves many tenants and a
|
|
17
|
+
* tenant many domains.
|
|
18
|
+
*
|
|
19
|
+
* The read never decides whether the shop renders: it is bounded by a 300 ms
|
|
20
|
+
* timeout, asked again only after the bundle's max-age, and fails OPEN to the
|
|
21
|
+
* last bundle held, or to the service's own defaults. Same stance as
|
|
22
|
+
* ./storefrontMessages.ts.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Used when the answer names no max-age. The service sends 30 s. */
|
|
26
|
+
const SEO_RULES_TTL_MS = 30_000;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The shortest a bundle is held, whatever max-age says: `max-age=0` would
|
|
30
|
+
* otherwise put a call to the seo service in front of every request.
|
|
31
|
+
*/
|
|
32
|
+
const SEO_RULES_MIN_TTL_MS = 5_000;
|
|
33
|
+
|
|
34
|
+
/** A rules read that has not answered by then is not waited for. */
|
|
35
|
+
const SEO_RULES_TIMEOUT_MS = 300;
|
|
36
|
+
|
|
37
|
+
/** The host arrives with the request, so the map must not grow with whatever a client sends. */
|
|
38
|
+
const MAX_ENTRIES = 1_000;
|
|
39
|
+
|
|
40
|
+
/* ------------------------------------------------------------------ */
|
|
41
|
+
/* Transport */
|
|
42
|
+
/* ------------------------------------------------------------------ */
|
|
43
|
+
|
|
44
|
+
export interface SeoRulesRequest {
|
|
45
|
+
/** Gateway base URL, e.g. https://api.revenexx.com */
|
|
46
|
+
readonly endpoint: string;
|
|
47
|
+
/** Tenant + auth headers, as the SDK would send them. */
|
|
48
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
49
|
+
readonly host: string;
|
|
50
|
+
/** ETag of the bundle already held. */
|
|
51
|
+
readonly etag?: string;
|
|
52
|
+
readonly timeoutMs?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type SeoRulesAnswer =
|
|
56
|
+
| { readonly status: "fresh"; readonly rules: SeoRules; readonly etag: string; readonly maxAgeMs: number | null }
|
|
57
|
+
| { readonly status: "unchanged"; readonly maxAgeMs: number | null };
|
|
58
|
+
|
|
59
|
+
function maxAgeOf(response: Response): number | null {
|
|
60
|
+
const match = /max-age=(\d+)/.exec(response.headers.get("cache-control") ?? "");
|
|
61
|
+
return match ? Number(match[1]) * 1_000 : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
65
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isStringList(value: unknown): value is string[] {
|
|
69
|
+
return Array.isArray(value) && value.every(item => typeof item === "string");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isStringOrNull(value: unknown): value is string | null {
|
|
73
|
+
return value === null || typeof value === "string";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Every part of the bundle the storefront reads, with the type it reads it
|
|
78
|
+
* as. A bundle that passes is dereferenced during rendering without further
|
|
79
|
+
* checks, so anything less is not a bundle: the cache then fails open to
|
|
80
|
+
* what it holds or to the defaults, rather than a page failing on it.
|
|
81
|
+
*/
|
|
82
|
+
function isSeoRules(value: unknown): value is SeoRules {
|
|
83
|
+
if (!isRecord(value) || typeof value.host !== "string" || typeof value.site_name !== "string") {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const { canonical, hreflang, max_length: maxLength, page_types: pageTypes, organisation } = value;
|
|
87
|
+
return isRecord(canonical)
|
|
88
|
+
&& isStringOrNull(canonical.host)
|
|
89
|
+
&& isStringList(canonical.cross_domain_page_types)
|
|
90
|
+
&& isStringList(canonical.strip_params)
|
|
91
|
+
&& isRecord(hreflang)
|
|
92
|
+
&& isStringOrNull(hreflang.x_default)
|
|
93
|
+
&& (hreflang.locales === null || isStringList(hreflang.locales))
|
|
94
|
+
&& isRecord(maxLength)
|
|
95
|
+
&& typeof maxLength.title === "number"
|
|
96
|
+
&& typeof maxLength.description === "number"
|
|
97
|
+
&& isRecord(pageTypes)
|
|
98
|
+
&& Object.values(pageTypes).every(type => isRecord(type)
|
|
99
|
+
&& typeof type.robots === "string"
|
|
100
|
+
&& (type.title === undefined || typeof type.title === "string")
|
|
101
|
+
&& (type.description === undefined || isStringOrNull(type.description)))
|
|
102
|
+
&& (organisation === null || (isRecord(organisation)
|
|
103
|
+
&& typeof organisation.name === "string"
|
|
104
|
+
&& isStringOrNull(organisation.logo)
|
|
105
|
+
&& isStringList(organisation.same_as)))
|
|
106
|
+
&& isRecord(value.structured_data)
|
|
107
|
+
&& typeof value.structured_data.prices === "boolean";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** One read of one host's bundle. Throws on anything but 200/304 or a bundle it cannot read. */
|
|
111
|
+
export async function fetchSeoRules(request: SeoRulesRequest): Promise<SeoRulesAnswer> {
|
|
112
|
+
const url = new URL(`${request.endpoint.replace(/\/+$/, "")}/v1/seo/storefront/rules`);
|
|
113
|
+
url.searchParams.set("host", request.host);
|
|
114
|
+
|
|
115
|
+
const headers: Record<string, string> = { Accept: "application/json", ...request.headers };
|
|
116
|
+
if (request.etag) {
|
|
117
|
+
headers["If-None-Match"] = request.etag;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const response = await fetch(url, {
|
|
121
|
+
headers,
|
|
122
|
+
signal: AbortSignal.timeout(request.timeoutMs ?? SEO_RULES_TIMEOUT_MS),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (response.status === 304) {
|
|
126
|
+
return { status: "unchanged", maxAgeMs: maxAgeOf(response) };
|
|
127
|
+
}
|
|
128
|
+
if (!response.ok) {
|
|
129
|
+
throw new Error(`seo/storefront/rules answered ${response.status}`);
|
|
130
|
+
}
|
|
131
|
+
const body = await response.json() as { data?: unknown } | null;
|
|
132
|
+
if (!isSeoRules(body?.data)) {
|
|
133
|
+
throw new Error("seo/storefront/rules answered no bundle");
|
|
134
|
+
}
|
|
135
|
+
return { status: "fresh", rules: body.data, etag: response.headers.get("etag") ?? "", maxAgeMs: maxAgeOf(response) };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* ------------------------------------------------------------------ */
|
|
139
|
+
/* Cache */
|
|
140
|
+
/* ------------------------------------------------------------------ */
|
|
141
|
+
|
|
142
|
+
export interface SeoRulesKey {
|
|
143
|
+
readonly tenant: string;
|
|
144
|
+
readonly host: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
type AuthHeaders = Readonly<Record<string, string>>;
|
|
148
|
+
|
|
149
|
+
export interface SeoRulesCacheOptions {
|
|
150
|
+
/** Reads one bundle; `etag` is what is held, `auth` the headers of the request that asked. */
|
|
151
|
+
readonly load: (key: SeoRulesKey, etag: string, auth: AuthHeaders) => Promise<SeoRulesAnswer>;
|
|
152
|
+
readonly ttlMs?: number;
|
|
153
|
+
readonly maxEntries?: number;
|
|
154
|
+
readonly now?: () => number;
|
|
155
|
+
readonly onError?: (err: unknown, key: SeoRulesKey) => void;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface Entry {
|
|
159
|
+
rules: SeoRules;
|
|
160
|
+
etag: string;
|
|
161
|
+
expiresAt: number;
|
|
162
|
+
/**
|
|
163
|
+
* Defaults rather than a real domain's bundle: held because no bundle was
|
|
164
|
+
* ever read for this host, or read for a host the service does not know.
|
|
165
|
+
*/
|
|
166
|
+
fallback: boolean;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface SeoRulesCache {
|
|
170
|
+
read: (key: SeoRulesKey, auth?: AuthHeaders) => Promise<SeoRules>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Bundles held in this process, partitioned by tenant + host. Pure — the
|
|
175
|
+
* loader and the clock are injected — so the refresh and fail-open rules are
|
|
176
|
+
* tested without a server.
|
|
177
|
+
*/
|
|
178
|
+
export function createSeoRulesCache(options: SeoRulesCacheOptions): SeoRulesCache {
|
|
179
|
+
const fallbackTtl = options.ttlMs ?? SEO_RULES_TTL_MS;
|
|
180
|
+
const maxEntries = options.maxEntries ?? MAX_ENTRIES;
|
|
181
|
+
const now = options.now ?? Date.now;
|
|
182
|
+
const entries = new Map<string, Entry>();
|
|
183
|
+
/** A burst of requests for one host makes one read, not one each. */
|
|
184
|
+
const inFlight = new Map<string, Promise<SeoRules>>();
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* When the map is full, a host without a real bundle goes first: the host
|
|
188
|
+
* comes with the request, so a client sending made-up hosts fills the map
|
|
189
|
+
* with fallbacks, and those must not push out the real domains' bundles.
|
|
190
|
+
* The service answers a made-up host with its defaults and `known: false`,
|
|
191
|
+
* so that bundle counts as a fallback too.
|
|
192
|
+
*/
|
|
193
|
+
function remember(id: string, entry: Entry): void {
|
|
194
|
+
entries.delete(id);
|
|
195
|
+
entries.set(id, entry);
|
|
196
|
+
while (entries.size > maxEntries) {
|
|
197
|
+
let victim: string | undefined;
|
|
198
|
+
for (const [key, held] of entries) {
|
|
199
|
+
if (held.fallback) {
|
|
200
|
+
victim = key;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
victim ??= entries.keys().next().value;
|
|
205
|
+
if (victim === undefined) {
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
entries.delete(victim);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const expiry = (maxAgeMs: number | null): number => now() + Math.max(maxAgeMs ?? fallbackTtl, SEO_RULES_MIN_TTL_MS);
|
|
213
|
+
|
|
214
|
+
async function refresh(id: string, key: SeoRulesKey, auth: AuthHeaders, held: Entry | undefined): Promise<SeoRules> {
|
|
215
|
+
try {
|
|
216
|
+
const answer = await options.load(key, held?.etag ?? "", auth);
|
|
217
|
+
const expiresAt = expiry(answer.maxAgeMs);
|
|
218
|
+
if (answer.status === "unchanged") {
|
|
219
|
+
const rules = held?.rules ?? defaultSeoRules(key.host);
|
|
220
|
+
remember(id, { rules, etag: held?.etag ?? "", expiresAt, fallback: held?.fallback ?? true });
|
|
221
|
+
return rules;
|
|
222
|
+
}
|
|
223
|
+
remember(id, { rules: answer.rules, etag: answer.etag, expiresAt, fallback: answer.rules.known === false });
|
|
224
|
+
return answer.rules;
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
options.onError?.(err, key);
|
|
228
|
+
// Fail open: keep what was held — or the service's defaults — and wait
|
|
229
|
+
// out the window before asking again, so an unreachable service is not
|
|
230
|
+
// asked on every page view.
|
|
231
|
+
const rules = held?.rules ?? defaultSeoRules(key.host);
|
|
232
|
+
remember(id, { rules, etag: held?.etag ?? "", expiresAt: now() + fallbackTtl, fallback: held?.fallback ?? true });
|
|
233
|
+
return rules;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
async read(key, auth = {}) {
|
|
239
|
+
const id = `${key.tenant}\u0000${key.host}`;
|
|
240
|
+
const held = entries.get(id);
|
|
241
|
+
if (held && now() < held.expiresAt) {
|
|
242
|
+
return held.rules;
|
|
243
|
+
}
|
|
244
|
+
let pending = inFlight.get(id);
|
|
245
|
+
if (!pending) {
|
|
246
|
+
pending = refresh(id, key, auth, held).finally(() => inFlight.delete(id));
|
|
247
|
+
inFlight.set(id, pending);
|
|
248
|
+
}
|
|
249
|
+
return await pending;
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* ------------------------------------------------------------------ */
|
|
255
|
+
/* The request's rules */
|
|
256
|
+
/* ------------------------------------------------------------------ */
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Registry key, like every other BFF domain: "mock" (the layer default — the
|
|
260
|
+
* service's defaults for the request's host, no call) or "api" (the seo
|
|
261
|
+
* service through the gateway).
|
|
262
|
+
*/
|
|
263
|
+
function isSeoRulesLive(event?: H3Event): boolean {
|
|
264
|
+
return resolveServiceKey(event, {
|
|
265
|
+
domain: "seoService",
|
|
266
|
+
mockKey: "mock",
|
|
267
|
+
liveKey: "api",
|
|
268
|
+
}) === "api";
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let processCache: SeoRulesCache | undefined;
|
|
272
|
+
let warnedUnconfigured = false;
|
|
273
|
+
|
|
274
|
+
function seoRulesCache(): SeoRulesCache {
|
|
275
|
+
processCache ??= createSeoRulesCache({
|
|
276
|
+
load: (key, etag, auth) => fetchSeoRules({ endpoint: gatewayEndpoint(), headers: auth, host: key.host, etag }),
|
|
277
|
+
onError: (err, key) => getLogService().warn(`SEO rules unavailable for ${key.host}`, apiErrorContext(err)),
|
|
278
|
+
});
|
|
279
|
+
return processCache;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The rules for the domain this request was made on. */
|
|
283
|
+
export async function readStorefrontSeoRules(event: H3Event, host: string): Promise<SeoRules> {
|
|
284
|
+
if (!isSeoRulesLive(event)) {
|
|
285
|
+
return defaultSeoRules(host);
|
|
286
|
+
}
|
|
287
|
+
const auth = gatewayHeaders(event);
|
|
288
|
+
if (!auth) {
|
|
289
|
+
// Switched to the seo service but nothing to ask it with: say so once,
|
|
290
|
+
// or the defaults look like a domain nobody configured.
|
|
291
|
+
if (!warnedUnconfigured) {
|
|
292
|
+
warnedUnconfigured = true;
|
|
293
|
+
getLogService().warn("SEO rules: seoService is \"api\" but no tenant credentials are set; serving the defaults");
|
|
294
|
+
}
|
|
295
|
+
return defaultSeoRules(host);
|
|
296
|
+
}
|
|
297
|
+
return await seoRulesCache().read({ tenant: auth["X-Revenexx-Tenant"] ?? "", host }, auth);
|
|
298
|
+
}
|