import {z} from 'zod' export type GetApiV1ProjectsProjectKeyArgs = {project_key: string}; export type GetApiV1ProjectsProjectKeyOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dateTime = z.string(); export const nullableDateTime = z.string(); export const connectionType = z.union([z.literal("athena"), z.literal("bigquery"), z.literal("clickhouse"), z.literal("databricks"), z.literal("mcp"), z.literal("mssql"), z.literal("mysql"), z.literal("postgresql"), z.literal("redshift"), z.literal("snowflake"), z.literal("synapse"), z.literal("googlesheets")]); export const project = z.object({key: z.string(), name: z.string(), created_at: dateTime, description: z.string(), modified_at: nullableDateTime, permitted_actions: z.object({create_canvas: z.boolean(), run_query: z.boolean()}), permissions: z.array(z.object({key: z.string(), role: z.union([z.literal("admin"), z.literal("analyst"), z.literal("editor"), z.literal("viewer"), z.literal("presentation_viewer")]), type: z.union([z.literal("user"), z.literal("group"), z.literal("service_account"), z.literal("workspace")])})), sources: z.array(z.object({type: z.union([z.literal("connection"), z.literal("catalog")]), source_key: z.string(), source_name: z.string(), connection_type: connectionType.optional(), datasets: z.array(z.string()).optional()})), agent_context: z.string().optional()}); export const getApiV1ProjectsProjectKeyResponse = z.object({success: z.literal(true), request_id: z.string(), result: project}); 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 a project * * GET /v1/projects/:project_key */ export const getApiV1ProjectsProjectKey = async (args: GetApiV1ProjectsProjectKeyArgs, options?: GetApiV1ProjectsProjectKeyOptions) => { const {baseUrl = "https://api.app.count.co/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/:project_key${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(getApiV1ProjectsProjectKeyResponse, await res.json()) };