@decocms/blocks 7.71.4 → 7.71.5

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.71.4",
3
+ "version": "7.71.5",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -985,6 +985,45 @@ describe("extractSeoFromProps — commerce jsonLD structured data", () => {
985
985
  expect(seo.jsonLDs?.[0].numberOfItems).toBe(2);
986
986
  });
987
987
 
988
+ it("makes path-only breadcrumb items absolute without touching the source", () => {
989
+ const breadcrumb = {
990
+ "@type": "BreadcrumbList",
991
+ itemListElement: [
992
+ { "@type": "ListItem", position: 1, name: "Cat", item: "/cat" },
993
+ { "@type": "ListItem", position: 2, name: "Sub", item: "https://y.com/cat/sub" },
994
+ ],
995
+ };
996
+ const seo = extractSeoFromProps({
997
+ jsonLD: plp({ breadcrumb, products: [{ name: "A", url: "https://x.com/a/p" }] }),
998
+ });
999
+ expect(seo.jsonLDs?.[1].itemListElement.map((el: { item: string }) => el.item)).toEqual([
1000
+ "https://x.com/cat",
1001
+ "https://y.com/cat/sub",
1002
+ ]);
1003
+ // In-app breadcrumb (section data) keeps its relative links.
1004
+ expect(breadcrumb.itemListElement[0].item).toBe("/cat");
1005
+ });
1006
+
1007
+ it("falls back to seo.canonical for the origin and leaves //host items alone", () => {
1008
+ const seo = extractSeoFromProps({
1009
+ jsonLD: plp({
1010
+ seo: { title: "T", canonical: "https://z.com/cat" },
1011
+ products: [{ name: "No URL" }, { name: "A", url: "/a/p" }],
1012
+ breadcrumb: {
1013
+ "@type": "BreadcrumbList",
1014
+ itemListElement: [
1015
+ { "@type": "ListItem", position: 1, name: "Cat", item: "/cat" },
1016
+ { "@type": "ListItem", position: 2, name: "Ext", item: "//evil.com/x" },
1017
+ ],
1018
+ },
1019
+ }),
1020
+ });
1021
+ expect(seo.jsonLDs?.[1].itemListElement.map((el: { item: string }) => el.item)).toEqual([
1022
+ "https://z.com/cat",
1023
+ "//evil.com/x",
1024
+ ]);
1025
+ });
1026
+
988
1027
  it("omits the BreadcrumbList when the listing has no breadcrumb", () => {
989
1028
  const seo = extractSeoFromProps({ jsonLD: plp({ breadcrumb: undefined }) });
990
1029
  expect(seo.jsonLDs).toHaveLength(1);
@@ -2023,11 +2023,31 @@ function plpStructuredData(plp: Record<string, any>): Record<string, unknown>[]
2023
2023
  },
2024
2024
  ];
2025
2025
  if (plp.breadcrumb?.itemListElement?.length) {
2026
- out.push({ ...plp.breadcrumb, "@context": "https://schema.org" });
2026
+ // Loaders emit path-only breadcrumb items (`/a/b`) for in-app links; in
2027
+ // structured data make them absolute, using the products' origin.
2028
+ const origin = originOf(itemListElement[0]?.url) ?? originOf(plp.seo?.canonical);
2029
+ out.push({
2030
+ ...plp.breadcrumb,
2031
+ "@context": "https://schema.org",
2032
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2033
+ itemListElement: plp.breadcrumb.itemListElement.map((el: any) =>
2034
+ origin && typeof el.item === "string" && /^\/(?!\/)/.test(el.item)
2035
+ ? { ...el, item: new URL(el.item, origin).href }
2036
+ : el,
2037
+ ),
2038
+ });
2027
2039
  }
2028
2040
  return out;
2029
2041
  }
2030
2042
 
