-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
124 lines (108 loc) · 3.22 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
export interface DataTypeProperties {
[property: string]: MethodDataSchema;
}
export interface MethodDataSchema {
type: string;
description?: string;
required?: Array<string>;
properties?: DataTypeProperties;
items?: MethodDataSchema;
additionalProperties: boolean;
}
export interface MethodSchema {
public?: boolean;
description?: string;
params?: MethodDataSchema;
result?: MethodDataSchema;
emit?: MethodDataSchema;
roles?: Array<string>;
transport?: 'ws' | 'http';
}
export interface ModuleSchema {
[method: string]: MethodSchema;
}
export interface ServerModule<Class> {
schema: ModuleSchema;
Module: { new (): Class };
}
export interface MessageTransport {
send(destination: string, code: number): Promise<void>;
}
declare class User {
constructor();
username: string;
password: string;
createdTime: string;
role: string;
}
declare class Session {
constructor();
username: string;
token: string;
createdTime: string;
}
declare class Client {
constructor();
id: number;
user: User;
session: Session;
setUser(): Promise<void>;
emit(event: string, data: any): Promise<void>;
checkConnection(): boolean;
startSession(user: User): Promise<void>;
deleteSession(): Promise<void>;
}
declare class LockoutRecord {
constructor();
fail(): void;
freeTime(): number;
isLock(): boolean;
renew(time: number): void;
}
export declare class MessageService {
constructor();
setTransport(transport: MessageTransport): void;
setCodeTimeOut(timeout: number): void;
send(destination: string): Promise<string>;
checkDestination(destination: string): boolean;
getCode(destination: string): boolean;
deleteCode(destination: string): void;
}
export declare class LockoutManager {
constructor();
access(username: string): boolean;
fail(username: string): void;
}
export declare class Auth {
constructor(manager: LockoutManager);
register(
data: { username: string; password: string },
context: Client
): Promise<{ username: string; role: string; createdTime: string }>;
login(
data: { username: string; password: string },
context: Client
): Promise<{ username: string; role: string; createdTime: string }>;
logout(data: object, context: Client): Promise<void>;
me(data: object, context: Client): Promise<{ username: string; role: string; createdTime: string }>;
changePassword(
data: { oldPassword: string; newPassword: string },
context: Client
): Promise<{ username: string; role: string; createdTime: string }>;
}
export declare class TwoFactorAuth extends Auth {
constructor(service: MessageService, manager: LockoutManager);
register(
data: { username: string; password: string; code: number },
context: Client
): Promise<{ username: string; role: string; createdTime: string }>;
restore(data: { username: string; password: string; code: number }): Promise<string>;
send(data: { destination: string }): Promise<string>;
}
export const AuthModule: ServerModule<Auth>;
export const TwoFactorAuthModule: ServerModule<TwoFactorAuth>;
export const messageService: MessageService;
export const lockoutManager: LockoutManager;
export const CODE_TIMEOUT: number;
export const OBSERVATION_WINDOW: number;
export const LOCKOUT_THRESHOLD: number;