import {z} from 'zod' export type UpdateApiPipelinesIdArgs = {id: number, body: {name?: string | undefined, funnel_type?: number | undefined, user_id?: string | undefined, is_main?: boolean | undefined, limit_time?: number | undefined, order?: number | undefined, description?: string | undefined, visibility?: number | undefined, allowedUsers?: ({'0'?: ({id?: number | undefined}) | undefined, '1'?: ({id?: number | undefined}) | undefined, '2'?: ({id?: number | undefined}) | undefined, '3'?: ({id?: number | undefined}) | undefined, '4'?: ({id?: number | undefined}) | undefined, '5'?: ({id?: number | undefined}) | undefined, '6'?: Record | undefined, '7'?: Record | undefined, '8'?: Record | undefined}) | undefined}}; export type UpdateApiPipelinesIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiPipelinesIdResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), data: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), funnel_type: z.number().int().optional(), user_id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), funnel_type_name: z.string().optional(), order: z.number().int().optional(), is_main: z.boolean().optional(), limit_time: z.number().int().optional(), visibility: z.number().int().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 funil * * PUT /pipelines/{id} */ export const updateApiPipelinesId = async (args: UpdateApiPipelinesIdArgs, options?: UpdateApiPipelinesIdOptions) => { 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 (sec0 !== undefined) headers.set("token", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/pipelines/${encodeURIComponent(String(args.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(updateApiPipelinesIdResponse, await res.json()) };