ncblock 0.0.4 → 0.0.5
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/HOST.md +68 -0
- package/bridge/SandboxBridge.ts +659 -0
- package/bridge/context.ts +58 -0
- package/bridge/dataSources/dataSource.ts +63 -0
- package/bridge/dataSources/dataSourcePage.ts +69 -0
- package/bridge/dataSources/dataSourceValue.ts +19 -0
- package/bridge/dataSources/dateValue.ts +96 -0
- package/bridge/dataSources/propertySchema.ts +186 -0
- package/bridge/dataSources/recordPointer.ts +13 -0
- package/bridge/dataSources/resolve.ts +96 -0
- package/bridge/dataSources/resolveProperty.ts +96 -0
- package/bridge/hostState.ts +146 -0
- package/bridge/ids.ts +30 -0
- package/bridge/incomingType.ts +19 -0
- package/bridge/loadManifest.ts +54 -0
- package/bridge/manifest.ts +53 -0
- package/bridge/messages/contextChanged.ts +15 -0
- package/bridge/messages/createPage.ts +64 -0
- package/bridge/messages/createPageResult.ts +25 -0
- package/bridge/messages/dataSourcesChanged.ts +18 -0
- package/bridge/messages/getPage.ts +32 -0
- package/bridge/messages/getUser.ts +32 -0
- package/bridge/messages/hostToSandbox.ts +33 -0
- package/bridge/messages/init.ts +20 -0
- package/bridge/messages/invalidHostMessage.ts +16 -0
- package/bridge/messages/invalidSandboxMessage.ts +18 -0
- package/bridge/messages/listUsers.ts +33 -0
- package/bridge/messages/queryDataSource.ts +16 -0
- package/bridge/messages/queryDataSourceResult.ts +18 -0
- package/bridge/messages/ready.ts +25 -0
- package/bridge/messages/resize.ts +13 -0
- package/bridge/messages/sandboxToHost.ts +30 -0
- package/bridge/messages/themeChanged.ts +15 -0
- package/bridge/messages/updatePage.ts +21 -0
- package/bridge/messages/updatePageResult.ts +24 -0
- package/bridge/pages/page.ts +314 -0
- package/bridge/pendingRequests.ts +28 -0
- package/bridge/sandboxClient.ts +112 -0
- package/bridge/theme.ts +5 -0
- package/bridge/users/user.ts +31 -0
- package/docs/context.md +45 -0
- package/docs/data-sources.md +161 -0
- package/docs/lifecycle.md +92 -0
- package/docs/manifest.md +42 -0
- package/docs/pages.md +143 -0
- package/docs/users.md +61 -0
- package/host.ts +67 -0
- package/index.ts +86 -0
- package/init.ts +92 -0
- package/package.json +15 -5
- package/react.tsx +418 -0
- package/types.ts +157 -0
- package/users.ts +26 -0
- package/utils.ts +13 -0
- package/vite-plugin/index.d.ts +46 -0
- package/vite-plugin/index.js +115 -0
package/HOST.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# ncblock/host
|
|
2
|
+
|
|
3
|
+
Host-side entrypoint. Use this when implementing the host end of the custom block bridge — the Notion app, the dev shell, tests, mocks, anything that talks to a sandboxed custom block over `postMessage`. Nothing here is meant for use inside a custom block and everything here should be considered a private API that may change without a version bump. That main API surface lives in `ncblock`.
|
|
4
|
+
|
|
5
|
+
Every export here is a thin re-export of an internal `bridge/*` module. Hosts validate inbound sandbox traffic against the same valibot schemas the SDK uses on the sandbox side, so both ends of the bridge agree on shape.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
parseNotionCustomBlockContext,
|
|
10
|
+
sandboxToHostMessageSchema,
|
|
11
|
+
type SandboxToHostMessage,
|
|
12
|
+
} from "ncblock/host";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Context
|
|
16
|
+
|
|
17
|
+
- `parseNotionCustomBlockContext(value)` — best-effort parser which returns `NotionCustomBlockContext | undefined`. Used by shells that ingest user-edited context JSON.
|
|
18
|
+
- `notionCustomBlockContextSchema` — the underlying valibot schema, for stricter integration.
|
|
19
|
+
|
|
20
|
+
## Data sources
|
|
21
|
+
|
|
22
|
+
Types:
|
|
23
|
+
|
|
24
|
+
- `NotionDataSourceBinding` — a single binding (collection pointer + schema + property mapping).
|
|
25
|
+
- `NotionDataSourceBindings` — keyed-by-semantic-key map of bindings, the shape carried in `init` and `dataSourcesChanged`.
|
|
26
|
+
- `NotionDataSourcePageBridge` — wire shape for a single page (raw property IDs in `propertiesById`). The SDK derives the consumer-facing `NotionDataSourcePage` from it.
|
|
27
|
+
|
|
28
|
+
Schemas:
|
|
29
|
+
|
|
30
|
+
- `notionDataSourceBindingSchema`
|
|
31
|
+
- `notionDataSourceBindingsSchema`
|
|
32
|
+
- `notionDataSourcePageBridgeSchema`
|
|
33
|
+
|
|
34
|
+
## Sandbox → host messages
|
|
35
|
+
|
|
36
|
+
Messages sent from the sandbox to the host.
|
|
37
|
+
|
|
38
|
+
Hosts parse these out of `window` `message` events. Each message ships as a `{ FooMessage, fooMessageSchema }` pair:
|
|
39
|
+
|
|
40
|
+
- `ReadyMessage` / `readyMessageSchema`
|
|
41
|
+
- `QueryDataSourceMessage` / `queryDataSourceMessageSchema`
|
|
42
|
+
- `CreatePageMessage` / `createPageMessageSchema`
|
|
43
|
+
- `GetPageMessage` / `getPageMessageSchema`
|
|
44
|
+
- `UpdatePageMessage` / `updatePageMessageSchema`
|
|
45
|
+
- `ResizeMessage` / `resizeMessageSchema`
|
|
46
|
+
- `InvalidHostMessage` / `invalidHostMessageSchema`
|
|
47
|
+
|
|
48
|
+
`SandboxToHostMessage` / `sandboxToHostMessageSchema` is the discriminated union over all of the above.
|
|
49
|
+
|
|
50
|
+
## Host → sandbox messages
|
|
51
|
+
|
|
52
|
+
Messages sent from the host to the sandbox. Follows the same `{ FooMessage, fooMessageSchema }` convention:
|
|
53
|
+
|
|
54
|
+
- `InitMessage` / `initMessageSchema`
|
|
55
|
+
- `ThemeChangedMessage` / `themeChangedMessageSchema`
|
|
56
|
+
- `ContextChangedMessage` / `contextChangedMessageSchema`
|
|
57
|
+
- `DataSourcesChangedMessage` / `dataSourcesChangedMessageSchema`
|
|
58
|
+
- `QueryDataSourceResultMessage` / `queryDataSourceResultMessageSchema`
|
|
59
|
+
- `CreatePageResultMessage` / `createPageResultMessageSchema`
|
|
60
|
+
- `GetPageResultMessage` / `getPageResultMessageSchema`
|
|
61
|
+
- `UpdatePageResultMessage` / `updatePageResultMessageSchema`
|
|
62
|
+
- `InvalidSandboxMessage` / `invalidSandboxMessageSchema`
|
|
63
|
+
|
|
64
|
+
`HostToSandboxMessage` / `hostToSandboxMessageSchema` is the discriminated union over all of the above.
|
|
65
|
+
|
|
66
|
+
## Utilities
|
|
67
|
+
|
|
68
|
+
- `readIncomingType(data)` — best-effort `string | undefined` lookup of the `type` field on an arbitrary `unknown` payload. Used after schema validation fails, so a host can still distinguish (and avoid NACK-looping on) `invalidHostMessage` and surface a useful reason in `invalidSandboxMessage`.
|