import {z} from 'zod' export type GetApiDealsDealIdTasksArgs = {page?: number | undefined, per_page?: number | undefined, finishedDateGt?: string | undefined, finishedDateLt?: string | undefined, dueDateGt?: string | undefined, dueDateLt?: string | undefined, updatedDateGt?: string | undefined, updatedDateLt?: string | undefined, createdDateGt?: string | undefined, createdDateLt?: string | undefined, metricId?: number | undefined, finishedEq?: ('true' | 'false') | undefined, deal_id: number}; export type GetApiDealsDealIdTasksOptions = {baseUrl: string, token?: string | undefined, fetch?: typeof fetch | undefined}; export const leanUserEntity = z.object({accountId: z.number().int().optional(), id: z.number().int().optional(), name: z.string().optional()}); export const activityMetricEntity = z.object({id: z.number().int().optional(), name: z.string().optional(), value: z.number().optional()}); export const taskEntity = z.object({id: z.number().int().optional(), accountId: z.number().int().optional(), user: z.object({accountId: z.number().int().optional(), id: z.number().int().optional(), name: z.string().optional()}).optional(), text: z.string().optional(), organization: z.object({id: z.string().optional(), name: z.string().optional(), email: z.string().optional()}).optional(), person: z.object({id: z.number().int().optional(), name: z.string().optional(), email: z.string().optional()}).optional(), deal: z.object({id: z.string().optional(), title: z.string().optional(), currency: z.object({id: z.number().int().optional(), isoCode: z.string().optional(), name: z.string().optional(), symbol: z.string().optional()}).optional(), exchangeRate: z.number().optional(), exchangeRateSource: z.enum(["deal", "closed", "account"]).optional(), valueInBrl: z.number().optional()}).optional(), dueDate: z.unknown(), finishedAt: z.unknown(), finishedBy: z.object({accountId: z.number().int().optional(), id: z.number().int().optional(), name: z.string().optional()}).optional(), createdAt: z.unknown(), updatedAt: z.unknown(), assignedUsers: z.array(leanUserEntity).optional(), metrics: z.array(activityMetricEntity).optional(), type: z.string().optional(), _webUrl: z.string().optional(), audioTranscription: z.object({id: z.number().int().optional(), content: z.string().optional(), liked: z.boolean().optional(), feedback: z.string().optional()}).optional(), audioSummary: z.object({id: z.number().int().optional(), content: z.string().optional(), liked: z.boolean().optional(), feedback: z.string().optional(), audioTranscriptionId: z.number().int().optional()}).optional()}); export const getApiDealsDealIdTasksResponse = z.object({data: z.array(taskEntity).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 and search tasks of a deal. * * GET /deals/{deal_id}/tasks */ export const getApiDealsDealIdTasks = async (args: GetApiDealsDealIdTasksArgs, options: GetApiDealsDealIdTasksOptions) => { const {baseUrl, fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.finishedDateGt != null) query.append("finishedDateGt", String(args.finishedDateGt)) if (args.finishedDateLt != null) query.append("finishedDateLt", String(args.finishedDateLt)) if (args.dueDateGt != null) query.append("dueDateGt", String(args.dueDateGt)) if (args.dueDateLt != null) query.append("dueDateLt", String(args.dueDateLt)) if (args.updatedDateGt != null) query.append("updatedDateGt", String(args.updatedDateGt)) if (args.updatedDateLt != null) query.append("updatedDateLt", String(args.updatedDateLt)) if (args.createdDateGt != null) query.append("createdDateGt", String(args.createdDateGt)) if (args.createdDateLt != null) query.append("createdDateLt", String(args.createdDateLt)) if (args.metricId != null) query.append("metricId", String(args.metricId)) if (args.finishedEq != null) query.append("finishedEq", String(args.finishedEq)) if (token !== undefined) headers.set("Authorization", token) const url = `${baseUrl.replace(/\/+$/, '')}/deals/${encodeURIComponent(String(args.deal_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(getApiDealsDealIdTasksResponse, await res.json()) };