@notionhq/custom-blocks-dev-shell 0.1.115 → 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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -13
  3. package/THIRD_PARTY_LICENSES.md +133 -0
  4. package/dist/assets/index-DSaseWP_.js +11 -0
  5. package/dist/assets/index-Do-x8yIt.css +2 -0
  6. package/dist/index.html +2 -2
  7. package/dist-cli/cli/published-cli.js +8467 -51
  8. package/docs/bindings.md +17 -12
  9. package/docs/bridge/changelog.md +67 -0
  10. package/docs/bridge/protocol.md +204 -0
  11. package/docs/bridge/versioning.md +38 -0
  12. package/docs/data-sources.md +49 -36
  13. package/docs/host/README.md +177 -0
  14. package/docs/host/docs/compatibility.md +68 -0
  15. package/docs/host/docs/handlers.md +199 -0
  16. package/docs/host/docs/lifecycle.md +117 -0
  17. package/package.json +5 -3
  18. package/dist/assets/index-DXzPwq_J.js +0 -11
  19. package/dist/assets/index-E1j3FxAu.css +0 -2
  20. package/dist-cli/cli/binding-cli-flags.js +0 -33
  21. package/dist-cli/cli/binding-errors.js +0 -15
  22. package/dist-cli/cli/block-csp.js +0 -84
  23. package/dist-cli/cli/build-block-registry.js +0 -30
  24. package/dist-cli/cli/convert-values.js +0 -222
  25. package/dist-cli/cli/convert.js +0 -210
  26. package/dist-cli/cli/data-source-files.js +0 -6
  27. package/dist-cli/cli/data-sources.js +0 -114
  28. package/dist-cli/cli/dev-shell-launcher.js +0 -239
  29. package/dist-cli/cli/dev-shell-run.js +0 -72
  30. package/dist-cli/cli/errors.js +0 -12
  31. package/dist-cli/cli/launcher-bindings.js +0 -144
  32. package/dist-cli/cli/materialize.js +0 -105
  33. package/dist-cli/cli/ports.js +0 -20
  34. package/dist-cli/cli/prebuilt.js +0 -23
  35. package/dist-cli/cli/runtime-error-client.js +0 -52
  36. package/dist-cli/cli/serve-ui.js +0 -110
  37. package/dist-cli/cli/shared-server.js +0 -70
  38. package/dist-cli/cli/utils.js +0 -52
  39. package/dist-cli/cli/vite-block-server.js +0 -125
  40. package/dist-cli/cli/vite-middleware.js +0 -111
  41. package/dist-cli/cli/worker-manifest.js +0 -158
  42. package/dist-cli/protocol/contrast.d.ts +0 -4
  43. package/dist-cli/protocol/contrast.js +0 -3
  44. package/dist-cli/protocol/dataSources/dataSource.d.ts +0 -786
  45. package/dist-cli/protocol/dataSources/dataSource.js +0 -66
  46. package/dist-cli/protocol/dataSources/dataSourcePage.d.ts +0 -74
  47. package/dist-cli/protocol/dataSources/dataSourcePage.js +0 -15
  48. package/dist-cli/protocol/dataSources/dataSourceValue.d.ts +0 -66
  49. package/dist-cli/protocol/dataSources/dataSourceValue.js +0 -14
  50. package/dist-cli/protocol/dataSources/dateValue.d.ts +0 -157
  51. package/dist-cli/protocol/dataSources/dateValue.js +0 -61
  52. package/dist-cli/protocol/dataSources/errors.d.ts +0 -8
  53. package/dist-cli/protocol/dataSources/errors.js +0 -7
  54. package/dist-cli/protocol/dataSources/propertySchema.d.ts +0 -200
  55. package/dist-cli/protocol/dataSources/propertySchema.js +0 -174
  56. package/dist-cli/protocol/dataSources/recordPointer.d.ts +0 -9
  57. package/dist-cli/protocol/dataSources/recordPointer.js +0 -8
  58. package/dist-cli/protocol/dataSources/sortDirection.d.ts +0 -3
  59. package/dist-cli/protocol/dataSources/sortDirection.js +0 -2
  60. package/dist-cli/protocol/errors.d.ts +0 -12
  61. package/dist-cli/protocol/errors.js +0 -6
  62. package/dist-cli/protocol/ids.d.ts +0 -31
  63. package/dist-cli/protocol/ids.js +0 -26
  64. package/dist-cli/protocol/index.d.ts +0 -53
  65. package/dist-cli/protocol/index.js +0 -53
  66. package/dist-cli/protocol/manifest.d.ts +0 -67
  67. package/dist-cli/protocol/manifest.js +0 -36
  68. package/dist-cli/protocol/messages/connect.d.ts +0 -54
  69. package/dist-cli/protocol/messages/connect.js +0 -39
  70. package/dist-cli/protocol/messages/contrastModeChanged.d.ts +0 -7
  71. package/dist-cli/protocol/messages/contrastModeChanged.js +0 -7
  72. package/dist-cli/protocol/messages/createPage.d.ts +0 -290
  73. package/dist-cli/protocol/messages/createPage.js +0 -51
  74. package/dist-cli/protocol/messages/createPageResult.d.ts +0 -897
  75. package/dist-cli/protocol/messages/createPageResult.js +0 -43
  76. package/dist-cli/protocol/messages/currentUserChanged.d.ts +0 -18
  77. package/dist-cli/protocol/messages/currentUserChanged.js +0 -9
  78. package/dist-cli/protocol/messages/dataSourcesChanged.d.ts +0 -157
  79. package/dist-cli/protocol/messages/dataSourcesChanged.js +0 -13
  80. package/dist-cli/protocol/messages/getPage.d.ts +0 -902
  81. package/dist-cli/protocol/messages/getPage.js +0 -48
  82. package/dist-cli/protocol/messages/getUser.d.ts +0 -44
  83. package/dist-cli/protocol/messages/getUser.js +0 -32
  84. package/dist-cli/protocol/messages/hostToSandbox.d.ts +0 -4385
  85. package/dist-cli/protocol/messages/hostToSandbox.js +0 -48
  86. package/dist-cli/protocol/messages/incomingType.d.ts +0 -9
  87. package/dist-cli/protocol/messages/incomingType.js +0 -17
  88. package/dist-cli/protocol/messages/init.d.ts +0 -273
  89. package/dist-cli/protocol/messages/init.js +0 -57
  90. package/dist-cli/protocol/messages/initResult.d.ts +0 -37
  91. package/dist-cli/protocol/messages/initResult.js +0 -29
  92. package/dist-cli/protocol/messages/invalidHostMessage.d.ts +0 -14
  93. package/dist-cli/protocol/messages/invalidHostMessage.js +0 -13
  94. package/dist-cli/protocol/messages/invalidSandboxMessage.d.ts +0 -14
  95. package/dist-cli/protocol/messages/invalidSandboxMessage.js +0 -13
  96. package/dist-cli/protocol/messages/isInitHandshakeMessage.d.ts +0 -4
  97. package/dist-cli/protocol/messages/isInitHandshakeMessage.js +0 -11
  98. package/dist-cli/protocol/messages/listUsers.d.ts +0 -52
  99. package/dist-cli/protocol/messages/listUsers.js +0 -33
  100. package/dist-cli/protocol/messages/messagePayload.d.ts +0 -19
  101. package/dist-cli/protocol/messages/messagePayload.js +0 -1
  102. package/dist-cli/protocol/messages/openExternalUrl.d.ts +0 -32
  103. package/dist-cli/protocol/messages/openExternalUrl.js +0 -26
  104. package/dist-cli/protocol/messages/openPage.d.ts +0 -38
  105. package/dist-cli/protocol/messages/openPage.js +0 -34
  106. package/dist-cli/protocol/messages/pageChanged.d.ts +0 -32
  107. package/dist-cli/protocol/messages/pageChanged.js +0 -9
  108. package/dist-cli/protocol/messages/parentChanged.d.ts +0 -26
  109. package/dist-cli/protocol/messages/parentChanged.js +0 -9
  110. package/dist-cli/protocol/messages/queryDataSource.d.ts +0 -1446
  111. package/dist-cli/protocol/messages/queryDataSource.js +0 -252
  112. package/dist-cli/protocol/messages/queryDataSourceResult.d.ts +0 -686
  113. package/dist-cli/protocol/messages/queryDataSourceResult.js +0 -44
  114. package/dist-cli/protocol/messages/resize.d.ts +0 -11
  115. package/dist-cli/protocol/messages/resize.js +0 -10
  116. package/dist-cli/protocol/messages/sandboxToHost.d.ts +0 -1091
  117. package/dist-cli/protocol/messages/sandboxToHost.js +0 -33
  118. package/dist-cli/protocol/messages/themeChanged.d.ts +0 -10
  119. package/dist-cli/protocol/messages/themeChanged.js +0 -10
  120. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.d.ts +0 -10
  121. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.js +0 -9
  122. package/dist-cli/protocol/messages/updatePage.d.ts +0 -271
  123. package/dist-cli/protocol/messages/updatePage.js +0 -23
  124. package/dist-cli/protocol/messages/updatePageResult.d.ts +0 -895
  125. package/dist-cli/protocol/messages/updatePageResult.js +0 -41
  126. package/dist-cli/protocol/pages/page.d.ts +0 -1422
  127. package/dist-cli/protocol/pages/page.js +0 -318
  128. package/dist-cli/protocol/parent.d.ts +0 -32
  129. package/dist-cli/protocol/parent.js +0 -13
  130. package/dist-cli/protocol/protocolVersion.d.ts +0 -8
  131. package/dist-cli/protocol/protocolVersion.js +0 -11
  132. package/dist-cli/protocol/theme.d.ts +0 -3
  133. package/dist-cli/protocol/theme.js +0 -2
  134. package/dist-cli/protocol/users/user.d.ts +0 -32
  135. package/dist-cli/protocol/users/user.js +0 -20
  136. package/dist-cli/shared/block-registry.js +0 -28
  137. package/dist-cli/shared/data-source.js +0 -22
  138. package/dist-cli/shared/runtime-config.js +0 -10
  139. package/dist-cli/shared/sample-data-source.js +0 -12
