import {z} from 'zod' export type CreateApiApiV1AppConnectionsClickhouseArgs = {body: {method: 'username-and-password', credentials: {host: string, port: number, database: string, username: string, password: string, sslEnabled: boolean, sslRejectUnauthorized: boolean, sslCertificate?: string | undefined}, name: string, description?: (string | null) | undefined, projectId?: string | undefined, isPlatformManagedCredentials?: false | undefined, gatewayId?: (string | null) | undefined, gatewayPoolId?: (string | null) | undefined, isAutoRotationEnabled?: false | undefined, rotation?: ('null' | null) | undefined}}; export type CreateApiApiV1AppConnectionsClickhouseOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1AppConnectionsClickhouseResponse = z.object({appConnection: 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 }; /** * Create a ClickHouse Connection. * * POST /api/v1/app-connections/clickhouse */ export const createApiApiV1AppConnectionsClickhouse = async (args: CreateApiApiV1AppConnectionsClickhouseArgs, options?: CreateApiApiV1AppConnectionsClickhouseOptions) => { const {baseUrl = "https://us.infisical.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/app-connections/clickhouse${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1AppConnectionsClickhouseResponse, await res.json()) };