@notionhq/custom-blocks-dev-shell 0.2.0 → 0.3.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.
@@ -7,24 +7,48 @@ Protocol version rules are in [Bridge protocol versioning](versioning.md). The h
7
7
  [compatibility reference](../host/docs/compatibility.md) describes current support and response
8
8
  conversions.
9
9
 
10
- Publication dates refer to npm releases in Pacific time, not deployment in Notion. Unqualified SDK
11
- versions refer to `@notionhq/custom-blocks`.
12
-
13
- | Protocol | SDK release | Published | Breaking contract changes |
14
- | ------------------------------------------------------ | ---------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
15
- | 1 | `ncblock@0.0.1` | May 11, 2026 | Initial `ready` / `init` handshake and block APIs |
16
- | 2 | `ncblock@0.0.36` | June 18, 2026 | Structured errors, handshake changes, and raw data-source IDs instead of manifest keys |
17
- | 3 | `0.1.0` | July 22, 2026 | Accumulated contract changes include `connect → init → initResult`, initialization identity, subscription identity, and required structured connect errors |
18
- | 4 | `0.2.0` | September 17, 2026 | Required `init.contrastMode` and page/query `is_archived` and `in_trash` fields |
19
- | 5 [†](#protocol-5-unavailable-containing-page-context) | `0.2.16` | September 30, 2026 | Query filters and sorts must address actual database properties. Filter and sort payloads reject extra fields |
20
- | 6 [‡](#protocol-6-richer-fallback-properties) | `0.3.0` | October 26, 2026 | Typed, display-name-keyed query properties and unified page responses replace the older query representation |
21
- | 7 | `0.3.3` | October 30, 2026 | Typed text fallback properties for unique ID, button, formula, location, rollup, and verification |
22
- | 8 | `0.3.4` | November 3, 2026 | Local manifests move from `/manifest` to HTML metadata sent in `connect`; `manifestSource` selects the initialization manifest |
23
- | 9 | Unreleased | — | Native page icons; older protocols receive external SVG URLs |
24
- | 10 | `0.4.0` | November 10, 2026 | Removes `last_visited_time` from property schemas, page properties, and page metadata |
25
-
26
- The table lists SDK release boundaries, not complete supported version ranges. Host compatibility
27
- depends on `connect.bridgeProtocolVersion`, not the SDK package version.
10
+ Dates refer to npm releases in Pacific time, not deployment in Notion. Planned entries show the
11
+ expected package version and release date. Unqualified SDK versions refer to
12
+ `@notionhq/custom-blocks`.
13
+
14
+ | Protocol | First SDK release | First standalone host release | First dev shell release | Breaking contract changes |
15
+ | ------------------------------------------------------ | ----------------------------- | ----------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
16
+ | 1 | `ncblock@0.0.1` · 2026-05-11 | — | — | Initial `ready` / `init` handshake and block APIs |
17
+ | 2 | `ncblock@0.0.36` · 2026-06-18 | — | `0.0.1` · 2026-07-21 | Structured errors, handshake changes, and raw data-source IDs instead of manifest keys |
18
+ | 3 | `0.0.79` · 2026-07-22 | `0.0.1` · 2026-09-09 | `0.0.8` · 2026-07-22 | Accumulated contract changes include `connect → init → initResult`, initialization identity, subscription identity, and required structured connect errors |
19
+ | 4 | `0.2.0` · 2026-09-17 | `0.1.14` · 2026-09-17 | `0.1.63` · 2026-09-17 | Required `init.contrastMode` and page/query `is_archived` and `in_trash` fields |
20
+ | 5 [†](#protocol-5-unavailable-containing-page-context) | `0.2.16` · 2026-09-30 | `0.1.25` · 2026-10-02 | `0.1.79` · 2026-09-30 | Query filters and sorts must address actual database properties. Filter and sort payloads reject extra fields |
21
+ | 6 [‡](#protocol-6-richer-fallback-properties) | `0.3.0` · 2026-10-26 | `0.2.21` · 2026-10-22 | `0.1.105` · 2026-10-22 | Typed, display-name-keyed query properties and unified page responses replace the older query representation |
22
+ | 7 | `0.3.3` · 2026-10-30 | `0.3.11` · 2026-10-30 | `0.1.115` · 2026-10-30 | Typed text fallback properties for unique ID, button, formula, location, rollup, and verification |
23
+ | 8 | `0.3.4` · 2026-11-03 | `0.4.0` · 2026-11-02 | `0.1.116` · 2026-11-05 | Local manifests move from `/manifest` to HTML metadata sent in `connect`; `manifestSource` selects the initialization manifest |
24
+ | 9 | — | `0.6.0` · 2026-11-05 | — | Native page icons; older protocols receive external SVG URLs |
25
+ | 10 | `0.4.0` · 2026-11-11 | `0.7.0` · 2026-11-10 | `0.2.0` · 2026-11-10 | Removes `last_visited_time` from property schemas, page properties, and page metadata |
26
+ | 11 | `0.5.0` · 2026-11-13 | `0.10.0` · 2026-11-13 | `0.3.1` · 2026-11-13 | Removes `location` from manifests, binding schemas, and page properties; renames data source binding fields |
27
+
28
+ `—` means no release in that package line carried that specific protocol version.
29
+
30
+ Host compatibility depends on `connect.bridgeProtocolVersion`, not the SDK package version.
31
+
32
+ Native host package pins and protocol mappings are tracked separately in
33
+ [Notion's native host configuration](https://github.com/makenotion/notion-next/blob/main/src/cli/mobile/codegen/customBlockHost/config.ts)
34
+ and
35
+ [mobile shell registry](https://github.com/makenotion/notion-next/blob/main/src/cloudflare-customBlockWorker/lib/mobileShellRegistry.ts).
36
+
37
+ ## Protocol 11: location removal and data source binding names
38
+
39
+ Current bindings use `dataSourceSchema` and `dataSourcePointer` in `init` and `dataSourcesChanged`.
40
+ Current SDK types and host APIs use the same names. The host encodes `collectionSchema` and
41
+ `collectionPointer` for supported protocols 3–10 only at its outgoing boundary. Protocols 3–4 still
42
+ receive synthetic metadata schemas there.
43
+
44
+ Publish and deploy the updated host before adopting the new SDK. Native host generation and mobile
45
+ shell registration must use the published release; the planned releases are SDK 0.5.0, host 0.10.0,
46
+ and dev shell 0.3.1.
47
+
48
+ `location` represents the source of an item in Notion's aggregated views. Protocol 11 removes it
49
+ from manifests, binding schemas, and page property values. Updated hosts omit it for every supported
50
+ protocol version. Existing blocks that declare it in a manifest must remove that declaration and
51
+ rebuild. Older SDKs can still connect with manifests that use supported property types.
28
52
 
29
53
  ## Protocol 10: remove last visited time
30
54
 
@@ -79,7 +103,7 @@ describes current compatibility behavior.
79
103
  ### Protocol 6: richer fallback properties
80
104
 
81
105
  The protocol version changed in code on October 22, 2026. On October 26, the `pages` and
82
- `dataSources` APIs adopted a shared page representation: data-source query rows and page operation
106
+ `dataSources` APIs adopted a shared page representation: data source query rows and page operation
83
107
  results use the same page shape, with typed properties keyed by display name.
84
108
 
85
109
  Some SDKs added text fallback property objects for unique ID, button, formula, location, rollup, and
@@ -34,7 +34,7 @@ sends `connect.error` with `manifest_invalid`.
34
34
  The embedding application selects the manifest source. In host mode, the host uses its persisted
35
35
  manifest and ignores the sandbox declaration. In sandbox mode, the host uses `connect.manifest` from
36
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
37
+ manifest is authoritative and is returned in `init` with context and data source bindings. Errors
38
38
  from the selected manifest source pass through unchanged. Host mode can initialize after a sandbox
39
39
  `manifest_invalid` error using its own manifest; other connect errors remain fatal. The connect
40
40
  parser discards unknown properties.
@@ -126,9 +126,9 @@ for `code`, including unknown codes. TypeScript aliases list known codes for aut
126
126
  ### Bindings and IDs
127
127
 
128
128
  Hosts send `BridgeDataSourceBindings` as `dataSources: { bindings }`, keyed by the semantic data
129
- source key declared in the manifest. `collectionSchema` contains only actual database properties.
129
+ source key declared in the manifest. `dataSourceSchema` contains only actual database properties.
130
130
 
131
- Sandbox-to-host object references are raw IDs. The SDK resolves semantic data-source and property
131
+ Sandbox-to-host object references are raw IDs. The SDK resolves semantic data source and property
132
132
  keys before sending query or page-operation requests. Get and update requests can carry an optional
133
133
  resolved `dataSourceId`.
134
134
 
@@ -139,23 +139,22 @@ without sending a message.
139
139
 
140
140
  ### Query requests
141
141
 
142
+ `queryDataSource.archive_status` accepts `active`, `archived`, or `all`. It defaults to `active`.
143
+
142
144
  `queryDataSource` may include a resolved `filter` and an ordered `sorts` list. Each sort contains a
143
145
  raw `propertyId` and an `ascending` or `descending` direction. Hosts apply sorts in array order. The
144
146
  SDK and host validate that the list contains at most ten unique properties. The host rejects
145
147
  property types without a supported sort value.
146
148
 
147
- Every filter and sort property ID must exist in `collectionSchema.propertiesById`. Queries with
149
+ Every filter and sort property ID must exist in `dataSourceSchema.propertiesById`. Queries with
148
150
  filters or sorts return `data_source_schema_unavailable` when the schema is unavailable. Filter
149
151
  branches, operators, person references, and sort objects reject extra fields.
150
152
 
151
- #### Creator and status filters
152
-
153
- Creator filters require `propertyId` to identify an actual database property of type `created_by`.
154
- The `created_by` filter branch selects the property type, while `propertyId` addresses the column.
153
+ #### Creator, editor, and status filters
155
154
 
156
- The `created_by` filter supports human user targets with `contains` and `does_not_contain`, plus
157
- `is_empty` and `is_not_empty`. Hosts use row creator metadata, including non-human and missing
158
- creators in exclusion results.
155
+ `created_by` and `last_edited_by` use People operators. Group operands match exact identities, not
156
+ members of the group. Bot actors count as present for empty checks. Older hosts reject
157
+ `last_edited_by` and group operands in `created_by` filters.
159
158
 
160
159
  Status filters support option operators and stored group names. Group operators accept one name or
161
160
  an array of 1–5 names. Hosts must validate each name against the bound Status property.
@@ -183,21 +182,23 @@ filter: {
183
182
  }
184
183
  ```
185
184
 
186
- ## Capabilities
185
+ `created_time` and `last_edited_time` use Date operators without `target`: timestamps have no end
186
+ date.
187
+
188
+ ## Grants
187
189
 
188
- `manifest.capabilities` lists `{ capability, resource }` declarations. `capability` is an open
189
- string and `resource` is an open string or a non-empty array of them, so a newer vocabulary never
190
- makes an older receiver reject a manifest. An array declares the capability on each element.
191
- Receivers never split a resource string on commas. An omitted `capabilities` marks a block that
192
- predates approval.
190
+ `manifest.grants` lists `{ action, resource }` declarations. `action` is an open string and
191
+ `resource` is an open string or a non-empty array of them, so a newer vocabulary never makes an
192
+ older receiver reject a manifest. An array applies the action to each element. Receivers never split
193
+ a resource string on commas. An omitted `grants` marks a block that predates approval.
193
194
 
194
- Page capability resources can name one manifest data source as `data_source:<key>`. The key is the
195
+ Resources for page actions can name one manifest data source as `data_source:<key>`. The key is the
195
196
  semantic key from `manifest.dataSources`; hosts resolve it to the bound data source when they record
196
197
  and check grants. Bare `data_source` covers every declared key.
197
198
 
198
- The `capability_not_granted` error code is reserved for a request that the viewer's grants do not
199
- cover, with `isRetryable: false`. No adapter sends it yet, and no receiver restricts requests by
200
- capability. The SDK's capabilities guide documents the vocabulary.
199
+ The `not_granted` error code is reserved for a request that the viewer's grants do not cover, with
200
+ `isRetryable: false`. No adapter sends it yet, and no receiver restricts requests by grant. The
201
+ SDK's grants guide documents the vocabulary.
201
202
 
202
203
  ## Page context
203
204
 
@@ -219,9 +220,9 @@ names as keys and typed values that include their raw property IDs. Only actual
219
220
  are returned. Query results contain `items` and `hasMore`. `bridgePageSchema` defines the page
220
221
  fields, including archive state and creation, edit, and visit metadata.
221
222
 
222
- Page reads return string values for `unique_id`, `formula`, `rollup`, `button`, `verification`, and
223
- `location`, preserving each property's type. These properties are read-only. Values use stored text,
224
- or `""` when absent. Hosts do not evaluate formulas or rollups.
223
+ Page reads return string values for `unique_id`, `formula`, `rollup`, `button`, and `verification`,
224
+ preserving each property's type. These properties are read-only. Values use stored text, or `""`
225
+ when absent. Hosts do not evaluate formulas or rollups.
225
226
 
226
227
  The host converts responses to the sandbox's declared protocol. See
227
228
  [versioning and compatibility](versioning.md) for protocol version rules. The host's
@@ -77,10 +77,12 @@ property keys to property IDs before it sends the query. Empty values stay last
77
77
  Date-only and zone-less datetime values sort using UTC. Datetime values with a `time_zone` use that
78
78
  named zone, and an explicit offset in `start_time` wins.
79
79
 
80
- People and Created by sorts use record IDs as mock display names. People sorts preserve pointer
81
- order and remove duplicates. Groups use their composite group and workspace IDs. Created by sorts
82
- read row metadata. The dev shell uses `en-US` collation. Notion uses resolved display names and the
83
- user’s locale.
80
+ Created time and Last edited time values accept ISO timestamp strings or the sample `date` shapes
81
+ above.
82
+
83
+ People, Created by, and Last edited by sorts use record IDs as mock display names. People sorts
84
+ preserve pointer order and remove duplicates. Groups use their composite group and workspace IDs.
85
+ The dev shell uses `en-US` collation. Notion uses resolved display names and the user’s locale.
84
86
 
85
87
  Status group filters use each Status property's `options` and `groups`. Group `option_ids` must
86
88
  reference option IDs from the same property.
@@ -5,16 +5,23 @@ 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.
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.
9
11
 
10
12
  For configuration and lifecycle details, see [Initialization and lifecycle](docs/lifecycle.md).
11
13
 
14
+ For platform handlers, signal-based live queries, and explicit partial implementations, see the
15
+ [Host contract](docs/host-contract.md). The host accepts `CustomBlockHostOptions`.
16
+
12
17
  Use `BridgeParent` from `@notionhq/custom-blocks-host/protocol` to construct parent references with
13
18
  plain string IDs. The host validates the parent before sending it to the block.
14
19
 
15
- Implement `CustomBlockHostHandlers` to connect the host to your application. Handlers return shared
16
- bridge data using `CustomBlockHostResult`. Use `makeBridgePage` to construct a complete `BridgePage`
17
- from your records. See [Return bridge data](docs/handlers.md#return-bridge-data).
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
+ request context. Handlers return shared bridge data using `CustomBlockHostHandlerResult`. Use
23
+ `makeBridgePage` to construct a complete `BridgePage` from your records. See
24
+ [Return bridge data](docs/handlers.md#return-bridge-data).
18
25
 
19
26
  ## Create a host
20
27
 
@@ -26,7 +33,7 @@ This example embeds a block with no data sources and supplies fixed demo context
26
33
  than the embedding application.
27
34
 
28
35
  ```ts
29
- import { createCustomBlockHost } from "@notionhq/custom-blocks-host"
36
+ import { createCustomBlockHost, hostHandlerNotImplemented } from "@notionhq/custom-blocks-host"
30
37
 
31
38
  function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
32
39
  if (
@@ -56,46 +63,46 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
56
63
 
57
64
  const host = createCustomBlockHost({
58
65
  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
+ }),
76
+ theme: "light",
77
+ contrastMode: "standard",
78
+ containingPage: {
79
+ type: "page",
80
+ id: "22222222-2222-4222-8222-222222222222",
81
+ parent: { type: "workspace", workspace: true },
82
+ },
83
+ parent: {
84
+ type: "page_id",
85
+ page_id: "22222222-2222-4222-8222-222222222222",
86
+ },
59
87
  sandboxUrl: blockUrl.href,
60
88
  manifestSource: "host",
61
89
  getPersistedManifest: async () => ({
62
90
  status: "success",
63
91
  manifest: { version: 1, dataSources: {} },
64
92
  }),
65
- prepareInitialState: async () => ({
66
- status: "success",
67
- initialState: {
68
- theme: "light",
69
- contrastMode: "standard",
70
- blockId: "11111111-1111-4111-8111-111111111111",
71
- parent: {
72
- type: "page_id",
73
- page_id: "22222222-2222-4222-8222-222222222222",
74
- },
75
- page: {
76
- type: "page",
77
- id: "22222222-2222-4222-8222-222222222222",
78
- parent: { type: "workspace", workspace: true },
79
- },
80
- currentUser: {
81
- object: "user",
82
- id: "33333333-3333-4333-8333-333333333333",
83
- name: "Demo viewer",
84
- avatar_url: null,
85
- type: "person",
86
- person: { email: "viewer@example.com" },
87
- },
88
- dataSources: { bindings: {} },
89
- },
90
- }),
93
+ bindings: { pages: {}, dataSources: {} },
91
94
  handlers: {
92
- queryDataSource: () => ({
95
+ getDataSource: async () => ({ status: "success", state: { status: "unavailable" } }),
96
+ subscribeToQuery: ({ onError }) => onError(hostHandlerNotImplemented("subscribeToQuery")),
97
+ getPage: async () => ({ status: "error", error: hostHandlerNotImplemented("getPage") }),
98
+ createPage: async () => ({ status: "error", error: hostHandlerNotImplemented("createPage") }),
99
+ updatePage: async () => ({ status: "error", error: hostHandlerNotImplemented("updatePage") }),
100
+ getUser: async () => ({ status: "error", error: hostHandlerNotImplemented("getUser") }),
101
+ listUsers: async () => ({ status: "error", error: hostHandlerNotImplemented("listUsers") }),
102
+ openPage: async () => ({ status: "error", error: hostHandlerNotImplemented("openPage") }),
103
+ openExternalUrl: async () => ({
93
104
  status: "error",
94
- error: {
95
- code: "unknown_data_source_key",
96
- message: "This demo has no data sources.",
97
- isRetryable: false,
98
- },
105
+ error: hostHandlerNotImplemented("openExternalUrl"),
99
106
  }),
100
107
  resize: message => setHeight(message.height),
101
108
  },
@@ -110,7 +117,6 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
110
117
  status.textContent = `Block failed: ${state.error.code}`
111
118
  }
112
119
  },
113
- onQueryUnsubscribed: undefined,
114
120
  })
115
121
 
116
122
  // The host must listen before the block starts its handshake.
@@ -133,6 +139,12 @@ pixels.
133
139
  Call `dispose()` when your application removes the embed. To retry a failed connection or change the
134
140
  block URL, dispose of the current embed and call `mountCustomBlock()` again.
135
141
 
142
+ 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.
147
+
136
148
  For a production integration, replace the demo context and manifest with your application's values.
137
149
  Supply data-source bindings and handlers for the APIs your block uses. Your application must enforce
138
150
  permissions and record access.
@@ -173,7 +185,7 @@ import {
173
185
  `LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest bridge protocol version defined by the
174
186
  bundled protocol.
175
187
 
176
- Host APIs, configuration, handler results, and `*MessageInput` types are available from
188
+ Host APIs, configuration, handler results, and domain argument types are available from
177
189
  `@notionhq/custom-blocks-host`.
178
190
 
179
191
  These schemas validate wire payloads. Your application still enforces permissions.
@@ -185,9 +197,9 @@ additional modules, such as under an exact-URL Content Security Policy.
185
197
 
186
198
  ### Native page icons
187
199
 
188
- `CustomBlockHostPageIcon` accepts canonical native icon names from adapters. Adapters validate names
189
- and colors before writing. The runtime validates response payloads.
200
+ `CustomBlockHostPageIcon` accepts canonical native icon names from hosts. Hosts validate names and
201
+ colors before writing. The runtime validates response payloads.
190
202
 
191
- Adapters must check URL-backed icon and cover writes against the block's network permissions before
203
+ Hosts must check URL-backed icon and cover writes against the block's network permissions before
192
204
  mutating records. Notion permits the submitted HTTPS destination only when its origin is
193
205
  allowlisted; that origin is trusted to redirect.
@@ -16,7 +16,7 @@ does not guarantee that future features work.
16
16
 
17
17
  `sdkVersion` is analytics metadata. Compatibility behavior depends on the protocol version.
18
18
 
19
- The current SDK declares protocol 10. The shared runtime minimum is 3. The dev shell uses the Worker
19
+ The current SDK declares protocol 11. The shared runtime minimum is 3. The dev shell uses the Worker
20
20
  manifest in host mode and accepts the shared runtime's supported protocol versions. Protocols 7 and
21
21
  8 use the same page and query response formats. Protocol 8's local manifest declaration is selected
22
22
  only in sandbox mode; host mode uses the persisted manifest. See the
@@ -74,3 +74,13 @@ objects carry these fields at the top level. Protocol 3–5 query adapters copy
74
74
 
75
75
  Filters and sorts require actual database properties in the bound schema. The host does not support
76
76
  queries against synthetic metadata IDs without corresponding database properties.
77
+
78
+ ## Data source binding names
79
+
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.
@@ -2,8 +2,8 @@
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, a
6
- data-source example, refreshes, and external navigation.
5
+ permissions and implements the requested operations. This guide covers handler contracts,
6
+ data-source setup, updates, and external navigation.
7
7
 
8
8
  The [dev shell](https://www.npmjs.com/package/@notionhq/custom-blocks-dev-shell) is a working host
9
9
  implementation with local sample data. Use it as a reference for a larger integration. Production
@@ -11,8 +11,11 @@ hosts must provide their own permissions, data access, and persistence.
11
11
 
12
12
  ## Handler contracts
13
13
 
14
- `queryDataSource` is required. Other handlers are optional. A handler returns a result synchronously
15
- or as a promise. Errors carry `{ code, message, isRetryable }`, with open string codes.
14
+ Every `CustomBlockHostHandlers` method is required. Use `hostHandlerNotImplemented()` in explicit
15
+ wrappers for the
16
+ [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
18
+ string codes.
16
19
 
17
20
  ### Return bridge data
18
21
 
@@ -23,151 +26,41 @@ The host validates result shapes, matches responses to requests, and converts re
23
26
  block's protocol version. Your application checks that records exist and that the viewer may perform
24
27
  the requested operation.
25
28
 
26
- Query filters and sorts are validated against the actual bound database schema before
27
- `queryDataSource` runs. See the [wire reference](../../bridge/protocol.md#data-sources) for
29
+ The runtime validates query filters and sorts against the bound data-source schema before
30
+ `subscribeToQuery` runs. See the [wire reference](../../bridge/protocol.md#data-sources) for
28
31
  query semantics.
29
32
 
30
- For one-shot requests, a missing handler returns `unsupported_operation`. A handler that throws,
31
- rejects, or returns a malformed result produces `unknown_error`. Exception details go to `onLog`;
32
- the sandbox receives a generic error. Specific errors returned by handlers pass through unchanged.
33
+ 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
35
+ errors returned by handlers pass through unchanged.
33
36
 
34
37
  ## Connect a data source
35
38
 
36
- Connect an embedded block to an in-memory Tasks data source with one numeric Estimate property. This
37
- walkthrough extends the [README's embed example](../README.md#create-a-host): declare the data
38
- source, bind its keys to IDs, return a query result, and refresh that result after a value changes.
39
-
40
- Keep the iframe, context, and lifecycle callbacks from the embed example. The block must declare the
41
- same manifest and query `tasks` through the SDK's public APIs.
42
-
43
- ### Declare and bind the data source
44
-
45
- The manifest uses block-defined keys. Bindings connect those keys to actual data-source and property
46
- IDs. Add these definitions before creating the host:
47
-
48
- ```ts
49
- import type {
50
- CustomBlockHostDataSourcesPayload,
51
- CustomBlockHostHandlers,
52
- } from "@notionhq/custom-blocks-host"
53
- import {
54
- makeBridgePage,
55
- type BridgeCustomBlockManifest,
56
- type BridgePage,
57
- } from "@notionhq/custom-blocks-host/protocol"
58
-
59
- const tasksId = "44444444-4444-4444-8444-444444444444"
60
-
61
- const manifest: BridgeCustomBlockManifest = {
62
- version: 1,
63
- dataSources: {
64
- tasks: {
65
- name: "Tasks",
66
- properties: {
67
- estimate: { name: "Estimate", type: "number" },
68
- },
69
- },
70
- },
71
- }
72
-
73
- const taskBindings: CustomBlockHostDataSourcesPayload = {
74
- bindings: {
75
- tasks: {
76
- collectionPointer: { table: "collection", id: tasksId },
77
- collectionSchema: {
78
- propertiesById: {
79
- "estimate-id": { name: "Estimate", type: "number" },
80
- },
81
- },
82
- propertyIdsByKey: { estimate: "estimate-id" },
83
- },
84
- },
85
- }
86
- ```
87
-
88
- In the embed example, return `{ status: "success", manifest }` from `getPersistedManifest` and
89
- replace `initialState.dataSources` with `taskBindings`. Here, `tasks` and `estimate` are semantic
90
- keys; `tasksId` and `estimate-id` identify the bound data source and property.
91
-
92
- ### Return query results
93
-
94
- Add this handler and use it as the embed example's `handlers.queryDataSource`. Keep its existing
95
- `resize` handler.
96
-
97
- ```ts
98
- let estimate = 3
99
-
100
- const handlers: CustomBlockHostHandlers = {
101
- queryDataSource: message => {
102
- if (message.dataSourceId !== tasksId) {
103
- return {
104
- status: "error",
105
- error: {
106
- code: "unmapped_data_source",
107
- message: "This data source is not available.",
108
- isRetryable: false,
109
- },
110
- }
111
- }
112
-
113
- if (message.filter || message.sorts?.length) {
114
- return {
115
- status: "error",
116
- error: {
117
- code: "invalid_data_source_query",
118
- message: "This demo supports only unfiltered, unsorted queries.",
119
- isRetryable: false,
120
- },
121
- }
122
- }
123
-
124
- const items: BridgePage[] = [
125
- makeBridgePage({
126
- id: "55555555-5555-4555-8555-555555555555",
127
- parent: { type: "data_source_id", data_source_id: tasksId },
128
- is_archived: false,
129
- in_trash: false,
130
- properties: {
131
- Estimate: { id: "estimate-id", type: "number", number: estimate },
132
- },
133
- }),
134
- ]
135
-
136
- return {
137
- status: "success",
138
- items: items.slice(0, message.limit),
139
- hasMore: items.length > message.limit,
140
- }
141
- },
142
- }
143
- ```
144
-
145
- The SDK resolves `tasks` to `tasksId` before the host receives the request. Result properties use
146
- display names as keys (`Estimate`) and include their raw property IDs (`estimate-id`). The runtime
147
- handles subscription IDs, validates results, and converts them for supported older SDKs.
148
-
149
- This demo rejects filters and sorts rather than silently ignoring them. A production adapter must
150
- enforce record access, execute the requested filter and sorts, and honor the result limit. See
151
- [query semantics](../../bridge/protocol.md#data-sources).
39
+ To extend the [embed example](../README.md#create-a-host) with a data source, add its manifest
40
+ declaration, bindings, metadata handler, and query handler. The block uses the same declaration and
41
+ queries the source through the SDK's public APIs.
152
42
 
153
- ## Refresh active queries
43
+ Declare `tasks` and its property keys in the manifest. Supply their IDs in `bindings.dataSources`,
44
+ and return the schema from `getDataSource({ dataSourceId, signal })`. Missing resources and denied
45
+ access both return `{ status: "success", state: { status: "unavailable" } }`. Binding failures
46
+ return an error. See [metadata and configuration](host-contract.md#metadata-and-configuration).
154
47
 
155
- After creating the host, update the in-memory value and notify active subscriptions:
48
+ `subscribeToQuery` receives the source ID, query options, limit, signal, and callbacks described in
49
+ [queries and cancellation](host-contract.md#queries-and-cancellation). Enforce record access, apply
50
+ 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.
156
53
 
157
- ```ts
158
- estimate = 5
159
- host.refreshQuery({ dataSourceId: tasksId })
160
- ```
54
+ ## Refresh active queries
161
55
 
162
- If the block has an active query for Tasks, its next result contains an estimate of `5`. A query
163
- started later also reads the updated value. The application triggers refreshes when its underlying
164
- data changes; the runtime re-runs matching subscriptions. Call `host.stop()` when removing the
165
- embed.
56
+ The platform observer calls `onSnapshot` again when rows change. Release the observer and cancel
57
+ pending setup when the subscription signal aborts. The shared host handles subscription IDs,
58
+ replacement, unsubscribe, and shutdown. Do not return a second cleanup callback.
166
59
 
167
- `refreshQuery()` re-runs active subscriptions for the supplied data-source ID with their existing
168
- filter, sorts, and limit. Overlapping refreshes queue one follow-up query. The running query
169
- delivers its result first. Unsubscribe, replacement, and stop discard queued work and suppress late
170
- results. Non-retryable query errors end subscriptions. Retryable errors retain them.
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).
171
64
 
172
65
  ## Page and user operations
173
66
 
@@ -182,9 +75,9 @@ CSS pixels. The application owns navigation and iframe sizing.
182
75
  ## External navigation
183
76
 
184
77
  `openExternalUrl` receives an `AbortSignal` and an absolute HTTP or HTTPS URL without credentials.
185
- The URL is limited to 2,048 JavaScript code units before and after normalization. The adapter
186
- displays the exact URL, obtains approval, and navigates only after approval. It may apply further
187
- restrictions. Dismiss pending confirmation UI when the signal aborts.
78
+ The URL is limited to 2,048 JavaScript code units before and after normalization. The host
79
+ implementation displays the exact URL, obtains approval, and navigates only after approval. It may
80
+ apply further restrictions. Dismiss pending confirmation UI when the signal aborts.
188
81
 
189
82
  Each iframe permits one pending navigation. A different request receives `pending_navigation`. A
190
83
  duplicate of the active request is ignored. Completed requests are forgotten, so later requests
@@ -205,6 +98,6 @@ properties, the manifest property stays unmapped.
205
98
  `toNotionDateValue()` converts `NotionDateInput` into the four `CustomBlockDateValue` variants,
206
99
  including reminders. Invalid input throws `InvalidNotionDateError`.
207
100
 
208
- The root exports host configuration, handlers, results, and `*MessageInput` types. Wire schemas,
101
+ The root exports host configuration, handlers, results, and domain argument types. Wire schemas,
209
102
  message and page types, and constants such as `LATEST_BRIDGE_PROTOCOL_VERSION` use the
210
103
  [protocol subpath](../README.md#protocol-schemas-and-types).