@revenexx/cover 0.19.0 → 0.21.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.
Files changed (95) hide show
  1. package/app/api/marketing.ts +24 -0
  2. package/app/app.config.ts +22 -0
  3. package/app/components/account/approvals/AccountPendingApprovals.vue +54 -13
  4. package/app/components/account/approvals/AccountPendingOrderDetail.vue +156 -0
  5. package/app/components/account/loyalty/AccountLoyalty.vue +205 -0
  6. package/app/components/account/orders/AccountOrderContents.vue +142 -0
  7. package/app/components/account/orders/AccountOrderDetail.vue +16 -178
  8. package/app/components/account/orders/AccountOrderHead.vue +79 -0
  9. package/app/components/account/orders/AccountOrderPay.vue +13 -3
  10. package/app/components/account/orders/AccountOrdersTable.vue +2 -0
  11. package/app/components/cart/position/CartPosition.vue +6 -6
  12. package/app/components/cart/view/CartSummaryPanel.vue +4 -0
  13. package/app/components/checkout/onepage/CheckoutPaymentSection.vue +20 -8
  14. package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -0
  15. package/app/components/checkout/return/CheckoutPaymentReturn.vue +209 -0
  16. package/app/components/loyalty/hint/LoyaltyPerkHint.vue +28 -0
  17. package/app/components/newsletter/confirm/NewsletterConfirmation.vue +54 -0
  18. package/app/components/newsletter/preferences/NewsletterPreferenceCentre.vue +183 -0
  19. package/app/components/newsletter/state/NewsletterLinkRefusal.vue +45 -0
  20. package/app/components/review/form/ReviewForm.vue +211 -0
  21. package/app/composables/useAccountDashboard.ts +1 -0
  22. package/app/composables/useCampaignAttribution.ts +120 -0
  23. package/app/composables/useCheckoutOnePage.ts +80 -7
  24. package/app/composables/useLoyaltyAccount.ts +79 -0
  25. package/app/composables/useMarketingConsent.ts +49 -0
  26. package/app/composables/usePendingApprovals.ts +11 -3
  27. package/app/composables/usePspCheckout.ts +130 -29
  28. package/app/config/colorRamp.ts +55 -0
  29. package/app/config/navigation.ts +1 -1
  30. package/app/config/quickActions.ts +1 -0
  31. package/app/interfaces/account/approvals.ts +34 -1
  32. package/app/interfaces/account/order-list.ts +8 -1
  33. package/app/interfaces/cart-calculation.ts +7 -1
  34. package/app/interfaces/cart-item.ts +12 -0
  35. package/app/interfaces/payment.ts +22 -0
  36. package/app/pages/account/points.vue +26 -0
  37. package/app/pages/checkout/payment-return.vue +17 -0
  38. package/app/pages/newsletter/confirm/[token].vue +23 -0
  39. package/app/pages/newsletter/preferences/[token].vue +24 -0
  40. package/app/pages/review/[token].vue +23 -0
  41. package/app/payments/psp/novalnet.ts +255 -0
  42. package/app/payments/psp/registry.ts +7 -3
  43. package/app/payments/psp/rules.ts +99 -0
  44. package/app/payments/psp/stripe.ts +6 -2
  45. package/app/payments/psp/types.ts +72 -6
  46. package/app/plugins/campaign-attribution.client.ts +47 -0
  47. package/app/shared/campaignAttribution.ts +281 -0
  48. package/app/shared/personalisation.ts +107 -0
  49. package/app/shared/pspReturn.ts +62 -0
  50. package/i18n/locales/de/account.json +20 -5
  51. package/i18n/locales/de/cart.json +4 -2
  52. package/i18n/locales/de/checkout.json +32 -0
  53. package/i18n/locales/de/editor.json +10 -0
  54. package/i18n/locales/de/marketing.json +71 -0
  55. package/i18n/locales/en/account.json +20 -5
  56. package/i18n/locales/en/cart.json +4 -2
  57. package/i18n/locales/en/checkout.json +32 -0
  58. package/i18n/locales/en/editor.json +10 -0
  59. package/i18n/locales/en/marketing.json +71 -0
  60. package/package.json +3 -2
  61. package/server/api/account/orders/[id]/pay.post.ts +47 -7
  62. package/server/api/account/pending-approvals/index.get.ts +16 -12
  63. package/server/api/account/pending-approvals/orders/[number]/approve.post.ts +6 -0
  64. package/server/api/account/pending-approvals/orders/[number]/reject.post.ts +6 -0
  65. package/server/api/account/pending-approvals/orders/[number].get.ts +15 -0
  66. package/server/api/campaigns/touches.post.ts +42 -0
  67. package/server/api/cart/attribution.put.ts +31 -0
  68. package/server/api/checkout/payment-return.post.ts +30 -0
  69. package/server/api/loyalty/account.get.ts +27 -0
  70. package/server/api/newsletter/confirm/[token].post.ts +21 -0
  71. package/server/api/newsletter/preferences/[token].get.ts +14 -0
  72. package/server/api/newsletter/preferences/[token].post.ts +36 -0
  73. package/server/api/orders/index.post.ts +47 -12
  74. package/server/api/payment/methods.post.ts +19 -9
  75. package/server/api/payment/psp-config.get.ts +5 -4
  76. package/server/api/reviews/requests/[token].get.ts +14 -0
  77. package/server/api/reviews/submit/[token].post.ts +31 -0
  78. package/server/interfaces/cart.ts +6 -0
  79. package/server/interfaces/marketing.ts +150 -0
  80. package/server/services/ApiCartService.ts +22 -0
  81. package/server/services/ApiMarketingService.ts +292 -0
  82. package/server/services/ApiProductService.ts +6 -2
  83. package/server/services/MockCartCalculationService.ts +29 -0
  84. package/server/services/MockMarketingService.ts +178 -0
  85. package/server/utils/cartItemHints.ts +29 -0
  86. package/server/utils/checkoutSession.ts +16 -0
  87. package/server/utils/liveCatalog.ts +244 -31
  88. package/server/utils/liveOrders.ts +33 -0
  89. package/server/utils/marketingService.ts +63 -0
  90. package/server/utils/orderAttribution.ts +65 -0
  91. package/server/utils/orderPayment.ts +79 -0
  92. package/server/utils/pendingApprovals.ts +157 -2
  93. package/server/utils/personalisationViewer.ts +28 -0
  94. package/server/utils/pspConfig.ts +125 -13
  95. package/server/utils/pspReturn.ts +267 -0
