@miqro/core 1.3.6 → 1.4.0
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 +36 -112
- package/dist/handler/api-router-utils.d.ts +12 -1
- package/dist/handler/api-router-utils.js +86 -1
- package/dist/handler/api-router-utils.js.map +1 -1
- package/dist/handler/api-router.d.ts +29 -2
- package/dist/handler/api-router.js +2 -2
- package/dist/handler/api-router.js.map +1 -1
- package/dist/handler/app.js +1 -0
- package/dist/handler/app.js.map +1 -1
- package/dist/handler/common/context.d.ts +3 -11
- package/dist/handler/common/context.js +18 -13
- package/dist/handler/common/context.js.map +1 -1
- package/dist/handler/common/index.js.map +1 -1
- package/dist/handler/common/router-utils.js +60 -5
- package/dist/handler/common/router-utils.js.map +1 -1
- package/dist/handler/index.d.ts +0 -3
- package/dist/handler/index.js +0 -3
- package/dist/handler/index.js.map +1 -1
- package/dist/handler/middleware/cookie.js +2 -2
- package/dist/handler/middleware/cookie.js.map +1 -1
- package/dist/handler/middleware/form.js +7 -1
- package/dist/handler/middleware/form.js.map +1 -1
- package/dist/handler/middleware/group.js +44 -2
- package/dist/handler/middleware/group.js.map +1 -1
- package/dist/handler/middleware/index.js +2 -6
- package/dist/handler/middleware/index.js.map +1 -1
- package/dist/handler/middleware/json.js +8 -2
- package/dist/handler/middleware/json.js.map +1 -1
- package/dist/handler/middleware/session.js.map +1 -1
- package/dist/handler/middleware/text.js +8 -1
- package/dist/handler/middleware/text.js.map +1 -1
- package/dist/handler/proxy.d.ts +2 -5
- package/dist/handler/proxy.js +2 -3
- package/dist/handler/proxy.js.map +1 -1
- package/dist/util/cli/index.d.ts +6 -1
- package/dist/util/cli/index.js +26 -0
- package/dist/util/cli/index.js.map +1 -1
- package/dist/util/error/configfilenotfound.js.map +1 -1
- package/dist/util/error/forbiddenerror.js.map +1 -1
- package/dist/util/error/notfound.js.map +1 -1
- package/dist/util/error/notimplemented.js.map +1 -1
- package/dist/util/error/parsererror.d.ts +2 -1
- package/dist/util/error/parsererror.js +5 -1
- package/dist/util/error/parsererror.js.map +1 -1
- package/dist/util/error/unauthorizederror.js.map +1 -1
- package/dist/util/index.d.ts +0 -1
- package/dist/util/index.js +0 -3
- package/dist/util/index.js.map +1 -1
- package/dist/util/loader/index.d.ts +0 -3
- package/dist/util/loader/index.js +2 -9
- package/dist/util/loader/index.js.map +1 -1
- package/dist/util/logger/formatter.js +1 -1
- package/dist/util/logger/formatter.js.map +1 -1
- package/dist/util/request/index.d.ts +1 -1
- package/dist/util/request/index.js +1 -3
- package/dist/util/request/index.js.map +1 -1
- package/dist/util/session/common.d.ts +0 -1
- package/dist/util/session/common.js +0 -46
- package/dist/util/session/common.js.map +1 -1
- package/dist/util/session/service.js +2 -2
- package/dist/util/session/service.js.map +1 -1
- package/package.json +14 -11
- package/src/handler/api-router-utils.ts +91 -2
- package/src/handler/api-router.ts +30 -4
- package/src/handler/app.ts +2 -1
- package/src/handler/common/context.ts +19 -24
- package/src/handler/common/index.ts +1 -2
- package/src/handler/common/router-utils.ts +194 -146
- package/src/handler/index.ts +0 -3
- package/src/handler/middleware/cookie.ts +12 -12
- package/src/handler/middleware/form.ts +8 -2
- package/src/handler/middleware/group.ts +44 -2
- package/src/handler/middleware/index.ts +24 -28
- package/src/handler/middleware/json.ts +9 -3
- package/src/handler/middleware/session.ts +128 -128
- package/src/handler/middleware/text.ts +8 -1
- package/src/handler/proxy.ts +3 -8
- package/src/util/cli/index.ts +25 -1
- package/src/util/error/configfilenotfound.ts +1 -1
- package/src/util/error/forbiddenerror.ts +1 -1
- package/src/util/error/notfound.ts +1 -1
- package/src/util/error/notimplemented.ts +1 -1
- package/src/util/error/parsererror.ts +7 -2
- package/src/util/error/unauthorizederror.ts +1 -1
- package/src/util/index.ts +0 -3
- package/src/util/loader/index.ts +1 -7
- package/src/util/logger/formatter.ts +1 -1
- package/src/util/parser/common.ts +1 -1
- package/src/util/parser/index.ts +0 -3
- package/src/util/request/index.ts +2 -2
- package/src/util/session/common.ts +0 -43
- package/src/util/session/index.ts +1 -1
- package/src/util/session/service.ts +126 -126
- package/dist/handler/api-handler.d.ts +0 -29
- package/dist/handler/api-handler.js +0 -42
- package/dist/handler/api-handler.js.map +0 -1
- package/dist/handler/feature-router.d.ts +0 -12
- package/dist/handler/feature-router.js +0 -90
- package/dist/handler/feature-router.js.map +0 -1
- package/dist/handler/response/html.d.ts +0 -10
- package/dist/handler/response/html.js +0 -34
- package/dist/handler/response/html.js.map +0 -1
- package/dist/handler/response/index.d.ts +0 -3
- package/dist/handler/response/index.js +0 -16
- package/dist/handler/response/index.js.map +0 -1
- package/dist/handler/response/json.d.ts +0 -2
- package/dist/handler/response/json.js +0 -21
- package/dist/handler/response/json.js.map +0 -1
- package/dist/handler/response/result.d.ts +0 -4
- package/dist/handler/response/result.js +0 -46
- package/dist/handler/response/result.js.map +0 -1
- package/dist/util/client.d.ts +0 -17
- package/dist/util/client.js +0 -55
- package/dist/util/client.js.map +0 -1
- package/dist/util/cookie/cookie.d.ts +0 -50
- package/dist/util/cookie/cookie.js +0 -168
- package/dist/util/cookie/cookie.js.map +0 -1
- package/dist/util/cookie/index.d.ts +0 -16
- package/dist/util/cookie/index.js +0 -9
- package/dist/util/cookie/index.js.map +0 -1
- package/dist/util/test/app.d.ts +0 -3
- package/dist/util/test/app.js +0 -50
- package/dist/util/test/app.js.map +0 -1
- package/dist/util/test/common.d.ts +0 -6
- package/dist/util/test/common.js +0 -15
- package/dist/util/test/common.js.map +0 -1
- package/dist/util/test/index.d.ts +0 -2
- package/dist/util/test/index.js +0 -15
- package/dist/util/test/index.js.map +0 -1
- package/dist/util/uuid/index.d.ts +0 -7
- package/dist/util/uuid/index.js +0 -8
- package/dist/util/uuid/index.js.map +0 -1
- package/dist/util/uuid/regex.d.ts +0 -2
- package/dist/util/uuid/regex.js +0 -5
- package/dist/util/uuid/regex.js.map +0 -1
- package/dist/util/uuid/rng.d.ts +0 -1
- package/dist/util/uuid/rng.js +0 -18
- package/dist/util/uuid/rng.js.map +0 -1
- package/dist/util/uuid/stringify.d.ts +0 -2
- package/dist/util/uuid/stringify.js +0 -50
- package/dist/util/uuid/stringify.js.map +0 -1
- package/dist/util/uuid/v4.d.ts +0 -5
- package/dist/util/uuid/v4.js +0 -27
- package/dist/util/uuid/v4.js.map +0 -1
- package/dist/util/uuid/validate.d.ts +0 -2
- package/dist/util/uuid/validate.js +0 -12
- package/dist/util/uuid/validate.js.map +0 -1
- package/src/handler/api-handler.ts +0 -55
- package/src/handler/feature-router.ts +0 -92
- package/src/handler/response/html.ts +0 -36
- package/src/handler/response/index.ts +0 -3
- package/src/handler/response/json.ts +0 -19
- package/src/handler/response/result.ts +0 -40
- package/src/util/client.ts +0 -64
- package/src/util/cookie/cookie.ts +0 -207
- package/src/util/cookie/index.ts +0 -6
- package/src/util/test/app.ts +0 -44
- package/src/util/test/common.ts +0 -17
- package/src/util/test/index.ts +0 -2
- package/src/util/uuid/index.ts +0 -5
- package/src/util/uuid/regex.ts +0 -2
- package/src/util/uuid/rng.ts +0 -14
- package/src/util/uuid/stringify.ts +0 -53
- package/src/util/uuid/v4.ts +0 -30
- package/src/util/uuid/validate.ts +0 -8
|
@@ -4,7 +4,7 @@ import { checkEnvVariables } from "../config";
|
|
|
4
4
|
import { UnAuthorizedError } from "../error";
|
|
5
5
|
import { request, RequestOptions, RequestResponse } from "../request";
|
|
6
6
|
import { parse } from "../parser";
|
|
7
|
-
import {
|
|
7
|
+
import { parse as cookieParse } from "cookie";
|
|
8
8
|
|
|
9
9
|
const DEFAULT_TOKEN_LOCATION = "header";
|
|
10
10
|
const DEFAULT_TOKEN_HEADER = "Authorization";
|
|
@@ -12,143 +12,143 @@ const DEFAULT_TOKEN_QUERY = "token";
|
|
|
12
12
|
const DEFAULT_TOKEN_COOKIE = "Authorization";
|
|
13
13
|
|
|
14
14
|
export interface VerifyTokenService {
|
|
15
|
-
|
|
15
|
+
verify(args: { token: string; ctx: Context }): Promise<Session | null>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface VerifyEndpointServiceOptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
url: string;
|
|
20
|
+
method: string;
|
|
21
|
+
tokenLocation: "header" | "query" | "cookie";
|
|
22
|
+
tokenLocationName: string | ((ctx: Context) => Promise<string>);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export class VerifyEndpointService implements VerifyTokenService {
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
protected options: VerifyEndpointServiceOptions;
|
|
28
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
|
-
}
|
|
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;
|
|
60
59
|
}
|
|
60
|
+
}
|
|
61
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
|
-
}, ctx);
|
|
101
|
-
break;
|
|
102
|
-
default:
|
|
103
|
-
throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header, query or cookie)`);
|
|
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;`
|
|
104
99
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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;
|
|
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
|
+
}
|
|
131
121
|
}
|
|
132
|
-
|
|
133
|
-
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
token,
|
|
125
|
+
...session
|
|
126
|
+
} as Session;
|
|
134
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 : ""}]`);
|
|
135
134
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
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
|
+
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { GroupPolicy } from "../util/session";
|
|
2
|
-
import { SessionHandlerOptions } from "./middleware/session";
|
|
3
|
-
import { Parser } from "../util/parser";
|
|
4
|
-
import { ParseOptions } from "../util/parser/common";
|
|
5
|
-
import { Handler } from "./common";
|
|
6
|
-
export interface APIHandlerOptions {
|
|
7
|
-
parser?: Parser;
|
|
8
|
-
headers?: ParseOptions | ParseOptions[];
|
|
9
|
-
query?: ParseOptions | false | ParseOptions[];
|
|
10
|
-
params?: ParseOptions | false | ParseOptions[];
|
|
11
|
-
body?: ParseOptions | false | ParseOptions[];
|
|
12
|
-
result?: ParseOptions | ParseOptions[];
|
|
13
|
-
handler: Array<Handler> | Handler;
|
|
14
|
-
middleware?: Handler[];
|
|
15
|
-
session?: SessionHandlerOptions | Handler;
|
|
16
|
-
policy?: GroupPolicy;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* APIHandler
|
|
20
|
-
*
|
|
21
|
-
* ```typescript
|
|
22
|
-
*app.use(APIHandler({
|
|
23
|
-
* query: { ... },
|
|
24
|
-
* body: { ... },
|
|
25
|
-
* result: { ... }
|
|
26
|
-
*}));
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare const APIHandler: (options: APIHandlerOptions) => Array<Handler>;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APIHandler = void 0;
|
|
4
|
-
const session_1 = require("./middleware/session");
|
|
5
|
-
const group_1 = require("./middleware/group");
|
|
6
|
-
const parse_1 = require("./middleware/parse");
|
|
7
|
-
const json_1 = require("./response/json");
|
|
8
|
-
const result_1 = require("./response/result");
|
|
9
|
-
/**
|
|
10
|
-
* APIHandler
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
*app.use(APIHandler({
|
|
14
|
-
* query: { ... },
|
|
15
|
-
* body: { ... },
|
|
16
|
-
* result: { ... }
|
|
17
|
-
*}));
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
const APIHandler = (options) =>
|
|
21
|
-
// setup options.middleware
|
|
22
|
-
(options.middleware ? options.middleware : [])
|
|
23
|
-
// setup session
|
|
24
|
-
.concat(options.session ? typeof options.session === "function" ? [options.session] : [(0, session_1.SessionHandler)(options.session)] : [])
|
|
25
|
-
// setup policy
|
|
26
|
-
.concat(options.policy ? [(0, group_1.GroupPolicyHandler)(options.policy)] : [])
|
|
27
|
-
// setup request parse
|
|
28
|
-
.concat([(0, parse_1.ParseRequest)({
|
|
29
|
-
headers: options.headers,
|
|
30
|
-
query: options.query,
|
|
31
|
-
params: options.params,
|
|
32
|
-
body: options.body,
|
|
33
|
-
parser: options.parser
|
|
34
|
-
})])
|
|
35
|
-
// setup options.handler
|
|
36
|
-
.concat(options.handler instanceof Array ? options.handler : [options.handler])
|
|
37
|
-
// setup response parse
|
|
38
|
-
.concat(options.result ? (0, result_1.ResultParser)(options.result, options.parser) : [])
|
|
39
|
-
// setup response handler
|
|
40
|
-
.concat((0, json_1.ResponseHandler)());
|
|
41
|
-
exports.APIHandler = APIHandler;
|
|
42
|
-
//# sourceMappingURL=api-handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.js","sourceRoot":"","sources":["../../src/handler/api-handler.ts"],"names":[],"mappings":";;;AACA,kDAA6E;AAC7E,8CAAwD;AAIxD,8CAAkD;AAClD,0CAAkD;AAClD,8CAAiD;AAejD;;;;;;;;;;GAUG;AACI,MAAM,UAAU,GAAG,CAAC,OAA0B,EAAkB,EAAE;AACvE,2BAA2B;AAC3B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,gBAAgB;KACf,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,wBAAc,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7H,eAAe;KACd,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAA,0BAAkB,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,sBAAsB;KACrB,MAAM,CAAC,CAAC,IAAA,oBAAY,EAAC;QACpB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC,CAAC;IACJ,wBAAwB;KACvB,MAAM,CAAC,OAAO,CAAC,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/E,uBAAuB;KACtB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,qBAAY,EAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,yBAAyB;KACxB,MAAM,CAAC,IAAA,sBAAe,GAAE,CAAC,CAAC;AApBlB,QAAA,UAAU,cAoBQ"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { SimpleMap } from "../util/parser/common";
|
|
2
|
-
import { Logger } from "../util/logger";
|
|
3
|
-
import { Router, Handler, Method } from "./common";
|
|
4
|
-
import { RouterHandlerOptions } from "./common/router-utils";
|
|
5
|
-
export interface FeatureRouterPathOptions {
|
|
6
|
-
path: string | string[];
|
|
7
|
-
method: Method | Method[];
|
|
8
|
-
handler: Array<Handler> | Handler;
|
|
9
|
-
options?: RouterHandlerOptions;
|
|
10
|
-
}
|
|
11
|
-
export declare type FeatureRouterOptions = SimpleMap<FeatureRouterPathOptions>;
|
|
12
|
-
export declare const FeatureRouter: (options: FeatureRouterOptions, logger?: Logger | undefined) => Router;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FeatureRouter = void 0;
|
|
4
|
-
const featuretoggle_1 = require("../util/config/featuretoggle");
|
|
5
|
-
const tokenize_match_1 = require("./common/tokenize-match");
|
|
6
|
-
const common_1 = require("./common");
|
|
7
|
-
const FEATURE_ROUTER_METHODS = ["get", "post", "put", "delete", "patch", "options"];
|
|
8
|
-
const FeatureRouter = (options, logger) => {
|
|
9
|
-
const router = new common_1.Router();
|
|
10
|
-
const toSetup = Object.keys(options);
|
|
11
|
-
const enabled = [];
|
|
12
|
-
const disabled = [];
|
|
13
|
-
const enabledPaths = {};
|
|
14
|
-
for (const featureName of toSetup) {
|
|
15
|
-
const handlerOptions = options[featureName];
|
|
16
|
-
if (!handlerOptions) {
|
|
17
|
-
throw new Error(`no handler options for feature [${featureName}]`);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
const { path, handler: implementation, method } = handlerOptions;
|
|
21
|
-
if (!method) {
|
|
22
|
-
throw new Error(`no methods for feature [${featureName}]`);
|
|
23
|
-
}
|
|
24
|
-
else if (!implementation) {
|
|
25
|
-
throw new Error(`no implementation for feature [${featureName}]`);
|
|
26
|
-
}
|
|
27
|
-
else if (!path) {
|
|
28
|
-
throw new Error(`no path for feature [${featureName}]`);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
if (method instanceof Array) {
|
|
32
|
-
for (const m of method) {
|
|
33
|
-
if (FEATURE_ROUTER_METHODS.indexOf(m.toLowerCase()) === -1) {
|
|
34
|
-
throw new Error(`feature [${featureName}] method [${m.toUpperCase()}] not defined! use only [${FEATURE_ROUTER_METHODS.join(",")}]`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else if (FEATURE_ROUTER_METHODS.indexOf(method.toLowerCase()) === -1) {
|
|
39
|
-
throw new Error(`feature [${featureName}] method [${method.toUpperCase()}] not defined! use only [${FEATURE_ROUTER_METHODS.join(",")}]`);
|
|
40
|
-
}
|
|
41
|
-
const methods = method instanceof Array ? method : [method];
|
|
42
|
-
if ((0, featuretoggle_1.isFeatureEnabled)(featureName)) {
|
|
43
|
-
if (logger) {
|
|
44
|
-
logger.trace(`feature [${featureName}] enabled`);
|
|
45
|
-
}
|
|
46
|
-
enabled.push(featureName);
|
|
47
|
-
const paths = path instanceof Array ? path : [path];
|
|
48
|
-
for (const nnP of paths) {
|
|
49
|
-
const p = (0, tokenize_match_1.normalizePath)(nnP);
|
|
50
|
-
for (const m of methods) {
|
|
51
|
-
if (logger) {
|
|
52
|
-
logger.info("%s", featureName);
|
|
53
|
-
logger.info("\t%s:%s", m.toUpperCase(), p);
|
|
54
|
-
if (handlerOptions.___filePath) {
|
|
55
|
-
logger.info("\t%s", handlerOptions.___filePath);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (enabledPaths[`${p}${m}`] !== undefined) {
|
|
59
|
-
throw new Error(`${featureName} collides with feature ${enabledPaths[`${p}${m}`]} on path ${p} method ${m}`);
|
|
60
|
-
}
|
|
61
|
-
enabledPaths[`${p}${m}`] = featureName;
|
|
62
|
-
router.use(implementation, p, m.toLocaleLowerCase(), handlerOptions.options);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
if (logger) {
|
|
68
|
-
logger.debug("feature [%s] disabled", featureName);
|
|
69
|
-
}
|
|
70
|
-
disabled.push(featureName);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (logger && enabled.length > 0) {
|
|
76
|
-
logger.debug("enabled features [%s]", enabled.join(","));
|
|
77
|
-
}
|
|
78
|
-
if (logger) {
|
|
79
|
-
if (disabled.length > 0) {
|
|
80
|
-
logger.warn("disabled features [%s]", disabled.join(","));
|
|
81
|
-
logger.warn(`to enable them just add the env var <feature>=true`);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
logger.debug(`no features disabled`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return router;
|
|
88
|
-
};
|
|
89
|
-
exports.FeatureRouter = FeatureRouter;
|
|
90
|
-
//# sourceMappingURL=feature-router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feature-router.js","sourceRoot":"","sources":["../../src/handler/feature-router.ts"],"names":[],"mappings":";;;AAEA,gEAAgE;AAChE,4DAAwD;AACxD,qCAAmD;AAYnD,MAAM,sBAAsB,GAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAEvF,MAAM,aAAa,GAAG,CAAC,OAA6B,EAAE,MAAe,EAAU,EAAE;IACtF,MAAM,MAAM,GAAW,IAAI,eAAM,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,YAAY,GAAsB,EAAE,CAAC;IAC3C,KAAK,MAAM,WAAW,IAAI,OAAO,EAAE;QACjC,MAAM,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,CAAC,cAAc,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,WAAW,GAAG,CAAC,CAAC;SACpE;aAAM;YACL,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;YACjE,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,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I,MAAM,EAAE;QACV,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1D,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;SACnE;aAAM;YACL,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACtC;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAzEW,QAAA,aAAa,iBAyExB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { OutgoingHttpHeaders } from "http";
|
|
3
|
-
import { Context, Handler } from "../common";
|
|
4
|
-
export declare type HTMLResponseResult = string | {
|
|
5
|
-
status?: number;
|
|
6
|
-
headers?: OutgoingHttpHeaders;
|
|
7
|
-
body?: string;
|
|
8
|
-
template: (ctx: Context) => Promise<string>;
|
|
9
|
-
};
|
|
10
|
-
export declare const HTMLResponseHandler: () => Handler<void>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTMLResponseHandler = void 0;
|
|
4
|
-
const HTMLResponseHandler = () => async (ctx) => {
|
|
5
|
-
const results = ctx.results;
|
|
6
|
-
const lastResult = results[results.length - 1];
|
|
7
|
-
ctx.logger.trace(`last result is [${lastResult}]`);
|
|
8
|
-
if (lastResult && typeof lastResult === "string" ||
|
|
9
|
-
((typeof lastResult.headers === "object" || lastResult.headers === undefined) &&
|
|
10
|
-
(typeof lastResult.status === "number" || lastResult.status === undefined) &&
|
|
11
|
-
(typeof lastResult.body === "string" || typeof lastResult.template === "function"))) {
|
|
12
|
-
const status = typeof lastResult.status === "number" ? lastResult.status : 200;
|
|
13
|
-
const headers = typeof lastResult.headers === "object" ? lastResult.headers : {
|
|
14
|
-
"content-type": "text/html; charset=utf-8"
|
|
15
|
-
};
|
|
16
|
-
const toSend = lastResult.template ? await lastResult.template(ctx) : (typeof lastResult.body === "string" ? lastResult.body : lastResult);
|
|
17
|
-
if (typeof toSend === "string") {
|
|
18
|
-
ctx.logger.debug(`sending [${toSend}]`);
|
|
19
|
-
await ctx.end({
|
|
20
|
-
status,
|
|
21
|
-
headers,
|
|
22
|
-
body: toSend
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new Error("html result from HTMLResponseResult not string so last result not valid");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new Error("html result from HTMLResponseResult not string so last result not valid");
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
exports.HTMLResponseHandler = HTMLResponseHandler;
|
|
34
|
-
//# sourceMappingURL=html.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../../src/handler/response/html.ts"],"names":[],"mappings":";;;AAKO,MAAM,mBAAmB,GAAG,GAAkB,EAAE,CACrD,KAAK,EAAE,GAAY,EAAiB,EAAE;IACpC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/C,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,UAAU,GAAG,CAAC,CAAC;IACnD,IAAI,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ;QAC9C,CACE,CAAC,OAAO,UAAU,CAAC,OAAO,KAAK,QAAQ,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,CAAC;YAC5E,CAAC,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,CAAC;YAC1E,CAAC,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,CACnF,EACD;QACA,MAAM,MAAM,GAAG,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;QAC/E,MAAM,OAAO,GAAG,OAAO,UAAU,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5E,cAAc,EAAE,0BAA0B;SAC3C,CAAC;QACF,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3I,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,MAAM,GAAG,CAAC,CAAC;YACxC,MAAM,GAAG,CAAC,GAAG,CAAC;gBACZ,MAAM;gBACN,OAAO;gBACP,IAAI,EAAE,MAAM;aACb,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;SAC5F;KACF;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;KAC5F;AACH,CAAC,CAAA;AA9BU,QAAA,mBAAmB,uBA8B7B"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./html"), exports);
|
|
14
|
-
__exportStar(require("./json"), exports);
|
|
15
|
-
__exportStar(require("./result"), exports);
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handler/response/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,yCAAuB;AACvB,2CAAyB"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseHandler = void 0;
|
|
4
|
-
const ResponseHandler = () => async (ctx) => {
|
|
5
|
-
ctx.logger.trace("results [%o]", ctx.results);
|
|
6
|
-
if (!ctx.results || ctx.results.length === 0) {
|
|
7
|
-
throw new Error(`no response to send. Is your handler returning a value differente than boolean 'true|false' ?`);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
const lastResult = ctx.results[ctx.results.length - 1];
|
|
11
|
-
ctx.logger.debug("response [%o]", lastResult);
|
|
12
|
-
if (lastResult !== undefined) {
|
|
13
|
-
await ctx.json(lastResult);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
throw new Error(`no response to send. Is your handler returning a value differente than boolean 'true|false' ?`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
exports.ResponseHandler = ResponseHandler;
|
|
21
|
-
//# sourceMappingURL=json.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/handler/response/json.ts"],"names":[],"mappings":";;;AAEO,MAAM,eAAe,GAAG,GAAkB,EAAE,CACjD,KAAK,EAAE,GAAY,EAAiB,EAAE;IACpC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5C,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;KAClH;SAAM;QACL,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACvD,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAC9C,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC5B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;SAClH;KACF;AACH,CAAC,CAAC;AAdS,QAAA,eAAe,mBAcxB"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResultParser = void 0;
|
|
4
|
-
const util_1 = require("../../util");
|
|
5
|
-
const ResultParser = (options, parser) => async (ctx) => {
|
|
6
|
-
if (!ctx.results || ctx.results.length === 0) {
|
|
7
|
-
ctx.logger.debug(`not parsing results`);
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
const index = ctx.results.length - 1;
|
|
12
|
-
const lastResult = ctx.results[index];
|
|
13
|
-
ctx.logger.trace(`parsing lastResult[%o]`, lastResult);
|
|
14
|
-
try {
|
|
15
|
-
if (options instanceof Array) {
|
|
16
|
-
for (let i = 0; i < options.length; i++) {
|
|
17
|
-
const o = options[i];
|
|
18
|
-
try {
|
|
19
|
-
const mappedResults = (parser ? parser.parse : util_1.parse)(`ctx.results[${index}]`, lastResult, o.options, o.mode, o.ignoreUndefined);
|
|
20
|
-
ctx.logger.trace(`ctx.results[%s] mapped to %o`, index, mappedResults);
|
|
21
|
-
return mappedResults;
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
if (i === options.length - 1) {
|
|
25
|
-
throw e;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const mappedResults = (parser ? parser.parse : util_1.parse)(`ctx.results[${index}]`, lastResult, options.options, options.mode, options.ignoreUndefined);
|
|
35
|
-
ctx.logger.trace(`ctx.results[%s] mapped to %o`, index, mappedResults);
|
|
36
|
-
return mappedResults;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (e) {
|
|
40
|
-
ctx.logger.error(`error parsing lastResult[%o]`, lastResult);
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
exports.ResultParser = ResultParser;
|
|
46
|
-
//# sourceMappingURL=result.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/handler/response/result.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAIpC,MAAM,YAAY,GAAG,CAAC,OAAsC,EAAE,MAAe,EAAgB,EAAE,CACpG,KAAK,EAAE,GAAY,EAAgB,EAAE;IACnC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5C,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACxC,OAAO,SAAS,CAAC;KAClB;SAAM;QACL,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,MAA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