import {z} from 'zod' export type GetApiIntegrationsConnectAttemptsAttemptIdArgs = {attemptId: string, organizationId?: string | undefined}; export type GetApiIntegrationsConnectAttemptsAttemptIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiIntegrationsConnectAttemptsAttemptIdResponse = z.object({status: z.enum(["pending", "completed", "not_connected", "failed", "expired"]), conflictPending: z.boolean().optional(), errorCode: z.string().nullable(), connection: z.object({connectionStatus: z.object({state: z.enum(["connected", "needs_attention", "connecting", "not_connected"]), reasonCode: z.enum(["credentials_rejected", "permissions_missing", "configuration_invalid", "discovery_failed", "health_check_failed", "stream_failed", "recovery_required"]).nullable(), checkedAt: z.string().nullable(), verification: z.enum(["verified", "unverified"])}).optional(), recovery: z.object({action: z.enum(["reconnect", "update_credentials", "manage_installation", "manage_owner", "review_setup"]).nullable(), canCheck: z.boolean(), canDisconnect: z.boolean(), target: z.object({kind: z.enum(["integration", "connected_account", "mcp_connector", "log_source", "sandbox_cli"]), resourceId: z.string(), providerId: z.string(), scope: z.object({kind: z.enum(["user", "organization", "project"]), id: z.string()})}).optional()}).optional(), id: z.string(), provider: z.enum(["slack", "github", "linear", "pagerduty", "victorops", "rootly", "better_stack", "incident_io", "webhook", "teams", "discord", "discord_bot", "bitbucket", "jira", "gitcafe", "cursor", "devin", "capy", "warp", "replicas", "claude", "codex", "hoplite", "tembo"]), displayName: z.string().nullable(), distinctName: z.string().nullable().optional(), status: z.enum(["pending", "connected", "error", "revoked"]), isActive: z.boolean(), needsAttention: z.boolean(), metadata: z.record(z.string(), z.unknown()), healthStatus: z.enum(["healthy", "unhealthy", "unknown"]), healthMessage: z.string().nullable(), healthCheckedAt: z.string().nullable(), healthConsecutiveFailures: z.number().int().gte(-9007199254740991).lte(9007199254740991), connectedBy: z.string().nullable(), createdAt: z.string(), updatedAt: z.string()}).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 }; /** * Get a connect attempt * * GET /integrations/connect/attempts/{attemptId} */ export const getApiIntegrationsConnectAttemptsAttemptId = async (args: GetApiIntegrationsConnectAttemptsAttemptIdArgs, options?: GetApiIntegrationsConnectAttemptsAttemptIdOptions) => { const {baseUrl = "https://api.sazabi.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.organizationId != null) query.append("organizationId", String(args.organizationId)) const url = `${baseUrl.replace(/\/+$/, '')}/integrations/connect/attempts/${encodeURIComponent(String(args.attemptId))}${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(getApiIntegrationsConnectAttemptsAttemptIdResponse, await res.json()) };