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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +108 -22
  3. package/THIRD_PARTY_LICENSES.md +133 -0
  4. package/bin/cli.js +3 -1
  5. package/dist/assets/index-DSaseWP_.js +11 -0
  6. package/dist/assets/index-Do-x8yIt.css +2 -0
  7. package/dist/index.html +2 -2
  8. package/dist-cli/cli/published-cli.js +8476 -0
  9. package/docs/bindings.md +84 -27
  10. package/docs/bridge/changelog.md +67 -0
  11. package/docs/bridge/protocol.md +204 -0
  12. package/docs/bridge/versioning.md +38 -0
  13. package/docs/data-sources.md +49 -36
  14. package/docs/host/README.md +177 -0
  15. package/docs/host/docs/compatibility.md +68 -0
  16. package/docs/host/docs/handlers.md +199 -0
  17. package/docs/host/docs/lifecycle.md +117 -0
  18. package/package.json +9 -28
  19. package/dist/assets/index-E1j3FxAu.css +0 -2
  20. package/dist/assets/index-F02ZboyS.js +0 -11
  21. package/dist-cli/block-csp.js +0 -84
  22. package/dist-cli/build-block-registry.js +0 -28
  23. package/dist-cli/convert-values.js +0 -222
  24. package/dist-cli/convert.js +0 -210
  25. package/dist-cli/data-sources.js +0 -167
  26. package/dist-cli/date-value.js +0 -46
  27. package/dist-cli/dev-shell-launcher.js +0 -226
  28. package/dist-cli/dev-shell-run.js +0 -72
  29. package/dist-cli/errors.js +0 -8
  30. package/dist-cli/materialize.js +0 -105
  31. package/dist-cli/ports.js +0 -20
  32. package/dist-cli/prebuilt.js +0 -23
  33. package/dist-cli/published-cli.js +0 -60
  34. package/dist-cli/resolve-bindings.js +0 -39
  35. package/dist-cli/runtime-error-client.js +0 -52
  36. package/dist-cli/serve-ui.js +0 -110
  37. package/dist-cli/shared-server.js +0 -70
  38. package/dist-cli/source-bindings.js +0 -17
  39. package/dist-cli/utils.js +0 -52
  40. package/dist-cli/vite-block-server.js +0 -125
  41. package/dist-cli/vite-middleware.js +0 -111
  42. package/dist-cli/worker-manifest.js +0 -141
