import {z} from 'zod' export type DeleteApiV1IntegrationsGithubInstallationsInstallationIdArgs = {installation_id: string, delete_data?: boolean | undefined}; export type DeleteApiV1IntegrationsGithubInstallationsInstallationIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const integrationInstallation = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), organization_id: z.string(), provider: z.string(), external_account_id: z.string(), external_account_name: z.string().nullable(), installed_by_user_id: z.string().nullable(), status: z.string(), scopes: z.array(z.string()).nullable(), metadata: z.record(z.string(), z.unknown())}); export const integrationInstallationResponse = z.object({data: integrationInstallation}); 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 }; /** * Disconnect GitHub * * DELETE /v1/integrations/github/installations/{installation_id} */ export const deleteApiV1IntegrationsGithubInstallationsInstallationId = async (args: DeleteApiV1IntegrationsGithubInstallationsInstallationIdArgs, options?: DeleteApiV1IntegrationsGithubInstallationsInstallationIdOptions) => { const {baseUrl = "https://api.mixedbread.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.delete_data != null) query.append("delete_data", String(args.delete_data)) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/integrations/github/installations/${encodeURIComponent(String(args.installation_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(integrationInstallationResponse, await res.json()) };