@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.
Files changed (192) hide show
  1. package/README.md +2 -2
  2. package/dist/bridge/SandboxBridge.d.ts +4 -39
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +36 -142
  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 +18 -4
  10. package/dist/dataSources/bridge/resolveDataSources.js +4 -4
  11. package/dist/dataSources/createDataSourcePage.d.ts.map +1 -1
  12. package/dist/dataSources/createDataSourcePage.js +5 -1
  13. package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -1
  14. package/dist/dataSources/filters/resolveFilter.js +13 -3
  15. package/dist/dataSources/filters/types.d.ts +9 -3
  16. package/dist/dataSources/filters/types.d.ts.map +1 -1
  17. package/dist/dataSources/properties/resolvePropertyAddress.js +1 -1
  18. package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.js +1 -1
  19. package/dist/dataSources/resolvePageDataSource.js +2 -2
  20. package/dist/dataSources/subscribeToDataSource.d.ts +1 -4
  21. package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
  22. package/dist/dataSources/subscribeToDataSource.js +2 -3
  23. package/dist/dataSources/types.d.ts +2 -0
  24. package/dist/dataSources/types.d.ts.map +1 -1
  25. package/dist/files/files.d.ts +2 -0
  26. package/dist/files/files.d.ts.map +1 -0
  27. package/dist/files/files.js +1 -0
  28. package/dist/files/icons.d.ts +2 -0
  29. package/dist/files/icons.d.ts.map +1 -0
  30. package/dist/files/icons.js +1 -0
  31. package/dist/index.d.ts +5 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/initialization/getInitBindingError.js +2 -2
  34. package/dist/manifest/types.d.ts +5 -4
  35. package/dist/manifest/types.d.ts.map +1 -1
  36. package/dist/navigation/openExternalUrl.d.ts.map +1 -1
  37. package/dist/navigation/openExternalUrl.js +2 -1
  38. package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -1
  39. package/dist/pages/bridge/getPageForDataSource.js +3 -2
  40. package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -1
  41. package/dist/pages/bridge/sendCreatePageRequest.js +2 -1
  42. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +14 -2
  43. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -1
  44. package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +0 -1
  45. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -1
  46. package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +0 -8
  47. package/dist/pages/bridge/updatePage.d.ts.map +1 -1
  48. package/dist/pages/bridge/updatePage.js +20 -5
  49. package/dist/pages/createPage.d.ts.map +1 -1
  50. package/dist/pages/createPage.js +5 -1
  51. package/dist/pages/openPage.d.ts.map +1 -1
  52. package/dist/pages/openPage.js +2 -1
  53. package/dist/pages/properties/getPropertyByKey.js +2 -2
  54. package/dist/pages/types.d.ts +10 -14
  55. package/dist/pages/types.d.ts.map +1 -1
  56. package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.d.ts +530 -0
  57. package/dist/protocol/compatibility/protocol3To10/dataSourceBindings.js +25 -0
  58. package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +12 -11
  59. package/dist/protocol/compatibility/protocol3To5/bridgePage.js +3 -3
  60. package/dist/protocol/context/containingPage.d.ts +3 -0
  61. package/dist/protocol/context/messages/pageChanged.d.ts +3 -0
  62. package/dist/protocol/context/messages/parentChanged.d.ts +3 -0
  63. package/dist/protocol/context/parent.d.ts +5 -0
  64. package/dist/protocol/context/parent.js +6 -1
  65. package/dist/protocol/dataSources/bridgeArchiveStatus.d.ts +3 -0
  66. package/dist/protocol/dataSources/bridgeArchiveStatus.js +6 -0
  67. package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +3 -11
  68. package/dist/protocol/dataSources/bridgeDataSourceBinding.js +5 -5
  69. package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +2 -10
  70. package/dist/protocol/dataSources/{collectionPointer.d.ts → dataSourcePointer.d.ts} +2 -2
  71. package/dist/protocol/dataSources/{collectionPointer.js → dataSourcePointer.js} +1 -1
  72. package/dist/protocol/dataSources/{collectionSchema.d.ts → dataSourceSchema.d.ts} +2 -10
  73. package/dist/protocol/dataSources/{collectionSchema.js → dataSourceSchema.js} +1 -1
  74. package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.d.ts +1458 -12
  75. package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.d.ts +729 -6
  76. package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.js +14 -2
  77. package/dist/protocol/dataSources/filters/peopleFilterOperator.d.ts +3 -3
  78. package/dist/protocol/dataSources/filters/peopleFilterOperator.js +1 -1
  79. package/dist/protocol/dataSources/filters/timestampFilterOperator.d.ts +354 -0
  80. package/dist/protocol/dataSources/filters/timestampFilterOperator.js +4 -0
  81. package/dist/protocol/dataSources/messages/dataSourcesChanged.d.ts +2 -10
  82. package/dist/protocol/dataSources/messages/queryDataSource.d.ts +1485 -38
  83. package/dist/protocol/dataSources/messages/queryDataSource.js +2 -0
  84. package/dist/protocol/dataSources/notionDataSource.d.ts +3 -19
  85. package/dist/protocol/dataSources/notionDataSource.js +5 -5
  86. package/dist/protocol/dataSources/properties/propertySchema.d.ts +4 -13
  87. package/dist/protocol/dataSources/properties/propertySchema.js +2 -6
  88. package/dist/protocol/dataSources/resolveDataSourceBinding.d.ts +4 -4
  89. package/dist/protocol/dataSources/resolveDataSourceBinding.js +2 -2
  90. package/dist/protocol/files.d.ts +32 -0
  91. package/dist/protocol/files.js +17 -0
  92. package/dist/protocol/handshake/connect.d.ts +15 -4
  93. package/dist/protocol/handshake/init.d.ts +23 -14
  94. package/dist/protocol/icons.d.ts +32 -0
  95. package/dist/protocol/icons.js +39 -0
  96. package/dist/protocol/index.d.ts +25 -19
  97. package/dist/protocol/index.js +15 -9
  98. package/dist/protocol/manifest/grants.d.ts +48 -0
  99. package/dist/protocol/manifest/grants.js +19 -0
  100. package/dist/protocol/manifest/manifest.d.ts +39 -16
  101. package/dist/protocol/manifest/manifest.js +17 -11
  102. package/dist/protocol/messages/hostToSandbox.d.ts +196 -177
  103. package/dist/protocol/messages/invalidHostMessage.d.ts +2 -0
  104. package/dist/protocol/messages/invalidHostMessage.js +2 -0
  105. package/dist/protocol/messages/invalidSandboxMessage.d.ts +2 -0
  106. package/dist/protocol/messages/invalidSandboxMessage.js +2 -0
  107. package/dist/protocol/messages/sandboxToHost.d.ts +1571 -50
  108. package/dist/protocol/navigation/openExternalUrl.d.ts +2 -2
  109. package/dist/protocol/pages/bridgePage.d.ts +12 -12
  110. package/dist/protocol/pages/bridgePage.js +3 -4
  111. package/dist/protocol/pages/makeBridgePage.d.ts +3 -1
  112. package/dist/protocol/pages/messages/createPage.d.ts +645 -62
  113. package/dist/protocol/pages/messages/createPage.js +27 -13
  114. package/dist/protocol/pages/messages/getPage.d.ts +38 -37
  115. package/dist/protocol/pages/messages/openPage.d.ts +2 -2
  116. package/dist/protocol/pages/messages/updatePage.d.ts +47 -48
  117. package/dist/protocol/pages/messages/updatePage.js +3 -3
  118. package/dist/protocol/pages/pageAppearance.d.ts +9 -28
  119. package/dist/protocol/pages/pageAppearance.js +11 -31
  120. package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +4 -20
  121. package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +2 -10
  122. package/dist/protocol/pages/properties/bridgePagePropertyValue.js +2 -12
  123. package/dist/protocol/users/makeBridgeUser.d.ts +3 -1
  124. package/dist/protocol/users/messages/getUser.d.ts +2 -2
  125. package/dist/protocol/users/messages/listUsers.d.ts +2 -2
  126. package/dist/protocol/utils/errors.d.ts +6 -4
  127. package/dist/protocol/utils/errors.js +3 -3
  128. package/dist/protocol/utils/ids.d.ts +2 -0
  129. package/dist/protocol/utils/ids.js +1 -0
  130. package/dist/protocol/utils/protocolVersion.d.ts +3 -1
  131. package/dist/protocol/utils/protocolVersion.js +5 -1
  132. package/dist/protocol/utils/readRequestId.d.ts +2 -0
  133. package/dist/protocol/utils/readRequestId.js +7 -0
  134. package/dist/react/NotionCustomBlock.d.ts.map +1 -1
  135. package/dist/react/NotionCustomBlock.js +1 -15
  136. package/dist/users/getUser.d.ts.map +1 -1
  137. package/dist/users/getUser.js +2 -1
  138. package/dist/users/listUsers.d.ts.map +1 -1
  139. package/dist/users/listUsers.js +4 -2
  140. package/dist/utils/version.js +1 -1
  141. package/docs/data-sources.md +85 -83
  142. package/docs/deployment.md +4 -5
  143. package/docs/errors.md +47 -5
  144. package/docs/grants.md +127 -0
  145. package/docs/pages.md +105 -56
  146. package/docs/users.md +2 -2
  147. package/package.json +1 -1
  148. package/src/bridge/SandboxBridge.ts +44 -243
  149. package/src/bridge/requests.ts +138 -0
  150. package/src/dataSources/bridge/resolveDataSourceQuery.ts +24 -4
  151. package/src/dataSources/bridge/resolveDataSources.ts +4 -4
  152. package/src/dataSources/createDataSourcePage.ts +5 -1
  153. package/src/dataSources/filters/resolveFilter.ts +12 -3
  154. package/src/dataSources/filters/types.ts +7 -4
  155. package/src/dataSources/properties/resolvePropertyAddress.ts +1 -1
  156. package/src/dataSources/properties/resolvePropertyWriteMapForDataSource.ts +1 -1
  157. package/src/dataSources/resolvePageDataSource.ts +2 -2
  158. package/src/dataSources/subscribeToDataSource.ts +7 -19
  159. package/src/dataSources/types.ts +3 -0
  160. package/src/files/files.ts +5 -0
  161. package/src/files/icons.ts +9 -0
  162. package/src/index.ts +10 -11
  163. package/src/initialization/getInitBindingError.ts +2 -2
  164. package/src/manifest/types.ts +10 -4
  165. package/src/navigation/openExternalUrl.ts +5 -1
  166. package/src/pages/bridge/getPageForDataSource.ts +6 -2
  167. package/src/pages/bridge/sendCreatePageRequest.ts +5 -1
  168. package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +0 -1
  169. package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +0 -8
  170. package/src/pages/bridge/updatePage.ts +29 -9
  171. package/src/pages/createPage.ts +5 -1
  172. package/src/pages/openPage.ts +5 -1
  173. package/src/pages/properties/getPropertyByKey.ts +2 -2
  174. package/src/pages/types.ts +14 -16
  175. package/src/react/NotionCustomBlock.tsx +1 -16
  176. package/src/users/getUser.ts +5 -1
  177. package/src/users/listUsers.ts +9 -4
  178. package/dist/bridge/pendingRequests.d.ts +0 -14
  179. package/dist/bridge/pendingRequests.d.ts.map +0 -1
  180. package/dist/bridge/pendingRequests.js +0 -28
  181. package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +0 -17
  182. package/dist/protocol/dataSources/filters/createdByFilterOperator.js +0 -11
  183. package/dist/protocol/manifest/capabilities.d.ts +0 -37
  184. package/dist/protocol/manifest/capabilities.js +0 -13
  185. package/dist/protocol/pages/properties/fileInput.d.ts +0 -16
  186. package/dist/protocol/pages/properties/fileInput.js +0 -16
  187. package/dist/react/DebugMessageLog.d.ts +0 -2
  188. package/dist/react/DebugMessageLog.d.ts.map +0 -1
  189. package/dist/react/DebugMessageLog.js +0 -23
  190. package/docs/capabilities.md +0 -111
  191. package/src/bridge/pendingRequests.ts +0 -28
  192. package/src/react/DebugMessageLog.tsx +0 -34
