import {z} from 'zod' export type CreateApiV2TeamsTeamIdConnectionsArgs = {teamId: string, body: {name: string, server_url?: string | undefined, type?: string | undefined, provider: 'user', auth_method: 'url' | 'apikey' | 'headers' | 'oauth', custom_integration_id?: string | undefined, headers?: ({plaintext?: {[key: string]: string} | undefined, secret?: {[key: string]: string} | undefined}) | undefined}}; export type CreateApiV2TeamsTeamIdConnectionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2TeamsTeamIdConnectionsResponse = 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 }; /** * Create Connection * * POST /v2/teams/{teamId}/connections */ export const createApiV2TeamsTeamIdConnections = async (args: CreateApiV2TeamsTeamIdConnectionsArgs, options?: CreateApiV2TeamsTeamIdConnectionsOptions) => { 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/teams/${encodeURIComponent(String(args.teamId))}/connections${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV2TeamsTeamIdConnectionsResponse, await res.json()) };