@revenexx/cover 0.10.1 → 0.12.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 +4 -0
- package/app/assets/css/cover.css +9 -0
- package/app/components/RevenexxForm.vue +4 -0
- package/app/components/account/AccountSidebar.vue +2 -5
- package/app/components/account/carts/AccountCartsTable.vue +4 -2
- package/app/components/account/dashboard/AccountDashboardKpis.vue +74 -34
- package/app/components/account/dashboard/AccountDashboardQuickActions.vue +24 -6
- package/app/components/account/organization/AccountOrganization.vue +3 -1
- package/app/components/account/team/AccountTeam.vue +32 -7
- package/app/components/auth/AuthForgotPasswordPanel.vue +9 -4
- package/app/components/auth/AuthLoginPanel.vue +75 -18
- package/app/components/auth/AuthRegisterPanel.vue +1 -1
- package/app/components/cart/actions/CartSaveToListModal.vue +5 -0
- package/app/components/cart/item/CartItem.vue +17 -75
- package/app/components/cart/position/CartPosition.vue +17 -30
- package/app/components/cart/quote/CartQuoteRequestModal.vue +9 -1
- package/app/components/cart/switcher/CartSwitcher.vue +5 -2
- package/app/components/category/view/GridView.vue +10 -1
- package/app/components/category/view/ListView.vue +10 -1
- package/app/components/checkout/confirmation/CheckoutConfirmationActions.vue +2 -0
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +4 -4
- package/app/components/checkout/onepage/CheckoutDeliverySection.vue +18 -2
- package/app/components/checkout/onepage/CheckoutGate.vue +2 -0
- package/app/components/checkout/onepage/CheckoutOnePageView.vue +1 -1
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +10 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +7 -1
- package/app/components/layout/Region.vue +13 -0
- package/app/components/layout/footer/Footer.vue +8 -0
- package/app/components/layout/header/AppBar.vue +4 -3
- package/app/components/layout/header/MainNav.vue +3 -3
- package/app/components/listing/ListingResults.vue +3 -1
- package/app/components/product/card/Compact.vue +10 -1
- package/app/components/product/detail/ProductDetailAddToCart.vue +51 -18
- package/app/components/product/detail/ProductDetailIdentity.vue +1 -1
- package/app/components/product/detail/ProductDetailPriceRequest.vue +1 -1
- package/app/components/product/detail/ProductDetailSaveToList.vue +10 -0
- package/app/composables/useAccountDashboard.ts +0 -10
- package/app/composables/useAccountNavigation.ts +35 -0
- package/app/composables/useAuthStore.ts +6 -2
- package/app/composables/useCategoryListing.ts +6 -0
- package/app/composables/useCheckoutOnePage.ts +21 -2
- package/app/composables/useMasterDataEditable.ts +23 -0
- package/app/composables/useProductCard.ts +29 -2
- package/app/composables/useProductListing.ts +79 -0
- package/app/composables/useQuantityStepper.ts +90 -0
- package/app/composables/useQuickActions.ts +35 -0
- package/app/composables/useRoleGrants.ts +32 -0
- package/app/composables/useSearchListing.ts +4 -0
- package/app/composables/useThemeEvents.ts +144 -0
- package/app/config/accountDashboard.ts +26 -0
- package/app/config/quickActions.ts +40 -5
- package/app/interfaces/account/dashboard.ts +2 -0
- package/app/interfaces/auth.ts +25 -4
- package/app/interfaces/quantity-stepper.ts +17 -0
- package/app/interfaces/shopSettings.ts +84 -0
- package/app/layouts/default.vue +19 -10
- package/app/layouts/focus.vue +28 -7
- package/app/middleware/checkout-guard.ts +7 -1
- package/app/pages/punchout/transfer.vue +22 -0
- package/app/plugins/theme-events.client.ts +132 -0
- package/app/shared/themeEvents.ts +445 -0
- package/i18n/locales/de/account.json +7 -0
- package/i18n/locales/de/auth.json +42 -2
- package/i18n/locales/de/cart.json +4 -2
- package/i18n/locales/de/checkout.json +2 -1
- package/i18n/locales/de/common.json +2 -0
- package/i18n/locales/de/cover.json +44 -0
- package/i18n/locales/de/editor.json +47 -1
- package/i18n/locales/en/account.json +7 -0
- package/i18n/locales/en/auth.json +42 -2
- package/i18n/locales/en/cart.json +4 -2
- package/i18n/locales/en/checkout.json +2 -1
- package/i18n/locales/en/common.json +2 -0
- package/i18n/locales/en/cover.json +44 -0
- package/i18n/locales/en/editor.json +47 -1
- package/nuxt.config.ts +15 -1
- package/package.json +5 -2
- package/server/api/account/orders/[id]/cancel.post.ts +1 -1
- package/server/api/account/orders/[id]/messages.get.ts +1 -1
- package/server/api/account/orders/[id]/messages.post.ts +1 -1
- package/server/api/account/orders/[id]/return.post.ts +1 -0
- package/server/api/account/orders/[id].get.ts +1 -1
- package/server/api/account/pending-approvals/index.get.ts +1 -0
- package/server/api/account/profile.get.ts +3 -1
- package/server/api/auth/login.post.ts +22 -3
- package/server/api/auth/magic-link.put.ts +6 -1
- package/server/api/auth/otp.put.ts +6 -1
- package/server/api/carts/[id]/activate.post.ts +8 -0
- package/server/api/carts/[id]/index.delete.ts +3 -0
- package/server/api/carts/[id]/index.put.ts +1 -0
- package/server/api/carts/[id]/items.post.ts +1 -0
- package/server/api/carts/index.post.ts +4 -0
- package/server/api/orders/index.post.ts +33 -0
- package/server/api/quick-actions.get.ts +6 -38
- package/server/interfaces/auth.ts +10 -1
- package/server/middleware/buyer-principal.ts +18 -0
- package/server/routes/punchout/start.get.ts +6 -15
- package/server/services/ApiAddressBookService.ts +43 -1
- package/server/services/ApiAuthService.ts +119 -22
- package/server/services/ApiCartService.ts +67 -32
- package/server/services/ApiOrganizationService.ts +7 -2
- package/server/services/ApiTeamService.ts +93 -21
- package/server/services/MockAuthService.ts +21 -2
- package/server/utils/buyerIdentity.ts +168 -0
- package/server/utils/cartOwnership.ts +67 -0
- package/server/utils/liveOrderLists.ts +50 -23
- package/server/utils/liveOrders.ts +39 -24
- package/server/utils/livePrices.ts +7 -15
- package/server/utils/masterData.ts +29 -0
- package/server/utils/passwordlessSignIn.ts +13 -4
- package/server/utils/pendingApprovals.ts +29 -7
- package/server/utils/procurementCheckout.ts +2 -0
- package/server/utils/quickActionCatalogue.ts +53 -0
- package/server/utils/revenexxSdk.ts +116 -2
- package/server/utils/shopSettings.ts +5 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { AuthMethod } from "@revenexx/tag-manager-nuxt/events";
|
|
2
|
+
import type { RouteLocationNormalized } from "vue-router";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
browserSession,
|
|
6
|
+
cartEcommerce,
|
|
7
|
+
itemsValue,
|
|
8
|
+
pageTypeOf,
|
|
9
|
+
takePurchase,
|
|
10
|
+
trackCartChanges,
|
|
11
|
+
} from "../shared/themeEvents";
|
|
12
|
+
|
|
13
|
+
/** How long a cart-dependent page event waits for the cart to be restored. */
|
|
14
|
+
const CART_READY_WAIT_MS = 3000;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The theme events no single component owns (RAD-178).
|
|
18
|
+
*
|
|
19
|
+
* - `page_view`: pages are blökkli-authored, so the router is the only uniform
|
|
20
|
+
* point. Once per path — a query change (a filter, a page of results) is the
|
|
21
|
+
* same page.
|
|
22
|
+
* - `view_cart`, `begin_checkout`, `purchase`: by the page reached, so every
|
|
23
|
+
* theme on this layer reports them whichever pages it ships (the blökkli
|
|
24
|
+
* theme, the custom theme and the demo shop each have their own).
|
|
25
|
+
* - `add_to_cart` / `remove_from_cart`: read off the cart store's actions, so
|
|
26
|
+
* every add-to-cart button in the design system reports without knowing it,
|
|
27
|
+
* and only an add the store accepted counts.
|
|
28
|
+
* - `login` / `sign_up`: read off the auth store's actions, once they resolved.
|
|
29
|
+
*
|
|
30
|
+
* Editor and preview contexts emit nothing (`useThemeEvents`).
|
|
31
|
+
*/
|
|
32
|
+
export default defineNuxtPlugin({
|
|
33
|
+
name: "cover:theme-events",
|
|
34
|
+
setup(nuxtApp) {
|
|
35
|
+
const events = useThemeEvents();
|
|
36
|
+
const router = useRouter();
|
|
37
|
+
const cart = useCartStore();
|
|
38
|
+
const auth = useAuthStore();
|
|
39
|
+
|
|
40
|
+
/* ---- the cart is restored asynchronously ----------------------------- */
|
|
41
|
+
// auth-init restores the cart from the server after the session check; a
|
|
42
|
+
// cart page reached on a hard load would otherwise report an empty cart.
|
|
43
|
+
let markCartReady: () => void = () => {};
|
|
44
|
+
const cartReady = new Promise<void>((resolve) => {
|
|
45
|
+
markCartReady = resolve;
|
|
46
|
+
setTimeout(resolve, CART_READY_WAIT_MS);
|
|
47
|
+
});
|
|
48
|
+
cart.$onAction(({ name, after, onError }) => {
|
|
49
|
+
if (name === "initFromServer") {
|
|
50
|
+
after(() => markCartReady());
|
|
51
|
+
onError(() => markCartReady());
|
|
52
|
+
}
|
|
53
|
+
}, true);
|
|
54
|
+
|
|
55
|
+
/* ---- per page ------------------------------------------------------- */
|
|
56
|
+
const localeCodes = (): string[] => {
|
|
57
|
+
const locales = (nuxtApp.$i18n as { locales?: { value: ({ code: string } | string)[] } } | undefined)?.locales?.value ?? [];
|
|
58
|
+
return locales.map(l => (typeof l === "string" ? l : l.code));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
async function pageEvents(to: RouteLocationNormalized): Promise<void> {
|
|
62
|
+
const type = pageTypeOf(to.path, localeCodes());
|
|
63
|
+
if (type === "cart") {
|
|
64
|
+
await cartReady;
|
|
65
|
+
events.emit("view_cart", { ecommerce: cartEcommerce(cart.items) });
|
|
66
|
+
}
|
|
67
|
+
else if (type === "checkout") {
|
|
68
|
+
await cartReady;
|
|
69
|
+
if (cart.items.length) {
|
|
70
|
+
events.emit("begin_checkout", { ecommerce: cartEcommerce(cart.items) });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (type === "confirmation") {
|
|
74
|
+
purchase(to);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One `purchase` per order, on the confirmation page. Not for an approval
|
|
80
|
+
* request or a requisition — nothing was bought yet. The order id IS the
|
|
81
|
+
* event id, so the emitter drops a reload of the same confirmation.
|
|
82
|
+
*/
|
|
83
|
+
function purchase(to: RouteLocationNormalized): void {
|
|
84
|
+
const id = typeof to.query.id === "string" ? to.query.id.trim() : "";
|
|
85
|
+
const kind = typeof to.query.type === "string" ? to.query.type : "order";
|
|
86
|
+
if (!id || kind !== "order") {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const placed = takePurchase(browserSession());
|
|
90
|
+
if (!placed?.items?.length) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
events.emit("purchase", { ecommerce: { ...placed, transaction_id: id.slice(0, 128) } });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let lastPath: string | null = null;
|
|
97
|
+
const onPage = (to: RouteLocationNormalized) => {
|
|
98
|
+
if (to.path === lastPath) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
lastPath = to.path;
|
|
102
|
+
events.emit("page_view");
|
|
103
|
+
void pageEvents(to);
|
|
104
|
+
};
|
|
105
|
+
// The first page once the app is mounted; every later one after its navigation.
|
|
106
|
+
nuxtApp.hook("app:mounted", () => onPage(router.currentRoute.value));
|
|
107
|
+
router.afterEach((to, _from, failure) => {
|
|
108
|
+
if (!failure && nuxtApp.isHydrating !== true) {
|
|
109
|
+
onPage(to);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/* ---- cart ----------------------------------------------------------- */
|
|
114
|
+
trackCartChanges(cart, (event, items) => {
|
|
115
|
+
events.emit(event, { ecommerce: { items, ...itemsValue(items) } });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/* ---- signing in ----------------------------------------------------- */
|
|
119
|
+
auth.$onAction(({ name, args, after }) => {
|
|
120
|
+
if (name === "login") {
|
|
121
|
+
after(() => events.emit("login", { auth: { method: "password" } }));
|
|
122
|
+
}
|
|
123
|
+
else if (name === "confirmSignInMail") {
|
|
124
|
+
const method: AuthMethod = args[0] === "otp" ? "otp" : "magic_link";
|
|
125
|
+
after(() => events.emit("login", { auth: { method } }));
|
|
126
|
+
}
|
|
127
|
+
else if (name === "register") {
|
|
128
|
+
after(() => events.emit("sign_up", { auth: { method: "password" } }));
|
|
129
|
+
}
|
|
130
|
+
}, true);
|
|
131
|
+
},
|
|
132
|
+
});
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The theme event contract (`theme-events/1`) as cover speaks it.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is pure: no Nuxt, no Vue, no store. It turns what the shop
|
|
5
|
+
* holds — cart lines, listing hits, a route — into what the contract allows, so
|
|
6
|
+
* the rules (net and gross, "on request" is null and never 0, which page is
|
|
7
|
+
* which, where nothing may be emitted) are decided once and unit-tested
|
|
8
|
+
* without an application around them. `useThemeEvents()` stamps the
|
|
9
|
+
* context and sends; the plugin and the components only say what happened.
|
|
10
|
+
*
|
|
11
|
+
* Never put anything about the visitor in here beyond the two booleans the
|
|
12
|
+
* envelope carries. The contract closes every object, so a forbidden field is
|
|
13
|
+
* dropped by validation in dev — but the place to not send it is here.
|
|
14
|
+
*/
|
|
15
|
+
import type {
|
|
16
|
+
PageType,
|
|
17
|
+
ThemeEventEcommerce,
|
|
18
|
+
ThemeEventItem,
|
|
19
|
+
} from "@revenexx/tag-manager-nuxt/events";
|
|
20
|
+
|
|
21
|
+
import type { CartItem } from "../interfaces/cart-item";
|
|
22
|
+
import type { ProductList } from "../interfaces/product-list";
|
|
23
|
+
|
|
24
|
+
/** The cart store's own fallback rate (`TAX_RATE`), as a percentage. */
|
|
25
|
+
const DEFAULT_TAX_PERCENT = 19;
|
|
26
|
+
|
|
27
|
+
/** Path prefixes of the editor and the preview — nothing is ever emitted there. */
|
|
28
|
+
const EDITOR_PATH_PREFIXES = ["/admin", "/preview"];
|
|
29
|
+
|
|
30
|
+
/** Hosts the theme editor renders on. */
|
|
31
|
+
const EDITOR_HOST_SUFFIX = ".theme.rvnxx.site";
|
|
32
|
+
|
|
33
|
+
const round2 = (n: number): number => Math.round(n * 100) / 100;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A unit price the contract can carry: a positive finite amount, rounded to
|
|
37
|
+
* cents — or `null`. Zero is "on request" in this shop (the prices app answers
|
|
38
|
+
* on_request rather than 0), and a tag must never report a free article.
|
|
39
|
+
*/
|
|
40
|
+
export function eventPrice(value: unknown): number | null {
|
|
41
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? round2(value) : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A tax rate as a fraction, accepting both 19 and 0.19. */
|
|
45
|
+
function taxFraction(rate: unknown): number {
|
|
46
|
+
const raw = typeof rate === "number" && Number.isFinite(rate) && rate >= 0 ? rate : DEFAULT_TAX_PERCENT;
|
|
47
|
+
return raw > 1 ? raw / 100 : raw;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Net and gross from the one price the shop holds. Cart lines and listing
|
|
52
|
+
* offers carry the NET unit price — the cart store taxes it on top, and
|
|
53
|
+
* displays it with tax only where the market quotes gross — so gross is
|
|
54
|
+
* derived, never read.
|
|
55
|
+
*/
|
|
56
|
+
export function netAndGross(net: number | null, taxRate: unknown): { price_net: number | null; price_gross: number | null } {
|
|
57
|
+
if (net === null) {
|
|
58
|
+
return { price_net: null, price_gross: null };
|
|
59
|
+
}
|
|
60
|
+
return { price_net: net, price_gross: round2(net * (1 + taxFraction(taxRate))) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Anything shaped like a cart line: a cart item, an order-list position, a
|
|
65
|
+
* quote request position. Only what an event may carry is read.
|
|
66
|
+
*/
|
|
67
|
+
export type LineLike = Pick<CartItem, "id" | "sku" | "name" | "price" | "quantity">
|
|
68
|
+
& Partial<Pick<CartItem, "name2" | "taxRate" | "priceTiers">>;
|
|
69
|
+
|
|
70
|
+
/** The unit price a line pays at its quantity — the cart store's tier rule. */
|
|
71
|
+
export function lineUnitPrice(item: Pick<LineLike, "price" | "priceTiers" | "quantity">): number {
|
|
72
|
+
let price = item.price;
|
|
73
|
+
for (const tier of item.priceTiers ?? []) {
|
|
74
|
+
if (item.quantity >= tier.minQuantity) {
|
|
75
|
+
price = tier.unitPrice;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return price;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A cart line as a contract item. `quantity` overrides the line's own (a delta). */
|
|
85
|
+
export function cartLineToItem(item: LineLike, quantity: number = item.quantity): ThemeEventItem {
|
|
86
|
+
const { price_net, price_gross } = netAndGross(eventPrice(lineUnitPrice(item)), item.taxRate);
|
|
87
|
+
return {
|
|
88
|
+
sku: item.sku || String(item.id),
|
|
89
|
+
name: item.name || item.sku || String(item.id),
|
|
90
|
+
...(item.name2 ? { variant: item.name2.slice(0, 128) } : {}),
|
|
91
|
+
price_net,
|
|
92
|
+
price_gross,
|
|
93
|
+
quantity,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The unit price of the first tier of a listing offer (`{ "1": cents }`), in currency units. */
|
|
98
|
+
export function offerUnitPrice(prices: { [key: string]: number }[] | undefined): number | null {
|
|
99
|
+
const map = prices?.[0];
|
|
100
|
+
if (!map) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const tiers = Object.entries(map)
|
|
104
|
+
.map(([q, cents]) => ({ q: Number.parseInt(q, 10), cents: Number(cents) }))
|
|
105
|
+
.filter(t => Number.isFinite(t.q) && t.q > 0 && Number.isFinite(t.cents))
|
|
106
|
+
.sort((a, b) => a.q - b.q);
|
|
107
|
+
const first = tiers[0];
|
|
108
|
+
return first ? eventPrice(first.cents / first.q / 100) : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A listing hit as a contract item, priced from its offer when one has arrived. */
|
|
112
|
+
export function listingProductToItem(
|
|
113
|
+
product: ProductList,
|
|
114
|
+
options: { position?: number; listId?: string; prices?: { [key: string]: number }[] } = {},
|
|
115
|
+
): ThemeEventItem {
|
|
116
|
+
const net = offerUnitPrice(options.prices ?? product.prices);
|
|
117
|
+
const categoryPath = [product.category, product.subcategory]
|
|
118
|
+
.filter((c): c is string => typeof c === "string" && c.trim().length > 0)
|
|
119
|
+
.map(c => c.slice(0, 128));
|
|
120
|
+
return {
|
|
121
|
+
sku: product.sku || String(product.id),
|
|
122
|
+
name: product.name || product.sku || String(product.id),
|
|
123
|
+
...(categoryPath.length ? { category_path: categoryPath } : {}),
|
|
124
|
+
...netAndGross(net, product.tax?.rate),
|
|
125
|
+
quantity: 1,
|
|
126
|
+
...(options.position && options.position >= 1 ? { list_position: Math.floor(options.position) } : {}),
|
|
127
|
+
...(options.listId ? { list_id: options.listId.slice(0, 128) } : {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Sum of the items' net and gross, or null as soon as one line is on request. */
|
|
132
|
+
export function itemsValue(items: ThemeEventItem[]): Pick<ThemeEventEcommerce, "value_net" | "value_gross"> {
|
|
133
|
+
let net = 0;
|
|
134
|
+
let gross = 0;
|
|
135
|
+
for (const item of items) {
|
|
136
|
+
if (item.price_net == null || item.price_gross == null) {
|
|
137
|
+
return { value_net: null, value_gross: null };
|
|
138
|
+
}
|
|
139
|
+
net += item.price_net * item.quantity;
|
|
140
|
+
gross += item.price_gross * item.quantity;
|
|
141
|
+
}
|
|
142
|
+
return { value_net: round2(net), value_gross: round2(gross) };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The `ecommerce` block for a set of cart lines: items plus their value. */
|
|
146
|
+
export function cartEcommerce(lines: readonly LineLike[], extra: Partial<ThemeEventEcommerce> = {}): ThemeEventEcommerce {
|
|
147
|
+
const items = lines.map(line => cartLineToItem(line));
|
|
148
|
+
return { items, ...itemsValue(items), ...extra };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The list id of a category listing, as the contract names it. */
|
|
152
|
+
export function categoryListId(categorySlug: string, subcategorySlug?: string): string {
|
|
153
|
+
return `category:${categorySlug}${subcategorySlug ? `/${subcategorySlug}` : ""}`.slice(0, 128);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* ---- where we are --------------------------------------------------------- */
|
|
157
|
+
|
|
158
|
+
/** The path without a leading locale segment (`/en/cart` → `/cart`). */
|
|
159
|
+
export function stripLocalePrefix(path: string, localeCodes: readonly string[]): string {
|
|
160
|
+
const clean = (path.split(/[?#]/)[0] || "/").replace(/\/+$/, "") || "/";
|
|
161
|
+
const first = clean.split("/")[1] ?? "";
|
|
162
|
+
if (first && localeCodes.includes(first)) {
|
|
163
|
+
return clean.slice(first.length + 1) || "/";
|
|
164
|
+
}
|
|
165
|
+
return clean;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const startsWithSegment = (path: string, prefix: string): boolean =>
|
|
169
|
+
path === prefix || path.startsWith(`${prefix}/`);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* True where the shop is being authored or previewed: the editor and preview
|
|
173
|
+
* routes, a `?blokkliEdit=1` render, and the theme editor's own hosts. The
|
|
174
|
+
* editor seeds sample carts and renders sample products — none of that is a
|
|
175
|
+
* shopper, and none of it may reach a tag.
|
|
176
|
+
*/
|
|
177
|
+
export function isEditorContext(where: {
|
|
178
|
+
path: string;
|
|
179
|
+
host?: string;
|
|
180
|
+
query?: Record<string, unknown>;
|
|
181
|
+
localeCodes?: readonly string[];
|
|
182
|
+
}): boolean {
|
|
183
|
+
if (where.host && where.host.toLowerCase().split(":")[0]!.endsWith(EDITOR_HOST_SUFFIX)) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
const edit = where.query?.blokkliEdit;
|
|
187
|
+
if (edit === "1" || (Array.isArray(edit) && edit.includes("1"))) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
const path = stripLocalePrefix(where.path, where.localeCodes ?? []);
|
|
191
|
+
return EDITOR_PATH_PREFIXES.some(prefix => startsWithSegment(path, prefix));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** What kind of page a path is, in the contract's vocabulary. */
|
|
195
|
+
export function pageTypeOf(fullPath: string, localeCodes: readonly string[] = []): PageType {
|
|
196
|
+
const path = stripLocalePrefix(fullPath, localeCodes);
|
|
197
|
+
if (path === "/") {
|
|
198
|
+
return "home";
|
|
199
|
+
}
|
|
200
|
+
if (startsWithSegment(path, "/category")) {
|
|
201
|
+
return path.split("/").includes("product") ? "product" : "category";
|
|
202
|
+
}
|
|
203
|
+
const rules: [string, PageType][] = [
|
|
204
|
+
["/search", "search"],
|
|
205
|
+
["/cart", "cart"],
|
|
206
|
+
["/checkout/confirmation", "confirmation"],
|
|
207
|
+
["/checkout", "checkout"],
|
|
208
|
+
["/account/quotes", "quote"],
|
|
209
|
+
["/account/order-lists", "orderlist"],
|
|
210
|
+
["/account", "account"],
|
|
211
|
+
["/punchout", "punchout"],
|
|
212
|
+
["/login", "login"],
|
|
213
|
+
["/register", "register"],
|
|
214
|
+
];
|
|
215
|
+
return rules.find(([prefix]) => startsWithSegment(path, prefix))?.[1] ?? "content";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* ---- the cart, read as a series of changes -------------------------------- */
|
|
219
|
+
|
|
220
|
+
/** One line's quantity, keyed the way the cart store keys lines. */
|
|
221
|
+
export interface LineSnapshot {
|
|
222
|
+
key: string;
|
|
223
|
+
quantity: number;
|
|
224
|
+
line: CartItem;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export const lineKeyOf = (item: CartItem): string => item.lineKey ?? `id-${item.id}`;
|
|
228
|
+
|
|
229
|
+
export function snapshotLines(items: readonly CartItem[]): Map<string, LineSnapshot> {
|
|
230
|
+
return new Map(items.map(item => [lineKeyOf(item), { key: lineKeyOf(item), quantity: item.quantity, line: { ...item } }]));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* What changed between two readings of the cart, line by line: quantity that
|
|
235
|
+
* arrived and quantity that left. A line that vanished left whole; a new one
|
|
236
|
+
* arrived whole. Prices are the line's own at the moment it was read.
|
|
237
|
+
*/
|
|
238
|
+
export function diffLines(
|
|
239
|
+
before: Map<string, LineSnapshot>,
|
|
240
|
+
after: Map<string, LineSnapshot>,
|
|
241
|
+
): { added: ThemeEventItem[]; removed: ThemeEventItem[] } {
|
|
242
|
+
const added: ThemeEventItem[] = [];
|
|
243
|
+
const removed: ThemeEventItem[] = [];
|
|
244
|
+
for (const [key, now] of after) {
|
|
245
|
+
const delta = now.quantity - (before.get(key)?.quantity ?? 0);
|
|
246
|
+
if (delta > 0) {
|
|
247
|
+
added.push(cartLineToItem(now.line, delta));
|
|
248
|
+
}
|
|
249
|
+
else if (delta < 0) {
|
|
250
|
+
removed.push(cartLineToItem(now.line, -delta));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const [key, was] of before) {
|
|
254
|
+
if (!after.has(key) && was.quantity > 0) {
|
|
255
|
+
removed.push(cartLineToItem(was.line, was.quantity));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return { added, removed };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** The cart store actions whose effect is reported, and which way. */
|
|
262
|
+
export const CART_ADD_ACTIONS = ["addItem"] as const;
|
|
263
|
+
export const CART_CHANGE_ACTIONS = ["removeItem", "updateQuantity", "removeByKeys", "updateQuantityByKey"] as const;
|
|
264
|
+
|
|
265
|
+
interface CartLike {
|
|
266
|
+
items: CartItem[];
|
|
267
|
+
$onAction(callback: (context: {
|
|
268
|
+
name: string;
|
|
269
|
+
after: (cb: (result: unknown) => void) => void;
|
|
270
|
+
}) => void, detached?: boolean): () => void;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Report what the buyer did to their cart.
|
|
275
|
+
*
|
|
276
|
+
* - `add_to_cart` only for an add the store ACCEPTED: `addItem` returns false
|
|
277
|
+
* for a read-only punchout cart, a line at its ceiling or a full cart, and a
|
|
278
|
+
* refused add is not an add.
|
|
279
|
+
* - Raising a quantity is an add of the difference, lowering it a removal.
|
|
280
|
+
* - `clearCart` is never a removal: it runs after an order, a quote, a login and
|
|
281
|
+
* a logout, none of which is a buyer taking something out.
|
|
282
|
+
* - Changes made in one go (the product page adds one and then sets the
|
|
283
|
+
* quantity) are coalesced into one event per direction.
|
|
284
|
+
*
|
|
285
|
+
* Returns the unsubscribe function.
|
|
286
|
+
*/
|
|
287
|
+
export function trackCartChanges(
|
|
288
|
+
cart: CartLike,
|
|
289
|
+
report: (event: "add_to_cart" | "remove_from_cart", items: ThemeEventItem[]) => void,
|
|
290
|
+
options: { schedule?: (flush: () => void) => void } = {},
|
|
291
|
+
): () => void {
|
|
292
|
+
const schedule = options.schedule ?? ((flush: () => void) => { void Promise.resolve().then(flush); });
|
|
293
|
+
let pendingAdded: ThemeEventItem[] = [];
|
|
294
|
+
let pendingRemoved: ThemeEventItem[] = [];
|
|
295
|
+
let scheduled = false;
|
|
296
|
+
|
|
297
|
+
const merge = (into: ThemeEventItem[], items: ThemeEventItem[]): ThemeEventItem[] => {
|
|
298
|
+
const out = [...into];
|
|
299
|
+
for (const item of items) {
|
|
300
|
+
const same = out.find(o => o.sku === item.sku && o.price_net === item.price_net && o.variant === item.variant);
|
|
301
|
+
if (same) {
|
|
302
|
+
same.quantity += item.quantity;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
out.push({ ...item });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const flush = () => {
|
|
312
|
+
scheduled = false;
|
|
313
|
+
const added = pendingAdded;
|
|
314
|
+
const removed = pendingRemoved;
|
|
315
|
+
pendingAdded = [];
|
|
316
|
+
pendingRemoved = [];
|
|
317
|
+
if (added.length) {
|
|
318
|
+
report("add_to_cart", added);
|
|
319
|
+
}
|
|
320
|
+
if (removed.length) {
|
|
321
|
+
report("remove_from_cart", removed);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const queue = (added: ThemeEventItem[], removed: ThemeEventItem[]) => {
|
|
326
|
+
if (!added.length && !removed.length) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
pendingAdded = merge(pendingAdded, added);
|
|
330
|
+
pendingRemoved = merge(pendingRemoved, removed);
|
|
331
|
+
if (!scheduled) {
|
|
332
|
+
scheduled = true;
|
|
333
|
+
schedule(flush);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
return cart.$onAction(({ name, after }) => {
|
|
338
|
+
const isAdd = (CART_ADD_ACTIONS as readonly string[]).includes(name);
|
|
339
|
+
const isChange = (CART_CHANGE_ACTIONS as readonly string[]).includes(name);
|
|
340
|
+
if (!isAdd && !isChange) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const before = snapshotLines(cart.items);
|
|
344
|
+
after((result) => {
|
|
345
|
+
// addItem answers whether the cart took the article. Anything but a
|
|
346
|
+
// plain `true` is a refusal, and a refusal reports nothing.
|
|
347
|
+
if (isAdd && result !== true) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const { added, removed } = diffLines(before, snapshotLines(cart.items));
|
|
351
|
+
queue(added, isAdd ? [] : removed);
|
|
352
|
+
});
|
|
353
|
+
}, true);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/* ---- the order, from the checkout to the confirmation --------------------- */
|
|
357
|
+
|
|
358
|
+
const PURCHASE_STASH_KEY = "rvx_se_checkout";
|
|
359
|
+
const PURCHASE_STASH_TTL_MS = 60 * 60 * 1000;
|
|
360
|
+
|
|
361
|
+
export interface PurchaseSnapshot {
|
|
362
|
+
ecommerce: Omit<ThemeEventEcommerce, "transaction_id">;
|
|
363
|
+
at: number;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
interface StorageLike {
|
|
367
|
+
getItem(key: string): string | null;
|
|
368
|
+
setItem(key: string, value: string): void;
|
|
369
|
+
removeItem(key: string): void;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Totals rows the cart calculation answers with, as far as a purchase needs them. */
|
|
373
|
+
interface TotalsRow {
|
|
374
|
+
key: string;
|
|
375
|
+
amount: number;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* The order as it is about to be placed: the lines and the money, read from
|
|
380
|
+
* the cart and its server calculation BEFORE the cart is cleared. Values fall
|
|
381
|
+
* back to the cart's own arithmetic where no calculation has arrived.
|
|
382
|
+
*/
|
|
383
|
+
export function purchaseFromCart(
|
|
384
|
+
lines: CartItem[],
|
|
385
|
+
totals: TotalsRow[] | null | undefined,
|
|
386
|
+
fallback: { subtotal: number; tax: number },
|
|
387
|
+
extra: Partial<ThemeEventEcommerce> = {},
|
|
388
|
+
): Omit<ThemeEventEcommerce, "transaction_id"> {
|
|
389
|
+
const items = lines.map(line => cartLineToItem(line));
|
|
390
|
+
const row = (key: string): number | undefined => {
|
|
391
|
+
const found = (totals ?? []).filter(r => r.key === key);
|
|
392
|
+
return found.length ? found.reduce((sum, r) => sum + (Number.isFinite(r.amount) ? r.amount : 0), 0) : undefined;
|
|
393
|
+
};
|
|
394
|
+
const tax = row("tax") ?? fallback.tax;
|
|
395
|
+
const shipping = row("shipping") ?? 0;
|
|
396
|
+
const gross = row("total") ?? fallback.subtotal + fallback.tax;
|
|
397
|
+
const nonNegative = (n: number): number => (Number.isFinite(n) && n > 0 ? round2(n) : 0);
|
|
398
|
+
return {
|
|
399
|
+
items,
|
|
400
|
+
value_net: nonNegative(gross - tax),
|
|
401
|
+
value_gross: nonNegative(gross),
|
|
402
|
+
tax: nonNegative(tax),
|
|
403
|
+
shipping: nonNegative(shipping),
|
|
404
|
+
...extra,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** The tab's sessionStorage, or null where the browser refuses it (private modes, blocked storage). */
|
|
409
|
+
export function browserSession(): StorageLike | null {
|
|
410
|
+
try {
|
|
411
|
+
return (globalThis as { sessionStorage?: StorageLike }).sessionStorage ?? null;
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Keep the order the checkout is about to place, for the confirmation page to report. */
|
|
419
|
+
export function stashPurchase(storage: StorageLike | null | undefined, ecommerce: PurchaseSnapshot["ecommerce"], now = Date.now()): void {
|
|
420
|
+
try {
|
|
421
|
+
storage?.setItem(PURCHASE_STASH_KEY, JSON.stringify({ ecommerce, at: now } satisfies PurchaseSnapshot));
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
// Storage blocked or full: the purchase goes unreported, the order does not.
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** Take the stashed order (once), if it is recent enough to be the one just placed. */
|
|
429
|
+
export function takePurchase(storage: StorageLike | null | undefined, now = Date.now()): PurchaseSnapshot["ecommerce"] | null {
|
|
430
|
+
try {
|
|
431
|
+
const raw = storage?.getItem(PURCHASE_STASH_KEY);
|
|
432
|
+
if (!raw) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
storage?.removeItem(PURCHASE_STASH_KEY);
|
|
436
|
+
const parsed = JSON.parse(raw) as Partial<PurchaseSnapshot>;
|
|
437
|
+
if (!parsed.ecommerce || typeof parsed.at !== "number" || now - parsed.at > PURCHASE_STASH_TTL_MS) {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
return parsed.ecommerce;
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
@@ -580,6 +580,7 @@
|
|
|
580
580
|
"organization": {
|
|
581
581
|
"title": "Firmendaten",
|
|
582
582
|
"locked": "Ihre Firmendaten werden von uns gepflegt. Für eine Änderung wenden Sie sich bitte an Ihren Ansprechpartner.",
|
|
583
|
+
"lockedRole": "Ihre Rolle umfasst nicht das Ändern der Firmendaten. Bitte wenden Sie sich an einen Administrator Ihres Unternehmens.",
|
|
583
584
|
"description": "Daten Ihres Unternehmens ansehen und bearbeiten.",
|
|
584
585
|
"companySection": "Unternehmen",
|
|
585
586
|
"edit": "Bearbeiten",
|
|
@@ -607,6 +608,7 @@
|
|
|
607
608
|
"team": {
|
|
608
609
|
"title": "Benutzer",
|
|
609
610
|
"locked": "Die Benutzer Ihres Unternehmens werden von uns gepflegt. Für einen neuen Zugang wenden Sie sich bitte an Ihren Ansprechpartner.",
|
|
611
|
+
"lockedRole": "Ihre Rolle umfasst nicht die Verwaltung der Benutzer Ihres Unternehmens. Bitte wenden Sie sich an einen Administrator Ihres Unternehmens.",
|
|
610
612
|
"description": "Verwalten Sie die Benutzer Ihres Unternehmens und deren Rollen.",
|
|
611
613
|
"searchPlaceholder": "Nach Name, E-Mail oder Rolle suchen …",
|
|
612
614
|
"invite": "Benutzer einladen",
|
|
@@ -619,6 +621,11 @@
|
|
|
619
621
|
"cancel": "Abbrechen",
|
|
620
622
|
"saved": "Gespeichert",
|
|
621
623
|
"saveError": "Speichern fehlgeschlagen",
|
|
624
|
+
"refused": {
|
|
625
|
+
"roleAboveOwn": "Sie können niemandem eine Rolle über Ihrer eigenen geben.",
|
|
626
|
+
"ownRole": "Ihre eigene Rolle kann hier nicht geändert werden.",
|
|
627
|
+
"notFound": "Dieser Benutzer gehört nicht zu Ihrem Unternehmen."
|
|
628
|
+
},
|
|
622
629
|
"errorTitle": "Benutzer nicht verfügbar",
|
|
623
630
|
"errorDescription": "Die Benutzer konnten nicht geladen werden.",
|
|
624
631
|
"columns": {
|
|
@@ -99,10 +99,17 @@
|
|
|
99
99
|
"errors": {
|
|
100
100
|
"invalidCredentials": "E-Mail oder Passwort ist falsch.",
|
|
101
101
|
"accountBlocked": "Dieses Konto wurde gesperrt. Bitte wenden Sie sich an den Support.",
|
|
102
|
+
"organizationBlocked": "Ihr Unternehmen ist für diesen Shop gesperrt. Bitte wenden Sie sich an Ihren Ansprechpartner beim Händler.",
|
|
102
103
|
"rateLimited": "Zu viele Versuche. Bitte versuchen Sie es in ein paar Minuten erneut.",
|
|
103
104
|
"network": "Server nicht erreichbar. Bitte prüfen Sie Ihre Verbindung und versuchen Sie es erneut.",
|
|
104
105
|
"sessionExists": "Sie sind bereits angemeldet.",
|
|
105
|
-
"unknown": "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
|
|
106
|
+
"unknown": "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut.",
|
|
107
|
+
"identifierNotOffered": "Diese Angabe nimmt der Shop zur Anmeldung nicht an. Bitte melden Sie sich mit {accepted} an.",
|
|
108
|
+
"invalidCredentialsBy": {
|
|
109
|
+
"email": "E-Mail oder Passwort ist falsch.",
|
|
110
|
+
"username": "Benutzername oder Passwort ist falsch.",
|
|
111
|
+
"customerNumber": "Kundennummer oder Passwort ist falsch. Mit der Kundennummer melden Sie sich als Hauptansprechpartner Ihres Unternehmens an — mit dessen Passwort."
|
|
112
|
+
}
|
|
106
113
|
},
|
|
107
114
|
"heroTitle": "Kundenportal + Shop + Digitale Services =",
|
|
108
115
|
"heroHighlight": "Ein Konto.",
|
|
@@ -130,7 +137,40 @@
|
|
|
130
137
|
"existingCustomer": "Ich habe bereits ein Konto",
|
|
131
138
|
"newCustomer": "Ich bin Neukunde",
|
|
132
139
|
"newCustomerText": "Registrieren Sie sich für Ihren persönlichen Zugang zu Preisen, Bestellungen und digitalen Services.",
|
|
133
|
-
"registerCta": "Jetzt Kunde werden"
|
|
140
|
+
"registerCta": "Jetzt Kunde werden",
|
|
141
|
+
"identifier": {
|
|
142
|
+
"email": {
|
|
143
|
+
"label": "E-Mail-Adresse",
|
|
144
|
+
"placeholder": "Ihre E-Mail-Adresse"
|
|
145
|
+
},
|
|
146
|
+
"username": {
|
|
147
|
+
"label": "Benutzername",
|
|
148
|
+
"placeholder": "Ihr Benutzername"
|
|
149
|
+
},
|
|
150
|
+
"customerNumber": {
|
|
151
|
+
"label": "Kundennummer",
|
|
152
|
+
"placeholder": "Ihre Kundennummer"
|
|
153
|
+
},
|
|
154
|
+
"email_username": {
|
|
155
|
+
"label": "E-Mail oder Benutzername",
|
|
156
|
+
"placeholder": "E-Mail-Adresse oder Benutzername"
|
|
157
|
+
},
|
|
158
|
+
"email_customerNumber": {
|
|
159
|
+
"label": "E-Mail oder Kundennummer",
|
|
160
|
+
"placeholder": "E-Mail-Adresse oder Kundennummer"
|
|
161
|
+
},
|
|
162
|
+
"username_customerNumber": {
|
|
163
|
+
"label": "Benutzername oder Kundennummer",
|
|
164
|
+
"placeholder": "Benutzername oder Kundennummer"
|
|
165
|
+
},
|
|
166
|
+
"email_username_customerNumber": {
|
|
167
|
+
"label": "E-Mail, Benutzername oder Kundennummer",
|
|
168
|
+
"placeholder": "E-Mail-Adresse, Benutzername oder Kundennummer"
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"identifierHelp": {
|
|
172
|
+
"customerNumber": "Mit der Kundennummer melden Sie sich als Hauptansprechpartner Ihres Unternehmens an."
|
|
173
|
+
}
|
|
134
174
|
},
|
|
135
175
|
"currentPassword": {
|
|
136
176
|
"fields": {
|
|
@@ -135,7 +135,8 @@
|
|
|
135
135
|
"skuPlaceholder": "z. B. NK-G42…",
|
|
136
136
|
"quantityLabel": "Menge",
|
|
137
137
|
"add": "Hinzufügen",
|
|
138
|
-
"added": "{quantity}× {name} hinzugefügt"
|
|
138
|
+
"added": "{quantity}× {name} hinzugefügt",
|
|
139
|
+
"notFound": "Artikel {sku} ist nicht bestellbar."
|
|
139
140
|
},
|
|
140
141
|
"quickOrder": {
|
|
141
142
|
"title": "Schnell zur Bestellung",
|
|
@@ -202,7 +203,8 @@
|
|
|
202
203
|
"title": "Nur der aktive Warenkorb",
|
|
203
204
|
"description": "Legen Sie weitere Warenkörbe über „Neuer Warenkorb“ an — z. B. je Projekt oder Kostenstelle."
|
|
204
205
|
},
|
|
205
|
-
"disabled": "Mehrere Warenkörbe sind für Ihre Organisation nicht aktiviert."
|
|
206
|
+
"disabled": "Mehrere Warenkörbe sind für Ihre Organisation nicht aktiviert.",
|
|
207
|
+
"punchout": "Bei einem Punchout-Besuch arbeiten Sie in dem einen Warenkorb, den Ihr Beschaffungssystem erhält."
|
|
206
208
|
}
|
|
207
209
|
},
|
|
208
210
|
"boost": {
|