import {z} from 'zod' export type LogExportFormat = 'raw' | 'json' | 'csv'; export type GetApiV1ScansScanIdScanLogExportArgs = {'X-Team-Id'?: string | undefined, rescan_count?: number | undefined, host?: string | undefined, template?: string | undefined, matched?: string | undefined, time?: string | undefined, search?: string | undefined, error?: string | undefined, format?: LogExportFormat | undefined, async?: boolean | undefined, alert_email?: string | undefined, severity?: ('error' | 'info' | 'all_logs') | undefined}; export type GetApiV1ScansScanIdScanLogExportOptions = {baseUrl?: string | undefined, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ScansScanIdScanLogExportResponse = z.object({url: 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 }; /** * Export scan log of given scan id * * GET /v1/scans/{scan_id}/scan_log/export */ export const getApiV1ScansScanIdScanLogExport = async (args: GetApiV1ScansScanIdScanLogExportArgs, options?: GetApiV1ScansScanIdScanLogExportOptions) => { const {baseUrl = "https://api.projectdiscovery.io", fetch: fetchFn = fetch, XAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Team-Id'] != null) headers.set("X-Team-Id", String(args['X-Team-Id'])) if (args.rescan_count != null) query.append("rescan_count", String(args.rescan_count)) if (args.host != null) query.append("host", String(args.host)) if (args.template != null) query.append("template", String(args.template)) if (args.matched != null) query.append("matched", String(args.matched)) if (args.time != null) query.append("time", String(args.time)) if (args.search != null) query.append("search", String(args.search)) if (args.error != null) query.append("error", String(args.error)) if (args.format != null) query.append("format", String(args.format)) if (args.async != null) query.append("async", String(args.async)) if (args.alert_email != null) query.append("alert_email", String(args.alert_email)) if (args.severity != null) query.append("severity", String(args.severity)) if (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/scans/${encodeURIComponent(String(args.scan_id))}/scan_log/export${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(getApiV1ScansScanIdScanLogExportResponse, await res.json()) };