@revenexx/cover 0.17.0 → 0.19.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.
package/app/app.config.ts CHANGED
@@ -46,6 +46,10 @@ export default defineAppConfig({
46
46
  // nothing, and every surface then falls back to the default the owning app
47
47
  // itself declares, so the demo and an untouched live tenant behave alike.
48
48
  settingsService: "mock",
49
+ // The tenant's own storefront texts, published from the Experience Studio
50
+ // through transpose and merged over the theme's locale files. Mock reads
51
+ // nothing, so the demo shows the theme's texts; a theme switches it to "api".
52
+ translationsService: "mock",
49
53
  // How an ordered quote is paid. A quote is a negotiated B2B price, so the
50
54
  // order it becomes goes on account; a storefront that takes quotes on
51
55
  // another method names its code here.
@@ -13,7 +13,9 @@ const props = defineProps<{
13
13
  const has3d = computed(() => !!props.modelUrl);
14
14
 
15
15
  // 'image' shows the selected still; 'model' shows the interactive 3D viewer.
16
- const mode = ref<"image" | "model">("image");
16
+ // A product with a model but no picture opens in 3D rather than on an empty stage.
17
+ const initialMode = (): "image" | "model" => (props.images.length || !props.modelUrl ? "image" : "model");
18
+ const mode = ref<"image" | "model">(initialMode());
17
19
  const selectedIndex = ref(0);
18
20
  const selectedImage = computed(() => props.images[selectedIndex.value]);
19
21
 
@@ -22,9 +24,9 @@ function showImage(index: number): void {
22
24
  mode.value = "image";
23
25
  }
24
26
 
25
- watch(() => props.images, () => {
27
+ watch([() => props.images, () => props.modelUrl], () => {
26
28
  selectedIndex.value = 0;
27
- mode.value = "image";
29
+ mode.value = initialMode();
28
30
  });
29
31
  </script>
30
32
 
@@ -77,26 +79,50 @@ watch(() => props.images, () => {
77
79
  >
78
80
  </button>
79
81
 
80
- <!-- 3D entry -->
82
+ <!-- 3D entry: the model's preview still with a 3D badge in the corner,
83
+ so it reads as "this picture turns"; the bare icon when there is no still. -->
81
84
  <button
82
85
  v-if="has3d"
83
86
  type="button"
84
87
  tabindex="0"
85
- class="aspect-square rounded-lg overflow-hidden bg-elevated/60
88
+ class="relative aspect-square rounded-lg overflow-hidden bg-elevated/60
86
89
  ring-1 transition-all cursor-pointer flex flex-col items-center justify-center gap-0.5
87
90
  focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
88
- :class="mode === 'model'
89
- ? 'ring-2 ring-(--ui-primary)'
90
- : 'ring-(--ui-border) hover:ring-(--ui-primary)/50'"
91
+ :class="[
92
+ mode === 'model'
93
+ ? 'ring-2 ring-(--ui-primary)'
94
+ : 'ring-(--ui-border) hover:ring-(--ui-primary)/50',
95
+ modelPoster ? 'p-1.5' : '',
96
+ ]"
91
97
  aria-label="3D view"
92
98
  :aria-pressed="mode === 'model'"
93
99
  @click="mode = 'model'"
94
100
  >
95
- <UIcon
96
- name="i-lucide-rotate-3d"
97
- class="size-5 text-muted"
98
- />
99
- <span class="text-[10px] font-semibold uppercase tracking-wide text-muted">3D</span>
101
+ <template v-if="modelPoster">
102
+ <img
103
+ :src="modelPoster"
104
+ alt=""
105
+ class="w-full h-full object-contain"
106
+ data-testid="gallery-3d-poster"
107
+ >
108
+ <span
109
+ class="absolute top-1 right-1 flex items-center gap-0.5 rounded-md
110
+ bg-inverted px-1 py-0.5 text-[9px] font-bold leading-none tracking-wide text-inverted"
111
+ >
112
+ <UIcon
113
+ name="i-lucide-rotate-3d"
114
+ class="size-2.5"
115
+ />
116
+ 3D
117
+ </span>
118
+ </template>
119
+ <template v-else>
120
+ <UIcon
121
+ name="i-lucide-rotate-3d"
122
+ class="size-5 text-muted"
123
+ />
124
+ <span class="text-[10px] font-semibold uppercase tracking-wide text-muted">3D</span>
125
+ </template>
100
126
  </button>
101
127
  </div>
102
128
  </div>
@@ -17,7 +17,7 @@ const { slug, id } = useRouteProductSubject();
17
17
 
18
18
  const {
19
19
  status,
20
- productInfo, mainImages, longDescription,
20
+ productInfo, mainImages, model3d, longDescription,
21
21
  stocks, attributes, prices, taxRate, offerPending,
22
22
  productCategories, categorySlug, subcategorySlug,
23
23
  formatPrice, getDetailImageUrl, ready,
@@ -123,6 +123,8 @@ const breadcrumb = computed(() => [
123
123
  class="lg:sticky lg:top-(--ui-header-height)"
124
124
  :images="mainImages"
125
125
  :get-image-url="getDetailImageUrl"
126
+ :model-url="model3d?.url"
127
+ :model-poster="model3d?.poster"
126
128
  />
127
129
 
128
130
  <div class="flex flex-col gap-6">
@@ -7,6 +7,7 @@ import type {
7
7
  ProductDetailStock,
8
8
  ProductDetailAttribute,
9
9
  ProductDetailCategory,
10
+ ProductDetailModel,
10
11
  } from "../interfaces/product-detail";
11
12
 
12
13
  export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
@@ -71,6 +72,10 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
71
72
  .sort((a, b) => a.priority - b.priority),
72
73
  );
73
74
 
75
+ // `model3d`, not `model`: a variant's `model` (its grouping parent) sits
76
+ // next to it on the product page.
77
+ const model3d = computed<ProductDetailModel | null>(() => detail.value?.model ?? null);
78
+
74
79
  const longDescription = computed<string | undefined>(
75
80
  () => detail.value?.descriptions?.find(d => d.type === "long")?.content,
76
81
  );
@@ -130,7 +135,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
130
135
 
131
136
  return {
132
137
  detail, status, error, refresh, ready,
133
- productInfo, mainImages, longDescription,
138
+ productInfo, mainImages, model3d, longDescription,
134
139
  stocks, attributes, prices, taxRate, offerPending,
135
140
  productCategories, categorySlug, subcategorySlug,
136
141
  formatPrice, getDetailImageUrl,
@@ -42,6 +42,15 @@ export interface ProductDetailImage {
42
42
  url: string;
43
43
  }
44
44
 
45
+ /**
46
+ * The product's interactive 3D model: a glTF mesh the storage service renders
47
+ * from the product's own CAD file (STEP), and the still shown while it loads.
48
+ */
49
+ export interface ProductDetailModel {
50
+ url: string;
51
+ poster?: string | null;
52
+ }
53
+
45
54
  export interface ProductDetailAttribute {
46
55
  id: number;
47
56
  name: string;
@@ -57,4 +66,6 @@ export interface ProductDetail {
57
66
  images: ProductDetailImage[];
58
67
  attributes: ProductDetailAttribute[];
59
68
  prices: { [key: string]: number }[];
69
+ /** Absent when the product carries no 3D asset: the gallery then has no 3D entry. */
70
+ model?: ProductDetailModel | null;
60
71
  }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The tenant's storefront texts over the theme's (PE-1073, transpose
3
+ * sprachtags §3.2).
4
+ *
5
+ * The theme's locale files are bundled once for every tenant; what a tenant
6
+ * changed in the Experience Studio arrives per request as an overlay from
7
+ * /api/i18n/{locale} (the BFF holds it per tenant). This plugin merges it into
8
+ * the request's vue-i18n messages — on the server before the page renders, and
9
+ * again in the browser from the payload, so the client hydrates with exactly
10
+ * the texts the server rendered.
11
+ *
12
+ * It runs after @nuxtjs/i18n has loaded the initial locale (a merge before
13
+ * that would be overwritten by the theme's messages), and wraps the module's
14
+ * message loader so a later language switch gets its overlay right after the
15
+ * theme's messages for that locale, before the locale changes.
16
+ *
17
+ * Not an @nuxtjs/i18n locale loader on purpose: loader results are cached per
18
+ * locale for the whole process, and one build serves many tenants.
19
+ */
20
+
21
+ type MessageTree = Record<string, unknown>;
22
+
23
+ interface I18nTarget {
24
+ mergeLocaleMessage: (locale: string, messages: MessageTree) => void;
25
+ locale: { value: string } | string;
26
+ }
27
+
28
+ /** The slice of @nuxtjs/i18n's internal context this plugin wraps. */
29
+ interface NuxtI18nContext {
30
+ loadMessages: (locale: string) => Promise<void>;
31
+ }
32
+
33
+ const STATE_KEY = "cover:storefront-messages";
34
+
35
+ export default defineNuxtPlugin({
36
+ name: "cover:storefront-messages",
37
+ dependsOn: ["i18n:plugin:route-locale-detect"],
38
+ async setup(nuxtApp) {
39
+ // Per request on the server, shipped in the payload to the client.
40
+ const overlays = useState<Record<string, MessageTree>>(STATE_KEY, () => ({}));
41
+ const i18n = nuxtApp.$i18n as unknown as I18nTarget;
42
+ const requestFetch = useRequestFetch();
43
+
44
+ // On the first page of a preview the cookie is only being set, so the
45
+ // server-side read names the token itself (server/middleware/
46
+ // storefront-preview.ts left it on the request).
47
+ const preview = import.meta.server
48
+ ? String((useRequestEvent()?.context as Record<string, unknown> | undefined)?.coverStorefrontPreview ?? "")
49
+ : "";
50
+
51
+ async function overlayFor(locale: string): Promise<MessageTree> {
52
+ const held = overlays.value[locale];
53
+ if (held) {
54
+ return held;
55
+ }
56
+ let messages: MessageTree = {};
57
+ try {
58
+ const res = await requestFetch<{ messages?: MessageTree }>(`/api/i18n/${encodeURIComponent(locale)}`, {
59
+ query: preview ? { preview } : undefined,
60
+ });
61
+ messages = res?.messages && typeof res.messages === "object" ? res.messages : {};
62
+ }
63
+ catch {
64
+ // Fails open: the theme's own texts stand.
65
+ }
66
+ overlays.value = { ...overlays.value, [locale]: messages };
67
+ return messages;
68
+ }
69
+
70
+ async function apply(locale: string): Promise<void> {
71
+ if (!locale) {
72
+ return;
73
+ }
74
+ const messages = await overlayFor(locale);
75
+ if (Object.keys(messages).length > 0) {
76
+ i18n.mergeLocaleMessage(locale, messages);
77
+ }
78
+ }
79
+
80
+ const ctx = (nuxtApp as unknown as { _nuxtI18n?: NuxtI18nContext })._nuxtI18n;
81
+ if (ctx && typeof ctx.loadMessages === "function") {
82
+ const loadThemeMessages = ctx.loadMessages;
83
+ ctx.loadMessages = async (locale: string) => {
84
+ await loadThemeMessages(locale);
85
+ await apply(locale);
86
+ };
87
+ }
88
+ else {
89
+ // The module's internals moved: still correct, one render later.
90
+ nuxtApp.hook("i18n:localeSwitched", ({ newLocale }) => apply(newLocale));
91
+ }
92
+
93
+ const current = typeof i18n.locale === "string" ? i18n.locale : i18n.locale.value;
94
+ await apply(current);
95
+ },
96
+ });
package/nuxt.config.ts CHANGED
@@ -8,6 +8,7 @@ import { defineNuxtConfig } from "nuxt/config";
8
8
 
9
9
  const currentDir = dirname(fileURLToPath(import.meta.url));
10
10
  const require_ = createRequire(import.meta.url);
11
+ const coverVersion = String((require_("./package.json") as { version?: string }).version ?? "");
11
12
 
12
13
  /**
13
14
  * Auto-discovers the layer's locale files under i18n/locales/{code}/.
@@ -121,6 +122,14 @@ export default defineNuxtConfig({
121
122
  // HMAC secret for the stateless checkout session tokens — override
122
123
  // via NUXT_CHECKOUT_SESSION_SECRET in multi-tenant deployments.
123
124
  checkoutSessionSecret: "",
125
+ // The transpose catalog this build's storefront texts are published
126
+ // under, `theme:<vendor>/<name>` (PE-1073). Each theme sets its own;
127
+ // empty reads nothing. Override via NUXT_TRANSPOSE_CATALOG.
128
+ transposeCatalog: "",
129
+ // What the shop hands over its texts as (PE-1072): a name for the
130
+ // Studio, and the layer's version so a theme update shows as one.
131
+ transposeCatalogName: "",
132
+ transposeCatalogVersion: coverVersion,
124
133
  public: {
125
134
  // Cart state keys the layer's stores read — apps may override, but
126
135
  // the layer must ship working defaults (an undefined TTL turns the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "Cover — 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",
@@ -0,0 +1,34 @@
1
+ import { createError, getQuery, getRouterParam, setResponseHeader } from "h3";
2
+
3
+ /**
4
+ * The tenant's storefront texts for one UI locale — the overlay transpose
5
+ * published, only what differs from the theme (PE-1073).
6
+ *
7
+ * Read by the storefront-messages plugin: on the server for the page being
8
+ * rendered, in the browser when the buyer switches language. Both go through
9
+ * the same per-tenant cache, so a page and a later switch can never disagree.
10
+ *
11
+ * `?preview=<token>` reads the Studio's draft, like `?rx-preview=` on a page;
12
+ * the server-side render passes it explicitly because on the first page of a
13
+ * preview the cookie is set, not yet sent.
14
+ */
15
+ export default defineEventHandler(async (event) => {
16
+ const locale = getRouterParam(event, "locale") ?? "";
17
+ if (!isStorefrontLocale(locale)) {
18
+ throw createError({ statusCode: 400, statusMessage: "Unknown locale" });
19
+ }
20
+
21
+ const preview = getQuery(event).preview;
22
+ if (isStorefrontPreviewToken(preview)) {
23
+ setStorefrontPreview(event, preview);
24
+ }
25
+
26
+ const messages = await readStorefrontMessages(event, locale);
27
+
28
+ setResponseHeader(
29
+ event,
30
+ "Cache-Control",
31
+ resolveStorefrontPreview(event) ? "no-store" : "private, max-age=30",
32
+ );
33
+ return { locale, messages };
34
+ });
@@ -0,0 +1,38 @@
1
+ import { deleteCookie, getQuery, getRequestProtocol, setCookie, setResponseHeader } from "h3";
2
+
3
+ /**
4
+ * Keep the Studio's preview for the visit (PE-1073, transpose sprachtags §3.3).
5
+ *
6
+ * The Experience Studio opens the shop with `?rx-preview=<token>`. Only that
7
+ * first URL carries it, so it goes into a short-lived cookie and every later
8
+ * page — and every client-side language switch through /api/i18n — reads the
9
+ * draft too. An empty `?rx-preview=` ends the preview.
10
+ *
11
+ * A request that reads the draft is never cached: `Cache-Control: no-store`
12
+ * on whatever it answers, so no edge or browser cache hands a draft to a
13
+ * buyer.
14
+ */
15
+ export default defineEventHandler((event) => {
16
+ const fromQuery = getQuery(event)[STOREFRONT_PREVIEW_QUERY];
17
+
18
+ if (fromQuery === "") {
19
+ deleteCookie(event, STOREFRONT_PREVIEW_COOKIE, { path: "/" });
20
+ setStorefrontPreview(event, "");
21
+ return;
22
+ }
23
+
24
+ if (isStorefrontPreviewToken(fromQuery)) {
25
+ setCookie(event, STOREFRONT_PREVIEW_COOKIE, fromQuery, {
26
+ path: "/",
27
+ httpOnly: true,
28
+ sameSite: "lax",
29
+ secure: getRequestProtocol(event, { xForwardedProto: true }) === "https",
30
+ maxAge: STOREFRONT_PREVIEW_MAX_AGE_S,
31
+ });
32
+ setStorefrontPreview(event, fromQuery);
33
+ }
34
+
35
+ if (resolveStorefrontPreview(event)) {
36
+ setResponseHeader(event, "Cache-Control", "no-store");
37
+ }
38
+ });
@@ -48,7 +48,26 @@ export class ApiProductService implements IProductService {
48
48
  // The locale selects the document AND the labels: mapLiveDocToDetail
49
49
  // resolves every attribute name and select-option value through it.
50
50
  // Dropping it here left the spec table German on an English page.
51
- return doc ? mapLiveDocToDetail(doc, locale) : null;
51
+ if (!doc) {
52
+ return null;
53
+ }
54
+ const detail = await mapLiveDocToDetail(doc, locale);
55
+ return { ...detail, model: await this.getProductModel(doc.attrs ?? {}) };
56
+ }
57
+
58
+ /**
59
+ * The product's 3D model from its own media (resolveLiveProductModel).
60
+ * Soft-failing like variants: a media hiccup costs the 3D entry, not the
61
+ * product page.
62
+ */
63
+ private async getProductModel(attrs: Record<string, unknown>): Promise<ProductDetail["model"]> {
64
+ try {
65
+ return await resolveLiveProductModel(attrs);
66
+ }
67
+ catch (err) {
68
+ getLogService().warn("Live 3D model lookup failed", toErrorContext(err));
69
+ return null;
70
+ }
52
71
  }
53
72
 
54
73
  async getProductLanguages(id: string, languages: readonly string[]): Promise<string[]> {
@@ -138,6 +138,14 @@ function mapToProduct(source: SourceItem): Product | null {
138
138
  * Mirrors the lookup pattern of a real database-backed product service.
139
139
  * Replace with a database-backed implementation once a data store is available.
140
140
  */
141
+ /**
142
+ * The demo catalogue has no CAD files of its own, so every mock product shows
143
+ * this part in the 3D viewer — a showcase of the gallery, not product data.
144
+ * Live products carry their own model (resolveLiveProductModel).
145
+ */
146
+ const DEMO_MODEL_BASE = "https://storage.revenexx.com/revenexx/fusskammer-gr-3-mod-3101-2-r-d22030005.stp";
147
+ const DEMO_MODEL = { url: `${DEMO_MODEL_BASE}?d=model`, poster: `${DEMO_MODEL_BASE}?d=preview` };
148
+
141
149
  export class LocalFileProductService implements IProductService {
142
150
  private readonly listKey: string;
143
151
  private readonly detailKey: string;
@@ -184,7 +192,7 @@ export class LocalFileProductService implements IProductService {
184
192
  return null;
185
193
  }
186
194
  // Catalog shell — strip price + availability; the Offer domain owns them.
187
- return { ...detail, prices: [], stocks: [] };
195
+ return { ...detail, prices: [], stocks: [], model: detail.model === undefined ? DEMO_MODEL : detail.model };
188
196
  }
189
197
 
190
198
  /**
@@ -1,23 +1,49 @@
1
+ import type { H3Event } from "h3";
2
+
1
3
  type TranslationRecord = Record<string, unknown>;
2
4
 
3
5
  const cache = new Map<string, TranslationRecord>();
4
6
 
7
+ /** The request being served, when there is one (Nitro's async context). */
8
+ function currentEvent(): H3Event | undefined {
9
+ try {
10
+ return useEvent();
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+
5
17
  /**
6
18
  * Loads locale namespaces from the layer's i18n server assets into the cache.
7
19
  * Call this once per request before using the synchronous serverT() — e.g.
8
20
  * at the top of an event handler or service method.
21
+ *
22
+ * Also reads the tenant's published texts for the locale (and its fallback)
23
+ * into the request, so serverT() answers what the page shows: a text the
24
+ * tenant changed in the Experience Studio reads changed here too.
9
25
  */
10
26
  export async function preloadLocaleNamespaces(locale: string, namespaces: string[]): Promise<void> {
11
27
  const fallbackLocale = String(useRuntimeConfig().public.defaultLocale);
12
28
  const wanted = locale === fallbackLocale ? [locale] : [locale, fallbackLocale];
13
- await Promise.all(wanted.flatMap(loc => namespaces.map(async (ns) => {
14
- const key = `${loc}/${ns}`;
15
- if (cache.has(key)) {
16
- return;
17
- }
18
- const data = await readCoverLocaleJson<TranslationRecord>(loc, ns);
19
- cache.set(key, data ?? {});
20
- })));
29
+ const event = currentEvent();
30
+ await Promise.all([
31
+ ...wanted.flatMap(loc => namespaces.map(async (ns) => {
32
+ const key = `${loc}/${ns}`;
33
+ if (cache.has(key)) {
34
+ return;
35
+ }
36
+ const data = await readCoverLocaleJson<TranslationRecord>(loc, ns);
37
+ cache.set(key, data ?? {});
38
+ })),
39
+ ...wanted.map(loc => readStorefrontMessages(event, loc)),
40
+ ]);
41
+ }
42
+
43
+ /** The tenant's text for a key, when its overlay was read for this request. */
44
+ function overlayValue(locale: string, keyPath: string): string | undefined {
45
+ const overlay = storefrontMessagesRead(currentEvent(), locale);
46
+ return overlay ? getNestedValue(overlay, keyPath) : undefined;
21
47
  }
22
48
 
23
49
  function getNamespace(locale: string, namespace: string): TranslationRecord {
@@ -60,14 +86,17 @@ export function serverT(
60
86
  );
61
87
  };
62
88
 
63
- const value = getNestedValue(getNamespace(locale, namespace), key);
89
+ // The tenant's text first: vue-i18n merges all namespace files into one
90
+ // tree, and the overlay is keyed the same way, so `key` addresses it as is.
91
+ const value = overlayValue(locale, key) ?? getNestedValue(getNamespace(locale, namespace), key);
64
92
  if (value !== undefined) {
65
93
  return interpolate(value);
66
94
  }
67
95
 
68
96
  const fallbackLocale = String(useRuntimeConfig().public.defaultLocale);
69
97
  if (locale !== fallbackLocale) {
70
- const fallbackValue = getNestedValue(getNamespace(fallbackLocale, namespace), key);
98
+ const fallbackValue = overlayValue(fallbackLocale, key)
99
+ ?? getNestedValue(getNamespace(fallbackLocale, namespace), key);
71
100
  if (fallbackValue !== undefined) {
72
101
  return interpolate(fallbackValue);
73
102
  }