UNPKG

mira-app-server

Version:

Mira Server - standalone server application using mira-app-core

84 lines 2.78 kB
/** * 多 profile 凭证存储 * * 将登录凭证持久化到 ~/.mira/credentials.json,支持多个命名 profile, * 通过 current 指针记录当前激活的 profile,便于在不同服务器/账号间切换。 * * 文件结构: * { * "current": "default", * "profiles": { * "default": { "server": "...", "token": "...", "username": "...", "updatedAt": "..." } * } * } */ /** 单个 profile 的凭证信息 */ export interface CredentialProfile { /** 服务器地址,例如 http://localhost:8081 */ server: string; /** 访问令牌 */ token: string; /** 登录用户名,便于辨识(可选) */ username?: string; /** 最近一次更新时间(ISO 字符串,可选) */ updatedAt?: string; } /** 凭证文件结构 */ export interface CredentialsFile { /** 当前激活的 profile 名 */ current?: string; /** 所有 profile */ profiles: Record<string, CredentialProfile>; } /** 默认 profile 名 */ export declare const DEFAULT_PROFILE_NAME = "default"; /** 凭证目录:~/.mira */ export declare const MIRA_DIR: string; /** 凭证文件路径:~/.mira/credentials.json */ export declare const CREDENTIALS_PATH: string; /** * 读取凭证文件,容错处理: * - 文件不存在 → 返回空结构 * - 文件损坏/格式异常 → 返回空结构,不抛错(避免 CLI 崩溃) */ export declare function loadCredentials(): CredentialsFile; /** * 写入凭证文件。目录不存在时自动创建(权限 0o700)。 */ export declare function saveCredentials(data: CredentialsFile): void; /** * 获取指定名称的 profile */ export declare function getProfile(name: string): CredentialProfile | undefined; /** * 保存(新增或覆盖)一个 profile,并记录更新时间。 * 如果尚无 current,则将其设为当前。 */ export declare function saveProfile(name: string, profile: CredentialProfile): void; /** * 设置当前激活的 profile * @returns 是否设置成功(profile 不存在则返回 false) */ export declare function setCurrent(name: string): boolean; /** * 删除一个 profile。若删除的是当前 profile,则清空 current。 */ export declare function removeProfile(name: string): boolean; /** * 列出所有 profile 名 */ export declare function listProfiles(): string[]; /** * 获取当前激活的 profile * @returns { name, profile } 或 null(无任何 profile 时) */ export declare function getCurrentProfile(): { name: string; profile: CredentialProfile; } | null; /** * 清空当前 profile 的 token(登出)。 * @returns 是否成功(无当前 profile 则返回 false) */ export declare function clearCurrentToken(): boolean; //# sourceMappingURL=credentials.d.ts.map