@notionhq/custom-blocks-dev-shell 0.1.114 → 0.1.115

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 (131) hide show
  1. package/README.md +27 -14
  2. package/bin/cli.js +3 -1
  3. package/dist/assets/index-DXzPwq_J.js +11 -0
  4. package/dist/index.html +1 -1
  5. package/dist-cli/cli/binding-cli-flags.js +33 -0
  6. package/dist-cli/cli/binding-errors.js +15 -0
  7. package/dist-cli/{build-block-registry.js → cli/build-block-registry.js} +2 -0
  8. package/dist-cli/{convert-values.js → cli/convert-values.js} +5 -5
  9. package/dist-cli/{convert.js → cli/convert.js} +3 -3
  10. package/dist-cli/cli/data-source-files.js +6 -0
  11. package/dist-cli/{data-sources.js → cli/data-sources.js} +12 -65
  12. package/dist-cli/{dev-shell-launcher.js → cli/dev-shell-launcher.js} +23 -10
  13. package/dist-cli/{errors.js → cli/errors.js} +5 -1
  14. package/dist-cli/cli/launcher-bindings.js +144 -0
  15. package/dist-cli/{published-cli.js → cli/published-cli.js} +2 -2
  16. package/dist-cli/{worker-manifest.js → cli/worker-manifest.js} +18 -1
  17. package/dist-cli/protocol/contrast.d.ts +4 -0
  18. package/dist-cli/protocol/contrast.js +3 -0
  19. package/dist-cli/protocol/dataSources/dataSource.d.ts +786 -0
  20. package/dist-cli/protocol/dataSources/dataSource.js +66 -0
  21. package/dist-cli/protocol/dataSources/dataSourcePage.d.ts +74 -0
  22. package/dist-cli/protocol/dataSources/dataSourcePage.js +15 -0
  23. package/dist-cli/protocol/dataSources/dataSourceValue.d.ts +66 -0
  24. package/dist-cli/protocol/dataSources/dataSourceValue.js +14 -0
  25. package/dist-cli/protocol/dataSources/dateValue.d.ts +157 -0
  26. package/dist-cli/protocol/dataSources/dateValue.js +61 -0
  27. package/dist-cli/protocol/dataSources/errors.d.ts +8 -0
  28. package/dist-cli/protocol/dataSources/errors.js +7 -0
  29. package/dist-cli/protocol/dataSources/propertySchema.d.ts +200 -0
  30. package/dist-cli/protocol/dataSources/propertySchema.js +174 -0
  31. package/dist-cli/protocol/dataSources/recordPointer.d.ts +9 -0
  32. package/dist-cli/protocol/dataSources/recordPointer.js +8 -0
  33. package/dist-cli/protocol/dataSources/sortDirection.d.ts +3 -0
  34. package/dist-cli/protocol/dataSources/sortDirection.js +2 -0
  35. package/dist-cli/protocol/errors.d.ts +12 -0
  36. package/dist-cli/protocol/errors.js +6 -0
  37. package/dist-cli/protocol/ids.d.ts +31 -0
  38. package/dist-cli/protocol/ids.js +26 -0
  39. package/dist-cli/protocol/index.d.ts +53 -0
  40. package/dist-cli/protocol/index.js +53 -0
  41. package/dist-cli/protocol/manifest.d.ts +67 -0
  42. package/dist-cli/protocol/manifest.js +36 -0
  43. package/dist-cli/protocol/messages/connect.d.ts +54 -0
  44. package/dist-cli/protocol/messages/connect.js +39 -0
  45. package/dist-cli/protocol/messages/contrastModeChanged.d.ts +7 -0
  46. package/dist-cli/protocol/messages/contrastModeChanged.js +7 -0
  47. package/dist-cli/protocol/messages/createPage.d.ts +290 -0
  48. package/dist-cli/protocol/messages/createPage.js +51 -0
  49. package/dist-cli/protocol/messages/createPageResult.d.ts +897 -0
  50. package/dist-cli/protocol/messages/createPageResult.js +43 -0
  51. package/dist-cli/protocol/messages/currentUserChanged.d.ts +18 -0
  52. package/dist-cli/protocol/messages/currentUserChanged.js +9 -0
  53. package/dist-cli/protocol/messages/dataSourcesChanged.d.ts +157 -0
  54. package/dist-cli/protocol/messages/dataSourcesChanged.js +13 -0
  55. package/dist-cli/protocol/messages/getPage.d.ts +902 -0
  56. package/dist-cli/protocol/messages/getPage.js +48 -0
  57. package/dist-cli/protocol/messages/getUser.d.ts +44 -0
  58. package/dist-cli/protocol/messages/getUser.js +32 -0
  59. package/dist-cli/protocol/messages/hostToSandbox.d.ts +4385 -0
  60. package/dist-cli/protocol/messages/hostToSandbox.js +48 -0
  61. package/dist-cli/protocol/messages/incomingType.d.ts +9 -0
  62. package/dist-cli/protocol/messages/incomingType.js +17 -0
  63. package/dist-cli/protocol/messages/init.d.ts +273 -0
  64. package/dist-cli/protocol/messages/init.js +57 -0
  65. package/dist-cli/protocol/messages/initResult.d.ts +37 -0
  66. package/dist-cli/protocol/messages/initResult.js +29 -0
  67. package/dist-cli/protocol/messages/invalidHostMessage.d.ts +14 -0
  68. package/dist-cli/protocol/messages/invalidHostMessage.js +13 -0
  69. package/dist-cli/protocol/messages/invalidSandboxMessage.d.ts +14 -0
  70. package/dist-cli/protocol/messages/invalidSandboxMessage.js +13 -0
  71. package/dist-cli/protocol/messages/isInitHandshakeMessage.d.ts +4 -0
  72. package/dist-cli/protocol/messages/isInitHandshakeMessage.js +11 -0
  73. package/dist-cli/protocol/messages/listUsers.d.ts +52 -0
  74. package/dist-cli/protocol/messages/listUsers.js +33 -0
  75. package/dist-cli/protocol/messages/messagePayload.d.ts +19 -0
  76. package/dist-cli/protocol/messages/messagePayload.js +1 -0
  77. package/dist-cli/protocol/messages/openExternalUrl.d.ts +32 -0
  78. package/dist-cli/protocol/messages/openExternalUrl.js +26 -0
  79. package/dist-cli/protocol/messages/openPage.d.ts +38 -0
  80. package/dist-cli/protocol/messages/openPage.js +34 -0
  81. package/dist-cli/protocol/messages/pageChanged.d.ts +32 -0
  82. package/dist-cli/protocol/messages/pageChanged.js +9 -0
  83. package/dist-cli/protocol/messages/parentChanged.d.ts +26 -0
  84. package/dist-cli/protocol/messages/parentChanged.js +9 -0
  85. package/dist-cli/protocol/messages/queryDataSource.d.ts +1446 -0
  86. package/dist-cli/protocol/messages/queryDataSource.js +252 -0
  87. package/dist-cli/protocol/messages/queryDataSourceResult.d.ts +686 -0
  88. package/dist-cli/protocol/messages/queryDataSourceResult.js +44 -0
  89. package/dist-cli/protocol/messages/resize.d.ts +11 -0
  90. package/dist-cli/protocol/messages/resize.js +10 -0
  91. package/dist-cli/protocol/messages/sandboxToHost.d.ts +1091 -0
  92. package/dist-cli/protocol/messages/sandboxToHost.js +33 -0
  93. package/dist-cli/protocol/messages/themeChanged.d.ts +10 -0
  94. package/dist-cli/protocol/messages/themeChanged.js +10 -0
  95. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.d.ts +10 -0
  96. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.js +9 -0
  97. package/dist-cli/protocol/messages/updatePage.d.ts +271 -0
  98. package/dist-cli/protocol/messages/updatePage.js +23 -0
  99. package/dist-cli/protocol/messages/updatePageResult.d.ts +895 -0
  100. package/dist-cli/protocol/messages/updatePageResult.js +41 -0
  101. package/dist-cli/protocol/pages/page.d.ts +1422 -0
  102. package/dist-cli/protocol/pages/page.js +318 -0
  103. package/dist-cli/protocol/parent.d.ts +32 -0
  104. package/dist-cli/protocol/parent.js +13 -0
  105. package/dist-cli/protocol/protocolVersion.d.ts +8 -0
  106. package/dist-cli/protocol/protocolVersion.js +11 -0
  107. package/dist-cli/protocol/theme.d.ts +3 -0
  108. package/dist-cli/protocol/theme.js +2 -0
  109. package/dist-cli/protocol/users/user.d.ts +32 -0
  110. package/dist-cli/protocol/users/user.js +20 -0
  111. package/dist-cli/shared/block-registry.js +28 -0
  112. package/dist-cli/shared/data-source.js +22 -0
  113. package/dist-cli/shared/runtime-config.js +10 -0
  114. package/dist-cli/shared/sample-data-source.js +12 -0
  115. package/docs/bindings.md +79 -27
  116. package/package.json +5 -26
  117. package/dist/assets/index-F02ZboyS.js +0 -11
  118. package/dist-cli/date-value.js +0 -46
  119. package/dist-cli/resolve-bindings.js +0 -39
  120. package/dist-cli/source-bindings.js +0 -17
  121. /package/dist-cli/{block-csp.js → cli/block-csp.js} +0 -0
  122. /package/dist-cli/{dev-shell-run.js → cli/dev-shell-run.js} +0 -0
  123. /package/dist-cli/{materialize.js → cli/materialize.js} +0 -0
  124. /package/dist-cli/{ports.js → cli/ports.js} +0 -0
  125. /package/dist-cli/{prebuilt.js → cli/prebuilt.js} +0 -0
  126. /package/dist-cli/{runtime-error-client.js → cli/runtime-error-client.js} +0 -0
  127. /package/dist-cli/{serve-ui.js → cli/serve-ui.js} +0 -0
  128. /package/dist-cli/{shared-server.js → cli/shared-server.js} +0 -0
  129. /package/dist-cli/{utils.js → cli/utils.js} +0 -0
  130. /package/dist-cli/{vite-block-server.js → cli/vite-block-server.js} +0 -0
  131. /package/dist-cli/{vite-middleware.js → cli/vite-middleware.js} +0 -0
