@revenexx/cover 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +20 -8
- 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/checkout/onepage/CheckoutSummarySection.vue +8 -0
- package/app/components/checkout/return/CheckoutPaymentReturn.vue +7 -0
- package/app/components/layout/footer/Footer.vue +21 -4
- package/app/components/layout/header/AppBar.vue +5 -2
- package/app/components/layout/header/LocaleSwitcher.vue +7 -9
- package/app/components/layout/header/MobileMenu.vue +4 -1
- 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/components/punchout/action/PunchoutTransferAction.vue +4 -3
- 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/usePunchoutVisit.ts +36 -1
- 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/punchout.ts +11 -0
- package/app/interfaces/seo.ts +48 -0
- package/app/layouts/default.vue +2 -8
- package/app/layouts/focus.vue +3 -1
- package/app/middleware/punchout-exits.global.ts +25 -0
- package/app/payments/psp/novalnet.ts +25 -3
- package/app/payments/psp/novalnetStyle.ts +186 -0
- package/app/plugins/punchout-links.client.ts +46 -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/punchoutExits.ts +156 -0
- 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/de/punchout.json +3 -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/i18n/locales/en/punchout.json +3 -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 +18 -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/interfaces/punchout.ts +20 -1
- package/server/middleware/missing-media.ts +2 -2
- package/server/middleware/punchout-exits.ts +45 -0
- package/server/middleware/punchout-visit-csp.ts +35 -0
- package/server/plugins/previewHostNoindex.ts +21 -0
- package/server/plugins/punchout-cookies.ts +48 -0
- package/server/plugins/seoSiteConfig.ts +62 -0
- package/server/routes/punchout/start.get.ts +7 -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/punchoutFrame.ts +131 -0
- package/server/utils/punchoutOrder.ts +40 -0
- package/server/utils/punchoutVisit.ts +41 -8
- 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
- package/server/middleware/punchout-hand-back-csp.ts +0 -17
|
@@ -127,6 +127,12 @@ export default defineEventHandler(async (event) => {
|
|
|
127
127
|
throw createError({ status: 400, message: "Cart is empty" });
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
// The punchout visit this order is placed in, if any. Whether the
|
|
131
|
+
// visit may order at all — and whether it has run out — is settled
|
|
132
|
+
// before this handler runs (the punchout-exits middleware, RAD-226).
|
|
133
|
+
const visitRecord = readPunchoutVisit(event);
|
|
134
|
+
const punchoutVisit = isRestrictingVisit(visitRecord) ? visitRecord : null;
|
|
135
|
+
|
|
130
136
|
const customerType = body.customerType === "private" ? "private" : "business";
|
|
131
137
|
const addressError = validateAddress(body.address ?? {}, customerType);
|
|
132
138
|
if (addressError) {
|
|
@@ -346,17 +352,7 @@ export default defineEventHandler(async (event) => {
|
|
|
346
352
|
tax_rate: linePrices[index]!.taxRate,
|
|
347
353
|
})),
|
|
348
354
|
});
|
|
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
|
-
}));
|
|
355
|
+
let discounts = orderDiscounts(promo?.applied ?? []);
|
|
360
356
|
|
|
361
357
|
// The cart this order came out of. The promotions app keys its
|
|
362
358
|
// redemption ledger on it, so without it a reservation has
|
|
@@ -446,6 +442,9 @@ export default defineEventHandler(async (event) => {
|
|
|
446
442
|
...(item.subcategorySlug ? { subcategorySlug: String(item.subcategorySlug) } : {}),
|
|
447
443
|
},
|
|
448
444
|
})) as unknown as Models.OrderItemCreateRequest[],
|
|
445
|
+
// Which punchout visit this order came from (RAD-226), so a
|
|
446
|
+
// punchout order is recognisable on its own.
|
|
447
|
+
...(punchoutVisit ? { metadata: punchoutOrderMetadata(punchoutVisit) } : {}),
|
|
449
448
|
userData: {
|
|
450
449
|
...(body.deliveryNote ? { delivery_note: body.deliveryNote } : {}),
|
|
451
450
|
...(body.orderNote ? { order_note: body.orderNote } : {}),
|
|
@@ -496,6 +495,11 @@ export default defineEventHandler(async (event) => {
|
|
|
496
495
|
if (reserved === "held" && cartId) {
|
|
497
496
|
await releaseRedemption(event, { cartId, reason: PromotionsRedemptionsReleaseReason.CartReleased });
|
|
498
497
|
}
|
|
498
|
+
// An order awaiting approval ends a punchout visit too: the
|
|
499
|
+
// cart is converted either way.
|
|
500
|
+
if (punchoutVisit) {
|
|
501
|
+
await settlePunchoutOrder(event, punchoutVisit);
|
|
502
|
+
}
|
|
499
503
|
return {
|
|
500
504
|
orderId: placed.number,
|
|
501
505
|
status: "approval-pending",
|
|
@@ -508,6 +512,9 @@ export default defineEventHandler(async (event) => {
|
|
|
508
512
|
|
|
509
513
|
orderId = placed.number;
|
|
510
514
|
liveOrderUuid = placed.id;
|
|
515
|
+
if (punchoutVisit) {
|
|
516
|
+
await settlePunchoutOrder(event, punchoutVisit);
|
|
517
|
+
}
|
|
511
518
|
liveOrderTotal = typeof placed.grand_total === "number" ? placed.grand_total : null;
|
|
512
519
|
|
|
513
520
|
// The order exists, so the hold becomes a spend. Best-effort: a
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PunchoutIntent, PunchoutProtocol } from "../../app/interfaces/punchout";
|
|
1
|
+
import type { PunchoutIntent, PunchoutProtocol, PunchoutPurchaseMode } from "../../app/interfaces/punchout";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What `POST /punchout/sessions/{psid}/claim` answers.
|
|
@@ -16,6 +16,17 @@ export interface PunchoutClaim {
|
|
|
16
16
|
readonly entry_action: string | null;
|
|
17
17
|
readonly entry_intent: PunchoutIntent | null;
|
|
18
18
|
readonly cart_id: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Which exit the visit has (punchout 2.4.0). Absent from an older app,
|
|
21
|
+
* which is read as `transfer`: an order placed in the shop would bypass the
|
|
22
|
+
* ERP's own approval and purchase order.
|
|
23
|
+
*/
|
|
24
|
+
readonly purchase_mode?: PunchoutPurchaseMode | null;
|
|
25
|
+
/**
|
|
26
|
+
* The origins the punchout account allows to show the visit inside a frame
|
|
27
|
+
* (punchout 4.3.0). Absent or empty: the visit is not framed.
|
|
28
|
+
*/
|
|
29
|
+
readonly frame_ancestors?: readonly string[] | null;
|
|
19
30
|
readonly expires_at: string;
|
|
20
31
|
readonly contact_id: string | null;
|
|
21
32
|
readonly organization_id: string | null;
|
|
@@ -47,6 +58,14 @@ export interface PunchoutVisit {
|
|
|
47
58
|
readonly readOnly: boolean;
|
|
48
59
|
/** Set once the cart has been handed back; a repeat ask replays the payload. */
|
|
49
60
|
readonly handedBack: boolean;
|
|
61
|
+
/** Which exits the shop offers this visit, from the claim (RAD-226). */
|
|
62
|
+
readonly purchaseMode?: PunchoutPurchaseMode;
|
|
63
|
+
/** The origins the account allows to frame the visit — its `frame-ancestors`. */
|
|
64
|
+
readonly frameAncestors?: readonly string[];
|
|
65
|
+
/** The visit was opened inside a frame, so its cookies are partitioned. */
|
|
66
|
+
readonly framed?: boolean;
|
|
67
|
+
/** The checkout placed this visit's order; set by the order route. */
|
|
68
|
+
readonly ordered?: boolean;
|
|
50
69
|
/**
|
|
51
70
|
* The origin the hand-back form posts to, once the punchout app has
|
|
52
71
|
* answered it — what the hand-back page's `form-action` allows (PE-994).
|
|
@@ -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,45 @@
|
|
|
1
|
+
import { createError, sendRedirect } from "h3";
|
|
2
|
+
|
|
3
|
+
import { isCheckoutCall, punchoutRefusal } from "../../app/shared/punchoutExits";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Punchout mode, enforced (RAD-226): during a live visit a request for an exit
|
|
7
|
+
* the visit does not have goes back to the visit's cart, and a call that
|
|
8
|
+
* would take one is refused. The shop hides those exits as well; this is the
|
|
9
|
+
* half that holds when the buyer types the address.
|
|
10
|
+
*
|
|
11
|
+
* A visit that ran out may not place its order either: an order created after
|
|
12
|
+
* the visit's expiry does not count for the visit, and the procurement system
|
|
13
|
+
* would never hear of it.
|
|
14
|
+
*/
|
|
15
|
+
export default defineEventHandler(async (event) => {
|
|
16
|
+
const record = readPunchoutVisitRecord(event);
|
|
17
|
+
if (!record || record.handedBack === true) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (isLapsed(record)) {
|
|
21
|
+
if (isCheckoutCall(event.path, event.method)) {
|
|
22
|
+
throw createError({
|
|
23
|
+
statusCode: 409,
|
|
24
|
+
statusMessage: "The punchout session has run out",
|
|
25
|
+
message: "The punchout session has run out. Start the catalogue again from your procurement system.",
|
|
26
|
+
data: { type: "punchout_session_closed" },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const refusal = punchoutRefusal(event.path, event.method, record);
|
|
33
|
+
if (!refusal) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (refusal.kind === "redirect") {
|
|
37
|
+
return await sendRedirect(event, refusal.to, 302);
|
|
38
|
+
}
|
|
39
|
+
throw createError({
|
|
40
|
+
statusCode: 403,
|
|
41
|
+
statusMessage: "Not offered in this punchout session",
|
|
42
|
+
message: "This punchout session ends through its own action in the cart; this one is not offered.",
|
|
43
|
+
data: { type: refusal.type },
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { setResponseHeader } from "h3";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The CSP of a punchout visit's pages.
|
|
5
|
+
*
|
|
6
|
+
* Two things a visit's pages answer that an ordinary storefront page does not:
|
|
7
|
+
*
|
|
8
|
+
* - **`frame-ancestors`** with the parents the punchout account allows, so the
|
|
9
|
+
* shop renders inside the procurement system's iframe (RAD-226). From the
|
|
10
|
+
* claim, kept on the visit cookie; outside a visit nothing is set and the
|
|
11
|
+
* edge's own `frame-ancestors 'self'` stands.
|
|
12
|
+
* - **`form-action`** on the hand-back page, so it can submit its form to the
|
|
13
|
+
* visit's return address (PE-994). Which origin: the one the punchout app
|
|
14
|
+
* answered on the first hand-back, kept on the visit cookie. The page is
|
|
15
|
+
* rendered with it in `event.context` so it can tell whether THIS document
|
|
16
|
+
* may submit the form, or has to be loaded once more with the header that
|
|
17
|
+
* allows it.
|
|
18
|
+
*
|
|
19
|
+
* One header for both, because a response carries one policy the edge keeps;
|
|
20
|
+
* the rest of it repeats the edge's default so a visit's page is held to the
|
|
21
|
+
* same rules as every other.
|
|
22
|
+
*/
|
|
23
|
+
export default defineEventHandler((event) => {
|
|
24
|
+
const handBackPage = isHandBackPath(event.path);
|
|
25
|
+
const visit = readPunchoutVisit(event);
|
|
26
|
+
if (handBackPage) {
|
|
27
|
+
event.context.punchoutHandBackOrigin = visit?.handBackOrigin ?? null;
|
|
28
|
+
}
|
|
29
|
+
if (visit) {
|
|
30
|
+
setResponseHeader(event, "Content-Security-Policy", punchoutVisitCsp(visit, handBackPage));
|
|
31
|
+
}
|
|
32
|
+
else if (handBackPage) {
|
|
33
|
+
setResponseHeader(event, "Content-Security-Policy", handBackFormAction(null));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -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
|
+
});
|