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

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.
@@ -1,9 +1,13 @@
1
1
  # Dev shell data sources
2
2
 
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.
3
+ The dev shell loads sample data from your project’s `data/*.json` files. Use [bindings](bindings.md)
4
+ to connect a file to a block.
5
+
6
+ ## Built-in examples
7
+
8
+ Open **Workspace → Data sources → Add data source**. **Add** copies an example into `data/`. **Add
9
+ all missing** copies the remaining examples. Existing files are never overwritten, including files
10
+ with errors.
7
11
 
8
12
  ## File format
9
13
 
@@ -37,17 +41,18 @@ For example, `data/tasks.json`:
37
41
  }
38
42
  ```
39
43
 
40
- - `type` — the source's kind. Hand-authored files declare `"worker"` (the default). The pre-built
41
- sources the shell adds carry `"built-in"`.
42
- - `name` — the label shown in the shell sidebar. If omitted, it defaults to the filename without
44
+ - `type`: the source's kind. Hand-authored files declare `"worker"` (the default). The built-in
45
+ examples the shell adds carry `"built-in"`.
46
+ - `name`: the label shown in Workspace and Bindings. If omitted, it defaults to the filename without
43
47
  `.json`.
44
- - `icon` — optional emoji shown alongside the name.
45
- - `schema` — maps each property key to its runtime property schema. If omitted, it defaults to `{}`.
48
+ - `icon`: optional emoji shown alongside the name.
49
+ - `schema`: maps each property key to its runtime property schema. If omitted, it defaults to `{}`.
46
50
  Use the same property keys and types the block declares. Status properties can include `options`
47
51
  and `groups`. Types: `title`, `rich_text`, `number`, `select`, `multi_select`, `status`, `date`,
48
- `checkbox`, `url`, `email`, `phone_number`, `people`, `files`, `relation`.
49
- - `rows` — the source records. If omitted, it defaults to `[]`. Each row needs a unique string `id`.
50
- Store property values under their schema keys.
52
+ `checkbox`, `url`, `email`, `phone_number`, `people`, `files`, `relation`, `created_time`,
53
+ `last_edited_time`, `created_by`, `last_edited_by`.
54
+ - `rows`: the source records. If omitted, it defaults to `[]`. Each row needs a nonempty string
55
+ `id`, unique across all sample data files. Store property values under their schema keys.
51
56
 
52
57
  Value shapes by property type:
53
58
 
@@ -62,13 +67,17 @@ Value shapes by property type:
62
67
  | `relation` | array of `{ "id": "...", "table": "block" }` pointers |
63
68
  | `files` | string (the host serializes file properties as text today) |
64
69
 
70
+ People properties use user IDs, not page IDs from a directory data source.
71
+
65
72
  ## Validation
66
73
 
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.
69
- `data/tasks.json: rows.0.id: Invalid key: Expected "id" but received undefined`. The filename
70
- without `.json` is the source identity used by bindings and source pickers. Renaming a file changes
71
- its identity.
74
+ Files are validated independently at startup and after edits. Errors name the file and problem, for
75
+ example `data/tasks.json: rows.0.id: Invalid key: Expected "id" but received undefined`. The
76
+ filename without `.json` is the source identity used by bindings and source pickers. Renaming a file
77
+ changes its identity.
78
+
79
+ Duplicate page IDs make every file containing that ID unavailable until the collision is fixed. The
80
+ error names the ID and conflicting files. Other files remain available.
72
81
 
73
82
  ## Querying
74
83
 
@@ -77,8 +86,8 @@ property keys to property IDs before it sends the query. Empty values stay last
77
86
  Date-only and zone-less datetime values sort using UTC. Datetime values with a `time_zone` use that
78
87
  named zone, and an explicit offset in `start_time` wins.
79
88
 
80
- Created time and Last edited time values accept ISO timestamp strings or the sample `date` shapes
81
- above.
89
+ Date, Created time, and Last edited time values accept ISO timestamp strings or the sample `date`
90
+ shapes above.
82
91
 
83
92
  People, Created by, and Last edited by sorts use record IDs as mock display names. People sorts
84
93
  preserve pointer order and remove duplicates. Groups use their composite group and workspace IDs.
@@ -87,21 +96,24 @@ The dev shell uses `en-US` collation. Notion uses resolved display names and the
87
96
  Status group filters use each Status property's `options` and `groups`. Group `option_ids` must
88
97
  reference option IDs from the same property.
89
98
 
99
+ The dev shell clamps valid requests above 999 rows and reports
100
+ `limitClamp: { requested, applied: 999 }`. `hasMore` reports whether matching rows were omitted.
101
+ Limits that are not positive safe integers return `data_source_query_invalid_limit`.
102
+
90
103
  ## Generated files
91
104
 
92
105
  At startup, the shell creates `data/worker_<key>.json` for each declared data source without an
93
106
  existing file. Each file contains the declared schema and no rows. Declarations include
94
107
  `worker.database(...)` entries and inline `worker.customBlock({ dataSources })` schemas.
95
108
 
96
- The `worker_` prefix keeps generated files separate from files you create. The sidebar uses the
97
- declared data source name.
109
+ The `worker_` prefix keeps generated files separate from files you create.
98
110
 
99
111
  The shell preserves existing files, so your row edits survive restarts. To regenerate a file from
100
112
  the declared schema, delete the file and restart the shell.
101
113
 
102
- The shell shows exactly the sources in `data/`, nothing else.
114
+ The shell lists only sources in `data/`.
103
115
 
104
- ## Sample rows into a generated source
116
+ ## Add sample rows to a generated source
105
117
 
106
118
  To populate a declared slot, use the generated file as the sample target:
107
119
 
@@ -120,16 +132,17 @@ The shell loads sampled data automatically.
120
132
 
121
133
  ## Live updates and local writes
122
134
 
123
- The shell watches sample data source files. When a selected file changes, the active block restarts,
124
- clearing its UI state and in-memory data changes. Changes to unrelated files do not restart the
125
- block. Adding or removing a file can change automatic selection and restart the block.
135
+ The shell watches sample data files. Changes to loaded filenames, schemas, or rows reset all page
136
+ records to the sample files and restart the preview. This includes adding or removing a source, or a
137
+ loaded source becoming invalid. Saving equivalent data or changing source labels or icons preserves
138
+ page records.
126
139
 
127
- Your selected block and binding selections stay the same. Saving unchanged data does not restart the
128
- block.
140
+ **Retry** and changes to blocks, bindings, or display mode preserve page records. Opening or closing
141
+ Workspace also preserves them. Restarting the preview clears the block's JavaScript and UI state.
142
+ Refreshing the browser resets page records to the sample files.
129
143
 
130
- A file with invalid JSON or an invalid schema shows **Error** in the sidebar. Select the file for
131
- details. Blocks bound to the file show the error until you fix and save the file. Once the file
132
- loads successfully, the active block restarts. Other sample data sources remain available.
144
+ Blocks bound to an invalid file show its error until you fix and save the file. Once the file loads,
145
+ the active block restarts. Other sample data sources remain available.
133
146
 
134
147
  SDK writes stay in memory. They never change JSON files or production data.
135
148
 
@@ -5,20 +5,22 @@ owns the iframe, permissions, data access, persistence, analytics, and UI. Block
5
5
  `@notionhq/custom-blocks`.
6
6
 
7
7
  Create the host before navigating the iframe. Pass the full block URL as `sandboxUrl`, and call
8
- `stop()` when removing the iframe. A host instance belongs to the required `viewerId`. Supply one
9
- asynchronous `getCurrentUser` profile reader; its returned ID must match that viewer. Create a fresh
10
- host and iframe when the viewer changes.
8
+ `stop()` when removing the iframe. The host calls `getViewer()` synchronously once to capture a user
9
+ or anonymous identity. Create a fresh host and iframe when that identity changes. The
10
+ `handlers.getUser` handler loads profiles separately. See
11
+ [Current viewer](docs/host-contract.md#current-viewer) for identity validation and profile-read
12
+ errors.
11
13
 
12
14
  For configuration and lifecycle details, see [Initialization and lifecycle](docs/lifecycle.md).
13
15
 
14
- For platform handlers, signal-based live queries, and explicit partial implementations, see the
16
+ For data handlers, query subscriptions, and partial integrations, see the
15
17
  [Host contract](docs/host-contract.md). The host accepts `CustomBlockHostOptions`.
16
18
 
17
19
  Use `BridgeParent` from `@notionhq/custom-blocks-host/protocol` to construct parent references with
18
20
  plain string IDs. The host validates the parent before sending it to the block.
19
21
 
20
- Implement `CustomBlockHostHandlers` to connect the host to your application. Result-returning
21
- handlers return promises. `CustomBlockHostHandler<Args, Payload>` supplies the shared signature and
22
+ Implement `CustomBlockHostHandlers` to connect the host to your application. Handlers that return
23
+ results use promises. `CustomBlockHostHandler<Args, Payload>` supplies the shared signature and
22
24
  request context. Handlers return shared bridge data using `CustomBlockHostHandlerResult`. Use
23
25
  `makeBridgePage` to construct a complete `BridgePage` from your records. See
24
26
  [Return bridge data](docs/handlers.md#return-bridge-data).
@@ -63,16 +65,8 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
63
65
 
64
66
  const host = createCustomBlockHost({
65
67
  iframe,
66
- blockId: "11111111-1111-4111-8111-111111111111",
67
- viewerId: "33333333-3333-4333-8333-333333333333",
68
- getCurrentUser: async () => ({
69
- object: "user",
70
- id: "33333333-3333-4333-8333-333333333333",
71
- type: "person",
72
- name: "Demo viewer",
73
- avatar_url: null,
74
- person: { email: "viewer@example.com" },
75
- }),
68
+ instance: { type: "block", blockId: "11111111-1111-4111-8111-111111111111" },
69
+ getViewer: () => ({ type: "user", userId: "33333333-3333-4333-8333-333333333333" }),
76
70
  theme: "light",
77
71
  contrastMode: "standard",
78
72
  containingPage: {
@@ -107,7 +101,7 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
107
101
  resize: message => setHeight(message.height),
108
102
  },
109
103
  onStatusChange: state => {
110
- if (state.status === "initialized") {
104
+ if (state.status === "ready") {
111
105
  setHeight(state.initialHeight ?? 300)
112
106
  status.hidden = true
113
107
  iframe.style.visibility = "visible"
@@ -132,7 +126,7 @@ const dispose = mountCustomBlock(document.body, new URL("https://blocks.example.
132
126
  window.addEventListener("pagehide", dispose, { once: true })
133
127
  ```
