bdy 1.12.8-beta → 1.12.8-dev-pipeline-run

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 (156) hide show
  1. package/distTs/package.json +1 -1
  2. package/package.json +1 -1
  3. package/distTs/bin/cli.js +0 -5
  4. package/distTs/src/agent/agent.js +0 -328
  5. package/distTs/src/agent/linux.js +0 -124
  6. package/distTs/src/agent/manager.js +0 -519
  7. package/distTs/src/agent/osx.js +0 -146
  8. package/distTs/src/agent/socket/client.js +0 -178
  9. package/distTs/src/agent/socket/tunnel.js +0 -237
  10. package/distTs/src/agent/socket.js +0 -242
  11. package/distTs/src/agent/system.js +0 -179
  12. package/distTs/src/agent/wait.js +0 -23
  13. package/distTs/src/agent/windows.js +0 -159
  14. package/distTs/src/agent.js +0 -302
  15. package/distTs/src/api/agent.js +0 -99
  16. package/distTs/src/api/buddy.js +0 -139
  17. package/distTs/src/api/socket.js +0 -159
  18. package/distTs/src/cfg.js +0 -234
  19. package/distTs/src/command/agent/disable.js +0 -27
  20. package/distTs/src/command/agent/enable.js +0 -27
  21. package/distTs/src/command/agent/install.js +0 -117
  22. package/distTs/src/command/agent/restart.js +0 -27
  23. package/distTs/src/command/agent/run.js +0 -19
  24. package/distTs/src/command/agent/start.js +0 -28
  25. package/distTs/src/command/agent/status.js +0 -34
  26. package/distTs/src/command/agent/stop.js +0 -28
  27. package/distTs/src/command/agent/target/disable.js +0 -27
  28. package/distTs/src/command/agent/target/enable.js +0 -27
  29. package/distTs/src/command/agent/target/status.js +0 -32
  30. package/distTs/src/command/agent/target.js +0 -15
  31. package/distTs/src/command/agent/tunnel/http.js +0 -43
  32. package/distTs/src/command/agent/tunnel/list.js +0 -27
  33. package/distTs/src/command/agent/tunnel/remove.js +0 -28
  34. package/distTs/src/command/agent/tunnel/start.js +0 -34
  35. package/distTs/src/command/agent/tunnel/status.js +0 -31
  36. package/distTs/src/command/agent/tunnel/tcp.js +0 -43
  37. package/distTs/src/command/agent/tunnel/tls.js +0 -43
  38. package/distTs/src/command/agent/tunnel.js +0 -23
  39. package/distTs/src/command/agent/uninstall.js +0 -44
  40. package/distTs/src/command/agent/update.js +0 -38
  41. package/distTs/src/command/agent/version.js +0 -21
  42. package/distTs/src/command/agent.js +0 -35
  43. package/distTs/src/command/config/add/http.js +0 -25
  44. package/distTs/src/command/config/add/tcp.js +0 -25
  45. package/distTs/src/command/config/add/tls.js +0 -25
  46. package/distTs/src/command/config/add.js +0 -15
  47. package/distTs/src/command/config/get/region.js +0 -15
  48. package/distTs/src/command/config/get/timeout.js +0 -15
  49. package/distTs/src/command/config/get/token.js +0 -15
  50. package/distTs/src/command/config/get/tunnel.js +0 -19
  51. package/distTs/src/command/config/get/tunnels.js +0 -15
  52. package/distTs/src/command/config/get/whitelist.js +0 -15
  53. package/distTs/src/command/config/get.js +0 -21
  54. package/distTs/src/command/config/remove/tunnel.js +0 -19
  55. package/distTs/src/command/config/remove.js +0 -11
  56. package/distTs/src/command/config/set/region.js +0 -17
  57. package/distTs/src/command/config/set/timeout.js +0 -17
  58. package/distTs/src/command/config/set/token.js +0 -16
  59. package/distTs/src/command/config/set/whitelist.js +0 -17
  60. package/distTs/src/command/config/set.js +0 -17
  61. package/distTs/src/command/config.js +0 -17
  62. package/distTs/src/command/http.js +0 -30
  63. package/distTs/src/command/pre.js +0 -49
  64. package/distTs/src/command/start.js +0 -28
  65. package/distTs/src/command/tcp.js +0 -30
  66. package/distTs/src/command/tls.js +0 -30
  67. package/distTs/src/command/tunnel/config.js +0 -17
  68. package/distTs/src/command/tunnel/http.js +0 -31
  69. package/distTs/src/command/tunnel/start.js +0 -28
  70. package/distTs/src/command/tunnel/tcp.js +0 -30
  71. package/distTs/src/command/tunnel/tls.js +0 -30
  72. package/distTs/src/command/tunnel.js +0 -19
  73. package/distTs/src/command/ut/upload.js +0 -108
  74. package/distTs/src/command/ut.js +0 -12
  75. package/distTs/src/command/version.js +0 -13
  76. package/distTs/src/command/vt/close.js +0 -27
  77. package/distTs/src/command/vt/compare/validation.js +0 -173
  78. package/distTs/src/command/vt/compare.js +0 -97
  79. package/distTs/src/command/vt/exec.js +0 -81
  80. package/distTs/src/command/vt/installBrowser.js +0 -20
  81. package/distTs/src/command/vt/scrap.js +0 -193
  82. package/distTs/src/command/vt/storybook.js +0 -92
  83. package/distTs/src/command/vt.js +0 -22
  84. package/distTs/src/format.js +0 -174
  85. package/distTs/src/index.js +0 -34
  86. package/distTs/src/input.js +0 -270
  87. package/distTs/src/logger.js +0 -95
  88. package/distTs/src/output/interactive/tunnel.js +0 -860
  89. package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
  90. package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
  91. package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
  92. package/distTs/src/output/noninteractive/tunnel.js +0 -59
  93. package/distTs/src/output.js +0 -143
  94. package/distTs/src/server/cert.js +0 -52
  95. package/distTs/src/server/http1.js +0 -75
  96. package/distTs/src/server/http2.js +0 -78
  97. package/distTs/src/server/sftp.js +0 -497
  98. package/distTs/src/server/ssh.js +0 -446
  99. package/distTs/src/server/tls.js +0 -41
  100. package/distTs/src/ssh/client.js +0 -197
  101. package/distTs/src/texts.js +0 -421
  102. package/distTs/src/tunnel/agent.js +0 -103
  103. package/distTs/src/tunnel/api/agent.js +0 -100
  104. package/distTs/src/tunnel/api/buddy.js +0 -141
  105. package/distTs/src/tunnel/cfg.js +0 -243
  106. package/distTs/src/tunnel/compression.js +0 -44
  107. package/distTs/src/tunnel/dns.js +0 -53
  108. package/distTs/src/tunnel/html/503.html +0 -338
  109. package/distTs/src/tunnel/html.js +0 -33
  110. package/distTs/src/tunnel/http/log.js +0 -218
  111. package/distTs/src/tunnel/http/serve.js +0 -133
  112. package/distTs/src/tunnel/http/stream.js +0 -34
  113. package/distTs/src/tunnel/http.js +0 -508
  114. package/distTs/src/tunnel/identification.js +0 -103
  115. package/distTs/src/tunnel/latency.js +0 -83
  116. package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
  117. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
  118. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
  119. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
  120. package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
  121. package/distTs/src/tunnel/server/cert.js +0 -54
  122. package/distTs/src/tunnel/server/http1.js +0 -80
  123. package/distTs/src/tunnel/server/http2.js +0 -84
  124. package/distTs/src/tunnel/server/sftp.js +0 -514
  125. package/distTs/src/tunnel/server/ssh.js +0 -464
  126. package/distTs/src/tunnel/server/tls.js +0 -47
  127. package/distTs/src/tunnel/ssh/client.js +0 -211
  128. package/distTs/src/tunnel/tcp.js +0 -113
  129. package/distTs/src/tunnel/tunnel.js +0 -1010
  130. package/distTs/src/tunnel.js +0 -656
  131. package/distTs/src/types/ciInfo.js +0 -10
  132. package/distTs/src/types/options.js +0 -2
  133. package/distTs/src/types/plugin.js +0 -2
  134. package/distTs/src/types/queue.js +0 -2
  135. package/distTs/src/types/requests.js +0 -2
  136. package/distTs/src/types/resources.js +0 -2
  137. package/distTs/src/types/schemas.js +0 -54
  138. package/distTs/src/types/scrape.js +0 -2
  139. package/distTs/src/types/snapshots.js +0 -2
  140. package/distTs/src/types/storybook.js +0 -2
  141. package/distTs/src/types/tunnel.js +0 -141
  142. package/distTs/src/unitTest/ci.js +0 -108
  143. package/distTs/src/unitTest/requests.js +0 -72
  144. package/distTs/src/utils.js +0 -378
  145. package/distTs/src/visualTest/browser.js +0 -39
  146. package/distTs/src/visualTest/ci.js +0 -241
  147. package/distTs/src/visualTest/context.js +0 -52
  148. package/distTs/src/visualTest/exec.js +0 -51
  149. package/distTs/src/visualTest/linkUtils.js +0 -21
  150. package/distTs/src/visualTest/queue.js +0 -43
  151. package/distTs/src/visualTest/requests.js +0 -365
  152. package/distTs/src/visualTest/resources.js +0 -259
  153. package/distTs/src/visualTest/server.js +0 -109
  154. package/distTs/src/visualTest/snapshots.js +0 -129
  155. package/distTs/src/visualTest/utils/parseDom.js +0 -238
  156. package/distTs/src/visualTest/validation.js +0 -18
