@notionhq/custom-blocks 0.2.24 → 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.
Files changed (73) hide show
  1. package/README.md +8 -5
  2. package/dist/bridge/SandboxBridge.d.ts +15 -14
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +117 -35
  5. package/dist/bridge/dataSources/resolve.d.ts +1 -3
  6. package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
  7. package/dist/bridge/dataSources/resolve.js +1 -11
  8. package/dist/bridge/dataSources/subscribe.d.ts +2 -1
  9. package/dist/bridge/dataSources/subscribe.d.ts.map +1 -1
  10. package/dist/bridge/dataSources/subscribe.js +6 -1
  11. package/dist/bridge/hostState.d.ts +11 -39
  12. package/dist/bridge/hostState.d.ts.map +1 -1
  13. package/dist/bridge/hostState.js +5 -50
  14. package/dist/bridge/page.d.ts +14 -0
  15. package/dist/bridge/page.d.ts.map +1 -0
  16. package/dist/bridge/page.js +59 -0
  17. package/dist/bridge/sandboxClient.d.ts +8 -14
  18. package/dist/bridge/sandboxClient.d.ts.map +1 -1
  19. package/dist/bridge/sandboxClient.js +13 -21
  20. package/dist/dataSources.d.ts +8 -0
  21. package/dist/dataSources.d.ts.map +1 -0
  22. package/dist/dataSources.js +103 -0
  23. package/dist/index.d.ts +6 -6
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -2
  26. package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -5
  27. package/dist/protocol/dataSources/dataSourcePage.js +2 -3
  28. package/dist/protocol/dataSources/propertySchema.d.ts +1 -0
  29. package/dist/protocol/index.d.ts +1 -0
  30. package/dist/protocol/index.js +1 -0
  31. package/dist/protocol/messages/createPage.js +2 -2
  32. package/dist/protocol/messages/createPageResult.d.ts +468 -1
  33. package/dist/protocol/messages/createPageResult.js +17 -2
  34. package/dist/protocol/messages/getPage.d.ts +468 -1
  35. package/dist/protocol/messages/getPage.js +18 -3
  36. package/dist/protocol/messages/hostToSandbox.d.ts +2587 -178
  37. package/dist/protocol/messages/hostToSandbox.js +24 -12
  38. package/dist/protocol/messages/openExternalUrl.d.ts +32 -0
  39. package/dist/protocol/messages/openExternalUrl.js +26 -0
  40. package/dist/protocol/messages/queryDataSourceResult.d.ts +468 -1
  41. package/dist/protocol/messages/queryDataSourceResult.js +18 -2
  42. package/dist/protocol/messages/sandboxToHost.d.ts +6 -0
  43. package/dist/protocol/messages/sandboxToHost.js +2 -0
  44. package/dist/protocol/messages/updatePage.d.ts +1 -0
  45. package/dist/protocol/messages/updatePage.js +4 -3
  46. package/dist/protocol/messages/updatePageResult.d.ts +467 -1
  47. package/dist/protocol/messages/updatePageResult.js +16 -2
  48. package/dist/protocol/pages/page.d.ts +386 -6
  49. package/dist/protocol/pages/page.js +23 -2
  50. package/dist/protocol/protocolVersion.d.ts +2 -1
  51. package/dist/protocol/protocolVersion.js +4 -1
  52. package/dist/react/useDataSource.d.ts +1 -1
  53. package/dist/react/useDataSource.d.ts.map +1 -1
  54. package/dist/react/useDataSource.js +1 -3
  55. package/dist/types.d.ts +55 -96
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/version.js +1 -1
  58. package/docs/block-location.md +3 -3
  59. package/docs/data-sources.md +167 -133
  60. package/docs/errors.md +9 -9
  61. package/docs/links.md +44 -0
  62. package/docs/pages.md +113 -182
  63. package/package.json +1 -1
  64. package/src/bridge/SandboxBridge.ts +189 -62
  65. package/src/bridge/dataSources/resolve.ts +1 -20
  66. package/src/bridge/dataSources/subscribe.ts +10 -5
  67. package/src/bridge/hostState.ts +21 -100
  68. package/src/bridge/page.ts +90 -0
  69. package/src/bridge/sandboxClient.ts +15 -25
  70. package/src/dataSources.ts +140 -0
  71. package/src/index.ts +8 -19
  72. package/src/react/useDataSource.ts +1 -3
  73. package/src/types.ts +61 -109