134
128
 
135
- You should see “Loading block…” until the block completes initialization, then the block iframe. A
129
+ The example displays “Loading block…” until the host reports `ready`, then reveals the iframe. A
136
130
  connection failure displays its error code. The example limits the iframe height to 120–1,200 CSS
137
131
  pixels.
138
132
 
@@ -140,40 +134,44 @@ Call `dispose()` when your application removes the embed. To retry a failed conn
140
134
  block URL, dispose of the current embed and call `mountCustomBlock()` again.
141
135
 
142
136
  Initial `theme`, `contrastMode`, `containingPage`, and `parent` may be `null` while loading. Call
143
- the corresponding setters as values resolve. The shared host waits for all four before sending
144
- `init`. The wait counts toward `initialStateTimeoutMs` after `connect`. Setters take resolved values
145
- only. For containing-page context, `{ type: "unavailable" }` means denied access, distinct from
146
- loading.
137
+ the corresponding setters as values resolve. Setup waits for the manifest, theme, and contrast mode.
138
+ Parent and containing page values can arrive later. See
139
+ [manifest and initial state](docs/lifecycle.md#manifest-and-initial-state) for the loading contract.
147
140
 
148
141
  For a production integration, replace the demo context and manifest with your application's values.
149
- Supply data-source bindings and handlers for the APIs your block uses. Your application must enforce
142
+ Supply data source bindings and handlers for the APIs your block uses. Your application must enforce
150
143
  permissions and record access.
151
144
 
152
145
  To connect workspace data, see [Connect a data source](docs/handlers.md#connect-a-data-source).
153
146
 
147
+ Data source reads resolve configured property IDs against the loaded schema. Exact matches win.
148
+ Otherwise, the host decodes a URL-encoded ID once and uses it only when it matches a schema
149
+ property. The host validates these mappings before returning them; saved bindings stay unchanged.
150
+
151
+ `CustomBlockHostInstance` accepts plain string IDs. `instance` identifies the configured block,
152
+ page, or view independently of the page currently being displayed. `CustomBlockInstance` uses
153
+ `{ type: "block" | "page", blockId }` or `{ type: "view", viewId }`. The identity stays fixed for
154
+ the host connection and is included in `init`. A layout module backed by a custom block uses that
155
+ block's identity.
156
+
154
157
  ## Guides and reference
155
158
 
156
- - [Initialization and lifecycle](docs/lifecycle.md): manifests, context, timeouts, live state, and
157
- cleanup.
158
- - [Handlers and data](docs/handlers.md): application handlers, data-source integration, queries, and
159
+ - [Initialization and lifecycle](docs/lifecycle.md): manifests, initial values, timeouts, live
160
+ updates, and cleanup.
161
+ - [Handlers and data](docs/handlers.md): application handlers, data source integration, queries, and
159
162
  navigation.
160
- - [Host compatibility](docs/compatibility.md): supported versions and response conversions.
163
+ - [Connection compatibility](docs/compatibility.md): protocol negotiation and version requirements.
161
164
 
162
- The runtime handles the wire handshake and message validation. The shared protocol references cover
163
- payload semantics, version rules, and contract history:
165
+ The runtime handles the wire handshake and message validation. The shared protocol references define
166
+ message payloads and versioning:
164
167
 
165
168
  - [Wire protocol](../bridge/protocol.md)
166
169
  - [Protocol versioning](../bridge/versioning.md)
167
- - [Protocol changelog](../bridge/changelog.md)
168
170
 
169
171
  ## Protocol schemas and types
170
172
 
171
- The `/protocol` entrypoint exposes the protocol definitions bundled with this host release. It
172
- provides message schemas and types, data shapes, IDs, error definitions, and protocol-version
173
- constants.
174
-
175
- Import these definitions through the host package to use the protocol version shipped with that
176
- host:
173
+ The `/protocol` entrypoint exposes message schemas and types, data shapes, IDs, and error
174
+ definitions. Import these definitions through the host package:
177
175
 
178
176
  ```ts
179
177
  import {
@@ -182,9 +180,6 @@ import {
182
180
  } from "@notionhq/custom-blocks-host/protocol"
183
181
  ```
184
182
 
185
- `LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest bridge protocol version defined by the
186
- bundled protocol.
187
-
188
183
  Host APIs, configuration, handler results, and domain argument types are available from
189
184
  `@notionhq/custom-blocks-host`.
190
185
 
@@ -202,4 +197,4 @@ colors before writing. The runtime validates response payloads.
202
197
 
203
198
  Hosts must check URL-backed icon and cover writes against the block's network permissions before
204
199
  mutating records. Notion permits the submitted HTTPS destination only when its origin is
205
- allowlisted; that origin is trusted to redirect.
200
+ allowlisted. That origin is trusted to redirect.
@@ -1,47 +1,62 @@
1
- # Host compatibility
1
+ # Connection compatibility
2
2
 
3
- A host can update while deployed blocks keep older SDKs. The runtime accepts supported protocol
4
- versions and converts current handler results to each block's declared contract. This reference
5
- covers version admission, normalization, and the formats sent to older blocks. Protocol version
6
- rules and release history are in the [versioning guide](../../bridge/versioning.md) and
7
- [changelog](../../bridge/changelog.md).
3
+ The SDK and host release independently. Their package versions do not determine whether they can
4
+ communicate. The connection uses a protocol version that both implement.
8
5
 
9
6
  ## Supported versions
10
7
 
11
- The protocol subpath exports `LATEST_BRIDGE_PROTOCOL_VERSION` and
12
- `MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION`. These constants define the package's latest known
13
- protocol and runtime minimum. Embedders can raise the minimum but cannot enable retired versions.
14
- The host admits future positive integer versions and validates them against known schemas. Admission
15
- does not guarantee that future features work.
8
+ The current SDK connection contract is protocol 12. The SDK sends `connect` with a
9
+ `supportedProtocolVersions` array of distinct positive integers. The host selects a version from
10
+ that offer and returns it in `connectResult.protocolVersion`. This host selects protocol 12 when the
11
+ offer includes it and the configured minimum permits it. Otherwise, it returns
12
+ `unsupported_protocol_version`.
16
13
 
17
- `sdkVersion` is analytics metadata. Compatibility behavior depends on the protocol version.
14
+ The selected version applies to the connection. `init` does not repeat it. `sdkVersion` identifies
15
+ the SDK package for diagnostics. It does not select the protocol.
18
16
 
19
- The current SDK declares protocol 11. The shared runtime minimum is 3. The dev shell uses the Worker
20
- manifest in host mode and accepts the shared runtime's supported protocol versions. Protocols 7 and
21
- 8 use the same page and query response formats. Protocol 8's local manifest declaration is selected
22
- only in sandbox mode; host mode uses the persisted manifest. See the
23
- [protocol 8 release entry](../../bridge/changelog.md#protocol-8-local-manifest-declarations).
17
+ `LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest contract defined by the protocol package.
18
+ `MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION` defines the host runtime's minimum. The
19
+ `minBridgeProtocolVersion` option defaults to that minimum and can restrict which SDKs an embedding
20
+ application accepts. Changing this option cannot add support for a contract the host does not
21
+ implement.
24
22
 
25
- The `minBridgeProtocolVersion` option defaults to the runtime minimum. Raising the option rejects
26
- older SDKs for this embedding application. Lowering it cannot restore retired versions. Raising
27
- `MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION` retires those versions across the runtime.
23
+ The host also accepts the protocol 3–11 handshake, where `connect` declares a single
24
+ `bridgeProtocolVersion`. Those connections retain eager initialization and their response formats.
25
+ The current SDK requires protocol 12 and cannot connect to a host that supports only protocols 3–11.
26
+
27
+ ## Connection requirements
28
+
29
+ Create the host before navigating the iframe so it can receive `connect`. Each host and iframe
30
+ handle one connection. Create a fresh pair to retry, change the block URL, or change viewers.
31
+
32
+ A successful `connectResult` confirms the selected protocol. Setup completes when the sandbox
33
+ accepts `init` and sends a successful `initResult`. The host then permits data operations while it
34
+ waits for `ready`. The embedding application reveals the iframe when the host reports `ready`. See
35
+ [Initialization and lifecycle](lifecycle.md) for payload delivery, callbacks, and timeouts.
36
+
37
+ An SDK must implement every protocol version it advertises. If the SDK requires a contract the host
38
+ does not implement, update the embedding application's host before adopting that SDK. Publishing a
39
+ host package does not update applications that use it.
40
+
41
+ The [protocol versioning reference](../../bridge/versioning.md) defines the rules for wire
42
+ contract changes.
28
43
 
29
44
  ## Host normalization
30
45
 
31
46
  The host validates sandbox requests before dispatching them to handlers. Handlers use current data
32
47
  shapes, and the host converts responses to the sandbox's declared protocol. Setters, query
33
- refreshes, and handler responses use the same conversion. Unchanged messages and errors pass
34
- through.
48
+ refreshes, and handler responses use the same conversion. Messages that need no conversion pass
49
+ through unchanged.
35
50
 
36
51
  ## Current compatibility behavior
37
52
 
38
53
  | Target | Query results | Page operation results | Binding schemas | Native icons |
39
54
  | ------ | --------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
40
- | 3–4 | Flat ID-keyed values, including synthetic metadata entries | ID-keyed properties with unsupported property objects omitted | Synthetic metadata read schemas restored in outgoing copies | External SVG URLs in page operations; icons omitted from flat query results |
55
+ | 3–4 | Flat ID-keyed values, including synthetic metadata entries | ID-keyed properties with unsupported property objects omitted | Synthetic metadata read schemas restored in outgoing copies | External SVG URLs in page operations. Icons omitted from flat query results |
41
56
  | 5 | Same query values as protocols 3–4 | Same page format as protocols 3–4 | Actual database schemas. The SDK supplies synthetic read schemas locally | Same as protocols 3–4 |
42
57
  | 6 | Unified name-keyed properties. Text fallback property objects become `null` | Same unified page format | Actual database schemas | External SVG URLs |
43
58
  | 7–8 | Unified pages with typed text fallback properties | Same unified page format | Actual database schemas | External SVG URLs |
44
- | 9+ | Unified pages with typed text fallback properties | Same unified page format | Actual database schemas | Native icon objects |
59
+ | 9–12 | Unified pages with typed text fallback properties | Same unified page format | Actual database schemas | Native icon objects |
45
60
 
46
61
  The synthetic metadata IDs are `created_time`, `last_edited_time`, `created_by`, and
47
62
  `last_edited_by`. They retain metadata meaning if an actual property uses the same raw ID. This
@@ -77,10 +92,35 @@ queries against synthetic metadata IDs without corresponding database properties
77
92
 
78
93
  ## Data source binding names
79
94
 
80
- Protocol 11 uses `dataSourceSchema` and `dataSourcePointer`. Host adapters supply only these current
81
- names. The outgoing boundary restores `collectionSchema` and `collectionPointer` for protocols 3–10,
82
- including initialization and live binding updates. The host runtime minimum is unchanged.
83
-
84
- The renamed `CustomBlockHostDataSourceState.dataSource.dataSourceSchema` is a host API field, not a
85
- sandbox message. Update its producers when adopting the host package. Publish the host and deploy
86
- each embedding application's adoption before releasing an SDK that requires protocol 11.
95
+ Protocols 11–12 use `dataSourceSchema` and `dataSourcePointer`. Host adapters supply only these
96
+ current names. The outgoing boundary restores `collectionSchema` and `collectionPointer` for
97
+ protocols 3–10.
98
+
99
+ Protocols 3–11 receive bindings in eager initialization and replacement bindings in
100
+ `dataSourcesChanged`. Protocol 12 reads bindings through `getDataSource`. After a configuration
101
+ change, `dataSourcesInvalidated` tells the SDK to reload metadata when an operation needs it.
102
+
103
+ ## Initialization and location values
104
+
105
+ | Contract | Protocols 3–11 | Protocol 12 |
106
+ | ---------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
107
+ | Initialization | Eager values include the current user, parent, containing page, and data source bindings | Setup contains `instance`, `manifest`, and `preferences`. Data access does not block setup |
108
+ | Reveal | Successful `initResult` supplies the initial height and permits reveal | Successful `initResult` permits data operations. `ready` supplies the initial height and permits reveal |
109
+ | Containing-page display mode | Omitted from eager init and `pageChanged` | Required on accessible containing-page descriptors. Defaults to `full_page` |
110
+ | Location failures | Known initial failures fail eager initialization. `parentError` and `pageError` are not sent | `parentError` and `pageError` report known failures independently. Later value notifications clear the corresponding error |
111
+ | Missing user names | Compatibility encoding omits missing names and preserves empty strings | Full user profiles contain `name: string \| null` |
112
+
113
+ For protocols 3–11, a malformed `initResult` with the active `initializationId` fails setup with
114
+ `invalid_init_result_payload`. See [host lifecycle](lifecycle.md#callbacks) for setup diagnostics.
115
+
116
+ For protocols 3–11, the host converts `does_not_exist`, `permission_denied`, and `load_failed`
117
+ handler errors to the operation's existing error codes. User lookup and listing use
118
+ `get_user_failed` and `list_users_failed`. Page reads, creation, and updates use `get_page_failed`,
119
+ `create_page_failed`, or `update_page_failed` for load failures, and `page_unavailable` for missing
120
+ or inaccessible pages. Page opening uses `page_unavailable`. Protocol 12 preserves the shared
121
+ resource error codes.
122
+
123
+ Protocols 3–11 require a user viewer and a successful `handlers.getUser` result for eager
124
+ initialization. On these protocols, anonymous setup fails with `current_user_unavailable` before
125
+ profile loading. Protocol 12 anonymous setup succeeds. The `getViewer` request and `getViewerResult`
126
+ response require a host with viewer-read support.
@@ -2,8 +2,7 @@
2
2
 
3
3
  Handlers connect block requests to your application's data access, persistence, and navigation. The
4
4
  runtime validates bridge messages and manages subscriptions. Your application enforces viewer
5
- permissions and implements the requested operations. This guide covers handler contracts,
6
- data-source setup, updates, and external navigation.
5
+ permissions and implements the requested operations.
7
6
 
8
7
  The [dev shell](https://www.npmjs.com/package/@notionhq/custom-blocks-dev-shell) is a working host
9
8
  implementation with local sample data. Use it as a reference for a larger integration. Production
@@ -14,7 +13,7 @@ hosts must provide their own permissions, data access, and persistence.
14
13
  Every `CustomBlockHostHandlers` method is required. Use `hostHandlerNotImplemented()` in explicit
15
14
  wrappers for the
16
15
  [operations that can report unsupported](host-contract.md#options-and-partial-implementations).
17
- Result-returning handlers return promises. Errors carry `{ code, message, isRetryable }`, with open
16
+ Handlers that return results use promises. Errors carry `{ code, message, isRetryable }`, with open
18
17
  string codes.
19
18
 
20
19
  ### Return bridge data
@@ -22,18 +21,23 @@ string codes.
22
21
  Handlers return data in the bridge's shared types. Use bridge builders to construct complete objects
23
22
  from application records.
24
23
 
25
- The host validates result shapes, matches responses to requests, and converts responses for the
26
- block's protocol version. Your application checks that records exist and that the viewer may perform
27
- the requested operation.
24
+ The host validates result shapes and matches responses to requests. Your application checks that
25
+ records exist and that the viewer may perform the requested operation.
28
26
 
29
- The runtime validates query filters and sorts against the bound data-source schema before
27
+ The runtime validates query filters and sorts against the bound data source schema before
30
28
  `subscribeToQuery` runs. See the [wire reference](../../bridge/protocol.md#data-sources) for
31
29
  query semantics.
32
30
 
33
31
  For one-shot requests, a handler that throws, rejects, or returns a malformed result produces
34
- `unknown_error`. Exception details go to `onLog`; the sandbox receives a generic error. Specific
32
+ `unknown_error`. Exception details go to `onLog`. The sandbox receives a generic error. Specific
35
33
  errors returned by handlers pass through unchanged.
36
34
 
35
+ Shared resource errors are `load_failed`, `permission_denied`, and `does_not_exist`. Return
36
+ `does_not_exist` only when the underlying operation establishes absence and permits disclosing it.
37
+ Missing local records do not establish absence. Preserve an unavailable result when the underlying
38
+ operation does not distinguish missing resources from denied access. The embedding application makes
39
+ that decision. The shared host forwards its result.
40
+
37
41
  ## Connect a data source
38
42
 
39
43
  To extend the [embed example](../README.md#create-a-host) with a data source, add its manifest
@@ -48,8 +52,11 @@ return an error. See [metadata and configuration](host-contract.md#metadata-and-
48
52
  `subscribeToQuery` receives the source ID, query options, limit, signal, and callbacks described in
49
53
  [queries and cancellation](host-contract.md#queries-and-cancellation). Enforce record access, apply
50
54
  the requested filters, sorts, and archive selection, and honor the limit before calling
51
- `onSnapshot({ items, hasMore })`. Result properties use display names as keys and include raw
52
- property IDs. The runtime validates results and converts them for supported older SDKs.
55
+ `onSnapshot({ items, hasMore })`. If you reduce the requested limit, include
56
+ `limitClamp: { requested, applied }` in the snapshot. See
57
+ [query limits](../../bridge/protocol.md#host-applied-query-limits) for the result contract.
58
+ Result properties use display names as keys and include raw property IDs. The runtime validates
59
+ results before sending them to the SDK.
53
60
 
54
61
  ## Refresh active queries
55
62
 
@@ -57,10 +64,10 @@ The platform observer calls `onSnapshot` again when rows change. Release the obs
57
64
  pending setup when the subscription signal aborts. The shared host handles subscription IDs,
58
65
  replacement, unsubscribe, and shutdown. Do not return a second cleanup callback.
59
66
 
60
- Use `host.refreshDataSource({ dataSourceId })` when source metadata or access changes. A successful
61
- refresh sends updated bindings and cancels queries whose bindings changed. Unchanged bindings keep
62
- their existing subscriptions. Ordinary row changes flow through the existing observer. See
63
- [queries and cancellation](host-contract.md#queries-and-cancellation).
67
+ Use `host.refreshDataSource({ dataSourceId })` when source metadata or access changes. The refresh
68
+ invalidates metadata and cancels queries for every source, not just `dataSourceId`. It does not
69
+ fetch replacement metadata. See [Updates](host-contract.md#updates) for the contract. Ordinary row
70
+ changes flow through the active observer and need no metadata refresh.
64
71
 
65
72
  ## Page and user operations
66
73
 
@@ -69,6 +76,15 @@ and persistence. `getUser` and `listUsers` supply user data. Each handler return
69
76
  or an error. The runtime adds the request's correlation ID and sends the response. The application
70
77
  enforces record access before reading or writing data.
71
78
 
79
+ For `createPage` and `updatePage`, return success after your application confirms the save. A local
80
+ cache update or queued transaction does not establish that a remote save succeeded. Capture the
81
+ requested mutation's response state before waiting, so later edits do not enter its result.
82
+
83
+ If a save fails or confirmation exceeds your application's deadline, return `create_page_failed` or
84
+ `update_page_failed`. A timeout does not cancel the queued write. Set `isRetryable: false` when
85
+ repeating the operation could duplicate a create or race a write that is still pending. Keep any
86
+ private server rejection details in internal application logs; return a safe message to the block.
87
+
72
88
  `openPage` handles navigation to a Notion page. `resize` receives the block's requested height in
73
89
  CSS pixels. The application owns navigation and iframe sizing.
74
90
 
@@ -99,5 +115,5 @@ properties, the manifest property stays unmapped.
99
115
  including reminders. Invalid input throws `InvalidNotionDateError`.
100
116
 
101
117
  The root exports host configuration, handlers, results, and domain argument types. Wire schemas,
102
- message and page types, and constants such as `LATEST_BRIDGE_PROTOCOL_VERSION` use the
118
+ message and page types, and shared constants use the
103
119
  [protocol subpath](../README.md#protocol-schemas-and-types).