@catafal/notion-cli 5.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +552 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +14 -0
- package/bin/run.cmd +3 -0
- package/dist/base-command.d.ts +73 -0
- package/dist/base-command.js +179 -0
- package/dist/base-flags.d.ts +14 -0
- package/dist/base-flags.js +59 -0
- package/dist/cache.d.ts +84 -0
- package/dist/cache.js +351 -0
- package/dist/commands/append.d.ts +37 -0
- package/dist/commands/append.js +120 -0
- package/dist/commands/batch/delete.d.ts +42 -0
- package/dist/commands/batch/delete.js +199 -0
- package/dist/commands/batch/retrieve.d.ts +43 -0
- package/dist/commands/batch/retrieve.js +272 -0
- package/dist/commands/block/append.d.ts +42 -0
- package/dist/commands/block/append.js +219 -0
- package/dist/commands/block/delete.d.ts +30 -0
- package/dist/commands/block/delete.js +97 -0
- package/dist/commands/block/retrieve/children.d.ts +31 -0
- package/dist/commands/block/retrieve/children.js +177 -0
- package/dist/commands/block/retrieve.d.ts +30 -0
- package/dist/commands/block/retrieve.js +101 -0
- package/dist/commands/block/update.d.ts +45 -0
- package/dist/commands/block/update.js +242 -0
- package/dist/commands/bookmark/list.d.ts +30 -0
- package/dist/commands/bookmark/list.js +60 -0
- package/dist/commands/bookmark/remove.d.ts +26 -0
- package/dist/commands/bookmark/remove.js +47 -0
- package/dist/commands/bookmark/set.d.ts +29 -0
- package/dist/commands/bookmark/set.js +96 -0
- package/dist/commands/browse.d.ts +13 -0
- package/dist/commands/browse.js +44 -0
- package/dist/commands/cache/info.d.ts +19 -0
- package/dist/commands/cache/info.js +145 -0
- package/dist/commands/config/set-token.d.ts +22 -0
- package/dist/commands/config/set-token.js +137 -0
- package/dist/commands/daily/index.d.ts +32 -0
- package/dist/commands/daily/index.js +135 -0
- package/dist/commands/daily/setup.d.ts +42 -0
- package/dist/commands/daily/setup.js +149 -0
- package/dist/commands/db/create.d.ts +31 -0
- package/dist/commands/db/create.js +124 -0
- package/dist/commands/db/query.d.ts +41 -0
- package/dist/commands/db/query.js +360 -0
- package/dist/commands/db/retrieve.d.ts +33 -0
- package/dist/commands/db/retrieve.js +134 -0
- package/dist/commands/db/schema.d.ts +32 -0
- package/dist/commands/db/schema.js +308 -0
- package/dist/commands/db/update.d.ts +31 -0
- package/dist/commands/db/update.js +117 -0
- package/dist/commands/doctor.d.ts +50 -0
- package/dist/commands/doctor.js +420 -0
- package/dist/commands/init.d.ts +65 -0
- package/dist/commands/init.js +479 -0
- package/dist/commands/list.d.ts +29 -0
- package/dist/commands/list.js +219 -0
- package/dist/commands/open.d.ts +29 -0
- package/dist/commands/open.js +100 -0
- package/dist/commands/page/create.d.ts +33 -0
- package/dist/commands/page/create.js +261 -0
- package/dist/commands/page/delete.d.ts +36 -0
- package/dist/commands/page/delete.js +107 -0
- package/dist/commands/page/export.d.ts +38 -0
- package/dist/commands/page/export.js +120 -0
- package/dist/commands/page/retrieve/property_item.d.ts +24 -0
- package/dist/commands/page/retrieve/property_item.js +75 -0
- package/dist/commands/page/retrieve.d.ts +36 -0
- package/dist/commands/page/retrieve.js +244 -0
- package/dist/commands/page/update.d.ts +34 -0
- package/dist/commands/page/update.js +184 -0
- package/dist/commands/quick.d.ts +35 -0
- package/dist/commands/quick.js +168 -0
- package/dist/commands/search.d.ts +43 -0
- package/dist/commands/search.js +361 -0
- package/dist/commands/stats.d.ts +35 -0
- package/dist/commands/stats.js +274 -0
- package/dist/commands/sync.d.ts +24 -0
- package/dist/commands/sync.js +183 -0
- package/dist/commands/template/get.d.ts +28 -0
- package/dist/commands/template/get.js +59 -0
- package/dist/commands/template/list.d.ts +32 -0
- package/dist/commands/template/list.js +62 -0
- package/dist/commands/template/remove.d.ts +27 -0
- package/dist/commands/template/remove.js +48 -0
- package/dist/commands/template/save.d.ts +32 -0
- package/dist/commands/template/save.js +92 -0
- package/dist/commands/template/use.d.ts +34 -0
- package/dist/commands/template/use.js +142 -0
- package/dist/commands/user/list.d.ts +27 -0
- package/dist/commands/user/list.js +99 -0
- package/dist/commands/user/retrieve/bot.d.ts +28 -0
- package/dist/commands/user/retrieve/bot.js +96 -0
- package/dist/commands/user/retrieve.d.ts +30 -0
- package/dist/commands/user/retrieve.js +103 -0
- package/dist/commands/whoami.d.ts +19 -0
- package/dist/commands/whoami.js +175 -0
- package/dist/deduplication.d.ts +41 -0
- package/dist/deduplication.js +71 -0
- package/dist/envelope.d.ts +169 -0
- package/dist/envelope.js +257 -0
- package/dist/errors/enhanced-errors.d.ts +168 -0
- package/dist/errors/enhanced-errors.js +567 -0
- package/dist/errors/index.d.ts +18 -0
- package/dist/errors/index.js +33 -0
- package/dist/examples/cache-retry-examples.d.ts +64 -0
- package/dist/examples/cache-retry-examples.js +375 -0
- package/dist/helper.d.ts +102 -0
- package/dist/helper.js +885 -0
- package/dist/http-agent.d.ts +38 -0
- package/dist/http-agent.js +60 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/interface.d.ts +4 -0
- package/dist/interface.js +2 -0
- package/dist/notion.d.ts +144 -0
- package/dist/notion.js +547 -0
- package/dist/retry.d.ts +72 -0
- package/dist/retry.js +381 -0
- package/dist/utils/bookmarks.d.ts +32 -0
- package/dist/utils/bookmarks.js +98 -0
- package/dist/utils/daily-config.d.ts +22 -0
- package/dist/utils/daily-config.js +60 -0
- package/dist/utils/disk-cache.d.ts +80 -0
- package/dist/utils/disk-cache.js +291 -0
- package/dist/utils/fuzzy.d.ts +36 -0
- package/dist/utils/fuzzy.js +69 -0
- package/dist/utils/interactive-navigator.d.ts +63 -0
- package/dist/utils/interactive-navigator.js +123 -0
- package/dist/utils/markdown-to-blocks.d.ts +21 -0
- package/dist/utils/markdown-to-blocks.js +333 -0
- package/dist/utils/notion-resolver.d.ts +49 -0
- package/dist/utils/notion-resolver.js +278 -0
- package/dist/utils/notion-url-parser.d.ts +48 -0
- package/dist/utils/notion-url-parser.js +121 -0
- package/dist/utils/property-expander.d.ts +45 -0
- package/dist/utils/property-expander.js +323 -0
- package/dist/utils/schema-examples.d.ts +40 -0
- package/dist/utils/schema-examples.js +359 -0
- package/dist/utils/schema-extractor.d.ts +65 -0
- package/dist/utils/schema-extractor.js +235 -0
- package/dist/utils/shell-config.d.ts +30 -0
- package/dist/utils/shell-config.js +84 -0
- package/dist/utils/table-formatter.d.ts +36 -0
- package/dist/utils/table-formatter.js +125 -0
- package/dist/utils/templates.d.ts +30 -0
- package/dist/utils/templates.js +82 -0
- package/dist/utils/terminal-banner.d.ts +24 -0
- package/dist/utils/terminal-banner.js +34 -0
- package/dist/utils/token-validator.d.ts +42 -0
- package/dist/utils/token-validator.js +66 -0
- package/dist/utils/update-notifier.d.ts +26 -0
- package/dist/utils/update-notifier.js +54 -0
- package/dist/utils/workspace-cache.d.ts +58 -0
- package/dist/utils/workspace-cache.js +185 -0
- package/oclif.manifest.json +6471 -0
- package/package.json +118 -0
- package/scripts/banner.js +38 -0
- package/scripts/postinstall.js +44 -0
|
@@ -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
|
+
}
|