-
Notifications
You must be signed in to change notification settings - Fork 73
/
request.ts
77 lines (70 loc) · 1.81 KB
/
request.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
import Logging, { LogWrapper } from "../components/logging";
import crypto from "crypto";
import { ThinRequest } from "..";
import { Request } from "express";
import { ParsedQs } from "qs";
// Methods supported by a express.Router
export type Methods = 'all' |
'get' |
'post' |
'put' |
'delete' |
'patch' |
'options' |
'head' |
'checkout' |
'connect' |
'copy' |
'lock' |
'merge' |
'mkactivity' |
'mkcol' |
'move' |
'm-search' |
'notify' |
'propfind' |
'proppatch' |
'purge' |
'report' |
'search' |
'subscribe' |
'trace' |
'unlock' |
'unsubscribe';
export class ProvisioningRequest<
// These types are taken from express.Request
Params = {[key: string]: string},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ResBody = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ReqBody = any,
ReqQuery = ParsedQs> implements ThinRequest {
public readonly log: LogWrapper;
public readonly id: string;
constructor(
public readonly expressReq: Request<Params, ResBody, ReqBody, ReqQuery>,
public readonly userId: string|null,
public readonly requestSource: "widget"|"provisioner",
public readonly widgetToken?: string,
public readonly fnName?: string,
) {
this.id = crypto.randomBytes(4).toString('hex');
this.fnName = fnName || expressReq.path;
this.log = Logging.get(
`ProvisionRequest ${[this.id, fnName].filter(n => !!n).join(" ")}`
);
this.log.debug(`Request ${userId} (${requestSource}) ${this.fnName}`);
}
public getId(): string {
return this.id;
}
get body(): ReqBody {
return this.expressReq.body;
}
get params(): Params {
return this.expressReq.params;
}
get query(): ReqQuery {
return this.expressReq.query;
}
}