@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,31 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class BlockRetrieveChildren extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ block_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
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ 'show-databases': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ };
30
+ run(): Promise<void>;
31
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const notion = require("../../../notion");
5
+ const helper_1 = require("../../../helper");
6
+ const base_flags_1 = require("../../../base-flags");
7
+ const errors_1 = require("../../../errors");
8
+ const table_formatter_1 = require("../../../utils/table-formatter");
9
+ const notion_resolver_1 = require("../../../utils/notion-resolver");
10
+ class BlockRetrieveChildren extends core_1.Command {
11
+ async run() {
12
+ const { args, flags } = await this.parse(BlockRetrieveChildren);
13
+ try {
14
+ // Resolve URL/name/ID to clean Notion ID
15
+ const blockId = await (0, notion_resolver_1.resolveNotionId)(args.block_id, 'page');
16
+ // TODO: Add support start_cursor, page_size
17
+ let res = await notion.retrieveBlockChildren(blockId);
18
+ // Handle --show-databases flag: filter and enrich child_database blocks
19
+ if (flags['show-databases']) {
20
+ const databases = await (0, helper_1.getChildDatabasesWithIds)(res.results);
21
+ // Handle JSON output for automation
22
+ if (flags.json) {
23
+ this.log(JSON.stringify({
24
+ success: true,
25
+ data: databases,
26
+ timestamp: new Date().toISOString()
27
+ }, null, 2));
28
+ process.exit(0);
29
+ return;
30
+ }
31
+ // Handle raw JSON output
32
+ if (flags.raw) {
33
+ (0, helper_1.outputRawJson)(databases);
34
+ process.exit(0);
35
+ return;
36
+ }
37
+ // Display databases in table format
38
+ const columns = {
39
+ block_id: {
40
+ header: 'Block ID',
41
+ },
42
+ title: {
43
+ header: 'Title',
44
+ },
45
+ data_source_id: {
46
+ header: 'Data Source ID',
47
+ },
48
+ database_id: {
49
+ header: 'Database ID',
50
+ },
51
+ };
52
+ const options = {
53
+ printLine: this.log.bind(this),
54
+ ...flags,
55
+ };
56
+ (0, table_formatter_1.formatTable)(databases, columns, options);
57
+ // Show helpful tip
58
+ if (databases.length > 0) {
59
+ this.log('\nTip: Use the data_source_id to query databases:');
60
+ this.log(` notion-cli db query <data_source_id>`);
61
+ }
62
+ else {
63
+ this.log('\nNo child databases found on this page.');
64
+ }
65
+ process.exit(0);
66
+ return;
67
+ }
68
+ // Auto-enrich child_database blocks for JSON/raw output
69
+ if (flags.json || flags.raw) {
70
+ const enrichedResults = await Promise.all(res.results.map(async (block) => {
71
+ if (block.type === 'child_database') {
72
+ return await (0, helper_1.enrichChildDatabaseBlock)(block);
73
+ }
74
+ return block;
75
+ }));
76
+ res.results = enrichedResults;
77
+ }
78
+ // Apply minimal flag to strip metadata
79
+ if (flags.minimal) {
80
+ res = (0, helper_1.stripMetadata)(res);
81
+ }
82
+ // Handle JSON output for automation
83
+ if (flags.json) {
84
+ this.log(JSON.stringify({
85
+ success: true,
86
+ data: res,
87
+ timestamp: new Date().toISOString()
88
+ }, null, 2));
89
+ process.exit(0);
90
+ return;
91
+ }
92
+ // Handle raw JSON output (legacy)
93
+ if (flags.raw) {
94
+ (0, helper_1.outputRawJson)(res);
95
+ process.exit(0);
96
+ return;
97
+ }
98
+ // Handle table output
99
+ const columns = {
100
+ object: {},
101
+ id: {},
102
+ type: {},
103
+ content: {
104
+ get: (row) => {
105
+ return (0, helper_1.getBlockPlainText)(row);
106
+ },
107
+ },
108
+ };
109
+ const options = {
110
+ printLine: this.log.bind(this),
111
+ ...flags,
112
+ };
113
+ (0, table_formatter_1.formatTable)(res.results, columns, options);
114
+ process.exit(0);
115
+ }
116
+ catch (error) {
117
+ const cliError = error instanceof errors_1.NotionCLIError
118
+ ? error
119
+ : (0, errors_1.wrapNotionError)(error, {
120
+ resourceType: 'block',
121
+ attemptedId: args.block_id,
122
+ endpoint: 'blocks.children.list'
123
+ });
124
+ if (flags.json) {
125
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
126
+ }
127
+ else {
128
+ this.error(cliError.toHumanString());
129
+ }
130
+ process.exit(1);
131
+ }
132
+ }
133
+ }
134
+ BlockRetrieveChildren.description = 'Retrieve block children (supports database discovery via --show-databases)';
135
+ BlockRetrieveChildren.aliases = ['block:r:c'];
136
+ BlockRetrieveChildren.examples = [
137
+ {
138
+ description: 'Retrieve block children',
139
+ command: `$ notion-cli block retrieve:children BLOCK_ID`,
140
+ },
141
+ {
142
+ description: 'Retrieve block children and output raw json',
143
+ command: `$ notion-cli block retrieve:children BLOCK_ID -r`,
144
+ },
145
+ {
146
+ description: 'Retrieve block children and output JSON for automation',
147
+ command: `$ notion-cli block retrieve:children BLOCK_ID --json`,
148
+ },
149
+ {
150
+ description: 'Discover databases on a page with queryable IDs',
151
+ command: `$ notion-cli block retrieve:children PAGE_ID --show-databases`,
152
+ },
153
+ {
154
+ description: 'Get databases as JSON for automation',
155
+ command: `$ notion-cli block retrieve:children PAGE_ID --show-databases --json`,
156
+ },
157
+ ];
158
+ BlockRetrieveChildren.args = {
159
+ block_id: core_1.Args.string({
160
+ description: 'block_id or page_id',
161
+ required: true,
162
+ }),
163
+ };
164
+ BlockRetrieveChildren.flags = {
165
+ raw: core_1.Flags.boolean({
166
+ char: 'r',
167
+ description: 'output raw json',
168
+ }),
169
+ 'show-databases': core_1.Flags.boolean({
170
+ char: 'd',
171
+ description: 'show only child databases with their queryable IDs (data_source_id)',
172
+ default: false,
173
+ }),
174
+ ...table_formatter_1.tableFlags,
175
+ ...base_flags_1.AutomationFlags,
176
+ };
177
+ exports.default = BlockRetrieveChildren;
@@ -0,0 +1,30 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class BlockRetrieve extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ block_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
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ };
29
+ run(): Promise<void>;
30
+ }
@@ -0,0 +1,101 @@
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 BlockRetrieve extends core_1.Command {
11
+ async run() {
12
+ const { args, flags } = await this.parse(BlockRetrieve);
13
+ try {
14
+ // Resolve URL/name/ID to clean Notion ID
15
+ const blockId = await (0, notion_resolver_1.resolveNotionId)(args.block_id, 'page');
16
+ let res = await notion.retrieveBlock(blockId);
17
+ // Apply minimal flag to strip metadata
18
+ if (flags.minimal) {
19
+ res = (0, helper_1.stripMetadata)(res);
20
+ }
21
+ // Handle JSON output for automation
22
+ if (flags.json) {
23
+ this.log(JSON.stringify({
24
+ success: true,
25
+ data: res,
26
+ timestamp: new Date().toISOString()
27
+ }, null, 2));
28
+ process.exit(0);
29
+ return;
30
+ }
31
+ // Handle raw JSON output (legacy)
32
+ if (flags.raw) {
33
+ (0, helper_1.outputRawJson)(res);
34
+ process.exit(0);
35
+ return;
36
+ }
37
+ // Handle table output
38
+ const columns = {
39
+ object: {},
40
+ id: {},
41
+ type: {},
42
+ parent: {},
43
+ content: {
44
+ get: (row) => {
45
+ return (0, helper_1.getBlockPlainText)(row);
46
+ },
47
+ },
48
+ };
49
+ const options = {
50
+ printLine: this.log.bind(this),
51
+ ...flags,
52
+ };
53
+ (0, table_formatter_1.formatTable)([res], columns, options);
54
+ process.exit(0);
55
+ }
56
+ catch (error) {
57
+ const cliError = error instanceof errors_1.NotionCLIError
58
+ ? error
59
+ : (0, errors_1.wrapNotionError)(error, {
60
+ resourceType: 'block',
61
+ attemptedId: args.block_id,
62
+ endpoint: 'blocks.retrieve'
63
+ });
64
+ if (flags.json) {
65
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
66
+ }
67
+ else {
68
+ this.error(cliError.toHumanString());
69
+ }
70
+ process.exit(1);
71
+ }
72
+ }
73
+ }
74
+ BlockRetrieve.description = 'Retrieve a block';
75
+ BlockRetrieve.aliases = ['block:r'];
76
+ BlockRetrieve.examples = [
77
+ {
78
+ description: 'Retrieve a block',
79
+ command: `$ notion-cli block retrieve BLOCK_ID`,
80
+ },
81
+ {
82
+ description: 'Retrieve a block and output raw json',
83
+ command: `$ notion-cli block retrieve BLOCK_ID -r`,
84
+ },
85
+ {
86
+ description: 'Retrieve a block and output JSON for automation',
87
+ command: `$ notion-cli block retrieve BLOCK_ID --json`,
88
+ },
89
+ ];
90
+ BlockRetrieve.args = {
91
+ block_id: core_1.Args.string({ required: true }),
92
+ };
93
+ BlockRetrieve.flags = {
94
+ raw: core_1.Flags.boolean({
95
+ char: 'r',
96
+ description: 'output raw json',
97
+ }),
98
+ ...table_formatter_1.tableFlags,
99
+ ...base_flags_1.AutomationFlags,
100
+ };
101
+ exports.default = BlockRetrieve;
@@ -0,0 +1,45 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class BlockUpdate extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ block_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
+ archived: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ content: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
29
+ text: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
30
+ 'heading-1': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
31
+ 'heading-2': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
32
+ 'heading-3': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
33
+ bullet: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
34
+ numbered: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
35
+ todo: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
36
+ toggle: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
37
+ code: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
38
+ language: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
39
+ quote: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
40
+ callout: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
41
+ color: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
42
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
43
+ };
44
+ run(): Promise<void>;
45
+ }
@@ -0,0 +1,242 @@
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 client_1 = require("@notionhq/client");
7
+ const helper_1 = require("../../helper");
8
+ const notion_resolver_1 = require("../../utils/notion-resolver");
9
+ const base_flags_1 = require("../../base-flags");
10
+ const errors_1 = require("../../errors");
11
+ class BlockUpdate extends core_1.Command {
12
+ async run() {
13
+ const { args, flags } = await this.parse(BlockUpdate);
14
+ try {
15
+ // Resolve block ID from URL or direct ID
16
+ const blockId = await (0, notion_resolver_1.resolveNotionId)(args.block_id, 'page');
17
+ const params = {
18
+ block_id: blockId,
19
+ };
20
+ // Handle archived flag
21
+ if (flags.archived !== undefined) {
22
+ params.archived = flags.archived;
23
+ }
24
+ // Check if using simple text-based flags or complex JSON
25
+ const hasTextFlags = flags.text || flags['heading-1'] || flags['heading-2'] || flags['heading-3'] ||
26
+ flags.bullet || flags.numbered || flags.todo || flags.toggle ||
27
+ flags.code || flags.quote || flags.callout;
28
+ if (hasTextFlags && flags.content) {
29
+ this.error('Cannot use both text-based flags (--text, --heading-1, etc.) and --content flag together. Choose one approach.');
30
+ }
31
+ // Handle content updates
32
+ if (hasTextFlags) {
33
+ // Use simple text-based flags
34
+ const blockUpdate = (0, helper_1.buildBlockUpdateFromTextFlags)('', {
35
+ text: flags.text,
36
+ heading1: flags['heading-1'],
37
+ heading2: flags['heading-2'],
38
+ heading3: flags['heading-3'],
39
+ bullet: flags.bullet,
40
+ numbered: flags.numbered,
41
+ todo: flags.todo,
42
+ toggle: flags.toggle,
43
+ code: flags.code,
44
+ language: flags.language,
45
+ quote: flags.quote,
46
+ callout: flags.callout,
47
+ });
48
+ if (blockUpdate) {
49
+ Object.assign(params, blockUpdate);
50
+ }
51
+ }
52
+ else if (flags.content) {
53
+ // Use complex JSON
54
+ try {
55
+ // Strip prototype pollution keys before merging user-provided JSON
56
+ const { __proto__, constructor, prototype, ...safeContent } = JSON.parse(flags.content);
57
+ Object.assign(params, safeContent);
58
+ }
59
+ catch (error) {
60
+ throw errors_1.NotionCLIErrorFactory.invalidJson(flags.content, error);
61
+ }
62
+ }
63
+ // Handle color updates
64
+ if (flags.color) {
65
+ // Retrieve the block to determine its type
66
+ const blockResponse = await notion.retrieveBlock(blockId);
67
+ // Ensure we have a full block response
68
+ if (!(0, client_1.isFullBlock)(blockResponse)) {
69
+ throw new errors_1.NotionCLIError(errors_1.NotionCLIErrorCode.API_ERROR, 'Received partial block response. Cannot determine block type for color update.', [], { attemptedId: blockId });
70
+ }
71
+ // Color is only supported for certain block types
72
+ const colorSupportedTypes = [
73
+ 'paragraph', 'heading_1', 'heading_2', 'heading_3',
74
+ 'bulleted_list_item', 'numbered_list_item', 'toggle',
75
+ 'quote', 'callout'
76
+ ];
77
+ if (!colorSupportedTypes.includes(blockResponse.type)) {
78
+ this.error(`Color property is not supported for block type: ${blockResponse.type}. Supported types: ${colorSupportedTypes.join(', ')}`);
79
+ }
80
+ // Color must be nested within the block type property
81
+ params[blockResponse.type] = {
82
+ ...params[blockResponse.type],
83
+ color: flags.color
84
+ };
85
+ }
86
+ const res = await notion.updateBlock(params);
87
+ // Handle JSON output for automation
88
+ if (flags.json) {
89
+ this.log(JSON.stringify({
90
+ success: true,
91
+ data: res,
92
+ timestamp: new Date().toISOString()
93
+ }, null, 2));
94
+ process.exit(0);
95
+ return;
96
+ }
97
+ // Handle raw JSON output (legacy)
98
+ if (flags.raw) {
99
+ (0, helper_1.outputRawJson)(res);
100
+ process.exit(0);
101
+ return;
102
+ }
103
+ // Handle table output
104
+ const columns = {
105
+ object: {},
106
+ id: {},
107
+ type: {},
108
+ parent: {},
109
+ content: {
110
+ get: (row) => {
111
+ return (0, helper_1.getBlockPlainText)(row);
112
+ },
113
+ },
114
+ };
115
+ const options = {
116
+ printLine: this.log.bind(this),
117
+ ...flags,
118
+ };
119
+ (0, table_formatter_1.formatTable)([res], columns, options);
120
+ process.exit(0);
121
+ }
122
+ catch (error) {
123
+ const cliError = error instanceof errors_1.NotionCLIError
124
+ ? error
125
+ : (0, errors_1.wrapNotionError)(error, {
126
+ resourceType: 'block',
127
+ attemptedId: args.block_id,
128
+ endpoint: 'blocks.update',
129
+ userInput: flags.content
130
+ });
131
+ if (flags.json) {
132
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
133
+ }
134
+ else {
135
+ this.error(cliError.toHumanString());
136
+ }
137
+ process.exit(1);
138
+ }
139
+ }
140
+ }
141
+ BlockUpdate.description = 'Update a block';
142
+ BlockUpdate.aliases = ['block:u'];
143
+ BlockUpdate.examples = [
144
+ {
145
+ description: 'Update block with simple text',
146
+ command: `$ notion-cli block update BLOCK_ID --text "Updated content"`,
147
+ },
148
+ {
149
+ description: 'Update heading content',
150
+ command: `$ notion-cli block update BLOCK_ID --heading-1 "New Title"`,
151
+ },
152
+ {
153
+ description: 'Update code block',
154
+ command: `$ notion-cli block update BLOCK_ID --code "const x = 42;" --language javascript`,
155
+ },
156
+ {
157
+ description: 'Archive a block',
158
+ command: `$ notion-cli block update BLOCK_ID -a`,
159
+ },
160
+ {
161
+ description: 'Archive a block via URL',
162
+ command: `$ notion-cli block update https://notion.so/BLOCK_ID -a`,
163
+ },
164
+ {
165
+ description: 'Update block content with complex JSON (for advanced cases)',
166
+ command: `$ notion-cli block update BLOCK_ID -c '{"paragraph":{"rich_text":[{"text":{"content":"Updated text"}}]}}'`,
167
+ },
168
+ {
169
+ description: 'Update block color',
170
+ command: `$ notion-cli block update BLOCK_ID --color blue`,
171
+ },
172
+ {
173
+ description: 'Update a block and output raw json',
174
+ command: `$ notion-cli block update BLOCK_ID --text "Updated" -r`,
175
+ },
176
+ {
177
+ description: 'Update a block and output JSON for automation',
178
+ command: `$ notion-cli block update BLOCK_ID --text "Updated" --json`,
179
+ },
180
+ ];
181
+ BlockUpdate.args = {
182
+ block_id: core_1.Args.string({ description: 'Block ID or URL', required: true }),
183
+ };
184
+ BlockUpdate.flags = {
185
+ archived: core_1.Flags.boolean({
186
+ char: 'a',
187
+ description: 'Archive the block',
188
+ }),
189
+ content: core_1.Flags.string({
190
+ char: 'c',
191
+ description: 'Updated block content (JSON object with block type properties) - for complex cases',
192
+ }),
193
+ // Simple text-based flags
194
+ text: core_1.Flags.string({
195
+ description: 'Update paragraph text',
196
+ }),
197
+ 'heading-1': core_1.Flags.string({
198
+ description: 'Update H1 heading text',
199
+ }),
200
+ 'heading-2': core_1.Flags.string({
201
+ description: 'Update H2 heading text',
202
+ }),
203
+ 'heading-3': core_1.Flags.string({
204
+ description: 'Update H3 heading text',
205
+ }),
206
+ bullet: core_1.Flags.string({
207
+ description: 'Update bulleted list item text',
208
+ }),
209
+ numbered: core_1.Flags.string({
210
+ description: 'Update numbered list item text',
211
+ }),
212
+ todo: core_1.Flags.string({
213
+ description: 'Update to-do item text',
214
+ }),
215
+ toggle: core_1.Flags.string({
216
+ description: 'Update toggle block text',
217
+ }),
218
+ code: core_1.Flags.string({
219
+ description: 'Update code block content',
220
+ }),
221
+ language: core_1.Flags.string({
222
+ description: 'Update code block language (used with --code)',
223
+ default: 'plain text',
224
+ }),
225
+ quote: core_1.Flags.string({
226
+ description: 'Update quote block text',
227
+ }),
228
+ callout: core_1.Flags.string({
229
+ description: 'Update callout block text',
230
+ }),
231
+ color: core_1.Flags.string({
232
+ description: 'Block color (for supported block types)',
233
+ options: ['default', 'gray', 'brown', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink', 'red'],
234
+ }),
235
+ raw: core_1.Flags.boolean({
236
+ char: 'r',
237
+ description: 'output raw json',
238
+ }),
239
+ ...table_formatter_1.tableFlags,
240
+ ...base_flags_1.AutomationFlags,
241
+ };
242
+ exports.default = BlockUpdate;
@@ -0,0 +1,30 @@
1
+ import { Command } from '@oclif/core';
2
+ /**
3
+ * List all saved bookmarks.
4
+ * Shows name, type, ID, and which one is the default.
5
+ */
6
+ export default class BookmarkList extends Command {
7
+ static description: string;
8
+ static aliases: string[];
9
+ static examples: {
10
+ description: string;
11
+ command: string;
12
+ }[];
13
+ static flags: {
14
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
16
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
22
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
23
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
24
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ };
29
+ run(): Promise<void>;
30
+ }