@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
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const notion = require("../../notion");
5
+ const schema_extractor_1 = require("../../utils/schema-extractor");
6
+ const schema_examples_1 = require("../../utils/schema-examples");
7
+ const errors_1 = require("../../errors");
8
+ const notion_resolver_1 = require("../../utils/notion-resolver");
9
+ class DbSchema extends core_1.Command {
10
+ async run() {
11
+ const { args, flags } = await this.parse(DbSchema);
12
+ try {
13
+ // Resolve ID from URL, direct ID, or name (future)
14
+ const dataSourceId = await (0, notion_resolver_1.resolveNotionId)(args.data_source_id, 'database');
15
+ // Fetch data source from Notion (uses caching)
16
+ const dataSource = await notion.retrieveDataSource(dataSourceId);
17
+ // Extract clean schema
18
+ let schema = (0, schema_extractor_1.extractSchema)(dataSource);
19
+ // Filter properties if specified
20
+ if (flags.properties) {
21
+ const propertyNames = flags.properties.split(',').map(p => p.trim());
22
+ schema = (0, schema_extractor_1.filterProperties)(schema, propertyNames);
23
+ }
24
+ // Generate examples if requested
25
+ if (flags['with-examples']) {
26
+ const examples = (0, schema_examples_1.generatePropertyExamples)(dataSource.properties);
27
+ const { writable, readOnly } = (0, schema_examples_1.groupExamplesByWritability)(examples);
28
+ // Determine output format
29
+ const outputFormat = flags.json ? 'json' : flags.output;
30
+ // Handle JSON output
31
+ if (outputFormat === 'json') {
32
+ this.log(JSON.stringify({
33
+ success: true,
34
+ data: {
35
+ schema: schema,
36
+ examples: {
37
+ writable: writable,
38
+ read_only: readOnly,
39
+ all: examples,
40
+ },
41
+ },
42
+ metadata: {
43
+ timestamp: new Date().toISOString(),
44
+ command: 'db schema',
45
+ examples_count: examples.length,
46
+ writable_count: writable.length,
47
+ read_only_count: readOnly.length,
48
+ },
49
+ }, null, 2));
50
+ process.exit(0);
51
+ return;
52
+ }
53
+ // Human-readable output with examples
54
+ this.outputSchemaWithExamples(schema, examples);
55
+ process.exit(0);
56
+ return;
57
+ }
58
+ // Regular schema output (without examples)
59
+ // Determine output format
60
+ const outputFormat = flags.json ? 'json' : flags.output;
61
+ // Handle markdown output
62
+ if (flags.markdown) {
63
+ const markdown = (0, schema_extractor_1.formatSchemaAsMarkdown)(schema);
64
+ this.log(markdown);
65
+ process.exit(0);
66
+ return;
67
+ }
68
+ // Handle JSON output (for AI agents)
69
+ if (outputFormat === 'json') {
70
+ this.log(JSON.stringify({
71
+ success: true,
72
+ data: schema,
73
+ timestamp: new Date().toISOString(),
74
+ }, null, 2));
75
+ process.exit(0);
76
+ return;
77
+ }
78
+ // Handle YAML output
79
+ if (outputFormat === 'yaml') {
80
+ const yaml = this.formatAsYaml(schema);
81
+ this.log(yaml);
82
+ process.exit(0);
83
+ return;
84
+ }
85
+ // Handle table output (default)
86
+ this.outputTable(schema);
87
+ process.exit(0);
88
+ }
89
+ catch (error) {
90
+ const cliError = error instanceof errors_1.NotionCLIError
91
+ ? error
92
+ : (0, errors_1.wrapNotionError)(error, {
93
+ resourceType: 'database',
94
+ endpoint: 'dataSources.retrieve'
95
+ });
96
+ if (flags.json || flags.output === 'json') {
97
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
98
+ }
99
+ else {
100
+ this.error(cliError.toHumanString());
101
+ }
102
+ process.exit(1);
103
+ }
104
+ }
105
+ /**
106
+ * Output schema with examples in human-readable format
107
+ */
108
+ outputSchemaWithExamples(schema, examples) {
109
+ // First show basic schema info
110
+ this.log(`\n📋 ${schema.title}`);
111
+ if (schema.description) {
112
+ this.log(` ${schema.description}`);
113
+ }
114
+ this.log(` ID: ${schema.id}`);
115
+ if (schema.url) {
116
+ this.log(` URL: ${schema.url}`);
117
+ }
118
+ this.log('');
119
+ // Group examples by writability
120
+ const { writable, readOnly } = (0, schema_examples_1.groupExamplesByWritability)(examples);
121
+ // Show writable properties with examples
122
+ if (writable.length > 0) {
123
+ this.log('✏️ Writable Properties (can be set via API)');
124
+ this.log('='.repeat(80));
125
+ for (const example of writable) {
126
+ this.log('');
127
+ this.log(`${example.property_name} (${example.property_type})`);
128
+ this.log(` ${example.description}`);
129
+ this.log('');
130
+ this.log(' Simple value:');
131
+ this.log(` ${JSON.stringify(example.simple_value)}`);
132
+ this.log('');
133
+ this.log(' Notion API payload:');
134
+ const payload = JSON.stringify(example.notion_payload, null, 2);
135
+ const indentedPayload = payload.split('\n').map(line => ` ${line}`).join('\n');
136
+ this.log(indentedPayload);
137
+ this.log('-'.repeat(80));
138
+ }
139
+ }
140
+ // Show read-only properties
141
+ if (readOnly.length > 0) {
142
+ this.log('');
143
+ this.log('🔒 Read-Only Properties (cannot be set via API)');
144
+ this.log('='.repeat(80));
145
+ for (const example of readOnly) {
146
+ this.log('');
147
+ this.log(`${example.property_name} (${example.property_type})`);
148
+ this.log(` ${example.description}`);
149
+ this.log('-'.repeat(80));
150
+ }
151
+ }
152
+ this.log('');
153
+ }
154
+ /**
155
+ * Output schema as formatted table
156
+ */
157
+ outputTable(schema) {
158
+ this.log(`\n📋 ${schema.title}`);
159
+ if (schema.description) {
160
+ this.log(` ${schema.description}`);
161
+ }
162
+ this.log(` ID: ${schema.id}`);
163
+ if (schema.url) {
164
+ this.log(` URL: ${schema.url}`);
165
+ }
166
+ this.log('');
167
+ if (schema.properties.length === 0) {
168
+ this.log(' No properties found.');
169
+ return;
170
+ }
171
+ // Calculate column widths
172
+ const nameWidth = Math.max(20, ...schema.properties.map(p => p.name.length));
173
+ const typeWidth = Math.max(12, ...schema.properties.map(p => p.type.length));
174
+ // Print header
175
+ this.log(` ${'Name'.padEnd(nameWidth)} | ${'Type'.padEnd(typeWidth)} | Req | Details`);
176
+ this.log(` ${'-'.repeat(nameWidth)}-+-${'-'.repeat(typeWidth)}-+-----+---------`);
177
+ // Print properties
178
+ for (const prop of schema.properties) {
179
+ const name = prop.name.padEnd(nameWidth);
180
+ const type = prop.type.padEnd(typeWidth);
181
+ const required = prop.required ? ' ✓ ' : ' ';
182
+ const details = prop.options
183
+ ? prop.options.slice(0, 3).join(', ') +
184
+ (prop.options.length > 3 ? '...' : '')
185
+ : prop.description || '';
186
+ this.log(` ${name} | ${type} | ${required} | ${details}`);
187
+ }
188
+ this.log('');
189
+ }
190
+ /**
191
+ * Format schema as YAML
192
+ */
193
+ formatAsYaml(schema) {
194
+ const lines = [];
195
+ lines.push('id: ' + schema.id);
196
+ lines.push('title: ' + schema.title);
197
+ if (schema.description) {
198
+ lines.push('description: ' + schema.description);
199
+ }
200
+ if (schema.url) {
201
+ lines.push('url: ' + schema.url);
202
+ }
203
+ lines.push('properties:');
204
+ for (const prop of schema.properties) {
205
+ lines.push(` - name: ${prop.name}`);
206
+ lines.push(` type: ${prop.type}`);
207
+ if (prop.required) {
208
+ lines.push(` required: true`);
209
+ }
210
+ if (prop.options && prop.options.length > 0) {
211
+ lines.push(` options:`);
212
+ for (const opt of prop.options) {
213
+ lines.push(` - ${opt}`);
214
+ }
215
+ }
216
+ if (prop.description) {
217
+ lines.push(` description: ${prop.description}`);
218
+ }
219
+ if (prop.config) {
220
+ lines.push(` config:`);
221
+ for (const [key, value] of Object.entries(prop.config)) {
222
+ lines.push(` ${key}: ${value}`);
223
+ }
224
+ }
225
+ }
226
+ return lines.join('\n');
227
+ }
228
+ }
229
+ DbSchema.description = 'Extract clean, AI-parseable schema from a Notion data source (table). ' +
230
+ 'This command is optimized for AI agents and automation - it returns property names, ' +
231
+ 'types, options (for select/multi-select), and configuration in an easy-to-parse format.';
232
+ DbSchema.aliases = ['db:s', 'ds:schema', 'ds:s'];
233
+ DbSchema.examples = [
234
+ {
235
+ description: 'Get full schema in JSON format (recommended for AI agents)',
236
+ command: '<%= config.bin %> db schema abc123def456 --output json',
237
+ },
238
+ {
239
+ description: 'Get schema with property payload examples (recommended for AI agents)',
240
+ command: '<%= config.bin %> db schema abc123def456 --with-examples --json',
241
+ },
242
+ {
243
+ description: 'Get schema using database URL',
244
+ command: '<%= config.bin %> db schema https://notion.so/DATABASE_ID --output json',
245
+ },
246
+ {
247
+ description: 'Get schema as formatted table',
248
+ command: '<%= config.bin %> db schema abc123def456',
249
+ },
250
+ {
251
+ description: 'Get schema with examples in human-readable format',
252
+ command: '<%= config.bin %> db schema abc123def456 --with-examples',
253
+ },
254
+ {
255
+ description: 'Get schema in YAML format',
256
+ command: '<%= config.bin %> db schema abc123def456 --output yaml',
257
+ },
258
+ {
259
+ description: 'Get only specific properties',
260
+ command: '<%= config.bin %> db schema abc123def456 --properties Name,Status,Tags --output json',
261
+ },
262
+ {
263
+ description: 'Get schema as markdown documentation',
264
+ command: '<%= config.bin %> db schema abc123def456 --markdown',
265
+ },
266
+ {
267
+ description: 'Parse schema with jq (extract property names)',
268
+ command: '<%= config.bin %> db schema abc123def456 --output json | jq \'.data.properties[].name\'',
269
+ },
270
+ {
271
+ description: 'Find all select/multi-select properties and their options',
272
+ command: '<%= config.bin %> db schema abc123def456 --output json | jq \'.data.properties[] | select(.options) | {name, options}\'',
273
+ },
274
+ ];
275
+ DbSchema.args = {
276
+ data_source_id: core_1.Args.string({
277
+ required: true,
278
+ description: 'Data source ID or URL (the table whose schema you want to extract)',
279
+ }),
280
+ };
281
+ DbSchema.flags = {
282
+ output: core_1.Flags.string({
283
+ char: 'o',
284
+ description: 'Output format',
285
+ options: ['json', 'yaml', 'table'],
286
+ default: 'table',
287
+ }),
288
+ properties: core_1.Flags.string({
289
+ char: 'p',
290
+ description: 'Comma-separated list of properties to include (default: all)',
291
+ }),
292
+ markdown: core_1.Flags.boolean({
293
+ char: 'm',
294
+ description: 'Output as markdown documentation',
295
+ default: false,
296
+ }),
297
+ json: core_1.Flags.boolean({
298
+ char: 'j',
299
+ description: 'Output as JSON (shorthand for --output json)',
300
+ default: false,
301
+ }),
302
+ 'with-examples': core_1.Flags.boolean({
303
+ char: 'e',
304
+ description: 'Include property payload examples for create/update operations',
305
+ default: false,
306
+ }),
307
+ };
308
+ exports.default = DbSchema;
@@ -0,0 +1,31 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class DbUpdate extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ database_id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
11
+ };
12
+ static flags: {
13
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
15
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
17
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
21
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
22
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
23
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
24
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ title: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
28
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ };
30
+ run(): Promise<void>;
31
+ }
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const table_formatter_1 = require("../../utils/table-formatter");
5
+ const notion = require("../../notion");
6
+ const helper_1 = require("../../helper");
7
+ const base_flags_1 = require("../../base-flags");
8
+ const errors_1 = require("../../errors");
9
+ const notion_resolver_1 = require("../../utils/notion-resolver");
10
+ class DbUpdate extends core_1.Command {
11
+ async run() {
12
+ const { args, flags } = await this.parse(DbUpdate);
13
+ try {
14
+ // Resolve ID from URL, direct ID, or name (future)
15
+ const dataSourceId = await (0, notion_resolver_1.resolveNotionId)(args.database_id, 'database');
16
+ const dsTitle = flags.title;
17
+ // TODO: support other properties (description, properties schema, etc.)
18
+ const dsProps = {
19
+ data_source_id: dataSourceId,
20
+ title: [
21
+ {
22
+ type: 'text',
23
+ text: {
24
+ content: dsTitle,
25
+ },
26
+ },
27
+ ],
28
+ };
29
+ const res = await notion.updateDataSource(dsProps);
30
+ // Handle JSON output for automation
31
+ if (flags.json) {
32
+ this.log(JSON.stringify({
33
+ success: true,
34
+ data: res,
35
+ timestamp: new Date().toISOString()
36
+ }, null, 2));
37
+ process.exit(0);
38
+ return;
39
+ }
40
+ // Handle raw JSON output (legacy)
41
+ if (flags.raw) {
42
+ (0, helper_1.outputRawJson)(res);
43
+ process.exit(0);
44
+ return;
45
+ }
46
+ // Handle table output
47
+ const columns = {
48
+ title: {
49
+ get: (row) => {
50
+ return (0, helper_1.getDataSourceTitle)(row);
51
+ },
52
+ },
53
+ object: {},
54
+ id: {},
55
+ url: {},
56
+ };
57
+ const options = {
58
+ printLine: this.log.bind(this),
59
+ ...flags,
60
+ };
61
+ (0, table_formatter_1.formatTable)([res], columns, options);
62
+ process.exit(0);
63
+ }
64
+ catch (error) {
65
+ const cliError = error instanceof errors_1.NotionCLIError
66
+ ? error
67
+ : (0, errors_1.wrapNotionError)(error, {
68
+ resourceType: 'database',
69
+ attemptedId: args.database_id,
70
+ endpoint: 'dataSources.update'
71
+ });
72
+ if (flags.json) {
73
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
74
+ }
75
+ else {
76
+ this.error(cliError.toHumanString());
77
+ }
78
+ process.exit(1);
79
+ }
80
+ }
81
+ }
82
+ DbUpdate.description = 'Update a data source (table) title and properties';
83
+ DbUpdate.aliases = ['db:u', 'ds:update', 'ds:u'];
84
+ DbUpdate.examples = [
85
+ {
86
+ description: 'Update a data source with a specific data_source_id and title',
87
+ command: `$ notion-cli db update DATA_SOURCE_ID -t 'My Data Source'`,
88
+ },
89
+ {
90
+ description: 'Update a data source via URL',
91
+ command: `$ notion-cli db update https://notion.so/DATABASE_ID -t 'My Data Source'`,
92
+ },
93
+ {
94
+ description: 'Update a data source with a specific data_source_id and output raw json',
95
+ command: `$ notion-cli db update DATA_SOURCE_ID -t 'My Table' -r`,
96
+ },
97
+ ];
98
+ DbUpdate.args = {
99
+ database_id: core_1.Args.string({
100
+ required: true,
101
+ description: 'Data source ID or URL (the ID of the table you want to update)',
102
+ }),
103
+ };
104
+ DbUpdate.flags = {
105
+ title: core_1.Flags.string({
106
+ char: 't',
107
+ description: 'New database title',
108
+ required: true,
109
+ }),
110
+ raw: core_1.Flags.boolean({
111
+ char: 'r',
112
+ description: 'output raw json',
113
+ }),
114
+ ...table_formatter_1.tableFlags,
115
+ ...base_flags_1.AutomationFlags,
116
+ };
117
+ exports.default = DbUpdate;
@@ -0,0 +1,50 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Doctor extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static flags: {
10
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ run(): Promise<void>;
13
+ /**
14
+ * Check Node.js version meets requirement (>=18.0.0)
15
+ */
16
+ private checkNodeVersion;
17
+ /**
18
+ * Check if NOTION_TOKEN environment variable is set
19
+ */
20
+ private checkTokenSet;
21
+ /**
22
+ * Check if token format is valid
23
+ * Accepts both "secret_" prefix (internal integrations) and "ntn_" prefix (OAuth tokens)
24
+ */
25
+ private checkTokenFormat;
26
+ /**
27
+ * Check network connectivity to api.notion.com
28
+ */
29
+ private checkNetworkConnectivity;
30
+ /**
31
+ * Check if can connect to Notion API (whoami check)
32
+ */
33
+ private checkApiConnection;
34
+ /**
35
+ * Check if workspace cache exists
36
+ */
37
+ private checkCacheExists;
38
+ /**
39
+ * Check if cache is fresh (< 24 hours old) or needs sync
40
+ */
41
+ private checkCacheFreshness;
42
+ /**
43
+ * Test HTTPS connection to a host
44
+ */
45
+ private checkHttpsConnection;
46
+ /**
47
+ * Print human-readable output
48
+ */
49
+ private printHumanReadable;
50
+ }