import {z} from 'zod' 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 ExcludedAssetGroups = {assetGroupIDs?: Array> | undefined, links: Array}; export type ExcludedScanTargets = {addresses?: Array | undefined, links: Array}; export type SubsetIncludeScanAssetGroupsResource = {assetGroupIDs?: Array> | undefined, links: Array}; export type SubsetIncludeScanTargetsResource = {addresses?: Array | undefined, links: Array}; export type ScheduledScanTargets = {excludedAssetGroups?: ExcludedAssetGroups | undefined, excludedTargets?: ExcludedScanTargets | undefined, includedAssetGroups?: SubsetIncludeScanAssetGroupsResource | undefined, includedTargets?: SubsetIncludeScanTargetsResource | undefined}; export type Repeat = {dayOfWeek?: ('sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday') | undefined, every: 'hour' | 'day' | 'week' | 'date-of-month' | 'day-of-month', interval: number, lastDayOfMonth?: boolean | undefined, weekOfMonth?: number | undefined}; export type ScanSchedule = {assets?: ScheduledScanTargets | undefined, duration?: string | undefined, enabled: boolean, id?: Record | undefined, links: Array, nextRuntimes?: Array | undefined, onScanRepeat: 'restart-scan' | 'resume-scan', repeat?: Repeat | undefined, scanEngineId?: number | undefined, scanName?: string | undefined, scanTemplateId?: string | undefined, start: string}; export type UpdateApiApi3SitesIdScanSchedulesArgs = {id: number, body: Array}; export type UpdateApiApi3SitesIdScanSchedulesOptions = {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 links = z.object({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 }; /** * Site Scan Schedules * * PUT /api/3/sites/{id}/scan_schedules */ export const updateApiApi3SitesIdScanSchedules = async (args: UpdateApiApi3SitesIdScanSchedulesArgs, options?: UpdateApiApi3SitesIdScanSchedulesOptions) => { 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))}/scan_schedules${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(links, await res.json()) };