repoburg 1.0.40 → 1.0.42

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.
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const express_1 = require("express");
4
7
  const serviceManager_1 = require("../serviceManager");
5
8
  const checkAuth_1 = require("../middleware/checkAuth");
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
6
10
  const router = (0, express_1.Router)();
7
11
  router.get('/', (req, res) => {
8
12
  try {
@@ -58,10 +62,34 @@ router.delete('/:name', async (req, res) => {
58
62
  res.status(404).json({ error: message });
59
63
  }
60
64
  });
61
- router.get('/:name/logs', (req, res) => {
65
+ router.post('/remove-all', async (req, res) => {
66
+ try {
67
+ const result = await serviceManager_1.serviceManager.removeAll();
68
+ res.json(result);
69
+ }
70
+ catch (error) {
71
+ const message = error instanceof Error ? error.message : 'An unknown error occurred';
72
+ res.status(500).json({ error: message });
73
+ }
74
+ });
75
+ router.get('/:name/logs', async (req, res) => {
62
76
  try {
63
77
  const logPaths = serviceManager_1.serviceManager.getLogPaths(req.params.name);
64
- res.json(logPaths);
78
+ const readLogFile = async (filePath) => {
79
+ try {
80
+ return await fs_extra_1.default.readFile(filePath, 'utf-8');
81
+ }
82
+ catch (error) {
83
+ if (error.code === 'ENOENT') {
84
+ return '(not found)';
85
+ }
86
+ console.error(`Error reading log file ${filePath}:`, error);
87
+ return `(error reading file: ${error.message})`;
88
+ }
89
+ };
90
+ const out = await readLogFile(logPaths.out);
91
+ const err = await readLogFile(logPaths.err);
92
+ res.json({ out, err });
65
93
  }
66
94
  catch (error) {
67
95
  const message = error instanceof Error ? error.message : 'An unknown error occurred';
@@ -102,6 +102,24 @@ class AuthManager {
102
102
  return 'invalid';
103
103
  }
104
104
  }
105
+ async verifyToken(token) {
106
+ if (!this.publicKey) {
107
+ console.error('[AuthManager] Public key not loaded, cannot verify token.');
108
+ return false;
109
+ }
110
+ try {
111
+ await jose.jwtVerify(token, this.publicKey, {
112
+ issuer: 'repoburg.com',
113
+ audience: 'repoburg-daemon',
114
+ });
115
+ console.log('[AuthManager] Passed-in JWT verification successful.');
116
+ return true;
117
+ }
118
+ catch (error) {
119
+ console.warn('[AuthManager] Passed-in JWT verification failed:', error.message);
120
+ return false;
121
+ }
122
+ }
105
123
  async saveToken(token) {
106
124
  try {
107
125
  await fs_extra_1.default.ensureDir(REPOBURG_DIR);
@@ -18,7 +18,8 @@ async function main() {
18
18
  const server = http_1.default.createServer(app);
19
19
  const wss = new ws_1.WebSocketServer({ server });
20
20
  app.use((0, cors_1.default)({
21
- origin: [/^http:\/\/localhost:\d+$/, 'https://app.repoburg.com'],
21
+ origin: '*', // Allow all
22
+ methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
22
23
  credentials: true,
23
24
  }));
24
25
  app.use(express_1.default.json());
@@ -3,6 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkAuth = checkAuth;
4
4
  const authManager_1 = require("../auth/authManager");
5
5
  async function checkAuth(req, res, next) {
6
+ // Check for Bearer token first for browser-based requests
7
+ const authHeader = req.headers.authorization;
8
+ if (authHeader && authHeader.startsWith('Bearer ')) {
9
+ const token = authHeader.substring(7);
10
+ const isValid = await authManager_1.authManager.verifyToken(token);
11
+ if (isValid) {
12
+ return next();
13
+ }
14
+ // If token is present but invalid, deny access immediately
15
+ return res.status(401).json({ error: 'Unauthorized', message: 'Invalid or expired token provided.' });
16
+ }
17
+ // Fallback to file-based auth status for CLI
6
18
  const status = await authManager_1.authManager.getAuthStatus();
7
19
  if (status === 'authorized') {
8
20
  return next();
@@ -246,6 +246,28 @@ class ServiceManager {
246
246
  return { message: `Service '${name}' removed from state. Could not remove from PM2.` };
247
247
  }
248
248
  }
249
+ async removeAll() {
250
+ console.log('Attempting to remove all services.');
251
+ const services = this.list();
252
+ const results = [];
253
+ if (services.length === 0) {
254
+ console.log('No services to remove.');
255
+ return { results: [] };
256
+ }
257
+ for (const service of services) {
258
+ try {
259
+ const result = await this.remove(service.name);
260
+ results.push({ name: service.name, message: result.message });
261
+ }
262
+ catch (error) {
263
+ const message = error instanceof Error ? error.message : 'An unknown error occurred';
264
+ results.push({ name: service.name, message: `Failed to remove: ${message}` });
265
+ console.error(`Failed to remove service ${service.name} during removeAll:`, error);
266
+ }
267
+ }
268
+ console.log('Finished removing all services.');
269
+ return { results };
270
+ }
249
271
  list() {
250
272
  return stateManager_1.stateManager.getServices();
251
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repoburg",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "A local AI-powered software developer assistant that runs on your own machine.",
5
5
  "author": "Celal Ertug",
6
6
  "license": "SEE LICENSE IN LICENSE",
package/platform-cli.js CHANGED
@@ -234,6 +234,38 @@ program
234
234
  }
235
235
  });
236
236
 
237
+ program
238
+ .command('remove-all')
239
+ .description('Stop and remove all services from management.')
240
+ .action(async () => {
241
+ const { default: chalk } = await import('chalk');
242
+ try {
243
+ const response = await axios.post(`${DAEMON_BASE_URL}/services/remove-all`);
244
+ const { results } = response.data;
245
+
246
+ if (!results || results.length === 0) {
247
+ console.log(chalk.yellow('No services were managed.'));
248
+ return;
249
+ }
250
+
251
+ console.log(chalk.green('✓ All services processed:'));
252
+
253
+ const Table = require('cli-table3');
254
+ const table = new Table({
255
+ head: ['NAME', 'RESULT'].map(h => chalk.cyan(h)),
256
+ colWidths: [20, 80]
257
+ });
258
+
259
+ results.forEach(result => {
260
+ table.push([result.name, result.message]);
261
+ });
262
+ console.log(table.toString());
263
+
264
+ } catch (error) {
265
+ handleApiError(error);
266
+ }
267
+ });
268
+
237
269
  program
238
270
  .command('logs <name>')
239
271
  .description('Display logs for a specific backend instance.')