import type { Knex } from '@nangohq/database'; import type { Config as ProviderConfig, AuthCredentials, OAuth1Credentials, Config } from '../models/index.js'; import { NangoError } from '../utils/error.js'; import type { ConnectionConfig, Connection, StoredConnection, NangoConnection } from '../models/Connection.js'; import type { Metadata, Provider, ProviderJwt, ProviderOAuth2, AuthModeType, TbaCredentials, TableauCredentials, MaybePromise, DBTeam, DBEnvironment, JwtCredentials, BillCredentials, IntegrationConfig, DBConnection, DBEndUser, TwoStepCredentials, ProviderTwoStep, ProviderSignature, SignatureCredentials, MessageRowInsert } from '@nangohq/types'; import type { Result } from '@nangohq/utils'; import type { ServiceResponse } from '../models/Generic.js'; import type { AppCredentials, AppStoreCredentials, OAuth2Credentials, OAuth2ClientCredentials, ApiKeyCredentials, BasicApiCredentials, ConnectionUpsertResponse } from '../models/Auth.js'; import type { LogContext, LogContextGetter } from '@nangohq/logs'; import type { Orchestrator } from '../clients/orchestrator.js'; import type { Locking } from '../utils/lock/locking.js'; type KeyValuePairs = Record; declare class ConnectionService { private locking; constructor(locking: Locking); generateConnectionId(): string; upsertConnection({ connectionId, providerConfigKey, provider, parsedRawCredentials, connectionConfig, environmentId, accountId, metadata }: { connectionId: string; providerConfigKey: string; provider: string; parsedRawCredentials: AuthCredentials; connectionConfig?: ConnectionConfig; environmentId: number; accountId: number; metadata?: Metadata | null; }): Promise; upsertAuthConnection({ connectionId, providerConfigKey, credentials, connectionConfig, metadata, config, environment, account }: { connectionId: string; providerConfigKey: string; credentials: TwoStepCredentials | TableauCredentials | TbaCredentials | JwtCredentials | ApiKeyCredentials | BasicApiCredentials | BillCredentials | SignatureCredentials; connectionConfig?: ConnectionConfig; config: ProviderConfig; metadata?: Metadata | null; environment: DBEnvironment; account: DBTeam; }): Promise; upsertUnauthConnection({ connectionId, providerConfigKey, provider, metadata, connectionConfig, environment, account }: { connectionId: string; providerConfigKey: string; provider: string; metadata?: Metadata | null; connectionConfig?: ConnectionConfig; environment: DBEnvironment; account: DBTeam; }): Promise; importOAuthConnection({ connectionId, providerConfigKey, provider, environment, account, metadata, connectionConfig, parsedRawCredentials, connectionCreatedHook }: { connectionId: string; providerConfigKey: string; provider: string; environment: DBEnvironment; account: DBTeam; metadata?: Metadata | null; connectionConfig?: ConnectionConfig; parsedRawCredentials: OAuth2Credentials | OAuth1Credentials | OAuth2ClientCredentials; connectionCreatedHook: (res: ConnectionUpsertResponse) => MaybePromise; }): Promise<(ConnectionUpsertResponse | undefined)[]>; importApiAuthConnection({ connectionId, providerConfigKey, metadata, environment, account, connectionConfig, credentials, connectionCreatedHook }: { connectionId: string; providerConfigKey: string; provider: string; environment: DBEnvironment; account: DBTeam; metadata?: Metadata | null; connectionConfig?: ConnectionConfig; credentials: BasicApiCredentials | ApiKeyCredentials; connectionCreatedHook: (res: ConnectionUpsertResponse) => MaybePromise; }): Promise<(ConnectionUpsertResponse | undefined)[]>; getConnectionById(id: number): Promise | null>; checkIfConnectionExists(connection_id: string, provider_config_key: string, environment_id: number): Promise; getConnection(connectionId: string, providerConfigKey: string, environment_id: number): Promise>; getConnectionForPrivateApi({ connectionId, providerConfigKey, environmentId }: { connectionId: string; providerConfigKey: string; environmentId: number; }): Promise>; updateConnection(connection: Connection): Promise; getMetadata(connection: Connection): Promise>; getConnectionConfig(connection: Pick): Promise; countConnections({ environmentId, providerConfigKey }: { environmentId: number; providerConfigKey: string; }): Promise; getConnectionsByEnvironmentAndConfig(environment_id: number, providerConfigKey: string): Promise; getConnectionsByEnvironmentAndConfigId(environment_id: number, config_id: number): Promise; copyConnections(connections: StoredConnection[], environment_id: number, config_id: number): Promise; getStaleConnections({ days, limit, cursor }: { days: number; limit: number; cursor?: number | undefined; }): Promise<{ connection: Connection; account: DBTeam; environment: DBEnvironment; cursor: number; integration: ProviderConfig; }[]>; replaceMetadata(ids: number[], metadata: Metadata, trx: Knex.Transaction): Promise; replaceConnectionConfig(connection: Connection, config: ConnectionConfig): Promise; updateMetadata(connections: Connection[], metadata: Metadata): Promise; updateConnectionConfig(connection: Connection, config: ConnectionConfig): Promise; findConnectionsByConnectionConfigValue(key: string, value: string, environmentId: number): Promise; findConnectionsByMetadataValue({ metadataProperty, payloadIdentifier, configId, environmentId }: { metadataProperty: string; payloadIdentifier: string; configId: number | undefined; environmentId: number; }): Promise; findConnectionsByMultipleConnectionConfigValues(keyValuePairs: KeyValuePairs, environmentId: number): Promise; count({ environmentId }: { environmentId: number; }): Promise>; /** * List connections with associated data (active_logs, end_users) and pagination * If you want the raw list, use something else */ listConnections({ environmentId, connectionId, integrationIds, withError, search, endUserId, endUserOrganizationId, limit, page }: { environmentId: number; connectionId?: string | undefined; integrationIds?: string[] | undefined; withError?: boolean | undefined; search?: string | undefined; endUserId?: string | undefined; endUserOrganizationId?: string | undefined; limit?: number; page?: number | undefined; }): Promise<{ connection: DBConnection; end_user: DBEndUser | null; active_logs: [{ type: string; log_id: string; }]; provider: string; }[]>; deleteConnection({ connection, providerConfigKey, environmentId, orchestrator, logContextGetter, preDeletionHook }: { connection: Connection; providerConfigKey: string; environmentId: number; orchestrator: Orchestrator; logContextGetter: LogContextGetter; preDeletionHook: () => Promise; }): Promise; refreshOrTestCredentials({ account, environment, connection, integration, logContextGetter, instantRefresh, onRefreshSuccess, onRefreshFailed, connectionTestHook }: { account: DBTeam; environment: DBEnvironment; connection: Connection; integration: IntegrationConfig; logContextGetter: LogContextGetter; instantRefresh: boolean; onRefreshSuccess: (args: { connection: Connection; environment: DBEnvironment; config: ProviderConfig; }) => Promise; onRefreshFailed: (args: { connection: Connection; logCtx: LogContext; authError: { type: string; description: string; }; environment: DBEnvironment; provider: Provider; config: ProviderConfig; action: 'token_refresh' | 'connection_test'; }) => Promise; connectionTestHook?: ((args: { config: Config; provider: Provider; credentials: ApiKeyCredentials | BasicApiCredentials | TbaCredentials | JwtCredentials | SignatureCredentials; connectionId: string; connectionConfig: ConnectionConfig; }) => Promise>) | undefined; }): Promise>; updateLastFetched(id: number): Promise; parseRawCredentials(rawCredentials: object, authMode: AuthModeType, template?: ProviderOAuth2 | ProviderTwoStep): AuthCredentials; private refreshCredentialsIfNeeded; getAppStoreCredentials(provider: Provider, connectionConfig: Connection['connection_config'], privateKey: string): Promise>; getAppCredentialsAndFinishConnection(connectionId: string, integration: ProviderConfig, provider: Provider, connectionConfig: ConnectionConfig, logCtx: LogContext, connectionCreatedHook: (res: ConnectionUpsertResponse) => MaybePromise): Promise; getAppCredentials(provider: Provider, config: ProviderConfig, connectionConfig: Connection['connection_config']): Promise>; getOauthClientCredentials(provider: ProviderOAuth2, client_id: string, client_secret: string, connectionConfig: Record): Promise>; getTableauCredentials(provider: Provider, patName: string, patSecret: string, connectionConfig: Record, contentUrl?: string): Promise>; getJwtCredentials(provider: ProviderJwt, privateKey: { id: string; secret: string; } | string, privateKeyId?: string, issuerId?: string): ServiceResponse; private generateJWT; getBillCredentials(provider: Provider, username: string, password: string, organizationId: string, devKey: string): Promise>; getTwoStepCredentials(provider: ProviderTwoStep, dynamicCredentials: Record, connectionConfig: Record): Promise>; getSignatureCredentials(provider: ProviderSignature, username: string, password: string): ServiceResponse; shouldCapUsage({ providerConfigKey, environmentId, type }: { providerConfigKey: string; environmentId: number; type: 'activate' | 'deploy'; }): Promise; private formatAndGetJWTCredentials; private shouldRefreshCredentials; private getNewCredentials; } declare const _default: ConnectionService; export default _default;