mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-02 02:38:38 +00:00
- Implemented githubTokensDb for managing GitHub tokens with CRUD operations. - Created otificationPreferencesDb to handle user notification preferences. - Added projectsDb for project path management and related operations. - Introduced pushSubscriptionsDb for managing browser push subscriptions. - Developed scanStateDb to track the last scanned timestamp. - Established sessionsDb for session management with CRUD functionalities. - Created userDb for user management, including authentication and onboarding. - Implemented apidKeysDb for storing and managing VAPID keys. feat(database): define schema for new database tables - Added SQL schema definitions for users, API keys, user credentials, notification preferences, VAPID keys, push subscriptions, projects, sessions, scan state, and app configuration. - Included necessary indexes for performance optimization. refactor(shared): enhance type definitions and utility functions - Updated shared types and interfaces for improved clarity and consistency. - Added new types for credential management and provider-specific operations. - Refined utility functions for better error handling and message normalization.
101 lines
2.7 KiB
TypeScript
101 lines
2.7 KiB
TypeScript
/**
|
|
* GitHub tokens repository.
|
|
*
|
|
* Backward-compatible helper layer over generic credentials storage.
|
|
* Tokens are stored in `user_credentials` with `credential_type = 'github_token'`.
|
|
*/
|
|
|
|
import { getConnection } from '@/modules/database/connection.js';
|
|
import { credentialsDb } from '@/modules/database/repositories/credentials.js';
|
|
import type {
|
|
CredentialPublicRow,
|
|
CreateCredentialResult,
|
|
} from '@/shared/types.js';
|
|
|
|
const GITHUB_TOKEN_TYPE = 'github_token';
|
|
|
|
type CredentialRow = {
|
|
id: number;
|
|
user_id: number;
|
|
credential_name: string;
|
|
credential_type: string;
|
|
credential_value: string;
|
|
description: string | null;
|
|
created_at: string;
|
|
is_active: number;
|
|
};
|
|
|
|
type GithubTokenLookup = CredentialRow & {
|
|
github_token: string;
|
|
};
|
|
|
|
export const githubTokensDb = {
|
|
/** Creates a GitHub token credential entry. */
|
|
createGithubToken(
|
|
userId: number,
|
|
tokenName: string,
|
|
githubToken: string,
|
|
description: string | null = null
|
|
): CreateCredentialResult {
|
|
return credentialsDb.createCredential(
|
|
userId,
|
|
tokenName,
|
|
GITHUB_TOKEN_TYPE,
|
|
githubToken,
|
|
description
|
|
);
|
|
},
|
|
|
|
/** Returns all GitHub tokens (safe shape: no credential value). */
|
|
getGithubTokens(userId: number): CredentialPublicRow[] {
|
|
return credentialsDb.getCredentials(userId, GITHUB_TOKEN_TYPE);
|
|
},
|
|
|
|
/** Returns the most recent active GitHub token value for a user. */
|
|
getActiveGithubToken(userId: number): string | null {
|
|
return credentialsDb.getActiveCredential(userId, GITHUB_TOKEN_TYPE);
|
|
},
|
|
|
|
/**
|
|
* Returns a specific active GitHub token row by id/user, including
|
|
* a `github_token` compatibility field.
|
|
*/
|
|
getGithubTokenById(userId: number, tokenId: number): GithubTokenLookup | null {
|
|
const db = getConnection();
|
|
const row = db
|
|
.prepare(
|
|
`SELECT *
|
|
FROM user_credentials
|
|
WHERE id = ? AND user_id = ? AND credential_type = ? AND is_active = 1`
|
|
)
|
|
.get(tokenId, userId, GITHUB_TOKEN_TYPE) as CredentialRow | undefined;
|
|
|
|
if (!row) return null;
|
|
|
|
return {
|
|
...row,
|
|
github_token: row.credential_value,
|
|
};
|
|
},
|
|
|
|
/** Updates active state for a GitHub token. */
|
|
updateGithubToken(
|
|
userId: number,
|
|
tokenId: number,
|
|
isActive: boolean
|
|
): boolean {
|
|
return credentialsDb.toggleCredential(userId, tokenId, isActive);
|
|
},
|
|
|
|
/** Deletes a GitHub token. */
|
|
deleteGithubToken(userId: number, tokenId: number): boolean {
|
|
return credentialsDb.deleteCredential(userId, tokenId);
|
|
},
|
|
|
|
// Legacy alias used by existing routes
|
|
toggleGithubToken(userId: number, tokenId: number, isActive: boolean): boolean {
|
|
return githubTokensDb.updateGithubToken(userId, tokenId, isActive);
|
|
},
|
|
};
|
|
|