@notionhq/custom-blocks 0.3.5 → 0.4.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 (124) hide show
  1. package/README.md +2 -2
  2. package/dist/bridge/SandboxBridge.d.ts +4 -23
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +36 -104
  5. package/dist/bridge/requests.d.ts +35 -0
  6. package/dist/bridge/requests.d.ts.map +1 -0
  7. package/dist/bridge/requests.js +97 -0
  8. package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -1
  9. package/dist/dataSources/bridge/resolveDataSourceQuery.js +15 -1
  10. package/dist/dataSources/createDataSourcePage.d.ts.map +1 -1
  11. package/dist/dataSources/createDataSourcePage.js +5 -1
  12. package/dist/dataSources/types.d.ts +2 -0
  13. package/dist/dataSources/types.d.ts.map +1 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/manifest/types.d.ts +1 -1
  17. package/dist/manifest/types.d.ts.map +1 -1
  18. package/dist/navigation/openExternalUrl.d.ts.map +1 -1
  19. package/dist/navigation/openExternalUrl.js +2 -1
  20. package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
  21. package/dist/pages/bridge/getPageForDataSource.js +2 -1
  22. package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
  23. package/dist/pages/bridge/sendCreatePageRequest.js +2 -1
  24. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +11 -2
  25. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
  26. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +0 -1
  27. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
  28. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -6
  29. package/dist/pages/bridge/updatePage.d.ts.map +1 -1
  30. package/dist/pages/bridge/updatePage.js +19 -4
  31. package/dist/pages/createPage.d.ts.map +1 -1
  32. package/dist/pages/createPage.js +5 -1
  33. package/dist/pages/openPage.d.ts.map +1 -1
  34. package/dist/pages/openPage.js +2 -1
  35. package/dist/pages/types.d.ts +5 -7
  36. package/dist/pages/types.d.ts.map +1 -1
  37. package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +7 -5
  38. package/dist/protocol/context/parent.d.ts +2 -0
  39. package/dist/protocol/dataSources/bridgeArchiveStatus.d.ts +3 -0
  40. package/dist/protocol/dataSources/bridgeArchiveStatus.js +6 -0
  41. package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +0 -4
  42. package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +0 -4
  43. package/dist/protocol/dataSources/collectionSchema.d.ts +0 -4
  44. package/dist/protocol/dataSources/messages/dataSourcesChanged.d.ts +0 -4
  45. package/dist/protocol/dataSources/messages/queryDataSource.d.ts +17 -14
  46. package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
  47. package/dist/protocol/dataSources/notionDataSource.d.ts +0 -8
  48. package/dist/protocol/dataSources/properties/propertySchema.d.ts +3 -7
  49. package/dist/protocol/dataSources/properties/propertySchema.js +1 -3
  50. package/dist/protocol/handshake/connect.d.ts +15 -4
  51. package/dist/protocol/handshake/init.d.ts +15 -8
  52. package/dist/protocol/icons.d.ts +17 -0
  53. package/dist/protocol/icons.js +27 -0
  54. package/dist/protocol/index.d.ts +13 -9
  55. package/dist/protocol/index.js +8 -5
  56. package/dist/protocol/manifest/grants.d.ts +48 -0
  57. package/dist/protocol/manifest/grants.js +19 -0
  58. package/dist/protocol/manifest/manifest.d.ts +33 -10
  59. package/dist/protocol/manifest/manifest.js +11 -5
  60. package/dist/protocol/messages/hostToSandbox.d.ts +109 -87
  61. package/dist/protocol/messages/invalidHostMessage.d.ts +2 -0
  62. package/dist/protocol/messages/invalidHostMessage.js +2 -0
  63. package/dist/protocol/messages/invalidSandboxMessage.d.ts +2 -0
  64. package/dist/protocol/messages/invalidSandboxMessage.js +2 -0
  65. package/dist/protocol/messages/sandboxToHost.d.ts +104 -17
  66. package/dist/protocol/navigation/openExternalUrl.d.ts +2 -2
  67. package/dist/protocol/pages/bridgePage.d.ts +7 -6
  68. package/dist/protocol/pages/bridgePage.js +0 -1
  69. package/dist/protocol/pages/makeBridgePage.d.ts +3 -1
  70. package/dist/protocol/pages/messages/createPage.d.ts +103 -27
  71. package/dist/protocol/pages/messages/createPage.js +3 -1
  72. package/dist/protocol/pages/messages/getPage.d.ts +23 -19
  73. package/dist/protocol/pages/messages/openPage.d.ts +2 -2
  74. package/dist/protocol/pages/messages/updatePage.d.ts +30 -24
  75. package/dist/protocol/pages/pageAppearance.d.ts +36 -1
  76. package/dist/protocol/pages/pageAppearance.js +9 -0
  77. package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +0 -8
  78. package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +0 -4
  79. package/dist/protocol/pages/properties/bridgePagePropertyValue.js +0 -5
  80. package/dist/protocol/users/makeBridgeUser.d.ts +3 -1
  81. package/dist/protocol/users/messages/getUser.d.ts +2 -2
  82. package/dist/protocol/users/messages/listUsers.d.ts +2 -2
  83. package/dist/protocol/utils/errors.d.ts +6 -4
  84. package/dist/protocol/utils/errors.js +3 -3
  85. package/dist/protocol/utils/protocolVersion.d.ts +2 -1
  86. package/dist/protocol/utils/protocolVersion.js +3 -1
  87. package/dist/protocol/utils/readRequestId.d.ts +2 -0
  88. package/dist/protocol/utils/readRequestId.js +7 -0
  89. package/dist/users/getUser.d.ts.map +1 -1
  90. package/dist/users/getUser.js +2 -1
  91. package/dist/users/listUsers.d.ts.map +1 -1
  92. package/dist/users/listUsers.js +4 -2
  93. package/dist/utils/version.js +1 -1
  94. package/docs/data-sources.md +38 -34
  95. package/docs/errors.md +47 -5
  96. package/docs/grants.md +127 -0
  97. package/docs/pages.md +45 -32
  98. package/docs/users.md +2 -2
  99. package/package.json +1 -1
  100. package/src/bridge/SandboxBridge.ts +44 -188
  101. package/src/bridge/requests.ts +138 -0
  102. package/src/dataSources/bridge/resolveDataSourceQuery.ts +21 -1
  103. package/src/dataSources/createDataSourcePage.ts +5 -1
  104. package/src/dataSources/types.ts +3 -0
  105. package/src/index.ts +8 -4
  106. package/src/manifest/types.ts +1 -1
  107. package/src/navigation/openExternalUrl.ts +5 -1
  108. package/src/pages/bridge/getPageForDataSource.ts +5 -1
  109. package/src/pages/bridge/sendCreatePageRequest.ts +5 -1
  110. package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +0 -1
  111. package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -6
  112. package/src/pages/bridge/updatePage.ts +28 -8
  113. package/src/pages/createPage.ts +5 -1
  114. package/src/pages/openPage.ts +5 -1
  115. package/src/pages/types.ts +7 -5
  116. package/src/users/getUser.ts +5 -1
  117. package/src/users/listUsers.ts +9 -4
  118. package/dist/bridge/pendingRequests.d.ts +0 -14
  119. package/dist/bridge/pendingRequests.d.ts.map +0 -1
  120. package/dist/bridge/pendingRequests.js +0 -28
  121. package/dist/protocol/manifest/capabilities.d.ts +0 -37
  122. package/dist/protocol/manifest/capabilities.js +0 -13
  123. package/docs/capabilities.md +0 -111
  124. package/src/bridge/pendingRequests.ts +0 -28
