import {z} from 'zod' export type GetApiV0ApiKeysApiKeyIdArgs = {'api-key-id': string}; export type GetApiV0ApiKeysApiKeyIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0ApiKeysApiKeyIdResponse = z.object({"api-key-url": z.union([z.string(), z.string()]), "api-key-name": z.string().min(1).max(64), "api-key-live?": z.boolean(), "organization-url": z.string(), "user-url": z.string(), "created-at": z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get API key * * GET /v0/api-keys/{api-key-id} */ export const getApiV0ApiKeysApiKeyId = async (args: GetApiV0ApiKeysApiKeyIdArgs, options?: GetApiV0ApiKeysApiKeyIdOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/api-keys/${encodeURIComponent(String(args['api-key-id']))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV0ApiKeysApiKeyIdResponse, await res.json()) };