@notionhq/custom-blocks 0.3.1 → 0.3.3
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 -8
- package/dist/bridge/SandboxBridge.d.ts +469 -15
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +119 -88
- package/dist/bridge/dataSources/resolveProperty.d.ts +1 -20
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolveProperty.js +37 -32
- package/dist/bridge/page.d.ts +11 -7
- package/dist/bridge/page.d.ts.map +1 -1
- package/dist/bridge/page.js +20 -50
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +32 -6
- package/dist/dataSources.d.ts.map +1 -1
- package/dist/dataSources.js +4 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/protocol/dataSources/dateValue.d.ts +2 -2
- package/dist/protocol/dataSources/dateValue.js +9 -7
- package/dist/protocol/messages/createPage.d.ts +64 -2
- package/dist/protocol/messages/createPageResult.d.ts +192 -6
- package/dist/protocol/messages/getPage.d.ts +192 -6
- package/dist/protocol/messages/hostToSandbox.d.ts +704 -22
- package/dist/protocol/messages/queryDataSourceResult.d.ts +128 -4
- package/dist/protocol/messages/sandboxToHost.d.ts +128 -4
- package/dist/protocol/messages/updatePage.d.ts +64 -2
- package/dist/protocol/messages/updatePageResult.d.ts +192 -6
- package/dist/protocol/pages/page.d.ts +360 -12
- package/dist/protocol/pages/page.js +48 -2
- package/dist/protocol/protocolVersion.d.ts +2 -1
- package/dist/protocol/protocolVersion.js +3 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/build-tools.md +55 -0
- package/docs/data-sources.md +12 -9
- package/docs/deployment.md +16 -34
- package/docs/errors.md +65 -52
- package/docs/pages.md +85 -78
- package/package.json +2 -18
- package/src/bridge/SandboxBridge.ts +168 -129
- package/src/bridge/dataSources/resolveProperty.ts +48 -39
- package/src/bridge/page.ts +32 -75
- package/src/bridge/sandboxClient.ts +40 -7
- package/src/dataSources.ts +7 -9
- package/src/index.ts +6 -0
- package/src/types.ts +6 -0
|
@@ -7,10 +7,12 @@ import type {
|
|
|
7
7
|
GetUserResult,
|
|
8
8
|
ListUsersArgs,
|
|
9
9
|
ListUsersResult,
|
|
10
|
+
NotionPage,
|
|
10
11
|
NotionUserId,
|
|
11
12
|
OpenExternalUrlResult,
|
|
12
13
|
OpenPageOptions,
|
|
13
14
|
OpenPageResult,
|
|
15
|
+
UpdatePageResult,
|
|
14
16
|
} from "../types.js"
|
|
15
17
|
import {
|
|
16
18
|
type CustomBlockHostState,
|
|
@@ -19,6 +21,7 @@ import {
|
|
|
19
21
|
} from "./hostState.js"
|
|
20
22
|
import type { ManifestLoadResult } from "./loadManifest.js"
|
|
21
23
|
import type { MessageInterceptor } from "./messageInterceptor.js"
|
|
24
|
+
import { makeUpdatePageByKey, toNotionPageFromNotionPageData } from "./page.js"
|
|
22
25
|
import {
|
|
23
26
|
type MessageLogEntry,
|
|
24
27
|
type QueryDataSourceArgs,
|
|
@@ -94,11 +97,35 @@ export const customBlockDataSources = {
|
|
|
94
97
|
hostState,
|
|
95
98
|
key,
|
|
96
99
|
subscriptionId,
|
|
97
|
-
({ page, dataSource }) =>
|
|
98
|
-
getBridge()
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
({ page: pageData, dataSource }) => {
|
|
101
|
+
const bridge = getBridge()
|
|
102
|
+
const update = async (
|
|
103
|
+
args: Parameters<SandboxBridge["updatePage"]>[0],
|
|
104
|
+
): Promise<UpdatePageResult> => {
|
|
105
|
+
const result = await bridge.updatePage(args)
|
|
106
|
+
if (result.status === "error") {
|
|
107
|
+
return result
|
|
108
|
+
}
|
|
109
|
+
Object.assign(page, result.page)
|
|
110
|
+
return { status: "success", page }
|
|
111
|
+
}
|
|
112
|
+
const page: NotionPage = toNotionPageFromNotionPageData({
|
|
113
|
+
page: pageData,
|
|
114
|
+
dataSourceKey: key,
|
|
115
|
+
getPropertyById: propertyId =>
|
|
116
|
+
bridge.getPropertyById({ page, propertyId }),
|
|
117
|
+
getPropertyByKey: propertyKey =>
|
|
118
|
+
bridge.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
119
|
+
updateById: payload =>
|
|
120
|
+
update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
121
|
+
updateByKey: makeUpdatePageByKey({
|
|
122
|
+
dataSource,
|
|
123
|
+
update: payload =>
|
|
124
|
+
update({ ...payload, pageId: page.id, dataSource }),
|
|
125
|
+
}),
|
|
126
|
+
})
|
|
127
|
+
return page
|
|
128
|
+
},
|
|
102
129
|
)
|
|
103
130
|
},
|
|
104
131
|
}
|
|
@@ -121,14 +148,20 @@ export const pages = {
|
|
|
121
148
|
* Creates a new Notion page.
|
|
122
149
|
*/
|
|
123
150
|
create: (input: CreatePageArgs): Promise<CreatePageResult> => {
|
|
124
|
-
return getBridge().createPage(
|
|
151
|
+
return getBridge().createPage({
|
|
152
|
+
...input,
|
|
153
|
+
dataSource: undefined,
|
|
154
|
+
})
|
|
125
155
|
},
|
|
126
156
|
|
|
127
157
|
/**
|
|
128
158
|
* Fetches a page by id.
|
|
129
159
|
*/
|
|
130
160
|
get: (pageId: NotionPageId): Promise<GetPageResult> => {
|
|
131
|
-
return getBridge().getPage(
|
|
161
|
+
return getBridge().getPage({
|
|
162
|
+
pageId,
|
|
163
|
+
dataSource: undefined,
|
|
164
|
+
})
|
|
132
165
|
},
|
|
133
166
|
|
|
134
167
|
/**
|
package/src/dataSources.ts
CHANGED
|
@@ -23,8 +23,8 @@ export const dataSources = {
|
|
|
23
23
|
if (resolved.status === "error") {
|
|
24
24
|
return resolved
|
|
25
25
|
}
|
|
26
|
-
const { dataSource
|
|
27
|
-
const result = await getBridge().getPage(pageId,
|
|
26
|
+
const { dataSource } = resolved
|
|
27
|
+
const result = await getBridge().getPage({ pageId, dataSource })
|
|
28
28
|
return result.status === "error"
|
|
29
29
|
? result
|
|
30
30
|
: { ...result, propertyIdsByKey: dataSource.propertyIdsByKey }
|
|
@@ -38,13 +38,11 @@ export const dataSources = {
|
|
|
38
38
|
return resolved
|
|
39
39
|
}
|
|
40
40
|
const { dataSource, dataSourceId } = resolved
|
|
41
|
-
const result = await getBridge().createPage(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
dataSourceId,
|
|
47
|
-
)
|
|
41
|
+
const result = await getBridge().createPage({
|
|
42
|
+
...payload,
|
|
43
|
+
parent: { type: "data_source_id", data_source_id: dataSourceId },
|
|
44
|
+
dataSource,
|
|
45
|
+
})
|
|
48
46
|
return result.status === "error"
|
|
49
47
|
? result
|
|
50
48
|
: { ...result, propertyIdsByKey: dataSource.propertyIdsByKey }
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,12 @@ export type {
|
|
|
12
12
|
NotionCollectionSchema,
|
|
13
13
|
NotionDataSource,
|
|
14
14
|
} from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
|
|
15
|
+
export type {
|
|
16
|
+
NotionDateReminder,
|
|
17
|
+
NotionDateTimeReminder,
|
|
18
|
+
NotionDisabledReminder,
|
|
19
|
+
NotionTimeReminder,
|
|
20
|
+
} from "@notionhq/custom-blocks-protocol/dataSources/dateValue.js"
|
|
15
21
|
export type {
|
|
16
22
|
CustomBlockDataSourceResolutionErrorCode,
|
|
17
23
|
CustomBlockDataSourceResolutionErrorInfo,
|
package/src/types.ts
CHANGED
|
@@ -87,6 +87,12 @@ export type NotionPagePropertyInputValue =
|
|
|
87
87
|
| "created_by"
|
|
88
88
|
| "last_edited_by"
|
|
89
89
|
| "last_visited_time"
|
|
90
|
+
| "unique_id"
|
|
91
|
+
| "button"
|
|
92
|
+
| "formula"
|
|
93
|
+
| "location"
|
|
94
|
+
| "rollup"
|
|
95
|
+
| "verification"
|
|
90
96
|
}
|
|
91
97
|
> extends infer PropertyValue
|
|
92
98
|
? PropertyValue extends { id: string }
|