@@ -0,0 +1,27 @@
1
+ import * as v from "valibot";
2
+ /** Icon names stay open as hosts add to their catalogs. */
3
+ export const notionIconNameSchema = v.string();
4
+ const knownNotionIconColorSchema = v.picklist([
5
+ "gray",
6
+ "lightgray",
7
+ "brown",
8
+ "yellow",
9
+ "orange",
10
+ "green",
11
+ "blue",
12
+ "purple",
13
+ "pink",
14
+ "red",
15
+ ]);
16
+ export const notionIconColorSchema = v.union([
17
+ knownNotionIconColorSchema,
18
+ v.string(),
19
+ ]);
20
+ /** Reads and writes share an open shape; hosts resolve names and default omitted colors. */
21
+ export const notionNativeIconSchema = v.looseObject({
22
+ type: v.literal("icon"),
23
+ icon: v.looseObject({
24
+ name: notionIconNameSchema,
25
+ color: v.optional(notionIconColorSchema),
26
+ }),
27
+ });
@@ -19,10 +19,12 @@ export type { ResizeMessage } from "./context/messages/resize.js";
19
19
  export { resizeMessageSchema } from "./context/messages/resize.js";
20
20
  export type { ThemeChangedMessage } from "./context/messages/themeChanged.js";
21
21
  export { themeChangedMessageSchema } from "./context/messages/themeChanged.js";
