@revenexx/cover 0.11.0 → 0.13.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/recommend/CartCrossSell.vue +2 -1
- package/app/components/cart/switcher/CartSwitcher.vue +5 -2
- package/app/components/listing/ListingFilterBar.vue +1 -0
- package/app/components/listing/ListingFilterDrawer.vue +1 -0
- package/app/components/listing/ListingFilterRail.vue +1 -0
- package/app/components/search/filter/SearchFacets.vue +10 -3
- package/app/components/search/filter/SearchFacetsBar.vue +7 -3
- package/app/components/search/filter/SearchFacetsDrawer.vue +7 -2
- package/app/components/ui/forms/SearchInput.vue +4 -1
- package/app/composables/useAuthStore.ts +4 -2
- package/app/composables/useFacetMeta.ts +6 -6
- package/app/composables/useProductListing.ts +18 -2
- package/app/composables/useSearchListing.ts +16 -0
- package/app/interfaces/auth.ts +12 -2
- package/app/interfaces/shopSettings.ts +84 -0
- package/app/shared/locale.ts +114 -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/nuxt.config.ts +22 -0
- package/package.json +1 -1
- package/server/api/account/quotes/[id]/order.post.ts +14 -3
- package/server/api/auth/login.post.ts +16 -3
- package/server/api/cart/calculate.post.ts +4 -0
- 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/api/categories/[slug]/subcategories.get.ts +34 -31
- package/server/api/orders/index.post.ts +78 -31
- package/server/api/payment/psp-config.get.ts +11 -21
- package/server/api/quotes/request.post.ts +2 -2
- package/server/api/typesense/search.post.ts +61 -317
- package/server/api/typesense/suggest.post.ts +14 -9
- package/server/{api/typesense/drop.get.ts → dev/typesense/drop.ts} +2 -1
- package/server/{api/typesense/health.get.ts → dev/typesense/health.ts} +1 -0
- package/server/dev/typesense/seed.ts +59 -0
- package/server/dev/typesense/seedDocuments.ts +105 -0
- package/server/interfaces/auth.ts +10 -1
- package/server/routes/punchout/start.get.ts +44 -16
- package/server/services/ApiAuthService.ts +22 -6
- package/server/services/ApiBrandService.ts +28 -42
- package/server/services/ApiCartService.ts +64 -22
- package/server/services/ApiProductService.ts +10 -11
- package/server/services/MockAuthService.ts +21 -2
- package/server/utils/buyerIdentity.ts +11 -0
- package/server/utils/cartOwnership.ts +40 -0
- package/server/utils/liveCatalog.ts +132 -49
- package/server/utils/liveListingSearch.ts +201 -0
- package/server/utils/livePrices.ts +24 -9
- package/server/utils/orderLinePrices.ts +72 -0
- package/server/utils/paymentFee.ts +59 -0
- package/server/utils/pspConfig.ts +42 -0
- package/server/utils/revenexxSdk.ts +25 -2
- package/server/utils/searchClient.ts +305 -0
- package/server/utils/searchMultiSearchFallback.ts +216 -0
- package/server/utils/shopSettings.ts +5 -0
- package/server/api/typesense/seed.get.ts +0 -111
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale codes as the catalogue speaks them, next to the language the
|
|
3
|
+
* storefront speaks.
|
|
4
|
+
*
|
|
5
|
+
* The UI works in a bare language (`de`, `en`: the URL prefix, the i18n
|
|
6
|
+
* files). The catalogue does not agree with itself: search documents carry
|
|
7
|
+
* `locale: "de"` today and `locale: "de-DE"` after the full-code migration,
|
|
8
|
+
* and label maps from different PIMs are keyed either way. Everything here
|
|
9
|
+
* accepts both forms in both directions and prefers the full code, so the
|
|
10
|
+
* shop works before, during and after that migration.
|
|
11
|
+
*
|
|
12
|
+
* Pure functions, shared by the BFF (search filters, label picking) and the
|
|
13
|
+
* client (facet labels), so both resolve a label the same way.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The region a bare UI language stands for when a full code is needed. */
|
|
17
|
+
export const DEFAULT_LOCALE_REGIONS: Readonly<Record<string, string>> = {
|
|
18
|
+
de: "DE",
|
|
19
|
+
en: "US",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Languages a label falls back to, in order, after the requested one. */
|
|
23
|
+
export const LABEL_FALLBACK_LANGUAGES = ["de", "en"] as const;
|
|
24
|
+
|
|
25
|
+
/** `de_de` / `DE-de` / ` de-DE ` → `de-DE`; `DE` → `de`. */
|
|
26
|
+
export function normalizeLocaleCode(code: string): string {
|
|
27
|
+
const [language = "", region, ...rest] = code.trim().replace(/_/g, "-").split("-");
|
|
28
|
+
if (!region) {
|
|
29
|
+
return language.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
return [language.toLowerCase(), region.length === 2 ? region.toUpperCase() : region, ...rest].join("-");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The language subtag: `de-DE` → `de`, `de` → `de`. */
|
|
35
|
+
export function localeLanguage(code: string): string {
|
|
36
|
+
return normalizeLocaleCode(code).split("-")[0] ?? "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The full BCP-47 code for a locale: a full code is kept as it is, a bare
|
|
41
|
+
* language gets its default region (`de` → `de-DE`, `en` → `en-US`). A
|
|
42
|
+
* language without a known region stays bare.
|
|
43
|
+
*/
|
|
44
|
+
export function fullLocaleCode(code: string): string {
|
|
45
|
+
const normalized = normalizeLocaleCode(code);
|
|
46
|
+
if (normalized.includes("-")) {
|
|
47
|
+
return normalized;
|
|
48
|
+
}
|
|
49
|
+
const region = DEFAULT_LOCALE_REGIONS[normalized];
|
|
50
|
+
return region ? `${normalized}-${region}` : normalized;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The locale values a catalogue document may carry for this locale, most
|
|
55
|
+
* preferred first: the full code, then the bare language.
|
|
56
|
+
* `de` → `["de-DE", "de"]`, `de-AT` → `["de-AT", "de"]`.
|
|
57
|
+
*/
|
|
58
|
+
export function searchLocaleKeys(code: string): string[] {
|
|
59
|
+
const language = localeLanguage(code);
|
|
60
|
+
if (!language) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const full = fullLocaleCode(code);
|
|
64
|
+
return full === language ? [language] : [full, language];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A label map's value for one locale, whichever form its keys take.
|
|
69
|
+
*
|
|
70
|
+
* Tried in order: the locale's full code, its bare language, then any other
|
|
71
|
+
* region of the same language (in sorted key order, so a map carrying
|
|
72
|
+
* `de-AT` and `de-CH` always answers the same way). Keys are compared
|
|
73
|
+
* normalised (`de_DE`, `DE-de`). An empty string counts as no label: it
|
|
74
|
+
* renders as a blank name, which is worse than the fallback.
|
|
75
|
+
*/
|
|
76
|
+
export function labelForLocale(labels: Record<string, string>, locale: string): string | undefined {
|
|
77
|
+
const present = Object.keys(labels)
|
|
78
|
+
.filter(key => labels[key])
|
|
79
|
+
.sort()
|
|
80
|
+
.map(key => ({ key, code: normalizeLocaleCode(key) }));
|
|
81
|
+
|
|
82
|
+
for (const wanted of searchLocaleKeys(locale)) {
|
|
83
|
+
const hit = present.find(entry => entry.code === wanted);
|
|
84
|
+
if (hit) {
|
|
85
|
+
return labels[hit.key];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const language = localeLanguage(locale);
|
|
90
|
+
const sameLanguage = present.find(entry => entry.code.split("-")[0] === language);
|
|
91
|
+
return sameLanguage ? labels[sameLanguage.key] : undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Localised label with the catalogue's fallback chain: the requested locale,
|
|
96
|
+
* then German, then English, then `fallback` (usually the technical code).
|
|
97
|
+
* Every step matches full and short codes in both directions.
|
|
98
|
+
*/
|
|
99
|
+
export function pickLocalizedLabel(
|
|
100
|
+
labels: Record<string, string> | null | undefined,
|
|
101
|
+
locale: string,
|
|
102
|
+
fallback: string,
|
|
103
|
+
): string {
|
|
104
|
+
if (!labels) {
|
|
105
|
+
return fallback;
|
|
106
|
+
}
|
|
107
|
+
for (const candidate of [locale, ...LABEL_FALLBACK_LANGUAGES]) {
|
|
108
|
+
const label = labelForLocale(labels, candidate);
|
|
109
|
+
if (label) {
|
|
110
|
+
return label;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
|
@@ -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/nuxt.config.ts
CHANGED
|
@@ -176,6 +176,28 @@ export default defineNuxtConfig({
|
|
|
176
176
|
},
|
|
177
177
|
|
|
178
178
|
hooks: {
|
|
179
|
+
/**
|
|
180
|
+
* Local Typesense maintenance (seed/drop/health), dev server only.
|
|
181
|
+
*
|
|
182
|
+
* They act on the local demo index without any auth, so they must not
|
|
183
|
+
* exist in a build: they live outside server/api and are only
|
|
184
|
+
* registered here when Nuxt runs in dev. A production build seeds via
|
|
185
|
+
* `pnpm typesense:seed` (scripts/seed-typesense.mjs) instead.
|
|
186
|
+
*/
|
|
187
|
+
"nitro:config": (nitroConfig) => {
|
|
188
|
+
if (!useNuxt().options.dev) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
nitroConfig.handlers = [
|
|
192
|
+
...(nitroConfig.handlers ?? []),
|
|
193
|
+
...["seed", "drop", "health"].map(name => ({
|
|
194
|
+
route: `/api/typesense/${name}`,
|
|
195
|
+
method: "get" as const,
|
|
196
|
+
handler: resolve(currentDir, `server/dev/typesense/${name}.ts`),
|
|
197
|
+
})),
|
|
198
|
+
];
|
|
199
|
+
},
|
|
200
|
+
|
|
179
201
|
/**
|
|
180
202
|
* Hand the consuming app's i18n routing strategy to the server.
|
|
181
203
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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",
|
|
@@ -96,8 +96,16 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
96
96
|
let placed: { id: string; number: string; grand_total?: number };
|
|
97
97
|
try {
|
|
98
98
|
placed = await sdk.orders.ordersPlace({
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
// A buyer's call is placed for the buyer the principal names, and the
|
|
100
|
+
// orders app refuses a body that names anybody else (RAD-174) — a
|
|
101
|
+
// colleague's quote included, where the draft carries the colleague.
|
|
102
|
+
// Only a call acting for nobody states who the order is for.
|
|
103
|
+
...(principalContactId(event)
|
|
104
|
+
? {}
|
|
105
|
+
: {
|
|
106
|
+
contactId: draft.contact_id ?? actor.contactId,
|
|
107
|
+
organizationId: draft.organization_id ?? actor.organizationId,
|
|
108
|
+
}),
|
|
101
109
|
currency: draft.currency,
|
|
102
110
|
...(body?.customerOrderNumber?.trim() ? { customerOrderNumber: body.customerOrderNumber.trim() } : {}),
|
|
103
111
|
buyer: (draft.buyer ?? { name: actor.user.name, email: actor.user.email }) as object,
|
|
@@ -135,6 +143,7 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
if (resolvePaymentServiceKey(event) === "api") {
|
|
146
|
+
const payerContactId = principalContactId(event);
|
|
138
147
|
try {
|
|
139
148
|
const payment = await sdk.call<{ id: string; status: string }>("POST", "/v1/payments", {
|
|
140
149
|
body: {
|
|
@@ -143,6 +152,8 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
143
152
|
currency: draft.currency,
|
|
144
153
|
country: toIsoCountry(draft.billing_address?.country ?? draft.shipping_address?.country),
|
|
145
154
|
order_ref: placed.number,
|
|
155
|
+
// The buyer's own payment, listed on their payments page (RAD-171).
|
|
156
|
+
...(payerContactId ? { contact_id: payerContactId } : {}),
|
|
146
157
|
idempotency_key: `quote-${quote.id}-${placed.id}`,
|
|
147
158
|
metadata: { quote_number: quote.number },
|
|
148
159
|
},
|
|
@@ -150,7 +161,7 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
150
161
|
const mapped = ["captured", "succeeded", "paid"].includes(payment.status)
|
|
151
162
|
? OrderPaymentStatus.Paid
|
|
152
163
|
: payment.status === "authorized" ? OrderPaymentStatus.Authorized : OrderPaymentStatus.Pending;
|
|
153
|
-
await
|
|
164
|
+
await useTenantSdk().orders.ordersPaymentStatusUpdate({ id: placed.id, status: mapped });
|
|
154
165
|
}
|
|
155
166
|
catch (err) {
|
|
156
167
|
// An invoice order stands without a captured payment; the payment
|
|
@@ -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
|
}
|
|
@@ -37,6 +37,10 @@ async function resolveOverrides(
|
|
|
37
37
|
sku: it.sku ? String(it.sku) : undefined,
|
|
38
38
|
quantity: Number(it.quantity) || 1,
|
|
39
39
|
})) as Models.PriceResolveItem[],
|
|
40
|
+
// The signed-in buyer's own prices — contract and organization
|
|
41
|
+
// lists included — not the anonymous ones (RAD-170). The same
|
|
42
|
+
// scope the order is priced under.
|
|
43
|
+
...priceBuyerContext(event),
|
|
40
44
|
...(currency ? { currency } : {}),
|
|
41
45
|
}) as unknown as { prices: Array<{ product_id: string | null; sku: string | null; tax_rate: number | null; on_request: boolean; unit_price: number | null }> };
|
|
42
46
|
const itemTaxRates: Record<string, number> = {};
|
|
@@ -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
|
}
|
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
liveSubcategoryIndex,
|
|
8
8
|
mapLiveDocToProduct,
|
|
9
9
|
rollUpSubcategoryCounts,
|
|
10
|
-
searchLiveProducts,
|
|
11
|
-
searchLiveProductsMulti,
|
|
12
10
|
tsFilterValue,
|
|
13
11
|
} from "../../../utils/liveCatalog";
|
|
14
12
|
import { PRODUCTS_COLLECTION } from "../../../utils/productsSchema";
|
|
@@ -38,11 +36,15 @@ import { PRODUCTS_COLLECTION } from "../../../utils/productsSchema";
|
|
|
38
36
|
const MAX_SUBCATEGORY_VALUES = 250;
|
|
39
37
|
|
|
40
38
|
/**
|
|
41
|
-
* Sub-searches per multi_search request. Typesense's
|
|
42
|
-
* defaults to 50; staying under it keeps a category with
|
|
39
|
+
* Sub-searches per multi_search request against the mock index. Typesense's
|
|
40
|
+
* `limit_multi_searches` defaults to 50; staying under it keeps a category with
|
|
41
|
+
* many children working.
|
|
43
42
|
*/
|
|
44
43
|
const SEARCH_BATCH_SIZE = 40;
|
|
45
44
|
|
|
45
|
+
/** Live image lookups in flight at once — one search per child. */
|
|
46
|
+
const LIVE_IMAGE_CONCURRENCY = 8;
|
|
47
|
+
|
|
46
48
|
/** Narrowed shape of the mock index's multi_search response. */
|
|
47
49
|
interface MockMultiSearchResponse {
|
|
48
50
|
results?: {
|
|
@@ -78,19 +80,10 @@ function toTiles(
|
|
|
78
80
|
// products are spread over every code beneath it.
|
|
79
81
|
// ---------------------------------------------------------------------------
|
|
80
82
|
|
|
81
|
-
/** `locale:=… && enabled:=true && categories:=[…]`, the live catalogue's baseline. */
|
|
82
|
-
function liveFilter(locale: Locale, codes: readonly string[]): string {
|
|
83
|
-
return [
|
|
84
|
-
`locale:=${tsFilterValue(locale)}`,
|
|
85
|
-
"enabled:=true",
|
|
86
|
-
`categories:=[${codes.map(tsFilterValue).join(",")}]`,
|
|
87
|
-
].join(" && ");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
83
|
/**
|
|
91
|
-
* Product counts per direct child
|
|
92
|
-
*
|
|
93
|
-
*
|
|
84
|
+
* Product counts per direct child, from the search service's `category` view —
|
|
85
|
+
* the view the category page's listing asks, so the cards and the filter rail
|
|
86
|
+
* can never disagree. The service pins locale and enabled products.
|
|
94
87
|
*/
|
|
95
88
|
async function liveCounts(categorySlug: string, locale: Locale): Promise<Map<string, number>> {
|
|
96
89
|
const { branchOf } = await liveSubcategoryIndex(categorySlug, locale);
|
|
@@ -99,27 +92,27 @@ async function liveCounts(categorySlug: string, locale: Locale): Promise<Map<str
|
|
|
99
92
|
return new Map();
|
|
100
93
|
}
|
|
101
94
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
facetBy: "categories",
|
|
106
|
-
maxFacetValues: MAX_SUBCATEGORY_VALUES,
|
|
95
|
+
const result = await searchClient.search({
|
|
96
|
+
view: "category",
|
|
97
|
+
filters: { categories: leafCodes },
|
|
107
98
|
perPage: 1,
|
|
99
|
+
locale,
|
|
108
100
|
});
|
|
109
101
|
|
|
110
102
|
return rollUpSubcategoryCounts(
|
|
111
|
-
|
|
103
|
+
result.facets.find(facet => facet.field === "categories")?.counts ?? [],
|
|
112
104
|
branchOf,
|
|
113
105
|
);
|
|
114
106
|
}
|
|
115
107
|
|
|
116
108
|
/**
|
|
117
109
|
* One representative product image per direct child: a 1-hit search per child,
|
|
118
|
-
*
|
|
110
|
+
* a few at a time.
|
|
119
111
|
*
|
|
120
|
-
* Per child rather than one big page of hits, because a page is capped
|
|
121
|
-
*
|
|
122
|
-
*
|
|
112
|
+
* Per child rather than one big page of hits, because a page is capped and a
|
|
113
|
+
* category with thousands of products would leave most children imageless —
|
|
114
|
+
* which is exactly how this looked when it was broken. A child whose lookup
|
|
115
|
+
* fails keeps its icon; the others keep their images.
|
|
123
116
|
*/
|
|
124
117
|
async function liveImages(categorySlug: string, locale: Locale): Promise<Map<string, string>> {
|
|
125
118
|
const { branchOf } = await liveSubcategoryIndex(categorySlug, locale);
|
|
@@ -136,15 +129,25 @@ async function liveImages(categorySlug: string, locale: Locale): Promise<Map<str
|
|
|
136
129
|
const children = [...leavesByChild.keys()];
|
|
137
130
|
const images = new Map<string, string>();
|
|
138
131
|
|
|
139
|
-
for (const batch of chunk(children,
|
|
140
|
-
const results = await
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
for (const batch of chunk(children, LIVE_IMAGE_CONCURRENCY)) {
|
|
133
|
+
const results = await Promise.allSettled(batch.map(child => searchClient.search({
|
|
134
|
+
view: "category",
|
|
135
|
+
filters: { categories: leavesByChild.get(child) ?? [child] },
|
|
143
136
|
perPage: 1,
|
|
137
|
+
locale,
|
|
144
138
|
})));
|
|
145
139
|
|
|
140
|
+
const failed = results.find((r): r is PromiseRejectedResult => r.status === "rejected");
|
|
141
|
+
if (failed) {
|
|
142
|
+
getLogService().warn(
|
|
143
|
+
"categories/subcategories: some preview image lookups failed",
|
|
144
|
+
{ slug: categorySlug, ...toErrorContext(failed.reason) },
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
146
148
|
batch.forEach((child, index) => {
|
|
147
|
-
const
|
|
149
|
+
const settled = results[index];
|
|
150
|
+
const doc = settled?.status === "fulfilled" ? settled.value.docs[0] : undefined;
|
|
148
151
|
if (doc) {
|
|
149
152
|
images.set(child, mapLiveDocToProduct(doc).image);
|
|
150
153
|
}
|