@notionhq/custom-blocks 0.3.5 → 0.5.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 +2 -2
- package/dist/bridge/SandboxBridge.d.ts +4 -39
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +36 -142
- package/dist/bridge/requests.d.ts +35 -0
- package/dist/bridge/requests.d.ts.map +1 -0
- package/dist/bridge/requests.js +97 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
- package/dist/dataSources/bridge/resolveDataSourceQuery.js +18 -4
- package/dist/dataSources/bridge/resolveDataSources.js +4 -4
- package/dist/dataSources/createDataSourcePage.d.ts.map +1 -1
- package/dist/dataSources/createDataSourcePage.js +5 -1
- package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -1
- package/dist/dataSources/filters/resolveFilter.js +13 -3
- package/dist/dataSources/filters/types.d.ts +9 -3
- package/dist/dataSources/filters/types.d.ts.map +1 -1
- package/dist/dataSources/properties/resolvePropertyAddress.js +1 -1
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.js +1 -1
- package/dist/dataSources/resolvePageDataSource.js +2 -2
- package/dist/dataSources/subscribeToDataSource.d.ts +1 -4
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
- package/dist/dataSources/subscribeToDataSource.js +2 -3
- package/dist/dataSources/types.d.ts +2 -0
- package/dist/dataSources/types.d.ts.map +1 -1
- package/dist/files/files.d.ts +2 -0
- package/dist/files/files.d.ts.map +1 -0
- package/dist/files/files.js +1 -0
- package/dist/files/icons.d.ts +2 -0
- package/dist/files/icons.d.ts.map +1 -0
- package/dist/files/icons.js +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/initialization/getInitBindingError.js +2 -2
- package/dist/manifest/types.d.ts +5 -4
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.js +2 -1
- package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
- package/dist/pages/bridge/getPageForDataSource.js +3 -2
- package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
- package/dist/pages/bridge/sendCreatePageRequest.js +2 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +14 -2
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +0 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -8
- package/dist/pages/bridge/updatePage.d.ts.map +1 -1
- package/dist/pages/bridge/updatePage.js +20 -5
- package/dist/pages/createPage.d.ts.map +1 -1
- package/dist/pages/createPage.js +5 -1
- package/dist/pages/openPage.d.ts.map +1 -1
- package/dist/pages/openPage.js +2 -1
- package/dist/pages/properties/getPropertyByKey.js +2 -2
- package/dist/pages/types.d.ts +10 -14
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.d.ts +530 -0
- package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.js +25 -0
- package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +12 -11
- package/dist/protocol/compatibility/protocol3To5/bridgePage.js +3 -3
- package/dist/protocol/context/containingPage.d.ts +3 -0
- package/dist/protocol/context/messages/pageChanged.d.ts +3 -0
- package/dist/protocol/context/messages/parentChanged.d.ts +3 -0
- package/dist/protocol/context/parent.d.ts +5 -0
- package/dist/protocol/context/parent.js +6 -1
- package/dist/protocol/dataSources/bridgeArchiveStatus.d.ts +3 -0
- package/dist/protocol/dataSources/bridgeArchiveStatus.js +6 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +3 -11
- package/dist/protocol/dataSources/bridgeDataSourceBinding.js +5 -5
- package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +2 -10
- package/dist/protocol/dataSources/{collectionPointer.d.ts → dataSourcePointer.d.ts} +2 -2
- package/dist/protocol/dataSources/{collectionPointer.js → dataSourcePointer.js} +1 -1
- package/dist/protocol/dataSources/{collectionSchema.d.ts → dataSourceSchema.d.ts} +2 -10
- package/dist/protocol/dataSources/{collectionSchema.js → dataSourceSchema.js} +1 -1
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.d.ts +1458 -12
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.d.ts +729 -6
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.js +14 -2
- package/dist/protocol/dataSources/filters/peopleFilterOperator.d.ts +3 -3
- package/dist/protocol/dataSources/filters/peopleFilterOperator.js +1 -1
- package/dist/protocol/dataSources/filters/timestampFilterOperator.d.ts +354 -0
- package/dist/protocol/dataSources/filters/timestampFilterOperator.js +4 -0
- package/dist/protocol/dataSources/messages/dataSourcesChanged.d.ts +2 -10
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +1485 -38
- package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
- package/dist/protocol/dataSources/notionDataSource.d.ts +3 -19
- package/dist/protocol/dataSources/notionDataSource.js +5 -5
- package/dist/protocol/dataSources/properties/propertySchema.d.ts +4 -13
- package/dist/protocol/dataSources/properties/propertySchema.js +2 -6
- package/dist/protocol/dataSources/resolveDataSourceBinding.d.ts +4 -4
- package/dist/protocol/dataSources/resolveDataSourceBinding.js +2 -2
- package/dist/protocol/files.d.ts +32 -0
- package/dist/protocol/files.js +17 -0
- package/dist/protocol/handshake/connect.d.ts +15 -4
- package/dist/protocol/handshake/init.d.ts +23 -14
- package/dist/protocol/icons.d.ts +32 -0
- package/dist/protocol/icons.js +39 -0
- package/dist/protocol/index.d.ts +25 -19
- package/dist/protocol/index.js +15 -9
- package/dist/protocol/manifest/grants.d.ts +48 -0
- package/dist/protocol/manifest/grants.js +19 -0
- package/dist/protocol/manifest/manifest.d.ts +39 -16
- package/dist/protocol/manifest/manifest.js +17 -11
- package/dist/protocol/messages/hostToSandbox.d.ts +196 -177
- package/dist/protocol/messages/invalidHostMessage.d.ts +2 -0
- package/dist/protocol/messages/invalidHostMessage.js +2 -0
- package/dist/protocol/messages/invalidSandboxMessage.d.ts +2 -0
- package/dist/protocol/messages/invalidSandboxMessage.js +2 -0
- package/dist/protocol/messages/sandboxToHost.d.ts +1571 -50
- package/dist/protocol/navigation/openExternalUrl.d.ts +2 -2
- package/dist/protocol/pages/bridgePage.d.ts +12 -12
- package/dist/protocol/pages/bridgePage.js +3 -4
- package/dist/protocol/pages/makeBridgePage.d.ts +3 -1
- package/dist/protocol/pages/messages/createPage.d.ts +645 -62
- package/dist/protocol/pages/messages/createPage.js +27 -13
- package/dist/protocol/pages/messages/getPage.d.ts +38 -37
- package/dist/protocol/pages/messages/openPage.d.ts +2 -2
- package/dist/protocol/pages/messages/updatePage.d.ts +47 -48
- package/dist/protocol/pages/messages/updatePage.js +3 -3
- package/dist/protocol/pages/pageAppearance.d.ts +9 -28
- package/dist/protocol/pages/pageAppearance.js +11 -31
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +4 -20
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +2 -10
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +2 -12
- package/dist/protocol/users/makeBridgeUser.d.ts +3 -1
- package/dist/protocol/users/messages/getUser.d.ts +2 -2
- package/dist/protocol/users/messages/listUsers.d.ts +2 -2
- package/dist/protocol/utils/errors.d.ts +6 -4
- package/dist/protocol/utils/errors.js +3 -3
- package/dist/protocol/utils/ids.d.ts +2 -0
- package/dist/protocol/utils/ids.js +1 -0
- package/dist/protocol/utils/protocolVersion.d.ts +3 -1
- package/dist/protocol/utils/protocolVersion.js +5 -1
- package/dist/protocol/utils/readRequestId.d.ts +2 -0
- package/dist/protocol/utils/readRequestId.js +7 -0
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +1 -15
- package/dist/users/getUser.d.ts.map +1 -1
- package/dist/users/getUser.js +2 -1
- package/dist/users/listUsers.d.ts.map +1 -1
- package/dist/users/listUsers.js +4 -2
- package/dist/utils/version.js +1 -1
- package/docs/data-sources.md +85 -83
- package/docs/deployment.md +4 -5
- package/docs/errors.md +47 -5
- package/docs/grants.md +127 -0
- package/docs/pages.md +105 -56
- package/docs/users.md +2 -2
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +44 -243
- package/src/bridge/requests.ts +138 -0
- package/src/dataSources/bridge/resolveDataSourceQuery.ts +24 -4
- package/src/dataSources/bridge/resolveDataSources.ts +4 -4
- package/src/dataSources/createDataSourcePage.ts +5 -1
- package/src/dataSources/filters/resolveFilter.ts +12 -3
- package/src/dataSources/filters/types.ts +7 -4
- package/src/dataSources/properties/resolvePropertyAddress.ts +1 -1
- package/src/dataSources/properties/resolvePropertyWriteMapForDataSource.ts +1 -1
- package/src/dataSources/resolvePageDataSource.ts +2 -2
- package/src/dataSources/subscribeToDataSource.ts +7 -19
- package/src/dataSources/types.ts +3 -0
- package/src/files/files.ts +5 -0
- package/src/files/icons.ts +9 -0
- package/src/index.ts +10 -11
- package/src/initialization/getInitBindingError.ts +2 -2
- package/src/manifest/types.ts +10 -4
- package/src/navigation/openExternalUrl.ts +5 -1
- package/src/pages/bridge/getPageForDataSource.ts +6 -2
- package/src/pages/bridge/sendCreatePageRequest.ts +5 -1
- package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +0 -1
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -8
- package/src/pages/bridge/updatePage.ts +29 -9
- package/src/pages/createPage.ts +5 -1
- package/src/pages/openPage.ts +5 -1
- package/src/pages/properties/getPropertyByKey.ts +2 -2
- package/src/pages/types.ts +14 -16
- package/src/react/NotionCustomBlock.tsx +1 -16
- package/src/users/getUser.ts +5 -1
- package/src/users/listUsers.ts +9 -4
- package/dist/bridge/pendingRequests.d.ts +0 -14
- package/dist/bridge/pendingRequests.d.ts.map +0 -1
- package/dist/bridge/pendingRequests.js +0 -28
- package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +0 -17
- package/dist/protocol/dataSources/filters/createdByFilterOperator.js +0 -11
- package/dist/protocol/manifest/capabilities.d.ts +0 -37
- package/dist/protocol/manifest/capabilities.js +0 -13
- package/dist/protocol/pages/properties/fileInput.d.ts +0 -16
- package/dist/protocol/pages/properties/fileInput.js +0 -16
- package/dist/react/DebugMessageLog.d.ts +0 -2
- package/dist/react/DebugMessageLog.d.ts.map +0 -1
- package/dist/react/DebugMessageLog.js +0 -23
- package/docs/capabilities.md +0 -111
- package/src/bridge/pendingRequests.ts +0 -28
- package/src/react/DebugMessageLog.tsx +0 -34
package/docs/pages.md
CHANGED
|
@@ -24,9 +24,8 @@ if (result.status === "success") {
|
|
|
24
24
|
raw property ID. `getPropertyById` returns the loaded value with that ID, or `null`. Neither
|
|
25
25
|
property getter fetches data.
|
|
26
26
|
|
|
27
|
-
Every page has `created_time`, `last_edited_time`, `created_by`, `last_edited_by
|
|
28
|
-
|
|
29
|
-
properties.
|
|
27
|
+
Every page has `created_time`, `last_edited_time`, `created_by`, and `last_edited_by` fields.
|
|
28
|
+
Unavailable values are `null`. These fields are separate from database properties.
|
|
30
29
|
|
|
31
30
|
Parent, icon, cover, URLs, timestamps, and archive state are page metadata. Missing icons, covers,
|
|
32
31
|
URLs, and timestamps are `null`. `is_archived` and `in_trash` include inherited state. The SDK
|
|
@@ -80,7 +79,8 @@ const row = await pages.create({
|
|
|
80
79
|
```
|
|
81
80
|
|
|
82
81
|
If a property value includes `id`, it must match the target's raw property ID. Unknown or unbound
|
|
83
|
-
manifest keys return `unmapped_property`. Creation
|
|
82
|
+
manifest keys return `unmapped_property`. Creation accepts native icons, emoji, custom emoji, and
|
|
83
|
+
URL-backed icons and covers. URL-backed inputs require host network permission.
|
|
84
84
|
|
|
85
85
|
## Mutate pages
|
|
86
86
|
|
|
@@ -103,8 +103,7 @@ The SDK validates all properties before sending an update. Invalid values, misma
|
|
|
103
103
|
targets, and unresolved keys return local errors. An update must include at least one property or
|
|
104
104
|
metadata change. See [Local page update errors](errors.md#local-page-update-errors).
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
external URLs, and existing hosted file URLs. File upload references are unsupported.
|
|
106
|
+
For the supported icon, cover, and file property values, see [Files and icons](#files-and-icons).
|
|
108
107
|
|
|
109
108
|
## Types
|
|
110
109
|
|
|
@@ -120,65 +119,73 @@ external URLs, and existing hosted file URLs. File upload references are unsuppo
|
|
|
120
119
|
|
|
121
120
|
## Property support
|
|
122
121
|
|
|
123
|
-
|
|
122
|
+
This table shows property support for custom blocks running in Notion.
|
|
124
123
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
- **Create** covers property writes through `pages.create`.
|
|
128
|
-
- **Update** covers property writes through `page.updateById`.
|
|
124
|
+
Read page shows property values returned by reads, creates, and successful updates. Create page and
|
|
125
|
+
Update page cover property writes.
|
|
129
126
|
|
|
130
|
-
Pages outside a data source support only `title`. Other
|
|
131
|
-
|
|
127
|
+
Pages outside a data source support only `title`. Other property writes require a data source row
|
|
128
|
+
and a property in its schema.
|
|
129
|
+
|
|
130
|
+
Property values can be `null` when empty or unavailable.
|
|
132
131
|
|
|
133
132
|
- 🟢 **Supported:** The SDK supports this operation in Notion.
|
|
134
|
-
- 🟡 **Limited:** The SDK supports this operation with the
|
|
135
|
-
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
152
|
-
| `
|
|
153
|
-
| `
|
|
154
|
-
| `
|
|
155
|
-
| `
|
|
156
|
-
| `
|
|
157
|
-
| `
|
|
158
|
-
| `
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
165
|
-
| `last_edited_by` | 🟢 Actor record pointer | 🔴 Unavailable | 🔴 Unavailable |
|
|
133
|
+
- 🟡 **Limited:** The SDK supports this operation with the restrictions shown in the table and
|
|
134
|
+
notes.
|
|
135
|
+
- 🔒 **Read-only:** Notion sets this value. You cannot set it when creating or updating a page.
|
|
136
|
+
- 🔴 **Unavailable:** The SDK does not support this operation.
|
|
137
|
+
|
|
138
|
+
| Property type | Read page | Create page | Update page |
|
|
139
|
+
| ------------------ | ----------------------------------------- | ------------------- | ------------------- |
|
|
140
|
+
| `title` | 🟡 Plain text array | 🟡 Plain text only | 🟡 Plain text only |
|
|
141
|
+
| `rich_text` | 🟡 Plain text array | 🟡 Plain text only | 🟡 Plain text only |
|
|
142
|
+
| `number` | 🟢 Number | 🟢 Supported | 🟢 Supported |
|
|
143
|
+
| `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported |
|
|
144
|
+
| `url` | 🟢 String | 🟢 Supported | 🟢 Supported |
|
|
145
|
+
| `email` | 🟢 String | 🟢 Supported | 🟢 Supported |
|
|
146
|
+
| `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported |
|
|
147
|
+
| `select` | 🟢 Selected option | 🟢 Supported | 🟢 Supported |
|
|
148
|
+
| `multi_select` | 🟢 Selected options | 🟢 Supported | 🟢 Supported |
|
|
149
|
+
| `status` | 🟢 Selected option | 🟢 Supported | 🟢 Supported |
|
|
150
|
+
| `date` | 🟢 `start` and optional `end` strings | 🟡 Minute precision | 🟡 Minute precision |
|
|
151
|
+
| `people` | 🟢 Array of user or group ID objects | 🟢 Supported | 🟢 Supported |
|
|
152
|
+
| `files` | 🟢 External links and hosted files | 🟡 File URLs only | 🟡 File URLs only |
|
|
153
|
+
| `unique_id` | 🟡 Formatted ID | 🔴 Unavailable | 🔴 Unavailable |
|
|
154
|
+
| `relation` | 🟢 Array of page ID objects | 🟡 Replaces value | 🟡 Replaces value |
|
|
155
|
+
| `place` | 🟢 Coordinates and optional place details | 🟢 Supported | 🟢 Supported |
|
|
156
|
+
| `formula` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
|
|
157
|
+
| `rollup` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
|
|
158
|
+
| `button` | 🟡 Button label | 🔴 Unavailable | 🔴 Unavailable |
|
|
159
|
+
| `verification` | 🟡 Status text | 🔴 Unavailable | 🔴 Unavailable |
|
|
160
|
+
| `created_time` | 🟢 Timestamp | 🔒 Read-only | 🔒 Read-only |
|
|
161
|
+
| `last_edited_time` | 🟢 Timestamp | 🔒 Read-only | 🔒 Read-only |
|
|
162
|
+
| `created_by` | 🟢 Actor reference | 🔒 Read-only | 🔒 Read-only |
|
|
163
|
+
| `last_edited_by` | 🟢 Actor reference | 🔒 Read-only | 🔒 Read-only |
|
|
166
164
|
|
|
167
165
|
### Notes
|
|
168
166
|
|
|
169
|
-
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
- Timestamps are ISO 8601 strings in UTC.
|
|
168
|
+
- Actor references identify who created or last edited the page.
|
|
169
|
+
- Unique IDs return a formatted string, including the data source prefix when available. Missing
|
|
170
|
+
values return `""`.
|
|
171
|
+
- Formula and rollup reads return stored plain text. They do not evaluate formulas or aggregations.
|
|
172
|
+
Missing values return `""`.
|
|
173
|
+
- Button reads return the automation name when readable, or the property name as a fallback.
|
|
174
|
+
- Verification reads return a localized status label, such as "Verified" or "Expired". Missing or
|
|
175
|
+
invalid values return `""`.
|
|
176
|
+
- Select, multi-select, and status reads return option names and colors when available. They also
|
|
177
|
+
return IDs when the options match the schema.
|
|
178
|
+
- Select, multi-select, and status writes select existing options by ID or name. They do not create
|
|
179
|
+
or edit schema options. If you supply both an ID and a name, the host uses the ID. The host
|
|
180
|
+
rejects unknown IDs.
|
|
172
181
|
- Date-time writes preserve hours and minutes but discard seconds and milliseconds.
|
|
173
|
-
- Title and rich text use text arrays
|
|
174
|
-
|
|
175
|
-
-
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
- Title and rich text use text arrays, but reads and writes preserve only plain text. Reads and
|
|
183
|
+
writes do not preserve formatting, links, mentions, or equations as structured rich text.
|
|
184
|
+
- Files reads return external links and signed URLs for Notion-hosted files, including create and
|
|
185
|
+
update responses. File writes accept `external` URLs and existing `file` URLs and store them as
|
|
186
|
+
links. Upload references (`file_upload`) are unsupported.
|
|
178
187
|
- Relation writes replace the value and reject `has_more: true`.
|
|
179
|
-
- Top-level `created_time` and `last_edited_time` do not depend on the
|
|
180
|
-
- Formula, rollup, unique ID, button, verification, and location reads keep their type but return
|
|
181
|
-
stored text as a string. Formulas and rollups are not evaluated. Missing values return `""`.
|
|
188
|
+
- Top-level `created_time` and `last_edited_time` do not depend on the data source schema.
|
|
182
189
|
|
|
183
190
|
For query properties, filters, and sorts, see
|
|
184
191
|
[Data source property support](data-sources.md#property-support).
|
|
@@ -246,3 +253,45 @@ if (fetched.status === "success") {
|
|
|
246
253
|
if (result.status === "success") console.log(page.properties.Score)
|
|
247
254
|
}
|
|
248
255
|
```
|
|
256
|
+
|
|
257
|
+
## Files and icons
|
|
258
|
+
|
|
259
|
+
The SDK provides five types for icons and file references. Page icons, covers, and file properties
|
|
260
|
+
accept different combinations of these types. Import them from `@notionhq/custom-blocks`.
|
|
261
|
+
|
|
262
|
+
### File and icon types
|
|
263
|
+
|
|
264
|
+
- `NotionIcon` — an icon from Notion's built-in catalog, identified by name with an optional color.
|
|
265
|
+
- `NotionEmoji` — a Unicode emoji.
|
|
266
|
+
- `NotionCustomEmoji` — a workspace custom emoji, identified by ID with an optional name and image
|
|
267
|
+
URL.
|
|
268
|
+
- `NotionExternalFile` — a file hosted outside Notion, referenced by URL.
|
|
269
|
+
- `NotionHostedFile` — a file hosted by Notion, referenced by a URL with an optional expiration
|
|
270
|
+
time.
|
|
271
|
+
|
|
272
|
+
### Where these types are used
|
|
273
|
+
|
|
274
|
+
- **Page icons:** `NotionPageIcon` accepts any of the five types. The same type describes
|
|
275
|
+
`page.icon` and the `icon` field used to create or update a page.
|
|
276
|
+
- **Page covers:** `NotionPageCover` accepts `NotionExternalFile` or `NotionHostedFile`. The same
|
|
277
|
+
type describes `page.cover` and the `cover` field used to create or update a page.
|
|
278
|
+
- **Page file properties:** A property with `type: "files"` contains a `files` array of
|
|
279
|
+
`NotionFilePropertyItem` entries. Each entry combines `NotionExternalFile` or `NotionHostedFile`
|
|
280
|
+
with a required display name (`name`).
|
|
281
|
+
|
|
282
|
+
File upload references are unsupported. File references point to existing URLs.
|
|
283
|
+
|
|
284
|
+
### Native page icons
|
|
285
|
+
|
|
286
|
+
`pages.create`, `dataSources.create`, `page.updateById`, and `page.updateByKey` accept
|
|
287
|
+
`{ type: "icon", icon: { name: "star", color: "blue" } }` in the `icon` field.
|
|
288
|
+
|
|
289
|
+
The host resolves aliases and defaults omitted colors to gray. Native icons require a protocol 9
|
|
290
|
+
host. `NotionIconName` accepts any string. Reads and writes preserve optional colors and future icon
|
|
291
|
+
fields. `NotionIconColor` accepts any string and suggests known colors for autocomplete.
|
|
292
|
+
|
|
293
|
+
### URL permissions
|
|
294
|
+
|
|
295
|
+
External icon and cover writes require an HTTPS origin allowed by the block's network permissions.
|
|
296
|
+
The host checks the submitted URL; allowlisted origins are trusted to redirect. Without network
|
|
297
|
+
permission, URL-backed writes fail before changing the page.
|
package/docs/users.md
CHANGED
|
@@ -153,8 +153,8 @@ APIs.
|
|
|
153
153
|
A user returned by `users.list()` does not necessarily have access to the current page or data
|
|
154
154
|
source. Do not use this list to check page or data source permissions.
|
|
155
155
|
|
|
156
|
-
Declare `{
|
|
157
|
-
|
|
156
|
+
Declare `{ action: "user.read", resource: "workspace" }` for `users.get()` on another user and for
|
|
157
|
+
`users.list()`, and `user.read_email` for `person.email`. See [grants](grants.md).
|
|
158
158
|
|
|
159
159
|
If a request returns `status: "error"`, handle the error before reading `result.user` or
|
|
160
160
|
`result.list`. See [error handling](errors.md).
|
package/package.json
CHANGED
|
@@ -6,36 +6,8 @@ import type { CustomBlockInitResultErrorInfo } from "@notionhq/custom-blocks-pro
|
|
|
6
6
|
import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
|
|
7
7
|
import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
|
|
8
8
|
import type { InvalidHostMessage } from "@notionhq/custom-blocks-protocol/messages/invalidHostMessage.js"
|
|
9
|
-
import type { BridgeMessagePayload } from "@notionhq/custom-blocks-protocol/messages/messagePayload.js"
|
|
10
9
|
import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/messages/sandboxToHost.js"
|
|
11
|
-
import
|
|
12
|
-
OpenExternalUrlMessage,
|
|
13
|
-
OpenExternalUrlResultMessage,
|
|
14
|
-
} from "@notionhq/custom-blocks-protocol/navigation/openExternalUrl.js"
|
|
15
|
-
import type {
|
|
16
|
-
CreatePageMessage,
|
|
17
|
-
CreatePageResultMessage,
|
|
18
|
-
} from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
|
|
19
|
-
import type {
|
|
20
|
-
GetPageMessage,
|
|
21
|
-
GetPageResultMessage,
|
|
22
|
-
} from "@notionhq/custom-blocks-protocol/pages/messages/getPage.js"
|
|
23
|
-
import type {
|
|
24
|
-
OpenPageMessage,
|
|
25
|
-
OpenPageResultMessage,
|
|
26
|
-
} from "@notionhq/custom-blocks-protocol/pages/messages/openPage.js"
|
|
27
|
-
import type {
|
|
28
|
-
UpdatePageMessage,
|
|
29
|
-
UpdatePageResultMessage,
|
|
30
|
-
} from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
31
|
-
import type {
|
|
32
|
-
GetUserMessage,
|
|
33
|
-
GetUserResultMessage,
|
|
34
|
-
} from "@notionhq/custom-blocks-protocol/users/messages/getUser.js"
|
|
35
|
-
import type {
|
|
36
|
-
ListUsersMessage,
|
|
37
|
-
ListUsersResultMessage,
|
|
38
|
-
} from "@notionhq/custom-blocks-protocol/users/messages/listUsers.js"
|
|
10
|
+
import { readRequestId } from "@notionhq/custom-blocks-protocol/utils/readRequestId.js"
|
|
39
11
|
import * as v from "valibot"
|
|
40
12
|
import { applyContextMessage } from "../context/applyContextMessage.js"
|
|
41
13
|
import type { CustomBlockHostState } from "../context/hostState.js"
|
|
@@ -47,17 +19,11 @@ import { notifyListener } from "../utils/notifyListener.js"
|
|
|
47
19
|
import { unreachable } from "../utils/unreachable.js"
|
|
48
20
|
import { SandboxInitialization } from "./initialization/SandboxInitialization.js"
|
|
49
21
|
import type { MessageInterceptor } from "./messageInterceptor.js"
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
type MessageLogEntry = {
|
|
57
|
-
timestamp: string
|
|
58
|
-
direction: "sent" | "received"
|
|
59
|
-
data: unknown
|
|
60
|
-
}
|
|
22
|
+
import {
|
|
23
|
+
type RequestMessage,
|
|
24
|
+
Requests,
|
|
25
|
+
type ResponseSchema,
|
|
26
|
+
} from "./requests.js"
|
|
61
27
|
|
|
62
28
|
export class SandboxBridge {
|
|
63
29
|
private hostState: CustomBlockHostState = {
|
|
@@ -72,29 +38,7 @@ export class SandboxBridge {
|
|
|
72
38
|
(message: QueryDataSourceResultMessage) => void
|
|
73
39
|
>()
|
|
74
40
|
private messageInterceptors = new Set<MessageInterceptor>()
|
|
75
|
-
private
|
|
76
|
-
private messageLogListeners = new Set<() => void>()
|
|
77
|
-
private readonly pendingCreatePage = new PendingRequests<
|
|
78
|
-
BridgeMessagePayload<CreatePageResultMessage>
|
|
79
|
-
>("custom-block-create-page")
|
|
80
|
-
private readonly pendingGetPage = new PendingRequests<
|
|
81
|
-
BridgeMessagePayload<GetPageResultMessage>
|
|
82
|
-
>("custom-block-get-page")
|
|
83
|
-
private readonly pendingGetUser = new PendingRequests<
|
|
84
|
-
BridgeMessagePayload<GetUserResultMessage>
|
|
85
|
-
>("custom-block-get-user")
|
|
86
|
-
private readonly pendingListUsers = new PendingRequests<
|
|
87
|
-
BridgeMessagePayload<ListUsersResultMessage>
|
|
88
|
-
>("custom-block-list-users")
|
|
89
|
-
private readonly pendingOpenPage = new PendingRequests<
|
|
90
|
-
BridgeMessagePayload<OpenPageResultMessage>
|
|
91
|
-
>("custom-block-open-page")
|
|
92
|
-
private readonly pendingOpenExternalUrl = new PendingRequests<
|
|
93
|
-
BridgeMessagePayload<OpenExternalUrlResultMessage>
|
|
94
|
-
>("custom-block-open-url")
|
|
95
|
-
private readonly pendingUpdatePage = new PendingRequests<
|
|
96
|
-
BridgeMessagePayload<UpdatePageResultMessage>
|
|
97
|
-
>("custom-block-update-page")
|
|
41
|
+
private readonly requests = new Requests(message => this.postToHost(message))
|
|
98
42
|
private latestDataSourceBindings: BridgeDataSourceBindings = {}
|
|
99
43
|
private isListening = false
|
|
100
44
|
private isDisposed = false
|
|
@@ -115,10 +59,11 @@ export class SandboxBridge {
|
|
|
115
59
|
* acknowledgment callbacks, removes the message listener, and discards queued
|
|
116
60
|
* outbound messages. Further host messages are ignored.
|
|
117
61
|
*
|
|
118
|
-
* Pending
|
|
62
|
+
* Pending requests complete with request_disposed, and their timers are cleared.
|
|
119
63
|
*/
|
|
120
64
|
dispose() {
|
|
121
65
|
this.isDisposed = true
|
|
66
|
+
this.requests.disposeAll()
|
|
122
67
|
this.initialization.dispose()
|
|
123
68
|
if (this.isListening) {
|
|
124
69
|
window.removeEventListener("message", this.handleMessage)
|
|
@@ -126,7 +71,6 @@ export class SandboxBridge {
|
|
|
126
71
|
}
|
|
127
72
|
this.listeners.clear()
|
|
128
73
|
this.dataSourceQueryListeners.clear()
|
|
129
|
-
this.messageLogListeners.clear()
|
|
130
74
|
}
|
|
131
75
|
|
|
132
76
|
startListening() {
|
|
@@ -137,31 +81,6 @@ export class SandboxBridge {
|
|
|
137
81
|
window.addEventListener("message", this.handleMessage)
|
|
138
82
|
}
|
|
139
83
|
|
|
140
|
-
private static MAX_LOG_ENTRIES = 100
|
|
141
|
-
|
|
142
|
-
private logMessage(direction: "sent" | "received", data: unknown) {
|
|
143
|
-
if (this.messageLog.length >= SandboxBridge.MAX_LOG_ENTRIES) {
|
|
144
|
-
this.messageLog.shift()
|
|
145
|
-
}
|
|
146
|
-
this.messageLog.push({
|
|
147
|
-
timestamp: new Date().toISOString(),
|
|
148
|
-
direction,
|
|
149
|
-
data: redactExternalUrl(data),
|
|
150
|
-
})
|
|
151
|
-
for (const listener of this.messageLogListeners) {
|
|
152
|
-
listener()
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
getMessageLog = (): readonly MessageLogEntry[] => {
|
|
157
|
-
return this.messageLog
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
subscribeToMessageLog = (listener: () => void) => {
|
|
161
|
-
this.messageLogListeners.add(listener)
|
|
162
|
-
return () => this.messageLogListeners.delete(listener)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
84
|
registerMessageInterceptor(interceptor: MessageInterceptor): () => void {
|
|
166
85
|
this.messageInterceptors.add(interceptor)
|
|
167
86
|
return () => this.messageInterceptors.delete(interceptor)
|
|
@@ -179,7 +98,6 @@ export class SandboxBridge {
|
|
|
179
98
|
return
|
|
180
99
|
}
|
|
181
100
|
}
|
|
182
|
-
this.logMessage("sent", message)
|
|
183
101
|
window.parent.postMessage(message, "*")
|
|
184
102
|
}
|
|
185
103
|
|
|
@@ -194,7 +112,6 @@ export class SandboxBridge {
|
|
|
194
112
|
if (this.isDisposed) {
|
|
195
113
|
return
|
|
196
114
|
}
|
|
197
|
-
this.logMessage("received", data)
|
|
198
115
|
|
|
199
116
|
const parsed = v.safeParse(hostToSandboxMessageSchema, data)
|
|
200
117
|
if (!parsed.success) {
|
|
@@ -212,6 +129,15 @@ export class SandboxBridge {
|
|
|
212
129
|
) {
|
|
213
130
|
return
|
|
214
131
|
}
|
|
132
|
+
const requestId = readRequestId(data)
|
|
133
|
+
const reason = formatInvalidHostReason(incomingType, parsed.issues)
|
|
134
|
+
if (requestId !== undefined) {
|
|
135
|
+
this.requests.fail(requestId, {
|
|
136
|
+
code: "invalid_host_message",
|
|
137
|
+
message: reason,
|
|
138
|
+
isRetryable: false,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
215
141
|
// Loop guard: never NACK a NACK. Excludes both directions —
|
|
216
142
|
// `invalidSandboxMessage` is what the host normally sends, but
|
|
217
143
|
// a buggy host that echoes our own `invalidHostMessage` back
|
|
@@ -222,7 +148,8 @@ export class SandboxBridge {
|
|
|
222
148
|
) {
|
|
223
149
|
const nack: InvalidHostMessage = {
|
|
224
150
|
type: "invalidHostMessage",
|
|
225
|
-
|
|
151
|
+
...(requestId !== undefined ? { requestId } : {}),
|
|
152
|
+
reason,
|
|
226
153
|
}
|
|
227
154
|
this.postToHost(nack)
|
|
228
155
|
}
|
|
@@ -230,11 +157,14 @@ export class SandboxBridge {
|
|
|
230
157
|
}
|
|
231
158
|
const message = parsed.output
|
|
232
159
|
|
|
233
|
-
// If the host couldn't parse one of our outbound sandbox-to-host messages, it sends back an
|
|
234
|
-
// `invalidSandboxMessage` NACK with a human-readable `reason`. Log it for developer
|
|
235
|
-
// visibility and stop. We don't retry as the sandbox can't recover from a host-side parse
|
|
236
|
-
// failure on its own.
|
|
237
160
|
if (message.type === "invalidSandboxMessage") {
|
|
161
|
+
if (message.requestId !== undefined) {
|
|
162
|
+
this.requests.fail(message.requestId, {
|
|
163
|
+
code: "invalid_sandbox_message",
|
|
164
|
+
message: message.reason,
|
|
165
|
+
isRetryable: false,
|
|
166
|
+
})
|
|
167
|
+
}
|
|
238
168
|
console.warn(
|
|
239
169
|
"[custom-blocks-sdk] host reported invalid sandbox message:",
|
|
240
170
|
message.reason,
|
|
@@ -258,6 +188,18 @@ export class SandboxBridge {
|
|
|
258
188
|
return
|
|
259
189
|
}
|
|
260
190
|
|
|
191
|
+
if ("requestId" in message) {
|
|
192
|
+
const error = this.requests.receive(message)
|
|
193
|
+
if (error !== undefined) {
|
|
194
|
+
this.postToHost({
|
|
195
|
+
type: "invalidHostMessage",
|
|
196
|
+
requestId: message.requestId,
|
|
197
|
+
reason: error.message,
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
|
|
261
203
|
switch (message.type) {
|
|
262
204
|
case "themeChanged":
|
|
263
205
|
case "contrastModeChanged":
|
|
@@ -278,76 +220,6 @@ export class SandboxBridge {
|
|
|
278
220
|
return
|
|
279
221
|
}
|
|
280
222
|
|
|
281
|
-
case "createPageResult": {
|
|
282
|
-
const { type: _, requestId, ...result } = message
|
|
283
|
-
if (!this.pendingCreatePage.resolve(requestId, result)) {
|
|
284
|
-
console.warn(
|
|
285
|
-
`[custom-blocks-sdk] createPageResult for unknown requestId ${message.requestId}`,
|
|
286
|
-
)
|
|
287
|
-
}
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
case "getPageResult": {
|
|
292
|
-
const { type: _, requestId, ...result } = message
|
|
293
|
-
if (!this.pendingGetPage.resolve(requestId, result)) {
|
|
294
|
-
console.warn(
|
|
295
|
-
`[custom-blocks-sdk] getPageResult for unknown requestId ${message.requestId}`,
|
|
296
|
-
)
|
|
297
|
-
}
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
case "getUserResult": {
|
|
302
|
-
const { type: _, requestId, ...result } = message
|
|
303
|
-
if (!this.pendingGetUser.resolve(requestId, result)) {
|
|
304
|
-
console.warn(
|
|
305
|
-
`[custom-blocks-sdk] getUserResult for unknown requestId ${message.requestId}`,
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
return
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
case "listUsersResult": {
|
|
312
|
-
const { type: _, requestId, ...result } = message
|
|
313
|
-
if (!this.pendingListUsers.resolve(requestId, result)) {
|
|
314
|
-
console.warn(
|
|
315
|
-
`[custom-blocks-sdk] listUsersResult for unknown requestId ${message.requestId}`,
|
|
316
|
-
)
|
|
317
|
-
}
|
|
318
|
-
return
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
case "openPageResult": {
|
|
322
|
-
const { type: _, requestId, ...result } = message
|
|
323
|
-
if (!this.pendingOpenPage.resolve(requestId, result)) {
|
|
324
|
-
console.warn(
|
|
325
|
-
`[custom-blocks-sdk] openPageResult for unknown requestId ${message.requestId}`,
|
|
326
|
-
)
|
|
327
|
-
}
|
|
328
|
-
return
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
case "openExternalUrlResult": {
|
|
332
|
-
const { type: _, requestId, ...result } = message
|
|
333
|
-
if (!this.pendingOpenExternalUrl.resolve(requestId, result)) {
|
|
334
|
-
console.warn(
|
|
335
|
-
`[custom-blocks-sdk] openExternalUrlResult for unknown requestId ${message.requestId}`,
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
return
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
case "updatePageResult": {
|
|
342
|
-
const { type: _, requestId, ...result } = message
|
|
343
|
-
if (!this.pendingUpdatePage.resolve(requestId, result)) {
|
|
344
|
-
console.warn(
|
|
345
|
-
`[custom-blocks-sdk] updatePageResult for unknown requestId ${message.requestId}`,
|
|
346
|
-
)
|
|
347
|
-
}
|
|
348
|
-
return
|
|
349
|
-
}
|
|
350
|
-
|
|
351
223
|
case "queryDataSourceResult": {
|
|
352
224
|
const listener = this.dataSourceQueryListeners.get(
|
|
353
225
|
message.subscriptionId,
|
|
@@ -414,67 +286,11 @@ export class SandboxBridge {
|
|
|
414
286
|
return undefined
|
|
415
287
|
}
|
|
416
288
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
this.postToHost({ type: "createPage", requestId, ...args })
|
|
423
|
-
})
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
requestGetPage(
|
|
427
|
-
args: Omit<GetPageMessage, "type" | "requestId">,
|
|
428
|
-
): Promise<BridgeMessagePayload<GetPageResultMessage>> {
|
|
429
|
-
return new Promise(resolve => {
|
|
430
|
-
const requestId = this.pendingGetPage.allocate(resolve)
|
|
431
|
-
this.postToHost({ type: "getPage", requestId, ...args })
|
|
432
|
-
})
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
requestUpdatePage(
|
|
436
|
-
args: Omit<UpdatePageMessage, "type" | "requestId">,
|
|
437
|
-
): Promise<BridgeMessagePayload<UpdatePageResultMessage>> {
|
|
438
|
-
return new Promise(resolve => {
|
|
439
|
-
const requestId = this.pendingUpdatePage.allocate(resolve)
|
|
440
|
-
this.postToHost({ type: "updatePage", requestId, ...args })
|
|
441
|
-
})
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
requestGetUser(
|
|
445
|
-
args: Omit<GetUserMessage, "type" | "requestId">,
|
|
446
|
-
): Promise<BridgeMessagePayload<GetUserResultMessage>> {
|
|
447
|
-
return new Promise(resolve => {
|
|
448
|
-
const requestId = this.pendingGetUser.allocate(resolve)
|
|
449
|
-
this.postToHost({ type: "getUser", requestId, ...args })
|
|
450
|
-
})
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
requestListUsers(
|
|
454
|
-
args: Omit<ListUsersMessage, "type" | "requestId">,
|
|
455
|
-
): Promise<BridgeMessagePayload<ListUsersResultMessage>> {
|
|
456
|
-
return new Promise(resolve => {
|
|
457
|
-
const requestId = this.pendingListUsers.allocate(resolve)
|
|
458
|
-
this.postToHost({ type: "listUsers", requestId, ...args })
|
|
459
|
-
})
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
requestOpenPage(
|
|
463
|
-
args: Omit<OpenPageMessage, "type" | "requestId">,
|
|
464
|
-
): Promise<BridgeMessagePayload<OpenPageResultMessage>> {
|
|
465
|
-
return new Promise(resolve => {
|
|
466
|
-
const requestId = this.pendingOpenPage.allocate(resolve)
|
|
467
|
-
this.postToHost({ type: "openPage", requestId, ...args })
|
|
468
|
-
})
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
requestOpenExternalUrl(
|
|
472
|
-
args: Omit<OpenExternalUrlMessage, "type" | "requestId">,
|
|
473
|
-
): Promise<BridgeMessagePayload<OpenExternalUrlResultMessage>> {
|
|
474
|
-
return new Promise(resolve => {
|
|
475
|
-
const requestId = this.pendingOpenExternalUrl.allocate(resolve)
|
|
476
|
-
this.postToHost({ type: "openExternalUrl", requestId, ...args })
|
|
477
|
-
})
|
|
289
|
+
request<Schema extends ResponseSchema>(
|
|
290
|
+
message: RequestMessage,
|
|
291
|
+
responseSchema: Schema,
|
|
292
|
+
) {
|
|
293
|
+
return this.requests.send(message, responseSchema)
|
|
478
294
|
}
|
|
479
295
|
}
|
|
480
296
|
|
|
@@ -500,21 +316,6 @@ function readInitializationId(data: unknown): string | undefined {
|
|
|
500
316
|
return undefined
|
|
501
317
|
}
|
|
502
318
|
|
|
503
|
-
function redactExternalUrl(data: unknown): unknown {
|
|
504
|
-
if (
|
|
505
|
-
typeof data === "object" &&
|
|
506
|
-
data !== null &&
|
|
507
|
-
"type" in data &&
|
|
508
|
-
data.type === "openExternalUrl"
|
|
509
|
-
) {
|
|
510
|
-
return {
|
|
511
|
-
type: "openExternalUrl",
|
|
512
|
-
...("requestId" in data ? { requestId: data.requestId } : {}),
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
return data
|
|
516
|
-
}
|
|
517
|
-
|
|
518
319
|
function formatInvalidHostReason(
|
|
519
320
|
incomingType: string | undefined,
|
|
520
321
|
issues: readonly v.BaseIssue<unknown>[],
|