22
- export type { DataSourceParent, NotionParent, PageParent, } from "./context/parent.js";
22
+ export type { BridgeParent, DataSourceParent, NotionParent, PageParent, } from "./context/parent.js";
23
23
  export { dataSourceParentSchema, notionParentSchema, pageParentSchema, } from "./context/parent.js";
24
24
  export type { NotionTheme } from "./context/theme.js";
25
25
  export { notionThemeSchema } from "./context/theme.js";
26
+ export type { BridgeArchiveStatus } from "./dataSources/bridgeArchiveStatus.js";
27
+ export { bridgeArchiveStatusSchema } from "./dataSources/bridgeArchiveStatus.js";
26
28
  export type { BridgeDataSourceBinding } from "./dataSources/bridgeDataSourceBinding.js";
27
29
  export { bridgeDataSourceBindingSchema } from "./dataSources/bridgeDataSourceBinding.js";
28
30
  export type { BridgeDataSourceBindings } from "./dataSources/bridgeDataSourceBindings.js";
@@ -85,10 +87,11 @@ export { CustomBlockInitializationError, customBlockInitErrorCodeSchema, customB
85
87
  export type { CustomBlockInitResultErrorCode, CustomBlockInitResultErrorInfo, InitResultMessage, } from "./handshake/initResult.js";
86
88
  export { customBlockInitResultErrorCodeSchema, customBlockInitResultErrorInfoSchema, initResultMessageSchema, } from "./handshake/initResult.js";
87
89
  export { isInitHandshakeMessage } from "./handshake/isInitHandshakeMessage.js";
88
- export type { CustomBlockCapabilityDeclaration, CustomBlockCapabilityName, CustomBlockCapabilityResourceName, CustomBlockOriginResourceName, } from "./manifest/capabilities.js";
89
- export { customBlockCapabilityDeclarationSchema } from "./manifest/capabilities.js";
90
- export type { BridgeCustomBlockManifest, ManifestDataSource, ManifestIcon, ManifestProperty, } from "./manifest/manifest.js";
91
- export { manifestDataSourceSchema, manifestIconSchema, manifestPropertySchema, manifestSchema, } from "./manifest/manifest.js";
90
+ export * from "./icons.js";
91
+ export type { CustomBlockDataSourceResourceName, CustomBlockGrant, CustomBlockGrantAction, CustomBlockGrantResourceName, CustomBlockOriginResourceName, } from "./manifest/grants.js";
92
+ export { customBlockGrantSchema } from "./manifest/grants.js";
93
+ export type { BridgeCustomBlockManifest, ManifestDataSource, ManifestIcon, ManifestPage, ManifestProperty, } from "./manifest/manifest.js";
94
+ export { manifestDataSourceSchema, manifestIconSchema, manifestPageSchema, manifestPropertySchema, manifestSchema, } from "./manifest/manifest.js";
92
95
  export type { HostToSandboxMessage, HostToSandboxMessageWithProtocol3To5Compatibility, } from "./messages/hostToSandbox.js";
93
96
  export { hostToSandboxMessageSchema, hostToSandboxMessageWithProtocol3To5CompatibilitySchema, } from "./messages/hostToSandbox.js";
94
97
  export { readIncomingType } from "./messages/incomingType.js";
@@ -114,7 +117,7 @@ export { customBlockOpenPageErrorCodeSchema, customBlockOpenPageErrorInfoSchema,
114
117
  export type { CustomBlockUpdatePageErrorCode, CustomBlockUpdatePageErrorInfo, UpdatePageMessage, UpdatePageResultMessage, UpdatePageResultMessageWithProtocol3To5Compatibility, } from "./pages/messages/updatePage.js";
115
118
  export { customBlockUpdatePageErrorCodeSchema, customBlockUpdatePageErrorInfoSchema, updatePageMessageSchema, updatePageResultMessageSchema, updatePageResultMessageWithProtocol3To5CompatibilitySchema, } from "./pages/messages/updatePage.js";
116
119
  export type { NotionPageCover, NotionPageIcon } from "./pages/pageAppearance.js";
117
- export { notionCustomEmojiIconSchema, notionEmojiIconSchema, notionExternalFileSchema, notionHostedFileSchema, notionPageCoverSchema, notionPageIconSchema, } from "./pages/pageAppearance.js";
120
+ export { type NotionCreatePageIcon, notionCreatePageIconSchema, notionCustomEmojiIconSchema, notionEmojiIconSchema, notionExternalFileSchema, notionHostedFileSchema, notionPageCoverSchema, notionPageIconSchema, } from "./pages/pageAppearance.js";
118
121
  export type { BridgePagePropertyReadMap, BridgePagePropertyWriteMap, } from "./pages/properties/bridgePagePropertyMaps.js";
119
122
  export { bridgePagePropertyReadMapSchema, bridgePagePropertyWriteMapSchema, } from "./pages/properties/bridgePagePropertyMaps.js";
120
123
  export type { BridgePagePropertyValue } from "./pages/properties/bridgePagePropertyValue.js";
@@ -140,11 +143,12 @@ export type { CustomBlockListUsersErrorCode, CustomBlockListUsersErrorInfo, List
140
143
  export { customBlockListUsersErrorCodeSchema, customBlockListUsersErrorInfoSchema, listUsersMessageSchema, listUsersResultMessageSchema, } from "./users/messages/listUsers.js";
141
144
  export type { NotionUserId } from "./users/userId.js";
142
145
  export { notionUserIdSchema } from "./users/userId.js";
143
- export type { CustomBlockCapabilityErrorCode, CustomBlockErrorCode, CustomBlockErrorInfo, } from "./utils/errors.js";
144
- export { CAPABILITY_NOT_GRANTED_ERROR_CODE, customBlockErrorInfoSchema, } from "./utils/errors.js";
146
+ export type { CustomBlockErrorCode, CustomBlockErrorInfo, CustomBlockGrantErrorCode, CustomBlockRequestErrorCode, } from "./utils/errors.js";
147
+ export { customBlockErrorInfoSchema, NOT_GRANTED_ERROR_CODE, } from "./utils/errors.js";
145
148
  export type { NotionAgentId, NotionBlockId, NotionDataSourceId, NotionPageId, NotionSpaceId, } from "./utils/ids.js";
146
149
  export { notionAgentIdSchema, notionBlockIdSchema, notionDataSourceIdSchema, notionPageIdSchema, notionSpaceIdSchema, } from "./utils/ids.js";
147
150
  export { isLocalBlockServerUrl } from "./utils/isLocalBlockServerUrl.js";
148
- export { LATEST_BRIDGE_PROTOCOL_VERSION, TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, UNIFIED_PAGE_PROTOCOL_VERSION, } from "./utils/protocolVersion.js";
151
+ export { LATEST_BRIDGE_PROTOCOL_VERSION, NATIVE_ICON_PROTOCOL_VERSION, TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, UNIFIED_PAGE_PROTOCOL_VERSION, } from "./utils/protocolVersion.js";
152
+ export { readRequestId } from "./utils/readRequestId.js";
149
153
  export type { NotionRecordPointer } from "./utils/recordPointer.js";
150
154
  export { notionRecordPointerSchema } from "./utils/recordPointer.js";
@@ -11,6 +11,7 @@ export { resizeMessageSchema } from "./context/messages/resize.js";
11
11
  export { themeChangedMessageSchema } from "./context/messages/themeChanged.js";
12
12
  export { dataSourceParentSchema, notionParentSchema, pageParentSchema, } from "./context/parent.js";
13
13
  export { notionThemeSchema } from "./context/theme.js";
14
+ export { bridgeArchiveStatusSchema } from "./dataSources/bridgeArchiveStatus.js";
14
15
  export { bridgeDataSourceBindingSchema } from "./dataSources/bridgeDataSourceBinding.js";
15
16
  export { bridgeDataSourceBindingsSchema } from "./dataSources/bridgeDataSourceBindings.js";
16
17
  export { notionCollectionSchemaValidator } from "./dataSources/collectionSchema.js";
@@ -42,8 +43,9 @@ export { connectMessageSchema } from "./handshake/connect.js";
42
43
  export { CustomBlockInitializationError, customBlockInitErrorCodeSchema, customBlockInitErrorInfoSchema, initMessageSchema, } from "./handshake/init.js";
43
44
  export { customBlockInitResultErrorCodeSchema, customBlockInitResultErrorInfoSchema, initResultMessageSchema, } from "./handshake/initResult.js";
44
45
  export { isInitHandshakeMessage } from "./handshake/isInitHandshakeMessage.js";
45
- export { customBlockCapabilityDeclarationSchema } from "./manifest/capabilities.js";
46
- export { manifestDataSourceSchema, manifestIconSchema, manifestPropertySchema, manifestSchema, } from "./manifest/manifest.js";
46
+ export * from "./icons.js";
47
+ export { customBlockGrantSchema } from "./manifest/grants.js";
48
+ export { manifestDataSourceSchema, manifestIconSchema, manifestPageSchema, manifestPropertySchema, manifestSchema, } from "./manifest/manifest.js";
47
49
  export { hostToSandboxMessageSchema, hostToSandboxMessageWithProtocol3To5CompatibilitySchema, } from "./messages/hostToSandbox.js";
48
50
  export { readIncomingType } from "./messages/incomingType.js";
49
51
  export { invalidHostMessageSchema } from "./messages/invalidHostMessage.js";
@@ -56,7 +58,7 @@ export { createPageMessageSchema, createPageParentSchema, createPageResultMessag
56
58
  export { customBlockGetPageErrorCodeSchema, customBlockGetPageErrorInfoSchema, getPageMessageSchema, getPageResultMessageSchema, getPageResultMessageWithProtocol3To5CompatibilitySchema, } from "./pages/messages/getPage.js";
57
59
  export { customBlockOpenPageErrorCodeSchema, customBlockOpenPageErrorInfoSchema, openPageMessageSchema, openPageModeSchema, openPageResultMessageSchema, } from "./pages/messages/openPage.js";
58
60
  export { customBlockUpdatePageErrorCodeSchema, customBlockUpdatePageErrorInfoSchema, updatePageMessageSchema, updatePageResultMessageSchema, updatePageResultMessageWithProtocol3To5CompatibilitySchema, } from "./pages/messages/updatePage.js";
59
- export { notionCustomEmojiIconSchema, notionEmojiIconSchema, notionExternalFileSchema, notionHostedFileSchema, notionPageCoverSchema, notionPageIconSchema, } from "./pages/pageAppearance.js";
61
+ export { notionCreatePageIconSchema, notionCustomEmojiIconSchema, notionEmojiIconSchema, notionExternalFileSchema, notionHostedFileSchema, notionPageCoverSchema, notionPageIconSchema, } from "./pages/pageAppearance.js";
60
62
  export { bridgePagePropertyReadMapSchema, bridgePagePropertyWriteMapSchema, } from "./pages/properties/bridgePagePropertyMaps.js";
61
63
  export { bridgePagePropertyValueSchema } from "./pages/properties/bridgePagePropertyValue.js";
62
64
  export { bridgeUserSchema } from "./users/bridgeUser.js";
@@ -66,8 +68,9 @@ export { currentUserChangedMessageSchema } from "./users/messages/currentUserCha
66
68
  export { customBlockGetUserErrorCodeSchema, customBlockGetUserErrorInfoSchema, getUserMessageSchema, getUserResultMessageSchema, } from "./users/messages/getUser.js";
67
69
  export { customBlockListUsersErrorCodeSchema, customBlockListUsersErrorInfoSchema, listUsersMessageSchema, listUsersResultMessageSchema, } from "./users/messages/listUsers.js";
68
70
  export { notionUserIdSchema } from "./users/userId.js";
69
- export { CAPABILITY_NOT_GRANTED_ERROR_CODE, customBlockErrorInfoSchema, } from "./utils/errors.js";
71
+ export { customBlockErrorInfoSchema, NOT_GRANTED_ERROR_CODE, } from "./utils/errors.js";
70
72
  export { notionAgentIdSchema, notionBlockIdSchema, notionDataSourceIdSchema, notionPageIdSchema, notionSpaceIdSchema, } from "./utils/ids.js";
71
73
  export { isLocalBlockServerUrl } from "./utils/isLocalBlockServerUrl.js";
72
- export { LATEST_BRIDGE_PROTOCOL_VERSION, TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, UNIFIED_PAGE_PROTOCOL_VERSION, } from "./utils/protocolVersion.js";
74
+ export { LATEST_BRIDGE_PROTOCOL_VERSION, NATIVE_ICON_PROTOCOL_VERSION, TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION, UNIFIED_PAGE_PROTOCOL_VERSION, } from "./utils/protocolVersion.js";
75
+ export { readRequestId } from "./utils/readRequestId.js";
73
76
  export { notionRecordPointerSchema } from "./utils/recordPointer.js";
@@ -0,0 +1,48 @@
1
+ import * as v from "valibot";
2
+ /**
3
+ * One entry in the block manifest's `grants`: what the block needs to do
4
+ * (`action`) and what it acts on (`resource`). Viewers approve declared
5
+ * entries before the block loads.
6
+ *
7
+ * `resource` is one resource or a non-empty array of them. An array applies
8
+ * the action to each element. A resource string is never split, so
9
+ * `"data_source:tasks,projects"` names one key.
10
+ *
11
+ * Names are open strings so a newer vocabulary never makes an older host or SDK
12
+ * reject a manifest. Notion stores each array element as its own entry at
13
+ * deploy, so the manifest a deployed block receives in `init` has string
14
+ * resources only.
15
+ */
16
+ export declare const customBlockGrantSchema: v.ObjectSchema<{
17
+ readonly action: v.StringSchema<undefined>;
18
+ readonly resource: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.MinLengthAction<string[], 1, undefined>]>], undefined>;
19
+ }, undefined>;
20
+ export type CustomBlockGrant = v.InferOutput<typeof customBlockGrantSchema>;
21
+ /**
22
+ * Grant actions that hosts recognize. `user` is shorthand for `user.read`
23
+ * and `user.read_email` on the same resource. `page` is shorthand for
24
+ * `page.read`, `page.insert`, `page.update`, and `page.archive` on the same
25
+ * resource. `page.trash` is reserved for a future Trash call and is not
26
+ * accepted yet.
27
+ */
28
+ export type CustomBlockGrantAction = "user" | "user.read" | "user.read_email" | "page" | "page.read" | "page.insert" | "page.update" | "page.archive" | "network.fetch";
29
+ /**
30
+ * Resource names that hosts recognize. User actions take `current_user`
31
+ * or `workspace` (every member of the workspace). Page actions take
32
+ * `workspace` (every page the viewer can access), `containing_page`,
33
+ * `data_source:<key>`, or `data_source` (every declared data source).
34
+ * `private` is reserved for a future `page.insert` into the viewer's Private
35
+ * section and is not accepted yet. `network.fetch` takes a bare HTTPS origin.
36
+ */
37
+ export type CustomBlockGrantResourceName = "current_user" | "workspace" | "containing_page" | "data_source" | CustomBlockDataSourceResourceName | CustomBlockOriginResourceName;
38
+ /**
39
+ * The data source bound to one key of the manifest's `dataSources`, such as
40
+ * `data_source:tasks`. The key must match a declared data source exactly.
41
+ */
42
+ export type CustomBlockDataSourceResourceName = `data_source:${string}`;
43
+ /**
44
+ * An HTTPS origin the block loads content from and connects to, such as
45
+ * `https://api.example.com`. `https://*.example.com` covers subdomains. Hosts
46
+ * allow only origins that are also on the workspace's network allowlist.
47
+ */
48
+ export type CustomBlockOriginResourceName = `https://${string}`;
@@ -0,0 +1,19 @@
1
+ import * as v from "valibot";
2
+ /**
3
+ * One entry in the block manifest's `grants`: what the block needs to do
4
+ * (`action`) and what it acts on (`resource`). Viewers approve declared
5
+ * entries before the block loads.
6
+ *
7
+ * `resource` is one resource or a non-empty array of them. An array applies
8
+ * the action to each element. A resource string is never split, so
9
+ * `"data_source:tasks,projects"` names one key.
10
+ *
11
+ * Names are open strings so a newer vocabulary never makes an older host or SDK
12
+ * reject a manifest. Notion stores each array element as its own entry at
13
+ * deploy, so the manifest a deployed block receives in `init` has string
14
+ * resources only.
15
+ */
16
+ export const customBlockGrantSchema = v.object({
17
+ action: v.string(),
18
+ resource: v.union([v.string(), v.pipe(v.array(v.string()), v.minLength(1))]),
19
+ });
@@ -15,9 +15,21 @@ export type ManifestIcon = v.InferOutput<typeof manifestIconSchema>;
15
15
  export declare const manifestPropertySchema: v.ObjectSchema<{
16
16
  readonly name: v.StringSchema<undefined>;
17
17
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
18
- readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
18
+ readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
19
19
  }, undefined>;
20
20
  export type ManifestProperty = v.InferOutput<typeof manifestPropertySchema>;
21
+ export declare const manifestPageSchema: v.ObjectSchema<{
22
+ readonly name: v.StringSchema<undefined>;
23
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
24
+ readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
25
+ readonly type: v.LiteralSchema<"emoji", undefined>;
26
+ readonly emoji: v.StringSchema<undefined>;
27
+ }, undefined>, v.ObjectSchema<{
28
+ readonly type: v.LiteralSchema<"external", undefined>;
29
+ readonly url: v.StringSchema<undefined>;
30
+ }, undefined>], undefined>, undefined>;
31
+ }, undefined>;
32
+ export type ManifestPage = v.InferOutput<typeof manifestPageSchema>;
21
33
  export declare const manifestDataSourceSchema: v.ObjectSchema<{
22
34
  readonly name: v.StringSchema<undefined>;
23
35
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -31,7 +43,7 @@ export declare const manifestDataSourceSchema: v.ObjectSchema<{
31
43
  readonly properties: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
32
44
  readonly name: v.StringSchema<undefined>;
33
45
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
34
- readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
46
+ readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
35
47
  }, undefined>, undefined>, {}>;
36
48
  }, undefined>;
