@youkno/edge-cli 1.21.54 → 1.21.55
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/dist/commands/login.js +5 -0
- package/dist/commands/shell.js +4 -2
- package/dist/lib/auth.js +7 -2
- package/package.json +1 -1
- package/src/commands/login.ts +5 -0
- package/src/commands/shell.ts +4 -3
- package/src/lib/auth.ts +7 -2
package/dist/commands/login.js
CHANGED
|
@@ -3,16 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerLogin = registerLogin;
|
|
4
4
|
const auth_1 = require("../lib/auth");
|
|
5
5
|
const config_1 = require("../lib/config");
|
|
6
|
+
const shell_1 = require("./shell");
|
|
6
7
|
function registerLogin(program) {
|
|
7
8
|
program
|
|
8
9
|
.command("login")
|
|
9
10
|
.description("Authenticate via browser and store JWT tokens")
|
|
11
|
+
.option("--shell", "start interactive shell after login")
|
|
10
12
|
.action(async function loginAction() {
|
|
11
13
|
const parent = this.parent;
|
|
12
14
|
const opts = (parent?.opts() ?? {});
|
|
13
15
|
const cfg = await (0, config_1.resolveEffectiveConfig)(opts);
|
|
14
16
|
const email = await (0, auth_1.login)(cfg);
|
|
15
17
|
process.stdout.write(`Successfully authenticated as ${email}\n`);
|
|
18
|
+
if (this.opts().shell) {
|
|
19
|
+
await (0, shell_1.repl)(cfg, {});
|
|
20
|
+
}
|
|
16
21
|
});
|
|
17
22
|
program
|
|
18
23
|
.command("login:list")
|
package/dist/commands/shell.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.repl = repl;
|
|
6
7
|
exports.registerShell = registerShell;
|
|
7
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -101,7 +102,7 @@ async function shellScript(cfg, authHeader, scriptText, options, scriptName = "i
|
|
|
101
102
|
}
|
|
102
103
|
process.stdout.write(body.endsWith("\n") ? body : `${body}\n`);
|
|
103
104
|
}
|
|
104
|
-
async function repl(cfg,
|
|
105
|
+
async function repl(cfg, options) {
|
|
105
106
|
const rl = node_readline_1.default.createInterface({
|
|
106
107
|
input: process.stdin,
|
|
107
108
|
output: process.stdout,
|
|
@@ -117,6 +118,7 @@ async function repl(cfg, authHeader, options) {
|
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
120
|
try {
|
|
121
|
+
const authHeader = await (0, auth_1.resolveAuthHeaderFast)(cfg);
|
|
120
122
|
await shellCmd(cfg, authHeader, cmd, Boolean(options.json));
|
|
121
123
|
}
|
|
122
124
|
catch (err) {
|
|
@@ -156,7 +158,7 @@ function registerShell(program) {
|
|
|
156
158
|
const options = this.opts();
|
|
157
159
|
const authHeader = await (0, auth_1.resolveAuthHeader)(cfg);
|
|
158
160
|
if (!target && (!inlineScript || inlineScript.length === 0)) {
|
|
159
|
-
await repl(cfg,
|
|
161
|
+
await repl(cfg, options);
|
|
160
162
|
return;
|
|
161
163
|
}
|
|
162
164
|
if (target?.endsWith(".esh")) {
|
package/dist/lib/auth.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.logout = logout;
|
|
|
9
9
|
exports.login = login;
|
|
10
10
|
exports.resolveAccessToken = resolveAccessToken;
|
|
11
11
|
exports.resolveAuthHeader = resolveAuthHeader;
|
|
12
|
+
exports.resolveAuthHeaderFast = resolveAuthHeaderFast;
|
|
12
13
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
14
|
const node_os_1 = __importDefault(require("node:os"));
|
|
14
15
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -391,7 +392,7 @@ async function refreshDefaultToken(cfg) {
|
|
|
391
392
|
storeTokens(cfg, email, merged);
|
|
392
393
|
return merged.accessToken;
|
|
393
394
|
}
|
|
394
|
-
async function resolveAccessToken(cfg, forceRefresh = false) {
|
|
395
|
+
async function resolveAccessToken(cfg, forceRefresh = false, skipValidate = false) {
|
|
395
396
|
const db = readDb();
|
|
396
397
|
const scope = getScope(db, cfg);
|
|
397
398
|
const email = scope.default;
|
|
@@ -422,7 +423,7 @@ async function resolveAccessToken(cfg, forceRefresh = false) {
|
|
|
422
423
|
// continue with existing token
|
|
423
424
|
}
|
|
424
425
|
}
|
|
425
|
-
if (!(await validateAccessToken(cfg, accessToken)) && account.refreshToken) {
|
|
426
|
+
if (!skipValidate && !(await validateAccessToken(cfg, accessToken)) && account.refreshToken) {
|
|
426
427
|
const refreshed = await refreshDefaultToken(cfg);
|
|
427
428
|
if (refreshed) {
|
|
428
429
|
accessToken = refreshed;
|
|
@@ -434,3 +435,7 @@ async function resolveAuthHeader(cfg) {
|
|
|
434
435
|
const accessToken = await resolveAccessToken(cfg);
|
|
435
436
|
return `Bearer ${accessToken}`;
|
|
436
437
|
}
|
|
438
|
+
async function resolveAuthHeaderFast(cfg) {
|
|
439
|
+
const accessToken = await resolveAccessToken(cfg, false, true);
|
|
440
|
+
return `Bearer ${accessToken}`;
|
|
441
|
+
}
|
package/package.json
CHANGED
package/src/commands/login.ts
CHANGED
|
@@ -2,18 +2,23 @@ import { Command } from "commander";
|
|
|
2
2
|
|
|
3
3
|
import { login, listLogins, logout, setDefaultLogin } from "../lib/auth";
|
|
4
4
|
import { resolveEffectiveConfig } from "../lib/config";
|
|
5
|
+
import { repl } from "./shell";
|
|
5
6
|
import { CliOptions } from "../lib/types";
|
|
6
7
|
|
|
7
8
|
export function registerLogin(program: Command): void {
|
|
8
9
|
program
|
|
9
10
|
.command("login")
|
|
10
11
|
.description("Authenticate via browser and store JWT tokens")
|
|
12
|
+
.option("--shell", "start interactive shell after login")
|
|
11
13
|
.action(async function loginAction(this: Command) {
|
|
12
14
|
const parent = this.parent;
|
|
13
15
|
const opts = (parent?.opts() ?? {}) as CliOptions;
|
|
14
16
|
const cfg = await resolveEffectiveConfig(opts);
|
|
15
17
|
const email = await login(cfg);
|
|
16
18
|
process.stdout.write(`Successfully authenticated as ${email}\n`);
|
|
19
|
+
if (this.opts<{ shell?: boolean }>().shell) {
|
|
20
|
+
await repl(cfg, {});
|
|
21
|
+
}
|
|
17
22
|
});
|
|
18
23
|
|
|
19
24
|
program
|
package/src/commands/shell.ts
CHANGED
|
@@ -4,7 +4,7 @@ import readline from "node:readline";
|
|
|
4
4
|
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
|
|
7
|
-
import { resolveAuthHeader } from "../lib/auth";
|
|
7
|
+
import { resolveAuthHeader, resolveAuthHeaderFast } from "../lib/auth";
|
|
8
8
|
import { resolveEffectiveConfig } from "../lib/config";
|
|
9
9
|
import { baseHeaders, checkedText } from "../lib/request";
|
|
10
10
|
import { CliOptions, EffectiveConfig } from "../lib/types";
|
|
@@ -126,7 +126,7 @@ async function shellScript(
|
|
|
126
126
|
process.stdout.write(body.endsWith("\n") ? body : `${body}\n`);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
async function repl(cfg: EffectiveConfig,
|
|
129
|
+
export async function repl(cfg: EffectiveConfig, options: ShellOptions) {
|
|
130
130
|
const rl = readline.createInterface({
|
|
131
131
|
input: process.stdin,
|
|
132
132
|
output: process.stdout,
|
|
@@ -144,6 +144,7 @@ async function repl(cfg: EffectiveConfig, authHeader: string, options: ShellOpti
|
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
146
|
try {
|
|
147
|
+
const authHeader = await resolveAuthHeaderFast(cfg);
|
|
147
148
|
await shellCmd(cfg, authHeader, cmd, Boolean(options.json));
|
|
148
149
|
} catch (err) {
|
|
149
150
|
process.stderr.write(`ERROR: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
@@ -185,7 +186,7 @@ export function registerShell(program: Command): void {
|
|
|
185
186
|
const authHeader = await resolveAuthHeader(cfg);
|
|
186
187
|
|
|
187
188
|
if (!target && (!inlineScript || inlineScript.length === 0)) {
|
|
188
|
-
await repl(cfg,
|
|
189
|
+
await repl(cfg, options);
|
|
189
190
|
return;
|
|
190
191
|
}
|
|
191
192
|
|
package/src/lib/auth.ts
CHANGED
|
@@ -459,7 +459,7 @@ async function refreshDefaultToken(cfg: EffectiveConfig): Promise<string | undef
|
|
|
459
459
|
return merged.accessToken;
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
export async function resolveAccessToken(cfg: EffectiveConfig, forceRefresh = false): Promise<string> {
|
|
462
|
+
export async function resolveAccessToken(cfg: EffectiveConfig, forceRefresh = false, skipValidate = false): Promise<string> {
|
|
463
463
|
const db = readDb();
|
|
464
464
|
const scope = getScope(db, cfg);
|
|
465
465
|
const email = scope.default;
|
|
@@ -493,7 +493,7 @@ export async function resolveAccessToken(cfg: EffectiveConfig, forceRefresh = fa
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
if (!(await validateAccessToken(cfg, accessToken)) && account.refreshToken) {
|
|
496
|
+
if (!skipValidate && !(await validateAccessToken(cfg, accessToken)) && account.refreshToken) {
|
|
497
497
|
const refreshed = await refreshDefaultToken(cfg);
|
|
498
498
|
if (refreshed) {
|
|
499
499
|
accessToken = refreshed;
|
|
@@ -507,3 +507,8 @@ export async function resolveAuthHeader(cfg: EffectiveConfig): Promise<string> {
|
|
|
507
507
|
const accessToken = await resolveAccessToken(cfg);
|
|
508
508
|
return `Bearer ${accessToken}`;
|
|
509
509
|
}
|
|
510
|
+
|
|
511
|
+
export async function resolveAuthHeaderFast(cfg: EffectiveConfig): Promise<string> {
|
|
512
|
+
const accessToken = await resolveAccessToken(cfg, false, true);
|
|
513
|
+
return `Bearer ${accessToken}`;
|
|
514
|
+
}
|