import {z} from 'zod' export type DocumentSource = 'ingestion_api' | 'slack' | 'web' | 'google_drive' | 'gmail' | 'requesttracker' | 'github' | 'gitlab' | 'guru' | 'bookstack' | 'confluence' | 'discourse' | 'slab' | 'salesforce' | 'jira' | 'productboard' | 'file' | 'notion' | 'zulip' | 'linear' | 'hubspot' | 'document360' | 'gong' | 'google_sites' | 'zendesk' | 'loopio' | 'sharepoint' | 'teams' | 'freshdesk'; export type InputType = 'load_state' | 'poll' | 'event'; export type ConnectorBase = {name: string, source: DocumentSource, input_type: InputType, connector_specific_config: Record, refresh_freq?: number | undefined, disabled: boolean}; export type PatchApiManageAdminConnectorConnectorIdArgs = {connector_id: number, body: ConnectorBase}; export type PatchApiManageAdminConnectorConnectorIdOptions = {baseUrl: string, APIKeyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const documentSource = z.enum(["ingestion_api", "slack", "web", "google_drive", "gmail", "requesttracker", "github", "gitlab", "guru", "bookstack", "confluence", "discourse", "slab", "salesforce", "jira", "productboard", "file", "notion", "zulip", "linear", "hubspot", "document360", "gong", "google_sites", "zendesk", "loopio", "sharepoint", "teams", "freshdesk"]); export const inputType = z.enum(["load_state", "poll", "event"]); export const connectorSnapshot = z.object({name: z.string(), source: documentSource, input_type: inputType, connector_specific_config: z.object({}), refresh_freq: z.number().int().optional(), disabled: z.boolean(), id: z.number().int(), credential_ids: z.array(z.number().int()), time_created: z.string(), time_updated: z.string()}); export const statusResponseInt = z.object({success: z.boolean(), message: z.string().optional(), data: z.number().int().optional()}); export const patchApiManageAdminConnectorConnectorIdResponse = z.union([connectorSnapshot, statusResponseInt]); 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 Connector From Model * * PATCH /manage/admin/connector/{connector_id} */ export const patchApiManageAdminConnectorConnectorId = async (args: PatchApiManageAdminConnectorConnectorIdArgs, options: PatchApiManageAdminConnectorConnectorIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyCookie !== undefined) cookies.push("fastapiusersauth=" + encodeURIComponent(APIKeyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/manage/admin/connector/${encodeURIComponent(String(args.connector_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(patchApiManageAdminConnectorConnectorIdResponse, await res.json()) };