secrez 1.1.0 → 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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +414 -291
  3. package/bin/secrez.js +50 -47
  4. package/coverage.report +81 -0
  5. package/package.json +18 -20
  6. package/src/Command.js +78 -57
  7. package/src/PreCommand.js +74 -70
  8. package/src/Welcome.js +144 -134
  9. package/src/cliConfig.js +14 -14
  10. package/src/commands/Alias.js +123 -100
  11. package/src/commands/Bash.js +10 -12
  12. package/src/commands/Cat.js +117 -107
  13. package/src/commands/Cd.js +39 -42
  14. package/src/commands/Chat.js +75 -63
  15. package/src/commands/Conf.js +123 -99
  16. package/src/commands/Contacts.js +189 -171
  17. package/src/commands/Copy.js +132 -113
  18. package/src/commands/Courier.js +123 -105
  19. package/src/commands/Ds.js +88 -76
  20. package/src/commands/Edit.js +122 -103
  21. package/src/commands/Export.js +153 -114
  22. package/src/commands/Find.js +115 -110
  23. package/src/commands/Help.js +20 -23
  24. package/src/commands/Import.js +296 -225
  25. package/src/commands/Lcat.js +36 -39
  26. package/src/commands/Lcd.js +38 -39
  27. package/src/commands/Lls.js +58 -55
  28. package/src/commands/Lpwd.js +20 -24
  29. package/src/commands/Ls.js +107 -97
  30. package/src/commands/Mkdir.js +35 -38
  31. package/src/commands/Mv.js +147 -114
  32. package/src/commands/Paste.js +68 -65
  33. package/src/commands/Pwd.js +18 -23
  34. package/src/commands/Quit.js +22 -24
  35. package/src/commands/Rm.js +78 -70
  36. package/src/commands/Shell.js +31 -32
  37. package/src/commands/Ssh.js +77 -63
  38. package/src/commands/Tag.js +133 -112
  39. package/src/commands/Totp.js +166 -136
  40. package/src/commands/Touch.js +169 -56
  41. package/src/commands/Use.js +44 -41
  42. package/src/commands/Ver.js +16 -18
  43. package/src/commands/Whoami.js +34 -37
  44. package/src/commands/chat/Contacts.js +41 -44
  45. package/src/commands/chat/Help.js +20 -23
  46. package/src/commands/chat/Join.js +59 -55
  47. package/src/commands/chat/Leave.js +16 -22
  48. package/src/commands/chat/Quit.js +19 -24
  49. package/src/commands/chat/Send.js +58 -57
  50. package/src/commands/chat/Show.js +60 -51
  51. package/src/commands/chat/Whoami.js +18 -22
  52. package/src/commands/index.js +20 -22
  53. package/src/index.js +3 -3
  54. package/src/prompts/ChatPrompt.js +87 -82
  55. package/src/prompts/ChatPromptMock.js +11 -17
  56. package/src/prompts/CommandPrompt.js +146 -138
  57. package/src/prompts/Completion.js +64 -69
  58. package/src/prompts/MainPrompt.js +84 -77
  59. package/src/prompts/MainPromptMock.js +19 -30
  60. package/src/prompts/MultiEditorPrompt.js +21 -22
  61. package/src/prompts/SigintManager.js +21 -24
  62. package/src/utils/AliasManager.js +16 -18
  63. package/src/utils/ContactManager.js +15 -17
  64. package/src/utils/Fido2Client.js +59 -49
  65. package/src/utils/HelpProto.js +130 -117
  66. package/src/utils/Logger.js +48 -50
  67. package/.eslintignore +0 -0
  68. package/.eslintrc +0 -33
  69. package/.jshintrc +0 -3
