@indigoai-us/hq-cli 5.5.1 → 5.5.2-sentry-rc.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/dist/bin/hq-auth-refresh.js +22 -12
- package/dist/bin/hq-auth-refresh.js.map +1 -1
- package/dist/commands/_patterns.d.ts +3 -0
- package/dist/commands/_patterns.d.ts.map +1 -0
- package/dist/commands/_patterns.js +3 -0
- package/dist/commands/_patterns.js.map +1 -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/groups.d.ts +3 -0
- package/dist/commands/groups.d.ts.map +1 -0
- package/dist/commands/groups.js +341 -0
- package/dist/commands/groups.js.map +1 -0
- 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 +12 -0
- package/dist/commands/secrets.d.ts.map +1 -0
- package/dist/commands/secrets.js +756 -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 +21 -2
- package/dist/index.js.map +1 -1
- package/dist/sentry-before-send.d.ts +3 -0
- package/dist/sentry-before-send.d.ts.map +1 -0
- package/dist/sentry-before-send.js +216 -0
- package/dist/sentry-before-send.js.map +1 -0
- package/dist/sentry-dsn.generated.d.ts +2 -0
- package/dist/sentry-dsn.generated.d.ts.map +1 -0
- package/dist/sentry-dsn.generated.js.map +1 -0
- package/dist/sentry.d.ts +4 -0
- package/dist/sentry.d.ts.map +1 -0
- package/dist/sentry.js +19 -0
- package/dist/sentry.js.map +1 -0
- 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 +135 -0
- package/dist/utils/secrets-cache.js.map +1 -0
- package/package.json +9 -5
- package/scripts/generate-dsn.mjs +26 -0
- package/src/bin/hq-auth-refresh.ts +23 -16
- package/src/commands/_patterns.ts +2 -0
- package/src/commands/add.ts +7 -6
- package/src/commands/auth.ts +0 -3
- package/src/commands/groups.ts +357 -0
- 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 +950 -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 +22 -2
- package/src/sentry-before-send.test.ts +359 -0
- package/src/sentry-before-send.ts +221 -0
- package/src/sentry.test.ts +24 -0
- package/src/sentry.ts +19 -0
- 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 +130 -0
- package/tsconfig.json +2 -1
- package/dist/utils/auth.d.ts +0 -27
- package/dist/utils/auth.d.ts.map +0 -1
- package/dist/utils/auth.js +0 -155
- package/dist/utils/auth.js.map +0 -1
- package/dist/utils/token-store.d.ts +0 -28
- package/dist/utils/token-store.d.ts.map +0 -1
- package/dist/utils/token-store.js +0 -68
- package/dist/utils/token-store.js.map +0 -1
- package/src/utils/auth.ts +0 -193
- package/src/utils/token-store.ts +0 -83
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";
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
4
|
+
import { vaultApiFetch, getCompanyUid } from "./secrets.js";
|
|
5
|
+
import { GROUP_ID_PATTERN } from "./_patterns.js";
|
|
6
|
+
|
|
7
|
+
const EMAIL_PATTERN = /^[^\s]+@[^\s]+$/;
|
|
8
|
+
const PERSON_UID_PATTERN = /^prs_[A-Za-z0-9_-]+$/;
|
|
9
|
+
|
|
10
|
+
function detectPrincipalType(
|
|
11
|
+
principal: string,
|
|
12
|
+
): { granteeType: "email" | "person"; granteeId: string } | null {
|
|
13
|
+
if (EMAIL_PATTERN.test(principal)) {
|
|
14
|
+
// Server normalizes email again; we normalize here so local validation /
|
|
15
|
+
// cache keys agree with the server-side canonicalization.
|
|
16
|
+
return { granteeType: "email", granteeId: principal.trim().toLowerCase() };
|
|
17
|
+
}
|
|
18
|
+
if (PERSON_UID_PATTERN.test(principal)) {
|
|
19
|
+
return { granteeType: "person", granteeId: principal };
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function shortDate(iso: string): string {
|
|
25
|
+
return iso.slice(0, 10);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerGroupsCommand(program: Command): void {
|
|
29
|
+
const groups = program
|
|
30
|
+
.command("groups")
|
|
31
|
+
.description("Manage groups in HQ vault")
|
|
32
|
+
.option("--company <slug>", "Company slug (resolves to companyUid)");
|
|
33
|
+
|
|
34
|
+
groups
|
|
35
|
+
.command("create <groupId>")
|
|
36
|
+
.description("Create a new group")
|
|
37
|
+
.requiredOption("--name <name>", "Human-readable group name")
|
|
38
|
+
.option("--description <desc>", "Optional description")
|
|
39
|
+
.action(async (groupId: string, opts: { name: string; description?: string }) => {
|
|
40
|
+
try {
|
|
41
|
+
if (!GROUP_ID_PATTERN.test(groupId)) {
|
|
42
|
+
console.error(chalk.red(`Invalid group id '${groupId}': must match grp_<alphanumeric>`));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const token = await ensureCognitoToken();
|
|
47
|
+
const companySlug = groups.opts().company as string | undefined;
|
|
48
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
49
|
+
|
|
50
|
+
const body: Record<string, unknown> = { groupId, name: opts.name };
|
|
51
|
+
if (opts.description) body.description = opts.description;
|
|
52
|
+
|
|
53
|
+
const res = await vaultApiFetch({
|
|
54
|
+
token,
|
|
55
|
+
path: `/secrets/${encodeURIComponent(companyUid)}/groups`,
|
|
56
|
+
method: "POST",
|
|
57
|
+
body,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
const err = await res.json().catch(() => ({})) as Record<string, string>;
|
|
62
|
+
if (res.status === 401) {
|
|
63
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
64
|
+
} else if (res.status === 403) {
|
|
65
|
+
console.error(chalk.red("Not authorized — owner or admin role required"));
|
|
66
|
+
} else if (res.status === 409) {
|
|
67
|
+
console.error(chalk.red(`Group already exists: ${groupId}`));
|
|
68
|
+
} else if (res.status >= 500) {
|
|
69
|
+
console.error(chalk.red(`Server error: ${err.error ?? res.statusText}`));
|
|
70
|
+
} else {
|
|
71
|
+
console.error(chalk.red(err.message ?? err.error ?? "Invalid request"));
|
|
72
|
+
}
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log(chalk.green(`Group '${groupId}' (${opts.name}) created`));
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
groups
|
|
84
|
+
.command("delete <groupId>")
|
|
85
|
+
.description("Delete a group")
|
|
86
|
+
.action(async (groupId: string) => {
|
|
87
|
+
try {
|
|
88
|
+
if (!GROUP_ID_PATTERN.test(groupId)) {
|
|
89
|
+
console.error(chalk.red(`Invalid group id '${groupId}': must match grp_<alphanumeric>`));
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const token = await ensureCognitoToken();
|
|
94
|
+
const companySlug = groups.opts().company as string | undefined;
|
|
95
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
96
|
+
|
|
97
|
+
const res = await vaultApiFetch({
|
|
98
|
+
token,
|
|
99
|
+
path: `/secrets/${encodeURIComponent(companyUid)}/groups`,
|
|
100
|
+
method: "DELETE",
|
|
101
|
+
query: { groupId },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
const err = await res.json().catch(() => ({})) as Record<string, string>;
|
|
106
|
+
if (res.status === 401) {
|
|
107
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
108
|
+
} else if (res.status === 403) {
|
|
109
|
+
console.error(chalk.red("Not authorized — owner or admin role required"));
|
|
110
|
+
} else if (res.status === 404) {
|
|
111
|
+
console.error(chalk.red(`Group not found: ${groupId}`));
|
|
112
|
+
} else if (res.status >= 500) {
|
|
113
|
+
console.error(chalk.red(`Server error: ${err.error ?? res.statusText}`));
|
|
114
|
+
} else {
|
|
115
|
+
console.error(chalk.red(err.message ?? err.error ?? "Invalid request"));
|
|
116
|
+
}
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(chalk.green(`Group '${groupId}' deleted`));
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
groups
|
|
128
|
+
.command("add <groupId> <principal>")
|
|
129
|
+
.description("Add a person to a group (principal: email or personUid)")
|
|
130
|
+
.action(async (groupId: string, principal: string) => {
|
|
131
|
+
try {
|
|
132
|
+
if (!GROUP_ID_PATTERN.test(groupId)) {
|
|
133
|
+
console.error(chalk.red(`Invalid group id '${groupId}': must match grp_<alphanumeric>`));
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const detected = detectPrincipalType(principal);
|
|
138
|
+
if (!detected) {
|
|
139
|
+
console.error(chalk.red(`Invalid principal '${principal}': must be an email address or a personUid matching prs_<alphanumeric>`));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const token = await ensureCognitoToken();
|
|
144
|
+
const companySlug = groups.opts().company as string | undefined;
|
|
145
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
146
|
+
|
|
147
|
+
const res = await vaultApiFetch({
|
|
148
|
+
token,
|
|
149
|
+
path: `/secrets/${encodeURIComponent(companyUid)}/groups/members`,
|
|
150
|
+
method: "POST",
|
|
151
|
+
body: { groupId, granteeType: detected.granteeType, granteeId: detected.granteeId },
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!res.ok) {
|
|
155
|
+
const err = await res.json().catch(() => ({})) as Record<string, string>;
|
|
156
|
+
if (res.status === 401) {
|
|
157
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
158
|
+
} else if (res.status === 403) {
|
|
159
|
+
console.error(chalk.red("Not authorized — owner/admin role or group creator required"));
|
|
160
|
+
} else if (res.status === 404) {
|
|
161
|
+
// Server provides a helpful message (email not found vs group not found)
|
|
162
|
+
console.error(chalk.red(err.error ?? `Not found`));
|
|
163
|
+
} else if (res.status >= 500) {
|
|
164
|
+
console.error(chalk.red(`Server error: ${err.error ?? res.statusText}`));
|
|
165
|
+
} else {
|
|
166
|
+
console.error(chalk.red(err.message ?? err.error ?? "Invalid request"));
|
|
167
|
+
}
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
console.log(chalk.green(`Added ${principal} to group '${groupId}'`));
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
groups
|
|
179
|
+
.command("remove <groupId> <principal>")
|
|
180
|
+
.description("Remove a person from a group (principal: email or personUid)")
|
|
181
|
+
.action(async (groupId: string, principal: string) => {
|
|
182
|
+
try {
|
|
183
|
+
if (!GROUP_ID_PATTERN.test(groupId)) {
|
|
184
|
+
console.error(chalk.red(`Invalid group id '${groupId}': must match grp_<alphanumeric>`));
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const detected = detectPrincipalType(principal);
|
|
189
|
+
if (!detected) {
|
|
190
|
+
console.error(chalk.red(`Invalid principal '${principal}': must be an email address or a personUid matching prs_<alphanumeric>`));
|
|
191
|
+
process.exit(1);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const token = await ensureCognitoToken();
|
|
195
|
+
const companySlug = groups.opts().company as string | undefined;
|
|
196
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
197
|
+
|
|
198
|
+
const res = await vaultApiFetch({
|
|
199
|
+
token,
|
|
200
|
+
path: `/secrets/${encodeURIComponent(companyUid)}/groups/members`,
|
|
201
|
+
method: "DELETE",
|
|
202
|
+
query: {
|
|
203
|
+
groupId,
|
|
204
|
+
granteeType: detected.granteeType,
|
|
205
|
+
granteeId: detected.granteeId,
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (!res.ok) {
|
|
210
|
+
const err = await res.json().catch(() => ({})) as Record<string, string>;
|
|
211
|
+
if (res.status === 401) {
|
|
212
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
213
|
+
} else if (res.status === 403) {
|
|
214
|
+
console.error(chalk.red("Not authorized — owner/admin role or group creator required"));
|
|
215
|
+
} else if (res.status === 404) {
|
|
216
|
+
console.error(chalk.red(err.error ?? `Not found`));
|
|
217
|
+
} else if (res.status >= 500) {
|
|
218
|
+
console.error(chalk.red(`Server error: ${err.error ?? res.statusText}`));
|
|
219
|
+
} else {
|
|
220
|
+
console.error(chalk.red(err.message ?? err.error ?? "Invalid request"));
|
|
221
|
+
}
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
console.log(chalk.green(`Removed ${principal} from group '${groupId}'`));
|
|
226
|
+
} catch (err) {
|
|
227
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
228
|
+
process.exit(1);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
groups
|
|
233
|
+
.command("list")
|
|
234
|
+
.description("List all groups in the company")
|
|
235
|
+
.action(async () => {
|
|
236
|
+
try {
|
|
237
|
+
const token = await ensureCognitoToken();
|
|
238
|
+
const companySlug = groups.opts().company as string | undefined;
|
|
239
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
240
|
+
|
|
241
|
+
const res = await vaultApiFetch({
|
|
242
|
+
token,
|
|
243
|
+
path: `/secrets/${encodeURIComponent(companyUid)}/groups`,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (!res.ok) {
|
|
247
|
+
const err = await res.json().catch(() => ({})) as Record<string, string>;
|
|
248
|
+
if (res.status === 401) {
|
|
249
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
250
|
+
} else if (res.status === 403) {
|
|
251
|
+
console.error(chalk.red("Not authorized to list groups"));
|
|
252
|
+
} else if (res.status >= 500) {
|
|
253
|
+
console.error(chalk.red(`Server error: ${err.error ?? res.statusText}`));
|
|
254
|
+
} else {
|
|
255
|
+
console.error(chalk.red(err.message ?? err.error ?? "Invalid request"));
|
|
256
|
+
}
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const data = await res.json() as {
|
|
261
|
+
groups: Array<{ groupId: string; name: string; description?: string; createdAt: string }>;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
if (data.groups.length === 0) {
|
|
265
|
+
console.log(chalk.gray("No groups in this company yet."));
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const idW = Math.max(8, ...data.groups.map((g) => g.groupId.length));
|
|
270
|
+
const nameW = Math.max(4, ...data.groups.map((g) => g.name.length));
|
|
271
|
+
const descW = Math.max(11, ...data.groups.map((g) => (g.description ?? "").length));
|
|
272
|
+
console.log(chalk.bold([
|
|
273
|
+
"GROUP_ID".padEnd(idW),
|
|
274
|
+
"NAME".padEnd(nameW),
|
|
275
|
+
"DESCRIPTION".padEnd(descW),
|
|
276
|
+
"CREATED_AT",
|
|
277
|
+
].join(" ")));
|
|
278
|
+
for (const g of data.groups) {
|
|
279
|
+
console.log([
|
|
280
|
+
g.groupId.padEnd(idW),
|
|
281
|
+
g.name.padEnd(nameW),
|
|
282
|
+
(g.description ?? "").padEnd(descW),
|
|
283
|
+
shortDate(g.createdAt),
|
|
284
|
+
].join(" "));
|
|
285
|
+
}
|
|
286
|
+
} catch (err) {
|
|
287
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
288
|
+
process.exit(1);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
groups
|
|
293
|
+
.command("members <groupId>")
|
|
294
|
+
.description("List members of a group")
|
|
295
|
+
.action(async (groupId: string) => {
|
|
296
|
+
try {
|
|
297
|
+
if (!GROUP_ID_PATTERN.test(groupId)) {
|
|
298
|
+
console.error(chalk.red(`Invalid group id '${groupId}': must match grp_<alphanumeric>`));
|
|
299
|
+
process.exit(1);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const token = await ensureCognitoToken();
|
|
303
|
+
const companySlug = groups.opts().company as string | undefined;
|
|
304
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
305
|
+
|
|
306
|
+
const res = await vaultApiFetch({
|
|
307
|
+
token,
|
|
308
|
+
path: `/secrets/${encodeURIComponent(companyUid)}/groups/members`,
|
|
309
|
+
query: { groupId },
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
if (!res.ok) {
|
|
313
|
+
const err = await res.json().catch(() => ({})) as Record<string, string>;
|
|
314
|
+
if (res.status === 401) {
|
|
315
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
316
|
+
} else if (res.status === 403) {
|
|
317
|
+
console.error(chalk.red("Not authorized to view group members"));
|
|
318
|
+
} else if (res.status === 404) {
|
|
319
|
+
console.error(chalk.red(`Group not found: ${groupId}`));
|
|
320
|
+
} else if (res.status >= 500) {
|
|
321
|
+
console.error(chalk.red(`Server error: ${err.error ?? res.statusText}`));
|
|
322
|
+
} else {
|
|
323
|
+
console.error(chalk.red(err.message ?? err.error ?? "Invalid request"));
|
|
324
|
+
}
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const data = await res.json() as {
|
|
329
|
+
members: Array<{ personUid: string; addedBy: string; addedAt: string }>;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
console.log(`Members of '${groupId}':`);
|
|
333
|
+
if (data.members.length === 0) {
|
|
334
|
+
console.log(chalk.gray("No members yet — use 'hq groups add' to add."));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const uidW = Math.max(10, ...data.members.map((m) => m.personUid.length));
|
|
339
|
+
const byW = Math.max(8, ...data.members.map((m) => m.addedBy.length));
|
|
340
|
+
console.log(chalk.bold([
|
|
341
|
+
"PERSON_UID".padEnd(uidW),
|
|
342
|
+
"ADDED_BY".padEnd(byW),
|
|
343
|
+
"ADDED_AT",
|
|
344
|
+
].join(" ")));
|
|
345
|
+
for (const m of data.members) {
|
|
346
|
+
console.log([
|
|
347
|
+
m.personUid.padEnd(uidW),
|
|
348
|
+
m.addedBy.padEnd(byW),
|
|
349
|
+
shortDate(m.addedAt),
|
|
350
|
+
].join(" "));
|
|
351
|
+
}
|
|
352
|
+
} catch (err) {
|
|
353
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
354
|
+
process.exit(1);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
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(
|