dotshare-cli 1.0.0 → 3.0.1

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 (57) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +258 -189
  3. package/SECURITY.md +145 -0
  4. package/bin/dotshare-agent.js +7 -0
  5. package/bin/dotshare-cli.js +11 -7
  6. package/bin/dotshare-mcp.js +6 -0
  7. package/docs/AGENT_INTEGRATION.md +556 -0
  8. package/out/agent/commands.js +120 -0
  9. package/out/agent/server.js +98 -0
  10. package/out/cli/commands.js +129 -376
  11. package/package.json +34 -94
  12. package/bin/dotshare-scheduler.js +0 -208
  13. package/out/analytics.js +0 -67
  14. package/out/analytics.js.map +0 -1
  15. package/out/bluesky.js +0 -100
  16. package/out/bluesky.js.map +0 -1
  17. package/out/cli/commands.js.map +0 -1
  18. package/out/cli/config.js +0 -144
  19. package/out/cli/config.js.map +0 -1
  20. package/out/credential-provider.js +0 -92
  21. package/out/credential-provider.js.map +0 -1
  22. package/out/discord.js +0 -85
  23. package/out/discord.js.map +0 -1
  24. package/out/extension.js +0 -1383
  25. package/out/extension.js.map +0 -1
  26. package/out/facebook.js +0 -66
  27. package/out/facebook.js.map +0 -1
  28. package/out/gemini.js +0 -219
  29. package/out/gemini.js.map +0 -1
  30. package/out/linkedin.js +0 -110
  31. package/out/linkedin.js.map +0 -1
  32. package/out/message-handlers.js +0 -391
  33. package/out/message-handlers.js.map +0 -1
  34. package/out/openai.js +0 -217
  35. package/out/openai.js.map +0 -1
  36. package/out/post-executor.js +0 -168
  37. package/out/post-executor.js.map +0 -1
  38. package/out/reddit.js +0 -538
  39. package/out/reddit.js.map +0 -1
  40. package/out/scheduled-posts.js +0 -100
  41. package/out/scheduled-posts.js.map +0 -1
  42. package/out/scheduler.js +0 -98
  43. package/out/scheduler.js.map +0 -1
  44. package/out/storage-manager.js +0 -403
  45. package/out/storage-manager.js.map +0 -1
  46. package/out/telegram.js +0 -104
  47. package/out/telegram.js.map +0 -1
  48. package/out/types.js +0 -3
  49. package/out/types.js.map +0 -1
  50. package/out/webview-provider.js +0 -168
  51. package/out/webview-provider.js.map +0 -1
  52. package/out/x.js +0 -55
  53. package/out/x.js.map +0 -1
  54. package/out/xai.js +0 -235
  55. package/out/xai.js.map +0 -1
  56. package/src/cli/commands.ts +0 -380
  57. package/src/cli/config.ts +0 -148
