@decocms/tanstack 7.50.1 → 7.52.0

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/tanstack",
3
- "version": "7.50.1",
3
+ "version": "7.52.0",
4
4
  "type": "module",
5
5
  "description": "Deco framework binding for TanStack Start + Cloudflare Workers",
6
6
  "repository": {
@@ -24,9 +24,9 @@
24
24
  "lint:unused": "knip"
25
25
  },
26
26
  "dependencies": {
27
- "@decocms/blocks": "7.50.1",
28
- "@decocms/blocks-admin": "7.50.1",
29
- "@decocms/blocks-cli": "7.50.1",
27
+ "@decocms/blocks": "7.52.0",
28
+ "@decocms/blocks-admin": "7.52.0",
29
+ "@decocms/blocks-cli": "7.52.0",
30
30
  "@deco-cx/warp-node": "^0.3.16",
31
31
  "fast-json-patch": "^3.1.0",
32
32
  "ws": "^8.18.0"
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  clearDraftCache,
3
3
  getRequestDraftOverride,
4
+ isDraftPreviewEnabled,
5
+ setDecoSiteHost,
4
6
  setDraftPreviewHosts,
5
7
  } from "@decocms/blocks/cms";
6
8
  import { RequestContext } from "@decocms/blocks/sdk/requestContext";
@@ -10,6 +12,7 @@ import {
10
12
  applyDraftCookieAndHeaders,
11
13
  bindRequestDraft,
12
14
  type DraftDecision,
15
+ installDecoSiteHostFromEnv,
13
16
  installPreviewHostsFromBlocks,
14
17
  registerDraftOverride,
15
18
  requestCarriesDraft,
@@ -297,3 +300,42 @@ describe("installPreviewHostsFromBlocks", () => {
297
300
  ).toBe(false);
298
301
  });
299
302
  });
303
+
304
+ describe("installDecoSiteHostFromEnv", () => {
305
+ afterEach(() => {
306
+ setDecoSiteHost(null);
307
+ });
308
+
309
+ it("arms the deco-hosted domains from the DECO_SITE_NAME binding", () => {
310
+ setDraftPreviewHosts([]);
311
+ installDecoSiteHostFromEnv({ DECO_SITE_NAME: "casaevideo-tanstack" });
312
+
313
+ // Verified through the wire: both deco-operated hosts now preview, with no
314
+ // site-block/env config at all.
315
+ for (const host of [
316
+ "casaevideo-tanstack.deco.site",
317
+ "casaevideo-tanstack.deco-cx.workers.dev",
318
+ ]) {
319
+ const url = new URL(
320
+ `https://${host}/p?__draft=abc.preview-studio.decocms.com@v1`,
321
+ );
322
+ expect(requestCarriesDraft(req({ url: url.toString(), host }), url)).toBe(true);
323
+ }
324
+ // A custom production domain is never inferred.
325
+ const url = new URL("https://www.casaevideo.com.br/p?__draft=x@v1");
326
+ expect(
327
+ requestCarriesDraft(
328
+ req({ url: url.toString(), host: "www.casaevideo.com.br" }),
329
+ url,
330
+ ),
331
+ ).toBe(false);
332
+ });
333
+
334
+ it("an unset or non-string binding registers nothing", () => {
335
+ setDraftPreviewHosts([]);
336
+ installDecoSiteHostFromEnv({});
337
+ expect(isDraftPreviewEnabled({})).toBe(false);
338
+ installDecoSiteHostFromEnv({ DECO_SITE_NAME: 42 });
339
+ expect(isDraftPreviewEnabled({})).toBe(false);
340
+ });
341
+ });
package/src/sdk/draft.ts CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  isDraftHostAllowed,
38
38
  isDraftPreviewEnabled,
39
39
  resolveDraftForRequest,
40
+ setDecoSiteHost,
40
41
  setDraftOverrideGetter,
41
42
  setDraftPreviewHosts,
42
43
  } from "@decocms/blocks/cms";
@@ -90,6 +91,28 @@ export function installPreviewHostsFromBlocks(blocks: Record<string, unknown> |
90
91
  if (Array.isArray(site?.previewHosts)) setDraftPreviewHosts(site.previewHosts);
91
92
  }
92
93
 
94
+ /**
95
+ * Register the deco-operated preview hosts inferred from the site name —
96
+ * `<site>.deco.site` and `<site>.deco-cx.workers.dev` (the workers.dev deploy
97
+ * URL, e.g. `casaevideo-tanstack.deco-cx.workers.dev`) — so a signed
98
+ * `?__draft=` grant previews on deco-hosted infra with zero per-site config.
99
+ *
100
+ * Fed from the Workers env binding `DECO_SITE_NAME`: deploy-time configuration
101
+ * set by deco's hosting, trusted the same way `DECO_ALLOWED_PREVIEW_HOSTS` is —
102
+ * never derived from the request. Merged ON TOP of the site block/env list
103
+ * (see `setDecoSiteHost` in `@decocms/blocks`); an unset binding registers
104
+ * nothing, and `DECO_ALLOWED_PREVIEW_HOSTS=none` kills the inferred hosts too.
105
+ *
106
+ * This inference is deliberately tanstack-only (like Fast Deploy): the
107
+ * deco-operated domains only ever serve Workers deployments, and in the Next
108
+ * binding flipping `isDraftPreviewEnabled()` on costs every page its
109
+ * static/ISR rendering — Next sites keep the explicit opt-in.
110
+ */
111
+ export function installDecoSiteHostFromEnv(env: Record<string, unknown>): void {
112
+ const site = env.DECO_SITE_NAME;
113
+ setDecoSiteHost(typeof site === "string" ? site : undefined);
114
+ }
115
+
93
116
  // ---------------------------------------------------------------------------
94
117
  // Per-request resolution + response decoration
95
118
  // ---------------------------------------------------------------------------
@@ -82,6 +82,7 @@ import {
82
82
  applyDraftCookieAndHeaders,
83
83
  bindRequestDraft,
84
84
  type DraftDecision,
85
+ installDecoSiteHostFromEnv,
85
86
  installPreviewHostsFromBlocks,
86
87
  registerDraftOverride,
87
88
  requestCarriesDraft,
@@ -1553,6 +1554,14 @@ export function createDecoWorkerEntry(
1553
1554
  const reqUrl = new URL(request.url);
1554
1555
  const method = request.method;
1555
1556
 
1557
+ // Deco-hosted preview hosts (`<site>.deco.site`,
1558
+ // `<site>.deco-cx.workers.dev`) inferred from the DECO_SITE_NAME
1559
+ // binding. Installed before any draft
1560
+ // gate runs (requestCarriesDraft participates in the cacheability
1561
+ // decision below). The binding is deploy-constant, so this is an
1562
+ // idempotent write.
1563
+ installDecoSiteHostFromEnv(env);
1564
+
1556
1565
  // Inject CF geo data as cookies for location matchers (before anything reads cookies)
1557
1566
  if (geoOpt) {
1558
1567
  request = injectGeoCookies(request);