import type { ApiError, ApiTimestamps, Endpoint } from '../../api.js'; import type { AllAuthCredentials, ApiKeyCredentials, BasicApiCredentials, OAuth1Credentials, OAuth2ClientCredentials, OAuth2Credentials, TbaCredentials } from '../../auth/api.js'; import type { EndUserInput } from '../../connect/api.js'; import type { Tags } from '../../db.js'; import type { ApiEndUser } from '../../endUser/index.js'; import type { ActiveLog } from '../../notification/active-logs/db.js'; import type { ReplaceInObject } from '../../utils.js'; import type { ConnectionConfig, DBConnection, DBConnectionDecrypted } from '../db.js'; import type { Merge } from 'type-fest'; export type ApiConnectionSimple = Pick, 'id' | 'connection_id' | 'provider_config_key' | 'created_at' | 'updated_at'> & { provider: string; errors: { type: string; log_id: string; }[]; endUser: ApiEndUser | null; tags: Tags; pausedSyncs: string[]; }; export type GetConnections = Endpoint<{ Method: 'GET'; Querystring: { env: string; integrationIds?: string[] | undefined; search?: string | undefined; withError?: boolean | undefined; page?: number | undefined; }; Path: '/api/v1/connections'; Success: { data: ApiConnectionSimple[]; }; }>; export type GetConnectionsCount = Endpoint<{ Method: 'GET'; Querystring: { env: string; }; Path: '/api/v1/connections/count'; Success: { data: { total: number; withAuthError: number; withSyncError: number; withError: number; }; }; }>; export type ApiPublicConnection = Pick & { provider_config_key: string; created: string; metadata: Record | null; provider: string; errors: { type: string; log_id: string; }[]; end_user: ApiEndUser | null; tags: Tags; }; export type GetPublicConnections = Endpoint<{ Method: 'GET'; Querystring: { connectionId?: string | undefined; search?: string | undefined; endUserId?: string | undefined; integrationId?: string | undefined; endUserOrganizationId?: string | undefined; tags?: Tags | undefined; limit?: number | undefined; page?: number | undefined; }; Path: '/connection'; Success: { connections: ApiPublicConnection[]; }; }>; export type PostPublicConnection = Endpoint<{ Method: 'POST'; Path: '/connections'; Body: { connection_id?: string | undefined; provider_config_key: string; metadata?: Record | undefined; connection_config?: ConnectionConfig | undefined; credentials: Omit | Omit | Omit | Omit | Omit | Omit | { type: 'APP'; app_id: string; installation_id: string; } | { type: 'CUSTOM'; app_id: string; installation_id: string; } | { type: 'NONE'; }; end_user?: EndUserInput | undefined; tags?: Tags | undefined; }; Error: ApiError<'connection_test_failed'> | ApiError<'connection_validation_failed'>; Success: ApiPublicConnectionFull; }>; export type ApiConnectionFull = Omit, 'credentials_iv' | 'end_user_id' | 'credentials_tag' | 'deleted' | 'deleted_at'>; export type GetConnection = Endpoint<{ Method: 'GET'; Params: { connectionId: string; }; Querystring: { env: string; provider_config_key: string; }; Path: '/api/v1/connections/:connectionId'; Error: ApiError<'unknown_provider_config'>; Success: { data: { provider: string; connection: ApiConnectionFull; endUser: ApiEndUser | null; errorLog: ActiveLog | null; }; }; }>; export type ApiPublicConnectionFull = Pick & { provider_config_key: string; created_at: string; updated_at: string; last_fetched_at: string | null; metadata: Record | null; provider: string; errors: { type: string; log_id: string; }[]; end_user: ApiEndUser | null; tags: Tags; credentials: AllAuthCredentials; }; export type GetPublicConnection = Endpoint<{ Method: 'GET'; Params: { connectionId: string; }; Querystring: { provider_config_key: string; refresh_token?: boolean | undefined; force_refresh?: boolean | undefined; refresh_github_app_jwt_token?: boolean | undefined; }; Path: '/connection/:connectionId'; Error: ApiError<'unknown_provider_config' | 'invalid_credentials'>; Success: ApiPublicConnectionFull; }>; export type PatchPublicConnection = Endpoint<{ Method: 'PATCH'; Path: '/connections/:connectionId'; Params: { connectionId: string; }; Querystring: { provider_config_key: string; }; Body: { end_user?: EndUserInput | undefined; tags?: Tags | undefined; }; Success: { success: boolean; }; Error: ApiError<'unknown_provider_config'>; }>; export type PostConnectionRefresh = Endpoint<{ Method: 'POST'; Params: { connectionId: string; }; Querystring: { env: string; provider_config_key: string; }; Path: '/api/v1/connections/:connectionId/refresh'; Error: ApiError<'unknown_provider_config'> | ApiError<'failed_to_refresh', any, ActiveLog | null>; Success: { data: { success: boolean; }; }; }>; export type DeletePublicConnection = Endpoint<{ Method: 'DELETE'; Path: '/connection/:connectionId'; Params: { connectionId: string; }; Querystring: { provider_config_key: string; }; Error: ApiError<'unknown_connection'> | ApiError<'unknown_provider_config'>; Success: { success: boolean; }; }>; export type DeleteConnection = Endpoint<{ Method: 'DELETE'; Path: '/api/v1/connections/:connectionId'; Params: { connectionId: string; }; Querystring: { provider_config_key: string; env: string; }; Error: ApiError<'unknown_connection'> | ApiError<'unknown_provider_config'>; Success: { success: boolean; }; }>;