summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src/credentials/api-keys.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-04 21:21:20 +0900
committerAdam Malczewski <[email protected]>2026-06-04 21:21:20 +0900
commit394f1ed37ce860da6fdc385769bf29f9737105cd (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /packages/core/src/credentials/api-keys.ts
parent81a9cdbadf8c9d940d4fe9a2a0de607dee1f5f1a (diff)
downloaddispatch-394f1ed37ce860da6fdc385769bf29f9737105cd.tar.gz
dispatch-394f1ed37ce860da6fdc385769bf29f9737105cd.zip
chore: genesis — remove all files to rebuild from scratch (arch rewrite)
Diffstat (limited to 'packages/core/src/credentials/api-keys.ts')
-rw-r--r--packages/core/src/credentials/api-keys.ts80
1 files changed, 0 insertions, 80 deletions
diff --git a/packages/core/src/credentials/api-keys.ts b/packages/core/src/credentials/api-keys.ts
deleted file mode 100644
index ef30400..0000000
--- a/packages/core/src/credentials/api-keys.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import { getDatabase } from "../db/index.js";
-
-export interface StoredApiKey {
- keyId: string;
- provider: string;
- apiKey: string;
- importedAt: number;
- updatedAt: number;
-}
-
-/**
- * Store or update an API key in the database.
- */
-export function setApiKey(keyId: string, provider: string, apiKey: string): void {
- const db = getDatabase();
- const now = Date.now();
- db.query(
- `INSERT INTO api_keys (key_id, provider, api_key, imported_at, updated_at)
- VALUES ($keyId, $provider, $apiKey, $now, $now)
- ON CONFLICT(key_id) DO UPDATE SET
- api_key = $apiKey,
- updated_at = $now`,
- ).run({
- $keyId: keyId,
- $provider: provider,
- $apiKey: apiKey,
- $now: now,
- });
-}
-
-/**
- * Get a stored API key by key ID. Returns the key string or null.
- */
-export function getApiKey(keyId: string): string | null {
- const db = getDatabase();
- const row = db
- .query("SELECT api_key FROM api_keys WHERE key_id = $keyId")
- .get({ $keyId: keyId }) as { api_key: string } | null;
- return row?.api_key ?? null;
-}
-
-/**
- * Resolve an API key from the database, with env var fallback.
- * Pass the env var name (e.g. "GOOGLE_API_KEY") to check process.env as well.
- */
-export function resolveApiKey(keyId: string, envVar?: string): string | null {
- const dbKey = getApiKey(keyId);
- if (dbKey) return dbKey;
- if (envVar) return process.env[envVar] ?? null;
- return null;
-}
-
-/**
- * Delete a stored API key.
- */
-export function deleteApiKey(keyId: string): void {
- const db = getDatabase();
- db.query("DELETE FROM api_keys WHERE key_id = $keyId").run({ $keyId: keyId });
-}
-
-/**
- * List all stored API keys with metadata (key value excluded for security).
- */
-export function listApiKeys(): Array<{
- keyId: string;
- provider: string;
- importedAt: number;
- updatedAt: number;
-}> {
- const db = getDatabase();
- const rows = db
- .query("SELECT key_id, provider, imported_at, updated_at FROM api_keys ORDER BY key_id")
- .all() as Array<Record<string, unknown>>;
- return rows.map((row) => ({
- keyId: row.key_id as string,
- provider: row.provider as string,
- importedAt: row.imported_at as number,
- updatedAt: row.updated_at as number,
- }));
-}