@revenexx/cover 0.22.1 → 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.
@@ -18,11 +18,12 @@ const cart = useCartStore();
18
18
  const actions = useCartActions();
19
19
  const { calculation, pending } = useCartCalculation();
20
20
  const { settings, role, workflows } = useB2BContext();
21
- // Inside a punchout visit the cart does not end in an order here: it is handed
22
- // back to the buyer's own procurement system, which decides. So the checkout
23
- // CTA is replaced rather than joined — two primary actions would be an
24
- // invitation to order twice.
25
- const { isPunchout, isReadOnly } = usePunchoutVisit();
21
+ // Inside a punchout visit the cart ends where the account's purchase mode says
22
+ // (RAD-226): handed back to the buyer's own procurement system, which decides
23
+ // (`transfer`), or ordered here (`order`, `order_and_transfer`). Outside the
24
+ // checkout of an ordering visit, the checkout CTA is replaced rather than
25
+ // joined — two primary actions would be an invitation to order twice.
26
+ const { isPunchout, isReadOnly, offersCheckout, ordersThenHandsBack } = usePunchoutVisit();
26
27
  const { formatCurrency } = useCartSummaryFormatting();
27
28
 
28
29
  const codeInput = ref("");
@@ -331,7 +332,7 @@ const trustItems = computed(() => {
331
332
 
332
333
  <CartApprovalsPanel :limits="calculation?.approvalLimits ?? []" />
333
334
 
334
- <PunchoutTransferAction v-if="isPunchout" />
335
+ <PunchoutTransferAction v-if="isPunchout && !offersCheckout" />
335
336
  <template v-else-if="quoteMessage">
336
337
  <UButton
337
338
  color="primary"
@@ -370,6 +371,12 @@ const trustItems = computed(() => {
370
371
  >
371
372
  {{ t('cart.cta.notOrderable') }}
372
373
  </p>
374
+ <p
375
+ v-else-if="ordersThenHandsBack"
376
+ class="text-xs text-muted text-center"
377
+ >
378
+ {{ t('punchout.orderAndTransfer.hint') }}
379
+ </p>
373
380
  </template>
374
381
 
375
382
  <!-- Trust: the promises that close B2B orders -->
@@ -17,6 +17,7 @@ const isRequester = computed(() => role.value === "requester");
17
17
  const selectedWorkflowId = useState<string | null>("cart-selected-workflow", () => null);
18
18
  const { to } = useAppUrl();
19
19
  const cart = useCartStore();
20
+ const { ordersThenHandsBack, refresh: refreshPunchoutVisit } = usePunchoutVisit();
20
21
  const { formatCurrency } = useCartSummaryFormatting();
21
22
 
22
23
  // The checkout shows the same server-calculated document as the cart,
@@ -49,6 +50,13 @@ async function handlePlaceOrder() {
49
50
 
50
51
  validateField("acceptedTerms");
51
52
  const result = await submitOrder();
53
+ // `order_and_transfer` (RAD-226): one step — the order, then the hand-back
54
+ // of the ordered cart, which the hand-back page fetches and submits.
55
+ if (result && ordersThenHandsBack.value) {
56
+ await refreshPunchoutVisit();
57
+ await navigateTo(to("/punchout/transfer"));
58
+ return;
59
+ }
52
60
  if (result) {
53
61
  await navigateTo(to("/checkout/confirmation", {
54
62
  id: result.orderId,
@@ -22,6 +22,7 @@ const { icon } = useIcons();
22
22
  const { to } = useAppUrl();
23
23
  const localePath = useLocalePath();
24
24
  const route = useRoute();
25
+ const { ordersThenHandsBack, refresh: refreshPunchoutVisit } = usePunchoutVisit();
25
26
 
26
27
  const orderId = computed(() => {
27
28
  const raw = route.query[PSP_RETURN_ORDER_PARAM];
@@ -52,6 +53,12 @@ async function confirm(): Promise<void> {
52
53
  );
53
54
  canRetryFromAccount.value = answer.canRetryFromAccount;
54
55
  retryUrl.value = answer.retryUrl ?? null;
56
+ if (answer.outcome === "paid" && ordersThenHandsBack.value) {
57
+ // `order_and_transfer` (RAD-226): the paid order is handed back next.
58
+ await refreshPunchoutVisit();
59
+ await navigateTo(to("/punchout/transfer"), { replace: true });
60
+ return;
61
+ }
55
62
  if (answer.outcome === "paid") {
56
63
  await navigateTo(to("/checkout/confirmation", { id: answer.orderId }), { replace: true });
57
64
  return;
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import type { ShopContact } from "../../../config/navigation";
3
3
  import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact as noContact, withdrawalPath } from "../../../config/navigation";
4
+ import { punchoutRefusal } from "../../../shared/punchoutExits";
4
5
 
5
6
  // Consumers replace the footer columns / legal links, in priority order:
6
7
  // per-request live menus (useState, e.g. the Blokkli theme from the pages app)
@@ -14,11 +15,24 @@ import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, sho
14
15
  const appConfig = useAppConfig();
15
16
  const liveFooterLinks = useState<{ heading: string; links: { label: string; to: string }[] }[] | null>("cover:nav:footerLinks", () => null);
16
17
  const liveLegalLinks = useState<{ label: string; to: string }[] | null>("cover:nav:legalLinks", () => null);
17
- const footerLinks = computed(() => liveFooterLinks.value ?? (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks);
18
+ // Punchout mode (RAD-226): a live visit has one way out, its own action in the
19
+ // cart, so the footer keeps only the links that stay inside the shop and lead
20
+ // somewhere the visit may go — no external site, no account page.
21
+ const { isRestricted, visit } = usePunchoutVisit();
22
+ const staysInVisit = (to: string) => !isRestricted.value || (to.startsWith("/") && !to.startsWith("//") && !punchoutRefusal(to, "GET", visit.value));
23
+ const footerLinks = computed(() => {
24
+ const groups = liveFooterLinks.value ?? (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks;
25
+ if (!isRestricted.value || !Array.isArray(groups)) {
26
+ return groups;
27
+ }
28
+ return groups
29
+ .map(group => ({ ...group, links: group.links.filter(link => staysInVisit(link.to)) }))
30
+ .filter(group => group.links.length > 0);
31
+ });
18
32
  // The withdrawal entry is rendered on its own below, so a tenant menu that
19
33
  // already lists it does not print it twice.
20
34
  const legalLinks = computed(() => (liveLegalLinks.value ?? (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks)
21
- .filter(link => link.to !== withdrawalPath));
35
+ .filter(link => link.to !== withdrawalPath && staysInVisit(link.to)));
22
36
  // The shop's own contact details. The design system holds none, so a storefront
23
37
  // that states nothing prints nothing rather than somebody else's address.
24
38
  const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopContact | undefined) ?? noContact);
@@ -166,8 +180,11 @@ const year = new Date().getFullYear();
166
180
  </ConsentPreferencesLink>
167
181
  </nav>
168
182
 
169
- <!-- Social icons -->
170
- <div class="flex items-center gap-1">
183
+ <!-- Social icons — not in a punchout visit, which never leaves the shop -->
184
+ <div
185
+ v-if="!isRestricted"
186
+ class="flex items-center gap-1"
187
+ >
171
188
  <UButton
172
189
  to="https://linkedin.com"
173
190
  target="_blank"
@@ -41,6 +41,8 @@ onMounted(() => {
41
41
  onUnmounted(() => mq?.removeEventListener("change", closeMenu));
42
42
 
43
43
  const { navigateToSearch } = useSearch();
44
+ // Punchout mode (RAD-226): the account area and signing in or out are hidden.
45
+ const { isRestricted } = usePunchoutVisit();
44
46
  </script>
45
47
 
46
48
  <template>
@@ -70,13 +72,14 @@ const { navigateToSearch } = useSearch();
70
72
 
71
73
  <template #right>
72
74
  <LayoutHeaderActionItem
73
- v-if="features.directOrder !== false"
75
+ v-if="features.directOrder !== false && !isRestricted"
74
76
  :icon="icon('direct-order')"
75
77
  :label="t('topbar.directOrder')"
76
78
  :to="localePath('/account/direct-order')"
77
79
  class="hidden md:flex"
78
80
  />
79
- <AccountMenu />
81
+ <!-- Not in a punchout visit: it has no account area, and signing in or out is not its exit (RAD-226) -->
82
+ <AccountMenu v-if="!isRestricted" />
80
83
  <CartButton />
81
84
  </template>
82
85
 
@@ -9,6 +9,7 @@ const { categoryNavItems } = useCategories();
9
9
  // buyer on a phone had no way to search at all.
10
10
  const { navigateToSearch } = useSearch();
11
11
  const auth = useAuthStore();
12
+ const { isRestricted } = usePunchoutVisit();
12
13
  const toast = useToast();
13
14
  const { t } = useI18n();
14
15
  const localePath = useLocalePath();
@@ -66,7 +67,9 @@ const onLogout = async () => {
66
67
 
67
68
  <USeparator class="md:hidden" />
68
69
 
69
- <template v-if="auth.isLoggedIn">
70
+ <!-- Punchout mode (RAD-226): no account area, no signing in or out -->
71
+ <template v-if="isRestricted" />
72
+ <template v-else-if="auth.isLoggedIn">
70
73
  <UNavigationMenu
71
74
  :items="accountLinks"
72
75
  orientation="vertical"
@@ -2,7 +2,8 @@
2
2
  /**
3
3
  * "Transfer cart" — the end of a punchout visit, as the buyer meets it.
4
4
  *
5
- * Offered ONLY inside a punchout session, and worded by that session's
5
+ * Offered ONLY inside a punchout session whose purchase mode hands the cart
6
+ * back (RAD-226) — after the order, for `order_and_transfer` — and worded by that session's
6
7
  * protocol: the same button is "transfer the basket back" to an SRM buyer,
7
8
  * "return the requisition" to a cXML one and "send the cart to your trade
8
9
  * software" to an IDS craftsman.
@@ -15,7 +16,7 @@
15
16
  const { icon } = useIcons();
16
17
  const { t } = useI18n();
17
18
  const { to } = useAppUrl();
18
- const { isPunchout, isReadOnly, protocol, transferLabelKey } = usePunchoutVisit();
19
+ const { isReadOnly, offersHandBack, protocol, transferLabelKey } = usePunchoutVisit();
19
20
  const cart = useCartStore();
20
21
 
21
22
  const props = withDefaults(defineProps<{
@@ -33,7 +34,7 @@ const isEmpty = computed(() => cart.items.length === 0);
33
34
 
34
35
  <template>
35
36
  <div
36
- v-if="isPunchout"
37
+ v-if="offersHandBack"
37
38
  class="space-y-2"
38
39
  >
39
40
  <UButton
@@ -1,4 +1,5 @@
1
1
  import type { PunchoutVisitView } from "../interfaces/punchout";
2
+ import { punchoutExits } from "../shared/punchoutExits";
2
3
 
3
4
  const EMPTY: PunchoutVisitView = {
4
5
  active: false,
@@ -9,6 +10,8 @@ const EMPTY: PunchoutVisitView = {
9
10
  cartId: null,
10
11
  expiresAt: null,
11
12
  handedBack: false,
13
+ purchaseMode: "transfer",
14
+ ordered: false,
12
15
  };
13
16
 
14
17
  /**
@@ -51,5 +54,37 @@ export function usePunchoutVisit() {
51
54
  `punchout.transfer.action.${visit.value.protocol ?? "oci"}`,
52
55
  );
53
56
 
54
- return { visit, isPunchout, isReadOnly, protocol, transferLabelKey, refresh };
57
+ /**
58
+ * Punchout mode (RAD-226): a live visit offers only its own exits, and
59
+ * the shop hides every other way out — the account area, signing in or
60
+ * out, registering, links that leave the shop. Over once the cart was
61
+ * handed back.
62
+ */
63
+ const isRestricted = computed(() => visit.value.active && !visit.value.handedBack);
64
+ const exits = computed(() => punchoutExits(visit.value));
65
+ /** The checkout places this visit's order — `order`, or `order_and_transfer`. */
66
+ const offersCheckout = computed(() => isRestricted.value && exits.value.checkout);
67
+ /**
68
+ * The cart is handed back — `transfer`, or after the order in
69
+ * `order_and_transfer`, whose hand-back the punchout app refuses without
70
+ * the order. Still true once handed back, so the hand-back page can
71
+ * replay it.
72
+ */
73
+ const offersHandBack = computed(() => isPunchout.value && exits.value.handBack
74
+ && (visit.value.purchaseMode !== "order_and_transfer" || visit.value.ordered || visit.value.handedBack));
75
+ /** The checkout is followed by the hand-back, as one step. */
76
+ const ordersThenHandsBack = computed(() => isPunchout.value && visit.value.purchaseMode === "order_and_transfer");
77
+
78
+ return {
79
+ visit,
80
+ isPunchout,
81
+ isReadOnly,
82
+ isRestricted,
83
+ offersCheckout,
84
+ offersHandBack,
85
+ ordersThenHandsBack,
86
+ protocol,
87
+ transferLabelKey,
88
+ refresh,
89
+ };
55
90
  }
@@ -11,6 +11,13 @@
11
11
  /** The three protocols a visit can be entered by. */
12
12
  export type PunchoutProtocol = "oci" | "cxml" | "ids";
13
13
 
14
+ /**
15
+ * Which exit a visit has, as the punchout account says: hand the cart back,
16
+ * order in the shop, or order and then hand the ordered cart back in one step.
17
+ * Anything but `transfer` is IDS only.
18
+ */
19
+ export type PunchoutPurchaseMode = "transfer" | "order" | "order_and_transfer";
20
+
14
21
  /**
15
22
  * What the visit is FOR, in the punchout app's own words rather than any
16
23
  * protocol's. The shop branches on this and never on OCI's `FUNCTION`, cXML's
@@ -47,6 +54,10 @@ export interface PunchoutVisitView {
47
54
  readonly expiresAt: string | null;
48
55
  /** True once the cart has been handed back — the visit is over. */
49
56
  readonly handedBack: boolean;
57
+ /** Which exit the visit has; `transfer` outside a visit too. */
58
+ readonly purchaseMode: PunchoutPurchaseMode;
59
+ /** True once the checkout placed this visit's order. */
60
+ readonly ordered: boolean;
50
61
  }
51
62
 
52
63
  /**
@@ -0,0 +1,25 @@
1
+ import type { PunchoutVisitView } from "../interfaces/punchout";
2
+ import { punchoutRefusal } from "../shared/punchoutExits";
3
+
4
+ /**
5
+ * Punchout mode inside the app (RAD-226): a link followed during a live visit
6
+ * to an exit the visit does not have — the account area, signing in, the
7
+ * checkout of a visit that only hands its cart back — goes to the visit's
8
+ * cart instead. The same rules as the BFF's, which holds them for a typed
9
+ * address; this half covers a navigation the server never sees.
10
+ *
11
+ * Reads the visit the shop shell already fetched rather than asking again:
12
+ * on the first page load the server has decided, and every later navigation
13
+ * finds it in the payload.
14
+ */
15
+ export default defineNuxtRouteMiddleware((to) => {
16
+ const { data } = useNuxtData<PunchoutVisitView>("punchout-visit");
17
+ const visit = data.value;
18
+ if (!visit?.active || visit.handedBack) {
19
+ return;
20
+ }
21
+ const refusal = punchoutRefusal(to.path, "GET", visit);
22
+ if (refusal?.kind === "redirect") {
23
+ return navigateTo(refusal.to, { replace: true });
24
+ }
25
+ });
@@ -0,0 +1,46 @@
1
+ import type { PunchoutVisitView } from "../interfaces/punchout";
2
+
3
+ /**
4
+ * Punchout mode for links the shop does not render itself (RAD-226): CMS
5
+ * content, a product description, a tenant's footer menu. During a live
6
+ * visit a link that would leave the shop does nothing, and a link that would
7
+ * open a new window opens in place — the visit runs inside the buyer's
8
+ * procurement system, and a window or a site outside it is a way out that
9
+ * strands the cart.
10
+ *
11
+ * One listener on the document rather than a rule in every component: the
12
+ * links that matter here are exactly the ones no component knows about.
13
+ */
14
+ export default defineNuxtPlugin(() => {
15
+ const visit = () => useNuxtData<PunchoutVisitView>("punchout-visit").data.value;
16
+
17
+ document.addEventListener("click", (event) => {
18
+ const current = visit();
19
+ if (!current?.active || current.handedBack || event.defaultPrevented) {
20
+ return;
21
+ }
22
+ const anchor = (event.target as Element | null)?.closest?.("a[href]") as HTMLAnchorElement | null;
23
+ if (!anchor) {
24
+ return;
25
+ }
26
+ let url: URL;
27
+ try {
28
+ url = new URL(anchor.href, window.location.href);
29
+ }
30
+ catch {
31
+ return;
32
+ }
33
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
34
+ // mailto:, tel: — they open another program, not another site.
35
+ return;
36
+ }
37
+ if (url.origin !== window.location.origin) {
38
+ event.preventDefault();
39
+ return;
40
+ }
41
+ if (anchor.target && anchor.target !== "_self") {
42
+ event.preventDefault();
43
+ void navigateTo(`${url.pathname}${url.search}${url.hash}`);
44
+ }
45
+ }, true);
46
+ });
@@ -0,0 +1,156 @@
1
+ import type { PunchoutPurchaseMode } from "../interfaces/punchout";
2
+
3
+ /** What the rules read off a visit — the server's record and the browser's view alike. */
4
+ export interface PunchoutExitVisit {
5
+ readonly purchaseMode?: PunchoutPurchaseMode | null;
6
+ /** The checkout placed this visit's order. */
7
+ readonly ordered?: boolean;
8
+ }
9
+
10
+ /**
11
+ * The exits a punchout visit has, and the routes it may not reach (RAD-226).
12
+ *
13
+ * A punchout visit runs inside the buyer's procurement system and has one way
14
+ * out: the one its account's purchase mode names. Everything a storefront
15
+ * session offers besides — the account area, signing in or out, registering,
16
+ * the checkout of a visit that only hands its cart back — is hidden in the
17
+ * shop AND refused here, because a buyer can type an address.
18
+ *
19
+ * Shared by the BFF (a typed address, a full page load) and the shop's route
20
+ * middleware (a link followed inside the app), so the two cannot disagree.
21
+ *
22
+ * The rule holds only while the visit is live. A visit that was handed back,
23
+ * or that ran out, is over, and the shop is an ordinary shop again.
24
+ */
25
+
26
+ /** A purchase mode the claim did not answer is `transfer` (punchout's own default). */
27
+ export function purchaseModeOf(value: unknown): PunchoutPurchaseMode {
28
+ return value === "order" || value === "order_and_transfer" ? value : "transfer";
29
+ }
30
+
31
+ export interface PunchoutExits {
32
+ /** The shop's checkout places an order. */
33
+ readonly checkout: boolean;
34
+ /** The cart can be handed back to the procurement system. */
35
+ readonly handBack: boolean;
36
+ }
37
+
38
+ /**
39
+ * Which exits a visit offers.
40
+ *
41
+ * `order_and_transfer` offers both, as ONE step: the checkout, and then the
42
+ * hand-back of the ordered cart, which the punchout app refuses without the
43
+ * order. A visit already ordered in `order` mode has no exit left.
44
+ */
45
+ export function punchoutExits(visit: PunchoutExitVisit): PunchoutExits {
46
+ const mode = purchaseModeOf(visit.purchaseMode);
47
+ if (mode === "order") {
48
+ return { checkout: visit.ordered !== true, handBack: false };
49
+ }
50
+ if (mode === "order_and_transfer") {
51
+ return { checkout: visit.ordered !== true, handBack: true };
52
+ }
53
+ return { checkout: false, handBack: true };
54
+ }
55
+
56
+ /** A path without its locale prefix (`/de/account` → `/account`) and query. */
57
+ export function unprefixedPath(path: string): { readonly prefix: string; readonly rest: string } {
58
+ const bare = (path.split("?")[0] ?? "/").replace(/\/+$/, "") || "/";
59
+ const match = /^\/([a-z]{2}(?:-[a-z]{2})?)(\/.*|$)/i.exec(bare);
60
+ // `/de` alone is the home page in that locale, not a page called `de`.
61
+ if (match && !/^\/(api|_nuxt|punchout)\b/.test(bare)) {
62
+ return { prefix: `/${match[1]}`, rest: match[2] || "/" };
63
+ }
64
+ return { prefix: "", rest: bare };
65
+ }
66
+
67
+ /** Pages a live visit never shows: the account area and everything about signing in. */
68
+ const PAGES_NEVER = [
69
+ /^\/account(?:\/|$)/,
70
+ /^\/login(?:\/|$)/,
71
+ /^\/register(?:\/|$)/,
72
+ /^\/forgot-password$/,
73
+ /^\/reset-password$/,
74
+ /^\/callback$/,
75
+ ];
76
+
77
+ /** The checkout pages — only for a visit that may order. */
78
+ const CHECKOUT_PAGES = /^\/checkout(?:\/|$)/;
79
+ /** The hand-back page — only for a visit that may hand back. */
80
+ const HAND_BACK_PAGE = /^\/punchout\/transfer$/;
81
+
82
+ /** BFF routes a live visit never calls: signing in or out, registering, recovering a password. */
83
+ const API_NEVER = [
84
+ /^\/api\/auth\/(?:login|logout|register|recovery|magic-link|otp)$/,
85
+ ];
86
+
87
+ /** BFF routes that place an order. */
88
+ const CHECKOUT_API = [
89
+ /^\/api\/orders$/,
90
+ /^\/api\/checkout\/session$/,
91
+ ];
92
+
93
+ /** The BFF route that hands the cart back. */
94
+ const HAND_BACK_API = /^\/api\/punchout\/return$/;
95
+
96
+ export type PunchoutRefusal =
97
+ | { readonly kind: "redirect"; readonly to: string }
98
+ | { readonly kind: "refuse"; readonly type: "punchout_exit_not_offered" | "punchout_session_closed" };
99
+
100
+ /**
101
+ * What a live visit does with this request: nothing (null), send the page back
102
+ * to the visit's cart, or refuse the call.
103
+ *
104
+ * Only state-changing calls are refused on the BFF side: what a buyer READS
105
+ * about their own account is theirs to read, and a product page that asks
106
+ * for an order list should not break because the visit has no account area.
107
+ */
108
+ export function punchoutRefusal(
109
+ path: string,
110
+ method: string,
111
+ visit: PunchoutExitVisit,
112
+ ): PunchoutRefusal | null {
113
+ const { prefix, rest } = unprefixedPath(path);
114
+ const exits = punchoutExits(visit);
115
+ const back: PunchoutRefusal = { kind: "redirect", to: `${prefix}/cart` };
116
+
117
+ if (rest.startsWith("/api/")) {
118
+ const writes = method.toUpperCase() !== "GET" && method.toUpperCase() !== "HEAD";
119
+ if (!writes) {
120
+ return null;
121
+ }
122
+ if (API_NEVER.some(rule => rule.test(rest))) {
123
+ return { kind: "refuse", type: "punchout_exit_not_offered" };
124
+ }
125
+ if (!exits.checkout && CHECKOUT_API.some(rule => rule.test(rest))) {
126
+ return { kind: "refuse", type: "punchout_exit_not_offered" };
127
+ }
128
+ if (!exits.handBack && HAND_BACK_API.test(rest)) {
129
+ return { kind: "refuse", type: "punchout_exit_not_offered" };
130
+ }
131
+ return null;
132
+ }
133
+
134
+ if (PAGES_NEVER.some(rule => rule.test(rest))) {
135
+ return back;
136
+ }
137
+ // The confirmation of the order this visit placed stays reachable: the
138
+ // buyer has to be able to read what they ordered.
139
+ if (!exits.checkout && CHECKOUT_PAGES.test(rest) && !(visit.ordered === true && rest === "/checkout/confirmation")) {
140
+ return back;
141
+ }
142
+ if (!exits.handBack && HAND_BACK_PAGE.test(rest)) {
143
+ return back;
144
+ }
145
+ return null;
146
+ }
147
+
148
+ /**
149
+ * The checkout calls a visit that RAN OUT may not make: an order created after
150
+ * the visit's expiry does not count for it, and the buyer would have placed
151
+ * an order their procurement system never hears of.
152
+ */
153
+ export function isCheckoutCall(path: string, method: string): boolean {
154
+ const { rest } = unprefixedPath(path);
155
+ return method.toUpperCase() === "POST" && CHECKOUT_API.some(rule => rule.test(rest));
156
+ }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.22.1",
3
+ "version": "0.23.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",
@@ -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,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
 
@@ -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
- if (!visit?.psid || !visit.protocol) {
70
- return null;
71
- }
72
- if (visit.expiresAt && new Date(visit.expiresAt).getTime() <= now.getTime()) {
73
- return null;
74
- }
75
- return visit;
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
  }
@@ -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
- });