safely-serve 0.0.2 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/eslint.config.mjs CHANGED
@@ -1,38 +1,74 @@
1
-
2
1
  // SPDX-License-Identifier: GPL-3.0-or-later
3
2
 
4
- // ----------------------------------------------------------------------
5
- // Copyright © 2024, 2025
6
- // Jiang Jie
7
- // Copyright © 2025
8
- // Pellegrino Prevete
9
- //
10
- // All rights reserved
11
- // ----------------------------------------------------------------------
12
- //
13
- // This program is free software: you can redistribute it and/or modify
14
- // it under the terms of the GNU General Public License as published by
15
- // the Free Software Foundation, either version 3 of the License, or
16
- // (at your option) any later version.
17
- //
18
- // This program is distributed in the hope that it will be useful,
19
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- // GNU General Public License for more details.
22
- //
23
- // You should have received a copy of the GNU General Public License
24
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
3
+ /** ----------------------------------------------------------------------
4
+ * Copyright ©
5
+ * Pellegrino Prevete
6
+ * 2024, 2025, 2026
7
+ *
8
+ * All rights reserved
9
+ * ----------------------------------------------------------------------
10
+ *
11
+ * This program is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation, either version 3 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * This program is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
23
+ */
24
+
25
25
 
26
+ import js from "@eslint/js";
27
+ import globals from "globals";
26
28
  import { defineConfig } from "eslint/config";
27
29
 
30
+ const
31
+ _project =
32
+ "safely-serve";
33
+
28
34
  export default defineConfig([
29
- { ignores: [
30
- "build/**",
31
- "eslint.config.js"
32
- ],
33
- rules:
34
- { semi:
35
- "error",
36
- "prefer-const":
37
- "error" } },
35
+ { ignores: [
36
+ "build/**",
37
+ "eslint.config.js",
38
+ "man/**"
39
+ ],
40
+ rules:
41
+ { semi:
42
+ "error",
43
+ "prefer-const":
44
+ "error" },
45
+ files:
46
+ [ "**/*js,mjs,cjs}",
47
+ `**/${_project}*`,
48
+ `**/lib${_project}` ],
49
+ plugins:
50
+ { js },
51
+ extends:
52
+ [ "js/recommended" ],
53
+ languageOptions:
54
+ { globals:
55
+ { ...globals.browser,
56
+ ...globals.node} } },
57
+ { ignores: [
58
+ "build/**",
59
+ "eslint.config.js",
60
+ "man/**"
61
+ ],
62
+ rules:
63
+ { semi:
64
+ "error",
65
+ "prefer-const":
66
+ "error" },
67
+ files:
68
+ [ "**/*.js",
69
+ `**/${_project}*`,
70
+ `**/lib${_project}` ],
71
+ languageOptions:
72
+ { sourceType:
73
+ "commonjs" } },
38
74
  ]);