@@ -1,141 +0,0 @@
1
- /**
2
- * Extract a worker's manifest without deploying it, following the localhost
3
- * verification strategy: build the worker, then read the manifest off the
4
- * built module's default export. This is the one prerequisite the dev shell
5
- * needs before it can list a worker's blocks and data sources.
6
- *
7
- * The worker manifest is otherwise in-memory only (tied to `worker.ts` + cloud
8
- * build), so we materialize it under the worker's git-ignored `.dev-shell/` dir
9
- * (clearly a dev shell artifact, not something the author maintains).
10
- * Regenerated on every spin-up.
11
- */
12
- import { execSync } from "node:child_process";
13
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
14
- import { dirname, resolve } from "node:path";
15
- import { pathToFileURL } from "node:url";
16
- const WORKER_MANIFEST_FILENAME = "worker_manifest.json";
17
- /**
18
- * Heuristic for the no-flag fallback: does `dir` look like a worker project?
19
- * True if it carries a worker deploy binding (`worker.json`/`workers.json`) or
20
- * depends on `@notionhq/workers`.
21
- */
22
- function looksLikeWorkerDir(dir) {
23
- if (existsSync(resolve(dir, "worker.json")) ||
24
- existsSync(resolve(dir, "workers.json"))) {
25
- return true;
26
- }
27
- const pkgPath = resolve(dir, "package.json");
28
- if (!existsSync(pkgPath)) {
29
- return false;
30
- }
31
- try {
32
- const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
33
- return Boolean(pkg.dependencies?.["@notionhq/workers"] ??
34
- pkg.devDependencies?.["@notionhq/workers"] ??
35
- pkg.dependencies?.["@notionhq/apps"] ??
36
- pkg.devDependencies?.["@notionhq/apps"]);
37
- }
38
- catch {
39
- return false;
40
- }
41
- }
42
- /**
43
- * Walk up from `startDir` looking for a worker directory (see
44
- * `looksLikeWorkerDir`), so the shell can be launched from anywhere inside a
45
- * worker, not only its root. Stops once it reaches a git-repo boundary (a
46
- * `.git` at the current level, checked after the worker test) or the filesystem
47
- * root — it should never escape the project the user is in.
48
- */
49
- export function findWorkerDir(startDir) {
50
- let current = resolve(startDir);
51
- while (true) {
52
- if (looksLikeWorkerDir(current)) {
53
- return current;
54
- }
55
- if (existsSync(resolve(current, ".git"))) {
56
- return undefined;
57
- }
58
- const parent = dirname(current);
59
- if (parent === current) {
60
- return undefined;
61
- }
62
- current = parent;
63
- }
64
- }
65
- /** The custom-block capabilities in a manifest, narrowed by `_tag`. */
66
- export function blockCapabilities(manifest) {
67
- return manifest.capabilities.filter((capability) => capability._tag === "custom_block");
68
- }
69
- function isManifestShape(value) {
70
- return (typeof value === "object" &&
71
- value !== null &&
72
- Array.isArray(value.capabilities));
73
- }
74
- /**
75
- * Build the worker in `workerDir` and read its manifest off the built default
76
- * export. Mirrors the deploy path (build → read the built module) rather than
77
- * importing TypeScript source, so what the dev shell sees matches what a deploy
78
- * would produce.
79
- */
80
- async function extractWorkerManifest(workerDir, options = {}) {
81
- const root = resolve(workerDir);
82
- if (!existsSync(resolve(root, "package.json"))) {
83
- throw new Error(`No package.json found in worker directory: ${root}`);
84
- }
85
- if (options.build !== false) {
86
- execSync("npm run build", { cwd: root, stdio: "inherit" });
87
- }
88
- const pkg = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));
89
- if (pkg.dependencies?.["@notionhq/apps"] ||
90
- pkg.devDependencies?.["@notionhq/apps"]) {
91
- const raw = JSON.parse(readFileSync(resolve(root, "dist/manifest.json"), "utf8"));
92
- if (!isManifestShape(raw)) {
93
- throw new Error("Apps manifest has no capabilities array");
94
- }
95
- return {
96
- ...raw,
97
- databases: raw.databases ?? [],
98
- pacers: raw.pacers ?? [],
99
- capabilities: raw.capabilities.map(capability => ({
100
- ...capability,
101
- _tag: "type" in capability && typeof capability.type === "string"
102
- ? capability.type
103
- : capability._tag,
104
- })),
105
- };
106
- }
107
- const entry = resolve(root, "dist/index.js");
108
- if (!existsSync(entry)) {
109
- throw new Error(`Built worker entry not found at ${entry}. The worker's build must emit dist/index.js.`);
110
- }
111
- const mod = (await import(pathToFileURL(entry).href));
112
- const worker = mod.default;
113
- if (worker === undefined) {
114
- throw new Error(`Built worker at ${entry} has no default export.`);
115
- }
116
- // Read the built worker's manifest, falling back to a bare capabilities array
117
- // (per the localhost verification doc's `w.manifest || w.capabilities`).
118
- const raw = worker.manifest ?? worker.capabilities;
119
- if (isManifestShape(raw)) {
120
- // The shape check only guarantees `capabilities`; older manifests omit
121
- // the other arrays.
122
- return { ...raw, databases: raw.databases ?? [], pacers: raw.pacers ?? [] };
123
- }
124
- if (Array.isArray(raw)) {
125
- return { databases: [], pacers: [], capabilities: raw };
126
- }
127
- throw new Error(`Built worker at ${entry} exposed no usable manifest (expected .manifest or .capabilities).`);
128
- }
129
- /**
130
- * Extract the worker manifest and write it to `.dev-shell/worker_manifest.json`
131
- * inside the worker (a git-ignored dev shell artifact directory). Returns the parsed
132
- * manifest and the path written.
133
- */
134
- export async function generateWorkerManifest(workerDir, options = {}) {
135
- const manifest = await extractWorkerManifest(workerDir, options);
136
- const dir = resolve(workerDir, ".dev-shell");
137
- mkdirSync(dir, { recursive: true });
138
- const manifestPath = resolve(dir, WORKER_MANIFEST_FILENAME);
139
- writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
140
- return { manifest, manifestPath };
141
- }