@revenexx/cover 0.2.26 → 0.2.27

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 (79) hide show
  1. package/app/api/brands.ts +5 -0
  2. package/app/api/categories.ts +1 -0
  3. package/app/api/product.ts +2 -0
  4. package/app/app.config.ts +8 -0
  5. package/app/components/cart/quickadd/CartQuickAdd.vue +110 -34
  6. package/app/components/category/view/GridView.vue +34 -13
  7. package/app/components/category/view/ListView.vue +5 -5
  8. package/app/components/layout/AppLogo.vue +2 -1
  9. package/app/components/layout/footer/Footer.vue +9 -3
  10. package/app/components/layout/header/CategoryPanel.vue +92 -0
  11. package/app/components/layout/header/MainNav.vue +89 -2
  12. package/app/components/listing/ListingResults.vue +16 -2
  13. package/app/components/listing/ListingSubcategories.vue +124 -0
  14. package/app/components/product/card/Compact.vue +144 -0
  15. package/app/components/product/detail/ProductDetailAssociations.vue +96 -0
  16. package/app/components/product/detail/ProductDetailIdentity.vue +50 -5
  17. package/app/components/product/detail/ProductDetailVariantRow.vue +139 -0
  18. package/app/components/product/detail/ProductDetailVariants.vue +613 -0
  19. package/app/components/product/media/ProductMediaImage.vue +70 -0
  20. package/app/components/ui/forms/SearchInput.vue +14 -2
  21. package/app/components/ui/media/ImageSlider.vue +158 -0
  22. package/app/composables/useBranding.ts +22 -0
  23. package/app/composables/useBrands.ts +42 -0
  24. package/app/composables/useCategories.ts +55 -1
  25. package/app/composables/useProduct.ts +5 -4
  26. package/app/composables/useProductAssociations.ts +35 -0
  27. package/app/composables/useProductImage.ts +35 -2
  28. package/app/composables/useProductVariants.ts +46 -0
  29. package/app/composables/useSearchListing.ts +16 -5
  30. package/app/composables/useSubcategoryTiles.ts +36 -0
  31. package/app/config/navigation.ts +9 -0
  32. package/app/config/palette.ts +1 -0
  33. package/app/config/quickActions.ts +137 -0
  34. package/app/config/themes.ts +1 -0
  35. package/app/interfaces/brand.ts +16 -0
  36. package/app/interfaces/category.ts +45 -0
  37. package/app/interfaces/image-slider.ts +18 -0
  38. package/app/interfaces/product-associations.ts +32 -0
  39. package/app/interfaces/product-detail.ts +6 -0
  40. package/app/interfaces/product-variants.ts +73 -0
  41. package/i18n/locales/de/account.json +17 -0
  42. package/i18n/locales/de/cart.json +5 -1
  43. package/i18n/locales/de/common.json +42 -2
  44. package/i18n/locales/de/editor.json +91 -0
  45. package/i18n/locales/de/product.json +48 -2
  46. package/i18n/locales/de/search.json +4 -2
  47. package/i18n/locales/en/account.json +17 -0
  48. package/i18n/locales/en/cart.json +4 -0
  49. package/i18n/locales/en/common.json +42 -2
  50. package/i18n/locales/en/editor.json +91 -0
  51. package/i18n/locales/en/product.json +47 -1
  52. package/i18n/locales/en/search.json +3 -1
  53. package/nuxt.config.ts +10 -0
  54. package/package.json +3 -1
  55. package/public/img/brands/revenexx.svg +39 -0
  56. package/server/api/brands.get.ts +27 -0
  57. package/server/api/categories/[slug]/subcategories.get.ts +280 -0
  58. package/server/api/product/[id]/associations.get.ts +27 -0
  59. package/server/api/product/[id]/variants.get.ts +27 -0
  60. package/server/api/quick-actions.get.ts +43 -0
  61. package/server/api/typesense/search.post.ts +116 -13
  62. package/server/data/categories.json +5 -0
  63. package/server/data/product-associations.json +44 -0
  64. package/server/data/product-detail.json +346 -0
  65. package/server/data/product-list.json +340 -0
  66. package/server/data/product-variant-models.json +75 -0
  67. package/server/interfaces/brand.ts +17 -0
  68. package/server/interfaces/product.ts +14 -0
  69. package/server/services/ApiBrandService.ts +110 -0
  70. package/server/services/ApiProductService.ts +43 -9
  71. package/server/services/LocalFileProductService.ts +200 -6
  72. package/server/services/MockBrandService.ts +52 -0
  73. package/server/utils/brandService.ts +24 -0
  74. package/server/utils/contentTenant.ts +67 -0
  75. package/server/utils/liveCatalog.ts +744 -46
  76. package/server/utils/productService.ts +6 -1
  77. package/server/utils/productsSchema.ts +5 -2
  78. package/server/utils/revenexxCredentials.ts +258 -0
  79. package/server/utils/revenexxSdk.ts +38 -47
