@notionhq/custom-blocks-dev-shell 0.4.1 → 0.4.3

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/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Custom blocks dev shell
2
2
 
3
- The dev shell runs custom blocks in a local mock Notion host. It builds your worker and runs its
4
- blocks with local sample data. Use it before `ntn workers deploy`.
3
+ Use the dev shell to preview your custom block with local sample data before you deploy. The dev
4
+ shell builds your worker and runs its blocks in a mock Notion host.
5
5
 
6
- ## Usage
6
+ ## Quick start
7
7
 
8
8
  Run this command from your worker project:
9
9
 
@@ -11,10 +11,21 @@ Run this command from your worker project:
11
11
  ntn workers customblocks dev
12
12
  ```
13
13
 
14
- Open the shell URL printed by the command. Blocks hot reload when their source files change. Each
15
- run uses one port for the shell and all blocks. The default is `9873`. If that port is occupied, the
16
- launcher selects the next available port. You can start multiple runs without choosing a port for
17
- each run. Stopping one run leaves the others active.
14
+ Open the shell URL printed by the command and select your block. The dev shell hot reloads changes
15
+ to block source files.
16
+
17
+ ## Documentation
18
+
19
+ - [Dev shell data sources](docs/data-sources.md) explains how to define sample records and use
20
+ data sources generated from worker schemas.
21
+ - [Dev shell bindings](docs/bindings.md) explains how to select a sample data source and map its
22
+ properties.
23
+
24
+ ## Usage
25
+
26
+ Each run uses one port for the shell and all blocks. The default is `9873`. If that port is
27
+ occupied, the launcher selects the next available port. You can start multiple runs without choosing
28
+ a port for each run. Stopping one run leaves the others active.
18
29
 
19
30
  The shell and blocks keep separate browser origins through localhost subdomains:
20
31
 
@@ -135,8 +146,34 @@ Block responses enforce a production-like content security policy (CSP) and send
135
146
  from a CDN at runtime are blocked. WebAssembly compilation is allowed; JavaScript string
136
147
  evaluation remains blocked.
137
148
  - **Media and fonts:** Notion-hosted media and Google Fonts use the same exceptions as production.
138
- - **External access:** Network requests and nested frames may use any origin for now. Browser CORS
139
- checks still apply.
149
+ - **External access:** Network requests and nested frames can use HTTPS origins declared in the
150
+ block's `network.fetch` grants. Browser CORS checks still apply.
151
+
152
+ #### Allow external origins
153
+
154
+ Add a `network.fetch` grant with a bare HTTPS origin to the block declaration in
155
+ `worker.customBlock()`.
156
+
157
+ ```ts
158
+ worker.customBlock("chart", {
159
+ path: "./blocks/chart",
160
+ grants: [{ action: "network.fetch", resource: "https://api.example.com" }],
161
+ })
162
+ ```
163
+
164
+ Restart the dev shell to pick up changes to the manifest.
165
+
166
+ Origin validation follows production. Single-label hosts such as `localhost`, Notion app origins,
167
+ and wildcards over public suffixes such as `*.co.uk` are rejected.
168
+
169
+ The dev shell treats these declarations as local approvals. If you omit `grants`, set `grants: []`,
170
+ or declare only other actions, the preview grants no external origins. Same-origin requests, hot
171
+ reload, and the built-in media and font exceptions still work.
172
+
173
+ The same grants are checked when you write an external URL to a Files property, page icon, or cover.
174
+ An HTTPS URL without a matching grant returns `not_granted` and names the origin to declare. An
175
+ invalid external URL returns `invalid_property_value`. For a blocked browser `fetch()`, check the
176
+ browser console for the CSP violation.
140
177
 
141
178
  #### Differences from production
142
179
 
@@ -147,8 +184,8 @@ Block responses enforce a production-like content security policy (CSP) and send
147
184
  - **Local origins:** Blocks and the shell use HTTP localhost origins instead of production HTTPS
148
185
  origins.
149
186
  - **Hot reload:** CSP permits the block's exact WebSocket host and port for Vite HMR.
150
- - **External access:** Production uses workspace-approved external origins. The dev shell currently
151
- allows all origins.
187
+ - **External access:** Production resolves approvals separately from the manifest. Depending on the
188
+ approval flow, it can also allow origins from the workspace network allowlist.
152
189
  - **Embedding hosts:** Any host may embed local blocks for now, including Notion apps in every
153
190
  environment.
154
191
  - **Parent navigation policy:** The shell does not apply production's parent navigation CSP. The
@@ -201,23 +238,3 @@ create a new host and iframe.
201
238
  `links.open` uses a host-owned confirmation before opening the normalized URL shown in the
202
239
  confirmation. The dev shell supports only HTTP and HTTPS. Other schemes return `invalid_url` without
203
240
  showing a prompt. Production Notion also applies its existing URL sanitizer.
204
-
205
- ## Documentation
206
-
207
- These docs ship with the package and are available from `node_modules`:
208
-
209
- - [`docs/bindings.md`](docs/bindings.md): Connect blocks to data sources. The page covers
210
- automatic mapping, compatibility, initialization, and live rebinding.
211
- - [`docs/data-sources.md`](docs/data-sources.md): Define local data sources in `data/*.json`. The
212
- page covers value shapes, validation, and files generated from worker schemas.
213
-
214
- The shared guides also include [host integration documentation](docs/host/README.md) for reference.
215
-
216
- Use the SDK's public APIs to build blocks. The bridge references below are for debugging
217
- communication between the SDK and host and investigating version compatibility.
218
-
219
- - [Bridge wire protocol](docs/bridge/protocol.md): Message identity, validation, and payload
220
- semantics.
221
- - [Versioning and compatibility](docs/bridge/versioning.md): Protocol identifiers and
222
- version-change rules.
223
- - [Protocol changelog](docs/bridge/changelog.md): Breaking changes and SDK release boundaries.