@notionhq/custom-blocks 0.0.78 → 0.1.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.
Files changed (36) hide show
  1. package/HOST.md +9 -2
  2. package/README.md +4 -2
  3. package/dist/bridge/SandboxBridge.d.ts +1 -1
  4. package/dist/bridge/SandboxBridge.js +1 -1
  5. package/dist/bridge/messages/connect.d.ts +1 -1
  6. package/dist/bridge/messages/connect.d.ts.map +1 -1
  7. package/dist/bridge/messages/connect.js +2 -8
  8. package/dist/bridge/messages/sandboxToHost.d.ts +1 -1
  9. package/dist/host/createCustomBlockHost.d.ts +1 -1
  10. package/dist/host/createCustomBlockHost.d.ts.map +1 -1
  11. package/dist/host/createCustomBlockHost.js +17 -4
  12. package/dist/host/lifecycle/{ready.d.ts → protocolVersion.d.ts} +1 -1
  13. package/dist/host/lifecycle/protocolVersion.d.ts.map +1 -0
  14. package/dist/version.js +1 -1
  15. package/docs/data-sources.md +7 -5
  16. package/docs/vite-plugin.md +46 -0
  17. package/package.json +1 -2
  18. package/src/bridge/SandboxBridge.ts +1 -1
  19. package/src/bridge/messages/connect.ts +2 -9
  20. package/src/host/createCustomBlockHost.ts +25 -5
  21. package/bin/cli/attach.js +0 -180
  22. package/bin/cli/cli.js +0 -248
  23. package/bin/cli/create.js +0 -106
  24. package/bin/cli/datasources.js +0 -255
  25. package/bin/cli/deploy.js +0 -109
  26. package/bin/cli/ids.js +0 -13
  27. package/bin/cli/ntn.js +0 -95
  28. package/bin/cli/pullData.js +0 -76
  29. package/bin/cli/pullManifest.js +0 -158
  30. package/bin/cli/target.js +0 -95
  31. package/bin/src/bridge/dataSources/propertySchema.js +0 -148
  32. package/bin/src/bridge/manifest.js +0 -40
  33. package/dist/host/lifecycle/ready.d.ts.map +0 -1
  34. package/docs/manifest.md +0 -42
  35. /package/dist/host/lifecycle/{ready.js → protocolVersion.js} +0 -0
  36. /package/src/host/lifecycle/{ready.ts → protocolVersion.ts} +0 -0
