@notionhq/custom-blocks 0.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOST.md +171 -0
- package/README.md +57 -0
- package/bin/cli/attach.js +180 -0
- package/bin/cli/cli.js +248 -0
- package/bin/cli/create.js +106 -0
- package/bin/cli/datasources.js +255 -0
- package/bin/cli/deploy.js +109 -0
- package/bin/cli/ids.js +13 -0
- package/bin/cli/ntn.js +95 -0
- package/bin/cli/pullData.js +76 -0
- package/bin/cli/pullManifest.js +158 -0
- package/bin/cli/target.js +95 -0
- package/bin/src/bridge/dataSources/propertySchema.js +148 -0
- package/bin/src/bridge/manifest.js +40 -0
- package/dist/autoResize.d.ts +4 -0
- package/dist/autoResize.d.ts.map +1 -0
- package/dist/autoResize.js +71 -0
- package/dist/bridge/SandboxBridge.d.ts +92 -0
- package/dist/bridge/SandboxBridge.d.ts.map +1 -0
- package/dist/bridge/SandboxBridge.js +718 -0
- package/dist/bridge/dataSources/dataSource.d.ts +732 -0
- package/dist/bridge/dataSources/dataSource.d.ts.map +1 -0
- package/dist/bridge/dataSources/dataSource.js +37 -0
- package/dist/bridge/dataSources/dataSourcePage.d.ts +118 -0
- package/dist/bridge/dataSources/dataSourcePage.d.ts.map +1 -0
- package/dist/bridge/dataSources/dataSourcePage.js +14 -0
- package/dist/bridge/dataSources/dataSourceValue.d.ts +67 -0
- package/dist/bridge/dataSources/dataSourceValue.d.ts.map +1 -0
- package/dist/bridge/dataSources/dataSourceValue.js +14 -0
- package/dist/bridge/dataSources/dateValue.d.ts +158 -0
- package/dist/bridge/dataSources/dateValue.d.ts.map +1 -0
- package/dist/bridge/dataSources/dateValue.js +59 -0
- package/dist/bridge/dataSources/errors.d.ts +6 -0
- package/dist/bridge/dataSources/errors.d.ts.map +1 -0
- package/dist/bridge/dataSources/errors.js +4 -0
- package/dist/bridge/dataSources/propertySchema.d.ts +191 -0
- package/dist/bridge/dataSources/propertySchema.d.ts.map +1 -0
- package/dist/bridge/dataSources/propertySchema.js +148 -0
- package/dist/bridge/dataSources/recordPointer.d.ts +10 -0
- package/dist/bridge/dataSources/recordPointer.d.ts.map +1 -0
- package/dist/bridge/dataSources/recordPointer.js +8 -0
- package/dist/bridge/dataSources/resolve.d.ts +22 -0
- package/dist/bridge/dataSources/resolve.d.ts.map +1 -0
- package/dist/bridge/dataSources/resolve.js +65 -0
- package/dist/bridge/dataSources/resolveProperty.d.ts +41 -0
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -0
- package/dist/bridge/dataSources/resolveProperty.js +73 -0
- package/dist/bridge/errors.d.ts +12 -0
- package/dist/bridge/errors.d.ts.map +1 -0
- package/dist/bridge/errors.js +6 -0
- package/dist/bridge/hostState.d.ts +65 -0
- package/dist/bridge/hostState.d.ts.map +1 -0
- package/dist/bridge/hostState.js +65 -0
- package/dist/bridge/ids.d.ts +39 -0
- package/dist/bridge/ids.d.ts.map +1 -0
- package/dist/bridge/ids.js +5 -0
- package/dist/bridge/incomingType.d.ts +10 -0
- package/dist/bridge/incomingType.d.ts.map +1 -0
- package/dist/bridge/incomingType.js +17 -0
- package/dist/bridge/loadManifest.d.ts +25 -0
- package/dist/bridge/loadManifest.d.ts.map +1 -0
- package/dist/bridge/loadManifest.js +68 -0
- package/dist/bridge/manifest.d.ts +66 -0
- package/dist/bridge/manifest.d.ts.map +1 -0
- package/dist/bridge/manifest.js +40 -0
- package/dist/bridge/messages/createPage.d.ts +225 -0
- package/dist/bridge/messages/createPage.d.ts.map +1 -0
- package/dist/bridge/messages/createPage.js +46 -0
- package/dist/bridge/messages/createPageResult.d.ts +211 -0
- package/dist/bridge/messages/createPageResult.d.ts.map +1 -0
- package/dist/bridge/messages/createPageResult.js +28 -0
- package/dist/bridge/messages/currentUserChanged.d.ts +19 -0
- package/dist/bridge/messages/currentUserChanged.d.ts.map +1 -0
- package/dist/bridge/messages/currentUserChanged.js +9 -0
- package/dist/bridge/messages/dataSourcesChanged.d.ts +158 -0
- package/dist/bridge/messages/dataSourcesChanged.d.ts.map +1 -0
- package/dist/bridge/messages/dataSourcesChanged.js +13 -0
- package/dist/bridge/messages/getPage.d.ts +216 -0
- package/dist/bridge/messages/getPage.d.ts.map +1 -0
- package/dist/bridge/messages/getPage.js +33 -0
- package/dist/bridge/messages/getUser.d.ts +45 -0
- package/dist/bridge/messages/getUser.d.ts.map +1 -0
- package/dist/bridge/messages/getUser.js +32 -0
- package/dist/bridge/messages/hostToSandbox.d.ts +1089 -0
- package/dist/bridge/messages/hostToSandbox.d.ts.map +1 -0
- package/dist/bridge/messages/hostToSandbox.js +32 -0
- package/dist/bridge/messages/init.d.ts +209 -0
- package/dist/bridge/messages/init.d.ts.map +1 -0
- package/dist/bridge/messages/init.js +47 -0
- package/dist/bridge/messages/invalidHostMessage.d.ts +15 -0
- package/dist/bridge/messages/invalidHostMessage.d.ts.map +1 -0
- package/dist/bridge/messages/invalidHostMessage.js +13 -0
- package/dist/bridge/messages/invalidSandboxMessage.d.ts +15 -0
- package/dist/bridge/messages/invalidSandboxMessage.d.ts.map +1 -0
- package/dist/bridge/messages/invalidSandboxMessage.js +13 -0
- package/dist/bridge/messages/listUsers.d.ts +53 -0
- package/dist/bridge/messages/listUsers.d.ts.map +1 -0
- package/dist/bridge/messages/listUsers.js +33 -0
- package/dist/bridge/messages/pageChanged.d.ts +12 -0
- package/dist/bridge/messages/pageChanged.d.ts.map +1 -0
- package/dist/bridge/messages/pageChanged.js +9 -0
- package/dist/bridge/messages/parentChanged.d.ts +22 -0
- package/dist/bridge/messages/parentChanged.d.ts.map +1 -0
- package/dist/bridge/messages/parentChanged.js +9 -0
- package/dist/bridge/messages/queryDataSource.d.ts +20 -0
- package/dist/bridge/messages/queryDataSource.d.ts.map +1 -0
- package/dist/bridge/messages/queryDataSource.js +19 -0
- package/dist/bridge/messages/queryDataSourceResult.d.ts +90 -0
- package/dist/bridge/messages/queryDataSourceResult.d.ts.map +1 -0
- package/dist/bridge/messages/queryDataSourceResult.js +21 -0
- package/dist/bridge/messages/ready.d.ts +45 -0
- package/dist/bridge/messages/ready.d.ts.map +1 -0
- package/dist/bridge/messages/ready.js +37 -0
- package/dist/bridge/messages/resize.d.ts +12 -0
- package/dist/bridge/messages/resize.d.ts.map +1 -0
- package/dist/bridge/messages/resize.js +10 -0
- package/dist/bridge/messages/sandboxToHost.d.ts +410 -0
- package/dist/bridge/messages/sandboxToHost.d.ts.map +1 -0
- package/dist/bridge/messages/sandboxToHost.js +25 -0
- package/dist/bridge/messages/themeChanged.d.ts +11 -0
- package/dist/bridge/messages/themeChanged.d.ts.map +1 -0
- package/dist/bridge/messages/themeChanged.js +10 -0
- package/dist/bridge/messages/updatePage.d.ts +171 -0
- package/dist/bridge/messages/updatePage.d.ts.map +1 -0
- package/dist/bridge/messages/updatePage.js +15 -0
- package/dist/bridge/messages/updatePageResult.d.ts +210 -0
- package/dist/bridge/messages/updatePageResult.d.ts.map +1 -0
- package/dist/bridge/messages/updatePageResult.js +27 -0
- package/dist/bridge/pages/page.d.ts +600 -0
- package/dist/bridge/pages/page.d.ts.map +1 -0
- package/dist/bridge/pages/page.js +217 -0
- package/dist/bridge/parent.d.ts +25 -0
- package/dist/bridge/parent.d.ts.map +1 -0
- package/dist/bridge/parent.js +11 -0
- package/dist/bridge/pendingRequests.d.ts +14 -0
- package/dist/bridge/pendingRequests.d.ts.map +1 -0
- package/dist/bridge/pendingRequests.js +27 -0
- package/dist/bridge/sandboxClient.d.ts +63 -0
- package/dist/bridge/sandboxClient.d.ts.map +1 -0
- package/dist/bridge/sandboxClient.js +92 -0
- package/dist/bridge/theme.d.ts +4 -0
- package/dist/bridge/theme.d.ts.map +1 -0
- package/dist/bridge/theme.js +2 -0
- package/dist/bridge/users/user.d.ts +36 -0
- package/dist/bridge/users/user.d.ts.map +1 -0
- package/dist/bridge/users/user.js +19 -0
- package/dist/customBlock.d.ts +36 -0
- package/dist/customBlock.d.ts.map +1 -0
- package/dist/customBlock.js +65 -0
- package/dist/host/createCustomBlockHost.d.ts +34 -0
- package/dist/host/createCustomBlockHost.d.ts.map +1 -0
- package/dist/host/createCustomBlockHost.js +278 -0
- package/dist/host/lifecycle/initErrors.d.ts +10 -0
- package/dist/host/lifecycle/initErrors.d.ts.map +1 -0
- package/dist/host/lifecycle/initErrors.js +123 -0
- package/dist/host/lifecycle/ready.d.ts +8 -0
- package/dist/host/lifecycle/ready.d.ts.map +1 -0
- package/dist/host/lifecycle/ready.js +24 -0
- package/dist/host/lifecycle/types.d.ts +24 -0
- package/dist/host/lifecycle/types.d.ts.map +1 -0
- package/dist/host/lifecycle/types.js +1 -0
- package/dist/host/messages/invalidSandboxMessage.d.ts +7 -0
- package/dist/host/messages/invalidSandboxMessage.d.ts.map +1 -0
- package/dist/host/messages/invalidSandboxMessage.js +24 -0
- package/dist/host/messages/types.d.ts +60 -0
- package/dist/host/messages/types.d.ts.map +1 -0
- package/dist/host/messages/types.js +1 -0
- package/dist/host/queries/querySubscriptions.d.ts +20 -0
- package/dist/host/queries/querySubscriptions.d.ts.map +1 -0
- package/dist/host/queries/querySubscriptions.js +29 -0
- package/dist/host/queries/types.d.ts +9 -0
- package/dist/host/queries/types.d.ts.map +1 -0
- package/dist/host/queries/types.js +1 -0
- package/dist/host.d.ts +73 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +42 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/init.d.ts +53 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +87 -0
- package/dist/react/DebugMessageLog.d.ts +2 -0
- package/dist/react/DebugMessageLog.d.ts.map +1 -0
- package/dist/react/DebugMessageLog.js +22 -0
- package/dist/react/NotionCustomBlock.css +110 -0
- package/dist/react/NotionCustomBlock.d.ts +50 -0
- package/dist/react/NotionCustomBlock.d.ts.map +1 -0
- package/dist/react/NotionCustomBlock.js +81 -0
- package/dist/react/index.d.ts +14 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +13 -0
- package/dist/react/standalonePreview.d.ts +2 -0
- package/dist/react/standalonePreview.d.ts.map +1 -0
- package/dist/react/standalonePreview.js +26 -0
- package/dist/react/useCustomBlockAutoResize.d.ts +30 -0
- package/dist/react/useCustomBlockAutoResize.d.ts.map +1 -0
- package/dist/react/useCustomBlockAutoResize.js +35 -0
- package/dist/react/useCustomBlockInit.d.ts +43 -0
- package/dist/react/useCustomBlockInit.d.ts.map +1 -0
- package/dist/react/useCustomBlockInit.js +60 -0
- package/dist/react/useDataSource.d.ts +13 -0
- package/dist/react/useDataSource.d.ts.map +1 -0
- package/dist/react/useDataSource.js +37 -0
- package/dist/react/useHostState.d.ts +2 -0
- package/dist/react/useHostState.d.ts.map +1 -0
- package/dist/react/useHostState.js +5 -0
- package/dist/react/useRuntimeState.d.ts +66 -0
- package/dist/react/useRuntimeState.d.ts.map +1 -0
- package/dist/react/useRuntimeState.js +73 -0
- package/dist/types.d.ts +154 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +10 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/docs/block-location.md +83 -0
- package/docs/data-sources.md +186 -0
- package/docs/lifecycle.md +172 -0
- package/docs/manifest.md +42 -0
- package/docs/pages.md +143 -0
- package/docs/users.md +92 -0
- package/package.json +69 -0
- package/src/autoResize.ts +84 -0
- package/src/bridge/SandboxBridge.ts +921 -0
- package/src/bridge/dataSources/dataSource.ts +63 -0
- package/src/bridge/dataSources/dataSourcePage.ts +71 -0
- package/src/bridge/dataSources/dataSourceValue.ts +19 -0
- package/src/bridge/dataSources/dateValue.ts +96 -0
- package/src/bridge/dataSources/errors.ts +14 -0
- package/src/bridge/dataSources/propertySchema.ts +186 -0
- package/src/bridge/dataSources/recordPointer.ts +13 -0
- package/src/bridge/dataSources/resolve.ts +99 -0
- package/src/bridge/dataSources/resolveProperty.ts +130 -0
- package/src/bridge/errors.ts +13 -0
- package/src/bridge/hostState.ts +154 -0
- package/src/bridge/ids.ts +58 -0
- package/src/bridge/incomingType.ts +19 -0
- package/src/bridge/loadManifest.ts +89 -0
- package/src/bridge/manifest.ts +53 -0
- package/src/bridge/messages/createPage.ts +67 -0
- package/src/bridge/messages/createPageResult.ts +52 -0
- package/src/bridge/messages/currentUserChanged.ts +14 -0
- package/src/bridge/messages/dataSourcesChanged.ts +18 -0
- package/src/bridge/messages/getPage.ts +52 -0
- package/src/bridge/messages/getUser.ts +48 -0
- package/src/bridge/messages/hostToSandbox.ts +37 -0
- package/src/bridge/messages/init.ts +81 -0
- package/src/bridge/messages/invalidHostMessage.ts +16 -0
- package/src/bridge/messages/invalidSandboxMessage.ts +18 -0
- package/src/bridge/messages/listUsers.ts +49 -0
- package/src/bridge/messages/pageChanged.ts +12 -0
- package/src/bridge/messages/parentChanged.ts +14 -0
- package/src/bridge/messages/queryDataSource.ts +24 -0
- package/src/bridge/messages/queryDataSourceResult.ts +38 -0
- package/src/bridge/messages/ready.ts +41 -0
- package/src/bridge/messages/resize.ts +13 -0
- package/src/bridge/messages/sandboxToHost.ts +30 -0
- package/src/bridge/messages/themeChanged.ts +15 -0
- package/src/bridge/messages/updatePage.ts +22 -0
- package/src/bridge/messages/updatePageResult.ts +49 -0
- package/src/bridge/pages/page.ts +281 -0
- package/src/bridge/parent.ts +27 -0
- package/src/bridge/pendingRequests.ts +28 -0
- package/src/bridge/sandboxClient.ts +137 -0
- package/src/bridge/theme.ts +5 -0
- package/src/bridge/users/user.ts +31 -0
- package/src/css.d.ts +1 -0
- package/src/customBlock.ts +102 -0
- package/src/host/createCustomBlockHost.ts +392 -0
- package/src/host/lifecycle/initErrors.ts +132 -0
- package/src/host/lifecycle/ready.ts +36 -0
- package/src/host/lifecycle/types.ts +28 -0
- package/src/host/messages/invalidSandboxMessage.ts +38 -0
- package/src/host/messages/types.ts +67 -0
- package/src/host/queries/querySubscriptions.ts +52 -0
- package/src/host/queries/types.ts +16 -0
- package/src/host.ts +167 -0
- package/src/index.ts +115 -0
- package/src/init.ts +143 -0
- package/src/react/DebugMessageLog.tsx +30 -0
- package/src/react/NotionCustomBlock.css +110 -0
- package/src/react/NotionCustomBlock.tsx +151 -0
- package/src/react/index.ts +28 -0
- package/src/react/standalonePreview.ts +28 -0
- package/src/react/useCustomBlockAutoResize.ts +46 -0
- package/src/react/useCustomBlockInit.ts +91 -0
- package/src/react/useDataSource.ts +47 -0
- package/src/react/useHostState.ts +9 -0
- package/src/react/useRuntimeState.ts +85 -0
- package/src/types.ts +175 -0
- package/src/utils.ts +13 -0
- package/src/version.ts +8 -0
- package/vite-plugin/index.d.ts +46 -0
- package/vite-plugin/index.js +115 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { notionDataSourceBindingsSchema } from "../dataSources/dataSource.js"
|
|
3
|
+
import type { CustomBlockErrorInfo } from "../errors.js"
|
|
4
|
+
import { notionBlockIdSchema } from "../ids.js"
|
|
5
|
+
import { customBlockPageSchema } from "../pages/page.js"
|
|
6
|
+
import { notionParentSchema } from "../parent.js"
|
|
7
|
+
import { notionThemeSchema } from "../theme.js"
|
|
8
|
+
import { notionUserSchema } from "../users/user.js"
|
|
9
|
+
|
|
10
|
+
// The schema accepts any string code. The type lists known codes for
|
|
11
|
+
// autocomplete, with an open string fallback for newer senders.
|
|
12
|
+
export const customBlockInitErrorCodeSchema = v.string()
|
|
13
|
+
|
|
14
|
+
export type CustomBlockInitErrorCode =
|
|
15
|
+
| "no_ready"
|
|
16
|
+
| "invalid_ready"
|
|
17
|
+
| "manifest_unavailable"
|
|
18
|
+
| "manifest_invalid"
|
|
19
|
+
| "invalid_protocol_version"
|
|
20
|
+
| "unsupported_protocol_version"
|
|
21
|
+
| "context_unavailable"
|
|
22
|
+
| "current_user_unavailable"
|
|
23
|
+
| "missing_data_source_binding"
|
|
24
|
+
| "data_source_unavailable"
|
|
25
|
+
| "missing_property_binding"
|
|
26
|
+
| "invalid_property_binding"
|
|
27
|
+
| "not_in_iframe"
|
|
28
|
+
| "init_timeout"
|
|
29
|
+
| "unknown_error"
|
|
30
|
+
| (string & {})
|
|
31
|
+
|
|
32
|
+
export type CustomBlockInitErrorInfo =
|
|
33
|
+
CustomBlockErrorInfo<CustomBlockInitErrorCode>
|
|
34
|
+
|
|
35
|
+
export const customBlockInitErrorInfoSchema = v.object({
|
|
36
|
+
code: customBlockInitErrorCodeSchema,
|
|
37
|
+
message: v.string(),
|
|
38
|
+
isRetryable: v.boolean(),
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export class CustomBlockInitError
|
|
42
|
+
extends Error
|
|
43
|
+
implements CustomBlockErrorInfo
|
|
44
|
+
{
|
|
45
|
+
constructor(error: CustomBlockInitErrorInfo) {
|
|
46
|
+
super(error.message)
|
|
47
|
+
this.name = "CustomBlockInitError"
|
|
48
|
+
this.code = error.code
|
|
49
|
+
this.isRetryable = error.isRetryable
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
code: CustomBlockInitErrorCode
|
|
53
|
+
isRetryable: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Initialization message sent by the host to the sandbox exactly once, in response to the
|
|
58
|
+
* sandbox's `ready` message. After init, live updates flow through narrower messages
|
|
59
|
+
* (`themeChanged`, `parentChanged`, `pageChanged`, `dataSourcesChanged`).
|
|
60
|
+
*/
|
|
61
|
+
export const initMessageSchema = v.variant("status", [
|
|
62
|
+
v.object({
|
|
63
|
+
type: v.literal("init"),
|
|
64
|
+
status: v.literal("success"),
|
|
65
|
+
theme: notionThemeSchema,
|
|
66
|
+
blockId: notionBlockIdSchema,
|
|
67
|
+
parent: notionParentSchema,
|
|
68
|
+
page: customBlockPageSchema,
|
|
69
|
+
dataSources: v.object({
|
|
70
|
+
bindings: notionDataSourceBindingsSchema,
|
|
71
|
+
}),
|
|
72
|
+
currentUser: notionUserSchema,
|
|
73
|
+
}),
|
|
74
|
+
v.object({
|
|
75
|
+
type: v.literal("init"),
|
|
76
|
+
status: v.literal("error"),
|
|
77
|
+
error: customBlockInitErrorInfoSchema,
|
|
78
|
+
}),
|
|
79
|
+
])
|
|
80
|
+
|
|
81
|
+
export type InitMessage = v.InferOutput<typeof initMessageSchema>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sent by the sandbox back to the host when an inbound host-to-sandbox message could not be parsed
|
|
5
|
+
* (unknown `type`, schema mismatch, etc.). The host should never reply to an `invalidHostMessage`
|
|
6
|
+
* with another bridge error message.
|
|
7
|
+
*/
|
|
8
|
+
export const invalidHostMessageSchema = v.object({
|
|
9
|
+
type: v.literal("invalidHostMessage"),
|
|
10
|
+
/**
|
|
11
|
+
* A human-readable string intended for sandbox-side logging. It has no structured contract.
|
|
12
|
+
*/
|
|
13
|
+
reason: v.string(),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export type InvalidHostMessage = v.InferOutput<typeof invalidHostMessageSchema>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sent by the host back to the sandbox when an inbound sandbox-to-host message could not be parsed
|
|
5
|
+
* (unknown `type`, schema mismatch, etc.). The sandbox should never reply to an
|
|
6
|
+
* `invalidSandboxMessage` with another bridge error message.
|
|
7
|
+
*/
|
|
8
|
+
export const invalidSandboxMessageSchema = v.object({
|
|
9
|
+
type: v.literal("invalidSandboxMessage"),
|
|
10
|
+
/**
|
|
11
|
+
* A human-readable string intended for sandbox-side logging. It has no structured contract.
|
|
12
|
+
*/
|
|
13
|
+
reason: v.string(),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export type InvalidSandboxMessage = v.InferOutput<
|
|
17
|
+
typeof invalidSandboxMessageSchema
|
|
18
|
+
>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import type { CustomBlockErrorInfo } from "../errors.js"
|
|
3
|
+
import { notionUserListSchema } 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 customBlockListUsersErrorCodeSchema = v.string()
|
|
8
|
+
|
|
9
|
+
export type CustomBlockListUsersErrorCode = "list_users_failed" | (string & {})
|
|
10
|
+
|
|
11
|
+
export type CustomBlockListUsersErrorInfo =
|
|
12
|
+
CustomBlockErrorInfo<CustomBlockListUsersErrorCode>
|
|
13
|
+
|
|
14
|
+
export const customBlockListUsersErrorInfoSchema = v.object({
|
|
15
|
+
code: customBlockListUsersErrorCodeSchema,
|
|
16
|
+
message: v.string(),
|
|
17
|
+
isRetryable: v.boolean(),
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Sandbox -> host: list users visible in the custom block's workspace.
|
|
22
|
+
*/
|
|
23
|
+
export const listUsersMessageSchema = v.object({
|
|
24
|
+
type: v.literal("listUsers"),
|
|
25
|
+
requestId: v.string(),
|
|
26
|
+
startCursor: v.optional(v.string()),
|
|
27
|
+
pageSize: v.optional(v.number()),
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export type ListUsersMessage = v.InferOutput<typeof listUsersMessageSchema>
|
|
31
|
+
|
|
32
|
+
export const listUsersResultMessageSchema = v.variant("status", [
|
|
33
|
+
v.object({
|
|
34
|
+
type: v.literal("listUsersResult"),
|
|
35
|
+
requestId: v.string(),
|
|
36
|
+
status: v.literal("success"),
|
|
37
|
+
list: notionUserListSchema,
|
|
38
|
+
}),
|
|
39
|
+
v.object({
|
|
40
|
+
type: v.literal("listUsersResult"),
|
|
41
|
+
requestId: v.string(),
|
|
42
|
+
status: v.literal("error"),
|
|
43
|
+
error: customBlockListUsersErrorInfoSchema,
|
|
44
|
+
}),
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
export type ListUsersResultMessage = v.InferOutput<
|
|
48
|
+
typeof listUsersResultMessageSchema
|
|
49
|
+
>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { customBlockPageSchema } from "../pages/page.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Message sent by the host whenever the custom block's nearest page ancestor changes.
|
|
6
|
+
*/
|
|
7
|
+
export const pageChangedMessageSchema = v.object({
|
|
8
|
+
type: v.literal("pageChanged"),
|
|
9
|
+
page: customBlockPageSchema,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export type PageChangedMessage = v.InferOutput<typeof pageChangedMessageSchema>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { notionParentSchema } from "../parent.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Message sent by the host whenever the custom block's parent changes.
|
|
6
|
+
*/
|
|
7
|
+
export const parentChangedMessageSchema = v.object({
|
|
8
|
+
type: v.literal("parentChanged"),
|
|
9
|
+
parent: notionParentSchema,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export type ParentChangedMessage = v.InferOutput<
|
|
13
|
+
typeof parentChangedMessageSchema
|
|
14
|
+
>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { notionDataSourceIdSchema } from "../ids.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Message sent by the sandbox to ask the host for the current rows in a resolved
|
|
6
|
+
* Notion data source.
|
|
7
|
+
*/
|
|
8
|
+
export const queryDataSourceMessageSchema = v.object({
|
|
9
|
+
type: v.literal("queryDataSource"),
|
|
10
|
+
requestId: v.string(),
|
|
11
|
+
/**
|
|
12
|
+
* The stable snapshot ID that identifies the SDK result slot to update. This is stable for the
|
|
13
|
+
* lifetime of the subscription.
|
|
14
|
+
*/
|
|
15
|
+
snapshotId: v.string(),
|
|
16
|
+
/** The raw Notion data source ID to read from. */
|
|
17
|
+
dataSourceId: notionDataSourceIdSchema,
|
|
18
|
+
/** The number of items to return in the snapshot. */
|
|
19
|
+
limit: v.number(),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export type QueryDataSourceMessage = v.InferOutput<
|
|
23
|
+
typeof queryDataSourceMessageSchema
|
|
24
|
+
>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { notionDataSourcePageBridgeSchema } from "../dataSources/dataSourcePage.js"
|
|
3
|
+
import type { CustomBlockErrorInfo } from "../errors.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 customBlockQueryDataSourceErrorCodeSchema = v.string()
|
|
8
|
+
|
|
9
|
+
export type CustomBlockQueryDataSourceErrorCode =
|
|
10
|
+
| "query_data_source_failed"
|
|
11
|
+
| "unknown_data_source_key"
|
|
12
|
+
| "unmapped_data_source"
|
|
13
|
+
| (string & {})
|
|
14
|
+
|
|
15
|
+
export type CustomBlockQueryDataSourceErrorInfo =
|
|
16
|
+
CustomBlockErrorInfo<CustomBlockQueryDataSourceErrorCode>
|
|
17
|
+
|
|
18
|
+
export const customBlockQueryDataSourceErrorInfoSchema = v.object({
|
|
19
|
+
code: customBlockQueryDataSourceErrorCodeSchema,
|
|
20
|
+
message: v.string(),
|
|
21
|
+
isRetryable: v.boolean(),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Message sent by the host to the sandbox in response to a `queryDataSource` request.
|
|
26
|
+
*/
|
|
27
|
+
export const queryDataSourceResultMessageSchema = v.object({
|
|
28
|
+
type: v.literal("queryDataSourceResult"),
|
|
29
|
+
requestId: v.string(),
|
|
30
|
+
snapshotId: v.string(),
|
|
31
|
+
items: v.array(notionDataSourcePageBridgeSchema),
|
|
32
|
+
hasMore: v.boolean(),
|
|
33
|
+
error: v.optional(customBlockQueryDataSourceErrorInfoSchema),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export type QueryDataSourceResultMessage = v.InferOutput<
|
|
37
|
+
typeof queryDataSourceResultMessageSchema
|
|
38
|
+
>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { customBlockReadyErrorSchema } from "../loadManifest.js"
|
|
3
|
+
import { manifestSchema } from "../manifest.js"
|
|
4
|
+
|
|
5
|
+
const readyMessageCommonEntries = {
|
|
6
|
+
type: v.literal("ready"),
|
|
7
|
+
/**
|
|
8
|
+
* Used to ensure that the host and client are using the same version of the bridge protocol. A
|
|
9
|
+
* single host needs to support multiple custom blocks built with different versions of the bridge
|
|
10
|
+
* protocol. Increment this number any time a breaking change is made to the bridge protocol.
|
|
11
|
+
*/
|
|
12
|
+
bridgeProtocolVersion: v.number(),
|
|
13
|
+
/**
|
|
14
|
+
* Semver version of the SDK package that sent this ready message. Should only be used for
|
|
15
|
+
* analytics purposes. Business logic should compare against `bridgeProtocolVersion` instead.
|
|
16
|
+
*/
|
|
17
|
+
sdkVersion: v.string(),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* First message the sandbox sends after mount, kicking off the bridge handshake. The host replies
|
|
22
|
+
* with `init`.
|
|
23
|
+
*/
|
|
24
|
+
export const readyMessageSchema = v.union([
|
|
25
|
+
v.object({
|
|
26
|
+
status: v.literal("success"),
|
|
27
|
+
/**
|
|
28
|
+
* The data sources and settings the custom block expects, or null when the
|
|
29
|
+
* block has no manifest and no declared data requirements.
|
|
30
|
+
*/
|
|
31
|
+
manifest: v.union([manifestSchema, v.null_()]),
|
|
32
|
+
...readyMessageCommonEntries,
|
|
33
|
+
}),
|
|
34
|
+
v.object({
|
|
35
|
+
status: v.literal("error"),
|
|
36
|
+
error: customBlockReadyErrorSchema,
|
|
37
|
+
...readyMessageCommonEntries,
|
|
38
|
+
}),
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
export type ReadyMessage = v.InferOutput<typeof readyMessageSchema>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Message sent by the sandbox whenever its measured content height changes, so the host can resize
|
|
5
|
+
* the surrounding iframe to match. The host is free to clamp the value or ignore it. The sandbox
|
|
6
|
+
* always reports the most recent measurement.
|
|
7
|
+
*/
|
|
8
|
+
export const resizeMessageSchema = v.object({
|
|
9
|
+
type: v.literal("resize"),
|
|
10
|
+
height: v.pipe(v.number(), v.finite(), v.minValue(0)),
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export type ResizeMessage = v.InferOutput<typeof resizeMessageSchema>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { createPageMessageSchema } from "./createPage.js"
|
|
3
|
+
import { getPageMessageSchema } from "./getPage.js"
|
|
4
|
+
import { getUserMessageSchema } from "./getUser.js"
|
|
5
|
+
import { invalidHostMessageSchema } from "./invalidHostMessage.js"
|
|
6
|
+
import { listUsersMessageSchema } from "./listUsers.js"
|
|
7
|
+
import { queryDataSourceMessageSchema } from "./queryDataSource.js"
|
|
8
|
+
import { readyMessageSchema } from "./ready.js"
|
|
9
|
+
import { resizeMessageSchema } from "./resize.js"
|
|
10
|
+
import { updatePageMessageSchema } from "./updatePage.js"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Union of every message the sandbox is allowed to send the host. Useful for hosts to validate
|
|
14
|
+
* inbound traffic from sandboxes without re-implementing validation logic.
|
|
15
|
+
*/
|
|
16
|
+
export const sandboxToHostMessageSchema = v.union([
|
|
17
|
+
readyMessageSchema,
|
|
18
|
+
queryDataSourceMessageSchema,
|
|
19
|
+
createPageMessageSchema,
|
|
20
|
+
getPageMessageSchema,
|
|
21
|
+
getUserMessageSchema,
|
|
22
|
+
listUsersMessageSchema,
|
|
23
|
+
updatePageMessageSchema,
|
|
24
|
+
resizeMessageSchema,
|
|
25
|
+
invalidHostMessageSchema,
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
export type SandboxToHostMessage = v.InferOutput<
|
|
29
|
+
typeof sandboxToHostMessageSchema
|
|
30
|
+
>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { notionThemeSchema } from "../theme.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Message sent by the host every time the theme changes after the initial
|
|
6
|
+
* `init` handshake.
|
|
7
|
+
*/
|
|
8
|
+
export const themeChangedMessageSchema = v.object({
|
|
9
|
+
type: v.literal("themeChanged"),
|
|
10
|
+
theme: notionThemeSchema,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export type ThemeChangedMessage = v.InferOutput<
|
|
14
|
+
typeof themeChangedMessageSchema
|
|
15
|
+
>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import { notionPageIdSchema } from "../ids.js"
|
|
3
|
+
import {
|
|
4
|
+
notionPageCoverSchema,
|
|
5
|
+
notionPageIconSchema,
|
|
6
|
+
notionPagePropertyWriteMapSchema,
|
|
7
|
+
} from "../pages/page.js"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Sandbox -> host: patch an existing page.
|
|
11
|
+
*/
|
|
12
|
+
export const updatePageMessageSchema = v.object({
|
|
13
|
+
type: v.literal("updatePage"),
|
|
14
|
+
requestId: v.string(),
|
|
15
|
+
pageId: notionPageIdSchema,
|
|
16
|
+
properties: v.optional(notionPagePropertyWriteMapSchema),
|
|
17
|
+
icon: v.optional(notionPageIconSchema),
|
|
18
|
+
cover: v.optional(notionPageCoverSchema),
|
|
19
|
+
archived: v.optional(v.boolean()),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export type UpdatePageMessage = v.InferOutput<typeof updatePageMessageSchema>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as v from "valibot"
|
|
2
|
+
import type { 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 customBlockUpdatePageErrorCodeSchema = v.string()
|
|
8
|
+
|
|
9
|
+
export type CustomBlockUpdatePageErrorCode =
|
|
10
|
+
| "update_page_failed"
|
|
11
|
+
| "invalid_page_update"
|
|
12
|
+
| "page_access_failed"
|
|
13
|
+
| "collection_access_failed"
|
|
14
|
+
| "unmapped_property"
|
|
15
|
+
| "property_id_mismatch"
|
|
16
|
+
| "duplicate_property"
|
|
17
|
+
| "invalid_property_value"
|
|
18
|
+
| (string & {})
|
|
19
|
+
|
|
20
|
+
export type CustomBlockUpdatePageErrorInfo =
|
|
21
|
+
CustomBlockErrorInfo<CustomBlockUpdatePageErrorCode>
|
|
22
|
+
|
|
23
|
+
export const customBlockUpdatePageErrorInfoSchema = v.object({
|
|
24
|
+
code: customBlockUpdatePageErrorCodeSchema,
|
|
25
|
+
message: v.string(),
|
|
26
|
+
isRetryable: v.boolean(),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Host -> sandbox: result for a page update request.
|
|
31
|
+
*/
|
|
32
|
+
export const updatePageResultMessageSchema = v.variant("status", [
|
|
33
|
+
v.object({
|
|
34
|
+
type: v.literal("updatePageResult"),
|
|
35
|
+
requestId: v.string(),
|
|
36
|
+
status: v.literal("success"),
|
|
37
|
+
page: notionPageSchema,
|
|
38
|
+
}),
|
|
39
|
+
v.object({
|
|
40
|
+
type: v.literal("updatePageResult"),
|
|
41
|
+
requestId: v.string(),
|
|
42
|
+
status: v.literal("error"),
|
|
43
|
+
error: customBlockUpdatePageErrorInfoSchema,
|
|
44
|
+
}),
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
export type UpdatePageResultMessage = v.InferOutput<
|
|
48
|
+
typeof updatePageResultMessageSchema
|
|
49
|
+
>
|