@notionhq/custom-blocks-host 0.1.23 → 0.1.25

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.
Files changed (37) hide show
  1. package/README.md +13 -8
  2. package/dist/createCustomBlockHost.d.ts +8 -6
  3. package/dist/createCustomBlockHost.d.ts.map +1 -1
  4. package/dist/createCustomBlockHost.js +31 -18
  5. package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts +6 -0
  6. package/dist/lifecycle/normalizeHostToSandboxMessage.d.ts.map +1 -0
  7. package/dist/lifecycle/normalizeHostToSandboxMessage.js +38 -0
  8. package/dist/protocol/dataSources/dataSource.d.ts +61 -6
  9. package/dist/protocol/dataSources/dataSource.js +35 -6
  10. package/dist/protocol/dataSources/propertySchema.d.ts +2 -0
  11. package/dist/protocol/dataSources/propertySchema.js +7 -0
  12. package/dist/protocol/messages/createPageResult.d.ts +1 -1
  13. package/dist/protocol/messages/getPage.d.ts +1 -1
  14. package/dist/protocol/messages/hostToSandbox.d.ts +10 -4
  15. package/dist/protocol/messages/init.d.ts +5 -2
  16. package/dist/protocol/messages/openPage.d.ts +1 -1
  17. package/dist/protocol/messages/pageChanged.d.ts +5 -2
  18. package/dist/protocol/messages/queryDataSource.d.ts +485 -485
  19. package/dist/protocol/messages/queryDataSource.js +43 -43
  20. package/dist/protocol/messages/queryDataSourceResult.d.ts +1 -1
  21. package/dist/protocol/messages/sandboxToHost.d.ts +178 -178
  22. package/dist/protocol/messages/updatePageResult.d.ts +1 -1
  23. package/dist/protocol/pages/page.d.ts +5 -2
  24. package/dist/protocol/pages/page.js +15 -9
  25. package/dist/protocol/protocolVersion.d.ts +1 -1
  26. package/dist/protocol/protocolVersion.js +1 -1
  27. package/dist/queries/validateQueryDataSourceFilter.d.ts +1 -1
  28. package/dist/queries/validateQueryDataSourceFilter.d.ts.map +1 -1
  29. package/dist/queries/validateQueryDataSourceFilter.js +8 -4
  30. package/dist/queries/validateQueryDataSourceSorts.d.ts +1 -1
  31. package/dist/queries/validateQueryDataSourceSorts.d.ts.map +1 -1
  32. package/dist/queries/validateQueryDataSourceSorts.js +3 -5
  33. package/package.json +1 -1
  34. package/src/createCustomBlockHost.ts +54 -31
  35. package/src/lifecycle/normalizeHostToSandboxMessage.ts +46 -0
  36. package/src/queries/validateQueryDataSourceFilter.ts +9 -5
  37. package/src/queries/validateQueryDataSourceSorts.ts +4 -10
package/README.md CHANGED
@@ -127,14 +127,19 @@ and record access.
127
127
 
128
128
  ### Query requests
129
129
 
130
- The `queryDataSource` handler receives raw data source and property IDs. Its optional `filter` and
131
- `sorts` fields have already been resolved by the SDK. The host validates that sorts contain at most
132
- 10 unique property IDs, checks property IDs and currently supported property types against the bound
133
- collection schema when available, and applies valid sorts in the order provided by the array.
134
-
135
- When a data source binding includes `collectionSchema`, the runtime validates select, multi-select,
136
- and status option names before invoking `queryDataSource`. Bindings without a collection schema
137
- cannot perform this check, so their query handlers remain responsible for validating option names.
130
+ The `queryDataSource` handler receives raw data source and property IDs. The SDK resolves semantic
131
+ keys before it sends a request. The runtime requires every filter and sort property ID to exist in
132
+ `collectionSchema.propertiesById`. This map must contain only actual database properties. The SDK
133
+ adds synthetic metadata to its separate read map, `propertySchemasById`.
134
+
135
+ For SDKs using protocol 3 or 4, the runtime adds synthetic metadata schemas to outgoing
136
+ `collectionSchema` payloads during initialization and binding updates. Query validation still uses
137
+ the actual database schema supplied by the host. Protocol 5 SDKs receive that schema directly and
138
+ add the metadata read schemas themselves.
139
+
140
+ The runtime validates option names, supported sort types, and the limit of ten unique sort
141
+ properties before it invokes the handler. Sorts retain their array order. Extra fields and mixed
142
+ filter types fail protocol validation.
138
143
 
