@decocms/blocks-admin 7.3.0 → 7.4.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 +2 -2
- package/src/admin/decofile.test.ts +13 -3
- package/src/admin/decofile.ts +17 -8
- package/src/admin/render.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks-admin",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco admin protocol: /live/_meta, /.decofile, /deco/invoke, /deco/render, plus admin-facing site setup and commerce-app auto-configuration",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint:unused": "knip"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@decocms/blocks": "7.
|
|
28
|
+
"@decocms/blocks": "7.4.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": "^19.0.0",
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
2
2
|
import { KV_KEYS, type KVNamespace, getRevision, loadBlocks, setBlocks } from "@decocms/blocks/cms";
|
|
3
3
|
import { handleDecofileReload, setFastDeployKVGetter } from "./decofile";
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// handleDecofileReload's dev-bypass keys off NODE_ENV === "development" (see
|
|
6
|
+
// decofile.ts), not import.meta.env.DEV. Vitest itself runs with
|
|
7
|
+
// NODE_ENV=test (not "development"), so force it here to preserve this
|
|
8
|
+
// suite's original intent: exercise the reload handler via the same no-auth
|
|
9
|
+
// branch the dev Vite plugin / `next dev` use, without needing a token.
|
|
10
|
+
const ORIGINAL_NODE_ENV = process.env.NODE_ENV;
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
process.env.NODE_ENV = "development";
|
|
13
|
+
});
|
|
14
|
+
afterAll(() => {
|
|
15
|
+
process.env.NODE_ENV = ORIGINAL_NODE_ENV;
|
|
16
|
+
});
|
|
7
17
|
|
|
8
18
|
// decofile.ts no longer hard-imports getFastDeployKV (that would create a
|
|
9
19
|
// admin → tanstack dependency, which is backwards). Instead the
|
package/src/admin/decofile.ts
CHANGED
|
@@ -105,14 +105,23 @@ export async function handleDecofileReload(
|
|
|
105
105
|
// both the reload token and the fast-deploy KV binding.
|
|
106
106
|
const runtimeEnv = env ?? getRuntimeEnv();
|
|
107
107
|
|
|
108
|
-
// In dev mode the Vite plugin
|
|
109
|
-
// module invalidation (which breaks TanStack
|
|
110
|
-
// so the plugin can POST from localhost.
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
// In dev mode the Vite plugin (tanstack) or `next dev` POSTs new blocks
|
|
109
|
+
// here to hot-reload without module invalidation (which breaks TanStack
|
|
110
|
+
// Start/Router state). Skip auth so the plugin can POST from localhost.
|
|
111
|
+
//
|
|
112
|
+
// `import.meta.env?.DEV` was a Vite-ism AND a syntax error for CJS
|
|
113
|
+
// consumers (ts-jest compiles this raw-TS package to CJS, where
|
|
114
|
+
// `import.meta` cannot be represented at all). It was also always `false`
|
|
115
|
+
// under Next.js — Turbopack/webpack never define `import.meta.env` — so
|
|
116
|
+
// this dev-bypass never applied to `next dev` before this change. Checking
|
|
117
|
+
// NODE_ENV instead widens the bypass to any Node process with
|
|
118
|
+
// NODE_ENV=development, including `next dev`. That widening is intentional:
|
|
119
|
+
// dev environments shouldn't need a production reload token, and the check
|
|
120
|
+
// remains fail-closed (auth required) for any other NODE_ENV value (unset,
|
|
121
|
+
// "test", "production").
|
|
122
|
+
const isDevRuntime =
|
|
123
|
+
typeof process !== "undefined" && process.env.NODE_ENV === "development";
|
|
124
|
+
if (!isDevRuntime) {
|
|
116
125
|
const authHeader = request.headers.get("Authorization") || "";
|
|
117
126
|
const expectedToken =
|
|
118
127
|
(runtimeEnv?.DECO_RELEASE_RELOAD_TOKEN as string | undefined) ??
|
package/src/admin/render.ts
CHANGED
|
@@ -132,7 +132,6 @@ export async function handleRender(request: Request): Promise<Response> {
|
|
|
132
132
|
const url = new URL(request.url);
|
|
133
133
|
const resolveChain = url.searchParams.get("resolveChain");
|
|
134
134
|
const propsParam = url.searchParams.get("props");
|
|
135
|
-
console.log("handleRender", request.url);
|
|
136
135
|
|
|
137
136
|
const pathPrefix = "/live/previews/";
|
|
138
137
|
const rawPathComponent = url.pathname.startsWith(pathPrefix)
|