@notionhq/custom-blocks-dev-shell 0.1.114 → 0.1.116

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +108 -22
  3. package/THIRD_PARTY_LICENSES.md +133 -0
  4. package/bin/cli.js +3 -1
  5. package/dist/assets/index-DSaseWP_.js +11 -0
  6. package/dist/assets/index-Do-x8yIt.css +2 -0
  7. package/dist/index.html +2 -2
  8. package/dist-cli/cli/published-cli.js +8476 -0
  9. package/docs/bindings.md +84 -27
  10. package/docs/bridge/changelog.md +67 -0
  11. package/docs/bridge/protocol.md +204 -0
  12. package/docs/bridge/versioning.md +38 -0
  13. package/docs/data-sources.md +49 -36
  14. package/docs/host/README.md +177 -0
  15. package/docs/host/docs/compatibility.md +68 -0
  16. package/docs/host/docs/handlers.md +199 -0
  17. package/docs/host/docs/lifecycle.md +117 -0
  18. package/package.json +9 -28
  19. package/dist/assets/index-E1j3FxAu.css +0 -2
  20. package/dist/assets/index-F02ZboyS.js +0 -11
  21. package/dist-cli/block-csp.js +0 -84
  22. package/dist-cli/build-block-registry.js +0 -28
  23. package/dist-cli/convert-values.js +0 -222
  24. package/dist-cli/convert.js +0 -210
  25. package/dist-cli/data-sources.js +0 -167
  26. package/dist-cli/date-value.js +0 -46
  27. package/dist-cli/dev-shell-launcher.js +0 -226
  28. package/dist-cli/dev-shell-run.js +0 -72
  29. package/dist-cli/errors.js +0 -8
  30. package/dist-cli/materialize.js +0 -105
  31. package/dist-cli/ports.js +0 -20
  32. package/dist-cli/prebuilt.js +0 -23
  33. package/dist-cli/published-cli.js +0 -60
  34. package/dist-cli/resolve-bindings.js +0 -39
  35. package/dist-cli/runtime-error-client.js +0 -52
  36. package/dist-cli/serve-ui.js +0 -110
  37. package/dist-cli/shared-server.js +0 -70
  38. package/dist-cli/source-bindings.js +0 -17
  39. package/dist-cli/utils.js +0 -52
  40. package/dist-cli/vite-block-server.js +0 -125
  41. package/dist-cli/vite-middleware.js +0 -111
  42. package/dist-cli/worker-manifest.js +0 -141
package/docs/bindings.md CHANGED
@@ -1,16 +1,21 @@
1
1
  # Dev shell bindings
2
2
 
3
- The dev shell previews your worker's custom blocks with local data from `data/*.json`. Each data
4
- source selects its file in this order:
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.
6
+
7
+ Use launcher flags to select sample files and map properties at startup. You can also edit bindings
8
+ in **Data**. The block initializes once every declared data source and property is connected.
9
+
10
+ Each data source selects its file in this order:
5
11
 
6
12
  1. The explicit `--bind` selection.
7
13
  2. `data/worker_<dataSourceKey>.json`, if it exists.
8
14
  3. `data/<dataSourceKey>.json`, if it exists.
9
- 4. Otherwise, it stays unbound. The shell starts, but the block cannot initialize until you connect
10
- the source in **Data**.
15
+ 4. If neither file exists, the data source stays unbound.
11
16
 
12
- An invalid explicit selection stops startup instead of falling back to another file. An empty file
13
- still takes precedence over later choices.
17
+ A missing explicit file stops startup. A valid source with no rows still takes precedence over later
18
+ choices.
14
19
 
15
20
  ## Choose sample data
16
21
 
