@notionhq/custom-blocks 0.2.21 → 0.2.23

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 (70) hide show
  1. package/README.md +2 -0
  2. package/dist/bridge/SandboxBridge.d.ts +14 -18
  3. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  4. package/dist/bridge/SandboxBridge.js +59 -201
  5. package/dist/bridge/SandboxInitialization.d.ts +52 -0
  6. package/dist/bridge/SandboxInitialization.d.ts.map +1 -0
  7. package/dist/bridge/SandboxInitialization.js +217 -0
  8. package/dist/bridge/dataSources/query.d.ts.map +1 -1
  9. package/dist/bridge/dataSources/query.js +39 -23
  10. package/dist/bridge/messageInterceptor.d.ts +4 -0
  11. package/dist/bridge/messageInterceptor.d.ts.map +1 -0
  12. package/dist/bridge/messageInterceptor.js +1 -0
  13. package/dist/bridge/sandboxClient.d.ts +3 -2
  14. package/dist/bridge/sandboxClient.d.ts.map +1 -1
  15. package/dist/bridge/sandboxClient.js +3 -5
  16. package/dist/bridge.d.ts +11 -0
  17. package/dist/bridge.d.ts.map +1 -0
  18. package/dist/bridge.js +11 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/init.d.ts +4 -38
  22. package/dist/init.d.ts.map +1 -1
  23. package/dist/init.js +4 -91
  24. package/dist/initTypes.d.ts +31 -0
  25. package/dist/initTypes.d.ts.map +1 -0
  26. package/dist/initTypes.js +18 -0
  27. package/dist/protocol/dataSources/propertySchema.d.ts +1 -1
  28. package/dist/protocol/dataSources/propertySchema.js +2 -0
  29. package/dist/protocol/dataSources/sortDirection.d.ts +3 -0
  30. package/dist/protocol/dataSources/sortDirection.js +2 -0
  31. package/dist/protocol/index.d.ts +1 -0
  32. package/dist/protocol/index.js +1 -0
  33. package/dist/protocol/manifest.d.ts +10 -3
  34. package/dist/protocol/manifest.js +5 -1
  35. package/dist/protocol/messages/connect.d.ts +9 -2
  36. package/dist/protocol/messages/hostToSandbox.d.ts +9 -5
  37. package/dist/protocol/messages/init.d.ts +10 -3
  38. package/dist/protocol/messages/queryDataSource.d.ts +300 -47
  39. package/dist/protocol/messages/queryDataSource.js +107 -9
  40. package/dist/protocol/messages/sandboxToHost.d.ts +103 -18
  41. package/dist/styles/nds.css +1 -1
  42. package/dist/types.d.ts +8 -3
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/version.js +1 -1
  45. package/docs/bridge-interceptors.md +27 -0
  46. package/docs/data-sources.md +93 -13
  47. package/docs/errors.md +3 -2
  48. package/docs/lifecycle.md +1 -1
  49. package/docs/pages.md +22 -10
  50. package/package.json +4 -4
  51. package/src/bridge/SandboxBridge.ts +74 -239
  52. package/src/bridge/SandboxInitialization.ts +295 -0
  53. package/src/bridge/dataSources/query.ts +51 -25
  54. package/src/bridge/messageInterceptor.ts +6 -0
  55. package/src/bridge/sandboxClient.ts +6 -5
  56. package/src/bridge.ts +17 -0
  57. package/src/index.ts +1 -0
  58. package/src/init.ts +8 -119
  59. package/src/initTypes.ts +43 -0
  60. package/src/styles/nds.css +1 -1
  61. package/src/styles/nds.css.metadata.json +3 -3
  62. package/src/types.ts +11 -2
  63. package/dist/bridge/primedResponses.d.ts +0 -8
  64. package/dist/bridge/primedResponses.d.ts.map +0 -1
  65. package/dist/bridge/primedResponses.js +0 -5
  66. package/dist/testing.d.ts +0 -12
  67. package/dist/testing.d.ts.map +0 -1
  68. package/dist/testing.js +0 -9
  69. package/src/bridge/primedResponses.ts +0 -11
  70. package/src/testing.ts +0 -19
@@ -0,0 +1,18 @@
1
+ import { CustomBlockInitializationError } from "./protocol/messages/init.js";
2
+ /**
3
+ * Error thrown when the SDK is loaded in a top-level standalone window with no parent frame.
4
+ * `postMessage` would just hit the same window and the handshake can never complete.
5
+ * `<NotionCustomBlock>` catches this specifically and falls back to a standalone preview with a
6
+ * warning banner. Direct callers can `instanceof` it to apply their own policy.
7
+ */
8
+ export class NotInIframeError extends CustomBlockInitializationError {
9
+ constructor(message = NOT_IN_IFRAME_MESSAGE) {
10
+ super({
11
+ code: "not_in_iframe",
12
+ message,
13
+ isRetryable: false,
14
+ });
15
+ this.name = "NotInIframeError";
16
+ }
17
+ }
18
+ const NOT_IN_IFRAME_MESSAGE = "Custom block initialization requires a Notion host. For local development, open the block in the dev shell. Otherwise, deploy it to Notion.";
@@ -48,7 +48,7 @@ export type NotionPropertyType = v.InferOutput<typeof notionPropertyTypeSchema>;
48
48
  * Keep this list narrower than {@link NOTION_PROPERTY_TYPES} when a property
