@indigoai-us/hq-cloud 6.14.50 → 6.15.1

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 (340) hide show
  1. package/dist/bin/sync-mutation.d.ts +14 -0
  2. package/dist/bin/sync-mutation.d.ts.map +1 -0
  3. package/dist/bin/sync-mutation.js +60 -0
  4. package/dist/bin/sync-mutation.js.map +1 -0
  5. package/dist/bin/sync-mutation.test.d.ts +2 -0
  6. package/dist/bin/sync-mutation.test.d.ts.map +1 -0
  7. package/dist/bin/sync-mutation.test.js +64 -0
  8. package/dist/bin/sync-mutation.test.js.map +1 -0
  9. package/dist/bin/sync-runner-company.d.ts +8 -0
  10. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  11. package/dist/bin/sync-runner-company.js +16 -0
  12. package/dist/bin/sync-runner-company.js.map +1 -1
  13. package/dist/bin/sync-runner-company.test.d.ts +2 -0
  14. package/dist/bin/sync-runner-company.test.d.ts.map +1 -0
  15. package/dist/bin/sync-runner-company.test.js +36 -0
  16. package/dist/bin/sync-runner-company.test.js.map +1 -0
  17. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  18. package/dist/bin/sync-runner-watch-loop.js +98 -8
  19. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  20. package/dist/bin/sync-runner.d.ts +17 -0
  21. package/dist/bin/sync-runner.d.ts.map +1 -1
  22. package/dist/bin/sync-runner.js.map +1 -1
  23. package/dist/bin/sync-runner.test.js +109 -0
  24. package/dist/bin/sync-runner.test.js.map +1 -1
  25. package/dist/cli/conflict-recovery.test.d.ts +2 -0
  26. package/dist/cli/conflict-recovery.test.d.ts.map +1 -0
  27. package/dist/cli/conflict-recovery.test.js +201 -0
  28. package/dist/cli/conflict-recovery.test.js.map +1 -0
  29. package/dist/cli/conflict.d.ts +60 -0
  30. package/dist/cli/conflict.d.ts.map +1 -1
  31. package/dist/cli/conflict.js +333 -0
  32. package/dist/cli/conflict.js.map +1 -1
  33. package/dist/cli/reindex-knowledge.d.ts +7 -0
  34. package/dist/cli/reindex-knowledge.d.ts.map +1 -0
  35. package/dist/cli/reindex-knowledge.js +389 -0
  36. package/dist/cli/reindex-knowledge.js.map +1 -0
  37. package/dist/cli/reindex-knowledge.test.d.ts +12 -0
  38. package/dist/cli/reindex-knowledge.test.d.ts.map +1 -0
  39. package/dist/cli/reindex-knowledge.test.js +260 -0
  40. package/dist/cli/reindex-knowledge.test.js.map +1 -0
  41. package/dist/cli/reindex.d.ts.map +1 -1
  42. package/dist/cli/reindex.js +8 -0
  43. package/dist/cli/reindex.js.map +1 -1
  44. package/dist/cli/rescue-settings-reconcile.test.js +47 -0
  45. package/dist/cli/rescue-settings-reconcile.test.js.map +1 -1
  46. package/dist/cli/sync.d.ts +27 -0
  47. package/dist/cli/sync.d.ts.map +1 -1
  48. package/dist/cli/sync.js +52 -0
  49. package/dist/cli/sync.js.map +1 -1
  50. package/dist/cli/sync.test.js +31 -1
  51. package/dist/cli/sync.test.js.map +1 -1
  52. package/dist/index.d.ts +2 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +1 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/skill-telemetry.d.ts +6 -0
  57. package/dist/skill-telemetry.d.ts.map +1 -1
  58. package/dist/skill-telemetry.js +14 -2
  59. package/dist/skill-telemetry.js.map +1 -1
  60. package/dist/skill-telemetry.test.js +79 -0
  61. package/dist/skill-telemetry.test.js.map +1 -1
  62. package/dist/sync/candidate-uploader.d.ts +88 -0
  63. package/dist/sync/candidate-uploader.d.ts.map +1 -0
  64. package/dist/sync/candidate-uploader.js +212 -0
  65. package/dist/sync/candidate-uploader.js.map +1 -0
  66. package/dist/sync/candidate-uploader.test.d.ts +2 -0
  67. package/dist/sync/candidate-uploader.test.d.ts.map +1 -0
  68. package/dist/sync/candidate-uploader.test.js +132 -0
  69. package/dist/sync/candidate-uploader.test.js.map +1 -0
  70. package/dist/sync/delta-client.d.ts +73 -0
  71. package/dist/sync/delta-client.d.ts.map +1 -0
  72. package/dist/sync/delta-client.js +201 -0
  73. package/dist/sync/delta-client.js.map +1 -0
  74. package/dist/sync/delta-client.test.d.ts +2 -0
  75. package/dist/sync/delta-client.test.d.ts.map +1 -0
  76. package/dist/sync/delta-client.test.js +97 -0
  77. package/dist/sync/delta-client.test.js.map +1 -0
  78. package/dist/sync/durable-apply.d.ts +76 -0
  79. package/dist/sync/durable-apply.d.ts.map +1 -0
  80. package/dist/sync/durable-apply.js +530 -0
  81. package/dist/sync/durable-apply.js.map +1 -0
  82. package/dist/sync/durable-apply.test.d.ts +2 -0
  83. package/dist/sync/durable-apply.test.d.ts.map +1 -0
  84. package/dist/sync/durable-apply.test.js +180 -0
  85. package/dist/sync/durable-apply.test.js.map +1 -0
  86. package/dist/sync/event-sync.d.ts +33 -1
  87. package/dist/sync/event-sync.d.ts.map +1 -1
  88. package/dist/sync/event-sync.js +149 -1
  89. package/dist/sync/event-sync.js.map +1 -1
  90. package/dist/sync/event-sync.test.js +142 -1
  91. package/dist/sync/event-sync.test.js.map +1 -1
  92. package/dist/sync/index.d.ts +2 -0
  93. package/dist/sync/index.d.ts.map +1 -1
  94. package/dist/sync/index.js +1 -0
  95. package/dist/sync/index.js.map +1 -1
  96. package/dist/sync/multipart-uploader.d.ts +99 -0
  97. package/dist/sync/multipart-uploader.d.ts.map +1 -0
  98. package/dist/sync/multipart-uploader.js +447 -0
  99. package/dist/sync/multipart-uploader.js.map +1 -0
  100. package/dist/sync/multipart-uploader.test.d.ts +2 -0
  101. package/dist/sync/multipart-uploader.test.d.ts.map +1 -0
  102. package/dist/sync/multipart-uploader.test.js +119 -0
  103. package/dist/sync/multipart-uploader.test.js.map +1 -0
  104. package/dist/sync/mutation-client.d.ts +82 -0
  105. package/dist/sync/mutation-client.d.ts.map +1 -0
  106. package/dist/sync/mutation-client.js +221 -0
  107. package/dist/sync/mutation-client.js.map +1 -0
  108. package/dist/sync/mutation-client.test.d.ts +2 -0
  109. package/dist/sync/mutation-client.test.d.ts.map +1 -0
  110. package/dist/sync/mutation-client.test.js +51 -0
  111. package/dist/sync/mutation-client.test.js.map +1 -0
  112. package/dist/sync/push-receiver.d.ts +45 -0
  113. package/dist/sync/push-receiver.d.ts.map +1 -1
  114. package/dist/sync/push-receiver.js +101 -0
  115. package/dist/sync/push-receiver.js.map +1 -1
  116. package/dist/sync/push-receiver.test.js +54 -2
  117. package/dist/sync/push-receiver.test.js.map +1 -1
  118. package/dist/sync/scope-inventory-client.d.ts +69 -0
  119. package/dist/sync/scope-inventory-client.d.ts.map +1 -0
  120. package/dist/sync/scope-inventory-client.js +210 -0
  121. package/dist/sync/scope-inventory-client.js.map +1 -0
  122. package/dist/sync/scope-inventory-client.test.d.ts +2 -0
  123. package/dist/sync/scope-inventory-client.test.d.ts.map +1 -0
  124. package/dist/sync/scope-inventory-client.test.js +94 -0
  125. package/dist/sync/scope-inventory-client.test.js.map +1 -0
  126. package/dist/sync/snapshot-client.d.ts +98 -0
  127. package/dist/sync/snapshot-client.d.ts.map +1 -0
  128. package/dist/sync/snapshot-client.js +402 -0
  129. package/dist/sync/snapshot-client.js.map +1 -0
  130. package/dist/sync/snapshot-client.test.d.ts +2 -0
  131. package/dist/sync/snapshot-client.test.d.ts.map +1 -0
  132. package/dist/sync/snapshot-client.test.js +169 -0
  133. package/dist/sync/snapshot-client.test.js.map +1 -0
  134. package/dist/sync/uploader-finalization.d.ts +97 -0
  135. package/dist/sync/uploader-finalization.d.ts.map +1 -0
  136. package/dist/sync/uploader-finalization.js +273 -0
  137. package/dist/sync/uploader-finalization.js.map +1 -0
  138. package/dist/sync/uploader-finalization.test.d.ts +2 -0
  139. package/dist/sync/uploader-finalization.test.d.ts.map +1 -0
  140. package/dist/sync/uploader-finalization.test.js +92 -0
  141. package/dist/sync/uploader-finalization.test.js.map +1 -0
  142. package/dist/telemetry.d.ts +11 -1
  143. package/dist/telemetry.d.ts.map +1 -1
  144. package/dist/telemetry.js +21 -2
  145. package/dist/telemetry.js.map +1 -1
  146. package/dist/telemetry.test.js +80 -0
  147. package/dist/telemetry.test.js.map +1 -1
  148. package/package.json +6 -1
  149. package/.claude/policies/hq-cloud-esm-cannot-spy-fs-builtins.md +0 -30
  150. package/.claude/policies/hq-cloud-strip-types-no-parameter-properties.md +0 -22
  151. package/.github/workflows/ci.yml +0 -84
  152. package/.github/workflows/publish.yml +0 -56
  153. package/.github/workflows/unreleased-commits-nag.yml +0 -256
  154. package/eslint.config.js +0 -67
  155. package/pnpm-workspace.yaml +0 -2
  156. package/scripts/presign-transport-e2e.mjs +0 -250
  157. package/scripts/vault-rebaseline.sh +0 -323
  158. package/scripts/vault-rescue.sh +0 -332
  159. package/src/active-company.test.ts +0 -188
  160. package/src/active-company.ts +0 -168
  161. package/src/agent-codex-instructions.test.ts +0 -332
  162. package/src/agent-codex-instructions.ts +0 -309
  163. package/src/auth.ts +0 -146
  164. package/src/backup-prune.test.ts +0 -98
  165. package/src/backup-prune.ts +0 -182
  166. package/src/bin/backup-prune-runner.ts +0 -33
  167. package/src/bin/rescue-runner.ts +0 -25
  168. package/src/bin/sync-runner-company.ts +0 -695
  169. package/src/bin/sync-runner-events.test.ts +0 -143
  170. package/src/bin/sync-runner-events.ts +0 -55
  171. package/src/bin/sync-runner-planning.test.ts +0 -311
  172. package/src/bin/sync-runner-planning.ts +0 -258
  173. package/src/bin/sync-runner-rollup.test.ts +0 -37
  174. package/src/bin/sync-runner-rollup.ts +0 -97
  175. package/src/bin/sync-runner-telemetry.ts +0 -15
  176. package/src/bin/sync-runner-watch-loop.ts +0 -1235
  177. package/src/bin/sync-runner-watch-routes.test.ts +0 -71
  178. package/src/bin/sync-runner-watch-routes.ts +0 -184
  179. package/src/bin/sync-runner.test.ts +0 -8767
  180. package/src/bin/sync-runner.ts +0 -2190
  181. package/src/cli/accept.ts +0 -124
  182. package/src/cli/conflict.ts +0 -119
  183. package/src/cli/doctor.test.ts +0 -581
  184. package/src/cli/doctor.ts +0 -642
  185. package/src/cli/index.ts +0 -49
  186. package/src/cli/invite.test.ts +0 -250
  187. package/src/cli/invite.ts +0 -214
  188. package/src/cli/promote.ts +0 -157
  189. package/src/cli/reindex.test.ts +0 -957
  190. package/src/cli/reindex.ts +0 -970
  191. package/src/cli/rescue-classify-ordering.test.ts +0 -548
  192. package/src/cli/rescue-clone-diagnostics.test.ts +0 -120
  193. package/src/cli/rescue-core.ts +0 -3011
  194. package/src/cli/rescue-drift-reconcile.test.ts +0 -179
  195. package/src/cli/rescue-drop-dir-symlink.test.ts +0 -224
  196. package/src/cli/rescue-exec-bit-preserve.test.ts +0 -187
  197. package/src/cli/rescue-hq-root-guard.test.ts +0 -232
  198. package/src/cli/rescue-journal-reconcile.test.ts +0 -215
  199. package/src/cli/rescue-mtime-preserve.test.ts +0 -203
  200. package/src/cli/rescue-settings-reconcile.test.ts +0 -583
  201. package/src/cli/rescue-snapshot.test.ts +0 -57
  202. package/src/cli/rescue-snapshot.ts +0 -51
  203. package/src/cli/rescue.reindex.test.ts +0 -63
  204. package/src/cli/rescue.test.ts +0 -131
  205. package/src/cli/rescue.ts +0 -182
  206. package/src/cli/share.test.ts +0 -7843
  207. package/src/cli/share.ts +0 -3663
  208. package/src/cli/sync-scope.test.ts +0 -652
  209. package/src/cli/sync.test.ts +0 -5207
  210. package/src/cli/sync.ts +0 -3470
  211. package/src/cli/tombstones.ts +0 -106
  212. package/src/cli/watch-event-push-conflict.test.ts +0 -234
  213. package/src/client-info.test.ts +0 -214
  214. package/src/client-info.ts +0 -121
  215. package/src/cognito-auth.test.ts +0 -712
  216. package/src/cognito-auth.ts +0 -1422
  217. package/src/company-resolver.test.ts +0 -618
  218. package/src/company-resolver.ts +0 -521
  219. package/src/context.test.ts +0 -583
  220. package/src/context.ts +0 -378
  221. package/src/daemon-worker.ts +0 -26
  222. package/src/daemon.ts +0 -99
  223. package/src/entity-resolver.test.ts +0 -315
  224. package/src/entity-resolver.ts +0 -180
  225. package/src/ignore.test.ts +0 -466
  226. package/src/ignore.ts +0 -469
  227. package/src/index.ts +0 -439
  228. package/src/journal.test.ts +0 -968
  229. package/src/journal.ts +0 -765
  230. package/src/lib/cloud-authoritative.test.ts +0 -45
  231. package/src/lib/cloud-authoritative.ts +0 -59
  232. package/src/lib/conflict-file.ts +0 -86
  233. package/src/lib/conflict-index.ts +0 -289
  234. package/src/lib/conflict.test.ts +0 -348
  235. package/src/lib/describe-error.test.ts +0 -100
  236. package/src/lib/describe-error.ts +0 -58
  237. package/src/lib/exit-codes.ts +0 -24
  238. package/src/lib/machine-id.test.ts +0 -231
  239. package/src/lib/machine-id.ts +0 -175
  240. package/src/lib/net-errors.test.ts +0 -65
  241. package/src/lib/net-errors.ts +0 -86
  242. package/src/lib/readlink-safe.test.ts +0 -43
  243. package/src/lib/readlink-safe.ts +0 -29
  244. package/src/local-path-codec.test.ts +0 -138
  245. package/src/local-path-codec.ts +0 -161
  246. package/src/machine-auth.test.ts +0 -1323
  247. package/src/manifest-reconcile.test.ts +0 -1123
  248. package/src/manifest-reconcile.ts +0 -518
  249. package/src/object-io.test.ts +0 -1221
  250. package/src/object-io.ts +0 -1306
  251. package/src/operation-lock.test.ts +0 -484
  252. package/src/operation-lock.ts +0 -680
  253. package/src/outcome-telemetry.test.ts +0 -498
  254. package/src/outcome-telemetry.ts +0 -639
  255. package/src/personal-vault-exclusions.test.ts +0 -308
  256. package/src/personal-vault-exclusions.ts +0 -354
  257. package/src/personal-vault.test.ts +0 -756
  258. package/src/personal-vault.ts +0 -496
  259. package/src/prefix-coalesce.test.ts +0 -240
  260. package/src/prefix-coalesce.ts +0 -273
  261. package/src/public-surface.test.ts +0 -117
  262. package/src/qmd-reindex.test.ts +0 -877
  263. package/src/qmd-reindex.ts +0 -842
  264. package/src/read-only-state-dir.test.ts +0 -188
  265. package/src/remote-pull.test.ts +0 -1130
  266. package/src/remote-pull.ts +0 -618
  267. package/src/s3.symlink-materialize.test.ts +0 -492
  268. package/src/s3.test.ts +0 -1789
  269. package/src/s3.ts +0 -1532
  270. package/src/schemas/signal-types.test.ts +0 -82
  271. package/src/schemas/signal-types.ts +0 -38
  272. package/src/schemas/source-channels.test.ts +0 -82
  273. package/src/schemas/source-channels.ts +0 -53
  274. package/src/scope-shrink.test.ts +0 -633
  275. package/src/scope-shrink.ts +0 -481
  276. package/src/signals/get.test.ts +0 -310
  277. package/src/signals/get.ts +0 -75
  278. package/src/signals/internals.ts +0 -195
  279. package/src/signals/list.test.ts +0 -420
  280. package/src/signals/list.ts +0 -79
  281. package/src/signals/parse.ts +0 -8
  282. package/src/signals/types.ts +0 -91
  283. package/src/skill-telemetry.test.ts +0 -1825
  284. package/src/skill-telemetry.ts +0 -1439
  285. package/src/sources/get.test.ts +0 -293
  286. package/src/sources/get.ts +0 -66
  287. package/src/sources/internals.ts +0 -198
  288. package/src/sources/list.test.ts +0 -402
  289. package/src/sources/list.ts +0 -84
  290. package/src/sources/parse.ts +0 -43
  291. package/src/sources/types.ts +0 -84
  292. package/src/sync/event-sync.test.ts +0 -594
  293. package/src/sync/event-sync.ts +0 -545
  294. package/src/sync/feature-flags.test.ts +0 -378
  295. package/src/sync/feature-flags.ts +0 -62
  296. package/src/sync/index.ts +0 -76
  297. package/src/sync/lease-client.test.ts +0 -128
  298. package/src/sync/lease-client.ts +0 -207
  299. package/src/sync/logger.test.ts +0 -242
  300. package/src/sync/logger.ts +0 -79
  301. package/src/sync/metrics.test.ts +0 -462
  302. package/src/sync/metrics.ts +0 -213
  303. package/src/sync/pull-scope.ts +0 -265
  304. package/src/sync/push-event.test.ts +0 -266
  305. package/src/sync/push-event.ts +0 -224
  306. package/src/sync/push-receiver.test.ts +0 -566
  307. package/src/sync/push-receiver.ts +0 -1048
  308. package/src/sync/push-transport.ts +0 -231
  309. package/src/sync/realtime-rollout.test.ts +0 -86
  310. package/src/sync/realtime-rollout.ts +0 -262
  311. package/src/sync/state-store.test.ts +0 -194
  312. package/src/sync/state-store.ts +0 -727
  313. package/src/sync-core.ts +0 -58
  314. package/src/sync-progress.test.ts +0 -94
  315. package/src/sync-progress.ts +0 -140
  316. package/src/telemetry-events.test.ts +0 -88
  317. package/src/telemetry-events.ts +0 -205
  318. package/src/telemetry.test.ts +0 -1280
  319. package/src/telemetry.ts +0 -1109
  320. package/src/types.ts +0 -314
  321. package/src/vault-client.test.ts +0 -1380
  322. package/src/vault-client.ts +0 -1694
  323. package/src/version.ts +0 -24
  324. package/src/watch-roots.test.ts +0 -278
  325. package/src/watch-roots.ts +0 -162
  326. package/src/watcher-event-gate.test.ts +0 -212
  327. package/src/watcher.test.ts +0 -1079
  328. package/src/watcher.ts +0 -1741
  329. package/test/e2e/sync/cross-tenant-isolation.test.ts +0 -630
  330. package/test/e2e/sync/skill-telemetry-oversized-transcript.test.ts +0 -124
  331. package/test/e2e/sync/transient-company-leg.test.ts +0 -384
  332. package/test/e2e/sync/windows-unreadable-link-leg.test.ts +0 -191
  333. package/test/e2e/watcher-real-chokidar.test.ts +0 -165
  334. package/test/e2e/watcher-recursive-backend.test.ts +0 -181
  335. package/test/e2e/watcher-scoped-coverage.test.ts +0 -381
  336. package/test/invite-flow.integration.test.ts +0 -244
  337. package/test/joiner-manifest-reconcile.integration.test.ts +0 -322
  338. package/test/share-sync.integration.test.ts +0 -213
  339. package/tsconfig.json +0 -19
  340. package/vitest.config.ts +0 -22
