@revenexx/cover 0.6.0 → 0.7.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 (55) hide show
  1. package/app/app.config.ts +12 -0
  2. package/app/components/account/address/AccountAddressView.vue +12 -1
  3. package/app/components/account/orderlists/AccountOrderListDetail.vue +16 -2
  4. package/app/components/account/orderlists/AccountOrderListsTable.vue +9 -1
  5. package/app/components/account/quotes/AccountQuoteDetail.vue +77 -3
  6. package/app/components/auth/AuthLoginPanel.vue +31 -0
  7. package/app/components/auth/AuthRegisterPanel.vue +71 -3
  8. package/app/components/cart/drawer/CartDrawer.vue +2 -1
  9. package/app/components/cart/item/CartItem.vue +4 -1
  10. package/app/components/cart/position/CartPosition.vue +7 -2
  11. package/app/components/cart/quote/CartQuoteRequestModal.vue +9 -0
  12. package/app/components/cart/view/CartSummaryPanel.vue +42 -5
  13. package/app/components/category/info/CategoryPrice.vue +4 -2
  14. package/app/components/layout/header/TopBar.vue +13 -4
  15. package/app/components/product/card/Compact.vue +4 -2
  16. package/app/components/product/detail/ProductDetailAddToCart.vue +8 -3
  17. package/app/composables/useCartLimits.ts +54 -0
  18. package/app/composables/useCartStore.ts +39 -6
  19. package/app/composables/useCartSummaryFormatting.ts +21 -3
  20. package/app/composables/useDeliveryPromise.ts +112 -0
  21. package/app/composables/useOrderListRules.ts +72 -0
  22. package/app/composables/useProduct.ts +5 -2
  23. package/app/composables/useRegistrationConfig.ts +27 -6
  24. package/app/composables/useShopSettings.ts +66 -0
  25. package/app/config/navigation.ts +16 -2
  26. package/app/interfaces/account/quotes.ts +20 -0
  27. package/app/interfaces/cart-calculation.ts +9 -1
  28. package/app/interfaces/shopSettings.ts +246 -0
  29. package/app/plugins/shop-settings.ts +52 -0
  30. package/i18n/locales/de/account.json +6 -0
  31. package/i18n/locales/de/auth.json +12 -0
  32. package/i18n/locales/de/cart.json +12 -3
  33. package/i18n/locales/de/common.json +3 -2
  34. package/i18n/locales/en/account.json +6 -0
  35. package/i18n/locales/en/auth.json +12 -0
  36. package/i18n/locales/en/cart.json +12 -3
  37. package/i18n/locales/en/common.json +3 -2
  38. package/nuxt.config.ts +0 -1
  39. package/package.json +1 -1
  40. package/server/api/account/quotes/[id]/decline.post.ts +1 -1
  41. package/server/api/account/quotes/[id]/order.post.ts +25 -5
  42. package/server/api/account/quotes/[id].get.ts +1 -1
  43. package/server/api/account/quotes.get.ts +10 -3
  44. package/server/api/auth/registration-config.get.ts +19 -33
  45. package/server/api/cart/calculate.post.ts +35 -18
  46. package/server/api/orders/index.post.ts +30 -0
  47. package/server/api/shop/settings.get.ts +14 -0
  48. package/server/config/shop/app-settings.json +54 -0
  49. package/server/interfaces/cartCalculation.ts +22 -0
  50. package/server/services/MockB2BContextService.ts +43 -1
  51. package/server/services/MockCartCalculationService.ts +117 -11
  52. package/server/utils/appSettings.ts +242 -0
  53. package/server/utils/livePrices.ts +24 -2
  54. package/server/utils/quotesService.ts +109 -16
  55. package/server/utils/shopSettings.ts +130 -0
@@ -26,9 +26,14 @@ const quantity = ref(1);
26
26
  const currentCartQuantity = computed(() =>
27
27
  cartStore.items.find((item: CartItem) => item.id === props.product.id && !item.requisitionId)?.quantity ?? 0,
28
28
  );