@@ -1,380 +0,0 @@
1
- import { Command } from 'commander';
2
- import open from 'open';
3
- import axios from 'axios';
4
- import * as readline from 'readline';
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import { ConfigManager } from './config';
8
-
9
- const configManager = new ConfigManager();
10
-
11
- // Create readline interface for user input
12
- function createReadlineInterface() {
13
- return readline.createInterface({
14
- input: process.stdin,
15
- output: process.stdout
16
- });
17
- }
18
-
19
- function question(rl: readline.Interface, query: string): Promise<string> {
20
- return new Promise((resolve) => {
21
- rl.question(query, resolve);
22
- });
23
- }
24
-
25
- // Init command
26
- export function setupInitCommand(program: Command) {
27
- program
28
- .command('init')
29
- .description('Initialize DotShare CLI configuration')
30
- .action(async () => {
31
- console.log('🚀 Welcome to DotShare CLI Setup!\n');
32
-
33
- const rl = createReadlineInterface();
34
-
35
- try {
36
- // Get server URL
37
- const currentConfig = configManager.getConfig();
38
- const defaultServerUrl = currentConfig.serverUrl || 'http://localhost:3000';
39
-
40
- const serverUrl = await question(rl, `Python server URL [${defaultServerUrl}]: `);
41
- const finalServerUrl = serverUrl.trim() || defaultServerUrl;
42
-
43
- configManager.setServerUrl(finalServerUrl);
44
- console.log(`✅ Server URL set to: ${finalServerUrl}\n`);
45
-
46
- // Test server connection
47
- console.log('🔍 Testing server connection...');
48
- try {
49
- const response = await axios.get(`${finalServerUrl}/`, { timeout: 5000 });
50
- if (response.status === 200) {
51
- console.log('✅ Server connection successful!\n');
52
- }
53
- } catch (error) {
54
- console.log('⚠️ Server connection failed. Make sure the Python server is running.\n');
55
- }
56
-
57
- console.log('🎉 DotShare CLI initialized successfully!');
58
- console.log('Next steps:');
59
- console.log(' • Run "dotshare login telegram" to authenticate Telegram');
60
- console.log(' • Run "dotshare login linkedin" to authenticate LinkedIn');
61
- console.log(' • Run "dotshare login reddit" to authenticate Reddit');
62
- console.log(' • Run "dotshare whoami" to check your setup');
63
- console.log(' • Run "dotshare \'Hello World!\'" to post to all platforms');
64
-
65
- } catch (error) {
66
- console.error('❌ Error during initialization:', error);
67
- } finally {
68
- rl.close();
69
- }
70
- });
71
- }
72
-
73
- // Login commands
74
- export function setupLoginCommand(program: Command) {
75
- const loginCmd = program
76
- .command('login')
77
- .description('Authenticate with social platforms');
78
-
79
- loginCmd
80
- .command('telegram')
81
- .description('Authenticate with Telegram')
82
- .action(async () => {
83
- console.log('🔐 Telegram Authentication');
84
- console.log('This will open your browser to authenticate with Telegram.\n');
85
-
86
- const config = configManager.getConfig();
87
- const serverUrl = config.serverUrl;
88
-
89
- try {
90
- // Check server connection
91
- await axios.get(`${serverUrl}/`, { timeout: 3000 });
92
-
93
- // Open browser to Python server
94
- const authUrl = `${serverUrl}/?provider=telegram`;
95
- console.log(`🌐 Opening: ${authUrl}`);
96
- await open(authUrl);
97
-
98
- console.log('\n📝 Instructions:');
99
- console.log('1. Complete the authentication in your browser');
100
- console.log('2. Copy the access token from the success page');
101
- console.log('3. Run the following command with your token:');
102
- console.log(' dotshare login telegram --token YOUR_TOKEN --chat YOUR_CHAT_ID');
103
-
104
- // Wait for user to provide token
105
- const rl = createReadlineInterface();
106
- try {
107
- const token = await question(rl, '\nEnter Telegram bot token: ');
108
- const chatId = await question(rl, 'Enter Telegram chat ID: ');
109
-
110
- if (token.trim() && chatId.trim()) {
111
- configManager.setTelegramCredentials(token.trim(), chatId.trim());
112
- console.log('✅ Telegram credentials saved!');
113
- } else {
114
- console.log('❌ Token or chat ID cannot be empty');
115
- }
116
- } finally {
117
- rl.close();
118
- }
119
-
120
- } catch (error) {
121
- console.error('❌ Error:', error instanceof Error ? error.message : 'Unknown error');
122
- console.log('💡 Make sure the Python server is running on', serverUrl);
123
- }
124
- });
125
-
126
- loginCmd
127
- .command('linkedin')
128
- .description('Authenticate with LinkedIn')
129
- .action(async () => {
130
- console.log('🔐 LinkedIn Authentication');
131
- console.log('This will open your browser to authenticate with LinkedIn.\n');
132
-
133
- const config = configManager.getConfig();
134
- const serverUrl = config.serverUrl;
135
-
136
- try {
137
- // Check server connection
138
- await axios.get(`${serverUrl}/`, { timeout: 3000 });
139
-
140
- // Open browser to Python server
141
- const authUrl = `${serverUrl}/?provider=linkedin`;
142
- console.log(`🌐 Opening: ${authUrl}`);
143
- await open(authUrl);
144
-
145
- console.log('\n📝 Instructions:');
146
- console.log('1. Complete the LinkedIn OAuth flow in your browser');
147
- console.log('2. Copy the access token from the success page');
148
- console.log('3. Run the following command with your token:');
149
- console.log(' dotshare login linkedin --token YOUR_TOKEN');
150
-
151
- // Wait for user to provide token
152
- const rl = createReadlineInterface();
153
- try {
154
- const token = await question(rl, '\nEnter LinkedIn access token: ');
155
-
156
- if (token.trim()) {
157
- configManager.setLinkedInToken(token.trim());
158
- console.log('✅ LinkedIn credentials saved!');
159
- } else {
160
- console.log('❌ Token cannot be empty');
161
- }
162
- } finally {
163
- rl.close();
164
- }
165
-
166
- } catch (error) {
167
- console.error('❌ Error:', error instanceof Error ? error.message : 'Unknown error');
168
- console.log('💡 Make sure the Python server is running on', serverUrl);
169
- }
170
- });
171
-
172
- loginCmd
173
- .command('reddit')
174
- .description('Authenticate with Reddit')
175
- .action(async () => {
176
- console.log('🔐 Reddit Authentication');
177
- console.log('This will open your browser to authenticate with Reddit.\n');
178
-
179
- const config = configManager.getConfig();
180
- const serverUrl = config.serverUrl;
181
-
182
- try {
183
- // Check server connection
184
- await axios.get(`${serverUrl}/`, { timeout: 3000 });
185
-
186
- // Open browser to Python server
187
- const authUrl = `${serverUrl}/?provider=reddit`;
188
- console.log(`🌐 Opening: ${authUrl}`);
189
- await open(authUrl);
190
-
191
- console.log('\n📝 Instructions:');
192
- console.log('1. Complete the Reddit OAuth flow in your browser');
193
- console.log('2. Copy the access token from the success page');
194
- console.log('3. Run the following command with your token:');
195
- console.log(' dotshare login reddit --token YOUR_TOKEN');
196
-
197
- // Wait for user to provide token
198
- const rl = createReadlineInterface();
199
- try {
200
- const token = await question(rl, '\nEnter Reddit access token: ');
201
- const refreshToken = await question(rl, 'Enter Reddit refresh token (optional): ');
202
-
203
- if (token.trim()) {
204
- configManager.setRedditCredentials(token.trim(), refreshToken.trim() || undefined);
205
- console.log('✅ Reddit credentials saved!');
206
- } else {
207
- console.log('❌ Token cannot be empty');
208
- }
209
- } finally {
210
- rl.close();
211
- }
212
-
213
- } catch (error) {
214
- console.error('❌ Error:', error instanceof Error ? error.message : 'Unknown error');
215
- console.log('💡 Make sure the Python server is running on', serverUrl);
216
- }
217
- });
218
- }
219
-
220
- // Whoami command
221
- export function setupWhoamiCommand(program: Command) {
222
- program
223
- .command('whoami')
224
- .description('Show current configuration and status')
225
- .action(() => {
226
- const config = configManager.getConfig();
227
- const platforms = configManager.getConfiguredPlatforms();
228
-
229
- console.log('🔍 DotShare CLI Status\n');
230
-
231
- console.log(`📡 Server URL: ${config.serverUrl}`);
232
-
233
- console.log('\n🔐 Authenticated Platforms:');
234
- if (platforms.length === 0) {
235
- console.log(' None - Run "dotshare login <platform>" to authenticate');
236
- } else {
237
- platforms.forEach(platform => {
238
- console.log(` ✅ ${platform.charAt(0).toUpperCase() + platform.slice(1)}`);
239
- });
240
- }
241
-
242
- console.log('\n📊 Configuration:');
243
- console.log(` Config file: ~/.dotshare/config.json`);
244
-
245
- if (platforms.length > 0) {
246
- console.log('\n🚀 Ready to post! Try:');
247
- console.log(' dotshare "Hello from CLI!"');
248
- console.log(' dotshare "Check this image" --media ./image.jpg');
249
- } else {
250
- console.log('\n⚠️ Setup incomplete. Run "dotshare init" to get started.');
251
- }
252
- });
253
- }
254
-
255
- // Default posting command
256
- export function setupDefaultCommand(program: Command) {
257
- program
258
- .arguments('[message]')
259
- .option('--media <path>', 'Path to media file')
260
- .option('--platforms <list>', 'Comma-separated list of platforms (telegram,linkedin,reddit)')
261
- .description('Post message to configured platforms')
262
- .action(async (message: string | undefined, options: { media?: string; platforms?: string }) => {
263
- if (!message && !options.media) {
264
- console.log('❌ Error: Message or media file is required\n');
265
- console.log('Usage examples:');
266
- console.log(' dotshare "Hello World!"');
267
- console.log(' dotshare --media ./image.jpg');
268
- console.log(' dotshare "Check this out" --media ./video.mp4 --platforms telegram,linkedin');
269
- return;
270
- }
271
-
272
- const config = configManager.getConfig();
273
- const availablePlatforms = configManager.getConfiguredPlatforms();
274
-
275
- if (availablePlatforms.length === 0) {
276
- console.log('❌ No platforms configured. Run "dotshare login <platform>" first.');
277
- return;
278
- }
279
-
280
- // Parse platforms option
281
- let targetPlatforms: ('telegram' | 'linkedin' | 'reddit')[];
282
- if (options.platforms) {
283
- targetPlatforms = options.platforms.split(',').map(p => p.trim().toLowerCase()) as ('telegram' | 'linkedin' | 'reddit')[];
284
- // Validate platforms
285
- const invalidPlatforms = targetPlatforms.filter(p => !availablePlatforms.includes(p));
286
- if (invalidPlatforms.length > 0) {
287
- console.log(`❌ Invalid platforms: ${invalidPlatforms.join(', ')}`);
288
- console.log(`Available platforms: ${availablePlatforms.join(', ')}`);
289
- return;
290
- }
291
- } else {
292
- targetPlatforms = availablePlatforms;
293
- }
294
-
295
- console.log('🚀 Posting to platforms:', targetPlatforms.join(', '));
296
-
297
- // Prepare media data URLs if media file provided
298
- let mediaUrls: string[] = [];
299
- if (options.media && fs.existsSync(options.media)) {
300
- console.log(`📎 Media: ${options.media}`);
301
-
302
- const fileContent = fs.readFileSync(options.media);
303
- const ext = path.extname(options.media).toLowerCase();
304
- let mimeType = 'application/octet-stream';
305
- if (ext === '.jpg' || ext === '.jpeg') mimeType = 'image/jpeg';
306
- else if (ext === '.png') mimeType = 'image/png';
307
- else if (ext === '.gif') mimeType = 'image/gif';
308
- else if (ext === '.mp4') mimeType = 'video/mp4';
309
-
310
- const dataUrl = `data:${mimeType};base64,${fileContent.toString('base64')}`;
311
- mediaUrls = [dataUrl];
312
- }
313
-
314
- // Post to each platform
315
- const results: { platform: string; success: boolean; error?: string }[] = [];
316
-
317
- for (const platform of targetPlatforms) {
318
- try {
319
- console.log(`📤 Posting to ${platform}...`);
320
-
321
- let endpoint: string;
322
- const payload: any = {
323
- text: message || '',
324
- media_urls: mediaUrls
325
- };
326
-
327
- switch (platform) {
328
- case 'telegram':
329
- endpoint = '/api/post/telegram';
330
- payload.bot_token = config.credentials.telegram?.botToken;
331
- payload.chat_id = config.credentials.telegram?.chatId;
332
- break;
333
- case 'linkedin':
334
- endpoint = '/api/post/linkedin';
335
- payload.access_token = config.credentials.linkedin?.accessToken;
336
- break;
337
- case 'reddit':
338
- endpoint = '/api/post/reddit';
339
- payload.access_token = config.credentials.reddit?.accessToken;
340
- payload.subreddit = 'test'; // Default subreddit
341
- payload.title = message?.substring(0, 300) || 'Posted from DotShare CLI';
342
- break;
343
- default:
344
- throw new Error(`Unsupported platform: ${platform}`);
345
- }
346
-
347
- const response = await axios.post(`${config.serverUrl}${endpoint}`, payload, {
348
- timeout: 30000
349
- });
350
-
351
- if (response.data.success) {
352
- console.log(`✅ ${platform}: Success`);
353
- results.push({ platform, success: true });
354
- } else {
355
- console.log(`❌ ${platform}: ${response.data.error || 'Unknown error'}`);
356
- results.push({ platform, success: false, error: response.data.error });
357
- }
358
-
359
- } catch (error: any) {
360
- const errorMsg = error.response?.data?.error || error.message || 'Unknown error';
361
- console.log(`❌ ${platform}: ${errorMsg}`);
362
- results.push({ platform, success: false, error: errorMsg });
363
- }
364
- }
365
-
366
- // Summary
367
- const successful = results.filter(r => r.success).length;
368
- const total = results.length;
369
-
370
- console.log(`\n📊 Results: ${successful}/${total} successful`);
371
-
372
- if (successful === total) {
373
- console.log('🎉 All posts successful!');
374
- } else if (successful > 0) {
375
- console.log('⚠️ Some posts failed. Check the errors above.');
376
- } else {
377
- console.log('💥 All posts failed. Check your configuration and server.');
378
- }
379
- });
380
- }
package/src/cli/config.ts DELETED
@@ -1,148 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as os from 'os';
4
-
5
- export interface DotShareConfig {
6
- serverUrl: string;
7
- credentials: {
8
- telegram?: {
9
- botToken: string;
10
- chatId: string;
11
- };
12
- linkedin?: {
13
- accessToken: string;
14
- };
15
- reddit?: {
16
- accessToken: string;
17
- refreshToken?: string;
18
- };
19
- };
20
- defaultPlatforms: ('telegram' | 'linkedin' | 'reddit')[];
21
- }
22
-
23
- const DEFAULT_SERVER_URL = 'https://web-production-9d87f2.up.railway.app';
24
- export class ConfigManager {
25
- private configPath: string;
26
- private config: DotShareConfig | null = null;
27
-
28
- constructor() {
29
- const homeDir = os.homedir();
30
- const configDir = path.join(homeDir, '.dotshare');
31
- this.configPath = path.join(configDir, 'config.json');
32
-
33
- // Ensure config directory exists
34
- if (!fs.existsSync(configDir)) {
35
- fs.mkdirSync(configDir, { recursive: true });
36
- }
37
- }
38
-
39
- private loadConfig(): DotShareConfig {
40
- if (this.config) return this.config;
41
-
42
- try {
43
- if (fs.existsSync(this.configPath)) {
44
- const data = fs.readFileSync(this.configPath, 'utf8');
45
- this.config = JSON.parse(data);
46
- } else {
47
- // Create default config
48
- this.config = {
49
- serverUrl: DEFAULT_SERVER_URL,
50
- credentials: {},
51
- defaultPlatforms: []
52
- };
53
- this.saveConfig();
54
- }
55
- } catch (error) {
56
- console.error('Error loading config:', error);
57
- // Return default config on error
58
- this.config = {
59
- serverUrl: DEFAULT_SERVER_URL,
60
- credentials: {},
61
- defaultPlatforms: []
62
- };
63
- }
64
-
65
- // Ensure we always return a valid config
66
- return this.config || {
67
- serverUrl: DEFAULT_SERVER_URL,
68
- credentials: {},
69
- defaultPlatforms: []
70
- };
71
- }
72
-
73
- private saveConfig(): void {
74
- if (!this.config) return;
75
-
76
- try {
77
- fs.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2));
78
- } catch (error) {
79
- console.error('Error saving config:', error);
80
- }
81
- }
82
-
83
- public getConfig(): DotShareConfig {
84
- return this.loadConfig();
85
- }
86
-
87
- public setServerUrl(url: string): void {
88
- this.loadConfig();
89
- if (this.config) {
90
- this.config.serverUrl = url;
91
- this.saveConfig();
92
- }
93
- }
94
-
95
- public setTelegramCredentials(botToken: string, chatId: string): void {
96
- this.loadConfig();
97
- if (this.config) {
98
- this.config.credentials.telegram = { botToken, chatId };
99
- this.saveConfig();
100
- }
101
- }
102
-
103
- public setLinkedInToken(accessToken: string): void {
104
- this.loadConfig();
105
- if (this.config) {
106
- this.config.credentials.linkedin = { accessToken };
107
- this.saveConfig();
108
- }
109
- }
110
-
111
- public setRedditCredentials(accessToken: string, refreshToken?: string): void {
112
- this.loadConfig();
113
- if (this.config) {
114
- this.config.credentials.reddit = { accessToken, refreshToken };
115
- this.saveConfig();
116
- }
117
- }
118
-
119
- public setDefaultPlatforms(platforms: ('telegram' | 'linkedin' | 'reddit')[]): void {
120
- this.loadConfig();
121
- if (this.config) {
122
- this.config.defaultPlatforms = platforms;
123
- this.saveConfig();
124
- }
125
- }
126
-
127
- public getConfiguredPlatforms(): ('telegram' | 'linkedin' | 'reddit')[] {
128
- const config = this.loadConfig();
129
- const platforms: ('telegram' | 'linkedin' | 'reddit')[] = [];
130
-
131
- if (config.credentials.telegram?.botToken && config.credentials.telegram?.chatId) {
132
- platforms.push('telegram');
133
- }
134
- if (config.credentials.linkedin?.accessToken) {
135
- platforms.push('linkedin');
136
- }
137
- if (config.credentials.reddit?.accessToken) {
138
- platforms.push('reddit');
139
- }
140
-
141
- return platforms;
142
- }
143
-
144
- public isInitialized(): boolean {
145
- const config = this.loadConfig();
146
- return !!(config.serverUrl && Object.keys(config.credentials).length > 0);
147
- }
148
- }