import {z} from 'zod' export type CreateApiApiV1CertManagerCaInternalCaIdSigningConfigArgs = {caId: string, body: {type: 'internal', parentCaId?: string | undefined} | {type: 'manual'} | {type: 'venafi', appConnectionId: string, destinationConfig: {applicationId: string, issuingTemplateId: string, validityPeriod?: number | undefined}} | {type: 'azure-ad-cs', appConnectionId: string, destinationConfig: {template: string, validityPeriod?: number | undefined}} | {type: 'adcs', appConnectionId: string, destinationConfig: {template: string, caName?: string | undefined}}}; export type CreateApiApiV1CertManagerCaInternalCaIdSigningConfigOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1CertManagerCaInternalCaIdSigningConfigResponse = z.object({id: z.string(), caId: z.string(), type: z.string(), parentCaId: z.string().nullable().optional(), appConnectionId: z.string().nullable().optional(), destinationConfig: z.unknown(), lastExternalCertificateId: z.string().nullable().optional(), createdAt: z.string(), updatedAt: z.string()}); 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 signing configuration for a CA * * POST /api/v1/cert-manager/ca/internal/{caId}/signing-config */ export const createApiApiV1CertManagerCaInternalCaIdSigningConfig = async (args: CreateApiApiV1CertManagerCaInternalCaIdSigningConfigArgs, options?: CreateApiApiV1CertManagerCaInternalCaIdSigningConfigOptions) => { 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/cert-manager/ca/internal/${encodeURIComponent(String(args.caId))}/signing-config${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(createApiApiV1CertManagerCaInternalCaIdSigningConfigResponse, await res.json()) };