spec-3nweb-server 1.6.4 → 1.7.1

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 (66) hide show
  1. package/README.md +0 -1
  2. package/build/3nstorage/resources/sessions.d.ts +2 -2
  3. package/build/3nstorage/resources/store.d.ts +1 -1
  4. package/build/3nstorage/resources/users.d.ts +15 -15
  5. package/build/admin/admin-app.d.ts +1 -1
  6. package/build/admin/admin-app.js +4 -1
  7. package/build/admin/resources/users.d.ts +3 -3
  8. package/build/admin/signup-tokens.d.ts +1 -1
  9. package/build/asmail/resources/delivery-sessions.d.ts +3 -3
  10. package/build/asmail/resources/inbox.d.ts +9 -9
  11. package/build/asmail/resources/recipients.d.ts +18 -18
  12. package/build/asmail/resources/sessions.d.ts +2 -2
  13. package/build/asmail/routes/delivery/sender-authorization.d.ts +1 -1
  14. package/build/asmail/routes/delivery/start-session.d.ts +1 -1
  15. package/build/config/cli/index.d.ts +9 -0
  16. package/build/config/cli/index.js +68 -0
  17. package/build/config/cli/run-cmd.d.ts +10 -0
  18. package/build/config/cli/run-cmd.js +69 -0
  19. package/build/config/cli/signup-cmd.d.ts +17 -0
  20. package/build/config/cli/signup-cmd.js +194 -0
  21. package/build/config/cli/user-cmd.d.ts +9 -0
  22. package/build/config/cli/user-cmd.js +55 -0
  23. package/build/config/cli/utils.d.ts +45 -0
  24. package/build/config/cli/utils.js +52 -0
  25. package/build/config/from-yaml.d.ts +2 -0
  26. package/build/config/from-yaml.js +28 -0
  27. package/build/config/letsencrypt.d.ts +7 -0
  28. package/build/config/letsencrypt.js +62 -0
  29. package/build/config/signup.d.ts +15 -0
  30. package/build/config/signup.js +133 -0
  31. package/build/lib-common/byte-streaming/common.d.ts +2 -2
  32. package/build/lib-common/byte-streaming/common.js +5 -5
  33. package/build/lib-common/exceptions/file.d.ts +1 -1
  34. package/build/lib-common/ipc/generic-ipc.d.ts +7 -7
  35. package/build/lib-common/ipc/generic-ipc.js +6 -6
  36. package/build/lib-common/objs-on-disk/file-layout.d.ts +4 -4
  37. package/build/lib-common/objs-on-disk/utils.d.ts +3 -3
  38. package/build/lib-common/processes.d.ts +1 -1
  39. package/build/lib-common/service-api/ipc-api.d.ts +6 -6
  40. package/build/lib-common/service-api/web-socket-base.d.ts +1 -1
  41. package/build/lib-server/middleware/error-handler.d.ts +1 -1
  42. package/build/lib-server/resources/dns.d.ts +1 -1
  43. package/build/lib-server/resources/dns.js +48 -10
  44. package/build/lib-server/resources/sessions.d.ts +2 -2
  45. package/build/lib-server/resources/user-files.d.ts +1 -1
  46. package/build/lib-server/routes/pub-key-login/start-exchange.d.ts +4 -4
  47. package/build/lib-server/routes/sessions/mid-auth.d.ts +1 -1
  48. package/build/lib-server/routes/sessions/start.d.ts +4 -4
  49. package/build/lib-server/web-sockets/app.d.ts +1 -1
  50. package/build/lib-server/web-sockets/app.js +6 -6
  51. package/build/lib-server/web-sockets/server-events.d.ts +1 -1
  52. package/build/lib.d.ts +1 -1
  53. package/build/lib.js +3 -5
  54. package/build/mailerId/resources/certifier.d.ts +1 -1
  55. package/build/mailerId/resources/sessions.d.ts +1 -1
  56. package/build/main.js +196 -45
  57. package/build/mock/node-child-ipc.d.ts +2 -2
  58. package/build/mock/run-in-proc.js +6 -3
  59. package/build/services.d.ts +4 -2
  60. package/build/services.js +15 -6
  61. package/package.json +16 -3
  62. package/postinstall.js +25 -0
  63. package/build/run-config.d.ts +0 -10
  64. package/build/run-config.js +0 -146
  65. package/build/run.d.ts +0 -1
  66. package/build/run.js +0 -45
