-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
320 lines (232 loc) · 7.09 KB
/
index.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/** Contains a collection of Ruscord API status codes. */
export enum ApiStatusCodes {
/** General success. */
SUCCESS = 501,
/** Data provided by user has some missing fields. */
MALFORMED_DATA = 2001,
/** Data validation failed. */
VALIDATION_FAILED = 2011,
/** Data validation succeeded. */
VALIDATION_SUCCEEDED = 2012,
/** Data found/exists. */
FOUND = 3001,
/** Data not found/exists. */
NOT_FOUND = 3002,
/** Data deleted. */
DELETED = 3003,
/** Data corrupted. */
CORRUPTED = 3004,
/** Authentication succeeded. */
AUTHENTICATED = 4001,
/** Authentication failed. */
UNAUTHENTICATED = 4002,
/** Unauthorized access to API nodes of denied access to FS or logical modules. */
UNAUTHORIZED = 4003,
/** Action requires confirmation via OTP. */
CONFIRMATION_REQUIRED = 4004,
/** Action confirmation code was resent to an email. */
CONFIRMATION_RESENT = 4005,
/** Action confirmation code has expired. */
CONFIRMATION_EXPIRED = 4006,
/** Something went wrong on a server side. */
SERVER_FAULT = 8001,
/** Something went wrong on a client side. */
CLIENT_FAULT = 8002,
/** Someone should be fired... */
MODULE_FAULT = 8011,
/** Something went wrong on a database side. */
DATABASE_FAULT = 8012,
}
/** Defines properties of a Ruscord API response. */
export interface ApiResponse<T = any> {
/** Gets response status code. */
status: ApiStatusCodes;
/** Gets response message. */
message?: string | undefined;
/** Gets response data. */
data?: T | undefined;
}
/** Defines properties of a confirm action request. */
export interface ConfirmRequest {
/** Gets confrimation code. */
code: number;
}
/** Defines properties of a 2FA setup response. */
export interface Setup2faResponse {
/** Gets QR-code data string. */
qrCode: string;
/** Gets antiforgery token. */
antiforgery: string;
}
/** Defines properties of a 2FA confirmation request. */
export interface Confirm2faRequest {
/** Gets antiforgery token. */
antiforgery: string;
}
/** Defines properties of a device data. */
export interface DeviceData {
/** Gets device name. */
name: string;
/** Gets device fingerprint. */
print: string;
}
/** Defines properties of a sign-in request. */
export interface SignInRequest {
/** Gets login or email. */
identity: string;
/** Gets password. */
password: string;
/** Gets device data. */
deviceData: DeviceData;
}
/** Defines properties of a sign in response. */
export interface SignInResponse {
/** Gets access token. */
accessToken: string;
/** Gets refresh token. */
refreshToken: string;
}
/** Defines properties of a sign-up request. */
export interface SignUpRequest {
/** Gets login. */
login: string;
/** Gets email. */
email: string;
/** Gets password. */
password: string;
/** Gets device data. */
deviceData: DeviceData;
}
/** Defines properties of a Module error. */
export interface ModuleError {
/** Gets error name. */
name: string;
/** Gets error message. */
message: string;
/** Gets error cause if provided. */
cause?: unknown;
}
/**
* Contains a collection of validation check names.
* @remarks Check names should be read negated.
*/
export enum ValidationCheck {
/** Indicates that unknown check failed. */
UNKNOWN,
/** Indicates that field was not alphabetic (a-zA-Z). */
ALPHA,
/** Indicates that field was not alphanumeric. */
ALPHANUMERIC,
/** Indicates that fiels was not a boolean. */
BOOLEAN,
/** Indicates that field does not contain substring/char. */
CONTAINS,
/** Indicates that field was not a credit card number. */
CREDIT_CARD,
/** Indicates that field was not a date. */
DATE,
/** Indicates that field was not a decimal. */
DECIMAL,
/** Indicates that field cannot be divided by some number. */
DIVISIBLE_BY,
/** Indicates that field was not an email. */
EMAIL,
/** Indicates that field was not empty. */
EMPTY,
/** Indicates that field was not equal to some valud. */
EQUALS,
/** Indicates that field does not exist. */
EXISTS,
/** Indicates that field was not a float. */
FLOAT,
/** Indicates that field was not a fully qualified domain name. */
FQDN,
/** Indicates that field was not an hexadecimal. */
HEXADECIMAL,
/** Indicates that field was not an HEX color. */
HEX_COLOR,
/** Indicates that field was not in an array. */
IN,
/** Indicates that field was not a JSON. */
JSON,
/** Indicates that field length was less than or greater than given range. */
LENGTH,
/** Indicates that field was not a locale name. */
LOCALE,
/** Indicates that field was not in a lowercase. */
LOWERCASE,
/** Indicates that field does not matches to a valid MIME type format. */
MIME_TYPE,
/** Indicates that field was not a mobile phone number. */
MOBILE_PHONE,
/** Indicates that field was empty. */
NOT_EMPTY,
/** Indicates that field was not a number. */
NUMBER,
/** Indicates that field was not a numeric. */
NUMERIC,
/** Indicates that field was not a port. */
PORT,
/** Indicates that field was not a string. */
STRING,
/** Indicates that field was not a strong password. */
STRONG_PASSWORD,
/** Indicates that field was not a time. */
TIME,
/** Indicates that field was not in an uppercase. */
UPPERCASE,
/** Indicates that field was not an URL. */
URL,
/** Indicates that field was not an UUID. */
UUID,
/** Indicates that field was not an IP address. */
IP,
}
/** Points where error occurred. */
declare type Location = "body" | "cookies" | "headers" | "params" | "query";
/** Defines fields of an error message. */
export interface ValidationMessage {
/** Gets the name of a failed check. */
check: ValidationCheck;
/** Gets an error message. */
message?: string | undefined;
}
/** Defines properties of a field validation error. */
export type FieldError = {
/** Gets error type. */
type: "field";
/** Gets field name. */
field: string;
/** Gets field value */
value?: string | undefined;
/** Gets field location. */
location?: Location | undefined;
/** Gets the name of a check and error message. */
message: ValidationMessage;
};
/**
* Defines properties of an alternative validation error.
* @remarks Thrown when compaining A | B. Contain errors from the first check group.
*/
export type AlternativeError = {
/** Gets error type. */
type: "alternative" | "unknown";
/** Gets error message for this alternative validation check. */
message: ValidationMessage;
/** Gets a collection of field errors. */
errors: FieldError[];
};
/**
* Defines properties of a grouped alternative validation error.
* @remarks Thrown when comparing [ A | B | C | ... ]. Contains all errors from every check group.
*/
export type GroupedAlternativeError = {
/** Gets error type. */
type: "grouped";
/** Gets error message for this alternative validation group. */
message: ValidationMessage;
/** Gets grouped collection of field errors. */
errors: FieldError[][];
};
/** Defines type of a validation result. */
export type ValidationResult = (FieldError | AlternativeError | GroupedAlternativeError)[];