@notionhq/custom-blocks-dev-shell 0.2.0 → 0.3.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.
@@ -14,12 +14,13 @@ messages and target outgoing messages. `CustomBlockManifestSource` selects the m
14
14
  | `"host"` | The manifest returned by `getPersistedManifest({ signal })` |
15
15
  | `"sandbox"` | The local declaration supplied in `connect.manifest`, subject to the [local URL policy](#local-block-urls) |
16
16
 
17
- `getPersistedManifest` is required in both modes and starts when the host is created. It returns
18
- `CustomBlockHostManifestResult`: either `{ status: "success", manifest }` or
19
- `{ status: "error", error }`. It must not resolve to `null` or `undefined`. A definition that is
20
- still loading keeps the promise pending; a failed load returns an error result. The host validates
21
- the result and normalizes the manifest before calling `prepareInitialState`. Omitted `dataSources`
22
- and each source's omitted `properties` default to `{}`.
17
+ `getPersistedManifest` is required in both modes and starts when the host is created. It returns a
18
+ `CustomBlockHostHandlerResult` with either `{ status: "success", manifest }` or
19
+ `{ status: "error", error }`. The manifest follows `manifestSchema` from the protocol subpath. The
20
+ callback must not resolve to `null` or `undefined`. A definition that is still loading keeps the
21
+ promise pending; a failed load returns an error result. The host validates the result and normalizes
22
+ the manifest before reading the current user and source metadata. Omitted `dataSources` and each
23
+ source's omitted `properties` default to `{}`.
23
24
 
24
25
  The sandbox loads independently and sends `connect`. In sandbox mode, the SDK reads the manifest
25
26
  from JSON metadata injected into the local block HTML by dev tooling. The host validates the
@@ -28,18 +29,22 @@ determines initialization. Sandbox mode has no persisted fallback. The
28
29
  [wire reference](../../bridge/protocol.md#initialization) describes the declaration and its
29
30
  validation errors.
30
31
 
31
- Once the selected manifest is ready, the host calls `prepareInitialState({ manifest, signal })`
32
- once. Return `{ status: "success", initialState }` with context and data-source bindings, or
33
- `{ status: "error", error }`. This callback also must not resolve to `null` or `undefined`. The host
34
- validates its result. The prepared state omits the manifest; the host adds the selected manifest to
35
- `init`. Host-mode preparation runs concurrently with connection setup. Sandbox-mode preparation
36
- starts after `connect` supplies the declaration. The host sends `init` after preparation and a valid
37
- connection succeed. A preparation failure is retained until the sandbox connects.
32
+ Supply initial `theme`, `contrastMode`, `containingPage`, and `parent` as required constructor
33
+ options, using `null` for values that have not loaded yet. Set resolved values with the
34
+ corresponding setters. The shared host retains the latest values and waits for all four before
35
+ sending `init`. The wait counts toward `initialStateTimeoutMs` after `connect`. A containing-page
36
+ value of `{ type: "unavailable" }` means denied access, not loading. Once the selected manifest is
37
+ ready, the host reads the current user and source metadata through the handlers. The shared host
38
+ assembles and validates the existing init payload. See the [host contract](host-contract.md) for
39
+ handler results and cancellation. Host-mode preparation runs concurrently with connection setup.
40
+ Sandbox-mode preparation starts after `connect` supplies the declaration. The host sends `init`
41
+ after preparation and a valid connection succeed. A preparation failure is retained until the
42
+ sandbox connects.
38
43
 
39
44
  Errors from the selected manifest source retain their `code`, `message`, and `isRetryable`. A
40
45
  missing sandbox declaration produces `manifest_unavailable`. A sandbox `manifest_invalid` error is
41
46
  ignored in host mode because that mode uses the persisted manifest; other connect errors remain
42
- fatal. Unexpected exceptions or invalid results from either callback produce `unknown_error`.
47
+ fatal. Unexpected exceptions or invalid results during preparation produce `unknown_error`.
43
48
  Diagnostics go to `onLog("warn", payload)`. Stopping aborts preparation and suppresses late results
44
49
  without a cancellation warning.
45
50
 
@@ -52,27 +57,16 @@ without a cancellation warning.
52
57
  | `noInitResultTimeoutMs` | `initResult` after `init` | 5 seconds | `no_init_result` |
53
58
 
54
59
  The SDK waits for `init` without its own timeout. Handshake failures abort preparation and suppress
55
- late results. Manifest and state preparation providers must respect their `signal`.
60
+ late results. `getPersistedManifest`, `getCurrentUser`, and `getDataSource` must respect their
61
+ `signal`.
56
62
 
57
63
  ## Live state
58
64
 
59
- `setTheme()`, `setContrastMode()`, `setParent()`, `setPage()`, `setDataSources()`, and
60
- `setCurrentUser()` hold updates during initialization and send them after `initResult.success`. For
61
- data-source query refreshes, see [Handlers and data](handlers.md#refresh-active-queries).
62
-
63
- `setDataSources()` returns a synchronous `CustomBlockHostSetDataSourcesResult`. Success means local
64
- acceptance only; it does not guarantee sandbox delivery or successful initialization. Existing
65
- callers can ignore the return value. Malformed bindings can throw during schema parsing.
66
-
67
- - `{ status: "success" }`: accepts the bindings into local state.
68
- - `{ status: "error", error: { code, message, isRetryable } }`: logs a warning, keeps the last
69
- accepted bindings and pending update, and sends no update. Codes are
70
- `missing_data_source_binding`, `missing_property_binding`, and `invalid_property_binding`. All
71
- have `isRetryable: false`; correct the bindings before resubmitting.
72
-
73
- Pre-connect updates are checked against the selected manifest during initialization. Later updates
74
- are validated once that manifest is available. Accepted updates wait for `initResult.success` before
75
- sending; after failed initialization, they only change local state and do not restart it.
65
+ `setTheme()`, `setContrastMode()`, `setParent()`, and `setContainingPage()` hold updates during
66
+ initialization and send them after `initResult.success`. Use `setBindings()` and
67
+ `refreshDataSource()` to refresh source configuration. Each host instance belongs to one viewer.
68
+ Stop it and create a fresh host and iframe when the viewer changes. See
69
+ [updates](host-contract.md#updates) for their results and cancellation behavior.
76
70
 
77
71
  ## Callbacks
78
72
 
@@ -88,7 +82,7 @@ The required `onStatusChange(state)` callback receives the `CustomBlockHostStatu
88
82
  | `stopped` | The application explicitly disposed of the host | None |
89
83
 
90
84
  `localManifest` is optional and comes only from a permitted local sandbox. It is available before
91
- initialization completes, so an adapter can use its requirements to prepare bindings.
85
+ initialization completes, so the application can use its requirements to prepare bindings.
92
86
  `resolvedManifest` is the selected declaration sent in `init`. Rejected connections can skip
93
87
  intermediate statuses. Both `failed` and `stopped` are terminal; stopping a failed host releases
94
88
  resources without replacing its failure status.
@@ -101,10 +95,7 @@ At `initialized`, apply a supplied `initialHeight` in CSS pixels before revealin
101
95
  height is absent, use your application's default size. The `resize` handler applies later height
102
96
  changes. Reveal, sizing, and failure UI belong to the embedding application.
103
97
 
104
- | Other callback | Behavior |
105
- | ------------------------------------- | -------------------------------------------------------------------------------------------- |
106
- | `onQueryUnsubscribed(subscriptionId)` | Runs once when a subscription ends through unsubscribe, replacement, terminal error, or stop |
107
- | `onLog(direction, payload)` | Receives bridge messages and warnings |
98
+ The optional `onLog(direction, payload)` callback receives bridge messages and warnings.
108
99
 
109
100
  ## Iframe lifetime
110
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-dev-shell",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Local development shell for Notion custom block workers.",
5
5
  "license": "MIT",
6
6
  "type": "module",