@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,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const notion_1 = require("../notion");
|
|
5
|
+
const retry_1 = require("../retry");
|
|
6
|
+
const workspace_cache_1 = require("../utils/workspace-cache");
|
|
7
|
+
const base_flags_1 = require("../base-flags");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
const token_validator_1 = require("../utils/token-validator");
|
|
10
|
+
class Sync extends core_1.Command {
|
|
11
|
+
async run() {
|
|
12
|
+
const { flags } = await this.parse(Sync);
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
try {
|
|
15
|
+
// Verify NOTION_TOKEN is set (throws if not)
|
|
16
|
+
(0, token_validator_1.validateNotionToken)();
|
|
17
|
+
if (!flags.json) {
|
|
18
|
+
core_1.ux.action.start('Syncing workspace databases');
|
|
19
|
+
}
|
|
20
|
+
// Fetch all databases from Notion API with progress updates
|
|
21
|
+
const databases = await this.fetchAllDatabases(flags.json);
|
|
22
|
+
// const _fetchTime = Date.now() - startTime
|
|
23
|
+
if (!flags.json) {
|
|
24
|
+
core_1.ux.action.stop(`Found ${databases.length} database${databases.length === 1 ? '' : 's'}`);
|
|
25
|
+
core_1.ux.action.start('Generating search aliases');
|
|
26
|
+
}
|
|
27
|
+
// Build cache entries
|
|
28
|
+
const cacheEntries = databases.map(db => (0, workspace_cache_1.buildCacheEntry)(db));
|
|
29
|
+
if (!flags.json) {
|
|
30
|
+
core_1.ux.action.stop();
|
|
31
|
+
core_1.ux.action.start('Saving cache');
|
|
32
|
+
}
|
|
33
|
+
// Save to cache
|
|
34
|
+
const cache = {
|
|
35
|
+
version: '1.0.0',
|
|
36
|
+
lastSync: new Date().toISOString(),
|
|
37
|
+
databases: cacheEntries,
|
|
38
|
+
};
|
|
39
|
+
await (0, workspace_cache_1.saveCache)(cache);
|
|
40
|
+
const cachePath = await (0, workspace_cache_1.getCachePath)();
|
|
41
|
+
const executionTime = Date.now() - startTime;
|
|
42
|
+
// Build comprehensive metadata
|
|
43
|
+
const metadata = {
|
|
44
|
+
sync_time: new Date().toISOString(),
|
|
45
|
+
execution_time_ms: executionTime,
|
|
46
|
+
databases_found: databases.length,
|
|
47
|
+
cache_ttls: {
|
|
48
|
+
in_memory: {
|
|
49
|
+
data_source_ms: parseInt(process.env.NOTION_CLI_CACHE_DS_TTL || '600000', 10),
|
|
50
|
+
page_ms: parseInt(process.env.NOTION_CLI_CACHE_PAGE_TTL || '60000', 10),
|
|
51
|
+
user_ms: parseInt(process.env.NOTION_CLI_CACHE_USER_TTL || '3600000', 10),
|
|
52
|
+
block_ms: parseInt(process.env.NOTION_CLI_CACHE_BLOCK_TTL || '30000', 10),
|
|
53
|
+
},
|
|
54
|
+
workspace: {
|
|
55
|
+
persistence: 'until next sync',
|
|
56
|
+
recommended_sync_interval_hours: 24,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
next_recommended_sync: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
|
|
60
|
+
cache_location: cachePath,
|
|
61
|
+
};
|
|
62
|
+
if (flags.json) {
|
|
63
|
+
this.log(JSON.stringify({
|
|
64
|
+
success: true,
|
|
65
|
+
data: {
|
|
66
|
+
databases: cacheEntries.map(db => ({
|
|
67
|
+
id: db.id,
|
|
68
|
+
title: db.title,
|
|
69
|
+
aliases: db.aliases,
|
|
70
|
+
url: db.url,
|
|
71
|
+
})),
|
|
72
|
+
summary: {
|
|
73
|
+
total: databases.length,
|
|
74
|
+
cached_at: cache.lastSync,
|
|
75
|
+
cache_version: cache.version,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
metadata,
|
|
79
|
+
}, null, 2));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
core_1.ux.action.stop();
|
|
83
|
+
// Enhanced completion summary
|
|
84
|
+
const elapsedSeconds = (executionTime / 1000).toFixed(2);
|
|
85
|
+
this.log(`\n✓ Synced ${databases.length} database${databases.length === 1 ? '' : 's'} in ${elapsedSeconds}s`);
|
|
86
|
+
this.log('');
|
|
87
|
+
this.log(`📁 Cache: ${cachePath}`);
|
|
88
|
+
this.log(`🕐 Last updated: ${new Date(cache.lastSync).toLocaleString()}`);
|
|
89
|
+
this.log(`📊 Databases: ${databases.length} total`);
|
|
90
|
+
this.log('');
|
|
91
|
+
this.log(`Next sync recommended: ${new Date(metadata.next_recommended_sync).toLocaleString()}`);
|
|
92
|
+
if (databases.length > 0) {
|
|
93
|
+
this.log('\nIndexed databases:');
|
|
94
|
+
cacheEntries.slice(0, 10).forEach(db => {
|
|
95
|
+
const aliasesStr = db.aliases.slice(0, 3).join(', ');
|
|
96
|
+
this.log(` • ${db.title} (aliases: ${aliasesStr})`);
|
|
97
|
+
});
|
|
98
|
+
if (databases.length > 10) {
|
|
99
|
+
this.log(` ... and ${databases.length - 10} more`);
|
|
100
|
+
}
|
|
101
|
+
this.log('\nTry: notion-cli list');
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.log('\nNo databases found in workspace.');
|
|
105
|
+
this.log('Make sure your integration has access to databases.');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
112
|
+
? error
|
|
113
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
114
|
+
endpoint: 'search',
|
|
115
|
+
resourceType: 'database'
|
|
116
|
+
});
|
|
117
|
+
if (flags.json) {
|
|
118
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
core_1.ux.action.stop('failed');
|
|
122
|
+
this.error(cliError.toHumanString());
|
|
123
|
+
}
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Fetch all databases from Notion API with pagination
|
|
129
|
+
*/
|
|
130
|
+
async fetchAllDatabases(isJsonMode) {
|
|
131
|
+
const databases = [];
|
|
132
|
+
let cursor = undefined;
|
|
133
|
+
while (true) {
|
|
134
|
+
const response = await (0, retry_1.fetchWithRetry)(() => notion_1.client.search({
|
|
135
|
+
filter: {
|
|
136
|
+
value: 'data_source',
|
|
137
|
+
property: 'object',
|
|
138
|
+
},
|
|
139
|
+
start_cursor: cursor,
|
|
140
|
+
page_size: 100, // Max allowed by API
|
|
141
|
+
}), {
|
|
142
|
+
context: 'sync:fetchAllDatabases',
|
|
143
|
+
config: { maxRetries: 5 }, // Higher retries for sync
|
|
144
|
+
});
|
|
145
|
+
databases.push(...response.results);
|
|
146
|
+
// Show progress update (only in non-JSON mode)
|
|
147
|
+
if (!isJsonMode && response.has_more) {
|
|
148
|
+
// Update the spinner text to show current count
|
|
149
|
+
core_1.ux.action.start(`Syncing workspace databases (found ${databases.length} so far)`);
|
|
150
|
+
}
|
|
151
|
+
if (!response.has_more || !response.next_cursor) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
cursor = response.next_cursor;
|
|
155
|
+
}
|
|
156
|
+
return databases;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
Sync.description = 'Sync workspace databases to local cache for fast lookups';
|
|
160
|
+
Sync.aliases = ['db:sync'];
|
|
161
|
+
Sync.examples = [
|
|
162
|
+
{
|
|
163
|
+
description: 'Sync all workspace databases',
|
|
164
|
+
command: 'notion-cli sync',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
description: 'Force resync even if cache exists',
|
|
168
|
+
command: 'notion-cli sync --force',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
description: 'Sync and output as JSON',
|
|
172
|
+
command: 'notion-cli sync --json',
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
Sync.flags = {
|
|
176
|
+
force: core_1.Flags.boolean({
|
|
177
|
+
char: 'f',
|
|
178
|
+
description: 'Force resync even if cache is fresh',
|
|
179
|
+
default: false,
|
|
180
|
+
}),
|
|
181
|
+
...base_flags_1.AutomationFlags,
|
|
182
|
+
};
|
|
183
|
+
exports.default = Sync;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class UserList 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
|
+
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
25
|
+
};
|
|
26
|
+
run(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 UserList extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const { flags } = await this.parse(UserList);
|
|
12
|
+
try {
|
|
13
|
+
let res = await notion.listUser();
|
|
14
|
+
// Apply minimal flag to strip metadata
|
|
15
|
+
if (flags.minimal) {
|
|
16
|
+
res = (0, helper_1.stripMetadata)(res);
|
|
17
|
+
}
|
|
18
|
+
// Handle JSON output for automation
|
|
19
|
+
if (flags.json) {
|
|
20
|
+
this.log(JSON.stringify({
|
|
21
|
+
success: true,
|
|
22
|
+
data: res,
|
|
23
|
+
timestamp: new Date().toISOString()
|
|
24
|
+
}, null, 2));
|
|
25
|
+
process.exit(0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Handle raw JSON output (legacy)
|
|
29
|
+
if (flags.raw) {
|
|
30
|
+
(0, helper_1.outputRawJson)(res);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Handle table output
|
|
35
|
+
const columns = {
|
|
36
|
+
id: {},
|
|
37
|
+
name: {},
|
|
38
|
+
object: {},
|
|
39
|
+
type: {},
|
|
40
|
+
person_or_bot: {
|
|
41
|
+
header: 'person/bot',
|
|
42
|
+
get: (row) => {
|
|
43
|
+
if (row.type === 'person') {
|
|
44
|
+
return row.person;
|
|
45
|
+
}
|
|
46
|
+
return row.bot;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
avatar_url: {},
|
|
50
|
+
};
|
|
51
|
+
const options = {
|
|
52
|
+
printLine: this.log.bind(this),
|
|
53
|
+
...flags,
|
|
54
|
+
};
|
|
55
|
+
(0, table_formatter_1.formatTable)(res.results, columns, options);
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
60
|
+
? error
|
|
61
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
62
|
+
resourceType: 'user',
|
|
63
|
+
endpoint: 'users.list'
|
|
64
|
+
});
|
|
65
|
+
if (flags.json) {
|
|
66
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.error(cliError.toHumanString());
|
|
70
|
+
}
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
UserList.description = 'List all users';
|
|
76
|
+
UserList.aliases = ['user:l'];
|
|
77
|
+
UserList.examples = [
|
|
78
|
+
{
|
|
79
|
+
description: 'List all users',
|
|
80
|
+
command: `$ notion-cli user list`,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
description: 'List all users and output raw json',
|
|
84
|
+
command: `$ notion-cli user list -r`,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
description: 'List all users and output JSON for automation',
|
|
88
|
+
command: `$ notion-cli user list --json`,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
UserList.flags = {
|
|
92
|
+
raw: core_1.Flags.boolean({
|
|
93
|
+
char: 'r',
|
|
94
|
+
description: 'output raw json',
|
|
95
|
+
}),
|
|
96
|
+
...table_formatter_1.tableFlags,
|
|
97
|
+
...base_flags_1.AutomationFlags,
|
|
98
|
+
};
|
|
99
|
+
exports.default = UserList;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class UserRetrieveBot extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static aliases: string[];
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static args: {};
|
|
10
|
+
static flags: {
|
|
11
|
+
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
|
+
retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
|
+
sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
+
filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
21
|
+
csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
24
|
+
'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
25
|
+
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
26
|
+
};
|
|
27
|
+
run(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 UserRetrieveBot extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const { flags } = await this.parse(UserRetrieveBot);
|
|
12
|
+
try {
|
|
13
|
+
const res = await notion.botUser();
|
|
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
|
+
id: {},
|
|
33
|
+
name: {},
|
|
34
|
+
object: {},
|
|
35
|
+
type: {},
|
|
36
|
+
person_or_bot: {
|
|
37
|
+
header: 'person/bot',
|
|
38
|
+
get: (row) => {
|
|
39
|
+
if (row.type === 'person') {
|
|
40
|
+
return row.person;
|
|
41
|
+
}
|
|
42
|
+
return row.bot;
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
avatar_url: {},
|
|
46
|
+
};
|
|
47
|
+
const options = {
|
|
48
|
+
printLine: this.log.bind(this),
|
|
49
|
+
...flags,
|
|
50
|
+
};
|
|
51
|
+
(0, table_formatter_1.formatTable)([res], columns, options);
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
56
|
+
? error
|
|
57
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
58
|
+
resourceType: 'user',
|
|
59
|
+
endpoint: 'users.me'
|
|
60
|
+
});
|
|
61
|
+
if (flags.json) {
|
|
62
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.error(cliError.toHumanString());
|
|
66
|
+
}
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
UserRetrieveBot.description = 'Retrieve a bot user';
|
|
72
|
+
UserRetrieveBot.aliases = ['user:r:b'];
|
|
73
|
+
UserRetrieveBot.examples = [
|
|
74
|
+
{
|
|
75
|
+
description: 'Retrieve a bot user',
|
|
76
|
+
command: `$ notion-cli user retrieve:bot`,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
description: 'Retrieve a bot user and output raw json',
|
|
80
|
+
command: `$ notion-cli user retrieve:bot -r`,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
description: 'Retrieve a bot user and output JSON for automation',
|
|
84
|
+
command: `$ notion-cli user retrieve:bot --json`,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
UserRetrieveBot.args = {};
|
|
88
|
+
UserRetrieveBot.flags = {
|
|
89
|
+
raw: core_1.Flags.boolean({
|
|
90
|
+
char: 'r',
|
|
91
|
+
description: 'output raw json',
|
|
92
|
+
}),
|
|
93
|
+
...table_formatter_1.tableFlags,
|
|
94
|
+
...base_flags_1.AutomationFlags,
|
|
95
|
+
};
|
|
96
|
+
exports.default = UserRetrieveBot;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class UserRetrieve extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static aliases: string[];
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static args: {
|
|
10
|
+
user_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,103 @@
|
|
|
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 UserRetrieve extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(UserRetrieve);
|
|
12
|
+
try {
|
|
13
|
+
let res = await notion.retrieveUser(args.user_id);
|
|
14
|
+
// Apply minimal flag to strip metadata
|
|
15
|
+
if (flags.minimal) {
|
|
16
|
+
res = (0, helper_1.stripMetadata)(res);
|
|
17
|
+
}
|
|
18
|
+
// Handle JSON output for automation
|
|
19
|
+
if (flags.json) {
|
|
20
|
+
this.log(JSON.stringify({
|
|
21
|
+
success: true,
|
|
22
|
+
data: res,
|
|
23
|
+
timestamp: new Date().toISOString()
|
|
24
|
+
}, null, 2));
|
|
25
|
+
process.exit(0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Handle raw JSON output (legacy)
|
|
29
|
+
if (flags.raw) {
|
|
30
|
+
(0, helper_1.outputRawJson)(res);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Handle table output
|
|
35
|
+
const columns = {
|
|
36
|
+
id: {},
|
|
37
|
+
name: {},
|
|
38
|
+
object: {},
|
|
39
|
+
type: {},
|
|
40
|
+
person_or_bot: {
|
|
41
|
+
header: 'person/bot',
|
|
42
|
+
get: (row) => {
|
|
43
|
+
if (row.type === 'person') {
|
|
44
|
+
return row.person;
|
|
45
|
+
}
|
|
46
|
+
return row.bot;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
avatar_url: {},
|
|
50
|
+
};
|
|
51
|
+
const options = {
|
|
52
|
+
printLine: this.log.bind(this),
|
|
53
|
+
...flags,
|
|
54
|
+
};
|
|
55
|
+
(0, table_formatter_1.formatTable)([res], columns, options);
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const cliError = error instanceof errors_1.NotionCLIError
|
|
60
|
+
? error
|
|
61
|
+
: (0, errors_1.wrapNotionError)(error, {
|
|
62
|
+
resourceType: 'user',
|
|
63
|
+
attemptedId: args.user_id,
|
|
64
|
+
endpoint: 'users.retrieve'
|
|
65
|
+
});
|
|
66
|
+
if (flags.json) {
|
|
67
|
+
this.log(JSON.stringify(cliError.toJSON(), null, 2));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.error(cliError.toHumanString());
|
|
71
|
+
}
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
UserRetrieve.description = 'Retrieve a user';
|
|
77
|
+
UserRetrieve.aliases = ['user:r'];
|
|
78
|
+
UserRetrieve.examples = [
|
|
79
|
+
{
|
|
80
|
+
description: 'Retrieve a user',
|
|
81
|
+
command: `$ notion-cli user retrieve USER_ID`,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
description: 'Retrieve a user and output raw json',
|
|
85
|
+
command: `$ notion-cli user retrieve USER_ID -r`,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
description: 'Retrieve a user and output JSON for automation',
|
|
89
|
+
command: `$ notion-cli user retrieve USER_ID --json`,
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
UserRetrieve.args = {
|
|
93
|
+
user_id: core_1.Args.string(),
|
|
94
|
+
};
|
|
95
|
+
UserRetrieve.flags = {
|
|
96
|
+
raw: core_1.Flags.boolean({
|
|
97
|
+
char: 'r',
|
|
98
|
+
description: 'output raw json',
|
|
99
|
+
}),
|
|
100
|
+
...table_formatter_1.tableFlags,
|
|
101
|
+
...base_flags_1.AutomationFlags,
|
|
102
|
+
};
|
|
103
|
+
exports.default = UserRetrieve;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Whoami 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
|
+
};
|
|
18
|
+
run(): Promise<void>;
|
|
19
|
+
}
|