import { apiClient } from '../client'; import { ApiKey, CreateApiKey, UpdateApiKey } from '../schemas/api-keys'; // Commented out as it's not used // const mockApiKeys: ApiKey[] = [ // { // id: '1', // name: 'Production API Key', // key: 'sk_prod_' + crypto.randomBytes(16).toString('hex'), // user_id: '1', // organization_id: '1', // is_active: true, // created_at: new Date('2023-01-01').toISOString(), // }, // { // id: '2', // name: 'Development API Key', // key: 'sk_dev_' + crypto.randomBytes(16).toString('hex'), // user_id: '2', // organization_id: '1', // is_active: true, // created_at: new Date('2023-02-15').toISOString(), // }, // { // id: '3', // name: 'Testing API Key', // key: 'sk_test_' + crypto.randomBytes(16).toString('hex'), // user_id: '3', // organization_id: '1', // is_active: false, // created_at: new Date('2023-03-10').toISOString(), // }, // ]; export class ApiKeyService { static async listApiKeys(organizationId?: string): Promise { try { const params: Record = {}; if (organizationId) { params.organization_id = organizationId; } return await apiClient.get('/api/api-keys', params); } catch (error) { console.error('Error fetching API keys:', error); throw error; } } static async getApiKey(id: string): Promise { try { return await apiClient.get(`/api/api-keys/${id}`); } catch (error) { console.error(`Error fetching API key ${id}:`, error); throw error; } } static async createApiKey(data: CreateApiKey): Promise { try { return await apiClient.post( '/api/api-keys', data as Record ); } catch (error) { console.error('Error creating API key:', error); throw error; } } static async updateApiKey(id: string, data: UpdateApiKey): Promise { try { return await apiClient.put( `/api/api-keys/${id}`, data as Record ); } catch (error) { console.error(`Error updating API key ${id}:`, error); throw error; } } static async deleteApiKey(id: string): Promise { try { await apiClient.delete(`/api/api-keys/${id}`); } catch (error) { console.error(`Error deleting API key ${id}:`, error); throw error; } } }