@revenexx/cover 0.7.1 → 0.11.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.
Files changed (175) hide show
  1. package/app/api/account.ts +4 -0
  2. package/app/api/forms.ts +1 -0
  3. package/app/app.config.ts +17 -12
  4. package/app/assets/css/cover.css +9 -0
  5. package/app/components/RevenexxForm.vue +84 -12
  6. package/app/components/account/AccountShell.vue +18 -0
  7. package/app/components/account/AccountSidebar.vue +2 -5
  8. package/app/components/account/approvals/AccountPendingApprovals.vue +178 -0
  9. package/app/components/account/dashboard/AccountDashboardKpis.vue +74 -34
  10. package/app/components/account/dashboard/AccountDashboardQuickActions.vue +24 -6
  11. package/app/components/account/orderlists/AccountOrderListDetail.vue +47 -4
  12. package/app/components/account/orders/AccountOrderDetail.vue +186 -1
  13. package/app/components/account/organization/AccountOrganization.vue +3 -1
  14. package/app/components/account/payments/AccountPayments.vue +129 -0
  15. package/app/components/account/quotes/AccountQuoteDetail.vue +48 -16
  16. package/app/components/account/team/AccountTeam.vue +32 -7
  17. package/app/components/auth/AuthForgotPasswordPanel.vue +9 -4
  18. package/app/components/auth/AuthLoginPanel.vue +136 -18
  19. package/app/components/auth/AuthMagicLinkPanel.vue +70 -0
  20. package/app/components/cart/actions/CartSaveToListModal.vue +5 -0
  21. package/app/components/cart/item/CartItem.vue +17 -75
  22. package/app/components/cart/position/CartPosition.vue +17 -30
  23. package/app/components/cart/quote/CartQuoteRequestModal.vue +9 -1
  24. package/app/components/cart/view/CartSummaryPanel.vue +54 -0
  25. package/app/components/category/view/GridView.vue +10 -1
  26. package/app/components/category/view/ListView.vue +10 -1
  27. package/app/components/checkout/confirmation/CheckoutConfirmationActions.vue +2 -0
  28. package/app/components/checkout/onepage/CheckoutAddressSection.vue +4 -4
  29. package/app/components/checkout/onepage/CheckoutDeliverySection.vue +31 -3
  30. package/app/components/checkout/onepage/CheckoutGate.vue +10 -7
  31. package/app/components/checkout/onepage/CheckoutOnePageView.vue +1 -1
  32. package/app/components/checkout/onepage/CheckoutPaymentSection.vue +10 -0
  33. package/app/components/checkout/onepage/CheckoutSummarySection.vue +7 -1
  34. package/app/components/form/FormPage.vue +40 -0
  35. package/app/components/layout/Region.vue +13 -0
  36. package/app/components/layout/footer/Footer.vue +8 -0
  37. package/app/components/layout/header/AppBar.vue +11 -4
  38. package/app/components/layout/header/MainNav.vue +26 -4
  39. package/app/components/layout/header/MobileMenu.vue +12 -0
  40. package/app/components/listing/ListingResults.vue +3 -1
  41. package/app/components/product/card/Compact.vue +10 -1
  42. package/app/components/product/detail/ProductDetailAddToCart.vue +51 -18
  43. package/app/components/product/detail/ProductDetailIdentity.vue +1 -1
  44. package/app/components/product/detail/ProductDetailPriceRequest.vue +39 -0
  45. package/app/components/product/detail/ProductDetailSaveToList.vue +10 -0
  46. package/app/components/product/detail/ProductDetailView.vue +57 -0
  47. package/app/composables/useAccountDashboard.ts +0 -10
  48. package/app/composables/useAccountHold.ts +45 -0
  49. package/app/composables/useAccountNavigation.ts +35 -0
  50. package/app/composables/useAccountPayments.ts +21 -0
  51. package/app/composables/useAccountQuotes.ts +15 -2
  52. package/app/composables/useAuthStore.ts +84 -2
  53. package/app/composables/useAuthoredForms.ts +26 -0
  54. package/app/composables/useAvailableOffers.ts +42 -0
  55. package/app/composables/useCategoryListing.ts +6 -0
  56. package/app/composables/useCheckoutOnePage.ts +21 -2
  57. package/app/composables/useGuestOrdering.ts +28 -0
  58. package/app/composables/useMasterDataEditable.ts +45 -7
  59. package/app/composables/useOrderListRules.ts +21 -1
  60. package/app/composables/usePendingApprovals.ts +37 -0
  61. package/app/composables/useProductCard.ts +29 -2
  62. package/app/composables/useProductListing.ts +79 -0
  63. package/app/composables/useQuantityStepper.ts +90 -0
  64. package/app/composables/useQuickActions.ts +35 -0
  65. package/app/composables/useRoleGrants.ts +32 -0
  66. package/app/composables/useSearchListing.ts +4 -0
  67. package/app/composables/useThemeEvents.ts +144 -0
  68. package/app/config/accountDashboard.ts +26 -0
  69. package/app/config/icons.ts +2 -0
  70. package/app/config/navigation.ts +2 -2
  71. package/app/config/quickActions.ts +40 -5
  72. package/app/formkit.config.ts +14 -0
  73. package/app/interfaces/account/approvals.ts +37 -0
  74. package/app/interfaces/account/dashboard.ts +2 -0
  75. package/app/interfaces/account/order-list.ts +29 -0
  76. package/app/interfaces/account/order-lists.ts +9 -0
  77. package/app/interfaces/account/payments.ts +48 -0
  78. package/app/interfaces/auth.ts +24 -2
  79. package/app/interfaces/b2b.ts +8 -8
  80. package/app/interfaces/offers.ts +35 -0
  81. package/app/interfaces/quantity-stepper.ts +17 -0
  82. package/app/interfaces/shopSettings.ts +77 -0
  83. package/app/layouts/default.vue +19 -10
  84. package/app/layouts/focus.vue +28 -7
  85. package/app/middleware/checkout-guard.ts +7 -1
  86. package/app/pages/punchout/transfer.vue +22 -0
  87. package/app/plugins/account-hold.client.ts +20 -0
  88. package/app/plugins/shop-settings.ts +27 -12
  89. package/app/plugins/theme-events.client.ts +132 -0
  90. package/app/shared/themeEvents.ts +445 -0
  91. package/i18n/locales/de/account.json +87 -0
  92. package/i18n/locales/de/auth.json +30 -0
  93. package/i18n/locales/de/cart.json +9 -1
  94. package/i18n/locales/de/checkout.json +4 -2
  95. package/i18n/locales/de/common.json +4 -0
  96. package/i18n/locales/de/cover.json +44 -0
  97. package/i18n/locales/de/editor.json +47 -1
  98. package/i18n/locales/de/forms.json +27 -0
  99. package/i18n/locales/en/account.json +87 -0
  100. package/i18n/locales/en/auth.json +30 -0
  101. package/i18n/locales/en/cart.json +9 -1
  102. package/i18n/locales/en/checkout.json +4 -2
  103. package/i18n/locales/en/common.json +4 -0
  104. package/i18n/locales/en/cover.json +44 -0
  105. package/i18n/locales/en/editor.json +47 -1
  106. package/i18n/locales/en/forms.json +27 -0
  107. package/nuxt.config.ts +15 -1
  108. package/package.json +6 -2
  109. package/server/api/account/address/[id].delete.ts +1 -1
  110. package/server/api/account/address/[id].put.ts +1 -1
  111. package/server/api/account/address/index.post.ts +1 -1
  112. package/server/api/account/order-lists/[id].get.ts +37 -3
  113. package/server/api/account/orders/[id]/cancel.post.ts +54 -0
  114. package/server/api/account/orders/[id]/messages.get.ts +63 -0
  115. package/server/api/account/orders/[id]/messages.post.ts +44 -0
  116. package/server/api/account/orders/[id]/return.post.ts +1 -0
  117. package/server/api/account/orders/[id].get.ts +1 -1
  118. package/server/api/account/organization.put.ts +1 -1
  119. package/server/api/account/payments.get.ts +54 -0
  120. package/server/api/account/pending-approvals/[id]/approve.post.ts +10 -0
  121. package/server/api/account/pending-approvals/[id]/decline.post.ts +10 -0
  122. package/server/api/account/pending-approvals/index.get.ts +26 -0
  123. package/server/api/account/profile.get.ts +3 -1
  124. package/server/api/account/profile.put.ts +1 -1
  125. package/server/api/account/quotes/[id]/decline.post.ts +35 -6
  126. package/server/api/account/team/[id].put.ts +1 -1
  127. package/server/api/account/team.post.ts +1 -1
  128. package/server/api/auth/login.post.ts +6 -0
  129. package/server/api/auth/magic-link.post.ts +32 -0
  130. package/server/api/auth/magic-link.put.ts +35 -0
  131. package/server/api/auth/otp.post.ts +33 -0
  132. package/server/api/auth/otp.put.ts +33 -0
  133. package/server/api/carts/[id]/activate.post.ts +1 -0
  134. package/server/api/carts/[id]/index.delete.ts +1 -0
  135. package/server/api/carts/[id]/index.put.ts +1 -0
  136. package/server/api/carts/[id]/items.post.ts +1 -0
  137. package/server/api/checkout/profile.get.ts +6 -3
  138. package/server/api/forms/[slug]/submit.post.ts +27 -16
  139. package/server/api/forms/[slug].get.ts +9 -1
  140. package/server/api/forms/index.get.ts +23 -0
  141. package/server/api/orders/index.post.ts +41 -0
  142. package/server/api/promotions/available.post.ts +37 -0
  143. package/server/api/quick-actions.get.ts +6 -38
  144. package/server/config/account/organization.json +0 -4
  145. package/server/config/shop/app-settings.json +4 -0
  146. package/server/data/forms/authored.json +337 -0
  147. package/server/interfaces/forms.ts +51 -0
  148. package/server/middleware/buyer-principal.ts +18 -0
  149. package/server/routes/punchout/start.get.ts +2 -2
  150. package/server/services/ApiAddressBookService.ts +43 -1
  151. package/server/services/ApiAuthService.ts +101 -10
  152. package/server/services/ApiCartService.ts +3 -10
  153. package/server/services/ApiFormsService.ts +56 -0
  154. package/server/services/ApiOrganizationService.ts +7 -2
  155. package/server/services/ApiTeamService.ts +93 -21
  156. package/server/services/MockB2BContextService.ts +1 -5
  157. package/server/services/MockFormsService.ts +63 -0
  158. package/server/utils/accountPayments.ts +45 -0
  159. package/server/utils/appSettings.ts +69 -4
  160. package/server/utils/buyerIdentity.ts +168 -0
  161. package/server/utils/cartOwnership.ts +27 -0
  162. package/server/utils/forms.ts +62 -14
  163. package/server/utils/formsService.ts +29 -0
  164. package/server/utils/liveOrderLists.ts +50 -23
  165. package/server/utils/liveOrders.ts +65 -24
  166. package/server/utils/livePrices.ts +7 -15
  167. package/server/utils/masterData.ts +60 -11
  168. package/server/utils/passwordlessSignIn.ts +82 -0
  169. package/server/utils/pendingApprovals.ts +175 -0
  170. package/server/utils/procurementCheckout.ts +2 -0
  171. package/server/utils/promotionsService.ts +90 -0
  172. package/server/utils/quickActionCatalogue.ts +53 -0
  173. package/server/utils/quotesService.ts +15 -0
  174. package/server/utils/revenexxSdk.ts +116 -2
  175. package/server/utils/shopSettings.ts +35 -4
