import { pathRecursion } from './util.path-match'; import { Config, Extends } from './index'; import { File } from './server.multipart'; import * as Role from './role'; import * as Url from './url'; import * as Router from './router'; import { getCookie, setCookie, clearCookie } from './server.cookie'; export interface AppExtendedObject { api?: any; app?: any; extend?: any; fs?: any; log?: any; config?: any; util?: any; db?: any; } export interface ExtendedObject extends AppExtendedObject { user: object; } export declare type ExtendedAttribute = keyof ExtendedObject; export interface MiniInfo { /** 是否为调试模式 */ readonly type: string; /** 是否为调试模式 */ readonly isDebug: boolean; /** 获取请求域名 */ readonly domain: string; /** 获取请求方法 */ readonly method: string; /** 获取请求路径 */ readonly path: string; /** 客户端 IP */ readonly clientIp: string[]; getHeader(h: string): undefined | string | string[]; setHeader(h: string, v: string | string[]): void; /** 自定义工具 */ readonly util?: Ext['util']; /** 自定义 API */ readonly api?: Ext['api']; /** 自定义 APP 接口 */ readonly app?: Ext['app']; /** 自定义扩展接口 */ readonly extend?: Ext['extend']; /** 自定义文件系统接口 */ readonly fs?: Ext['fs']; /** 自定义日志接口 */ readonly log?: Ext['log']; /** 自定义配置接口 */ readonly config?: Ext['config']; /** 自定义数据库接口 */ readonly db?: Ext['db']; } export interface BaseInfo extends MiniInfo { /** 获取主机名 */ readonly host: string; /** 获取端口 */ readonly port: number; /** 获取请求来源域名 */ readonly origin: string; /** 获取请求来源路径 */ readonly referer: string; /** 获取请求来源域名 */ readonly originDomain: string; /** 获取请求来源来源 */ readonly originPort: number; /** 自定义用户相关 API */ readonly user: Ext['user'] | null; /** * 获取Cookie * @param {String} cname Cookie名称 * @return {String} Cookie值 */ getCookie(cname: string): string; /** * 设置Cookie * @param {String} cname Cookie名称 * @param {String} cookie Cookie值 * @param {Object} opt Cookie选项 */ setCookie(cname: string, cookie: string, opt?: object): boolean; /** * 清除Cookie * @param {String} cname Cookie名称 * @param {Object} opt Cookie选项 */ clearCookie(cname: string, opt?: object): void; /** * 清除所有 Cookie * @param {Object} opt Cookie选项 */ clearCookie(opt?: object): void; /** * 获取模块的Url * @param {String} id 模块Id * @return {String} 模块Id */ getUrl(id: string): string; /** * 判断是否为授权域名 * @param {Number} level 限制级别 */ verifyDomain(level: number): boolean; /** * 检查域名 * @param {Number} level 限制级别 */ checkDomain(level: number): boolean; /** 获取用户ID */ readonly userId: string; /** * 设置用户登录 * @param uid 用户ID */ login(uid: string): Promise; /** 用户退出 */ exit(): Promise; /** * 检查用户是否登录 * 如果用户没有登录,则报错 * @throws {ActiveError} If 用户没有登录 */ checkLogin(): void; /** 获取用户权限 */ getPower(v?: string): Promise; /** * 判断用户是否有权限 * 特别的,如果用户有超级权限,则视为用户有任意权限 * @param {...String} powers 要判断的权限 * @return {Boolean} 用户是否有列出的权限之一 */ hasPower(...powers: (string | [string] | [string, (string | string[])])[]): Promise; /** * 检查用户权限 * 如果用户没有登录或者列出的权限用户均没有,则报错 * 特别的,如果用户有超级权限,则视为用户有任意权限 * @param {...String} powers 检查的权限 * @throws {ActiveError} If 用户没有登录或者列出的权限用户均没有 */ checkPower(...powers: (string | [string] | [string, (string | string[])])[]): Promise; } /** 执行模块函数 */ interface InfoExec { /** * * @param {String} id 模块Id * @return {String} 模块Id */ (pathId: string, data: object, method: string, ...symbols: symbol[]): Promise; (pathId: string, data: object, ...symbols: symbol[]): Promise; (pathId: string, method?: string, ...symbols: symbol[]): Promise; (pathId: string, ...symbols: symbol[]): Promise; } declare const symbol: Readonly<{ restful: symbol; }>; export interface Info extends BaseInfo { /** 获取文件列表 */ readonly files: File[]; /** 获取查询字段 */ readonly query: Query; /** 获取请求体 */ readonly body: Body; /** 执行模块函数 */ exec: InfoExec; symbol: typeof symbol; } interface InInfo extends Info { init(body: any, nfiles: File[], data: any): void; } interface InfoInitThis { extends: Extends; recursion: pathRecursion; getUrl: Url.get; getRole: Role.get; getRouter: Router.get; isDebug: boolean; cookieConfig: object; tokenName: string; getPower(id: string): any | Promise; util: Ext['util']; api: Ext['api']; userApi: (uid: string) => Ext['user'] | null; /** 用于设置登陆用户的方法 */ login(uid: string, config: object, info: Info): string | boolean | Promise; /** 用于退出用户的方法 */ exit(config: object, info: Info): boolean | Promise; /** 用于判定当前用户是否登陆的方法 */ checkCookie(cookie: string, config: object, info: Info): string | [string] | [string, string] | Promise; } export interface Opt { method: string; domain: string; path: string; getCookie: getCookie; setCookie: setCookie; clearCookie: clearCookie; getHeader(h: string): undefined | string | string[]; setHeader(h: string, v: string | string[]): void; clientIp: string | string[]; isVirtual?: boolean; } export interface createInfo { (opt: Opt, query: object): Promise>; } /** * 封装用户信息 * @param {File[]} options.files 上传的文件 * @param {String} options.method 请求方法 * @param {String} options.path 请求路径 * @param {Function} options.getCookie 获取Cookie的基本函数 * @param {Function} options.setCookie 设置Cookie的基本函数 * @param {Function} options.clearCookie 清楚Cookie的基本函数 * @param {Function} options.getHeader 获取Header的基本函数 * @param {Function} options.setHeader 设置Header的基本函数 * @param {String[]} clientIp 客户端数组 * @return {Object} 用户信息 */ export declare function createInfo(this: InfoInitThis | void, { method, path, domain, getCookie, setCookie, clearCookie, getHeader, setHeader, clientIp, }: Opt, query: object): Promise>; export default function init(config: Config, recursion: pathRecursion, getUrl: Url.get, getRole: Role.get, getRouter: Router.get): createInfo; export {};