@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,185 @@
1
+ "use strict";
2
+ /**
3
+ * Workspace Cache Utility
4
+ *
5
+ * Manages persistent caching of workspace databases for fast name-to-ID resolution.
6
+ * Cache is stored at ~/.notion-cli/databases.json
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getCacheDir = getCacheDir;
10
+ exports.getCachePath = getCachePath;
11
+ exports.ensureCacheDir = ensureCacheDir;
12
+ exports.loadCache = loadCache;
13
+ exports.saveCache = saveCache;
14
+ exports.generateAliases = generateAliases;
15
+ exports.buildCacheEntry = buildCacheEntry;
16
+ exports.createEmptyCache = createEmptyCache;
17
+ const fs = require("fs/promises");
18
+ const path = require("path");
19
+ const os = require("os");
20
+ const client_1 = require("@notionhq/client");
21
+ const CACHE_VERSION = '1.0.0';
22
+ const CACHE_DIR_NAME = '.notion-cli';
23
+ const CACHE_FILE_NAME = 'databases.json';
24
+ /**
25
+ * Get the cache directory path
26
+ */
27
+ function getCacheDir() {
28
+ return path.join(os.homedir(), CACHE_DIR_NAME);
29
+ }
30
+ /**
31
+ * Get the cache file path
32
+ */
33
+ async function getCachePath() {
34
+ return path.join(getCacheDir(), CACHE_FILE_NAME);
35
+ }
36
+ /**
37
+ * Ensure cache directory exists
38
+ */
39
+ async function ensureCacheDir() {
40
+ const cacheDir = getCacheDir();
41
+ try {
42
+ await fs.mkdir(cacheDir, { recursive: true, mode: 0o700 });
43
+ }
44
+ catch (error) {
45
+ if (error.code !== 'EEXIST') {
46
+ throw new Error(`Failed to create cache directory: ${error.message}`);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Load cache from disk
52
+ * Returns null if cache doesn't exist or is corrupted
53
+ */
54
+ async function loadCache() {
55
+ try {
56
+ const cachePath = await getCachePath();
57
+ const content = await fs.readFile(cachePath, 'utf-8');
58
+ const cache = JSON.parse(content);
59
+ // Validate cache structure
60
+ if (!cache.version || !Array.isArray(cache.databases)) {
61
+ console.warn('Cache file is corrupted, will rebuild on next sync');
62
+ return null;
63
+ }
64
+ return cache;
65
+ }
66
+ catch (error) {
67
+ if (error.code === 'ENOENT') {
68
+ // Cache doesn't exist yet
69
+ return null;
70
+ }
71
+ // Parse error or other error
72
+ console.warn(`Failed to load cache: ${error.message}`);
73
+ return null;
74
+ }
75
+ }
76
+ /**
77
+ * Save cache to disk (atomic write)
78
+ */
79
+ async function saveCache(data) {
80
+ await ensureCacheDir();
81
+ const cachePath = await getCachePath();
82
+ const tmpPath = `${cachePath}.tmp`;
83
+ try {
84
+ // Write to temporary file
85
+ await fs.writeFile(tmpPath, JSON.stringify(data, null, 2), { encoding: 'utf-8', mode: 0o600 });
86
+ // Atomic rename (replaces old file)
87
+ await fs.rename(tmpPath, cachePath);
88
+ }
89
+ catch (error) {
90
+ // Clean up temp file if it exists
91
+ try {
92
+ await fs.unlink(tmpPath);
93
+ }
94
+ catch {
95
+ // Intentionally empty - cache directory may not exist
96
+ }
97
+ throw new Error(`Failed to save cache: ${error.message}`);
98
+ }
99
+ }
100
+ /**
101
+ * Generate search aliases from a database title
102
+ *
103
+ * @example
104
+ * generateAliases('Tasks Database')
105
+ * // Returns: ['tasks database', 'tasks', 'task', 'tasks db', 'task db', 'td']
106
+ */
107
+ function generateAliases(title) {
108
+ const aliases = new Set();
109
+ const normalized = title.toLowerCase().trim();
110
+ // Add full title (normalized)
111
+ aliases.add(normalized);
112
+ // Add title without common suffixes
113
+ const withoutSuffixes = normalized.replace(/\s+(database|db|table|list|tracker|log)$/i, '');
114
+ if (withoutSuffixes !== normalized) {
115
+ aliases.add(withoutSuffixes);
116
+ }
117
+ // Add title with common suffixes
118
+ if (withoutSuffixes !== normalized) {
119
+ aliases.add(`${withoutSuffixes} db`);
120
+ aliases.add(`${withoutSuffixes} database`);
121
+ }
122
+ // Add singular/plural variants
123
+ if (withoutSuffixes.endsWith('s')) {
124
+ aliases.add(withoutSuffixes.slice(0, -1)); // Remove 's'
125
+ }
126
+ else {
127
+ aliases.add(`${withoutSuffixes}s`); // Add 's'
128
+ }
129
+ // Add acronym if multi-word (e.g., "Meeting Notes" → "mn")
130
+ const words = withoutSuffixes.split(/\s+/);
131
+ if (words.length > 1) {
132
+ const acronym = words.map(w => w[0]).join('');
133
+ if (acronym.length >= 2) {
134
+ aliases.add(acronym);
135
+ }
136
+ }
137
+ return Array.from(aliases);
138
+ }
139
+ /**
140
+ * Build a cached database entry from a data source response
141
+ */
142
+ function buildCacheEntry(dataSource) {
143
+ let title = 'Untitled';
144
+ let properties = {};
145
+ let url;
146
+ let lastEditedTime;
147
+ if ((0, client_1.isFullDataSource)(dataSource)) {
148
+ if (dataSource.title && dataSource.title.length > 0) {
149
+ title = dataSource.title[0].plain_text;
150
+ }
151
+ // Extract property schema
152
+ if (dataSource.properties) {
153
+ properties = dataSource.properties;
154
+ }
155
+ // Extract URL if available
156
+ if ('url' in dataSource) {
157
+ url = dataSource.url;
158
+ }
159
+ // Extract last edited time
160
+ if ('last_edited_time' in dataSource) {
161
+ lastEditedTime = dataSource.last_edited_time;
162
+ }
163
+ }
164
+ const titleNormalized = title.toLowerCase().trim();
165
+ const aliases = generateAliases(title);
166
+ return {
167
+ id: dataSource.id,
168
+ title,
169
+ titleNormalized,
170
+ aliases,
171
+ url,
172
+ lastEditedTime,
173
+ properties,
174
+ };
175
+ }
176
+ /**
177
+ * Create an empty cache
178
+ */
179
+ function createEmptyCache() {
180
+ return {
181
+ version: CACHE_VERSION,
182
+ lastSync: new Date().toISOString(),
183
+ databases: [],
184
+ };
185
+ }