37
49
  export type ManifestDataSource = v.InferOutput<typeof manifestDataSourceSchema>;
@@ -57,21 +69,32 @@ export declare const manifestSchema: v.ObjectSchema<{
57
69
  readonly properties: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
58
70
  readonly name: v.StringSchema<undefined>;
59
71
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
60
- readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
72
+ readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
61
73
  }, undefined>, undefined>, {}>;
62
74
  }, undefined>, undefined>, {}>;
75
+ readonly pages: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
76
+ readonly name: v.StringSchema<undefined>;
77
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
78
+ readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
79
+ readonly type: v.LiteralSchema<"emoji", undefined>;
80
+ readonly emoji: v.StringSchema<undefined>;
81
+ }, undefined>, v.ObjectSchema<{
82
+ readonly type: v.LiteralSchema<"external", undefined>;
83
+ readonly url: v.StringSchema<undefined>;
84
+ }, undefined>], undefined>, undefined>;
85
+ }, undefined>, undefined>, undefined>;
63
86
  /**
64
- * Capabilities the block needs. Omitted means the block predates capability
65
- * approval, so hosts do not ask the viewer. An empty array declares no
66
- * capabilities.
87
+ * Grants the block needs. Omitted means the block predates viewer
88
+ * approval, so hosts do not ask the viewer. An empty array declares
89
+ * nothing.
67
90
  */
