@indigoai-us/hq-cli 5.109.1 → 5.109.2

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 CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.109.2] — 2026-09-09
6
+
7
+ ### Fixed
8
+
9
+ - `hq integrations connect <app>` now says so when the app is already
10
+ connected, instead of opening a browser and waiting for a sign-in that
11
+ changes nothing. It prints the reconnect command for re-authorizing the
12
+ existing connection, and `--force` still adds a second one. Across a
13
+ few-hundred-app sweep the old behavior read as a silent failure.
14
+
15
+ The check only short-circuits a connection that is genuinely finished. A row
16
+ whose installation is still at `needs_credentials`, `pending`, `error`, or
17
+ `revoked` falls through to the ordinary connect, because that connect is the
18
+ only thing that repairs those states. An installation status the CLI does not
19
+ recognize is treated the same way, so an unknown state costs a redundant
20
+ sign-in rather than a stranded integration.
21
+
5
22
  ## [5.109.1] — 2026-09-08
6
23
 
7
24
  ### Added
@@ -17,6 +17,7 @@
17
17
  * "key" but is really OAuth-protected still connects on the first try.
18
18
  */
19
19
  import { Command } from "commander";
20
+ import type { AdminConnection } from "./integrations-core.js";
20
21
  /**
21
22
  * Validate `--auth` against the supported enum, rejecting an unknown value
22
23
  * before anything is installed. A finite provider/runtime option must never be
@@ -46,5 +47,6 @@ export declare function consoleOrigin(vaultApiUrl?: string): string | undefined;
46
47
  * by slug), or undefined when the console for this control plane is unknown.
47
48
  */
48
49
  export declare function consoleIntegrationsUrl(companySlug: string | undefined, origin: string | undefined): string | undefined;
50
+ export declare function findAlreadyConnected(connections: readonly AdminConnection[], app: string): AdminConnection | undefined;
49
51
  export declare function registerConnectCommands(integrations: Command): void;
50
52
  //# sourceMappingURL=integrations-connect.d.ts.map
@@ -20,7 +20,7 @@ import chalk from "chalk";
20
20
  import open from "open";
21
21
  import { DEFAULT_VAULT_API_URL, ensureCognitoIdToken, } from "../utils/cognito-session.js";
22
22
  import { getCompanyUid } from "../utils/vault-api.js";
23
- import { IntegrationsCliError, bareProvider, connectionDomain, printJson, revokedConnectionDetails, resolveConnection, } from "./integrations-core.js";
23
+ import { IntegrationsCliError, bareProvider, connectionDomain, fetchAdminSurface, printJson, revokedConnectionDetails, resolveConnection, } from "./integrations-core.js";
24
24
  import { completeOAuth, discoverDocs, installIntegration, listCatalog, pullBlueprint, startOAuth, } from "./integrations-api.js";
25
25
  import { startLoopbackListener } from "./integrations-oauth.js";
26
26
  /** hq-pro's machine code for "this endpoint needs a browser sign-in". */
@@ -886,6 +886,115 @@ async function connectApp(token, companyUid, app, opts, expectedRevivedConnectio
886
886
  throw err;
887
887
  }
888
888
  }
