import {z} from 'zod' export type EnumerationIDTypes = {id: string}; export type TimeRangeQueryParameter = 'last_day' | 'last_week' | 'last_month' | 'last_3_months' | 'last_6_months' | 'last_12_months' | 'all_time'; export type AssetFilters = {is_tech?: boolean | undefined, is_favicon?: boolean | undefined, is_new?: boolean | undefined, labels?: string | undefined, host?: string | undefined, port?: string | undefined, status_code?: string | undefined, content_length?: string | undefined, title?: string | undefined, domain?: Array | undefined, cname?: string | undefined, technologies?: string | undefined, ip?: string | undefined, is_screenshot?: boolean | undefined, time?: TimeRangeQueryParameter | undefined, start_date?: string | undefined, end_date?: string | undefined, custom_filter?: string | undefined, search?: string | undefined, enumeration_ids?: Array | undefined, only_dns?: boolean | undefined, only_ip?: boolean | undefined, not_seen_for_days?: number | undefined}; export type ScanConfigUpdateItem = {targets?: Array | undefined, assets_lists?: Array | undefined, templates?: Array | undefined, early_templates?: Array | undefined, scan_config_ids?: Array | undefined, report_config_ids?: Array | undefined, alerting_config_ids?: Array | undefined, enumeration_ids?: Array | undefined, agent_id?: string | undefined, agent_tags?: Array | undefined, agent_networks?: Array | undefined, agent_behavior?: ('distribute' | 'mirror') | undefined, scan_all_assets?: boolean | undefined, asset_filters?: AssetFilters | undefined}; export type PatchApiV1ScansScanIdConfigArgs = {update_type?: ('append' | 'replace') | undefined, 'X-Team-Id'?: string | undefined, body: ScanConfigUpdateItem}; export type PatchApiV1ScansScanIdConfigOptions = {baseUrl?: string | undefined, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV1ScansScanIdConfigResponse = z.object({ok: z.boolean().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 }; /** * Update Scan Config * * PATCH /v1/scans/{scan_id}/config */ export const patchApiV1ScansScanIdConfig = async (args: PatchApiV1ScansScanIdConfigArgs, options?: PatchApiV1ScansScanIdConfigOptions) => { const {baseUrl = "https://api.projectdiscovery.io", fetch: fetchFn = fetch, XAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.update_type != null) query.append("update_type", String(args.update_type)) if (args['X-Team-Id'] != null) headers.set("X-Team-Id", String(args['X-Team-Id'])) if (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/scans/${encodeURIComponent(String(args.scan_id))}/config${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV1ScansScanIdConfigResponse, await res.json()) };