@sectester/repeater 0.27.0 → 0.28.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 +3 -3
- package/package.json +7 -4
- package/src/api/DefaultRepeatersManager.js.map +1 -1
- package/src/api/ExecuteRequestEventHandler.js +1 -1
- package/src/api/ExecuteRequestEventHandler.js.map +1 -1
- package/src/api/commands/index.d.ts +0 -1
- package/src/api/commands/index.js +1 -4
- package/src/api/commands/index.js.map +1 -1
- package/src/api/index.d.ts +0 -3
- package/src/api/index.js +0 -7
- package/src/api/index.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -2
- package/src/index.js.map +1 -1
- package/src/lib/DefaultRepeaterCommands.d.ts +7 -0
- package/src/lib/DefaultRepeaterCommands.js +26 -0
- package/src/lib/DefaultRepeaterCommands.js.map +1 -0
- package/src/lib/DefaultRepeaterServer.d.ts +57 -0
- package/src/lib/DefaultRepeaterServer.js +218 -0
- package/src/lib/DefaultRepeaterServer.js.map +1 -0
- package/src/lib/Repeater.d.ts +18 -15
- package/src/lib/Repeater.js +90 -62
- package/src/lib/Repeater.js.map +1 -1
- package/src/lib/RepeaterCommands.d.ts +5 -0
- package/src/lib/RepeaterCommands.js +5 -0
- package/src/lib/RepeaterCommands.js.map +1 -0
- package/src/lib/RepeaterFactory.d.ts +3 -4
- package/src/lib/RepeaterFactory.js +18 -35
- package/src/lib/RepeaterFactory.js.map +1 -1
- package/src/lib/RepeaterServer.d.ts +92 -0
- package/src/lib/RepeaterServer.js +15 -0
- package/src/lib/RepeaterServer.js.map +1 -0
- package/src/lib/index.d.ts +8 -5
- package/src/lib/index.js +9 -7
- package/src/lib/index.js.map +1 -1
- package/src/models/Protocol.d.ts +1 -2
- package/src/models/Protocol.js +0 -1
- package/src/models/Protocol.js.map +1 -1
- package/src/register.js +18 -4
- package/src/register.js.map +1 -1
- package/src/request-runner/Request.d.ts +13 -9
- package/src/request-runner/Request.js +9 -19
- package/src/request-runner/Request.js.map +1 -1
- package/src/request-runner/Response.d.ts +5 -3
- package/src/request-runner/Response.js +2 -1
- package/src/request-runner/Response.js.map +1 -1
- package/src/request-runner/protocols/HttpRequestRunner.d.ts +9 -7
- package/src/request-runner/protocols/HttpRequestRunner.js +100 -88
- package/src/request-runner/protocols/HttpRequestRunner.js.map +1 -1
- package/src/request-runner/protocols/index.d.ts +0 -1
- package/src/request-runner/protocols/index.js +0 -1
- package/src/request-runner/protocols/index.js.map +1 -1
- package/src/utils/DefaultProxyFactory.d.ts +20 -0
- package/src/utils/DefaultProxyFactory.js +66 -0
- package/src/utils/DefaultProxyFactory.js.map +1 -0
- package/src/utils/NormalizeZlibDeflateTransformStream.d.ts +8 -0
- package/src/utils/NormalizeZlibDeflateTransformStream.js +25 -0
- package/src/utils/NormalizeZlibDeflateTransformStream.js.map +1 -0
- package/src/utils/PatchedHttpsProxyAgent.d.ts +14 -0
- package/src/utils/PatchedHttpsProxyAgent.js +17 -0
- package/src/utils/PatchedHttpsProxyAgent.js.map +1 -0
- package/src/utils/ProxyFactory.d.ts +19 -0
- package/src/utils/ProxyFactory.js +5 -0
- package/src/utils/ProxyFactory.js.map +1 -0
- package/src/utils/index.d.ts +3 -0
- package/src/utils/index.js +7 -0
- package/src/utils/index.js.map +1 -0
- package/src/api/commands/RegisterRepeaterCommand.d.ts +0 -22
- package/src/api/commands/RegisterRepeaterCommand.js +0 -18
- package/src/api/commands/RegisterRepeaterCommand.js.map +0 -1
- package/src/api/events/RepeaterStatusEvent.d.ts +0 -10
- package/src/api/events/RepeaterStatusEvent.js +0 -11
- package/src/api/events/RepeaterStatusEvent.js.map +0 -1
- package/src/api/events/index.d.ts +0 -1
- package/src/api/events/index.js +0 -5
- package/src/api/events/index.js.map +0 -1
- package/src/request-runner/protocols/WsRequestRunner.d.ts +0 -24
- package/src/request-runner/protocols/WsRequestRunner.js +0 -149
- package/src/request-runner/protocols/WsRequestRunner.js.map +0 -1
|
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Request = void 0;
|
|
4
4
|
const url_1 = require("url");
|
|
5
5
|
class Request {
|
|
6
|
-
constructor({ protocol, method, url, body,
|
|
6
|
+
constructor({ protocol, method, url, body, timeout, maxContentSize, encoding, decompress = true, headers = {} }) {
|
|
7
7
|
var _a;
|
|
8
|
+
this._headers = {};
|
|
8
9
|
this.protocol = protocol;
|
|
9
|
-
this.
|
|
10
|
+
this.method = (_a = method === null || method === void 0 ? void 0 : method.toUpperCase()) !== null && _a !== void 0 ? _a : 'GET';
|
|
10
11
|
this.validateUrl(url);
|
|
11
|
-
this.url = url;
|
|
12
|
-
this.correlationIdRegex =
|
|
13
|
-
this.normalizeCorrelationIdRegex(correlationIdRegex);
|
|
14
|
-
this.setHeaders(headers);
|
|
12
|
+
this.url = url.trim();
|
|
15
13
|
this.precheckBody(body);
|
|
16
14
|
this.body = body;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
this.setHeaders(headers);
|
|
16
|
+
this.encoding = encoding;
|
|
17
|
+
this.timeout = timeout;
|
|
18
|
+
this.maxContentSize = maxContentSize;
|
|
19
|
+
this.decompress = !!decompress;
|
|
20
20
|
}
|
|
21
21
|
get headers() {
|
|
22
22
|
return this._headers;
|
|
@@ -50,16 +50,6 @@ class Request {
|
|
|
50
50
|
throw new Error('Body must be string.');
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
normalizeCorrelationIdRegex(correlationIdRegex) {
|
|
54
|
-
if (correlationIdRegex) {
|
|
55
|
-
try {
|
|
56
|
-
return new RegExp(correlationIdRegex, 'i');
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
throw new Error('Correlation id must be regular expression.');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
53
|
}
|
|
64
54
|
exports.Request = Request;
|
|
65
55
|
Request.SINGLE_VALUE_HEADERS = new Set([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/Request.ts"],"names":[],"mappings":";;;AACA,6BAA0B;
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/Request.ts"],"names":[],"mappings":";;;AACA,6BAA0B;AAc1B,MAAa,OAAO;IAqClB,YAAY,EACV,QAAQ,EACR,MAAM,EACN,GAAG,EACH,IAAI,EACJ,OAAO,EACP,cAAc,EACd,QAAQ,EACR,UAAU,GAAG,IAAI,EACjB,OAAO,GAAG,EAAE,EACG;;QApBT,aAAQ,GAAsC,EAAE,CAAC;QAqBvD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,EAAE,mCAAI,KAAK,CAAC;QAE7C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QAEtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;IACjC,CAAC;IAlCD,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IA8BM,UAAU,CAAC,OAA0C;QAC1D,MAAM,aAAa,GAAG;YACpB,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,OAAO;SACX,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CAChC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAC/B,CAAC,CAAC,KAAK,EAAE,KAAK,CAA8B,EAAE,EAAE,CAAC;YAC/C,KAAK;YACL,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBACpB,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;gBACnD,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;gBAClB,CAAC,CAAC,KAAK;SACV,CACF,CACF,CAAC;IACJ,CAAC;IAEO,WAAW,CAAC,GAAW;QAC7B,IAAI;YACF,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;SACd;QAAC,MAAM;YACN,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,YAAY,CAAC,IAAwB;QAC3C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACzC;IACH,CAAC;;AAhGH,0BAiGC;AAhGwB,4BAAoB,GACzC,IAAI,GAAG,CAAS;IACd,eAAe;IACf,qBAAqB;IACrB,gBAAgB;IAChB,cAAc;IACd,MAAM;IACN,MAAM;IACN,mBAAmB;IACnB,qBAAqB;IACrB,UAAU;IACV,cAAc;IACd,qBAAqB;IACrB,SAAS;IACT,YAAY;CACb,CAAC,CAAC"}
|
|
@@ -2,16 +2,18 @@ import { Protocol } from '../models';
|
|
|
2
2
|
export declare class Response {
|
|
3
3
|
readonly protocol: Protocol;
|
|
4
4
|
readonly statusCode?: number;
|
|
5
|
-
readonly headers?: Record<string, string | string[]
|
|
5
|
+
readonly headers?: Record<string, string | string[]>;
|
|
6
6
|
readonly body?: string;
|
|
7
|
+
readonly encoding?: 'base64';
|
|
7
8
|
readonly message?: string;
|
|
8
9
|
readonly errorCode?: string;
|
|
9
|
-
constructor({ protocol, statusCode, headers, body, message, errorCode }: {
|
|
10
|
+
constructor({ protocol, statusCode, headers, body, message, errorCode, encoding }: {
|
|
10
11
|
protocol: Protocol;
|
|
11
12
|
statusCode?: number;
|
|
12
13
|
message?: string;
|
|
13
14
|
errorCode?: string;
|
|
14
|
-
headers?: Record<string, string | string[]
|
|
15
|
+
headers?: Record<string, string | string[]>;
|
|
15
16
|
body?: string;
|
|
17
|
+
encoding?: 'base64';
|
|
16
18
|
});
|
|
17
19
|
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Response = void 0;
|
|
4
4
|
class Response {
|
|
5
|
-
constructor({ protocol, statusCode, headers, body, message, errorCode }) {
|
|
5
|
+
constructor({ protocol, statusCode, headers, body, message, errorCode, encoding }) {
|
|
6
6
|
this.protocol = protocol;
|
|
7
7
|
this.statusCode = statusCode;
|
|
8
8
|
this.headers = headers;
|
|
9
9
|
this.body = body;
|
|
10
10
|
this.errorCode = errorCode;
|
|
11
11
|
this.message = message;
|
|
12
|
+
this.encoding = encoding;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
exports.Response = Response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/Response.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/Response.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IASnB,YAAY,EACV,QAAQ,EACR,UAAU,EACV,OAAO,EACP,IAAI,EACJ,OAAO,EACP,SAAS,EACT,QAAQ,EAST;QACC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAlCD,4BAkCC"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { RequestRunner } from '../RequestRunner';
|
|
2
|
+
import { Response } from '../Response';
|
|
3
|
+
import { Request } from '../Request';
|
|
2
4
|
import { Protocol } from '../../models';
|
|
3
5
|
import { RequestRunnerOptions } from '../RequestRunnerOptions';
|
|
4
|
-
import {
|
|
5
|
-
import { Response } from '../Response';
|
|
6
|
+
import { ProxyFactory } from '../../utils';
|
|
6
7
|
import { Logger } from '@sectester/core';
|
|
7
8
|
export declare class HttpRequestRunner implements RequestRunner {
|
|
8
|
-
private readonly options;
|
|
9
9
|
private readonly logger;
|
|
10
|
-
private readonly
|
|
10
|
+
private readonly proxyFactory;
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly httpProxyAgent?;
|
|
13
|
+
private readonly httpsProxyAgent?;
|
|
11
14
|
private readonly httpAgent?;
|
|
12
15
|
private readonly httpsAgent?;
|
|
13
|
-
private readonly maxContentLength;
|
|
14
16
|
get protocol(): Protocol;
|
|
15
|
-
constructor(
|
|
17
|
+
constructor(logger: Logger, proxyFactory: ProxyFactory, options: RequestRunnerOptions);
|
|
16
18
|
run(options: Request): Promise<Response>;
|
|
17
|
-
private
|
|
19
|
+
private convertHeaders;
|
|
18
20
|
private request;
|
|
19
21
|
private createRequest;
|
|
20
22
|
private setTimeout;
|
|
@@ -2,154 +2,163 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpRequestRunner = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const Response_1 = require("../Response");
|
|
5
6
|
const models_1 = require("../../models");
|
|
6
7
|
const RequestRunnerOptions_1 = require("../RequestRunnerOptions");
|
|
7
|
-
const
|
|
8
|
-
const content_type_1 = require("content-type");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
9
|
const core_1 = require("@sectester/core");
|
|
10
|
-
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
11
10
|
const tsyringe_1 = require("tsyringe");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
11
|
+
const iconv_lite_1 = tslib_1.__importDefault(require("iconv-lite"));
|
|
12
|
+
const fast_content_type_parse_1 = require("fast-content-type-parse");
|
|
13
|
+
const node_url_1 = require("node:url");
|
|
14
|
+
const node_http_1 = tslib_1.__importDefault(require("node:http"));
|
|
15
|
+
const node_https_1 = tslib_1.__importDefault(require("node:https"));
|
|
16
|
+
const node_events_1 = require("node:events");
|
|
17
|
+
const node_zlib_1 = require("node:zlib");
|
|
17
18
|
let HttpRequestRunner = class HttpRequestRunner {
|
|
18
|
-
constructor(
|
|
19
|
-
this.options = options;
|
|
19
|
+
constructor(logger, proxyFactory, options) {
|
|
20
20
|
this.logger = logger;
|
|
21
|
+
this.proxyFactory = proxyFactory;
|
|
22
|
+
this.options = options;
|
|
21
23
|
if (this.options.proxyUrl) {
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
});
|
|
24
|
+
({ httpsAgent: this.httpsProxyAgent, httpAgent: this.httpProxyAgent } =
|
|
25
|
+
this.proxyFactory.createProxy({ proxyUrl: this.options.proxyUrl }));
|
|
25
26
|
}
|
|
26
|
-
this.maxContentLength =
|
|
27
|
-
typeof this.options.maxContentLength === 'number'
|
|
28
|
-
? this.options.maxContentLength
|
|
29
|
-
: -1;
|
|
30
27
|
if (this.options.reuseConnection) {
|
|
31
28
|
const agentOptions = {
|
|
32
29
|
keepAlive: true,
|
|
33
30
|
maxSockets: 100,
|
|
34
31
|
timeout: this.options.timeout
|
|
35
32
|
};
|
|
36
|
-
this.httpsAgent = new
|
|
37
|
-
this.httpAgent = new
|
|
33
|
+
this.httpsAgent = new node_https_1.default.Agent(agentOptions);
|
|
34
|
+
this.httpAgent = new node_http_1.default.Agent(agentOptions);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
get protocol() {
|
|
41
38
|
return models_1.Protocol.HTTP;
|
|
42
39
|
}
|
|
43
40
|
async run(options) {
|
|
41
|
+
var _a;
|
|
44
42
|
try {
|
|
45
43
|
if (this.options.headers) {
|
|
46
44
|
options.setHeaders(this.options.headers);
|
|
47
45
|
}
|
|
48
46
|
this.logger.debug('Executing HTTP request with following params: %j', options);
|
|
49
|
-
const
|
|
47
|
+
const { res, body } = await this.request(options);
|
|
50
48
|
return new Response_1.Response({
|
|
49
|
+
body,
|
|
51
50
|
protocol: this.protocol,
|
|
52
|
-
statusCode:
|
|
53
|
-
headers:
|
|
54
|
-
|
|
51
|
+
statusCode: res.statusCode,
|
|
52
|
+
headers: this.convertHeaders(res.headers),
|
|
53
|
+
encoding: options.encoding
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
catch (err) {
|
|
58
|
-
|
|
57
|
+
const { cause } = err;
|
|
58
|
+
const { message, code, syscall, name } = cause !== null && cause !== void 0 ? cause : err;
|
|
59
|
+
const errorCode = (_a = code !== null && code !== void 0 ? code : syscall) !== null && _a !== void 0 ? _a : name;
|
|
60
|
+
this.logger.error('Error executing request: "%s %s HTTP/1.1"', options.method, options.url);
|
|
61
|
+
this.logger.error('Cause: %s', message);
|
|
62
|
+
return new Response_1.Response({
|
|
63
|
+
message,
|
|
64
|
+
errorCode,
|
|
65
|
+
protocol: this.protocol
|
|
66
|
+
});
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (typeof errorCode !== 'string') {
|
|
67
|
-
errorCode = Error.name;
|
|
68
|
-
}
|
|
69
|
-
this.logger.error('Error executing request: "%s %s HTTP/1.1"', options.method, options.url);
|
|
70
|
-
this.logger.error('Cause: %s', message);
|
|
71
|
-
return new Response_1.Response({
|
|
72
|
-
message,
|
|
73
|
-
errorCode,
|
|
74
|
-
protocol: this.protocol
|
|
75
|
-
});
|
|
69
|
+
convertHeaders(headers) {
|
|
70
|
+
return Object.fromEntries(Object.entries(headers).map(([name, value]) => [
|
|
71
|
+
name,
|
|
72
|
+
value !== null && value !== void 0 ? value : ''
|
|
73
|
+
]));
|
|
76
74
|
}
|
|
77
75
|
async request(options) {
|
|
78
|
-
const ac = new AbortController();
|
|
79
|
-
const { signal } = ac;
|
|
80
76
|
let timer;
|
|
81
77
|
let res;
|
|
82
78
|
try {
|
|
83
|
-
const req = this.createRequest(options
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
const req = this.createRequest(options);
|
|
80
|
+
process.nextTick(() => req.end(options.encoding && options.body
|
|
81
|
+
? iconv_lite_1.default.encode(options.body, options.encoding)
|
|
82
|
+
: options.body));
|
|
83
|
+
timer = this.setTimeout(req, options.timeout);
|
|
84
|
+
[res] = (await (0, node_events_1.once)(req, 'response'));
|
|
89
85
|
}
|
|
90
86
|
finally {
|
|
91
87
|
clearTimeout(timer);
|
|
92
88
|
}
|
|
93
|
-
return this.truncateResponse(res);
|
|
89
|
+
return this.truncateResponse(options, res);
|
|
94
90
|
}
|
|
95
|
-
createRequest(request
|
|
96
|
-
const protocol = request.secureEndpoint ?
|
|
97
|
-
const outgoingMessage = protocol.request(this.createRequestOptions(request
|
|
91
|
+
createRequest(request) {
|
|
92
|
+
const protocol = request.secureEndpoint ? node_https_1.default : node_http_1.default;
|
|
93
|
+
const outgoingMessage = protocol.request(this.createRequestOptions(request));
|
|
98
94
|
this.setHeaders(outgoingMessage, request);
|
|
99
95
|
if (!outgoingMessage.hasHeader('accept-encoding')) {
|
|
100
96
|
outgoingMessage.setHeader('accept-encoding', 'gzip, deflate');
|
|
101
97
|
}
|
|
102
98
|
return outgoingMessage;
|
|
103
99
|
}
|
|
104
|
-
setTimeout(
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
setTimeout(req, timeout) {
|
|
101
|
+
timeout !== null && timeout !== void 0 ? timeout : (timeout = this.options.timeout);
|
|
102
|
+
if (typeof timeout === 'number') {
|
|
103
|
+
return setTimeout(() => req.destroy(new Error('Waiting response has timed out')), timeout);
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
|
-
createRequestOptions(request
|
|
110
|
-
|
|
106
|
+
createRequestOptions(request) {
|
|
107
|
+
var _a;
|
|
108
|
+
const { auth, hostname, port, hash = '', pathname = '/', search = '' } = (0, node_url_1.parse)(request.url);
|
|
111
109
|
const path = `${pathname !== null && pathname !== void 0 ? pathname : '/'}${search !== null && search !== void 0 ? search : ''}${hash !== null && hash !== void 0 ? hash : ''}`;
|
|
112
110
|
const agent = this.getRequestAgent(request);
|
|
111
|
+
const timeout = (_a = request.timeout) !== null && _a !== void 0 ? _a : this.options.timeout;
|
|
113
112
|
return {
|
|
114
|
-
...options,
|
|
115
113
|
hostname,
|
|
116
114
|
port,
|
|
117
115
|
path,
|
|
118
116
|
auth,
|
|
119
117
|
agent,
|
|
118
|
+
timeout,
|
|
120
119
|
method: request.method,
|
|
121
|
-
timeout: this.options.timeout,
|
|
122
120
|
rejectUnauthorized: false
|
|
123
121
|
};
|
|
124
122
|
}
|
|
125
123
|
getRequestAgent(options) {
|
|
126
|
-
var _a;
|
|
127
|
-
return
|
|
124
|
+
var _a, _b;
|
|
125
|
+
return options.secureEndpoint
|
|
126
|
+
? (_a = this.httpsProxyAgent) !== null && _a !== void 0 ? _a : this.httpsAgent
|
|
127
|
+
: (_b = this.httpProxyAgent) !== null && _b !== void 0 ? _b : this.httpAgent;
|
|
128
128
|
}
|
|
129
|
-
async truncateResponse(res) {
|
|
129
|
+
async truncateResponse({ decompress, encoding, maxContentSize }, res) {
|
|
130
130
|
var _a;
|
|
131
131
|
if (this.responseHasNoBody(res)) {
|
|
132
132
|
this.logger.debug('The response does not contain any body.');
|
|
133
|
-
res
|
|
134
|
-
|
|
133
|
+
return { res, body: '' };
|
|
134
|
+
}
|
|
135
|
+
const contentType = this.parseContentType(res);
|
|
136
|
+
const { type } = contentType;
|
|
137
|
+
const requiresTruncating = this.options.maxContentLength !== -1 &&
|
|
138
|
+
!((_a = this.options.allowedMimes) === null || _a === void 0 ? void 0 : _a.some((mime) => type.startsWith(mime)));
|
|
139
|
+
const maxBodySize = typeof maxContentSize === 'number'
|
|
140
|
+
? maxContentSize * 1024
|
|
141
|
+
: this.options.maxContentLength
|
|
142
|
+
? Math.abs(this.options.maxContentLength) * 1024
|
|
143
|
+
: undefined;
|
|
144
|
+
const body = await this.parseBody(res, {
|
|
145
|
+
decompress,
|
|
146
|
+
maxBodySize: requiresTruncating ? maxBodySize : undefined
|
|
147
|
+
});
|
|
148
|
+
res.headers['content-length'] = body.byteLength.toFixed();
|
|
149
|
+
if (decompress) {
|
|
150
|
+
delete res.headers['content-encoding'];
|
|
135
151
|
}
|
|
136
|
-
|
|
137
|
-
const maxBodySize = this.maxContentLength * 1024;
|
|
138
|
-
const requiresTruncating = !((_a = this.options.allowedMimes) === null || _a === void 0 ? void 0 : _a.some((mime) => type.startsWith(mime)));
|
|
139
|
-
const body = await this.parseBody(res, { maxBodySize, requiresTruncating });
|
|
140
|
-
res.body = body.toString();
|
|
141
|
-
res.headers['content-length'] = String(body.byteLength);
|
|
142
|
-
return res;
|
|
152
|
+
return { res, body: iconv_lite_1.default.decode(body, encoding !== null && encoding !== void 0 ? encoding : contentType.encoding) };
|
|
143
153
|
}
|
|
144
154
|
parseContentType(res) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// noop
|
|
155
|
+
const contentType = res.headers['content-type'] || 'application/octet-stream';
|
|
156
|
+
const { type, parameters: { charset } } = (0, fast_content_type_parse_1.safeParse)(contentType);
|
|
157
|
+
let encoding = charset;
|
|
158
|
+
if (!encoding || !iconv_lite_1.default.encodingExists(encoding)) {
|
|
159
|
+
encoding = 'utf-8';
|
|
151
160
|
}
|
|
152
|
-
return type;
|
|
161
|
+
return { type, encoding };
|
|
153
162
|
}
|
|
154
163
|
unzipBody(response) {
|
|
155
164
|
let body = response;
|
|
@@ -158,18 +167,20 @@ let HttpRequestRunner = class HttpRequestRunner {
|
|
|
158
167
|
contentEncoding = contentEncoding.trim().toLowerCase();
|
|
159
168
|
// Always using Z_SYNC_FLUSH is what cURL does.
|
|
160
169
|
const zlibOptions = {
|
|
161
|
-
flush:
|
|
162
|
-
finishFlush:
|
|
170
|
+
flush: node_zlib_1.constants.Z_SYNC_FLUSH,
|
|
171
|
+
finishFlush: node_zlib_1.constants.Z_SYNC_FLUSH
|
|
163
172
|
};
|
|
164
173
|
switch (contentEncoding) {
|
|
165
174
|
case 'gzip':
|
|
166
|
-
body = response.pipe((0,
|
|
175
|
+
body = response.pipe((0, node_zlib_1.createGunzip)(zlibOptions));
|
|
167
176
|
break;
|
|
168
177
|
case 'deflate':
|
|
169
|
-
body = response
|
|
178
|
+
body = response
|
|
179
|
+
.pipe(new utils_1.NormalizeZlibDeflateTransformStream())
|
|
180
|
+
.pipe((0, node_zlib_1.createInflate)(zlibOptions));
|
|
170
181
|
break;
|
|
171
182
|
case 'br':
|
|
172
|
-
body = response.pipe((0,
|
|
183
|
+
body = response.pipe((0, node_zlib_1.createBrotliDecompress)());
|
|
173
184
|
break;
|
|
174
185
|
}
|
|
175
186
|
}
|
|
@@ -184,13 +195,13 @@ let HttpRequestRunner = class HttpRequestRunner {
|
|
|
184
195
|
}
|
|
185
196
|
async parseBody(res, options) {
|
|
186
197
|
const chunks = [];
|
|
187
|
-
|
|
198
|
+
const stream = options.decompress ? this.unzipBody(res) : res;
|
|
199
|
+
for await (const chuck of stream) {
|
|
188
200
|
chunks.push(chuck);
|
|
189
201
|
}
|
|
190
202
|
let body = Buffer.concat(chunks);
|
|
191
|
-
const truncated =
|
|
192
|
-
body.byteLength > options.maxBodySize
|
|
193
|
-
options.requiresTruncating;
|
|
203
|
+
const truncated = typeof options.maxBodySize === 'number' &&
|
|
204
|
+
body.byteLength > options.maxBodySize;
|
|
194
205
|
if (truncated) {
|
|
195
206
|
this.logger.debug('Truncate original response body to %i bytes', options.maxBodySize);
|
|
196
207
|
body = body.subarray(0, options.maxBodySize);
|
|
@@ -221,8 +232,9 @@ let HttpRequestRunner = class HttpRequestRunner {
|
|
|
221
232
|
};
|
|
222
233
|
HttpRequestRunner = tslib_1.__decorate([
|
|
223
234
|
(0, tsyringe_1.injectable)(),
|
|
224
|
-
tslib_1.__param(
|
|
225
|
-
tslib_1.
|
|
235
|
+
tslib_1.__param(1, (0, tsyringe_1.inject)(utils_1.ProxyFactory)),
|
|
236
|
+
tslib_1.__param(2, (0, tsyringe_1.inject)(RequestRunnerOptions_1.RequestRunnerOptions)),
|
|
237
|
+
tslib_1.__metadata("design:paramtypes", [core_1.Logger, Object, Object])
|
|
226
238
|
], HttpRequestRunner);
|
|
227
239
|
exports.HttpRequestRunner = HttpRequestRunner;
|
|
228
240
|
//# sourceMappingURL=HttpRequestRunner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpRequestRunner.js","sourceRoot":"","sources":["../../../../../../packages/repeater/src/request-runner/protocols/HttpRequestRunner.ts"],"names":[],"mappings":";;;;AACA,yCAAwC;AACxC,kEAA+D;
|
|
1
|
+
{"version":3,"file":"HttpRequestRunner.js","sourceRoot":"","sources":["../../../../../../packages/repeater/src/request-runner/protocols/HttpRequestRunner.ts"],"names":[],"mappings":";;;;AACA,0CAAuC;AAEvC,yCAAwC;AACxC,kEAA+D;AAC/D,uCAAgF;AAChF,0CAAyC;AACzC,uCAA8C;AAC9C,oEAA+B;AAC/B,qEAAoD;AACpD,uCAA6C;AAC7C,kEAImB;AACnB,oEAGoB;AACpB,6CAAmC;AAEnC,yCAKmB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AO,GAAa,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC5D,MAAM,aAAa,GAAuB,OAAO,CAAC,IAAI;QACpD,yEAAyE;QACzE,IAAI,CAAC,EAAE,CACL,CAAC,qBAAqB,EAAE,uBAAuB,CAAC,CAAC,QAAQ,CACvD,IAAI,CAAC,QAAQ,EAAE,CAChB,CACJ,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,aAAa,IAAI,OAAO,CAAC,OAAO,EAAE;YACxD,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC;gBACjC,MAAA,GAAG,CAAC,aAAa,CAAC,mCAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YAE7C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CACrC,CAAC,CAAC,GAAG,EAAE,KAAK,CAA8B,EAAE,EAAE;gBAC5C,IAAI,GAAG,EAAE;oBACP,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC;iBAC/D;YACH,CAAC,CACF,CAAC;SACH;IACH,CAAC;CACF,CAAA;AAvUY,iBAAiB;IAD7B,IAAA,qBAAU,GAAE;IAaR,mBAAA,IAAA,iBAAM,EAAC,oBAAY,CAAC,CAAA;IACpB,mBAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,CAAA;6CAFJ,aAAM;GAXtB,iBAAiB,CAuU7B;AAvUY,8CAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/repeater/src/request-runner/protocols/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/repeater/src/request-runner/protocols/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ProxyFactory, ProxyOptions, TargetProxyOptions } from './ProxyFactory';
|
|
4
|
+
import { PatchedHttpsProxyAgent } from './PatchedHttpsProxyAgent';
|
|
5
|
+
import { HttpProxyAgent } from 'http-proxy-agent';
|
|
6
|
+
import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
7
|
+
import https from 'node:https';
|
|
8
|
+
import http from 'node:http';
|
|
9
|
+
export declare class DefaultProxyFactory implements ProxyFactory {
|
|
10
|
+
createProxy({ proxyUrl, rejectUnauthorized }: ProxyOptions): {
|
|
11
|
+
httpsAgent: PatchedHttpsProxyAgent<string>;
|
|
12
|
+
httpAgent: HttpProxyAgent<string>;
|
|
13
|
+
} | {
|
|
14
|
+
httpAgent: SocksProxyAgent;
|
|
15
|
+
httpsAgent: SocksProxyAgent;
|
|
16
|
+
};
|
|
17
|
+
createProxyForClient({ targetUrl, ...options }: TargetProxyOptions): https.Agent | http.Agent;
|
|
18
|
+
private createHttpProxy;
|
|
19
|
+
private createSocksProxy;
|
|
20
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultProxyFactory = void 0;
|
|
4
|
+
const PatchedHttpsProxyAgent_1 = require("./PatchedHttpsProxyAgent");
|
|
5
|
+
const http_proxy_agent_1 = require("http-proxy-agent");
|
|
6
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
7
|
+
class DefaultProxyFactory {
|
|
8
|
+
createProxy({ proxyUrl, rejectUnauthorized = false }) {
|
|
9
|
+
let protocol;
|
|
10
|
+
try {
|
|
11
|
+
({ protocol } = new URL(proxyUrl));
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
throw new Error(`Invalid Proxy URL: '${proxyUrl}'. Please provide a valid URL.`);
|
|
15
|
+
}
|
|
16
|
+
switch (protocol) {
|
|
17
|
+
case 'http:':
|
|
18
|
+
case 'https:':
|
|
19
|
+
return this.createHttpProxy(proxyUrl, rejectUnauthorized);
|
|
20
|
+
case 'socks:':
|
|
21
|
+
case 'socks4:':
|
|
22
|
+
case 'socks4a:':
|
|
23
|
+
case 'socks5:':
|
|
24
|
+
case 'socks5h:':
|
|
25
|
+
return this.createSocksProxy(proxyUrl);
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`Unsupported proxy protocol: '${protocol.replace(':', '')}'. Please use a supported protocol (HTTP(S), SOCKS4, or SOCKS5).`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
createProxyForClient({ targetUrl, ...options }) {
|
|
31
|
+
const proxies = this.createProxy(options);
|
|
32
|
+
let protocol;
|
|
33
|
+
try {
|
|
34
|
+
({ protocol } = new URL(targetUrl));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new Error(`Invalid Target URL: '${targetUrl}'. Please contact support at support@brightsec.com`);
|
|
38
|
+
}
|
|
39
|
+
switch (protocol) {
|
|
40
|
+
case 'http:':
|
|
41
|
+
case 'ws:':
|
|
42
|
+
return proxies.httpAgent;
|
|
43
|
+
case 'https:':
|
|
44
|
+
case 'wss:':
|
|
45
|
+
return proxies.httpsAgent;
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Proxy not supported for protocol '${protocol}'. Please contact support at support@brightsec.com`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
createHttpProxy(proxyUrl, rejectUnauthorized) {
|
|
51
|
+
return {
|
|
52
|
+
httpsAgent: new PatchedHttpsProxyAgent_1.PatchedHttpsProxyAgent(proxyUrl, {
|
|
53
|
+
rejectUnauthorized
|
|
54
|
+
}),
|
|
55
|
+
httpAgent: new http_proxy_agent_1.HttpProxyAgent(proxyUrl, {
|
|
56
|
+
rejectUnauthorized
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
createSocksProxy(proxyUrl) {
|
|
61
|
+
const common = new socks_proxy_agent_1.SocksProxyAgent(proxyUrl);
|
|
62
|
+
return { httpAgent: common, httpsAgent: common };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.DefaultProxyFactory = DefaultProxyFactory;
|
|
66
|
+
//# sourceMappingURL=DefaultProxyFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultProxyFactory.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/utils/DefaultProxyFactory.ts"],"names":[],"mappings":";;;AACA,qEAAkE;AAClE,uDAAkD;AAClD,yDAAoD;AAIpD,MAAa,mBAAmB;IACvB,WAAW,CAAC,EAAE,QAAQ,EAAE,kBAAkB,GAAG,KAAK,EAAgB;QACvE,IAAI,QAAgB,CAAC;QACrB,IAAI;YACF,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;SACpC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,gCAAgC,CAChE,CAAC;SACH;QAED,QAAQ,QAAQ,EAAE;YAChB,KAAK,OAAO,CAAC;YACb,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YAC5D,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,UAAU,CAAC;YAChB,KAAK,SAAS,CAAC;YACf,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YACzC;gBACE,MAAM,IAAI,KAAK,CACb,gCAAgC,QAAQ,CAAC,OAAO,CAC9C,GAAG,EACH,EAAE,CACH,kEAAkE,CACpE,CAAC;SACL;IACH,CAAC;IAEM,oBAAoB,CAAC,EAC1B,SAAS,EACT,GAAG,OAAO,EACS;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,QAAgB,CAAC;QACrB,IAAI;YACF,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;SACrC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,wBAAwB,SAAS,oDAAoD,CACtF,CAAC;SACH;QAED,QAAQ,QAAQ,EAAE;YAChB,KAAK,OAAO,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,OAAO,CAAC,SAAS,CAAC;YAC3B,KAAK,QAAQ,CAAC;YACd,KAAK,MAAM;gBACT,OAAO,OAAO,CAAC,UAAU,CAAC;YAC5B;gBACE,MAAM,IAAI,KAAK,CACb,qCAAqC,QAAQ,oDAAoD,CAClG,CAAC;SACL;IACH,CAAC;IAEO,eAAe,CAAC,QAAgB,EAAE,kBAA4B;QACpE,OAAO;YACL,UAAU,EAAE,IAAI,+CAAsB,CAAC,QAAQ,EAAE;gBAC/C,kBAAkB;aACnB,CAAC;YACF,SAAS,EAAE,IAAI,iCAAc,CAAC,QAAQ,EAAE;gBACtC,kBAAkB;aACnB,CAAC;SACH,CAAC;IACJ,CAAC;IAEO,gBAAgB,CAAC,QAAgB;QACvC,MAAM,MAAM,GAAG,IAAI,mCAAe,CAAC,QAAQ,CAAC,CAAC;QAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IACnD,CAAC;CACF;AA3ED,kDA2EC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Transform, TransformCallback } from 'node:stream';
|
|
4
|
+
export declare class NormalizeZlibDeflateTransformStream extends Transform {
|
|
5
|
+
private hasCheckedHead;
|
|
6
|
+
private readonly header;
|
|
7
|
+
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NormalizeZlibDeflateTransformStream = void 0;
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
|
+
class NormalizeZlibDeflateTransformStream extends node_stream_1.Transform {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.hasCheckedHead = false;
|
|
9
|
+
this.header = Buffer.from([0x78, 0x9c]);
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
+
_transform(chunk, encoding, callback) {
|
|
13
|
+
if (!this.hasCheckedHead && chunk.length !== 0) {
|
|
14
|
+
// ADHOC: detects raw deflate: https://stackoverflow.com/a/37528114
|
|
15
|
+
if (chunk.compare(this.header, 0, 1, 0, 1) !== 0) {
|
|
16
|
+
this.push(this.header, encoding);
|
|
17
|
+
}
|
|
18
|
+
this.hasCheckedHead = true;
|
|
19
|
+
}
|
|
20
|
+
this.push(chunk, encoding);
|
|
21
|
+
callback();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NormalizeZlibDeflateTransformStream = NormalizeZlibDeflateTransformStream;
|
|
25
|
+
//# sourceMappingURL=NormalizeZlibDeflateTransformStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NormalizeZlibDeflateTransformStream.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/utils/NormalizeZlibDeflateTransformStream.ts"],"names":[],"mappings":";;;AAAA,6CAA2D;AAE3D,MAAa,mCAAoC,SAAQ,uBAAS;IAAlE;;QACU,mBAAc,GAAG,KAAK,CAAC;QACd,WAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAkBtD,CAAC;IAjBC,gEAAgE;IACzD,UAAU,CACf,KAAU,EACV,QAAwB,EACxB,QAA2B;QAE3B,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,mEAAmE;YACnE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE;gBAChD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;aAClC;YACD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;SAC5B;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC3B,QAAQ,EAAE,CAAC;IACb,CAAC;CACF;AApBD,kFAoBC"}
|