@catafal/notion-cli 5.9.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +552 -0
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +14 -0
  6. package/bin/run.cmd +3 -0
  7. package/dist/base-command.d.ts +73 -0
  8. package/dist/base-command.js +179 -0
  9. package/dist/base-flags.d.ts +14 -0
  10. package/dist/base-flags.js +59 -0
  11. package/dist/cache.d.ts +84 -0
  12. package/dist/cache.js +351 -0
  13. package/dist/commands/append.d.ts +37 -0
  14. package/dist/commands/append.js +120 -0
  15. package/dist/commands/batch/delete.d.ts +42 -0
  16. package/dist/commands/batch/delete.js +199 -0
  17. package/dist/commands/batch/retrieve.d.ts +43 -0
  18. package/dist/commands/batch/retrieve.js +272 -0
  19. package/dist/commands/block/append.d.ts +42 -0
  20. package/dist/commands/block/append.js +219 -0
  21. package/dist/commands/block/delete.d.ts +30 -0
  22. package/dist/commands/block/delete.js +97 -0
  23. package/dist/commands/block/retrieve/children.d.ts +31 -0
  24. package/dist/commands/block/retrieve/children.js +177 -0
  25. package/dist/commands/block/retrieve.d.ts +30 -0
  26. package/dist/commands/block/retrieve.js +101 -0
  27. package/dist/commands/block/update.d.ts +45 -0
  28. package/dist/commands/block/update.js +242 -0
  29. package/dist/commands/bookmark/list.d.ts +30 -0
  30. package/dist/commands/bookmark/list.js +60 -0
  31. package/dist/commands/bookmark/remove.d.ts +26 -0
  32. package/dist/commands/bookmark/remove.js +47 -0
  33. package/dist/commands/bookmark/set.d.ts +29 -0
  34. package/dist/commands/bookmark/set.js +96 -0
  35. package/dist/commands/browse.d.ts +13 -0
  36. package/dist/commands/browse.js +44 -0
  37. package/dist/commands/cache/info.d.ts +19 -0
  38. package/dist/commands/cache/info.js +145 -0
  39. package/dist/commands/config/set-token.d.ts +22 -0
  40. package/dist/commands/config/set-token.js +137 -0
  41. package/dist/commands/daily/index.d.ts +32 -0
  42. package/dist/commands/daily/index.js +135 -0
  43. package/dist/commands/daily/setup.d.ts +42 -0
  44. package/dist/commands/daily/setup.js +149 -0
  45. package/dist/commands/db/create.d.ts +31 -0
  46. package/dist/commands/db/create.js +124 -0
  47. package/dist/commands/db/query.d.ts +41 -0
  48. package/dist/commands/db/query.js +360 -0
  49. package/dist/commands/db/retrieve.d.ts +33 -0
  50. package/dist/commands/db/retrieve.js +134 -0
  51. package/dist/commands/db/schema.d.ts +32 -0
  52. package/dist/commands/db/schema.js +308 -0
  53. package/dist/commands/db/update.d.ts +31 -0
  54. package/dist/commands/db/update.js +117 -0
  55. package/dist/commands/doctor.d.ts +50 -0
  56. package/dist/commands/doctor.js +420 -0
  57. package/dist/commands/init.d.ts +65 -0
  58. package/dist/commands/init.js +479 -0
  59. package/dist/commands/list.d.ts +29 -0
  60. package/dist/commands/list.js +219 -0
  61. package/dist/commands/open.d.ts +29 -0
  62. package/dist/commands/open.js +100 -0
  63. package/dist/commands/page/create.d.ts +33 -0
  64. package/dist/commands/page/create.js +261 -0
  65. package/dist/commands/page/delete.d.ts +36 -0
  66. package/dist/commands/page/delete.js +107 -0
  67. package/dist/commands/page/export.d.ts +38 -0
  68. package/dist/commands/page/export.js +120 -0
  69. package/dist/commands/page/retrieve/property_item.d.ts +24 -0
  70. package/dist/commands/page/retrieve/property_item.js +75 -0
  71. package/dist/commands/page/retrieve.d.ts +36 -0
  72. package/dist/commands/page/retrieve.js +244 -0
  73. package/dist/commands/page/update.d.ts +34 -0
  74. package/dist/commands/page/update.js +184 -0
  75. package/dist/commands/quick.d.ts +35 -0
  76. package/dist/commands/quick.js +168 -0
  77. package/dist/commands/search.d.ts +43 -0
  78. package/dist/commands/search.js +361 -0
  79. package/dist/commands/stats.d.ts +35 -0
  80. package/dist/commands/stats.js +274 -0
  81. package/dist/commands/sync.d.ts +24 -0
  82. package/dist/commands/sync.js +183 -0
  83. package/dist/commands/template/get.d.ts +28 -0
  84. package/dist/commands/template/get.js +59 -0
  85. package/dist/commands/template/list.d.ts +32 -0
  86. package/dist/commands/template/list.js +62 -0
  87. package/dist/commands/template/remove.d.ts +27 -0
  88. package/dist/commands/template/remove.js +48 -0
  89. package/dist/commands/template/save.d.ts +32 -0
  90. package/dist/commands/template/save.js +92 -0
  91. package/dist/commands/template/use.d.ts +34 -0
  92. package/dist/commands/template/use.js +142 -0
  93. package/dist/commands/user/list.d.ts +27 -0
  94. package/dist/commands/user/list.js +99 -0
  95. package/dist/commands/user/retrieve/bot.d.ts +28 -0
  96. package/dist/commands/user/retrieve/bot.js +96 -0
  97. package/dist/commands/user/retrieve.d.ts +30 -0
  98. package/dist/commands/user/retrieve.js +103 -0
  99. package/dist/commands/whoami.d.ts +19 -0
  100. package/dist/commands/whoami.js +175 -0
  101. package/dist/deduplication.d.ts +41 -0
  102. package/dist/deduplication.js +71 -0
  103. package/dist/envelope.d.ts +169 -0
  104. package/dist/envelope.js +257 -0
  105. package/dist/errors/enhanced-errors.d.ts +168 -0
  106. package/dist/errors/enhanced-errors.js +567 -0
  107. package/dist/errors/index.d.ts +18 -0
  108. package/dist/errors/index.js +33 -0
  109. package/dist/examples/cache-retry-examples.d.ts +64 -0
  110. package/dist/examples/cache-retry-examples.js +375 -0
  111. package/dist/helper.d.ts +102 -0
  112. package/dist/helper.js +885 -0
  113. package/dist/http-agent.d.ts +38 -0
  114. package/dist/http-agent.js +60 -0
  115. package/dist/index.d.ts +1 -0
  116. package/dist/index.js +4 -0
  117. package/dist/interface.d.ts +4 -0
  118. package/dist/interface.js +2 -0
  119. package/dist/notion.d.ts +144 -0
  120. package/dist/notion.js +547 -0
  121. package/dist/retry.d.ts +72 -0
  122. package/dist/retry.js +381 -0
  123. package/dist/utils/bookmarks.d.ts +32 -0
  124. package/dist/utils/bookmarks.js +98 -0
  125. package/dist/utils/daily-config.d.ts +22 -0
  126. package/dist/utils/daily-config.js +60 -0
  127. package/dist/utils/disk-cache.d.ts +80 -0
  128. package/dist/utils/disk-cache.js +291 -0
  129. package/dist/utils/fuzzy.d.ts +36 -0
  130. package/dist/utils/fuzzy.js +69 -0
  131. package/dist/utils/interactive-navigator.d.ts +63 -0
  132. package/dist/utils/interactive-navigator.js +123 -0
  133. package/dist/utils/markdown-to-blocks.d.ts +21 -0
  134. package/dist/utils/markdown-to-blocks.js +333 -0
  135. package/dist/utils/notion-resolver.d.ts +49 -0
  136. package/dist/utils/notion-resolver.js +278 -0
  137. package/dist/utils/notion-url-parser.d.ts +48 -0
  138. package/dist/utils/notion-url-parser.js +121 -0
  139. package/dist/utils/property-expander.d.ts +45 -0
  140. package/dist/utils/property-expander.js +323 -0
  141. package/dist/utils/schema-examples.d.ts +40 -0
  142. package/dist/utils/schema-examples.js +359 -0
  143. package/dist/utils/schema-extractor.d.ts +65 -0
  144. package/dist/utils/schema-extractor.js +235 -0
  145. package/dist/utils/shell-config.d.ts +30 -0
  146. package/dist/utils/shell-config.js +84 -0
  147. package/dist/utils/table-formatter.d.ts +36 -0
  148. package/dist/utils/table-formatter.js +125 -0
  149. package/dist/utils/templates.d.ts +30 -0
  150. package/dist/utils/templates.js +82 -0
  151. package/dist/utils/terminal-banner.d.ts +24 -0
  152. package/dist/utils/terminal-banner.js +34 -0
  153. package/dist/utils/token-validator.d.ts +42 -0
  154. package/dist/utils/token-validator.js +66 -0
  155. package/dist/utils/update-notifier.d.ts +26 -0
  156. package/dist/utils/update-notifier.js +54 -0
  157. package/dist/utils/workspace-cache.d.ts +58 -0
  158. package/dist/utils/workspace-cache.js +185 -0
  159. package/oclif.manifest.json +6471 -0
  160. package/package.json +118 -0
  161. package/scripts/banner.js +38 -0
  162. package/scripts/postinstall.js +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Coastal Programs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,552 @@
