github-connection.mjs
37 lines 1.0 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * GitHub connection (self-hosted): store access token for "Connect GitHub" flow.
3 * Used when pushing vault to a user's repo; token is stored in data_dir (do not commit).
4 */
5
6 import fs from 'fs';
7 import path from 'path';
8
9 const FILENAME = 'github_connection.json';
10
11 /**
12 * @param {string} dataDir
13 * @returns {{ access_token?: string } | null}
14 */
15 export function readConnection(dataDir) {
16 if (!dataDir) return null;
17 const p = path.join(dataDir, FILENAME);
18 if (!fs.existsSync(p)) return null;
19 try {
20 const raw = fs.readFileSync(p, 'utf8');
21 const data = JSON.parse(raw);
22 return data && typeof data === 'object' ? data : null;
23 } catch (_) {
24 return null;
25 }
26 }
27
28 /**
29 * @param {string} dataDir
30 * @param {{ access_token: string }} data
31 */
32 export function writeConnection(dataDir, data) {
33 if (!dataDir) throw new Error('data_dir required');
34 const p = path.join(dataDir, FILENAME);
35 fs.mkdirSync(dataDir, { recursive: true });
36 fs.writeFileSync(p, JSON.stringify({ access_token: data.access_token || '' }, null, 0), 'utf8');
37 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 49 days ago