import {z} from 'zod' export type CreateApiApiV1CertManagerDiscoveryJobsArgs = {body: {name: string, description?: string | undefined, discoveryType?: ('network' | 'linux-server' | 'windows-server') | undefined, targetConfig: {ipRanges?: Array | undefined, domains?: Array | undefined, ports?: string | undefined, connectionIds?: Array | undefined, searchFolderPaths?: Array | undefined, skipFolderPaths?: Array | undefined, maxFolderDepth?: number | undefined, maxFileSizeKb?: number | undefined, importStandaloneCaCertificates?: boolean | undefined, certificateStores?: (Array<'My' | 'WebHosting' | 'Remote Desktop' | 'CA' | 'Root'>) | undefined}, isAutoScanEnabled?: boolean | undefined, scanIntervalDays?: number | undefined, gatewayId?: string | undefined, gatewayPoolId?: string | undefined}}; export type CreateApiApiV1CertManagerDiscoveryJobsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1CertManagerDiscoveryJobsResponse = z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), discoveryType: z.string().optional(), targetConfig: z.unknown(), isAutoScanEnabled: z.boolean().optional(), scanIntervalDays: z.number().nullable().optional(), gatewayId: z.string().nullable().optional(), isActive: z.boolean().optional(), lastScanStatus: z.string().nullable().optional(), lastScanJobId: z.string().nullable().optional(), lastScanMessage: z.string().nullable().optional(), lastScannedAt: z.string().nullable().optional(), createdAt: z.string(), updatedAt: z.string(), gatewayPoolId: z.string().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 new PKI discovery configuration * * POST /api/v1/cert-manager/discovery-jobs */ export const createApiApiV1CertManagerDiscoveryJobs = async (args: CreateApiApiV1CertManagerDiscoveryJobsArgs, options?: CreateApiApiV1CertManagerDiscoveryJobsOptions) => { 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/discovery-jobs${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(createApiApiV1CertManagerDiscoveryJobsResponse, await res.json()) };