import {z} from 'zod' export type OAuthProviderUpdate = {provider_name?: (string | null) | undefined, name?: (string | null) | undefined, client_id?: (string | null) | undefined, client_secret?: (string | null) | undefined, auth_url?: (string | null) | undefined, token_url?: (string | null) | undefined, redirect_uri?: (string | null) | undefined, userinfo_url?: (string | null) | undefined, user_id_path?: (string | null) | undefined, email_path?: (string | null) | undefined, default_scopes?: (Array | null) | undefined}; export type UpdateApiApiAdminMcpProvidersProviderIdArgs = {provider_id: number, body: OAuthProviderUpdate}; export type UpdateApiApiAdminMcpProvidersProviderIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const oAuthProviderResponse = z.object({provider_name: z.string(), name: z.string(), client_id: z.string(), client_secret: z.string(), auth_url: z.string(), token_url: z.string(), redirect_uri: z.string().nullable().optional(), userinfo_url: z.string().nullable().optional(), user_id_path: z.string().nullable().optional(), email_path: z.string().nullable().optional(), default_scopes: z.array(z.string()).nullable().optional(), id: z.number().int()}); 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 Provider * * PUT /api/admin/mcp/providers/{provider_id} */ export const updateApiApiAdminMcpProvidersProviderId = async (args: UpdateApiApiAdminMcpProvidersProviderIdArgs, options: UpdateApiApiAdminMcpProvidersProviderIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/admin/mcp/providers/${encodeURIComponent(String(args.provider_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(oAuthProviderResponse, await res.json()) };