1
+ <div align="center">
2
+ <pre>
3
+ ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗ ██████╗██╗ ██╗
4
+ ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ ██╔════╝██║ ██║
5
+ ██╔██╗ ██║██║ ██║ ██║ ██║██║ ██║██╔██╗ ██║ ██║ ██║ ██║
6
+ ██║╚██╗██║██║ ██║ ██║ ██║██║ ██║██║╚██╗██║ ██║ ██║ ██║
7
+ ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║ ╚██████╗███████╗██║
8
+ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═╝
9
+ </pre>
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/Catafal/notion-cli/actions/workflows/ci.yml">
13
+ <img src="https://github.com/Catafal/notion-cli/actions/workflows/ci.yml/badge.svg" alt="CI/CD Pipeline">
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@catafal/notion-cli">
16
+ <img src="https://img.shields.io/npm/v/@catafal/notion-cli.svg" alt="npm version">
17
+ </a>
18
+ <a href="https://nodejs.org">
19
+ <img src="https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen.svg" alt="Node.js Version">
20
+ </a>
21
+ <a href="https://github.com/Catafal/notion-cli/blob/main/LICENSE">
22
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
23
+ </a>
24
+ </p>
25
+ </div>
26
+
27
+ **IMPORTANT NOTICE:**
28
+
29
+ This is an independent, unofficial command-line tool for working with Notion's API.
30
+ This project is not affiliated with, endorsed by, or sponsored by Notion Labs, Inc.
31
+ "Notion" is a registered trademark of Notion Labs, Inc.
32
+
33
+ > Notion CLI for AI Agents & Automation
34
+
35
+ A powerful command-line interface for Notion's API, optimized for AI coding assistants and automation scripts.
36
+
37
+ **Key Features:**
38
+ - 🚀 **Fast & Direct**: Native API integration with intelligent caching
39
+ - 🤖 **AI-First Design**: JSON output, structured errors, exit codes
40
+ - ⚡ **Non-Interactive**: Perfect for scripts and automation
41
+ - 📊 **Flexible Output**: JSON, CSV, markdown tables, or raw API responses
42
+ - 🔍 **Schema Discovery**: AI-friendly database schema extraction
43
+ - 🗄️ **Workspace Caching**: Fast database lookups without API calls
44
+ - 🧠 **Smart ID Resolution**: Automatic database_id → data_source_id conversion
45
+ - 🔎 **Fuzzy Search**: Typo-tolerant name resolution and database filtering
46
+ - 🔄 **Reliable**: Automatic retry with exponential backoff and circuit breaker
47
+ - 🔒 **Secure**: 0 production vulnerabilities
48
+
49
+ See [CHANGELOG.md](./CHANGELOG.md) for version history and release notes.
50
+
51
+ ---
52
+
53
+ ## Quick Start
54
+
55
+ ### Installation
56
+
57
+ ```bash
58
+ # From npm (recommended)
59
+ npm install -g @catafal/notion-cli
60
+
61
+ # Or from source
62
+ npm install -g Catafal/notion-cli
63
+ ```
64
+
65
+ **Note**: Windows users installing from source should use the local clone method due to symlink limitations:
66
+ ```bash
67
+ git clone https://github.com/Catafal/notion-cli
68
+ cd notion-cli
69
+ npm install
70
+ npm run build
71
+ npm link
72
+ ```
73
+
74
+ ### First-Time Setup
75
+
76
+ ```bash
77
+ # Run the interactive setup wizard
78
+ notion-cli init
79
+ ```
80
+
81
+ This guides you through:
82
+ 1. Setting your Notion API token
83
+ 2. Testing the connection
84
+ 3. Syncing your workspace
85
+
86
+ **Manual setup** (if you prefer):
87
+ ```bash
88
+ # Both token formats are supported:
89
+ export NOTION_TOKEN="secret_your_token_here" # Internal integration token
90
+ export NOTION_TOKEN="ntn_your_token_here" # OAuth token (newer format)
91
+
92
+ notion-cli whoami # Test connection
93
+ notion-cli sync # Cache workspace
94
+ ```
95
+
96
+ **Get your API token**: https://developers.notion.com/docs/create-a-notion-integration
97
+
98
+ ### Common Commands
99
+
100
+ ```bash
101
+ # List your databases
102
+ notion-cli list --json
103
+
104
+ # Discover database schema
105
+ notion-cli db schema <DATA_SOURCE_ID> --with-examples --json
106
+
107
+ # Create a page (simple properties mode)
108
+ notion-cli page create -d <DATA_SOURCE_ID> -S --properties '{
109
+ "Name": "My Task",
110
+ "Status": "In Progress",
111
+ "Priority": 5,
112
+ "Due Date": "tomorrow"
113
+ }'
114
+
115
+ # Search workspace
116
+ notion-cli search "project" --json
117
+ ```
118
+
119
+ All commands support `--json` for machine-readable output.
120
+
121
+ ---
122
+
123
+ ## Key Features for AI Agents
124
+
125
+ ### Simple Properties — 70% Less Complexity
126
+
127
+ Use flat JSON instead of complex nested Notion API structures with the `-S` flag:
128
+
129
+ ```bash
130
+ # Simple properties with -S flag
131
+ notion-cli page create -d DB_ID -S --properties '{
132
+ "Name": "Task",
133
+ "Status": "In Progress",
134
+ "Priority": 5,
135
+ "Tags": ["urgent", "bug"],
136
+ "Due Date": "tomorrow"
137
+ }'
138
+
139
+ # Update is just as easy
140
+ notion-cli page update PAGE_ID -S --properties '{
141
+ "Status": "Done",
142
+ "Completed": true
143
+ }'
144
+ ```
145
+
146
+ Supports 13 property types, case-insensitive matching, and relative dates (`"today"`, `"+7 days"`, `"+2 weeks"`).
147
+
148
+ [📖 Simple Properties Guide](./docs/user-guides/simple-properties.md)
149
+
150
+ ### Smart Database ID Resolution
151
+
152
+ No need to worry about `database_id` vs `data_source_id` — the CLI auto-converts:
153
+
154
+ ```bash
155
+ # Both work! Use whichever ID you have
156
+ notion-cli db retrieve 1fb79d4c71bb8032b722c82305b63a00 # database_id
157
+ notion-cli db retrieve 2gc80e5d82cc9043c833d93416c74b11 # data_source_id
158
+ ```
159
+
160
+ [📖 Smart ID Resolution](./docs/architecture/smart-id-resolution.md)
161
+
162
+ ### JSON Mode — Perfect for AI Processing
163
+
164
+ Every command supports `--json` for structured, parseable output:
165
+
166
+ ```bash
167
+ notion-cli db query <ID> --json | jq '.data.results[].properties'
168
+ ```
169
+
170
+ Error responses are also structured JSON with exit codes (`0` = success, `1` = API error, `2` = CLI error).
171
+
172
+ ### Schema Discovery
173
+
174
+ Extract complete database schemas in AI-friendly formats:
175
+
176
+ ```bash
177
+ notion-cli db schema <DATA_SOURCE_ID> --with-examples --json
178
+ ```
179
+
180
+ ### Workspace Caching
181
+
182
+ Cache your workspace locally for instant lookups:
183
+
184
+ ```bash
185
+ notion-cli sync # One-time sync
186
+ notion-cli db query "Tasks Database" --json # Use names instead of IDs
187
+ notion-cli list --filter "tasks" # Fuzzy-filter cached databases
188
+ notion-cli cache:info --json # Check cache freshness
189
+ ```
190
+
191
+ ### Output Size Control
192
+
193
+ Reduce response size for large queries:
194
+
195
+ ```bash
196
+ notion-cli db query <ID> --minimal --compact-json --page-size 10
197
+ notion-cli db query <ID> --select "Name,Status" --minimal
198
+ NO_COLOR=1 notion-cli search "My Page" # Strip ANSI codes for clean parsing
199
+ ```
200
+
201
+ [📖 AI Agent Guide](./docs/user-guides/ai-agent-guide.md) | [📖 AI Agent Cookbook](./docs/user-guides/ai-agent-cookbook.md)
202
+
203
+ ---
204
+
205
+ ## Core Commands
206
+
207
+ ### Setup & Diagnostics
208
+
209
+ ```bash
210
+ notion-cli init # First-time setup wizard
211
+ notion-cli doctor # Health check and diagnostics (aliases: diagnose, healthcheck)
212
+ notion-cli whoami # Test connectivity (aliases: test, health)
213
+ ```
214
+
215
+ ### Database Commands
216
+
217
+ ```bash
218
+ notion-cli db retrieve <ID> # Get database metadata
219
+ notion-cli db query <ID> --json # Query with results
220
+ notion-cli db query <ID> --filter '{"property": "Status", "select": {"equals": "Done"}}' --json
221
+ notion-cli db schema <ID> --with-examples --json # Extract schema
222
+ notion-cli db update <ID> --title "New Title" # Update database
223
+ notion-cli db create --parent-page <PAGE_ID> --title "My DB" --properties '{...}'
224
+ ```
225
+
226
+ [📖 Filter Guide](./docs/user-guides/filter-guide.md)
227
+
228
+ ### Page Commands
229
+
230
+ ```bash
231
+ notion-cli page create -d <DB_ID> -S --properties '{...}' # Create in database
232
+ notion-cli page create -p <PAGE_ID> -f notes.md # Create from markdown
233
+ notion-cli page retrieve <PAGE_ID> --json # Get page
234
+ notion-cli page update <PAGE_ID> -S --properties '{...}' # Update properties
235
+ notion-cli page export <PAGE_ID> -o page.md # Export to markdown
236
+ notion-cli page export <PAGE_ID> --json -o page.json # Export to JSON
237
+ ```
238
+
239
+ [📖 Export Guide](./docs/export.md)
240
+
241
+ ### Block Commands
242
+
243
+ ```bash
244
+ notion-cli block retrieve <BLOCK_ID> # Get block
245
+ notion-cli block append <BLOCK_ID> --children '[...]' # Append children
246
+ notion-cli block update <BLOCK_ID> --content "text" # Update block
247
+ notion-cli block delete <BLOCK_ID> # Delete block
248
+ ```
249
+
250
+ ### Batch Operations
251
+
252
+ ```bash
253
+ notion-cli batch retrieve <ID1> <ID2> <ID3> --json # Retrieve multiple
254
+ notion-cli batch delete <ID1> <ID2> <ID3> # Delete multiple in parallel
255
+ ```
256
+
257
+ [📖 Batch Operations Guide](./docs/batch.md)
258
+
259
+ ### Daily Journal
260
+
261
+ ```bash
262
+ notion-cli daily # Create/find today's entry
263
+ notion-cli daily "Had a productive standup" # Create with body content
264
+ notion-cli daily "Another thought" # Append to existing entry
265
+ notion-cli daily setup DB_ID # Setup: point to existing database
266
+ notion-cli daily setup --auto PAGE_ID # Setup: auto-create database
267
+ ```
268
+
269
+ [📖 Daily Journal Guide](./docs/user-guides/daily-journal-setup.md)
270
+
271
+ ### Templates
272
+
273
+ ```bash
274
+ notion-cli template save "meeting" -p '{"Status": "To Do"}' -c "# Agenda" --icon "📋"
275
+ notion-cli template list # List all templates
276
+ notion-cli template get "meeting" # View template details
277
+ notion-cli template use "meeting" --to tasks --title "Sprint" # Create page from template
278
+ notion-cli template remove "meeting" # Delete a template
279
+ notion-cli quick "My Meeting" --template meeting --to tasks # Quick capture with template
280
+ ```
281
+
282
+ [📖 Templates Guide](./docs/user-guides/templates-guide.md)
283
+
284
+ ### Append
285
+
286
+ ```bash
287
+ notion-cli append "Daily Log" "Had a productive standup" # Append by page name
288
+ notion-cli append "Meeting Notes" "## Action Items\n\n- Fix bug" # Markdown content
289
+ cat notes.md | notion-cli append "Knowledge Hub" # Pipe from file
290
+ notion-cli a "Daily Log" "Quick note" # Short alias
291
+ ```
292
+
293
+ [📖 Append Reference](./docs/append.md)
294
+
295
+ ### Search
296
+
297
+ ```bash
298
+ notion-cli search "project" --json # Search workspace
299
+ notion-cli search "docs" -p page --json # Filter by type
300
+ notion-cli search "report" --created-after 2025-10-01 # Date filters
301
+ ```
302
+
303
+ ### User Commands
304
+
305
+ ```bash
306
+ notion-cli user list --json # List all users
307
+ notion-cli user retrieve <USER_ID> # Get user
308
+ notion-cli user retrieve bot # Get bot info
309
+ ```
310
+
311
+ ### Stats Dashboard
312
+
313
+ ```bash
314
+ notion-cli stats # Workspace overview from cache (instant)
315
+ notion-cli stats --live # Also fetch page counts per DB (slower)
316
+ notion-cli stats --relations # Show database relation graph
317
+ notion-cli stats --json # JSON output for automation
318
+ notion-cli dashboard # Alias
319
+ ```
320
+
321
+ [📖 Stats Reference](./docs/stats.md)
322
+
323
+ ### Workspace & Cache
324
+
325
+ ```bash
326
+ notion-cli sync # Cache all databases
327
+ notion-cli list --json # List cached databases
328
+ notion-cli cache:info --json # Cache statistics
329
+ notion-cli config set-token # Configure token
330
+ notion-cli browse <PAGE_ID> # Interactive page tree navigation
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Output Formats
336
+
337
+ All commands support multiple output formats:
338
+
339
+ ```bash
340
+ notion-cli db query <ID> --json # Structured JSON with envelope
341
+ notion-cli db query <ID> --compact-json # Single-line JSON (ideal for piping)
342
+ notion-cli db query <ID> --markdown # GitHub-flavored markdown table
343
+ notion-cli db query <ID> --pretty # Table with borders
344
+ notion-cli db query <ID> --csv # CSV format
345
+ notion-cli db query <ID> --raw # Raw API response
346
+ notion-cli db query <ID> --minimal # Strip metadata (~40% smaller)
347
+ ```
348
+
349
+ [📖 Output Formats Guide](./docs/user-guides/output-formats.md) | [📖 Envelope System](./docs/user-guides/envelope-index.md)
350
+
351
+ ---
352
+
353
+ ## Environment Variables
354
+
355
+ ### Authentication
356
+ ```bash
357
+ NOTION_TOKEN=secret_your_token_here # Internal integration token
358
+ # or
359
+ NOTION_TOKEN=ntn_your_token_here # OAuth token (newer format)
360
+ ```
361
+
362
+ ### Retry & Circuit Breaker
363
+ ```bash
364
+ NOTION_RETRY_MAX_ATTEMPTS=3 # Max retry attempts (default: 3)
365
+ NOTION_RETRY_INITIAL_DELAY=1000 # Initial delay in ms (default: 1000)
366
+ NOTION_RETRY_MAX_DELAY=30000 # Max delay in ms (default: 30000)
367
+ NOTION_CB_FAILURE_THRESHOLD=5 # Failures before circuit opens (default: 5)
368
+ ```
369
+
370
+ ### Caching & Performance
371
+ ```bash
372
+ NOTION_CACHE_DISABLED=true # Disable all caching
373
+ NOTION_CLI_DISK_CACHE_ENABLED=true # Persistent disk cache (default: true)
374
+ NOTION_CLI_DISK_CACHE_MAX_SIZE=104857600 # Max disk cache size (default: 100MB)
375
+ NOTION_CLI_HTTP_KEEP_ALIVE=true # Connection pooling (default: true)
376
+ NOTION_CLI_DELETE_CONCURRENCY=5 # Parallel deletion limit (default: 5)
377
+ ```
378
+
379
+ ### Debugging
380
+ ```bash
381
+ NOTION_CLI_VERBOSE=true # Structured event logging to stderr
382
+ NOTION_CLI_DEBUG=true # DEBUG + VERBOSE modes
383
+ NO_COLOR=1 # Disable ANSI color codes in tables
384
+ ```
385
+
386
+ [📖 Verbose Logging Guide](./docs/user-guides/verbose-logging.md)
387
+
388
+ ---
389
+
390
+ ## Real-World Examples
391
+
392
+ ### Automated Task Management
393
+
394
+ ```bash
395
+ #!/bin/bash
396
+ # Create task with simple properties
397
+ TASK_ID=$(notion-cli page create \
398
+ -d <TASKS_DB_ID> -S --properties '{
399
+ "Name": "Review PR",
400
+ "Status": "In Progress"
401
+ }' --json | jq -r '.data.id')
402
+
403
+ echo "Working on task: $TASK_ID"
404
+
405
+ # Mark complete
406
+ notion-cli page update $TASK_ID -S --properties '{"Status": "Done"}' --json
407
+ ```
408
+
409
+ ### Daily Sync Script
410
+
411
+ ```bash
412
+ #!/bin/bash
413
+ notion-cli sync
414
+ notion-cli list --json > databases.json
415
+ echo "# Database Report - $(date)" > report.md
416
+ jq -r '.[] | "- **\(.title)** (\(.page_count) pages)"' databases.json >> report.md
417
+ ```
418
+
419
+ ---
420
+
421
+ ## Troubleshooting
422
+
423
+ **Run diagnostics first:**
424
+ ```bash
425
+ notion-cli doctor # Shows 7 checks with pass/fail and recommendations
426
+ ```
427
+
428
+ | Problem | Solution |
429
+ |---------|----------|
430
+ | Token not configured | `notion-cli init` or `export NOTION_TOKEN="secret_..."` (or `"ntn_..."`) |
431
+ | Database not found | `notion-cli sync` to refresh cache, or check ID type |
432
+ | 429 rate limiting | Automatic retry handles this; increase `NOTION_RETRY_MAX_ATTEMPTS` if needed |
433
+ | Slow queries | Use `--filter` to reduce data, `notion-cli sync` for caching |
434
+ | Auth errors | `notion-cli init` to reconfigure, check integration access at notion.so/my-integrations |
435
+
436
+ ---
437
+
438
+ ## Development
439
+
440
+ ### Prerequisites
441
+
442
+ - Node.js >= 22.0.0
443
+ - npm >= 8.0.0
444
+
445
+ ### Setup
446
+
447
+ ```bash
448
+ git clone https://github.com/Catafal/notion-cli
449
+ cd notion-cli
450
+ npm install
451
+ npm run build
452
+ ```
453
+
454
+ ### Workflow
455
+
456
+ ```bash
457
+ npm run build # Build TypeScript
458
+ npm test # Run tests (mocha + chai)
459
+ npm run lint # Lint (ESLint v9)
460
+ npm run build && npm test && npm run lint # Full quality check
461
+ ```
462
+
463
+ ### Project Structure
464
+
465
+ ```
466
+ notion-cli/
467
+ ├── src/ # TypeScript source
468
+ │ ├── commands/ # CLI commands
469
+ │ ├── utils/ # Utilities
470
+ │ ├── notion.ts # Notion API client
471
+ │ └── cache.ts # Caching layer
472
+ ├── test/ # Tests
473
+ ├── docs/ # Documentation
474
+ └── dist/ # Compiled output
475
+ ```
476
+
477
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
478
+
479
+ ---
480
+
481
+ ## Documentation
482
+
483
+ Full documentation lives in the `/docs` folder:
484
+
485
+ - **[AI Agent Guide](./docs/user-guides/ai-agent-guide.md)** — Quick reference for AI assistants
486
+ - **[AI Agent Cookbook](./docs/user-guides/ai-agent-cookbook.md)** — Common patterns and recipes
487
+ - **[Simple Properties](./docs/user-guides/simple-properties.md)** — Flat JSON property format
488
+ - **[Filter Guide](./docs/user-guides/filter-guide.md)** — Database query filtering syntax
489
+ - **[Output Formats](./docs/user-guides/output-formats.md)** — JSON, CSV, markdown output options
490
+ - **[Verbose Logging](./docs/user-guides/verbose-logging.md)** — Debug mode and troubleshooting
491
+ - **[Batch Operations](./docs/batch.md)** — Retrieve or delete multiple resources
492
+ - **[Page Export](./docs/export.md)** — Export pages to markdown or JSON
493
+ - **[Interactive Browsing](./docs/user-guides/interactive-browsing.md)** — Navigate page trees
494
+ - **[Templates](./docs/user-guides/templates-guide.md)** — Reusable page presets
495
+ - **[Error Handling](./docs/user-guides/error-handling-examples.md)** — Understanding errors
496
+ - **[Envelope System](./docs/user-guides/envelope-index.md)** — Standardized response format
497
+ - **[Fuzzy Search](./docs/user-guides/fuzzy-search.md)** — Typo-tolerant name resolution and filtering
498
+ - **[Append Command](./docs/append.md)** — Add content to existing pages by name
499
+ - **[Stats Dashboard](./docs/stats.md)** — Workspace statistics and relation graph
500
+ - **[Markdown to Notion](./docs/user-guides/markdown-to-notion.md)** — Supported markdown features and block mapping
501
+ - **[Smart ID Resolution](./docs/architecture/smart-id-resolution.md)** — Auto ID conversion
502
+
503
+ See [docs/README.md](./docs/README.md) for the complete index.
504
+
505
+ ---
506
+
507
+ ## Contributing
508
+
509
+ Contributions welcome! Please:
510
+
511
+ 1. Fork the repository
512
+ 2. Create a feature branch
513
+ 3. Add tests for new features
514
+ 4. Submit a pull request
515
+
516
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for code style, test requirements, PR process, and commit format.
517
+
518
+ ## API Version
519
+
520
+ This CLI uses **Notion API v5.2.1** with full support for:
521
+ - Data sources (new database API)
522
+ - Enhanced properties
523
+ - Improved pagination
524
+ - Better error handling
525
+
526
+ ## Support
527
+
528
+ - **Documentation**: Full guides in `/docs` folder
529
+ - **Issues**: Report bugs on [GitHub Issues](https://github.com/Catafal/notion-cli/issues)
530
+ - **Discussions**: Ask questions in [GitHub Discussions](https://github.com/Catafal/notion-cli/discussions)
531
+
532
+ ## Related Projects
533
+
534
+ - **Notion API**: https://developers.notion.com
535
+ - **@notionhq/client**: Official Notion SDK
536
+
537
+ ## Legal & Compliance
538
+
539
+ ### Trademark Notice
540
+ "Notion" is a registered trademark of Notion Labs, Inc. This project is an independent,
541
+ unofficial tool and is not affiliated with, endorsed by, or sponsored by Notion Labs, Inc.
542
+
543
+ ### License
544
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
545
+
546
+ ### Third-Party Licenses
547
+ This project uses various open-source dependencies. See [NOTICE](NOTICE) for complete
548
+ third-party license information.
549
+
550
+ ---
551
+
552
+ **Built for AI agents, optimized for automation.**
package/bin/dev ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ const oclif = require('@oclif/core')
4
+
5
+ const path = require('path')
6
+ const project = path.join(__dirname, '..', 'tsconfig.json')
7
+
8
+ // In dev mode -> use ts-node and dev plugins
9
+ process.env.NODE_ENV = 'development'
10
+
11
+ require('ts-node').register({project})
12
+
13
+ // In dev mode, always show stack traces
14
+ oclif.settings.debug = true;
15
+
16
+ // Start the CLI
17
+ oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
package/bin/dev.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\dev" %*
package/bin/run ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ const oclif = require('@oclif/core')
4
+
5
+ // Check for updates asynchronously (doesn't block CLI execution)
6
+ // This will notify users once per day if a new version is available
7
+ try {
8
+ const { checkForUpdates } = require('../dist/utils/update-notifier')
9
+ checkForUpdates()
10
+ } catch (error) {
11
+ // Silently fail if update check fails (e.g., during development)
12
+ }
13
+
14
+ oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
package/bin/run.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\run" %*
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Base Command with Envelope Support
3
+ *
4
+ * Extends oclif Command with automatic envelope wrapping for consistent JSON output.
5
+ * All commands should extend this class to get automatic envelope support.
6
+ */
7
+ import { Command, Interfaces } from '@oclif/core';
8
+ import { EnvelopeFormatter, OutputFlags } from './envelope';
9
+ import { NotionCLIError } from './errors/index';
10
+ /**
11
+ * Base command configuration
12
+ */
13
+ export type CommandConfig = Interfaces.Config;
14
+ /**
15
+ * BaseCommand - Extends oclif Command with envelope support
16
+ *
17
+ * Features:
18
+ * - Automatic envelope wrapping for JSON output
19
+ * - Consistent error handling
20
+ * - Execution time tracking
21
+ * - Version metadata injection
22
+ * - Stdout/stderr separation
23
+ */
24
+ export declare abstract class BaseCommand extends Command {
25
+ protected envelope: EnvelopeFormatter;
26
+ protected shouldUseEnvelope: boolean;
27
+ /**
28
+ * Initialize command and create envelope formatter
29
+ */
30
+ init(): Promise<void>;
31
+ /**
32
+ * Cleanup hook - flushes disk cache and destroys HTTP agents before exit
33
+ */
34
+ finally(error?: Error): Promise<void>;
35
+ /**
36
+ * Determine if envelope should be used based on flags
37
+ */
38
+ protected checkEnvelopeUsage(flags: Record<string, unknown>): boolean;
39
+ /**
40
+ * Output success response with automatic envelope wrapping
41
+ *
42
+ * @param data - Response data
43
+ * @param flags - Command flags
44
+ * @param additionalMetadata - Optional metadata to include
45
+ */
46
+ protected outputSuccess<T>(data: T, flags: OutputFlags & Record<string, unknown>, additionalMetadata?: Record<string, unknown>): never;
47
+ /**
48
+ * Output error response with automatic envelope wrapping
49
+ *
50
+ * @param error - Error object
51
+ * @param flags - Command flags
52
+ * @param additionalContext - Optional error context
53
+ */
54
+ protected outputError(error: Error | NotionCLIError, flags: OutputFlags & Record<string, unknown>, additionalContext?: Record<string, unknown>): never;
55
+ /**
56
+ * Get appropriate exit code for error
57
+ */
58
+ private getExitCodeForError;
59
+ /**
60
+ * Catch handler that ensures proper envelope error output
61
+ */
62
+ catch(error: Error & {
63
+ exitCode?: number;
64
+ }): Promise<void>;
65
+ }
66
+ /**
67
+ * Standard flags that all envelope-enabled commands should include
68
+ */
69
+ export declare const EnvelopeFlags: {
70
+ json: Interfaces.BooleanFlag<boolean>;
71
+ 'compact-json': Interfaces.BooleanFlag<boolean>;
72
+ raw: Interfaces.BooleanFlag<boolean>;
73
+ };