@@ -1,72 +1,69 @@
1
- const utils = require('@secrez/utils')
2
- const fs = require('fs-extra')
3
-
4
- class Lcat extends require('../Command') {
1
+ const utils = require("@secrez/utils");
2
+ const fs = require("fs-extra");
5
3
 
4
+ class Lcat extends require("../Command") {
6
5
  setHelpAndCompletion() {
7
6
  this.cliConfig.completion.lcat = {
8
7
  _func: this.selfCompletion(this, {
9
- external: true
8
+ external: true,
10
9
  }),
11
- _self: this
12
- }
13
- this.cliConfig.completion.help.lcat = true
10
+ _self: this,
11
+ };
12
+ this.cliConfig.completion.help.lcat = true;
14
13
  this.optionDefinitions = [
15
14
  {
16
- name: 'help',
17
- alias: 'h',
18
- type: Boolean
15
+ name: "help",
16
+ alias: "h",
17
+ type: Boolean,
19
18
  },
20
19
  {
21
- name: 'path',
22
- completionType: 'file',
23
- alias: 'p',
20
+ name: "path",
21
+ completionType: "file",
22
+ alias: "p",
24
23
  defaultOption: true,
25
- type: String
24
+ type: String,
26
25
  },
27
26
  {
28
- name: 'force',
29
- alias: 'f',
30
- type: Boolean
31
- }
32
- ]
27
+ name: "force",
28
+ alias: "f",
29
+ type: Boolean,
30
+ },
31
+ ];
33
32
  }
34
33
 
35
34
  help() {
36
35
  return {
37
- description: ['Similar to a standard cat in the external fs.'],
36
+ description: ["Similar to a standard cat in the external fs."],
38
37
  examples: [
39
- 'lcat ../passwords/Facebook',
40
- ['lcat -f somefile.ext', 'Force view even if file looks binary']
41
- ]
42
- }
38
+ "lcat ../passwords/Facebook",
39
+ ["lcat -f somefile.ext", "Force view even if file looks binary"],
40
+ ],
41
+ };
43
42
  }
44
43
 
45
44
  async lcat(options) {
46
- let efs = this.externalFs
47
- let p = efs.getNormalizedPath(options.path)
48
- if (!options.force && await utils.isBinary(p)) {
49
- throw new Error('The file looks as a binary file')
45
+ let efs = this.externalFs;
46
+ let p = efs.getNormalizedPath(options.path);
47
+ if (!options.force && (await utils.isBinary(p))) {
48
+ throw new Error("The file looks as a binary file");
50
49
  } else {
51
- return await fs.readFile(p, 'utf8')
50
+ return await fs.readFile(p, "utf8");
52
51
  }
53
52
  }
54
53
 
55
54
  async exec(options = {}) {
56
55
  if (options.help) {
57
- return this.showHelp()
56
+ return this.showHelp();
58
57
  }
59
58
  try {
60
- this.validate(options)
61
- let data = await this.lcat(options)
62
- this.Logger.reset(data)
59
+ this.validate(options);
60
+ let data = await this.lcat(options);
61
+ this.Logger.reset(data);
63
62
  } catch (e) {
64
- this.Logger.red(e.message)
63
+ this.Logger.red(e.message);
65
64
  }
66
- await this.prompt.run()
65
+ await this.prompt.run();
67
66
  }
68
67
  }
69
68
 
70
- module.exports = Lcat
71
-
72
-
69
+ module.exports = Lcat;
@@ -1,77 +1,76 @@
1
- class Lcd extends require('../Command') {
2
-
1
+ class Lcd extends require("../Command") {
3
2
  setHelpAndCompletion() {
4
3
  this.cliConfig.completion.lcd = {
5
4
  _func: this.selfCompletion(this, {
6
5
  external: true,
7
6
  all: true,
8
- dironly: true
7
+ dironly: true,
9
8
  }),
10
- _self: this
11
- }
12
- this.cliConfig.completion.help.lcd = true
9
+ _self: this,
10
+ };
11
+ this.cliConfig.completion.help.lcd = 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: 'path',
21
- completionType: 'file',
22
- alias: 'p',
19
+ name: "path",
20
+ completionType: "file",
21
+ alias: "p",
23
22
  defaultOption: true,
24
23
  type: String,
25
- defaultValue: '/'
26
- }
27
- ]
24
+ defaultValue: "/",
25
+ },
26
+ ];
28
27
  }
29
28
 
30
29
  help() {
31
30
  return {
32
- description: ['Changes the external working directory.',
33
- 'Secrez refers to external when refers to unencrypted standard files in the OS.'
31
+ description: [
32
+ "Changes the external working directory.",
33
+ "Secrez refers to external when refers to unencrypted standard files in the OS.",
34
34
  ],
35
35
  examples: [
36
- 'lcd ~/Downloads',
37
- ['lcd', 'change to home dir, like "lcd ~"'],
38
- 'lcd /var/nginx/log',
39
- ]
40
- }
36
+ "lcd ~/Downloads",
37
+ ["lcd", 'change to home dir, like "lcd ~"'],
38
+ "lcd /var/nginx/log",
39
+ ],
40
+ };
41
41
  }
