create-ncblock 0.0.39 → 0.0.41

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 (40) hide show
  1. package/package.json +1 -1
  2. package/scripts/init.ts +39 -23
  3. package/scripts/utils/templates.ts +53 -8
  4. package/sdk-version.json +1 -1
  5. package/templates/worker/.agents/INSTRUCTIONS.md +593 -0
  6. package/templates/worker/.agents/skills/auth-guide/SKILL.md +227 -0
  7. package/templates/worker/.agents/skills/sync/SKILL.md +368 -0
  8. package/templates/worker/.agents/skills/sync-debug/SKILL.md +101 -0
  9. package/templates/worker/.agents/skills/sync-guide/SKILL.md +253 -0
  10. package/templates/worker/.agents/skills/sync-guide/api-pagination-patterns.md +661 -0
  11. package/templates/worker/.agents/skills/sync-guide/examples/incremental-basic.ts +103 -0
  12. package/templates/worker/.agents/skills/sync-guide/examples/incremental-bimodal.ts +207 -0
  13. package/templates/worker/.agents/skills/sync-guide/examples/incremental-events.ts +132 -0
  14. package/templates/worker/.agents/skills/sync-guide/examples/replace-paginated.ts +79 -0
  15. package/templates/worker/.agents/skills/sync-guide/examples/replace-simple.ts +57 -0
  16. package/templates/worker/.agents/skills/sync-validate/SKILL.md +60 -0
  17. package/templates/worker/.claudeignore +2 -0
  18. package/templates/worker/.codexignore +2 -0
  19. package/templates/worker/.examples/automation-example.ts +60 -0
  20. package/templates/worker/.examples/oauth-example.ts +79 -0
  21. package/templates/worker/.examples/sync-example.ts +184 -0
  22. package/templates/worker/.examples/tool-example.ts +37 -0
  23. package/templates/worker/.examples/webhook-example.ts +66 -0
  24. package/templates/worker/README.md +765 -0
  25. package/templates/worker/_gitignore +6 -0
  26. package/templates/worker/docs/custom-tool.png +0 -0
  27. package/templates/worker/notionhq-workers-0.4.0.tgz +0 -0
  28. package/templates/worker/package.json +25 -0
  29. package/templates/worker/src/index.ts +8 -0
  30. package/templates/worker/tsconfig.json +16 -0
  31. package/templates/worker/views/empty/AGENTS.md +71 -0
  32. package/templates/worker/views/empty/README.md +10 -0
  33. package/templates/worker/views/empty/_gitignore +2 -0
  34. package/templates/worker/views/empty/custom_blocks.json +4 -0
  35. package/templates/worker/views/empty/index.html +15 -0
  36. package/templates/worker/views/empty/package.json +23 -0
  37. package/templates/worker/views/empty/src/index.css +33 -0
  38. package/templates/worker/views/empty/src/index.tsx +20 -0
  39. package/templates/worker/views/empty/tsconfig.json +17 -0
  40. package/templates/worker/views/empty/vite.config.ts +7 -0
