@sectester/repeater 0.16.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/LICENSE +21 -0
- package/README.md +173 -0
- package/package.json +60 -0
- package/src/api/DefaultRepeatersManager.d.ts +13 -0
- package/src/api/DefaultRepeatersManager.js +31 -0
- package/src/api/DefaultRepeatersManager.js.map +1 -0
- package/src/api/RepeatersManager.d.ts +10 -0
- package/src/api/RepeatersManager.js +5 -0
- package/src/api/RepeatersManager.js.map +1 -0
- package/src/api/commands/CreateRepeaterRequest.d.ts +9 -0
- package/src/api/commands/CreateRepeaterRequest.js +15 -0
- package/src/api/commands/CreateRepeaterRequest.js.map +1 -0
- package/src/api/commands/DeleteRepeaterRequest.d.ts +6 -0
- package/src/api/commands/DeleteRepeaterRequest.js +16 -0
- package/src/api/commands/DeleteRepeaterRequest.js.map +1 -0
- package/src/api/commands/ListRepeatersRequest.d.ts +8 -0
- package/src/api/commands/ListRepeatersRequest.js +11 -0
- package/src/api/commands/ListRepeatersRequest.js.map +1 -0
- package/src/api/commands/index.d.ts +3 -0
- package/src/api/commands/index.js +10 -0
- package/src/api/commands/index.js.map +1 -0
- package/src/api/index.d.ts +2 -0
- package/src/api/index.js +6 -0
- package/src/api/index.js.map +1 -0
- package/src/api/register.d.ts +1 -0
- package/src/api/register.js +7 -0
- package/src/api/register.js.map +1 -0
- package/src/bus/EventBusFactory.d.ts +5 -0
- package/src/bus/EventBusFactory.js +5 -0
- package/src/bus/EventBusFactory.js.map +1 -0
- package/src/bus/ExecuteRequestEventHandler.d.ts +25 -0
- package/src/bus/ExecuteRequestEventHandler.js +37 -0
- package/src/bus/ExecuteRequestEventHandler.js.map +1 -0
- package/src/bus/RegisterRepeaterCommand.d.ts +22 -0
- package/src/bus/RegisterRepeaterCommand.js +18 -0
- package/src/bus/RegisterRepeaterCommand.js.map +1 -0
- package/src/bus/RepeaterEventBusFactory.d.ts +11 -0
- package/src/bus/RepeaterEventBusFactory.js +40 -0
- package/src/bus/RepeaterEventBusFactory.js.map +1 -0
- package/src/bus/RepeaterStatusEvent.d.ts +10 -0
- package/src/bus/RepeaterStatusEvent.js +11 -0
- package/src/bus/RepeaterStatusEvent.js.map +1 -0
- package/src/bus/index.d.ts +5 -0
- package/src/bus/index.js +9 -0
- package/src/bus/index.js.map +1 -0
- package/src/bus/register.d.ts +1 -0
- package/src/bus/register.js +14 -0
- package/src/bus/register.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +9 -0
- package/src/index.js.map +1 -0
- package/src/lib/Repeater.d.ts +29 -0
- package/src/lib/Repeater.js +120 -0
- package/src/lib/Repeater.js.map +1 -0
- package/src/lib/RepeaterFactory.d.ts +16 -0
- package/src/lib/RepeaterFactory.js +79 -0
- package/src/lib/RepeaterFactory.js.map +1 -0
- package/src/lib/RepeaterOptions.d.ts +6 -0
- package/src/lib/RepeaterOptions.js +3 -0
- package/src/lib/RepeaterOptions.js.map +1 -0
- package/src/lib/index.d.ts +5 -0
- package/src/lib/index.js +10 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/register.d.ts +1 -0
- package/src/lib/register.js +11 -0
- package/src/lib/register.js.map +1 -0
- package/src/models/Protocol.d.ts +4 -0
- package/src/models/Protocol.js +9 -0
- package/src/models/Protocol.js.map +1 -0
- package/src/models/RepeaterStatus.d.ts +1 -0
- package/src/models/RepeaterStatus.js +3 -0
- package/src/models/RepeaterStatus.js.map +1 -0
- package/src/models/index.d.ts +3 -0
- package/src/models/index.js +8 -0
- package/src/models/index.js.map +1 -0
- package/src/request-runner/Request.d.ts +23 -0
- package/src/request-runner/Request.js +56 -0
- package/src/request-runner/Request.js.map +1 -0
- package/src/request-runner/RequestRunner.d.ts +8 -0
- package/src/request-runner/RequestRunner.js +5 -0
- package/src/request-runner/RequestRunner.js.map +1 -0
- package/src/request-runner/RequestRunnerOptions.d.ts +9 -0
- package/src/request-runner/RequestRunnerOptions.js +5 -0
- package/src/request-runner/RequestRunnerOptions.js.map +1 -0
- package/src/request-runner/Response.d.ts +17 -0
- package/src/request-runner/Response.js +15 -0
- package/src/request-runner/Response.js.map +1 -0
- package/src/request-runner/index.d.ts +5 -0
- package/src/request-runner/index.js +9 -0
- package/src/request-runner/index.js.map +1 -0
- package/src/request-runner/protocols/HttpRequestRunner.d.ts +29 -0
- package/src/request-runner/protocols/HttpRequestRunner.js +180 -0
- package/src/request-runner/protocols/HttpRequestRunner.js.map +1 -0
- package/src/request-runner/protocols/WsRequestRunner.d.ts +24 -0
- package/src/request-runner/protocols/WsRequestRunner.js +148 -0
- package/src/request-runner/protocols/WsRequestRunner.js.map +1 -0
- package/src/request-runner/protocols/index.d.ts +2 -0
- package/src/request-runner/protocols/index.js +6 -0
- package/src/request-runner/protocols/index.js.map +1 -0
- package/src/request-runner/register.d.ts +1 -0
- package/src/request-runner/register.js +12 -0
- package/src/request-runner/register.js.map +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepeaterEventBusFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tsyringe_1 = require("tsyringe");
|
|
6
|
+
const core_1 = require("@sectester/core");
|
|
7
|
+
const bus_1 = require("@sectester/bus");
|
|
8
|
+
let RepeaterEventBusFactory = class RepeaterEventBusFactory {
|
|
9
|
+
constructor(container, config, retryStrategy) {
|
|
10
|
+
this.container = container;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.retryStrategy = retryStrategy;
|
|
13
|
+
}
|
|
14
|
+
async create(repeaterId, options = {}) {
|
|
15
|
+
var _a;
|
|
16
|
+
await this.config.loadCredentials();
|
|
17
|
+
if (!this.config.credentials) {
|
|
18
|
+
throw new Error('Please provide credentials to establish a connection with the bus.');
|
|
19
|
+
}
|
|
20
|
+
const busConfig = {
|
|
21
|
+
...options,
|
|
22
|
+
url: this.config.bus,
|
|
23
|
+
exchange: 'EventBus',
|
|
24
|
+
appQueue: 'app',
|
|
25
|
+
clientQueue: `agent:${repeaterId}`,
|
|
26
|
+
credentials: {
|
|
27
|
+
username: 'bot',
|
|
28
|
+
password: (_a = this.config.credentials.token) !== null && _a !== void 0 ? _a : ''
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return new bus_1.RMQEventBus(this.container, this.retryStrategy, busConfig);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
RepeaterEventBusFactory = (0, tslib_1.__decorate)([
|
|
35
|
+
(0, tsyringe_1.autoInjectable)(),
|
|
36
|
+
(0, tslib_1.__param)(2, (0, tsyringe_1.inject)(core_1.RetryStrategy)),
|
|
37
|
+
(0, tslib_1.__metadata)("design:paramtypes", [Object, core_1.Configuration, Object])
|
|
38
|
+
], RepeaterEventBusFactory);
|
|
39
|
+
exports.RepeaterEventBusFactory = RepeaterEventBusFactory;
|
|
40
|
+
//# sourceMappingURL=RepeaterEventBusFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterEventBusFactory.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/bus/RepeaterEventBusFactory.ts"],"names":[],"mappings":";;;;AACA,uCAAuE;AACvE,0CAAyE;AACzE,wCAAgE;AAGhE,IAAa,uBAAuB,GAApC,MAAa,uBAAuB;IAClC,YACmB,SAA8B,EAC9B,MAAqB,EACE,aAA4B;QAFnD,cAAS,GAAT,SAAS,CAAqB;QAC9B,WAAM,GAAN,MAAM,CAAe;QACE,kBAAa,GAAb,aAAa,CAAe;IACnE,CAAC;IAEG,KAAK,CAAC,MAAM,CACjB,UAAkB,EAClB,UAGI,EAAE;;QAEN,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAEpC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YAC5B,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,MAAM,SAAS,GAAsB;YACnC,GAAG,OAAO;YACV,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG;YACpB,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,SAAS,UAAU,EAAE;YAClC,WAAW,EAAE;gBACX,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE,MAAA,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,mCAAI,EAAE;aAC9C;SACF,CAAC;QAEF,OAAO,IAAI,iBAAW,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AApCY,uBAAuB;IADnC,IAAA,yBAAc,GAAE;IAKZ,wBAAA,IAAA,iBAAM,EAAC,oBAAa,CAAC,CAAA;0DADG,oBAAa;GAH7B,uBAAuB,CAoCnC;AApCY,0DAAuB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RepeaterStatus } from '../lib';
|
|
2
|
+
import { Event } from '@sectester/core';
|
|
3
|
+
interface RepeaterStatusEventPayload {
|
|
4
|
+
repeaterId: string;
|
|
5
|
+
status: RepeaterStatus;
|
|
6
|
+
}
|
|
7
|
+
export declare class RepeaterStatusEvent extends Event<RepeaterStatusEventPayload> {
|
|
8
|
+
constructor(payload: RepeaterStatusEventPayload);
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepeaterStatusEvent = void 0;
|
|
4
|
+
const core_1 = require("@sectester/core");
|
|
5
|
+
class RepeaterStatusEvent extends core_1.Event {
|
|
6
|
+
constructor(payload) {
|
|
7
|
+
super(payload, 'RepeaterStatusUpdated');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.RepeaterStatusEvent = RepeaterStatusEvent;
|
|
11
|
+
//# sourceMappingURL=RepeaterStatusEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterStatusEvent.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/bus/RepeaterStatusEvent.ts"],"names":[],"mappings":";;;AACA,0CAAwC;AAOxC,MAAa,mBAAoB,SAAQ,YAAiC;IACxE,YAAY,OAAmC;QAC7C,KAAK,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAC1C,CAAC;CACF;AAJD,kDAIC"}
|
package/src/bus/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("./register");
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./EventBusFactory"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./ExecuteRequestEventHandler"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./RegisterRepeaterCommand"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./RepeaterStatusEvent"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/bus/index.ts"],"names":[],"mappings":";;;AAAA,sBAAoB;AAEpB,iEAAkC;AAClC,4EAA6C;AAC7C,yEAA0C;AAC1C,qEAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const EventBusFactory_1 = require("./EventBusFactory");
|
|
4
|
+
const RepeaterEventBusFactory_1 = require("./RepeaterEventBusFactory");
|
|
5
|
+
const tsyringe_1 = require("tsyringe");
|
|
6
|
+
const core_1 = require("@sectester/core");
|
|
7
|
+
tsyringe_1.container.register(EventBusFactory_1.EventBusFactory, {
|
|
8
|
+
useFactory(childContainer) {
|
|
9
|
+
const configuration = childContainer.resolve(core_1.Configuration);
|
|
10
|
+
const retryStrategy = childContainer.resolve(core_1.RetryStrategy);
|
|
11
|
+
return new RepeaterEventBusFactory_1.RepeaterEventBusFactory(childContainer, configuration, retryStrategy);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/bus/register.ts"],"names":[],"mappings":";;AAAA,uDAAoD;AACpD,uEAAoE;AACpE,uCAA0D;AAC1D,0CAA+D;AAE/D,oBAAS,CAAC,QAAQ,CAAC,iCAAe,EAAE;IAClC,UAAU,CAAC,cAAmC;QAC5C,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,oBAAa,CAAC,CAAC;QAC5D,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAgB,oBAAa,CAAC,CAAC;QAE3E,OAAO,IAAI,iDAAuB,CAChC,cAAc,EACd,aAAa,EACb,aAAa,CACd,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepeatersManager = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var api_1 = require("./api");
|
|
6
|
+
Object.defineProperty(exports, "RepeatersManager", { enumerable: true, get: function () { return api_1.RepeatersManager; } });
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./lib"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./request-runner"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/repeater/src/index.ts"],"names":[],"mappings":";;;;AAAA,6BAAyC;AAAhC,uGAAA,gBAAgB,OAAA;AACzB,qDAAsB;AACtB,gEAAiC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Configuration, EventBus } from '@sectester/core';
|
|
2
|
+
export declare enum RunningStatus {
|
|
3
|
+
OFF = 0,
|
|
4
|
+
STARTING = 1,
|
|
5
|
+
RUNNING = 2
|
|
6
|
+
}
|
|
7
|
+
export declare class Repeater {
|
|
8
|
+
readonly repeaterId: string;
|
|
9
|
+
private readonly bus;
|
|
10
|
+
private readonly configuration;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private timer?;
|
|
13
|
+
private _runningStatus;
|
|
14
|
+
get runningStatus(): RunningStatus;
|
|
15
|
+
constructor({ repeaterId, bus, configuration }: {
|
|
16
|
+
repeaterId: string;
|
|
17
|
+
bus: EventBus;
|
|
18
|
+
configuration: Configuration;
|
|
19
|
+
});
|
|
20
|
+
start(): Promise<void>;
|
|
21
|
+
stop(): Promise<void>;
|
|
22
|
+
private register;
|
|
23
|
+
private subscribeToEvents;
|
|
24
|
+
private schedulePing;
|
|
25
|
+
private sendStatus;
|
|
26
|
+
private setupShutdown;
|
|
27
|
+
private handleRegisterResult;
|
|
28
|
+
private handleRegisterError;
|
|
29
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repeater = exports.RunningStatus = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bus_1 = require("../bus");
|
|
6
|
+
const core_1 = require("@sectester/core");
|
|
7
|
+
const semver_1 = require("semver");
|
|
8
|
+
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
9
|
+
var RunningStatus;
|
|
10
|
+
(function (RunningStatus) {
|
|
11
|
+
RunningStatus[RunningStatus["OFF"] = 0] = "OFF";
|
|
12
|
+
RunningStatus[RunningStatus["STARTING"] = 1] = "STARTING";
|
|
13
|
+
RunningStatus[RunningStatus["RUNNING"] = 2] = "RUNNING";
|
|
14
|
+
})(RunningStatus = exports.RunningStatus || (exports.RunningStatus = {}));
|
|
15
|
+
class Repeater {
|
|
16
|
+
constructor({ repeaterId, bus, configuration }) {
|
|
17
|
+
this._runningStatus = RunningStatus.OFF;
|
|
18
|
+
this.repeaterId = repeaterId;
|
|
19
|
+
this.bus = bus;
|
|
20
|
+
this.configuration = configuration;
|
|
21
|
+
const { container } = this.configuration;
|
|
22
|
+
this.logger = container.resolve(core_1.Logger);
|
|
23
|
+
this.setupShutdown();
|
|
24
|
+
}
|
|
25
|
+
get runningStatus() {
|
|
26
|
+
return this._runningStatus;
|
|
27
|
+
}
|
|
28
|
+
async start() {
|
|
29
|
+
if (this.runningStatus !== RunningStatus.OFF) {
|
|
30
|
+
throw new Error('Repeater is already active.');
|
|
31
|
+
}
|
|
32
|
+
this._runningStatus = RunningStatus.STARTING;
|
|
33
|
+
try {
|
|
34
|
+
await this.register();
|
|
35
|
+
await this.subscribeToEvents();
|
|
36
|
+
await this.schedulePing();
|
|
37
|
+
this._runningStatus = RunningStatus.RUNNING;
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
this._runningStatus = RunningStatus.OFF;
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async stop() {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (this.runningStatus !== RunningStatus.RUNNING) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this._runningStatus = RunningStatus.OFF;
|
|
50
|
+
if (this.timer) {
|
|
51
|
+
clearInterval(this.timer);
|
|
52
|
+
}
|
|
53
|
+
await this.sendStatus('disconnected');
|
|
54
|
+
await ((_b = (_a = this.bus).destroy) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
55
|
+
}
|
|
56
|
+
async register() {
|
|
57
|
+
const res = await this.bus.execute(new bus_1.RegisterRepeaterCommand({
|
|
58
|
+
version: this.configuration.repeaterVersion,
|
|
59
|
+
repeaterId: this.repeaterId
|
|
60
|
+
}));
|
|
61
|
+
if (!res) {
|
|
62
|
+
throw new Error('Error registering repeater.');
|
|
63
|
+
}
|
|
64
|
+
this.handleRegisterResult(res);
|
|
65
|
+
}
|
|
66
|
+
async subscribeToEvents() {
|
|
67
|
+
await Promise.all([
|
|
68
|
+
bus_1.ExecuteRequestEventHandler
|
|
69
|
+
// TODO repeater scripts
|
|
70
|
+
].map(type => this.bus.register(type)));
|
|
71
|
+
}
|
|
72
|
+
async schedulePing() {
|
|
73
|
+
await this.sendStatus('connected');
|
|
74
|
+
this.timer = setInterval(() => this.sendStatus('connected'), 10000);
|
|
75
|
+
this.timer.unref();
|
|
76
|
+
}
|
|
77
|
+
async sendStatus(status) {
|
|
78
|
+
await this.bus.publish(new bus_1.RepeaterStatusEvent({
|
|
79
|
+
status,
|
|
80
|
+
repeaterId: this.repeaterId
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
setupShutdown() {
|
|
84
|
+
['SIGTERM', 'SIGINT', 'SIGHUP'].forEach(event => {
|
|
85
|
+
process.on(event, async () => {
|
|
86
|
+
try {
|
|
87
|
+
await this.stop();
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
this.logger.error(e.message);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
handleRegisterResult(res) {
|
|
96
|
+
const { payload } = res;
|
|
97
|
+
if ('error' in payload) {
|
|
98
|
+
this.handleRegisterError(payload.error);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if ((0, semver_1.gt)(payload.version, this.configuration.repeaterVersion)) {
|
|
102
|
+
this.logger.warn('%s: A new Repeater version (%s) is available, please update @sectester.', chalk_1.default.yellow('(!) IMPORTANT'), payload.version);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
handleRegisterError(error) {
|
|
107
|
+
switch (error) {
|
|
108
|
+
case bus_1.RepeaterRegisteringError.NOT_ACTIVE:
|
|
109
|
+
throw new Error(`Access Refused: The current Repeater is not active.`);
|
|
110
|
+
case bus_1.RepeaterRegisteringError.NOT_FOUND:
|
|
111
|
+
throw new Error(`Unauthorized access. Please check your credentials.`);
|
|
112
|
+
case bus_1.RepeaterRegisteringError.BUSY:
|
|
113
|
+
throw new Error(`Access Refused: There is an already running Repeater with ID ${this.repeaterId}`);
|
|
114
|
+
case bus_1.RepeaterRegisteringError.REQUIRES_TO_BE_UPDATED:
|
|
115
|
+
throw new Error(`${chalk_1.default.red('(!) CRITICAL')}: The current running version is no longer supported, please update @sectester.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.Repeater = Repeater;
|
|
120
|
+
//# sourceMappingURL=Repeater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Repeater.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/lib/Repeater.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Repeater } from './Repeater';
|
|
2
|
+
import { RepeaterOptions } from './RepeaterOptions';
|
|
3
|
+
import { Configuration } from '@sectester/core';
|
|
4
|
+
/**
|
|
5
|
+
* A factory that is able to create a dedicated instance of the repeater with a bus and other dependencies.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RepeaterFactory {
|
|
8
|
+
private readonly configuration;
|
|
9
|
+
private readonly DEFAULT_RUNNER_OPTIONS;
|
|
10
|
+
private readonly container;
|
|
11
|
+
private readonly repeatersManager;
|
|
12
|
+
private readonly eventBusFactory;
|
|
13
|
+
constructor(configuration: Configuration);
|
|
14
|
+
createRepeater({ namePrefix, description, requestRunnerOptions }?: RepeaterOptions): Promise<Repeater>;
|
|
15
|
+
private registerRequestRunnerOptions;
|
|
16
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepeaterFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Repeater_1 = require("./Repeater");
|
|
6
|
+
const request_runner_1 = require("../request-runner");
|
|
7
|
+
const api_1 = require("../api");
|
|
8
|
+
const bus_1 = require("../bus");
|
|
9
|
+
const core_1 = require("@sectester/core");
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const tsyringe_1 = require("tsyringe");
|
|
12
|
+
/**
|
|
13
|
+
* A factory that is able to create a dedicated instance of the repeater with a bus and other dependencies.
|
|
14
|
+
*/
|
|
15
|
+
let RepeaterFactory = class RepeaterFactory {
|
|
16
|
+
constructor(configuration) {
|
|
17
|
+
this.configuration = configuration;
|
|
18
|
+
this.DEFAULT_RUNNER_OPTIONS = {
|
|
19
|
+
timeout: 30000,
|
|
20
|
+
maxContentLength: 100,
|
|
21
|
+
reuseConnection: false,
|
|
22
|
+
allowedMimes: [
|
|
23
|
+
'text/html',
|
|
24
|
+
'text/plain',
|
|
25
|
+
'text/css',
|
|
26
|
+
'text/javascript',
|
|
27
|
+
'text/markdown',
|
|
28
|
+
'text/xml',
|
|
29
|
+
'application/javascript',
|
|
30
|
+
'application/x-javascript',
|
|
31
|
+
'application/json',
|
|
32
|
+
'application/xml',
|
|
33
|
+
'application/x-www-form-urlencoded',
|
|
34
|
+
'application/msgpack',
|
|
35
|
+
'application/ld+json',
|
|
36
|
+
'application/graphql'
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
this.container = this.configuration.container.createChildContainer();
|
|
40
|
+
this.repeatersManager =
|
|
41
|
+
this.container.resolve(api_1.RepeatersManager);
|
|
42
|
+
this.eventBusFactory =
|
|
43
|
+
this.container.resolve(bus_1.EventBusFactory);
|
|
44
|
+
}
|
|
45
|
+
async createRepeater({ namePrefix, description, requestRunnerOptions } = {
|
|
46
|
+
namePrefix: `sectester`
|
|
47
|
+
}) {
|
|
48
|
+
var _a;
|
|
49
|
+
if (namePrefix && namePrefix.length > 44) {
|
|
50
|
+
throw new Error('Name prefix must be less than 44 characters.');
|
|
51
|
+
}
|
|
52
|
+
this.registerRequestRunnerOptions(requestRunnerOptions);
|
|
53
|
+
const { repeaterId } = await this.repeatersManager.createRepeater({
|
|
54
|
+
name: `${namePrefix}-${(0, uuid_1.v4)()}`,
|
|
55
|
+
description
|
|
56
|
+
});
|
|
57
|
+
const bus = await this.eventBusFactory.create(repeaterId);
|
|
58
|
+
await ((_a = bus.init) === null || _a === void 0 ? void 0 : _a.call(bus));
|
|
59
|
+
return new Repeater_1.Repeater({
|
|
60
|
+
repeaterId,
|
|
61
|
+
bus,
|
|
62
|
+
configuration: this.configuration
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
registerRequestRunnerOptions(options) {
|
|
66
|
+
this.container.register(request_runner_1.RequestRunnerOptions, {
|
|
67
|
+
useValue: {
|
|
68
|
+
...this.DEFAULT_RUNNER_OPTIONS,
|
|
69
|
+
...(options !== null && options !== void 0 ? options : {})
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
RepeaterFactory = (0, tslib_1.__decorate)([
|
|
75
|
+
(0, tsyringe_1.injectable)(),
|
|
76
|
+
(0, tslib_1.__metadata)("design:paramtypes", [core_1.Configuration])
|
|
77
|
+
], RepeaterFactory);
|
|
78
|
+
exports.RepeaterFactory = RepeaterFactory;
|
|
79
|
+
//# sourceMappingURL=RepeaterFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterFactory.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/lib/RepeaterFactory.ts"],"names":[],"mappings":";;;;AAAA,yCAAsC;AACtC,sDAAyD;AAEzD,gCAA0C;AAC1C,gCAAyC;AACzC,0CAAgD;AAChD,+BAAoC;AACpC,uCAA2D;AAE3D;;GAEG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAe;IA0B1B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAzBxC,2BAAsB,GAAmC;YACxE,OAAO,EAAE,KAAK;YACd,gBAAgB,EAAE,GAAG;YACrB,eAAe,EAAE,KAAK;YACtB,YAAY,EAAE;gBACZ,WAAW;gBACX,YAAY;gBACZ,UAAU;gBACV,iBAAiB;gBACjB,eAAe;gBACf,UAAU;gBACV,wBAAwB;gBACxB,0BAA0B;gBAC1B,kBAAkB;gBAClB,iBAAiB;gBACjB,mCAAmC;gBACnC,qBAAqB;gBACrB,qBAAqB;gBACrB,qBAAqB;aACtB;SACF,CAAC;QAMA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC;QAErE,IAAI,CAAC,gBAAgB;YACnB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAmB,sBAAgB,CAAC,CAAC;QAC7D,IAAI,CAAC,eAAe;YAClB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAkB,qBAAe,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,KAAsB;QACnE,UAAU,EAAE,WAAW;KACxB;;QAED,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE;YACxC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;SACjE;QAED,IAAI,CAAC,4BAA4B,CAAC,oBAAoB,CAAC,CAAC;QAExD,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC;YAChE,IAAI,EAAE,GAAG,UAAU,IAAI,IAAA,SAAM,GAAE,EAAE;YACjC,WAAW;SACZ,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAE1D,MAAM,CAAA,MAAA,GAAG,CAAC,IAAI,+CAAR,GAAG,CAAS,CAAA,CAAC;QAEnB,OAAO,IAAI,mBAAQ,CAAC;YAClB,UAAU;YACV,GAAG;YACH,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAClC,OAAyC;QAEzC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,qCAAoB,EAAE;YAC5C,QAAQ,EAAE;gBACR,GAAG,IAAI,CAAC,sBAAsB;gBAC9B,GAAG,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;aACnB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxEY,eAAe;IAD3B,IAAA,qBAAU,GAAE;kDA2BiC,oBAAa;GA1B9C,eAAe,CAwE3B;AAxEY,0CAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterOptions.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/lib/RepeaterOptions.ts"],"names":[],"mappings":""}
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepeaterFactory = exports.RunningStatus = exports.Repeater = void 0;
|
|
4
|
+
require("./register");
|
|
5
|
+
var Repeater_1 = require("./Repeater");
|
|
6
|
+
Object.defineProperty(exports, "Repeater", { enumerable: true, get: function () { return Repeater_1.Repeater; } });
|
|
7
|
+
Object.defineProperty(exports, "RunningStatus", { enumerable: true, get: function () { return Repeater_1.RunningStatus; } });
|
|
8
|
+
var RepeaterFactory_1 = require("./RepeaterFactory");
|
|
9
|
+
Object.defineProperty(exports, "RepeaterFactory", { enumerable: true, get: function () { return RepeaterFactory_1.RepeaterFactory; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,sBAAoB;AAEpB,uCAAqD;AAA5C,oGAAA,QAAQ,OAAA;AAAE,yGAAA,aAAa,OAAA;AAChC,qDAAoD;AAA3C,kHAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const RepeaterFactory_1 = require("./RepeaterFactory");
|
|
4
|
+
const tsyringe_1 = require("tsyringe");
|
|
5
|
+
const core_1 = require("@sectester/core");
|
|
6
|
+
tsyringe_1.container.register(RepeaterFactory_1.RepeaterFactory, {
|
|
7
|
+
useFactory(childContainer) {
|
|
8
|
+
return new RepeaterFactory_1.RepeaterFactory(childContainer.resolve(core_1.Configuration));
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/lib/register.ts"],"names":[],"mappings":";;AAAA,uDAAoD;AACpD,uCAA0D;AAC1D,0CAAgD;AAEhD,oBAAS,CAAC,QAAQ,CAAC,iCAAe,EAAE;IAClC,UAAU,CAAC,cAAmC;QAC5C,OAAO,IAAI,iCAAe,CAAC,cAAc,CAAC,OAAO,CAAC,oBAAa,CAAC,CAAC,CAAC;IACpE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Protocol = void 0;
|
|
4
|
+
var Protocol;
|
|
5
|
+
(function (Protocol) {
|
|
6
|
+
Protocol["HTTP"] = "http";
|
|
7
|
+
Protocol["WS"] = "ws";
|
|
8
|
+
})(Protocol = exports.Protocol || (exports.Protocol = {}));
|
|
9
|
+
//# sourceMappingURL=Protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Protocol.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/models/Protocol.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,qBAAS,CAAA;AACX,CAAC,EAHW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAGnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type RepeaterStatus = 'connected' | 'disconnected';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterStatus.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/models/RepeaterStatus.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Container = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./Protocol"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./RepeaterStatus"), exports);
|
|
7
|
+
exports.Container = Symbol('DependencyContainer');
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/models/index.ts"],"names":[],"mappings":";;;;AAAA,0DAA2B;AAC3B,gEAAiC;AAEpB,QAAA,SAAS,GAAkB,MAAM,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface RequestOptions {
|
|
2
|
+
method?: string;
|
|
3
|
+
url: string;
|
|
4
|
+
headers: Record<string, string | string[]>;
|
|
5
|
+
body?: string;
|
|
6
|
+
correlationIdRegex?: string | RegExp;
|
|
7
|
+
}
|
|
8
|
+
export declare class Request {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
readonly body?: string;
|
|
11
|
+
readonly correlationIdRegex?: RegExp;
|
|
12
|
+
private readonly _method?;
|
|
13
|
+
get method(): string | undefined;
|
|
14
|
+
private _headers;
|
|
15
|
+
get headers(): Readonly<Record<string, string | string[]>>;
|
|
16
|
+
constructor({ method, url, body, correlationIdRegex, headers }: Omit<RequestOptions, 'headers'> & {
|
|
17
|
+
headers?: Record<string, string | string[]>;
|
|
18
|
+
});
|
|
19
|
+
setHeaders(headers: Record<string, string | string[]>): void;
|
|
20
|
+
private normalizeUrl;
|
|
21
|
+
private precheckBody;
|
|
22
|
+
private normalizeCorrelationIdRegex;
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Request = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
class Request {
|
|
6
|
+
constructor({ method, url, body, correlationIdRegex, headers = {} }) {
|
|
7
|
+
var _a;
|
|
8
|
+
this._method = (_a = method === null || method === void 0 ? void 0 : method.toUpperCase()) !== null && _a !== void 0 ? _a : 'GET';
|
|
9
|
+
this.url = this.normalizeUrl(url);
|
|
10
|
+
this.correlationIdRegex =
|
|
11
|
+
this.normalizeCorrelationIdRegex(correlationIdRegex);
|
|
12
|
+
this._headers = headers;
|
|
13
|
+
this.precheckBody(body);
|
|
14
|
+
this.body = body;
|
|
15
|
+
}
|
|
16
|
+
get method() {
|
|
17
|
+
return this._method;
|
|
18
|
+
}
|
|
19
|
+
get headers() {
|
|
20
|
+
return this._headers;
|
|
21
|
+
}
|
|
22
|
+
setHeaders(headers) {
|
|
23
|
+
this._headers = {
|
|
24
|
+
...this._headers,
|
|
25
|
+
...headers
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
normalizeUrl(url) {
|
|
29
|
+
if (!url) {
|
|
30
|
+
throw new Error('Url must be declared explicitly.');
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return new url_1.URL(url).toString();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error('Invalid URL.');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
precheckBody(body) {
|
|
40
|
+
if (body && typeof body !== 'string') {
|
|
41
|
+
throw new Error('Body must be string.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
normalizeCorrelationIdRegex(correlationIdRegex) {
|
|
45
|
+
if (correlationIdRegex) {
|
|
46
|
+
try {
|
|
47
|
+
return new RegExp(correlationIdRegex, 'i');
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new Error('Correlation id must be regular expression.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.Request = Request;
|
|
56
|
+
//# sourceMappingURL=Request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/Request.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAU1B,MAAa,OAAO;IAiBlB,YAAY,EACV,MAAM,EACN,GAAG,EACH,IAAI,EACJ,kBAAkB,EAClB,OAAO,GAAG,EAAE,EAGb;;QACC,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,EAAE,mCAAI,KAAK,CAAC;QAC9C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,kBAAkB;YACrB,IAAI,CAAC,2BAA2B,CAAC,kBAAkB,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IA3BD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAID,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAqBM,UAAU,CAAC,OAA0C;QAC1D,IAAI,CAAC,QAAQ,GAAG;YACd,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,GAAW;QAC9B,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;QAED,IAAI;YACF,OAAO,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;SAChC;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;IAEO,2BAA2B,CACjC,kBAA+C;QAE/C,IAAI,kBAAkB,EAAE;YACtB,IAAI;gBACF,OAAO,IAAI,MAAM,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;aAC5C;YAAC,MAAM;gBACN,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;aAC/D;SACF;IACH,CAAC;CACF;AAxED,0BAwEC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request } from './Request';
|
|
2
|
+
import { Response } from './Response';
|
|
3
|
+
import { Protocol } from '../models';
|
|
4
|
+
export interface RequestRunner {
|
|
5
|
+
protocol: Protocol;
|
|
6
|
+
run(request: Request): Promise<Response>;
|
|
7
|
+
}
|
|
8
|
+
export declare const RequestRunner: unique symbol;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestRunner.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/RequestRunner.ts"],"names":[],"mappings":";;;AASa,QAAA,aAAa,GAAkB,MAAM,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface RequestRunnerOptions {
|
|
2
|
+
timeout?: number;
|
|
3
|
+
proxyUrl?: string;
|
|
4
|
+
headers?: Record<string, string | string[]>;
|
|
5
|
+
allowedMimes?: string[];
|
|
6
|
+
maxContentLength?: number;
|
|
7
|
+
reuseConnection?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const RequestRunnerOptions: unique symbol;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestRunnerOptions.js","sourceRoot":"","sources":["../../../../../packages/repeater/src/request-runner/RequestRunnerOptions.ts"],"names":[],"mappings":";;;AASa,QAAA,oBAAoB,GAAkB,MAAM,CACvD,sBAAsB,CACvB,CAAC"}
|