@revenexx/cover 0.21.1 → 0.22.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/app.config.ts +5 -0
- package/app/components/checkout/onepage/CheckoutDeliverySection.vue +3 -0
- package/app/components/ui/forms/FormKitDatePicker.vue +8 -2
- package/app/composables/useCheckoutOnePage.ts +15 -4
- package/app/formkit.config.ts +1 -1
- package/app/shared/requestedDate.ts +49 -0
- package/i18n/locales/de/checkout.json +1 -0
- package/i18n/locales/en/checkout.json +1 -0
- package/package.json +1 -1
- package/server/api/orders/index.post.ts +17 -1
- package/server/utils/orderAttribution.ts +23 -3
package/app/app.config.ts
CHANGED
|
@@ -157,6 +157,11 @@ export default defineAppConfig({
|
|
|
157
157
|
// request tomorrow.
|
|
158
158
|
checkout: {
|
|
159
159
|
earliestDeliveryDays: 0,
|
|
160
|
+
// An ERP that plans every order by its delivery date needs one on
|
|
161
|
+
// every order. On, the checkout fills in the earliest day (see
|
|
162
|
+
// earliestDeliveryDays), the buyer may move it later but not clear
|
|
163
|
+
// it, and the BFF sends that day when the request carries none.
|
|
164
|
+
requestedDateRequired: false,
|
|
160
165
|
},
|
|
161
166
|
// Master data another system owns — an ERP, usually — is shown in the account
|
|
162
167
|
// and not changed there. That used to be four flags here, which was a guess in
|
|
@@ -44,6 +44,8 @@ const shippingCountry = computed(() => {
|
|
|
44
44
|
const appConfig = useAppConfig();
|
|
45
45
|
const earliestDeliveryDays = computed<number>(() =>
|
|
46
46
|
Number(appConfig.checkout?.earliestDeliveryDays ?? 0));
|
|
47
|
+
/** A date is always sent: prefilled, movable, never cleared (`checkout.requestedDateRequired`). */
|
|
48
|
+
const requestedDateRequired = computed<boolean>(() => Boolean(appConfig.checkout?.requestedDateRequired));
|
|
47
49
|
|
|
48
50
|
const { data: rates, status: ratesStatus } = useFetch<{
|
|
49
51
|
managed: boolean;
|
|
@@ -214,6 +216,7 @@ watch([deliveryOptions, () => form.value.deliveryMethod], ([options, selected])
|
|
|
214
216
|
:min-days="earliestDeliveryDays"
|
|
215
217
|
:max-days="100"
|
|
216
218
|
disable-weekends
|
|
219
|
+
:clearable="!requestedDateRequired"
|
|
217
220
|
@input="(value: unknown) => { form.requestedDate = String(value ?? ''); validateField('requestedDate'); }"
|
|
218
221
|
/>
|
|
219
222
|
<p
|
|
@@ -7,7 +7,8 @@ import type { FormKitFrameworkContext } from "@formkit/core";
|
|
|
7
7
|
* `type="datepicker"` (see formkit.config.ts). Values travel as ISO
|
|
8
8
|
* "YYYY-MM-DD" strings, so the input drops into any string-backed form
|
|
9
9
|
* state. Min/max and a date filter come in via the FormKit props
|
|
10
|
-
* `minDays`/`maxDays`/`disableWeekends
|
|
10
|
+
* `minDays`/`maxDays`/`disableWeekends`; `clearable: false` keeps a chosen
|
|
11
|
+
* date from being removed again (a field that must always hold one).
|
|
11
12
|
*/
|
|
12
13
|
const props = defineProps<{
|
|
13
14
|
context: FormKitFrameworkContext;
|
|
@@ -49,6 +50,7 @@ const maxValue = computed(() => {
|
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
const disableWeekends = computed(() => Boolean(props.context.disableWeekends));
|
|
53
|
+
const clearable = computed(() => props.context.clearable !== false && props.context.clearable !== "false");
|
|
52
54
|
|
|
53
55
|
function isDateDisabled(date: { toDate: (tz: string) => Date }): boolean {
|
|
54
56
|
if (!disableWeekends.value) {
|
|
@@ -59,6 +61,10 @@ function isDateDisabled(date: { toDate: (tz: string) => Date }): boolean {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function onSelect(value: CalendarDate | null | undefined): void {
|
|
64
|
+
if (!value && !clearable.value) {
|
|
65
|
+
open.value = false;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
62
68
|
props.context.node.input(value ? value.toString() : "");
|
|
63
69
|
open.value = false;
|
|
64
70
|
}
|
|
@@ -106,7 +112,7 @@ function clear(): void {
|
|
|
106
112
|
@update:model-value="onSelect($event as CalendarDate | null)"
|
|
107
113
|
/>
|
|
108
114
|
<div
|
|
109
|
-
v-if="calendarValue"
|
|
115
|
+
v-if="calendarValue && clearable"
|
|
110
116
|
class="flex justify-end pt-1"
|
|
111
117
|
>
|
|
112
118
|
<UButton
|
|
@@ -4,6 +4,7 @@ import type { CartCalculation } from "../interfaces/cart-calculation";
|
|
|
4
4
|
import type { CheckoutOnePageForm, CheckoutProfile } from "../interfaces/checkout";
|
|
5
5
|
import { checkoutAddressFieldOf, checkoutAddressRefusalOf } from "../shared/checkoutAddressRefusal";
|
|
6
6
|
import { browserSession, purchaseFromCart, stashPurchase } from "../shared/themeEvents";
|
|
7
|
+
import { calendarToday, earliestRequestedDate } from "../shared/requestedDate";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Who is checking out:
|
|
@@ -71,7 +72,17 @@ export function useCheckoutOnePage() {
|
|
|
71
72
|
const customerType = useState<CheckoutCustomerType>("checkout-customer-type", () => "account");
|
|
72
73
|
const isGuest = computed(() => customerType.value !== "account");
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
// The delivery date every order must carry where the merchant requires one
|
|
76
|
+
// (`checkout.requestedDateRequired`): the earliest day they can deliver,
|
|
77
|
+
// prefilled so the buyer sees it and can only move it later.
|
|
78
|
+
const appConfig = useAppConfig();
|
|
79
|
+
const requestedDateRequired = computed(() => Boolean(appConfig.checkout?.requestedDateRequired));
|
|
80
|
+
const defaultRequestedDate = (): string => requestedDateRequired.value
|
|
81
|
+
? earliestRequestedDate(Number(appConfig.checkout?.earliestDeliveryDays ?? 0), calendarToday())
|
|
82
|
+
: "";
|
|
83
|
+
const emptyForm = (): CheckoutOnePageForm => ({ ...EMPTY_FORM, requestedDate: defaultRequestedDate() });
|
|
84
|
+
|
|
85
|
+
const form = useState<CheckoutOnePageForm>("checkout-one-page-form", emptyForm);
|
|
75
86
|
const guestContact = useState("checkout-guest-contact", () => ({ email: "", phone: "" }));
|
|
76
87
|
const guestShipping = useState<CheckoutGuestAddress>("checkout-guest-shipping", () => ({ ...EMPTY_GUEST_ADDRESS }));
|
|
77
88
|
const guestBilling = useState<CheckoutGuestAddress>("checkout-guest-billing", () => ({ ...EMPTY_GUEST_ADDRESS }));
|
|
@@ -94,7 +105,7 @@ export function useCheckoutOnePage() {
|
|
|
94
105
|
|
|
95
106
|
const requestedDateError = (value: string): string | null => {
|
|
96
107
|
if (!value) {
|
|
97
|
-
return null;
|
|
108
|
+
return requestedDateRequired.value ? t("onepage.errors.requestedDateRequired") : null;
|
|
98
109
|
}
|
|
99
110
|
const date = new Date(value);
|
|
100
111
|
if (isNaN(date.getTime())) {
|
|
@@ -163,7 +174,7 @@ export function useCheckoutOnePage() {
|
|
|
163
174
|
|
|
164
175
|
function initFromProfile(p: CheckoutProfile) {
|
|
165
176
|
form.value = {
|
|
166
|
-
...
|
|
177
|
+
...emptyForm(),
|
|
167
178
|
shippingAddressId: p.defaultShippingAddressId,
|
|
168
179
|
billingAddressId: p.defaultBillingAddressId,
|
|
169
180
|
deliveryMethod: p.defaultDeliveryMethod,
|
|
@@ -541,7 +552,7 @@ export function useCheckoutOnePage() {
|
|
|
541
552
|
}
|
|
542
553
|
|
|
543
554
|
function reset() {
|
|
544
|
-
form.value =
|
|
555
|
+
form.value = emptyForm();
|
|
545
556
|
guestContact.value = { email: "", phone: "" };
|
|
546
557
|
guestShipping.value = { ...EMPTY_GUEST_ADDRESS };
|
|
547
558
|
guestBilling.value = { ...EMPTY_GUEST_ADDRESS };
|
package/app/formkit.config.ts
CHANGED
|
@@ -38,7 +38,7 @@ export default defineFormKitConfig({
|
|
|
38
38
|
// Custom inputs: `datepicker` wraps Nuxt UI's UCalendar (ISO string value).
|
|
39
39
|
inputs: {
|
|
40
40
|
datepicker: createInput(FormKitDatePicker, {
|
|
41
|
-
props: ["minDays", "maxDays", "disableWeekends"],
|
|
41
|
+
props: ["minDays", "maxDays", "disableWeekends", "clearable"],
|
|
42
42
|
}),
|
|
43
43
|
},
|
|
44
44
|
rules: {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The requested delivery date a storefront fills in by itself.
|
|
3
|
+
*
|
|
4
|
+
* A merchant whose ERP plans every order by its delivery date cannot take an
|
|
5
|
+
* order without one (`checkout.requestedDateRequired`). The buyer may still
|
|
6
|
+
* choose a later day; when they choose none, the order carries the first day
|
|
7
|
+
* the merchant can deliver: today plus `checkout.earliestDeliveryDays`, moved
|
|
8
|
+
* to the next Monday when that lands on a weekend — the calendar offers no
|
|
9
|
+
* weekend either.
|
|
10
|
+
*
|
|
11
|
+
* Dates are calendar days as ISO "YYYY-MM-DD" strings, the shape the date
|
|
12
|
+
* picker and the orders app both use.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Today's calendar date in `timeZone`, as "YYYY-MM-DD". */
|
|
16
|
+
export function calendarToday(timeZone?: string, now: Date = new Date()): string {
|
|
17
|
+
// en-CA formats a date as YYYY-MM-DD.
|
|
18
|
+
return new Intl.DateTimeFormat("en-CA", {
|
|
19
|
+
timeZone,
|
|
20
|
+
year: "numeric",
|
|
21
|
+
month: "2-digit",
|
|
22
|
+
day: "2-digit",
|
|
23
|
+
}).format(now);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The first working day `leadDays` or more after `todayIso`. */
|
|
27
|
+
export function earliestRequestedDate(leadDays: number, todayIso: string): string {
|
|
28
|
+
const [y, m, d] = todayIso.split("-").map(Number);
|
|
29
|
+
const date = new Date(Date.UTC(y!, m! - 1, d!));
|
|
30
|
+
date.setUTCDate(date.getUTCDate() + Math.max(0, Math.floor(Number.isFinite(leadDays) ? leadDays : 0)));
|
|
31
|
+
const weekday = date.getUTCDay();
|
|
32
|
+
if (weekday === 6) {
|
|
33
|
+
date.setUTCDate(date.getUTCDate() + 2);
|
|
34
|
+
}
|
|
35
|
+
else if (weekday === 0) {
|
|
36
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
37
|
+
}
|
|
38
|
+
return date.toISOString().slice(0, 10);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The date an order goes out with when the storefront requires one: the
|
|
43
|
+
* buyer's own, unless it is missing, malformed or earlier than the merchant
|
|
44
|
+
* can deliver — then the earliest possible day.
|
|
45
|
+
*/
|
|
46
|
+
export function requiredRequestedDate(given: unknown, earliestIso: string): string {
|
|
47
|
+
const value = typeof given === "string" ? given.trim() : "";
|
|
48
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value) && value >= earliestIso ? value : earliestIso;
|
|
49
|
+
}
|
|
@@ -194,6 +194,7 @@
|
|
|
194
194
|
"requestedDateInvalid": "Bitte geben Sie ein gültiges Datum ein.",
|
|
195
195
|
"submitError": "Bestellung fehlgeschlagen. Bitte versuchen Sie es erneut.",
|
|
196
196
|
"orderNumberRequired": "Bitte geben Sie Ihre Bestellnummer an.",
|
|
197
|
+
"requestedDateRequired": "Bitte wählen Sie einen Wunschtermin.",
|
|
197
198
|
"requestedDatePast": "Der Wunschtermin darf nicht in der Vergangenheit liegen.",
|
|
198
199
|
"requestedDateTooFar": "Der Wunschtermin darf maximal {days} Tage in der Zukunft liegen.",
|
|
199
200
|
"requestedDateWeekend": "Bitte wählen Sie einen Werktag als Wunschtermin.",
|
|
@@ -194,6 +194,7 @@
|
|
|
194
194
|
"requestedDateInvalid": "Please enter a valid date.",
|
|
195
195
|
"submitError": "Failed to place order. Please try again.",
|
|
196
196
|
"orderNumberRequired": "Please provide your order number.",
|
|
197
|
+
"requestedDateRequired": "Please pick a requested delivery date.",
|
|
197
198
|
"requestedDatePast": "The requested date must not be in the past.",
|
|
198
199
|
"requestedDateTooFar": "The requested date may be at most {days} days ahead.",
|
|
199
200
|
"requestedDateWeekend": "Please pick a working day as the requested date.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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",
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { pspReturnUrl, rememberPspReturn } from "../../utils/pspReturn";
|
|
16
16
|
import { placeOrderWithAttribution } from "../../utils/orderAttribution";
|
|
17
17
|
import { sanitizeAttribution } from "../../../app/shared/campaignAttribution";
|
|
18
|
+
import { calendarToday, earliestRequestedDate, requiredRequestedDate } from "../../../app/shared/requestedDate";
|
|
18
19
|
|
|
19
20
|
// Method codes are generic — live mode validates them against the
|
|
20
21
|
// payments app; the demo-only methods keep their extra fields.
|
|
@@ -449,7 +450,7 @@ export default defineEventHandler(async (event) => {
|
|
|
449
450
|
...(body.deliveryNote ? { delivery_note: body.deliveryNote } : {}),
|
|
450
451
|
...(body.orderNote ? { order_note: body.orderNote } : {}),
|
|
451
452
|
...(body.partialDelivery !== undefined ? { partial_delivery: body.partialDelivery } : {}),
|
|
452
|
-
...(body.requestedDate ? { requested_date: body.requestedDate } : {}),
|
|
453
|
+
...(requestedDateOf(body.requestedDate) ? { requested_date: requestedDateOf(body.requestedDate) } : {}),
|
|
453
454
|
},
|
|
454
455
|
};
|
|
455
456
|
|
|
@@ -768,3 +769,18 @@ export default defineEventHandler(async (event) => {
|
|
|
768
769
|
throw createError({ statusCode: 500, message: "Internal server error" });
|
|
769
770
|
}
|
|
770
771
|
});
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* The requested delivery date the order goes out with. Where the storefront
|
|
775
|
+
* requires one (`checkout.requestedDateRequired`) the BFF does not trust the
|
|
776
|
+
* browser to have sent it: a missing, malformed or too early date becomes the
|
|
777
|
+
* earliest day the merchant can deliver, in the merchant's time zone.
|
|
778
|
+
*/
|
|
779
|
+
function requestedDateOf(given: string | undefined): string | undefined {
|
|
780
|
+
const checkout = (useAppConfig() as { checkout?: { requestedDateRequired?: boolean; earliestDeliveryDays?: number } }).checkout;
|
|
781
|
+
if (!checkout?.requestedDateRequired) {
|
|
782
|
+
return given || undefined;
|
|
783
|
+
}
|
|
784
|
+
const earliest = earliestRequestedDate(Number(checkout.earliestDeliveryDays ?? 0), calendarToday("Europe/Berlin"));
|
|
785
|
+
return requiredRequestedDate(given, earliest);
|
|
786
|
+
}
|
|
@@ -47,19 +47,39 @@ function clientAdding(client: SdkClient, extra: Record<string, unknown>): SdkCli
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Keys of a placement the typed SDK does not map and silently drops, sent on
|
|
52
|
+
* the wire as they are given. `discounts` is what the promotions app decided
|
|
53
|
+
* and reserved for this cart: without it the order is stored at the full
|
|
54
|
+
* price while the redemption is committed against it.
|
|
55
|
+
*/
|
|
56
|
+
const UNMAPPED_KEYS = ["discounts"] as const;
|
|
57
|
+
|
|
58
|
+
function unmappedOf(submission: unknown): Record<string, unknown> {
|
|
59
|
+
const body = (submission ?? {}) as Record<string, unknown>;
|
|
60
|
+
return Object.fromEntries(UNMAPPED_KEYS
|
|
61
|
+
.filter(key => Array.isArray(body[key]) ? (body[key] as unknown[]).length > 0 : body[key] !== undefined)
|
|
62
|
+
.map(key => [key, body[key]]));
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
export async function placeOrderWithAttribution<T>(submission: unknown, attribution: Attribution | null): Promise<T> {
|
|
51
66
|
const sdk = useRevenexxSdk();
|
|
67
|
+
const unmapped = unmappedOf(submission);
|
|
68
|
+
const place = async (extra: Record<string, unknown>): Promise<T> => (Object.keys(extra).length
|
|
69
|
+
? await new Orders(clientAdding(sdk.client, extra) as never).ordersPlace(submission as never)
|
|
70
|
+
: await sdk.orders.ordersPlace(submission as never)) as unknown as T;
|
|
71
|
+
|
|
52
72
|
if (!attribution) {
|
|
53
|
-
return await
|
|
73
|
+
return await place(unmapped);
|
|
54
74
|
}
|
|
55
75
|
try {
|
|
56
|
-
return await
|
|
76
|
+
return await place({ ...unmapped, attribution });
|
|
57
77
|
}
|
|
58
78
|
catch (err) {
|
|
59
79
|
if (!isAttributionRefusal(err)) {
|
|
60
80
|
throw err;
|
|
61
81
|
}
|
|
62
82
|
getLogService().warn("order attribution refused, placed without it", apiErrorContext(err));
|
|
63
|
-
return await
|
|
83
|
+
return await place(unmapped);
|
|
64
84
|
}
|
|
65
85
|
}
|