29
+ // The article's own stock ceiling and the carts app's line ceiling, whichever
30
+ // binds first. A buy box that offers a quantity the cart will refuse sends the
31
+ // buyer into an error they could not have foreseen.
32
+ const { lineCeiling } = useCartLimits();
33
+ const effectiveMaxQuantity = computed(() => lineCeiling(props.maxQuantity) ?? props.maxQuantity);
29
34
  const quantityInvalid = computed(() => quantity.value < 1);
30
35
  const quantityExceeded = computed(() =>
31
- currentCartQuantity.value + quantity.value > props.maxQuantity,
36
+ currentCartQuantity.value + quantity.value > effectiveMaxQuantity.value,
32
37
  );
33
38
 
34
39
  let exceededTimer: ReturnType<typeof setTimeout> | null = null;
@@ -99,7 +104,7 @@ function addToCart() {
99
104
  price: props.price / 100,
100
105
  taxRate: props.taxRate,
101
106
  priceTiers: buildPriceTiers(props.prices),
102
- maxOrderQuantity: props.maxQuantity,
107
+ maxOrderQuantity: effectiveMaxQuantity.value,
103
108
  categorySlug: props.categorySlug,
104
109
  subcategorySlug: props.subcategorySlug,
105
110
  }, { chooseTarget: true });
