@indigoai-us/hq-cli 5.77.14 → 5.78.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 (308) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/assets/scaffold/core/scripts/archive-old-threads.sh +86 -0
  3. package/assets/scaffold/core/scripts/backfill-company-skill-mirrors.sh +73 -0
  4. package/assets/scaffold/core/scripts/backfill-workspace-mirror.sh +51 -0
  5. package/assets/scaffold/core/scripts/codex-skill-bridge.sh +550 -0
  6. package/assets/scaffold/core/scripts/detect-stale-core-policy-mirror.sh +185 -0
  7. package/assets/scaffold/core/scripts/hq-status-summary.sh +187 -0
  8. package/assets/scaffold/core/scripts/ontology-readme-drift.sh +264 -0
  9. package/assets/scaffold/core/scripts/qmd-reindex-after-sync.sh +93 -0
  10. package/assets/scaffold/core/scripts/rebuild-all-indexes.sh +69 -0
  11. package/assets/scaffold/core/scripts/rebuild-companies-index.sh +206 -0
  12. package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +127 -0
  13. package/assets/scaffold/core/scripts/rebuild-orchestrator-index.sh +86 -0
  14. package/assets/scaffold/core/scripts/rebuild-projects-index.sh +105 -0
  15. package/assets/scaffold/core/scripts/rebuild-public-knowledge-index.sh +83 -0
  16. package/assets/scaffold/core/scripts/rebuild-reports-index.sh +114 -0
  17. package/assets/scaffold/core/scripts/rebuild-social-drafts-index.sh +135 -0
  18. package/assets/scaffold/core/scripts/rebuild-threads-index.sh +82 -0
  19. package/assets/scaffold/core/scripts/rebuild-workers-index.sh +97 -0
  20. package/assets/scaffold/core/scripts/resize-screenshot.sh +47 -0
  21. package/assets/scaffold/core/scripts/token-usage-report.sh +254 -0
  22. package/assets/scaffold/core/scripts/worktree.sh +136 -0
  23. package/dist/commands/agents.js +28 -12
  24. package/dist/commands/api-keys.js +100 -20
  25. package/dist/commands/core.d.ts +90 -0
  26. package/dist/commands/core.js +279 -0
  27. package/dist/commands/files-browse.d.ts +21 -0
  28. package/dist/commands/files-browse.js +145 -24
  29. package/dist/commands/files.js +33 -7
  30. package/dist/commands/members.js +16 -5
  31. package/dist/commands/pack-install.d.ts +14 -0
  32. package/dist/commands/pack-install.js +42 -2
  33. package/dist/commands/pkg-install.js +39 -2
  34. package/dist/commands/run.js +6 -2
  35. package/dist/commands/secrets.js +120 -65
  36. package/dist/main.js +6 -0
  37. package/dist/utils/api-key-command-gate.d.ts +45 -0
  38. package/dist/utils/api-key-command-gate.js +51 -0
  39. package/dist/utils/hq-roots.d.ts +91 -0
  40. package/dist/utils/hq-roots.js +212 -0
  41. package/dist/utils/resolve-vault-credential.d.ts +63 -3
  42. package/dist/utils/resolve-vault-credential.js +152 -6
  43. package/dist/utils/run-bundled-script.d.ts +66 -0
  44. package/dist/utils/run-bundled-script.js +80 -0
  45. package/dist/utils/vault-api.d.ts +21 -0
  46. package/dist/utils/vault-api.js +74 -3
  47. package/package.json +7 -1
  48. package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
  49. package/.github/workflows/ci.yml +0 -46
  50. package/.github/workflows/publish.yml +0 -36
  51. package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
  52. package/e2e/cli.test.ts +0 -128
  53. package/eslint.config.js +0 -37
  54. package/pnpm-workspace.yaml +0 -4
  55. package/scripts/chmod-bins.mjs +0 -49
  56. package/scripts/generate-dsn.mjs +0 -26
  57. package/scripts/generate-scan-packages-table.mjs +0 -113
  58. package/scripts/smoke-sources-signals.sh +0 -103
  59. package/src/bin/hq-auth-refresh.ts +0 -43
  60. package/src/cli-version.ts +0 -13
  61. package/src/commands/__fixtures__/make-tar.ts +0 -126
  62. package/src/commands/_patterns.ts +0 -10
  63. package/src/commands/add.ts +0 -75
  64. package/src/commands/agents.test.ts +0 -527
  65. package/src/commands/agents.ts +0 -923
  66. package/src/commands/api-keys.test.ts +0 -291
  67. package/src/commands/api-keys.ts +0 -382
  68. package/src/commands/artifact-verify.test.ts +0 -177
  69. package/src/commands/auth.test.ts +0 -82
  70. package/src/commands/auth.ts +0 -213
  71. package/src/commands/billing.test.ts +0 -158
  72. package/src/commands/billing.ts +0 -146
  73. package/src/commands/channels.test.ts +0 -74
  74. package/src/commands/channels.ts +0 -91
  75. package/src/commands/cloud-demote.test.ts +0 -401
  76. package/src/commands/cloud-demote.ts +0 -278
  77. package/src/commands/cloud-provision.test.ts +0 -1117
  78. package/src/commands/cloud-provision.ts +0 -942
  79. package/src/commands/cloud.pull-all.test.ts +0 -711
  80. package/src/commands/cloud.pull-per-company.test.ts +0 -188
  81. package/src/commands/cloud.push-all.test.ts +0 -485
  82. package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
  83. package/src/commands/cloud.selectors.test.ts +0 -208
  84. package/src/commands/cloud.status.test.ts +0 -160
  85. package/src/commands/cloud.test.ts +0 -41
  86. package/src/commands/cloud.ts +0 -2130
  87. package/src/commands/company.test.ts +0 -202
  88. package/src/commands/company.ts +0 -148
  89. package/src/commands/creators.test.ts +0 -60
  90. package/src/commands/creators.ts +0 -117
  91. package/src/commands/crm.test.ts +0 -179
  92. package/src/commands/crm.ts +0 -236
  93. package/src/commands/db-migrate.ts +0 -55
  94. package/src/commands/db-provision.ts +0 -114
  95. package/src/commands/db-sql.ts +0 -124
  96. package/src/commands/db-status.ts +0 -108
  97. package/src/commands/db.ts +0 -26
  98. package/src/commands/dm.test.ts +0 -748
  99. package/src/commands/dm.ts +0 -1226
  100. package/src/commands/feedback.test.ts +0 -413
  101. package/src/commands/feedback.ts +0 -169
  102. package/src/commands/files-browse.test.ts +0 -1249
  103. package/src/commands/files-browse.ts +0 -1506
  104. package/src/commands/files-delete.test.ts +0 -484
  105. package/src/commands/files-recovery.test.ts +0 -370
  106. package/src/commands/files.test.ts +0 -722
  107. package/src/commands/files.ts +0 -1446
  108. package/src/commands/group-grants.test.ts +0 -330
  109. package/src/commands/group-grants.ts +0 -455
  110. package/src/commands/groups.test.ts +0 -44
  111. package/src/commands/groups.ts +0 -368
  112. package/src/commands/integrations.test.ts +0 -633
  113. package/src/commands/integrations.ts +0 -507
  114. package/src/commands/list.ts +0 -85
  115. package/src/commands/login.ts +0 -52
  116. package/src/commands/logout.ts +0 -30
  117. package/src/commands/marketplace-install.test.ts +0 -543
  118. package/src/commands/marketplace-security.test.ts +0 -646
  119. package/src/commands/mcp-registration.test.ts +0 -2787
  120. package/src/commands/mcp-registration.ts +0 -2612
  121. package/src/commands/mcp-status.test.ts +0 -483
  122. package/src/commands/mcp-status.ts +0 -575
  123. package/src/commands/mcp-status.us011.test.ts +0 -243
  124. package/src/commands/meetings.test.ts +0 -522
  125. package/src/commands/meetings.ts +0 -789
  126. package/src/commands/members.test.ts +0 -1474
  127. package/src/commands/members.ts +0 -1181
  128. package/src/commands/onboard-identity-guard.test.ts +0 -99
  129. package/src/commands/onboard-identity-guard.ts +0 -103
  130. package/src/commands/onboard-join.test.ts +0 -96
  131. package/src/commands/onboard-join.ts +0 -101
  132. package/src/commands/onboard-warning.test.ts +0 -26
  133. package/src/commands/onboard-warning.ts +0 -12
  134. package/src/commands/onboard.ts +0 -267
  135. package/src/commands/outposts-heartbeat.test.ts +0 -299
  136. package/src/commands/outposts-heartbeat.ts +0 -310
  137. package/src/commands/outposts-replica-sync.test.ts +0 -272
  138. package/src/commands/outposts-self-deploy.test.ts +0 -243
  139. package/src/commands/outposts.test.ts +0 -1039
  140. package/src/commands/outposts.ts +0 -1935
  141. package/src/commands/pack-install-secret-authorization.test.ts +0 -115
  142. package/src/commands/pack-install.test.ts +0 -1469
  143. package/src/commands/pack-install.ts +0 -2256
  144. package/src/commands/pack-update-cache.test.ts +0 -149
  145. package/src/commands/packs-update-api-key.test.ts +0 -105
  146. package/src/commands/packs.test.ts +0 -88
  147. package/src/commands/packs.ts +0 -622
  148. package/src/commands/people.test.ts +0 -807
  149. package/src/commands/people.ts +0 -422
  150. package/src/commands/pkg-install.dispatch.test.ts +0 -103
  151. package/src/commands/pkg-install.ts +0 -221
  152. package/src/commands/pkg-list.test.ts +0 -79
  153. package/src/commands/pkg-list.ts +0 -13
  154. package/src/commands/pkg-remove.ts +0 -71
  155. package/src/commands/pkg-update.ts +0 -189
  156. package/src/commands/publish.test.ts +0 -650
  157. package/src/commands/publish.ts +0 -580
  158. package/src/commands/reindex.test.ts +0 -259
  159. package/src/commands/reindex.ts +0 -274
  160. package/src/commands/rescue.test.ts +0 -39
  161. package/src/commands/rescue.ts +0 -210
  162. package/src/commands/run.env-local.test.ts +0 -88
  163. package/src/commands/run.test.ts +0 -45
  164. package/src/commands/run.ts +0 -190
  165. package/src/commands/safe-extract.test.ts +0 -459
  166. package/src/commands/safe-extract.ts +0 -444
  167. package/src/commands/secrets-scope.test.ts +0 -56
  168. package/src/commands/secrets-scope.ts +0 -32
  169. package/src/commands/secrets.parse-destination.test.ts +0 -38
  170. package/src/commands/secrets.test.ts +0 -2050
  171. package/src/commands/secrets.ts +0 -2249
  172. package/src/commands/signals.ts +0 -351
  173. package/src/commands/skill.test.ts +0 -770
  174. package/src/commands/skill.ts +0 -796
  175. package/src/commands/sources.ts +0 -362
  176. package/src/commands/sync-mode.test.ts +0 -366
  177. package/src/commands/sync-mode.ts +0 -387
  178. package/src/commands/sync-narrow.test.ts +0 -633
  179. package/src/commands/sync-narrow.ts +0 -555
  180. package/src/commands/sync.ts +0 -165
  181. package/src/commands/team-sync.ts +0 -628
  182. package/src/commands/update.ts +0 -71
  183. package/src/commands/whoami.ts +0 -83
  184. package/src/commands/workers.test.ts +0 -158
  185. package/src/commands/workers.ts +0 -301
  186. package/src/index.test.ts +0 -32
  187. package/src/index.ts +0 -20
  188. package/src/lib/db/control-plane.test.ts +0 -59
  189. package/src/lib/db/control-plane.ts +0 -113
  190. package/src/lib/db/local.test.ts +0 -81
  191. package/src/lib/db/local.ts +0 -148
  192. package/src/lib/db/migrate.test.ts +0 -133
  193. package/src/lib/db/migrate.ts +0 -137
  194. package/src/lib/db/paths.test.ts +0 -112
  195. package/src/lib/db/paths.ts +0 -128
  196. package/src/lib/db/remote-engine.test.ts +0 -44
  197. package/src/lib/db/remote-engine.ts +0 -148
  198. package/src/lib/db/remote-sql.test.ts +0 -32
  199. package/src/lib/db/remote-sql.ts +0 -62
  200. package/src/lib/db/sql.test.ts +0 -106
  201. package/src/lib/db/sql.ts +0 -192
  202. package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
  203. package/src/lib/local-tree-diff.test.ts +0 -301
  204. package/src/lib/local-tree-diff.ts +0 -362
  205. package/src/lib/narrow-hint-banner.test.ts +0 -235
  206. package/src/lib/narrow-hint-banner.ts +0 -212
  207. package/src/lib/plan-limit-nag.test.ts +0 -317
  208. package/src/lib/plan-limit-nag.ts +0 -264
  209. package/src/main.ts +0 -371
  210. package/src/node-preflight.test.ts +0 -60
  211. package/src/node-preflight.ts +0 -67
  212. package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
  213. package/src/outpost/session-heartbeat-guard.test.ts +0 -105
  214. package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
  215. package/src/outpost/session-heartbeat-publisher.ts +0 -186
  216. package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
  217. package/src/outpost/session-heartbeat.test.ts +0 -459
  218. package/src/outpost/session-heartbeat.ts +0 -877
  219. package/src/packaging.test.ts +0 -109
  220. package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
  221. package/src/run/discover-schemas.test.ts +0 -153
  222. package/src/run/discover-schemas.ts +0 -79
  223. package/src/run/hq-plugin.test.ts +0 -371
  224. package/src/run/hq-plugin.ts +0 -277
  225. package/src/run/varlock-shape.test.ts +0 -57
  226. package/src/schemas/hq-package.schema.json +0 -155
  227. package/src/sentry-before-send.test.ts +0 -359
  228. package/src/sentry-before-send.ts +0 -221
  229. package/src/sentry-epipe.test.ts +0 -37
  230. package/src/sentry-release.test.ts +0 -54
  231. package/src/sentry.test.ts +0 -24
  232. package/src/sentry.ts +0 -54
  233. package/src/strategies/link.ts +0 -62
  234. package/src/strategies/merge.ts +0 -142
  235. package/src/types.ts +0 -146
  236. package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
  237. package/src/utils/auth-error.test.ts +0 -40
  238. package/src/utils/auth-error.ts +0 -42
  239. package/src/utils/billing-gate.test.ts +0 -95
  240. package/src/utils/billing-gate.ts +0 -228
  241. package/src/utils/breadcrumb-buffer.ts +0 -18
  242. package/src/utils/cli-telemetry.test.ts +0 -153
  243. package/src/utils/cli-telemetry.ts +0 -61
  244. package/src/utils/cognito-session.machine.test.ts +0 -109
  245. package/src/utils/cognito-session.refresh.test.ts +0 -84
  246. package/src/utils/cognito-session.test.ts +0 -328
  247. package/src/utils/cognito-session.ts +0 -448
  248. package/src/utils/company-selection-error.test.ts +0 -42
  249. package/src/utils/company-selection-error.ts +0 -45
  250. package/src/utils/contribution-table.ts +0 -83
  251. package/src/utils/environmental-error.test.ts +0 -45
  252. package/src/utils/environmental-error.ts +0 -39
  253. package/src/utils/epipe.test.ts +0 -28
  254. package/src/utils/epipe.ts +0 -29
  255. package/src/utils/expected-cli-error.test.ts +0 -28
  256. package/src/utils/expected-cli-error.ts +0 -39
  257. package/src/utils/feedback-diagnostics.test.ts +0 -183
  258. package/src/utils/feedback-diagnostics.ts +0 -123
  259. package/src/utils/feedback-screenshots.test.ts +0 -134
  260. package/src/utils/feedback-screenshots.ts +0 -124
  261. package/src/utils/feedback-versions.test.ts +0 -98
  262. package/src/utils/feedback-versions.ts +0 -68
  263. package/src/utils/git.ts +0 -74
  264. package/src/utils/integrity.ts +0 -59
  265. package/src/utils/intercepted-process-exit.test.ts +0 -37
  266. package/src/utils/intercepted-process-exit.ts +0 -36
  267. package/src/utils/login-provider.test.ts +0 -42
  268. package/src/utils/login-provider.ts +0 -30
  269. package/src/utils/manifest.test.ts +0 -167
  270. package/src/utils/manifest.ts +0 -131
  271. package/src/utils/pack-contributions.test.ts +0 -603
  272. package/src/utils/pack-contributions.ts +0 -450
  273. package/src/utils/people.ts +0 -215
  274. package/src/utils/registry-client.ts +0 -204
  275. package/src/utils/registry.ts +0 -90
  276. package/src/utils/resolve-vault-credential.test.ts +0 -69
  277. package/src/utils/resolve-vault-credential.ts +0 -60
  278. package/src/utils/sandbox-runner-client.test.ts +0 -279
  279. package/src/utils/sandbox-runner-client.ts +0 -260
  280. package/src/utils/secrets-cache.ts +0 -183
  281. package/src/utils/sentry-identity.ts +0 -45
  282. package/src/utils/settle-with-timeout.test.ts +0 -21
  283. package/src/utils/settle-with-timeout.ts +0 -22
  284. package/src/utils/user-yaml-error.test.ts +0 -24
  285. package/src/utils/user-yaml-error.ts +0 -30
  286. package/src/utils/vault-api.test.ts +0 -536
  287. package/src/utils/vault-api.ts +0 -382
  288. package/src/utils/version-check.test.ts +0 -176
  289. package/src/utils/version-check.ts +0 -155
  290. package/src/utils/version-gate.test.ts +0 -1024
  291. package/src/utils/version-gate.ts +0 -702
  292. package/test/commands/db-tenant-isolation.test.ts +0 -94
  293. package/test/commands/db.test.ts +0 -85
  294. package/test/commands/signals.test.ts +0 -207
  295. package/test/commands/sources.test.ts +0 -231
  296. package/test/e2e/smoke-install-mcp.sh +0 -113
  297. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
  298. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
  299. package/test/fixtures/signals/action_item/sample.md +0 -16
  300. package/test/fixtures/signals/summary/sample.md +0 -12
  301. package/test/fixtures/sources/meetings/sample.md +0 -25
  302. package/test/helpers/cli-runner.ts +0 -150
  303. package/test/helpers/s3-list-mock.ts +0 -79
  304. package/test/helpers/vault-service-mock.ts +0 -295
  305. package/test/sources-signals/smoke.test.ts +0 -228
  306. package/tsconfig.json +0 -20
  307. package/vitest.config.ts +0 -11
  308. package/vitest.e2e.config.ts +0 -7
