type Fail = { ok: false; reason: string; }; export declare function chatQuotaKey(chatId: string, openId: string): string; export declare function globalQuotaKey(openId: string): string; export declare function getGrantExpiresAt(larkAppId: string, grantKey: string): number | undefined; export declare function addChatGrant(larkAppId: string, chatId: string, openId: string, quota?: number, expiresAt?: number): Promise<{ ok: true; created: boolean; } | Fail>; /** * 全局对话授权:把 open_id 加入 globalGrants(被授权在任意群与本 bot 对话的名单,人/bot 通用)。 * talk-only —— 只进 canTalk / bot 路由闸,绝不写 allowedUsers、不授 canOperate(与 addChatGrant 同源)。 */ export declare function addGlobalGrant(larkAppId: string, openId: string, quota?: number, expiresAt?: number): Promise<{ ok: true; created: boolean; } | Fail>; /** * scope-aware talk-only 移除:删本群 chatGrants[chatId] 中的 openId + 其 chat quota 记录。 * 额度用尽/崩溃自愈时调。不碰 allowedUsers、不碰 globalGrants,故无 would_open_bot 守卫。 */ export declare function removeChatGrant(larkAppId: string, chatId: string, openId: string): Promise<{ ok: true; removed: boolean; } | Fail>; /** * scope-aware talk-only 移除:删 globalGrants 中的 openId + 其 global quota 记录。 * talk-only,不碰 allowedUsers,无 would_open_bot 守卫(清空它不放大 operate)。 */ export declare function removeGlobalGrant(larkAppId: string, openId: string): Promise<{ ok: true; removed: boolean; } | Fail>; /** * 仅当磁盘中的过期时间仍等于观察值且确已到期时回收,避免异步清理误删刚续期的授权。 */ export declare function removeExpiredGrant(larkAppId: string, scope: 'chat' | 'global', chatId: string | undefined, openId: string, observedExpiresAt: number, now?: number): Promise<{ ok: true; removed: boolean; } | Fail>; /** * 扣一次额度(一条对话输入)。RMW 锁内递增、内存以锁内磁盘快照 used 为准。 * 无记录 → tracked:false(无需 enforce,放行)。 * 已达/超上限 → allow:false(应拦本条 + 自愈 revoke)。 * 正常递增 → allow:true,exhausted=(used 恰好达 limit),调用方放行本条、若 exhausted 则处理后 revoke。 * 基础设施失败(getBot / RMW)会 throw —— 调用方 catch 后 fail-closed(拒发以保硬上限)。 * * defaultLimit>0 且 quotaKey 对应记录不存在时:懒初始化 {limit:defaultLimit, used:1} * (oncall 群默认额度场景,避免每条消息都要显式 /grant 才落记录)。 * * `expiredGrant`(可选):oncall ∩ chatGrant 交集用。传入时**锁内**以「本 key 的**当前** expiry」 * 为唯一权威判定(不看调用方 evaluate 时的观察值——那可能已陈旧): * • 当前 expiry 存在且 <= now → grant 确已过期 → 同一把锁内原子清「成员+quota+expiry」,本条 * 按「grant 已消失」处理(回落 defaultLimit 懒初始化 / 无 default 则 tracked:false)。 * • 当前无 expiry / expiry 在未来(永久/已续期)→ 仍是成员则 grant **live**:不兜 default,按现有 * 记录消费(无记录=显式不限→tracked:false);已非成员(被 revoke/整条清)→ 普通 oncall→回落 default。 * 这样「过期清理 + 本次 oncall 额度决策」收口在同一原子 RMW,杜绝跨 await 用陈旧 ev 决策。 */ export declare function consumeQuota(larkAppId: string, quotaKey: string, defaultLimit?: number, expiredGrant?: { scope: 'chat' | 'global'; chatId?: string; openId: string; now?: number; }): Promise<{ tracked: boolean; allow: boolean; exhausted: boolean; used: number; limit: number; }>; /** * 整群 talk 授权:把 chatId 加入 allowedChatGroups("talk-open 的 chat_id 列表")。 * 命中后该 chat 任何成员都过 canTalk(见 event-dispatcher.canTalk),不授 canOperate。 */ export declare function addAllowedChatGroup(larkAppId: string, chatId: string): Promise<{ ok: true; created: boolean; } | Fail>; /** 撤销整群 talk 授权:把 chatId 从 allowedChatGroups 移除。 */ export declare function removeAllowedChatGroup(larkAppId: string, chatId: string): Promise<{ ok: true; removed: boolean; } | Fail>; /** * 原子彻底撤销:同一 RMW 内删 chatGrants[chatId]、全局 allowedUsers(email 反查)与 * globalGrants(全局对话授权)。三重防开放守卫只约束 allowedUsers 这一支(operate/owner 安全), * chatGrants / globalGrants 是 talk-only,删空不会让 bot 对所有人开放 operate,无需守卫: * #2 禁止撤销当前 owner 本人(否则 owner 身份会漂移到别人)。 * R2#3 移除后运行时 resolvedAllowedUsers 不能变空(catch 未解析 email 导致 resolved 空)。 * R3#3 在 RMW 锁内按最新磁盘 entry 再判一次(catch 并发写把 allowlist 删空)。 */ export declare function revokeGrant(larkAppId: string, chatId: string, openId: string): Promise<{ ok: true; removed: { chat: boolean; global: boolean; globalTalk: boolean; }; } | Fail>; export {}; //# sourceMappingURL=grant-store.d.ts.map