@revenexx/cover 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/app/api/account.ts +1 -0
  2. package/app/components/RevenexxForm.vue +183 -19
  3. package/app/components/account/address/AccountAddressCard.vue +8 -2
  4. package/app/components/account/address/AccountAddressView.vue +5 -1
  5. package/app/components/account/carts/AccountCartsTable.vue +85 -3
  6. package/app/components/account/dashboard/AccountDashboardBudgets.vue +2 -1
  7. package/app/components/account/dashboard/AccountDashboardRecentOrders.vue +2 -1
  8. package/app/components/account/dashboard/AccountDashboardRequisitions.vue +2 -1
  9. package/app/components/account/directorder/AccountDirectOrder.vue +100 -12
  10. package/app/components/account/governance/AccountApprovalLimitsTable.vue +124 -8
  11. package/app/components/account/governance/AccountCostCenterDetail.vue +3 -2
  12. package/app/components/account/governance/AccountCostCentersTable.vue +133 -6
  13. package/app/components/account/governance/AccountRequisitionDetail.vue +2 -1
  14. package/app/components/account/governance/AccountRequisitionsTable.vue +102 -6
  15. package/app/components/account/governance/AccountWorkflowDetail.vue +3 -2
  16. package/app/components/account/governance/AccountWorkflowsTable.vue +76 -1
  17. package/app/components/account/governance/GovernanceApprovalLimitModal.vue +8 -0
  18. package/app/components/account/governance/GovernanceCostCenterModal.vue +7 -0
  19. package/app/components/account/governance/GovernanceWorkflowModal.vue +7 -0
  20. package/app/components/account/orderlists/AccountOrderListDetail.vue +14 -4
  21. package/app/components/account/orderlists/AccountOrderListsTable.vue +115 -7
  22. package/app/components/account/orders/AccountOrderDetail.vue +67 -3
  23. package/app/components/account/orders/AccountOrderPay.vue +211 -0
  24. package/app/components/account/orders/AccountOrdersTable.vue +119 -10
  25. package/app/components/account/organization/AccountOrganization.vue +6 -0
  26. package/app/components/account/profile/AccountPasswordForm.vue +2 -0
  27. package/app/components/account/profile/AccountProfileForm.vue +4 -0
  28. package/app/components/account/quotes/AccountQuoteDetail.vue +7 -10
  29. package/app/components/account/team/AccountTeam.vue +91 -0
  30. package/app/components/auth/AuthLoginTeaser.vue +1 -1
  31. package/app/components/auth/AuthRegisterPanel.vue +22 -3
  32. package/app/components/cart/manage/CartNameModal.vue +4 -0
  33. package/app/components/checkout/onepage/CheckoutAddressSection.vue +5 -1
  34. package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +9 -1
  35. package/app/components/checkout/onepage/CheckoutSummarySection.vue +6 -1
  36. package/app/components/form/FormPage.vue +7 -4
  37. package/app/components/layout/footer/Footer.vue +15 -2
  38. package/app/components/layout/header/LocaleSwitcher.vue +79 -12
  39. package/app/components/ui/forms/PasswordInput.vue +2 -0
  40. package/app/components/ui/forms/SearchInput.vue +205 -8
  41. package/app/components/ui/table/TableCardList.vue +69 -0
  42. package/app/components/ui/table/TableSortButton.vue +1 -1
  43. package/app/components/ui/table/TableToolbar.vue +2 -0
  44. package/app/components/withdrawal/WithdrawalDeclaration.vue +286 -0
  45. package/app/composables/useCheckoutOnePage.ts +22 -0
  46. package/app/composables/useMobileTableSort.ts +82 -0
  47. package/app/composables/useProductCard.ts +14 -0
  48. package/app/composables/useProductListing.ts +27 -1
  49. package/app/composables/useSearchEvents.ts +67 -0
  50. package/app/config/forms.ts +8 -0
  51. package/app/config/navigation.ts +8 -0
  52. package/app/formkit.config.ts +21 -0
  53. package/app/interfaces/account/order-list.ts +11 -0
  54. package/app/interfaces/account/quotes.ts +7 -3
  55. package/app/interfaces/market.ts +7 -0
  56. package/app/pages/punchout/transfer.vue +36 -1
  57. package/app/pages/widerruf.vue +33 -0
  58. package/app/plugins/search-events.client.ts +41 -0
  59. package/app/shared/addressLines.ts +66 -0
  60. package/app/shared/checkoutAddressRefusal.ts +63 -0
  61. package/app/shared/locale.ts +133 -0
  62. package/app/shared/searchAttribution.ts +91 -0
  63. package/app/shared/themeEvents.ts +1 -1
  64. package/i18n/locales/de/account.json +13 -1
  65. package/i18n/locales/de/cart.json +1 -0
  66. package/i18n/locales/de/checkout.json +1 -1
  67. package/i18n/locales/de/common.json +7 -0
  68. package/i18n/locales/de/search.json +7 -0
  69. package/i18n/locales/de/withdrawal.json +34 -0
  70. package/i18n/locales/en/account.json +13 -1
  71. package/i18n/locales/en/cart.json +1 -0
  72. package/i18n/locales/en/checkout.json +1 -1
  73. package/i18n/locales/en/common.json +7 -0
  74. package/i18n/locales/en/search.json +7 -0
  75. package/i18n/locales/en/withdrawal.json +34 -0
  76. package/nuxt.config.ts +3 -0
  77. package/package.json +1 -1
  78. package/server/api/account/orders/[id]/pay.post.ts +100 -0
  79. package/server/api/account/orders/[id].get.ts +5 -1
  80. package/server/api/account/quotes/[id]/order.post.ts +22 -22
  81. package/server/api/brands.get.ts +3 -2
  82. package/server/api/categories/[slug]/subcategories.get.ts +9 -6
  83. package/server/api/forms/[slug].get.ts +1 -3
  84. package/server/api/orders/index.post.ts +33 -50
  85. package/server/api/products/index.get.ts +6 -1
  86. package/server/api/punchout/return.post.ts +3 -1
  87. package/server/api/search/events.post.ts +65 -0
  88. package/server/api/typesense/search.post.ts +12 -1
  89. package/server/api/typesense/suggest.post.ts +43 -22
  90. package/server/data/forms/authored.json +69 -8
  91. package/server/dev/errorHandler.ts +47 -0
  92. package/server/interfaces/brand.ts +3 -2
  93. package/server/interfaces/product.ts +5 -0
  94. package/server/interfaces/punchout.ts +5 -0
  95. package/server/middleware/missing-media.ts +35 -0
  96. package/server/middleware/punchout-hand-back-csp.ts +17 -0
  97. package/server/plugins/vue-devtools-sink.ts +28 -0
  98. package/server/services/ApiBrandService.ts +8 -8
  99. package/server/services/ApiMarketService.ts +9 -2
  100. package/server/services/ApiProductService.ts +1 -1
  101. package/server/services/MockFormsService.ts +3 -1
  102. package/server/utils/addressRefusal.ts +63 -0
  103. package/server/utils/country.ts +23 -0
  104. package/server/utils/forms.ts +23 -1
  105. package/server/utils/liveOrders.ts +44 -2
  106. package/server/utils/locale.ts +58 -4
  107. package/server/utils/orderPayment.ts +155 -0
  108. package/server/utils/punchoutFormAction.ts +44 -0
  109. package/server/utils/searchClient.ts +27 -4
  110. package/server/utils/searchEvents.ts +46 -0
  111. package/server/utils/searchMultiSearchFallback.ts +2 -0
  112. package/server/utils/searchSuggest.ts +207 -0
  113. package/server/utils/suggestTiles.ts +141 -0
