import type { CcClientConfig } from '../types/client.types.js'; import type { Command } from '../types/command.types.js'; import type { CcRequest, CcRequestConfigPartial, CcRequestParams, CcResponse } from '../types/request.types.js'; import type { CcAuth } from './auth/cc-auth.js'; import { CompositeCommand, type SimpleCommand } from './command/command.js'; import type { GetUrl } from './get-url.js'; import type { CcStream } from './stream/cc-stream.js'; import type { CcStreamConfigPartial } from './stream/cc-stream.types.js'; import type { StreamCommand } from './stream/stream-command.js'; /** * CcClient is the main client class for interacting with the Clever Cloud API. * It handles HTTP requests, authentication, response processing, and real-time streaming. * * @template Api - The API type this client targets (e.g., 'cc-api', 'cc-api-bridge') * * @description * The CcClient class provides methods to: * - Send commands to the API (both simple and composite) * - Create and manage real-time streams (Server-Sent Events) * - Handle request/response lifecycle * - Manage authentication * - Transform request parameters and responses * - Handle errors * * @example * ```typescript * // Create client configuration * const config = { * baseUrl: 'https://api.clever-cloud.com', * defaultRequestConfig: { timeout: 5000 }, * defaultStreamsConfig: { * retry: { maxRetryCount: 5, initRetryTimeout: 1000, backoffFactor: 1.25 }, * heartbeatPeriod: 2000, * healthcheckInterval: 1000 * } * }; * * // Initialize authentication and client * // (CcAuth, SimpleCommand and StreamCommand are abstract: use concrete subclasses) * const auth = new CcAuthApiToken('your-api-token'); * const client = new CcClient(config, auth); * * // Send a command * const command = new GetApplicationCommand({ applicationId: 'app_123' }); * const result = await client.send(command); * * // Create a stream for real-time data * const streamCommand = new GetApplicationLogsCommand({ applicationId: 'app_123' }); * const stream = await client.stream(streamCommand); * stream.onLog(log => console.log('Received log:', log)); * await stream.start(); * ``` */ export declare class CcClient { #private; /** * Creates a new CcClient instance * * @param config - Client configuration including baseUrl and default request settings * @param auth - Optional authentication handler */ constructor(config: CcClientConfig, auth?: CcAuth); /** * Sends a command to the API and processes the response * * @param command - The command to execute * @param requestConfig - Optional request configuration that overrides the default * @returns The processed command response * @throws {CcClientError} When there's a client-side error * @throws {CcHttpError} When there's a server-side error */ send(command: Command, requestConfig?: CcRequestConfigPartial): Promise; /** * Gets the signal the requests sent with the given configuration abort with: the signal of that * configuration, or else the default signal of the client. * * @param requestConfig - The request configuration a command is sent with * @returns The signal, if any */ protected _getRequestSignal(requestConfig: CcRequestConfigPartial | undefined): AbortSignal | undefined; /** * Sends a command, under the idempotency ceiling of whatever encloses it. * * Every command goes through here, including the ones a composite command sends through its composer. * * @param command - The command to execute * @param requestConfig - Request configuration that overrides the default * @param isIdempotentCeiling - Whether what encloses this command can be replayed at all * @returns The processed command response */ protected _send(command: Command, requestConfig: CcRequestConfigPartial | undefined, isIdempotentCeiling: boolean): Promise; /** * Constructs a complete URL for an API endpoint * * @param getUrl - URL generator with parameters * @returns The complete URL with base URL and authentication parameters */ getUrl(getUrl: GetUrl): URL; /** * Creates and returns a stream based on the provided command. * * @param command - The stream command to execute * @param requestAndStreamConfig - Optional stream and request configuration that overrides the default * @returns A promise that resolves to the created stream */ stream(command: StreamCommand, requestAndStreamConfig?: CcStreamConfigPartial & CcRequestConfigPartial): Promise; /** * Transforms command parameters before sending the request * * @param command - The command whose parameters need transformation * @param _requestConfig - Optional request configuration * @returns The transformed parameters */ protected _transformCommandParams(command: Command, _requestConfig?: CcRequestConfigPartial): Promise; /** * Transforms stream command parameters before creating the stream * * @param command - The stream command whose parameters need transformation * @param _requestConfig - Optional request configuration * @returns The transformed parameters */ protected _transformStreamParams(command: StreamCommand, _requestConfig?: CcRequestConfigPartial): Promise; /** * Handles execution of composite commands that consist of multiple sub-commands * * @param command - The composite command to execute * @param requestConfig - Request configuration that overrides the default * @param isIdempotentCeiling - Whether what encloses this composite command can be replayed at all * @returns The result of executing all sub-commands */ protected _compose(command: CompositeCommand, requestConfig: CcRequestConfigPartial | undefined, isIdempotentCeiling: boolean): Promise; /** * Prepares request parameters for a simple command * * @param command - The command to prepare parameters for * @param requestConfig - Optional request configuration * @returns The prepared request parameters */ protected _getCommandRequestParams(command: SimpleCommand, requestConfig?: CcRequestConfigPartial): Promise>; /** * Prepares the final request by combining parameters, configuration, and authentication * * @param command - The command to prepare request for * @param requestParams - The request parameters * @param requestConfig - Request configuration that overrides the default * @param isIdempotent - Whether sending the prepared request twice means it twice * @returns The prepared request */ protected _prepareRequest(command: SimpleCommand | StreamCommand, requestParams: Partial, requestConfig: CcRequestConfigPartial | undefined, isIdempotent: boolean): Promise; /** * Processes the API response and transforms it according to the command's requirements * * @param response - The response * @param request - The request * @param command - The command that generated the response * @returns The processed response * @throws {CcClientError} When there's a client-side error processing the response * @throws {CcHttpError} When the server returns an error response */ protected _handleResponse(response: CcResponse, request: CcRequest, command: SimpleCommand): Promise; } //# sourceMappingURL=cc-client.d.ts.map