@@ -1,250 +0,0 @@
1
- /**
2
- * invite CLI command tests (VLT-7 US-002).
3
- */
4
-
5
- import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from "vitest";
6
- import { invite, listInvites, revokeInvite } from "./invite.js";
7
- import type { VaultServiceConfig } from "../types.js";
8
-
9
- // ---------------------------------------------------------------------------
10
- // Helpers
11
- // ---------------------------------------------------------------------------
12
-
13
- function jsonResponse(status: number, body: unknown): Response {
14
- return new Response(JSON.stringify(body), {
15
- status,
16
- headers: { "Content-Type": "application/json" },
17
- });
18
- }
19
-
20
- const VAULT_CONFIG: VaultServiceConfig = {
21
- apiUrl: "https://vault.test.example.com",
22
- authToken: "test-token",
23
- };
24
-
25
- let fetchSpy: MockInstance<typeof fetch>;
26
-
27
- beforeEach(() => {
28
- fetchSpy = vi.spyOn(globalThis, "fetch");
29
- });
30
-
31
- afterEach(() => {
32
- vi.restoreAllMocks();
33
- });
34
-
35
- // ---------------------------------------------------------------------------
36
- // invite()
37
- // ---------------------------------------------------------------------------
38
-
39
- describe("invite", () => {
40
- it("creates invite for email target and returns magic link", async () => {
41
- // First call: entity.findBySlug to resolve company
42
- // (PR 4 reverted the CLI-side namespace-aware switch; will land
43
- // as a follow-up commit once the cascading test-fixture updates
44
- // can be batched cleanly.)
45
- fetchSpy
46
- .mockResolvedValueOnce(
47
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
48
- )
49
- // Second call: createInvite
50
- .mockResolvedValueOnce(
51
- jsonResponse(200, {
52
- membership: { membershipKey: "psn_1#cmp_abc", role: "member", status: "pending" },
53
- inviteToken: "tok_secure123",
54
- }),
55
- );
56
-
57
- const result = await invite({
58
- target: "alice@example.com",
59
- role: "member",
60
- company: "acme",
61
- vaultConfig: VAULT_CONFIG,
62
- callerUid: "psn_admin",
63
- });
64
-
65
- expect(result.magicLink).toBe("hq://accept/tok_secure123");
66
- expect(result.inviteToken).toBe("tok_secure123");
67
- expect(result.membership.status).toBe("pending");
68
- });
69
-
70
- it("creates invite for person UID target", async () => {
71
- // Company is already a UID — no entity lookup needed
72
- fetchSpy.mockResolvedValueOnce(
73
- jsonResponse(200, {
74
- membership: { membershipKey: "psn_bob#cmp_abc", role: "admin", status: "pending" },
75
- inviteToken: "tok_456",
76
- }),
77
- );
78
-
79
- const result = await invite({
80
- target: "psn_bob",
81
- role: "admin",
82
- company: "cmp_abc",
83
- vaultConfig: VAULT_CONFIG,
84
- callerUid: "psn_admin",
85
- });
86
-
87
- expect(result.magicLink).toBe("hq://accept/tok_456");
88
-
89
- // Should have called createInvite with personUid, not inviteeEmail
90
- const body = JSON.parse(fetchSpy.mock.calls[0][1]?.body as string);
91
- expect(body.personUid).toBe("psn_bob");
92
- expect(body.inviteeEmail).toBeUndefined();
93
- });
94
-
95
- it("rejects --paths without --role guest", async () => {
96
- await expect(
97
- invite({
98
- target: "alice@example.com",
99
- role: "member",
100
- paths: "docs/",
101
- company: "acme",
102
- vaultConfig: VAULT_CONFIG,
103
- callerUid: "psn_admin",
104
- }),
105
- ).rejects.toThrow("--paths is only valid with --role guest");
106
- });
107
-
108
- it("allows --paths with --role guest", async () => {
109
- fetchSpy
110
- .mockResolvedValueOnce(
111
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
112
- )
113
- .mockResolvedValueOnce(
114
- jsonResponse(200, {
115
- membership: { membershipKey: "psn_1#cmp_abc", role: "guest", status: "pending", allowedPrefixes: ["docs/", "shared/"] },
116
- inviteToken: "tok_guest",
117
- }),
118
- );
119
-
120
- const result = await invite({
121
- target: "alice@example.com",
122
- role: "guest",
123
- paths: "docs/, shared/",
124
- company: "acme",
125
- vaultConfig: VAULT_CONFIG,
126
- callerUid: "psn_admin",
127
- });
128
-
129
- expect(result.membership.allowedPrefixes).toEqual(["docs/", "shared/"]);
130
-
131
- // Verify allowedPrefixes sent to API
132
- const body = JSON.parse(fetchSpy.mock.calls[1][1]?.body as string);
133
- expect(body.allowedPrefixes).toEqual(["docs/", "shared/"]);
134
- });
135
-
136
- it("maps VaultPermissionDeniedError to human-readable message", async () => {
137
- fetchSpy
138
- .mockResolvedValueOnce(
139
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
140
- )
141
- .mockResolvedValueOnce(
142
- jsonResponse(403, { message: "Admin required" }),
143
- );
144
-
145
- await expect(
146
- invite({
147
- target: "alice@example.com",
148
- company: "acme",
149
- vaultConfig: VAULT_CONFIG,
150
- callerUid: "psn_member",
151
- }),
152
- ).rejects.toThrow("Permission denied — only admins and owners can invite members");
153
- });
154
-
155
- it("throws when no company specified", async () => {
156
- await expect(
157
- invite({
158
- target: "alice@example.com",
159
- vaultConfig: VAULT_CONFIG,
160
- callerUid: "psn_admin",
161
- }),
162
- ).rejects.toThrow("No company specified");
163
- });
164
-
165
- it("maps VaultConflictError to human-readable message", async () => {
166
- fetchSpy
167
- .mockResolvedValueOnce(
168
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
169
- )
170
- .mockResolvedValueOnce(
171
- jsonResponse(409, { message: "Already exists" }),
172
- );
173
-
174
- await expect(
175
- invite({
176
- target: "alice@example.com",
177
- company: "acme",
178
- vaultConfig: VAULT_CONFIG,
179
- callerUid: "psn_admin",
180
- }),
181
- ).rejects.toThrow("already has a membership or pending invite");
182
- });
183
- });
184
-
185
- // ---------------------------------------------------------------------------
186
- // listInvites()
187
- // ---------------------------------------------------------------------------
188
-
189
- describe("listInvites", () => {
190
- it("returns pending invites for a company", async () => {
191
- fetchSpy
192
- .mockResolvedValueOnce(
193
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
194
- )
195
- .mockResolvedValueOnce(
196
- jsonResponse(200, {
197
- invites: [
198
- { membershipKey: "psn_1#cmp_abc", status: "pending", role: "member" },
199
- { membershipKey: "psn_2#cmp_abc", status: "pending", role: "guest" },
200
- ],
201
- }),
202
- );
203
-
204
- const invites = await listInvites({
205
- company: "acme",
206
- vaultConfig: VAULT_CONFIG,
207
- callerUid: "psn_admin",
208
- });
209
-
210
- expect(invites).toHaveLength(2);
211
- });
212
- });
213
-
214
- // ---------------------------------------------------------------------------
215
- // revokeInvite()
216
- // ---------------------------------------------------------------------------
217
-
218
- describe("revokeInvite", () => {
219
- it("revokes a pending invite", async () => {
220
- fetchSpy
221
- .mockResolvedValueOnce(
222
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
223
- )
224
- .mockResolvedValueOnce(new Response(null, { status: 204 }));
225
-
226
- await expect(
227
- revokeInvite({
228
- tokenOrKey: "psn_1#cmp_abc",
229
- company: "acme",
230
- vaultConfig: VAULT_CONFIG,
231
- }),
232
- ).resolves.toBeUndefined();
233
- });
234
-
235
- it("maps 404 to human-readable message", async () => {
236
- fetchSpy
237
- .mockResolvedValueOnce(
238
- jsonResponse(200, { entity: { uid: "cmp_abc", slug: "acme", type: "company", status: "active" } }),
239
- )
240
- .mockResolvedValueOnce(jsonResponse(404, { message: "Not found" }));
241
-
242
- await expect(
243
- revokeInvite({
244
- tokenOrKey: "psn_1#cmp_abc",
245
- company: "acme",
246
- vaultConfig: VAULT_CONFIG,
247
- }),
248
- ).rejects.toThrow("Invite not found");
249
- });
250
- });
package/src/cli/invite.ts DELETED
@@ -1,214 +0,0 @@
1
- /**
2
- * `hq invite` command — create pending membership + magic link (VLT-7 US-002).
3
- *
4
- * Thin UX layer over VaultClient.createInvite(). Handles arg parsing,
5
- * validation (paths only with guest role), and formats the magic link output.
6
- */
7
-
8
- import type { VaultServiceConfig } from "../types.js";
9
- import {
10
- VaultClient,
11
- VaultAuthError,
12
- VaultPermissionDeniedError,
13
- VaultNotFoundError,
14
- VaultConflictError,
15
- } from "../vault-client.js";
16
- import type { MembershipRole, Membership } from "../vault-client.js";
17
- import { emitCloudTelemetry } from "../telemetry-events.js";
18
-
19
- export interface InviteOptions {
20
- /** Target — email address or person slug/uid */
21
- target: string;
22
- /** Role for the invitee (default: member) */
23
- role?: MembershipRole;
24
- /** Comma-separated allowed prefixes (only valid with role=guest) */
25
- paths?: string;
26
- /** Company slug or UID (defaults to active company) */
27
- company?: string;
28
- /** Vault service config */
29
- vaultConfig: VaultServiceConfig;
30
- /** Caller's person UID */
31
- callerUid: string;
32
- }
33
-
34
- export interface InviteResult {
35
- inviteToken: string;
36
- magicLink: string;
37
- membership: Membership;
38
- }
39
-
40
- export interface InviteListOptions {
41
- company?: string;
42
- vaultConfig: VaultServiceConfig;
43
- callerUid: string;
44
- }
45
-
46
- export interface InviteRevokeOptions {
47
- tokenOrKey: string;
48
- /** Company slug or UID — required so the server can authorize the caller */
49
- company: string;
50
- vaultConfig: VaultServiceConfig;
51
- }
52
-
53
- /**
54
- * Create a pending membership invite and return a magic link.
55
- */
56
- export async function invite(options: InviteOptions): Promise<InviteResult> {
57
- const { target, role = "member", paths, company, vaultConfig, callerUid } = options;
58
-
59
- // Validate: --paths only with --role guest
60
- if (paths && role !== "guest") {
61
- throw new Error("--paths is only valid with --role guest (allowedPrefixes are only meaningful for the guest role)");
62
- }
63
-
64
- const client = new VaultClient(vaultConfig);
65
-
66
- // Resolve company UID
67
- const companyUid = await resolveCompanyUid(client, company);
68
-
69
- // Parse paths
70
- const allowedPrefixes = paths
71
- ? paths.split(",").map((p) => p.trim()).filter(Boolean)
72
- : undefined;
73
-
74
- // Determine if target is email or person identifier
75
- const isEmail = target.includes("@");
76
-
77
- try {
78
- const result = await client.createInvite({
79
- ...(isEmail ? { inviteeEmail: target } : { personUid: target }),
80
- companyUid,
81
- role,
82
- allowedPrefixes,
83
- invitedBy: callerUid,
84
- });
85
-
86
- const magicLink = `hq://accept/${result.inviteToken}`;
87
- void emitCloudTelemetry(client, {
88
- eventName: "membership_invite",
89
- source: "hq-cli",
90
- companyUid,
91
- properties: {
92
- role,
93
- result: "success",
94
- targetType: isEmail ? "email" : "person",
95
- allowedPrefixCount: allowedPrefixes?.length ?? 0,
96
- },
97
- });
98
-
99
- return {
100
- inviteToken: result.inviteToken,
101
- magicLink,
102
- membership: result.membership,
103
- };
104
- } catch (err) {
105
- void emitCloudTelemetry(client, {
106
- eventName: "membership_invite",
107
- source: "hq-cli",
108
- companyUid,
109
- properties: {
110
- role,
111
- result: "failure",
112
- errorCode: classifyInviteError(err),
113
- targetType: isEmail ? "email" : "person",
114
- allowedPrefixCount: allowedPrefixes?.length ?? 0,
115
- },
116
- });
117
- if (err instanceof VaultAuthError) {
118
- throw new Error("Authentication failed — run `hq auth` to refresh your session");
119
- }
120
- if (err instanceof VaultPermissionDeniedError) {
121
- throw new Error("Permission denied — only admins and owners can invite members");
122
- }
123
- if (err instanceof VaultConflictError) {
124
- throw new Error("This person already has a membership or pending invite for this company");
125
- }
126
- throw err;
127
- }
128
- }
129
-
130
- function classifyInviteError(err: unknown): string {
131
- if (err instanceof VaultAuthError) return "auth";
132
- if (err instanceof VaultPermissionDeniedError) return "permission";
133
- if (err instanceof VaultConflictError) return "conflict";
134
- return "error";
135
- }
136
-
137
- /**
138
- * List pending invites for a company.
139
- */
140
- export async function listInvites(options: InviteListOptions): Promise<Membership[]> {
141
- const { company, vaultConfig } = options;
142
- const client = new VaultClient(vaultConfig);
143
- const companyUid = await resolveCompanyUid(client, company);
144
-
145
- try {
146
- return await client.listPendingInvites(companyUid);
147
- } catch (err) {
148
- if (err instanceof VaultAuthError) {
149
- throw new Error("Authentication failed — run `hq auth` to refresh your session");
150
- }
151
- if (err instanceof VaultPermissionDeniedError) {
152
- throw new Error("Permission denied — only admins and owners can list invites");
153
- }
154
- throw err;
155
- }
156
- }
157
-
158
- /**
159
- * Revoke a pending invite.
160
- */
161
- export async function revokeInvite(options: InviteRevokeOptions): Promise<void> {
162
- const { tokenOrKey, company, vaultConfig } = options;
163
- const client = new VaultClient(vaultConfig);
164
- const companyUid = await resolveCompanyUid(client, company);
165
-
166
- try {
167
- await client.revokeMembership(tokenOrKey, companyUid);
168
- } catch (err) {
169
- if (err instanceof VaultAuthError) {
170
- throw new Error("Authentication failed — run `hq auth` to refresh your session");
171
- }
172
- if (err instanceof VaultPermissionDeniedError) {
173
- throw new Error("Permission denied — only admins and owners can revoke invites");
174
- }
175
- if (err instanceof VaultNotFoundError) {
176
- throw new Error("Invite not found — it may have already been accepted or revoked");
177
- }
178
- throw err;
179
- }
180
- }
181
-
182
- // ---------------------------------------------------------------------------
183
- // Helpers
184
- // ---------------------------------------------------------------------------
185
-
186
- async function resolveCompanyUid(
187
- client: VaultClient,
188
- companyRef?: string,
189
- ): Promise<string> {
190
- if (!companyRef) {
191
- throw new Error(
192
- "No company specified. Use --company <slug> or set up .hq/config.json",
193
- );
194
- }
195
-
196
- // If already a UID, return it
197
- if (companyRef.startsWith("cmp_")) {
198
- return companyRef;
199
- }
200
-
201
- // Resolve slug → UID via entity registry. TODO(slug-namespace-PR4-followup):
202
- // switch to `findInMyNamespace` for per-user semantics; reverted in
203
- // this PR to keep test surface manageable. The new vault-client
204
- // method is already wired and ready when this is re-enabled.
205
- try {
206
- const entity = await client.entity.findBySlug("company", companyRef);
207
- return entity.uid;
208
- } catch (err) {
209
- if (err instanceof VaultNotFoundError) {
210
- throw new Error(`Company "${companyRef}" not found in the vault registry`);
211
- }
212
- throw err;
213
- }
214
- }
@@ -1,157 +0,0 @@
1
- /**
2
- * `hq promote` command — change an existing member's role (VLT-7 US-003).
3
- *
4
- * Admin+ only. Surfaces last-owner demotion errors as human messages.
5
- */
6
-
7
- import type { VaultServiceConfig } from "../types.js";
8
- import {
9
- VaultClient,
10
- VaultAuthError,
11
- VaultPermissionDeniedError,
12
- VaultNotFoundError,
13
- VaultConflictError,
14
- } from "../vault-client.js";
15
- import type { MembershipRole, Membership } from "../vault-client.js";
16
- import { emitCloudTelemetry } from "../telemetry-events.js";
17
-
18
- export interface PromoteOptions {
19
- /** Person slug or UID of the member to promote */
20
- target: string;
21
- /** New role to assign */
22
- newRole: MembershipRole;
23
- /** Allowed prefixes (only valid with guest role) */
24
- paths?: string;
25
- /** Company slug or UID */
26
- company?: string;
27
- /** Caller's person UID */
28
- callerUid: string;
29
- /** Vault service config */
30
- vaultConfig: VaultServiceConfig;
31
- }
32
-
33
- export interface PromoteResult {
34
- membership: Membership;
35
- previousRole?: MembershipRole;
36
- }
37
-
38
- /**
39
- * Change a member's role.
40
- */
41
- export async function promote(options: PromoteOptions): Promise<PromoteResult> {
42
- const { target, newRole, paths, company, callerUid, vaultConfig } = options;
43
-
44
- // Validate: --paths only with guest role
45
- if (paths && newRole !== "guest") {
46
- throw new Error("--paths is only valid with --role guest (allowedPrefixes are only meaningful for the guest role)");
47
- }
48
-
49
- const client = new VaultClient(vaultConfig);
50
-
51
- // Resolve company UID
52
- const companyUid = await resolveCompanyUid(client, company);
53
-
54
- // Build membership key from target + company
55
- const membershipKey = buildMembershipKey(target, companyUid);
56
-
57
- const allowedPrefixes = paths
58
- ? paths.split(",").map((p) => p.trim()).filter(Boolean)
59
- : undefined;
60
-
61
- try {
62
- const membership = await client.updateRole({
63
- membershipKey,
64
- newRole,
65
- allowedPrefixes,
66
- updaterUid: callerUid,
67
- companyUid,
68
- });
69
-
70
- void emitCloudTelemetry(client, {
71
- eventName: "membership_promote",
72
- source: "hq-cli",
73
- companyUid,
74
- properties: {
75
- role: newRole,
76
- result: "success",
77
- allowedPrefixCount: allowedPrefixes?.length ?? 0,
78
- },
79
- });
80
-
81
- return { membership };
82
- } catch (err) {
83
- void emitCloudTelemetry(client, {
84
- eventName: "membership_promote",
85
- source: "hq-cli",
86
- companyUid,
87
- properties: {
88
- role: newRole,
89
- result: "failure",
90
- errorCode: classifyPromoteError(err),
91
- allowedPrefixCount: allowedPrefixes?.length ?? 0,
92
- },
93
- });
94
- if (err instanceof VaultAuthError) {
95
- throw new Error("Authentication failed — run `hq auth` to refresh your session");
96
- }
97
- if (err instanceof VaultPermissionDeniedError) {
98
- throw new Error("Permission denied — only admins and owners can change member roles");
99
- }
100
- if (err instanceof VaultNotFoundError) {
101
- throw new Error(`Member "${target}" not found in this company`);
102
- }
103
- if (err instanceof VaultConflictError) {
104
- throw new Error("Cannot leave company without an owner — promote another member to owner first");
105
- }
106
- throw err;
107
- }
108
- }
109
-
110
- function classifyPromoteError(err: unknown): string {
111
- if (err instanceof VaultAuthError) return "auth";
112
- if (err instanceof VaultPermissionDeniedError) return "permission";
113
- if (err instanceof VaultNotFoundError) return "not_found";
114
- if (err instanceof VaultConflictError) return "conflict";
115
- return "error";
116
- }
117
-
118
- // ---------------------------------------------------------------------------
119
- // Helpers
120
- // ---------------------------------------------------------------------------
121
-
122
- function buildMembershipKey(personRef: string, companyUid: string): string {
123
- // If already a composite key, use as-is
124
- if (personRef.includes("#")) {
125
- return personRef;
126
- }
127
- // Build composite key: personUid#companyUid
128
- return `${personRef}#${companyUid}`;
129
- }
130
-
131
- async function resolveCompanyUid(
132
- client: VaultClient,
133
- companyRef?: string,
134
- ): Promise<string> {
135
- if (!companyRef) {
136
- throw new Error(
137
- "No company specified. Use --company <slug> or set up .hq/config.json",
138
- );
139
- }
140
-
141
- if (companyRef.startsWith("cmp_")) {
142
- return companyRef;
143
- }
144
-
145
- // TODO(slug-namespace-PR4-followup): switch to `findInMyNamespace`
146
- // for per-user semantics; reverted in this PR to keep test surface
147
- // manageable. The new vault-client method is already wired.
148
- try {
149
- const entity = await client.entity.findBySlug("company", companyRef);
150
- return entity.uid;
151
- } catch (err) {
152
- if (err instanceof VaultNotFoundError) {
153
- throw new Error(`Company "${companyRef}" not found in the vault registry`);
154
- }
155
- throw err;
156
- }
157
- }