2043
+ function originOf(url: unknown): string | undefined {
2044
+ try {
2045
+ return typeof url === "string" ? new URL(url).origin : undefined;
2046
+ } catch {
2047
+ return undefined;
2048
+ }
2049
+ }
2050
+
2031
2051
  /**
2032
2052
  * Derive SEO metadata from a commerce `jsonLD` data source (a resolved
2033
2053
  * ProductListingPage / ProductDetailsPage), mirroring the deco-cx
@@ -1,9 +1,11 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import {
3
+ getImageCdnDomain,
3
4
  getImageQuality,
4
5
  getOptimizedMediaUrl,
5
6
  getSrcSet,
6
7
  type ImageQuality,
8
+ registerImageCdnDomain,
7
9
  registerImageQuality,
8
10
  } from "./Image";
9
11
 
@@ -105,6 +107,22 @@ describe("getOptimizedMediaUrl", () => {
105
107
  expect(result).toMatch(/&src=site\/a\.png$/);
106
108
  });
107
109
 
110
+ it("keeps decoims.com absolute on Azion CDNs, which may 404 the relative path", () => {
111
+ const prev = getImageCdnDomain();
112
+ registerImageCdnDomain("deco-assets.edgedeco.com");
113
+ try {
114
+ const result = getOptimizedMediaUrl({
115
+ originalSrc: "https://decoims.com/site/a.png",
116
+ width: 100,
117
+ fit: "cover",
118
+ });
119
+ expect(result).toContain("https://deco-assets.edgedeco.com/image?");
120
+ expect(result).toContain("&src=https://decoims.com/site/a.png");
121
+ } finally {
122
+ registerImageCdnDomain(prev);
123
+ }
124
+ });
125
+
108
126
  it("only strips a leading Deco host", () => {
109
127
  const result = getOptimizedMediaUrl({
110
128
  originalSrc: "https://cdn.example.com/https://decoims.com/x.png",
@@ -5,11 +5,15 @@ import { forwardRef } from "react";
5
5
  // Known asset prefixes that get stripped to produce a relative src path
6
6
  // -------------------------------------------------------------------------
7
7
 
8
- // decocache, S3, and decoims.com — the legacy default image CDN (pre-#495).
9
- // Decofiles are full of decoims URLs; passing one as `src=` to a Deco CDN makes
10
- // it fetch itself → 508 Loop Detected. Anchored: only a leading host is stripped.
8
+ // Anchored: only a leading host is stripped.
11
9
  const DECO_ASSET_PREFIX_RE =
12
- /^https:\/\/(?:assets\.decocache\.com|deco-sites-assets\.s3\.sa-east-1\.amazonaws\.com|decoims\.com)\//;
10
+ /^https:\/\/(?:assets\.decocache\.com|deco-sites-assets\.s3\.sa-east-1\.amazonaws\.com)\//;
11
+ // decoims.com — the legacy default image CDN (pre-#495). Decofiles are full of
12
+ // these URLs; passing one as `src=` to a Cloudflare Deco CDN makes it fetch
13
+ // itself → 508 Loop Detected. Azion CDNs (edgedeco/decoazn) fetch it fine but
14
+ // may 404 on the relative path, so only strip it for the Cloudflare ones.
15
+ const DECOIMS_PREFIX_RE = /^https:\/\/decoims\.com\//;
16
+ const CLOUDFLARE_CDNS = new Set(["assets.decocms.com", "decoims.com"]);
13
17
 
14
18
  // -------------------------------------------------------------------------
15
19
  // Configurable CDN domain
@@ -173,6 +177,7 @@ export function getOptimizedMediaUrl(opts: OptimizationOptions): string {
173
177
  }
174
178
 
175
179
  let imageSource = originalSrc.replace(DECO_ASSET_PREFIX_RE, "").split("?")[0];
180
+ if (CLOUDFLARE_CDNS.has(imageCdnDomain)) imageSource = imageSource.replace(DECOIMS_PREFIX_RE, "");
176
181
 
177
182
  // Already on the image CDN — strip the host so we don't proxy through ourselves.
178
183
  const cdnPrefix = `https://${imageCdnDomain}/`;