import type { Knex } from 'knex';
import type { TemplateOAuth2 as ProviderTemplateOAuth2, Template as ProviderTemplate, Config as ProviderConfig, AuthCredentials, LogAction } from '../models/index.js';
import type { ConnectionConfig, Connection, NangoConnection } from '../models/Connection.js';
import type { Metadata } from '@nangohq/types';
import type { ServiceResponse } from '../models/Generic.js';
import type { AppCredentials, AppStoreCredentials, OAuth2Credentials, OAuth2ClientCredentials, ImportedCredentials, ApiKeyCredentials, BasicApiCredentials, ConnectionUpsertResponse } from '../models/Auth.js';
import { AuthModes as ProviderAuthModes } from '../models/Auth.js';
import { Locking } from '../utils/lock/locking.js';
import type { LogContext, LogContextGetter } from '@nangohq/logs';
type KeyValuePairs = Record<string, string | boolean>;
declare class ConnectionService {
    private locking;
    constructor(locking: Locking);
    upsertConnection(connectionId: string, providerConfigKey: string, provider: string, parsedRawCredentials: AuthCredentials, connectionConfig: Record<string, string | boolean>, environment_id: number, accountId: number, metadata?: Metadata): Promise<ConnectionUpsertResponse[]>;
    upsertApiConnection(connectionId: string, providerConfigKey: string, provider: string, credentials: ApiKeyCredentials | BasicApiCredentials, connectionConfig: Record<string, string>, environment_id: number, accountId: number): Promise<ConnectionUpsertResponse[]>;
    upsertUnauthConnection(connectionId: string, providerConfigKey: string, provider: string, environment_id: number, accountId: number): Promise<ConnectionUpsertResponse[]>;
    importOAuthConnection(connection_id: string, provider_config_key: string, provider: string, environmentId: number, accountId: number, parsedRawCredentials: ImportedCredentials, logContextGetter: LogContextGetter): Promise<(ConnectionUpsertResponse | undefined)[]>;
    importApiAuthConnection(connection_id: string, provider_config_key: string, provider: string, environmentId: number, accountId: number, credentials: BasicApiCredentials | ApiKeyCredentials, logContextGetter: LogContextGetter): 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 | {
        id: number;
        metadata: Metadata;
    }>;
    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: Connection): Promise<ConnectionConfig>;
    getConnectionsByEnvironmentAndConfig(environment_id: number, providerConfigKey: string): Promise<NangoConnection[]>;
    getOldConnections({ days, limit }: {
        days: number;
        limit: number;
    }): Promise<(NangoConnection & {
        account_id: number;
    })[]>;
    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;
    }[]>;
    getAllNames(environment_id: number): Promise<string[]>;
    deleteConnection(connection: Connection, providerConfigKey: string, environment_id: number): Promise<number>;
    getConnectionCredentials(accountId: number, environmentId: number, connectionId: string, providerConfigKey: string, logContextGetter: LogContextGetter, activityLogId?: number | null | undefined, logCtx?: LogContext, action?: LogAction, instantRefresh?: boolean): Promise<ServiceResponse<Connection>>;
    updateLastFetched(id: number): Promise<void>;
    parseRawCredentials(rawCredentials: object, authMode: ProviderAuthModes): AuthCredentials;
    refreshCredentialsIfNeeded({ connection, providerConfig, template, activityLogId, environment_id, instantRefresh, logAction, logContextGetter }: {
        connection: Connection;
        providerConfig: ProviderConfig;
        template: ProviderTemplateOAuth2;
        activityLogId: number | null | undefined;
        environment_id: number;
        instantRefresh?: boolean;
        logAction?: LogAction | undefined;
        logContextGetter: LogContextGetter;
    }): Promise<ServiceResponse<OAuth2Credentials | AppCredentials | AppStoreCredentials | OAuth2ClientCredentials>>;
    getAppStoreCredentials(template: ProviderTemplate, connectionConfig: Connection['connection_config'], privateKey: string): Promise<ServiceResponse<AppStoreCredentials>>;
    getAppCredentialsAndFinishConnection(connectionId: string, integration: ProviderConfig, template: ProviderTemplate, connectionConfig: ConnectionConfig, activityLogId: number, logCtx: LogContext, logContextGetter: LogContextGetter): Promise<void>;
    getAppCredentials(template: ProviderTemplate, config: ProviderConfig, connectionConfig: Connection['connection_config']): Promise<ServiceResponse<AppCredentials>>;
    getOauthClientCredentials(template: ProviderTemplate, client_id: string, client_secret: string): Promise<ServiceResponse<OAuth2ClientCredentials>>;
    shouldCapUsage({ providerConfigKey, environmentId, type }: {
        providerConfigKey: string;
        environmentId: number;
        type: 'activate' | 'deploy';
    }): Promise<boolean>;
    private getJWTCredentials;
    private shouldRefreshCredentials;
    private getNewCredentials;
    private logErrorActivity;
}
declare const _default: ConnectionService;
export default _default;
