@notionhq/custom-blocks 0.2.24 → 0.3.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/README.md +8 -5
- package/dist/bridge/SandboxBridge.d.ts +15 -14
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +117 -35
- package/dist/bridge/dataSources/resolve.d.ts +1 -3
- package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolve.js +1 -11
- package/dist/bridge/dataSources/subscribe.d.ts +4 -1
- package/dist/bridge/dataSources/subscribe.d.ts.map +1 -1
- package/dist/bridge/dataSources/subscribe.js +14 -1
- package/dist/bridge/hostState.d.ts +11 -39
- package/dist/bridge/hostState.d.ts.map +1 -1
- package/dist/bridge/hostState.js +5 -50
- package/dist/bridge/page.d.ts +14 -0
- package/dist/bridge/page.d.ts.map +1 -0
- package/dist/bridge/page.js +59 -0
- package/dist/bridge/sandboxClient.d.ts +8 -14
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +13 -21
- package/dist/dataSources.d.ts +8 -0
- package/dist/dataSources.d.ts.map +1 -0
- package/dist/dataSources.js +104 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -5
- package/dist/protocol/dataSources/dataSourcePage.js +2 -3
- package/dist/protocol/dataSources/propertySchema.d.ts +1 -0
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/messages/createPage.js +2 -2
- package/dist/protocol/messages/createPageResult.d.ts +468 -1
- package/dist/protocol/messages/createPageResult.js +17 -2
- package/dist/protocol/messages/getPage.d.ts +468 -1
- package/dist/protocol/messages/getPage.js +18 -3
- package/dist/protocol/messages/hostToSandbox.d.ts +2587 -178
- package/dist/protocol/messages/hostToSandbox.js +24 -12
- package/dist/protocol/messages/openExternalUrl.d.ts +32 -0
- package/dist/protocol/messages/openExternalUrl.js +26 -0
- package/dist/protocol/messages/queryDataSourceResult.d.ts +468 -1
- package/dist/protocol/messages/queryDataSourceResult.js +18 -2
- package/dist/protocol/messages/sandboxToHost.d.ts +6 -0
- package/dist/protocol/messages/sandboxToHost.js +2 -0
- package/dist/protocol/messages/updatePage.d.ts +1 -0
- package/dist/protocol/messages/updatePage.js +4 -3
- package/dist/protocol/messages/updatePageResult.d.ts +467 -1
- package/dist/protocol/messages/updatePageResult.js +16 -2
- package/dist/protocol/pages/page.d.ts +386 -6
- package/dist/protocol/pages/page.js +23 -2
- package/dist/protocol/protocolVersion.d.ts +2 -1
- package/dist/protocol/protocolVersion.js +4 -1
- package/dist/react/useDataSource.d.ts +1 -1
- package/dist/react/useDataSource.d.ts.map +1 -1
- package/dist/react/useDataSource.js +19 -4
- package/dist/types.d.ts +59 -97
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +3 -3
- package/docs/data-sources.md +170 -133
- package/docs/errors.md +13 -9
- package/docs/links.md +44 -0
- package/docs/pages.md +113 -182
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +189 -62
- package/src/bridge/dataSources/resolve.ts +1 -20
- package/src/bridge/dataSources/subscribe.ts +32 -5
- package/src/bridge/hostState.ts +21 -100
- package/src/bridge/page.ts +90 -0
- package/src/bridge/sandboxClient.ts +15 -25
- package/src/dataSources.ts +138 -0
- package/src/index.ts +8 -19
- package/src/react/useDataSource.ts +20 -4
- package/src/types.ts +65 -110
package/docs/data-sources.md
CHANGED
|
@@ -6,9 +6,9 @@ them current as the data changes.
|
|
|
6
6
|
Use `customBlock.subscribeToDataSource(...)` with any TypeScript UI framework. For React,
|
|
7
7
|
`useDataSource(key, options)` provides the latest snapshot and handles subscription cleanup.
|
|
8
8
|
|
|
9
|
-
Each snapshot contains
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
Each snapshot contains `items`, `propertyIdsByKey`, `isLoading`, and `hasMore`. Each query result
|
|
10
|
+
replaces the previous rows in the snapshot. Subscriptions remain independent, even when they query
|
|
11
|
+
the same data source.
|
|
12
12
|
|
|
13
13
|
Queries default to 20 rows and support up to 999. See [Known limitations](#known-limitations) for
|
|
14
14
|
pagination, filter, and sort restrictions.
|
|
@@ -22,8 +22,9 @@ When someone adds the block to Notion, they bind each declaration to a data sour
|
|
|
22
22
|
properties. Your code queries the declared key and the SDK resolves the binding. This lets the same
|
|
23
23
|
block work with different data sources across workspaces.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
Use the shared `propertyIdsByKey` map to resolve declared keys to raw property IDs. Use page getters
|
|
26
|
+
to read values by ID or key. Read each property object from `properties[name]`. `properties` maps
|
|
27
|
+
database property names to property objects.
|
|
27
28
|
|
|
28
29
|
Use `ManifestDataSource`, `ManifestProperty`, and `ManifestIcon` for declaration metadata. To list
|
|
29
30
|
declared keys, use `useManifest()` in React or `customBlock.getManifest()` in TypeScript. These APIs
|
|
@@ -41,9 +42,17 @@ function customBlock.subscribeToDataSource(
|
|
|
41
42
|
type SubscribeToDataSourceArgs = {
|
|
42
43
|
key: string;
|
|
43
44
|
onSnapshot: (snapshot: DataSourceSnapshot) => void;
|
|
45
|
+
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void;
|
|
44
46
|
options?: DataSourceQueryOptions;
|
|
45
47
|
};
|
|
46
48
|
|
|
49
|
+
type DataSourceSnapshot = {
|
|
50
|
+
items: NotionPage[];
|
|
51
|
+
propertyIdsByKey: { [key: string]: string | undefined };
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
hasMore: boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
47
56
|
type DataSourceQueryOptions = {
|
|
48
57
|
limit?: number;
|
|
49
58
|
filter?: NotionDataSourceFilter;
|
|
@@ -56,8 +65,8 @@ remain subscribed. Queries start only after SDK initialization.
|
|
|
56
65
|
|
|
57
66
|
The listener receives the current snapshot immediately and receives later updates. Unrelated host
|
|
58
67
|
changes do not trigger the listener. A new query result can trigger the listener even if its row
|
|
59
|
-
values are unchanged. Each snapshot contains
|
|
60
|
-
updating, archiving, and unarchiving.
|
|
68
|
+
values are unchanged. Each snapshot contains `items`, `propertyIdsByKey`, `isLoading`, and
|
|
69
|
+
`hasMore`. Each item provides methods for updating, archiving, and unarchiving.
|
|
61
70
|
|
|
62
71
|
The SDK calls `onSnapshot` immediately with the current snapshot, before `subscribeToDataSource`
|
|
63
72
|
returns.
|
|
@@ -70,6 +79,7 @@ await initCustomBlock()
|
|
|
70
79
|
const unsubscribe = customBlock.subscribeToDataSource({
|
|
71
80
|
key: "people",
|
|
72
81
|
onSnapshot: snapshot => render(snapshot),
|
|
82
|
+
onError: error => showError(error.message),
|
|
73
83
|
options: {
|
|
74
84
|
limit: 50,
|
|
75
85
|
sorts: [{ key: "name", direction: "ascending" }],
|
|
@@ -101,14 +111,11 @@ function useDataSource(
|
|
|
101
111
|
): UseDataSourceResult
|
|
102
112
|
|
|
103
113
|
type UseDataSourceResult = {
|
|
104
|
-
items:
|
|
105
|
-
collectionSchema?: NotionCollectionSchema
|
|
106
|
-
propertySchemasById: { [propertyId: string]: NotionPropertySchema }
|
|
114
|
+
items: NotionPage[]
|
|
107
115
|
propertyIdsByKey: { [key: string]: string | undefined }
|
|
108
|
-
propertySchemasByKey: { [key: string]: NotionPropertySchema | undefined }
|
|
109
116
|
isLoading: boolean
|
|
110
117
|
hasMore: boolean
|
|
111
|
-
error
|
|
118
|
+
error: CustomBlockQueryDataSourceErrorInfo | undefined
|
|
112
119
|
}
|
|
113
120
|
```
|
|
114
121
|
|
|
@@ -116,8 +123,7 @@ Reads the data source mapped to `key`. To request more rows, store the limit in
|
|
|
116
123
|
pass it to `useDataSource` again.
|
|
117
124
|
|
|
118
125
|
`propertyIdsByKey` maps manifest property keys to raw Notion property IDs; unbound keys map to
|
|
119
|
-
`undefined`.
|
|
120
|
-
for declared-but-unbound slots.
|
|
126
|
+
`undefined`. The snapshot does not expose schemas.
|
|
121
127
|
|
|
122
128
|
`useDataSource` uses `customBlock.subscribeToDataSource` and returns its latest snapshot. A change
|
|
123
129
|
to the key, limit, filter, or sorts replaces the subscription.
|
|
@@ -126,7 +132,10 @@ Each consumer has its own host subscription. On unmount, the SDK removes its loc
|
|
|
126
132
|
sends an unsubscribe message. The host stops future refreshes and ignores pending results. Other
|
|
127
133
|
consumers remain subscribed.
|
|
128
134
|
|
|
129
|
-
Query failures
|
|
135
|
+
Query failures set `error` and stop loading. The hook retains the last successful rows and bindings
|
|
136
|
+
for the same query. A later snapshot clears the error, including when a changed binding restarts the
|
|
137
|
+
query. Changing the key or options starts a separate query without the previous query's rows or
|
|
138
|
+
error.
|
|
130
139
|
|
|
131
140
|
## Query options
|
|
132
141
|
|
|
@@ -190,7 +199,7 @@ a raw property ID. The condition type, such as `checkbox`, must match the proper
|
|
|
190
199
|
Pass a single condition directly, or combine up to 25 conditions with `and`. Nested groups and `or`
|
|
191
200
|
are unsupported. An empty `and` group applies no conditions. Both APIs accept the same filter shape.
|
|
192
201
|
|
|
193
|
-
The SDK
|
|
202
|
+
The SDK rejects invalid keys, types, operators, and values before sending the query.
|
|
194
203
|
|
|
195
204
|
Use stored Status group names with either subscription API:
|
|
196
205
|
|
|
@@ -217,10 +226,8 @@ filter: {
|
|
|
217
226
|
}
|
|
218
227
|
```
|
|
219
228
|
|
|
220
|
-
Use `propertyId`
|
|
221
|
-
|
|
222
|
-
`propertiesById.created_by` is available without a column, but `propertyId: "created_by"` does not
|
|
223
|
-
address a Created by column.
|
|
229
|
+
Use `propertyId` with the column’s actual property ID to address it directly. `created_by` selects
|
|
230
|
+
the filter type, not the column.
|
|
224
231
|
|
|
225
232
|
<details>
|
|
226
233
|
<summary>Filter operators and values</summary>
|
|
@@ -343,33 +350,34 @@ require an actual Created by column in the database schema.
|
|
|
343
350
|
|
|
344
351
|
## Pages within a data source
|
|
345
352
|
|
|
346
|
-
Each row
|
|
347
|
-
|
|
348
|
-
|
|
353
|
+
Each row is a unified `NotionPage` with metadata, typed properties, getters, and mutation methods.
|
|
354
|
+
|
|
355
|
+
- `page.properties[name]` reads a value by display name.
|
|
356
|
+
- `page.getPropertyByKey(key)` reads a loaded value through its manifest binding.
|
|
357
|
+
- `page.getPropertyById(id)` reads a loaded value by raw ID.
|
|
349
358
|
|
|
350
|
-
|
|
351
|
-
|
|
359
|
+
The result contains one shared `propertyIdsByKey` map. Each entry maps a manifest key to a raw
|
|
360
|
+
property ID or `undefined`.
|
|
352
361
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
they do not appear in the `*ByKey` views.
|
|
362
|
+
Rows include metadata properties only when the database schema defines matching columns. Metadata
|
|
363
|
+
properties use the column's configured name and raw property ID.
|
|
356
364
|
|
|
357
|
-
Matching metadata columns also appear under their schema
|
|
358
|
-
`last_visited_time` requires an internal schema property and resolves the
|
|
365
|
+
Matching metadata columns also appear under their schema display names. Page getters resolve IDs and
|
|
366
|
+
bound manifest keys. `last_visited_time` requires an internal schema property and resolves the
|
|
367
|
+
current viewer’s visit.
|
|
359
368
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
`propertySchemasById` does not make a property available for filters or sorts.
|
|
369
|
+
The bridge keeps database schemas internally to validate filter and sort references. Query results
|
|
370
|
+
do not expose those schemas.
|
|
363
371
|
|
|
364
372
|
Property queries fail when the host does not provide a database schema. Queries without filters or
|
|
365
373
|
sorts can continue.
|
|
366
374
|
|
|
367
375
|
### Updating a row
|
|
368
376
|
|
|
369
|
-
Each page
|
|
377
|
+
Each page has `updateById` and `updateByKey` methods:
|
|
370
378
|
|
|
371
379
|
```ts
|
|
372
|
-
await row.
|
|
380
|
+
await row.updateByKey({
|
|
373
381
|
properties: {
|
|
374
382
|
score: { type: "number", number: 8 }, // semantic key
|
|
375
383
|
},
|
|
@@ -377,18 +385,16 @@ await row.update({
|
|
|
377
385
|
})
|
|
378
386
|
```
|
|
379
387
|
|
|
380
|
-
|
|
381
|
-
|
|
388
|
+
Use `updateByKey` for manifest keys and `updateById` for raw property IDs. The SDK resolves manifest
|
|
389
|
+
keys before sending the request.
|
|
382
390
|
|
|
383
|
-
|
|
384
|
-
(e.g. you only have a `pageId`), drop down to the top-level [`pages` API](./pages.md) — it covers
|
|
385
|
-
create / get / update / archive / unarchive and accepts raw property IDs only.
|
|
391
|
+
Read a page through `pages.get(pageId)` before calling its instance methods.
|
|
386
392
|
|
|
387
393
|
### Archiving and unarchiving a row
|
|
388
394
|
|
|
389
|
-
`row.archive()` is shorthand for calling `row.
|
|
390
|
-
shorthand for calling `row.
|
|
391
|
-
`UpdatePageResult`. Use `row.
|
|
395
|
+
`row.archive()` is shorthand for calling `row.updateById({ is_archived: true })`. `row.unarchive()`
|
|
396
|
+
is shorthand for calling `row.updateById({ is_archived: false })`. Both methods return a
|
|
397
|
+
`UpdatePageResult`. Use `row.updateById` to change archive status and other fields in one request.
|
|
392
398
|
|
|
393
399
|
## Read declarations
|
|
394
400
|
|
|
@@ -430,24 +436,21 @@ rendering:
|
|
|
430
436
|
|
|
431
437
|
```tsx
|
|
432
438
|
import { useState } from "react"
|
|
433
|
-
import type {
|
|
439
|
+
import type { NotionPage } from "@notionhq/custom-blocks"
|
|
434
440
|
import { useDataSource } from "@notionhq/custom-blocks/react"
|
|
435
441
|
|
|
436
442
|
const KEY = "people"
|
|
437
443
|
|
|
438
|
-
function isComplete(item:
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
Number.isFinite(item.propertiesByKey.score)
|
|
443
|
-
)
|
|
444
|
+
function isComplete(item: NotionPage): boolean {
|
|
445
|
+
const title = item.getPropertyByKey("name")
|
|
446
|
+
const score = item.getPropertyByKey("score")
|
|
447
|
+
return title?.type === "title" && score?.type === "number" && Number.isFinite(score.number)
|
|
444
448
|
}
|
|
445
449
|
|
|
446
450
|
export function ScoreList() {
|
|
447
451
|
const [limit, setLimit] = useState(20)
|
|
448
|
-
const { items, isLoading, hasMore
|
|
452
|
+
const { items, isLoading, hasMore } = useDataSource(KEY, { limit })
|
|
449
453
|
|
|
450
|
-
if (error) return <div role="alert">Couldn't load: {error.message}</div>
|
|
451
454
|
if (isLoading && items.length === 0) return <div>Loading…</div>
|
|
452
455
|
|
|
453
456
|
const displayItems = items.filter(isComplete)
|
|
@@ -458,11 +461,17 @@ export function ScoreList() {
|
|
|
458
461
|
return (
|
|
459
462
|
<div>
|
|
460
463
|
<ul>
|
|
461
|
-
{displayItems.map(item =>
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
{displayItems.map(item => {
|
|
465
|
+
const title = item.getPropertyByKey("name")
|
|
466
|
+
const score = item.getPropertyByKey("score")
|
|
467
|
+
return (
|
|
468
|
+
<li key={item.id}>
|
|
469
|
+
{title?.type === "title" ? title.title.map(text => text.plain_text).join("") : ""}
|
|
470
|
+
{" — "}
|
|
471
|
+
{score?.type === "number" ? score.number : ""}
|
|
472
|
+
</li>
|
|
473
|
+
)
|
|
474
|
+
})}
|
|
466
475
|
</ul>
|
|
467
476
|
{hasMore && limit < 999 ? (
|
|
468
477
|
<button
|
|
@@ -495,11 +504,13 @@ export function ScoreList() {
|
|
|
495
504
|
|
|
496
505
|
## Property support
|
|
497
506
|
|
|
498
|
-
This table shows property support for custom blocks running in Notion.
|
|
507
|
+
This table shows property support for custom blocks running in Notion. The query-result descriptions
|
|
508
|
+
refer to the core values inside each property object. For example, “Number” refers to
|
|
509
|
+
`property.number` in `{ id, type: "number", number: 8 }`.
|
|
499
510
|
|
|
500
|
-
- **Query result** shows values in `
|
|
511
|
+
- **Query result** shows values in `properties` from `useDataSource` and
|
|
501
512
|
`customBlock.subscribeToDataSource`. Missing values can be `undefined`.
|
|
502
|
-
- **Update row** covers writes through `item.
|
|
513
|
+
- **Update row** covers writes through `item.updateByKey({ properties: ... })`.
|
|
503
514
|
- **Filter** and **Sort** cover query options.
|
|
504
515
|
|
|
505
516
|
- 🟢 **Supported:** The SDK supports this operation in Notion.
|
|
@@ -507,80 +518,73 @@ This table shows property support for custom blocks running in Notion.
|
|
|
507
518
|
- 🔴 **Unavailable:** The SDK does not expose this operation.
|
|
508
519
|
- ⚫ **Not supported in Notion:** Notion itself does not support this operation in the stated case.
|
|
509
520
|
|
|
510
|
-
| Property type | Query result
|
|
511
|
-
| ------------------- |
|
|
512
|
-
| `title` | 🟢 Plain text
|
|
513
|
-
| `rich_text` | 🟢 Plain text
|
|
514
|
-
| `number` | 🟢 Number
|
|
515
|
-
| `checkbox` | 🟢 Boolean
|
|
516
|
-
| `url` | 🟢 String
|
|
517
|
-
| `email` | 🟢 String
|
|
518
|
-
| `phone_number` | 🟢 String
|
|
519
|
-
| `select` | 🟢 Option
|
|
520
|
-
| `multi_select` | 🟢 Array of option
|
|
521
|
-
| `status` | 🟢 Option
|
|
522
|
-
| `date` | 🟢
|
|
523
|
-
| `people` | 🟢
|
|
524
|
-
| `files` | 🟡
|
|
525
|
-
| `unique_id` |
|
|
526
|
-
| `relation` | 🟢
|
|
527
|
-
| `place` |
|
|
528
|
-
| `formula` |
|
|
529
|
-
| `rollup` |
|
|
530
|
-
| `button` |
|
|
531
|
-
| `verification` |
|
|
532
|
-
| `last_visited_time` | 🟡 Viewer
|
|
533
|
-
| `location` |
|
|
534
|
-
| `created_time` | 🟢
|
|
535
|
-
| `last_edited_time` | 🟢
|
|
536
|
-
| `created_by` | 🟢
|
|
537
|
-
| `last_edited_by` | 🟢
|
|
521
|
+
| Property type | Query result | Update row | Filter | Sort |
|
|
522
|
+
| ------------------- | --------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
523
|
+
| `title` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
|
|
524
|
+
| `rich_text` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
|
|
525
|
+
| `number` | 🟢 Number | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
526
|
+
| `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
527
|
+
| `url` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
528
|
+
| `email` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
529
|
+
| `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
530
|
+
| `select` | 🟢 Option object | 🟡 Set value only | 🟢 Supported | 🔴 Unavailable |
|
|
531
|
+
| `multi_select` | 🟢 Array of option objects | 🟡 Set values only | 🟢 Supported | 🔴 Unavailable |
|
|
532
|
+
| `status` | 🟢 Option object | 🟡 Set value only | 🟢 Option names, group names, or empty checks | 🔴 Unavailable |
|
|
533
|
+
| `date` | 🟢 Date object | 🟡 Minute precision | 🟢 Supported | 🟢 Supported |
|
|
534
|
+
| `people` | 🟢 User or group references | 🟢 Supported | 🟢 Supported | 🟢 Native name ordering |
|
|
535
|
+
| `files` | 🟡 External files only | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
|
|
536
|
+
| `unique_id` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
537
|
+
| `relation` | 🟢 Page reference array | 🟡 Replaces value. Rejects `has_more: true`. | 🟢 Supported | 🔴 Unavailable for standard relations. ⚫ Notion cannot sort XLDB targets. |
|
|
538
|
+
| `place` | 🟢 Place object | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
|
|
539
|
+
| `formula` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
540
|
+
| `rollup` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
|
|
541
|
+
| `button` | 🔴 `undefined` | 🔴 Unavailable | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
|
|
542
|
+
| `verification` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
543
|
+
| `last_visited_time` | 🟡 Viewer timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
544
|
+
| `location` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable elsewhere. ⚫ Notion disables filters in My Meetings and Library system databases. | 🔴 Unavailable elsewhere. ⚫ Notion disables sorts in Library system databases. |
|
|
545
|
+
| `created_time` | 🟢 Timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
546
|
+
| `last_edited_time` | 🟢 Timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
547
|
+
| `created_by` | 🟢 Actor reference or null | 🔴 Unavailable | 🟡 Schema-backed creator filters | 🟡 Schema property only |
|
|
548
|
+
| `last_edited_by` | 🟢 Actor reference or null | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
538
549
|
|
|
539
550
|
### Notes
|
|
540
551
|
|
|
541
|
-
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
-
|
|
545
|
-
|
|
546
|
-
`last_edited_time`, `created_by`, and `last_edited_by`. The data source does not need matching
|
|
547
|
-
schema properties. These values are read-only. Timestamps use `NotionDateTime` in UTC. Creator and
|
|
548
|
-
editor values use arrays of record pointers.
|
|
552
|
+
- Query data source results use the Pages API property objects. Narrow each object by its `type`
|
|
553
|
+
field.
|
|
554
|
+
- Date values use `start` and optional `end`.
|
|
555
|
+
- Missing or unsupported properties return `undefined`. Empty supported properties keep their typed
|
|
556
|
+
objects.
|
|
549
557
|
- Filters and sorts can only reference properties defined in the database schema. For example, to
|
|
550
558
|
sort by creation time, you must first add a **Created time** property to the database and
|
|
551
|
-
reference that property's ID.
|
|
552
|
-
read-only metadata and cannot be used when querying.
|
|
559
|
+
reference that property's ID.
|
|
553
560
|
- You can sort by up to 10 unique properties.
|
|
554
561
|
- Date-time filter values may include seconds or milliseconds. The Notion host evaluates them at
|
|
555
562
|
minute precision. Date filters do not expose end-date targeting.
|
|
556
563
|
- Status group filters use stored English group names. The SDK does not normalize localized names.
|
|
557
564
|
- `group_equals` matches any listed group. `group_does_not_equal` excludes all listed groups.
|
|
558
565
|
- Empty group arrays and unknown group names return a nonretryable query error.
|
|
559
|
-
- People properties
|
|
560
|
-
`
|
|
561
|
-
`groupId|workspaceId`. People filters support users and groups. Bot and organization bot filtering
|
|
562
|
-
is not supported.
|
|
566
|
+
- People properties contain arrays of user or group references in `people`. Group IDs use
|
|
567
|
+
`groupId|workspaceId`.
|
|
563
568
|
- Creator filters require an actual **Created by** column. Use its bound key or property ID, not the
|
|
564
569
|
synthetic `created_by` metadata ID.
|
|
565
570
|
- Filters accept one condition or an `and` group of up to 25 conditions. The SDK does not support
|
|
566
571
|
`or` or nested groups.
|
|
567
|
-
- Select, multi-select, and status
|
|
568
|
-
|
|
569
|
-
colors.
|
|
572
|
+
- Select, multi-select, and status values contain option objects. Writes do not edit option
|
|
573
|
+
definitions or colors.
|
|
570
574
|
|
|
571
575
|
### Writing values
|
|
572
576
|
|
|
573
|
-
|
|
574
|
-
status as a string:
|
|
577
|
+
Read the status name from its typed property object:
|
|
575
578
|
|
|
576
579
|
```ts
|
|
577
|
-
item.
|
|
580
|
+
const property = item.getPropertyByKey("status")
|
|
581
|
+
const name = property?.type === "status" ? property.status?.name : undefined
|
|
578
582
|
```
|
|
579
583
|
|
|
580
|
-
|
|
584
|
+
Write inputs remain unchanged. Here, `status` is a declared property key:
|
|
581
585
|
|
|
582
586
|
```ts
|
|
583
|
-
const result = await item.
|
|
587
|
+
const result = await item.updateByKey({
|
|
584
588
|
properties: {
|
|
585
589
|
status: { type: "status", status: { name: "Done" } },
|
|
586
590
|
},
|
|
@@ -605,13 +609,12 @@ See [Pages property support](./pages.md#property-support) for the page-property
|
|
|
605
609
|
|
|
606
610
|
### Rows & values
|
|
607
611
|
|
|
608
|
-
- `NotionDataSource` — a resolved data source
|
|
609
|
-
|
|
610
|
-
- `
|
|
611
|
-
`{ id,
|
|
612
|
-
- `
|
|
613
|
-
- `
|
|
614
|
-
`update` helper.
|
|
612
|
+
- `NotionDataSource` — a resolved data source returned by `initCustomBlock()`, including its binding
|
|
613
|
+
and database schemas.
|
|
614
|
+
- `NotionPage` — a single row exposed to app code:
|
|
615
|
+
`{ id, properties, getPropertyById, getPropertyByKey, updateById, updateByKey, archive, unarchive }`.
|
|
616
|
+
- `NotionPagePropertyValue` — the typed property values exposed by unified pages.
|
|
617
|
+
- `PageUpdatePayload` / `UpdatePageResult` — arguments and result for the page mutation methods.
|
|
615
618
|
- `UseDataSourceOptions` — options accepted by `useDataSource`: `limit?: number`,
|
|
616
619
|
`filter?: NotionDataSourceFilter`, and `sorts?: NotionDataSourceSort[]`.
|
|
617
620
|
- `NotionDataSourceFilter` — one property condition or one shallow `and` group.
|
|
@@ -645,9 +648,6 @@ See [Pages property support](./pages.md#property-support) for the page-property
|
|
|
645
648
|
- `NotionStatusGroup` — the `status` property's "To do / In progress / Done" grouping.
|
|
646
649
|
- `NotionDualProperty` — properties that have both a primary and a secondary axis (e.g. `unique_id`
|
|
647
650
|
prefix + number).
|
|
648
|
-
- `NotionBuiltinPropertyId` — string-literal union of the four synthetic property IDs
|
|
649
|
-
(`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
|
|
650
|
-
- `NOTION_BUILTIN_PROPERTY_IDS` — runtime list of the four built-in IDs.
|
|
651
651
|
|
|
652
652
|
### Database schema & pointers
|
|
653
653
|
|
|
@@ -666,16 +666,53 @@ Branded string types — they're plain strings at runtime but TypeScript disting
|
|
|
666
666
|
|
|
667
667
|
### Date values
|
|
668
668
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
669
|
+
Read date values from `properties[name].date`. The value is `null` when the property is empty.
|
|
670
|
+
Otherwise, it contains `start` and optional `end` and `time_zone` fields. All-day values use date
|
|
671
|
+
strings. Values with a time component use ISO 8601 datetime strings.
|
|
672
|
+
|
|
673
|
+
```ts
|
|
674
|
+
const date = row.properties["Due date"]
|
|
675
|
+
if (date?.type === "date" && date.date) {
|
|
676
|
+
console.log(date.date.start, date.date.end)
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
`NotionDateInput` describes this date shape for reads and writes. The SDK does not expose date
|
|
681
|
+
reminders.
|
|
682
|
+
|
|
683
|
+
## Shared page results
|
|
684
|
+
|
|
685
|
+
Data source results expose one `propertyIdsByKey` map beside `items`. Unbound keys map to
|
|
686
|
+
`undefined`. Each `NotionPage` exposes property getters and mutation methods.
|
|
687
|
+
`DataSourcesQueryResult` and `DataSourcesPageResult` describe the shared result structures used by
|
|
688
|
+
all page operations. The same page type appears in asynchronous namespace results.
|
|
689
|
+
|
|
690
|
+
## Asynchronous namespace
|
|
691
|
+
|
|
692
|
+
Calls to `dataSources.query()` before initialization wait until the SDK initializes. Initialization
|
|
693
|
+
failure returns `{ status: "error", error }` without creating a query subscription.
|
|
694
|
+
|
|
695
|
+
```ts
|
|
696
|
+
import { dataSources } from "@notionhq/custom-blocks"
|
|
697
|
+
|
|
698
|
+
const query = await dataSources.query("people", { limit: 50 })
|
|
699
|
+
if (query.status === "success") {
|
|
700
|
+
const { items, propertyIdsByKey, hasMore } = query
|
|
701
|
+
}
|
|
702
|
+
const result = await dataSources.getPage("people", pageId)
|
|
703
|
+
if (result.status === "success") {
|
|
704
|
+
console.log(result.page.id)
|
|
705
|
+
}
|
|
706
|
+
const created = await dataSources.create("people", {
|
|
707
|
+
properties: { name: { type: "title", title: [{ text: { content: "Alex" } }] } },
|
|
708
|
+
})
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
These methods return `{ status: "success", ...data }` or `{ status: "error", error }`. A successful
|
|
712
|
+
`query` result includes `isLoading: false`. The query releases its subscription after success or
|
|
713
|
+
failure. Hooks and subscriptions keep their existing reactive behavior. `hasMore` reports truncation
|
|
714
|
+
beyond the requested limit. Queries retain existing filters, sorts, and limits.
|
|
715
|
+
|
|
716
|
+
`dataSources.create` accepts `Omit<CreatePageArgs, "parent" | "position">`. The selected binding
|
|
717
|
+
supplies the create parent. `DataSourcesPageResult` describes get/create results.
|
|
718
|
+
`DataSourcesQueryResult` describes the one-shot query result.
|
package/docs/errors.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# Error handling
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Pages reads, Pages creates, and asynchronous data source methods return discriminated results.
|
|
4
|
+
Success returns `{ status: "success", page }` or query data. Failure returns
|
|
5
|
+
`{ status: "error", error }`.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```
|
|
7
|
+
Page instance mutations, navigation, and Users methods also retain their result envelopes.
|
|
8
|
+
Initialization still rejects on failure. Hooks and subscriptions keep their existing error behavior.
|
|
10
9
|
|
|
11
10
|
## Error format
|
|
12
11
|
|
|
@@ -37,6 +36,7 @@ newer hosts may send codes that an older SDK does not list.
|
|
|
37
36
|
`CustomBlockUpdatePageErrorInfo`.
|
|
38
37
|
- Users: `CustomBlockGetUserErrorCode` / `CustomBlockGetUserErrorInfo` and
|
|
39
38
|
`CustomBlockListUsersErrorCode` / `CustomBlockListUsersErrorInfo`.
|
|
39
|
+
- External links: `CustomBlockOpenExternalUrlErrorCode` / `CustomBlockOpenExternalUrlErrorInfo`.
|
|
40
40
|
- Data sources: `CustomBlockQueryDataSourceErrorCode` / `CustomBlockQueryDataSourceErrorInfo`.
|
|
41
41
|
- Shared resolution failures: `CustomBlockPropertyErrorCode` / `CustomBlockPropertyErrorInfo` and
|
|
42
42
|
`CustomBlockDataSourceResolutionErrorCode` / `CustomBlockDataSourceResolutionErrorInfo`.
|
|
@@ -52,14 +52,18 @@ newer hosts may send codes that an older SDK does not list.
|
|
|
52
52
|
- `invalid_data_source_query_sort`: The host rejects a sort, for example, because its property ID is
|
|
53
53
|
unknown, its property type is unsupported, or the query repeats a sort property.
|
|
54
54
|
|
|
55
|
+
`useDataSource` exposes query failures as `error` and sets `isLoading` to `false`. It retains the
|
|
56
|
+
last successful rows for the same query. A later snapshot clears the error. Framework-neutral
|
|
57
|
+
subscriptions report failures through their optional error callback.
|
|
58
|
+
|
|
55
59
|
Data source subscriptions repeat the query when the host supplies a changed schema or binding. This
|
|
56
60
|
recovery does not depend on `isRetryable`.
|
|
57
61
|
|
|
58
62
|
## Initialization errors
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
`initCustomBlock` rejects with `CustomBlockInitializationError`. Its `code` type is
|
|
65
|
+
`CustomBlockInitializationErrorCode`, which covers failures reported by either side of the handshake
|
|
66
|
+
plus SDK-local iframe errors.
|
|
63
67
|
|
|
64
68
|
`CustomBlockInitializationErrorInfo` is the matching `{ code, message, isRetryable }` object type.
|
|
65
69
|
|
package/docs/links.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# `links` API
|
|
2
|
+
|
|
3
|
+
Use `links.open` to ask the host to open an external HTTP or HTTPS URL. The host shows the complete
|
|
4
|
+
normalized URL in a confirmation surface before navigating.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { links } from "@notionhq/custom-blocks"
|
|
8
|
+
|
|
9
|
+
const result = await links.open("https://example.com/report")
|
|
10
|
+
if (result.status === "error") {
|
|
11
|
+
console.error(result.error.message)
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The argument is the URL string.
|
|
16
|
+
|
|
17
|
+
Use an absolute URL without embedded credentials. Both the submitted string and its normalized URL
|
|
18
|
+
must be no longer than 2,048 JavaScript code units. Only HTTP and HTTPS are allowed; email, phone,
|
|
19
|
+
app links, and all other schemes are rejected, as are relative URLs. Notion additionally applies its
|
|
20
|
+
existing URL sanitizer. The host displays and opens the same normalized URL.
|
|
21
|
+
|
|
22
|
+
`OpenExternalUrlResult` is `{ status: "success" }` after the user approves and the host starts
|
|
23
|
+
navigation. Errors use `CustomBlockOpenExternalUrlErrorInfo` and the known
|
|
24
|
+
`CustomBlockOpenExternalUrlErrorCode` values:
|
|
25
|
+
|
|
26
|
+
- `user_decline`: the user cancelled; not retryable.
|
|
27
|
+
- `pending_navigation`: this block already has a confirmation open; retryable.
|
|
28
|
+
- `invalid_url`: the URL did not meet the host's safety rules; not retryable.
|
|
29
|
+
|
|
30
|
+
The host owns confirmation and navigation. Do not use `window.open`, top-level navigation, or a
|
|
31
|
+
sandbox-built confirmation as a substitute. An older host that does not implement this additive
|
|
32
|
+
message may leave the promise pending.
|
|
33
|
+
|
|
34
|
+
Cancellation is an error result, not a successful navigation:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
if (result.status === "error" && result.error.code === "user_decline") {
|
|
38
|
+
// Nothing was opened. Do not automatically retry a user's cancellation.
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
A later deliberate click may call `links.open` again. Notion suppresses prompts from this block for
|
|
43
|
+
60 seconds after three cancellations within 10 seconds; remounting the host component resets that
|
|
44
|
+
local history.
|