@notionhq/custom-blocks 0.0.74 → 0.0.76
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/HOST.md +2 -0
- package/dist/bridge/dataSources/resolve.d.ts +3 -8
- package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolve.js +4 -28
- package/dist/bridge/dataSources/resolveProperty.d.ts +2 -1
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolveProperty.js +7 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/bridge/dataSources/resolve.ts +4 -40
- package/src/bridge/dataSources/resolveProperty.ts +7 -1
package/HOST.md
CHANGED
|
@@ -119,6 +119,8 @@ Types:
|
|
|
119
119
|
- `NotionDataSourceBindings` — keyed-by-semantic-key map of bindings, the shape carried in `init.dataSources` and `dataSourcesChanged`.
|
|
120
120
|
- `NotionDataSourcePageBridge` — wire shape for a single page (raw property IDs in `propertiesById`). The SDK derives the consumer-facing `NotionDataSourcePage` from it.
|
|
121
121
|
|
|
122
|
+
The host is authoritative for property bindings. The SDK validates each supplied property ID against the manifest and collection schema, but leaves omitted mappings unbound rather than inferring them from property IDs or names.
|
|
123
|
+
|
|
122
124
|
Schemas:
|
|
123
125
|
|
|
124
126
|
- `notionBlockIdSchema`
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CustomBlockManifest } from "../manifest.js";
|
|
2
2
|
import type { NotionDataSource, NotionDataSourceBindings } from "./dataSource.js";
|
|
3
|
-
import type { NotionPropertySchema } from "./propertySchema.js";
|
|
4
3
|
type ResolveDataSourcesArgs = {
|
|
5
4
|
manifest: CustomBlockManifest | null;
|
|
6
5
|
dataSourceBindings: NotionDataSourceBindings;
|
|
@@ -9,14 +8,10 @@ type ResolveDataSourcesArgs = {
|
|
|
9
8
|
* Builds the public {@link NotionDataSource} list the SDK exposes to consumers.
|
|
10
9
|
*
|
|
11
10
|
* Combines the host-supplied bindings (collection pointers + schemas) with the
|
|
12
|
-
* manifest's declared data-source keys.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* manifest's declared data-source keys. Property mappings are host-owned: the
|
|
12
|
+
* SDK validates the supplied property id against the manifest and live schema,
|
|
13
|
+
* but does not infer a missing mapping.
|
|
15
14
|
*/
|
|
16
15
|
export declare function resolveDataSources(args: ResolveDataSourcesArgs): NotionDataSource[];
|
|
17
|
-
export declare function findPropertyIdByManifestProperty(propertySchemasById: Record<string, NotionPropertySchema>, manifestProperty: {
|
|
18
|
-
key: string;
|
|
19
|
-
type: NotionPropertySchema["type"];
|
|
20
|
-
}): string | undefined;
|
|
21
16
|
export {};
|
|
22
17
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/dataSources/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EACX,gBAAgB,EAChB,wBAAwB,EACxB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/dataSources/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EACX,gBAAgB,EAChB,wBAAwB,EACxB,MAAM,iBAAiB,CAAA;AAExB,KAAK,sBAAsB,GAAG;IAC7B,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAA;IACpC,kBAAkB,EAAE,wBAAwB,CAAA;CAC5C,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,sBAAsB,GAC1B,gBAAgB,EAAE,CAyCpB"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Builds the public {@link NotionDataSource} list the SDK exposes to consumers.
|
|
3
3
|
*
|
|
4
4
|
* Combines the host-supplied bindings (collection pointers + schemas) with the
|
|
5
|
-
* manifest's declared data-source keys.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* manifest's declared data-source keys. Property mappings are host-owned: the
|
|
6
|
+
* SDK validates the supplied property id against the manifest and live schema,
|
|
7
|
+
* but does not infer a missing mapping.
|
|
8
8
|
*/
|
|
9
9
|
export function resolveDataSources(args) {
|
|
10
10
|
if (args.manifest === null) {
|
|
@@ -23,12 +23,7 @@ export function resolveDataSources(args) {
|
|
|
23
23
|
const propertyIdsByKey = {};
|
|
24
24
|
const manifestProperties = Object.entries(manifestDataSource.properties ?? {});
|
|
25
25
|
for (const [propertyKey, manifestProperty] of manifestProperties) {
|
|
26
|
-
const propertyId = propertyKey
|
|
27
|
-
? bindingPropertyIdsByKey[propertyKey]
|
|
28
|
-
: findPropertyIdByManifestProperty(propertySchemasById, {
|
|
29
|
-
key: propertyKey,
|
|
30
|
-
type: manifestProperty.type,
|
|
31
|
-
});
|
|
26
|
+
const propertyId = bindingPropertyIdsByKey[propertyKey];
|
|
32
27
|
const propertySchema = propertyId === undefined ? undefined : propertySchemasById[propertyId];
|
|
33
28
|
propertyIdsByKey[propertyKey] =
|
|
34
29
|
propertySchema?.type === manifestProperty.type
|
|
@@ -44,22 +39,3 @@ export function resolveDataSources(args) {
|
|
|
44
39
|
};
|
|
45
40
|
});
|
|
46
41
|
}
|
|
47
|
-
export function findPropertyIdByManifestProperty(propertySchemasById, manifestProperty) {
|
|
48
|
-
// `ManifestProperty.name` is display copy for setup UI. Binding fallback is based
|
|
49
|
-
// on the stable semantic key so copy changes don't affect property resolution.
|
|
50
|
-
const propertySchemaForKey = propertySchemasById[manifestProperty.key];
|
|
51
|
-
if (propertySchemaForKey?.type === manifestProperty.type) {
|
|
52
|
-
return manifestProperty.key;
|
|
53
|
-
}
|
|
54
|
-
const normalizedKey = normalizePropertyName(manifestProperty.key);
|
|
55
|
-
for (const [propertyId, propertySchema] of Object.entries(propertySchemasById)) {
|
|
56
|
-
if (propertySchema.type === manifestProperty.type &&
|
|
57
|
-
normalizePropertyName(propertySchema.name) === normalizedKey) {
|
|
58
|
-
return propertyId;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
function normalizePropertyName(value) {
|
|
64
|
-
return value.trim().toLowerCase();
|
|
65
|
-
}
|
|
@@ -25,7 +25,8 @@ export declare function resolvePropertyWriteMapForDataSource(args: {
|
|
|
25
25
|
operationName: string;
|
|
26
26
|
}): PropertyWriteMapResolutionResult;
|
|
27
27
|
/**
|
|
28
|
-
* Treats
|
|
28
|
+
* Treats bound data-source keys as aliases for property IDs. An unbound key may still be used as
|
|
29
|
+
* a raw ID when it exactly matches a property in the data source schema.
|
|
29
30
|
*/
|
|
30
31
|
export declare function resolvePropertyIdentifierForDataSource(args: {
|
|
31
32
|
dataSource: NotionDataSource | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProperty.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/dataSources/resolveProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EACX,0BAA0B,EAC1B,0BAA0B,EAC1B,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,eAAO,MAAM,kCAAkC,2BAAa,CAAA;AAE5D,MAAM,MAAM,4BAA4B,GACrC,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,GACxB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,4BAA4B,GACvC,oBAAoB,CAAC,4BAA4B,CAAC,CAAA;AAEnD,MAAM,MAAM,gCAAgC,GACzC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,0BAA0B,CAAA;CAAE,GAC7D;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,4BAA4B,CAAA;CAAE,CAAA;AAS3D;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAAC,IAAI,EAAE;IAC1D,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,UAAU,EAAE,0BAA0B,CAAA;IACtC,aAAa,EAAE,MAAM,CAAA;CACrB,GAAG,gCAAgC,CAwDnC;AAED
|
|
1
|
+
{"version":3,"file":"resolveProperty.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/dataSources/resolveProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EACX,0BAA0B,EAC1B,0BAA0B,EAC1B,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,eAAO,MAAM,kCAAkC,2BAAa,CAAA;AAE5D,MAAM,MAAM,4BAA4B,GACrC,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,GACxB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,4BAA4B,GACvC,oBAAoB,CAAC,4BAA4B,CAAC,CAAA;AAEnD,MAAM,MAAM,gCAAgC,GACzC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,0BAA0B,CAAA;CAAE,GAC7D;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,4BAA4B,CAAA;CAAE,CAAA;AAS3D;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAAC,IAAI,EAAE;IAC1D,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,UAAU,EAAE,0BAA0B,CAAA;IACtC,aAAa,EAAE,MAAM,CAAA;CACrB,GAAG,gCAAgC,CAwDnC;AAED;;;GAGG;AACH,wBAAgB,sCAAsC,CAAC,IAAI,EAAE;IAC5D,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACrB,GACE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,4BAA4B,CAAA;CAAE,CAsB1D"}
|
|
@@ -55,13 +55,19 @@ export function resolvePropertyWriteMapForDataSource(args) {
|
|
|
55
55
|
return { status: "success", properties: resolvedProperties };
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* Treats
|
|
58
|
+
* Treats bound data-source keys as aliases for property IDs. An unbound key may still be used as
|
|
59
|
+
* a raw ID when it exactly matches a property in the data source schema.
|
|
59
60
|
*/
|
|
60
61
|
export function resolvePropertyIdentifierForDataSource(args) {
|
|
61
62
|
const { dataSource, identifier, operationName } = args;
|
|
62
63
|
if (dataSource !== undefined && identifier in dataSource.propertyIdsByKey) {
|
|
63
64
|
const propertyId = dataSource.propertyIdsByKey[identifier];
|
|
64
65
|
if (propertyId === undefined) {
|
|
66
|
+
// If the property is not bound to a key, check if it is a valid property ID. If so, we
|
|
67
|
+
// can use it directly.
|
|
68
|
+
if (identifier in dataSource.propertySchemasById) {
|
|
69
|
+
return { status: "success", propertyId: identifier };
|
|
70
|
+
}
|
|
65
71
|
return {
|
|
66
72
|
status: "error",
|
|
67
73
|
error: makePropertyError("unmapped_property", `${operationName} cannot resolve property key "${identifier}" because it is not bound to a Notion property.`),
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,6 @@ import type {
|
|
|
3
3
|
NotionDataSource,
|
|
4
4
|
NotionDataSourceBindings,
|
|
5
5
|
} from "./dataSource.js"
|
|
6
|
-
import type { NotionPropertySchema } from "./propertySchema.js"
|
|
7
6
|
|
|
8
7
|
type ResolveDataSourcesArgs = {
|
|
9
8
|
manifest: CustomBlockManifest | null
|
|
@@ -14,9 +13,9 @@ type ResolveDataSourcesArgs = {
|
|
|
14
13
|
* Builds the public {@link NotionDataSource} list the SDK exposes to consumers.
|
|
15
14
|
*
|
|
16
15
|
* Combines the host-supplied bindings (collection pointers + schemas) with the
|
|
17
|
-
* manifest's declared data-source keys.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* manifest's declared data-source keys. Property mappings are host-owned: the
|
|
17
|
+
* SDK validates the supplied property id against the manifest and live schema,
|
|
18
|
+
* but does not infer a missing mapping.
|
|
20
19
|
*/
|
|
21
20
|
export function resolveDataSources(
|
|
22
21
|
args: ResolveDataSourcesArgs,
|
|
@@ -43,13 +42,7 @@ export function resolveDataSources(
|
|
|
43
42
|
manifestDataSource.properties ?? {},
|
|
44
43
|
)
|
|
45
44
|
for (const [propertyKey, manifestProperty] of manifestProperties) {
|
|
46
|
-
const propertyId =
|
|
47
|
-
propertyKey in bindingPropertyIdsByKey
|
|
48
|
-
? bindingPropertyIdsByKey[propertyKey]
|
|
49
|
-
: findPropertyIdByManifestProperty(propertySchemasById, {
|
|
50
|
-
key: propertyKey,
|
|
51
|
-
type: manifestProperty.type,
|
|
52
|
-
})
|
|
45
|
+
const propertyId = bindingPropertyIdsByKey[propertyKey]
|
|
53
46
|
const propertySchema =
|
|
54
47
|
propertyId === undefined ? undefined : propertySchemasById[propertyId]
|
|
55
48
|
propertyIdsByKey[propertyKey] =
|
|
@@ -68,32 +61,3 @@ export function resolveDataSources(
|
|
|
68
61
|
},
|
|
69
62
|
)
|
|
70
63
|
}
|
|
71
|
-
|
|
72
|
-
export function findPropertyIdByManifestProperty(
|
|
73
|
-
propertySchemasById: Record<string, NotionPropertySchema>,
|
|
74
|
-
manifestProperty: { key: string; type: NotionPropertySchema["type"] },
|
|
75
|
-
): string | undefined {
|
|
76
|
-
// `ManifestProperty.name` is display copy for setup UI. Binding fallback is based
|
|
77
|
-
// on the stable semantic key so copy changes don't affect property resolution.
|
|
78
|
-
const propertySchemaForKey = propertySchemasById[manifestProperty.key]
|
|
79
|
-
if (propertySchemaForKey?.type === manifestProperty.type) {
|
|
80
|
-
return manifestProperty.key
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const normalizedKey = normalizePropertyName(manifestProperty.key)
|
|
84
|
-
for (const [propertyId, propertySchema] of Object.entries(
|
|
85
|
-
propertySchemasById,
|
|
86
|
-
)) {
|
|
87
|
-
if (
|
|
88
|
-
propertySchema.type === manifestProperty.type &&
|
|
89
|
-
normalizePropertyName(propertySchema.name) === normalizedKey
|
|
90
|
-
) {
|
|
91
|
-
return propertyId
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return undefined
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function normalizePropertyName(value: string): string {
|
|
98
|
-
return value.trim().toLowerCase()
|
|
99
|
-
}
|
|
@@ -102,7 +102,8 @@ export function resolvePropertyWriteMapForDataSource(args: {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
* Treats
|
|
105
|
+
* Treats bound data-source keys as aliases for property IDs. An unbound key may still be used as
|
|
106
|
+
* a raw ID when it exactly matches a property in the data source schema.
|
|
106
107
|
*/
|
|
107
108
|
export function resolvePropertyIdentifierForDataSource(args: {
|
|
108
109
|
dataSource: NotionDataSource | undefined
|
|
@@ -115,6 +116,11 @@ export function resolvePropertyIdentifierForDataSource(args: {
|
|
|
115
116
|
if (dataSource !== undefined && identifier in dataSource.propertyIdsByKey) {
|
|
116
117
|
const propertyId = dataSource.propertyIdsByKey[identifier]
|
|
117
118
|
if (propertyId === undefined) {
|
|
119
|
+
// If the property is not bound to a key, check if it is a valid property ID. If so, we
|
|
120
|
+
// can use it directly.
|
|
121
|
+
if (identifier in dataSource.propertySchemasById) {
|
|
122
|
+
return { status: "success", propertyId: identifier }
|
|
123
|
+
}
|
|
118
124
|
return {
|
|
119
125
|
status: "error",
|
|
120
126
|
error: makePropertyError(
|