import {z} from 'zod' export type CreateApiApiV2SecretRotationsClickhouseCredentialsArgs = {body: {name: string, projectId: string, description?: (string | null) | undefined, connectionId: string, environment: string, secretPath: string, isAutoRotationEnabled?: boolean | undefined, rotationInterval: number, rotateAtUtc?: {hours: number, minutes: number} | undefined, parameters: {username1: string, username2: string}, secretsMapping: {username: string, password: string}}}; export type CreateApiApiV2SecretRotationsClickhouseCredentialsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV2SecretRotationsClickhouseCredentialsResponse = z.object({secretRotation: z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), isAutoRotationEnabled: z.boolean().optional(), activeIndex: z.number().optional(), folderId: z.string(), connectionId: z.string(), createdAt: z.string(), updatedAt: z.string(), rotationInterval: z.number(), rotationStatus: z.string(), lastRotationAttemptedAt: z.string(), lastRotatedAt: z.string(), lastRotationJobId: z.string().nullable().optional(), nextRotationAt: z.string().nullable().optional(), isLastRotationManual: z.boolean().optional(), connection: z.object({app: z.literal("clickhouse"), name: z.string(), id: z.string()}), environment: z.object({slug: z.string(), name: z.string(), id: z.string()}), projectId: z.string(), folder: z.object({id: z.string(), path: z.string()}), rotateAtUtc: z.object({hours: z.number().gte(0).lte(23), minutes: z.number().gte(0).lte(59)}), lastRotationMessage: z.string().nullable().optional(), type: z.literal("clickhouse-credentials"), parameters: z.object({username1: z.string().min(1).max(256), username2: z.string().min(1).max(256)}), secretsMapping: z.object({username: z.string().min(1), password: z.string().min(1)})})}); 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 Credentials Rotation for the specified project. * * POST /api/v2/secret-rotations/clickhouse-credentials */ export const createApiApiV2SecretRotationsClickhouseCredentials = async (args: CreateApiApiV2SecretRotationsClickhouseCredentialsArgs, options?: CreateApiApiV2SecretRotationsClickhouseCredentialsOptions) => { 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/v2/secret-rotations/clickhouse-credentials${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(createApiApiV2SecretRotationsClickhouseCredentialsResponse, await res.json()) };