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,131 +1,138 @@
1
- const chalk = require('chalk')
2
- const _ = require('lodash')
3
- const path = require('path')
4
- const {InternalFs, ExternalFs, DataCache} = require('@secrez/fs')
5
- const Logger = require('../utils/Logger')
6
- const cliConfig = require('../cliConfig')
7
- const Commands = require('../commands')
8
- const welcome = require('../Welcome')
9
- const AliasManager = require('../utils/AliasManager')
10
- const ContactManager = require('../utils/ContactManager')
11
-
12
- class MainPrompt extends require('./CommandPrompt') {
1
+ const chalk = require("chalk");
2
+ const _ = require("lodash");
3
+ const path = require("path");
4
+ const { InternalFs, ExternalFs, DataCache } = require("@secrez/fs");
5
+ const Logger = require("../utils/Logger");
6
+ const cliConfig = require("../cliConfig");
7
+ const Commands = require("../commands");
8
+ const welcome = require("../Welcome");
9
+ const AliasManager = require("../utils/AliasManager");
10
+ const ContactManager = require("../utils/ContactManager");
13
11
 
12
+ class MainPrompt extends require("./CommandPrompt") {
14
13
  async init(options) {
15
- this.secrez = new (require('@secrez/core').Secrez())
16
- await this.secrez.init(options.container, options.localDir)
17
- this.secrez.cache = new DataCache(path.join(this.secrez.config.container, 'cache'), this.secrez)
18
- this.secrez.cache.initEncryption('alias', 'contact')
19
- await this.secrez.cache.load('id')
20
- this.internalFs = new InternalFs(this.secrez)
21
- this.externalFs = new ExternalFs(this.secrez)
14
+ this.secrez = new (require("@secrez/core").Secrez())();
15
+ await this.secrez.init(options.container, options.localDir);
16
+ this.secrez.cache = new DataCache(
17
+ path.join(this.secrez.config.container, "cache"),
18
+ this.secrez
19
+ );
20
+ this.secrez.cache.initEncryption("alias", "contact");
21
+ await this.secrez.cache.load("id");
22
+ this.internalFs = new InternalFs(this.secrez);
23
+ this.externalFs = new ExternalFs(this.secrez);
22
24
  this.getReady({
23
25
  historyPath: this.secrez.config.historyPath,
24
- completion: 'completion',
25
- commands: (new Commands(this, cliConfig)).getCommands()
26
- })
27
- this.cache = {}
26
+ completion: "completion",
27
+ commands: new Commands(this, cliConfig).getCommands(),
28
+ });
29
+ this.cache = {};
28
30
  }
29
31
 
30
32
  async preRun(options = {}) {
31
33
  if (!this.loggedIn) {
32
- await welcome.start(this.secrez, options)
33
- this.startSigintManager()
34
- this.internalFs.init().then(() => delete this.showLoading)
35
- this.loadingMessage = 'Initializing'
36
- await this.loading()
37
- await this.loadSavedHistory()
38
- this.loggedIn = true
39
- let alerts = this.internalFs.tree.alerts
34
+ await welcome.start(this.secrez, options);
35
+ this.startSigintManager();
36
+ this.internalFs.init().then(() => delete this.showLoading);
37
+ this.loadingMessage = "Initializing";
38
+ await this.loading();
39
+ await this.loadSavedHistory();
40
+ this.loggedIn = true;
41
+ let alerts = this.internalFs.tree.alerts;
40
42
  if (alerts.length) {
41
- Logger.red(alerts[0])
42
- Logger.cyan(alerts.slice(1).join('\n'))
43
+ Logger.red(alerts[0]);
44
+ Logger.cyan(alerts.slice(1).join("\n"));
43
45
  }
44
- await this.secrez.cache.load('alias')
45
- await this.secrez.cache.load('contact')
46
- this.aliasManager = new AliasManager(this.secrez.cache)
47
- this.contactManager = new ContactManager(this.secrez.cache)
46
+ await this.secrez.cache.load("alias");
47
+ await this.secrez.cache.load("contact");
48
+ this.aliasManager = new AliasManager(this.secrez.cache);
49
+ this.contactManager = new ContactManager(this.secrez.cache);
48
50
  }
49
51
  }