@@ -1,148 +0,0 @@
1
- import * as v from "valibot";
2
- /**
3
- * Hex-token identifiers for Notion's named colors. Mirrors the public API's
4
- * `select.options[].color` enum
5
- * (https://developers.notion.com/reference/property-object#select).
6
- */
7
- export const notionPropertyColorSchema = v.picklist([
8
- "default",
9
- "gray",
10
- "brown",
11
- "orange",
12
- "yellow",
13
- "green",
14
- "blue",
15
- "purple",
16
- "pink",
17
- "red",
18
- "gray_background",
19
- "brown_background",
20
- "orange_background",
21
- "yellow_background",
22
- "green_background",
23
- "blue_background",
24
- "purple_background",
25
- "pink_background",
26
- "red_background",
27
- "default_background",
28
- ]);
29
- export const notionPropertyOptionSchema = v.object({
30
- id: v.string(),
31
- name: v.string(),
32
- color: v.optional(notionPropertyColorSchema),
33
- description: v.optional(v.string()),
34
- });
35
- export const notionStatusGroupSchema = v.object({
36
- id: v.string(),
37
- name: v.string(),
38
- color: v.optional(notionPropertyColorSchema),
39
- option_ids: v.array(v.string()),
40
- });
41
- export const notionDualPropertySchema = v.object({
42
- synced_property_id: v.string(),
43
- synced_property_name: v.string(),
44
- });
45
- const baseProp = v.object({
46
- name: v.string(),
47
- description: v.optional(v.string()),
48
- });
49
- /**
50
- * Every Notion property type the bridge speaks, in a single readable list.
51
- * Mirrors the Notion public API
52
- * [property object](https://developers.notion.com/reference/property-object)
53
- * type field. Internal-only types (`button`, `verification`,
54
- * `last_visited_time`, `location`) and the four built-ins (`created_time`,
55
- * `last_edited_time`, `created_by`, `last_edited_by`) are included under their
56
- * bridge-native names.
57
- */
58
- export const NOTION_PROPERTY_TYPES = [
59
- "title",
60
- "rich_text",
61
- "number",
62
- "checkbox",
63
- "url",
64
- "email",
65
- "phone_number",
66
- "select",
67
- "multi_select",
68
- "status",
69
- "date",
70
- "people",
71
- "files",
72
- "unique_id",
73
- "relation",
74
- "place",
75
- "formula",
76
- "rollup",
77
- "button",
78
- "verification",
79
- "last_visited_time",
80
- "location",
81
- "created_time",
82
- "last_edited_time",
83
- "created_by",
84
- "last_edited_by",
85
- ];
86
- export const notionPropertyTypeSchema = v.picklist(NOTION_PROPERTY_TYPES);
87
- /**
88
- * Per-property schema as exposed by the host over the custom-block bridge.
89
- * The `type` discriminator must be one of {@link NOTION_PROPERTY_TYPES}.
90
- */
91
- export const notionPropertySchemaSchema = v.variant("type", [
92
- v.object({ ...baseProp.entries, type: v.literal("title") }),
93
- v.object({ ...baseProp.entries, type: v.literal("rich_text") }),
94
- v.object({ ...baseProp.entries, type: v.literal("number") }),
95
- v.object({ ...baseProp.entries, type: v.literal("checkbox") }),
96
- v.object({ ...baseProp.entries, type: v.literal("url") }),
97
- v.object({ ...baseProp.entries, type: v.literal("email") }),
98
- v.object({ ...baseProp.entries, type: v.literal("phone_number") }),
99
- v.object({
100
- ...baseProp.entries,
101
- type: v.literal("select"),
102
- options: v.array(notionPropertyOptionSchema),
103
- }),
104
- v.object({
105
- ...baseProp.entries,
106
- type: v.literal("multi_select"),
107
- options: v.array(notionPropertyOptionSchema),
108
- }),
109
- v.object({
110
- ...baseProp.entries,
111
- type: v.literal("status"),
112
- options: v.array(notionPropertyOptionSchema),
113
- groups: v.array(notionStatusGroupSchema),
114
- }),
115
- v.object({ ...baseProp.entries, type: v.literal("date") }),
116
- v.object({ ...baseProp.entries, type: v.literal("people") }),
117
- v.object({ ...baseProp.entries, type: v.literal("files") }),
118
- v.object({ ...baseProp.entries, type: v.literal("unique_id") }),
119
- v.object({
120
- ...baseProp.entries,
121
- type: v.literal("relation"),
122
- data_source_id: v.optional(v.string()),
123
- dual_property: v.optional(notionDualPropertySchema),
124
- }),
125
- v.object({ ...baseProp.entries, type: v.literal("place") }),
126
- v.object({ ...baseProp.entries, type: v.literal("formula") }),
127
- v.object({ ...baseProp.entries, type: v.literal("rollup") }),
128
- // Internal-only types passed through under their bridge-native names.
129
- v.object({ ...baseProp.entries, type: v.literal("button") }),
130
- v.object({ ...baseProp.entries, type: v.literal("verification") }),
131
- v.object({ ...baseProp.entries, type: v.literal("last_visited_time") }),
132
- v.object({ ...baseProp.entries, type: v.literal("location") }),
133
- // Synthetic built-ins. The host always emits one of each per data source.
134
- v.object({ ...baseProp.entries, type: v.literal("created_time") }),
135
- v.object({ ...baseProp.entries, type: v.literal("last_edited_time") }),
136
- v.object({ ...baseProp.entries, type: v.literal("created_by") }),
137
- v.object({ ...baseProp.entries, type: v.literal("last_edited_by") }),
138
- ]);
139
- /**
140
- * The four synthetic built-in property IDs the host always includes in every
141
- * data source's `propertySchemasById` and every row's `propertiesById`.
142
- */
143
- export const NOTION_BUILTIN_PROPERTY_IDS = [
144
- "created_time",
145
- "last_edited_time",
146
- "created_by",
147
- "last_edited_by",
148
- ];
@@ -1,40 +0,0 @@
1
- import * as v from "valibot";
2
- import { notionPropertyTypeSchema } from "./dataSources/propertySchema.js";
3
- /**
4
- * User-authored manifest declaring the data sources the custom block expects.
5
- * Lives at `custom_blocks.json` in the project root. The sandbox may send it in
6
- * `connect`, and the host returns the authoritative manifest in `init`. The
7
- * `notionCustomBlock` Vite plugin from
8
- * `@notionhq/custom-blocks/vite` wires the JSON file into the dev server and
9
- * the build output.
10
- */
11
- /**
12
- * Decorative icon attached to a manifest data source. Mirrors the
13
- * `emoji` / `external` icon variants the public Notion API uses, so the host
14
- * can render a recognizable affordance next to the slot in setup UI.
15
- */
16
- export const manifestIconSchema = v.variant("type", [
17
- v.object({
18
- type: v.literal("emoji"),
19
- emoji: v.string(),
20
- }),
21
- v.object({
22
- type: v.literal("external"),
23
- url: v.string(),
24
- }),
25
- ]);
26
- export const manifestPropertySchema = v.object({
27
- name: v.string(),
28
- description: v.optional(v.string()),
29
- type: notionPropertyTypeSchema,
30
- });
31
- export const manifestDataSourceSchema = v.object({
32
- name: v.string(),
33
- description: v.optional(v.string()),
34
- icon: v.optional(manifestIconSchema),
35
- properties: v.optional(v.record(v.string(), manifestPropertySchema), {}),
36
- });
37
- export const manifestSchema = v.object({
38
- version: v.literal(1),
39
- dataSources: v.record(v.string(), manifestDataSourceSchema),
40
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"ready.d.ts","sourceRoot":"","sources":["../../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/host/lifecycle/ready.ts"],"names":[],"mappings":"AAAA,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAErE"}
package/docs/manifest.md DELETED
@@ -1,42 +0,0 @@
1
- # Manifest
2
-
3
- A custom block declares its required data sources in `custom_blocks.json` at the project root. Notion uses the manifest to know what semantic keys the block expects, what shape each property should be, and what to show when an admin is configuring the block.
4
-
5
- ```json
6
- {
7
- "version": 1,
8
- "dataSources": {
9
- "tasks": {
10
- "name": "Tasks",
11
- "description": "The collection of tasks to render",
12
- "properties": {
13
- "title": { "name": "Title", "type": "title" },
14
- "dueDate": { "name": "Due date", "type": "date" }
15
- }
16
- }
17
- }
18
- }
19
- ```
20
-
21
- `initCustomBlock()` fetches the manifest and forwards it with `connect`. The `notionCustomBlock()` Vite plugin from `@notionhq/custom-blocks/vite` serves it in dev and emits it into `dist/` on build. If the file is missing, the SDK omits `manifest` from `connect`. If the file is unavailable for another reason or invalid, the SDK sends `connect` with `status: "error"` and an `error` payload. The host returns its authoritative manifest in `init`. The SDK uses that manifest even when it differs from the manifest sent in `connect`.
22
-
23
- ## Vite plugin
24
-
25
- ```ts
26
- import { defineConfig } from "vite";
27
- import react from "@vitejs/plugin-react";
28
- import { notionCustomBlock } from "@notionhq/custom-blocks/vite";
29
-
30
- export default defineConfig({
31
- plugins: [react(), notionCustomBlock()],
32
- });
33
- ```
34
-
35
- In dev, the plugin serves `custom_blocks.json` from the project root so HMR + the SDK handshake see the same file. On `vite build`, it emits `custom_blocks.json` into `dist/` as a separate asset alongside the bundled HTML and JS.
36
-
37
- ## Types
38
-
39
- - `CustomBlockManifest` — the parsed shape of `custom_blocks.json`.
40
- - `ManifestDataSource` — a single entry in `dataSources` (name, description, properties).
41
- - `ManifestProperty` — a single property declaration inside a `ManifestDataSource`.
42
- - `ManifestIcon` — the icon variant accepted on a `ManifestDataSource`.