@revenexx/cover 0.2.27 → 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.
|
|
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,26 +69,60 @@ 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
|
*
|
|
75
78
|
* The `image` common attribute is either an absolute URL (the PIM's own media
|
|
76
|
-
* CDN) or a
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
+
* CDN) or a storage key. The key is served through the platform's `/cdn/` path
|
|
80
|
+
* — the edge CDN in production, the theme's `/cdn/` proxy route in dev and in
|
|
81
|
+
* the editor canvas.
|
|
82
|
+
*
|
|
83
|
+
* THE KEY MAY ALREADY CARRY THE TENANT FOLDER, and it must not end up in the
|
|
84
|
+
* url twice. The DAM stores `delivery_path` as `<tenant>/<file>` and hands that
|
|
85
|
+
* through to the attribute, while the edge resolves the tenant from the request
|
|
86
|
+
* host and therefore expects the key WITHOUT it — one build serves every
|
|
87
|
+
* customer domain. Prefixing blindly produced `/cdn/acme/photo.jpg`, which
|
|
88
|
+
* 404s, and on a tile that surfaced as the icon fallback: images "gone" on a
|
|
89
|
+
* catalogue whose files were all there.
|
|
90
|
+
*
|
|
91
|
+
* Only a leading segment equal to this tenant is dropped, so a file that
|
|
92
|
+
* happens to live in a same-named subfolder deeper in the key is left alone.
|
|
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.
|
|
79
100
|
*
|
|
80
101
|
* Normalising HERE is what keeps the client rule unambiguous: a bare storage
|
|
81
102
|
* key and a bundled demo filename look identical, and only the server knows
|
|
82
103
|
* which mode produced the value.
|
|
83
104
|
*
|
|
84
105
|
* Exported because manufacturer logos (ApiBrandService) are the same kind of
|
|
85
|
-
* value read from a different attribute
|
|
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.
|
|
86
108
|
*/
|
|
87
109
|
export function liveImageSrc(raw: string): string {
|
|
88
|
-
|
|
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)) {
|
|
89
116
|
return raw;
|
|
90
117
|
}
|
|
91
|
-
|
|
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
|
+
}
|
|
124
|
+
const tenant = revenexxTenantKey();
|
|
125
|
+
return `${CDN_PREFIX}${tenant && key.startsWith(`${tenant}/`) ? key.slice(tenant.length + 1) : key}`;
|
|
92
126
|
}
|
|
93
127
|
|
|
94
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),
|