@notionhq/custom-blocks-dev-shell 0.3.0 → 0.4.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 +42 -18
- package/data/customers.json +286 -0
- package/data/meetings.json +519 -0
- package/data/people.json +171 -47
- package/data/projects.json +338 -0
- package/data/tasks.json +828 -38
- package/dist/assets/index-B4LAgGzW.css +2 -0
- package/dist/assets/index-CjUu48lJ.js +12 -0
- package/dist/index.html +3 -3
- package/dist-cli/cli/published-cli.js +1289 -764
- package/docs/bindings.md +16 -22
- package/docs/bridge/changelog.md +91 -28
- package/docs/bridge/protocol.md +157 -88
- package/docs/bridge/versioning.md +16 -4
- package/docs/data-sources.md +44 -31
- package/docs/host/README.md +26 -29
- package/docs/host/docs/compatibility.md +62 -24
- package/docs/host/docs/handlers.md +22 -15
- package/docs/host/docs/host-contract.md +72 -72
- package/docs/host/docs/lifecycle.md +64 -53
- package/package.json +1 -1
- package/data/radar.json +0 -87
- package/dist/assets/index-CWJ-vFk0.js +0 -12
- package/dist/assets/index-Do-x8yIt.css +0 -2
|
@@ -4,20 +4,27 @@ The SDK inside a block and the host in its embedding application release indepen
|
|
|
4
4
|
protocol version identifies the wire contract they use, independently of their package versions.
|
|
5
5
|
This reference defines the version identifiers, protocol format names, and rules for contract
|
|
6
6
|
changes. Release boundaries and exceptions are recorded in the [changelog](changelog.md). The host's
|
|
7
|
-
[
|
|
8
|
-
|
|
7
|
+
[connection reference](../host/docs/compatibility.md) describes negotiation and version
|
|
8
|
+
requirements.
|
|
9
9
|
|
|
10
10
|
## Version identifiers
|
|
11
11
|
|
|
12
|
-
- **
|
|
12
|
+
- **Protocol:** `connect.supportedProtocolVersions` lists the SDK's implemented contracts. The host
|
|
13
|
+
selects the highest version that both sides implement in `connectResult.protocolVersion`.
|
|
13
14
|
- **SDK package:** identifies the SDK's public API and implementation. It can change without a wire
|
|
14
15
|
change.
|
|
15
16
|
- **Host package:** identifies the runtime implementation. Publishing it does not deploy it to
|
|
16
17
|
Notion.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
The selected protocol version belongs to the connection. Protocol 12 `init` does not repeat it.
|
|
20
|
+
`sdkVersion` is analytics metadata. The
|
|
21
|
+
[connection reference](../host/docs/compatibility.md#supported-versions) describes the current
|
|
22
|
+
negotiation contract.
|
|
23
|
+
|
|
19
24
|
`LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest contract defined by the package.
|
|
20
25
|
`NATIVE_ICON_PROTOCOL_VERSION` is 9, the first protocol with native icon responses and writes.
|
|
26
|
+
`MINIMAL_INIT_PROTOCOL_VERSION` is 12, the first protocol with separate setup and render readiness,
|
|
27
|
+
location notifications after setup, and explicit current-user and source metadata reads.
|
|
21
28
|
|
|
22
29
|
## Protocol export names
|
|
23
30
|
|
|
@@ -35,5 +42,10 @@ required fields, and new response variants an older receiver rejects. Optional f
|
|
|
35
42
|
messages need no bump only when older receivers can safely ignore or NACK them. Parsing success
|
|
36
43
|
alone does not prove compatible SDK behavior.
|
|
37
44
|
|
|
45
|
+
Each advertised version requires a working schema, adapter, and compatibility tests. An SDK that
|
|
46
|
+
advertises `[13, 12]` must still implement protocol 12 when a host selects it. Optional fields must
|
|
47
|
+
remain safe for older readers to ignore. A receiver rejects unknown requests with a correlated NACK
|
|
48
|
+
when it can read their `requestId`.
|
|
49
|
+
|
|
38
50
|
An SDK that requires a newer protocol needs a host that supports that contract. Updating the SDK
|
|
39
51
|
package does not update the host in the embedding application.
|
package/docs/data-sources.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# Dev shell data sources
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
41
|
-
|
|
42
|
-
- `name
|
|
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
|
|
45
|
-
- `schema
|
|
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
|
-
|
|
50
|
-
|
|
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.
|
|
68
|
-
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
|
|
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`
|
|
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.
|
|
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
|
|
114
|
+
The shell lists only sources in `data/`.
|
|
103
115
|
|
|
104
|
-
##
|
|
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
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
|
package/docs/host/README.md
CHANGED
|
@@ -6,19 +6,19 @@ owns the iframe, permissions, data access, persistence, analytics, and UI. Block
|
|
|
6
6
|
|
|
7
7
|
Create the host before navigating the iframe. Pass the full block URL as `sandboxUrl`, and call
|
|
8
8
|
`stop()` when removing the iframe. A host instance belongs to the required `viewerId`. Supply one
|
|
9
|
-
asynchronous `getCurrentUser` profile reader
|
|
9
|
+
asynchronous `getCurrentUser` profile reader. Its returned ID must match that viewer. Create a fresh
|
|
10
10
|
host and iframe when the viewer changes.
|
|
11
11
|
|
|
12
12
|
For configuration and lifecycle details, see [Initialization and lifecycle](docs/lifecycle.md).
|
|
13
13
|
|
|
14
|
-
For
|
|
14
|
+
For data handlers, query subscriptions, and partial integrations, see the
|
|
15
15
|
[Host contract](docs/host-contract.md). The host accepts `CustomBlockHostOptions`.
|
|
16
16
|
|
|
17
17
|
Use `BridgeParent` from `@notionhq/custom-blocks-host/protocol` to construct parent references with
|
|
18
18
|
plain string IDs. The host validates the parent before sending it to the block.
|
|
19
19
|
|
|
20
|
-
Implement `CustomBlockHostHandlers` to connect the host to your application.
|
|
21
|
-
|
|
20
|
+
Implement `CustomBlockHostHandlers` to connect the host to your application. Handlers that return
|
|
21
|
+
results use promises. `CustomBlockHostHandler<Args, Payload>` supplies the shared signature and
|
|
22
22
|
request context. Handlers return shared bridge data using `CustomBlockHostHandlerResult`. Use
|
|
23
23
|
`makeBridgePage` to construct a complete `BridgePage` from your records. See
|
|
24
24
|
[Return bridge data](docs/handlers.md#return-bridge-data).
|
|
@@ -63,7 +63,7 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
|
|
|
63
63
|
|
|
64
64
|
const host = createCustomBlockHost({
|
|
65
65
|
iframe,
|
|
66
|
-
blockId: "11111111-1111-4111-8111-111111111111",
|
|
66
|
+
instance: { type: "block", blockId: "11111111-1111-4111-8111-111111111111" },
|
|
67
67
|
viewerId: "33333333-3333-4333-8333-333333333333",
|
|
68
68
|
getCurrentUser: async () => ({
|
|
69
69
|
object: "user",
|
|
@@ -107,7 +107,7 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
|
|
|
107
107
|
resize: message => setHeight(message.height),
|
|
108
108
|
},
|
|
109
109
|
onStatusChange: state => {
|
|
110
|
-
if (state.status === "
|
|
110
|
+
if (state.status === "ready") {
|
|
111
111
|
setHeight(state.initialHeight ?? 300)
|
|
112
112
|
status.hidden = true
|
|
113
113
|
iframe.style.visibility = "visible"
|
|
@@ -132,7 +132,7 @@ const dispose = mountCustomBlock(document.body, new URL("https://blocks.example.
|
|
|
132
132
|
window.addEventListener("pagehide", dispose, { once: true })
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
The example displays “Loading block…” until the host reports `ready`, then reveals the iframe. A
|
|
136
136
|
connection failure displays its error code. The example limits the iframe height to 120–1,200 CSS
|
|
137
137
|
pixels.
|
|
138
138
|
|
|
@@ -140,40 +140,40 @@ Call `dispose()` when your application removes the embed. To retry a failed conn
|
|
|
140
140
|
block URL, dispose of the current embed and call `mountCustomBlock()` again.
|
|
141
141
|
|
|
142
142
|
Initial `theme`, `contrastMode`, `containingPage`, and `parent` may be `null` while loading. Call
|
|
143
|
-
the corresponding setters as values resolve.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
loading.
|
|
143
|
+
the corresponding setters as values resolve. Setup waits for the manifest, theme, and contrast mode.
|
|
144
|
+
Parent and containing page values can arrive later. See
|
|
145
|
+
[manifest and initial state](docs/lifecycle.md#manifest-and-initial-state) for the loading contract.
|
|
147
146
|
|
|
148
147
|
For a production integration, replace the demo context and manifest with your application's values.
|
|
149
|
-
Supply data
|
|
148
|
+
Supply data source bindings and handlers for the APIs your block uses. Your application must enforce
|
|
150
149
|
permissions and record access.
|
|
151
150
|
|
|
152
151
|
To connect workspace data, see [Connect a data source](docs/handlers.md#connect-a-data-source).
|
|
153
152
|
|
|
153
|
+
`CustomBlockHostInstance` accepts plain string IDs. `instance` identifies the configured block,
|
|
154
|
+
page, or view independently of the page currently being displayed. `CustomBlockInstance` uses
|
|
155
|
+
`{ type: "block" | "page", blockId }` or `{ type: "view", viewId }`. The identity stays fixed for
|
|
156
|
+
the host connection and is included in `init`. A layout module backed by a custom block uses that
|
|
157
|
+
block's identity.
|
|
158
|
+
|
|
154
159
|
## Guides and reference
|
|
155
160
|
|
|
156
|
-
- [Initialization and lifecycle](docs/lifecycle.md): manifests,
|
|
157
|
-
cleanup.
|
|
158
|
-
- [Handlers and data](docs/handlers.md): application handlers, data
|
|
161
|
+
- [Initialization and lifecycle](docs/lifecycle.md): manifests, initial values, timeouts, live
|
|
162
|
+
updates, and cleanup.
|
|
163
|
+
- [Handlers and data](docs/handlers.md): application handlers, data source integration, queries, and
|
|
159
164
|
navigation.
|
|
160
|
-
- [
|
|
165
|
+
- [Connection compatibility](docs/compatibility.md): protocol negotiation and version requirements.
|
|
161
166
|
|
|
162
|
-
The runtime handles the wire handshake and message validation. The shared protocol references
|
|
163
|
-
|
|
167
|
+
The runtime handles the wire handshake and message validation. The shared protocol references define
|
|
168
|
+
message payloads and versioning:
|
|
164
169
|
|
|
165
170
|
- [Wire protocol](../bridge/protocol.md)
|
|
166
171
|
- [Protocol versioning](../bridge/versioning.md)
|
|
167
|
-
- [Protocol changelog](../bridge/changelog.md)
|
|
168
172
|
|
|
169
173
|
## Protocol schemas and types
|
|
170
174
|
|
|
171
|
-
The `/protocol` entrypoint exposes
|
|
172
|
-
|
|
173
|
-
constants.
|
|
174
|
-
|
|
175
|
-
Import these definitions through the host package to use the protocol version shipped with that
|
|
176
|
-
host:
|
|
175
|
+
The `/protocol` entrypoint exposes message schemas and types, data shapes, IDs, and error
|
|
176
|
+
definitions. Import these definitions through the host package:
|
|
177
177
|
|
|
178
178
|
```ts
|
|
179
179
|
import {
|
|
@@ -182,9 +182,6 @@ import {
|
|
|
182
182
|
} from "@notionhq/custom-blocks-host/protocol"
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
-
`LATEST_BRIDGE_PROTOCOL_VERSION` identifies the latest bridge protocol version defined by the
|
|
186
|
-
bundled protocol.
|
|
187
|
-
|
|
188
185
|
Host APIs, configuration, handler results, and domain argument types are available from
|
|
189
186
|
`@notionhq/custom-blocks-host`.
|
|
190
187
|
|
|
@@ -202,4 +199,4 @@ colors before writing. The runtime validates response payloads.
|
|
|
202
199
|
|
|
203
200
|
Hosts must check URL-backed icon and cover writes against the block's network permissions before
|
|
204
201
|
mutating records. Notion permits the submitted HTTPS destination only when its origin is
|
|
205
|
-
allowlisted
|
|
202
|
+
allowlisted. That origin is trusted to redirect.
|
|
@@ -1,47 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Connection compatibility
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
12
|
-
`
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
@@ -74,3 +89,26 @@ objects carry these fields at the top level. Protocol 3–5 query adapters copy
|
|
|
74
89
|
|
|
75
90
|
Filters and sorts require actual database properties in the bound schema. The host does not support
|
|
76
91
|
queries against synthetic metadata IDs without corresponding database properties.
|
|
92
|
+
|
|
93
|
+
## Data source binding names
|
|
94
|
+
|
|
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, including initialization and live binding updates.
|
|
98
|
+
|
|
99
|
+
## Initialization and location values
|
|
100
|
+
|
|
101
|
+
| Contract | Protocols 3–11 | Protocol 12 |
|
|
102
|
+
| ---------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| 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 |
|
|
104
|
+
| Reveal | Successful `initResult` supplies the initial height and permits reveal | Successful `initResult` permits data operations. `ready` supplies the initial height and permits reveal |
|
|
105
|
+
| Containing-page display mode | Omitted from eager init and `pageChanged` | Required on accessible containing-page descriptors. Defaults to `full_page` |
|
|
106
|
+
| 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 |
|
|
107
|
+
| Missing user names | Compatibility encoding omits missing names and preserves empty strings | Full user profiles contain `name: string \| null` |
|
|
108
|
+
|
|
109
|
+
For protocols 3–11, the host converts `does_not_exist`, `permission_denied`, and `load_failed`
|
|
110
|
+
handler errors to the operation's existing error codes. User lookup and listing use
|
|
111
|
+
`get_user_failed` and `list_users_failed`. Page reads, creation, and updates use `get_page_failed`,
|
|
112
|
+
`create_page_failed`, or `update_page_failed` for load failures, and `page_unavailable` for missing
|
|
113
|
+
or inaccessible pages. Page opening uses `page_unavailable`. Protocol 12 preserves the shared
|
|
114
|
+
resource error codes.
|
|
@@ -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.
|
|
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
|
-
|
|
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
|
|
26
|
-
|
|
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
|
|
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
|
|
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 })`.
|
|
52
|
-
|
|
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.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
|
@@ -99,5 +106,5 @@ properties, the manifest property stays unmapped.
|
|
|
99
106
|
including reminders. Invalid input throws `InvalidNotionDateError`.
|
|
100
107
|
|
|
101
108
|
The root exports host configuration, handlers, results, and domain argument types. Wire schemas,
|
|
102
|
-
message and page types, and constants
|
|
109
|
+
message and page types, and shared constants use the
|
|
103
110
|
[protocol subpath](../README.md#protocol-schemas-and-types).
|