@@ -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 rows, property schemas, loading and error state, and `hasMore`. Each query
10
- result replaces the previous rows in the snapshot. Subscriptions remain independent, even when they
11
- query the same data source.
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
- Prefer `propertiesByKey` when reading declared properties. These keys stay the same across bindings.
26
- `propertiesById` exposes values keyed by the bound data source's raw property IDs.
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 rows, schema, loading state, and row methods for
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: NotionDataSourcePage[]
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`. `propertySchemasByKey` exposes the corresponding schemas and is likewise `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 follow the SDK's [error-handling contract](./errors.md).
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 reports invalid keys, types, operators, and values through the snapshot's `error` field.
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` instead of `key` to address the column by its actual property ID. The `created_by`
221
- key selects the filter type. It does not identify the column. The synthetic read entry
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,33 +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 returned by either API is a `NotionDataSourcePage` —
347
- `{ id, propertiesById, propertiesByKey, update, archive, unarchive }`. Read property values through
348
- either of the two views:
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
- - `propertiesByKey[key]` — keyed by the semantic property keys you declared in the manifest.
351
- - `propertiesById[propertyId]` — keyed by the raw Notion property ID.
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
- The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) are always
354
- present in row `propertiesById` and snapshot `propertySchemasById`. They have no semantic keys, so
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
- Matching metadata columns also appear under their schema property IDs and bound semantic keys.
358
- `last_visited_time` requires an internal schema property and resolves the current viewer’s visit.
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.
359
365
 
360
- `collectionSchema.propertiesById` contains only actual database properties. The SDK uses this map to
361
- resolve bindings and validate every filter and sort reference. Synthetic metadata in
362
- `propertySchemasById` does not make a property available for filters or sorts.
366
+ The bridge keeps database schemas internally to validate filter and sort references. Query results
367
+ do not expose those schemas.
363
368
 
364
369
  Property queries fail when the host does not provide a database schema. Queries without filters or
365
370
  sorts can continue.
366
371
 
367
372
  ### Updating a row
368
373
 
369
- Each page carries its own `update` helper:
374
+ Each page has `updateById` and `updateByKey` methods:
370
375
 
371
376
  ```ts
