import {z} from 'zod' export type GetApiV1AssetEnumerateMisconfigurationArgs = {'X-Team-Id'?: string | undefined, limit?: number | undefined, offset?: number | undefined, search?: string | undefined, finding_type?: ('dangling_dns' | 'origin_exposure') | undefined}; export type GetApiV1AssetEnumerateMisconfigurationOptions = {baseUrl?: string | undefined, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const misconfigurationResponse = z.object({id: z.string().optional(), enumeration_id: z.string().optional(), finding_type: z.enum(["dangling_dns", "origin_exposure"]).optional(), host: z.string().optional(), severity: z.enum(["critical", "high", "medium", "low", "info", "unknown"]).optional(), status: z.enum(["open", "fixed", "false_positive", "duplicate", "fix_in_progress", "accepted_risk", "triaged", "out_of_scope"]).optional(), event: z.record(z.string(), z.unknown()).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const getApiV1AssetEnumerateMisconfigurationResponse = z.object({message: z.string().optional(), total_pages: z.number().int().optional(), total_results: z.number().int().optional(), current_page: z.number().int().optional(), data: z.array(misconfigurationResponse).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 }; /** * List Misconfiguration Findings * * GET /v1/asset/enumerate/misconfiguration */ export const getApiV1AssetEnumerateMisconfiguration = async (args: GetApiV1AssetEnumerateMisconfigurationArgs, options?: GetApiV1AssetEnumerateMisconfigurationOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.search != null) query.append("search", String(args.search)) if (args.finding_type != null) query.append("finding_type", String(args.finding_type)) if (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/asset/enumerate/misconfiguration${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(getApiV1AssetEnumerateMisconfigurationResponse, await res.json()) };