49
49
  * type is exposed but its sort value is not yet represented by every host.
50
50
  */
51
- export declare const CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES: readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "date", "created_time", "last_edited_time"];
51
+ export declare const CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES: readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "date", "created_time", "last_edited_time", "people", "created_by"];
52
52
  export type CustomBlockDataSourceSortablePropertyType = (typeof CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES)[number];
53
53
  /**
54
54
  * Per-property schema as exposed by the host over the custom-block bridge.
@@ -100,6 +100,8 @@ export const CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES = [
100
100
  "date",
101
101
  "created_time",
102
102
  "last_edited_time",
103
+ "people",
104
+ "created_by",
103
105
  ];
104
106
  /**
105
107
  * Per-property schema as exposed by the host over the custom-block bridge.
@@ -0,0 +1,3 @@
1
+ import * as v from "valibot";
2
+ export declare const notionSortDirectionSchema: v.PicklistSchema<["ascending", "descending"], undefined>;
3
+ export type NotionSortDirection = v.InferOutput<typeof notionSortDirectionSchema>;
@@ -0,0 +1,2 @@
1
+ import * as v from "valibot";
2
+ export const notionSortDirectionSchema = v.picklist(["ascending", "descending"]);
@@ -13,6 +13,7 @@ export * from "./dataSources/dateValue.js";
13
13
  export * from "./dataSources/errors.js";
14
14
  export * from "./dataSources/propertySchema.js";
15
15
  export * from "./dataSources/recordPointer.js";
16
+ export * from "./dataSources/sortDirection.js";
16
17
  export * from "./errors.js";
17
18
  export * from "./ids.js";
18
19
  export * from "./manifest.js";
@@ -13,6 +13,7 @@ export * from "./dataSources/dateValue.js";
13
13
  export * from "./dataSources/errors.js";
14
14
  export * from "./dataSources/propertySchema.js";
15
15
  export * from "./dataSources/recordPointer.js";
16
+ export * from "./dataSources/sortDirection.js";
16
17
  export * from "./errors.js";
17
18
  export * from "./ids.js";
18
19
  export * from "./manifest.js";
@@ -37,7 +37,14 @@ export declare const manifestDataSourceSchema: v.ObjectSchema<{
37
37
  export type ManifestDataSource = v.InferOutput<typeof manifestDataSourceSchema>;
38
38
  export declare const manifestSchema: v.ObjectSchema<{
39
39
  readonly version: v.LiteralSchema<1, undefined>;
40
- readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
40
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
41
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
42
+ readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
43
+ readonly icon: v.OptionalSchema<v.ObjectSchema<{
44
+ readonly type: v.LiteralSchema<"emoji", undefined>;
45
+ readonly emoji: v.StringSchema<undefined>;
46
+ }, undefined>, undefined>;
47
+ readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
41
48
  readonly name: v.StringSchema<undefined>;
42
49
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
43
50
  readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
@@ -52,9 +59,9 @@ export declare const manifestSchema: v.ObjectSchema<{
52
59
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
53
60
  readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
54
61
  }, undefined>, undefined>, {}>;
55
- }, undefined>, undefined>;
62
+ }, undefined>, undefined>, {}>;
56
63
  }, undefined>;
57
64
  /**
58
- * Manifest declaring the data sources required by a custom block.
65
+ * Manifest describing a custom block and its required data sources.
59
66
  */
60
67
  export type CustomBlockManifest = v.InferOutput<typeof manifestSchema>;
@@ -28,5 +28,9 @@ export const manifestDataSourceSchema = v.object({
28
28
  });
29
29
  export const manifestSchema = v.object({
30
30
  version: v.literal(1),
31
- dataSources: v.record(v.string(), manifestDataSourceSchema),
31
+ name: v.optional(v.string()),
32
+ description: v.optional(v.string()),
33
+ slashCommand: v.optional(v.string()),
34
+ icon: v.optional(v.object({ type: v.literal("emoji"), emoji: v.string() })),
35
+ dataSources: v.optional(v.record(v.string(), manifestDataSourceSchema), {}),
32
36
  });
