@notionhq/custom-blocks-host 0.3.8 → 0.4.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/LICENSE +21 -0
- package/README.md +143 -225
- package/THIRD_PARTY_LICENSES.md +9 -0
- package/dist/autoBindProperties.d.ts +5 -2
- package/dist/autoBindProperties.d.ts.map +1 -1
- package/dist/autoBindProperties.js +5 -2
- package/dist/browser.js +1 -1
- package/dist/compatibility/addMetadataReadSchemasForProtocol3To4.d.ts +1215 -0
- package/dist/compatibility/addMetadataReadSchemasForProtocol3To4.d.ts.map +1 -0
- package/dist/compatibility/addMetadataReadSchemasForProtocol3To4.js +27 -0
- package/dist/compatibility/normalizeHostToSandboxMessage.d.ts +8 -0
- package/dist/compatibility/normalizeHostToSandboxMessage.d.ts.map +1 -0
- package/dist/compatibility/normalizeHostToSandboxMessage.js +39 -0
- package/dist/compatibility/normalizePageResultsForProtocol3To5.d.ts +11 -0
- package/dist/compatibility/normalizePageResultsForProtocol3To5.d.ts.map +1 -0
- package/dist/compatibility/normalizePageResultsForProtocol3To5.js +18 -0
- package/dist/compatibility/normalizePageResultsForProtocol6.d.ts +9 -0
- package/dist/compatibility/normalizePageResultsForProtocol6.d.ts.map +1 -0
- package/dist/compatibility/normalizePageResultsForProtocol6.js +18 -0
- package/dist/compatibility/normalizeSandboxToHostMessage.d.ts +1091 -0
- package/dist/compatibility/normalizeSandboxToHostMessage.d.ts.map +1 -0
- package/dist/compatibility/normalizeSandboxToHostMessage.js +9 -0
- package/dist/compatibility/pageForProtocol3To5.d.ts +159 -0
- package/dist/compatibility/pageForProtocol3To5.d.ts.map +1 -0
- package/dist/{lifecycle/legacyPage.js → compatibility/pageForProtocol3To5.js} +50 -9
- package/dist/compatibility/pageResult.d.ts +11 -0
- package/dist/compatibility/pageResult.d.ts.map +1 -0
- package/dist/compatibility/pageWithNullTextFallbackProperties.d.ts +9 -0
- package/dist/compatibility/pageWithNullTextFallbackProperties.d.ts.map +1 -0
- package/dist/compatibility/pageWithNullTextFallbackProperties.js +46 -0
- package/dist/createCustomBlockHost.d.ts +18 -19
- package/dist/createCustomBlockHost.d.ts.map +1 -1
- package/dist/createCustomBlockHost.js +103 -38
- package/dist/index.d.ts +2 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/{localBlockUrl.d.ts → isAllowedLocalPreviewUrl.d.ts} +2 -2
- package/dist/isAllowedLocalPreviewUrl.d.ts.map +1 -0
- package/dist/{localBlockUrl.js → isAllowedLocalPreviewUrl.js} +3 -7
- package/dist/lifecycle/initErrors.d.ts +1 -0
- package/dist/lifecycle/initErrors.d.ts.map +1 -1
- package/dist/lifecycle/initErrors.js +7 -0
- package/dist/lifecycle/initializationController.d.ts +6 -4
- package/dist/lifecycle/initializationController.d.ts.map +1 -1
- package/dist/lifecycle/initializationController.js +24 -15
- package/dist/lifecycle/resolveManifest.d.ts +13 -0
- package/dist/lifecycle/resolveManifest.d.ts.map +1 -0
- package/dist/lifecycle/resolveManifest.js +21 -0
- package/dist/lifecycle/types.d.ts +1637 -17
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/lifecycle/types.js +18 -0
- package/dist/messages/sandboxMessageRouter.d.ts.map +1 -1
- package/dist/messages/sandboxMessageRouter.js +2 -2
- package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -4
- package/dist/protocol/dataSources/dataSourcePage.js +2 -3
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/isLocalBlockServerUrl.d.ts +2 -0
- package/dist/protocol/isLocalBlockServerUrl.js +9 -0
- package/dist/protocol/messages/connect.d.ts +2 -2
- package/dist/protocol/messages/connect.js +2 -2
- package/dist/protocol/messages/createPageResult.d.ts +2 -2
- package/dist/protocol/messages/createPageResult.js +3 -3
- package/dist/protocol/messages/getPage.d.ts +2 -2
- package/dist/protocol/messages/getPage.js +3 -3
- package/dist/protocol/messages/hostToSandbox.d.ts +3 -3
- package/dist/protocol/messages/hostToSandbox.js +10 -10
- package/dist/protocol/messages/init.d.ts +1 -1
- package/dist/protocol/messages/queryDataSourceResult.d.ts +3 -3
- package/dist/protocol/messages/queryDataSourceResult.js +6 -3
- package/dist/protocol/messages/updatePageResult.d.ts +2 -2
- package/dist/protocol/messages/updatePageResult.js +3 -3
- package/dist/protocol/pages/page.d.ts +2 -2
- package/dist/protocol/pages/page.js +1 -1
- package/dist/protocol/protocolVersion.d.ts +3 -2
- package/dist/protocol/protocolVersion.js +4 -2
- package/dist/protocol.d.ts +9 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +8 -0
- package/docs/bridge/changelog.md +67 -0
- package/docs/bridge/protocol.md +182 -0
- package/docs/bridge/versioning.md +38 -0
- package/docs/compatibility.md +68 -0
- package/docs/handlers.md +199 -0
- package/docs/lifecycle.md +117 -0
- package/package.json +11 -3
- package/src/autoBindProperties.ts +5 -2
- package/src/compatibility/addMetadataReadSchemasForProtocol3To4.ts +36 -0
- package/src/compatibility/normalizeHostToSandboxMessage.ts +54 -0
- package/src/compatibility/normalizePageResultsForProtocol3To5.ts +28 -0
- package/src/compatibility/normalizePageResultsForProtocol6.ts +23 -0
- package/src/compatibility/normalizeSandboxToHostMessage.ts +10 -0
- package/src/{lifecycle/legacyPage.ts → compatibility/pageForProtocol3To5.ts} +52 -11
- package/src/compatibility/pageResult.ts +18 -0
- package/src/compatibility/pageWithNullTextFallbackProperties.ts +53 -0
- package/src/createCustomBlockHost.ts +152 -62
- package/src/index.ts +4 -51
- package/src/{localBlockUrl.ts → isAllowedLocalPreviewUrl.ts} +4 -7
- package/src/lifecycle/initErrors.ts +9 -0
- package/src/lifecycle/initializationController.ts +34 -19
- package/src/lifecycle/resolveManifest.ts +31 -0
- package/src/lifecycle/types.ts +84 -16
- package/src/messages/sandboxMessageRouter.ts +2 -2
- package/src/protocol.ts +8 -0
- package/dist/lifecycle/legacyPage.d.ts +0 -70
- package/dist/lifecycle/legacyPage.d.ts.map +0 -1
- package/dist/lifecycle/loadCustomBlockManifest.d.ts +0 -16
- package/dist/lifecycle/loadCustomBlockManifest.d.ts.map +0 -1
- package/dist/lifecycle/loadCustomBlockManifest.js +0 -65
- package/dist/lifecycle/manifestOptions.d.ts +0 -17
- package/dist/lifecycle/manifestOptions.d.ts.map +0 -1
- package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts +0 -6
- package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts.map +0 -1
- package/dist/lifecycle/normalizeHostToSandboxMessage.js +0 -16
- package/dist/lifecycle/normalizePage.d.ts +0 -7
- package/dist/lifecycle/normalizePage.d.ts.map +0 -1
- package/dist/lifecycle/normalizePage.js +0 -22
- package/dist/localBlockUrl.d.ts.map +0 -1
- package/src/lifecycle/loadCustomBlockManifest.ts +0 -89
- package/src/lifecycle/manifestOptions.ts +0 -19
- package/src/lifecycle/normalizeHostToSandboxMessage.ts +0 -29
- package/src/lifecycle/normalizePage.ts +0 -35
- /package/dist/{lifecycle/manifestOptions.js → compatibility/pageResult.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeSandboxToHostMessage.d.ts","sourceRoot":"","sources":["../../src/compatibility/normalizeSandboxToHostMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAE7D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { sandboxToHostMessageSchema } from "../protocol/messages/sandboxToHost.js";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
/**
|
|
4
|
+
* Validates sandbox wire messages before handler dispatch. Supported requests
|
|
5
|
+
* currently share one schema, so parsing produces the current handler shape.
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeSandboxToHostMessage(payload) {
|
|
8
|
+
return v.safeParse(sandboxToHostMessageSchema, payload);
|
|
9
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { NotionPageForProtocol3To5, notionPageDataSchema } from "../protocol/pages/page.js";
|
|
2
|
+
import type { InferOutput } from "valibot";
|
|
3
|
+
/**
|
|
4
|
+
* Converts current page data to the page-operation format used by protocols 3–5.
|
|
5
|
+
* Keys property objects by raw ID and omits null properties. Optional icons,
|
|
6
|
+
* covers, timestamps, and URLs use undefined instead of null in this format.
|
|
7
|
+
* Call after clearing property objects unsupported by these protocols.
|
|
8
|
+
*
|
|
9
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toPageForProtocol3To5(page: InferOutput<typeof notionPageDataSchema>): NotionPageForProtocol3To5;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a current page to a protocol 3–5 query row, keeping its ID and archive
|
|
14
|
+
* flags while flattening typed property objects into raw-ID-keyed values.
|
|
15
|
+
* Copies page creation and edit metadata into the reserved property IDs that
|
|
16
|
+
* these query readers expect.
|
|
17
|
+
*
|
|
18
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toQueryPageForProtocol3To5(page: InferOutput<typeof notionPageDataSchema>): {
|
|
21
|
+
id: string & import("valibot").Brand<"NotionPageId">;
|
|
22
|
+
is_archived: boolean;
|
|
23
|
+
in_trash: boolean;
|
|
24
|
+
propertiesById: {
|
|
25
|
+
created_time: string | number | boolean | string[] | {
|
|
26
|
+
id: string;
|
|
27
|
+
table: string;
|
|
28
|
+
}[] | {
|
|
29
|
+
type: "date";
|
|
30
|
+
start_date: string;
|
|
31
|
+
reminder?: {
|
|
32
|
+
unit: "day" | "month" | "week" | "year";
|
|
33
|
+
value: number;
|
|
34
|
+
time: string;
|
|
35
|
+
defaultTimeZone?: string | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
unit: "none";
|
|
38
|
+
} | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
type: "daterange";
|
|
41
|
+
start_date: string;
|
|
42
|
+
end_date: string;
|
|
43
|
+
reminder?: {
|
|
44
|
+
unit: "day" | "month" | "week" | "year";
|
|
45
|
+
value: number;
|
|
46
|
+
time: string;
|
|
47
|
+
defaultTimeZone?: string | undefined;
|
|
48
|
+
} | {
|
|
49
|
+
unit: "none";
|
|
50
|
+
} | undefined;
|
|
51
|
+
} | {
|
|
52
|
+
type: "datetime";
|
|
53
|
+
start_date: string;
|
|
54
|
+
start_time: string;
|
|
55
|
+
time_zone?: string | undefined;
|
|
56
|
+
reminder?: {
|
|
57
|
+
unit: "day" | "month" | "week" | "year";
|
|
58
|
+
value: number;
|
|
59
|
+
time: string;
|
|
60
|
+
defaultTimeZone?: string | undefined;
|
|
61
|
+
} | {
|
|
62
|
+
unit: "hour" | "minute";
|
|
63
|
+
value: number;
|
|
64
|
+
} | {
|
|
65
|
+
unit: "none";
|
|
66
|
+
} | undefined;
|
|
67
|
+
} | {
|
|
68
|
+
type: "datetimerange";
|
|
69
|
+
start_date: string;
|
|
70
|
+
start_time: string;
|
|
71
|
+
end_date: string;
|
|
72
|
+
end_time: string;
|
|
73
|
+
time_zone?: string | undefined;
|
|
74
|
+
reminder?: {
|
|
75
|
+
unit: "day" | "month" | "week" | "year";
|
|
76
|
+
value: number;
|
|
77
|
+
time: string;
|
|
78
|
+
defaultTimeZone?: string | undefined;
|
|
79
|
+
} | {
|
|
80
|
+
unit: "hour" | "minute";
|
|
81
|
+
value: number;
|
|
82
|
+
} | {
|
|
83
|
+
unit: "none";
|
|
84
|
+
} | undefined;
|
|
85
|
+
} | undefined;
|
|
86
|
+
last_edited_time: string | number | boolean | string[] | {
|
|
87
|
+
id: string;
|
|
88
|
+
table: string;
|
|
89
|
+
}[] | {
|
|
90
|
+
type: "date";
|
|
91
|
+
start_date: string;
|
|
92
|
+
reminder?: {
|
|
93
|
+
unit: "day" | "month" | "week" | "year";
|
|
94
|
+
value: number;
|
|
95
|
+
time: string;
|
|
96
|
+
defaultTimeZone?: string | undefined;
|
|
97
|
+
} | {
|
|
98
|
+
unit: "none";
|
|
99
|
+
} | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
type: "daterange";
|
|
102
|
+
start_date: string;
|
|
103
|
+
end_date: string;
|
|
104
|
+
reminder?: {
|
|
105
|
+
unit: "day" | "month" | "week" | "year";
|
|
106
|
+
value: number;
|
|
107
|
+
time: string;
|
|
108
|
+
defaultTimeZone?: string | undefined;
|
|
109
|
+
} | {
|
|
110
|
+
unit: "none";
|
|
111
|
+
} | undefined;
|
|
112
|
+
} | {
|
|
113
|
+
type: "datetime";
|
|
114
|
+
start_date: string;
|
|
115
|
+
start_time: string;
|
|
116
|
+
time_zone?: string | undefined;
|
|
117
|
+
reminder?: {
|
|
118
|
+
unit: "day" | "month" | "week" | "year";
|
|
119
|
+
value: number;
|
|
120
|
+
time: string;
|
|
121
|
+
defaultTimeZone?: string | undefined;
|
|
122
|
+
} | {
|
|
123
|
+
unit: "hour" | "minute";
|
|
124
|
+
value: number;
|
|
125
|
+
} | {
|
|
126
|
+
unit: "none";
|
|
127
|
+
} | undefined;
|
|
128
|
+
} | {
|
|
129
|
+
type: "datetimerange";
|
|
130
|
+
start_date: string;
|
|
131
|
+
start_time: string;
|
|
132
|
+
end_date: string;
|
|
133
|
+
end_time: string;
|
|
134
|
+
time_zone?: string | undefined;
|
|
135
|
+
reminder?: {
|
|
136
|
+
unit: "day" | "month" | "week" | "year";
|
|
137
|
+
value: number;
|
|
138
|
+
time: string;
|
|
139
|
+
defaultTimeZone?: string | undefined;
|
|
140
|
+
} | {
|
|
141
|
+
unit: "hour" | "minute";
|
|
142
|
+
value: number;
|
|
143
|
+
} | {
|
|
144
|
+
unit: "none";
|
|
145
|
+
} | undefined;
|
|
146
|
+
} | undefined;
|
|
147
|
+
created_by: {
|
|
148
|
+
id: string;
|
|
149
|
+
table: "bot" | "notion_user" | "organization_bot";
|
|
150
|
+
spaceId?: string | undefined;
|
|
151
|
+
}[] | undefined;
|
|
152
|
+
last_edited_by: {
|
|
153
|
+
id: string;
|
|
154
|
+
table: "bot" | "notion_user" | "organization_bot";
|
|
155
|
+
spaceId?: string | undefined;
|
|
156
|
+
}[] | undefined;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=pageForProtocol3To5.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageForProtocol3To5.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageForProtocol3To5.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,yBAAyB,EAEzB,oBAAoB,EACpB,MAAM,gDAAgD,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,GAC5C,yBAAyB,CAe3B;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsB9C"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { toNotionDateValue } from "../dateValue.js";
|
|
2
2
|
import { unreachable } from "../utils.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Converts current page data to the page-operation format used by protocols 3–5.
|
|
5
|
+
* Keys property objects by raw ID and omits null properties. Optional icons,
|
|
6
|
+
* covers, timestamps, and URLs use undefined instead of null in this format.
|
|
7
|
+
* Call after clearing property objects unsupported by these protocols.
|
|
8
|
+
*
|
|
9
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
10
|
+
*/
|
|
11
|
+
export function toPageForProtocol3To5(page) {
|
|
4
12
|
return {
|
|
5
13
|
...page,
|
|
6
14
|
properties: Object.fromEntries(Object.values(page.properties).flatMap(property => property ? [[property.id, property]] : [])),
|
|
@@ -12,20 +20,41 @@ export function toLegacyPage(page) {
|
|
|
12
20
|
public_url: page.public_url ?? undefined,
|
|
13
21
|
};
|
|
14
22
|
}
|
|
15
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Converts a current page to a protocol 3–5 query row, keeping its ID and archive
|
|
25
|
+
* flags while flattening typed property objects into raw-ID-keyed values.
|
|
26
|
+
* Copies page creation and edit metadata into the reserved property IDs that
|
|
27
|
+
* these query readers expect.
|
|
28
|
+
*
|
|
29
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
30
|
+
*/
|
|
31
|
+
export function toQueryPageForProtocol3To5(page) {
|
|
16
32
|
const propertiesById = {};
|
|
17
33
|
for (const property of Object.values(page.properties)) {
|
|
18
34
|
if (property) {
|
|
19
|
-
propertiesById[property.id] =
|
|
35
|
+
propertiesById[property.id] = toPropertyValueForProtocol3To5(property);
|
|
20
36
|
}
|
|
21
37
|
}
|
|
22
38
|
return {
|
|
23
39
|
id: page.id,
|
|
24
40
|
is_archived: page.is_archived,
|
|
25
41
|
in_trash: page.in_trash,
|
|
26
|
-
|
|
42
|
+
// Reserved metadata IDs retain their historical meaning even if an actual
|
|
43
|
+
// property uses the same ID. Binding schemas use the same precedence.
|
|
44
|
+
propertiesById: {
|
|
45
|
+
...propertiesById,
|
|
46
|
+
created_time: toDateTimeValueForProtocol3To5(page.created_time),
|
|
47
|
+
last_edited_time: toDateTimeValueForProtocol3To5(page.last_edited_time),
|
|
48
|
+
created_by: page.created_by ? [page.created_by] : undefined,
|
|
49
|
+
last_edited_by: page.last_edited_by ? [page.last_edited_by] : undefined,
|
|
50
|
+
},
|
|
27
51
|
};
|
|
28
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Flattens rich-text items to the string used by protocol 3–5 query values.
|
|
55
|
+
*
|
|
56
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
57
|
+
*/
|
|
29
58
|
function plainText(items) {
|
|
30
59
|
return items
|
|
31
60
|
.map(item => {
|
|
@@ -42,7 +71,13 @@ function plainText(items) {
|
|
|
42
71
|
})
|
|
43
72
|
.join("");
|
|
44
73
|
}
|
|
45
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Converts a timestamp to the UTC date/time object used by protocol 3–5 queries.
|
|
76
|
+
* Missing or invalid timestamps produce undefined; time is stored to the minute.
|
|
77
|
+
*
|
|
78
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
79
|
+
*/
|
|
80
|
+
function toDateTimeValueForProtocol3To5(value) {
|
|
46
81
|
if (value === undefined || value === null || value === "") {
|
|
47
82
|
return undefined;
|
|
48
83
|
}
|
|
@@ -57,7 +92,13 @@ function timestamp(value) {
|
|
|
57
92
|
time_zone: "UTC",
|
|
58
93
|
};
|
|
59
94
|
}
|
|
60
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Converts a typed page property to the scalar, list, record-reference, or
|
|
97
|
+
* date/time value used by protocol 3–5 query results.
|
|
98
|
+
*
|
|
99
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 6.
|
|
100
|
+
*/
|
|
101
|
+
function toPropertyValueForProtocol3To5(property) {
|
|
61
102
|
switch (property.type) {
|
|
62
103
|
case "title":
|
|
63
104
|
return plainText(property.title);
|
|
@@ -108,11 +149,11 @@ function toLegacyProperty(property) {
|
|
|
108
149
|
case "place":
|
|
109
150
|
return "";
|
|
110
151
|
case "created_time":
|
|
111
|
-
return
|
|
152
|
+
return toDateTimeValueForProtocol3To5(property.created_time);
|
|
112
153
|
case "last_edited_time":
|
|
113
|
-
return
|
|
154
|
+
return toDateTimeValueForProtocol3To5(property.last_edited_time);
|
|
114
155
|
case "last_visited_time":
|
|
115
|
-
return
|
|
156
|
+
return toDateTimeValueForProtocol3To5(property.last_visited_time);
|
|
116
157
|
case "created_by":
|
|
117
158
|
return property.created_by ? [property.created_by] : undefined;
|
|
118
159
|
case "last_edited_by":
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HostToSandboxMessage } from "../protocol/messages/hostToSandbox.js";
|
|
2
|
+
/**
|
|
3
|
+
* Page-bearing responses accepted by the target-protocol adapters. The dispatcher
|
|
4
|
+
* passes errors and unrelated messages through unchanged before calling them.
|
|
5
|
+
* Sharing this subset keeps both adapters limited to successful page conversions.
|
|
6
|
+
*/
|
|
7
|
+
export type SuccessfulPageResult = Extract<HostToSandboxMessage, {
|
|
8
|
+
type: "queryDataSourceResult" | "getPageResult" | "createPageResult" | "updatePageResult";
|
|
9
|
+
status: "success";
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=pageResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageResult.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AAEtG;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACzC,oBAAoB,EACpB;IACC,IAAI,EACD,uBAAuB,GACvB,eAAe,GACf,kBAAkB,GAClB,kBAAkB,CAAA;IACrB,MAAM,EAAE,SAAS,CAAA;CACjB,CACD,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { notionPageDataSchema } from "../protocol/pages/page.js";
|
|
2
|
+
import type { InferOutput } from "valibot";
|
|
3
|
+
/**
|
|
4
|
+
* Shared field conversion for receivers that cannot decode text fallback objects.
|
|
5
|
+
*
|
|
6
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 7.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toPageWithNullTextFallbackProperties(page: InferOutput<typeof notionPageDataSchema>): InferOutput<typeof notionPageDataSchema>;
|
|
9
|
+
//# sourceMappingURL=pageWithNullTextFallbackProperties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageWithNullTextFallbackProperties.d.ts","sourceRoot":"","sources":["../../src/compatibility/pageWithNullTextFallbackProperties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C;;;;GAIG;AACH,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,GAC5C,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAyC1C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { unreachable } from "../utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Shared field conversion for receivers that cannot decode text fallback objects.
|
|
4
|
+
*
|
|
5
|
+
* Delete when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION >= 7.
|
|
6
|
+
*/
|
|
7
|
+
export function toPageWithNullTextFallbackProperties(page) {
|
|
8
|
+
return {
|
|
9
|
+
...page,
|
|
10
|
+
properties: Object.fromEntries(Object.entries(page.properties).map(([name, property]) => {
|
|
11
|
+
switch (property?.type) {
|
|
12
|
+
case "unique_id":
|
|
13
|
+
case "button":
|
|
14
|
+
case "formula":
|
|
15
|
+
case "location":
|
|
16
|
+
case "rollup":
|
|
17
|
+
case "verification":
|
|
18
|
+
return [name, null];
|
|
19
|
+
case "title":
|
|
20
|
+
case "rich_text":
|
|
21
|
+
case "number":
|
|
22
|
+
case "url":
|
|
23
|
+
case "email":
|
|
24
|
+
case "phone_number":
|
|
25
|
+
case "checkbox":
|
|
26
|
+
case "select":
|
|
27
|
+
case "status":
|
|
28
|
+
case "multi_select":
|
|
29
|
+
case "date":
|
|
30
|
+
case "people":
|
|
31
|
+
case "relation":
|
|
32
|
+
case "files":
|
|
33
|
+
case "place":
|
|
34
|
+
case "created_time":
|
|
35
|
+
case "last_edited_time":
|
|
36
|
+
case "created_by":
|
|
37
|
+
case "last_edited_by":
|
|
38
|
+
case "last_visited_time":
|
|
39
|
+
case undefined:
|
|
40
|
+
return [name, property];
|
|
41
|
+
default:
|
|
42
|
+
return unreachable(property);
|
|
43
|
+
}
|
|
44
|
+
})),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import type { notionContrastModeSchema } from "./protocol/contrast.js";
|
|
2
2
|
import { notionDataSourceIdSchema } from "./protocol/ids.js";
|
|
3
|
-
import type { CustomBlockManifest } from "./protocol/manifest.js";
|
|
4
3
|
import type { customBlockPageSchema } from "./protocol/pages/page.js";
|
|
5
4
|
import type { notionParentSchema } from "./protocol/parent.js";
|
|
6
5
|
import type { notionThemeSchema } from "./protocol/theme.js";
|
|
7
6
|
import type { notionUserSchema } from "./protocol/users/user.js";
|
|
8
7
|
import type { InferInput } from "valibot";
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import type { CustomBlockHostDataSourcesPayload, CustomBlockHostManifestResult, CustomBlockHostPrepareInitialState, CustomBlockHostStatus, CustomBlockManifestSource } from "./lifecycle/types.js";
|
|
9
|
+
import type { CustomBlockHostHandlers, CustomBlockHostLogDirection } from "./messages/types.js";
|
|
10
|
+
export type CustomBlockHostOptions = {
|
|
11
|
+
manifestSource: CustomBlockManifestSource;
|
|
12
|
+
/**
|
|
13
|
+
* Returns success with a persisted manifest or an explicit loading error, never null or
|
|
14
|
+
* undefined. The host validates the result and applies manifest defaults. It calls this
|
|
15
|
+
* when created, regardless of manifestSource. A returned error prevents initialization
|
|
16
|
+
* only when manifestSource is "host".
|
|
17
|
+
*/
|
|
18
|
+
getPersistedManifest: (args: {
|
|
19
|
+
signal: AbortSignal;
|
|
20
|
+
}) => Promise<CustomBlockHostManifestResult>;
|
|
13
21
|
iframe: HTMLIFrameElement;
|
|
14
|
-
|
|
22
|
+
/** Full block URL. Its origin is used to authenticate bridge messages. */
|
|
23
|
+
sandboxUrl: string;
|
|
15
24
|
/**
|
|
16
25
|
* Minimum sandbox protocol version to accept. Defaults to the host runtime
|
|
17
26
|
* minimum. Higher values retire older SDKs; lower values cannot enable
|
|
@@ -21,22 +30,12 @@ export type CustomBlockHostOptions = CustomBlockHostManifestOptions & {
|
|
|
21
30
|
noConnectTimeoutMs?: number;
|
|
22
31
|
noInitResultTimeoutMs?: number;
|
|
23
32
|
handlers: CustomBlockHostHandlers;
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
manifest: CustomBlockManifest;
|
|
27
|
-
initialHeight?: number;
|
|
28
|
-
}) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Reports a handshake failure, timeout, unavailable page context, or iframe reload.
|
|
31
|
-
* Iframe reloads and unavailable page context for older SDKs stop the host
|
|
32
|
-
* before this callback runs.
|
|
33
|
-
* This callback can run after initialization succeeds.
|
|
34
|
-
*/
|
|
35
|
-
onConnectionFailure: ((error: CustomBlockHostFailure) => void) | undefined;
|
|
33
|
+
/** Reports accepted lifecycle transitions, starting synchronously with waitingForConnect. */
|
|
34
|
+
onStatusChange: (state: CustomBlockHostStatus) => void;
|
|
36
35
|
/** Releases adapter resources when a query ends, including replacement and terminal errors. */
|
|
37
36
|
onQueryUnsubscribed: ((subscriptionId: string) => void) | undefined;
|
|
38
37
|
onLog?: (direction: CustomBlockHostLogDirection, payload: unknown) => void;
|
|
39
|
-
/** Runs once,
|
|
38
|
+
/** Runs once, after the selected manifest is validated. */
|
|
40
39
|
prepareInitialState: CustomBlockHostPrepareInitialState;
|
|
41
40
|
initialStateTimeoutMs?: number;
|
|
42
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../src/createCustomBlockHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AAI5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../src/createCustomBlockHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAA;AAI5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAA;AAsBlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAA;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAEpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAczC,OAAO,KAAK,EACX,iCAAiC,EAGjC,6BAA6B,EAG7B,kCAAkC,EAClC,qBAAqB,EACrB,yBAAyB,EACzB,MAAM,sBAAsB,CAAA;AAQ7B,OAAO,KAAK,EAEX,uBAAuB,EACvB,2BAA2B,EAC3B,MAAM,qBAAqB,CAAA;AAe5B,MAAM,MAAM,sBAAsB,GAAG;IACpC,cAAc,EAAE,yBAAyB,CAAA;IACzC;;;;;OAKG;IACH,oBAAoB,EAAE,CAAC,IAAI,EAAE;QAC5B,MAAM,EAAE,WAAW,CAAA;KACnB,KAAK,OAAO,CAAC,6BAA6B,CAAC,CAAA;IAC5C,MAAM,EAAE,iBAAiB,CAAA;IACzB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,EAAE,uBAAuB,CAAA;IACjC,6FAA6F;IAC7F,cAAc,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAA;IACtD,+FAA+F;IAC/F,mBAAmB,EAAE,CAAC,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IACnE,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1E,2DAA2D;IAC3D,mBAAmB,EAAE,kCAAkC,CAAA;IACvD,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAC/D,eAAe,EAAE,CAChB,YAAY,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,KACrD,IAAI,CAAA;IACT,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,KAAK,IAAI,CAAA;IAClE,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,KAAK,IAAI,CAAA;IACjE,cAAc,EAAE,CAAC,WAAW,EAAE,iCAAiC,KAAK,IAAI,CAAA;IACxE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,KAAK,IAAI,CAAA;IAC1E,YAAY,EAAE,CAAC,IAAI,EAAE;QACpB,YAAY,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA;KACzD,KAAK,IAAI,CAAA;CACV,CAAA;AAQD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CAyjBvB"}
|