@@ -24,39 +29,91 @@ This connects the `tasks` data source on `task-board` to `data/sample_tasks.json
24
29
  from `data/`, including `.json`.
25
30
 
26
31
  Repeat `--bind` for additional data sources. Sources without an override keep their defaults. When
27
- running `custom-blocks-dev-shell` directly, omit the `--` separator.
32
+ running `custom-blocks-dev-shell` directly, omit the forwarding `--` separator.
33
+
34
+ The launcher rejects unknown, ambiguous, or repeated targets and missing files. Malformed files
35
+ appear as errors in the shell.
36
+
37
+ ## Choose property mappings
38
+
39
+ Use `--bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>` when a block
40
+ property must map to a specific property in your sample data:
41
+
42
+ ```bash
43
+ ntn workers customblocks dev -- \
44
+ --bind task-board.tasks=sample_tasks.json \
45
+ --bind-property task-board.tasks.title=task_name \
46
+ --bind-property task-board.tasks.status=workflow_status
47
+ ```
48
+
49
+ This selects `data/sample_tasks.json` for the `tasks` slot on `task-board`. The block's `title`
50
+ property maps to `schema.task_name`, and its `status` property maps to `schema.workflow_status`. The
51
+ source property key is a key in the sample file's `schema`, not its display name.
52
+
53
+ Repeat `--bind-property` for each property you want to set. Explicit mappings override automatic
54
+ matches. Properties without an override keep automatic matching. You can omit `--bind` when the slot
55
+ already selects a file by its default filename. Flag order does not affect source selection.
56
+
57
+ An unknown or ambiguous target, duplicate property target, missing source, missing source property,
58
+ or property type mismatch stops startup. Other properties can remain unmapped until you connect them
59
+ in **Data**. If the data source file cannot load, its property mappings remain unvalidated until you
60
+ fix and save the file.
61
+
62
+ ## Binding errors
63
+
64
+ The launcher stops on the first binding failure. Binding syntax and mapping errors end with
65
+ `(error code: <code>)`, for example:
66
+
67
+ ```text
68
+ Cannot bind task-board.tasks.title: source property "score" has type "number", expected "title". (error code: property_type_mismatch)
69
+ ```
70
+
71
+ The codes identify the cause:
28
72
 
29
- An unknown target, duplicate target, or missing file stops startup. Invalid JSON or an invalid
30
- source file also stops startup.
73
+ | Code | Cause |
74
+ | ----------------------------------- | ----------------------------------------------------------------------------- |
75
+ | `invalid_binding_syntax` | A `--bind` value does not follow the required syntax. |
76
+ | `invalid_property_binding_syntax` | A `--bind-property` value does not follow the required syntax. |
77
+ | `unknown_binding_target` | No block and data source slot match the `--bind` target. |
78
+ | `ambiguous_binding_target` | More than one block and slot match the `--bind` target. |
79
+ | `duplicate_binding_target` | A full `--bind` target appears more than once. |
80
+ | `sample_file_not_found` | The file selected by `--bind` does not exist in `data/`. |
81
+ | `unknown_property_binding_target` | No declared property matches the `--bind-property` target. |
82
+ | `ambiguous_property_binding_target` | More than one declared property matches the target. |
83
+ | `duplicate_property_binding_target` | A full `--bind-property` target appears more than once. |
84
+ | `binding_source_missing` | A property override has neither an explicit source nor a default source file. |
85
+ | `source_property_not_found` | The selected source's `schema` has no entry for the requested property key. |
86
+ | `property_type_mismatch` | The source property type differs from the block property's declared type. |
31
87
 
32
- The browser maps compatible properties automatically. Incomplete mappings do not stop the shell.
33
- Open **Data** to finish connecting the block. Empty rows are valid.
88
+ Repeating a full target fails even when both values are identical. The same property key in
89
+ different slots or blocks is allowed. Multiple declared properties can share a source property when
90
+ their types match.
34
91
 
35
- ## Connecting data
92
+ ## Edit bindings in Data
36
93
 
37
- **Data** in the toolbar opens the bindings modal: one section per slot from the block's
38
- `worker.customBlock({ dataSources })` declaration, each with a source picker and a per-property
39
- mapping. The sources on offer are the ones in your worker's `data/*.json` (format:
40
- [`data-sources.md`](./data-sources.md)). The modal shows each slot and its property mappings.
94
+ Open **Data** in the toolbar to select a source and map properties for each declared data source
95
+ slot. The modal lists your worker's `data/*.json` files. See the
96
+ [sample data format](data-sources.md) to define a source.
41
97
 
42
- Properties map automatically when there is a unique source property with a matching key or name and
43
- the same type. Use the property pickers to adjust mappings. Selecting a different source resets its
44
- property mappings.
98
+ A property maps automatically only when exactly one source property matches its key or name and has
99
+ the same type. If no property matches, or several properties match, the property stays unmapped.
100
+ Open **Data** to select a mapping. Selecting a different source resets its property mappings.
45
101
 
46
- ## Initialization & binding edits
102
+ ## Initialization and refresh
47
103
 
48
104
  Once every slot is bound and every property mapped, the block initializes and renders. Saving
49
105
  binding changes restarts the block with the updated data. If initialization fails, fix the bindings
50
106
  and save.
51
107
 
52
- Bindings last for the page load, per block: refresh the shell and every block returns to its CLI
53
- selection or filename default.
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.
54
111
 
55
- The shell reads `data/*.json` once at spin-up. To pick up file edits, restart the dev-shell command;
56
- a browser refresh is not enough.
112
+ See [live updates and local writes](data-sources.md#live-updates-and-local-writes) for state
113
+ resets and error recovery.
57
114
 
58
115
  ## Data view
59
116
 
60
- Click a data source in the sidebar to inspect its schema and rows, read-only. The shell shows
61
- exactly the sources in `data/`, nothing else. Sources bound to the selected block carry a green
62
- **Bound** pill; the pill follows the block selection, so switching blocks updates it.
117
+ Click a data source in the sidebar to inspect its schema and rows. This view is read-only. Sources
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,67 @@
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.4.0` | November 2, 2026 | Local manifests move from `/manifest` to HTML metadata sent in `connect`; `manifestSource` selects the initialization manifest |
23
+
24
+ The table lists SDK release boundaries, not complete supported version ranges. Host compatibility
25
+ depends on `connect.bridgeProtocolVersion`, not the SDK package version.
26
+
27
+ ## Protocol 8: local manifest declarations
28
+
29
+ The dev shell removes the `/manifest` route and embeds the local manifest in block HTML. The SDK
30
+ reads that metadata and sends the declaration in `connect.manifest`; initialization no longer
31
+ fetches `/manifest`.
32
+
33
+ The host option `manifestSource` selects the initialization manifest: `"sandbox"` uses the
34
+ declaration from `connect`, and `"host"` uses the persisted manifest returned by
35
+ `getPersistedManifest`. Only the selected source determines initialization. Deployed blocks using
36
+ supported earlier protocols retain their existing response formats.
37
+
38
+ The shared host runtime minimum remains 3. The dev shell uses the Worker manifest in host mode and
39
+ accepts supported earlier protocols. Sandbox-mode initialization uses the protocol 8 declaration
40
+ from `connect`.
41
+
42
+ ## Changes within a declared version
43
+
44
+ ### Protocol 5: unavailable containing-page context
45
+
46
+ On October 2, 2026, SDK 0.2.17 added `{ type: "unavailable" }` to containing-page context while
47
+ retaining protocol 5. SDK 0.2.16 rejects that shape. The host preserves later protocol 5 behavior
48
+ and accepts the limitation for the older SDK, as decided on October 31, 2026. Affected blocks must
49
+ upgrade and rebuild. The host's [compatibility reference](../host/docs/compatibility.md)
50
+ describes current compatibility behavior.
51
+
52
+ ### Protocol 6: richer fallback properties
53
+
54
+ The protocol version changed in code on October 22, 2026. On October 26, the `pages` and
55
+ `dataSources` APIs adopted a shared page representation: data-source query rows and page operation
56
+ results use the same page shape, with typed properties keyed by display name.
57
+
58
+ Some SDKs added text fallback property objects for unique ID, button, formula, location, rollup, and
59
+ verification while still reporting protocol 6. Earlier protocol 6 SDKs reject those property
60
+ objects. Because both groups declare the same protocol version, updated hosts send `null` for these
61
+ properties to every protocol 6 block.
62
+
63
+ Blocks built with the later protocol 6 SDKs therefore lose those property values when their host
64
+ updates. UI that displays the values can become empty, and code that assumes a property object is
65
+ present can fail. Upgrade the SDK to protocol 7 or later and rebuild the block to receive the text
66
+ fallback property objects. Host adapters continue returning the current page shape; the host runtime
67
+ applies the protocol-specific conversion.
@@ -0,0 +1,204 @@
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` and bridge NACKs, have no correlation ID.
66
+
67
+ Hosts key query state by `subscriptionId`, replace state when a request reuses one, and suppress
68
+ stale asynchronous results.
69
+
70
+ The sandbox can send `unsubscribeDataSourceQuery` with the same `subscriptionId` when it no longer
71
+ needs the subscription. An unknown or repeated unsubscribe is a no-op. Hosts stop future refreshes
72
+ and suppress results from work already in progress.
73
+
74
+ ## Validation and errors
75
+
76
+ Each direction has a validation schema:
77
+
78
+ - Sandbox to host: `sandboxToHostMessageSchema`
79
+ - Host to sandbox: `hostToSandboxMessageSchema`
80
+
81
+ On parse failure, the host replies with `invalidSandboxMessage` and the sandbox replies with
82
+ `invalidHostMessage`, except for the handshake cases below. These replies are negative
83
+ acknowledgments (NACKs). Receivers do not NACK another NACK.
84
+
85
+ Malformed sandbox messages do not change the host's initialization state or timeout, except as
86
+ follows:
87
+
88
+ - The host expects `connect` and receives a malformed `connect` with a readable `initializationId`.
89
+ The host sends `init.error` instead of a NACK, then fails initialization. An invalid or
90
+ unsupported numeric protocol version takes precedence over `invalid_connect_payload`.
91
+ - The host expects `initResult` and receives a malformed `initResult` with the active
92
+ `initializationId`. The host sends a NACK and fails initialization with
93
+ `invalid_init_result_payload`. This error code describes a local host failure. The host does not
94
+ send it in `initResult.error`.
95
+
96
+ A malformed `initResult` with a missing or stale ID does not end initialization or reset its
97
+ timeout. Malformed messages do not restart initialization after it succeeds or fails.
98
+
99
+ The sandbox handles a malformed `init` differently if it can verify the `initializationId`. In that
100
+ case, it sends `initResult.error` with `invalid_init_payload` instead of a NACK. Otherwise, it sends
101
+ `invalidHostMessage`.
102
+
103
+ `CustomBlockErrorInfo` carries `code`, `message`, and `isRetryable`. Error schemas accept any string
104
+ for `code`, including unknown codes. TypeScript aliases list known codes for autocomplete.
105
+
106
+ ## Data sources
107
+
108
+ ### Bindings and IDs
109
+
110
+ Hosts send `BridgeDataSourceBindings` as `dataSources: { bindings }`, keyed by the semantic data
111
+ source key declared in the manifest. `collectionSchema` contains only actual database properties.
112
+
113
+ Sandbox-to-host object references are raw IDs. The SDK resolves semantic data-source and property
114
+ keys before sending query or page-operation requests. Get and update requests can carry an optional
115
+ resolved `dataSourceId`.
116
+
117
+ A binding with `inaccessible: true` marks a bound data source that the viewer can't read. The host
118
+ omits its pointer, schema, and property mappings. The SDK and host still initialize the block. The
119
+ SDK fails queries and page creation that use the data source with `data_source_inaccessible`,
120
+ without sending a message.
121
+
122
+ ### Query requests
123
+
124
+ `queryDataSource` may include a resolved `filter` and an ordered `sorts` list. Each sort contains a
125
+ raw `propertyId` and an `ascending` or `descending` direction. Hosts apply sorts in array order. The
126
+ SDK and host validate that the list contains at most ten unique properties. The host rejects
127
+ property types without a supported sort value.
128
+
129
+ Every filter and sort property ID must exist in `collectionSchema.propertiesById`. Queries with
130
+ filters or sorts return `data_source_schema_unavailable` when the schema is unavailable. Filter
131
+ branches, operators, person references, and sort objects reject extra fields.
132
+
133
+ #### Creator and status filters
134
+
135
+ Creator filters require `propertyId` to identify an actual database property of type `created_by`.
136
+ The `created_by` filter branch selects the property type, while `propertyId` addresses the column.
137
+
138
+ The `created_by` filter supports human user targets with `contains` and `does_not_contain`, plus
139
+ `is_empty` and `is_not_empty`. Hosts use row creator metadata, including non-human and missing
140
+ creators in exclusion results.
141
+
142
+ Status filters support option operators and stored group names. Group operators accept one name or
143
+ an array of 1–5 names. Hosts must validate each name against the bound Status property.
144
+
145
+ #### Relation filters
146
+
147
+ Relation filters require an actual `relation` property in the bound schema. `contains` and
148
+ `does_not_contain` accept one page ID. `is_empty` and `is_not_empty` accept only `true` and require
149
+ no page ID. Each relation filter accepts exactly one operator. Adapters must evaluate empty checks
150
+ against relation values, including XLDB row IDs where supported.
151
+
152
+ #### Date filters
153
+
154
+ Date comparisons accept ISO values and relative values such as `today`. The query schema defines the
155
+ accepted values and range operators. Range operators require an empty object.
156
+
157
+ Date comparisons accept `target` inside `date`, beside the operator. The target is `start_date` by
158
+ default. For ranges, `end_date` compares the range end. For individual dates, it compares the date.
159
+ Empty checks accept either target, but they test the whole property.
160
+
161
+ ```ts
162
+ filter: {
163
+ propertyId: "schedule-id",
164
+ date: { target: "end_date", on_or_after: "2026-10-08" },
165
+ }
166
+ ```
167
+
168
+ ## Capabilities
169
+
170
+ `manifest.capabilities` lists `{ capability, resource }` declarations. Both fields are open strings,
171
+ so a newer vocabulary never makes an older receiver reject a manifest. An omitted `capabilities`
172
+ marks a block that predates approval.
173
+
174
+ The `capability_not_granted` error code is reserved for a request that the viewer's grants do not
175
+ cover, with `isRetryable: false`. No adapter sends it yet, and no receiver restricts requests by
176
+ capability. The SDK's capabilities guide documents the vocabulary.
177
+
178
+ ## Page context
179
+
180
+ Containing-page context uses `CustomBlockPage`. The `init.page` and `pageChanged.page` fields
181
+ contain `{ type: "page", id, parent }` for an accessible page, or `{ type: "unavailable" }` when the
182
+ containing page itself is inaccessible. The unavailable shape never carries a page ID. This is
183
+ distinct from an accessible page with an inaccessible parent
184
+ (`page.parent: { type: "unavailable" }`).
185
+
186
+ ## Page writes
187
+
188
+ The `createPage` and `updatePage` messages use raw property IDs from Notion as map keys. Each value
189
+ must carry the same raw property ID in its `id` field.
190
+
191
+ ## Page responses
192
+
193
+ Host handlers return unified `BridgePage` for queries and page operations. Properties use display
194
+ names as keys and typed values that include their raw property IDs. Only actual schema properties
195
+ are returned. Query results contain `items` and `hasMore`. `bridgePageSchema` defines the page
196
+ fields, including archive state and creation, edit, and visit metadata.
197
+
198
+ Page reads return string values for `unique_id`, `formula`, `rollup`, `button`, `verification`, and
199
+ `location`, preserving each property's type. These properties are read-only. Values use stored text,
200
+ or `""` when absent. Hosts do not evaluate formulas or rollups.
201
+
202
+ The host converts responses to the sandbox's declared protocol. See
203
+ [versioning and compatibility](versioning.md) for protocol version rules. The host's
204
+ [compatibility reference](../host/docs/compatibility.md) describes older response formats.
@@ -0,0 +1,38 @@
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
+
21
+ ## Protocol export names
22
+
23
+ The `@notionhq/custom-blocks-host/protocol` entrypoint exports wire definitions. Page formats used
24
+ by protocols 3–5 are named `BridgePageForProtocol3To5` and `NotionDataSourcePageForProtocol3To5`,
25
+ with matching `bridgePageForProtocol3To5Schema` and `notionDataSourcePageForProtocol3To5Schema`
26
+ validators. Message types and schemas containing `WithProtocol3To5Compatibility` accept both current
27
+ page formats and protocol 3–5 page formats. `UNIFIED_PAGE_PROTOCOL_VERSION` is 6, the minimum
28
+ protocol version that uses unified pages.
29
+
30
+ ## Version changes
31
+
32
+ A breaking wire change increases the bridge protocol version. This includes changed meanings,
33
+ required fields, and new response variants an older receiver rejects. Optional fields and new
34
+ messages need no bump only when older receivers can safely ignore or NACK them. Parsing success
35
+ alone does not prove compatible SDK behavior.
36
+
37
+ An SDK that requires a newer protocol needs a host that supports that contract. Updating the SDK
38
+ package does not update the host in the embedding application.
@@ -1,12 +1,9 @@
1
- # Dev-shell data sources
1
+ # Dev shell data sources
2
2
 
3
- Data sources come in kinds, marked by their `type`, and all live in the worker's `data/*.json` — one
4
- source per file, read at spin-up. The shell supports the following types today:
5
-
6
- - `worker` — hand-authored JSON files. This is how you give your blocks data, and what this document
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); the pre-built
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" }`; ranges and datetimes use `"daterange"` / `"datetime"` / `"datetimerange"` with `end_date`, `start_time`, `end_time` |
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 spin-up, before they reach the shell UI. A malformed file fails the run with
71
- the file and problem named, e.g.
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
- ## Materialization
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
- You don't have to write these files from scratch. At spin-up the shell materializes a file for every
94
- data source the worker declares — both `worker.database(...)` entries and inline
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
- - The `worker_` prefix on the filename namespaces generated files away from ones you author
100
- yourself, so both coexist; the display `name` stays as declared, so the sidebar shows the clean
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 stop it before sampling. `--row-only`
117
- preserves the schema and appends rows with new IDs. Add `--overwrite` to replace existing rows.
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`](./bindings.md#choose-sample-data).
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
- Restart the dev shell after sampling to load the updated data.
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.