@@ -240,6 +240,23 @@
240
240
  "noRequisitions": "No open requisitions.",
241
241
  "noBudgets": "No budgets configured."
242
242
  },
243
+ "quickActions": {
244
+ "directOrder": { "title": "Quick entry", "description": "Enter article numbers directly" },
245
+ "orderLists": { "description": "Recurring requirements" },
246
+ "orders": { "description": "Status & reordering" },
247
+ "cart": { "description": "Go to checkout" },
248
+ "dashboard": { "description": "Your account at a glance" },
249
+ "carts": { "description": "Saved shopping carts" },
250
+ "requisitions": { "description": "Request and track approvals" },
251
+ "approvals": { "description": "Handle pending approvals" },
252
+ "costCenters": { "description": "Budgets and allocation" },
253
+ "workflows": { "description": "Manage approval processes" },
254
+ "profile": { "description": "Master data and password" },
255
+ "organization": { "description": "Manage your organization" },
256
+ "team": { "description": "Access and roles" },
257
+ "preferences": { "description": "Defaults for your orders" },
258
+ "addresses": { "description": "Delivery and billing addresses" }
259
+ },
243
260
  "comingSoon": {
244
261
  "title": "In development",
245
262
  "description": "This area is part of the product roadmap and will be built here.",
@@ -133,6 +133,10 @@
133
133
  "add": "Add",
134
134
  "added": "Added {quantity}× {name}"
135
135
  },
136
+ "quickOrder": {
137
+ "title": "Straight to your order",
138
+ "description": "Enter an article number or article name, choose a quantity and add it straight to the cart."
139
+ },
136
140
  "requisition": {
137
141
  "title": "Requisition",
138
142
  "meta": "Requested by {name} on {date}",
@@ -10,7 +10,13 @@
10
10
  "services": "Services",
11
11
  "knowledge": "Knowledge",
12
12
  "mainNavigation": "Main navigation",
13
- "backToShop": "Back to shop"
13
+ "backToShop": "Back to shop",
14
+ "catalog": {
15
+ "loading": "Loading product groups…",
16
+ "showAllGroups": "all {count} groups",
17
+ "browseAll": "Browse the whole catalogue",
18
+ "groupCount": "{count} product groups"
19
+ }
14
20
  },
15
21
  "summary": {
16
22
  "subtotal": "Subtotal",
@@ -30,7 +36,30 @@
30
36
  "appName": "Cover",
31
37
  "footer": {
32
38
  "tagline": "B2B supply solutions for modern businesses.",
33
- "copyright": "© {year} Cover Corp — All rights reserved."
39
+ "copyright": "© {year} Cover Corp — All rights reserved.",
40
+ "columns": {
41
+ "products": {
42
+ "heading": "Products",
43
+ "all": "All products",
44
+ "new": "New arrivals",
45
+ "featured": "Featured",
46
+ "catalog": "Catalogue"
47
+ },
48
+ "account": {
49
+ "heading": "Account",
50
+ "orders": "Orders",
51
+ "invoices": "Invoices",
52
+ "lists": "Lists",
53
+ "contracts": "Contracts"
54
+ },
55
+ "support": {
56
+ "heading": "Support",
57
+ "contact": "Contact",
58
+ "docs": "Documentation",
59
+ "status": "System status",
60
+ "quote": "Request a quote"
61
+ }
62
+ }
34
63
  },
35
64
  "topbar": {
36
65
  "freeShipping": "Free shipping on orders over €100",
@@ -76,5 +105,16 @@
76
105
  "placeholder": "Pick a date…",
77
106
  "clear": "Clear"
78
107
  }
108
+ },
109
+ "slider": {
110
+ "region": "Campaigns",
111
+ "slide": "Slide {index}",
112
+ "previous": "Previous slide",
113
+ "next": "Next slide"
114
+ },
115
+ "legal": {
116
+ "privacy": "Privacy policy",
117
+ "terms": "Terms of service",
118
+ "cookies": "Cookie policy"
79
119
  }
80
120
  }
@@ -3,6 +3,97 @@
3
3
  "provider": {
4
4
  "editLabel": "Edit page"
5
5
  },
