import {z} from 'zod' export type NetworkFlowV1SelectSchema = {projectId?: boolean | undefined, networkDeviceId?: boolean | undefined, exporterIp?: boolean | undefined, srcIp?: boolean | undefined, dstIp?: boolean | undefined, srcPort?: boolean | undefined, dstPort?: boolean | undefined, protocol?: boolean | undefined, inputInterfaceIndex?: boolean | undefined, outputInterfaceIndex?: boolean | undefined, octets?: boolean | undefined, packets?: boolean | undefined, flowStartAt?: boolean | undefined, flowEndAt?: boolean | undefined, ingestedAt?: boolean | undefined, flowFormat?: boolean | undefined, samplingRate?: boolean | undefined, flowCount?: boolean | undefined, probeId?: boolean | undefined, srcName?: boolean | undefined, dstName?: boolean | undefined, _id?: boolean | undefined, createdAt?: boolean | undefined}; export type CreateApiNetworkFlowIdGetItemArgs = {id: string, body: {select?: NetworkFlowV1SelectSchema | undefined}}; export type CreateApiNetworkFlowIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const networkFlowV1 = z.object({projectId: z.string(), networkDeviceId: z.string(), exporterIp: z.string(), srcIp: z.string(), dstIp: z.string(), srcPort: z.number(), dstPort: z.number(), protocol: z.number(), inputInterfaceIndex: z.number(), outputInterfaceIndex: z.number(), octets: z.string().optional(), packets: z.string().optional(), flowStartAt: z.string().optional(), flowEndAt: z.string().optional(), ingestedAt: z.string().optional(), flowFormat: z.string(), samplingRate: z.number(), flowCount: z.number(), probeId: z.string().optional(), srcName: z.string(), dstName: z.string()}); export const createApiNetworkFlowIdGetItemResponse = z.object({data: networkFlowV1.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 }; /** * Get Network Flow * * POST /network-flow/{id}/get-item */ export const createApiNetworkFlowIdGetItem = async (args: CreateApiNetworkFlowIdGetItemArgs, options?: CreateApiNetworkFlowIdGetItemOptions) => { 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-flow/${encodeURIComponent(String(args.id))}/get-item${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(createApiNetworkFlowIdGetItemResponse, await res.json()) };