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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/bindings.md CHANGED
@@ -88,11 +88,12 @@ their types match.
88
88
  ## Edit bindings
89
89
 
90
90
  Open **Bindings → Data access** to select files from your worker’s `data/` directory and map their
91
- properties. See the [sample data format](data-sources.md) to define a source. **Done** applies
92
- changes. Closing the dialog or pressing Escape discards them.
91
+ properties. Changes apply as you make them. See the [sample data format](data-sources.md) to
92
+ define a source.
93
93
 
94
- **Page access** appears only when the manifest declares `pages`. It lists the declarations. Page
95
- bindings are not supported yet.
94
+ **Page access** appears when the manifest declares at least one page slot. Select a page from your
95
+ loaded sample data to apply the selection immediately. Named page selections are available in the
96
+ shell UI. Blocks can use the SDK to read sample pages by ID.
96
97
 
97
98
  A property maps automatically only when exactly one source property matches its key or name and has
98
99
  the same type. If no property matches, or several properties match, the property stays unmapped.
@@ -101,9 +102,9 @@ resets its property mappings.
101
102
 
102
103
  ## Initialization and refresh
103
104
 
104
- Once every declared data source and property is mapped, the shell mounts the preview. Applying
105
- binding changes with **Done** restarts the block with the updated data. If initialization fails
106
- because of a binding error, fix the bindings and select **Done** again.
105
+ The shell mounts the preview once every declared data source and property is mapped. Changing a data
106
+ source or property mapping restarts the preview once the bindings are complete. You can finish
107
+ mapping properties while the dialog is open.
107
108
 
108
109
  The shell keeps binding selections separately for each block until you refresh the browser. Refresh
109
110
  the shell to restore each block's CLI source and property selections, with automatic matching for
@@ -24,6 +24,7 @@ expected package version and release date. Unqualified SDK versions refer to
24
24
  | 9 | — | `0.6.0` · 2026-11-05 | — | Native page icons. Older protocols receive external SVG URLs |
25
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
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
+ | 12 | `0.6.0` · 2026-11-19 | `0.11.0` · 2026-11-18 | `0.4.0` · 2026-11-18 | Negotiates the protocol and separates setup, data reads, and render readiness |
27
28
 
28
29
  `—` means no release in that package line carried that specific protocol version.
29
30
 
@@ -35,23 +36,26 @@ Native host package pins and protocol mappings are tracked separately in
35
36
  and
