@infograb/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.
- package/LICENSE +21 -0
- package/README.md +1386 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +14 -0
- package/bin/run.cmd +3 -0
- package/dist/base-command.d.ts +73 -0
- package/dist/base-command.js +179 -0
- package/dist/base-flags.d.ts +14 -0
- package/dist/base-flags.js +59 -0
- package/dist/cache.d.ts +84 -0
- package/dist/cache.js +351 -0
- package/dist/commands/batch/retrieve.d.ts +43 -0
- package/dist/commands/batch/retrieve.js +265 -0
- package/dist/commands/block/append.d.ts +42 -0
- package/dist/commands/block/append.js +219 -0
- package/dist/commands/block/delete.d.ts +30 -0
- package/dist/commands/block/delete.js +94 -0
- package/dist/commands/block/retrieve/children.d.ts +31 -0
- package/dist/commands/block/retrieve/children.js +174 -0
- package/dist/commands/block/retrieve.d.ts +30 -0
- package/dist/commands/block/retrieve.js +98 -0
- package/dist/commands/block/update.d.ts +45 -0
- package/dist/commands/block/update.js +241 -0
- package/dist/commands/cache/info.d.ts +19 -0
- package/dist/commands/cache/info.js +145 -0
- package/dist/commands/config/set-token.d.ts +30 -0
- package/dist/commands/config/set-token.js +201 -0
- package/dist/commands/db/create.d.ts +31 -0
- package/dist/commands/db/create.js +124 -0
- package/dist/commands/db/query.d.ts +41 -0
- package/dist/commands/db/query.js +355 -0
- package/dist/commands/db/retrieve.d.ts +33 -0
- package/dist/commands/db/retrieve.js +134 -0
- package/dist/commands/db/schema.d.ts +32 -0
- package/dist/commands/db/schema.js +308 -0
- package/dist/commands/db/update.d.ts +31 -0
- package/dist/commands/db/update.js +117 -0
- package/dist/commands/doctor.d.ts +50 -0
- package/dist/commands/doctor.js +420 -0
- package/dist/commands/init.d.ts +57 -0
- package/dist/commands/init.js +471 -0
- package/dist/commands/list.d.ts +29 -0
- package/dist/commands/list.js +184 -0
- package/dist/commands/page/create.d.ts +33 -0
- package/dist/commands/page/create.js +240 -0
- package/dist/commands/page/retrieve/property_item.d.ts +24 -0
- package/dist/commands/page/retrieve/property_item.js +72 -0
- package/dist/commands/page/retrieve.d.ts +36 -0
- package/dist/commands/page/retrieve.js +244 -0
- package/dist/commands/page/update.d.ts +34 -0
- package/dist/commands/page/update.js +184 -0
- package/dist/commands/search.d.ts +40 -0
- package/dist/commands/search.js +348 -0
- package/dist/commands/sync.d.ts +24 -0
- package/dist/commands/sync.js +183 -0
- package/dist/commands/user/list.d.ts +27 -0
- package/dist/commands/user/list.js +99 -0
- package/dist/commands/user/retrieve/bot.d.ts +28 -0
- package/dist/commands/user/retrieve/bot.js +96 -0
- package/dist/commands/user/retrieve.d.ts +30 -0
- package/dist/commands/user/retrieve.js +103 -0
- package/dist/commands/whoami.d.ts +19 -0
- package/dist/commands/whoami.js +175 -0
- package/dist/deduplication.d.ts +41 -0
- package/dist/deduplication.js +71 -0
- package/dist/envelope.d.ts +169 -0
- package/dist/envelope.js +257 -0
- package/dist/errors/enhanced-errors.d.ts +168 -0
- package/dist/errors/enhanced-errors.js +570 -0
- package/dist/errors/index.d.ts +18 -0
- package/dist/errors/index.js +33 -0
- package/dist/examples/cache-retry-examples.d.ts +64 -0
- package/dist/examples/cache-retry-examples.js +375 -0
- package/dist/helper.d.ts +102 -0
- package/dist/helper.js +885 -0
- package/dist/http-agent.d.ts +38 -0
- package/dist/http-agent.js +60 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/interface.d.ts +4 -0
- package/dist/interface.js +2 -0
- package/dist/notion.d.ts +144 -0
- package/dist/notion.js +547 -0
- package/dist/retry.d.ts +72 -0
- package/dist/retry.js +381 -0
- package/dist/utils/disk-cache.d.ts +80 -0
- package/dist/utils/disk-cache.js +291 -0
- package/dist/utils/markdown-to-blocks.d.ts +19 -0
- package/dist/utils/markdown-to-blocks.js +259 -0
- package/dist/utils/notion-resolver.d.ts +48 -0
- package/dist/utils/notion-resolver.js +262 -0
- package/dist/utils/notion-url-parser.d.ts +46 -0
- package/dist/utils/notion-url-parser.js +111 -0
- package/dist/utils/property-expander.d.ts +45 -0
- package/dist/utils/property-expander.js +323 -0
- package/dist/utils/schema-examples.d.ts +40 -0
- package/dist/utils/schema-examples.js +359 -0
- package/dist/utils/schema-extractor.d.ts +65 -0
- package/dist/utils/schema-extractor.js +235 -0
- package/dist/utils/table-formatter.d.ts +36 -0
- package/dist/utils/table-formatter.js +122 -0
- package/dist/utils/terminal-banner.d.ts +24 -0
- package/dist/utils/terminal-banner.js +34 -0
- package/dist/utils/token-validator.d.ts +55 -0
- package/dist/utils/token-validator.js +85 -0
- package/dist/utils/update-notifier.d.ts +26 -0
- package/dist/utils/update-notifier.js +54 -0
- package/dist/utils/workspace-cache.d.ts +58 -0
- package/dist/utils/workspace-cache.js +185 -0
- package/oclif.manifest.json +4497 -0
- package/package.json +115 -0
- package/scripts/banner.js +38 -0
- package/scripts/postinstall.js +56 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class BlockAppend 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
|
+
'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
|
+
retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
18
|
+
sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
|
+
filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
+
csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
24
|
+
block_id: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
25
|
+
children: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
26
|
+
text: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
27
|
+
'heading-1': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
28
|
+
'heading-2': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
29
|
+
'heading-3': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
30
|
+
bullet: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
31
|
+
numbered: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
32
|
+
todo: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
33
|
+
toggle: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
34
|
+
code: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
35
|
+
language: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
36
|
+
quote: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
37
|
+
callout: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
38
|
+
after: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
39
|
+
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
40
|
+
};
|
|
41
|
+
run(): Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
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 notion_resolver_1 = require("../../utils/notion-resolver");
|
|
8
|
+
const base_flags_1 = require("../../base-flags");
|
|
9
|
+
const errors_1 = require("../../errors");
|
|
10
|
+
class BlockAppend extends core_1.Command {
|
|
11
|
+
async run() {
|
|
12
|
+
const { flags } = await this.parse(BlockAppend);
|
|
13
|
+
try {
|
|
14
|
+
// Resolve block ID from URL or direct ID
|
|
15
|
+
const blockId = await (0, notion_resolver_1.resolveNotionId)(flags.block_id, 'page');
|
|
16
|
+
let children;
|
|
17
|
+
// Check if using simple text-based flags or complex JSON
|
|
18
|
+
const hasTextFlags = flags.text || flags['heading-1'] || flags['heading-2'] || flags['heading-3'] ||
|
|
19
|
+
flags.bullet || flags.numbered || flags.todo || flags.toggle ||
|
|
20
|
+
flags.code || flags.quote || flags.callout;
|
|
21
|
+
if (hasTextFlags && flags.children) {
|
|
22
|
+
this.error('Cannot use both text-based flags (--text, --heading-1, etc.) and --children flag together. Choose one approach.');
|
|
23
|
+
}
|
|
24
|
+
if (hasTextFlags) {
|
|
25
|
+
// Use simple text-based flags
|
|
26
|
+
children = (0, helper_1.buildBlocksFromTextFlags)({
|
|
27
|
+
text: flags.text,
|
|
28
|
+
heading1: flags['heading-1'],
|
|
29
|
+
heading2: flags['heading-2'],
|
|
30
|
+
heading3: flags['heading-3'],
|
|
31
|
+
bullet: flags.bullet,
|
|
32
|
+
numbered: flags.numbered,
|
|
33
|
+
todo: flags.todo,
|
|
34
|
+
toggle: flags.toggle,
|
|
35
|
+
code: flags.code,
|
|
36
|
+
language: flags.language,
|
|
37
|
+
quote: flags.quote,
|
|
38
|
+
callout: flags.callout,
|
|
39
|
+
});
|
|
40
|
+
if (children.length === 0) {
|
|
41
|
+
this.error('No content provided. Use text-based flags (--text, --heading-1, etc.) or --children flag.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (flags.children) {
|
|
45
|
+
// Use complex JSON
|
|
46
|
+
try {
|
|
47
|
+
children = JSON.parse(flags.children);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw errors_1.NotionCLIErrorFactory.invalidJson(flags.children, error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.error('No content provided. Use text-based flags (--text, --heading-1, etc.) or --children flag.');
|
|
55
|
+
}
|
|
56
|
+
const params = {
|
|
57
|
+
block_id: blockId,
|
|
58
|
+
children: children,
|
|
59
|
+
};
|
|
60
|
+
if (flags.after) {
|
|
61
|
+
// Resolve after block ID from URL or direct ID
|
|
62
|
+
const afterBlockId = await (0, notion_resolver_1.resolveNotionId)(flags.after, 'page');
|
|
63
|
+
params.after = afterBlockId;
|
|
64
|
+
}
|
|
65
|
+
const res = await notion.appendBlockChildren(params);
|
|
66
|
+
// Handle JSON output for automation
|
|
67
|
+
if (flags.json) {
|
|
68
|
+
this.log(JSON.stringify({
|
|
69
|
+
success: true,
|
|
70
|
+
data: res,
|
|
71
|
+
timestamp: new Date().toISOString()
|
|
72
|
+
}, null, 2));
|
|
73
|
+
process.exit(0);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Handle raw JSON output (legacy)
|
|
77
|
+
if (flags.raw) {
|
|
78
|
+
(0, helper_1.outputRawJson)(res);
|
|
79
|
+
process.exit(0);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Handle table output
|
|
83
|
+
const columns = {
|
|
84
|
+
object: {},
|
|
85
|
+
id: {},
|
|
86
|
+
type: {},
|
|
87
|
+
parent: {},
|
|
88
|
+
content: {
|
|
89
|
+
get: (row) => {
|
|
90
|
+
return (0, helper_1.getBlockPlainText)(row);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const options = {
|
|
95
|
+
printLine: this.log.bind(this),
|
|
96
|
+
...flags,
|
|
97
|
+
};
|
|
98
|
+
(0, table_formatter_1.formatTable)(res.results, columns, options);
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
103
|
+
? error
|
|
104
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
105
|
+
resourceType: 'block',
|
|
106
|
+
attemptedId: flags.block_id,
|
|
107
|
+
endpoint: 'blocks.children.append',
|
|
108
|
+
userInput: flags.children
|
|
109
|
+
});
|
|
110
|
+
if (flags.json) {
|
|
111
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.error(cliError.toHumanString());
|
|
115
|
+
}
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
BlockAppend.description = 'Append block children';
|
|
121
|
+
BlockAppend.aliases = ['block:a'];
|
|
122
|
+
BlockAppend.examples = [
|
|
123
|
+
{
|
|
124
|
+
description: 'Append a simple paragraph',
|
|
125
|
+
command: `$ notion-cli block append -b BLOCK_ID --text "Hello world!"`,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
description: 'Append a heading',
|
|
129
|
+
command: `$ notion-cli block append -b BLOCK_ID --heading-1 "Chapter Title"`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
description: 'Append a bullet point',
|
|
133
|
+
command: `$ notion-cli block append -b BLOCK_ID --bullet "First item"`,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
description: 'Append a code block',
|
|
137
|
+
command: `$ notion-cli block append -b BLOCK_ID --code "console.log('test')" --language javascript`,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
description: 'Append block children with complex JSON (for advanced cases)',
|
|
141
|
+
command: `$ notion-cli block append -b BLOCK_ID -c '[{"object":"block","type":"paragraph","paragraph":{"rich_text":[{"type":"text","text":{"content":"Hello world!"}}]}}]'`,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
description: 'Append block children via URL',
|
|
145
|
+
command: `$ notion-cli block append -b https://notion.so/BLOCK_ID --text "Hello world!"`,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
description: 'Append block children after a block',
|
|
149
|
+
command: `$ notion-cli block append -b BLOCK_ID --text "Hello world!" -a AFTER_BLOCK_ID`,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
description: 'Append block children and output raw json',
|
|
153
|
+
command: `$ notion-cli block append -b BLOCK_ID --text "Hello world!" -r`,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
description: 'Append block children and output JSON for automation',
|
|
157
|
+
command: `$ notion-cli block append -b BLOCK_ID --text "Hello world!" --json`,
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
BlockAppend.flags = {
|
|
161
|
+
block_id: core_1.Flags.string({
|
|
162
|
+
char: 'b',
|
|
163
|
+
description: 'Parent block ID or URL',
|
|
164
|
+
required: true,
|
|
165
|
+
}),
|
|
166
|
+
children: core_1.Flags.string({
|
|
167
|
+
char: 'c',
|
|
168
|
+
description: 'Block children (JSON array) - for complex cases',
|
|
169
|
+
}),
|
|
170
|
+
// Simple text-based flags
|
|
171
|
+
text: core_1.Flags.string({
|
|
172
|
+
description: 'Paragraph text',
|
|
173
|
+
}),
|
|
174
|
+
'heading-1': core_1.Flags.string({
|
|
175
|
+
description: 'H1 heading text',
|
|
176
|
+
}),
|
|
177
|
+
'heading-2': core_1.Flags.string({
|
|
178
|
+
description: 'H2 heading text',
|
|
179
|
+
}),
|
|
180
|
+
'heading-3': core_1.Flags.string({
|
|
181
|
+
description: 'H3 heading text',
|
|
182
|
+
}),
|
|
183
|
+
bullet: core_1.Flags.string({
|
|
184
|
+
description: 'Bulleted list item text',
|
|
185
|
+
}),
|
|
186
|
+
numbered: core_1.Flags.string({
|
|
187
|
+
description: 'Numbered list item text',
|
|
188
|
+
}),
|
|
189
|
+
todo: core_1.Flags.string({
|
|
190
|
+
description: 'To-do item text',
|
|
191
|
+
}),
|
|
192
|
+
toggle: core_1.Flags.string({
|
|
193
|
+
description: 'Toggle block text',
|
|
194
|
+
}),
|
|
195
|
+
code: core_1.Flags.string({
|
|
196
|
+
description: 'Code block content',
|
|
197
|
+
}),
|
|
198
|
+
language: core_1.Flags.string({
|
|
199
|
+
description: 'Code block language (used with --code)',
|
|
200
|
+
default: 'plain text',
|
|
201
|
+
}),
|
|
202
|
+
quote: core_1.Flags.string({
|
|
203
|
+
description: 'Quote block text',
|
|
204
|
+
}),
|
|
205
|
+
callout: core_1.Flags.string({
|
|
206
|
+
description: 'Callout block text',
|
|
207
|
+
}),
|
|
208
|
+
after: core_1.Flags.string({
|
|
209
|
+
char: 'a',
|
|
210
|
+
description: 'Block ID or URL to append after (optional)',
|
|
211
|
+
}),
|
|
212
|
+
raw: core_1.Flags.boolean({
|
|
213
|
+
char: 'r',
|
|
214
|
+
description: 'output raw json',
|
|
215
|
+
}),
|
|
216
|
+
...table_formatter_1.tableFlags,
|
|
217
|
+
...base_flags_1.AutomationFlags,
|
|
218
|
+
};
|
|
219
|
+
exports.default = BlockAppend;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class BlockDelete 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,94 @@
|
|
|
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
|
+
class BlockDelete extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(BlockDelete);
|
|
12
|
+
try {
|
|
13
|
+
const res = await notion.deleteBlock(args.block_id);
|
|
14
|
+
// Handle JSON output for automation
|
|
15
|
+
if (flags.json) {
|
|
16
|
+
this.log(JSON.stringify({
|
|
17
|
+
success: true,
|
|
18
|
+
data: res,
|
|
19
|
+
timestamp: new Date().toISOString()
|
|
20
|
+
}, null, 2));
|
|
21
|
+
process.exit(0);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// Handle raw JSON output (legacy)
|
|
25
|
+
if (flags.raw) {
|
|
26
|
+
(0, helper_1.outputRawJson)(res);
|
|
27
|
+
process.exit(0);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Handle table output
|
|
31
|
+
const columns = {
|
|
32
|
+
object: {},
|
|
33
|
+
id: {},
|
|
34
|
+
type: {},
|
|
35
|
+
parent: {},
|
|
36
|
+
content: {
|
|
37
|
+
get: (row) => {
|
|
38
|
+
return (0, helper_1.getBlockPlainText)(row);
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const options = {
|
|
43
|
+
printLine: this.log.bind(this),
|
|
44
|
+
...flags,
|
|
45
|
+
};
|
|
46
|
+
(0, table_formatter_1.formatTable)([res], columns, options);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
51
|
+
? error
|
|
52
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
53
|
+
resourceType: 'block',
|
|
54
|
+
attemptedId: args.block_id,
|
|
55
|
+
endpoint: 'blocks.delete'
|
|
56
|
+
});
|
|
57
|
+
if (flags.json) {
|
|
58
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.error(cliError.toHumanString());
|
|
62
|
+
}
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
BlockDelete.description = 'Delete a block';
|
|
68
|
+
BlockDelete.aliases = ['block:d'];
|
|
69
|
+
BlockDelete.examples = [
|
|
70
|
+
{
|
|
71
|
+
description: 'Delete a block',
|
|
72
|
+
command: `$ notion-cli block delete BLOCK_ID`,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
description: 'Delete a block and output raw json',
|
|
76
|
+
command: `$ notion-cli block delete BLOCK_ID -r`,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
description: 'Delete a block and output JSON for automation',
|
|
80
|
+
command: `$ notion-cli block delete BLOCK_ID --json`,
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
BlockDelete.args = {
|
|
84
|
+
block_id: core_1.Args.string({ required: true }),
|
|
85
|
+
};
|
|
86
|
+
BlockDelete.flags = {
|
|
87
|
+
raw: core_1.Flags.boolean({
|
|
88
|
+
char: 'r',
|
|
89
|
+
description: 'output raw json',
|
|
90
|
+
}),
|
|
91
|
+
...table_formatter_1.tableFlags,
|
|
92
|
+
...base_flags_1.AutomationFlags,
|
|
93
|
+
};
|
|
94
|
+
exports.default = BlockDelete;
|
|
@@ -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,174 @@
|
|
|
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
|
+
class BlockRetrieveChildren extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(BlockRetrieveChildren);
|
|
12
|
+
try {
|
|
13
|
+
// TODO: Add support start_cursor, page_size
|
|
14
|
+
let res = await notion.retrieveBlockChildren(args.block_id);
|
|
15
|
+
// Handle --show-databases flag: filter and enrich child_database blocks
|
|
16
|
+
if (flags['show-databases']) {
|
|
17
|
+
const databases = await (0, helper_1.getChildDatabasesWithIds)(res.results);
|
|
18
|
+
// Handle JSON output for automation
|
|
19
|
+
if (flags.json) {
|
|
20
|
+
this.log(JSON.stringify({
|
|
21
|
+
success: true,
|
|
22
|
+
data: databases,
|
|
23
|
+
timestamp: new Date().toISOString()
|
|
24
|
+
}, null, 2));
|
|
25
|
+
process.exit(0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Handle raw JSON output
|
|
29
|
+
if (flags.raw) {
|
|
30
|
+
(0, helper_1.outputRawJson)(databases);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Display databases in table format
|
|
35
|
+
const columns = {
|
|
36
|
+
block_id: {
|
|
37
|
+
header: 'Block ID',
|
|
38
|
+
},
|
|
39
|
+
title: {
|
|
40
|
+
header: 'Title',
|
|
41
|
+
},
|
|
42
|
+
data_source_id: {
|
|
43
|
+
header: 'Data Source ID',
|
|
44
|
+
},
|
|
45
|
+
database_id: {
|
|
46
|
+
header: 'Database ID',
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const options = {
|
|
50
|
+
printLine: this.log.bind(this),
|
|
51
|
+
...flags,
|
|
52
|
+
};
|
|
53
|
+
(0, table_formatter_1.formatTable)(databases, columns, options);
|
|
54
|
+
// Show helpful tip
|
|
55
|
+
if (databases.length > 0) {
|
|
56
|
+
this.log('\nTip: Use the data_source_id to query databases:');
|
|
57
|
+
this.log(` notion-cli db query <data_source_id>`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.log('\nNo child databases found on this page.');
|
|
61
|
+
}
|
|
62
|
+
process.exit(0);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// Auto-enrich child_database blocks for JSON/raw output
|
|
66
|
+
if (flags.json || flags.raw) {
|
|
67
|
+
const enrichedResults = await Promise.all(res.results.map(async (block) => {
|
|
68
|
+
if (block.type === 'child_database') {
|
|
69
|
+
return await (0, helper_1.enrichChildDatabaseBlock)(block);
|
|
70
|
+
}
|
|
71
|
+
return block;
|
|
72
|
+
}));
|
|
73
|
+
res.results = enrichedResults;
|
|
74
|
+
}
|
|
75
|
+
// Apply minimal flag to strip metadata
|
|
76
|
+
if (flags.minimal) {
|
|
77
|
+
res = (0, helper_1.stripMetadata)(res);
|
|
78
|
+
}
|
|
79
|
+
// Handle JSON output for automation
|
|
80
|
+
if (flags.json) {
|
|
81
|
+
this.log(JSON.stringify({
|
|
82
|
+
success: true,
|
|
83
|
+
data: res,
|
|
84
|
+
timestamp: new Date().toISOString()
|
|
85
|
+
}, null, 2));
|
|
86
|
+
process.exit(0);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// Handle raw JSON output (legacy)
|
|
90
|
+
if (flags.raw) {
|
|
91
|
+
(0, helper_1.outputRawJson)(res);
|
|
92
|
+
process.exit(0);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Handle table output
|
|
96
|
+
const columns = {
|
|
97
|
+
object: {},
|
|
98
|
+
id: {},
|
|
99
|
+
type: {},
|
|
100
|
+
content: {
|
|
101
|
+
get: (row) => {
|
|
102
|
+
return (0, helper_1.getBlockPlainText)(row);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const options = {
|
|
107
|
+
printLine: this.log.bind(this),
|
|
108
|
+
...flags,
|
|
109
|
+
};
|
|
110
|
+
(0, table_formatter_1.formatTable)(res.results, columns, options);
|
|
111
|
+
process.exit(0);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
115
|
+
? error
|
|
116
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
117
|
+
resourceType: 'block',
|
|
118
|
+
attemptedId: args.block_id,
|
|
119
|
+
endpoint: 'blocks.children.list'
|
|
120
|
+
});
|
|
121
|
+
if (flags.json) {
|
|
122
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.error(cliError.toHumanString());
|
|
126
|
+
}
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
BlockRetrieveChildren.description = 'Retrieve block children (supports database discovery via --show-databases)';
|
|
132
|
+
BlockRetrieveChildren.aliases = ['block:r:c'];
|
|
133
|
+
BlockRetrieveChildren.examples = [
|
|
134
|
+
{
|
|
135
|
+
description: 'Retrieve block children',
|
|
136
|
+
command: `$ notion-cli block retrieve:children BLOCK_ID`,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
description: 'Retrieve block children and output raw json',
|
|
140
|
+
command: `$ notion-cli block retrieve:children BLOCK_ID -r`,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
description: 'Retrieve block children and output JSON for automation',
|
|
144
|
+
command: `$ notion-cli block retrieve:children BLOCK_ID --json`,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
description: 'Discover databases on a page with queryable IDs',
|
|
148
|
+
command: `$ notion-cli block retrieve:children PAGE_ID --show-databases`,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
description: 'Get databases as JSON for automation',
|
|
152
|
+
command: `$ notion-cli block retrieve:children PAGE_ID --show-databases --json`,
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
BlockRetrieveChildren.args = {
|
|
156
|
+
block_id: core_1.Args.string({
|
|
157
|
+
description: 'block_id or page_id',
|
|
158
|
+
required: true,
|
|
159
|
+
}),
|
|
160
|
+
};
|
|
161
|
+
BlockRetrieveChildren.flags = {
|
|
162
|
+
raw: core_1.Flags.boolean({
|
|
163
|
+
char: 'r',
|
|
164
|
+
description: 'output raw json',
|
|
165
|
+
}),
|
|
166
|
+
'show-databases': core_1.Flags.boolean({
|
|
167
|
+
char: 'd',
|
|
168
|
+
description: 'show only child databases with their queryable IDs (data_source_id)',
|
|
169
|
+
default: false,
|
|
170
|
+
}),
|
|
171
|
+
...table_formatter_1.tableFlags,
|
|
172
|
+
...base_flags_1.AutomationFlags,
|
|
173
|
+
};
|
|
174
|
+
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
|
+
}
|