UNPKG

2.58 kBTypeScriptView Raw
1import { EnumLiteralsOf, IUserEntity } from 'bf-types';
2import { ClientConfig, NexusConfig, Nullable } from '../common/types';
3import { Nexus } from './Nexus';
4export declare type HeadersType = Record<string, string>;
5export declare type ObjectType = Record<string, any>;
6export declare type Lock<T> = (suppliedKey: symbol) => T;
7export declare type InitSettings = {
8 nexus: NexusConfig;
9 client: ClientConfig;
10 auth: ClientAuth;
11 logging: SystemLoggerOptions;
12 impersonate?: Record<string, string>;
13 protected?: boolean;
14};
15export declare type SystemLogLevel = 'debug' | 'info' | 'warn' | 'error';
16export declare type SystemLogLevelMask = SystemLogLevel[];
17export declare type SystemLoggerOptions = {
18 logger: SystemLogger;
19 mask: SystemLogLevelMask;
20};
21export interface SystemLogger {
22 debug: (message: any) => void;
23 info: (message: any) => void;
24 warn: (message: any) => void;
25 error: (message: any) => void;
26}
27export interface SystemWrapper {
28 init(settings: InitSettings): void;
29 sealModule<T extends ObjectType>(module: T): Lock<T>;
30}
31export interface SystemInstance {
32 nexus: Nexus;
33 isProtected(): boolean;
34 getHttpHeaders(): Record<string, string>;
35 getImpersonationHeaders(): Record<string, string>;
36 setHttpHeader(key: string, value: string): void;
37 getEventBus(): EventBus;
38 getLibModule: <T>(type: LibModule) => T;
39}
40export declare type System = SystemInstance & SystemWrapper;
41export declare type LibModule = EnumLiteralsOf<typeof LibModule>;
42export declare const LibModule: Readonly<{
43 readonly API: symbol;
44 readonly AUTH: symbol;
45 readonly MODULE: symbol;
46 readonly MULTITOOL: symbol;
47}>;
48export interface ClientAuth {
49 connect(nexusUrl: string): Promise<Nullable<IUserEntity>> | Nullable<IUserEntity>;
50 afterConnect?: (system: SystemInstance) => void;
51 afterDisconnect?: (system: SystemInstance) => void;
52 reconnect(system: SystemInstance): Promise<Nullable<IUserEntity>> | Nullable<IUserEntity>;
53 disconnect(system: SystemInstance): void;
54}
55export declare type Event<T> = {
56 topic: string;
57 data: T;
58};
59export declare type EventHandler<T> = (event: Event<T>) => void;
60export declare type EventHandlerSet = Set<EventHandler<any>>;
61export declare type EventHandlerMap = Map<string, EventHandlerSet>;
62/**
63 * An EventBus is used by the system for interal, decoupled communication
64 * between different modules
65 */
66export interface EventBus {
67 publish(channel: string, event: Event<any>): void;
68 subscribe(channel: string, handler: EventHandler<any>): void;
69}