36
37
  [mobile shell registry](https://github.com/makenotion/notion-next/blob/main/src/cloudflare-customBlockWorker/lib/mobileShellRegistry.ts).
37
38
 
38
- ## Protocol 12: minimal handshake and post-init reads (unreleased)
39
+ ## Protocol 12: minimal handshake and post-init reads
40
+
41
+ Option colors, status-group colors, and page-metadata actor tables accept future string values.
39
42
 
40
43
  Protocol 12 negotiates a version with `connect` and `connectResult`, then sends setup-only `init`
41
44
  with its own request ID, fixed `instance` identity, manifest, and
42
45
  `preferences: { theme, contrastMode }`. `initResult` acknowledges setup. A separate
43
46
  `ready { initialHeight }` permits reveal. Protocols 3–11 retain their handshake and eager payloads.
44
47
 
48
+ `getViewer` returns a user identity or an anonymous viewer without loading a profile. Anonymous
49
+ viewers can initialize. `getCurrentUser` remains supported; protocols 3–11 still require a user.
50
+
45
51
  After acknowledgment, `parentChanged` and `pageChanged` deliver initial resolved location values and
46
52
  later changes without sandbox requests. Unresolved parent and containing page values do not delay
47
53
  setup. `getCurrentUser` and `getDataSource` requests load profiles and source metadata
48
54
  independently. Binding refresh uses `dataSourcesInvalidated`. Raw-ID page operations remain
49
55
  unchanged.
50
56
 
51
- Host support is [#713](https://github.com/makenotion/custom-blocks/pull/713). SDK domains and React
52
- states follow in [#716](https://github.com/makenotion/custom-blocks/pull/716) and
53
- [#717](https://github.com/makenotion/custom-blocks/pull/717). Publish the SDK after host adoption.
54
- Host-owned key resolution, grants, and pagination remain future work.
57
+ `operation_not_allowed` reports that an operation is unavailable in the workspace.
58
+ `block_limit_reached` reports that the workspace's block limit prevents page creation.
55
59
 
56
60
  Full profiles require `name: string | null`. The `makeBridgeUser` builder supplies `null` when its
57
61
  caller omits the name. Protocols 3–11 retain omitted names on the wire for deployed SDKs. Empty
@@ -63,17 +67,21 @@ descriptors preserve this field, and mode-only changes use the existing `pageCha
63
67
  The shared host also reports known parent/page failures through `parentError` and `pageError`. Later
64
68
  value notifications recover each field.
65
69
 
70
+ Query NACKs can include `subscriptionId`. Rejected queries and malformed responses now report an
71
+ error immediately when the SDK can identify the affected subscription.
72
+
73
+ Unsupported page icon types read as `null`. Icon writes still require a supported shape.
74
+
66
75
  ## Optional query limit metadata
67
76
 
68
77
  Query results can include optional `limitClamp` metadata when a host reduces the requested limit.
69
- Older SDKs ignore the field, so the protocol version remains 11.
78
+ The field was added in protocol 11. SDKs that do not recognize it ignore it.
70
79
 
71
80
  ## Protocol 11: location removal and data source binding names
72
81
 
73
- Current bindings use `dataSourceSchema` and `dataSourcePointer` in `init` and `dataSourcesChanged`.
74
- Current SDK types and host APIs use the same names. The host encodes `collectionSchema` and
75
- `collectionPointer` for supported protocols 3–10 only at its outgoing boundary. Protocols 3–4 still
76
- receive synthetic metadata schemas there.
82
+ Protocol 11 uses `dataSourceSchema` and `dataSourcePointer` in `init` and `dataSourcesChanged`. The
83
+ host encodes `collectionSchema` and `collectionPointer` for supported protocols 3–10 only at its
84
+ outgoing boundary. Protocols 3–4 still receive synthetic metadata schemas there.
77
85
 
78
86
  SDK 0.5.1 adds incoming compatibility for the `collectionSchema` and `collectionPointer` names sent
79
87
  by older hosts such as 0.9.0. It normalizes these fields in both `init` and `dataSourcesChanged`,
@@ -72,15 +72,21 @@ metadata for init. `preferences` groups fields only in `init`. Later updates use
72
72
  `contrastModeChanged`.
73
73
 
74
74
  After a successful `initResult`, data operations are available regardless of render readiness. The
75
- following requests read the current user profile and one data source binding:
75
+ following requests read viewer identity, the current user profile, or source metadata:
76
76
 
77
77
  | Request | Success result |
78
78
  | ------------------------------------------- | ------------------------------------------------------------------------------------------------- |
79
+ | `{ type: "getViewer", requestId }` | `{ type: "getViewerResult", requestId, status: "success", viewer: BridgeViewer }` |
79
80
  | `{ type: "getCurrentUser", requestId }` | `{ type: "getCurrentUserResult", requestId, status: "success", user: BridgeUser }` |
80
81
  | `{ type: "getDataSource", requestId, key }` | `{ type: "getDataSourceResult", requestId, status: "success", binding: BridgeDataSourceBinding }` |
81
82
 
83
+ `BridgeViewer` is `{ type: "user", userId }` or `{ type: "anonymous" }`. Identity is fixed for the
84
+ connection. A viewer read does not load a profile. For an anonymous viewer, `getCurrentUser` returns
85
+ an error with code `current_user_unavailable`. The embedding application authorizes each data
86
+ operation separately.
87
+
82
88
  A failure returns `{ type: "<request type>Result", requestId, status: "error", error }` and leaves
83
- other operations available. User reads return the full profile, including email. Source reads
89
+ other operations available. Profile reads return the full profile, including email. Source reads
84
90
  resolve metadata for a declared binding. Page operations and queries address raw record IDs.
85
91
 
86
92
  Configuration refresh aborts pending operations and queries, clears source metadata, and sends
@@ -161,7 +167,13 @@ request with `invalid_sandbox_message`. When the SDK rejects a host response, it
161
167
  matching request locally with `invalid_host_message` and includes the ID in `invalidHostMessage`.
162
168
  Both errors have `isRetryable: false`.
163
169
 
164
- SDK requests time out after 60 seconds. Missing, unreadable, or unknown IDs do not fail unrelated
170
+ When the host rejects a `queryDataSource` message, it includes any readable `subscriptionId` in
171
+ `invalidSandboxMessage`. The SDK reports `invalid_sandbox_message` to that subscription. When the
172
+ SDK cannot parse a query response with a readable `subscriptionId`, it reports
173
+ `invalid_host_message` to that subscription and includes the ID in `invalidHostMessage`. Missing or
174
+ unknown IDs do not affect other subscriptions. Receivers do not reply to malformed NACKs.
175
+
176
+ SDK requests time out after 30 seconds. Missing, unreadable, or unknown IDs do not fail unrelated
165
177
  requests. A NACK without a readable `requestId` cannot complete a pending request. That request
166
178
  retains its timeout.
167
179
 
@@ -178,13 +190,21 @@ Other malformed sandbox messages receive a NACK without changing the host's life
178
190
  resetting its timeout. A missing or malformed `initResult` leaves the host waiting until the setup
179
191
  acknowledgment timeout. Valid results with a stale ID are ignored.
180
192
 
181
- A sandbox that can read a malformed `init` message's `requestId` replies with `initResult`,
182
- `status: "error"`, and `invalid_init_payload`. Otherwise, it sends `invalidHostMessage`. A malformed
183
- message does not restart initialization after success or failure.
193
+ During setup, a sandbox that can read a malformed `init` message's `requestId` replies with
194
+ `initResult`, `status: "error"`, and `invalid_init_payload`. Without a readable request ID, setup
195
+ fails locally with `unsupported_protocol_version`. A malformed message does not restart
196
+ initialization after success or failure.
184
197
 
185
198
  `CustomBlockErrorInfo` carries `code`, `message`, and `isRetryable`. Error schemas accept any string
186
199
  for `code`, including unknown codes. TypeScript aliases list known codes for autocomplete.
187
200
 
201
+ ### Workspace restrictions
202
+
203
+ `operation_not_allowed` reports a workspace restriction without disclosing private policy or billing
204
+ reasons. Applications keep those reasons in internal diagnostics, outside sandbox messages and
205
+ sandbox-visible logs. Page creation reports `block_limit_reached` when the workspace block allowance
206
+ prevents creation.
207
+
188
208
  ## Data sources
189
209
 
190
210
  ### Bindings and IDs
@@ -5,9 +5,11 @@ owns the iframe, permissions, data access, persistence, analytics, and UI. Block
5
5
  `@notionhq/custom-blocks`.
6
6
 
7
7
  Create the host before navigating the iframe. Pass the full block URL as `sandboxUrl`, and call
8
- `stop()` when removing the iframe. A host instance belongs to the required `viewerId`. Supply one
9
- asynchronous `getCurrentUser` profile reader. Its returned ID must match that viewer. Create a fresh
10
- host and iframe when the viewer changes.
8
+ `stop()` when removing the iframe. The host calls `getViewer()` synchronously once to capture a user
9
+ or anonymous identity. Create a fresh host and iframe when that identity changes. The
10
+ `handlers.getUser` handler loads profiles separately. See
11
+ [Current viewer](docs/host-contract.md#current-viewer) for identity validation and profile-read
12
+ errors.
11
13
 
12
14
  For configuration and lifecycle details, see [Initialization and lifecycle](docs/lifecycle.md).
13
15
 
@@ -64,15 +66,7 @@ function mountCustomBlock(container: HTMLElement, blockUrl: URL): () => void {
64
66
  const host = createCustomBlockHost({
65
67
  iframe,
66
68
  instance: { type: "block", 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
- }),
69
+ getViewer: () => ({ type: "user", userId: "33333333-3333-4333-8333-333333333333" }),
76
70
  theme: "light",
77
71
  contrastMode: "standard",
78
72
  containingPage: {
@@ -150,6 +144,10 @@ permissions and record access.
150
144
 
151
145
  To connect workspace data, see [Connect a data source](docs/handlers.md#connect-a-data-source).
152
146
 
147
+ Data source reads resolve configured property IDs against the loaded schema. Exact matches win.
148
+ Otherwise, the host decodes a URL-encoded ID once and uses it only when it matches a schema
149
+ property. The host validates these mappings before returning them; saved bindings stay unchanged.
150
+
153
151
  `CustomBlockHostInstance` accepts plain string IDs. `instance` identifies the configured block,
154
152
  page, or view independently of the page currently being displayed. `CustomBlockInstance` uses
155
153
  `{ type: "block" | "page", blockId }` or `{ type: "view", viewId }`. The identity stays fixed for
@@ -94,7 +94,11 @@ queries against synthetic metadata IDs without corresponding database properties
94
94
 
95
95
  Protocols 11–12 use `dataSourceSchema` and `dataSourcePointer`. Host adapters supply only these
96
96
  current names. The outgoing boundary restores `collectionSchema` and `collectionPointer` for
97
- protocols 3–10, including initialization and live binding updates.
97
+ protocols 3–10.
98
+
99
+ Protocols 3–11 receive bindings in eager initialization and replacement bindings in
100
+ `dataSourcesChanged`. Protocol 12 reads bindings through `getDataSource`. After a configuration
101
+ change, `dataSourcesInvalidated` tells the SDK to reload metadata when an operation needs it.
98
102
 
99
103
  ## Initialization and location values
100
104
 
@@ -106,9 +110,17 @@ protocols 3–10, including initialization and live binding updates.
106
110
  | Location failures | Known initial failures fail eager initialization. `parentError` and `pageError` are not sent | `parentError` and `pageError` report known failures independently. Later value notifications clear the corresponding error |
107
111
  | Missing user names | Compatibility encoding omits missing names and preserves empty strings | Full user profiles contain `name: string \| null` |
108
112
 
113
+ For protocols 3–11, a malformed `initResult` with the active `initializationId` fails setup with
114
+ `invalid_init_result_payload`. See [host lifecycle](lifecycle.md#callbacks) for setup diagnostics.
115
+
109
116
  For protocols 3–11, the host converts `does_not_exist`, `permission_denied`, and `load_failed`
110
117
  handler errors to the operation's existing error codes. User lookup and listing use
111
118
  `get_user_failed` and `list_users_failed`. Page reads, creation, and updates use `get_page_failed`,
112
119
  `create_page_failed`, or `update_page_failed` for load failures, and `page_unavailable` for missing
113
120
  or inaccessible pages. Page opening uses `page_unavailable`. Protocol 12 preserves the shared
114
121
  resource error codes.
122
+
123
+ Protocols 3–11 require a user viewer and a successful `handlers.getUser` result for eager
124
+ initialization. On these protocols, anonymous setup fails with `current_user_unavailable` before
125
+ profile loading. Protocol 12 anonymous setup succeeds. The `getViewer` request and `getViewerResult`
126
+ response require a host with viewer-read support.
@@ -76,6 +76,15 @@ and persistence. `getUser` and `listUsers` supply user data. Each handler return
76
76
  or an error. The runtime adds the request's correlation ID and sends the response. The application
77
77
  enforces record access before reading or writing data.
78
78
 
79
+ For `createPage` and `updatePage`, return success after your application confirms the save. A local
80
+ cache update or queued transaction does not establish that a remote save succeeded. Capture the
81
+ requested mutation's response state before waiting, so later edits do not enter its result.
82
+
83
+ If a save fails or confirmation exceeds your application's deadline, return `create_page_failed` or
84
+ `update_page_failed`. A timeout does not cancel the queued write. Set `isRetryable: false` when
85
+ repeating the operation could duplicate a create or race a write that is still pending. Keep any
86
+ private server rejection details in internal application logs; return a safe message to the block.
87
+
79
88
  `openPage` handles navigation to a Notion page. `resize` receives the block's requested height in
80
89
  CSS pixels. The application owns navigation and iframe sizing.
81
90
 
@@ -10,11 +10,11 @@ belongs to one viewer. Stop the host and create a fresh host and iframe to chang
10
10
 
11
11
  ## Options and partial implementations
12
12
 
13
- Required options are `instance`, `viewerId`, `getCurrentUser`, `theme`, `contrastMode`,
14
- `containingPage`, `parent`, `iframe`, `sandboxUrl`, `manifestSource`, `getPersistedManifest`,
15
- `onStatusChange`, `bindings`, and `handlers`. `instance` and `viewerId` stay fixed for the instance.
16
- Optional settings for this contract are `onLog`, `minBridgeProtocolVersion`, `noConnectTimeoutMs`,
17
- `initialStateTimeoutMs`, `noInitResultTimeoutMs`, and `noReadyTimeoutMs`.
13
+ Required options are `instance`, `getViewer`, `theme`, `contrastMode`, `containingPage`, `parent`,
14
+ `iframe`, `sandboxUrl`, `manifestSource`, `getPersistedManifest`, `onStatusChange`, `bindings`, and
15
+ `handlers`. `instance` and viewer identity stay fixed for the connection. Optional settings for this
16
+ contract are `onLog`, `minBridgeProtocolVersion`, `noConnectTimeoutMs`, `initialStateTimeoutMs`,
17
+ `noInitResultTimeoutMs`, and `noReadyTimeoutMs`.
18
18
 
19
19
  `theme`, `contrastMode`, `containingPage`, and `parent` accept `null` while unresolved. Supply
20
20
  resolved values through `setTheme()`, `setContrastMode()`, `setContainingPage()`, and `setParent()`.
@@ -109,15 +109,22 @@ arguments with `CustomBlockHostRequestContext` and the shared result type. `subs
109
109
 
110
110
  ## Current viewer
111
111
 
112
- `viewerId` is a required, nonempty identity supplied before host construction. The application
113
- handles missing authentication before mounting a host. Anonymous viewers are not modeled by this
114
- contract.
112
+ `getViewer()` runs synchronously once during host creation and returns `CustomBlockHostViewer`:
115
113
 
116
- `getCurrentUser({ signal })` is a required constructor callback returning a promise of a complete
117
- `BridgeUser` profile directly, without a success envelope or separate field readers. The shared host
118
- validates the profile and checks its ID against `viewerId`. The host invokes the callback for each
119
- `getCurrentUser` request. A rejected read, mismatched ID, or malformed profile returns a correlated
120
- `unknown_error`. Diagnostics stay in the host log. The host does not cache the profile.
114
+ ```ts
115
+ type CustomBlockHostViewer = { type: "user"; userId: string } | { type: "anonymous" }
116
+ ```
117
+
118
+ The callback returns a known identity. The host validates and retains it. Login, logout, and account
119
+ switching require a new host and iframe. The `getViewer` bridge request returns the captured
120
+ identity without loading a profile. Anonymous setup succeeds. The embedding application authorizes
121
+ rendering and each data operation.
122
+
123
+ `handlers.getUser({ userId, signal })` supplies profiles for user reads and eager initialization.
124
+ Current-user reads use the captured viewer ID and verify that the returned profile matches it.
125
+ Anonymous current-user reads return non-retryable `current_user_unavailable` without calling the
126
+ handler. Handler errors are forwarded. A rejected promise, mismatched ID, or malformed profile
127
+ produces `unknown_error`, with details in the host log. The host does not cache profiles.
121
128
 
122
129
  ## Metadata and configuration
123
130
 
@@ -66,8 +66,8 @@ the selected manifest, theme, and contrast mode. Parent and containing page load
66
66
  toward this timeout.
67
67
 
68
68
  A successful `initResult` permits data operations while the host waits for `ready`. The callbacks
69
- `getPersistedManifest`, `getCurrentUser`, and `getDataSource` must respect their `signal`. Stopping
70
- the host aborts pending work and suppresses late results.
69
+ `getPersistedManifest`, `handlers.getUser`, and `handlers.getDataSource` must respect their
70
+ `signal`. Stopping the host aborts pending work and suppresses late results.
71
71
 
72
72
  ## Live state
73
73
 
@@ -101,6 +101,18 @@ Connection failures contain `{ phase, source, code, message, isRetryable }`. The
101
101
  `init`, `initResult`, `ready`, or `runtime`. The source identifies who reported the failure.
102
102
  Failures can occur after setup succeeds.
103
103
 
104
+ During setup, use the failure code and the bridge log to locate the failed exchange.
105
+
106
+ | Code | Meaning |
107
+ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
108
+ | `invalid_connect_payload` | The host could read the `connect` request ID but could not validate the request. The host sends a failed `connectResult`. |
109
+ | `invalid_init_payload` | The sandbox could read the `init` request ID but could not validate the setup data. The sandbox sends a failed `initResult`. |
110
+
111
+ If the host receives no valid setup acknowledgment before `noInitResultTimeoutMs`, it reports
112
+ `no_init_result`. A malformed acknowledgment leaves that timer running. See the
113
+ [wire reference](../../bridge/protocol.md#validation-and-errors) for message validation and
114
+ request matching.
115
+
104
116
  At `ready`, apply a supplied `initialHeight` in CSS pixels before revealing the iframe. If the
105
117
  height is absent, use your application's default size. Resize messages can arrive after setup
106
118
  succeeds. Apply height changes without revealing the iframe until `ready`. Reveal, sizing, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-dev-shell",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Local development shell for Notion custom block workers.",
5
5
  "license": "MIT",
6
6
  "type": "module",