@notionhq/custom-blocks 0.0.60 → 0.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/HOST.md CHANGED
@@ -158,7 +158,7 @@ Messages sent from the host to the sandbox. Same `{ wire type, type / schema, be
158
158
  | `pageChanged` | `PageChangedMessage` / `pageChangedMessageSchema` | Replaces the nearest page ancestor without disturbing theme, block ID, parent, user, or query state. |
159
159
  | `currentUserChanged` | `CurrentUserChangedMessage` / `currentUserChangedMessageSchema` | Replaces the current viewer record. Send when any viewer field changes (name, avatar, email). |
160
160
  | `dataSourcesChanged` | `DataSourcesChangedMessage` / `dataSourcesChangedMessageSchema` | Replaces data-source bindings; the sandbox preserves cached query state for keys that still exist and drops removed keys. |
161
- | `queryDataSourceResult` | `QueryDataSourceResultMessage` / `queryDataSourceResultMessageSchema` | `requestId` / `snapshotId`-keyed response with `items`, `hasMore`, and optional `error`. |
161
+ | `queryDataSourceResult` | `QueryDataSourceResultMessage` / `queryDataSourceResultMessageSchema` | `requestId` / `snapshotId`-keyed response with `status: "success"`, `items`, and `hasMore`, or `status: "error"` and `error`. |
162
162
  | `createPageResult` | `CreatePageResultMessage` / `createPageResultMessageSchema` | `requestId`-keyed page response with `status: "success"` or `status: "error"`. |
163
163
  | `getPageResult` | `GetPageResultMessage` / `getPageResultMessageSchema` | Same success/error shape as `createPageResult`. |
164
164
  | `updatePageResult` | `UpdatePageResultMessage` / `updatePageResultMessageSchema` | Same success/error shape as `createPageResult`. |
@@ -0,0 +1,187 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import * as fs from "node:fs";
3
+ import * as path from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { packDirToTarGz } from "./tar.js";
6
+ export const BUILD_OUTPUT_SENTINEL = "<__notion_custom_block__>";
7
+ export const BUILD_OUTPUT_SENTINEL_CLOSE = "</__notion_custom_block__>";
8
+ const WORKER_ENTRY = "dist/index.js";
9
+ /**
10
+ * Build every `_tag: "custom_block"` view declared by the worker.
11
+ *
12
+ * Imports the worker bundle (`<cwd>/dist/index.js`), reads its runtime manifest,
13
+ * and runs the command specified (default `npm run build`)
14
+ */
15
+ export async function buildCustomBlocks(args) {
16
+ const projectRoot = args.cwd ?? process.cwd();
17
+ const entryPath = path.resolve(projectRoot, WORKER_ENTRY);
18
+ const outDir = path.resolve(args.out);
19
+ const blocks = await readCustomBlocks(entryPath);
20
+ if (blocks.length === 0) {
21
+ return { blocks: [] };
22
+ }
23
+ const built = [];
24
+ for (const block of blocks) {
25
+ const bundleDir = path.join(outDir, block.key);
26
+ buildCustomBlock({ block, projectRoot, bundleDir });
27
+ const { checksumCrc32 } = packDirToTarGz(bundleDir);
28
+ built.push({ key: block.key, checksumCrc32, bundleDir });
29
+ }
30
+ return { blocks: built };
31
+ }
32
+ /** Print the build output as the sentinel-wrapped single-line JSON contract. */
33
+ export function printBuildOutput(output) {
34
+ process.stdout.write(`${BUILD_OUTPUT_SENTINEL}${JSON.stringify(output)}${BUILD_OUTPUT_SENTINEL_CLOSE}\n`);
35
+ }
36
+ async function readCustomBlocks(entryPath) {
37
+ const mod = await import(pathToFileURL(entryPath).href);
38
+ const worker = resolveWorker(mod);
39
+ const manifest = readProp(worker, "manifest");
40
+ const capabilities = readProp(manifest, "capabilities");
41
+ if (!Array.isArray(capabilities)) {
42
+ throw new Error(`worker manifest at ${entryPath} has no capabilities array`);
43
+ }
44
+ const blocks = [];
45
+ for (const capability of capabilities) {
46
+ const block = asCustomBlock(capability);
47
+ if (block) {
48
+ blocks.push(block);
49
+ }
50
+ }
51
+ return blocks;
52
+ }
53
+ function resolveWorker(mod) {
54
+ const top = readProp(mod, "default");
55
+ if (top === undefined) {
56
+ throw new Error("worker module has no default export");
57
+ }
58
+ const nested = readProp(top, "default");
59
+ return nested ?? top;
60
+ }
61
+ function readProp(value, key) {
62
+ if (typeof value !== "object" || value === null) {
63
+ return undefined;
64
+ }
65
+ return value[key];
66
+ }
67
+ function asCustomBlock(value) {
68
+ if (typeof value !== "object" || value === null) {
69
+ return undefined;
70
+ }
71
+ const record = value;
72
+ if (record._tag !== "custom_block") {
73
+ return undefined;
74
+ }
75
+ if (typeof record.key !== "string") {
76
+ throw new Error("custom_block capability is missing a string key");
77
+ }
78
+ const config = record.config;
79
+ if (typeof config !== "object" || config === null) {
80
+ throw new Error(`custom_block "${record.key}" is missing config`);
81
+ }
82
+ const source = parseSource(record.key, config.source);
83
+ const dataSources = config.dataSources;
84
+ const manifest = config.manifest;
85
+ return {
86
+ key: record.key,
87
+ config: {
88
+ source,
89
+ ...(isStringRecord(dataSources) ? { dataSources } : {}),
90
+ manifest,
91
+ },
92
+ };
93
+ }
94
+ function parseSource(key, value) {
95
+ if (typeof value !== "object" || value === null) {
96
+ throw new Error(`custom_block "${key}" is missing a source`);
97
+ }
98
+ const source = value;
99
+ if (source.type === "project") {
100
+ if (typeof source.path !== "string") {
101
+ throw new Error(`custom_block "${key}" project source is missing a string path`);
102
+ }
103
+ return {
104
+ type: "project",
105
+ path: source.path,
106
+ ...(typeof source.command === "string"
107
+ ? { command: source.command }
108
+ : {}),
109
+ ...(typeof source.output === "string" ? { output: source.output } : {}),
110
+ };
111
+ }
112
+ if (source.type === "static") {
113
+ if (typeof source.path !== "string") {
114
+ throw new Error(`custom_block "${key}" static source is missing a string path`);
115
+ }
116
+ return { type: "static", path: source.path };
117
+ }
118
+ throw new Error(`custom_block "${key}" has an unsupported source type "${String(source.type)}" — this worker may need a newer @notionhq/workers`);
119
+ }
120
+ function isStringRecord(value) {
121
+ if (typeof value !== "object" || value === null) {
122
+ return false;
123
+ }
124
+ return Object.values(value).every(v => typeof v === "string");
125
+ }
126
+ function buildCustomBlock(args) {
127
+ const { block, projectRoot, bundleDir } = args;
128
+ const sourceDir = resolveSourceDir(block.key, block.config.source, projectRoot);
129
+ fs.rmSync(bundleDir, { recursive: true, force: true });
130
+ fs.mkdirSync(bundleDir, { recursive: true });
131
+ fs.cpSync(sourceDir, bundleDir, { recursive: true });
132
+ }
133
+ const DEFAULT_BUILD_COMMAND = "npm run build";
134
+ const DEFAULT_OUTPUT_DIR = "dist";
135
+ function resolveSourceDir(key, source, projectRoot) {
136
+ if (source.type === "static") {
137
+ const dir = path.resolve(projectRoot, source.path);
138
+ if (!fs.existsSync(dir)) {
139
+ throw new Error(`custom_block "${key}" static dir not found: ${dir}`);
140
+ }
141
+ return dir;
142
+ }
143
+ const projectDir = path.resolve(projectRoot, source.path);
144
+ if (!fs.existsSync(projectDir)) {
145
+ throw new Error(`custom_block "${key}" project dir not found: ${projectDir}`);
146
+ }
147
+ installProjectDeps(key, projectDir);
148
+ const command = source.command ?? DEFAULT_BUILD_COMMAND;
149
+ runCommand(key, command, projectDir);
150
+ const outputDir = path.resolve(projectDir, source.output ?? DEFAULT_OUTPUT_DIR);
151
+ if (!fs.existsSync(outputDir)) {
152
+ throw new Error(`custom_block "${key}" build command "${command}" produced no output at ${outputDir}`);
153
+ }
154
+ return outputDir;
155
+ }
156
+ /**
157
+ * Install a `project` source's own dependencies before building it. `npm ci`
158
+ * when a lockfile is present (faster + deterministic), else `npm install`. No-op
159
+ * when the project has no package.json.
160
+ */
161
+ function installProjectDeps(key, projectDir) {
162
+ if (!fs.existsSync(path.join(projectDir, "package.json"))) {
163
+ return;
164
+ }
165
+ const hasLockfile = fs.existsSync(path.join(projectDir, "package-lock.json"));
166
+ runCommand(key, hasLockfile ? "npm ci" : "npm install", projectDir);
167
+ }
168
+ /**
169
+ * Run a shell command in `cwd`. The child's stdout/stderr are forwarded to our
170
+ * stderr so build/install logs never contaminate the sentinel-wrapped JSON
171
+ * contract this tool writes to stdout.
172
+ */
173
+ function runCommand(key, command, cwd) {
174
+ const result = spawnSync(command, { cwd, shell: true, encoding: "utf8" });
175
+ if (result.stdout) {
176
+ process.stderr.write(result.stdout);
177
+ }
178
+ if (result.stderr) {
179
+ process.stderr.write(result.stderr);
180
+ }
181
+ if (result.error) {
182
+ throw new Error(`custom_block "${key}" build command "${command}" failed to start: ${result.error.message}`);
183
+ }
184
+ if (result.status !== 0) {
185
+ throw new Error(`custom_block "${key}" build command "${command}" exited with code ${String(result.status)}`);
186
+ }
187
+ }
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ import { buildCustomBlocks, printBuildOutput } from "./build.js";
3
+ import { parseUploadsInput, uploadViews } from "./upload.js";
4
+ export async function main(argv) {
5
+ const [command, ...rest] = argv;
6
+ switch (command) {
7
+ case "build":
8
+ return runBuild(rest);
9
+ case "upload":
10
+ return runUpload(rest);
11
+ default:
12
+ printUsage();
13
+ return command === undefined ? 0 : 1;
14
+ }
15
+ }
16
+ async function runBuild(args) {
17
+ const flags = parseFlags(args);
18
+ const out = flags.out;
19
+ if (out === undefined) {
20
+ process.stderr.write("usage: notion-custom-blocks build --out <dir>\n");
21
+ return 1;
22
+ }
23
+ const output = await buildCustomBlocks({ out });
24
+ printBuildOutput(output);
25
+ return 0;
26
+ }
27
+ async function runUpload(args) {
28
+ const flags = parseFlags(args);
29
+ const raw = flags.uploads;
30
+ if (raw === undefined) {
31
+ process.stderr.write("usage: notion-custom-blocks upload --uploads '<json>'\n");
32
+ return 1;
33
+ }
34
+ const uploads = parseUploadsInput(raw);
35
+ const output = await uploadViews(uploads);
36
+ process.stdout.write(`${JSON.stringify(output)}\n`);
37
+ return 0;
38
+ }
39
+ function parseFlags(args) {
40
+ const flags = {};
41
+ for (let i = 0; i < args.length; i++) {
42
+ const arg = args[i];
43
+ if (arg === undefined || !arg.startsWith("--")) {
44
+ continue;
45
+ }
46
+ const name = arg.slice(2);
47
+ const value = args[i + 1];
48
+ if (value === undefined) {
49
+ continue;
50
+ }
51
+ flags[name] = value;
52
+ i++;
53
+ }
54
+ return flags;
55
+ }
56
+ function printUsage() {
57
+ process.stderr.write("Invalid command. See notion-custom-blocks source.");
58
+ }
59
+ main(process.argv.slice(2))
60
+ .then(code => {
61
+ process.exitCode = code;
62
+ })
63
+ .catch((error) => {
64
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
65
+ process.exitCode = 1;
66
+ });
@@ -0,0 +1,102 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import * as zlib from "node:zlib";
4
+ /**
5
+ * Deterministic gzipped-tarball packing for custom-block bundles, shared by the
6
+ * `build` and `upload` phases.
7
+ */
8
+ const BLOCK_SIZE = 512;
9
+ /**
10
+ * Pack a directory into a deterministic gzipped tarball and return both the
11
+ * bytes and their base64 big-endian crc32 checksum (the form
12
+ * `CreateCustomBlockDeploy` signs into the presigned PUT URL).
13
+ */
14
+ export function packDirToTarGz(dir) {
15
+ const entries = collectFiles(dir);
16
+ const tar = writeUstarArchive(entries);
17
+ const tarGz = zlib.gzipSync(tar, {
18
+ level: zlib.constants.Z_BEST_COMPRESSION,
19
+ });
20
+ // Zero the gzip header's MTIME field (bytes 4..7) so repeated packs of the
21
+ // same input are byte-identical. The build phase's crc32 must match the
22
+ // bytes the upload phase PUTs, and gzip otherwise stamps the current time.
23
+ if (tarGz.length >= 8) {
24
+ tarGz.writeUInt32LE(0, 4);
25
+ }
26
+ return { tarGz, checksumCrc32: crc32Base64(tarGz) };
27
+ }
28
+ /** Base64-encoded big-endian crc32, matching the server's `CRC32_BASE64_REGEX`. */
29
+ export function crc32Base64(data) {
30
+ const checksum = zlib.crc32(data) >>> 0;
31
+ const buf = Buffer.alloc(4);
32
+ buf.writeUInt32BE(checksum);
33
+ return buf.toString("base64");
34
+ }
35
+ /** Recursively collect regular files under `dir`, sorted by archive path. */
36
+ function collectFiles(dir) {
37
+ const entries = [];
38
+ function walk(absDir, relDir) {
39
+ const dirents = fs.readdirSync(absDir, { withFileTypes: true });
40
+ for (const dirent of dirents) {
41
+ const abs = path.join(absDir, dirent.name);
42
+ const rel = relDir === "" ? dirent.name : `${relDir}/${dirent.name}`;
43
+ if (dirent.isDirectory()) {
44
+ walk(abs, rel);
45
+ }
46
+ else if (dirent.isFile()) {
47
+ entries.push({ name: rel, contents: fs.readFileSync(abs) });
48
+ }
49
+ }
50
+ }
51
+ walk(dir, "");
52
+ entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
53
+ return entries;
54
+ }
55
+ /** Serialize entries as a minimal POSIX ustar archive. */
56
+ function writeUstarArchive(entries) {
57
+ const chunks = [];
58
+ for (const entry of entries) {
59
+ chunks.push(writeUstarHeader(entry.name, entry.contents.length));
60
+ chunks.push(entry.contents);
61
+ const remainder = entry.contents.length % BLOCK_SIZE;
62
+ if (remainder !== 0) {
63
+ chunks.push(Buffer.alloc(BLOCK_SIZE - remainder));
64
+ }
65
+ }
66
+ // Two zero blocks mark end-of-archive.
67
+ chunks.push(Buffer.alloc(BLOCK_SIZE * 2));
68
+ return Buffer.concat(chunks);
69
+ }
70
+ function writeUstarHeader(name, size) {
71
+ const header = Buffer.alloc(BLOCK_SIZE);
72
+ const nameBytes = Buffer.from(name, "utf8");
73
+ if (nameBytes.length > 100) {
74
+ // ustar splits long paths into name/prefix; keep bundles simple by
75
+ // requiring short paths rather than emitting a GNU/PAX extension.
76
+ throw new Error(`tar entry path too long (max 100 bytes): ${name}`);
77
+ }
78
+ nameBytes.copy(header, 0);
79
+ writeOctal(header, 100, 8, 0o644); // mode
80
+ writeOctal(header, 108, 8, 0); // uid
81
+ writeOctal(header, 116, 8, 0); // gid
82
+ writeOctal(header, 124, 12, size); // size
83
+ writeOctal(header, 136, 12, 0); // mtime
84
+ header.write("0", 156, 1, "ascii"); // typeflag: regular file
85
+ header.write("ustar\0", 257, 6, "ascii"); // magic
86
+ header.write("00", 263, 2, "ascii"); // version
87
+ // Checksum field: spaces during computation, then octal value.
88
+ header.fill(" ", 148, 156);
89
+ let checksum = 0;
90
+ for (let i = 0; i < BLOCK_SIZE; i++) {
91
+ checksum += header[i] ?? 0;
92
+ }
93
+ header.write(checksum.toString(8).padStart(6, "0"), 148, 6, "ascii");
94
+ header.write("\0 ", 154, 2, "ascii");
95
+ return header;
96
+ }
97
+ function writeOctal(header, offset, length, value) {
98
+ // Numeric fields are octal ASCII, null-terminated, right-justified.
99
+ const str = value.toString(8).padStart(length - 1, "0");
100
+ header.write(str, offset, length - 1, "ascii");
101
+ header.write("\0", offset + length - 1, 1, "ascii");
102
+ }
@@ -0,0 +1,60 @@
1
+ import { packDirToTarGz } from "./tar.js";
2
+ const DEFAULT_DEPS = { fetch: globalThis.fetch };
3
+ export async function uploadViews(uploads, deps = DEFAULT_DEPS) {
4
+ const uploaded = {};
5
+ for (const [key, target] of Object.entries(uploads)) {
6
+ const { tarGz, checksumCrc32 } = packDirToTarGz(target.bundleDir);
7
+ const response = await deps.fetch(target.uploadUrl, {
8
+ method: "PUT",
9
+ headers: {
10
+ "Content-Type": "application/gzip",
11
+ "x-amz-checksum-crc32": checksumCrc32,
12
+ },
13
+ body: new Uint8Array(tarGz),
14
+ });
15
+ if (!response.ok) {
16
+ const text = await safeReadText(response);
17
+ throw new Error(`upload failed for block "${key}": ${response.status} ${response.statusText}${text ? `\n${text}` : ""}`);
18
+ }
19
+ uploaded[key] = true;
20
+ }
21
+ return { uploaded };
22
+ }
23
+ export function parseUploadsInput(raw) {
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(raw);
27
+ }
28
+ catch (error) {
29
+ throw new Error(`--uploads is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
30
+ }
31
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
32
+ throw new Error("--uploads must be a JSON object of { key: target }");
33
+ }
34
+ const result = {};
35
+ for (const [key, value] of Object.entries(parsed)) {
36
+ if (typeof value !== "object" || value === null) {
37
+ throw new Error(`--uploads["${key}"] must be an object`);
38
+ }
39
+ const record = value;
40
+ if (typeof record.uploadUrl !== "string") {
41
+ throw new Error(`--uploads["${key}"].uploadUrl must be a string`);
42
+ }
43
+ if (typeof record.bundleDir !== "string") {
44
+ throw new Error(`--uploads["${key}"].bundleDir must be a string`);
45
+ }
46
+ result[key] = {
47
+ uploadUrl: record.uploadUrl,
48
+ bundleDir: record.bundleDir,
49
+ };
50
+ }
51
+ return result;
52
+ }
53
+ async function safeReadText(response) {
54
+ try {
55
+ return await response.text();
56
+ }
57
+ catch {
58
+ return "";
59
+ }
60
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EACX,+BAA+B,EAC/B,gCAAgC,EAChC,MAAM,iCAAiC,CAAA;AAGxC,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAQxD,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAW3E;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,IAAI,EAAE,OAAO,CAAA;CACb,CAAA;AAED,qBAAa,aAAa;IACzB,OAAO,CAAC,SAAS,CAGhB;IACD,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,mBAAmB,CAAwB;IACnD,OAAO,CAAC,aAAa,CAAI;IACzB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAEjC;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AAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAYrD,SAAS,CAAC,KAAK,GAAE,cAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;IAa/D,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2C7D;;;;OAIG;IACH,oBAAoB,CAAC,IAAI,EAAE;QAC1B,UAAU,EAAE,gBAAgB,CAAA;QAC5B,MAAM,EAAE,YAAY,CAAA;QACpB,KAAK,EAAE,+BAA+B,CAAA;KACtC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAuB7C;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAkE/B"}
1
+ {"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EACX,+BAA+B,EAC/B,gCAAgC,EAChC,MAAM,iCAAiC,CAAA;AAGxC,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAQxD,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAW3E;;;;GAIG;AAEH,eAAO,MAAM,oCAAoC,IAAI,CAAA;AAErD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE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IA+CjB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB;IAqE/D,OAAO,CAAC,uBAAuB;IAyB/B,UAAU,CAAC,MAAM,EAAE,MAAM;IAazB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoC7D,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAYrD,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAYrD,SAAS,CAAC,KAAK,GAAE,cAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;IAa/D,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2C7D;;;;OAIG;IACH,oBAAoB,CAAC,IAAI,EAAE;QAC1B,UAAU,EAAE,gBAAgB,CAAA;QAC5B,MAAM,EAAE,YAAY,CAAA;QACpB,KAAK,EAAE,+BAA+B,CAAA;KACtC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAuB7C;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAkE/B"}
@@ -13,6 +13,7 @@ import { PendingRequests } from "./pendingRequests.js";
13
13
  * single host needs to support multiple custom blocks built with different versions of the bridge
14
14
  * protocol. Increment this number any time a breaking change is made to the bridge protocol.
15
15
  */
16
+ // TODO(custom-blocks): Update when bumping bridge protocol version to 3.
16
17
  export const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION = 2;
17
18
  export class SandboxBridge {
18
19
  constructor() {
@@ -205,15 +206,32 @@ export class SandboxBridge {
205
206
  if (currentState.latestRequestId !== message.requestId) {
206
207
  return;
207
208
  }
209
+ const queryResult = "status" in message
210
+ ? message.status === "error"
211
+ ? {
212
+ items: [],
213
+ hasMore: false,
214
+ error: message.error,
215
+ }
216
+ : {
217
+ items: message.items,
218
+ hasMore: message.hasMore,
219
+ error: undefined,
220
+ }
221
+ : {
222
+ items: message.items,
223
+ hasMore: message.hasMore,
224
+ error: message.error,
225
+ };
208
226
  this.hostState = {
209
227
  ...hostState,
210
228
  dataSourceState: {
211
229
  ...hostState.dataSourceState,
212
230
  [key]: {
213
- items: message.items,
231
+ items: queryResult.items,
214
232
  isLoading: false,
215
- hasMore: message.hasMore,
216
- error: message.error,
233
+ hasMore: queryResult.hasMore,
234
+ error: queryResult.error,
217
235
  // Keep the request ID so later host-pushed refreshes for the
218
236
  // same subscription still match.
219
237
  latestRequestId: message.requestId,
@@ -378,7 +378,87 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
378
378
  readonly propertyIdsByKey: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
379
379
  }, undefined>, undefined>;
380
380
  }, undefined>;
381
+ }, undefined>, v.VariantSchema<"status", [v.ObjectSchema<{
382
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
383
+ readonly requestId: v.StringSchema<undefined>;
384
+ readonly snapshotId: v.StringSchema<undefined>;
385
+ readonly status: v.LiteralSchema<"success", undefined>;
386
+ readonly items: v.ArraySchema<v.ObjectSchema<{
387
+ readonly id: v.CustomSchema<import("../ids.js").NotionPageId, v.ErrorMessage<v.CustomIssue> | undefined>;
388
+ readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
389
+ readonly type: v.LiteralSchema<"date", undefined>;
390
+ readonly start_date: v.StringSchema<undefined>;
391
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
392
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
393
+ readonly value: v.NumberSchema<undefined>;
394
+ readonly time: v.StringSchema<undefined>;
395
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
396
+ }, undefined>, v.ObjectSchema<{
397
+ readonly unit: v.LiteralSchema<"none", undefined>;
398
+ }, undefined>], undefined>, undefined>;
399
+ }, undefined>, v.ObjectSchema<{
400
+ readonly type: v.LiteralSchema<"daterange", undefined>;
401
+ readonly start_date: v.StringSchema<undefined>;
402
+ readonly end_date: v.StringSchema<undefined>;
403
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
404
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
405
+ readonly value: v.NumberSchema<undefined>;
406
+ readonly time: v.StringSchema<undefined>;
407
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
408
+ }, undefined>, v.ObjectSchema<{
409
+ readonly unit: v.LiteralSchema<"none", undefined>;
410
+ }, undefined>], undefined>, undefined>;
411
+ }, undefined>, v.ObjectSchema<{
412
+ readonly type: v.LiteralSchema<"datetime", undefined>;
413
+ readonly start_date: v.StringSchema<undefined>;
414
+ readonly start_time: v.StringSchema<undefined>;
415
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
416
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
417
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
418
+ readonly value: v.NumberSchema<undefined>;
419
+ readonly time: v.StringSchema<undefined>;
420
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
421
+ }, undefined>, v.ObjectSchema<{
422
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
423
+ readonly value: v.NumberSchema<undefined>;
424
+ }, undefined>], undefined>, v.ObjectSchema<{
425
+ readonly unit: v.LiteralSchema<"none", undefined>;
426
+ }, undefined>], undefined>, undefined>;
427
+ }, undefined>, v.ObjectSchema<{
428
+ readonly type: v.LiteralSchema<"datetimerange", undefined>;
429
+ readonly start_date: v.StringSchema<undefined>;
430
+ readonly start_time: v.StringSchema<undefined>;
431
+ readonly end_date: v.StringSchema<undefined>;
432
+ readonly end_time: v.StringSchema<undefined>;
433
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
434
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
435
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
436
+ readonly value: v.NumberSchema<undefined>;
437
+ readonly time: v.StringSchema<undefined>;
438
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
439
+ }, undefined>, v.ObjectSchema<{
440
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
441
+ readonly value: v.NumberSchema<undefined>;
442
+ }, undefined>], undefined>, v.ObjectSchema<{
443
+ readonly unit: v.LiteralSchema<"none", undefined>;
444
+ }, undefined>], undefined>, undefined>;
445
+ }, undefined>], undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, v.ArraySchema<v.ObjectSchema<{
446
+ readonly id: v.StringSchema<undefined>;
447
+ readonly table: v.StringSchema<undefined>;
448
+ }, undefined>, undefined>], undefined>, undefined>, undefined>;
449
+ }, undefined>, undefined>;
450
+ readonly hasMore: v.BooleanSchema<undefined>;
381
451
  }, undefined>, v.ObjectSchema<{
452
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
453
+ readonly requestId: v.StringSchema<undefined>;
454
+ readonly snapshotId: v.StringSchema<undefined>;
455
+ readonly status: v.LiteralSchema<"error", undefined>;
456
+ readonly error: v.ObjectSchema<{
457
+ readonly code: v.StringSchema<undefined>;
458
+ readonly message: v.StringSchema<undefined>;
459
+ readonly isRetryable: v.BooleanSchema<undefined>;
460
+ }, undefined>;
461
+ }, undefined>], undefined>, v.ObjectSchema<{
382
462
  readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
383
463
  readonly requestId: v.StringSchema<undefined>;
384
464
  readonly snapshotId: v.StringSchema<undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"hostToSandbox.d.ts","sour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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAerC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAC/C,OAAO,0BAA0B,CACjC,CAAA"}
