@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
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { OrderPaymentStatus, PromotionsRedemptionsReleaseReason } from "@revenexx/sdk";
|
|
2
2
|
import type { Models } from "@revenexx/sdk";
|
|
3
3
|
|
|
4
|
+
import { type EligibleMethodFee, paymentFee } from "../../utils/paymentFee";
|
|
5
|
+
import { orderLinePrices, type PriceResolveAnswer } from "../../utils/orderLinePrices";
|
|
6
|
+
|
|
4
7
|
// Method codes are generic — live mode validates them against the
|
|
5
8
|
// payments app; the demo-only methods keep their extra fields.
|
|
6
9
|
interface OrderPayment {
|
|
@@ -218,7 +221,12 @@ export default defineEventHandler(async (event) => {
|
|
|
218
221
|
if (!rate) {
|
|
219
222
|
throw createError({ status: 422, message: `Delivery method '${body.deliveryMethod}' is not available for this order` });
|
|
220
223
|
}
|
|
221
|
-
|
|
224
|
+
// A null rate is unknown, not untaxed (RAD-175): shipping is not
|
|
225
|
+
// placed at 0 % because the shipping app could not say.
|
|
226
|
+
if (rate.tax_rate == null) {
|
|
227
|
+
throw createError({ status: 422, message: `Delivery method '${body.deliveryMethod}' could not be taxed` });
|
|
228
|
+
}
|
|
229
|
+
liveShippingRate = { price: rate.price, tax_rate: Number(rate.tax_rate) };
|
|
222
230
|
}
|
|
223
231
|
catch (err) {
|
|
224
232
|
if (isError(err)) {
|
|
@@ -229,6 +237,38 @@ export default defineEventHandler(async (event) => {
|
|
|
229
237
|
}
|
|
230
238
|
}
|
|
231
239
|
|
|
240
|
+
// The payment surcharge, and the rate it is taxed at — both the payments
|
|
241
|
+
// app's, the same way the shipping charge above is the shipping app's
|
|
242
|
+
// (RX-781). The BFF resolves it server-side and never takes it from the
|
|
243
|
+
// browser: a fee the shopper could name is a fee the shopper could set.
|
|
244
|
+
//
|
|
245
|
+
// The orders app stores it, taxes it with the rate given and folds both
|
|
246
|
+
// into grand_total. It is handed no finished figure, exactly as with
|
|
247
|
+
// shipping.
|
|
248
|
+
let livePaymentFee: { fee: number; tax_rate: number } | null = null;
|
|
249
|
+
if (livePayments) {
|
|
250
|
+
const address = body.address as Record<string, unknown> | undefined;
|
|
251
|
+
try {
|
|
252
|
+
const { methods } = await useRevenexxSdk().paymentsMethods.paymentsMethodsEligible({
|
|
253
|
+
amount: calculation.totals.find(row => row.key === "subtotal")?.amount
|
|
254
|
+
?? calculation.totals.find(row => row.key === "total")?.amount ?? 0,
|
|
255
|
+
country: String(address?.country ?? ""),
|
|
256
|
+
...(selectedCurrency ? { currency: selectedCurrency } : {}),
|
|
257
|
+
}) as unknown as { methods: EligibleMethodFee[] };
|
|
258
|
+
const placed = paymentFee(methods, payment.method);
|
|
259
|
+
if (placed) {
|
|
260
|
+
livePaymentFee = { fee: placed.fee, tax_rate: placed.taxRate };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
if (isError(err)) {
|
|
265
|
+
throw err;
|
|
266
|
+
}
|
|
267
|
+
getLogService().error("Payment fee resolution failed", apiErrorContext(err));
|
|
268
|
+
throw createError({ status: 502, message: "Payment service unavailable" });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
232
272
|
let orderId = `ORD-${Date.now()}-${Math.random().toString(36).slice(2, 7).toUpperCase()}`;
|
|
233
273
|
|
|
234
274
|
// Live orders: place through the orders app FIRST — the real order
|
|
@@ -262,35 +302,27 @@ export default defineEventHandler(async (event) => {
|
|
|
262
302
|
const contactId = refs.contact_id ?? user?.contactId;
|
|
263
303
|
const organizationId = refs.organization_id ?? user?.organizationId;
|
|
264
304
|
|
|
265
|
-
//
|
|
266
|
-
// the storefront),
|
|
267
|
-
//
|
|
305
|
+
// Every line's price and tax rate from the prices app (same resolve
|
|
306
|
+
// that prices the storefront), one bulk call. Nothing the browser
|
|
307
|
+
// sent is a price here (RAD-175): a line prices cannot price, or a
|
|
308
|
+
// rate it cannot establish, refuses the order. The orders app then
|
|
309
|
+
// taxes items + shipping and computes grand_total itself.
|
|
268
310
|
const orderItems = body.items as Array<Record<string, unknown>>;
|
|
269
|
-
|
|
270
|
-
const itemPrice = new Map<string, number>();
|
|
311
|
+
let answer: PriceResolveAnswer;
|
|
271
312
|
try {
|
|
272
|
-
|
|
313
|
+
answer = await useRevenexxSdk().prices.pricesResolve({
|
|
273
314
|
items: orderItems.map(it => ({ product_id: String(it.id), sku: it.sku ? String(it.sku) : undefined, quantity: Number(it.quantity) || 1 })) as Models.PriceResolveItem[],
|
|
274
|
-
|
|
275
|
-
|
|
315
|
+
// Never a buyer id that could contradict the principal, which
|
|
316
|
+
// prices 1.0 refuses as buyer_mismatch (RAD-170).
|
|
317
|
+
...priceBuyerContext(event),
|
|
276
318
|
...(selectedCurrency ? { currency: selectedCurrency } : {}),
|
|
277
|
-
}) as unknown as
|
|
278
|
-
for (const p of resolved) {
|
|
279
|
-
if (p.tax_rate != null) {
|
|
280
|
-
if (p.product_id) itemRate.set(p.product_id, p.tax_rate);
|
|
281
|
-
if (p.sku) itemRate.set(p.sku, p.tax_rate);
|
|
282
|
-
}
|
|
283
|
-
// Re-price in the resolved currency (the orders app is the SoR
|
|
284
|
-
// for totals, but it must be fed prices in the buyer's currency).
|
|
285
|
-
if (!p.on_request && p.unit_price != null) {
|
|
286
|
-
if (p.product_id) itemPrice.set(p.product_id, p.unit_price);
|
|
287
|
-
if (p.sku) itemPrice.set(p.sku, p.unit_price);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
319
|
+
}) as unknown as PriceResolveAnswer;
|
|
290
320
|
}
|
|
291
|
-
catch (
|
|
292
|
-
getLogService().error("Item price/tax resolution failed", apiErrorContext(
|
|
321
|
+
catch (priceErr) {
|
|
322
|
+
getLogService().error("Item price/tax resolution failed", apiErrorContext(priceErr));
|
|
323
|
+
throw createError({ status: 502, message: "Price service unavailable" });
|
|
293
324
|
}
|
|
325
|
+
const linePrices = orderLinePrices(answer, orderItems.length);
|
|
294
326
|
|
|
295
327
|
// What the promotions app decided, evaluated once more against the
|
|
296
328
|
// prices that were just resolved — not the figures the cart was
|
|
@@ -314,8 +346,8 @@ export default defineEventHandler(async (event) => {
|
|
|
314
346
|
product_id: String(it.id),
|
|
315
347
|
name: String(it.name ?? it.sku ?? it.id),
|
|
316
348
|
quantity: calculation.lines[index]?.adjustedQuantity ?? Number(it.quantity),
|
|
317
|
-
unit_price:
|
|
318
|
-
tax_rate:
|
|
349
|
+
unit_price: linePrices[index]!.unitPrice,
|
|
350
|
+
tax_rate: linePrices[index]!.taxRate,
|
|
319
351
|
})),
|
|
320
352
|
});
|
|
321
353
|
let discounts = (promo?.applied ?? []).map(a => ({
|
|
@@ -382,7 +414,12 @@ export default defineEventHandler(async (event) => {
|
|
|
382
414
|
buyer: user ? { name: user.name, email: user.email } : { email: body.contactEmail ?? null },
|
|
383
415
|
billingAddress: (billing ?? null) as object,
|
|
384
416
|
shippingAddress: (address ?? null) as object,
|
|
385
|
-
payment: {
|
|
417
|
+
payment: {
|
|
418
|
+
method: payment.method,
|
|
419
|
+
// Only when there is one: a method that charges nothing
|
|
420
|
+
// sends no fee, rather than a zero that reads as "resolved".
|
|
421
|
+
...(livePaymentFee ? { fee: livePaymentFee.fee, fee_tax_rate: livePaymentFee.tax_rate } : {}),
|
|
422
|
+
},
|
|
386
423
|
// Shipping price + tax_rate from the shipping app; the orders
|
|
387
424
|
// app taxes it and computes grand_total — the BFF sends NO
|
|
388
425
|
// grand_total (orders is the single source of truth).
|
|
@@ -396,8 +433,8 @@ export default defineEventHandler(async (event) => {
|
|
|
396
433
|
sku: String(item.sku ?? "") || undefined,
|
|
397
434
|
name: String(item.name ?? item.sku ?? item.id),
|
|
398
435
|
quantity: calculation.lines[index]?.adjustedQuantity ?? Number(item.quantity),
|
|
399
|
-
unit_price:
|
|
400
|
-
tax_rate:
|
|
436
|
+
unit_price: linePrices[index]!.unitPrice,
|
|
437
|
+
tax_rate: linePrices[index]!.taxRate,
|
|
401
438
|
// Whether this position can be ordered at all. The orders app
|
|
402
439
|
// holds the merchant's policy for one that cannot — order it,
|
|
403
440
|
// leave it out, or refuse the lot — and cannot see stock
|
|
@@ -497,6 +534,11 @@ export default defineEventHandler(async (event) => {
|
|
|
497
534
|
if (reserved === "held" && cartId) {
|
|
498
535
|
await releaseRedemption(event, { cartId, reason: PromotionsRedemptionsReleaseReason.CartReleased });
|
|
499
536
|
}
|
|
537
|
+
// Refused here on purpose (an unpriced line, an unknown rate, the
|
|
538
|
+
// price service down): that answer goes to the buyer as it is.
|
|
539
|
+
if (isError(err)) {
|
|
540
|
+
throw err;
|
|
541
|
+
}
|
|
500
542
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
501
543
|
throw createError({ status: 422, message: err.message });
|
|
502
544
|
}
|
|
@@ -536,6 +578,7 @@ export default defineEventHandler(async (event) => {
|
|
|
536
578
|
// is forwarded as-is; paymentsCreate's typed params drop unknown
|
|
537
579
|
// fields, so the create goes through the low-level transport.
|
|
538
580
|
const instrument = body.paymentInstrument as { token?: string } | undefined;
|
|
581
|
+
const payerContactId = principalContactId(event);
|
|
539
582
|
try {
|
|
540
583
|
const created = await useRevenexxSdk().call<{ id: string; status: string; error_message?: string | null; next_action?: { type?: string; url?: string } | null }>(
|
|
541
584
|
"POST",
|
|
@@ -548,6 +591,10 @@ export default defineEventHandler(async (event) => {
|
|
|
548
591
|
currency: selectedCurrency ?? calculation.currency,
|
|
549
592
|
country,
|
|
550
593
|
order_ref: orderId,
|
|
594
|
+
// Whose payment this is: the account's payments page lists by
|
|
595
|
+
// it (RAD-171). The principal's contact, which payments holds
|
|
596
|
+
// the body to — a guest pays as nobody.
|
|
597
|
+
...(payerContactId ? { contact_id: payerContactId } : {}),
|
|
551
598
|
idempotency_key: body.checkoutSessionToken,
|
|
552
599
|
...(instrument?.token ? { token: instrument.token } : {}),
|
|
553
600
|
...(body.returnUrl ? { return_url: body.returnUrl } : {}),
|
|
@@ -571,7 +618,7 @@ export default defineEventHandler(async (event) => {
|
|
|
571
618
|
// A placed live order must not survive a failed payment.
|
|
572
619
|
if (liveOrderUuid) {
|
|
573
620
|
try {
|
|
574
|
-
await
|
|
621
|
+
await useTenantSdk().orders.ordersCancel({ id: liveOrderUuid, reason: "payment failed" });
|
|
575
622
|
}
|
|
576
623
|
catch (cancelErr) {
|
|
577
624
|
getLogService().error("Order cancel after payment failure failed", apiErrorContext(cancelErr));
|
|
@@ -597,7 +644,7 @@ export default defineEventHandler(async (event) => {
|
|
|
597
644
|
? OrderPaymentStatus.Paid
|
|
598
645
|
: livePaymentStatus === "authorized" ? OrderPaymentStatus.Authorized : OrderPaymentStatus.Pending;
|
|
599
646
|
try {
|
|
600
|
-
await
|
|
647
|
+
await useTenantSdk().orders.ordersPaymentStatusUpdate({ id: liveOrderUuid, status: mapped });
|
|
601
648
|
}
|
|
602
649
|
catch (err) {
|
|
603
650
|
getLogService().error("Order payment-status sync failed", apiErrorContext(err));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { pspPublicConfig, type PspProviderRow, type PspPublicConfig } from "../../utils/pspConfig";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Public PSP config for the checkout's client-side tokenizers — ONLY the
|
|
3
5
|
* publishable/public keys of enabled PSP providers, never the secret keys.
|
|
@@ -5,36 +7,24 @@
|
|
|
5
7
|
* which provider needs client-side tokenization and with which public key.
|
|
6
8
|
*
|
|
7
9
|
* Shape: { providers: { stripe: { publishableKey, testMode }, … } }
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* The key is read from the provider's `options.publishable_key` (see
|
|
11
|
+
* utils/pspConfig.ts); adding Novalnet/Mollie later = they appear here once
|
|
12
|
+
* enabled with one, and the FE registry gets a new entry.
|
|
10
13
|
*/
|
|
11
|
-
interface ApiProviderRow {
|
|
12
|
-
provider: string;
|
|
13
|
-
enabled: boolean;
|
|
14
|
-
test_mode: boolean;
|
|
15
|
-
credentials: Record<string, unknown> | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
export default defineEventHandler(async (event) => {
|
|
19
15
|
if (resolvePaymentServiceKey(event) !== "api") {
|
|
20
|
-
return { providers: {} as
|
|
16
|
+
return { providers: {} as PspPublicConfig };
|
|
21
17
|
}
|
|
22
18
|
try {
|
|
23
|
-
const { items } = await useRevenexxSdk().call<{ items:
|
|
24
|
-
const providers
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const pk = row.credentials?.publishable_key;
|
|
30
|
-
if (typeof pk === "string" && pk.length > 0) {
|
|
31
|
-
providers[row.provider] = { publishableKey: pk, testMode: row.test_mode !== false };
|
|
32
|
-
}
|
|
19
|
+
const { items } = await useRevenexxSdk().call<{ items: PspProviderRow[] }>("GET", "/v1/payments/providers");
|
|
20
|
+
const { providers, refused } = pspPublicConfig(items ?? []);
|
|
21
|
+
if (refused.length) {
|
|
22
|
+
getLogService().error("Secret key configured as publishable_key — not published", { providers: refused });
|
|
33
23
|
}
|
|
34
24
|
return { providers };
|
|
35
25
|
}
|
|
36
26
|
catch (err) {
|
|
37
27
|
getLogService().error("Service error: payment/psp-config", apiErrorContext(err));
|
|
38
|
-
return { providers: {} as
|
|
28
|
+
return { providers: {} as PspPublicConfig };
|
|
39
29
|
}
|
|
40
30
|
});
|
|
@@ -50,8 +50,8 @@ export default defineEventHandler(async (event): Promise<QuoteRequestResult> =>
|
|
|
50
50
|
try {
|
|
51
51
|
const { prices } = await useRevenexxSdk().prices.pricesResolve({
|
|
52
52
|
items: body.items.map(it => ({ product_id: String(it.id), sku: it.sku || undefined, quantity: Number(it.quantity) || 1 })) as Models.PriceResolveItem[],
|
|
53
|
-
|
|
54
|
-
...(
|
|
53
|
+
// The principal decides whose prices these are (RAD-170).
|
|
54
|
+
...priceBuyerContext(event),
|
|
55
55
|
currency,
|
|
56
56
|
}) as unknown as { prices: Array<{ product_id: string | null; sku: string | null; tax_rate: number | null; on_request: boolean; unit_price: number | null }> };
|
|
57
57
|
for (const p of prices) {
|