@miqro/core 1.3.11 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -61
- package/dist/api-router.d.ts +36 -0
- package/dist/{handler/api-router.js → api-router.js} +1 -2
- package/dist/{handler/app.d.ts → app.d.ts} +1 -2
- package/dist/{handler/app.js → app.js} +10 -11
- package/dist/common/api-router-helpers.d.ts +31 -0
- package/dist/common/api-router-helpers.js +2 -0
- package/dist/{handler → common}/api-router-utils.d.ts +7 -6
- package/dist/{handler → common}/api-router-utils.js +4 -5
- package/dist/{util → common}/config/config.d.ts +4 -4
- package/dist/{util → common}/config/config.js +31 -29
- package/dist/{util → common}/config/featuretoggle.d.ts +0 -0
- package/dist/{util → common}/config/featuretoggle.js +0 -1
- package/dist/{util → common}/config/index.d.ts +1 -1
- package/dist/{util → common}/config/index.js +1 -2
- package/dist/common/config/loader.d.ts +13 -0
- package/dist/{util/loader/index.js → common/config/loader.js} +11 -6
- package/dist/{handler/common → common}/context.d.ts +5 -5
- package/dist/{handler/common → common}/context.js +3 -17
- package/dist/common/error/badrequesterror.d.ts +3 -0
- package/dist/common/error/badrequesterror.js +10 -0
- package/dist/common/error/configfilenotfound.d.ts +3 -0
- package/dist/{util → common}/error/configfilenotfound.js +1 -3
- package/dist/common/error/forbiddenerror.d.ts +3 -0
- package/dist/{util → common}/error/forbiddenerror.js +1 -3
- package/dist/{util → common}/error/index.d.ts +1 -1
- package/dist/{util → common}/error/index.js +1 -2
- package/dist/common/error/notfound.d.ts +3 -0
- package/dist/{util → common}/error/notfound.js +1 -3
- package/dist/common/error/notimplemented.d.ts +3 -0
- package/dist/{util → common}/error/notimplemented.js +1 -3
- package/dist/common/error/unauthorizederror.d.ts +3 -0
- package/dist/{util → common}/error/unauthorizederror.js +1 -3
- package/dist/{handler/common → common}/helpers.d.ts +0 -0
- package/dist/{handler/common → common}/helpers.js +0 -1
- package/dist/{util → common}/index.d.ts +5 -5
- package/dist/{util → common}/index.js +5 -6
- package/dist/{util → common}/logger/common.d.ts +0 -0
- package/dist/{util → common}/logger/common.js +0 -1
- package/dist/{util → common}/logger/factory.d.ts +0 -0
- package/dist/{util → common}/logger/factory.js +8 -3
- package/dist/{util → common}/logger/formatter.d.ts +0 -0
- package/dist/{util → common}/logger/formatter.js +0 -1
- package/dist/{util → common}/logger/index.d.ts +1 -1
- package/dist/{util → common}/logger/index.js +1 -1
- package/dist/{util → common}/logger/logger.d.ts +0 -0
- package/dist/{util → common}/logger/logger.js +0 -1
- package/dist/{util → common}/logger/transport.d.ts +0 -0
- package/dist/{util → common}/logger/transport.js +2 -3
- package/dist/{util → common}/parser/common.d.ts +0 -0
- package/dist/{util/session → common/parser}/common.js +0 -1
- package/dist/common/parser/error.d.ts +4 -0
- package/dist/common/parser/error.js +11 -0
- package/dist/{util → common}/parser/get.d.ts +0 -0
- package/dist/{util → common}/parser/get.js +1 -2
- package/dist/common/parser/helpers.d.ts +1 -0
- package/dist/common/parser/helpers.js +9 -0
- package/dist/{util → common}/parser/index.d.ts +1 -0
- package/dist/{util → common}/parser/index.js +1 -1
- package/dist/{util → common}/parser/parser.d.ts +0 -0
- package/dist/{util → common}/parser/parser.js +1 -2
- package/dist/{util → common}/parser/types/any.d.ts +0 -0
- package/dist/{util → common}/parser/types/any.js +0 -1
- package/dist/{util → common}/parser/types/array.d.ts +0 -0
- package/dist/{util → common}/parser/types/array.js +0 -1
- package/dist/{util → common}/parser/types/boolean.d.ts +0 -0
- package/dist/{util → common}/parser/types/boolean.js +0 -1
- package/dist/{util → common}/parser/types/email.d.ts +0 -0
- package/dist/{util → common}/parser/types/email.js +0 -1
- package/dist/{util → common}/parser/types/enum.d.ts +0 -0
- package/dist/{util → common}/parser/types/enum.js +1 -2
- package/dist/{util → common}/parser/types/index.d.ts +0 -0
- package/dist/{util → common}/parser/types/index.js +0 -1
- package/dist/{util → common}/parser/types/multiple.d.ts +0 -0
- package/dist/{util → common}/parser/types/multiple.js +1 -2
- package/dist/{util → common}/parser/types/nested.d.ts +0 -0
- package/dist/{util → common}/parser/types/nested.js +1 -2
- package/dist/{util → common}/parser/types/number.d.ts +0 -0
- package/dist/{util → common}/parser/types/number.js +0 -1
- package/dist/{util → common}/parser/types/object.d.ts +0 -0
- package/dist/{util → common}/parser/types/object.js +0 -1
- package/dist/{util → common}/parser/types/regex.d.ts +0 -0
- package/dist/{util → common}/parser/types/regex.js +1 -2
- package/dist/{util → common}/parser/types/string.d.ts +0 -0
- package/dist/{util → common}/parser/types/string.js +0 -1
- package/dist/{util → common}/parser/types/url.d.ts +0 -0
- package/dist/{util → common}/parser/types/url.js +1 -2
- package/dist/common/router-helpers.d.ts +3 -0
- package/dist/common/router-helpers.js +21 -0
- package/dist/common/router-utils.d.ts +33 -0
- package/dist/common/router-utils.js +62 -0
- package/dist/{handler/middleware/session.d.ts → common/session/common.d.ts} +16 -3
- package/dist/{util/parser → common/session}/common.js +0 -1
- package/dist/{util → common}/session/index.d.ts +0 -0
- package/dist/{util → common}/session/index.js +0 -1
- package/dist/{util → common}/session/service.d.ts +2 -2
- package/dist/{util → common}/session/service.js +2 -3
- package/dist/{handler/common → common}/tokenize-match.d.ts +0 -0
- package/dist/{handler/common → common}/tokenize-match.js +0 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +6 -4
- package/dist/{handler/middleware → middleware}/buffer.d.ts +0 -0
- package/dist/middleware/buffer.js +79 -0
- package/dist/{handler/middleware → middleware}/cookie.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/cookie.js +1 -2
- package/dist/{handler/middleware → middleware}/cors.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/cors.js +4 -6
- package/dist/{handler/middleware → middleware}/form.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/form.js +5 -7
- package/dist/middleware/group.d.ts +2 -0
- package/dist/{handler/middleware → middleware}/group.js +7 -8
- package/dist/{handler/middleware → middleware}/index.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/index.js +8 -9
- package/dist/{handler/middleware → middleware}/json.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/json.js +6 -8
- package/dist/{handler/middleware → middleware}/logger.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/logger.js +1 -2
- package/dist/{handler/middleware → middleware}/parse.d.ts +1 -3
- package/dist/{handler/middleware → middleware}/parse.js +3 -4
- package/dist/middleware/session.d.ts +2 -0
- package/dist/{handler/middleware → middleware}/session.js +11 -14
- package/dist/{handler/middleware → middleware}/tag.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/tag.js +1 -2
- package/dist/{handler/middleware → middleware}/text.d.ts +0 -0
- package/dist/{handler/middleware → middleware}/text.js +5 -7
- package/dist/{handler/proxy.d.ts → proxy.d.ts} +1 -1
- package/dist/{handler/proxy.js → proxy.js} +3 -4
- package/dist/{handler/common/router.d.ts → router.d.ts} +31 -7
- package/dist/{handler/common/router-utils.js → router.js} +101 -73
- package/package.json +11 -15
- package/dist/handler/api-router-utils.js.map +0 -1
- package/dist/handler/api-router.d.ts +0 -70
- package/dist/handler/api-router.js.map +0 -1
- package/dist/handler/app.js.map +0 -1
- package/dist/handler/common/context.js.map +0 -1
- package/dist/handler/common/helpers.js.map +0 -1
- package/dist/handler/common/index.d.ts +0 -2
- package/dist/handler/common/index.js +0 -15
- package/dist/handler/common/index.js.map +0 -1
- package/dist/handler/common/router-utils.d.ts +0 -59
- package/dist/handler/common/router-utils.js.map +0 -1
- package/dist/handler/common/router.js +0 -93
- package/dist/handler/common/router.js.map +0 -1
- package/dist/handler/common/tokenize-match.js.map +0 -1
- package/dist/handler/index.d.ts +0 -5
- package/dist/handler/index.js +0 -18
- package/dist/handler/index.js.map +0 -1
- package/dist/handler/middleware/buffer.js +0 -79
- package/dist/handler/middleware/buffer.js.map +0 -1
- package/dist/handler/middleware/cookie.js.map +0 -1
- package/dist/handler/middleware/cors.js.map +0 -1
- package/dist/handler/middleware/form.js.map +0 -1
- package/dist/handler/middleware/group.d.ts +0 -3
- package/dist/handler/middleware/group.js.map +0 -1
- package/dist/handler/middleware/index.js.map +0 -1
- package/dist/handler/middleware/json.js.map +0 -1
- package/dist/handler/middleware/logger.js.map +0 -1
- package/dist/handler/middleware/parse.js.map +0 -1
- package/dist/handler/middleware/session.js.map +0 -1
- package/dist/handler/middleware/tag.js.map +0 -1
- package/dist/handler/middleware/text.js.map +0 -1
- package/dist/handler/proxy.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/test/common/app.d.ts +0 -3
- package/dist/test/common/app.js +0 -51
- package/dist/test/common/app.js.map +0 -1
- package/dist/test/common/common.d.ts +0 -6
- package/dist/test/common/common.js +0 -15
- package/dist/test/common/common.js.map +0 -1
- package/dist/test/common/index.d.ts +0 -3
- package/dist/test/common/index.js +0 -16
- package/dist/test/common/index.js.map +0 -1
- package/dist/test/common/runner.d.ts +0 -28
- package/dist/test/common/runner.js +0 -88
- package/dist/test/common/runner.js.map +0 -1
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +0 -14
- package/dist/test/index.js.map +0 -1
- package/dist/test/main.d.ts +0 -1
- package/dist/test/main.js +0 -31
- package/dist/test/main.js.map +0 -1
- package/dist/util/cli/index.d.ts +0 -16
- package/dist/util/cli/index.js +0 -84
- package/dist/util/cli/index.js.map +0 -1
- package/dist/util/config/browser.d.ts +0 -1
- package/dist/util/config/browser.js +0 -10
- package/dist/util/config/browser.js.map +0 -1
- package/dist/util/config/config.js.map +0 -1
- package/dist/util/config/featuretoggle.js.map +0 -1
- package/dist/util/config/index.js.map +0 -1
- package/dist/util/error/configfilenotfound.d.ts +0 -4
- package/dist/util/error/configfilenotfound.js.map +0 -1
- package/dist/util/error/forbiddenerror.d.ts +0 -4
- package/dist/util/error/forbiddenerror.js.map +0 -1
- package/dist/util/error/index.js.map +0 -1
- package/dist/util/error/named.d.ts +0 -3
- package/dist/util/error/named.js +0 -11
- package/dist/util/error/named.js.map +0 -1
- package/dist/util/error/notfound.d.ts +0 -4
- package/dist/util/error/notfound.js.map +0 -1
- package/dist/util/error/notimplemented.d.ts +0 -4
- package/dist/util/error/notimplemented.js.map +0 -1
- package/dist/util/error/parsererror.d.ts +0 -8
- package/dist/util/error/parsererror.js +0 -20
- package/dist/util/error/parsererror.js.map +0 -1
- package/dist/util/error/unauthorizederror.d.ts +0 -4
- package/dist/util/error/unauthorizederror.js.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/loader/index.d.ts +0 -4
- package/dist/util/loader/index.js.map +0 -1
- package/dist/util/logger/common.js.map +0 -1
- package/dist/util/logger/factory.js.map +0 -1
- package/dist/util/logger/formatter.js.map +0 -1
- package/dist/util/logger/index.js.map +0 -1
- package/dist/util/logger/logger.js.map +0 -1
- package/dist/util/logger/transport.js.map +0 -1
- package/dist/util/parser/common.js.map +0 -1
- package/dist/util/parser/get.js.map +0 -1
- package/dist/util/parser/index.js.map +0 -1
- package/dist/util/parser/parser.js.map +0 -1
- package/dist/util/parser/types/any.js.map +0 -1
- package/dist/util/parser/types/array.js.map +0 -1
- package/dist/util/parser/types/boolean.js.map +0 -1
- package/dist/util/parser/types/email.js.map +0 -1
- package/dist/util/parser/types/enum.js.map +0 -1
- package/dist/util/parser/types/index.js.map +0 -1
- package/dist/util/parser/types/multiple.js.map +0 -1
- package/dist/util/parser/types/nested.js.map +0 -1
- package/dist/util/parser/types/number.js.map +0 -1
- package/dist/util/parser/types/object.js.map +0 -1
- package/dist/util/parser/types/regex.js.map +0 -1
- package/dist/util/parser/types/string.js.map +0 -1
- package/dist/util/parser/types/url.js.map +0 -1
- package/dist/util/request/common.d.ts +0 -57
- package/dist/util/request/common.js +0 -146
- package/dist/util/request/common.js.map +0 -1
- package/dist/util/request/index.d.ts +0 -4
- package/dist/util/request/index.js +0 -231
- package/dist/util/request/index.js.map +0 -1
- package/dist/util/session/common.d.ts +0 -15
- package/dist/util/session/common.js.map +0 -1
- package/dist/util/session/index.js.map +0 -1
- package/dist/util/session/service.js.map +0 -1
- package/src/handler/api-router-utils.ts +0 -187
- package/src/handler/api-router.ts +0 -86
- package/src/handler/app.ts +0 -133
- package/src/handler/common/context.ts +0 -156
- package/src/handler/common/helpers.ts +0 -11
- package/src/handler/common/index.ts +0 -3
- package/src/handler/common/router-utils.ts +0 -239
- package/src/handler/common/router.ts +0 -98
- package/src/handler/common/tokenize-match.ts +0 -152
- package/src/handler/index.ts +0 -5
- package/src/handler/middleware/buffer.ts +0 -79
- package/src/handler/middleware/cookie.ts +0 -19
- package/src/handler/middleware/cors.ts +0 -98
- package/src/handler/middleware/form.ts +0 -59
- package/src/handler/middleware/group.ts +0 -70
- package/src/handler/middleware/index.ts +0 -48
- package/src/handler/middleware/json.ts +0 -56
- package/src/handler/middleware/logger.ts +0 -18
- package/src/handler/middleware/parse.ts +0 -93
- package/src/handler/middleware/session.ts +0 -155
- package/src/handler/middleware/tag.ts +0 -15
- package/src/handler/middleware/text.ts +0 -47
- package/src/handler/proxy.ts +0 -39
- package/src/index.ts +0 -3
- package/src/test/common/app.ts +0 -45
- package/src/test/common/common.ts +0 -17
- package/src/test/common/index.ts +0 -3
- package/src/test/common/runner.ts +0 -116
- package/src/test/index.ts +0 -1
- package/src/test/main.ts +0 -32
- package/src/util/cli/index.ts +0 -80
- package/src/util/config/browser.ts +0 -5
- package/src/util/config/config.ts +0 -93
- package/src/util/config/featuretoggle.ts +0 -6
- package/src/util/config/index.ts +0 -3
- package/src/util/error/configfilenotfound.ts +0 -8
- package/src/util/error/forbiddenerror.ts +0 -8
- package/src/util/error/index.ts +0 -6
- package/src/util/error/named.ts +0 -3
- package/src/util/error/notfound.ts +0 -8
- package/src/util/error/notimplemented.ts +0 -8
- package/src/util/error/parsererror.ts +0 -15
- package/src/util/error/unauthorizederror.ts +0 -8
- package/src/util/index.ts +0 -8
- package/src/util/loader/index.ts +0 -61
- package/src/util/logger/common.ts +0 -6
- package/src/util/logger/factory.ts +0 -45
- package/src/util/logger/formatter.ts +0 -9
- package/src/util/logger/index.ts +0 -6
- package/src/util/logger/logger.ts +0 -114
- package/src/util/logger/transport.ts +0 -69
- package/src/util/parser/common.ts +0 -81
- package/src/util/parser/get.ts +0 -40
- package/src/util/parser/index.ts +0 -6
- package/src/util/parser/parser.ts +0 -235
- package/src/util/parser/types/any.ts +0 -8
- package/src/util/parser/types/array.ts +0 -73
- package/src/util/parser/types/boolean.ts +0 -13
- package/src/util/parser/types/email.ts +0 -26
- package/src/util/parser/types/enum.ts +0 -29
- package/src/util/parser/types/index.ts +0 -12
- package/src/util/parser/types/multiple.ts +0 -36
- package/src/util/parser/types/nested.ts +0 -19
- package/src/util/parser/types/number.ts +0 -34
- package/src/util/parser/types/object.ts +0 -10
- package/src/util/parser/types/regex.ts +0 -17
- package/src/util/parser/types/string.ts +0 -23
- package/src/util/parser/types/url.ts +0 -35
- package/src/util/request/common.ts +0 -193
- package/src/util/request/index.ts +0 -230
- package/src/util/session/common.ts +0 -20
- package/src/util/session/index.ts +0 -2
- package/src/util/session/service.ts +0 -154
- package/tsconfig.json +0 -32
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import http from "http";
|
|
2
|
-
import { NamedError } from "../error/named";
|
|
3
|
-
import { mergeSearchParams } from "../../handler/common/tokenize-match";
|
|
4
|
-
import { SimpleMap } from "../parser/common";
|
|
5
|
-
import { URL } from "url";
|
|
6
|
-
import { newURL } from "../../handler/common/helpers";
|
|
7
|
-
import { Logger } from "../logger/logger";
|
|
8
|
-
|
|
9
|
-
export const readResponseBuffer = ({
|
|
10
|
-
res,
|
|
11
|
-
readTimeout,
|
|
12
|
-
options,
|
|
13
|
-
req,
|
|
14
|
-
reject,
|
|
15
|
-
logger
|
|
16
|
-
}: {
|
|
17
|
-
res: http.IncomingMessage;
|
|
18
|
-
readTimeout: NodeJS.Timeout | null,
|
|
19
|
-
options: RequestOptions,
|
|
20
|
-
req: http.ClientRequest,
|
|
21
|
-
reject: (error: Error) => void;
|
|
22
|
-
logger?: Logger;
|
|
23
|
-
}, cb: (buffers: Buffer[]) => void): void => {
|
|
24
|
-
try {
|
|
25
|
-
const buffers: Buffer[] = [];
|
|
26
|
-
|
|
27
|
-
if (readTimeout) {
|
|
28
|
-
clearTimeout(readTimeout);
|
|
29
|
-
}
|
|
30
|
-
const responseTimeout = options.timeout ? setTimeout(() => {
|
|
31
|
-
res.removeListener("data", chunkListener);
|
|
32
|
-
res.removeListener("error", errorListener)
|
|
33
|
-
res.removeListener("end", endListener);
|
|
34
|
-
req.end(() => {
|
|
35
|
-
try {
|
|
36
|
-
req.destroy();
|
|
37
|
-
res.destroy();
|
|
38
|
-
} catch (e) {
|
|
39
|
-
if (logger) {
|
|
40
|
-
logger.error(e);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
reject(new Error(`response timeout ${options.timeout}`));
|
|
44
|
-
return;
|
|
45
|
-
});
|
|
46
|
-
}, options.timeout) : null;
|
|
47
|
-
|
|
48
|
-
let responseLength = 0;
|
|
49
|
-
const chunkListener = (chunk: Buffer) => {
|
|
50
|
-
responseLength += chunk.length;
|
|
51
|
-
if (options.maxResponse && options.maxResponse < responseLength) {
|
|
52
|
-
res.removeListener("data", chunkListener);
|
|
53
|
-
res.removeListener("error", errorListener)
|
|
54
|
-
res.removeListener("end", endListener);
|
|
55
|
-
req.end(() => {
|
|
56
|
-
try {
|
|
57
|
-
req.destroy();
|
|
58
|
-
res.destroy();
|
|
59
|
-
} catch (e) {
|
|
60
|
-
if (logger) {
|
|
61
|
-
logger.error(e);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
reject(new Error(`response too big maxResponse ${options.maxResponse} < ${responseLength}`));
|
|
65
|
-
return;
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
buffers.push(chunk);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const errorListener = (e2: Error) => {
|
|
72
|
-
res.removeListener("data", chunkListener);
|
|
73
|
-
res.removeListener("end", endListener);
|
|
74
|
-
res.removeListener("error", errorListener);
|
|
75
|
-
try {
|
|
76
|
-
req.destroy();
|
|
77
|
-
res.destroy();
|
|
78
|
-
} catch (e) {
|
|
79
|
-
if (logger) {
|
|
80
|
-
logger.error(e);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
reject(e2);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const endListener = () => {
|
|
87
|
-
try {
|
|
88
|
-
if (responseTimeout) {
|
|
89
|
-
clearTimeout(responseTimeout);
|
|
90
|
-
}
|
|
91
|
-
res.removeListener("data", chunkListener);
|
|
92
|
-
res.removeListener("error", errorListener);
|
|
93
|
-
cb(buffers);
|
|
94
|
-
} catch (e: any) {
|
|
95
|
-
reject(e);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
// setup listeners
|
|
101
|
-
res.on("data", chunkListener);
|
|
102
|
-
res.once("error", errorListener)
|
|
103
|
-
res.once("end", endListener);
|
|
104
|
-
} catch (e3: any) {
|
|
105
|
-
// remove listeners
|
|
106
|
-
res.removeListener("data", chunkListener);
|
|
107
|
-
res.removeListener("end", endListener);
|
|
108
|
-
res.removeListener("error", errorListener);
|
|
109
|
-
reject(e3);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
} catch (e: any) {
|
|
113
|
-
reject(e);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export const parseRedirectLocation = (url: string, extraQuery?: SimpleMap<string | string[] | number | boolean | number[] | boolean[]>, socketPath?: string): {
|
|
119
|
-
protocol?: string;
|
|
120
|
-
queryStr: string;
|
|
121
|
-
pathname: string;
|
|
122
|
-
hash: string;
|
|
123
|
-
hostname?: string;
|
|
124
|
-
socketPath?: string;
|
|
125
|
-
port?: string;
|
|
126
|
-
url: string;
|
|
127
|
-
} => {
|
|
128
|
-
const ret = (urlO: URL, url: string, ignoreHostPort?: boolean) => {
|
|
129
|
-
return {
|
|
130
|
-
queryStr: mergeSearchParams(urlO.searchParams, extraQuery).toString(),
|
|
131
|
-
protocol: ignoreHostPort ? "http:" : urlO.protocol,
|
|
132
|
-
hash: urlO.hash,
|
|
133
|
-
pathname: urlO.pathname,
|
|
134
|
-
socketPath: ignoreHostPort ? socketPath : undefined,
|
|
135
|
-
hostname: ignoreHostPort ? undefined : urlO.hostname,
|
|
136
|
-
port: ignoreHostPort ? undefined : urlO.port,
|
|
137
|
-
url: ignoreHostPort ? url : urlO.toString()
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
return ret(newURL(url), url);
|
|
142
|
-
} catch (eU) {
|
|
143
|
-
if (url && url.length > 0 && url[0] === "/") {
|
|
144
|
-
return ret(newURL(`http://localhost${url}`), url, true);
|
|
145
|
-
} else {
|
|
146
|
-
throw eU;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export class ResponseError extends NamedError implements RequestResponse {
|
|
152
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
153
|
-
constructor(
|
|
154
|
-
public readonly status: number,
|
|
155
|
-
public readonly headers: http.IncomingHttpHeaders,
|
|
156
|
-
public readonly url: string,
|
|
157
|
-
public readonly redirectedUrl: string | null,
|
|
158
|
-
public readonly data: any,
|
|
159
|
-
public readonly buffer: Buffer,
|
|
160
|
-
public readonly locations: string[]
|
|
161
|
-
) {
|
|
162
|
-
super(`request ended with ${status ? `status [${status}]` : "no status"}`);
|
|
163
|
-
this.name = "ResponseError";
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export interface RequestOptions {
|
|
168
|
-
url: string;
|
|
169
|
-
method?: string;
|
|
170
|
-
query?: SimpleMap<string | string[] | number | boolean | number[] | boolean[]>;
|
|
171
|
-
socketPath?: string;
|
|
172
|
-
followRedirect?: boolean;
|
|
173
|
-
disableUserAgent?: true;
|
|
174
|
-
maxRedirects?: number;
|
|
175
|
-
maxResponse?: number;
|
|
176
|
-
locations?: string[];
|
|
177
|
-
timeout?: number;
|
|
178
|
-
disableThrow?: boolean;
|
|
179
|
-
headers?: http.OutgoingHttpHeaders;
|
|
180
|
-
data?: any;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface RequestResponse {
|
|
184
|
-
url: string;
|
|
185
|
-
redirectedUrl: string | null;
|
|
186
|
-
locations: string[];
|
|
187
|
-
headers: http.IncomingHttpHeaders,
|
|
188
|
-
status: number;
|
|
189
|
-
data: any;
|
|
190
|
-
buffer: Buffer;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../logger";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import https from "https";
|
|
4
|
-
import { parseRedirectLocation, RequestOptions, RequestResponse, ResponseError, readResponseBuffer } from "./common";
|
|
5
|
-
import { gunzipSync } from "zlib";
|
|
6
|
-
import { isBrowser } from "../config/browser";
|
|
7
|
-
|
|
8
|
-
export { RequestOptions, RequestResponse } from "./common";
|
|
9
|
-
|
|
10
|
-
const DEFAULT_USER_AGENT = "curl/7.69.1";
|
|
11
|
-
const CONTENT_TYPE_HEADER = "Content-Type";
|
|
12
|
-
const JSON_TYPE = "application/json;charset=utf-8";
|
|
13
|
-
const TEXT_TYPE = "plain/text;charset=utf-8";
|
|
14
|
-
|
|
15
|
-
export const request = (options: RequestOptions, logger?: Logger): Promise<RequestResponse> => {
|
|
16
|
-
if ((options.method && options.method.toLowerCase() === "get" || !options.method) && options.data !== undefined) {
|
|
17
|
-
return Promise.reject(new Error("cannot send data on method get"));
|
|
18
|
-
} else {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
try {
|
|
21
|
-
if (!options.headers) {
|
|
22
|
-
options.headers = {};
|
|
23
|
-
}
|
|
24
|
-
if (typeof options.maxRedirects === "undefined") {
|
|
25
|
-
options.maxRedirects = 10;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const contentType = options.headers[CONTENT_TYPE_HEADER] || options.headers[CONTENT_TYPE_HEADER.toLowerCase()] || undefined || options.headers[CONTENT_TYPE_HEADER.toUpperCase()];
|
|
29
|
-
const isJSONType = contentType ? contentType.toString().toLocaleLowerCase().indexOf("application/json") === 0 : undefined;
|
|
30
|
-
|
|
31
|
-
const noType = !contentType;
|
|
32
|
-
|
|
33
|
-
const isText: boolean = typeof options.data === "string";
|
|
34
|
-
const JsonStringify: boolean = (!isText && (noType || isJSONType as boolean));
|
|
35
|
-
|
|
36
|
-
if (JsonStringify && noType) {
|
|
37
|
-
options.headers["Content-Type"] = JSON_TYPE;
|
|
38
|
-
} else if (isText && noType) {
|
|
39
|
-
options.headers["Content-Type"] = TEXT_TYPE;
|
|
40
|
-
}
|
|
41
|
-
const data = options.data ? JsonStringify ? JSON.stringify(options.data) : options.data : undefined;
|
|
42
|
-
const contentLength = data ? Buffer.from(data).length : 0;
|
|
43
|
-
|
|
44
|
-
// { socketPath, protocol, queryStr, hash, pathname, hostname, port }
|
|
45
|
-
const parsed = parseRedirectLocation(options.url, options.query, options.socketPath);
|
|
46
|
-
|
|
47
|
-
if (!parsed.socketPath && !parsed.hostname) {
|
|
48
|
-
throw new Error(`Bad url ${options.url}`);
|
|
49
|
-
}
|
|
50
|
-
switch (parsed.protocol) {
|
|
51
|
-
case "https:":
|
|
52
|
-
case "http:":
|
|
53
|
-
const readTimeout = options.timeout ? setTimeout(() => {
|
|
54
|
-
try {
|
|
55
|
-
req.end(() => {
|
|
56
|
-
try {
|
|
57
|
-
req.destroy();
|
|
58
|
-
} catch (e) {
|
|
59
|
-
if (logger) {
|
|
60
|
-
logger.error(e);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
reject(new Error(`response timeout ${options.timeout}`));
|
|
64
|
-
return;
|
|
65
|
-
});
|
|
66
|
-
} catch (e) {
|
|
67
|
-
reject(e);
|
|
68
|
-
}
|
|
69
|
-
}, options.timeout) : null;
|
|
70
|
-
const req: http.ClientRequest = (parsed.protocol === "https:" ? https.request : http.request)({
|
|
71
|
-
agent: false,
|
|
72
|
-
path: `${parsed.pathname}${parsed.queryStr ? `?${parsed.queryStr}` : ""}${parsed.hash ? parsed.hash : ""}`,
|
|
73
|
-
method: options.method,
|
|
74
|
-
socketPath: options.socketPath,
|
|
75
|
-
headers: options.disableUserAgent ? {
|
|
76
|
-
["Content-Length"]: contentLength,
|
|
77
|
-
...options.headers
|
|
78
|
-
} : {
|
|
79
|
-
["User-Agent"]: DEFAULT_USER_AGENT,
|
|
80
|
-
["Content-Length"]: contentLength,
|
|
81
|
-
...options.headers
|
|
82
|
-
},
|
|
83
|
-
timeout: options.timeout,
|
|
84
|
-
hostname: parsed.hostname,
|
|
85
|
-
port: parsed.port
|
|
86
|
-
}, (res: http.IncomingMessage) => readResponseBuffer({
|
|
87
|
-
options,
|
|
88
|
-
req,
|
|
89
|
-
readTimeout,
|
|
90
|
-
logger,
|
|
91
|
-
reject,
|
|
92
|
-
res
|
|
93
|
-
}, (buffers) => {
|
|
94
|
-
try {
|
|
95
|
-
const responseBuffer: Buffer = res.headers["content-encoding"] === "gzip" && !isBrowser() ?
|
|
96
|
-
gunzipSync(Buffer.concat(buffers)) : Buffer.concat(buffers);
|
|
97
|
-
let data: any = responseBuffer.toString();
|
|
98
|
-
|
|
99
|
-
const contentType = res.headers["content-type"];
|
|
100
|
-
if (contentType && data && (contentType.indexOf("json") !== -1)) {
|
|
101
|
-
data = JSON.parse(responseBuffer.toString());
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const status = res.statusCode;
|
|
105
|
-
if (!status) {
|
|
106
|
-
const err = new ResponseError(status as any, res.headers, options.url, null, data, responseBuffer, options.locations ? options.locations : []);
|
|
107
|
-
reject(err);
|
|
108
|
-
return;
|
|
109
|
-
} else if (status >= 300 && status < 400 && options.followRedirect) {
|
|
110
|
-
// follow redirect
|
|
111
|
-
const location = res.headers["location"];
|
|
112
|
-
try {
|
|
113
|
-
if (!location) {
|
|
114
|
-
reject(new Error(`[${location}] not valid from ${options.url}`));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
// parse location and add query data from current location
|
|
118
|
-
const locationData = parseRedirectLocation(location, options.query, options.socketPath);
|
|
119
|
-
|
|
120
|
-
// if no host is set in location header set the current header and protocol
|
|
121
|
-
// protocol is infered from current location
|
|
122
|
-
if (!locationData.hostname && parsed.hostname && !locationData.socketPath) {
|
|
123
|
-
locationData.url = `${parsed.protocol}//${parsed.hostname}${parsed.port ? `:${parsed.port}` : ""}${locationData.url}`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (logger) {
|
|
127
|
-
logger.debug(`redirecting to [${locationData.url}] from [${options.url}][${status}]`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// avoid loop redirect
|
|
131
|
-
if (options.url === locationData.url || (options.locations && options.locations.indexOf(locationData.url) !== -1)) {
|
|
132
|
-
reject(new Error(`loop redirect to [${location}] from [${options.url}][${status}] locations ${options.locations ? options.locations.join(",") : "[]"}`));
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// append new location
|
|
137
|
-
options.locations = options.locations ? options.locations.concat([locationData.url]) : [options.url, locationData.url];
|
|
138
|
-
|
|
139
|
-
// check options.maxRedirects
|
|
140
|
-
if (options.maxRedirects !== undefined && (options.locations.length - 1) > options.maxRedirects) {
|
|
141
|
-
reject(new Error(`too many redirects to [${location}] from [${options.url}][${status}]`));
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// request new location pass current options
|
|
146
|
-
request({
|
|
147
|
-
...options,
|
|
148
|
-
socketPath: locationData.socketPath,
|
|
149
|
-
url: locationData.url,
|
|
150
|
-
locations: options.locations
|
|
151
|
-
}, logger).then((ret) => {
|
|
152
|
-
resolve({
|
|
153
|
-
...ret,
|
|
154
|
-
url: options.url,
|
|
155
|
-
redirectedUrl: ret.locations && ret.locations.length > 0 ? ret.locations[ret.locations.length - 1] : ret.url
|
|
156
|
-
});
|
|
157
|
-
return;
|
|
158
|
-
}).catch((e4: any) => {
|
|
159
|
-
// bad redirect
|
|
160
|
-
if (e4.url && e4.status && e4.headers && e4.data) {
|
|
161
|
-
const err = new ResponseError(e4.status, e4.headers, e4.url, e4.redirectedUrl, e4.data, e4.buffer, e4.locations ? e4.locations : (options.locations ? options.locations : []));
|
|
162
|
-
err.stack = e4.stack;
|
|
163
|
-
reject(err);
|
|
164
|
-
return;
|
|
165
|
-
} else {
|
|
166
|
-
(e4 as any).redirectedUrl = locationData.url;
|
|
167
|
-
(e4 as any).locations = options.locations;
|
|
168
|
-
(e4 as any).url = options.url;
|
|
169
|
-
reject(e4);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
return;
|
|
174
|
-
} catch (e5) {
|
|
175
|
-
reject(new ResponseError(status, res.headers, options.url, location ? location : null, data, responseBuffer, options.locations ? options.locations : []));
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
} else if (status >= 200 && status < 300) {
|
|
179
|
-
// always resolve with 2xx
|
|
180
|
-
resolve({
|
|
181
|
-
url: options.url,
|
|
182
|
-
status,
|
|
183
|
-
locations: options.locations ? options.locations : [],
|
|
184
|
-
redirectedUrl: null,
|
|
185
|
-
headers: res.headers,
|
|
186
|
-
data,
|
|
187
|
-
buffer: responseBuffer
|
|
188
|
-
});
|
|
189
|
-
return;
|
|
190
|
-
} else {
|
|
191
|
-
if (options.disableThrow && status !== undefined) {
|
|
192
|
-
// disable throw and resolve with 4xx 5xx etc
|
|
193
|
-
resolve({
|
|
194
|
-
url: options.url,
|
|
195
|
-
status,
|
|
196
|
-
locations: options.locations ? options.locations : [],
|
|
197
|
-
redirectedUrl: null,
|
|
198
|
-
headers: res.headers,
|
|
199
|
-
data,
|
|
200
|
-
buffer: responseBuffer
|
|
201
|
-
});
|
|
202
|
-
} else {
|
|
203
|
-
// throw with 4xx 5xx etc
|
|
204
|
-
const err = new ResponseError(status, res.headers, options.url, null, data, responseBuffer, options.locations ? options.locations : []);
|
|
205
|
-
reject(err);
|
|
206
|
-
}
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
} catch (e: any) {
|
|
210
|
-
reject(e);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
}))
|
|
214
|
-
req.once("error", (e: Error) => {
|
|
215
|
-
if ((e as any).code === "ECONNREFUSED") {
|
|
216
|
-
e.name = "ResponseConnectionRefusedError";
|
|
217
|
-
}
|
|
218
|
-
reject(e);
|
|
219
|
-
});
|
|
220
|
-
req.end(data);
|
|
221
|
-
break;
|
|
222
|
-
default:
|
|
223
|
-
reject(new Error(`unknown protocol [${parsed.protocol}]`))
|
|
224
|
-
}
|
|
225
|
-
} catch (e) {
|
|
226
|
-
reject(e);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SimpleMap, SimpleTypes } from "../parser/common";
|
|
2
|
-
|
|
3
|
-
export interface NoTokenSession extends SimpleMap<SimpleTypes> {
|
|
4
|
-
account: string;
|
|
5
|
-
username: string;
|
|
6
|
-
groups: string[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface Session extends NoTokenSession {
|
|
10
|
-
token: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type GroupPolicyType = "at_least_one" | "all";
|
|
14
|
-
|
|
15
|
-
export type GroupPolicyGroups = string | string[];
|
|
16
|
-
|
|
17
|
-
export interface GroupPolicy {
|
|
18
|
-
groups: GroupPolicyGroups[];
|
|
19
|
-
groupPolicy: GroupPolicyType;
|
|
20
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { Session, NoTokenSession } from "./common";
|
|
2
|
-
import { Context } from "../../handler/common";
|
|
3
|
-
import { checkEnvVariables } from "../config";
|
|
4
|
-
import { UnAuthorizedError } from "../error";
|
|
5
|
-
import { request, RequestOptions, RequestResponse } from "../request";
|
|
6
|
-
import { parse } from "../parser";
|
|
7
|
-
import { parse as cookieParse } from "cookie";
|
|
8
|
-
|
|
9
|
-
const DEFAULT_TOKEN_LOCATION = "header";
|
|
10
|
-
const DEFAULT_TOKEN_HEADER = "Authorization";
|
|
11
|
-
const DEFAULT_TOKEN_QUERY = "token";
|
|
12
|
-
const DEFAULT_TOKEN_COOKIE = "Authorization";
|
|
13
|
-
|
|
14
|
-
export interface VerifyTokenService {
|
|
15
|
-
verify(args: { token: string; ctx: Context }): Promise<Session | null>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface VerifyEndpointServiceOptions {
|
|
19
|
-
url: string;
|
|
20
|
-
method: string;
|
|
21
|
-
tokenLocation: "header" | "query" | "cookie";
|
|
22
|
-
tokenLocationName: string | ((ctx: Context) => Promise<string>);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class VerifyEndpointService implements VerifyTokenService {
|
|
26
|
-
|
|
27
|
-
protected options: VerifyEndpointServiceOptions;
|
|
28
|
-
|
|
29
|
-
constructor(options?: VerifyEndpointServiceOptions) {
|
|
30
|
-
if (!options) {
|
|
31
|
-
const [url, method] = checkEnvVariables(["TOKEN_VERIFY_ENDPOINT", "TOKEN_VERIFY_ENDPOINT_METHOD"]);
|
|
32
|
-
const [tokenVerifyLocation] = checkEnvVariables(["TOKEN_VERIFY_LOCATION"], [DEFAULT_TOKEN_LOCATION]);
|
|
33
|
-
let tokenLocationName;
|
|
34
|
-
switch (tokenVerifyLocation) {
|
|
35
|
-
case "header":
|
|
36
|
-
tokenLocationName = checkEnvVariables(["TOKEN_HEADER"], [DEFAULT_TOKEN_HEADER])[0];
|
|
37
|
-
break;
|
|
38
|
-
case "query":
|
|
39
|
-
tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
|
|
40
|
-
break;
|
|
41
|
-
case "cookie":
|
|
42
|
-
tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header or query)`);
|
|
46
|
-
}
|
|
47
|
-
this.options = {
|
|
48
|
-
url, method,
|
|
49
|
-
tokenLocation: tokenVerifyLocation,
|
|
50
|
-
tokenLocationName
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
this.options = parse("options", options as any, [
|
|
54
|
-
{ name: "url", required: true, type: "string", stringMinLength: 1 },
|
|
55
|
-
{ name: "method", required: true, type: "string", stringMinLength: 1 },
|
|
56
|
-
{ name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
|
|
57
|
-
{ name: "tokenLocationName", required: true, type: "any" }
|
|
58
|
-
], "no_extra") as any;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public async verify({ token, ctx }: { token: string; ctx: Context }): Promise<Session | null> {
|
|
63
|
-
try {
|
|
64
|
-
let response = null;
|
|
65
|
-
const tokenVerifyLocation = this.options.tokenLocation;
|
|
66
|
-
const url = this.options.url;
|
|
67
|
-
const method = this.options.method;
|
|
68
|
-
switch (tokenVerifyLocation) {
|
|
69
|
-
case "header":
|
|
70
|
-
const tokenHeaderLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
|
|
71
|
-
ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_HEADER=[${tokenHeaderLocation}]`);
|
|
72
|
-
response = await this.getResponse({
|
|
73
|
-
url,
|
|
74
|
-
headers: {
|
|
75
|
-
[tokenHeaderLocation]: token
|
|
76
|
-
},
|
|
77
|
-
method
|
|
78
|
-
}, ctx);
|
|
79
|
-
break;
|
|
80
|
-
case "query":
|
|
81
|
-
const tokenQueryLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
|
|
82
|
-
ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_QUERY=[${tokenQueryLocation}]`);
|
|
83
|
-
response = await this.getResponse({
|
|
84
|
-
url,
|
|
85
|
-
query: {
|
|
86
|
-
[tokenQueryLocation]: token
|
|
87
|
-
},
|
|
88
|
-
method
|
|
89
|
-
}, ctx);
|
|
90
|
-
break;
|
|
91
|
-
case "cookie":
|
|
92
|
-
const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
|
|
93
|
-
ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_COOKIE=[${tokenCookieLocation}]`);
|
|
94
|
-
response = await this.getResponse({
|
|
95
|
-
url,
|
|
96
|
-
method,
|
|
97
|
-
headers: {
|
|
98
|
-
Cookie: `${tokenCookieLocation}=${token}; Path=/; HttpOnly;`
|
|
99
|
-
}
|
|
100
|
-
}, ctx);
|
|
101
|
-
break;
|
|
102
|
-
default:
|
|
103
|
-
throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header, query or cookie)`);
|
|
104
|
-
}
|
|
105
|
-
if (response) {
|
|
106
|
-
const session = await this.decodeSession(response, token, ctx);
|
|
107
|
-
if (!this.checkSession(session, ctx)) {
|
|
108
|
-
ctx.logger.warn(`unauthorized token not valid [${token}]`);
|
|
109
|
-
return null;
|
|
110
|
-
} else {
|
|
111
|
-
ctx.logger.trace("token [%s]authorized!", token);
|
|
112
|
-
|
|
113
|
-
if (tokenVerifyLocation === "cookie" && response.headers["set-cookie"]) {
|
|
114
|
-
const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
|
|
115
|
-
const cookies = response.headers["set-cookie"].map(c => cookieParse(c)).filter(c => c[tokenCookieLocation] !== undefined);
|
|
116
|
-
if (cookies.length === 1) {
|
|
117
|
-
const value = cookies[0][tokenCookieLocation];
|
|
118
|
-
if (value) {
|
|
119
|
-
session.token = value; // replace token because token update via set-cookie
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
token,
|
|
125
|
-
...session
|
|
126
|
-
} as Session;
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
ctx.logger.warn(`unauthorized token not valid [${token}]`);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
} catch (e: any) {
|
|
133
|
-
throw new UnAuthorizedError(`Fail to authenticate token! error verifying [${token}] [${e.status}][${e.config ? e.config.url : ""}]`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
137
|
-
protected async getResponse(config: RequestOptions, ctx?: Context): Promise<RequestResponse> {
|
|
138
|
-
return request(config);
|
|
139
|
-
}
|
|
140
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
141
|
-
protected checkSession(session: NoTokenSession, ctx?: Context): boolean {
|
|
142
|
-
parse("session", session, [
|
|
143
|
-
{ name: "username", required: true, type: "string" },
|
|
144
|
-
{ name: "account", required: true, type: "string" },
|
|
145
|
-
{ name: "groups", required: true, type: "array", arrayType: "string" }
|
|
146
|
-
], "add_extra");
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
150
|
-
protected async decodeSession(response: RequestResponse, token: string, ctx?: Context): Promise<NoTokenSession> {
|
|
151
|
-
const session = response.data;
|
|
152
|
-
return session as NoTokenSession;
|
|
153
|
-
}
|
|
154
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"typedocOptions": {
|
|
3
|
-
"entryPoints": ["src/index.ts"],
|
|
4
|
-
"out": "docs"
|
|
5
|
-
},
|
|
6
|
-
"compileOnSave": true,
|
|
7
|
-
"compilerOptions": {
|
|
8
|
-
"lib": ["es2021"],
|
|
9
|
-
"module": "commonjs",
|
|
10
|
-
"target": "es2021",
|
|
11
|
-
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
|
|
17
|
-
"outDir": "./dist/",
|
|
18
|
-
"removeComments": false,
|
|
19
|
-
"noImplicitAny": true,
|
|
20
|
-
"preserveConstEnums": true,
|
|
21
|
-
"sourceMap": true,
|
|
22
|
-
"declaration": true,
|
|
23
|
-
"moduleResolution": "node"
|
|
24
|
-
},
|
|
25
|
-
"include": [
|
|
26
|
-
"src/**/*"
|
|
27
|
-
],
|
|
28
|
-
"exclude": [
|
|
29
|
-
"node_modules/",
|
|
30
|
-
"test/",
|
|
31
|
-
]
|
|
32
|
-
}
|