import type { Knex } from '@nangohq/database';
import type { Config as ProviderConfig, AuthCredentials, OAuth1Credentials } from '../models/index.js';
import { NangoError } from '../utils/error.js';
import type { ConnectionConfig, Connection, StoredConnection, NangoConnection } from '../models/Connection.js';
import type { Metadata, ActiveLogIds, Provider, ProviderOAuth2, AuthModeType, TbaCredentials, TableauCredentials, MaybePromise, DBTeam, DBEnvironment } 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 { Locking } from '../utils/lock/locking.js';
import type { LogContext, LogContextGetter } from '@nangohq/logs';
import type { Orchestrator } from '../clients/orchestrator.js';
type KeyValuePairs = Record<string, string | boolean>;
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<ConnectionUpsertResponse[]>;
    upsertTbaConnection({ connectionId, providerConfigKey, credentials, connectionConfig, metadata, config, environment, account }: {
        connectionId: string;
        providerConfigKey: string;
        credentials: TbaCredentials;
        connectionConfig?: ConnectionConfig;
        config: ProviderConfig;
        metadata?: Metadata | null;
        environment: DBEnvironment;
        account: DBTeam;
    }): Promise<ConnectionUpsertResponse[]>;
    upsertTableauConnection({ connectionId, providerConfigKey, credentials, connectionConfig, metadata, config, environment, account }: {
        connectionId: string;
        providerConfigKey: string;
        credentials: TableauCredentials;
        connectionConfig?: ConnectionConfig;
        config: ProviderConfig;
        metadata?: Metadata | null;
        environment: DBEnvironment;
        account: DBTeam;
    }): Promise<ConnectionUpsertResponse[]>;
    upsertApiConnection({ connectionId, providerConfigKey, provider, credentials, connectionConfig, metadata, environment, account }: {
        connectionId: string;
        providerConfigKey: string;
        provider: string;
        credentials: ApiKeyCredentials | BasicApiCredentials;
        connectionConfig?: ConnectionConfig;
        metadata?: Metadata | null;
        environment: DBEnvironment;
        account: DBTeam;
    }): Promise<ConnectionUpsertResponse[]>;
    upsertUnauthConnection({ connectionId, providerConfigKey, provider, metadata, connectionConfig, environment, account }: {
        connectionId: string;
        providerConfigKey: string;
        provider: string;
        metadata?: Metadata | null;
        connectionConfig?: ConnectionConfig;
        environment: DBEnvironment;
        account: DBTeam;
    }): Promise<ConnectionUpsertResponse[]>;
    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<void>;
    }): Promise<(ConnectionUpsertResponse | undefined)[]>;
    importApiAuthConnection({ connectionId, providerConfigKey, provider, 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<void>;
    }): Promise<(ConnectionUpsertResponse | undefined)[]>;
    getConnectionById(id: number): Promise<Pick<Connection, 'id' | 'connection_id' | 'provider_config_key' | 'environment_id' | 'connection_config' | 'metadata'> | null>;
    checkIfConnectionExists(connection_id: string, provider_config_key: string, environment_id: number): Promise<null | StoredConnection>;
    getConnection(connectionId: string, providerConfigKey: string, environment_id: number): Promise<ServiceResponse<Connection>>;
    updateConnection(connection: Connection): Promise<void>;
    getMetadata(connection: Connection): Promise<Record<string, string>>;
    getConnectionConfig(connection: Pick<Connection, 'connection_id' | 'provider_config_key' | 'environment_id'>): Promise<ConnectionConfig>;
    countConnections({ environmentId, providerConfigKey }: {
        environmentId: number;
        providerConfigKey: string;
    }): Promise<number>;
    getConnectionsByEnvironmentAndConfig(environment_id: number, providerConfigKey: string): Promise<NangoConnection[]>;
    getConnectionsByEnvironmentAndConfigId(environment_id: number, config_id: number): Promise<StoredConnection[]>;
    copyConnections(connections: StoredConnection[], environment_id: number, config_id: number): Promise<void>;
    getOldConnections({ days, limit }: {
        days: number;
        limit: number;
    }): Promise<{
        connection_id: string;
        provider_config_key: string;
        account: DBTeam;
        environment: DBEnvironment;
    }[]>;
    replaceMetadata(ids: number[], metadata: Metadata, trx: Knex.Transaction): Promise<void>;
    replaceConnectionConfig(connection: Connection, config: ConnectionConfig): Promise<void>;
    updateMetadata(connections: Connection[], metadata: Metadata): Promise<void>;
    updateConnectionConfig(connection: Connection, config: ConnectionConfig): Promise<ConnectionConfig>;
    findConnectionsByConnectionConfigValue(key: string, value: string, environmentId: number): Promise<Connection[] | null>;
    findConnectionsByMultipleConnectionConfigValues(keyValuePairs: KeyValuePairs, environmentId: number): Promise<Connection[] | null>;
    listConnections(environment_id: number, connectionId?: string): Promise<{
        id: number;
        connection_id: string;
        provider: string;
        created: string;
        metadata: Metadata;
        active_logs: ActiveLogIds;
    }[]>;
    getAllNames(environment_id: number): Promise<string[]>;
    deleteConnection({ connection, providerConfigKey, environmentId, orchestrator, logContextGetter }: {
        connection: Connection;
        providerConfigKey: string;
        environmentId: number;
        orchestrator: Orchestrator;
        logContextGetter: LogContextGetter;
    }): Promise<number>;
    getConnectionCredentials({ account, environment, connectionId, providerConfigKey, logContextGetter, instantRefresh, onRefreshSuccess, onRefreshFailed }: {
        account: DBTeam;
        environment: DBEnvironment;
        connectionId: string;
        providerConfigKey: string;
        logContextGetter: LogContextGetter;
        instantRefresh: boolean;
        onRefreshSuccess: (args: {
            connection: Connection;
            environment: DBEnvironment;
            config: ProviderConfig;
        }) => Promise<void>;
        onRefreshFailed: (args: {
            connection: Connection;
            logCtx: LogContext;
            authError: {
                type: string;
                description: string;
            };
            environment: DBEnvironment;
            provider: Provider;
            config: ProviderConfig;
        }) => Promise<void>;
    }): Promise<Result<Connection, NangoError>>;
    updateLastFetched(id: number): Promise<void>;
    parseRawCredentials(rawCredentials: object, authMode: AuthModeType, template?: ProviderOAuth2): AuthCredentials;
    private refreshCredentialsIfNeeded;
    getAppStoreCredentials(provider: Provider, connectionConfig: Connection['connection_config'], privateKey: string): Promise<ServiceResponse<AppStoreCredentials>>;
    getAppCredentialsAndFinishConnection(connectionId: string, integration: ProviderConfig, provider: Provider, connectionConfig: ConnectionConfig, logCtx: LogContext, connectionCreatedHook: (res: ConnectionUpsertResponse) => MaybePromise<void>): Promise<void>;
    getAppCredentials(provider: Provider, config: ProviderConfig, connectionConfig: Connection['connection_config']): Promise<ServiceResponse<AppCredentials>>;
    getOauthClientCredentials(provider: ProviderOAuth2, client_id: string, client_secret: string, connectionConfig: Record<string, string>): Promise<ServiceResponse<OAuth2ClientCredentials>>;
    getTableauCredentials(provider: Provider, patName: string, patSecret: string, connectionConfig: Record<string, string>, contentUrl?: string): Promise<ServiceResponse<TableauCredentials>>;
    shouldCapUsage({ providerConfigKey, environmentId, type }: {
        providerConfigKey: string;
        environmentId: number;
        type: 'activate' | 'deploy';
    }): Promise<boolean>;
    private getJWTCredentials;
    private shouldRefreshCredentials;
    private getNewCredentials;
}
declare const _default: ConnectionService;
export default _default;
