@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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a category URL names a category the catalogue has (PE-1236): the
|
|
3
|
+
* category page and a removed product's 301 ask before they answer. Not a
|
|
4
|
+
* 404 for a missing one, so the caller can tell "no such category" from a
|
|
5
|
+
* catalogue that could not be read (a 5xx).
|
|
6
|
+
*
|
|
7
|
+
* `?subcategory=` names the second URL segment, which must lie below the
|
|
8
|
+
* category.
|
|
9
|
+
*/
|
|
10
|
+
export default defineEventHandler(async (event): Promise<{ exists: boolean }> => {
|
|
11
|
+
// The client encodes the slug (categoriesApi.exists); h3 decodes a route
|
|
12
|
+
// param only when asked, and `küche` must not arrive as `k%C3%BCche`.
|
|
13
|
+
const slug = getRouterParam(event, "slug", { decode: true });
|
|
14
|
+
if (!slug) {
|
|
15
|
+
throw createError({ status: 400, message: "Missing slug" });
|
|
16
|
+
}
|
|
17
|
+
const { subcategory } = getQuery(event);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const exists = await getCategoryService(event)
|
|
21
|
+
.hasCategory(slug, typeof subcategory === "string" && subcategory ? subcategory : undefined);
|
|
22
|
+
return { exists };
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
getLogService().error("Service error: categories/exists", { slug, ...toErrorContext(err) });
|
|
26
|
+
throw createError({ statusCode: 500, message: "Internal server error" });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Offer } from "../../interfaces/offer";
|
|
2
|
+
|
|
3
|
+
/** What the structured data reads of an offer; stock records stay out of the page payload. */
|
|
4
|
+
type GuestOffer = Pick<Offer, "prices" | "isOutOfStock">;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How long a product page's render waits for the public price. The offer is an
|
|
8
|
+
* ERP-grade call the buyer-facing page never waits for; the structured data
|
|
9
|
+
* (PE-1103) has to, so it gets a budget and goes without a price beyond it.
|
|
10
|
+
*/
|
|
11
|
+
const GUEST_OFFER_TIMEOUT_MS = 300;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The offer a guest gets for one product — what the product's structured data
|
|
15
|
+
* publishes (PE-1103, K4): the price the prices app answers for nobody, never
|
|
16
|
+
* the signed-in buyer's own. `offer` is null when it took too long or failed,
|
|
17
|
+
* which the page renders as a product without a price, like "on request".
|
|
18
|
+
* Only the prices and whether it is out of stock: the answer ends up in every
|
|
19
|
+
* product page's payload.
|
|
20
|
+
*/
|
|
21
|
+
export default defineEventHandler(async (event): Promise<{ offer: GuestOffer | null }> => {
|
|
22
|
+
const query = getQuery(event);
|
|
23
|
+
const id = typeof query.id === "string" ? query.id : "";
|
|
24
|
+
const sku = typeof query.sku === "string" && query.sku ? query.sku : undefined;
|
|
25
|
+
if (!id) {
|
|
26
|
+
throw createError({ statusCode: 400, statusMessage: "id is required" });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
30
|
+
const late = new Promise<"late">((resolve) => {
|
|
31
|
+
timer = setTimeout(() => resolve("late"), GUEST_OFFER_TIMEOUT_MS);
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
const offer = await Promise.race([
|
|
35
|
+
getOffers(event, [{ id, ...(sku ? { sku } : {}) }], { guest: true }).then(offers => offers.get(id) ?? null),
|
|
36
|
+
late,
|
|
37
|
+
]);
|
|
38
|
+
if (offer === "late") {
|
|
39
|
+
// Not an error, but not "no price" either: a product page without
|
|
40
|
+
// its offer in the structured data, which only shows here.
|
|
41
|
+
getLogService().warn("Guest offer: no answer within the budget", { id, budgetMs: GUEST_OFFER_TIMEOUT_MS });
|
|
42
|
+
return { offer: null };
|
|
43
|
+
}
|
|
44
|
+
return { offer: offer ? { prices: offer.prices, isOutOfStock: offer.isOutOfStock } : null };
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
getLogService().error("Service error: guest offer", toErrorContext(err));
|
|
48
|
+
return { offer: null };
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
@@ -346,17 +346,7 @@ export default defineEventHandler(async (event) => {
|
|
|
346
346
|
tax_rate: linePrices[index]!.taxRate,
|
|
347
347
|
})),
|
|
348
348
|
});
|
|
349
|
-
let discounts = (promo?.applied ?? [])
|
|
350
|
-
promotion_id: a.promotion_id,
|
|
351
|
-
promotion_name: a.promotion_name,
|
|
352
|
-
...(a.voucher_code ? { voucher_code: a.voucher_code } : {}),
|
|
353
|
-
...(a.value_type ? { value_type: a.value_type } : {}),
|
|
354
|
-
...(a.percent != null ? { percent: a.percent } : {}),
|
|
355
|
-
...(a.line_position != null
|
|
356
|
-
? { placement: "line" as const, line_position: a.line_position }
|
|
357
|
-
: { placement: "head" as const }),
|
|
358
|
-
amount: a.amount,
|
|
359
|
-
}));
|
|
349
|
+
let discounts = orderDiscounts(promo?.applied ?? []);
|
|
360
350
|
|
|
361
351
|
// The cart this order came out of. The promotions app keys its
|
|
362
352
|
// redemption ledger on it, so without it a reservation has
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import type { PaymentOption } from "../../../app/interfaces/payment";
|
|
2
2
|
import type { Locale } from "../../utils/locale";
|
|
3
|
-
import { type
|
|
4
|
-
|
|
5
|
-
/** Eligible method row of the payments app. */
|
|
6
|
-
interface ApiEligibleMethod {
|
|
7
|
-
code: string;
|
|
8
|
-
name: string;
|
|
9
|
-
labels: Record<string, string> | null;
|
|
10
|
-
description: string | null;
|
|
11
|
-
kind: string;
|
|
12
|
-
provider: string | null;
|
|
13
|
-
fee: number;
|
|
14
|
-
fee_type: "none" | "fixed" | "percent";
|
|
15
|
-
currency: string;
|
|
16
|
-
position: number;
|
|
17
|
-
/** How a PSP method takes the instrument (RAD-364); null for self-managed ones. */
|
|
18
|
-
checkout?: ApiMethodCheckout | null;
|
|
19
|
-
}
|
|
3
|
+
import { type ApiEligibleMethod, paymentOptionOf } from "../../utils/paymentOptions";
|
|
20
4
|
|
|
21
5
|
/**
|
|
22
6
|
* The checkout's payment question — "what can THIS buyer pay with?".
|
|
@@ -47,22 +31,7 @@ export default defineEventHandler(async (event) => {
|
|
|
47
31
|
currency,
|
|
48
32
|
}) as unknown as { methods: ApiEligibleMethod[] };
|
|
49
33
|
|
|
50
|
-
const options: PaymentOption[] = methods.map(
|
|
51
|
-
const checkout = paymentCheckoutOf(m.checkout);
|
|
52
|
-
// The checkout block names the provider the payment would actually go
|
|
53
|
-
// to (method → default → fallback provider); it wins over the row's.
|
|
54
|
-
const provider = checkout?.provider ?? m.provider;
|
|
55
|
-
return {
|
|
56
|
-
method: m.code,
|
|
57
|
-
label: m.labels?.[locale] ?? m.name,
|
|
58
|
-
...(m.description ? { description: m.description } : {}),
|
|
59
|
-
fee: m.fee,
|
|
60
|
-
feeType: m.fee_type,
|
|
61
|
-
kind: m.kind,
|
|
62
|
-
...(provider ? { provider } : {}),
|
|
63
|
-
...(checkout ? { checkout } : {}),
|
|
64
|
-
};
|
|
65
|
-
});
|
|
34
|
+
const options: PaymentOption[] = methods.map(m => paymentOptionOf(m, locale));
|
|
66
35
|
|
|
67
36
|
return {
|
|
68
37
|
managed: true,
|
|
@@ -8,6 +8,11 @@ export interface ProductLocalesResponse {
|
|
|
8
8
|
* on any other page.
|
|
9
9
|
*/
|
|
10
10
|
locales: string[] | null;
|
|
11
|
+
/**
|
|
12
|
+
* The product's name in each of `locales`, for the slug of a link into
|
|
13
|
+
* that language (PE-1236); `null` when the names are not known.
|
|
14
|
+
*/
|
|
15
|
+
names: Record<string, string> | null;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
/** A locale code as the storefront writes it (`de`, `en-US`). */
|
|
@@ -44,14 +49,15 @@ export default defineEventHandler(async (event): Promise<ProductLocalesResponse>
|
|
|
44
49
|
|
|
45
50
|
const service = getProductService(event);
|
|
46
51
|
if (!service.getProductLanguages) {
|
|
47
|
-
return { locales: null };
|
|
52
|
+
return { locales: null, names: null };
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
try {
|
|
51
|
-
|
|
56
|
+
const { languages, names } = await service.getProductLanguages(id, requested);
|
|
57
|
+
return { locales: languages, names };
|
|
52
58
|
}
|
|
53
59
|
catch (err) {
|
|
54
60
|
getLogService().warn("Product locales lookup failed", { id, ...toErrorContext(err) });
|
|
55
|
-
return { locales: null };
|
|
61
|
+
return { locales: null, names: null };
|
|
56
62
|
}
|
|
57
63
|
});
|
|
@@ -2174,11 +2174,6 @@
|
|
|
2174
2174
|
"type": "main",
|
|
2175
2175
|
"priority": 1,
|
|
2176
2176
|
"url": "6984-1.png"
|
|
2177
|
-
},
|
|
2178
|
-
{
|
|
2179
|
-
"type": "main",
|
|
2180
|
-
"priority": 2,
|
|
2181
|
-
"url": "6984-2.png"
|
|
2182
2177
|
}
|
|
2183
2178
|
],
|
|
2184
2179
|
"attributes": [
|
|
@@ -2284,11 +2279,6 @@
|
|
|
2284
2279
|
"type": "main",
|
|
2285
2280
|
"priority": 1,
|
|
2286
2281
|
"url": "6985-1.png"
|
|
2287
|
-
},
|
|
2288
|
-
{
|
|
2289
|
-
"type": "main",
|
|
2290
|
-
"priority": 2,
|
|
2291
|
-
"url": "6985-2.png"
|
|
2292
2282
|
}
|
|
2293
2283
|
],
|
|
2294
2284
|
"attributes": [
|
|
@@ -2393,16 +2383,6 @@
|
|
|
2393
2383
|
"type": "main",
|
|
2394
2384
|
"priority": 1,
|
|
2395
2385
|
"url": "6986-1.png"
|
|
2396
|
-
},
|
|
2397
|
-
{
|
|
2398
|
-
"type": "main",
|
|
2399
|
-
"priority": 2,
|
|
2400
|
-
"url": "6986-2.png"
|
|
2401
|
-
},
|
|
2402
|
-
{
|
|
2403
|
-
"type": "main",
|
|
2404
|
-
"priority": 3,
|
|
2405
|
-
"url": "6986-3.png"
|
|
2406
2386
|
}
|
|
2407
2387
|
],
|
|
2408
2388
|
"attributes": [
|
|
@@ -12,9 +12,13 @@ import { getRequestHeader, send, setResponseHeader, setResponseStatus } from "h3
|
|
|
12
12
|
* is also the point where the parser starts failing with `unreachable`).
|
|
13
13
|
*
|
|
14
14
|
* So no error is run through the source maps. Client errors are answered with
|
|
15
|
-
*
|
|
16
|
-
* JSON body, which is what Nitro's default handler
|
|
17
|
-
* source-mapped code frame.
|
|
15
|
+
* their status, message and `data`; server errors (5xx) also keep their raw
|
|
16
|
+
* stack in the log and in the JSON body, which is what Nitro's default handler
|
|
17
|
+
* would print minus the source-mapped code frame.
|
|
18
|
+
*
|
|
19
|
+
* `data` must survive: the client tells errors apart by it (`data.type` maps a
|
|
20
|
+
* failed sign-in to "wrong password", `data.message` explains a refused
|
|
21
|
+
* approval). Dropping it turned every such error into a generic one in dev.
|
|
18
22
|
*/
|
|
19
23
|
const handler: NitroErrorHandler = async function devErrorHandler(error, event) {
|
|
20
24
|
const statusCode = error.statusCode || 500;
|
|
@@ -30,7 +34,7 @@ const handler: NitroErrorHandler = async function devErrorHandler(error, event)
|
|
|
30
34
|
event,
|
|
31
35
|
wantsHtml
|
|
32
36
|
? `<!doctype html><title>${statusCode} ${statusMessage}</title><h1>${statusCode} ${statusMessage}</h1>`
|
|
33
|
-
: JSON.stringify({ error: true, statusCode, statusMessage }),
|
|
37
|
+
: JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, data: error.data }),
|
|
34
38
|
);
|
|
35
39
|
}
|
|
36
40
|
|
|
@@ -40,7 +44,7 @@ const handler: NitroErrorHandler = async function devErrorHandler(error, event)
|
|
|
40
44
|
event,
|
|
41
45
|
wantsHtml
|
|
42
46
|
? `<!doctype html><title>${statusCode} ${statusMessage}</title><h1>${statusCode} ${statusMessage}</h1><pre>${(error.stack ?? error.message).replace(/</g, "<")}</pre>`
|
|
43
|
-
: JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, stack }, null, 2),
|
|
47
|
+
: JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, data: error.data, stack }, null, 2),
|
|
44
48
|
);
|
|
45
49
|
};
|
|
46
50
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { dropProductsCollection, productsDocumentCount, seedProductsCollection } from "./seedProducts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Seeds the local Typesense index when the dev server starts and the
|
|
5
|
+
* `products` collection is missing — dev server only (registered in the
|
|
6
|
+
* layer's nuxt.config).
|
|
7
|
+
*
|
|
8
|
+
* Category pages and search read every product from that index, so a fresh
|
|
9
|
+
* or reset `typesense-data` volume left the demo shop without products until
|
|
10
|
+
* someone called GET /api/typesense/seed by hand. A collection that holds
|
|
11
|
+
* documents is never touched, so a re-seeded or inflated index survives
|
|
12
|
+
* restarts. An EMPTY one counts as missing: it is what a seed that failed
|
|
13
|
+
* halfway leaves behind (the import timed out, or the server stopped between
|
|
14
|
+
* creating the collection and filling it), and it would otherwise keep the
|
|
15
|
+
* shop empty across every later restart.
|
|
16
|
+
*
|
|
17
|
+
* Typesense may still be starting when Nuxt is up (both start together in
|
|
18
|
+
* docker-compose.dev.yml), so the check is retried for a while. Startup is
|
|
19
|
+
* never blocked or failed by it. Set NUXT_TYPESENSE_AUTO_SEED=false to turn
|
|
20
|
+
* it off, e.g. when the dev server points at a shared Typesense.
|
|
21
|
+
*/
|
|
22
|
+
const MAX_ATTEMPTS = 10;
|
|
23
|
+
const RETRY_DELAY_MS = 3000;
|
|
24
|
+
|
|
25
|
+
async function seedWhenMissing(): Promise<void> {
|
|
26
|
+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
27
|
+
try {
|
|
28
|
+
const count = await productsDocumentCount();
|
|
29
|
+
if (count !== null && count > 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (count === 0) {
|
|
33
|
+
await dropProductsCollection();
|
|
34
|
+
}
|
|
35
|
+
const result = await seedProductsCollection(0);
|
|
36
|
+
if (result.indexed === 0) {
|
|
37
|
+
// Every document failed: the collection is empty again, which the
|
|
38
|
+
// next attempt drops and seeds anew.
|
|
39
|
+
throw new Error(`Typesense import indexed none of ${result.total} documents`);
|
|
40
|
+
}
|
|
41
|
+
getLogService().warn(`Typesense: products collection was ${count === 0 ? "empty" : "missing"}, seeded the demo catalogue`, {
|
|
42
|
+
indexed: result.indexed,
|
|
43
|
+
failed: result.failed,
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (attempt === MAX_ATTEMPTS) {
|
|
49
|
+
getLogService().warn("Typesense: auto-seed gave up, call GET /api/typesense/seed once Typesense is up", toErrorContext(err));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default defineNitroPlugin(() => {
|
|
58
|
+
if (!import.meta.dev || useRuntimeConfig().typesenseAutoSeed === false) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Fire and forget on purpose: seeding must not delay or fail startup.
|
|
62
|
+
void seedWhenMissing();
|
|
63
|
+
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PRODUCTS_COLLECTION, productsSchema } from "../../utils/productsSchema";
|
|
3
|
-
import type { SeedEntry } from "./seedDocuments";
|
|
4
|
-
import { buildSeedDocuments } from "./seedDocuments";
|
|
1
|
+
import { dropProductsCollection, seedProductsCollection } from "./seedProducts";
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* GET /api/typesense/seed — dev server only (registered in the layer's
|
|
@@ -12,48 +9,12 @@ export default defineEventHandler(async (event) => {
|
|
|
12
9
|
const query = getQuery(event);
|
|
13
10
|
const requestedCount = parseInt(String(query.count ?? "0"), 10);
|
|
14
11
|
|
|
15
|
-
const ts = useTypesense();
|
|
16
|
-
|
|
17
12
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (exists) {
|
|
21
|
-
await ts.collections(PRODUCTS_COLLECTION).delete();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
await ts.collections().create(productsSchema);
|
|
13
|
+
await dropProductsCollection();
|
|
14
|
+
return await seedProductsCollection(requestedCount);
|
|
25
15
|
}
|
|
26
16
|
catch (err) {
|
|
27
|
-
getLogService().error("Typesense error: seed
|
|
17
|
+
getLogService().error("Typesense error: seed", toErrorContext(err));
|
|
28
18
|
throw createError({ statusCode: 503, message: "Search service unavailable" });
|
|
29
19
|
}
|
|
30
|
-
|
|
31
|
-
const documents = buildSeedDocuments(productsData as SeedEntry[], requestedCount);
|
|
32
|
-
|
|
33
|
-
let result: { success: boolean; error?: string; document?: unknown }[] = [];
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
result = await ts.collections(PRODUCTS_COLLECTION).documents().import(
|
|
37
|
-
documents,
|
|
38
|
-
{ action: "upsert" },
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
catch (e: unknown) {
|
|
42
|
-
if (e && typeof e === "object" && "importResults" in e) {
|
|
43
|
-
result = (e as { importResults: typeof result }).importResults;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
getLogService().error("Typesense error: seed import", toErrorContext(e));
|
|
47
|
-
throw e;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const failed = result.filter(r => !r.success);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
total: documents.length,
|
|
55
|
-
indexed: documents.length - failed.length,
|
|
56
|
-
failed: failed.length,
|
|
57
|
-
errors: failed,
|
|
58
|
-
};
|
|
59
20
|
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import productsData from "../../data/product-list.json";
|
|
2
|
+
import { PRODUCTS_COLLECTION, productsSchema } from "../../utils/productsSchema";
|
|
3
|
+
import type { SeedEntry } from "./seedDocuments";
|
|
4
|
+
import { buildSeedDocuments } from "./seedDocuments";
|
|
5
|
+
|
|
6
|
+
export interface SeedResult {
|
|
7
|
+
readonly total: number;
|
|
8
|
+
readonly indexed: number;
|
|
9
|
+
readonly failed: number;
|
|
10
|
+
readonly errors: readonly ImportResult[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ImportResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
error?: string;
|
|
16
|
+
document?: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Whether the local index already has the `products` collection. */
|
|
20
|
+
export async function hasProductsCollection(): Promise<boolean> {
|
|
21
|
+
return (await productsDocumentCount()) !== null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How many documents the local `products` collection holds, or null where it
|
|
26
|
+
* does not exist. An empty collection is what a seed that failed halfway
|
|
27
|
+
* leaves behind, so callers that only seed a missing index must treat 0 like
|
|
28
|
+
* null.
|
|
29
|
+
*/
|
|
30
|
+
export async function productsDocumentCount(): Promise<number | null> {
|
|
31
|
+
const collections = await useTypesense().collections().retrieve();
|
|
32
|
+
const products = collections.find(c => c.name === PRODUCTS_COLLECTION);
|
|
33
|
+
return products ? products.num_documents : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Drops the local `products` collection; a missing one is not an error. */
|
|
37
|
+
export async function dropProductsCollection(): Promise<void> {
|
|
38
|
+
if (await hasProductsCollection()) {
|
|
39
|
+
await useTypesense().collections(PRODUCTS_COLLECTION).delete();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Creates the `products` collection and imports the demo catalogue into it.
|
|
45
|
+
* The collection must not exist yet. Shared by the dev seed route (which drops
|
|
46
|
+
* it first) and the dev startup plugin (which only runs when it is missing).
|
|
47
|
+
*
|
|
48
|
+
* The collection is created before the import, so an import that fails outright
|
|
49
|
+
* (a timeout while Typesense is still starting) would leave it empty — and an
|
|
50
|
+
* empty collection looks like a seeded one to everything that only checks for
|
|
51
|
+
* its existence. It is dropped again before the error goes on.
|
|
52
|
+
*/
|
|
53
|
+
export async function seedProductsCollection(requestedCount: number): Promise<SeedResult> {
|
|
54
|
+
const ts = useTypesense();
|
|
55
|
+
await ts.collections().create(productsSchema);
|
|
56
|
+
|
|
57
|
+
const documents = buildSeedDocuments(productsData as SeedEntry[], requestedCount);
|
|
58
|
+
|
|
59
|
+
let result: ImportResult[] = [];
|
|
60
|
+
try {
|
|
61
|
+
result = await ts.collections(PRODUCTS_COLLECTION).documents().import(
|
|
62
|
+
documents,
|
|
63
|
+
{ action: "upsert" },
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
catch (e: unknown) {
|
|
67
|
+
// A partial failure throws, but still carries the per-document results.
|
|
68
|
+
if (e && typeof e === "object" && "importResults" in e) {
|
|
69
|
+
result = (e as { importResults: ImportResult[] }).importResults;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
await dropProductsCollection().catch(() => {
|
|
73
|
+
// Typesense is unreachable: the next seed treats the empty
|
|
74
|
+
// collection as missing anyway.
|
|
75
|
+
});
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const failed = result.filter(r => !r.success);
|
|
81
|
+
return {
|
|
82
|
+
total: documents.length,
|
|
83
|
+
indexed: documents.length - failed.length,
|
|
84
|
+
failed: failed.length,
|
|
85
|
+
errors: failed,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -9,4 +9,9 @@ import type { Locale } from "../utils/locale";
|
|
|
9
9
|
export interface ICategoryService {
|
|
10
10
|
listCategories(locale?: Locale): Promise<ProductCategory[]>;
|
|
11
11
|
getCategoryBySlug(slug: string, locale?: Locale): Promise<ProductCategory | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a category URL names a category the catalogue has, and the
|
|
14
|
+
* subcategory below it when one is named (PE-1236: else a 404).
|
|
15
|
+
*/
|
|
16
|
+
hasCategory(slug: string, subcategory?: string): Promise<boolean>;
|
|
12
17
|
}
|
|
@@ -4,6 +4,12 @@ import type { ProductDetail } from "../../app/interfaces/product-detail";
|
|
|
4
4
|
import type { ProductVariants } from "../../app/interfaces/product-variants";
|
|
5
5
|
import type { Locale } from "../utils/locale";
|
|
6
6
|
|
|
7
|
+
/** The languages a product has a page in, and its name in each (for the slug). */
|
|
8
|
+
export interface ProductLanguages {
|
|
9
|
+
readonly languages: string[];
|
|
10
|
+
readonly names: Readonly<Record<string, string>>;
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
export interface ProductListFilter {
|
|
8
14
|
category?: string;
|
|
9
15
|
subcategory?: string;
|
|
@@ -38,11 +44,12 @@ export interface IProductService {
|
|
|
38
44
|
*/
|
|
39
45
|
getProductAssociations(id: string, locale?: Locale): Promise<ProductAssociations | null>;
|
|
40
46
|
/**
|
|
41
|
-
* The storefront languages (of `languages`) this product has a page in
|
|
42
|
-
* catalogue that hides untranslated products
|
|
43
|
-
* has none in a language the product is not
|
|
44
|
-
* service without it has the product in every
|
|
45
|
-
* storefront assumes when it is
|
|
47
|
+
* The storefront languages (of `languages`) this product has a page in,
|
|
48
|
+
* and its name in each. A catalogue that hides untranslated products
|
|
49
|
+
* (`search_untranslated=hide`) has none in a language the product is not
|
|
50
|
+
* translated into. Optional: a service without it has the product in every
|
|
51
|
+
* language under one name, which is what the storefront assumes when it is
|
|
52
|
+
* missing.
|
|
46
53
|
*/
|
|
47
|
-
getProductLanguages?(id: string, languages: readonly string[]): Promise<
|
|
54
|
+
getProductLanguages?(id: string, languages: readonly string[]): Promise<ProductLanguages>;
|
|
48
55
|
}
|
|
@@ -3,9 +3,9 @@ import { getMethod } from "h3";
|
|
|
3
3
|
/**
|
|
4
4
|
* Paths that own their own 404 handling, or that Vite serves in dev.
|
|
5
5
|
* `/_nuxt` and `/@` are the dev bundler's, `/api` and `/cdn` answer for
|
|
6
|
-
* themselves, `/_ipx` is @nuxt/image.
|
|
6
|
+
* themselves, `/_ipx` is @nuxt/image, `/_og` is nuxt-og-image (PE-1048).
|
|
7
7
|
*/
|
|
8
|
-
const OWN_NOT_FOUND = ["/api/", "/cdn/", "/_nuxt/", "/_ipx/", "/@", "/node_modules/"];
|
|
8
|
+
const OWN_NOT_FOUND = ["/api/", "/cdn/", "/_nuxt/", "/_ipx/", "/_og/", "/@", "/node_modules/"];
|
|
9
9
|
|
|
10
10
|
const MEDIA_EXTENSION = /\.(?:png|jpe?g|gif|webp|avif|svg|ico)$/i;
|
|
11
11
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { setResponseHeader } from "h3";
|
|
2
|
+
|
|
3
|
+
import { isPreviewHost } from "../../app/shared/seoRules";
|
|
4
|
+
import { seoRequestHost } from "../utils/seoRequestHost";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Nothing a preview host answers may be indexed (PE-1237): pages, but also
|
|
8
|
+
* images, PDFs and API answers, which carry no meta robots. Set before any
|
|
9
|
+
* handler runs, so static files get it too; a page's own robots rule sets the
|
|
10
|
+
* same value again (the site is not indexable there, see seoSiteConfig.ts).
|
|
11
|
+
*
|
|
12
|
+
* The host is the request's `Host` (seoRequestHost), so a cache keyed by host
|
|
13
|
+
* keeps a preview's `noindex` apart from the production domain.
|
|
14
|
+
*/
|
|
15
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
16
|
+
nitroApp.hooks.hook("request", (event) => {
|
|
17
|
+
if (isPreviewHost(seoRequestHost(event))) {
|
|
18
|
+
setResponseHeader(event, "X-Robots-Tag", "noindex, nofollow");
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import { isPreviewHost } from "../../app/shared/seoRules";
|
|
4
|
+
import { readStorefrontSeoRules } from "../utils/storefrontSeoRules";
|
|
5
|
+
import { seoRequestHost, seoRequestOrigin } from "../utils/seoRequestHost";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Nuxt SEO's site config per request, from the domain's seo rules (PE-1235).
|
|
9
|
+
*
|
|
10
|
+
* One build serves many tenants and domains (ADR-0062), so nothing about the
|
|
11
|
+
* site can be fixed at build time. nuxt-site-config keeps one config stack per
|
|
12
|
+
* request and calls `site-config:init` from Nitro's `request` hook — before any
|
|
13
|
+
* middleware or render reads it — and awaits it, so the rules can be read here.
|
|
14
|
+
* What this pushes wins over the build's config.
|
|
15
|
+
*
|
|
16
|
+
* The rules also go on `event.context.seoRules`, from where the app takes them
|
|
17
|
+
* into the payload (app/composables/useSeoRules.ts).
|
|
18
|
+
*
|
|
19
|
+
* The host is the request's `Host` (seoRequestHost), and the same host goes
|
|
20
|
+
* into the site's `url`, from which canonical, hreflang and `og:url` take
|
|
21
|
+
* their origin: nuxt-site-config would otherwise set it from
|
|
22
|
+
* `X-Forwarded-Host`, and a page would render the rules of one host under the
|
|
23
|
+
* URLs of another. Prerendering is the exception: there the host is the
|
|
24
|
+
* prerenderer's own (`localhost`), so the `url` stays the build's (`site.url` /
|
|
25
|
+
* `NUXT_PUBLIC_SITE_URL`), as nuxt-site-config does too.
|
|
26
|
+
*
|
|
27
|
+
* BFF calls and build assets render nothing and skip the read, so an expired
|
|
28
|
+
* bundle never holds them up. Everything else may render or read the site
|
|
29
|
+
* config: pages, robots, sitemaps, link previews and islands (`/__…`).
|
|
30
|
+
*/
|
|
31
|
+
const SKIPPED_PREFIXES: readonly string[] = ["/api/", "/_nuxt/"];
|
|
32
|
+
|
|
33
|
+
interface SiteConfigInit {
|
|
34
|
+
event: unknown;
|
|
35
|
+
siteConfig: { push: (input: Record<string, unknown>) => void };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The `site-config:init` handler; `prerender` keeps the request's host out of `url`. */
|
|
39
|
+
export function siteConfigFromRules({ prerender }: { prerender: boolean }) {
|
|
40
|
+
return async ({ event: siteEvent, siteConfig }: SiteConfigInit): Promise<void> => {
|
|
41
|
+
// Typed as the context alone; it is the request's H3 event.
|
|
42
|
+
const event = siteEvent as H3Event;
|
|
43
|
+
if (SKIPPED_PREFIXES.some(prefix => event.path.startsWith(prefix))) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const host = seoRequestHost(event);
|
|
47
|
+
const rules = await readStorefrontSeoRules(event, host);
|
|
48
|
+
event.context.seoRules = rules;
|
|
49
|
+
siteConfig.push({
|
|
50
|
+
_context: "cover:seo-rules",
|
|
51
|
+
name: rules.site_name,
|
|
52
|
+
...(prerender ? {} : { url: seoRequestOrigin(event) }),
|
|
53
|
+
// Only ever switches indexing off: whether a site is indexable at all
|
|
54
|
+
// stays with its environment (a dev server never is).
|
|
55
|
+
...(isPreviewHost(host) ? { indexable: false } : {}),
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
61
|
+
nitroApp.hooks.hook("site-config:init", siteConfigFromRules({ prerender: Boolean(import.meta.prerender) }));
|
|
62
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createError, setResponseHeader } from "h3";
|
|
2
|
+
|
|
3
|
+
import { isPreviewHost } from "../../app/shared/seoRules";
|
|
4
|
+
import { seoRequestHost } from "../utils/seoRequestHost";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* robots.txt of a preview host only (PE-1237): `<tenant>.theme.rvnxx.site`
|
|
8
|
+
* shows drafts and unreleased themes, so it shuts every crawler out.
|
|
9
|
+
*
|
|
10
|
+
* Every other host's robots.txt is the seo service's, which the edge serves
|
|
11
|
+
* (ADR-0116); this answers 404 there, as the shop did before — a theme that
|
|
12
|
+
* ships its own `public/robots.txt` is served before any route.
|
|
13
|
+
*/
|
|
14
|
+
export default defineEventHandler((event) => {
|
|
15
|
+
if (!isPreviewHost(seoRequestHost(event))) {
|
|
16
|
+
throw createError({ statusCode: 404, statusMessage: "Not Found" });
|
|
17
|
+
}
|
|
18
|
+
setResponseHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
19
|
+
setResponseHeader(event, "Cache-Control", "public, max-age=3600");
|
|
20
|
+
return "User-agent: *\nDisallow: /\n";
|
|
21
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ProductCategory } from "../../app/config/navigation";
|
|
2
2
|
import type { ICategoryService } from "../interfaces/category";
|
|
3
|
+
import { liveCategoryExists } from "../utils/liveCatalog";
|
|
3
4
|
import type { Locale } from "../utils/locale";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -22,4 +23,9 @@ export class ApiCategoryService implements ICategoryService {
|
|
|
22
23
|
const parent = categories.find(c => c.subcategories.some(s => s.slug === slug));
|
|
23
24
|
return parent ?? null;
|
|
24
25
|
}
|
|
26
|
+
|
|
27
|
+
/** Any code of the catalogue, at any depth; a subcategory anywhere below the category. */
|
|
28
|
+
async hasCategory(slug: string, subcategory?: string): Promise<boolean> {
|
|
29
|
+
return liveCategoryExists(slug, subcategory);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
@@ -4,7 +4,7 @@ import type { ProductDetail } from "../../app/interfaces/product-detail";
|
|
|
4
4
|
import type { ProductVariants } from "../../app/interfaces/product-variants";
|
|
5
5
|
import type { Locale } from "../utils/locale";
|
|
6
6
|
|
|
7
|
-
import type { IProductService, ProductListFilter } from "../interfaces/product";
|
|
7
|
+
import type { IProductService, ProductLanguages, ProductListFilter } from "../interfaces/product";
|
|
8
8
|
|
|
9
9
|
/** Listing cap for the stub — the live index holds tens of thousands of products. */
|
|
10
10
|
const LIST_PAGE_SIZE = 48;
|
|
@@ -74,7 +74,7 @@ export class ApiProductService implements IProductService {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
async getProductLanguages(id: string, languages: readonly string[]): Promise<
|
|
77
|
+
async getProductLanguages(id: string, languages: readonly string[]): Promise<ProductLanguages> {
|
|
78
78
|
return getLiveProductLanguages(id, languages);
|
|
79
79
|
}
|
|
80
80
|
|