@notionhq/custom-blocks 0.5.0 → 0.5.2
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/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +2 -3
- package/dist/bridge/parseHostToSandboxMessage.d.ts +3678 -0
- package/dist/bridge/parseHostToSandboxMessage.d.ts.map +1 -0
- package/dist/bridge/parseHostToSandboxMessage.js +47 -0
- package/dist/dataSources/bridge/resolveDataSources.js +2 -2
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -1
- package/dist/dataSources/subscribeToDataSource.js +3 -0
- package/dist/dataSources/types.d.ts +5 -0
- package/dist/dataSources/types.d.ts.map +1 -1
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +10 -10
- package/dist/protocol/dataSources/bridgeDataSourceQueryLimitClamp.d.ts +10 -0
- package/dist/protocol/dataSources/bridgeDataSourceQueryLimitClamp.js +6 -0
- package/dist/protocol/dataSources/messages/queryDataSource.d.ts +14 -0
- package/dist/protocol/dataSources/messages/queryDataSource.js +3 -0
- package/dist/protocol/index.d.ts +2 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/messages/hostToSandbox.d.ts +14 -0
- package/dist/utils/version.js +1 -1
- package/docs/data-sources.md +37 -31
- package/docs/errors.md +5 -7
- package/docs/pages.md +28 -30
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +3 -3
- package/src/bridge/parseHostToSandboxMessage.ts +54 -0
- package/src/dataSources/bridge/resolveDataSources.ts +2 -2
- package/src/dataSources/subscribeToDataSource.ts +3 -0
- package/src/dataSources/types.ts +6 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { bridgeDataSourceBindingSchema } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceBinding.js"
|
|
2
|
+
import { dataSourcePointerValidator } from "@notionhq/custom-blocks-protocol/dataSources/dataSourcePointer.js"
|
|
3
|
+
import { notionDataSourceSchemaValidator } from "@notionhq/custom-blocks-protocol/dataSources/dataSourceSchema.js"
|
|
4
|
+
import { initMessageSchema } from "@notionhq/custom-blocks-protocol/handshake/init.js"
|
|
5
|
+
import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
|
|
6
|
+
import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
|
|
7
|
+
import * as v from "valibot"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Older hosts such as 0.9.0 send `collectionPointer` and `collectionSchema` during
|
|
11
|
+
* initialization and live updates. Normalize these pre-protocol-11 names to
|
|
12
|
+
* `dataSourcePointer` and `dataSourceSchema` before exposing bindings to SDK consumers.
|
|
13
|
+
* Current fields take precedence when both names are present. Malformed fields and
|
|
14
|
+
* invalid property mappings still fail validation; this compatibility does not add
|
|
15
|
+
* host operations or repair bindings the Notion client cannot read from storage.
|
|
16
|
+
*/
|
|
17
|
+
export function parseHostToSandboxMessage(data: unknown) {
|
|
18
|
+
const type = readIncomingType(data)
|
|
19
|
+
if (type === "init" || type === "dataSourcesChanged") {
|
|
20
|
+
return v.safeParse(bindingMessageSchema, data)
|
|
21
|
+
}
|
|
22
|
+
return v.safeParse(hostToSandboxMessageSchema, data)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const bindingSchema = v.pipe(
|
|
26
|
+
v.object({
|
|
27
|
+
...bridgeDataSourceBindingSchema.entries,
|
|
28
|
+
collectionPointer: v.optional(dataSourcePointerValidator),
|
|
29
|
+
collectionSchema: v.optional(notionDataSourceSchemaValidator),
|
|
30
|
+
}),
|
|
31
|
+
v.transform(({ collectionPointer, collectionSchema, ...binding }) => ({
|
|
32
|
+
...binding,
|
|
33
|
+
dataSourcePointer: binding.dataSourcePointer ?? collectionPointer,
|
|
34
|
+
dataSourceSchema: binding.dataSourceSchema ?? collectionSchema,
|
|
35
|
+
})),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const dataSourcesSchema = v.object({
|
|
39
|
+
bindings: v.record(v.string(), bindingSchema),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const bindingMessageSchema = v.variant("type", [
|
|
43
|
+
v.variant("status", [
|
|
44
|
+
v.object({
|
|
45
|
+
...initMessageSchema.options[0].entries,
|
|
46
|
+
dataSources: dataSourcesSchema,
|
|
47
|
+
}),
|
|
48
|
+
initMessageSchema.options[1],
|
|
49
|
+
]),
|
|
50
|
+
v.object({
|
|
51
|
+
type: v.literal("dataSourcesChanged"),
|
|
52
|
+
dataSources: dataSourcesSchema,
|
|
53
|
+
}),
|
|
54
|
+
])
|
|
@@ -17,7 +17,7 @@ export function resolveDataSources(args: {
|
|
|
17
17
|
return Object.entries(args.manifest.dataSources).map(
|
|
18
18
|
([key, manifestDataSource]) => {
|
|
19
19
|
const binding = args.dataSourceBindings[key]
|
|
20
|
-
const
|
|
20
|
+
const dataSourceProperties =
|
|
21
21
|
binding?.dataSourceSchema?.propertiesById ?? {}
|
|
22
22
|
|
|
23
23
|
const resolvedBinding = resolveDataSourceBinding({
|
|
@@ -36,7 +36,7 @@ export function resolveDataSources(args: {
|
|
|
36
36
|
dataSourcePointer: binding?.dataSourcePointer,
|
|
37
37
|
dataSourceSchema: binding?.dataSourceSchema,
|
|
38
38
|
propertyIdsByKey,
|
|
39
|
-
propertySchemasById:
|
|
39
|
+
propertySchemasById: dataSourceProperties,
|
|
40
40
|
...(binding?.inaccessible === true && { inaccessible: true }),
|
|
41
41
|
}
|
|
42
42
|
},
|
|
@@ -35,6 +35,9 @@ export function subscribeToDataSource({
|
|
|
35
35
|
propertyIdsByKey: source?.propertyIdsByKey ?? {},
|
|
36
36
|
isLoading,
|
|
37
37
|
hasMore: result?.status === "success" && result.hasMore,
|
|
38
|
+
...(result?.status === "success" && result.limitClamp !== undefined
|
|
39
|
+
? { limitClamp: result.limitClamp }
|
|
40
|
+
: {}),
|
|
38
41
|
}
|
|
39
42
|
notifyListener(() => onSnapshot(snapshot))
|
|
40
43
|
}
|
package/src/dataSources/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BridgeDataSourceQueryLimitClamp } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceQueryLimitClamp.js"
|
|
1
2
|
import type { CustomBlockQueryDataSourceErrorInfo } from "@notionhq/custom-blocks-protocol/dataSources/messages/queryDataSource.js"
|
|
2
3
|
import type { CustomBlockCreatePageErrorInfo } from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
|
|
3
4
|
import type { CustomBlockGetPageErrorInfo } from "@notionhq/custom-blocks-protocol/pages/messages/getPage.js"
|
|
@@ -22,12 +23,17 @@ export type DataSourcesQueryResult =
|
|
|
22
23
|
| ({ status: "success" } & DataSourceSnapshot)
|
|
23
24
|
| { status: "error"; error: CustomBlockQueryDataSourceErrorInfo }
|
|
24
25
|
|
|
26
|
+
/** A host-reported reduction of the requested row limit. */
|
|
27
|
+
export type DataSourceQueryLimitClamp = BridgeDataSourceQueryLimitClamp
|
|
28
|
+
|
|
25
29
|
/** Latest live snapshot of a data source query. */
|
|
26
30
|
export type DataSourceSnapshot = {
|
|
27
31
|
items: NotionPage[]
|
|
28
32
|
propertyIdsByKey: { [key: string]: string | undefined }
|
|
29
33
|
isLoading: boolean
|
|
30
34
|
hasMore: boolean
|
|
35
|
+
/** A reported host cap. Older hosts may cap queries without reporting it. */
|
|
36
|
+
limitClamp?: DataSourceQueryLimitClamp
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export type NotionArchiveStatus = "active" | "archived" | "all"
|