@@ -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);
@@ -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 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;
@@ -0,0 +1,62 @@
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.sslOptsFromConfig = void 0;
20
+ const fs_1 = require("fs");
21
+ const path_1 = require("path");
22
+ function sslOptsFromConfig(letsencrypt, sslOpts, skipReloadOnCertsChange) {
23
+ if (!sslOpts) {
24
+ sslOpts = {};
25
+ }
26
+ if (letsencrypt) {
27
+ sslOpts.cert = (0, fs_1.readFileSync)((0, path_1.join)(letsencrypt, 'fullchain.pem'));
28
+ sslOpts.key = (0, fs_1.readFileSync)((0, path_1.join)(letsencrypt, 'privkey.pem'));
29
+ if (skipReloadOnCertsChange) {
30
+ return { sslOpts };
31
+ }
32
+ const onCertsUpdate = makeCertsUpdatesWatch();
33
+ return { sslOpts, onCertsUpdate };
34
+ }
35
+ else if (sslOpts.cert && sslOpts.key) {
36
+ sslOpts.cert = (0, fs_1.readFileSync)(sslOpts.cert);
37
+ sslOpts.key = (0, fs_1.readFileSync)(sslOpts.key);
38
+ if (skipReloadOnCertsChange) {
39
+ return { sslOpts };
40
+ }
41
+ const onCertsUpdate = makeCertsUpdatesWatch();
42
+ return { sslOpts, onCertsUpdate };
43
+ }
44
+ else if ((!sslOpts.cert && sslOpts.key)
45
+ || (sslOpts.cert && !sslOpts.key)) {
46
+ throw new Error(`servicesConnect.sslOpts section must have both key and cert fields pointing to respective files.`);
47
+ }
48
+ else {
49
+ return;
50
+ }
51
+ }
52
+ exports.sslOptsFromConfig = sslOptsFromConfig;
53
+ function makeCertsUpdatesWatch(
54
+ // XXX pass locations, or some fs watching object
55
+ ) {
56
+ return listener => {
57
+ // XXX start watching a signal
58
+ const stopWatching = () => { };
59
+ return stopWatching;
60
+ };
61
+ }
62
+ Object.freeze(exports);
@@ -0,0 +1,15 @@
1
+ import { MultiDomainSignupCtx, SingleUserSignupCtx } from "../admin/signup-tokens";
2
+ export declare function addSingleUserSignup(rootFolder: string, userId: string): Promise<string>;
3
+ export declare function addMultiDomainSignup(rootFolder: string, domains: string[]): Promise<string>;
4
+ export declare function readNoTokensFile(noTokenFile: string): Promise<MultiDomainSignupCtx>;
5
+ export declare function readTokenFile(rootFolder: string, tokenId: string): Promise<SingleUserSignupCtx | MultiDomainSignupCtx | undefined>;
6
+ export declare function readAllSignupTokens(rootFolder: string): Promise<{
7
+ singleUserTokens: {
8
+ tokenId: string;
9
+ ctx: SingleUserSignupCtx;
10
+ }[];
11
+ multiUserTokens: {
12
+ tokenId: string;
13
+ ctx: MultiDomainSignupCtx;
14
+ }[];
15
+ }>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2019 - 2020 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.readAllSignupTokens = exports.readTokenFile = exports.readNoTokensFile = exports.addMultiDomainSignup = exports.addSingleUserSignup = void 0;
20
+ const async_fs_node_1 = require("../lib-common/async-fs-node");
21
+ const signup_tokens_1 = require("../admin/signup-tokens");
22
+ const server_data_folders_1 = require("../lib-server/resources/server-data-folders");
23
+ const error_1 = require("../lib-common/exceptions/error");
24
+ const path_1 = require("path");
25
+ async function addSingleUserSignup(rootFolder, userId) {
26
+ const token = await (0, signup_tokens_1.generateToken)();
27
+ const ctx = (0, signup_tokens_1.makeSingleUserSignupCtx)(token, userId);
28
+ const fPath = (0, signup_tokens_1.tokenPath)(rootFolder, token);
29
+ try {
30
+ await (0, async_fs_node_1.writeFile)(fPath, JSON.stringify(ctx), { encoding: 'utf8', flag: 'wx' });
31
+ return token;
32
+ }
33
+ catch (exc) {
34
+ if (exc.alreadyExists) {
35
+ return addSingleUserSignup(rootFolder, userId);
36
+ }
37
+ else if (exc.notFound) {
38
+ await (0, async_fs_node_1.mkdir)((0, server_data_folders_1.tokensInRootFolder)(rootFolder))
39
+ .catch((exc) => {
40
+ if (!exc.alreadyExists) {
41
+ throw exc;
42
+ }
43
+ });
44
+ return addSingleUserSignup(rootFolder, userId);
45
+ }
46
+ else {
47
+ throw exc;
48
+ }
49
+ }
50
+ }
51
+ exports.addSingleUserSignup = addSingleUserSignup;
52
+ async function addMultiDomainSignup(rootFolder, domains) {
53
+ const token = await (0, signup_tokens_1.generateToken)();
54
+ const ctx = (0, signup_tokens_1.makeMultiDomainSignupCtx)(domains, token);
55
+ const fPath = (0, signup_tokens_1.tokenPath)(rootFolder, token);
56
+ try {
57
+ await (0, async_fs_node_1.writeFile)(fPath, JSON.stringify(ctx), { encoding: 'utf8', flag: 'wx' });
58
+ return token;
59
+ }
60
+ catch (exc) {
61
+ if (exc.alreadyExists) {
62
+ return addMultiDomainSignup(rootFolder, domains);
63
+ }
64
+ else if (exc.notFound) {
65
+ await (0, async_fs_node_1.mkdir)((0, server_data_folders_1.tokensInRootFolder)(rootFolder))
66
+ .catch((exc) => {
67
+ if (!exc.alreadyExists) {
68
+ throw exc;
69
+ }
70
+ });
71
+ return addMultiDomainSignup(rootFolder, domains);
72
+ }
73
+ else {
74
+ throw exc;
75
+ }
76
+ }
77
+ }
78
+ exports.addMultiDomainSignup = addMultiDomainSignup;
79
+ async function readNoTokensFile(noTokenFile) {
80
+ try {
81
+ const str = await (0, async_fs_node_1.readFile)(noTokenFile, { encoding: 'utf8' });
82
+ return JSON.parse(str);
83
+ }
84
+ catch (err) {
85
+ throw (0, error_1.errWithCause)(err, `Fail to read "no tokens" signup context file ${noTokenFile}`);
86
+ }
87
+ }
88
+ exports.readNoTokensFile = readNoTokensFile;
89
+ async function readTokenFile(rootFolder, tokenId) {
90
+ try {
91
+ const fPath = (0, path_1.join)((0, server_data_folders_1.tokensInRootFolder)(rootFolder), tokenId);
92
+ const str = await (0, async_fs_node_1.readFile)(fPath, { encoding: 'utf8' });
93
+ const ctx = JSON.parse(str);
94
+ if (!ctx.token) {
95
+ return;
96
+ }
97
+ else if (ctx.type === 'multi-domain') {
98
+ return (ctx.domains ? ctx : undefined);
99
+ }
100
+ else if (ctx.type === 'single-user') {
101
+ return (ctx.userId ? ctx : undefined);
102
+ }
103
+ else {
104
+ return;
105
+ }
106
+ }
107
+ catch (err) {
108
+ console.error(err);
109
+ return;
110
+ }
111
+ }
112
+ exports.readTokenFile = readTokenFile;
113
+ async function readAllSignupTokens(rootFolder) {
114
+ const singleUserTokens = [];
115
+ const multiUserTokens = [];
116
+ const tokenIds = await (0, async_fs_node_1.readdir)((0, server_data_folders_1.tokensInRootFolder)(rootFolder));
117
+ for (const tokenId of tokenIds) {
118
+ const ctx = await readTokenFile(rootFolder, tokenId);
119
+ if (!ctx) {
120
+ continue;
121
+ }
122
+ if (ctx.type === 'multi-domain') {
123
+ multiUserTokens.push({ tokenId, ctx });
124
+ }
125
+ else {
126
+ singleUserTokens.push({ tokenId, ctx });
127
+ }
128
+ }
129
+ return { multiUserTokens, singleUserTokens };
130
+ }
131
+ exports.readAllSignupTokens = readAllSignupTokens;
132
+ // XXX external qrencode command can be used to display QR code
133
+ Object.freeze(exports);
@@ -1,6 +1,6 @@
1
- export declare type ByteSource = web3n.ByteSource;
1
+ export type ByteSource = web3n.ByteSource;
2
2
  export declare function wrapByteSourceImplementation(src: ByteSource): ByteSource;
