@catafal/notion-cli 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +552 -0
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +14 -0
  6. package/bin/run.cmd +3 -0
  7. package/dist/base-command.d.ts +73 -0
  8. package/dist/base-command.js +179 -0
  9. package/dist/base-flags.d.ts +14 -0
  10. package/dist/base-flags.js +59 -0
  11. package/dist/cache.d.ts +84 -0
  12. package/dist/cache.js +351 -0
  13. package/dist/commands/append.d.ts +37 -0
  14. package/dist/commands/append.js +120 -0
  15. package/dist/commands/batch/delete.d.ts +42 -0
  16. package/dist/commands/batch/delete.js +199 -0
  17. package/dist/commands/batch/retrieve.d.ts +43 -0
  18. package/dist/commands/batch/retrieve.js +272 -0
  19. package/dist/commands/block/append.d.ts +42 -0
  20. package/dist/commands/block/append.js +219 -0
  21. package/dist/commands/block/delete.d.ts +30 -0
  22. package/dist/commands/block/delete.js +97 -0
  23. package/dist/commands/block/retrieve/children.d.ts +31 -0
  24. package/dist/commands/block/retrieve/children.js +177 -0
  25. package/dist/commands/block/retrieve.d.ts +30 -0
  26. package/dist/commands/block/retrieve.js +101 -0
  27. package/dist/commands/block/update.d.ts +45 -0
  28. package/dist/commands/block/update.js +242 -0
  29. package/dist/commands/bookmark/list.d.ts +30 -0
  30. package/dist/commands/bookmark/list.js +60 -0
  31. package/dist/commands/bookmark/remove.d.ts +26 -0
  32. package/dist/commands/bookmark/remove.js +47 -0
  33. package/dist/commands/bookmark/set.d.ts +29 -0
  34. package/dist/commands/bookmark/set.js +96 -0
  35. package/dist/commands/browse.d.ts +13 -0
  36. package/dist/commands/browse.js +44 -0
  37. package/dist/commands/cache/info.d.ts +19 -0
  38. package/dist/commands/cache/info.js +145 -0
  39. package/dist/commands/config/set-token.d.ts +22 -0
  40. package/dist/commands/config/set-token.js +137 -0
  41. package/dist/commands/daily/index.d.ts +32 -0
  42. package/dist/commands/daily/index.js +135 -0
  43. package/dist/commands/daily/setup.d.ts +42 -0
  44. package/dist/commands/daily/setup.js +149 -0
  45. package/dist/commands/db/create.d.ts +31 -0
  46. package/dist/commands/db/create.js +124 -0
  47. package/dist/commands/db/query.d.ts +41 -0
  48. package/dist/commands/db/query.js +360 -0
  49. package/dist/commands/db/retrieve.d.ts +33 -0
  50. package/dist/commands/db/retrieve.js +134 -0
  51. package/dist/commands/db/schema.d.ts +32 -0
  52. package/dist/commands/db/schema.js +308 -0
  53. package/dist/commands/db/update.d.ts +31 -0
  54. package/dist/commands/db/update.js +117 -0
  55. package/dist/commands/doctor.d.ts +50 -0
  56. package/dist/commands/doctor.js +420 -0
  57. package/dist/commands/init.d.ts +65 -0
  58. package/dist/commands/init.js +479 -0
  59. package/dist/commands/list.d.ts +29 -0
  60. package/dist/commands/list.js +219 -0
  61. package/dist/commands/open.d.ts +29 -0
  62. package/dist/commands/open.js +100 -0
  63. package/dist/commands/page/create.d.ts +33 -0
  64. package/dist/commands/page/create.js +261 -0
  65. package/dist/commands/page/delete.d.ts +36 -0
  66. package/dist/commands/page/delete.js +107 -0
  67. package/dist/commands/page/export.d.ts +38 -0
  68. package/dist/commands/page/export.js +120 -0
  69. package/dist/commands/page/retrieve/property_item.d.ts +24 -0
  70. package/dist/commands/page/retrieve/property_item.js +75 -0
  71. package/dist/commands/page/retrieve.d.ts +36 -0
  72. package/dist/commands/page/retrieve.js +244 -0
  73. package/dist/commands/page/update.d.ts +34 -0
  74. package/dist/commands/page/update.js +184 -0
  75. package/dist/commands/quick.d.ts +35 -0
  76. package/dist/commands/quick.js +168 -0
  77. package/dist/commands/search.d.ts +43 -0
  78. package/dist/commands/search.js +361 -0
  79. package/dist/commands/stats.d.ts +35 -0
  80. package/dist/commands/stats.js +274 -0
  81. package/dist/commands/sync.d.ts +24 -0
  82. package/dist/commands/sync.js +183 -0
  83. package/dist/commands/template/get.d.ts +28 -0
  84. package/dist/commands/template/get.js +59 -0
  85. package/dist/commands/template/list.d.ts +32 -0
  86. package/dist/commands/template/list.js +62 -0
  87. package/dist/commands/template/remove.d.ts +27 -0
  88. package/dist/commands/template/remove.js +48 -0
  89. package/dist/commands/template/save.d.ts +32 -0
  90. package/dist/commands/template/save.js +92 -0
  91. package/dist/commands/template/use.d.ts +34 -0
  92. package/dist/commands/template/use.js +142 -0
  93. package/dist/commands/user/list.d.ts +27 -0
  94. package/dist/commands/user/list.js +99 -0
  95. package/dist/commands/user/retrieve/bot.d.ts +28 -0
  96. package/dist/commands/user/retrieve/bot.js +96 -0
  97. package/dist/commands/user/retrieve.d.ts +30 -0
  98. package/dist/commands/user/retrieve.js +103 -0
  99. package/dist/commands/whoami.d.ts +19 -0
  100. package/dist/commands/whoami.js +175 -0
  101. package/dist/deduplication.d.ts +41 -0
  102. package/dist/deduplication.js +71 -0
  103. package/dist/envelope.d.ts +169 -0
  104. package/dist/envelope.js +257 -0
  105. package/dist/errors/enhanced-errors.d.ts +168 -0
  106. package/dist/errors/enhanced-errors.js +567 -0
  107. package/dist/errors/index.d.ts +18 -0
  108. package/dist/errors/index.js +33 -0
  109. package/dist/examples/cache-retry-examples.d.ts +64 -0
  110. package/dist/examples/cache-retry-examples.js +375 -0
  111. package/dist/helper.d.ts +102 -0
  112. package/dist/helper.js +885 -0
  113. package/dist/http-agent.d.ts +38 -0
  114. package/dist/http-agent.js +60 -0
  115. package/dist/index.d.ts +1 -0
  116. package/dist/index.js +4 -0
  117. package/dist/interface.d.ts +4 -0
  118. package/dist/interface.js +2 -0
  119. package/dist/notion.d.ts +144 -0
  120. package/dist/notion.js +547 -0
  121. package/dist/retry.d.ts +72 -0
  122. package/dist/retry.js +381 -0
  123. package/dist/utils/bookmarks.d.ts +32 -0
  124. package/dist/utils/bookmarks.js +98 -0
  125. package/dist/utils/daily-config.d.ts +22 -0
  126. package/dist/utils/daily-config.js +60 -0
  127. package/dist/utils/disk-cache.d.ts +80 -0
  128. package/dist/utils/disk-cache.js +291 -0
  129. package/dist/utils/fuzzy.d.ts +36 -0
  130. package/dist/utils/fuzzy.js +69 -0
  131. package/dist/utils/interactive-navigator.d.ts +63 -0
  132. package/dist/utils/interactive-navigator.js +123 -0
  133. package/dist/utils/markdown-to-blocks.d.ts +21 -0
  134. package/dist/utils/markdown-to-blocks.js +333 -0
  135. package/dist/utils/notion-resolver.d.ts +49 -0
  136. package/dist/utils/notion-resolver.js +278 -0
  137. package/dist/utils/notion-url-parser.d.ts +48 -0
  138. package/dist/utils/notion-url-parser.js +121 -0
  139. package/dist/utils/property-expander.d.ts +45 -0
  140. package/dist/utils/property-expander.js +323 -0
  141. package/dist/utils/schema-examples.d.ts +40 -0
  142. package/dist/utils/schema-examples.js +359 -0
  143. package/dist/utils/schema-extractor.d.ts +65 -0
  144. package/dist/utils/schema-extractor.js +235 -0
  145. package/dist/utils/shell-config.d.ts +30 -0
  146. package/dist/utils/shell-config.js +84 -0
  147. package/dist/utils/table-formatter.d.ts +36 -0
  148. package/dist/utils/table-formatter.js +125 -0
  149. package/dist/utils/templates.d.ts +30 -0
  150. package/dist/utils/templates.js +82 -0
  151. package/dist/utils/terminal-banner.d.ts +24 -0
  152. package/dist/utils/terminal-banner.js +34 -0
  153. package/dist/utils/token-validator.d.ts +42 -0
  154. package/dist/utils/token-validator.js +66 -0
  155. package/dist/utils/update-notifier.d.ts +26 -0
  156. package/dist/utils/update-notifier.js +54 -0
  157. package/dist/utils/workspace-cache.d.ts +58 -0
  158. package/dist/utils/workspace-cache.js +185 -0
  159. package/oclif.manifest.json +6471 -0
  160. package/package.json +118 -0
  161. package/scripts/banner.js +38 -0
  162. package/scripts/postinstall.js +44 -0
@@ -0,0 +1,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;