@notionhq/custom-blocks 0.4.0 → 0.5.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/dist/bridge/SandboxBridge.d.ts +0 -16
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +2 -41
- package/dist/bridge/parseHostToSandboxMessage.d.ts +3658 -0
- package/dist/bridge/parseHostToSandboxMessage.d.ts.map +1 -0
- package/dist/bridge/parseHostToSandboxMessage.js +47 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.js +3 -3
- package/dist/dataSources/bridge/resolveDataSources.js +5 -5
- 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/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 +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/initialization/getInitBindingError.js +2 -2
- package/dist/manifest/types.d.ts +4 -3
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/pages/bridge/getPageForDataSource.js +1 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +4 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -2
- package/dist/pages/bridge/updatePage.js +1 -1
- package/dist/pages/properties/getPropertyByKey.js +2 -2
- package/dist/pages/types.d.ts +8 -10
- 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 +6 -7
- 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 +3 -0
- package/dist/protocol/context/parent.js +6 -1
- package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +3 -7
- package/dist/protocol/dataSources/bridgeDataSourceBinding.js +5 -5
- package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +2 -6
- 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 -6
- 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 -6
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +1470 -26
- package/dist/protocol/dataSources/notionDataSource.d.ts +3 -11
- package/dist/protocol/dataSources/notionDataSource.js +5 -5
- package/dist/protocol/dataSources/properties/propertySchema.d.ts +4 -9
- package/dist/protocol/dataSources/properties/propertySchema.js +2 -4
- 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 +1 -1
- package/dist/protocol/handshake/init.d.ts +9 -7
- package/dist/protocol/icons.d.ts +22 -7
- package/dist/protocol/icons.js +19 -7
- package/dist/protocol/index.d.ts +16 -14
- package/dist/protocol/index.js +10 -7
- package/dist/protocol/manifest/manifest.d.ts +9 -9
- package/dist/protocol/manifest/manifest.js +7 -7
- package/dist/protocol/messages/hostToSandbox.d.ts +100 -103
- package/dist/protocol/messages/sandboxToHost.d.ts +1471 -37
- package/dist/protocol/pages/bridgePage.d.ts +6 -7
- package/dist/protocol/pages/bridgePage.js +3 -3
- package/dist/protocol/pages/messages/createPage.d.ts +547 -40
- package/dist/protocol/pages/messages/createPage.js +27 -15
- package/dist/protocol/pages/messages/getPage.d.ts +18 -21
- package/dist/protocol/pages/messages/updatePage.d.ts +21 -28
- package/dist/protocol/pages/messages/updatePage.js +3 -3
- package/dist/protocol/pages/pageAppearance.d.ts +5 -59
- package/dist/protocol/pages/pageAppearance.js +11 -40
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +4 -12
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +2 -6
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +2 -7
- package/dist/protocol/utils/ids.d.ts +2 -0
- package/dist/protocol/utils/ids.js +1 -0
- package/dist/protocol/utils/protocolVersion.d.ts +2 -1
- package/dist/protocol/utils/protocolVersion.js +3 -1
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +1 -15
- package/dist/utils/version.js +1 -1
- package/docs/data-sources.md +75 -76
- package/docs/deployment.md +4 -5
- package/docs/pages.md +90 -56
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +3 -58
- package/src/bridge/parseHostToSandboxMessage.ts +54 -0
- package/src/dataSources/bridge/resolveDataSourceQuery.ts +3 -3
- package/src/dataSources/bridge/resolveDataSources.ts +6 -6
- 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/files/files.ts +5 -0
- package/src/files/icons.ts +9 -0
- package/src/index.ts +6 -11
- package/src/initialization/getInitBindingError.ts +2 -2
- package/src/manifest/types.ts +9 -3
- package/src/pages/bridge/getPageForDataSource.ts +1 -1
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -2
- package/src/pages/bridge/updatePage.ts +1 -1
- package/src/pages/properties/getPropertyByKey.ts +2 -2
- package/src/pages/types.ts +9 -13
- package/src/react/NotionCustomBlock.tsx +1 -16
- package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +0 -17
- package/dist/protocol/dataSources/filters/createdByFilterOperator.js +0 -11
- 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/src/react/DebugMessageLog.tsx +0 -34
package/docs/pages.md
CHANGED
|
@@ -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,64 +119,71 @@ 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
|
-
| `created_time` | 🟢
|
|
162
|
-
| `last_edited_time` | 🟢
|
|
163
|
-
| `created_by` | 🟢 Actor
|
|
164
|
-
| `last_edited_by` | 🟢 Actor
|
|
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 | 🟢 Supported | 🟢 Supported |
|
|
151
|
+
| `people` | 🟢 Array of user or group ID objects | 🟢 Supported | 🟢 Supported |
|
|
152
|
+
| `relation` | 🟢 Array of page ID objects | 🟡 Replaces value | 🟡 Replaces value |
|
|
153
|
+
| `place` | 🟢 Coordinates and optional place details | 🟢 Supported | 🟢 Supported |
|
|
154
|
+
| `files` | 🟢 External links and hosted files | 🔴 Unavailable | 🔴 Unavailable |
|
|
155
|
+
| `unique_id` | 🟡 Formatted ID | 🔴 Unavailable | 🔴 Unavailable |
|
|
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 |
|
|
165
164
|
|
|
166
165
|
### Notes
|
|
167
166
|
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
-
|
|
173
|
-
|
|
174
|
-
-
|
|
175
|
-
|
|
176
|
-
|
|
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.
|
|
181
|
+
- Date-time writes support minute precision. Seconds and milliseconds are not preserved.
|
|
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.
|
|
177
185
|
- Relation writes replace the value and reject `has_more: true`.
|
|
178
|
-
- Top-level `created_time` and `last_edited_time` do not depend on the
|
|
179
|
-
- Formula, rollup, unique ID, button, verification, and location reads keep their type but return
|
|
180
|
-
stored text as a string. Formulas and rollups are not evaluated. Missing values return `""`.
|
|
186
|
+
- Top-level `created_time` and `last_edited_time` do not depend on the data source schema.
|
|
181
187
|
|
|
182
188
|
For query properties, filters, and sorts, see
|
|
183
189
|
[Data source property support](data-sources.md#property-support).
|
|
@@ -246,15 +252,43 @@ if (fetched.status === "success") {
|
|
|
246
252
|
}
|
|
247
253
|
```
|
|
248
254
|
|
|
255
|
+
## Files and icons
|
|
256
|
+
|
|
257
|
+
The SDK provides five types for icons and file references. Page icons, covers, and file properties
|
|
258
|
+
accept different combinations of these types. Import them from `@notionhq/custom-blocks`.
|
|
259
|
+
|
|
260
|
+
### File and icon types
|
|
261
|
+
|
|
262
|
+
- `NotionIcon` — an icon from Notion's built-in catalog, identified by name with an optional color.
|
|
263
|
+
- `NotionEmoji` — a Unicode emoji.
|
|
264
|
+
- `NotionCustomEmoji` — a workspace custom emoji, identified by ID with an optional name and image
|
|
265
|
+
URL.
|
|
266
|
+
- `NotionExternalFile` — a file hosted outside Notion, referenced by URL.
|
|
267
|
+
- `NotionHostedFile` — a file hosted by Notion, referenced by a URL with an optional expiration
|
|
268
|
+
time.
|
|
269
|
+
|
|
270
|
+
### Where these types are used
|
|
271
|
+
|
|
272
|
+
- **Page icons:** `NotionPageIcon` accepts any of the five types. The same type describes
|
|
273
|
+
`page.icon` and the `icon` field used to create or update a page.
|
|
274
|
+
- **Page covers:** `NotionPageCover` accepts `NotionExternalFile` or `NotionHostedFile`. The same
|
|
275
|
+
type describes `page.cover` and the `cover` field used to create or update a page.
|
|
276
|
+
- **Page file properties:** A property with `type: "files"` contains a `files` array of
|
|
277
|
+
`NotionFilePropertyItem` entries. Each entry combines `NotionExternalFile` or `NotionHostedFile`
|
|
278
|
+
with a required display name (`name`).
|
|
279
|
+
|
|
280
|
+
File upload references are unsupported. File references point to existing URLs.
|
|
281
|
+
|
|
249
282
|
### Native page icons
|
|
250
283
|
|
|
251
284
|
`pages.create`, `dataSources.create`, `page.updateById`, and `page.updateByKey` accept
|
|
252
|
-
`{ type: "icon", icon: { name: "star", color: "blue" } }
|
|
285
|
+
`{ type: "icon", icon: { name: "star", color: "blue" } }` in the `icon` field.
|
|
253
286
|
|
|
254
287
|
The host resolves aliases and defaults omitted colors to gray. Native icons require a protocol 9
|
|
255
|
-
host. `NotionIconName` accepts any string. Reads and writes
|
|
256
|
-
|
|
257
|
-
|
|
288
|
+
host. `NotionIconName` accepts any string. Reads and writes preserve optional colors and future icon
|
|
289
|
+
fields. `NotionIconColor` accepts any string and suggests known colors for autocomplete.
|
|
290
|
+
|
|
291
|
+
### URL permissions
|
|
258
292
|
|
|
259
293
|
External icon and cover writes require an HTTPS origin allowed by the block's network permissions.
|
|
260
294
|
The host checks the submitted URL; allowlisted origins are trusted to redirect. Without network
|
package/package.json
CHANGED
|
@@ -3,12 +3,11 @@ import type { BridgeDataSourceBindings } from "@notionhq/custom-blocks-protocol/
|
|
|
3
3
|
import type { QueryDataSourceResultMessage } from "@notionhq/custom-blocks-protocol/dataSources/messages/queryDataSource.js"
|
|
4
4
|
import type { InitMessage } from "@notionhq/custom-blocks-protocol/handshake/init.js"
|
|
5
5
|
import type { CustomBlockInitResultErrorInfo } from "@notionhq/custom-blocks-protocol/handshake/initResult.js"
|
|
6
|
-
import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
|
|
7
6
|
import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
|
|
8
7
|
import type { InvalidHostMessage } from "@notionhq/custom-blocks-protocol/messages/invalidHostMessage.js"
|
|
9
8
|
import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/messages/sandboxToHost.js"
|
|
10
9
|
import { readRequestId } from "@notionhq/custom-blocks-protocol/utils/readRequestId.js"
|
|
11
|
-
import * as v from "valibot"
|
|
10
|
+
import type * as v from "valibot"
|
|
12
11
|
import { applyContextMessage } from "../context/applyContextMessage.js"
|
|
13
12
|
import type { CustomBlockHostState } from "../context/hostState.js"
|
|
14
13
|
import { syncDocumentAppearance } from "../context/syncDocumentAppearance.js"
|
|
@@ -19,22 +18,13 @@ import { notifyListener } from "../utils/notifyListener.js"
|
|
|
19
18
|
import { unreachable } from "../utils/unreachable.js"
|
|
20
19
|
import { SandboxInitialization } from "./initialization/SandboxInitialization.js"
|
|
21
20
|
import type { MessageInterceptor } from "./messageInterceptor.js"
|
|
21
|
+
import { parseHostToSandboxMessage } from "./parseHostToSandboxMessage.js"
|
|
22
22
|
import {
|
|
23
23
|
type RequestMessage,
|
|
24
24
|
Requests,
|
|
25
25
|
type ResponseSchema,
|
|
26
26
|
} from "./requests.js"
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* A single entry in the bridge message log. Kept intentionally plain so the log is copy-pasteable
|
|
30
|
-
* to a local coding agent without needing extra context.
|
|
31
|
-
*/
|
|
32
|
-
type MessageLogEntry = {
|
|
33
|
-
timestamp: string
|
|
34
|
-
direction: "sent" | "received"
|
|
35
|
-
data: unknown
|
|
36
|
-
}
|
|
37
|
-
|
|
38
28
|
export class SandboxBridge {
|
|
39
29
|
private hostState: CustomBlockHostState = {
|
|
40
30
|
status: "uninitialized",
|
|
@@ -48,8 +38,6 @@ export class SandboxBridge {
|
|
|
48
38
|
(message: QueryDataSourceResultMessage) => void
|
|
49
39
|
>()
|
|
50
40
|
private messageInterceptors = new Set<MessageInterceptor>()
|
|
51
|
-
private messageLog: MessageLogEntry[] = []
|
|
52
|
-
private messageLogListeners = new Set<() => void>()
|
|
53
41
|
private readonly requests = new Requests(message => this.postToHost(message))
|
|
54
42
|
private latestDataSourceBindings: BridgeDataSourceBindings = {}
|
|
55
43
|
private isListening = false
|
|
@@ -83,7 +71,6 @@ export class SandboxBridge {
|
|
|
83
71
|
}
|
|
84
72
|
this.listeners.clear()
|
|
85
73
|
this.dataSourceQueryListeners.clear()
|
|
86
|
-
this.messageLogListeners.clear()
|
|
87
74
|
}
|
|
88
75
|
|
|
89
76
|
startListening() {
|
|
@@ -94,31 +81,6 @@ export class SandboxBridge {
|
|
|
94
81
|
window.addEventListener("message", this.handleMessage)
|
|
95
82
|
}
|
|
96
83
|
|
|
97
|
-
private static MAX_LOG_ENTRIES = 100
|
|
98
|
-
|
|
99
|
-
private logMessage(direction: "sent" | "received", data: unknown) {
|
|
100
|
-
if (this.messageLog.length >= SandboxBridge.MAX_LOG_ENTRIES) {
|
|
101
|
-
this.messageLog.shift()
|
|
102
|
-
}
|
|
103
|
-
this.messageLog.push({
|
|
104
|
-
timestamp: new Date().toISOString(),
|
|
105
|
-
direction,
|
|
106
|
-
data: redactExternalUrl(data),
|
|
107
|
-
})
|
|
108
|
-
for (const listener of this.messageLogListeners) {
|
|
109
|
-
listener()
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
getMessageLog = (): readonly MessageLogEntry[] => {
|
|
114
|
-
return this.messageLog
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
subscribeToMessageLog = (listener: () => void) => {
|
|
118
|
-
this.messageLogListeners.add(listener)
|
|
119
|
-
return () => this.messageLogListeners.delete(listener)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
84
|
registerMessageInterceptor(interceptor: MessageInterceptor): () => void {
|
|
123
85
|
this.messageInterceptors.add(interceptor)
|
|
124
86
|
return () => this.messageInterceptors.delete(interceptor)
|
|
@@ -136,7 +98,6 @@ export class SandboxBridge {
|
|
|
136
98
|
return
|
|
137
99
|
}
|
|
138
100
|
}
|
|
139
|
-
this.logMessage("sent", message)
|
|
140
101
|
window.parent.postMessage(message, "*")
|
|
141
102
|
}
|
|
142
103
|
|
|
@@ -151,9 +112,8 @@ export class SandboxBridge {
|
|
|
151
112
|
if (this.isDisposed) {
|
|
152
113
|
return
|
|
153
114
|
}
|
|
154
|
-
this.logMessage("received", data)
|
|
155
115
|
|
|
156
|
-
const parsed =
|
|
116
|
+
const parsed = parseHostToSandboxMessage(data)
|
|
157
117
|
if (!parsed.success) {
|
|
158
118
|
console.warn(
|
|
159
119
|
"[custom-blocks-sdk] ignoring malformed host message",
|
|
@@ -356,21 +316,6 @@ function readInitializationId(data: unknown): string | undefined {
|
|
|
356
316
|
return undefined
|
|
357
317
|
}
|
|
358
318
|
|
|
359
|
-
function redactExternalUrl(data: unknown): unknown {
|
|
360
|
-
if (
|
|
361
|
-
typeof data === "object" &&
|
|
362
|
-
data !== null &&
|
|
363
|
-
"type" in data &&
|
|
364
|
-
data.type === "openExternalUrl"
|
|
365
|
-
) {
|
|
366
|
-
return {
|
|
367
|
-
type: "openExternalUrl",
|
|
368
|
-
...("requestId" in data ? { requestId: data.requestId } : {}),
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return data
|
|
372
|
-
}
|
|
373
|
-
|
|
374
319
|
function formatInvalidHostReason(
|
|
375
320
|
incomingType: string | undefined,
|
|
376
321
|
issues: readonly v.BaseIssue<unknown>[],
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { bridgeDataSourceBindingSchema } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceBinding.js"
|
|
2
|
+
import { dataSourcePointerValidator } from "@notionhq/custom-blocks-protocol/dataSources/dataSourcePointer.js"
|
|
3
|
+
import { notionDataSourceSchemaValidator } from "@notionhq/custom-blocks-protocol/dataSources/dataSourceSchema.js"
|
|
4
|
+
import { initMessageSchema } from "@notionhq/custom-blocks-protocol/handshake/init.js"
|
|
5
|
+
import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
|
|
6
|
+
import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
|
|
7
|
+
import * as v from "valibot"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Older hosts such as 0.9.0 send `collectionPointer` and `collectionSchema` during
|
|
11
|
+
* initialization and live updates. Normalize these pre-protocol-11 names to
|
|
12
|
+
* `dataSourcePointer` and `dataSourceSchema` before exposing bindings to SDK consumers.
|
|
13
|
+
* Current fields take precedence when both names are present. Malformed fields and
|
|
14
|
+
* invalid property mappings still fail validation; this compatibility does not add
|
|
15
|
+
* host operations or repair bindings the Notion client cannot read from storage.
|
|
16
|
+
*/
|
|
17
|
+
export function parseHostToSandboxMessage(data: unknown) {
|
|
18
|
+
const type = readIncomingType(data)
|
|
19
|
+
if (type === "init" || type === "dataSourcesChanged") {
|
|
20
|
+
return v.safeParse(bindingMessageSchema, data)
|
|
21
|
+
}
|
|
22
|
+
return v.safeParse(hostToSandboxMessageSchema, data)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const bindingSchema = v.pipe(
|
|
26
|
+
v.object({
|
|
27
|
+
...bridgeDataSourceBindingSchema.entries,
|
|
28
|
+
collectionPointer: v.optional(dataSourcePointerValidator),
|
|
29
|
+
collectionSchema: v.optional(notionDataSourceSchemaValidator),
|
|
30
|
+
}),
|
|
31
|
+
v.transform(({ collectionPointer, collectionSchema, ...binding }) => ({
|
|
32
|
+
...binding,
|
|
33
|
+
dataSourcePointer: binding.dataSourcePointer ?? collectionPointer,
|
|
34
|
+
dataSourceSchema: binding.dataSourceSchema ?? collectionSchema,
|
|
35
|
+
})),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const dataSourcesSchema = v.object({
|
|
39
|
+
bindings: v.record(v.string(), bindingSchema),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const bindingMessageSchema = v.variant("type", [
|
|
43
|
+
v.variant("status", [
|
|
44
|
+
v.object({
|
|
45
|
+
...initMessageSchema.options[0].entries,
|
|
46
|
+
dataSources: dataSourcesSchema,
|
|
47
|
+
}),
|
|
48
|
+
initMessageSchema.options[1],
|
|
49
|
+
]),
|
|
50
|
+
v.object({
|
|
51
|
+
type: v.literal("dataSourcesChanged"),
|
|
52
|
+
dataSources: dataSourcesSchema,
|
|
53
|
+
}),
|
|
54
|
+
])
|
|
@@ -44,7 +44,7 @@ export function resolveDataSourceQuery(args: {
|
|
|
44
44
|
if (dataSource.inaccessible === true) {
|
|
45
45
|
return { status: "error", error: dataSourceInaccessibleError(key) }
|
|
46
46
|
}
|
|
47
|
-
if (dataSource.
|
|
47
|
+
if (dataSource.dataSourcePointer === undefined) {
|
|
48
48
|
return {
|
|
49
49
|
status: "error",
|
|
50
50
|
error: {
|
|
@@ -68,7 +68,7 @@ export function resolveDataSourceQuery(args: {
|
|
|
68
68
|
if (
|
|
69
69
|
(queryOptions?.filter !== undefined ||
|
|
70
70
|
(Array.isArray(queryOptions?.sorts) && queryOptions.sorts.length > 0)) &&
|
|
71
|
-
dataSource.
|
|
71
|
+
dataSource.dataSourceSchema === undefined
|
|
72
72
|
) {
|
|
73
73
|
return {
|
|
74
74
|
status: "error",
|
|
@@ -119,7 +119,7 @@ export function resolveDataSourceQuery(args: {
|
|
|
119
119
|
return {
|
|
120
120
|
status: "ok",
|
|
121
121
|
query: {
|
|
122
|
-
dataSourceId: dataSource.
|
|
122
|
+
dataSourceId: dataSource.dataSourcePointer.id,
|
|
123
123
|
limit: limit.limit,
|
|
124
124
|
filter: filter.filter,
|
|
125
125
|
sorts: sorts.sorts,
|
|
@@ -17,12 +17,12 @@ export function resolveDataSources(args: {
|
|
|
17
17
|
return Object.entries(args.manifest.dataSources).map(
|
|
18
18
|
([key, manifestDataSource]) => {
|
|
19
19
|
const binding = args.dataSourceBindings[key]
|
|
20
|
-
const
|
|
21
|
-
binding?.
|
|
20
|
+
const dataSourceProperties =
|
|
21
|
+
binding?.dataSourceSchema?.propertiesById ?? {}
|
|
22
22
|
|
|
23
23
|
const resolvedBinding = resolveDataSourceBinding({
|
|
24
24
|
manifestDataSource,
|
|
25
|
-
|
|
25
|
+
dataSourceSchema: binding?.dataSourceSchema,
|
|
26
26
|
propertyIdsByKey: binding?.propertyIdsByKey,
|
|
27
27
|
})
|
|
28
28
|
const propertyIdsByKey: Record<string, string | undefined> = {}
|
|
@@ -33,10 +33,10 @@ export function resolveDataSources(args: {
|
|
|
33
33
|
|
|
34
34
|
return {
|
|
35
35
|
key,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
dataSourcePointer: binding?.dataSourcePointer,
|
|
37
|
+
dataSourceSchema: binding?.dataSourceSchema,
|
|
38
38
|
propertyIdsByKey,
|
|
39
|
-
propertySchemasById:
|
|
39
|
+
propertySchemasById: dataSourceProperties,
|
|
40
40
|
...(binding?.inaccessible === true && { inaccessible: true }),
|
|
41
41
|
}
|
|
42
42
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BridgeDataSourceFilter } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilter.js"
|
|
2
2
|
import type { BridgeDataSourceFilterCondition } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilterCondition.js"
|
|
3
3
|
import { bridgeDataSourceFilterConditionSchema } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilterCondition.js"
|
|
4
|
+
import type { CustomBlockDateFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
|
|
4
5
|
import { customBlockRelativeDateValueSchema } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
|
|
5
6
|
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
6
7
|
import * as v from "valibot"
|
|
@@ -139,9 +140,17 @@ function parsePropertyFilter(args: {
|
|
|
139
140
|
) {
|
|
140
141
|
return invalidOperator("number")
|
|
141
142
|
}
|
|
143
|
+
let dateOperator: CustomBlockDateFilterOperator | undefined
|
|
144
|
+
if ("date" in filter) {
|
|
145
|
+
dateOperator = filter.date
|
|
146
|
+
} else if ("created_time" in filter) {
|
|
147
|
+
dateOperator = filter.created_time
|
|
148
|
+
} else if ("last_edited_time" in filter) {
|
|
149
|
+
dateOperator = filter.last_edited_time
|
|
150
|
+
}
|
|
142
151
|
if (
|
|
143
|
-
|
|
144
|
-
!Object.entries(
|
|
152
|
+
dateOperator !== undefined &&
|
|
153
|
+
!Object.entries(dateOperator).every(
|
|
145
154
|
([key, entry]) =>
|
|
146
155
|
key === "target" ||
|
|
147
156
|
entry === true ||
|
|
@@ -150,7 +159,7 @@ function parsePropertyFilter(args: {
|
|
|
150
159
|
isValidIsoDate(entry),
|
|
151
160
|
)
|
|
152
161
|
) {
|
|
153
|
-
return invalidOperator(
|
|
162
|
+
return invalidOperator(branch)
|
|
154
163
|
}
|
|
155
164
|
return { status: "ok", filter }
|
|
156
165
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CustomBlockCheckboxFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/checkboxFilterOperator.js"
|
|
2
2
|
import type { CustomBlockContainsFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/containsFilterOperator.js"
|
|
3
|
-
import type { CustomBlockCreatedByFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/createdByFilterOperator.js"
|
|
4
3
|
import type { CustomBlockDateFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
|
|
5
4
|
import type { CustomBlockNumberFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/numberFilterOperator.js"
|
|
6
5
|
import type { CustomBlockOptionFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/optionFilterOperator.js"
|
|
@@ -11,6 +10,7 @@ import type {
|
|
|
11
10
|
import type { CustomBlockRelationFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/relationFilterOperator.js"
|
|
12
11
|
import type { CustomBlockStatusFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/statusFilterOperator.js"
|
|
13
12
|
import type { CustomBlockTextFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/textFilterOperator.js"
|
|
13
|
+
import type { CustomBlockTimestampFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/timestampFilterOperator.js"
|
|
14
14
|
import type { NotionSortDirection } from "@notionhq/custom-blocks-protocol/dataSources/sortDirection.js"
|
|
15
15
|
import type { ExclusiveUnion } from "../../utils/typeUtils.js"
|
|
16
16
|
|
|
@@ -35,8 +35,8 @@ export type NotionDataSourceContainsFilterOperator =
|
|
|
35
35
|
export type NotionDataSourceDateFilterOperator =
|
|
36
36
|
ExclusiveUnion<CustomBlockDateFilterOperator>
|
|
37
37
|
|
|
38
|
-
export type
|
|
39
|
-
ExclusiveUnion<
|
|
38
|
+
export type NotionDataSourceTimestampFilterOperator =
|
|
39
|
+
ExclusiveUnion<CustomBlockTimestampFilterOperator>
|
|
40
40
|
|
|
41
41
|
export type NotionDataSourcePersonFilterValue = CustomBlockPersonFilterValue
|
|
42
42
|
|
|
@@ -63,9 +63,12 @@ export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress &
|
|
|
63
63
|
| { multi_select: NotionDataSourceContainsFilterOperator }
|
|
64
64
|
| { status: NotionDataSourceStatusFilterOperator }
|
|
65
65
|
| { date: NotionDataSourceDateFilterOperator }
|
|
66
|
+
| { created_time: NotionDataSourceTimestampFilterOperator }
|
|
67
|
+
| { last_edited_time: NotionDataSourceTimestampFilterOperator }
|
|
66
68
|
| { people: NotionDataSourcePeopleFilterOperator }
|
|
67
69
|
| { relation: NotionDataSourceRelationFilterOperator }
|
|
68
|
-
| { created_by:
|
|
70
|
+
| { created_by: NotionDataSourcePeopleFilterOperator }
|
|
71
|
+
| { last_edited_by: NotionDataSourcePeopleFilterOperator }
|
|
69
72
|
>
|
|
70
73
|
|
|
71
74
|
export type NotionDataSourceSort = NotionDataSourcePropertyAddress & {
|
|
@@ -46,7 +46,7 @@ export function resolvePropertyAddress(
|
|
|
46
46
|
}
|
|
47
47
|
propertyId = value.propertyId
|
|
48
48
|
}
|
|
49
|
-
const properties = dataSource.
|
|
49
|
+
const properties = dataSource.dataSourceSchema?.propertiesById ?? {}
|
|
50
50
|
if (!Object.hasOwn(properties, propertyId)) {
|
|
51
51
|
return {
|
|
52
52
|
status: "error",
|
|
@@ -118,7 +118,7 @@ function resolveWriteIdentifier(args: {
|
|
|
118
118
|
: undefined
|
|
119
119
|
if (
|
|
120
120
|
propertyId === undefined ||
|
|
121
|
-
!dataSource.
|
|
121
|
+
!dataSource.dataSourceSchema?.propertiesById[propertyId]
|
|
122
122
|
) {
|
|
123
123
|
return {
|
|
124
124
|
status: "error",
|
|
@@ -39,7 +39,7 @@ export function resolvePageDataSource(args: {
|
|
|
39
39
|
if (dataSource.inaccessible === true) {
|
|
40
40
|
return { status: "error", error: dataSourceInaccessibleError(key) }
|
|
41
41
|
}
|
|
42
|
-
if (dataSource.
|
|
42
|
+
if (dataSource.dataSourcePointer === undefined) {
|
|
43
43
|
return {
|
|
44
44
|
status: "error",
|
|
45
45
|
error: {
|
|
@@ -52,6 +52,6 @@ export function resolvePageDataSource(args: {
|
|
|
52
52
|
return {
|
|
53
53
|
status: "success",
|
|
54
54
|
dataSource,
|
|
55
|
-
dataSourceId: dataSource.
|
|
55
|
+
dataSourceId: dataSource.dataSourcePointer.id,
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -9,24 +9,12 @@ import { notifyListener } from "../utils/notifyListener.js"
|
|
|
9
9
|
import { resolveDataSourceQuery } from "./bridge/resolveDataSourceQuery.js"
|
|
10
10
|
import type { SubscribeToDataSourceArgs } from "./types.js"
|
|
11
11
|
|
|
12
|
-
export function subscribeToDataSource(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
19
|
-
): () => void
|
|
20
|
-
export function subscribeToDataSource(
|
|
21
|
-
{
|
|
22
|
-
key,
|
|
23
|
-
onSnapshot,
|
|
24
|
-
onError: providedOnError,
|
|
25
|
-
options: providedOptions = {},
|
|
26
|
-
}: SubscribeToDataSourceArgs,
|
|
27
|
-
legacyOnError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
28
|
-
): () => void {
|
|
29
|
-
const onError = providedOnError ?? legacyOnError
|
|
12
|
+
export function subscribeToDataSource({
|
|
13
|
+
key,
|
|
14
|
+
onSnapshot,
|
|
15
|
+
onError,
|
|
16
|
+
options: providedOptions = {},
|
|
17
|
+
}: SubscribeToDataSourceArgs): () => void {
|
|
30
18
|
const options = structuredClone(providedOptions)
|
|
31
19
|
const bridge = getBridge()
|
|
32
20
|
const subscriptionId = `data-source:${globalThis.crypto.randomUUID()}`
|
|
@@ -82,7 +70,7 @@ export function subscribeToDataSource(
|
|
|
82
70
|
}
|
|
83
71
|
const backingSourceChanged =
|
|
84
72
|
bindingSignature !== undefined &&
|
|
85
|
-
dataSource?.
|
|
73
|
+
dataSource?.dataSourcePointer?.id !== nextSource?.dataSourcePointer?.id
|
|
86
74
|
bindingSignature = signature
|
|
87
75
|
dataSource = nextSource
|
|
88
76
|
if (backingSourceChanged) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Icons and emoji cross the bridge unchanged. Reusing the inferred types keeps
|
|
2
|
+
// SDK types aligned with validation, including support for future icon fields.
|
|
3
|
+
export type {
|
|
4
|
+
BridgeCustomEmoji as NotionCustomEmoji,
|
|
5
|
+
BridgeEmoji as NotionEmoji,
|
|
6
|
+
BridgeIcon as NotionIcon,
|
|
7
|
+
BridgeIconColor as NotionIconColor,
|
|
8
|
+
BridgeIconName as NotionIconName,
|
|
9
|
+
} from "@notionhq/custom-blocks-protocol/icons.js"
|