import {z} from 'zod' export type CreateApiApiV1PkiSyncsImpervaArgs = {body: {name: string, description?: string | undefined, isAutoSyncEnabled?: boolean | undefined, destinationConfig: {siteId: string, siteName?: string | undefined}, syncOptions: {canRemoveCertificates?: boolean | undefined, includeRootCa?: boolean | undefined}, subscriberId?: (string | null) | undefined, connectionId: string, applicationId?: string | undefined, certificateIds?: Array | undefined, filters?: ({profileIds?: Array | undefined, certificateOrderIds?: Array | undefined, metadata?: (Array<{key: string, value?: string | undefined}>) | undefined} | null) | undefined}}; export type CreateApiApiV1PkiSyncsImpervaOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1PkiSyncsImpervaResponse = z.object({id: z.string(), name: z.string().max(256), description: z.string().nullable().optional(), destination: z.literal("imperva"), isAutoSyncEnabled: z.boolean(), destinationConfig: z.object({siteId: z.string().min(1).max(20), siteName: z.string().max(512).optional()}), syncOptions: z.object({canRemoveCertificates: z.boolean().optional(), includeRootCa: z.boolean().optional()}), projectId: z.string(), subscriberId: z.string().nullable().optional(), connectionId: z.string(), createdAt: z.string(), updatedAt: z.string(), syncStatus: z.string().nullable().optional(), lastSyncedAt: z.string().nullable().optional(), lastHealthCheckRanAt: z.string().nullable().optional(), lastHealthCheckStatus: z.enum(["pending", "running", "succeeded", "failed"]).nullable().optional(), lastHealthCheckMessage: z.string().nullable().optional(), filters: z.object({profileIds: z.array(z.string()).optional(), certificateOrderIds: z.array(z.string()).optional(), metadata: z.array(z.object({key: z.string(), value: z.string().optional()})).optional()}).nullable().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 Imperva PKI Sync. * * POST /api/v1/pki/syncs/imperva */ export const createApiApiV1PkiSyncsImperva = async (args: CreateApiApiV1PkiSyncsImpervaArgs, options?: CreateApiApiV1PkiSyncsImpervaOptions) => { 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/pki/syncs/imperva${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(createApiApiV1PkiSyncsImpervaResponse, await res.json()) };