@notionhq/custom-blocks 0.3.5 → 0.5.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 +2 -2
- package/dist/bridge/SandboxBridge.d.ts +4 -39
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +36 -142
- package/dist/bridge/requests.d.ts +35 -0
- package/dist/bridge/requests.d.ts.map +1 -0
- package/dist/bridge/requests.js +97 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
- package/dist/dataSources/bridge/resolveDataSourceQuery.js +18 -4
- package/dist/dataSources/bridge/resolveDataSources.js +4 -4
- package/dist/dataSources/createDataSourcePage.d.ts.map +1 -1
- package/dist/dataSources/createDataSourcePage.js +5 -1
- package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -1
- package/dist/dataSources/filters/resolveFilter.js +13 -3
- package/dist/dataSources/filters/types.d.ts +9 -3
- package/dist/dataSources/filters/types.d.ts.map +1 -1
- package/dist/dataSources/properties/resolvePropertyAddress.js +1 -1
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.js +1 -1
- package/dist/dataSources/resolvePageDataSource.js +2 -2
- package/dist/dataSources/subscribeToDataSource.d.ts +1 -4
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
- package/dist/dataSources/subscribeToDataSource.js +2 -3
- package/dist/dataSources/types.d.ts +2 -0
- package/dist/dataSources/types.d.ts.map +1 -1
- package/dist/files/files.d.ts +2 -0
- package/dist/files/files.d.ts.map +1 -0
- package/dist/files/files.js +1 -0
- package/dist/files/icons.d.ts +2 -0
- package/dist/files/icons.d.ts.map +1 -0
- package/dist/files/icons.js +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/initialization/getInitBindingError.js +2 -2
- package/dist/manifest/types.d.ts +5 -4
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.d.ts.map +1 -1
- package/dist/navigation/openExternalUrl.js +2 -1
- package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
- package/dist/pages/bridge/getPageForDataSource.js +3 -2
- package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
- package/dist/pages/bridge/sendCreatePageRequest.js +2 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +14 -2
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +0 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -8
- package/dist/pages/bridge/updatePage.d.ts.map +1 -1
- package/dist/pages/bridge/updatePage.js +20 -5
- package/dist/pages/createPage.d.ts.map +1 -1
- package/dist/pages/createPage.js +5 -1
- package/dist/pages/openPage.d.ts.map +1 -1
- package/dist/pages/openPage.js +2 -1
- package/dist/pages/properties/getPropertyByKey.js +2 -2
- package/dist/pages/types.d.ts +10 -14
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.d.ts +530 -0
- package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.js +25 -0
- package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +12 -11
- package/dist/protocol/compatibility/protocol3To5/bridgePage.js +3 -3
- package/dist/protocol/context/containingPage.d.ts +3 -0
- package/dist/protocol/context/messages/pageChanged.d.ts +3 -0
- package/dist/protocol/context/messages/parentChanged.d.ts +3 -0
- package/dist/protocol/context/parent.d.ts +5 -0
- package/dist/protocol/context/parent.js +6 -1
- package/dist/protocol/dataSources/bridgeArchiveStatus.d.ts +3 -0
- package/dist/protocol/dataSources/bridgeArchiveStatus.js +6 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +3 -11
- package/dist/protocol/dataSources/bridgeDataSourceBinding.js +5 -5
- package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +2 -10
- package/dist/protocol/dataSources/{collectionPointer.d.ts → dataSourcePointer.d.ts} +2 -2
- package/dist/protocol/dataSources/{collectionPointer.js → dataSourcePointer.js} +1 -1
- package/dist/protocol/dataSources/{collectionSchema.d.ts → dataSourceSchema.d.ts} +2 -10
- package/dist/protocol/dataSources/{collectionSchema.js → dataSourceSchema.js} +1 -1
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.d.ts +1458 -12
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.d.ts +729 -6
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.js +14 -2
- package/dist/protocol/dataSources/filters/peopleFilterOperator.d.ts +3 -3
- package/dist/protocol/dataSources/filters/peopleFilterOperator.js +1 -1
- package/dist/protocol/dataSources/filters/timestampFilterOperator.d.ts +354 -0
- package/dist/protocol/dataSources/filters/timestampFilterOperator.js +4 -0
- package/dist/protocol/dataSources/messages/dataSourcesChanged.d.ts +2 -10
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +1485 -38
- package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
- package/dist/protocol/dataSources/notionDataSource.d.ts +3 -19
- package/dist/protocol/dataSources/notionDataSource.js +5 -5
- package/dist/protocol/dataSources/properties/propertySchema.d.ts +4 -13
- package/dist/protocol/dataSources/properties/propertySchema.js +2 -6
- package/dist/protocol/dataSources/resolveDataSourceBinding.d.ts +4 -4
- package/dist/protocol/dataSources/resolveDataSourceBinding.js +2 -2
- package/dist/protocol/files.d.ts +32 -0
- package/dist/protocol/files.js +17 -0
- package/dist/protocol/handshake/connect.d.ts +15 -4
- package/dist/protocol/handshake/init.d.ts +23 -14
- package/dist/protocol/icons.d.ts +32 -0
- package/dist/protocol/icons.js +39 -0
- package/dist/protocol/index.d.ts +25 -19
- package/dist/protocol/index.js +15 -9
- package/dist/protocol/manifest/grants.d.ts +48 -0
- package/dist/protocol/manifest/grants.js +19 -0
- package/dist/protocol/manifest/manifest.d.ts +39 -16
- package/dist/protocol/manifest/manifest.js +17 -11
- package/dist/protocol/messages/hostToSandbox.d.ts +196 -177
- package/dist/protocol/messages/invalidHostMessage.d.ts +2 -0
- package/dist/protocol/messages/invalidHostMessage.js +2 -0
- package/dist/protocol/messages/invalidSandboxMessage.d.ts +2 -0
- package/dist/protocol/messages/invalidSandboxMessage.js +2 -0
- package/dist/protocol/messages/sandboxToHost.d.ts +1571 -50
- package/dist/protocol/navigation/openExternalUrl.d.ts +2 -2
- package/dist/protocol/pages/bridgePage.d.ts +12 -12
- package/dist/protocol/pages/bridgePage.js +3 -4
- package/dist/protocol/pages/makeBridgePage.d.ts +3 -1
- package/dist/protocol/pages/messages/createPage.d.ts +645 -62
- package/dist/protocol/pages/messages/createPage.js +27 -13
- package/dist/protocol/pages/messages/getPage.d.ts +38 -37
- package/dist/protocol/pages/messages/openPage.d.ts +2 -2
- package/dist/protocol/pages/messages/updatePage.d.ts +47 -48
- package/dist/protocol/pages/messages/updatePage.js +3 -3
- package/dist/protocol/pages/pageAppearance.d.ts +9 -28
- package/dist/protocol/pages/pageAppearance.js +11 -31
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +4 -20
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +2 -10
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +2 -12
- package/dist/protocol/users/makeBridgeUser.d.ts +3 -1
- package/dist/protocol/users/messages/getUser.d.ts +2 -2
- package/dist/protocol/users/messages/listUsers.d.ts +2 -2
- package/dist/protocol/utils/errors.d.ts +6 -4
- package/dist/protocol/utils/errors.js +3 -3
- package/dist/protocol/utils/ids.d.ts +2 -0
- package/dist/protocol/utils/ids.js +1 -0
- package/dist/protocol/utils/protocolVersion.d.ts +3 -1
- package/dist/protocol/utils/protocolVersion.js +5 -1
- package/dist/protocol/utils/readRequestId.d.ts +2 -0
- package/dist/protocol/utils/readRequestId.js +7 -0
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +1 -15
- package/dist/users/getUser.d.ts.map +1 -1
- package/dist/users/getUser.js +2 -1
- package/dist/users/listUsers.d.ts.map +1 -1
- package/dist/users/listUsers.js +4 -2
- package/dist/utils/version.js +1 -1
- package/docs/data-sources.md +85 -83
- package/docs/deployment.md +4 -5
- package/docs/errors.md +47 -5
- package/docs/grants.md +127 -0
- package/docs/pages.md +105 -56
- package/docs/users.md +2 -2
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +44 -243
- package/src/bridge/requests.ts +138 -0
- package/src/dataSources/bridge/resolveDataSourceQuery.ts +24 -4
- package/src/dataSources/bridge/resolveDataSources.ts +4 -4
- package/src/dataSources/createDataSourcePage.ts +5 -1
- package/src/dataSources/filters/resolveFilter.ts +12 -3
- package/src/dataSources/filters/types.ts +7 -4
- package/src/dataSources/properties/resolvePropertyAddress.ts +1 -1
- package/src/dataSources/properties/resolvePropertyWriteMapForDataSource.ts +1 -1
- package/src/dataSources/resolvePageDataSource.ts +2 -2
- package/src/dataSources/subscribeToDataSource.ts +7 -19
- package/src/dataSources/types.ts +3 -0
- package/src/files/files.ts +5 -0
- package/src/files/icons.ts +9 -0
- package/src/index.ts +10 -11
- package/src/initialization/getInitBindingError.ts +2 -2
- package/src/manifest/types.ts +10 -4
- package/src/navigation/openExternalUrl.ts +5 -1
- package/src/pages/bridge/getPageForDataSource.ts +6 -2
- package/src/pages/bridge/sendCreatePageRequest.ts +5 -1
- package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +0 -1
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -8
- package/src/pages/bridge/updatePage.ts +29 -9
- package/src/pages/createPage.ts +5 -1
- package/src/pages/openPage.ts +5 -1
- package/src/pages/properties/getPropertyByKey.ts +2 -2
- package/src/pages/types.ts +14 -16
- package/src/react/NotionCustomBlock.tsx +1 -16
- package/src/users/getUser.ts +5 -1
- package/src/users/listUsers.ts +9 -4
- package/dist/bridge/pendingRequests.d.ts +0 -14
- package/dist/bridge/pendingRequests.d.ts.map +0 -1
- package/dist/bridge/pendingRequests.js +0 -28
- package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +0 -17
- package/dist/protocol/dataSources/filters/createdByFilterOperator.js +0 -11
- package/dist/protocol/manifest/capabilities.d.ts +0 -37
- package/dist/protocol/manifest/capabilities.js +0 -13
- package/dist/protocol/pages/properties/fileInput.d.ts +0 -16
- package/dist/protocol/pages/properties/fileInput.js +0 -16
- package/dist/react/DebugMessageLog.d.ts +0 -2
- package/dist/react/DebugMessageLog.d.ts.map +0 -1
- package/dist/react/DebugMessageLog.js +0 -23
- package/docs/capabilities.md +0 -111
- package/src/bridge/pendingRequests.ts +0 -28
- package/src/react/DebugMessageLog.tsx +0 -34
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
UpdatePageMessage,
|
|
5
5
|
UpdatePageResultMessage,
|
|
6
6
|
} from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
7
|
+
import { updatePageResultMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
7
8
|
import type { NotionPageId } from "@notionhq/custom-blocks-protocol/utils/ids.js"
|
|
8
9
|
|
|
9
10
|
import type { SandboxBridge } from "../../bridge/SandboxBridge.js"
|
|
@@ -17,7 +18,7 @@ export type UpdatePageArgs = PageUpdatePayload & {
|
|
|
17
18
|
|
|
18
19
|
const pendingPageUpdatesByBridge = new WeakMap<
|
|
19
20
|
SandboxBridge,
|
|
20
|
-
Map<NotionPageId, Promise<
|
|
21
|
+
Map<NotionPageId, Promise<boolean>>
|
|
21
22
|
>()
|
|
22
23
|
|
|
23
24
|
export function updatePage(
|
|
@@ -29,11 +30,22 @@ export function updatePage(
|
|
|
29
30
|
pendingPageUpdates = new Map()
|
|
30
31
|
pendingPageUpdatesByBridge.set(bridge, pendingPageUpdates)
|
|
31
32
|
}
|
|
32
|
-
const operation = async (
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const operation = async (
|
|
34
|
+
previousWriteIncomplete: boolean,
|
|
35
|
+
): Promise<BridgeMessagePayload<UpdatePageResultMessage>> => {
|
|
36
|
+
if (previousWriteIncomplete) {
|
|
37
|
+
return {
|
|
38
|
+
status: "error",
|
|
39
|
+
error: {
|
|
40
|
+
code: "previous_write_incomplete",
|
|
41
|
+
message:
|
|
42
|
+
"This queued update was not sent because a previous write timed out and may still complete.",
|
|
43
|
+
isRetryable: false,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
35
47
|
const { dataSource } = args
|
|
36
|
-
const dataSourceId = dataSource?.
|
|
48
|
+
const dataSourceId = dataSource?.dataSourcePointer?.id
|
|
37
49
|
const resolved = resolvePropertyWriteMapForDataSource({
|
|
38
50
|
dataSource,
|
|
39
51
|
properties: args.properties === undefined ? {} : args.properties,
|
|
@@ -72,13 +84,21 @@ export function updatePage(
|
|
|
72
84
|
if (args.is_archived !== undefined) {
|
|
73
85
|
outbound.archived = args.is_archived
|
|
74
86
|
}
|
|
75
|
-
return bridge.
|
|
87
|
+
return bridge.request(
|
|
88
|
+
{ type: "updatePage", ...outbound },
|
|
89
|
+
updatePageResultMessageSchema,
|
|
90
|
+
)
|
|
76
91
|
}
|
|
77
92
|
const pending = pendingPageUpdates.get(args.pageId)
|
|
78
|
-
const result = pending ? pending.then(operation) : operation()
|
|
93
|
+
const result = pending ? pending.then(operation) : operation(false)
|
|
94
|
+
// A timeout does not cancel host work. Skip the rest of this queue to avoid
|
|
95
|
+
// sending writes that could be applied before the timed-out write.
|
|
79
96
|
const finished = result.then(
|
|
80
|
-
|
|
81
|
-
|
|
97
|
+
result =>
|
|
98
|
+
result.status === "error" &&
|
|
99
|
+
(result.error.code === "request_timeout" ||
|
|
100
|
+
result.error.code === "previous_write_incomplete"),
|
|
101
|
+
() => false,
|
|
82
102
|
)
|
|
83
103
|
pendingPageUpdates.set(args.pageId, finished)
|
|
84
104
|
void finished.then(() => {
|
package/src/pages/createPage.ts
CHANGED
|
@@ -25,7 +25,11 @@ export async function createPage(
|
|
|
25
25
|
}
|
|
26
26
|
return sendCreatePageRequest({
|
|
27
27
|
bridge,
|
|
28
|
-
request:
|
|
28
|
+
request: {
|
|
29
|
+
...prepared.request,
|
|
30
|
+
...(input.icon === undefined ? {} : { icon: input.icon }),
|
|
31
|
+
...(input.cover === undefined ? {} : { cover: input.cover }),
|
|
32
|
+
},
|
|
29
33
|
dataSource: undefined,
|
|
30
34
|
})
|
|
31
35
|
}
|
package/src/pages/openPage.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { openPageResultMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/openPage.js"
|
|
1
2
|
import type { NotionPageId } from "@notionhq/custom-blocks-protocol/utils/ids.js"
|
|
2
3
|
import { getBridge } from "../bridge/getBridge.js"
|
|
3
4
|
import type { OpenPageOptions, OpenPageResult } from "./types.js"
|
|
@@ -9,5 +10,8 @@ export const openPage = (
|
|
|
9
10
|
pageId: NotionPageId,
|
|
10
11
|
options: OpenPageOptions,
|
|
11
12
|
): Promise<OpenPageResult> => {
|
|
12
|
-
return getBridge().
|
|
13
|
+
return getBridge().request(
|
|
14
|
+
{ type: "openPage", pageId, mode: options.mode },
|
|
15
|
+
openPageResultMessageSchema,
|
|
16
|
+
)
|
|
13
17
|
}
|
|
@@ -18,8 +18,8 @@ export function getPropertyByKey(
|
|
|
18
18
|
: undefined
|
|
19
19
|
// Keep the captured mapping valid only while its key remains bound to the original database.
|
|
20
20
|
if (
|
|
21
|
-
!dataSource?.
|
|
22
|
-
currentDataSource?.
|
|
21
|
+
!dataSource?.dataSourcePointer ||
|
|
22
|
+
currentDataSource?.dataSourcePointer?.id !== dataSource.dataSourcePointer.id
|
|
23
23
|
) {
|
|
24
24
|
return null
|
|
25
25
|
}
|
package/src/pages/types.ts
CHANGED
|
@@ -14,26 +14,25 @@ import type {
|
|
|
14
14
|
} from "@notionhq/custom-blocks-protocol/pages/messages/openPage.js"
|
|
15
15
|
import type { CustomBlockUpdatePageErrorInfo } from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
16
16
|
import type {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
BridgePageCover,
|
|
18
|
+
BridgePageIcon,
|
|
19
19
|
} from "@notionhq/custom-blocks-protocol/pages/pageAppearance.js"
|
|
20
20
|
import type { NotionDateInput } from "@notionhq/custom-blocks-protocol/pages/properties/dateInput.js"
|
|
21
|
-
import type { NotionFileInput } from "@notionhq/custom-blocks-protocol/pages/properties/fileInput.js"
|
|
22
21
|
import type { NotionPlaceInput } from "@notionhq/custom-blocks-protocol/pages/properties/placeInput.js"
|
|
23
22
|
import type { NotionRelationInput } from "@notionhq/custom-blocks-protocol/pages/properties/relationInput.js"
|
|
24
23
|
import type { NotionRichTextItem } from "@notionhq/custom-blocks-protocol/pages/properties/richText.js"
|
|
25
24
|
import type { NotionSelectOptionInput } from "@notionhq/custom-blocks-protocol/pages/properties/selectOption.js"
|
|
26
25
|
import type { NotionUserInput } from "@notionhq/custom-blocks-protocol/pages/properties/userInput.js"
|
|
27
26
|
import type { NotionPageId } from "@notionhq/custom-blocks-protocol/utils/ids.js"
|
|
27
|
+
import type { NotionFilePropertyItem } from "../files/files.js"
|
|
28
28
|
import type { KeyedDataSourceParent } from "./parent.js"
|
|
29
29
|
|
|
30
|
-
export type {
|
|
31
|
-
NotionPageCover,
|
|
32
|
-
NotionPageIcon,
|
|
33
|
-
} from "@notionhq/custom-blocks-protocol/pages/pageAppearance.js"
|
|
34
30
|
// These leaf values intentionally share their SDK and protocol representation.
|
|
35
31
|
export type { NotionDateInput } from "@notionhq/custom-blocks-protocol/pages/properties/dateInput.js"
|
|
36
32
|
|
|
33
|
+
export type NotionPageIcon = BridgePageIcon
|
|
34
|
+
export type NotionPageCover = BridgePageCover
|
|
35
|
+
|
|
37
36
|
export type NotionPagePropertyValue = { id: string } & (
|
|
38
37
|
| { type: "title"; title: NotionRichTextItem[] }
|
|
39
38
|
| { type: "rich_text"; rich_text: NotionRichTextItem[] }
|
|
@@ -48,17 +47,15 @@ export type NotionPagePropertyValue = { id: string } & (
|
|
|
48
47
|
| { type: "date"; date: NotionDateInput | null }
|
|
49
48
|
| { type: "people"; people: NotionUserInput[] }
|
|
50
49
|
| { type: "relation"; relation: NotionRelationInput[]; has_more?: boolean }
|
|
51
|
-
| { type: "files"; files:
|
|
50
|
+
| { type: "files"; files: NotionFilePropertyItem[] }
|
|
52
51
|
| { type: "place"; place: NotionPlaceInput | null }
|
|
53
52
|
| { type: "created_time"; created_time: string | null }
|
|
54
53
|
| { type: "last_edited_time"; last_edited_time: string | null }
|
|
55
54
|
| { type: "created_by"; created_by: PageMetadataActor | null }
|
|
56
55
|
| { type: "last_edited_by"; last_edited_by: PageMetadataActor | null }
|
|
57
|
-
| { type: "last_visited_time"; last_visited_time: string | null }
|
|
58
56
|
| { type: "unique_id"; unique_id: string }
|
|
59
57
|
| { type: "button"; button: string }
|
|
60
58
|
| { type: "formula"; formula: string }
|
|
61
|
-
| { type: "location"; location: string }
|
|
62
59
|
| { type: "rollup"; rollup: string }
|
|
63
60
|
| { type: "verification"; verification: string }
|
|
64
61
|
)
|
|
@@ -83,11 +80,9 @@ export type NotionPagePropertyInputValue =
|
|
|
83
80
|
| "last_edited_time"
|
|
84
81
|
| "created_by"
|
|
85
82
|
| "last_edited_by"
|
|
86
|
-
| "last_visited_time"
|
|
87
83
|
| "unique_id"
|
|
88
84
|
| "button"
|
|
89
85
|
| "formula"
|
|
90
|
-
| "location"
|
|
91
86
|
| "rollup"
|
|
92
87
|
| "verification"
|
|
93
88
|
}
|
|
@@ -108,7 +103,6 @@ export type NotionPage = {
|
|
|
108
103
|
properties: NotionPagePropertyReadMap
|
|
109
104
|
created_by: PageMetadataActor | null
|
|
110
105
|
last_edited_by: PageMetadataActor | null
|
|
111
|
-
last_visited_time: string | null
|
|
112
106
|
created_time: string | null
|
|
113
107
|
last_edited_time: string | null
|
|
114
108
|
icon: NotionPageIcon | null
|
|
@@ -147,7 +141,7 @@ export type CreatePageResult =
|
|
|
147
141
|
*
|
|
148
142
|
* - `page_id`: Create a child page under the given Notion page.
|
|
149
143
|
* - `data_source_id`: Create a row inside the given Notion data source. The public API's
|
|
150
|
-
* `data_source_id` is the same UUID as the `
|
|
144
|
+
* `data_source_id` is the same UUID as the `dataSourcePointer.id` exposed in `dataSources`,
|
|
151
145
|
* so either value works here.
|
|
152
146
|
* - `data_source_key`: Create a row inside the data source that the custom block was configured with
|
|
153
147
|
* under this semantic key. The SDK resolves the key to a `data_source_id` locally before
|
|
@@ -156,9 +150,13 @@ export type CreatePageResult =
|
|
|
156
150
|
export type { CreatePageParent } from "./parent.js"
|
|
157
151
|
|
|
158
152
|
/**
|
|
159
|
-
* Arguments accepted by `sdk.pages.create`.
|
|
153
|
+
* Arguments accepted by `sdk.pages.create`.
|
|
160
154
|
*/
|
|
161
|
-
export type CreatePageArgs = {
|
|
155
|
+
export type CreatePageArgs = {
|
|
156
|
+
properties: NotionPagePropertyInputMap
|
|
157
|
+
icon?: NotionPageIcon
|
|
158
|
+
cover?: NotionPageCover
|
|
159
|
+
} & (
|
|
162
160
|
| {
|
|
163
161
|
parent: PageParent
|
|
164
162
|
position?: NotionCreatePagePosition
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { CustomBlockInitializationError } from "@notionhq/custom-blocks-protocol/handshake/init.js"
|
|
2
2
|
import type { ReactNode } from "react"
|
|
3
|
-
import { useEffect, useLayoutEffect
|
|
3
|
+
import { useEffect, useLayoutEffect } from "react"
|
|
4
4
|
import { getBridge } from "../bridge/getBridge.js"
|
|
5
5
|
import { useCustomBlockInit } from "../initialization/react/useCustomBlockInit.js"
|
|
6
6
|
import { autoResize } from "../layout/autoResize.js"
|
|
7
|
-
import { DebugMessageLog } from "./DebugMessageLog.js"
|
|
8
7
|
import { InitializationErrorDetails } from "./InitializationErrorDetails.js"
|
|
9
8
|
import { MissingHostScreen } from "./MissingHostScreen.js"
|
|
10
9
|
import "./InitializationErrorScreen.css"
|
|
@@ -51,7 +50,6 @@ export function NotionCustomBlock({
|
|
|
51
50
|
errorFallback,
|
|
52
51
|
}: NotionCustomBlockProps) {
|
|
53
52
|
const init = useCustomBlockInit()
|
|
54
|
-
const [debugOpen, setDebugOpen] = useState(false)
|
|
55
53
|
|
|
56
54
|
// Keep the host iframe height in sync with the block's content after initialization.
|
|
57
55
|
useEffect(() => {
|
|
@@ -61,16 +59,6 @@ export function NotionCustomBlock({
|
|
|
61
59
|
return autoResize({ target: document.getElementById("root") })
|
|
62
60
|
}, [init.isLoaded])
|
|
63
61
|
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
const onKeyDown = (e: KeyboardEvent) => {
|
|
66
|
-
if (e.key === "\\") {
|
|
67
|
-
setDebugOpen(prev => !prev)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
window.addEventListener("keydown", onKeyDown)
|
|
71
|
-
return () => window.removeEventListener("keydown", onKeyDown)
|
|
72
|
-
}, [])
|
|
73
|
-
|
|
74
62
|
useLayoutEffect(() => {
|
|
75
63
|
if (!init.isLoaded) {
|
|
76
64
|
return
|
|
@@ -80,9 +68,6 @@ export function NotionCustomBlock({
|
|
|
80
68
|
getBridge().completeInitialization()
|
|
81
69
|
}, [init.isLoaded])
|
|
82
70
|
|
|
83
|
-
if (debugOpen) {
|
|
84
|
-
return <DebugMessageLog />
|
|
85
|
-
}
|
|
86
71
|
if (init.error) {
|
|
87
72
|
if (errorFallback === undefined) {
|
|
88
73
|
return <DefaultInitErrorFallback error={init.error} />
|
package/src/users/getUser.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getUserResultMessageSchema } from "@notionhq/custom-blocks-protocol/users/messages/getUser.js"
|
|
1
2
|
import type { NotionUserId } from "@notionhq/custom-blocks-protocol/users/userId.js"
|
|
2
3
|
import { getBridge } from "../bridge/getBridge.js"
|
|
3
4
|
import { toNotionUserFromBridgeUser } from "./bridge/toNotionUserFromBridgeUser.js"
|
|
@@ -7,7 +8,10 @@ import type { GetUserResult } from "./types.js"
|
|
|
7
8
|
* Fetches a user by id.
|
|
8
9
|
*/
|
|
9
10
|
export async function getUser(userId: NotionUserId): Promise<GetUserResult> {
|
|
10
|
-
const result = await getBridge().
|
|
11
|
+
const result = await getBridge().request(
|
|
12
|
+
{ type: "getUser", userId },
|
|
13
|
+
getUserResultMessageSchema,
|
|
14
|
+
)
|
|
11
15
|
return result.status === "error"
|
|
12
16
|
? result
|
|
13
17
|
: { status: "success", user: toNotionUserFromBridgeUser(result.user) }
|
package/src/users/listUsers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { listUsersResultMessageSchema } from "@notionhq/custom-blocks-protocol/users/messages/listUsers.js"
|
|
1
2
|
import { getBridge } from "../bridge/getBridge.js"
|
|
2
3
|
import { toNotionUserFromBridgeUser } from "./bridge/toNotionUserFromBridgeUser.js"
|
|
3
4
|
import type { ListUsersArgs, ListUsersResult } from "./types.js"
|
|
@@ -8,10 +9,14 @@ import type { ListUsersArgs, ListUsersResult } from "./types.js"
|
|
|
8
9
|
export async function listUsers(
|
|
9
10
|
input: ListUsersArgs = {},
|
|
10
11
|
): Promise<ListUsersResult> {
|
|
11
|
-
const result = await getBridge().
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const result = await getBridge().request(
|
|
13
|
+
{
|
|
14
|
+
type: "listUsers",
|
|
15
|
+
startCursor: input.startCursor,
|
|
16
|
+
pageSize: input.pageSize,
|
|
17
|
+
},
|
|
18
|
+
listUsersResultMessageSchema,
|
|
19
|
+
)
|
|
15
20
|
return result.status === "error"
|
|
16
21
|
? result
|
|
17
22
|
: {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tracks one-shot request/response pairs over the `postMessage` bridge. Each `allocate` reserves a
|
|
3
|
-
* unique `requestId` and stores its resolver. `resolve` finds the pending resolver by `requestId`
|
|
4
|
-
* and calls it, then removes the entry so the same `requestId` cannot be resolved twice.
|
|
5
|
-
*/
|
|
6
|
-
export declare class PendingRequests<T> {
|
|
7
|
-
private readonly prefix;
|
|
8
|
-
private nextId;
|
|
9
|
-
private readonly entries;
|
|
10
|
-
constructor(prefix: string);
|
|
11
|
-
allocate(resolver: (value: T) => void): string;
|
|
12
|
-
resolve(requestId: string, value: T): boolean;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=pendingRequests.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pendingRequests.d.ts","sourceRoot":"","sources":["../../src/bridge/pendingRequests.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,eAAe,CAAC,CAAC;IAIjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAEhE,YAA6B,MAAM,EAAE,MAAM,EAAI;IAE/C,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,CAK7C;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAQ5C;CACD"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tracks one-shot request/response pairs over the `postMessage` bridge. Each `allocate` reserves a
|
|
3
|
-
* unique `requestId` and stores its resolver. `resolve` finds the pending resolver by `requestId`
|
|
4
|
-
* and calls it, then removes the entry so the same `requestId` cannot be resolved twice.
|
|
5
|
-
*/
|
|
6
|
-
export class PendingRequests {
|
|
7
|
-
prefix;
|
|
8
|
-
nextId = 1;
|
|
9
|
-
entries = new Map();
|
|
10
|
-
constructor(prefix) {
|
|
11
|
-
this.prefix = prefix;
|
|
12
|
-
}
|
|
13
|
-
allocate(resolver) {
|
|
14
|
-
const requestId = `${this.prefix}-${this.nextId}`;
|
|
15
|
-
this.nextId += 1;
|
|
16
|
-
this.entries.set(requestId, resolver);
|
|
17
|
-
return requestId;
|
|
18
|
-
}
|
|
19
|
-
resolve(requestId, value) {
|
|
20
|
-
const resolver = this.entries.get(requestId);
|
|
21
|
-
if (resolver === undefined) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
this.entries.delete(requestId);
|
|
25
|
-
resolver(value);
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
export declare const customBlockCreatedByFilterOperatorSchema: v.UnionSchema<[v.StrictObjectSchema<{
|
|
3
|
-
readonly contains: v.StrictObjectSchema<{
|
|
4
|
-
readonly object: v.LiteralSchema<"user", undefined>;
|
|
5
|
-
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
|
|
6
|
-
}, undefined>;
|
|
7
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
8
|
-
readonly does_not_contain: v.StrictObjectSchema<{
|
|
9
|
-
readonly object: v.LiteralSchema<"user", undefined>;
|
|
10
|
-
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
|
|
11
|
-
}, undefined>;
|
|
12
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
13
|
-
readonly is_empty: v.LiteralSchema<true, undefined>;
|
|
14
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
15
|
-
readonly is_not_empty: v.LiteralSchema<true, undefined>;
|
|
16
|
-
}, undefined>], undefined>;
|
|
17
|
-
export type CustomBlockCreatedByFilterOperator = v.InferOutput<typeof customBlockCreatedByFilterOperatorSchema>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
const customBlockCreatorFilterValueSchema = v.strictObject({
|
|
3
|
-
object: v.literal("user"),
|
|
4
|
-
id: v.pipe(v.string(), v.minLength(1), v.maxLength(2_000)),
|
|
5
|
-
});
|
|
6
|
-
export const customBlockCreatedByFilterOperatorSchema = v.union([
|
|
7
|
-
v.strictObject({ contains: customBlockCreatorFilterValueSchema }),
|
|
8
|
-
v.strictObject({ does_not_contain: customBlockCreatorFilterValueSchema }),
|
|
9
|
-
v.strictObject({ is_empty: v.literal(true) }),
|
|
10
|
-
v.strictObject({ is_not_empty: v.literal(true) }),
|
|
11
|
-
]);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
/**
|
|
3
|
-
* One entry in the block manifest's `capabilities`: what the block needs to do
|
|
4
|
-
* (`capability`) and what it acts on (`resource`). Viewers approve declared
|
|
5
|
-
* entries before the block loads.
|
|
6
|
-
*
|
|
7
|
-
* Both fields accept any string so a newer vocabulary never makes an older host
|
|
8
|
-
* or SDK reject a manifest.
|
|
9
|
-
*/
|
|
10
|
-
export declare const customBlockCapabilityDeclarationSchema: v.ObjectSchema<{
|
|
11
|
-
readonly capability: v.StringSchema<undefined>;
|
|
12
|
-
readonly resource: v.StringSchema<undefined>;
|
|
13
|
-
}, undefined>;
|
|
14
|
-
export type CustomBlockCapabilityDeclaration = v.InferOutput<typeof customBlockCapabilityDeclarationSchema>;
|
|
15
|
-
/**
|
|
16
|
-
* Capability names that hosts recognize. `user` is shorthand for `user.read`
|
|
17
|
-
* and `user.read_email` on the same resource. `page` is shorthand for
|
|
18
|
-
* `page.read`, `page.insert`, `page.update`, and `page.archive` on the same
|
|
19
|
-
* resource. `page.trash` is reserved for a future Trash call and is not
|
|
20
|
-
* accepted yet.
|
|
21
|
-
*/
|
|
22
|
-
export type CustomBlockCapabilityName = "user" | "user.read" | "user.read_email" | "page" | "page.read" | "page.insert" | "page.update" | "page.archive" | "network.fetch";
|
|
23
|
-
/**
|
|
24
|
-
* Resource names that hosts recognize. User capabilities take `current_user`
|
|
25
|
-
* or `workspace` (every member of the workspace). Page capabilities take
|
|
26
|
-
* `workspace` (every page the viewer can access), `containing_page`, or
|
|
27
|
-
* `data_source`. `private` is reserved for a future
|
|
28
|
-
* `page.insert` into the viewer's Private section and is not accepted yet.
|
|
29
|
-
* `network.fetch` takes a bare HTTPS origin.
|
|
30
|
-
*/
|
|
31
|
-
export type CustomBlockCapabilityResourceName = "current_user" | "workspace" | "containing_page" | "data_source" | CustomBlockOriginResourceName;
|
|
32
|
-
/**
|
|
33
|
-
* An HTTPS origin the block loads content from and connects to, such as
|
|
34
|
-
* `https://api.example.com`. `https://*.example.com` covers subdomains. Hosts
|
|
35
|
-
* allow only origins that are also on the workspace's network allowlist.
|
|
36
|
-
*/
|
|
37
|
-
export type CustomBlockOriginResourceName = `https://${string}`;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
/**
|
|
3
|
-
* One entry in the block manifest's `capabilities`: what the block needs to do
|
|
4
|
-
* (`capability`) and what it acts on (`resource`). Viewers approve declared
|
|
5
|
-
* entries before the block loads.
|
|
6
|
-
*
|
|
7
|
-
* Both fields accept any string so a newer vocabulary never makes an older host
|
|
8
|
-
* or SDK reject a manifest.
|
|
9
|
-
*/
|
|
10
|
-
export const customBlockCapabilityDeclarationSchema = v.object({
|
|
11
|
-
capability: v.string(),
|
|
12
|
-
resource: v.string(),
|
|
13
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
export declare const notionFileInputSchema: v.UnionSchema<[v.ObjectSchema<{
|
|
3
|
-
readonly type: v.LiteralSchema<"external", undefined>;
|
|
4
|
-
readonly name: v.StringSchema<undefined>;
|
|
5
|
-
readonly external: v.ObjectSchema<{
|
|
6
|
-
readonly url: v.StringSchema<undefined>;
|
|
7
|
-
}, undefined>;
|
|
8
|
-
}, undefined>, v.ObjectSchema<{
|
|
9
|
-
readonly type: v.LiteralSchema<"file", undefined>;
|
|
10
|
-
readonly name: v.StringSchema<undefined>;
|
|
11
|
-
readonly file: v.ObjectSchema<{
|
|
12
|
-
readonly url: v.StringSchema<undefined>;
|
|
13
|
-
readonly expiry_time: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
14
|
-
}, undefined>;
|
|
15
|
-
}, undefined>], undefined>;
|
|
16
|
-
export type NotionFileInput = v.InferOutput<typeof notionFileInputSchema>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
export const notionFileInputSchema = v.union([
|
|
3
|
-
v.object({
|
|
4
|
-
type: v.literal("external"),
|
|
5
|
-
name: v.string(),
|
|
6
|
-
external: v.object({ url: v.string() }),
|
|
7
|
-
}),
|
|
8
|
-
v.object({
|
|
9
|
-
type: v.literal("file"),
|
|
10
|
-
name: v.string(),
|
|
11
|
-
file: v.object({
|
|
12
|
-
url: v.string(),
|
|
13
|
-
expiry_time: v.optional(v.string()),
|
|
14
|
-
}),
|
|
15
|
-
}),
|
|
16
|
-
]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DebugMessageLog.d.ts","sourceRoot":"","sources":["../../src/react/DebugMessageLog.tsx"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,gCAiB9B"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
import { getBridge } from "../bridge/getBridge.js";
|
|
4
|
-
export function DebugMessageLog() {
|
|
5
|
-
const bridge = getBridge();
|
|
6
|
-
const log = useSyncExternalStore(bridge.subscribeToMessageLog, bridge.getMessageLog);
|
|
7
|
-
const text = log
|
|
8
|
-
.map(entry => `[${entry.timestamp}] ${entry.direction}: ${JSON.stringify(entry.data)}`)
|
|
9
|
-
.join("\n");
|
|
10
|
-
return (_jsx("pre", { "data-testid": "debug-message-log", style: DEBUG_PRE_STYLE, children: text || "(no messages yet)" }));
|
|
11
|
-
}
|
|
12
|
-
const DEBUG_PRE_STYLE = {
|
|
13
|
-
margin: 0,
|
|
14
|
-
padding: "8px 12px",
|
|
15
|
-
fontSize: 12,
|
|
16
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
17
|
-
lineHeight: 1.5,
|
|
18
|
-
whiteSpace: "pre-wrap",
|
|
19
|
-
wordBreak: "break-all",
|
|
20
|
-
userSelect: "text",
|
|
21
|
-
background: "#1e1e1e",
|
|
22
|
-
color: "#d4d4d4",
|
|
23
|
-
};
|
package/docs/capabilities.md
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
# Capabilities
|
|
2
|
-
|
|
3
|
-
The block manifest's `capabilities` lists what a custom block needs to do. Notion asks each viewer
|
|
4
|
-
to approve the declared capabilities before it loads the block.
|
|
5
|
-
|
|
6
|
-
Hosts do not restrict bridge requests by capability yet. A request that the approved capabilities do
|
|
7
|
-
not cover still runs. Declare what the block uses anyway, so viewers see it before approving.
|
|
8
|
-
|
|
9
|
-
Each entry pairs a `capability` with a `resource`. The capability names what the block does, and the
|
|
10
|
-
resource names what it acts on:
|
|
11
|
-
|
|
12
|
-
```json
|
|
13
|
-
{
|
|
14
|
-
"version": 1,
|
|
15
|
-
"dataSources": {
|
|
16
|
-
"tasks": { "name": "Tasks" }
|
|
17
|
-
},
|
|
18
|
-
"capabilities": [
|
|
19
|
-
{ "capability": "page", "resource": "data_source" },
|
|
20
|
-
{ "capability": "user.read", "resource": "workspace" }
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
`@notionhq/workers` 0.9 does not pass `capabilities` from `worker.customBlock()` into the block
|
|
26
|
-
manifest yet.
|
|
27
|
-
|
|
28
|
-
## Vocabulary
|
|
29
|
-
|
|
30
|
-
| Capability | Resource | Covers |
|
|
31
|
-
| ----------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
-
| `user.read` | `current_user` | `users.get` for the viewer. |
|
|
33
|
-
| `user.read` | `workspace` | `users.get` for any user and `users.list`. |
|
|
34
|
-
| `user.read_email` | `current_user` | The viewer's `person.email` in `users.get` results. |
|
|
35
|
-
| `user.read_email` | `workspace` | Every user's `person.email` in `users.get` and `users.list` results. Requires `user.read` at `workspace`. |
|
|
36
|
-
| `user` | any user resource | Shorthand for `user.read` and `user.read_email` on the same resource. |
|
|
37
|
-
| `page.read` | `containing_page` | `pages.get` and `pages.open` for the page that contains the block. |
|
|
38
|
-
| `page.read` | `data_source` | Queries of the block's bound data sources, plus `pages.get` and `pages.open` for their rows. |
|
|
39
|
-
| `page.read` | `workspace` | Reads of any page or data source that the viewer can access. |
|
|
40
|
-
| `page.insert` | `containing_page` | `pages.create` under the containing page. |
|
|
41
|
-
| `page.insert` | `data_source` | `pages.create` in the block's bound data sources. |
|
|
42
|
-
| `page.insert` | `workspace` | `pages.create` under any page or in any data source that the viewer can edit. |
|
|
43
|
-
| `page.update` | `containing_page` | `page.updateById()` and `page.updateByKey()` for the containing page. |
|
|
44
|
-
| `page.update` | `data_source` | `row.updateById()`, `row.updateByKey()`, `page.updateById()`, and `page.updateByKey()` for rows of the block's bound data sources. |
|
|
45
|
-
| `page.update` | `workspace` | `page.updateById()` and `page.updateByKey()` for any page that the viewer can edit. |
|
|
46
|
-
| `page.archive` | `containing_page` | Archiving or unarchiving the containing page. See [Archive](#archive). |
|
|
47
|
-
| `page.archive` | `data_source` | Archiving or unarchiving rows of the block's bound data sources. |
|
|
48
|
-
| `page.archive` | `workspace` | Archiving or unarchiving any page that the viewer can edit. |
|
|
49
|
-
| `page` | any page resource | Shorthand for `page.read`, `page.insert`, `page.update`, and `page.archive` on the same resource. |
|
|
50
|
-
| `network.fetch` | an HTTPS origin | Loading content from and connecting to that origin, such as `https://api.example.com`. See [Network access](#network-access). |
|
|
51
|
-
|
|
52
|
-
For user capabilities, `workspace` is every member of the workspace. For page capabilities, it's
|
|
53
|
-
every page the viewer can access. Either way it covers every narrower resource of the same
|
|
54
|
-
capability. A `containing_page` resource applies to the page that the block instance sits on, so
|
|
55
|
-
viewers approve it again after the block moves to another page. A `data_source` resource applies to
|
|
56
|
-
each data source bound to the block instance, and viewers approve each data source separately. A
|
|
57
|
-
bound data source that the viewer hasn't approved stays unbound for them. The `private` page
|
|
58
|
-
resource is reserved and not accepted yet.
|
|
59
|
-
|
|
60
|
-
Deploys reject unknown capabilities, unknown resources, and pairs that the table does not list.
|
|
61
|
-
|
|
62
|
-
A block that declares `dataSources` must also declare a page capability on `data_source`, such as
|
|
63
|
-
`{ capability: "page.read", resource: "data_source" }`. Otherwise the deploy fails.
|
|
64
|
-
|
|
65
|
-
## Archive
|
|
66
|
-
|
|
67
|
-
`page.update` does not cover archiving or unarchiving a page. Declare `page.archive`, or the `page`
|
|
68
|
-
shorthand, on the same resource.
|
|
69
|
-
|
|
70
|
-
`page.archive` covers updates that set `is_archived`: `page.archive()`, `page.unarchive()`,
|
|
71
|
-
`row.archive()`, `row.unarchive()`, and any update that passes `is_archived`. An update that sets
|
|
72
|
-
`is_archived` and other fields needs both `page.archive` and `page.update`.
|
|
73
|
-
|
|
74
|
-
`page.trash` is reserved for a future call that moves pages to Trash. Deploys do not accept it yet.
|
|
75
|
-
|
|
76
|
-
## Network access
|
|
77
|
-
|
|
78
|
-
`network.fetch` takes a bare HTTPS origin as its resource and lets the block load content from and
|
|
79
|
-
connect to that origin, for example
|
|
80
|
-
`{ capability: "network.fetch", resource: "https://api.example.com" }`. It covers `fetch` and other
|
|
81
|
-
connections, plus images, media, fonts, stylesheets, and frames loaded from the origin. An
|
|
82
|
-
`https://*.example.com` resource covers subdomains. Deploys reject resources that are not bare HTTPS
|
|
83
|
-
origins. Notion allows an approved origin only while it is also on the workspace's custom block
|
|
84
|
-
network allowlist. The dev shell does not limit network access.
|
|
85
|
-
|
|
86
|
-
The declared origins, written as a JSON array such as `["https://api.example.com"]`, can use at most
|
|
87
|
-
2,048 characters. Deploys reject longer lists. Combine origins that share a domain into one
|
|
88
|
-
wildcard, such as `https://*.example.com`, to stay under the limit. The workspace allowlist has the
|
|
89
|
-
same limit.
|
|
90
|
-
|
|
91
|
-
## Blocks without capabilities
|
|
92
|
-
|
|
93
|
-
A manifest that omits `capabilities` loads without an approval step. Notion may require
|
|
94
|
-
`capabilities` in a future release. An empty `capabilities` array declares nothing.
|
|
95
|
-
|
|
96
|
-
## Capability errors
|
|
97
|
-
|
|
98
|
-
The protocol defines the `capability_not_granted` error code for requests that the approved
|
|
99
|
-
capabilities do not cover. No host sends it yet. When a host does, the result will resolve with
|
|
100
|
-
`status: "error"` and `isRetryable: false`. See [error handling](errors.md).
|
|
101
|
-
|
|
102
|
-
## Dev shell
|
|
103
|
-
|
|
104
|
-
The dev shell does not ask for approval. It loads every block as if its capabilities were approved.
|
|
105
|
-
|
|
106
|
-
## Types
|
|
107
|
-
|
|
108
|
-
- `CustomBlockCapabilityDeclaration`: one `{ capability, resource }` entry. Both fields are strings
|
|
109
|
-
on the wire, so newer names do not break older SDKs.
|
|
110
|
-
- `CustomBlockCapabilityName`: the capability names in the vocabulary table.
|
|
111
|
-
- `CustomBlockCapabilityResourceName`: the resource names in the vocabulary table.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tracks one-shot request/response pairs over the `postMessage` bridge. Each `allocate` reserves a
|
|
3
|
-
* unique `requestId` and stores its resolver. `resolve` finds the pending resolver by `requestId`
|
|
4
|
-
* and calls it, then removes the entry so the same `requestId` cannot be resolved twice.
|
|
5
|
-
*/
|
|
6
|
-
export class PendingRequests<T> {
|
|
7
|
-
private nextId = 1
|
|
8
|
-
private readonly entries = new Map<string, (value: T) => void>()
|
|
9
|
-
|
|
10
|
-
constructor(private readonly prefix: string) {}
|
|
11
|
-
|
|
12
|
-
allocate(resolver: (value: T) => void): string {
|
|
13
|
-
const requestId = `${this.prefix}-${this.nextId}`
|
|
14
|
-
this.nextId += 1
|
|
15
|
-
this.entries.set(requestId, resolver)
|
|
16
|
-
return requestId
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
resolve(requestId: string, value: T): boolean {
|
|
20
|
-
const resolver = this.entries.get(requestId)
|
|
21
|
-
if (resolver === undefined) {
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
24
|
-
this.entries.delete(requestId)
|
|
25
|
-
resolver(value)
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
}
|