import { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'; import { AdManager } from './code/ad-manager/ad-manager'; import { AffiliateManager } from './code/affiliate-manager/affiliate-manager'; import { AgentStudio } from './code/agent-studio/agent-studio'; import { Associations } from './code/associations/associations'; import { Blogs } from './code/blogs/blogs'; import { BrandBoards } from './code/brand-boards/brand-boards'; import { Businesses } from './code/businesses/businesses'; import { Calendars } from './code/calendars/calendars'; import { Campaigns } from './code/campaigns/campaigns'; import { ChatWidget } from './code/chat-widget/chat-widget'; import { Companies } from './code/companies/companies'; import { Contacts } from './code/contacts/contacts'; import { ConversationAi } from './code/conversation-ai/conversation-ai'; import { Conversations } from './code/conversations/conversations'; import { Courses } from './code/courses/courses'; import { CustomFields } from './code/custom-fields/custom-fields'; import { CustomMenus } from './code/custom-menus/custom-menus'; import { EmailIsv } from './code/email-isv/email-isv'; import { Emails } from './code/emails/emails'; import { Files } from './code/files/files'; import { Forms } from './code/forms/forms'; import { Funnels } from './code/funnels/funnels'; import { Invoices } from './code/invoices/invoices'; import { KnowledgeBase } from './code/knowledge-base/knowledge-base'; import { Links } from './code/links/links'; import { Locations } from './code/locations/locations'; import { Marketplace } from './code/marketplace/marketplace'; import { Medias } from './code/medias/medias'; import { Oauth } from './code/oauth/oauth'; import { Objects } from './code/objects/objects'; import { Opportunities } from './code/opportunities/opportunities'; import { Payments } from './code/payments/payments'; import { PhoneSystem } from './code/phone-system/phone-system'; import { Products } from './code/products/products'; import { Proposals } from './code/proposals/proposals'; import { SaasApi } from './code/saas-api/saas-api'; import { Snapshots } from './code/snapshots/snapshots'; import { SocialMediaPosting } from './code/social-media-posting/social-media-posting'; import { Store } from './code/store/store'; import { Surveys } from './code/surveys/surveys'; import { Users } from './code/users/users'; import { VoiceAi } from './code/voice-ai/voice-ai'; import { Workflows } from './code/workflows/workflows'; import { SessionStorage } from './storage'; import { LogLevelType } from './logging'; import { WebhookManager } from './webhook'; import { type TokenProvider } from './utils/request-utils'; declare module 'axios' { interface AxiosRequestConfig { __isRetryRequest?: boolean; __rateLimitAttempt?: number; __secutiryRequirements?: string[]; __preferredTokenType?: 'company' | 'location'; } } /** * Opt-in automatic retry of requests rejected by the burst rate limit (429). * The wait is the burst window reported in x-ratelimit-interval-milliseconds; * exponential backoff is used only when the response carries no rate limit * headers. A 429 caused by the daily limit is never retried. */ export interface RateLimitRetryConfig { /** Maximum number of retries after the first 429 (default 3) */ maxRetries?: number; /** Base delay for the exponential backoff fallback (default 1000 ms) */ baseDelayMs?: number; /** Upper bound for any single wait, including the reported burst window (default 30000 ms) */ maxDelayMs?: number; } export interface HighLevelConfig { apiVersion?: string; privateIntegrationToken?: string; agencyAccessToken?: string; locationAccessToken?: string; clientId?: string; clientSecret?: string; sessionStorage?: SessionStorage; logLevel?: LogLevelType; /** * Ed25519 public key used to verify webhook signatures (x-ghl-signature header). * Falls back to the WEBHOOK_SIGNATURE_PUBLIC_KEY environment variable. */ webhookPublicKey?: string; /** * Retry requests that fail with 429 Too Many Requests. Disabled by default; * pass `true` for the defaults or an object to tune them. */ rateLimitRetry?: boolean | RateLimitRetryConfig; /** * By default Authorization headers, tokens and secrets are redacted from debug * logs and from the request attached to errors. Set to `true` to log them as-is. */ logSensitiveData?: boolean; } export type ValidConfig = HighLevelConfig & ({ privateIntegrationToken: string; } | { clientId: string; clientSecret: string; }); export { GHLError } from './errors'; export interface RequestInterceptor { onFulfilled?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise; onRejected?: (error: any) => any; } export interface ResponseInterceptor { onFulfilled?: (response: AxiosResponse) => AxiosResponse | Promise; onRejected?: (error: any) => any; } /** HighLevel SDK Client */ export declare class HighLevel implements TokenProvider { private static readonly BASE_URL; private config; private httpClient; private sessionStorage; private logger; private refreshInFlight; private rejectedRefreshTokens; adManager: AdManager; affiliateManager: AffiliateManager; agentStudio: AgentStudio; associations: Associations; blogs: Blogs; brandBoards: BrandBoards; businesses: Businesses; calendars: Calendars; campaigns: Campaigns; chatWidget: ChatWidget; companies: Companies; contacts: Contacts; conversationAi: ConversationAi; conversations: Conversations; courses: Courses; customFields: CustomFields; customMenus: CustomMenus; emailIsv: EmailIsv; emails: Emails; files: Files; forms: Forms; funnels: Funnels; invoices: Invoices; knowledgeBase: KnowledgeBase; links: Links; locations: Locations; marketplace: Marketplace; medias: Medias; oauth: Oauth; objects: Objects; opportunities: Opportunities; payments: Payments; phoneSystem: PhoneSystem; products: Products; proposals: Proposals; saasApi: SaasApi; snapshots: Snapshots; socialMediaPosting: SocialMediaPosting; store: Store; surveys: Surveys; users: Users; voiceAi: VoiceAi; workflows: Workflows; webhooks: WebhookManager; constructor(config: ValidConfig); /** * Generate default headers for HTTP requests */ private getDefaultHeaders; /** * Get appropriate token for API requests (internal method) * @param resourceId - Optional resourceId (companyId or locationId) for storage-based token lookup * @returns Authorization header value or null */ getAuthToken(resourceId?: string): Promise; /** * Helper method to try getting token from storage * @param resourceId - Resource ID for token lookup * @returns Bearer token if found, null otherwise */ private fetchToken; /** * Check if a token should be refreshed based on expiration * @param sessionData - Session data containing expiration info * @returns True if token should be refreshed */ private shouldRefreshToken; /** * Check if the stored access token has expired (or expires within 30 seconds). * Expired when either expire_at or the token's own exp claim has passed; when neither is known the token is treated as expired. * @param sessionData - Session data containing the token and expiration info * @returns True if the token has expired or its expiry is unknown */ private isTokenExpired; /** * Read the expiry from the access token's exp claim (the token is decoded, not verified) * @param accessToken - Access token (JWT) * @returns Expiry in milliseconds since epoch, or null when the token is not a JWT with an exp claim */ private getTokenExpireAt; /** * Refresh token if expired and store the new token. * Concurrent calls for the same resource share a single refresh so a rotated * refresh token is never used twice. * @param resourceId - Resource ID for the session * @param sessionData - Current session data * @returns New Bearer token if successful, null otherwise */ private refreshTokenIfNeeded; private performTokenRefresh; /** * Call the refresh token API, retrying when no response arrived (network error, timeout) or the server * failed (5xx). A retry within 30 seconds of a refresh the server completed returns the same tokens. * @param refreshToken - Refresh token to exchange * @param userType - User type of the session * @returns Token response from the OAuth server */ private requestTokenRefresh; /** * Handle a refresh token the OAuth server rejected: try the company token fallback for a * location, otherwise throw, since only reconnecting the app issues a new refresh token * @param resourceId - Resource ID for the session * @param sessionData - Current session data * @param response - OAuth server error response, when the rejection just happened * @returns New Bearer token from the company token fallback */ private handleRejectedRefreshToken; /** * Handle location token refresh fallback using company token * @param locationId - The location ID that failed to refresh * @param locationSessionData - The location session data * @returns New Bearer token if successful, null otherwise */ private handleLocationTokenFallback; /** * Internal method to get token based on security requirements and request data * @param securityRequirements - Security requirements from OpenAPI spec * @param headers - Request headers * @param query - Query parameters * @param body - Request body * @param preferredTokenType - Preferred token type when both are available ('company' or 'location') * @returns Authorization header value or throws error */ getTokenForSecurity(securityRequirements: string[], headers?: any, query?: any, body?: any, preferredTokenType?: 'company' | 'location'): Promise; /** * Extract resourceId from request data based on security requirements * @param securityRequirements - Security requirements to determine token type * @param headers - Request headers * @param query - Query parameters * @param body - Request body * @param preferredTokenType - Preferred token type when both are available ('company' or 'location') * @returns Extracted resourceId (companyId or locationId) */ extractResourceId(securityRequirements: string[], headers?: any, query?: any, body?: any, preferredTokenType?: 'company' | 'location'): string | null; /** * Setup default request and response interceptors */ private setupDefaultInterceptors; /** * Handle response errors with proper error formatting */ private handleResponseError; /** * Redact credentials unless the user opted into logging sensitive data */ private redact; /** * Copy of the request config with credentials redacted (unless logSensitiveData is set), safe to attach to errors and logs */ private sanitizeRequestConfig; /** * Effective rate-limit retry policy, or null when retries are disabled */ private getRateLimitRetryPolicy; /** * Delay before the next retry: the burst window reported by the API when present, * otherwise exponential backoff with jitter */ private getRateLimitRetryDelay; private sleep; /** * Extract meaningful error message from API response */ private extractErrorMessage; /** * Initialize all service instances with the shared HTTP client */ private initializeServices; /** * Update session storage logger to match the main logger level */ private updateSessionStorageLogger; /** * Initialize session storage (always exists now - either provided or auto-created) */ private initializeSessionStorage; /** * Get the session storage instance (always available) */ getSessionStorage(): SessionStorage; /** * Set or update the session storage instance */ setSessionStorage(sessionStorage: SessionStorage): void; /** * Disconnect session storage */ disconnectSessionStorage(): Promise; /** * Update configuration and refresh all services */ updateConfig(newConfig: Partial): void; /** * Set or update the private integration token (used without Bearer prefix) */ setPrivateIntegrationToken(token: string): void; /** * Get current private integration token */ getPrivateIntegrationToken(): string | undefined; /** * Get current temporary agency access token (read-only, set during initialization) */ getAgencyAccessToken(): string | undefined; /** * Get current temporary location access token (read-only, set during initialization) */ getLocationAccessToken(): string | undefined; /** * Set client ID for OAuth operations and update session storage */ setClientId(clientId: string): void; /** * Get current client ID */ getClientId(): string | undefined; /** * Set client secret for OAuth operations */ setClientSecret(clientSecret: string): void; /** * Get current client secret */ getClientSecret(): string | undefined; /** * Set API version */ setApiVersion(version: string): void; /** * Get current configuration */ getConfig(): HighLevelConfig; /** * Get current default headers */ getHeaders(): Record; /** * Add custom request interceptor */ addRequestInterceptor(interceptor: RequestInterceptor): number; /** * Add custom response interceptor */ addResponseInterceptor(interceptor: ResponseInterceptor): number; /** * Remove request interceptor by ID */ removeRequestInterceptor(interceptorId: number): void; /** * Remove response interceptor by ID */ removeResponseInterceptor(interceptorId: number): void; /** * Get the underlying HTTP client (for advanced usage) */ getHttpClient(): AxiosInstance; /** * Make a raw HTTP request using the configured client */ request(config: AxiosRequestConfig): Promise>; /** * Health check method to test connectivity */ healthCheck(): Promise; } export default HighLevel; //# sourceMappingURL=HighLevel.d.ts.map