@indigoai-us/hq-cli 5.15.0 → 5.17.0-sources-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.
Files changed (41) hide show
  1. package/.github/workflows/ci.yml +8 -4
  2. package/.github/workflows/publish.yml +8 -3
  3. package/dist/cli-version.d.ts +1 -0
  4. package/dist/cli-version.js +3 -2
  5. package/dist/commands/cloud-provision.d.ts +25 -0
  6. package/dist/commands/cloud-provision.js +75 -9
  7. package/dist/commands/groups.js +6 -6
  8. package/dist/commands/meetings.js +8 -8
  9. package/dist/commands/members.d.ts +4 -2
  10. package/dist/commands/members.js +30 -14
  11. package/dist/commands/signals.d.ts +24 -0
  12. package/dist/commands/signals.js +240 -0
  13. package/dist/commands/sources.d.ts +22 -0
  14. package/dist/commands/sources.js +250 -0
  15. package/dist/index.js +8 -2
  16. package/dist/utils/cognito-session.d.ts +10 -1
  17. package/dist/utils/cognito-session.js +18 -3
  18. package/package.json +5 -4
  19. package/scripts/smoke-sources-signals.sh +103 -0
  20. package/src/cli-version.ts +5 -1
  21. package/src/commands/cloud-provision.test.ts +27 -2
  22. package/src/commands/cloud-provision.ts +122 -7
  23. package/src/commands/groups.ts +4 -4
  24. package/src/commands/meetings.ts +6 -6
  25. package/src/commands/members.test.ts +56 -0
  26. package/src/commands/members.ts +44 -13
  27. package/src/commands/signals.ts +345 -0
  28. package/src/commands/sources.ts +356 -0
  29. package/src/index.ts +8 -0
  30. package/src/utils/cognito-session.test.ts +24 -1
  31. package/src/utils/cognito-session.ts +18 -0
  32. package/test/commands/signals.test.ts +200 -0
  33. package/test/commands/sources.test.ts +225 -0
  34. package/test/fixtures/signals/action_item/sample.md +16 -0
  35. package/test/fixtures/signals/summary/sample.md +12 -0
  36. package/test/fixtures/sources/meetings/sample.md +25 -0
  37. package/test/helpers/cli-runner.ts +150 -0
  38. package/test/helpers/s3-list-mock.ts +79 -0
  39. package/test/helpers/vault-service-mock.ts +160 -0
  40. package/test/sources-signals/smoke.test.ts +226 -0
  41. package/vitest.config.ts +11 -0
@@ -10,12 +10,16 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v4
13
+ - uses: pnpm/action-setup@v4
14
+ with:
15
+ version: 10
13
16
  - uses: actions/setup-node@v4
14
17
  with:
15
18
  node-version: 22
16
- - run: npm ci
19
+ cache: pnpm
20
+ - run: pnpm install --frozen-lockfile --config.minimumReleaseAge=1440
17
21
  # generate-dsn.mjs only fatals when GITHUB_JOB=publish, so CI builds with
18
22
  # an empty BUNDLED_DSN. That's intentional — the DSN is publish-only.
19
- - run: npm run build --if-present
20
- - run: npm run typecheck --if-present
21
- - run: npm test --if-present
23
+ - run: pnpm run build
24
+ - run: pnpm run typecheck
25
+ - run: pnpm test
@@ -11,6 +11,9 @@ jobs:
11
11
  id-token: write
12
12
  steps:
13
13
  - uses: actions/checkout@v4
14
+ - uses: pnpm/action-setup@v4
15
+ with:
16
+ version: 10
14
17
  - uses: actions/setup-node@v4
15
18
  with:
16
19
  # Node 24 ships npm 11.x, required for npm's trusted-publisher OIDC
@@ -18,12 +21,14 @@ jobs:
18
21
  # rationale (npm 10.x produces masked-404 failures on publish PUT).
19
22
  node-version: 24