@@ -179,7 +184,7 @@ onUnmounted(() => {
179
184
  <UiFeedbackErrorBoundary
180
185
  v-if="showQuantityExceeded"
181
186
  :title="t('product.actions.maxQuantityReachedTitle', { count: currentCartQuantity })"
182
- :description="t('product.actions.maxQuantityReachedDescription', { max: maxQuantity })"
187
+ :description="t('product.actions.maxQuantityReachedDescription', { max: effectiveMaxQuantity })"
183
188
  :show-retry="false"
184
189
  />
185
190
 
@@ -0,0 +1,54 @@
1
+ /**
2
+ * How much a cart may hold, as the apps that hold it decide.
3
+ *
4
+ * Two ceilings, from two apps. The carts app caps a single line's quantity and
5
+ * the number of distinct lines a cart may carry; the orders app caps the
6
+ * positions one order may have. Both refuse with an error once they are passed
7
+ * — a 422 from carts, a 400 from orders — so a shop that does not know them
8
+ * sends a buyer into a wall they had no way to see coming, after they had
9
+ * already done the work of filling the cart.
10
+ *
11
+ * Zero means no limit in both apps, which is why every getter here returns null
12
+ * for "no ceiling" rather than a number to compare against.
13
+ */
14
+ export function useCartLimits() {
15
+ const { cart, orders } = useShopSettings();
16
+
17
+ /** Ceiling on one line's quantity, or null where neither app sets one. */
18
+ const maxQuantityPerLine = computed<number | null>(() => {
19
+ const max = cart.value?.maxQuantityPerLine ?? 0;
20
+ return max > 0 ? max : null;
21
+ });
22
+
23
+ /**
24
+ * Ceiling on the number of positions, the stricter of the two apps'.
25
+ *
26
+ * A cart the carts app would hold but the orders app would refuse is worse
27
+ * than no cart: the buyer gets all the way to the checkout before anything
28
+ * objects. So the smaller number is the one the shop enforces.
29
+ */
30
+ const maxLines = computed<number | null>(() => {
31
+ const fromCart = cart.value?.maxLines ?? 0;
32
+ const fromOrders = orders.value?.maxPositions ?? 0;
33
+ const both = [fromCart, fromOrders].filter(n => n > 0);
34
+ return both.length > 0 ? Math.min(...both) : null;
35
+ });
36
+
37
+ /**
38
+ * The ceiling that actually applies to one line: the stock the article has
39
+ * and the quantity the carts app allows, whichever is lower.
40
+ *
41
+ * `undefined` in and no app ceiling out means undefined — an article with no
42
+ * stock limit in a shop with no line limit has no ceiling, and returning a
43
+ * number there would invent one.
44
+ */
45
+ function lineCeiling(stockLimit?: number): number | undefined {
46
+ const app = maxQuantityPerLine.value;
47
+ if (app === null) {
48
+ return stockLimit;
49
+ }
50
+ return typeof stockLimit === "number" ? Math.min(stockLimit, app) : app;
51
+ }
52
+
53
+ return { maxQuantityPerLine, maxLines, lineCeiling };
54
+ }
@@ -29,7 +29,17 @@ const MULTI_CART_STORAGE = "cover-carts";
29
29
  const ADD_PREF_STORAGE = "cover-cart-add-pref";
30
30
 
31
31
  export const useCartStore = defineStore("cart", () => {
32
- const { public: { cartInactivityTtl: cartInactivityTtlRaw, taxIncludedPrices } } = useRuntimeConfig();
32
+ const { public: { cartInactivityTtl: cartInactivityTtlRaw } } = useRuntimeConfig();
33
+ // The price basis comes from the apps (prices + markets), read from shared
34
+ // state the shop-settings plugin fills before anything renders — a store
35
+ // cannot open a fetch of its own.
36
+ const { taxIncludedPrices } = useShopSettings();
37
+ // What the carts and orders apps allow a cart to hold. Without them the shop
38
+ // lets a buyer fill a cart that gets refused at the checkout.
39
+ const { maxLines, lineCeiling } = useCartLimits();
40
+ // Held whole: the promotions app decides how codes are read and how many a
41
+ // cart may carry, and addVoucherCode below reads both.
42
+ const shopSettings = useShopSettings();
33
43
  // A missing/invalid TTL must never collapse to setTimeout(..., NaN),
34
44
  // which fires immediately and silently empties the cart after every add.
35
45
  const cartInactivityTtl = Number.isFinite(Number(cartInactivityTtlRaw)) && Number(cartInactivityTtlRaw) > 0
@@ -47,12 +57,28 @@ export const useCartStore = defineStore("cart", () => {
47
57
  */
48
58
  const voucherCodes = skipHydrate(ref<string[]>([]));
49
59
 
50
- function addVoucherCode(code: string): void {
51
- const trimmed = code.trim().toUpperCase();
60
+ /**
61
+ * Hold a code the buyer typed.
62
+ *
63
+ * Two of the promotions app's answers apply. Whether case matters: the shop
64
+ * used to upper-case every code, which is right for the usual campaign code
65
+ * and wrong for a tenant whose codes are case-sensitive — it turned a valid
66
+ * code into one the engine had never heard of. And how many codes one cart
67
+ * may carry: the app refuses the extra one, so a cart holding three where
68
+ * one is allowed shows three chips and gets one discount.
69
+ */
70
+ function addVoucherCode(code: string): boolean {
71
+ const promotions = shopSettings.promotions.value;
72
+ const trimmed = promotions?.codeCaseSensitive ? code.trim() : code.trim().toUpperCase();
52
73
  if (!trimmed || voucherCodes.value.includes(trimmed)) {
53
- return;
74
+ return false;
75
+ }
76
+ const max = promotions?.maxCodesPerCart ?? 0;
77
+ if (max > 0 && voucherCodes.value.length >= max) {
78
+ return false;
54
79
  }
55
80
  voucherCodes.value = [...voucherCodes.value, trimmed];
81
+ return true;
56
82
  }
57
83
 
58
84
  function removeVoucherCode(code: string): void {
@@ -203,7 +229,7 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
203
229
  const subtotalDisplay = computed(() =>
204
230
  items.value.reduce((sum, item) => {
205
231
  const unitPrice = resolveUnitPrice(item);
206
- if (!taxIncludedPrices) {
232
+ if (!taxIncludedPrices.value) {
207
233
  return sum + unitPrice * item.quantity;
208
234
  }
209
235
 
@@ -248,7 +274,8 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
248
274
  const existing = items.value.find(i => i.id === product.id && !i.requisitionId);
249
275
  let addedKey: string | null = null;
250
276
  if (existing) {
251
- const maxOrderQuantity = existing.maxOrderQuantity ?? product.maxOrderQuantity;
277
+ // The stock's ceiling and the carts app's, whichever is lower.
278
+ const maxOrderQuantity = lineCeiling(existing.maxOrderQuantity ?? product.maxOrderQuantity);
252
279
  if (typeof maxOrderQuantity === "number" && existing.quantity >= maxOrderQuantity) {
253
280
  return false;
254
281
  }
@@ -262,6 +289,12 @@ const SERVER_CART_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
262
289
  if (typeof product.maxOrderQuantity === "number" && product.maxOrderQuantity < 1) {
263
290
  return false;
264
291
  }
292
+ // A cart already at the apps' position ceiling takes no further line.
293
+ // Refusing here is the only way the buyer finds out while they can
294
+ // still do something about it.
295
+ if (maxLines.value !== null && items.value.length >= maxLines.value) {
296
+ return false;
297
+ }
265
298
  const lineKey = nextLineKey("li");
266
299
  items.value.push({ ...product, lineKey, quantity: 1 });
267
300
  addedKey = lineKey;
@@ -1,9 +1,12 @@
1
1
  export const useCartSummaryFormatting = () => {
2
2
  const { t } = useI18n();
3
- const { public: { locale, taxIncludedPrices } } = useRuntimeConfig();
3
+ const { public: { locale } } = useRuntimeConfig();
4
4
  const currency = useDisplayCurrency();
5
+ // Whether the summary says "incl." or "excl." follows the basis the prices
6
+ // app and the market resolved, not a build-time flag.
7
+ const { taxIncludedPrices, prices } = useShopSettings();
5
8
 
6
- const taxLabelKey = computed(() => taxIncludedPrices ? "summary.tax.incl" : "summary.tax.excl");
9
+ const taxLabelKey = computed(() => taxIncludedPrices.value ? "summary.tax.incl" : "summary.tax.excl");
7
10
 
8
11
  function formatPercent(rate: number): string {
9
12
  return `${Math.round(rate * 100)}%`;
@@ -16,8 +19,23 @@ export const useCartSummaryFormatting = () => {
16
19
  });
17
20
  }
18
21
 
22
+ /**
23
+ * A figure as this tenant states figures.
24
+ *
25
+ * The decimals are the prices app's `price_precision`, not the locale's
26
+ * default two: a tenant selling by the metre at four decimals had every
27
+ * amount rounded in the summary while the order was booked on the unrounded
28
+ * one, and the two disagreed by a cent on almost every line.
29
+ */
19
30
  function formatCurrency(value: number): string {
20
- return (value).toLocaleString(locale as string, { style: "currency", currency: currency.value });
31
+ const digits = prices.value?.precision;
32
+ return (value).toLocaleString(locale as string, {
33
+ style: "currency",
34
+ currency: currency.value,
35
+ ...(typeof digits === "number" && digits >= 0 && digits <= 6
36
+ ? { minimumFractionDigits: digits, maximumFractionDigits: digits }
37
+ : {}),
38
+ });
21
39
  }
22
40
 
23
41
  return {
@@ -0,0 +1,112 @@
1
+ import type { TopbarUsp } from "../config/navigation";
2
+
3
+ /**
4
+ * What this merchant promises about delivery, in words a buyer can read.
5
+ *
6
+ * Both figures belong to the shipping app: the order value that earns free
7
+ * delivery, and the time of day after which an order ships tomorrow. The shop
8
+ * used to carry them as sentences with the numbers written in — free above
9
+ * 100 €, ordered by four o'clock — while the app charged and shipped by figures
10
+ * of its own. The buyer read one and was billed by the other.
11
+ *
12
+ * Now every line is built from the app's answer, and a line whose figure the
13
+ * merchant never set is not built at all. `null` means say nothing.
14
+ */
15
+ export function useDeliveryPromise() {
16
+ const { t, locale } = useI18n();
17
+ const { shipping } = useShopSettings();
18
+ const currency = useDisplayCurrency();
19
+ const appConfig = useAppConfig();
20
+
21
+ /**
22
+ * The zone the cut-off is quoted in. The shipping app states it in UTC —
23
+ * it has to, it serves every market — and which zone a shop quotes it back
24
+ * in is the storefront's own decision, so it lives in app.config rather
25
+ * than being guessed from the buyer's browser (which would make the line
26
+ * change between the server's render and the browser's).
27
+ */
28
+ const cutoffZone = computed(() =>
29
+ (appConfig.shipping as { cutoffTimezone?: string } | undefined)?.cutoffTimezone ?? "UTC",
30
+ );
31
+
32
+ /** "Versandkostenfrei ab 250 €" — or nothing, where none is promised. */
33
+ const freeShippingLabel = computed<string | null>(() => {
34
+ const threshold = shipping.value?.freeThreshold;
35
+ if (threshold === null || threshold === undefined) {
36
+ return null;
37
+ }
38
+ return t("topbar.freeShipping", {
39
+ amount: threshold.toLocaleString(locale.value, {
40
+ style: "currency",
41
+ currency: currency.value,
42
+ maximumFractionDigits: 0,
43
+ }),
44
+ });
45
+ });
46
+
47
+ /** "Bis 16:00 bestellt, morgen geliefert" — built from cut-off and handling days. */
48
+ const deliveryCutoffLabel = computed<string | null>(() => {
49
+ const s = shipping.value;
50
+ if (!s?.cutoffTime) {
51
+ return null;
52
+ }
53
+ const time = formatCutoff(s.cutoffTime, cutoffZone.value, locale.value);
54
+ if (!time) {
55
+ return null;
56
+ }
57
+ // Handling days are working days BEFORE a shipment leaves, so one day of
58
+ // handling is what "shipped tomorrow" already means; more than that is a
59
+ // different promise and gets a different sentence.
60
+ return s.handlingDays > 1
61
+ ? t("topbar.deliveryInDays", { time, days: s.handlingDays })
62
+ : t("topbar.nextDayDelivery", { time });
63
+ });
64
+
65
+ /** The line for one configured USP, or null where its figure is unknown. */
66
+ function uspLabel(usp: TopbarUsp): string | null {
67
+ if (usp.needs === "freeShippingThreshold") {
68
+ return freeShippingLabel.value;
69
+ }
70
+ if (usp.needs === "deliveryCutoff") {
71
+ return deliveryCutoffLabel.value;
72
+ }
73
+ return t(usp.labelKey);
74
+ }
75
+
76
+ return { freeShippingLabel, deliveryCutoffLabel, uspLabel };
77
+ }
78
+
79
+ /**
80
+ * A "HH:MM" wall time in UTC, read back in the zone the shop quotes.
81
+ *
82
+ * Any date would do — only the time of day is shown — but it has to be a fixed
83
+ * one, or a shop rendered either side of a daylight-saving change would show
84
+ * two different cut-offs for the same setting. Today's date is the one that
85
+ * makes the offset the one actually in force.
86
+ */
87
+ function formatCutoff(cutoff: string, zone: string, locale: string): string | null {
88
+ const match = /^(\d{1,2}):(\d{2})$/.exec(cutoff.trim());
89
+ if (!match) {
90
+ return null;
91
+ }
92
+ const hours = Number(match[1]);
93
+ const minutes = Number(match[2]);
94
+ if (hours > 23 || minutes > 59) {
95
+ return null;
96
+ }
97
+ const today = new Date();
98
+ const at = new Date(Date.UTC(
99
+ today.getUTCFullYear(),
100
+ today.getUTCMonth(),
101
+ today.getUTCDate(),
102
+ hours,
103
+ minutes,
104
+ ));
105
+ try {
106
+ return at.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit", timeZone: zone });
107
+ }
108
+ catch {
109
+ // An unknown zone in app.config must not take the header down.
110
+ return at.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });
111
+ }
112
+ }
@@ -0,0 +1,72 @@
1
+ import type { OrderList } from "../interfaces/account/order-lists";
2
+
3
+ /**
4
+ * What a buyer may do with an order list, as the orderlists app decides.
5
+ *
6
+ * Four of its settings reach this surface. Who may change a list the whole
7
+ * company can see (`shared_lists_editable`); how many positions one list holds
8
+ * and how many lists one person keeps (`max_items_per_list`,
9
+ * `max_lists_per_owner`); and whether putting a list in the cart adds to what
10
+ * is there or replaces it (`cart_merge_mode`). The shop used to answer all four
11
+ * for itself: only the owner could edit, there was no ceiling anywhere, and a
12
+ * list always appended.
13
+ */
14
+ export function useOrderListRules() {
15
+ const { orderLists } = useShopSettings();
16
+ const authStore = useAuthStore();
17
+
18
+ /**
19
+ * Whether this buyer may change the positions on a list.
20
+ *
21
+ * Their own, always. A list shared with the company only where the app says
22
+ * a shared list is the company's to edit — which is how a team keeps one
23
+ * list for a machine rather than five copies of it.
24
+ */
25
+ function canEditPositions(list: Pick<OrderList, "owner" | "public">): boolean {
26
+ if (isOwnOrderList(list, authStore.user)) {
27
+ return true;
28
+ }
29
+ return list.public && (orderLists.value?.sharedEditable ?? false);
30
+ }
31
+
32
+ /**
33
+ * Whether this buyer may rename, share, or delete the list itself.
34
+ *
35
+ * The owner only, and deliberately narrower than editing: "a shared list is
36
+ * editable by the whole organization" is about what is ON the list. Letting
37
+ * a colleague delete it, or take away the sharing everybody else relies on,
38
+ * is a different permission the app does not grant.
39
+ */
40
+ function canManage(list: Pick<OrderList, "owner">): boolean {
41
+ return isOwnOrderList(list, authStore.user);
42
+ }
43
+
44
+ /** Positions one list may hold, or null where the app sets no ceiling. */
45
+ const maxPositions = computed<number | null>(() => {
46
+ const max = orderLists.value?.maxItems ?? 0;
47
+ return max > 0 ? max : null;
48
+ });
49
+
50
+ /** Lists one buyer may keep, or null where the app sets no ceiling. */
51
+ const maxLists = computed<number | null>(() => {
52
+ const max = orderLists.value?.maxLists ?? 0;
53
+ return max > 0 ? max : null;
54
+ });
55
+
56
+ /**
57
+ * Whether putting a list in the cart adds to what is there, or replaces it.
58
+ *
59
+ * `replace` is the one a buyer working from a list wants — the list IS the
60
+ * order — and `append` is right where the list is a set of extras. Getting
61
+ * it wrong either loses the cart or double-orders half of it, which is why
62
+ * the merchant decides and not the shop.
63
+ */
64
+ const cartMergeMode = computed<"append" | "replace">(() =>
65
+ orderLists.value?.cartMergeMode ?? "append",
66
+ );
67
+
68
+ /** The kind a new list starts as, where the app names one. */
69
+ const defaultKind = computed(() => orderLists.value?.defaultKind ?? null);
70
+
71
+ return { canEditPositions, canManage, maxPositions, maxLists, cartMergeMode, defaultKind };
72
+ }
@@ -10,7 +10,10 @@ import type {
10
10
  } from "../interfaces/product-detail";
11
11
 
12
12
  export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
13
- const { public: { locale, taxIncludedPrices } } = useRuntimeConfig();
13
+ const { public: { locale } } = useRuntimeConfig();
14
+ // Net or gross is the prices app's answer, and the market's — never this
15
+ // shop's. See useShopSettings().
16
+ const { taxIncludedPrices } = useShopSettings();
14
17
  const currency = useDisplayCurrency();
15
18
  const { locale: activeLocale } = useI18n();
16
19
  // One rule for every catalogue image, shared with the listing cards: live
@@ -109,7 +112,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
109
112
 
110
113
  const formatPrice = (cents: number): string => {
111
114
  const basePrice = cents / 100;
112
- const displayPrice = getPriceWithOptionalTax(basePrice, taxRate.value, taxIncludedPrices);
115
+ const displayPrice = getPriceWithOptionalTax(basePrice, taxRate.value, taxIncludedPrices.value);
113
116
 
114
117
  return displayPrice.toLocaleString(locale, { style: "currency", currency: currency.value });
115
118
  };
@@ -5,18 +5,39 @@ export interface RegistrationConfig {
5
5
  b2c: boolean;
6
6
  /** A VAT id is mandatory when registering an organization. */
7
7
  vatRequired: boolean;
8
+ /**
9
+ * What happens after the form is sent. `open` signs the applicant in;
10
+ * `approval_required` leaves them waiting for the merchant to decide, which
11
+ * is a different sentence to end a registration on — and the difference
12
+ * between a buyer who starts shopping and one who wonders what went wrong.
13
+ */
14
+ mode: "open" | "approval_required";
15
+ /**
16
+ * How far a VAT id is checked: not at all, for its shape, or against VIES.
17
+ * `vies` can refuse an id that looks perfectly well formed, so a form that
18
+ * only checks the shape promises more than the app will accept.
19
+ */
20
+ vatValidation: "off" | "format" | "vies";
8
21
  }
9
22
 
10
23
  /**
11
- * The tenant's registration availability, resolved from the customers app's
12
- * settings through the BFF. Drives whether the storefront shows or hides the
13
- * register form — the customers app enforces the same flags server-side, so
14
- * this is purely the matching UX. Shared by key across the teaser and the
15
- * panel, and defaults open so a settings hiccup never hides registration.
24
+ * The tenant's registration terms, as the customers app holds them.
25
+ *
26
+ * Drives whether the storefront shows the register form at all, what it insists
27
+ * on, and what it says once the form is sent. The app enforces the same answers
28
+ * server-side, so this is the matching UX. Shared by key across the teaser and
29
+ * the panel; the defaults are the app's own, so a settings hiccup never hides
30
+ * registration.
16
31
  */
17
32
  export function useRegistrationConfig() {
18
33
  return useFetch<RegistrationConfig>("/api/auth/registration-config", {
19
34
  key: "registration-config",
20
- default: () => ({ b2b: true, b2c: true, vatRequired: false }),
35
+ default: (): RegistrationConfig => ({
36
+ b2b: true,
37
+ b2c: true,
38
+ vatRequired: false,
39
+ mode: "open",
40
+ vatValidation: "off",
41
+ }),
21
42
  });
22
43
  }
@@ -0,0 +1,66 @@
1
+ import type { ShopSettings } from "../interfaces/shopSettings";
2
+ import { resolvePriceBasis } from "../interfaces/shopSettings";
3
+
4
+ /**
5
+ * What the shop was configured to do — the apps' answers, not the shop's.
6
+ *
7
+ * Read from shared state that the shop-settings plugin fills once per page
8
+ * load, so this is synchronous everywhere: a component, a composable and the
9
+ * cart store all see the same answer at the same moment, and nothing flips
10
+ * after hydration.
11
+ *
12
+ * Every getter survives not knowing. Where the answer has not arrived — or
13
+ * where the merchant configured nothing — the honest rendering is the same:
14
+ * say nothing, and fall back to what the layer has always done.
15
+ */
16
+ export function useShopSettings() {
17
+ const state = useState<ShopSettings | null>("cover:shop-settings", () => null);
18
+
19
+ /**
20
+ * Re-read after something that could have changed them (a market switch).
21
+ *
22
+ * The same headers the plugin forwards: an internal call during SSR inherits
23
+ * nothing, so without them the answer is the wrong tenant's or the demo's.
24
+ */
25
+ async function refresh(): Promise<void> {
26
+ try {
27
+ state.value = await $fetch<ShopSettings>("/api/shop/settings", {
28
+ headers: useRequestHeaders(["cookie", "x-revenexx-tenant", "x-revenexx-context"]),
29
+ });
30
+ }
31
+ catch {
32
+ // Keep the answer we had rather than dropping to none.
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Net or gross for this market: the prices app states the basis the tenant
38
+ * stores in, a market may override it. Net while unknown — this is a B2B
39
+ * storefront, and net is what the layer has always shown.
40
+ */
41
+ const priceBasis = computed<"net" | "gross">(() =>
42
+ state.value ? resolvePriceBasis(state.value.prices) : "net",
43
+ );
44
+
45
+ return {
46
+ settings: computed(() => state.value),
47
+ priceBasis,
48
+ /** True where prices are quoted with tax — the old taxIncludedPrices flag. */
49
+ taxIncludedPrices: computed(() => priceBasis.value === "gross"),
50
+ /** The order value from which delivery is free, or null if none is promised. */
51
+ freeShippingThreshold: computed(() => state.value?.shipping.freeThreshold ?? null),
52
+ cart: computed(() => state.value?.cart ?? null),
53
+ orders: computed(() => state.value?.orders ?? null),
54
+ shipping: computed(() => state.value?.shipping ?? null),
55
+ prices: computed(() => state.value?.prices ?? null),
56
+ promotions: computed(() => state.value?.promotions ?? null),
57
+ quotes: computed(() => state.value?.quotes ?? null),
58
+ orderLists: computed(() => state.value?.orderLists ?? null),
59
+ signIn: computed(() => state.value?.signIn ?? null),
60
+ account: computed(() => state.value?.account ?? null),
61
+ registration: computed(() => state.value?.registration ?? null),
62
+ inventory: computed(() => state.value?.inventory ?? null),
63
+ procurement: computed(() => state.value?.procurement ?? null),
64
+ refresh,
65
+ };
66
+ }
@@ -93,12 +93,26 @@ export interface NavItem {
93
93
  export interface TopbarUsp {
94
94
  labelKey: string;
95
95
  icon: string;
96
+ /**
97
+ * A figure this line states, and without which it must not be shown.
98
+ *
99
+ * Both of these lines are promises about THIS merchant's terms, and both
100
+ * used to be sentences with numbers baked into them — free delivery above
101
+ * 100 €, ordered by four o'clock. Neither figure was the shop's to name:
102
+ * the shipping app holds them, and a storefront repeating a different one
103
+ * is telling buyers something the app will not honour.
104
+ *
105
+ * So a line that needs a figure renders only once the figure is known, and
106
+ * disappears where the merchant has not set one. A promise nobody
107
+ * configured is better unsaid.
108
+ */
109
+ needs?: "freeShippingThreshold" | "deliveryCutoff";
96
110
  }
97
111
 
98
112
  /** Left side of the topbar — unique selling points. */
99
113
  export const topbarUsps: TopbarUsp[] = [
100
- { labelKey: "topbar.freeShipping", icon: "delivery" },
101
- { labelKey: "topbar.nextDayDelivery", icon: "clock" },
114
+ { labelKey: "topbar.freeShipping", icon: "delivery", needs: "freeShippingThreshold" },
115
+ { labelKey: "topbar.nextDayDelivery", icon: "clock", needs: "deliveryCutoff" },
102
116
  ];
103
117
 
104
118
  /** Right side of the topbar — quick links. */
@@ -73,6 +73,19 @@ export interface AccountQuote {
73
73
  canOrder: boolean;
74
74
  canDecline: boolean;
75
75
  expired: boolean;
76
+ /**
77
+ * Valid, but not for much longer — inside the window the quotes app says to
78
+ * warn in (`expiry_warning_days`). A buyer sitting on a quote that lapses
79
+ * unwarned has to ask for the same price twice.
80
+ */
81
+ expiresSoon: boolean;
82
+ /**
83
+ * Whether the buyer may take part of this quote and leave the rest, as the
84
+ * quotes app allows it (`partial_acceptance_enabled`). The app refuses a
85
+ * partial acceptance outright where the merchant does not, so offering the
86
+ * choice here without asking would offer a button that answers with an error.
87
+ */
88
+ partialAcceptance: boolean;
76
89
  }
77
90
 
78
91
  export interface AccountQuoteListResponse {
@@ -99,6 +112,13 @@ export interface QuoteOrderPayload {
99
112
  /** The buyer's own order reference. */
100
113
  customerOrderNumber?: string;
101
114
  orderNote?: string;
115
+ /**
116
+ * Which positions to take. Left out, every position still open is taken —
117
+ * which is what the quotes app does with an acceptance carrying none, and
118
+ * what a merchant who does not allow a quote to be taken apart gets either
119
+ * way.
120
+ */
121
+ lineIds?: string[];
102
122
  }
103
123
 
104
124
  export interface QuoteOrderResult {
@@ -17,7 +17,15 @@ export type CartLineHintType =
17
17
  | "missing-cost-center"
18
18
  | "quantity-adjusted"
19
19
  | "replaced"
20
- | "duplicate";
20
+ | "duplicate"
21
+ /**
22
+ * This position cannot be ordered — the stock is not there and the
23
+ * inventories app does not allow backorders. What will HAPPEN to it is the
24
+ * orders app's policy, and the hint's message says which of the three it is,
25
+ * because "out of stock" and "this will be left out of your order" ask
26
+ * different things of the buyer.
27
+ */
28
+ | "not-orderable";
21
29
 
22
30
  export interface CartLineHint {
23
31
  type: CartLineHintType;