@revenexx/cover 0.14.0 → 0.16.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/api/account.ts +1 -0
- package/app/components/RevenexxForm.vue +183 -19
- package/app/components/account/address/AccountAddressCard.vue +8 -2
- package/app/components/account/address/AccountAddressView.vue +5 -1
- package/app/components/account/carts/AccountCartsTable.vue +85 -3
- package/app/components/account/dashboard/AccountDashboardBudgets.vue +2 -1
- package/app/components/account/dashboard/AccountDashboardRecentOrders.vue +2 -1
- package/app/components/account/dashboard/AccountDashboardRequisitions.vue +2 -1
- package/app/components/account/directorder/AccountDirectOrder.vue +100 -12
- package/app/components/account/governance/AccountApprovalLimitsTable.vue +124 -8
- package/app/components/account/governance/AccountCostCenterDetail.vue +3 -2
- package/app/components/account/governance/AccountCostCentersTable.vue +133 -6
- package/app/components/account/governance/AccountRequisitionDetail.vue +2 -1
- package/app/components/account/governance/AccountRequisitionsTable.vue +102 -6
- package/app/components/account/governance/AccountWorkflowDetail.vue +3 -2
- package/app/components/account/governance/AccountWorkflowsTable.vue +76 -1
- package/app/components/account/governance/GovernanceApprovalLimitModal.vue +8 -0
- package/app/components/account/governance/GovernanceCostCenterModal.vue +7 -0
- package/app/components/account/governance/GovernanceWorkflowModal.vue +7 -0
- package/app/components/account/orderlists/AccountOrderListDetail.vue +14 -4
- package/app/components/account/orderlists/AccountOrderListsTable.vue +115 -7
- package/app/components/account/orders/AccountOrderDetail.vue +67 -3
- package/app/components/account/orders/AccountOrderPay.vue +211 -0
- package/app/components/account/orders/AccountOrdersTable.vue +119 -10
- package/app/components/account/organization/AccountOrganization.vue +6 -0
- package/app/components/account/profile/AccountPasswordForm.vue +2 -0
- package/app/components/account/profile/AccountProfileForm.vue +4 -0
- package/app/components/account/quotes/AccountQuoteDetail.vue +7 -10
- package/app/components/account/team/AccountTeam.vue +91 -0
- package/app/components/auth/AuthLoginTeaser.vue +1 -1
- package/app/components/auth/AuthRegisterPanel.vue +22 -3
- package/app/components/cart/manage/CartNameModal.vue +4 -0
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +5 -1
- package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +9 -1
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +6 -1
- package/app/components/form/FormPage.vue +7 -4
- package/app/components/layout/footer/Footer.vue +15 -2
- package/app/components/layout/header/LocaleSwitcher.vue +79 -12
- package/app/components/ui/forms/PasswordInput.vue +2 -0
- package/app/components/ui/forms/SearchInput.vue +205 -8
- package/app/components/ui/table/TableCardList.vue +69 -0
- package/app/components/ui/table/TableSortButton.vue +1 -1
- package/app/components/ui/table/TableToolbar.vue +2 -0
- package/app/components/withdrawal/WithdrawalDeclaration.vue +286 -0
- package/app/composables/useCheckoutOnePage.ts +22 -0
- package/app/composables/useMobileTableSort.ts +82 -0
- package/app/composables/useProductCard.ts +14 -0
- package/app/composables/useProductListing.ts +27 -1
- package/app/composables/useSearchEvents.ts +67 -0
- package/app/config/forms.ts +8 -0
- package/app/config/navigation.ts +8 -0
- package/app/formkit.config.ts +21 -0
- package/app/interfaces/account/order-list.ts +11 -0
- package/app/interfaces/account/quotes.ts +7 -3
- package/app/interfaces/market.ts +7 -0
- package/app/pages/punchout/transfer.vue +36 -1
- package/app/pages/widerruf.vue +33 -0
- package/app/plugins/search-events.client.ts +41 -0
- package/app/shared/addressLines.ts +66 -0
- package/app/shared/checkoutAddressRefusal.ts +63 -0
- package/app/shared/locale.ts +133 -0
- package/app/shared/searchAttribution.ts +91 -0
- package/app/shared/themeEvents.ts +1 -1
- package/i18n/locales/de/account.json +13 -1
- package/i18n/locales/de/cart.json +1 -0
- package/i18n/locales/de/checkout.json +1 -1
- package/i18n/locales/de/common.json +7 -0
- package/i18n/locales/de/search.json +7 -0
- package/i18n/locales/de/withdrawal.json +34 -0
- package/i18n/locales/en/account.json +13 -1
- package/i18n/locales/en/cart.json +1 -0
- package/i18n/locales/en/checkout.json +1 -1
- package/i18n/locales/en/common.json +7 -0
- package/i18n/locales/en/search.json +7 -0
- package/i18n/locales/en/withdrawal.json +34 -0
- package/nuxt.config.ts +3 -0
- package/package.json +1 -1
- package/server/api/account/orders/[id]/pay.post.ts +100 -0
- package/server/api/account/orders/[id].get.ts +5 -1
- package/server/api/account/quotes/[id]/order.post.ts +22 -22
- package/server/api/brands.get.ts +3 -2
- package/server/api/categories/[slug]/subcategories.get.ts +9 -6
- package/server/api/forms/[slug].get.ts +1 -3
- package/server/api/orders/index.post.ts +33 -50
- package/server/api/products/index.get.ts +6 -1
- package/server/api/punchout/return.post.ts +3 -1
- package/server/api/search/events.post.ts +65 -0
- package/server/api/typesense/search.post.ts +12 -1
- package/server/api/typesense/suggest.post.ts +43 -22
- package/server/data/forms/authored.json +69 -8
- package/server/dev/errorHandler.ts +47 -0
- package/server/interfaces/brand.ts +3 -2
- package/server/interfaces/product.ts +5 -0
- package/server/interfaces/punchout.ts +5 -0
- package/server/middleware/missing-media.ts +35 -0
- package/server/middleware/punchout-hand-back-csp.ts +17 -0
- package/server/plugins/vue-devtools-sink.ts +28 -0
- package/server/services/ApiBrandService.ts +8 -8
- package/server/services/ApiMarketService.ts +9 -2
- package/server/services/ApiProductService.ts +1 -1
- package/server/services/MockFormsService.ts +3 -1
- package/server/utils/addressRefusal.ts +63 -0
- package/server/utils/country.ts +23 -0
- package/server/utils/forms.ts +23 -1
- package/server/utils/liveOrders.ts +44 -2
- package/server/utils/locale.ts +58 -4
- package/server/utils/orderPayment.ts +155 -0
- package/server/utils/punchoutFormAction.ts +44 -0
- package/server/utils/searchClient.ts +27 -4
- package/server/utils/searchEvents.ts +46 -0
- package/server/utils/searchMultiSearchFallback.ts +2 -0
- package/server/utils/searchSuggest.ts +207 -0
- package/server/utils/suggestTiles.ts +141 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Customer addresses may carry the country as a display name ("Deutschland",
|
|
2
|
+
// "Austria") — the payments app's eligibility check expects ISO 3166-1
|
|
3
|
+
// alpha-2 codes. Two-letter values pass through unchanged.
|
|
4
|
+
const COUNTRY_NAME_TO_ISO: Record<string, string> = {
|
|
5
|
+
deutschland: "DE", germany: "DE",
|
|
6
|
+
österreich: "AT", austria: "AT",
|
|
7
|
+
schweiz: "CH", switzerland: "CH",
|
|
8
|
+
niederlande: "NL", netherlands: "NL",
|
|
9
|
+
frankreich: "FR", france: "FR",
|
|
10
|
+
italien: "IT", italy: "IT",
|
|
11
|
+
spanien: "ES", spain: "ES",
|
|
12
|
+
belgien: "BE", belgium: "BE",
|
|
13
|
+
polen: "PL", poland: "PL",
|
|
14
|
+
tschechien: "CZ", "czech republic": "CZ", czechia: "CZ",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function toIsoCountry(value: unknown): string {
|
|
18
|
+
const raw = String(value ?? "").trim();
|
|
19
|
+
if (/^[A-Za-z]{2}$/.test(raw)) {
|
|
20
|
+
return raw.toUpperCase();
|
|
21
|
+
}
|
|
22
|
+
return COUNTRY_NAME_TO_ISO[raw.toLowerCase()] ?? raw;
|
|
23
|
+
}
|
package/server/utils/forms.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
|
-
import type { FormRow, FormSettings, FormSpamPolicy } from "../interfaces/forms";
|
|
3
|
+
import type { FormPublicSettings, FormRow, FormSettings, FormSpamPolicy } from "../interfaces/forms";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Run a form's post-submit actions once a submission is recorded. Best-effort
|
|
@@ -79,6 +79,28 @@ export function localizeDefinition(
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* The form's own words — submit label, success message — for the visitor.
|
|
84
|
+
*
|
|
85
|
+
* The Cockpit's overlay translates fields only, so these exist in the authored
|
|
86
|
+
* language alone. Shown to a visitor reading another language they would be the
|
|
87
|
+
* one sentence on the page in a language they did not choose; left out, the
|
|
88
|
+
* storefront says the same in its own translated words instead.
|
|
89
|
+
*/
|
|
90
|
+
export function localizeSettings(
|
|
91
|
+
settings: FormSettings | null | undefined,
|
|
92
|
+
locale: string,
|
|
93
|
+
): FormPublicSettings | null {
|
|
94
|
+
if (!settings) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const base = settings.default_locale ?? "en";
|
|
98
|
+
if (locale && locale !== base) {
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
return { submit_label: settings.submit_label, success_message: settings.success_message };
|
|
102
|
+
}
|
|
103
|
+
|
|
82
104
|
/**
|
|
83
105
|
* The field names a definition declares. Only a named node collects a value —
|
|
84
106
|
* the same rule the app counts its field ceiling by — so content nodes and step
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
3
|
import type { AccountOrder, AccountOrderPosition, AccountOrderReturn, AccountOrderStatus, AccountOrderPaymentStatus } from "../../app/interfaces/account/order-list";
|
|
4
|
+
import { addressLines } from "../../app/shared/addressLines";
|
|
4
5
|
|
|
5
6
|
import { verifiedBuyer } from "./buyerIdentity";
|
|
7
|
+
import { toIsoCountry } from "./country";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Live orders via the orders app — placing from the checkout snapshot and
|
|
@@ -86,9 +88,13 @@ function mapPaymentStatus(status: string): AccountOrderPaymentStatus {
|
|
|
86
88
|
return "open";
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
/**
|
|
92
|
+
* One address as the account and the confirmation print it: the lines frozen on
|
|
93
|
+
* the order when there are some, else the address type's keys (RAD-236). The
|
|
94
|
+
* pages split this back on " · ".
|
|
95
|
+
*/
|
|
89
96
|
const addressLine = (a: Record<string, unknown> | null | undefined): string =>
|
|
90
|
-
|
|
91
|
-
.filter(Boolean).join(" · ");
|
|
97
|
+
addressLines(a).join(" · ");
|
|
92
98
|
|
|
93
99
|
/** Units already returned per order_item id, summed across all return records. */
|
|
94
100
|
function returnedByOrderItem(returns: LiveOrderReturn[] | undefined): Record<string, number> {
|
|
@@ -181,9 +187,45 @@ export function mapLiveOrderToAccount(order: LiveOrder): AccountOrder {
|
|
|
181
187
|
// cancellation once anything has shipped, so the shop asks the same
|
|
182
188
|
// question rather than offering a button that answers with an error.
|
|
183
189
|
cancellable: canBeCancelled(order),
|
|
190
|
+
...(paymentCountry(order) ? { paymentCountry: paymentCountry(order) } : {}),
|
|
184
191
|
};
|
|
185
192
|
}
|
|
186
193
|
|
|
194
|
+
/**
|
|
195
|
+
* The country an order is paid from, as the payments app reads one: the billing
|
|
196
|
+
* address's, else the delivery address's, as an ISO code. One answer for both
|
|
197
|
+
* questions asked of it, which methods the order may be paid with and the
|
|
198
|
+
* payment itself, so the methods offered are the ones the payment is taken under.
|
|
199
|
+
*/
|
|
200
|
+
export function paymentCountry(order: LiveOrder): string | undefined {
|
|
201
|
+
// `||`, not `??`: an address saved with an empty country names none. The
|
|
202
|
+
// address type's `country_code` first, the old flat key after (RAD-236).
|
|
203
|
+
const billing = order.billing_address;
|
|
204
|
+
const shipping = order.shipping_address;
|
|
205
|
+
return toIsoCountry(billing?.country_code || billing?.country || shipping?.country_code || shipping?.country) || undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Whether the order itself stands open for a payment.
|
|
210
|
+
*
|
|
211
|
+
* An order that waited for approval was not paid at the checkout, so once it is
|
|
212
|
+
* placed it is open with nothing behind it (RAD-173) — as is one whose payment
|
|
213
|
+
* failed. One still waiting, or called off, owes nothing; one with a payment
|
|
214
|
+
* under way is the payments app's to settle; and one naming no method cannot be
|
|
215
|
+
* paid by the buyer at all. Whether a payment already sits on it is the second
|
|
216
|
+
* half of the question, which only the payments app can answer
|
|
217
|
+
* (`orderAwaitsPayment`).
|
|
218
|
+
*/
|
|
219
|
+
export function canBePaid(order: LiveOrder): boolean {
|
|
220
|
+
if (order.status === "pending" || order.status === "cancelled") {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
if (!order.payment?.method) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return order.payment_status === "open" || order.payment_status === "failed";
|
|
227
|
+
}
|
|
228
|
+
|
|
187
229
|
/**
|
|
188
230
|
* Whether this order can still be called off.
|
|
189
231
|
*
|
package/server/utils/locale.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { getCookie, getHeader, type H3Event } from "h3";
|
|
2
2
|
|
|
3
|
+
import { pickMarketLocale } from "../../app/shared/locale";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Cookie the language choice persists the chosen MARKET locale in (`de-CH`,
|
|
7
|
+
* `fr-FR`). The URL prefix only says which UI strings render; this says
|
|
8
|
+
* which catalogue language the buyer asked for, which differs when the
|
|
9
|
+
* market offers a language the storefront has no UI strings for (PE-866).
|
|
10
|
+
*/
|
|
11
|
+
export const CONTENT_LOCALE_COOKIE_NAME = "cover-content-locale";
|
|
12
|
+
|
|
3
13
|
// Update when adding/removing locale subdirectories in i18n/locales/
|
|
4
14
|
const SUPPORTED = new Set(["de", "en"] as const);
|
|
5
15
|
export type Locale = "de" | "en";
|
|
@@ -34,10 +44,45 @@ export function resolveLocale(event: H3Event): Locale {
|
|
|
34
44
|
return fromAccept;
|
|
35
45
|
}
|
|
36
46
|
|
|
47
|
+
return defaultUiLanguage();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function defaultUiLanguage(): Locale {
|
|
37
51
|
const configDefault = useRuntimeConfig().public.defaultLocale;
|
|
38
52
|
return (SUPPORTED.has(configDefault as Locale) ? configDefault : "de") as Locale;
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The market locale this request reads the catalogue in — what search sends
|
|
57
|
+
* as `X-Revenexx-Locale` and what a contact is stored under.
|
|
58
|
+
*
|
|
59
|
+
* The market is the source of truth for which locales a store offers (its
|
|
60
|
+
* `preparing` locales excluded): the buyer's explicit choice when it fits the
|
|
61
|
+
* page language, else the market's locale for the page language. Without
|
|
62
|
+
* markets, or when they cannot be read, the page language's full code — what
|
|
63
|
+
* the storefront asked before markets carried locales.
|
|
64
|
+
*/
|
|
65
|
+
export async function resolveMarketLocale(event: H3Event): Promise<string> {
|
|
66
|
+
const language = resolveLocale(event);
|
|
67
|
+
let locales: { code: string; language?: string; isDefault?: boolean; status?: string }[] = [];
|
|
68
|
+
try {
|
|
69
|
+
const markets = await getMarketService(event).listMarkets();
|
|
70
|
+
const selected = resolveSelectedMarket(event);
|
|
71
|
+
const market = markets.find(m => m.code === selected) ?? markets.find(m => m.isDefault) ?? markets[0];
|
|
72
|
+
locales = market?.locales ?? [];
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
locales = [];
|
|
76
|
+
}
|
|
77
|
+
return pickMarketLocale({
|
|
78
|
+
locales,
|
|
79
|
+
chosen: getCookie(event, CONTENT_LOCALE_COOKIE_NAME),
|
|
80
|
+
uiLanguage: language,
|
|
81
|
+
uiLanguages: [...SUPPORTED],
|
|
82
|
+
defaultUiLanguage: defaultUiLanguage(),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
41
86
|
/**
|
|
42
87
|
* The locale a CONTACT is stored under, which is not the locale the UI
|
|
43
88
|
* speaks. The storefront works in a language ("de"); the customers app keeps
|
|
@@ -46,6 +91,7 @@ export function resolveLocale(event: H3Event): Locale {
|
|
|
46
91
|
* language reads to the buyer as a registration that silently breaks.
|
|
47
92
|
*
|
|
48
93
|
* The market is the source of truth for which locales a store has. Falls back
|
|
94
|
+
* to the market's default locale when it has none for the page language, and
|
|
49
95
|
* to the bare language when markets cannot be read: a registration that
|
|
50
96
|
* reaches the app and may be refused beats one that never leaves.
|
|
51
97
|
*/
|
|
@@ -56,10 +102,18 @@ export async function resolveStoreLocale(event: H3Event): Promise<string> {
|
|
|
56
102
|
const selected = resolveSelectedMarket(event);
|
|
57
103
|
const market = markets.find(m => m.code === selected) ?? markets.find(m => m.isDefault) ?? markets[0];
|
|
58
104
|
const locales = market?.locales ?? [];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
105
|
+
if (!locales.length) {
|
|
106
|
+
return language;
|
|
107
|
+
}
|
|
108
|
+
const picked = pickMarketLocale({
|
|
109
|
+
locales,
|
|
110
|
+
chosen: getCookie(event, CONTENT_LOCALE_COOKIE_NAME),
|
|
111
|
+
uiLanguage: language,
|
|
112
|
+
uiLanguages: [...SUPPORTED],
|
|
113
|
+
defaultUiLanguage: defaultUiLanguage(),
|
|
114
|
+
});
|
|
115
|
+
const known = locales.some(l => l.code === picked);
|
|
116
|
+
return known ? picked : (locales.find(l => l.isDefault) ?? locales[0])?.code ?? language;
|
|
63
117
|
}
|
|
64
118
|
catch {
|
|
65
119
|
return language;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { OrderPaymentStatus } from "@revenexx/sdk";
|
|
2
|
+
import type { H3Event } from "h3";
|
|
3
|
+
|
|
4
|
+
import { canBePaid, type LiveOrder } from "./liveOrders";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* When a purchase is paid, and what its payment says about the order (RAD-173).
|
|
8
|
+
*
|
|
9
|
+
* A purchase that waits for somebody's approval is not paid at the checkout:
|
|
10
|
+
* there is no order yet, and the approval may never produce one. It is paid
|
|
11
|
+
* once the order exists — from the order's own page — and every payment for an
|
|
12
|
+
* order names it, so the payments app can hold the payment to the order's
|
|
13
|
+
* currency, buyer and open total.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Whether the checkout takes the payment now, or leaves it to the order. */
|
|
17
|
+
export function checkoutTakesPayment(livePayments: boolean, awaitingApproval: boolean): boolean {
|
|
18
|
+
return livePayments && !awaitingApproval;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface OrderPaymentInput {
|
|
22
|
+
method: string;
|
|
23
|
+
amount: number;
|
|
24
|
+
currency: string;
|
|
25
|
+
country: string;
|
|
26
|
+
/** The order's display number. */
|
|
27
|
+
orderRef: string;
|
|
28
|
+
/** The order's id, once the orders app placed it. */
|
|
29
|
+
orderId?: string | null;
|
|
30
|
+
contactId?: string;
|
|
31
|
+
idempotencyKey: string;
|
|
32
|
+
token?: string;
|
|
33
|
+
returnUrl?: string;
|
|
34
|
+
metadata?: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The body the payments app is asked to create a payment with. */
|
|
38
|
+
export function orderPaymentRequest(input: OrderPaymentInput): Record<string, unknown> {
|
|
39
|
+
return {
|
|
40
|
+
method_code: input.method,
|
|
41
|
+
amount: Math.max(0, Math.round(input.amount * 100) / 100),
|
|
42
|
+
currency: input.currency,
|
|
43
|
+
country: input.country,
|
|
44
|
+
order_ref: input.orderRef,
|
|
45
|
+
// The order itself, wherever there is one: payments then checks the
|
|
46
|
+
// payment against it and refuses one the order never owed.
|
|
47
|
+
...(input.orderId ? { order_id: input.orderId } : {}),
|
|
48
|
+
// Whose payment this is: the account's payments page lists by it
|
|
49
|
+
// (RAD-171). The principal's contact, which payments holds the body to —
|
|
50
|
+
// a guest pays as nobody.
|
|
51
|
+
...(input.contactId ? { contact_id: input.contactId } : {}),
|
|
52
|
+
idempotency_key: input.idempotencyKey,
|
|
53
|
+
...(input.token ? { token: input.token } : {}),
|
|
54
|
+
...(input.returnUrl ? { return_url: input.returnUrl } : {}),
|
|
55
|
+
metadata: input.metadata ?? {},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The order's payment dimension for what the payments app answered. Its
|
|
61
|
+
* terminal "paid" state is `captured` (PSP auto/manual capture);
|
|
62
|
+
* `succeeded`/`paid` are accepted as synonyms.
|
|
63
|
+
*
|
|
64
|
+
* A failed payment says so, and a cancelled one leaves the order open: neither
|
|
65
|
+
* holds any of the order's money, so the order is still owed and its page
|
|
66
|
+
* offers it for payment (RAD-173). Recorded as pending, a quote order whose
|
|
67
|
+
* payment failed would read as being paid and never be offered.
|
|
68
|
+
*/
|
|
69
|
+
export function orderPaymentStatusFor(paymentStatus: string): OrderPaymentStatus {
|
|
70
|
+
if (["captured", "succeeded", "paid"].includes(paymentStatus)) {
|
|
71
|
+
return OrderPaymentStatus.Paid;
|
|
72
|
+
}
|
|
73
|
+
if (paymentStatus === "authorized") {
|
|
74
|
+
return OrderPaymentStatus.Authorized;
|
|
75
|
+
}
|
|
76
|
+
if (paymentStatus === "failed") {
|
|
77
|
+
return OrderPaymentStatus.Failed;
|
|
78
|
+
}
|
|
79
|
+
if (paymentStatus === "cancelled") {
|
|
80
|
+
return OrderPaymentStatus.Open;
|
|
81
|
+
}
|
|
82
|
+
return OrderPaymentStatus.Pending;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Payment states that hold part of an order's total — the payments app's own
|
|
87
|
+
* rule for what counts against an order. A failed, cancelled or refunded one
|
|
88
|
+
* leaves the order owed again.
|
|
89
|
+
*/
|
|
90
|
+
const HOLDING_PAYMENT = new Set(["created", "requires_action", "authorized", "captured"]);
|
|
91
|
+
|
|
92
|
+
interface OrderPaymentRow {
|
|
93
|
+
status: string;
|
|
94
|
+
idempotency_key?: string | null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether this order waits for the buyer to pay it (RAD-173).
|
|
99
|
+
*
|
|
100
|
+
* The order has to stand open for a payment (`canBePaid`), the storefront has
|
|
101
|
+
* to take live payments, and no payment may already sit on it. That last part
|
|
102
|
+
* is asked of the payments app by the order's number, not its id: payments made
|
|
103
|
+
* before they named the order carry only the number, and an order whose status
|
|
104
|
+
* sync failed back then would otherwise be charged a second time. It is read as
|
|
105
|
+
* the merchant's system, because a buyer's list shows only payments made out to
|
|
106
|
+
* them, and an older payment may be made out to nobody.
|
|
107
|
+
*
|
|
108
|
+
* One payment does not stand in the way: the one made under `idempotencyKey`.
|
|
109
|
+
* That is this same attempt asked again, after its answer was lost. Let through,
|
|
110
|
+
* the payments app replays it, which is how a buyer whose 3-D Secure step was
|
|
111
|
+
* lost on the way back still gets the redirect.
|
|
112
|
+
*
|
|
113
|
+
* Fails closed: a payments app that cannot say means no offer to pay.
|
|
114
|
+
*/
|
|
115
|
+
export async function orderAwaitsPayment(event: H3Event, order: LiveOrder, idempotencyKey?: string): Promise<boolean> {
|
|
116
|
+
if (resolvePaymentServiceKey(event) !== "api" || !order.payment?.method) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (order.status === "pending" || order.status === "cancelled") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const answer = await useTenantSdk().call<{ payments?: OrderPaymentRow[]; items?: OrderPaymentRow[] }>(
|
|
124
|
+
"GET",
|
|
125
|
+
"/v1/payments",
|
|
126
|
+
{ query: { order_ref: order.number, limit: 50 } },
|
|
127
|
+
);
|
|
128
|
+
const holding = (answer.payments ?? answer.items ?? []).filter(p => HOLDING_PAYMENT.has(p.status));
|
|
129
|
+
// This attempt's own payment: through, whatever the order says by now —
|
|
130
|
+
// the first call may already have recorded it as pending before its
|
|
131
|
+
// answer was lost.
|
|
132
|
+
if (idempotencyKey !== undefined && holding.some(p => p.idempotency_key === idempotencyKey)) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
return canBePaid(order) && holding.length === 0;
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
getLogService().error(`Payments for order ${order.number} could not be read`, apiErrorContext(err));
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Record on the order what its payment came to — as the merchant's system,
|
|
145
|
+
* because the orders app refuses a payment status from a buyer (RAD-174).
|
|
146
|
+
* Best-effort: the payment stands either way, and a missed sync is logged.
|
|
147
|
+
*/
|
|
148
|
+
export async function recordOrderPaymentStatus(orderUuid: string, paymentStatus: string): Promise<void> {
|
|
149
|
+
try {
|
|
150
|
+
await useTenantSdk().orders.ordersPaymentStatusUpdate({ id: orderUuid, status: orderPaymentStatusFor(paymentStatus) });
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
getLogService().error("Order payment-status sync failed", apiErrorContext(err));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PunchoutVisit } from "../interfaces/punchout";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where the hand-back form may be submitted to (PE-994).
|
|
5
|
+
*
|
|
6
|
+
* The hand-back is a form the buyer's browser submits to the procurement
|
|
7
|
+
* system's return address — OCI `HOOK_URL`, cXML `BrowserFormPost`, IDS
|
|
8
|
+
* `hookurl`. A shop that answers `form-action 'self'` makes the browser refuse
|
|
9
|
+
* that submit, and the buyer is left on the interstitial with a button that
|
|
10
|
+
* does nothing. The address differs per ERP and per visit, so no static
|
|
11
|
+
* allowlist can cover it: the hand-back page names the one origin THIS visit
|
|
12
|
+
* goes back to, and every other page keeps `'self'`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The hand-back page, under any locale prefix. */
|
|
16
|
+
const HAND_BACK_PATH = /(?:^|\/)punchout\/transfer\/?$/;
|
|
17
|
+
|
|
18
|
+
export function isHandBackPath(path: string): boolean {
|
|
19
|
+
return HAND_BACK_PATH.test(path.split("?")[0] ?? "");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The origin a hand-back payload posts to, or null when the browser posts
|
|
24
|
+
* nothing (a secured OCI visit answers no `target_url`) or the address is not
|
|
25
|
+
* an http(s) URL — anything else must not reach a CSP header.
|
|
26
|
+
*/
|
|
27
|
+
export function handBackOrigin(targetUrl: string | null | undefined): string | null {
|
|
28
|
+
if (!targetUrl) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const url = new URL(targetUrl);
|
|
33
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.origin : null;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The `form-action` directive the hand-back page answers for this visit. */
|
|
41
|
+
export function handBackFormAction(visit: PunchoutVisit | null): string {
|
|
42
|
+
const origin = visit?.handBackOrigin;
|
|
43
|
+
return origin ? `form-action 'self' ${origin}` : "form-action 'self'";
|
|
44
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { searchLocaleKeys } from "../../app/shared/locale";
|
|
1
|
+
import { localeLanguage, searchLocaleKeys } from "../../app/shared/locale";
|
|
2
2
|
import type { LiveProductDoc } from "./liveCatalog";
|
|
3
3
|
import { preferLocaleDocs } from "./liveCatalog";
|
|
4
4
|
import { searchViaMultiSearch } from "./searchMultiSearchFallback";
|
|
@@ -78,8 +78,18 @@ export interface SearchClientResult {
|
|
|
78
78
|
found: number;
|
|
79
79
|
page: number;
|
|
80
80
|
perPage: number;
|
|
81
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The locale whose index answered, "" when none. With one index per
|
|
83
|
+
* language (PE-865) the service answers a language it has no index for
|
|
84
|
+
* from the tenant's default language and says so here (it also sends
|
|
85
|
+
* `X-Revenexx-Locale-Served`, which the SDK call does not surface).
|
|
86
|
+
*/
|
|
82
87
|
locale: string;
|
|
88
|
+
/**
|
|
89
|
+
* True when another language answered than the one asked for — a page can
|
|
90
|
+
* say "shown in German" instead of passing the results off as French.
|
|
91
|
+
*/
|
|
92
|
+
localeFallback: boolean;
|
|
83
93
|
/** One document per product, the best-matching locale winning. */
|
|
84
94
|
docs: LiveProductDoc[];
|
|
85
95
|
facets: SearchFacetResult[];
|
|
@@ -194,7 +204,7 @@ function safeRedirectUrl(raw: unknown): string | null {
|
|
|
194
204
|
return /^https?:\/\//i.test(url) ? url : null;
|
|
195
205
|
}
|
|
196
206
|
|
|
197
|
-
function
|
|
207
|
+
export function normalizeSearchAction(raw: unknown): SearchAction | null {
|
|
198
208
|
if (!raw || typeof raw !== "object") {
|
|
199
209
|
return null;
|
|
200
210
|
}
|
|
@@ -212,6 +222,18 @@ function normalizeAction(raw: unknown): SearchAction | null {
|
|
|
212
222
|
return null;
|
|
213
223
|
}
|
|
214
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Whether the served locale is another language than the requested one.
|
|
227
|
+
* A region answering for another region of the same language (`de` for
|
|
228
|
+
* `de-CH`) is not a fallback: the text is the buyer's language.
|
|
229
|
+
*/
|
|
230
|
+
export function isLocaleFallback(requested: string | undefined, served: string | undefined): boolean {
|
|
231
|
+
if (!requested || !served) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
return localeLanguage(requested) !== localeLanguage(served);
|
|
235
|
+
}
|
|
236
|
+
|
|
215
237
|
/** The query endpoint's answer in the shape every caller reads. */
|
|
216
238
|
export function mapSearchQueryResponse(
|
|
217
239
|
response: SearchQueryResponse,
|
|
@@ -230,6 +252,7 @@ export function mapSearchQueryResponse(
|
|
|
230
252
|
page: response.page ?? Math.max(1, params.page ?? 1),
|
|
231
253
|
perPage: response.per_page ?? params.perPage ?? hits.length,
|
|
232
254
|
locale: response.locale ?? "",
|
|
255
|
+
localeFallback: isLocaleFallback(params.locale, response.locale),
|
|
233
256
|
docs,
|
|
234
257
|
facets: (response.facets ?? []).map(facet => ({
|
|
235
258
|
field: facet.field,
|
|
@@ -237,7 +260,7 @@ export function mapSearchQueryResponse(
|
|
|
237
260
|
...(facet.stats ? { stats: facet.stats } : {}),
|
|
238
261
|
})),
|
|
239
262
|
actions: (response.actions ?? [])
|
|
240
|
-
.map(
|
|
263
|
+
.map(normalizeSearchAction)
|
|
241
264
|
.filter((action): action is SearchAction => action !== null),
|
|
242
265
|
ignoredFilters: response.ignored_filters ?? [],
|
|
243
266
|
ignoredSort: response.ignored_sort ?? null,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The body POST /v1/search/events gets from the storefront's BFF (PE-867):
|
|
3
|
+
* the storefront's camelCase event, checked, in the search service's shape.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const TYPES = new Set(["click", "add_to_cart", "purchase"]);
|
|
7
|
+
const COLLECTION_RE = /^[a-z][a-z0-9_-]{0,62}$/;
|
|
8
|
+
const DOC_ID_RE = /^[\w.:-]{1,128}$/;
|
|
9
|
+
const QUERY_ID_RE = /^[\w-]{1,40}$/;
|
|
10
|
+
|
|
11
|
+
export interface SearchEventInput {
|
|
12
|
+
type?: string;
|
|
13
|
+
queryId?: string;
|
|
14
|
+
collection?: string;
|
|
15
|
+
docId?: string;
|
|
16
|
+
position?: number;
|
|
17
|
+
q?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The body the search service gets, or null when the storefront sent nonsense. */
|
|
21
|
+
export function searchEventBody(input: SearchEventInput, userToken: string): Record<string, unknown> | null {
|
|
22
|
+
if (!input.type || !TYPES.has(input.type) || !input.collection || !COLLECTION_RE.test(input.collection)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (input.queryId !== undefined && !QUERY_ID_RE.test(input.queryId)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (input.docId !== undefined && !DOC_ID_RE.test(input.docId)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (input.type === "click" && !input.queryId) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const position = typeof input.position === "number" && Number.isInteger(input.position) && input.position >= 1 && input.position <= 1000
|
|
35
|
+
? input.position
|
|
36
|
+
: undefined;
|
|
37
|
+
return {
|
|
38
|
+
type: input.type,
|
|
39
|
+
collection: input.collection,
|
|
40
|
+
...(input.queryId ? { query_id: input.queryId } : {}),
|
|
41
|
+
...(input.docId ? { doc_id: input.docId } : {}),
|
|
42
|
+
...(position ? { position } : {}),
|
|
43
|
+
...(typeof input.q === "string" && input.q.trim() ? { q: input.q.trim().slice(0, 200) } : {}),
|
|
44
|
+
user_token: userToken,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -203,6 +203,8 @@ export async function searchViaMultiSearch(params: SearchClientParams): Promise<
|
|
|
203
203
|
page: response.page ?? page,
|
|
204
204
|
perPage,
|
|
205
205
|
locale,
|
|
206
|
+
// multi_search filters the mixed index by locale, it never substitutes one.
|
|
207
|
+
localeFallback: false,
|
|
206
208
|
docs,
|
|
207
209
|
facets: (response.facet_counts ?? []).map(fc => ({
|
|
208
210
|
field: fc.field_name,
|