/** * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file src/bce_base_client.ts * @author leeight */ import { EventEmitter } from 'events'; import { Writable } from 'stream'; import HttpClient, { RequestBody } from './http_client'; import type { BceConfig, BceResponse, Credentials, HttpMethod, HttpHeaders } from './types/common'; /** 请求参数接口 */ export interface RequestArgs { /** 请求体 */ body?: RequestBody; /** 请求头 */ headers?: HttpHeaders; /** 查询参数 */ params?: Record; /** 请求级别的配置 */ config?: Partial; /** 输出流 */ outputStream?: Writable; } /** * BCE 基础客户端类 * 所有 BCE 服务客户端的基类,提供通用的请求处理逻辑 * * @example * ```typescript * class CustomClient extends BceBaseClient { * constructor(config: BceConfig) { * super(config, 'custom-service', true); * } * * async customMethod(): Promise { * return this.sendRequest('GET', '/custom-path'); * } * } * ``` */ export declare class BceBaseClient extends EventEmitter { /** 客户端配置 */ config: BceConfig; /** 服务 ID */ serviceId: string; /** 是否支持地域 */ regionSupported: boolean; /** 时间偏移量(用于时间同步) */ timeOffset?: number; /** HTTP 代理客户端 */ private _httpAgent; /** * 构造函数 * @param clientConfig 客户端配置 * @param serviceId 服务 ID * @param regionSupported 是否支持地域 */ constructor(clientConfig: BceConfig, serviceId: string, regionSupported?: boolean); /** * 计算服务端点 * @returns 服务端点 URL */ private _computeEndpoint; /** * 创建签名 * @param credentials 认证凭据 * @param httpMethod HTTP 方法 * @param path 请求路径 * @param params 查询参数 * @param headers 请求头 * @returns Promise<签名字符串> */ createSignature(credentials: Credentials, httpMethod: HttpMethod, path: string, params: Record, headers: HttpHeaders): Promise; /** * 发送请求(高级接口) * @param httpMethod HTTP 方法 * @param resource 资源路径 * @param varArgs 请求参数 * @returns Promise */ sendRequest(httpMethod: HttpMethod, resource: string, varArgs?: Partial): Promise; /** * 发送 HTTP 请求(底层接口) * @param httpMethod HTTP 方法 * @param resource 资源路径 * @param args 请求参数 * @param requestConfig 请求配置 * @returns Promise */ sendHTTPRequest(httpMethod: HttpMethod, resource: string, args: RequestArgs, requestConfig: BceConfig): Promise; /** * 获取当前 HTTP 代理 * @returns HTTP 客户端实例 */ getHttpAgent(): HttpClient | null; /** * 更新配置 * @param newConfig 新的配置 */ updateConfig(newConfig: Partial): void; /** * 获取服务端点 * @returns 服务端点 URL */ getEndpoint(): string; /** * 获取服务 ID * @returns 服务 ID */ getServiceId(): string; /** * 检查是否支持地域 * @returns 是否支持地域 */ isRegionSupported(): boolean; /** * 销毁客户端,清理资源 */ destroy(): void; } export default BceBaseClient; //# sourceMappingURL=bce_base_client.d.ts.map