@decocms/blocks 7.71.0 → 7.71.2

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.0",
3
+ "version": "7.71.2",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import {
3
3
  canonicalizeServerFnPayloadForCacheKey,
4
+ payloadHasTrackingParams,
4
5
  detectCacheProfile,
5
6
  getCacheProfile,
6
7
  registerCachePattern,
@@ -232,3 +233,26 @@ describe("cache configuration can tighten, not loosen", () => {
232
233
  expect(detectCacheProfile("/tenis")).toBe("static");
233
234
  });
234
235
  });
236
+
237
+ describe("payloadHasTrackingParams", () => {
238
+ const p = (v: unknown) => JSON.stringify(v);
239
+
240
+ it("finds a tracking param in an embedded absolute URL", () => {
241
+ expect(payloadHasTrackingParams(p({ data: { pageUrl: "https://x.test/p?gclid=1" } }))).toBe(
242
+ true,
243
+ );
244
+ });
245
+
246
+ it("finds a tracking param in an embedded route path", () => {
247
+ expect(payloadHasTrackingParams(p(["/produtos?utm_source=ads&page=2"]))).toBe(true);
248
+ });
249
+
250
+ it("ignores real params and plain strings", () => {
251
+ expect(payloadHasTrackingParams(p({ pageUrl: "/produtos?sort=price:asc&page=2" }))).toBe(false);
252
+ expect(payloadHasTrackingParams(p({ label: "gclid=1 in a sentence" }))).toBe(false);
253
+ });
254
+
255
+ it("is fail-safe on malformed payloads", () => {
256
+ expect(payloadHasTrackingParams("not json {")).toBe(false);
257
+ });
258
+ });
@@ -508,6 +508,55 @@ export function serverFnPagePath(url: URL): string | null {
508
508
  }
509
509
  }
510
510
 
511
+ /**
512
+ * `true` when a server-fn payload (GET `payload` param or POST body) embeds a
513
+ * route path or absolute URL carrying a tracking param — e.g. a deferred
514
+ * section's `pageUrl` built from `location.href` on an ad landing. Same walk as
515
+ * {@link canonicalizeServerFnPayloadForCacheKey}. Returns `false` on any parse
516
+ * failure (fail-safe: the caller keeps its normal behavior).
517
+ */
518
+ export function payloadHasTrackingParams(payload: string): boolean {
519
+ try {
520
+ let found = false;
521
+ const check = (s: string): void => {
522
+ let search: string;
523
+ if (/^https?:\/\//i.test(s)) {
524
+ try {
525
+ search = new URL(s).search;
526
+ } catch {
527
+ return;
528
+ }
529
+ } else if (s.startsWith("/") && !s.startsWith("//")) {
530
+ const q = s.indexOf("?");
531
+ if (q < 0) return;
532
+ search = s.slice(q);
533
+ } else {
534
+ return;
535
+ }
536
+ for (const k of new URLSearchParams(search).keys()) {
537
+ if (isTrackingParam(k)) {
538
+ found = true;
539
+ return;
540
+ }
541
+ }
542
+ };
543
+ const visit = (v: unknown): void => {
544
+ if (found) return;
545
+ if (typeof v === "string") {
546
+ check(v);
547
+ } else if (Array.isArray(v)) {
548
+ for (const x of v) visit(x);
549
+ } else if (v && typeof v === "object") {
550
+ for (const x of Object.values(v)) visit(x);
551
+ }
552
+ };
553
+ visit(JSON.parse(payload));
554
+ return found;
555
+ } catch {
556
+ return false;
557
+ }
558
+ }
559
+
511
560
  /**
512
561
  * Search params that never change a CMS page's resolved server-fn response and
513
562
  * so must not fragment its edge cache key. `skuId`/`idsku` select a product