@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,101 @@
|
|
|
1
|
+
import type { NotionCollectionSchema } from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
|
|
2
|
+
import type {
|
|
3
|
+
CustomBlockContainsFilterOperator,
|
|
4
|
+
CustomBlockOptionFilterOperator,
|
|
5
|
+
ResolvedCustomBlockDataSourceFilter,
|
|
6
|
+
ResolvedCustomBlockDataSourcePropertyFilter,
|
|
7
|
+
} from "@notionhq/custom-blocks-protocol/messages/queryDataSource.js"
|
|
8
|
+
import type { CustomBlockQueryDataSourceErrorInfo } from "@notionhq/custom-blocks-protocol/messages/queryDataSourceResult.js"
|
|
9
|
+
import { unreachable } from "../utils.js"
|
|
10
|
+
|
|
11
|
+
type OptionFilterOperator =
|
|
12
|
+
| CustomBlockOptionFilterOperator
|
|
13
|
+
| CustomBlockContainsFilterOperator
|
|
14
|
+
|
|
15
|
+
export function validateQueryDataSourceFilter(
|
|
16
|
+
filter: ResolvedCustomBlockDataSourceFilter | undefined,
|
|
17
|
+
collectionSchema: NotionCollectionSchema | undefined,
|
|
18
|
+
): CustomBlockQueryDataSourceErrorInfo | undefined {
|
|
19
|
+
if (filter === undefined || collectionSchema === undefined) {
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const propertyFilters = "and" in filter ? filter.and : [filter]
|
|
24
|
+
for (const propertyFilter of propertyFilters) {
|
|
25
|
+
const error = validatePropertyFilter(propertyFilter, collectionSchema)
|
|
26
|
+
if (error !== undefined) {
|
|
27
|
+
return error
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function validatePropertyFilter(
|
|
34
|
+
filter: ResolvedCustomBlockDataSourcePropertyFilter,
|
|
35
|
+
collectionSchema: NotionCollectionSchema,
|
|
36
|
+
): CustomBlockQueryDataSourceErrorInfo | undefined {
|
|
37
|
+
const propertySchema = collectionSchema.propertiesById[filter.propertyId]
|
|
38
|
+
if (propertySchema === undefined) {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const optionFilter = getOptionFilter(filter)
|
|
43
|
+
if (
|
|
44
|
+
optionFilter === undefined ||
|
|
45
|
+
propertySchema.type !== optionFilter.propertyType
|
|
46
|
+
) {
|
|
47
|
+
return undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const optionNames = new Set(propertySchema.options.map(option => option.name))
|
|
51
|
+
const invalidOptionName = getOptionFilterValues(optionFilter.operator).find(
|
|
52
|
+
optionName => !optionNames.has(optionName),
|
|
53
|
+
)
|
|
54
|
+
if (invalidOptionName === undefined) {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
code: "invalid_data_source_query_filter",
|
|
60
|
+
message: `Data source query filter option "${invalidOptionName}" is not defined for property "${filter.propertyId}".`,
|
|
61
|
+
isRetryable: false,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getOptionFilter(filter: ResolvedCustomBlockDataSourcePropertyFilter):
|
|
66
|
+
| {
|
|
67
|
+
propertyType: "select" | "multi_select" | "status"
|
|
68
|
+
operator: OptionFilterOperator
|
|
69
|
+
}
|
|
70
|
+
| undefined {
|
|
71
|
+
if ("select" in filter) {
|
|
72
|
+
return { propertyType: "select", operator: filter.select }
|
|
73
|
+
}
|
|
74
|
+
if ("multi_select" in filter) {
|
|
75
|
+
return { propertyType: "multi_select", operator: filter.multi_select }
|
|
76
|
+
}
|
|
77
|
+
if ("status" in filter) {
|
|
78
|
+
return { propertyType: "status", operator: filter.status }
|
|
79
|
+
}
|
|
80
|
+
return undefined
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getOptionFilterValues(operator: OptionFilterOperator): string[] {
|
|
84
|
+
let value: string | string[]
|
|
85
|
+
if ("equals" in operator) {
|
|
86
|
+
value = operator.equals
|
|
87
|
+
} else if ("does_not_equal" in operator) {
|
|
88
|
+
value = operator.does_not_equal
|
|
89
|
+
} else if ("contains" in operator) {
|
|
90
|
+
value = operator.contains
|
|
91
|
+
} else if ("contains_all" in operator) {
|
|
92
|
+
value = operator.contains_all
|
|
93
|
+
} else if ("does_not_contain" in operator) {
|
|
94
|
+
value = operator.does_not_contain
|
|
95
|
+
} else if ("is_empty" in operator || "is_not_empty" in operator) {
|
|
96
|
+
return []
|
|
97
|
+
} else {
|
|
98
|
+
return unreachable(operator)
|
|
99
|
+
}
|
|
100
|
+
return Array.isArray(value) ? value : [value]
|
|
101
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { NotionCollectionSchema } from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
|
|
2
|
+
import { CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES } from "@notionhq/custom-blocks-protocol/dataSources/propertySchema.js"
|
|
3
|
+
import {
|
|
4
|
+
CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS,
|
|
5
|
+
type ResolvedCustomBlockDataSourceSort,
|
|
6
|
+
} from "@notionhq/custom-blocks-protocol/messages/queryDataSource.js"
|
|
7
|
+
import type { CustomBlockQueryDataSourceErrorInfo } from "@notionhq/custom-blocks-protocol/messages/queryDataSourceResult.js"
|
|
8
|
+
|
|
9
|
+
const supportedDataSourceSortPropertyTypes = new Set<string>(
|
|
10
|
+
CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Ensures the sorts of a data source query are valid.
|
|
15
|
+
*/
|
|
16
|
+
export function validateQueryDataSourceSorts(
|
|
17
|
+
sorts: ResolvedCustomBlockDataSourceSort[] | undefined,
|
|
18
|
+
collectionSchema: NotionCollectionSchema | undefined,
|
|
19
|
+
): CustomBlockQueryDataSourceErrorInfo | undefined {
|
|
20
|
+
if (sorts === undefined) {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
if (sorts.length > CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS) {
|
|
24
|
+
return {
|
|
25
|
+
code: "invalid_data_source_query_sort",
|
|
26
|
+
message: `Data source query sorts may contain at most ${CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS} entries.`,
|
|
27
|
+
isRetryable: false,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const seenPropertyIds = new Set<string>()
|
|
32
|
+
for (const sort of sorts) {
|
|
33
|
+
if (seenPropertyIds.has(sort.propertyId)) {
|
|
34
|
+
return {
|
|
35
|
+
code: "invalid_data_source_query_sort",
|
|
36
|
+
message: `Data source query sorts cannot contain duplicate property ID "${sort.propertyId}".`,
|
|
37
|
+
isRetryable: false,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
seenPropertyIds.add(sort.propertyId)
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
collectionSchema !== undefined &&
|
|
44
|
+
!Object.prototype.hasOwnProperty.call(
|
|
45
|
+
collectionSchema.propertiesById,
|
|
46
|
+
sort.propertyId,
|
|
47
|
+
)
|
|
48
|
+
) {
|
|
49
|
+
return {
|
|
50
|
+
code: "invalid_data_source_query_sort",
|
|
51
|
+
message: `Data source query sort property ID "${sort.propertyId}" is not defined in the bound data source schema.`,
|
|
52
|
+
isRetryable: false,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const propertySchema = collectionSchema?.propertiesById[sort.propertyId]
|
|
57
|
+
if (
|
|
58
|
+
propertySchema !== undefined &&
|
|
59
|
+
!supportedDataSourceSortPropertyTypes.has(propertySchema.type)
|
|
60
|
+
) {
|
|
61
|
+
return {
|
|
62
|
+
code: "invalid_data_source_query_sort",
|
|
63
|
+
message: `Data source query sorts do not yet support property type "${propertySchema.type}".`,
|
|
64
|
+
isRetryable: false,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return undefined
|
|
69
|
+
}
|