octocode-shared 1.0.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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Credentials Module Exports
3
+ */
4
+ export type { OAuthToken, StoredCredentials, StoreResult, DeleteResult, CredentialsStore, TokenSource, } from './types.js';
5
+ export { initializeSecureStorage, isSecureStorageAvailable, isUsingSecureStorage, storeCredentials, getCredentials, type GetCredentialsOptions, getCredentialsSync, deleteCredentials, updateToken, invalidateCredentialsCache, getToken, getTokenSync, resolveToken, type ResolvedToken, getTokenWithRefresh, type TokenWithRefreshResult, resolveTokenWithRefresh, type ResolvedTokenWithRefresh, refreshAuthToken, type RefreshResult, resolveTokenFull, type FullTokenResolution, type GhCliTokenGetter, listStoredHosts, listStoredHostsSync, hasCredentials, hasCredentialsSync, isTokenExpired, isRefreshTokenExpired, getCredentialsFilePath, readCredentialsStore, encrypt, decrypt, ensureOctocodeDir, OCTOCODE_DIR, CREDENTIALS_FILE, KEY_FILE, ENV_TOKEN_VARS, getTokenFromEnv, getEnvTokenSource, hasEnvToken, TimeoutError, _setSecureStorageAvailable, _resetSecureStorageState, _getCacheStats, _resetCredentialsCache, } from './storage.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAEL,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EAGpB,gBAAgB,EAChB,cAAc,EACd,KAAK,qBAAqB,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EAGX,0BAA0B,EAG1B,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,KAAK,aAAa,EAGlB,mBAAmB,EACnB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,gBAAgB,EAChB,KAAK,aAAa,EAGlB,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAGrB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAGlB,cAAc,EACd,qBAAqB,EAGrB,sBAAsB,EAGtB,oBAAoB,EACpB,OAAO,EACP,OAAO,EACP,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,QAAQ,EACR,cAAc,EAGd,eAAe,EACf,iBAAiB,EACjB,WAAW,EAGX,YAAY,EAGZ,0BAA0B,EAC1B,wBAAwB,EACxB,cAAc,EACd,sBAAsB,GACvB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { C, E, K, O, T, H, I, G, _, z, d, y, A, g, w, c, D, f, B, h, j, p, q, F, i, e, v, a, t, b, n, o, x, l, r, m, k, s, u } from "../storage-DuH3rTiu.js";
2
+ export {
3
+ C as CREDENTIALS_FILE,
4
+ E as ENV_TOKEN_VARS,
5
+ K as KEY_FILE,
6
+ O as OCTOCODE_DIR,
7
+ T as TimeoutError,
8
+ H as _getCacheStats,
9
+ I as _resetCredentialsCache,
10
+ G as _resetSecureStorageState,
11
+ _ as _setSecureStorageAvailable,
12
+ z as decrypt,
13
+ d as deleteCredentials,
14
+ y as encrypt,
15
+ A as ensureOctocodeDir,
16
+ g as getCredentials,
17
+ w as getCredentialsFilePath,
18
+ c as getCredentialsSync,
19
+ D as getEnvTokenSource,
20
+ f as getToken,
21
+ B as getTokenFromEnv,
22
+ h as getTokenSync,
23
+ j as getTokenWithRefresh,
24
+ p as hasCredentials,
25
+ q as hasCredentialsSync,
26
+ F as hasEnvToken,
27
+ i as initializeSecureStorage,
28
+ e as invalidateCredentialsCache,
29
+ v as isRefreshTokenExpired,
30
+ a as isSecureStorageAvailable,
31
+ t as isTokenExpired,
32
+ b as isUsingSecureStorage,
33
+ n as listStoredHosts,
34
+ o as listStoredHostsSync,
35
+ x as readCredentialsStore,
36
+ l as refreshAuthToken,
37
+ r as resolveToken,
38
+ m as resolveTokenFull,
39
+ k as resolveTokenWithRefresh,
40
+ s as storeCredentials,
41
+ u as updateToken
42
+ };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Native Keychain Access
3
+ *
4
+ * Cross-platform secure credential storage using @napi-rs/keyring.
5
+ * This wraps the Rust keyring-rs library via napi-rs for native OS keychain access.
6
+ *
7
+ * Supported platforms (prebuilt binaries):
8
+ * - macOS: Keychain Access (darwin-arm64, darwin-x64)
9
+ * - Windows: Credential Manager (win32-x64, win32-arm64, win32-ia32)
10
+ * - Linux: Secret Service API via libsecret (linux-x64-gnu, linux-x64-musl, linux-arm64-gnu, etc.)
11
+ * - FreeBSD: Secret Service API
12
+ *
13
+ * This replaces the previous custom implementation with a battle-tested library,
14
+ * following the same pattern as gh CLI's use of zalando/go-keyring.
15
+ */
16
+ /**
17
+ * Check if native keychain is available on this platform.
18
+ * With @napi-rs/keyring, this is always true since it has prebuilt binaries
19
+ * for all supported platforms.
20
+ */
21
+ export declare function isKeychainAvailable(): boolean;
22
+ /**
23
+ * Store a password in the system keychain
24
+ * @param service - Service name (app identifier)
25
+ * @param account - Account identifier (e.g., hostname)
26
+ * @param password - Password/data to store
27
+ */
28
+ export declare function setPassword(service: string, account: string, password: string): Promise<void>;
29
+ /**
30
+ * Get a password from the system keychain
31
+ * @param service - Service name (app identifier)
32
+ * @param account - Account identifier (e.g., hostname)
33
+ * @returns Password/data or null if not found
34
+ */
35
+ export declare function getPassword(service: string, account: string): Promise<string | null>;
36
+ /**
37
+ * Delete a password from the system keychain
38
+ * @param service - Service name (app identifier)
39
+ * @param account - Account identifier (e.g., hostname)
40
+ * @returns true if deleted, false if not found
41
+ */
42
+ export declare function deletePassword(service: string, account: string): Promise<boolean>;
43
+ /**
44
+ * Find all credentials for a service
45
+ * @param service - Service name (app identifier)
46
+ * @returns Array of {account, password} objects
47
+ */
48
+ export declare function findCredentials(service: string): Promise<{
49
+ account: string;
50
+ password: string;
51
+ }[]>;
52
+ //# sourceMappingURL=keychain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keychain.d.ts","sourceRoot":"","sources":["../../src/credentials/keychain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAI7C;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASxB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAQlD"}
@@ -0,0 +1,367 @@
1
+ /**
2
+ * Token Storage Utility
3
+ *
4
+ * Stores OAuth tokens securely using:
5
+ * 1. System keychain (native OS commands) - preferred for desktop environments
6
+ * 2. Encrypted file fallback (~/.octocode/credentials.json) - for CI/server
7
+ *
8
+ * Behavior matches gh CLI's credential storage approach.
9
+ */
10
+ import type { StoredCredentials, StoreResult, DeleteResult, CredentialsStore, TokenSource } from './types.js';
11
+ /**
12
+ * Timeout error for keyring operations
13
+ */
14
+ export declare class TimeoutError extends Error {
15
+ constructor(message: string);
16
+ }
17
+ export declare const OCTOCODE_DIR: string;
18
+ export declare const CREDENTIALS_FILE: string;
19
+ export declare const KEY_FILE: string;
20
+ /**
21
+ * Invalidate cache for a hostname (call after credential changes)
22
+ * @param hostname - Hostname to invalidate, or undefined to clear all
23
+ */
24
+ export declare function invalidateCredentialsCache(hostname?: string): void;
25
+ /**
26
+ * Get cache statistics (for debugging/monitoring)
27
+ * @internal
28
+ */
29
+ export declare function _getCacheStats(): {
30
+ size: number;
31
+ entries: Array<{
32
+ hostname: string;
33
+ age: number;
34
+ valid: boolean;
35
+ }>;
36
+ };
37
+ /**
38
+ * Reset cache state (for testing)
39
+ * @internal
40
+ */
41
+ export declare function _resetCredentialsCache(): void;
42
+ /**
43
+ * Environment variable names for token lookup (in priority order)
44
+ */
45
+ export declare const ENV_TOKEN_VARS: readonly ["OCTOCODE_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"];
46
+ /**
47
+ * Get token from environment variables
48
+ *
49
+ * Checks environment variables in priority order:
50
+ * 1. OCTOCODE_TOKEN - octocode-specific token
51
+ * 2. GH_TOKEN - GitHub CLI compatible
52
+ * 3. GITHUB_TOKEN - GitHub Actions native
53
+ *
54
+ * @returns Token string or null if not found in any env var
55
+ */
56
+ export declare function getTokenFromEnv(): string | null;
57
+ /**
58
+ * Get the source of an environment variable token
59
+ *
60
+ * @returns The env var name that contains the token, or null if none found
61
+ */
62
+ export declare function getEnvTokenSource(): TokenSource;
63
+ /**
64
+ * Check if token is available from environment variables
65
+ */
66
+ export declare function hasEnvToken(): boolean;
67
+ /**
68
+ * Initialize secure storage by checking keychain availability.
69
+ * Call this before using any credential functions to ensure keychain is checked.
70
+ *
71
+ * Note: Migration from file to keychain happens lazily on first credential access,
72
+ * not at startup. This avoids triggering keychain permission prompts on every app launch.
73
+ *
74
+ * @returns true if secure storage (native keychain) is available
75
+ */
76
+ export declare function initializeSecureStorage(): Promise<boolean>;
77
+ /**
78
+ * Check if secure storage (native keychain) is available
79
+ */
80
+ export declare function isSecureStorageAvailable(): boolean;
81
+ /**
82
+ * Force set secure storage availability (for testing)
83
+ * @internal
84
+ */
85
+ export declare function _setSecureStorageAvailable(available: boolean): void;
86
+ /**
87
+ * Reset secure storage state (for testing)
88
+ * @internal
89
+ */
90
+ export declare function _resetSecureStorageState(): void;
91
+ /**
92
+ * Encrypt data for file storage
93
+ */
94
+ export declare function encrypt(data: string): string;
95
+ /**
96
+ * Decrypt data from file storage
97
+ */
98
+ export declare function decrypt(encryptedData: string): string;
99
+ /**
100
+ * Ensure .octocode directory exists with secure permissions (0o700)
101
+ */
102
+ export declare function ensureOctocodeDir(): void;
103
+ /**
104
+ * Read credentials store from file
105
+ */
106
+ export declare function readCredentialsStore(): CredentialsStore;
107
+ /**
108
+ * Store credentials using keyring-first strategy (like gh CLI)
109
+ *
110
+ * Flow:
111
+ * 1. Try keyring with timeout
112
+ * 2. On success: remove from file storage (clean migration)
113
+ * 3. On failure: fallback to encrypted file storage
114
+ * 4. Invalidate cache to ensure fresh reads
115
+ *
116
+ * @returns StoreResult with insecureStorageUsed flag
117
+ */
118
+ export declare function storeCredentials(credentials: StoredCredentials): Promise<StoreResult>;
119
+ /**
120
+ * Options for getCredentials
121
+ */
122
+ export interface GetCredentialsOptions {
123
+ /** Bypass cache and fetch fresh credentials from storage */
124
+ bypassCache?: boolean;
125
+ }
126
+ /**
127
+ * Get credentials using keyring-first strategy (like gh CLI)
128
+ *
129
+ * Flow:
130
+ * 1. Check in-memory cache (unless bypassed)
131
+ * 2. Try keyring with timeout
132
+ * 3. Fallback to file storage (with lazy migration to keyring)
133
+ * 4. Cache result for future calls
134
+ *
135
+ * @param hostname - GitHub hostname (default: 'github.com')
136
+ * @param options - Optional settings (e.g., bypassCache)
137
+ * @returns Stored credentials or null if not found
138
+ */
139
+ export declare function getCredentials(hostname?: string, options?: GetCredentialsOptions): Promise<StoredCredentials | null>;
140
+ /**
141
+ * Get credentials synchronously (file storage only)
142
+ *
143
+ * ⚠️ WARNING: This only reads from file storage, not keyring.
144
+ * Use getCredentials() (async) for the full keyring-first lookup.
145
+ * This sync version is kept for backward compatibility only.
146
+ *
147
+ * @param hostname - GitHub hostname (default: 'github.com')
148
+ * @returns Stored credentials from file or null if not found
149
+ */
150
+ export declare function getCredentialsSync(hostname?: string): StoredCredentials | null;
151
+ /**
152
+ * Delete credentials from both keyring and file storage
153
+ *
154
+ * Flow:
155
+ * 1. Delete from keyring (with timeout, best-effort)
156
+ * 2. Delete from file storage
157
+ * 3. Return combined result with details
158
+ *
159
+ * @returns DeleteResult with details about what was deleted
160
+ */
161
+ export declare function deleteCredentials(hostname?: string): Promise<DeleteResult>;
162
+ /**
163
+ * List all stored hostnames (from both keyring and file)
164
+ */
165
+ export declare function listStoredHosts(): Promise<string[]>;
166
+ /**
167
+ * List stored hosts synchronously (file storage only)
168
+ *
169
+ * ⚠️ WARNING: This only lists file storage, not keyring.
170
+ * Use listStoredHosts() (async) for full list.
171
+ */
172
+ export declare function listStoredHostsSync(): string[];
173
+ /**
174
+ * Check if credentials exist for a hostname
175
+ */
176
+ export declare function hasCredentials(hostname?: string): Promise<boolean>;
177
+ /**
178
+ * Check if credentials exist synchronously (file storage only)
179
+ *
180
+ * ⚠️ WARNING: This only checks file storage, not keyring.
181
+ * Use hasCredentials() (async) for full check.
182
+ */
183
+ export declare function hasCredentialsSync(hostname?: string): boolean;
184
+ /**
185
+ * Update token for a hostname (used for refresh)
186
+ */
187
+ export declare function updateToken(hostname: string, token: StoredCredentials['token']): Promise<boolean>;
188
+ /**
189
+ * Get the credentials storage location (for display purposes)
190
+ */
191
+ export declare function getCredentialsFilePath(): string;
192
+ /**
193
+ * Alias for isSecureStorageAvailable (for backward compatibility)
194
+ */
195
+ export declare function isUsingSecureStorage(): boolean;
196
+ /**
197
+ * Check if token is expired (for GitHub Apps with expiring tokens)
198
+ */
199
+ export declare function isTokenExpired(credentials: StoredCredentials): boolean;
200
+ /**
201
+ * Check if refresh token is expired
202
+ */
203
+ export declare function isRefreshTokenExpired(credentials: StoredCredentials): boolean;
204
+ /**
205
+ * Get token from stored credentials (keychain/file only)
206
+ *
207
+ * Convenience function that retrieves credentials and returns just the token string.
208
+ * Checks for token expiration before returning.
209
+ *
210
+ * NOTE: This does NOT check environment variables. Use resolveToken() for full resolution.
211
+ * NOTE: This does NOT refresh expired tokens. Use getTokenWithRefresh() for auto-refresh.
212
+ *
213
+ * @param hostname - GitHub hostname (default: 'github.com')
214
+ * @returns Token string or null if not found/expired
215
+ */
216
+ export declare function getToken(hostname?: string): Promise<string | null>;
217
+ /**
218
+ * Result of a token refresh operation
219
+ */
220
+ export interface RefreshResult {
221
+ success: boolean;
222
+ username?: string;
223
+ hostname?: string;
224
+ error?: string;
225
+ }
226
+ /**
227
+ * Refresh an expired OAuth token using the refresh token
228
+ *
229
+ * @param hostname - GitHub hostname (default: 'github.com')
230
+ * @param clientId - OAuth client ID (default: octocode client ID)
231
+ * @returns RefreshResult with success status and error details
232
+ */
233
+ export declare function refreshAuthToken(hostname?: string, clientId?: string): Promise<RefreshResult>;
234
+ /**
235
+ * Result of getting a token with refresh capability
236
+ */
237
+ export interface TokenWithRefreshResult {
238
+ token: string | null;
239
+ source: 'stored' | 'refreshed' | 'none';
240
+ username?: string;
241
+ refreshError?: string;
242
+ }
243
+ /**
244
+ * Get token with automatic refresh for expired tokens
245
+ *
246
+ * This is the recommended function for getting stored tokens. It will:
247
+ * 1. Check if credentials exist
248
+ * 2. If token is expired and has a refresh token, attempt to refresh
249
+ * 3. Return the valid token or null
250
+ *
251
+ * NOTE: This does NOT check environment variables. Use resolveTokenWithRefresh()
252
+ * for full resolution including env vars.
253
+ *
254
+ * @param hostname - GitHub hostname (default: 'github.com')
255
+ * @param clientId - OAuth client ID for refresh (default: octocode client ID)
256
+ * @returns TokenWithRefreshResult with token, source, and any refresh errors
257
+ */
258
+ export declare function getTokenWithRefresh(hostname?: string, clientId?: string): Promise<TokenWithRefreshResult>;
259
+ /**
260
+ * Token resolution result with source tracking
261
+ */
262
+ export interface ResolvedToken {
263
+ token: string;
264
+ source: TokenSource;
265
+ }
266
+ /**
267
+ * Resolve token using the full priority chain
268
+ *
269
+ * Priority order:
270
+ * 1. OCTOCODE_TOKEN env var
271
+ * 2. GH_TOKEN env var
272
+ * 3. GITHUB_TOKEN env var
273
+ * 4. Native keychain (most secure for desktop)
274
+ * 5. Encrypted file storage (~/.octocode/credentials.json)
275
+ *
276
+ * NOTE: This does NOT refresh expired tokens. Use resolveTokenWithRefresh() for auto-refresh.
277
+ *
278
+ * @param hostname - GitHub hostname (default: 'github.com')
279
+ * @returns ResolvedToken with token and source, or null if not found
280
+ */
281
+ export declare function resolveToken(hostname?: string): Promise<ResolvedToken | null>;
282
+ /**
283
+ * Extended resolved token result with refresh support
284
+ */
285
+ export interface ResolvedTokenWithRefresh extends ResolvedToken {
286
+ /** Whether the token was refreshed during resolution */
287
+ wasRefreshed?: boolean;
288
+ /** Username associated with the token (if from storage) */
289
+ username?: string;
290
+ /** Error message if refresh was attempted but failed */
291
+ refreshError?: string;
292
+ }
293
+ /**
294
+ * Resolve token with automatic refresh for expired tokens
295
+ *
296
+ * This is the recommended function for token resolution. It will:
297
+ * 1. Check environment variables first (OCTOCODE_TOKEN, GH_TOKEN, GITHUB_TOKEN)
298
+ * 2. Check stored credentials (keychain → file)
299
+ * 3. If stored token is expired and has a refresh token, attempt to refresh
300
+ * 4. Return the valid token with source information
301
+ *
302
+ * Priority order:
303
+ * 1. OCTOCODE_TOKEN env var
304
+ * 2. GH_TOKEN env var
305
+ * 3. GITHUB_TOKEN env var
306
+ * 4. Stored credentials with auto-refresh (keychain → file)
307
+ *
308
+ * @param hostname - GitHub hostname (default: 'github.com')
309
+ * @param clientId - OAuth client ID for refresh (default: octocode client ID)
310
+ * @returns ResolvedTokenWithRefresh with token, source, and refresh status
311
+ */
312
+ export declare function resolveTokenWithRefresh(hostname?: string, clientId?: string): Promise<ResolvedTokenWithRefresh | null>;
313
+ /**
314
+ * Full token resolution result including gh CLI fallback
315
+ */
316
+ export interface FullTokenResolution {
317
+ /** The resolved token */
318
+ token: string;
319
+ /** Source of the token */
320
+ source: TokenSource | 'gh-cli';
321
+ /** Whether the token was refreshed during resolution */
322
+ wasRefreshed?: boolean;
323
+ /** Username associated with the token (if from storage) */
324
+ username?: string;
325
+ /** Error message if refresh was attempted but failed */
326
+ refreshError?: string;
327
+ }
328
+ /**
329
+ * Callback type for getting gh CLI token
330
+ */
331
+ export type GhCliTokenGetter = (hostname?: string) => string | null | Promise<string | null>;
332
+ /**
333
+ * Full token resolution with gh CLI fallback
334
+ *
335
+ * This is the recommended function for complete token resolution across all sources.
336
+ * Uses in-memory cache (5-minute TTL) for performance, with automatic invalidation
337
+ * on credential updates/refresh.
338
+ *
339
+ * Priority order:
340
+ * 1. OCTOCODE_TOKEN env var
341
+ * 2. GH_TOKEN env var
342
+ * 3. GITHUB_TOKEN env var
343
+ * 4. Octocode storage with auto-refresh (keychain → file, cached)
344
+ * 5. gh CLI token (fallback via callback)
345
+ *
346
+ * @param options - Resolution options
347
+ * @param options.hostname - GitHub hostname (default: 'github.com')
348
+ * @param options.clientId - OAuth client ID for refresh (default: octocode client ID)
349
+ * @param options.getGhCliToken - Callback to get gh CLI token (optional)
350
+ * @returns FullTokenResolution with token, source, and metadata, or null if not found
351
+ */
352
+ export declare function resolveTokenFull(options?: {
353
+ hostname?: string;
354
+ clientId?: string;
355
+ getGhCliToken?: GhCliTokenGetter;
356
+ }): Promise<FullTokenResolution | null>;
357
+ /**
358
+ * Get token synchronously (file storage only)
359
+ *
360
+ * ⚠️ WARNING: This only reads from file storage, not keyring.
361
+ * Use getToken() (async) for the full keyring-first lookup.
362
+ *
363
+ * @param hostname - GitHub hostname (default: 'github.com')
364
+ * @returns Token string or null if not found/expired
365
+ */
366
+ export declare function getTokenSync(hostname?: string): string | null;
367
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/credentials/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,KAAK,EACV,iBAA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4
+ * Shared types for OAuth tokens and credential storage across octocode packages.
5
+ */
6
+ /**
7
+ * OAuth token structure
8
+ */
9
+ export interface OAuthToken {
10
+ token: string;
11
+ tokenType: 'oauth';
12
+ scopes?: string[];
13
+ refreshToken?: string;
14
+ expiresAt?: string;
15
+ refreshTokenExpiresAt?: string;
16
+ }
17
+ /**
18
+ * Stored credentials for a GitHub host
19
+ */
20
+ export interface StoredCredentials {
21
+ hostname: string;
22
+ username: string;
23
+ token: OAuthToken;
24
+ gitProtocol: 'ssh' | 'https';
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ }
28
+ /**
29
+ * Result from storing credentials (keyring-first strategy)
30
+ */
31
+ export interface StoreResult {
32
+ success: boolean;
33
+ /** True if fallback to encrypted file was used (keyring unavailable/failed) */
34
+ insecureStorageUsed: boolean;
35
+ }
36
+ /**
37
+ * Result from deleting credentials
38
+ */
39
+ export interface DeleteResult {
40
+ success: boolean;
41
+ deletedFromKeyring: boolean;
42
+ deletedFromFile: boolean;
43
+ }
44
+ /**
45
+ * Storage interface for credentials (file fallback)
46
+ */
47
+ export interface CredentialsStore {
48
+ version: number;
49
+ credentials: Record<string, StoredCredentials>;
50
+ }
51
+ /**
52
+ * Token source identifier for debugging and display
53
+ *
54
+ * Priority order:
55
+ * 1. Environment variables (OCTOCODE_TOKEN > GH_TOKEN > GITHUB_TOKEN)
56
+ * 2. Native keychain (most secure for desktop)
57
+ * 3. Encrypted file fallback (secure for headless)
58
+ * 4. gh CLI stored token (external fallback)
59
+ */
60
+ export type TokenSource = 'env:OCTOCODE_TOKEN' | 'env:GH_TOKEN' | 'env:GITHUB_TOKEN' | 'keychain' | 'file' | 'gh-cli' | null;
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/credentials/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,UAAU,CAAC;IAClB,WAAW,EAAE,KAAK,GAAG,OAAO,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,+EAA+E;IAC/E,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAChD;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GACnB,oBAAoB,GACpB,cAAc,GACd,kBAAkB,GAClB,UAAU,GACV,MAAM,GACN,QAAQ,GACR,IAAI,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Octocode Shared
3
+ *
4
+ * Shared utilities for Octocode packages:
5
+ * - Credential management with keytar and encrypted file storage
6
+ * - Platform detection utilities
7
+ * - Session persistence
8
+ */
9
+ export * from './credentials/index.js';
10
+ export * from './platform/index.js';
11
+ export * from './session/index.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,wBAAwB,CAAC;AAGvC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import { C, E, K, O, T, H, I, G, _, z, d, y, A, g, w, c, D, f, B, h, j, p, q, F, i, e, v, a, t, b, n, o, x, l, r, m, k, s, u } from "./storage-DuH3rTiu.js";
2
+ import { H as H2, g as g2, e as e2, c as c2, d as d2, b as b2, a as a2, i as i2 } from "./platform-1V_81nPi.js";
3
+ import { S, _ as _2, d as d3, f as f2, b as b3, g as g3, a as a3, e as e3, c as c3, h as h2, i as i3, r as r2, j as j2, u as u2, w as w2 } from "./storage-D-QEqQEn.js";
4
+ export {
5
+ C as CREDENTIALS_FILE,
6
+ E as ENV_TOKEN_VARS,
7
+ H2 as HOME,
8
+ K as KEY_FILE,
9
+ O as OCTOCODE_DIR,
10
+ S as SESSION_FILE,
11
+ T as TimeoutError,
12
+ H as _getCacheStats,
13
+ I as _resetCredentialsCache,
14
+ G as _resetSecureStorageState,
15
+ _2 as _resetSessionState,
16
+ _ as _setSecureStorageAvailable,
17
+ z as decrypt,
18
+ d as deleteCredentials,
19
+ d3 as deleteSession,
20
+ y as encrypt,
21
+ A as ensureOctocodeDir,
22
+ f2 as flushSession,
23
+ b3 as flushSessionSync,
24
+ g2 as getAppDataPath,
25
+ e2 as getArchitecture,
26
+ g as getCredentials,
27
+ w as getCredentialsFilePath,
28
+ c as getCredentialsSync,
29
+ D as getEnvTokenSource,
30
+ c2 as getLocalAppDataPath,
31
+ g3 as getOrCreateSession,
32
+ d2 as getPlatformName,
33
+ a3 as getSessionId,
34
+ f as getToken,
35
+ B as getTokenFromEnv,
36
+ h as getTokenSync,
37
+ j as getTokenWithRefresh,
38
+ p as hasCredentials,
39
+ q as hasCredentialsSync,
40
+ F as hasEnvToken,
41
+ e3 as incrementErrors,
42
+ c3 as incrementPromptCalls,
43
+ h2 as incrementRateLimits,
44
+ i3 as incrementToolCalls,
45
+ i as initializeSecureStorage,
46
+ e as invalidateCredentialsCache,
47
+ b2 as isLinux,
48
+ a2 as isMac,
49
+ v as isRefreshTokenExpired,
50
+ a as isSecureStorageAvailable,
51
+ t as isTokenExpired,
52
+ b as isUsingSecureStorage,
53
+ i2 as isWindows,
54
+ n as listStoredHosts,
55
+ o as listStoredHostsSync,
56
+ x as readCredentialsStore,
57
+ r2 as readSession,
58
+ l as refreshAuthToken,
59
+ j2 as resetSessionStats,
60
+ r as resolveToken,
61
+ m as resolveTokenFull,
62
+ k as resolveTokenWithRefresh,
63
+ s as storeCredentials,
64
+ u2 as updateSessionStats,
65
+ u as updateToken,
66
+ w2 as writeSession
67
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Platform Module Exports
3
+ */
4
+ export { isWindows, isMac, isLinux, HOME, getAppDataPath, getLocalAppDataPath, getPlatformName, getArchitecture, } from './platform.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,SAAS,EACT,KAAK,EACL,OAAO,EACP,IAAI,EACJ,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,eAAe,GAChB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { H, g, e, c, d, b, a, i } from "../platform-1V_81nPi.js";
2
+ export {
3
+ H as HOME,
4
+ g as getAppDataPath,
5
+ e as getArchitecture,
6
+ c as getLocalAppDataPath,
7
+ d as getPlatformName,
8
+ b as isLinux,
9
+ a as isMac,
10
+ i as isWindows
11
+ };