@posterly/cli 0.1.2 → 0.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 +10 -5
- package/bin/posterly.mjs +67 -5
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ folder. In that case `posterly` will only be available as
|
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
37
|
posterly auth:login
|
|
38
|
-
posterly auth:key
|
|
38
|
+
posterly auth:key
|
|
39
39
|
posterly whoami --pretty
|
|
40
40
|
posterly accounts:list --pretty
|
|
41
41
|
posterly accounts:disconnect 123 --confirm --pretty
|
|
@@ -61,10 +61,15 @@ The CLI outputs JSON by default so it can be piped into `jq` or other tools. Use
|
|
|
61
61
|
`--pretty` for formatted output. `--human` is accepted as an alias for
|
|
62
62
|
`--pretty` for older examples.
|
|
63
63
|
|
|
64
|
-
Authentication
|
|
64
|
+
Authentication:
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
- Prefer `posterly auth:login` for browser-based OAuth.
|
|
67
|
+
- Use `posterly auth:key` with no argument to paste an API key into a hidden prompt.
|
|
68
|
+
- For non-interactive setup, pipe the key on stdin: `printf '%s\n' "$POSTERLY_API_KEY" | posterly auth:key`.
|
|
69
|
+
- `POSTERLY_API_KEY` can be used directly without saving local config.
|
|
70
|
+
|
|
71
|
+
`--api-key` is still supported for automation, but avoid passing live keys as
|
|
72
|
+
command-line arguments in interactive shells because argv can be stored in shell
|
|
73
|
+
history or exposed through local process listings.
|
|
69
74
|
|
|
70
75
|
Set `--url` or `POSTERLY_URL` to point at a non-production posterly deployment.
|
package/bin/posterly.mjs
CHANGED
|
@@ -22,7 +22,7 @@ const OAUTH_SCOPES = ['accounts:read', 'accounts:write', 'posts:read', 'posts:wr
|
|
|
22
22
|
|
|
23
23
|
const COMMANDS = [
|
|
24
24
|
'auth:login [--url https://www.poster.ly] [--no-open]',
|
|
25
|
-
'auth:key [
|
|
25
|
+
'auth:key [--url https://www.poster.ly]',
|
|
26
26
|
'auth:status',
|
|
27
27
|
'auth:logout',
|
|
28
28
|
'whoami',
|
|
@@ -55,7 +55,7 @@ async function main() {
|
|
|
55
55
|
posterly: 'CLI for the posterly API',
|
|
56
56
|
usage: 'posterly <command> [--flag value]',
|
|
57
57
|
commands: COMMANDS,
|
|
58
|
-
auth: 'Run `npx @posterly/cli@latest auth:login` for the no-install flow, `posterly auth:login` after global install, `posterly auth:key
|
|
58
|
+
auth: 'Run `npx @posterly/cli@latest auth:login` for the no-install flow, `posterly auth:login` after global install, run `posterly auth:key` and paste a key at the prompt, or set POSTERLY_API_KEY.',
|
|
59
59
|
}, flags);
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -369,7 +369,9 @@ async function createClient(flags) {
|
|
|
369
369
|
const config = await readConfig();
|
|
370
370
|
const apiKey = flags.apiKey || process.env.POSTERLY_API_KEY || config.apiKey;
|
|
371
371
|
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || config.baseUrl || DEFAULT_BASE_URL);
|
|
372
|
-
if (!apiKey)
|
|
372
|
+
if (!apiKey) {
|
|
373
|
+
throw new Error('Missing API key. Run `npx @posterly/cli@latest auth:login`, `posterly auth:login` after global install, run `posterly auth:key` and paste a key at the prompt, or set POSTERLY_API_KEY.');
|
|
374
|
+
}
|
|
373
375
|
|
|
374
376
|
async function request(method, path, body) {
|
|
375
377
|
const res = await fetch(`${baseUrl}/api/v1${path}`, {
|
|
@@ -403,8 +405,14 @@ async function createClient(flags) {
|
|
|
403
405
|
}
|
|
404
406
|
|
|
405
407
|
async function saveKey(key, flags) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
+
if (key || flags.apiKey) {
|
|
409
|
+
console.warn('Warning: passing API keys as command-line arguments can expose them through shell history or process listings. Prefer `posterly auth:key` with no argument or POSTERLY_API_KEY.');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const apiKey = key || flags.apiKey || process.env.POSTERLY_API_KEY || await readApiKeyFromInput();
|
|
413
|
+
if (!apiKey) {
|
|
414
|
+
throw new Error('Missing API key. Run `posterly auth:key` and paste a key at the prompt, pipe a key on stdin, use `npx @posterly/cli@latest auth:key`, or set POSTERLY_API_KEY.');
|
|
415
|
+
}
|
|
408
416
|
await mkdir(CONFIG_DIR, { recursive: true });
|
|
409
417
|
const config = {
|
|
410
418
|
apiKey,
|
|
@@ -415,6 +423,60 @@ async function saveKey(key, flags) {
|
|
|
415
423
|
return print({ saved: true, config_file: CONFIG_FILE, base_url: config.baseUrl }, flags);
|
|
416
424
|
}
|
|
417
425
|
|
|
426
|
+
async function readApiKeyFromInput() {
|
|
427
|
+
if (!process.stdin.isTTY) {
|
|
428
|
+
const chunks = [];
|
|
429
|
+
for await (const chunk of process.stdin) {
|
|
430
|
+
chunks.push(Buffer.from(chunk));
|
|
431
|
+
}
|
|
432
|
+
return Buffer.concat(chunks).toString('utf8').trim();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (!process.stdout.isTTY || typeof process.stdin.setRawMode !== 'function') {
|
|
436
|
+
return '';
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
process.stdout.write('Posterly API key: ');
|
|
440
|
+
process.stdin.setRawMode(true);
|
|
441
|
+
process.stdin.resume();
|
|
442
|
+
process.stdin.setEncoding('utf8');
|
|
443
|
+
|
|
444
|
+
let value = '';
|
|
445
|
+
try {
|
|
446
|
+
return await new Promise((resolve, reject) => {
|
|
447
|
+
const onData = (chunk) => {
|
|
448
|
+
if (chunk === '\u0003') {
|
|
449
|
+
cleanup();
|
|
450
|
+
process.stdout.write('\n');
|
|
451
|
+
reject(new Error('Cancelled'));
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (chunk === '\r' || chunk === '\n') {
|
|
455
|
+
cleanup();
|
|
456
|
+
process.stdout.write('\n');
|
|
457
|
+
resolve(value.trim());
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (chunk === '\u0008' || chunk === '\u007f') {
|
|
461
|
+
value = value.slice(0, -1);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
value += chunk;
|
|
465
|
+
};
|
|
466
|
+
const cleanup = () => {
|
|
467
|
+
process.stdin.off('data', onData);
|
|
468
|
+
process.stdin.setRawMode(false);
|
|
469
|
+
process.stdin.pause();
|
|
470
|
+
};
|
|
471
|
+
process.stdin.on('data', onData);
|
|
472
|
+
});
|
|
473
|
+
} finally {
|
|
474
|
+
if (process.stdin.isRaw) {
|
|
475
|
+
process.stdin.setRawMode(false);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
418
480
|
async function authLogin(flags) {
|
|
419
481
|
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || DEFAULT_BASE_URL);
|
|
420
482
|
const redirectUri = `http://127.0.0.1:${OAUTH_CALLBACK_PORT}${OAUTH_CALLBACK_PATH}`;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posterly/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Command line interface for the posterly API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"posterly": "bin/posterly.mjs"
|
|
9
9
|
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
10
13
|
"engines": {
|
|
11
14
|
"node": ">=20"
|
|
12
15
|
}
|