50
52
 
51
53
  setCache(name, index, content) {
52
54
  if (!this.cache[name]) {
53
- this.resetCache(name)
55
+ this.resetCache(name);
54
56
  }
55
- this.cache[name][index] = content
57
+ this.cache[name][index] = content;
56
58
  }
57
59
 
58
60
  resetCache(name) {
59
- this.cache[name] = {}
61
+ this.cache[name] = {};
60
62
  }
61
63
 
62
64
  getCache(name, index) {
63
65
  if (!this.cache[name]) {
64
- return null
66
+ return null;
65
67
  }
66
- if (typeof index !== 'undefined') {
67
- return this.cache[name][index]
68
+ if (typeof index !== "undefined") {
69
+ return this.cache[name][index];
68
70
  } else {
69
- return this.cache[name]
71
+ return this.cache[name];
70
72
  }
71
73
  }
72
74
 
73
75
  prePromptMessage(options = {}) {
74
- return chalk.reset(`Secrez ${this.internalFs.tree.name}:${this.internalFs.tree.workingNode.getPath()}`)
76
+ return chalk.reset(
77
+ `Secrez ${
78
+ this.internalFs.tree.name
79
+ }:${this.internalFs.tree.workingNode.getPath()}`
80
+ );
75
81
  }
76
82
 
77
83
  async postRun(options = {}) {
78
- let cmd = options.cmd
79
- let components = cmd.split(' ')
80
- let command = components[0]
84
+ let cmd = options.cmd;
85
+ let components = cmd.split(" ");
86
+ let command = components[0];
81
87
  /* istanbul ignore if */
82
88
  if (!this.basicCommands.includes(command)) {
83
- command = command.replace(/^\//, '')
84
- let data = this.aliasManager.get(command)
89
+ command = command.replace(/^\//, "");
90
+ let data = this.aliasManager.get(command);
85
91
  if (data) {
86
- let cmds = data.content.split('&&').map(e => _.trim(e))
87
- let max = 0
88
- let missing = false
92
+ let cmds = data.content.split("&&").map((e) => _.trim(e));
93
+ let max = 0;
94
+ let missing = false;
89
95
  for (let i = 0; i < cmds.length; i++) {
90
- let c = cmds[i]
91
- let params = c.match(/\$\w{1}/g)
96
+ let c = cmds[i];
97
+ let params = c.match(/\$\w{1}/g);
92
98
  if (params) {
93
99
  for (let p of params) {
94
- let num = parseInt(p.substring(1))
95
- max = Math.max(max, num)
96
- let option = components[num]
100
+ let num = parseInt(p.substring(1));
101
+ max = Math.max(max, num);
102
+ let option = components[num];
97
103
  if (!option) {
98
- missing = true
104
+ missing = true;
99
105
  }
100
- c = c.replace(RegExp('\\$' + num), option)
106
+ c = c.replace(RegExp("\\$" + num), option);
101
107
  }
102
108
  }
103
109
  if (!missing) {
104
- Logger.green('>> ' + chalk.bold.grey(c))
105
- this.disableRun = i !== cmds.length - 1
106
- await this.exec([c])
110
+ Logger.green(">> " + chalk.bold.grey(c));
111
+ this.disableRun = i !== cmds.length - 1;
112
+ await this.exec([c]);
107
113
  if (i === cmds.length - 1) {
108
- return
114
+ return;
109
115
  }
110
116
  }
111
117
  }
112
118
  if (missing) {
113
- Logger.red(`The alias "${command}" requires ${max} parameter${max > 1 ? 's' : ''}`)
114
- this.disableRun = false
119
+ Logger.red(
120
+ `The alias "${command}" requires ${max} parameter${
121
+ max > 1 ? "s" : ""
122
+ }`
123
+ );
124
+ this.disableRun = false;
115
125
  }
116
- this.run()
117
- return
126
+ this.run();
127
+ return;
118
128
  }
119
- Logger.red('Command not found')
120
- this.run()
121
- return
129
+ Logger.red("Command not found");
130
+ this.run();
131
+ return;
122
132
  }
123
- await this.exec([cmd])
124
- this.previousCommandLine = cmd
125
-
133
+ await this.exec([cmd]);
134
+ this.previousCommandLine = cmd;
126
135
  }
127
-
128
136
  }
129
137
 
130
- module.exports = MainPrompt
131
-
138
+ module.exports = MainPrompt;
@@ -1,43 +1,32 @@
1
- const path = require('path')
1
+ const path = require("path");
2
2
 
3
- const {InternalFs, ExternalFs, DataCache} = require('@secrez/fs')
4
- const inquirerCommandPrompt = require('inquirer-command-prompt')
5
-
6
- const cliConfig = require('../cliConfig')
7
- const Commands = require('../commands')
3
+ const { InternalFs, ExternalFs, DataCache } = require("@secrez/fs");
4
+ const inquirerCommandPrompt = require("inquirer-command-prompt");
8
5
 
6
+ const cliConfig = require("../cliConfig");
7
+ const Commands = require("../commands");
9
8
 
10
9
  class MainPromptMock {
11
-
12
10
  async init(options) {
13
- this.secrez = new (require('@secrez/core').Secrez())
14
- await this.secrez.init(options.container, options.localDir)
15
- this.secrez.cache = new DataCache(path.join(options.container, 'cache'))
16
- this.internalFs = new InternalFs(this.secrez)
17
- this.externalFs = new ExternalFs(this.secrez)
18
- this.commands = (new Commands(this, cliConfig)).getCommands()
19
- this.commandPrompt = inquirerCommandPrompt
20
- this.cache = {}
11
+ this.secrez = new (require("@secrez/core").Secrez())();
12
+ await this.secrez.init(options.container, options.localDir);
13
+ this.secrez.cache = new DataCache(path.join(options.container, "cache"));
14
+ this.internalFs = new InternalFs(this.secrez);
15
+ this.externalFs = new ExternalFs(this.secrez);
16
+ this.commands = new Commands(this, cliConfig).getCommands();
17
+ this.commandPrompt = inquirerCommandPrompt;
18
+ this.cache = {};
21
19
  }
22
20
 
23
- setCache() {
24
- }
21
+ setCache() {}
25
22
 
26
- getCache() {
27
- }
23
+ getCache() {}
28
24
 
29
- async run(options) {
30
- }
25
+ async run(options) {}
31
26
 
32
- async exec(cmds, noRun) {
33
- }
34
-
35
- async loading() {
36
- }
27
+ async exec(cmds, noRun) {}
37
28
 
29
+ async loading() {}
38
30
  }
39
31
 
40
-
41
-
42
- module.exports = MainPromptMock
43
-
32
+ module.exports = MainPromptMock;
@@ -1,42 +1,41 @@
1
- const editAsync = require('external-editor').editAsync
2
- const EditorPrompt = require('inquirer/lib/prompts/editor')
3
- const chalk = require('chalk')
1
+ const editAsync = require("external-editor").editAsync;
2
+ const EditorPrompt = require("inquirer/lib/prompts/editor");
3
+ const chalk = require("chalk");
4
4
 
5
5
  class MultiEditorPrompt extends EditorPrompt {
6
-
7
6
  render(error) {
8
- var bottomContent = ''
9
- var message = this.getQuestion()
7
+ var bottomContent = "";
8
+ var message = this.getQuestion();
10
9
 
11
- if (this.status === 'answered') {
12
- message += chalk.dim('Received')
10
+ if (this.status === "answered") {
11
+ message += chalk.dim("Received");
13
12
  } else {
14
- message += this.opt.extraMessage || ''
13
+ message += this.opt.extraMessage || "";
15
14
  }
16
15
  if (error) {
17
- bottomContent = chalk.red('>> ') + error
16
+ bottomContent = chalk.red(">> ") + error;
18
17
  }
19
- this.screen.render(message, bottomContent)
18
+ this.screen.render(message, bottomContent);
20
19
  }
21
20
 
22
21
  async startExternalEditor() {
23
- this.rl.pause()
22
+ this.rl.pause();
24
23
  editAsync(
25
- this.currentText,
26
- this.endExternalEditor.bind(this),
27
- this.opt.tempDir ? {
28
- dir: this.opt.tempDir
29
- } : undefined
30
- )
24
+ this.currentText,
25
+ this.endExternalEditor.bind(this),
26
+ this.opt.tempDir
27
+ ? {
28
+ dir: this.opt.tempDir,
29
+ }
30
+ : undefined
31
+ );
31
32
  }
32
33
 
33
34
  close() {
34
35
  if (this.opt.onClose) {
35
- this.opt.onClose()
36
+ this.opt.onClose();
36
37
  }
37
38
  }
38
-
39
39
  }
40
40
 
41
- module.exports = MultiEditorPrompt
42
-
41
+ module.exports = MultiEditorPrompt;
@@ -1,46 +1,43 @@
1
1
  class SigintManager {
2
-
3
2
  constructor() {
4
- this.prompts = []
5
- this.siginted = false
6
- this.lastCalled = Date.now()
7
- this.started = false
3
+ this.prompts = [];
4
+ this.siginted = false;
5
+ this.lastCalled = Date.now();
6
+ this.started = false;
8
7
  }
9
8
 
10
9
  start() {
11
- if (!this.started && process.env.NODE_ENV !== 'test') {
12
- process.on('SIGINT', async () => {
13
- await this.onSigint()
14
- })
15
- this.started = true
10
+ if (!this.started && process.env.NODE_ENV !== "test") {
11
+ process.on("SIGINT", async () => {
12
+ await this.onSigint();
13
+ });
14
+ this.started = true;
16
15
  }
17
16
  }
18
17
 
19
18
  async onSigint() {
20
- this.siginted = true
19
+ this.siginted = true;
21
20
  if (Date.now() - this.lastCalled < 500) {
22
21
  // eslint-disable-next-line no-process-exit
23
- process.exit(0)
22
+ process.exit(0);
24
23
  }
25
- console.info('To exit, type quit or press ^C two times')
26
- this.lastCalled = Date.now()
27
- return this.prompts[this.prompts.length - 1].run()
24
+ console.info("To exit, type quit or press ^C two times");
25
+ this.lastCalled = Date.now();
26
+ return this.prompts[this.prompts.length - 1].run();
28
27
  }
29
28
 
30
29
  async setPosition(prompt) {
31
- this.prompts.push(prompt)
32
- let runNow
30
+ this.prompts.push(prompt);
31
+ let runNow;
33
32
  if (this.siginted && prompt.context === 0) {
34
- this.siginted = false
35
- runNow = true
33
+ this.siginted = false;
34
+ runNow = true;
36
35
  }
37
36
  return {
38
37
  position: this.prompts.length - 1,
39
- runNow
40
- }
38
+ runNow,
39
+ };
41
40
  }
42
-
43
41
  }
44
42
 
45
- module.exports = new SigintManager
46
-
43
+ module.exports = new SigintManager();
@@ -1,58 +1,56 @@
1
1
  class AliasManager {
2
-
3
2
  constructor(cache) {
4
- this.cache = cache
3
+ this.cache = cache;
5
4
  }
6
5
 
7
6
  get(alias) {
8
- return this.cache.get('alias', alias)
7
+ return this.cache.get("alias", alias);
9
8
  }
10
9
 
11
10
  validateCommand(line, regularCmds) {
12
11
  /* istanbul ignore if */
13
12
  if (!line) {
14
- return 'No previous command'
13
+ return "No previous command";
15
14
  }
16
- let cmd = line.split(' ')[0]
15
+ let cmd = line.split(" ")[0];
17
16
  if (this.get(cmd)) {
18
- return 'Can not make an alias of an alias'
17
+ return "Can not make an alias of an alias";
19
18
  }
20
19
  if (regularCmds && !regularCmds[cmd]) {
21
- return `"${cmd}" is not a valid command`
20
+ return `"${cmd}" is not a valid command`;
22
21
  }
23
22
  }
24
23
 
25
24
  validateName(name) {
26
25
  if (!/^(\w|-)+$/g.test(name)) {
27
- return `The name "${name}" is invalid. Aliases' names can be any combination of upper and lower letters, numerals, underscores and hiphens`
26
+ return `The name "${name}" is invalid. Aliases' names can be any combination of upper and lower letters, numerals, underscores and hiphens`;
28
27
  }
29
28
  }
30
29
 
31
30
  async create(options) {
32
31
  /* istanbul ignore if */
33
32
  if (this.get(options.name)) {
34
- throw new Error(`An alias named "${options.name}" already exists`)
33
+ throw new Error(`An alias named "${options.name}" already exists`);
35
34
  }
36
- return await this.cache.puts('alias', {
35
+ return await this.cache.puts("alias", {
37
36
  value: options.name,
38
- content: options.commandLine
39
- })
37
+ content: options.commandLine,
38
+ });
40
39
  }
41
40
 
42
41
  async remove(alias) {
43
- return await this.cache.remove('alias', alias)
42
+ return await this.cache.remove("alias", alias);
44
43
  }
45
44
 
46
45
  async rename(existentName, alias) {
47
- let old = this.get(existentName)
46
+ let old = this.get(existentName);
48
47
  if (await this.remove(existentName)) {
49
48
  return await this.create({
50
49
  name: alias,
51
- commandLine: old.content
52
- })
50
+ commandLine: old.content,
51
+ });
53
52
  }
54
53
  }
55
-
56
54
  }
