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
package/src/Command.js
CHANGED
@@ -1,115 +1,136 @@
|
|
1
|
-
const {chalk} = require(
|
2
|
-
const Logger = require(
|
3
|
-
const cliConfig = require(
|
4
|
-
const PreCommand = require(
|
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(
|
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 ===
|
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
|
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 (
|
63
|
-
|
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 !==
|
68
|
-
options.path = options[currentOption]
|
72
|
+
if (currentOption !== "path") {
|
73
|
+
options.path = options[currentOption];
|
69
74
|
}
|
70
|
-
if (
|
71
|
-
|
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[
|
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 !==
|
86
|
-
throw new Error(
|
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(
|
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 (
|
95
|
-
options.path
|
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 =
|
122
|
+
let err = "";
|
123
|
+
let prefix = "Missing options: ";
|
100
124
|
for (let o in mandatoryOptions) {
|
101
125
|
if (!options[o]) {
|
102
|
-
err += (err ?
|
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,121 @@
|
|
1
|
-
const {chalk} = require(
|
2
|
-
const Crypto = require(
|
3
|
-
const {utils: hubUtils} = require(
|
4
|
-
const superagent = require(
|
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 =
|
8
|
+
let message = "your OS default editor.";
|
10
9
|
if (options.internal) {
|
11
|
-
message =
|
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 =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
return result
|
32
|
-
|
34
|
+
]);
|
35
|
+
return result;
|
33
36
|
}
|
34
37
|
|
35
|
-
|
36
38
|
async useSelect(options) {
|
37
|
-
let 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:
|
44
|
-
name:
|
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:
|
61
|
-
name:
|
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
|
73
|
-
let
|
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 ||
|
77
|
-
name:
|
75
|
+
type: options.type || "input",
|
76
|
+
name: "result",
|
78
77
|
message: options.message,
|
79
78
|
default: options.content,
|
80
|
-
|
79
|
+
choices: options.choices,
|
80
|
+
validate: (val) => {
|
81
81
|
if (val) {
|
82
82
|
if (val === exitCode) {
|
83
|
-
return true
|
83
|
+
return true;
|
84
84
|
} else if (options.validate) {
|
85
|
-
return options.validate(val, exitCode)
|
85
|
+
return options.validate(val, exitCode);
|
86
86
|
} else if (val.length) {
|
87
|
-
return true
|
87
|
+
return true;
|
88
88
|
}
|
89
89
|
}
|
90
|
-
return chalk.grey(
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
return chalk.grey(
|
91
|
+
`Please, type the ${options.name}, or cancel typing ${chalk.bold(
|
92
|
+
exitCode
|
93
|
+
)}`
|
94
|
+
);
|
95
|
+
},
|
96
|
+
},
|
97
|
+
]);
|
94
98
|
if (result !== exitCode) {
|
95
|
-
return result
|
99
|
+
return result;
|
96
100
|
}
|
97
101
|
}
|
98
102
|
|
99
103
|
async callCourier(_payload, port, caCrt, pathname) {
|
100
|
-
const {payload, signature} = hubUtils.setPayloadAndSignIt(
|
104
|
+
const { payload, signature } = hubUtils.setPayloadAndSignIt(
|
105
|
+
this.secrez,
|
106
|
+
_payload
|
107
|
+
);
|
101
108
|
try {
|
102
109
|
const res = await superagent
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
110
|
+
.get(`https://localhost:${port}${pathname || ""}`)
|
111
|
+
.set("Accept", "application/json")
|
112
|
+
.query({ payload, signature })
|
113
|
+
[caCrt ? "ca" : "trustLocalhost"](caCrt);
|
114
|
+
return res.body;
|
107
115
|
} catch (e) {
|
108
|
-
return {error: e.message}
|
116
|
+
return { error: e.message };
|
109
117
|
}
|
110
118
|
}
|
111
|
-
|
112
119
|
}
|
113
120
|
|
114
|
-
module.exports = PreCommand
|
115
|
-
|
116
|
-
|
121
|
+
module.exports = PreCommand;
|