import {z} from 'zod' export type PatchApiV2ConnectionsConnectionIdArgs = {connection_id: string, body: {name?: string | undefined, server_url?: string | undefined, auth_method?: ('url' | 'oauth' | 'apikey' | 'headers') | undefined, headers?: ({plaintext?: {[key: string]: string} | undefined, secret?: {[key: string]: string} | undefined} | null) | undefined, shared?: boolean | undefined}}; export type PatchApiV2ConnectionsConnectionIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV2ConnectionsConnectionIdResponse = z.object({id: z.string(), name: z.string(), type: z.string(), provider: z.string(), user_id: z.string().nullable(), team_id: z.string(), server_url: z.string().optional(), transport_type: z.enum(["stdio", "sse", "http"]).optional(), auth_method: z.string().nullable().optional(), custom_integration_id: z.string().nullable().optional(), icon_url: z.string().nullable().optional(), oauth_provider: z.string().nullable().optional(), oauth_provider_key: z.string().nullable().optional(), oauth_scopes: z.array(z.string()).nullable().optional(), has_headers: z.boolean().optional(), has_oauth_tokens: z.boolean().optional(), integration_id: z.string().nullable().optional(), shared: z.boolean().optional(), created_by: z.string().nullable().optional(), broken_at: z.string().nullable().optional(), broken_reason: z.string().nullable().optional(), created_at: z.string(), updated_at: 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 }; /** * Update Connection * * PATCH /v2/connections/{connection_id} */ export const patchApiV2ConnectionsConnectionId = async (args: PatchApiV2ConnectionsConnectionIdArgs, options?: PatchApiV2ConnectionsConnectionIdOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/connections/${encodeURIComponent(String(args.connection_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV2ConnectionsConnectionIdResponse, await res.json()) };