import {z} from 'zod' export type DeleteApiApiV2SecretRotationsMongodbCredentialsRotationIdArgs = {deleteSecrets?: ('true' | 'false') | undefined, revokeGeneratedCredentials?: ('true' | 'false') | undefined, rotationId: string}; export type DeleteApiApiV2SecretRotationsMongodbCredentialsRotationIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteApiApiV2SecretRotationsMongodbCredentialsRotationIdResponse = 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("mongodb"), 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("mongodb-credentials"), parameters: z.object({username1: z.string().min(1), username2: z.string().min(1)}), 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 }; /** * Delete the specified MongoDB Credentials Rotation. * * DELETE /api/v2/secret-rotations/mongodb-credentials/{rotationId} */ export const deleteApiApiV2SecretRotationsMongodbCredentialsRotationId = async (args: DeleteApiApiV2SecretRotationsMongodbCredentialsRotationIdArgs, options?: DeleteApiApiV2SecretRotationsMongodbCredentialsRotationIdOptions) => { 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.deleteSecrets != null) query.append("deleteSecrets", String(args.deleteSecrets)) if (args.revokeGeneratedCredentials != null) query.append("revokeGeneratedCredentials", String(args.revokeGeneratedCredentials)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/secret-rotations/mongodb-credentials/${encodeURIComponent(String(args.rotationId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteApiApiV2SecretRotationsMongodbCredentialsRotationIdResponse, await res.json()) };