@@ -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
+ }
@@ -54,6 +54,49 @@
54
54
  "deleted": "Adresse erfolgreich gelöscht"
55
55
  }
56
56
  },
57
+ "approvals": {
58
+ "queue": {
59
+ "title": "Wartet auf Ihre Entscheidung",
60
+ "loading": "Wird geladen …",
61
+ "layer": "Stufe {layer}",
62
+ "unnamedRequest": "Anfrage",
63
+ "approve": "Freigeben",
64
+ "decline": "Ablehnen",
65
+ "declineTitle": "Anfrage ablehnen",
66
+ "declineIntro": "Eine Ablehnung beendet die gesamte Anfrage und gibt reserviertes Budget zurück.",
67
+ "declineReason": "Grund",
68
+ "declineReasonPlaceholder": "Damit der Anfragende weiß, wie er es anders stellen kann.",
69
+ "approved": "Freigegeben",
70
+ "declined": "Abgelehnt",
71
+ "failed": "Entscheidung nicht möglich",
72
+ "empty": {
73
+ "title": "Nichts wartet auf Sie",
74
+ "description": "Sobald eine Anfrage Ihre Freigabe braucht, erscheint sie hier."
75
+ }
76
+ }
77
+ },
78
+ "payments": {
79
+ "title": "Zahlungen",
80
+ "description": "Was offen ist, was fällig ist und was bereits bezahlt wurde.",
81
+ "outstanding": "Offener Betrag",
82
+ "overdueTitle": "{count} Zahlung(en) überfällig",
83
+ "overdueDescription": "Bitte begleichen Sie diese Posten oder wenden Sie sich an Ihren Ansprechpartner.",
84
+ "columns": { "order": "Bestellung", "amount": "Betrag", "state": "Status", "due": "Fällig / bezahlt" },
85
+ "states": {
86
+ "open": "Offen",
87
+ "pending": "In Bearbeitung",
88
+ "authorized": "Autorisiert",
89
+ "paid": "Bezahlt",
90
+ "partially_paid": "Teilweise bezahlt",
91
+ "refunded": "Erstattet",
92
+ "failed": "Fehlgeschlagen",
93
+ "overdue": "Überfällig"
94
+ },
95
+ "empty": {
96
+ "title": "Keine Zahlungen",
97
+ "description": "Sobald eine Bestellung abgerechnet wird, erscheint sie hier."
98
+ }
99
+ },
57
100
  "orders": {
58
101
  "title": "Ihre Bestellungen",
59
102
  "description": "Alle Ihre bisherigen Bestellungen im Überblick.",
@@ -97,6 +140,25 @@
97
140
  "refresh": "Aktualisieren",
98
141
  "notFound": "Bestellung nicht gefunden",
99
142
  "searchPlaceholder": "Nach Bestellnummer oder Artikel suchen …",
143
+ "cancel": {
144
+ "action": "Bestellung stornieren",
145
+ "title": "Bestellung {number} stornieren",
146
+ "intro": "Die Bestellung wird vollständig storniert. Solange nichts versendet wurde, ist das möglich.",
147
+ "reason": "Grund (kann erforderlich sein)",
148
+ "reasonPlaceholder": "z. B. doppelt bestellt",
149
+ "confirm": "Verbindlich stornieren",
150
+ "done": "Bestellung storniert",
151
+ "failed": "Stornierung nicht möglich"
152
+ },
153
+ "messages": {
154
+ "title": "Nachrichten zu dieser Bestellung",
155
+ "you": "Sie",
156
+ "merchant": "Unser Team",
157
+ "empty": "Noch keine Nachrichten. Schreiben Sie uns, wenn etwas zu klären ist.",
158
+ "placeholder": "Ihre Nachricht zu dieser Bestellung …",
159
+ "send": "Senden",
160
+ "failed": "Nachricht konnte nicht gesendet werden"
161
+ },
100
162
  "returns": {
101
163
  "requestReturn": "Rücksendung anfragen",
102
164
  "modalTitle": "Rücksendung anfragen",
@@ -176,6 +238,12 @@
176
238
  "accountAriaLabel": "Zum Kundenkonto"
177
239
  },
178
240
  "account": {
241
+ "hold": {
242
+ "title": "Ihr Konto ist vorübergehend gesperrt",
243
+ "everything": "Sie können weiterarbeiten wie bisher. Bitte wenden Sie sich an Ihren Ansprechpartner, damit die Sperre aufgehoben wird.",
244
+ "catalogue": "Sie können weiterhin im Katalog stöbern und Preise sehen, aber nicht bestellen. Bitte wenden Sie sich an Ihren Ansprechpartner.",
245
+ "nothing": "Bis die Sperre aufgehoben ist, steht Ihnen dieser Bereich nicht zur Verfügung. Bitte wenden Sie sich an Ihren Ansprechpartner."
246
+ },
179
247
  "nav": {
180
248
  "groups": {
181
249
  "account": "Konto",
@@ -195,6 +263,7 @@
195
263
  "inquiries": "Anfragen",
196
264
  "quotes": "Angebote",
197
265
  "orders": "Bestellungen",
266
+ "payments": "Zahlungen",
198
267
  "deliveries": "Lieferungen",
199
268
  "subscriptions": "Abos",
200
269
  "downloads": "Downloads",
@@ -405,6 +474,11 @@
405
474
  "title": "Bestelllisten",
406
475
  "description": "Einkaufs- und Etikettenlisten — gespeicherte Positionen, die direkt zurück in den Warenkorb fließen.",
407
476
  "add": "Liste anlegen",
477
+ "missing": {
478
+ "blocked": "{count} Position(en) werden nicht mehr geführt. Bitte entfernen Sie sie aus der Liste, bevor Sie sie übernehmen.",
479
+ "skipped": "{count} Position(en) übernommen, {skipped} entfallen — diese Artikel führen wir nicht mehr.",
480
+ "gone": "Nicht mehr im Sortiment"
481
+ },
408
482
  "limitReached": "Sie haben die maximale Anzahl von {max} Listen erreicht. Löschen Sie eine Liste, um eine neue anzulegen.",
409
483
  "addTitle": "Neue Liste",
410
484
  "editTitle": "Liste bearbeiten",
@@ -506,6 +580,7 @@
506
580
  "organization": {
507
581
  "title": "Firmendaten",
508
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.",
509
584
  "description": "Daten Ihres Unternehmens ansehen und bearbeiten.",
510
585
  "companySection": "Unternehmen",
511
586
  "edit": "Bearbeiten",
@@ -533,6 +608,7 @@
533
608
  "team": {
534
609
  "title": "Benutzer",
535
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.",
536
612
  "description": "Verwalten Sie die Benutzer Ihres Unternehmens und deren Rollen.",
537
613
  "searchPlaceholder": "Nach Name, E-Mail oder Rolle suchen …",
538
614
  "invite": "Benutzer einladen",
@@ -545,6 +621,11 @@
545
621
  "cancel": "Abbrechen",
546
622
  "saved": "Gespeichert",
547
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
+ },
548
629
  "errorTitle": "Benutzer nicht verfügbar",
549
630
  "errorDescription": "Die Benutzer konnten nicht geladen werden.",
550
631
  "columns": {
@@ -606,6 +687,7 @@
606
687
  "open": "Öffnen",
607
688
  "order": "Zum Angebotspreis bestellen ({total})",
608
689
  "orderSelected": "{count} Position(en) bestellen ({total})",
690
+ "declineSelected": "{count} Position(en) ablehnen",
609
691
  "decline": "Angebot ablehnen"
610
692
  },
611
693
  "detail": {
@@ -623,6 +705,11 @@
623
705
  "sellerNote": "Nachricht von uns",
624
706
  "trail": "Verlauf",
625
707
  "onRequest": "auf Anfrage",
708
+ "choice": {
709
+ "order": "Bestellen",
710
+ "decline": "Ablehnen",
711
+ "open": "Offen lassen"
712
+ },
626
713
  "selectPosition": "Position {name} für die Bestellung auswählen",
627
714
  "partialHint": "{remaining} Position(en) bleiben offen und können später separat bestellt werden.",
628
715
  "hint": {
@@ -29,6 +29,8 @@
29
29
  "emailFormat": "Bitte geben Sie eine gültige E-Mail-Adresse ein",
30
30
  "passwordsMismatch": "Passwörter stimmen nicht überein",
31
31
  "registrationDisabled": "Die Registrierung ist derzeit geschlossen. Bitte kontaktieren Sie uns, um ein Konto einzurichten.",
32
+ "emailExists": "Für diese E-Mail-Adresse besteht bereits ein Konto. Bitte melden Sie sich an oder setzen Sie Ihr Passwort zurück.",
33
+ "network": "Server nicht erreichbar. Bitte prüfen Sie Ihre Verbindung und versuchen Sie es erneut.",
32
34
  "unknown": "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut."
33
35
  },
34
36
  "disabled": {
@@ -97,6 +99,7 @@
97
99
  "errors": {
98
100
  "invalidCredentials": "E-Mail oder Passwort ist falsch.",
99
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.",
100
103
  "rateLimited": "Zu viele Versuche. Bitte versuchen Sie es in ein paar Minuten erneut.",
101
104
  "network": "Server nicht erreichbar. Bitte prüfen Sie Ihre Verbindung und versuchen Sie es erneut.",
102
105
  "sessionExists": "Sie sind bereits angemeldet.",
@@ -106,6 +109,19 @@
106
109
  "heroHighlight": "Ein Konto.",
107
110
  "heroLine1": "Wir vereinen alle Funktionen unter einem zentralen Kundenkonto.",
108
111
  "heroLine2": "Melden Sie sich jetzt an oder registrieren Sie sich für Ihren persönlichen Zugang.",
112
+ "mailed": {
113
+ "alternative": "Oder melden Sie sich ohne Passwort an:",
114
+ "only": "Geben Sie Ihre E-Mail-Adresse ein — wir senden Ihnen den Zugang zu.",
115
+ "requestLink": "Anmeldelink senden",
116
+ "requestCode": "Code senden",
117
+ "sentTitle": "Prüfen Sie Ihr Postfach",
118
+ "sentLink": "Wir haben einen Anmeldelink an {email} gesendet. Er ist nur kurze Zeit gültig.",
119
+ "sentCode": "Wir haben einen Code an {email} gesendet. Geben Sie ihn hier ein.",
120
+ "codePlaceholder": "Code aus der E-Mail",
121
+ "confirmCode": "Anmelden",
122
+ "codeRejected": "Dieser Code ist falsch oder abgelaufen.",
123
+ "startOver": "Andere E-Mail-Adresse verwenden"
124
+ },
109
125
  "passwordDisabled": {
110
126
  "title": "Anmeldung per E-Mail",
111
127
  "magicLink": "Dieser Shop arbeitet ohne Passwort. Bitte fordern Sie einen Anmeldelink per E-Mail an — wenden Sie sich an unser Team, wenn Sie keinen erhalten.",
@@ -167,6 +183,20 @@
167
183
  },
168
184
  "logout": {
169
185
  "success": "Sie wurden abgemeldet"
186
+ },
187
+ "magicLink": {
188
+ "title": "Anmeldung per Link",
189
+ "description": "Wir prüfen Ihren Anmeldelink.",
190
+ "confirming": "Einen Moment, wir melden Sie an …",
191
+ "rejected": {
192
+ "title": "Dieser Link ist nicht mehr gültig",
193
+ "description": "Anmeldelinks gelten nur kurz und nur einmal. Fordern Sie einfach einen neuen an."
194
+ },
195
+ "unavailable": {
196
+ "title": "Wir konnten Sie gerade nicht anmelden",
197
+ "description": "Der Dienst ist im Moment nicht erreichbar. Bitte versuchen Sie es in einigen Minuten erneut."
198
+ },
199
+ "retry": "Neuen Link anfordern"
170
200
  }
171
201
  }
172
202
  }
@@ -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",
@@ -213,6 +214,13 @@
213
214
  "popularTitle": "Beliebt im Sortiment",
214
215
  "add": "In den Warenkorb"
215
216
  },
217
+ "offers": {
218
+ "title": "Das könnten Sie noch bekommen",
219
+ "missingValue": "noch {amount}",
220
+ "missingQuantity": "noch {count} Stück",
221
+ "reached": "erreicht",
222
+ "needsCode": "mit Aktionscode"
223
+ },
216
224
  "trust": {
217
225
  "invoice": "Kauf auf Rechnung für Geschäftskunden",
218
226
  "support": "Persönliches Service-Team, werktags 8–17 Uhr"