@@ -15,7 +15,14 @@ export declare const connectMessageSchema: v.VariantSchema<"status", [v.ObjectSc
15
15
  */
16
16
  readonly manifest: v.OptionalSchema<v.ObjectSchema<{
17
17
  readonly version: v.LiteralSchema<1, undefined>;
18
- readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
18
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
19
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
20
+ readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
21
+ readonly icon: v.OptionalSchema<v.ObjectSchema<{
22
+ readonly type: v.LiteralSchema<"emoji", undefined>;
23
+ readonly emoji: v.StringSchema<undefined>;
24
+ }, undefined>, undefined>;
25
+ readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
19
26
  readonly name: v.StringSchema<undefined>;
20
27
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
21
28
  readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
@@ -30,7 +37,7 @@ export declare const connectMessageSchema: v.VariantSchema<"status", [v.ObjectSc
30
37
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
31
38
  readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
32
39
  }, undefined>, undefined>, {}>;
33
- }, undefined>, undefined>;
40
+ }, undefined>, undefined>, {}>;
34
41
  }, undefined>, undefined>;
35
42
  }, undefined>, v.ObjectSchema<{
36
43
  readonly type: v.LiteralSchema<"connect", undefined>;
@@ -53,7 +53,14 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
53
53
  }, undefined>], undefined>;
54
54
  readonly manifest: v.ObjectSchema<{
55
55
  readonly version: v.LiteralSchema<1, undefined>;
56
- readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
56
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
57
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
58
+ readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
59
+ readonly icon: v.OptionalSchema<v.ObjectSchema<{
60
+ readonly type: v.LiteralSchema<"emoji", undefined>;
61
+ readonly emoji: v.StringSchema<undefined>;
62
+ }, undefined>, undefined>;
63
+ readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
57
64
  readonly name: v.StringSchema<undefined>;
58
65
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
59
66
  readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
@@ -68,7 +75,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
68
75
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
69
76
  readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
70
77
  }, undefined>, undefined>, {}>;
71
- }, undefined>, undefined>;
78
+ }, undefined>, undefined>, {}>;
72
79
  }, undefined>;
73
80
  readonly dataSources: v.ObjectSchema<{
74
81
  readonly bindings: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
@@ -1201,6 +1208,3 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
1201
1208
  readonly reason: v.StringSchema<undefined>;
1202
1209
  }, undefined>], undefined>;
1203
1210
  export type HostToSandboxMessage = v.InferOutput<typeof hostToSandboxMessageSchema>;
1204
- export type PrimeableHostToSandboxMessage = Extract<HostToSandboxMessage, {
1205
- type: "getPageResult" | "openPageResult" | "createPageResult" | "updatePageResult" | "getUserResult" | "listUsersResult" | "queryDataSourceResult";
1206
- }>;
@@ -2,7 +2,7 @@ import * as v from "valibot";
2
2
  import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
3
3
  import type { CustomBlockInitResultErrorCode } from "./initResult.js";
4
4
  export declare const customBlockInitErrorCodeSchema: v.StringSchema<undefined>;
5
- export type CustomBlockInitErrorCode = CustomBlockErrorCode<"manifest_unavailable" | "manifest_invalid" | "invalid_connect_payload" | "invalid_protocol_version" | "unsupported_protocol_version" | "init_timeout" | "context_unavailable" | "current_user_unavailable" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding">;
5
+ export type CustomBlockInitErrorCode = CustomBlockErrorCode<"manifest_unavailable" | "manifest_invalid" | "invalid_connect_payload" | "invalid_protocol_version" | "unsupported_protocol_version" | "init_timeout" | "context_unavailable" | "current_user_unavailable" | "initial_state_timeout" | "missing_data_source_binding" | "data_source_unavailable" | "missing_property_binding" | "invalid_property_binding">;
6
6
  export type CustomBlockInitErrorInfo = CustomBlockErrorInfo<CustomBlockInitErrorCode>;
7
7
  /**
8
8
  * Every initialization failure visible to block code. This combines errors
@@ -79,7 +79,14 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
79
79
  }, undefined>], undefined>;
80
80
  readonly manifest: v.ObjectSchema<{
81
81
  readonly version: v.LiteralSchema<1, undefined>;
82
- readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
82
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
83
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
84
+ readonly slashCommand: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
85
+ readonly icon: v.OptionalSchema<v.ObjectSchema<{
86
+ readonly type: v.LiteralSchema<"emoji", undefined>;
87
+ readonly emoji: v.StringSchema<undefined>;
88
+ }, undefined>, undefined>;
89
+ readonly dataSources: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
83
90
  readonly name: v.StringSchema<undefined>;
84
91
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
85
92
  readonly icon: v.OptionalSchema<v.VariantSchema<"type", [v.ObjectSchema<{
@@ -94,7 +101,7 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
94
101
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
95
102
  readonly type: v.PicklistSchema<readonly ["title", "rich_text", "number", "checkbox", "url", "email", "phone_number", "select", "multi_select", "status", "date", "people", "files", "unique_id", "relation", "place", "formula", "rollup", "button", "verification", "last_visited_time", "location", "created_time", "last_edited_time", "created_by", "last_edited_by"], undefined>;
96
103
  }, undefined>, undefined>, {}>;
97
- }, undefined>, undefined>;
104
+ }, undefined>, undefined>, {}>;
98
105
  }, undefined>;
99
106
  readonly dataSources: v.ObjectSchema<{
100
107
  readonly bindings: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{