import {z} from 'zod' export type GetApiWorkspacesWorkspaceIdProjectsProjectIdTasksArgs = {workspace_id: number, project_id: number}; export type GetApiWorkspacesWorkspaceIdProjectsProjectIdTasksOptions = {baseUrl: string, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const modelsTask = z.object({active: z.boolean().optional(), at: z.string().optional(), estimated_seconds: z.number().int().nullable().optional(), id: z.number().int().optional(), name: z.string().optional(), permissions: z.string().optional(), project_id: z.number().int().optional(), recurring: z.boolean().optional(), server_deleted_at: z.string().nullable().optional(), toggl_accounts_id: z.string().nullable().optional(), tracked_seconds: z.number().int().optional(), user_id: z.number().int().nullable().optional(), workspace_id: z.number().int().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 }; /** * WorkspaceProjectTasks * * GET /workspaces/{workspace_id}/projects/{project_id}/tasks */ export const getApiWorkspacesWorkspaceIdProjectsProjectIdTasks = async (args: GetApiWorkspacesWorkspaceIdProjectsProjectIdTasksArgs, options: GetApiWorkspacesWorkspaceIdProjectsProjectIdTasksOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/projects/${encodeURIComponent(String(args.project_id))}/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(modelsTask, await res.json()) };