spec-3nweb-server 1.6.4 → 1.7.0

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/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
 
2
-
3
2
  # Spec Server
4
3
 
5
4
  This repository contains 3NWeb protocols' specification test suite and a single-machine server implementation, conforming to spec's suite.
@@ -1,4 +1,4 @@
1
1
  import * as express from 'express';
2
2
  import { ErrLogger } from '../lib-server/middleware/error-handler';
3
3
  import { Configurations } from '../services';
4
- export declare function makeApp(conf: Configurations, errLogger?: ErrLogger): express.Express;
4
+ export declare function makeApp(conf: Configurations, errLogger?: ErrLogger, logSetup?: 'console'): express.Express;
@@ -33,12 +33,15 @@ 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, errLogger) {
36
+ function makeApp(conf, errLogger, logSetup) {
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
+ if (logSetup === 'console') {
43
+ console.log(`Enabled signup service.`);
44
+ }
42
45
  }
43
46
  app.use((0, error_handler_1.makeErrHandler)(errLogger));
44
47
  return app;
@@ -0,0 +1,9 @@
1
+ import { ParsedRunArgs } from "./run-cmd";
2
+ import { ParsedSignupArgs } from "./signup-cmd";
3
+ import { CliUsageDisplay } from "./utils";
4
+ export { CliUsageDisplay } from "./utils";
5
+ export declare function parseProcessArgv(): {
6
+ runCmd?: ParsedRunArgs;
7
+ signupCmd?: ParsedSignupArgs;
8
+ showUsage?: CliUsageDisplay;
9
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2023 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.parseProcessArgv = void 0;
20
+ const path_1 = require("path");
21
+ const run_cmd_1 = require("./run-cmd");
22
+ const signup_cmd_1 = require("./signup-cmd");
23
+ const utils_1 = require("./utils");
24
+ function mainUsage(execName) {
25
+ return [
26
+ {
27
+ header: execName,
28
+ content: `Server of all 3NWeb utilities: MailerId, ASMail, 3NStorage.`
29
+ },
30
+ {
31
+ header: `Usage:`,
32
+ content: `${execName} [command]`
33
+ },
34
+ {
35
+ header: 'Available commands:',
36
+ content: [
37
+ run_cmd_1.runCmd,
38
+ signup_cmd_1.signupCmd
39
+ ]
40
+ },
41
+ {
42
+ header: '',
43
+ content: `Use "${execName} [command] --help" for more information about a command.`
44
+ }
45
+ ];
46
+ }
47
+ function parseProcessArgv() {
48
+ const args = process.argv.slice(2);
49
+ const execName = (0, path_1.basename)(process.argv0);
50
+ if (args.length === 0) {
51
+ return (0, utils_1.toUsageDisplay)(0, mainUsage(execName));
52
+ }
53
+ if (args[0] === run_cmd_1.runCmd.name) {
54
+ return (0, run_cmd_1.parseRunArgs)(args.slice(1), execName);
55
+ }
56
+ else if (args[0] === signup_cmd_1.signupCmd.name) {
57
+ return (0, signup_cmd_1.parseSignupArgs)(args.slice(1), execName);
58
+ }
59
+ else {
60
+ const opts = (0, utils_1.parseArgv)(args, [utils_1.helpOpt], { partial: true });
61
+ if (opts.help) {
62
+ return (0, utils_1.toUsageDisplay)(0, mainUsage(execName));
63
+ }
64
+ return (0, utils_1.toUsageDisplay)(-1, (0, utils_1.toErrorUsage)(mainUsage(execName), `Unknown command '${args[0]}'`));
65
+ }
66
+ }
67
+ exports.parseProcessArgv = parseProcessArgv;
68
+ Object.freeze(exports);
@@ -0,0 +1,10 @@
1
+ import { CliUsageDisplay, CommandDef } from "./utils";
2
+ export declare const runCmd: CommandDef<'run'>;
3
+ export interface ParsedRunArgs {
4
+ config?: string;
5
+ help?: boolean;
6
+ }
7
+ export declare function parseRunArgs(args: string[], execName: string): {
8
+ runCmd?: ParsedRunArgs;
9
+ showUsage?: CliUsageDisplay;
10
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2023 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.parseRunArgs = exports.runCmd = void 0;
20
+ const utils_1 = require("./utils");
21
+ exports.runCmd = {
22
+ name: 'run',
23
+ summary: 'runs 3NWeb services'
24
+ };
25
+ function runUsage(execName) {
26
+ return [
27
+ {
28
+ content: `This command runs some or all 3NWeb services. Configuration is read from a yaml file.`
29
+ },
30
+ {
31
+ header: 'Usage:',
32
+ content: `${execName} ${exports.runCmd.name} [options] [config_file]`
33
+ },
34
+ {
35
+ header: 'Options:',
36
+ optionList: runOpts
37
+ }
38
+ ];
39
+ }
40
+ const runOpts = [
41
+ {
42
+ name: 'config',
43
+ alias: 'c',
44
+ type: String,
45
+ typeLabel: '{underline <file>}',
46
+ description: `path of a configuration yaml file`
47
+ },
48
+ utils_1.helpOpt
49
+ ];
50
+ function parseRunArgs(args, execName) {
51
+ if (args.length === 0) {
52
+ return (0, utils_1.toUsageDisplay)(0, runUsage(execName));
53
+ }
54
+ const runArgs = (0, utils_1.parseArgv)(args, runOpts, { partial: true });
55
+ if (runArgs.help) {
56
+ return (0, utils_1.toUsageDisplay)(0, runUsage(execName));
57
+ }
58
+ else if (runArgs.config) {
59
+ return { runCmd: runArgs };
60
+ }
61
+ else if (runArgs._unknown) {
62
+ return { runCmd: { config: runArgs._unknown[0] } };
63
+ }
64
+ else {
65
+ return (0, utils_1.toUsageDisplay)(-1, (0, utils_1.toErrorUsage)(runUsage(execName), `Missing configuration file path.`));
66
+ }
67
+ }
68
+ exports.parseRunArgs = parseRunArgs;
69
+ Object.freeze(exports);
@@ -0,0 +1,17 @@
1
+ import { CliUsageDisplay, CommandDef } from "./utils";
2
+ export declare const signupCmd: CommandDef<'signup'>;
3
+ export interface ParsedSignupArgs {
4
+ info?: boolean;
5
+ config?: string;
6
+ help?: boolean;
7
+ listTokens?: boolean;
8
+ showToken?: boolean;
9
+ token?: string;
10
+ createToken?: boolean;
11
+ domain?: string[];
12
+ user?: string;
13
+ }
14
+ export declare function parseSignupArgs(args: string[], execName: string): {
15
+ signupCmd?: ParsedSignupArgs;
16
+ showUsage?: CliUsageDisplay;
17
+ };
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2023 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.parseSignupArgs = exports.signupCmd = void 0;
20
+ const utils_1 = require("./utils");
21
+ exports.signupCmd = {
22
+ name: 'signup',
23
+ summary: 'controls adding new users to this instance'
24
+ };
25
+ function signupUsage(execName) {
26
+ return [
27
+ {
28
+ content: `This command controls parameters of adding new users to this instance.`
29
+ },
30
+ {
31
+ header: 'Usage:',
32
+ content: `${execName} ${exports.signupCmd.name} [command] [options] [config_file]`
33
+ },
34
+ {
35
+ header: 'Available commands:',
36
+ content: [
37
+ infoCmd,
38
+ listTokensCmd,
39
+ showTokenCmd,
40
+ createTokenCmd
41
+ ]
42
+ },
43
+ {
44
+ header: `${infoCmd.name} options:`,
45
+ optionList: infoOpts
46
+ },
47
+ {
48
+ header: `${listTokensCmd.name} options:`,
49
+ optionList: listTokensOpts
50
+ },
51
+ {
52
+ header: `${showTokenCmd.name} options:`,
53
+ optionList: showTokenOpts
54
+ },
55
+ {
56
+ header: `${createTokenCmd.name} options:`,
57
+ optionList: createTokenOpts
58
+ }
59
+ ];
60
+ }
61
+ const configOpt = {
62
+ name: 'config',
63
+ alias: 'c',
64
+ type: String,
65
+ typeLabel: '{underline <file>}',
66
+ description: `path of a configuration yaml file`
67
+ };
68
+ const infoCmd = {
69
+ name: 'info',
70
+ summary: 'shows state of signup subsystem'
71
+ };
72
+ const infoOpts = [
73
+ configOpt
74
+ ];
75
+ const listTokensCmd = {
76
+ name: 'list-tokens',
77
+ summary: 'lists signup tokens'
78
+ };
79
+ const listTokensOpts = [
80
+ configOpt
81
+ ];
82
+ const showTokenCmd = {
83
+ name: 'show-token',
84
+ summary: 'shows signup token with complete value'
85
+ };
86
+ const showTokenOpts = [
87
+ configOpt,
88
+ {
89
+ name: 'token',
90
+ alias: 't',
91
+ type: String,
92
+ typeLabel: '{underline <token_id>}',
93
+ description: `token id`
94
+ }
95
+ ];
96
+ const createTokenCmd = {
97
+ name: 'create-token',
98
+ summary: 'creates signup token for single user, when user id is given, and for many users, when domain(s) are given'
99
+ };
100
+ const createTokenOpts = [
101
+ configOpt,
102
+ {
103
+ name: 'domain',
104
+ alias: 'd',
105
+ type: String,
106
+ typeLabel: '{underline <domain>}',
107
+ multiple: true,
108
+ description: `domain for new users. Several domain options will attach all domains to same token.`
109
+ },
110
+ {
111
+ name: 'user',
112
+ alias: 'u',
113
+ type: String,
114
+ typeLabel: '{underline <user_address>}',
115
+ description: `address of a single user`
116
+ }
117
+ ];
118
+ function parseWithConfFile(args, optList) {
119
+ const opts = (0, utils_1.parseArgv)(args, optList, { partial: true });
120
+ if (opts.config) {
121
+ return opts;
122
+ }
123
+ else if (opts._unknown) {
124
+ opts.config = opts._unknown[0];
125
+ return opts;
126
+ }
127
+ else {
128
+ return;
129
+ }
130
+ }
131
+ function cmdUsageErr(execName, cmd, errTxt = `missing configuration file`) {
132
+ return (0, utils_1.toUsageDisplay)(-1, (0, utils_1.toErrorUsage)(signupUsage(execName), `Incorrect options for command '${exports.signupCmd.name} ${cmd}': ${errTxt}`));
133
+ }
134
+ function parseSignupArgs(args, execName) {
135
+ if (args.length === 0) {
136
+ return (0, utils_1.toUsageDisplay)(0, signupUsage(execName));
137
+ }
138
+ if (args[0] === infoCmd.name) {
139
+ const signupCmd = parseWithConfFile(args.slice(1), infoOpts);
140
+ if (signupCmd) {
141
+ signupCmd.info = true;
142
+ return { signupCmd };
143
+ }
144
+ else {
145
+ return cmdUsageErr(execName, infoCmd.name);
146
+ }
147
+ }
148
+ else if (args[0] === listTokensCmd.name) {
149
+ const signupCmd = parseWithConfFile(args.slice(1), listTokensOpts);
150
+ if (signupCmd) {
151
+ signupCmd.listTokens = true;
152
+ return { signupCmd };
153
+ }
154
+ else {
155
+ return cmdUsageErr(execName, listTokensCmd.name);
156
+ }
157
+ }
158
+ else if (args[0] === showTokenCmd.name) {
159
+ const signupCmd = parseWithConfFile(args.slice(1), showTokenOpts);
160
+ if (signupCmd) {
161
+ if (!signupCmd.token) {
162
+ return cmdUsageErr(execName, showTokenCmd.name, `missing token`);
163
+ }
164
+ signupCmd.showToken = true;
165
+ return { signupCmd };
166
+ }
167
+ else {
168
+ return cmdUsageErr(execName, showTokenCmd.name);
169
+ }
170
+ }
171
+ else if (args[0] === createTokenCmd.name) {
172
+ console.log(args);
173
+ const signupCmd = parseWithConfFile(args.slice(1), createTokenOpts);
174
+ if (signupCmd) {
175
+ if (!signupCmd.domain && !signupCmd.user) {
176
+ return cmdUsageErr(execName, createTokenCmd.name, `either user address, or domain(s) should be given`);
177
+ }
178
+ signupCmd.createToken = true;
179
+ return { signupCmd };
180
+ }
181
+ else {
182
+ return cmdUsageErr(execName, createTokenCmd.name);
183
+ }
184
+ }
185
+ else {
186
+ const opts = (0, utils_1.parseArgv)(args, [utils_1.helpOpt], { partial: true });
187
+ if (opts.help) {
188
+ return (0, utils_1.toUsageDisplay)(0, signupUsage(execName));
189
+ }
190
+ return (0, utils_1.toUsageDisplay)(-1, (0, utils_1.toErrorUsage)(signupUsage(execName), `Unknown command '${args[0]}'`));
191
+ }
192
+ }
193
+ exports.parseSignupArgs = parseSignupArgs;
194
+ Object.freeze(exports);
@@ -0,0 +1,9 @@
1
+ import { CliUsageDisplay, CommandDef } from "./utils";
2
+ export declare const userCmd: CommandDef<'user'>;
3
+ export interface ParsedUserArgs {
4
+ listAll?: true;
5
+ }
6
+ export declare function parseSignupArgs(args: string[], execName: string): {
7
+ userCmd?: ParsedUserArgs;
8
+ showUsage?: CliUsageDisplay;
9
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2023 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.parseSignupArgs = exports.userCmd = void 0;
20
+ const utils_1 = require("./utils");
21
+ exports.userCmd = {
22
+ name: 'user',
23
+ summary: 'provides information about existing users'
24
+ };
25
+ const listCmd = {
26
+ name: 'list',
27
+ summary: `lists users`
28
+ };
29
+ function userUsage(execName) {
30
+ return [
31
+ {
32
+ header: execName,
33
+ content: `Server of all 3NWeb utilities: MailerId, ASMail, 3NStorage.`
34
+ },
35
+ {
36
+ header: `Usage:`,
37
+ content: `${execName} user [command]`
38
+ },
39
+ {
40
+ header: 'Available commands:',
41
+ content: []
42
+ },
43
+ {
44
+ content: `Use "${execName} user [command] --help" for more information about a command.`
45
+ }
46
+ ];
47
+ }
48
+ function parseSignupArgs(args, execName) {
49
+ if (args.length === 0) {
50
+ return (0, utils_1.toUsageDisplay)(0, userUsage(execName));
51
+ }
52
+ // XXX
53
+ return {};
54
+ }
55
+ exports.parseSignupArgs = parseSignupArgs;
@@ -0,0 +1,45 @@
1
+ export interface CommandDef<T extends string> {
2
+ name: T;
3
+ summary: string;
4
+ }
5
+ export interface OptionDef {
6
+ name: string;
7
+ type: (typeof Boolean) | (typeof String) | (typeof Number) | ((value: string) => any);
8
+ alias?: string;
9
+ description?: string;
10
+ typeLabel?: string;
11
+ multiple?: boolean;
12
+ defaultOption?: boolean;
13
+ }
14
+ export interface UsageSection {
15
+ header?: string;
16
+ summary?: string;
17
+ optionList?: OptionDef[];
18
+ content?: string | UsageSectionContent | (string | UsageSection)[];
19
+ }
20
+ export interface UsageSectionContent {
21
+ options: any;
22
+ data: any;
23
+ }
24
+ export interface ParseOptions {
25
+ argv?: string[];
26
+ partial?: boolean;
27
+ stopAtFirstUnknown?: boolean;
28
+ camelCase?: boolean;
29
+ caseInsensitive?: boolean;
30
+ }
31
+ export interface CliUsageDisplay {
32
+ txtToDisplay: string;
33
+ exitStatus: number;
34
+ }
35
+ export declare const helpOpt: OptionDef;
36
+ export interface HelpArg {
37
+ help?: boolean;
38
+ }
39
+ export declare function toUsageDisplay(exitStatus: number, usage: UsageSection[]): {
40
+ showUsage: CliUsageDisplay;
41
+ };
42
+ export declare function parseArgv<T>(argv: string[], argOpts: OptionDef[], opts?: ParseOptions): T & {
43
+ _unknown?: string[];
44
+ };
45
+ export declare function toErrorUsage(usage: UsageSection[], errTxt: string): UsageSection[];
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2023 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.toErrorUsage = exports.parseArgv = exports.toUsageDisplay = exports.helpOpt = void 0;
20
+ const commandLineArgs = require("command-line-args");
21
+ const commandLineUsage = require("command-line-usage");
22
+ exports.helpOpt = {
23
+ name: 'help',
24
+ alias: 'h',
25
+ type: Boolean,
26
+ description: 'shows help'
27
+ };
28
+ function toUsageDisplay(exitStatus, usage) {
29
+ return {
30
+ showUsage: {
31
+ txtToDisplay: commandLineUsage(usage),
32
+ exitStatus
33
+ }
34
+ };
35
+ }
36
+ exports.toUsageDisplay = toUsageDisplay;
37
+ function parseArgv(argv, argOpts, opts) {
38
+ if (opts) {
39
+ opts.argv = argv;
40
+ }
41
+ else {
42
+ opts = { argv };
43
+ }
44
+ return commandLineArgs(argOpts, opts);
45
+ }
46
+ exports.parseArgv = parseArgv;
47
+ function toErrorUsage(usage, errTxt) {
48
+ usage[0] = { content: errTxt };
49
+ return usage;
50
+ }
51
+ exports.toErrorUsage = toErrorUsage;
52
+ Object.freeze(exports);
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Configurations } from "./services";
2
+ import { Configurations } from "../services";
3
3
  import { ServerOptions } from "https";
4
4
  export declare function getConfsFromEnv(): Configurations;
5
5
  export declare function getBindParamsFromEnv(): {
@@ -7,4 +7,3 @@ export declare function getBindParamsFromEnv(): {
7
7
  port: number;
8
8
  sslOpts?: ServerOptions;
9
9
  };
10
- export declare function addSingleUserSignup(rootFolder: string, userId: string): Promise<string>;
@@ -16,12 +16,10 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.addSingleUserSignup = exports.getBindParamsFromEnv = exports.getConfsFromEnv = void 0;
20
- const async_fs_node_1 = require("./lib-common/async-fs-node");
19
+ exports.getBindParamsFromEnv = exports.getConfsFromEnv = void 0;
20
+ const async_fs_node_1 = require("../lib-common/async-fs-node");
21
21
  const path_1 = require("path");
22
22
  const fs_1 = require("fs");
23
- const signup_tokens_1 = require("./admin/signup-tokens");
24
- const server_data_folders_1 = require("./lib-server/resources/server-data-folders");
25
23
  const DOMAIN_VAR = 'W3N_DOMAIN';
26
24
  const DATA_DIR_VAR = 'W3N_DATA_DIR';
27
25
  const NO_TOKENS_FILE = 'NO_TOKENS_FILE';
@@ -116,31 +114,4 @@ function getTLSParamsFromEnv() {
116
114
  throw new Error(`Both ${TLS_CERT_VAR} and ${TLS_KEY_VAR} environment parameters should be present, but one is missing.`);
117
115
  }
118
116
  }
119
- async function addSingleUserSignup(rootFolder, userId) {
120
- const token = await (0, signup_tokens_1.generateToken)();
121
- const ctx = (0, signup_tokens_1.makeSingleUserSignupCtx)(token, userId);
122
- const fPath = (0, signup_tokens_1.tokenPath)(rootFolder, token);
123
- try {
124
- await (0, async_fs_node_1.writeFile)(fPath, JSON.stringify(ctx), { encoding: 'utf8', flag: 'wx' });
125
- return token;
126
- }
127
- catch (exc) {
128
- if (exc.alreadyExists) {
129
- return addSingleUserSignup(rootFolder, userId);
130
- }
131
- else if (exc.notFound) {
132
- await (0, async_fs_node_1.mkdir)((0, server_data_folders_1.tokensInRootFolder)(rootFolder))
133
- .catch((exc) => {
134
- if (!exc.alreadyExists) {
135
- throw exc;
136
- }
137
- });
138
- return addSingleUserSignup(rootFolder, userId);
139
- }
140
- else {
141
- throw exc;
142
- }
143
- }
144
- }
145
- exports.addSingleUserSignup = addSingleUserSignup;
146
117
  Object.freeze(exports);
@@ -0,0 +1,2 @@
1
+ import { Configurations } from '../services';
2
+ export declare function readYamlConfFile(path: string): Configurations;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2023 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.readYamlConfFile = void 0;
20
+ const fs_1 = require("fs");
21
+ const yaml = require("js-yaml");
22
+ function readYamlConfFile(path) {
23
+ const txt = (0, fs_1.readFileSync)(path, 'utf8');
24
+ const conf = yaml.load(txt);
25
+ return conf;
26
+ }
27
+ exports.readYamlConfFile = readYamlConfFile;
28
+ Object.freeze(exports);
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { ServerOptions } from "https";
3
+ export declare type CertsUpdateListener = (newOpts: ServerOptions, originalOpts: ServerOptions) => Promise<void>;
4
+ export declare function sslOptsFromConfig(letsencrypt: string | undefined, sslOpts: ServerOptions | undefined, skipReloadOnCertsChange: boolean | undefined): {
5
+ sslOpts: ServerOptions;
6
+ onCertsUpdate?: (listener: CertsUpdateListener) => (() => void);
7
+ } | undefined;