@@ -0,0 +1,138 @@
1
+ import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/messages/sandboxToHost.js"
2
+ import type { CustomBlockErrorInfo } from "@notionhq/custom-blocks-protocol/utils/errors.js"
3
+ import * as v from "valibot"
4
+
5
+ export type RequestMessage<Message = SandboxToHostMessage> = Message extends {
6
+ requestId: string
7
+ }
8
+ ? Omit<Message, "requestId">
9
+ : never
10
+
11
+ export type RequestError = { status: "error"; error: CustomBlockErrorInfo }
12
+
13
+ type PendingRequest = {
14
+ receive: (message: unknown) => CustomBlockErrorInfo | undefined
15
+ fail: (error: CustomBlockErrorInfo) => void
16
+ timeout: ReturnType<typeof setTimeout>
17
+ }
18
+
19
+ export type ResponseSchema = v.GenericSchema<
20
+ unknown,
21
+ { type: string; requestId: string; status: "success" } | RequestError
22
+ >
23
+ export type RequestResult<Schema extends ResponseSchema> =
24
+ | Omit<
25
+ Extract<v.InferOutput<Schema>, { status: "success" }>,
26
+ "type" | "requestId"
27
+ >
28
+ | RequestError
29
+
30
+ /** Owns correlation, response validation, and completion for one bridge's requests. */
31
+ export class Requests {
32
+ private nextId = 1
33
+ private isDisposed = false
34
+ private readonly pending = new Map<string, PendingRequest>()
35
+
36
+ constructor(
37
+ private readonly post: (message: SandboxToHostMessage) => void,
38
+ private readonly timeoutMs = 60_000,
39
+ ) {}
40
+
41
+ send<Schema extends ResponseSchema>(
42
+ message: RequestMessage,
43
+ responseSchema: Schema,
44
+ ): Promise<RequestResult<Schema>> {
45
+ if (this.isDisposed) {
46
+ return Promise.resolve({ status: "error", error: disposedError() })
47
+ }
48
+ return new Promise(resolve => {
49
+ const requestId = `custom-block-request-${this.nextId++}`
50
+ const timeout = setTimeout(() => {
51
+ this.fail(requestId, {
52
+ code: "request_timeout",
53
+ message: `The host did not return a result within ${this.timeoutMs} ms. The operation may still complete.`,
54
+ isRetryable: false,
55
+ })
56
+ }, this.timeoutMs)
57
+ this.pending.set(requestId, {
58
+ timeout,
59
+ fail: error => resolve({ status: "error", error }),
60
+ receive: response => {
61
+ const parsed = v.safeParse(responseSchema, response)
62
+ if (!parsed.success) {
63
+ const error: CustomBlockErrorInfo = {
64
+ code: "invalid_host_message",
65
+ message: `The host returned an invalid response to ${message.type}.`,
66
+ isRetryable: false,
67
+ }
68
+ resolve({ status: "error", error })
69
+ return error
70
+ }
71
+ if (isSuccessResponse<Schema>(parsed.output)) {
72
+ const { type: _, requestId: __, ...result } = parsed.output
73
+ resolve(result)
74
+ } else if (parsed.output.status === "error") {
75
+ resolve({ status: "error", error: parsed.output.error })
76
+ }
77
+ },
78
+ })
79
+ try {
80
+ this.post({ ...message, requestId })
81
+ } catch (error) {
82
+ console.warn("[custom-blocks-sdk] could not send request", error)
83
+ this.fail(requestId, {
84
+ code: "request_send_failed",
85
+ message: "The SDK could not send the request to the host.",
86
+ isRetryable: false,
87
+ })
88
+ }
89
+ })
90
+ }
91
+
92
+ receive<Message extends { requestId: string }>(
93
+ message: Message,
94
+ ): CustomBlockErrorInfo | undefined {
95
+ const request = this.finish(message.requestId)
96
+ if (request === undefined) {
97
+ console.warn(
98
+ `[custom-blocks-sdk] result for unknown requestId ${message.requestId}`,
99
+ )
100
+ return
101
+ }
102
+ return request.receive(message)
103
+ }
104
+
105
+ fail(requestId: string, error: CustomBlockErrorInfo) {
106
+ this.finish(requestId)?.fail(error)
107
+ }
108
+
109
+ disposeAll() {
110
+ this.isDisposed = true
111
+ for (const requestId of this.pending.keys()) {
112
+ this.fail(requestId, disposedError())
113
+ }
114
+ }
115
+
116
+ private finish(requestId: string): PendingRequest | undefined {
117
+ const request = this.pending.get(requestId)
118
+ if (request !== undefined) {
119
+ this.pending.delete(requestId)
120
+ clearTimeout(request.timeout)
121
+ }
122
+ return request
123
+ }
124
+ }
125
+
126
+ function disposedError(): CustomBlockErrorInfo {
127
+ return {
128
+ code: "request_disposed",
129
+ message: "The SDK bridge was disposed. The operation may still complete.",
130
+ isRetryable: false,
131
+ }
132
+ }
133
+
134
+ function isSuccessResponse<Schema extends ResponseSchema>(
135
+ response: v.InferOutput<Schema>,
136
+ ): response is Extract<v.InferOutput<Schema>, { status: "success" }> {
137
+ return response.status === "success"
138
+ }
@@ -15,6 +15,7 @@ type DataSourceQueryOptions = {
15
15
  limit?: unknown
16
16
  filter?: unknown
17
17
  sorts?: unknown
18
+ archiveStatus?: unknown
18
19
  }