@@ -5,7 +5,16 @@ 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 { checkoutTakesPayment, orderPaymentRequest, recordOrderPaymentStatus } from "../../utils/orderPayment";
8
+ import {
9
+ checkoutTakesPayment,
10
+ orderPaymentRequest,
11
+ paymentCustomerOf,
12
+ recordOrderPaymentStatus,
13
+ sanitizePaymentInstrument,
14
+ } from "../../utils/orderPayment";
15
+ import { pspReturnUrl, rememberPspReturn } from "../../utils/pspReturn";
16
+ import { placeOrderWithAttribution } from "../../utils/orderAttribution";
17
+ import { sanitizeAttribution } from "../../../app/shared/campaignAttribution";
9
18
 
10
19
  // Method codes are generic — live mode validates them against the
11
20
  // payments app; the demo-only methods keep their extra fields.
@@ -40,10 +49,17 @@ interface OrderPayload {
40
49
  promoCode?: string;
41
50
  /** The codes the buyer entered on the cart, carried to the engine at submit. */
42
51
  voucherCodes?: string[];
43
- /** PSP single-use token from the checkout's client-side tokenizer (e.g. Stripe pm_…). */
44
- paymentInstrument?: { token?: string };
45
- /** Where the PSP returns the buyer after a redirect/3DS step-up. */
46
- returnUrl?: string;
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> };
58
+ /**
59
+ * Where the visit came from (RAD-293), as the browser kept it under the
60
+ * visitor's consent. Rebuilt into the closed shape before it travels.
61
+ */
62
+ attribution?: unknown;
47
63
  }