@@ -0,0 +1,6 @@
1
+ .env
2
+ .env.*
3
+ dist/
4
+ node_modules/
5
+ workers.*.json
6
+ workers.json
@@ -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,8 @@
1
+ import { Worker } from "@notionhq/workers"
2
+
3
+ const worker = new Worker()
4
+ export default worker
5
+
6
+ worker.customBlock("empty", {
7
+ path: "./views/empty",
8
+ })
@@ -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,71 @@
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
+ This view ships as part of a **worker**: it is declared with `worker.customBlock("empty", { path: "./views/empty" })` in the worker's `src/index.ts`, and it builds and deploys together with the worker via `ntn workers deploy`. There is **no separate `ncblock` CLI step** — do not run `npx ncblock connect` / `deploy`. This file covers how to author the view; for how the worker wires and deploys it, see the worker's `AGENTS.md` ("Custom blocks (views)").
6
+
7
+ ## Data sources
8
+
9
+ This view reads data from **managed databases declared in the worker**, not from a database you connect here. Wiring happens in the worker's `src/index.ts`:
10
+
11
+ 1. Declare a database with `worker.database(...)`.
12
+ 2. Bind it in the `dataSources` map of `worker.customBlock("empty", { path, dataSources: { <viewKey>: <databaseKey> } })`.
13
+
14
+ The worker generates this view's `custom_blocks.json` from that declaration on deploy, so don't hand-edit it (or run `ncblock connect`) — those changes are ignored. Inside the view, read a bound data source with `useDataSource(<viewKey>)`.
15
+
16
+ ## Talking to the host
17
+
18
+ - Always use the React hooks from `ncblock/react`. Never call `window.parent.postMessage` directly — the SDK owns the protocol.
19
+ - Render app code inside `<NotionCustomBlock>` so the handshake completes before hooks like `useTheme` or `useBlockId` run.
20
+
21
+ `<NotionCustomBlock>` runs `useCustomBlockAutoResize` for you by default — no extra wiring needed. Pass `autoResize={false}` for full-bleed views. Read `node_modules/ncblock/README.md` and the `.d.ts` files for current APIs and signatures.
22
+
23
+ ## Sizing
24
+
25
+ - The host owns width and height — no hard-coded widths. Layouts must reflow from a phone column to a desktop block.
26
+ - `100vh` ≠ a screen inside an iframe. Use intrinsic sizing with `min-height`.
27
+ - Use container queries (`@container`) — iframe width, not device width, is the real constraint.
28
+
29
+ ## Forbidden APIs
30
+
31
+ - No top-level navigation, `window.open`, or auth redirects.
32
+ - No network requests. All data comes through host data sources.
33
+
34
+ ## Conventions
35
+
36
+ - Mount into `<div id="root">` — `useCustomBlockAutoResize` looks for that exact id.
37
+ - `custom_blocks.json` is the data contract. The SDK's Vite plugin serves it in dev; in a worker it is **generated** from the worker's `worker.customBlock(...)` declaration at deploy time.
38
+
39
+ ## Previewing during development
40
+
41
+ Run the Vite dev server from this view's directory:
42
+
43
+ ```bash
44
+ npm run dev # http://localhost:5173
45
+ ```
46
+
47
+ Then preview against a host:
48
+
49
+ 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.
50
+ 2. **Mock host** — run the dev shell in another tab:
51
+ ```bash
52
+ git clone https://github.com/makenotion/custom
53
+ cd custom && pnpm install && pnpm run dev:shell # http://localhost:9875
54
+ ```
55
+
56
+ When the view is ready, deploy it with the worker from the worker root:
57
+
58
+ ```bash
59
+ ntn workers deploy
60
+ ```
61
+
62
+ ## Where to look next
63
+
64
+ - `node_modules/ncblock/README.md` — landing page with a TOC into the per-category docs below.
65
+ - `node_modules/ncblock/docs/lifecycle.md` — `<NotionCustomBlock>`, init, sizing, auto-resize.
66
+ - `node_modules/ncblock/docs/block-location.md` — `useBlockId`, `useParent`, `usePage`, `useTheme`.
67
+ - `node_modules/ncblock/docs/data-sources.md` — `useDataSource`, row/property/date types, worked example.
68
+ - `node_modules/ncblock/docs/pages.md` — `pages.create / get / update / delete`.
69
+ - `node_modules/ncblock/docs/users.md` — `users.list / get`, `NotionUser`.
70
+ - `node_modules/ncblock/docs/manifest.md` — `custom_blocks.json` + Vite plugin.
71
+ - https://github.com/makenotion/custom — source and examples.
@@ -0,0 +1,10 @@
1
+ # empty
2
+
3
+ Sandbox template for iterating on the SDK's minimal React entry API. Renders a single heading and nothing else.
4
+
5
+ ## Development
6
+
7
+ ```bash
8
+ npm run dev # Start Vite dev server
9
+ npm run build # Build to dist/
10
+ ```
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": 1,
3
+ "dataSources": {}
4
+ }
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ import react from "@vitejs/plugin-react"
2
+ import { notionCustomBlock } from "ncblock/vite"
3
+ import { defineConfig } from "vite"
4
+
5
+ export default defineConfig({
6
+ plugins: [react(), notionCustomBlock()],
7
+ })