@notionhq/custom-blocks-host 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/browser.js +1 -1
- package/dist/compatibility/normalizeHostToSandboxMessage.d.ts.map +1 -1
- package/dist/compatibility/normalizeHostToSandboxMessage.js +5 -1
- package/dist/compatibility/normalizeSandboxToHostMessage.d.ts +87 -1
- package/dist/compatibility/normalizeSandboxToHostMessage.d.ts.map +1 -1
- package/dist/compatibility/pages/toIconForProtocol3To8.d.ts +4 -0
- package/dist/compatibility/pages/toIconForProtocol3To8.d.ts.map +1 -0
- package/dist/compatibility/pages/toIconForProtocol3To8.js +13 -0
- package/dist/compatibility/protocol3To5/toPageForProtocol3To5.d.ts.map +1 -1
- package/dist/compatibility/protocol3To5/toPageForProtocol3To5.js +2 -1
- package/dist/compatibility/protocol3To5/toQueryPageForProtocol3To5.d.ts +8 -8
- package/dist/compatibility/protocol6/normalizePageResultsForProtocol6.d.ts.map +1 -1
- package/dist/compatibility/protocol6/normalizePageResultsForProtocol6.js +9 -2
- package/dist/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.d.ts +4 -0
- package/dist/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.d.ts.map +1 -0
- package/dist/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.js +16 -0
- package/dist/createCustomBlockHost.d.ts.map +1 -1
- package/dist/createCustomBlockHost.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/messages/createSandboxMessageRouter.d.ts +3 -2
- package/dist/messages/createSandboxMessageRouter.d.ts.map +1 -1
- package/dist/messages/createSandboxMessageRouter.js +7 -1
- package/dist/messages/invalidNativeIconColor.d.ts +5 -0
- package/dist/messages/invalidNativeIconColor.d.ts.map +1 -0
- package/dist/messages/invalidNativeIconColor.js +34 -0
- package/dist/pages/types.d.ts +2 -0
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/protocol/compatibility/protocol3To5/bridgePage.d.ts +7 -1
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +14 -2
- package/dist/protocol/icons.d.ts +17 -0
- package/dist/protocol/icons.js +27 -0
- package/dist/protocol/index.d.ts +3 -2
- package/dist/protocol/index.js +3 -2
- package/dist/protocol/messages/hostToSandbox.d.ts +77 -11
- package/dist/protocol/messages/sandboxToHost.d.ts +87 -1
- package/dist/protocol/pages/bridgePage.d.ts +7 -1
- package/dist/protocol/pages/messages/createPage.d.ts +102 -4
- package/dist/protocol/pages/messages/createPage.js +3 -1
- package/dist/protocol/pages/messages/getPage.d.ts +21 -3
- package/dist/protocol/pages/messages/updatePage.d.ts +29 -5
- package/dist/protocol/pages/pageAppearance.d.ts +36 -1
- package/dist/protocol/pages/pageAppearance.js +9 -0
- package/dist/protocol/utils/protocolVersion.d.ts +2 -1
- package/dist/protocol/utils/protocolVersion.js +3 -1
- package/docs/bridge/changelog.md +12 -0
- package/docs/bridge/protocol.md +11 -0
- package/docs/bridge/versioning.md +1 -0
- package/docs/compatibility.md +15 -7
- package/package.json +1 -1
- package/src/compatibility/normalizeHostToSandboxMessage.ts +5 -0
- package/src/compatibility/pages/toIconForProtocol3To8.ts +17 -0
- package/src/compatibility/protocol3To5/toPageForProtocol3To5.ts +2 -1
- package/src/compatibility/protocol6/normalizePageResultsForProtocol6.ts +11 -2
- package/src/compatibility/protocol7To8/normalizePageResultsForProtocol7To8.ts +22 -0
- package/src/createCustomBlockHost.ts +1 -0
- package/src/index.ts +1 -0
- package/src/messages/createSandboxMessageRouter.ts +18 -2
- package/src/messages/invalidNativeIconColor.ts +43 -0
- package/src/pages/types.ts +3 -0
package/src/index.ts
CHANGED
|
@@ -6,10 +6,16 @@ import type { InitResultMessage } from "@notionhq/custom-blocks-protocol/handsha
|
|
|
6
6
|
import { isInitHandshakeMessage } from "@notionhq/custom-blocks-protocol/handshake/isInitHandshakeMessage.js"
|
|
7
7
|
import type { InvalidSandboxMessage } from "@notionhq/custom-blocks-protocol/messages/invalidSandboxMessage.js"
|
|
8
8
|
import type { OpenExternalUrlMessage } from "@notionhq/custom-blocks-protocol/navigation/openExternalUrl.js"
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
CreatePageMessage,
|
|
11
|
+
CreatePageResultMessage,
|
|
12
|
+
} from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
|
|
10
13
|
import type { GetPageMessage } from "@notionhq/custom-blocks-protocol/pages/messages/getPage.js"
|
|
11
14
|
import type { OpenPageMessage } from "@notionhq/custom-blocks-protocol/pages/messages/openPage.js"
|
|
12
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
UpdatePageMessage,
|
|
17
|
+
UpdatePageResultMessage,
|
|
18
|
+
} from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
13
19
|
import type { GetUserMessage } from "@notionhq/custom-blocks-protocol/users/messages/getUser.js"
|
|
14
20
|
import type { ListUsersMessage } from "@notionhq/custom-blocks-protocol/users/messages/listUsers.js"
|
|
15
21
|
import * as v from "valibot"
|
|
@@ -20,6 +26,7 @@ import { invalidInitResultPayloadError } from "../lifecycle/errors/invalidInitRe
|
|
|
20
26
|
import type { InitStatus } from "../lifecycle/types.js"
|
|
21
27
|
import { unreachable } from "../utils/unreachable.js"
|
|
22
28
|
import { getInvalidSandboxMessageResponse } from "./getInvalidSandboxMessageResponse.js"
|
|
29
|
+
import { getInvalidNativeIconColorResponse } from "./invalidNativeIconColor.js"
|
|
23
30
|
import type { CustomBlockHostLogDirection } from "./logging.js"
|
|
24
31
|
|
|
25
32
|
const initializationIdentitySchema = v.object({
|
|
@@ -38,6 +45,9 @@ export type SandboxMessageRouterOptions = {
|
|
|
38
45
|
getInitStatus: () => InitStatus
|
|
39
46
|
emit: (direction: CustomBlockHostLogDirection, payload: unknown) => void
|
|
40
47
|
sendNack: (message: InvalidSandboxMessage) => void
|
|
48
|
+
sendPageMutationError: (
|
|
49
|
+
message: UpdatePageResultMessage | CreatePageResultMessage,
|
|
50
|
+
) => void
|
|
41
51
|
onInvalidConnect: InitializationController["handleInvalidConnect"]
|
|
42
52
|
onInvalidInitResult: InitializationController["handleInvalidInitResult"]
|
|
43
53
|
onConnect: (message: ConnectMessage) => void
|
|
@@ -65,6 +75,7 @@ export function createSandboxMessageRouter(
|
|
|
65
75
|
getInitStatus,
|
|
66
76
|
emit,
|
|
67
77
|
sendNack,
|
|
78
|
+
sendPageMutationError,
|
|
68
79
|
onInvalidConnect,
|
|
69
80
|
onInvalidInitResult,
|
|
70
81
|
onConnect,
|
|
@@ -85,6 +96,11 @@ export function createSandboxMessageRouter(
|
|
|
85
96
|
data: unknown,
|
|
86
97
|
issues: readonly v.BaseIssue<unknown>[],
|
|
87
98
|
) {
|
|
99
|
+
const iconError = getInvalidNativeIconColorResponse(data)
|
|
100
|
+
if (iconError !== undefined && getInitStatus() === "initialized") {
|
|
101
|
+
sendPageMutationError(iconError)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
88
104
|
emit("warn", {
|
|
89
105
|
message: "Ignored unsupported sandbox message",
|
|
90
106
|
payload: redactExternalUrl(data),
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { notionIconColorSchema } from "@notionhq/custom-blocks-protocol/icons.js"
|
|
2
|
+
import type { CreatePageResultMessage } from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
|
|
3
|
+
import type { UpdatePageResultMessage } from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
4
|
+
import * as v from "valibot"
|
|
5
|
+
|
|
6
|
+
const nativeIconMutationSchema = v.object({
|
|
7
|
+
type: v.picklist(["updatePage", "createPage"]),
|
|
8
|
+
requestId: v.string(),
|
|
9
|
+
icon: v.object({
|
|
10
|
+
type: v.literal("icon"),
|
|
11
|
+
icon: v.object({ color: v.unknown() }),
|
|
12
|
+
}),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
/** Reject malformed colors with a correlated result before invoking a page mutation handler. */
|
|
16
|
+
export function getInvalidNativeIconColorResponse(
|
|
17
|
+
data: unknown,
|
|
18
|
+
): UpdatePageResultMessage | CreatePageResultMessage | undefined {
|
|
19
|
+
const parsed = v.safeParse(nativeIconMutationSchema, data)
|
|
20
|
+
if (!parsed.success) {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
const color = parsed.output.icon.icon.color
|
|
24
|
+
if (
|
|
25
|
+
color === undefined ||
|
|
26
|
+
v.safeParse(notionIconColorSchema, color).success
|
|
27
|
+
) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
type:
|
|
32
|
+
parsed.output.type === "createPage"
|
|
33
|
+
? "createPageResult"
|
|
34
|
+
: "updatePageResult",
|
|
35
|
+
requestId: parsed.output.requestId,
|
|
36
|
+
status: "error",
|
|
37
|
+
error: {
|
|
38
|
+
code: "invalid_icon_color",
|
|
39
|
+
message: "Use a supported Notion icon color.",
|
|
40
|
+
isRetryable: false,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/pages/types.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { createPageMessageSchema } from "@notionhq/custom-blocks-protocol/p
|
|
|
3
3
|
import type { getPageMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/getPage.js"
|
|
4
4
|
import type { openPageMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/openPage.js"
|
|
5
5
|
import type { updatePageMessageSchema } from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
6
|
+
import type { notionPageIconSchema } from "@notionhq/custom-blocks-protocol/pages/pageAppearance.js"
|
|
6
7
|
import type { InferInput } from "valibot"
|
|
7
8
|
import type { CustomBlockHostResult } from "../messages/result.js"
|
|
8
9
|
|
|
@@ -20,3 +21,5 @@ export type CustomBlockHostPageResult = CustomBlockHostResult<{
|
|
|
20
21
|
export type CustomBlockHostOpenPageResult = CustomBlockHostResult<{
|
|
21
22
|
pageId: string
|
|
22
23
|
}>
|
|
24
|
+
|
|
25
|
+
export type CustomBlockHostPageIcon = InferInput<typeof notionPageIconSchema>
|