@revenexx/cover 0.11.0 → 0.12.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/components/account/carts/AccountCartsTable.vue +4 -2
- package/app/components/auth/AuthLoginPanel.vue +71 -16
- package/app/components/auth/AuthRegisterPanel.vue +1 -1
- package/app/components/cart/switcher/CartSwitcher.vue +5 -2
- package/app/composables/useAuthStore.ts +4 -2
- package/app/interfaces/auth.ts +12 -2
- package/app/interfaces/shopSettings.ts +84 -0
- package/i18n/locales/de/auth.json +41 -2
- package/i18n/locales/de/cart.json +2 -1
- package/i18n/locales/en/auth.json +41 -2
- package/i18n/locales/en/cart.json +2 -1
- package/package.json +1 -1
- package/server/api/auth/login.post.ts +16 -3
- package/server/api/carts/[id]/activate.post.ts +7 -0
- package/server/api/carts/[id]/index.delete.ts +2 -0
- package/server/api/carts/index.post.ts +4 -0
- package/server/interfaces/auth.ts +10 -1
- package/server/routes/punchout/start.get.ts +4 -13
- package/server/services/ApiAuthService.ts +22 -6
- package/server/services/ApiCartService.ts +64 -22
- package/server/services/MockAuthService.ts +21 -2
- package/server/utils/cartOwnership.ts +40 -0
- package/server/utils/shopSettings.ts +5 -0
|
@@ -15,10 +15,12 @@ const { to } = useAppUrl();
|
|
|
15
15
|
const toast = useToast();
|
|
16
16
|
const cart = useCartStore();
|
|
17
17
|
const { settings } = useB2BContext();
|
|
18
|
+
const { isPunchout } = usePunchoutVisit();
|
|
18
19
|
const { formatCurrency } = useCartSummaryFormatting();
|
|
19
20
|
const { tableUi } = useDataTable();
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
// A punchout visit has exactly one cart, the one handed back (RAD-109).
|
|
23
|
+
const enabled = computed(() => settings.value?.cart.multipleCarts === true && !isPunchout.value);
|
|
22
24
|
|
|
23
25
|
/* ---- search ----------------------------------------------------------- */
|
|
24
26
|
const search = ref("");
|
|
@@ -113,7 +115,7 @@ function onDelete(): void {
|
|
|
113
115
|
color="neutral"
|
|
114
116
|
variant="subtle"
|
|
115
117
|
:icon="icon('info')"
|
|
116
|
-
:title="t('cart.multi.page.disabled')"
|
|
118
|
+
:title="isPunchout ? t('cart.multi.page.punchout') : t('cart.multi.page.disabled')"
|
|
117
119
|
/>
|
|
118
120
|
|
|
119
121
|
<template v-else>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { LoginFormState } from "../../interfaces/auth";
|
|
3
|
+
import type { LoginIdentifierKind } from "../../interfaces/shopSettings";
|
|
4
|
+
import { loginIdentifierField, loginIdentifierKind, offeredLoginIdentifiers } from "../../interfaces/shopSettings";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* "I already have an account" panel of the split login page. Owns the login
|
|
@@ -29,6 +31,17 @@ const magicLinkOffered = computed(() => signIn.value?.magicLink === true);
|
|
|
29
31
|
const otpOffered = computed(() => signIn.value?.emailOtp === true);
|
|
30
32
|
const anyMailedWay = computed(() => magicLinkOffered.value || otpOffered.value);
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* What the password field asks for (RAD-151): an address, a username, a
|
|
36
|
+
* customer number, or any mix the merchant switched on. Label, keyboard,
|
|
37
|
+
* autofill and validation follow it — a field that insists on an address would
|
|
38
|
+
* refuse a buyer the shop lets in by username before the shop ever saw it.
|
|
39
|
+
*/
|
|
40
|
+
const identifierField = computed(() => loginIdentifierField(signIn.value?.identifiers));
|
|
41
|
+
const identifierLabel = computed(() => t(`${identifierField.value.key}.label`));
|
|
42
|
+
/** Where it accepts only an address, the mailed ways share that one field. */
|
|
43
|
+
const identifierIsEmail = computed(() => identifierField.value.type === "email");
|
|
44
|
+
|
|
32
45
|
/* ---- signing in by mail ------------------------------------------------ */
|
|
33
46
|
|
|
34
47
|
/** Which mailed way the buyer is in the middle of, and how far. */
|
|
@@ -38,13 +51,21 @@ const mailSent = ref(false);
|
|
|
38
51
|
const otpUserId = ref<string | null>(null);
|
|
39
52
|
const otpCode = ref("");
|
|
40
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The address a link or code goes to. The mailed ways only ever take an
|
|
56
|
+
* address, so where the sign-in field accepts a username too, they get a field
|
|
57
|
+
* of their own rather than mailing whatever was typed.
|
|
58
|
+
*/
|
|
59
|
+
const mailAddress = computed(() => (passwordOffered.value && identifierIsEmail.value ? state.identifier : state.email).trim());
|
|
60
|
+
const mailNeedsOwnField = computed(() => !passwordOffered.value || !identifierIsEmail.value);
|
|
61
|
+
|
|
41
62
|
async function requestMail(kind: "magic-link" | "otp"): Promise<void> {
|
|
42
|
-
if (!
|
|
63
|
+
if (!mailAddress.value) {
|
|
43
64
|
return;
|
|
44
65
|
}
|
|
45
66
|
mailedKind.value = kind;
|
|
46
67
|
try {
|
|
47
|
-
otpUserId.value = await auth.requestSignInMail(kind,
|
|
68
|
+
otpUserId.value = await auth.requestSignInMail(kind, mailAddress.value);
|
|
48
69
|
mailSent.value = true;
|
|
49
70
|
}
|
|
50
71
|
catch {
|
|
@@ -77,14 +98,41 @@ function startOver(): void {
|
|
|
77
98
|
}
|
|
78
99
|
|
|
79
100
|
const state = reactive<LoginFormState>({
|
|
80
|
-
|
|
101
|
+
identifier: "",
|
|
81
102
|
password: "",
|
|
103
|
+
email: "",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/** The kind of identifier last submitted — what a refusal is worded for. */
|
|
107
|
+
const submittedKind = ref<LoginIdentifierKind>("email");
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The refusal, in the words of what was typed. Wrong credentials name the
|
|
111
|
+
* identifier the buyer used; a customer number adds that it signs in as the
|
|
112
|
+
* company's primary contact, which is why a buyer's own password does not
|
|
113
|
+
* open it. An identifier the shop does not take says which ones it does.
|
|
114
|
+
*/
|
|
115
|
+
const errorMessage = computed(() => {
|
|
116
|
+
if (!error.value) {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
if (error.value === "auth.login.errors.invalidCredentials") {
|
|
120
|
+
return t(`auth.login.errors.invalidCredentialsBy.${submittedKind.value}`);
|
|
121
|
+
}
|
|
122
|
+
if (error.value === "auth.login.errors.identifierNotOffered") {
|
|
123
|
+
return t(error.value, { accepted: identifierLabel.value });
|
|
124
|
+
}
|
|
125
|
+
return t(error.value);
|
|
82
126
|
});
|
|
83
127
|
|
|
84
128
|
async function onSubmit(): Promise<void> {
|
|
129
|
+
const identifier = state.identifier.trim();
|
|
130
|
+
// One accepted kind is what was meant, whatever it looks like.
|
|
131
|
+
const offered = offeredLoginIdentifiers(signIn.value?.identifiers);
|
|
132
|
+
submittedKind.value = offered.length === 1 ? offered[0]! : loginIdentifierKind(identifier);
|
|
85
133
|
try {
|
|
86
134
|
await auth.login({
|
|
87
|
-
|
|
135
|
+
identifier,
|
|
88
136
|
password: state.password,
|
|
89
137
|
});
|
|
90
138
|
emit("success");
|
|
@@ -123,7 +171,7 @@ async function onSubmit(): Promise<void> {
|
|
|
123
171
|
{{ t(passwordOffered ? 'auth.login.mailed.alternative' : 'auth.login.mailed.only') }}
|
|
124
172
|
</p>
|
|
125
173
|
<UInput
|
|
126
|
-
v-if="
|
|
174
|
+
v-if="mailNeedsOwnField"
|
|
127
175
|
v-model="state.email"
|
|
128
176
|
type="email"
|
|
129
177
|
class="w-full"
|
|
@@ -135,7 +183,7 @@ async function onSubmit(): Promise<void> {
|
|
|
135
183
|
v-if="magicLinkOffered"
|
|
136
184
|
color="neutral"
|
|
137
185
|
:variant="passwordOffered ? 'outline' : 'solid'"
|
|
138
|
-
:disabled="!
|
|
186
|
+
:disabled="!mailAddress || loading"
|
|
139
187
|
:label="t('auth.login.mailed.requestLink')"
|
|
140
188
|
@click="requestMail('magic-link')"
|
|
141
189
|
/>
|
|
@@ -143,7 +191,7 @@ async function onSubmit(): Promise<void> {
|
|
|
143
191
|
v-if="otpOffered"
|
|
144
192
|
color="neutral"
|
|
145
193
|
:variant="passwordOffered ? 'outline' : 'solid'"
|
|
146
|
-
:disabled="!
|
|
194
|
+
:disabled="!mailAddress || loading"
|
|
147
195
|
:label="t('auth.login.mailed.requestCode')"
|
|
148
196
|
@click="requestMail('otp')"
|
|
149
197
|
/>
|
|
@@ -155,7 +203,7 @@ async function onSubmit(): Promise<void> {
|
|
|
155
203
|
color="success"
|
|
156
204
|
variant="soft"
|
|
157
205
|
:title="t('auth.login.mailed.sentTitle')"
|
|
158
|
-
:description="t(mailedKind === 'otp' ? 'auth.login.mailed.sentCode' : 'auth.login.mailed.sentLink', { email:
|
|
206
|
+
:description="t(mailedKind === 'otp' ? 'auth.login.mailed.sentCode' : 'auth.login.mailed.sentLink', { email: mailAddress })"
|
|
159
207
|
/>
|
|
160
208
|
<!-- The code is typed back here; a link is followed instead. -->
|
|
161
209
|
<div
|
|
@@ -193,15 +241,22 @@ async function onSubmit(): Promise<void> {
|
|
|
193
241
|
class="space-y-4"
|
|
194
242
|
@submit="onSubmit"
|
|
195
243
|
>
|
|
244
|
+
<!-- Keyed on the type: FormKit fixes an input's type when it mounts. -->
|
|
196
245
|
<FormKit
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
246
|
+
:key="identifierField.type"
|
|
247
|
+
v-model="state.identifier"
|
|
248
|
+
:type="identifierField.type"
|
|
249
|
+
:label="identifierLabel"
|
|
250
|
+
name="identifier"
|
|
251
|
+
:validation="identifierField.validation"
|
|
252
|
+
:validation-label="identifierLabel"
|
|
253
|
+
:autocomplete="identifierField.autocomplete"
|
|
254
|
+
:inputmode="identifierField.inputmode"
|
|
255
|
+
autocapitalize="none"
|
|
256
|
+
spellcheck="false"
|
|
257
|
+
:help="identifierField.customerNumber ? t('auth.login.identifierHelp.customerNumber') : undefined"
|
|
203
258
|
input-class="h-8 py-1 bg-(--ui-bg)"
|
|
204
|
-
:placeholder="t(
|
|
259
|
+
:placeholder="t(`${identifierField.key}.placeholder`)"
|
|
205
260
|
/>
|
|
206
261
|
|
|
207
262
|
<FormKit
|
|
@@ -219,7 +274,7 @@ async function onSubmit(): Promise<void> {
|
|
|
219
274
|
v-if="error"
|
|
220
275
|
color="error"
|
|
221
276
|
variant="soft"
|
|
222
|
-
:title="
|
|
277
|
+
:title="errorMessage"
|
|
223
278
|
/>
|
|
224
279
|
|
|
225
280
|
<UButton
|
|
@@ -5,15 +5,18 @@ import type { DropdownMenuItem } from "@nuxt/ui";
|
|
|
5
5
|
/**
|
|
6
6
|
* Cart switcher for the cart page (multiple-carts feature): pick the
|
|
7
7
|
* active cart, create a new one, rename or delete the current one.
|
|
8
|
-
* Renders nothing while the org flag is off
|
|
8
|
+
* Renders nothing while the org flag is off, and on a punchout visit: the
|
|
9
|
+
* visit works in the one cart its procurement system receives (RAD-109), and
|
|
10
|
+
* the BFF refuses switching or deleting it with 409 `punchout_cart_fixed`.
|
|
9
11
|
*/
|
|
10
12
|
const { icon } = useIcons();
|
|
11
13
|
const { t } = useI18n();
|
|
12
14
|
const toast = useToast();
|
|
13
15
|
const cart = useCartStore();
|
|
14
16
|
const { settings } = useB2BContext();
|
|
17
|
+
const { isPunchout } = usePunchoutVisit();
|
|
15
18
|
|
|
16
|
-
const enabled = computed(() => settings.value?.cart.multipleCarts === true);
|
|
19
|
+
const enabled = computed(() => settings.value?.cart.multipleCarts === true && !isPunchout.value);
|
|
17
20
|
|
|
18
21
|
const createOpen = ref(false);
|
|
19
22
|
const renameOpen = ref(false);
|
|
@@ -42,6 +42,8 @@ function mapAuthError(err: unknown, context: "login" | "recovery" | "register" =
|
|
|
42
42
|
return "auth.login.errors.accountBlocked";
|
|
43
43
|
case "organization_blocked":
|
|
44
44
|
return "auth.login.errors.organizationBlocked";
|
|
45
|
+
case "identifier_not_offered":
|
|
46
|
+
return "auth.login.errors.identifierNotOffered";
|
|
45
47
|
case "general_rate_limit_exceeded":
|
|
46
48
|
return context === "recovery"
|
|
47
49
|
? "auth.recovery.errors.rateLimited"
|
|
@@ -114,13 +116,13 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
114
116
|
}
|
|
115
117
|
};
|
|
116
118
|
|
|
117
|
-
const login = async ({
|
|
119
|
+
const login = async ({ identifier, password }: LoginInput) => {
|
|
118
120
|
loading.value = true;
|
|
119
121
|
error.value = null;
|
|
120
122
|
try {
|
|
121
123
|
const result = await $fetch<{ user: AuthUser; session: StoredSession }>("/api/auth/login", {
|
|
122
124
|
method: "POST",
|
|
123
|
-
body: {
|
|
125
|
+
body: { identifier, password },
|
|
124
126
|
});
|
|
125
127
|
user.value = result.user;
|
|
126
128
|
session.value = result.session;
|
package/app/interfaces/auth.ts
CHANGED
|
@@ -69,7 +69,11 @@ export interface RegisterInput {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export interface LoginInput {
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* What the buyer signs in with: an address, a username or a customer
|
|
74
|
+
* number, whichever the shop accepts (RAD-151).
|
|
75
|
+
*/
|
|
76
|
+
identifier: string;
|
|
73
77
|
password: string;
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -91,8 +95,14 @@ export interface StoredSession {
|
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
export interface LoginFormState {
|
|
94
|
-
|
|
98
|
+
/** The password sign-in field — whatever identifiers the shop accepts. */
|
|
99
|
+
identifier: string;
|
|
95
100
|
password: string;
|
|
101
|
+
/**
|
|
102
|
+
* The address a mailed link or code goes to. Only its own field where the
|
|
103
|
+
* sign-in field accepts more than an address; otherwise it is that field.
|
|
104
|
+
*/
|
|
105
|
+
email: string;
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
export interface RegisterFormState {
|
|
@@ -202,6 +202,24 @@ export interface SignInAppSettings {
|
|
|
202
202
|
emailOtp: boolean;
|
|
203
203
|
/** customers.email_verification — when the address has to be confirmed. */
|
|
204
204
|
emailVerification: "off" | "on_registration" | "required_for_login";
|
|
205
|
+
/**
|
|
206
|
+
* What a buyer may type into the password sign-in field (RAD-151). The
|
|
207
|
+
* mailed ways — link and code — always take an address, whatever is here.
|
|
208
|
+
*/
|
|
209
|
+
identifiers: LoginIdentifierAppSettings;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface LoginIdentifierAppSettings {
|
|
213
|
+
/** customers.login_identifier_email — on unless the merchant turned it off. */
|
|
214
|
+
email: boolean;
|
|
215
|
+
/** customers.login_identifier_username — off until asked for. */
|
|
216
|
+
username: boolean;
|
|
217
|
+
/**
|
|
218
|
+
* customers.login_identifier_customer_number — off until asked for. A
|
|
219
|
+
* customer number names a company, so it signs in as that company's
|
|
220
|
+
* primary contact.
|
|
221
|
+
*/
|
|
222
|
+
customerNumber: boolean;
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
/* ------------------------------------------------------------------ */
|
|
@@ -321,3 +339,69 @@ export function resolvePriceBasis(prices: PriceAppSettings): "net" | "gross" {
|
|
|
321
339
|
}
|
|
322
340
|
return prices.stored;
|
|
323
341
|
}
|
|
342
|
+
|
|
343
|
+
/* ------------------------------------------------------------------ */
|
|
344
|
+
/* What the sign-in field asks for */
|
|
345
|
+
/* ------------------------------------------------------------------ */
|
|
346
|
+
|
|
347
|
+
export type LoginIdentifierKind = "email" | "username" | "customerNumber";
|
|
348
|
+
|
|
349
|
+
/** In the order a label names them. */
|
|
350
|
+
const IDENTIFIER_ORDER: readonly LoginIdentifierKind[] = ["email", "username", "customerNumber"];
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The identifiers this shop accepts, in label order.
|
|
354
|
+
*
|
|
355
|
+
* Never empty: the customers app takes the address when the merchant has
|
|
356
|
+
* switched every identifier off — a misconfiguration narrows a shop and never
|
|
357
|
+
* shuts it — so the field has to ask for the address in that case too.
|
|
358
|
+
*/
|
|
359
|
+
export function offeredLoginIdentifiers(identifiers?: LoginIdentifierAppSettings | null): LoginIdentifierKind[] {
|
|
360
|
+
const offered = IDENTIFIER_ORDER.filter(kind =>
|
|
361
|
+
kind === "email" ? identifiers?.email !== false : identifiers?.[kind] === true,
|
|
362
|
+
);
|
|
363
|
+
return offered.length > 0 ? offered : ["email"];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Which kind of identifier a typed value is, by the same rule the customers
|
|
368
|
+
* app applies: an `@` makes an address, digits alone a customer number, and
|
|
369
|
+
* anything else is a username.
|
|
370
|
+
*/
|
|
371
|
+
export function loginIdentifierKind(value: string): LoginIdentifierKind {
|
|
372
|
+
const trimmed = value.trim();
|
|
373
|
+
if (trimmed.includes("@")) {
|
|
374
|
+
return "email";
|
|
375
|
+
}
|
|
376
|
+
if (/^[0-9]+$/.test(trimmed)) {
|
|
377
|
+
return "customerNumber";
|
|
378
|
+
}
|
|
379
|
+
return "username";
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** How the password sign-in field presents itself for one set of identifiers. */
|
|
383
|
+
export interface LoginIdentifierField {
|
|
384
|
+
/** i18n key under which `.label` and `.placeholder` name the field. */
|
|
385
|
+
key: string;
|
|
386
|
+
type: "email" | "text";
|
|
387
|
+
autocomplete: "email" | "username";
|
|
388
|
+
inputmode: "email" | "numeric" | "text";
|
|
389
|
+
/** FormKit validation: the address format only where nothing else is accepted. */
|
|
390
|
+
validation: string;
|
|
391
|
+
/** Whether a customer number is accepted, which signs in as the company's primary contact. */
|
|
392
|
+
customerNumber: boolean;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export function loginIdentifierField(identifiers?: LoginIdentifierAppSettings | null): LoginIdentifierField {
|
|
396
|
+
const offered = offeredLoginIdentifiers(identifiers);
|
|
397
|
+
const emailOnly = offered.length === 1 && offered[0] === "email";
|
|
398
|
+
const numberOnly = offered.length === 1 && offered[0] === "customerNumber";
|
|
399
|
+
return {
|
|
400
|
+
key: `auth.login.identifier.${offered.join("_")}`,
|
|
401
|
+
type: emailOnly ? "email" : "text",
|
|
402
|
+
autocomplete: emailOnly ? "email" : "username",
|
|
403
|
+
inputmode: emailOnly ? "email" : numberOnly ? "numeric" : "text",
|
|
404
|
+
validation: emailOnly ? "required|email" : "required",
|
|
405
|
+
customerNumber: offered.includes("customerNumber"),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
@@ -103,7 +103,13 @@
|
|
|
103
103
|
"rateLimited": "Zu viele Versuche. Bitte versuchen Sie es in ein paar Minuten erneut.",
|
|
104
104
|
"network": "Server nicht erreichbar. Bitte prüfen Sie Ihre Verbindung und versuchen Sie es erneut.",
|
|
105
105
|
"sessionExists": "Sie sind bereits angemeldet.",
|
|
106
|
-
"unknown": "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
|
|
106
|
+
"unknown": "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut.",
|
|
107
|
+
"identifierNotOffered": "Diese Angabe nimmt der Shop zur Anmeldung nicht an. Bitte melden Sie sich mit {accepted} an.",
|
|
108
|
+
"invalidCredentialsBy": {
|
|
109
|
+
"email": "E-Mail oder Passwort ist falsch.",
|
|
110
|
+
"username": "Benutzername oder Passwort ist falsch.",
|
|
111
|
+
"customerNumber": "Kundennummer oder Passwort ist falsch. Mit der Kundennummer melden Sie sich als Hauptansprechpartner Ihres Unternehmens an — mit dessen Passwort."
|
|
112
|
+
}
|
|
107
113
|
},
|
|
108
114
|
"heroTitle": "Kundenportal + Shop + Digitale Services =",
|
|
109
115
|
"heroHighlight": "Ein Konto.",
|
|
@@ -131,7 +137,40 @@
|
|
|
131
137
|
"existingCustomer": "Ich habe bereits ein Konto",
|
|
132
138
|
"newCustomer": "Ich bin Neukunde",
|
|
133
139
|
"newCustomerText": "Registrieren Sie sich für Ihren persönlichen Zugang zu Preisen, Bestellungen und digitalen Services.",
|
|
134
|
-
"registerCta": "Jetzt Kunde werden"
|
|
140
|
+
"registerCta": "Jetzt Kunde werden",
|
|
141
|
+
"identifier": {
|
|
142
|
+
"email": {
|
|
143
|
+
"label": "E-Mail-Adresse",
|
|
144
|
+
"placeholder": "Ihre E-Mail-Adresse"
|
|
145
|
+
},
|
|
146
|
+
"username": {
|
|
147
|
+
"label": "Benutzername",
|
|
148
|
+
"placeholder": "Ihr Benutzername"
|
|
149
|
+
},
|
|
150
|
+
"customerNumber": {
|
|
151
|
+
"label": "Kundennummer",
|
|
152
|
+
"placeholder": "Ihre Kundennummer"
|
|
153
|
+
},
|
|
154
|
+
"email_username": {
|
|
155
|
+
"label": "E-Mail oder Benutzername",
|
|
156
|
+
"placeholder": "E-Mail-Adresse oder Benutzername"
|
|
157
|
+
},
|
|
158
|
+
"email_customerNumber": {
|
|
159
|
+
"label": "E-Mail oder Kundennummer",
|
|
160
|
+
"placeholder": "E-Mail-Adresse oder Kundennummer"
|
|
161
|
+
},
|
|
162
|
+
"username_customerNumber": {
|
|
163
|
+
"label": "Benutzername oder Kundennummer",
|
|
164
|
+
"placeholder": "Benutzername oder Kundennummer"
|
|
165
|
+
},
|
|
166
|
+
"email_username_customerNumber": {
|
|
167
|
+
"label": "E-Mail, Benutzername oder Kundennummer",
|
|
168
|
+
"placeholder": "E-Mail-Adresse, Benutzername oder Kundennummer"
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"identifierHelp": {
|
|
172
|
+
"customerNumber": "Mit der Kundennummer melden Sie sich als Hauptansprechpartner Ihres Unternehmens an."
|
|
173
|
+
}
|
|
135
174
|
},
|
|
136
175
|
"currentPassword": {
|
|
137
176
|
"fields": {
|
|
@@ -203,7 +203,8 @@
|
|
|
203
203
|
"title": "Nur der aktive Warenkorb",
|
|
204
204
|
"description": "Legen Sie weitere Warenkörbe über „Neuer Warenkorb“ an — z. B. je Projekt oder Kostenstelle."
|
|
205
205
|
},
|
|
206
|
-
"disabled": "Mehrere Warenkörbe sind für Ihre Organisation nicht aktiviert."
|
|
206
|
+
"disabled": "Mehrere Warenkörbe sind für Ihre Organisation nicht aktiviert.",
|
|
207
|
+
"punchout": "Bei einem Punchout-Besuch arbeiten Sie in dem einen Warenkorb, den Ihr Beschaffungssystem erhält."
|
|
207
208
|
}
|
|
208
209
|
},
|
|
209
210
|
"boost": {
|
|
@@ -103,7 +103,13 @@
|
|
|
103
103
|
"rateLimited": "Too many attempts. Please try again in a few minutes.",
|
|
104
104
|
"network": "Could not reach the server. Check your connection and try again.",
|
|
105
105
|
"sessionExists": "You are already logged in.",
|
|
106
|
-
"unknown": "Something went wrong. Please try again."
|
|
106
|
+
"unknown": "Something went wrong. Please try again.",
|
|
107
|
+
"identifierNotOffered": "This shop does not accept that to sign in. Please sign in with: {accepted}.",
|
|
108
|
+
"invalidCredentialsBy": {
|
|
109
|
+
"email": "Email or password is incorrect.",
|
|
110
|
+
"username": "Username or password is incorrect.",
|
|
111
|
+
"customerNumber": "Customer number or password is incorrect. A customer number signs in as your company's primary contact — with that contact's password."
|
|
112
|
+
}
|
|
107
113
|
},
|
|
108
114
|
"heroTitle": "Customer portal + shop + digital services =",
|
|
109
115
|
"heroHighlight": "One account.",
|
|
@@ -131,7 +137,40 @@
|
|
|
131
137
|
"existingCustomer": "I already have an account",
|
|
132
138
|
"newCustomer": "I am a new customer",
|
|
133
139
|
"newCustomerText": "Register for personal access to prices, orders and digital services.",
|
|
134
|
-
"registerCta": "Become a customer"
|
|
140
|
+
"registerCta": "Become a customer",
|
|
141
|
+
"identifier": {
|
|
142
|
+
"email": {
|
|
143
|
+
"label": "Email address",
|
|
144
|
+
"placeholder": "Your email address"
|
|
145
|
+
},
|
|
146
|
+
"username": {
|
|
147
|
+
"label": "Username",
|
|
148
|
+
"placeholder": "Your username"
|
|
149
|
+
},
|
|
150
|
+
"customerNumber": {
|
|
151
|
+
"label": "Customer number",
|
|
152
|
+
"placeholder": "Your customer number"
|
|
153
|
+
},
|
|
154
|
+
"email_username": {
|
|
155
|
+
"label": "Email or username",
|
|
156
|
+
"placeholder": "Email address or username"
|
|
157
|
+
},
|
|
158
|
+
"email_customerNumber": {
|
|
159
|
+
"label": "Email or customer number",
|
|
160
|
+
"placeholder": "Email address or customer number"
|
|
161
|
+
},
|
|
162
|
+
"username_customerNumber": {
|
|
163
|
+
"label": "Username or customer number",
|
|
164
|
+
"placeholder": "Username or customer number"
|
|
165
|
+
},
|
|
166
|
+
"email_username_customerNumber": {
|
|
167
|
+
"label": "Email, username or customer number",
|
|
168
|
+
"placeholder": "Email address, username or customer number"
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"identifierHelp": {
|
|
172
|
+
"customerNumber": "A customer number signs you in as your company's primary contact."
|
|
173
|
+
}
|
|
135
174
|
},
|
|
136
175
|
"currentPassword": {
|
|
137
176
|
"fields": {
|
|
@@ -203,7 +203,8 @@
|
|
|
203
203
|
"title": "Only the active cart",
|
|
204
204
|
"description": "Create more carts via “New cart” — e.g. per project or cost center."
|
|
205
205
|
},
|
|
206
|
-
"disabled": "Multiple carts are not enabled for your organization."
|
|
206
|
+
"disabled": "Multiple carts are not enabled for your organization.",
|
|
207
|
+
"punchout": "On a punchout visit you work in the one cart your procurement system receives."
|
|
207
208
|
}
|
|
208
209
|
},
|
|
209
210
|
"boost": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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",
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export default defineEventHandler(async (event) => {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// `identifier` is what the sign-in form sends: an address, a username or a
|
|
3
|
+
// customer number (RAD-151). `email` stays accepted under its own name for
|
|
4
|
+
// callers written before — the testkit and any theme posting here directly.
|
|
5
|
+
const body = await readBody<{
|
|
6
|
+
identifier?: string; email?: string; password?: string;
|
|
4
7
|
}>(event);
|
|
8
|
+
const identifier = String(body?.identifier ?? body?.email ?? "").trim();
|
|
9
|
+
const password = String(body?.password ?? "");
|
|
10
|
+
if (!identifier || !password) {
|
|
11
|
+
throw createError({ statusCode: 400, data: { type: "user_invalid_credentials" } });
|
|
12
|
+
}
|
|
5
13
|
|
|
6
14
|
try {
|
|
7
|
-
const result = await getAuthService(event).login(event,
|
|
15
|
+
const result = await getAuthService(event).login(event, identifier, password);
|
|
8
16
|
|
|
9
17
|
// Live carts: hand the guest's session carts to the contact — merge
|
|
10
18
|
// into the customer's current cart or adopt them. Best-effort: a cart
|
|
@@ -28,6 +36,11 @@ export default defineEventHandler(async (event) => {
|
|
|
28
36
|
if (refused) {
|
|
29
37
|
throw createError({ statusCode: 403, data: { type: refused } });
|
|
30
38
|
}
|
|
39
|
+
// A kind of identifier this shop does not take (customers >= 1.1.2) —
|
|
40
|
+
// shop configuration, not a secret, so the form can say which to use.
|
|
41
|
+
if (apiErrorCode(err) === "identifier_not_offered") {
|
|
42
|
+
throw createError({ statusCode: 403, data: { type: "identifier_not_offered" } });
|
|
43
|
+
}
|
|
31
44
|
if (isApiUserError(err)) {
|
|
32
45
|
throw createError({ statusCode: err.code, data: { type: apiAuthErrorType(err) } });
|
|
33
46
|
}
|
|
@@ -7,12 +7,19 @@ export default defineEventHandler(async (event) => {
|
|
|
7
7
|
if (!id) {
|
|
8
8
|
throw createError({ statusCode: 400, message: "Cart id is required" });
|
|
9
9
|
}
|
|
10
|
+
// On a punchout visit, switching away from its cart is refused as such (409),
|
|
11
|
+
// before the ownership check would call that other cart "not found".
|
|
12
|
+
assertPunchoutCartKept(event, id, "activate");
|
|
10
13
|
await assertOwnCart(event, manager, id);
|
|
11
14
|
try {
|
|
12
15
|
const items = await manager.activateCart(event, id);
|
|
13
16
|
return { items };
|
|
14
17
|
}
|
|
15
18
|
catch (err) {
|
|
19
|
+
// A punchout visit refuses to switch away from its own cart.
|
|
20
|
+
if (isError(err)) {
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
16
23
|
getLogService().error("Service error: carts/activate", toErrorContext(err));
|
|
17
24
|
throw createError({ statusCode: 500, message: "Internal server error" });
|
|
18
25
|
}
|
|
@@ -7,6 +7,8 @@ export default defineEventHandler(async (event) => {
|
|
|
7
7
|
if (!id) {
|
|
8
8
|
throw createError({ statusCode: 400, message: "Cart id is required" });
|
|
9
9
|
}
|
|
10
|
+
// A punchout visit's own cart is the one its hand-back sends.
|
|
11
|
+
assertPunchoutCartKept(event, id, "delete");
|
|
10
12
|
await assertOwnCart(event, manager, id);
|
|
11
13
|
try {
|
|
12
14
|
await manager.deleteCart(event, id);
|
|
@@ -8,6 +8,10 @@ export default defineEventHandler(async (event) => {
|
|
|
8
8
|
return await manager.createCart(event, name ?? "", Boolean(activate));
|
|
9
9
|
}
|
|
10
10
|
catch (err) {
|
|
11
|
+
// A punchout visit refuses a second cart.
|
|
12
|
+
if (isError(err)) {
|
|
13
|
+
throw err;
|
|
14
|
+
}
|
|
11
15
|
getLogService().error("Service error: carts/create", toErrorContext(err));
|
|
12
16
|
throw createError({ statusCode: 500, message: "Internal server error" });
|
|
13
17
|
}
|
|
@@ -6,6 +6,10 @@ export interface AuthPersona {
|
|
|
6
6
|
readonly id: string;
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly email: string;
|
|
9
|
+
/** Demo only: lets the persona sign in by username where the shop takes one. */
|
|
10
|
+
readonly username?: string;
|
|
11
|
+
/** Demo only: the persona's company customer number, likewise. */
|
|
12
|
+
readonly customerNumber?: string;
|
|
9
13
|
readonly role: AuthRole;
|
|
10
14
|
readonly description: string;
|
|
11
15
|
}
|
|
@@ -26,7 +30,12 @@ export interface AuthLoginResult {
|
|
|
26
30
|
* auth flow (store, guards, middleware) is identical.
|
|
27
31
|
*/
|
|
28
32
|
export interface IAuthService {
|
|
29
|
-
|
|
33
|
+
/**
|
|
34
|
+
* `identifier` is an address, a username or a customer number — whichever
|
|
35
|
+
* the shop accepts (customers.login_identifier_*). A kind it does not
|
|
36
|
+
* accept is refused with `identifier_not_offered`.
|
|
37
|
+
*/
|
|
38
|
+
login(event: H3Event, identifier: string, password: string): Promise<AuthLoginResult>;
|
|
30
39
|
me(event: H3Event): Promise<AuthUser | null>;
|
|
31
40
|
logout(event: H3Event): Promise<void>;
|
|
32
41
|
}
|
|
@@ -127,19 +127,10 @@ export default defineEventHandler(async (event) => {
|
|
|
127
127
|
};
|
|
128
128
|
setPunchoutVisit(event, visit);
|
|
129
129
|
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
await getCartManager(event)?.activateCart(event, visit.cartId);
|
|
136
|
-
}
|
|
137
|
-
catch (err) {
|
|
138
|
-
// The cart exists and the visit names it; failing to make it the
|
|
139
|
-
// active one is worth a line in the log, not a refused visit.
|
|
140
|
-
getLogService().error("Punchout cart activation failed", toErrorContext(err));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
130
|
+
// There is deliberately no "make the visit's cart the current one" here:
|
|
131
|
+
// the cart service addresses `visit.cartId` directly for the whole visit.
|
|
132
|
+
// Activating it would flip the contact's `is_current` — which every other
|
|
133
|
+
// visit and the contact's ordinary sessions resolve "the" cart by (RAD-109).
|
|
143
134
|
|
|
144
135
|
// The locale prefix is applied last, because the decision above is about
|
|
145
136
|
// WHERE the buyer goes and this is about how this storefront spells it.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
3
|
import type { AuthRole, AuthUser, StoredSession } from "../../app/interfaces/auth";
|
|
4
|
+
import { loginIdentifierKind } from "../../app/interfaces/shopSettings";
|
|
4
5
|
import type { AuthLoginResult, IAuthService } from "../interfaces/auth";
|
|
5
6
|
import type { CustomersPermissionAnswer } from "../utils/buyerIdentity";
|
|
6
7
|
import { forgetVerifiedBuyer, grantsFrom, rememberVerifiedBuyer } from "../utils/buyerIdentity";
|
|
@@ -71,6 +72,13 @@ function toAuthRole(role?: string | null): AuthRole | undefined {
|
|
|
71
72
|
return role && KNOWN_ROLES.has(role as AuthRole) ? (role as AuthRole) : undefined;
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
/** What the customers app's login takes, for every version that serves it. */
|
|
76
|
+
export function loginBody(identifier: string, password: string): Record<string, string> {
|
|
77
|
+
return loginIdentifierKind(identifier) === "email"
|
|
78
|
+
? { identifier, email: identifier, password }
|
|
79
|
+
: { identifier, password };
|
|
80
|
+
}
|
|
81
|
+
|
|
74
82
|
function contactName(contact: ApiContact | null, fallback: string): string {
|
|
75
83
|
const name = [contact?.first_name, contact?.last_name].filter(Boolean).join(" ").trim();
|
|
76
84
|
return name || fallback;
|
|
@@ -78,7 +86,7 @@ function contactName(contact: ApiContact | null, fallback: string): string {
|
|
|
78
86
|
|
|
79
87
|
/**
|
|
80
88
|
* Live authentication via the public revenexx API (customers app):
|
|
81
|
-
*
|
|
89
|
+
* auth/login (raw call) → platform session (incl. secret) + contact
|
|
82
90
|
* auth/me (raw call) → platform user + contact
|
|
83
91
|
* customersAuthLogout → revokes the platform session
|
|
84
92
|
*
|
|
@@ -87,12 +95,18 @@ function contactName(contact: ApiContact | null, fallback: string): string {
|
|
|
87
95
|
* session secret stays server-side only — the BFF never forwards it.
|
|
88
96
|
*/
|
|
89
97
|
export class ApiAuthService implements IAuthService {
|
|
90
|
-
async login(event: H3Event,
|
|
91
|
-
|
|
98
|
+
async login(event: H3Event, identifier: string, password: string): Promise<AuthLoginResult> {
|
|
99
|
+
// Raw call: the generated customersAuthLogin() of @revenexx/sdk 0.2.0
|
|
100
|
+
// only knows `email` and refuses to send without it. customers 1.1.2
|
|
101
|
+
// declares `identifier` and keeps `email` as an alias, so `identifier`
|
|
102
|
+
// always goes — and `email` beside it only when the value IS an address,
|
|
103
|
+
// which is all a customers app older than the identifier can sign in
|
|
104
|
+
// with. A username or customer number is never passed off as an address.
|
|
105
|
+
const { session, contact, permissions } = await useRevenexxSdk().call<{
|
|
92
106
|
session: ApiSession;
|
|
93
107
|
contact: ApiContact | null;
|
|
94
108
|
permissions?: CustomersPermissionAnswer | null;
|
|
95
|
-
};
|
|
109
|
+
}>("POST", "/v1/customers/auth/login", { body: loginBody(identifier, password) });
|
|
96
110
|
|
|
97
111
|
// The cookie points at the platform session and nothing else: the
|
|
98
112
|
// contact and organization are re-resolved per request (RAD-155).
|
|
@@ -106,8 +120,10 @@ export class ApiAuthService implements IAuthService {
|
|
|
106
120
|
return {
|
|
107
121
|
user: {
|
|
108
122
|
$id: session.userId,
|
|
109
|
-
name: contactName(contact,
|
|
110
|
-
|
|
123
|
+
name: contactName(contact, identifier),
|
|
124
|
+
// Never the identifier itself unless it is an address: a username
|
|
125
|
+
// or customer number in the email slot would be mailed to.
|
|
126
|
+
email: contact?.email ?? (loginIdentifierKind(identifier) === "email" ? identifier : ""),
|
|
111
127
|
role: toAuthRole(contact?.role),
|
|
112
128
|
...(contact?.id ? { contactId: contact.id } : {}),
|
|
113
129
|
...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
|
|
@@ -52,6 +52,22 @@ function resolveOwner(event: H3Event): CartOwner {
|
|
|
52
52
|
return { contactId, sessionKey: getOrCreateCartSessionId(event) };
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The cart a punchout visit works in, or null outside one.
|
|
57
|
+
*
|
|
58
|
+
* `is_current` is one cart per contact, and several ERP users on one punchout
|
|
59
|
+
* account can resolve to the same contact — so a visit that went through "the"
|
|
60
|
+
* current cart would share it with every other visit of that contact, and hand
|
|
61
|
+
* back only its own (stale) cart. A visit therefore addresses the cart its
|
|
62
|
+
* claim named and never touches `is_current`, which also leaves an ordinary
|
|
63
|
+
* session of that contact exactly as it was (RAD-109). A handed-back visit is
|
|
64
|
+
* over: the buyer is signed out, and whatever they do next is not the visit's.
|
|
65
|
+
*/
|
|
66
|
+
function visitCartId(event: H3Event): string | null {
|
|
67
|
+
const visit = readPunchoutVisit(event);
|
|
68
|
+
return visit && !visit.handedBack ? visit.cartId : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
55
71
|
/** Storefront CartItem → carts-app line. The snapshot is the loose product copy. */
|
|
56
72
|
function toApiLine(item: CartItem, position: number): Record<string, unknown> {
|
|
57
73
|
return {
|
|
@@ -159,24 +175,32 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
159
175
|
}) as unknown as ApiCart;
|
|
160
176
|
}
|
|
161
177
|
|
|
178
|
+
private async listItems(cartId: string): Promise<CartItem[]> {
|
|
179
|
+
const { items } = await useRevenexxSdk().cartsItems.cartsItemsList({ cartId }) as unknown as { items: ApiCartLine[] };
|
|
180
|
+
return items.map(toCartItem);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The request's active cart id: the visit's cart, else the owner's current one. */
|
|
184
|
+
private async activeCartId(event: H3Event): Promise<string | null> {
|
|
185
|
+
const visitCart = visitCartId(event);
|
|
186
|
+
if (visitCart) {
|
|
187
|
+
return visitCart;
|
|
188
|
+
}
|
|
189
|
+
const carts = await this.listActive(resolveOwner(event));
|
|
190
|
+
return (carts.find(c => c.is_current) ?? carts[0])?.id ?? null;
|
|
191
|
+
}
|
|
192
|
+
|
|
162
193
|
// ---- ICartService (the active cart) --------------------------------
|
|
163
194
|
|
|
164
195
|
async getItems(event: H3Event): Promise<CartItem[]> {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
const current = carts.find(c => c.is_current) ?? carts[0];
|
|
168
|
-
if (!current) {
|
|
169
|
-
return [];
|
|
170
|
-
}
|
|
171
|
-
const { items } = await useRevenexxSdk().cartsItems.cartsItemsList({ cartId: current.id }) as unknown as { items: ApiCartLine[] };
|
|
172
|
-
return items.map(toCartItem);
|
|
196
|
+
const cartId = await this.activeCartId(event);
|
|
197
|
+
return cartId ? await this.listItems(cartId) : [];
|
|
173
198
|
}
|
|
174
199
|
|
|
175
200
|
async saveItems(event: H3Event, items: CartItem[]): Promise<void> {
|
|
176
|
-
const
|
|
177
|
-
const cart = await this.ensureActiveCart(owner);
|
|
201
|
+
const cartId = visitCartId(event) ?? (await this.ensureActiveCart(resolveOwner(event))).id;
|
|
178
202
|
await useRevenexxSdk().cartsItems.cartsItemsReplace({
|
|
179
|
-
cartId
|
|
203
|
+
cartId,
|
|
180
204
|
items: items.map((item, index) => toApiLine(item, index)) as unknown as Models.CartItemCreateRequest[],
|
|
181
205
|
});
|
|
182
206
|
}
|
|
@@ -188,8 +212,15 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
188
212
|
// ---- ICartManager (multi-cart) --------------------------------------
|
|
189
213
|
|
|
190
214
|
async listCarts(event: H3Event): Promise<{ carts: CartSummaryRow[]; activeCartId: string | null }> {
|
|
191
|
-
|
|
192
|
-
|
|
215
|
+
// A visit's cart is owned by the punchout session, not by the contact,
|
|
216
|
+
// so the contact's list would not even contain it — and the hand-back
|
|
217
|
+
// sends that cart and no other. The visit sees exactly its own cart.
|
|
218
|
+
const visitCart = visitCartId(event);
|
|
219
|
+
if (visitCart) {
|
|
220
|
+
const cart = await useRevenexxSdk().call<ApiCart>("GET", `/v1/carts/${encodeURIComponent(visitCart)}`);
|
|
221
|
+
return { carts: [{ ...toSummary(cart), active: true }], activeCartId: visitCart };
|
|
222
|
+
}
|
|
223
|
+
const carts = await this.listActive(resolveOwner(event));
|
|
193
224
|
const active = carts.find(c => c.is_current) ?? carts[0] ?? null;
|
|
194
225
|
return {
|
|
195
226
|
carts: carts.map(c => ({ ...toSummary(c), active: c.id === active?.id })),
|
|
@@ -198,6 +229,11 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
198
229
|
}
|
|
199
230
|
|
|
200
231
|
async createCart(event: H3Event, name: string, activate: boolean): Promise<CartSummaryRow> {
|
|
232
|
+
if (visitCartId(event)) {
|
|
233
|
+
// A visit works in the one cart its hand-back sends; a second cart
|
|
234
|
+
// would be one the procurement system never receives.
|
|
235
|
+
throw createError({ statusCode: 409, data: { type: "punchout_cart_fixed" } });
|
|
236
|
+
}
|
|
201
237
|
const owner = resolveOwner(event);
|
|
202
238
|
const cart = await useRevenexxSdk().carts.cartsCreate({
|
|
203
239
|
name: name.trim() || DEFAULT_CART_NAME,
|
|
@@ -216,9 +252,17 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
216
252
|
}
|
|
217
253
|
|
|
218
254
|
async activateCart(event: H3Event, id: string): Promise<CartItem[]> {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
255
|
+
const visitCart = visitCartId(event);
|
|
256
|
+
if (visitCart && id !== visitCart) {
|
|
257
|
+
// The hand-back sends the visit's cart and no other, so switching
|
|
258
|
+
// away from it would leave the buyer filling a cart that never
|
|
259
|
+
// reaches their procurement system.
|
|
260
|
+
throw createError({ statusCode: 409, data: { type: "punchout_cart_fixed" } });
|
|
261
|
+
}
|
|
262
|
+
if (!visitCart) {
|
|
263
|
+
await useRevenexxSdk().carts.cartsActivate({ id });
|
|
264
|
+
}
|
|
265
|
+
return await this.listItems(id);
|
|
222
266
|
}
|
|
223
267
|
|
|
224
268
|
async addItemToCart(event: H3Event, id: string, item: CartItem): Promise<void> {
|
|
@@ -239,14 +283,12 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
239
283
|
}
|
|
240
284
|
|
|
241
285
|
async orderActiveCart(event: H3Event, orderRef: string): Promise<string | null> {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
const current = carts.find(c => c.is_current) ?? carts[0];
|
|
245
|
-
if (!current) {
|
|
286
|
+
const cartId = await this.activeCartId(event);
|
|
287
|
+
if (!cartId) {
|
|
246
288
|
return null;
|
|
247
289
|
}
|
|
248
|
-
await useRevenexxSdk().carts.cartsOrder({ id:
|
|
249
|
-
return
|
|
290
|
+
await useRevenexxSdk().carts.cartsOrder({ id: cartId, orderRef });
|
|
291
|
+
return cartId;
|
|
250
292
|
}
|
|
251
293
|
|
|
252
294
|
async claimSession(event: H3Event, contactId: string): Promise<void> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
3
|
import type { AuthUser, StoredSession } from "../../app/interfaces/auth";
|
|
4
|
+
import { loginIdentifierKind, offeredLoginIdentifiers } from "../../app/interfaces/shopSettings";
|
|
4
5
|
import type { AuthLoginResult, AuthPersona, IAuthService } from "../interfaces/auth";
|
|
5
6
|
|
|
6
7
|
const SESSION_TTL_MS = 1000 * 60 * 60 * 12; // 12h demo session
|
|
@@ -51,8 +52,26 @@ export class MockAuthService implements IAuthService {
|
|
|
51
52
|
return { $id: persona.id, name: persona.name, email: persona.email, role: persona.role };
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Signs a persona in by whatever the shop accepts, refusing a kind it does
|
|
57
|
+
* not the way the customers app does — so the demo shows the same answer a
|
|
58
|
+
* live shop gives rather than one only the demo can.
|
|
59
|
+
*/
|
|
60
|
+
async login(event: H3Event, identifier: string): Promise<AuthLoginResult> {
|
|
61
|
+
const kind = loginIdentifierKind(identifier);
|
|
62
|
+
const identifiers = await getShopSettings(event).then(s => s.signIn.identifiers, () => null);
|
|
63
|
+
if (!offeredLoginIdentifiers(identifiers).includes(kind)) {
|
|
64
|
+
throw createError({ statusCode: 403, data: { type: "identifier_not_offered" } });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const wanted = identifier.trim().toLowerCase();
|
|
68
|
+
const persona = await this.findPersona((p) => {
|
|
69
|
+
switch (kind) {
|
|
70
|
+
case "email": return p.email.toLowerCase() === wanted;
|
|
71
|
+
case "username": return p.username?.toLowerCase() === wanted;
|
|
72
|
+
case "customerNumber": return p.customerNumber === wanted;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
56
75
|
if (!persona) {
|
|
57
76
|
throw createError({ statusCode: 401, data: { type: "user_invalid_credentials" } });
|
|
58
77
|
}
|
|
@@ -2,6 +2,18 @@ import type { H3Event } from "h3";
|
|
|
2
2
|
|
|
3
3
|
import type { ICartManager } from "../interfaces/cart";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The cart an open punchout visit works in, or null outside one.
|
|
7
|
+
*
|
|
8
|
+
* The visit cookie is HTTP-only and written by the shop itself from the
|
|
9
|
+
* punchout app's claim, so the cart it names is the request's own for as long
|
|
10
|
+
* as the visit is open. A handed-back visit is over (RAD-109).
|
|
11
|
+
*/
|
|
12
|
+
function openVisitCartId(event: H3Event): string | null {
|
|
13
|
+
const visit = readPunchoutVisit(event);
|
|
14
|
+
return visit && !visit.handedBack ? visit.cartId : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
/**
|
|
6
18
|
* Refuse a cart the request does not own.
|
|
7
19
|
*
|
|
@@ -11,8 +23,16 @@ import type { ICartManager } from "../interfaces/cart";
|
|
|
11
23
|
* cart (RAD-155). A cart is the request's own when it is among the carts listed
|
|
12
24
|
* for the verified contact, or for the guest session. Anybody else's answers
|
|
13
25
|
* exactly like one that does not exist.
|
|
26
|
+
*
|
|
27
|
+
* On an open punchout visit the visit's cart is owned by the visit's handle
|
|
28
|
+
* (pSid), not by the contact — so it is the request's own by the visit, without
|
|
29
|
+
* asking the contact's list, which would not contain it (RAD-109).
|
|
14
30
|
*/
|
|
15
31
|
export async function assertOwnCart(event: H3Event, manager: ICartManager, id: string): Promise<void> {
|
|
32
|
+
const visitCart = openVisitCartId(event);
|
|
33
|
+
if (visitCart && id === visitCart) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
16
36
|
let ids: string[];
|
|
17
37
|
try {
|
|
18
38
|
ids = (await manager.listCarts(event)).carts.map(cart => cart.id);
|
|
@@ -25,3 +45,23 @@ export async function assertOwnCart(event: H3Event, manager: ICartManager, id: s
|
|
|
25
45
|
throw createError({ statusCode: 404, message: "Cart not found" });
|
|
26
46
|
}
|
|
27
47
|
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Refuse to leave a punchout visit's cart (RAD-109).
|
|
51
|
+
*
|
|
52
|
+
* The hand-back sends the visit's cart and no other, so a visit that switched
|
|
53
|
+
* to another cart would fill one its procurement system never receives, and a
|
|
54
|
+
* visit that deleted its own would have nothing left to hand back. Both answer
|
|
55
|
+
* 409 `punchout_cart_fixed` — a refusal the shop can name, not a "not found"
|
|
56
|
+
* that would read as a broken cart. Outside a visit this does nothing.
|
|
57
|
+
*/
|
|
58
|
+
export function assertPunchoutCartKept(event: H3Event, id: string, action: "activate" | "delete"): void {
|
|
59
|
+
const visitCart = openVisitCartId(event);
|
|
60
|
+
if (!visitCart) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const leaves = action === "activate" ? id !== visitCart : id === visitCart;
|
|
64
|
+
if (leaves) {
|
|
65
|
+
throw createError({ statusCode: 409, data: { type: "punchout_cart_fixed" } });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -115,6 +115,11 @@ export async function getShopSettings(event?: H3Event): Promise<ShopSettings> {
|
|
|
115
115
|
["off", "on_registration", "required_for_login"] as const,
|
|
116
116
|
"off",
|
|
117
117
|
),
|
|
118
|
+
identifiers: {
|
|
119
|
+
email: boolSetting(s.customers, "login_identifier_email", true),
|
|
120
|
+
username: boolSetting(s.customers, "login_identifier_username", false),
|
|
121
|
+
customerNumber: boolSetting(s.customers, "login_identifier_customer_number", false),
|
|
122
|
+
},
|
|
118
123
|
},
|
|
119
124
|
account: {
|
|
120
125
|
singleDefaultAddressPerType: boolSetting(s.customers, "single_default_address_per_type", true),
|