@@ -0,0 +1,207 @@
1
+ import { searchLocaleKeys } from "../../app/shared/locale";
2
+ import type { LiveProductDoc } from "./liveCatalog";
3
+ import { preferLocaleDocs } from "./liveCatalog";
4
+ import type { SearchAction } from "./searchClient";
5
+ import { isSearchRouteMissing, normalizeSearchAction, searchClient } from "./searchClient";
6
+
7
+ /**
8
+ * The quick search (PE-867): products and the category, manufacturer and page
9
+ * tiles beside them, from ONE request to the search service's suggest
10
+ * endpoint. Each collection is searched with its own `suggest` preset; a
11
+ * collection the tenant does not have is simply not in the answer.
12
+ *
13
+ * A gateway without `POST /v1/search/suggest` answers 404/405. The quick
14
+ * search then asks the products' `suggest` view alone, as before, and has no
15
+ * tiles; that is remembered per tenant for a few minutes.
16
+ */
17
+
18
+ /** A category document of the `categories` collection (products app, search.json v3). */
19
+ export interface LiveCategoryDoc {
20
+ id: string;
21
+ entity_id: string;
22
+ code: string;
23
+ name: string;
24
+ /** The ancestors' names, root first, in the document's language. */
25
+ path?: string[];
26
+ /** The ancestors' codes, root first. */
27
+ parents?: string[];
28
+ image?: string;
29
+ product_count?: number;
30
+ locale: string;
31
+ }
32
+
33
+ /** A manufacturer document of the `manufacturers` collection. */
34
+ export interface LiveManufacturerDoc {
35
+ id: string;
36
+ entity_id: string;
37
+ code: string;
38
+ name: string;
39
+ logo?: string;
40
+ product_count?: number;
41
+ locale: string;
42
+ }
43
+
44
+ /** A page document of the `pages` collection (pages app). */
45
+ export interface LivePageDoc {
46
+ id: string;
47
+ entity_id: string;
48
+ title: string;
49
+ slug?: string;
50
+ locale: string;
51
+ }
52
+
53
+ export interface SearchSuggestResult {
54
+ /** `suggest` (one request, tiles) or `query` (the products-only fallback). */
55
+ source: "suggest" | "query" | "multi_search";
56
+ /** For search events; "" when the answer had none. */
57
+ queryId: string;
58
+ locale: string;
59
+ products: LiveProductDoc[];
60
+ categories: LiveCategoryDoc[];
61
+ manufacturers: LiveManufacturerDoc[];
62
+ pages: LivePageDoc[];
63
+ actions: SearchAction[];
64
+ }
65
+
66
+ export interface SearchSuggestParams {
67
+ readonly q: string;
68
+ readonly locale?: string;
69
+ /** Hits per collection; left to the presets when omitted. */
70
+ readonly perPage?: number;
71
+ }
72
+
73
+ /** The suggest endpoint's answer, as it comes off the wire. */
74
+ export interface SearchSuggestResponse {
75
+ query_id?: string;
76
+ locale?: string;
77
+ groups?: { collection: string; found?: number; hits?: { document: Record<string, unknown> }[] }[];
78
+ actions?: unknown[];
79
+ }
80
+
81
+ const SUGGEST_PATH = "/v1/search/suggest";
82
+ const ROUTE_MISSING_TTL_MS = 5 * 60 * 1000;
83
+ const routeMissingUntil = new Map<string, number>();
84
+ const routeMissingLogged = new Set<string>();
85
+
86
+ /** Clears the fallback memory — tests only. */
87
+ export function resetSearchSuggestState(): void {
88
+ routeMissingUntil.clear();
89
+ routeMissingLogged.clear();
90
+ }
91
+
92
+ /** Path, body and headers of the suggest request. */
93
+ export function buildSearchSuggestRequest(params: SearchSuggestParams): {
94
+ path: string;
95
+ body: Record<string, unknown>;
96
+ headers: Record<string, string>;
97
+ } {
98
+ const headers: Record<string, string> = {};
99
+ const locale = params.locale ? searchLocaleKeys(params.locale)[0] : undefined;
100
+ if (locale) {
101
+ headers["X-Revenexx-Locale"] = locale;
102
+ }
103
+ const body: Record<string, unknown> = { q: params.q.trim() };
104
+ if (params.perPage !== undefined) {
105
+ body.per_page = Math.min(20, Math.max(1, Math.floor(params.perPage)));
106
+ }
107
+ return { path: SUGGEST_PATH, body, headers };
108
+ }
109
+
110
+ function docsOf<T>(response: SearchSuggestResponse, collection: string): T[] {
111
+ const group = (response.groups ?? []).find(g => g.collection === collection);
112
+ return (group?.hits ?? [])
113
+ .map(hit => hit.document)
114
+ .filter((doc): doc is Record<string, unknown> => Boolean(doc)) as T[];
115
+ }
116
+
117
+ /** One tile per entity: a language and its region can both come back. */
118
+ function onePerEntity<T extends { entity_id?: string; id: string }>(docs: T[]): T[] {
119
+ const seen = new Set<string>();
120
+ return docs.filter((doc) => {
121
+ const key = doc.entity_id || doc.id;
122
+ if (seen.has(key)) {
123
+ return false;
124
+ }
125
+ seen.add(key);
126
+ return true;
127
+ });
128
+ }
129
+
130
+ /** The suggest endpoint's answer in the shape the quick search reads. */
131
+ export function mapSearchSuggestResponse(response: SearchSuggestResponse, params: SearchSuggestParams): SearchSuggestResult {
132
+ const products = docsOf<LiveProductDoc>(response, "products");
133
+ return {
134
+ source: "suggest",
135
+ queryId: response.query_id ?? "",
136
+ locale: response.locale ?? "",
137
+ products: params.locale ? preferLocaleDocs(products, params.locale) : products,
138
+ categories: onePerEntity(docsOf<LiveCategoryDoc>(response, "categories")),
139
+ manufacturers: onePerEntity(docsOf<LiveManufacturerDoc>(response, "manufacturers")),
140
+ pages: onePerEntity(docsOf<LivePageDoc>(response, "pages")),
141
+ actions: (response.actions ?? [])
142
+ .map(normalizeSearchAction)
143
+ .filter((action): action is SearchAction => action !== null),
144
+ };
145
+ }
146
+
147
+ function tenantKey(): string {
148
+ try {
149
+ return revenexxTenantKey();
150
+ }
151
+ catch {
152
+ return "";
153
+ }
154
+ }
155
+
156
+ async function productsOnly(params: SearchSuggestParams): Promise<SearchSuggestResult> {
157
+ const result = await searchClient.search({
158
+ view: "suggest",
159
+ q: params.q,
160
+ ...(params.perPage !== undefined ? { perPage: params.perPage } : {}),
161
+ ...(params.locale ? { locale: params.locale } : {}),
162
+ });
163
+ return {
164
+ source: result.source,
165
+ queryId: result.queryId,
166
+ locale: result.locale,
167
+ products: result.docs,
168
+ categories: [],
169
+ manufacturers: [],
170
+ pages: [],
171
+ actions: result.actions,
172
+ };
173
+ }
174
+
175
+ async function suggest(params: SearchSuggestParams): Promise<SearchSuggestResult> {
176
+ const tenant = tenantKey();
177
+ const missingUntil = routeMissingUntil.get(tenant);
178
+ if (missingUntil && missingUntil > Date.now()) {
179
+ return await productsOnly(params);
180
+ }
181
+
182
+ const request = buildSearchSuggestRequest(params);
183
+ try {
184
+ const response = await useRevenexxSdk().call<SearchSuggestResponse>("POST", request.path, {
185
+ body: request.body,
186
+ headers: request.headers,
187
+ });
188
+ routeMissingUntil.delete(tenant);
189
+ return mapSearchSuggestResponse(response ?? {}, params);
190
+ }
191
+ catch (err) {
192
+ if (!isSearchRouteMissing(err)) {
193
+ throw err;
194
+ }
195
+ routeMissingUntil.set(tenant, Date.now() + ROUTE_MISSING_TTL_MS);
196
+ if (!routeMissingLogged.has(tenant)) {
197
+ routeMissingLogged.add(tenant);
198
+ getLogService().warn(
199
+ `search: the gateway has no ${SUGGEST_PATH} route yet, the quick search shows products only`,
200
+ { tenant, ...apiErrorContext(err) },
201
+ );
202
+ }
203
+ return await productsOnly(params);
204
+ }
205
+ }
206
+
207
+ export const searchSuggestClient = { suggest };
@@ -0,0 +1,141 @@
1
+ import type { ProductCategory } from "../../app/config/navigation";
2
+ import type { LiveProductDoc } from "./liveCatalog";
3
+ import { liveImageSrc } from "./liveCatalog";
4
+ import type { LiveCategoryDoc, LiveManufacturerDoc, LivePageDoc } from "./searchSuggest";
5
+
6
+ /**
7
+ * What the quick search dropdown renders (PE-867). Paths are site paths
8
+ * without the locale prefix; the client localises them. `docId` (the
9
+ * record's id, the same in every language) goes back with the click event, so
10
+ * the analytics can tell which tile was taken.
11
+ */
12
+
13
+ export interface ProductSuggestion {
14
+ id: string;
15
+ docId: string;
16
+ name: string;
17
+ sku: string;
18
+ category: string;
19
+ categorySlug: string;
20
+ subcategorySlug?: string;
21
+ }
22
+
23
+ export interface CategoryTile {
24
+ docId: string;
25
+ code: string;
26
+ name: string;
27
+ /** The ancestors' names, root first — "Werkzeuge › Halter". */
28
+ path: string[];
29
+ image: string | null;
30
+ productCount: number;
31
+ to: string;
32
+ }
33
+
34
+ export interface ManufacturerTile {
35
+ docId: string;
36
+ code: string;
37
+ name: string;
38
+ logo: string | null;
39
+ productCount: number;
40
+ }
41
+
42
+ export interface PageTile {
43
+ docId: string;
44
+ title: string;
45
+ to: string;
46
+ }
47
+
48
+ export function productSuggestion(doc: LiveProductDoc): ProductSuggestion {
49
+ return {
50
+ id: doc.entity_id,
51
+ docId: doc.entity_id || doc.id,
52
+ name: doc.name,
53
+ sku: doc.sku,
54
+ category: doc.category_labels?.[0] ?? doc.categories?.[0] ?? "",
55
+ categorySlug: doc.categories?.[0] ?? "",
56
+ subcategorySlug: undefined,
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Where a category tile leads. The storefront navigates two levels (see
62
+ * buildLiveCategoryTree): a top-level category is `/category/<code>`, one
63
+ * below it `/category/<top>/<code>`. A category deeper than that opens the
64
+ * second-level page it sits under, which lists it — the storefront has no page
65
+ * of its own for it. A category outside the navigation (an import's stray
66
+ * root) leads nowhere and gets no tile.
67
+ */
68
+ export function categoryTilePath(doc: Pick<LiveCategoryDoc, "code" | "parents">, tree: readonly ProductCategory[]): string | null {
69
+ const chain = [...(doc.parents ?? []), doc.code];
70
+ const topIndex = chain.findIndex(code => tree.some(top => top.slug === code));
71
+ if (topIndex < 0) {
72
+ return null;
73
+ }
74
+ const top = tree.find(t => t.slug === chain[topIndex])!;
75
+ const sub = chain[topIndex + 1];
76
+ if (sub !== undefined && top.subcategories.some(s => s.slug === sub)) {
77
+ return `/category/${encodeURIComponent(top.slug)}/${encodeURIComponent(sub)}`;
78
+ }
79
+ return `/category/${encodeURIComponent(top.slug)}`;
80
+ }
81
+
82
+ export function categoryTiles(docs: LiveCategoryDoc[], tree: readonly ProductCategory[], limit: number): CategoryTile[] {
83
+ const shown = new Set(tree.map(t => t.slug));
84
+ const tiles: CategoryTile[] = [];
85
+ for (const doc of docs) {
86
+ const to = categoryTilePath(doc, tree);
87
+ if (!to) {
88
+ continue;
89
+ }
90
+ tiles.push({
91
+ docId: doc.entity_id || doc.id,
92
+ code: doc.code,
93
+ name: doc.name,
94
+ path: shopPath(doc, shown),
95
+ image: doc.image ? liveImageSrc(doc.image) : null,
96
+ productCount: doc.product_count ?? 0,
97
+ to,
98
+ });
99
+ if (tiles.length === limit) {
100
+ break;
101
+ }
102
+ }
103
+ return tiles;
104
+ }
105
+
106
+ /**
107
+ * The category's path as the shop shows it: an import's artificial root above
108
+ * the navigation is not part of it. Names and codes line up only when every
109
+ * ancestor has a name in this language; otherwise the names are kept as they
110
+ * are rather than cut at a guessed position.
111
+ */
112
+ function shopPath(doc: LiveCategoryDoc, shown: Set<string>): string[] {
113
+ const names = doc.path ?? [];
114
+ const codes = doc.parents ?? [];
115
+ if (names.length !== codes.length) {
116
+ return names;
117
+ }
118
+ const first = codes.findIndex(code => shown.has(code));
119
+ return first < 0 ? [] : names.slice(first);
120
+ }
121
+
122
+ export function manufacturerTiles(docs: LiveManufacturerDoc[], limit: number): ManufacturerTile[] {
123
+ return docs.slice(0, limit).map(doc => ({
124
+ docId: doc.entity_id || doc.id,
125
+ code: doc.code,
126
+ name: doc.name,
127
+ logo: doc.logo ? liveImageSrc(doc.logo) : null,
128
+ productCount: doc.product_count ?? 0,
129
+ }));
130
+ }
131
+
132
+ export function pageTiles(docs: LivePageDoc[], limit: number): PageTile[] {
133
+ return docs
134
+ .filter(doc => typeof doc.slug === "string" && doc.slug.trim() !== "")
135
+ .slice(0, limit)
136
+ .map(doc => ({
137
+ docId: doc.entity_id || doc.id,
138
+ title: doc.title,
139
+ to: `/${doc.slug!.trim().replace(/^\/+/, "")}`,
140
+ }));
141
+ }