import * as _nestjs_common from '@nestjs/common'; import { DynamicModule, CanActivate, ExecutionContext } from '@nestjs/common'; import { PlatformHttpClient, ObservableService, RequestContextService } from '@lark-apaas/nestjs-common'; import { Reflector } from '@nestjs/core'; /** * 通讯录相关类型 * * 字段集合严格对齐平台 InnerAPI `account/list_users` 的返回:只有 * miaodaUserID / name / avatar,不含邮箱、手机号等其他用户信息。 */ /** 国际化文本,key 为语言码(zh_cn / en_us / ja_jp) */ type I18nText = Record; /** * 用户头像。 * * 注意是嵌套结构,不是 URL 字符串——URL 在 `image.large` 上。 */ interface MiaodaUserAvatar { /** 头像来源,平台当前返回 'image' */ source?: string; image?: { /** 大尺寸头像 URL */ large?: string; [size: string]: string | undefined; }; } /** 按 ID 批量查人的单条结果 */ interface MiaodaUserInfo { /** 妙搭用户 ID */ miaodaUserID: string; /** * 用户名。 * * 是国际化文本对象(`{ zh_cn, en_us, ja_jp }`),不是字符串—— * 直接当字符串渲染会得到 `[object Object]`,需自行按语言取值。 */ name?: I18nText; /** 用户头像 */ avatar?: MiaodaUserAvatar; } /** * AuthNPaas 模块配置 */ interface AuthNPaasModuleOptions { /** @deprecated 是否总是需要登录,默认 true */ alwaysNeedLogin?: boolean; } declare class AuthNPaasModule { static forRoot(options?: AuthNPaasModuleOptions): DynamicModule; } /** * ID 转换结果项 */ interface UserIDMappingItem { sourceUserID: string; targetUserID: string; } declare class AuthNPaasService { private readonly httpClient; private readonly obs; private readonly requestContext; private readonly logger; constructor(httpClient: PlatformHttpClient, obs: ObservableService, requestContext: RequestContextService); /** * 获取当前登录用户的飞书 user_id * * 从请求上下文获取当前妙搭 userId,调用转换接口获取对应的飞书 user_id * * @returns 飞书 user_id,如果当前用户未登录或转换失败返回 null */ getCurrentUserLarkUserId(): Promise; /** * 批量将妙搭 userId 转换为飞书 user_id * * @param userIds - 妙搭用户 ID 列表,最多 100 个 * @returns 飞书 user_id 数组,顺序与输入对应,转换失败的项为 null */ getBatchLarkUserIds(userIds: string[]): Promise<(string | null)[]>; /** * 批量将飞书 user_id(employee_id)转换为妙搭 userId * * @param employeeIds - 飞书 user_id(employee_id)列表,最多 100 个 * @returns 妙搭 userId 数组,顺序与输入对应,转换失败的项为 null */ getBatchMiaodaUserIds(employeeIds: string[]): Promise<(string | null)[]>; /** * 调用批量转换接口(带可观测性) */ private batchConvertUserIds; /** * 按妙搭 userID 批量查用户信息(姓名 + 头像) * * @param userIds - 妙搭用户 ID 列表,最多 100 个 * @returns 与入参**等长且同序**的数组;未命中的位置为 `null` * * @throws {Error} 入参超过 100 个,或请求上下文中缺少 appId * @throws {HttpException} 平台调用失败(502),错误信息含平台 code 与 x-tt-logid * * @example * ```ts * const [alice, bob] = await contacts.listUsersByIds([aliceId, bobId]); * const displayName = alice?.name?.zh_cn ?? alice?.name?.en_us ?? ''; * const avatarUrl = alice?.avatar?.image?.large; * ``` */ listUsersByIds(userIds: string[]): Promise<(MiaodaUserInfo | null)[]>; /** 发起平台调用并解析出 items(带可观测性) */ private requestListUsers; } declare class AuthNPaasController { private readonly authnService; constructor(authnService: AuthNPaasService); /** * 获取当前登录用户的飞书 user_id * * GET /api/authnpaas/lark-user-id */ getCurrentUserLarkUserId(): Promise<{ lark_user_id: string | null; }>; } /** * Public 装饰器的元数据键 */ declare const IS_PUBLIC_KEY = "isPublic"; /** * 标记接口为公开接口,跳过 AuthNPaasGuard 的鉴权检查 * * @example * ```typescript * @Controller('mock-api/users') * @Public() // 控制器级别 * export class MockPermissionController { * @Get(':userId/permissions') * getUserPermissions() {} * } * * // 或者在方法级别 * @Controller('api') * export class ApiController { * @Get('public-info') * @Public() // 方法级别 * getPublicInfo() {} * } * ``` */ declare const Public: () => _nestjs_common.CustomDecorator; /** * NeedLogin 装饰器 * 标记接口需要登录。如果鉴权失败(如 401/403),异常过滤器会将请求重定向到登录页。 * 可选地传入登录页路径,默认 '/login'。 */ declare const NeedLogin: (loginPath?: string) => MethodDecorator & ClassDecorator; /** * AuthNPaas 守卫 * 负责协调所有鉴权检查,具体检查逻辑委托给 PermissionService */ declare class AuthNPaasGuard implements CanActivate { private reflector; constructor(reflector: Reflector); canActivate(context: ExecutionContext): Promise; } /** * 常量 */ /** AuthNPaas 模块选项 Token */ declare const AUTHNPAAS_MODULE_OPTIONS: unique symbol; /** * 元数据键 */ /** 需要登录元数据键 */ declare const NEED_LOGIN_KEY = "authnpaas:needLogin"; export { AUTHNPAAS_MODULE_OPTIONS, AuthNPaasController, AuthNPaasGuard, AuthNPaasModule, type AuthNPaasModuleOptions, AuthNPaasService, type I18nText, IS_PUBLIC_KEY, type MiaodaUserAvatar, type MiaodaUserInfo, NEED_LOGIN_KEY, NeedLogin, Public, type UserIDMappingItem };