package/fs-worker.js CHANGED
@@ -1 +1 @@
1
- (()=>{var e={314:(e,o,n)=>{const t=n(816);_sync_agent=t.startSyncAgent,e.exports={_sync_agent},_sync_agent()},816:(e,o,n)=>{function t(){let e;return"undefined"==typeof window&&void 0!==n.g&&n.g.global===n.g&&"function"!=typeof n||(e=function(){let e;try{e=n(816)}catch(e){console.log(e);const o="Error importing the '@themartiancompany/opfs' module as 'opfs'. If you got this error while bundling a webpack for a project depending on this module double check its 'webpack.config.js' file or whether the 'opfs' module is listed in developer dependencies and install them.I'm sorry for this inconvenience but Node packagement system does not currently distinguish 'development' from 'build' dependencies.";throw console.error(o),e}return e}()),e}const r=t();e.exports=r,e.exports.getModule=function(e){let o;if(""==_module_name||"undefined"==typeof _module_name)o=t();else if("opfs"==_module_name)o=n(816);else{if("fs"!=_module_name){const e="Unknown file system module "+`'${_module_name}'.`.const;throw _error={msg:e},console.error(e),_error}o=n(816)}return o}}},o={};function n(t){var r=o[t];if(void 0!==r)return r.exports;var s=o[t]={exports:{}};return e[t](s,s.exports,n),s.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(314)})();
1
+ (()=>{var e={816(e,o,n){function t(){let e;return"undefined"==typeof window&&void 0!==n.g&&n.g.global===n.g&&"function"!=typeof n||(e=function(){let e;try{e=n(816)}catch(e){console.log(e);const o="Error importing the '@themartiancompany/opfs' module as 'opfs'. If you got this error while bundling a webpack for a project depending on this module double check its 'webpack.config.js' file or whether the 'opfs' module is listed in developer dependencies and install them.I'm sorry for this inconvenience but Node packagement system does not currently distinguish 'development' from 'build' dependencies.";throw console.error(o),e}return e}()),e}const r=t();e.exports=r,e.exports.getModule=function(e){let o;if(""==_module_name||"undefined"==typeof _module_name)o=t();else if("opfs"==_module_name)o=n(816);else{if("fs"!=_module_name){const e="Unknown file system module "+`'${_module_name}'.`.const;throw _error={msg:e},console.error(e),_error}o=n(816)}return o}},314(e,o,n){const t=n(816);_sync_agent=t.startSyncAgent,e.exports={_sync_agent},_sync_agent()}},o={};function n(t){var r=o[t];if(void 0!==r)return r.exports;var s=o[t]={exports:{}};return e[t](s,s.exports,n),s.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(314)})();
package/libsafely-serve CHANGED
@@ -21,44 +21,297 @@
21
21
  // You should have received a copy of the GNU Affero General Public License
22
22
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
23
23
 
24
+ /* eslint
25
+ no-unused-vars: [
26
+ "error",
27
+ { "vars":
28
+ "local",
29
+ "argsIgnorePattern":
30
+ "_output" } ] */
31
+ /* eslint
32
+ no-unassigned-vars:
33
+ "off" */
34
+
24
35
  const
25
- _serve_module =
36
+ { spawn } =
26
37
  require(
27
- 'serve');
38
+ "node:child_process");
39
+ /* global
40
+ _spawn */
41
+ const
42
+ _spawn =
43
+ spawn;
28
44
  const
29
45
  _cert_tools_module =
30
46
  require(
31
47
  'cert-tools');
48
+ /* global
49
+ _cert_gen */
50
+ const
51
+ _cert_gen =
52
+ _cert_tools_module._cert_gen;
53
+ const
54
+ _sha_module =
55
+ require(
56
+ 'js-sha256');
57
+ /* global
58
+ _sha256 */
59
+ const
60
+ _sha256 =
61
+ _sha_module.sha256;
32
62
  const
33
63
  _libcrash =
34
64
  require(
35
65
  'crash-js');
36
- _error_display =
37
- _libcrash._error_display;
38
- _ext_rm =
39
- _libcrash._ext_rm;
40
- _file_exists =
41
- _libcrash._file_exists;
42
- _file_read =
43
- _libcrash._file_read;
44
- _file_write =
45
- _libcrash._file_write;
46
- _fs_worker_start =
47
- _libcrash._fs_worker_start;
48
- _json_read =
49
- _libcrash._json_read;
50
- _ls =
51
- _libcrash._ls;
52
- _mkdir =
53
- _libcrash._mkdir;
54
- _msg_info =
55
- _libcrash._msg_info;
56
- _msg_error =
57
- _libcrash._msg_error;
66
+ /* global
67
+ _dirname */
68
+ const
69
+ _dirname =
70
+ _libcrash._dirname;
71
+ /* global
72
+ _file_exists */
73
+ const
74
+ _file_exists =
75
+ _libcrash._file_exists;
76
+ /* global
77
+ _mkdir */
78
+ const
79
+ _mkdir =
80
+ _libcrash._mkdir;
81
+ /* global
82
+ _msg_info */
83
+ const
84
+ _msg_info =
85
+ _libcrash._msg_info;
86
+
87
+ function
88
+ _path_encode(
89
+ _path) {
90
+ const
91
+ _string =
92
+ _sha256(
93
+ _path + "\n");
94
+ return _string;
95
+ }
96
+
97
+ function
98
+ _serve_close_callback_get(
99
+ _output) {
100
+ const
101
+ _close_callback =
102
+ function(
103
+ _code) {
104
+ let
105
+ _msg;
106
+ _msg =
107
+ `Exit code: ${_code}`;
108
+ console.log(
109
+ _msg);
110
+ _msg =
111
+ `Output: ${_output}`;
112
+ console.log(
113
+ _msg);
114
+ };
115
+ return _close_callback;
116
+ }
117
+
118
+ function
119
+ _serve_data_callback_get(
120
+ _output) {
121
+ const
122
+ _data_callback =
123
+ function(
124
+ _data) {
125
+ _data =
126
+ _data.toString();
127
+ console.log(
128
+ _data);
129
+ /* global
130
+ _output */
131
+ _output +=
132
+ _data;
133
+ };
134
+ return _data_callback;
135
+ }
136
+
137
+ function
138
+ _npx_cmdline_get(
139
+ _target_directory,
140
+ _listen_uris,
141
+ _target_port,
142
+ _index_redirect,
143
+ _debug_enabled,
144
+ _config_file,
145
+ _logging_disabled,
146
+ _cors_enabled,
147
+ _clipboard_disabled,
148
+ _compression_disabled,
149
+ _etag_disabled,
150
+ _symlinks_enabled,
151
+ _ssl_cert,
152
+ _ssl_key,
153
+ _ssl_pass,
154
+ _port_switching_disabled) {
155
+ let
156
+ _uri;
157
+ const
158
+ _cmd_args = [
159
+ "serve"
160
+ ];
161
+ for ( _uri of _listen_uris ) {
162
+ _cmd_args.push(
163
+ "-l",
164
+ _uri);
165
+ }
166
+ _cmd_args.push(
167
+ "-p",
168
+ _target_port);
169
+ if ( _index_redirect == "y" ) {
170
+ _cmd_args.push(
171
+ "--single");
172
+ }
173
+ if ( _debug_enabled != "n" ) {
174
+ _cmd_args.push(
175
+ "--debug");
176
+ }
177
+ if ( _config_file != "" ) {
178
+ _cmd_args.push(
179
+ "--config",
180
+ _config_file);
181
+ }
182
+ if ( _logging_disabled == "y" ) {
183
+ _cmd_args.push(
184
+ "--no-request-logging");
185
+ }
186
+ if ( _cors_enabled == "y" ) {
187
+ _cmd_args.push(
188
+ "--cors");
189
+ }
190
+ if ( _clipboard_disabled == "y" ) {
191
+ _cmd_args.push(
192
+ "--no-clipboard");
193
+ }
194
+ if ( _compression_disabled == "y" ) {
195
+ _cmd_args.push(
196
+ "--no-compression");
197
+ }
198
+ if ( _etag_disabled == "y" ) {
199
+ _cmd_args.push(
200
+ "--no-etag");
201
+ }
202
+ if ( _symlinks_enabled == "y" ) {
203
+ _cmd_args.push(
204
+ "--symlinks");
205
+ }
206
+ if ( _port_switching_disabled == "y" ) {
207
+ _cmd_args.push(
208
+ "--no-port-switching");
209
+ }
210
+ if ( _ssl_cert != "" ) {
211
+ /* global
212
+ ssl_cert */
213
+ _cmd_args.push(
214
+ "--ssl-cert",
215
+ ssl_cert);
216
+ }
217
+ if ( _ssl_key != "" ) {
218
+ /* global
219
+ ssl_key */
220
+ _cmd_args.push(
221
+ "--ssl-key",
222
+ ssl_key);
223
+ }
224
+ if ( _ssl_pass != "" ) {
225
+ /* global
226
+ ssl_pass */
227
+ _cmd_args.push(
228
+ "--ssl-pass",
229
+ ssl_pass);
230
+ }
231
+ }
232
+
233
+ function
234
+ _serve(
235
+ _target_directory,
236
+ _listen_uris,
237
+ _target_port,
238
+ _index_redirect,
239
+ _debug_enabled,
240
+ _config_file,
241
+ _logging_disabled,
242
+ _cors_enabled,
243
+ _clipboard_disabled,
244
+ _compression_disabled,
245
+ _etag_disabled,
246
+ _symlinks_enabled,
247
+ _ssl_cert,
248
+ _ssl_key,
249
+ _ssl_pass,
250
+ _port_switching_disabled) {
251
+ let
252
+ _output;
253
+ const
254
+ _cmd =
255
+ "npx";
256
+ const
257
+ _cmd_args =
258
+ _npx_cmdline_get(
259
+ _target_directory,
260
+ _listen_uris,
261
+ _target_port,
262
+ _index_redirect,
263
+ _debug_enabled,
264
+ _config_file,
265
+ _logging_disabled,
266
+ _cors_enabled,
267
+ _clipboard_disabled,
268
+ _compression_disabled,
269
+ _etag_disabled,
270
+ _symlinks_enabled,
271
+ _ssl_cert,
272
+ _ssl_key,
273
+ _ssl_pass,
274
+ _port_switching_disabled);
275
+ const
276
+ _serve_process =
277
+ _spawn(
278
+ _cmd,
279
+ _cmd_args);
280
+ const
281
+ _serve_data_callback =
282
+ _serve_data_callback_get(
283
+ _output);
284
+ _serve_process.stdout.on(
285
+ 'data',
286
+ _serve_data_callback);
287
+ const
288
+ _serve_close_callback =
289
+ _serve_close_callback_get(
290
+ _output);
291
+ _serve_process.stdout.on(
292
+ 'close',
293
+ _serve_close_callback);
294
+ }
58
295
 
59
296
  async function
60
297
  _safely_serve(
61
- _key_private_path,
298
+ _target_directory,
299
+ _listen_uris,
300
+ _target_port,
301
+ _index_redirect,
302
+ _debug_enabled,
303
+ _config_file,
304
+ _logging_disabled,
305
+ _cors_enabled,
306
+ _clipboard_disabled,
307
+ _compression_disabled,
308
+ _etag_disabled,
309
+ _symlinks_enabled,
310
+ _cert_new,
311
+ _ssl_cert,
312
+ _ssl_key,
313
+ _ssl_pass,
314
+ _port_switching_disabled,
62
315
  _keys_length,
63
316
  _serial_number,
64
317
  _validity_min,
@@ -68,65 +321,84 @@ async function
68
321
  _state_name,
69
322
  _locality_name,
70
323
  _organization_name,
71
- _organization_unit,
72
- _output_file) {
324
+ _organization_unit) {
73
325
  let
74
- _alt_names,
75
- _attrs,
76
- _basic_constraints,
77
- _cert,
78
- _ext_key_usage,
79
- _key_usage,
80
- _key_pem,
81
- _key_private,
82
- _keys,
83
- _keys_pem,
84
- _ns_cert_type,
85
- _pem,
86
- _subject_alt_name,
87
- _subject_key_identifier;
88
- _keys_length =
89
- Number(
90
- _keys_length);
91
- if ( _key_private_path == "" ||
92
- ! _file_exists(
93
- _key_private_path) ) {
94
- _keys =
95
- _rsa.generateKeyPair(
96
- _keys_length);
97
- _key_pem =
98
- _pki.privateKeyToPem(
99
- _keys.privateKey);
100
- _file_write(
101
- _key_private_path,
102
- _key_pem);
103
- _key_private =
104
- _keys.privateKey;
105
- }
106
- else {
107
- _key_pem =
108
- _file_read(
109
- _key_private_path);
110
- _key_private =
111
- _pki.privateKeyFromPem(
112
- _key_pem);
113
- _keys =
114
- { privateKey:
115
- _key_private };
116
- }
117
- if ( _log_file != "" ) {
118
- if ( typeof window !== 'undefined') {
119
- await _fs_worker_start(
120
- "fs-worker.js");
121
- }
122
- _file_write(
123
- _log_file,
124
- _whatever_log);
326
+ _cert_gen_opts_str,
327
+ _msg;
328
+ if ( ! _file_exists(
329
+ _ssl_cert) &&
330
+ _cert_new == "y" ) {
331
+ const
332
+ _mkdir_opts =
333
+ { "recursive":
334
+ true,
335
+ "mode":
336
+ "0700" };
337
+ const
338
+ _mkdir_args = [
339
+ _dirname(
340
+ _ssl_cert),
341
+ _mkdir_opts
342
+ ];
343
+ _mkdir.apply(
344
+ null,
345
+ _mkdir_args);
346
+ const
347
+ _cert_gen_opts = [
348
+ _ssl_key,
349
+ _keys_length,
350
+ _serial_number,
351
+ _validity_min,
352
+ _validity_max,
353
+ _domain_name,
354
+ _country_name,
355
+ _state_name,
356
+ _locality_name,
357
+ _organization_name,
358
+ _organization_unit,
359
+ _ssl_cert
360
+ ];
361
+ _cert_gen_opts_str =
362
+ " ".join(
363
+ _cert_gen_opts);
364
+ _msg =
365
+ `Running 'cert-gen' ` +
366
+ `options '${_cert_gen_opts_str}'.`;
367
+ _msg_info(
368
+ _msg);
369
+ await _cert_gen.apply(
370
+ null,
371
+ _cert_gen_opts);
125
372
  }
126
- return true;
373
+ const
374
+ _serve_opts = [
375
+ _target_directory,
376
+ _listen_uris,
377
+ _target_port,
378
+ _index_redirect,
379
+ _debug_enabled,
380
+ _config_file,
381
+ _logging_disabled,
382
+ _cors_enabled,
383
+ _clipboard_disabled,
384
+ _compression_disabled,
385
+ _etag_disabled,
386
+ _symlinks_enabled,
387
+ _ssl_cert,
388
+ _ssl_key,
389
+ _ssl_pass,
390
+ _port_switching_disabled
391
+ ];
392
+ _serve.apply(
393
+ null,
394
+ _serve_opts);
127
395
  }
128
396
 
129
397
  module.exports = {
398
+ _path_encode:
399
+ _path_encode,
130
400
  _safely_serve:
131
- _safely_serve
401
+ _safely_serve,
402
+ _serve:
403
+ _serve
132
404
  };
@@ -15,6 +15,10 @@ const
15
15
  const
16
16
  _output_file_name =
17
17
  `${_input_file_name}.js`;
18
+ const
19
+ _child_process_ignore =
20
+ { resourceRegExp:
21
+ /^node:child_process$/ };
18
22
  const
19
23
  _serve_ignore =
20
24
  { resourceRegExp:
@@ -35,6 +39,10 @@ const
35
39
  const
36
40
  _ignore_plugin =
37
41
  _webpack.IgnorePlugin;
42
+ const
43
+ _child_process_ignore_plugin =
44
+ new _ignore_plugin(
45
+ _child_process_ignore);
38
46
  const
39
47
  _serve_ignore_plugin =
40
48
  new _ignore_plugin(
@@ -72,8 +80,14 @@ module.exports = {
72
80
  _path.resolve(
73
81
  __dirname,
74
82
  'node_modules/path/mod.js'),
83
+ "serve":
84
+ _path.resolve(
85
+ __dirname,
86
+ 'node_modules/serve/build/main.js'),
75
87
  },
76
88
  fallback: {
89
+ "node:child_process":
90
+ false,
77
91
  "serve":
78
92
  false,
79
93
  "utils":
@@ -90,6 +104,7 @@ module.exports = {
90
104
  { yargs:
91
105
  'yargs' },
92
106
  plugins: [
107
+ _child_process_ignore_plugin,
93
108
  _serve_ignore_plugin,
94
109
  _yargs_ignore_plugin,
95
110
  _yargs_helpers_ignore_plugin