bdy 1.10.14-stage → 1.11.0-beta

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.
Files changed (100) hide show
  1. package/distTs/bin/cli.js +1 -1
  2. package/distTs/package.json +1 -1
  3. package/distTs/src/agent/agent.js +302 -0
  4. package/distTs/src/agent/manager.js +41 -41
  5. package/distTs/src/agent/socket/client.js +159 -0
  6. package/distTs/src/agent/socket/tunnel.js +3 -3
  7. package/distTs/src/agent/wait.js +2 -2
  8. package/distTs/src/command/agent/disable.js +1 -1
  9. package/distTs/src/command/agent/enable.js +1 -1
  10. package/distTs/src/command/agent/install.js +45 -45
  11. package/distTs/src/command/agent/restart.js +8 -8
  12. package/distTs/src/command/agent/start.js +8 -8
  13. package/distTs/src/command/agent/status.js +15 -15
  14. package/distTs/src/command/agent/stop.js +8 -8
  15. package/distTs/src/command/agent/target/disable.js +1 -1
  16. package/distTs/src/command/agent/target/enable.js +1 -1
  17. package/distTs/src/command/agent/target/status.js +1 -1
  18. package/distTs/src/command/agent/tunnel/http.js +18 -18
  19. package/distTs/src/command/agent/tunnel/list.js +7 -7
  20. package/distTs/src/command/agent/tunnel/remove.js +9 -9
  21. package/distTs/src/command/agent/tunnel/start.js +14 -14
  22. package/distTs/src/command/agent/tunnel/status.js +11 -11
  23. package/distTs/src/command/agent/tunnel/tcp.js +19 -19
  24. package/distTs/src/command/agent/tunnel/tls.js +17 -17
  25. package/distTs/src/command/agent/tunnel.js +16 -16
  26. package/distTs/src/command/agent/uninstall.js +13 -13
  27. package/distTs/src/command/agent/update.js +12 -12
  28. package/distTs/src/command/agent/version.js +6 -6
  29. package/distTs/src/command/agent.js +18 -18
  30. package/distTs/src/command/config/add/http.js +15 -15
  31. package/distTs/src/command/config/add/tcp.js +15 -15
  32. package/distTs/src/command/config/add/tls.js +15 -15
  33. package/distTs/src/command/config/add.js +8 -8
  34. package/distTs/src/command/config/get/region.js +5 -5
  35. package/distTs/src/command/config/get/timeout.js +5 -5
  36. package/distTs/src/command/config/get/token.js +5 -5
  37. package/distTs/src/command/config/get/tunnel.js +9 -9
  38. package/distTs/src/command/config/get/tunnels.js +6 -6
  39. package/distTs/src/command/config/get/whitelist.js +5 -5
  40. package/distTs/src/command/config/get.js +14 -14
  41. package/distTs/src/command/config/remove/tunnel.js +9 -9
  42. package/distTs/src/command/config/remove.js +4 -4
  43. package/distTs/src/command/config/set/region.js +8 -8
  44. package/distTs/src/command/config/set/timeout.js +9 -9
  45. package/distTs/src/command/config/set/token.js +7 -7
  46. package/distTs/src/command/config/set/whitelist.js +8 -8
  47. package/distTs/src/command/config/set.js +10 -10
  48. package/distTs/src/command/pre.js +14 -14
  49. package/distTs/src/command/tunnel/config.js +17 -0
  50. package/distTs/src/command/tunnel/http.js +30 -0
  51. package/distTs/src/command/tunnel/start.js +28 -0
  52. package/distTs/src/command/tunnel/tcp.js +30 -0
  53. package/distTs/src/command/tunnel/tls.js +30 -0
  54. package/distTs/src/command/tunnel.js +19 -0
  55. package/distTs/src/command/ut/upload.js +6 -6
  56. package/distTs/src/command/ut.js +3 -2
  57. package/distTs/src/command/version.js +4 -4
  58. package/distTs/src/command/vt/close.js +4 -4
  59. package/distTs/src/command/vt/compare.js +16 -16
  60. package/distTs/src/command/vt/exec.js +12 -12
  61. package/distTs/src/command/vt/installBrowser.js +2 -2
  62. package/distTs/src/command/vt/scrap.js +17 -17
  63. package/distTs/src/command/vt/storybook.js +8 -8
  64. package/distTs/src/command/vt.js +5 -4
  65. package/distTs/src/index.js +12 -20
  66. package/distTs/src/input.js +38 -38
  67. package/distTs/src/logger.js +2 -2
  68. package/distTs/src/output.js +14 -14
  69. package/distTs/src/texts.js +5 -4
  70. package/distTs/src/tunnel/agent.js +3 -3
  71. package/distTs/src/tunnel/api/agent.js +99 -0
  72. package/distTs/src/tunnel/api/buddy.js +139 -0
  73. package/distTs/src/tunnel/cfg.js +234 -0
  74. package/distTs/src/tunnel/http/log.js +3 -3
  75. package/distTs/src/tunnel/http.js +29 -29
  76. package/distTs/src/tunnel/identification.js +13 -13
  77. package/distTs/src/tunnel/latency.js +3 -3
  78. package/distTs/src/tunnel/output/interactive/tunnel.js +860 -0
  79. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +43 -0
  80. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +65 -0
  81. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +18 -0
  82. package/distTs/src/tunnel/output/noninteractive/tunnel.js +59 -0
  83. package/distTs/src/tunnel/server/cert.js +52 -0
  84. package/distTs/src/tunnel/server/http1.js +75 -0
  85. package/distTs/src/tunnel/server/http2.js +78 -0
  86. package/distTs/src/tunnel/server/sftp.js +497 -0
  87. package/distTs/src/tunnel/server/ssh.js +446 -0
  88. package/distTs/src/tunnel/server/tls.js +41 -0
  89. package/distTs/src/tunnel/ssh/client.js +197 -0
  90. package/distTs/src/tunnel/tcp.js +3 -3
  91. package/distTs/src/tunnel/tunnel.js +656 -0
  92. package/distTs/src/utils.js +2 -2
  93. package/distTs/src/visualTest/ci.js +10 -10
  94. package/distTs/src/visualTest/context.js +4 -4
  95. package/distTs/src/visualTest/requests.js +71 -71
  96. package/distTs/src/visualTest/resources.js +5 -5
  97. package/distTs/src/visualTest/server.js +9 -9
  98. package/distTs/src/visualTest/snapshots.js +18 -18
  99. package/distTs/src/visualTest/validation.js +3 -3
  100. package/package.json +1 -1