48
64
 
49
65
  function isNonEmptyString(v: unknown): v is string {
@@ -445,7 +461,9 @@ export default defineEventHandler(async (event) => {
445
461
  ? await submitThroughProcurement(submission as never)
446
462
  : {
447
463
  kind: "order" as const,
448
- order: await useRevenexxSdk().orders.ordersPlace(submission as never) as unknown as SubmittedOrder,
464
+ // The cart's attribution goes with the order: orders never
465
+ // reads the cart for it (RAD-287).
466
+ order: await placeOrderWithAttribution<SubmittedOrder>(submission, sanitizeAttribution(body.attribution)),
449
467
  };
450
468
 
451
469
  if (outcome.kind === "request") {
@@ -568,10 +586,13 @@ export default defineEventHandler(async (event) => {
568
586
  ? address?.billing as Record<string, unknown> | undefined
569
587
  : address;
570
588
  const country = toIsoCountry(body.billingCountry ?? billing?.country ?? "");
571
- // The instrument (PSP token from the checkout's client-side tokenizer)
572
- // is forwarded as-is; paymentsCreate's typed params drop unknown
573
- // fields, so the create goes through the low-level transport.
574
- const instrument = body.paymentInstrument as { token?: string } | undefined;
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;
575
596
  const payerContactId = principalContactId(event);
576
597
  try {
577
598
  const created = await useRevenexxSdk().call<{ id: string; status: string; error_message?: string | null; next_action?: { type?: string; url?: string } | null }>(
@@ -588,8 +609,19 @@ export default defineEventHandler(async (event) => {
588
609
  orderId: liveOrderUuid,
589
610
  contactId: payerContactId,
590
611
  idempotencyKey: body.checkoutSessionToken,
591
- token: instrument?.token,
592
- returnUrl: body.returnUrl,
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,
593
625
  metadata: {
594
626
  ...(payment.poNumber ? { po_number: payment.poNumber } : {}),
595
627
  ...(payment.costCenter ? { cost_center: payment.costCenter } : {}),
@@ -603,6 +635,9 @@ export default defineEventHandler(async (event) => {
603
635
  if (created.status === "requires_action" && created.next_action?.url) {
604
636
  // Order stays placed (payment pending); buyer completes at the PSP.
605
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 });
606
641
  }
607
642
  livePaymentStatus = created.status;
608
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
- method: m.code,
49
- label: m.labels?.[locale] ?? m.name,
50
- ...(m.description ? { description: m.description } : {}),
51
- fee: m.fee,
52
- feeType: m.fee_type,
53
- kind: m.kind,
54
- ...(m.provider ? { provider: m.provider } : {}),
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
- * The key is read from the provider's `options.publishable_key` (see
11
- * utils/pspConfig.ts); adding Novalnet/Mollie later = they appear here once
12
- * enabled with one, and the FE registry gets a new entry.
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") {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The review form behind a review request link (RAD-293): the products of
3
+ * one order the buyer may rate, and which of them they already rated. The
4
+ * link is the reviews app's; the journey that sent it asked for it.
5
+ */
6
+ export default defineEventHandler(async (event) => {
7
+ const token = routeToken(event);
8
+ try {
9
+ return await getMarketingService(event).reviewRequest(event, token);
10
+ }
11
+ catch (err) {
12
+ return rethrowTokenRefusal(err);
13
+ }
14
+ });
@@ -0,0 +1,31 @@
1
+ import type { ReviewInput } from "../../../interfaces/marketing";
2
+
3
+ /**
4
+ * The ratings a buyer gave on the review form. Only rated products are sent;
5
+ * the reviews app checks each one against the request and answers per product.
6
+ */
7
+ export default defineEventHandler(async (event) => {
8
+ const token = routeToken(event);
9
+ const body = await readBody<{ reviews?: unknown }>(event).catch(() => null);
10
+ const reviews: ReviewInput[] = Array.isArray(body?.reviews)
11
+ ? (body.reviews as Record<string, unknown>[])
12
+ .filter(review => review && typeof review.product_id === "string"
13
+ && Number.isInteger(review.rating) && Number(review.rating) >= 1 && Number(review.rating) <= 5)
14
+ .slice(0, 50)
15
+ .map(review => ({
16
+ product_id: String(review.product_id),
17
+ rating: Number(review.rating),
18
+ ...(typeof review.title === "string" && review.title.trim() ? { title: review.title.trim().slice(0, 200) } : {}),
19
+ ...(typeof review.body === "string" && review.body.trim() ? { body: review.body.trim().slice(0, 5000) } : {}),
20
+ }))
21
+ : [];
22
+ if (!reviews.length) {
23
+ throw createError({ statusCode: 422, message: "No rating given" });
24
+ }
25
+ try {
26
+ return await getMarketingService(event).submitReviews(event, token, reviews, resolveLocale(event));
27
+ }
28
+ catch (err) {
29
+ return rethrowTokenRefusal(err);
30
+ }
31
+ });
@@ -1,6 +1,7 @@
1
1
  import type { H3Event } from "h3";
2
2
 
3
3
  import type { CartItem } from "../../app/interfaces/cart-item";
4
+ import type { Attribution } from "../../app/shared/campaignAttribution";
4
5
 
5
6
  /** Summary row for the cart switcher / account page. */
6
7
  export interface CartSummaryRow {
@@ -43,4 +44,9 @@ export interface ICartManager {
43
44
  claimSession(event: H3Event, contactId: string): Promise<void>;
44
45
  /** Order hand-over: freeze the owner's current cart as ordered (+order_ref). */
45
46
  orderActiveCart(event: H3Event, orderRef: string): Promise<string | null>;
47
+ /**
48
+ * Where the visit came from, written onto the owner's current cart as a
49
+ * whole (null clears it). False when there is no cart to write it on yet.
50
+ */
51
+ setActiveCartAttribution(event: H3Event, attribution: Attribution | null): Promise<boolean>;
46
52
  }
@@ -0,0 +1,150 @@
1
+ import type { H3Event } from "h3";
2
+
3
+ /**
4
+ * The marketing apps as the storefront reaches them (RAD-293): the double
5
+ * opt-in confirmation and the preference centre (marketing-consents), the
6
+ * review form (reviews), the loyalty account page and perk hint (loyalty),
7
+ * the audiences of a signed-in contact (audiences) and onsite touches
8
+ * (campaigns). Shapes follow the marketing contracts and their appendix.
9
+ */
10
+
11
+ /** Labels as the apps keep them: one text per language. */
12
+ export type Labels = Record<string, string> | null;
13
+
14
+ /** Why a token page cannot be used. */
15
+ export type TokenRefusal = "unknown" | "expired";
16
+
17
+ export class MarketingTokenError extends Error {
18
+ constructor(public readonly refusal: TokenRefusal) {
19
+ super(refusal === "expired" ? "link expired" : "link unknown");
20
+ this.name = "MarketingTokenError";
21
+ }
22
+ }
23
+
24
+ export interface Evidence {
25
+ ip: string | null;
26
+ user_agent: string | null;
27
+ page_url?: string | null;
28
+ }
29
+
30
+ export interface ConfirmResult {
31
+ alreadyConfirmed: boolean;
32
+ }
33
+
34
+ export interface PreferenceType {
35
+ code: string;
36
+ label: string;
37
+ description: string | null;
38
+ subscribed: boolean;
39
+ state: string | null;
40
+ consentTextId: string | null;
41
+ consentText: string | null;
42
+ }
43
+
44
+ export interface PreferenceView {
45
+ addressHint: string;
46
+ types: PreferenceType[];
47
+ }
48
+
49
+ export interface PreferenceChoice {
50
+ subscription_type: string;
51
+ subscribed: boolean;
52
+ consent_text_id?: string | null;
53
+ }
54
+
55
+ export interface PreferenceChange {
56
+ subscription_type: string | null;
57
+ action: string;
58
+ }
59
+
60
+ export interface ReviewProduct {
61
+ productId: string;
62
+ sku: string | null;
63
+ name: string;
64
+ reviewed: boolean;
65
+ }
66
+
67
+ export interface ReviewRequestView {
68
+ orderNumber: string | null;
69
+ expiresAt: string | null;
70
+ products: ReviewProduct[];
71
+ }
72
+
73
+ export interface ReviewInput {
74
+ product_id: string;
75
+ rating: number;
76
+ title?: string;
77
+ body?: string;
78
+ }
79
+
80
+ export interface ReviewSubmitResult {
81
+ accepted: string[];
82
+ rejected: { productId: string | null; reason: string }[];
83
+ }
84
+
85
+ export interface LoyaltyTier {
86
+ code: string;
87
+ labels: Labels;
88
+ perks: Labels[];
89
+ }
90
+
91
+ export interface LoyaltyProgressTier {
92
+ code: string;
93
+ labels: Labels;
94
+ threshold: number | null;
95
+ bonusPercent: number;
96
+ reached: boolean;
97
+ current: boolean;
98
+ }
99
+
100
+ export interface LoyaltyProgress {
101
+ period: string | number | null;
102
+ currency: string;
103
+ turnoverYtd: number;
104
+ projectedTurnover: number | null;
105
+ tiers: LoyaltyProgressTier[];
106
+ nextTier: { code: string; labels: Labels; gap: number; bonusPercent: number } | null;
107
+ bonusNow: number | null;
108
+ expectedBonus: number | null;
109
+ requiresNoOverdue: boolean;
110
+ }
111
+
112
+ export interface LoyaltyMembership {
113
+ program: { code: string; labels: Labels; kind: "points" | "turnover_bonus" | string };
114
+ tier: LoyaltyTier | null;
115
+ pointsBalance: number | null;
116
+ agreementId: string | null;
117
+ }
118
+
119
+ export interface LoyaltyAccount {
120
+ memberships: LoyaltyMembership[];
121
+ progress: LoyaltyProgress | null;
122
+ }
123
+
124
+ export interface CampaignTouch {
125
+ campaign_id: string;
126
+ kind: "onsite_impression" | "onsite_click";
127
+ ref?: string;
128
+ key?: string;
129
+ }
130
+
131
+ export interface IMarketingService {
132
+ confirmSubscription(event: H3Event, token: string, evidence: Evidence): Promise<ConfirmResult>;
133
+ preferences(event: H3Event, token: string, locale: string): Promise<PreferenceView>;
134
+ savePreferences(
135
+ event: H3Event,
136
+ token: string,
137
+ input: { choices?: PreferenceChoice[]; unsubscribeAll?: boolean; locale: string },
138
+ evidence: Evidence,
139
+ ): Promise<{ view: PreferenceView; changes: PreferenceChange[] }>;
140
+ reviewRequest(event: H3Event, token: string): Promise<ReviewRequestView>;
141
+ submitReviews(event: H3Event, token: string, reviews: ReviewInput[], locale: string): Promise<ReviewSubmitResult>;
142
+ /** Null when the buyer holds no membership, or loyalty is not there to ask. */
143
+ loyaltyAccount(event: H3Event, holder: { contactId: string; organizationId?: string | null }): Promise<LoyaltyAccount | null>;
144
+ /** The audience codes of a signed-in contact; empty when unknown or unanswerable. */
145
+ audienceCodes(event: H3Event, contactId: string): Promise<string[]>;
146
+ recordTouches(
147
+ event: H3Event,
148
+ touches: (CampaignTouch & { contact_id?: string; session_key?: string; market?: string })[],
149
+ ): Promise<void>;
150
+ }
@@ -3,7 +3,9 @@ import type { Models } from "@revenexx/sdk";
3
3
  import type { H3Event } from "h3";
4
4
 
5
5
  import type { CartItem } from "../../app/interfaces/cart-item";
6
+ import type { Attribution } from "../../app/shared/campaignAttribution";
6
7
  import type { CartSummaryRow, ICartManager, ICartService } from "../interfaces/cart";
8
+ import { readCartItemHints } from "../utils/cartItemHints";
7
9
 
8
10
  /** Cart row of the carts app. */
9
11
  interface ApiCart {
@@ -93,6 +95,7 @@ function cartPath(cartId: string, suffix = ""): string {
93
95
 
94
96
  /** Storefront CartItem → carts-app line. The snapshot is the loose product copy. */
95
97
  function toApiLine(item: CartItem, position: number): Record<string, unknown> {
98
+ const hints = readCartItemHints(item.hints);
96
99
  return {
97
100
  type: "product",
98
101
  product_id: UUID.test(item.id) ? item.id : null,
@@ -117,6 +120,8 @@ function toApiLine(item: CartItem, position: number): Record<string, unknown> {
117
120
  ...(item.positionTexts !== undefined ? { positionTexts: item.positionTexts } : {}),
118
121
  ...(item.nonCatalog !== undefined ? { nonCatalog: item.nonCatalog } : {}),
119
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 } : {}),
120
125
  },
121
126
  };
122
127
  }
@@ -134,6 +139,7 @@ function toCartItem(line: ApiCartLine): CartItem {
134
139
  // old rows on read and leaves current ones untouched.
135
140
  const snapshot = (line.snapshot ?? {}) as Partial<CartItem> & { id?: string; image?: string };
136
141
  const metadata = (line.metadata ?? {}) as Partial<CartItem>;
142
+ const hints = readCartItemHints(line.metadata?.hints);
137
143
  return {
138
144
  id: String(snapshot.id ?? line.product_id ?? line.sku ?? line.id),
139
145
  name: line.name,
@@ -152,6 +158,7 @@ function toCartItem(line: ApiCartLine): CartItem {
152
158
  ...(metadata.positionTexts !== undefined ? { positionTexts: metadata.positionTexts } : {}),
153
159
  ...(metadata.nonCatalog !== undefined ? { nonCatalog: metadata.nonCatalog } : {}),
154
160
  ...(metadata.requisitionId !== undefined ? { requisitionId: metadata.requisitionId } : {}),
161
+ ...(hints ? { hints } : {}),
155
162
  };
156
163
  }
157
164
 
@@ -360,6 +367,21 @@ export class ApiCartService implements ICartService, ICartManager {
360
367
  return cartId;
361
368
  }
362
369
 
370
+ /**
371
+ * `PUT /v1/carts/{id} { attribution }` replaces the whole object (carts
372
+ * 2.9.0, RAD-287); first and last touch are the storefront's to compute.
373
+ * Through the escape hatch: the typed SDK predates the field.
374
+ */
375
+ async setActiveCartAttribution(event: H3Event, attribution: Attribution | null): Promise<boolean> {
376
+ const cartId = await this.activeCartId(event);
377
+ if (!cartId) {
378
+ return false;
379
+ }
380
+ const query = visitCartKey(event, cartId) ?? undefined;
381
+ await useRevenexxSdk().call("PUT", cartPath(cartId), { ...(query ? { query } : {}), body: { attribution } });
382
+ return true;
383
+ }
384
+
363
385
  async claimSession(event: H3Event, contactId: string): Promise<void> {
364
386
  const sessionKey = getCookie(event, "cover-cart-session");
365
387
  if (!sessionKey) {