import {z} from 'zod' export type Address = {ip?: string | undefined, mac?: string | undefined}; export type Configuration = {name: string, value?: string | undefined}; export type Database = {description?: string | undefined, id?: number | undefined, name: string}; export type File = {attributes?: Array | undefined, name: string, size?: number | undefined, type: 'file' | 'directory'}; export type AssetHistory = {date?: string | undefined, description?: string | undefined, scanId?: Record | undefined, type?: string | undefined, user?: string | undefined, version?: number | undefined, vulnerabilityExceptionId?: Record | undefined}; export type HostName = {name: string, source?: ('user' | 'dns' | 'netbios' | 'dce' | 'epsec' | 'ldap' | 'other') | undefined}; export type UniqueId = {id: string, source?: string | undefined}; export type Link = {deprecation?: string | undefined, href?: string | undefined, hreflang?: string | undefined, media?: string | undefined, rel?: string | undefined, title?: string | undefined, type?: string | undefined}; export type OperatingSystemCpe = {edition?: string | undefined, language?: string | undefined, other?: string | undefined, part: 'o' | 'a' | 'h', product?: string | undefined, swEdition?: string | undefined, targetHW?: string | undefined, targetSW?: string | undefined, update?: string | undefined, 'v2.2'?: string | undefined, 'v2.3'?: string | undefined, vendor?: string | undefined, version?: string | undefined}; export type OperatingSystem = {architecture?: string | undefined, configurations?: Array | undefined, cpe?: OperatingSystemCpe | undefined, description?: string | undefined, family?: string | undefined, id?: number | undefined, product?: string | undefined, systemName?: string | undefined, type?: string | undefined, vendor?: string | undefined, version?: string | undefined}; export type GroupAccount = {id?: number | undefined, name: string}; export type UserAccount = {fullName?: string | undefined, id?: number | undefined, name?: string | undefined}; export type WebPage = {linkType?: ('seed' | 'html-ref' | 'robots' | 'js-string' | 'query-param' | 'pdf' | 'css' | 'implied-dir' | 'rss' | 'redirection' | 'sitemap' | 'backup' | 'vck-rewrite' | 'non-ref-guess' | 'soft-404') | undefined, path?: string | undefined, response?: number | undefined}; export type WebApplication = {id?: number | undefined, pages?: Array | undefined, root?: string | undefined, virtualHost?: string | undefined}; export type Service = {configurations?: Array | undefined, databases?: Array | undefined, family?: string | undefined, links: Array, name?: string | undefined, nic?: string | undefined, port: number, product?: string | undefined, protocol: 'ip' | 'icmp' | 'igmp' | 'ggp' | 'tcp' | 'pup' | 'udp' | 'idp' | 'esp' | 'nd' | 'raw', userGroups?: Array | undefined, users?: Array | undefined, vendor?: string | undefined, version?: string | undefined, webApplications?: Array | undefined}; export type SoftwareCpe = {edition?: string | undefined, language?: string | undefined, other?: string | undefined, part: 'o' | 'a' | 'h', product?: string | undefined, swEdition?: string | undefined, targetHW?: string | undefined, targetSW?: string | undefined, update?: string | undefined, 'v2.2'?: string | undefined, 'v2.3'?: string | undefined, vendor?: string | undefined, version?: string | undefined}; export type Software = {configurations?: Array | undefined, cpe?: SoftwareCpe | undefined, description?: string | undefined, family?: string | undefined, id?: Record | undefined, product?: string | undefined, type?: string | undefined, vendor?: string | undefined, version?: string | undefined}; export type AssetVulnerabilities = {critical?: number | undefined, exploits?: number | undefined, malwareKits?: number | undefined, moderate?: number | undefined, severe?: number | undefined, total?: number | undefined}; export type AssetCreate = {addresses?: Array
| undefined, assessedForPolicies?: boolean | undefined, assessedForVulnerabilities?: boolean | undefined, configurations?: Array | undefined, cpe?: string | undefined, databases?: Array | undefined, date: string, description?: string | undefined, files?: Array | undefined, history?: Array | undefined, hostName?: string | undefined, hostNames?: Array | undefined, id?: Record | undefined, ids?: Array | undefined, ip?: string | undefined, links: Array, mac?: string | undefined, os?: string | undefined, osCertainty?: string | undefined, osFingerprint?: OperatingSystem | undefined, rawRiskScore?: number | undefined, riskScore?: number | undefined, services?: Array | undefined, software?: Array | undefined, type?: ('unknown' | 'guest' | 'hypervisor' | 'physical' | 'mobile') | undefined, userGroups?: Array | undefined, users?: Array | undefined, vulnerabilities?: AssetVulnerabilities | undefined}; export type CreateApiApi3SitesIdAssetsArgs = {id: number, body: AssetCreate}; export type CreateApiApi3SitesIdAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({deprecation: z.string().optional(), href: z.string().optional(), hreflang: z.string().optional(), media: z.string().optional(), rel: z.string().optional(), title: z.string().optional(), type: z.string().optional()}); export const createdReference = z.object({id: z.object({}).optional(), links: z.array(link).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 }; /** * Assets * * POST /api/3/sites/{id}/assets */ export const createApiApi3SitesIdAssets = async (args: CreateApiApi3SitesIdAssetsArgs, options?: CreateApiApi3SitesIdAssetsOptions) => { const {baseUrl = "https://:", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json;charset=UTF-8") const url = `${baseUrl.replace(/\/+$/, '')}/api/3/sites/${encodeURIComponent(String(args.id))}/assets${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createdReference, await res.json()) };