secrez 1.1.1 → 1.1.2

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 (68) hide show
  1. package/README.md +414 -291
  2. package/bin/secrez.js +50 -47
  3. package/coverage.report +63 -305
  4. package/package.json +10 -12
  5. package/src/Command.js +78 -57
  6. package/src/PreCommand.js +74 -70
  7. package/src/Welcome.js +144 -134
  8. package/src/cliConfig.js +14 -14
  9. package/src/commands/Alias.js +123 -100
  10. package/src/commands/Bash.js +10 -12
  11. package/src/commands/Cat.js +117 -107
  12. package/src/commands/Cd.js +39 -42
  13. package/src/commands/Chat.js +75 -63
  14. package/src/commands/Conf.js +123 -99
  15. package/src/commands/Contacts.js +189 -171
  16. package/src/commands/Copy.js +132 -113
  17. package/src/commands/Courier.js +123 -105
  18. package/src/commands/Ds.js +88 -76
  19. package/src/commands/Edit.js +122 -103
  20. package/src/commands/Export.js +153 -114
  21. package/src/commands/Find.js +115 -110
  22. package/src/commands/Help.js +20 -23
  23. package/src/commands/Import.js +296 -225
  24. package/src/commands/Lcat.js +36 -39
  25. package/src/commands/Lcd.js +38 -39
  26. package/src/commands/Lls.js +58 -55
  27. package/src/commands/Lpwd.js +20 -24
  28. package/src/commands/Ls.js +107 -97
  29. package/src/commands/Mkdir.js +35 -38
  30. package/src/commands/Mv.js +147 -114
  31. package/src/commands/Paste.js +68 -65
  32. package/src/commands/Pwd.js +18 -23
  33. package/src/commands/Quit.js +22 -24
  34. package/src/commands/Rm.js +78 -70
  35. package/src/commands/Shell.js +31 -32
  36. package/src/commands/Ssh.js +77 -63
  37. package/src/commands/Tag.js +133 -112
  38. package/src/commands/Totp.js +166 -136
  39. package/src/commands/Touch.js +169 -56
  40. package/src/commands/Use.js +44 -41
  41. package/src/commands/Ver.js +16 -18
  42. package/src/commands/Whoami.js +34 -37
  43. package/src/commands/chat/Contacts.js +41 -44
  44. package/src/commands/chat/Help.js +20 -23
  45. package/src/commands/chat/Join.js +59 -55
  46. package/src/commands/chat/Leave.js +16 -22
  47. package/src/commands/chat/Quit.js +19 -24
  48. package/src/commands/chat/Send.js +58 -57
  49. package/src/commands/chat/Show.js +60 -51
  50. package/src/commands/chat/Whoami.js +18 -22
  51. package/src/commands/index.js +20 -22
  52. package/src/index.js +3 -3
  53. package/src/prompts/ChatPrompt.js +87 -82
  54. package/src/prompts/ChatPromptMock.js +11 -17
  55. package/src/prompts/CommandPrompt.js +146 -138
  56. package/src/prompts/Completion.js +64 -69
  57. package/src/prompts/MainPrompt.js +84 -77
  58. package/src/prompts/MainPromptMock.js +19 -30
  59. package/src/prompts/MultiEditorPrompt.js +21 -22
  60. package/src/prompts/SigintManager.js +21 -24
  61. package/src/utils/AliasManager.js +16 -18
  62. package/src/utils/ContactManager.js +15 -17
  63. package/src/utils/Fido2Client.js +59 -49
  64. package/src/utils/HelpProto.js +130 -117
  65. package/src/utils/Logger.js +48 -50
  66. package/.eslintignore +0 -0
  67. package/.eslintrc +0 -33
  68. 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: 'help',
13
- alias: 'h',
14
- type: Boolean
10
+ name: "help",
11
+ alias: "h",
12
+ type: Boolean,
15
13
  },
16
14
  {
17
- name: 'list',
18
- alias: 'l',
15
+ name: "list",
16
+ alias: "l",
19
17
  type: Boolean,
20
- default: true
18
+ default: true,
21
19
  },
22
20
  {
23
- name: 'add',
24
- alias: 'a',
25
- type: String
21
+ name: "add",
22
+ alias: "a",
23
+ type: String,
26
24
  },
