@aloth/olcli 0.11.0 → 0.12.0
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 +33 -2
- package/dist/cli.js +118 -11
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +56 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -4
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +37 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +34 -2
- package/dist/config.js.map +1 -1
- package/dist/prompt.d.ts +63 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +146 -0
- package/dist/prompt.js.map +1 -0
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Configuration management for olcli
|
|
3
3
|
*/
|
|
4
4
|
import Conf from 'conf';
|
|
5
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
const config = new Conf({
|
|
8
8
|
projectName: 'olcli',
|
|
@@ -99,11 +99,43 @@ export function clearConfig() {
|
|
|
99
99
|
export function getConfigPath() {
|
|
100
100
|
return config.path;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Where a `.olauth` file would live for a given directory.
|
|
104
|
+
*
|
|
105
|
+
* Defaults to the current working directory, which is what `saveOlAuth` and
|
|
106
|
+
* `getSessionCookie` both use.
|
|
107
|
+
*/
|
|
108
|
+
export function getOlAuthPath(dir) {
|
|
109
|
+
return join(dir || process.cwd(), '.olauth');
|
|
110
|
+
}
|
|
102
111
|
/**
|
|
103
112
|
* Save session cookie in .olauth format for compatibility
|
|
104
113
|
*/
|
|
105
114
|
export function saveOlAuth(cookie, path) {
|
|
106
|
-
const authPath = path ||
|
|
115
|
+
const authPath = path || getOlAuthPath();
|
|
107
116
|
writeFileSync(authPath, `${getSessionCookieName()}=${cookie}`, 'utf-8');
|
|
108
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Delete the `.olauth` file for a directory, if there is one.
|
|
120
|
+
*
|
|
121
|
+
* Returns the path that was removed, or null when there was nothing to
|
|
122
|
+
* remove. `logout` needs the distinction to report what it actually did.
|
|
123
|
+
*/
|
|
124
|
+
export function clearOlAuth(dir) {
|
|
125
|
+
const authPath = getOlAuthPath(dir);
|
|
126
|
+
if (!existsSync(authPath))
|
|
127
|
+
return null;
|
|
128
|
+
rmSync(authPath);
|
|
129
|
+
return authPath;
|
|
130
|
+
}
|
|
131
|
+
export function inspectStoredCredentials(dir) {
|
|
132
|
+
const authPath = getOlAuthPath(dir);
|
|
133
|
+
return {
|
|
134
|
+
sessionCookie: Boolean(config.get('sessionCookie')),
|
|
135
|
+
password: Boolean(config.get('loginEmail') || config.get('loginPassword')),
|
|
136
|
+
olAuthPath: existsSync(authPath) ? authPath : null,
|
|
137
|
+
envSession: Boolean(process.env.OVERLEAF_SESSION),
|
|
138
|
+
envPassword: Boolean(process.env.OVERLEAF_EMAIL && process.env.OVERLEAF_PASSWORD)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
109
141
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IA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CAAC,GAAG,CAAC,iBAAiB,CAAC;KAClF,CAAC;AACJ,CAAC"}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive terminal prompts.
|
|
3
|
+
*
|
|
4
|
+
* Exists for one reason: reading a password without it appearing on the
|
|
5
|
+
* command line, and therefore in shell history. See issue #50.
|
|
6
|
+
*
|
|
7
|
+
* No dependency for this. A masked read is a raw-mode loop over stdin, and
|
|
8
|
+
* pulling in a prompt library to avoid writing it would cost more than it
|
|
9
|
+
* saves - the bar in this repo is low dependency count, not zero.
|
|
10
|
+
*
|
|
11
|
+
* The keystroke handling is a pure reducer (`applyChunk`) with the terminal
|
|
12
|
+
* wiring wrapped around it, for the same reason `diff.ts` is pure: a raw-mode
|
|
13
|
+
* loop cannot be exercised without a pty, and the part that can silently
|
|
14
|
+
* corrupt a password is the character handling, not the plumbing.
|
|
15
|
+
*/
|
|
16
|
+
/** Raised when the user aborts the prompt (Ctrl+C / Ctrl+D). */
|
|
17
|
+
export declare class PromptCancelled extends Error {
|
|
18
|
+
constructor();
|
|
19
|
+
}
|
|
20
|
+
/** Raised when there is no terminal to prompt on. */
|
|
21
|
+
export declare class NotATerminal extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export interface KeyState {
|
|
25
|
+
/** What the user has typed so far. */
|
|
26
|
+
value: string;
|
|
27
|
+
/**
|
|
28
|
+
* Where we are in an ANSI escape sequence.
|
|
29
|
+
*
|
|
30
|
+
* 'none' - ordinary input
|
|
31
|
+
* 'esc' - saw ESC, waiting to see whether a sequence follows
|
|
32
|
+
* 'csi' - inside `ESC [` or `ESC O`, swallowing until the final byte
|
|
33
|
+
*/
|
|
34
|
+
escape: 'none' | 'esc' | 'csi';
|
|
35
|
+
outcome: 'pending' | 'submit' | 'cancel';
|
|
36
|
+
}
|
|
37
|
+
export declare function initialKeyState(): KeyState;
|
|
38
|
+
/**
|
|
39
|
+
* Fold one chunk of terminal input into the state.
|
|
40
|
+
*
|
|
41
|
+
* A chunk is not one keystroke: a paste arrives whole, and a single arrow key
|
|
42
|
+
* arrives as the three characters `ESC [ A`. Both have to be handled here.
|
|
43
|
+
*
|
|
44
|
+
* Escape sequences are swallowed rather than filtered character by character.
|
|
45
|
+
* Dropping only the ESC leaves `[` and `A` behind, and both are printable - so
|
|
46
|
+
* an arrow key pressed mid-entry would append "[A" to the password and the
|
|
47
|
+
* user would never see it. That is the failure this state machine exists to
|
|
48
|
+
* prevent; it was found by driving the prompt over a pty.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applyChunk(state: KeyState, chunk: string): KeyState;
|
|
51
|
+
/**
|
|
52
|
+
* Read a line from stdin without echoing it.
|
|
53
|
+
*
|
|
54
|
+
* Nothing is written back as the user types - not even asterisks. `sudo`
|
|
55
|
+
* behaves the same way, and echoing one character per keystroke leaks the
|
|
56
|
+
* length of the secret to anyone looking at the screen.
|
|
57
|
+
*
|
|
58
|
+
* Throws `NotATerminal` when stdin is piped or redirected. A masked read is
|
|
59
|
+
* impossible there, and silently falling back to an unmasked one would defeat
|
|
60
|
+
* the point; the caller is expected to name the scripted alternative instead.
|
|
61
|
+
*/
|
|
62
|
+
export declare function promptHidden(label: string): Promise<string>;
|
|
63
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,gEAAgE;AAChE,qBAAa,eAAgB,SAAQ,KAAK;;CAKzC;AAED,qDAAqD;AACrD,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,QAAQ;IACvB,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;IAC/B,OAAO,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC1C;AAED,wBAAgB,eAAe,IAAI,QAAQ,CAE1C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CA4CnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4C3D"}
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive terminal prompts.
|
|
3
|
+
*
|
|
4
|
+
* Exists for one reason: reading a password without it appearing on the
|
|
5
|
+
* command line, and therefore in shell history. See issue #50.
|
|
6
|
+
*
|
|
7
|
+
* No dependency for this. A masked read is a raw-mode loop over stdin, and
|
|
8
|
+
* pulling in a prompt library to avoid writing it would cost more than it
|
|
9
|
+
* saves - the bar in this repo is low dependency count, not zero.
|
|
10
|
+
*
|
|
11
|
+
* The keystroke handling is a pure reducer (`applyChunk`) with the terminal
|
|
12
|
+
* wiring wrapped around it, for the same reason `diff.ts` is pure: a raw-mode
|
|
13
|
+
* loop cannot be exercised without a pty, and the part that can silently
|
|
14
|
+
* corrupt a password is the character handling, not the plumbing.
|
|
15
|
+
*/
|
|
16
|
+
import { stdin, stdout } from 'node:process';
|
|
17
|
+
const CTRL_C = '\u0003';
|
|
18
|
+
const CTRL_D = '\u0004';
|
|
19
|
+
const DEL = '\u007f';
|
|
20
|
+
const ESC = '\u001b';
|
|
21
|
+
/** Raised when the user aborts the prompt (Ctrl+C / Ctrl+D). */
|
|
22
|
+
export class PromptCancelled extends Error {
|
|
23
|
+
constructor() {
|
|
24
|
+
super('Cancelled');
|
|
25
|
+
this.name = 'PromptCancelled';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Raised when there is no terminal to prompt on. */
|
|
29
|
+
export class NotATerminal extends Error {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'NotATerminal';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function initialKeyState() {
|
|
36
|
+
return { value: '', escape: 'none', outcome: 'pending' };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fold one chunk of terminal input into the state.
|
|
40
|
+
*
|
|
41
|
+
* A chunk is not one keystroke: a paste arrives whole, and a single arrow key
|
|
42
|
+
* arrives as the three characters `ESC [ A`. Both have to be handled here.
|
|
43
|
+
*
|
|
44
|
+
* Escape sequences are swallowed rather than filtered character by character.
|
|
45
|
+
* Dropping only the ESC leaves `[` and `A` behind, and both are printable - so
|
|
46
|
+
* an arrow key pressed mid-entry would append "[A" to the password and the
|
|
47
|
+
* user would never see it. That is the failure this state machine exists to
|
|
48
|
+
* prevent; it was found by driving the prompt over a pty.
|
|
49
|
+
*/
|
|
50
|
+
export function applyChunk(state, chunk) {
|
|
51
|
+
let { value, escape, outcome } = state;
|
|
52
|
+
for (const ch of chunk) {
|
|
53
|
+
if (outcome !== 'pending')
|
|
54
|
+
break;
|
|
55
|
+
if (escape === 'csi') {
|
|
56
|
+
// Parameter and intermediate bytes continue the sequence; a final byte
|
|
57
|
+
// in @..~ ends it. `ESC [ 3 ~` (Delete) needs the parameter handling.
|
|
58
|
+
if (ch >= '@' && ch <= '~')
|
|
59
|
+
escape = 'none';
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (escape === 'esc') {
|
|
63
|
+
// `ESC [` is CSI, `ESC O` is the alternate cursor mode some terminals
|
|
64
|
+
// use for arrows. Anything else was a lone ESC plus a real character.
|
|
65
|
+
escape = ch === '[' || ch === 'O' ? 'csi' : 'none';
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
switch (ch) {
|
|
69
|
+
case '\r':
|
|
70
|
+
case '\n':
|
|
71
|
+
outcome = 'submit';
|
|
72
|
+
break;
|
|
73
|
+
case CTRL_C:
|
|
74
|
+
case CTRL_D:
|
|
75
|
+
outcome = 'cancel';
|
|
76
|
+
break;
|
|
77
|
+
case DEL:
|
|
78
|
+
case '\b':
|
|
79
|
+
value = value.slice(0, -1);
|
|
80
|
+
break;
|
|
81
|
+
case ESC:
|
|
82
|
+
escape = 'esc';
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
// Remaining control characters are not password material. Appending
|
|
86
|
+
// them would corrupt the value invisibly.
|
|
87
|
+
if (ch >= ' ')
|
|
88
|
+
value += ch;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { value, escape, outcome };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Read a line from stdin without echoing it.
|
|
95
|
+
*
|
|
96
|
+
* Nothing is written back as the user types - not even asterisks. `sudo`
|
|
97
|
+
* behaves the same way, and echoing one character per keystroke leaks the
|
|
98
|
+
* length of the secret to anyone looking at the screen.
|
|
99
|
+
*
|
|
100
|
+
* Throws `NotATerminal` when stdin is piped or redirected. A masked read is
|
|
101
|
+
* impossible there, and silently falling back to an unmasked one would defeat
|
|
102
|
+
* the point; the caller is expected to name the scripted alternative instead.
|
|
103
|
+
*/
|
|
104
|
+
export function promptHidden(label) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
if (!stdin.isTTY) {
|
|
107
|
+
reject(new NotATerminal('stdin is not a terminal, so a password cannot be prompted for'));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Restore whatever mode the caller was in rather than assuming cooked:
|
|
111
|
+
// olcli may be driven from a wrapper that set raw mode itself.
|
|
112
|
+
const wasRaw = stdin.isRaw;
|
|
113
|
+
let state = initialKeyState();
|
|
114
|
+
let settled = false;
|
|
115
|
+
const cleanup = () => {
|
|
116
|
+
if (settled)
|
|
117
|
+
return;
|
|
118
|
+
settled = true;
|
|
119
|
+
stdin.removeListener('data', onData);
|
|
120
|
+
stdin.setRawMode(wasRaw);
|
|
121
|
+
stdin.pause();
|
|
122
|
+
stdout.write('\n');
|
|
123
|
+
};
|
|
124
|
+
const onData = (chunk) => {
|
|
125
|
+
state = applyChunk(state, chunk);
|
|
126
|
+
if (state.outcome === 'submit') {
|
|
127
|
+
cleanup();
|
|
128
|
+
resolve(state.value);
|
|
129
|
+
}
|
|
130
|
+
else if (state.outcome === 'cancel') {
|
|
131
|
+
cleanup();
|
|
132
|
+
reject(new PromptCancelled());
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
// Raw mode goes on before the label is written. The terminal's line
|
|
136
|
+
// discipline echoes whatever arrives while ECHO is still set, so a caller
|
|
137
|
+
// that answers the instant the prompt appears - anything automated - would
|
|
138
|
+
// otherwise have its first keystrokes echoed to the screen.
|
|
139
|
+
stdin.setRawMode(true);
|
|
140
|
+
stdin.resume();
|
|
141
|
+
stdin.setEncoding('utf8');
|
|
142
|
+
stdin.on('data', onData);
|
|
143
|
+
stdout.write(label);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,GAAG,GAAG,QAAQ,CAAC;AACrB,MAAM,GAAG,GAAG,QAAQ,CAAC;AAErB,gEAAgE;AAChE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,qDAAqD;AACrD,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,O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