import {z} from 'zod' export type GetApiFinalizeV2TasksTaskIdArgs = {task_id: string, include?: string | undefined}; export type GetApiFinalizeV2TasksTaskIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiFinalizeV2TasksTaskIdResponse = z.object({data: z.object({id: z.string(), active: z.boolean(), agreement_id: z.string().nullable(), approval_type: z.enum(["latest_version", "text", "attachment"]).nullable(), assignee_ids: z.array(z.string()), attachment_id: z.string().nullable(), author_id: z.string().nullable(), created_at: z.string(), due_date: z.string().nullable(), name: z.string().nullable(), position: z.number().int().nullable(), resolver_id: z.string().nullable(), status: z.enum(["unreviewed", "approved", "rejected(deprecated)"]), text: z.string(), type: z.enum(["ApprovalTask", "GenericTask", "StandaloneTask"])}), _embedded: z.object({users: z.array(z.object({id: z.string(), first_name: z.string(), last_name: z.string(), email: z.string()}))})}); 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 Task * * GET /finalize/v2/tasks/{task_id} */ export const getApiFinalizeV2TasksTaskId = async (args: GetApiFinalizeV2TasksTaskIdArgs, options?: GetApiFinalizeV2TasksTaskIdOptions) => { const {baseUrl = "https://api.linksquares.com/api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include != null) query.append("include", String(args.include)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/finalize/v2/tasks/${encodeURIComponent(String(args.task_id))}${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(getApiFinalizeV2TasksTaskIdResponse, await res.json()) };