import {z} from 'zod' export type GetApiApiV1AccountsAccountIdTasksArgs = {accountId: string, top?: number | undefined, skip?: number | undefined, count?: boolean | undefined, filter?: string | undefined}; export type GetApiApiV1AccountsAccountIdTasksOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskStatus = z.object({enabled: z.boolean().optional(), delivery_state: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), last_job_date: z.string().nullable().optional()}); export const taskRecurrencePattern = z.object({type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]).optional(), frequency: z.number().int().nullable().optional(), days_of_week: z.array(z.number().int()).optional(), week_of_month: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]).nullable().optional(), date_of_month: z.array(z.number().int().nullable()).optional(), month_of_year: z.array(z.number().int().nullable()).optional()}); export const taskSchedule = z.object({type: z.union([z.literal(1), z.literal(2), z.literal(3)]).optional(), start_date: z.string().optional(), is_local_time: z.boolean().optional(), recurrence: taskRecurrencePattern.optional(), execution_timeout: z.string().optional(), execution_window: z.union([z.literal(0), z.literal(1)]).nullable().optional(), execution_window_expiration: z.string().optional(), publish_date: z.string().nullable().optional()}); export const tasksOutput = z.object({account_id: z.string().optional(), id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), type: z.union([z.literal(1), z.literal(2), z.literal(6), z.literal(7), z.literal(10)]).optional(), status: taskStatus.optional(), schedule: taskSchedule.optional(), can_be_deleted: z.boolean().optional(), can_be_copied: z.boolean().optional(), can_access_to_detailed_view: z.boolean().optional(), scope_type: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional()}); export const tasksOutputFindResponse = z.object({data: tasksOutput.optional(), total_items: z.number().int().nullable().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 }; /** * Retrieve tasks. * * GET /api/v1/accounts/{accountId}/tasks */ export const getApiApiV1AccountsAccountIdTasks = async (args: GetApiApiV1AccountsAccountIdTasksArgs, options?: GetApiApiV1AccountsAccountIdTasksOptions) => { const {baseUrl = "https://api.usa.cloud.watchguard.com/rest/aether-endpoint-security/aether-mgmt", fetch: fetchFn = fetch, ApiKeyAuth, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.top != null) query.append("top", String(args.top)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.count != null) query.append("count", String(args.count)) if (args.filter != null) query.append("filter", String(args.filter)) if (ApiKeyAuth !== undefined) headers.set("WatchGuard-API-Key", ApiKeyAuth) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/accounts/${encodeURIComponent(String(args.accountId))}/tasks${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(tasksOutputFindResponse, await res.json()) };