-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
executable file
·83 lines (71 loc) · 2.78 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
declare module '@outofsync/request-utils'
import {
ClientRequest,
ServerResponse,
} from 'http';
import Localize from '@outofsync/localize';
type ClosureFn = (...params: any) => void;
type ExpressHandlerFn = (locals: any, req: ClientRequest, res: ServerResponse, next: ClosureFn) => void;
type ReqUtilsCheckPermissionsFn = (req: ClientRequest) => boolean;
type ErrorOrUndef = Error | undefined;
type RequestUtilsAuthContext = {
[key: string]: boolean;
}
interface RequestUtilsOptions {
checkPermission?: ReqUtilsCheckPermissionsFn;
customErrorResponseCodes?: any;
customResponsMessageKeys?: any;
defaultAuthContext?: RequestUtilsAuthContext;
defaultLang?: string;
i18n?: typeof Localize;
}
interface RequestUtilsRequiredParamsMap {
required: any;
options: any;
}
interface RequestUtilsResponseMessage {
summary: string;
message: string;
}
interface RequestUtilsHandledError {
msg: string;
code: string;
stack?: string;
}
interface RequestUtilsDataFieldOptions {
type: string;
required: boolean;
source: string[];
}
type RequestUtilsDataHandlerParams = {
[key: string]: RequestUtilsDataFieldOptions;
}
interface RequestUtilsHandleRequestOptions {
params: RequestUtilsDataHandlerParams;
security: any;
secure?: boolean;
}
declare class RequestUtils {
constructor(req: ClientRequest, options?: RequestUtilsOptions);
setSkipAuth(value: any, req?: ClientRequest): void;
skipAuth(req?: ClientRequest): void;
setTimedout(req?: ClientRequest): void;
setError(code: number, req?: ClientRequest): void;
setData(data: any, req?: ClientRequest): void;
hasResponse(req?: ClientRequest): void;
setAuthContext(authContext: RequestUtilsAuthContext, req?: ClientRequest): void;
updateAuthContext(authContext: RequestUtilsAuthContext, req?: ClientRequest): void;
checkAuthContext(options?: RequestUtilsAuthContext, req?: ClientRequest): void;
checkPermissions(req?: ClientRequest): void;
retrieveParams(params: any, req?: ClientRequest): void;
compileRequiredParams(params?: any): RequestUtilsRequiredParamsMap;
hasRequiredParams(params: any): Array<any>;
handleDefaults(params: any, req?: ClientRequest): void;
validateParams(params: any): Array<any>;
getResponseMessage(code: string | number, lang?: string, customMessageKeys?: any): RequestUtilsResponseMessage;
handleCustomerErrors(err: Error | string, customCodes?: any, customMessageKeys?: any): RequestUtilsHandledError;
handleRequest(handlerOptions: RequestUtilsHandleRequestOptions, closure: ExpressHandlerFn, next: ClosureFn, res: ServerResponse, req?: ClientRequest): ErrorOrUndef;
handleRequestAsync(handlerOptions: RequestUtilsHandleRequestOptions, closure: ExpressHandlerFn, next: ClosureFn, res: ServerResponse, req?: ClientRequest): ErrorOrUndef;
}
declare const obj: RequestUtils;
export default obj;