139
144
  `initialState.dataSources` may also be a function of the successful `connect` message. This lets a
140
145
  host derive bindings from the sandbox-provided manifest.
@@ -12,16 +12,19 @@ export type CustomBlockHostOptions = {
12
12
  iframe: HTMLIFrameElement;
13
13
  sandboxOrigin: string;
14
14
  /**
15
- * Minimum sandbox protocol version to accept. Defaults to the host runtime
16
- * minimum. Higher values retire older SDKs; lower values cannot enable
17
- * protocol versions the runtime no longer supports.
15
+ * Minimum sandbox protocol version to accept. Defaults to the host runtime minimum. Higher
16
+ * values retire older SDKs; lower values cannot enable protocol versions the runtime no longer
17
+ * supports.
18
18
  */
19
19
  minBridgeProtocolVersion?: number;
20
20
  noConnectTimeoutMs?: number;
21
21
  noInitResultTimeoutMs?: number;
22
22
  initialState: CustomBlockHostInitialState;
23
23
  handlers: CustomBlockHostHandlers;
24
- /** Called as soon as the `manifest` is available after `connect`, before `onInitialized` and binding validation. */
24
+ /**
25
+ * Called as soon as the `manifest` is available after `connect`, before `onInitialized` and
26
+ * binding validation.
27
+ */
25
28
  onManifest?: (manifest: CustomBlockManifest) => void;
26
29
  /** Callback fired when the initialization handshake with the sandbox completed successfully. */
27
30
  onInitialized?: (state: {
@@ -31,8 +34,7 @@ export type CustomBlockHostOptions = {
31
34
  /** Callback fired when the initialization handshake with the sandbox failed or timed out. */
32
35
  onInitializationFailure?: (error: CustomBlockHostInitializationFailure) => void;
33
36
  /**
34
- * Callback fired when the current host and iframe must restart.
35
- * Recreate both to continue.
37
+ * Callback fired when the current host and iframe must restart. Recreate both to continue.
36
38
  */
37
39
  onRestartRequired?: () => void;
38
40
  onLog?: (direction: CustomBlockHostLogDirection, payload: unknown) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../src/createCustomBlockHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,kBAAkB,EACvB,MAAM,8CAA8C,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AAavF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AAiBtG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AACrF,OAAO,KA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K,IAAI,CAAA;IACxE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,KAAK,IAAI,CAAA;IACjD,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,kBAAkB,CAAA;KAAE,KAAK,IAAI,CAAA;CAClE,CAAA;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CAgZvB"}
@@ -1,6 +1,8 @@
1
1
  import { DEFAULT_CONTRAST_MODE, } from "./protocol/contrast.js";
2
+ import { LATEST_BRIDGE_PROTOCOL_VERSION } from "./protocol/protocolVersion.js";
2
3
  import { initErrorForFailureReason } from "./lifecycle/initErrors.js";
3
4
  import { createInitializationController } from "./lifecycle/initializationController.js";
5
+ import { normalizeHostToSandboxMessage } from "./lifecycle/normalizeHostToSandboxMessage.js";
4
6
  import { createSandboxMessageRouter } from "./messages/sandboxMessageRouter.js";
5
7
  import { MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION } from "./protocolVersion.js";
6
8
  import { QuerySubscriptions, } from "./queries/querySubscriptions.js";
@@ -8,8 +10,8 @@ import { validateQueryDataSourceFilter } from "./queries/validateQueryDataSource
8
10
  import { validateQueryDataSourceSorts } from "./queries/validateQueryDataSourceSorts.js";
9
11
  export function createCustomBlockHost(options) {
10
12
  const { iframe, initialState, handlers, onManifest, onInitialized, onInitializationFailure, onRestartRequired, onLog, sandboxOrigin, minBridgeProtocolVersion: configuredMinBridgeProtocolVersion, noConnectTimeoutMs, noInitResultTimeoutMs, } = options;
11
- // Callers can retire older SDKs, but cannot restore support for protocols
12
- // the runtime no longer implements. Omission uses the runtime minimum.
13
+ // Callers can retire older SDKs, but cannot restore support for protocols the runtime no longer
14
+ // implements. Omission uses the runtime minimum.
13
15
  const minBridgeProtocolVersion = Math.max(configuredMinBridgeProtocolVersion ??
14
16
  MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION, MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION);
15
17
  let theme = initialState.theme;
@@ -18,6 +20,7 @@ export function createCustomBlockHost(options) {
18
20
  let page = initialState.page;
19
21
  let dataSources = initialState.dataSources;
20
22
  let activeDataSources;
23
+ let sandboxBridgeProtocolVersion = LATEST_BRIDGE_PROTOCOL_VERSION;
21
24
  let manifest = initialState.manifest;
22
25
  let currentUser = initialState.currentUser;
23
26
  let pendingThemeChange = false;
@@ -31,8 +34,9 @@ export function createCustomBlockHost(options) {
31
34
  onLog?.(direction, payload);
32
35
  }
33
36
  function post(message) {
34
- emit("out", message);
35
- iframe.contentWindow?.postMessage(message, sandboxOrigin);
37
+ const sandboxMessage = normalizeHostToSandboxMessage(message, sandboxBridgeProtocolVersion);
38
+ emit("out", sandboxMessage);
39
+ iframe.contentWindow?.postMessage(sandboxMessage, sandboxOrigin);
36
40
  }
37
41
  function postQueryDataSourceResult(args) {
38
42
  const message = args.response.status === "error"
@@ -53,22 +57,12 @@ export function createCustomBlockHost(options) {
53
57
  }
54
58
  async function handleQuery(message, token = querySubscriptions.subscribe(message)) {
55
59
  const collectionSchema = getCollectionSchema(activeDataSources, message.dataSourceId);
56
- const filterError = validateQueryDataSourceFilter(message.filter, collectionSchema);
57
- if (filterError !== undefined) {
60
+ const queryError = getQueryValidationError(message, collectionSchema);
61
+ if (queryError !== undefined) {
58
62
  if (querySubscriptions.isCurrent(message.subscriptionId, token)) {
59
63
  postQueryDataSourceResult({
60
64
  subscriptionId: message.subscriptionId,
61
- response: { status: "error", error: filterError },
62
- });
63
- }
64
- return;
65
- }
66
- const sortError = validateQueryDataSourceSorts(message.sorts, collectionSchema);
67
- if (sortError !== undefined) {
68
- if (querySubscriptions.isCurrent(message.subscriptionId, token)) {
69
- postQueryDataSourceResult({
70
- subscriptionId: message.subscriptionId,
71
- response: { status: "error", error: sortError },
65
+ response: { status: "error", error: queryError },
72
66
  });
73
67
  }
74
68
  return;
@@ -179,7 +173,10 @@ export function createCustomBlockHost(options) {
179
173
  if (pendingDataSourcesChange !== undefined) {
180
174
  const nextDataSources = pendingDataSourcesChange;
181
175
  pendingDataSourcesChange = undefined;
182
- post({ type: "dataSourcesChanged", dataSources: nextDataSources });
176
+ post({
177
+ type: "dataSourcesChanged",
178
+ dataSources: nextDataSources,
179
+ });
183
180
  }
184
181
  if (pendingCurrentUserChange) {
185
182
  pendingCurrentUserChange = false;
@@ -196,6 +193,7 @@ export function createCustomBlockHost(options) {
196
193
  currentUser,
197
194
  }),
198
195
  prepareInit(connect) {
196
+ sandboxBridgeProtocolVersion = connect.bridgeProtocolVersion;
199
197
  manifest = connect.manifest ?? initialState.manifest;
200
198
  if (manifest === undefined) {
201
199
  return {
@@ -382,3 +380,18 @@ function getBindingErrorCode(manifest, dataSources) {
382
380
  }
383
381
  return undefined;
384
382
  }
383
+ function getQueryValidationError(message, collectionSchema) {
384
+ // The host can omit the database schema. Queries without filters or sorts need no schema validation.
385
+ if (collectionSchema === undefined) {
386
+ if (message.filter === undefined && (message.sorts?.length ?? 0) === 0) {
387
+ return undefined;
388
+ }
389
+ return {
390
+ code: "data_source_schema_unavailable",
391
+ message: "You cannot query this data source with filters or sorts because its schema is unavailable.",
392
+ isRetryable: false,
393
+ };
394
+ }
395
+ return (validateQueryDataSourceFilter(message.filter, collectionSchema) ??
396
+ validateQueryDataSourceSorts(message.sorts, collectionSchema));
397
+ }
@@ -0,0 +1,6 @@
1
+ import type { HostToSandboxMessage } from "../protocol/messages/hostToSandbox.js";
2
+ /**
3
+ * Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
4
+ */
5
+ export declare function normalizeHostToSandboxMessage(message: HostToSandboxMessage, bridgeProtocolVersion: number): HostToSandboxMessage;
6
+ //# sourceMappingURL=normalizeHostToSandboxMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/lifecycle/normalizeHostToSandboxMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AAEtG;;GAEG;AAGH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,MAAM,GAC3B,oBAAoB,CAkCtB"}
@@ -0,0 +1,38 @@
1
+ import { NOTION_BUILTIN_PROPERTY_SCHEMAS } from "../protocol/dataSources/propertySchema.js";
2
+ /**
3
+ * Normalizes an outgoing message for the bridge protocol version requested by the sandbox.
4
+ */
5
+ // TODO(custom-blocks): Remove this function when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION
6
+ // reaches 5.
7
+ export function normalizeHostToSandboxMessage(message, bridgeProtocolVersion) {
8
+ // The latest SDK version does not need any normalization.
9
+ if (bridgeProtocolVersion >= 5) {
10
+ return message;
11
+ }
12
+ const containsDataSources = (message.type === "init" && message.status === "success") ||
13
+ message.type === "dataSourcesChanged";
14
+ if (!containsDataSources) {
15
+ return message;
16
+ }
17
+ // Protocol 5 excludes synthetic IDs such as created_time from collectionSchema.propertiesById.
18
+ // Older SDKs derive read schemas from that map. Restore those entries in outgoing copies so
19
+ // host query validation still uses the actual database schema.
20
+ return {
21
+ ...message,
22
+ dataSources: {
23
+ bindings: Object.fromEntries(Object.entries(message.dataSources.bindings).map(([key, binding]) => [
24
+ key,
25
+ {
26
+ ...binding,
27
+ collectionSchema: {
28
+ ...binding.collectionSchema,
29
+ propertiesById: {
30
+ ...binding.collectionSchema?.propertiesById,
31
+ ...NOTION_BUILTIN_PROPERTY_SCHEMAS,
32
+ },
33
+ },
34
+ },
35
+ ])),
36
+ },
37
+ };
38
+ }
@@ -7,6 +7,11 @@ declare const collectionPointerValidator: v.ObjectSchema<{
7
7
  export type NotionCollectionPointer = v.InferOutput<typeof collectionPointerValidator>;
8
8
  export declare const notionCollectionSchemaValidator: v.ObjectSchema<{
9
9
  readonly id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>, undefined>;
10
+ /**
11
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
12
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
13
+ * to validate filter and sort references.
14
+ */
10
15
  readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
11
16
  readonly name: v.StringSchema<undefined>;
12
17
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -144,8 +149,8 @@ export declare const notionCollectionSchemaValidator: v.ObjectSchema<{
144
149
  }, undefined>;
145
150
  export type NotionCollectionSchema = v.InferOutput<typeof notionCollectionSchemaValidator>;
146
151
  /**
147
- * Bridge shape for a single data source: a semantic key bound (optionally) to a collection,
148
- * its property name → ID mapping, and its column schemas.
152
+ * Describes a data source, its optional database binding, and its property schemas. The
153
+ * database schema validates query references. The read schemas describe snapshot values.
149
154
  */
150
155
  export declare const notionDataSourceSchema: v.ObjectSchema<{
151
156
  readonly key: v.StringSchema<undefined>;
@@ -154,8 +159,18 @@ export declare const notionDataSourceSchema: v.ObjectSchema<{
154
159
  readonly table: v.StringSchema<undefined>;
155
160
  readonly spaceId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionSpaceId">]>, undefined>;
156
161
  }, undefined>, undefined>;
162
+ /**
163
+ * Describes database properties. Use this schema to resolve property bindings. Use this
164
+ * schema to validate filter and sort references. Undefined when the host does not provide a
165
+ * database schema.
166
+ */
157
167
  readonly collectionSchema: v.OptionalSchema<v.ObjectSchema<{
158
168
  readonly id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>, undefined>;
169
+ /**
170
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
171
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
172
+ * to validate filter and sort references.
173
+ */
159
174
  readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
160
175
  readonly name: v.StringSchema<undefined>;
161
176
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -292,13 +307,21 @@ export declare const notionDataSourceSchema: v.ObjectSchema<{
292
307
  }, undefined>], undefined>, undefined>;
293
308
  }, undefined>, undefined>;
294
309
  /**
295
- * Keyed mapping of user-defined keys to a raw property ID. A key mapped to `undefined`
296
- * is a declared-but-unbound slot.
310
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
311
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
312
+ * property without a valid binding. Synthetic metadata does not add entries to this map.
297
313
  */
298
314
  readonly propertyIdsByKey: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.StringSchema<undefined>, undefined>, undefined>;
299
315
  /**
300
- * Keyed mapping of raw property IDs to their schema. Always includes the four built-ins
301
- * (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
316
+ * Describes property values in query snapshots. Keys use the same property IDs as a snapshot's
317
+ * `propertiesById` map.
318
+ *
319
+ * Includes four synthetic metadata fields, even when the database schema is unavailable:
320
+ * `created_time`, `last_edited_time`, `created_by`, and `last_edited_by`. Also includes
321
+ * database properties when the host provides their schema.
322
+ *
323
+ * Use `propertiesById` to read a value. Use this map to read the value's schema. Use
324
+ * `collectionSchema` to validate filter and sort references.
302
325
  */
303
326
  readonly propertySchemasById: v.RecordSchema<v.StringSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
304
327
  readonly name: v.StringSchema<undefined>;
@@ -442,8 +465,18 @@ export declare const notionDataSourceBindingSchema: v.ObjectSchema<{
442
465
  readonly table: v.StringSchema<undefined>;
443
466
  readonly spaceId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionSpaceId">]>, undefined>;
444
467
  }, undefined>, undefined>;
468
+ /**
469
+ * Describes database properties. Use this schema to resolve property bindings. Use this
470
+ * schema to validate filter and sort references. Undefined when the host does not provide a
471
+ * database schema.
472
+ */
445
473
  readonly collectionSchema: v.OptionalSchema<v.ObjectSchema<{
446
474
  readonly id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>, undefined>;
475
+ /**
476
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
477
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
478
+ * to validate filter and sort references.
479
+ */
447
480
  readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
448
481
  readonly name: v.StringSchema<undefined>;
449
482
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -579,6 +612,12 @@ export declare const notionDataSourceBindingSchema: v.ObjectSchema<{
579
612
  readonly type: v.LiteralSchema<"last_edited_by", undefined>;
580
613
  }, undefined>], undefined>, undefined>;
581
614
  }, undefined>, undefined>;
615
+ /**
616
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
617
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
618
+ * property without a binding. Omitted when the host does not provide property mappings.
619
+ * Synthetic metadata does not add entries to this map.
620
+ */
582
621
  readonly propertyIdsByKey: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
583
622
  }, undefined>;
584
623
  export type NotionDataSourceBinding = v.InferOutput<typeof notionDataSourceBindingSchema>;
@@ -588,8 +627,18 @@ export declare const notionDataSourceBindingsSchema: v.RecordSchema<v.StringSche
588
627
  readonly table: v.StringSchema<undefined>;
589
628
  readonly spaceId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionSpaceId">]>, undefined>;
590
629
  }, undefined>, undefined>;
630
+ /**
631
+ * Describes database properties. Use this schema to resolve property bindings. Use this
632
+ * schema to validate filter and sort references. Undefined when the host does not provide a
633
+ * database schema.
634
+ */
591
635
  readonly collectionSchema: v.OptionalSchema<v.ObjectSchema<{
592
636
  readonly id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>, undefined>;
637
+ /**
638
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
639
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
640
+ * to validate filter and sort references.
641
+ */
593
642
  readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
594
643
  readonly name: v.StringSchema<undefined>;
595
644
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -725,6 +774,12 @@ export declare const notionDataSourceBindingsSchema: v.RecordSchema<v.StringSche
725
774
  readonly type: v.LiteralSchema<"last_edited_by", undefined>;
726
775
  }, undefined>], undefined>, undefined>;
727
776
  }, undefined>, undefined>;
777
+ /**
778
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
779
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
780
+ * property without a binding. Omitted when the host does not provide property mappings.
781
+ * Synthetic metadata does not add entries to this map.
782
+ */
728
783
  readonly propertyIdsByKey: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
729
784
  }, undefined>, undefined>;
730
785
  export type NotionDataSourceBindings = v.InferOutput<typeof notionDataSourceBindingsSchema>;
@@ -8,30 +8,59 @@ const collectionPointerValidator = v.object({
8
8
  });
9
9
  export const notionCollectionSchemaValidator = v.object({
10
10
  id: v.optional(notionDataSourceIdSchema),
11
+ /**
12
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
13
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
14
+ * to validate filter and sort references.
15
+ */
11
16
  propertiesById: v.record(v.string(), notionPropertySchemaSchema),
12
17
  });
13
18
  /**
14
- * Bridge shape for a single data source: a semantic key bound (optionally) to a collection,
15
- * its property name → ID mapping, and its column schemas.
19
+ * Describes a data source, its optional database binding, and its property schemas. The
20
+ * database schema validates query references. The read schemas describe snapshot values.
16
21
  */
17
22
  export const notionDataSourceSchema = v.object({
18
23
  key: v.string(),
19
24
  collectionPointer: v.optional(collectionPointerValidator),
25
+ /**
26
+ * Describes database properties. Use this schema to resolve property bindings. Use this
27
+ * schema to validate filter and sort references. Undefined when the host does not provide a
28
+ * database schema.
29
+ */
20
30
  collectionSchema: v.optional(notionCollectionSchemaValidator),
21
31
  /**
22
- * Keyed mapping of user-defined keys to a raw property ID. A key mapped to `undefined`
23
- * is a declared-but-unbound slot.
32
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
33
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
34
+ * property without a valid binding. Synthetic metadata does not add entries to this map.
24
35
  */
25
36
  propertyIdsByKey: v.record(v.string(), v.optional(v.string())),
26
37
  /**
27
- * Keyed mapping of raw property IDs to their schema. Always includes the four built-ins
28
- * (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
38
+ * Describes property values in query snapshots. Keys use the same property IDs as a snapshot's
39
+ * `propertiesById` map.
40
+ *
41
+ * Includes four synthetic metadata fields, even when the database schema is unavailable:
42
+ * `created_time`, `last_edited_time`, `created_by`, and `last_edited_by`. Also includes
43
+ * database properties when the host provides their schema.
44
+ *
45
+ * Use `propertiesById` to read a value. Use this map to read the value's schema. Use
46
+ * `collectionSchema` to validate filter and sort references.
29
47
  */
30
48
  propertySchemasById: v.record(v.string(), notionPropertySchemaSchema),
31
49
  });
32
50
  export const notionDataSourceBindingSchema = v.object({
33
51
  collectionPointer: v.optional(collectionPointerValidator),
52
+ /**
53
+ * Describes database properties. Use this schema to resolve property bindings. Use this
54
+ * schema to validate filter and sort references. Undefined when the host does not provide a
55
+ * database schema.
56
+ */
34
57
  collectionSchema: v.optional(notionCollectionSchemaValidator),
58
+ /**
59
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
60
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
61
+ * property without a binding. Omitted when the host does not provide property mappings.
62
+ * Synthetic metadata does not add entries to this map.
63
+ */
35
64
  propertyIdsByKey: v.optional(v.record(v.string(), v.optional(v.string()))),
36
65
  });
37
66
  export const notionDataSourceBindingsSchema = v.record(v.string(), notionDataSourceBindingSchema);
@@ -195,3 +195,5 @@ export type NotionPropertySchema = v.InferOutput<typeof notionPropertySchemaSche
195
195
  */
196
196
  export declare const NOTION_BUILTIN_PROPERTY_IDS: readonly ["created_time", "last_edited_time", "created_by", "last_edited_by"];
197
197
  export type NotionBuiltinPropertyId = (typeof NOTION_BUILTIN_PROPERTY_IDS)[number];
198
+ /** Schemas for synthetic metadata values in query snapshots. */
199
+ export declare const NOTION_BUILTIN_PROPERTY_SCHEMAS: Record<NotionBuiltinPropertyId, NotionPropertySchema>;
@@ -163,3 +163,10 @@ export const NOTION_BUILTIN_PROPERTY_IDS = [
163
163
  "created_by",
164
164
  "last_edited_by",
165
165
  ];
166
+ /** Schemas for synthetic metadata values in query snapshots. */
167
+ export const NOTION_BUILTIN_PROPERTY_SCHEMAS = {
168
+ created_time: { type: "created_time", name: "Created time" },
169
+ last_edited_time: { type: "last_edited_time", name: "Last edited time" },
170
+ created_by: { type: "created_by", name: "Created by" },
171
+ last_edited_by: { type: "last_edited_by", name: "Last edited by" },
172
+ };
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
2
  import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockCreatePageErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "page_access_failed" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
4
+ export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "page_unavailable" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
5
5
  export type CustomBlockCreatePageErrorInfo = CustomBlockErrorInfo<CustomBlockCreatePageErrorCode>;
6
6
  export declare const customBlockCreatePageErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -1,7 +1,7 @@
1
1
  import * as v from "valibot";
2
2
  import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const customBlockGetPageErrorCodeSchema: v.StringSchema<undefined>;
4
- export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "page_access_failed">;
4
+ export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "page_unavailable">;
5
5
  export type CustomBlockGetPageErrorInfo = CustomBlockErrorInfo<CustomBlockGetPageErrorCode>;
6
6
  export declare const customBlockGetPageErrorInfoSchema: v.ObjectSchema<{
7
7
  readonly code: v.StringSchema<undefined>;
@@ -27,7 +27,10 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
27
27
  }, undefined>, v.ObjectSchema<{
28
28
  readonly type: v.LiteralSchema<"unavailable", undefined>;
29
29
  }, undefined>], undefined>;
30
- readonly page: v.ObjectSchema<{
30
+ readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
31
+ readonly type: v.LiteralSchema<"unavailable", undefined>;
32
+ }, undefined>, v.ObjectSchema<{
33
+ readonly type: v.LiteralSchema<"page", undefined>;
31
34
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
32
35
  readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
33
36
  readonly type: v.LiteralSchema<"page_id", undefined>;
@@ -47,7 +50,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
47
50
  }, undefined>, v.ObjectSchema<{
48
51
  readonly type: v.LiteralSchema<"unavailable", undefined>;
49
52
  }, undefined>], undefined>;
50
- }, undefined>;
53
+ }, undefined>], undefined>;
51
54
  readonly manifest: v.ObjectSchema<{
52
55
  readonly version: v.LiteralSchema<1, undefined>;
53
56
  readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
@@ -261,7 +264,10 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
261
264
  }, undefined>], undefined>;
262
265
  }, undefined>, v.ObjectSchema<{
263
266
  readonly type: v.LiteralSchema<"pageChanged", undefined>;
264
- readonly page: v.ObjectSchema<{
267
+ readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
268
+ readonly type: v.LiteralSchema<"unavailable", undefined>;
269
+ }, undefined>, v.ObjectSchema<{
270
+ readonly type: v.LiteralSchema<"page", undefined>;
265
271
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
266
272
  readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
267
273
  readonly type: v.LiteralSchema<"page_id", undefined>;
@@ -281,7 +287,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
281
287
  }, undefined>, v.ObjectSchema<{
282
288
  readonly type: v.LiteralSchema<"unavailable", undefined>;
283
289
  }, undefined>], undefined>;
284
- }, undefined>;
290
+ }, undefined>], undefined>;
285
291
  }, undefined>, v.ObjectSchema<{
286
292
  readonly type: v.LiteralSchema<"currentUserChanged", undefined>;
287
293
  readonly currentUser: v.ObjectSchema<{
@@ -53,7 +53,10 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
53
53
  }, undefined>, v.ObjectSchema<{
54
54
  readonly type: v.LiteralSchema<"unavailable", undefined>;
55
55
  }, undefined>], undefined>;
