@notionhq/custom-blocks-dev-shell 0.1.99 → 0.1.100
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.
|
@@ -59,6 +59,22 @@ const captureRuntimeErrors = {
|
|
|
59
59
|
},
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Allows Notion apps and local hosts to read the dev server's manifest.
|
|
64
|
+
* CORS checks the requesting page's origin, so hosted Notion origins must
|
|
65
|
+
* be allowed even though the manifest is served from localhost.
|
|
66
|
+
*/
|
|
67
|
+
function isAllowedManifestOrigin(origin) {
|
|
68
|
+
if (!origin) {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const localOrigin = ${/^https?:\/\/(?:(?:[a-z0-9-]+\.)*localhost|127\.0\.0\.1|\[::1\]|local\.notion\.so)(?::[0-9]+)?$/i}
|
|
73
|
+
const notionOrigin = ${/^https:\/\/(?:(?:dev|stg|www)\.notion\.so|app(?:\.(?:local|dev|stg|prod|canary))?\.notion\.com)$/i}
|
|
74
|
+
|
|
75
|
+
return localOrigin.test(origin) || notionOrigin.test(origin)
|
|
76
|
+
}
|
|
77
|
+
|
|
62
78
|
const serveWorkerManifest = {
|
|
63
79
|
name: "dev-shell:worker-block-manifest",
|
|
64
80
|
enforce: "pre",
|
|
@@ -68,6 +84,13 @@ const serveWorkerManifest = {
|
|
|
68
84
|
next()
|
|
69
85
|
return
|
|
70
86
|
}
|
|
87
|
+
// Notion hosts read custom blocks' manifests for in-app preview.
|
|
88
|
+
// Allow CORS for these reads without opening other routes.
|
|
89
|
+
const { origin } = req.headers
|
|
90
|
+
if (isAllowedManifestOrigin(origin)) {
|
|
91
|
+
res.setHeader("Access-Control-Allow-Origin", origin)
|
|
92
|
+
}
|
|
93
|
+
res.setHeader("Vary", "Origin")
|
|
71
94
|
res.setHeader("Content-Type", "application/json")
|
|
72
95
|
res.end(manifest)
|
|
73
96
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/custom-blocks-dev-shell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.100",
|
|
4
4
|
"description": "Local preview shell for Notion custom block workers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"vite": "^8.2.2",
|
|
37
37
|
"vitest": "^5.0.0",
|
|
38
38
|
"@notionhq/custom-blocks-protocol": "0.1.0",
|
|
39
|
-
"@notionhq/custom-blocks-host": "0.2.
|
|
39
|
+
"@notionhq/custom-blocks-host": "0.2.16"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "vite",
|