import {z} from 'zod' export type UpdateApiCallsCallIdArgs = {'Content-Type': string, Token: string, call_id: number, body: {account_id?: number | undefined, user_id?: number | undefined, from_user_id?: number | undefined, deal_id?: number | undefined, company_id?: number | undefined, person_id?: number | undefined, username?: string | undefined, from_number?: string | undefined, to_number?: string | undefined, record_audio?: boolean | undefined, from_caller_id?: number | undefined, to_caller_id?: number | undefined, description?: string | undefined, start_at?: string | undefined, end_at?: string | undefined, record_url?: string | undefined, external_call_id?: number | undefined, important?: boolean | undefined, duration?: number | undefined, cost?: string | undefined}}; export type UpdateApiCallsCallIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiCallsCallIdResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), data: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), user_id: z.number().int().optional(), from_user_id: z.number().int().optional(), deal_id: z.number().int().optional(), company_id: z.number().int().optional(), person_id: z.number().int().optional(), webphone_id: z.number().int().optional(), webphone_extension_id: z.number().int().optional(), name: z.string().optional(), from_number: z.string().optional(), to_number: z.string().optional(), record_audio: z.number().int().optional(), from_caller_id: z.string().optional(), to_caller_id: z.string().optional(), description: z.string().optional(), start_at: z.string().optional(), end_at: z.string().optional(), status: z.number().int().optional(), record_url: z.string().optional(), external_call_id: z.number().int().optional(), json_return: z.string().optional(), important: z.number().int().optional(), duration: z.string().optional(), cost: z.number().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).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 }; /** * Atualizar histórico de ligação * * PUT /calls/{call_id} */ export const updateApiCallsCallId = async (args: UpdateApiCallsCallIdArgs, options?: UpdateApiCallsCallIdOptions) => { const {baseUrl = "https://api.pipe.run/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Token != null) headers.set("Token", String(args.Token)) if (sec0 !== undefined) headers.set("token", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/calls/${encodeURIComponent(String(args.call_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiCallsCallIdResponse, await res.json()) };