@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
package/dist/envelope.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JSON Envelope Standardization System for Notion CLI
|
|
4
|
+
*
|
|
5
|
+
* Provides consistent machine-readable output across all commands with:
|
|
6
|
+
* - Standard success/error envelopes
|
|
7
|
+
* - Metadata tracking (command, timestamp, execution time)
|
|
8
|
+
* - Exit code standardization (0=success, 1=API error, 2=CLI error)
|
|
9
|
+
* - Proper stdout/stderr separation
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EnvelopeFormatter = exports.ExitCode = void 0;
|
|
13
|
+
exports.createEnvelopeFormatter = createEnvelopeFormatter;
|
|
14
|
+
exports.isSuccessEnvelope = isSuccessEnvelope;
|
|
15
|
+
exports.isErrorEnvelope = isErrorEnvelope;
|
|
16
|
+
const index_1 = require("./errors/index");
|
|
17
|
+
/**
|
|
18
|
+
* Exit codes for consistent process termination
|
|
19
|
+
*/
|
|
20
|
+
var ExitCode;
|
|
21
|
+
(function (ExitCode) {
|
|
22
|
+
/** Command completed successfully */
|
|
23
|
+
ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
|
|
24
|
+
/** API/Notion error (auth, not found, rate limit, network, etc.) */
|
|
25
|
+
ExitCode[ExitCode["API_ERROR"] = 1] = "API_ERROR";
|
|
26
|
+
/** CLI/validation error (invalid args, syntax, config issues) */
|
|
27
|
+
ExitCode[ExitCode["CLI_ERROR"] = 2] = "CLI_ERROR";
|
|
28
|
+
})(ExitCode || (exports.ExitCode = ExitCode = {}));
|
|
29
|
+
/**
|
|
30
|
+
* Maps error codes to appropriate exit codes
|
|
31
|
+
*/
|
|
32
|
+
function getExitCodeForError(errorCode) {
|
|
33
|
+
// CLI/validation errors
|
|
34
|
+
const cliErrors = [
|
|
35
|
+
index_1.NotionCLIErrorCode.VALIDATION_ERROR,
|
|
36
|
+
'VALIDATION_ERROR',
|
|
37
|
+
'CLI_ERROR',
|
|
38
|
+
'CONFIG_ERROR',
|
|
39
|
+
'INVALID_ARGUMENT',
|
|
40
|
+
];
|
|
41
|
+
if (cliErrors.includes(errorCode)) {
|
|
42
|
+
return ExitCode.CLI_ERROR;
|
|
43
|
+
}
|
|
44
|
+
// All other errors are API-related
|
|
45
|
+
return ExitCode.API_ERROR;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Suggestion generator based on error codes
|
|
49
|
+
*/
|
|
50
|
+
function generateSuggestions(errorCode) {
|
|
51
|
+
const suggestions = [];
|
|
52
|
+
switch (errorCode) {
|
|
53
|
+
case index_1.NotionCLIErrorCode.UNAUTHORIZED:
|
|
54
|
+
suggestions.push('Verify your NOTION_TOKEN is set correctly');
|
|
55
|
+
suggestions.push('Check token at: https://www.notion.so/my-integrations');
|
|
56
|
+
break;
|
|
57
|
+
case index_1.NotionCLIErrorCode.NOT_FOUND:
|
|
58
|
+
suggestions.push('Verify the resource ID is correct');
|
|
59
|
+
suggestions.push('Ensure your integration has access to the resource');
|
|
60
|
+
suggestions.push('Try running: notion-cli sync');
|
|
61
|
+
break;
|
|
62
|
+
case index_1.NotionCLIErrorCode.RATE_LIMITED:
|
|
63
|
+
suggestions.push('Wait and retry - the CLI will auto-retry with backoff');
|
|
64
|
+
suggestions.push('Reduce request frequency if this persists');
|
|
65
|
+
break;
|
|
66
|
+
case index_1.NotionCLIErrorCode.VALIDATION_ERROR:
|
|
67
|
+
suggestions.push('Check command syntax: notion-cli [command] --help');
|
|
68
|
+
suggestions.push('Verify all required arguments are provided');
|
|
69
|
+
break;
|
|
70
|
+
case 'CLI_ERROR':
|
|
71
|
+
case 'CONFIG_ERROR':
|
|
72
|
+
suggestions.push('Run: notion-cli config set-token');
|
|
73
|
+
suggestions.push('Check your .env file configuration');
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
return suggestions;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* EnvelopeFormatter - Core utility for creating and outputting envelopes
|
|
80
|
+
*/
|
|
81
|
+
class EnvelopeFormatter {
|
|
82
|
+
/**
|
|
83
|
+
* Initialize formatter with command metadata
|
|
84
|
+
*
|
|
85
|
+
* @param commandName - Full command name (e.g., "page retrieve")
|
|
86
|
+
* @param version - CLI version from package.json
|
|
87
|
+
*/
|
|
88
|
+
constructor(commandName, version) {
|
|
89
|
+
this.startTime = Date.now();
|
|
90
|
+
this.commandName = commandName;
|
|
91
|
+
this.version = version;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create success envelope with data and metadata
|
|
95
|
+
*
|
|
96
|
+
* @param data - The actual response data
|
|
97
|
+
* @param additionalMetadata - Optional additional metadata fields
|
|
98
|
+
* @returns Success envelope ready for output
|
|
99
|
+
*/
|
|
100
|
+
wrapSuccess(data, additionalMetadata) {
|
|
101
|
+
const executionTime = Date.now() - this.startTime;
|
|
102
|
+
return {
|
|
103
|
+
success: true,
|
|
104
|
+
data,
|
|
105
|
+
metadata: {
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
command: this.commandName,
|
|
108
|
+
execution_time_ms: executionTime,
|
|
109
|
+
version: this.version,
|
|
110
|
+
...additionalMetadata,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create error envelope from Error, NotionCLIError, or raw error object
|
|
116
|
+
*
|
|
117
|
+
* @param error - Error instance or error object
|
|
118
|
+
* @param additionalContext - Optional additional error context
|
|
119
|
+
* @returns Error envelope ready for output
|
|
120
|
+
*/
|
|
121
|
+
wrapError(error, additionalContext) {
|
|
122
|
+
const executionTime = Date.now() - this.startTime;
|
|
123
|
+
let errorDetails;
|
|
124
|
+
// Handle NotionCLIError
|
|
125
|
+
if (error instanceof index_1.NotionCLIError) {
|
|
126
|
+
errorDetails = {
|
|
127
|
+
code: error.code,
|
|
128
|
+
message: error.message,
|
|
129
|
+
details: { ...error.context, ...additionalContext },
|
|
130
|
+
suggestions: error.suggestions.map(s => s.description),
|
|
131
|
+
notionError: error.context.originalError,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Handle standard Error
|
|
135
|
+
else if (error instanceof Error) {
|
|
136
|
+
errorDetails = {
|
|
137
|
+
code: 'UNKNOWN',
|
|
138
|
+
message: error.message,
|
|
139
|
+
details: { stack: error.stack, ...additionalContext },
|
|
140
|
+
suggestions: ['Check the error message for details'],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Handle raw error objects
|
|
144
|
+
else {
|
|
145
|
+
errorDetails = {
|
|
146
|
+
code: error.code || 'UNKNOWN',
|
|
147
|
+
message: error.message || 'An unknown error occurred',
|
|
148
|
+
details: { ...error, ...additionalContext },
|
|
149
|
+
suggestions: generateSuggestions(error.code || 'UNKNOWN'),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
success: false,
|
|
154
|
+
error: errorDetails,
|
|
155
|
+
metadata: {
|
|
156
|
+
timestamp: new Date().toISOString(),
|
|
157
|
+
command: this.commandName,
|
|
158
|
+
execution_time_ms: executionTime,
|
|
159
|
+
version: this.version,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Output envelope to stdout with proper formatting
|
|
165
|
+
* Handles flag-based format selection and stdout/stderr separation
|
|
166
|
+
*
|
|
167
|
+
* @param envelope - Success or error envelope
|
|
168
|
+
* @param flags - Output format flags
|
|
169
|
+
* @param logFn - Logging function (typically this.log from Command)
|
|
170
|
+
*/
|
|
171
|
+
outputEnvelope(envelope, flags, logFn = console.log) {
|
|
172
|
+
// Raw mode bypasses envelope - outputs data directly
|
|
173
|
+
if (flags.raw && envelope.success) {
|
|
174
|
+
logFn(JSON.stringify(envelope.data, null, 2));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
// Compact JSON - single line for piping
|
|
178
|
+
if (flags['compact-json']) {
|
|
179
|
+
logFn(JSON.stringify(envelope));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Default: Pretty JSON (--json flag or error state)
|
|
183
|
+
logFn(JSON.stringify(envelope, null, 2));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get appropriate exit code for the envelope
|
|
187
|
+
*
|
|
188
|
+
* @param envelope - Success or error envelope
|
|
189
|
+
* @returns Exit code (0, 1, or 2)
|
|
190
|
+
*/
|
|
191
|
+
getExitCode(envelope) {
|
|
192
|
+
if (envelope.success) {
|
|
193
|
+
return ExitCode.SUCCESS;
|
|
194
|
+
}
|
|
195
|
+
// Type narrowing: at this point, envelope is ErrorEnvelope
|
|
196
|
+
return getExitCodeForError(envelope.error.code);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Write diagnostic messages to stderr (won't pollute JSON on stdout)
|
|
200
|
+
* Useful for retry messages, cache hits, debug info, etc.
|
|
201
|
+
*
|
|
202
|
+
* @param message - Diagnostic message
|
|
203
|
+
* @param level - Message level (info, warn, error)
|
|
204
|
+
*/
|
|
205
|
+
static writeDiagnostic(message, level = 'info') {
|
|
206
|
+
const prefix = {
|
|
207
|
+
info: '[INFO]',
|
|
208
|
+
warn: '[WARN]',
|
|
209
|
+
error: '[ERROR]',
|
|
210
|
+
}[level];
|
|
211
|
+
// Write to stderr to avoid polluting JSON output on stdout
|
|
212
|
+
console.error(`${prefix} ${message}`);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Helper to log retry attempts to stderr (doesn't pollute JSON output)
|
|
216
|
+
*
|
|
217
|
+
* @param attempt - Retry attempt number
|
|
218
|
+
* @param maxRetries - Maximum retry attempts
|
|
219
|
+
* @param delay - Delay before next retry in milliseconds
|
|
220
|
+
*/
|
|
221
|
+
static logRetry(attempt, maxRetries, delay) {
|
|
222
|
+
EnvelopeFormatter.writeDiagnostic(`Retry attempt ${attempt}/${maxRetries} after ${delay}ms`, 'warn');
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Helper to log cache hits to stderr (for debugging)
|
|
226
|
+
*
|
|
227
|
+
* @param cacheKey - Cache key that was hit
|
|
228
|
+
*/
|
|
229
|
+
static logCacheHit(cacheKey) {
|
|
230
|
+
if (process.env.DEBUG === 'true') {
|
|
231
|
+
EnvelopeFormatter.writeDiagnostic(`Cache hit: ${cacheKey}`, 'info');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.EnvelopeFormatter = EnvelopeFormatter;
|
|
236
|
+
/**
|
|
237
|
+
* Convenience function to create an envelope formatter
|
|
238
|
+
*
|
|
239
|
+
* @param commandName - Full command name
|
|
240
|
+
* @param version - CLI version
|
|
241
|
+
* @returns New EnvelopeFormatter instance
|
|
242
|
+
*/
|
|
243
|
+
function createEnvelopeFormatter(commandName, version) {
|
|
244
|
+
return new EnvelopeFormatter(commandName, version);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Type guard to check if envelope is a success envelope
|
|
248
|
+
*/
|
|
249
|
+
function isSuccessEnvelope(envelope) {
|
|
250
|
+
return envelope.success === true;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Type guard to check if envelope is an error envelope
|
|
254
|
+
*/
|
|
255
|
+
function isErrorEnvelope(envelope) {
|
|
256
|
+
return envelope.success === false;
|
|
257
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced AI-Friendly Error Handling System
|
|
3
|
+
*
|
|
4
|
+
* Provides context-rich errors with actionable suggestions for:
|
|
5
|
+
* - AI assistants debugging automation failures
|
|
6
|
+
* - Human users troubleshooting CLI issues
|
|
7
|
+
* - Automated systems logging meaningful errors
|
|
8
|
+
*
|
|
9
|
+
* Key Features:
|
|
10
|
+
* - Error codes for programmatic handling
|
|
11
|
+
* - Contextual suggestions with fix commands
|
|
12
|
+
* - Support for both human and JSON output
|
|
13
|
+
* - Notion API error mapping
|
|
14
|
+
* - Common scenario detection
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Comprehensive error codes covering all common scenarios
|
|
18
|
+
*/
|
|
19
|
+
export declare enum NotionCLIErrorCode {
|
|
20
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
21
|
+
TOKEN_MISSING = "TOKEN_MISSING",
|
|
22
|
+
TOKEN_INVALID = "TOKEN_INVALID",
|
|
23
|
+
TOKEN_EXPIRED = "TOKEN_EXPIRED",
|
|
24
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
25
|
+
INTEGRATION_NOT_SHARED = "INTEGRATION_NOT_SHARED",
|
|
26
|
+
NOT_FOUND = "NOT_FOUND",
|
|
27
|
+
OBJECT_NOT_FOUND = "OBJECT_NOT_FOUND",
|
|
28
|
+
DATABASE_NOT_FOUND = "DATABASE_NOT_FOUND",
|
|
29
|
+
PAGE_NOT_FOUND = "PAGE_NOT_FOUND",
|
|
30
|
+
BLOCK_NOT_FOUND = "BLOCK_NOT_FOUND",
|
|
31
|
+
INVALID_ID_FORMAT = "INVALID_ID_FORMAT",
|
|
32
|
+
INVALID_DATABASE_ID = "INVALID_DATABASE_ID",
|
|
33
|
+
INVALID_PAGE_ID = "INVALID_PAGE_ID",
|
|
34
|
+
INVALID_BLOCK_ID = "INVALID_BLOCK_ID",
|
|
35
|
+
INVALID_URL = "INVALID_URL",
|
|
36
|
+
DATABASE_ID_CONFUSION = "DATABASE_ID_CONFUSION",// data_source_id vs database_id
|
|
37
|
+
WORKSPACE_VS_DATABASE = "WORKSPACE_VS_DATABASE",// workspace ID instead of database ID
|
|
38
|
+
RATE_LIMITED = "RATE_LIMITED",
|
|
39
|
+
API_ERROR = "API_ERROR",
|
|
40
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
41
|
+
TIMEOUT = "TIMEOUT",
|
|
42
|
+
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
43
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
44
|
+
INVALID_PROPERTY = "INVALID_PROPERTY",
|
|
45
|
+
INVALID_FILTER = "INVALID_FILTER",
|
|
46
|
+
INVALID_JSON = "INVALID_JSON",
|
|
47
|
+
MISSING_REQUIRED_FIELD = "MISSING_REQUIRED_FIELD",
|
|
48
|
+
CACHE_ERROR = "CACHE_ERROR",
|
|
49
|
+
WORKSPACE_NOT_SYNCED = "WORKSPACE_NOT_SYNCED",
|
|
50
|
+
UNKNOWN = "UNKNOWN",
|
|
51
|
+
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Suggested fix with command example
|
|
55
|
+
*/
|
|
56
|
+
export interface ErrorSuggestion {
|
|
57
|
+
description: string;
|
|
58
|
+
command?: string;
|
|
59
|
+
link?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Contextual error information for better debugging
|
|
63
|
+
*/
|
|
64
|
+
export interface ErrorContext {
|
|
65
|
+
/** The resource type being accessed */
|
|
66
|
+
resourceType?: 'database' | 'page' | 'block' | 'user' | 'workspace';
|
|
67
|
+
/** The ID that was attempted */
|
|
68
|
+
attemptedId?: string;
|
|
69
|
+
/** The input that led to the error */
|
|
70
|
+
userInput?: string;
|
|
71
|
+
/** The API endpoint that failed */
|
|
72
|
+
endpoint?: string;
|
|
73
|
+
/** HTTP status code if applicable */
|
|
74
|
+
statusCode?: number;
|
|
75
|
+
/** Original error from Notion API or other source */
|
|
76
|
+
originalError?: any;
|
|
77
|
+
/** Additional debug information */
|
|
78
|
+
metadata?: Record<string, any>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Enhanced CLI Error with AI-friendly formatting
|
|
82
|
+
*/
|
|
83
|
+
export declare class NotionCLIError extends Error {
|
|
84
|
+
readonly code: NotionCLIErrorCode;
|
|
85
|
+
readonly userMessage: string;
|
|
86
|
+
readonly suggestions: ErrorSuggestion[];
|
|
87
|
+
readonly context: ErrorContext;
|
|
88
|
+
readonly timestamp: string;
|
|
89
|
+
constructor(code: NotionCLIErrorCode, userMessage: string, suggestions?: ErrorSuggestion[], context?: ErrorContext);
|
|
90
|
+
/**
|
|
91
|
+
* Format error for human-readable console output
|
|
92
|
+
*/
|
|
93
|
+
toHumanString(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Format error for JSON output (automation-friendly)
|
|
96
|
+
*/
|
|
97
|
+
toJSON(): {
|
|
98
|
+
success: boolean;
|
|
99
|
+
error: {
|
|
100
|
+
code: NotionCLIErrorCode;
|
|
101
|
+
message: string;
|
|
102
|
+
suggestions: ErrorSuggestion[];
|
|
103
|
+
context: ErrorContext;
|
|
104
|
+
timestamp: string;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Format error for compact JSON (single-line)
|
|
109
|
+
*/
|
|
110
|
+
toCompactJSON(): string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Error factory functions for common scenarios
|
|
114
|
+
*/
|
|
115
|
+
export declare class NotionCLIErrorFactory {
|
|
116
|
+
/**
|
|
117
|
+
* Token is missing or not set
|
|
118
|
+
*/
|
|
119
|
+
static tokenMissing(): NotionCLIError;
|
|
120
|
+
/**
|
|
121
|
+
* Token is invalid or expired
|
|
122
|
+
*/
|
|
123
|
+
static tokenInvalid(): NotionCLIError;
|
|
124
|
+
/**
|
|
125
|
+
* Integration not shared with resource
|
|
126
|
+
*/
|
|
127
|
+
static integrationNotShared(resourceType: 'database' | 'page', resourceId?: string): NotionCLIError;
|
|
128
|
+
/**
|
|
129
|
+
* Database/Page/Block not found
|
|
130
|
+
*/
|
|
131
|
+
static resourceNotFound(resourceType: 'database' | 'page' | 'block', identifier: string): NotionCLIError;
|
|
132
|
+
/**
|
|
133
|
+
* Invalid ID format
|
|
134
|
+
*/
|
|
135
|
+
static invalidIdFormat(input: string, resourceType?: 'database' | 'page' | 'block'): NotionCLIError;
|
|
136
|
+
/**
|
|
137
|
+
* Common confusion: using database_id when data_source_id is needed
|
|
138
|
+
*/
|
|
139
|
+
static databaseIdConfusion(attemptedId: string): NotionCLIError;
|
|
140
|
+
/**
|
|
141
|
+
* Workspace not synced (cache miss for name resolution)
|
|
142
|
+
*/
|
|
143
|
+
static workspaceNotSynced(databaseName: string): NotionCLIError;
|
|
144
|
+
/**
|
|
145
|
+
* Rate limited by Notion API
|
|
146
|
+
*/
|
|
147
|
+
static rateLimited(retryAfter?: number): NotionCLIError;
|
|
148
|
+
/**
|
|
149
|
+
* Invalid JSON in filter or property value
|
|
150
|
+
*/
|
|
151
|
+
static invalidJson(jsonString: string, parseError: Error): NotionCLIError;
|
|
152
|
+
/**
|
|
153
|
+
* Invalid property name or type
|
|
154
|
+
*/
|
|
155
|
+
static invalidProperty(propertyName: string, databaseId?: string): NotionCLIError;
|
|
156
|
+
/**
|
|
157
|
+
* Network or connection error
|
|
158
|
+
*/
|
|
159
|
+
static networkError(originalError: Error): NotionCLIError;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Map Notion API errors to CLI errors with context
|
|
163
|
+
*/
|
|
164
|
+
export declare function wrapNotionError(error: any, context?: ErrorContext): NotionCLIError;
|
|
165
|
+
/**
|
|
166
|
+
* Handle CLI errors with proper formatting based on output mode
|
|
167
|
+
*/
|
|
168
|
+
export declare function handleCliError(error: any, outputJson?: boolean, context?: ErrorContext): never;
|