19
20
 
20
21
  export function resolveDataSourceQuery(args: {
@@ -43,7 +44,7 @@ export function resolveDataSourceQuery(args: {
43
44
  if (dataSource.inaccessible === true) {
44
45
  return { status: "error", error: dataSourceInaccessibleError(key) }
45
46
  }
46
- if (dataSource.collectionPointer === undefined) {
47
+ if (dataSource.dataSourcePointer === undefined) {
47
48
  return {
48
49
  status: "error",
49
50
  error: {
@@ -67,7 +68,7 @@ export function resolveDataSourceQuery(args: {
67
68
  if (
68
69
  (queryOptions?.filter !== undefined ||
69
70
  (Array.isArray(queryOptions?.sorts) && queryOptions.sorts.length > 0)) &&
70
- dataSource.collectionSchema === undefined
71
+ dataSource.dataSourceSchema === undefined
71
72
  ) {
72
73
  return {
73
74
  status: "error",
@@ -100,13 +101,29 @@ export function resolveDataSourceQuery(args: {
100
101
  return { status: "error", error: getInvalidQueryError(sorts.error) }
101
102
  }
102
103
 
104
+ const archiveStatus = queryOptions?.archiveStatus
105
+ if (
106
+ archiveStatus !== undefined &&
107
+ archiveStatus !== "active" &&
108
+ archiveStatus !== "archived" &&
109
+ archiveStatus !== "all"
110
+ ) {
111
+ return {
112
+ status: "error",
113
+ error: getInvalidQueryError(
114
+ 'Data source archiveStatus must be "active", "archived", or "all".',
115
+ ),
116
+ }
117
+ }
118
+
103
119
  return {
104
120
  status: "ok",
105
121
  query: {
106
- dataSourceId: dataSource.collectionPointer.id,
122
+ dataSourceId: dataSource.dataSourcePointer.id,
107
123
  limit: limit.limit,
108
124
  filter: filter.filter,
109
125
  sorts: sorts.sorts,
126
+ ...(archiveStatus !== undefined ? { archive_status: archiveStatus } : {}),
110
127
  },
111
128
  }
112
129
  }
@@ -146,7 +163,7 @@ function resolveDataSourceQueryOptions(
146
163
  const optionsObject = options as Record<string, unknown>
147
164
  if (
148
165
  Object.keys(optionsObject).some(
149
- key => !["limit", "filter", "sorts"].includes(key),
166
+ key => !["limit", "filter", "sorts", "archiveStatus"].includes(key),
150
167
  )
151
168
  ) {
152
169
  return {
@@ -157,6 +174,9 @@ function resolveDataSourceQueryOptions(
157
174
  return {
158
175
  status: "ok",
159
176
  options: {
177
+ archiveStatus: Object.hasOwn(optionsObject, "archiveStatus")
178
+ ? optionsObject.archiveStatus
179
+ : undefined,
160
180
  limit: Object.hasOwn(optionsObject, "limit")
161
181
  ? optionsObject.limit
162
182
  : undefined,
@@ -18,11 +18,11 @@ export function resolveDataSources(args: {
18
18
  ([key, manifestDataSource]) => {
19
19
  const binding = args.dataSourceBindings[key]
20
20
  const collectionProperties =
21
- binding?.collectionSchema?.propertiesById ?? {}
21
+ binding?.dataSourceSchema?.propertiesById ?? {}
22
22
 
23
23
  const resolvedBinding = resolveDataSourceBinding({
24
24
  manifestDataSource,
25
- collectionSchema: binding?.collectionSchema,
25
+ dataSourceSchema: binding?.dataSourceSchema,
26
26
  propertyIdsByKey: binding?.propertyIdsByKey,
27
27
  })
28
28
  const propertyIdsByKey: Record<string, string | undefined> = {}
@@ -33,8 +33,8 @@ export function resolveDataSources(args: {
33
33
 
34
34
  return {
35
35
  key,
36
- collectionPointer: binding?.collectionPointer,
37
- collectionSchema: binding?.collectionSchema,
36
+ dataSourcePointer: binding?.dataSourcePointer,
37
+ dataSourceSchema: binding?.dataSourceSchema,
38
38
  propertyIdsByKey,
39
39
  propertySchemasById: collectionProperties,
40
40
  ...(binding?.inaccessible === true && { inaccessible: true }),
@@ -32,7 +32,11 @@ export async function createDataSourcePage(
32
32
  }
33
33
  const result = await sendCreatePageRequest({
34
34
  bridge,
35
- request: prepared.request,
35
+ request: {
36
+ ...prepared.request,
37
+ ...(payload.icon === undefined ? {} : { icon: payload.icon }),
38
+ ...(payload.cover === undefined ? {} : { cover: payload.cover }),
39
+ },
36
40
  dataSource,
37
41
  })
38
42
  if (result.status === "error") {
@@ -1,6 +1,7 @@
1
1
  import type { BridgeDataSourceFilter } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilter.js"
2
2
  import type { BridgeDataSourceFilterCondition } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilterCondition.js"
3
3
  import { bridgeDataSourceFilterConditionSchema } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilterCondition.js"
4
+ import type { CustomBlockDateFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
4
5
  import { customBlockRelativeDateValueSchema } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
5
6
  import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
6
7
  import * as v from "valibot"
@@ -139,9 +140,17 @@ function parsePropertyFilter(args: {
139
140
  ) {
140
141
  return invalidOperator("number")
141
142
  }
143
+ let dateOperator: CustomBlockDateFilterOperator | undefined
144
+ if ("date" in filter) {
145
+ dateOperator = filter.date
146
+ } else if ("created_time" in filter) {
147
+ dateOperator = filter.created_time
148
+ } else if ("last_edited_time" in filter) {
149
+ dateOperator = filter.last_edited_time
150
+ }
142
151
  if (
143
- "date" in filter &&
144
- !Object.entries(filter.date).every(
152
+ dateOperator !== undefined &&
153
+ !Object.entries(dateOperator).every(
145
154
  ([key, entry]) =>
146
155
  key === "target" ||
147
156
  entry === true ||
@@ -150,7 +159,7 @@ function parsePropertyFilter(args: {
150
159
  isValidIsoDate(entry),
151
160
  )
152
161
  ) {
153
- return invalidOperator("date")
162
+ return invalidOperator(branch)
154
163
  }
155
164
  return { status: "ok", filter }
156
165
  }
@@ -1,6 +1,5 @@
1
1
  import type { CustomBlockCheckboxFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/checkboxFilterOperator.js"
2
2
  import type { CustomBlockContainsFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/containsFilterOperator.js"
3
- import type { CustomBlockCreatedByFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/createdByFilterOperator.js"
4
3
  import type { CustomBlockDateFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
5
4
  import type { CustomBlockNumberFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/numberFilterOperator.js"
6
5
  import type { CustomBlockOptionFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/optionFilterOperator.js"
@@ -11,6 +10,7 @@ import type {
11
10
  import type { CustomBlockRelationFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/relationFilterOperator.js"
12
11
  import type { CustomBlockStatusFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/statusFilterOperator.js"
13
12
  import type { CustomBlockTextFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/textFilterOperator.js"
13
+ import type { CustomBlockTimestampFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/timestampFilterOperator.js"
14
14
  import type { NotionSortDirection } from "@notionhq/custom-blocks-protocol/dataSources/sortDirection.js"
15
15
  import type { ExclusiveUnion } from "../../utils/typeUtils.js"
16
16
 
@@ -35,8 +35,8 @@ export type NotionDataSourceContainsFilterOperator =
35
35
  export type NotionDataSourceDateFilterOperator =
36
36
  ExclusiveUnion<CustomBlockDateFilterOperator>
37
37
 
38
- export type NotionDataSourceCreatedByFilterOperator =
39
- ExclusiveUnion<CustomBlockCreatedByFilterOperator>
38
+ export type NotionDataSourceTimestampFilterOperator =
39
+ ExclusiveUnion<CustomBlockTimestampFilterOperator>
40
40
 
41
41
  export type NotionDataSourcePersonFilterValue = CustomBlockPersonFilterValue
42
42
 
@@ -63,9 +63,12 @@ export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress &
63
63
  | { multi_select: NotionDataSourceContainsFilterOperator }
64
64
  | { status: NotionDataSourceStatusFilterOperator }
65
65
  | { date: NotionDataSourceDateFilterOperator }
66
+ | { created_time: NotionDataSourceTimestampFilterOperator }
67
+ | { last_edited_time: NotionDataSourceTimestampFilterOperator }
66
68
  | { people: NotionDataSourcePeopleFilterOperator }
67
69
  | { relation: NotionDataSourceRelationFilterOperator }
68
- | { created_by: NotionDataSourceCreatedByFilterOperator }
70
+ | { created_by: NotionDataSourcePeopleFilterOperator }
71
+ | { last_edited_by: NotionDataSourcePeopleFilterOperator }
69
72
  >
70
73
 
71
74
  export type NotionDataSourceSort = NotionDataSourcePropertyAddress & {
@@ -46,7 +46,7 @@ export function resolvePropertyAddress(
46
46
  }
47
47
  propertyId = value.propertyId
48
48
  }
49
- const properties = dataSource.collectionSchema?.propertiesById ?? {}
49
+ const properties = dataSource.dataSourceSchema?.propertiesById ?? {}
50
50
  if (!Object.hasOwn(properties, propertyId)) {
51
51
  return {
52
52
  status: "error",
@@ -118,7 +118,7 @@ function resolveWriteIdentifier(args: {
118
118
  : undefined
119
119
  if (
120
120
  propertyId === undefined ||
121
- !dataSource.collectionSchema?.propertiesById[propertyId]
121
+ !dataSource.dataSourceSchema?.propertiesById[propertyId]
122
122
  ) {
123
123
  return {
124
124
  status: "error",
@@ -39,7 +39,7 @@ export function resolvePageDataSource(args: {
39
39
  if (dataSource.inaccessible === true) {
40
40
  return { status: "error", error: dataSourceInaccessibleError(key) }
41
41
  }
42
- if (dataSource.collectionPointer === undefined) {
42
+ if (dataSource.dataSourcePointer === undefined) {
43
43
  return {
44
44
  status: "error",
45
45
  error: {
@@ -52,6 +52,6 @@ export function resolvePageDataSource(args: {
52
52
  return {
53
53
  status: "success",
54
54
  dataSource,
55
- dataSourceId: dataSource.collectionPointer.id,
55
+ dataSourceId: dataSource.dataSourcePointer.id,
56
56
  }
57
57
  }
@@ -9,24 +9,12 @@ import { notifyListener } from "../utils/notifyListener.js"
9
9
  import { resolveDataSourceQuery } from "./bridge/resolveDataSourceQuery.js"
10
10
  import type { SubscribeToDataSourceArgs } from "./types.js"
11
11
 
12
- export function subscribeToDataSource(
13
- args: SubscribeToDataSourceArgs,
14
- ): () => void
15
- /** @deprecated Pass onError in the first argument instead. */
16
- export function subscribeToDataSource(
17
- args: SubscribeToDataSourceArgs,
18
- onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
19
- ): () => void
20
- export function subscribeToDataSource(
21
- {
22
- key,
23
- onSnapshot,
24
- onError: providedOnError,
25
- options: providedOptions = {},
26
- }: SubscribeToDataSourceArgs,
27
- legacyOnError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
28
- ): () => void {
29
- const onError = providedOnError ?? legacyOnError
12
+ export function subscribeToDataSource({
13
+ key,
14
+ onSnapshot,
15
+ onError,
16
+ options: providedOptions = {},
17
+ }: SubscribeToDataSourceArgs): () => void {
30
18
  const options = structuredClone(providedOptions)
31
19
  const bridge = getBridge()
32
20
  const subscriptionId = `data-source:${globalThis.crypto.randomUUID()}`
@@ -82,7 +70,7 @@ export function subscribeToDataSource(
82
70
  }
83
71
  const backingSourceChanged =
84
72
  bindingSignature !== undefined &&
85
- dataSource?.collectionPointer?.id !== nextSource?.collectionPointer?.id
73
+ dataSource?.dataSourcePointer?.id !== nextSource?.dataSourcePointer?.id
86
74
  bindingSignature = signature
87
75
  dataSource = nextSource
88
76
  if (backingSourceChanged) {
@@ -30,6 +30,8 @@ export type DataSourceSnapshot = {
30
30
  hasMore: boolean
31
31
  }
32
32
 
33
+ export type NotionArchiveStatus = "active" | "archived" | "all"
34
+
33
35
  export type DataSourceQueryOptions = {
34
36
  /** Maximum number of rows to request from the host. Defaults to 20. */
35
37
  limit?: number
@@ -37,6 +39,7 @@ export type DataSourceQueryOptions = {
37
39
  filter?: NotionDataSourceFilter
38
40
  /** Optional property sorts. The host applies them in array order. */
39
41
  sorts?: NotionDataSourceSort[]
42
+ archiveStatus?: NotionArchiveStatus
40
43
  }
41
44
 
42
45
  export type SubscribeToDataSourceArgs = {
@@ -0,0 +1,5 @@
1
+ export type {
2
+ BridgeExternalFile as NotionExternalFile,
3
+ BridgeFilePropertyItem as NotionFilePropertyItem,
4
+ BridgeNotionHostedFile as NotionHostedFile,
5
+ } from "@notionhq/custom-blocks-protocol/files.js"
@@ -0,0 +1,9 @@
1
+ // Icons and emoji cross the bridge unchanged. Reusing the inferred types keeps
2
+ // SDK types aligned with validation, including support for future icon fields.
3
+ export type {
4
+ BridgeCustomEmoji as NotionCustomEmoji,
5
+ BridgeEmoji as NotionEmoji,
6
+ BridgeIcon as NotionIcon,
7
+ BridgeIconColor as NotionIconColor,
8
+ BridgeIconName as NotionIconName,
9
+ } from "@notionhq/custom-blocks-protocol/icons.js"
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ export type { CustomBlockPage } from "@notionhq/custom-blocks-protocol/context/c
11
11
  export type { NotionContrastMode } from "@notionhq/custom-blocks-protocol/context/contrast.js"
12
12
  export type { NotionParent } from "@notionhq/custom-blocks-protocol/context/parent.js"
13
13
  export type { NotionTheme } from "@notionhq/custom-blocks-protocol/context/theme.js"
14
- export type { NotionCollectionSchema } from "@notionhq/custom-blocks-protocol/dataSources/collectionSchema.js"
14
+ export type { NotionDataSourceSchema } from "@notionhq/custom-blocks-protocol/dataSources/dataSourceSchema.js"
15
15
  export type {
16
16
  CustomBlockDataSourceResolutionErrorCode,
17
17
  CustomBlockDataSourceResolutionErrorInfo,
@@ -45,15 +45,10 @@ export type {
45
45
  } from "@notionhq/custom-blocks-protocol/handshake/init.js"
46
46
  export { CustomBlockInitializationError } from "@notionhq/custom-blocks-protocol/handshake/init.js"
47
47
  export type {
48
- CustomBlockCapabilityDeclaration,
49
- CustomBlockCapabilityName,
50
- CustomBlockCapabilityResourceName,
51
- } from "@notionhq/custom-blocks-protocol/manifest/capabilities.js"
52
- export type {
53
- ManifestDataSource,
54
- ManifestIcon,
55
- ManifestProperty,
56
- } from "@notionhq/custom-blocks-protocol/manifest/manifest.js"
48
+ CustomBlockGrant,
49
+ CustomBlockGrantAction,
50
+ CustomBlockGrantResourceName,
51
+ } from "@notionhq/custom-blocks-protocol/manifest/grants.js"
57
52
  export type {
58
53
  CustomBlockOpenExternalUrlErrorCode,
59
54
  CustomBlockOpenExternalUrlErrorInfo,
@@ -97,12 +92,16 @@ export { customBlock } from "./context/index.js"
97
92
  export type * from "./dataSources/filters/types.js"
98
93
  export { dataSources } from "./dataSources/index.js"
99
94
  export type * from "./dataSources/types.js"
95
+ export type * from "./files/files.js"
96
+ export type * from "./files/icons.js"
100
97
  export { initCustomBlock } from "./initialization/initCustomBlock.js"
101
98
  export { NotInIframeError } from "./initialization/NotInIframeError.js"
102
99
  export type { CustomBlockInitPayload } from "./initialization/types.js"
103
100
  export type {
104
- CustomBlockManifest,
105
101
  NotionCustomBlockManifest,
102
+ NotionManifestDataSource,
103
+ NotionManifestIcon,
104
+ NotionManifestProperty,
106
105
  } from "./manifest/types.js"
107
106
  export { links } from "./navigation/index.js"
108
107
  export type * from "./navigation/types.js"
@@ -14,8 +14,8 @@ export function getInitBindingError(
14
14
  continue
15
15
  }
16
16
  if (
17
- dataSource?.collectionPointer === undefined ||
18
- dataSource.collectionSchema === undefined
17
+ dataSource?.dataSourcePointer === undefined ||
18
+ dataSource.dataSourceSchema === undefined
19
19
  ) {
20
20
  return {
21
21
  code: "invalid_init_bindings",
@@ -1,7 +1,13 @@
1
- import type { BridgeCustomBlockManifest } from "@notionhq/custom-blocks-protocol/manifest/manifest.js"
1
+ import type {
2
+ BridgeCustomBlockManifest,
3
+ BridgeManifestDataSource,
4
+ BridgeManifestIcon,
5
+ BridgeManifestProperty,
6
+ } from "@notionhq/custom-blocks-protocol/manifest/manifest.js"
2
7
 
3
- /** A block's declared metadata, data sources, and capabilities. */
8
+ /** A block's declared metadata, data sources, and grants. */
4
9
  export type NotionCustomBlockManifest = BridgeCustomBlockManifest
5
10
 
6
- /** @deprecated Use NotionCustomBlockManifest. */
7
- export type CustomBlockManifest = NotionCustomBlockManifest
11
+ export type NotionManifestIcon = BridgeManifestIcon
12
+ export type NotionManifestProperty = BridgeManifestProperty
13
+ export type NotionManifestDataSource = BridgeManifestDataSource
@@ -1,3 +1,4 @@
1
+ import { openExternalUrlResultMessageSchema } from "@notionhq/custom-blocks-protocol/navigation/openExternalUrl.js"
1
2
  import { getBridge } from "../bridge/getBridge.js"
2
3
  import type { OpenExternalUrlResult } from "./types.js"
3
4
 
@@ -5,5 +6,8 @@ import type { OpenExternalUrlResult } from "./types.js"
5
6
  export const openExternalUrl = (
6
7
  url: string,
7
8
  ): Promise<OpenExternalUrlResult> => {
8
- return getBridge().requestOpenExternalUrl({ url })
9
+ return getBridge().request(
10
+ { type: "openExternalUrl", url },
11
+ openExternalUrlResultMessageSchema,
12
+ )
9
13
  }
@@ -1,4 +1,5 @@
1
1
  import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
2
+ import { getPageResultMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/getPage.js"
2
3
  import type { NotionPageId } from "@notionhq/custom-blocks-protocol/utils/ids.js"
3
4
  import type { SandboxBridge } from "../../bridge/SandboxBridge.js"
4
5
  import { makeNotionPage } from "../makeNotionPage.js"
@@ -12,8 +13,11 @@ export async function getPageForDataSource(
12
13
  },
13
14
  ): Promise<GetPageResult> {
14
15
  const { pageId, dataSource } = args
15
- const dataSourceId = dataSource?.collectionPointer?.id
16
- const result = await bridge.requestGetPage({ dataSourceId, pageId })
16
+ const dataSourceId = dataSource?.dataSourcePointer?.id
17
+ const result = await bridge.request(
18
+ { type: "getPage", dataSourceId, pageId },
19
+ getPageResultMessageSchema,
20
+ )
17
21
 
18
22
  if (result.status === "error") {
19
23
  return result
@@ -1,6 +1,7 @@
1
1
  import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
2
2
  import type { BridgeMessagePayload } from "@notionhq/custom-blocks-protocol/messages/messagePayload.js"
3
3
  import type { CreatePageMessage } from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
4
+ import { createPageResultMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
4
5
  import type { SandboxBridge } from "../../bridge/SandboxBridge.js"
5
6
  import { makeNotionPage } from "../makeNotionPage.js"
6
7
  import type { CreatePageResult } from "../types.js"
@@ -11,7 +12,10 @@ export async function sendCreatePageRequest(args: {
11
12
  dataSource: NotionDataSource | undefined
12
13
  }): Promise<CreatePageResult> {
13
14
  const { bridge, request, dataSource } = args
14
- const result = await bridge.requestCreatePage(request)
15
+ const result = await bridge.request(
16
+ { type: "createPage", ...request },
17
+ createPageResultMessageSchema,
18
+ )
15
19
  if (result.status === "error") {
16
20
  return result
17
21
  }
@@ -15,7 +15,6 @@ export function toNotionPageFieldsFromBridgePage(page: BridgePage) {
15
15
  properties,
16
16
  created_by: page.created_by,
17
17
  last_edited_by: page.last_edited_by,
18
- last_visited_time: page.last_visited_time,
19
18
  created_time: page.created_time,
20
19
  last_edited_time: page.last_edited_time,
21
20
  icon: page.icon,
@@ -69,20 +69,12 @@ export function toNotionPagePropertyFromBridgeProperty(
69
69
  type: value.type,
70
70
  last_edited_by: value.last_edited_by,
71
71
  }
72
- case "last_visited_time":
73
- return {
74
- id: value.id,
75
- type: value.type,
76
- last_visited_time: value.last_visited_time,
77
- }
78
72
  case "unique_id":
79
73
  return { id: value.id, type: value.type, unique_id: value.unique_id }
80
74
  case "button":
81
75
  return { id: value.id, type: value.type, button: value.button }
82
76
  case "formula":
83
77
  return { id: value.id, type: value.type, formula: value.formula }
84
- case "location":
85
- return { id: value.id, type: value.type, location: value.location }
86
78
  case "rollup":
87
79
  return { id: value.id, type: value.type, rollup: value.rollup }
88
80
  case "verification":