@@ -9,7 +9,7 @@ import { invalidSandboxMessageSchema } from "./invalidSandboxMessage.js";
9
9
  import { listUsersResultMessageSchema } from "./listUsers.js";
10
10
  import { pageChangedMessageSchema } from "./pageChanged.js";
11
11
  import { parentChangedMessageSchema } from "./parentChanged.js";
12
- import { queryDataSourceResultMessageSchema } from "./queryDataSourceResult.js";
12
+ import { legacyQueryDataSourceResultMessageSchema, statusQueryDataSourceResultMessageSchema, } from "./queryDataSourceResult.js";
13
13
  import { themeChangedMessageSchema } from "./themeChanged.js";
14
14
  import { updatePageResultMessageSchema } from "./updatePageResult.js";
15
15
  /**
@@ -22,7 +22,8 @@ export const hostToSandboxMessageSchema = v.variant("type", [
22
22
  pageChangedMessageSchema,
23
23
  currentUserChangedMessageSchema,
24
24
  dataSourcesChangedMessageSchema,
25
- queryDataSourceResultMessageSchema,
25
+ statusQueryDataSourceResultMessageSchema,
26
+ legacyQueryDataSourceResultMessageSchema,
26
27
  createPageResultMessageSchema,
27
28
  getPageResultMessageSchema,
28
29
  getUserResultMessageSchema,
@@ -11,7 +11,7 @@ export declare const customBlockQueryDataSourceErrorInfoSchema: v.ObjectSchema<{
11
11
  /**
12
12
  * Message sent by the host to the sandbox in response to a `queryDataSource` request.
13
13
  */
