@revenexx/cover 0.2.28 → 0.2.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
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",
@@ -92,13 +92,20 @@ function toApiLine(item: CartItem, position: number): Record<string, unknown> {
92
92
  function toCartItem(line: ApiCartLine): CartItem {
93
93
  // The snapshot/metadata blobs were written by toApiLine — restoring the
94
94
  // original field types is safe by construction.
95
+ //
96
+ // The image is the one field that is NOT safe to restore verbatim. It is a
97
+ // resolved src frozen when the line was added, so a cart that outlives a
98
+ // deploy replays whatever that release emitted — including the double
99
+ // tenant prefix shipped in 0.2.27, which 404s on every cart surface at
100
+ // once. `liveImageSrc` is idempotent, so passing it back through heals the
101
+ // old rows on read and leaves current ones untouched.
95
102
  const snapshot = (line.snapshot ?? {}) as Partial<CartItem> & { id?: string; image?: string };
96
103
  const metadata = (line.metadata ?? {}) as Partial<CartItem>;
97
104
  return {
98
105
  id: String(snapshot.id ?? line.product_id ?? line.sku ?? line.id),
99
106
  name: line.name,
100
107
  sku: line.sku ?? "",
101
- image: String(snapshot.image ?? ""),
108
+ image: liveImageSrc(String(snapshot.image ?? "")),
102
109
  price: Number(line.unit_price),
103
110
  quantity: Number(line.quantity),
104
111
  ...(line.unit ? { unit: line.unit } : {}),
@@ -69,6 +69,9 @@ export interface LiveSearchParams {
69
69
  maxFacetValues?: number;
70
70
  }
71
71
 
72
+ /** Where the platform's CDN is mounted, on every storefront domain. */
73
+ const CDN_PREFIX = "/cdn/";
74
+
72
75
  /**
73
76
  * A live catalogue image value, resolved to a src the client can load as-is.
74
77
  *
@@ -88,22 +91,38 @@ export interface LiveSearchParams {
88
91
  * Only a leading segment equal to this tenant is dropped, so a file that
89
92
  * happens to live in a same-named subfolder deeper in the key is left alone.
90
93
  *
94
+ * IDEMPOTENT, and that is load-bearing rather than tidy: a cart line and an
95
+ * order position freeze a COPY of this src (`snapshot.image`) at the moment
96
+ * the item is added, so every src this function ever emitted is still stored
97
+ * somewhere and gets replayed months later. Re-normalising its own output is
98
+ * what lets a snapshot written by an earlier version heal on read instead of
99
+ * needing the stored rows rewritten.
100
+ *
91
101
  * Normalising HERE is what keeps the client rule unambiguous: a bare storage
92
102
  * key and a bundled demo filename look identical, and only the server knows
93
103
  * which mode produced the value.
94
104
  *
95
105
  * Exported because manufacturer logos (ApiBrandService) are the same kind of
96
- * value read from a different attribute — and hit the same double prefix.
106
+ * value read from a different attribute — and hit the same double prefix — and
107
+ * because the cart and order readers pass their snapshots back through it.
97
108
  */
98
109
  export function liveImageSrc(raw: string): string {
99
- if (/^https?:\/\//.test(raw) || raw.startsWith("/")) {
110
+ // Stored snapshots reach this with a missing image as "" — that empty value
111
+ // is the signal a tile renders its glyph for, and `/cdn/` is not.
112
+ if (!raw.trim()) {
113
+ return "";
114
+ }
115
+ if (/^https?:\/\//.test(raw)) {
100
116
  return raw;
101
117
  }
118
+ // Our own output, coming back in. Anything else rooted at `/` is a path the
119
+ // app serves itself (a bundled demo asset) and is not ours to rewrite.
120
+ const key = raw.startsWith(CDN_PREFIX) ? raw.slice(CDN_PREFIX.length) : raw;
121
+ if (key.startsWith("/")) {
122
+ return key;
123
+ }
102
124
  const tenant = revenexxTenantKey();
103
- const key = tenant && raw.startsWith(`${tenant}/`)
104
- ? raw.slice(tenant.length + 1)
105
- : raw;
106
- return `/cdn/${key}`;
125
+ return `${CDN_PREFIX}${tenant && key.startsWith(`${tenant}/`) ? key.slice(tenant.length + 1) : key}`;
107
126
  }
108
127
 
109
128
  /** Fallback attribute code holding a manufacturer's logo on the product doc. */
@@ -102,6 +102,10 @@ function returnedByOrderItem(returns: LiveOrderReturn[] | undefined): Record<str
102
102
  function mapPositions(items: LiveOrderItem[] | undefined, returns: LiveOrderReturn[] | undefined): AccountOrderPosition[] {
103
103
  const returned = returnedByOrderItem(returns);
104
104
  return (items ?? []).map((item) => {
105
+ // The frozen product copy from order time. Its image is a src an earlier
106
+ // release resolved, so it goes back through `liveImageSrc` (idempotent)
107
+ // rather than to the page as-is — an order placed under 0.2.27 carries
108
+ // the double tenant prefix and would show a broken thumbnail forever.
105
109
  const snapshot = (item.product ?? {}) as Record<string, unknown>;
106
110
  const shipped = Number(item.quantity_shipped) || 0;
107
111
  const returnable = Math.max(0, shipped - (returned[item.id] ?? 0));
@@ -109,7 +113,7 @@ function mapPositions(items: LiveOrderItem[] | undefined, returns: LiveOrderRetu
109
113
  id: item.product_id ?? item.sku ?? item.id,
110
114
  sku: item.sku ?? "",
111
115
  name: item.name,
112
- ...(snapshot.image ? { image: String(snapshot.image) } : {}),
116
+ ...(snapshot.image ? { image: liveImageSrc(String(snapshot.image)) } : {}),
113
117
  quantity: Number(item.quantity),
114
118
  unitPrice: Number(item.unit_price),
115
119
  lineTotal: Number(item.line_total),