import { DeviceFlowOptions } from './oauth'; import { Credential, RequestConfig } from '../types'; export * from './common'; export * from './credential'; export * from './web-auth'; export * from './oauth'; export * from './api-key'; export interface AuthSupervisorOptions { /** * 是否在内存中缓存 credential 信息 */ cache?: boolean; /** * 网络请求代理配置 */ proxy?: string; /** * 请求超时时间 */ timeout?: number; /** * 登录失败时是否抛出错误,默认返回 null */ throwError?: boolean; } export type AuthFlow = 'web' | 'device'; export interface WebAuthOptions { /** * 请在初始化实例时指定 * @deprecated */ throwError?: boolean; /** * 授权方式 * - 'web': 使用网页回调授权 * - 'device': 使用 Device Flow 授权 * @default 'device' */ flow?: AuthFlow; getAuthUrl?: (rawUrl: string) => string; noBrowser?: boolean; callbackTimeout?: number; /** Device Flow 的客户端 ID */ client_id?: string; /** Device Flow 回调,获取设备码后通知调用方 */ onDeviceCode?: DeviceFlowOptions['onDeviceCode']; /** 自定义 OAuth API 请求的 endpoint */ getOAuthEndpoint?: DeviceFlowOptions['getOAuthEndpoint']; /** 静默模式,不打印任何日志 */ silent?: boolean; /** * 自定义授权流程模式 * 为 true 时,device/code 和 token 接口的返回值没有外层 { code, result, reqId } 包装, * 直接就是 result 本体;同时 verification_uri 直接使用接口返回值,不再由客户端拼接。 */ custom?: DeviceFlowOptions['custom']; /** * Web 授权认证模式(仅 flow='web' 生效) * - 'oauth': 原行为,授权 URL 指向 /dev#/cli-auth(缺省值) * - 'apikey': 授权 URL 指向 /login?cliAuth=1,支持环境 API Key 登录 */ authMode?: 'oauth' | 'apikey'; } export interface LoginByApiSecretOptions { /** * 强制更新 Credential,忽略缓存 * @default false */ forceUpdate?: boolean; /** * 是否将 credential 存储为 WebCredential 格式 * @default false */ storeAsWebCredential?: boolean; /** * 额外的 Credential 字段 */ additionalCredentialFields?: Omit; } export interface LoginByApiKeyOptions { /** * 强制更新 Credential,忽略缓存 * @default false */ forceUpdate?: boolean; /** * 地域 * @default 'ap-shanghai' */ region?: string; /** * 项目工作目录,传入后凭证存储到 projects/ 子目录 * 不传时存储到全局 auth.json */ cwd?: string; } export declare class AuthSupervisor { static instance: AuthSupervisor; /** * 单例模式,全局缓存 * @param options */ static getInstance(options?: AuthSupervisorOptions): AuthSupervisor; cacheCredential: Credential; needCache: boolean; cacheExpiredTime: number; requestConfig: RequestConfig; throwError: boolean; constructor(options?: AuthSupervisorOptions); /** * 获取登录状态信息 */ getLoginState(): Promise; /** * 通过网页授权登录 * @returns credential */ loginByWebAuth(options?: WebAuthOptions): Promise; /** * 通过 API Secret 登录,支持临时秘钥 * @param secretId * @param secretKey * @param token * @param opts 选项配置,包括强制更新和额外的 Credential 字段 * @returns credential */ loginByApiSecret(secretId?: string, secretKey?: string, token?: string, opts?: LoginByApiSecretOptions): Promise; /** * 通过 CloudBase API Key 登录 * * API Key 是环境级别的长期凭证,通过 /capi/credential 端点换取临时 STS 密钥。 * 临时密钥过期后,自动用 API Key 重新换取(无需 refreshToken 机制)。 * * @param apiKey CloudBase 环境的 API Key * @param envId CloudBase 环境 ID * @param opts 选项配置 */ loginByApiKey(apiKey: string, envId: string, opts?: LoginByApiKeyOptions): Promise; logout(opts?: { cwd?: string; }): Promise; private isCacheExpire; } /** * @deprecated Use `AuthSupervisorOptions` instead. This type has a spelling error and will be removed in a future version. */ export interface AuthSupevisorOptions extends AuthSupervisorOptions { } /** * @deprecated Use `AuthSupervisor` instead. This class has a spelling error and will be removed in a future version. */ export declare class AuthSupevisor extends AuthSupervisor { static instance: AuthSupevisor; /** * @deprecated Use `AuthSupervisor.getInstance` instead */ static getInstance(options?: AuthSupevisorOptions): AuthSupevisor; /** * @deprecated Use `AuthSupervisor` constructor instead */ constructor(options?: AuthSupevisorOptions); }