@notionhq/custom-blocks-dev-shell 0.4.0 → 0.4.2
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 +59 -41
- package/dist/assets/index-BPt5jNdQ.js +12 -0
- package/dist/assets/{index-B4LAgGzW.css → index-CohEBjwO.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-cli/cli/published-cli.js +10472 -324
- package/docs/bindings.md +8 -7
- package/package.json +2 -8
- package/dist/assets/index-CjUu48lJ.js +0 -12
- package/docs/bridge/changelog.md +0 -157
- package/docs/bridge/protocol.md +0 -309
- package/docs/bridge/versioning.md +0 -51
- package/docs/host/README.md +0 -202
- package/docs/host/docs/compatibility.md +0 -114
- package/docs/host/docs/handlers.md +0 -110
- package/docs/host/docs/host-contract.md +0 -196
- package/docs/host/docs/lifecycle.md +0 -133
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Custom blocks dev shell
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
##
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
|
@@ -132,10 +143,37 @@ Block responses enforce a production-like content security policy (CSP) and send
|
|
|
132
143
|
- **Blocked features:** Native form submission, browser workers, `<object>`, `<embed>`, web app
|
|
133
144
|
manifests, and `<base>`.
|
|
134
145
|
- **Scripts and styles:** Bundled scripts, inline scripts, and inline styles work. Scripts loaded
|
|
135
|
-
from a CDN at runtime are blocked.
|
|
146
|
+
from a CDN at runtime are blocked. WebAssembly compilation is allowed; JavaScript string
|
|
147
|
+
evaluation remains blocked.
|
|
136
148
|
- **Media and fonts:** Notion-hosted media and Google Fonts use the same exceptions as production.
|
|
137
|
-
- **External access:** Network requests and nested frames
|
|
138
|
-
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.
|
|
139
177
|
|
|
140
178
|
#### Differences from production
|
|
141
179
|
|
|
@@ -146,8 +184,8 @@ Block responses enforce a production-like content security policy (CSP) and send
|
|
|
146
184
|
- **Local origins:** Blocks and the shell use HTTP localhost origins instead of production HTTPS
|
|
147
185
|
origins.
|
|
148
186
|
- **Hot reload:** CSP permits the block's exact WebSocket host and port for Vite HMR.
|
|
149
|
-
- **External access:** Production
|
|
150
|
-
|
|
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.
|
|
151
189
|
- **Embedding hosts:** Any host may embed local blocks for now, including Notion apps in every
|
|
152
190
|
environment.
|
|
153
191
|
- **Parent navigation policy:** The shell does not apply production's parent navigation CSP. The
|
|
@@ -159,13 +197,13 @@ Block responses enforce a production-like content security policy (CSP) and send
|
|
|
159
197
|
|
|
160
198
|
### Reload behavior
|
|
161
199
|
|
|
162
|
-
| Change
|
|
163
|
-
|
|
|
164
|
-
| Block code or styles
|
|
165
|
-
| Retry or changes to
|
|
166
|
-
| Loaded sample filenames, schemas, or rows
|
|
167
|
-
| Browser refresh
|
|
168
|
-
| Worker declarations, including data source definitions
|
|
200
|
+
| Change | What happens |
|
|
201
|
+
| -------------------------------------------------------------------- | --------------------------------------------------------------------- |
|
|
202
|
+
| Block code or styles | Vite applies hot updates. |
|
|
203
|
+
| Retry or changes to the block, data source bindings, or display mode | The preview restarts. Page records stay in memory. |
|
|
204
|
+
| Loaded sample filenames, schemas, or rows | All page records reset to the sample files, and the preview restarts. |
|
|
205
|
+
| Browser refresh | All page records reset to the sample files. |
|
|
206
|
+
| Worker declarations, including data source definitions | Restart the dev shell to rebuild the manifest. |
|
|
169
207
|
|
|
170
208
|
See [live updates and local writes](docs/data-sources.md#live-updates-and-local-writes) for sample
|
|
171
209
|
changes and error recovery.
|
|
@@ -173,8 +211,8 @@ changes and error recovery.
|
|
|
173
211
|
### Sample users
|
|
174
212
|
|
|
175
213
|
The dev shell provides a fixed set of sample users, with Ada Lovelace as the current user.
|
|
176
|
-
`
|
|
177
|
-
reloads and changes to sample data files preserve these user identities.
|
|
214
|
+
`getViewer()` identifies the viewer. `NotionUser` field reads and `listUsers()` use the same
|
|
215
|
+
profiles. Block reloads and changes to sample data files preserve these user identities.
|
|
178
216
|
|
|
179
217
|
The built-in People data source contains directory pages that reference sample users. Adding,
|
|
180
218
|
editing, or deleting a worker's People file does not change the sample users.
|
|
@@ -200,23 +238,3 @@ create a new host and iframe.
|
|
|
200
238
|
`links.open` uses a host-owned confirmation before opening the normalized URL shown in the
|
|
201
239
|
confirmation. The dev shell supports only HTTP and HTTPS. Other schemes return `invalid_url` without
|
|
202
240
|
showing a prompt. Production Notion also applies its existing URL sanitizer.
|
|
203
|
-
|
|
204
|
-
## Documentation
|
|
205
|
-
|
|
206
|
-
These docs ship with the package and are available from `node_modules`:
|
|
207
|
-
|
|
208
|
-
- [`docs/bindings.md`](docs/bindings.md): Connect blocks to data sources. The page covers
|
|
209
|
-
automatic mapping, compatibility, initialization, and live rebinding.
|
|
210
|
-
- [`docs/data-sources.md`](docs/data-sources.md): Define local data sources in `data/*.json`. The
|
|
211
|
-
page covers value shapes, validation, and files generated from worker schemas.
|
|
212
|
-
|
|
213
|
-
The shared guides also include [host integration documentation](docs/host/README.md) for reference.
|
|
214
|
-
|
|
215
|
-
Use the SDK's public APIs to build blocks. The bridge references below are for debugging
|
|
216
|
-
communication between the SDK and host and investigating version compatibility.
|
|
217
|
-
|
|
218
|
-
- [Bridge wire protocol](docs/bridge/protocol.md): Message identity, validation, and payload
|
|
219
|
-
semantics.
|
|
220
|
-
- [Versioning and compatibility](docs/bridge/versioning.md): Protocol identifiers and
|
|
221
|
-
version-change rules.
|
|
222
|
-
- [Protocol changelog](docs/bridge/changelog.md): Breaking changes and SDK release boundaries.
|