@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
package/app/formkit.config.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import { de, en } from "@formkit/i18n";
|
|
2
2
|
import { generateClasses } from "@formkit/themes";
|
|
3
|
+
import type { DefaultConfigOptions } from "@formkit/vue";
|
|
4
|
+
|
|
3
5
|
import { createInput, defineFormKitConfig } from "@formkit/vue";
|
|
4
6
|
|
|
5
7
|
import FormKitDatePicker from "./components/ui/forms/FormKitDatePicker.vue";
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* `requiredIf:field,value` — required only while the sibling `field` holds
|
|
11
|
+
* `value`, e.g. the phone number once "answer by phone" is chosen. Runs on an
|
|
12
|
+
* empty value (that is the point); FormKit re-validates when the sibling changes.
|
|
13
|
+
*/
|
|
14
|
+
type FormKitValidationRule = NonNullable<DefaultConfigOptions["rules"]>[string];
|
|
15
|
+
|
|
16
|
+
const requiredIf: FormKitValidationRule = (node, field, expected) => {
|
|
17
|
+
const other = node.at(`$parent.${String(field)}`);
|
|
18
|
+
if (String(other?.value ?? "") !== String(expected)) return true;
|
|
19
|
+
return String(node.value ?? "").trim() !== "";
|
|
20
|
+
};
|
|
21
|
+
requiredIf.skipEmpty = false;
|
|
22
|
+
|
|
7
23
|
/**
|
|
8
24
|
* FormKit configuration for the cover design system.
|
|
9
25
|
*
|
|
@@ -15,6 +31,10 @@ import FormKitDatePicker from "./components/ui/forms/FormKitDatePicker.vue";
|
|
|
15
31
|
export default defineFormKitConfig({
|
|
16
32
|
locales: { de, en },
|
|
17
33
|
locale: "de",
|
|
34
|
+
messages: {
|
|
35
|
+
de: { validation: { requiredIf: de.validation.required ?? "Dieses Feld ist erforderlich." } },
|
|
36
|
+
en: { validation: { requiredIf: en.validation.required ?? "This field is required." } },
|
|
37
|
+
},
|
|
18
38
|
// Custom inputs: `datepicker` wraps Nuxt UI's UCalendar (ISO string value).
|
|
19
39
|
inputs: {
|
|
20
40
|
datepicker: createInput(FormKitDatePicker, {
|
|
@@ -22,6 +42,7 @@ export default defineFormKitConfig({
|
|
|
22
42
|
}),
|
|
23
43
|
},
|
|
24
44
|
rules: {
|
|
45
|
+
requiredIf,
|
|
25
46
|
zip(node) {
|
|
26
47
|
const v = String(node.value ?? "").trim();
|
|
27
48
|
if (!/^\d{3,5}$/.test(v)) return false;
|
|
@@ -68,6 +68,17 @@ export interface AccountOrder {
|
|
|
68
68
|
* than no button.
|
|
69
69
|
*/
|
|
70
70
|
readonly cancellable?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the order waits for the buyer's payment: placed, naming a method,
|
|
73
|
+
* and with no payment on it — as one approved after it was requested is, since
|
|
74
|
+
* the checkout took none. Set on one order's detail only, never in the list.
|
|
75
|
+
*/
|
|
76
|
+
readonly payable?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* ISO country the order is paid from — billing address, else delivery address.
|
|
79
|
+
* What payment methods are offered for, and what the payment is taken under.
|
|
80
|
+
*/
|
|
81
|
+
readonly paymentCountry?: string;
|
|
71
82
|
/** Where cancelling requires the buyer to say why, as the merchant set it. */
|
|
72
83
|
readonly cancelNeedsReason?: boolean;
|
|
73
84
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Address } from "../address";
|
|
2
1
|
|
|
3
2
|
/**
|
|
4
3
|
* A quote as the buyer's account shows it (RX-783).
|
|
@@ -63,8 +62,13 @@ export interface AccountQuote {
|
|
|
63
62
|
reason: string | null;
|
|
64
63
|
buyerNote: string | null;
|
|
65
64
|
sellerNote: string | null;
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
/**
|
|
66
|
+
* As the quotes app answers it: the platform's address type plus the old
|
|
67
|
+
* flat keys (RAD-236). Printed through the shared address lines, never read
|
|
68
|
+
* key by key.
|
|
69
|
+
*/
|
|
70
|
+
shippingAddress: Record<string, unknown> | null;
|
|
71
|
+
billingAddress: Record<string, unknown> | null;
|
|
68
72
|
lines: AccountQuoteLine[];
|
|
69
73
|
trail: AccountQuoteNote[];
|
|
70
74
|
/** Orders placed out of this quote. */
|
package/app/interfaces/market.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* locales (language + country) and the currencies it trades in; the locale
|
|
4
4
|
* selector is driven by this.
|
|
5
5
|
*/
|
|
6
|
+
import type { MarketLocaleStatus } from "../shared/locale";
|
|
7
|
+
|
|
6
8
|
export interface ShopMarketLocale {
|
|
7
9
|
/** BCP-47 code, e.g. "de-DE". */
|
|
8
10
|
code: string;
|
|
@@ -11,6 +13,11 @@ export interface ShopMarketLocale {
|
|
|
11
13
|
/** ISO 3166-1 alpha-2 country, e.g. "DE". */
|
|
12
14
|
country: string;
|
|
13
15
|
isDefault: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Rollout state from the markets app. A `preparing` locale is being built
|
|
18
|
+
* (catalogue, search) and is never offered to buyers; absent = active.
|
|
19
|
+
*/
|
|
20
|
+
status?: MarketLocaleStatus;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export interface ShopMarketCurrency {
|
|
@@ -27,6 +27,11 @@ import { cartEcommerce } from "../../shared/themeEvents";
|
|
|
27
27
|
* payload is being answered again. It is submitted like any other — a buyer who
|
|
28
28
|
* pressed back, or a browser that double-submitted, must get the form and not
|
|
29
29
|
* an error page.
|
|
30
|
+
*
|
|
31
|
+
* The browser only submits to an origin the DOCUMENT's `form-action` allows
|
|
32
|
+
* (PE-994), and the return address is not known until the payload is in hand.
|
|
33
|
+
* So the first hand-back loads this page once more: the server then answers it
|
|
34
|
+
* with the visit's origin allowed, and the replayed payload is submitted.
|
|
30
35
|
*/
|
|
31
36
|
const { t } = useI18n();
|
|
32
37
|
const { icon } = useIcons();
|
|
@@ -77,6 +82,32 @@ const fields = computed(() => Object.entries(payload.value?.fields ?? {}));
|
|
|
77
82
|
*/
|
|
78
83
|
const isBackChannel = computed(() => payload.value !== null && !payload.value.target_url);
|
|
79
84
|
|
|
85
|
+
/**
|
|
86
|
+
* The origin this document's `form-action` allows besides 'self' — set by the
|
|
87
|
+
* server when it rendered this page, and unset when the buyer came here by a
|
|
88
|
+
* client-side navigation, whose document carries some other page's policy.
|
|
89
|
+
*/
|
|
90
|
+
const allowedOrigin = useState<string | null>("punchout-hand-back-origin", () =>
|
|
91
|
+
(import.meta.server ? useRequestEvent()?.context.punchoutHandBackOrigin : null) ?? null);
|
|
92
|
+
|
|
93
|
+
/** Reloaded once already; a second reload could only loop. */
|
|
94
|
+
const RELOAD_PARAM = "handback";
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Whether the form can be submitted from this document. If not, load the page
|
|
98
|
+
* again — once — so the server answers it with the visit's origin allowed.
|
|
99
|
+
*/
|
|
100
|
+
function reloadForFormAction(targetUrl: string): boolean {
|
|
101
|
+
const url = new URL(window.location.href);
|
|
102
|
+
const origin = new URL(targetUrl, url).origin;
|
|
103
|
+
if (origin === url.origin || origin === allowedOrigin.value || url.searchParams.has(RELOAD_PARAM)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
url.searchParams.set(RELOAD_PARAM, "1");
|
|
107
|
+
window.location.replace(url.toString());
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
80
111
|
onMounted(async () => {
|
|
81
112
|
try {
|
|
82
113
|
payload.value = await $fetch<PunchoutReturnPayload>("/api/punchout/return", { method: "POST" });
|
|
@@ -91,9 +122,13 @@ onMounted(async () => {
|
|
|
91
122
|
return;
|
|
92
123
|
}
|
|
93
124
|
|
|
125
|
+
reportTransfer();
|
|
126
|
+
if (payload.value?.target_url && reloadForFormAction(payload.value.target_url)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
94
130
|
// One tick so the form is in the DOM, and a beat so the buyer sees where
|
|
95
131
|
// they are going rather than a flash of a page they cannot read.
|
|
96
|
-
reportTransfer();
|
|
97
132
|
await nextTick();
|
|
98
133
|
window.setTimeout(() => form.value?.submit(), 400);
|
|
99
134
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import WithdrawalDeclaration from "../components/withdrawal/WithdrawalDeclaration.vue";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Withdrawing from a contract (§ 356a BGB) — reached from the footer on every
|
|
6
|
+
* page and from an order's detail page, which hands the order over as
|
|
7
|
+
* `?order=`. Shipped by the layer rather than each storefront, because the
|
|
8
|
+
* obligation is the same for all of them; open to guests, who have the same
|
|
9
|
+
* right as a signed-in buyer.
|
|
10
|
+
*/
|
|
11
|
+
const { t } = useI18n();
|
|
12
|
+
const route = useRoute();
|
|
13
|
+
|
|
14
|
+
const orderId = computed(() => {
|
|
15
|
+
const value = route.query.order;
|
|
16
|
+
return typeof value === "string" ? value : undefined;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
useHead({ title: () => t("withdrawal.title") });
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<UContainer class="max-w-xl py-10 lg:py-14">
|
|
24
|
+
<h1 class="text-2xl font-semibold text-highlighted mb-2">
|
|
25
|
+
{{ t('withdrawal.title') }}
|
|
26
|
+
</h1>
|
|
27
|
+
<p class="text-muted mb-8">
|
|
28
|
+
{{ t('withdrawal.intro') }}
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<WithdrawalDeclaration :order-id="orderId" />
|
|
32
|
+
</UContainer>
|
|
33
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ThemeEventEnvelope } from "@revenexx/tag-manager-nuxt/events";
|
|
2
|
+
|
|
3
|
+
import { forgetSearchAttributions, searchAttributions } from "../shared/searchAttribution";
|
|
4
|
+
import { browserSession } from "../shared/themeEvents";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Add-to-cart and purchase as search events (PE-867).
|
|
8
|
+
*
|
|
9
|
+
* The cart and the checkout already report both as theme events, once and
|
|
10
|
+
* only for what really happened (theme-events.client.ts). This listens to
|
|
11
|
+
* those and, for every article a search led to (searchAttribution.ts), tells
|
|
12
|
+
* the search service — so the analytics see which searches end in a cart or
|
|
13
|
+
* an order, without a second set of hooks in the cart.
|
|
14
|
+
*/
|
|
15
|
+
export default defineNuxtPlugin({
|
|
16
|
+
name: "cover:search-events",
|
|
17
|
+
dependsOn: ["cover:theme-events"],
|
|
18
|
+
setup(nuxtApp) {
|
|
19
|
+
const { send } = useSearchEvents();
|
|
20
|
+
|
|
21
|
+
nuxtApp.hook("revenexx:event", (envelope: ThemeEventEnvelope) => {
|
|
22
|
+
if (envelope.event !== "add_to_cart" && envelope.event !== "purchase") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const skus = (envelope.ecommerce?.items ?? []).map(item => item.sku).filter(Boolean);
|
|
26
|
+
const storage = browserSession();
|
|
27
|
+
for (const { attribution } of searchAttributions(storage, skus)) {
|
|
28
|
+
send({
|
|
29
|
+
type: envelope.event,
|
|
30
|
+
queryId: attribution.queryId,
|
|
31
|
+
collection: "products",
|
|
32
|
+
docId: attribution.docId,
|
|
33
|
+
q: attribution.q,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (envelope.event === "purchase") {
|
|
37
|
+
forgetSearchAttributions(storage, skus);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lines an address prints as, for an address the orders or quotes app
|
|
3
|
+
* answered (RAD-236).
|
|
4
|
+
*
|
|
5
|
+
* Those apps hold every address to the platform's address type (customers,
|
|
6
|
+
* `contracts/address.schema.json`) and answer the type plus the old flat keys.
|
|
7
|
+
* A placed order also carries `formatted`: the lines frozen when the order took
|
|
8
|
+
* the address over, ending with the country. Those are what the document says,
|
|
9
|
+
* so they are shown as they are. Without them the lines are put together from
|
|
10
|
+
* the type's keys, then from the old flat keys, then from the storefront's own
|
|
11
|
+
* camelCase ones, so an order stored before the move still reads.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type AddressLike = Record<string, unknown> | null | undefined;
|
|
15
|
+
|
|
16
|
+
const text = (value: unknown): string => (typeof value === "string" || typeof value === "number")
|
|
17
|
+
? String(value).trim()
|
|
18
|
+
: "";
|
|
19
|
+
|
|
20
|
+
const first = (a: Record<string, unknown>, ...keys: string[]): string => {
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const value = text(a[key]);
|
|
23
|
+
if (value) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return "";
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface AddressLinesOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Whether the lines put together from the keys end with the country. The
|
|
33
|
+
* frozen `formatted` lines always carry it; this decides only the fallback.
|
|
34
|
+
*/
|
|
35
|
+
country?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function addressLines(address: AddressLike, options: AddressLinesOptions = {}): string[] {
|
|
39
|
+
if (!address || typeof address !== "object") {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const a = address as Record<string, unknown>;
|
|
43
|
+
|
|
44
|
+
if (Array.isArray(a.formatted)) {
|
|
45
|
+
const printed = a.formatted.map(text).filter(Boolean);
|
|
46
|
+
if (printed.length) {
|
|
47
|
+
return printed;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const street = first(a, "address_line1")
|
|
52
|
+
|| [text(a.street_name), text(a.house_number), text(a.house_number_addition)].filter(Boolean).join(" ")
|
|
53
|
+
|| first(a, "street");
|
|
54
|
+
const postalCode = first(a, "postal_code", "zip", "postalCode");
|
|
55
|
+
const locality = first(a, "locality", "city");
|
|
56
|
+
|
|
57
|
+
return [
|
|
58
|
+
first(a, "organization_name", "company", "companyName"),
|
|
59
|
+
first(a, "recipient_name", "name", "contactName"),
|
|
60
|
+
street,
|
|
61
|
+
first(a, "address_line2", "street2"),
|
|
62
|
+
first(a, "address_line3"),
|
|
63
|
+
`${postalCode} ${locality}`.trim(),
|
|
64
|
+
options.country ? first(a, "country_code", "country") : "",
|
|
65
|
+
].filter(Boolean);
|
|
66
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where on the checkout an address refusal from the orders app belongs
|
|
3
|
+
* (RAD-236).
|
|
4
|
+
*
|
|
5
|
+
* The orders app checks postal codes and the rest per country and refuses with
|
|
6
|
+
* one sentence naming the field (`shipping_address.postal_code`). The BFF hands
|
|
7
|
+
* that on as `{ type: "invalid_address", address, key, message }`; this says
|
|
8
|
+
* which of the checkout's field errors carries it.
|
|
9
|
+
*/
|
|
10
|
+
export interface CheckoutAddressRefusal {
|
|
11
|
+
address: "billing" | "shipping" | null;
|
|
12
|
+
key: string | null;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The address type's keys, as the guest form's fields. */
|
|
17
|
+
const GUEST_FIELD: Record<string, string> = {
|
|
18
|
+
organization_name: "companyName",
|
|
19
|
+
recipient_name: "lastName",
|
|
20
|
+
address_line1: "street",
|
|
21
|
+
street_name: "street",
|
|
22
|
+
house_number: "street",
|
|
23
|
+
house_number_addition: "street",
|
|
24
|
+
postal_code: "postalCode",
|
|
25
|
+
locality: "city",
|
|
26
|
+
country_code: "country",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The refusal the BFF answered, out of a failed `$fetch`, or null for any other failure. */
|
|
30
|
+
export function checkoutAddressRefusalOf(err: unknown): CheckoutAddressRefusal | null {
|
|
31
|
+
const data = (err as { data?: { data?: Record<string, unknown> } } | null)?.data?.data;
|
|
32
|
+
if (!data || data.type !== "invalid_address" || typeof data.message !== "string" || !data.message) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const address = data.address === "billing" || data.address === "shipping" ? data.address : null;
|
|
36
|
+
return {
|
|
37
|
+
address,
|
|
38
|
+
key: typeof data.key === "string" && data.key ? data.key : null,
|
|
39
|
+
message: data.message,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The field error key a refusal is shown under.
|
|
45
|
+
*
|
|
46
|
+
* A billing address that is the delivery address is shown on the delivery
|
|
47
|
+
* address, because that is the one the buyer filled in. A signed-in buyer picked
|
|
48
|
+
* the address from the address book, so the sentence goes under the picker; a
|
|
49
|
+
* guest typed it, so it goes under the field itself, or under the first one
|
|
50
|
+
* when the app named only the address.
|
|
51
|
+
*/
|
|
52
|
+
export function checkoutAddressFieldOf(
|
|
53
|
+
refusal: CheckoutAddressRefusal,
|
|
54
|
+
options: { guest: boolean; billingSameAsShipping: boolean },
|
|
55
|
+
): string {
|
|
56
|
+
const billing = refusal.address === "billing" && !options.billingSameAsShipping;
|
|
57
|
+
if (!options.guest) {
|
|
58
|
+
return billing ? "billingAddressId" : "shippingAddressId";
|
|
59
|
+
}
|
|
60
|
+
const form = billing ? "guestBilling" : "guestShipping";
|
|
61
|
+
const field = (refusal.key && GUEST_FIELD[refusal.key]) || "street";
|
|
62
|
+
return `${form}.${field}`;
|
|
63
|
+
}
|
package/app/shared/locale.ts
CHANGED
|
@@ -112,3 +112,136 @@ export function pickLocalizedLabel(
|
|
|
112
112
|
}
|
|
113
113
|
return fallback;
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Where a market locale stands in its rollout (markets app, PE-866):
|
|
118
|
+
* `preparing` while the catalogue and search are being built for it, then
|
|
119
|
+
* `active`. A locale without a status predates the field and is active.
|
|
120
|
+
*/
|
|
121
|
+
export type MarketLocaleStatus = "preparing" | "active";
|
|
122
|
+
|
|
123
|
+
/** The part of a market locale the language choice needs. */
|
|
124
|
+
export interface MarketLocaleRef {
|
|
125
|
+
/** BCP-47 code as the market stores it, e.g. "de-CH". */
|
|
126
|
+
code: string;
|
|
127
|
+
/** ISO 639-1 language, e.g. "de". Derived from the code when empty. */
|
|
128
|
+
language?: string;
|
|
129
|
+
isDefault?: boolean;
|
|
130
|
+
status?: MarketLocaleStatus | string | null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Whether the storefront may offer this locale: anything but `preparing`. */
|
|
134
|
+
export function isOfferedLocale(locale: Pick<MarketLocaleRef, "status">): boolean {
|
|
135
|
+
return locale.status !== "preparing";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The locales a market offers its buyers, in the order to show them: the
|
|
140
|
+
* market's default first, the rest as the market lists them. A `preparing`
|
|
141
|
+
* locale is left out, and so is a second entry for the same code.
|
|
142
|
+
*/
|
|
143
|
+
export function offeredLocales<T extends MarketLocaleRef>(locales: readonly T[] | null | undefined): T[] {
|
|
144
|
+
const seen = new Set<string>();
|
|
145
|
+
const offered: T[] = [];
|
|
146
|
+
for (const locale of locales ?? []) {
|
|
147
|
+
const code = normalizeLocaleCode(locale.code);
|
|
148
|
+
if (!code || !isOfferedLocale(locale) || seen.has(code)) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
seen.add(code);
|
|
152
|
+
offered.push(locale);
|
|
153
|
+
}
|
|
154
|
+
return [...offered.filter(l => l.isDefault), ...offered.filter(l => !l.isDefault)];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The language of a market locale, from its `language` or its code. */
|
|
158
|
+
export function marketLocaleLanguage(locale: MarketLocaleRef): string {
|
|
159
|
+
return (locale.language?.trim() || localeLanguage(locale.code)).toLowerCase();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One entry of the language choice. */
|
|
163
|
+
export interface LanguageOption {
|
|
164
|
+
/** The market locale the catalogue and search are asked in, e.g. "de-CH". */
|
|
165
|
+
locale: string;
|
|
166
|
+
language: string;
|
|
167
|
+
/** The UI language the pages render in: the language itself, or the default UI language. */
|
|
168
|
+
uiLocale: string;
|
|
169
|
+
/** True when there are no UI strings for this language and the default UI language stands in. */
|
|
170
|
+
uiFallback: boolean;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The languages a market offers, one per language (the first locale the
|
|
175
|
+
* market offers for it wins, so the market's default leads). A language the
|
|
176
|
+
* storefront has no UI strings for is still offered: its catalogue and
|
|
177
|
+
* search answer in that language, the pages render in the default UI
|
|
178
|
+
* language. Null when the market offers no locale: the caller keeps its
|
|
179
|
+
* fixed UI languages, as before markets carried locales.
|
|
180
|
+
*/
|
|
181
|
+
export function marketLanguageOptions(
|
|
182
|
+
locales: readonly MarketLocaleRef[] | null | undefined,
|
|
183
|
+
uiLanguages: readonly string[],
|
|
184
|
+
defaultUiLanguage: string,
|
|
185
|
+
): LanguageOption[] | null {
|
|
186
|
+
const offered = offeredLocales(locales ?? []);
|
|
187
|
+
if (!offered.length) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const ui = new Set(uiLanguages.map(code => code.toLowerCase()));
|
|
191
|
+
const options: LanguageOption[] = [];
|
|
192
|
+
const languages = new Set<string>();
|
|
193
|
+
for (const entry of offered) {
|
|
194
|
+
const language = marketLocaleLanguage(entry);
|
|
195
|
+
if (!language || languages.has(language)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
languages.add(language);
|
|
199
|
+
const hasUi = ui.has(language);
|
|
200
|
+
options.push({
|
|
201
|
+
locale: normalizeLocaleCode(entry.code),
|
|
202
|
+
language,
|
|
203
|
+
uiLocale: hasUi ? language : defaultUiLanguage,
|
|
204
|
+
uiFallback: !hasUi,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return options;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The market locale the catalogue and search are asked in, for a page that
|
|
212
|
+
* renders in `uiLanguage`.
|
|
213
|
+
*
|
|
214
|
+
* `chosen` is the buyer's explicit choice (a market locale code). It wins
|
|
215
|
+
* when it is offered and agrees with the page: same language, or a language
|
|
216
|
+
* without UI strings shown in the default UI language. Otherwise the
|
|
217
|
+
* market's locale for the page language, else `fallback` (the bare
|
|
218
|
+
* language's full code, what the storefront asked before markets carried
|
|
219
|
+
* locales). A `preparing` locale is never answered.
|
|
220
|
+
*/
|
|
221
|
+
export function pickMarketLocale(input: {
|
|
222
|
+
locales: readonly MarketLocaleRef[] | null | undefined;
|
|
223
|
+
chosen?: string | null;
|
|
224
|
+
uiLanguage: string;
|
|
225
|
+
uiLanguages: readonly string[];
|
|
226
|
+
defaultUiLanguage: string;
|
|
227
|
+
}): string {
|
|
228
|
+
const uiLanguage = input.uiLanguage.toLowerCase();
|
|
229
|
+
const offered = offeredLocales(input.locales ?? []);
|
|
230
|
+
const ui = new Set(input.uiLanguages.map(code => code.toLowerCase()));
|
|
231
|
+
|
|
232
|
+
if (input.chosen) {
|
|
233
|
+
const chosen = normalizeLocaleCode(input.chosen);
|
|
234
|
+
const hit = offered.find(entry => normalizeLocaleCode(entry.code) === chosen);
|
|
235
|
+
if (hit) {
|
|
236
|
+
const language = marketLocaleLanguage(hit);
|
|
237
|
+
const agrees = language === uiLanguage
|
|
238
|
+
|| (!ui.has(language) && uiLanguage === input.defaultUiLanguage.toLowerCase());
|
|
239
|
+
if (agrees) {
|
|
240
|
+
return normalizeLocaleCode(hit.code);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const sameLanguage = offered.find(entry => marketLocaleLanguage(entry) === uiLanguage);
|
|
246
|
+
return sameLanguage ? normalizeLocaleCode(sameLanguage.code) : fullLocaleCode(uiLanguage);
|
|
247
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { StorageLike } from "./themeEvents";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which search led to a product (PE-867). A click from a search result or the
|
|
5
|
+
* quick search is remembered per article number, so the add-to-cart and the
|
|
6
|
+
* purchase that follow can be counted for that search. Kept in the tab's
|
|
7
|
+
* session storage only: it never leaves the browser except as the events
|
|
8
|
+
* themselves, and it ends with the tab.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface SearchAttribution {
|
|
12
|
+
queryId: string;
|
|
13
|
+
/** The product's search document id, sent back as the event's doc_id. */
|
|
14
|
+
docId: string;
|
|
15
|
+
q: string;
|
|
16
|
+
at: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const KEY = "rvx:search-attribution";
|
|
20
|
+
/** A click older than this no longer explains a cart. */
|
|
21
|
+
export const ATTRIBUTION_TTL_MS = 24 * 60 * 60 * 1000;
|
|
22
|
+
/** Products remembered at most; the oldest go first. */
|
|
23
|
+
export const ATTRIBUTION_LIMIT = 50;
|
|
24
|
+
|
|
25
|
+
type Store = Record<string, SearchAttribution>;
|
|
26
|
+
|
|
27
|
+
function read(storage: StorageLike | null | undefined, now: number): Store {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(storage?.getItem(KEY) ?? "{}") as Store;
|
|
30
|
+
const fresh: Store = {};
|
|
31
|
+
for (const [sku, entry] of Object.entries(parsed ?? {})) {
|
|
32
|
+
if (entry && typeof entry.queryId === "string" && typeof entry.at === "number" && now - entry.at < ATTRIBUTION_TTL_MS) {
|
|
33
|
+
fresh[sku] = entry;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return fresh;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function write(storage: StorageLike | null | undefined, store: Store): void {
|
|
44
|
+
try {
|
|
45
|
+
storage?.setItem(KEY, JSON.stringify(store));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// storage full or blocked: attribution is a nicety, never an error
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Remember that `sku` was opened from the search `entry.queryId`. */
|
|
53
|
+
export function rememberSearchClick(
|
|
54
|
+
storage: StorageLike | null | undefined,
|
|
55
|
+
sku: string,
|
|
56
|
+
entry: Omit<SearchAttribution, "at">,
|
|
57
|
+
now = Date.now(),
|
|
58
|
+
): void {
|
|
59
|
+
if (!sku || !entry.queryId) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const store = read(storage, now);
|
|
63
|
+
delete store[sku];
|
|
64
|
+
store[sku] = { ...entry, at: now };
|
|
65
|
+
const skus = Object.keys(store);
|
|
66
|
+
for (const old of skus.slice(0, Math.max(0, skus.length - ATTRIBUTION_LIMIT))) {
|
|
67
|
+
delete store[old];
|
|
68
|
+
}
|
|
69
|
+
write(storage, store);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The searches behind these article numbers, for those that have one. */
|
|
73
|
+
export function searchAttributions(
|
|
74
|
+
storage: StorageLike | null | undefined,
|
|
75
|
+
skus: readonly string[],
|
|
76
|
+
now = Date.now(),
|
|
77
|
+
): { sku: string; attribution: SearchAttribution }[] {
|
|
78
|
+
const store = read(storage, now);
|
|
79
|
+
return skus
|
|
80
|
+
.filter((sku, i) => skus.indexOf(sku) === i && store[sku] !== undefined)
|
|
81
|
+
.map(sku => ({ sku, attribution: store[sku]! }));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Forget these article numbers — after a purchase, a later order is not this search's. */
|
|
85
|
+
export function forgetSearchAttributions(storage: StorageLike | null | undefined, skus: readonly string[], now = Date.now()): void {
|
|
86
|
+
const store = read(storage, now);
|
|
87
|
+
for (const sku of skus) {
|
|
88
|
+
delete store[sku];
|
|
89
|
+
}
|
|
90
|
+
write(storage, store);
|
|
91
|
+
}
|
|
@@ -150,6 +150,18 @@
|
|
|
150
150
|
"done": "Bestellung storniert",
|
|
151
151
|
"failed": "Stornierung nicht möglich"
|
|
152
152
|
},
|
|
153
|
+
"pay": {
|
|
154
|
+
"action": "Jetzt bezahlen",
|
|
155
|
+
"title": "Bestellung {number} bezahlen",
|
|
156
|
+
"intro": "Diese Bestellung wartet auf Ihre Zahlung über {amount}.",
|
|
157
|
+
"method": "Zahlungsart",
|
|
158
|
+
"confirm": "{amount} bezahlen",
|
|
159
|
+
"done": "Vielen Dank – die Zahlung ist unterwegs",
|
|
160
|
+
"failed": "Die Zahlung ist nicht durchgegangen",
|
|
161
|
+
"due": "Diese Bestellung wartet auf Ihre Zahlung",
|
|
162
|
+
"unavailable": "Diese Zahlungsart ist für diese Bestellung gerade nicht verfügbar. Bitte kontaktieren Sie uns.",
|
|
163
|
+
"settled": "Diese Bestellung wartet nicht mehr auf eine Zahlung."
|
|
164
|
+
},
|
|
153
165
|
"messages": {
|
|
154
166
|
"title": "Nachrichten zu dieser Bestellung",
|
|
155
167
|
"you": "Sie",
|
|
@@ -741,7 +753,7 @@
|
|
|
741
753
|
"note": "Anmerkung zur Bestellung (optional)",
|
|
742
754
|
"terms": "Mit Ihrer Bestellung gelten unsere AGB.",
|
|
743
755
|
"cancel": "Abbrechen",
|
|
744
|
-
"submit": "
|
|
756
|
+
"submit": "Zahlungspflichtig bestellen",
|
|
745
757
|
"success": "Bestellung {number} aufgegeben",
|
|
746
758
|
"failed": "Bestellung fehlgeschlagen"
|
|
747
759
|
},
|
|
@@ -191,6 +191,7 @@
|
|
|
191
191
|
"page": {
|
|
192
192
|
"title": "Warenkörbe",
|
|
193
193
|
"description": "Alle Warenkörbe, die Sie gerade befüllen — wechseln, umbenennen oder löschen Sie sie hier.",
|
|
194
|
+
"positionsCount": "{count} Position | {count} Positionen",
|
|
194
195
|
"searchPlaceholder": "Nach Name suchen …",
|
|
195
196
|
"columns": {
|
|
196
197
|
"name": "Name",
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
"promoCode": "Aktionscode",
|
|
149
149
|
"promoCodePlaceholder": "Aktionscode",
|
|
150
150
|
"applyPromo": "Einlösen",
|
|
151
|
-
"placeOrder": "
|
|
151
|
+
"placeOrder": "Zahlungspflichtig bestellen",
|
|
152
152
|
"backToCart": "Zurück zum Warenkorb",
|
|
153
153
|
"termsText": "Ich akzeptiere die {link}",
|
|
154
154
|
"termsLink": "AGB und Datenschutzbestimmungen",
|
|
@@ -101,6 +101,13 @@
|
|
|
101
101
|
},
|
|
102
102
|
"table": {
|
|
103
103
|
"filterAll": "Alle",
|
|
104
|
+
"sortBy": "Sortieren nach",
|
|
105
|
+
"sortAsc": "{column} (A–Z)",
|
|
106
|
+
"sortDesc": "{column} (Z–A)",
|
|
107
|
+
"sortNewest": "{column} (neueste zuerst)",
|
|
108
|
+
"sortOldest": "{column} (älteste zuerst)",
|
|
109
|
+
"sortHigh": "{column} (höchste zuerst)",
|
|
110
|
+
"sortLow": "{column} (niedrigste zuerst)",
|
|
104
111
|
"noResults": {
|
|
105
112
|
"title": "Keine Treffer",
|
|
106
113
|
"description": "Passen Sie Suche oder Filter an, um Ergebnisse zu sehen."
|