6
+ "pages": {
7
+ "title": "Pages",
8
+ "description": "This tenant's pages. Pick one to open it in the editor.",
9
+ "searchPlaceholder": "Search by title or slug …",
10
+ "columns": {
11
+ "title": "Title",
12
+ "slug": "Slug",
13
+ "status": "Status",
14
+ "updated": "Updated"
15
+ },
16
+ "edit": "Edit",
17
+ "view": "View",
18
+ "reload": "Reload",
19
+ "empty": "No pages found.",
20
+ "count": "{count} pages",
21
+ "mode": {
22
+ "live": "Live API",
23
+ "mock": "Local demo data"
24
+ },
25
+ "tenant": {
26
+ "label": "Tenant",
27
+ "hint": "Content, navigation and theme settings come from this tenant."
28
+ },
29
+ "create": {
30
+ "button": "New page",
31
+ "title": "Create a page",
32
+ "fields": {
33
+ "title": "Title",
34
+ "slug": "Slug",
35
+ "bundle": "Bundle"
36
+ },
37
+ "placeholders": {
38
+ "title": "About us",
39
+ "slug": "about-us"
40
+ },
41
+ "slugHelp": "Lowercase letters, digits, \"-\" and \"/\" for nested paths.",
42
+ "bundleHelp": "Always treated as \"standard\" locally; the value only takes effect once the page is promoted and served by the live API.",
43
+ "warnings": {
44
+ "routeSlug": "This slug belongs to a named route — the page will not be reachable at that path."
45
+ },
46
+ "errors": {
47
+ "duplicate": "A page with this slug already exists.",
48
+ "invalidSlug": "Lowercase letters and digits only, separated by \"-\" or \"/\"."
49
+ },
50
+ "cancel": "Cancel",
51
+ "submit": "Create and edit",
52
+ "saved": "Page created.",
53
+ "error": "The page could not be created."
54
+ },
55
+ "localOverride": {
56
+ "badge": "local copy",
57
+ "baselineBadge": "committed baseline",
58
+ "hint": "Local working copy {file} (changed {modified}) overrides the committed baseline. Delete the file to reset, copy it over {baseFile} to promote.",
59
+ "invalid": "{file} is not valid JSON and is being ignored — showing the committed baseline instead.",
60
+ "baselineHint": "Showing the committed baseline. The local working copy {file} is untouched and read-only — switch back to it to edit.",
61
+ "source": {
62
+ "label": "Content source",
63
+ "local": "Local working copy",
64
+ "baseline": "Committed baseline"
65
+ }
66
+ },
67
+ "liveData": {
68
+ "label": "Live catalogue data",
69
+ "hint": "Products, categories, prices and stock come from this tenant's API instead of the demo data.",
70
+ "hintFrom": "Products, categories, prices and stock come from gateway tenant “{gateway}” instead of the demo data.",
71
+ "unavailable": "No API credentials resolve for “{tenant}” — neither an entry of its own (NUXT_REVENEXX_TENANTS) nor the env pair (NUXT_REVENEXX_TENANT / NUXT_REVENEXX_API_KEY)."
72
+ }
73
+ },
74
+ "canvas": {
75
+ "noData": "No data",
76
+ "productMissing": {
77
+ "title": "Sample product not found",
78
+ "description": "The stored product id “{id}” does not exist in this tenant's catalogue, so the preview stays empty. On a real product URL the product comes from the path.",
79
+ "descriptionNoId": "The catalogue returns no product to preview for this tenant. On a real product URL the product comes from the path."
80
+ },
81
+ "productFallback": {
82
+ "title": "Preview shows a different product",
83
+ "description": "The stored product id “{id}” does not exist in the active catalogue, so “{name}” is previewed instead. Pick the right tenant and switch “Live catalogue data” on to preview the pinned product."
84
+ },
85
+ "blocks": {
86
+ "product_gallery": "Gallery",
87
+ "product_identity": "Product header",
88
+ "product_stock": "Availability",
89
+ "product_add_to_cart": "Add to cart",
90
+ "product_pricing": "Volume pricing",
91
+ "product_description": "Description",
92
+ "product_specifications": "Specifications",
93
+ "product_variants": "Variants",
94
+ "product_associations": "Accessories & references"
95
+ }
96
+ },
6
97
  "appearance": {
7
98
  "colorScheme": {
8
99
  "title": "Color scheme"
@@ -3,6 +3,30 @@
3
3
  "sku": "SKU",
4
4
  "description": "Description",
5
5
  "specifications": "Specifications",
6
+ "associations": {
7
+ "mandatoryNote": "must be ordered along"
8
+ },
9
+ "variants": {
10
+ "title": "Variants",
11
+ "count": "{count} variant | {count} variants",
12
+ "countFiltered": "{shown} of {total}",
13
+ "filterSkuAria": "Filter by item number",
14
+ "availableOnly": "In stock only",
15
+ "chipAvailable": "In stock",
16
+ "clearAxis": "Clear",
17
+ "resetAll": "Reset all",
18
+ "reset": "Reset",
19
+ "empty": "No variant matches these filters.",
20
+ "notOrderable": "Not orderable",
21
+ "addToCartAria": "Add to cart: {sku}",
22
+ "sortBy": "Sort by {column}",
23
+ "showAll": "Show all {count} variants",
24
+ "columns": {
25
+ "name": "Description",
26
+ "price": "Price",
27
+ "availability": "Availability"
28
+ }
29
+ },
6
30
  "pricing": {
7
31
  "volumePricing": "Volume Pricing",
8
32
  "minQuantity": "Min. Quantity",
@@ -20,7 +44,10 @@
20
44
  },
21
45
  "price": {
22
46
  "from": "from",
23
- "onRequest": "Price on request"
47
+ "onRequest": "Price on request",
48
+ "inclTax": "incl. VAT",
49
+ "exclTax": "excl. VAT",
50
+ "volume": "Volume pricing available"
24
51
  },
25
52
  "actions": {
26
53
  "info": "Info",
@@ -66,6 +93,25 @@
66
93
  "delivery": "Delivery in 1–3 working days",
67
94
  "paymentTerms": "Buy on invoice — 30 days net",
68
95
  "volume": "Volume pricing for bulk orders"
96
+ },
97
+ "grid": {
98
+ "count": "{count} item | {count} items",
99
+ "error": "Products could not be loaded",
100
+ "noSelection": {
101
+ "title": "No category or brand selected",
102
+ "description": "Pick a category or a brand in the block options."
103
+ },
104
+ "empty": {
105
+ "title": "No products found",
106
+ "description": "There are currently no products for this selection."
107
+ }
108
+ },
109
+ "brandGrid": {
110
+ "error": "Brands could not be loaded",
111
+ "empty": {
112
+ "title": "No brands found",
113
+ "description": "The catalogue currently lists no manufacturer."
114
+ }
69
115
  }
70
116
  }
71
117
  }
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "results": {
10
10
  "title": "Search results for \"{query}\"",
11
+ "catalogTitle": "Catalog",
11
12
  "count": "{count} result | {count} results",
12
13
  "error": "Search failed",
13
14
  "emptyTitle": "No matches",
@@ -50,7 +51,8 @@
50
51
  },
