@indigoai-us/hq-cli 5.5.0 → 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/cloud.d.ts +12 -2
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +112 -80
- package/dist/commands/cloud.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/onboard.d.ts +23 -0
- package/dist/commands/onboard.d.ts.map +1 -0
- package/dist/commands/onboard.js +142 -0
- package/dist/commands/onboard.js.map +1 -0
- 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 +24 -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.d.ts +18 -7
- package/dist/utils/cognito-session.d.ts.map +1 -1
- package/dist/utils/cognito-session.js +35 -8
- 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 +17 -6
- 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/cloud.ts +214 -101
- 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/onboard.ts +193 -0
- 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 +26 -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 +46 -14
- 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
|
@@ -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(
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hq onboard` — bootstrap an HQ vault: sign in to Cognito + provision
|
|
3
|
+
* the company entity, S3 bucket, KMS key, owner membership, and STS-vended
|
|
4
|
+
* credentials in one flow.
|
|
5
|
+
*
|
|
6
|
+
* This is the "the entire flow" entry point that VLT-9 was building toward:
|
|
7
|
+
* a real user can install hq-cli and run `hq onboard create-company` once
|
|
8
|
+
* to land in a fully provisioned vault, then use `hq sync push|pull` to
|
|
9
|
+
* round-trip files against S3.
|
|
10
|
+
*
|
|
11
|
+
* Subcommands:
|
|
12
|
+
* hq onboard create-company — provision a brand new company
|
|
13
|
+
* hq onboard join — accept an invite from another user
|
|
14
|
+
* hq onboard resume — resume a partially-completed flow from checkpoint
|
|
15
|
+
* hq onboard dry-run — show what create-company would do, without doing it
|
|
16
|
+
*
|
|
17
|
+
* Auth: we cache the Cognito access + refresh tokens at ~/.hq/cognito-tokens.json.
|
|
18
|
+
* If the cached token is missing or expired beyond the refresh window, the
|
|
19
|
+
* browser-OAuth flow opens automatically.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { Command } from "commander";
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
|
|
25
|
+
import { runOnboardCli } from "@indigoai-us/hq-onboarding";
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_HQ_ROOT,
|
|
28
|
+
ensureCognitoToken,
|
|
29
|
+
buildVaultConfig,
|
|
30
|
+
} from "../utils/cognito-session.js";
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Command registration
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
export function registerOnboardCommand(program: Command): void {
|
|
37
|
+
const onboard = program
|
|
38
|
+
.command("onboard")
|
|
39
|
+
.description("Provision an HQ vault: sign in, create company, S3 bucket, STS, sync");
|
|
40
|
+
|
|
41
|
+
onboard
|
|
42
|
+
.command("create-company")
|
|
43
|
+
.description("Sign in and provision a brand new HQ vault for a company")
|
|
44
|
+
.requiredOption("--slug <slug>", "Company slug (used as bucket name suffix)")
|
|
45
|
+
.requiredOption("--name <name>", "Company display name")
|
|
46
|
+
.requiredOption("--email <email>", "Your email (must match Cognito sign-in)")
|
|
47
|
+
.requiredOption("--person-name <name>", "Your display name")
|
|
48
|
+
.option(
|
|
49
|
+
"--hq-root <path>",
|
|
50
|
+
`Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`,
|
|
51
|
+
DEFAULT_HQ_ROOT,
|
|
52
|
+
)
|
|
53
|
+
.action(async (options: {
|
|
54
|
+
slug: string;
|
|
55
|
+
name: string;
|
|
56
|
+
email: string;
|
|
57
|
+
personName: string;
|
|
58
|
+
hqRoot: string;
|
|
59
|
+
}) => {
|
|
60
|
+
try {
|
|
61
|
+
console.log(chalk.bold(`\nHQ Onboard — Create Company`));
|
|
62
|
+
console.log(` Company: ${options.name} (${options.slug})`);
|
|
63
|
+
console.log(` Person: ${options.personName} <${options.email}>`);
|
|
64
|
+
console.log(` HQ root: ${options.hqRoot}\n`);
|
|
65
|
+
|
|
66
|
+
const accessToken = await ensureCognitoToken();
|
|
67
|
+
const result = await runOnboardCli({
|
|
68
|
+
mode: "create-company",
|
|
69
|
+
personName: options.personName,
|
|
70
|
+
personEmail: options.email,
|
|
71
|
+
companyName: options.name,
|
|
72
|
+
companySlug: options.slug,
|
|
73
|
+
vaultConfig: buildVaultConfig(accessToken),
|
|
74
|
+
hqRoot: options.hqRoot,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (!result.success) {
|
|
78
|
+
console.error(chalk.red(`\n✗ Onboarding failed: ${result.error}`));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(
|
|
83
|
+
chalk.red("\n✗ Error:"),
|
|
84
|
+
err instanceof Error ? err.message : String(err),
|
|
85
|
+
);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
onboard
|
|
91
|
+
.command("join")
|
|
92
|
+
.description("Accept an invite and join an existing company")
|
|
93
|
+
.requiredOption("--invite-token <token>", "Magic link token from your invite email")
|
|
94
|
+
.requiredOption("--email <email>", "Your email (must match Cognito sign-in)")
|
|
95
|
+
.requiredOption("--person-name <name>", "Your display name")
|
|
96
|
+
.option(
|
|
97
|
+
"--hq-root <path>",
|
|
98
|
+
`Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`,
|
|
99
|
+
DEFAULT_HQ_ROOT,
|
|
100
|
+
)
|
|
101
|
+
.action(async (options: {
|
|
102
|
+
inviteToken: string;
|
|
103
|
+
email: string;
|
|
104
|
+
personName: string;
|
|
105
|
+
hqRoot: string;
|
|
106
|
+
}) => {
|
|
107
|
+
try {
|
|
108
|
+
console.log(chalk.bold(`\nHQ Onboard — Join Company`));
|
|
109
|
+
console.log(` Person: ${options.personName} <${options.email}>`);
|
|
110
|
+
console.log(` HQ root: ${options.hqRoot}\n`);
|
|
111
|
+
|
|
112
|
+
const accessToken = await ensureCognitoToken();
|
|
113
|
+
const result = await runOnboardCli({
|
|
114
|
+
mode: "join-company",
|
|
115
|
+
personName: options.personName,
|
|
116
|
+
personEmail: options.email,
|
|
117
|
+
inviteToken: options.inviteToken,
|
|
118
|
+
vaultConfig: buildVaultConfig(accessToken),
|
|
119
|
+
hqRoot: options.hqRoot,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (!result.success) {
|
|
123
|
+
console.error(chalk.red(`\n✗ Join failed: ${result.error}`));
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.error(
|
|
128
|
+
chalk.red("\n✗ Error:"),
|
|
129
|
+
err instanceof Error ? err.message : String(err),
|
|
130
|
+
);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
onboard
|
|
136
|
+
.command("resume")
|
|
137
|
+
.description("Resume a partially-completed onboarding flow from local checkpoint")
|
|
138
|
+
.option(
|
|
139
|
+
"--hq-root <path>",
|
|
140
|
+
`Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`,
|
|
141
|
+
DEFAULT_HQ_ROOT,
|
|
142
|
+
)
|
|
143
|
+
.action(async (options: { hqRoot: string }) => {
|
|
144
|
+
try {
|
|
145
|
+
const accessToken = await ensureCognitoToken();
|
|
146
|
+
const result = await runOnboardCli({
|
|
147
|
+
mode: "resume",
|
|
148
|
+
vaultConfig: buildVaultConfig(accessToken),
|
|
149
|
+
hqRoot: options.hqRoot,
|
|
150
|
+
});
|
|
151
|
+
if (!result.success) {
|
|
152
|
+
console.error(chalk.red(`\n✗ Resume failed: ${result.error}`));
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error(
|
|
157
|
+
chalk.red("\n✗ Error:"),
|
|
158
|
+
err instanceof Error ? err.message : String(err),
|
|
159
|
+
);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
onboard
|
|
165
|
+
.command("dry-run")
|
|
166
|
+
.description("Show what create-company would do, without provisioning anything")
|
|
167
|
+
.option(
|
|
168
|
+
"--hq-root <path>",
|
|
169
|
+
`Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`,
|
|
170
|
+
DEFAULT_HQ_ROOT,
|
|
171
|
+
)
|
|
172
|
+
.action(async (options: { hqRoot: string }) => {
|
|
173
|
+
try {
|
|
174
|
+
// No auth needed for dry-run — runOnboardCli handles this branch
|
|
175
|
+
// without touching the vault-service.
|
|
176
|
+
const result = await runOnboardCli({
|
|
177
|
+
mode: "dry-run",
|
|
178
|
+
vaultConfig: buildVaultConfig("dry-run-no-token"),
|
|
179
|
+
hqRoot: options.hqRoot,
|
|
180
|
+
});
|
|
181
|
+
if (!result.success) {
|
|
182
|
+
console.error(chalk.red(`\n✗ Dry-run failed: ${result.error}`));
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
console.error(
|
|
187
|
+
chalk.red("\n✗ Error:"),
|
|
188
|
+
err instanceof Error ? err.message : String(err),
|
|
189
|
+
);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|