create-ncblock 0.0.38 → 0.0.40
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/package.json +1 -1
- package/scripts/utils/templates.ts +37 -7
- package/sdk-version.json +1 -1
- package/templates/worker/.agents/INSTRUCTIONS.md +536 -0
- package/templates/worker/.agents/skills/auth-guide/SKILL.md +227 -0
- package/templates/worker/.agents/skills/sync/SKILL.md +368 -0
- package/templates/worker/.agents/skills/sync-debug/SKILL.md +101 -0
- package/templates/worker/.agents/skills/sync-guide/SKILL.md +253 -0
- package/templates/worker/.agents/skills/sync-guide/api-pagination-patterns.md +661 -0
- package/templates/worker/.agents/skills/sync-guide/examples/incremental-basic.ts +103 -0
- package/templates/worker/.agents/skills/sync-guide/examples/incremental-bimodal.ts +207 -0
- package/templates/worker/.agents/skills/sync-guide/examples/incremental-events.ts +132 -0
- package/templates/worker/.agents/skills/sync-guide/examples/replace-paginated.ts +79 -0
- package/templates/worker/.agents/skills/sync-guide/examples/replace-simple.ts +57 -0
- package/templates/worker/.agents/skills/sync-validate/SKILL.md +60 -0
- package/templates/worker/.claudeignore +2 -0
- package/templates/worker/.codexignore +2 -0
- package/templates/worker/.examples/automation-example.ts +60 -0
- package/templates/worker/.examples/oauth-example.ts +79 -0
- package/templates/worker/.examples/sync-example.ts +184 -0
- package/templates/worker/.examples/tool-example.ts +37 -0
- package/templates/worker/.examples/webhook-example.ts +66 -0
- package/templates/worker/README.md +765 -0
- package/templates/worker/_gitignore +6 -0
- package/templates/worker/docs/custom-tool.png +0 -0
- package/templates/worker/notionhq-workers-0.4.0.tgz +0 -0
- package/templates/worker/package.json +25 -0
- package/templates/worker/src/index.ts +8 -0
- package/templates/worker/tsconfig.json +16 -0
- package/templates/worker/views/empty/AGENTS.md +67 -0
- package/templates/worker/views/empty/README.md +10 -0
- package/templates/worker/views/empty/_gitignore +2 -0
- package/templates/worker/views/empty/custom_blocks.json +4 -0
- package/templates/worker/views/empty/index.html +15 -0
- package/templates/worker/views/empty/package.json +23 -0
- package/templates/worker/views/empty/src/index.css +33 -0
- package/templates/worker/views/empty/src/index.tsx +20 -0
- package/templates/worker/views/empty/tsconfig.json +17 -0
- package/templates/worker/views/empty/vite.config.ts +7 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@notionhq/workers-template",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc",
|
|
7
|
+
"check": "tsc --noEmit"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=22.0.0",
|
|
11
|
+
"npm": ">=10.9.2"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^22.9.0",
|
|
15
|
+
"tsx": "^4.20.6",
|
|
16
|
+
"typescript": "^5.8.0"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@notionhq/workers": "file:./notionhq-workers-0.4.0.tgz"
|
|
20
|
+
},
|
|
21
|
+
"notionCustomTemplate": {
|
|
22
|
+
"title": "Worker",
|
|
23
|
+
"description": "Notion Worker with sync, tool, automation, OAuth, and webhook capability examples."
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"moduleResolution": "nodenext"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"],
|
|
15
|
+
"exclude": ["node_modules", "dist"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# empty
|
|
2
|
+
|
|
3
|
+
A **Notion custom view** — a sandboxed `<iframe>` rendered inside a Notion block. The iframe is the entire viewport; the only channel to the host is a `postMessage` bridge wrapped by `ncblock`.
|
|
4
|
+
|
|
5
|
+
## Connecting to a Notion database
|
|
6
|
+
|
|
7
|
+
If `custom_blocks.json` or `.notion/target.json` doesn't yet reference a datasource, ask the user if they want to connect a database by url or id, then run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx ncblock connect <database-url-or-id>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
That writes `custom_blocks.json`, `.notion/target.json`, and PATCHes any blocks already listed there. Discover other commands with `npx ncblock --help`.
|
|
14
|
+
|
|
15
|
+
## Talking to the host
|
|
16
|
+
|
|
17
|
+
- Always use the React hooks from `ncblock`. Never call `window.parent.postMessage` directly — the SDK owns the protocol.
|
|
18
|
+
- Render app code inside `<NotionCustomBlock>` so the handshake completes before hooks like `useTheme` or `useCustomBlockContext` run.
|
|
19
|
+
|
|
20
|
+
Hooks at a glance:
|
|
21
|
+
|
|
22
|
+
- `useCustomBlockContext()` — `{ customBlockId, parent, page }`.
|
|
23
|
+
- `useTheme()` — `"light" | "dark"`.
|
|
24
|
+
- `useDataSource(key, initialLimit?)` — `{ items, isLoading, hasMore, fetchMore, error }`.
|
|
25
|
+
- `useManifest()` — the declared manifest: data-source keys plus their property declarations.
|
|
26
|
+
- `pages.create(input)` — creates a page; pass `parent: { type: "data_source_key", key }` to target the block's wired data source.
|
|
27
|
+
|
|
28
|
+
`<NotionCustomBlock>` runs `useCustomBlockAutoResize` for you by default — no extra wiring needed. Pass `autoResize={false}` for full-bleed views. Full signatures live in `node_modules/ncblock/docs/*.md` and the `.d.ts` files.
|
|
29
|
+
|
|
30
|
+
## Sizing
|
|
31
|
+
|
|
32
|
+
- The host owns width and height — no hard-coded widths. Layouts must reflow from a phone column to a desktop block.
|
|
33
|
+
- `100vh` ≠ a screen inside an iframe. Use intrinsic sizing with `min-height`.
|
|
34
|
+
- Use container queries (`@container`) — iframe width, not device width, is the real constraint.
|
|
35
|
+
|
|
36
|
+
## Forbidden APIs
|
|
37
|
+
|
|
38
|
+
- No top-level navigation, `window.open`, or auth redirects.
|
|
39
|
+
- No network requests. All data comes through host data sources.
|
|
40
|
+
|
|
41
|
+
## Conventions
|
|
42
|
+
|
|
43
|
+
- Mount into `<div id="root">` — `useCustomBlockAutoResize` looks for that exact id.
|
|
44
|
+
- `custom_blocks.json` at the project root defines the data contract. The SDK's Vite plugin serves it in dev; `ntn` bundles it into the deploy.
|
|
45
|
+
|
|
46
|
+
## Previewing during development
|
|
47
|
+
|
|
48
|
+
Two options:
|
|
49
|
+
|
|
50
|
+
1. **Live Notion host** — ask the user to create a block via `/custom` and paste the Vite dev URL (e.g. `http://localhost:5173`) into the block's URL field.
|
|
51
|
+
2. **Mock host** — run the dev shell in another tab:
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/makenotion/custom
|
|
54
|
+
cd custom && pnpm install && pnpm run dev:shell # http://localhost:9875
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Where to look next
|
|
58
|
+
|
|
59
|
+
- `node_modules/ncblock/README.md` — landing page with a TOC into the per-category docs below.
|
|
60
|
+
- `node_modules/ncblock/docs/lifecycle.md` — `<NotionCustomBlock>`, init, sizing, auto-resize.
|
|
61
|
+
- `node_modules/ncblock/docs/context.md` — `useCustomBlockContext`, `useTheme`.
|
|
62
|
+
- `node_modules/ncblock/docs/data-sources.md` — `useDataSource`, row/property/date types, worked example.
|
|
63
|
+
- `node_modules/ncblock/docs/pages.md` — `pages.create / get / update / delete`.
|
|
64
|
+
- `node_modules/ncblock/docs/users.md` — `users.list / get`, `NotionUser`.
|
|
65
|
+
- `node_modules/ncblock/docs/manifest.md` — `custom_blocks.json` + Vite plugin.
|
|
66
|
+
- `node_modules/ncblock/dist/*.d.ts` — typed surface; hover in your editor.
|
|
67
|
+
- https://github.com/makenotion/custom — source and examples.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<style>
|
|
7
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
8
|
+
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; }
|
|
9
|
+
</style>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
<script type="module" src="/src/index.tsx"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "empty",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"typecheck": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"ncblock": "^0.0.36",
|
|
13
|
+
"react": "^19.2.5",
|
|
14
|
+
"react-dom": "^19.2.5"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/react": "^19.2.14",
|
|
18
|
+
"@types/react-dom": "^19.2.3",
|
|
19
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
20
|
+
"typescript": "^6.0.3",
|
|
21
|
+
"vite": "^8.0.10"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: light dark;
|
|
3
|
+
--background: #ffffff;
|
|
4
|
+
--foreground: #1f1f1f;
|
|
5
|
+
--muted: #5f5e5b;
|
|
6
|
+
--border: #e6e6e6;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@media (prefers-color-scheme: dark) {
|
|
10
|
+
:root {
|
|
11
|
+
--background: #191919;
|
|
12
|
+
--foreground: #f1f1ef;
|
|
13
|
+
--muted: #b7b6b2;
|
|
14
|
+
--border: #3f3f3c;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
body {
|
|
19
|
+
background: var(--background);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main {
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
padding: 8px 24px;
|
|
25
|
+
border: 1px solid var(--border);
|
|
26
|
+
border-radius: 12px;
|
|
27
|
+
color: var(--foreground);
|
|
28
|
+
background: var(--background);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
p {
|
|
32
|
+
color: var(--muted);
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NotionCustomBlock } from "ncblock/react"
|
|
2
|
+
import ReactDOM from "react-dom/client"
|
|
3
|
+
import "./index.css"
|
|
4
|
+
|
|
5
|
+
function App() {
|
|
6
|
+
return (
|
|
7
|
+
<main>
|
|
8
|
+
<h3>empty</h3>
|
|
9
|
+
<p>
|
|
10
|
+
Edit <code>src/index.tsx</code> and then deploy using <code>ntn</code>
|
|
11
|
+
</p>
|
|
12
|
+
</main>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
17
|
+
<NotionCustomBlock>
|
|
18
|
+
<App />
|
|
19
|
+
</NotionCustomBlock>,
|
|
20
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noUnusedLocals": true,
|
|
8
|
+
"noUnusedParameters": true,
|
|
9
|
+
"types": ["vite/client"],
|
|
10
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"jsx": "react-jsx"
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "vite.config.ts"]
|
|
17
|
+
}
|