import {z} from 'zod' export type GetApiApiV2UiTaskwrapperdisplaysArgs = {'page[after]'?: string | undefined, 'page[before]'?: string | undefined, 'page[size]'?: number | undefined, filter?: {[key: string]: string} | undefined, include?: Array<'tasks'> | undefined, aggregate?: {[key: string]: string} | undefined}; export type GetApiApiV2UiTaskwrapperdisplaysOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskWrapperDisplayListResponse = z.object({jsonapi: z.object({version: z.string(), ext: z.array(z.string()).optional()}), links: z.object({self: z.string(), first: z.string(), last: z.string().nullable(), next: z.string().nullable(), prev: z.string().nullable()}), meta: z.object({page: z.object({total_elements: z.number().int()})}), data: z.array(z.object({id: z.number().int(), type: z.literal("taskWrapperDisplay"), attributes: z.object({taskWrapperPriority: z.number().int(), taskWrapperMaxAgents: z.number().int(), taskType: z.union([z.literal(0), z.literal(1)]), hashlistId: z.number().int(), accessGroupId: z.number().int(), taskWrapperName: z.string(), displayName: z.string(), taskWrapperIsArchived: z.boolean(), cracked: z.number().int(), taskId: z.number().int().nullable(), taskName: z.string().nullable(), color: z.string().nullable(), attackCmd: z.string().nullable(), chunkTime: z.number().int().nullable(), statusTimer: z.number().int().nullable(), keyspace: z.number().int().nullable(), keyspaceProgress: z.number().int().nullable(), taskPriority: z.number().int().nullable(), taskMaxAgents: z.number().int().nullable(), isSmall: z.boolean(), isCpuTask: z.boolean(), taskIsArchived: z.boolean(), preprocessorId: z.number().int().nullable(), hashlistName: z.string(), hashCount: z.number().int(), hashlistCracked: z.number().int(), hashlistIsSecret: z.boolean(), hashTypeId: z.number().int(), hashTypeDescription: z.string(), groupName: z.string(), totalAssignedAgents: z.number().int().optional(), dispatched: z.string().optional(), searched: z.string().optional(), status: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), currentSpeed: z.number().int().optional(), estimatedTime: z.number().int().optional(), cprogress: z.number().int().optional(), timeSpent: z.number().int().optional()}), links: z.object({self: z.string()}), relationships: z.object({tasks: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.array(z.object({type: z.literal("task"), id: z.number().int()})).optional()})})})), included: z.array(z.object({id: z.number().int(), type: z.literal("task"), attributes: z.object({taskName: z.string(), attackCmd: z.string(), chunkTime: z.number().int(), statusTimer: z.number().int(), keyspace: z.number().int(), keyspaceProgress: z.number().int(), priority: z.number().int(), maxAgents: z.number().int(), color: z.string().nullable(), isSmall: z.boolean(), isCpuTask: z.boolean(), useNewBench: z.boolean(), skipKeyspace: z.number().int(), crackerBinaryId: z.number().int(), crackerBinaryTypeId: z.number().int().nullable(), taskWrapperId: z.number().int(), isArchived: z.boolean(), notes: z.string(), staticChunks: z.number().int(), chunkSize: z.number().int(), forcePipe: z.boolean(), preprocessorId: z.number().int(), preprocessorCommand: z.string()})})).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 TaskWrapperDisplays * * GET /api/v2/ui/taskwrapperdisplays */ export const getApiApiV2UiTaskwrapperdisplays = async (args: GetApiApiV2UiTaskwrapperdisplaysArgs, options: GetApiApiV2UiTaskwrapperdisplaysOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (args.include != null) query.append("include", args.include.join(',')) if (args.aggregate != null) query.append("aggregate", JSON.stringify(args.aggregate)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/ui/taskwrapperdisplays${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(taskWrapperDisplayListResponse, await res.json()) };