@@ -0,0 +1,318 @@
1
+ /**
2
+ * Notion page shapes exchanged over the custom block bridge.
3
+ *
4
+ * These mirror a narrow subset of Notion's public `POST /v1/pages` API, since that's the bridge
5
+ * shape the host delivers for messages like `createPageResult`.
6
+ */
7
+ import * as v from "valibot";
8
+ import { notionDateReminderSchema, notionDateTimeReminderSchema, notionDisabledReminderSchema, } from "../dataSources/dateValue.js";
9
+ import { notionRecordPointerSchema } from "../dataSources/recordPointer.js";
10
+ import { notionPageIdSchema } from "../ids.js";
11
+ import { notionParentSchema } from "../parent.js";
12
+ /**
13
+ * The custom block's nearest enclosing page ancestor, carried in `init.page` and `pageChanged`.
14
+ */
15
+ export const customBlockPageSchema = v.variant("type", [
16
+ /** The viewer cannot access the containing page; its ID and parent are not exposed. */
17
+ v.object({ type: v.literal("unavailable") }),
18
+ /** The viewer can access the containing page; includes its ID and parent location. */
19
+ v.object({
20
+ type: v.literal("page"),
21
+ id: notionPageIdSchema,
22
+ /**
23
+ * The containing page's own parent. It lets a block distinguish a freestanding page from a
24
+ * database row without a round trip. Not to be confused with the top-level `parent` runtime
25
+ * value, which is the custom block's own parent.
26
+ */
27
+ parent: notionParentSchema,
28
+ }),
29
+ ]);
30
+ export const notionEmojiIconSchema = v.object({
31
+ type: v.literal("emoji"),
32
+ emoji: v.string(),
33
+ });
34
+ export const notionCustomEmojiIconSchema = v.object({
35
+ type: v.literal("custom_emoji"),
36
+ custom_emoji: v.object({
37
+ id: v.string(),
38
+ name: v.optional(v.string()),
39
+ url: v.optional(v.string()),
40
+ }),
41
+ });
42
+ export const notionExternalFileSchema = v.object({
43
+ type: v.literal("external"),
44
+ external: v.object({ url: v.string() }),
45
+ });
46
+ export const notionHostedFileSchema = v.object({
47
+ type: v.literal("file"),
48
+ file: v.object({
49
+ url: v.string(),
50
+ expiry_time: v.optional(v.string()),
51
+ }),
52
+ });
53
+ export const notionPageIconSchema = v.variant("type", [
54
+ notionEmojiIconSchema,
55
+ notionCustomEmojiIconSchema,
56
+ notionExternalFileSchema,
57
+ notionHostedFileSchema,
58
+ ]);
59
+ export const notionPageCoverSchema = v.variant("type", [
60
+ notionExternalFileSchema,
61
+ notionHostedFileSchema,
62
+ ]);
63
+ const nullableStringSchema = v.nullable(v.string());
64
+ const notionRichTextItemSchema = v.record(v.string(), v.unknown());
65
+ const notionSelectOptionInputSchema = v.union([
66
+ v.object({
67
+ id: v.string(),
68
+ name: v.optional(v.string()),
69
+ color: v.optional(v.string()),
70
+ description: v.optional(nullableStringSchema),
71
+ }),
72
+ v.object({
73
+ name: v.string(),
74
+ id: v.optional(v.string()),
75
+ color: v.optional(v.string()),
76
+ description: v.optional(nullableStringSchema),
77
+ }),
78
+ ]);
79
+ const dateInputEntries = {
80
+ start: v.string(),
81
+ end: v.optional(nullableStringSchema),
82
+ time_zone: v.optional(nullableStringSchema),
83
+ reminder: v.optional(v.union([notionDateTimeReminderSchema, notionDisabledReminderSchema])),
84
+ };
85
+ const notionDateInputSchema = v.union([
86
+ v.object({
87
+ ...dateInputEntries,
88
+ start: v.pipe(v.string(), v.includes("T")),
89
+ }),
90
+ v.object({
91
+ ...dateInputEntries,
92
+ time_zone: v.string(),
93
+ }),
94
+ v.object({
95
+ ...dateInputEntries,
96
+ reminder: v.optional(v.union([notionDateReminderSchema, notionDisabledReminderSchema])),
97
+ }),
98
+ ]);
99
+ const notionUserInputSchema = v.union([
100
+ v.object({
101
+ object: v.optional(v.literal("user")),
102
+ id: v.string(),
103
+ }),
104
+ v.object({
105
+ object: v.literal("group"),
106
+ id: v.string(),
107
+ name: v.optional(nullableStringSchema),
108
+ }),
109
+ ]);
110
+ const notionRelationInputSchema = v.object({ id: v.string() });
111
+ const notionFileInputSchema = v.union([
112
+ v.object({
113
+ type: v.literal("external"),
114
+ name: v.string(),
115
+ external: v.object({ url: v.string() }),
116
+ }),
117
+ v.object({
118
+ type: v.literal("file"),
119
+ name: v.string(),
120
+ file: v.object({
121
+ url: v.string(),
122
+ expiry_time: v.optional(v.string()),
123
+ }),
124
+ }),
125
+ ]);
126
+ const notionPlaceInputSchema = v.object({
127
+ lat: v.number(),
128
+ lon: v.number(),
129
+ name: v.optional(nullableStringSchema),
130
+ address: v.optional(nullableStringSchema),
131
+ aws_place_id: v.optional(nullableStringSchema),
132
+ google_place_id: v.optional(nullableStringSchema),
133
+ });
134
+ const pagePropertyBaseSchema = {
135
+ id: v.string(),
136
+ };
137
+ // TODO(custom-blocks): Make spaceId required for metadataActor
138
+ const metadataActorSchema = v.nullable(v.object({
139
+ ...notionRecordPointerSchema.entries,
140
+ table: v.picklist(["notion_user", "bot", "organization_bot"]),
141
+ spaceId: v.optional(v.string()),
142
+ }));
143
+ /**
144
+ * A page property value.
145
+ */
146
+ export const notionPagePropertyValueSchema = v.variant("type", [
147
+ v.object({
148
+ ...pagePropertyBaseSchema,
149
+ type: v.literal("title"),
150
+ title: v.array(notionRichTextItemSchema),
151
+ }),
152
+ v.object({
153
+ ...pagePropertyBaseSchema,
154
+ type: v.literal("rich_text"),
155
+ rich_text: v.array(notionRichTextItemSchema),
156
+ }),
157
+ v.object({
158
+ ...pagePropertyBaseSchema,
159
+ type: v.literal("number"),
160
+ number: v.nullable(v.number()),
161
+ }),
162
+ v.object({
163
+ ...pagePropertyBaseSchema,
164
+ type: v.literal("url"),
165
+ url: nullableStringSchema,
166
+ }),
167
+ v.object({
168
+ ...pagePropertyBaseSchema,
169
+ type: v.literal("email"),
170
+ email: nullableStringSchema,
171
+ }),
172
+ v.object({
173
+ ...pagePropertyBaseSchema,
174
+ type: v.literal("phone_number"),
175
+ phone_number: nullableStringSchema,
176
+ }),
177
+ v.object({
178
+ ...pagePropertyBaseSchema,
179
+ type: v.literal("checkbox"),
180
+ checkbox: v.boolean(),
181
+ }),
182
+ v.object({
183
+ ...pagePropertyBaseSchema,
184
+ type: v.literal("select"),
185
+ select: v.nullable(notionSelectOptionInputSchema),
186
+ }),
187
+ v.object({
188
+ ...pagePropertyBaseSchema,
189
+ type: v.literal("status"),
190
+ status: v.nullable(notionSelectOptionInputSchema),
191
+ }),
192
+ v.object({
193
+ ...pagePropertyBaseSchema,
194
+ type: v.literal("multi_select"),
195
+ multi_select: v.array(notionSelectOptionInputSchema),
196
+ }),
197
+ v.object({
198
+ ...pagePropertyBaseSchema,
199
+ type: v.literal("date"),
200
+ date: v.nullable(notionDateInputSchema),
201
+ }),
202
+ v.object({
203
+ ...pagePropertyBaseSchema,
204
+ type: v.literal("people"),
205
+ people: v.array(notionUserInputSchema),
206
+ }),
207
+ v.object({
208
+ ...pagePropertyBaseSchema,
209
+ type: v.literal("relation"),
210
+ has_more: v.optional(v.boolean()),
211
+ relation: v.array(notionRelationInputSchema),
212
+ }),
213
+ v.object({
214
+ ...pagePropertyBaseSchema,
215
+ type: v.literal("files"),
216
+ files: v.array(notionFileInputSchema),
217
+ }),
218
+ v.object({
219
+ ...pagePropertyBaseSchema,
220
+ type: v.literal("place"),
221
+ place: v.nullable(notionPlaceInputSchema),
222
+ }),
223
+ v.object({
224
+ ...pagePropertyBaseSchema,
225
+ type: v.literal("created_time"),
226
+ created_time: nullableStringSchema,
227
+ }),
228
+ v.object({
229
+ ...pagePropertyBaseSchema,
230
+ type: v.literal("last_edited_time"),
231
+ last_edited_time: nullableStringSchema,
232
+ }),
233
+ v.object({
234
+ ...pagePropertyBaseSchema,
235
+ type: v.literal("created_by"),
236
+ created_by: metadataActorSchema,
237
+ }),
238
+ v.object({
239
+ ...pagePropertyBaseSchema,
240
+ type: v.literal("last_edited_by"),
241
+ last_edited_by: metadataActorSchema,
242
+ }),
243
+ v.object({
244
+ ...pagePropertyBaseSchema,
245
+ type: v.literal("last_visited_time"),
246
+ last_visited_time: nullableStringSchema,
247
+ }),
248
+ v.object({
249
+ ...pagePropertyBaseSchema,
250
+ type: v.literal("unique_id"),
251
+ unique_id: v.string(),
252
+ }),
253
+ v.object({
254
+ ...pagePropertyBaseSchema,
255
+ type: v.literal("button"),
256
+ button: v.string(),
257
+ }),
258
+ v.object({
259
+ ...pagePropertyBaseSchema,
260
+ type: v.literal("formula"),
261
+ formula: v.string(),
262
+ }),
263
+ v.object({
264
+ ...pagePropertyBaseSchema,
265
+ type: v.literal("location"),
266
+ location: v.string(),
267
+ }),
268
+ v.object({
269
+ ...pagePropertyBaseSchema,
270
+ type: v.literal("rollup"),
271
+ rollup: v.string(),
272
+ }),
273
+ v.object({
274
+ ...pagePropertyBaseSchema,
275
+ type: v.literal("verification"),
276
+ verification: v.string(),
277
+ }),
278
+ ]);
279
+ export const notionPagePropertyWriteMapSchema = v.record(v.string(), notionPagePropertyValueSchema);
280
+ export const notionPagePropertyReadMapSchema = v.record(v.string(), v.nullable(notionPagePropertyValueSchema));
281
+ /**
282
+ * The `Page` object returned in `createPageResult` messages.
283
+ */
284
+ export const notionPageDataSchema = v.object({
285
+ object: v.literal("page"),
286
+ id: notionPageIdSchema,
287
+ parent: notionParentSchema,
288
+ properties: notionPagePropertyReadMapSchema,
289
+ created_by: v.optional(metadataActorSchema, null),
290
+ last_edited_by: v.optional(metadataActorSchema, null),
291
+ last_visited_time: v.optional(v.nullable(v.string()), null),
292
+ created_time: v.optional(v.nullable(v.string()), null),
293
+ last_edited_time: v.optional(v.nullable(v.string()), null),
294
+ icon: v.optional(v.nullable(notionPageIconSchema), null),
295
+ cover: v.optional(v.nullable(notionPageCoverSchema), null),
296
+ url: v.optional(v.nullable(v.string()), null),
297
+ public_url: v.optional(v.nullable(v.string()), null),
298
+ /** Whether the page or an ancestor is archived. */
299
+ is_archived: v.boolean(),
300
+ /** Whether the page or an ancestor is in Trash. */
301
+ in_trash: v.boolean(),
302
+ });
303
+ export const legacyNotionPageSchema = v.object({
304
+ object: v.literal("page"),
305
+ id: notionPageIdSchema,
306
+ parent: notionParentSchema,
307
+ properties: notionPagePropertyWriteMapSchema,
308
+ created_time: v.optional(v.string()),
309
+ last_edited_time: v.optional(v.string()),
310
+ icon: v.optional(notionPageIconSchema),
311
+ cover: v.optional(notionPageCoverSchema),
312
+ url: v.optional(v.string()),
313
+ public_url: v.optional(v.string()),
314
+ /** Whether the page or an ancestor is archived. */
315
+ is_archived: v.boolean(),
316
+ /** Whether the page or an ancestor is in Trash. */
317
+ in_trash: v.boolean(),
318
+ });
@@ -0,0 +1,32 @@
1
+ import * as v from "valibot";
2
+ export declare const notionParentSchema: v.VariantSchema<"type", [v.ObjectSchema<{
3
+ readonly type: v.LiteralSchema<"page_id", undefined>;
4
+ readonly page_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
5
+ }, undefined>, v.ObjectSchema<{
6
+ readonly type: v.LiteralSchema<"data_source_id", undefined>;
7
+ readonly data_source_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionDataSourceId">]>;
8
+ }, undefined>, v.ObjectSchema<{
9
+ readonly type: v.LiteralSchema<"workspace", undefined>;
10
+ readonly workspace: v.LiteralSchema<true, undefined>;
11
+ }, undefined>, v.ObjectSchema<{
12
+ readonly type: v.LiteralSchema<"block_id", undefined>;
13
+ readonly block_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionBlockId">]>;
14
+ }, undefined>, v.ObjectSchema<{
15
+ readonly type: v.LiteralSchema<"agent_id", undefined>;
16
+ readonly agent_id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionAgentId">]>;
17
+ }, undefined>, v.ObjectSchema<{
18
+ readonly type: v.LiteralSchema<"unavailable", undefined>;
19
+ }, undefined>], undefined>;
20
+ /**
21
+ * A record's parent reference.
22
+ *
23
+ * Uses Notion public API parent names, plus an unavailable state:
24
+ * - `page_id` — parented directly under a page.
25
+ * - `block_id` — parented under a non-page container block (toggle, column, callout, ...).
26
+ * - `data_source_id` — parented under a collection (data source).
27
+ * - `workspace` — top-level / team-rooted.
28
+ * - `agent_id` — owned by an agent, such as an agent instruction page or its blocks.
29
+ * - `unavailable` — the viewer cannot access the parent resource. Neither its ID nor its kind
30
+ * is exposed, including when a readable child identifies the parent as a data source.
31
+ */
32
+ export type NotionParent = v.InferOutput<typeof notionParentSchema>;
@@ -0,0 +1,13 @@
1
+ import * as v from "valibot";
2
+ import { notionAgentIdSchema, notionBlockIdSchema, notionDataSourceIdSchema, notionPageIdSchema, } from "./ids.js";
3
+ export const notionParentSchema = v.variant("type", [
4
+ v.object({ type: v.literal("page_id"), page_id: notionPageIdSchema }),
5
+ v.object({
6
+ type: v.literal("data_source_id"),
7
+ data_source_id: notionDataSourceIdSchema,
8
+ }),
9
+ v.object({ type: v.literal("workspace"), workspace: v.literal(true) }),
10
+ v.object({ type: v.literal("block_id"), block_id: notionBlockIdSchema }),
11
+ v.object({ type: v.literal("agent_id"), agent_id: notionAgentIdSchema }),
12
+ v.object({ type: v.literal("unavailable") }),
13
+ ]);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The protocol version that the current SDK sends in `connect`.
3
+ * Increase this value for breaking wire changes. Hosts can continue to accept
4
+ * older versions, so this value does not set the minimum or maximum they accept.
5
+ */
6
+ export declare const LATEST_BRIDGE_PROTOCOL_VERSION = 7;
7
+ export declare const LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION = 6;
8
+ export declare const TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION = 7;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The protocol version that the current SDK sends in `connect`.
3
+ * Increase this value for breaking wire changes. Hosts can continue to accept
4
+ * older versions, so this value does not set the minimum or maximum they accept.
5
+ */
6
+ export const LATEST_BRIDGE_PROTOCOL_VERSION = 7;
7
+ // Protocol 6 introduces unified pages with name-keyed property objects.
8
+ // Keep this cutoff fixed when the latest protocol version increases.
9
+ export const LEGACY_PROPERTY_SHAPE_PROTOCOL_VERSION = 6;
10
+ // Protocol 7 adds typed text fallbacks for previously unsupported page properties.
11
+ export const TEXT_FALLBACK_PROPERTY_PROTOCOL_VERSION = 7;
@@ -0,0 +1,3 @@
1
+ import * as v from "valibot";
2
+ export declare const notionThemeSchema: v.PicklistSchema<["light", "dark"], undefined>;
3
+ export type NotionTheme = v.InferOutput<typeof notionThemeSchema>;
@@ -0,0 +1,2 @@
1
+ import * as v from "valibot";
2
+ export const notionThemeSchema = v.picklist(["light", "dark"]);
@@ -0,0 +1,32 @@
1
+ import * as v from "valibot";
2
+ export declare const notionUserIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionUserId">]>;
3
+ export type NotionUserId = v.InferOutput<typeof notionUserIdSchema>;
4
+ export declare const notionUserSchema: v.ObjectSchema<{
5
+ readonly object: v.LiteralSchema<"user", undefined>;
6
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionUserId">]>;
7
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
8
+ readonly avatar_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
9
+ readonly type: v.LiteralSchema<"person", undefined>;
10
+ readonly person: v.ObjectSchema<{
11
+ readonly email: v.StringSchema<undefined>;
12
+ }, undefined>;
13
+ }, undefined>;
14
+ export type NotionUser = v.InferOutput<typeof notionUserSchema>;
15
+ export declare const notionUserListSchema: v.ObjectSchema<{
16
+ readonly object: v.LiteralSchema<"list", undefined>;
17
+ readonly results: v.ArraySchema<v.ObjectSchema<{
18
+ readonly object: v.LiteralSchema<"user", undefined>;
19
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionUserId">]>;
20
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
21
+ readonly avatar_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
22
+ readonly type: v.LiteralSchema<"person", undefined>;
23
+ readonly person: v.ObjectSchema<{
24
+ readonly email: v.StringSchema<undefined>;
25
+ }, undefined>;
26
+ }, undefined>, undefined>;
27
+ readonly next_cursor: v.NullableSchema<v.StringSchema<undefined>, undefined>;
28
+ readonly has_more: v.BooleanSchema<undefined>;
29
+ readonly type: v.LiteralSchema<"user", undefined>;
30
+ readonly user: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
31
+ }, undefined>;
32
+ export type NotionUserList = v.InferOutput<typeof notionUserListSchema>;
@@ -0,0 +1,20 @@
1
+ import * as v from "valibot";
2
+ export const notionUserIdSchema = v.pipe(v.string(), v.brand("NotionUserId"));
3
+ export const notionUserSchema = v.object({
4
+ object: v.literal("user"),
5
+ id: notionUserIdSchema,
6
+ name: v.optional(v.string()),
7
+ avatar_url: v.nullable(v.string()),
8
+ type: v.literal("person"),
9
+ person: v.object({
10
+ email: v.string(),
11
+ }),
12
+ });
13
+ export const notionUserListSchema = v.object({
14
+ object: v.literal("list"),
15
+ results: v.array(notionUserSchema),
16
+ next_cursor: v.nullable(v.string()),
17
+ has_more: v.boolean(),
18
+ type: v.literal("user"),
19
+ user: v.record(v.string(), v.unknown()),
20
+ });
@@ -0,0 +1,28 @@
1
+ import { manifestSchema } from "../protocol/index.js";
2
+ import * as v from "valibot";
3
+ /** Launcher configuration serialized to the dev shell UI. */
4
+ const registryBlockSchema = v.object({
5
+ key: v.string(),
6
+ name: v.string(),
7
+ url: v.string(),
8
+ /** Invalid manifests stay unavailable so the preview can report the failure. */
9
+ manifest: v.optional(manifestSchema),
10
+ /** Maps each slot key to a filename in data/, including .json. Other slots use filename defaults. */
11
+ sampleFilesByDataSource: v.optional(v.record(v.string(), v.string()), {}),
12
+ /** Maps slot keys to declared property keys, then to sample schema keys. Overrides automatic matches. */
13
+ propertyIdsByDataSource: v.optional(v.record(v.string(), v.record(v.string(), v.string())), {}),
14
+ });
15
+ /** Validate registry fields while retaining blocks with invalid manifests. */
16
+ export function parseRegistryBlocks(input) {
17
+ const metadataSchema = v.looseObject(v.omit(registryBlockSchema, ["manifest"]).entries);
18
+ return v.parse(v.array(metadataSchema), input).map(block => {
19
+ const parsed = v.safeParse(manifestSchema, block.manifest);
20
+ if (!parsed.success) {
21
+ console.warn("[dev-shell] Invalid worker manifest", {
22
+ blockKey: block.key,
23
+ issues: parsed.issues,
24
+ });
25
+ }
26
+ return { ...block, manifest: parsed.success ? parsed.output : undefined };
27
+ });
28
+ }
@@ -0,0 +1,22 @@
1
+ import { notionPropertySchemaSchema } from "../protocol/index.js";
2
+ import * as v from "valibot";
3
+ export const dataSourceTypeSchema = v.picklist([
4
+ "built-in",
5
+ "worker",
6
+ "manual",
7
+ "syncedFromProd",
8
+ ]);
9
+ const dataSourceRowSchema = v.looseObject({ id: v.string() });
10
+ const dataSourcePropertiesSchema = v.record(v.string(), notionPropertySchemaSchema);
11
+ /** Normalized sample data sent from the launcher to the browser. */
12
+ export const dataSourceSchema = v.object({
13
+ type: dataSourceTypeSchema,
14
+ key: v.string(),
15
+ filename: v.optional(v.string()),
16
+ name: v.string(),
17
+ /** Optional emoji shown alongside the source. */
18
+ icon: v.optional(v.string()),
19
+ schema: dataSourcePropertiesSchema,
20
+ rows: v.array(dataSourceRowSchema),
21
+ });
22
+ const fileDataSourceSchema = v.required(dataSourceSchema, ["filename"]);
@@ -0,0 +1,10 @@
1
+ import * as v from "valibot";
2
+ import { parseRegistryBlocks } from "./block-registry.js";
3
+ import { dataSourceSchema } from "./data-source.js";
4
+ /** Configuration injected into the prebuilt UI or supplied through Vite. */
5
+ export const runtimeConfigSchema = v.object({
6
+ blocks: v.pipe(v.unknown(), v.transform(parseRegistryBlocks)),
7
+ dataSources: v.array(dataSourceSchema),
8
+ /** Filenames without .json. The UI offers bundled sources until all are present. */
9
+ prebuiltFilenames: v.optional(v.array(v.string())),
10
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Select a sample data source by filename for one declared data source slot.
3
+ * Use `explicitFilename` when supplied. Otherwise prefer `worker_<slotKey>.json`
4
+ * over `<slotKey>.json`. Return `undefined` when no file matches.
5
+ */
6
+ export function selectSampleDataSource({ slotKey, sources, explicitFilename, }) {
7
+ if (explicitFilename !== undefined) {
8
+ return sources.find(source => `${source.filename}.json` === explicitFilename);
9
+ }
10
+ return (sources.find(source => source.filename === `worker_${slotKey}`) ??
11
+ sources.find(source => source.filename === slotKey));
12
+ }
package/docs/bindings.md CHANGED
@@ -1,16 +1,19 @@
1
1
  # Dev shell bindings
2
2
 
3
- The dev shell previews your worker's custom blocks with local data from `data/*.json`. Each data
4
- source selects its file in this order:
3
+ The dev shell previews your worker's custom blocks with local data from `data/*.json`.
4
+
5
+ Use launcher flags to select sample files and map properties at startup. You can also edit bindings
6
+ in **Data**. The block initializes once every declared data source and property is connected.
7
+
8
+ Each data source selects its file in this order:
5
9
 
6
10
  1. The explicit `--bind` selection.
7
11
  2. `data/worker_<dataSourceKey>.json`, if it exists.
8
12
  3. `data/<dataSourceKey>.json`, if it exists.
9
- 4. Otherwise, it stays unbound. The shell starts, but the block cannot initialize until you connect
10
- the source in **Data**.
13
+ 4. If neither file exists, the data source stays unbound.
11
14
 
12
- An invalid explicit selection stops startup instead of falling back to another file. An empty file
13
- still takes precedence over later choices.
15
+ An invalid explicit selection stops startup. A valid source with no rows still takes precedence over
16
+ later choices.
14
17
 
15
18
  ## Choose sample data
16
19
 
@@ -24,39 +27,88 @@ This connects the `tasks` data source on `task-board` to `data/sample_tasks.json
24
27
  from `data/`, including `.json`.
25
28
 
26
29
  Repeat `--bind` for additional data sources. Sources without an override keep their defaults. When
27
- running `custom-blocks-dev-shell` directly, omit the `--` separator.
30
+ running `custom-blocks-dev-shell` directly, omit the forwarding `--` separator.
31
+
32
+ The launcher rejects unknown, ambiguous, or repeated targets and missing files. Invalid JSON or an
33
+ invalid source file also stops startup.
34
+
35
+ ## Choose property mappings
36
+
37
+ Use `--bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>` when a block
38
+ property must map to a specific property in your sample data:
39
+
40
+ ```bash
41
+ ntn workers customblocks dev -- \
42
+ --bind task-board.tasks=sample_tasks.json \
43
+ --bind-property task-board.tasks.title=task_name \
44
+ --bind-property task-board.tasks.status=workflow_status
45
+ ```
46
+
47
+ This selects `data/sample_tasks.json` for the `tasks` slot on `task-board`. The block's `title`
48
+ property maps to `schema.task_name`, and its `status` property maps to `schema.workflow_status`. The
49
+ source property key is a key in the sample file's `schema`, not its display name.
50
+
51
+ Repeat `--bind-property` for each property you want to set. Explicit mappings override automatic
52
+ matches. Properties without an override keep automatic matching. You can omit `--bind` when the slot
53
+ already selects a file by its default filename. Flag order does not affect source selection.
54
+
55
+ An unknown or ambiguous target, duplicate property target, missing source, missing source property,
56
+ or property type mismatch stops startup. Other properties can remain unmapped until you connect them
57
+ in **Data**.
58
+
59
+ ## Binding errors
60
+
61
+ The launcher stops on the first binding failure. Binding syntax and mapping errors end with
62
+ `(error code: <code>)`, for example:
63
+
64
+ ```text
65
+ Cannot bind task-board.tasks.title: source property "score" has type "number", expected "title". (error code: property_type_mismatch)
66
+ ```
67
+
68
+ The codes identify the cause:
28
69
 
29
- An unknown target, duplicate target, or missing file stops startup. Invalid JSON or an invalid
30
- source file also stops startup.
70
+ | Code | Cause |
71
+ | ----------------------------------- | ----------------------------------------------------------------------------- |
72
+ | `invalid_binding_syntax` | A `--bind` value does not follow the required syntax. |
73
+ | `invalid_property_binding_syntax` | A `--bind-property` value does not follow the required syntax. |
74
+ | `unknown_binding_target` | No block and data source slot match the `--bind` target. |
75
+ | `ambiguous_binding_target` | More than one block and slot match the `--bind` target. |
76
+ | `duplicate_binding_target` | A full `--bind` target appears more than once. |
77
+ | `sample_file_not_found` | The file selected by `--bind` does not exist in `data/`. |
78
+ | `unknown_property_binding_target` | No declared property matches the `--bind-property` target. |
79
+ | `ambiguous_property_binding_target` | More than one declared property matches the target. |
80
+ | `duplicate_property_binding_target` | A full `--bind-property` target appears more than once. |
81
+ | `binding_source_missing` | A property override has neither an explicit source nor a default source file. |
82
+ | `source_property_not_found` | The selected source's `schema` has no entry for the requested property key. |
83
+ | `property_type_mismatch` | The source property type differs from the block property's declared type. |
31
84
 
32
- The browser maps compatible properties automatically. Incomplete mappings do not stop the shell.
33
- Open **Data** to finish connecting the block. Empty rows are valid.
85
+ Repeating a full target fails even when both values are identical. The same property key in
86
+ different slots or blocks is allowed. Multiple declared properties can share a source property when
87
+ their types match.
34
88
 
35
- ## Connecting data
89
+ ## Edit bindings in Data
36
90
 
37
- **Data** in the toolbar opens the bindings modal: one section per slot from the block's
38
- `worker.customBlock({ dataSources })` declaration, each with a source picker and a per-property
39
- mapping. The sources on offer are the ones in your worker's `data/*.json` (format:
40
- [`data-sources.md`](./data-sources.md)). The modal shows each slot and its property mappings.
91
+ Open **Data** in the toolbar to select a source and map properties for each declared data source
92
+ slot. The modal lists your worker's `data/*.json` files. See the
93
+ [sample data format](./data-sources.md) to define a source.
41
94
 
42
- Properties map automatically when there is a unique source property with a matching key or name and
43
- the same type. Use the property pickers to adjust mappings. Selecting a different source resets its
44
- property mappings.
95
+ A property maps automatically only when exactly one source property matches its key or name and has
96
+ the same type. If no property matches, or several properties match, the property stays unmapped.
97
+ Open **Data** to select a mapping. Selecting a different source resets its property mappings.
45
98
 
46
- ## Initialization & binding edits
99
+ ## Initialization and refresh
47
100
 
48
101
  Once every slot is bound and every property mapped, the block initializes and renders. Saving
49
102
  binding changes restarts the block with the updated data. If initialization fails, fix the bindings
50
103
  and save.
51
104
 
52
- Bindings last for the page load, per block: refresh the shell and every block returns to its CLI
53
- selection or filename default.
105
+ Bindings last for the page load, per block. Refresh the shell to restore each block's CLI source and
106
+ property selections, with automatic matching for properties without an override.
54
107
 
55
- The shell reads `data/*.json` once at spin-up. To pick up file edits, restart the dev-shell command;
56
- a browser refresh is not enough.
108
+ The launcher reads `data/*.json` once at startup. To load file edits, restart the dev shell command.
109
+ A browser refresh does not reload the files.
57
110
 
58
111
  ## Data view
59
112
 
60
- Click a data source in the sidebar to inspect its schema and rows, read-only. The shell shows
61
- exactly the sources in `data/`, nothing else. Sources bound to the selected block carry a green
62
- **Bound** pill; the pill follows the block selection, so switching blocks updates it.
113
+ Click a data source in the sidebar to inspect its schema and rows. This view is read-only. Sources
114
+ connected to the selected block show a green **Bound** label.