@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.
- package/dist/assets/index-CWJ-vFk0.js +12 -0
- package/dist/index.html +1 -1
- package/dist-cli/cli/published-cli.js +158 -103
- package/docs/bridge/protocol.md +18 -17
- package/docs/data-sources.md +6 -4
- package/docs/host/README.md +54 -42
- package/docs/host/docs/handlers.md +36 -143
- package/docs/host/docs/host-contract.md +196 -0
- package/docs/host/docs/lifecycle.md +28 -37
- package/package.json +1 -1
- package/dist/assets/index-n0_PUieY.js +0 -11
|
@@ -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
|
-
`
|
|
19
|
-
`{ status: "error", error }`.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
and
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
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.
|
|
60
|
+
late results. `getPersistedManifest`, `getCurrentUser`, and `getDataSource` must respect their
|
|
61
|
+
`signal`.
|
|
56
62
|
|
|
57
63
|
## Live state
|
|
58
64
|
|
|
59
|
-
`setTheme()`, `setContrastMode()`, `setParent()`, `
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|