@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.
- package/LICENSE +21 -0
- package/README.md +552 -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/append.d.ts +37 -0
- package/dist/commands/append.js +120 -0
- package/dist/commands/batch/delete.d.ts +42 -0
- package/dist/commands/batch/delete.js +199 -0
- package/dist/commands/batch/retrieve.d.ts +43 -0
- package/dist/commands/batch/retrieve.js +272 -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 +97 -0
- package/dist/commands/block/retrieve/children.d.ts +31 -0
- package/dist/commands/block/retrieve/children.js +177 -0
- package/dist/commands/block/retrieve.d.ts +30 -0
- package/dist/commands/block/retrieve.js +101 -0
- package/dist/commands/block/update.d.ts +45 -0
- package/dist/commands/block/update.js +242 -0
- package/dist/commands/bookmark/list.d.ts +30 -0
- package/dist/commands/bookmark/list.js +60 -0
- package/dist/commands/bookmark/remove.d.ts +26 -0
- package/dist/commands/bookmark/remove.js +47 -0
- package/dist/commands/bookmark/set.d.ts +29 -0
- package/dist/commands/bookmark/set.js +96 -0
- package/dist/commands/browse.d.ts +13 -0
- package/dist/commands/browse.js +44 -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 +22 -0
- package/dist/commands/config/set-token.js +137 -0
- package/dist/commands/daily/index.d.ts +32 -0
- package/dist/commands/daily/index.js +135 -0
- package/dist/commands/daily/setup.d.ts +42 -0
- package/dist/commands/daily/setup.js +149 -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 +360 -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 +65 -0
- package/dist/commands/init.js +479 -0
- package/dist/commands/list.d.ts +29 -0
- package/dist/commands/list.js +219 -0
- package/dist/commands/open.d.ts +29 -0
- package/dist/commands/open.js +100 -0
- package/dist/commands/page/create.d.ts +33 -0
- package/dist/commands/page/create.js +261 -0
- package/dist/commands/page/delete.d.ts +36 -0
- package/dist/commands/page/delete.js +107 -0
- package/dist/commands/page/export.d.ts +38 -0
- package/dist/commands/page/export.js +120 -0
- package/dist/commands/page/retrieve/property_item.d.ts +24 -0
- package/dist/commands/page/retrieve/property_item.js +75 -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/quick.d.ts +35 -0
- package/dist/commands/quick.js +168 -0
- package/dist/commands/search.d.ts +43 -0
- package/dist/commands/search.js +361 -0
- package/dist/commands/stats.d.ts +35 -0
- package/dist/commands/stats.js +274 -0
- package/dist/commands/sync.d.ts +24 -0
- package/dist/commands/sync.js +183 -0
- package/dist/commands/template/get.d.ts +28 -0
- package/dist/commands/template/get.js +59 -0
- package/dist/commands/template/list.d.ts +32 -0
- package/dist/commands/template/list.js +62 -0
- package/dist/commands/template/remove.d.ts +27 -0
- package/dist/commands/template/remove.js +48 -0
- package/dist/commands/template/save.d.ts +32 -0
- package/dist/commands/template/save.js +92 -0
- package/dist/commands/template/use.d.ts +34 -0
- package/dist/commands/template/use.js +142 -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 +567 -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/bookmarks.d.ts +32 -0
- package/dist/utils/bookmarks.js +98 -0
- package/dist/utils/daily-config.d.ts +22 -0
- package/dist/utils/daily-config.js +60 -0
- package/dist/utils/disk-cache.d.ts +80 -0
- package/dist/utils/disk-cache.js +291 -0
- package/dist/utils/fuzzy.d.ts +36 -0
- package/dist/utils/fuzzy.js +69 -0
- package/dist/utils/interactive-navigator.d.ts +63 -0
- package/dist/utils/interactive-navigator.js +123 -0
- package/dist/utils/markdown-to-blocks.d.ts +21 -0
- package/dist/utils/markdown-to-blocks.js +333 -0
- package/dist/utils/notion-resolver.d.ts +49 -0
- package/dist/utils/notion-resolver.js +278 -0
- package/dist/utils/notion-url-parser.d.ts +48 -0
- package/dist/utils/notion-url-parser.js +121 -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/shell-config.d.ts +30 -0
- package/dist/utils/shell-config.js +84 -0
- package/dist/utils/table-formatter.d.ts +36 -0
- package/dist/utils/table-formatter.js +125 -0
- package/dist/utils/templates.d.ts +30 -0
- package/dist/utils/templates.js +82 -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 +42 -0
- package/dist/utils/token-validator.js +66 -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 +6471 -0
- package/package.json +118 -0
- package/scripts/banner.js +38 -0
- package/scripts/postinstall.js +44 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append Shortcut Command
|
|
3
|
+
*
|
|
4
|
+
* Quick-append content to any existing Notion page by name, URL, ID, or bookmark.
|
|
5
|
+
* Combines resolveNotionId (name → page ID) with appendBlockChildren (content → blocks).
|
|
6
|
+
*
|
|
7
|
+
* This is the "write to existing page" counterpart of `quick` (which creates new pages).
|
|
8
|
+
*
|
|
9
|
+
* notion-cli append "Daily Log" "New note"
|
|
10
|
+
* notion-cli append PAGE_URL "## Heading\n\nBody"
|
|
11
|
+
* echo "piped text" | notion-cli append "Daily Log"
|
|
12
|
+
*/
|
|
13
|
+
import { Command } from '@oclif/core';
|
|
14
|
+
export default class Append extends Command {
|
|
15
|
+
static description: string;
|
|
16
|
+
static aliases: string[];
|
|
17
|
+
static examples: {
|
|
18
|
+
description: string;
|
|
19
|
+
command: string;
|
|
20
|
+
}[];
|
|
21
|
+
static args: {
|
|
22
|
+
target: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
23
|
+
content: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
24
|
+
};
|
|
25
|
+
static flags: {
|
|
26
|
+
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
27
|
+
'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
28
|
+
retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
29
|
+
timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
30
|
+
'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
31
|
+
verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
32
|
+
minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
33
|
+
};
|
|
34
|
+
run(): Promise<void>;
|
|
35
|
+
/** Read all data from stdin (for piped input). */
|
|
36
|
+
private readStdin;
|
|
37
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Append Shortcut Command
|
|
4
|
+
*
|
|
5
|
+
* Quick-append content to any existing Notion page by name, URL, ID, or bookmark.
|
|
6
|
+
* Combines resolveNotionId (name → page ID) with appendBlockChildren (content → blocks).
|
|
7
|
+
*
|
|
8
|
+
* This is the "write to existing page" counterpart of `quick` (which creates new pages).
|
|
9
|
+
*
|
|
10
|
+
* notion-cli append "Daily Log" "New note"
|
|
11
|
+
* notion-cli append PAGE_URL "## Heading\n\nBody"
|
|
12
|
+
* echo "piped text" | notion-cli append "Daily Log"
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const core_1 = require("@oclif/core");
|
|
16
|
+
const notion = require("../notion");
|
|
17
|
+
const notion_resolver_1 = require("../utils/notion-resolver");
|
|
18
|
+
const markdown_to_blocks_1 = require("../utils/markdown-to-blocks");
|
|
19
|
+
const base_flags_1 = require("../base-flags");
|
|
20
|
+
const errors_1 = require("../errors");
|
|
21
|
+
class Append extends core_1.Command {
|
|
22
|
+
async run() {
|
|
23
|
+
const { args, flags } = await this.parse(Append);
|
|
24
|
+
// 1. Get content — from arg or stdin (checked before try/catch so oclif
|
|
25
|
+
// error() isn't accidentally caught by the NotionCLIError handler)
|
|
26
|
+
let content = args.content || '';
|
|
27
|
+
if (!content && !process.stdin.isTTY) {
|
|
28
|
+
content = await this.readStdin();
|
|
29
|
+
}
|
|
30
|
+
if (!content) {
|
|
31
|
+
this.log('No content provided.\n' +
|
|
32
|
+
'Usage: notion-cli append "Page Name" "content to add"\n' +
|
|
33
|
+
' or: echo "content" | notion-cli append "Page Name"');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
// 2. Resolve target page — supports names, URLs, IDs, bookmarks, fuzzy
|
|
39
|
+
const pageId = await (0, notion_resolver_1.resolveNotionId)(args.target, 'page');
|
|
40
|
+
// 3. Convert markdown content to Notion blocks
|
|
41
|
+
const children = (0, markdown_to_blocks_1.markdownToBlocks)(content);
|
|
42
|
+
// 4. Append blocks to the page
|
|
43
|
+
const res = await notion.appendBlockChildren({
|
|
44
|
+
block_id: pageId,
|
|
45
|
+
children,
|
|
46
|
+
});
|
|
47
|
+
// 5. Output
|
|
48
|
+
if (flags.json) {
|
|
49
|
+
this.log(JSON.stringify({
|
|
50
|
+
success: true,
|
|
51
|
+
data: res,
|
|
52
|
+
timestamp: new Date().toISOString(),
|
|
53
|
+
}, null, 2));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.log(`Appended to: ${args.target}`);
|
|
57
|
+
this.log(`${res.results.length} block(s) added`);
|
|
58
|
+
}
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
63
|
+
? error
|
|
64
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
65
|
+
endpoint: 'blocks.children.append',
|
|
66
|
+
resourceType: 'page',
|
|
67
|
+
attemptedId: args.target,
|
|
68
|
+
});
|
|
69
|
+
if (flags.json) {
|
|
70
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.error(cliError.toHumanString());
|
|
74
|
+
}
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Read all data from stdin (for piped input). */
|
|
79
|
+
readStdin() {
|
|
80
|
+
return new Promise((resolve) => {
|
|
81
|
+
const chunks = [];
|
|
82
|
+
process.stdin.on('data', (chunk) => chunks.push(chunk));
|
|
83
|
+
process.stdin.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8').trim()));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
Append.description = 'Append content to an existing page by name, URL, or ID';
|
|
88
|
+
Append.aliases = ['a'];
|
|
89
|
+
Append.examples = [
|
|
90
|
+
{
|
|
91
|
+
description: 'Append text to a page by name',
|
|
92
|
+
command: '$ notion-cli append "Daily Log" "New note to add"',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
description: 'Append markdown content',
|
|
96
|
+
command: '$ notion-cli append "Knowledge Hub" "## Section\\n\\nSome content"',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
description: 'Pipe content from stdin',
|
|
100
|
+
command: '$ echo "Piped content" | notion-cli append "Daily Log"',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
description: 'Use page URL or ID directly',
|
|
104
|
+
command: '$ notion-cli append PAGE_ID "Quick fix note" --json',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
Append.args = {
|
|
108
|
+
target: core_1.Args.string({
|
|
109
|
+
required: true,
|
|
110
|
+
description: 'Page name, bookmark, URL, or ID',
|
|
111
|
+
}),
|
|
112
|
+
content: core_1.Args.string({
|
|
113
|
+
required: false,
|
|
114
|
+
description: 'Markdown content to append',
|
|
115
|
+
}),
|
|
116
|
+
};
|
|
117
|
+
Append.flags = {
|
|
118
|
+
...base_flags_1.AutomationFlags,
|
|
119
|
+
};
|
|
120
|
+
exports.default = Append;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class BatchDelete extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static aliases: string[];
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static args: {
|
|
10
|
+
ids: 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
|
+
markdown: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
'compact-json': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
pretty: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
24
|
+
sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
25
|
+
filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
26
|
+
csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
27
|
+
extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
28
|
+
'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
29
|
+
'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
30
|
+
ids: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
31
|
+
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Read IDs from stdin, one per line. Times out after 5s if no input.
|
|
35
|
+
*/
|
|
36
|
+
private readStdin;
|
|
37
|
+
/**
|
|
38
|
+
* Delete a single block. Resolves URL/name/ID first, then calls Notion API.
|
|
39
|
+
*/
|
|
40
|
+
private deleteResource;
|
|
41
|
+
run(): Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 readline = require("readline");
|
|
10
|
+
const notion_resolver_1 = require("../../utils/notion-resolver");
|
|
11
|
+
class BatchDelete extends core_1.Command {
|
|
12
|
+
/**
|
|
13
|
+
* Read IDs from stdin, one per line. Times out after 5s if no input.
|
|
14
|
+
*/
|
|
15
|
+
async readStdin() {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const ids = [];
|
|
18
|
+
const rl = readline.createInterface({
|
|
19
|
+
input: process.stdin,
|
|
20
|
+
output: process.stdout,
|
|
21
|
+
terminal: false,
|
|
22
|
+
});
|
|
23
|
+
rl.on('line', (line) => {
|
|
24
|
+
const trimmed = line.trim();
|
|
25
|
+
if (trimmed) {
|
|
26
|
+
ids.push(trimmed);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
rl.on('close', () => {
|
|
30
|
+
resolve(ids);
|
|
31
|
+
});
|
|
32
|
+
rl.on('error', (err) => {
|
|
33
|
+
reject(err);
|
|
34
|
+
});
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
rl.close();
|
|
37
|
+
resolve(ids);
|
|
38
|
+
}, 5000);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Delete a single block. Resolves URL/name/ID first, then calls Notion API.
|
|
43
|
+
*/
|
|
44
|
+
async deleteResource(id) {
|
|
45
|
+
try {
|
|
46
|
+
const resolvedId = await (0, notion_resolver_1.resolveNotionId)(id, 'page');
|
|
47
|
+
const data = await notion.deleteBlock(resolvedId);
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
success: true,
|
|
51
|
+
data,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
56
|
+
? error
|
|
57
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
58
|
+
resourceType: 'block',
|
|
59
|
+
attemptedId: id,
|
|
60
|
+
endpoint: 'blocks.delete'
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
id,
|
|
64
|
+
success: false,
|
|
65
|
+
error: cliError.code,
|
|
66
|
+
message: cliError.userMessage,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async run() {
|
|
71
|
+
const { args, flags } = await this.parse(BatchDelete);
|
|
72
|
+
try {
|
|
73
|
+
// Collect IDs from args, --ids flag, or stdin
|
|
74
|
+
let ids = [];
|
|
75
|
+
if (args.ids) {
|
|
76
|
+
ids = args.ids.split(',').map(id => id.trim()).filter(id => id);
|
|
77
|
+
}
|
|
78
|
+
else if (flags.ids) {
|
|
79
|
+
ids = flags.ids.split(',').map(id => id.trim()).filter(id => id);
|
|
80
|
+
}
|
|
81
|
+
else if (!process.stdin.isTTY) {
|
|
82
|
+
ids = await this.readStdin();
|
|
83
|
+
}
|
|
84
|
+
if (ids.length === 0) {
|
|
85
|
+
throw new errors_1.NotionCLIError(errors_1.NotionCLIErrorCode.VALIDATION_ERROR, 'No IDs provided. Use --ids flag, positional argument, or pipe IDs via stdin', [
|
|
86
|
+
{
|
|
87
|
+
description: 'Provide IDs via --ids flag',
|
|
88
|
+
command: 'notion-cli batch delete --ids ID1,ID2,ID3'
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
description: 'Or pipe IDs from a file',
|
|
92
|
+
command: 'cat block_ids.txt | notion-cli batch delete'
|
|
93
|
+
}
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
// Delete all blocks in parallel
|
|
97
|
+
const results = await Promise.all(ids.map(id => this.deleteResource(id)));
|
|
98
|
+
const successCount = results.filter(r => r.success).length;
|
|
99
|
+
const failureCount = results.filter(r => !r.success).length;
|
|
100
|
+
// JSON output for automation
|
|
101
|
+
if (flags.json) {
|
|
102
|
+
this.log(JSON.stringify({
|
|
103
|
+
success: successCount > 0,
|
|
104
|
+
total: results.length,
|
|
105
|
+
succeeded: successCount,
|
|
106
|
+
failed: failureCount,
|
|
107
|
+
results,
|
|
108
|
+
timestamp: new Date().toISOString(),
|
|
109
|
+
}, null, 2));
|
|
110
|
+
process.exit(failureCount === 0 ? 0 : 1);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Compact JSON output
|
|
114
|
+
if (flags['compact-json']) {
|
|
115
|
+
(0, helper_1.outputCompactJson)({
|
|
116
|
+
total: results.length,
|
|
117
|
+
succeeded: successCount,
|
|
118
|
+
failed: failureCount,
|
|
119
|
+
results,
|
|
120
|
+
});
|
|
121
|
+
process.exit(failureCount === 0 ? 0 : 1);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Raw JSON output
|
|
125
|
+
if (flags.raw) {
|
|
126
|
+
(0, helper_1.outputRawJson)(results);
|
|
127
|
+
process.exit(failureCount === 0 ? 0 : 1);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// Table output (default)
|
|
131
|
+
const tableData = results.map(result => ({
|
|
132
|
+
id: result.id,
|
|
133
|
+
status: result.success ? 'deleted' : 'failed',
|
|
134
|
+
content: result.success && result.data
|
|
135
|
+
? (0, helper_1.getBlockPlainText)(result.data) || '-'
|
|
136
|
+
: result.message || result.error || 'Unknown error',
|
|
137
|
+
}));
|
|
138
|
+
const columns = {
|
|
139
|
+
id: {},
|
|
140
|
+
status: {},
|
|
141
|
+
content: {},
|
|
142
|
+
};
|
|
143
|
+
const options = {
|
|
144
|
+
printLine: this.log.bind(this),
|
|
145
|
+
...flags,
|
|
146
|
+
};
|
|
147
|
+
(0, table_formatter_1.formatTable)(tableData, columns, options);
|
|
148
|
+
this.log(`\nTotal: ${results.length} | Deleted: ${successCount} | Failed: ${failureCount}`);
|
|
149
|
+
process.exit(failureCount === 0 ? 0 : 1);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
153
|
+
? error
|
|
154
|
+
: (0, errors_1.wrapNotionError)(error, { endpoint: 'batch.delete' });
|
|
155
|
+
if (flags.json) {
|
|
156
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.error(cliError.toHumanString());
|
|
160
|
+
}
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
BatchDelete.description = 'Batch delete multiple blocks in parallel';
|
|
166
|
+
BatchDelete.aliases = ['batch:d'];
|
|
167
|
+
BatchDelete.examples = [
|
|
168
|
+
{
|
|
169
|
+
description: 'Delete multiple blocks via --ids flag',
|
|
170
|
+
command: '$ notion-cli batch delete --ids BLOCK_ID_1,BLOCK_ID_2,BLOCK_ID_3 --json',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
description: 'Delete blocks from stdin (one ID per line)',
|
|
174
|
+
command: '$ cat block_ids.txt | notion-cli batch delete --json',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
description: 'Delete using Notion URLs (auto-resolved)',
|
|
178
|
+
command: '$ notion-cli batch delete --ids "https://notion.so/Page-abc123,https://notion.so/Other-def456"',
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
BatchDelete.args = {
|
|
182
|
+
ids: core_1.Args.string({
|
|
183
|
+
required: false,
|
|
184
|
+
description: 'Comma-separated list of block IDs to delete (or use --ids flag or stdin)',
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
BatchDelete.flags = {
|
|
188
|
+
ids: core_1.Flags.string({
|
|
189
|
+
description: 'Comma-separated list of block IDs to delete',
|
|
190
|
+
}),
|
|
191
|
+
raw: core_1.Flags.boolean({
|
|
192
|
+
char: 'r',
|
|
193
|
+
description: 'output raw json',
|
|
194
|
+
}),
|
|
195
|
+
...table_formatter_1.tableFlags,
|
|
196
|
+
...base_flags_1.OutputFormatFlags,
|
|
197
|
+
...base_flags_1.AutomationFlags,
|
|
198
|
+
};
|
|
199
|
+
exports.default = BatchDelete;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class BatchRetrieve extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static aliases: string[];
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static args: {
|
|
10
|
+
ids: 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
|
+
markdown: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
'compact-json': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
pretty: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
24
|
+
sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
25
|
+
filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
26
|
+
csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
27
|
+
extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
28
|
+
'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
29
|
+
'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
30
|
+
ids: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
31
|
+
type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
32
|
+
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Read IDs from stdin
|
|
36
|
+
*/
|
|
37
|
+
private readStdin;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve a single resource and handle errors
|
|
40
|
+
*/
|
|
41
|
+
private retrieveResource;
|
|
42
|
+
run(): Promise<void>;
|
|
43
|
+
}
|