@revenexx/cover 0.2.26 → 0.2.28

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 +759 -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
@@ -0,0 +1,75 @@
1
+ {
2
+ "_comment": "Demo variant groups. Each model lists product ids from product-detail.json; every member of a model shares a manufacturer AND subcategory, so a sibling link resolves on the current product's category path. Axis values are read from the members' own `attributes` entries — nothing is duplicated here.",
3
+ "orderUnit": {
4
+ "de": "Stück",
5
+ "en": "pc."
6
+ },
7
+ "axes": {
8
+ "color": {
9
+ "attribute": "Color",
10
+ "labels": {
11
+ "de": "Farbe",
12
+ "en": "Colour"
13
+ }
14
+ },
15
+ "storage": {
16
+ "attribute": "Storage",
17
+ "labels": {
18
+ "de": "Speicher",
19
+ "en": "Storage"
20
+ }
21
+ }
22
+ },
23
+ "models": [
24
+ {
25
+ "id": "model-ip-16",
26
+ "sku": "IP-MODEL-001",
27
+ "names": {
28
+ "de": "Apple iPhone",
29
+ "en": "Apple iPhone"
30
+ },
31
+ "axes": ["color", "storage"],
32
+ "members": ["6336", "6360", "6363", "6413"]
33
+ },
34
+ {
35
+ "id": "model-sg-galaxy",
36
+ "sku": "SG-MODEL-001",
37
+ "names": {
38
+ "de": "Samsung Galaxy",
39
+ "en": "Samsung Galaxy"
40
+ },
41
+ "axes": ["color", "storage"],
42
+ "members": ["5137", "5519", "5713", "5930"]
43
+ },
44
+ {
45
+ "id": "model-gp-pixel-9",
46
+ "sku": "GP-MODEL-001",
47
+ "names": {
48
+ "de": "Google Pixel 9",
49
+ "en": "Google Pixel 9"
50
+ },
51
+ "axes": ["color", "storage"],
52
+ "members": ["6641", "6659", "6985"]
53
+ },
54
+ {
55
+ "id": "model-xi",
56
+ "sku": "XI-MODEL-001",
57
+ "names": {
58
+ "de": "Xiaomi",
59
+ "en": "Xiaomi"
60
+ },
61
+ "axes": ["color", "storage"],
62
+ "members": ["6477", "6509", "6545"]
63
+ },
64
+ {
65
+ "id": "model-op",
66
+ "sku": "OP-MODEL-001",
67
+ "names": {
68
+ "de": "OnePlus",
69
+ "en": "OnePlus"
70
+ },
71
+ "axes": ["color", "storage"],
72
+ "members": ["6701", "6755"]
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,17 @@
1
+ import type { ShopBrand } from "../../app/interfaces/brand";
2
+ import type { Locale } from "../utils/locale";
3
+
4
+ /**
5
+ * Service contract for brand data — the catalogue's manufacturers with their
6
+ * article counts, ranked by count descending.
7
+ * Register the active implementation via app.config → brandService.
8
+ */
9
+ export interface IBrandService {
10
+ listBrands(limit: number, locale: Locale): Promise<ShopBrand[]>;
11
+ /**
12
+ * The complete manufacturer list without logos (`logo: null`) — for pickers
13
+ * that must offer every brand, not the top N a grid shows. Cheaper than
14
+ * `listBrands`: no per-brand logo lookups.
15
+ */
16
+ listBrandNames(locale: Locale): Promise<ShopBrand[]>;
17
+ }
@@ -1,5 +1,7 @@
1
1
  import type { Product } from "../../app/composables/useProducts";
2
+ import type { ProductAssociations } from "../../app/interfaces/product-associations";
2
3
  import type { ProductDetail } from "../../app/interfaces/product-detail";
4
+ import type { ProductVariants } from "../../app/interfaces/product-variants";
3
5
  import type { Locale } from "../utils/locale";
4
6
 
5
7
  export interface ProductListFilter {
@@ -18,4 +20,16 @@ export interface IProductService {
18
20
  listProducts(filter?: ProductListFilter): Promise<Product[]>;
19
21
  getProductById(id: string, locale?: Locale): Promise<Product | null>;
20
22
  getProductDetail(id: string, locale?: Locale): Promise<ProductDetail | null>;
23
+ /**
24
+ * The sibling articles of this product's model, with the axes that
25
+ * distinguish them. `null` when the product belongs to no model (a
26
+ * standalone article) — the storefront then renders no variants section.
27
+ */
28
+ getProductVariants(id: string, locale?: Locale): Promise<ProductVariants | null>;
29
+ /**
30
+ * Articles this product relates to, grouped by relation type (accessories,
31
+ * spare parts, …). `null` when it relates to nothing — the storefront then
32
+ * renders no associations section.
33
+ */
34
+ getProductAssociations(id: string, locale?: Locale): Promise<ProductAssociations | null>;
21
35
  }
@@ -0,0 +1,110 @@
1
+ import type { ShopBrand } from "../../app/interfaces/brand";
2
+ import type { IBrandService } from "../interfaces/brand";
3
+ import type { Locale } from "../utils/locale";
4
+
5
+ const BRAND_CACHE_TTL_MS = 5 * 60 * 1000;
6
+
7
+ /**
8
+ * Typesense answers with 10 facet values per field when this is unset, which
9
+ * would silently cap the grid at 10 brands. Mirrors search.post.ts.
10
+ */
11
+ const LIVE_MAX_FACET_VALUES = 250;
12
+
13
+ // Partitioned by tenant — a multi-tenant theme must never serve one tenant's
14
+ // brands to another (see revenexxTenantKey()). Locale and limit are part of the
15
+ // key because both change the answer.
16
+ const cache = new Map<string, { brands: ShopBrand[]; loadedAt: number }>();
17
+
18
+ /**
19
+ * Live brands from the platform's Typesense product index.
20
+ *
21
+ * Two questions, two round trips:
22
+ * 1. facet `manufacturer` over the whole catalogue → names + article counts,
23
+ * already ranked by count descending.
24
+ * 2. ONE multi_search with a sub-search per top brand → the logo, which lives
25
+ * on the product document (`attrs.<logoAttribute>`), not on any brand
26
+ * entity. `include_fields` cannot narrow this: asking for `attrs` returns
27
+ * an empty object, so the full document has to come back.
28
+ *
29
+ * Both carry the same pinned filters the storefront's search uses — without
30
+ * them the counts drift from what the search page reports for the same brand.
31
+ */
32
+ export class ApiBrandService implements IBrandService {
33
+ async listBrands(limit: number, locale: Locale): Promise<ShopBrand[]> {
34
+ const cacheKey = `${revenexxTenantKey()}:${locale}:${limit}`;
35
+ const cached = cache.get(cacheKey);
36
+ if (cached && Date.now() - cached.loadedAt < BRAND_CACHE_TTL_MS) {
37
+ return cached.brands;
38
+ }
39
+
40
+ const counts = await this.facetManufacturers(locale);
41
+ const top = counts.filter(entry => entry.value.trim().length > 0).slice(0, limit);
42
+
43
+ if (top.length === 0) {
44
+ cache.set(cacheKey, { brands: [], loadedAt: Date.now() });
45
+ return [];
46
+ }
47
+
48
+ // Same attribute the product detail reads its logo from (liveCatalog).
49
+ const attribute = manufacturerLogoAttribute();
50
+
51
+ // One representative product per brand, in a single request. A failed
52
+ // SUB-search is reported positionally rather than thrown, so one brand
53
+ // without a hit costs that brand its logo and nothing more.
54
+ const pinned = this.pinnedFilter(locale);
55
+ const logoResults = await searchLiveProductsMulti(top.map(entry => ({
56
+ q: "*",
57
+ queryBy: "name",
58
+ filterBy: `${pinned} && manufacturer:=${tsFilterValue(entry.value)}`,
59
+ perPage: 1,
60
+ })));
61
+
62
+ const brands = top.map((entry, index): ShopBrand => {
63
+ const raw = logoResults[index]?.hits?.[0]?.document?.attrs?.[attribute];
64
+ const logo = typeof raw === "string" && raw.trim().length > 0
65
+ ? liveImageSrc(raw.trim())
66
+ : null;
67
+ return { name: entry.value, logo, productCount: entry.count };
68
+ });
69
+
70
+ cache.set(cacheKey, { brands, loadedAt: Date.now() });
71
+ return brands;
72
+ }
73
+
74
+ async listBrandNames(locale: Locale): Promise<ShopBrand[]> {
75
+ // "names" cannot collide with a numeric limit key.
76
+ const cacheKey = `${revenexxTenantKey()}:${locale}:names`;
77
+ const cached = cache.get(cacheKey);
78
+ if (cached && Date.now() - cached.loadedAt < BRAND_CACHE_TTL_MS) {
79
+ return cached.brands;
80
+ }
81
+
82
+ const counts = await this.facetManufacturers(locale);
83
+ const brands = counts
84
+ .filter(entry => entry.value.trim().length > 0)
85
+ .map((entry): ShopBrand => ({ name: entry.value, logo: null, productCount: entry.count }));
86
+
87
+ cache.set(cacheKey, { brands, loadedAt: Date.now() });
88
+ return brands;
89
+ }
90
+
91
+ /** Round trip 1 of listBrands: names + counts, count-descending. */
92
+ private async facetManufacturers(locale: Locale): Promise<{ value: string; count: number }[]> {
93
+ const facetResult = await searchLiveProducts({
94
+ q: "*",
95
+ queryBy: "name",
96
+ filterBy: this.pinnedFilter(locale),
97
+ facetBy: "manufacturer",
98
+ maxFacetValues: LIVE_MAX_FACET_VALUES,
99
+ perPage: 0,
100
+ });
101
+
102
+ return (facetResult.facet_counts ?? [])
103
+ .find(facet => facet.field_name === "manufacturer")
104
+ ?.counts ?? [];
105
+ }
106
+
107
+ private pinnedFilter(locale: Locale): string {
108
+ return `locale:=${tsFilterValue(locale)} && enabled:=true`;
109
+ }
110
+ }
@@ -1,5 +1,7 @@
1
1
  import type { Product } from "../../app/composables/useProducts";
2
+ import type { ProductAssociations } from "../../app/interfaces/product-associations";
2
3
  import type { ProductDetail } from "../../app/interfaces/product-detail";
4
+ import type { ProductVariants } from "../../app/interfaces/product-variants";
3
5
  import type { Locale } from "../utils/locale";
4
6
 
5
7
  import type { IProductService, ProductListFilter } from "../interfaces/product";
@@ -19,15 +21,11 @@ export class ApiProductService implements IProductService {
19
21
  const filterParts = [`locale:=${tsFilterValue(locale)}`, "enabled:=true"];
20
22
 
21
23
  // Category facets carry the category CODE — our category slugs.
22
- // Products are indexed with their LEAF category only, so a top-level
23
- // category filters across all of its subcategory codes.
24
- if (filter?.subcategory) {
25
- filterParts.push(`categories:=${tsFilterValue(filter.subcategory)}`);
26
- }
27
- else if (filter?.category) {
28
- const tree = await getLiveCategories(locale);
29
- const node = tree.find(c => c.slug === filter.category);
30
- const codes = [filter.category, ...(node?.subcategories.map(s => s.slug) ?? [])];
24
+ // Products are indexed with their LEAF category only, so a branch
25
+ // filters across its whole subtree, however deep the tree runs.
26
+ const branch = filter?.subcategory ?? filter?.category;
27
+ if (branch) {
28
+ const codes = await liveCategorySubtreeCodes([branch]);
31
29
  filterParts.push(`categories:=[${codes.map(tsFilterValue).join(",")}]`);
32
30
  }
33
31
 
@@ -53,4 +51,40 @@ export class ApiProductService implements IProductService {
53
51
  // Dropping it here left the spec table German on an English page.
54
52
  return doc ? mapLiveDocToDetail(doc, locale) : null;
55
53
  }
54
+
55
+ /**
56
+ * Model siblings from the products app's REST rows — the search index has
57
+ * no parent link, so this is the one read that bypasses it.
58
+ *
59
+ * Soft-failing on purpose: variants are an enrichment of the detail page,
60
+ * so a PIM hiccup must degrade to "no variants section" rather than take
61
+ * the whole product page down with it.
62
+ */
63
+ async getProductVariants(id: string, locale: Locale = "de"): Promise<ProductVariants | null> {
64
+ try {
65
+ return await getLiveProductVariants(id, locale);
66
+ }
67
+ catch (err) {
68
+ getLogService().warn("Live variants lookup failed", { id, ...toErrorContext(err) });
69
+ return null;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Related articles from the products app's association rows, with their
75
+ * targets resolved through the search index.
76
+ *
77
+ * Soft-failing for the same reason as variants: the associations grid
78
+ * enriches the detail page, so a PIM hiccup must cost the section, not the
79
+ * page.
80
+ */
81
+ async getProductAssociations(id: string, locale: Locale = "de"): Promise<ProductAssociations | null> {
82
+ try {
83
+ return await getLiveProductAssociations(id, locale);
84
+ }
85
+ catch (err) {
86
+ getLogService().warn("Live associations lookup failed", { id, ...toErrorContext(err) });
87
+ return null;
88
+ }
89
+ }
56
90
  }
@@ -1,5 +1,16 @@
1
1
  import type { Product } from "../../app/composables/useProducts";
2
+ import type {
3
+ ProductAssociationGroup,
4
+ ProductAssociationItem,
5
+ ProductAssociations,
6
+ } from "../../app/interfaces/product-associations";
2
7
  import type { ProductDetail } from "../../app/interfaces/product-detail";
8
+ import type {
9
+ ProductVariant,
10
+ ProductVariantAxis,
11
+ ProductVariants,
12
+ } from "../../app/interfaces/product-variants";
13
+ import type { Locale } from "../utils/locale";
3
14
 
4
15
  import type { IProductService, ProductListFilter } from "../interfaces/product";
5
16
 
@@ -40,6 +51,46 @@ interface SourceItem {
40
51
  tax?: SourceTax;
41
52
  }
42
53
 
54
+ /** Shape of `product-variant-models.json` — demo variant groups. */
55
+ interface VariantModelsFile {
56
+ orderUnit: Record<string, string>;
57
+ axes: Record<string, { attribute: string; labels: Record<string, string> }>;
58
+ models: {
59
+ id: string;
60
+ sku: string;
61
+ names: Record<string, string>;
62
+ axes: string[];
63
+ members: string[];
64
+ }[];
65
+ }
66
+
67
+ /** Shape of `product-associations.json` — demo related-article groups. */
68
+ interface AssociationsFile {
69
+ types: {
70
+ code: string;
71
+ labels: Record<string, string>;
72
+ isMandatory?: boolean;
73
+ }[];
74
+ /** Main category slug → type code → target product ids. */
75
+ byCategory: Record<string, Record<string, string[]>>;
76
+ /** Product id → type code → target product ids. Wins over byCategory. */
77
+ byProduct: Record<string, Record<string, string[]>>;
78
+ }
79
+
80
+ /** Localised pick with the same de → en fallback chain the live mapping uses. */
81
+ function pickLabel(labels: Record<string, string> | undefined, locale: Locale, fallback: string): string {
82
+ return labels?.[locale] ?? labels?.de ?? labels?.en ?? fallback;
83
+ }
84
+
85
+ /** The tile image of a catalogue entry: its main image, else the first, else none. */
86
+ function primaryImageUrl(source: SourceItem): string {
87
+ return [...(source.images ?? [])]
88
+ .sort((a, b) => a.priority - b.priority)
89
+ .find(img => img.type === "main")?.url
90
+ ?? source.images?.[0]?.url
91
+ ?? "";
92
+ }
93
+
43
94
  function mapToProduct(source: SourceItem): Product | null {
44
95
  const mainProduct = source.product[0];
45
96
  if (!mainProduct) {
@@ -57,11 +108,7 @@ function mapToProduct(source: SourceItem): Product | null {
57
108
  const categoryName = source.categories.find(c => c.type === "main")?.name ?? categorySlug;
58
109
  const subcategoryName = source.categories.find(c => c.type === "subcategory")?.name;
59
110
 
60
- const primaryImage = [...(source.images ?? [])]
61
- .sort((a, b) => a.priority - b.priority)
62
- .find(img => img.type === "main")?.url
63
- ?? source.images?.[0]?.url
64
- ?? "";
111
+ const primaryImage = primaryImageUrl(source);
65
112
 
66
113
  const taxRate = typeof source.tax?.rate === "number" && Number.isFinite(source.tax.rate)
67
114
  ? source.tax.rate
@@ -94,10 +141,19 @@ function mapToProduct(source: SourceItem): Product | null {
94
141
  export class LocalFileProductService implements IProductService {
95
142
  private readonly listKey: string;
96
143
  private readonly detailKey: string;
144
+ private readonly variantModelsKey: string;
145
+ private readonly associationsKey: string;
97
146
 
98
- constructor(listKey: string, detailKey: string) {
147
+ constructor(
148
+ listKey: string,
149
+ detailKey: string,
150
+ variantModelsKey: string,
151
+ associationsKey: string,
152
+ ) {
99
153
  this.listKey = listKey;
100
154
  this.detailKey = detailKey;
155
+ this.variantModelsKey = variantModelsKey;
156
+ this.associationsKey = associationsKey;
101
157
  }
102
158
 
103
159
  async listProducts(filter?: ProductListFilter): Promise<Product[]> {
@@ -130,4 +186,142 @@ export class LocalFileProductService implements IProductService {
130
186
  // Catalog shell — strip price + availability; the Offer domain owns them.
131
187
  return { ...detail, prices: [], stocks: [] };
132
188
  }
189
+
190
+ /**
191
+ * Demo variants: the model groups in `product-variant-models.json` name
192
+ * member product ids, and every row is resolved from that member's own
193
+ * entry in `product-detail.json` — name, sku and availability from the
194
+ * product, axis values from its `attributes`. Nothing is duplicated in the
195
+ * groups file, so demo data stays single-sourced.
196
+ */
197
+ async getProductVariants(id: string, locale: Locale = "de"): Promise<ProductVariants | null> {
198
+ const file = await readCoverDataJson<VariantModelsFile>(this.variantModelsKey);
199
+ const model = file.models.find(candidate => candidate.members.includes(id));
200
+ if (!model) {
201
+ return null;
202
+ }
203
+
204
+ const details = await readCoverDataJson<Record<string, ProductDetail>>(this.detailKey);
205
+ const orderUnit = pickLabel(file.orderUnit, locale, "");
206
+
207
+ const axes: ProductVariantAxis[] = model.axes
208
+ .filter(code => file.axes[code])
209
+ .map(code => ({
210
+ code,
211
+ label: pickLabel(file.axes[code]?.labels, locale, code),
212
+ unit: null,
213
+ }));
214
+
215
+ const variants: ProductVariant[] = [];
216
+ for (const memberId of model.members) {
217
+ const detail = details[memberId];
218
+ const product = detail?.product?.[0];
219
+ if (!product) {
220
+ // A group naming a product the catalogue no longer has must not
221
+ // produce a row that links nowhere.
222
+ continue;
223
+ }
224
+
225
+ const values: Record<string, string> = {};
226
+ for (const axis of axes) {
227
+ const attributeName = file.axes[axis.code]?.attribute;
228
+ const match = detail.attributes?.find(attribute => attribute.name === attributeName);
229
+ if (match) {
230
+ values[axis.code] = String(match.value);
231
+ }
232
+ }
233
+
234
+ variants.push({
235
+ id: memberId,
236
+ sku: product.sku,
237
+ name: product.name,
238
+ available: product.available,
239
+ orderUnit: orderUnit || null,
240
+ isSelf: memberId === id,
241
+ values,
242
+ });
243
+ }
244
+
245
+ // A group of one is not a variant choice — treat it as a standalone
246
+ // article so the section disappears instead of showing a single row.
247
+ if (variants.length < 2) {
248
+ return null;
249
+ }
250
+
251
+ return {
252
+ variants,
253
+ // Drop axes no member actually carries a value for — an all-empty
254
+ // column is noise the editor never asked for.
255
+ axes: axes.filter(axis => variants.some(variant => variant.values[axis.code])),
256
+ model: {
257
+ id: model.id,
258
+ sku: model.sku,
259
+ name: pickLabel(model.names, locale, model.sku),
260
+ },
261
+ };
262
+ }
263
+
264
+ /**
265
+ * Demo associations: `product-associations.json` names target product ids
266
+ * per relation type, either for one product or for every product in a main
267
+ * category, and each tile is resolved from that target's own catalogue
268
+ * entry — so names, SKUs and images stay single-sourced.
269
+ */
270
+ async getProductAssociations(id: string, locale: Locale = "de"): Promise<ProductAssociations | null> {
271
+ const file = await readCoverDataJson<AssociationsFile>(this.associationsKey);
272
+ const all = await readCoverDataJson<SourceItem[]>(this.listKey);
273
+
274
+ const self = all.find(item => String(item.product[0]?.id ?? "") === id);
275
+ if (!self) {
276
+ return null;
277
+ }
278
+
279
+ // A product's own entry replaces its category's rather than adding to
280
+ // it, so a fixture can give one article a deliberately different set.
281
+ const categorySlug = self.categories.find(c => c.type === "slug")?.name.split("/")[0] ?? "";
282
+ const byCode = file.byProduct[id] ?? file.byCategory[categorySlug];
283
+ if (!byCode) {
284
+ return null;
285
+ }
286
+
287
+ const byId = new Map(all.map(item => [String(item.product[0]?.id ?? ""), item]));
288
+
289
+ const groups: ProductAssociationGroup[] = [];
290
+ // `types` fixes the group order; a type the fixture never references is
291
+ // simply absent.
292
+ for (const type of file.types) {
293
+ const targetIds = byCode[type.code] ?? [];
294
+ const items: ProductAssociationItem[] = [];
295
+
296
+ for (const targetId of targetIds) {
297
+ // Never let a product accessorise itself, and skip a target the
298
+ // catalogue no longer has rather than link nowhere.
299
+ if (targetId === id) {
300
+ continue;
301
+ }
302
+ const target = byId.get(targetId);
303
+ const product = target?.product[0];
304
+ if (!target || !product) {
305
+ continue;
306
+ }
307
+ items.push({
308
+ id: targetId,
309
+ sku: product.sku,
310
+ name: product.name,
311
+ image: primaryImageUrl(target),
312
+ });
313
+ }
314
+
315
+ if (items.length > 0) {
316
+ groups.push({
317
+ code: type.code,
318
+ label: pickLabel(type.labels, locale, type.code),
319
+ isMandatory: type.isMandatory === true,
320
+ items,
321
+ });
322
+ }
323
+ }
324
+
325
+ return groups.length > 0 ? { groups } : null;
326
+ }
133
327
  }
@@ -0,0 +1,52 @@
1
+ import type { ShopBrand } from "../../app/interfaces/brand";
2
+ import type { IBrandService } from "../interfaces/brand";
3
+
4
+ /** The slice of a product-list.json record this service reads. */
5
+ interface SourceItem {
6
+ product: { manufacturer?: string }[];
7
+ }
8
+
9
+ /**
10
+ * Bundled demo brands, aggregated from the demo catalogue.
11
+ *
12
+ * Deliberately NOT via Typesense, even though the mock index facets on
13
+ * `manufacturer` too: the demo catalogue is a couple of dozen records, and a
14
+ * landing-page block must still render when the Typesense container is not
15
+ * running. The counts match a mock search's `found` anyway — the seeder indexes
16
+ * this very file.
17
+ */
18
+ export class MockBrandService implements IBrandService {
19
+ private readonly dataKey: string;
20
+
21
+ constructor(dataKey: string) {
22
+ this.dataKey = dataKey;
23
+ }
24
+
25
+ async listBrands(limit: number): Promise<ShopBrand[]> {
26
+ const brands = await this.aggregateBrands();
27
+ return brands.slice(0, limit);
28
+ }
29
+
30
+ async listBrandNames(): Promise<ShopBrand[]> {
31
+ return this.aggregateBrands();
32
+ }
33
+
34
+ private async aggregateBrands(): Promise<ShopBrand[]> {
35
+ const items = await readCoverDataJson<SourceItem[]>(this.dataKey);
36
+
37
+ const counts = new Map<string, number>();
38
+ for (const item of items) {
39
+ const name = item.product[0]?.manufacturer?.trim();
40
+ if (name) {
41
+ counts.set(name, (counts.get(name) ?? 0) + 1);
42
+ }
43
+ }
44
+
45
+ // Count descending, then name ascending so ties keep a stable order
46
+ // across requests (Map iteration order would otherwise leak the
47
+ // catalogue's row order into the grid).
48
+ return [...counts.entries()]
49
+ .map(([name, productCount]): ShopBrand => ({ name, logo: null, productCount }))
50
+ .sort((a, b) => b.productCount - a.productCount || a.name.localeCompare(b.name));
51
+ }
52
+ }
@@ -0,0 +1,24 @@
1
+ import type { H3Event } from "h3";
2
+
3
+ import type { IBrandService } from "../interfaces/brand";
4
+ import { ApiBrandService } from "../services/ApiBrandService";
5
+ import { MockBrandService } from "../services/MockBrandService";
6
+
7
+ /**
8
+ * Registry of available brand implementations:
9
+ * - "mock" — manufacturers aggregated from the demo catalogue (product-list.json)
10
+ * - "api" — live manufacturers via the platform's Typesense product index
11
+ */
12
+ const serviceRegistry: Record<string, IBrandService> = {
13
+ mock: new MockBrandService("product-list.json"),
14
+ api: new ApiBrandService(),
15
+ };
16
+
17
+ export function getBrandService(event?: H3Event): IBrandService {
18
+ const key = resolveServiceKey(event, {
19
+ domain: "brandService",
20
+ mockKey: "mock",
21
+ liveKey: "api",
22
+ });
23
+ return serviceRegistry[key] ?? serviceRegistry["mock"]!;
24
+ }
@@ -0,0 +1,67 @@
1
+ import type { H3Event } from "h3";
2
+
3
+ /**
4
+ * The content-tenant cookie, as the BFF sees it.
5
+ *
6
+ * Two tenant axes meet in this layer. The CONTENT tenant is a `cover-tenant`
7
+ * cookie naming a Blökkli bundle in the theme layer; the PLATFORM tenant is the
8
+ * slug plus API key the BFF authenticates to api.revenexx.com with. Without a
9
+ * link between them, switching the storefront to another tenant swapped its
10
+ * pages, menus and colours while its products still came from whichever tenant
11
+ * the environment happened to name (see ./revenexxCredentials.ts).
12
+ *
13
+ * The cookie primitive lives HERE, in the cover layer, rather than only next to
14
+ * resolveTenantKey() in the theme: this layer ships the BFF that needs it, and
15
+ * it must not depend on a layer that extends it (the demo shop and
16
+ * custom-theme both build without the theme's tenant bundles). Nitro merges
17
+ * every layer's server/utils into one auto-import scope, so the theme reuses
18
+ * this rather than the other way round.
19
+ *
20
+ * The names here are deliberately NOT the theme's (`TENANT_COOKIE_NAME`,
21
+ * `resolveTenantKey`): one merged auto-import scope means two layers exporting
22
+ * one name is a collision. The theme keeps its names and delegates.
23
+ *
24
+ * Shape follows resolveSelectedMarket() in ./market.ts: a cookie, a format
25
+ * check, a fallback.
26
+ */
27
+
28
+ /**
29
+ * Cookie the tenant pickers persist the chosen content tenant in. The theme
30
+ * re-exports this as TENANT_COOKIE_NAME (server/utils/tenant.ts) and mirrors it
31
+ * for the client in app/config/tenant.ts — that module cannot import a server
32
+ * util, so the string is duplicated there and tested for drift.
33
+ */
34
+ export const CONTENT_TENANT_COOKIE = "cover-tenant";
35
+
36
+ /**
37
+ * Tenant keys are interpolated into a filename by the theme, so this format
38
+ * check is also the traversal guard: no dots, no slashes, nothing that can
39
+ * climb out of server/data/tenants.
40
+ */
41
+ const CONTENT_TENANT_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
42
+
43
+ /**
44
+ * The content tenant this request names, or undefined when it names none —
45
+ * no event (a call outside a request), no cookie, or a malformed one.
46
+ *
47
+ * Undefined rather than a default on purpose: this layer must not know that
48
+ * the theme's default bundle is called "cover", and every caller here wants
49
+ * "no tenant-specific answer, fall back" for exactly these three cases. The
50
+ * theme applies its own default on top (see server/utils/tenant.ts).
51
+ */
52
+ export function resolveContentTenantKey(event?: H3Event): string | undefined {
53
+ if (!event) {
54
+ return undefined;
55
+ }
56
+ const raw = getCookie(event, CONTENT_TENANT_COOKIE);
57
+ if (!raw) {
58
+ return undefined;
59
+ }
60
+ const key = raw.trim().toLowerCase();
61
+ return CONTENT_TENANT_PATTERN.test(key) ? key : undefined;
62
+ }
63
+
64
+ /** Whether a slug is usable as a content tenant key. */
65
+ export function isContentTenantKey(value: string): boolean {
66
+ return CONTENT_TENANT_PATTERN.test(value);
67
+ }