bdy 1.12.10-dev-pipeline-run → 1.12.10-stage

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