import {z} from 'zod' export type EnumerationLaunchConfig = {'follow-redirect'?: boolean | undefined, ports?: string | undefined}; export type EnumerationConfig = {name?: string | undefined, root_domains?: Array | undefined, enrichment_inputs?: Array | undefined, steps?: (Array<'dns_resolve' | 'dns_bruteforce' | 'dns_permute' | 'port_scan' | 'http_probe' | 'http_screenshot' | 'endpoint_crawling' | 'dns_passive' | 'tls_scan' | 'uncover_assets' | 'dns_scraping'>) | undefined, enum_ports?: string | undefined, enumeration_config?: EnumerationLaunchConfig | undefined, alerting_config_ids?: Array | undefined, subfinder_config_ids?: Array | undefined, exclusions?: Array | undefined, automatic_vuln_scans?: boolean | undefined}; export type PatchApiV1AssetEnumerateEnumerateIdConfigArgs = {update_type?: ('append' | 'replace') | undefined, 'X-Team-Id'?: string | undefined, body: EnumerationConfig}; export type PatchApiV1AssetEnumerateEnumerateIdConfigOptions = {baseUrl?: string | undefined, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV1AssetEnumerateEnumerateIdConfigResponse = z.object({message: 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 }; /** * Update enumeration config * * PATCH /v1/asset/enumerate/{enumerate_id}/config */ export const patchApiV1AssetEnumerateEnumerateIdConfig = async (args: PatchApiV1AssetEnumerateEnumerateIdConfigArgs, options?: PatchApiV1AssetEnumerateEnumerateIdConfigOptions) => { 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/asset/enumerate/${encodeURIComponent(String(args.enumerate_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(patchApiV1AssetEnumerateEnumerateIdConfigResponse, await res.json()) };