package/distTs/bin/cli.js CHANGED
@@ -2,4 +2,4 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  console.log = () => { }; // fix for termkit
5
- require("../src/index.js");
5
+ require("../src/index");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.10.14-stage",
4
+ "version": "1.11.0-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const events_1 = __importDefault(require("events"));
7
+ const logger_1 = __importDefault(require("../logger"));
8
+ const texts_1 = require("../texts");
9
+ const utils_1 = require("../utils");
10
+ const tunnel_1 = __importDefault(require("../tunnel/tunnel"));
11
+ const output_1 = __importDefault(require("../output"));
12
+ const client_1 = __importDefault(require("./socket/client"));
13
+ class Agent extends events_1.default {
14
+ constructor(id, host, token, service, target, api, disabled) {
15
+ super();
16
+ this.id = id;
17
+ this.host = host;
18
+ this.token = token;
19
+ this.service = service;
20
+ this.target = target;
21
+ this.disabled = disabled;
22
+ this.tunnels = [];
23
+ this.tunnelsUpdating = false;
24
+ this.started = false;
25
+ this.api = api;
26
+ this.manager = null;
27
+ this.onRefresh = null;
28
+ this.socket = new client_1.default(host, id, token);
29
+ this.socket.on(utils_1.SOCKET_IO_EVENT_FETCH_SUCCESS, (data) => this._onSocketFetch(data));
30
+ this.socket.on(utils_1.SOCKET_IO_EVENT_FETCH_FAILED, (err) => this._onSocketFetchFailed(err));
31
+ this.socket.on(utils_1.SOCKET_IO_EVENT_CONNECTED, () => this._onSocketConnected());
32
+ this.socket.on(utils_1.SOCKET_IO_EVENT_DISCONNECTED, () => this._onSocketDisconnected());
33
+ this.socket.on(utils_1.SOCKET_IO_EVENT_TUNNEL, (tunnel, action) => this._onSocketTunnel(tunnel, action));
34
+ this.socket.on(utils_1.SOCKET_IO_EVENT_AGENT, (agent, action) => this._onSocketAgent(agent, action));
35
+ }
36
+ destroy() {
37
+ if (this.socket) {
38
+ this.socket.removeAllListeners();
39
+ this.socket.destroy();
40
+ this.socket = null;
41
+ }
42
+ this.manager = null;
43
+ this.onRefresh = null;
44
+ this.api = null;
45
+ // musza byc manualnie wczesniej zniszczone to tylko czysci obiekt
46
+ this.tunnels = null;
47
+ }
48
+ _onSocketTunnel(data, action) {
49
+ if (action === 'DEL') {
50
+ this.destroyTunnel(data.id);
51
+ if (!this.service && this.tunnels.length <= 0)
52
+ output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
53
+ }
54
+ else {
55
+ logger_1.default.debug('Socket fetch tunnel after sync push');
56
+ this.socket.fetch(this.started, null, null, false, []);
57
+ }
58
+ }
59
+ async _onSocketAgent(data, action) {
60
+ if (action === 'DEL') {
61
+ if (this.manager) {
62
+ return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
63
+ }
64
+ output_1.default.exitError(texts_1.ERR_AGENT_REMOVED);
65
+ }
66
+ else {
67
+ this.target = !!data.target;
68
+ this.disabled = !!data.disabled;
69
+ if (data.disabled === this.started) {
70
+ await this.makeAction(data.disabled ? utils_1.AGENT_ACTION_STOP : utils_1.AGENT_ACTION_START);
71
+ }
72
+ else if (data.action) {
73
+ try {
74
+ await this.makeAction(data.action);
75
+ }
76
+ catch (err) {
77
+ logger_1.default.error('Agent sync error');
78
+ logger_1.default.error(err);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ _onSocketConnected() {
84
+ if (this.onRefresh)
85
+ this.onRefresh(true);
86
+ }
87
+ _onSocketDisconnected() {
88
+ if (this.onRefresh)
89
+ this.onRefresh(false);
90
+ }
91
+ async _onSocketFetch(data) {
92
+ try {
93
+ if (data.agent.action)
94
+ await this.makeAction(data.agent.action);
95
+ this.refreshTunnels(data.tunnels || []);
96
+ }
97
+ catch (err) {
98
+ logger_1.default.error('Fetch error');
99
+ logger_1.default.error(err);
100
+ }
101
+ }
102
+ _onSocketFetchFailed(err) {
103
+ if (err instanceof utils_1.ApiErrorAgentNotFound) {
104
+ if (this.manager) {
105
+ return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
106
+ }
107
+ output_1.default.exitError(texts_1.ERR_AGENT_REMOVED);
108
+ }
109
+ else {
110
+ logger_1.default.error(texts_1.LOG_ERROR_WHILE_REFRESHING_AGENT);
111
+ logger_1.default.error(err);
112
+ }
113
+ }
114
+ startRefreshingConfiguration(onRefresh) {
115
+ this.onRefresh = onRefresh;
116
+ if (this.onRefresh)
117
+ this.onRefresh(this.socket.connected);
118
+ this.refreshIn15();
119
+ }
120
+ async start() {
121
+ this.started = true;
122
+ this.tunnels.forEach((t) => {
123
+ t.start();
124
+ });
125
+ this.socket.fetch(this.started, '', null, true, this.getTunnelsUpdate());
126
+ }
127
+ async enable() {
128
+ this.disabled = false;
129
+ this.started = true;
130
+ this.tunnels.forEach((t) => {
131
+ t.start();
132
+ });
133
+ this.socket.fetch(this.started, '', false, true, this.getTunnelsUpdate());
134
+ }
135
+ async stop(clearAction = true) {
136
+ this.started = false;
137
+ this.tunnels.forEach((t) => {
138
+ t.stop();
139
+ });
140
+ this.socket.fetch(this.started, clearAction ? '' : null, null, false, this.getTunnelsUpdate());
141
+ }
142
+ async disable() {
143
+ this.disabled = true;
144
+ this.started = false;
145
+ this.tunnels.forEach((t) => {
146
+ t.stop();
147
+ });
148
+ this.socket.fetch(this.started, '', true, false, this.getTunnelsUpdate());
149
+ }
150
+ async restart() {
151
+ await this.stop(false);
152
+ await (0, utils_1.sleep)(100);
153
+ await this.start();
154
+ }
155
+ async delete() {
156
+ try {
157
+ await this.api.unregister(this.id, this.host, this.token);
158
+ }
159
+ catch {
160
+ // do nothing
161
+ }
162
+ process.exit(0);
163
+ }
164
+ refreshIn15(fetch = true, counter = 1) {
165
+ setTimeout(async () => {
166
+ try {
167
+ if (fetch || counter >= 3) {
168
+ counter = 0;
169
+ this.socket.fetch(this.started, null, null, false, this.getTunnelsUpdate());
170
+ }
171
+ else {
172
+ this.update();
173
+ }
174
+ }
175
+ catch {
176
+ // do nothing
177
+ }
178
+ this.refreshIn15(false, counter + 1);
179
+ }, 15000);
180
+ }
181
+ httpRequest(tunnelId, logRequest) {
182
+ this.socket.request(tunnelId, logRequest);
183
+ }
184
+ update(force = false) {
185
+ this.socket.update(this.started, this.getTunnelsUpdate(), force);
186
+ }
187
+ async makeAction(action) {
188
+ if (action === utils_1.AGENT_ACTION_STOP) {
189
+ if (this.manager) {
190
+ return this.manager.agentStop();
191
+ }
192
+ return this.stop();
193
+ }
194
+ if (action === utils_1.AGENT_ACTION_START) {
195
+ if (this.manager) {
196
+ return this.manager.agentStart();
197
+ }
198
+ return this.start();
199
+ }
200
+ if (action === utils_1.AGENT_ACTION_RESTART) {
201
+ if (this.manager) {
202
+ return this.manager.agentRestart();
203
+ }
204
+ return this.restart();
205
+ }
206
+ if (action === utils_1.AGENT_ACTION_DELETE) {
207
+ if (this.manager) {
208
+ return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
209
+ }
210
+ return this.delete();
211
+ }
212
+ }
213
+ refreshTunnels(tunnels) {
214
+ if (this.tunnelsUpdating)
215
+ return;
216
+ this.tunnelsUpdating = true;
217
+ let hasTunnels = false;
218
+ let haveTunnels = false;
219
+ try {
220
+ const tt = [...this.tunnels];
221
+ hasTunnels = tt.length > 0;
222
+ haveTunnels = tunnels.length > 0;
223
+ if (hasTunnels) {
224
+ tt.forEach((tunnel) => {
225
+ if (!tunnels.find((t) => t.id === tunnel.id)) {
226
+ this.destroyTunnel(tunnel.id);
227
+ }
228
+ });
229
+ }
230
+ if (haveTunnels) {
231
+ tunnels.forEach((data) => {
232
+ let sshHostKey;
233
+ if (this.manager)
234
+ sshHostKey = this.manager.sshHostKey;
235
+ const tunnel = tt.find((tunnel) => data.id === tunnel.id);
236
+ if (!tunnel) {
237
+ this.addTunnel(new tunnel_1.default({
238
+ ...data,
239
+ sshHostKey,
240
+ agent: {
241
+ id: this.id,
242
+ host: this.host,
243
+ token: this.token,
244
+ },
245
+ }));
246
+ }
247
+ else if (tunnel.hasChanged(data)) {
248
+ tunnel.recreate(data);
249
+ }
250
+ });
251
+ }
252
+ }
253
+ catch {
254
+ // do nothing
255
+ }
256
+ this.tunnelsUpdating = false;
257
+ if (!this.service && hasTunnels && !haveTunnels) {
258
+ output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
259
+ }
260
+ }
261
+ getTunnelsUpdate() {
262
+ const update = [];
263
+ this.tunnels.forEach((t) => {
264
+ update.push({
265
+ id: t.id,
266
+ active: t.status === utils_1.TUNNEL_OPEN,
267
+ regionLatency: t.regionLatency ? t.regionLatency.latency : -1,
268
+ targetLatency: t.targetLatency ? t.targetLatency.latency : -1,
269
+ totalConnections: t.totalConnections,
270
+ currentConnections: Object.keys(t.connections).length,
271
+ httpIdentified: t.identify ? t.identify.type : '',
272
+ });
273
+ });
274
+ return update;
275
+ }
276
+ addTunnel(tunnel) {
277
+ this.tunnels.push(tunnel);
278
+ if (this.started)
279
+ tunnel.start();
280
+ tunnel.on(utils_1.TUNNEL_EVENT_OPEN, () => this.update(true));
281
+ tunnel.on(utils_1.TUNNEL_EVENT_CLOSED, () => this.update());
282
+ tunnel.on(utils_1.TUNNEL_EVENT_TCP_OPEN, () => this.update());
283
+ tunnel.on(utils_1.TUNNEL_EVENT_TCP_CLOSED, () => this.update());
284
+ tunnel.on(utils_1.TUNNEL_EVENT_TLS_OPEN, () => this.update());
285
+ tunnel.on(utils_1.TUNNEL_EVENT_TLS_CLOSED, () => this.update());
286
+ tunnel.on(utils_1.TUNNEL_EVENT_HTTP_IDENTIFIED, () => this.update());
287
+ tunnel.on(utils_1.TUNNEL_EVENT_HTTP_OPEN, () => this.update());
288
+ tunnel.on(utils_1.TUNNEL_EVENT_HTTP_CLOSED, () => this.update());
289
+ tunnel.on(utils_1.TUNNEL_EVENT_STOPPED, () => this.update());
290
+ tunnel.on(utils_1.TUNNEL_EVENT_HTTP_REQUEST, (t, logRequest) => this.httpRequest(t.id, logRequest));
291
+ }
292
+ destroyTunnel(id) {
293
+ let tunnel = this.tunnels.find((t) => t.id === id);
294
+ if (!tunnel)
295
+ return null;
296
+ this.tunnels = this.tunnels.filter((t) => t.id !== tunnel.id);
297
+ tunnel.stop();
298
+ tunnel.removeAllListeners();
299
+ return tunnel;
300
+ }
301
+ }
302
+ exports.default = Agent;
@@ -3,21 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const utils_js_1 = require("../utils.js");
6
+ const utils_1 = require("../utils");
7
7
  const ws_1 = require("ws");
8
- const logger_js_1 = __importDefault(require("../logger.js"));
8
+ const logger_1 = __importDefault(require("../logger"));
9
9
  const http_1 = __importDefault(require("http"));
10
- const output_js_1 = __importDefault(require("../output.js"));
11
- const texts_js_1 = require("../texts.js");
10
+ const output_1 = __importDefault(require("../output"));
11
+ const texts_1 = require("../texts");
12
12
  const windows_1 = __importDefault(require("./windows"));
13
13
  const linux_1 = __importDefault(require("./linux"));
14
14
  const system_1 = __importDefault(require("./system"));
15
15
  const osx_1 = __importDefault(require("./osx"));
16
- const buddy_js_1 = __importDefault(require("../api/buddy.js"));
17
- const socket_js_1 = __importDefault(require("./socket.js"));
16
+ const buddy_1 = __importDefault(require("../tunnel/api/buddy"));
17
+ const socket_1 = __importDefault(require("./socket"));
18
18
  class AgentManagerClass {
19
19
  constructor() {
20
- this.status = utils_js_1.AGENT_STATUS_DISABLED;
20
+ this.status = utils_1.AGENT_STATUS_DISABLED;
21
21
  this.id = null;
22
22
  this.host = null;
23
23
  this.token = null;
@@ -27,13 +27,13 @@ class AgentManagerClass {
27
27
  this.agent = null;
28
28
  this.server = null;
29
29
  this.ws = null;
30
- if ((0, utils_js_1.isOsx)()) {
30
+ if ((0, utils_1.isOsx)()) {
31
31
  this.system = new osx_1.default();
32
32
  }
33
- else if ((0, utils_js_1.isLinux)()) {
33
+ else if ((0, utils_1.isLinux)()) {
34
34
  this.system = new linux_1.default();
35
35
  }
36
- else if ((0, utils_js_1.isWindows)()) {
36
+ else if ((0, utils_1.isWindows)()) {
37
37
  this.system = new windows_1.default();
38
38
  }
39
39
  else {
@@ -45,26 +45,26 @@ class AgentManagerClass {
45
45
  }
46
46
  async tryFetch() {
47
47
  try {
48
- this.agent = await buddy_js_1.default.fetchAgent(this.id, this.host, this.token);
48
+ this.agent = await buddy_1.default.fetchAgent(this.id, this.host, this.token);
49
49
  this.agent.manager = this;
50
50
  this.agent.startRefreshingConfiguration((success) => {
51
51
  if (success)
52
- this.status = utils_js_1.AGENT_STATUS_ENABLED;
52
+ this.status = utils_1.AGENT_STATUS_ENABLED;
53
53
  else
54
- this.status = utils_js_1.AGENT_STATUS_FETCH_FAILED;
54
+ this.status = utils_1.AGENT_STATUS_FETCH_FAILED;
55
55
  });
56
56
  if (this.shouldStart)
57
57
  await this.agent.start();
58
- this.status = utils_js_1.AGENT_STATUS_ENABLED;
58
+ this.status = utils_1.AGENT_STATUS_ENABLED;
59
59
  }
60
60
  catch (err) {
61
- if (err instanceof utils_js_1.ApiErrorAgentNotFound) {
62
- await this.disableAgentAndExit(texts_js_1.ERR_AGENT_NOT_FOUND);
61
+ if (err instanceof utils_1.ApiErrorAgentNotFound) {
62
+ await this.disableAgentAndExit(texts_1.ERR_AGENT_NOT_FOUND);
63
63
  }
64
64
  else {
65
- output_js_1.default.normal(texts_js_1.AGENT_FETCH_RETRY);
66
- this.status = utils_js_1.AGENT_STATUS_FETCH_FAILED;
67
- await (0, utils_js_1.sleep)(3000);
65
+ output_1.default.normal(texts_1.AGENT_FETCH_RETRY);
66
+ this.status = utils_1.AGENT_STATUS_FETCH_FAILED;
67
+ await (0, utils_1.sleep)(3000);
68
68
  return this.tryFetch();
69
69
  }
70
70
  }
@@ -88,7 +88,7 @@ class AgentManagerClass {
88
88
  const tunnels = [];
89
89
  if (this.agent) {
90
90
  this.agent.tunnels.forEach((tunnel) => {
91
- if (tunnel.type === utils_js_1.TUNNEL_SSH)
91
+ if (tunnel.type === utils_1.TUNNEL_SSH)
92
92
  return;
93
93
  tunnels.push({
94
94
  id: tunnel.id,
@@ -130,7 +130,7 @@ class AgentManagerClass {
130
130
  return;
131
131
  }
132
132
  try {
133
- await buddy_js_1.default.enableTarget(this.id, this.host, this.token);
133
+ await buddy_1.default.enableTarget(this.id, this.host, this.token);
134
134
  this.agent.target = true;
135
135
  }
136
136
  catch (err) {
@@ -145,7 +145,7 @@ class AgentManagerClass {
145
145
  return;
146
146
  }
147
147
  try {
148
- await buddy_js_1.default.disableTarget(this.id, this.host, this.token);
148
+ await buddy_1.default.disableTarget(this.id, this.host, this.token);
149
149
  this.agent.target = false;
150
150
  }
151
151
  catch (err) {
@@ -158,9 +158,9 @@ class AgentManagerClass {
158
158
  this.serverOutput(res, {
159
159
  id: this.id,
160
160
  status: this.status,
161
- version: (0, utils_js_1.getVersion)(),
161
+ version: (0, utils_1.getVersion)(),
162
162
  started: this.shouldStart,
163
- enabled: this.status === utils_js_1.AGENT_STATUS_ENABLED,
163
+ enabled: this.status === utils_1.AGENT_STATUS_ENABLED,
164
164
  });
165
165
  }
166
166
  processBody(req) {
@@ -199,7 +199,7 @@ class AgentManagerClass {
199
199
  return;
200
200
  }
201
201
  try {
202
- await buddy_js_1.default.removeTunnel(this.id, tunnel.id, this.host, this.token);
202
+ await buddy_1.default.removeTunnel(this.id, tunnel.id, this.host, this.token);
203
203
  }
204
204
  catch (err) {
205
205
  this.serverError(res, err.message);
@@ -213,11 +213,11 @@ class AgentManagerClass {
213
213
  let saved = await this.agentStop();
214
214
  if (!saved)
215
215
  return false;
216
- await (0, utils_js_1.sleep)(100);
216
+ await (0, utils_1.sleep)(100);
217
217
  return await this.agentStart();
218
218
  }
219
219
  async disableAgentAndExit(txt) {
220
- logger_js_1.default.error(txt);
220
+ logger_1.default.error(txt);
221
221
  try {
222
222
  await this.system.disable();
223
223
  }
@@ -225,7 +225,7 @@ class AgentManagerClass {
225
225
  // do nothing
226
226
  }
227
227
  try {
228
- await buddy_js_1.default.unregister(this.id, this.host, this.token);
228
+ await buddy_1.default.unregister(this.id, this.host, this.token);
229
229
  }
230
230
  catch {
231
231
  // do nothing
@@ -242,7 +242,7 @@ class AgentManagerClass {
242
242
  catch {
243
243
  // do nothing
244
244
  }
245
- output_js_1.default.exitError(txt);
245
+ output_1.default.exitError(txt);
246
246
  }
247
247
  async agentStop() {
248
248
  const saved = this.resaveAgentConfig(false, true);
@@ -370,7 +370,7 @@ class AgentManagerClass {
370
370
  }
371
371
  let tunnel;
372
372
  try {
373
- tunnel = await buddy_js_1.default.addTunnel(this.id, this.host, this.token, data, this.sshHostKey);
373
+ tunnel = await buddy_1.default.addTunnel(this.id, this.host, this.token, data, this.sshHostKey);
374
374
  }
375
375
  catch (err) {
376
376
  this.serverError(res, err.message);
@@ -383,7 +383,7 @@ class AgentManagerClass {
383
383
  });
384
384
  }
385
385
  async processRequest(req, res) {
386
- logger_js_1.default.info((0, texts_js_1.LOG_REQUEST)(req.url));
386
+ logger_1.default.info((0, texts_1.LOG_REQUEST)(req.url));
387
387
  if (req.url === '/status')
388
388
  return this.processStatus(res);
389
389
  if (req.url === '/target')
@@ -411,7 +411,7 @@ class AgentManagerClass {
411
411
  this.server404(res);
412
412
  }
413
413
  processUpgrade(req, socket, head) {
414
- logger_js_1.default.info((0, texts_js_1.LOG_REQUEST)(req.url));
414
+ logger_1.default.info((0, texts_1.LOG_REQUEST)(req.url));
415
415
  const url = new URL(req.url, 'http://localhost');
416
416
  const id = url.searchParams.get('id');
417
417
  if (url.pathname === '/tunnel' && id) {
@@ -428,11 +428,11 @@ class AgentManagerClass {
428
428
  return;
429
429
  }
430
430
  const tunnel = this.agent.tunnels.find((t) => t.id === id);
431
- if (!tunnel || tunnel.type === utils_js_1.TUNNEL_SSH) {
431
+ if (!tunnel || tunnel.type === utils_1.TUNNEL_SSH) {
432
432
  con.close();
433
433
  return;
434
434
  }
435
- new socket_js_1.default(con, tunnel);
435
+ new socket_1.default(con, tunnel);
436
436
  }
437
437
  createServer() {
438
438
  this.server = http_1.default.createServer((req, res) => this.processRequest(req, res));
@@ -441,10 +441,10 @@ class AgentManagerClass {
441
441
  this.server.on('upgrade', (req, socket, head) => this.processUpgrade(req, socket, head));
442
442
  this.server.listen(this.port, async (err) => {
443
443
  if (err) {
444
- await this.disableAgentAndExit(texts_js_1.LOG_ERROR_STARTING_AGENT_SERVER);
444
+ await this.disableAgentAndExit(texts_1.LOG_ERROR_STARTING_AGENT_SERVER);
445
445
  }
446
446
  else {
447
- logger_js_1.default.info(texts_js_1.LOG_AGENT_SERVER_STARTED);
447
+ logger_1.default.info(texts_1.LOG_AGENT_SERVER_STARTED);
448
448
  }
449
449
  });
450
450
  }
@@ -461,7 +461,7 @@ class AgentManagerClass {
461
461
  this.shouldStart = shouldStart;
462
462
  }
463
463
  if (!this.sshHostKey)
464
- this.sshHostKey = (0, utils_js_1.createSshHostKey)();
464
+ this.sshHostKey = (0, utils_1.createSshHostKey)();
465
465
  }
466
466
  else {
467
467
  // save from param
@@ -477,23 +477,23 @@ class AgentManagerClass {
477
477
  }
478
478
  }
479
479
  async load(id, host, token, port, start) {
480
- this.status = utils_js_1.AGENT_STATUS_INITIALIZING;
480
+ this.status = utils_1.AGENT_STATUS_INITIALIZING;
481
481
  this.id = id;
482
482
  this.host = host;
483
483
  this.token = token;
484
484
  this.port = parseInt(port, 10);
485
485
  if (!this.id || !this.token || !this.host || !this.port) {
486
- await this.disableAgentAndExit(texts_js_1.ERR_AGENT_NOT_REGISTERED);
486
+ await this.disableAgentAndExit(texts_1.ERR_AGENT_NOT_REGISTERED);
487
487
  return;
488
488
  }
489
489
  const ok = this.resaveAgentConfig(start);
490
490
  if (!ok) {
491
- await this.disableAgentAndExit(texts_js_1.ERR_SAVING_AGENT_CONFIG);
491
+ await this.disableAgentAndExit(texts_1.ERR_SAVING_AGENT_CONFIG);
492
492
  return;
493
493
  }
494
494
  this.createServer();
495
495
  await this.tryFetch();
496
- logger_js_1.default.info(texts_js_1.LOG_AGENT_STARTED);
496
+ logger_1.default.info(texts_1.LOG_AGENT_STARTED);
497
497
  }
498
498
  }
499
499
  const AgentManager = new AgentManagerClass();