@revenexx/cover 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/components/account/approvals/AccountPendingApprovals.vue +54 -13
- package/app/components/account/approvals/AccountPendingOrderDetail.vue +156 -0
- package/app/components/account/orders/AccountOrderContents.vue +142 -0
- package/app/components/account/orders/AccountOrderDetail.vue +16 -178
- package/app/components/account/orders/AccountOrderHead.vue +79 -0
- package/app/components/account/orders/AccountOrderPay.vue +13 -3
- package/app/components/account/orders/AccountOrdersTable.vue +2 -0
- package/app/components/cart/position/CartPosition.vue +6 -6
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +20 -8
- package/app/components/checkout/return/CheckoutPaymentReturn.vue +209 -0
- package/app/composables/useAccountDashboard.ts +1 -0
- package/app/composables/useCheckoutOnePage.ts +71 -7
- package/app/composables/usePendingApprovals.ts +11 -3
- package/app/composables/usePspCheckout.ts +130 -29
- package/app/config/colorRamp.ts +55 -0
- package/app/interfaces/account/approvals.ts +34 -1
- package/app/interfaces/account/order-list.ts +8 -1
- package/app/interfaces/cart-calculation.ts +7 -1
- package/app/interfaces/cart-item.ts +12 -0
- package/app/interfaces/payment.ts +22 -0
- package/app/pages/checkout/payment-return.vue +17 -0
- package/app/payments/psp/novalnet.ts +254 -0
- package/app/payments/psp/registry.ts +7 -3
- package/app/payments/psp/rules.ts +99 -0
- package/app/payments/psp/stripe.ts +6 -2
- package/app/payments/psp/types.ts +72 -6
- package/app/shared/pspReturn.ts +62 -0
- package/i18n/locales/de/account.json +17 -3
- package/i18n/locales/de/cart.json +4 -2
- package/i18n/locales/de/checkout.json +32 -0
- package/i18n/locales/de/editor.json +10 -0
- package/i18n/locales/en/account.json +17 -3
- package/i18n/locales/en/cart.json +4 -2
- package/i18n/locales/en/checkout.json +32 -0
- package/i18n/locales/en/editor.json +10 -0
- package/package.json +3 -2
- package/server/api/account/orders/[id]/pay.post.ts +47 -7
- package/server/api/account/pending-approvals/index.get.ts +16 -12
- package/server/api/account/pending-approvals/orders/[number]/approve.post.ts +6 -0
- package/server/api/account/pending-approvals/orders/[number]/reject.post.ts +6 -0
- package/server/api/account/pending-approvals/orders/[number].get.ts +15 -0
- package/server/api/checkout/payment-return.post.ts +30 -0
- package/server/api/orders/index.post.ts +37 -11
- package/server/api/payment/methods.post.ts +19 -9
- package/server/api/payment/psp-config.get.ts +5 -4
- package/server/services/ApiCartService.ts +6 -0
- package/server/services/ApiProductService.ts +6 -2
- package/server/services/MockCartCalculationService.ts +29 -0
- package/server/utils/cartItemHints.ts +29 -0
- package/server/utils/checkoutSession.ts +16 -0
- package/server/utils/liveCatalog.ts +244 -31
- package/server/utils/liveOrders.ts +33 -0
- package/server/utils/orderPayment.ts +79 -0
- package/server/utils/pendingApprovals.ts +157 -2
- package/server/utils/procurementCheckout.ts +5 -0
- package/server/utils/pspConfig.ts +125 -13
- package/server/utils/pspReturn.ts +267 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { PendingApprovalsResponse } from "../../../../app/interfaces/account/approvals";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* What is waiting on this approver
|
|
4
|
+
* What is waiting on this approver: the procurement layers waiting on them, and
|
|
5
|
+
* the orders of their company waiting in the orders app (RAD-229) — one inbox,
|
|
6
|
+
* because the approver signs in with one question.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
* different model with no queue behind them, and a made-up row here would put a
|
|
8
|
+
* Each half is empty where its source is not live: the demo's approval limits are
|
|
9
|
+
* a different model with no queue behind them, and a made-up row here would put a
|
|
8
10
|
* decision in front of somebody that nothing would record.
|
|
9
11
|
*/
|
|
10
12
|
export default defineEventHandler(async (event): Promise<PendingApprovalsResponse> => {
|
|
@@ -12,15 +14,17 @@ export default defineEventHandler(async (event): Promise<PendingApprovalsRespons
|
|
|
12
14
|
if (!user) {
|
|
13
15
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
14
16
|
}
|
|
15
|
-
if (!isProcurementLive(event)) {
|
|
16
|
-
return { approvals: [] };
|
|
17
|
-
}
|
|
18
17
|
|
|
19
18
|
const refs = sessionOrderRefs(event);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const [requests, orders] = await Promise.all([
|
|
20
|
+
isProcurementLive(event)
|
|
21
|
+
? listPendingApprovals(event, {
|
|
22
|
+
...(user.contactId ?? refs?.contact_id ? { contactId: (user.contactId ?? refs?.contact_id) as string } : {}),
|
|
23
|
+
...(user.role ? { role: user.role } : {}),
|
|
24
|
+
...(user.organizationId ? { organizationId: user.organizationId } : {}),
|
|
25
|
+
})
|
|
26
|
+
: [],
|
|
27
|
+
listPendingOrderApprovals(event, user),
|
|
28
|
+
]);
|
|
29
|
+
return { approvals: [...requests, ...orders] };
|
|
26
30
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PendingOrderDetail } from "../../../../../app/interfaces/account/approvals";
|
|
2
|
+
|
|
3
|
+
/** A colleague's order, as the person who may approve it sees it (RAD-229). */
|
|
4
|
+
export default defineEventHandler(async (event): Promise<PendingOrderDetail> => {
|
|
5
|
+
try {
|
|
6
|
+
return await readPendingOrder(event);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
if (isError(err)) {
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
getLogService().error("Pending order detail failed", apiErrorContext(err));
|
|
13
|
+
throw createError({ statusCode: 502, message: "Order service unavailable" });
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { pspReturnParams } from "../../../app/shared/pspReturn";
|
|
2
|
+
import { confirmPspReturn } from "../../utils/pspReturn";
|
|
3
|
+
|
|
4
|
+
interface PaymentReturnPayload {
|
|
5
|
+
/** The order's number, as the return address carried it (`?order=`). */
|
|
6
|
+
order?: string;
|
|
7
|
+
/** Every query parameter the provider returned the buyer with, `rx_payment` included. */
|
|
8
|
+
params?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The return from a payment provider (FE-5): confirm the payment the buyer was
|
|
13
|
+
* sent off for, and say how it ended — `paid`, `failed` or `pending`.
|
|
14
|
+
*
|
|
15
|
+
* Provider-agnostic: the payments app reads the provider's own parameters.
|
|
16
|
+
* Not an open confirm proxy: only the payment of the order the return names,
|
|
17
|
+
* and only for the browser the checkout sent off, or the buyer whose order it
|
|
18
|
+
* is (see utils/pspReturn.ts). Anything else is a 404.
|
|
19
|
+
*/
|
|
20
|
+
export default defineEventHandler(async (event) => {
|
|
21
|
+
if (resolvePaymentServiceKey(event) !== "api") {
|
|
22
|
+
throw createError({ statusCode: 501, message: "This storefront does not take payments on demo data" });
|
|
23
|
+
}
|
|
24
|
+
const body = await readBody<PaymentReturnPayload>(event).catch(() => ({} as PaymentReturnPayload));
|
|
25
|
+
const params = pspReturnParams(body?.params && typeof body.params === "object" ? body.params : {});
|
|
26
|
+
return await confirmPspReturn(event, {
|
|
27
|
+
order: typeof body?.order === "string" ? body.order : "",
|
|
28
|
+
params,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -5,7 +5,14 @@ import { addressRefusalOf } from "../../utils/addressRefusal";
|
|
|
5
5
|
import { type EligibleMethodFee, paymentFee } from "../../utils/paymentFee";
|
|
6
6
|
import { orderLinePrices, type PriceResolveAnswer } from "../../utils/orderLinePrices";
|
|
7
7
|
import { toIsoCountry } from "../../utils/country";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
checkoutTakesPayment,
|
|
10
|
+
orderPaymentRequest,
|
|
11
|
+
paymentCustomerOf,
|
|
12
|
+
recordOrderPaymentStatus,
|
|
13
|
+
sanitizePaymentInstrument,
|
|
14
|
+
} from "../../utils/orderPayment";
|
|
15
|
+
import { pspReturnUrl, rememberPspReturn } from "../../utils/pspReturn";
|
|
9
16
|
import { placeOrderWithAttribution } from "../../utils/orderAttribution";
|
|
10
17
|
import { sanitizeAttribution } from "../../../app/shared/campaignAttribution";
|
|
11
18
|
|
|
@@ -42,10 +49,12 @@ interface OrderPayload {
|
|
|
42
49
|
promoCode?: string;
|
|
43
50
|
/** The codes the buyer entered on the cart, carried to the engine at submit. */
|
|
44
51
|
voucherCodes?: string[];
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
/**
|
|
53
|
+
* From the checkout's client-side tokenizer: a provider instrument
|
|
54
|
+
* (`{ type: "<provider>_<kind>", … }`) or the legacy single-use token
|
|
55
|
+
* (Stripe pm_…). Neither = the PSP's hosted page.
|
|
56
|
+
*/
|
|
57
|
+
paymentInstrument?: { token?: string; instrument?: Record<string, unknown> };
|
|
49
58
|
/**
|
|
50
59
|
* Where the visit came from (RAD-293), as the browser kept it under the
|
|
51
60
|
* visitor's consent. Rebuilt into the closed shape before it travels.
|
|
@@ -577,10 +586,13 @@ export default defineEventHandler(async (event) => {
|
|
|
577
586
|
? address?.billing as Record<string, unknown> | undefined
|
|
578
587
|
: address;
|
|
579
588
|
const country = toIsoCountry(body.billingCountry ?? billing?.country ?? "");
|
|
580
|
-
// The instrument (PSP token from the checkout's
|
|
581
|
-
// is forwarded
|
|
582
|
-
// fields, so the create goes through the low-level
|
|
583
|
-
|
|
589
|
+
// The instrument (PSP token or instrument from the checkout's
|
|
590
|
+
// client-side tokenizer) is forwarded; paymentsCreate's typed params
|
|
591
|
+
// drop unknown fields, so the create goes through the low-level
|
|
592
|
+
// transport. Where the PSP returns the buyer is built HERE, on this
|
|
593
|
+
// request's own host, never taken from the browser (FE-5).
|
|
594
|
+
const instrument = body.paymentInstrument;
|
|
595
|
+
const token = typeof instrument?.token === "string" && instrument.token ? instrument.token : undefined;
|
|
584
596
|
const payerContactId = principalContactId(event);
|
|
585
597
|
try {
|
|
586
598
|
const created = await useRevenexxSdk().call<{ id: string; status: string; error_message?: string | null; next_action?: { type?: string; url?: string } | null }>(
|
|
@@ -597,8 +609,19 @@ export default defineEventHandler(async (event) => {
|
|
|
597
609
|
orderId: liveOrderUuid,
|
|
598
610
|
contactId: payerContactId,
|
|
599
611
|
idempotencyKey: body.checkoutSessionToken,
|
|
600
|
-
token
|
|
601
|
-
|
|
612
|
+
token,
|
|
613
|
+
instrument: sanitizePaymentInstrument(instrument?.instrument),
|
|
614
|
+
returnUrl: pspReturnUrl(event, orderId),
|
|
615
|
+
// Who pays, for the provider's fraud and 3-D Secure checks
|
|
616
|
+
// (RAD-364) — the billing address and the order's e-mail.
|
|
617
|
+
customer: paymentCustomerOf({
|
|
618
|
+
email: user?.email ?? body.contactEmail ?? null,
|
|
619
|
+
contactName: (billing?.contactName ?? address?.contactName) as string | undefined,
|
|
620
|
+
ip: getRequestIP(event, { xForwardedFor: true }) ?? null,
|
|
621
|
+
billing: billing ?? null,
|
|
622
|
+
countryCode: country || null,
|
|
623
|
+
}),
|
|
624
|
+
language: locale,
|
|
602
625
|
metadata: {
|
|
603
626
|
...(payment.poNumber ? { po_number: payment.poNumber } : {}),
|
|
604
627
|
...(payment.costCenter ? { cost_center: payment.costCenter } : {}),
|
|
@@ -612,6 +635,9 @@ export default defineEventHandler(async (event) => {
|
|
|
612
635
|
if (created.status === "requires_action" && created.next_action?.url) {
|
|
613
636
|
// Order stays placed (payment pending); buyer completes at the PSP.
|
|
614
637
|
pendingAction = { paymentId: created.id, redirectUrl: created.next_action.url };
|
|
638
|
+
// The return page may confirm this payment for this browser
|
|
639
|
+
// only — a guest has no other claim to it (FE-5).
|
|
640
|
+
rememberPspReturn(event, { paymentId: created.id, orderRef: orderId, orderUuid: liveOrderUuid });
|
|
615
641
|
}
|
|
616
642
|
livePaymentStatus = created.status;
|
|
617
643
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PaymentOption } from "../../../app/interfaces/payment";
|
|
2
2
|
import type { Locale } from "../../utils/locale";
|
|
3
|
+
import { type ApiMethodCheckout, paymentCheckoutOf } from "../../utils/pspConfig";
|
|
3
4
|
|
|
4
5
|
/** Eligible method row of the payments app. */
|
|
5
6
|
interface ApiEligibleMethod {
|
|
@@ -13,6 +14,8 @@ interface ApiEligibleMethod {
|
|
|
13
14
|
fee_type: "none" | "fixed" | "percent";
|
|
14
15
|
currency: string;
|
|
15
16
|
position: number;
|
|
17
|
+
/** How a PSP method takes the instrument (RAD-364); null for self-managed ones. */
|
|
18
|
+
checkout?: ApiMethodCheckout | null;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -44,15 +47,22 @@ export default defineEventHandler(async (event) => {
|
|
|
44
47
|
currency,
|
|
45
48
|
}) as unknown as { methods: ApiEligibleMethod[] };
|
|
46
49
|
|
|
47
|
-
const options: PaymentOption[] = methods.map(m =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const options: PaymentOption[] = methods.map((m) => {
|
|
51
|
+
const checkout = paymentCheckoutOf(m.checkout);
|
|
52
|
+
// The checkout block names the provider the payment would actually go
|
|
53
|
+
// to (method → default → fallback provider); it wins over the row's.
|
|
54
|
+
const provider = checkout?.provider ?? m.provider;
|
|
55
|
+
return {
|
|
56
|
+
method: m.code,
|
|
57
|
+
label: m.labels?.[locale] ?? m.name,
|
|
58
|
+
...(m.description ? { description: m.description } : {}),
|
|
59
|
+
fee: m.fee,
|
|
60
|
+
feeType: m.fee_type,
|
|
61
|
+
kind: m.kind,
|
|
62
|
+
...(provider ? { provider } : {}),
|
|
63
|
+
...(checkout ? { checkout } : {}),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
56
66
|
|
|
57
67
|
return {
|
|
58
68
|
managed: true,
|
|
@@ -6,10 +6,11 @@ import { pspPublicConfig, type PspProviderRow, type PspPublicConfig } from "../.
|
|
|
6
6
|
* The per-PSP frontend registry (see app/payments/psp) reads this to know
|
|
7
7
|
* which provider needs client-side tokenization and with which public key.
|
|
8
8
|
*
|
|
9
|
-
* Shape: { providers: { stripe: { publishableKey, testMode },
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Shape: { providers: { stripe: { publishableKey, testMode },
|
|
10
|
+
* novalnet: { publishableKey, testMode, checkoutMode }, … } }
|
|
11
|
+
* The key is read from the provider's options — Stripe `publishable_key`,
|
|
12
|
+
* Novalnet `client_key` — and Novalnet's `checkout_mode` (embedded | hosted)
|
|
13
|
+
* decides whether the checkout mounts its card field (see utils/pspConfig.ts).
|
|
13
14
|
*/
|
|
14
15
|
export default defineEventHandler(async (event) => {
|
|
15
16
|
if (resolvePaymentServiceKey(event) !== "api") {
|
|
@@ -5,6 +5,7 @@ import type { H3Event } from "h3";
|
|
|
5
5
|
import type { CartItem } from "../../app/interfaces/cart-item";
|
|
6
6
|
import type { Attribution } from "../../app/shared/campaignAttribution";
|
|
7
7
|
import type { CartSummaryRow, ICartManager, ICartService } from "../interfaces/cart";
|
|
8
|
+
import { readCartItemHints } from "../utils/cartItemHints";
|
|
8
9
|
|
|
9
10
|
/** Cart row of the carts app. */
|
|
10
11
|
interface ApiCart {
|
|
@@ -94,6 +95,7 @@ function cartPath(cartId: string, suffix = ""): string {
|
|
|
94
95
|
|
|
95
96
|
/** Storefront CartItem → carts-app line. The snapshot is the loose product copy. */
|
|
96
97
|
function toApiLine(item: CartItem, position: number): Record<string, unknown> {
|
|
98
|
+
const hints = readCartItemHints(item.hints);
|
|
97
99
|
return {
|
|
98
100
|
type: "product",
|
|
99
101
|
product_id: UUID.test(item.id) ? item.id : null,
|
|
@@ -118,6 +120,8 @@ function toApiLine(item: CartItem, position: number): Record<string, unknown> {
|
|
|
118
120
|
...(item.positionTexts !== undefined ? { positionTexts: item.positionTexts } : {}),
|
|
119
121
|
...(item.nonCatalog !== undefined ? { nonCatalog: item.nonCatalog } : {}),
|
|
120
122
|
...(item.requisitionId !== undefined ? { requisitionId: item.requisitionId } : {}),
|
|
123
|
+
// Written back so saving the cart does not erase what the line was sent with.
|
|
124
|
+
...(hints ? { hints } : {}),
|
|
121
125
|
},
|
|
122
126
|
};
|
|
123
127
|
}
|
|
@@ -135,6 +139,7 @@ function toCartItem(line: ApiCartLine): CartItem {
|
|
|
135
139
|
// old rows on read and leaves current ones untouched.
|
|
136
140
|
const snapshot = (line.snapshot ?? {}) as Partial<CartItem> & { id?: string; image?: string };
|
|
137
141
|
const metadata = (line.metadata ?? {}) as Partial<CartItem>;
|
|
142
|
+
const hints = readCartItemHints(line.metadata?.hints);
|
|
138
143
|
return {
|
|
139
144
|
id: String(snapshot.id ?? line.product_id ?? line.sku ?? line.id),
|
|
140
145
|
name: line.name,
|
|
@@ -153,6 +158,7 @@ function toCartItem(line: ApiCartLine): CartItem {
|
|
|
153
158
|
...(metadata.positionTexts !== undefined ? { positionTexts: metadata.positionTexts } : {}),
|
|
154
159
|
...(metadata.nonCatalog !== undefined ? { nonCatalog: metadata.nonCatalog } : {}),
|
|
155
160
|
...(metadata.requisitionId !== undefined ? { requisitionId: metadata.requisitionId } : {}),
|
|
161
|
+
...(hints ? { hints } : {}),
|
|
156
162
|
};
|
|
157
163
|
}
|
|
158
164
|
|
|
@@ -51,8 +51,12 @@ export class ApiProductService implements IProductService {
|
|
|
51
51
|
if (!doc) {
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// Side by side: both read the product's media and share each lookup.
|
|
55
|
+
const [detail, model] = await Promise.all([
|
|
56
|
+
mapLiveDocToDetail(doc, locale),
|
|
57
|
+
this.getProductModel(doc.attrs ?? {}),
|
|
58
|
+
]);
|
|
59
|
+
return { ...detail, model };
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/**
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CartCalculation,
|
|
5
5
|
CartCalculationRequest,
|
|
6
6
|
CartLineHint,
|
|
7
|
+
CartLineHintType,
|
|
7
8
|
CartMessage,
|
|
8
9
|
CartTotalRow,
|
|
9
10
|
PriceLabelCode,
|
|
@@ -11,6 +12,15 @@ import type {
|
|
|
11
12
|
import type { CartItem } from "../../app/interfaces/cart-item";
|
|
12
13
|
|
|
13
14
|
import type { CartCalculationOverrides, ICartCalculationService } from "../interfaces/cartCalculation";
|
|
15
|
+
import { readCartItemHints } from "../utils/cartItemHints";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hints a cart line carries from the backend (`CartItem.hints`) that the cart
|
|
19
|
+
* renders, by type → i18n key. A type missing here is not shown.
|
|
20
|
+
*/
|
|
21
|
+
const ITEM_HINT_KEYS = new Map<string, { type: CartLineHintType; messageKey: string }>([
|
|
22
|
+
["unit-changed", { type: "unit-changed", messageKey: "calc.hints.unitChanged" }],
|
|
23
|
+
]);
|
|
14
24
|
|
|
15
25
|
/* ------------------------------------------------------------------ */
|
|
16
26
|
/* Demo rule tables — stand-ins for ERP master data */
|
|
@@ -199,6 +209,15 @@ export class MockCartCalculationService implements ICartCalculationService {
|
|
|
199
209
|
});
|
|
200
210
|
}
|
|
201
211
|
|
|
212
|
+
// Hints the line was sent with. Only known types render: a hint without
|
|
213
|
+
// a message would be an empty alert.
|
|
214
|
+
for (const hint of readCartItemHints(item.hints) ?? []) {
|
|
215
|
+
const known = ITEM_HINT_KEYS.get(hint.type);
|
|
216
|
+
if (known) {
|
|
217
|
+
hints.push({ ...known, ...(hint.params ? { params: hint.params } : {}) });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
202
221
|
if ((skuCounts.get(item.sku ?? "") ?? 0) > 1) {
|
|
203
222
|
hints.push({ type: "duplicate", messageKey: "calc.hints.duplicate" });
|
|
204
223
|
}
|
|
@@ -379,6 +398,16 @@ export class MockCartCalculationService implements ICartCalculationService {
|
|
|
379
398
|
}
|
|
380
399
|
}
|
|
381
400
|
|
|
401
|
+
// A switched unit keeps the quantity, and 10 metres are not 10 pieces —
|
|
402
|
+
// a warning, not a block: the buyer may well have meant 10 pieces.
|
|
403
|
+
if (lines.some(l => l.hints.some(h => h.type === "unit-changed"))) {
|
|
404
|
+
messages.push({
|
|
405
|
+
severity: "warning",
|
|
406
|
+
code: "units-changed",
|
|
407
|
+
messageKey: "calc.messages.unitsChanged",
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
382
411
|
if (settings.costCenters.enabled && settings.costCenters.required && role) {
|
|
383
412
|
const missing = lines.some(l => l.hints.some(h => h.type === "missing-cost-center"));
|
|
384
413
|
if (context.costCenters.length === 0) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CartItemHint } from "../../app/interfaces/cart-item";
|
|
2
|
+
|
|
3
|
+
/** A plain object — not null and not an array, which `typeof` lets through. */
|
|
4
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The well-formed entries of a cart line's hints. The line metadata is not
|
|
10
|
+
* only ours — punchout writes the hints on an inbound cart — and the client
|
|
11
|
+
* sends the items back whole on every sync and calculation, so the hints are
|
|
12
|
+
* cleaned wherever they come in rather than cast: on read, on write and in
|
|
13
|
+
* the calculation.
|
|
14
|
+
*/
|
|
15
|
+
export function readCartItemHints(value: unknown): CartItemHint[] | undefined {
|
|
16
|
+
if (!Array.isArray(value)) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const hints = value.flatMap((entry: unknown): CartItemHint[] => {
|
|
20
|
+
if (!isRecord(entry) || typeof entry.type !== "string" || !entry.type) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const params = Object.fromEntries(Object.entries(isRecord(entry.params) ? entry.params : {}).filter(
|
|
24
|
+
(pair): pair is [string, string | number] => ["string", "number"].includes(typeof pair[1]),
|
|
25
|
+
));
|
|
26
|
+
return [{ type: entry.type, ...(Object.keys(params).length ? { params } : {}) }];
|
|
27
|
+
});
|
|
28
|
+
return hints.length ? hints : undefined;
|
|
29
|
+
}
|
|
@@ -25,6 +25,22 @@ function sign(payload: string): string {
|
|
|
25
25
|
return createHmac("sha256", sessionSecret()).update(payload).digest("hex");
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The same signature, under its own purpose label, for other short-lived
|
|
30
|
+
* browser-held claims of the checkout (the PSP return, FE-5). The label keeps
|
|
31
|
+
* one kind of token from being replayed as another.
|
|
32
|
+
*/
|
|
33
|
+
export function checkoutSignature(purpose: string, payload: string): string {
|
|
34
|
+
return sign(`${purpose}:${payload}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Constant-time comparison of two signatures. */
|
|
38
|
+
export function signaturesMatch(given: string, expected: string): boolean {
|
|
39
|
+
const a = Buffer.from(given, "utf8");
|
|
40
|
+
const b = Buffer.from(expected, "utf8");
|
|
41
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
/** Per-instance replay cache (best-effort one-time use). */
|
|
29
45
|
const consumed = new Map<string, number>();
|
|
30
46
|
|