UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

62 lines (61 loc) 2.94 kB
/** * Per-domain auth profile. * - developerToken: permanent token, manually provided via `login --token` * - accessToken: temporary OAuth token from Device Code flow * Priority: developerToken > accessToken */ export interface AuthProfile { developerToken?: string; accessToken?: string; accessTokenExpiresAt?: number; refreshToken?: string; refreshTokenExpiresAt?: number; clientId?: string; tokenId?: string; lastUsedAt?: number; } /** Multi-domain auth store: origin → AuthProfile */ export type AuthStore = Record<string, AuthProfile>; export declare function resolveConfigDir(): string; export declare function resolveConfigPath(): string; /** * 把用户传入的 site-domain 归一化成 origin(e.g. https://meego.example.com)。 * 兼容不同书写形式: * - 缺协议头自动补 https://(`meego.feishu.cn` → `https://meego.feishu.cn`); * - 去掉多余 path / query / 末尾斜杠(`https://x.cn/b/auth/?a=1` → `https://x.cn`); * - 已显式带协议的原样识别(`http://localhost:8080` 保留 http 与端口)。 * 空串 / 无法解析时按既有行为抛错(new URL 抛 Invalid URL),由调用方决定兜底。 */ export declare function normalizeSiteDomain(url: string): string; /** Load the full multi-domain auth store from disk. */ export declare function loadStore(): AuthStore; /** Save the full multi-domain auth store to disk. */ export declare function saveStore(store: AuthStore): void; /** Load the auth profile for a specific domain. */ export declare function loadProfile(serverUrl: string): AuthProfile | null; /** Save/update the auth profile for a specific domain (merge, not overwrite). */ export declare function saveProfile(serverUrl: string, update: Partial<AuthProfile>): void; /** * 给某域名打上「最近使用」时间戳(unix 秒)。仅当该 origin 已是文件里的真实登录态 * 时才写——纯环境变量来源 / 未登录的 origin 不落盘,避免污染 auth.json。 * * 写失败静默吞掉:这只是给 whoami 用的「最近使用」提示,绝不能因为落盘失败 * (磁盘满 / 权限)把一次本该成功的鉴权拖垮(与 loadStore 读失败返回 {} 同策略)。 */ export declare function touchLastUsed(serverUrl: string): void; /** * Load effective auth profile for a domain. * Falls back to env vars if no file-based profile exists. */ export declare function loadEffectiveProfile(serverUrl: string): AuthProfile | null; /** * Resolve the effective Bearer token for a domain. * Priority: developerToken > accessToken * Returns the token string, or null if none available. */ export declare function resolveToken(profile: AuthProfile): string | null; /** * Check whether the profile has a permanent developer token. */ export declare function hasDeveloperToken(profile: AuthProfile): boolean; export declare function authSource(): 'env' | 'config';