@revenexx/cover 0.22.1 → 0.24.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/components/cart/view/CartSummaryPanel.vue +13 -6
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +2 -2
- package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +6 -0
- package/app/components/checkout/onepage/CheckoutNotesSection.vue +2 -0
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +2 -0
- 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/MobileMenu.vue +4 -1
- package/app/components/punchout/action/PunchoutTransferAction.vue +4 -3
- package/app/components/ui/forms/FormKitDatePicker.vue +1 -1
- package/app/composables/usePunchoutVisit.ts +36 -1
- package/app/interfaces/punchout.ts +11 -0
- package/app/middleware/punchout-exits.global.ts +25 -0
- package/app/plugins/punchout-links.client.ts +46 -0
- package/app/shared/punchoutExits.ts +156 -0
- package/app/shared/signInLink.ts +86 -0
- package/i18n/locales/de/punchout.json +3 -0
- package/i18n/locales/en/punchout.json +3 -0
- package/nuxt.config.ts +13 -0
- package/package.json +23 -21
- package/server/api/campaigns/touches.post.ts +1 -1
- package/server/api/orders/index.post.ts +17 -0
- package/server/interfaces/punchout.ts +20 -1
- package/server/middleware/market-scope.ts +24 -0
- package/server/middleware/punchout-exits.ts +45 -0
- package/server/middleware/punchout-visit-csp.ts +35 -0
- package/server/plugins/punchout-cookies.ts +48 -0
- package/server/routes/punchout/start.get.ts +7 -0
- package/server/services/ApiAuthService.ts +14 -3
- package/server/utils/appSettings.ts +1 -1
- package/server/utils/buyerIdentity.ts +28 -1
- package/server/utils/locale.ts +2 -2
- package/server/utils/market.ts +131 -7
- 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 +33 -6
- package/server/middleware/punchout-hand-back-csp.ts +0 -17
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a sign-in link carries beside the secret (RAD-472).
|
|
3
|
+
*
|
|
4
|
+
* A mailed link carries `userId` and `secret` only. The link a sales rep opens
|
|
5
|
+
* when acting for a buyer carries more: where the shop should open
|
|
6
|
+
* (`landing`), the handover entry (`acting`), and the buyer's `market`,
|
|
7
|
+
* `locale` and `currency`. The link's values are a suggestion for where the
|
|
8
|
+
* buyer starts, never a grant: each is checked for its form here, and the shop
|
|
9
|
+
* then treats it exactly like the same choice made in the locale selector.
|
|
10
|
+
*
|
|
11
|
+
* Pure functions, shared by the link page and the server redirect in front of
|
|
12
|
+
* it, so both read a link the same way.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { localeLanguage, normalizeLocaleCode } from "./locale";
|
|
16
|
+
|
|
17
|
+
/** Where a handed-over buyer lands, as the sales-reps app names it. */
|
|
18
|
+
export type SignInLanding = "home" | "quick_order";
|
|
19
|
+
|
|
20
|
+
export interface SignInLinkPreferences {
|
|
21
|
+
readonly landing?: SignInLanding;
|
|
22
|
+
readonly market?: string;
|
|
23
|
+
/** The full locale code, `de-DE`, or a bare language, `de`. */
|
|
24
|
+
readonly locale?: string;
|
|
25
|
+
/** The locale's language, `de`. */
|
|
26
|
+
readonly language?: string;
|
|
27
|
+
readonly currency?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const LANDINGS: readonly SignInLanding[] = ["home", "quick_order"];
|
|
31
|
+
const MARKET_CODE = /^[a-z][a-z0-9_]{0,62}$/;
|
|
32
|
+
const LOCALE_CODE = /^[a-z]{2,3}(?:-[A-Z]{2})?$/;
|
|
33
|
+
const CURRENCY_CODE = /^[A-Z]{3}$/;
|
|
34
|
+
|
|
35
|
+
const text = (value: unknown): string => (typeof value === "string" ? value.trim() : "");
|
|
36
|
+
|
|
37
|
+
/** The values of a link's query the shop may follow; anything malformed is left out. */
|
|
38
|
+
export function signInLinkPreferences(query: Readonly<Record<string, unknown>>): SignInLinkPreferences {
|
|
39
|
+
const landing = text(query.landing);
|
|
40
|
+
const market = text(query.market).toLowerCase();
|
|
41
|
+
const locale = normalizeLocaleCode(text(query.locale));
|
|
42
|
+
const currency = text(query.currency).toUpperCase();
|
|
43
|
+
return {
|
|
44
|
+
...(LANDINGS.includes(landing as SignInLanding) ? { landing: landing as SignInLanding } : {}),
|
|
45
|
+
...(MARKET_CODE.test(market) ? { market } : {}),
|
|
46
|
+
...(LOCALE_CODE.test(locale) ? { locale, language: localeLanguage(locale) } : {}),
|
|
47
|
+
...(CURRENCY_CODE.test(currency) ? { currency } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The page a signed-in link opens: the home page or the cart, whose quick entry
|
|
53
|
+
* is the shop's fast product entry, where the link names a landing; the
|
|
54
|
+
* account, as before, where it names none.
|
|
55
|
+
*/
|
|
56
|
+
export function signInLinkDestination(preferences: SignInLinkPreferences): string {
|
|
57
|
+
switch (preferences.landing) {
|
|
58
|
+
case "home": return "/";
|
|
59
|
+
case "quick_order": return "/cart";
|
|
60
|
+
default: return "/account";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The language-prefixed address of the link page for a link that arrived
|
|
66
|
+
* without a prefix, or null when it needs none.
|
|
67
|
+
*
|
|
68
|
+
* Links are minted as `/login/link`, which a shop that prefixes every page with
|
|
69
|
+
* its language does not serve. The link's own `locale` decides the language
|
|
70
|
+
* where the shop speaks it, so a handed-over English buyer lands in English;
|
|
71
|
+
* otherwise the shop's default language.
|
|
72
|
+
*/
|
|
73
|
+
export function prefixedSignInLinkPath(
|
|
74
|
+
path: string,
|
|
75
|
+
query: Readonly<Record<string, unknown>>,
|
|
76
|
+
languages: readonly string[],
|
|
77
|
+
defaultLanguage: string,
|
|
78
|
+
): string | null {
|
|
79
|
+
const [pathname = "", search = ""] = path.split("?");
|
|
80
|
+
if (pathname.replace(/\/+$/, "") !== "/login/link") {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const wanted = signInLinkPreferences(query).language;
|
|
84
|
+
const language = wanted && languages.includes(wanted) ? wanted : defaultLanguage;
|
|
85
|
+
return `/${language}/login/link${search ? `?${search}` : ""}`;
|
|
86
|
+
}
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"readOnly": {
|
|
41
41
|
"hint": "Diese Anforderung wurde nur zur Ansicht geöffnet und kann hier nicht geändert werden.",
|
|
42
42
|
"badge": "Nur zur Ansicht"
|
|
43
|
+
},
|
|
44
|
+
"orderAndTransfer": {
|
|
45
|
+
"hint": "Nach der Bestellung gehen Warenkorb und Bestellung im selben Schritt an Ihre Handwerkersoftware zurück."
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"readOnly": {
|
|
41
41
|
"hint": "This requisition was opened for viewing only and cannot be changed here.",
|
|
42
42
|
"badge": "View only"
|
|
43
|
+
},
|
|
44
|
+
"orderAndTransfer": {
|
|
45
|
+
"hint": "After the order, the cart and its order go back to your trade software in the same step."
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
package/nuxt.config.ts
CHANGED
|
@@ -149,11 +149,20 @@ export default defineNuxtConfig({
|
|
|
149
149
|
// (PE-1103) writes the JSON-LD: a WebSite and WebPage on every page, the
|
|
150
150
|
// Organization from the rules (useSeoHead), Product and BreadcrumbList from
|
|
151
151
|
// the product and category pages.
|
|
152
|
+
//
|
|
153
|
+
// Analytics: @revenexx/beats-nuxt sends page views and the theme events
|
|
154
|
+
// (theme-events/1, mapped onto beats commerce events) to beats. There is
|
|
155
|
+
// no key here: the platform's Site router sets x-revenexx-beats-key on
|
|
156
|
+
// each request to the tenant's ingest key (and drops client copies), and
|
|
157
|
+
// the module hands it to the browser. A host without a key (a preview, the
|
|
158
|
+
// docs website, local dev) sends nothing. Cookieless; nothing identifies
|
|
159
|
+
// the visitor.
|
|
152
160
|
modules: [
|
|
153
161
|
"@formkit/nuxt",
|
|
154
162
|
"@nuxt/scripts",
|
|
155
163
|
"@revenexx/consent-manager-nuxt",
|
|
156
164
|
"@revenexx/tag-manager-nuxt",
|
|
165
|
+
"@revenexx/beats-nuxt",
|
|
157
166
|
"nuxt-site-config",
|
|
158
167
|
"nuxt-seo-utils",
|
|
159
168
|
"nuxt-schema-org",
|
|
@@ -161,6 +170,10 @@ export default defineNuxtConfig({
|
|
|
161
170
|
"nuxt-og-image",
|
|
162
171
|
],
|
|
163
172
|
|
|
173
|
+
beats: {
|
|
174
|
+
apiHost: "https://beats.revenexx.com",
|
|
175
|
+
},
|
|
176
|
+
|
|
164
177
|
// Broken links while developing; a production build has no use for it.
|
|
165
178
|
$development: {
|
|
166
179
|
modules: ["nuxt-link-checker"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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",
|
|
@@ -34,38 +34,40 @@
|
|
|
34
34
|
"./validations/*": "./app/validations/*.ts"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@formkit/barcode": "^1.0
|
|
38
|
-
"@formkit/core": "^
|
|
39
|
-
"@formkit/i18n": "^
|
|
40
|
-
"@formkit/nuxt": "^
|
|
41
|
-
"@formkit/themes": "^
|
|
42
|
-
"@formkit/vue": "^
|
|
43
|
-
"@iconify-json/lucide": "^1.2.
|
|
44
|
-
"@internationalized/date": "^3.12.
|
|
37
|
+
"@formkit/barcode": "^1.1.0",
|
|
38
|
+
"@formkit/core": "^2.9.0",
|
|
39
|
+
"@formkit/i18n": "^2.9.0",
|
|
40
|
+
"@formkit/nuxt": "^2.9.0",
|
|
41
|
+
"@formkit/themes": "^2.9.0",
|
|
42
|
+
"@formkit/vue": "^2.9.0",
|
|
43
|
+
"@iconify-json/lucide": "^1.2.157",
|
|
44
|
+
"@internationalized/date": "^3.12.4",
|
|
45
45
|
"@nuxt/scripts": "^1.3.0",
|
|
46
46
|
"@nuxtjs/robots": "7.0.2",
|
|
47
|
-
"@revenexx/
|
|
48
|
-
"@revenexx/
|
|
49
|
-
"@revenexx/
|
|
50
|
-
"@revenexx/
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
47
|
+
"@revenexx/beats-nuxt": "0.2.0",
|
|
48
|
+
"@revenexx/consent-manager-nuxt": "^0.1.1",
|
|
49
|
+
"@revenexx/sdk": "^0.9.0",
|
|
50
|
+
"@revenexx/storage-model-viewer": "^0.3.1",
|
|
51
|
+
"@revenexx/tag-manager-nuxt": "^0.1.1",
|
|
52
|
+
"@takumi-rs/core": "2.22.1",
|
|
53
|
+
"@vueuse/core": "^15.0.0",
|
|
53
54
|
"nuxt-link-checker": "6.0.1",
|
|
54
55
|
"nuxt-og-image": "7.0.7",
|
|
55
56
|
"nuxt-schema-org": "7.0.1",
|
|
56
|
-
"nuxt-seo-utils": "9.0.
|
|
57
|
+
"nuxt-seo-utils": "9.0.2",
|
|
57
58
|
"nuxt-site-config": "5.0.3",
|
|
58
|
-
"typesense": "^3.0
|
|
59
|
+
"typesense": "^3.2.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"@nuxt/ui": "^4.5.1",
|
|
62
|
-
"pinia": "^3.0.4",
|
|
63
|
+
"pinia": "^3.0.4 || ^4.0.0",
|
|
63
64
|
"vue": "^3.5.0",
|
|
64
|
-
"vue-i18n": "^11.
|
|
65
|
+
"vue-i18n": "^11.4.23"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
|
-
"@nuxt/kit": "^4.6.
|
|
68
|
-
"nuxt": "^4.6.
|
|
68
|
+
"@nuxt/kit": "^4.6.4",
|
|
69
|
+
"nuxt": "^4.6.4",
|
|
70
|
+
"pinia": "^4.1.0"
|
|
69
71
|
},
|
|
70
72
|
"publishConfig": {
|
|
71
73
|
"registry": "https://registry.npmjs.org",
|
|
@@ -25,7 +25,7 @@ export default defineEventHandler(async (event) => {
|
|
|
25
25
|
return { recorded: 0 };
|
|
26
26
|
}
|
|
27
27
|
const contactId = sessionOrderRefs(event).contact_id;
|
|
28
|
-
const market =
|
|
28
|
+
const market = requestMarket(event);
|
|
29
29
|
const sessionKey = getOrCreateCartSessionId(event);
|
|
30
30
|
try {
|
|
31
31
|
await getMarketingService(event).recordTouches(event, touches.map(touch => ({
|
|
@@ -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) {
|
|
@@ -436,6 +442,9 @@ export default defineEventHandler(async (event) => {
|
|
|
436
442
|
...(item.subcategorySlug ? { subcategorySlug: String(item.subcategorySlug) } : {}),
|
|
437
443
|
},
|
|
438
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) } : {}),
|
|
439
448
|
userData: {
|
|
440
449
|
...(body.deliveryNote ? { delivery_note: body.deliveryNote } : {}),
|
|
441
450
|
...(body.orderNote ? { order_note: body.orderNote } : {}),
|
|
@@ -486,6 +495,11 @@ export default defineEventHandler(async (event) => {
|
|
|
486
495
|
if (reserved === "held" && cartId) {
|
|
487
496
|
await releaseRedemption(event, { cartId, reason: PromotionsRedemptionsReleaseReason.CartReleased });
|
|
488
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
|
+
}
|
|
489
503
|
return {
|
|
490
504
|
orderId: placed.number,
|
|
491
505
|
status: "approval-pending",
|
|
@@ -498,6 +512,9 @@ export default defineEventHandler(async (event) => {
|
|
|
498
512
|
|
|
499
513
|
orderId = placed.number;
|
|
500
514
|
liveOrderUuid = placed.id;
|
|
515
|
+
if (punchoutVisit) {
|
|
516
|
+
await settlePunchoutOrder(event, punchoutVisit);
|
|
517
|
+
}
|
|
501
518
|
liveOrderTotal = typeof placed.grand_total === "number" ? placed.grand_total : null;
|
|
502
519
|
|
|
503
520
|
// The order exists, so the hold becomes a spend. Best-effort: a
|
|
@@ -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).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths that never call an app: the bundler's, @nuxt/image's, the OG images,
|
|
3
|
+
* module plumbing under `/api/_`, and anything that names a file.
|
|
4
|
+
*/
|
|
5
|
+
const NO_APP_CALLS = ["/_nuxt/", "/__nuxt", "/_ipx/", "/_og/", "/@", "/node_modules/", "/api/_"];
|
|
6
|
+
const FILE_PATH = /\.[a-z0-9]{2,5}$/i;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Decide the request's market before any handler calls an app (RAD-479).
|
|
10
|
+
*
|
|
11
|
+
* The shop used to send `X-Revenexx-Market` only when the buyer had picked a
|
|
12
|
+
* market, so a buyer who never touched the selector created carts that
|
|
13
|
+
* belonged to no market. Resolved here once, every SDK call of the request
|
|
14
|
+
* carries it (useRevenexxSdk reads requestMarket()): the buyer's choice, else
|
|
15
|
+
* the market the domain is bound to in Experience Studio (RAD-471), else the
|
|
16
|
+
* tenant's default market.
|
|
17
|
+
*/
|
|
18
|
+
export default defineEventHandler(async (event) => {
|
|
19
|
+
const path = event.path.split("?")[0] ?? "";
|
|
20
|
+
if (FILE_PATH.test(path) || NO_APP_CALLS.some(prefix => path.startsWith(prefix))) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await resolveRequestMarket(event);
|
|
24
|
+
});
|
|
@@ -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,48 @@
|
|
|
1
|
+
import { getCookie } from "h3";
|
|
2
|
+
|
|
3
|
+
import { PUNCHOUT_COOKIE_NAME } from "../utils/punchoutVisit";
|
|
4
|
+
import { isFramedNavigation, punchoutCookieModeOf, punchoutCookies } from "../utils/punchoutFrame";
|
|
5
|
+
import type { PunchoutCookieMode } from "../utils/punchoutFrame";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* During a punchout visit every cookie the shop sets is `SameSite=None;
|
|
9
|
+
* Secure` — and `Partitioned` when the visit is framed — so the visit keeps its
|
|
10
|
+
* session inside the procurement system's iframe (RAD-226). See
|
|
11
|
+
* punchoutFrame.ts for why, and why only then.
|
|
12
|
+
*
|
|
13
|
+
* Applied where a cookie is written rather than in each setter, because a
|
|
14
|
+
* visit page sets cookies from a dozen places (the session, the cart, the
|
|
15
|
+
* market, the locale, modules the layer does not own), and the one a setter
|
|
16
|
+
* forgot is the one that signs the buyer out inside the frame.
|
|
17
|
+
*
|
|
18
|
+
* Which requests: those carrying the visit cookie, and `/punchout/start`,
|
|
19
|
+
* which sets it — there the request itself says whether it is framed.
|
|
20
|
+
* Skipped in development, where the shop is served over plain http and a
|
|
21
|
+
* `Secure` cookie would not be stored.
|
|
22
|
+
*/
|
|
23
|
+
const START_PATH = /(?:^|\/)punchout\/start\/?(?:\?|$)/;
|
|
24
|
+
|
|
25
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
26
|
+
if (import.meta.dev) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
nitroApp.hooks.hook("request", (event) => {
|
|
30
|
+
const mode: PunchoutCookieMode | null = START_PATH.test(event.path)
|
|
31
|
+
? { partitioned: isFramedNavigation(event) }
|
|
32
|
+
: punchoutCookieModeOf(getCookie(event, PUNCHOUT_COOKIE_NAME));
|
|
33
|
+
if (!mode) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
event.context.punchoutCookieMode = mode;
|
|
37
|
+
|
|
38
|
+
const res = event.node.res;
|
|
39
|
+
const setHeader = res.setHeader.bind(res);
|
|
40
|
+
res.setHeader = ((name: string, value: number | string | readonly string[]) =>
|
|
41
|
+
setHeader(name, name.toLowerCase() === "set-cookie" ? punchoutCookies(value, mode) : value)) as typeof res.setHeader;
|
|
42
|
+
if (typeof res.appendHeader === "function") {
|
|
43
|
+
const appendHeader = res.appendHeader.bind(res);
|
|
44
|
+
res.appendHeader = ((name: string, value: string | readonly string[]) =>
|
|
45
|
+
appendHeader(name, name.toLowerCase() === "set-cookie" ? punchoutCookies(value, mode) as string | string[] : value)) as typeof res.appendHeader;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import type { StoredSession } from "../../../app/interfaces/auth";
|
|
12
12
|
import type { PunchoutClaim, PunchoutVisit } from "../../interfaces/punchout";
|
|
13
|
+
import { purchaseModeOf } from "../../../app/shared/punchoutExits";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* `/punchout/start?pSid=…` — where the entry redirect lands the buyer.
|
|
@@ -131,6 +132,12 @@ export default defineEventHandler(async (event) => {
|
|
|
131
132
|
expiresAt: claim.expires_at,
|
|
132
133
|
readOnly: claim.entry_intent?.read_only === true,
|
|
133
134
|
handedBack: false,
|
|
135
|
+
// Punchout mode (RAD-226): the exits the shop offers, the parents that
|
|
136
|
+
// may frame it, and whether it was opened in a frame — which decides
|
|
137
|
+
// whether its cookies are partitioned.
|
|
138
|
+
purchaseMode: purchaseModeOf(claim.purchase_mode),
|
|
139
|
+
frameAncestors: frameAncestorsOf(claim.frame_ancestors),
|
|
140
|
+
framed: isFramedNavigation(event),
|
|
134
141
|
};
|
|
135
142
|
setPunchoutVisit(event, visit);
|
|
136
143
|
|
|
@@ -38,6 +38,8 @@ interface ApiMeAnswer {
|
|
|
38
38
|
|
|
39
39
|
/** The verified identity of one request, resolved at most once per request. */
|
|
40
40
|
const ME_KEY = "coverApiAuthMe";
|
|
41
|
+
/** The platform session the cookie named, once it was well-formed enough to ask about. */
|
|
42
|
+
const VERIFIED_SESSION_KEY = "coverApiAuthSession";
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* A short cross-request memory of verified answers, keyed by tenant + user +
|
|
@@ -145,15 +147,22 @@ export class ApiAuthService implements IAuthService {
|
|
|
145
147
|
if (pending) {
|
|
146
148
|
return pending;
|
|
147
149
|
}
|
|
148
|
-
const resolving = this.resolve(event).then((user) => {
|
|
149
|
-
rememberVerifiedBuyer(event, user);
|
|
150
|
+
const resolving = this.resolve(event).then(({ user, sessionId }) => {
|
|
151
|
+
rememberVerifiedBuyer(event, user, sessionId);
|
|
150
152
|
return user;
|
|
151
153
|
});
|
|
152
154
|
context[ME_KEY] = resolving;
|
|
153
155
|
return resolving;
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
|
|
158
|
+
/** The verified user, and the session it was verified for. */
|
|
159
|
+
private async resolve(event: H3Event): Promise<{ user: AuthUser | null; sessionId?: string }> {
|
|
160
|
+
const user = await this.verify(event);
|
|
161
|
+
const sessionId = user ? (event.context as Record<string, unknown>)[VERIFIED_SESSION_KEY] : undefined;
|
|
162
|
+
return { user, ...(typeof sessionId === "string" ? { sessionId } : {}) };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private async verify(event: H3Event): Promise<AuthUser | null> {
|
|
157
166
|
const raw = getCookie(event, SESSION_COOKIE_NAME);
|
|
158
167
|
if (!raw) {
|
|
159
168
|
return null;
|
|
@@ -177,6 +186,8 @@ export class ApiAuthService implements IAuthService {
|
|
|
177
186
|
return null;
|
|
178
187
|
}
|
|
179
188
|
|
|
189
|
+
// The session every answer below is verified for, whichever path gives it.
|
|
190
|
+
(event.context as Record<string, unknown>)[VERIFIED_SESSION_KEY] = parsed.id;
|
|
180
191
|
const cacheKey = `${revenexxTenantKey()}\u0000${parsed.userId}\u0000${parsed.id}`;
|
|
181
192
|
const remembered = verified.get(cacheKey);
|
|
182
193
|
if (remembered && remembered.until > Date.now()) {
|
|
@@ -130,7 +130,7 @@ export async function readAppSettings(event: H3Event | undefined, app: string):
|
|
|
130
130
|
return { ...await readDemoAppSettings(app), ...override };
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
const market = event ?
|
|
133
|
+
const market = event ? requestMarket(event) : undefined;
|
|
134
134
|
// Partitioned by tenant: a theme serving several must never answer one
|
|
135
135
|
// tenant's page with another's settings (see revenexxTenantKey()).
|
|
136
136
|
const key = `${revenexxTenantKey()}|${app}|${market ?? "-"}`;
|
|
@@ -30,6 +30,7 @@ import type { AuthRole, AuthUser } from "../../app/interfaces/auth";
|
|
|
30
30
|
|
|
31
31
|
const BUYER_KEY = "coverVerifiedBuyer";
|
|
32
32
|
const PRINCIPAL_KEY = "revenexxPrincipal";
|
|
33
|
+
const SESSION_KEY = "revenexxBuyerSession";
|
|
33
34
|
|
|
34
35
|
type BuyerContext = Record<string, unknown>;
|
|
35
36
|
|
|
@@ -42,8 +43,12 @@ function contextOf(event: H3Event | undefined): BuyerContext | null {
|
|
|
42
43
|
* Record what the identity service answered for this request. Only a verified
|
|
43
44
|
* answer comes through here; null records "signed out" so a second read in the
|
|
44
45
|
* same request does not ask again.
|
|
46
|
+
*
|
|
47
|
+
* `sessionId` is the platform session the answer was verified for: the
|
|
48
|
+
* identity service confirmed it is that user's live one, so it may ride beside
|
|
49
|
+
* the principal (buyerSession).
|
|
45
50
|
*/
|
|
46
|
-
export function rememberVerifiedBuyer(event: H3Event, user: AuthUser | null): void {
|
|
51
|
+
export function rememberVerifiedBuyer(event: H3Event, user: AuthUser | null, sessionId?: string): void {
|
|
47
52
|
const context = contextOf(event);
|
|
48
53
|
if (!context) {
|
|
49
54
|
return;
|
|
@@ -55,6 +60,12 @@ export function rememberVerifiedBuyer(event: H3Event, user: AuthUser | null): vo
|
|
|
55
60
|
else {
|
|
56
61
|
delete context[PRINCIPAL_KEY];
|
|
57
62
|
}
|
|
63
|
+
if (user?.contactId && sessionId) {
|
|
64
|
+
context[SESSION_KEY] = sessionId;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
delete context[SESSION_KEY];
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
/** Forget it again — after a sign-out within the same request. */
|
|
@@ -63,6 +74,7 @@ export function forgetVerifiedBuyer(event: H3Event): void {
|
|
|
63
74
|
if (context) {
|
|
64
75
|
delete context[BUYER_KEY];
|
|
65
76
|
delete context[PRINCIPAL_KEY];
|
|
77
|
+
delete context[SESSION_KEY];
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
|
|
@@ -88,6 +100,21 @@ export function buyerPrincipal(event: H3Event | undefined): string {
|
|
|
88
100
|
return typeof value === "string" ? value : "";
|
|
89
101
|
}
|
|
90
102
|
|
|
103
|
+
/**
|
|
104
|
+
* The value for `X-Revenexx-Session`: the platform session the verified buyer
|
|
105
|
+
* holds, or "" when there is none (RAD-472).
|
|
106
|
+
*
|
|
107
|
+
* The gateway hands it to the customers app beside the principal, and only
|
|
108
|
+
* then learns whether a sales rep opened that session for the buyer — which it
|
|
109
|
+
* forwards to every app as the acting rep. Without it a handed-over session
|
|
110
|
+
* looks like the buyer's own. It can only ever add the rep: who the buyer is
|
|
111
|
+
* still comes from the principal.
|
|
112
|
+
*/
|
|
113
|
+
export function buyerSession(event: H3Event | undefined): string {
|
|
114
|
+
const value = contextOf(event)?.[SESSION_KEY];
|
|
115
|
+
return typeof value === "string" ? value : "";
|
|
116
|
+
}
|
|
117
|
+
|
|
91
118
|
/**
|
|
92
119
|
* The contact the request acts for, or undefined. A body that names a contact
|
|
93
120
|
* to an app enforcing the principal (payments 1.0) has to name exactly this
|
package/server/utils/locale.ts
CHANGED
|
@@ -62,7 +62,7 @@ export async function resolveMarketLocale(event: H3Event): Promise<string> {
|
|
|
62
62
|
let locales: { code: string; language?: string; isDefault?: boolean; status?: string }[] = [];
|
|
63
63
|
try {
|
|
64
64
|
const markets = await getMarketService(event).listMarkets();
|
|
65
|
-
const selected =
|
|
65
|
+
const selected = requestMarket(event);
|
|
66
66
|
const market = markets.find(m => m.code === selected) ?? markets.find(m => m.isDefault) ?? markets[0];
|
|
67
67
|
locales = market?.locales ?? [];
|
|
68
68
|
}
|
|
@@ -94,7 +94,7 @@ export async function resolveStoreLocale(event: H3Event): Promise<string> {
|
|
|
94
94
|
const language = resolveLocale(event);
|
|
95
95
|
try {
|
|
96
96
|
const markets = await getMarketService(event).listMarkets();
|
|
97
|
-
const selected =
|
|
97
|
+
const selected = requestMarket(event);
|
|
98
98
|
const market = markets.find(m => m.code === selected) ?? markets.find(m => m.isDefault) ?? markets[0];
|
|
99
99
|
const locales = market?.locales ?? [];
|
|
100
100
|
if (!locales.length) {
|