14
- export declare const queryDataSourceResultMessageSchema: v.ObjectSchema<{
14
+ export declare const legacyQueryDataSourceResultMessageSchema: v.ObjectSchema<{
15
15
  readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
16
16
  readonly requestId: v.StringSchema<undefined>;
17
17
  readonly snapshotId: v.StringSchema<undefined>;
@@ -86,5 +86,245 @@ export declare const queryDataSourceResultMessageSchema: v.ObjectSchema<{
86
86
  readonly isRetryable: v.BooleanSchema<undefined>;
87
87
  }, undefined>, undefined>;
88
88
  }, undefined>;
89
+ export declare const statusQueryDataSourceResultMessageSchema: v.VariantSchema<"status", [v.ObjectSchema<{
90
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
91
+ readonly requestId: v.StringSchema<undefined>;
92
+ readonly snapshotId: v.StringSchema<undefined>;
93
+ readonly status: v.LiteralSchema<"success", undefined>;
94
+ readonly items: v.ArraySchema<v.ObjectSchema<{
95
+ readonly id: v.CustomSchema<import("../ids.js").NotionPageId, v.ErrorMessage<v.CustomIssue> | undefined>;
96
+ readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
97
+ readonly type: v.LiteralSchema<"date", undefined>;
98
+ readonly start_date: v.StringSchema<undefined>;
99
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
100
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
101
+ readonly value: v.NumberSchema<undefined>;
102
+ readonly time: v.StringSchema<undefined>;
103
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
104
+ }, undefined>, v.ObjectSchema<{
105
+ readonly unit: v.LiteralSchema<"none", undefined>;
106
+ }, undefined>], undefined>, undefined>;
107
+ }, undefined>, v.ObjectSchema<{
108
+ readonly type: v.LiteralSchema<"daterange", undefined>;
109
+ readonly start_date: v.StringSchema<undefined>;
110
+ readonly end_date: v.StringSchema<undefined>;
111
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
112
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
113
+ readonly value: v.NumberSchema<undefined>;
114
+ readonly time: v.StringSchema<undefined>;
115
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
116
+ }, undefined>, v.ObjectSchema<{
117
+ readonly unit: v.LiteralSchema<"none", undefined>;
118
+ }, undefined>], undefined>, undefined>;
119
+ }, undefined>, v.ObjectSchema<{
120
+ readonly type: v.LiteralSchema<"datetime", undefined>;
121
+ readonly start_date: v.StringSchema<undefined>;
122
+ readonly start_time: v.StringSchema<undefined>;
123
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
124
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
125
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
126
+ readonly value: v.NumberSchema<undefined>;
127
+ readonly time: v.StringSchema<undefined>;
128
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
129
+ }, undefined>, v.ObjectSchema<{
130
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
131
+ readonly value: v.NumberSchema<undefined>;
132
+ }, undefined>], undefined>, v.ObjectSchema<{
133
+ readonly unit: v.LiteralSchema<"none", undefined>;
134
+ }, undefined>], undefined>, undefined>;
135
+ }, undefined>, v.ObjectSchema<{
136
+ readonly type: v.LiteralSchema<"datetimerange", undefined>;
137
+ readonly start_date: v.StringSchema<undefined>;
138
+ readonly start_time: v.StringSchema<undefined>;
139
+ readonly end_date: v.StringSchema<undefined>;
140
+ readonly end_time: v.StringSchema<undefined>;
141
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
142
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
143
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
144
+ readonly value: v.NumberSchema<undefined>;
145
+ readonly time: v.StringSchema<undefined>;
146
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
147
+ }, undefined>, v.ObjectSchema<{
148
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
149
+ readonly value: v.NumberSchema<undefined>;
150
+ }, undefined>], undefined>, v.ObjectSchema<{
151
+ readonly unit: v.LiteralSchema<"none", undefined>;
152
+ }, undefined>], undefined>, undefined>;
153
+ }, undefined>], undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, v.ArraySchema<v.ObjectSchema<{
154
+ readonly id: v.StringSchema<undefined>;
155
+ readonly table: v.StringSchema<undefined>;
156
+ }, undefined>, undefined>], undefined>, undefined>, undefined>;
157
+ }, undefined>, undefined>;
158
+ readonly hasMore: v.BooleanSchema<undefined>;
159
+ }, undefined>, v.ObjectSchema<{
160
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
161
+ readonly requestId: v.StringSchema<undefined>;
162
+ readonly snapshotId: v.StringSchema<undefined>;
163
+ readonly status: v.LiteralSchema<"error", undefined>;
164
+ readonly error: v.ObjectSchema<{
165
+ readonly code: v.StringSchema<undefined>;
166
+ readonly message: v.StringSchema<undefined>;
167
+ readonly isRetryable: v.BooleanSchema<undefined>;
168
+ }, undefined>;
169
+ }, undefined>], undefined>;
170
+ /**
171
+ * TODO(custom-blocks): Update when bumping bridge protocol version to 3.
172
+ * Protocol version 2 hosts and sandboxes use the legacy optional-error shape.
173
+ */
174
+ export declare const queryDataSourceResultMessageSchema: v.UnionSchema<[v.ObjectSchema<{
175
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
176
+ readonly requestId: v.StringSchema<undefined>;
177
+ readonly snapshotId: v.StringSchema<undefined>;
178
+ readonly items: v.ArraySchema<v.ObjectSchema<{
179
+ readonly id: v.CustomSchema<import("../ids.js").NotionPageId, v.ErrorMessage<v.CustomIssue> | undefined>;
180
+ readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
181
+ readonly type: v.LiteralSchema<"date", undefined>;
182
+ readonly start_date: v.StringSchema<undefined>;
183
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
184
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
185
+ readonly value: v.NumberSchema<undefined>;
186
+ readonly time: v.StringSchema<undefined>;
187
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
188
+ }, undefined>, v.ObjectSchema<{
189
+ readonly unit: v.LiteralSchema<"none", undefined>;
190
+ }, undefined>], undefined>, undefined>;
191
+ }, undefined>, v.ObjectSchema<{
192
+ readonly type: v.LiteralSchema<"daterange", undefined>;
193
+ readonly start_date: v.StringSchema<undefined>;
194
+ readonly end_date: v.StringSchema<undefined>;
195
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
196
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
197
+ readonly value: v.NumberSchema<undefined>;
198
+ readonly time: v.StringSchema<undefined>;
199
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
200
+ }, undefined>, v.ObjectSchema<{
201
+ readonly unit: v.LiteralSchema<"none", undefined>;
202
+ }, undefined>], undefined>, undefined>;
203
+ }, undefined>, v.ObjectSchema<{
204
+ readonly type: v.LiteralSchema<"datetime", undefined>;
205
+ readonly start_date: v.StringSchema<undefined>;
206
+ readonly start_time: v.StringSchema<undefined>;
207
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
208
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
209
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
210
+ readonly value: v.NumberSchema<undefined>;
211
+ readonly time: v.StringSchema<undefined>;
212
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
213
+ }, undefined>, v.ObjectSchema<{
214
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
215
+ readonly value: v.NumberSchema<undefined>;
216
+ }, undefined>], undefined>, v.ObjectSchema<{
217
+ readonly unit: v.LiteralSchema<"none", undefined>;
218
+ }, undefined>], undefined>, undefined>;
219
+ }, undefined>, v.ObjectSchema<{
220
+ readonly type: v.LiteralSchema<"datetimerange", undefined>;
221
+ readonly start_date: v.StringSchema<undefined>;
222
+ readonly start_time: v.StringSchema<undefined>;
223
+ readonly end_date: v.StringSchema<undefined>;
224
+ readonly end_time: v.StringSchema<undefined>;
225
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
226
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
227
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
228
+ readonly value: v.NumberSchema<undefined>;
229
+ readonly time: v.StringSchema<undefined>;
230
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
231
+ }, undefined>, v.ObjectSchema<{
232
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
233
+ readonly value: v.NumberSchema<undefined>;
234
+ }, undefined>], undefined>, v.ObjectSchema<{
235
+ readonly unit: v.LiteralSchema<"none", undefined>;
236
+ }, undefined>], undefined>, undefined>;
237
+ }, undefined>], undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, v.ArraySchema<v.ObjectSchema<{
238
+ readonly id: v.StringSchema<undefined>;
239
+ readonly table: v.StringSchema<undefined>;
240
+ }, undefined>, undefined>], undefined>, undefined>, undefined>;
241
+ }, undefined>, undefined>;
242
+ readonly hasMore: v.BooleanSchema<undefined>;
243
+ readonly error: v.OptionalSchema<v.ObjectSchema<{
244
+ readonly code: v.StringSchema<undefined>;
245
+ readonly message: v.StringSchema<undefined>;
246
+ readonly isRetryable: v.BooleanSchema<undefined>;
247
+ }, undefined>, undefined>;
248
+ }, undefined>, v.VariantSchema<"status", [v.ObjectSchema<{
249
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
250
+ readonly requestId: v.StringSchema<undefined>;
251
+ readonly snapshotId: v.StringSchema<undefined>;
252
+ readonly status: v.LiteralSchema<"success", undefined>;
253
+ readonly items: v.ArraySchema<v.ObjectSchema<{
254
+ readonly id: v.CustomSchema<import("../ids.js").NotionPageId, v.ErrorMessage<v.CustomIssue> | undefined>;
255
+ readonly propertiesById: v.RecordSchema<v.StringSchema<undefined>, v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.VariantSchema<"type", [v.ObjectSchema<{
256
+ readonly type: v.LiteralSchema<"date", undefined>;
257
+ readonly start_date: v.StringSchema<undefined>;
258
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
259
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
260
+ readonly value: v.NumberSchema<undefined>;
261
+ readonly time: v.StringSchema<undefined>;
262
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
263
+ }, undefined>, v.ObjectSchema<{
264
+ readonly unit: v.LiteralSchema<"none", undefined>;
265
+ }, undefined>], undefined>, undefined>;
266
+ }, undefined>, v.ObjectSchema<{
267
+ readonly type: v.LiteralSchema<"daterange", undefined>;
268
+ readonly start_date: v.StringSchema<undefined>;
269
+ readonly end_date: v.StringSchema<undefined>;
270
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.ObjectSchema<{
271
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
272
+ readonly value: v.NumberSchema<undefined>;
273
+ readonly time: v.StringSchema<undefined>;
274
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
275
+ }, undefined>, v.ObjectSchema<{
276
+ readonly unit: v.LiteralSchema<"none", undefined>;
277
+ }, undefined>], undefined>, undefined>;
278
+ }, undefined>, v.ObjectSchema<{
279
+ readonly type: v.LiteralSchema<"datetime", undefined>;
280
+ readonly start_date: v.StringSchema<undefined>;
281
+ readonly start_time: v.StringSchema<undefined>;
282
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
283
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
284
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
285
+ readonly value: v.NumberSchema<undefined>;
286
+ readonly time: v.StringSchema<undefined>;
287
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
288
+ }, undefined>, v.ObjectSchema<{
289
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
290
+ readonly value: v.NumberSchema<undefined>;
291
+ }, undefined>], undefined>, v.ObjectSchema<{
292
+ readonly unit: v.LiteralSchema<"none", undefined>;
293
+ }, undefined>], undefined>, undefined>;
294
+ }, undefined>, v.ObjectSchema<{
295
+ readonly type: v.LiteralSchema<"datetimerange", undefined>;
296
+ readonly start_date: v.StringSchema<undefined>;
297
+ readonly start_time: v.StringSchema<undefined>;
298
+ readonly end_date: v.StringSchema<undefined>;
299
+ readonly end_time: v.StringSchema<undefined>;
300
+ readonly time_zone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
301
+ readonly reminder: v.OptionalSchema<v.UnionSchema<[v.UnionSchema<[v.ObjectSchema<{
302
+ readonly unit: v.PicklistSchema<["year", "month", "week", "day"], undefined>;
303
+ readonly value: v.NumberSchema<undefined>;
304
+ readonly time: v.StringSchema<undefined>;
305
+ readonly defaultTimeZone: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
306
+ }, undefined>, v.ObjectSchema<{
307
+ readonly unit: v.PicklistSchema<["hour", "minute"], undefined>;
308
+ readonly value: v.NumberSchema<undefined>;
309
+ }, undefined>], undefined>, v.ObjectSchema<{
310
+ readonly unit: v.LiteralSchema<"none", undefined>;
311
+ }, undefined>], undefined>, undefined>;
312
+ }, undefined>], undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, v.ArraySchema<v.ObjectSchema<{
313
+ readonly id: v.StringSchema<undefined>;
314
+ readonly table: v.StringSchema<undefined>;
315
+ }, undefined>, undefined>], undefined>, undefined>, undefined>;
316
+ }, undefined>, undefined>;
317
+ readonly hasMore: v.BooleanSchema<undefined>;
318
+ }, undefined>, v.ObjectSchema<{
319
+ readonly type: v.LiteralSchema<"queryDataSourceResult", undefined>;
320
+ readonly requestId: v.StringSchema<undefined>;
321
+ readonly snapshotId: v.StringSchema<undefined>;
322
+ readonly status: v.LiteralSchema<"error", undefined>;
323
+ readonly error: v.ObjectSchema<{
324
+ readonly code: v.StringSchema<undefined>;
325
+ readonly message: v.StringSchema<undefined>;
326
+ readonly isRetryable: v.BooleanSchema<undefined>;
327
+ }, undefined>;
328
+ }, undefined>], undefined>], undefined>;
89
329
  export type QueryDataSourceResultMessage = v.InferOutput<typeof queryDataSourceResultMessageSchema>;
