@indigoai-us/hq-cli 5.5.1 → 5.5.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.
- package/dist/bin/hq-auth-refresh.js +0 -0
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +2 -1
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/auth.d.ts +0 -3
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +0 -3
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +18 -1
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/login.d.ts +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +28 -9
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.d.ts.map +1 -1
- package/dist/commands/logout.js +8 -3
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/pack-install.d.ts +44 -0
- package/dist/commands/pack-install.d.ts.map +1 -0
- package/dist/commands/pack-install.js +513 -0
- package/dist/commands/pack-install.js.map +1 -0
- package/dist/commands/pkg-install.d.ts.map +1 -1
- package/dist/commands/pkg-install.js +20 -8
- package/dist/commands/pkg-install.js.map +1 -1
- package/dist/commands/pkg-list.js +4 -4
- package/dist/commands/pkg-list.js.map +1 -1
- package/dist/commands/pkg-update.js +3 -3
- package/dist/commands/pkg-update.js.map +1 -1
- package/dist/commands/secrets.d.ts +3 -0
- package/dist/commands/secrets.d.ts.map +1 -0
- package/dist/commands/secrets.js +521 -0
- package/dist/commands/secrets.js.map +1 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +10 -2
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/team-sync.d.ts.map +1 -1
- package/dist/commands/team-sync.js +6 -6
- package/dist/commands/team-sync.js.map +1 -1
- package/dist/commands/whoami.d.ts +1 -1
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +23 -7
- package/dist/commands/whoami.js.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/strategies/link.d.ts +2 -2
- package/dist/strategies/link.d.ts.map +1 -1
- package/dist/strategies/link.js.map +1 -1
- package/dist/strategies/merge.d.ts +2 -2
- package/dist/strategies/merge.d.ts.map +1 -1
- package/dist/strategies/merge.js.map +1 -1
- package/dist/types.d.ts +37 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/cognito-session.js.map +1 -1
- package/dist/utils/manifest.d.ts +13 -0
- package/dist/utils/manifest.d.ts.map +1 -1
- package/dist/utils/manifest.js +24 -1
- package/dist/utils/manifest.js.map +1 -1
- package/dist/utils/secrets-cache.d.ts +7 -0
- package/dist/utils/secrets-cache.d.ts.map +1 -0
- package/dist/utils/secrets-cache.js +134 -0
- package/dist/utils/secrets-cache.js.map +1 -0
- package/package.json +7 -4
- package/src/commands/add.ts +7 -6
- package/src/commands/auth.ts +0 -3
- package/src/commands/list.ts +20 -1
- package/src/commands/login.ts +28 -9
- package/src/commands/logout.ts +8 -3
- package/src/commands/pack-install.ts +667 -0
- package/src/commands/pkg-install.ts +34 -16
- package/src/commands/pkg-list.ts +4 -4
- package/src/commands/pkg-update.ts +3 -3
- package/src/commands/secrets.ts +670 -0
- package/src/commands/sync.ts +20 -4
- package/src/commands/team-sync.ts +7 -8
- package/src/commands/whoami.ts +22 -7
- package/src/index.ts +5 -1
- package/src/strategies/link.ts +2 -2
- package/src/strategies/merge.ts +2 -2
- package/src/types.ts +54 -4
- package/src/utils/cognito-session.ts +3 -3
- package/src/utils/manifest.test.ts +148 -0
- package/src/utils/manifest.ts +22 -1
- package/src/utils/secrets-cache.ts +129 -0
- package/tsconfig.json +2 -1
- package/src/utils/auth.ts +0 -193
- package/src/utils/token-store.ts +0 -83
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
const CACHE_DIR = path.join(os.homedir(), ".hq", "secrets-cache");
|
|
6
|
+
const KEY_PATH = path.join(CACHE_DIR, ".key");
|
|
7
|
+
const TTL_MS = 5 * 60 * 1000;
|
|
8
|
+
const ALGORITHM = "aes-256-gcm";
|
|
9
|
+
const IV_BYTES = 12;
|
|
10
|
+
const AUTH_TAG_BYTES = 16;
|
|
11
|
+
function ensureCacheDir(companyUid) {
|
|
12
|
+
const dir = path.join(CACHE_DIR, companyUid);
|
|
13
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
14
|
+
}
|
|
15
|
+
function validateInputs(companyUid, name) {
|
|
16
|
+
if (!companyUid || companyUid.includes("/") || companyUid.includes(".."))
|
|
17
|
+
return false;
|
|
18
|
+
if (!/^[A-Z][A-Z0-9_]*$/.test(name))
|
|
19
|
+
return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function getOrCreateKey() {
|
|
23
|
+
try {
|
|
24
|
+
const key = fs.readFileSync(KEY_PATH);
|
|
25
|
+
if (key.length === 32) {
|
|
26
|
+
const mode = fs.statSync(KEY_PATH).mode & 0o777;
|
|
27
|
+
if (mode !== 0o600) {
|
|
28
|
+
process.stderr.write(`Warning: secrets cache key has permissions ${mode.toString(8)}, expected 600\n`);
|
|
29
|
+
}
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Key doesn't exist or is unreadable — generate a new one
|
|
35
|
+
}
|
|
36
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true, mode: 0o700 });
|
|
37
|
+
const key = crypto.randomBytes(32);
|
|
38
|
+
const tmpPath = `${KEY_PATH}.tmp.${process.pid}`;
|
|
39
|
+
fs.writeFileSync(tmpPath, key, { mode: 0o600 });
|
|
40
|
+
fs.renameSync(tmpPath, KEY_PATH);
|
|
41
|
+
return fs.readFileSync(KEY_PATH);
|
|
42
|
+
}
|
|
43
|
+
export function readCache(companyUid, name) {
|
|
44
|
+
if (!validateInputs(companyUid, name))
|
|
45
|
+
return null;
|
|
46
|
+
const filePath = path.join(CACHE_DIR, companyUid, name);
|
|
47
|
+
let raw;
|
|
48
|
+
try {
|
|
49
|
+
raw = fs.readFileSync(filePath);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
// Format: [8 bytes timestamp][12 bytes IV][16 bytes authTag][...ciphertext]
|
|
55
|
+
const headerLen = 8 + IV_BYTES + AUTH_TAG_BYTES;
|
|
56
|
+
if (raw.length < headerLen)
|
|
57
|
+
return null;
|
|
58
|
+
const timestampMs = Number(raw.readBigInt64BE(0));
|
|
59
|
+
if (Date.now() - timestampMs > TTL_MS) {
|
|
60
|
+
try {
|
|
61
|
+
fs.unlinkSync(filePath);
|
|
62
|
+
}
|
|
63
|
+
catch { /* ok */ }
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const iv = raw.subarray(8, 8 + IV_BYTES);
|
|
67
|
+
const authTag = raw.subarray(8 + IV_BYTES, headerLen);
|
|
68
|
+
const ciphertext = raw.subarray(headerLen);
|
|
69
|
+
let key;
|
|
70
|
+
try {
|
|
71
|
+
key = getOrCreateKey();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
|
|
78
|
+
decipher.setAuthTag(authTag);
|
|
79
|
+
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
80
|
+
return decrypted.toString("utf8");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
try {
|
|
84
|
+
fs.unlinkSync(filePath);
|
|
85
|
+
}
|
|
86
|
+
catch { /* ok */ }
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function writeCache(companyUid, name, value) {
|
|
91
|
+
try {
|
|
92
|
+
if (!validateInputs(companyUid, name))
|
|
93
|
+
return;
|
|
94
|
+
ensureCacheDir(companyUid);
|
|
95
|
+
const key = getOrCreateKey();
|
|
96
|
+
const iv = crypto.randomBytes(IV_BYTES);
|
|
97
|
+
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
|
|
98
|
+
const encrypted = Buffer.concat([cipher.update(value, "utf8"), cipher.final()]);
|
|
99
|
+
const authTag = cipher.getAuthTag();
|
|
100
|
+
const timestamp = Buffer.alloc(8);
|
|
101
|
+
timestamp.writeBigInt64BE(BigInt(Date.now()));
|
|
102
|
+
const out = Buffer.concat([timestamp, iv, authTag, encrypted]);
|
|
103
|
+
const filePath = path.join(CACHE_DIR, companyUid, name);
|
|
104
|
+
const tmpPath = `${filePath}.tmp.${process.pid}`;
|
|
105
|
+
fs.writeFileSync(tmpPath, out, { mode: 0o600 });
|
|
106
|
+
fs.renameSync(tmpPath, filePath);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// Cache write failure is non-fatal
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function removeCacheEntry(companyUid, name) {
|
|
113
|
+
if (!validateInputs(companyUid, name))
|
|
114
|
+
return;
|
|
115
|
+
const filePath = path.join(CACHE_DIR, companyUid, name);
|
|
116
|
+
try {
|
|
117
|
+
fs.unlinkSync(filePath);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Cache entry may not exist
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function clearAllCache() {
|
|
124
|
+
let removed = 0;
|
|
125
|
+
try {
|
|
126
|
+
fs.rmSync(CACHE_DIR, { recursive: true, force: true });
|
|
127
|
+
removed = 1;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Cache dir may not exist
|
|
131
|
+
}
|
|
132
|
+
return { removed };
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=secrets-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-cache.js","sourceRoot":"","sources":["../../src/utils/secrets-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7B,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,SAAS,cAAc,CAAC,UAAkB;IACxC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC7C,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,cAAc,CAAC,UAAkB,EAAE,IAAY;IACtD,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACvF,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC;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,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,GAAG,QAAQ,QAAQ,OAAO,CAAC,GAAG,EAAE,CAAC;QACjD,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAChD,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,mCAAmC;IACrC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,UAAkB,EAAE,IAAY;IAC/D,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC;QAAE,OAAO;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACxD,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,4BAA4B;IAC9B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,CAAC;QACH,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,0BAA0B;IAC5B,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.2",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,20 +10,23 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"typecheck": "tsc --noEmit",
|
|
13
|
+
"test": "vitest run",
|
|
13
14
|
"clean": "rm -rf dist"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@indigoai-us/hq-cloud": "^5.1.0",
|
|
17
|
-
"@indigoai-us/hq-onboarding": "0.1.
|
|
18
|
+
"@indigoai-us/hq-onboarding": "^0.1.1",
|
|
18
19
|
"chalk": "^5.3.0",
|
|
19
20
|
"commander": "^12.1.0",
|
|
20
21
|
"js-yaml": "^4.1.0",
|
|
21
|
-
"simple-git": "^3.27.0"
|
|
22
|
+
"simple-git": "^3.27.0",
|
|
23
|
+
"semver": "^7.6.3"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@types/js-yaml": "^4.0.9",
|
|
25
27
|
"@types/node": "^22.0.0",
|
|
26
|
-
"typescript": "^5.7.0"
|
|
28
|
+
"typescript": "^5.7.0",
|
|
29
|
+
"@types/semver": "^7.5.8"
|
|
27
30
|
},
|
|
28
31
|
"repository": {
|
|
29
32
|
"type": "git",
|
package/src/commands/add.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Command } from 'commander';
|
|
6
6
|
import { findHqRoot, addModule, parseRepoName, isValidRepoUrl } from '../utils/manifest.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { LegacyModuleDefinition, LegacyStrategy } from '../types.js';
|
|
8
8
|
|
|
9
9
|
export function registerAddCommand(program: Command): void {
|
|
10
10
|
program
|
|
@@ -30,9 +30,10 @@ export function registerAddCommand(program: Command): void {
|
|
|
30
30
|
// Parse name
|
|
31
31
|
const name = options.as || parseRepoName(repoUrl);
|
|
32
32
|
|
|
33
|
-
// Validate strategy
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Validate strategy (hq modules add is for legacy git-repo modules;
|
|
34
|
+
// content packs are added via `hq install`, not `hq modules add`)
|
|
35
|
+
const validStrategies: LegacyStrategy[] = ['link', 'merge', 'copy'];
|
|
36
|
+
if (!validStrategies.includes(options.strategy as LegacyStrategy)) {
|
|
36
37
|
console.error(`Error: Invalid strategy "${options.strategy}". Use: ${validStrategies.join(', ')}`);
|
|
37
38
|
process.exit(1);
|
|
38
39
|
}
|
|
@@ -48,11 +49,11 @@ export function registerAddCommand(program: Command): void {
|
|
|
48
49
|
})
|
|
49
50
|
: [{ src: '.', dest: `workers/${name}` }]; // Default: entire repo to workers/
|
|
50
51
|
|
|
51
|
-
const module:
|
|
52
|
+
const module: LegacyModuleDefinition = {
|
|
52
53
|
name,
|
|
53
54
|
repo: repoUrl,
|
|
54
55
|
branch: options.branch,
|
|
55
|
-
strategy: options.strategy as
|
|
56
|
+
strategy: options.strategy as LegacyStrategy,
|
|
56
57
|
paths,
|
|
57
58
|
};
|
|
58
59
|
|
package/src/commands/auth.ts
CHANGED
|
@@ -12,9 +12,6 @@
|
|
|
12
12
|
* into this machine by writing ~/.hq/cognito-tokens.json; once cached, the
|
|
13
13
|
* session is kept fresh by `hq auth refresh` / `hq-auth-refresh` and consumed
|
|
14
14
|
* by the deploy + sync skills.
|
|
15
|
-
*
|
|
16
|
-
* Note: the top-level `hq login` command authenticates against the HQ package
|
|
17
|
-
* registry (Clerk), not Cognito — that is a different auth stack.
|
|
18
15
|
*/
|
|
19
16
|
|
|
20
17
|
import { Command } from "commander";
|
package/src/commands/list.ts
CHANGED
|
@@ -29,10 +29,29 @@ export function registerListCommand(program: Command): void {
|
|
|
29
29
|
console.log('Modules:\n');
|
|
30
30
|
|
|
31
31
|
for (const module of manifest.modules) {
|
|
32
|
+
console.log(` ${module.name}`);
|
|
33
|
+
|
|
34
|
+
if (module.strategy === 'package') {
|
|
35
|
+
// hq-pack content pack — wired by scripts/scan-packages.sh
|
|
36
|
+
console.log(` Strategy: package`);
|
|
37
|
+
console.log(` Source: ${module.source}`);
|
|
38
|
+
if (module.version) {
|
|
39
|
+
console.log(` Version: ${module.version}`);
|
|
40
|
+
}
|
|
41
|
+
if (module.installed_at) {
|
|
42
|
+
console.log(` Path: ${module.installed_at}`);
|
|
43
|
+
}
|
|
44
|
+
if (module.resolved_sha) {
|
|
45
|
+
console.log(` SHA: ${module.resolved_sha}`);
|
|
46
|
+
}
|
|
47
|
+
console.log();
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// legacy git-repo module
|
|
32
52
|
const moduleDir = path.join(modulesDir, module.name);
|
|
33
53
|
const installed = await isRepo(moduleDir);
|
|
34
54
|
|
|
35
|
-
console.log(` ${module.name}`);
|
|
36
55
|
console.log(` Repo: ${module.repo}`);
|
|
37
56
|
console.log(` Branch: ${module.branch || 'main'}`);
|
|
38
57
|
console.log(` Strategy: ${module.strategy}`);
|
package/src/commands/login.ts
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* hq login — opens browser for
|
|
2
|
+
* hq login — opens browser for Cognito auth via Google OAuth
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { Command } from 'commander';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
7
|
+
import { browserLogin, loadCachedTokens, isExpiring } from '@indigoai-us/hq-cloud';
|
|
8
|
+
import { DEFAULT_COGNITO } from '../utils/cognito-session.js';
|
|
9
|
+
|
|
10
|
+
function peekIdToken(idToken: string): { email?: string; sub?: string } {
|
|
11
|
+
try {
|
|
12
|
+
const payload = idToken.split('.')[1];
|
|
13
|
+
if (!payload) return {};
|
|
14
|
+
const pad = payload.length % 4 === 0 ? '' : '='.repeat(4 - (payload.length % 4));
|
|
15
|
+
const normalized = payload.replace(/-/g, '+').replace(/_/g, '/') + pad;
|
|
16
|
+
const decoded = JSON.parse(Buffer.from(normalized, 'base64').toString('utf-8'));
|
|
17
|
+
return { email: decoded.email, sub: decoded.sub };
|
|
18
|
+
} catch {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
10
22
|
|
|
11
23
|
export function registerLoginCommand(program: Command): void {
|
|
12
24
|
program
|
|
13
25
|
.command('login')
|
|
14
|
-
.description('Authenticate with
|
|
26
|
+
.description('Authenticate with HQ via Cognito (Google OAuth)')
|
|
15
27
|
.action(async () => {
|
|
16
28
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
const existing = loadCachedTokens();
|
|
30
|
+
if (existing && !isExpiring(existing, 120)) {
|
|
31
|
+
const who = peekIdToken(existing.idToken).email ?? 'cached session';
|
|
32
|
+
console.log(chalk.green(`Already logged in as ${who}. Run \`hq logout\` to switch accounts.`));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log('Opening browser for authentication...');
|
|
37
|
+
const tokens = await browserLogin(DEFAULT_COGNITO);
|
|
38
|
+
const who = peekIdToken(tokens.idToken).email ?? 'HQ';
|
|
39
|
+
console.log(chalk.green(`Logged in as ${who}`));
|
|
21
40
|
} catch (error) {
|
|
22
41
|
console.error(
|
|
23
42
|
chalk.red('Login failed:'),
|
package/src/commands/logout.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* hq logout — clears cached session
|
|
2
|
+
* hq logout — clears cached Cognito session
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { Command } from 'commander';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
|
-
import {
|
|
7
|
+
import { clearCachedTokens, loadCachedTokens } from '@indigoai-us/hq-cloud';
|
|
8
8
|
|
|
9
9
|
export function registerLogoutCommand(program: Command): void {
|
|
10
10
|
program
|
|
@@ -12,7 +12,12 @@ export function registerLogoutCommand(program: Command): void {
|
|
|
12
12
|
.description('Log out and clear cached credentials')
|
|
13
13
|
.action(async () => {
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
const existing = loadCachedTokens();
|
|
16
|
+
if (!existing) {
|
|
17
|
+
console.log(chalk.yellow('No cached HQ session'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
clearCachedTokens();
|
|
16
21
|
console.log(chalk.green('Logged out successfully'));
|
|
17
22
|
} catch (error) {
|
|
18
23
|
console.error(
|