import {z} from 'zod' export type NetworkDeviceDiscoveryScanCreateSchema = {projectId?: string | undefined, probeId: string, name?: string | undefined, cidr: string, snmpConfigs?: Record | undefined, isSnmpEnabled?: boolean | undefined, useShortDeviceNames?: boolean | undefined, snmpVersion?: string | undefined, snmpCommunityString?: string | undefined, snmpPort?: number | undefined, snmpV3SecurityLevel?: string | undefined, snmpV3Username?: string | undefined, snmpV3AuthProtocol?: string | undefined, snmpV3AuthKey?: string | undefined, snmpV3PrivProtocol?: string | undefined, snmpV3PrivKey?: string | undefined, isNetbiosLookupEnabled?: boolean | undefined, isRecurring?: boolean | undefined, rescanIntervalInMinutes?: number | undefined}; export type CreateApiNetworkDeviceDiscoveryScanArgs = {body: {data: NetworkDeviceDiscoveryScanCreateSchema}}; export type CreateApiNetworkDeviceDiscoveryScanOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const networkDeviceDiscoveryScanReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), probeId: z.string(), name: z.string().optional(), cidr: z.string(), snmpConfigs: z.object({}).optional(), isSnmpEnabled: z.boolean().optional(), useShortDeviceNames: z.boolean().optional(), snmpVersion: z.string().optional(), snmpCommunityString: z.string().optional(), snmpPort: z.number().optional(), snmpV3SecurityLevel: z.string().optional(), snmpV3Username: z.string().optional(), snmpV3AuthProtocol: z.string().optional(), snmpV3AuthKey: z.string().optional(), snmpV3PrivProtocol: z.string().optional(), snmpV3PrivKey: z.string().optional(), status: z.string().optional(), statusMessage: z.string().optional(), isNetbiosLookupEnabled: z.boolean().optional(), discoveredDevices: z.object({}).optional(), scannedHostCount: z.number().optional(), respondedHostCount: z.number().optional(), startedAt: z.object({}).optional(), completedAt: z.object({}).optional(), isRecurring: z.boolean().optional(), rescanIntervalInMinutes: z.number().optional(), nextScanAt: z.object({}).optional(), autoImportProcessedAt: z.object({}).optional(), createdByUserId: z.string().optional(), deletedByUserId: z.string().optional()}); export const createApiNetworkDeviceDiscoveryScanResponse = z.object({data: networkDeviceDiscoveryScanReadSchema.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 }; /** * Create Network Device Discovery Scan * * POST /network-device-discovery-scan */ export const createApiNetworkDeviceDiscoveryScan = async (args: CreateApiNetworkDeviceDiscoveryScanArgs, options?: CreateApiNetworkDeviceDiscoveryScanOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/network-device-discovery-scan${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(createApiNetworkDeviceDiscoveryScanResponse, await res.json()) };