@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
|
@@ -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
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
defineEventHandler,
|
|
4
|
+
getQuery,
|
|
5
|
+
getRequestHeader,
|
|
6
|
+
sendRedirect,
|
|
7
|
+
setResponseHeader,
|
|
8
|
+
setResponseStatus,
|
|
9
|
+
} from "h3";
|
|
3
10
|
|
|
4
11
|
import type { StoredSession } from "../../../app/interfaces/auth";
|
|
5
12
|
import type { PunchoutClaim, PunchoutVisit } from "../../interfaces/punchout";
|
|
@@ -127,25 +134,16 @@ export default defineEventHandler(async (event) => {
|
|
|
127
134
|
};
|
|
128
135
|
setPunchoutVisit(event, visit);
|
|
129
136
|
|
|
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
|
-
}
|
|
137
|
+
// There is deliberately no "make the visit's cart the current one" here:
|
|
138
|
+
// the cart service addresses `visit.cartId` directly for the whole visit.
|
|
139
|
+
// Activating it would flip the contact's `is_current` — which every other
|
|
140
|
+
// visit and the contact's ordinary sessions resolve "the" cart by (RAD-109).
|
|
143
141
|
|
|
144
142
|
// The locale prefix is applied last, because the decision above is about
|
|
145
143
|
// WHERE the buyer goes and this is about how this storefront spells it.
|
|
146
144
|
const punchoutConfig = (useRuntimeConfig(event).punchout ?? {}) as { localeStrategy?: string; defaultLocale?: string };
|
|
147
145
|
const path = punchoutLocalePath(
|
|
148
|
-
await landingPath(claim),
|
|
146
|
+
await landingPath(event, claim),
|
|
149
147
|
resolveLocale(event),
|
|
150
148
|
String(punchoutConfig.localeStrategy ?? "no_prefix"),
|
|
151
149
|
String(punchoutConfig.defaultLocale ?? ""),
|
|
@@ -161,7 +159,7 @@ export default defineEventHandler(async (event) => {
|
|
|
161
159
|
* article needs the catalogue, because an external system names an article
|
|
162
160
|
* NUMBER and the shop's product pages are addressed by id and slug.
|
|
163
161
|
*/
|
|
164
|
-
async function landingPath(claim: PunchoutClaim): Promise<string> {
|
|
162
|
+
async function landingPath(event: H3Event, claim: PunchoutClaim): Promise<string> {
|
|
165
163
|
const target = punchoutLandingTarget(claim.entry_action, claim.entry_intent, claim.cart_id);
|
|
166
164
|
const direct = punchoutLandingPath(target);
|
|
167
165
|
if (direct) {
|
|
@@ -174,6 +172,7 @@ async function landingPath(claim: PunchoutClaim): Promise<string> {
|
|
|
174
172
|
const found = await $fetch<SearchAnswer>("/api/typesense/search", {
|
|
175
173
|
method: "POST",
|
|
176
174
|
body: { q: supplierPartId, page: 1, perPage: 5 },
|
|
175
|
+
headers: searchRequestHeaders(event),
|
|
177
176
|
});
|
|
178
177
|
return punchoutArticlePath(found?.products ?? [], supplierPartId);
|
|
179
178
|
}
|
|
@@ -185,6 +184,35 @@ async function landingPath(claim: PunchoutClaim): Promise<string> {
|
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
|
|
187
|
+
/**
|
|
188
|
+
* What the internal search call needs to see the same shop as this request.
|
|
189
|
+
*
|
|
190
|
+
* An internal `$fetch` starts a fresh request with none of the caller's
|
|
191
|
+
* headers, so the search ran without the brokered tenant context, without
|
|
192
|
+
* the market and service-mode cookies, and in whatever locale it could guess:
|
|
193
|
+
* an article number could resolve in the wrong catalogue or not at all.
|
|
194
|
+
*/
|
|
195
|
+
const FORWARDED_SEARCH_HEADERS = [
|
|
196
|
+
"cookie",
|
|
197
|
+
"accept-language",
|
|
198
|
+
"x-revenexx-tenant",
|
|
199
|
+
"x-revenexx-context",
|
|
200
|
+
"x-revenexx-market",
|
|
201
|
+
"x-revenexx-channel",
|
|
202
|
+
] as const;
|
|
203
|
+
|
|
204
|
+
function searchRequestHeaders(event: H3Event): Record<string, string> {
|
|
205
|
+
const headers: Record<string, string> = {};
|
|
206
|
+
for (const name of FORWARDED_SEARCH_HEADERS) {
|
|
207
|
+
const value = getRequestHeader(event, name);
|
|
208
|
+
if (value) {
|
|
209
|
+
headers[name] = value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
headers["x-locale"] = resolveLocale(event);
|
|
213
|
+
return headers;
|
|
214
|
+
}
|
|
215
|
+
|
|
188
216
|
/** Why a visit could not be opened — one page per cause, in plain words. */
|
|
189
217
|
type RefusalCause = "missing" | "unusable" | "unavailable";
|
|
190
218
|
|
|
@@ -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 } : {}),
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { ShopBrand } from "../../app/interfaces/brand";
|
|
2
2
|
import type { IBrandService } from "../interfaces/brand";
|
|
3
|
+
import type { SearchClientResult } from "../utils/searchClient";
|
|
3
4
|
import type { Locale } from "../utils/locale";
|
|
4
5
|
|
|
5
6
|
const BRAND_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
* would silently cap the grid at 10 brands. Mirrors search.post.ts.
|
|
10
|
-
*/
|
|
11
|
-
const LIVE_MAX_FACET_VALUES = 250;
|
|
8
|
+
/** Logo lookups in flight at once — one search per brand. */
|
|
9
|
+
const LOGO_LOOKUP_CONCURRENCY = 8;
|
|
12
10
|
|
|
13
11
|
// Partitioned by tenant — a multi-tenant theme must never serve one tenant's
|
|
14
12
|
// brands to another (see revenexxTenantKey()). Locale and limit are part of the
|
|
@@ -16,18 +14,16 @@ const LIVE_MAX_FACET_VALUES = 250;
|
|
|
16
14
|
const cache = new Map<string, { brands: ShopBrand[]; loadedAt: number }>();
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
|
-
* Live brands from the platform's Typesense product index
|
|
17
|
+
* Live brands from the platform's Typesense product index, through the
|
|
18
|
+
* search service's `brand` view (searchClient.ts):
|
|
19
|
+
* 1. the view's `manufacturer` facet over the whole catalogue → names +
|
|
20
|
+
* article counts, already ranked by count descending.
|
|
21
|
+
* 2. one 1-hit search per top brand → the logo, which lives on the product
|
|
22
|
+
* document (`attrs.<logoAttribute>`), not on any brand entity.
|
|
20
23
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* 2. ONE multi_search with a sub-search per top brand → the logo, which lives
|
|
25
|
-
* on the product document (`attrs.<logoAttribute>`), not on any brand
|
|
26
|
-
* entity. `include_fields` cannot narrow this: asking for `attrs` returns
|
|
27
|
-
* an empty object, so the full document has to come back.
|
|
28
|
-
*
|
|
29
|
-
* Both carry the same pinned filters the storefront's search uses — without
|
|
30
|
-
* them the counts drift from what the search page reports for the same brand.
|
|
24
|
+
* The service pins locale and enabled products on both, the same pins the
|
|
25
|
+
* storefront's search gets — so the counts match what the search page reports
|
|
26
|
+
* for the same brand.
|
|
31
27
|
*/
|
|
32
28
|
export class ApiBrandService implements IBrandService {
|
|
33
29
|
async listBrands(limit: number, locale: Locale): Promise<ShopBrand[]> {
|
|
@@ -48,19 +44,22 @@ export class ApiBrandService implements IBrandService {
|
|
|
48
44
|
// Same attribute the product detail reads its logo from (liveCatalog).
|
|
49
45
|
const attribute = manufacturerLogoAttribute();
|
|
50
46
|
|
|
51
|
-
// One representative product per brand
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
// One representative product per brand. Settled one by one: a brand
|
|
48
|
+
// whose lookup fails costs that brand its logo and nothing more.
|
|
49
|
+
const logoResults: (PromiseSettledResult<SearchClientResult> | undefined)[] = [];
|
|
50
|
+
for (let index = 0; index < top.length; index += LOGO_LOOKUP_CONCURRENCY) {
|
|
51
|
+
const batch = top.slice(index, index + LOGO_LOOKUP_CONCURRENCY);
|
|
52
|
+
logoResults.push(...await Promise.allSettled(batch.map(entry => searchClient.search({
|
|
53
|
+
view: "brand",
|
|
54
|
+
filters: { manufacturer: [entry.value] },
|
|
55
|
+
perPage: 1,
|
|
56
|
+
locale,
|
|
57
|
+
}))));
|
|
58
|
+
}
|
|
61
59
|
|
|
62
60
|
const brands = top.map((entry, index): ShopBrand => {
|
|
63
|
-
const
|
|
61
|
+
const settled = logoResults[index];
|
|
62
|
+
const raw = settled?.status === "fulfilled" ? settled.value.docs[0]?.attrs?.[attribute] : undefined;
|
|
64
63
|
const logo = typeof raw === "string" && raw.trim().length > 0
|
|
65
64
|
? liveImageSrc(raw.trim())
|
|
66
65
|
: null;
|
|
@@ -90,21 +89,8 @@ export class ApiBrandService implements IBrandService {
|
|
|
90
89
|
|
|
91
90
|
/** Round trip 1 of listBrands: names + counts, count-descending. */
|
|
92
91
|
private async facetManufacturers(locale: Locale): Promise<{ value: string; count: number }[]> {
|
|
93
|
-
const
|
|
94
|
-
q: "*",
|
|
95
|
-
queryBy: "name",
|
|
96
|
-
filterBy: this.pinnedFilter(locale),
|
|
97
|
-
facetBy: "manufacturer",
|
|
98
|
-
maxFacetValues: LIVE_MAX_FACET_VALUES,
|
|
99
|
-
perPage: 0,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return (facetResult.facet_counts ?? [])
|
|
103
|
-
.find(facet => facet.field_name === "manufacturer")
|
|
104
|
-
?.counts ?? [];
|
|
105
|
-
}
|
|
92
|
+
const result = await searchClient.search({ view: "brand", locale });
|
|
106
93
|
|
|
107
|
-
|
|
108
|
-
return `locale:=${tsFilterValue(locale)} && enabled:=true`;
|
|
94
|
+
return result.facets.find(facet => facet.field === "manufacturer")?.counts ?? [];
|
|
109
95
|
}
|
|
110
96
|
}
|
|
@@ -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> {
|
|
@@ -11,32 +11,31 @@ const LIST_PAGE_SIZE = 48;
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Live product reads via the public revenexx API: the products app's real
|
|
14
|
-
* Typesense collection, scoped per locale (document id = `{entity_id}:{locale}
|
|
14
|
+
* Typesense collection, scoped per locale (document id = `{entity_id}:{locale}`,
|
|
15
|
+
* the locale a full code like `de-DE` or, before the migration, a bare `de`).
|
|
16
|
+
* Listings go through the search service's `listing` view (searchClient.ts);
|
|
17
|
+
* single products are looked up by document id (getLiveProductDoc).
|
|
15
18
|
* Prices, stocks and images are not in the index yet — the mapping serves
|
|
16
19
|
* neutral defaults (see liveCatalog.ts).
|
|
17
20
|
*/
|
|
18
21
|
export class ApiProductService implements IProductService {
|
|
19
22
|
async listProducts(filter?: ProductListFilter): Promise<Product[]> {
|
|
20
23
|
const locale: Locale = filter?.locale ?? "de";
|
|
21
|
-
const filterParts = [`locale:=${tsFilterValue(locale)}`, "enabled:=true"];
|
|
22
24
|
|
|
23
25
|
// Category facets carry the category CODE — our category slugs.
|
|
24
26
|
// Products are indexed with their LEAF category only, so a branch
|
|
25
27
|
// filters across its whole subtree, however deep the tree runs.
|
|
26
28
|
const branch = filter?.subcategory ?? filter?.category;
|
|
27
|
-
|
|
28
|
-
const codes = await liveCategorySubtreeCodes([branch]);
|
|
29
|
-
filterParts.push(`categories:=[${codes.map(tsFilterValue).join(",")}]`);
|
|
30
|
-
}
|
|
29
|
+
const categories = branch ? await liveCategorySubtreeCodes([branch]) : [];
|
|
31
30
|
|
|
32
|
-
const result = await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
filterBy: filterParts.join(" && "),
|
|
31
|
+
const result = await searchClient.search({
|
|
32
|
+
view: "listing",
|
|
33
|
+
...(categories.length ? { filters: { categories } } : {}),
|
|
36
34
|
perPage: LIST_PAGE_SIZE,
|
|
35
|
+
locale,
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
return
|
|
38
|
+
return result.docs.map(doc => mapLiveDocToProduct(doc));
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
async getProductById(id: string, locale: Locale = "de"): Promise<Product | null> {
|
|
@@ -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
|
}
|
|
@@ -88,6 +88,17 @@ export function buyerPrincipal(event: H3Event | undefined): string {
|
|
|
88
88
|
return typeof value === "string" ? value : "";
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The contact the request acts for, or undefined. A body that names a contact
|
|
93
|
+
* to an app enforcing the principal (payments 1.0) has to name exactly this
|
|
94
|
+
* one, or is refused as `buyer_mismatch` — so it is read from the principal,
|
|
95
|
+
* not from the session cookie.
|
|
96
|
+
*/
|
|
97
|
+
export function principalContactId(event: H3Event | undefined): string | undefined {
|
|
98
|
+
const principal = buyerPrincipal(event);
|
|
99
|
+
return principal.startsWith("contact:") ? principal.slice("contact:".length) || undefined : undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
91
102
|
/**
|
|
92
103
|
* Least → most privileged, as the customers app orders its built-ins. A role
|
|
93
104
|
* the shop does not know ranks below all of them, so it can grant nothing.
|
|
@@ -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
|
+
}
|