20
23
  registry-url: https://registry.npmjs.org
24
+ cache: pnpm
21
25
 
22
- - run: node --version && npm --version
23
- - run: npm ci
26
+ - run: node --version && npm --version && pnpm --version
27
+ # Install with pnpm (supply-chain policy); npm publish keeps OIDC.
28
+ - run: pnpm install --frozen-lockfile --config.minimumReleaseAge=1440
24
29
 
25
30
  - name: Build
26
- run: npm run build --if-present
31
+ run: pnpm run build
27
32
  env:
28
33
  # generate-dsn.mjs fatals when GITHUB_JOB=publish and this var is
29
34
  # missing. Set this as a repo secret to bundle a Sentry DSN into the
@@ -1,2 +1,3 @@
1
+ export declare const CLI_NAME: string;
1
2
  export declare const CLI_VERSION: string;
2
3
  //# sourceMappingURL=cli-version.d.ts.map
@@ -1,11 +1,12 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9d613278-0268-5da9-a6d0-f1b4f15d405a")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3e4e6f0a-40ac-5bee-b3c0-547fffb71ea5")}catch(e){}}();
3
3
  import { readFileSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import path from "node:path";
6
6
  const here = path.dirname(fileURLToPath(import.meta.url));
7
7
  const pkgPath = path.resolve(here, "..", "package.json");
8
8
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
9
+ export const CLI_NAME = pkg.name;
9
10
  export const CLI_VERSION = pkg.version;
10
11
  //# sourceMappingURL=cli-version.js.map
11
- //# debugId=9d613278-0268-5da9-a6d0-f1b4f15d405a
12
+ //# debugId=3e4e6f0a-40ac-5bee-b3c0-547fffb71ea5
@@ -111,7 +111,32 @@ export interface VaultClient {
111
111
  * entity.
112
112
  */
113
113
  listMyPersonEntities(): Promise<VaultEntity[]>;
114
+ /**
115
+ * Legacy global-uniqueness lookup. Under the per-user-namespace model
116
+ * (hq-pro 2026-05-15) this can return any tenant's entity when more
117
+ * than one user holds the same slug, OR `null` when the caller doesn't
118
+ * have it but a different user does. Kept on the interface for any
119
+ * remaining callers, but `provisionCompany` now uses
120
+ * `checkSlugInMyNamespace` instead — same-slug-different-owner is
121
+ * legitimate and should NOT trigger reuse of the stranger's entity.
122
+ */
114
123
  findCompanyBySlug(slug: string): Promise<VaultEntity | null>;
124
+ /**
125
+ * Caller-scoped slug availability check via
126
+ * `GET /entity/check-slug/me?type=company&slug=...`. Returns
127
+ * `{available: true}` when the caller's namespace
128
+ * (owned ∪ active-member-of, soft-deleted excluded) doesn't hold the
129
+ * slug, or `{available: false, conflictingCompanyUid}` when it does
130
+ * — `provisionCompany` reuses the `conflictingCompanyUid` as the
131
+ * idempotent entity instead of creating a duplicate.
132
+ */
133
+ checkSlugInMyNamespace(slug: string): Promise<{
134
+ available: boolean;
135
+ conflictingCompanyUid?: string;
136
+ }>;
137
+ /** Fetch a company entity by uid. Used to materialize the entity
138
+ * after `checkSlugInMyNamespace` reports a same-namespace collision. */
139
+ getCompanyByUid(uid: string): Promise<VaultEntity>;
115
140
  createCompanyEntity(input: {
116
141
  slug: string;
117
142
  name: string;
@@ -28,7 +28,7 @@
28
28
  * `initial_sync.ok=false`). Manifest + config may have been written.
29
29
  */
30
30
 
31
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3c9e69f3-8137-5db1-8692-e38774558f61")}catch(e){}}();
31
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="925baddc-7b12-5ad4-b64f-d7e20bd0daab")}catch(e){}}();
32
32
  import chalk from "chalk";
