secrez 1.1.1 → 1.1.3
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 +503 -444
- package/bin/secrez.js +50 -47
- package/coverage.report +91 -85
- package/package.json +10 -12
- package/src/Command.js +78 -57
- package/src/PreCommand.js +75 -70
- package/src/Welcome.js +144 -134
- package/src/cliConfig.js +14 -14
- package/src/commands/Alias.js +123 -100
- package/src/commands/Bash.js +10 -12
- package/src/commands/Cat.js +117 -107
- package/src/commands/Cd.js +39 -42
- package/src/commands/Chat.js +75 -63
- package/src/commands/Conf.js +123 -99
- package/src/commands/Contacts.js +189 -171
- package/src/commands/Copy.js +132 -113
- package/src/commands/Courier.js +123 -105
- package/src/commands/Ds.js +88 -76
- package/src/commands/Edit.js +122 -103
- package/src/commands/Export.js +201 -116
- package/src/commands/Find.js +115 -110
- package/src/commands/Help.js +20 -23
- package/src/commands/Import.js +296 -225
- package/src/commands/Lcat.js +36 -39
- package/src/commands/Lcd.js +38 -39
- package/src/commands/Lls.js +58 -55
- package/src/commands/Lpwd.js +20 -24
- package/src/commands/Ls.js +107 -97
- package/src/commands/Mkdir.js +35 -38
- package/src/commands/Mv.js +147 -114
- package/src/commands/Paste.js +68 -65
- package/src/commands/Pwd.js +18 -23
- package/src/commands/Quit.js +22 -24
- package/src/commands/Rm.js +78 -70
- package/src/commands/Shell.js +31 -32
- package/src/commands/Ssh.js +77 -63
- package/src/commands/Tag.js +133 -112
- package/src/commands/Totp.js +166 -136
- package/src/commands/Touch.js +169 -56
- package/src/commands/Use.js +44 -41
- package/src/commands/Ver.js +16 -18
- package/src/commands/Whoami.js +34 -37
- package/src/commands/chat/Contacts.js +41 -44
- package/src/commands/chat/Help.js +20 -23
- package/src/commands/chat/Join.js +59 -55
- package/src/commands/chat/Leave.js +16 -22
- package/src/commands/chat/Quit.js +19 -24
- package/src/commands/chat/Send.js +58 -57
- package/src/commands/chat/Show.js +60 -51
- package/src/commands/chat/Whoami.js +18 -22
- package/src/commands/index.js +20 -22
- package/src/index.js +3 -3
- package/src/prompts/ChatPrompt.js +87 -82
- package/src/prompts/ChatPromptMock.js +11 -17
- package/src/prompts/CommandPrompt.js +146 -138
- package/src/prompts/Completion.js +64 -69
- package/src/prompts/MainPrompt.js +84 -77
- package/src/prompts/MainPromptMock.js +19 -30
- package/src/prompts/MultiEditorPrompt.js +21 -22
- package/src/prompts/SigintManager.js +21 -24
- package/src/utils/AliasManager.js +16 -18
- package/src/utils/ContactManager.js +15 -17
- package/src/utils/Fido2Client.js +59 -49
- package/src/utils/HelpProto.js +130 -117
- package/src/utils/Logger.js +48 -50
- package/.eslintignore +0 -0
- package/.eslintrc +0 -33
- package/.jshintrc +0 -3
@@ -1,90 +1,87 @@
|
|
1
|
-
|
2
|
-
class Contacts extends require('../../Command') {
|
3
|
-
|
1
|
+
class Contacts extends require("../../Command") {
|
4
2
|
setHelpAndCompletion() {
|
5
3
|
this.cliConfig.chatCompletion.contacts = {
|
6
4
|
_func: this.selfCompletion(this),
|
7
|
-
_self: this
|
8
|
-
}
|
9
|
-
this.cliConfig.chatCompletion.help.contacts = true
|
5
|
+
_self: this,
|
6
|
+
};
|
7
|
+
this.cliConfig.chatCompletion.help.contacts = true;
|
10
8
|
this.optionDefinitions = [
|
11
9
|
{
|
12
|
-
name:
|
13
|
-
alias:
|
14
|
-
type: Boolean
|
10
|
+
name: "help",
|
11
|
+
alias: "h",
|
12
|
+
type: Boolean,
|
15
13
|
},
|
16
14
|
{
|
17
|
-
name:
|
18
|
-
alias:
|
15
|
+
name: "list",
|
16
|
+
alias: "l",
|
19
17
|
type: Boolean,
|
20
|
-
default: true
|
18
|
+
default: true,
|
21
19
|
},
|
22
20
|
{
|
23
|
-
name:
|
24
|
-
alias:
|
25
|
-
type: String
|
21
|
+
name: "add",
|
22
|
+
alias: "a",
|
23
|
+
type: String,
|
26
24
|
},
|
27
25
|
{
|
28
|
-
name:
|
29
|
-
alias:
|
30
|
-
type: String
|
26
|
+
name: "update",
|
27
|
+
alias: "u",
|
28
|
+
type: String,
|
31
29
|
},
|
32
30
|
{
|
33
|
-
name:
|
34
|
-
alias:
|
35
|
-
type: String
|
31
|
+
name: "delete",
|
32
|
+
alias: "d",
|
33
|
+
type: String,
|
36
34
|
},
|
37
35
|
{
|
38
|
-
name:
|
39
|
-
alias:
|
36
|
+
name: "rename",
|
37
|
+
alias: "r",
|
40
38
|
type: String,
|
41
|
-
multiple: true
|
39
|
+
multiple: true,
|
42
40
|
},
|
43
41
|
{
|
44
|
-
name:
|
45
|
-
alias:
|
46
|
-
type: String
|
47
|
-
}
|
48
|
-
]
|
42
|
+
name: "show",
|
43
|
+
alias: "s",
|
44
|
+
type: String,
|
45
|
+
},
|
46
|
+
];
|
49
47
|
}
|
50
48
|
|
51
49
|
help() {
|
52
|
-
return this.prompt.environment.prompt.commands.contacts.help()
|
50
|
+
return this.prompt.environment.prompt.commands.contacts.help();
|
53
51
|
}
|
54
52
|
|
55
53
|
async customCompletion(options, originalLine, defaultOption) {
|
56
|
-
return []
|
54
|
+
return [];
|
57
55
|
}
|
58
56
|
|
59
57
|
async contacts(options) {
|
60
|
-
return await this.prompt.environment.prompt.commands.contacts.contacts(
|
58
|
+
return await this.prompt.environment.prompt.commands.contacts.contacts(
|
59
|
+
options
|
60
|
+
);
|
61
61
|
}
|
62
62
|
|
63
63
|
async exec(options = {}) {
|
64
64
|
if (options.help) {
|
65
|
-
return this.showHelp()
|
65
|
+
return this.showHelp();
|
66
66
|
}
|
67
67
|
try {
|
68
68
|
if (!Object.keys(options).length) {
|
69
|
-
options.list = true
|
69
|
+
options.list = true;
|
70
70
|
}
|
71
|
-
this.validate(options)
|
72
|
-
let result = await this.contacts(options)
|
71
|
+
this.validate(options);
|
72
|
+
let result = await this.contacts(options);
|
73
73
|
if (!Array.isArray(result)) {
|
74
|
-
result = [result]
|
74
|
+
result = [result];
|
75
75
|
}
|
76
76
|
for (let r of result) {
|
77
|
-
this.Logger.reset(r)
|
77
|
+
this.Logger.reset(r);
|
78
78
|
}
|
79
|
-
|
80
79
|
} catch (e) {
|
81
80
|
// console.log(e)
|
82
|
-
this.Logger.red(e.message)
|
81
|
+
this.Logger.red(e.message);
|
83
82
|
}
|
84
|
-
await this.prompt.run()
|
83
|
+
await this.prompt.run();
|
85
84
|
}
|
86
85
|
}
|
87
86
|
|
88
|
-
module.exports = Contacts
|
89
|
-
|
90
|
-
|
87
|
+
module.exports = Contacts;
|
@@ -1,51 +1,48 @@
|
|
1
|
-
const HelpProto = require(
|
2
|
-
|
3
|
-
class Help extends require('../../Command') {
|
1
|
+
const HelpProto = require("../../utils/HelpProto");
|
4
2
|
|
3
|
+
class Help extends require("../../Command") {
|
5
4
|
constructor(prompt) {
|
6
|
-
super(prompt)
|
5
|
+
super(prompt);
|
7
6
|
this.proto = new HelpProto({
|
8
7
|
prompt: this.prompt,
|
9
8
|
cliConfig: this.cliConfig,
|
10
9
|
helpDescription: this.helpDescription,
|
11
10
|
completions: this.completion,
|
12
|
-
completionObj:
|
13
|
-
})
|
11
|
+
completionObj: "chatCompletion",
|
12
|
+
});
|
14
13
|
}
|
15
14
|
|
16
15
|
setHelpAndCompletion() {
|
17
16
|
this.optionDefinitions = [
|
18
17
|
{
|
19
|
-
name:
|
20
|
-
alias:
|
18
|
+
name: "command",
|
19
|
+
alias: "c",
|
21
20
|
defaultOption: true,
|
22
|
-
type: String
|
23
|
-
}
|
24
|
-
]
|
21
|
+
type: String,
|
22
|
+
},
|
23
|
+
];
|
25
24
|
}
|
26
25
|
|
27
26
|
help() {
|
28
|
-
return this.proto.help()
|
27
|
+
return this.proto.help();
|
29
28
|
}
|
30
29
|
|
31
30
|
async exec(options = {}) {
|
32
|
-
let help
|
33
|
-
let command = options.command
|
31
|
+
let help;
|
32
|
+
let command = options.command;
|
34
33
|
if (command) {
|
35
34
|
if (this.prompt.commands[command]) {
|
36
|
-
help = this.prompt.commands[command].help()
|
35
|
+
help = this.prompt.commands[command].help();
|
37
36
|
} else {
|
38
|
-
this.Logger.red(
|
39
|
-
return await this.prompt.run()
|
37
|
+
this.Logger.red("Invalid command.");
|
38
|
+
return await this.prompt.run();
|
40
39
|
}
|
41
40
|
} else {
|
42
|
-
help = this.help()
|
41
|
+
help = this.help();
|
43
42
|
}
|
44
|
-
this.proto.format(help, command)
|
45
|
-
await this.prompt.run()
|
43
|
+
this.proto.format(help, command);
|
44
|
+
await this.prompt.run();
|
46
45
|
}
|
47
46
|
}
|
48
47
|
|
49
|
-
module.exports = Help
|
50
|
-
|
51
|
-
|
48
|
+
module.exports = Help;
|
@@ -1,92 +1,98 @@
|
|
1
|
-
const {ConfigUtils} = require(
|
2
|
-
|
3
|
-
class Join extends require('../../Command') {
|
1
|
+
const { ConfigUtils } = require("@secrez/core");
|
4
2
|
|
3
|
+
class Join extends require("../../Command") {
|
5
4
|
setHelpAndCompletion() {
|
6
5
|
this.cliConfig.chatCompletion.join = {
|
7
6
|
_func: this.selfCompletion(this),
|
8
|
-
_self: this
|
9
|
-
}
|
10
|
-
this.cliConfig.chatCompletion.help.join = true
|
7
|
+
_self: this,
|
8
|
+
};
|
9
|
+
this.cliConfig.chatCompletion.help.join = true;
|
11
10
|
this.optionDefinitions = [
|
12
11
|
{
|
13
|
-
name:
|
14
|
-
alias:
|
15
|
-
type: Boolean
|
12
|
+
name: "help",
|
13
|
+
alias: "h",
|
14
|
+
type: Boolean,
|
16
15
|
},
|
17
16
|
{
|
18
|
-
name:
|
19
|
-
alias:
|
17
|
+
name: "chat",
|
18
|
+
alias: "c",
|
20
19
|
defaultOption: true,
|
21
20
|
multiple: true,
|
22
|
-
type: String
|
23
|
-
}
|
24
|
-
]
|
21
|
+
type: String,
|
22
|
+
},
|
23
|
+
];
|
25
24
|
}
|
26
25
|
|
27
26
|
help() {
|
28
27
|
return {
|
29
|
-
description: [
|
28
|
+
description: ["Joins conversation."],
|
30
29
|
examples: [
|
31
|
-
[
|
32
|
-
|
33
|
-
|
30
|
+
[
|
31
|
+
"join pan",
|
32
|
+
'joins a conversation with the previously-added user "pan"',
|
33
|
+
],
|
34
|
+
],
|
35
|
+
};
|
34
36
|
}
|
35
37
|
|
36
38
|
async getAllUsers() {
|
37
|
-
let all = await this.prompt.environment.prompt.commands.contacts.list({})
|
39
|
+
let all = await this.prompt.environment.prompt.commands.contacts.list({});
|
38
40
|
if (all && all.length) {
|
39
|
-
return all.map(e => e[0])
|
41
|
+
return all.map((e) => e[0]);
|
40
42
|
}
|
41
|
-
return []
|
43
|
+
return [];
|
42
44
|
}
|
43
45
|
|
44
46
|
async customCompletion(options, originalLine, currentOption) {
|
45
|
-
const existingUsers = await this.getAllUsers()
|
47
|
+
const existingUsers = await this.getAllUsers();
|
46
48
|
if (options.chat) {
|
47
|
-
let lastUser = options.chat[options.chat.length - 1]
|
48
|
-
return existingUsers.filter(e => {
|
49
|
-
return RegExp(
|
50
|
-
})
|
49
|
+
let lastUser = options.chat[options.chat.length - 1];
|
50
|
+
return existingUsers.filter((e) => {
|
51
|
+
return RegExp("^" + lastUser).test(e);
|
52
|
+
});
|
51
53
|
} else {
|
52
|
-
return existingUsers
|
54
|
+
return existingUsers;
|
53
55
|
}
|
54
56
|
}
|
55
57
|
|
56
58
|
async joinRoom(options) {
|
57
|
-
const existingUsers = await this.getAllUsers({asIs: true})
|
58
|
-
if (typeof options.chat ===
|
59
|
-
options.chat = [options.chat]
|
59
|
+
const existingUsers = await this.getAllUsers({ asIs: true });
|
60
|
+
if (typeof options.chat === "string") {
|
61
|
+
options.chat = [options.chat];
|
60
62
|
}
|
61
63
|
if (options.chat.length > 1) {
|
62
|
-
throw new Error(
|
64
|
+
throw new Error("Multiple chat not supported yet");
|
63
65
|
}
|
64
66
|
if (!existingUsers.includes(options.chat[0])) {
|
65
|
-
throw new Error(
|
67
|
+
throw new Error("Contact not found");
|
66
68
|
}
|
67
|
-
let room = []
|
69
|
+
let room = [];
|
68
70
|
for (let contact of options.chat) {
|
69
|
-
room.push(
|
70
|
-
show
|
71
|
-
|
72
|
-
|
71
|
+
room.push(
|
72
|
+
await this.prompt.environment.prompt.commands.contacts.show({
|
73
|
+
show: contact,
|
74
|
+
asIs: true,
|
75
|
+
})
|
76
|
+
);
|
73
77
|
}
|
74
|
-
this.prompt.environment.room = room
|
75
|
-
this.prompt.start()
|
78
|
+
this.prompt.environment.room = room;
|
79
|
+
this.prompt.start();
|
76
80
|
}
|
77
81
|
|
78
82
|
async join(options) {
|
79
83
|
if (!options.chat) {
|
80
|
-
throw new Error(
|
84
|
+
throw new Error("Missing parameters");
|
81
85
|
} else {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
await this.joinRoom(options)
|
86
|
+
const env = (options.env = await ConfigUtils.getEnv(this.secrez.config));
|
87
|
+
if (env.courier) {
|
88
|
+
await this.prompt.environment.prompt.commands.courier.preInit(options);
|
89
|
+
if (options.ready) {
|
90
|
+
await this.joinRoom(options);
|
87
91
|
if (!this.hint) {
|
88
|
-
this.Logger.grey(
|
89
|
-
|
92
|
+
this.Logger.grey(
|
93
|
+
'In a room, by default, you send messages, but you can also execute commands. If a message looks like a command, for example "join me tonight", disambiguate it by prefixing it with a slash, like "/join me tonight".'
|
94
|
+
);
|
95
|
+
this.hint = true;
|
90
96
|
}
|
91
97
|
}
|
92
98
|
}
|
@@ -95,18 +101,16 @@ class Join extends require('../../Command') {
|
|
95
101
|
|
96
102
|
async exec(options = {}) {
|
97
103
|
if (options.help) {
|
98
|
-
return this.showHelp()
|
104
|
+
return this.showHelp();
|
99
105
|
}
|
100
106
|
try {
|
101
|
-
this.validate(options)
|
102
|
-
await this.join(options)
|
107
|
+
this.validate(options);
|
108
|
+
await this.join(options);
|
103
109
|
} catch (e) {
|
104
|
-
this.Logger.red(e.message)
|
110
|
+
this.Logger.red(e.message);
|
105
111
|
}
|
106
|
-
await this.prompt.run()
|
112
|
+
await this.prompt.run();
|
107
113
|
}
|
108
114
|
}
|
109
115
|
|
110
|
-
module.exports = Join
|
111
|
-
|
112
|
-
|
116
|
+
module.exports = Join;
|
@@ -1,41 +1,35 @@
|
|
1
|
-
|
2
|
-
class Leave extends require('../../Command') {
|
3
|
-
|
1
|
+
class Leave extends require("../../Command") {
|
4
2
|
setHelpAndCompletion() {
|
5
3
|
this.cliConfig.chatCompletion.leave = {
|
6
4
|
_func: this.selfCompletion(this),
|
7
|
-
_self: this
|
8
|
-
}
|
9
|
-
this.cliConfig.chatCompletion.help.leave = true
|
5
|
+
_self: this,
|
6
|
+
};
|
7
|
+
this.cliConfig.chatCompletion.help.leave = true;
|
10
8
|
this.optionDefinitions = [
|
11
9
|
{
|
12
|
-
name:
|
13
|
-
alias:
|
14
|
-
type: Boolean
|
15
|
-
}
|
16
|
-
]
|
10
|
+
name: "help",
|
11
|
+
alias: "h",
|
12
|
+
type: Boolean,
|
13
|
+
},
|
14
|
+
];
|
17
15
|
}
|
18
16
|
|
19
17
|
help() {
|
20
18
|
return {
|
21
|
-
description: [
|
22
|
-
examples: [
|
23
|
-
|
24
|
-
]
|
25
|
-
}
|
19
|
+
description: ["Leaves a room"],
|
20
|
+
examples: ["leave"],
|
21
|
+
};
|
26
22
|
}
|
27
23
|
|
28
24
|
async exec(options = {}) {
|
29
25
|
if (options.help) {
|
30
|
-
return this.showHelp()
|
26
|
+
return this.showHelp();
|
31
27
|
}
|
32
28
|
if (this.prompt.environment.room) {
|
33
|
-
this.prompt.environment.chatPrompt.onBeforeClose()
|
29
|
+
this.prompt.environment.chatPrompt.onBeforeClose();
|
34
30
|
}
|
35
|
-
await this.prompt.run()
|
31
|
+
await this.prompt.run();
|
36
32
|
}
|
37
33
|
}
|
38
34
|
|
39
|
-
module.exports = Leave
|
40
|
-
|
41
|
-
|
35
|
+
module.exports = Leave;
|
@@ -1,44 +1,39 @@
|
|
1
|
-
class Quit extends require(
|
2
|
-
|
1
|
+
class Quit extends require("../../Command") {
|
3
2
|
setHelpAndCompletion() {
|
4
3
|
this.cliConfig.chatCompletion.quit = {
|
5
4
|
_func: this.selfCompletion(this),
|
6
|
-
_self: this
|
7
|
-
}
|
8
|
-
this.cliConfig.chatCompletion.help.quit = true
|
5
|
+
_self: this,
|
6
|
+
};
|
7
|
+
this.cliConfig.chatCompletion.help.quit = true;
|
9
8
|
this.optionDefinitions = [
|
10
9
|
{
|
11
|
-
name:
|
12
|
-
alias:
|
13
|
-
type: Boolean
|
14
|
-
}
|
15
|
-
]
|
10
|
+
name: "help",
|
11
|
+
alias: "h",
|
12
|
+
type: Boolean,
|
13
|
+
},
|
14
|
+
];
|
16
15
|
}
|
17
16
|
|
18
17
|
help() {
|
19
18
|
return {
|
20
|
-
description: [
|
21
|
-
examples: [
|
22
|
-
|
23
|
-
]
|
24
|
-
}
|
19
|
+
description: ["Quits the chat environment"],
|
20
|
+
examples: ["quit"],
|
21
|
+
};
|
25
22
|
}
|
26
23
|
|
27
24
|
async exec(options = {}) {
|
28
25
|
if (options.help) {
|
29
|
-
return this.showHelp()
|
26
|
+
return this.showHelp();
|
30
27
|
}
|
31
28
|
/* istanbul ignore if */
|
32
|
-
if (process.env.NODE_ENV !==
|
33
|
-
await this.prompt.saveHistory()
|
34
|
-
delete this.prompt.environment.chatPrompt
|
35
|
-
await this.prompt.environment.prompt.setSigintPosition()
|
29
|
+
if (process.env.NODE_ENV !== "test") {
|
30
|
+
await this.prompt.saveHistory();
|
31
|
+
delete this.prompt.environment.chatPrompt;
|
32
|
+
await this.prompt.environment.prompt.setSigintPosition();
|
36
33
|
} else {
|
37
|
-
this.Logger.reset(
|
34
|
+
this.Logger.reset("Chat quit");
|
38
35
|
}
|
39
36
|
}
|
40
37
|
}
|
41
38
|
|
42
|
-
module.exports = Quit
|
43
|
-
|
44
|
-
|
39
|
+
module.exports = Quit;
|
@@ -1,98 +1,99 @@
|
|
1
|
-
const superagent = require(
|
2
|
-
const {utils: hubUtils} = require(
|
3
|
-
const {ConfigUtils} = require(
|
4
|
-
|
5
|
-
class Send extends require('../../Command') {
|
1
|
+
const superagent = require("superagent");
|
2
|
+
const { utils: hubUtils } = require("@secrez/hub");
|
3
|
+
const { ConfigUtils } = require("@secrez/core");
|
6
4
|
|
5
|
+
class Send extends require("../../Command") {
|
7
6
|
setHelpAndCompletion() {
|
8
7
|
this.cliConfig.chatCompletion.send = {
|
9
8
|
_func: this.selfCompletion(this),
|
10
|
-
_self: this
|
11
|
-
}
|
12
|
-
this.cliConfig.chatCompletion.help.send = true
|
9
|
+
_self: this,
|
10
|
+
};
|
11
|
+
this.cliConfig.chatCompletion.help.send = true;
|
13
12
|
this.optionDefinitions = [
|
14
13
|
{
|
15
|
-
name:
|
16
|
-
alias:
|
17
|
-
type: Boolean
|
14
|
+
name: "help",
|
15
|
+
alias: "h",
|
16
|
+
type: Boolean,
|
18
17
|
},
|
19
18
|
{
|
20
|
-
name:
|
21
|
-
alias:
|
19
|
+
name: "message",
|
20
|
+
alias: "m",
|
22
21
|
type: String,
|
23
|
-
default: true
|
24
|
-
}
|
25
|
-
]
|
22
|
+
default: true,
|
23
|
+
},
|
24
|
+
];
|
26
25
|
}
|
27
26
|
|
28
27
|
help() {
|
29
28
|
return {
|
30
|
-
description: [
|
31
|
-
examples: [
|
32
|
-
|
33
|
-
]
|
34
|
-
}
|
29
|
+
description: ["Sends either a room or the chat"],
|
30
|
+
examples: ["send"],
|
31
|
+
};
|
35
32
|
}
|
36
33
|
|
37
|
-
async sendMessage
|
38
|
-
const env = options.env = await ConfigUtils.getEnv(this.secrez.config)
|
34
|
+
async sendMessage(options) {
|
35
|
+
const env = (options.env = await ConfigUtils.getEnv(this.secrez.config));
|
39
36
|
if (!env.courier) {
|
40
|
-
throw new Error(
|
37
|
+
throw new Error("Courier configuration not found");
|
41
38
|
}
|
42
|
-
await this.prompt.environment.prompt.commands.courier.preInit(options)
|
39
|
+
await this.prompt.environment.prompt.commands.courier.preInit(options);
|
43
40
|
if (!options.ready) {
|
44
|
-
throw new Error(
|
41
|
+
throw new Error("Connection with the courier lost");
|
45
42
|
}
|
46
43
|
if (!this.prompt.environment.room) {
|
47
|
-
throw new Error(
|
44
|
+
throw new Error("No room active");
|
48
45
|
}
|
49
|
-
let recipient = this.prompt.environment.room[0].publicKey
|
50
|
-
let encryptedMessage = this.secrez.encryptSharedData(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
const {payload:
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
let recipient = this.prompt.environment.room[0].publicKey;
|
47
|
+
let encryptedMessage = this.secrez.encryptSharedData(
|
48
|
+
options.message,
|
49
|
+
recipient
|
50
|
+
);
|
51
|
+
const { payload: payloadMessage, signature: signatureMessage } =
|
52
|
+
hubUtils.setPayloadAndSignIt(this.secrez, {
|
53
|
+
message: encryptedMessage,
|
54
|
+
});
|
55
|
+
const { payload: payload2, signature: signature2 } =
|
56
|
+
hubUtils.setPayloadAndSignIt(this.secrez, {
|
57
|
+
action: {
|
58
|
+
name: "send",
|
59
|
+
recipient,
|
60
|
+
message: {
|
61
|
+
payload: payloadMessage,
|
62
|
+
signature: signatureMessage,
|
63
|
+
},
|
64
|
+
},
|
65
|
+
});
|
66
|
+
return superagent
|
67
|
+
.get(`https://localhost:${env.courier.port}/admin`)
|
68
|
+
.set("Accept", "application/json")
|
69
|
+
.query({ payload: payload2, signature: signature2 })
|
70
|
+
.ca(await env.courier.caCrt);
|
68
71
|
}
|
69
72
|
|
70
73
|
async send(options) {
|
71
74
|
if (options.message) {
|
72
|
-
let res = await this.sendMessage(options)
|
75
|
+
let res = await this.sendMessage(options);
|
73
76
|
if (!res.body.success) {
|
74
|
-
throw new Error(
|
77
|
+
throw new Error("Sending failed :o(");
|
75
78
|
}
|
76
79
|
}
|
77
80
|
}
|
78
81
|
|
79
82
|
async exec(options = {}) {
|
80
83
|
if (options.help) {
|
81
|
-
return this.showHelp()
|
84
|
+
return this.showHelp();
|
82
85
|
}
|
83
86
|
try {
|
84
87
|
if (!this.prompt.environment.room) {
|
85
|
-
throw new Error(
|
88
|
+
throw new Error("You not in a chat room");
|
86
89
|
}
|
87
|
-
this.validate(options)
|
88
|
-
await this.send(options)
|
90
|
+
this.validate(options);
|
91
|
+
await this.send(options);
|
89
92
|
} catch (e) {
|
90
|
-
this.Logger.red(e.message)
|
93
|
+
this.Logger.red(e.message);
|
91
94
|
}
|
92
|
-
await this.prompt.run()
|
95
|
+
await this.prompt.run();
|
93
96
|
}
|
94
97
|
}
|
95
98
|
|
96
|
-
module.exports = Send
|
97
|
-
|
98
|
-
|
99
|
+
module.exports = Send;
|