@notionhq/custom-blocks 0.1.7 → 0.1.8

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 (298) hide show
  1. package/README.md +14 -1
  2. package/bin/notion-custom-blocks/cli.js +6 -0
  3. package/dist/bridge/SandboxBridge.d.ts +3 -9
  4. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  5. package/dist/bridge/SandboxBridge.js +5 -10
  6. package/dist/bridge/dataSources/resolve.d.ts +3 -3
  7. package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
  8. package/dist/bridge/dataSources/resolve.js +1 -1
  9. package/dist/bridge/dataSources/resolveProperty.d.ts +6 -9
  10. package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
  11. package/dist/bridge/dataSources/resolveProperty.js +3 -6
  12. package/dist/bridge/hostState.d.ts +11 -11
  13. package/dist/bridge/hostState.d.ts.map +1 -1
  14. package/dist/bridge/loadManifest.d.ts +2 -2
  15. package/dist/bridge/loadManifest.d.ts.map +1 -1
  16. package/dist/bridge/loadManifest.js +1 -1
  17. package/dist/bridge/sandboxClient.d.ts +1 -1
  18. package/dist/bridge/sandboxClient.d.ts.map +1 -1
  19. package/dist/customBlock.d.ts +8 -8
  20. package/dist/customBlock.d.ts.map +1 -1
  21. package/dist/index.d.ts +24 -25
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +2 -2
  24. package/dist/init.d.ts +8 -8
  25. package/dist/init.d.ts.map +1 -1
  26. package/dist/init.js +1 -1
  27. package/dist/protocol/contrast.d.ts.map +1 -0
  28. package/dist/protocol/dataSources/dataSource.d.ts.map +1 -0
  29. package/dist/protocol/dataSources/dataSourcePage.d.ts.map +1 -0
  30. package/dist/protocol/dataSources/dataSourceValue.d.ts.map +1 -0
  31. package/dist/protocol/dataSources/dateValue.d.ts.map +1 -0
  32. package/dist/{bridge → protocol}/dataSources/errors.d.ts +3 -0
  33. package/dist/protocol/dataSources/errors.d.ts.map +1 -0
  34. package/dist/{bridge → protocol}/dataSources/errors.js +3 -0
  35. package/dist/protocol/dataSources/propertySchema.d.ts.map +1 -0
  36. package/dist/protocol/dataSources/recordPointer.d.ts.map +1 -0
  37. package/dist/protocol/errors.d.ts.map +1 -0
  38. package/dist/protocol/ids.d.ts.map +1 -0
  39. package/dist/protocol/incomingType.d.ts.map +1 -0
  40. package/dist/protocol/index.d.ts +48 -0
  41. package/dist/protocol/index.d.ts.map +1 -0
  42. package/dist/protocol/index.js +47 -0
  43. package/dist/protocol/manifest.d.ts.map +1 -0
  44. package/dist/protocol/messages/connect.d.ts.map +1 -0
  45. package/dist/protocol/messages/contrastModeChanged.d.ts.map +1 -0
  46. package/dist/protocol/messages/createPage.d.ts.map +1 -0
  47. package/dist/protocol/messages/createPageResult.d.ts.map +1 -0
  48. package/dist/protocol/messages/currentUserChanged.d.ts.map +1 -0
  49. package/dist/{bridge → protocol}/messages/dataSourcesChanged.d.ts +1 -1
  50. package/dist/protocol/messages/dataSourcesChanged.d.ts.map +1 -0
  51. package/dist/{bridge → protocol}/messages/dataSourcesChanged.js +1 -1
  52. package/dist/protocol/messages/getPage.d.ts.map +1 -0
  53. package/dist/protocol/messages/getUser.d.ts.map +1 -0
  54. package/dist/{bridge → protocol}/messages/hostToSandbox.d.ts.map +1 -1
  55. package/dist/protocol/messages/init.d.ts.map +1 -0
  56. package/dist/protocol/messages/initResult.d.ts.map +1 -0
  57. package/dist/protocol/messages/invalidHostMessage.d.ts.map +1 -0
  58. package/dist/protocol/messages/invalidSandboxMessage.d.ts.map +1 -0
  59. package/dist/protocol/messages/listUsers.d.ts.map +1 -0
  60. package/dist/protocol/messages/pageChanged.d.ts.map +1 -0
  61. package/dist/protocol/messages/parentChanged.d.ts.map +1 -0
  62. package/dist/protocol/messages/queryDataSource.d.ts.map +1 -0
  63. package/dist/protocol/messages/queryDataSourceResult.d.ts.map +1 -0
  64. package/dist/protocol/messages/resize.d.ts.map +1 -0
  65. package/dist/{bridge → protocol}/messages/sandboxToHost.d.ts.map +1 -1
  66. package/dist/protocol/messages/themeChanged.d.ts.map +1 -0
  67. package/dist/protocol/messages/updatePage.d.ts.map +1 -0
  68. package/dist/protocol/messages/updatePageResult.d.ts.map +1 -0
  69. package/dist/{bridge → protocol}/pages/page.d.ts +1 -1
  70. package/dist/protocol/pages/page.d.ts.map +1 -0
  71. package/dist/protocol/parent.d.ts.map +1 -0
  72. package/dist/protocol/protocolVersion.d.ts +7 -0
  73. package/dist/protocol/protocolVersion.d.ts.map +1 -0
  74. package/dist/protocol/protocolVersion.js +6 -0
  75. package/dist/protocol/theme.d.ts.map +1 -0
  76. package/dist/protocol/users/user.d.ts.map +1 -0
  77. package/dist/react/index.d.ts +1 -1
  78. package/dist/react/index.js +1 -1
  79. package/dist/react/standalonePreview.d.ts.map +1 -1
  80. package/dist/react/standalonePreview.js +2 -2
  81. package/dist/react/useCustomBlockInit.d.ts +1 -1
  82. package/dist/react/useCustomBlockInit.d.ts.map +1 -1
  83. package/dist/react/useDataSource.d.ts +1 -1
  84. package/dist/react/useDataSource.js +1 -1
  85. package/dist/react/useRuntimeState.d.ts +9 -9
  86. package/dist/react/useRuntimeState.d.ts.map +1 -1
  87. package/dist/react/useRuntimeState.js +2 -2
  88. package/dist/types.d.ts +19 -18
  89. package/dist/types.d.ts.map +1 -1
  90. package/dist/version.js +1 -1
  91. package/docs/block-location.md +1 -1
  92. package/docs/data-sources.md +1 -1
  93. package/docs/deployment.md +1 -1
  94. package/docs/errors.md +0 -2
  95. package/docs/lifecycle.md +5 -5
  96. package/docs/pages.md +4 -4
  97. package/package.json +3 -7
  98. package/src/bridge/SandboxBridge.ts +36 -42
  99. package/src/bridge/dataSources/resolve.ts +3 -3
  100. package/src/bridge/dataSources/resolveProperty.ts +14 -20
  101. package/src/bridge/hostState.ts +15 -12
  102. package/src/bridge/loadManifest.ts +5 -2
  103. package/src/bridge/sandboxClient.ts +1 -1
  104. package/src/customBlock.ts +8 -8
  105. package/src/index.ts +26 -30
  106. package/src/init.ts +8 -8
  107. package/src/react/index.ts +1 -1
  108. package/src/react/standalonePreview.ts +5 -2
  109. package/src/react/useCustomBlockInit.ts +1 -1
  110. package/src/react/useDataSource.ts +1 -1
  111. package/src/react/useRuntimeState.ts +9 -9
  112. package/src/types.ts +27 -24
  113. package/HOST.md +0 -224
  114. package/dist/bridge/contrast.d.ts.map +0 -1
  115. package/dist/bridge/dataSources/dataSource.d.ts.map +0 -1
  116. package/dist/bridge/dataSources/dataSourcePage.d.ts.map +0 -1
  117. package/dist/bridge/dataSources/dataSourceValue.d.ts.map +0 -1
  118. package/dist/bridge/dataSources/dateValue.d.ts.map +0 -1
  119. package/dist/bridge/dataSources/errors.d.ts.map +0 -1
  120. package/dist/bridge/dataSources/propertySchema.d.ts.map +0 -1
  121. package/dist/bridge/dataSources/recordPointer.d.ts.map +0 -1
  122. package/dist/bridge/errors.d.ts.map +0 -1
  123. package/dist/bridge/ids.d.ts.map +0 -1
  124. package/dist/bridge/incomingType.d.ts.map +0 -1
  125. package/dist/bridge/manifest.d.ts.map +0 -1
  126. package/dist/bridge/messages/connect.d.ts.map +0 -1
  127. package/dist/bridge/messages/contrastModeChanged.d.ts.map +0 -1
  128. package/dist/bridge/messages/createPage.d.ts.map +0 -1
  129. package/dist/bridge/messages/createPageResult.d.ts.map +0 -1
  130. package/dist/bridge/messages/currentUserChanged.d.ts.map +0 -1
  131. package/dist/bridge/messages/dataSourcesChanged.d.ts.map +0 -1
  132. package/dist/bridge/messages/getPage.d.ts.map +0 -1
  133. package/dist/bridge/messages/getUser.d.ts.map +0 -1
  134. package/dist/bridge/messages/init.d.ts.map +0 -1
  135. package/dist/bridge/messages/initResult.d.ts.map +0 -1
  136. package/dist/bridge/messages/invalidHostMessage.d.ts.map +0 -1
  137. package/dist/bridge/messages/invalidSandboxMessage.d.ts.map +0 -1
  138. package/dist/bridge/messages/listUsers.d.ts.map +0 -1
  139. package/dist/bridge/messages/pageChanged.d.ts.map +0 -1
  140. package/dist/bridge/messages/parentChanged.d.ts.map +0 -1
  141. package/dist/bridge/messages/queryDataSource.d.ts.map +0 -1
  142. package/dist/bridge/messages/queryDataSourceResult.d.ts.map +0 -1
  143. package/dist/bridge/messages/resize.d.ts.map +0 -1
  144. package/dist/bridge/messages/themeChanged.d.ts.map +0 -1
  145. package/dist/bridge/messages/updatePage.d.ts.map +0 -1
  146. package/dist/bridge/messages/updatePageResult.d.ts.map +0 -1
  147. package/dist/bridge/pages/page.d.ts.map +0 -1
  148. package/dist/bridge/parent.d.ts.map +0 -1
  149. package/dist/bridge/theme.d.ts.map +0 -1
  150. package/dist/bridge/users/user.d.ts.map +0 -1
  151. package/dist/host/createCustomBlockHost.d.ts +0 -39
  152. package/dist/host/createCustomBlockHost.d.ts.map +0 -1
  153. package/dist/host/createCustomBlockHost.js +0 -495
  154. package/dist/host/lifecycle/initErrors.d.ts +0 -13
  155. package/dist/host/lifecycle/initErrors.d.ts.map +0 -1
  156. package/dist/host/lifecycle/initErrors.js +0 -152
  157. package/dist/host/lifecycle/protocolVersion.d.ts +0 -2
  158. package/dist/host/lifecycle/protocolVersion.d.ts.map +0 -1
  159. package/dist/host/lifecycle/protocolVersion.js +0 -3
  160. package/dist/host/lifecycle/types.d.ts +0 -28
  161. package/dist/host/lifecycle/types.d.ts.map +0 -1
  162. package/dist/host/lifecycle/types.js +0 -1
  163. package/dist/host/messages/invalidSandboxMessage.d.ts +0 -7
  164. package/dist/host/messages/invalidSandboxMessage.d.ts.map +0 -1
  165. package/dist/host/messages/invalidSandboxMessage.js +0 -21
  166. package/dist/host/messages/types.d.ts +0 -60
  167. package/dist/host/messages/types.d.ts.map +0 -1
  168. package/dist/host/messages/types.js +0 -1
  169. package/dist/host/queries/querySubscriptions.d.ts +0 -20
  170. package/dist/host/queries/querySubscriptions.d.ts.map +0 -1
  171. package/dist/host/queries/querySubscriptions.js +0 -45
  172. package/dist/host/queries/types.d.ts +0 -11
  173. package/dist/host/queries/types.d.ts.map +0 -1
  174. package/dist/host/queries/types.js +0 -1
  175. package/dist/host.d.ts +0 -79
  176. package/dist/host.d.ts.map +0 -1
  177. package/dist/host.js +0 -45
  178. package/src/bridge/contrast.ts +0 -6
  179. package/src/bridge/dataSources/dataSource.ts +0 -63
  180. package/src/bridge/dataSources/dataSourcePage.ts +0 -71
  181. package/src/bridge/dataSources/dataSourceValue.ts +0 -19
  182. package/src/bridge/dataSources/dateValue.ts +0 -96
  183. package/src/bridge/dataSources/errors.ts +0 -14
  184. package/src/bridge/dataSources/propertySchema.ts +0 -186
  185. package/src/bridge/dataSources/recordPointer.ts +0 -13
  186. package/src/bridge/errors.ts +0 -21
  187. package/src/bridge/ids.ts +0 -72
  188. package/src/bridge/incomingType.ts +0 -19
  189. package/src/bridge/manifest.ts +0 -47
  190. package/src/bridge/messages/connect.ts +0 -42
  191. package/src/bridge/messages/contrastModeChanged.ts +0 -12
  192. package/src/bridge/messages/createPage.ts +0 -62
  193. package/src/bridge/messages/createPageResult.ts +0 -52
  194. package/src/bridge/messages/currentUserChanged.ts +0 -14
  195. package/src/bridge/messages/dataSourcesChanged.ts +0 -18
  196. package/src/bridge/messages/getPage.ts +0 -51
  197. package/src/bridge/messages/getUser.ts +0 -49
  198. package/src/bridge/messages/hostToSandbox.ts +0 -39
  199. package/src/bridge/messages/init.ts +0 -99
  200. package/src/bridge/messages/initResult.ts +0 -37
  201. package/src/bridge/messages/invalidHostMessage.ts +0 -16
  202. package/src/bridge/messages/invalidSandboxMessage.ts +0 -18
  203. package/src/bridge/messages/listUsers.ts +0 -50
  204. package/src/bridge/messages/pageChanged.ts +0 -12
  205. package/src/bridge/messages/parentChanged.ts +0 -14
  206. package/src/bridge/messages/queryDataSource.ts +0 -20
  207. package/src/bridge/messages/queryDataSourceResult.ts +0 -45
  208. package/src/bridge/messages/resize.ts +0 -13
  209. package/src/bridge/messages/sandboxToHost.ts +0 -32
  210. package/src/bridge/messages/themeChanged.ts +0 -15
  211. package/src/bridge/messages/updatePage.ts +0 -22
  212. package/src/bridge/messages/updatePageResult.ts +0 -49
  213. package/src/bridge/pages/page.ts +0 -290
  214. package/src/bridge/parent.ts +0 -30
  215. package/src/bridge/theme.ts +0 -5
  216. package/src/bridge/users/user.ts +0 -31
  217. package/src/host/createCustomBlockHost.ts +0 -662
  218. package/src/host/lifecycle/initErrors.ts +0 -165
  219. package/src/host/lifecycle/protocolVersion.ts +0 -3
  220. package/src/host/lifecycle/types.ts +0 -40
  221. package/src/host/messages/invalidSandboxMessage.ts +0 -35
  222. package/src/host/messages/types.ts +0 -67
  223. package/src/host/queries/querySubscriptions.ts +0 -71
  224. package/src/host/queries/types.ts +0 -13
  225. package/src/host.ts +0 -182
  226. /package/dist/{bridge → protocol}/contrast.d.ts +0 -0
  227. /package/dist/{bridge → protocol}/contrast.js +0 -0
  228. /package/dist/{bridge → protocol}/dataSources/dataSource.d.ts +0 -0
  229. /package/dist/{bridge → protocol}/dataSources/dataSource.js +0 -0
  230. /package/dist/{bridge → protocol}/dataSources/dataSourcePage.d.ts +0 -0
  231. /package/dist/{bridge → protocol}/dataSources/dataSourcePage.js +0 -0
  232. /package/dist/{bridge → protocol}/dataSources/dataSourceValue.d.ts +0 -0
  233. /package/dist/{bridge → protocol}/dataSources/dataSourceValue.js +0 -0
  234. /package/dist/{bridge → protocol}/dataSources/dateValue.d.ts +0 -0
  235. /package/dist/{bridge → protocol}/dataSources/dateValue.js +0 -0
  236. /package/dist/{bridge → protocol}/dataSources/propertySchema.d.ts +0 -0
  237. /package/dist/{bridge → protocol}/dataSources/propertySchema.js +0 -0
  238. /package/dist/{bridge → protocol}/dataSources/recordPointer.d.ts +0 -0
  239. /package/dist/{bridge → protocol}/dataSources/recordPointer.js +0 -0
  240. /package/dist/{bridge → protocol}/errors.d.ts +0 -0
  241. /package/dist/{bridge → protocol}/errors.js +0 -0
  242. /package/dist/{bridge → protocol}/ids.d.ts +0 -0
  243. /package/dist/{bridge → protocol}/ids.js +0 -0
  244. /package/dist/{bridge → protocol}/incomingType.d.ts +0 -0
  245. /package/dist/{bridge → protocol}/incomingType.js +0 -0
  246. /package/dist/{bridge → protocol}/manifest.d.ts +0 -0
  247. /package/dist/{bridge → protocol}/manifest.js +0 -0
  248. /package/dist/{bridge → protocol}/messages/connect.d.ts +0 -0
  249. /package/dist/{bridge → protocol}/messages/connect.js +0 -0
  250. /package/dist/{bridge → protocol}/messages/contrastModeChanged.d.ts +0 -0
  251. /package/dist/{bridge → protocol}/messages/contrastModeChanged.js +0 -0
  252. /package/dist/{bridge → protocol}/messages/createPage.d.ts +0 -0
  253. /package/dist/{bridge → protocol}/messages/createPage.js +0 -0
  254. /package/dist/{bridge → protocol}/messages/createPageResult.d.ts +0 -0
  255. /package/dist/{bridge → protocol}/messages/createPageResult.js +0 -0
  256. /package/dist/{bridge → protocol}/messages/currentUserChanged.d.ts +0 -0
  257. /package/dist/{bridge → protocol}/messages/currentUserChanged.js +0 -0
  258. /package/dist/{bridge → protocol}/messages/getPage.d.ts +0 -0
  259. /package/dist/{bridge → protocol}/messages/getPage.js +0 -0
  260. /package/dist/{bridge → protocol}/messages/getUser.d.ts +0 -0
  261. /package/dist/{bridge → protocol}/messages/getUser.js +0 -0
  262. /package/dist/{bridge → protocol}/messages/hostToSandbox.d.ts +0 -0
  263. /package/dist/{bridge → protocol}/messages/hostToSandbox.js +0 -0
  264. /package/dist/{bridge → protocol}/messages/init.d.ts +0 -0
  265. /package/dist/{bridge → protocol}/messages/init.js +0 -0
  266. /package/dist/{bridge → protocol}/messages/initResult.d.ts +0 -0
  267. /package/dist/{bridge → protocol}/messages/initResult.js +0 -0
  268. /package/dist/{bridge → protocol}/messages/invalidHostMessage.d.ts +0 -0
  269. /package/dist/{bridge → protocol}/messages/invalidHostMessage.js +0 -0
  270. /package/dist/{bridge → protocol}/messages/invalidSandboxMessage.d.ts +0 -0
  271. /package/dist/{bridge → protocol}/messages/invalidSandboxMessage.js +0 -0
  272. /package/dist/{bridge → protocol}/messages/listUsers.d.ts +0 -0
  273. /package/dist/{bridge → protocol}/messages/listUsers.js +0 -0
  274. /package/dist/{bridge → protocol}/messages/pageChanged.d.ts +0 -0
  275. /package/dist/{bridge → protocol}/messages/pageChanged.js +0 -0
  276. /package/dist/{bridge → protocol}/messages/parentChanged.d.ts +0 -0
  277. /package/dist/{bridge → protocol}/messages/parentChanged.js +0 -0
  278. /package/dist/{bridge → protocol}/messages/queryDataSource.d.ts +0 -0
  279. /package/dist/{bridge → protocol}/messages/queryDataSource.js +0 -0
  280. /package/dist/{bridge → protocol}/messages/queryDataSourceResult.d.ts +0 -0
  281. /package/dist/{bridge → protocol}/messages/queryDataSourceResult.js +0 -0
  282. /package/dist/{bridge → protocol}/messages/resize.d.ts +0 -0
  283. /package/dist/{bridge → protocol}/messages/resize.js +0 -0
  284. /package/dist/{bridge → protocol}/messages/sandboxToHost.d.ts +0 -0
  285. /package/dist/{bridge → protocol}/messages/sandboxToHost.js +0 -0
  286. /package/dist/{bridge → protocol}/messages/themeChanged.d.ts +0 -0
  287. /package/dist/{bridge → protocol}/messages/themeChanged.js +0 -0
  288. /package/dist/{bridge → protocol}/messages/updatePage.d.ts +0 -0
  289. /package/dist/{bridge → protocol}/messages/updatePage.js +0 -0
  290. /package/dist/{bridge → protocol}/messages/updatePageResult.d.ts +0 -0
  291. /package/dist/{bridge → protocol}/messages/updatePageResult.js +0 -0
  292. /package/dist/{bridge → protocol}/pages/page.js +0 -0
  293. /package/dist/{bridge → protocol}/parent.d.ts +0 -0
  294. /package/dist/{bridge → protocol}/parent.js +0 -0
  295. /package/dist/{bridge → protocol}/theme.d.ts +0 -0
  296. /package/dist/{bridge → protocol}/theme.js +0 -0
  297. /package/dist/{bridge → protocol}/users/user.d.ts +0 -0
  298. /package/dist/{bridge → protocol}/users/user.js +0 -0
