@notionhq/custom-blocks 0.2.23 → 0.3.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 +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/resolveProperty.d.ts +3 -3
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolveProperty.js +1 -1
- package/dist/bridge/dataSources/subscribe.d.ts +2 -1
- package/dist/bridge/dataSources/subscribe.d.ts.map +1 -1
- package/dist/bridge/dataSources/subscribe.js +6 -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 +103 -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.d.ts +28 -0
- package/dist/protocol/messages/createPageResult.d.ts +496 -1
- package/dist/protocol/messages/createPageResult.js +17 -2
- package/dist/protocol/messages/getPage.d.ts +496 -1
- package/dist/protocol/messages/getPage.js +18 -3
- package/dist/protocol/messages/hostToSandbox.d.ts +2647 -154
- 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 +62 -0
- package/dist/protocol/messages/sandboxToHost.js +2 -0
- package/dist/protocol/messages/updatePage.d.ts +29 -0
- package/dist/protocol/messages/updatePage.js +2 -1
- package/dist/protocol/messages/updatePageResult.d.ts +495 -1
- package/dist/protocol/messages/updatePageResult.js +16 -2
- package/dist/protocol/pages/page.d.ts +470 -3
- package/dist/protocol/pages/page.js +53 -1
- 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 +1 -3
- package/dist/types.d.ts +55 -96
- 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 +159 -122
- package/docs/errors.md +9 -9
- package/docs/links.md +44 -0
- package/docs/pages.md +121 -191
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +189 -62
- package/src/bridge/dataSources/resolve.ts +1 -20
- package/src/bridge/dataSources/resolveProperty.ts +4 -4
- package/src/bridge/dataSources/subscribe.ts +10 -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 +140 -0
- package/src/index.ts +9 -19
- package/src/react/useDataSource.ts +1 -3
- package/src/types.ts +61 -109
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
|
|
@@ -36,6 +37,7 @@ are useful for a data source switcher.
|
|
|
36
37
|
```ts
|
|
37
38
|
function customBlock.subscribeToDataSource(
|
|
38
39
|
args: SubscribeToDataSourceArgs,
|
|
40
|
+
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
39
41
|
): () => void;
|
|
40
42
|
|
|
41
43
|
type SubscribeToDataSourceArgs = {
|
|
@@ -44,6 +46,13 @@ type SubscribeToDataSourceArgs = {
|
|
|
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.
|
|
@@ -101,14 +110,10 @@ function useDataSource(
|
|
|
101
110
|
): UseDataSourceResult
|
|
102
111
|
|
|
103
112
|
type UseDataSourceResult = {
|
|
104
|
-
items:
|
|
105
|
-
collectionSchema?: NotionCollectionSchema
|
|
106
|
-
propertySchemasById: { [propertyId: string]: NotionPropertySchema }
|
|
113
|
+
items: NotionPage[]
|
|
107
114
|
propertyIdsByKey: { [key: string]: string | undefined }
|
|
108
|
-
propertySchemasByKey: { [key: string]: NotionPropertySchema | undefined }
|
|
109
115
|
isLoading: boolean
|
|
110
116
|
hasMore: boolean
|
|
111
|
-
error?: CustomBlockQueryDataSourceErrorInfo
|
|
112
117
|
}
|
|
113
118
|
```
|
|
114
119
|
|
|
@@ -116,8 +121,7 @@ Reads the data source mapped to `key`. To request more rows, store the limit in
|
|
|
116
121
|
pass it to `useDataSource` again.
|
|
117
122
|
|
|
118
123
|
`propertyIdsByKey` maps manifest property keys to raw Notion property IDs; unbound keys map to
|
|
119
|
-
`undefined`.
|
|
120
|
-
for declared-but-unbound slots.
|
|
124
|
+
`undefined`. The snapshot does not expose schemas.
|
|
121
125
|
|
|
122
126
|
`useDataSource` uses `customBlock.subscribeToDataSource` and returns its latest snapshot. A change
|
|
123
127
|
to the key, limit, filter, or sorts replaces the subscription.
|
|
@@ -126,7 +130,9 @@ Each consumer has its own host subscription. On unmount, the SDK removes its loc
|
|
|
126
130
|
sends an unsubscribe message. The host stops future refreshes and ignores pending results. Other
|
|
127
131
|
consumers remain subscribed.
|
|
128
132
|
|
|
129
|
-
Query failures
|
|
133
|
+
Query failures stop loading. Snapshots keep their four fields and do not expose an error field. Pass
|
|
134
|
+
an optional second callback to `customBlock.subscribeToDataSource` to receive structured query
|
|
135
|
+
errors.
|
|
130
136
|
|
|
131
137
|
## Query options
|
|
132
138
|
|
|
@@ -190,7 +196,7 @@ a raw property ID. The condition type, such as `checkbox`, must match the proper
|
|
|
190
196
|
Pass a single condition directly, or combine up to 25 conditions with `and`. Nested groups and `or`
|
|
191
197
|
are unsupported. An empty `and` group applies no conditions. Both APIs accept the same filter shape.
|
|
192
198
|
|
|
193
|
-
The SDK
|
|
199
|
+
The SDK rejects invalid keys, types, operators, and values before sending the query.
|
|
194
200
|
|
|
195
201
|
Use stored Status group names with either subscription API:
|
|
196
202
|
|
|
@@ -217,10 +223,8 @@ filter: {
|
|
|
217
223
|
}
|
|
218
224
|
```
|
|
219
225
|
|
|
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.
|
|
226
|
+
Use `propertyId` with the column’s actual property ID to address it directly. `created_by` selects
|
|
227
|
+
the filter type, not the column.
|
|
224
228
|
|
|
225
229
|
<details>
|
|
226
230
|
<summary>Filter operators and values</summary>
|
|
@@ -343,30 +347,34 @@ require an actual Created by column in the database schema.
|
|
|
343
347
|
|
|
344
348
|
## Pages within a data source
|
|
345
349
|
|
|
346
|
-
Each row
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
Each row is a unified `NotionPage` with metadata, typed properties, getters, and mutation methods.
|
|
351
|
+
|
|
352
|
+
- `page.properties[name]` reads a value by display name.
|
|
353
|
+
- `page.getPropertyByKey(key)` reads a loaded value through its manifest binding.
|
|
354
|
+
- `page.getPropertyById(id)` reads a loaded value by raw ID.
|
|
349
355
|
|
|
350
|
-
|
|
351
|
-
|
|
356
|
+
The result contains one shared `propertyIdsByKey` map. Each entry maps a manifest key to a raw
|
|
357
|
+
property ID or `undefined`.
|
|
352
358
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
they do not appear in the `*ByKey` views.
|
|
359
|
+
Rows include metadata properties only when the database schema defines matching columns. Metadata
|
|
360
|
+
properties use the column's configured name and raw property ID.
|
|
356
361
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
362
|
+
Matching metadata columns also appear under their schema display names. Page getters resolve IDs and
|
|
363
|
+
bound manifest keys. `last_visited_time` requires an internal schema property and resolves the
|
|
364
|
+
current viewer’s visit.
|
|
365
|
+
|
|
366
|
+
The bridge keeps database schemas internally to validate filter and sort references. Query results
|
|
367
|
+
do not expose those schemas.
|
|
360
368
|
|
|
361
369
|
Property queries fail when the host does not provide a database schema. Queries without filters or
|
|
362
370
|
sorts can continue.
|
|
363
371
|
|
|
364
372
|
### Updating a row
|
|
365
373
|
|
|
366
|
-
Each page
|
|
374
|
+
Each page has `updateById` and `updateByKey` methods:
|
|
367
375
|
|
|
368
376
|
```ts
|
|
369
|
-
await row.
|
|
377
|
+
await row.updateByKey({
|
|
370
378
|
properties: {
|
|
371
379
|
score: { type: "number", number: 8 }, // semantic key
|
|
372
380
|
},
|
|
@@ -374,18 +382,16 @@ await row.update({
|
|
|
374
382
|
})
|
|
375
383
|
```
|
|
376
384
|
|
|
377
|
-
|
|
378
|
-
|
|
385
|
+
Use `updateByKey` for manifest keys and `updateById` for raw property IDs. The SDK resolves manifest
|
|
386
|
+
keys before sending the request.
|
|
379
387
|
|
|
380
|
-
|
|
381
|
-
(e.g. you only have a `pageId`), drop down to the top-level [`pages` API](./pages.md) — it covers
|
|
382
|
-
create / get / update / archive / unarchive and accepts raw property IDs only.
|
|
388
|
+
Read a page through `pages.get(pageId)` before calling its instance methods.
|
|
383
389
|
|
|
384
390
|
### Archiving and unarchiving a row
|
|
385
391
|
|
|
386
|
-
`row.archive()` is shorthand for calling `row.
|
|
387
|
-
shorthand for calling `row.
|
|
388
|
-
`UpdatePageResult`. Use `row.
|
|
392
|
+
`row.archive()` is shorthand for calling `row.updateById({ is_archived: true })`. `row.unarchive()`
|
|
393
|
+
is shorthand for calling `row.updateById({ is_archived: false })`. Both methods return a
|
|
394
|
+
`UpdatePageResult`. Use `row.updateById` to change archive status and other fields in one request.
|
|
389
395
|
|
|
390
396
|
## Read declarations
|
|
391
397
|
|
|
@@ -427,24 +433,21 @@ rendering:
|
|
|
427
433
|
|
|
428
434
|
```tsx
|
|
429
435
|
import { useState } from "react"
|
|
430
|
-
import type {
|
|
436
|
+
import type { NotionPage } from "@notionhq/custom-blocks"
|
|
431
437
|
import { useDataSource } from "@notionhq/custom-blocks/react"
|
|
432
438
|
|
|
433
439
|
const KEY = "people"
|
|
434
440
|
|
|
435
|
-
function isComplete(item:
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
Number.isFinite(item.propertiesByKey.score)
|
|
440
|
-
)
|
|
441
|
+
function isComplete(item: NotionPage): boolean {
|
|
442
|
+
const title = item.getPropertyByKey("name")
|
|
443
|
+
const score = item.getPropertyByKey("score")
|
|
444
|
+
return title?.type === "title" && score?.type === "number" && Number.isFinite(score.number)
|
|
441
445
|
}
|
|
442
446
|
|
|
443
447
|
export function ScoreList() {
|
|
444
448
|
const [limit, setLimit] = useState(20)
|
|
445
|
-
const { items, isLoading, hasMore
|
|
449
|
+
const { items, isLoading, hasMore } = useDataSource(KEY, { limit })
|
|
446
450
|
|
|
447
|
-
if (error) return <div role="alert">Couldn't load: {error.message}</div>
|
|
448
451
|
if (isLoading && items.length === 0) return <div>Loading…</div>
|
|
449
452
|
|
|
450
453
|
const displayItems = items.filter(isComplete)
|
|
@@ -455,11 +458,17 @@ export function ScoreList() {
|
|
|
455
458
|
return (
|
|
456
459
|
<div>
|
|
457
460
|
<ul>
|
|
458
|
-
{displayItems.map(item =>
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
{displayItems.map(item => {
|
|
462
|
+
const title = item.getPropertyByKey("name")
|
|
463
|
+
const score = item.getPropertyByKey("score")
|
|
464
|
+
return (
|
|
465
|
+
<li key={item.id}>
|
|
466
|
+
{title?.type === "title" ? title.title.map(text => text.plain_text).join("") : ""}
|
|
467
|
+
{" — "}
|
|
468
|
+
{score?.type === "number" ? score.number : ""}
|
|
469
|
+
</li>
|
|
470
|
+
)
|
|
471
|
+
})}
|
|
463
472
|
</ul>
|
|
464
473
|
{hasMore && limit < 999 ? (
|
|
465
474
|
<button
|
|
@@ -492,11 +501,13 @@ export function ScoreList() {
|
|
|
492
501
|
|
|
493
502
|
## Property support
|
|
494
503
|
|
|
495
|
-
This table shows property support for custom blocks running in Notion.
|
|
504
|
+
This table shows property support for custom blocks running in Notion. The query-result descriptions
|
|
505
|
+
refer to the core values inside each property object. For example, “Number” refers to
|
|
506
|
+
`property.number` in `{ id, type: "number", number: 8 }`.
|
|
496
507
|
|
|
497
|
-
- **Query result** shows values in `
|
|
508
|
+
- **Query result** shows values in `properties` from `useDataSource` and
|
|
498
509
|
`customBlock.subscribeToDataSource`. Missing values can be `undefined`.
|
|
499
|
-
- **Update row** covers writes through `item.
|
|
510
|
+
- **Update row** covers writes through `item.updateByKey({ properties: ... })`.
|
|
500
511
|
- **Filter** and **Sort** cover query options.
|
|
501
512
|
|
|
502
513
|
- 🟢 **Supported:** The SDK supports this operation in Notion.
|
|
@@ -513,71 +524,64 @@ This table shows property support for custom blocks running in Notion.
|
|
|
513
524
|
| `url` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
514
525
|
| `email` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
515
526
|
| `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
516
|
-
| `select` | 🟢 Option
|
|
517
|
-
| `multi_select` | 🟢 Array of option
|
|
518
|
-
| `status` | 🟢 Option
|
|
519
|
-
| `date` | 🟢
|
|
520
|
-
| `people` | 🟢
|
|
521
|
-
| `files` | 🟡
|
|
522
|
-
| `unique_id` |
|
|
523
|
-
| `relation` | 🟢
|
|
524
|
-
| `place` |
|
|
525
|
-
| `formula` |
|
|
526
|
-
| `rollup` |
|
|
527
|
-
| `button` |
|
|
528
|
-
| `verification` |
|
|
529
|
-
| `last_visited_time` | 🟡
|
|
530
|
-
| `location` |
|
|
531
|
-
| `created_time` | 🟢
|
|
532
|
-
| `last_edited_time` | 🟢
|
|
533
|
-
| `created_by` | 🟢
|
|
534
|
-
| `last_edited_by` | 🟢
|
|
527
|
+
| `select` | 🟢 Option object | 🟡 Set value only | 🟢 Supported | 🔴 Unavailable |
|
|
528
|
+
| `multi_select` | 🟢 Array of option objects | 🟡 Set values only | 🟢 Supported | 🔴 Unavailable |
|
|
529
|
+
| `status` | 🟢 Option object | 🟡 Set value only | 🟢 Option names, group names, or empty checks | 🔴 Unavailable |
|
|
530
|
+
| `date` | 🟢 Date object | 🟡 Minute precision | 🟢 Supported | 🟢 Supported |
|
|
531
|
+
| `people` | 🟢 User or group references | 🟢 Supported | 🟢 Supported | 🟢 Native name ordering |
|
|
532
|
+
| `files` | 🟡 External files only | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
|
|
533
|
+
| `unique_id` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
534
|
+
| `relation` | 🟢 Page reference array | 🟡 Replaces value. Rejects `has_more: true`. | 🟢 Supported | 🔴 Unavailable for standard relations. ⚫ Notion cannot sort XLDB targets. |
|
|
535
|
+
| `place` | 🟢 Place object | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
|
|
536
|
+
| `formula` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
537
|
+
| `rollup` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
|
|
538
|
+
| `button` | 🔴 `undefined` | 🔴 Unavailable | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
|
|
539
|
+
| `verification` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
540
|
+
| `last_visited_time` | 🟡 Viewer timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
541
|
+
| `location` | 🔴 `undefined` | 🔴 Unavailable | 🔴 Unavailable elsewhere. ⚫ Notion disables filters in My Meetings and Library system databases. | 🔴 Unavailable elsewhere. ⚫ Notion disables sorts in Library system databases. |
|
|
542
|
+
| `created_time` | 🟢 Timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
543
|
+
| `last_edited_time` | 🟢 Timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
544
|
+
| `created_by` | 🟢 Actor reference or null | 🔴 Unavailable | 🟡 Schema-backed creator filters | 🟡 Schema property only |
|
|
545
|
+
| `last_edited_by` | 🟢 Actor reference or null | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
535
546
|
|
|
536
547
|
### Notes
|
|
537
548
|
|
|
538
|
-
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
-
|
|
542
|
-
|
|
543
|
-
`last_edited_time`, `created_by`, and `last_edited_by`. The data source does not need matching
|
|
544
|
-
schema properties. These values are read-only. Timestamps use `NotionDateTime` in UTC. Creator and
|
|
545
|
-
editor values use arrays of record pointers.
|
|
549
|
+
- Query data source results use the Pages API property objects. Narrow each object by its `type`
|
|
550
|
+
field.
|
|
551
|
+
- Date values use `start` and optional `end`.
|
|
552
|
+
- Missing or unsupported properties return `undefined`. Empty supported properties keep their typed
|
|
553
|
+
objects.
|
|
546
554
|
- Filters and sorts can only reference properties defined in the database schema. For example, to
|
|
547
555
|
sort by creation time, you must first add a **Created time** property to the database and
|
|
548
|
-
reference that property's ID.
|
|
549
|
-
read-only metadata and cannot be used when querying.
|
|
556
|
+
reference that property's ID.
|
|
550
557
|
- You can sort by up to 10 unique properties.
|
|
551
558
|
- Date-time filter values may include seconds or milliseconds. The Notion host evaluates them at
|
|
552
559
|
minute precision. Date filters do not expose end-date targeting.
|
|
553
560
|
- Status group filters use stored English group names. The SDK does not normalize localized names.
|
|
554
561
|
- `group_equals` matches any listed group. `group_does_not_equal` excludes all listed groups.
|
|
555
562
|
- Empty group arrays and unknown group names return a nonretryable query error.
|
|
556
|
-
- People properties
|
|
557
|
-
`
|
|
558
|
-
`groupId|workspaceId`. People filters support users and groups. Bot and organization bot filtering
|
|
559
|
-
is not supported.
|
|
563
|
+
- People properties contain arrays of user or group references in `people`. Group IDs use
|
|
564
|
+
`groupId|workspaceId`.
|
|
560
565
|
- Creator filters require an actual **Created by** column. Use its bound key or property ID, not the
|
|
561
566
|
synthetic `created_by` metadata ID.
|
|
562
567
|
- Filters accept one condition or an `and` group of up to 25 conditions. The SDK does not support
|
|
563
568
|
`or` or nested groups.
|
|
564
|
-
- Select, multi-select, and status
|
|
565
|
-
|
|
566
|
-
colors.
|
|
569
|
+
- Select, multi-select, and status values contain option objects. Writes do not edit option
|
|
570
|
+
definitions or colors.
|
|
567
571
|
|
|
568
572
|
### Writing values
|
|
569
573
|
|
|
570
|
-
|
|
571
|
-
status as a string:
|
|
574
|
+
Read the status name from its typed property object:
|
|
572
575
|
|
|
573
576
|
```ts
|
|
574
|
-
item.
|
|
577
|
+
const property = item.getPropertyByKey("status")
|
|
578
|
+
const name = property?.type === "status" ? property.status?.name : undefined
|
|
575
579
|
```
|
|
576
580
|
|
|
577
|
-
|
|
581
|
+
Write inputs remain unchanged. Here, `status` is a declared property key:
|
|
578
582
|
|
|
579
583
|
```ts
|
|
580
|
-
const result = await item.
|
|
584
|
+
const result = await item.updateByKey({
|
|
581
585
|
properties: {
|
|
582
586
|
status: { type: "status", status: { name: "Done" } },
|
|
583
587
|
},
|
|
@@ -602,13 +606,12 @@ See [Pages property support](./pages.md#property-support) for the page-property
|
|
|
602
606
|
|
|
603
607
|
### Rows & values
|
|
604
608
|
|
|
605
|
-
- `NotionDataSource` — a resolved data source
|
|
606
|
-
|
|
607
|
-
- `
|
|
608
|
-
`{ id,
|
|
609
|
-
- `
|
|
610
|
-
- `
|
|
611
|
-
`update` helper.
|
|
609
|
+
- `NotionDataSource` — a resolved data source returned by `initCustomBlock()`, including its binding
|
|
610
|
+
and database schemas.
|
|
611
|
+
- `NotionPage` — a single row exposed to app code:
|
|
612
|
+
`{ id, properties, getPropertyById, getPropertyByKey, updateById, updateByKey, archive, unarchive }`.
|
|
613
|
+
- `NotionPagePropertyValue` — the typed property values exposed by unified pages.
|
|
614
|
+
- `PageUpdatePayload` / `UpdatePageResult` — arguments and result for the page mutation methods.
|
|
612
615
|
- `UseDataSourceOptions` — options accepted by `useDataSource`: `limit?: number`,
|
|
613
616
|
`filter?: NotionDataSourceFilter`, and `sorts?: NotionDataSourceSort[]`.
|
|
614
617
|
- `NotionDataSourceFilter` — one property condition or one shallow `and` group.
|
|
@@ -642,9 +645,6 @@ See [Pages property support](./pages.md#property-support) for the page-property
|
|
|
642
645
|
- `NotionStatusGroup` — the `status` property's "To do / In progress / Done" grouping.
|
|
643
646
|
- `NotionDualProperty` — properties that have both a primary and a secondary axis (e.g. `unique_id`
|
|
644
647
|
prefix + number).
|
|
645
|
-
- `NotionBuiltinPropertyId` — string-literal union of the four synthetic property IDs
|
|
646
|
-
(`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
|
|
647
|
-
- `NOTION_BUILTIN_PROPERTY_IDS` — runtime list of the four built-in IDs.
|
|
648
648
|
|
|
649
649
|
### Database schema & pointers
|
|
650
650
|
|
|
@@ -663,16 +663,53 @@ Branded string types — they're plain strings at runtime but TypeScript disting
|
|
|
663
663
|
|
|
664
664
|
### Date values
|
|
665
665
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
666
|
+
Read date values from `properties[name].date`. The value is `null` when the property is empty.
|
|
667
|
+
Otherwise, it contains `start` and optional `end` and `time_zone` fields. All-day values use date
|
|
668
|
+
strings. Values with a time component use ISO 8601 datetime strings.
|
|
669
|
+
|
|
670
|
+
```ts
|
|
671
|
+
const date = row.properties["Due date"]
|
|
672
|
+
if (date?.type === "date" && date.date) {
|
|
673
|
+
console.log(date.date.start, date.date.end)
|
|
674
|
+
}
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
`NotionDateInput` describes this date shape for reads and writes. The SDK does not expose date
|
|
678
|
+
reminders.
|
|
679
|
+
|
|
680
|
+
## Shared page results
|
|
681
|
+
|
|
682
|
+
Data source results expose one `propertyIdsByKey` map beside `items`. Unbound keys map to
|
|
683
|
+
`undefined`. Each `NotionPage` exposes property getters and mutation methods.
|
|
684
|
+
`DataSourcesQueryResult` and `DataSourcesPageResult` describe the shared result structures used by
|
|
685
|
+
all page operations. The same page type appears in asynchronous namespace results.
|
|
686
|
+
|
|
687
|
+
## Asynchronous namespace
|
|
688
|
+
|
|
689
|
+
Calls to `dataSources.query()` before initialization wait until the SDK initializes. Initialization
|
|
690
|
+
failure returns `{ status: "error", error }` without creating a query subscription.
|
|
691
|
+
|
|
692
|
+
```ts
|
|
693
|
+
import { dataSources } from "@notionhq/custom-blocks"
|
|
694
|
+
|
|
695
|
+
const query = await dataSources.query("people", { limit: 50 })
|
|
696
|
+
if (query.status === "success") {
|
|
697
|
+
const { items, propertyIdsByKey, hasMore } = query
|
|
698
|
+
}
|
|
699
|
+
const result = await dataSources.getPage("people", pageId)
|
|
700
|
+
if (result.status === "success") {
|
|
701
|
+
console.log(result.page.id)
|
|
702
|
+
}
|
|
703
|
+
const created = await dataSources.create("people", {
|
|
704
|
+
properties: { name: { type: "title", title: [{ text: { content: "Alex" } }] } },
|
|
705
|
+
})
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
These methods return `{ status: "success", ...data }` or `{ status: "error", error }`. A successful
|
|
709
|
+
`query` result includes `isLoading: false`. The query releases its subscription after success or
|
|
710
|
+
failure. Hooks and subscriptions keep their existing reactive behavior. `hasMore` reports truncation
|
|
711
|
+
beyond the requested limit. Queries retain existing filters, sorts, and limits.
|
|
712
|
+
|
|
713
|
+
`dataSources.create` accepts `Omit<CreatePageArgs, "parent" | "position">`. The selected binding
|
|
714
|
+
supplies the create parent. `DataSourcesPageResult` describes get/create results.
|
|
715
|
+
`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`.
|
|
@@ -57,9 +57,9 @@ recovery does not depend on `isRetryable`.
|
|
|
57
57
|
|
|
58
58
|
## Initialization errors
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
`initCustomBlock` rejects with `CustomBlockInitializationError`. Its `code` type is
|
|
61
|
+
`CustomBlockInitializationErrorCode`, which covers failures reported by either side of the handshake
|
|
62
|
+
plus SDK-local iframe errors.
|
|
63
63
|
|
|
64
64
|
`CustomBlockInitializationErrorInfo` is the matching `{ code, message, isRetryable }` object type.
|
|
65
65
|
|
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.
|