889
+ /**
890
+ * The connection `app` already names, if it is connected RIGHT NOW.
891
+ *
892
+ * `connect` used to start a fresh sign-in for an app that was already
893
+ * connected: it opened a browser, printed an authorize URL and waited, saying
894
+ * nothing about the connection already sitting there. Sweeping a few hundred
895
+ * apps, that reads as a silent failure — you approve a vendor a second time and
896
+ * get no acknowledgement that the first one exists.
897
+ *
898
+ * Only `status === "connected"` counts. A `needs-reauth`, `error` or `revoked`
899
+ * row is NOT a reason to refuse: those are exactly the rows a person runs this
900
+ * command to repair, and blocking them would strand the app.
901
+ *
902
+ * Matching is deliberately anchored on the app's own name. A connected
903
+ * `installation.domain` matches when it IS the app, or is a subdomain of it
904
+ * (`notion.com` is served by `mcp.notion.com`) — never the reverse, so an
905
+ * unrelated host can never be read as this app. The provider slug and display
906
+ * name are matched too, because `connect notion` and `connect notion.com` are
907
+ * the same request.
908
+ */
909
+ /**
910
+ * Whether a row is finished enough that starting another sign-in would be
911
+ * redundant work rather than the repair the caller needs.
912
+ *
913
+ * `connection.status === "connected"` is NOT sufficient on its own. A row can
914
+ * be connected at the connection level while its installation still sits at
915
+ * `needs_credentials`, `pending`, `error`, or `revoked` — states whose ONLY
916
+ * remedy is the very connect the caller just asked for. Short-circuiting those
917
+ * would strand them: the command would report "already connected" about a thing
918
+ * that cannot be used, and the person would have no way to fix it.
919
+ *
920
+ * So this is an allowlist, not a denylist of known-bad states. An absent
921
+ * installation is treated as settled (a non-factory connection has no
922
+ * installation to be mid-flight), but any PRESENT status other than `installed`
923
+ * is treated as unfinished. A status this CLI has not heard of therefore falls
924
+ * through to the ordinary connect — the safe direction, since a redundant
925
+ * sign-in costs a browser round-trip while a wrong skip costs a broken
926
+ * integration with no visible path out.
927
+ */
928
+ function isSettledInstallation(connection) {
929
+ const status = connection.installation?.status?.trim().toLowerCase();
930
+ return status === undefined || status === "" || status === "installed";
931
+ }
932
+ export function findAlreadyConnected(connections, app) {
933
+ const want = app.trim().toLowerCase();
934
+ if (want === "")
935
+ return undefined;
936
+ const wantSlug = displayNameSlug(want);
937
+ return connections.find((connection) => {
938
+ if (connection.status !== "connected")
939
+ return false;
940
+ if (!isSettledInstallation(connection))
941
+ return false;
942
+ const domain = (connectionDomain(connection) ?? "").toLowerCase();
943
+ if (domain === want || domain.endsWith(`.${want}`))
944
+ return true;
945
+ if (bareProvider(connection.provider).toLowerCase() === want)
946
+ return true;
947
+ const displayName = (connection.installation?.displayName ?? "").trim();
948
+ if (displayName === "")
949
+ return false;
950
+ if (displayName.toLowerCase() === want)
951
+ return true;
952
+ // `connect aws-marketplace` is the copy-pasteable form of the display name
953
+ // "AWS Marketplace", and it is what the catalog resolver already accepts.
954
+ // Compare on the same slug both ways or this check misses every app whose
955
+ // name has a space in it.
956
+ return wantSlug !== "" && displayNameSlug(displayName) === wantSlug;
957
+ });
958
+ }
959
+ /**
960
+ * Report an app as already connected instead of opening a second sign-in.
961
+ * Returns true when the connect should stop here.
962
+ */
963
+ async function refuseIfAlreadyConnected(token, companyUid, app, opts) {
964
+ // Only a plain `connect <app>`. An explicit --mcp-url / --docs-url /
965
+ // --entry-id names an endpoint rather than an installed app, and --force is
966
+ // the deliberate "yes, add another one" escape hatch.
967
+ if (!app || opts.force || opts.mcpUrl || opts.docsUrl || opts.entryId)
968
+ return false;
969
+ let connections;
970
+ try {
971
+ connections = (await fetchAdminSurface(token, companyUid)).connections ?? [];
972
+ }
973
+ catch {
974
+ // Never let this convenience check block a connect. If the list cannot be
975
+ // read, fall through and let the real flow report whatever is wrong.
976
+ return false;
977
+ }
978
+ const existing = findAlreadyConnected(connections, app);
979
+ if (!existing)
980
+ return false;
981
+ const slug = bareProvider(existing.provider);
982
+ if (opts.json) {
983
+ printJson({
984
+ ok: true,
985
+ alreadyConnected: true,
986
+ provider: slug,
987
+ connection: existing.id,
988
+ ...(connectionDomain(existing) ? { domain: connectionDomain(existing) } : {}),
989
+ });
990
+ return true;
991
+ }
992
+ const label = existing.installation?.displayName ?? slug;
993
+ console.log(chalk.green(`${label} is already connected.`));
994
+ console.log(chalk.dim(` Sign in again: hq integrations reconnect --provider ${slug}\n` +
995
+ ` Add a second: hq integrations connect ${shellQuote(app)} --force`));
996
+ return true;
997
+ }
889
998
  export function registerConnectCommands(integrations) {
890
999
  integrations
891
1000
  .command("catalog [query]")
@@ -1014,11 +1123,14 @@ export function registerConnectCommands(integrations) {
1014
1123
  .option("--scopes <list>", "Permissions to request, space- or comma-separated (default: what the app needs)")
1015
1124
  .option("--no-browser", "Print the sign-in URL instead of opening a browser")
1016
1125
  .option("--timeout <seconds>", "How long to wait for a browser sign-in (default 300)")
1126
+ .option("--force", "Connect again even if this app is already connected")
1017
1127
  .option("--json", "Machine-readable output")
1018
1128
  .action(async (app, opts) => {
1019
1129
  assertAuthMode(opts.auth);
1020
1130
  const token = await ensureCognitoIdToken();
1021
1131
  const companyUid = await getCompanyUid(token, opts.company);
1132
+ if (await refuseIfAlreadyConnected(token, companyUid, app, opts))
1133
+ return;
1022
1134
  await connectApp(token, companyUid, app, opts);
1023
1135
  });
1024
1136
  integrations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.109.1",
3
+ "version": "5.109.2",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {