@notionhq/custom-blocks-host 0.0.1
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 +204 -0
- package/dist/autoBindProperties.d.ts +21 -0
- package/dist/autoBindProperties.d.ts.map +1 -0
- package/dist/autoBindProperties.js +38 -0
- package/dist/createCustomBlockHost.d.ts +46 -0
- package/dist/createCustomBlockHost.d.ts.map +1 -0
- package/dist/createCustomBlockHost.js +433 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/lifecycle/initErrors.d.ts +13 -0
- package/dist/lifecycle/initErrors.d.ts.map +1 -0
- package/dist/lifecycle/initErrors.js +152 -0
- package/dist/lifecycle/initializationController.d.ts +54 -0
- package/dist/lifecycle/initializationController.d.ts.map +1 -0
- package/dist/lifecycle/initializationController.js +182 -0
- package/dist/lifecycle/protocolVersion.d.ts +2 -0
- package/dist/lifecycle/protocolVersion.d.ts.map +1 -0
- package/dist/lifecycle/protocolVersion.js +3 -0
- package/dist/lifecycle/types.d.ts +28 -0
- package/dist/lifecycle/types.d.ts.map +1 -0
- package/dist/lifecycle/types.js +1 -0
- package/dist/messages/invalidSandboxMessage.d.ts +7 -0
- package/dist/messages/invalidSandboxMessage.d.ts.map +1 -0
- package/dist/messages/invalidSandboxMessage.js +21 -0
- package/dist/messages/types.d.ts +29 -0
- package/dist/messages/types.d.ts.map +1 -0
- package/dist/messages/types.js +1 -0
- package/dist/protocol/contrast.d.ts +4 -0
- package/dist/protocol/contrast.js +3 -0
- package/dist/protocol/dataSources/dataSource.d.ts +731 -0
- package/dist/protocol/dataSources/dataSource.js +37 -0
- package/dist/protocol/dataSources/dataSourcePage.d.ts +72 -0
- package/dist/protocol/dataSources/dataSourcePage.js +12 -0
- package/dist/protocol/dataSources/dataSourceValue.d.ts +66 -0
- package/dist/protocol/dataSources/dataSourceValue.js +14 -0
- package/dist/protocol/dataSources/dateValue.d.ts +157 -0
- package/dist/protocol/dataSources/dateValue.js +59 -0
- package/dist/protocol/dataSources/errors.d.ts +8 -0
- package/dist/protocol/dataSources/errors.js +7 -0
- package/dist/protocol/dataSources/propertySchema.d.ts +197 -0
- package/dist/protocol/dataSources/propertySchema.js +165 -0
- package/dist/protocol/dataSources/recordPointer.d.ts +9 -0
- package/dist/protocol/dataSources/recordPointer.js +8 -0
- package/dist/protocol/errors.d.ts +12 -0
- package/dist/protocol/errors.js +6 -0
- package/dist/protocol/ids.d.ts +31 -0
- package/dist/protocol/ids.js +26 -0
- package/dist/protocol/incomingType.d.ts +9 -0
- package/dist/protocol/incomingType.js +17 -0
- package/dist/protocol/index.d.ts +48 -0
- package/dist/protocol/index.js +48 -0
- package/dist/protocol/manifest.d.ts +60 -0
- package/dist/protocol/manifest.js +32 -0
- package/dist/protocol/messagePayload.d.ts +19 -0
- package/dist/protocol/messagePayload.js +1 -0
- package/dist/protocol/messages/connect.d.ts +47 -0
- package/dist/protocol/messages/connect.js +38 -0
- package/dist/protocol/messages/contrastModeChanged.d.ts +7 -0
- package/dist/protocol/messages/contrastModeChanged.js +7 -0
- package/dist/protocol/messages/createPage.d.ts +200 -0
- package/dist/protocol/messages/createPage.js +52 -0
- package/dist/protocol/messages/createPageResult.d.ts +213 -0
- package/dist/protocol/messages/createPageResult.js +28 -0
- package/dist/protocol/messages/currentUserChanged.d.ts +18 -0
- package/dist/protocol/messages/currentUserChanged.js +9 -0
- package/dist/protocol/messages/dataSourcesChanged.d.ts +157 -0
- package/dist/protocol/messages/dataSourcesChanged.js +13 -0
- package/dist/protocol/messages/getPage.d.ts +218 -0
- package/dist/protocol/messages/getPage.js +33 -0
- package/dist/protocol/messages/getUser.d.ts +44 -0
- package/dist/protocol/messages/getUser.js +32 -0
- package/dist/protocol/messages/hostToSandbox.d.ts +1167 -0
- package/dist/protocol/messages/hostToSandbox.js +34 -0
- package/dist/protocol/messages/init.d.ts +259 -0
- package/dist/protocol/messages/init.js +56 -0
- package/dist/protocol/messages/initResult.d.ts +37 -0
- package/dist/protocol/messages/initResult.js +28 -0
- package/dist/protocol/messages/invalidHostMessage.d.ts +14 -0
- package/dist/protocol/messages/invalidHostMessage.js +13 -0
- package/dist/protocol/messages/invalidSandboxMessage.d.ts +14 -0
- package/dist/protocol/messages/invalidSandboxMessage.js +13 -0
- package/dist/protocol/messages/listUsers.d.ts +52 -0
- package/dist/protocol/messages/listUsers.js +33 -0
- package/dist/protocol/messages/pageChanged.d.ts +27 -0
- package/dist/protocol/messages/pageChanged.js +9 -0
- package/dist/protocol/messages/parentChanged.d.ts +24 -0
- package/dist/protocol/messages/parentChanged.js +9 -0
- package/dist/protocol/messages/queryDataSource.d.ts +985 -0
- package/dist/protocol/messages/queryDataSource.js +123 -0
- package/dist/protocol/messages/queryDataSourceResult.d.ts +93 -0
- package/dist/protocol/messages/queryDataSourceResult.js +28 -0
- package/dist/protocol/messages/resize.d.ts +11 -0
- package/dist/protocol/messages/resize.js +10 -0
- package/dist/protocol/messages/sandboxToHost.d.ts +744 -0
- package/dist/protocol/messages/sandboxToHost.js +27 -0
- package/dist/protocol/messages/themeChanged.d.ts +10 -0
- package/dist/protocol/messages/themeChanged.js +10 -0
- package/dist/protocol/messages/updatePage.d.ts +180 -0
- package/dist/protocol/messages/updatePage.js +22 -0
- package/dist/protocol/messages/updatePageResult.d.ts +212 -0
- package/dist/protocol/messages/updatePageResult.js +27 -0
- package/dist/protocol/pages/page.d.ts +597 -0
- package/dist/protocol/pages/page.js +212 -0
- package/dist/protocol/parent.d.ts +28 -0
- package/dist/protocol/parent.js +12 -0
- package/dist/protocol/protocolVersion.d.ts +6 -0
- package/dist/protocol/protocolVersion.js +6 -0
- package/dist/protocol/theme.d.ts +3 -0
- package/dist/protocol/theme.js +2 -0
- package/dist/protocol/users/user.d.ts +32 -0
- package/dist/protocol/users/user.js +20 -0
- package/dist/queries/querySubscriptions.d.ts +17 -0
- package/dist/queries/querySubscriptions.d.ts.map +1 -0
- package/dist/queries/querySubscriptions.js +38 -0
- package/dist/queries/types.d.ts +4 -0
- package/dist/queries/types.d.ts.map +1 -0
- package/dist/queries/types.js +1 -0
- package/dist/queries/validateQueryDataSourceFilter.d.ts +5 -0
- package/dist/queries/validateQueryDataSourceFilter.d.ts.map +1 -0
- package/dist/queries/validateQueryDataSourceFilter.js +72 -0
- package/dist/queries/validateQueryDataSourceSorts.d.ts +8 -0
- package/dist/queries/validateQueryDataSourceSorts.d.ts.map +1 -0
- package/dist/queries/validateQueryDataSourceSorts.js +47 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/package.json +26 -0
- package/src/autoBindProperties.ts +63 -0
- package/src/createCustomBlockHost.ts +605 -0
- package/src/index.ts +25 -0
- package/src/lifecycle/initErrors.ts +165 -0
- package/src/lifecycle/initializationController.ts +290 -0
- package/src/lifecycle/protocolVersion.ts +3 -0
- package/src/lifecycle/types.ts +40 -0
- package/src/messages/invalidSandboxMessage.ts +35 -0
- package/src/messages/types.ts +80 -0
- package/src/queries/querySubscriptions.ts +57 -0
- package/src/queries/types.ts +10 -0
- package/src/queries/validateQueryDataSourceFilter.ts +101 -0
- package/src/queries/validateQueryDataSourceSorts.ts +69 -0
- package/src/utils.ts +8 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Hex-token identifiers for Notion's named colors. Mirrors the public API's
|
|
4
|
+
* `select.options[].color` enum
|
|
5
|
+
* (https://developers.notion.com/reference/property-object#select).
|
|
6
|
+
*/
|
|
7
|
+
export const notionPropertyColorSchema = v.picklist([
|
|
8
|
+
"default",
|
|
9
|
+
"gray",
|
|
10
|
+
"brown",
|
|
11
|
+
"orange",
|
|
12
|
+
"yellow",
|
|
13
|
+
"green",
|
|
14
|
+
"blue",
|
|
15
|
+
"purple",
|
|
16
|
+
"pink",
|
|
17
|
+
"red",
|
|
18
|
+
"gray_background",
|
|
19
|
+
"brown_background",
|
|
20
|
+
"orange_background",
|
|
21
|
+
"yellow_background",
|
|
22
|
+
"green_background",
|
|
23
|
+
"blue_background",
|
|
24
|
+
"purple_background",
|
|
25
|
+
"pink_background",
|
|
26
|
+
"red_background",
|
|
27
|
+
"default_background",
|
|
28
|
+
]);
|
|
29
|
+
export const notionPropertyOptionSchema = v.object({
|
|
30
|
+
id: v.string(),
|
|
31
|
+
name: v.string(),
|
|
32
|
+
color: v.optional(notionPropertyColorSchema),
|
|
33
|
+
description: v.optional(v.string()),
|
|
34
|
+
});
|
|
35
|
+
export const notionStatusGroupSchema = v.object({
|
|
36
|
+
id: v.string(),
|
|
37
|
+
name: v.string(),
|
|
38
|
+
color: v.optional(notionPropertyColorSchema),
|
|
39
|
+
option_ids: v.array(v.string()),
|
|
40
|
+
});
|
|
41
|
+
export const notionDualPropertySchema = v.object({
|
|
42
|
+
synced_property_id: v.string(),
|
|
43
|
+
synced_property_name: v.string(),
|
|
44
|
+
});
|
|
45
|
+
const baseProp = v.object({
|
|
46
|
+
name: v.string(),
|
|
47
|
+
description: v.optional(v.string()),
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Every Notion property type the bridge speaks, in a single readable list.
|
|
51
|
+
* Mirrors the Notion public API
|
|
52
|
+
* [property object](https://developers.notion.com/reference/property-object)
|
|
53
|
+
* type field. Internal-only types (`button`, `verification`,
|
|
54
|
+
* `last_visited_time`, `location`) and the four built-ins (`created_time`,
|
|
55
|
+
* `last_edited_time`, `created_by`, `last_edited_by`) are included under their
|
|
56
|
+
* bridge-native names.
|
|
57
|
+
*/
|
|
58
|
+
export const NOTION_PROPERTY_TYPES = [
|
|
59
|
+
"title",
|
|
60
|
+
"rich_text",
|
|
61
|
+
"number",
|
|
62
|
+
"checkbox",
|
|
63
|
+
"url",
|
|
64
|
+
"email",
|
|
65
|
+
"phone_number",
|
|
66
|
+
"select",
|
|
67
|
+
"multi_select",
|
|
68
|
+
"status",
|
|
69
|
+
"date",
|
|
70
|
+
"people",
|
|
71
|
+
"files",
|
|
72
|
+
"unique_id",
|
|
73
|
+
"relation",
|
|
74
|
+
"place",
|
|
75
|
+
"formula",
|
|
76
|
+
"rollup",
|
|
77
|
+
"button",
|
|
78
|
+
"verification",
|
|
79
|
+
"last_visited_time",
|
|
80
|
+
"location",
|
|
81
|
+
"created_time",
|
|
82
|
+
"last_edited_time",
|
|
83
|
+
"created_by",
|
|
84
|
+
"last_edited_by",
|
|
85
|
+
];
|
|
86
|
+
export const notionPropertyTypeSchema = v.picklist(NOTION_PROPERTY_TYPES);
|
|
87
|
+
/**
|
|
88
|
+
* Property types currently supported by the custom-block data source sort API.
|
|
89
|
+
* Keep this list narrower than {@link NOTION_PROPERTY_TYPES} when a property
|
|
90
|
+
* type is exposed but its sort value is not yet represented by every host.
|
|
91
|
+
*/
|
|
92
|
+
export const CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES = [
|
|
93
|
+
"title",
|
|
94
|
+
"rich_text",
|
|
95
|
+
"number",
|
|
96
|
+
"checkbox",
|
|
97
|
+
"url",
|
|
98
|
+
"email",
|
|
99
|
+
"phone_number",
|
|
100
|
+
"date",
|
|
101
|
+
"created_time",
|
|
102
|
+
"last_edited_time",
|
|
103
|
+
];
|
|
104
|
+
/**
|
|
105
|
+
* Per-property schema as exposed by the host over the custom-block bridge.
|
|
106
|
+
* The `type` discriminator must be one of {@link NOTION_PROPERTY_TYPES}.
|
|
107
|
+
*/
|
|
108
|
+
export const notionPropertySchemaSchema = v.variant("type", [
|
|
109
|
+
v.object({ ...baseProp.entries, type: v.literal("title") }),
|
|
110
|
+
v.object({ ...baseProp.entries, type: v.literal("rich_text") }),
|
|
111
|
+
v.object({ ...baseProp.entries, type: v.literal("number") }),
|
|
112
|
+
v.object({ ...baseProp.entries, type: v.literal("checkbox") }),
|
|
113
|
+
v.object({ ...baseProp.entries, type: v.literal("url") }),
|
|
114
|
+
v.object({ ...baseProp.entries, type: v.literal("email") }),
|
|
115
|
+
v.object({ ...baseProp.entries, type: v.literal("phone_number") }),
|
|
116
|
+
v.object({
|
|
117
|
+
...baseProp.entries,
|
|
118
|
+
type: v.literal("select"),
|
|
119
|
+
options: v.array(notionPropertyOptionSchema),
|
|
120
|
+
}),
|
|
121
|
+
v.object({
|
|
122
|
+
...baseProp.entries,
|
|
123
|
+
type: v.literal("multi_select"),
|
|
124
|
+
options: v.array(notionPropertyOptionSchema),
|
|
125
|
+
}),
|
|
126
|
+
v.object({
|
|
127
|
+
...baseProp.entries,
|
|
128
|
+
type: v.literal("status"),
|
|
129
|
+
options: v.array(notionPropertyOptionSchema),
|
|
130
|
+
groups: v.array(notionStatusGroupSchema),
|
|
131
|
+
}),
|
|
132
|
+
v.object({ ...baseProp.entries, type: v.literal("date") }),
|
|
133
|
+
v.object({ ...baseProp.entries, type: v.literal("people") }),
|
|
134
|
+
v.object({ ...baseProp.entries, type: v.literal("files") }),
|
|
135
|
+
v.object({ ...baseProp.entries, type: v.literal("unique_id") }),
|
|
136
|
+
v.object({
|
|
137
|
+
...baseProp.entries,
|
|
138
|
+
type: v.literal("relation"),
|
|
139
|
+
data_source_id: v.optional(v.string()),
|
|
140
|
+
dual_property: v.optional(notionDualPropertySchema),
|
|
141
|
+
}),
|
|
142
|
+
v.object({ ...baseProp.entries, type: v.literal("place") }),
|
|
143
|
+
v.object({ ...baseProp.entries, type: v.literal("formula") }),
|
|
144
|
+
v.object({ ...baseProp.entries, type: v.literal("rollup") }),
|
|
145
|
+
// Internal-only types passed through under their bridge-native names.
|
|
146
|
+
v.object({ ...baseProp.entries, type: v.literal("button") }),
|
|
147
|
+
v.object({ ...baseProp.entries, type: v.literal("verification") }),
|
|
148
|
+
v.object({ ...baseProp.entries, type: v.literal("last_visited_time") }),
|
|
149
|
+
v.object({ ...baseProp.entries, type: v.literal("location") }),
|
|
150
|
+
// Synthetic built-ins. The host always emits one of each per data source.
|
|
151
|
+
v.object({ ...baseProp.entries, type: v.literal("created_time") }),
|
|
152
|
+
v.object({ ...baseProp.entries, type: v.literal("last_edited_time") }),
|
|
153
|
+
v.object({ ...baseProp.entries, type: v.literal("created_by") }),
|
|
154
|
+
v.object({ ...baseProp.entries, type: v.literal("last_edited_by") }),
|
|
155
|
+
]);
|
|
156
|
+
/**
|
|
157
|
+
* The four synthetic built-in property IDs the host always includes in every
|
|
158
|
+
* data source's `propertySchemasById` and every row's `propertiesById`.
|
|
159
|
+
*/
|
|
160
|
+
export const NOTION_BUILTIN_PROPERTY_IDS = [
|
|
161
|
+
"created_time",
|
|
162
|
+
"last_edited_time",
|
|
163
|
+
"created_by",
|
|
164
|
+
"last_edited_by",
|
|
165
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* A pointer to a record in a database.
|
|
4
|
+
*/
|
|
5
|
+
export declare const notionRecordPointerSchema: v.ObjectSchema<{
|
|
6
|
+
readonly id: v.StringSchema<undefined>;
|
|
7
|
+
readonly table: v.StringSchema<undefined>;
|
|
8
|
+
}, undefined>;
|
|
9
|
+
export type NotionRecordPointer = v.InferOutput<typeof notionRecordPointerSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export type CustomBlockErrorCode<KnownCode extends string> = KnownCode | "unknown_error" | (string & {});
|
|
3
|
+
export type CustomBlockErrorInfo<TCode extends string = string> = {
|
|
4
|
+
code: TCode;
|
|
5
|
+
message: string;
|
|
6
|
+
isRetryable: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const customBlockErrorInfoSchema: v.ObjectSchema<{
|
|
9
|
+
readonly code: v.StringSchema<undefined>;
|
|
10
|
+
readonly message: v.StringSchema<undefined>;
|
|
11
|
+
readonly isRetryable: v.BooleanSchema<undefined>;
|
|
12
|
+
}, undefined>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Branded Notion block ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
4
|
+
* but the brand keeps block IDs from being accidentally mixed with other IDs in TypeScript.
|
|
5
|
+
*/
|
|
6
|
+
export declare const notionBlockIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionBlockId">]>;
|
|
7
|
+
export type NotionBlockId = v.InferOutput<typeof notionBlockIdSchema>;
|
|
8
|
+
/**
|
|
9
|
+
* Branded Notion data source ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
10
|
+
* but the brand keeps data source IDs from being accidentally mixed with other IDs in TypeScript.
|
|
11
|
+
*/
|
|
12
|
+
export declare const notionDataSourceIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>;
|
|
13
|
+
export type NotionDataSourceId = v.InferOutput<typeof notionDataSourceIdSchema>;
|
|
14
|
+
/**
|
|
15
|
+
* Branded Notion page ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
16
|
+
* but the brand keeps page IDs from being accidentally mixed with other IDs in TypeScript.
|
|
17
|
+
*/
|
|
18
|
+
export declare const notionPageIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
19
|
+
export type NotionPageId = v.InferOutput<typeof notionPageIdSchema>;
|
|
20
|
+
/**
|
|
21
|
+
* Branded Notion agent ID. Agent parents identify the workflow that owns an
|
|
22
|
+
* instruction page or one of its blocks.
|
|
23
|
+
*/
|
|
24
|
+
export declare const notionAgentIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionAgentId">]>;
|
|
25
|
+
export type NotionAgentId = v.InferOutput<typeof notionAgentIdSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Branded Notion workspace/space ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
28
|
+
* but the brand keeps space IDs from being accidentally mixed with other IDs in TypeScript.
|
|
29
|
+
*/
|
|
30
|
+
export declare const notionSpaceIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionSpaceId">]>;
|
|
31
|
+
export type NotionSpaceId = v.InferOutput<typeof notionSpaceIdSchema>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Branded Notion block ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
4
|
+
* but the brand keeps block IDs from being accidentally mixed with other IDs in TypeScript.
|
|
5
|
+
*/
|
|
6
|
+
export const notionBlockIdSchema = v.pipe(v.string(), v.brand("NotionBlockId"));
|
|
7
|
+
/**
|
|
8
|
+
* Branded Notion data source ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
9
|
+
* but the brand keeps data source IDs from being accidentally mixed with other IDs in TypeScript.
|
|
10
|
+
*/
|
|
11
|
+
export const notionDataSourceIdSchema = v.pipe(v.string(), v.brand("NotionDataSourceId"));
|
|
12
|
+
/**
|
|
13
|
+
* Branded Notion page ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
14
|
+
* but the brand keeps page IDs from being accidentally mixed with other IDs in TypeScript.
|
|
15
|
+
*/
|
|
16
|
+
export const notionPageIdSchema = v.pipe(v.string(), v.brand("NotionPageId"));
|
|
17
|
+
/**
|
|
18
|
+
* Branded Notion agent ID. Agent parents identify the workflow that owns an
|
|
19
|
+
* instruction page or one of its blocks.
|
|
20
|
+
*/
|
|
21
|
+
export const notionAgentIdSchema = v.pipe(v.string(), v.brand("NotionAgentId"));
|
|
22
|
+
/**
|
|
23
|
+
* Branded Notion workspace/space ID. Host payloads and SDK APIs use plain strings at runtime,
|
|
24
|
+
* but the brand keeps space IDs from being accidentally mixed with other IDs in TypeScript.
|
|
25
|
+
*/
|
|
26
|
+
export const notionSpaceIdSchema = v.pipe(v.string(), v.brand("NotionSpaceId"));
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare function readIncomingType(data: unknown): string | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
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) {
|
|
10
|
+
if (typeof data === "object" &&
|
|
11
|
+
data !== null &&
|
|
12
|
+
"type" in data &&
|
|
13
|
+
typeof data.type === "string") {
|
|
14
|
+
return data.type;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wire contract for custom block sandboxes and hosts.
|
|
3
|
+
*
|
|
4
|
+
* This package contains only protocol data: message schemas, wire types, IDs,
|
|
5
|
+
* errors, manifests, and protocol-version constants. Runtime behavior belongs
|
|
6
|
+
* in either the author SDK or the host package.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./contrast.js";
|
|
9
|
+
export * from "./dataSources/dataSource.js";
|
|
10
|
+
export * from "./dataSources/dataSourcePage.js";
|
|
11
|
+
export * from "./dataSources/dataSourceValue.js";
|
|
12
|
+
export * from "./dataSources/dateValue.js";
|
|
13
|
+
export * from "./dataSources/errors.js";
|
|
14
|
+
export * from "./dataSources/propertySchema.js";
|
|
15
|
+
export * from "./dataSources/recordPointer.js";
|
|
16
|
+
export * from "./errors.js";
|
|
17
|
+
export * from "./ids.js";
|
|
18
|
+
export * from "./incomingType.js";
|
|
19
|
+
export * from "./manifest.js";
|
|
20
|
+
export * from "./messagePayload.js";
|
|
21
|
+
export * from "./messages/connect.js";
|
|
22
|
+
export * from "./messages/contrastModeChanged.js";
|
|
23
|
+
export * from "./messages/createPage.js";
|
|
24
|
+
export * from "./messages/createPageResult.js";
|
|
25
|
+
export * from "./messages/currentUserChanged.js";
|
|
26
|
+
export * from "./messages/dataSourcesChanged.js";
|
|
27
|
+
export * from "./messages/getPage.js";
|
|
28
|
+
export * from "./messages/getUser.js";
|
|
29
|
+
export * from "./messages/hostToSandbox.js";
|
|
30
|
+
export * from "./messages/init.js";
|
|
31
|
+
export * from "./messages/initResult.js";
|
|
32
|
+
export * from "./messages/invalidHostMessage.js";
|
|
33
|
+
export * from "./messages/invalidSandboxMessage.js";
|
|
34
|
+
export * from "./messages/listUsers.js";
|
|
35
|
+
export * from "./messages/pageChanged.js";
|
|
36
|
+
export * from "./messages/parentChanged.js";
|
|
37
|
+
export * from "./messages/queryDataSource.js";
|
|
38
|
+
export * from "./messages/queryDataSourceResult.js";
|
|
39
|
+
export * from "./messages/resize.js";
|
|
40
|
+
export * from "./messages/sandboxToHost.js";
|
|
41
|
+
export * from "./messages/themeChanged.js";
|
|
42
|
+
export * from "./messages/updatePage.js";
|
|
43
|
+
export * from "./messages/updatePageResult.js";
|
|
44
|
+
export * from "./pages/page.js";
|
|
45
|
+
export * from "./parent.js";
|
|
46
|
+
export * from "./protocolVersion.js";
|
|
47
|
+
export * from "./theme.js";
|
|
48
|
+
export * from "./users/user.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wire contract for custom block sandboxes and hosts.
|
|
3
|
+
*
|
|
4
|
+
* This package contains only protocol data: message schemas, wire types, IDs,
|
|
5
|
+
* errors, manifests, and protocol-version constants. Runtime behavior belongs
|
|
6
|
+
* in either the author SDK or the host package.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./contrast.js";
|
|
9
|
+
export * from "./dataSources/dataSource.js";
|
|
10
|
+
export * from "./dataSources/dataSourcePage.js";
|
|
11
|
+
export * from "./dataSources/dataSourceValue.js";
|
|
12
|
+
export * from "./dataSources/dateValue.js";
|
|
13
|
+
export * from "./dataSources/errors.js";
|
|
14
|
+
export * from "./dataSources/propertySchema.js";
|
|
15
|
+
export * from "./dataSources/recordPointer.js";
|
|
16
|
+
export * from "./errors.js";
|
|
17
|
+
export * from "./ids.js";
|
|
18
|
+
export * from "./incomingType.js";
|
|
19
|
+
export * from "./manifest.js";
|
|
20
|
+
export * from "./messagePayload.js";
|
|
21
|
+
export * from "./messages/connect.js";
|
|
22
|
+
export * from "./messages/contrastModeChanged.js";
|
|
23
|
+
export * from "./messages/createPage.js";
|
|
24
|
+
export * from "./messages/createPageResult.js";
|
|
25
|
+
export * from "./messages/currentUserChanged.js";
|
|
26
|
+
export * from "./messages/dataSourcesChanged.js";
|
|
27
|
+
export * from "./messages/getPage.js";
|
|
28
|
+
export * from "./messages/getUser.js";
|
|
29
|
+
export * from "./messages/hostToSandbox.js";
|
|
30
|
+
export * from "./messages/init.js";
|
|
31
|
+
export * from "./messages/initResult.js";
|
|
32
|
+
export * from "./messages/invalidHostMessage.js";
|
|
33
|
+
export * from "./messages/invalidSandboxMessage.js";
|
|
34
|
+
export * from "./messages/listUsers.js";
|
|
35
|
+
export * from "./messages/pageChanged.js";
|
|
36
|
+
export * from "./messages/parentChanged.js";
|
|
37
|
+
export * from "./messages/queryDataSource.js";
|
|
38
|
+
export * from "./messages/queryDataSourceResult.js";
|
|
39
|
+
export * from "./messages/resize.js";
|
|
40
|
+
export * from "./messages/sandboxToHost.js";
|
|
41
|
+
export * from "./messages/themeChanged.js";
|
|
42
|
+
export * from "./messages/updatePage.js";
|
|
43
|
+
export * from "./messages/updatePageResult.js";
|
|
44
|
+
export * from "./pages/page.js";
|
|
45
|
+
export * from "./parent.js";
|
|
46
|
+
export * from "./protocolVersion.js";
|
|
47
|
+
export * from "./theme.js";
|
|
48
|
+
export * from "./users/user.js";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Decorative icon attached to a manifest data source. Mirrors the
|
|
4
|
+
* `emoji` / `external` icon variants the public Notion API uses, so the host
|
|
5
|
+
* can render a recognizable affordance next to the slot in setup UI.
|
|
6
|
+
*/
|
|
7
|
+
export declare const manifestIconSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
8
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
9
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
10
|
+
}, undefined>, v.ObjectSchema<{
|
|
11
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
12
|
+
readonly url: v.StringSchema<undefined>;
|
|
13
|
+
}, undefined>], undefined>;
|
|
14
|
+
export type ManifestIcon = v.InferOutput<typeof manifestIconSchema>;
|
|
15
|
+
export declare const manifestPropertySchema: v.ObjectSchema<{
|
|
16
|
+
readonly name: v.StringSchema<undefined>;
|
|
17
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
18
|
+
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>;
|
|
19
|
+
}, undefined>;
|
|
20
|
+
export type ManifestProperty = v.InferOutput<typeof manifestPropertySchema>;
|
|
21
|
+
export declare const manifestDataSourceSchema: v.ObjectSchema<{
|
|
22
|
+
readonly name: v.StringSchema<undefined>;
|
|
23
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
24
|
+
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
25
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
26
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
27
|
+
}, undefined>, v.ObjectSchema<{
|
|
28
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
29
|
+
readonly url: v.StringSchema<undefined>;
|
|
30
|
+
}, undefined>], undefined>, undefined>;
|
|
31
|
+
readonly properties: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
32
|
+
readonly name: v.StringSchema<undefined>;
|
|
33
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
34
|
+
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>;
|
|
35
|
+
}, undefined>, undefined>, {}>;
|
|
36
|
+
}, undefined>;
|
|
37
|
+
export type ManifestDataSource = v.InferOutput<typeof manifestDataSourceSchema>;
|
|
38
|
+
export declare const manifestSchema: v.ObjectSchema<{
|
|
39
|
+
readonly version: v.LiteralSchema<1, undefined>;
|
|
40
|
+
readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
41
|
+
readonly name: v.StringSchema<undefined>;
|
|
42
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
43
|
+
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
44
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
45
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
46
|
+
}, undefined>, v.ObjectSchema<{
|
|
47
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
48
|
+
readonly url: v.StringSchema<undefined>;
|
|
49
|
+
}, undefined>], undefined>, undefined>;
|
|
50
|
+
readonly properties: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
51
|
+
readonly name: v.StringSchema<undefined>;
|
|
52
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
53
|
+
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
|
+
}, undefined>, undefined>, {}>;
|
|
55
|
+
}, undefined>, undefined>;
|
|
56
|
+
}, undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* Manifest declaring the data sources required by a custom block.
|
|
59
|
+
*/
|
|
60
|
+
export type CustomBlockManifest = v.InferOutput<typeof manifestSchema>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { notionPropertyTypeSchema } from "./dataSources/propertySchema.js";
|
|
3
|
+
/**
|
|
4
|
+
* Decorative icon attached to a manifest data source. Mirrors the
|
|
5
|
+
* `emoji` / `external` icon variants the public Notion API uses, so the host
|
|
6
|
+
* can render a recognizable affordance next to the slot in setup UI.
|
|
7
|
+
*/
|
|
8
|
+
export const manifestIconSchema = v.variant("type", [
|
|
9
|
+
v.object({
|
|
10
|
+
type: v.literal("emoji"),
|
|
11
|
+
emoji: v.string(),
|
|
12
|
+
}),
|
|
13
|
+
v.object({
|
|
14
|
+
type: v.literal("external"),
|
|
15
|
+
url: v.string(),
|
|
16
|
+
}),
|
|
17
|
+
]);
|
|
18
|
+
export const manifestPropertySchema = v.object({
|
|
19
|
+
name: v.string(),
|
|
20
|
+
description: v.optional(v.string()),
|
|
21
|
+
type: notionPropertyTypeSchema,
|
|
22
|
+
});
|
|
23
|
+
export const manifestDataSourceSchema = v.object({
|
|
24
|
+
name: v.string(),
|
|
25
|
+
description: v.optional(v.string()),
|
|
26
|
+
icon: v.optional(manifestIconSchema),
|
|
27
|
+
properties: v.optional(v.record(v.string(), manifestPropertySchema), {}),
|
|
28
|
+
});
|
|
29
|
+
export const manifestSchema = v.object({
|
|
30
|
+
version: v.literal(1),
|
|
31
|
+
dataSources: v.record(v.string(), manifestDataSourceSchema),
|
|
32
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CustomBlockErrorInfo } from "./errors.js";
|
|
2
|
+
type WithTypedErrorInfo<T, TErrorInfo extends CustomBlockErrorInfo | undefined> = TErrorInfo extends CustomBlockErrorInfo ? T extends {
|
|
3
|
+
error: CustomBlockErrorInfo;
|
|
4
|
+
} ? Omit<T, "error"> & {
|
|
5
|
+
error: TErrorInfo;
|
|
6
|
+
} : T : T;
|
|
7
|
+
/**
|
|
8
|
+
* Removes bridge envelope fields from every member of a message union.
|
|
9
|
+
*
|
|
10
|
+
* The conditional type makes the operation distributive, preserving
|
|
11
|
+
* success/error-specific fields such as `page` and `error`.
|
|
12
|
+
*
|
|
13
|
+
* Pass an API-specific error-info type to preserve its known error-code
|
|
14
|
+
* literals while still accepting unknown string codes at runtime.
|
|
15
|
+
*/
|
|
16
|
+
export type BridgeMessagePayload<T extends {
|
|
17
|
+
type: string;
|
|
18
|
+
}, TErrorInfo extends CustomBlockErrorInfo | undefined = undefined> = T extends unknown ? WithTypedErrorInfo<Omit<T, "type" | "requestId" | "subscriptionId">, TErrorInfo> : never;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* First message the sandbox sends after mount. It identifies the sandbox and starts the bridge
|
|
4
|
+
* initialization exchange. The host echoes `initializationId` in its `init` response.
|
|
5
|
+
*/
|
|
6
|
+
export declare const connectMessageSchema: v.VariantSchema<"status", [v.ObjectSchema<{
|
|
7
|
+
readonly type: v.LiteralSchema<"connect", undefined>;
|
|
8
|
+
readonly initializationId: v.StringSchema<undefined>;
|
|
9
|
+
readonly bridgeProtocolVersion: v.NumberSchema<undefined>;
|
|
10
|
+
readonly sdkVersion: v.StringSchema<undefined>;
|
|
11
|
+
readonly status: v.LiteralSchema<"success", undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* The data sources and settings the custom block expects. Hosts may omit
|
|
14
|
+
* this when they already have an authoritative manifest.
|
|
15
|
+
*/
|
|
16
|
+
readonly manifest: v.OptionalSchema<v.ObjectSchema<{
|
|
17
|
+
readonly version: v.LiteralSchema<1, undefined>;
|
|
18
|
+
readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
19
|
+
readonly name: v.StringSchema<undefined>;
|
|
20
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
21
|
+
readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
22
|
+
readonly type: v.LiteralSchema<"emoji", undefined>;
|
|
23
|
+
readonly emoji: v.StringSchema<undefined>;
|
|
24
|
+
}, undefined>, v.ObjectSchema<{
|
|
25
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
26
|
+
readonly url: v.StringSchema<undefined>;
|
|
27
|
+
}, undefined>], undefined>, undefined>;
|
|
28
|
+
readonly properties: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
29
|
+
readonly name: v.StringSchema<undefined>;
|
|
30
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
31
|
+
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
|
+
}, undefined>, undefined>, {}>;
|
|
33
|
+
}, undefined>, undefined>;
|
|
34
|
+
}, undefined>, undefined>;
|
|
35
|
+
}, undefined>, v.ObjectSchema<{
|
|
36
|
+
readonly type: v.LiteralSchema<"connect", undefined>;
|
|
37
|
+
readonly initializationId: v.StringSchema<undefined>;
|
|
38
|
+
readonly bridgeProtocolVersion: v.NumberSchema<undefined>;
|
|
39
|
+
readonly sdkVersion: v.StringSchema<undefined>;
|
|
40
|
+
readonly status: v.LiteralSchema<"error", undefined>;
|
|
41
|
+
readonly error: v.ObjectSchema<{
|
|
42
|
+
readonly code: v.StringSchema<undefined>;
|
|
43
|
+
readonly message: v.StringSchema<undefined>;
|
|
44
|
+
readonly isRetryable: v.BooleanSchema<undefined>;
|
|
45
|
+
}, undefined>;
|
|
46
|
+
}, undefined>], undefined>;
|
|
47
|
+
export type ConnectMessage = v.InferOutput<typeof connectMessageSchema>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { customBlockErrorInfoSchema } from "../errors.js";
|
|
3
|
+
import { manifestSchema } from "../manifest.js";
|
|
4
|
+
const connectMessageCommonEntries = {
|
|
5
|
+
type: v.literal("connect"),
|
|
6
|
+
initializationId: v.string(),
|
|
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 connect message. Should only be used for
|
|
15
|
+
* analytics purposes. Business logic should compare against `bridgeProtocolVersion` instead.
|
|
16
|
+
*/
|
|
17
|
+
sdkVersion: v.string(),
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* First message the sandbox sends after mount. It identifies the sandbox and starts the bridge
|
|
21
|
+
* initialization exchange. The host echoes `initializationId` in its `init` response.
|
|
22
|
+
*/
|
|
23
|
+
export const connectMessageSchema = v.variant("status", [
|
|
24
|
+
v.object({
|
|
25
|
+
status: v.literal("success"),
|
|
26
|
+
/**
|
|
27
|
+
* The data sources and settings the custom block expects. Hosts may omit
|
|
28
|
+
* this when they already have an authoritative manifest.
|
|
29
|
+
*/
|
|
30
|
+
manifest: v.optional(manifestSchema),
|
|
31
|
+
...connectMessageCommonEntries,
|
|
32
|
+
}),
|
|
33
|
+
v.object({
|
|
34
|
+
status: v.literal("error"),
|
|
35
|
+
error: customBlockErrorInfoSchema,
|
|
36
|
+
...connectMessageCommonEntries,
|
|
37
|
+
}),
|
|
38
|
+
]);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** Message sent by the host when contrast changes after initialization. */
|
|
3
|
+
export declare const contrastModeChangedMessageSchema: v.ObjectSchema<{
|
|
4
|
+
readonly type: v.LiteralSchema<"contrastModeChanged", undefined>;
|
|
5
|
+
readonly contrastMode: v.PicklistSchema<["standard", "high"], undefined>;
|
|
6
|
+
}, undefined>;
|
|
7
|
+
export type ContrastModeChangedMessage = v.InferOutput<typeof contrastModeChangedMessageSchema>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { notionContrastModeSchema } from "../contrast.js";
|
|
3
|
+
/** Message sent by the host when contrast changes after initialization. */
|
|
4
|
+
export const contrastModeChangedMessageSchema = v.object({
|
|
5
|
+
type: v.literal("contrastModeChanged"),
|
|
6
|
+
contrastMode: notionContrastModeSchema,
|
|
7
|
+
});
|