@notionhq/custom-blocks-dev-shell 0.1.115 → 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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -13
  3. package/THIRD_PARTY_LICENSES.md +133 -0
  4. package/dist/assets/index-DSaseWP_.js +11 -0
  5. package/dist/assets/index-Do-x8yIt.css +2 -0
  6. package/dist/index.html +2 -2
  7. package/dist-cli/cli/published-cli.js +8467 -51
  8. package/docs/bindings.md +17 -12
  9. package/docs/bridge/changelog.md +67 -0
  10. package/docs/bridge/protocol.md +204 -0
  11. package/docs/bridge/versioning.md +38 -0
  12. package/docs/data-sources.md +49 -36
  13. package/docs/host/README.md +177 -0
  14. package/docs/host/docs/compatibility.md +68 -0
  15. package/docs/host/docs/handlers.md +199 -0
  16. package/docs/host/docs/lifecycle.md +117 -0
  17. package/package.json +5 -3
  18. package/dist/assets/index-DXzPwq_J.js +0 -11
  19. package/dist/assets/index-E1j3FxAu.css +0 -2
  20. package/dist-cli/cli/binding-cli-flags.js +0 -33
  21. package/dist-cli/cli/binding-errors.js +0 -15
  22. package/dist-cli/cli/block-csp.js +0 -84
  23. package/dist-cli/cli/build-block-registry.js +0 -30
  24. package/dist-cli/cli/convert-values.js +0 -222
  25. package/dist-cli/cli/convert.js +0 -210
  26. package/dist-cli/cli/data-source-files.js +0 -6
  27. package/dist-cli/cli/data-sources.js +0 -114
  28. package/dist-cli/cli/dev-shell-launcher.js +0 -239
  29. package/dist-cli/cli/dev-shell-run.js +0 -72
  30. package/dist-cli/cli/errors.js +0 -12
  31. package/dist-cli/cli/launcher-bindings.js +0 -144
  32. package/dist-cli/cli/materialize.js +0 -105
  33. package/dist-cli/cli/ports.js +0 -20
  34. package/dist-cli/cli/prebuilt.js +0 -23
  35. package/dist-cli/cli/runtime-error-client.js +0 -52
  36. package/dist-cli/cli/serve-ui.js +0 -110
  37. package/dist-cli/cli/shared-server.js +0 -70
  38. package/dist-cli/cli/utils.js +0 -52
  39. package/dist-cli/cli/vite-block-server.js +0 -125
  40. package/dist-cli/cli/vite-middleware.js +0 -111
  41. package/dist-cli/cli/worker-manifest.js +0 -158
  42. package/dist-cli/protocol/contrast.d.ts +0 -4
  43. package/dist-cli/protocol/contrast.js +0 -3
  44. package/dist-cli/protocol/dataSources/dataSource.d.ts +0 -786
  45. package/dist-cli/protocol/dataSources/dataSource.js +0 -66
  46. package/dist-cli/protocol/dataSources/dataSourcePage.d.ts +0 -74
  47. package/dist-cli/protocol/dataSources/dataSourcePage.js +0 -15
  48. package/dist-cli/protocol/dataSources/dataSourceValue.d.ts +0 -66
  49. package/dist-cli/protocol/dataSources/dataSourceValue.js +0 -14
  50. package/dist-cli/protocol/dataSources/dateValue.d.ts +0 -157
  51. package/dist-cli/protocol/dataSources/dateValue.js +0 -61
  52. package/dist-cli/protocol/dataSources/errors.d.ts +0 -8
  53. package/dist-cli/protocol/dataSources/errors.js +0 -7
  54. package/dist-cli/protocol/dataSources/propertySchema.d.ts +0 -200
  55. package/dist-cli/protocol/dataSources/propertySchema.js +0 -174
  56. package/dist-cli/protocol/dataSources/recordPointer.d.ts +0 -9
  57. package/dist-cli/protocol/dataSources/recordPointer.js +0 -8
  58. package/dist-cli/protocol/dataSources/sortDirection.d.ts +0 -3
  59. package/dist-cli/protocol/dataSources/sortDirection.js +0 -2
  60. package/dist-cli/protocol/errors.d.ts +0 -12
  61. package/dist-cli/protocol/errors.js +0 -6
  62. package/dist-cli/protocol/ids.d.ts +0 -31
  63. package/dist-cli/protocol/ids.js +0 -26
  64. package/dist-cli/protocol/index.d.ts +0 -53
  65. package/dist-cli/protocol/index.js +0 -53
  66. package/dist-cli/protocol/manifest.d.ts +0 -67
  67. package/dist-cli/protocol/manifest.js +0 -36
  68. package/dist-cli/protocol/messages/connect.d.ts +0 -54
  69. package/dist-cli/protocol/messages/connect.js +0 -39
  70. package/dist-cli/protocol/messages/contrastModeChanged.d.ts +0 -7
  71. package/dist-cli/protocol/messages/contrastModeChanged.js +0 -7
  72. package/dist-cli/protocol/messages/createPage.d.ts +0 -290
  73. package/dist-cli/protocol/messages/createPage.js +0 -51
  74. package/dist-cli/protocol/messages/createPageResult.d.ts +0 -897
  75. package/dist-cli/protocol/messages/createPageResult.js +0 -43
  76. package/dist-cli/protocol/messages/currentUserChanged.d.ts +0 -18
  77. package/dist-cli/protocol/messages/currentUserChanged.js +0 -9
  78. package/dist-cli/protocol/messages/dataSourcesChanged.d.ts +0 -157
  79. package/dist-cli/protocol/messages/dataSourcesChanged.js +0 -13
  80. package/dist-cli/protocol/messages/getPage.d.ts +0 -902
  81. package/dist-cli/protocol/messages/getPage.js +0 -48
  82. package/dist-cli/protocol/messages/getUser.d.ts +0 -44
  83. package/dist-cli/protocol/messages/getUser.js +0 -32
  84. package/dist-cli/protocol/messages/hostToSandbox.d.ts +0 -4385
  85. package/dist-cli/protocol/messages/hostToSandbox.js +0 -48
  86. package/dist-cli/protocol/messages/incomingType.d.ts +0 -9
  87. package/dist-cli/protocol/messages/incomingType.js +0 -17
  88. package/dist-cli/protocol/messages/init.d.ts +0 -273
  89. package/dist-cli/protocol/messages/init.js +0 -57
  90. package/dist-cli/protocol/messages/initResult.d.ts +0 -37
  91. package/dist-cli/protocol/messages/initResult.js +0 -29
  92. package/dist-cli/protocol/messages/invalidHostMessage.d.ts +0 -14
  93. package/dist-cli/protocol/messages/invalidHostMessage.js +0 -13
  94. package/dist-cli/protocol/messages/invalidSandboxMessage.d.ts +0 -14
  95. package/dist-cli/protocol/messages/invalidSandboxMessage.js +0 -13
  96. package/dist-cli/protocol/messages/isInitHandshakeMessage.d.ts +0 -4
  97. package/dist-cli/protocol/messages/isInitHandshakeMessage.js +0 -11
  98. package/dist-cli/protocol/messages/listUsers.d.ts +0 -52
  99. package/dist-cli/protocol/messages/listUsers.js +0 -33
  100. package/dist-cli/protocol/messages/messagePayload.d.ts +0 -19
  101. package/dist-cli/protocol/messages/messagePayload.js +0 -1
  102. package/dist-cli/protocol/messages/openExternalUrl.d.ts +0 -32
  103. package/dist-cli/protocol/messages/openExternalUrl.js +0 -26
  104. package/dist-cli/protocol/messages/openPage.d.ts +0 -38
  105. package/dist-cli/protocol/messages/openPage.js +0 -34
  106. package/dist-cli/protocol/messages/pageChanged.d.ts +0 -32
  107. package/dist-cli/protocol/messages/pageChanged.js +0 -9
  108. package/dist-cli/protocol/messages/parentChanged.d.ts +0 -26
  109. package/dist-cli/protocol/messages/parentChanged.js +0 -9
  110. package/dist-cli/protocol/messages/queryDataSource.d.ts +0 -1446
  111. package/dist-cli/protocol/messages/queryDataSource.js +0 -252
  112. package/dist-cli/protocol/messages/queryDataSourceResult.d.ts +0 -686
  113. package/dist-cli/protocol/messages/queryDataSourceResult.js +0 -44
  114. package/dist-cli/protocol/messages/resize.d.ts +0 -11
  115. package/dist-cli/protocol/messages/resize.js +0 -10
  116. package/dist-cli/protocol/messages/sandboxToHost.d.ts +0 -1091
  117. package/dist-cli/protocol/messages/sandboxToHost.js +0 -33
  118. package/dist-cli/protocol/messages/themeChanged.d.ts +0 -10
  119. package/dist-cli/protocol/messages/themeChanged.js +0 -10
  120. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.d.ts +0 -10
  121. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.js +0 -9
  122. package/dist-cli/protocol/messages/updatePage.d.ts +0 -271
  123. package/dist-cli/protocol/messages/updatePage.js +0 -23
  124. package/dist-cli/protocol/messages/updatePageResult.d.ts +0 -895
  125. package/dist-cli/protocol/messages/updatePageResult.js +0 -41
  126. package/dist-cli/protocol/pages/page.d.ts +0 -1422
  127. package/dist-cli/protocol/pages/page.js +0 -318
  128. package/dist-cli/protocol/parent.d.ts +0 -32
  129. package/dist-cli/protocol/parent.js +0 -13
  130. package/dist-cli/protocol/protocolVersion.d.ts +0 -8
  131. package/dist-cli/protocol/protocolVersion.js +0 -11
  132. package/dist-cli/protocol/theme.d.ts +0 -3
  133. package/dist-cli/protocol/theme.js +0 -2
  134. package/dist-cli/protocol/users/user.d.ts +0 -32
  135. package/dist-cli/protocol/users/user.js +0 -20
  136. package/dist-cli/shared/block-registry.js +0 -28
  137. package/dist-cli/shared/data-source.js +0 -22
  138. package/dist-cli/shared/runtime-config.js +0 -10
  139. 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
- The dev shell previews your worker's custom blocks with local data from `data/*.json`.
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
- An invalid explicit selection stops startup. A valid source with no rows still takes precedence over
16
- later choices.
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. Invalid JSON or an
33
- invalid source file also stops startup.
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](./data-sources.md) to define a source.
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
- Bindings last for the page load, per block. Refresh the shell to restore each block's CLI source and
106
- property selections, with automatic matching for properties without an override.
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
- The launcher reads `data/*.json` once at startup. To load file edits, restart the dev shell command.
109
- A browser refresh does not reload the files.
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,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.