27
25
  {
28
- name: 'update',
29
- alias: 'u',
30
- type: String
26
+ name: "update",
27
+ alias: "u",
28
+ type: String,
31
29
  },
32
30
  {
33
- name: 'delete',
34
- alias: 'd',
35
- type: String
31
+ name: "delete",
32
+ alias: "d",
33
+ type: String,
36
34
  },
37
35
  {
38
- name: 'rename',
39
- alias: 'r',
36
+ name: "rename",
37
+ alias: "r",
40
38
  type: String,
41
- multiple: true
39
+ multiple: true,
42
40
  },
43
41
  {
44
- name: 'show',
45
- alias: 's',
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(options)
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('../../utils/HelpProto')
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: 'chatCompletion'
13
- })
11
+ completionObj: "chatCompletion",
12
+ });
14
13
  }
15
14
 
16
15
  setHelpAndCompletion() {
17
16
  this.optionDefinitions = [
18
17
  {
19
- name: 'command',
20
- alias: 'c',
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('Invalid command.')
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('@secrez/core')
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: 'help',
14
- alias: 'h',
15
- type: Boolean
12
+ name: "help",
13
+ alias: "h",
14
+ type: Boolean,
16
15
  },
17
16
  {
18
- name: 'chat',
19
- alias: 'c',
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: ['Joins conversation.'],
28
+ description: ["Joins conversation."],
30
29
  examples: [
31
- ['join pan', 'joins a conversation with the previously-added user "pan"']
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('^' + lastUser).test(e)
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 === 'string') {
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('Multiple chat not supported yet')
64
+ throw new Error("Multiple chat not supported yet");
63
65
  }
64
66
  if (!existingUsers.includes(options.chat[0])) {
65
- throw new Error('Contact not found')
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(await this.prompt.environment.prompt.commands.contacts.show({
70
- show: contact,
71
- asIs: true
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('Missing parameters')
84
+ throw new Error("Missing parameters");
81
85
  } else {
82
- const env = options.env = await ConfigUtils.getEnv(this.secrez.config)
83
- if (env.courier) {
84
- await this.prompt.environment.prompt.commands.courier.preInit(options)
85
- if (options.ready) {
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('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".')
89
- this.hint = true
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: 'help',
13
- alias: 'h',
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: ['Leaves a room'],
22
- examples: [
23
- 'leave'
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('../../Command') {
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: 'help',
12
- alias: 'h',
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: ['Quits the chat environment'],
21
- examples: [
22
- 'quit'
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 !== 'test') {
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('Chat quit')
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('superagent')
2
- const {utils: hubUtils} = require('@secrez/hub')
3
- const {ConfigUtils} = require('@secrez/core')
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: 'help',
16
- alias: 'h',
17
- type: Boolean
14
+ name: "help",
15
+ alias: "h",
16
+ type: Boolean,
18
17
  },
19
18
  {
20
- name: 'message',
21
- alias: 'm',
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: ['Sends either a room or the chat'],
31
- examples: [
32
- 'send'
33
- ]
34
- }
29
+ description: ["Sends either a room or the chat"],
30
+ examples: ["send"],
31
+ };
35
32
  }
36
33
 
37
- async sendMessage (options) {
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('Courier configuration not found')
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('Connection with the courier lost')
41
+ throw new Error("Connection with the courier lost");
45
42
  }
46
43
  if (!this.prompt.environment.room) {
47
- throw new Error('No room active')
44
+ throw new Error("No room active");
48
45
  }
49
- let recipient = this.prompt.environment.room[0].publicKey
50
- let encryptedMessage = this.secrez.encryptSharedData(options.message, recipient)
51
- const {payload: payloadMessage, signature: signatureMessage} = hubUtils.setPayloadAndSignIt(this.secrez, {
52
- message: encryptedMessage
53
- })
54
- const {payload: payload2, signature: signature2} = hubUtils.setPayloadAndSignIt(this.secrez, {
55
- action: {
56
- name: 'send',
57
- recipient,
58
- message: {
59
- payload: payloadMessage,
60
- signature: signatureMessage
61
- }
62
- }
63
- })
64
- return superagent.get(`https://localhost:${env.courier.port}/admin`)
65
- .set('Accept', 'application/json')
66
- .query({payload: payload2, signature: signature2})
67
- .ca(await env.courier.caCrt)
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('Sending failed :o(')
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('You not in a chat room')
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;