@indigoai-us/hq-cli 5.345.212-beta.0 → 5.345.214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -1
- package/dist/bin/hq-auth-refresh.js +2 -1
- package/dist/command-catalog.generated.d.ts +308 -43
- package/dist/command-catalog.generated.js +373 -43
- package/dist/command-registration-plan.d.ts +15 -0
- package/dist/command-registration-plan.js +20 -1
- package/dist/commands/agent-inbox.d.ts +11 -1
- package/dist/commands/agent-inbox.js +128 -38
- package/dist/commands/agent-kit.js +2 -2
- package/dist/commands/agents.js +6 -1
- package/dist/commands/billing.js +17 -4
- package/dist/commands/core-handoff.js +1 -0
- package/dist/commands/core-hq-session-native.js +2 -2
- package/dist/commands/core-pin-native.js +1 -1
- package/dist/commands/core-policy.js +1 -1
- package/dist/commands/core-resolve-company-native.js +1 -1
- package/dist/commands/core-sentry-report-fast.d.ts +2 -0
- package/dist/commands/core-sentry-report-fast.js +3 -1
- package/dist/commands/daemon.js +68 -6
- package/dist/commands/files.js +2 -2
- package/dist/commands/integrations-api.d.ts +11 -0
- package/dist/commands/integrations-connect.d.ts +9 -1
- package/dist/commands/integrations-connect.js +154 -18
- package/dist/commands/integrations-core.d.ts +1 -1
- package/dist/commands/integrations-core.js +18 -10
- package/dist/commands/integrations.js +1 -1
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/lanes.js +34 -16
- package/dist/commands/rescue.js +13 -0
- package/dist/commands/secrets.d.ts +11 -0
- package/dist/commands/secrets.js +41 -7
- package/dist/index.js +2 -0
- package/dist/lazy-commands.js +6 -1
- package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
- package/dist/lib/agent-kit/inbox-fetch.js +215 -3
- package/dist/lib/agent-kit/inbox-redact.js +1 -1
- package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
- package/dist/lib/agent-kit/inbox-state.js +261 -4
- package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
- package/dist/lib/agent-kit/mcp/tools.js +68 -25
- package/dist/lib/agent-kit/run/inbox.js +4 -2
- package/dist/lib/agent-kit/skills.js +4 -1
- package/dist/lib/agent-kit/wake.d.ts +9 -1
- package/dist/lib/agent-kit/wake.js +10 -3
- package/dist/lib/billing/usage-only.d.ts +4 -1
- package/dist/lib/billing/usage-only.js +7 -2
- package/dist/lib/bot/fleet-cron.js +193 -14
- package/dist/lib/bot/fleet-download.d.ts +2 -0
- package/dist/lib/bot/fleet-download.js +23 -0
- package/dist/lib/bot/fleet-local.d.ts +1 -0
- package/dist/lib/bot/fleet-local.js +41 -8
- package/dist/lib/capacity/ledger.d.ts +7 -0
- package/dist/lib/capacity/ledger.js +31 -1
- package/dist/lib/capacity/project.d.ts +1 -1
- package/dist/lib/capacity/project.js +13 -4
- package/dist/lib/capacity/route.d.ts +10 -0
- package/dist/lib/capacity/route.js +16 -0
- package/dist/lib/core-utils/session-id.d.ts +1 -1
- package/dist/lib/core-utils/session-id.js +4 -0
- package/dist/lib/daemon/install.d.ts +15 -0
- package/dist/lib/daemon/install.js +31 -0
- package/dist/lib/daemon/migrate.js +29 -4
- package/dist/lib/daemon/run.js +9 -1
- package/dist/lib/daemon/updater.d.ts +34 -2
- package/dist/lib/daemon/updater.js +51 -2
- package/dist/lib/doctor/__testing__/run-doctor.js +4 -0
- package/dist/lib/doctor/checks/jq.d.ts +27 -0
- package/dist/lib/doctor/checks/jq.js +82 -0
- package/dist/lib/doctor/checks/release-links.d.ts +50 -8
- package/dist/lib/doctor/checks/release-links.js +260 -24
- package/dist/lib/doctor/fix/apply.js +24 -8
- package/dist/lib/doctor/fix/remediation.js +15 -5
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/flag-snapshot-file.js +36 -8
- package/dist/lib/install/codex-targets.d.ts +52 -1
- package/dist/lib/install/codex-targets.js +77 -2
- package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
- package/dist/lib/lanes/autopilot-registry.js +59 -7
- package/dist/lib/lanes/links.d.ts +14 -0
- package/dist/lib/lanes/links.js +320 -25
- package/dist/lib/lanes/monitor.d.ts +4 -1
- package/dist/lib/lanes/monitor.js +47 -10
- package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
- package/dist/lib/lanes/outpost-pruner-install.js +4 -3
- package/dist/lib/lanes/spawn.js +8 -1
- package/dist/lib/lanes/watch.js +31 -0
- package/dist/lib/onboarding/checkpoint.d.ts +6 -0
- package/dist/lib/onboarding/checkpoint.js +6 -0
- package/dist/lib/onboarding/orchestrator.d.ts +3 -1
- package/dist/lib/onboarding/orchestrator.js +62 -9
- package/dist/lib/onboarding/types.d.ts +8 -0
- package/dist/lib/work-context/organize.d.ts +23 -1
- package/dist/lib/work-context/organize.js +25 -3
- package/dist/lib/work-context/reconcile.js +3 -2
- package/dist/main.js +3 -1
- package/dist/secrets-env-action.js +7 -5
- package/dist/sentry-init.d.ts +2 -0
- package/dist/sentry-init.js +13 -2
- package/dist/sentry.d.ts +2 -0
- package/dist/sentry.js +5 -1
- package/dist/startup-registration.js +7 -2
- package/dist/utils/billing-gate.d.ts +12 -16
- package/dist/utils/billing-gate.js +17 -18
- package/dist/utils/cli-network-lifecycle.d.ts +9 -0
- package/dist/utils/cli-network-lifecycle.js +52 -0
- package/dist/utils/install-tree-torn.d.ts +22 -4
- package/dist/utils/install-tree-torn.js +24 -0
- package/dist/utils/registration-plan-error.d.ts +22 -0
- package/dist/utils/registration-plan-error.js +27 -0
- package/dist/utils/safe-link.d.ts +63 -0
- package/dist/utils/safe-link.js +246 -0
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
- package/dist/utils/sentry-keepalive-transport.js +70 -0
- package/dist/utils/unauthorized-error.d.ts +36 -0
- package/dist/utils/unauthorized-error.js +105 -0
- package/dist/utils/vault-api.js +7 -5
- package/package.json +7 -7
- package/scripts/install-hook-engine.mjs +17 -0
package/dist/commands/daemon.js
CHANGED
|
@@ -25,7 +25,7 @@ import { DEFAULT_SERVICES, SERVICE_DESCRIPTIONS, enabledServices, hqCloudUnits }
|
|
|
25
25
|
import { applyServiceToggle, effectiveSyncOwner, readDaemonConfig, writeDaemonConfig } from "../lib/daemon/config.js";
|
|
26
26
|
import { daemonUnitInstalled } from "../lib/daemon/handoff.js";
|
|
27
27
|
import { adoptLegacyUnits, readAdoptedUnits, restoreLegacyUnits } from "../lib/daemon/migrate.js";
|
|
28
|
-
import { ROOT_REFUSAL, SYSTEM_UNIT_DIR, WINDOWS_START_WAIT_MS, daemonRootRefusal, installDaemonUnit, installScopeFor, classifyWindowsTask, daemonServiceStatus, describeSupervision, legacyWindowsTask, startDaemonUnit, readWindowsSid, uninstallDaemonUnit, windowsInteractiveSession, windowsTaskName, } from "../lib/daemon/install.js";
|
|
28
|
+
import { DAEMON_ALIVE_WAIT_MS, ROOT_REFUSAL, SYSTEM_UNIT_DIR, WINDOWS_START_WAIT_MS, waitForLiveDaemon, daemonRootRefusal, installDaemonUnit, installScopeFor, classifyWindowsTask, daemonServiceStatus, describeSupervision, legacyWindowsTask, startDaemonUnit, readWindowsSid, uninstallDaemonUnit, windowsInteractiveSession, windowsTaskName, } from "../lib/daemon/install.js";
|
|
29
29
|
import { PLIST_REFRESH_MARKER } from "../lib/daemon/plist-refresh.js";
|
|
30
30
|
import { describeLegacyUnit, findLegacyUnits } from "../lib/daemon/legacy.js";
|
|
31
31
|
import { isDaemonProcess, liveDaemonLock, runningDaemonPid } from "../lib/daemon/lock.js";
|
|
@@ -300,9 +300,16 @@ async function runInstall(d, opts) {
|
|
|
300
300
|
for (const line of describeServices(detected.type, config))
|
|
301
301
|
d.out(line);
|
|
302
302
|
const migratable = d.legacyUnits().filter((u) => u.migratable);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
// The older Work Mesh unit is taken over by the install itself once the
|
|
304
|
+
// daemon is running (feedback_c85ad51b): left alone, it kept running beside
|
|
305
|
+
// the daemon until someone ran `hq daemon migrate --apply` by hand.
|
|
306
|
+
const meshTakeover = scope === "user" && enabledServices(detected.type, config).includes("mesh")
|
|
307
|
+
? migratable.filter((u) => u.service === "mesh" && u.kind !== "systemd-system")
|
|
308
|
+
: [];
|
|
309
|
+
const noteLegacy = (u) => d.out(`Note: ${describeLegacyUnit(u)} still runs ${u.unitId}. The daemon leaves it alone until \`hq daemon migrate\` takes it over.`);
|
|
310
|
+
for (const u of migratable)
|
|
311
|
+
if (!meshTakeover.includes(u))
|
|
312
|
+
noteLegacy(u);
|
|
306
313
|
// A box worked out from its runner unit, --user or sudo gets the marker file
|
|
307
314
|
// provisioning would have written: `migrate --apply` moves the runner unit
|
|
308
315
|
// aside, and later root commands (uninstall) must still find the box's type
|
|
@@ -311,10 +318,13 @@ async function runInstall(d, opts) {
|
|
|
311
318
|
d.writeFile(MACHINE_TYPE_MARKER_PATH, `type=${detected.type}\nuser=${runAsUser}\n`);
|
|
312
319
|
}
|
|
313
320
|
const runAsHome = runAsUser ? d.userHome(runAsUser) : undefined;
|
|
321
|
+
const runningDaemon = () => liveDaemonLock(paths.lockPath, d.daemonAlive);
|
|
322
|
+
// The daemon from before this install, so the takeover can tell it from a new one.
|
|
323
|
+
const daemonBefore = meshTakeover.length > 0 ? runningDaemon() : null;
|
|
314
324
|
const result = installDaemonUnit(hostFor(d, paths, scope === "user"), { scope, runAsUser, runAsHome }, {
|
|
315
325
|
run: d.run,
|
|
316
326
|
sleep: d.sleep,
|
|
317
|
-
runningDaemon
|
|
327
|
+
runningDaemon,
|
|
318
328
|
});
|
|
319
329
|
handOver(d, { paths, detected, runAsUser });
|
|
320
330
|
if (result.notice)
|
|
@@ -323,6 +333,7 @@ async function runInstall(d, opts) {
|
|
|
323
333
|
d.err(result.warning);
|
|
324
334
|
if (result.kind === "manual") {
|
|
325
335
|
d.out(`This platform has no supported service manager. Start the daemon yourself with:\n ${result.manualCommand}`);
|
|
336
|
+
meshTakeover.forEach(noteLegacy);
|
|
326
337
|
return;
|
|
327
338
|
}
|
|
328
339
|
if (result.startPending) {
|
|
@@ -338,6 +349,7 @@ async function runInstall(d, opts) {
|
|
|
338
349
|
}
|
|
339
350
|
d.out("The daemon starts at your next sign-in to Windows. It is not running yet.");
|
|
340
351
|
d.out("Check it with: hq daemon status");
|
|
352
|
+
meshTakeover.forEach(noteLegacy);
|
|
341
353
|
return;
|
|
342
354
|
}
|
|
343
355
|
const seconds = WINDOWS_START_WAIT_MS / 1000;
|
|
@@ -353,6 +365,39 @@ async function runInstall(d, opts) {
|
|
|
353
365
|
throw new DaemonCommandError(`Installed ${result.unitPath}, but it did not start: ${result.error ?? "unknown error"}`);
|
|
354
366
|
}
|
|
355
367
|
d.out(`Installed and started: ${result.unitPath}`);
|
|
368
|
+
if (meshTakeover.length === 0)
|
|
369
|
+
return;
|
|
370
|
+
// launchd and systemd report "loaded" even when the daemon exits at once and
|
|
371
|
+
// crash-loops, so wait (bounded) for a live daemon to hold the lock before
|
|
372
|
+
// stopping the working mesh agent. schtasks already waited for that above.
|
|
373
|
+
const live = result.kind === "schtasks" ? runningDaemon() : waitForLiveDaemon(runningDaemon, daemonBefore, d.sleep);
|
|
374
|
+
if (!live) {
|
|
375
|
+
const seconds = DAEMON_ALIVE_WAIT_MS / 1000;
|
|
376
|
+
for (const u of meshTakeover) {
|
|
377
|
+
d.err(`warning: the daemon's service is loaded, but no running daemon held its lock within ${seconds} seconds, ` +
|
|
378
|
+
`so ${describeLegacyUnit(u)} keeps running ${u.unitId}. Check \`hq daemon status\` and \`hq daemon logs\`, then run \`hq daemon migrate --apply\`.`);
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
takeOverLegacyMesh(d, paths, meshTakeover);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Stop the older Work Mesh unit and move its definition aside now that the
|
|
386
|
+
* daemon runs mesh, the same takeover `hq daemon migrate --apply` does (so
|
|
387
|
+
* `hq daemon uninstall --restore-legacy` gives it back). A failed takeover
|
|
388
|
+
* leaves the old unit running as before and does not fail the install.
|
|
389
|
+
*/
|
|
390
|
+
function takeOverLegacyMesh(d, paths, units) {
|
|
391
|
+
const result = adoptLegacyUnits(units, { ...migrateDeps(d, paths), sleep: d.sleep });
|
|
392
|
+
for (const a of result.adopted)
|
|
393
|
+
d.out(`Took over ${a.unitId} from ${describeLegacyUnit(a)}; the daemon starts it within a minute.`);
|
|
394
|
+
for (const s of result.skipped)
|
|
395
|
+
d.out(`Left ${s.unit.unitId} to ${describeLegacyUnit(s.unit)}: ${s.reason}`);
|
|
396
|
+
for (const f of result.failed) {
|
|
397
|
+
d.err(`warning: could not take over ${f.unit.unitId} from ${describeLegacyUnit(f.unit)}: ${f.error}. It keeps running; retry with \`hq daemon migrate --apply\`.`);
|
|
398
|
+
}
|
|
399
|
+
if (result.adopted.length > 0)
|
|
400
|
+
d.out("`hq daemon uninstall --restore-legacy` puts the old unit back.");
|
|
356
401
|
}
|
|
357
402
|
/** Root acting for a box's login user needs that user's uid to reach their systemd manager. */
|
|
358
403
|
function loginUid(d, user) {
|
|
@@ -416,6 +461,13 @@ async function runUninstall(d, opts) {
|
|
|
416
461
|
throw new DaemonCommandError(`Some units were not restored; they are still listed in ${migrate.recordPath}.`);
|
|
417
462
|
}
|
|
418
463
|
}
|
|
464
|
+
if (!opts.restoreLegacy && adopted.length > 0) {
|
|
465
|
+
// `hq daemon install` takes over the older mesh unit by itself, so users
|
|
466
|
+
// reach this state without ever running migrate. Nothing runs those
|
|
467
|
+
// services once the daemon is gone; say how to give them back.
|
|
468
|
+
d.out(`hq daemon had taken over ${adopted.map((u) => u.unitId).join(", ")}; nothing runs ${adopted.length === 1 ? "it" : "them"} now. ` +
|
|
469
|
+
"Run `hq daemon uninstall --restore-legacy` to give the older units back.");
|
|
470
|
+
}
|
|
419
471
|
if (opts.purge) {
|
|
420
472
|
fs.rmSync(paths.root, { recursive: true, force: true });
|
|
421
473
|
d.out(`Deleted ${paths.root}`);
|
|
@@ -1032,12 +1084,14 @@ async function runMigrate(d, opts) {
|
|
|
1032
1084
|
d.out("Nothing was changed. `hq daemon migrate --apply` takes them over.");
|
|
1033
1085
|
}
|
|
1034
1086
|
async function runServiceSelfUpdate(d) {
|
|
1035
|
-
const [{ daemonSelfUpdate }, { hostToolUpdater, runDaemonUpdater, updaterEnv }, { TOOL_NAMES }, { cliSelfUpdatable }, { updateManagedHqCloud },] = await Promise.all([
|
|
1087
|
+
const [{ daemonSelfUpdate }, { hostToolUpdater, resolveRunningDaemonVersion, runDaemonUpdater, updaterEnv }, { TOOL_NAMES }, { cliSelfUpdatable }, { updateManagedHqCloud }, { pingHqdVersion }, { CLI_VERSION },] = await Promise.all([
|
|
1036
1088
|
import("../utils/self-update.js"),
|
|
1037
1089
|
import("../lib/daemon/updater.js"),
|
|
1038
1090
|
import("../lib/daemon/tools.js"),
|
|
1039
1091
|
import("../lib/daemon/run.js"),
|
|
1040
1092
|
import("../lib/daemon/hq-cloud.js"),
|
|
1093
|
+
import("../lib/daemon/convergence.js"),
|
|
1094
|
+
import("../cli-version.js"),
|
|
1041
1095
|
]);
|
|
1042
1096
|
const { paths, detected } = currentHost(d);
|
|
1043
1097
|
const env = updaterEnv(d.env);
|
|
@@ -1048,6 +1102,14 @@ async function runServiceSelfUpdate(d) {
|
|
|
1048
1102
|
updateHqCloud: async () => updateManagedHqCloud(paths.root, env),
|
|
1049
1103
|
hqCloudUnits: hqCloudUnits(detected.type, enabledServices(detected.type, readDaemonConfig(paths.configPath))),
|
|
1050
1104
|
requestDaemonRestart: () => writeControlRequest(paths.requestsDir, { action: "restart-daemon", deferUntilSyncIdle: true }),
|
|
1105
|
+
// A daemon started before this release keeps its old code until it restarts.
|
|
1106
|
+
installedCliVersion: CLI_VERSION,
|
|
1107
|
+
// hqd answers only while HQ Anywhere is on; the fallbacks cover the rest.
|
|
1108
|
+
runningDaemonVersion: () => resolveRunningDaemonVersion({
|
|
1109
|
+
ping: () => pingHqdVersion(hqdSocketPath(d.home, d.env, d.platform)),
|
|
1110
|
+
env: d.env,
|
|
1111
|
+
parentCommandLine: () => processCommandLine(process.ppid),
|
|
1112
|
+
}),
|
|
1051
1113
|
requestRestart: (unit) => writeControlRequest(paths.requestsDir, { action: "restart", unit }),
|
|
1052
1114
|
log: d.out,
|
|
1053
1115
|
});
|
package/dist/commands/files.js
CHANGED
|
@@ -7,7 +7,7 @@ import { gateApiKeyCapabilities } from "../utils/api-key-command-gate.js";
|
|
|
7
7
|
import { vaultApiFetch, getCompanyUid } from "./secrets.js";
|
|
8
8
|
import { GROUP_ID_PATTERN, EMAIL_PATTERN, isPrivateFolderPattern, normalizeFilePrefix, OUTPOST_UID_PATTERN, toSharedFolderGlob, } from "./_patterns.js";
|
|
9
9
|
import { looksLikeCompanyUid } from "../utils/vault-api.js";
|
|
10
|
-
import {
|
|
10
|
+
import { unauthorizedError } from "../utils/unauthorized-error.js";
|
|
11
11
|
import { formatAccessDenied, offerAccessLadder, } from "../utils/access-denied-hint.js";
|
|
12
12
|
import { fetchChannels, matchChannelsByName } from "./dm.js";
|
|
13
13
|
import { suggestChannels, withChannelSuggestions } from "./channel-suggest.js";
|
|
@@ -1496,7 +1496,7 @@ async function resolveCompanyUidForAnchoredPath(token, opts) {
|
|
|
1496
1496
|
signal: AbortSignal.timeout(15_000),
|
|
1497
1497
|
});
|
|
1498
1498
|
if (response.status === 401)
|
|
1499
|
-
throw
|
|
1499
|
+
throw unauthorizedError();
|
|
1500
1500
|
if (!response.ok) {
|
|
1501
1501
|
throw new Error(`Failed to resolve company '${opts.explicit}' (HTTP ${response.status})`);
|
|
1502
1502
|
}
|
|
@@ -162,6 +162,12 @@ export interface InstallInput {
|
|
|
162
162
|
header: string;
|
|
163
163
|
};
|
|
164
164
|
scope?: ConnectScope;
|
|
165
|
+
/**
|
|
166
|
+
* Reconnect: re-key exactly this existing connection and keep its owner.
|
|
167
|
+
* Without it hq-pro places the install by `scope`, which sent a legacy
|
|
168
|
+
* shared connection's new key to a personal row (feedback_a79e0c89).
|
|
169
|
+
*/
|
|
170
|
+
connectionId?: string;
|
|
165
171
|
}
|
|
166
172
|
export type ConnectScope = "personal" | "company";
|
|
167
173
|
export declare function scopeUnavailableMessage(scope: ConnectScope): string;
|
|
@@ -231,6 +237,11 @@ export interface OAuthStartInput {
|
|
|
231
237
|
*/
|
|
232
238
|
scopes?: string[];
|
|
233
239
|
scope?: ConnectScope;
|
|
240
|
+
/**
|
|
241
|
+
* Reconnect: sign in for exactly this existing connection and keep its
|
|
242
|
+
* owner, as on install (feedback_a79e0c89).
|
|
243
|
+
*/
|
|
244
|
+
connectionId?: string;
|
|
234
245
|
}
|
|
235
246
|
export declare function startOAuth(token: string, companyUid: string, input: OAuthStartInput): Promise<OAuthStartResult>;
|
|
236
247
|
export declare function completeOAuth(token: string, companyUid: string, input: {
|
|
@@ -93,6 +93,8 @@ interface ConnectTarget {
|
|
|
93
93
|
authClass?: "none" | "key" | "oauth";
|
|
94
94
|
/** Human label for prompts and success lines. */
|
|
95
95
|
label: string;
|
|
96
|
+
/** Reconnect only: the existing connection the install must re-key. */
|
|
97
|
+
connectionId?: string;
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
98
100
|
* Run the browser sign-in and finish the install.
|
|
@@ -118,7 +120,7 @@ export declare function consoleIntegrationsUrl(companySlug: string | undefined,
|
|
|
118
120
|
* credentials — but only the console can collect them, so say what is needed
|
|
119
121
|
* and hand the page over rather than restating the refusal and stopping.
|
|
120
122
|
*/
|
|
121
|
-
export declare function bringYourOwnClientHandoff(target: ConnectTarget, opts: ConnectOptions, reason: string, redirectUri?: string): Promise<null>;
|
|
123
|
+
export declare function bringYourOwnClientHandoff(target: ConnectTarget, opts: ConnectOptions, reason: string, redirectUri?: string, resolveEndpoint?: () => Promise<string | undefined>): Promise<null>;
|
|
122
124
|
/**
|
|
123
125
|
* Google issues "Desktop app" and "Web application" OAuth clients with the
|
|
124
126
|
* same client-id shape, but only a Web application client accepts HQ's hosted
|
|
@@ -133,5 +135,11 @@ export interface ConnectOwnership {
|
|
|
133
135
|
viewerPersonUid?: string;
|
|
134
136
|
}
|
|
135
137
|
export declare function findAlreadyConnected(connections: readonly AdminConnection[], app: string, ownership?: ConnectOwnership): AdminConnection | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* `connect --help` text for the `--json` stdout shapes. A sign-in that does
|
|
140
|
+
* not finish in this command prints exactly one JSON line on stdout, and
|
|
141
|
+
* `setup` says which of these it is.
|
|
142
|
+
*/
|
|
143
|
+
export declare const CONNECT_JSON_HELP = "\n--json output when the sign-in does not finish in this command (for example\nwith --link-only) is one JSON line on stdout. \"setup\" says which it is:\n {\"app\",\"setup\":\"sign-in-link\",\"authorizationUrl\"}\n Open authorizationUrl; the sign-in finishes on the HQ console.\n {\"app\",\"setup\":\"own-oauth-app\",\"callbackUrl\",\"command\"}\n Register callbackUrl with the provider, then run command with your\n app's client id (and its secret on stdin).\n {\"app\",\"setup\":\"console\",\"url\"?,\"serverAddress\"?}\n Finish on the console page at url (left out when the console address\n is unknown). serverAddress is the MCP endpoint to enter there.\nA finished connect prints the install result instead. Confirm any of the\nthree with `hq integrations list`.\n";
|
|
136
144
|
export declare function registerConnectCommands(integrations: Command): void;
|
|
137
145
|
//# sourceMappingURL=integrations-connect.d.ts.map
|
|
@@ -350,6 +350,13 @@ async function resolveKey(opts, appLabel) {
|
|
|
350
350
|
}
|
|
351
351
|
throw new IntegrationsCliError(`${appLabel} needs an API key. Pass it with --token-stdin (recommended, keeps it out of shell history) or --token <key>.`, { expected: true });
|
|
352
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Install or OAuth-start fields for a target, pinned to the reconnected
|
|
355
|
+
* connection when set, so a browser reconnect re-keys that row too.
|
|
356
|
+
*/
|
|
357
|
+
function installRefOf(target) {
|
|
358
|
+
return target.connectionId ? { ...target.ref, connectionId: target.connectionId } : target.ref;
|
|
359
|
+
}
|
|
353
360
|
/**
|
|
354
361
|
* Remote MCP endpoints the integrations.sh catalog lists as MCP without a URL.
|
|
355
362
|
*
|
|
@@ -623,7 +630,7 @@ async function connectViaOAuth(token, companyUid, target, opts) {
|
|
|
623
630
|
}
|
|
624
631
|
const requestedScopes = parseRequestedScopes(opts.scopes);
|
|
625
632
|
const startInput = {
|
|
626
|
-
...target
|
|
633
|
+
...installRefOf(target),
|
|
627
634
|
...(requestedScopes ? { scopes: requestedScopes } : {}),
|
|
628
635
|
};
|
|
629
636
|
const userClient = await resolveUserOAuthClient(opts, target.label);
|
|
@@ -667,7 +674,7 @@ async function connectViaOAuth(token, companyUid, target, opts) {
|
|
|
667
674
|
throw err;
|
|
668
675
|
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code)) {
|
|
669
676
|
listener.close();
|
|
670
|
-
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri);
|
|
677
|
+
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri, () => blueprintEndpoint(token, companyUid, target));
|
|
671
678
|
}
|
|
672
679
|
if (!CONSOLE_HANDOFF_CODES.has(err.code))
|
|
673
680
|
throw err;
|
|
@@ -731,12 +738,17 @@ companySlug, origin) {
|
|
|
731
738
|
* A `--mcp-url` or `--docs-url` target has no catalog row to search for over
|
|
732
739
|
* there — `resolveTarget` reduces a docs page to an opaque discovery receipt
|
|
733
740
|
* the console cannot take — so unless the handoff carries the address back,
|
|
734
|
-
* the only copy of it is in the caller's scrollback. A catalog target
|
|
735
|
-
* hint
|
|
741
|
+
* the only copy of it is in the caller's scrollback. A catalog target usually
|
|
742
|
+
* needs no hint, since its label is what they search for over there. A domain
|
|
743
|
+
* the catalog does not list (shopify.com, feedback_3013b98e) finds nothing in
|
|
744
|
+
* that search, so when the endpoint was resolved it is printed too.
|
|
736
745
|
*/
|
|
737
|
-
function targetSelectionHint(opts) {
|
|
746
|
+
function targetSelectionHint(opts, target) {
|
|
738
747
|
if (opts.mcpUrl)
|
|
739
748
|
return `Server address to enter there: ${redactSensitiveUrl(opts.mcpUrl)}`;
|
|
749
|
+
if (target?.ref.mcpUrl) {
|
|
750
|
+
return `Server address to enter there: ${redactSensitiveUrl(target.ref.mcpUrl)}`;
|
|
751
|
+
}
|
|
740
752
|
if (opts.docsUrl)
|
|
741
753
|
return `Found from these docs: ${redactSensitiveUrl(opts.docsUrl)}`;
|
|
742
754
|
if (opts.entryId)
|
|
@@ -803,10 +815,30 @@ function printConsoleDestination(target, opts, url) {
|
|
|
803
815
|
"(This session points at a control plane whose console address is not " +
|
|
804
816
|
"derivable — set HQ_CONSOLE_URL to name it.)");
|
|
805
817
|
}
|
|
806
|
-
const hint = targetSelectionHint(opts);
|
|
818
|
+
const hint = targetSelectionHint(opts, target);
|
|
807
819
|
if (hint)
|
|
808
820
|
console.error(` ${hint}`);
|
|
809
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* The `--json` stdout line for an outcome that ends on the console page.
|
|
824
|
+
*
|
|
825
|
+
* Every `connect --json` sign-in handoff prints exactly one line on stdout,
|
|
826
|
+
* told apart by `setup` (see CONNECT_JSON_HELP): this is the `"console"` one.
|
|
827
|
+
* It used to print nothing, so a bot reading stdout got an empty answer and
|
|
828
|
+
* exit 0. `url` is left out when the console address cannot be derived;
|
|
829
|
+
* `serverAddress` is the MCP endpoint to enter there, when one is known.
|
|
830
|
+
*/
|
|
831
|
+
function printConsoleJson(target, opts, url) {
|
|
832
|
+
if (!opts.json)
|
|
833
|
+
return;
|
|
834
|
+
const serverAddress = opts.mcpUrl ?? target.ref.mcpUrl;
|
|
835
|
+
console.log(JSON.stringify({
|
|
836
|
+
app: target.label,
|
|
837
|
+
setup: "console",
|
|
838
|
+
...(url ? { url: redactSensitiveUrl(url) } : {}),
|
|
839
|
+
...(serverAddress ? { serverAddress: redactSensitiveUrl(serverAddress) } : {}),
|
|
840
|
+
}));
|
|
841
|
+
}
|
|
810
842
|
/**
|
|
811
843
|
* Fallback for a backend that will not accept a loopback callback: send the
|
|
812
844
|
* caller to the console and let it run the whole sign-in.
|
|
@@ -829,6 +861,7 @@ async function consoleHandoff(target, opts) {
|
|
|
829
861
|
const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
|
|
830
862
|
console.error(chalk.yellow(`${target.label} signs in through the console, not the terminal — this HQ backend finishes these sign-ins there.`));
|
|
831
863
|
printConsoleDestination(target, opts, url);
|
|
864
|
+
printConsoleJson(target, opts, url);
|
|
832
865
|
// A console sign-in is started by the console, so there is nowhere to put a
|
|
833
866
|
// --scopes list. Saying nothing would let the connect finish with default
|
|
834
867
|
// permissions while the caller believes theirs were requested -- the exact
|
|
@@ -851,15 +884,23 @@ async function consoleHandoff(target, opts) {
|
|
|
851
884
|
* credentials — but only the console can collect them, so say what is needed
|
|
852
885
|
* and hand the page over rather than restating the refusal and stopping.
|
|
853
886
|
*/
|
|
854
|
-
export async function bringYourOwnClientHandoff(target, opts, reason, redirectUri) {
|
|
887
|
+
export async function bringYourOwnClientHandoff(target, opts, reason, redirectUri, resolveEndpoint) {
|
|
855
888
|
console.error(chalk.yellow(redactUrlsInText(reason)));
|
|
856
889
|
console.error(`${redactUrlsInText(target.label)} needs an OAuth app you register with the provider yourself.`);
|
|
890
|
+
// A domain, catalog or name connect (`connect shopify.com`) carries no MCP
|
|
891
|
+
// endpoint, and the recovery command must pin one: hq-pro reads a caller's
|
|
892
|
+
// own client credentials on the direct `mcpUrl` path only. Without this the
|
|
893
|
+
// handoff fell through to the generic Integrations page, where an app the
|
|
894
|
+
// catalog does not list has no control, no callback URL and no credential
|
|
895
|
+
// form (feedback_3013b98e). The endpoint is the one hq-pro's blueprint for
|
|
896
|
+
// the target names, the same lookup the access-key path uses.
|
|
897
|
+
const endpointTarget = await withResolvedEndpoint(target, resolveEndpoint);
|
|
857
898
|
// Prefer finishing here. The recovery needs two things the terminal can
|
|
858
899
|
// supply — the callback URL to register, and a client id + secret — and
|
|
859
900
|
// hq-pro sends the first one back on exactly these errors. Falling through
|
|
860
901
|
// to the console when either half is missing keeps the old behaviour rather
|
|
861
902
|
// than printing a half-command that cannot work.
|
|
862
|
-
const command = byoClientCommand(
|
|
903
|
+
const command = byoClientCommand(endpointTarget, opts);
|
|
863
904
|
if (redirectUri && command) {
|
|
864
905
|
console.error("");
|
|
865
906
|
console.error(`In the provider's developer portal, register this callback URL:`);
|
|
@@ -868,15 +909,72 @@ export async function bringYourOwnClientHandoff(target, opts, reason, redirectUr
|
|
|
868
909
|
console.error(` ${command}`);
|
|
869
910
|
console.error(chalk.dim("The secret is read from stdin, so it stays out of your shell history. " +
|
|
870
911
|
"Omit --client-secret-stdin for a public app that has no secret."));
|
|
912
|
+
if (opts.json) {
|
|
913
|
+
// `--json` callers (bots driving `--link-only`) read stdout only, so the
|
|
914
|
+
// setup path has to be there too, not just in the stderr prose.
|
|
915
|
+
console.log(JSON.stringify({
|
|
916
|
+
app: target.label,
|
|
917
|
+
setup: "own-oauth-app",
|
|
918
|
+
callbackUrl: redactSensitiveUrl(redirectUri),
|
|
919
|
+
command,
|
|
920
|
+
}));
|
|
921
|
+
}
|
|
871
922
|
return null;
|
|
872
923
|
}
|
|
873
924
|
const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
|
|
874
925
|
console.error("The console shows the callback URL to register and takes the credentials.");
|
|
875
|
-
printConsoleDestination(
|
|
926
|
+
printConsoleDestination(endpointTarget, opts, url);
|
|
927
|
+
printConsoleJson(endpointTarget, opts, url);
|
|
876
928
|
if (url && opts.browser !== false)
|
|
877
929
|
await open(url).catch((error) => warnBrowserOpenFailure(error));
|
|
878
930
|
return null;
|
|
879
931
|
}
|
|
932
|
+
/**
|
|
933
|
+
* `target` with the MCP endpoint `resolveEndpoint` names, when it had none.
|
|
934
|
+
*
|
|
935
|
+
* Best effort: a failed or empty lookup keeps `target` unchanged, which keeps
|
|
936
|
+
* the console handoff. A failure is logged, never thrown, because the caller
|
|
937
|
+
* is already reporting a refusal and a second error would bury it.
|
|
938
|
+
*/
|
|
939
|
+
async function withResolvedEndpoint(target, resolveEndpoint) {
|
|
940
|
+
if (target.ref.mcpUrl || !resolveEndpoint)
|
|
941
|
+
return target;
|
|
942
|
+
let mcpUrl;
|
|
943
|
+
try {
|
|
944
|
+
mcpUrl = await resolveEndpoint();
|
|
945
|
+
}
|
|
946
|
+
catch (error) {
|
|
947
|
+
console.warn("[hq-cli:integrations-connect] endpoint lookup failed", safeCaughtError(error));
|
|
948
|
+
return target;
|
|
949
|
+
}
|
|
950
|
+
if (!mcpUrl)
|
|
951
|
+
return target;
|
|
952
|
+
return {
|
|
953
|
+
...target,
|
|
954
|
+
ref: {
|
|
955
|
+
mcpUrl,
|
|
956
|
+
...(target.ref.provider ? { provider: target.ref.provider } : {}),
|
|
957
|
+
...(target.ref.displayName ? { displayName: target.ref.displayName } : {}),
|
|
958
|
+
...(target.ref.scope ? { scope: target.ref.scope } : {}),
|
|
959
|
+
},
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* The MCP endpoint hq-pro's blueprint names for a domain, catalog or name
|
|
964
|
+
* target, or undefined when the target has no such handle or the blueprint
|
|
965
|
+
* names no https `kind: "mcp"` surface.
|
|
966
|
+
*/
|
|
967
|
+
async function blueprintEndpoint(token, companyUid, target) {
|
|
968
|
+
const { domain, query, catalogEntryId } = target.ref;
|
|
969
|
+
if (!domain && !query && !catalogEntryId)
|
|
970
|
+
return undefined;
|
|
971
|
+
const blueprint = await pullBlueprint(token, companyUid, {
|
|
972
|
+
...(domain ? { domain } : {}),
|
|
973
|
+
...(query ? { query } : {}),
|
|
974
|
+
...(catalogEntryId ? { catalogEntryId } : {}),
|
|
975
|
+
});
|
|
976
|
+
return mcpUrlFromBlueprint(blueprint, { mcpOnly: true });
|
|
977
|
+
}
|
|
880
978
|
/**
|
|
881
979
|
* The copy-pasteable command that finishes a bring-your-own-app connect.
|
|
882
980
|
*
|
|
@@ -973,7 +1071,8 @@ async function resolveUserOAuthClient(opts, appLabel) {
|
|
|
973
1071
|
* console finishes the flow it did not start (hq-pro#2823, hq-console#783), so
|
|
974
1072
|
* the caller confirms with `hq integrations list` once the person says done.
|
|
975
1073
|
* The link goes to stdout (the whole line, unredacted: it is useless redacted)
|
|
976
|
-
* so a bot can read it; with --json it is `
|
|
1074
|
+
* so a bot can read it; with --json it is the `"sign-in-link"` line of
|
|
1075
|
+
* CONNECT_JSON_HELP.
|
|
977
1076
|
*/
|
|
978
1077
|
async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
979
1078
|
let started;
|
|
@@ -983,15 +1082,16 @@ async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
|
983
1082
|
catch (err) {
|
|
984
1083
|
if (!(err instanceof IntegrationsCliError) || !err.code)
|
|
985
1084
|
throw err;
|
|
986
|
-
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code))
|
|
987
|
-
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri);
|
|
1085
|
+
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code)) {
|
|
1086
|
+
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri, () => blueprintEndpoint(token, companyUid, target));
|
|
1087
|
+
}
|
|
988
1088
|
if (!CONSOLE_HANDOFF_CODES.has(err.code))
|
|
989
1089
|
throw err;
|
|
990
1090
|
return await consoleHandoff(target, { ...opts, browser: false });
|
|
991
1091
|
}
|
|
992
1092
|
const app = started.displayName || target.label;
|
|
993
1093
|
if (opts.json) {
|
|
994
|
-
console.log(JSON.stringify({ app, authorizationUrl: started.authorizationUrl }));
|
|
1094
|
+
console.log(JSON.stringify({ app, setup: "sign-in-link", authorizationUrl: started.authorizationUrl }));
|
|
995
1095
|
}
|
|
996
1096
|
else {
|
|
997
1097
|
console.error(`Sign-in link for ${redactUrlsInText(app)} (it finishes on the HQ console):`);
|
|
@@ -1021,7 +1121,7 @@ async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
|
1021
1121
|
*/
|
|
1022
1122
|
async function userClientSignIn(token, companyUid, target, opts, client, requestedScopes) {
|
|
1023
1123
|
const started = await startOAuth(token, companyUid, {
|
|
1024
|
-
...target
|
|
1124
|
+
...installRefOf(target),
|
|
1025
1125
|
clientId: client.clientId,
|
|
1026
1126
|
...(client.clientSecret ? { clientSecret: client.clientSecret } : {}),
|
|
1027
1127
|
// A caller who registered the app themselves is the one who knows which
|
|
@@ -1083,17 +1183,28 @@ async function completeCredentialIfNeeded(token, companyUid, target, opts, resul
|
|
|
1083
1183
|
console.error(chalk.dim(`${target.label} needs an API key to finish connecting.`));
|
|
1084
1184
|
const bearerToken = await resolveKey(opts, target.label);
|
|
1085
1185
|
return await installIntegration(token, companyUid, {
|
|
1086
|
-
...target
|
|
1186
|
+
...installRefOf(target),
|
|
1087
1187
|
authMode: "bearer",
|
|
1088
1188
|
bearerToken,
|
|
1089
1189
|
});
|
|
1090
1190
|
}
|
|
1091
|
-
|
|
1191
|
+
/**
|
|
1192
|
+
* The first https endpoint the blueprint names, recommended surface first.
|
|
1193
|
+
*
|
|
1194
|
+
* `mcpOnly` keeps only `kind: "mcp"` surfaces. The own-OAuth-app handoff
|
|
1195
|
+
* prints the result as `--mcp-url`, and a blueprint with no usable
|
|
1196
|
+
* recommended surface can still list a REST or GraphQL API first (Shopify's
|
|
1197
|
+
* Admin GraphQL URL), which is not an MCP server and would make the printed
|
|
1198
|
+
* command fail.
|
|
1199
|
+
*/
|
|
1200
|
+
function mcpUrlFromBlueprint(blueprint, { mcpOnly = false } = {}) {
|
|
1092
1201
|
const surfaces = [
|
|
1093
1202
|
...(blueprint.recommendedSurface ? [blueprint.recommendedSurface] : []),
|
|
1094
1203
|
...blueprint.surfaces,
|
|
1095
1204
|
];
|
|
1096
1205
|
for (const surface of surfaces) {
|
|
1206
|
+
if (mcpOnly && surface.kind !== "mcp")
|
|
1207
|
+
continue;
|
|
1097
1208
|
const url = surface.url?.trim();
|
|
1098
1209
|
if (url && /^https:\/\//i.test(url))
|
|
1099
1210
|
return url;
|
|
@@ -1416,6 +1527,25 @@ async function refuseIfAlreadyConnected(token, companyUid, app, opts) {
|
|
|
1416
1527
|
` Add a second: hq integrations connect ${shellQuote(app)}${requestedScope ? ` ${scopeFlag(requestedScope)}` : ""} --force`));
|
|
1417
1528
|
return true;
|
|
1418
1529
|
}
|
|
1530
|
+
/**
|
|
1531
|
+
* `connect --help` text for the `--json` stdout shapes. A sign-in that does
|
|
1532
|
+
* not finish in this command prints exactly one JSON line on stdout, and
|
|
1533
|
+
* `setup` says which of these it is.
|
|
1534
|
+
*/
|
|
1535
|
+
export const CONNECT_JSON_HELP = `
|
|
1536
|
+
--json output when the sign-in does not finish in this command (for example
|
|
1537
|
+
with --link-only) is one JSON line on stdout. "setup" says which it is:
|
|
1538
|
+
{"app","setup":"sign-in-link","authorizationUrl"}
|
|
1539
|
+
Open authorizationUrl; the sign-in finishes on the HQ console.
|
|
1540
|
+
{"app","setup":"own-oauth-app","callbackUrl","command"}
|
|
1541
|
+
Register callbackUrl with the provider, then run command with your
|
|
1542
|
+
app's client id (and its secret on stdin).
|
|
1543
|
+
{"app","setup":"console","url"?,"serverAddress"?}
|
|
1544
|
+
Finish on the console page at url (left out when the console address
|
|
1545
|
+
is unknown). serverAddress is the MCP endpoint to enter there.
|
|
1546
|
+
A finished connect prints the install result instead. Confirm any of the
|
|
1547
|
+
three with \`hq integrations list\`.
|
|
1548
|
+
`;
|
|
1419
1549
|
export function registerConnectCommands(integrations) {
|
|
1420
1550
|
integrations
|
|
1421
1551
|
.command("catalog [query]")
|
|
@@ -1550,6 +1680,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1550
1680
|
.option("--personal", "Connect it as your own personal connection (not --company <slug>, which picks the company)")
|
|
1551
1681
|
.option("--company-owned", "Connect it as a connection the whole company owns (needs permission to add company apps)")
|
|
1552
1682
|
.option("--json", "Machine-readable output")
|
|
1683
|
+
.addHelpText("after", CONNECT_JSON_HELP)
|
|
1553
1684
|
.action(async (app, opts) => {
|
|
1554
1685
|
connectScopeFromOptions(opts);
|
|
1555
1686
|
assertAuthMode(opts.auth);
|
|
@@ -1650,7 +1781,11 @@ export function registerConnectCommands(integrations) {
|
|
|
1650
1781
|
...(connection.installation?.displayName
|
|
1651
1782
|
? { displayName: connection.installation.displayName }
|
|
1652
1783
|
: {}),
|
|
1653
|
-
|
|
1784
|
+
// A legacy row is a shared one (hq-pro reports a creator-only
|
|
1785
|
+
// legacy row as person-owned), so it reconnects as a company
|
|
1786
|
+
// connection. Sending no scope defaulted to personal and wrote the
|
|
1787
|
+
// new key to a personal row (feedback_a79e0c89).
|
|
1788
|
+
...(connection.ownerType === "company" || connection.ownerType === "legacy"
|
|
1654
1789
|
? { scope: "company" }
|
|
1655
1790
|
: connection.ownerType === "person"
|
|
1656
1791
|
? { scope: "personal" }
|
|
@@ -1658,6 +1793,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1658
1793
|
},
|
|
1659
1794
|
...(opts.auth ? { authClass: opts.auth } : {}),
|
|
1660
1795
|
label: connection.installation?.displayName ?? bareProvider(connection.provider),
|
|
1796
|
+
connectionId: connection.id,
|
|
1661
1797
|
};
|
|
1662
1798
|
// Same gate `connectApp` applies. This path does not go through it —
|
|
1663
1799
|
// it resolves the endpoint off the existing connection and branches
|
|
@@ -1677,7 +1813,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1677
1813
|
const bearerToken = wantsKey ? await resolveKey(opts, target.label) : undefined;
|
|
1678
1814
|
try {
|
|
1679
1815
|
const result = await installIntegration(token, companyUid, {
|
|
1680
|
-
...target
|
|
1816
|
+
...installRefOf(target),
|
|
1681
1817
|
...(bearerToken ? { authMode: "bearer", bearerToken } : {}),
|
|
1682
1818
|
});
|
|
1683
1819
|
reportInstall(await completeCredentialIfNeeded(token, companyUid, target, opts, result), opts);
|
|
@@ -230,7 +230,7 @@ export declare function upstreamUnavailableMessage(status: number): string;
|
|
|
230
230
|
* status-specific message and `expected` classification unchanged.
|
|
231
231
|
*/
|
|
232
232
|
export declare function raiseIfUpstreamUnavailable(res: Response): void;
|
|
233
|
-
export declare function raiseIfUnauthorized(res: Response): void;
|
|
233
|
+
export declare function raiseIfUnauthorized(res: Response, body?: unknown): void;
|
|
234
234
|
/**
|
|
235
235
|
* A member connected, reinstalled, or signed in to an app that someone else
|
|
236
236
|
* already connected for the company. Members may add apps and reconnect their
|
|
@@ -13,7 +13,7 @@ import { delegatedMachineSessionFilePath, loadDelegatedMachineSession, getValidM
|
|
|
13
13
|
import { DEFAULT_COGNITO, ensureCognitoIdToken } from "../utils/cognito-session.js";
|
|
14
14
|
import chalk from "chalk";
|
|
15
15
|
import { vaultApiFetch } from "../utils/vault-api.js";
|
|
16
|
-
import {
|
|
16
|
+
import { unauthorizedError } from "../utils/unauthorized-error.js";
|
|
17
17
|
import { planGateErrorFromPayload } from "../utils/plan-gate-error.js";
|
|
18
18
|
import { redactErrorText } from "../utils/redact-error-text.js";
|
|
19
19
|
import { redactSensitiveUrls, redactUrlsInText } from "../utils/redact-url.js";
|
|
@@ -286,16 +286,21 @@ function gatewayErrorDetails(error) {
|
|
|
286
286
|
return { message, ...(rpcCode === undefined ? {} : { rpcCode }), shape };
|
|
287
287
|
}
|
|
288
288
|
// A 401 from ANY integration-gateway vault call means the caller's HQ session
|
|
289
|
-
// is expired or
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
289
|
+
// is expired, missing or rejected — an expected auth state, not an hq-cli
|
|
290
|
+
// defect. Raise the same typed AuthError the vault company-resolution paths
|
|
291
|
+
// use (HQ-CLI-8) so the top-level handler prints one actionable message and
|
|
292
|
+
// skips Sentry, instead of surfacing the opaque, unactionable
|
|
293
293
|
// "Integration gateway request failed (HTTP 401)" that shipped as a fatal from
|
|
294
294
|
// `callGateway` (HQ-CLI-9). Non-401 statuses keep their existing behavior:
|
|
295
295
|
// other 4xx stay expected client errors, 5xx still report.
|
|
296
|
-
|
|
296
|
+
//
|
|
297
|
+
// The message fits the caller (feedback_dfc0bb49): a person runs `hq login`,
|
|
298
|
+
// but a company Outpost job has no login to run, so it is told the server
|
|
299
|
+
// rejected the Outpost identity, with the server's code from `body` when the
|
|
300
|
+
// response carried one (OUTPOST_PRINCIPAL_INVALID), and the Outpost recovery.
|
|
301
|
+
export function raiseIfUnauthorized(res, body) {
|
|
297
302
|
if (res.status === 401)
|
|
298
|
-
throw
|
|
303
|
+
throw unauthorizedError({ body });
|
|
299
304
|
}
|
|
300
305
|
/**
|
|
301
306
|
* A member connected, reinstalled, or signed in to an app that someone else
|
|
@@ -322,7 +327,10 @@ const CLI_ERROR_MESSAGES = new Map([
|
|
|
322
327
|
* one route cannot quietly drift into reporting its 4xx as crashes.
|
|
323
328
|
*/
|
|
324
329
|
export async function raiseForResponse(res, fallback) {
|
|
325
|
-
|
|
330
|
+
// Read the 401 body for its server code (feedback_dfc0bb49); no other
|
|
331
|
+
// status reads the body before the guards below.
|
|
332
|
+
if (res.status === 401)
|
|
333
|
+
raiseIfUnauthorized(res, await res.json().catch(() => undefined));
|
|
326
334
|
raiseIfUpstreamUnavailable(res);
|
|
327
335
|
const body = (await res.json().catch(() => ({})));
|
|
328
336
|
// A plan-limit 402 is normally decoded by vaultApiFetch before it gets here.
|
|
@@ -704,7 +712,7 @@ export async function callGateway(token, params, idempotencyKey, method = "tools
|
|
|
704
712
|
terminalStatus = terminal.status;
|
|
705
713
|
}
|
|
706
714
|
if (res.status !== 202 && (!res.ok || !terminalMessage)) {
|
|
707
|
-
raiseIfUnauthorized(res);
|
|
715
|
+
raiseIfUnauthorized(res, message);
|
|
708
716
|
if (method === "tools/call" &&
|
|
709
717
|
params.acceptAsync === true &&
|
|
710
718
|
isInlineTimeoutStatus(res.status)) {
|
|
@@ -787,7 +795,7 @@ async function pollAsyncGatewayJob(token, companyUid, jobId, idempotencyKey, dea
|
|
|
787
795
|
clearTimeout(requestTimeout);
|
|
788
796
|
}
|
|
789
797
|
if (!res.ok) {
|
|
790
|
-
raiseIfUnauthorized(res);
|
|
798
|
+
raiseIfUnauthorized(res, poll);
|
|
791
799
|
raiseIfUpstreamUnavailable(res);
|
|
792
800
|
if (res.status === 404) {
|
|
793
801
|
throw new IntegrationsCliError(`Integration job ${jobId} was not found or is no longer available.`, { expected: true, status: 404 });
|
|
@@ -616,7 +616,7 @@ export function registerIntegrationsCommand(program) {
|
|
|
616
616
|
});
|
|
617
617
|
const body = (await res.json().catch(() => ({})));
|
|
618
618
|
if (!res.ok) {
|
|
619
|
-
raiseIfUnauthorized(res);
|
|
619
|
+
raiseIfUnauthorized(res, body);
|
|
620
620
|
raiseIfUpstreamUnavailable(res);
|
|
621
621
|
throw new IntegrationsCliError(body.error ?? `${decision} failed (HTTP ${res.status})`, { expected: isClientError(res.status) });
|
|
622
622
|
}
|