import {z} from 'zod' export type GetApiApiV2UiTaskwrappersArgs = {'page[after]'?: string | undefined, 'page[before]'?: string | undefined, 'page[size]'?: number | undefined, filter?: {[key: string]: string} | undefined, include?: (Array<'accessGroup' | 'hashlist' | 'hashType' | 'task' | 'tasks'>) | undefined}; export type GetApiApiV2UiTaskwrappersOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskWrapperListResponse = 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("taskWrapper"), attributes: z.object({priority: z.number().int(), maxAgents: z.number().int(), taskType: z.union([z.literal(0), z.literal(1)]), hashlistId: z.number().int(), accessGroupId: z.number().int(), taskWrapperName: z.string(), isArchived: z.boolean(), cracked: z.number().int()}), links: z.object({self: z.string()}), relationships: z.object({accessGroup: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.object({type: z.literal("accessGroup"), id: z.number().int()}).nullable().optional()}), hashType: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.object({type: z.literal("hashType"), id: z.number().int()}).nullable().optional()}), hashlist: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.object({type: z.literal("hashlist"), id: z.number().int()}).nullable().optional()}), task: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.object({type: z.literal("task"), id: z.number().int()}).nullable().optional()}), 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.discriminatedUnion("type", [z.object({id: z.number().int(), type: z.literal("accessGroup"), attributes: z.object({groupName: z.string()})}), z.object({id: z.number().int(), type: z.literal("hashlist"), attributes: z.object({name: z.string(), format: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]), hashTypeId: z.number().int(), hashCount: z.number().int(), separator: z.string().nullable(), cracked: z.number().int(), isSecret: z.boolean(), isHexSalt: z.boolean(), isSalted: z.boolean(), accessGroupId: z.number().int(), notes: z.string(), useBrain: z.boolean(), brainFeatures: z.number().int(), isArchived: z.boolean()})}), z.object({id: z.number().int(), type: z.literal("hashType"), attributes: z.object({description: z.string(), isSalted: z.boolean(), isSlowHash: z.boolean()})}), 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 TaskWrappers * * GET /api/v2/ui/taskwrappers */ export const getApiApiV2UiTaskwrappers = async (args: GetApiApiV2UiTaskwrappersArgs, options: GetApiApiV2UiTaskwrappersOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/ui/taskwrappers${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(taskWrapperListResponse, await res.json()) };