@notionhq/custom-blocks-dev-shell 0.1.116 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/assets/index-CWJ-vFk0.js +12 -0
- package/dist/index.html +1 -1
- package/dist-cli/cli/published-cli.js +271 -111
- package/docs/bridge/changelog.md +28 -1
- package/docs/bridge/protocol.md +51 -15
- package/docs/bridge/versioning.md +1 -0
- package/docs/data-sources.md +6 -4
- package/docs/host/README.md +64 -36
- package/docs/host/docs/compatibility.md +15 -7
- package/docs/host/docs/handlers.md +45 -141
- package/docs/host/docs/host-contract.md +196 -0
- package/docs/host/docs/lifecycle.md +28 -23
- package/package.json +1 -1
- package/dist/assets/index-DSaseWP_.js +0 -11
package/docs/bridge/changelog.md
CHANGED
|
@@ -19,11 +19,31 @@ versions refer to `@notionhq/custom-blocks`.
|
|
|
19
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
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
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
|
|
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 |
|
|
23
25
|
|
|
24
26
|
The table lists SDK release boundaries, not complete supported version ranges. Host compatibility
|
|
25
27
|
depends on `connect.bridgeProtocolVersion`, not the SDK package version.
|
|
26
28
|
|
|
29
|
+
## Protocol 10: remove last visited time
|
|
30
|
+
|
|
31
|
+
`last_visited_time` is viewer-specific recents data, not a database property type. Protocol 10
|
|
32
|
+
removes it from manifests, binding schemas, page property values, and top-level page metadata. Older
|
|
33
|
+
SDKs can still connect, but updated hosts no longer load or return viewer visit data. Older readers
|
|
34
|
+
default the absent page field to `null`. Blocks that use this field must remove that use and
|
|
35
|
+
rebuild.
|
|
36
|
+
|
|
37
|
+
## Protocol 9: native page icons
|
|
38
|
+
|
|
39
|
+
Page operations and query results can return `{ type: "icon", icon: { name, color } }`. Reads and
|
|
40
|
+
writes share a loose shape: names and colors accept strings, color is optional, and additional
|
|
41
|
+
native icon fields are retained. Hosts resolve names and default omitted colors to gray.
|
|
42
|
+
|
|
43
|
+
Protocols 3–8 receive external SVG URLs in page operation results. Protocols 6–8 receive the same
|
|
44
|
+
fallback in query results; protocols 3–5 keep their flat query format without appearance fields. The
|
|
45
|
+
released-SDK compatibility corpus exercises these conversions.
|
|
46
|
+
|
|
27
47
|
## Protocol 8: local manifest declarations
|
|
28
48
|
|
|
29
49
|
The dev shell removes the `/manifest` route and embeds the local manifest in block HTML. The SDK
|
|
@@ -41,6 +61,13 @@ from `connect`.
|
|
|
41
61
|
|
|
42
62
|
## Changes within a declared version
|
|
43
63
|
|
|
64
|
+
### Protocol 8: correlated request rejections
|
|
65
|
+
|
|
66
|
+
Bridge NACKs (`invalidHostMessage` and `invalidSandboxMessage`) gain an optional string `requestId`.
|
|
67
|
+
Updated SDKs complete the matching request immediately when a rejection can be correlated. Older
|
|
68
|
+
readers ignore the additional field; updated readers continue to accept NACKs without an ID.
|
|
69
|
+
Uncorrelated requests use the SDK's 60-second timeout. This additive change retains protocol 8.
|
|
70
|
+
|
|
44
71
|
### Protocol 5: unavailable containing-page context
|
|
45
72
|
|
|
46
73
|
On October 2, 2026, SDK 0.2.17 added `{ type: "unavailable" }` to containing-page context while
|
package/docs/bridge/protocol.md
CHANGED
|
@@ -62,7 +62,9 @@ a different origin from its embedding page.
|
|
|
62
62
|
- `queryDataSource` is a long-lived subscription; requests and every update use its stable
|
|
63
63
|
`subscriptionId`.
|
|
64
64
|
- The initialization lifecycle uses `initializationId`, not `requestId` or `subscriptionId`.
|
|
65
|
-
- One-way messages, such as `resize
|
|
65
|
+
- One-way messages, such as `resize`, have no correlation ID.
|
|
66
|
+
- Bridge NACKs include the rejected message's `requestId` when it is a string. The ID identifies the
|
|
67
|
+
original request, including when the rejected message is its response.
|
|
66
68
|
|
|
67
69
|
Hosts key query state by `subscriptionId`, replace state when a request reuses one, and suppress
|
|
68
70
|
stale asynchronous results.
|
|
@@ -82,6 +84,22 @@ On parse failure, the host replies with `invalidSandboxMessage` and the sandbox
|
|
|
82
84
|
`invalidHostMessage`, except for the handshake cases below. These replies are negative
|
|
83
85
|
acknowledgments (NACKs). Receivers do not NACK another NACK.
|
|
84
86
|
|
|
87
|
+
A sandbox request with a `requestId` expects a terminal result or correlated rejection. On parse
|
|
88
|
+
failure, read `requestId` separately from the invalid payload. The host includes a readable string
|
|
89
|
+
ID in `invalidSandboxMessage`, even for an unknown request type. The SDK completes the matching
|
|
90
|
+
request with `invalid_sandbox_message`. When the SDK rejects a host response, it completes the
|
|
91
|
+
matching request locally with `invalid_host_message` and includes the ID in `invalidHostMessage`.
|
|
92
|
+
Both errors have `isRetryable: false`.
|
|
93
|
+
|
|
94
|
+
One-shot SDK requests time out after 60 seconds. Missing, unreadable, or unknown IDs do not fail
|
|
95
|
+
unrelated requests. NACK IDs are optional: older readers ignore them, and newer readers accept
|
|
96
|
+
legacy NACKs without IDs. Those requests retain the timeout fallback.
|
|
97
|
+
|
|
98
|
+
Request completion clears its timer, removes the pending entry, and ignores duplicate or late
|
|
99
|
+
results. Disposing the SDK completes pending calls locally with `request_disposed` and clears their
|
|
100
|
+
timers. The SDK does not retry or cancel host work. A timed-out write may still complete; check its
|
|
101
|
+
resulting state before repeating it. Data source subscriptions use a separate lifecycle.
|
|
102
|
+
|
|
85
103
|
Malformed sandbox messages do not change the host's initialization state or timeout, except as
|
|
86
104
|
follows:
|
|
87
105
|
|
|
@@ -121,6 +139,8 @@ without sending a message.
|
|
|
121
139
|
|
|
122
140
|
### Query requests
|
|
123
141
|
|
|
142
|
+
`queryDataSource.archive_status` accepts `active`, `archived`, or `all`. It defaults to `active`.
|
|
143
|
+
|
|
124
144
|
`queryDataSource` may include a resolved `filter` and an ordered `sorts` list. Each sort contains a
|
|
125
145
|
raw `propertyId` and an `ascending` or `descending` direction. Hosts apply sorts in array order. The
|
|
126
146
|
SDK and host validate that the list contains at most ten unique properties. The host rejects
|
|
@@ -130,14 +150,11 @@ Every filter and sort property ID must exist in `collectionSchema.propertiesById
|
|
|
130
150
|
filters or sorts return `data_source_schema_unavailable` when the schema is unavailable. Filter
|
|
131
151
|
branches, operators, person references, and sort objects reject extra fields.
|
|
132
152
|
|
|
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.
|
|
153
|
+
#### Creator, editor, and status filters
|
|
137
154
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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.
|
|
141
158
|
|
|
142
159
|
Status filters support option operators and stored group names. Group operators accept one name or
|
|
143
160
|
an array of 1–5 names. Hosts must validate each name against the bound Status property.
|
|
@@ -165,15 +182,23 @@ filter: {
|
|
|
165
182
|
}
|
|
166
183
|
```
|
|
167
184
|
|
|
168
|
-
|
|
185
|
+
`created_time` and `last_edited_time` use Date operators without `target`: timestamps have no end
|
|
186
|
+
date.
|
|
169
187
|
|
|
170
|
-
|
|
171
|
-
so a newer vocabulary never makes an older receiver reject a manifest. An omitted `capabilities`
|
|
172
|
-
marks a block that predates approval.
|
|
188
|
+
## Grants
|
|
173
189
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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.
|
|
194
|
+
|
|
195
|
+
Resources for page actions can name one manifest data source as `data_source:<key>`. The key is the
|
|
196
|
+
semantic key from `manifest.dataSources`; hosts resolve it to the bound data source when they record
|
|
197
|
+
and check grants. Bare `data_source` covers every declared key.
|
|
198
|
+
|
|
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.
|
|
177
202
|
|
|
178
203
|
## Page context
|
|
179
204
|
|
|
@@ -202,3 +227,14 @@ or `""` when absent. Hosts do not evaluate formulas or rollups.
|
|
|
202
227
|
The host converts responses to the sandbox's declared protocol. See
|
|
203
228
|
[versioning and compatibility](versioning.md) for protocol version rules. The host's
|
|
204
229
|
[compatibility reference](../host/docs/compatibility.md) describes older response formats.
|
|
230
|
+
|
|
231
|
+
### Native page icon compatibility
|
|
232
|
+
|
|
233
|
+
Protocol 9 and later use native icon objects. Protocols 3–8 receive external SVG URLs in page
|
|
234
|
+
operation results. Unified query results in protocols 6–8 also use external SVG URLs; flat query
|
|
235
|
+
results in protocols 3–5 omit icon fields. Native colors accept any string in responses and write
|
|
236
|
+
inputs, so newer host colors do not require an SDK update.
|
|
237
|
+
|
|
238
|
+
`createPage` accepts native icons, emoji, custom emoji, and URL-backed icons and covers. The
|
|
239
|
+
application adapter checks submitted image URLs against the block's network permissions before
|
|
240
|
+
creating a page.
|
|
@@ -17,6 +17,7 @@ conversions.
|
|
|
17
17
|
|
|
18
18
|
`connect.bridgeProtocolVersion` selects the wire contract. `sdkVersion` is analytics metadata.
|
|
19
19
|
`LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest contract defined by the package.
|
|
20
|
+
`NATIVE_ICON_PROTOCOL_VERSION` is 9, the first protocol with native icon responses and writes.
|
|
20
21
|
|
|
21
22
|
## Protocol export names
|
|
22
23
|
|
package/docs/data-sources.md
CHANGED
|
@@ -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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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.
|
package/docs/host/README.md
CHANGED
|
@@ -5,10 +5,24 @@ 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
|
+
|
|
17
|
+
Use `BridgeParent` from `@notionhq/custom-blocks-host/protocol` to construct parent references with
|
|
18
|
+
plain string IDs. The host validates the parent before sending it to the block.
|
|
19
|
+
|
|
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).
|
|
25
|
+
|
|
12
26
|
## Create a host
|
|
13
27
|
|
|
14
28
|
Install `@notionhq/custom-blocks-host` in your embedding application. Run this TypeScript through
|
|
@@ -19,7 +33,7 @@ This example embeds a block with no data sources and supplies fixed demo context
|
|
|
19
33
|
than the embedding application.
|
|
20
34
|
|
|
21
35
|
```ts
|
|
22
|
-
import { createCustomBlockHost } from "@notionhq/custom-blocks-host"
|
|
36
|
+
import { createCustomBlockHost, hostHandlerNotImplemented } from "@notionhq/custom-blocks-host"
|
|
23
37
|
|
|
24
38
|
function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
|
|
25
39
|
if (
|
|
@@ -49,46 +63,46 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
|
|
|
49
63
|
|
|
50
64
|
const host = createCustomBlockHost({
|
|
51
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
|
+
},
|
|
52
87
|
sandboxUrl: blockUrl.href,
|
|
53
88
|
manifestSource: "host",
|
|
54
89
|
getPersistedManifest: async () => ({
|
|
55
90
|
status: "success",
|
|
56
91
|
manifest: { version: 1, dataSources: {} },
|
|
57
92
|
}),
|
|
58
|
-
|
|
59
|
-
status: "success",
|
|
60
|
-
initialState: {
|
|
61
|
-
theme: "light",
|
|
62
|
-
contrastMode: "standard",
|
|
63
|
-
blockId: "11111111-1111-4111-8111-111111111111",
|
|
64
|
-
parent: {
|
|
65
|
-
type: "page_id",
|
|
66
|
-
page_id: "22222222-2222-4222-8222-222222222222",
|
|
67
|
-
},
|
|
68
|
-
page: {
|
|
69
|
-
type: "page",
|
|
70
|
-
id: "22222222-2222-4222-8222-222222222222",
|
|
71
|
-
parent: { type: "workspace", workspace: true },
|
|
72
|
-
},
|
|
73
|
-
currentUser: {
|
|
74
|
-
object: "user",
|
|
75
|
-
id: "33333333-3333-4333-8333-333333333333",
|
|
76
|
-
name: "Demo viewer",
|
|
77
|
-
avatar_url: null,
|
|
78
|
-
type: "person",
|
|
79
|
-
person: { email: "viewer@example.com" },
|
|
80
|
-
},
|
|
81
|
-
dataSources: { bindings: {} },
|
|
82
|
-
},
|
|
83
|
-
}),
|
|
93
|
+
bindings: { pages: {}, dataSources: {} },
|
|
84
94
|
handlers: {
|
|
85
|
-
|
|
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 () => ({
|
|
86
104
|
status: "error",
|
|
87
|
-
error:
|
|
88
|
-
code: "unknown_data_source_key",
|
|
89
|
-
message: "This demo has no data sources.",
|
|
90
|
-
isRetryable: false,
|
|
91
|
-
},
|
|
105
|
+
error: hostHandlerNotImplemented("openExternalUrl"),
|
|
92
106
|
}),
|
|
93
107
|
resize: message => setHeight(message.height),
|
|
94
108
|
},
|
|
@@ -103,7 +117,6 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
|
|
|
103
117
|
status.textContent = `Block failed: ${state.error.code}`
|
|
104
118
|
}
|
|
105
119
|
},
|
|
106
|
-
onQueryUnsubscribed: undefined,
|
|
107
120
|
})
|
|
108
121
|
|
|
109
122
|
// The host must listen before the block starts its handshake.
|
|
@@ -126,6 +139,12 @@ pixels.
|
|
|
126
139
|
Call `dispose()` when your application removes the embed. To retry a failed connection or change the
|
|
127
140
|
block URL, dispose of the current embed and call `mountCustomBlock()` again.
|
|
128
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
|
+
|
|
129
148
|
For a production integration, replace the demo context and manifest with your application's values.
|
|
130
149
|
Supply data-source bindings and handlers for the APIs your block uses. Your application must enforce
|
|
131
150
|
permissions and record access.
|
|
@@ -166,7 +185,7 @@ import {
|
|
|
166
185
|
`LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest bridge protocol version defined by the
|
|
167
186
|
bundled protocol.
|
|
168
187
|
|
|
169
|
-
Host APIs, configuration, handler results, and
|
|
188
|
+
Host APIs, configuration, handler results, and domain argument types are available from
|
|
170
189
|
`@notionhq/custom-blocks-host`.
|
|
171
190
|
|
|
172
191
|
These schemas validate wire payloads. Your application still enforces permissions.
|
|
@@ -175,3 +194,12 @@ These schemas validate wire payloads. Your application still enforces permission
|
|
|
175
194
|
|
|
176
195
|
`dist/browser.js` is one ES module with all dependencies. Use it when the browser must not fetch
|
|
177
196
|
additional modules, such as under an exact-URL Content Security Policy.
|
|
197
|
+
|
|
198
|
+
### Native page icons
|
|
199
|
+
|
|
200
|
+
`CustomBlockHostPageIcon` accepts canonical native icon names from hosts. Hosts validate names and
|
|
201
|
+
colors before writing. The runtime validates response payloads.
|
|
202
|
+
|
|
203
|
+
Hosts must check URL-backed icon and cover writes against the block's network permissions before
|
|
204
|
+
mutating records. Notion permits the submitted HTTPS destination only when its origin is
|
|
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
|
|
19
|
+
The current SDK declares protocol 10. 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
|
|
@@ -35,12 +35,13 @@ through.
|
|
|
35
35
|
|
|
36
36
|
## Current compatibility behavior
|
|
37
37
|
|
|
38
|
-
| Target | Query results | Page operation results | Binding schemas |
|
|
39
|
-
| ------ | --------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
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 |
|
|
41
|
-
| 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 |
|
|
42
|
-
| 6 | Unified name-keyed properties. Text fallback property objects become `null` | Same unified page format | Actual database schemas |
|
|
43
|
-
| 7
|
|
38
|
+
| Target | Query results | Page operation results | Binding schemas | Native icons |
|
|
39
|
+
| ------ | --------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
|
|
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 |
|
|
41
|
+
| 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
|
+
| 6 | Unified name-keyed properties. Text fallback property objects become `null` | Same unified page format | Actual database schemas | External SVG URLs |
|
|
43
|
+
| 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 |
|
|
44
45
|
|
|
45
46
|
The synthetic metadata IDs are `created_time`, `last_edited_time`, `created_by`, and
|
|
46
47
|
`last_edited_by`. They retain metadata meaning if an actual property uses the same raw ID. This
|
|
@@ -52,6 +53,13 @@ Release-specific compatibility limits are documented in the changelog entries fo
|
|
|
52
53
|
and
|
|
53
54
|
[protocol 6 text fallback properties](../../bridge/changelog.md#protocol-6-richer-fallback-properties).
|
|
54
55
|
|
|
56
|
+
### Native page icons
|
|
57
|
+
|
|
58
|
+
Protocol 9 and later receive native icon objects. Protocols 3–8 receive external SVG URLs in page
|
|
59
|
+
operation results, and protocols 6–8 also receive them in query results. Protocols 3–5 use flat
|
|
60
|
+
query results without page appearance fields. Omitted native colors default to gray when producing
|
|
61
|
+
SVG URLs.
|
|
62
|
+
|
|
55
63
|
### Unavailable containing-page context
|
|
56
64
|
|
|
57
65
|
Protocols 3–4 receive `context_unavailable` during initialization or stop when containing-page
|
|
@@ -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,
|
|
6
|
-
data-source
|
|
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,152 +11,56 @@ hosts must provide their own permissions, data access, and persistence.
|
|
|
11
11
|
|
|
12
12
|
## Handler contracts
|
|
13
13
|
|
|
14
|
-
`
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
and `*MessageInput` types accept plain string IDs. The runtime validates these inputs and applies
|
|
20
|
-
schema defaults. ID brands do not check record existence or access.
|
|
20
|
+
### Return bridge data
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
Handlers return data in the bridge's shared types. Use bridge builders to construct complete objects
|
|
23
|
+
from application records.
|
|
24
|
+
|
|
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.
|
|
28
|
+
|
|
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
|
|
24
31
|
query semantics.
|
|
25
32
|
|
|
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.
|
|
36
|
+
|
|
26
37
|
## Connect a data source
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Keep the iframe, context, and lifecycle callbacks from the embed example. The block must declare the
|
|
33
|
-
same manifest and query `tasks` through the SDK's public APIs.
|
|
34
|
-
|
|
35
|
-
### Declare and bind the data source
|
|
36
|
-
|
|
37
|
-
The manifest uses block-defined keys. Bindings connect those keys to actual data-source and property
|
|
38
|
-
IDs. Add these definitions before creating the host:
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
import type {
|
|
42
|
-
CustomBlockHostDataSourcesPayload,
|
|
43
|
-
CustomBlockHostHandlers,
|
|
44
|
-
} from "@notionhq/custom-blocks-host"
|
|
45
|
-
import type { BridgeCustomBlockManifest, BridgePage } from "@notionhq/custom-blocks-host/protocol"
|
|
46
|
-
|
|
47
|
-
const tasksId = "44444444-4444-4444-8444-444444444444"
|
|
48
|
-
|
|
49
|
-
const manifest: BridgeCustomBlockManifest = {
|
|
50
|
-
version: 1,
|
|
51
|
-
dataSources: {
|
|
52
|
-
tasks: {
|
|
53
|
-
name: "Tasks",
|
|
54
|
-
properties: {
|
|
55
|
-
estimate: { name: "Estimate", type: "number" },
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const taskBindings: CustomBlockHostDataSourcesPayload = {
|
|
62
|
-
bindings: {
|
|
63
|
-
tasks: {
|
|
64
|
-
collectionPointer: { table: "collection", id: tasksId },
|
|
65
|
-
collectionSchema: {
|
|
66
|
-
propertiesById: {
|
|
67
|
-
"estimate-id": { name: "Estimate", type: "number" },
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
propertyIdsByKey: { estimate: "estimate-id" },
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
In the embed example, return `{ status: "success", manifest }` from `getPersistedManifest` and
|
|
77
|
-
replace `initialState.dataSources` with `taskBindings`. Here, `tasks` and `estimate` are semantic
|
|
78
|
-
keys; `tasksId` and `estimate-id` identify the bound data source and property.
|
|
79
|
-
|
|
80
|
-
### Return query results
|
|
81
|
-
|
|
82
|
-
Add this handler and use it as the embed example's `handlers.queryDataSource`. Keep its existing
|
|
83
|
-
`resize` handler.
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
let estimate = 3
|
|
87
|
-
|
|
88
|
-
const handlers: CustomBlockHostHandlers = {
|
|
89
|
-
queryDataSource: message => {
|
|
90
|
-
if (message.dataSourceId !== tasksId) {
|
|
91
|
-
return {
|
|
92
|
-
status: "error",
|
|
93
|
-
error: {
|
|
94
|
-
code: "unmapped_data_source",
|
|
95
|
-
message: "This data source is not available.",
|
|
96
|
-
isRetryable: false,
|
|
97
|
-
},
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (message.filter || message.sorts?.length) {
|
|
102
|
-
return {
|
|
103
|
-
status: "error",
|
|
104
|
-
error: {
|
|
105
|
-
code: "invalid_data_source_query",
|
|
106
|
-
message: "This demo supports only unfiltered, unsorted queries.",
|
|
107
|
-
isRetryable: false,
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const items: BridgePage[] = [
|
|
113
|
-
{
|
|
114
|
-
object: "page",
|
|
115
|
-
id: "55555555-5555-4555-8555-555555555555",
|
|
116
|
-
parent: { type: "data_source_id", data_source_id: tasksId },
|
|
117
|
-
is_archived: false,
|
|
118
|
-
in_trash: false,
|
|
119
|
-
properties: {
|
|
120
|
-
Estimate: { id: "estimate-id", type: "number", number: estimate },
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
]
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
status: "success",
|
|
127
|
-
items: items.slice(0, message.limit),
|
|
128
|
-
hasMore: items.length > message.limit,
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
The SDK resolves `tasks` to `tasksId` before the host receives the request. Result properties use
|
|
135
|
-
display names as keys (`Estimate`) and include their raw property IDs (`estimate-id`). The runtime
|
|
136
|
-
handles subscription IDs, validates results, and converts them for supported older SDKs.
|
|
137
|
-
|
|
138
|
-
This demo rejects filters and sorts rather than silently ignoring them. A production adapter must
|
|
139
|
-
enforce record access, execute the requested filter and sorts, and honor the result limit. See
|
|
140
|
-
[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.
|
|
141
42
|
|
|
142
|
-
|
|
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).
|
|
143
47
|
|
|
144
|
-
|
|
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.
|
|
145
53
|
|
|
146
|
-
|
|
147
|
-
estimate = 5
|
|
148
|
-
host.refreshQuery({ dataSourceId: tasksId })
|
|
149
|
-
```
|
|
54
|
+
## Refresh active queries
|
|
150
55
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
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.
|
|
155
59
|
|
|
156
|
-
`
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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).
|
|
160
64
|
|
|
161
65
|
## Page and user operations
|
|
162
66
|
|
|
@@ -171,9 +75,9 @@ CSS pixels. The application owns navigation and iframe sizing.
|
|
|
171
75
|
## External navigation
|
|
172
76
|
|
|
173
77
|
`openExternalUrl` receives an `AbortSignal` and an absolute HTTP or HTTPS URL without credentials.
|
|
174
|
-
The URL is limited to 2,048 JavaScript code units before and after normalization. The
|
|
175
|
-
displays the exact URL, obtains approval, and navigates only after approval. It may
|
|
176
|
-
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.
|
|
177
81
|
|
|
178
82
|
Each iframe permits one pending navigation. A different request receives `pending_navigation`. A
|
|
179
83
|
duplicate of the active request is ignored. Completed requests are forgotten, so later requests
|
|
@@ -194,6 +98,6 @@ properties, the manifest property stays unmapped.
|
|
|
194
98
|
`toNotionDateValue()` converts `NotionDateInput` into the four `CustomBlockDateValue` variants,
|
|
195
99
|
including reminders. Invalid input throws `InvalidNotionDateError`.
|
|
196
100
|
|
|
197
|
-
The root exports host configuration, handlers, results, and
|
|
101
|
+
The root exports host configuration, handlers, results, and domain argument types. Wire schemas,
|
|
198
102
|
message and page types, and constants such as `LATEST_BRIDGE_PROTOCOL_VERSION` use the
|
|
199
103
|
[protocol subpath](../README.md#protocol-schemas-and-types).
|