@notionhq/custom-blocks 0.2.21 → 0.2.23
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 +2 -0
- package/dist/bridge/SandboxBridge.d.ts +14 -18
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +59 -201
- package/dist/bridge/SandboxInitialization.d.ts +52 -0
- package/dist/bridge/SandboxInitialization.d.ts.map +1 -0
- package/dist/bridge/SandboxInitialization.js +217 -0
- package/dist/bridge/dataSources/query.d.ts.map +1 -1
- package/dist/bridge/dataSources/query.js +39 -23
- package/dist/bridge/messageInterceptor.d.ts +4 -0
- package/dist/bridge/messageInterceptor.d.ts.map +1 -0
- package/dist/bridge/messageInterceptor.js +1 -0
- package/dist/bridge/sandboxClient.d.ts +3 -2
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +3 -5
- package/dist/bridge.d.ts +11 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/init.d.ts +4 -38
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +4 -91
- package/dist/initTypes.d.ts +31 -0
- package/dist/initTypes.d.ts.map +1 -0
- package/dist/initTypes.js +18 -0
- package/dist/protocol/dataSources/propertySchema.d.ts +1 -1
- package/dist/protocol/dataSources/propertySchema.js +2 -0
- package/dist/protocol/dataSources/sortDirection.d.ts +3 -0
- package/dist/protocol/dataSources/sortDirection.js +2 -0
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/manifest.d.ts +10 -3
- package/dist/protocol/manifest.js +5 -1
- package/dist/protocol/messages/connect.d.ts +9 -2
- package/dist/protocol/messages/hostToSandbox.d.ts +9 -5
- package/dist/protocol/messages/init.d.ts +10 -3
- package/dist/protocol/messages/queryDataSource.d.ts +300 -47
- package/dist/protocol/messages/queryDataSource.js +107 -9
- package/dist/protocol/messages/sandboxToHost.d.ts +103 -18
- package/dist/styles/nds.css +1 -1
- package/dist/types.d.ts +8 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/bridge-interceptors.md +27 -0
- package/docs/data-sources.md +93 -13
- package/docs/errors.md +3 -2
- package/docs/lifecycle.md +1 -1
- package/docs/pages.md +22 -10
- package/package.json +4 -4
- package/src/bridge/SandboxBridge.ts +74 -239
- package/src/bridge/SandboxInitialization.ts +295 -0
- package/src/bridge/dataSources/query.ts +51 -25
- package/src/bridge/messageInterceptor.ts +6 -0
- package/src/bridge/sandboxClient.ts +6 -5
- package/src/bridge.ts +17 -0
- package/src/index.ts +1 -0
- package/src/init.ts +8 -119
- package/src/initTypes.ts +43 -0
- package/src/styles/nds.css +1 -1
- package/src/styles/nds.css.metadata.json +3 -3
- package/src/types.ts +11 -2
- package/dist/bridge/primedResponses.d.ts +0 -8
- package/dist/bridge/primedResponses.d.ts.map +0 -1
- package/dist/bridge/primedResponses.js +0 -5
- package/dist/testing.d.ts +0 -12
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -9
- package/src/bridge/primedResponses.ts +0 -11
- package/src/testing.ts +0 -19
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CustomBlockInitializationError } from "./protocol/messages/init.js";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when the SDK is loaded in a top-level standalone window with no parent frame.
|
|
4
|
+
* `postMessage` would just hit the same window and the handshake can never complete.
|
|
5
|
+
* `<NotionCustomBlock>` catches this specifically and falls back to a standalone preview with a
|
|
6
|
+
* warning banner. Direct callers can `instanceof` it to apply their own policy.
|
|
7
|
+
*/
|
|
8
|
+
export class NotInIframeError extends CustomBlockInitializationError {
|
|
9
|
+
constructor(message = NOT_IN_IFRAME_MESSAGE) {
|
|
10
|
+
super({
|
|
11
|
+
code: "not_in_iframe",
|
|
12
|
+
message,
|
|
13
|
+
isRetryable: false,
|
|
14
|
+
});
|
|
15
|
+
this.name = "NotInIframeError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const NOT_IN_IFRAME_MESSAGE = "Custom block initialization requires a Notion host. For local development, open the block in the dev shell. Otherwise, deploy it to Notion.";
|
|
@@ -48,7 +48,7 @@ export type NotionPropertyType = v.InferOutput<typeof notionPropertyTypeSchema>;
|
|
|
48
48
|
* Keep this list narrower than {@link NOTION_PROPERTY_TYPES} when a property
|
|
49
49
|
* type is exposed but its sort value is not yet represented by every host.
|
|
50
50
|
*/
|
|
51
|
-
export declare const CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES: readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "date", "created_time", "last_edited_time"];
|
|
51
|
+
export declare const CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES: readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "date", "created_time", "last_edited_time", "people", "created_by"];
|
|
52
52
|
export type CustomBlockDataSourceSortablePropertyType = (typeof CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES)[number];
|
|
53
53
|
/**
|
|
54
54
|
* Per-property schema as exposed by the host over the custom-block bridge.
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./dataSources/dateValue.js";
|
|
|
13
13
|
export * from "./dataSources/errors.js";
|
|
14
14
|
export * from "./dataSources/propertySchema.js";
|
|
15
15
|
export * from "./dataSources/recordPointer.js";
|
|
16
|
+
export * from "./dataSources/sortDirection.js";
|
|
16
17
|
export * from "./errors.js";
|
|
17
18
|
export * from "./ids.js";
|
|
18
19
|
export * from "./manifest.js";
|
package/dist/protocol/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./dataSources/dateValue.js";
|
|
|
13
13
|
export * from "./dataSources/errors.js";
|
|
14
14
|
export * from "./dataSources/propertySchema.js";
|
|
15
15
|
export * from "./dataSources/recordPointer.js";
|
|
16
|
+
export * from "./dataSources/sortDirection.js";
|
|
16
17
|
export * from "./errors.js";
|
|
17
18
|
export * from "./ids.js";
|
|
18
19
|
export * from "./manifest.js";
|
|
@@ -37,7 +37,14 @@ export declare const manifestDataSourceSchema: v.ObjectSchema<{
|
|
|
37
37
|
export type ManifestDataSource = v.InferOutput<typeof manifestDataSourceSchema>;
|
|
38
38
|
export declare const manifestSchema: v.ObjectSchema<{
|
|
39
39
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
40
|
-
readonly
|
|
40
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
41
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
42
|
+
readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
43
|
+
readonly icon: v.OptionalSchema<v.ObjectSchema<{
|
|
44
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
45
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
46
|
+
}, undefined>, undefined>;
|
|
47
|
+
readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
41
48
|
readonly name: v.StringSchema<undefined>;
|
|
42
49
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
43
50
|
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
@@ -52,9 +59,9 @@ export declare const manifestSchema: v.ObjectSchema<{
|
|
|
52
59
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
53
60
|
readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
|
|
54
61
|
}, undefined>, undefined>, {}>;
|
|
55
|
-
}, undefined>, undefined>;
|
|
62
|
+
}, undefined>, undefined>, {}>;
|
|
56
63
|
}, undefined>;
|
|
57
64
|
/**
|
|
58
|
-
* Manifest
|
|
65
|
+
* Manifest describing a custom block and its required data sources.
|
|
59
66
|
*/
|
|
60
67
|
export type CustomBlockManifest = v.InferOutput<typeof manifestSchema>;
|
|
@@ -28,5 +28,9 @@ export const manifestDataSourceSchema = v.object({
|
|
|
28
28
|
});
|
|
29
29
|
export const manifestSchema = v.object({
|
|
30
30
|
version: v.literal(1),
|
|
31
|
-
|
|
31
|
+
name: v.optional(v.string()),
|
|
32
|
+
description: v.optional(v.string()),
|
|
33
|
+
slashCommand: v.optional(v.string()),
|
|
34
|
+
icon: v.optional(v.object({ type: v.literal("emoji"), emoji: v.string() })),
|
|
35
|
+
dataSources: v.optional(v.record(v.string(), manifestDataSourceSchema), {}),
|
|
32
36
|
});
|
|
@@ -15,7 +15,14 @@ export declare const connectMessageSchema: v.VariantSchema<"status", [v.ObjectSc
|
|
|
15
15
|
*/
|
|
16
16
|
readonly manifest: v.OptionalSchema<v.ObjectSchema<{
|
|
17
17
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
18
|
-
readonly
|
|
18
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
19
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
20
|
+
readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
21
|
+
readonly icon: v.OptionalSchema<v.ObjectSchema<{
|
|
22
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
23
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
24
|
+
}, undefined>, undefined>;
|
|
25
|
+
readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
19
26
|
readonly name: v.StringSchema<undefined>;
|
|
20
27
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
21
28
|
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
@@ -30,7 +37,7 @@ export declare const connectMessageSchema: v.VariantSchema<"status", [v.ObjectSc
|
|
|
30
37
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
31
38
|
readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
|
|
32
39
|
}, undefined>, undefined>, {}>;
|
|
33
|
-
}, undefined>, undefined>;
|
|
40
|
+
}, undefined>, undefined>, {}>;
|
|
34
41
|
}, undefined>, undefined>;
|
|
35
42
|
}, undefined>, v.ObjectSchema<{
|
|
36
43
|
readonly type: v.LiteralSchema<"connect", undefined>;
|
|
@@ -53,7 +53,14 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
53
53
|
}, undefined>], undefined>;
|
|
54
54
|
readonly manifest: v.ObjectSchema<{
|
|
55
55
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
56
|
-
readonly
|
|
56
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
57
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
58
|
+
readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
59
|
+
readonly icon: v.OptionalSchema<v.ObjectSchema<{
|
|
60
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
61
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
62
|
+
}, undefined>, undefined>;
|
|
63
|
+
readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
57
64
|
readonly name: v.StringSchema<undefined>;
|
|
58
65
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
59
66
|
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
@@ -68,7 +75,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
68
75
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
69
76
|
readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
|
|
70
77
|
}, undefined>, undefined>, {}>;
|
|
71
|
-
}, undefined>, undefined>;
|
|
78
|
+
}, undefined>, undefined>, {}>;
|
|
72
79
|
}, undefined>;
|
|
73
80
|
readonly dataSources: v.ObjectSchema<{
|
|
74
81
|
readonly bindings: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
@@ -1201,6 +1208,3 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
1201
1208
|
readonly reason: v.StringSchema<undefined>;
|
|
1202
1209
|
}, undefined>], undefined>;
|
|
1203
1210
|
export type HostToSandboxMessage = v.InferOutput<typeof hostToSandboxMessageSchema>;
|
|
1204
|
-
export type PrimeableHostToSandboxMessage = Extract<HostToSandboxMessage, {
|
|
1205
|
-
type: "getPageResult" | "openPageResult" | "createPageResult" | "updatePageResult" | "getUserResult" | "listUsersResult" | "queryDataSourceResult";
|
|
1206
|
-
}>;
|
|
@@ -2,7 +2,7 @@ import * as v from "valibot";
|
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
import type { CustomBlockInitResultErrorCode } from "./initResult.js";
|
|
4
4
|
export declare const customBlockInitErrorCodeSchema: v.StringSchema<undefined>;
|
|
5
|
-
export type CustomBlockInitErrorCode = CustomBlockErrorCode<"manifest_unavailable" | "manifest_invalid" | "invalid_connect_payload" | "invalid_protocol_version" | "unsupported_protocol_version" | "init_timeout" | "context_unavailable" | "current_user_unavailable" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding">;
|
|
5
|
+
export type CustomBlockInitErrorCode = CustomBlockErrorCode<"manifest_unavailable" | "manifest_invalid" | "invalid_connect_payload" | "invalid_protocol_version" | "unsupported_protocol_version" | "init_timeout" | "context_unavailable" | "current_user_unavailable" | "initial_state_timeout" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding">;
|
|
6
6
|
export type CustomBlockInitErrorInfo = CustomBlockErrorInfo<CustomBlockInitErrorCode>;
|
|
7
7
|
/**
|
|
8
8
|
* Every initialization failure visible to block code. This combines errors
|
|
@@ -79,7 +79,14 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
|
|
|
79
79
|
}, undefined>], undefined>;
|
|
80
80
|
readonly manifest: v.ObjectSchema<{
|
|
81
81
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
82
|
-
readonly
|
|
82
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
83
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
84
|
+
readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
85
|
+
readonly icon: v.OptionalSchema<v.ObjectSchema<{
|
|
86
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
87
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
88
|
+
}, undefined>, undefined>;
|
|
89
|
+
readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
83
90
|
readonly name: v.StringSchema<undefined>;
|
|
84
91
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
85
92
|
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
@@ -94,7 +101,7 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
|
|
|
94
101
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
95
102
|
readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
|
|
96
103
|
}, undefined>, undefined>, {}>;
|
|
97
|
-
}, undefined>, undefined>;
|
|
104
|
+
}, undefined>, undefined>, {}>;
|
|
98
105
|
}, undefined>;
|
|
99
106
|
readonly dataSources: v.ObjectSchema<{
|
|
100
107
|
readonly bindings: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|