spec-3nweb-server 1.7.11 → 1.7.13

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.
@@ -6,4 +6,5 @@ export declare function parseProcessArgv(): {
6
6
  runCmd?: ParsedRunArgs;
7
7
  signupCmd?: ParsedSignupArgs;
8
8
  showUsage?: CliUsageDisplay;
9
+ showSampleConfig?: CliUsageDisplay;
9
10
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2023 3NSoft Inc.
3
+ Copyright (C) 2023, 2025 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -17,8 +17,9 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.parseProcessArgv = void 0;
20
- const path_1 = require("path");
20
+ const default_confs_1 = require("../default-confs");
21
21
  const run_cmd_1 = require("./run-cmd");
22
+ const show_sample_config_1 = require("./show-sample-config");
22
23
  const signup_cmd_1 = require("./signup-cmd");
23
24
  const utils_1 = require("./utils");
24
25
  function mainUsage(execName) {
@@ -35,7 +36,8 @@ function mainUsage(execName) {
35
36
  header: 'Available commands:',
36
37
  content: [
37
38
  run_cmd_1.runCmd,
38
- signup_cmd_1.signupCmd
39
+ signup_cmd_1.signupCmd,
40
+ show_sample_config_1.showSampleConfigCmd
39
41
  ]
40
42
  },
41
43
  {
@@ -46,22 +48,26 @@ function mainUsage(execName) {
46
48
  }
47
49
  function parseProcessArgv() {
48
50
  const args = process.argv.slice(2);
49
- const execName = (0, path_1.basename)(process.argv0);
50
51
  if (args.length === 0) {
51
- return (0, utils_1.toUsageDisplay)(0, mainUsage(execName));
52
+ return (0, utils_1.toUsageDisplay)(0, mainUsage(default_confs_1.EXECUTABLE_NAME));
52
53
  }
53
54
  if (args[0] === run_cmd_1.runCmd.name) {
54
- return (0, run_cmd_1.parseRunArgs)(args.slice(1), execName);
55
+ return (0, run_cmd_1.parseRunArgs)(args.slice(1), default_confs_1.EXECUTABLE_NAME);
55
56
  }
56
57
  else if (args[0] === signup_cmd_1.signupCmd.name) {
57
- return (0, signup_cmd_1.parseSignupArgs)(args.slice(1), execName);
58
+ return (0, signup_cmd_1.parseSignupArgs)(args.slice(1), default_confs_1.EXECUTABLE_NAME);
59
+ }
60
+ else if (args[0] === show_sample_config_1.showSampleConfigCmd.name) {
61
+ return { showSampleConfig: {
62
+ txtToDisplay: show_sample_config_1.sampleConfig, exitStatus: 0
63
+ } };
58
64
  }
59
65
  else {
60
66
  const opts = (0, utils_1.parseArgv)(args, [utils_1.helpOpt], { partial: true });
61
67
  if (opts.help) {
62
- return (0, utils_1.toUsageDisplay)(0, mainUsage(execName));
68
+ return (0, utils_1.toUsageDisplay)(0, mainUsage(default_confs_1.EXECUTABLE_NAME));
63
69
  }
64
- return (0, utils_1.toUsageDisplay)(-1, (0, utils_1.toErrorUsage)(mainUsage(execName), `Unknown command '${args[0]}'`));
70
+ return (0, utils_1.toUsageDisplay)(-1, (0, utils_1.toErrorUsage)(mainUsage(default_confs_1.EXECUTABLE_NAME), `Unknown command '${args[0]}'`));
65
71
  }
66
72
  }
67
73
  exports.parseProcessArgv = parseProcessArgv;
@@ -0,0 +1,3 @@
1
+ import { CommandDef } from "./utils";
2
+ export declare const showSampleConfigCmd: CommandDef<'show-sample-config'>;
3
+ export declare const sampleConfig = "\n# This is a sample configuration yaml file.\n# Uncomment and set required values.\n# Default path of this file is /etc/3nweb/conf.yaml\n\n# Uncomment to enable service\nenabledServices:\n # asmail: true\n # storage: true\n # mailerId: true\n\n# Data root folder. Set non-default value, if required.\n# rootFolder: /var/3nweb\n\n# Customize domain at which clients reach this server from an outside.\n# This value is used by users' MailerId-based login: assertion challenges\n# cryptographically imprint this domain to assure client that there is no\n# missuse.\ndomain: service-for.example.com\n\n# If MailerId provider service is enabled, this is its configuration\nmailerId:\n certs: /etc/3nweb/mailerid/certs\n\n# Customize servicesConnect before starting this server.\nservicesConnect:\n\n port: 7070\n # Hostname allows to restrict on which address service is listening for incoming connections\n # hostname: \"1.2.3.4\"\n\n # Uncomment path to Let's Encrypt folder, if it is used. This implicitly tells\n # server to HTTPS with given certificates.\n # letsencrypt: /etc/letsencrypt/live/service-for.example.com\n\n # By default HTTPS service reloads when certificates change. Skip, if required.\n # skipReloadOnCertsChange: false\n\n # Set TLS cert and key to do HTTPS. Use either this, or letsencrypt, but not both.\n # sslOpts: {\n # It is Node's https.ServerOptions. Follow https://nodejs.org/docs/latest/api/https.html\n # }\n\n# Configuration for signup service that creates new accounts on this server.\n# Comment out to disable signup service completely.\n# Note that signup cli commands should be used to create token, without which\n# signup doesn't happen, unless a no-token configuration file is provided.\nsignup: {\n # noTokenFile: /some/path/to/json\n}\n";
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2025 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along with
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.sampleConfig = exports.showSampleConfigCmd = void 0;
20
+ exports.showSampleConfigCmd = {
21
+ name: 'show-sample-config',
22
+ summary: 'prints out a template configuration yaml file with comments'
23
+ };
24
+ exports.sampleConfig = `
25
+ # This is a sample configuration yaml file.
26
+ # Uncomment and set required values.
27
+ # Default path of this file is /etc/3nweb/conf.yaml
28
+
29
+ # Uncomment to enable service
30
+ enabledServices:
31
+ # asmail: true
32
+ # storage: true
33
+ # mailerId: true
34
+
35
+ # Data root folder. Set non-default value, if required.
36
+ # rootFolder: /var/3nweb
37
+
38
+ # Customize domain at which clients reach this server from an outside.
39
+ # This value is used by users' MailerId-based login: assertion challenges
40
+ # cryptographically imprint this domain to assure client that there is no
41
+ # missuse.
42
+ domain: service-for.example.com
43
+
44
+ # If MailerId provider service is enabled, this is its configuration
45
+ mailerId:
46
+ certs: /etc/3nweb/mailerid/certs
47
+
48
+ # Customize servicesConnect before starting this server.
49
+ servicesConnect:
50
+
51
+ port: 7070
52
+ # Hostname allows to restrict on which address service is listening for incoming connections
53
+ # hostname: "1.2.3.4"
54
+
55
+ # Uncomment path to Let's Encrypt folder, if it is used. This implicitly tells
56
+ # server to HTTPS with given certificates.
57
+ # letsencrypt: /etc/letsencrypt/live/service-for.example.com
58
+
59
+ # By default HTTPS service reloads when certificates change. Skip, if required.
60
+ # skipReloadOnCertsChange: false
61
+
62
+ # Set TLS cert and key to do HTTPS. Use either this, or letsencrypt, but not both.
63
+ # sslOpts: {
64
+ # It is Node's https.ServerOptions. Follow https://nodejs.org/docs/latest/api/https.html
65
+ # }
66
+
67
+ # Configuration for signup service that creates new accounts on this server.
68
+ # Comment out to disable signup service completely.
69
+ # Note that signup cli commands should be used to create token, without which
70
+ # signup doesn't happen, unless a no-token configuration file is provided.
71
+ signup: {
72
+ # noTokenFile: /some/path/to/json
73
+ }
74
+ `;
75
+ Object.freeze(exports);
@@ -0,0 +1,3 @@
1
+ export declare const EXECUTABLE_NAME = "3nweb";
2
+ export declare const DEFAULT_DATA_ROOT_PATH = "/var/3nweb";
3
+ export declare const DEFAULT_CONFIG_PATH = "/etc/3nweb/conf.yaml";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2025 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along with
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.DEFAULT_CONFIG_PATH = exports.DEFAULT_DATA_ROOT_PATH = exports.EXECUTABLE_NAME = void 0;
20
+ exports.EXECUTABLE_NAME = '3nweb';
21
+ exports.DEFAULT_DATA_ROOT_PATH = '/var/3nweb';
22
+ exports.DEFAULT_CONFIG_PATH = `/etc/3nweb/conf.yaml`;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2023 3NSoft Inc.
3
+ Copyright (C) 2023, 2025 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -19,9 +19,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.readYamlConfFile = void 0;
20
20
  const fs_1 = require("fs");
21
21
  const yaml = require("js-yaml");
22
+ const default_confs_1 = require("./default-confs");
22
23
  function readYamlConfFile(path) {
23
24
  const txt = (0, fs_1.readFileSync)(path, 'utf8');
24
25
  const conf = yaml.load(txt);
26
+ if (conf.rootFolder) {
27
+ conf.rootFolder = default_confs_1.DEFAULT_DATA_ROOT_PATH;
28
+ }
25
29
  return conf;
26
30
  }
27
31
  exports.readYamlConfFile = readYamlConfFile;
package/build/main.d.ts CHANGED
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export {};
package/build/main.js CHANGED
@@ -1,6 +1,7 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  /*
3
- Copyright (C) 2015 - 2016, 2019 3NSoft Inc.
4
+ Copyright (C) 2015 - 2016, 2019, 2025 3NSoft Inc.
4
5
 
5
6
  This program is free software: you can redistribute it and/or modify it under
6
7
  the terms of the GNU General Public License as published by the Free Software
@@ -21,9 +22,11 @@ const from_yaml_1 = require("./config/from-yaml");
21
22
  const letsencrypt_1 = require("./config/letsencrypt");
22
23
  const lib_1 = require("./lib");
23
24
  const signup_1 = require("./config/signup");
25
+ const default_confs_1 = require("./config/default-confs");
26
+ const file_1 = require("./lib-common/exceptions/file");
24
27
  async function run(conf) {
25
28
  if (!conf.servicesConnect) {
26
- console.error(`No connection settings found in ??.`);
29
+ console.error(`❌ No connection settings found in configuration.`);
27
30
  process.exit(-1);
28
31
  return;
29
32
  }
@@ -39,7 +42,7 @@ async function run(conf) {
39
42
  return;
40
43
  }
41
44
  try {
42
- console.log(`Stopping app ...`);
45
+ console.log(`🏁 Stopping app ...`);
43
46
  await app.stop();
44
47
  console.log(`app has stopped.`);
45
48
  }
@@ -53,11 +56,11 @@ async function run(conf) {
53
56
  }
54
57
  async function startAppWithTLS(sslOpts, port, hostname) {
55
58
  await app.start(sslOpts, port, hostname);
56
- console.log(`Started 3NWeb server on port ${port},${hostname ? ` hostname ${hostname},` : ''} with TLS.`);
59
+ console.log(`🚀 Started 3NWeb server on port ${port},${hostname ? ` hostname ${hostname},` : ''} with TLS.`);
57
60
  }
58
61
  async function startAppWithoutTLS(port, hostname) {
59
62
  await app.start(undefined, port, hostname);
60
- console.log(`Started 3NWeb server on port ${port},${hostname ? ` hostname ${hostname},` : ''} without TLS, and requiring TLS reverse proxy infront.`);
63
+ console.log(`🚀 Started 3NWeb server on port ${port},${hostname ? ` hostname ${hostname},` : ''} without TLS, and requiring TLS reverse proxy infront.`);
61
64
  }
62
65
  try {
63
66
  app = createApp(conf);
@@ -67,7 +70,7 @@ async function run(conf) {
67
70
  await startAppWithTLS(tls.sslOpts, port, hostname);
68
71
  if (!skipReloadOnCertsChange) {
69
72
  tls.onCertsUpdate(async (newOpts, originalOpts) => {
70
- console.log(`Reloading server app server on TLS certificates change`);
73
+ console.log(`🗘 Reloading server app server on TLS certificates change`);
71
74
  try {
72
75
  await stopProcess();
73
76
  app = createApp(conf);
@@ -75,7 +78,7 @@ async function run(conf) {
75
78
  }
76
79
  catch (err) {
77
80
  console.error(err);
78
- console.log(`Failed to reload with new TLS certs. Attempting to load with original ones.`);
81
+ console.log(`⚠️ Failed to reload with new TLS certs. Attempting to load with original ones.`);
79
82
  try {
80
83
  await stopProcess();
81
84
  app = createApp(conf);
@@ -112,11 +115,19 @@ function showUsage({ txtToDisplay, exitStatus }) {
112
115
  process.exit(exitStatus);
113
116
  }
114
117
  function assembleConfig(configPath) {
115
- if (configPath) {
118
+ if (!configPath) {
119
+ configPath = default_confs_1.DEFAULT_CONFIG_PATH;
120
+ console.log(`Looking for configuration in default location: ${configPath}`);
121
+ }
122
+ try {
116
123
  return (0, from_yaml_1.readYamlConfFile)(configPath);
117
124
  }
118
- else {
119
- throw new Error(`Config path must be given`);
125
+ catch (err) {
126
+ if (err.code === file_1.Code.notFound) {
127
+ console.error(`❌ Configuration file ${configPath} is not found.`);
128
+ process.exit(-2);
129
+ }
130
+ throw err;
120
131
  }
121
132
  }
122
133
  async function displaySignupInfo(conf) {
@@ -222,12 +233,21 @@ else if (cmd.signupCmd) {
222
233
  }
223
234
  }
224
235
  else {
225
- throw new Error(`CLI parser failed to capture invalid command`);
236
+ showUsage({
237
+ txtToDisplay: `❌ No recognized subcommand given to signup module`,
238
+ exitStatus: -1
239
+ });
226
240
  }
227
241
  }
242
+ else if (cmd.showSampleConfig) {
243
+ showUsage(cmd.showSampleConfig);
244
+ }
228
245
  else if (cmd.showUsage) {
229
246
  showUsage(cmd.showUsage);
230
247
  }
231
248
  else {
232
- throw new Error(`CLI parser failed to trigger useful action`);
249
+ showUsage({
250
+ txtToDisplay: `❌ No recognized command given`,
251
+ exitStatus: -1
252
+ });
233
253
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "spec-3nweb-server",
3
- "version": "1.7.11",
3
+ "version": "1.7.13",
4
4
  "description": "3NWeb spec server.",
5
5
  "main": "build/lib.js",
6
6
  "types": "build/lib.d.ts",
7
7
  "bin": {
8
- "3nweb": "node build/main.js"
8
+ "3nweb": "build/main.js"
9
9
  },
10
10
  "scripts": {
11
11
  "build": "tsc -p ts-code",