68
- readonly capabilities: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
69
- readonly capability: v.StringSchema<undefined>;
70
- readonly resource: v.StringSchema<undefined>;
91
+ readonly grants: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
92
+ readonly action: v.StringSchema<undefined>;
93
+ readonly resource: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.MinLengthAction<string[], 1, undefined>]>], undefined>;
71
94
  }, undefined>, undefined>, undefined>;
72
95
  }, undefined>;
73
96
  /**
74
97
  * Manifest describing a custom block, its required data sources, and its
75
- * capabilities.
98
+ * grants.
76
99
  */
77
100
  export type BridgeCustomBlockManifest = v.InferOutput<typeof manifestSchema>;
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { notionPropertyTypeSchema } from "../dataSources/properties/propertySchema.js";
3
- import { customBlockCapabilityDeclarationSchema } from "./capabilities.js";
3
+ import { customBlockGrantSchema } from "./grants.js";
4
4
  /**
5
5
  * Decorative icon attached to a manifest data source. Mirrors the
6
6
  * `emoji` / `external` icon variants the public Notion API uses, so the host
@@ -21,6 +21,11 @@ export const manifestPropertySchema = v.object({
21
21
  description: v.optional(v.string()),
22
22
  type: notionPropertyTypeSchema,
23
23
  });
24
+ export const manifestPageSchema = v.object({
25
+ name: v.string(),
26
+ description: v.optional(v.string()),
27
+ icon: v.optional(manifestIconSchema),
28
+ });
24
29
  export const manifestDataSourceSchema = v.object({
25
30
  name: v.string(),
26
31
  description: v.optional(v.string()),
@@ -34,10 +39,11 @@ export const manifestSchema = v.object({
34
39
  slashCommand: v.optional(v.string()),
35
40
  icon: v.optional(v.object({ type: v.literal("emoji"), emoji: v.string() })),
36
41
  dataSources: v.optional(v.record(v.string(), manifestDataSourceSchema), {}),
42
+ pages: v.optional(v.record(v.string(), manifestPageSchema)),
37
43
  /**
38
- * Capabilities the block needs. Omitted means the block predates capability
39
- * approval, so hosts do not ask the viewer. An empty array declares no
40
- * capabilities.
44
+ * Grants the block needs. Omitted means the block predates viewer
45
+ * approval, so hosts do not ask the viewer. An empty array declares
46
+ * nothing.
41
47
  */
42
- capabilities: v.optional(v.array(customBlockCapabilityDeclarationSchema)),
48
+ grants: v.optional(v.array(customBlockGrantSchema)),
43
49
  });