@notionhq/custom-blocks-dev-shell 0.4.4 → 0.6.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.
package/README.md CHANGED
@@ -58,8 +58,10 @@ Reordering requires CSS visual reading-order support.
58
58
  **View** uses full-page SDK context. It does not simulate custom-view SDK context.
59
59
 
60
60
  **Workspace** opens shared data sources, pages, and users while the block keeps running. Workspace
61
- edits and SDK writes stay in memory. See [reload behavior](#reload-behavior) for when records reset,
62
- and [bindings](docs/bindings.md) to connect sample data.
61
+ edits and SDK writes stay in memory. Each launcher run gives the mock **Current page** a new UUID.
62
+ That ID stays the same when you reload the browser or edit sample files. See
63
+ [reload behavior](#reload-behavior) for when records reset, and [bindings](docs/bindings.md) to
64
+ connect sample data.
63
65
 
64
66
  ### Startup details for automation
65
67
 
@@ -70,47 +72,105 @@ ntn workers customblocks dev -- --json
70
72
  npx @notionhq/custom-blocks-dev-shell --json
71
73
  ```
72
74
 
73
- After the shell and block servers start, the launcher emits one JSON line. Logs and errors go to
74
- stderr. Example output, formatted for readability:
75
+ The launcher reports the startup outcome as one JSON line on stdout. Logs and human-readable errors
76
+ go to stderr. Example `ready` record, formatted for readability:
75
77
 
76
78
  ```json
77
79
  {
78
80
  "event": "ready",
81
+ "version": 1,
79
82
  "shellUrl": "http://localhost:9875",
80
83
  "workerDir": "/absolute/path/to/worker",
81
- "devShellVersion": "0.1.115",
84
+ "devShellVersion": "0.4.4",
85
+ "workerManifestPath": ".dev-shell/run-a1b2c3/worker_manifest.json",
82
86
  "customBlocks": [
83
87
  {
84
88
  "key": "task-board",
85
89
  "url": "http://task-board.localhost:9875/",
86
- "manifest": {
87
- "version": 1,
88
- "dataSources": {}
89
- },
90
- "sampleFilesByDataSource": {}
90
+ "bindings": {
91
+ "dataSources": {
92
+ "tasks": {
93
+ "status": "complete",
94
+ "sampleFile": "data/worker_tasks.json",
95
+ "propertyIdsByKey": { "title": "task_name" }
96
+ }
97
+ },
98
+ "pages": {
99
+ "brief": { "status": "complete", "selectedPageId": "launch-plan" },
100
+ "overview": { "status": "page_binding_missing" }
101
+ }
102
+ }
91
103
  }
92
104
  ]
93
105
  }
94
106
  ```
95
107
 
96
- URLs use the selected port and remain valid for the run. `workerDir` is absolute, and
97
- `devShellVersion` identifies the running package version. Each block includes its capability key,
98
- declared manifest, and selected sample files.
99
-
100
- `sampleFilesByDataSource` includes automatic selections and `--bind` overrides, with paths relative
101
- to `workerDir`. Slots without a selected file are omitted. The record is a startup snapshot, not a
102
- description of current browser property mappings. Later edits do not emit another record.
108
+ URLs use the selected port and remain valid for the run. `version` identifies the startup JSON
109
+ format, and `devShellVersion` identifies the running package version. Resolve `workerManifestPath`
110
+ and `sampleFile` relative to the absolute `workerDir`.
111
+
112
+ `workerManifestPath` points to the extracted worker manifest. The file can omit defaults the shell
113
+ applies, such as an empty `dataSources` map. Look up a block's capability key in `capabilities` to
114
+ find its `config.manifest`. Read the file during the run. The shell removes it when the run ends.
115
+
116
+ `bindings.dataSources` is keyed by the block's declared data source slots. It includes automatic
117
+ selections, `--bind-data-source` and `--bind-property` overrides, and unbound slots.
118
+ `bindings.pages` lists the block's declared page slots. A slot reports `complete` and includes
119
+ `selectedPageId` when its selected row is available at startup. Otherwise it reports
120
+ `page_binding_missing`. Blocks with no declared page slots omit `pages`.
121
+
122
+ | Status | Meaning | Additional fields |
123
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
124
+ | `data_source_binding_missing` | The slot has no selected sample file. | |
125
+ | `data_source_load_failed` | The selected sample file failed to load or disappeared after `--bind-data-source` validation. | `sampleFile` and `message`. |
126
+ | `incomplete_property_bindings` | The sample file loaded, but at least one required property lacks a compatible binding. | `sampleFile`, `propertyIdsByKey`, and `propertyIssues`. |
127
+ | `complete` | The sample file loaded and every required property has a compatible binding. The file may have zero rows. | `sampleFile` and `propertyIdsByKey`. |
128
+
129
+ `propertyIdsByKey` maps declared property keys to the sample schema keys the shell selected. Each
130
+ entry in `propertyIssues` includes the declared `propertyKey` and its `expectedType`.
131
+
132
+ | Issue type | Meaning | Additional fields |
133
+ | ---------------------------- | ------------------------------------------------------------------------ | ------------------------------------- |
134
+ | `property_binding_missing` | No sample property matches the declared key or display name. | |
135
+ | `ambiguous_property_binding` | More than one compatible sample property matches by key or display name. | `candidateSampleKeys`. |
136
+ | `sample_key_not_found` | The explicitly selected sample key is absent from the sample schema. | `sampleKey`. |
137
+ | `property_type_mismatch` | The explicit selection or every automatic match has the wrong type. | `bindingMode` and `sampleProperties`. |
138
+
139
+ For `property_type_mismatch`, `bindingMode` is `explicit` for a `--bind-property` selection and
140
+ `automatic` for automatic matching. Each entry in `sampleProperties` includes `sampleKey` and
141
+ `actualType`. An explicit mismatch lists the selected property. An automatic mismatch lists all
142
+ properties that matched by key or display name.
143
+
144
+ Loaded sources include `errors` when sample values are invalid. Each error identifies the sample
145
+ column in `propertyId` and the affected rows in `rowIds`. A mapped column with values of the wrong
146
+ type reports `invalid_property_value` and includes `expectedType`. An unmapped column with an
147
+ unsupported value reports `unsupported_property_value`. The binding status still describes whether
148
+ the required properties have compatible mappings.
149
+
150
+ The record describes the initial bindings. Later edits in the shell do not emit another record.
103
151
 
104
152
  Read the record without waiting for process exit. `ready` confirms that the shell and every block
105
153
  URL returned HTTP 2xx. It does not confirm block rendering, data access, or complete bindings. The
106
- checks allow 10 seconds after server setup. On timeout, stderr names the URLs that did not respond
107
- successfully, and the process exits nonzero without a ready record.
154
+ checks allow 10 seconds after server setup.
155
+
156
+ If the launcher encounters an error before `ready`, it emits a `startup_failed` record and exits
157
+ nonzero. The record includes `version` and `error` with a machine-readable `code` and a
158
+ human-readable `message`.
159
+
160
+ | Code | Meaning |
161
+ | --------------------------- | --------------------------------------------------------------------------------------------------- |
162
+ | `invalid_arguments` | The launcher could not parse the command line arguments. |
163
+ | `preview_readiness_timeout` | One or more preview URLs did not return HTTP 2xx before the deadline. The message lists those URLs. |
164
+ | `startup_error` | The launcher encountered another startup error, such as a failed worker build. |
165
+
166
+ Invalid `--bind-data-source`, `--bind-property`, and `--bind-page` values use the
167
+ [binding error codes](docs/bindings.md#binding-errors).
108
168
 
109
169
  ### Options
110
170
 
111
171
  ```bash
112
172
  ntn workers customblocks dev -- \
113
- --bind task-board.tasks=sample_tasks.json \
173
+ --bind-data-source task-board.tasks=sample_tasks.json \
114
174
  --bind-property task-board.tasks.title=task_name
115
175
  ```
116
176
 
@@ -122,11 +182,13 @@ The `--` separator is required to forward options through `ntn`. Omit it when ru
122
182
  [startup details for automation](#startup-details-for-automation).
123
183
  - `--port <port>`: Require this port for the whole run. If occupied, the command fails with an
124
184
  explanation. Omit this option to enable automatic fallback.
125
- - `--bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>`: Choose sample data. Repeat for
126
- multiple slots.
185
+ - `--bind-data-source <capabilityKey>.<dataSourceKey>=<sampleDataFileName>`: Choose sample data.
186
+ Repeat for multiple slots.
127
187
  - `--bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>`: Map a block
128
188
  property to a sample schema property. Repeat for multiple properties. Explicit mappings override
129
189
  automatic matches.
190
+ - `--bind-page <capabilityKey>.<pageKey>=<pageId>`: Preselect a loaded sample row in **Page
191
+ access**. Repeat for multiple page slots.
130
192
 
131
193
  See [bindings](docs/bindings.md) for source selection and property mapping rules.
132
194
 
@@ -145,9 +207,9 @@ Block responses enforce a production-like content security policy (CSP) and send
145
207
 
146
208
  - **Blocked features:** Native form submission, browser workers, `<object>`, `<embed>`, web app
147
209
  manifests, and `<base>`.
148
- - **Scripts and styles:** Bundled scripts, inline scripts, and inline styles work. Scripts loaded
149
- from a CDN at runtime are blocked. WebAssembly compilation is allowed; JavaScript string
150
- evaluation remains blocked.
210
+ - **Scripts and styles:** Bundled scripts and inline styles work. The dev shell blocks scripts that
211
+ remain inline after Vite processes the HTML, scripts from external origins, and JavaScript string
212
+ evaluation. WebAssembly compilation is allowed.
151
213
  - **Media and fonts:** Notion-hosted media and Google Fonts use the same exceptions as production.
152
214
  - **External access:** Network requests and nested frames can use HTTPS origins declared in the
153
215
  block's `network.fetch` grants. Browser CORS checks still apply.
@@ -187,8 +249,8 @@ browser console for the CSP violation.
187
249
  - **Local origins:** Blocks and the shell use HTTP localhost origins instead of production HTTPS
188
250
  origins.
189
251
  - **Hot reload:** CSP permits the block's exact WebSocket host and port for Vite HMR.
190
- - **External access:** Production resolves approvals separately from the manifest. Depending on the
191
- approval flow, it can also allow origins from the workspace network allowlist.
252
+ - **External access:** Workspace-approved domains and viewer approvals decide which declared origins
253
+ a block can reach.
192
254
  - **Embedding hosts:** Any host may embed local blocks for now, including Notion apps in every
193
255
  environment.
194
256
  - **Parent navigation policy:** The shell does not apply production's parent navigation CSP. The
@@ -217,6 +279,9 @@ The dev shell provides a fixed set of sample users, with Ada Lovelace as the cur
217
279
  `getViewer()` identifies the viewer. `NotionUser` field reads and `listUsers()` use the same
218
280
  profiles. Block reloads and changes to sample data files preserve these user identities.
219
281
 
282
+ The mock host reads and observes sample profiles from the same user store. Email is included when
283
+ the block requests it.
284
+
220
285
  The built-in People data source contains directory pages that reference sample users. Adding,
221
286
  editing, or deleting a worker's People file does not change the sample users.
222
287
 
@@ -79,8 +79,7 @@
79
79
  "website": "https://example.com/organizations/westfield-learning-center",
80
80
  "email": "westfield-learning-center@example.com",
81
81
  "last_contacted": {
82
- "type": "date",
83
- "start_date": "2026-11-13"
82
+ "start": "2026-11-13"
84
83
  }
85
84
  },
86
85
  {
@@ -98,8 +97,7 @@
98
97
  "website": "https://example.com/organizations/fieldwork-press",
99
98
  "email": "fieldwork-press@example.com",
100
99
  "last_contacted": {
101
- "type": "date",
102
- "start_date": "2026-11-12"
100
+ "start": "2026-11-12"
103
101
  }
104
102
  },
105
103
  {
@@ -117,8 +115,7 @@
117
115
  "website": "https://example.com/organizations/riverside-workshop",
118
116
  "email": "riverside-workshop@example.com",
119
117
  "last_contacted": {
120
- "type": "date",
121
- "start_date": "2026-11-10"
118
+ "start": "2026-11-10"
122
119
  }
123
120
  },
124
121
  {
@@ -150,8 +147,7 @@
150
147
  "needs": "Keep reading room terminals connected when a network link fails. Staff need a clear way to identify the failed connection.",
151
148
  "website": "https://example.com/organizations/county-records-office",
152
149
  "last_contacted": {
153
- "type": "date",
154
- "start_date": "2026-11-16"
150
+ "start": "2026-11-16"
155
151
  }
156
152
  },
157
153
  {
@@ -169,8 +165,7 @@
169
165
  "website": "https://example.com/organizations/evening-computing-school",
170
166
  "email": "evening-computing-school@example.com",
171
167
  "last_contacted": {
172
- "type": "date",
173
- "start_date": "2026-11-09"
168
+ "start": "2026-11-09"
174
169
  }
175
170
  },
176
171
  {
@@ -188,8 +183,7 @@
188
183
  "website": "https://example.com/organizations/local-history-museum",
189
184
  "email": "local-history-museum@example.com",
190
185
  "last_contacted": {
191
- "type": "date",
192
- "start_date": "2026-11-11"
186
+ "start": "2026-11-11"
193
187
  }
194
188
  },
195
189
  {
@@ -216,8 +210,7 @@
216
210
  "website": "https://example.com/organizations/workshop-cooperative",
217
211
  "email": "workshop-cooperative@example.com",
218
212
  "last_contacted": {
219
- "type": "date",
220
- "start_date": "2026-11-18"
213
+ "start": "2026-11-18"
221
214
  }
222
215
  },
223
216
  {
@@ -234,8 +227,7 @@
234
227
  "needs": "Recover locally saved interview notes after an interrupted session. Keep the original recording references with the restored draft.",
235
228
  "website": "https://example.com/organizations/community-history-archive",
236
229
  "last_contacted": {
237
- "type": "date",
238
- "start_date": "2026-11-18"
230
+ "start": "2026-11-18"
239
231
  }
240
232
  },
241
233
  {
@@ -253,8 +245,7 @@
253
245
  "website": "https://example.com/organizations/parkside-arts-center",
254
246
  "email": "parkside-arts-center@example.com",
255
247
  "last_contacted": {
256
- "type": "date",
257
- "start_date": "2026-11-19"
248
+ "start": "2026-11-19"
258
249
  }
259
250
  },
260
251
  {
@@ -277,8 +268,7 @@
277
268
  "owner": [],
278
269
  "value": 0,
279
270
  "last_contacted": {
280
- "type": "date",
281
- "start_date": "2026-10-14"
271
+ "start": "2026-10-14"
282
272
  },
283
273
  "needs": ""
284
274
  }