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
package/src/Command.js CHANGED
@@ -1,115 +1,136 @@
1
- const {chalk} = require('./utils/Logger')
2
- const Logger = require('./utils/Logger')
3
- const cliConfig = require('./cliConfig')
4
- const PreCommand = require('./PreCommand')
1
+ const { chalk } = require("./utils/Logger");
2
+ const Logger = require("./utils/Logger");
3
+ const cliConfig = require("./cliConfig");
4
+ const PreCommand = require("./PreCommand");
5
5
 
6
6
  class Command extends PreCommand {
7
-
8
7
  constructor(prompt) {
9
- super()
10
- this.prompt = prompt
11
- this.secrez = prompt.secrez
12
- this.optionDefinitions = []
13
- this.cliConfig = cliConfig
14
- this.internalFs = prompt.internalFs
15
- this.externalFs = prompt.externalFs
16
- this.Logger = Logger
17
- this.chalk = chalk
8
+ super();
9
+ this.prompt = prompt;
10
+ this.secrez = prompt.secrez;
11
+ this.optionDefinitions = [];
12
+ this.cliConfig = cliConfig;
13
+ this.internalFs = prompt.internalFs;
14
+ this.externalFs = prompt.externalFs;
15
+ this.Logger = Logger;
16
+ this.chalk = chalk;
18
17
  }
19
18
 
20
- help() {
21
- }
19
+ help() {}
22
20
 
23
21
  showHelp() {
24
- let command = this.constructor.name.toLowerCase()
25
- this.prompt.commands.help.exec({command})
22
+ let command = this.constructor.name.toLowerCase();
23
+ this.prompt.commands.help.exec({ command });
26
24
  }
27
25
 
28
- setHelpAndCompletion() {
29
- }
26
+ setHelpAndCompletion() {}
30
27
 
31
28
  getCompletionType(option) {
32
29
  if (!this.completionTypes) {
33
- this.completionTypes = {}
30
+ this.completionTypes = {};
34
31
  for (let item of this.optionDefinitions) {
35
- this.completionTypes[item.name] = item.completionType
32
+ this.completionTypes[item.name] = item.completionType;
36
33
  }
37
34
  }
38
- return this.completionTypes[option]
35
+ return this.completionTypes[option];
39
36
  }
40
37
 
41
38
  selfCompletion(self, extraOptions = {}) {
42
39
  return async (options, originalLine, currentOption) => {
43
- options = Object.assign(options, extraOptions)
44
- options.forAutoComplete = true
45
- let completionType = this.getCompletionType(currentOption)
40
+ options = Object.assign(options, extraOptions);
41
+ options.forAutoComplete = true;
42
+ let completionType = this.getCompletionType(currentOption);
46
43
  /* istanbul ignore if */
47
44
  if (this.customCompletion) {
48
- let extra = await this.customCompletion(options, originalLine, currentOption)
45
+ let extra = await this.customCompletion(
46
+ options,
47
+ originalLine,
48
+ currentOption
49
+ );
49
50
  if (extra) {
50
- return extra
51
+ return extra;
51
52
  }
52
53
  }
53
- if (completionType === 'dataset') {
54
- let datasetsInfo = await this.internalFs.getDatasetsInfo()
55
- options.forAutoComplete = true
54
+ if (completionType === "dataset") {
55
+ let datasetsInfo = await this.internalFs.getDatasetsInfo();
56
+ options.forAutoComplete = true;
56
57
  if (options.dataset) {
57
- return datasetsInfo.map(e => e.name).filter(e => RegExp('^' + options.dataset).test(e))
58
+ return datasetsInfo
59
+ .map((e) => e.name)
60
+ .filter((e) => RegExp("^" + options.dataset).test(e));
58
61
  } else {
59
- return datasetsInfo.map(e => e.name)
62
+ return datasetsInfo.map((e) => e.name);
60
63
  }
61
64
  }
62
- if ((process.env.NODE_ENV === 'test' && currentOption === 'path')
63
- || completionType === 'file') {
65
+ if (
66
+ (process.env.NODE_ENV === "test" && currentOption === "path") ||
67
+ completionType === "file"
68
+ ) {
64
69
  if (options[currentOption] === null) {
65
- delete options[currentOption]
70
+ delete options[currentOption];
66
71
  }
67
- if (currentOption !== 'path') {
68
- options.path = options[currentOption]
72
+ if (currentOption !== "path") {
73
+ options.path = options[currentOption];
69
74
  }
70
- if (self.prompt.cache && self.prompt.cache.findResult && /^(#|£)\d+$/.test(options.path)) {
71
- return [options.path + self.prompt.cache.findResult[options.path.replace(/^(#|£)/, '')][1] || undefined]
75
+ if (
76
+ self.prompt.cache &&
77
+ self.prompt.cache.findResult &&
78
+ /^(#|£)\d+$/.test(options.path)
79
+ ) {
80
+ return [
81
+ options.path +
82
+ self.prompt.cache.findResult[
83
+ options.path.replace(/^(#|£)/, "")
84
+ ][1] || undefined,
85
+ ];
72
86
  }
73
- return await self.prompt[extraOptions.external ? 'externalFs' : 'internalFs'].getFileList(options, true)
87
+ return await self.prompt[
88
+ extraOptions.external ? "externalFs" : "internalFs"
89
+ ].getFileList(options, true);
74
90
  } else {
75
- return []
91
+ return [];
76
92
  }
77
- }
93
+ };
78
94
  }
79
95
 
80
96
  threeRedDots(large) {
81
- return chalk.cyan(large ? '•••' : '···')
97
+ return chalk.cyan(large ? "•••" : "···");
82
98
  }
83
99
 
84
100
  checkPath(options) {
85
- if (typeof options.path !== 'string' || !options.path) {
86
- throw new Error('A valid path is required')
101
+ if (typeof options.path !== "string" || !options.path) {
102
+ throw new Error("A valid path is required");
87
103
  }
88
104
  }
89
105
 
90
106
  validate(options, mandatoryOptions) {
91
107
  if (options._unknown) {
92
- throw new Error(`Unknown option: ${options._unknown} ` + chalk.grey(`(run "${this.constructor.name.toLowerCase()} -h" for help)`))
108
+ throw new Error(
109
+ `Unknown option: ${options._unknown} ` +
110
+ chalk.grey(
111
+ `(run "${this.constructor.name.toLowerCase()} -h" for help)`
112
+ )
113
+ );
93
114
  }
94
- if (options.path && (/^(#|£)\d+\//.test(options.path) || /^(#|£)\d+\w+:\//.test(options.path))) {
95
- options.path = options.path.replace(/^(#|£)\d+/, '')
115
+ if (
116
+ options.path &&
117
+ (/^(#|£)\d+\//.test(options.path) || /^(#|£)\d+\w+:\//.test(options.path))
118
+ ) {
119
+ options.path = options.path.replace(/^(#|£)\d+/, "");
96
120
  }
97
121
  if (mandatoryOptions) {
98
- let err = ''
99
- let prefix = 'Missing options: '
122
+ let err = "";
123
+ let prefix = "Missing options: ";
100
124
  for (let o in mandatoryOptions) {
101
125
  if (!options[o]) {
102
- err += (err ? ', ' : '') + o
126
+ err += (err ? ", " : "") + o;
103
127
  }
104
128
  }
105
129
  if (err) {
106
- throw new Error(prefix + err)
130
+ throw new Error(prefix + err);
107
131
  }
108
132
  }
109
133
  }
110
-
111
134
  }
112
135
 
113
- module.exports = Command
114
-
115
-
136
+ module.exports = Command;
package/src/PreCommand.js CHANGED
@@ -1,116 +1,120 @@
1
- const {chalk} = require('./utils/Logger')
2
- const Crypto = require('@secrez/crypto')
3
- const {utils: hubUtils} = require('@secrez/hub')
4
- const superagent = require('superagent')
1
+ const { chalk } = require("./utils/Logger");
2
+ const Crypto = require("@secrez/crypto");
3
+ const { utils: hubUtils } = require("@secrez/hub");
4
+ const superagent = require("superagent");
5
5
 
6
6
  class PreCommand {
7
-
8
7
  async useEditor(options) {
9
- let message = 'your OS default editor.'
8
+ let message = "your OS default editor.";
10
9
  if (options.internal) {
11
- message = 'the minimalistic internal editor.'
10
+ message = "the minimalistic internal editor.";
12
11
  } else if (options.editor) {
13
- message = `${options.editor}.`
12
+ message = `${options.editor}.`;
14
13
  }
15
- let extraMessage = chalk.dim('Press <enter> to launch ')
16
- + message
17
- + chalk.reset(
18
- options.internal ? chalk.green('\n Ctrl-d to save the changes. Ctrl-c to abort.') : ''
19
- )
20
- let {result} = await this.prompt.inquirer.prompt([{
21
- type: 'multiEditor',
22
- name: 'result',
23
- message: 'Editing...',
24
- default: options.content,
25
- tempDir: this.cliConfig.tmpPath,
26
- validate: function (text) {
27
- return true
14
+ let extraMessage =
15
+ chalk.dim("Press <enter> to launch ") +
16
+ message +
17
+ chalk.reset(
18
+ options.internal
19
+ ? chalk.green("\n Ctrl-d to save the changes. Ctrl-c to abort.")
20
+ : ""
21
+ );
22
+ let { result } = await this.prompt.inquirer.prompt([
23
+ {
24
+ type: "multiEditor",
25
+ name: "result",
26
+ message: "Editing...",
27
+ default: options.content,
28
+ tempDir: this.cliConfig.tmpPath,
29
+ validate: function (text) {
30
+ return true;
31
+ },
32
+ extraMessage,
28
33
  },
29
- extraMessage
30
- }])
31
- return result
32
-
34
+ ]);
35
+ return result;
33
36
  }
34
37
 
35
-
36
38
  async useSelect(options) {
37
- let cancel = '(cancel)'
39
+ let cancel = "(cancel)";
38
40
  if (!options.dontCancel) {
39
- options.choices = options.choices.concat([cancel])
41
+ options.choices = options.choices.concat([cancel]);
40
42
  }
41
- let {result} = await this.prompt.inquirer.prompt([
43
+ let { result } = await this.prompt.inquirer.prompt([
42
44
  {
43
- type: 'list',
44
- name: 'result',
45
+ type: "list",
46
+ name: "result",
45
47
  message: options.message,
46
- choices: options.choices
47
- }
48
- ])
48
+ choices: options.choices,
49
+ },
50
+ ]);
49
51
  if (result === cancel) {
50
- return
52
+ return;
51
53
  } else {
52
- return result
54
+ return result;
53
55
  }
54
-
55
56
  }
56
57
 
57
58
  async useConfirm(options) {
58
- let {result} = await this.prompt.inquirer.prompt([
59
+ let { result } = await this.prompt.inquirer.prompt([
59
60
  {
60
- type: 'confirm',
61
- name: 'result',
61
+ type: "confirm",
62
+ name: "result",
62
63
  message: options.message,
63
- default: options.default
64
- }
65
- ])
66
- return result
67
-
64
+ default: options.default,
65
+ },
66
+ ]);
67
+ return result;
68
68
  }
69
69
 
70
70
  async useInput(options) {
71
-
72
- let prompt = this.prompt
73
- let exitCode = Crypto.getRandomBase58String(2)
74
- let {result} = await prompt.inquirer.prompt([
71
+ let prompt = this.prompt;
72
+ let exitCode = Crypto.getRandomBase58String(2);
73
+ let { result } = await prompt.inquirer.prompt([
75
74
  {
76
- type: options.type || 'input',
77
- name: 'result',
75
+ type: options.type || "input",
76
+ name: "result",
78
77
  message: options.message,
79
78
  default: options.content,
80
- validate: val => {
79
+ validate: (val) => {
81
80
  if (val) {
82
81
  if (val === exitCode) {
83
- return true
82
+ return true;
84
83
  } else if (options.validate) {
85
- return options.validate(val, exitCode)
84
+ return options.validate(val, exitCode);
86
85
  } else if (val.length) {
87
- return true
86
+ return true;
88
87
  }
89
88
  }
90
- return chalk.grey(`Please, type the ${options.name}, or cancel typing ${chalk.bold(exitCode)}`)
91
- }
92
- }
93
- ])
89
+ return chalk.grey(
90
+ `Please, type the ${options.name}, or cancel typing ${chalk.bold(
91
+ exitCode
92
+ )}`
93
+ );
94
+ },
95
+ },
96
+ ]);
94
97
  if (result !== exitCode) {
95
- return result
98
+ return result;
96
99
  }
97
100
  }
98
101
 
99
102
  async callCourier(_payload, port, caCrt, pathname) {
100
- const {payload, signature} = hubUtils.setPayloadAndSignIt(this.secrez, _payload)
103
+ const { payload, signature } = hubUtils.setPayloadAndSignIt(
104
+ this.secrez,
105
+ _payload
106
+ );
101
107
  try {
102
108
  const res = await superagent
103
- .get(`https://localhost:${port}${pathname || ''}`)
104
- .set('Accept', 'application/json')
105
- .query({payload, signature})[caCrt ? 'ca' : 'trustLocalhost'](caCrt)
106
- return res.body
109
+ .get(`https://localhost:${port}${pathname || ""}`)
110
+ .set("Accept", "application/json")
111
+ .query({ payload, signature })
112
+ [caCrt ? "ca" : "trustLocalhost"](caCrt);
113
+ return res.body;
107
114
  } catch (e) {
108
- return {error: e.message}
115
+ return { error: e.message };
109
116
  }
110
117
  }
111
-
112
118
  }
113
119
 
114
- module.exports = PreCommand
115
-
116
-
120
+ module.exports = PreCommand;