372
- await row.update({
377
+ await row.updateByKey({
373
378
  properties: {
374
379
  score: { type: "number", number: 8 }, // semantic key
375
380
  },
@@ -377,18 +382,16 @@ await row.update({
377
382
  })
378
383
  ```
379
384
 
380
- Property values can be keyed by **either** semantic keys or raw IDs. The SDK resolves semantic keys
381
- to IDs before sending the request.
385
+ Use `updateByKey` for manifest keys and `updateById` for raw property IDs. The SDK resolves manifest
386
+ keys before sending the request.
382
387
 
383
- Use `row.update(...)` whenever you already have a row in hand. For pages you don't have a row for
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.
388
+ Read a page through `pages.get(pageId)` before calling its instance methods.
386
389
 
387
390
  ### Archiving and unarchiving a row
388
391
 
389
- `row.archive()` is shorthand for calling `row.update({ is_archived: true })`. `row.unarchive()` is
390
- shorthand for calling `row.update({ is_archived: false })`. Both methods return an
391
- `UpdatePageResult`. Use `row.update` to change archive status and other fields in one request.
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.
392
395
 
393
396
  ## Read declarations
394
397
 
@@ -430,24 +433,21 @@ rendering:
430
433
 
431
434
  ```tsx
432
435
  import { useState } from "react"
433
- import type { NotionDataSourcePage } from "@notionhq/custom-blocks"
436
+ import type { NotionPage } from "@notionhq/custom-blocks"
434
437
  import { useDataSource } from "@notionhq/custom-blocks/react"
435
438
 
436
439
  const KEY = "people"
437
440
 
438
- function isComplete(item: NotionDataSourcePage): boolean {
439
- return (
440
- typeof item.propertiesByKey.name === "string" &&
441
- typeof item.propertiesByKey.score === "number" &&
442
- Number.isFinite(item.propertiesByKey.score)
443
- )
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)
444
445
  }
445
446
 
446
447
  export function ScoreList() {
447
448
  const [limit, setLimit] = useState(20)
448
- const { items, isLoading, hasMore, error } = useDataSource(KEY, { limit })
449
+ const { items, isLoading, hasMore } = useDataSource(KEY, { limit })
449
450
 
450
- if (error) return <div role="alert">Couldn't load: {error.message}</div>
451
451
  if (isLoading && items.length === 0) return <div>Loading…</div>
452
452
 
453
453
  const displayItems = items.filter(isComplete)
@@ -458,11 +458,17 @@ export function ScoreList() {
458
458
  return (
459
459
  <div>
460
460
  <ul>
461
- {displayItems.map(item => (
462
- <li key={item.id}>
463
- {String(item.propertiesByKey.name)} — {Number(item.propertiesByKey.score)}
464
- </li>
465
- ))}
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
+ })}
466
472
  </ul>
467
473
  {hasMore && limit < 999 ? (
468
474
  <button
@@ -495,11 +501,13 @@ export function ScoreList() {
495
501
 
496
502
  ## Property support
497
503
 
498
- 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 }`.
499
507
 
500
- - **Query result** shows values in `propertiesById` and `propertiesByKey` from `useDataSource` and
508
+ - **Query result** shows values in `properties` from `useDataSource` and
501
509
  `customBlock.subscribeToDataSource`. Missing values can be `undefined`.
502
- - **Update row** covers writes through `item.update({ properties: ... })`.
510
+ - **Update row** covers writes through `item.updateByKey({ properties: ... })`.
503
511
  - **Filter** and **Sort** cover query options.
504
512
 
505
513
  - 🟢 **Supported:** The SDK supports this operation in Notion.
@@ -507,80 +515,73 @@ This table shows property support for custom blocks running in Notion.
507
515
  - 🔴 **Unavailable:** The SDK does not expose this operation.
508
516
  - ⚫ **Not supported in Notion:** Notion itself does not support this operation in the stated case.
509
517
 
510
- | Property type | Query result | Update row | Filter | Sort |
511
- | ------------------- | ----------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
512
- | `title` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
513
- | `rich_text` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
514
- | `number` | 🟢 Number | 🟢 Supported | 🟢 Supported | 🟢 Supported |
515
- | `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported | 🟢 Supported |
516
- | `url` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
517
- | `email` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
518
- | `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
519
- | `select` | 🟢 Option name | 🟡 Set value only | 🟢 Supported | 🔴 Unavailable |
520
- | `multi_select` | 🟢 Array of option names | 🟡 Set values only | 🟢 Supported | 🔴 Unavailable |
521
- | `status` | 🟢 Option name | 🟡 Set value only | 🟢 Option names, group names, or empty checks | 🔴 Unavailable |
522
- | `date` | 🟢 `NotionDateValue` | 🟡 Minute precision | 🟢 Supported | 🟢 Supported |
523
- | `people` | 🟢 Array of record pointers | 🟢 Supported | 🟢 Supported | 🟢 Native name ordering |
524
- | `files` | 🟡 Text fallback | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
525
- | `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
526
- | `relation` | 🟢 Array of record pointers | 🟡 Replaces value. Rejects `has_more: true`. | 🟢 Supported | 🔴 Unavailable for standard relations. ⚫ Notion cannot sort XLDB targets. |
527
- | `place` | 🟡 Text fallback | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
528
- | `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
529
- | `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
530
- | `button` | 🟡 Text fallback | 🔴 Unavailable | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
531
- | `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
532
- | `last_visited_time` | 🟡 Viewer’s `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
533
- | `location` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable elsewhere. ⚫ Notion disables filters in My Meetings and Library system databases. | 🔴 Unavailable elsewhere. ⚫ Notion disables sorts in Library system databases. |
534
- | `created_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
535
- | `last_edited_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
536
- | `created_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🟡 Schema-backed creator filters | 🟡 Schema property only |
537
- | `last_edited_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
518
+ | Property type | Query result | Update row | Filter | Sort |
519
+ | ------------------- | --------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
520
+ | `title` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
521
+ | `rich_text` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
522
+ | `number` | 🟢 Number | 🟢 Supported | 🟢 Supported | 🟢 Supported |
523
+ | `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported | 🟢 Supported |
524
+ | `url` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
525
+ | `email` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
526
+ | `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
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 |
538
546
 
539
547
  ### Notes
540
548
 
541
- - Text values omit formatting, mention tokens, and annotations. A text fallback can be empty and
542
- does not preserve the property's structured value. It does not provide structured formula or
543
- rollup results.
544
- - Record pointers contain a table name and a record ID.
545
- - Every row includes four built-in properties in `propertiesById`: `created_time`,
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.
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.
549
554
  - Filters and sorts can only reference properties defined in the database schema. For example, to
550
555
  sort by creation time, you must first add a **Created time** property to the database and
551
- reference that property's ID. The synthetic `created_time` field returned with every row is
552
- read-only metadata and cannot be used when querying.
556
+ reference that property's ID.
553
557
  - You can sort by up to 10 unique properties.
554
558
  - Date-time filter values may include seconds or milliseconds. The Notion host evaluates them at
555
559
  minute precision. Date filters do not expose end-date targeting.
556
560
  - Status group filters use stored English group names. The SDK does not normalize localized names.
557
561
  - `group_equals` matches any listed group. `group_does_not_equal` excludes all listed groups.
558
562
  - Empty group arrays and unknown group names return a nonretryable query error.
559
- - People properties return record pointers with table values of `notion_user`,
560
- `space_permission_group`, `bot`, or `organization_bot`. Group IDs use the composite form
561
- `groupId|workspaceId`. People filters support users and groups. Bot and organization bot filtering
562
- is not supported.
563
+ - People properties contain arrays of user or group references in `people`. Group IDs use
564
+ `groupId|workspaceId`.
563
565
  - Creator filters require an actual **Created by** column. Use its bound key or property ID, not the
564
566
  synthetic `created_by` metadata ID.
565
567
  - Filters accept one condition or an `and` group of up to 25 conditions. The SDK does not support
566
568
  `or` or nested groups.
567
- - Select, multi-select, and status query values contain option names. Their schemas provide option
568
- IDs and colors separately. Writes set the selected values. They do not edit option definitions or
569
- colors.
569
+ - Select, multi-select, and status values contain option objects. Writes do not edit option
570
+ definitions or colors.
570
571
 
571
572
  ### Writing values
572
573
 
573
- The value you read has a different shape from the value you write. For example, a query returns a
574
- status as a string:
574
+ Read the status name from its typed property object:
575
575
 
576
576
  ```ts
577
- item.propertiesByKey.status // "Done"
577
+ const property = item.getPropertyByKey("status")
578
+ const name = property?.type === "status" ? property.status?.name : undefined
578
579
  ```
579
580
 
580
- To update it, wrap the string in a property object. Here, `status` is a declared property key:
581
+ Write inputs remain unchanged. Here, `status` is a declared property key:
581
582
 
582
583
  ```ts
583
- const result = await item.update({
584
+ const result = await item.updateByKey({
584
585
  properties: {
585
586
  status: { type: "status", status: { name: "Done" } },
586
587
  },
@@ -605,13 +606,12 @@ See [Pages property support](./pages.md#property-support) for the page-property
605
606
 
606
607
  ### Rows & values
607
608
 
608
- - `NotionDataSource` — a resolved data source: semantic key, optional `collectionSchema`,
609
- `propertyIdsByKey`, and `propertySchemasById`.
610
- - `NotionDataSourcePage` — a single row exposed to app code:
611
- `{ id, propertiesById, propertiesByKey, update, archive, unarchive }`.
612
- - `NotionDataSourceValue` — the value union for `propertiesById` and `propertiesByKey`.
613
- - `NotionDataSourcePageUpdateArgs` / `UpdatePageResult` — arguments and result for the per-page
614
- `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.
615
615
  - `UseDataSourceOptions` — options accepted by `useDataSource`: `limit?: number`,
616
616
  `filter?: NotionDataSourceFilter`, and `sorts?: NotionDataSourceSort[]`.
617
617
  - `NotionDataSourceFilter` — one property condition or one shallow `and` group.
@@ -645,9 +645,6 @@ See [Pages property support](./pages.md#property-support) for the page-property
645
645
  - `NotionStatusGroup` — the `status` property's "To do / In progress / Done" grouping.
646
646
  - `NotionDualProperty` — properties that have both a primary and a secondary axis (e.g. `unique_id`
647
647
  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
648
 
652
649
  ### Database schema & pointers
653
650
 
@@ -666,16 +663,53 @@ Branded string types — they're plain strings at runtime but TypeScript disting
666
663
 
667
664
  ### Date values
668
665
 
669
- Returned wherever a date / date-range value appears (e.g. inside `propertiesByKey` for a `date`
670
- property). All-day values use `NotionDate*` shapes; values with a time component use
671
- `NotionDateTime*`.
672
-
673
- - `NotionDateValue` — discriminated union covering every date-shaped value below.
674
- - `NotionDate`
675
- - `NotionDateRange`
676
- - `NotionDateTime`
677
- - `NotionDateTimeRange`
678
- - `NotionDateReminder`
679
- - `NotionDateTimeReminder`
680
- - `NotionTimeReminder`
681
- - `NotionNoReminder`
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
- Request-style SDK APIs resolve to a result with `status: "success"` or `status: "error"`.
4
- Conceptually, success payloads vary by API while error results contain an `error` object with a
5
- consistent structure:
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
- ```ts
8
- type Result<T> = { status: "success"; value: T } | { status: "error"; error: CustomBlockErrorInfo }
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
- Unlike request helpers, `initCustomBlock` rejects with `CustomBlockInitializationError`. Its `code`
61
- type is `CustomBlockInitializationErrorCode`, which covers failures reported by either side of the
62
- handshake plus SDK-local iframe errors.
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.