import { FeatureKey } from '../../../common/features';
import { KyselyTransaction } from "../../../database/types/kysely.types";
export type IntegrationCapability = 'oauth' | 'unfurl' | 'actions';
export type IdentityOAuthConfig = {
    authUrl: string;
    tokenUrl: string;
    scopes: string[];
    authParams?: Record<string, string>;
};
export type OAuthConfig = {
    authUrl: string;
    tokenUrl: string;
    scopes: string[];
    connectionScope?: 'workspace' | 'user';
    credentialsKey?: string;
    scopeOnRefresh?: boolean;
    authParams?: Record<string, string>;
    refreshUrl?: string;
    clientAuth?: 'basic';
    identity?: IdentityOAuthConfig;
};
export type ProviderAccount = {
    id: string;
    displayName?: string;
    username?: string;
};
export type IdentityLinkEvent = {
    integrationId: string;
    workspaceId: string;
    userId: string;
    tokenResponse: Record<string, any>;
    settings: Record<string, any>;
};
export type ResolvedIdentity = {
    account: ProviderAccount;
    email?: string;
    metadata?: Record<string, unknown>;
};
export type ResolveAccountOpts = {
    accessToken: string;
    tokenResponse: Record<string, any>;
};
export declare class IdentityEmailMismatchError extends Error {
    constructor(message?: string);
}
export declare class IdentityTenantMismatchError extends Error {
    constructor(message?: string);
}
export declare class IntegrationTenantInUseError extends Error {
    constructor(message?: string);
}
export type UnfurlPattern = {
    regex: RegExp;
    type: string;
};
export type UnfurlResult = {
    title: string;
    description?: string;
    url: string;
    provider: string;
    providerIcon?: string;
    status?: string;
    statusColor?: string;
    author?: string;
    authorAvatarUrl?: string;
    metadata?: Record<string, any>;
};
export type IntegrationDefinition = {
    type: string;
    name: string;
    description: string;
    icon: string;
    capabilities: IntegrationCapability[];
    oauth?: OAuthConfig;
    unfurlPatterns?: UnfurlPattern[];
    hidden?: boolean;
    requiresFeature?: FeatureKey;
};
export type ConnectedEvent = {
    integrationId: string;
    workspaceId: string;
    accessToken: string;
    refreshToken?: string;
    userId: string;
    metadata: Record<string, any>;
    account?: ProviderAccount;
    trx?: KyselyTransaction;
};
export type UnfurlOpts = {
    url: string;
    accessToken: string;
    match: RegExpMatchArray;
    patternType: string;
    settings?: Record<string, any>;
    userId: string;
    integrationId: string;
};
export type PublicUnfurlOpts = Pick<UnfurlOpts, 'url' | 'match' | 'patternType'>;
export declare class UnfurlForbiddenError extends Error {
    constructor(message?: string);
}
export declare class UnfurlNeedsConnectionError extends Error {
    constructor(message?: string);
}
export declare class TokenInvalidError extends Error {
    constructor(message?: string);
}
export declare class TokenExpiredError extends Error {
    constructor(message?: string);
}
export declare class ProviderApiError extends Error {
    readonly provider: string;
    readonly status: number;
    readonly retryAfterSeconds?: number;
    constructor(provider: string, status: number, statusText?: string, retryAfterSeconds?: number);
}
export type LinkDescription = {
    title: string;
    description?: string;
};
export type UnfurlNeedsConnection = {
    needsConnection: true;
    integrationId: string;
    integrationType: string;
    integrationName: string;
    title: string;
    description?: string;
};
export declare abstract class IntegrationProvider {
    abstract definition: IntegrationDefinition;
    getOAuthConfig?(workspaceSettings: Record<string, any>): OAuthConfig;
    getUnfurlPatterns?(workspaceSettings: Record<string, any>): UnfurlPattern[];
    getUnfurlHosts?(workspaceSettings: Record<string, any>): string[];
    onConnected?(opts: ConnectedEvent): Promise<void>;
    resolveIdentity?(opts: IdentityLinkEvent): Promise<ResolvedIdentity>;
    resolveAccount?(opts: ResolveAccountOpts): Promise<ProviderAccount>;
    unfurl?(opts: UnfurlOpts): Promise<UnfurlResult>;
    unfurlPublic?(opts: PublicUnfurlOpts): Promise<UnfurlResult>;
    describeLink?(patternType: string, match: RegExpMatchArray, url: string): LinkDescription | null;
}
