@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
package/server/utils/market.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
|
+
import type { ShopMarket } from "../../app/interfaces/market";
|
|
4
|
+
|
|
3
5
|
/** Cookie the storefront's locale selector persists the chosen market in. */
|
|
4
6
|
export const MARKET_COOKIE_NAME = "cover-market";
|
|
5
7
|
|
|
8
|
+
/** Where the request's market is remembered once it is resolved (resolveRequestMarket). */
|
|
9
|
+
const REQUEST_MARKET_KEY = "coverRequestMarket";
|
|
10
|
+
|
|
11
|
+
const MARKET_CODE = /^[a-z][a-z0-9_]{0,62}$/;
|
|
12
|
+
|
|
6
13
|
/**
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
* (
|
|
10
|
-
*
|
|
11
|
-
* no header → the API returns only global rows, so the shop works before any
|
|
12
|
-
* market is chosen. Market slugs are lowercase (e.g. "de").
|
|
14
|
+
* The market the buyer CHOSE, from the cookie the locale selector sets — or
|
|
15
|
+
* undefined when they chose none. Only the choice: which market a request is
|
|
16
|
+
* made in is requestMarket(), which falls back to the shop's own market when
|
|
17
|
+
* nothing was chosen. Market slugs are lowercase (e.g. "de").
|
|
13
18
|
*/
|
|
14
19
|
export function resolveSelectedMarket(event: H3Event): string | undefined {
|
|
15
20
|
const raw = getCookie(event, MARKET_COOKIE_NAME);
|
|
@@ -17,5 +22,124 @@ export function resolveSelectedMarket(event: H3Event): string | undefined {
|
|
|
17
22
|
return undefined;
|
|
18
23
|
}
|
|
19
24
|
const code = raw.trim().toLowerCase();
|
|
20
|
-
return
|
|
25
|
+
return MARKET_CODE.test(code) ? code : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Which market a request is made in (RAD-479), among the tenant's active
|
|
30
|
+
* markets: the chosen one when it is one of them, else the shop's own market.
|
|
31
|
+
*
|
|
32
|
+
* The shop's own market is the domain's (RAD-471): a domain in Experience
|
|
33
|
+
* Studio names the market it serves, or none, which means it serves every
|
|
34
|
+
* market and opens in the tenant's default one, else the first. A domain bound
|
|
35
|
+
* to a market the tenant does not run is read as one that names none. Pure,
|
|
36
|
+
* for the tests.
|
|
37
|
+
*/
|
|
38
|
+
export function pickRequestMarket(
|
|
39
|
+
markets: readonly ShopMarket[],
|
|
40
|
+
chosen: string | undefined,
|
|
41
|
+
domainMarket?: string | null,
|
|
42
|
+
): string | undefined {
|
|
43
|
+
if (chosen && markets.some(m => m.code === chosen)) {
|
|
44
|
+
return chosen;
|
|
45
|
+
}
|
|
46
|
+
if (domainMarket && markets.some(m => m.code === domainMarket)) {
|
|
47
|
+
return domainMarket;
|
|
48
|
+
}
|
|
49
|
+
return (markets.find(m => m.isDefault) ?? markets[0])?.code;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One shop domain as `GET /v1/settings/storefronts` answers it. */
|
|
53
|
+
interface StorefrontRow {
|
|
54
|
+
readonly host?: string;
|
|
55
|
+
readonly market?: string | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const STOREFRONTS_TTL_MS = 5 * 60 * 1000;
|
|
59
|
+
|
|
60
|
+
// Partitioned by tenant (see revenexxTenantKey()): host → bound market, or
|
|
61
|
+
// null where the domain serves every market. A failed read is remembered as an
|
|
62
|
+
// empty map for the same time, so a gateway without the route costs one call
|
|
63
|
+
// per tenant and TTL, not one per request.
|
|
64
|
+
const storefrontMarkets = new Map<string, { markets: Map<string, string | null>; loadedAt: number }>();
|
|
65
|
+
|
|
66
|
+
/** Test seam: forget every remembered storefront list. */
|
|
67
|
+
export function clearStorefrontMarkets(): void {
|
|
68
|
+
storefrontMarkets.clear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The market the domain this request was made to is bound to, from the
|
|
73
|
+
* tenant's storefronts in Experience Studio (RAD-471): its code, or null when
|
|
74
|
+
* the domain serves every market, is not a storefront the platform knows, or
|
|
75
|
+
* the list cannot be read. Host from `Host`, as seoRequestHost reads it.
|
|
76
|
+
*/
|
|
77
|
+
export async function domainMarket(event: H3Event): Promise<string | null> {
|
|
78
|
+
let tenant: string;
|
|
79
|
+
try {
|
|
80
|
+
tenant = revenexxTenantKey();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
let entry = storefrontMarkets.get(tenant);
|
|
86
|
+
if (!entry || Date.now() - entry.loadedAt >= STOREFRONTS_TTL_MS) {
|
|
87
|
+
const markets = new Map<string, string | null>();
|
|
88
|
+
try {
|
|
89
|
+
const answer = await useTenantSdk().call<{ storefronts?: StorefrontRow[] }>("GET", "/v1/settings/storefronts");
|
|
90
|
+
for (const row of answer?.storefronts ?? []) {
|
|
91
|
+
const host = typeof row.host === "string" ? row.host.toLowerCase() : "";
|
|
92
|
+
if (host) {
|
|
93
|
+
markets.set(host, typeof row.market === "string" && MARKET_CODE.test(row.market) ? row.market : null);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Not readable: no domain names a market, as before the list existed.
|
|
99
|
+
}
|
|
100
|
+
entry = { markets, loadedAt: Date.now() };
|
|
101
|
+
storefrontMarkets.set(tenant, entry);
|
|
102
|
+
}
|
|
103
|
+
return entry.markets.get(seoRequestHost(event)) ?? null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Resolve the request's market once, before any handler calls an app, and
|
|
108
|
+
* remember it on the event (server/middleware/market-scope.ts).
|
|
109
|
+
*
|
|
110
|
+
* Every call then carries `X-Revenexx-Market`, which is what Baseline assigns a
|
|
111
|
+
* new row of a market-scoped table to: a cart created without the header was
|
|
112
|
+
* nobody's market. When the markets cannot be read, the request keeps the
|
|
113
|
+
* buyer's choice and nothing else — the same as before markets were read here.
|
|
114
|
+
*/
|
|
115
|
+
export async function resolveRequestMarket(event: H3Event): Promise<string | undefined> {
|
|
116
|
+
const context = event.context as Record<string, unknown>;
|
|
117
|
+
if (REQUEST_MARKET_KEY in context) {
|
|
118
|
+
return context[REQUEST_MARKET_KEY] as string | undefined;
|
|
119
|
+
}
|
|
120
|
+
const chosen = resolveSelectedMarket(event);
|
|
121
|
+
let market = chosen;
|
|
122
|
+
try {
|
|
123
|
+
const [markets, bound] = await Promise.all([getMarketService(event).listMarkets(), domainMarket(event)]);
|
|
124
|
+
market = pickRequestMarket(markets, chosen, bound) ?? chosen;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// The markets app could not be asked: the choice, if any, stands.
|
|
128
|
+
}
|
|
129
|
+
context[REQUEST_MARKET_KEY] = market;
|
|
130
|
+
return market;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The market this request is made in: what resolveRequestMarket() decided, or
|
|
135
|
+
* the buyer's choice while nothing decided yet (startup code, the markets read
|
|
136
|
+
* itself). Synchronous, for the SDK client. Undefined → no header → the gateway
|
|
137
|
+
* answers global rows only.
|
|
138
|
+
*/
|
|
139
|
+
export function requestMarket(event: H3Event): string | undefined {
|
|
140
|
+
const context = (event as { context?: Record<string, unknown> }).context;
|
|
141
|
+
if (context && REQUEST_MARKET_KEY in context) {
|
|
142
|
+
return context[REQUEST_MARKET_KEY] as string | undefined;
|
|
143
|
+
}
|
|
144
|
+
return resolveSelectedMarket(event);
|
|
21
145
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { PunchoutVisit } from "../interfaces/punchout";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A punchout visit inside the procurement system's iframe (RAD-226).
|
|
7
|
+
*
|
|
8
|
+
* A punchout visit usually runs inside the ERP or the trade software, often in
|
|
9
|
+
* an iframe. Two things stop the shop rendering there, and both are answered
|
|
10
|
+
* here for the visit and only for the visit:
|
|
11
|
+
*
|
|
12
|
+
* - **framing.** The edge answers `frame-ancestors 'self'` (and
|
|
13
|
+
* `X-Frame-Options: SAMEORIGIN`) unless the storefront sends a CSP of its
|
|
14
|
+
* own, which it then keeps — the same mechanism the hand-back page's
|
|
15
|
+
* `form-action` relies on (PE-994). A visit's pages therefore answer a CSP
|
|
16
|
+
* whose `frame-ancestors` names the parents the punchout ACCOUNT allows,
|
|
17
|
+
* from the claim. A browser that sees `frame-ancestors` ignores
|
|
18
|
+
* `X-Frame-Options`, so the edge's header needs no change.
|
|
19
|
+
* - **cookies.** Inside a third-party iframe a `SameSite=Lax` cookie is
|
|
20
|
+
* neither stored nor sent, so the buyer would be signed out on the first
|
|
21
|
+
* click. During a visit every cookie the shop sets is `SameSite=None;
|
|
22
|
+
* Secure`, and `Partitioned` when the visit is framed, so a browser that
|
|
23
|
+
* blocks third-party cookies still keeps them inside that one frame. A
|
|
24
|
+
* normal storefront session keeps `lax`.
|
|
25
|
+
*
|
|
26
|
+
* `Partitioned` only for a framed visit: a top-level visit's cookies would
|
|
27
|
+
* otherwise sit beside the buyer's ordinary, unpartitioned ones under the same
|
|
28
|
+
* names, and the shop would read whichever the browser sent first.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One origin as a CSP source: http(s), an optional `*.`, a port, nothing else.
|
|
33
|
+
* The claim already answers checked origins; this is the storefront's own
|
|
34
|
+
* check, because the value goes into a response header.
|
|
35
|
+
*/
|
|
36
|
+
const FRAME_ORIGIN = /^https?:\/\/(?:\*\.)?[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*(?::\d{1,5})?$/;
|
|
37
|
+
|
|
38
|
+
/** At most this many parents reach the header, whatever the claim said. */
|
|
39
|
+
const MAX_FRAME_ANCESTORS = 10;
|
|
40
|
+
|
|
41
|
+
/** The claim's `frame_ancestors`, as the visit keeps them: checked, once each. */
|
|
42
|
+
export function frameAncestorsOf(value: unknown): string[] {
|
|
43
|
+
if (!Array.isArray(value)) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
const origins: string[] = [];
|
|
47
|
+
for (const entry of value) {
|
|
48
|
+
const origin = typeof entry === "string" ? entry.trim().toLowerCase().replace(/\/+$/, "") : "";
|
|
49
|
+
if (FRAME_ORIGIN.test(origin) && !origins.includes(origin)) {
|
|
50
|
+
origins.push(origin);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return origins.slice(0, MAX_FRAME_ANCESTORS);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether this navigation is being loaded into a frame. `Sec-Fetch-Dest` is
|
|
58
|
+
* sent by every current browser on a navigation; a browser that sends none is
|
|
59
|
+
* read as top-level, which keeps its cookies unpartitioned.
|
|
60
|
+
*/
|
|
61
|
+
export function isFramedNavigation(event: H3Event): boolean {
|
|
62
|
+
const dest = String(event.node.req.headers["sec-fetch-dest"] ?? "").toLowerCase();
|
|
63
|
+
return dest === "iframe" || dest === "frame";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The CSP a visit's pages answer: the edge's own default policy, with the
|
|
68
|
+
* account's parents added to `frame-ancestors` and — on the hand-back page
|
|
69
|
+
* only — the visit's return address added to `form-action`.
|
|
70
|
+
*/
|
|
71
|
+
export function punchoutVisitCsp(visit: Pick<PunchoutVisit, "frameAncestors" | "handBackOrigin"> | null, handBackPage: boolean): string {
|
|
72
|
+
const formAction = handBackPage && visit?.handBackOrigin ? `form-action 'self' ${visit.handBackOrigin}` : "form-action 'self'";
|
|
73
|
+
const parents = frameAncestorsOf(visit?.frameAncestors ?? []);
|
|
74
|
+
const frameAncestors = ["frame-ancestors 'self'", ...parents].join(" ");
|
|
75
|
+
return `object-src 'none'; ${formAction}; ${frameAncestors}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** How the visit's cookies are written. */
|
|
79
|
+
export interface PunchoutCookieMode {
|
|
80
|
+
readonly partitioned: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* One `Set-Cookie` value as a visit writes it: `SameSite=None; Secure`, and
|
|
85
|
+
* `Partitioned` for a framed visit. Whatever `SameSite` the setter chose is
|
|
86
|
+
* replaced; everything else — expiry, path, `HttpOnly` — is kept.
|
|
87
|
+
*/
|
|
88
|
+
export function punchoutCookie(setCookie: string, mode: PunchoutCookieMode): string {
|
|
89
|
+
const parts = setCookie.split(";").map(part => part.trim()).filter(Boolean);
|
|
90
|
+
const kept = parts.filter((part, index) => {
|
|
91
|
+
if (index === 0) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
const name = part.split("=")[0]!.trim().toLowerCase();
|
|
95
|
+
return name !== "samesite" && name !== "secure" && name !== "partitioned";
|
|
96
|
+
});
|
|
97
|
+
kept.push("Secure", "SameSite=None");
|
|
98
|
+
if (mode.partitioned) {
|
|
99
|
+
kept.push("Partitioned");
|
|
100
|
+
}
|
|
101
|
+
return kept.join("; ");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The same for a header value as Node holds it: one string or a list. */
|
|
105
|
+
export function punchoutCookies(value: number | string | readonly string[], mode: PunchoutCookieMode): number | string | string[] {
|
|
106
|
+
if (typeof value === "number") {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
return Array.isArray(value)
|
|
110
|
+
? value.map(cookie => punchoutCookie(String(cookie), mode))
|
|
111
|
+
: punchoutCookie(String(value), mode);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Whether a request belongs to a visit, for the cookie rule: the visit cookie
|
|
116
|
+
* is THERE — expired or not, because the request that drops an expired visit
|
|
117
|
+
* has to drop it with the attributes it was set with, or a partitioned cookie
|
|
118
|
+
* is not deleted. Answers the visit's mode, or null outside a visit.
|
|
119
|
+
*/
|
|
120
|
+
export function punchoutCookieModeOf(rawVisitCookie: string | undefined): PunchoutCookieMode | null {
|
|
121
|
+
if (!rawVisitCookie) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const visit = JSON.parse(rawVisitCookie) as Partial<PunchoutVisit> | null;
|
|
126
|
+
return { partitioned: visit?.framed === true };
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return { partitioned: false };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { PunchoutVisit } from "../interfaces/punchout";
|
|
4
|
+
import { purchaseModeOf } from "../../app/shared/punchoutExits";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An order placed inside a punchout visit (RAD-226).
|
|
8
|
+
*
|
|
9
|
+
* The checkout is the ordinary one; two things are added for a visit whose
|
|
10
|
+
* purchase mode lets it order. The order says which visit it came from, so a
|
|
11
|
+
* punchout order is recognisable on its own (in analytics, in the Cockpit).
|
|
12
|
+
* And the punchout app is told the visit ended in an order — for `order`
|
|
13
|
+
* that closes the visit; for `order_and_transfer` the hand-back that follows
|
|
14
|
+
* is what closes it, and the punchout app requires the order for it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** What the order carries about the visit, under `metadata.punchout`. */
|
|
18
|
+
export function punchoutOrderMetadata(visit: PunchoutVisit): { punchout: { account_code: string | null; protocol: string; psid: string } } {
|
|
19
|
+
return { punchout: { account_code: visit.accountCode ?? null, protocol: visit.protocol, psid: visit.psid } };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* After the order exists: mark the visit ordered and, for `order`, close it in
|
|
24
|
+
* the punchout app. Best-effort — the order is placed and the buyer charged,
|
|
25
|
+
* so a punchout app that does not answer is logged, not turned into a failed
|
|
26
|
+
* checkout; the punchout app also reads the order off the visit's cart by
|
|
27
|
+
* itself when the visit is next asked about.
|
|
28
|
+
*/
|
|
29
|
+
export async function settlePunchoutOrder(event: H3Event, visit: PunchoutVisit): Promise<void> {
|
|
30
|
+
updatePunchoutVisit(event, { ordered: true });
|
|
31
|
+
if (purchaseModeOf(visit.purchaseMode) !== "order") {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
await useRevenexxSdk().call("POST", `/v1/punchout/sessions/${encodeURIComponent(visit.psid)}/ordered`, { body: {} });
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
getLogService().error("Punchout visit could not be closed as ordered", apiErrorContext(err));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -4,6 +4,8 @@ import { deleteCookie, getCookie, setCookie } from "h3";
|
|
|
4
4
|
|
|
5
5
|
import type { PunchoutVisitView } from "../../app/interfaces/punchout";
|
|
6
6
|
import type { PunchoutVisit } from "../interfaces/punchout";
|
|
7
|
+
import { SESSION_COOKIE_NAME, sessionCookieOptions } from "./authCookie";
|
|
8
|
+
import { purchaseModeOf } from "../../app/shared/punchoutExits";
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* The storefront's own record of one punchout visit.
|
|
@@ -53,11 +55,23 @@ export function setPunchoutVisit(event: H3Event, visit: PunchoutVisit): void {
|
|
|
53
55
|
* response from paths that have already answered.
|
|
54
56
|
*/
|
|
55
57
|
export function readPunchoutVisit(event: H3Event, now: Date = new Date()): PunchoutVisit | null {
|
|
58
|
+
const visit = readPunchoutVisitRecord(event);
|
|
59
|
+
if (!visit || isLapsed(visit, now)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return visit;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The visit cookie as it was written, a lapsed visit included — for the one
|
|
67
|
+
* question that needs it: may this request still place the visit's order?
|
|
68
|
+
* An order created after the visit's expiry does not count for it (RAD-226).
|
|
69
|
+
*/
|
|
70
|
+
export function readPunchoutVisitRecord(event: H3Event): PunchoutVisit | null {
|
|
56
71
|
const raw = getCookie(event, PUNCHOUT_COOKIE_NAME);
|
|
57
72
|
if (!raw) {
|
|
58
73
|
return null;
|
|
59
74
|
}
|
|
60
|
-
|
|
61
75
|
let visit: PunchoutVisit;
|
|
62
76
|
try {
|
|
63
77
|
visit = JSON.parse(raw) as PunchoutVisit;
|
|
@@ -65,14 +79,20 @@ export function readPunchoutVisit(event: H3Event, now: Date = new Date()): Punch
|
|
|
65
79
|
catch {
|
|
66
80
|
return null;
|
|
67
81
|
}
|
|
82
|
+
return visit?.psid && visit.protocol ? visit : null;
|
|
83
|
+
}
|
|
68
84
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
/** Whether the visit has run out. */
|
|
86
|
+
export function isLapsed(visit: Pick<PunchoutVisit, "expiresAt">, now: Date = new Date()): boolean {
|
|
87
|
+
return Boolean(visit.expiresAt) && new Date(visit.expiresAt).getTime() <= now.getTime();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether the shop is in punchout mode for this visit: hiding and refusing
|
|
92
|
+
* every exit but the visit's own (RAD-226). A visit handed back is over.
|
|
93
|
+
*/
|
|
94
|
+
export function isRestrictingVisit(visit: PunchoutVisit | null): visit is PunchoutVisit {
|
|
95
|
+
return Boolean(visit) && visit!.handedBack !== true;
|
|
76
96
|
}
|
|
77
97
|
|
|
78
98
|
/**
|
|
@@ -83,6 +103,15 @@ export function readPunchoutVisit(event: H3Event, now: Date = new Date()): Punch
|
|
|
83
103
|
export function getPunchoutVisit(event: H3Event, now: Date = new Date()): PunchoutVisit | null {
|
|
84
104
|
const visit = readPunchoutVisit(event, now);
|
|
85
105
|
if (!visit && getCookie(event, PUNCHOUT_COOKIE_NAME)) {
|
|
106
|
+
// A visit that ran out ends together with the buyer's session, as a
|
|
107
|
+
// hand-back does (RAD-226): the shop session was the visit's, signed
|
|
108
|
+
// in by the claim, and must not outlive it on a machine the ERP
|
|
109
|
+
// handed over. Dropping the cookie signs the browser out; the platform
|
|
110
|
+
// session behind it runs out on its own.
|
|
111
|
+
const record = readPunchoutVisitRecord(event);
|
|
112
|
+
if (record && record.handedBack !== true && isLapsed(record, now)) {
|
|
113
|
+
deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
|
|
114
|
+
}
|
|
86
115
|
clearPunchoutVisit(event);
|
|
87
116
|
}
|
|
88
117
|
return visit;
|
|
@@ -119,6 +148,8 @@ export function punchoutVisitView(visit: PunchoutVisit | null): PunchoutVisitVie
|
|
|
119
148
|
cartId: null,
|
|
120
149
|
expiresAt: null,
|
|
121
150
|
handedBack: false,
|
|
151
|
+
purchaseMode: "transfer",
|
|
152
|
+
ordered: false,
|
|
122
153
|
};
|
|
123
154
|
}
|
|
124
155
|
return {
|
|
@@ -130,5 +161,7 @@ export function punchoutVisitView(visit: PunchoutVisit | null): PunchoutVisitVie
|
|
|
130
161
|
cartId: visit.cartId,
|
|
131
162
|
expiresAt: visit.expiresAt,
|
|
132
163
|
handedBack: visit.handedBack === true,
|
|
164
|
+
purchaseMode: purchaseModeOf(visit.purchaseMode),
|
|
165
|
+
ordered: visit.ordered === true,
|
|
133
166
|
};
|
|
134
167
|
}
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
|
|
26
26
|
// Explicit rather than a Nitro auto-import, so the header logic is reachable
|
|
27
27
|
// from a unit test that imports this module.
|
|
28
|
-
import { buyerPrincipal } from "./buyerIdentity";
|
|
28
|
+
import { buyerPrincipal, buyerSession } from "./buyerIdentity";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* The generated revenexx web SDK, configured for the BFF. Every live
|
|
@@ -227,14 +227,15 @@ export function apiErrorContext(err: unknown): Record<string, unknown> {
|
|
|
227
227
|
const clients = new Map<string, RevenexxSdk>();
|
|
228
228
|
|
|
229
229
|
/**
|
|
230
|
-
* The
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* (see
|
|
230
|
+
* The market the current request is made in (requestMarket in ./market.ts):
|
|
231
|
+
* the buyer's choice, else the shop's own market (RAD-479). "" only when
|
|
232
|
+
* neither is known — then no X-Revenexx-Market is sent and the gateway returns
|
|
233
|
+
* only global rows. Per-request, and never part of a cache key (see
|
|
234
|
+
* useRevenexxSdk).
|
|
234
235
|
*/
|
|
235
236
|
function activeMarket(): string {
|
|
236
237
|
try {
|
|
237
|
-
return
|
|
238
|
+
return requestMarket(useEvent()) ?? "";
|
|
238
239
|
}
|
|
239
240
|
catch {
|
|
240
241
|
// No async context (e.g. startup code) — no market scoping.
|
|
@@ -297,6 +298,24 @@ function activePrincipal(): string {
|
|
|
297
298
|
}
|
|
298
299
|
}
|
|
299
300
|
|
|
301
|
+
/**
|
|
302
|
+
* The platform session to assert beside `principal` (RAD-472): the verified
|
|
303
|
+
* buyer's own, and only when the call is made for that very buyer. A call made
|
|
304
|
+
* for nobody, or for a principal a caller named explicitly, carries none.
|
|
305
|
+
*/
|
|
306
|
+
function activeSession(principal: string): string {
|
|
307
|
+
if (!principal) {
|
|
308
|
+
return "";
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
const event = useEvent();
|
|
312
|
+
return principal === buyerPrincipal(event) ? buyerSession(event) : "";
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
return "";
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
300
319
|
export function useRevenexxSdk(options: RevenexxSdkOptions = {}): RevenexxSdk {
|
|
301
320
|
const { tenant, apiKey, jwt, source } = resolveRevenexxCredentials();
|
|
302
321
|
const market = activeMarket();
|
|
@@ -349,6 +368,14 @@ export function useRevenexxSdk(options: RevenexxSdkOptions = {}): RevenexxSdk {
|
|
|
349
368
|
// call made for a buyer, and on none made for nobody.
|
|
350
369
|
if (principal) {
|
|
351
370
|
client.headers["X-Revenexx-Principal"] = principal;
|
|
371
|
+
// The session the buyer holds, so the gateway can tell a session a sales
|
|
372
|
+
// rep opened for them from their own, and name the rep to every app
|
|
373
|
+
// (X-Revenexx-Acting-Rep). It names a rep only for the buyer it belongs
|
|
374
|
+
// to, and never changes who the buyer is.
|
|
375
|
+
const session = activeSession(principal);
|
|
376
|
+
if (session) {
|
|
377
|
+
client.headers["X-Revenexx-Session"] = session;
|
|
378
|
+
}
|
|
352
379
|
}
|
|
353
380
|
// Auth: the brokered context wins — it is a Zitadel JWT the gateway
|
|
354
381
|
// verifies against the same JWKS as any interactive caller, so one theme
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { setResponseHeader } from "h3";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Let the hand-back page submit its form to the visit's return address
|
|
5
|
-
* (PE-994). Which origin: the one the punchout app answered on the first
|
|
6
|
-
* hand-back, kept on the visit cookie. The page is rendered with it in
|
|
7
|
-
* `event.context` so it can tell whether THIS document may submit the form, or
|
|
8
|
-
* has to be loaded once more with the header that allows it.
|
|
9
|
-
*/
|
|
10
|
-
export default defineEventHandler((event) => {
|
|
11
|
-
if (!isHandBackPath(event.path)) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const visit = readPunchoutVisit(event);
|
|
15
|
-
event.context.punchoutHandBackOrigin = visit?.handBackOrigin ?? null;
|
|
16
|
-
setResponseHeader(event, "Content-Security-Policy", handBackFormAction(visit));
|
|
17
|
-
});
|