import {z} from 'zod' export type GetApiApiV30OrgsOrgUuidApplicationsApplicationUuidScansArgs = {cursor?: string | undefined, limit?: string | undefined, orgUuid: string, applicationUuid: string, checkUfDbStatus?: boolean | undefined}; export type GetApiApiV30OrgsOrgUuidApplicationsApplicationUuidScansOptions = {baseUrl?: string | undefined, bearerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const scanTagDTO = z.object({key: z.string().optional(), value: z.string().optional(), displayName: z.string().optional(), createdAt: z.string().optional()}); export const scanSummaryDTOV3 = z.object({uuid: z.string().optional(), name: z.string().optional(), processUuid: z.string().optional(), scanTime: z.string().optional(), scanStatus: z.string().optional(), engine: z.enum(["UNIFIED", "SCA", "SAST", "IAC", "IMG", "AI", "DAST"]).optional(), scanMode: z.enum(["baseline", "preview"]).optional(), scanDuration: z.string().optional(), configurationName: z.string().optional(), reference: z.string().optional(), triggeredBy: z.string().optional(), agentName: z.string().optional(), agentVersion: z.string().optional(), supportToken: z.string().optional(), projectName: z.string().optional(), projectUuid: z.string().optional(), tags: z.array(scanTagDTO).optional(), applicationName: z.string().optional(), applicationUuid: z.string().optional(), workflowUuids: z.array(z.string()).optional(), workflowNames: z.array(z.string()).optional(), statistics: z.record(z.string(), z.record(z.string(), z.number().int())).optional()}); export const dWRResponsePageableV3ListScanSummaryDTOV3 = z.object({additionalData: z.object({}).optional(), supportToken: z.string().optional(), response: z.array(scanSummaryDTOV3).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 }; /** * Get Application Scans * * GET /api/v3.0/orgs/{orgUuid}/applications/{applicationUuid}/scans */ export const getApiApiV30OrgsOrgUuidApplicationsApplicationUuidScans = async (args: GetApiApiV30OrgsOrgUuidApplicationsApplicationUuidScansArgs, options?: GetApiApiV30OrgsOrgUuidApplicationsApplicationUuidScansOptions) => { const {baseUrl = "https://baseUrl", fetch: fetchFn = fetch, bearerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.checkUfDbStatus != null) query.append("checkUfDbStatus", String(args.checkUfDbStatus)) if (bearerKey !== undefined) headers.set('authorization', `Bearer ${bearerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3.0/orgs/${encodeURIComponent(String(args.orgUuid))}/applications/${encodeURIComponent(String(args.applicationUuid))}/scans${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dWRResponsePageableV3ListScanSummaryDTOV3, await res.json()) };