/** * Central container of Nodes, with possibility to have clients connect to it. * One Hub can be re-used by many different endpoint protocols (such as * WebSocket servers, raw TCP ports, etc.) * * A HubClient can be used to (internally) connect to a Hub, and is in * turn used by e.g. TcpConnection, WSConnection, and LocalClient. */ import { Authenticator } from "./authenticator"; import { Matcher } from "./match"; import * as pubsub from "./pubsub"; import { Storage } from "./storage"; /** * Specify what permission a user has to e.g. publish or subscribe. * If specified as a boolean, the permission is granted/denied for * all nodes (and access denied will be returned regardless of whether * the specified node exists or not). * If specified as an object, rights can be set per node. * Again, the right per node can be set as a boolean to allow/deny * everything on that node, or only allow specific topic pattern or * patterns. * Note that when using a pattern, a subscribe call may succeed, * even though the rights would not allow any message to be received * by that user using the given subscription pattern. This is because * the server currently doesn't perform an intersection on the patterns * to see if they are disjoint. */ export declare type Permission = boolean | { [nodeName: string]: boolean | string | string[]; }; /** * Permissions specify whether a user can e.g. publish or subscribe * to certain nodes and/or topics. */ export interface Permissions { publish: Permission; subscribe: Permission; } /** * Partial permissions allow quick setting of only the items * that differ from the default permissions (which typically * deny everything). * It can also be set to a boolean, in which case the * defaultAllowPermissions or defaultDenyPermissions will be * used (for true and false, respectively). */ export declare type PartialPermissions = boolean | Partial; export interface UserRights { [username: string]: PartialPermissions; } export declare const defaultDenyPermissions: Permissions; export declare const defaultAllowPermissions: Permissions; export declare const defaultPermissions: Permissions; export declare class Authorizer { private _permissions; private _publishMatchers; constructor(partialPermissions: PartialPermissions | undefined); canPublish(node: string, topic: string): boolean; canSubscribe(node: string, pattern?: string): boolean | Matcher; private _hasPermission; } export declare class Hub { private _nodes; private _authenticator; private _rights; private _storage; constructor(authenticator: Authenticator); setRights(rights: UserRights): void; getAuthorizer(username: string): Authorizer; init(): Promise; setStorage(storage: Storage): void; getStorage(): Storage | undefined; add(node: pubsub.BaseNode): void; find(nodeName: string): pubsub.BaseNode | undefined; findSource(nodeName: string): pubsub.Source | undefined; findDestination(nodeName: string): pubsub.Destination | undefined; authenticate(username: string, password: string): Promise; } /** * Test validity of structure of UserRights. * Throws an error if it's incorrect. */ export declare function validateUserRights(rights: UserRights): void; export default Hub;