90
330
  //# sourceMappingURL=queryDataSourceResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryDataSourceResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/queryDataSourceResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAIxD,eAAO,MAAM,yCAAyC,2BAAa,CAAA;AAEnE,MAAM,MAAM,mCAAmC,GAC5C,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,mCAAmC,GAC9C,oBAAoB,CAAC,mCAAmC,CAAC,CAAA;AAE1D,eAAO,MAAM,yCAAyC;;;;aAIpD,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAO7C,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CACvD,OAAO,kCAAkC,CACzC,CAAA"}
1
+ {"version":3,"file":"queryDataSourceResult.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/messages/queryDataSourceResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAIxD,eAAO,MAAM,yCAAyC,2BAAa,CAAA;AAEnE,MAAM,MAAM,mCAAmC,GAC5C,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEhB,MAAM,MAAM,mCAAmC,GAC9C,oBAAoB,CAAC,mCAAmC,CAAC,CAAA;AAE1D,eAAO,MAAM,yCAAyC;;;;aAIpD,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAOnD,CAAA;AAEF,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAgBnD,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCAG7C,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CACvD,OAAO,kCAAkC,CACzC,CAAA"}
@@ -11,7 +11,7 @@ export const customBlockQueryDataSourceErrorInfoSchema = v.object({
11
11
  /**
12
12
  * Message sent by the host to the sandbox in response to a `queryDataSource` request.
13
13
  */
14
- export const queryDataSourceResultMessageSchema = v.object({
14
+ export const legacyQueryDataSourceResultMessageSchema = v.object({
15
15
  type: v.literal("queryDataSourceResult"),
16
16
  requestId: v.string(),
17
17
  snapshotId: v.string(),
@@ -19,3 +19,28 @@ export const queryDataSourceResultMessageSchema = v.object({
19
19
  hasMore: v.boolean(),
20
20
  error: v.optional(customBlockQueryDataSourceErrorInfoSchema),
21
21
  });
22
+ export const statusQueryDataSourceResultMessageSchema = v.variant("status", [
23
+ v.object({
24
+ type: v.literal("queryDataSourceResult"),
25
+ requestId: v.string(),
26
+ snapshotId: v.string(),
27
+ status: v.literal("success"),
28
+ items: v.array(notionDataSourcePageBridgeSchema),
29
+ hasMore: v.boolean(),
30
+ }),
31
+ v.object({
32
+ type: v.literal("queryDataSourceResult"),
33
+ requestId: v.string(),
34
+ snapshotId: v.string(),
35
+ status: v.literal("error"),
36
+ error: customBlockQueryDataSourceErrorInfoSchema,
37
+ }),
38
+ ]);
39
+ /**
40
+ * TODO(custom-blocks): Update when bumping bridge protocol version to 3.
41
+ * Protocol version 2 hosts and sandboxes use the legacy optional-error shape.
42
+ */
43
+ export const queryDataSourceResultMessageSchema = v.union([
44
+ legacyQueryDataSourceResultMessageSchema,
45
+ statusQueryDataSourceResultMessageSchema,
46
+ ]);
@@ -1 +1 @@
1
- {"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/createCustomBlockHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAY1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAkB/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAIzD,OAAO,KAAK,EACX,iCAAiC,EACjC,2BAA2B,EAE3B,mBAAmB,EACnB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAA;AAE9E,MAAM,MAAM,sBAAsB,GAAG;IACpC,MAAM,EAAE,iBAAiB,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,2BAA2B,CAAA;IACzC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAA;IAChD,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CAC1E,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAA;IAC7C,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;IACtC,SAAS,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAA;IACzC,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA;IACxC,cAAc,EAAE,CAAC,WAAW,EAAE,iCAAiC,KAAK,IAAI,CAAA;IACxE,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,KAAK,IAAI,CAAA;IACjD,YAAY,EAAE,CAAC,IAAI,EAAE;QACpB,YAAY,EAAE,kBAAkB,CAAA;QAChC,QAAQ,EAAE,oCAAoC,CAAA;KAC9C,KAAK,IAAI,CAAA;CACV,CAAA;AAKD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,GAC7B,qBAAqB,CAqTvB"}
1
+ {"version":3,"file":"createCustomBlockHost.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/createCustomBlockHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAY1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAkB/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAIzD,OAAO,KAAK,EACX,iCAAiC,EACjC,2B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,qBAAqB,CAuTvB"}
@@ -25,6 +25,8 @@ export function createCustomBlockHost(options) {
25
25
  iframe.contentWindow?.postMessage(message, targetOrigin);
26
26
  }
27
27
  function postQueryDataSourceResult(args) {
28
+ // TODO(custom-blocks): Update when bumping bridge protocol version to 3.
29
+ // Protocol v2 sandboxes require the legacy optional-error result shape.
28
30
  const message = {
29
31
  type: "queryDataSourceResult",
30
32
  requestId: args.requestId,
@@ -1,7 +1,8 @@
1
+ import type { NotionDataSourcePageBridge } from "../../bridge/dataSources/dataSourcePage.js";
1
2
  import type { QueryDataSourceMessage } from "../../bridge/messages/queryDataSource.js";
2
- import type { CustomBlockQueryDataSourceErrorInfo, QueryDataSourceResultMessage } from "../../bridge/messages/queryDataSourceResult.js";
3
+ import type { CustomBlockQueryDataSourceErrorInfo } from "../../bridge/messages/queryDataSourceResult.js";
3
4
  export type CustomBlockHostQueryDataSourceResult = {
4
- items: QueryDataSourceResultMessage["items"];
5
+ items: NotionDataSourcePageBridge[];
5
6
  hasMore?: boolean;
6
7
  error?: CustomBlockQueryDataSourceErrorInfo;
7
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/queries/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAA;AACtF,OAAO,KAAK,EACX,mCAAmC,EACnC,4BAA4B,EAC5B,MAAM,gDAAgD,CAAA;AAEvD,MAAM,MAAM,oCAAoC,GAAG;IAClD,KAAK,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAA;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,mCAAmC,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACxC,sBAAsB,EACtB,WAAW,GAAG,YAAY,GAAG,OAAO,CACpC,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/queries/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AAC5F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAA;AACtF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,gDAAgD,CAAA;AAEzG,MAAM,MAAM,oCAAoC,GAAG;IAClD,KAAK,EAAE,0BAA0B,EAAE,CAAA;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,mCAAmC,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACxC,sBAAsB,EACtB,WAAW,GAAG,YAAY,GAAG,OAAO,CACpC,CAAA"}
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  *
5
5
  * WARNING: Generated during SDK publish. Do not edit in the published package.
6
6
  */
7
- export const NCBLOCK_SDK_VERSION = "0.0.60"
7
+ export const NCBLOCK_SDK_VERSION = "0.0.62"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -32,7 +32,8 @@
32
32
  }
33
33
  },
34
34
  "bin": {
35
- "ncblock": "./bin/cli/cli.js"
35
+ "ncblock": "./bin/cli/cli.js",
36
+ "notion-custom-blocks": "./bin/notion-custom-blocks/cli.js"
36
37
  },
37
38
  "scripts": {
38
39
  "test": "vitest run --environment jsdom",
@@ -55,6 +55,7 @@ import type { NotionUser } from "./users/user.js"
55
55
  * single host needs to support multiple custom blocks built with different versions of the bridge
56
56
  * protocol. Increment this number any time a breaking change is made to the bridge protocol.
57
57
  */
58
+ // TODO(custom-blocks): Update when bumping bridge protocol version to 3.
58
59
  export const CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION = 2
59
60
 
60
61
  /**
@@ -408,15 +409,33 @@ export class SandboxBridge {
408
409
  if (currentState.latestRequestId !== message.requestId) {
409
410
  return
410
411
  }
412
+ const queryResult =
413
+ "status" in message
414
+ ? message.status === "error"
415
+ ? {
416
+ items: [],
417
+ hasMore: false,
418
+ error: message.error,
419
+ }
420
+ : {
421
+ items: message.items,
422
+ hasMore: message.hasMore,
423
+ error: undefined,
424
+ }
425
+ : {
426
+ items: message.items,
427
+ hasMore: message.hasMore,
428
+ error: message.error,
429
+ }
411
430
  this.hostState = {
412
431
  ...hostState,
413
432
  dataSourceState: {
414
433
  ...hostState.dataSourceState,
415
434
  [key]: {
416
- items: message.items,
435
+ items: queryResult.items,
417
436
  isLoading: false,
418
- hasMore: message.hasMore,
419
- error: message.error,
437
+ hasMore: queryResult.hasMore,
438
+ error: queryResult.error,
420
439
  // Keep the request ID so later host-pushed refreshes for the
421
440
  // same subscription still match.
422
441
  latestRequestId: message.requestId,
@@ -9,7 +9,10 @@ import { invalidSandboxMessageSchema } from "./invalidSandboxMessage.js"
9
9
  import { listUsersResultMessageSchema } from "./listUsers.js"
10
10
  import { pageChangedMessageSchema } from "./pageChanged.js"
11
11
  import { parentChangedMessageSchema } from "./parentChanged.js"
12
- import { queryDataSourceResultMessageSchema } from "./queryDataSourceResult.js"
12
+ import {
13
+ legacyQueryDataSourceResultMessageSchema,
14
+ statusQueryDataSourceResultMessageSchema,
15
+ } from "./queryDataSourceResult.js"
13
16
  import { themeChangedMessageSchema } from "./themeChanged.js"
14
17
  import { updatePageResultMessageSchema } from "./updatePageResult.js"
15
18
 
@@ -23,7 +26,8 @@ export const hostToSandboxMessageSchema = v.variant("type", [
23
26
  pageChangedMessageSchema,
24
27
  currentUserChangedMessageSchema,
25
28
  dataSourcesChangedMessageSchema,
26
- queryDataSourceResultMessageSchema,
29
+ statusQueryDataSourceResultMessageSchema,
30
+ legacyQueryDataSourceResultMessageSchema,
27
31
  createPageResultMessageSchema,
28
32
  getPageResultMessageSchema,
29
33
  getUserResultMessageSchema,
@@ -24,7 +24,7 @@ export const customBlockQueryDataSourceErrorInfoSchema = v.object({
24
24
  /**
25
25
  * Message sent by the host to the sandbox in response to a `queryDataSource` request.
26
26
  */
27
- export const queryDataSourceResultMessageSchema = v.object({
27
+ export const legacyQueryDataSourceResultMessageSchema = v.object({
28
28
  type: v.literal("queryDataSourceResult"),
29
29
  requestId: v.string(),
30
30
  snapshotId: v.string(),
@@ -33,6 +33,33 @@ export const queryDataSourceResultMessageSchema = v.object({
33
33
  error: v.optional(customBlockQueryDataSourceErrorInfoSchema),
34
34
  })
35
35
 
36
+ export const statusQueryDataSourceResultMessageSchema = v.variant("status", [
37
+ v.object({
38
+ type: v.literal("queryDataSourceResult"),
39
+ requestId: v.string(),
40
+ snapshotId: v.string(),
41
+ status: v.literal("success"),
42
+ items: v.array(notionDataSourcePageBridgeSchema),
43
+ hasMore: v.boolean(),
44
+ }),
45
+ v.object({
46
+ type: v.literal("queryDataSourceResult"),
47
+ requestId: v.string(),
48
+ snapshotId: v.string(),
49
+ status: v.literal("error"),
50
+ error: customBlockQueryDataSourceErrorInfoSchema,
51
+ }),
52
+ ])
53
+
54
+ /**
55
+ * TODO(custom-blocks): Update when bumping bridge protocol version to 3.
56
+ * Protocol version 2 hosts and sandboxes use the legacy optional-error shape.
57
+ */
58
+ export const queryDataSourceResultMessageSchema = v.union([
59
+ legacyQueryDataSourceResultMessageSchema,
60
+ statusQueryDataSourceResultMessageSchema,
61
+ ])
62
+
36
63
  export type QueryDataSourceResultMessage = v.InferOutput<
37
64
  typeof queryDataSourceResultMessageSchema
38
65
  >
@@ -115,6 +115,8 @@ export function createCustomBlockHost(
115
115
  snapshotId: string
116
116
  response: CustomBlockHostQueryDataSourceResult
117
117
  }) {
118
+ // TODO(custom-blocks): Update when bumping bridge protocol version to 3.
119
+ // Protocol v2 sandboxes require the legacy optional-error result shape.
118
120
  const message: QueryDataSourceResultMessage = {
119
121
  type: "queryDataSourceResult",
120
122
  requestId: args.requestId,
@@ -1,11 +1,9 @@
1
+ import type { NotionDataSourcePageBridge } from "../../bridge/dataSources/dataSourcePage.js"
1
2
  import type { QueryDataSourceMessage } from "../../bridge/messages/queryDataSource.js"
2
- import type {
3
- CustomBlockQueryDataSourceErrorInfo,
4
- QueryDataSourceResultMessage,
5
- } from "../../bridge/messages/queryDataSourceResult.js"
3
+ import type { CustomBlockQueryDataSourceErrorInfo } from "../../bridge/messages/queryDataSourceResult.js"
6
4
 
7
5
  export type CustomBlockHostQueryDataSourceResult = {
8
- items: QueryDataSourceResultMessage["items"]
6
+ items: NotionDataSourcePageBridge[]
9
7
  hasMore?: boolean
10
8
  error?: CustomBlockQueryDataSourceErrorInfo
11
9
  }