@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,33 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class PageCreate 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
+ parent_page_id: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
25
+ parent_data_source_id: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
26
+ file_path: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
27
+ title_property: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
28
+ properties: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
29
+ 'simple-properties': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
30
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
31
+ };
32
+ run(): Promise<void>;
33
+ }
@@ -0,0 +1,240 @@
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 fs = require("fs");
7
+ const path = require("path");
8
+ const markdown_to_blocks_1 = require("../../utils/markdown-to-blocks");
9
+ const helper_1 = require("../../helper");
10
+ const notion_resolver_1 = require("../../utils/notion-resolver");
11
+ const base_flags_1 = require("../../base-flags");
12
+ const errors_1 = require("../../errors");
13
+ const property_expander_1 = require("../../utils/property-expander");
14
+ class PageCreate extends core_1.Command {
15
+ async run() {
16
+ const { flags } = await this.parse(PageCreate);
17
+ try {
18
+ let pageProps;
19
+ let pageParent;
20
+ if (flags.parent_page_id) {
21
+ // Resolve parent page ID from URL, direct ID, or name (future)
22
+ const parentPageId = await (0, notion_resolver_1.resolveNotionId)(flags.parent_page_id, 'page');
23
+ pageParent = {
24
+ page_id: parentPageId,
25
+ };
26
+ }
27
+ else {
28
+ // Resolve parent database ID from URL, direct ID, or name (future)
29
+ const parentDataSourceId = await (0, notion_resolver_1.resolveNotionId)(flags.parent_data_source_id, 'database');
30
+ pageParent = {
31
+ data_source_id: parentDataSourceId,
32
+ };
33
+ }
34
+ // Build properties object
35
+ let properties = {};
36
+ // Handle properties flag
37
+ if (flags.properties) {
38
+ try {
39
+ const parsedProps = JSON.parse(flags.properties);
40
+ if (flags['simple-properties']) {
41
+ // User provided simple format - expand to Notion format
42
+ // Need to get database schema first
43
+ if (!flags.parent_data_source_id) {
44
+ throw new Error('The --simple-properties flag requires --parent_data_source_id (-d) to be set. ' +
45
+ 'Simple properties need the database schema for validation.');
46
+ }
47
+ const parentDataSourceId = await (0, notion_resolver_1.resolveNotionId)(flags.parent_data_source_id, 'database');
48
+ const dbSchema = await notion.retrieveDataSource(parentDataSourceId);
49
+ properties = await (0, property_expander_1.expandSimpleProperties)(parsedProps, dbSchema.properties);
50
+ }
51
+ else {
52
+ // Use raw Notion format
53
+ properties = parsedProps;
54
+ }
55
+ }
56
+ catch (error) {
57
+ if (error.message.includes('Unexpected token') || error.message.includes('JSON')) {
58
+ throw new Error(`Invalid JSON in --properties flag: ${error.message}\n` +
59
+ `Example: --properties '{"Name": "Task", "Status": "Done"}'`);
60
+ }
61
+ throw error;
62
+ }
63
+ }
64
+ if (flags.file_path) {
65
+ const p = path.join('./', flags.file_path);
66
+ const fileName = path.basename(flags.file_path);
67
+ const md = fs.readFileSync(p, { encoding: 'utf-8' });
68
+ const blocks = (0, markdown_to_blocks_1.markdownToBlocks)(md);
69
+ // Extract title from H1 heading or use filename without extension
70
+ const extractTitle = (markdown, filename) => {
71
+ const h1Match = markdown.match(/^#\s+(.+)$/m);
72
+ if (h1Match && h1Match[1]) {
73
+ return h1Match[1].trim();
74
+ }
75
+ // Fallback: use filename without extension
76
+ return filename.replace(/\.md$/, '');
77
+ };
78
+ const pageTitle = extractTitle(md, fileName);
79
+ // If no properties were provided via flag, use extracted title
80
+ if (!flags.properties) {
81
+ properties = {
82
+ [flags.title_property]: {
83
+ title: [{ text: { content: pageTitle } }],
84
+ },
85
+ };
86
+ }
87
+ else {
88
+ // Merge with existing properties, but ensure title is set
89
+ if (!properties[flags.title_property]) {
90
+ properties[flags.title_property] = {
91
+ title: [{ text: { content: pageTitle } }],
92
+ };
93
+ }
94
+ }
95
+ pageProps = {
96
+ parent: pageParent,
97
+ properties,
98
+ children: blocks,
99
+ };
100
+ }
101
+ else {
102
+ pageProps = {
103
+ parent: pageParent,
104
+ properties,
105
+ };
106
+ }
107
+ const res = await notion.createPage(pageProps);
108
+ // Handle JSON output for automation
109
+ if (flags.json) {
110
+ this.log(JSON.stringify({
111
+ success: true,
112
+ data: res,
113
+ timestamp: new Date().toISOString()
114
+ }, null, 2));
115
+ process.exit(0);
116
+ return;
117
+ }
118
+ // Handle raw JSON output (legacy)
119
+ if (flags.raw) {
120
+ (0, helper_1.outputRawJson)(res);
121
+ process.exit(0);
122
+ return;
123
+ }
124
+ // Handle table output
125
+ const columns = {
126
+ title: {
127
+ get: (row) => {
128
+ return (0, helper_1.getPageTitle)(row);
129
+ },
130
+ },
131
+ object: {},
132
+ id: {},
133
+ url: {},
134
+ };
135
+ const options = {
136
+ printLine: this.log.bind(this),
137
+ ...flags,
138
+ };
139
+ (0, table_formatter_1.formatTable)([res], columns, options);
140
+ process.exit(0);
141
+ }
142
+ catch (error) {
143
+ const cliError = error instanceof errors_1.NotionCLIError
144
+ ? error
145
+ : (0, errors_1.wrapNotionError)(error, {
146
+ resourceType: 'page',
147
+ endpoint: 'pages.create'
148
+ });
149
+ if (flags.json) {
150
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
151
+ }
152
+ else {
153
+ this.error(cliError.toHumanString());
154
+ }
155
+ process.exit(1);
156
+ }
157
+ }
158
+ }
159
+ PageCreate.description = 'Create a page';
160
+ PageCreate.aliases = ['page:c'];
161
+ PageCreate.examples = [
162
+ {
163
+ description: 'Create a page via interactive mode',
164
+ command: `$ notion-cli page create`,
165
+ },
166
+ {
167
+ description: 'Create a page with a specific parent_page_id',
168
+ command: `$ notion-cli page create -p PARENT_PAGE_ID`,
169
+ },
170
+ {
171
+ description: 'Create a page with a parent page URL',
172
+ command: `$ notion-cli page create -p https://notion.so/PARENT_PAGE_ID`,
173
+ },
174
+ {
175
+ description: 'Create a page with a specific parent_db_id',
176
+ command: `$ notion-cli page create -d PARENT_DB_ID`,
177
+ },
178
+ {
179
+ description: 'Create a page with simple properties (recommended for AI agents)',
180
+ command: `$ notion-cli page create -d DATA_SOURCE_ID -S --properties '{"Name": "My Task", "Status": "In Progress", "Due Date": "2025-12-31"}'`,
181
+ },
182
+ {
183
+ description: 'Create a page with simple properties using relative dates',
184
+ command: `$ notion-cli page create -d DATA_SOURCE_ID -S --properties '{"Name": "Review", "Due Date": "tomorrow", "Priority": "High"}'`,
185
+ },
186
+ {
187
+ description: 'Create a page with simple properties and multi-select',
188
+ command: `$ notion-cli page create -d DATA_SOURCE_ID -S --properties '{"Name": "Bug Fix", "Tags": ["urgent", "bug"], "Status": "Done"}'`,
189
+ },
190
+ {
191
+ description: 'Create a page with a specific source markdown file and parent_page_id',
192
+ command: `$ notion-cli page create -f ./path/to/source.md -p PARENT_PAGE_ID`,
193
+ },
194
+ {
195
+ description: 'Create a page with a specific source markdown file and parent_db_id',
196
+ command: `$ notion-cli page create -f ./path/to/source.md -d PARENT_DB_ID`,
197
+ },
198
+ {
199
+ description: 'Create a page with a specific source markdown file and output raw json with parent_page_id',
200
+ command: `$ notion-cli page create -f ./path/to/source.md -p PARENT_PAGE_ID -r`,
201
+ },
202
+ {
203
+ description: 'Create a page and output JSON for automation',
204
+ command: `$ notion-cli page create -p PARENT_PAGE_ID --json`,
205
+ },
206
+ ];
207
+ PageCreate.flags = {
208
+ parent_page_id: core_1.Flags.string({
209
+ char: 'p',
210
+ description: 'Parent page ID or URL (to create a sub-page)',
211
+ }),
212
+ parent_data_source_id: core_1.Flags.string({
213
+ char: 'd',
214
+ description: 'Parent data source ID or URL (to create a page in a table)',
215
+ }),
216
+ file_path: core_1.Flags.string({
217
+ char: 'f',
218
+ description: 'Path to a source markdown file',
219
+ }),
220
+ title_property: core_1.Flags.string({
221
+ char: 't',
222
+ description: 'Name of the title property (defaults to "Name" if not specified)',
223
+ default: 'Name',
224
+ }),
225
+ properties: core_1.Flags.string({
226
+ description: 'Page properties as JSON string',
227
+ }),
228
+ 'simple-properties': core_1.Flags.boolean({
229
+ char: 'S',
230
+ description: 'Use simplified property format (flat key-value pairs, recommended for AI agents)',
231
+ default: false,
232
+ }),
233
+ raw: core_1.Flags.boolean({
234
+ char: 'r',
235
+ description: 'output raw json',
236
+ }),
237
+ ...table_formatter_1.tableFlags,
238
+ ...base_flags_1.AutomationFlags,
239
+ };
240
+ exports.default = PageCreate;
@@ -0,0 +1,24 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class PageRetrievePropertyItem extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ page_id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
11
+ property_id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
12
+ };
13
+ static flags: {
14
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
16
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
22
+ };
23
+ run(): Promise<void>;
24
+ }
@@ -0,0 +1,72 @@
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
+ class PageRetrievePropertyItem extends core_1.Command {
9
+ async run() {
10
+ const { args, flags } = await this.parse(PageRetrievePropertyItem);
11
+ try {
12
+ const res = await notion.retrievePageProperty(args.page_id, args.property_id);
13
+ // Handle JSON output for automation
14
+ if (flags.json) {
15
+ this.log(JSON.stringify({
16
+ success: true,
17
+ data: res,
18
+ timestamp: new Date().toISOString()
19
+ }, null, 2));
20
+ process.exit(0);
21
+ return;
22
+ }
23
+ // Handle raw JSON output (default for this command)
24
+ (0, helper_1.outputRawJson)(res);
25
+ process.exit(0);
26
+ }
27
+ catch (error) {
28
+ const cliError = error instanceof errors_1.NotionCLIError
29
+ ? error
30
+ : (0, errors_1.wrapNotionError)(error, {
31
+ resourceType: 'page',
32
+ attemptedId: args.page_id,
33
+ endpoint: 'pages.properties.retrieve'
34
+ });
35
+ if (flags.json) {
36
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
37
+ }
38
+ else {
39
+ this.error(cliError.toHumanString());
40
+ }
41
+ process.exit(1);
42
+ }
43
+ }
44
+ }
45
+ PageRetrievePropertyItem.description = 'Retrieve a page property item';
46
+ PageRetrievePropertyItem.aliases = ['page:r:pi'];
47
+ PageRetrievePropertyItem.examples = [
48
+ {
49
+ description: 'Retrieve a page property item',
50
+ command: `$ notion-cli page retrieve:property_item PAGE_ID PROPERTY_ID`,
51
+ },
52
+ {
53
+ description: 'Retrieve a page property item and output raw json',
54
+ command: `$ notion-cli page retrieve:property_item PAGE_ID PROPERTY_ID -r`,
55
+ },
56
+ {
57
+ description: 'Retrieve a page property item and output JSON for automation',
58
+ command: `$ notion-cli page retrieve:property_item PAGE_ID PROPERTY_ID --json`,
59
+ },
60
+ ];
61
+ PageRetrievePropertyItem.args = {
62
+ page_id: core_1.Args.string({ required: true }),
63
+ property_id: core_1.Args.string({ required: true }),
64
+ };
65
+ PageRetrievePropertyItem.flags = {
66
+ raw: core_1.Flags.boolean({
67
+ char: 'r',
68
+ description: 'output raw json',
69
+ }),
70
+ ...base_flags_1.AutomationFlags,
71
+ };
72
+ exports.default = PageRetrievePropertyItem;
@@ -0,0 +1,36 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class PageRetrieve extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ page_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
+ markdown: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ 'compact-json': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
22
+ pretty: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
23
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
24
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
25
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
26
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
30
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
31
+ map: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
32
+ recursive: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
33
+ 'max-depth': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
34
+ };
35
+ run(): Promise<void>;
36
+ }
@@ -0,0 +1,244 @@
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 notion_to_md_1 = require("notion-to-md");
8
+ const base_flags_1 = require("../../base-flags");
9
+ const notion_resolver_1 = require("../../utils/notion-resolver");
10
+ const errors_1 = require("../../errors");
11
+ class PageRetrieve extends core_1.Command {
12
+ async run() {
13
+ const { args, flags } = await this.parse(PageRetrieve);
14
+ try {
15
+ // Resolve ID from URL, direct ID, or name (future)
16
+ const pageId = await (0, notion_resolver_1.resolveNotionId)(args.page_id, 'page');
17
+ // Handle map flag (fast structure discovery with parallel fetching)
18
+ if (flags.map) {
19
+ const mapData = await notion.mapPageStructure(pageId);
20
+ // Handle JSON output for automation (takes precedence)
21
+ if (flags.json) {
22
+ this.log(JSON.stringify({
23
+ success: true,
24
+ data: mapData,
25
+ timestamp: new Date().toISOString()
26
+ }, null, 2));
27
+ process.exit(0);
28
+ return;
29
+ }
30
+ // Handle compact JSON output
31
+ if (flags['compact-json']) {
32
+ (0, helper_1.outputCompactJson)(mapData);
33
+ process.exit(0);
34
+ return;
35
+ }
36
+ // Default: pretty JSON output for map
37
+ this.log(JSON.stringify(mapData, null, 2));
38
+ process.exit(0);
39
+ return;
40
+ }
41
+ // Handle page content as markdown (uses NotionToMarkdown)
42
+ if (flags.markdown) {
43
+ const n2m = new notion_to_md_1.NotionToMarkdown({ notionClient: notion.client });
44
+ const mdBlocks = await n2m.pageToMarkdown(pageId);
45
+ const mdString = n2m.toMarkdownString(mdBlocks);
46
+ console.log(mdString.parent);
47
+ process.exit(0);
48
+ return;
49
+ }
50
+ // Handle recursive fetching
51
+ if (flags.recursive) {
52
+ const recursiveData = await notion.retrievePageRecursive(pageId, 0, flags['max-depth']);
53
+ // Handle JSON output for automation (takes precedence)
54
+ if (flags.json) {
55
+ this.log(JSON.stringify({
56
+ success: true,
57
+ data: recursiveData,
58
+ timestamp: new Date().toISOString()
59
+ }, null, 2));
60
+ process.exit(0);
61
+ return;
62
+ }
63
+ // Handle compact JSON output
64
+ if (flags['compact-json']) {
65
+ (0, helper_1.outputCompactJson)(recursiveData);
66
+ process.exit(0);
67
+ return;
68
+ }
69
+ // Handle raw JSON output
70
+ if (flags.raw) {
71
+ (0, helper_1.outputRawJson)(recursiveData);
72
+ process.exit(0);
73
+ return;
74
+ }
75
+ // For other formats, show a message that they're not supported with recursive
76
+ this.error('Recursive mode only supports --json, --compact-json, or --raw output formats');
77
+ process.exit(1);
78
+ return;
79
+ }
80
+ const pageProps = {
81
+ page_id: pageId,
82
+ };
83
+ let res = await notion.retrievePage(pageProps);
84
+ // Apply minimal flag to strip metadata
85
+ if (flags.minimal) {
86
+ res = (0, helper_1.stripMetadata)(res);
87
+ }
88
+ // Handle JSON output for automation (takes precedence)
89
+ if (flags.json) {
90
+ this.log(JSON.stringify({
91
+ success: true,
92
+ data: res,
93
+ timestamp: new Date().toISOString()
94
+ }, null, 2));
95
+ process.exit(0);
96
+ return;
97
+ }
98
+ // Define columns for table output
99
+ const columns = {
100
+ title: {
101
+ get: (row) => {
102
+ return (0, helper_1.getPageTitle)(row);
103
+ },
104
+ },
105
+ object: {},
106
+ id: {},
107
+ url: {},
108
+ };
109
+ // Handle compact JSON output
110
+ if (flags['compact-json']) {
111
+ (0, helper_1.outputCompactJson)(res);
112
+ process.exit(0);
113
+ return;
114
+ }
115
+ // Handle pretty table output
116
+ if (flags.pretty) {
117
+ (0, helper_1.outputPrettyTable)([res], columns);
118
+ // Show hint after table output
119
+ (0, helper_1.showRawFlagHint)(1, res);
120
+ process.exit(0);
121
+ return;
122
+ }
123
+ // Handle raw JSON output
124
+ if (flags.raw) {
125
+ (0, helper_1.outputRawJson)(res);
126
+ process.exit(0);
127
+ return;
128
+ }
129
+ // Handle table output (default)
130
+ const options = {
131
+ printLine: this.log.bind(this),
132
+ ...flags,
133
+ };
134
+ (0, table_formatter_1.formatTable)([res], columns, options);
135
+ // Show hint after table output to make -r flag discoverable
136
+ (0, helper_1.showRawFlagHint)(1, res);
137
+ }
138
+ catch (error) {
139
+ const cliError = error instanceof errors_1.NotionCLIError
140
+ ? error
141
+ : (0, errors_1.wrapNotionError)(error, {
142
+ resourceType: 'page',
143
+ attemptedId: args.page_id,
144
+ endpoint: 'pages.retrieve'
145
+ });
146
+ if (flags.json) {
147
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
148
+ }
149
+ else {
150
+ this.error(cliError.toHumanString());
151
+ }
152
+ process.exit(1);
153
+ }
154
+ }
155
+ }
156
+ PageRetrieve.description = 'Retrieve a page';
157
+ PageRetrieve.aliases = ['page:r'];
158
+ PageRetrieve.examples = [
159
+ {
160
+ description: 'Retrieve a page with full data (recommended for AI assistants)',
161
+ command: `$ notion-cli page retrieve PAGE_ID -r`,
162
+ },
163
+ {
164
+ description: 'Fast structure overview (90% faster than full fetch)',
165
+ command: `$ notion-cli page retrieve PAGE_ID --map`,
166
+ },
167
+ {
168
+ description: 'Fast structure overview with compact JSON',
169
+ command: `$ notion-cli page retrieve PAGE_ID --map --compact-json`,
170
+ },
171
+ {
172
+ description: 'Retrieve entire page tree with all nested content (35% token reduction)',
173
+ command: `$ notion-cli page retrieve PAGE_ID --recursive --compact-json`,
174
+ },
175
+ {
176
+ description: 'Retrieve page tree with custom depth limit',
177
+ command: `$ notion-cli page retrieve PAGE_ID -R --max-depth 5 --json`,
178
+ },
179
+ {
180
+ description: 'Retrieve a page and output table',
181
+ command: `$ notion-cli page retrieve PAGE_ID`,
182
+ },
183
+ {
184
+ description: 'Retrieve a page via URL',
185
+ command: `$ notion-cli page retrieve https://notion.so/PAGE_ID`,
186
+ },
187
+ {
188
+ description: 'Retrieve a page and output raw json',
189
+ command: `$ notion-cli page retrieve PAGE_ID -r`,
190
+ },
191
+ {
192
+ description: 'Retrieve a page and output markdown',
193
+ command: `$ notion-cli page retrieve PAGE_ID -m`,
194
+ },
195
+ {
196
+ description: 'Retrieve a page metadata and output as markdown table',
197
+ command: `$ notion-cli page retrieve PAGE_ID --markdown`,
198
+ },
199
+ {
200
+ description: 'Retrieve a page metadata and output as compact JSON',
201
+ command: `$ notion-cli page retrieve PAGE_ID --compact-json`,
202
+ },
203
+ {
204
+ description: 'Retrieve a page and output JSON for automation',
205
+ command: `$ notion-cli page retrieve PAGE_ID --json`,
206
+ },
207
+ ];
208
+ PageRetrieve.args = {
209
+ page_id: core_1.Args.string({
210
+ required: true,
211
+ description: 'Page ID or full Notion URL (e.g., https://notion.so/...)',
212
+ }),
213
+ };
214
+ PageRetrieve.flags = {
215
+ raw: core_1.Flags.boolean({
216
+ char: 'r',
217
+ description: 'output raw json (recommended for AI assistants - returns all fields)',
218
+ }),
219
+ markdown: core_1.Flags.boolean({
220
+ char: 'm',
221
+ description: 'output page content as markdown',
222
+ }),
223
+ map: core_1.Flags.boolean({
224
+ description: 'fast structure discovery (returns minimal info: titles, types, IDs)',
225
+ default: false,
226
+ exclusive: ['raw', 'markdown'],
227
+ }),
228
+ recursive: core_1.Flags.boolean({
229
+ char: 'R',
230
+ description: 'recursively fetch all blocks and nested pages (reduces API calls)',
231
+ default: false,
232
+ }),
233
+ 'max-depth': core_1.Flags.integer({
234
+ description: 'maximum recursion depth for --recursive (default: 3)',
235
+ default: 3,
236
+ min: 1,
237
+ max: 10,
238
+ dependsOn: ['recursive'],
239
+ }),
240
+ ...table_formatter_1.tableFlags,
241
+ ...base_flags_1.OutputFormatFlags,
242
+ ...base_flags_1.AutomationFlags,
243
+ };
244
+ exports.default = PageRetrieve;