@@ -1,867 +0,0 @@
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 utils_1 = require("../../../utils");
7
- // @ts-ignore
8
- const termkit_no_lazy_require_1 = __importDefault(require("terminal-kit/lib/termkit-no-lazy-require"));
9
- const isbinaryfile_1 = require("isbinaryfile");
10
- const format_1 = __importDefault(require("../../../format"));
11
- const tunnel_1 = require("../../../types/tunnel");
12
- const COLOR_CYAN = 6;
13
- const COLOR_LIGHT_GRAY = 7;
14
- const COLOR_RED = 9;
15
- const COLOR_GREEN = 10;
16
- const COLOR_WHITE = 15;
17
- const ROW_LENGTH = 200;
18
- const COLUMN_LENGTH = 30;
19
- const REQUESTS_MAX = 10;
20
- const REQUESTS_MAX_LENGTH = 80;
21
- const REQUEST_INFO_MAX_LENGTH = 100;
22
- const REQUEST_INFO_START_Y = 3;
23
- const fillString = (str, len) => {
24
- if (str.length > len)
25
- return str.substring(0, len);
26
- const need = len - str.length;
27
- for (let i = 0; i < need; i += 1) {
28
- str += ' ';
29
- }
30
- return str;
31
- };
32
- const formatBytes = (len) => {
33
- if (len < 1024)
34
- return `${len}B`;
35
- len = Math.round(len / 1024);
36
- if (len < 1024)
37
- return `${len}KB`;
38
- len = Math.round(len / 1024);
39
- if (len < 1024)
40
- return `${len}MB`;
41
- len = Math.round(len / 1024);
42
- return `${len}GB`;
43
- };
44
- class OutputInteractiveTunnel {
45
- terminal;
46
- tunnel;
47
- viewPort;
48
- sprites;
49
- selectedRequest;
50
- constructor(terminal, tunnel) {
51
- this.terminal = terminal;
52
- this.tunnel = tunnel;
53
- this.viewPort = null;
54
- this.sprites = {};
55
- this.selectedRequest = null;
56
- }
57
- retry() {
58
- if (this.selectedRequest && !this.selectedRequest.requestBody.tooLarge) {
59
- this.tunnel.retryHttpLogRequest(this.selectedRequest);
60
- }
61
- }
62
- draw() {
63
- let y = 0;
64
- y += this.updateSpriteHeader(y);
65
- y += this.updateSpriteStatus(y);
66
- y += this.updateSpriteDns(y);
67
- y += this.updateSpriteType(y);
68
- y += this.updateSpriteRegion(y);
69
- y += this.updateSpriteTarget(y);
70
- y += this.updateSpriteIdentify(y);
71
- y += this.updateSpriteTerminate(y);
72
- y += this.updateSpriteEntry(y);
73
- y += this.updateSpriteLatency(y);
74
- y += this.updateSpriteConnections(y);
75
- y += this.updateSpriteRequests(y);
76
- y += this.updateSpriteRequestInfo(y);
77
- this.updateSpriteRequestScrollable();
78
- if (y < this.terminal.height) {
79
- this.viewPort.fill({
80
- char: ' ',
81
- region: {
82
- x: 0,
83
- y,
84
- width: this.terminal.width,
85
- height: this.terminal.height - y,
86
- },
87
- });
88
- }
89
- this.viewPort.draw();
90
- }
91
- createSpriteConnections() {
92
- let init = fillString('', ROW_LENGTH);
93
- init += '\n';
94
- init += fillString('Connections', ROW_LENGTH);
95
- init += '\n';
96
- init += fillString('', ROW_LENGTH);
97
- init += '\n';
98
- init += fillString('', ROW_LENGTH);
99
- this.sprites.connections = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
100
- attr: {
101
- color: COLOR_LIGHT_GRAY,
102
- },
103
- }, init);
104
- this.sprites.connections.put({
105
- x: 0,
106
- y: 2,
107
- attr: {
108
- color: COLOR_LIGHT_GRAY,
109
- },
110
- }, fillString(' Current:', ROW_LENGTH));
111
- this.sprites.connections.put({
112
- x: 0,
113
- y: 3,
114
- attr: {
115
- color: COLOR_LIGHT_GRAY,
116
- },
117
- }, fillString(' Total:', ROW_LENGTH));
118
- }
119
- createSpriteRequestInfo() {
120
- this.sprites.requestInfo = new termkit_no_lazy_require_1.default.ScreenBuffer({
121
- x: 0,
122
- y: 0,
123
- width: ROW_LENGTH,
124
- height: this.terminal.height,
125
- });
126
- this.sprites.requestInfoScroll = new termkit_no_lazy_require_1.default.ScreenBuffer({
127
- x: 0,
128
- y: REQUEST_INFO_START_Y,
129
- width: REQUEST_INFO_MAX_LENGTH,
130
- height: this.terminal.height,
131
- });
132
- }
133
- createSpriteRequests() {
134
- let header = fillString('', ROW_LENGTH);
135
- header += '\n';
136
- header += fillString('Requests (use arrows ↑↓ to inspect & `enter` to retry)', ROW_LENGTH);
137
- header += '\n';
138
- header += fillString('-------------------------------------------------------------------------------------------------------', ROW_LENGTH);
139
- this.sprites.requestsHeader = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
140
- attr: {
141
- color: COLOR_LIGHT_GRAY,
142
- },
143
- }, header);
144
- this.sprites.requests = new termkit_no_lazy_require_1.default.ScreenBuffer({
145
- x: 10,
146
- y: 0,
147
- width: ROW_LENGTH,
148
- height: REQUESTS_MAX,
149
- });
150
- this.sprites.requestsSelected = new termkit_no_lazy_require_1.default.ScreenBuffer({
151
- x: 0,
152
- y: 0,
153
- width: 10,
154
- height: REQUESTS_MAX,
155
- });
156
- this.sprites.requestsSelectedLast = new termkit_no_lazy_require_1.default.ScreenBuffer({
157
- x: 0,
158
- y: 0,
159
- width: ROW_LENGTH,
160
- height: 1,
161
- });
162
- }
163
- logRequestToText(r) {
164
- let msg = `${r.method} ${r.url}`;
165
- if (msg.length > REQUESTS_MAX_LENGTH)
166
- msg = msg.substring(0, REQUESTS_MAX_LENGTH);
167
- else
168
- msg = fillString(msg, REQUESTS_MAX_LENGTH);
169
- if (r.status === 'NEW') {
170
- msg += ' ^KNEW^';
171
- }
172
- else if (typeof (r.status) === 'number' && r.status >= 500) {
173
- msg += ` ^R${r.status}^`;
174
- }
175
- else if (typeof (r.status) === 'number' && r.status >= 400) {
176
- msg += ` ^Y${r.status}^`;
177
- }
178
- else if (typeof (r.status) === 'number' && r.status >= 300) {
179
- msg += ` ^B${r.status}^`;
180
- }
181
- else {
182
- msg += ` ${r.status}`;
183
- }
184
- if (r.finished)
185
- msg += ` in ^K${r.time}ms`;
186
- return msg;
187
- }
188
- getPathAndQuery(url) {
189
- const query = {};
190
- let path;
191
- try {
192
- const u = new URL(url, 'https://test.com');
193
- path = u.pathname;
194
- u.searchParams.forEach((val, name) => {
195
- query[name] = val;
196
- });
197
- }
198
- catch {
199
- path = url;
200
- }
201
- return {
202
- path,
203
- query,
204
- };
205
- }
206
- updateSpriteRequestScrollable() {
207
- if (this.selectedRequest) {
208
- this.sprites.requestInfoScroll.y = this.sprites.requestInfoScrollY;
209
- this.sprites.requestInfoScroll.fill({
210
- char: ' ',
211
- x: 0,
212
- y: 0,
213
- width: REQUEST_INFO_MAX_LENGTH,
214
- height: this.terminal.height,
215
- });
216
- const { query, path } = this.getPathAndQuery(this.selectedRequest.url);
217
- let msg = '^KStatus:^ ';
218
- msg += `^W${this.selectedRequest.status}^\n`;
219
- msg += '\n^KMethod:^ ';
220
- msg += `^WHTTP ${this.selectedRequest.httpVersion} ${this.selectedRequest.method}^\n`;
221
- msg += '\n^KPath:^ ';
222
- msg += `^W${path}^\n`;
223
- const queryKeys = Object.keys(query);
224
- if (queryKeys.length > 0) {
225
- msg += '\n^WQuery:^\n';
226
- queryKeys.forEach((name) => {
227
- msg += `^K${name}:^ ^W${query[name]}^\n`;
228
- });
229
- }
230
- if (this.selectedRequest.requestBody.realLength > 0) {
231
- msg += '\n^WBody:^\n';
232
- if (this.selectedRequest.requestBody.tooLarge ||
233
- this.selectedRequest.requestBody.realLength >
234
- 20 * REQUEST_INFO_MAX_LENGTH) {
235
- msg += `^K<Too large (${formatBytes(this.selectedRequest.requestBody.realLength)})>^\n`;
236
- }
237
- else {
238
- const isBinary = (0, isbinaryfile_1.isBinaryFileSync)(this.selectedRequest.requestBody.data);
239
- if (isBinary) {
240
- msg += '^K<Binary>^\n';
241
- }
242
- else {
243
- msg += `^K${this.selectedRequest.requestBody.data.toString('utf8')}^\n`;
244
- }
245
- }
246
- }
247
- msg += '\n^WHeaders:^\n';
248
- const headers = this.selectedRequest.headers || {};
249
- Object.keys(headers).forEach((name) => {
250
- msg += `^K${name}:^ ^W${headers[name]}^\n`;
251
- });
252
- if (this.selectedRequest.finished) {
253
- if (this.selectedRequest.responseBody.realLength > 0) {
254
- msg += '\n^WResponse body:^\n';
255
- if (this.selectedRequest.responseBody.tooLarge ||
256
- this.selectedRequest.responseBody.realLength >
257
- 20 * REQUEST_INFO_MAX_LENGTH) {
258
- msg += `^K<Too large (${formatBytes(this.selectedRequest.responseBody.realLength)})>^\n`;
259
- }
260
- else {
261
- const isBinary = (0, isbinaryfile_1.isBinaryFileSync)(this.selectedRequest.responseBody.data);
262
- if (isBinary) {
263
- msg += '^K<Binary>^\n';
264
- }
265
- else {
266
- msg += `^K${this.selectedRequest.responseBody.data.toString('utf8')}^\n`;
267
- }
268
- }
269
- }
270
- msg += '\n^WResponse headers:^\n';
271
- const headers = this.selectedRequest.responseHeaders || {};
272
- Object.keys(headers).forEach((name) => {
273
- msg += `^K${name}:^ ^W${headers[name]}^\n`;
274
- });
275
- }
276
- this.sprites.requestInfoScroll.put({
277
- x: 0,
278
- y: 0,
279
- newLine: true,
280
- markup: true,
281
- wrap: true,
282
- }, msg);
283
- }
284
- }
285
- updateSpriteRequestInfo(y) {
286
- if (this.tunnel.log) {
287
- this.sprites.requestInfo.fill({
288
- char: ' ',
289
- region: {
290
- x: 0,
291
- y: 0,
292
- width: ROW_LENGTH,
293
- height: this.terminal.height,
294
- },
295
- });
296
- if (this.selectedRequest) {
297
- this.sprites.requestInfoScroll.draw({
298
- dst: this.sprites.requestInfo,
299
- });
300
- this.sprites.requestInfo.put({
301
- attr: {
302
- color: COLOR_LIGHT_GRAY,
303
- },
304
- x: 0,
305
- y: 0,
306
- }, fillString('', ROW_LENGTH));
307
- this.sprites.requestInfo.put({
308
- attr: {
309
- color: COLOR_LIGHT_GRAY,
310
- },
311
- x: 0,
312
- y: 1,
313
- }, fillString('Request details (use `space` to scroll)', ROW_LENGTH));
314
- this.sprites.requestInfo.put({
315
- attr: {
316
- color: COLOR_LIGHT_GRAY,
317
- },
318
- x: 0,
319
- y: 2,
320
- }, fillString('-------------------------------------------------------------------------------------------------------', ROW_LENGTH));
321
- }
322
- this.sprites.requestInfo.draw({
323
- dst: this.viewPort,
324
- y,
325
- });
326
- return this.sprites.requestInfo.height;
327
- }
328
- return 0;
329
- }
330
- updateSpriteRequests(y) {
331
- if (this.tunnel.log && this.tunnel.httpLog) {
332
- const requests = this.tunnel.httpLog.requests;
333
- const max = requests.length > REQUESTS_MAX ? REQUESTS_MAX : requests.length;
334
- let col = 0;
335
- let selectedY = -1;
336
- for (let i = 0; i < max; i += 1) {
337
- const r = requests[i];
338
- if (this.selectedRequest === r) {
339
- selectedY = i;
340
- }
341
- this.sprites.requests.put({
342
- markup: true,
343
- x: 0,
344
- y: col,
345
- }, fillString(this.logRequestToText(r), ROW_LENGTH - 10));
346
- col += 1;
347
- }
348
- if (col < REQUESTS_MAX) {
349
- this.sprites.requests.fill({
350
- char: ' ',
351
- region: {
352
- x: 0,
353
- y: col,
354
- width: ROW_LENGTH,
355
- height: REQUESTS_MAX - col,
356
- },
357
- });
358
- }
359
- this.sprites.requestsSelected.fill({
360
- char: ' ',
361
- region: {
362
- x: 0,
363
- y: 0,
364
- width: 10,
365
- height: REQUESTS_MAX,
366
- },
367
- });
368
- this.sprites.requestsSelectedLast.fill({
369
- char: ' ',
370
- region: {
371
- x: 0,
372
- y: 0,
373
- width: ROW_LENGTH,
374
- height: 1,
375
- },
376
- });
377
- if (this.selectedRequest) {
378
- let last;
379
- let seltxt;
380
- let selcol;
381
- if (this.selectedRequest.requestBody.tooLarge) {
382
- last = '^R[ LARGE ]^ ';
383
- seltxt = '[ LARGE ]';
384
- selcol = COLOR_RED;
385
- }
386
- else {
387
- last = '^c[ RETRY ]^ ';
388
- seltxt = '[ RETRY ]';
389
- selcol = COLOR_CYAN;
390
- }
391
- if (selectedY >= 0) {
392
- this.sprites.requestsSelected.put({
393
- attr: {
394
- color: selcol,
395
- },
396
- x: 0,
397
- y: selectedY,
398
- }, fillString(seltxt, 10));
399
- }
400
- else {
401
- last += this.logRequestToText(this.selectedRequest);
402
- this.sprites.requestsSelectedLast.put({
403
- x: 0,
404
- y: 0,
405
- markup: true,
406
- }, fillString(last, ROW_LENGTH));
407
- }
408
- }
409
- this.sprites.requestsHeader.draw({
410
- dst: this.viewPort,
411
- y,
412
- });
413
- let h = this.sprites.requestsHeader.height;
414
- this.sprites.requests.draw({
415
- dst: this.viewPort,
416
- y: y + h,
417
- });
418
- this.sprites.requestsSelected.draw({
419
- dst: this.viewPort,
420
- y: y + h,
421
- });
422
- h += this.sprites.requests.height;
423
- this.sprites.requestsSelectedLast.draw({
424
- dst: this.viewPort,
425
- y: y + h,
426
- });
427
- h += this.sprites.requestsSelectedLast.height;
428
- return h;
429
- }
430
- return 0;
431
- }
432
- moveUpDown(up = true) {
433
- if (this.tunnel.log &&
434
- this.tunnel.httpLog &&
435
- this.tunnel.httpLog.requests.length > 0) {
436
- const r = this.tunnel.httpLog.requests;
437
- const max = r.length > REQUESTS_MAX ? REQUESTS_MAX : r.length;
438
- if (!this.selectedRequest)
439
- this.selectedRequest = !up ? r[0] : r[max - 1];
440
- else {
441
- let idx = -1;
442
- for (let i = 0; i < max; i += 1) {
443
- if (r[i].id === this.selectedRequest.id) {
444
- idx = !up ? i + 1 : i - 1;
445
- break;
446
- }
447
- }
448
- if (r[idx] && idx < max)
449
- this.selectedRequest = r[idx];
450
- else if (up)
451
- this.selectedRequest = r[max - 1];
452
- else
453
- this.selectedRequest = null;
454
- }
455
- this.sprites.requestInfoScrollY = REQUEST_INFO_START_Y;
456
- this.updateSpriteRequestScrollable();
457
- }
458
- }
459
- moveUp() {
460
- this.moveUpDown(true);
461
- }
462
- moveDown() {
463
- this.moveUpDown(false);
464
- }
465
- space() {
466
- if (this.selectedRequest && this.sprites.requestInfoScroll) {
467
- this.sprites.requestInfoScrollY -= 1;
468
- }
469
- }
470
- createSpriteLatency() {
471
- let init = fillString('', ROW_LENGTH);
472
- init += '\n';
473
- init += fillString('Latencies', ROW_LENGTH);
474
- init += '\n';
475
- init += fillString('', ROW_LENGTH);
476
- init += '\n';
477
- init += fillString('', ROW_LENGTH);
478
- this.sprites.latency = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
479
- attr: {
480
- color: COLOR_LIGHT_GRAY,
481
- },
482
- }, init);
483
- this.sprites.latency.put({
484
- x: 0,
485
- y: 2,
486
- attr: {
487
- color: COLOR_LIGHT_GRAY,
488
- },
489
- }, fillString(' Region:', ROW_LENGTH));
490
- this.sprites.latency.put({
491
- x: 0,
492
- y: 3,
493
- attr: {
494
- color: COLOR_LIGHT_GRAY,
495
- },
496
- }, fillString(' Target:', ROW_LENGTH));
497
- }
498
- createSpriteEntry() {
499
- this.sprites.entry = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
500
- attr: {
501
- color: COLOR_LIGHT_GRAY,
502
- },
503
- }, fillString('Entry:', ROW_LENGTH));
504
- }
505
- createSpriteTerminate() {
506
- if (this.tunnel.type === tunnel_1.TUNNEL_TYPE.TLS) {
507
- this.sprites.terminate = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
508
- attr: {
509
- color: COLOR_LIGHT_GRAY,
510
- },
511
- }, fillString('Terminate:', ROW_LENGTH));
512
- }
513
- }
514
- createSpriteTarget() {
515
- this.sprites.target = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
516
- attr: {
517
- color: COLOR_LIGHT_GRAY,
518
- },
519
- }, fillString('', ROW_LENGTH));
520
- }
521
- createSpriteHeader() {
522
- this.sprites.header = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
523
- attr: {
524
- color: COLOR_WHITE,
525
- },
526
- }, `${fillString(`Buddy Tunnel ${(0, utils_1.getVersion)()}`, ROW_LENGTH)}\n${fillString('', ROW_LENGTH)}`);
527
- }
528
- createSpriteStatus() {
529
- this.sprites.status = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
530
- attr: {
531
- color: COLOR_LIGHT_GRAY,
532
- },
533
- }, fillString('Status:', ROW_LENGTH));
534
- }
535
- createSpriteType() {
536
- this.sprites.type = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
537
- attr: {
538
- color: COLOR_LIGHT_GRAY,
539
- },
540
- }, fillString('Type:', ROW_LENGTH));
541
- }
542
- createSpriteDns() {
543
- this.sprites.dns = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
544
- attr: {
545
- color: COLOR_LIGHT_GRAY,
546
- },
547
- }, fillString('DNS:', ROW_LENGTH));
548
- }
549
- createSpriteRegion() {
550
- this.sprites.region = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
551
- attr: {
552
- color: COLOR_LIGHT_GRAY,
553
- },
554
- }, fillString('Region:', ROW_LENGTH));
555
- }
556
- createSpriteIdentify() {
557
- this.sprites.identify = termkit_no_lazy_require_1.default.ScreenBuffer.createFromString({
558
- attr: {
559
- color: COLOR_LIGHT_GRAY,
560
- },
561
- }, fillString('HTTP:', ROW_LENGTH));
562
- }
563
- updateSpriteDns(y) {
564
- let text;
565
- let color;
566
- const { checking, valid } = this.tunnel.dns;
567
- if (valid) {
568
- text = 'OK';
569
- color = COLOR_GREEN;
570
- }
571
- else if (checking) {
572
- text = 'Checking...';
573
- color = COLOR_WHITE;
574
- }
575
- else {
576
- text = 'Wrong. Clear DNS local cache';
577
- color = COLOR_RED;
578
- }
579
- this.sprites.dns.put({
580
- x: COLUMN_LENGTH,
581
- y: 0,
582
- attr: {
583
- color,
584
- },
585
- }, fillString(text, ROW_LENGTH - COLUMN_LENGTH));
586
- this.sprites.dns.draw({
587
- dst: this.viewPort,
588
- y,
589
- });
590
- return this.sprites.dns.height;
591
- }
592
- updateSpriteHeader(y) {
593
- this.sprites.header.draw({
594
- dst: this.viewPort,
595
- y,
596
- });
597
- return this.sprites.header.height;
598
- }
599
- updateSpriteStatus(y) {
600
- let text;
601
- let color;
602
- if (this.tunnel.status === tunnel_1.TUNNEL_STATUS.OPEN) {
603
- text = 'OPEN ';
604
- color = COLOR_GREEN;
605
- }
606
- else {
607
- text = 'CLOSED';
608
- color = COLOR_RED;
609
- }
610
- this.sprites.status.put({
611
- x: COLUMN_LENGTH,
612
- y: 0,
613
- attr: {
614
- color,
615
- },
616
- }, fillString(text, ROW_LENGTH - COLUMN_LENGTH));
617
- this.sprites.status.draw({
618
- dst: this.viewPort,
619
- y,
620
- });
621
- return this.sprites.status.height;
622
- }
623
- updateSpriteType(y) {
624
- this.sprites.type.put({
625
- x: COLUMN_LENGTH,
626
- y: 0,
627
- attr: {
628
- color: COLOR_WHITE,
629
- },
630
- }, fillString(format_1.default.type(this.tunnel.type), ROW_LENGTH - COLUMN_LENGTH));
631
- this.sprites.type.draw({
632
- dst: this.viewPort,
633
- y,
634
- });
635
- return this.sprites.type.height;
636
- }
637
- updateSpriteIdentify(y) {
638
- if (this.tunnel.type === tunnel_1.TUNNEL_TYPE.HTTP) {
639
- this.sprites.identify.put({
640
- x: COLUMN_LENGTH,
641
- y: 0,
642
- attr: {
643
- color: COLOR_WHITE,
644
- },
645
- }, fillString(format_1.default.identify(this.tunnel.identify?.type), ROW_LENGTH - COLUMN_LENGTH));
646
- this.sprites.identify.draw({
647
- dst: this.viewPort,
648
- y,
649
- });
650
- return this.sprites.identify.height;
651
- }
652
- return 0;
653
- }
654
- updateSpriteTarget(y) {
655
- let titleText;
656
- let valueText;
657
- if (this.tunnel.serve) {
658
- titleText = 'Serve:';
659
- valueText = format_1.default.serve(this.tunnel.serve);
660
- }
661
- else {
662
- titleText = 'Target:';
663
- valueText = format_1.default.target(this.tunnel.type, this.tunnel.target);
664
- }
665
- this.sprites.target.put({
666
- x: 0,
667
- y: 0,
668
- attr: {
669
- color: COLOR_LIGHT_GRAY,
670
- },
671
- }, fillString(titleText, ROW_LENGTH));
672
- this.sprites.target.put({
673
- x: COLUMN_LENGTH,
674
- y: 0,
675
- attr: {
676
- color: COLOR_WHITE,
677
- },
678
- }, fillString(valueText, ROW_LENGTH - COLUMN_LENGTH));
679
- this.sprites.target.draw({
680
- dst: this.viewPort,
681
- y,
682
- });
683
- return this.sprites.target.height;
684
- }
685
- updateSpriteRegion(y) {
686
- this.sprites.region.put({
687
- x: COLUMN_LENGTH,
688
- y: 0,
689
- attr: {
690
- color: COLOR_WHITE,
691
- },
692
- }, fillString(format_1.default.region(this.tunnel.region), ROW_LENGTH - COLUMN_LENGTH));
693
- this.sprites.region.draw({
694
- dst: this.viewPort,
695
- y,
696
- });
697
- return this.sprites.region.height;
698
- }
699
- updateSpriteTerminate(y) {
700
- if (this.tunnel.type === tunnel_1.TUNNEL_TYPE.TLS) {
701
- this.sprites.terminate.put({
702
- x: COLUMN_LENGTH,
703
- y: 0,
704
- attr: {
705
- color: COLOR_WHITE,
706
- },
707
- }, fillString(format_1.default.terminate(this.tunnel.terminate), ROW_LENGTH - COLUMN_LENGTH));
708
- this.sprites.terminate.draw({
709
- dst: this.viewPort,
710
- y,
711
- });
712
- return this.sprites.terminate.height;
713
- }
714
- return 0;
715
- }
716
- updateSpriteEntry(y) {
717
- this.sprites.entry.put({
718
- x: COLUMN_LENGTH,
719
- y: 0,
720
- attr: {
721
- color: COLOR_CYAN,
722
- bold: true,
723
- },
724
- }, fillString(format_1.default.entry(this.tunnel), ROW_LENGTH - COLUMN_LENGTH));
725
- this.sprites.entry.draw({
726
- dst: this.viewPort,
727
- y,
728
- });
729
- return this.sprites.entry.height;
730
- }
731
- updateSpriteConnections(y) {
732
- const count = Object.keys(this.tunnel.connections).length;
733
- this.sprites.connections.put({
734
- x: COLUMN_LENGTH,
735
- y: 2,
736
- attr: {
737
- color: COLOR_WHITE,
738
- },
739
- }, fillString(String(count), ROW_LENGTH - COLUMN_LENGTH));
740
- this.sprites.connections.put({
741
- x: COLUMN_LENGTH,
742
- y: 3,
743
- attr: {
744
- color: COLOR_WHITE,
745
- },
746
- }, fillString(String(this.tunnel.totalConnections), ROW_LENGTH - COLUMN_LENGTH));
747
- this.sprites.connections.draw({
748
- dst: this.viewPort,
749
- y,
750
- });
751
- return this.sprites.connections.height;
752
- }
753
- updateSpriteLatency(y) {
754
- let regionLatency = -1;
755
- let targetLatency = -1;
756
- if (this.tunnel.regionLatency)
757
- regionLatency = this.tunnel.regionLatency.latency;
758
- if (this.tunnel.serve)
759
- targetLatency = 0;
760
- else if (this.tunnel.targetLatency)
761
- targetLatency = this.tunnel.targetLatency.latency;
762
- let region;
763
- let regionColor;
764
- let target;
765
- let targetColor;
766
- if (regionLatency < 0) {
767
- region = 'Unreachable';
768
- regionColor = COLOR_RED;
769
- }
770
- else {
771
- region = format_1.default.latency(regionLatency);
772
- regionColor = COLOR_WHITE;
773
- }
774
- if (targetLatency < 0) {
775
- target = 'Unreachable';
776
- targetColor = COLOR_RED;
777
- }
778
- else {
779
- target = format_1.default.latency(targetLatency);
780
- targetColor = COLOR_WHITE;
781
- }
782
- this.sprites.latency.put({
783
- x: COLUMN_LENGTH,
784
- y: 2,
785
- attr: {
786
- color: regionColor,
787
- },
788
- }, fillString(region, ROW_LENGTH - COLUMN_LENGTH));
789
- this.sprites.latency.put({
790
- x: COLUMN_LENGTH,
791
- y: 3,
792
- attr: {
793
- color: targetColor,
794
- },
795
- }, fillString(target, ROW_LENGTH - COLUMN_LENGTH));
796
- this.sprites.latency.draw({
797
- dst: this.viewPort,
798
- y,
799
- });
800
- return this.sprites.latency.height;
801
- }
802
- init() {
803
- this.viewPort = new termkit_no_lazy_require_1.default.ScreenBuffer({
804
- dst: this.terminal,
805
- width: Math.min(this.terminal.width),
806
- height: Math.min(this.terminal.height),
807
- x: 1,
808
- y: 1,
809
- });
810
- this.createSpriteHeader();
811
- this.createSpriteStatus();
812
- this.createSpriteType();
813
- this.createSpriteDns();
814
- this.createSpriteRegion();
815
- this.createSpriteTarget();
816
- this.createSpriteIdentify();
817
- this.createSpriteTerminate();
818
- this.createSpriteEntry();
819
- this.createSpriteLatency();
820
- this.createSpriteConnections();
821
- this.createSpriteRequests();
822
- this.createSpriteRequestInfo();
823
- this.terminal.grabInput();
824
- this.terminal.hideCursor();
825
- this.terminal.fullscreen(true);
826
- this.terminal.on('key', (name) => {
827
- if (name === 'CTRL_C') {
828
- this.terminate();
829
- }
830
- else if (name === 'ENTER') {
831
- this.retry();
832
- }
833
- else if (name === 'DOWN') {
834
- this.moveDown();
835
- }
836
- else if (name === 'UP') {
837
- this.moveUp();
838
- }
839
- else if (name === ' ') {
840
- this.space();
841
- }
842
- });
843
- this.terminal.on('resize', () => {
844
- this.draw();
845
- });
846
- this.tunnel.on(tunnel_1.TUNNEL_EVENT.STOPPED, () => {
847
- this.terminate();
848
- });
849
- }
850
- terminate() {
851
- this.terminal.fullscreen(false);
852
- this.terminal.hideCursor(false);
853
- this.terminal.grabInput(false);
854
- process.exit();
855
- }
856
- animate() {
857
- this.draw();
858
- setTimeout(() => {
859
- this.animate();
860
- }, 50);
861
- }
862
- start() {
863
- this.init();
864
- this.animate();
865
- }
866
- }
867
- exports.default = OutputInteractiveTunnel;