bdy 1.8.3-dev → 1.8.5-dev

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 (113) hide show
  1. package/distTs/bin/cli.js +5 -0
  2. package/distTs/package.json +70 -0
  3. package/distTs/src/agent/linux.js +119 -0
  4. package/distTs/src/agent/manager.js +395 -0
  5. package/distTs/src/agent/osx.js +139 -0
  6. package/distTs/src/agent/socket/tunnel.js +212 -0
  7. package/distTs/src/agent/socket.js +220 -0
  8. package/distTs/src/agent/system.js +177 -0
  9. package/distTs/src/agent/wait.js +23 -0
  10. package/distTs/src/agent/windows.js +159 -0
  11. package/distTs/src/agent.js +237 -0
  12. package/distTs/src/api/agent.js +84 -0
  13. package/distTs/src/api/buddy.js +117 -0
  14. package/distTs/src/api/socket.js +133 -0
  15. package/distTs/src/cfg.js +238 -0
  16. package/distTs/src/command/agent/install.js +106 -0
  17. package/distTs/src/command/agent/restart.js +27 -0
  18. package/distTs/src/command/agent/run.js +19 -0
  19. package/distTs/src/command/agent/start.js +28 -0
  20. package/distTs/src/command/agent/status.js +35 -0
  21. package/distTs/src/command/agent/stop.js +28 -0
  22. package/distTs/src/command/agent/tunnel/http.js +44 -0
  23. package/distTs/src/command/agent/tunnel/list.js +27 -0
  24. package/distTs/src/command/agent/tunnel/remove.js +28 -0
  25. package/distTs/src/command/agent/tunnel/start.js +34 -0
  26. package/distTs/src/command/agent/tunnel/status.js +31 -0
  27. package/distTs/src/command/agent/tunnel/tcp.js +43 -0
  28. package/distTs/src/command/agent/tunnel/tls.js +43 -0
  29. package/distTs/src/command/agent/tunnel.js +23 -0
  30. package/distTs/src/command/agent/uninstall.js +38 -0
  31. package/distTs/src/command/agent/update.js +38 -0
  32. package/distTs/src/command/agent/version.js +21 -0
  33. package/distTs/src/command/agent.js +29 -0
  34. package/distTs/src/command/config/add/http.js +25 -0
  35. package/distTs/src/command/config/add/tcp.js +25 -0
  36. package/distTs/src/command/config/add/tls.js +25 -0
  37. package/distTs/src/command/config/add.js +15 -0
  38. package/distTs/src/command/config/get/region.js +15 -0
  39. package/distTs/src/command/config/get/timeout.js +15 -0
  40. package/distTs/src/command/config/get/token.js +15 -0
  41. package/distTs/src/command/config/get/tunnel.js +19 -0
  42. package/distTs/src/command/config/get/tunnels.js +15 -0
  43. package/distTs/src/command/config/get/whitelist.js +15 -0
  44. package/distTs/src/command/config/get.js +21 -0
  45. package/distTs/src/command/config/remove/tunnel.js +19 -0
  46. package/distTs/src/command/config/remove.js +11 -0
  47. package/distTs/src/command/config/set/region.js +17 -0
  48. package/distTs/src/command/config/set/timeout.js +17 -0
  49. package/distTs/src/command/config/set/token.js +16 -0
  50. package/distTs/src/command/config/set/whitelist.js +17 -0
  51. package/distTs/src/command/config/set.js +17 -0
  52. package/distTs/src/command/config.js +17 -0
  53. package/distTs/src/command/http.js +30 -0
  54. package/distTs/src/command/pre.js +49 -0
  55. package/distTs/src/command/start.js +28 -0
  56. package/distTs/src/command/tcp.js +30 -0
  57. package/distTs/src/command/tls.js +30 -0
  58. package/distTs/src/command/version.js +13 -0
  59. package/distTs/src/command/vt/close.js +28 -0
  60. package/distTs/src/command/vt/exec.js +79 -0
  61. package/distTs/src/command/vt/storybook.js +90 -0
  62. package/distTs/src/command/vt.js +15 -0
  63. package/distTs/src/format.js +172 -0
  64. package/distTs/src/index.js +40 -0
  65. package/distTs/src/input.js +286 -0
  66. package/distTs/src/logger.js +93 -0
  67. package/distTs/src/output/interactive/tunnel.js +860 -0
  68. package/distTs/src/output/noninteractive/agent/tunnels.js +43 -0
  69. package/distTs/src/output/noninteractive/config/tunnel.js +67 -0
  70. package/distTs/src/output/noninteractive/config/tunnels.js +18 -0
  71. package/distTs/src/output/noninteractive/tunnel.js +59 -0
  72. package/distTs/src/output.js +138 -0
  73. package/distTs/src/server/cert.js +52 -0
  74. package/distTs/src/server/http1.js +74 -0
  75. package/distTs/src/server/http2.js +74 -0
  76. package/distTs/src/server/sftp.js +487 -0
  77. package/distTs/src/server/ssh.js +112 -0
  78. package/distTs/src/server/tls.js +41 -0
  79. package/distTs/src/ssh/client.js +191 -0
  80. package/distTs/src/texts.js +344 -0
  81. package/distTs/src/tunnel/agent.js +100 -0
  82. package/distTs/src/tunnel/compression.js +41 -0
  83. package/distTs/src/tunnel/dns.js +54 -0
  84. package/distTs/src/tunnel/html.js +30 -0
  85. package/distTs/src/tunnel/http/log.js +196 -0
  86. package/distTs/src/tunnel/http/serve.js +132 -0
  87. package/distTs/src/tunnel/http/stream.js +45 -0
  88. package/distTs/src/tunnel/http.js +405 -0
  89. package/distTs/src/tunnel/identification.js +96 -0
  90. package/distTs/src/tunnel/latency.js +71 -0
  91. package/distTs/src/tunnel/tcp.js +92 -0
  92. package/distTs/src/tunnel.js +647 -0
  93. package/distTs/src/types/ciInfo.js +10 -0
  94. package/distTs/src/types/options.js +2 -0
  95. package/distTs/src/types/plugin.js +2 -0
  96. package/distTs/src/types/queue.js +2 -0
  97. package/distTs/src/types/requests.js +2 -0
  98. package/distTs/src/types/resources.js +2 -0
  99. package/distTs/src/types/snapshots.js +2 -0
  100. package/distTs/src/types/storybook.js +2 -0
  101. package/distTs/src/utils.js +437 -0
  102. package/distTs/src/visualTest/browser.js +32 -0
  103. package/distTs/src/visualTest/ci.js +206 -0
  104. package/distTs/src/visualTest/context.js +44 -0
  105. package/distTs/src/visualTest/exec.js +51 -0
  106. package/distTs/src/visualTest/queue.js +43 -0
  107. package/distTs/src/visualTest/requests.js +197 -0
  108. package/distTs/src/visualTest/resources.js +195 -0
  109. package/distTs/src/visualTest/server.js +33 -0
  110. package/distTs/src/visualTest/snapshots.js +109 -0
  111. package/distTs/src/visualTest/utils/parseDom.js +238 -0
  112. package/distTs/src/visualTest/validation.js +18 -0
  113. package/package.json +1 -1
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("./utils");
4
+ class Format {
5
+ static date() {
6
+ const dt = new Date();
7
+ return dt.toISOString();
8
+ }
9
+ static token(token) {
10
+ if (!token || token.length < 6)
11
+ return 'Not provided';
12
+ return token.substring(0, 3) + '...' + token.substring(token.length - 3);
13
+ }
14
+ static region(region) {
15
+ if (!region)
16
+ return 'Autodetect';
17
+ return region.toUpperCase();
18
+ }
19
+ static timeout(timeout) {
20
+ if (timeout === 1)
21
+ return '1 second';
22
+ return `${timeout} seconds`;
23
+ }
24
+ static tunnelTimeout(timeout) {
25
+ if (!timeout)
26
+ return 'Default';
27
+ return this.timeout(timeout);
28
+ }
29
+ static whitelist(whitelist) {
30
+ if (!whitelist || !whitelist.length)
31
+ return 'Everyone';
32
+ if (whitelist.includes('*'))
33
+ return 'Everyone';
34
+ return whitelist.join('\n');
35
+ }
36
+ static tunnelWhitelist(whitelist) {
37
+ if (!whitelist)
38
+ return 'Default';
39
+ return this.whitelist(whitelist);
40
+ }
41
+ static tunnelHeaders(headers) {
42
+ if (!headers || !headers.length)
43
+ return 'Not set';
44
+ return headers.map((h) => `${h.name}: ${h.value}`).join('\n');
45
+ }
46
+ static tunnelCircuitBreaker(cb) {
47
+ if (cb === undefined || cb === null)
48
+ return 'Not set';
49
+ return String(cb);
50
+ }
51
+ static tunnelUserAgent(userAgents) {
52
+ if (!userAgents || !userAgents.length)
53
+ return 'Everyone';
54
+ return userAgents.join('\n');
55
+ }
56
+ static tunnelDomain(domain) {
57
+ if (!domain)
58
+ return 'Default';
59
+ return domain;
60
+ }
61
+ static type(type) {
62
+ return type.toUpperCase();
63
+ }
64
+ static tunnelRegion(region) {
65
+ if (!region)
66
+ return 'Default';
67
+ return this.region(region);
68
+ }
69
+ static identify(identifyType) {
70
+ if (identifyType === utils_1.TUNNEL_IDENTIFIED_HTTP1)
71
+ return 'Ver. 1.1';
72
+ return 'Ver. 2';
73
+ }
74
+ static terminate(terminate) {
75
+ if (terminate === utils_1.TLS_TERMINATE_AT_AGENT)
76
+ return 'AGENT';
77
+ if (terminate === utils_1.TLS_TERMINATE_AT_REGION)
78
+ return 'REGION';
79
+ return 'TARGET';
80
+ }
81
+ static serve(serve) {
82
+ return serve;
83
+ }
84
+ static hostHeader(host) {
85
+ if (!host)
86
+ return 'Not set';
87
+ return host;
88
+ }
89
+ static basicAuth(login, pass) {
90
+ if (!login || !pass)
91
+ return 'Not set';
92
+ return `${login}:${pass}`;
93
+ }
94
+ static latency(latency) {
95
+ if (latency < 0)
96
+ return 'Unreachable';
97
+ if (latency < 1000)
98
+ return `${latency.toFixed(0)}ms`;
99
+ return `${(latency / 1000).toFixed(0)}s`;
100
+ }
101
+ static yesNo(val) {
102
+ if (!val)
103
+ return 'No';
104
+ return 'Yes';
105
+ }
106
+ static entryHost(tunnel) {
107
+ let host = '';
108
+ host += tunnel.subdomain;
109
+ host += '.';
110
+ // todo custom domain
111
+ host += tunnel.region.toLowerCase();
112
+ host += '-';
113
+ host += tunnel.sshId;
114
+ host += '.';
115
+ host += tunnel.domain;
116
+ return host;
117
+ }
118
+ static entry(tunnel) {
119
+ let entry = '';
120
+ if (tunnel.type === utils_1.TUNNEL_HTTP)
121
+ entry += 'https://';
122
+ entry += this.entryHost(tunnel);
123
+ if (tunnel.type === utils_1.TUNNEL_TCP)
124
+ entry += `:${tunnel.sshForwardPort}`;
125
+ else if (tunnel.type === utils_1.TUNNEL_TLS)
126
+ entry += ':443';
127
+ return entry;
128
+ }
129
+ static target(type, target) {
130
+ if (type === utils_1.TUNNEL_HTTP) {
131
+ let port = '80';
132
+ let host = 'localhost';
133
+ let proto = 'http';
134
+ let m = target.match(utils_1.TARGET_ONLY_PORT_REGEX);
135
+ if (m) {
136
+ port = m[0];
137
+ }
138
+ else {
139
+ m = target.match(utils_1.TARGET_HTTP_REGEX);
140
+ if (m) {
141
+ if (m[2])
142
+ proto = m[2];
143
+ if (m[4])
144
+ host = m[4];
145
+ if (m[6])
146
+ port = m[6];
147
+ else if (proto === 'https')
148
+ port = '443';
149
+ }
150
+ }
151
+ let t = `${proto}://${host}`;
152
+ if (proto === 'http' && port !== '80')
153
+ t += `:${port}`;
154
+ else if (proto === 'https' && port !== '443')
155
+ t += `:${port}`;
156
+ return t;
157
+ }
158
+ else {
159
+ let host = 'localhost';
160
+ let port = '80';
161
+ const m = target.match(utils_1.TARGET_TCP_TLS_REGEX);
162
+ if (m) {
163
+ if (m[3])
164
+ port = m[3];
165
+ if (m[2])
166
+ host = m[2];
167
+ }
168
+ return `${host}:${port}`;
169
+ }
170
+ }
171
+ }
172
+ exports.default = Format;
@@ -0,0 +1,40 @@
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 config_js_1 = __importDefault(require("./command/config.js"));
7
+ const output_js_1 = __importDefault(require("./output.js"));
8
+ const tcp_js_1 = __importDefault(require("./command/tcp.js"));
9
+ const tls_js_1 = __importDefault(require("./command/tls.js"));
10
+ const http_js_1 = __importDefault(require("./command/http.js"));
11
+ const start_js_1 = __importDefault(require("./command/start.js"));
12
+ const agent_js_1 = __importDefault(require("./command/agent.js"));
13
+ const logger_js_1 = __importDefault(require("./logger.js"));
14
+ const version_js_1 = __importDefault(require("./command/version.js"));
15
+ const pre_js_1 = __importDefault(require("./command/pre.js"));
16
+ const stream_1 = __importDefault(require("stream"));
17
+ const utils_1 = require("./utils");
18
+ const texts_1 = require("./texts");
19
+ const vt_1 = __importDefault(require("./command/vt"));
20
+ stream_1.default.setDefaultHighWaterMark(false, 67108864);
21
+ process.title = 'bdy';
22
+ process.on('uncaughtException', (err) => {
23
+ logger_js_1.default.fatal(err);
24
+ output_js_1.default.exitError(err);
25
+ });
26
+ const program = (0, utils_1.newCommand)(null, texts_1.DESC_PROGRAM);
27
+ program.hook('preAction', pre_js_1.default);
28
+ program.configureHelp({
29
+ formatHelp: utils_1.formatHelp,
30
+ });
31
+ program.addCommand(config_js_1.default);
32
+ program.addCommand(tcp_js_1.default);
33
+ program.addCommand(tls_js_1.default);
34
+ program.addCommand(http_js_1.default);
35
+ program.addCommand(start_js_1.default);
36
+ if (!(0, utils_1.isDocker)())
37
+ program.addCommand(agent_js_1.default);
38
+ program.addCommand(version_js_1.default);
39
+ program.addCommand(vt_1.default);
40
+ program.parse();
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const output_js_1 = __importDefault(require("./output.js"));
30
+ const netmask_1 = __importDefault(require("netmask"));
31
+ const fs_1 = __importStar(require("fs"));
32
+ const tls_1 = __importDefault(require("tls"));
33
+ const crypto_1 = __importDefault(require("crypto"));
34
+ const utils_js_1 = require("./utils.js");
35
+ const texts_js_1 = require("./texts.js");
36
+ class Input {
37
+ static timeout(timeout) {
38
+ const t = parseInt(timeout, 10);
39
+ if (isNaN(t) || t <= 0 || t > 999) {
40
+ output_js_1.default.exitError((0, texts_js_1.ERR_TIMEOUT_IS_NOT_VALID)(timeout));
41
+ }
42
+ return t;
43
+ }
44
+ static serve(serve) {
45
+ if (!serve)
46
+ return serve;
47
+ try {
48
+ const info = (0, fs_1.statSync)(serve);
49
+ if (!info.isDirectory()) {
50
+ output_js_1.default.exitError((0, texts_js_1.ERR_PATH_IS_NOT_DIRECTORY)(serve));
51
+ }
52
+ }
53
+ catch {
54
+ output_js_1.default.exitError((0, texts_js_1.ERR_DIRECTORY_DOES_NOT_EXISTS)(serve));
55
+ }
56
+ return serve;
57
+ }
58
+ static circuitBreaker(threshold) {
59
+ if (threshold === undefined)
60
+ return null;
61
+ const n = parseFloat(threshold);
62
+ if (isNaN(n) || n < 0 || n > 1) {
63
+ output_js_1.default.exitError((0, texts_js_1.ERR_CB_THRESHOLD_IS_NOT_VALID)(n));
64
+ }
65
+ return n;
66
+ }
67
+ static headers(headers) {
68
+ const r = [];
69
+ (headers || []).forEach((h) => {
70
+ if (!h)
71
+ return;
72
+ const s = h.split(':');
73
+ if (s.length !== 2)
74
+ return;
75
+ r.push({
76
+ name: s[0],
77
+ value: s[1],
78
+ });
79
+ });
80
+ return r;
81
+ }
82
+ static subdomain(subdomain) {
83
+ if (!/^[a-z0-9-]+$/i.test(subdomain)) {
84
+ output_js_1.default.exitError((0, texts_js_1.ERR_SUBDOMAIN_IS_NOT_VALID)(subdomain));
85
+ }
86
+ if (subdomain.length < 5) {
87
+ output_js_1.default.exitError((0, texts_js_1.ERR_SUBDOMAIN_IS_TOO_SHORT)(subdomain));
88
+ }
89
+ if (subdomain.length > 63) {
90
+ output_js_1.default.exitError((0, texts_js_1.ERR_SUBDOMAIN_IS_TOO_LONG)(subdomain));
91
+ }
92
+ return subdomain;
93
+ }
94
+ static domain(domain) {
95
+ if (!/^(?:[A-z0-9](?:[A-z0-9-]{0,61}[A-z0-9])?\.)+[A-z0-9][A-z0-9-]{0,61}[A-z0-9]$/i.test(domain)) {
96
+ output_js_1.default.exitError((0, texts_js_1.ERR_DOMAIN_IS_NOT_VALID)(domain));
97
+ }
98
+ return domain;
99
+ }
100
+ static auth(auth) {
101
+ const s = auth.split(':');
102
+ if (s.length !== 2) {
103
+ output_js_1.default.exitError((0, texts_js_1.ERR_BA_IS_NOT_VALID)(auth));
104
+ }
105
+ if (!s[0]) {
106
+ output_js_1.default.exitError(texts_js_1.ERR_BA_LOGIN_NOT_PROVIDED);
107
+ }
108
+ if (!s[1]) {
109
+ output_js_1.default.exitError(texts_js_1.ERR_BA_PASSWORD_NOT_PROVIDED);
110
+ }
111
+ return {
112
+ login: s[0],
113
+ password: s[1],
114
+ };
115
+ }
116
+ static useragents(useragents) {
117
+ if (!useragents || !useragents.length)
118
+ return [];
119
+ useragents.forEach((ua) => {
120
+ if ((0, utils_js_1.isStringRegExp)(ua)) {
121
+ try {
122
+ new RegExp(ua);
123
+ }
124
+ catch {
125
+ output_js_1.default.exitError((0, texts_js_1.ERR_USER_AGENT_IS_NOT_VALID)(ua));
126
+ }
127
+ }
128
+ });
129
+ return useragents;
130
+ }
131
+ static whitelist(whitelist) {
132
+ if (!whitelist || !whitelist.length)
133
+ return [];
134
+ for (let i = 0; i < whitelist.length; i += 1) {
135
+ const wh = whitelist[i];
136
+ if (wh === '*')
137
+ return ['*'];
138
+ try {
139
+ new netmask_1.default.Netmask(wh);
140
+ }
141
+ catch {
142
+ output_js_1.default.exitError((0, texts_js_1.ERR_WHITELIST_IS_NOT_VALID)(wh));
143
+ }
144
+ }
145
+ return whitelist;
146
+ }
147
+ static region(region) {
148
+ if (!region)
149
+ output_js_1.default.exitError((0, texts_js_1.ERR_REGION_IS_NOT_VALID)(''));
150
+ region = region.toUpperCase();
151
+ if (![utils_js_1.REGION_EU, utils_js_1.REGION_US].includes(region)) {
152
+ output_js_1.default.exitError((0, texts_js_1.ERR_REGION_IS_NOT_VALID)(region));
153
+ }
154
+ return region;
155
+ }
156
+ static terminate(terminate) {
157
+ if (!terminate)
158
+ return utils_js_1.TLS_TERMINATE_AT_REGION;
159
+ terminate = terminate.toUpperCase();
160
+ if (![
161
+ utils_js_1.TLS_TERMINATE_AT_AGENT,
162
+ utils_js_1.TLS_TERMINATE_AT_REGION,
163
+ utils_js_1.TLS_TERMINATE_AT_TARGET,
164
+ ].includes(terminate)) {
165
+ output_js_1.default.exitError((0, texts_js_1.ERR_TERMINATE_IS_NOT_VALID)(terminate));
166
+ }
167
+ return terminate;
168
+ }
169
+ static target(target, type) {
170
+ if (!target)
171
+ return '80';
172
+ if (target.length > 200) {
173
+ output_js_1.default.exitError((0, texts_js_1.ERR_TARGET_IS_NOT_VALID)(target));
174
+ }
175
+ target = target.toLowerCase();
176
+ // 80
177
+ // localhost
178
+ // localhost:80
179
+ // http://localhost:80
180
+ // http://localhost
181
+ // http://user:pass@localhost
182
+ // http://user:pass@localhost:80
183
+ let port;
184
+ if ([utils_js_1.TUNNEL_TCP, utils_js_1.TUNNEL_TLS].includes(type)) {
185
+ const m = target.match(utils_js_1.TARGET_TCP_TLS_REGEX);
186
+ if (!m) {
187
+ output_js_1.default.exitError((0, texts_js_1.ERR_TARGET_IS_NOT_VALID)(target));
188
+ }
189
+ port = m[3];
190
+ }
191
+ else {
192
+ let m = target.match(utils_js_1.TARGET_ONLY_PORT_REGEX);
193
+ if (m) {
194
+ port = m[0];
195
+ }
196
+ else {
197
+ m = target.match(utils_js_1.TARGET_HTTP_REGEX);
198
+ if (!m) {
199
+ output_js_1.default.exitError((0, texts_js_1.ERR_TARGET_IS_NOT_VALID)(target));
200
+ }
201
+ else {
202
+ let proto;
203
+ if (m[2])
204
+ proto = m[2];
205
+ else
206
+ proto = 'http';
207
+ if (m[6])
208
+ port = m[6];
209
+ else if (proto === 'https')
210
+ port = '443';
211
+ else
212
+ port = '80';
213
+ }
214
+ }
215
+ }
216
+ Input.port(port);
217
+ return target;
218
+ }
219
+ static port(port) {
220
+ const p = parseInt(port, 10);
221
+ if (isNaN(p) || p <= 0 || p > 65535)
222
+ output_js_1.default.exitError((0, texts_js_1.ERR_PORT_IS_NOT_VALID)(port));
223
+ return p;
224
+ }
225
+ static type(type) {
226
+ if (!type)
227
+ return utils_js_1.TUNNEL_TCP;
228
+ type = type.toUpperCase();
229
+ if (![utils_js_1.TUNNEL_TCP, utils_js_1.TUNNEL_TLS, utils_js_1.TUNNEL_HTTP].includes(type)) {
230
+ output_js_1.default.exitError((0, texts_js_1.ERR_TYPE_IS_NOT_VALID)(type));
231
+ }
232
+ return type;
233
+ }
234
+ static name(name) {
235
+ if (name.includes('*')) {
236
+ output_js_1.default.exitError(texts_js_1.ERR_NAME_WITHOUT_ASTERISK);
237
+ }
238
+ return name;
239
+ }
240
+ static ca(caPath) {
241
+ let cert;
242
+ try {
243
+ cert = fs_1.default.readFileSync(caPath, 'utf8');
244
+ }
245
+ catch {
246
+ output_js_1.default.exitError((0, texts_js_1.ERR_CA_PATH_IS_NOT_VALID)(caPath));
247
+ }
248
+ try {
249
+ new crypto_1.default.X509Certificate(cert);
250
+ }
251
+ catch {
252
+ output_js_1.default.exitError((0, texts_js_1.ERR_WRONG_CA)(caPath));
253
+ }
254
+ return cert;
255
+ }
256
+ static keyCert(keyPath, certPath) {
257
+ let key;
258
+ let cert;
259
+ try {
260
+ key = fs_1.default.readFileSync(keyPath, 'utf8');
261
+ }
262
+ catch {
263
+ output_js_1.default.exitError((0, texts_js_1.ERR_KEY_PATH_IS_NOT_VALID)(keyPath));
264
+ }
265
+ try {
266
+ cert = fs_1.default.readFileSync(certPath, 'utf8');
267
+ }
268
+ catch {
269
+ output_js_1.default.exitError((0, texts_js_1.ERR_CERT_PATH_IS_NOT_VALID)(certPath));
270
+ }
271
+ try {
272
+ tls_1.default.createSecureContext({
273
+ cert,
274
+ key,
275
+ });
276
+ }
277
+ catch {
278
+ output_js_1.default.exitError(texts_js_1.ERR_WRONG_KEY_CERT);
279
+ }
280
+ return {
281
+ cert,
282
+ key,
283
+ };
284
+ }
285
+ }
286
+ exports.default = Input;
@@ -0,0 +1,93 @@
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 pino_1 = __importDefault(require("pino"));
7
+ const path_1 = require("path");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const utils_js_1 = require("./utils.js");
10
+ class Logger {
11
+ rootPath = null;
12
+ logPath = null;
13
+ log1Path = null;
14
+ logStream = null;
15
+ p = null;
16
+ ts = null;
17
+ constructor() {
18
+ this.rootPath = (0, utils_js_1.getHomeDirectory)();
19
+ }
20
+ checkLogSize() {
21
+ try {
22
+ const s = fs_1.default.statSync(this.logPath);
23
+ if (s.size > 5242880) {
24
+ fs_1.default.copyFileSync(this.logPath, this.log1Path);
25
+ fs_1.default.truncateSync(this.logPath);
26
+ }
27
+ }
28
+ catch {
29
+ // do nothing
30
+ }
31
+ }
32
+ getPino() {
33
+ if (!this.p) {
34
+ this.logPath = (0, path_1.resolve)(this.rootPath, 'cli.log');
35
+ this.log1Path = (0, path_1.resolve)(this.rootPath, 'cli.1.log');
36
+ this.logStream = fs_1.default.openSync(this.logPath, 'w');
37
+ try {
38
+ fs_1.default.chmodSync(this.logPath, 0o666);
39
+ }
40
+ catch {
41
+ // do nothing
42
+ }
43
+ this.p = (0, pino_1.default)({
44
+ level: process.env.DEBUG === '1' ? 'debug' : 'info',
45
+ timestamp: () => `, "time": "${new Date().toISOString()}"`,
46
+ formatters: {
47
+ bindings: () => ({}),
48
+ level: (label) => ({
49
+ level: label.toUpperCase(),
50
+ }),
51
+ },
52
+ }, pino_1.default.destination(this.logStream));
53
+ this.checkLogSize();
54
+ this.ts = setInterval(() => {
55
+ this.checkLogSize();
56
+ }, 30000);
57
+ }
58
+ return this.p;
59
+ }
60
+ error(...args) {
61
+ this.getPino().error(...args);
62
+ }
63
+ info(...args) {
64
+ this.getPino().info(...args);
65
+ }
66
+ debug(...args) {
67
+ this.getPino().debug(...args);
68
+ }
69
+ fatal(...args) {
70
+ this.getPino().fatal(...args);
71
+ }
72
+ stack() {
73
+ this.getPino().info(new Error().stack);
74
+ }
75
+ changeRootPath(path) {
76
+ if (this.ts) {
77
+ clearInterval(this.ts);
78
+ this.ts = null;
79
+ }
80
+ if (this.logStream) {
81
+ try {
82
+ this.logStream.close();
83
+ }
84
+ catch {
85
+ // do nothing
86
+ }
87
+ this.logStream = null;
88
+ }
89
+ this.p = null;
90
+ this.rootPath = path;
91
+ }
92
+ }
93
+ exports.default = new Logger();