@revenexx/cover 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api/marketing.ts +24 -0
- package/app/app.config.ts +22 -0
- package/app/components/account/loyalty/AccountLoyalty.vue +205 -0
- package/app/components/cart/view/CartSummaryPanel.vue +4 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -0
- package/app/components/loyalty/hint/LoyaltyPerkHint.vue +28 -0
- package/app/components/newsletter/confirm/NewsletterConfirmation.vue +54 -0
- package/app/components/newsletter/preferences/NewsletterPreferenceCentre.vue +183 -0
- package/app/components/newsletter/state/NewsletterLinkRefusal.vue +45 -0
- package/app/components/product/detail/ProductDetailImageGallery.vue +39 -13
- package/app/components/product/detail/ProductDetailView.vue +3 -1
- package/app/components/review/form/ReviewForm.vue +211 -0
- package/app/composables/useCampaignAttribution.ts +120 -0
- package/app/composables/useCheckoutOnePage.ts +9 -0
- package/app/composables/useLoyaltyAccount.ts +79 -0
- package/app/composables/useMarketingConsent.ts +49 -0
- package/app/composables/useProduct.ts +6 -1
- package/app/config/navigation.ts +1 -1
- package/app/config/quickActions.ts +1 -0
- package/app/interfaces/product-detail.ts +11 -0
- package/app/pages/account/points.vue +26 -0
- package/app/pages/newsletter/confirm/[token].vue +23 -0
- package/app/pages/newsletter/preferences/[token].vue +24 -0
- package/app/pages/review/[token].vue +23 -0
- package/app/plugins/campaign-attribution.client.ts +47 -0
- package/app/shared/campaignAttribution.ts +281 -0
- package/app/shared/personalisation.ts +107 -0
- package/i18n/locales/de/account.json +3 -2
- package/i18n/locales/de/marketing.json +71 -0
- package/i18n/locales/en/account.json +3 -2
- package/i18n/locales/en/marketing.json +71 -0
- package/package.json +1 -1
- package/server/api/campaigns/touches.post.ts +42 -0
- package/server/api/cart/attribution.put.ts +31 -0
- package/server/api/loyalty/account.get.ts +27 -0
- package/server/api/newsletter/confirm/[token].post.ts +21 -0
- package/server/api/newsletter/preferences/[token].get.ts +14 -0
- package/server/api/newsletter/preferences/[token].post.ts +36 -0
- package/server/api/orders/index.post.ts +10 -1
- package/server/api/reviews/requests/[token].get.ts +14 -0
- package/server/api/reviews/submit/[token].post.ts +31 -0
- package/server/interfaces/cart.ts +6 -0
- package/server/interfaces/marketing.ts +150 -0
- package/server/services/ApiCartService.ts +16 -0
- package/server/services/ApiMarketingService.ts +292 -0
- package/server/services/ApiProductService.ts +20 -1
- package/server/services/LocalFileProductService.ts +9 -1
- package/server/services/MockMarketingService.ts +178 -0
- package/server/utils/liveCatalog.ts +178 -2
- package/server/utils/marketingService.ts +63 -0
- package/server/utils/orderAttribution.ts +65 -0
- package/server/utils/personalisationViewer.ts +28 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { sanitizeAttribution } from "../../../app/shared/campaignAttribution";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where the visit came from, onto the current cart (RAD-293): the carts app
|
|
5
|
+
* keeps it until the cart is ordered, and an abandoned cart's journey reads
|
|
6
|
+
* it. The browser sends it on landing, on every further campaign touch and
|
|
7
|
+
* when the first article goes in; `null` takes it off again once the visitor
|
|
8
|
+
* withdrew the consent it rested on.
|
|
9
|
+
*
|
|
10
|
+
* Best effort by design: no cart yet, the demo cart, or a carts app that
|
|
11
|
+
* refuses the field answer `{ stored: false }` and the visit goes on. Where
|
|
12
|
+
* the visit came from is never a reason to fail a page.
|
|
13
|
+
*/
|
|
14
|
+
export default defineEventHandler(async (event) => {
|
|
15
|
+
const body = await readBody<{ attribution?: unknown }>(event).catch(() => null);
|
|
16
|
+
const attribution = body?.attribution === null ? null : sanitizeAttribution(body?.attribution);
|
|
17
|
+
if (attribution === null && body?.attribution !== null) {
|
|
18
|
+
return { stored: false };
|
|
19
|
+
}
|
|
20
|
+
const manager = getCartManager(event);
|
|
21
|
+
if (!manager) {
|
|
22
|
+
return { stored: false };
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return { stored: await manager.setActiveCartAttribution(event, attribution) };
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
getLogService().warn("cart attribution not stored", apiErrorContext(err));
|
|
29
|
+
return { stored: false };
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LoyaltyAccount } from "../../interfaces/marketing";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The signed-in buyer's loyalty membership (RAD-293): the programme and tier,
|
|
5
|
+
* the points balance, and — for a yearly turnover bonus like eltric "Premium"
|
|
6
|
+
* — how far the company is this year. A company agreement is the
|
|
7
|
+
* organisation's, so the buyer's organisation goes along.
|
|
8
|
+
*
|
|
9
|
+
* Nobody signed in is a 401; a buyer in no programme, or a shop without the
|
|
10
|
+
* loyalty app, is `null` — the page then says there is nothing to show.
|
|
11
|
+
*/
|
|
12
|
+
export default defineEventHandler(async (event): Promise<LoyaltyAccount | null> => {
|
|
13
|
+
const user = await getAuthService(event).me(event);
|
|
14
|
+
if (!user) {
|
|
15
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
16
|
+
}
|
|
17
|
+
const refs = sessionOrderRefs(event);
|
|
18
|
+
const contactId = user.contactId ?? refs.contact_id;
|
|
19
|
+
// A demo persona has no contact; the mock answers for it anyway.
|
|
20
|
+
if (!contactId && resolveMarketingServiceKey(event) === "api") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return await getMarketingService(event).loyaltyAccount(event, {
|
|
24
|
+
contactId: contactId ?? "",
|
|
25
|
+
organizationId: refs.organization_id ?? null,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The double opt-in click (RAD-293): the link in the confirmation mail opens
|
|
3
|
+
* the shop's confirmation page, and the page — in the browser, never while it
|
|
4
|
+
* is rendered on the server — confirms here. A mail scanner that fetches the
|
|
5
|
+
* link without running the page confirms nothing.
|
|
6
|
+
*
|
|
7
|
+
* The address and the browser go along as the evidence marketing-consents
|
|
8
|
+
* keeps for the confirmation.
|
|
9
|
+
*/
|
|
10
|
+
export default defineEventHandler(async (event) => {
|
|
11
|
+
const token = routeToken(event);
|
|
12
|
+
const body = await readBody<{ page_url?: unknown }>(event).catch(() => null);
|
|
13
|
+
const pageUrl = typeof body?.page_url === "string" ? body.page_url.slice(0, 2048) : null;
|
|
14
|
+
try {
|
|
15
|
+
const result = await getMarketingService(event).confirmSubscription(event, token, consentEvidence(event, pageUrl));
|
|
16
|
+
return { confirmed: true, alreadyConfirmed: result.alreadyConfirmed };
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return rethrowTokenRefusal(err);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preference centre (RAD-293): what a recipient of the shop's mails is
|
|
3
|
+
* subscribed to, behind the personal link in every mail's footer. The address
|
|
4
|
+
* comes back masked; the link is the only proof of who is asking.
|
|
5
|
+
*/
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
const token = routeToken(event);
|
|
8
|
+
try {
|
|
9
|
+
return await getMarketingService(event).preferences(event, token, resolveLocale(event));
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
return rethrowTokenRefusal(err);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { PreferenceChoice } from "../../../interfaces/marketing";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a recipient changed in the preference centre: one choice per type, or
|
|
5
|
+
* leaving everything at once. A type that needs a double opt-in is requested,
|
|
6
|
+
* not subscribed — marketing-consents sends the confirmation mail.
|
|
7
|
+
*/
|
|
8
|
+
export default defineEventHandler(async (event) => {
|
|
9
|
+
const token = routeToken(event);
|
|
10
|
+
const body = await readBody<{ choices?: unknown; unsubscribe_all?: unknown }>(event).catch(() => null);
|
|
11
|
+
const unsubscribeAll = body?.unsubscribe_all === true;
|
|
12
|
+
const choices: PreferenceChoice[] = Array.isArray(body?.choices)
|
|
13
|
+
? (body.choices as Record<string, unknown>[])
|
|
14
|
+
.filter(choice => choice && typeof choice.subscription_type === "string" && typeof choice.subscribed === "boolean")
|
|
15
|
+
.slice(0, 50)
|
|
16
|
+
.map(choice => ({
|
|
17
|
+
subscription_type: String(choice.subscription_type),
|
|
18
|
+
subscribed: choice.subscribed === true,
|
|
19
|
+
...(typeof choice.consent_text_id === "string" ? { consent_text_id: choice.consent_text_id } : {}),
|
|
20
|
+
}))
|
|
21
|
+
: [];
|
|
22
|
+
if (!unsubscribeAll && !choices.length) {
|
|
23
|
+
throw createError({ statusCode: 422, message: "Nothing to change" });
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return await getMarketingService(event).savePreferences(
|
|
27
|
+
event,
|
|
28
|
+
token,
|
|
29
|
+
{ choices, unsubscribeAll, locale: resolveLocale(event) },
|
|
30
|
+
consentEvidence(event),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
return rethrowTokenRefusal(err);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -6,6 +6,8 @@ import { type EligibleMethodFee, paymentFee } from "../../utils/paymentFee";
|
|
|
6
6
|
import { orderLinePrices, type PriceResolveAnswer } from "../../utils/orderLinePrices";
|
|
7
7
|
import { toIsoCountry } from "../../utils/country";
|
|
8
8
|
import { checkoutTakesPayment, orderPaymentRequest, recordOrderPaymentStatus } from "../../utils/orderPayment";
|
|
9
|
+
import { placeOrderWithAttribution } from "../../utils/orderAttribution";
|
|
10
|
+
import { sanitizeAttribution } from "../../../app/shared/campaignAttribution";
|
|
9
11
|
|
|
10
12
|
// Method codes are generic — live mode validates them against the
|
|
11
13
|
// payments app; the demo-only methods keep their extra fields.
|
|
@@ -44,6 +46,11 @@ interface OrderPayload {
|
|
|
44
46
|
paymentInstrument?: { token?: string };
|
|
45
47
|
/** Where the PSP returns the buyer after a redirect/3DS step-up. */
|
|
46
48
|
returnUrl?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Where the visit came from (RAD-293), as the browser kept it under the
|
|
51
|
+
* visitor's consent. Rebuilt into the closed shape before it travels.
|
|
52
|
+
*/
|
|
53
|
+
attribution?: unknown;
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
function isNonEmptyString(v: unknown): v is string {
|
|
@@ -445,7 +452,9 @@ export default defineEventHandler(async (event) => {
|
|
|
445
452
|
? await submitThroughProcurement(submission as never)
|
|
446
453
|
: {
|
|
447
454
|
kind: "order" as const,
|
|
448
|
-
|
|
455
|
+
// The cart's attribution goes with the order: orders never
|
|
456
|
+
// reads the cart for it (RAD-287).
|
|
457
|
+
order: await placeOrderWithAttribution<SubmittedOrder>(submission, sanitizeAttribution(body.attribution)),
|
|
449
458
|
};
|
|
450
459
|
|
|
451
460
|
if (outcome.kind === "request") {
|
|
@@ -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,6 +3,7 @@ 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";
|
|
7
8
|
|
|
8
9
|
/** Cart row of the carts app. */
|
|
@@ -360,6 +361,21 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
360
361
|
return cartId;
|
|
361
362
|
}
|
|
362
363
|
|
|
364
|
+
/**
|
|
365
|
+
* `PUT /v1/carts/{id} { attribution }` replaces the whole object (carts
|
|
366
|
+
* 2.9.0, RAD-287); first and last touch are the storefront's to compute.
|
|
367
|
+
* Through the escape hatch: the typed SDK predates the field.
|
|
368
|
+
*/
|
|
369
|
+
async setActiveCartAttribution(event: H3Event, attribution: Attribution | null): Promise<boolean> {
|
|
370
|
+
const cartId = await this.activeCartId(event);
|
|
371
|
+
if (!cartId) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
const query = visitCartKey(event, cartId) ?? undefined;
|
|
375
|
+
await useRevenexxSdk().call("PUT", cartPath(cartId), { ...(query ? { query } : {}), body: { attribution } });
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
|
|
363
379
|
async claimSession(event: H3Event, contactId: string): Promise<void> {
|
|
364
380
|
const sessionKey = getCookie(event, "cover-cart-session");
|
|
365
381
|
if (!sessionKey) {
|