import {z} from 'zod' export type GetApiV1IntegrationsInstallationsInstallationIdResourcesFailedArgs = {installation_id: string}; export type GetApiV1IntegrationsInstallationsInstallationIdResourcesFailedOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const connectorSyncRun = z.object({status: z.enum(["in_progress", "completed", "failed", "stale"]), started_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), error: z.string().nullable().optional()}); export const connectorResourceSync = z.object({status: z.enum(["not_syncing", "syncing", "partial", "error"]), last_synced_at: z.string().nullable().optional(), error: z.string().nullable().optional(), last_run: connectorSyncRun.nullable().optional()}); export const connectorResource = z.object({id: z.string(), name: z.string(), kind: z.enum(["label", "folder", "file", "channel", "private_channel", "direct_message", "group_message"]), is_selected: z.boolean().optional(), parent_id: z.string().nullable().optional(), url: z.string().nullable().optional(), message_count: z.number().int().nullable().optional(), member_count: z.number().int().nullable().optional(), sync: connectorResourceSync.nullable().optional()}); export const connectorResourceListResponse = z.object({data: z.array(connectorResource)}); 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 }; /** * List a connected account's resources whose last sync failed * * GET /v1/integrations/installations/{installation_id}/resources/failed */ export const getApiV1IntegrationsInstallationsInstallationIdResourcesFailed = async (args: GetApiV1IntegrationsInstallationsInstallationIdResourcesFailedArgs, options?: GetApiV1IntegrationsInstallationsInstallationIdResourcesFailedOptions) => { 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 (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/integrations/installations/${encodeURIComponent(String(args.installation_id))}/resources/failed${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(connectorResourceListResponse, await res.json()) };