import { ClientConfig } from "./interfaces/Config"; export declare class Client { private static instance; private token; private readonly apiKey; private readonly patToken; private readonly clientId; private readonly orgId; private expiresAt; private readonly domain; private readonly tokenDomain; private readonly isUserProvidedToken; private readonly clientSource; private constructor(); /** * Initializes and returns a Client instance with the provided configuration. * * @static * @param {ClientConfig} config - The client configuration object * @return {Promise} A promise that resolves when the client is initialized * @throws {Error} Throws an error if: * - custom "host" is provided without "authUrl" * - token is provided without "clientId" * - apiKey is provided without "clientId" or "orgId" * - patToken is provided without "clientId" or with "orgId" * * @example * // Initialize with authentication URL * await Client.getClient({ * host: 'https://api.example.com', * authUrl: 'https://auth.example.com', * clientId: 'client123', * orgId: 'org456' * }); * * // Initialize with existing token * await Client.getClient({ * token: 'existing-jwt-token', * clientId: 'client123' * }); * * // Initialize with API key * await Client.getClient({ * apiKey: 'your-api-key', * clientId: 'client123', * orgId: 'org456' * }); * * // Initialize with PAT token * await Client.getClient({ * patToken: 'your-personal-access-token', * clientId: 'client123' * }); */ static getClient(config: ClientConfig): Promise; /** * Returns the domain URL configured for the client. * * @return {string} The domain URL string * * @example * const client = Client.getInstance(); * const apiDomain = client.getDomain(); * console.log(apiDomain); // e.g., 'https://api.example.com' */ getDomain(): string; /** * Returns the singleton instance of the Client. * * @static * @return {Client} The singleton Client instance * @throws {Error} Throws an error if the Client has not been initialized with getClient() * * @example * // First initialize the client * await Client.getClient({ * clientId: 'client123', * orgId: 'org456' * }); * * // Then get the instance * const client = Client.getInstance(); * // Use the client... */ static getInstance(): Client; /** * Refreshes the authentication token if it's about to expire. * Only refreshes if the token was not provided by the user and is expiring within 60 seconds. * * @return {Promise} A promise that resolves when the token refresh is complete * * @example * const client = Client.getInstance(); * // Ensure token is fresh before making API requests * await client.refreshToken(); * // Proceed with API requests... */ refreshToken(): Promise; /** * Returns the authorization header object with the Bearer token. * * @return {Record} An object containing the Authorization header with the Bearer token * * @example * const client = Client.getInstance(); * const headers = { * 'Content-Type': 'application/json', * ...client.getAuthHeader() * }; * // headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer token...' } */ getAuthHeader(): Record; /** * Returns the client ID configured for this client instance. * * @return {string} The client ID string * * @example * const client = Client.getInstance(); * const clientId = client.getClientId(); * console.log(clientId); // e.g., 'client123' */ getClientId(): string; /** * Returns the client source identifier for this client instance. * * @return {string} The client source string * * @example * const client = Client.getInstance(); * const source = client.getClientSource(); * console.log(source); // e.g., 'web', 'mobile', 'sdk' */ getClientSource(): string; /** * Requests an authentication token from the token generation API. * * @private * @static * @param {ClientConfig} config - The client configuration containing authentication details * @return {Promise} A promise that resolves to the authentication token string * @throws {Error} Throws an error if the token response is empty * * @example * // Internal usage within the Client class * const token = await Client.requestToken({ * apiKey: 'your-api-key', * clientId: 'client123', * orgId: 'org456', * authUrl: 'https://custom-auth.example.com/token' * }); */ private static requestToken; /** * Requests an authentication token by exchanging a Personal Access Token (PAT). * * @private * @static * @param {ClientConfig} config - The client configuration containing PAT and client details * @return {Promise} A promise that resolves to the authentication token string * @throws {Error} Throws an error if the token response is empty * * @example * // Internal usage within the Client class * const token = await Client.requestTokenFromPAT({ * patToken: 'your-personal-access-token', * clientId: 'client123', * authUrl: 'https://custom-auth.example.com/exchange' * }); */ private static requestTokenFromPAT; }