import {z} from 'zod' export type V1providersUpdateCustomProvider = {auth_patterns?: Array> | undefined, description?: string | undefined, display_name?: string | undefined, icon_src?: string | undefined, metadata?: {[key: string]: string} | undefined, proxy_enabled?: boolean | undefined, proxy_url?: string | undefined}; export type UpdateApiApiV1CustomProvidersIdentifierArgs = {identifier: string, body: V1providersUpdateCustomProvider}; export type UpdateApiApiV1CustomProvidersIdentifierOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const providersProvider = z.object({auth_patterns: z.array(z.object({})).optional(), categories: z.array(z.string()).optional(), coming_soon: z.boolean().optional(), description: z.string().optional(), display_name: z.string().optional(), display_priority: z.number().int().optional(), icon_src: z.string().optional(), id: z.string().optional(), identifier: z.string().optional(), is_custom: z.boolean().optional(), is_custom_mcp: z.boolean().optional(), metadata: z.record(z.string(), z.string()).optional(), proxy_enabled: z.boolean().optional(), proxy_url: z.string().optional()}); export const providersUpdateProviderResponse = z.object({provider: providersProvider.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 }; /** * Update a custom provider * * PUT /api/v1/custom-providers/{identifier} */ export const updateApiApiV1CustomProvidersIdentifier = async (args: UpdateApiApiV1CustomProvidersIdentifierArgs, options?: UpdateApiApiV1CustomProvidersIdentifierOptions) => { const {baseUrl = "https://$SCALEKIT_ENVIRONMENT_URL", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/custom-providers/${encodeURIComponent(String(args.identifier))}${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(providersUpdateProviderResponse, await res.json()) };