56
- readonly page: v.ObjectSchema<{
56
+ readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
57
+ readonly type: v.LiteralSchema<"unavailable", undefined>;
58
+ }, undefined>, v.ObjectSchema<{
59
+ readonly type: v.LiteralSchema<"page", undefined>;
57
60
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
58
61
  readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
59
62
  readonly type: v.LiteralSchema<"page_id", undefined>;
@@ -73,7 +76,7 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
73
76
  }, undefined>, v.ObjectSchema<{
74
77
  readonly type: v.LiteralSchema<"unavailable", undefined>;
75
78
  }, undefined>], undefined>;
76
- }, undefined>;
79
+ }, undefined>], undefined>;
77
80
  readonly manifest: v.ObjectSchema<{
78
81
  readonly version: v.LiteralSchema<1, undefined>;
79
82
  readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
@@ -3,7 +3,7 @@ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  export declare const openPageModeSchema: v.PicklistSchema<["side_peek", "center_peek"], undefined>;
4
4
  export type OpenPageMode = v.InferOutput<typeof openPageModeSchema>;
5
5
  export declare const customBlockOpenPageErrorCodeSchema: v.StringSchema<undefined>;
6
- export type CustomBlockOpenPageErrorCode = CustomBlockErrorCode<"open_page_failed" | "page_access_failed" | "navigation_unavailable">;
6
+ export type CustomBlockOpenPageErrorCode = CustomBlockErrorCode<"open_page_failed" | "page_unavailable" | "navigation_unavailable">;
7
7
  export type CustomBlockOpenPageErrorInfo = CustomBlockErrorInfo<CustomBlockOpenPageErrorCode>;
8
8
  export declare const customBlockOpenPageErrorInfoSchema: v.ObjectSchema<{
9
9
  readonly code: v.StringSchema<undefined>;
@@ -4,7 +4,10 @@ import * as v from "valibot";
4
4
  */
5
5
  export declare const pageChangedMessageSchema: v.ObjectSchema<{
6
6
  readonly type: v.LiteralSchema<"pageChanged", undefined>;
7
- readonly page: v.ObjectSchema<{
7
+ readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
8
+ readonly type: v.LiteralSchema<"unavailable", undefined>;
9
+ }, undefined>, v.ObjectSchema<{
10
+ readonly type: v.LiteralSchema<"page", undefined>;
8
11
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
9
12
  readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
10
13
  readonly type: v.LiteralSchema<"page_id", undefined>;
@@ -24,6 +27,6 @@ export declare const pageChangedMessageSchema: v.ObjectSchema<{
24
27
  }, undefined>, v.ObjectSchema<{
25
28
  readonly type: v.LiteralSchema<"unavailable", undefined>;
26
29
  }, undefined>], undefined>;
27
- }, undefined>;
30
+ }, undefined>], undefined>;
28
31
  }, undefined>;
29
32
  export type PageChangedMessage = v.InferOutput<typeof pageChangedMessageSchema>;