@@ -1,202 +0,0 @@
1
- /**
2
- * Unit tests for `hq company settings set` (company.ts).
3
- *
4
- * Mirrors members.test.ts: mock ensureCognitoToken + getEntityUid, spy on
5
- * global fetch, drive through a Commander program, assert the PUT
6
- * /company-settings request shape + exit behavior.
7
- */
8
-
9
- import { Command } from "commander";
10
- import {
11
- afterEach,
12
- beforeEach,
13
- describe,
14
- expect,
15
- it,
16
- vi,
17
- type MockInstance,
18
- } from "vitest";
19
-
20
- vi.mock("../utils/cognito-session.js", async (importOriginal) => {
21
- const original =
22
- await importOriginal<typeof import("../utils/cognito-session.js")>();
23
- return {
24
- ...original,
25
- ensureCognitoToken: vi.fn(async () => "test-token"),
26
- };
27
- });
28
-
29
- vi.mock("../utils/vault-api.js", async (importOriginal) => {
30
- const original = await importOriginal<typeof import("../utils/vault-api.js")>();
31
- return {
32
- ...original,
33
- getEntityUid: vi.fn(async () => "cmp_acme"),
34
- };
35
- });
36
-
37
- import { ensureCognitoToken } from "../utils/cognito-session.js";
38
- import { getEntityUid } from "../utils/vault-api.js";
39
- import { registerCompanyCommand } from "./company.js";
40
-
41
- function jsonResponse(status: number, body: unknown): Response {
42
- return new Response(JSON.stringify(body), {
43
- status,
44
- headers: { "Content-Type": "application/json" },
45
- });
46
- }
47
-
48
- let fetchSpy: MockInstance<typeof fetch>;
49
- let exitSpy: MockInstance<typeof process.exit>;
50
- const mockEnsureCognitoToken = vi.mocked(ensureCognitoToken);
51
- const mockGetEntityUid = vi.mocked(getEntityUid);
52
-
53
- beforeEach(() => {
54
- vi.clearAllMocks();
55
- fetchSpy = vi.spyOn(globalThis, "fetch");
56
- mockEnsureCognitoToken.mockResolvedValue("test-token");
57
- mockGetEntityUid.mockResolvedValue("cmp_acme");
58
- exitSpy = vi
59
- .spyOn(process, "exit")
60
- .mockImplementation((code?: number) => {
61
- throw new Error(`process.exit(${code})`);
62
- }) as unknown as MockInstance<typeof process.exit>;
63
- vi.spyOn(console, "log").mockImplementation(() => {});
64
- vi.spyOn(console, "error").mockImplementation(() => {});
65
- });
66
-
67
- afterEach(() => {
68
- vi.restoreAllMocks();
69
- });
70
-
71
- function buildProgram(): Command {
72
- const program = new Command();
73
- program.name("hq").exitOverride();
74
- registerCompanyCommand(program);
75
- return program;
76
- }
77
-
78
- async function run(args: string[]): Promise<void> {
79
- await buildProgram().parseAsync(["node", "hq", ...args]);
80
- }
81
-
82
- describe("hq company settings set", () => {
83
- it("PUTs crmEnabled=true with the resolved companyUid", async () => {
84
- fetchSpy.mockResolvedValueOnce(
85
- jsonResponse(200, { companySettings: { crmEnabled: true } }),
86
- );
87
-
88
- await run([
89
- "company",
90
- "settings",
91
- "set",
92
- "--company",
93
- "acme",
94
- "--crm-enabled",
95
- "true",
96
- ]);
97
-
98
- expect(fetchSpy).toHaveBeenCalledTimes(1);
99
- const [url, init] = fetchSpy.mock.calls[0];
100
- expect(String(url)).toContain("/company-settings");
101
- expect(init?.method).toBe("PUT");
102
- const sent = JSON.parse(init?.body as string);
103
- expect(sent).toMatchObject({ companyUid: "cmp_acme", crmEnabled: true });
104
- expect(sent.ontologyEnabled).toBeUndefined();
105
- });
106
-
107
- it("PUTs accountingEnabled=true with the resolved companyUid", async () => {
108
- fetchSpy.mockResolvedValueOnce(
109
- jsonResponse(200, { companySettings: { accountingEnabled: true } }),
110
- );
111
-
112
- await run([
113
- "company",
114
- "settings",
115
- "set",
116
- "--company",
117
- "acme",
118
- "--accounting-enabled",
119
- "true",
120
- ]);
121
-
122
- expect(fetchSpy).toHaveBeenCalledTimes(1);
123
- const sent = JSON.parse(fetchSpy.mock.calls[0][1]?.body as string);
124
- expect(sent).toMatchObject({
125
- companyUid: "cmp_acme",
126
- accountingEnabled: true,
127
- });
128
- expect(sent.crmEnabled).toBeUndefined();
129
- expect(sent.ontologyEnabled).toBeUndefined();
130
- });
131
-
132
- it("PUTs both flags when both are supplied", async () => {
133
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, {}));
134
-
135
- await run([
136
- "company",
137
- "settings",
138
- "set",
139
- "--company",
140
- "acme",
141
- "--crm-enabled",
142
- "false",
143
- "--ontology-enabled",
144
- "true",
145
- ]);
146
-
147
- const sent = JSON.parse(fetchSpy.mock.calls[0][1]?.body as string);
148
- expect(sent).toMatchObject({
149
- companyUid: "cmp_acme",
150
- crmEnabled: false,
151
- ontologyEnabled: true,
152
- });
153
- });
154
-
155
- it("requires at least one flag", async () => {
156
- await expect(
157
- run(["company", "settings", "set", "--company", "acme"]),
158
- ).rejects.toThrow("process.exit(1)");
159
- expect(fetchSpy).not.toHaveBeenCalled();
160
- });
161
-
162
- it("requires --company", async () => {
163
- await expect(
164
- run(["company", "settings", "set", "--crm-enabled", "true"]),
165
- ).rejects.toThrow("process.exit(1)");
166
- expect(fetchSpy).not.toHaveBeenCalled();
167
- });
168
-
169
- it("rejects a non-boolean flag value", async () => {
170
- await expect(
171
- run([
172
- "company",
173
- "settings",
174
- "set",
175
- "--company",
176
- "acme",
177
- "--crm-enabled",
178
- "yes",
179
- ]),
180
- ).rejects.toThrow("process.exit(1)");
181
- expect(fetchSpy).not.toHaveBeenCalled();
182
- });
183
-
184
- it("exits 1 on a 403 (non-owner)", async () => {
185
- fetchSpy.mockResolvedValueOnce(
186
- jsonResponse(403, { error: "Requires owner role", code: "FORBIDDEN" }),
187
- );
188
-
189
- await expect(
190
- run([
191
- "company",
192
- "settings",
193
- "set",
194
- "--company",
195
- "acme",
196
- "--crm-enabled",
197
- "true",
198
- ]),
199
- ).rejects.toThrow("process.exit(1)");
200
- expect(exitSpy).toHaveBeenCalledWith(1);
201
- });
202
- });
@@ -1,148 +0,0 @@
1
- import { Command } from "commander";
2
- import chalk from "chalk";
3
- import { ensureCognitoToken } from "../utils/cognito-session.js";
4
- import { vaultApiFetch, getEntityUid } from "../utils/vault-api.js";
5
-
6
- /**
7
- * `hq company settings set` — owner-only per-company settings toggles
8
- * (agency group-grants US-007 / hq-native-crm US-003). Wraps
9
- * `PUT /company-settings`, setting the runtime-flippable `crmEnabled` /
10
- * `ontologyEnabled` / `accountingEnabled` flags so an owner can enable the
11
- * native CRM, ontology gardener, or accounting pack for a company without a
12
- * redeploy.
13
- *
14
- * Conventions mirror `secrets.ts`: ensureCognitoToken() → getEntityUid() →
15
- * vaultApiFetch() → error-check → chalk output.
16
- */
17
-
18
- interface SettingsSetFlags {
19
- crmEnabled?: string;
20
- ontologyEnabled?: string;
21
- accountingEnabled?: string;
22
- }
23
-
24
- /**
25
- * Parse a `--flag <true|false>` string into a boolean, or throw. Commander
26
- * passes the raw string; we validate strictly so a typo never silently writes
27
- * the wrong value.
28
- */
29
- function parseBoolFlag(value: string, flag: string): boolean {
30
- const v = value.trim().toLowerCase();
31
- if (v === "true") return true;
32
- if (v === "false") return false;
33
- throw new Error(`${flag} must be 'true' or 'false' (got '${value}')`);
34
- }
35
-
36
- export function registerCompanyCommand(program: Command): void {
37
- const company = program
38
- .command("company")
39
- .description("Company-level settings")
40
- .option("--company <slug>", "Company slug (resolves to companyUid)");
41
-
42
- const settings = company
43
- .command("settings")
44
- .description("Per-company settings (owner-only)");
45
-
46
- settings
47
- .command("set")
48
- .description(
49
- "Set per-company settings (PUT /company-settings). Require at least one " +
50
- "of --crm-enabled / --ontology-enabled / --accounting-enabled.",
51
- )
52
- .option(
53
- "--crm-enabled <true|false>",
54
- "Enable/disable the native CRM for this company",
55
- )
56
- .option(
57
- "--ontology-enabled <true|false>",
58
- "Enable/disable the ontology gardener for this company",
59
- )
60
- .option(
61
- "--accounting-enabled <true|false>",
62
- "Enable/disable the accounting pack for this company",
63
- )
64
- .action(async (opts: SettingsSetFlags) => {
65
- try {
66
- const companySlug = company.opts().company as string | undefined;
67
- if (!companySlug) {
68
- console.error(chalk.red("Error: --company <slug> is required."));
69
- process.exit(1);
70
- }
71
- if (
72
- opts.crmEnabled === undefined &&
73
- opts.ontologyEnabled === undefined &&
74
- opts.accountingEnabled === undefined
75
- ) {
76
- console.error(
77
- chalk.red(
78
- "Error: provide at least one of --crm-enabled / --ontology-enabled / --accounting-enabled.",
79
- ),
80
- );
81
- process.exit(1);
82
- }
83
-
84
- const body: Record<string, unknown> = {};
85
- if (opts.crmEnabled !== undefined) {
86
- body.crmEnabled = parseBoolFlag(opts.crmEnabled, "--crm-enabled");
87
- }
88
- if (opts.ontologyEnabled !== undefined) {
89
- body.ontologyEnabled = parseBoolFlag(
90
- opts.ontologyEnabled,
91
- "--ontology-enabled",
92
- );
93
- }
94
- if (opts.accountingEnabled !== undefined) {
95
- body.accountingEnabled = parseBoolFlag(
96
- opts.accountingEnabled,
97
- "--accounting-enabled",
98
- );
99
- }
100
-
101
- const token = await ensureCognitoToken();
102
- const companyUid = await getEntityUid(token, { companySlug });
103
- body.companyUid = companyUid;
104
-
105
- const res = await vaultApiFetch({
106
- token,
107
- path: "/company-settings",
108
- method: "PUT",
109
- body,
110
- });
111
-
112
- if (!res.ok) {
113
- const errBody = (await res.json().catch(() => ({}))) as Record<
114
- string,
115
- unknown
116
- >;
117
- if (res.status === 403) {
118
- console.error(
119
- chalk.red(
120
- "Requires owner role on this company to change its settings.",
121
- ),
122
- );
123
- process.exit(1);
124
- }
125
- console.error(
126
- chalk.red(
127
- `Failed to update company settings: ${(errBody.error as string) ?? res.statusText}`,
128
- ),
129
- );
130
- process.exit(1);
131
- }
132
-
133
- const applied = Object.entries(body)
134
- .filter(([k]) => k !== "companyUid")
135
- .map(([k, v]) => `${k}=${v}`)
136
- .join(", ");
137
- console.log(
138
- chalk.green(`Company settings updated for ${companySlug}: ${applied}`),
139
- );
140
- } catch (err) {
141
- console.error(
142
- chalk.red("Error:"),
143
- err instanceof Error ? err.message : String(err),
144
- );
145
- process.exit(1);
146
- }
147
- });
148
- }
@@ -1,60 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { runCreatorApply } from "./creators.js";
3
-
4
- function jsonResponse(status: number, body: unknown): Response {
5
- return {
6
- status,
7
- json: async () => body,
8
- } as unknown as Response;
9
- }
10
-
11
- describe("runCreatorApply", () => {
12
- it("submits the application and reports the application id", async () => {
13
- const post = vi
14
- .fn()
15
- .mockResolvedValue(
16
- jsonResponse(202, { status: "request_received", applicationId: "capp_1" }),
17
- );
18
- const res = await runCreatorApply(
19
- { reason: "I build automation skills" },
20
- { getAccessToken: async () => "tok", post },
21
- );
22
- expect(res.message).toMatch(/submitted \(capp_1\)/);
23
- expect(post).toHaveBeenCalledWith("tok", { reason: "I build automation skills" });
24
- });
25
-
26
- it("passes an optional handle through", async () => {
27
- const post = vi.fn().mockResolvedValue(jsonResponse(202, { applicationId: "capp_2" }));
28
- await runCreatorApply(
29
- { reason: "pitch", handle: " acme " },
30
- { getAccessToken: async () => "tok", post },
31
- );
32
- expect(post).toHaveBeenCalledWith("tok", { reason: "pitch", handle: "acme" });
33
- });
34
-
35
- it("treats a 409 / APPLICATION_PENDING as an already-pending message", async () => {
36
- const post = vi
37
- .fn()
38
- .mockResolvedValue(jsonResponse(409, { code: "APPLICATION_PENDING", applicationId: "capp_3" }));
39
- const res = await runCreatorApply(
40
- { reason: "pitch" },
41
- { getAccessToken: async () => "tok", post },
42
- );
43
- expect(res.message).toMatch(/already have a pending/i);
44
- });
45
-
46
- it("requires a non-empty reason", async () => {
47
- const post = vi.fn();
48
- await expect(
49
- runCreatorApply({ reason: " " }, { getAccessToken: async () => "tok", post }),
50
- ).rejects.toThrow(/reason is required/i);
51
- expect(post).not.toHaveBeenCalled();
52
- });
53
-
54
- it("throws on a hard server error", async () => {
55
- const post = vi.fn().mockResolvedValue(jsonResponse(500, { error: "boom" }));
56
- await expect(
57
- runCreatorApply({ reason: "pitch" }, { getAccessToken: async () => "tok", post }),
58
- ).rejects.toThrow(/boom/);
59
- });
60
- });
@@ -1,117 +0,0 @@
1
- /**
2
- * `hq creators apply` — apply for verified-creator access.
3
- *
4
- * Publishing to the marketplace is gated on verified-creator status. An
5
- * unverified caller submits an application (a short pitch + optional desired
6
- * handle); it is persisted server-side and an Indigo admin reviews it. On
7
- * approval the caller becomes a verified creator and can `hq publish`.
8
- *
9
- * Wire contract (POST /v1/creators/request-access, authed):
10
- * body { reason: string, handle?: string }
11
- * 202 { status, code, applicationId, requestAccessPath }
12
- * 409 { code: "APPLICATION_PENDING", error, applicationId } (already pending)
13
- */
14
- import { Command } from "commander";
15
- import chalk from "chalk";
16
- import { ensureCognitoToken } from "../utils/cognito-session.js";
17
- import { vaultApiFetch } from "../utils/vault-api.js";
18
-
19
- export interface CreatorApplyOptions {
20
- reason: string;
21
- handle?: string;
22
- }
23
-
24
- export interface CreatorApplyDeps {
25
- /** Resolve a non-expired access token (prompts login when interactive). */
26
- getAccessToken: () => Promise<string>;
27
- /** POST the application body to the vault API. */
28
- post: (token: string, body: Record<string, unknown>) => Promise<Response>;
29
- }
30
-
31
- export interface CreatorApplyResult {
32
- message: string;
33
- }
34
-
35
- /**
36
- * Testable core. Submits the application and maps the server response to a
37
- * single human-readable message. Throws on hard failures.
38
- */
39
- export async function runCreatorApply(
40
- opts: CreatorApplyOptions,
41
- deps: CreatorApplyDeps,
42
- ): Promise<CreatorApplyResult> {
43
- const reason = opts.reason?.trim();
44
- if (!reason) {
45
- throw new Error(
46
- 'A reason is required — pass --reason "why you want to publish to the marketplace".',
47
- );
48
- }
49
-
50
- const token = await deps.getAccessToken();
51
- const body: Record<string, unknown> = { reason };
52
- const handle = opts.handle?.trim();
53
- if (handle) body.handle = handle;
54
-
55
- const res = await deps.post(token, body);
56
- const parsed = (await res
57
- .json()
58
- .catch(() => ({}))) as Record<string, unknown>;
59
-
60
- if (res.status === 409 || parsed.code === "APPLICATION_PENDING") {
61
- return {
62
- message:
63
- "You already have a pending creator application — an Indigo admin will review it.",
64
- };
65
- }
66
- if (res.status < 200 || res.status >= 300) {
67
- const msg =
68
- (parsed.error as string) ?? (parsed.message as string) ?? `HTTP ${res.status}`;
69
- throw new Error(`Creator application failed: ${msg}`);
70
- }
71
-
72
- const id =
73
- typeof parsed.applicationId === "string" ? ` (${parsed.applicationId})` : "";
74
- return {
75
- message:
76
- `Creator application submitted${id} — an Indigo admin will review it. ` +
77
- "You'll be able to `hq publish` once approved.",
78
- };
79
- }
80
-
81
- export function registerCreatorsCommand(program: Command): void {
82
- const creators = program
83
- .command("creators")
84
- .description("Creator marketplace account");
85
-
86
- creators
87
- .command("apply")
88
- .description(
89
- "Apply for verified-creator access (required to publish packs)",
90
- )
91
- .requiredOption(
92
- "--reason <reason>",
93
- "Why you want to publish to the marketplace",
94
- )
95
- .option("--handle <handle>", "Desired creator handle (optional)")
96
- .action(async (options: CreatorApplyOptions) => {
97
- try {
98
- const result = await runCreatorApply(
99
- { reason: options.reason, handle: options.handle },
100
- {
101
- getAccessToken: () => ensureCognitoToken({ interactive: true }),
102
- post: (token, body) =>
103
- vaultApiFetch({
104
- token,
105
- path: "/v1/creators/request-access",
106
- method: "POST",
107
- body,
108
- }),
109
- },
110
- );
111
- console.log(chalk.green(result.message));
112
- } catch (err) {
113
- console.error(chalk.red((err as Error).message));
114
- process.exitCode = 1;
115
- }
116
- });
117
- }
@@ -1,179 +0,0 @@
1
- /**
2
- * Unit tests for `hq crm entity upsert` (crm.ts).
3
- *
4
- * Mirrors members.test.ts: mock ensureCognitoToken + getEntityUid, spy on
5
- * global fetch (vaultApiFetch's transport), drive the command through a
6
- * Commander program, and assert the request shape + output / exit behavior.
7
- */
8
-
9
- import { Command } from "commander";
10
- import {
11
- afterEach,
12
- beforeEach,
13
- describe,
14
- expect,
15
- it,
16
- vi,
17
- type MockInstance,
18
- } from "vitest";
19
-
20
- vi.mock("../utils/cognito-session.js", async (importOriginal) => {
21
- const original =
22
- await importOriginal<typeof import("../utils/cognito-session.js")>();
23
- return {
24
- ...original,
25
- ensureCognitoToken: vi.fn(async () => "test-token"),
26
- };
27
- });
28
-
29
- vi.mock("../utils/vault-api.js", async (importOriginal) => {
30
- const original = await importOriginal<typeof import("../utils/vault-api.js")>();
31
- return {
32
- ...original,
33
- getEntityUid: vi.fn(async () => "cmp_acme"),
34
- };
35
- });
36
-
37
- import { ensureCognitoToken } from "../utils/cognito-session.js";
38
- import { getEntityUid } from "../utils/vault-api.js";
39
- import { registerCrmCommand } from "./crm.js";
40
-
41
- function jsonResponse(status: number, body: unknown): Response {
42
- return new Response(JSON.stringify(body), {
43
- status,
44
- headers: { "Content-Type": "application/json" },
45
- });
46
- }
47
-
48
- let fetchSpy: MockInstance<typeof fetch>;
49
- let exitSpy: MockInstance<typeof process.exit>;
50
- const mockEnsureCognitoToken = vi.mocked(ensureCognitoToken);
51
- const mockGetEntityUid = vi.mocked(getEntityUid);
52
-
53
- beforeEach(() => {
54
- vi.clearAllMocks();
55
- fetchSpy = vi.spyOn(globalThis, "fetch");
56
- mockEnsureCognitoToken.mockResolvedValue("test-token");
57
- mockGetEntityUid.mockResolvedValue("cmp_acme");
58
- // process.exit(1) on the error paths — throw so the test can assert instead
59
- // of tearing down the worker.
60
- exitSpy = vi
61
- .spyOn(process, "exit")
62
- .mockImplementation((code?: number) => {
63
- throw new Error(`process.exit(${code})`);
64
- }) as unknown as MockInstance<typeof process.exit>;
65
- vi.spyOn(console, "log").mockImplementation(() => {});
66
- vi.spyOn(console, "error").mockImplementation(() => {});
67
- });
68
-
69
- afterEach(() => {
70
- vi.restoreAllMocks();
71
- });
72
-
73
- function buildProgram(): Command {
74
- const program = new Command();
75
- program.name("hq").exitOverride();
76
- registerCrmCommand(program);
77
- return program;
78
- }
79
-
80
- async function run(args: string[]): Promise<void> {
81
- await buildProgram().parseAsync(["node", "hq", ...args]);
82
- }
83
-
84
- describe("hq crm entity upsert", () => {
85
- it("flag form: POSTs a single entity to /crm/entities with external_ids", async () => {
86
- fetchSpy.mockResolvedValueOnce(
87
- jsonResponse(200, {
88
- status: "written",
89
- created: 1,
90
- updated: 0,
91
- skipped: 0,
92
- errors: [],
93
- }),
94
- );
95
-
96
- await run([
97
- "crm",
98
- "entity",
99
- "upsert",
100
- "--company",
101
- "acme",
102
- "--type",
103
- "contact",
104
- "--name",
105
- "Jane Prospect",
106
- "--attio-id",
107
- "rec_jane",
108
- ]);
109
-
110
- expect(fetchSpy).toHaveBeenCalledTimes(1);
111
- const [url, init] = fetchSpy.mock.calls[0];
112
- expect(String(url)).toContain("/crm/entities");
113
- expect(init?.method).toBe("POST");
114
- const sent = JSON.parse(init?.body as string);
115
- expect(sent.companyUid).toBe("cmp_acme");
116
- expect(sent.entities).toHaveLength(1);
117
- expect(sent.entities[0]).toMatchObject({
118
- type: "contact",
119
- canonical_name: "Jane Prospect",
120
- external_ids: { attio: "rec_jane" },
121
- });
122
- });
123
-
124
- it("exits 1 with a helpful message on 403 CRM_DISABLED", async () => {
125
- fetchSpy.mockResolvedValueOnce(
126
- jsonResponse(403, {
127
- error: "the native CRM is not enabled for this company",
128
- code: "CRM_DISABLED",
129
- }),
130
- );
131
-
132
- await expect(
133
- run([
134
- "crm",
135
- "entity",
136
- "upsert",
137
- "--company",
138
- "acme",
139
- "--type",
140
- "contact",
141
- "--name",
142
- "Jane",
143
- ]),
144
- ).rejects.toThrow("process.exit(1)");
145
- expect(exitSpy).toHaveBeenCalledWith(1);
146
- });
147
-
148
- it("requires --company", async () => {
149
- await expect(
150
- run(["crm", "entity", "upsert", "--type", "contact", "--name", "Jane"]),
151
- ).rejects.toThrow("process.exit(1)");
152
- // Never made the request — failed before token resolution.
153
- expect(fetchSpy).not.toHaveBeenCalled();
154
- });
155
-
156
- it("requires --type when no --json is given", async () => {
157
- await expect(
158
- run(["crm", "entity", "upsert", "--company", "acme", "--name", "Jane"]),
159
- ).rejects.toThrow("process.exit(1)");
160
- expect(fetchSpy).not.toHaveBeenCalled();
161
- });
162
-
163
- it("rejects an unknown --type", async () => {
164
- await expect(
165
- run([
166
- "crm",
167
- "entity",
168
- "upsert",
169
- "--company",
170
- "acme",
171
- "--type",
172
- "widget",
173
- "--name",
174
- "Jane",
175
- ]),
176
- ).rejects.toThrow("process.exit(1)");
177
- expect(fetchSpy).not.toHaveBeenCalled();
178
- });
179
- });