@decocms/tanstack 7.51.0 → 7.52.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/tanstack",
3
- "version": "7.51.0",
3
+ "version": "7.52.1",
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.51.0",
28
- "@decocms/blocks-admin": "7.51.0",
29
- "@decocms/blocks-cli": "7.51.0",
27
+ "@decocms/blocks": "7.52.1",
28
+ "@decocms/blocks-admin": "7.52.1",
29
+ "@decocms/blocks-cli": "7.52.1",
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);
@@ -157,20 +157,20 @@ const STUB_SOURCE = {
157
157
  /**
158
158
  * Argv (after the generate-schema.ts script path) for a meta.gen.json run.
159
159
  *
160
- * `--compose` is MANDATORY. Without it generate-schema emits an UNCOMPOSED
161
- * manifest missing every framework `website/*` block (Page, matchers,
162
- * __SECTION_REF__, Resolvable). meta.gen.json is committed and Studio reads it
163
- * as-is (no composeMeta at read time), so an uncomposed rewrite silently breaks
164
- * the admin editors — e.g. the date matcher powering variant rules disappears
165
- * (casaevideo-tanstack #633). Mirrors `npm run generate`'s schema step
166
- * (`blocks-cli generate --compose`). Both invocation sites in configureServer
167
- * derive their args here so the flag can never drift off one of them.
160
+ * generate-schema ALWAYS composes before writing, so the emitted meta.gen.json
161
+ * carries every framework `website/*` block (Page, matchers, __SECTION_REF__,
162
+ * Resolvable). This matters because meta.gen.json is committed and Studio reads
163
+ * it as-is (no composeMeta at read time) — an uncomposed rewrite would silently
164
+ * break the admin editors, e.g. the date matcher powering variant rules
165
+ * disappearing (casaevideo-tanstack #633). Mirrors `npm run generate`'s schema
166
+ * step. Both invocation sites in configureServer derive their args here so they
167
+ * can never drift apart.
168
168
  *
169
169
  * @param {string} siteName
170
170
  * @returns {string[]}
171
171
  */
172
172
  export function generateSchemaArgs(siteName) {
173
- return ["--site", siteName, "--compose"];
173
+ return ["--site", siteName];
174
174
  }
175
175
 
176
176
  /** @returns {import("vite").PluginOption} */
@@ -473,8 +473,8 @@ export function decoVitePlugin() {
473
473
  // re-run generate-schema.ts so meta.gen.json stays in sync during dev.
474
474
  // No --out is passed to the generator below, so it writes to its own
475
475
  // default (.deco/meta.gen.json) — this constant must track that default.
476
- // Both invocations get their args from generateSchemaArgs(), which pins
477
- // the mandatory --compose flag (see its doc comment).
476
+ // Both invocations get their args from generateSchemaArgs() so they can't
477
+ // drift apart (see its doc comment).
478
478
  const schemaWatchDirs = ["src"];
479
479
  const schemaOutFile = path.resolve(cwd, ".deco/meta.gen.json");
480
480
 
@@ -55,17 +55,12 @@ describe("decoVitePlugin client stubs (regression guard)", () => {
55
55
 
56
56
  describe("generateSchemaArgs (regression: meta.gen.json must be composed)", () => {
57
57
  // Both generate-schema.ts invocations in configureServer (watch regen + cold
58
- // start) derive their args from this helper. --compose is mandatory: without
59
- // it the manifest is written UNCOMPOSED — missing every framework website/*
60
- // block (matchers/Page/Resolvable) — and Studio, which reads meta.gen.json
61
- // as-is, silently loses editors (e.g. the variant date matcher). See
62
- // casaevideo-tanstack #633.
63
- it("always includes --compose", () => {
64
- expect(generateSchemaArgs("casaevideo")).toContain("--compose");
65
- });
66
-
58
+ // start) derive their args from this helper. generate-schema always composes
59
+ // before writing, so the manifest carries every framework website/* block
60
+ // (matchers/Page/Resolvable) that Studio — which reads meta.gen.json as-is —
61
+ // needs, e.g. the variant date matcher. See casaevideo-tanstack #633.
67
62
  it("targets the given site", () => {
68
- expect(generateSchemaArgs("my-site")).toEqual(["--site", "my-site", "--compose"]);
63
+ expect(generateSchemaArgs("my-site")).toEqual(["--site", "my-site"]);
69
64
  });
70
65
  });
71
66