spec-3nweb-server 1.6.3 → 1.6.4

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.
@@ -1,3 +1,4 @@
1
1
  import { MidAuthorizer } from '../lib-server/routes/sessions/mid-auth';
2
+ import { ErrLogger } from '../lib-server/middleware/error-handler';
2
3
  import { AppWithWSs } from '../lib-server/web-sockets/app';
3
- export declare function makeApp(dataFolder: string, domain: string, midAuthorizer: MidAuthorizer): AppWithWSs;
4
+ export declare function makeApp(dataFolder: string, domain: string, midAuthorizer: MidAuthorizer, errLogger?: ErrLogger): AppWithWSs;
@@ -42,7 +42,7 @@ function setupStaticEntryRoute(app) {
42
42
  res.status(200).json(json);
43
43
  });
44
44
  }
45
- function makeApp(dataFolder, domain, midAuthorizer) {
45
+ function makeApp(dataFolder, domain, midAuthorizer, errLogger) {
46
46
  const app = new app_1.AppWithWSs();
47
47
  const ownersSessions = (0, sessions_1.makeSessionFactory)(20 * 60);
48
48
  const sharingSessions = (0, sessions_1.makeSessionFactory)(20 * 60);
@@ -50,12 +50,7 @@ function makeApp(dataFolder, domain, midAuthorizer) {
50
50
  setupStaticEntryRoute(app.http);
51
51
  app.use(PATHS.owner, owners.makeApp(domain, ownersSessions, users, midAuthorizer));
52
52
  app.http.use(PATHS.shared, sharing.makeApp(sharingSessions, users));
53
- app.http.use((0, error_handler_1.makeErrHandler)((err, req) => {
54
- if (typeof err.status !== 'number') {
55
- console.error(`\n --- Error occured in storage, when handling ${req.method} request to ${req.originalUrl}`);
56
- console.error(err);
57
- }
58
- }));
53
+ app.http.use((0, error_handler_1.makeErrHandler)(errLogger));
59
54
  return app;
60
55
  }
61
56
  exports.makeApp = makeApp;
@@ -1,3 +1,4 @@
1
1
  import * as express from 'express';
2
+ import { ErrLogger } from '../lib-server/middleware/error-handler';
2
3
  import { Configurations } from '../services';
3
- export declare function makeApp(conf: Configurations): express.Express;
4
+ export declare function makeApp(conf: Configurations, errLogger?: ErrLogger): express.Express;
@@ -33,14 +33,14 @@ function apiPart(users) {
33
33
  app.post('/' + signupApi.addUser.URL_END, (0, body_parsers_1.json)('4kb'), (0, add_1.addUser)(users.add));
34
34
  return app;
35
35
  }
36
- function makeApp(conf) {
36
+ function makeApp(conf, errLogger) {
37
37
  const app = express();
38
38
  const noTokenFile = (conf.signup ? conf.signup.noTokenFile : undefined);
39
39
  const users = (0, users_1.makeFactory)(conf.rootFolder, noTokenFile);
40
40
  if (conf.signup) {
41
41
  app.use('/signup', apiPart(users));
42
42
  }
43
- app.use((0, error_handler_1.makeErrHandler)());
43
+ app.use((0, error_handler_1.makeErrHandler)(errLogger));
44
44
  return app;
45
45
  }
46
46
  exports.makeApp = makeApp;
@@ -1,3 +1,4 @@
1
1
  import { AppWithWSs } from '../lib-server/web-sockets/app';
2
2
  import { MidAuthorizer } from '../lib-server/routes/sessions/mid-auth';
3
- export declare function makeApp(rootFolder: string, domain: string, midAuthorizer: MidAuthorizer): AppWithWSs;
3
+ import { ErrLogger } from '../lib-server/middleware/error-handler';
4
+ export declare function makeApp(rootFolder: string, domain: string, midAuthorizer: MidAuthorizer, errLogger?: ErrLogger): AppWithWSs;
@@ -46,7 +46,7 @@ function setupStaticEntryRoute(app) {
46
46
  res.status(200).json(json);
47
47
  });
48
48
  }
49
- function makeApp(rootFolder, domain, midAuthorizer) {
49
+ function makeApp(rootFolder, domain, midAuthorizer, errLogger) {
50
50
  const app = new app_1.AppWithWSs();
51
51
  const mailDeliverySessions = delivery_sessions_1.DeliverySessions.make(5 * 60);
52
52
  const recipientsSessions = (0, sessions_1.makeSessionFactory)(10 * 60);
@@ -56,12 +56,7 @@ function makeApp(rootFolder, domain, midAuthorizer) {
56
56
  app.http.use(PATHS.delivery, (0, delivery_1.makeApp)(domain, mailDeliverySessions, recipients, midAuthorizer));
57
57
  app.use(PATHS.retrieval, (0, retrieval_1.makeApp)(domain, recipientsSessions, recipients, midAuthorizer));
58
58
  app.http.use(PATHS.config, (0, config_1.makeApp)(domain, userSettingSessions, recipients, midAuthorizer));
59
- app.http.use((0, error_handler_1.makeErrHandler)((err, req) => {
60
- if (typeof err.status !== 'number') {
61
- console.error(`\n --- Error occured in asmail, when handling ${req.method} request to ${req.originalUrl}`);
62
- console.error(err);
63
- }
64
- }));
59
+ app.http.use((0, error_handler_1.makeErrHandler)(errLogger));
65
60
  return app;
66
61
  }
67
62
  exports.makeApp = makeApp;
@@ -13,3 +13,4 @@ export interface HttpError extends ErrorWithCause {
13
13
  export declare function makeErr(code: number, msg: string, cause?: any): HttpError;
14
14
  export declare type ErrLogger = (err: any, req: Request) => void;
15
15
  export declare function makeErrHandler(log?: ErrLogger): ErrorRequestHandler;
16
+ export declare function makeErrLoggerToConsole(srvName: string): ErrLogger;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016, 2020 3NSoft Inc.
3
+ Copyright (C) 2016, 2020, 2023 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
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.makeErrHandler = exports.makeErr = void 0;
19
+ exports.makeErrLoggerToConsole = exports.makeErrHandler = exports.makeErr = void 0;
20
20
  const http = require("http");
21
21
  const error_1 = require("../../lib-common/exceptions/error");
22
22
  /**
@@ -63,4 +63,13 @@ function makeErrHandler(log) {
63
63
  };
64
64
  }
65
65
  exports.makeErrHandler = makeErrHandler;
66
+ function makeErrLoggerToConsole(srvName) {
67
+ return (err, req) => {
68
+ if (typeof err.status !== 'number') {
69
+ console.error(`\n --- Error occured in ${srvName}, when handling ${req.method} request to ${req.originalUrl}`);
70
+ console.error(err);
71
+ }
72
+ };
73
+ }
74
+ exports.makeErrLoggerToConsole = makeErrLoggerToConsole;
66
75
  Object.freeze(exports);
package/build/lib.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export import services = require('./services');
2
- export import confs = require('./run-config');
3
- export import appUtils = require('./lib-server/web-sockets/app');
4
- export import mock = require('./mock/run-in-proc');
1
+ export { AppWithWSs } from './lib-server/web-sockets/app';
2
+ export { Configurations, servicesApp, adminApp } from './services';
3
+ export { addSingleUserSignup, getConfsFromEnv, getBindParamsFromEnv } from './run-config';
4
+ export import errors = require('./lib-server/middleware/error-handler');
5
+ export * as mock from './mock/run-in-proc';
package/build/lib.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020 3NSoft Inc.
3
+ Copyright (C) 2020, 2023 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
@@ -16,8 +16,16 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.services = require("./services");
20
- exports.confs = require("./run-config");
21
- exports.appUtils = require("./lib-server/web-sockets/app");
19
+ exports.mock = exports.getBindParamsFromEnv = exports.getConfsFromEnv = exports.addSingleUserSignup = exports.adminApp = exports.servicesApp = exports.AppWithWSs = void 0;
20
+ var app_1 = require("./lib-server/web-sockets/app");
21
+ Object.defineProperty(exports, "AppWithWSs", { enumerable: true, get: function () { return app_1.AppWithWSs; } });
22
+ var services_1 = require("./services");
23
+ Object.defineProperty(exports, "servicesApp", { enumerable: true, get: function () { return services_1.servicesApp; } });
24
+ Object.defineProperty(exports, "adminApp", { enumerable: true, get: function () { return services_1.adminApp; } });
25
+ var run_config_1 = require("./run-config");
26
+ Object.defineProperty(exports, "addSingleUserSignup", { enumerable: true, get: function () { return run_config_1.addSingleUserSignup; } });
27
+ Object.defineProperty(exports, "getConfsFromEnv", { enumerable: true, get: function () { return run_config_1.getConfsFromEnv; } });
28
+ Object.defineProperty(exports, "getBindParamsFromEnv", { enumerable: true, get: function () { return run_config_1.getBindParamsFromEnv; } });
29
+ exports.errors = require("./lib-server/middleware/error-handler");
22
30
  exports.mock = require("./mock/run-in-proc");
23
31
  Object.freeze(exports);
@@ -3,4 +3,5 @@
3
3
  * express MailerId application.
4
4
  */
5
5
  import * as express from 'express';
6
- export declare function makeApp(rootFolder: string, domain: string, certFile: string): express.Express;
6
+ import { ErrLogger } from '../lib-server/middleware/error-handler';
7
+ export declare function makeApp(rootFolder: string, domain: string, certFile: string, errLogger?: ErrLogger): express.Express;
@@ -43,7 +43,7 @@ function provisioningApp(sessions, users, certifier, computeDHSharedKey) {
43
43
  app.post('/' + api.certify.URL_END, sessions.ensureAuthorizedSession(), (0, body_parsers_1.binary)('16kb'), (0, certify_1.certify)(certifier.certify));
44
44
  return app;
45
45
  }
46
- function makeApp(rootFolder, domain, certFile) {
46
+ function makeApp(rootFolder, domain, certFile, errLogger) {
47
47
  const app = express();
48
48
  const certProvisSessions = (0, sessions_1.makeSessionFactory)(2 * 60);
49
49
  const users = (0, users_1.makeFactory)(rootFolder);
@@ -62,7 +62,7 @@ function makeApp(rootFolder, domain, certFile) {
62
62
  };
63
63
  res.status(200).json(json); // content type application/json
64
64
  });
65
- app.use((0, error_handler_1.makeErrHandler)());
65
+ app.use((0, error_handler_1.makeErrHandler)(errLogger));
66
66
  return app;
67
67
  }
68
68
  exports.makeApp = makeApp;
package/build/main.js CHANGED
@@ -13,13 +13,13 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
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/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  /*
19
20
  * This script starts server, according to settings, given in config file.
20
21
  */
21
- const services_1 = require("./services");
22
- const app_1 = require("./lib-server/web-sockets/app");
22
+ const lib_1 = require("./lib");
23
23
  const fs_1 = require("fs");
24
24
  const async_fs_node_1 = require("./lib-common/async-fs-node");
25
25
  const child_process_1 = require("child_process");
@@ -64,9 +64,9 @@ const noop = () => { };
64
64
  (0, async_fs_node_1.unlink)(PID_FILE).catch(noop);
65
65
  }
66
66
  try {
67
- app = new app_1.AppWithWSs();
68
- app.use((0, services_1.servicesApp)(conf));
69
- app.use((0, services_1.adminApp)(conf));
67
+ app = new lib_1.AppWithWSs();
68
+ app.use((0, lib_1.servicesApp)(conf));
69
+ app.use((0, lib_1.adminApp)(conf));
70
70
  const { hostname, port, sslOpts } = conf.servicesConnect;
71
71
  await app.start(sslOpts, port, hostname);
72
72
  console.log(`Started 3NWeb server at address "${hostname}", port ${port}, ${sslOpts ? 'via TLS' : 'without TLS, and requiring TLS reverse proxy infront.'}`);
package/build/run.js CHANGED
@@ -13,22 +13,32 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
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/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
- const services_1 = require("./services");
19
- const app_1 = require("./lib-server/web-sockets/app");
20
- const run_config_1 = require("./run-config");
19
+ const lib_1 = require("./lib");
21
20
  (async () => {
21
+ let app = undefined;
22
+ async function stopProcess() {
23
+ if (!app) {
24
+ return;
25
+ }
26
+ app.stop().then(err => console.log(err));
27
+ app = undefined;
28
+ }
22
29
  try {
23
- const conf = (0, run_config_1.getConfsFromEnv)();
24
- const app = new app_1.AppWithWSs();
25
- app.use((0, services_1.servicesApp)(conf));
26
- app.use((0, services_1.adminApp)(conf));
27
- const { address, port, sslOpts } = (0, run_config_1.getBindParamsFromEnv)();
30
+ const conf = (0, lib_1.getConfsFromEnv)();
31
+ app = new lib_1.AppWithWSs();
32
+ app.use((0, lib_1.servicesApp)(conf));
33
+ app.use((0, lib_1.adminApp)(conf));
34
+ const { address, port, sslOpts } = (0, lib_1.getBindParamsFromEnv)();
28
35
  await app.start(sslOpts, port, address);
29
36
  console.log(`Started 3NWeb server at address ${address}, port ${port}, ${sslOpts ? 'via TLS' : 'without TLS, and requiring TLS reverse proxy infront.'}`);
37
+ process.on('SIGINT', stopProcess);
38
+ process.on('SIGTERM', stopProcess);
30
39
  }
31
40
  catch (err) {
41
+ stopProcess();
32
42
  console.error(err);
33
43
  process.exit(-500);
34
44
  }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import * as https from "https";
3
3
  import { AppWithWSs } from './lib-server/web-sockets/app';
4
+ import { ErrLogger } from "./lib-server/middleware/error-handler";
4
5
  export interface Configurations {
5
6
  enabledServices: {
6
7
  asmail?: boolean;
@@ -21,5 +22,5 @@ export interface Configurations {
21
22
  noTokenFile?: string;
22
23
  };
23
24
  }
24
- export declare function servicesApp(conf: Configurations): AppWithWSs;
25
- export declare function adminApp(conf: Configurations): AppWithWSs;
25
+ export declare function servicesApp(conf: Configurations, errLogger?: ErrLogger | 'console'): AppWithWSs;
26
+ export declare function adminApp(conf: Configurations, errLogger?: ErrLogger | 'console'): AppWithWSs;
package/build/services.js CHANGED
@@ -23,26 +23,30 @@ const mailerId_app_1 = require("./mailerId/mailerId-app");
23
23
  const asmail_app_1 = require("./asmail/asmail-app");
24
24
  const _3nstorage_app_1 = require("./3nstorage/3nstorage-app");
25
25
  const admin_app_1 = require("./admin/admin-app");
26
- function servicesApp(conf) {
26
+ const error_handler_1 = require("./lib-server/middleware/error-handler");
27
+ function servicesApp(conf, errLogger) {
27
28
  if (!conf.enabledServices || (typeof conf.enabledServices !== 'object')) {
28
29
  throw new Error('Missing enabled-services sections in confs.');
29
30
  }
30
31
  const app = new app_1.AppWithWSs();
31
32
  const midAuthorizer = (0, mailerid_authorizer_1.validator)(); // share, allowing for caching of certs
32
33
  if (conf.enabledServices.mailerId) {
33
- app.http.use('/mailerid', (0, mailerId_app_1.makeApp)(conf.rootFolder, conf.domain, conf.mailerId.certs));
34
+ app.http.use('/mailerid', (0, mailerId_app_1.makeApp)(conf.rootFolder, conf.domain, conf.mailerId.certs, (errLogger === 'console') ? (0, error_handler_1.makeErrLoggerToConsole)('mailerid') : errLogger));
34
35
  }
35
36
  if (conf.enabledServices.asmail) {
36
- app.use('/asmail', (0, asmail_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer));
37
+ app.use('/asmail', (0, asmail_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer, (errLogger === 'console') ? (0, error_handler_1.makeErrLoggerToConsole)('asmail') : errLogger));
37
38
  }
38
39
  if (conf.enabledServices.storage) {
39
- app.use('/3nstorage', (0, _3nstorage_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer));
40
+ app.use('/3nstorage', (0, _3nstorage_app_1.makeApp)(conf.rootFolder, conf.domain, midAuthorizer, (errLogger === 'console') ? (0, error_handler_1.makeErrLoggerToConsole)('storage') : errLogger));
40
41
  }
41
42
  return app;
42
43
  }
43
44
  exports.servicesApp = servicesApp;
44
- function adminApp(conf) {
45
- return new app_1.AppWithWSs((0, admin_app_1.makeApp)(conf));
45
+ function adminApp(conf, errLogger) {
46
+ if (errLogger === 'console') {
47
+ errLogger = (0, error_handler_1.makeErrLoggerToConsole)('3NWeb server admin');
48
+ }
49
+ return new app_1.AppWithWSs((0, admin_app_1.makeApp)(conf, errLogger));
46
50
  }
47
51
  exports.adminApp = adminApp;
48
52
  Object.freeze(exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-3nweb-server",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "3NWeb spec server.",
5
5
  "main": "build/lib.js",
6
6
  "types": "build/lib.d.ts",