@notionhq/custom-blocks 0.3.1 → 0.3.3
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 -8
- package/dist/bridge/SandboxBridge.d.ts +469 -15
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +119 -88
- package/dist/bridge/dataSources/resolveProperty.d.ts +1 -20
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolveProperty.js +37 -32
- package/dist/bridge/page.d.ts +11 -7
- package/dist/bridge/page.d.ts.map +1 -1
- package/dist/bridge/page.js +20 -50
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +32 -6
- package/dist/dataSources.d.ts.map +1 -1
- package/dist/dataSources.js +4 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/protocol/dataSources/dateValue.d.ts +2 -2
- package/dist/protocol/dataSources/dateValue.js +9 -7
- package/dist/protocol/messages/createPage.d.ts +64 -2
- package/dist/protocol/messages/createPageResult.d.ts +192 -6
- package/dist/protocol/messages/getPage.d.ts +192 -6
- package/dist/protocol/messages/hostToSandbox.d.ts +704 -22
- package/dist/protocol/messages/queryDataSourceResult.d.ts +128 -4
- package/dist/protocol/messages/sandboxToHost.d.ts +128 -4
- package/dist/protocol/messages/updatePage.d.ts +64 -2
- package/dist/protocol/messages/updatePageResult.d.ts +192 -6
- package/dist/protocol/pages/page.d.ts +360 -12
- package/dist/protocol/pages/page.js +48 -2
- package/dist/protocol/protocolVersion.d.ts +2 -1
- package/dist/protocol/protocolVersion.js +3 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/build-tools.md +55 -0
- package/docs/data-sources.md +12 -9
- package/docs/deployment.md +16 -34
- package/docs/errors.md +65 -52
- package/docs/pages.md +85 -78
- package/package.json +2 -18
- package/src/bridge/SandboxBridge.ts +168 -129
- package/src/bridge/dataSources/resolveProperty.ts +48 -39
- package/src/bridge/page.ts +32 -75
- package/src/bridge/sandboxClient.ts +40 -7
- package/src/dataSources.ts +7 -9
- package/src/index.ts +6 -0
- package/src/types.ts +6 -0
package/docs/pages.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Pages
|
|
1
|
+
# Pages
|
|
2
2
|
|
|
3
|
-
`pages.get` and `pages.create` return `{ status: "success", page
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
`pages.get` and `pages.create` return `{ status: "success", page }` or `{ status: "error", error }`.
|
|
4
|
+
Both the Pages and Data sources namespaces return the same `NotionPage` type, with methods to read
|
|
5
|
+
and update properties.
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
import { pages, dataSources } from "@notionhq/custom-blocks"
|
|
@@ -14,23 +14,22 @@ if (result.status === "success") {
|
|
|
14
14
|
}
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
`NotionPageData` contains serializable page fields.
|
|
18
|
-
|
|
19
|
-
Both namespaces use this same page type.
|
|
17
|
+
`NotionPageData` contains the serializable page fields. `NotionPage` adds methods, which are not
|
|
18
|
+
serialized. Reads use loaded values. Writes send bridge messages to Notion.
|
|
20
19
|
|
|
21
20
|
## Page fields
|
|
22
21
|
|
|
23
|
-
`properties` maps property display names to typed values or `null`. Each typed value
|
|
24
|
-
property ID. `getPropertyById`
|
|
25
|
-
getter fetches data.
|
|
22
|
+
`properties` maps property display names to typed values or `null`. Each typed value includes its
|
|
23
|
+
raw property ID. `getPropertyById` returns the loaded value with that ID, or `null`. Neither
|
|
24
|
+
property getter fetches data.
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
`last_visited_time
|
|
26
|
+
Every page has `created_time`, `last_edited_time`, `created_by`, `last_edited_by`, and
|
|
27
|
+
`last_visited_time` fields. Unavailable values are `null`. These fields are separate from database
|
|
29
28
|
properties.
|
|
30
29
|
|
|
31
|
-
Parent, icon, cover, URLs, timestamps, and archive
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
Parent, icon, cover, URLs, timestamps, and archive state are page metadata. Missing icons, covers,
|
|
31
|
+
URLs, and timestamps are `null`. `is_archived` and `in_trash` include inherited state. The SDK
|
|
32
|
+
cannot move pages to or from the trash.
|
|
34
33
|
|
|
35
34
|
## Data source context
|
|
36
35
|
|
|
@@ -43,21 +42,29 @@ if (result.status === "success") {
|
|
|
43
42
|
}
|
|
44
43
|
```
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
Pages returned by Data sources methods retain their manifest key in `dataSourceKey`. Pages returned
|
|
46
|
+
by the Pages namespace have `dataSourceKey: null`.
|
|
47
|
+
|
|
48
|
+
`getPropertyByKey` uses the retained data source binding to resolve a manifest property key. It
|
|
49
|
+
returns `null` if the page has no context, the key is invalid or unbound, or the property is
|
|
50
|
+
missing. The result's `propertyIdsByKey` map exposes these bindings, with `undefined` for unbound
|
|
51
|
+
keys. The page itself has no binding map.
|
|
50
52
|
|
|
51
53
|
## Create pages
|
|
52
54
|
|
|
53
|
-
`pages.create`
|
|
55
|
+
`pages.create` accepts `CreatePageArgs` with one of three `CreatePageParent` variants:
|
|
54
56
|
|
|
55
57
|
- `{ type: "page_id", page_id }` creates a child page.
|
|
56
58
|
- `{ type: "data_source_id", data_source_id }` creates a data source row.
|
|
57
59
|
- `{ type: "data_source_key", key }` creates a row using a manifest binding.
|
|
58
60
|
|
|
59
|
-
Only
|
|
60
|
-
`
|
|
61
|
+
Only a `page_id` parent accepts `NotionCreatePagePosition`: `start`, `end`, `before`, or `after`.
|
|
62
|
+
The `before` and `after` positions require a `blockId`.
|
|
63
|
+
|
|
64
|
+
A `page_id` or `data_source_id` parent uses raw property IDs. A `data_source_key` parent uses
|
|
65
|
+
manifest property keys bound to properties in the loaded database schema.
|
|
66
|
+
|
|
67
|
+
In this example, `tasks` has a `title` manifest key bound to the database's title property:
|
|
61
68
|
|
|
62
69
|
```ts
|
|
63
70
|
const page = await pages.create({
|
|
@@ -71,28 +78,32 @@ const row = await pages.create({
|
|
|
71
78
|
})
|
|
72
79
|
```
|
|
73
80
|
|
|
74
|
-
|
|
75
|
-
icons or covers.
|
|
81
|
+
If a property value includes `id`, it must match the target's raw property ID. Unknown or unbound
|
|
82
|
+
manifest keys return `unmapped_property`. Creation does not accept icons or covers.
|
|
76
83
|
|
|
77
84
|
## Mutate pages
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
structured error. Successful writes refresh the same page object.
|
|
86
|
+
Page methods use the page's ID and retained data source context. `PageUpdatePayload` accepts
|
|
87
|
+
`properties`, `icon`, `cover`, and `is_archived`.
|
|
82
88
|
|
|
83
89
|
- `page.updateById` interprets property keys as raw property IDs.
|
|
84
90
|
- `page.updateByKey` interprets property keys as manifest keys.
|
|
85
91
|
- `page.archive()` sets `is_archived` to `true`.
|
|
86
92
|
- `page.unarchive()` sets `is_archived` to `false`.
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
properties. The SDK validates every key before sending any write. A missing context, invalid key,
|
|
91
|
-
unbound key, or missing property produces a local error. An empty update also produces a local
|
|
92
|
-
error.
|
|
94
|
+
Both update methods accept `NotionPagePropertyInputMap`. The SDK fills in omitted value IDs. If a
|
|
95
|
+
value includes `id`, it must match the target's raw property ID, even in a key-based update.
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
Property writes through `updateByKey` require a page returned by a Data sources method and keys
|
|
98
|
+
bound to properties in the loaded database schema. Updates to only `icon`, `cover`, or `is_archived`
|
|
99
|
+
do not require data source context.
|
|
100
|
+
|
|
101
|
+
The SDK validates all properties before sending an update. Invalid values, mismatched IDs, duplicate
|
|
102
|
+
targets, and unresolved keys return local errors. An update must include at least one property or
|
|
103
|
+
metadata change. See [Local page update errors](./errors.md#local-page-update-errors).
|
|
104
|
+
|
|
105
|
+
Icons use `NotionPageIcon` and covers use `NotionPageCover`. Supported values include emoji,
|
|
106
|
+
external URLs, and existing hosted file URLs. File upload references are unsupported.
|
|
96
107
|
|
|
97
108
|
## Types
|
|
98
109
|
|
|
@@ -108,20 +119,20 @@ hosted file URLs. File upload references remain unsupported.
|
|
|
108
119
|
|
|
109
120
|
## Property support
|
|
110
121
|
|
|
111
|
-
|
|
122
|
+
The table below shows property support in Notion:
|
|
112
123
|
|
|
113
|
-
- **Read value** shows `page.properties` after
|
|
114
|
-
|
|
124
|
+
- **Read value** shows `page.properties` after a read, create, or successful update. Unsupported
|
|
125
|
+
properties return `null`.
|
|
115
126
|
- **Create** covers property writes through `pages.create`.
|
|
116
127
|
- **Update** covers property writes through `page.updateById`.
|
|
117
128
|
|
|
118
|
-
Pages outside a data source support only `title`. Other
|
|
119
|
-
|
|
129
|
+
Pages outside a data source support only `title`. Other properties require a data source row and a
|
|
130
|
+
matching property in its schema.
|
|
120
131
|
|
|
121
132
|
- 🟢 **Supported:** The SDK supports this operation in Notion.
|
|
122
|
-
- 🟡 **Limited:** The SDK supports this operation with the restrictions
|
|
133
|
+
- 🟡 **Limited:** The SDK supports this operation with the listed restrictions.
|
|
123
134
|
- 🔴 **Unavailable:** The SDK does not expose this operation.
|
|
124
|
-
- ⚫ **Not supported in Notion:** Notion
|
|
135
|
+
- ⚫ **Not supported in Notion:** Notion does not support this operation in the stated case.
|
|
125
136
|
|
|
126
137
|
| Property type | Read value (`pages.get`) | Create (`pages.create`) | Update (`page.updateById`) |
|
|
127
138
|
| ------------------- | ---------------------------------------------------- | -------------------------------------------- | -------------------------------------------- |
|
|
@@ -138,15 +149,15 @@ and a property in its schema.
|
|
|
138
149
|
| `date` | 🟢 `start` and optional `end` strings, or `null` | 🟡 Minute precision | 🟡 Minute precision |
|
|
139
150
|
| `people` | 🟢 Array of user/group ID objects | 🟢 Supported | 🟢 Supported |
|
|
140
151
|
| `files` | 🟢 External links and hosted files | 🟡 File URLs only | 🟡 File URLs only |
|
|
141
|
-
| `unique_id` |
|
|
152
|
+
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
142
153
|
| `relation` | 🟢 Array of page ID objects | 🟡 Replaces value. Rejects `has_more: true`. | 🟡 Replaces value. Rejects `has_more: true`. |
|
|
143
154
|
| `place` | 🟢 Coordinates and optional place details, or `null` | 🟢 Supported | 🟢 Supported |
|
|
144
|
-
| `formula` |
|
|
145
|
-
| `rollup` |
|
|
146
|
-
| `button` |
|
|
147
|
-
| `verification` |
|
|
155
|
+
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
156
|
+
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
157
|
+
| `button` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
158
|
+
| `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
148
159
|
| `last_visited_time` | 🟡 Current viewer’s ISO timestamp | 🔴 Unavailable | 🔴 Unavailable |
|
|
149
|
-
| `location` |
|
|
160
|
+
| `location` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
150
161
|
| `created_time` | 🟢 ISO timestamp in UTC | 🔴 Unavailable | 🔴 Unavailable |
|
|
151
162
|
| `last_edited_time` | 🟢 ISO timestamp in UTC | 🔴 Unavailable | 🔴 Unavailable |
|
|
152
163
|
| `created_by` | 🟢 Actor record pointer | 🔴 Unavailable | 🔴 Unavailable |
|
|
@@ -154,27 +165,26 @@ and a property in its schema.
|
|
|
154
165
|
|
|
155
166
|
### Notes
|
|
156
167
|
|
|
157
|
-
- Select, multi-select, and status reads return option names and colors
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
the host uses the ID. The host rejects unknown IDs.
|
|
168
|
+
- Select, multi-select, and status reads return available option names and colors, plus IDs for
|
|
169
|
+
options that match the schema. Writes select options by ID or name without editing their
|
|
170
|
+
definitions. If you supply both, the host uses the ID. Unknown IDs fail.
|
|
161
171
|
- Date-time writes preserve hours and minutes but discard seconds and milliseconds.
|
|
162
|
-
- Title and rich text use text arrays
|
|
163
|
-
|
|
164
|
-
- `pages.get` resolves Files links and readable file
|
|
165
|
-
source. Create
|
|
166
|
-
existing `file` URLs
|
|
172
|
+
- Title and rich text use text arrays that preserve only plain text. Formatting, links, mentions,
|
|
173
|
+
and equations are not preserved as structured rich text.
|
|
174
|
+
- `pages.get` resolves Files links and readable file, image, PDF, audio, and video references with a
|
|
175
|
+
source. Create and update responses include only links. File writes store `external` URLs and
|
|
176
|
+
existing `file` URLs as links. Upload references (`file_upload`) are unsupported.
|
|
167
177
|
- Relation writes replace the value and reject `has_more: true`.
|
|
168
|
-
- Top-level `created_time` and `last_edited_time`
|
|
169
|
-
|
|
170
|
-
|
|
178
|
+
- Top-level `created_time` and `last_edited_time` do not depend on the database schema.
|
|
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 `""`.
|
|
171
181
|
|
|
172
182
|
For query properties, filters, and sorts, see
|
|
173
183
|
[Data source property support](./data-sources.md#property-support).
|
|
174
184
|
|
|
175
185
|
## Opening pages
|
|
176
186
|
|
|
177
|
-
`pages.open(pageId, { mode })` asks Notion to open a
|
|
187
|
+
`pages.open(pageId, { mode })` asks Notion to open a page the viewer can read:
|
|
178
188
|
|
|
179
189
|
```ts
|
|
180
190
|
const result = await pages.open(pageId, { mode: "side_peek" })
|
|
@@ -184,31 +194,31 @@ if (result.status === "error") {
|
|
|
184
194
|
}
|
|
185
195
|
```
|
|
186
196
|
|
|
187
|
-
|
|
188
|
-
|
|
197
|
+
If the block is inside a peek, opening another page in that peek unmounts the block and loses its
|
|
198
|
+
local state. The block may unmount before it receives the request result.
|
|
189
199
|
|
|
190
|
-
Modes are `"side_peek"` and `"center_peek"`. Success means the host
|
|
191
|
-
navigation
|
|
192
|
-
surface
|
|
193
|
-
result contains `{ pageId }
|
|
200
|
+
Modes are `"side_peek"` and `"center_peek"`. Success means the host passed the request to Notion's
|
|
201
|
+
navigation system. The method does not wait for confirmation to leave the current page or for the
|
|
202
|
+
new page to load. If the current surface cannot show the requested peek, Notion may open a full page
|
|
203
|
+
instead. The success result contains only `{ pageId }`. Use `pages.get(pageId)` to read the page's
|
|
194
204
|
metadata.
|
|
195
205
|
|
|
196
206
|
### Files reads
|
|
197
207
|
|
|
198
|
-
Each Files entry is either an external link (`type: "external"`) or a
|
|
208
|
+
Each Files entry is either an external link (`type: "external"`) or a file hosted by Notion
|
|
199
209
|
(`type: "file"`), in the order shown in Notion. A hosted file's `file.url` is a signed URL that
|
|
200
210
|
expires at `file.expiry_time`. Call `pages.get` again when you need a fresh URL. `expiry_time` can
|
|
201
211
|
be missing on older hosts.
|
|
202
212
|
|
|
203
|
-
An empty Files value returns `[]`. If the host
|
|
204
|
-
|
|
205
|
-
|
|
213
|
+
An empty Files value returns `[]`. If the host cannot resolve an entry, `pages.get` fails instead of
|
|
214
|
+
returning a partial list. For example, an entry may point to a folder or a file the viewer cannot
|
|
215
|
+
read.
|
|
206
216
|
|
|
207
217
|
## Mutation results
|
|
208
218
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
219
|
+
Update and archive methods return `UpdatePageResult`: `{ status: "success", page }` or
|
|
220
|
+
`{ status: "error", error }`. A successful update refreshes the same page object before the promise
|
|
221
|
+
resolves. Separately fetched pages remain independent objects.
|
|
212
222
|
|
|
213
223
|
## Namespace methods
|
|
214
224
|
|
|
@@ -221,8 +231,8 @@ methods refresh the same page object before resolving. Use `updateById` for raw
|
|
|
221
231
|
| `dataSources.getPage(key, pageId)` | `{ status: "success", page, propertyIdsByKey }` |
|
|
222
232
|
| `dataSources.create(key, payload)` | `{ status: "success", page, propertyIdsByKey }` |
|
|
223
233
|
|
|
224
|
-
The Pages namespace exposes `get`, `create`, and `open`. Use page
|
|
225
|
-
and archive
|
|
234
|
+
The Pages namespace exposes `get`, `create`, and `open`. Use page methods to update properties or
|
|
235
|
+
metadata and to archive or unarchive a page:
|
|
226
236
|
|
|
227
237
|
```ts
|
|
228
238
|
const fetched = await pages.get(pageId)
|
|
@@ -235,6 +245,3 @@ if (fetched.status === "success") {
|
|
|
235
245
|
if (result.status === "success") console.log(page.properties.Score)
|
|
236
246
|
}
|
|
237
247
|
```
|
|
238
|
-
|
|
239
|
-
The successful write refreshes this page before the promise resolves. Separately fetched pages
|
|
240
|
-
remain independent objects.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/custom-blocks",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -41,24 +41,8 @@
|
|
|
41
41
|
"optional": true
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@testing-library/react": "^16.3.3",
|
|
46
|
-
"@types/node": "^26.5.0",
|
|
47
|
-
"@types/react": "^19.2.18",
|
|
48
|
-
"@types/react-dom": "^19.2.7",
|
|
49
|
-
"@vitest/coverage-v8": "^5.0.0",
|
|
50
|
-
"jsdom": "^30.0.1",
|
|
51
|
-
"react": "^19.2.8",
|
|
52
|
-
"react-dom": "^19.2.8",
|
|
53
|
-
"vitest": "^5.0.0"
|
|
54
|
-
},
|
|
55
44
|
"dependencies": {
|
|
56
|
-
"valibot": "^1.
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"test": "vitest run --environment jsdom",
|
|
60
|
-
"test:coverage": "vitest run --environment jsdom --coverage --coverage.provider=v8 --coverage.reporter=json",
|
|
61
|
-
"typecheck": "tsc --project tsconfig.json && tsc --project cli/tsconfig.json"
|
|
45
|
+
"valibot": "^1.5.0"
|
|
62
46
|
},
|
|
63
47
|
"bin": {
|
|
64
48
|
"notion-custom-blocks": "./bin/notion-custom-blocks/cli.js"
|