1 | import { EnumLiteralsOf, IUserEntity } from 'bf-types';
|
2 | import { ClientConfig, NexusConfig, Nullable } from '../common/types';
|
3 | import { Nexus } from './Nexus';
|
4 | export declare type HeadersType = Record<string, string>;
|
5 | export declare type ObjectType = Record<string, any>;
|
6 | export declare type Lock<T> = (suppliedKey: symbol) => T;
|
7 | export declare type InitSettings = {
|
8 | nexus: NexusConfig;
|
9 | client: ClientConfig;
|
10 | auth: ClientAuth;
|
11 | logging: SystemLoggerOptions;
|
12 | impersonate?: Record<string, string>;
|
13 | protected?: boolean;
|
14 | };
|
15 | export declare type SystemLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
16 | export declare type SystemLogLevelMask = SystemLogLevel[];
|
17 | export declare type SystemLoggerOptions = {
|
18 | logger: SystemLogger;
|
19 | mask: SystemLogLevelMask;
|
20 | };
|
21 | export interface SystemLogger {
|
22 | debug: (message: any) => void;
|
23 | info: (message: any) => void;
|
24 | warn: (message: any) => void;
|
25 | error: (message: any) => void;
|
26 | }
|
27 | export interface SystemWrapper {
|
28 | init(settings: InitSettings): void;
|
29 | sealModule<T extends ObjectType>(module: T): Lock<T>;
|
30 | }
|
31 | export 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 | }
|
40 | export declare type System = SystemInstance & SystemWrapper;
|
41 | export declare type LibModule = EnumLiteralsOf<typeof LibModule>;
|
42 | export declare const LibModule: Readonly<{
|
43 | readonly API: symbol;
|
44 | readonly AUTH: symbol;
|
45 | readonly MODULE: symbol;
|
46 | readonly MULTITOOL: symbol;
|
47 | }>;
|
48 | export 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 | }
|
55 | export declare type Event<T> = {
|
56 | topic: string;
|
57 | data: T;
|
58 | };
|
59 | export declare type EventHandler<T> = (event: Event<T>) => void;
|
60 | export declare type EventHandlerSet = Set<EventHandler<any>>;
|
61 | export declare type EventHandlerMap = Map<string, EventHandlerSet>;
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | export interface EventBus {
|
67 | publish(channel: string, event: Event<any>): void;
|
68 | subscribe(channel: string, handler: EventHandler<any>): void;
|
69 | }
|