42
42
 
43
43
  async lcd(options) {
44
- let dir = options.path
44
+ let dir = options.path;
45
45
  if (!this.externalFs.initialLocalWorkingDir) {
46
- this.externalFs.initialLocalWorkingDir = this.secrez.config.localWorkingDir
46
+ this.externalFs.initialLocalWorkingDir =
47
+ this.secrez.config.localWorkingDir;
47
48
  }
48
- if (/^~\//.test(dir) || dir === '~') {
49
- dir = dir.replace(/^~/, this.externalFs.initialLocalWorkingDir)
49
+ if (/^~\//.test(dir) || dir === "~") {
50
+ dir = dir.replace(/^~/, this.externalFs.initialLocalWorkingDir);
50
51
  }
51
- dir = this.externalFs.getNormalizedPath(dir)
52
+ dir = this.externalFs.getNormalizedPath(dir);
52
53
  if (await this.externalFs.isDir(dir)) {
53
- this.secrez.config.localWorkingDir = dir
54
+ this.secrez.config.localWorkingDir = dir;
54
55
  } else {
55
- throw new Error('No such directory')
56
+ throw new Error("No such directory");
56
57
  }
57
58
  }
58
59
 
59
60
  async exec(options = {}) {
60
61
  if (options.help) {
61
- return this.showHelp()
62
+ return this.showHelp();
62
63
  }
63
64
  try {
64
- this.validate(options)
65
- options.all = true
66
- options.dironly = true
67
- await this.lcd(options)
65
+ this.validate(options);
66
+ options.all = true;
67
+ options.dironly = true;
68
+ await this.lcd(options);
68
69
  } catch (e) {
69
- this.Logger.red(e.message)
70
+ this.Logger.red(e.message);
70
71
  }
71
- await this.prompt.run()
72
+ await this.prompt.run();
72
73
  }
73
74
  }
74
75
 
75
- module.exports = Lcd
76
-
77
-
76
+ module.exports = Lcd;
@@ -1,100 +1,103 @@
1
- const {FsUtils} = require('@secrez/fs')
2
-
3
- class Lls extends require('../Command') {
1
+ const { FsUtils } = require("@secrez/fs");
4
2
 
3
+ class Lls extends require("../Command") {
5
4
  setHelpAndCompletion() {
6
5
  this.cliConfig.completion.lls = {
7
6
  _func: this.selfCompletion(this, {
8
- external: true
7
+ external: true,
9
8
  }),
10
- _self: this
11
- }
12
- this.cliConfig.completion.help.lls = true
9
+ _self: this,
10
+ };
11
+ this.cliConfig.completion.help.lls = 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: 'path',
21
- completionType: 'file',
22
- alias: 'p',
19
+ name: "path",
20
+ completionType: "file",
21
+ alias: "p",
23
22
  defaultOption: true,
24
- type: String
23
+ type: String,
25
24
  },
26
25
  {
27
- name: 'list',
28
- alias: 'l',
29
- type: Boolean
26
+ name: "list",
27
+ alias: "l",
28
+ type: Boolean,
30
29
  },
31
30
  {
32
- name: 'all', // includes hidden files
33
- alias: 'a',
34
- type: Boolean
31
+ name: "all", // includes hidden files
32
+ alias: "a",
33
+ type: Boolean,
35
34
  },
36
35
  {
37
- name: 'dironly', // has priority on fileonly
38
- alias: 'd',
39
- type: Boolean
36
+ name: "dironly", // has priority on fileonly
37
+ alias: "d",
38
+ type: Boolean,
40
39
  },
41
40
  {
42
- name: 'fileonly',
43
- alias: 'f',
44
- type: Boolean
45
- }
46
- ]
41
+ name: "fileonly",
42
+ alias: "f",
43
+ type: Boolean,
44
+ },
45
+ ];
47
46
  }
48
47
 
