@decocms/blocks 7.77.0 → 7.77.1

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": "@decocms/blocks",
3
- "version": "7.77.0",
3
+ "version": "7.77.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -237,3 +237,30 @@ describe("getSrcSet — legacy decoims.com sources", () => {
237
237
  for (const entry of result.split(", ")) expect(entry).toContain("&src=site/b.png");
238
238
  });
239
239
  });
240
+
241
+ describe("getOptimizedMediaUrl — Nuvemshop CDN", () => {
242
+ const SRC = "https://dcdn-us.mitiendanube.com/stores/008/336/778/products/3-76a3e88b446d6a938417912361162212-1024-1024.webp";
243
+ const at = (width: number) => getOptimizedMediaUrl({ originalSrc: SRC, width, fit: "cover" });
244
+ const base = SRC.replace(/-1024-1024\.webp$/, "");
245
+
246
+ it("serves the CDN's own fixed size that covers the width (no deco image proxy, which 403s it)", () => {
247
+ expect(at(50)).toBe(`${base}-50-0.webp`);
248
+ expect(at(287)).toBe(`${base}-320-0.webp`);
249
+ expect(at(480)).toBe(`${base}-480-0.webp`);
250
+ expect(at(574)).toBe(`${base}-640-0.webp`);
251
+ expect(at(700)).toBe(`${base}-1024-1024.webp`);
252
+ expect(at(4000)).toBe(`${base}-1024-1024.webp`);
253
+ });
254
+
255
+ it("keeps the original extension and works from any size variant", () => {
256
+ const jpg = "https://acdn-us.mitiendanube.com/stores/003/520/762/products/cadeira-1-480-0.jpg";
257
+ expect(getOptimizedMediaUrl({ originalSrc: jpg, width: 100, fit: "cover" })).toBe(
258
+ "https://acdn-us.mitiendanube.com/stores/003/520/762/products/cadeira-1-100-0.jpg",
259
+ );
260
+ });
261
+
262
+ it("leaves non-product Nuvemshop URLs to the default path", () => {
263
+ const logo = "https://dcdn-us.mitiendanube.com/stores/008/336/778/themes/common/logo.png";
264
+ expect(getOptimizedMediaUrl({ originalSrc: logo, width: 100, fit: "cover" })).toContain("/image?");
265
+ });
266
+ });
@@ -131,6 +131,19 @@ function optimizeShopify(originalSrc: string, width: number, height?: number): s
131
131
  return url.href;
132
132
  }
133
133
 
134
+ // Nuvemshop's product CDN serves only fixed sizes, picked by a filename suffix
135
+ // (`…-480-0.webp`, `…-1024-1024.webp`); any other size answers 403, and so does
136
+ // the deco image proxy for this host.
137
+ const NUVEMSHOP_IMAGE_RE =
138
+ /^(https:\/\/[a-z0-9-]+\.mitiendanube\.com\/stores\/.+\/products\/.+)-\d+-\d+\.(\w+)$/;
139
+ const NUVEMSHOP_SIZES = [50, 100, 240, 320, 480, 640];
140
+
141
+ function optimizeNuvemshop(match: RegExpMatchArray, width: number): string {
142
+ const [, base, ext] = match;
143
+ const size = NUVEMSHOP_SIZES.find((s) => s >= width);
144
+ return `${base}-${size ? `${size}-0` : "1024-1024"}.${ext}`;
145
+ }
146
+
134
147
  // -------------------------------------------------------------------------
135
148
  // Core optimization function
136
149
  // Ported from deco-cx/apps website/components/Image.tsx
@@ -142,7 +155,7 @@ function optimizeShopify(originalSrc: string, width: number, height?: number): s
142
155
  * For Deco-hosted images (decocache / S3 / decoims), strips the known prefix and
143
156
  * routes through the Deco image CDN for edge resize + format conversion.
144
157
  *
145
- * For platform-specific images (VTEX, Shopify), rewrites the URL using
158
+ * For platform-specific images (VTEX, Shopify, Nuvemshop), rewrites the URL using
146
159
  * the platform's native resize params — no CDN proxy needed.
147
160
  *
148
161
  * Data URIs are returned as-is.
@@ -176,6 +189,9 @@ export function getOptimizedMediaUrl(opts: OptimizationOptions): string {
176
189
  return optimizeShopify(originalSrc, width, height);
177
190
  }
178
191
 
192
+ const nuvemshop = originalSrc.match(NUVEMSHOP_IMAGE_RE);
193
+ if (nuvemshop) return optimizeNuvemshop(nuvemshop, width);
194
+
179
195
  let imageSource = originalSrc.replace(DECO_ASSET_PREFIX_RE, "").split("?")[0];
180
196
  if (CLOUDFLARE_CDNS.has(imageCdnDomain)) imageSource = imageSource.replace(DECOIMS_PREFIX_RE, "");
181
197