import { z } from 'zod'; import { APIClient, APIResponseSchema } from '@agentuity/api'; import { APIKeyResponseError } from './util.ts'; export const APIKeyDetailSchema = z.object({ id: z.string().describe('the API key id'), name: z.string().describe('the API key name'), orgId: z.string().describe('the organization id'), type: z.string().describe('the API key type'), expiresAt: z.string().datetime().nullable().describe('the expiration date'), lastUsedAt: z.string().datetime().nullable().optional().describe('the last used date'), createdAt: z.string().datetime().describe('the creation date'), project: z .object({ id: z.string().describe('the project id'), name: z.string().describe('the project name'), }) .nullable() .optional() .describe('the associated project'), }); export const APIKeyGetResponseSchema = APIResponseSchema(APIKeyDetailSchema); type APIKeyGetResponse = z.infer; export type APIKeyDetail = z.infer; /** * Get a specific API key by id * * @param client * @param id the API key id * @returns */ export async function apikeyGet(client: APIClient, id: string): Promise { const resp = await client.request( 'GET', `/cli/apikey/${id}`, APIKeyGetResponseSchema ); if (resp.success) { return resp.data; } throw new APIKeyResponseError({ message: resp.message }); }