@revenexx/cover 0.2.43 → 0.2.44
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/package.json +1 -1
- package/server/api/checkout/profile.get.ts +1 -1
- package/server/api/payment/methods.post.ts +1 -1
- package/server/api/quotes/request.post.ts +1 -1
- package/server/api/shipping/rates.post.ts +1 -1
- package/server/interfaces/checkoutProfile.ts +6 -1
- package/server/services/ApiAddressBookService.ts +34 -6
- package/server/services/LocalFileCheckoutProfileService.ts +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.44",
|
|
4
4
|
"description": "Cover \u2014 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",
|
|
@@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
|
-
return await getCheckoutProfileService().getProfile(event, user
|
|
15
|
+
return await getCheckoutProfileService().getProfile(event, user ?? null);
|
|
16
16
|
}
|
|
17
17
|
catch (err) {
|
|
18
18
|
getLogService().error("Service error: checkout/profile", toErrorContext(err));
|
|
@@ -28,7 +28,7 @@ export default defineEventHandler(async (event) => {
|
|
|
28
28
|
|
|
29
29
|
if (resolvePaymentServiceKey(event) !== "api") {
|
|
30
30
|
const user = await getAuthService(event).me(event);
|
|
31
|
-
const profile = await getCheckoutProfileService().getProfile(event, user
|
|
31
|
+
const profile = await getCheckoutProfileService().getProfile(event, user ?? null);
|
|
32
32
|
return {
|
|
33
33
|
managed: false,
|
|
34
34
|
methods: profile.availablePaymentMethods,
|
|
@@ -32,7 +32,7 @@ export default defineEventHandler(async (event): Promise<QuoteRequestResult> =>
|
|
|
32
32
|
throw createError({ statusCode: 401, message: "Sign in to ask for a quote" });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const profile = await getCheckoutProfileService().getProfile(event, actor.user
|
|
35
|
+
const profile = await getCheckoutProfileService().getProfile(event, actor.user);
|
|
36
36
|
const shippingAddress = profile.addresses.find(a => a.id === body.shippingAddressId);
|
|
37
37
|
const billingAddress = profile.addresses.find(a => a.id === body.billingAddressId);
|
|
38
38
|
if (!shippingAddress || !billingAddress) {
|
|
@@ -37,7 +37,7 @@ export default defineEventHandler(async (event) => {
|
|
|
37
37
|
|
|
38
38
|
if (resolveShippingServiceKey(event) !== "api") {
|
|
39
39
|
const user = await getAuthService(event).me(event);
|
|
40
|
-
const profile = await getCheckoutProfileService().getProfile(event, user
|
|
40
|
+
const profile = await getCheckoutProfileService().getProfile(event, user ?? null);
|
|
41
41
|
return {
|
|
42
42
|
managed: false,
|
|
43
43
|
methods: profile.availableDeliveryMethods,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
|
+
import type { AuthUser } from "../../app/interfaces/auth";
|
|
3
4
|
import type { CheckoutProfile } from "../../app/interfaces/checkout";
|
|
4
5
|
|
|
5
6
|
export interface ICheckoutProfileService {
|
|
@@ -7,6 +8,10 @@ export interface ICheckoutProfileService {
|
|
|
7
8
|
* The signed-in user's checkout profile. Addresses come from the
|
|
8
9
|
* address book service (mock or live per `addressService`); the event
|
|
9
10
|
* carries the session and the per-request service-mode resolution.
|
|
11
|
+
*
|
|
12
|
+
* The buyer themselves is passed, not just their id: an address book fed
|
|
13
|
+
* by an ERP carries no recipient name, and an order without one is
|
|
14
|
+
* refused — the person placing it is the answer.
|
|
10
15
|
*/
|
|
11
|
-
getProfile(event: H3Event,
|
|
16
|
+
getProfile(event: H3Event, user: AuthUser | null): Promise<CheckoutProfile>;
|
|
12
17
|
}
|
|
@@ -31,14 +31,18 @@ function splitStreet(street: string): { street: string; streetNumber: string } {
|
|
|
31
31
|
: { street: street.trim(), streetNumber: "" };
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function toAccountAddress(row: ApiAddressRow): AccountAddress {
|
|
34
|
+
function toAccountAddress(row: ApiAddressRow, companyFallback = ""): AccountAddress {
|
|
35
35
|
const name = (row.name ?? "").trim();
|
|
36
36
|
const [firstName, ...rest] = name.split(/\s+/).filter(Boolean);
|
|
37
37
|
const streetParts = splitStreet(row.street);
|
|
38
|
+
// An address the ERP hung on the company carries no company line of its
|
|
39
|
+
// own — the file has no such column. The company it belongs to is the
|
|
40
|
+
// answer, and an order will not go through without one.
|
|
41
|
+
const company = row.company || (row.organization_id ? companyFallback : "") || "";
|
|
38
42
|
return {
|
|
39
43
|
id: row.id,
|
|
40
|
-
company
|
|
41
|
-
label:
|
|
44
|
+
company,
|
|
45
|
+
label: company || name || streetParts.street,
|
|
42
46
|
firstName: firstName ?? "",
|
|
43
47
|
lastName: rest.join(" "),
|
|
44
48
|
street: streetParts.street,
|
|
@@ -62,6 +66,27 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
62
66
|
return sessionOrderRefs(event);
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
/**
|
|
70
|
+
* The company's name, for addresses that carry none. Best effort: a
|
|
71
|
+
* missing name is a worse label, while a failure here would be a checkout
|
|
72
|
+
* that cannot list an address at all.
|
|
73
|
+
*/
|
|
74
|
+
private async companyName(organizationId?: string): Promise<string> {
|
|
75
|
+
if (!organizationId) {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const org = await useRevenexxSdk().customers.customersOrganizationsGet({
|
|
80
|
+
id: organizationId,
|
|
81
|
+
}) as unknown as { name?: string };
|
|
82
|
+
return org?.name ?? "";
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
getLogService().error("API request failed: addresses/company-name", apiErrorContext(err));
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
65
90
|
private requireContact(event: H3Event): string {
|
|
66
91
|
const { contact_id } = this.contactRef(event);
|
|
67
92
|
if (!contact_id) {
|
|
@@ -104,15 +129,18 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
104
129
|
: Promise.resolve({ items: [] as ApiAddressRow[] }),
|
|
105
130
|
]);
|
|
106
131
|
const seen = new Set<string>();
|
|
107
|
-
|
|
132
|
+
const rows = [...(own.items ?? []), ...(company.items ?? [])]
|
|
108
133
|
.filter((row) => {
|
|
109
134
|
if (seen.has(row.id)) {
|
|
110
135
|
return false;
|
|
111
136
|
}
|
|
112
137
|
seen.add(row.id);
|
|
113
138
|
return true;
|
|
114
|
-
})
|
|
115
|
-
|
|
139
|
+
});
|
|
140
|
+
const companyName = rows.some(row => !row.company && row.organization_id)
|
|
141
|
+
? await this.companyName(organization_id)
|
|
142
|
+
: "";
|
|
143
|
+
return rows.map(row => toAccountAddress(row, companyName));
|
|
116
144
|
}
|
|
117
145
|
catch (err) {
|
|
118
146
|
getLogService().error("API request failed: addresses/list", apiErrorContext(err));
|
|
@@ -2,6 +2,7 @@ import type { H3Event } from "h3";
|
|
|
2
2
|
|
|
3
3
|
import type { AccountAddress } from "../../app/interfaces/account/address-list";
|
|
4
4
|
import type { Address } from "../../app/interfaces/address";
|
|
5
|
+
import type { AuthUser } from "../../app/interfaces/auth";
|
|
5
6
|
import type { CheckoutProfile } from "../../app/interfaces/checkout";
|
|
6
7
|
|
|
7
8
|
import type { ICheckoutProfileService } from "../interfaces/checkoutProfile";
|
|
@@ -88,16 +89,19 @@ function methodsFor(event: H3Event, mock: MethodBlocks): MethodBlocks {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
export class LocalFileCheckoutProfileService implements ICheckoutProfileService {
|
|
91
|
-
async getProfile(event: H3Event,
|
|
92
|
-
if (!
|
|
92
|
+
async getProfile(event: H3Event, user: AuthUser | null): Promise<CheckoutProfile> {
|
|
93
|
+
if (!user) {
|
|
93
94
|
return { ...GUEST_PROFILE, ...methodsFor(event, GUEST_PROFILE) };
|
|
94
95
|
}
|
|
95
96
|
try {
|
|
96
97
|
const entries = await getAddressBookService(event).list(event);
|
|
98
|
+
// A company address out of an ERP names no recipient — the file has
|
|
99
|
+
// no such column — and a business order is refused without one. The
|
|
100
|
+
// person placing the order is who it goes to.
|
|
97
101
|
const addresses: Address[] = entries.map(entry => ({
|
|
98
102
|
id: entry.id,
|
|
99
103
|
companyName: entry.company || `${entry.firstName} ${entry.lastName}`.trim(),
|
|
100
|
-
contactName: `${entry.firstName} ${entry.lastName}`.trim(),
|
|
104
|
+
contactName: `${entry.firstName} ${entry.lastName}`.trim() || user.name,
|
|
101
105
|
street: `${entry.street} ${entry.streetNumber}`.trim(),
|
|
102
106
|
city: entry.city,
|
|
103
107
|
postalCode: entry.zip,
|