@notionhq/custom-blocks-dev-shell 0.3.0 → 0.4.0

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.
@@ -180,6 +180,22 @@ function includes(requirement, message$1) {
180
180
  };
181
181
  }
182
182
  // @__NO_SIDE_EFFECTS__
183
+ function integer(message$1) {
184
+ return {
185
+ kind: "validation",
186
+ type: "integer",
187
+ reference: integer,
188
+ async: false,
189
+ expects: null,
190
+ requirement: Number.isInteger,
191
+ message: message$1,
192
+ "~run"(dataset, config$1) {
193
+ if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "integer", dataset, config$1);
194
+ return dataset;
195
+ }
196
+ };
197
+ }
198
+ // @__NO_SIDE_EFFECTS__
183
199
  function maxLength(requirement, message$1) {
184
200
  return {
185
201
  kind: "validation",
@@ -259,6 +275,22 @@ function regex(requirement, message$1) {
259
275
  };
260
276
  }
261
277
  // @__NO_SIDE_EFFECTS__
278
+ function safeInteger(message$1) {
279
+ return {
280
+ kind: "validation",
281
+ type: "safe_integer",
282
+ reference: safeInteger,
283
+ async: false,
284
+ expects: null,
285
+ requirement: Number.isSafeInteger,
286
+ message: message$1,
287
+ "~run"(dataset, config$1) {
288
+ if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "safe integer", dataset, config$1);
289
+ return dataset;
290
+ }
291
+ };
292
+ }
293
+ // @__NO_SIDE_EFFECTS__
262
294
  function transform(operation) {
263
295
  return {
264
296
  kind: "transformation",
@@ -444,6 +476,23 @@ function never(message$1) {
444
476
  });
445
477
  }
446
478
  // @__NO_SIDE_EFFECTS__