57
55
 
58
- module.exports = AliasManager
56
+ module.exports = AliasManager;
@@ -1,54 +1,52 @@
1
1
  class ContactManager {
2
-
3
2
  constructor(cache) {
4
- this.cache = cache
3
+ this.cache = cache;
5
4
  }
6
5
 
7
6
  get(contact) {
8
- return this.cache.get('contact', contact)
7
+ return this.cache.get("contact", contact);
9
8
  }
10
9
 
11
10
  validateName(name) {
12
11
  if (!/^(\w|-)+$/g.test(name)) {
13
- return `The name "${name}" is invalid. Aliases' names can be any combination of upper and lower letters, numerals, underscores and hiphens`
12
+ return `The name "${name}" is invalid. Aliases' names can be any combination of upper and lower letters, numerals, underscores and hiphens`;
14
13
  }
15
14
  }
16
15
 
17
16
  async create(options) {
18
17
  /* istanbul ignore if */
19
18
  if (this.get(options.name)) {
20
- throw new Error(`A contact named "${options.name}" already exists`)
19
+ throw new Error(`A contact named "${options.name}" already exists`);
21
20
  }
22
- return await this.cache.puts('contact', {
21
+ return await this.cache.puts("contact", {
23
22
  value: options.name,
24
23
  content: JSON.stringify({
25
24
  publicKey: options.publicKey,
26
- url: options.url
27
- })
28
- })
25
+ url: options.url,
26
+ }),
27
+ });
29
28
  }
30
29
 
31
30
  async remove(contact) {
32
- return await this.cache.remove('contact', contact)
31
+ return await this.cache.remove("contact", contact);
33
32
  }
34
33
 
35
34
  async empty() {
36
- let allContacts = Object.keys(this.get())
35
+ let allContacts = Object.keys(this.get());
37
36
  for (let contact of allContacts) {
38
- await this.cache.remove('contact', contact)
37
+ await this.cache.remove("contact", contact);
39
38
  }
40
39
  }
41
40
 
42
41
  async rename(existentName, contact) {
43
- let old = this.get(existentName)
42
+ let old = this.get(existentName);
44
43
  if (await this.remove(existentName)) {
45
44
  return await this.create({
46
45
  name: contact,
47
- content: old.content
48
- })
46
+ content: old.content,
47
+ });
49
48
  }
50
49
  }
51
-
52
50
  }
53
51
 
54
- module.exports = ContactManager
52
+ module.exports = ContactManager;