import {z} from 'zod' export type GetApiVaultsIdColumnsArgs = {id: string}; export type GetApiVaultsIdColumnsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const vaultColumnResponse = z.object({id: z.string().nullable(), field_key: z.string(), label: z.string(), instructions: z.string(), field_type: z.enum(["text", "date", "date_range", "enum", "multi_enum", "boolean", "number", "currency", "percentage", "duration", "email", "url", "list", "rich_text", "party_list", "related_agreement_list"]), field_meta: z.union([z.object({type: z.literal("enum"), options: z.array(z.string().min(1).max(200)), legacy_options: z.array(z.string().min(1).max(200)).optional()}), z.object({type: z.literal("multi_enum"), options: z.array(z.string().min(1).max(200))}), z.unknown()]), extraction_mode: z.enum(["ai", "manual", "import", "connector"]), kind: z.enum(["built_in", "system", "custom"]), editable: z.boolean(), sort_order: z.number().nullable(), created_at: z.string().nullable(), updated_at: z.string().nullable()}); export const vaultColumnListResponse = z.object({columns: z.array(vaultColumnResponse)}); 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 }; /** * List a vault's columns * * GET /vaults/{id}/columns */ export const getApiVaultsIdColumns = async (args: GetApiVaultsIdColumnsArgs, options?: GetApiVaultsIdColumnsOptions) => { const {baseUrl = "https://app.gc.ai/api/external/v1", 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(/\/+$/, '')}/vaults/${encodeURIComponent(String(args.id))}/columns${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(vaultColumnListResponse, await res.json()) };