33
33
  import * as fs from "node:fs";
34
34
  import * as path from "node:path";
@@ -295,6 +295,28 @@ export function createDefaultVaultClient(apiUrl, accessToken) {
295
295
  }
296
296
  return data.entity;
297
297
  },
298
+ async checkSlugInMyNamespace(slug) {
299
+ const url = `${apiUrl.replace(/\/$/, "")}/entity/check-slug/me?type=company&slug=${encodeURIComponent(slug)}`;
300
+ const res = await fetch(url, { method: "GET", headers });
301
+ if (!res.ok) {
302
+ const body = await safeBody(res);
303
+ throw new ProvisionError(1, `Vault GET /entity/check-slug/me failed: ${res.status} ${res.statusText} — ${body}`);
304
+ }
305
+ return (await res.json());
306
+ },
307
+ async getCompanyByUid(uid) {
308
+ const url = `${apiUrl.replace(/\/$/, "")}/entity/${encodeURIComponent(uid)}`;
309
+ const res = await fetch(url, { method: "GET", headers });
310
+ if (!res.ok) {
311
+ const body = await safeBody(res);
312
+ throw new ProvisionError(1, `Vault GET /entity/${uid} failed: ${res.status} ${res.statusText} — ${body}`);
313
+ }
314
+ const data = (await res.json());
315
+ if (!data.entity) {
316
+ throw new ProvisionError(1, `Vault GET /entity/${uid} returned 200 with no entity body`);
317
+ }
318
+ return data.entity;
319
+ },
298
320
  async createCompanyEntity(input) {
299
321
  const url = `${apiUrl.replace(/\/$/, "")}/entity`;
300
322
  const body = {
@@ -311,9 +333,15 @@ export function createDefaultVaultClient(apiUrl, accessToken) {
311
333
  });
312
334
  if (!res.ok) {
313
335
  const text = await safeBody(res);
314
- // 409 means a concurrent client created it between our GET and POST —
315
- // surface it as a vault error. The orchestrator is responsible for
316
- // retrying GET if it wants idempotency on collisions.
336
+ // 409 SLUG_IN_USE_FOR_PERSON: the caller already has the slug
337
+ // in their namespace (owned active-member-of). Under the
338
+ // per-user-namespace model this is the new same-user-collision
339
+ // signal — distinct from the legacy global EntityAlreadyExists.
340
+ // The CLI normally reaches `createCompanyEntity` only after
341
+ // `checkSlugInMyNamespace` reported `available: true`, so a
342
+ // 409 here means a race between the pre-check and the POST.
343
+ // Surface the response body verbatim so the caller can see the
344
+ // `code` + `conflictingCompanyUid` and resolve / retry.
317
345
  throw new ProvisionError(1, `Vault POST /entity failed: ${res.status} ${res.statusText} — ${text}`);
318
346
  }
319
347
  const data = (await res.json());
@@ -393,13 +421,51 @@ export async function provisionCompany(options) {
393
421
  throw new ProvisionError(2, 'No person entity found for this Cognito identity. Run `hq onboard` first to create your HQ identity, then re-run `hq cloud provision company`. (Provision was halted before any cloud-side resources were created.)');
394
422
  }
395
423
  log(`pre-flight ok — caller has ${persons.length} person entity(ies)`);
396
- let entity = await vaultClient.findCompanyBySlug(options.slug);
424
+ // Per-user-namespace-aware reuse-or-create. Replaces the legacy
425
+ // global `findCompanyBySlug` lookup, which under the per-user model
426
+ // (hq-pro 2026-05-15) returns ANY tenant's entity when more than one
427
+ // user holds the same slug, OR null when a different user has it —
428
+ // both wrong for the CLI's "reuse mine, or create" intent.
429
+ //
430
+ // `--owner` override: `options.ownerUid`, when set, lets a caller
431
+ // create the entity under a DIFFERENT person's ownership (e.g. an
432
+ // admin provisioning on behalf of someone). `/entity/check-slug/me`
433
+ // answers about the CALLER's namespace, not the target owner's, so
434
+ // the pre-check is meaningless in that case. Codex P2 on PR 7
435
+ // flagged this. The gate: only run the namespace check when the
436
+ // owner is the caller (or defaulted to the caller — i.e. no
437
+ // --owner supplied). On override, fall through to
438
+ // `createCompanyEntity` and let the server's authoritative 409
439
+ // (which IS scoped to the target's namespace, per the
440
+ // callerIsOwner gate on POST /entity in hq-pro PR 67) surface any
441
+ // real conflict.
442
+ //
443
+ // `callerIsOwner` is `true` whenever `options.ownerUid` is unset
444
+ // (defaults to caller server-side) OR — when set — happens to
445
+ // match the caller's own person UID(s) from `listMyPersonEntities`.
446
+ const callerOwnedUids = new Set(persons.map((p) => p.uid));
447
+ const callerIsOwner = !options.ownerUid || callerOwnedUids.has(options.ownerUid);
448
+ let entity;
397
449
  let createdEntity = false;
398
- if (entity) {
399
- log(`reusing existing vault entity uid=${entity.uid}`);
450
+ if (callerIsOwner) {
451
+ const slugCheck = await vaultClient.checkSlugInMyNamespace(options.slug);
452
+ if (!slugCheck.available && slugCheck.conflictingCompanyUid) {
453
+ log(`reusing existing vault entity uid=${slugCheck.conflictingCompanyUid} (slug already in caller's namespace)`);
454
+ entity = await vaultClient.getCompanyByUid(slugCheck.conflictingCompanyUid);
455
+ }
456
+ else {
457
+ log(`slug available in caller's namespace — creating vault entity`);
458
+ entity = await vaultClient.createCompanyEntity({
459
+ slug: options.slug,
460
+ name: options.name ?? options.slug,
461
+ ownerUid: options.ownerUid,
462
+ });
463
+ createdEntity = true;
464
+ log(`created vault entity uid=${entity.uid}`);
465
+ }
400
466
  }
401
467
  else {
402
- log(`vault entity not found creating`);
468
+ log(`--owner ${options.ownerUid} differs from caller's person(s); skipping namespace pre-check (server authoritatively gates per-target-namespace)`);
403
469
  entity = await vaultClient.createCompanyEntity({
404
470
  slug: options.slug,
405
471
  name: options.name ?? options.slug,
@@ -549,4 +615,4 @@ export function registerCloudProvisionCommands(program) {
549
615
  });
550
616
  }
551
617
  //# sourceMappingURL=cloud-provision.js.map
552
- //# debugId=3c9e69f3-8137-5db1-8692-e38774558f61
618
+ //# debugId=925baddc-7b12-5ad4-b64f-d7e20bd0daab
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="37e6bf57-eabb-58da-874c-57cc39e78d89")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="35b60d26-d8e7-5c10-9ad4-db53285eaaf0")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
5
  import { vaultApiFetch, getCompanyUid } from "./secrets.js";
@@ -58,7 +58,7 @@ export function registerGroupsCommand(program) {
58
58
  console.error(chalk.red("Not authenticated — please run `hq login`"));
59
59
  }
60
60
  else if (res.status === 403) {
61
- console.error(chalk.red("Not authorized — owner or admin role required"));
61
+ console.error(chalk.red("Not authorized — owner role required"));
62
62
  }
63
63
  else if (res.status === 409) {
64
64
  console.error(chalk.red(`Group already exists: ${groupId}`));
@@ -102,7 +102,7 @@ export function registerGroupsCommand(program) {
102
102
  console.error(chalk.red("Not authenticated — please run `hq login`"));
103
103
  }
104
104
  else if (res.status === 403) {
105
- console.error(chalk.red("Not authorized — owner or admin role required"));
105
+ console.error(chalk.red("Not authorized — owner role required"));
106
106
  }
107
107
  else if (res.status === 404) {
108
108
  console.error(chalk.red(`Group not found: ${groupId}`));
@@ -151,7 +151,7 @@ export function registerGroupsCommand(program) {
151
151
  console.error(chalk.red("Not authenticated — please run `hq login`"));
152
152
  }
153
153
  else if (res.status === 403) {
154
- console.error(chalk.red("Not authorized — owner/admin role or group creator required"));
154
+ console.error(chalk.red("Not authorized — owner role or group creator required"));
155
155
  }
156
156
  else if (res.status === 404) {
157
157
  // Server provides a helpful message (email not found vs group not found)
@@ -205,7 +205,7 @@ export function registerGroupsCommand(program) {
205
205
  console.error(chalk.red("Not authenticated — please run `hq login`"));
206
206
  }
207
207
  else if (res.status === 403) {
208
- console.error(chalk.red("Not authorized — owner/admin role or group creator required"));
208
+ console.error(chalk.red("Not authorized — owner role or group creator required"));
209
209
  }
210
210
  else if (res.status === 404) {
211
211
  console.error(chalk.red(err.error ?? `Not found`));
@@ -345,4 +345,4 @@ export function registerGroupsCommand(program) {
345
345
  });
346
346
  }
347
347
  //# sourceMappingURL=groups.js.map
348
- //# debugId=37e6bf57-eabb-58da-874c-57cc39e78d89
348
+ //# debugId=35b60d26-d8e7-5c10-9ad4-db53285eaaf0
@@ -1,8 +1,8 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8237a835-5842-52be-bb27-c4ffb7944d89")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e1c09963-744f-5033-9981-1ab6d37956e9")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
- import { vaultApiFetch } from "../utils/vault-api.js";
5
+ import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
6
6
  function formatDuration(seconds) {
7
7
  const h = Math.floor(seconds / 3600);
8
8
  const m = Math.floor((seconds % 3600) / 60);
@@ -132,7 +132,7 @@ export function registerMeetingsCommand(program) {
132
132
  if (opts.next)
133
133
  query.nextToken = opts.next;
134
134
  if (companySlug)
135
- query.companyId = companySlug;
135
+ query.companyId = await getCompanyUid(token, companySlug);
136
136
  const res = await vaultApiFetch({ token, path: "/v1/meetings", query });
137
137
  if (!res.ok)
138
138
  await handleApiError(res);
@@ -163,7 +163,7 @@ export function registerMeetingsCommand(program) {
163
163
  const query = {};
164
164
  const companySlug = meetings.opts().company;
165
165
  if (companySlug)
166
- query.companyId = companySlug;
166
+ query.companyId = await getCompanyUid(token, companySlug);
167
167
  const meetingId = await resolveShortId(token, rawId, query);
168
168
  const res = await vaultApiFetch({
169
169
  token,
@@ -217,7 +217,7 @@ export function registerMeetingsCommand(program) {
217
217
  const params = { q: query };
218
218
  const companySlug = meetings.opts().company;
219
219
  if (companySlug)
220
- params.companyId = companySlug;
220
+ params.companyId = await getCompanyUid(token, companySlug);
221
221
  const res = await vaultApiFetch({
222
222
  token,
223
223
  path: "/v1/meetings/search",
@@ -249,7 +249,7 @@ export function registerMeetingsCommand(program) {
249
249
  const query = {};
250
250
  const companySlug = meetings.opts().company;
251
251
  if (companySlug)
252
- query.companyId = companySlug;
252
+ query.companyId = await getCompanyUid(token, companySlug);
253
253
  const meetingId = await resolveShortId(token, rawId, query);
254
254
  const res = await vaultApiFetch({
255
255
  token,
@@ -299,7 +299,7 @@ export function registerMeetingsCommand(program) {
299
299
  const query = {};
300
300
  const companySlug = meetings.opts().company;
301
301
  if (companySlug)
302
- query.companyId = companySlug;
302
+ query.companyId = await getCompanyUid(token, companySlug);
303
303
  const meetingId = await resolveShortId(token, rawId, query);
304
304
  const res = await vaultApiFetch({
305
305
  token,
@@ -371,4 +371,4 @@ export function registerMeetingsCommand(program) {
371
371
  });
372
372
  }
373
373
  //# sourceMappingURL=meetings.js.map
374
- //# debugId=8237a835-5842-52be-bb27-c4ffb7944d89
374
+ //# debugId=e1c09963-744f-5033-9981-1ab6d37956e9
@@ -26,6 +26,7 @@ export interface InviteResult {
26
26
  membership: {
27
27
  role: string;
28
28
  status: string;
29
+ inviteToken?: string;
29
30
  };
30
31
  }
31
32
  export interface DetectedTarget {
@@ -44,9 +45,10 @@ export declare function getCallerPersonUid(token: string): Promise<string>;
44
45
  export declare function inviteMember(options: InviteOptions): Promise<InviteResult>;
45
46
  export declare class InviteHttpError extends Error {
46
47
  status: number;
47
- constructor(status: number, message: string);
48
+ code?: string | undefined;
49
+ constructor(status: number, message: string, code?: string | undefined);
48
50
  }
49
- export declare function formatInviteHttpError(status: number, fallback: string): string;
51
+ export declare function formatInviteHttpError(status: number, fallback: string, code?: string): string;
50
52
  export declare function listPendingInvites(token: string, companyUid: string): Promise<PendingInvite[]>;
51
53
  export declare function revokeInvite(token: string, tokenOrKey: string, companyUid: string): Promise<void>;
52
54
  export declare function registerMembersCommand(program: Command): void;
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1b3646e3-32c8-5601-9dba-1d7c0f6cf972")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5f8b5b62-a00e-5ca3-b293-23906579a464")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
5
  import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
@@ -69,27 +69,41 @@ export async function inviteMember(options) {
69
69
  });
70
70
  if (!res.ok) {
71
71
  const err = (await res.json().catch(() => ({})));
72
- throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
72
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText, err.code);
73
73
  }
74
74
  const data = (await res.json());
75
+ // The token may arrive at the response root OR nested on the membership row,
76
+ // depending on vault-service version. Resolve from either; never emit
77
+ // `hq://accept/undefined` (a broken link that looks like success).
78
+ const inviteToken = data.inviteToken ?? data.membership?.inviteToken;
79
+ if (!inviteToken) {
80
+ const keys = Object.keys(data ?? {}).join(", ") || "<empty>";
81
+ throw new Error(`Invite was created but the server response did not include an invite token (response keys: ${keys}). ` +
82
+ "Run `hq members list` to retrieve the pending invite, or upgrade hq.");
83
+ }
75
84
  return {
76
- inviteToken: data.inviteToken,
77
- magicLink: `hq://accept/${data.inviteToken}`,
78
- membership: data.membership,
85
+ inviteToken,
86
+ magicLink: `hq://accept/${inviteToken}`,
87
+ membership: data.membership ?? { role: options.role, status: "pending" },
79
88
  };
80
89
  }
81
90
  export class InviteHttpError extends Error {
82
91
  status;
83
- constructor(status, message) {
92
+ code;
93
+ constructor(status, message, code) {
84
94
  super(message);
85
95
  this.status = status;
96
+ this.code = code;
86
97
  this.name = "InviteHttpError";
87
98
  }
88
99
  }
89
- export function formatInviteHttpError(status, fallback) {
100
+ export function formatInviteHttpError(status, fallback, code) {
90
101
  if (status === 401)
91
102
  return "Not authenticated — please run `hq login`";
92
103
  if (status === 403) {
104
+ if (code === "ADMIN_ROLE_TARGET_RESTRICTED") {
105
+ return "Admin can only invite at role=member; ask an owner to invite at this role";
106
+ }
93
107
  return "Not authorized — only admins and owners can invite members";
94
108
  }
95
109
  if (status === 409) {
@@ -106,10 +120,10 @@ export async function listPendingInvites(token, companyUid) {
106
120
  });
107
121
  if (!res.ok) {
108
122
  const err = (await res.json().catch(() => ({})));
109
- throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
123
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText, err.code);
110
124
  }
111
125
  const data = (await res.json());
112
- return data.invites;
126
+ return data?.invites ?? [];
113
127
  }
114
128
  export async function revokeInvite(token, tokenOrKey, companyUid) {
115
129
  const res = await vaultApiFetch({
@@ -120,7 +134,7 @@ export async function revokeInvite(token, tokenOrKey, companyUid) {
120
134
  });
121
135
  if (!res.ok) {
122
136
  const err = (await res.json().catch(() => ({})));
123
- throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
137
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText, err.code);
124
138
  }
125
139
  }
126
140
  export function registerMembersCommand(program) {
@@ -156,7 +170,7 @@ export function registerMembersCommand(program) {
156
170
  }
157
171
  catch (err) {
158
172
  if (err instanceof InviteHttpError) {
159
- console.error(chalk.red(formatInviteHttpError(err.status, err.message)));
173
+ console.error(chalk.red(formatInviteHttpError(err.status, err.message, err.code)));
160
174
  process.exit(1);
161
175
  }
162
176
  console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
@@ -224,10 +238,12 @@ export function registerMembersCommand(program) {
224
238
  catch (err) {
225
239
  if (err instanceof InviteHttpError) {
226
240
  const msg = err.status === 403
227
- ? "Not authorized — only admins and owners can revoke invites"
241
+ ? err.code === "ADMIN_ROLE_TARGET_RESTRICTED"
242
+ ? "Admin can only revoke role=member; ask an owner to revoke this membership"
243
+ : "Not authorized — only admins and owners can revoke invites"
228
244
  : err.status === 404
229
245
  ? "Invite not found — it may have already been accepted or revoked"
230
- : formatInviteHttpError(err.status, err.message);
246
+ : formatInviteHttpError(err.status, err.message, err.code);
231
247
  console.error(chalk.red(msg));
232
248
  process.exit(1);
233
249
  }
@@ -237,4 +253,4 @@ export function registerMembersCommand(program) {
237
253
  });
238
254
  }
239
255
  //# sourceMappingURL=members.js.map
240
- //# debugId=1b3646e3-32c8-5601-9dba-1d7c0f6cf972
256
+ //# debugId=5f8b5b62-a00e-5ca3-b293-23906579a464
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `hq signals` subcommand group (US-007).
3
+ *
4
+ * Read-side surface over the signals written by sources-pipeline (and any
5
+ * future signal producer). Each invocation resolves a Cognito access
6
+ * token (or honors HQ_ACCESS_TOKEN), vends STS-scoped credentials via
7
+ * vault-service for the requested entity, and delegates to hq-cloud's
8
+ * listSignals/getSignal primitives.
9
+ *
10
+ * Subcommands:
11
+ * hq signals list List signals of a given type for an entity.
12
+ * hq signals get Fetch one signal by id.
13
+ * hq signals types Print the canonical SIGNAL_TYPES enum.
14
+ * hq signals entities List entities the caller has access to.
15
+ *
16
+ * Mirrors `hq sources` exactly — same flags, same TTY-aware defaults,
17
+ * same error/Sentry plumbing. Defense-in-depth signal-type validation
18
+ * (assertSignalType) runs at the CLI layer as well as in hq-cloud, so
19
+ * agents can't fabricate a signal type even if they bypass the CLI's
20
+ * --type flag parsing.
21
+ */
22
+ import { Command } from "commander";
23
+ export declare function registerSignalsCommand(program: Command): void;
24
+ //# sourceMappingURL=signals.d.ts.map