51
52
  "category": {
52
53
  "searchPlaceholder": "Search within this category…",
53
- "allProducts": "All products"
54
+ "allProducts": "All products",
55
+ "productCount": "{count} product | {count} products"
54
56
  }
55
57
  }
56
58
  }
package/nuxt.config.ts CHANGED
@@ -76,6 +76,16 @@ export default defineNuxtConfig({
76
76
  revenexxApiUrl: "https://api.revenexx.com",
77
77
  revenexxTenant: "",
78
78
  revenexxApiKey: "",
79
+ // Per-content-tenant gateway credentials, keyed by the `cover-tenant`
80
+ // cookie: {"eltric":{"tenant":"eltric","apiKey":"rvxk_…"}}. Lets one dev
81
+ // server serve several tenants' real catalogues (server/utils/
82
+ // revenexxCredentials.ts). Nitro destr()s NUXT_* values, so the env form
83
+ // arrives here already parsed — the parser accepts both shapes.
84
+ //
85
+ // DEV/PREVIEW ONLY. A deployed Site gets its tenant from the brokered
86
+ // request context, and a populated map here would let the cover-tenant
87
+ // cookie pick which tenant's API key the BFF authenticates with.
88
+ revenexxTenants: "",
79
89
  typesenseHost: "localhost",
80
90
  typesensePort: 8108,
81
91
  typesenseProtocol: "http",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -26,6 +26,8 @@
26
26
  "./composables/*": "./app/composables/*.ts",
27
27
  "./config/*": "./app/config/*.ts",
28
28
  "./interfaces/*": "./app/interfaces/*.ts",
29
+ "./server/services/*": "./server/services/*.ts",
30
+ "./server/utils/*": "./server/utils/*.ts",
29
31
  "./shared/*": "./app/shared/*.ts",
30
32
  "./validations/*": "./app/validations/*.ts"
31
33
  },
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ Manufacturer logo of the demo catalogue's own brand "revenexx" — the single
4
+ brand the bundled demo data carries a logo for, so the product detail's
5
+ identity block can show what a real catalogue logo looks like (third-party
6
+ demo brands stay logo-less on purpose and render no logo at all).
7
+
8
+ Same wordmark as apps/website/public/brand/logo/, recoloured for a light
9
+ product page: violet wordmark and mark, white glyph inside the mark.
10
+ -->
11
+ <svg id="LOGO" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 2858.64 427.65">
12
+ <defs>
13
+ <style>
14
+ .st0 {
15
+ fill: #fff;
16
+ }
17
+
18
+ .st1 {
19
+ fill: #2d009e;
20
+ }
21
+ </style>
22
+ </defs>
23
+ <g>
24
+ <path class="st1" d="M2783.61,359.02l-71.98-99.61-65.46,99.61h-70.85l101.43-148.22-102-141.61h73.19l72.62,100.81,67.85-100.81h70.23l-103.2,148.79,101.43,141.04h-73.26Z"/>
25
+ <path class="st1" d="M2460.31,359.02l-72.01-99.61-65.44,99.61h-70.87l101.45-148.22-102.02-141.61h73.21l72.62,100.81,67.85-100.81h70.23l-103.23,148.79,101.45,141.04h-73.26.02Z"/>
26
+ <path class="st1" d="M2225.22,196.99c0-78.62-52.84-136.18-133.28-136.18s-136.26,59.39-136.26,153.01,58.27,153.02,141.11,153.02c61.23,0,105.68-34.8,126.03-89.4l-52.2-16.77c-12.6,30.01-36.06,49.18-72.05,49.18-46.22,0-74.46-32.4-79.83-79.82h204.72c1.21-11.98,1.77-25.22,1.77-32.97v-.06h-.01ZM2019.92,183.81c7.82-39.59,31.83-66.01,72.05-66.01,43.84,0,67.21,31.77,72.08,66.01h-144.13Z"/>
27
+ <path class="st1" d="M1842.58,195.79c0-53.4-24.03-76.79-60.03-76.79-43.81,0-68.39,35.43-68.39,87v153.01h-64.82V69.19h58.82v52.2c18.03-37.83,50.43-60.59,97.22-60.59,60.03,0,102.07,37.83,102.07,113.42v184.79h-64.8v-163.23h-.07,0Z"/>
28
+ <path class="st1" d="M1596.81,196.99c0-78.62-52.84-136.18-133.28-136.18s-136.25,59.39-136.25,153.01,58.26,153.02,141.04,153.02c61.21,0,105.66-34.8,126.03-89.4l-52.2-16.77c-12.62,30.01-36,49.18-72.06,49.18-46.21,0-74.46-32.4-79.82-79.82h204.72c1.18-11.98,1.82-25.22,1.82-32.97v-.06h0ZM1391.53,183.81c7.82-39.59,31.84-66.01,72.06-66.01,43.82,0,67.21,31.77,72.05,66.01h-144.12,0Z"/>
29
+ <path class="st1" d="M1142.88,359.02l-112.85-289.83h67.27l74.4,205.22,73.83-205.22h67.27l-112.85,289.83h-57.07Z"/>
30
+ <path class="st1" d="M1016.53,196.99c0-78.62-52.83-136.18-133.28-136.18s-136.24,59.39-136.24,153.01,58.25,153.02,141.04,153.02c61.22,0,105.67-34.8,126.03-89.4l-52.2-16.77c-12.61,30.01-36,49.18-72.06,49.18-46.21,0-74.46-32.4-79.82-79.82h204.71c1.2-11.98,1.83-25.22,1.83-32.97v-.06h-.01ZM811.18,183.81c7.82-39.59,31.84-66.01,72.06-66.01,43.82,0,67.21,31.77,72.06,66.01h-144.13.01Z"/>
31
+ <path class="st1" d="M557.8,359.02V69.19h59.45v56.99c15.01-43.19,43.82-65.38,85.24-65.38,10.78,0,19.8,1.2,25.79,2.39v65.38c-9.58-2.39-18.03-3.03-25.22-3.03-46.84,0-79.82,34.17-79.82,112.22v121.18h-65.44v.08Z"/>
32
+ </g>
33
+ <g id="Layer_3">
34
+ <g>
35
+ <path class="st1" d="M38.36,0h347.67c21.17,0,38.36,17.19,38.36,38.36v350.93c0,21.17-17.19,38.36-38.36,38.36H38.36c-21.17,0-38.36-17.19-38.36-38.36V38.36C0,17.19,17.19,0,38.36,0Z"/>
36
+ <path class="st0" d="M62.03,248.41l81.87,47.21c13.57,7.84,21.92,22.3,21.92,38.04v26.37l47.72-27.71v-26.38c0-15.67-8.35-30.19-21.92-38.03l-69.7-40.2c-7.52-4.33-16.82-4.33-24.34,0l-35.49,20.65-.06.06h0ZM218.56,246.83c13.63,7.84,22.04,22.36,22.04,38.04v32.04l47.85-27.59v-32.04c0-15.74-8.41-30.26-22.04-38.04l-122-70.01c-7.52-4.33-16.76-4.33-24.27,0l-35.68,20.58,134.11,76.96v.06h-.01ZM340.7,170.06c13.57,7.83,21.98,22.29,21.98,38.03v38.1l-47.72,27.71v-38.09c0-15.67-8.35-30.2-21.98-38.04L107.46,90.86l35.61-20.64c7.52-4.4,16.82-4.4,24.34,0l173.35,99.9-.06-.06h0Z"/>
37
+ </g>
38
+ </g>
39
+ </svg>
@@ -0,0 +1,27 @@
1
+ /** Grid sizes the block offers top out at 12; 24 leaves room without inviting a scrape. */
2
+ const MAX_LIMIT = 24;
3
+ const DEFAULT_LIMIT = 8;
4
+
5
+ export default defineEventHandler(async (event) => {
6
+ const query = getQuery(event);
7
+ // `all=1` answers the complete manufacturer list without logos — the shape
8
+ // a picker needs. The limit cap only guards the logo-enriched default mode.
9
+ const wantsAll = String(query.all ?? "") === "1";
10
+
11
+ const parsed = Number.parseInt(String(query.limit ?? ""), 10);
12
+ const limit = Number.isFinite(parsed)
13
+ ? Math.min(Math.max(parsed, 1), MAX_LIMIT)
14
+ : DEFAULT_LIMIT;
15
+
16
+ try {
17
+ const service = getBrandService(event);
18
+ const locale = resolveLocale(event);
19
+ return wantsAll
20
+ ? await service.listBrandNames(locale)
21
+ : await service.listBrands(limit, locale);
22
+ }
23
+ catch (err) {
24
+ getLogService().error("Service error: brands/list", toErrorContext(err));
25
+ throw createError({ statusCode: 500, message: "Internal server error" });
26
+ }
27
+ });
@@ -0,0 +1,280 @@
1
+ import type { ProductSubcategory } from "../../../../app/config/navigation";
2
+ import type { SubcategoryTile } from "../../../../app/interfaces/category";
3
+ import type { Locale } from "../../../utils/locale";
4
+
5
+ import {
6
+ liveCategorySubtreeCodes,
7
+ liveSubcategoryIndex,
8
+ mapLiveDocToProduct,
9
+ rollUpSubcategoryCounts,
10
+ searchLiveProducts,
11
+ searchLiveProductsMulti,
12
+ tsFilterValue,
13
+ } from "../../../utils/liveCatalog";
14
+ import { PRODUCTS_COLLECTION } from "../../../utils/productsSchema";
15
+
16
+ /**
17
+ * The subcategory card grid's data: one category's children, each with a product
18
+ * count and a preview image.
19
+ *
20
+ * Neither category tree carries either fact — `ProductSubcategory` is
21
+ * label/slug/icon — so both are derived from the product index. The tree stays
22
+ * authoritative for which children exist and in what order; the index only
23
+ * enriches them.
24
+ *
25
+ * Counts and images are fetched INDEPENDENTLY, each best-effort. They used to
26
+ * share one grouped query, and that cost both: Typesense counts GROUPS rather
27
+ * than documents in `facet_counts` whenever `group_by` is active, so the counts
28
+ * came back as "how many leaf codes" instead of "how many products" (28 where
29
+ * the facet rail rightly said 698), and the grouped hits never yielded an image
30
+ * because `categories` is an array field whose group keys are not bare leaf
31
+ * codes. Splitting them also means an image failure can no longer take the
32
+ * counts down with it, and a category page never 500s because the index is
33
+ * unseeded or unreachable in dev: the tiles then keep `productCount: 0` and
34
+ * `image: null`, which the grid renders as its icon variant.
35
+ */
36
+
37
+ /** Typesense's ceiling for `max_facet_values` — 250 is its own limit. */
38
+ const MAX_SUBCATEGORY_VALUES = 250;
39
+
40
+ /**
41
+ * Sub-searches per multi_search request. Typesense's `limit_multi_searches`
42
+ * defaults to 50; staying under it keeps a category with many children working.
43
+ */
44
+ const SEARCH_BATCH_SIZE = 40;
45
+
46
+ /** Narrowed shape of the mock index's multi_search response. */
47
+ interface MockMultiSearchResponse {
48
+ results?: {
49
+ facet_counts?: { field_name: string; counts?: { value: string; count: number }[] }[];
50
+ hits?: { document: { image?: string } }[];
51
+ }[];
52
+ }
53
+
54
+ function chunk<T>(items: readonly T[], size: number): T[][] {
55
+ const batches: T[][] = [];
56
+ for (let i = 0; i < items.length; i += size) {
57
+ batches.push(items.slice(i, i + size));
58
+ }
59
+ return batches;
60
+ }
61
+
62
+ function toTiles(
63
+ subcategories: readonly ProductSubcategory[],
64
+ counts: Map<string, number>,
65
+ images: Map<string, string>,
66
+ ): SubcategoryTile[] {
67
+ return subcategories.map(sub => ({
68
+ slug: sub.slug,
69
+ label: sub.label,
70
+ icon: sub.icon,
71
+ productCount: counts.get(sub.slug) ?? 0,
72
+ image: images.get(sub.slug) ?? null,
73
+ }));
74
+ }
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Live index — products are indexed at their LEAF category, so a direct child's
78
+ // products are spread over every code beneath it.
79
+ // ---------------------------------------------------------------------------
80
+
81
+ /** `locale:=… && enabled:=true && categories:=[…]`, the live catalogue's baseline. */
82
+ function liveFilter(locale: Locale, codes: readonly string[]): string {
83
+ return [
84
+ `locale:=${tsFilterValue(locale)}`,
85
+ "enabled:=true",
86
+ `categories:=[${codes.map(tsFilterValue).join(",")}]`,
87
+ ].join(" && ");
88
+ }
89
+
90
+ /**
91
+ * Product counts per direct child. Deliberately the same call shape
92
+ * `api/typesense/search.post.ts` makes for its derived `subcategory` facet, so
93
+ * the cards and the filter rail can never disagree.
94
+ */
95
+ async function liveCounts(categorySlug: string, locale: Locale): Promise<Map<string, number>> {
96
+ const { branchOf } = await liveSubcategoryIndex(categorySlug, locale);
97
+ const leafCodes = await liveCategorySubtreeCodes([categorySlug]);
98
+ if (!leafCodes.length) {
99
+ return new Map();
100
+ }
101
+
102
+ const results = await searchLiveProducts({
103
+ q: "*",
104
+ filterBy: liveFilter(locale, leafCodes),
105
+ facetBy: "categories",
106
+ maxFacetValues: MAX_SUBCATEGORY_VALUES,
107
+ perPage: 1,
108
+ });
109
+
110
+ return rollUpSubcategoryCounts(
111
+ results.facet_counts?.find(fc => fc.field_name === "categories")?.counts ?? [],
112
+ branchOf,
113
+ );
114
+ }
115
+
116
+ /**
117
+ * One representative product image per direct child: a 1-hit search per child,
118
+ * batched into as few multi_search requests as possible.
119
+ *
120
+ * Per child rather than one big page of hits, because a page is capped at 250
121
+ * documents and a category with thousands of products would leave most children
122
+ * imageless — which is exactly how this looked when it was broken.
123
+ */
124
+ async function liveImages(categorySlug: string, locale: Locale): Promise<Map<string, string>> {
125
+ const { branchOf } = await liveSubcategoryIndex(categorySlug, locale);
126
+
127
+ // Invert leaf → child into child → its leaves. No extra catalogue call: the
128
+ // index is already loaded and cached per tenant.
129
+ const leavesByChild = new Map<string, string[]>();
130
+ for (const [leaf, child] of branchOf) {
131
+ const leaves = leavesByChild.get(child) ?? [];
132
+ leaves.push(leaf);
133
+ leavesByChild.set(child, leaves);
134
+ }
135
+
136
+ const children = [...leavesByChild.keys()];
137
+ const images = new Map<string, string>();
138
+
139
+ for (const batch of chunk(children, SEARCH_BATCH_SIZE)) {
140
+ const results = await searchLiveProductsMulti(batch.map(child => ({
141
+ q: "*",
142
+ filterBy: liveFilter(locale, leavesByChild.get(child) ?? [child]),
143
+ perPage: 1,
144
+ })));
145
+
146
+ batch.forEach((child, index) => {
147
+ const doc = results[index]?.hits?.[0]?.document;
148
+ if (doc) {
149
+ images.set(child, mapLiveDocToProduct(doc).image);
150
+ }
151
+ });
152
+ }
153
+
154
+ return images;
155
+ }
156
+
157
+ // ---------------------------------------------------------------------------
158
+ // Mock index — products carry `subcategorySlug` directly, so both halves read
159
+ // that one field. Same two-step shape as the live branch on purpose.
160
+ // ---------------------------------------------------------------------------
161
+
162
+ /** `categorySlug:=[…]`, the clause both mock halves are pinned to. */
163
+ function mockCategoryFilter(categorySlug: string): string {
164
+ return `categorySlug:=[${tsFilterValue(categorySlug)}]`;
165
+ }
166
+
167
+ /**
168
+ * Run a runtime-built list of searches against the mock index.
169
+ *
170
+ * The client's `multiSearch.perform` typings are generic over a TUPLE of
171
+ * document schemas and cannot describe a list whose length is only known at
172
+ * runtime, so the response is narrowed here — the one boundary cast.
173
+ */
174
+ async function mockMultiSearch(
175
+ searches: readonly Record<string, unknown>[],
176
+ ): Promise<NonNullable<MockMultiSearchResponse["results"]>> {
177
+ const results: NonNullable<MockMultiSearchResponse["results"]> = [];
178
+ for (const batch of chunk(searches, SEARCH_BATCH_SIZE)) {
179
+ const response = await useTypesense()
180
+ .multiSearch
181
+ .perform({ searches: batch }) as unknown as MockMultiSearchResponse;
182
+ results.push(...(response.results ?? []));
183
+ }
184
+ return results;
185
+ }
186
+
187
+ async function mockCounts(categorySlug: string): Promise<Map<string, number>> {
188
+ const [result] = await mockMultiSearch([{
189
+ collection: PRODUCTS_COLLECTION,
190
+ q: "*",
191
+ query_by: "name",
192
+ filter_by: mockCategoryFilter(categorySlug),
193
+ facet_by: "subcategorySlug",
194
+ max_facet_values: MAX_SUBCATEGORY_VALUES,
195
+ per_page: 1,
196
+ }]);
197
+
198
+ const counts = result?.facet_counts?.find(fc => fc.field_name === "subcategorySlug")?.counts ?? [];
199
+ return new Map(counts.map(c => [c.value, c.count]));
200
+ }
201
+
202
+ async function mockImages(
203
+ categorySlug: string,
204
+ subcategories: readonly ProductSubcategory[],
205
+ ): Promise<Map<string, string>> {
206
+ // Unique slugs: categories.json ships a category whose subcategories repeat
207
+ // a slug, and a second search for the same slug would be wasted.
208
+ const slugs = [...new Set(subcategories.map(sub => sub.slug))];
209
+
210
+ const results = await mockMultiSearch(slugs.map(slug => ({
211
+ collection: PRODUCTS_COLLECTION,
212
+ q: "*",
213
+ query_by: "name",
214
+ filter_by: `${mockCategoryFilter(categorySlug)} && subcategorySlug:=[${tsFilterValue(slug)}]`,
215
+ include_fields: "image",
216
+ per_page: 1,
217
+ })));
218
+
219
+ const images = new Map<string, string>();
220
+ slugs.forEach((slug, index) => {
221
+ const image = results[index]?.hits?.[0]?.document.image;
222
+ if (image) {
223
+ images.set(slug, image);
224
+ }
225
+ });
226
+ return images;
227
+ }
228
+
229
+ export default defineEventHandler(async (event): Promise<SubcategoryTile[]> => {
230
+ const locale = resolveLocale(event);
231
+ const slug = getRouterParam(event, "slug");
232
+ if (!slug) {
233
+ throw createError({ status: 400, message: "Missing slug" });
234
+ }
235
+
236
+ const category = await getCategoryService(event)
237
+ .getCategoryBySlug(slug, locale)
238
+ .catch((err: unknown) => {
239
+ getLogService().error("Service error: categories/subcategories", { slug, ...toErrorContext(err) });
240
+ throw createError({ statusCode: 500, message: "Internal server error" });
241
+ });
242
+
243
+ if (!category) {
244
+ throw createError({ status: 404, message: "Category not found" });
245
+ }
246
+
247
+ if (!category.subcategories.length) {
248
+ return [];
249
+ }
250
+
251
+ /**
252
+ * Best-effort: the navigation data alone still renders a usable grid, and the
253
+ * two enrichments degrade separately — a failed image lookup must not cost
254
+ * the counts, which is what a single shared query used to do.
255
+ */
256
+ function degrade<T>(what: string) {
257
+ return (err: unknown): Map<string, T> => {
258
+ getLogService().warn(
259
+ `categories/subcategories: ${what} unavailable, serving tiles without them`,
260
+ { slug, ...toErrorContext(err) },
261
+ );
262
+ return new Map<string, T>();
263
+ };
264
+ }
265
+
266
+ const isLive = resolveProductServiceKey(event) === "api";
267
+
268
+ const [counts, images] = await Promise.all([
269
+ (isLive
270
+ ? liveCounts(category.slug, locale)
271
+ : mockCounts(category.slug)
272
+ ).catch(degrade<number>("product counts")),
273
+ (isLive
274
+ ? liveImages(category.slug, locale)
275
+ : mockImages(category.slug, category.subcategories)
276
+ ).catch(degrade<string>("preview images")),
277
+ ]);
278
+
279
+ return toTiles(category.subcategories, counts, images);
280
+ });