@notionhq/custom-blocks-dev-shell 0.1.115 → 0.2.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/LICENSE +21 -0
- package/README.md +92 -13
- package/THIRD_PARTY_LICENSES.md +133 -0
- package/dist/assets/index-Do-x8yIt.css +2 -0
- package/dist/assets/index-n0_PUieY.js +11 -0
- package/dist/index.html +2 -2
- package/dist-cli/cli/published-cli.js +8572 -51
- package/docs/bindings.md +17 -12
- package/docs/bridge/changelog.md +94 -0
- package/docs/bridge/protocol.md +239 -0
- package/docs/bridge/versioning.md +39 -0
- package/docs/data-sources.md +49 -36
- package/docs/host/README.md +193 -0
- package/docs/host/docs/compatibility.md +76 -0
- package/docs/host/docs/handlers.md +210 -0
- package/docs/host/docs/lifecycle.md +131 -0
- package/package.json +5 -3
- package/dist/assets/index-DXzPwq_J.js +0 -11
- package/dist/assets/index-E1j3FxAu.css +0 -2
- package/dist-cli/cli/binding-cli-flags.js +0 -33
- package/dist-cli/cli/binding-errors.js +0 -15
- package/dist-cli/cli/block-csp.js +0 -84
- package/dist-cli/cli/build-block-registry.js +0 -30
- package/dist-cli/cli/convert-values.js +0 -222
- package/dist-cli/cli/convert.js +0 -210
- package/dist-cli/cli/data-source-files.js +0 -6
- package/dist-cli/cli/data-sources.js +0 -114
- package/dist-cli/cli/dev-shell-launcher.js +0 -239
- package/dist-cli/cli/dev-shell-run.js +0 -72
- package/dist-cli/cli/errors.js +0 -12
- package/dist-cli/cli/launcher-bindings.js +0 -144
- package/dist-cli/cli/materialize.js +0 -105
- package/dist-cli/cli/ports.js +0 -20
- package/dist-cli/cli/prebuilt.js +0 -23
- package/dist-cli/cli/runtime-error-client.js +0 -52
- package/dist-cli/cli/serve-ui.js +0 -110
- package/dist-cli/cli/shared-server.js +0 -70
- package/dist-cli/cli/utils.js +0 -52
- package/dist-cli/cli/vite-block-server.js +0 -125
- package/dist-cli/cli/vite-middleware.js +0 -111
- package/dist-cli/cli/worker-manifest.js +0 -158
- package/dist-cli/protocol/contrast.d.ts +0 -4
- package/dist-cli/protocol/contrast.js +0 -3
- package/dist-cli/protocol/dataSources/dataSource.d.ts +0 -786
- package/dist-cli/protocol/dataSources/dataSource.js +0 -66
- package/dist-cli/protocol/dataSources/dataSourcePage.d.ts +0 -74
- package/dist-cli/protocol/dataSources/dataSourcePage.js +0 -15
- package/dist-cli/protocol/dataSources/dataSourceValue.d.ts +0 -66
- package/dist-cli/protocol/dataSources/dataSourceValue.js +0 -14
- package/dist-cli/protocol/dataSources/dateValue.d.ts +0 -157
- package/dist-cli/protocol/dataSources/dateValue.js +0 -61
- package/dist-cli/protocol/dataSources/errors.d.ts +0 -8
- package/dist-cli/protocol/dataSources/errors.js +0 -7
- package/dist-cli/protocol/dataSources/propertySchema.d.ts +0 -200
- package/dist-cli/protocol/dataSources/propertySchema.js +0 -174
- package/dist-cli/protocol/dataSources/recordPointer.d.ts +0 -9
- package/dist-cli/protocol/dataSources/recordPointer.js +0 -8
- package/dist-cli/protocol/dataSources/sortDirection.d.ts +0 -3
- package/dist-cli/protocol/dataSources/sortDirection.js +0 -2
- package/dist-cli/protocol/errors.d.ts +0 -12
- package/dist-cli/protocol/errors.js +0 -6
- package/dist-cli/protocol/ids.d.ts +0 -31
- package/dist-cli/protocol/ids.js +0 -26
- package/dist-cli/protocol/index.d.ts +0 -53
- package/dist-cli/protocol/index.js +0 -53
- package/dist-cli/protocol/manifest.d.ts +0 -67
- package/dist-cli/protocol/manifest.js +0 -36
- package/dist-cli/protocol/messages/connect.d.ts +0 -54
- package/dist-cli/protocol/messages/connect.js +0 -39
- package/dist-cli/protocol/messages/contrastModeChanged.d.ts +0 -7
- package/dist-cli/protocol/messages/contrastModeChanged.js +0 -7
- package/dist-cli/protocol/messages/createPage.d.ts +0 -290
- package/dist-cli/protocol/messages/createPage.js +0 -51
- package/dist-cli/protocol/messages/createPageResult.d.ts +0 -897
- package/dist-cli/protocol/messages/createPageResult.js +0 -43
- package/dist-cli/protocol/messages/currentUserChanged.d.ts +0 -18
- package/dist-cli/protocol/messages/currentUserChanged.js +0 -9
- package/dist-cli/protocol/messages/dataSourcesChanged.d.ts +0 -157
- package/dist-cli/protocol/messages/dataSourcesChanged.js +0 -13
- package/dist-cli/protocol/messages/getPage.d.ts +0 -902
- package/dist-cli/protocol/messages/getPage.js +0 -48
- package/dist-cli/protocol/messages/getUser.d.ts +0 -44
- package/dist-cli/protocol/messages/getUser.js +0 -32
- package/dist-cli/protocol/messages/hostToSandbox.d.ts +0 -4385
- package/dist-cli/protocol/messages/hostToSandbox.js +0 -48
- package/dist-cli/protocol/messages/incomingType.d.ts +0 -9
- package/dist-cli/protocol/messages/incomingType.js +0 -17
- package/dist-cli/protocol/messages/init.d.ts +0 -273
- package/dist-cli/protocol/messages/init.js +0 -57
- package/dist-cli/protocol/messages/initResult.d.ts +0 -37
- package/dist-cli/protocol/messages/initResult.js +0 -29
- package/dist-cli/protocol/messages/invalidHostMessage.d.ts +0 -14
- package/dist-cli/protocol/messages/invalidHostMessage.js +0 -13
- package/dist-cli/protocol/messages/invalidSandboxMessage.d.ts +0 -14
- package/dist-cli/protocol/messages/invalidSandboxMessage.js +0 -13
- package/dist-cli/protocol/messages/isInitHandshakeMessage.d.ts +0 -4
- package/dist-cli/protocol/messages/isInitHandshakeMessage.js +0 -11
- package/dist-cli/protocol/messages/listUsers.d.ts +0 -52
- package/dist-cli/protocol/messages/listUsers.js +0 -33
- package/dist-cli/protocol/messages/messagePayload.d.ts +0 -19
- package/dist-cli/protocol/messages/messagePayload.js +0 -1
- package/dist-cli/protocol/messages/openExternalUrl.d.ts +0 -32
- package/dist-cli/protocol/messages/openExternalUrl.js +0 -26
- package/dist-cli/protocol/messages/openPage.d.ts +0 -38
- package/dist-cli/protocol/messages/openPage.js +0 -34
- package/dist-cli/protocol/messages/pageChanged.d.ts +0 -32
- package/dist-cli/protocol/messages/pageChanged.js +0 -9
- package/dist-cli/protocol/messages/parentChanged.d.ts +0 -26
- package/dist-cli/protocol/messages/parentChanged.js +0 -9
- package/dist-cli/protocol/messages/queryDataSource.d.ts +0 -1446
- package/dist-cli/protocol/messages/queryDataSource.js +0 -252
- package/dist-cli/protocol/messages/queryDataSourceResult.d.ts +0 -686
- package/dist-cli/protocol/messages/queryDataSourceResult.js +0 -44
- package/dist-cli/protocol/messages/resize.d.ts +0 -11
- package/dist-cli/protocol/messages/resize.js +0 -10
- package/dist-cli/protocol/messages/sandboxToHost.d.ts +0 -1091
- package/dist-cli/protocol/messages/sandboxToHost.js +0 -33
- package/dist-cli/protocol/messages/themeChanged.d.ts +0 -10
- package/dist-cli/protocol/messages/themeChanged.js +0 -10
- package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.d.ts +0 -10
- package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.js +0 -9
- package/dist-cli/protocol/messages/updatePage.d.ts +0 -271
- package/dist-cli/protocol/messages/updatePage.js +0 -23
- package/dist-cli/protocol/messages/updatePageResult.d.ts +0 -895
- package/dist-cli/protocol/messages/updatePageResult.js +0 -41
- package/dist-cli/protocol/pages/page.d.ts +0 -1422
- package/dist-cli/protocol/pages/page.js +0 -318
- package/dist-cli/protocol/parent.d.ts +0 -32
- package/dist-cli/protocol/parent.js +0 -13
- package/dist-cli/protocol/protocolVersion.d.ts +0 -8
- package/dist-cli/protocol/protocolVersion.js +0 -11
- package/dist-cli/protocol/theme.d.ts +0 -3
- package/dist-cli/protocol/theme.js +0 -2
- package/dist-cli/protocol/users/user.d.ts +0 -32
- package/dist-cli/protocol/users/user.js +0 -20
- package/dist-cli/shared/block-registry.js +0 -28
- package/dist-cli/shared/data-source.js +0 -22
- package/dist-cli/shared/runtime-config.js +0 -10
- package/dist-cli/shared/sample-data-source.js +0 -12
package/docs/bindings.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Dev shell bindings
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A binding connects a data source declared by a custom block to local sample data and maps the
|
|
4
|
+
block's property keys to source properties. This guide covers source selection, property mappings,
|
|
5
|
+
and changes to bindings while running in the dev shell.
|
|
4
6
|
|
|
5
7
|
Use launcher flags to select sample files and map properties at startup. You can also edit bindings
|
|
6
8
|
in **Data**. The block initializes once every declared data source and property is connected.
|
|
@@ -12,8 +14,8 @@ Each data source selects its file in this order:
|
|
|
12
14
|
3. `data/<dataSourceKey>.json`, if it exists.
|
|
13
15
|
4. If neither file exists, the data source stays unbound.
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
A missing explicit file stops startup. A valid source with no rows still takes precedence over later
|
|
18
|
+
choices.
|
|
17
19
|
|
|
18
20
|
## Choose sample data
|
|
19
21
|
|
|
@@ -29,8 +31,8 @@ from `data/`, including `.json`.
|
|
|
29
31
|
Repeat `--bind` for additional data sources. Sources without an override keep their defaults. When
|
|
30
32
|
running `custom-blocks-dev-shell` directly, omit the forwarding `--` separator.
|
|
31
33
|
|
|
32
|
-
The launcher rejects unknown, ambiguous, or repeated targets and missing files.
|
|
33
|
-
|
|
34
|
+
The launcher rejects unknown, ambiguous, or repeated targets and missing files. Malformed files
|
|
35
|
+
appear as errors in the shell.
|
|
34
36
|
|
|
35
37
|
## Choose property mappings
|
|
36
38
|
|
|
@@ -54,7 +56,8 @@ already selects a file by its default filename. Flag order does not affect sourc
|
|
|
54
56
|
|
|
55
57
|
An unknown or ambiguous target, duplicate property target, missing source, missing source property,
|
|
56
58
|
or property type mismatch stops startup. Other properties can remain unmapped until you connect them
|
|
57
|
-
in **Data**.
|
|
59
|
+
in **Data**. If the data source file cannot load, its property mappings remain unvalidated until you
|
|
60
|
+
fix and save the file.
|
|
58
61
|
|
|
59
62
|
## Binding errors
|
|
60
63
|
|
|
@@ -90,7 +93,7 @@ their types match.
|
|
|
90
93
|
|
|
91
94
|
Open **Data** in the toolbar to select a source and map properties for each declared data source
|
|
92
95
|
slot. The modal lists your worker's `data/*.json` files. See the
|
|
93
|
-
[sample data format](
|
|
96
|
+
[sample data format](data-sources.md) to define a source.
|
|
94
97
|
|
|
95
98
|
A property maps automatically only when exactly one source property matches its key or name and has
|
|
96
99
|
the same type. If no property matches, or several properties match, the property stays unmapped.
|
|
@@ -102,13 +105,15 @@ Once every slot is bound and every property mapped, the block initializes and re
|
|
|
102
105
|
binding changes restarts the block with the updated data. If initialization fails, fix the bindings
|
|
103
106
|
and save.
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
property selections, with automatic matching for
|
|
108
|
+
The shell keeps binding selections separately for each block until you refresh the browser. Refresh
|
|
109
|
+
the shell to restore each block's CLI source and property selections, with automatic matching for
|
|
110
|
+
properties without an override.
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
See [live updates and local writes](data-sources.md#live-updates-and-local-writes) for state
|
|
113
|
+
resets and error recovery.
|
|
110
114
|
|
|
111
115
|
## Data view
|
|
112
116
|
|
|
113
117
|
Click a data source in the sidebar to inspect its schema and rows. This view is read-only. Sources
|
|
114
|
-
connected to the selected block show a green **Bound** label.
|
|
118
|
+
connected to the selected block show a green **Bound** label. The data panel shows the file path.
|
|
119
|
+
Use **Copy path** to copy it relative to the worker root.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Bridge protocol changelog
|
|
2
|
+
|
|
3
|
+
The bridge protocol defines the messages exchanged by a custom block's SDK and its host. This
|
|
4
|
+
changelog records breaking contract changes and the SDK releases that introduced them. It also
|
|
5
|
+
describes compatibility exceptions within a declared protocol version and their effects on blocks.
|
|
6
|
+
Protocol version rules are in [Bridge protocol versioning](versioning.md). The host's
|
|
7
|
+
[compatibility reference](../host/docs/compatibility.md) describes current support and response
|
|
8
|
+
conversions.
|
|
9
|
+
|
|
10
|
+
Publication dates refer to npm releases in Pacific time, not deployment in Notion. Unqualified SDK
|
|
11
|
+
versions refer to `@notionhq/custom-blocks`.
|
|
12
|
+
|
|
13
|
+
| Protocol | SDK release | Published | Breaking contract changes |
|
|
14
|
+
| ------------------------------------------------------ | ---------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| 1 | `ncblock@0.0.1` | May 11, 2026 | Initial `ready` / `init` handshake and block APIs |
|
|
16
|
+
| 2 | `ncblock@0.0.36` | June 18, 2026 | Structured errors, handshake changes, and raw data-source IDs instead of manifest keys |
|
|
17
|
+
| 3 | `0.1.0` | July 22, 2026 | Accumulated contract changes include `connect → init → initResult`, initialization identity, subscription identity, and required structured connect errors |
|
|
18
|
+
| 4 | `0.2.0` | September 17, 2026 | Required `init.contrastMode` and page/query `is_archived` and `in_trash` fields |
|
|
19
|
+
| 5 [†](#protocol-5-unavailable-containing-page-context) | `0.2.16` | September 30, 2026 | Query filters and sorts must address actual database properties. Filter and sort payloads reject extra fields |
|
|
20
|
+
| 6 [‡](#protocol-6-richer-fallback-properties) | `0.3.0` | October 26, 2026 | Typed, display-name-keyed query properties and unified page responses replace the older query representation |
|
|
21
|
+
| 7 | `0.3.3` | October 30, 2026 | Typed text fallback properties for unique ID, button, formula, location, rollup, and verification |
|
|
22
|
+
| 8 | `0.3.4` | November 3, 2026 | Local manifests move from `/manifest` to HTML metadata sent in `connect`; `manifestSource` selects the initialization manifest |
|
|
23
|
+
| 9 | Unreleased | — | Native page icons; older protocols receive external SVG URLs |
|
|
24
|
+
| 10 | `0.4.0` | November 10, 2026 | Removes `last_visited_time` from property schemas, page properties, and page metadata |
|
|
25
|
+
|
|
26
|
+
The table lists SDK release boundaries, not complete supported version ranges. Host compatibility
|
|
27
|
+
depends on `connect.bridgeProtocolVersion`, not the SDK package version.
|
|
28
|
+
|
|
29
|
+
## Protocol 10: remove last visited time
|
|
30
|
+
|
|
31
|
+
`last_visited_time` is viewer-specific recents data, not a database property type. Protocol 10
|
|
32
|
+
removes it from manifests, binding schemas, page property values, and top-level page metadata. Older
|
|
33
|
+
SDKs can still connect, but updated hosts no longer load or return viewer visit data. Older readers
|
|
34
|
+
default the absent page field to `null`. Blocks that use this field must remove that use and
|
|
35
|
+
rebuild.
|
|
36
|
+
|
|
37
|
+
## Protocol 9: native page icons
|
|
38
|
+
|
|
39
|
+
Page operations and query results can return `{ type: "icon", icon: { name, color } }`. Reads and
|
|
40
|
+
writes share a loose shape: names and colors accept strings, color is optional, and additional
|
|
41
|
+
native icon fields are retained. Hosts resolve names and default omitted colors to gray.
|
|
42
|
+
|
|
43
|
+
Protocols 3–8 receive external SVG URLs in page operation results. Protocols 6–8 receive the same
|
|
44
|
+
fallback in query results; protocols 3–5 keep their flat query format without appearance fields. The
|
|
45
|
+
released-SDK compatibility corpus exercises these conversions.
|
|
46
|
+
|
|
47
|
+
## Protocol 8: local manifest declarations
|
|
48
|
+
|
|
49
|
+
The dev shell removes the `/manifest` route and embeds the local manifest in block HTML. The SDK
|
|
50
|
+
reads that metadata and sends the declaration in `connect.manifest`; initialization no longer
|
|
51
|
+
fetches `/manifest`.
|
|
52
|
+
|
|
53
|
+
The host option `manifestSource` selects the initialization manifest: `"sandbox"` uses the
|
|
54
|
+
declaration from `connect`, and `"host"` uses the persisted manifest returned by
|
|
55
|
+
`getPersistedManifest`. Only the selected source determines initialization. Deployed blocks using
|
|
56
|
+
supported earlier protocols retain their existing response formats.
|
|
57
|
+
|
|
58
|
+
The shared host runtime minimum remains 3. The dev shell uses the Worker manifest in host mode and
|
|
59
|
+
accepts supported earlier protocols. Sandbox-mode initialization uses the protocol 8 declaration
|
|
60
|
+
from `connect`.
|
|
61
|
+
|
|
62
|
+
## Changes within a declared version
|
|
63
|
+
|
|
64
|
+
### Protocol 8: correlated request rejections
|
|
65
|
+
|
|
66
|
+
Bridge NACKs (`invalidHostMessage` and `invalidSandboxMessage`) gain an optional string `requestId`.
|
|
67
|
+
Updated SDKs complete the matching request immediately when a rejection can be correlated. Older
|
|
68
|
+
readers ignore the additional field; updated readers continue to accept NACKs without an ID.
|
|
69
|
+
Uncorrelated requests use the SDK's 60-second timeout. This additive change retains protocol 8.
|
|
70
|
+
|
|
71
|
+
### Protocol 5: unavailable containing-page context
|
|
72
|
+
|
|
73
|
+
On October 2, 2026, SDK 0.2.17 added `{ type: "unavailable" }` to containing-page context while
|
|
74
|
+
retaining protocol 5. SDK 0.2.16 rejects that shape. The host preserves later protocol 5 behavior
|
|
75
|
+
and accepts the limitation for the older SDK, as decided on October 31, 2026. Affected blocks must
|
|
76
|
+
upgrade and rebuild. The host's [compatibility reference](../host/docs/compatibility.md)
|
|
77
|
+
describes current compatibility behavior.
|
|
78
|
+
|
|
79
|
+
### Protocol 6: richer fallback properties
|
|
80
|
+
|
|
81
|
+
The protocol version changed in code on October 22, 2026. On October 26, the `pages` and
|
|
82
|
+
`dataSources` APIs adopted a shared page representation: data-source query rows and page operation
|
|
83
|
+
results use the same page shape, with typed properties keyed by display name.
|
|
84
|
+
|
|
85
|
+
Some SDKs added text fallback property objects for unique ID, button, formula, location, rollup, and
|
|
86
|
+
verification while still reporting protocol 6. Earlier protocol 6 SDKs reject those property
|
|
87
|
+
objects. Because both groups declare the same protocol version, updated hosts send `null` for these
|
|
88
|
+
properties to every protocol 6 block.
|
|
89
|
+
|
|
90
|
+
Blocks built with the later protocol 6 SDKs therefore lose those property values when their host
|
|
91
|
+
updates. UI that displays the values can become empty, and code that assumes a property object is
|
|
92
|
+
present can fail. Upgrade the SDK to protocol 7 or later and rebuild the block to receive the text
|
|
93
|
+
fallback property objects. Host adapters continue returning the current page shape; the host runtime
|
|
94
|
+
applies the protocol-specific conversion.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Bridge wire protocol
|
|
2
|
+
|
|
3
|
+
The bridge carries initialization, data requests, results, and live updates between a custom block's
|
|
4
|
+
SDK and its host. This reference defines the handshake, message identity, validation, and payload
|
|
5
|
+
semantics for host integrators and bridge maintainers. Block authors use the SDK's public APIs.
|
|
6
|
+
|
|
7
|
+
Messages are `postMessage` payloads defined by shared Valibot schemas, exposed through
|
|
8
|
+
`@notionhq/custom-blocks-host/protocol`. The embedding application enforces permissions and record
|
|
9
|
+
access. Version-specific formats and conversions are described in
|
|
10
|
+
[Versioning and compatibility](versioning.md).
|
|
11
|
+
|
|
12
|
+
## Initialization
|
|
13
|
+
|
|
14
|
+
The handshake is:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
sandbox connect → host init → sandbox initResult
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
All three messages carry the sandbox-generated `initializationId`. A sandbox document sends
|
|
21
|
+
`connect` once. The host sends one `init` for the accepted connection and ignores subsequent
|
|
22
|
+
`connect` messages, including malformed ones. Live updates wait for `initResult.success`.
|
|
23
|
+
`init.error` and `initResult.error` are terminal.
|
|
24
|
+
|
|
25
|
+
The sandbox waits for `init` without a timeout. If host state preparation times out, the host sends
|
|
26
|
+
`init.error` with `initial_state_timeout` to end that wait.
|
|
27
|
+
|
|
28
|
+
`connect` carries connection identity, version metadata, and an optional local manifest declaration.
|
|
29
|
+
The SDK reads that declaration from the `application/json` script with ID
|
|
30
|
+
`notion-custom-block-manifest`, injected into the block HTML by dev tooling. It reads metadata only
|
|
31
|
+
from supported local block server URLs. Missing metadata omits `connect.manifest`; invalid metadata
|
|
32
|
+
sends `connect.error` with `manifest_invalid`.
|
|
33
|
+
|
|
34
|
+
The embedding application selects the manifest source. In host mode, the host uses its persisted
|
|
35
|
+
manifest and ignores the sandbox declaration. In sandbox mode, the host uses `connect.manifest` from
|
|
36
|
+
a permitted local sandbox; a missing declaration produces `manifest_unavailable`. The selected
|
|
37
|
+
manifest is authoritative and is returned in `init` with context and data-source bindings. Errors
|
|
38
|
+
from the selected manifest source pass through unchanged. Host mode can initialize after a sandbox
|
|
39
|
+
`manifest_invalid` error using its own manifest; other connect errors remain fatal. The connect
|
|
40
|
+
parser discards unknown properties.
|
|
41
|
+
|
|
42
|
+
`initResult.success` may include `initialHeight`, the height of the sandbox's rendered content in
|
|
43
|
+
CSS pixels. The host's [lifecycle guide](../host/docs/lifecycle.md) describes iframe sizing,
|
|
44
|
+
reveal, and retry behavior.
|
|
45
|
+
|
|
46
|
+
`connect.bridgeProtocolVersion` declares the sandbox's wire contract. `sdkVersion` is analytics
|
|
47
|
+
metadata. See [versioning and compatibility](versioning.md) for supported formats and
|
|
48
|
+
[Validation and errors](#validation-and-errors) for malformed handshake behavior.
|
|
49
|
+
|
|
50
|
+
## Manifests
|
|
51
|
+
|
|
52
|
+
A manifest declares a block's data sources and display metadata. `manifestSchema` defines its fields
|
|
53
|
+
and defaults omitted `dataSources` and each data source's omitted `properties` to `{}`.
|
|
54
|
+
|
|
55
|
+
`isLocalBlockServerUrl(url)` accepts HTTP(S) URLs on `localhost`, `*.localhost`, or `127.0.0.1`
|
|
56
|
+
without credentials. It checks the address only. The host also requires a sandbox-mode block to use
|
|
57
|
+
a different origin from its embedding page.
|
|
58
|
+
|
|
59
|
+
## Message identity
|
|
60
|
+
|
|
61
|
+
- One-shot request/result pairs use `requestId`.
|
|
62
|
+
- `queryDataSource` is a long-lived subscription; requests and every update use its stable
|
|
63
|
+
`subscriptionId`.
|
|
64
|
+
- The initialization lifecycle uses `initializationId`, not `requestId` or `subscriptionId`.
|
|
65
|
+
- One-way messages, such as `resize`, have no correlation ID.
|
|
66
|
+
- Bridge NACKs include the rejected message's `requestId` when it is a string. The ID identifies the
|
|
67
|
+
original request, including when the rejected message is its response.
|
|
68
|
+
|
|
69
|
+
Hosts key query state by `subscriptionId`, replace state when a request reuses one, and suppress
|
|
70
|
+
stale asynchronous results.
|
|
71
|
+
|
|
72
|
+
The sandbox can send `unsubscribeDataSourceQuery` with the same `subscriptionId` when it no longer
|
|
73
|
+
needs the subscription. An unknown or repeated unsubscribe is a no-op. Hosts stop future refreshes
|
|
74
|
+
and suppress results from work already in progress.
|
|
75
|
+
|
|
76
|
+
## Validation and errors
|
|
77
|
+
|
|
78
|
+
Each direction has a validation schema:
|
|
79
|
+
|
|
80
|
+
- Sandbox to host: `sandboxToHostMessageSchema`
|
|
81
|
+
- Host to sandbox: `hostToSandboxMessageSchema`
|
|
82
|
+
|
|
83
|
+
On parse failure, the host replies with `invalidSandboxMessage` and the sandbox replies with
|
|
84
|
+
`invalidHostMessage`, except for the handshake cases below. These replies are negative
|
|
85
|
+
acknowledgments (NACKs). Receivers do not NACK another NACK.
|
|
86
|
+
|
|
87
|
+
A sandbox request with a `requestId` expects a terminal result or correlated rejection. On parse
|
|
88
|
+
failure, read `requestId` separately from the invalid payload. The host includes a readable string
|
|
89
|
+
ID in `invalidSandboxMessage`, even for an unknown request type. The SDK completes the matching
|
|
90
|
+
request with `invalid_sandbox_message`. When the SDK rejects a host response, it completes the
|
|
91
|
+
matching request locally with `invalid_host_message` and includes the ID in `invalidHostMessage`.
|
|
92
|
+
Both errors have `isRetryable: false`.
|
|
93
|
+
|
|
94
|
+
One-shot SDK requests time out after 60 seconds. Missing, unreadable, or unknown IDs do not fail
|
|
95
|
+
unrelated requests. NACK IDs are optional: older readers ignore them, and newer readers accept
|
|
96
|
+
legacy NACKs without IDs. Those requests retain the timeout fallback.
|
|
97
|
+
|
|
98
|
+
Request completion clears its timer, removes the pending entry, and ignores duplicate or late
|
|
99
|
+
results. Disposing the SDK completes pending calls locally with `request_disposed` and clears their
|
|
100
|
+
timers. The SDK does not retry or cancel host work. A timed-out write may still complete; check its
|
|
101
|
+
resulting state before repeating it. Data source subscriptions use a separate lifecycle.
|
|
102
|
+
|
|
103
|
+
Malformed sandbox messages do not change the host's initialization state or timeout, except as
|
|
104
|
+
follows:
|
|
105
|
+
|
|
106
|
+
- The host expects `connect` and receives a malformed `connect` with a readable `initializationId`.
|
|
107
|
+
The host sends `init.error` instead of a NACK, then fails initialization. An invalid or
|
|
108
|
+
unsupported numeric protocol version takes precedence over `invalid_connect_payload`.
|
|
109
|
+
- The host expects `initResult` and receives a malformed `initResult` with the active
|
|
110
|
+
`initializationId`. The host sends a NACK and fails initialization with
|
|
111
|
+
`invalid_init_result_payload`. This error code describes a local host failure. The host does not
|
|
112
|
+
send it in `initResult.error`.
|
|
113
|
+
|
|
114
|
+
A malformed `initResult` with a missing or stale ID does not end initialization or reset its
|
|
115
|
+
timeout. Malformed messages do not restart initialization after it succeeds or fails.
|
|
116
|
+
|
|
117
|
+
The sandbox handles a malformed `init` differently if it can verify the `initializationId`. In that
|
|
118
|
+
case, it sends `initResult.error` with `invalid_init_payload` instead of a NACK. Otherwise, it sends
|
|
119
|
+
`invalidHostMessage`.
|
|
120
|
+
|
|
121
|
+
`CustomBlockErrorInfo` carries `code`, `message`, and `isRetryable`. Error schemas accept any string
|
|
122
|
+
for `code`, including unknown codes. TypeScript aliases list known codes for autocomplete.
|
|
123
|
+
|
|
124
|
+
## Data sources
|
|
125
|
+
|
|
126
|
+
### Bindings and IDs
|
|
127
|
+
|
|
128
|
+
Hosts send `BridgeDataSourceBindings` as `dataSources: { bindings }`, keyed by the semantic data
|
|
129
|
+
source key declared in the manifest. `collectionSchema` contains only actual database properties.
|
|
130
|
+
|
|
131
|
+
Sandbox-to-host object references are raw IDs. The SDK resolves semantic data-source and property
|
|
132
|
+
keys before sending query or page-operation requests. Get and update requests can carry an optional
|
|
133
|
+
resolved `dataSourceId`.
|
|
134
|
+
|
|
135
|
+
A binding with `inaccessible: true` marks a bound data source that the viewer can't read. The host
|
|
136
|
+
omits its pointer, schema, and property mappings. The SDK and host still initialize the block. The
|
|
137
|
+
SDK fails queries and page creation that use the data source with `data_source_inaccessible`,
|
|
138
|
+
without sending a message.
|
|
139
|
+
|
|
140
|
+
### Query requests
|
|
141
|
+
|
|
142
|
+
`queryDataSource` may include a resolved `filter` and an ordered `sorts` list. Each sort contains a
|
|
143
|
+
raw `propertyId` and an `ascending` or `descending` direction. Hosts apply sorts in array order. The
|
|
144
|
+
SDK and host validate that the list contains at most ten unique properties. The host rejects
|
|
145
|
+
property types without a supported sort value.
|
|
146
|
+
|
|
147
|
+
Every filter and sort property ID must exist in `collectionSchema.propertiesById`. Queries with
|
|
148
|
+
filters or sorts return `data_source_schema_unavailable` when the schema is unavailable. Filter
|
|
149
|
+
branches, operators, person references, and sort objects reject extra fields.
|
|
150
|
+
|
|
151
|
+
#### Creator and status filters
|
|
152
|
+
|
|
153
|
+
Creator filters require `propertyId` to identify an actual database property of type `created_by`.
|
|
154
|
+
The `created_by` filter branch selects the property type, while `propertyId` addresses the column.
|
|
155
|
+
|
|
156
|
+
The `created_by` filter supports human user targets with `contains` and `does_not_contain`, plus
|
|
157
|
+
`is_empty` and `is_not_empty`. Hosts use row creator metadata, including non-human and missing
|
|
158
|
+
creators in exclusion results.
|
|
159
|
+
|
|
160
|
+
Status filters support option operators and stored group names. Group operators accept one name or
|
|
161
|
+
an array of 1–5 names. Hosts must validate each name against the bound Status property.
|
|
162
|
+
|
|
163
|
+
#### Relation filters
|
|
164
|
+
|
|
165
|
+
Relation filters require an actual `relation` property in the bound schema. `contains` and
|
|
166
|
+
`does_not_contain` accept one page ID. `is_empty` and `is_not_empty` accept only `true` and require
|
|
167
|
+
no page ID. Each relation filter accepts exactly one operator. Adapters must evaluate empty checks
|
|
168
|
+
against relation values, including XLDB row IDs where supported.
|
|
169
|
+
|
|
170
|
+
#### Date filters
|
|
171
|
+
|
|
172
|
+
Date comparisons accept ISO values and relative values such as `today`. The query schema defines the
|
|
173
|
+
accepted values and range operators. Range operators require an empty object.
|
|
174
|
+
|
|
175
|
+
Date comparisons accept `target` inside `date`, beside the operator. The target is `start_date` by
|
|
176
|
+
default. For ranges, `end_date` compares the range end. For individual dates, it compares the date.
|
|
177
|
+
Empty checks accept either target, but they test the whole property.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
filter: {
|
|
181
|
+
propertyId: "schedule-id",
|
|
182
|
+
date: { target: "end_date", on_or_after: "2026-10-08" },
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Capabilities
|
|
187
|
+
|
|
188
|
+
`manifest.capabilities` lists `{ capability, resource }` declarations. `capability` is an open
|
|
189
|
+
string and `resource` is an open string or a non-empty array of them, so a newer vocabulary never
|
|
190
|
+
makes an older receiver reject a manifest. An array declares the capability on each element.
|
|
191
|
+
Receivers never split a resource string on commas. An omitted `capabilities` marks a block that
|
|
192
|
+
predates approval.
|
|
193
|
+
|
|
194
|
+
Page capability resources can name one manifest data source as `data_source:<key>`. The key is the
|
|
195
|
+
semantic key from `manifest.dataSources`; hosts resolve it to the bound data source when they record
|
|
196
|
+
and check grants. Bare `data_source` covers every declared key.
|
|
197
|
+
|
|
198
|
+
The `capability_not_granted` error code is reserved for a request that the viewer's grants do not
|
|
199
|
+
cover, with `isRetryable: false`. No adapter sends it yet, and no receiver restricts requests by
|
|
200
|
+
capability. The SDK's capabilities guide documents the vocabulary.
|
|
201
|
+
|
|
202
|
+
## Page context
|
|
203
|
+
|
|
204
|
+
Containing-page context uses `CustomBlockPage`. The `init.page` and `pageChanged.page` fields
|
|
205
|
+
contain `{ type: "page", id, parent }` for an accessible page, or `{ type: "unavailable" }` when the
|
|
206
|
+
containing page itself is inaccessible. The unavailable shape never carries a page ID. This is
|
|
207
|
+
distinct from an accessible page with an inaccessible parent
|
|
208
|
+
(`page.parent: { type: "unavailable" }`).
|
|
209
|
+
|
|
210
|
+
## Page writes
|
|
211
|
+
|
|
212
|
+
The `createPage` and `updatePage` messages use raw property IDs from Notion as map keys. Each value
|
|
213
|
+
must carry the same raw property ID in its `id` field.
|
|
214
|
+
|
|
215
|
+
## Page responses
|
|
216
|
+
|
|
217
|
+
Host handlers return unified `BridgePage` for queries and page operations. Properties use display
|
|
218
|
+
names as keys and typed values that include their raw property IDs. Only actual schema properties
|
|
219
|
+
are returned. Query results contain `items` and `hasMore`. `bridgePageSchema` defines the page
|
|
220
|
+
fields, including archive state and creation, edit, and visit metadata.
|
|
221
|
+
|
|
222
|
+
Page reads return string values for `unique_id`, `formula`, `rollup`, `button`, `verification`, and
|
|
223
|
+
`location`, preserving each property's type. These properties are read-only. Values use stored text,
|
|
224
|
+
or `""` when absent. Hosts do not evaluate formulas or rollups.
|
|
225
|
+
|
|
226
|
+
The host converts responses to the sandbox's declared protocol. See
|
|
227
|
+
[versioning and compatibility](versioning.md) for protocol version rules. The host's
|
|
228
|
+
[compatibility reference](../host/docs/compatibility.md) describes older response formats.
|
|
229
|
+
|
|
230
|
+
### Native page icon compatibility
|
|
231
|
+
|
|
232
|
+
Protocol 9 and later use native icon objects. Protocols 3–8 receive external SVG URLs in page
|
|
233
|
+
operation results. Unified query results in protocols 6–8 also use external SVG URLs; flat query
|
|
234
|
+
results in protocols 3–5 omit icon fields. Native colors accept any string in responses and write
|
|
235
|
+
inputs, so newer host colors do not require an SDK update.
|
|
236
|
+
|
|
237
|
+
`createPage` accepts native icons, emoji, custom emoji, and URL-backed icons and covers. The
|
|
238
|
+
application adapter checks submitted image URLs against the block's network permissions before
|
|
239
|
+
creating a page.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Bridge protocol versioning
|
|
2
|
+
|
|
3
|
+
The SDK inside a block and the host in its embedding application release independently. A bridge
|
|
4
|
+
protocol version identifies the wire contract they use, independently of their package versions.
|
|
5
|
+
This reference defines the version identifiers, protocol format names, and rules for contract
|
|
6
|
+
changes. Release boundaries and exceptions are recorded in the [changelog](changelog.md). The host's
|
|
7
|
+
[compatibility reference](../host/docs/compatibility.md) describes runtime support and response
|
|
8
|
+
conversions.
|
|
9
|
+
|
|
10
|
+
## Version identifiers
|
|
11
|
+
|
|
12
|
+
- **Bridge protocol:** `connect.bridgeProtocolVersion` declares the sandbox's wire contract.
|
|
13
|
+
- **SDK package:** identifies the SDK's public API and implementation. It can change without a wire
|
|
14
|
+
change.
|
|
15
|
+
- **Host package:** identifies the runtime implementation. Publishing it does not deploy it to
|
|
16
|
+
Notion.
|
|
17
|
+
|
|
18
|
+
`connect.bridgeProtocolVersion` selects the wire contract. `sdkVersion` is analytics metadata.
|
|
19
|
+
`LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest contract defined by the package.
|
|
20
|
+
`NATIVE_ICON_PROTOCOL_VERSION` is 9, the first protocol with native icon responses and writes.
|
|
21
|
+
|
|
22
|
+
## Protocol export names
|
|
23
|
+
|
|
24
|
+
The `@notionhq/custom-blocks-host/protocol` entrypoint exports wire definitions. Page formats used
|
|
25
|
+
by protocols 3–5 are named `BridgePageForProtocol3To5` and `NotionDataSourcePageForProtocol3To5`,
|
|
26
|
+
with matching `bridgePageForProtocol3To5Schema` and `notionDataSourcePageForProtocol3To5Schema`
|
|
27
|
+
validators. Message types and schemas containing `WithProtocol3To5Compatibility` accept both current
|
|
28
|
+
page formats and protocol 3–5 page formats. `UNIFIED_PAGE_PROTOCOL_VERSION` is 6, the minimum
|
|
29
|
+
protocol version that uses unified pages.
|
|
30
|
+
|
|
31
|
+
## Version changes
|
|
32
|
+
|
|
33
|
+
A breaking wire change increases the bridge protocol version. This includes changed meanings,
|
|
34
|
+
required fields, and new response variants an older receiver rejects. Optional fields and new
|
|
35
|
+
messages need no bump only when older receivers can safely ignore or NACK them. Parsing success
|
|
36
|
+
alone does not prove compatible SDK behavior.
|
|
37
|
+
|
|
38
|
+
An SDK that requires a newer protocol needs a host that supports that contract. Updating the SDK
|
|
39
|
+
package does not update the host in the embedding application.
|
package/docs/data-sources.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
# Dev
|
|
1
|
+
# Dev shell data sources
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describes.
|
|
8
|
-
- `manual` — sources a user creates themselves in the shell.
|
|
9
|
-
- `built-in` — sources we provide.
|
|
3
|
+
Local sample data lets custom blocks query rows without a production Notion database. This reference
|
|
4
|
+
describes files in your project's `data/*.json`, including schemas, row values, validation, and
|
|
5
|
+
files generated from worker schemas. Use [Dev shell bindings](bindings.md) to connect a source to a
|
|
6
|
+
block.
|
|
10
7
|
|
|
11
8
|
## File format
|
|
12
9
|
|
|
@@ -40,7 +37,7 @@ For example, `data/tasks.json`:
|
|
|
40
37
|
}
|
|
41
38
|
```
|
|
42
39
|
|
|
43
|
-
- `type` — the source's kind. Hand-authored files declare `"worker"` (the default)
|
|
40
|
+
- `type` — the source's kind. Hand-authored files declare `"worker"` (the default). The pre-built
|
|
44
41
|
sources the shell adds carry `"built-in"`.
|
|
45
42
|
- `name` — the label shown in the shell sidebar. If omitted, it defaults to the filename without
|
|
46
43
|
`.json`.
|
|
@@ -54,21 +51,21 @@ For example, `data/tasks.json`:
|
|
|
54
51
|
|
|
55
52
|
Value shapes by property type:
|
|
56
53
|
|
|
57
|
-
| Type | Value
|
|
58
|
-
| ------------------------------------------------------------------------ |
|
|
59
|
-
| `title`, `rich_text`, `select`, `status`, `url`, `email`, `phone_number` | string
|
|
60
|
-
| `multi_select` | array of strings
|
|
61
|
-
| `number` | number
|
|
62
|
-
| `checkbox` | boolean
|
|
63
|
-
| `date` | `{ "type": "date", "start_date": "YYYY-MM-DD" }
|
|
64
|
-
| `people` | array of `{ "id": "...", "table": "notion_user" }` pointers
|
|
65
|
-
| `relation` | array of `{ "id": "...", "table": "block" }` pointers
|
|
66
|
-
| `files` | string (the host serializes file properties as text today)
|
|
54
|
+
| Type | Value |
|
|
55
|
+
| ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `title`, `rich_text`, `select`, `status`, `url`, `email`, `phone_number` | string |
|
|
57
|
+
| `multi_select` | array of strings |
|
|
58
|
+
| `number` | number |
|
|
59
|
+
| `checkbox` | boolean |
|
|
60
|
+
| `date` | `{ "type": "date", "start_date": "YYYY-MM-DD" }`. Ranges and datetimes use `"daterange"`, `"datetime"`, or `"datetimerange"` with `end_date`, `start_time`, and `end_time`. |
|
|
61
|
+
| `people` | array of `{ "id": "...", "table": "notion_user" }` pointers |
|
|
62
|
+
| `relation` | array of `{ "id": "...", "table": "block" }` pointers |
|
|
63
|
+
| `files` | string (the host serializes file properties as text today) |
|
|
67
64
|
|
|
68
65
|
## Validation
|
|
69
66
|
|
|
70
|
-
Files are validated at
|
|
71
|
-
the file and problem
|
|
67
|
+
Files are validated independently at startup and after edits. A malformed file remains visible in
|
|
68
|
+
the shell with an error naming the file and problem, e.g.
|
|
72
69
|
`data/tasks.json: rows.0.id: Invalid key: Expected "id" but received undefined`. The filename
|
|
73
70
|
without `.json` is the source identity used by bindings and source pickers. Renaming a file changes
|
|
74
71
|
its identity.
|
|
@@ -88,19 +85,17 @@ user’s locale.
|
|
|
88
85
|
Status group filters use each Status property's `options` and `groups`. Group `option_ids` must
|
|
89
86
|
reference option IDs from the same property.
|
|
90
87
|
|
|
91
|
-
##
|
|
88
|
+
## Generated files
|
|
89
|
+
|
|
90
|
+
At startup, the shell creates `data/worker_<key>.json` for each declared data source without an
|
|
91
|
+
existing file. Each file contains the declared schema and no rows. Declarations include
|
|
92
|
+
`worker.database(...)` entries and inline `worker.customBlock({ dataSources })` schemas.
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
data source
|
|
95
|
-
`worker.customBlock({ dataSources })` schemas — that doesn't already have one:
|
|
96
|
-
`data/worker_<key>.json`, the declared schema with empty `rows`, mirroring a managed database before
|
|
97
|
-
any sync.
|
|
94
|
+
The `worker_` prefix keeps generated files separate from files you create. The sidebar uses the
|
|
95
|
+
declared data source name.
|
|
98
96
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
name.
|
|
102
|
-
- Files are only ever written when absent: fill in `rows` freely and your edits survive restarts.
|
|
103
|
-
Delete a generated file to regenerate it from the schema.
|
|
97
|
+
The shell preserves existing files, so your row edits survive restarts. To regenerate a file from
|
|
98
|
+
the declared schema, delete the file and restart the shell.
|
|
104
99
|
|
|
105
100
|
The shell shows exactly the sources in `data/`, nothing else.
|
|
106
101
|
|
|
@@ -113,10 +108,28 @@ ntn workers customblocks sample <url-or-data-source-id> \
|
|
|
113
108
|
--out data/worker_tasks.json --row-only
|
|
114
109
|
```
|
|
115
110
|
|
|
116
|
-
Run the dev shell once to create the generated file, then
|
|
117
|
-
|
|
111
|
+
Run the dev shell once to create the generated file, then sample your data. `--row-only` preserves
|
|
112
|
+
the schema and appends rows with new IDs. Add `--overwrite` to replace existing rows.
|
|
118
113
|
|
|
119
114
|
Sampled property keys must match the generated schema. If they differ, sample into a separate file
|
|
120
|
-
and select it with [`--bind`](
|
|
115
|
+
and select it with [`--bind`](bindings.md#choose-sample-data).
|
|
116
|
+
|
|
117
|
+
The shell loads sampled data automatically.
|
|
118
|
+
|
|
119
|
+
## Live updates and local writes
|
|
120
|
+
|
|
121
|
+
The shell watches sample data source files. When a selected file changes, the active block restarts,
|
|
122
|
+
clearing its UI state and in-memory data changes. Changes to unrelated files do not restart the
|
|
123
|
+
block. Adding or removing a file can change automatic selection and restart the block.
|
|
124
|
+
|
|
125
|
+
Your selected block and binding selections stay the same. Saving unchanged data does not restart the
|
|
126
|
+
block.
|
|
127
|
+
|
|
128
|
+
A file with invalid JSON or an invalid schema shows **Error** in the sidebar. Select the file for
|
|
129
|
+
details. Blocks bound to the file show the error until you fix and save the file. Once the file
|
|
130
|
+
loads successfully, the active block restarts. Other sample data sources remain available.
|
|
131
|
+
|
|
132
|
+
SDK writes stay in memory. They never change JSON files or production data.
|
|
121
133
|
|
|
122
|
-
|
|
134
|
+
If the file watcher fails, the shell keeps the last loaded data and shows that updates have stopped.
|
|
135
|
+
Restart the dev shell to resume file updates.
|