@@ -1,158 +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
- import { manifestSchema } from "../protocol/index.js";
17
- import * as v from "valibot";
18
- const workerBlockCapabilitySchema = v.object({
19
- _tag: v.literal("custom_block"),
20
- key: v.string(),
21
- config: v.object({
22
- source: v.object({
23
- type: v.string(),
24
- path: v.string(),
25
- command: v.optional(v.string()),
26
- output: v.optional(v.string()),
27
- }),
28
- manifest: manifestSchema,
29
- }),
30
- });
31
- const WORKER_MANIFEST_FILENAME = "worker_manifest.json";
32
- /**
33
- * Heuristic for the no-flag fallback: does `dir` look like a worker project?
34
- * True if it carries a worker deploy binding (`worker.json`/`workers.json`) or
35
- * depends on `@notionhq/workers`.
36
- */
37
- function looksLikeWorkerDir(dir) {
38
- if (existsSync(resolve(dir, "worker.json")) ||
39
- existsSync(resolve(dir, "workers.json"))) {
40
- return true;
41
- }
42
- const pkgPath = resolve(dir, "package.json");
43
- if (!existsSync(pkgPath)) {
44
- return false;
45
- }
46
- try {
47
- const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
48
- return Boolean(pkg.dependencies?.["@notionhq/workers"] ??
49
- pkg.devDependencies?.["@notionhq/workers"] ??
50
- pkg.dependencies?.["@notionhq/apps"] ??
51
- pkg.devDependencies?.["@notionhq/apps"]);
52
- }
53
- catch {
54
- return false;
55
- }
56
- }
57
- /**
58
- * Walk up from `startDir` looking for a worker directory (see
59
- * `looksLikeWorkerDir`), so the shell can be launched from anywhere inside a
60
- * worker, not only its root. Stops once it reaches a git-repo boundary (a
61
- * `.git` at the current level, checked after the worker test) or the filesystem
62
- * root — it should never escape the project the user is in.
63
- */
64
- export function findWorkerDir(startDir) {
65
- let current = resolve(startDir);
66
- while (true) {
67
- if (looksLikeWorkerDir(current)) {
68
- return current;
69
- }
70
- if (existsSync(resolve(current, ".git"))) {
71
- return undefined;
72
- }
73
- const parent = dirname(current);
74
- if (parent === current) {
75
- return undefined;
76
- }
77
- current = parent;
78
- }
79
- }
80
- /** The custom-block capabilities in a manifest, narrowed by `_tag`. */
81
- export function blockCapabilities(manifest) {
82
- return manifest.capabilities
83
- .filter(capability => capability._tag === "custom_block")
84
- .map(capability => v.parse(workerBlockCapabilitySchema, capability));
85
- }
86
- function isManifestShape(value) {
87
- return (typeof value === "object" &&
88
- value !== null &&
89
- Array.isArray(value.capabilities));
90
- }
91
- /**
92
- * Build the worker in `workerDir` and read its manifest off the built default
93
- * export. Mirrors the deploy path (build → read the built module) rather than
94
- * importing TypeScript source, so what the dev shell sees matches what a deploy
95
- * would produce.
96
- */
97
- async function extractWorkerManifest(workerDir, options = {}) {
98
- const root = resolve(workerDir);
99
- if (!existsSync(resolve(root, "package.json"))) {
100
- throw new Error(`No package.json found in worker directory: ${root}`);
101
- }
102
- if (options.build !== false) {
103
- execSync("npm run build", { cwd: root, stdio: "inherit" });
104
- }
105
- const pkg = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));
106
- if (pkg.dependencies?.["@notionhq/apps"] ||
107
- pkg.devDependencies?.["@notionhq/apps"]) {
108
- const raw = JSON.parse(readFileSync(resolve(root, "dist/manifest.json"), "utf8"));
109
- if (!isManifestShape(raw)) {
110
- throw new Error("Apps manifest has no capabilities array");
111
- }
112
- return {
113
- ...raw,
114
- databases: raw.databases ?? [],
115
- pacers: raw.pacers ?? [],
116
- capabilities: raw.capabilities.map(capability => ({
117
- ...capability,
118
- _tag: "type" in capability && typeof capability.type === "string"
119
- ? capability.type
120
- : capability._tag,
121
- })),
122
- };
123
- }
124
- const entry = resolve(root, "dist/index.js");
125
- if (!existsSync(entry)) {
126
- throw new Error(`Built worker entry not found at ${entry}. The worker's build must emit dist/index.js.`);
127
- }
128
- const mod = (await import(pathToFileURL(entry).href));
129
- const worker = mod.default;
130
- if (worker === undefined) {
131
- throw new Error(`Built worker at ${entry} has no default export.`);
132
- }
133
- // Read the built worker's manifest, falling back to a bare capabilities array
134
- // (per the localhost verification doc's `w.manifest || w.capabilities`).
135
- const raw = worker.manifest ?? worker.capabilities;
136
- if (isManifestShape(raw)) {
137
- // The shape check only guarantees `capabilities`; older manifests omit
138
- // the other arrays.
139
- return { ...raw, databases: raw.databases ?? [], pacers: raw.pacers ?? [] };
140
- }
141
- if (Array.isArray(raw)) {
142
- return { databases: [], pacers: [], capabilities: raw };
143
- }
144
- throw new Error(`Built worker at ${entry} exposed no usable manifest (expected .manifest or .capabilities).`);
145
- }
146
- /**
147
- * Extract the worker manifest and write it to `.dev-shell/worker_manifest.json`
148
- * inside the worker (a git-ignored dev shell artifact directory). Returns the parsed
149
- * manifest and the path written.
150
- */
151
- export async function generateWorkerManifest(workerDir, options = {}) {
152
- const manifest = await extractWorkerManifest(workerDir, options);
153
- const dir = resolve(workerDir, ".dev-shell");
154
- mkdirSync(dir, { recursive: true });
155
- const manifestPath = resolve(dir, WORKER_MANIFEST_FILENAME);
156
- writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
157
- return { manifest, manifestPath };
158
- }
@@ -1,4 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const notionContrastModeSchema: v.PicklistSchema<["standard", "high"], undefined>;
3
- export type NotionContrastMode = v.InferOutput<typeof notionContrastModeSchema>;
4
- export declare const DEFAULT_CONTRAST_MODE: NotionContrastMode;
@@ -1,3 +0,0 @@
1
- import * as v from "valibot";
2
- export const notionContrastModeSchema = v.picklist(["standard", "high"]);
3
- export const DEFAULT_CONTRAST_MODE = "standard";