49
48
  help() {
50
49
  return {
51
- description: ['Browses the external directories.',
52
- 'This is a quick command. Alternatively, you can run commands like',
53
- ' shell "ls -la"'
50
+ description: [
51
+ "Browses the external directories.",
52
+ "This is a quick command. Alternatively, you can run commands like",
53
+ ' shell "ls -la"',
54
54
  ],
55
55
  examples: [
56
- 'lls coin',
57
- 'lls -l ../passwords',
58
- 'lls ~',
59
- ['lls -a', 'Shows all the file, included hidden ones']
60
- ]
61
- }
56
+ "lls coin",
57
+ "lls -l ../passwords",
58
+ "lls ~",
59
+ ["lls -a", "Shows all the file, included hidden ones"],
60
+ ],
61
+ };
62
62
  }
63
63
 
64
64
  async lls(options) {
65
- options.returnIsDir = true
66
- let [isDir, list] = await this.externalFs.fileList(options)
65
+ options.returnIsDir = true;
66
+ let [isDir, list] = await this.externalFs.fileList(options);
67
67
  if (!isDir) {
68
- list = await FsUtils.filterLs(options, list)
68
+ list = await FsUtils.filterLs(options, list);
69
69
  }
70
- return list
70
+ return list;
71
71
  }
72
72
 
73
73
  async exec(options = {}) {
74
74
  if (options.help) {
75
- return this.showHelp()
75
+ return this.showHelp();
76
76
  }
77
77
  try {
78
- this.validate(options)
79
- let list = await this.lls(options)
78
+ this.validate(options);
79
+ let list = await this.lls(options);
80
80
  if (list) {
81
81
  if (list.length) {
82
- this.Logger.reset(options.list
83
- ? list.join('\n')
84
- : this.prompt.commandPrompt.formatList(list, 26, true, this.threeRedDots())
85
- )
82
+ this.Logger.reset(
83
+ options.list
84
+ ? list.join("\n")
85
+ : this.prompt.commandPrompt.formatList(
86
+ list,
87
+ 26,
88
+ true,
89
+ this.threeRedDots()
90
+ )
91
+ );
86
92
  } else {
87
- this.Logger.yellow('-- no files found --')
93
+ this.Logger.yellow("-- no files found --");
88
94
  }
89
95
  }
90
96
  } catch (e) {
91
- this.Logger.red(e.message)
97
+ this.Logger.red(e.message);
92
98
  }
93
- await this.prompt.run()
99
+ await this.prompt.run();
94
100
  }
95
101
  }
96
102
 
97
- module.exports = Lls
98
-
99
-
100
-
103
+ module.exports = Lls;
@@ -1,46 +1,42 @@
1
- class Lpwd extends require('../Command') {
2
-
1
+ class Lpwd extends require("../Command") {
3
2
  setHelpAndCompletion() {
4
- this.cliConfig.completion.lpwd = {}
5
- this.cliConfig.completion.help.lpwd = true
3
+ this.cliConfig.completion.lpwd = {};
4
+ this.cliConfig.completion.help.lpwd = true;
6
5
  this.optionDefinitions = [
7
6
  {
8
- name: 'help',
9
- alias: 'h',
10
- type: Boolean
11
- }
12
- ]
7
+ name: "help",
8
+ alias: "h",
9
+ type: Boolean,
10
+ },
11
+ ];
13
12
  }
14
13
 
15
14
  help() {
16
15
  return {
17
- description: ['Shows the path of the external working directory.',
18
- 'Secrez refers to external when refers to unencrypted standard files in the OS.'
16
+ description: [
17
+ "Shows the path of the external working directory.",
18
+ "Secrez refers to external when refers to unencrypted standard files in the OS.",
19
19
  ],
20
- examples: [
21
- 'lpwd'
22
- ]
23
- }
20
+ examples: ["lpwd"],
21
+ };
24
22
  }
25
23
 
26
24
  async lpwd() {
27
- return this.secrez.config.localWorkingDir
25
+ return this.secrez.config.localWorkingDir;
28
26
  }
29
27
 
30
28
  async exec(options = {}) {
31
29
  if (options.help) {
32
- return this.showHelp()
30
+ return this.showHelp();
33
31
  }
34
32
  try {
35
- this.validate(options)
36
- this.Logger.reset(await this.lpwd())
33
+ this.validate(options);
34
+ this.Logger.reset(await this.lpwd());
37
35
  } catch (e) {
38
- this.Logger.red(e.message)
36
+ this.Logger.red(e.message);
39
37
  }
40
- await this.prompt.run()
38
+ await this.prompt.run();
41
39
  }
42
40
  }
43
41
 
44
- module.exports = Lpwd
45
-
46
-
42
+ module.exports = Lpwd;