479
+ function nonOptional(wrapped, message$1) {
480
+ return _standardSchema({
481
+ kind: "schema",
482
+ type: "non_optional",
483
+ reference: nonOptional,
484
+ expects: "!undefined",
485
+ async: false,
486
+ wrapped,
487
+ message: message$1,
488
+ "~run"(dataset, config$1) {
489
+ if (dataset.value !== void 0) dataset = this.wrapped["~run"](dataset, config$1);
490
+ if (dataset.value === void 0) _addIssue(this, "type", dataset, config$1);
491
+ return dataset;
492
+ }
493
+ });
494
+ }
495
+ // @__NO_SIDE_EFFECTS__
447
496
  function nullable(wrapped, default_) {
448
497
  return _standardSchema({
449
498
  kind: "schema",
@@ -897,6 +946,17 @@ function pipe(...pipe$1) {
897
946
  });
898
947
  }
899
948
  // @__NO_SIDE_EFFECTS__
949
+ function required(schema, arg2, arg3) {
950
+ const keys = Array.isArray(arg2) ? arg2 : void 0;
951
+ const message$1 = Array.isArray(arg2) ? arg3 : arg2;
952
+ const entries$1 = {};
953
+ for (const key in schema.entries) entries$1[key] = !keys || keys.includes(key) ? /* @__PURE__ */ nonOptional(schema.entries[key], message$1) : schema.entries[key];
954
+ return _standardSchema({
955
+ ...schema,
956
+ entries: entries$1
957
+ });
958
+ }
959
+ // @__NO_SIDE_EFFECTS__
900
960
  function safeParse(schema, input, config$1) {
901
961
  const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
902
962
  return {
@@ -907,8 +967,204 @@ function safeParse(schema, input, config$1) {
907
967
  };
908
968
  }
909
969
 
970
+ // ../protocol/src/dataSources/properties/propertySchema.ts
971
+ var notionPropertyColorSchema = picklist([
972
+ "default",
973
+ "gray",
974
+ "brown",
975
+ "orange",
976
+ "yellow",
977
+ "green",
978
+ "blue",
979
+ "purple",
980
+ "pink",
981
+ "red",
982
+ "gray_background",
983
+ "brown_background",
984
+ "orange_background",
985
+ "yellow_background",
986
+ "green_background",
987
+ "blue_background",
988
+ "purple_background",
989
+ "pink_background",
990
+ "red_background",
991
+ "default_background"
992
+ ]);
993
+ var notionPropertyOptionSchema = object({
994
+ id: string(),
995
+ name: string(),
996
+ color: optional(notionPropertyColorSchema),
997
+ description: optional(string())
998
+ });
999
+ var notionStatusGroupSchema = object({
1000
+ id: string(),
1001
+ name: string(),
1002
+ color: optional(notionPropertyColorSchema),
1003
+ option_ids: array(string())
1004
+ });
1005
+ var notionDualPropertySchema = object({
1006
+ synced_property_id: string(),
1007
+ synced_property_name: string()
1008
+ });
1009
+ var baseProp = object({
1010
+ name: string(),
1011
+ description: optional(string())
1012
+ });
1013
+ var NOTION_PROPERTY_TYPES = [
1014
+ "title",
1015
+ "rich_text",
1016
+ "number",
1017
+ "checkbox",
1018
+ "url",
1019
+ "email",
1020
+ "phone_number",
1021
+ "select",
1022
+ "multi_select",
1023
+ "status",
1024
+ "date",
1025
+ "people",
1026
+ "files",
1027
+ "unique_id",
1028
+ "relation",
1029
+ "place",
1030
+ "formula",
1031
+ "rollup",
1032
+ "button",
1033
+ "verification",
1034
+ "created_time",
1035
+ "last_edited_time",
1036
+ "created_by",
1037
+ "last_edited_by"
1038
+ ];
1039
+ var notionPropertyTypeSchema = picklist(NOTION_PROPERTY_TYPES);
1040
+ var notionPropertySchemaSchema = variant("type", [
1041
+ object({ ...baseProp.entries, type: literal("title") }),
1042
+ object({ ...baseProp.entries, type: literal("rich_text") }),
1043
+ object({ ...baseProp.entries, type: literal("number") }),
1044
+ object({ ...baseProp.entries, type: literal("checkbox") }),
1045
+ object({ ...baseProp.entries, type: literal("url") }),
1046
+ object({ ...baseProp.entries, type: literal("email") }),
1047
+ object({ ...baseProp.entries, type: literal("phone_number") }),
1048
+ object({
1049
+ ...baseProp.entries,
1050
+ type: literal("select"),
1051
+ options: array(notionPropertyOptionSchema)
1052
+ }),
1053
+ object({
1054
+ ...baseProp.entries,
1055
+ type: literal("multi_select"),
1056
+ options: array(notionPropertyOptionSchema)
1057
+ }),
1058
+ object({
1059
+ ...baseProp.entries,
1060
+ type: literal("status"),
1061
+ options: array(notionPropertyOptionSchema),
1062
+ groups: array(notionStatusGroupSchema)
1063
+ }),
1064
+ object({ ...baseProp.entries, type: literal("date") }),
1065
+ object({ ...baseProp.entries, type: literal("people") }),
1066
+ object({ ...baseProp.entries, type: literal("files") }),
1067
+ object({ ...baseProp.entries, type: literal("unique_id") }),
1068
+ object({
1069
+ ...baseProp.entries,
1070
+ type: literal("relation"),
1071
+ data_source_id: optional(string()),
1072
+ dual_property: optional(notionDualPropertySchema)
1073
+ }),
1074
+ object({ ...baseProp.entries, type: literal("place") }),
1075
+ object({ ...baseProp.entries, type: literal("formula") }),
1076
+ object({ ...baseProp.entries, type: literal("rollup") }),
1077
+ // Internal-only types passed through under their bridge-native names.
1078
+ object({ ...baseProp.entries, type: literal("button") }),
1079
+ object({ ...baseProp.entries, type: literal("verification") }),
1080
+ // Page creation and edit metadata property types.
1081
+ object({ ...baseProp.entries, type: literal("created_time") }),
1082
+ object({ ...baseProp.entries, type: literal("last_edited_time") }),
1083
+ object({ ...baseProp.entries, type: literal("created_by") }),
1084
+ object({ ...baseProp.entries, type: literal("last_edited_by") })
1085
+ ]);
1086
+
1087
+ // ../protocol/src/manifest/grants.ts
1088
+ var customBlockGrantSchema = object({
1089
+ action: string(),
1090
+ resource: union([string(), pipe(array(string()), minLength(1))])
1091
+ });
1092
+
1093
+ // ../protocol/src/manifest/manifest.ts
1094
+ var bridgeManifestIconSchema = variant("type", [
1095
+ object({
1096
+ type: literal("emoji"),
1097
+ emoji: string()
1098
+ }),
1099
+ object({
1100
+ type: literal("external"),
1101
+ url: string()
1102
+ })
1103
+ ]);
1104
+ var bridgeManifestPropertySchema = object({
1105
+ name: string(),
1106
+ description: optional(string()),
1107
+ type: notionPropertyTypeSchema
1108
+ });
1109
+ var manifestPageSchema = object({
1110
+ name: string(),
1111
+ description: optional(string()),
1112
+ icon: optional(bridgeManifestIconSchema)
1113
+ });
1114
+ var bridgeManifestDataSourceSchema = object({
1115
+ name: string(),
1116
+ description: optional(string()),
1117
+ icon: optional(bridgeManifestIconSchema),
1118
+ properties: optional(
1119
+ record(string(), bridgeManifestPropertySchema),
1120
+ {}
1121
+ )
1122
+ });
1123
+ var manifestSchema = object({
1124
+ version: literal(1),
1125
+ name: optional(string()),
1126
+ description: optional(string()),
1127
+ slashCommand: optional(string()),
1128
+ icon: optional(object({ type: literal("emoji"), emoji: string() })),
1129
+ dataSources: optional(
1130
+ record(string(), bridgeManifestDataSourceSchema),
1131
+ {}
1132
+ ),
1133
+ pages: optional(record(string(), manifestPageSchema)),
1134
+ /**
1135
+ * Grants the block needs. Omitted means the block predates viewer
1136
+ * approval, so hosts do not ask the viewer. An empty array declares
1137
+ * nothing.
1138
+ */
1139
+ grants: optional(array(customBlockGrantSchema))
1140
+ });
1141
+
1142
+ // ../protocol/src/handshake/connect.ts
1143
+ var connectRequestMessageSchema = object({
1144
+ type: literal("connect"),
1145
+ /** Identifies this request. The host echoes it in `connectResult`. */
1146
+ requestId: string(),
1147
+ /** Every protocol contract the SDK implements, from which the host selects one. */
1148
+ supportedProtocolVersions: pipe(
1149
+ array(pipe(number(), integer(), minValue(1))),
1150
+ minLength(1),
1151
+ check((versions) => new Set(versions).size === versions.length)
1152
+ ),
1153
+ /** SDK package version for diagnostics. Does not select the wire protocol. */
1154
+ sdkVersion: string(),
1155
+ /**
1156
+ * Manifest injected by local dev tooling. The SDK omits it on non-loopback origins.
1157
+ * The host selects it only when `manifestSource` is `"sandbox"`.
1158
+ */
1159
+ manifest: optional(manifestSchema)
1160
+ });
1161
+
1162
+ // ../protocol/src/context/contrast.ts
1163
+ var notionContrastModeSchema = picklist(["standard", "high"]);
1164
+
910
1165
  // ../protocol/src/utils/ids.ts
911
1166
  var notionBlockIdSchema = pipe(string(), brand("NotionBlockId"));
1167
+ var notionViewIdSchema = pipe(string(), brand("NotionViewId"));
912
1168
  var notionDataSourceIdSchema = pipe(
913
1169
  string(),
914
1170
  brand("NotionDataSourceId")
@@ -921,22 +1177,104 @@ var notionAppInstallationIdSchema = pipe(
921
1177
  brand("NotionAppInstallationId")
922
1178
  );
923
1179
 
924
- // ../protocol/src/context/parent.ts
925
- var pageParentSchema = object({
926
- type: literal("page_id"),
927
- page_id: notionPageIdSchema
1180
+ // ../protocol/src/context/instance.ts
1181
+ var customBlockInstanceSchema = variant("type", [
1182
+ strictObject({ type: literal("block"), blockId: notionBlockIdSchema }),
1183
+ strictObject({ type: literal("page"), blockId: notionBlockIdSchema }),
1184
+ strictObject({ type: literal("view"), viewId: notionViewIdSchema })
1185
+ ]);
1186
+
1187
+ // ../protocol/src/context/theme.ts
1188
+ var notionThemeSchema = picklist(["light", "dark"]);
1189
+
1190
+ // ../protocol/src/handshake/init.ts
1191
+ var customBlockInitErrorCodeSchema = string();
1192
+ var customBlockInitErrorInfoSchema = object({
1193
+ code: customBlockInitErrorCodeSchema,
1194
+ message: string(),
1195
+ isRetryable: boolean()
928
1196
  });
929
- var dataSourceParentSchema = object({
930
- type: literal("data_source_id"),
931
- data_source_id: notionDataSourceIdSchema
1197
+ var setupInitMessageSchema = object({
1198
+ type: literal("init"),
1199
+ requestId: string(),
1200
+ instance: customBlockInstanceSchema,
1201
+ manifest: manifestSchema,
1202
+ preferences: object({
1203
+ theme: notionThemeSchema,
1204
+ contrastMode: notionContrastModeSchema
1205
+ })
932
1206
  });
933
- var workspaceParentSchema = object({
934
- type: literal("workspace"),
935
- workspace: literal(true)
1207
+
1208
+ // ../protocol/src/handshake/initResult.ts
1209
+ var customBlockInitResultErrorCodeSchema = string();
1210
+ var customBlockInitResultErrorInfoSchema = object({
1211
+ code: customBlockInitResultErrorCodeSchema,
1212
+ message: string(),
1213
+ isRetryable: boolean()
936
1214
  });
937
- var blockParentSchema = object({
938
- type: literal("block_id"),
939
- block_id: notionBlockIdSchema
1215
+ var initResultRequestMessageSchema = variant("status", [
1216
+ object({
1217
+ type: literal("initResult"),
1218
+ requestId: string(),
1219
+ status: literal("success")
1220
+ }),
1221
+ object({
1222
+ type: literal("initResult"),
1223
+ requestId: string(),
1224
+ status: literal("error"),
1225
+ error: customBlockInitResultErrorInfoSchema
1226
+ })
1227
+ ]);
1228
+
1229
+ // ../protocol/src/utils/errors.ts
1230
+ var customBlockErrorInfoSchema = object({
1231
+ code: string(),
1232
+ message: string(),
1233
+ isRetryable: boolean()
1234
+ });
1235
+
1236
+ // ../protocol/src/compatibility/protocol3To11/connect.ts
1237
+ var connectMessageCommonEntries = {
1238
+ type: literal("connect"),
1239
+ /** Identifies this startup attempt and is echoed in `init` and `initResult`. */
1240
+ initializationId: string(),
1241
+ /** The protocol version declared by the SDK. The host accepts or rejects this version without negotiation. */
1242
+ bridgeProtocolVersion: number(),
1243
+ /** SDK package version for diagnostics. Does not select the wire protocol. */
1244
+ sdkVersion: string()
1245
+ };
1246
+ var protocol3To11ConnectSuccessMessageSchema = object({
1247
+ status: literal("success"),
1248
+ /** Local dev manifest, selected only when `manifestSource` is `"sandbox"`. */
1249
+ manifest: optional(manifestSchema),
1250
+ ...connectMessageCommonEntries
1251
+ });
1252
+ var protocol3To11ConnectErrorMessageSchema = object({
1253
+ status: literal("error"),
1254
+ error: customBlockErrorInfoSchema,
1255
+ ...connectMessageCommonEntries
1256
+ });
1257
+ var protocol3To11ConnectMessageSchema = variant("status", [
1258
+ protocol3To11ConnectSuccessMessageSchema,
1259
+ protocol3To11ConnectErrorMessageSchema
1260
+ ]);
1261
+
1262
+ // ../protocol/src/context/parent.ts
1263
+ var pageParentSchema = object({
1264
+ type: literal("page_id"),
1265
+ page_id: notionPageIdSchema
1266
+ });
1267
+ var dataSourceParentSchema = object({
1268
+ type: literal("data_source_id"),
1269
+ data_source_id: notionDataSourceIdSchema
1270
+ });
1271
+ var workspaceParentSchema = object({
1272
+ type: literal("workspace"),
1273
+ workspace: literal(true)
1274
+ });
1275
+ var blockParentSchema = object({
1276
+ type: literal("block_id"),
1277
+ block_id: notionBlockIdSchema
940
1278
  });
941
1279
  var agentParentSchema = object({
942
1280
  type: literal("agent_id"),
@@ -957,76 +1295,268 @@ var notionParentSchema = variant("type", [
957
1295
  unavailableParentSchema
958
1296
  ]);
959
1297
 
960
- // ../protocol/src/files.ts
961
- var bridgeExternalFileSchema = object({
962
- type: literal("external"),
963
- external: object({ url: string() })
1298
+ // ../protocol/src/dataSources/dataSourcePointer.ts
1299
+ var dataSourcePointerValidator = object({
1300
+ id: notionDataSourceIdSchema,
1301
+ table: string(),
1302
+ spaceId: optional(notionSpaceIdSchema)
964
1303
  });
965
- var bridgeNotionHostedFileSchema = object({
966
- type: literal("file"),
967
- file: object({
968
- url: string(),
969
- expiry_time: optional(string())
1304
+
1305
+ // ../protocol/src/dataSources/dataSourceSchema.ts
1306
+ var notionDataSourceSchemaValidator = object({
1307
+ id: optional(notionDataSourceIdSchema),
1308
+ /**
1309
+ * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
1310
+ * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
1311
+ * to validate filter and sort references.
1312
+ */
1313
+ propertiesById: record(string(), notionPropertySchemaSchema)
1314
+ });
1315
+
1316
+ // ../protocol/src/dataSources/bridgeDataSourceBinding.ts
1317
+ var bridgeDataSourceBindingSchema = object({
1318
+ dataSourcePointer: optional(dataSourcePointerValidator),
1319
+ /**
1320
+ * Describes database properties. Use this schema to resolve property bindings. Use this
1321
+ * schema to validate filter and sort references. Undefined when the host does not provide a
1322
+ * database schema.
1323
+ */
1324
+ dataSourceSchema: optional(notionDataSourceSchemaValidator),
1325
+ /**
1326
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
1327
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
1328
+ * property without a binding. Omitted when the host does not provide property mappings.
1329
+ * Synthetic metadata does not add entries to this map.
1330
+ */
1331
+ propertyIdsByKey: optional(record(string(), optional(string()))),
1332
+ /**
1333
+ * `true` when the data source is bound but the viewer can't read it. The host omits
1334
+ * `dataSourcePointer`, `dataSourceSchema`, and `propertyIdsByKey`, so the binding reveals
1335
+ * nothing about the data source. The block still initializes.
1336
+ */
1337
+ inaccessible: optional(literal(true))
1338
+ });
1339
+
1340
+ // ../protocol/src/dataSources/bridgeDataSourceBindings.ts
1341
+ var bridgeDataSourceBindingsSchema = record(
1342
+ string(),
1343
+ bridgeDataSourceBindingSchema
1344
+ );
1345
+
1346
+ // ../protocol/src/users/userId.ts
1347
+ var notionUserIdSchema = pipe(string(), brand("NotionUserId"));
1348
+
1349
+ // ../protocol/src/compatibility/protocol3To11/bridgeUser.ts
1350
+ var bridgeUserForProtocol3To11Schema = object({
1351
+ object: literal("user"),
1352
+ id: notionUserIdSchema,
1353
+ name: optional(string()),
1354
+ avatar_url: nullable(string()),
1355
+ type: literal("person"),
1356
+ person: object({ email: string() })
1357
+ });
1358
+ var currentUserChangedForProtocol3To11Schema = object({
1359
+ type: literal("currentUserChanged"),
1360
+ currentUser: bridgeUserForProtocol3To11Schema
1361
+ });
1362
+ var getUserResultForProtocol3To11Schema = variant("status", [
1363
+ object({
1364
+ type: literal("getUserResult"),
1365
+ requestId: string(),
1366
+ status: literal("success"),
1367
+ user: bridgeUserForProtocol3To11Schema
1368
+ }),
1369
+ object({
1370
+ type: literal("getUserResult"),
1371
+ requestId: string(),
1372
+ status: literal("error"),
1373
+ error: customBlockErrorInfoSchema
1374
+ })
1375
+ ]);
1376
+ var listUsersResultForProtocol3To11Schema = variant("status", [
1377
+ object({
1378
+ type: literal("listUsersResult"),
1379
+ requestId: string(),
1380
+ status: literal("success"),
1381
+ list: object({
1382
+ object: literal("list"),
1383
+ results: array(bridgeUserForProtocol3To11Schema),
1384
+ next_cursor: nullable(string()),
1385
+ has_more: boolean(),
1386
+ type: literal("user"),
1387
+ user: record(string(), unknown())
1388
+ })
1389
+ }),
1390
+ object({
1391
+ type: literal("listUsersResult"),
1392
+ requestId: string(),
1393
+ status: literal("error"),
1394
+ error: customBlockErrorInfoSchema
1395
+ })
1396
+ ]);
1397
+
1398
+ // ../protocol/src/compatibility/protocol3To11/containingPage.ts
1399
+ var protocol3To11ContainingPageSchema = variant("type", [
1400
+ object({ type: literal("unavailable") }),
1401
+ object({
1402
+ type: literal("page"),
1403
+ id: notionPageIdSchema,
1404
+ parent: notionParentSchema
970
1405
  })
1406
+ ]);
1407
+ var protocol3To11PageChangedMessageSchema = object({
1408
+ type: literal("pageChanged"),
1409
+ page: protocol3To11ContainingPageSchema
971
1410
  });
972
- var bridgeFilePropertyItemSchema = union([
973
- object({ ...bridgeExternalFileSchema.entries, name: string() }),
974
- object({ ...bridgeNotionHostedFileSchema.entries, name: string() })
1411
+
1412
+ // ../protocol/src/compatibility/protocol3To11/init.ts
1413
+ var protocol3To11InitSuccessMessageSchema = object({
1414
+ type: literal("init"),
1415
+ initializationId: string(),
1416
+ status: literal("success"),
1417
+ theme: notionThemeSchema,
1418
+ contrastMode: notionContrastModeSchema,
1419
+ blockId: notionBlockIdSchema,
1420
+ parent: notionParentSchema,
1421
+ page: protocol3To11ContainingPageSchema,
1422
+ manifest: manifestSchema,
1423
+ dataSources: object({
1424
+ bindings: bridgeDataSourceBindingsSchema
1425
+ }),
1426
+ currentUser: bridgeUserForProtocol3To11Schema
1427
+ });
1428
+ var protocol3To11InitMessageSchema = variant("status", [
1429
+ protocol3To11InitSuccessMessageSchema,
1430
+ object({
1431
+ type: literal("init"),
1432
+ initializationId: string(),
1433
+ status: literal("error"),
1434
+ error: customBlockErrorInfoSchema
1435
+ })
975
1436
  ]);
976
1437
 
977
- // ../protocol/src/icons.ts
978
- var bridgeIconNameSchema = string();
979
- var knownBridgeIconColorSchema = picklist([
980
- "gray",
981
- "lightgray",
982
- "brown",
983
- "yellow",
984
- "orange",
985
- "green",
986
- "blue",
987
- "purple",
988
- "pink",
989
- "red"
1438
+ // ../protocol/src/compatibility/protocol3To11/initResult.ts
1439
+ var protocol3To11InitResultMessageSchema = variant("status", [
1440
+ object({
1441
+ type: literal("initResult"),
1442
+ initializationId: string(),
1443
+ status: literal("success"),
1444
+ /** Initial rendered content height in CSS pixels. Omission is accepted for protocols that do not supply it. */
1445
+ initialHeight: optional(pipe(number(), finite(), minValue(0)))
1446
+ }),
1447
+ object({
1448
+ type: literal("initResult"),
1449
+ initializationId: string(),
1450
+ status: literal("error"),
1451
+ error: customBlockErrorInfoSchema
1452
+ })
990
1453
  ]);
991
- var bridgeIconColorSchema = union([
992
- knownBridgeIconColorSchema,
993
- string()
1454
+
1455
+ // ../protocol/src/compatibility/handshake.ts
1456
+ var sandboxConnectMessageSchema = union([
1457
+ connectRequestMessageSchema,
1458
+ protocol3To11ConnectMessageSchema
994
1459
  ]);
995
- var bridgeIconSchema = looseObject({
996
- type: literal("icon"),
997
- icon: looseObject({
998
- name: bridgeIconNameSchema,
999
- color: optional(bridgeIconColorSchema)
1460
+ var hostInitMessageSchema = union([
1461
+ setupInitMessageSchema,
1462
+ protocol3To11InitMessageSchema
1463
+ ]);
1464
+ var initResultMessageWithCompatibilitySchema = union([
1465
+ initResultRequestMessageSchema,
1466
+ protocol3To11InitResultMessageSchema
1467
+ ]);
1468
+
1469
+ // ../protocol/src/context/messages/contrastModeChanged.ts
1470
+ var contrastModeChangedMessageSchema = object({
1471
+ type: literal("contrastModeChanged"),
1472
+ contrastMode: notionContrastModeSchema
1473
+ });
1474
+
1475
+ // ../protocol/src/context/containingPage.ts
1476
+ var customBlockPageSchema = variant("type", [
1477
+ /** The viewer cannot access the containing page. Its ID and parent are not exposed. */
1478
+ object({ type: literal("unavailable") }),
1479
+ /** The accessible containing page, with its ID and parent location. */
1480
+ object({
1481
+ type: literal("page"),
1482
+ id: notionPageIdSchema,
1483
+ /**
1484
+ * The containing page's own parent. It lets a block distinguish a freestanding page from a
1485
+ * database row without a round trip. Not to be confused with the top-level `parent` runtime
1486
+ * value, which is the custom block's own parent.
1487
+ */
1488
+ parent: notionParentSchema,
1489
+ /** How this block's containing page is displayed. Defaults to `full_page` for hosts without peek presentation. */
1490
+ displayMode: optional(
1491
+ picklist(["full_page", "side_peek", "center_peek"]),
1492
+ "full_page"
1493
+ )
1000
1494
  })
1495
+ ]);
1496
+
1497
+ // ../protocol/src/context/messages/pageChanged.ts
1498
+ var pageChangedMessageSchema = object({
1499
+ type: literal("pageChanged"),
1500
+ page: customBlockPageSchema
1001
1501
  });
1002
- var bridgeEmojiSchema = object({
1003
- type: literal("emoji"),
1004
- emoji: string()
1502
+
1503
+ // ../protocol/src/context/messages/pageError.ts
1504
+ var pageErrorMessageSchema = object({
1505
+ type: literal("pageError"),
1506
+ error: customBlockErrorInfoSchema
1005
1507
  });
1006
- var bridgeCustomEmojiSchema = object({
1007
- type: literal("custom_emoji"),
1008
- custom_emoji: object({
1009
- id: string(),
1010
- name: optional(string()),
1011
- url: optional(string())
1508
+
1509
+ // ../protocol/src/context/messages/parentChanged.ts
1510
+ var parentChangedMessageSchema = object({
1511
+ type: literal("parentChanged"),
1512
+ parent: notionParentSchema
1513
+ });
1514
+
1515
+ // ../protocol/src/context/messages/parentError.ts
1516
+ var parentErrorMessageSchema = object({
1517
+ type: literal("parentError"),
1518
+ error: customBlockErrorInfoSchema
1519
+ });
1520
+
1521
+ // ../protocol/src/context/messages/themeChanged.ts
1522
+ var themeChangedMessageSchema = object({
1523
+ type: literal("themeChanged"),
1524
+ theme: notionThemeSchema
1525
+ });
1526
+
1527
+ // ../protocol/src/dataSources/messages/dataSourcesChanged.ts
1528
+ var dataSourcesChangedMessageSchema = object({
1529
+ type: literal("dataSourcesChanged"),
1530
+ dataSources: object({
1531
+ bindings: bridgeDataSourceBindingsSchema
1012
1532
  })
1013
1533
  });
1014
1534
 
1015
- // ../protocol/src/pages/pageAppearance.ts
1016
- var bridgePageIconSchema = variant("type", [
1017
- bridgeIconSchema,
1018
- bridgeEmojiSchema,
1019
- bridgeCustomEmojiSchema,
1020
- bridgeExternalFileSchema,
1021
- bridgeNotionHostedFileSchema
1022
- ]);
1023
- var bridgePageCoverSchema = variant("type", [
1024
- bridgeExternalFileSchema,
1025
- bridgeNotionHostedFileSchema
1535
+ // ../protocol/src/dataSources/messages/getDataSource.ts
1536
+ var getDataSourceMessageSchema = object({
1537
+ type: literal("getDataSource"),
1538
+ requestId: string(),
1539
+ key: string()
1540
+ });
1541
+ var getDataSourceResultMessageSchema = variant("status", [
1542
+ object({
1543
+ type: literal("getDataSourceResult"),
1544
+ requestId: string(),
1545
+ status: literal("success"),
1546
+ binding: required(
1547
+ omit(bridgeDataSourceBindingSchema, ["inaccessible"])
1548
+ )
1549
+ }),
1550
+ object({
1551
+ type: literal("getDataSourceResult"),
1552
+ requestId: string(),
1553
+ status: literal("error"),
1554
+ error: customBlockErrorInfoSchema
1555
+ })
1026
1556
  ]);
1027
-
1028
- // ../protocol/src/utils/nullableStringSchema.ts
1029
- var nullableStringSchema = nullable(string());
1557
+ var dataSourcesInvalidatedMessageSchema = object({
1558
+ type: literal("dataSourcesInvalidated")
1559
+ });
1030
1560
 
1031
1561
  // ../protocol/src/dataSources/properties/dateValue.ts
1032
1562
  var notionDateReminderSchema = object({
@@ -1079,13 +1609,110 @@ var notionDateTimeRangeSchema = object({
1079
1609
  time_zone: optional(string()),
1080
1610
  reminder: dateTimeOrDisabledReminder
1081
1611
  });
1082
- var notionDateValueSchema = variant("type", [
1083
- notionDateSchema,
1084
- notionDateRangeSchema,
1085
- notionDateTimeSchema,
1086
- notionDateTimeRangeSchema
1612
+ var notionDateValueSchema = variant("type", [
1613
+ notionDateSchema,
1614
+ notionDateRangeSchema,
1615
+ notionDateTimeSchema,
1616
+ notionDateTimeRangeSchema
1617
+ ]);
1618
+
1619
+ // ../protocol/src/utils/recordPointer.ts
1620
+ var notionRecordPointerSchema = object({
1621
+ id: string(),
1622
+ table: string()
1623
+ });
1624
+
1625
+ // ../protocol/src/compatibility/protocol3To5/dataSourceValue.ts
1626
+ var notionDataSourceValueSchema = union([
1627
+ string(),
1628
+ number(),
1629
+ boolean(),
1630
+ notionDateValueSchema,
1631
+ array(string()),
1632
+ array(notionRecordPointerSchema)
1633
+ ]);
1634
+
1635
+ // ../protocol/src/compatibility/protocol3To5/dataSourcePage.ts
1636
+ var notionDataSourcePageForProtocol3To5Schema = object({
1637
+ id: notionPageIdSchema,
1638
+ /** Whether the page or an ancestor is archived. */
1639
+ is_archived: boolean(),
1640
+ /** Whether the page or an ancestor is in Trash. */
1641
+ in_trash: boolean(),
1642
+ propertiesById: record(string(), optional(notionDataSourceValueSchema))
1643
+ });
1644
+
1645
+ // ../protocol/src/files.ts
1646
+ var bridgeExternalFileSchema = object({
1647
+ type: literal("external"),
1648
+ external: object({ url: string() })
1649
+ });
1650
+ var bridgeNotionHostedFileSchema = object({
1651
+ type: literal("file"),
1652
+ file: object({
1653
+ url: string(),
1654
+ expiry_time: optional(string())
1655
+ })
1656
+ });
1657
+ var bridgeFilePropertyItemSchema = union([
1658
+ object({ ...bridgeExternalFileSchema.entries, name: string() }),
1659
+ object({ ...bridgeNotionHostedFileSchema.entries, name: string() })
1660
+ ]);
1661
+
1662
+ // ../protocol/src/icons.ts
1663
+ var bridgeIconNameSchema = string();
1664
+ var knownBridgeIconColorSchema = picklist([
1665
+ "gray",
1666
+ "lightgray",
1667
+ "brown",
1668
+ "yellow",
1669
+ "orange",
1670
+ "green",
1671
+ "blue",
1672
+ "purple",
1673
+ "pink",
1674
+ "red"
1675
+ ]);
1676
+ var bridgeIconColorSchema = union([
1677
+ knownBridgeIconColorSchema,
1678
+ string()
1679
+ ]);
1680
+ var bridgeIconSchema = looseObject({
1681
+ type: literal("icon"),
1682
+ icon: looseObject({
1683
+ name: bridgeIconNameSchema,
1684
+ color: optional(bridgeIconColorSchema)
1685
+ })
1686
+ });
1687
+ var bridgeEmojiSchema = object({
1688
+ type: literal("emoji"),
1689
+ emoji: string()
1690
+ });
1691
+ var bridgeCustomEmojiSchema = object({
1692
+ type: literal("custom_emoji"),
1693
+ custom_emoji: object({
1694
+ id: string(),
1695
+ name: optional(string()),
1696
+ url: optional(string())
1697
+ })
1698
+ });
1699
+
1700
+ // ../protocol/src/pages/pageAppearance.ts
1701
+ var bridgePageIconSchema = variant("type", [
1702
+ bridgeIconSchema,
1703
+ bridgeEmojiSchema,
1704
+ bridgeCustomEmojiSchema,
1705
+ bridgeExternalFileSchema,
1706
+ bridgeNotionHostedFileSchema
1707
+ ]);
1708
+ var bridgePageCoverSchema = variant("type", [
1709
+ bridgeExternalFileSchema,
1710
+ bridgeNotionHostedFileSchema
1087
1711
  ]);
1088
1712
 
1713
+ // ../protocol/src/utils/nullableStringSchema.ts
1714
+ var nullableStringSchema = nullable(string());
1715
+
1089
1716
  // ../protocol/src/pages/properties/dateInput.ts
1090
1717
  var dateInputEntries = {
1091
1718
  start: string(),
@@ -1112,12 +1739,6 @@ var notionDateInputSchema = union([
1112
1739
  })
1113
1740
  ]);
1114
1741
 
1115
- // ../protocol/src/utils/recordPointer.ts
1116
- var notionRecordPointerSchema = object({
1117
- id: string(),
1118
- table: string()
1119
- });
1120
-
1121
1742
  // ../protocol/src/pages/properties/metadataActor.ts
1122
1743
  var metadataActorSchema = nullable(
1123
1744
  object({
@@ -1287,300 +1908,62 @@ var bridgePagePropertyValueSchema = variant("type", [
1287
1908
  formula: string()
1288
1909
  }),
1289
1910
  object({
1290
- ...pagePropertyBaseSchema,
1291
- type: literal("location"),
1292
- location: string()
1293
- }),
1294
- object({
1295
- ...pagePropertyBaseSchema,
1296
- type: literal("rollup"),
1297
- rollup: string()
1298
- }),
1299
- object({
1300
- ...pagePropertyBaseSchema,
1301
- type: literal("verification"),
1302
- verification: string()
1303
- })
1304
- ]);
1305
-
1306
- // ../protocol/src/pages/properties/bridgePagePropertyMaps.ts
1307
- var bridgePagePropertyWriteMapSchema = record(
1308
- string(),
1309
- bridgePagePropertyValueSchema
1310
- );
1311
- var bridgePagePropertyReadMapSchema = record(
1312
- string(),
1313
- nullable(bridgePagePropertyValueSchema)
1314
- );
1315
-
1316
- // ../protocol/src/compatibility/protocol3To5/bridgePage.ts
1317
- var bridgePageForProtocol3To5Schema = object({
1318
- object: literal("page"),
1319
- id: notionPageIdSchema,
1320
- parent: notionParentSchema,
1321
- properties: bridgePagePropertyWriteMapSchema,
1322
- created_time: optional(string()),
1323
- last_edited_time: optional(string()),
1324
- icon: optional(bridgePageIconSchema),
1325
- cover: optional(bridgePageCoverSchema),
1326
- url: optional(string()),
1327
- public_url: optional(string()),
1328
- /** Whether the page or an ancestor is archived. */
1329
- is_archived: boolean(),
1330
- /** Whether the page or an ancestor is in Trash. */
1331
- in_trash: boolean()
1332
- });
1333
-
1334
- // ../protocol/src/compatibility/protocol3To5/dataSourceValue.ts
1335
- var notionDataSourceValueSchema = union([
1336
- string(),
1337
- number(),
1338
- boolean(),
1339
- notionDateValueSchema,
1340
- array(string()),
1341
- array(notionRecordPointerSchema)
1342
- ]);
1343
-
1344
- // ../protocol/src/compatibility/protocol3To5/dataSourcePage.ts
1345
- var notionDataSourcePageForProtocol3To5Schema = object({
1346
- id: notionPageIdSchema,
1347
- /** Whether the page or an ancestor is archived. */
1348
- is_archived: boolean(),
1349
- /** Whether the page or an ancestor is in Trash. */
1350
- in_trash: boolean(),
1351
- propertiesById: record(string(), optional(notionDataSourceValueSchema))
1352
- });
1353
-
1354
- // ../protocol/src/context/containingPage.ts
1355
- var customBlockPageSchema = variant("type", [
1356
- /** The viewer cannot access the containing page; its ID and parent are not exposed. */
1357
- object({ type: literal("unavailable") }),
1358
- /** The viewer can access the containing page; includes its ID and parent location. */
1359
- object({
1360
- type: literal("page"),
1361
- id: notionPageIdSchema,
1362
- /**
1363
- * The containing page's own parent. It lets a block distinguish a freestanding page from a
1364
- * database row without a round trip. Not to be confused with the top-level `parent` runtime
1365
- * value, which is the custom block's own parent.
1366
- */
1367
- parent: notionParentSchema
1368
- })
1369
- ]);
1370
-
1371
- // ../protocol/src/context/contrast.ts
1372
- var notionContrastModeSchema = picklist(["standard", "high"]);
1373
-
1374
- // ../protocol/src/context/messages/contrastModeChanged.ts
1375
- var contrastModeChangedMessageSchema = object({
1376
- type: literal("contrastModeChanged"),
1377
- contrastMode: notionContrastModeSchema
1378
- });
1379
-
1380
- // ../protocol/src/context/messages/pageChanged.ts
1381
- var pageChangedMessageSchema = object({
1382
- type: literal("pageChanged"),
1383
- page: customBlockPageSchema
1384
- });
1385
-
1386
- // ../protocol/src/context/messages/parentChanged.ts
1387
- var parentChangedMessageSchema = object({
1388
- type: literal("parentChanged"),
1389
- parent: notionParentSchema
1390
- });
1391
-
1392
- // ../protocol/src/context/messages/resize.ts
1393
- var resizeMessageSchema = object({
1394
- type: literal("resize"),
1395
- height: pipe(number(), finite(), minValue(0))
1396
- });
1397
-
1398
- // ../protocol/src/context/theme.ts
1399
- var notionThemeSchema = picklist(["light", "dark"]);
1400
-
1401
- // ../protocol/src/context/messages/themeChanged.ts
1402
- var themeChangedMessageSchema = object({
1403
- type: literal("themeChanged"),
1404
- theme: notionThemeSchema
1405
- });
1406
-
1407
- // ../protocol/src/dataSources/bridgeArchiveStatus.ts
1408
- var bridgeArchiveStatusSchema = picklist([
1409
- "active",
1410
- "archived",
1411
- "all"
1412
- ]);
1413
-
1414
- // ../protocol/src/dataSources/collectionPointer.ts
1415
- var collectionPointerValidator = object({
1416
- id: notionDataSourceIdSchema,
1417
- table: string(),
1418
- spaceId: optional(notionSpaceIdSchema)
1419
- });
1420
-
1421
- // ../protocol/src/dataSources/properties/propertySchema.ts
1422
- var notionPropertyColorSchema = picklist([
1423
- "default",
1424
- "gray",
1425
- "brown",
1426
- "orange",
1427
- "yellow",
1428
- "green",
1429
- "blue",
1430
- "purple",
1431
- "pink",
1432
- "red",
1433
- "gray_background",
1434
- "brown_background",
1435
- "orange_background",
1436
- "yellow_background",
1437
- "green_background",
1438
- "blue_background",
1439
- "purple_background",
1440
- "pink_background",
1441
- "red_background",
1442
- "default_background"
1443
- ]);
1444
- var notionPropertyOptionSchema = object({
1445
- id: string(),
1446
- name: string(),
1447
- color: optional(notionPropertyColorSchema),
1448
- description: optional(string())
1449
- });
1450
- var notionStatusGroupSchema = object({
1451
- id: string(),
1452
- name: string(),
1453
- color: optional(notionPropertyColorSchema),
1454
- option_ids: array(string())
1455
- });
1456
- var notionDualPropertySchema = object({
1457
- synced_property_id: string(),
1458
- synced_property_name: string()
1459
- });
1460
- var baseProp = object({
1461
- name: string(),
1462
- description: optional(string())
1463
- });
1464
- var NOTION_PROPERTY_TYPES = [
1465
- "title",
1466
- "rich_text",
1467
- "number",
1468
- "checkbox",
1469
- "url",
1470
- "email",
1471
- "phone_number",
1472
- "select",
1473
- "multi_select",
1474
- "status",
1475
- "date",
1476
- "people",
1477
- "files",
1478
- "unique_id",
1479
- "relation",
1480
- "place",
1481
- "formula",
1482
- "rollup",
1483
- "button",
1484
- "verification",
1485
- "location",
1486
- "created_time",
1487
- "last_edited_time",
1488
- "created_by",
1489
- "last_edited_by"
1490
- ];
1491
- var notionPropertyTypeSchema = picklist(NOTION_PROPERTY_TYPES);
1492
- var notionPropertySchemaSchema = variant("type", [
1493
- object({ ...baseProp.entries, type: literal("title") }),
1494
- object({ ...baseProp.entries, type: literal("rich_text") }),
1495
- object({ ...baseProp.entries, type: literal("number") }),
1496
- object({ ...baseProp.entries, type: literal("checkbox") }),
1497
- object({ ...baseProp.entries, type: literal("url") }),
1498
- object({ ...baseProp.entries, type: literal("email") }),
1499
- object({ ...baseProp.entries, type: literal("phone_number") }),
1500
- object({
1501
- ...baseProp.entries,
1502
- type: literal("select"),
1503
- options: array(notionPropertyOptionSchema)
1504
- }),
1505
- object({
1506
- ...baseProp.entries,
1507
- type: literal("multi_select"),
1508
- options: array(notionPropertyOptionSchema)
1509
- }),
1510
- object({
1511
- ...baseProp.entries,
1512
- type: literal("status"),
1513
- options: array(notionPropertyOptionSchema),
1514
- groups: array(notionStatusGroupSchema)
1515
- }),
1516
- object({ ...baseProp.entries, type: literal("date") }),
1517
- object({ ...baseProp.entries, type: literal("people") }),
1518
- object({ ...baseProp.entries, type: literal("files") }),
1519
- object({ ...baseProp.entries, type: literal("unique_id") }),
1520
- object({
1521
- ...baseProp.entries,
1522
- type: literal("relation"),
1523
- data_source_id: optional(string()),
1524
- dual_property: optional(notionDualPropertySchema)
1911
+ ...pagePropertyBaseSchema,
1912
+ type: literal("rollup"),
1913
+ rollup: string()
1525
1914
  }),
1526
- object({ ...baseProp.entries, type: literal("place") }),
1527
- object({ ...baseProp.entries, type: literal("formula") }),
1528
- object({ ...baseProp.entries, type: literal("rollup") }),
1529
- // Internal-only types passed through under their bridge-native names.
1530
- object({ ...baseProp.entries, type: literal("button") }),
1531
- object({ ...baseProp.entries, type: literal("verification") }),
1532
- object({ ...baseProp.entries, type: literal("location") }),
1533
- // Synthetic built-ins. The host always emits one of each per data source.
1534
- object({ ...baseProp.entries, type: literal("created_time") }),
1535
- object({ ...baseProp.entries, type: literal("last_edited_time") }),
1536
- object({ ...baseProp.entries, type: literal("created_by") }),
1537
- object({ ...baseProp.entries, type: literal("last_edited_by") })
1915
+ object({
1916
+ ...pagePropertyBaseSchema,
1917
+ type: literal("verification"),
1918
+ verification: string()
1919
+ })
1538
1920
  ]);
1539
1921
 
1540
- // ../protocol/src/dataSources/collectionSchema.ts
1541
- var notionCollectionSchemaValidator = object({
1542
- id: optional(notionDataSourceIdSchema),
1543
- /**
1544
- * Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
1545
- * synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
1546
- * to validate filter and sort references.
1547
- */
1548
- propertiesById: record(string(), notionPropertySchemaSchema)
1549
- });
1922
+ // ../protocol/src/pages/properties/bridgePagePropertyMaps.ts
1923
+ var bridgePagePropertyWriteMapSchema = record(
1924
+ string(),
1925
+ bridgePagePropertyValueSchema
1926
+ );
1927
+ var bridgePagePropertyReadMapSchema = record(
1928
+ string(),
1929
+ nullable(bridgePagePropertyValueSchema)
1930
+ );
1550
1931
 
1551
- // ../protocol/src/dataSources/bridgeDataSourceBinding.ts
1552
- var bridgeDataSourceBindingSchema = object({
1553
- collectionPointer: optional(collectionPointerValidator),
1554
- /**
1555
- * Describes database properties. Use this schema to resolve property bindings. Use this
1556
- * schema to validate filter and sort references. Undefined when the host does not provide a
1557
- * database schema.
1558
- */
1559
- collectionSchema: optional(notionCollectionSchemaValidator),
1560
- /**
1561
- * Maps user-defined property keys to database property IDs. Use this map to resolve a key
1562
- * such as `name` to its database property ID. A value of `undefined` marks a declared
1563
- * property without a binding. Omitted when the host does not provide property mappings.
1564
- * Synthetic metadata does not add entries to this map.
1565
- */
1566
- propertyIdsByKey: optional(record(string(), optional(string()))),
1567
- /**
1568
- * `true` when the data source is bound but the viewer can't read it. The host omits
1569
- * `collectionPointer`, `collectionSchema`, and `propertyIdsByKey`, so the binding reveals
1570
- * nothing about the data source. The block still initializes.
1571
- */
1572
- inaccessible: optional(literal(true))
1932
+ // ../protocol/src/pages/bridgePage.ts
1933
+ var bridgePageSchema = object({
1934
+ object: literal("page"),
1935
+ id: notionPageIdSchema,
1936
+ parent: notionParentSchema,
1937
+ properties: bridgePagePropertyReadMapSchema,
1938
+ created_by: optional(metadataActorSchema, null),
1939
+ last_edited_by: optional(metadataActorSchema, null),
1940
+ created_time: optional(nullable(string()), null),
1941
+ last_edited_time: optional(nullable(string()), null),
1942
+ icon: optional(nullable(bridgePageIconSchema), null),
1943
+ cover: optional(nullable(bridgePageCoverSchema), null),
1944
+ url: optional(nullable(string()), null),
1945
+ public_url: optional(nullable(string()), null),
1946
+ /** Whether the page or an ancestor is archived. */
1947
+ is_archived: boolean(),
1948
+ /** Whether the page or an ancestor is in Trash. */
1949
+ in_trash: boolean()
1573
1950
  });
1574
1951
 
1575
- // ../protocol/src/dataSources/bridgeDataSourceBindings.ts
1576
- var bridgeDataSourceBindingsSchema = record(
1577
- string(),
1578
- bridgeDataSourceBindingSchema
1579
- );
1952
+ // ../protocol/src/dataSources/bridgeArchiveStatus.ts
1953
+ var bridgeArchiveStatusSchema = picklist([
1954
+ "active",
1955
+ "archived",
1956
+ "all"
1957
+ ]);
1580
1958
 
1581
- // ../protocol/src/dataSources/errors.ts
1582
- var customBlockDataSourceResolutionErrorCodeSchema = string();
1583
- var customBlockPropertyErrorCodeSchema = string();
1959
+ // ../protocol/src/dataSources/bridgeDataSourceQueryLimitClamp.ts
1960
+ var bridgeDataSourceQueryLimitClampSchema = pipe(
1961
+ object({
1962
+ requested: pipe(number(), safeInteger(), minValue(1)),
1963
+ applied: pipe(number(), safeInteger(), minValue(1))
1964
+ }),
1965
+ check((value) => value.applied < value.requested)
1966
+ );
1584
1967
 
1585
1968
  // ../protocol/src/dataSources/filters/checkboxFilterOperator.ts
1586
1969
  var customBlockCheckboxFilterOperatorSchema = union([
@@ -1827,330 +2210,111 @@ var bridgeDataSourceFilterConditionSchema = union([
1827
2210
  propertyId: string(),
1828
2211
  select: customBlockOptionFilterOperatorSchema
1829
2212
  }),
1830
- strictObject({
1831
- propertyId: string(),
1832
- multi_select: customBlockContainsFilterOperatorSchema
1833
- }),
1834
- strictObject({
1835
- propertyId: string(),
1836
- status: customBlockStatusFilterOperatorSchema
1837
- }),
1838
- strictObject({
1839
- propertyId: string(),
1840
- date: customBlockDateFilterOperatorSchema
1841
- }),
1842
- strictObject({
1843
- propertyId: string(),
1844
- people: customBlockPeopleFilterOperatorSchema
1845
- })
1846
- ]);
1847
-
1848
- // ../protocol/src/dataSources/filters/bridgeDataSourceFilter.ts
1849
- var bridgeDataSourceFilterSchema = union([
1850
- bridgeDataSourceFilterConditionSchema,
1851
- strictObject({
1852
- and: array(bridgeDataSourceFilterConditionSchema)
1853
- })
1854
- ]);
1855
-
1856
- // ../protocol/src/dataSources/sortDirection.ts
1857
- var notionSortDirectionSchema = picklist(["ascending", "descending"]);
1858
-
1859
- // ../protocol/src/dataSources/filters/bridgeDataSourceSort.ts
1860
- var bridgeDataSourceSortSchema = strictObject({
1861
- propertyId: string(),
1862
- direction: notionSortDirectionSchema
1863
- });
1864
-
1865
- // ../protocol/src/dataSources/messages/dataSourcesChanged.ts
1866
- var dataSourcesChangedMessageSchema = object({
1867
- type: literal("dataSourcesChanged"),
1868
- dataSources: object({
1869
- bindings: bridgeDataSourceBindingsSchema
1870
- })
1871
- });
1872
-
1873
- // ../protocol/src/pages/bridgePage.ts
1874
- var bridgePageSchema = object({
1875
- object: literal("page"),
1876
- id: notionPageIdSchema,
1877
- parent: notionParentSchema,
1878
- properties: bridgePagePropertyReadMapSchema,
1879
- created_by: optional(metadataActorSchema, null),
1880
- last_edited_by: optional(metadataActorSchema, null),
1881
- created_time: optional(nullable(string()), null),
1882
- last_edited_time: optional(nullable(string()), null),
1883
- icon: optional(nullable(bridgePageIconSchema), null),
1884
- cover: optional(nullable(bridgePageCoverSchema), null),
1885
- url: optional(nullable(string()), null),
1886
- public_url: optional(nullable(string()), null),
1887
- /** Whether the page or an ancestor is archived. */
1888
- is_archived: boolean(),
1889
- /** Whether the page or an ancestor is in Trash. */
1890
- in_trash: boolean()
1891
- });
1892
-
1893
- // ../protocol/src/dataSources/messages/queryDataSource.ts
1894
- var queryDataSourceMessageSchema = object({
1895
- type: literal("queryDataSource"),
1896
- /** Stable for the lifetime of this query subscription. */
1897
- subscriptionId: string(),
1898
- /** The raw Notion data source ID to read from. */
1899
- dataSourceId: notionDataSourceIdSchema,
1900
- /** The number of items to return in each subscription update. */
1901
- limit: number(),
1902
- /** A sandbox-resolved property filter. */
1903
- filter: optional(bridgeDataSourceFilterSchema),
1904
- /** Sandbox-resolved property sorts, in priority order. */
1905
- sorts: optional(array(bridgeDataSourceSortSchema)),
1906
- archive_status: optional(bridgeArchiveStatusSchema)
1907
- });
1908
- var customBlockQueryDataSourceErrorCodeSchema = string();
1909
- var customBlockQueryDataSourceErrorInfoSchema = object({
1910
- code: customBlockQueryDataSourceErrorCodeSchema,
1911
- message: string(),
1912
- isRetryable: boolean()
1913
- });
1914
- var queryDataSourceResultMessageSchema = variant("status", [
1915
- object({
1916
- type: literal("queryDataSourceResult"),
1917
- subscriptionId: string(),
1918
- status: literal("success"),
1919
- items: array(bridgePageSchema),
1920
- hasMore: boolean()
1921
- }),
1922
- object({
1923
- type: literal("queryDataSourceResult"),
1924
- subscriptionId: string(),
1925
- status: literal("error"),
1926
- error: customBlockQueryDataSourceErrorInfoSchema
1927
- })
1928
- ]);
1929
- var queryDataSourceResultMessageWithProtocol3To5CompatibilitySchema = variant("status", [
1930
- object({
1931
- type: literal("queryDataSourceResult"),
1932
- subscriptionId: string(),
1933
- status: literal("success"),
1934
- items: array(
1935
- union([bridgePageSchema, notionDataSourcePageForProtocol3To5Schema])
1936
- ),
1937
- hasMore: boolean()
1938
- }),
1939
- object({
1940
- type: literal("queryDataSourceResult"),
1941
- subscriptionId: string(),
1942
- status: literal("error"),
1943
- error: customBlockQueryDataSourceErrorInfoSchema
1944
- })
1945
- ]);
1946
-
1947
- // ../protocol/src/dataSources/messages/unsubscribeDataSourceQuery.ts
1948
- var unsubscribeDataSourceQueryMessageSchema = object({
1949
- type: literal("unsubscribeDataSourceQuery"),
1950
- /** The subscription to remove from the host. */
1951
- subscriptionId: string()
1952
- });
1953
-
1954
- // ../protocol/src/dataSources/notionDataSource.ts
1955
- var notionDataSourceSchema = object({
1956
- key: string(),
1957
- collectionPointer: optional(collectionPointerValidator),
1958
- /**
1959
- * Describes database properties. Use this schema to resolve property bindings. Use this
1960
- * schema to validate filter and sort references. Undefined when the host does not provide a
1961
- * database schema.
1962
- */
1963
- collectionSchema: optional(notionCollectionSchemaValidator),
1964
- /**
1965
- * Maps user-defined property keys to database property IDs. Use this map to resolve a key
1966
- * such as `name` to its database property ID. A value of `undefined` marks a declared
1967
- * property without a valid binding. Synthetic metadata does not add entries to this map.
1968
- */
1969
- propertyIdsByKey: record(string(), optional(string())),
1970
- /**
1971
- * Describes property values in query snapshots. Keys use the same property IDs as a snapshot's
1972
- * `propertiesById` map.
1973
- *
1974
- * Includes four synthetic metadata fields, even when the database schema is unavailable:
1975
- * `created_time`, `last_edited_time`, `created_by`, and `last_edited_by`. Also includes
1976
- * database properties when the host provides their schema.
1977
- *
1978
- * Use `propertiesById` to read a value. Use this map to read the value's schema. Use
1979
- * `collectionSchema` to validate filter and sort references.
1980
- */
1981
- propertySchemasById: record(string(), notionPropertySchemaSchema),
1982
- /**
1983
- * `true` when the data source is bound but the viewer can't read it. The block still
1984
- * initializes. Queries and writes that use this data source fail with
1985
- * `data_source_inaccessible`.
1986
- */
1987
- inaccessible: optional(literal(true))
1988
- });
1989
-
1990
- // ../protocol/src/manifest/grants.ts
1991
- var customBlockGrantSchema = object({
1992
- action: string(),
1993
- resource: union([string(), pipe(array(string()), minLength(1))])
1994
- });
1995
-
1996
- // ../protocol/src/manifest/manifest.ts
1997
- var bridgeManifestIconSchema = variant("type", [
1998
- object({
1999
- type: literal("emoji"),
2000
- emoji: string()
2001
- }),
2002
- object({
2003
- type: literal("external"),
2004
- url: string()
2213
+ strictObject({
2214
+ propertyId: string(),
2215
+ multi_select: customBlockContainsFilterOperatorSchema
2216
+ }),
2217
+ strictObject({
2218
+ propertyId: string(),
2219
+ status: customBlockStatusFilterOperatorSchema
2220
+ }),
2221
+ strictObject({
2222
+ propertyId: string(),
2223
+ date: customBlockDateFilterOperatorSchema
2224
+ }),
2225
+ strictObject({
2226
+ propertyId: string(),
2227
+ people: customBlockPeopleFilterOperatorSchema
2005
2228
  })
2006
2229
  ]);
2007
- var bridgeManifestPropertySchema = object({
2008
- name: string(),
2009
- description: optional(string()),
2010
- type: notionPropertyTypeSchema
2011
- });
2012
- var manifestPageSchema = object({
2013
- name: string(),
2014
- description: optional(string()),
2015
- icon: optional(bridgeManifestIconSchema)
2016
- });
2017
- var bridgeManifestDataSourceSchema = object({
2018
- name: string(),
2019
- description: optional(string()),
2020
- icon: optional(bridgeManifestIconSchema),
2021
- properties: optional(
2022
- record(string(), bridgeManifestPropertySchema),
2023
- {}
2024
- )
2025
- });
2026
- var manifestSchema = object({
2027
- version: literal(1),
2028
- name: optional(string()),
2029
- description: optional(string()),
2030
- slashCommand: optional(string()),
2031
- icon: optional(object({ type: literal("emoji"), emoji: string() })),
2032
- dataSources: optional(
2033
- record(string(), bridgeManifestDataSourceSchema),
2034
- {}
2035
- ),
2036
- pages: optional(record(string(), manifestPageSchema)),
2037
- /**
2038
- * Grants the block needs. Omitted means the block predates viewer
2039
- * approval, so hosts do not ask the viewer. An empty array declares
2040
- * nothing.
2041
- */
2042
- grants: optional(array(customBlockGrantSchema))
2230
+
2231
+ // ../protocol/src/dataSources/filters/bridgeDataSourceFilter.ts
2232
+ var bridgeDataSourceFilterSchema = union([
2233
+ bridgeDataSourceFilterConditionSchema,
2234
+ strictObject({
2235
+ and: array(bridgeDataSourceFilterConditionSchema)
2236
+ })
2237
+ ]);
2238
+
2239
+ // ../protocol/src/dataSources/sortDirection.ts
2240
+ var notionSortDirectionSchema = picklist(["ascending", "descending"]);
2241
+
2242
+ // ../protocol/src/dataSources/filters/bridgeDataSourceSort.ts
2243
+ var bridgeDataSourceSortSchema = strictObject({
2244
+ propertyId: string(),
2245
+ direction: notionSortDirectionSchema
2043
2246
  });
2044
2247
 
2045
- // ../protocol/src/utils/errors.ts
2046
- var customBlockErrorInfoSchema = object({
2047
- code: string(),
2248
+ // ../protocol/src/dataSources/messages/queryDataSource.ts
2249
+ var queryDataSourceMessageSchema = object({
2250
+ type: literal("queryDataSource"),
2251
+ /** Stable for the lifetime of this query subscription. */
2252
+ subscriptionId: string(),
2253
+ /** The raw Notion data source ID to read from. */
2254
+ dataSourceId: notionDataSourceIdSchema,
2255
+ /** The number of items to return in each subscription update. */
2256
+ limit: number(),
2257
+ /** A sandbox-resolved property filter. */
2258
+ filter: optional(bridgeDataSourceFilterSchema),
2259
+ /** Sandbox-resolved property sorts, in priority order. */
2260
+ sorts: optional(array(bridgeDataSourceSortSchema)),
2261
+ archive_status: optional(bridgeArchiveStatusSchema)
2262
+ });
2263
+ var customBlockQueryDataSourceErrorCodeSchema = string();
2264
+ var customBlockQueryDataSourceErrorInfoSchema = object({
2265
+ code: customBlockQueryDataSourceErrorCodeSchema,
2048
2266
  message: string(),
2049
2267
  isRetryable: boolean()
2050
2268
  });
2051
-
2052
- // ../protocol/src/handshake/connect.ts
2053
- var connectMessageCommonEntries = {
2054
- type: literal("connect"),
2055
- initializationId: string(),
2056
- /**
2057
- * The bridge protocol version this sandbox uses to communicate with its host.
2058
- * Hosts control which versions they support and can support multiple versions
2059
- * at the same time. Support for older versions is eventually removed, so blocks
2060
- * may need to update their SDK to continue working.
2061
- */
2062
- bridgeProtocolVersion: number(),
2063
- /**
2064
- * Semver version of the SDK package that sent this connect message. Should only be used for
2065
- * analytics purposes. Business logic should compare against `bridgeProtocolVersion` instead.
2066
- */
2067
- sdkVersion: string()
2068
- };
2069
- var connectMessageSchema = variant("status", [
2269
+ var queryDataSourceResultMessageSchema = variant("status", [
2070
2270
  object({
2271
+ type: literal("queryDataSourceResult"),
2272
+ subscriptionId: string(),
2071
2273
  status: literal("success"),
2072
- /**
2073
- * The custom block manifest injected by local dev tooling. The SDK omits it on
2074
- * non-loopback origins. Initialization uses it only when manifestSource is "sandbox".
2075
- */
2076
- manifest: optional(manifestSchema),
2077
- ...connectMessageCommonEntries
2274
+ items: array(bridgePageSchema),
2275
+ hasMore: boolean(),
2276
+ limitClamp: optional(bridgeDataSourceQueryLimitClampSchema)
2078
2277
  }),
2079
2278
  object({
2279
+ type: literal("queryDataSourceResult"),
2280
+ subscriptionId: string(),
2080
2281
  status: literal("error"),
2081
- error: customBlockErrorInfoSchema,
2082
- ...connectMessageCommonEntries
2282
+ error: customBlockQueryDataSourceErrorInfoSchema
2083
2283
  })
2084
2284
  ]);
2085
-
2086
- // ../protocol/src/users/userId.ts
2087
- var notionUserIdSchema = pipe(string(), brand("NotionUserId"));
2088
-
2089
- // ../protocol/src/users/bridgeUser.ts
2090
- var bridgeUserSchema = object({
2091
- object: literal("user"),
2092
- id: notionUserIdSchema,
2093
- name: optional(string()),
2094
- avatar_url: nullable(string()),
2095
- type: literal("person"),
2096
- person: object({
2097
- email: string()
2098
- })
2099
- });
2100
-
2101
- // ../protocol/src/handshake/init.ts
2102
- var customBlockInitErrorCodeSchema = string();
2103
- var customBlockInitErrorInfoSchema = object({
2104
- code: customBlockInitErrorCodeSchema,
2105
- message: string(),
2106
- isRetryable: boolean()
2107
- });
2108
- var initMessageSchema = variant("status", [
2285
+ var queryDataSourceResultMessageWithProtocol3To5CompatibilitySchema = variant("status", [
2109
2286
  object({
2110
- type: literal("init"),
2111
- initializationId: string(),
2287
+ type: literal("queryDataSourceResult"),
2288
+ subscriptionId: string(),
2112
2289
  status: literal("success"),
2113
- theme: notionThemeSchema,
2114
- contrastMode: notionContrastModeSchema,
2115
- blockId: notionBlockIdSchema,
2116
- parent: notionParentSchema,
2117
- page: customBlockPageSchema,
2118
- manifest: manifestSchema,
2119
- dataSources: object({
2120
- bindings: bridgeDataSourceBindingsSchema
2121
- }),
2122
- currentUser: bridgeUserSchema
2290
+ items: array(
2291
+ union([bridgePageSchema, notionDataSourcePageForProtocol3To5Schema])
2292
+ ),
2293
+ hasMore: boolean(),
2294
+ limitClamp: optional(bridgeDataSourceQueryLimitClampSchema)
2123
2295
  }),
2124
2296
  object({
2125
- type: literal("init"),
2126
- initializationId: string(),
2297
+ type: literal("queryDataSourceResult"),
2298
+ subscriptionId: string(),
2127
2299
  status: literal("error"),
2128
- error: customBlockInitErrorInfoSchema
2300
+ error: customBlockQueryDataSourceErrorInfoSchema
2129
2301
  })
2130
2302
  ]);
2131
2303
 
2132
- // ../protocol/src/handshake/initResult.ts
2133
- var customBlockInitResultErrorCodeSchema = string();
2134
- var customBlockInitResultErrorInfoSchema = object({
2135
- code: customBlockInitResultErrorCodeSchema,
2136
- message: string(),
2137
- isRetryable: boolean()
2138
- });
2139
- var initResultMessageSchema = variant("status", [
2304
+ // ../protocol/src/handshake/connectResult.ts
2305
+ var connectResultMessageSchema = variant("status", [
2140
2306
  object({
2141
- type: literal("initResult"),
2142
- initializationId: string(),
2307
+ type: literal("connectResult"),
2308
+ requestId: string(),
2143
2309
  status: literal("success"),
2144
- /** Height of the initial rendered custom-block content, in CSS pixels. */
2145
- // Older SDKs can omit the height. Current SDKs always send it.
2146
- // TODO(custom-blocks): Make this required when MIN_HOST_SUPPORTED_BRIDGE_PROTOCOL_VERSION increases to 4.
2147
- initialHeight: optional(pipe(number(), finite(), minValue(0)))
2310
+ /** The version selected from `connect.supportedProtocolVersions`, used for the rest of this connection. */
2311
+ protocolVersion: pipe(number(), integer(), minValue(1))
2148
2312
  }),
2149
2313
  object({
2150
- type: literal("initResult"),
2151
- initializationId: string(),
2314
+ type: literal("connectResult"),
2315
+ requestId: string(),
2152
2316
  status: literal("error"),
2153
- error: customBlockInitResultErrorInfoSchema
2317
+ error: customBlockErrorInfoSchema
2154
2318
  })
2155
2319
  ]);
2156
2320
 
@@ -2180,6 +2344,24 @@ var openExternalUrlResultMessageSchema = variant("status", [
2180
2344
  })
2181
2345
  ]);
2182
2346
 
2347
+ // ../protocol/src/compatibility/protocol3To5/bridgePage.ts
2348
+ var bridgePageForProtocol3To5Schema = object({
2349
+ object: literal("page"),
2350
+ id: notionPageIdSchema,
2351
+ parent: notionParentSchema,
2352
+ properties: bridgePagePropertyWriteMapSchema,
2353
+ created_time: optional(string()),
2354
+ last_edited_time: optional(string()),
2355
+ icon: optional(bridgePageIconSchema),
2356
+ cover: optional(bridgePageCoverSchema),
2357
+ url: optional(string()),
2358
+ public_url: optional(string()),
2359
+ /** Whether the page or an ancestor is archived. */
2360
+ is_archived: boolean(),
2361
+ /** Whether the page or an ancestor is in Trash. */
2362
+ in_trash: boolean()
2363
+ });
2364
+
2183
2365
  // ../protocol/src/pages/messages/createPage.ts
2184
2366
  var customBlockCreatePageErrorCodeSchema = string();
2185
2367
  var customBlockCreatePageErrorInfoSchema = object({
@@ -2383,7 +2565,7 @@ var updatePageMessageSchema = object({
2383
2565
  * Property values, keyed by raw property IDs from Notion.
2384
2566
  *
2385
2567
  * Each value must carry the same raw property ID in its `id` field.
2386
- * To update a page with manifest-defined property keys, call `row.update()` on a row returned
2568
+ * To update a page with manifest-defined property keys, call `row.updateByKey()` on a row returned
2387
2569
  * by `useDataSource()`. The SDK resolves those keys before it sends this message.
2388
2570
  */
2389
2571
  properties: optional(bridgePagePropertyWriteMapSchema),
@@ -2392,12 +2574,45 @@ var updatePageMessageSchema = object({
2392
2574
  archived: optional(boolean())
2393
2575
  });
2394
2576
 
2577
+ // ../protocol/src/users/bridgeUser.ts
2578
+ var bridgeUserSchema = object({
2579
+ object: literal("user"),
2580
+ id: notionUserIdSchema,
2581
+ /** The user's name, or `null` when unavailable. Empty strings are preserved. */
2582
+ name: nullable(string()),
2583
+ avatar_url: nullable(string()),
2584
+ type: literal("person"),
2585
+ person: object({
2586
+ email: string()
2587
+ })
2588
+ });
2589
+
2395
2590
  // ../protocol/src/users/messages/currentUserChanged.ts
2396
2591
  var currentUserChangedMessageSchema = object({
2397
2592
  type: literal("currentUserChanged"),
2398
2593
  currentUser: bridgeUserSchema
2399
2594
  });
2400
2595
 
2596
+ // ../protocol/src/users/messages/getCurrentUser.ts
2597
+ var getCurrentUserMessageSchema = object({
2598
+ type: literal("getCurrentUser"),
2599
+ requestId: string()
2600
+ });
2601
+ var getCurrentUserResultMessageSchema = variant("status", [
2602
+ object({
2603
+ type: literal("getCurrentUserResult"),
2604
+ requestId: string(),
2605
+ status: literal("success"),
2606
+ user: bridgeUserSchema
2607
+ }),
2608
+ object({
2609
+ type: literal("getCurrentUserResult"),
2610
+ requestId: string(),
2611
+ status: literal("error"),
2612
+ error: customBlockErrorInfoSchema
2613
+ })
2614
+ ]);
2615
+
2401
2616
  // ../protocol/src/users/messages/getUser.ts
2402
2617
  var customBlockGetUserErrorCodeSchema = string();
2403
2618
  var customBlockGetUserErrorInfoSchema = object({
@@ -2461,11 +2676,115 @@ var listUsersResultMessageSchema = variant("status", [
2461
2676
  status: literal("error"),
2462
2677
  error: customBlockListUsersErrorInfoSchema
2463
2678
  })
2464
- ]);
2679
+ ]);
2680
+
2681
+ // ../protocol/src/messages/invalidSandboxMessage.ts
2682
+ var invalidSandboxMessageSchema = object({
2683
+ type: literal("invalidSandboxMessage"),
2684
+ /** Identifies the rejected request or response, when readable. */
2685
+ requestId: optional(string()),
2686
+ /**
2687
+ * A human-readable string intended for sandbox-side logging. It has no structured contract.
2688
+ */
2689
+ reason: string()
2690
+ });
2691
+
2692
+ // ../protocol/src/messages/hostToSandbox.ts
2693
+ var hostToSandboxMessageSchema = variant("type", [
2694
+ connectResultMessageSchema,
2695
+ setupInitMessageSchema,
2696
+ getDataSourceResultMessageSchema,
2697
+ getCurrentUserResultMessageSchema,
2698
+ dataSourcesInvalidatedMessageSchema,
2699
+ themeChangedMessageSchema,
2700
+ contrastModeChangedMessageSchema,
2701
+ parentChangedMessageSchema,
2702
+ pageChangedMessageSchema,
2703
+ pageErrorMessageSchema,
2704
+ parentErrorMessageSchema,
2705
+ currentUserChangedMessageSchema,
2706
+ dataSourcesChangedMessageSchema,
2707
+ getUserResultMessageSchema,
2708
+ listUsersResultMessageSchema,
2709
+ openPageResultMessageSchema,
2710
+ openExternalUrlResultMessageSchema,
2711
+ invalidSandboxMessageSchema,
2712
+ queryDataSourceResultMessageSchema,
2713
+ getPageResultMessageSchema,
2714
+ createPageResultMessageSchema,
2715
+ updatePageResultMessageSchema
2716
+ ]);
2717
+
2718
+ // ../protocol/src/compatibility/protocol3To11/hostToSandbox.ts
2719
+ var protocol3To11HostToSandboxMessageSchema = variant("type", [
2720
+ protocol3To11InitMessageSchema,
2721
+ themeChangedMessageSchema,
2722
+ contrastModeChangedMessageSchema,
2723
+ parentChangedMessageSchema,
2724
+ protocol3To11PageChangedMessageSchema,
2725
+ currentUserChangedForProtocol3To11Schema,
2726
+ dataSourcesChangedMessageSchema,
2727
+ getUserResultForProtocol3To11Schema,
2728
+ listUsersResultForProtocol3To11Schema,
2729
+ openPageResultMessageSchema,
2730
+ openExternalUrlResultMessageSchema,
2731
+ invalidSandboxMessageSchema,
2732
+ queryDataSourceResultMessageWithProtocol3To5CompatibilitySchema,
2733
+ getPageResultMessageWithProtocol3To5CompatibilitySchema,
2734
+ createPageResultMessageWithProtocol3To5CompatibilitySchema,
2735
+ updatePageResultMessageWithProtocol3To5CompatibilitySchema
2736
+ ]);
2737
+
2738
+ // ../protocol/src/compatibility/hostToSandbox.ts
2739
+ var hostToSandboxMessageWithCompatibilitySchema = union([
2740
+ hostToSandboxMessageSchema,
2741
+ protocol3To11HostToSandboxMessageSchema
2742
+ ]);
2743
+
2744
+ // ../protocol/src/compatibility/protocol3To10/dataSourceBindings.ts
2745
+ var bridgeDataSourceBindingsForProtocol3To10Schema = record(
2746
+ string(),
2747
+ object({
2748
+ collectionPointer: optional(dataSourcePointerValidator),
2749
+ collectionSchema: optional(notionDataSourceSchemaValidator),
2750
+ propertyIdsByKey: optional(record(string(), optional(string()))),
2751
+ inaccessible: optional(literal(true))
2752
+ })
2753
+ );
2754
+ var dataSourceBindingsMessageForProtocol3To10Schema = variant(
2755
+ "type",
2756
+ [
2757
+ object({
2758
+ ...protocol3To11InitSuccessMessageSchema.entries,
2759
+ dataSources: object({
2760
+ bindings: bridgeDataSourceBindingsForProtocol3To10Schema
2761
+ })
2762
+ }),
2763
+ object({
2764
+ type: literal("dataSourcesChanged"),
2765
+ dataSources: object({
2766
+ bindings: bridgeDataSourceBindingsForProtocol3To10Schema
2767
+ })
2768
+ })
2769
+ ]
2770
+ );
2465
2771
 
2466
- // ../protocol/src/messages/invalidSandboxMessage.ts
2467
- var invalidSandboxMessageSchema = object({
2468
- type: literal("invalidSandboxMessage"),
2772
+ // ../protocol/src/context/messages/resize.ts
2773
+ var resizeMessageSchema = object({
2774
+ type: literal("resize"),
2775
+ height: pipe(number(), finite(), minValue(0))
2776
+ });
2777
+
2778
+ // ../protocol/src/dataSources/messages/unsubscribeDataSourceQuery.ts
2779
+ var unsubscribeDataSourceQueryMessageSchema = object({
2780
+ type: literal("unsubscribeDataSourceQuery"),
2781
+ /** The subscription to remove from the host. */
2782
+ subscriptionId: string()
2783
+ });
2784
+
2785
+ // ../protocol/src/messages/invalidHostMessage.ts
2786
+ var invalidHostMessageSchema = object({
2787
+ type: literal("invalidHostMessage"),
2469
2788
  /** Identifies the rejected request or response, when readable. */
2470
2789
  requestId: optional(string()),
2471
2790
  /**
@@ -2474,51 +2793,57 @@ var invalidSandboxMessageSchema = object({
2474
2793
  reason: string()
2475
2794
  });
2476
2795
 
2477
- // ../protocol/src/messages/hostToSandbox.ts
2478
- var baseHostToSandboxMessageSchema = variant("type", [
2479
- initMessageSchema,
2796
+ // ../protocol/src/compatibility/protocol3To11/sandboxToHost.ts
2797
+ var protocol3To11SandboxToHostMessageSchema = variant("type", [
2798
+ protocol3To11ConnectMessageSchema,
2799
+ protocol3To11InitResultMessageSchema,
2800
+ queryDataSourceMessageSchema,
2801
+ unsubscribeDataSourceQueryMessageSchema,
2802
+ createPageMessageSchema,
2803
+ getPageMessageSchema,
2804
+ getUserMessageSchema,
2805
+ listUsersMessageSchema,
2806
+ openPageMessageSchema,
2807
+ openExternalUrlMessageSchema,
2808
+ updatePageMessageSchema,
2809
+ resizeMessageSchema,
2810
+ invalidHostMessageSchema
2811
+ ]);
2812
+
2813
+ // ../protocol/src/compatibility/protocol11/hostToSandbox.ts
2814
+ var protocol11HostToSandboxMessageSchema = variant("type", [
2815
+ protocol3To11InitMessageSchema,
2480
2816
  themeChangedMessageSchema,
2481
2817
  contrastModeChangedMessageSchema,
2482
2818
  parentChangedMessageSchema,
2483
- pageChangedMessageSchema,
2484
- currentUserChangedMessageSchema,
2819
+ protocol3To11PageChangedMessageSchema,
2820
+ currentUserChangedForProtocol3To11Schema,
2485
2821
  dataSourcesChangedMessageSchema,
2486
- getUserResultMessageSchema,
2487
- listUsersResultMessageSchema,
2822
+ getUserResultForProtocol3To11Schema,
2823
+ listUsersResultForProtocol3To11Schema,
2488
2824
  openPageResultMessageSchema,
2489
2825
  openExternalUrlResultMessageSchema,
2490
- invalidSandboxMessageSchema
2491
- ]);
2492
- var hostToSandboxMessageSchema = variant("type", [
2493
- ...baseHostToSandboxMessageSchema.options,
2826
+ invalidSandboxMessageSchema,
2494
2827
  queryDataSourceResultMessageSchema,
2495
2828
  getPageResultMessageSchema,
2496
2829
  createPageResultMessageSchema,
2497
2830
  updatePageResultMessageSchema
2498
2831
  ]);
2499
- var hostToSandboxMessageWithProtocol3To5CompatibilitySchema = variant("type", [
2500
- ...baseHostToSandboxMessageSchema.options,
2501
- queryDataSourceResultMessageWithProtocol3To5CompatibilitySchema,
2502
- getPageResultMessageWithProtocol3To5CompatibilitySchema,
2503
- createPageResultMessageWithProtocol3To5CompatibilitySchema,
2504
- updatePageResultMessageWithProtocol3To5CompatibilitySchema
2505
- ]);
2506
2832
 
2507
- // ../protocol/src/messages/invalidHostMessage.ts
2508
- var invalidHostMessageSchema = object({
2509
- type: literal("invalidHostMessage"),
2510
- /** Identifies the rejected request or response, when readable. */
2511
- requestId: optional(string()),
2512
- /**
2513
- * A human-readable string intended for sandbox-side logging. It has no structured contract.
2514
- */
2515
- reason: string()
2833
+ // ../protocol/src/handshake/ready.ts
2834
+ var readyMessageSchema = object({
2835
+ type: literal("ready"),
2836
+ /** Initial rendered content height in CSS pixels, applied by the embedding application before reveal. */
2837
+ initialHeight: pipe(number(), finite(), minValue(0))
2516
2838
  });
2517
2839
 
2518
2840
  // ../protocol/src/messages/sandboxToHost.ts
2519
2841
  var sandboxToHostMessageSchema = variant("type", [
2520
- connectMessageSchema,
2521
- initResultMessageSchema,
2842
+ connectRequestMessageSchema,
2843
+ getDataSourceMessageSchema,
2844
+ getCurrentUserMessageSchema,
2845
+ initResultRequestMessageSchema,
2846
+ readyMessageSchema,
2522
2847
  queryDataSourceMessageSchema,
2523
2848
  unsubscribeDataSourceQueryMessageSchema,
2524
2849
  createPageMessageSchema,
@@ -2532,6 +2857,52 @@ var sandboxToHostMessageSchema = variant("type", [
2532
2857
  invalidHostMessageSchema
2533
2858
  ]);
2534
2859
 
2860
+ // ../protocol/src/compatibility/sandboxToHost.ts
2861
+ var sandboxToHostMessageWithCompatibilitySchema = union([
2862
+ sandboxToHostMessageSchema,
2863
+ protocol3To11SandboxToHostMessageSchema
2864
+ ]);
2865
+
2866
+ // ../protocol/src/dataSources/errors.ts
2867
+ var customBlockDataSourceResolutionErrorCodeSchema = string();
2868
+ var customBlockPropertyErrorCodeSchema = string();
2869
+
2870
+ // ../protocol/src/dataSources/notionDataSource.ts
2871
+ var notionDataSourceSchema = object({
2872
+ key: string(),
2873
+ dataSourcePointer: optional(dataSourcePointerValidator),
2874
+ /**
2875
+ * Describes database properties. Use this schema to resolve property bindings. Use this
2876
+ * schema to validate filter and sort references. Undefined when the host does not provide a
2877
+ * database schema.
2878
+ */
2879
+ dataSourceSchema: optional(notionDataSourceSchemaValidator),
2880
+ /**
2881
+ * Maps user-defined property keys to database property IDs. Use this map to resolve a key
2882
+ * such as `name` to its database property ID. A value of `undefined` marks a declared
2883
+ * property without a valid binding. Synthetic metadata does not add entries to this map.
2884
+ */
2885
+ propertyIdsByKey: record(string(), optional(string())),
2886
+ /**
2887
+ * Describes property values in query snapshots. Keys use the same property IDs as a snapshot's
2888
+ * `propertiesById` map.
2889
+ *
2890
+ * Includes four synthetic metadata fields, even when the database schema is unavailable:
2891
+ * `created_time`, `last_edited_time`, `created_by`, and `last_edited_by`. Also includes
2892
+ * database properties when the host provides their schema.
2893
+ *
2894
+ * Use `propertiesById` to read a value. Use this map to read the value's schema. Use
2895
+ * `dataSourceSchema` to validate filter and sort references.
2896
+ */
2897
+ propertySchemasById: record(string(), notionPropertySchemaSchema),
2898
+ /**
2899
+ * `true` when the data source is bound but the viewer can't read it. The block still
2900
+ * initializes. Queries and writes that use this data source fail with
2901
+ * `data_source_inaccessible`.
2902
+ */
2903
+ inaccessible: optional(literal(true))
2904
+ });
2905
+
2535
2906
  // ../protocol/src/utils/readRequestId.ts
2536
2907
  var requestIdentitySchema = object({ requestId: string() });
2537
2908
 
@@ -2598,6 +2969,50 @@ function slugify(name) {
2598
2969
  import { readFileSync } from "node:fs";
2599
2970
  import { basename, resolve } from "node:path";
2600
2971
 
2972
+ // shared/dataSources/sampleDataSource.ts
2973
+ var sampleDataSourceTypeSchema = picklist([
2974
+ "built-in",
2975
+ "worker",
2976
+ "manual",
2977
+ "syncedFromProd"
2978
+ ]);
2979
+ var sampleDataSourceRowSchema = looseObject({ id: string() });
2980
+ var sampleDataSourcePropertiesSchema = record(
2981
+ string(),
2982
+ notionPropertySchemaSchema
2983
+ );
2984
+ var loadedSampleDataSourceSchema = object({
2985
+ status: literal("loaded"),
2986
+ /** Filename without .json. This is the sample data source's identity. */
2987
+ filename: string(),
2988
+ type: sampleDataSourceTypeSchema,
2989
+ name: string(),
2990
+ icon: optional(string()),
2991
+ schema: sampleDataSourcePropertiesSchema,
2992
+ rows: array(sampleDataSourceRowSchema)
2993
+ });
2994
+ var sampleDataSourceLoadErrorSchema = object({
2995
+ status: literal("failed"),
2996
+ filename: string(),
2997
+ message: string()
2998
+ });
2999
+ var sampleDataSourceSchema = variant("status", [
3000
+ loadedSampleDataSourceSchema,
3001
+ sampleDataSourceLoadErrorSchema
3002
+ ]);
3003
+ function selectSampleDataSource({
3004
+ slotKey,
3005
+ sources,
3006
+ explicitFilename
3007
+ }) {
3008
+ if (explicitFilename !== void 0) {
3009
+ return sources.find(
3010
+ (source) => `${source.filename}.json` === explicitFilename
3011
+ );
3012
+ }
3013
+ return sources.find((source) => source.filename === `worker_${slotKey}`) ?? sources.find((source) => source.filename === slotKey);
3014
+ }
3015
+
2601
3016
  // ../node_modules/.pnpm/temporal-polyfill@1.0.6/node_modules/temporal-polyfill/chunks/root.js
2602
3017
  var NativeTemporal = globalThis.Temporal;
2603
3018
 
@@ -6335,48 +6750,104 @@ var Temporal = /* @__PURE__ */ Object.defineProperties({}, {
6335
6750
  var Temporal2 = NativeTemporal || Temporal;
6336
6751
  var toTemporalInstant2 = NativeTemporal ? Date.prototype.toTemporalInstant : toTemporalInstant;
6337
6752
 
6338
- // shared/dataSources/sampleDataSource.ts
6339
- var sampleDataSourceTypeSchema = picklist([
6340
- "built-in",
6341
- "worker",
6342
- "manual",
6343
- "syncedFromProd"
6344
- ]);
6345
- var sampleDataSourceRowSchema = looseObject({ id: string() });
6346
- var sampleDataSourcePropertiesSchema = record(
6347
- string(),
6348
- notionPropertySchemaSchema
6349
- );
6350
- var loadedSampleDataSourceSchema = object({
6351
- status: literal("loaded"),
6352
- /** Filename without .json. This is the sample data source's identity. */
6353
- filename: string(),
6354
- type: sampleDataSourceTypeSchema,
6355
- name: string(),
6356
- icon: optional(string()),
6357
- schema: sampleDataSourcePropertiesSchema,
6358
- rows: array(sampleDataSourceRowSchema)
6359
- });
6360
- var sampleDataSourceLoadErrorSchema = object({
6361
- status: literal("failed"),
6362
- filename: string(),
6363
- message: string()
6364
- });
6365
- var sampleDataSourceSchema = variant("status", [
6366
- loadedSampleDataSourceSchema,
6367
- sampleDataSourceLoadErrorSchema
6368
- ]);
6369
- function selectSampleDataSource({
6370
- slotKey,
6371
- sources,
6372
- explicitFilename
6753
+ // shared/utils/unreachable.ts
6754
+ function unreachable(value) {
6755
+ throw new Error(
6756
+ `[custom-blocks-dev-shell] Unexpected value encountered: ${JSON.stringify(value)}`
6757
+ );
6758
+ }
6759
+
6760
+ // shared/dataSources/toNotionDateInput.ts
6761
+ function toNotionDateInput(value) {
6762
+ if ("time_zone" in value && value.time_zone !== void 0) {
6763
+ validateTimeZone(value.time_zone);
6764
+ }
6765
+ switch (value.type) {
6766
+ case "date":
6767
+ return {
6768
+ start: normalizeDateBoundary({ value: value.start_date }),
6769
+ reminder: value.reminder
6770
+ };
6771
+ case "daterange":
6772
+ return {
6773
+ start: normalizeDateBoundary({ value: value.start_date }),
6774
+ end: normalizeDateBoundary({ value: value.end_date }),
6775
+ reminder: value.reminder
6776
+ };
6777
+ case "datetime":
6778
+ return {
6779
+ start: normalizeDateBoundary({
6780
+ value: `${value.start_date}T${value.start_time}`,
6781
+ timeZone: value.time_zone
6782
+ }),
6783
+ reminder: value.reminder
6784
+ };
6785
+ case "datetimerange":
6786
+ return {
6787
+ start: normalizeDateBoundary({
6788
+ value: `${value.start_date}T${value.start_time}`,
6789
+ timeZone: value.time_zone
6790
+ }),
6791
+ end: normalizeDateBoundary({
6792
+ value: `${value.end_date}T${value.end_time}`,
6793
+ timeZone: value.time_zone
6794
+ }),
6795
+ reminder: value.reminder
6796
+ };
6797
+ default:
6798
+ return unreachable(value);
6799
+ }
6800
+ }
6801
+ function normalizeDateBoundary({
6802
+ value,
6803
+ timeZone
6373
6804
  }) {
6374
- if (explicitFilename !== void 0) {
6375
- return sources.find(
6376
- (source) => `${source.filename}.json` === explicitFilename
6377
- );
6805
+ if (!value.includes("T")) {
6806
+ return Temporal2.PlainDate.from(value).toString();
6807
+ }
6808
+ if (/(?:Z|[+-]\d{2}:?\d{2})$/i.test(value)) {
6809
+ return Temporal2.Instant.from(value).toString();
6810
+ }
6811
+ return Temporal2.PlainDateTime.from(value).toZonedDateTime(timeZone ?? "UTC").toInstant().toString();
6812
+ }
6813
+ function validateTimeZone(timeZone) {
6814
+ try {
6815
+ Temporal2.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);
6816
+ } catch (cause) {
6817
+ if (!(cause instanceof RangeError)) {
6818
+ throw cause;
6819
+ }
6820
+ throw new RangeError(`invalid time zone "${timeZone}"`, { cause });
6821
+ }
6822
+ }
6823
+
6824
+ // shared/dataSources/toDataSourceDateValue.ts
6825
+ function toDataSourceDateValue(value) {
6826
+ if (is(notionDateValueSchema, value)) {
6827
+ return value;
6828
+ }
6829
+ if (typeof value !== "string") {
6830
+ return void 0;
6831
+ }
6832
+ try {
6833
+ const [date, time] = value.split("T");
6834
+ const { start } = toNotionDateInput({
6835
+ type: "datetime",
6836
+ start_date: date,
6837
+ start_time: time ?? "00:00:00Z"
6838
+ });
6839
+ return {
6840
+ type: "datetime",
6841
+ start_date: start.slice(0, 10),
6842
+ start_time: start.slice(11),
6843
+ time_zone: "UTC"
6844
+ };
6845
+ } catch (error) {
6846
+ if (error instanceof RangeError) {
6847
+ return void 0;
6848
+ }
6849
+ throw error;
6378
6850
  }
6379
- return sources.find((source) => source.filename === `worker_${slotKey}`) ?? sources.find((source) => source.filename === slotKey);
6380
6851
  }
6381
6852
 
6382
6853
  // cli/dataSources/listDataSourceFiles.ts
@@ -6394,7 +6865,14 @@ var DEV_SHELL_STATUS_GROUP_NAMES = [
6394
6865
  "Future"
6395
6866
  ];
6396
6867
  function readDataSources(dataDir) {
6397
- return listDataSourceFiles(dataDir).map((name) => readDataSource(resolve(dataDir, name))).sort((left, right) => left.name.localeCompare(right.name));
6868
+ return readSampleDataSourcesSnapshot(dataDir).dataSources.map((source) => {
6869
+ if (source.status === "failed") {
6870
+ throw new Error(
6871
+ `${resolve(dataDir, `${source.filename}.json`)}: ${source.message}`
6872
+ );
6873
+ }
6874
+ return source;
6875
+ }).sort((left, right) => left.name.localeCompare(right.name));
6398
6876
  }
6399
6877
  function readSampleDataSourcesSnapshot(dataDir) {
6400
6878
  const dataSources = [];
@@ -6413,13 +6891,44 @@ function readSampleDataSourcesSnapshot(dataDir) {
6413
6891
  });
6414
6892
  }
6415
6893
  }
6416
- return { dataSources };
6894
+ return { dataSources: rejectDuplicatePageIds(dataSources) };
6895
+ }
6896
+ function rejectDuplicatePageIds(sources) {
6897
+ const filenamesByPageId = /* @__PURE__ */ new Map();
6898
+ for (const source of sources) {
6899
+ if (source.status === "failed") {
6900
+ continue;
6901
+ }
6902
+ for (const row of source.rows) {
6903
+ const filenames = filenamesByPageId.get(row.id) ?? [];
6904
+ filenames.push(source.filename);
6905
+ filenamesByPageId.set(row.id, filenames);
6906
+ }
6907
+ }
6908
+ const errorsByFilename = /* @__PURE__ */ new Map();
6909
+ for (const [pageId, filenames] of filenamesByPageId) {
6910
+ if (filenames.length < 2) {
6911
+ continue;
6912
+ }
6913
+ const files = [...new Set(filenames)].map((filename) => `${filename}.json`).join(", ");
6914
+ const message = `Duplicate page ID "${pageId}" in ${files}. Give each row a unique ID across all sample data files.`;
6915
+ for (const filename of filenames) {
6916
+ if (!errorsByFilename.has(filename)) {
6917
+ errorsByFilename.set(filename, message);
6918
+ }
6919
+ }
6920
+ }
6921
+ return sources.map((source) => {
6922
+ const message = errorsByFilename.get(source.filename);
6923
+ return message === void 0 ? source : { status: "failed", filename: source.filename, message };
6924
+ });
6417
6925
  }
6418
6926
  var nonEmptyString = pipe(string(), nonEmpty());
6419
6927
  var statusOptionsSchema = array(
6420
6928
  object({
6421
6929
  id: nonEmptyString,
6422
- name: nonEmptyString
6930
+ name: nonEmptyString,
6931
+ color: optional(notionPropertyColorSchema)
6423
6932
  })
6424
6933
  );
6425
6934
  var statusGroupsSchema = array(
@@ -6494,26 +7003,28 @@ function readDataSource(file) {
6494
7003
  ),
6495
7004
  rows
6496
7005
  };
6497
- validateDateTimeZones(file, source);
7006
+ validateDateValues(file, source);
6498
7007
  return source;
6499
7008
  }
6500
- function validateDateTimeZones(file, source) {
7009
+ function validateDateValues(file, source) {
6501
7010
  const dateProperties = Object.entries(source.schema).filter(
6502
- ([, property]) => property.type === "date"
7011
+ ([, property]) => property.type === "date" || property.type === "created_time" || property.type === "last_edited_time"
6503
7012
  );
6504
7013
  for (const row of source.rows) {
6505
7014
  for (const [propertyId] of dateProperties) {
6506
7015
  const value = row[propertyId];
6507
- if (!is(notionDateValueSchema, value) || !("time_zone" in value) || value.time_zone === void 0) {
7016
+ if (value === void 0 || value === null) {
6508
7017
  continue;
6509
7018
  }
6510
7019
  try {
6511
- Temporal2.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(
6512
- value.time_zone
6513
- );
7020
+ const date = toDataSourceDateValue(value);
7021
+ if (date === void 0) {
7022
+ throw new Error("Expected a date value or ISO timestamp.");
7023
+ }
7024
+ toNotionDateInput(date);
6514
7025
  } catch (cause) {
6515
7026
  throw new Error(
6516
- `${file}: row "${row.id}", property "${propertyId}": invalid time zone "${value.time_zone}"`,
7027
+ `${file}: row "${row.id}", property "${propertyId}": ${formatUnknownError(cause)}`,
6517
7028
  { cause }
6518
7029
  );
6519
7030
  }
@@ -6529,13 +7040,6 @@ function toNotionPropertySchema(propertyKey, property) {
6529
7040
  });
6530
7041
  }
6531
7042
 
6532
- // cli/utils/unreachable.ts
6533
- function unreachable(value) {
6534
- throw new Error(
6535
- `[custom-blocks-dev-shell] Unexpected value encountered: ${JSON.stringify(value)}`
6536
- );
6537
- }
6538
-
6539
7043
  // cli/dataSources/conversion/convertPublicApiPropertyValue.ts
6540
7044
  function convertPublicApiPropertyValue(publicType, value) {
6541
7045
  if (typeof value !== "object" || value === null) {
@@ -6596,7 +7100,6 @@ function convertPublicApiPropertyValue(publicType, value) {
6596
7100
  case "button":
6597
7101
  return void 0;
6598
7102
  case "place":
6599
- case "location":
6600
7103
  return JSON.stringify(payload);
6601
7104
  default:
6602
7105
  return unreachable(publicType);
@@ -6707,8 +7210,7 @@ var VALUE_SCHEMAS = {
6707
7210
  formula: stringValue,
6708
7211
  rollup: stringValue,
6709
7212
  verification: stringValue,
6710
- place: stringValue,
6711
- location: stringValue
7213
+ place: stringValue
6712
7214
  };
6713
7215
  function matchesPropertyType(value, type) {
6714
7216
  return is(VALUE_SCHEMAS[type] ?? anyLocalValue, value);
@@ -7290,10 +7792,13 @@ import { basename as basename2, dirname } from "node:path";
7290
7792
  // cli/dataSources/copyPrebuiltDataSources.ts
7291
7793
  import { copyFileSync, existsSync as existsSync2, mkdirSync } from "node:fs";
7292
7794
  import { resolve as resolve2 } from "node:path";
7293
- function copyPrebuiltDataSources(prebuiltDir, dataDir) {
7795
+ function copyPrebuiltDataSources(prebuiltDir, dataDir, selectedFilename) {
7294
7796
  mkdirSync(dataDir, { recursive: true });
7295
7797
  const written = [];
7296
7798
  for (const source of readDataSources(prebuiltDir)) {
7799
+ if (selectedFilename !== void 0 && source.filename !== selectedFilename) {
7800
+ continue;
7801
+ }
7297
7802
  const filename = `${source.filename}.json`;
7298
7803
  const target = resolve2(dataDir, filename);
7299
7804
  if (existsSync2(target)) {
@@ -7312,9 +7817,15 @@ function createDevShellDataService(options) {
7312
7817
  const clients = /* @__PURE__ */ new Set();
7313
7818
  let snapshot = {
7314
7819
  blocks,
7315
- prebuiltFilenames: readDataSources(prebuiltDir).map(
7316
- (source) => source.filename
7317
- ),
7820
+ prebuiltSources: readDataSources(prebuiltDir).map((source) => ({
7821
+ filename: source.filename,
7822
+ name: source.name,
7823
+ icon: source.icon,
7824
+ rowCount: source.rows.length,
7825
+ propertyNames: Object.values(source.schema).map(
7826
+ (property) => property.name
7827
+ )
7828
+ })),
7318
7829
  ...readSampleDataSourcesSnapshot(dataDir)
7319
7830
  };
7320
7831
  let serialized = JSON.stringify(snapshot);
@@ -7421,8 +7932,22 @@ function createDevShellDataService(options) {
7421
7932
  );
7422
7933
  return;
7423
7934
  }
7935
+ const filename = new URL(
7936
+ req.url ?? "/",
7937
+ "http://localhost"
7938
+ ).searchParams.get("filename");
7939
+ if (filename !== null && !snapshot.prebuiltSources.some((source) => source.filename === filename)) {
7940
+ res.writeHead(400, { "Content-Type": "application/json" }).end(
7941
+ JSON.stringify({ error: "Choose an available example data source." })
7942
+ );
7943
+ return;
7944
+ }
7424
7945
  try {
7425
- const written = copyPrebuiltDataSources(prebuiltDir, dataDir);
7946
+ const written = copyPrebuiltDataSources(
7947
+ prebuiltDir,
7948
+ dataDir,
7949
+ filename ?? void 0
7950
+ );
7426
7951
  if (written.length > 0) {
7427
7952
  log(`Added example data sources: ${written.join(", ")}`);
7428
7953
  }