import {z} from 'zod' export type GetApiApiV1AppConnectionsClickhouseArgs = {projectId?: string | undefined}; export type GetApiApiV1AppConnectionsClickhouseOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AppConnectionsClickhouseResponse = z.object({appConnections: z.array(z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), version: z.number().optional(), orgId: z.string(), createdAt: z.string(), updatedAt: z.string(), isPlatformManagedCredentials: z.boolean().nullable().optional(), gatewayId: z.string().nullable().optional(), projectId: z.string().nullable().optional(), isAutoRotationEnabled: z.boolean().optional(), gatewayPoolId: z.string().nullable().optional(), rotation: z.object({lastRotationMessage: z.string().nullable().optional(), rotationInterval: z.number(), nextRotationAt: z.string().nullable().optional(), rotationStatus: z.enum(["success", "failed"]), rotateAtUtc: z.object({hours: z.number(), minutes: z.number()})}).optional(), credentialsHash: z.string().optional(), project: z.object({name: z.string(), id: z.string(), type: z.string(), slug: z.string()}).nullable().optional(), app: z.literal("clickhouse"), method: z.literal("username-and-password"), credentials: z.object({host: z.string().min(1).max(255), database: z.string().min(1).max(255), port: z.number().int().gte(1).lte(65535), username: z.string().min(1).max(256), sslEnabled: z.boolean(), sslRejectUnauthorized: z.boolean(), sslCertificate: z.string().max(10240).optional()})}))}); 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 the ClickHouse Connections for the current organization or project. * * GET /api/v1/app-connections/clickhouse */ export const getApiApiV1AppConnectionsClickhouse = async (args: GetApiApiV1AppConnectionsClickhouseArgs, options?: GetApiApiV1AppConnectionsClickhouseOptions) => { const {baseUrl = "https://us.infisical.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/app-connections/clickhouse${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(getApiApiV1AppConnectionsClickhouseResponse, await res.json()) };