@@ -1,14 +0,0 @@
1
- import * as v from "valibot"
2
- import type { CustomBlockErrorInfo } from "../errors.js"
3
-
4
- // The schema accepts any string code. The type lists known codes for
5
- // autocomplete, with an open string fallback for newer senders.
6
- export const customBlockDataSourceResolutionErrorCodeSchema = v.string()
7
-
8
- export type CustomBlockDataSourceResolutionErrorCode =
9
- | "unknown_data_source_key"
10
- | "unmapped_data_source"
11
- | (string & {})
12
-
13
- export type CustomBlockDataSourceResolutionErrorInfo =
14
- CustomBlockErrorInfo<CustomBlockDataSourceResolutionErrorCode>
@@ -1,186 +0,0 @@
1
- import * as v from "valibot"
2
-
3
- /**
4
- * Hex-token identifiers for Notion's named colors. Mirrors the public API's
5
- * `select.options[].color` enum
6
- * (https://developers.notion.com/reference/property-object#select).
7
- */
8
- export const notionPropertyColorSchema = v.picklist([
9
- "default",
10
- "gray",
11
- "brown",
12
- "orange",
13
- "yellow",
14
- "green",
15
- "blue",
16
- "purple",
17
- "pink",
18
- "red",
19
- "gray_background",
20
- "brown_background",
21
- "orange_background",
22
- "yellow_background",
23
- "green_background",
24
- "blue_background",
25
- "purple_background",
26
- "pink_background",
27
- "red_background",
28
- "default_background",
29
- ])
30
-
31
- export type NotionPropertyColor = v.InferOutput<
32
- typeof notionPropertyColorSchema
33
- >
34
-
35
- export const notionPropertyOptionSchema = v.object({
36
- id: v.string(),
37
- name: v.string(),
38
- color: v.optional(notionPropertyColorSchema),
39
- description: v.optional(v.string()),
40
- })
41
-
42
- export type NotionPropertyOption = v.InferOutput<
43
- typeof notionPropertyOptionSchema
44
- >
45
-
46
- export const notionStatusGroupSchema = v.object({
47
- id: v.string(),
48
- name: v.string(),
49
- color: v.optional(notionPropertyColorSchema),
50
- option_ids: v.array(v.string()),
51
- })
52
-
53
- export type NotionStatusGroup = v.InferOutput<typeof notionStatusGroupSchema>
54
-
55
- export const notionDualPropertySchema = v.object({
56
- synced_property_id: v.string(),
57
- synced_property_name: v.string(),
58
- })
59
-
60
- export type NotionDualProperty = v.InferOutput<typeof notionDualPropertySchema>
61
-
62
- const baseProp = v.object({
63
- name: v.string(),
64
- description: v.optional(v.string()),
65
- })
66
-
67
- /**
68
- * Every Notion property type the bridge speaks, in a single readable list.
69
- * Mirrors the Notion public API
70
- * [property object](https://developers.notion.com/reference/property-object)
71
- * type field. Internal-only types (`button`, `verification`,
72
- * `last_visited_time`, `location`) and the four built-ins (`created_time`,
73
- * `last_edited_time`, `created_by`, `last_edited_by`) are included under their
74
- * bridge-native names.
75
- */
76
- export const NOTION_PROPERTY_TYPES = [
77
- "title",
78
- "rich_text",
79
- "number",
80
- "checkbox",
81
- "url",
82
- "email",
83
- "phone_number",
84
- "select",
85
- "multi_select",
86
- "status",
87
- "date",
88
- "people",
89
- "files",
90
- "unique_id",
91
- "relation",
92
- "place",
93
- "formula",
94
- "rollup",
95
- "button",
96
- "verification",
97
- "last_visited_time",
98
- "location",
99
- "created_time",
100
- "last_edited_time",
101
- "created_by",
102
- "last_edited_by",
103
- ] as const
104
-
105
- export const notionPropertyTypeSchema = v.picklist(NOTION_PROPERTY_TYPES)
106
-
107
- /**
108
- * String literal union of every supported Notion property type. Same set as
109
- * the discriminator in `NotionPropertySchema` — split out so the manifest
110
- * can declare expected property types without dragging in the per-type
111
- * payload shapes.
112
- */
113
- export type NotionPropertyType = v.InferOutput<typeof notionPropertyTypeSchema>
114
-
115
- /**
116
- * Per-property schema as exposed by the host over the custom-block bridge.
117
- * The `type` discriminator must be one of {@link NOTION_PROPERTY_TYPES}.
118
- */
119
- export const notionPropertySchemaSchema = v.variant("type", [
120
- v.object({ ...baseProp.entries, type: v.literal("title") }),
121
- v.object({ ...baseProp.entries, type: v.literal("rich_text") }),
122
- v.object({ ...baseProp.entries, type: v.literal("number") }),
123
- v.object({ ...baseProp.entries, type: v.literal("checkbox") }),
124
- v.object({ ...baseProp.entries, type: v.literal("url") }),
125
- v.object({ ...baseProp.entries, type: v.literal("email") }),
126
- v.object({ ...baseProp.entries, type: v.literal("phone_number") }),
127
- v.object({
128
- ...baseProp.entries,
129
- type: v.literal("select"),
130
- options: v.array(notionPropertyOptionSchema),
131
- }),
132
- v.object({
133
- ...baseProp.entries,
134
- type: v.literal("multi_select"),
135
- options: v.array(notionPropertyOptionSchema),
136
- }),
137
- v.object({
138
- ...baseProp.entries,
139
- type: v.literal("status"),
140
- options: v.array(notionPropertyOptionSchema),
141
- groups: v.array(notionStatusGroupSchema),
142
- }),
143
- v.object({ ...baseProp.entries, type: v.literal("date") }),
144
- v.object({ ...baseProp.entries, type: v.literal("people") }),
145
- v.object({ ...baseProp.entries, type: v.literal("files") }),
146
- v.object({ ...baseProp.entries, type: v.literal("unique_id") }),
147
- v.object({
148
- ...baseProp.entries,
149
- type: v.literal("relation"),
150
- data_source_id: v.optional(v.string()),
151
- dual_property: v.optional(notionDualPropertySchema),
152
- }),
153
- v.object({ ...baseProp.entries, type: v.literal("place") }),
154
- v.object({ ...baseProp.entries, type: v.literal("formula") }),
155
- v.object({ ...baseProp.entries, type: v.literal("rollup") }),
156
-
157
- // Internal-only types passed through under their bridge-native names.
158
- v.object({ ...baseProp.entries, type: v.literal("button") }),
159
- v.object({ ...baseProp.entries, type: v.literal("verification") }),
160
- v.object({ ...baseProp.entries, type: v.literal("last_visited_time") }),
161
- v.object({ ...baseProp.entries, type: v.literal("location") }),
162
-
163
- // Synthetic built-ins. The host always emits one of each per data source.
164
- v.object({ ...baseProp.entries, type: v.literal("created_time") }),
165
- v.object({ ...baseProp.entries, type: v.literal("last_edited_time") }),
166
- v.object({ ...baseProp.entries, type: v.literal("created_by") }),
167
- v.object({ ...baseProp.entries, type: v.literal("last_edited_by") }),
168
- ])
169
-
170
- export type NotionPropertySchema = v.InferOutput<
171
- typeof notionPropertySchemaSchema
172
- >
173
-
174
- /**
175
- * The four synthetic built-in property IDs the host always includes in every
176
- * data source's `propertySchemasById` and every row's `propertiesById`.
177
- */
178
- export const NOTION_BUILTIN_PROPERTY_IDS = [
179
- "created_time",
180
- "last_edited_time",
181
- "created_by",
182
- "last_edited_by",
183
- ] as const
184
-
185
- export type NotionBuiltinPropertyId =
186
- (typeof NOTION_BUILTIN_PROPERTY_IDS)[number]
@@ -1,13 +0,0 @@
1
- import * as v from "valibot"
2
-
3
- /**
4
- * A pointer to a record in a database.
5
- */
6
- export const notionRecordPointerSchema = v.object({
7
- id: v.string(),
8
- table: v.string(),
9
- })
10
-
11
- export type NotionRecordPointer = v.InferOutput<
12
- typeof notionRecordPointerSchema
13
- >
@@ -1,21 +0,0 @@
1
- import * as v from "valibot"
2
-
3
- export type CustomBlockErrorCode<KnownCode extends string> =
4
- // Accept a list of known codes for auto-completion.
5
- | KnownCode
6
- // Hosts send this for any errors that are not covered by an error code known by that host.
7
- | "unknown_error"
8
- // Hosts may introduce new codes in the future, so allow any string as a catch-all.
9
- | (string & {})
10
-
11
- export type CustomBlockErrorInfo<TCode extends string = string> = {
12
- code: TCode
13
- message: string
14
- isRetryable: boolean
15
- }
16
-
17
- export const customBlockErrorInfoSchema = v.object({
18
- code: v.string(),
19
- message: v.string(),
20
- isRetryable: v.boolean(),
21
- })
package/src/bridge/ids.ts DELETED
@@ -1,72 +0,0 @@
1
- import * as v from "valibot"
2
-
3
- declare const notionDataSourceIdBrand: unique symbol
4
- declare const notionBlockIdBrand: unique symbol
5
- declare const notionPageIdBrand: unique symbol
6
- declare const notionAgentIdBrand: unique symbol
7
- declare const notionSpaceIdBrand: unique symbol
8
-
9
- /**
10
- * Branded Notion block ID. Host payloads and SDK APIs use plain strings at runtime,
11
- * but the brand keeps block IDs from being accidentally mixed with other IDs in TypeScript.
12
- */
13
- export type NotionBlockId = string & {
14
- readonly [notionBlockIdBrand]: "NotionBlockId"
15
- }
16
-
17
- export const notionBlockIdSchema = v.custom<NotionBlockId>(
18
- value => typeof value === "string",
19
- "Expected a Notion block ID",
20
- )
21
-
22
- /**
23
- * Branded Notion data source ID. Host payloads and SDK APIs use plain strings at runtime,
24
- * but the brand keeps data source IDs from being accidentally mixed with other IDs in TypeScript.
25
- */
26
- export type NotionDataSourceId = string & {
27
- readonly [notionDataSourceIdBrand]: "NotionDataSourceId"
28
- }
29
-
30
- export const notionDataSourceIdSchema = v.custom<NotionDataSourceId>(
31
- value => typeof value === "string",
32
- "Expected a Notion data source ID",
33
- )
34
-
35
- /**
36
- * Branded Notion page ID. Host payloads and SDK APIs use plain strings at runtime,
37
- * but the brand keeps page IDs from being accidentally mixed with other IDs in TypeScript.
38
- */
39
- export type NotionPageId = string & {
40
- readonly [notionPageIdBrand]: "NotionPageId"
41
- }
42
-
43
- export const notionPageIdSchema = v.custom<NotionPageId>(
44
- value => typeof value === "string",
45
- "Expected a Notion page ID",
46
- )
47
-
48
- /**
49
- * Branded Notion agent ID. Agent parents identify the workflow that owns an
50
- * instruction page or one of its blocks.
51
- */
52
- export type NotionAgentId = string & {
53
- readonly [notionAgentIdBrand]: "NotionAgentId"
54
- }
55
-
56
- export const notionAgentIdSchema = v.custom<NotionAgentId>(
57
- value => typeof value === "string",
58
- "Expected a Notion agent ID",
59
- )
60
-
61
- /**
62
- * Branded Notion workspace/space ID. Host payloads and SDK APIs use plain strings at runtime,
63
- * but the brand keeps space IDs from being accidentally mixed with other IDs in TypeScript.
64
- */
65
- export type NotionSpaceId = string & {
66
- readonly [notionSpaceIdBrand]: "NotionSpaceId"
67
- }
68
-
69
- export const notionSpaceIdSchema = v.custom<NotionSpaceId>(
70
- value => typeof value === "string",
71
- "Expected a Notion space ID",
72
- )
@@ -1,19 +0,0 @@
1
- /**
2
- * Reads the `type` field off an inbound bridge message, if any.
3
- *
4
- * Used by both sides of the bridge after the canonical message schema rejects a payload. We still
5
- * want to know what type the sender claimed to be sending so we can (a) avoid NACK loops on
6
- * `invalidHostMessage` / `invalidSandboxMessage` and (b) include the type in the failure reason
7
- * for debugging.
8
- */
9
- export function readIncomingType(data: unknown): string | undefined {
10
- if (
11
- typeof data === "object" &&
12
- data !== null &&
13
- "type" in data &&
14
- typeof data.type === "string"
15
- ) {
16
- return data.type
17
- }
18
- return undefined
19
- }
@@ -1,47 +0,0 @@
1
- import * as v from "valibot"
2
- import { notionPropertyTypeSchema } from "./dataSources/propertySchema.js"
3
-
4
- /**
5
- * Decorative icon attached to a manifest data source. Mirrors the
6
- * `emoji` / `external` icon variants the public Notion API uses, so the host
7
- * can render a recognizable affordance next to the slot in setup UI.
8
- */
9
- export const manifestIconSchema = v.variant("type", [
10
- v.object({
11
- type: v.literal("emoji"),
12
- emoji: v.string(),
13
- }),
14
- v.object({
15
- type: v.literal("external"),
16
- url: v.string(),
17
- }),
18
- ])
19
-
20
- export type ManifestIcon = v.InferOutput<typeof manifestIconSchema>
21
-
22
- export const manifestPropertySchema = v.object({
23
- name: v.string(),
24
- description: v.optional(v.string()),
25
- type: notionPropertyTypeSchema,
26
- })
27
-
28
- export type ManifestProperty = v.InferOutput<typeof manifestPropertySchema>
29
-
30
- export const manifestDataSourceSchema = v.object({
31
- name: v.string(),
32
- description: v.optional(v.string()),
33
- icon: v.optional(manifestIconSchema),
34
- properties: v.optional(v.record(v.string(), manifestPropertySchema), {}),
35
- })
36
-
37
- export type ManifestDataSource = v.InferOutput<typeof manifestDataSourceSchema>
38
-
39
- export const manifestSchema = v.object({
40
- version: v.literal(1),
41
- dataSources: v.record(v.string(), manifestDataSourceSchema),
42
- })
43
-
44
- /**
45
- * Manifest declaring the data sources required by a custom block.
46
- */
47
- export type CustomBlockManifest = v.InferOutput<typeof manifestSchema>
@@ -1,42 +0,0 @@
1
- import * as v from "valibot"
2
- import { customBlockErrorInfoSchema } from "../errors.js"
3
- import { manifestSchema } from "../manifest.js"
4
-
5
- const connectMessageCommonEntries = {
6
- type: v.literal("connect"),
7
- initializationId: v.string(),
8
- /**
9
- * Used to ensure that the host and client are using the same version of the bridge protocol. A
10
- * single host needs to support multiple custom blocks built with different versions of the bridge
11
- * protocol. Increment this number any time a breaking change is made to the bridge protocol.
12
- */
13
- bridgeProtocolVersion: v.number(),
14
- /**
15
- * Semver version of the SDK package that sent this connect message. Should only be used for
16
- * analytics purposes. Business logic should compare against `bridgeProtocolVersion` instead.
17
- */
18
- sdkVersion: v.string(),
19
- }
20
-
21
- /**
22
- * First message the sandbox sends after mount. It identifies the sandbox and starts the bridge
23
- * initialization exchange. The host echoes `initializationId` in its `init` response.
24
- */
25
- export const connectMessageSchema = v.variant("status", [
26
- v.object({
27
- status: v.literal("success"),
28
- /**
29
- * The data sources and settings the custom block expects. Hosts may omit
30
- * this when they already have an authoritative manifest.
31
- */
32
- manifest: v.optional(manifestSchema),
33
- ...connectMessageCommonEntries,
34
- }),
35
- v.object({
36
- status: v.literal("error"),
37
- error: customBlockErrorInfoSchema,
38
- ...connectMessageCommonEntries,
39
- }),
40
- ])
41
-
42
- export type ConnectMessage = v.InferOutput<typeof connectMessageSchema>
@@ -1,12 +0,0 @@
1
- import * as v from "valibot"
2
- import { notionContrastModeSchema } from "../contrast.js"
3
-
4
- /** Message sent by the host when contrast changes after initialization. */
5
- export const contrastModeChangedMessageSchema = v.object({
6
- type: v.literal("contrastModeChanged"),
7
- contrastMode: notionContrastModeSchema,
8
- })
9
-
10
- export type ContrastModeChangedMessage = v.InferOutput<
11
- typeof contrastModeChangedMessageSchema
12
- >
@@ -1,62 +0,0 @@
1
- import * as v from "valibot"
2
- import {
3
- notionBlockIdSchema,
4
- notionDataSourceIdSchema,
5
- notionPageIdSchema,
6
- } from "../ids.js"
7
- import { notionPagePropertyWriteMapSchema } from "../pages/page.js"
8
-
9
- /**
10
- * Describes where the newly created page should be inserted.
11
- * - `start` / `end` (default): prepend / append to the request's `parent`
12
- * page's children.
13
- * - `before` / `after`: insert as a sibling of the anchor block identified by
14
- * `blockId`, using the anchor's own structural parent. The anchor can be
15
- * nested anywhere below the page (inside a toggle, column, callout, etc.).
16
- */
17
- export const notionCreatePagePositionSchema = v.variant("type", [
18
- v.object({ type: v.literal("start") }),
19
- v.object({ type: v.literal("end") }),
20
- v.object({ type: v.literal("before"), blockId: notionBlockIdSchema }),
21
- v.object({ type: v.literal("after"), blockId: notionBlockIdSchema }),
22
- ])
23
-
24
- export type NotionCreatePagePosition = v.InferOutput<
25
- typeof notionCreatePagePositionSchema
26
- >
27
-
28
- /**
29
- * Parent accepted by the outbound `createPage` bridge message.
30
- *
31
- * Mirrors Notion's public API `POST /v1/pages` parent shape: `page_id` for a page-parented child,
32
- * `data_source_id` for a database row. `data_source_id` is the internal collection ID.
33
- *
34
- * The SDK additionally accepts a higher-level `data_source_key` variant that resolves to
35
- * `data_source_id` locally, using the `dataSources` mapping.
36
- */
37
- export const createPageParentSchema = v.variant("type", [
38
- v.object({ type: v.literal("page_id"), page_id: notionPageIdSchema }),
39
- v.object({
40
- type: v.literal("data_source_id"),
41
- data_source_id: notionDataSourceIdSchema,
42
- }),
43
- ])
44
-
45
- export type CreatePageMessageParent = v.InferOutput<
46
- typeof createPageParentSchema
47
- >
48
-
49
- /**
50
- * Message sent by the sandbox to ask the host to create a new page on its behalf.
51
- * The payload mirrors Notion's public `POST /v1/pages` API.
52
- */
53
- export const createPageMessageSchema = v.object({
54
- type: v.literal("createPage"),
55
- requestId: v.string(),
56
- parent: createPageParentSchema,
57
- properties: notionPagePropertyWriteMapSchema,
58
- // TODO(custom-blocks): Add icon and cover once the Notion host supports them for page creation.
59
- position: v.optional(notionCreatePagePositionSchema),
60
- })
61
-
62
- export type CreatePageMessage = v.InferOutput<typeof createPageMessageSchema>
@@ -1,52 +0,0 @@
1
- import * as v from "valibot"
2
- import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
- import { notionPageSchema } from "../pages/page.js"
4
-
5
- // The schema accepts any string code. The type lists known codes for
6
- // autocomplete, with an open string fallback for newer senders.
7
- export const customBlockCreatePageErrorCodeSchema = v.string()
8
-
9
- export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<
10
- | "create_page_failed"
11
- | "invalid_page_parent"
12
- | "page_access_failed"
13
- | "collection_access_failed"
14
- | "unknown_data_source_key"
15
- | "unmapped_data_source"
16
- | "unmapped_property"
17
- | "property_id_mismatch"
18
- | "duplicate_property"
19
- | "invalid_property_value"
20
- >
21
-
22
- export type CustomBlockCreatePageErrorInfo =
23
- CustomBlockErrorInfo<CustomBlockCreatePageErrorCode>
24
-
25
- export const customBlockCreatePageErrorInfoSchema = v.object({
26
- code: customBlockCreatePageErrorCodeSchema,
27
- message: v.string(),
28
- isRetryable: v.boolean(),
29
- })
30
-
31
- /**
32
- * Message sent by the host in response to a sandbox `createPage` request.
33
- */
34
- export const createPageResultMessageSchema = v.variant("status", [
35
- v.object({
36
- type: v.literal("createPageResult"),
37
- requestId: v.string(),
38
- status: v.literal("success"),
39
- /** The newly created page. */
40
- page: notionPageSchema,
41
- }),
42
- v.object({
43
- type: v.literal("createPageResult"),
44
- requestId: v.string(),
45
- status: v.literal("error"),
46
- error: customBlockCreatePageErrorInfoSchema,
47
- }),
48
- ])
49
-
50
- export type CreatePageResultMessage = v.InferOutput<
51
- typeof createPageResultMessageSchema
52
- >
@@ -1,14 +0,0 @@
1
- import * as v from "valibot"
2
- import { notionUserSchema } from "../users/user.js"
3
-
4
- /**
5
- * Sent by the host when the viewing user's profile changes while the block is mounted.
6
- */
7
- export const currentUserChangedMessageSchema = v.object({
8
- type: v.literal("currentUserChanged"),
9
- currentUser: notionUserSchema,
10
- })
11
-
12
- export type CurrentUserChangedMessage = v.InferOutput<
13
- typeof currentUserChangedMessageSchema
14
- >
@@ -1,18 +0,0 @@
1
- import * as v from "valibot"
2
- import { notionDataSourceBindingsSchema } from "../dataSources/dataSource.js"
3
-
4
- /**
5
- * Message sent by the host whenever the custom block's data-source mapping changes (e.g. a key is
6
- * added, removed, or remapped). The SDK replaces its list of configured data sources but keeps any
7
- * in-flight `useDataSource` query state for keys that still exist.
8
- */
9
- export const dataSourcesChangedMessageSchema = v.object({
10
- type: v.literal("dataSourcesChanged"),
11
- dataSources: v.object({
12
- bindings: notionDataSourceBindingsSchema,
13
- }),
14
- })
15
-
16
- export type DataSourcesChangedMessage = v.InferOutput<
17
- typeof dataSourcesChangedMessageSchema
18
- >
@@ -1,51 +0,0 @@
1
- import * as v from "valibot"
2
- import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
- import { notionPageIdSchema } from "../ids.js"
4
- import { notionPageSchema } from "../pages/page.js"
5
-
6
- // The schema accepts any string code. The type lists known codes for
7
- // autocomplete, with an open string fallback for newer senders.
8
- export const customBlockGetPageErrorCodeSchema = v.string()
9
-
10
- export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<
11
- "get_page_failed" | "page_access_failed"
12
- >
13
-
14
- export type CustomBlockGetPageErrorInfo =
15
- CustomBlockErrorInfo<CustomBlockGetPageErrorCode>
16
-
17
- export const customBlockGetPageErrorInfoSchema = v.object({
18
- code: customBlockGetPageErrorCodeSchema,
19
- message: v.string(),
20
- isRetryable: v.boolean(),
21
- })
22
-
23
- /**
24
- * Sandbox -> host: fetch a page by ID.
25
- */
26
- export const getPageMessageSchema = v.object({
27
- type: v.literal("getPage"),
28
- requestId: v.string(),
29
- pageId: notionPageIdSchema,
30
- })
31
-
32
- export type GetPageMessage = v.InferOutput<typeof getPageMessageSchema>
33
-
34
- export const getPageResultMessageSchema = v.variant("status", [
35
- v.object({
36
- type: v.literal("getPageResult"),
37
- requestId: v.string(),
38
- status: v.literal("success"),
39
- page: notionPageSchema,
40
- }),
41
- v.object({
42
- type: v.literal("getPageResult"),
43
- requestId: v.string(),
44
- status: v.literal("error"),
45
- error: customBlockGetPageErrorInfoSchema,
46
- }),
47
- ])
48
-
49
- export type GetPageResultMessage = v.InferOutput<
50
- typeof getPageResultMessageSchema
51
- >
@@ -1,49 +0,0 @@
1
- import * as v from "valibot"
2
- import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js"
3
- import { notionUserSchema } from "../users/user.js"
4
-
5
- // The schema accepts any string code. The type lists known codes for
6
- // autocomplete, with an open string fallback for newer senders.
7
- export const customBlockGetUserErrorCodeSchema = v.string()
8
-
9
- export type CustomBlockGetUserErrorCode =
10
- CustomBlockErrorCode<"get_user_failed">
11
-
12
- export type CustomBlockGetUserErrorInfo =
13
- CustomBlockErrorInfo<CustomBlockGetUserErrorCode>
14
-
15
- export const customBlockGetUserErrorInfoSchema = v.object({
16
- code: customBlockGetUserErrorCodeSchema,
17
- message: v.string(),
18
- isRetryable: v.boolean(),
19
- })
20
-
21
- /**
22
- * Sandbox -> host: fetch a user by ID.
23
- */
24
- export const getUserMessageSchema = v.object({
25
- type: v.literal("getUser"),
26
- requestId: v.string(),
27
- userId: v.string(),
28
- })
29
-
30
- export type GetUserMessage = v.InferOutput<typeof getUserMessageSchema>
31
-
32
- export const getUserResultMessageSchema = v.variant("status", [
33
- v.object({
34
- type: v.literal("getUserResult"),
35
- requestId: v.string(),
36
- status: v.literal("success"),
37
- user: notionUserSchema,
38
- }),
39
- v.object({
40
- type: v.literal("getUserResult"),
41
- requestId: v.string(),
42
- status: v.literal("error"),
43
- error: customBlockGetUserErrorInfoSchema,
44
- }),
45
- ])
46
-
47
- export type GetUserResultMessage = v.InferOutput<
48
- typeof getUserResultMessageSchema
49
- >