@notionhq/custom-blocks 0.2.15 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/SandboxBridge.d.ts +7 -8
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +49 -44
- package/dist/bridge/dataSources/query.d.ts +2 -1
- package/dist/bridge/dataSources/query.d.ts.map +1 -1
- package/dist/bridge/dataSources/query.js +39 -8
- package/dist/bridge/dataSources/resolve.d.ts +10 -10
- package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolve.js +17 -5
- package/dist/protocol/dataSources/dataSource.d.ts +61 -6
- package/dist/protocol/dataSources/dataSource.js +35 -6
- package/dist/protocol/dataSources/propertySchema.d.ts +2 -0
- package/dist/protocol/dataSources/propertySchema.js +7 -0
- package/dist/protocol/messages/queryDataSource.d.ts +485 -485
- package/dist/protocol/messages/queryDataSource.js +43 -43
- package/dist/protocol/messages/queryDataSourceResult.d.ts +1 -1
- package/dist/protocol/messages/sandboxToHost.d.ts +178 -178
- package/dist/protocol/protocolVersion.d.ts +1 -1
- package/dist/protocol/protocolVersion.js +1 -1
- package/dist/typeUtils.d.ts +10 -0
- package/dist/typeUtils.d.ts.map +1 -0
- package/dist/typeUtils.js +1 -0
- package/dist/types.d.ts +18 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +4 -4
- package/docs/data-sources.md +60 -35
- package/docs/errors.md +17 -1
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +62 -50
- package/src/bridge/dataSources/query.ts +47 -9
- package/src/bridge/dataSources/resolve.ts +30 -13
- package/src/typeUtils.ts +10 -0
- package/src/types.ts +22 -16
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { CustomBlockQueryDataSourceErrorInfo } from "./protocol/messages/qu
|
|
|
14
14
|
import type { UpdatePageMessage } from "./protocol/messages/updatePage.js";
|
|
15
15
|
import type { CustomBlockUpdatePageErrorInfo, UpdatePageResultMessage } from "./protocol/messages/updatePageResult.js";
|
|
16
16
|
import type { NotionPageCover, NotionPageIcon, NotionPagePropertyValue } from "./protocol/pages/page.js";
|
|
17
|
+
import type { ExclusiveUnion } from "./typeUtils.js";
|
|
17
18
|
export type { CustomBlockErrorInfo } from "./protocol/errors.js";
|
|
18
19
|
export type { NotionDataSourceId, NotionSpaceId, } from "./protocol/ids.js";
|
|
19
20
|
export type { NotionUser, NotionUserId, NotionUserList, } from "./protocol/users/user.js";
|
|
@@ -73,14 +74,14 @@ export type NotionDataSourcePageUpdateArgs = {
|
|
|
73
74
|
/** Whether to archive this page. */
|
|
74
75
|
is_archived?: boolean;
|
|
75
76
|
};
|
|
76
|
-
export type NotionDataSourceTextFilterOperator = CustomBlockTextFilterOperator
|
|
77
|
-
export type NotionDataSourceNumberFilterOperator = CustomBlockNumberFilterOperator
|
|
78
|
-
export type NotionDataSourceCheckboxFilterOperator = CustomBlockCheckboxFilterOperator
|
|
79
|
-
export type NotionDataSourceOptionFilterOperator = CustomBlockOptionFilterOperator
|
|
80
|
-
export type NotionDataSourceContainsFilterOperator = CustomBlockContainsFilterOperator
|
|
81
|
-
export type NotionDataSourceDateFilterOperator = CustomBlockDateFilterOperator
|
|
77
|
+
export type NotionDataSourceTextFilterOperator = ExclusiveUnion<CustomBlockTextFilterOperator>;
|
|
78
|
+
export type NotionDataSourceNumberFilterOperator = ExclusiveUnion<CustomBlockNumberFilterOperator>;
|
|
79
|
+
export type NotionDataSourceCheckboxFilterOperator = ExclusiveUnion<CustomBlockCheckboxFilterOperator>;
|
|
80
|
+
export type NotionDataSourceOptionFilterOperator = ExclusiveUnion<CustomBlockOptionFilterOperator>;
|
|
81
|
+
export type NotionDataSourceContainsFilterOperator = ExclusiveUnion<CustomBlockContainsFilterOperator>;
|
|
82
|
+
export type NotionDataSourceDateFilterOperator = ExclusiveUnion<CustomBlockDateFilterOperator>;
|
|
82
83
|
export type NotionDataSourcePersonFilterValue = CustomBlockPersonFilterValue;
|
|
83
|
-
export type NotionDataSourcePeopleFilterOperator = CustomBlockPeopleFilterOperator
|
|
84
|
+
export type NotionDataSourcePeopleFilterOperator = ExclusiveUnion<CustomBlockPeopleFilterOperator>;
|
|
84
85
|
export type NotionDataSourcePropertyAddress = {
|
|
85
86
|
key: string;
|
|
86
87
|
propertyId?: never;
|
|
@@ -88,7 +89,7 @@ export type NotionDataSourcePropertyAddress = {
|
|
|
88
89
|
propertyId: string;
|
|
89
90
|
key?: never;
|
|
90
91
|
};
|
|
91
|
-
export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress &
|
|
92
|
+
export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress & ExclusiveUnion<{
|
|
92
93
|
title: NotionDataSourceTextFilterOperator;
|
|
93
94
|
} | {
|
|
94
95
|
rich_text: NotionDataSourceTextFilterOperator;
|
|
@@ -112,13 +113,13 @@ export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress & (
|
|
|
112
113
|
date: NotionDataSourceDateFilterOperator;
|
|
113
114
|
} | {
|
|
114
115
|
people: NotionDataSourcePeopleFilterOperator;
|
|
115
|
-
}
|
|
116
|
+
}>;
|
|
116
117
|
export type NotionDataSourceSort = NotionDataSourcePropertyAddress & {
|
|
117
118
|
direction: "ascending" | "descending";
|
|
118
119
|
};
|
|
119
|
-
export type NotionDataSourceFilter = NotionDataSourcePropertyFilter | {
|
|
120
|
+
export type NotionDataSourceFilter = ExclusiveUnion<NotionDataSourcePropertyFilter | {
|
|
120
121
|
and: NotionDataSourcePropertyFilter[];
|
|
121
|
-
}
|
|
122
|
+
}>;
|
|
122
123
|
/**
|
|
123
124
|
* Latest live snapshot of a data source query.
|
|
124
125
|
*
|
|
@@ -130,13 +131,15 @@ export type NotionDataSourceFilter = NotionDataSourcePropertyFilter | {
|
|
|
130
131
|
export type DataSourceSnapshot = {
|
|
131
132
|
items: NotionDataSourcePage[];
|
|
132
133
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
134
|
+
* Contains only properties in the database schema.
|
|
135
|
+
* Use this map to resolve property bindings and validate filter and sort references.
|
|
136
|
+
* Undefined when the host does not provide a schema.
|
|
135
137
|
*/
|
|
136
138
|
collectionSchema?: NotionCollectionSchema;
|
|
137
139
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
+
* Contains database properties and four synthetic metadata fields.
|
|
141
|
+
* Use this map to describe values in query snapshots.
|
|
142
|
+
* Synthetic entries do not establish filter or sort support.
|
|
140
143
|
*/
|
|
141
144
|
propertySchemasById: {
|
|
142
145
|
[propertyId: string]: NotionPropertySchema;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAA;AACxG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAA;AAC1G,OAAO,KAAK,EACX,kBAAkB,EAClB,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,OAAO,KAAK,EACX,uBAAuB,EACvB,8BAA8B,EAC9B,MAAM,+DAA+D,CAAA;AACtE,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,6BAA6B,EAC7B,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AACvG,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AA6B,CAC7B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,oBAAoB,CAC/C,oBAAoB,EACpB,2BAA2B,CAC3B,CAAA"}
|
package/dist/version.js
CHANGED
package/docs/block-location.md
CHANGED
|
@@ -65,14 +65,14 @@ before initialization. You can register before initialization without an error.
|
|
|
65
65
|
## Parent
|
|
66
66
|
|
|
67
67
|
Use `getParent()`, `subscribeToParent()`, and `useParent()` to access the block's `NotionParent` in
|
|
68
|
-
the document tree. For a custom
|
|
69
|
-
|
|
68
|
+
the document tree. For a custom database view, the parent identifies the data source associated with
|
|
69
|
+
the view.
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
type NotionParent =
|
|
73
73
|
| { type: "page_id"; page_id: string } // inline custom block under a page
|
|
74
74
|
| { type: "block_id"; block_id: NotionBlockId } // inline custom block under a toggle/column/callout/...
|
|
75
|
-
| { type: "data_source_id"; data_source_id: string } // custom block backing a custom
|
|
75
|
+
| { type: "data_source_id"; data_source_id: string } // custom block backing a custom database view
|
|
76
76
|
| { type: "workspace"; workspace: true } // top-level block parented by a team / workspace
|
|
77
77
|
| { type: "agent_id"; agent_id: NotionAgentId } // agent-owned instruction content
|
|
78
78
|
| { type: "unavailable" } // access denied; no parent ID or kind
|
|
@@ -97,7 +97,7 @@ export function AgentInstructionBadge() {
|
|
|
97
97
|
## Containing page
|
|
98
98
|
|
|
99
99
|
Use `getPage()`, `subscribeToPage()`, and `usePage()` to access the nearest enclosing page or
|
|
100
|
-
|
|
100
|
+
database view page. The page's parent can change even when its ID stays the same.
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
103
|
type CustomBlockPage = {
|
package/docs/data-sources.md
CHANGED
|
@@ -132,6 +132,23 @@ Query failures follow the SDK's [error-handling contract](./errors.md).
|
|
|
132
132
|
|
|
133
133
|
Both subscription APIs accept `limit`, `filter`, and `sorts`.
|
|
134
134
|
|
|
135
|
+
The SDK types prohibit:
|
|
136
|
+
|
|
137
|
+
- Multiple filter types in one property condition, such as
|
|
138
|
+
`{ key: "name", title: { equals: "A" }, number: { equals: 1 } }`.
|
|
139
|
+
- Both `key` and `propertyId` in one filter or sort, such as
|
|
140
|
+
`{ key: "name", propertyId: "title", direction: "ascending" }`.
|
|
141
|
+
- Multiple operators in one property condition, such as
|
|
142
|
+
`{ key: "name", title: { equals: "A", does_not_equal: "B" } }`.
|
|
143
|
+
- A property condition combined with an `and` group, such as
|
|
144
|
+
`{ key: "name", title: { equals: "A" }, and: [] }`.
|
|
145
|
+
|
|
146
|
+
Runtime validation also rejects extra fields. Filters and sorts can reference only actual database
|
|
147
|
+
properties of a supported type.
|
|
148
|
+
|
|
149
|
+
Synthetic metadata IDs such as `created_by` cannot be used in filters or sorts. Add a **Last edited
|
|
150
|
+
time** column to the database. Use its bound key or property ID instead.
|
|
151
|
+
|
|
135
152
|
### Row limits
|
|
136
153
|
|
|
137
154
|
`limit` defaults to 20 and must be a positive integer. The SDK caps values above 999. Each query
|
|
@@ -235,9 +252,16 @@ either of the two views:
|
|
|
235
252
|
- `propertiesById[propertyId]` — keyed by the raw Notion property ID.
|
|
236
253
|
|
|
237
254
|
The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) are always
|
|
238
|
-
present in `propertiesById` and `
|
|
255
|
+
present in row `propertiesById` and snapshot `propertySchemasById`. They have no semantic keys, so
|
|
239
256
|
they do not appear in the `*ByKey` views.
|
|
240
257
|
|
|
258
|
+
`collectionSchema.propertiesById` contains only actual database properties. The SDK uses this map to
|
|
259
|
+
resolve bindings and validate every filter and sort reference. Synthetic metadata in
|
|
260
|
+
`propertySchemasById` does not make a property available for filters or sorts.
|
|
261
|
+
|
|
262
|
+
Property queries fail when the host does not provide a database schema. Queries without filters or
|
|
263
|
+
sorts can continue.
|
|
264
|
+
|
|
241
265
|
### Updating a row
|
|
242
266
|
|
|
243
267
|
Each page carries its own `update` helper:
|
|
@@ -381,34 +405,34 @@ This table shows property support for custom blocks running in Notion.
|
|
|
381
405
|
- 🔴 **Unavailable:** The SDK does not expose this operation.
|
|
382
406
|
- ⚫ **Not supported in Notion:** Notion itself does not support this operation in the stated case.
|
|
383
407
|
|
|
384
|
-
| Property type | Query result | Update row | Filter
|
|
385
|
-
| ------------------- | --------------------------- | -------------------------------------------- |
|
|
386
|
-
| `title` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported
|
|
387
|
-
| `rich_text` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported
|
|
388
|
-
| `number` | 🟢 Number | 🟢 Supported | 🟢 Supported
|
|
389
|
-
| `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported
|
|
390
|
-
| `url` | 🟢 String | 🟢 Supported | 🟢 Supported
|
|
391
|
-
| `email` | 🟢 String | 🟢 Supported | 🟢 Supported
|
|
392
|
-
| `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported
|
|
393
|
-
| `select` | 🟢 Option name | 🟡 Set value only | 🟢 Supported
|
|
394
|
-
| `multi_select` | 🟢 Array of option names | 🟡 Set values only | 🟢 Supported
|
|
395
|
-
| `status` | 🟢 Option name | 🟡 Set value only | 🟡 Option names or empty checks, without groups
|
|
396
|
-
| `date` | 🟢 `NotionDateValue` | 🟡 Minute precision | 🟡 Fixed start-date comparisons or empty checks, at minute precision
|
|
397
|
-
| `people` | 🟢 Array of record pointers | 🟢 Supported | 🟢 Supported
|
|
398
|
-
| `files` | 🟡 Text fallback | 🟡 File URLs only | 🔴 Unavailable
|
|
399
|
-
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable
|
|
400
|
-
| `relation` | 🟢 Array of record pointers | 🟡 Replaces value. Rejects `has_more: true`. | 🔴 Unavailable
|
|
401
|
-
| `place` | 🟡 Text fallback | 🟢 Supported | 🔴 Unavailable
|
|
402
|
-
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable
|
|
403
|
-
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable
|
|
404
|
-
| `button` | 🟡 Text fallback | 🔴 Unavailable | ⚫ Not supported in Notion
|
|
405
|
-
| `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable
|
|
406
|
-
| `last_visited_time` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable
|
|
407
|
-
| `location` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable elsewhere. ⚫ Notion disables filters in My Meetings and Library system
|
|
408
|
-
| `created_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable
|
|
409
|
-
| `last_edited_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable
|
|
410
|
-
| `created_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable
|
|
411
|
-
| `last_edited_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable
|
|
408
|
+
| Property type | Query result | Update row | Filter | Sort |
|
|
409
|
+
| ------------------- | --------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
410
|
+
| `title` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
|
|
411
|
+
| `rich_text` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
|
|
412
|
+
| `number` | 🟢 Number | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
413
|
+
| `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
414
|
+
| `url` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
415
|
+
| `email` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
416
|
+
| `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
417
|
+
| `select` | 🟢 Option name | 🟡 Set value only | 🟢 Supported | 🔴 Unavailable |
|
|
418
|
+
| `multi_select` | 🟢 Array of option names | 🟡 Set values only | 🟢 Supported | 🔴 Unavailable |
|
|
419
|
+
| `status` | 🟢 Option name | 🟡 Set value only | 🟡 Option names or empty checks, without groups | 🔴 Unavailable |
|
|
420
|
+
| `date` | 🟢 `NotionDateValue` | 🟡 Minute precision | 🟡 Fixed start-date comparisons or empty checks, at minute precision | 🟢 Supported |
|
|
421
|
+
| `people` | 🟢 Array of record pointers | 🟢 Supported | 🟢 Supported | 🔴 Unavailable |
|
|
422
|
+
| `files` | 🟡 Text fallback | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
|
|
423
|
+
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
424
|
+
| `relation` | 🟢 Array of record pointers | 🟡 Replaces value. Rejects `has_more: true`. | 🔴 Unavailable | 🔴 Unavailable for standard relations. ⚫ Notion cannot sort XLDB targets. |
|
|
425
|
+
| `place` | 🟡 Text fallback | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
|
|
426
|
+
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
427
|
+
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
|
|
428
|
+
| `button` | 🟡 Text fallback | 🔴 Unavailable | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
|
|
429
|
+
| `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
430
|
+
| `last_visited_time` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
431
|
+
| `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. |
|
|
432
|
+
| `created_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
433
|
+
| `last_edited_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
434
|
+
| `created_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
435
|
+
| `last_edited_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
412
436
|
|
|
413
437
|
### Notes
|
|
414
438
|
|
|
@@ -420,9 +444,10 @@ This table shows property support for custom blocks running in Notion.
|
|
|
420
444
|
`last_edited_time`, `created_by`, and `last_edited_by`. The data source does not need matching
|
|
421
445
|
schema properties. These values are read-only. Timestamps use `NotionDateTime` in UTC. Creator and
|
|
422
446
|
editor values use arrays of record pointers.
|
|
423
|
-
-
|
|
424
|
-
|
|
425
|
-
synthetic
|
|
447
|
+
- Filters and sorts can only reference properties defined in the database schema. For example, to
|
|
448
|
+
sort by creation time, you must first add a **Created time** property to the database and
|
|
449
|
+
reference that property's ID. The synthetic `created_time` field returned with every row is
|
|
450
|
+
read-only metadata and cannot be used when querying.
|
|
426
451
|
- You can sort by up to 10 unique properties.
|
|
427
452
|
- Date-time filter values may include seconds or milliseconds, but the Notion host currently
|
|
428
453
|
evaluates them at minute precision. Date filters do not expose relative dates or end-date
|
|
@@ -516,12 +541,12 @@ See [Pages property support](./pages.md#property-support) for the page-property
|
|
|
516
541
|
(`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
|
|
517
542
|
- `NOTION_BUILTIN_PROPERTY_IDS` — runtime list of the four built-in IDs.
|
|
518
543
|
|
|
519
|
-
###
|
|
544
|
+
### Database schema & pointers
|
|
520
545
|
|
|
521
|
-
- `NotionCollectionSchema` — host-supplied schema for the bound
|
|
546
|
+
- `NotionCollectionSchema` — host-supplied schema for the bound database, including raw property
|
|
522
547
|
schemas.
|
|
523
548
|
- `NotionRecordPointer` — `{ id, table }`. Generic reference to any Notion record (page, block,
|
|
524
|
-
|
|
549
|
+
database row). Exported for convenience; `useDataSource` and the `pages` API don't take one as
|
|
525
550
|
input.
|
|
526
551
|
|
|
527
552
|
### IDs
|
package/docs/errors.md
CHANGED
|
@@ -22,7 +22,9 @@ type CustomBlockErrorInfo<TCode extends string = string> = {
|
|
|
22
22
|
|
|
23
23
|
- `code` is a stable identifier intended for application logic.
|
|
24
24
|
- `message` provides developer-facing details and is not a stable identifier.
|
|
25
|
-
- `isRetryable` indicates whether
|
|
25
|
+
- `isRetryable` indicates whether repeating the operation could succeed without changes to the
|
|
26
|
+
request or its configuration. A `false` value does not prevent recovery after you correct the
|
|
27
|
+
query, schema, or bindings.
|
|
26
28
|
|
|
27
29
|
Each API narrows `code` to its own open string union. The known literals provide autocomplete, but
|
|
28
30
|
newer hosts may send codes that an older SDK does not list.
|
|
@@ -39,6 +41,20 @@ newer hosts may send codes that an older SDK does not list.
|
|
|
39
41
|
- Shared resolution failures: `CustomBlockPropertyErrorCode` / `CustomBlockPropertyErrorInfo` and
|
|
40
42
|
`CustomBlockDataSourceResolutionErrorCode` / `CustomBlockDataSourceResolutionErrorInfo`.
|
|
41
43
|
|
|
44
|
+
## Data source errors
|
|
45
|
+
|
|
46
|
+
- `data_source_schema_unavailable`: The query uses filters or sorts, but the host did not provide
|
|
47
|
+
the database schema. SDK and generic host validation use this code. Queries without filters or
|
|
48
|
+
sorts can continue without a schema.
|
|
49
|
+
- `unmapped_data_source`: The data source has no database binding.
|
|
50
|
+
- `invalid_data_source_query_filter`: The host rejects a filter because its property ID or condition
|
|
51
|
+
does not match the database schema.
|
|
52
|
+
- `invalid_data_source_query_sort`: The host rejects a sort, for example, because its property ID is
|
|
53
|
+
unknown, its property type is unsupported, or the query repeats a sort property.
|
|
54
|
+
|
|
55
|
+
Data source subscriptions repeat the query when the host supplies a changed schema or binding. This
|
|
56
|
+
recovery does not depend on `isRetryable`.
|
|
57
|
+
|
|
42
58
|
## Initialization errors
|
|
43
59
|
|
|
44
60
|
Unlike request helpers, `initCustomBlock` rejects with `CustomBlockInitializationError`. Its `code`
|
package/package.json
CHANGED
|
@@ -60,7 +60,10 @@ import {
|
|
|
60
60
|
NOTION_LIGHT_BACKGROUND_BASE,
|
|
61
61
|
} from "./appearance.js"
|
|
62
62
|
import { resolveDataSourceQuery } from "./dataSources/query.js"
|
|
63
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
getDataSourceReadSchemas,
|
|
65
|
+
resolveDataSources,
|
|
66
|
+
} from "./dataSources/resolve.js"
|
|
64
67
|
import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js"
|
|
65
68
|
import {
|
|
66
69
|
type CustomBlockHostState,
|
|
@@ -73,8 +76,8 @@ import { PendingRequests } from "./pendingRequests.js"
|
|
|
73
76
|
import { globalPrimedResponsesCache } from "./primedResponses.js"
|
|
74
77
|
|
|
75
78
|
/**
|
|
76
|
-
* A single entry in the bridge message log. Kept intentionally plain so the log
|
|
77
|
-
*
|
|
79
|
+
* A single entry in the bridge message log. Kept intentionally plain so the log is copy-pasteable
|
|
80
|
+
* to a local coding agent without needing extra context.
|
|
78
81
|
*/
|
|
79
82
|
export type MessageLogEntry = {
|
|
80
83
|
timestamp: string
|
|
@@ -309,10 +312,9 @@ export class SandboxBridge {
|
|
|
309
312
|
this.sendInitResultError(invalidInitPayloadError(parsed.issues))
|
|
310
313
|
return
|
|
311
314
|
}
|
|
312
|
-
// Loop guard: never NACK a NACK. Excludes both directions —
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
// would otherwise spin a NACK feedback loop.
|
|
315
|
+
// Loop guard: never NACK a NACK. Excludes both directions — `invalidSandboxMessage` is
|
|
316
|
+
// what the host normally sends, but a buggy host that echoes our own
|
|
317
|
+
// `invalidHostMessage` back would otherwise spin a NACK feedback loop.
|
|
316
318
|
if (
|
|
317
319
|
incomingType !== "invalidSandboxMessage" &&
|
|
318
320
|
incomingType !== "invalidHostMessage"
|
|
@@ -327,8 +329,8 @@ export class SandboxBridge {
|
|
|
327
329
|
}
|
|
328
330
|
const message = parsed.output
|
|
329
331
|
|
|
330
|
-
// If the host couldn't parse one of our outbound sandbox-to-host messages, it sends back
|
|
331
|
-
//
|
|
332
|
+
// If the host couldn't parse one of our outbound sandbox-to-host messages, it sends back an
|
|
333
|
+
// `invalidSandboxMessage` NACK with a human-readable `reason`. Log it for developer
|
|
332
334
|
// visibility and stop. We don't retry as the sandbox can't recover from a host-side parse
|
|
333
335
|
// failure on its own.
|
|
334
336
|
if (message.type === "invalidSandboxMessage") {
|
|
@@ -339,8 +341,8 @@ export class SandboxBridge {
|
|
|
339
341
|
return
|
|
340
342
|
}
|
|
341
343
|
|
|
342
|
-
// `init` is the only message valid before initialization. Handle it up
|
|
343
|
-
//
|
|
344
|
+
// `init` is the only message valid before initialization. Handle it up front so every later
|
|
345
|
+
// case can assume `status === "initialized"`.
|
|
344
346
|
if (message.type === "init") {
|
|
345
347
|
if (message.initializationId !== this.initializationId) {
|
|
346
348
|
console.warn(
|
|
@@ -357,8 +359,8 @@ export class SandboxBridge {
|
|
|
357
359
|
return
|
|
358
360
|
}
|
|
359
361
|
|
|
360
|
-
// Alias to keep TS's narrowed `InitializedHostState` across the switch
|
|
361
|
-
//
|
|
362
|
+
// Alias to keep TS's narrowed `InitializedHostState` across the switch below. Reading
|
|
363
|
+
// `this.hostState` repeatedly would re-widen it.
|
|
362
364
|
const hostState = this.hostState
|
|
363
365
|
|
|
364
366
|
if (hostState.status !== "initialized") {
|
|
@@ -595,10 +597,9 @@ export class SandboxBridge {
|
|
|
595
597
|
}
|
|
596
598
|
|
|
597
599
|
/**
|
|
598
|
-
* Apply an `init` payload as if it had arrived from the host. Lets callers
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* of why it's being seeded.
|
|
600
|
+
* Apply an `init` payload as if it had arrived from the host. Lets callers seed the bridge
|
|
601
|
+
* directly (e.g. the React provider's standalone preview fallback) without going through
|
|
602
|
+
* `postMessage`. The bridge stays unaware of why it's being seeded.
|
|
602
603
|
*/
|
|
603
604
|
setMockState(message: InitMessage) {
|
|
604
605
|
this.isMockState = true
|
|
@@ -648,12 +649,12 @@ export class SandboxBridge {
|
|
|
648
649
|
this.isMockState = false
|
|
649
650
|
}
|
|
650
651
|
if (message.status === "error") {
|
|
651
|
-
// The host couldn't construct block location for this block (most commonly the parent
|
|
652
|
-
// failed to resolve). Surface the failure through the `awaitInit` promise so
|
|
653
|
-
// it through `useCustomBlockInit().error` instead of timing out. We also
|
|
654
|
-
// because not every consumer renders the error UI, and we want the failure
|
|
655
|
-
// the browser console either way. We deliberately don't NACK the host or
|
|
656
|
-
// back over the bridge since the host has already given up.
|
|
652
|
+
// The host couldn't construct block location for this block (most commonly the parent
|
|
653
|
+
// record failed to resolve). Surface the failure through the `awaitInit` promise so
|
|
654
|
+
// callers see it through `useCustomBlockInit().error` instead of timing out. We also
|
|
655
|
+
// log here because not every consumer renders the error UI, and we want the failure
|
|
656
|
+
// visible in the browser console either way. We deliberately don't NACK the host or
|
|
657
|
+
// post anything back over the bridge since the host has already given up.
|
|
657
658
|
console.error(
|
|
658
659
|
`[custom-blocks-sdk] host reported init error (${message.error.code}): ${message.error.message}`,
|
|
659
660
|
)
|
|
@@ -696,9 +697,8 @@ export class SandboxBridge {
|
|
|
696
697
|
contrastMode: message.contrastMode,
|
|
697
698
|
})
|
|
698
699
|
this.notify()
|
|
699
|
-
// Resolve the awaitInit promise once. Subsequent `init` messages
|
|
700
|
-
//
|
|
701
|
-
// don't re-resolve.
|
|
700
|
+
// Resolve the awaitInit promise once. Subsequent `init` messages (the host shouldn't send
|
|
701
|
+
// these, but be tolerant) update state but don't re-resolve.
|
|
702
702
|
if (this.resolveInit) {
|
|
703
703
|
this.resolveInit()
|
|
704
704
|
this.resolveInit = undefined
|
|
@@ -761,18 +761,26 @@ export class SandboxBridge {
|
|
|
761
761
|
? subscriptionState
|
|
762
762
|
: createEmptyDataSourceQueryState(key)
|
|
763
763
|
if (dataSource === undefined) {
|
|
764
|
-
this.setDataSourceQueryError(
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
764
|
+
this.setDataSourceQueryError({
|
|
765
|
+
subscriptionId,
|
|
766
|
+
currentState,
|
|
767
|
+
error: {
|
|
768
|
+
code: "unknown_data_source_key",
|
|
769
|
+
message: `Unknown data source key "${key}". Known keys: [${this.hostState.dataSources.map(entry => entry.key).join(", ")}].`,
|
|
770
|
+
isRetryable: false,
|
|
771
|
+
},
|
|
768
772
|
})
|
|
769
773
|
return
|
|
770
774
|
}
|
|
771
775
|
if (dataSource.collectionPointer === undefined) {
|
|
772
|
-
this.setDataSourceQueryError(
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
+
this.setDataSourceQueryError({
|
|
777
|
+
subscriptionId,
|
|
778
|
+
currentState,
|
|
779
|
+
error: {
|
|
780
|
+
code: "unmapped_data_source",
|
|
781
|
+
message: `Data source "${key}" has not been mapped to a database yet.`,
|
|
782
|
+
isRetryable: false,
|
|
783
|
+
},
|
|
776
784
|
})
|
|
777
785
|
return
|
|
778
786
|
}
|
|
@@ -783,10 +791,10 @@ export class SandboxBridge {
|
|
|
783
791
|
options,
|
|
784
792
|
})
|
|
785
793
|
if (resolvedQuery.status === "error") {
|
|
786
|
-
this.setDataSourceQueryError(
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
794
|
+
this.setDataSourceQueryError({
|
|
795
|
+
subscriptionId,
|
|
796
|
+
currentState,
|
|
797
|
+
error: resolvedQuery.error,
|
|
790
798
|
})
|
|
791
799
|
return
|
|
792
800
|
}
|
|
@@ -826,11 +834,15 @@ export class SandboxBridge {
|
|
|
826
834
|
this.notify()
|
|
827
835
|
}
|
|
828
836
|
|
|
829
|
-
private setDataSourceQueryError(
|
|
830
|
-
subscriptionId
|
|
831
|
-
currentState
|
|
832
|
-
error
|
|
833
|
-
|
|
837
|
+
private setDataSourceQueryError({
|
|
838
|
+
subscriptionId,
|
|
839
|
+
currentState,
|
|
840
|
+
error,
|
|
841
|
+
}: {
|
|
842
|
+
subscriptionId: string
|
|
843
|
+
currentState: DataSourceQueryState
|
|
844
|
+
error: CustomBlockQueryDataSourceErrorInfo
|
|
845
|
+
}) {
|
|
834
846
|
if (this.hostState.status !== "initialized") {
|
|
835
847
|
return
|
|
836
848
|
}
|
|
@@ -1043,8 +1055,8 @@ export class SandboxBridge {
|
|
|
1043
1055
|
|
|
1044
1056
|
/**
|
|
1045
1057
|
* Translates the public `CreatePageArgs["parent"]` into the bridge-native
|
|
1046
|
-
* `CreatePageMessageParent`. The `data_source_key` variant is resolved sandbox-side against
|
|
1047
|
-
*
|
|
1058
|
+
* `CreatePageMessageParent`. The `data_source_key` variant is resolved sandbox-side against the
|
|
1059
|
+
* data source mapping the host delivered in `init` / `dataSourcesChanged`.
|
|
1048
1060
|
*/
|
|
1049
1061
|
private resolveCreatePageParent(parent: CreatePageArgs["parent"]):
|
|
1050
1062
|
| {
|
|
@@ -1151,11 +1163,11 @@ function syncDocumentAppearance(args: {
|
|
|
1151
1163
|
}
|
|
1152
1164
|
|
|
1153
1165
|
/**
|
|
1154
|
-
* `postMessage` cloning creates new objects even for bindings that did not change.
|
|
1155
|
-
*
|
|
1166
|
+
* `postMessage` cloning creates new objects even for bindings that did not change. Preserve their
|
|
1167
|
+
* resolved object identity so React effects only run for changed bindings.
|
|
1156
1168
|
*
|
|
1157
|
-
* This comparison runs when the host sends an update instead of on every component render.
|
|
1158
|
-
*
|
|
1169
|
+
* This comparison runs when the host sends an update instead of on every component render. Bindings
|
|
1170
|
+
* are validated JSON-like bridge payloads, so serialization is sufficient here.
|
|
1159
1171
|
*/
|
|
1160
1172
|
function reuseDataSourcesForUnchangedBindings(args: {
|
|
1161
1173
|
previousDataSources: NotionDataSource[]
|
|
@@ -1243,7 +1255,7 @@ function resolveMockDataSources(
|
|
|
1243
1255
|
collectionPointer: binding.collectionPointer,
|
|
1244
1256
|
collectionSchema: binding.collectionSchema,
|
|
1245
1257
|
propertyIdsByKey: { ...(binding.propertyIdsByKey ?? {}) },
|
|
1246
|
-
propertySchemasById: binding.collectionSchema
|
|
1258
|
+
propertySchemasById: getDataSourceReadSchemas(binding.collectionSchema),
|
|
1247
1259
|
}))
|
|
1248
1260
|
}
|
|
1249
1261
|
|