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<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[]>;
    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<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, 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>>;
    getConnectionForPrivateApi({ connectionId, providerConfigKey, environmentId }: {
        connectionId: string;
        providerConfigKey: string;
        environmentId: number;
    }): Promise<Result<{
        connection: Connection;
        end_user: DBEndUser;
    }>>;
    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>;
    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<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>;
    findConnectionsByMetadataValue({ metadataProperty, payloadIdentifier, configId, environmentId }: {
        metadataProperty: string;
        payloadIdentifier: string;
        configId: number | undefined;
        environmentId: number;
    }): Promise<Connection[] | null>;
    findConnectionsByMultipleConnectionConfigValues(keyValuePairs: KeyValuePairs, environmentId: number): Promise<Connection[] | null>;
    count({ environmentId }: {
        environmentId: number;
    }): Promise<Result<{
        total: number;
        withAuthError: number;
        withSyncError: number;
        withError: number;
    }>>;
    /**
     * 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, limit, page }: {
        environmentId: number;
        connectionId?: string | undefined;
        integrationIds?: string[] | undefined;
        withError?: boolean | undefined;
        search?: 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<void>;
    }): Promise<number>;
    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<void>;
        onRefreshFailed: (args: {
            connection: Connection;
            logCtx: LogContext;
            authError: {
                type: string;
                description: string;
            };
            environment: DBEnvironment;
            provider: Provider;
            config: ProviderConfig;
            action: 'token_refresh' | 'connection_test';
        }) => Promise<void>;
        connectionTestHook?: ((args: {
            config: Config;
            provider: Provider;
            credentials: ApiKeyCredentials | BasicApiCredentials | TbaCredentials | JwtCredentials | SignatureCredentials;
            connectionId: string;
            connectionConfig: ConnectionConfig;
        }) => Promise<Result<{
            logs: MessageRowInsert[];
        }, NangoError>>) | undefined;
    }): Promise<Result<Connection, NangoError>>;
    updateLastFetched(id: number): Promise<void>;
    parseRawCredentials(rawCredentials: object, authMode: AuthModeType, template?: ProviderOAuth2 | ProviderTwoStep): 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>>;
    getJwtCredentials(provider: ProviderJwt, privateKey: {
        id: string;
        secret: string;
    } | string, privateKeyId?: string, issuerId?: string): ServiceResponse<JwtCredentials>;
    private generateJWT;
    getBillCredentials(provider: Provider, username: string, password: string, organizationId: string, devKey: string): Promise<ServiceResponse<BillCredentials>>;
    getTwoStepCredentials(provider: ProviderTwoStep, dynamicCredentials: Record<string, any>, connectionConfig: Record<string, string>): Promise<ServiceResponse<TwoStepCredentials>>;
    getSignatureCredentials(provider: ProviderSignature, username: string, password: string): ServiceResponse<SignatureCredentials>;
    shouldCapUsage({ providerConfigKey, environmentId, type }: {
        providerConfigKey: string;
        environmentId: number;
        type: 'activate' | 'deploy';
    }): Promise<boolean>;
    private formatAndGetJWTCredentials;
    private shouldRefreshCredentials;
    private getNewCredentials;
}
declare const _default: ConnectionService;
export default _default;
