@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.
Files changed (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1386 -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/batch/retrieve.d.ts +43 -0
  14. package/dist/commands/batch/retrieve.js +265 -0
  15. package/dist/commands/block/append.d.ts +42 -0
  16. package/dist/commands/block/append.js +219 -0
  17. package/dist/commands/block/delete.d.ts +30 -0
  18. package/dist/commands/block/delete.js +94 -0
  19. package/dist/commands/block/retrieve/children.d.ts +31 -0
  20. package/dist/commands/block/retrieve/children.js +174 -0
  21. package/dist/commands/block/retrieve.d.ts +30 -0
  22. package/dist/commands/block/retrieve.js +98 -0
  23. package/dist/commands/block/update.d.ts +45 -0
  24. package/dist/commands/block/update.js +241 -0
  25. package/dist/commands/cache/info.d.ts +19 -0
  26. package/dist/commands/cache/info.js +145 -0
  27. package/dist/commands/config/set-token.d.ts +30 -0
  28. package/dist/commands/config/set-token.js +201 -0
  29. package/dist/commands/db/create.d.ts +31 -0
  30. package/dist/commands/db/create.js +124 -0
  31. package/dist/commands/db/query.d.ts +41 -0
  32. package/dist/commands/db/query.js +355 -0
  33. package/dist/commands/db/retrieve.d.ts +33 -0
  34. package/dist/commands/db/retrieve.js +134 -0
  35. package/dist/commands/db/schema.d.ts +32 -0
  36. package/dist/commands/db/schema.js +308 -0
  37. package/dist/commands/db/update.d.ts +31 -0
  38. package/dist/commands/db/update.js +117 -0
  39. package/dist/commands/doctor.d.ts +50 -0
  40. package/dist/commands/doctor.js +420 -0
  41. package/dist/commands/init.d.ts +57 -0
  42. package/dist/commands/init.js +471 -0
  43. package/dist/commands/list.d.ts +29 -0
  44. package/dist/commands/list.js +184 -0
  45. package/dist/commands/page/create.d.ts +33 -0
  46. package/dist/commands/page/create.js +240 -0
  47. package/dist/commands/page/retrieve/property_item.d.ts +24 -0
  48. package/dist/commands/page/retrieve/property_item.js +72 -0
  49. package/dist/commands/page/retrieve.d.ts +36 -0
  50. package/dist/commands/page/retrieve.js +244 -0
  51. package/dist/commands/page/update.d.ts +34 -0
  52. package/dist/commands/page/update.js +184 -0
  53. package/dist/commands/search.d.ts +40 -0
  54. package/dist/commands/search.js +348 -0
  55. package/dist/commands/sync.d.ts +24 -0
  56. package/dist/commands/sync.js +183 -0
  57. package/dist/commands/user/list.d.ts +27 -0
  58. package/dist/commands/user/list.js +99 -0
  59. package/dist/commands/user/retrieve/bot.d.ts +28 -0
  60. package/dist/commands/user/retrieve/bot.js +96 -0
  61. package/dist/commands/user/retrieve.d.ts +30 -0
  62. package/dist/commands/user/retrieve.js +103 -0
  63. package/dist/commands/whoami.d.ts +19 -0
  64. package/dist/commands/whoami.js +175 -0
  65. package/dist/deduplication.d.ts +41 -0
  66. package/dist/deduplication.js +71 -0
  67. package/dist/envelope.d.ts +169 -0
  68. package/dist/envelope.js +257 -0
  69. package/dist/errors/enhanced-errors.d.ts +168 -0
  70. package/dist/errors/enhanced-errors.js +570 -0
  71. package/dist/errors/index.d.ts +18 -0
  72. package/dist/errors/index.js +33 -0
  73. package/dist/examples/cache-retry-examples.d.ts +64 -0
  74. package/dist/examples/cache-retry-examples.js +375 -0
  75. package/dist/helper.d.ts +102 -0
  76. package/dist/helper.js +885 -0
  77. package/dist/http-agent.d.ts +38 -0
  78. package/dist/http-agent.js +60 -0
  79. package/dist/index.d.ts +1 -0
  80. package/dist/index.js +4 -0
  81. package/dist/interface.d.ts +4 -0
  82. package/dist/interface.js +2 -0
  83. package/dist/notion.d.ts +144 -0
  84. package/dist/notion.js +547 -0
  85. package/dist/retry.d.ts +72 -0
  86. package/dist/retry.js +381 -0
  87. package/dist/utils/disk-cache.d.ts +80 -0
  88. package/dist/utils/disk-cache.js +291 -0
  89. package/dist/utils/markdown-to-blocks.d.ts +19 -0
  90. package/dist/utils/markdown-to-blocks.js +259 -0
  91. package/dist/utils/notion-resolver.d.ts +48 -0
  92. package/dist/utils/notion-resolver.js +262 -0
  93. package/dist/utils/notion-url-parser.d.ts +46 -0
  94. package/dist/utils/notion-url-parser.js +111 -0
  95. package/dist/utils/property-expander.d.ts +45 -0
  96. package/dist/utils/property-expander.js +323 -0
  97. package/dist/utils/schema-examples.d.ts +40 -0
  98. package/dist/utils/schema-examples.js +359 -0
  99. package/dist/utils/schema-extractor.d.ts +65 -0
  100. package/dist/utils/schema-extractor.js +235 -0
  101. package/dist/utils/table-formatter.d.ts +36 -0
  102. package/dist/utils/table-formatter.js +122 -0
  103. package/dist/utils/terminal-banner.d.ts +24 -0
  104. package/dist/utils/terminal-banner.js +34 -0
  105. package/dist/utils/token-validator.d.ts +55 -0
  106. package/dist/utils/token-validator.js +85 -0
  107. package/dist/utils/update-notifier.d.ts +26 -0
  108. package/dist/utils/update-notifier.js +54 -0
  109. package/dist/utils/workspace-cache.d.ts +58 -0
  110. package/dist/utils/workspace-cache.js +185 -0
  111. package/oclif.manifest.json +4497 -0
  112. package/package.json +115 -0
  113. package/scripts/banner.js +38 -0
  114. package/scripts/postinstall.js +56 -0
@@ -0,0 +1,98 @@
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 BlockRetrieve extends core_1.Command {
10
+ async run() {
11
+ const { args, flags } = await this.parse(BlockRetrieve);
12
+ try {
13
+ let res = await notion.retrieveBlock(args.block_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
+ object: {},
37
+ id: {},
38
+ type: {},
39
+ parent: {},
40
+ content: {
41
+ get: (row) => {
42
+ return (0, helper_1.getBlockPlainText)(row);
43
+ },
44
+ },
45
+ };
46
+ const options = {
47
+ printLine: this.log.bind(this),
48
+ ...flags,
49
+ };
50
+ (0, table_formatter_1.formatTable)([res], columns, options);
51
+ process.exit(0);
52
+ }
53
+ catch (error) {
54
+ const cliError = error instanceof errors_1.NotionCLIError
55
+ ? error
56
+ : (0, errors_1.wrapNotionError)(error, {
57
+ resourceType: 'block',
58
+ attemptedId: args.block_id,
59
+ endpoint: 'blocks.retrieve'
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
+ BlockRetrieve.description = 'Retrieve a block';
72
+ BlockRetrieve.aliases = ['block:r'];
73
+ BlockRetrieve.examples = [
74
+ {
75
+ description: 'Retrieve a block',
76
+ command: `$ notion-cli block retrieve BLOCK_ID`,
77
+ },
78
+ {
79
+ description: 'Retrieve a block and output raw json',
80
+ command: `$ notion-cli block retrieve BLOCK_ID -r`,
81
+ },
82
+ {
83
+ description: 'Retrieve a block and output JSON for automation',
84
+ command: `$ notion-cli block retrieve BLOCK_ID --json`,
85
+ },
86
+ ];
87
+ BlockRetrieve.args = {
88
+ block_id: core_1.Args.string({ required: true }),
89
+ };
90
+ BlockRetrieve.flags = {
91
+ raw: core_1.Flags.boolean({
92
+ char: 'r',
93
+ description: 'output raw json',
94
+ }),
95
+ ...table_formatter_1.tableFlags,
96
+ ...base_flags_1.AutomationFlags,
97
+ };
98
+ exports.default = BlockRetrieve;
@@ -0,0 +1,45 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class BlockUpdate extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ block_id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
11
+ };
12
+ static flags: {
13
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
15
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
17
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
21
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
22
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
23
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
24
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ archived: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ content: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
29
+ text: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
30
+ 'heading-1': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
31
+ 'heading-2': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
32
+ 'heading-3': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
33
+ bullet: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
34
+ numbered: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
35
+ todo: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
36
+ toggle: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
37
+ code: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
38
+ language: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
39
+ quote: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
40
+ callout: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
41
+ color: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
42
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
43
+ };
44
+ run(): Promise<void>;
45
+ }
@@ -0,0 +1,241 @@
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 client_1 = require("@notionhq/client");
7
+ const helper_1 = require("../../helper");
8
+ const notion_resolver_1 = require("../../utils/notion-resolver");
9
+ const base_flags_1 = require("../../base-flags");
10
+ const errors_1 = require("../../errors");
11
+ class BlockUpdate extends core_1.Command {
12
+ async run() {
13
+ const { args, flags } = await this.parse(BlockUpdate);
14
+ try {
15
+ // Resolve block ID from URL or direct ID
16
+ const blockId = await (0, notion_resolver_1.resolveNotionId)(args.block_id, 'page');
17
+ const params = {
18
+ block_id: blockId,
19
+ };
20
+ // Handle archived flag
21
+ if (flags.archived !== undefined) {
22
+ params.archived = flags.archived;
23
+ }
24
+ // Check if using simple text-based flags or complex JSON
25
+ const hasTextFlags = flags.text || flags['heading-1'] || flags['heading-2'] || flags['heading-3'] ||
26
+ flags.bullet || flags.numbered || flags.todo || flags.toggle ||
27
+ flags.code || flags.quote || flags.callout;
28
+ if (hasTextFlags && flags.content) {
29
+ this.error('Cannot use both text-based flags (--text, --heading-1, etc.) and --content flag together. Choose one approach.');
30
+ }
31
+ // Handle content updates
32
+ if (hasTextFlags) {
33
+ // Use simple text-based flags
34
+ const blockUpdate = (0, helper_1.buildBlockUpdateFromTextFlags)('', {
35
+ text: flags.text,
36
+ heading1: flags['heading-1'],
37
+ heading2: flags['heading-2'],
38
+ heading3: flags['heading-3'],
39
+ bullet: flags.bullet,
40
+ numbered: flags.numbered,
41
+ todo: flags.todo,
42
+ toggle: flags.toggle,
43
+ code: flags.code,
44
+ language: flags.language,
45
+ quote: flags.quote,
46
+ callout: flags.callout,
47
+ });
48
+ if (blockUpdate) {
49
+ Object.assign(params, blockUpdate);
50
+ }
51
+ }
52
+ else if (flags.content) {
53
+ // Use complex JSON
54
+ try {
55
+ const content = JSON.parse(flags.content);
56
+ Object.assign(params, content);
57
+ }
58
+ catch (error) {
59
+ throw errors_1.NotionCLIErrorFactory.invalidJson(flags.content, error);
60
+ }
61
+ }
62
+ // Handle color updates
63
+ if (flags.color) {
64
+ // Retrieve the block to determine its type
65
+ const blockResponse = await notion.retrieveBlock(blockId);
66
+ // Ensure we have a full block response
67
+ if (!(0, client_1.isFullBlock)(blockResponse)) {
68
+ throw new errors_1.NotionCLIError(errors_1.NotionCLIErrorCode.API_ERROR, 'Received partial block response. Cannot determine block type for color update.', [], { attemptedId: blockId });
69
+ }
70
+ // Color is only supported for certain block types
71
+ const colorSupportedTypes = [
72
+ 'paragraph', 'heading_1', 'heading_2', 'heading_3',
73
+ 'bulleted_list_item', 'numbered_list_item', 'toggle',
74
+ 'quote', 'callout'
75
+ ];
76
+ if (!colorSupportedTypes.includes(blockResponse.type)) {
77
+ this.error(`Color property is not supported for block type: ${blockResponse.type}. Supported types: ${colorSupportedTypes.join(', ')}`);
78
+ }
79
+ // Color must be nested within the block type property
80
+ params[blockResponse.type] = {
81
+ ...params[blockResponse.type],
82
+ color: flags.color
83
+ };
84
+ }
85
+ const res = await notion.updateBlock(params);
86
+ // Handle JSON output for automation
87
+ if (flags.json) {
88
+ this.log(JSON.stringify({
89
+ success: true,
90
+ data: res,
91
+ timestamp: new Date().toISOString()
92
+ }, null, 2));
93
+ process.exit(0);
94
+ return;
95
+ }
96
+ // Handle raw JSON output (legacy)
97
+ if (flags.raw) {
98
+ (0, helper_1.outputRawJson)(res);
99
+ process.exit(0);
100
+ return;
101
+ }
102
+ // Handle table output
103
+ const columns = {
104
+ object: {},
105
+ id: {},
106
+ type: {},
107
+ parent: {},
108
+ content: {
109
+ get: (row) => {
110
+ return (0, helper_1.getBlockPlainText)(row);
111
+ },
112
+ },
113
+ };
114
+ const options = {
115
+ printLine: this.log.bind(this),
116
+ ...flags,
117
+ };
118
+ (0, table_formatter_1.formatTable)([res], columns, options);
119
+ process.exit(0);
120
+ }
121
+ catch (error) {
122
+ const cliError = error instanceof errors_1.NotionCLIError
123
+ ? error
124
+ : (0, errors_1.wrapNotionError)(error, {
125
+ resourceType: 'block',
126
+ attemptedId: args.block_id,
127
+ endpoint: 'blocks.update',
128
+ userInput: flags.content
129
+ });
130
+ if (flags.json) {
131
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
132
+ }
133
+ else {
134
+ this.error(cliError.toHumanString());
135
+ }
136
+ process.exit(1);
137
+ }
138
+ }
139
+ }
140
+ BlockUpdate.description = 'Update a block';
141
+ BlockUpdate.aliases = ['block:u'];
142
+ BlockUpdate.examples = [
143
+ {
144
+ description: 'Update block with simple text',
145
+ command: `$ notion-cli block update BLOCK_ID --text "Updated content"`,
146
+ },
147
+ {
148
+ description: 'Update heading content',
149
+ command: `$ notion-cli block update BLOCK_ID --heading-1 "New Title"`,
150
+ },
151
+ {
152
+ description: 'Update code block',
153
+ command: `$ notion-cli block update BLOCK_ID --code "const x = 42;" --language javascript`,
154
+ },
155
+ {
156
+ description: 'Archive a block',
157
+ command: `$ notion-cli block update BLOCK_ID -a`,
158
+ },
159
+ {
160
+ description: 'Archive a block via URL',
161
+ command: `$ notion-cli block update https://notion.so/BLOCK_ID -a`,
162
+ },
163
+ {
164
+ description: 'Update block content with complex JSON (for advanced cases)',
165
+ command: `$ notion-cli block update BLOCK_ID -c '{"paragraph":{"rich_text":[{"text":{"content":"Updated text"}}]}}'`,
166
+ },
167
+ {
168
+ description: 'Update block color',
169
+ command: `$ notion-cli block update BLOCK_ID --color blue`,
170
+ },
171
+ {
172
+ description: 'Update a block and output raw json',
173
+ command: `$ notion-cli block update BLOCK_ID --text "Updated" -r`,
174
+ },
175
+ {
176
+ description: 'Update a block and output JSON for automation',
177
+ command: `$ notion-cli block update BLOCK_ID --text "Updated" --json`,
178
+ },
179
+ ];
180
+ BlockUpdate.args = {
181
+ block_id: core_1.Args.string({ description: 'Block ID or URL', required: true }),
182
+ };
183
+ BlockUpdate.flags = {
184
+ archived: core_1.Flags.boolean({
185
+ char: 'a',
186
+ description: 'Archive the block',
187
+ }),
188
+ content: core_1.Flags.string({
189
+ char: 'c',
190
+ description: 'Updated block content (JSON object with block type properties) - for complex cases',
191
+ }),
192
+ // Simple text-based flags
193
+ text: core_1.Flags.string({
194
+ description: 'Update paragraph text',
195
+ }),
196
+ 'heading-1': core_1.Flags.string({
197
+ description: 'Update H1 heading text',
198
+ }),
199
+ 'heading-2': core_1.Flags.string({
200
+ description: 'Update H2 heading text',
201
+ }),
202
+ 'heading-3': core_1.Flags.string({
203
+ description: 'Update H3 heading text',
204
+ }),
205
+ bullet: core_1.Flags.string({
206
+ description: 'Update bulleted list item text',
207
+ }),
208
+ numbered: core_1.Flags.string({
209
+ description: 'Update numbered list item text',
210
+ }),
211
+ todo: core_1.Flags.string({
212
+ description: 'Update to-do item text',
213
+ }),
214
+ toggle: core_1.Flags.string({
215
+ description: 'Update toggle block text',
216
+ }),
217
+ code: core_1.Flags.string({
218
+ description: 'Update code block content',
219
+ }),
220
+ language: core_1.Flags.string({
221
+ description: 'Update code block language (used with --code)',
222
+ default: 'plain text',
223
+ }),
224
+ quote: core_1.Flags.string({
225
+ description: 'Update quote block text',
226
+ }),
227
+ callout: core_1.Flags.string({
228
+ description: 'Update callout block text',
229
+ }),
230
+ color: core_1.Flags.string({
231
+ description: 'Block color (for supported block types)',
232
+ options: ['default', 'gray', 'brown', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink', 'red'],
233
+ }),
234
+ raw: core_1.Flags.boolean({
235
+ char: 'r',
236
+ description: 'output raw json',
237
+ }),
238
+ ...table_formatter_1.tableFlags,
239
+ ...base_flags_1.AutomationFlags,
240
+ };
241
+ exports.default = BlockUpdate;
@@ -0,0 +1,19 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class CacheInfo 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
+ }
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const base_flags_1 = require("../../base-flags");
5
+ const workspace_cache_1 = require("../../utils/workspace-cache");
6
+ const cache_1 = require("../../cache");
7
+ const errors_1 = require("../../errors");
8
+ class CacheInfo extends core_1.Command {
9
+ async run() {
10
+ const { flags } = await this.parse(CacheInfo);
11
+ try {
12
+ // Get workspace cache
13
+ const workspaceCache = await (0, workspace_cache_1.loadCache)();
14
+ const cachePath = await (0, workspace_cache_1.getCachePath)();
15
+ // Get in-memory cache stats
16
+ const inMemoryStats = cache_1.cacheManager.getStats();
17
+ const hitRate = cache_1.cacheManager.getHitRate();
18
+ // Calculate workspace cache age if available
19
+ let workspaceInfo = null;
20
+ if (workspaceCache) {
21
+ const lastSyncTime = new Date(workspaceCache.lastSync);
22
+ const cacheAgeMs = Date.now() - lastSyncTime.getTime();
23
+ const cacheAgeHours = cacheAgeMs / (1000 * 60 * 60);
24
+ const isStale = cacheAgeHours > 24;
25
+ workspaceInfo = {
26
+ databases_cached: workspaceCache.databases.length,
27
+ last_sync: workspaceCache.lastSync,
28
+ cache_age_ms: cacheAgeMs,
29
+ cache_age_hours: parseFloat(cacheAgeHours.toFixed(2)),
30
+ is_stale: isStale,
31
+ stale_threshold_hours: 24,
32
+ cache_version: workspaceCache.version,
33
+ cache_location: cachePath,
34
+ };
35
+ }
36
+ // Build comprehensive cache info
37
+ const cacheInfo = {
38
+ in_memory: {
39
+ enabled: cache_1.cacheManager.isEnabled(),
40
+ stats: {
41
+ size: inMemoryStats.size,
42
+ hits: inMemoryStats.hits,
43
+ misses: inMemoryStats.misses,
44
+ sets: inMemoryStats.sets,
45
+ evictions: inMemoryStats.evictions,
46
+ hit_rate: parseFloat((hitRate * 100).toFixed(2)),
47
+ },
48
+ ttls_ms: {
49
+ data_source: parseInt(process.env.NOTION_CLI_CACHE_DS_TTL || '600000', 10),
50
+ page: parseInt(process.env.NOTION_CLI_CACHE_PAGE_TTL || '60000', 10),
51
+ user: parseInt(process.env.NOTION_CLI_CACHE_USER_TTL || '3600000', 10),
52
+ block: parseInt(process.env.NOTION_CLI_CACHE_BLOCK_TTL || '30000', 10),
53
+ },
54
+ max_size: parseInt(process.env.NOTION_CLI_CACHE_MAX_SIZE || '1000', 10),
55
+ },
56
+ workspace: workspaceInfo,
57
+ recommendations: {
58
+ sync_interval_hours: 24,
59
+ next_sync: workspaceCache ?
60
+ new Date(new Date(workspaceCache.lastSync).getTime() + 24 * 60 * 60 * 1000).toISOString() :
61
+ null,
62
+ action_needed: !workspaceCache ? 'Run "notion-cli sync" to initialize cache' :
63
+ (workspaceInfo && workspaceInfo.is_stale) ? 'Cache is stale, run "notion-cli sync"' :
64
+ 'Cache is fresh',
65
+ },
66
+ };
67
+ // JSON output
68
+ if (flags.json) {
69
+ this.log(JSON.stringify({
70
+ success: true,
71
+ data: cacheInfo,
72
+ metadata: {
73
+ timestamp: new Date().toISOString(),
74
+ command: 'cache:info',
75
+ },
76
+ }, null, 2));
77
+ process.exit(0);
78
+ }
79
+ // Human-readable output
80
+ this.log('Cache Configuration');
81
+ this.log('='.repeat(60));
82
+ this.log('\nIn-Memory Cache:');
83
+ this.log(` Enabled: ${cacheInfo.in_memory.enabled ? 'Yes' : 'No'}`);
84
+ this.log(` Size: ${inMemoryStats.size} / ${cacheInfo.in_memory.max_size}`);
85
+ this.log(` Hits: ${inMemoryStats.hits}`);
86
+ this.log(` Misses: ${inMemoryStats.misses}`);
87
+ this.log(` Hit Rate: ${(hitRate * 100).toFixed(1)}%`);
88
+ this.log(` Evictions: ${inMemoryStats.evictions}`);
89
+ this.log('\n TTLs (milliseconds):');
90
+ this.log(` Data Sources: ${cacheInfo.in_memory.ttls_ms.data_source} (${(cacheInfo.in_memory.ttls_ms.data_source / 60000).toFixed(0)} min)`);
91
+ this.log(` Pages: ${cacheInfo.in_memory.ttls_ms.page} (${(cacheInfo.in_memory.ttls_ms.page / 1000).toFixed(0)} sec)`);
92
+ this.log(` Users: ${cacheInfo.in_memory.ttls_ms.user} (${(cacheInfo.in_memory.ttls_ms.user / 60000).toFixed(0)} min)`);
93
+ this.log(` Blocks: ${cacheInfo.in_memory.ttls_ms.block} (${(cacheInfo.in_memory.ttls_ms.block / 1000).toFixed(0)} sec)`);
94
+ this.log('\nWorkspace Cache:');
95
+ if (workspaceInfo) {
96
+ this.log(` Databases: ${workspaceInfo.databases_cached}`);
97
+ this.log(` Last Sync: ${new Date(workspaceInfo.last_sync).toLocaleString()}`);
98
+ this.log(` Age: ${workspaceInfo.cache_age_hours} hours`);
99
+ this.log(` Status: ${workspaceInfo.is_stale ? '⚠️ STALE' : '✓ Fresh'}`);
100
+ this.log(` Location: ${workspaceInfo.cache_location}`);
101
+ }
102
+ else {
103
+ this.log(` Status: Not initialized`);
104
+ this.log(` Action: Run "notion-cli sync"`);
105
+ }
106
+ this.log('\nRecommendations:');
107
+ this.log(` Sync Interval: Every ${cacheInfo.recommendations.sync_interval_hours} hours`);
108
+ if (cacheInfo.recommendations.next_sync) {
109
+ this.log(` Next Sync: ${new Date(cacheInfo.recommendations.next_sync).toLocaleString()}`);
110
+ }
111
+ this.log(` Action: ${cacheInfo.recommendations.action_needed}`);
112
+ process.exit(0);
113
+ }
114
+ catch (error) {
115
+ const cliError = error instanceof errors_1.NotionCLIError
116
+ ? error
117
+ : (0, errors_1.wrapNotionError)(error instanceof Error ? error : new Error(String(error)), {
118
+ endpoint: 'cache.info'
119
+ });
120
+ if (flags.json) {
121
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
122
+ }
123
+ else {
124
+ this.error(cliError.toHumanString());
125
+ }
126
+ process.exit(1);
127
+ }
128
+ }
129
+ }
130
+ CacheInfo.description = 'Show cache statistics and configuration';
131
+ CacheInfo.aliases = ['cache:stats', 'cache:status'];
132
+ CacheInfo.examples = [
133
+ {
134
+ description: 'Show cache info in JSON format',
135
+ command: 'notion-cli cache:info --json',
136
+ },
137
+ {
138
+ description: 'Show cache statistics',
139
+ command: 'notion-cli cache:info',
140
+ },
141
+ ];
142
+ CacheInfo.flags = {
143
+ ...base_flags_1.AutomationFlags,
144
+ };
145
+ exports.default = CacheInfo;
@@ -0,0 +1,30 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class ConfigSetToken extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ token: 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
+ };
21
+ run(): Promise<void>;
22
+ /**
23
+ * Detect the current shell
24
+ */
25
+ private detectShell;
26
+ /**
27
+ * Get the rc file path for the detected shell
28
+ */
29
+ private getRcFilePath;
30
+ }