3
- export declare type ByteSink = web3n.ByteSink;
3
+ export type ByteSink = web3n.ByteSink;
4
4
  export declare function wrapByteSinkImplementation(sink: ByteSink): ByteSink;
5
5
  export declare class BytesFIFOBuffer {
6
6
  private queue;
@@ -45,17 +45,17 @@ function wrapByteSinkImplementation(sink) {
45
45
  }
46
46
  exports.wrapByteSinkImplementation = wrapByteSinkImplementation;
47
47
  class BytesFIFOBuffer {
48
- constructor() {
49
- this.queue = [];
50
- this.bytesLen = 0;
51
- Object.seal(this);
52
- }
53
48
  get length() {
54
49
  return this.bytesLen;
55
50
  }
56
51
  get queueLength() {
57
52
  return this.queue.length;
58
53
  }
54
+ constructor() {
55
+ this.queue = [];
56
+ this.bytesLen = 0;
57
+ Object.seal(this);
58
+ }
59
59
  clear() {
60
60
  this.queue = [];
61
61
  this.bytesLen = 0;
@@ -1,6 +1,6 @@
1
1
  export declare const fileExceptionType = "file";
2
2
  export declare const Code: web3n.files.exceptionCode;
3
- export declare type FileException = web3n.files.FileException;
3
+ export type FileException = web3n.files.FileException;
4
4
  export declare function makeFileException(code: string | undefined, path: string, cause?: any): FileException;
5
5
  export declare function maskPathInExc(pathPrefixMaskLen: number, exc: any): FileException;
6
6
  export declare function ensureCorrectFS(fs: web3n.files.FS, type: web3n.files.FSType, writable: boolean): void;
@@ -1,12 +1,12 @@
1
1
  import { Envelope } from '../service-api/ipc-api';
2
2
  export { Envelope, EventEnvelope, EventEndEnvelope, EventException, RequestEnvelope, ReplyEnvelope } from '../service-api/ipc-api';
3
- export declare type RequestHandler<TReq, TRes> = web3n.ipc.RequestHandler<TReq, TRes>;
4
- export declare type RequestingClient = web3n.ipc.RequestingClient;
5
- export declare type RequestServer = web3n.ipc.RequestServer;
6
- export declare type EventfulServer = web3n.ipc.EventfulServer;
7
- export declare type SubscribingClient = web3n.ipc.SubscribingClient;
8
- export declare type Observer<T> = web3n.Observer<T>;
9
- export declare type RawDuplex<T> = web3n.ipc.RawDuplex<T>;
3
+ export type RequestHandler<TReq, TRes> = web3n.ipc.RequestHandler<TReq, TRes>;
4
+ export type RequestingClient = web3n.ipc.RequestingClient;
5
+ export type RequestServer = web3n.ipc.RequestServer;
6
+ export type EventfulServer = web3n.ipc.EventfulServer;
7
+ export type SubscribingClient = web3n.ipc.SubscribingClient;
8
+ export type Observer<T> = web3n.Observer<T>;
9
+ export type RawDuplex<T> = web3n.ipc.RawDuplex<T>;
10
10
  export declare function makeRequestingClient(channel: string | undefined, comm: RawDuplex<Envelope>): RequestingClient;
11
11
  export declare function makeRequestServer(channel: string | undefined, comm: RawDuplex<Envelope>): RequestServer;
12
12
  export declare function makeEventfulServer(channel: string | undefined, comm: RawDuplex<Envelope>): EventfulServer;