@antasphere/cli-core 0.3.0 → 0.4.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.
- package/README.md +40 -28
- package/dist/config.d.ts +26 -24
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -27
- package/dist/config.js.map +1 -1
- package/dist/connect-on-demand.d.ts +37 -24
- package/dist/connect-on-demand.d.ts.map +1 -1
- package/dist/connect-on-demand.js +45 -26
- package/dist/connect-on-demand.js.map +1 -1
- package/dist/connect.d.ts +43 -28
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +14 -8
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +38 -37
- package/src/connect-on-demand.ts +79 -46
- package/src/connect.ts +48 -31
- package/src/index.ts +9 -8
package/dist/connect.d.ts
CHANGED
|
@@ -5,17 +5,23 @@ import { CliAuthError, type CliAuthMintedKey } from './auth.js';
|
|
|
5
5
|
* API key is traded for a tool-local key in two calls:
|
|
6
6
|
*
|
|
7
7
|
* 1. POST {hub}/api/v1/sso/tool-token — auth = hub API key (Bearer),
|
|
8
|
-
* body `{ resource
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* body `{ resource }` → a USER-scoped, 120-second JWT for the tool's
|
|
9
|
+
* resource URL plus a one-time `hubRefreshToken` (the tool's standing
|
|
10
|
+
* offline grant for live as-the-user hub reads). Both are OPAQUE to
|
|
11
|
+
* this client: relayed hub → tool, never inspected or stored. The
|
|
12
|
+
* exchange names NO organization (hub ADR 014): the credential
|
|
13
|
+
* identifies the user; any org is a per-request selection tool-side.
|
|
11
14
|
* 2. POST {tool}/api/v1/sso/cli-connect — NO auth header (the JWT is
|
|
12
|
-
* the credential), body `{ token }` → the tool
|
|
13
|
-
*
|
|
15
|
+
* the credential), body `{ token, hubRefreshToken }` → the tool
|
|
16
|
+
* verifies, JIT-provisions, stores the grant, and mints an ordinary
|
|
17
|
+
* USER-scoped tool-local API key, returned exactly once.
|
|
14
18
|
*
|
|
15
19
|
* The hub key is sent to the HUB only — it never reaches the tool. The
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* hubRefreshToken is sent to the TOOL only (it is that tool's own grant;
|
|
21
|
+
* redeeming it needs the tool client's credentials) and never persisted by
|
|
22
|
+
* the CLI. The minted key is cached per (tool, hub profile) in the tool's
|
|
23
|
+
* config namespace (config.ts `connectKeys`); day-to-day tool CLI calls
|
|
24
|
+
* then take the ordinary local API-key path with the hub out of the loop.
|
|
19
25
|
*/
|
|
20
26
|
export type CliConnectStage = 'hub' | 'tool';
|
|
21
27
|
/**
|
|
@@ -23,8 +29,6 @@ export type CliConnectStage = 'hub' | 'tool';
|
|
|
23
29
|
* pick the remedy without string-matching:
|
|
24
30
|
*
|
|
25
31
|
* - hub 400 `unknown_resource` — the resource URL is not in the registry.
|
|
26
|
-
* - hub 403 `no_membership` / `workspace_suspended` — the target org is
|
|
27
|
-
* not exchangeable for this user; pick another org.
|
|
28
32
|
* - `needsHubLogin` — the hub rejected the KEY itself; re-run
|
|
29
33
|
* `antasphere login`.
|
|
30
34
|
* - `needsReExchange` — the tool rejected the 120 s JWT (expired/replayed
|
|
@@ -44,19 +48,23 @@ export declare class CliConnectError extends CliAuthError {
|
|
|
44
48
|
get needsReExchange(): boolean;
|
|
45
49
|
}
|
|
46
50
|
export interface CliToolTokenBody {
|
|
47
|
-
/** The tool's registry resource URL (e.g. `https://app.slideless.ai/mcp`).
|
|
51
|
+
/** The tool's registry resource URL (e.g. `https://app.slideless.ai/mcp`).
|
|
52
|
+
* The ONLY field — the exchange is user-scoped and names no org
|
|
53
|
+
* (hub contract `ssoToolTokenRequestSchema`, ADR 014). */
|
|
48
54
|
resource: string;
|
|
49
|
-
/** Target hub org — any live ACTIVE membership of the user (gcloud
|
|
50
|
-
* model); omit = the hub key's bound workspace. */
|
|
51
|
-
workspaceId?: string;
|
|
52
55
|
}
|
|
56
|
+
/** The hub's tool-token response (hub contract `ssoToolTokenSchema`). */
|
|
53
57
|
export interface CliToolTokenMinted {
|
|
54
|
-
/** The
|
|
58
|
+
/** The user-scoped exchange JWT — opaque, ~120 s; relay it, never keep it. */
|
|
55
59
|
token: string;
|
|
56
60
|
/** ISO expiry of the JWT (informational; the minted key outlives it). */
|
|
57
61
|
expiresAt: string;
|
|
58
|
-
/** The
|
|
59
|
-
|
|
62
|
+
/** The raw one-time offline-grant refresh token for the TARGET TOOL —
|
|
63
|
+
* relayed to that tool's /sso/cli-connect exactly once (it stores it as
|
|
64
|
+
* the standing grant for live as-the-user hub reads) and NEVER persisted
|
|
65
|
+
* or logged by the CLI. Without it, a fresh CLI user's connect is
|
|
66
|
+
* refused tool-side (`hub_grant_missing` — no key is minted born-dead). */
|
|
67
|
+
hubRefreshToken: string;
|
|
60
68
|
}
|
|
61
69
|
export interface CliConnected {
|
|
62
70
|
/** Full tool-local key (`slk_`-style) — shown once, never retrievable. */
|
|
@@ -67,12 +75,14 @@ export interface CliConnected {
|
|
|
67
75
|
email: string;
|
|
68
76
|
name: string;
|
|
69
77
|
};
|
|
70
|
-
/** The tool
|
|
71
|
-
|
|
78
|
+
/** The tool workspace the key is PINNED to — null on the live contract
|
|
79
|
+
* (user-scoped, unpinned; the org is a per-request parameter). */
|
|
80
|
+
workspaceId: string | null;
|
|
72
81
|
}
|
|
73
|
-
/** The flattened outcome of a full exchange
|
|
82
|
+
/** The flattened outcome of a full exchange. */
|
|
74
83
|
export interface CliConnectResult {
|
|
75
|
-
/** Full tool-local key —
|
|
84
|
+
/** Full tool-local key — user-scoped: ONE per (tool, hub profile),
|
|
85
|
+
* valid for every org the user can select per request (config.ts). */
|
|
76
86
|
key: string;
|
|
77
87
|
apiKey: CliAuthMintedKey;
|
|
78
88
|
user: {
|
|
@@ -80,10 +90,9 @@ export interface CliConnectResult {
|
|
|
80
90
|
email: string;
|
|
81
91
|
name: string;
|
|
82
92
|
};
|
|
83
|
-
/** The
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
toolWorkspaceId: string;
|
|
93
|
+
/** The tool workspace the key is pinned to — null = unpinned (the live
|
|
94
|
+
* contract always answers null; informational). */
|
|
95
|
+
toolWorkspaceId: string | null;
|
|
87
96
|
}
|
|
88
97
|
export interface CliConnectClientOptions {
|
|
89
98
|
/** Hub origin, e.g. https://account.antasphere.com */
|
|
@@ -99,9 +108,15 @@ export declare class CliConnectClient {
|
|
|
99
108
|
constructor(options: CliConnectClientOptions);
|
|
100
109
|
/** Step 1 — the hub mints the 120 s single-org JWT for the tool's resource. */
|
|
101
110
|
toolToken(hubApiKey: string, body: CliToolTokenBody): Promise<CliToolTokenMinted>;
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Step 2 — the tool verifies the JWT (its only credential) and mints its
|
|
113
|
+
* key. `hubRefreshToken` is the SAME response's offline grant, relayed so
|
|
114
|
+
* the tool can store it (a grant-less connect is refused for users with
|
|
115
|
+
* none already stored — `hub_grant_missing`).
|
|
116
|
+
*/
|
|
117
|
+
cliConnect(token: string, hubRefreshToken?: string): Promise<CliConnected>;
|
|
118
|
+
/** The full two-call exchange. The hub key goes to the hub ONLY; the
|
|
119
|
+
* offline grant goes to the TOOL only — neither is ever persisted here. */
|
|
105
120
|
exchange(hubApiKey: string, body: CliToolTokenBody): Promise<CliConnectResult>;
|
|
106
121
|
/** Mirrors CliAuthClient's parse: `{ error: { code, message, details } }` envelopes. */
|
|
107
122
|
private call;
|
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEhE
|
|
1
|
+
{"version":3,"file":"connect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MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD;wDACoD;IACpD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,uBAAuB;IACtC,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;gBAExC,OAAO,EAAE,uBAAuB;IAM5C,+EAA+E;IAC/E,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIjF;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAO1E;gFAC4E;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAWpF,wFAAwF;YAC1E,IAAI;CAkBnB"}
|
package/dist/connect.js
CHANGED
|
@@ -4,8 +4,6 @@ import { CliAuthError } from './auth.js';
|
|
|
4
4
|
* pick the remedy without string-matching:
|
|
5
5
|
*
|
|
6
6
|
* - hub 400 `unknown_resource` — the resource URL is not in the registry.
|
|
7
|
-
* - hub 403 `no_membership` / `workspace_suspended` — the target org is
|
|
8
|
-
* not exchangeable for this user; pick another org.
|
|
9
7
|
* - `needsHubLogin` — the hub rejected the KEY itself; re-run
|
|
10
8
|
* `antasphere login`.
|
|
11
9
|
* - `needsReExchange` — the tool rejected the 120 s JWT (expired/replayed
|
|
@@ -46,19 +44,27 @@ export class CliConnectClient {
|
|
|
46
44
|
toolToken(hubApiKey, body) {
|
|
47
45
|
return this.call('hub', `${this.hubBaseUrl}/api/v1/sso/tool-token`, body, hubApiKey);
|
|
48
46
|
}
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Step 2 — the tool verifies the JWT (its only credential) and mints its
|
|
49
|
+
* key. `hubRefreshToken` is the SAME response's offline grant, relayed so
|
|
50
|
+
* the tool can store it (a grant-less connect is refused for users with
|
|
51
|
+
* none already stored — `hub_grant_missing`).
|
|
52
|
+
*/
|
|
53
|
+
cliConnect(token, hubRefreshToken) {
|
|
54
|
+
return this.call('tool', `${this.toolBaseUrl}/api/v1/sso/cli-connect`, {
|
|
55
|
+
token,
|
|
56
|
+
...(hubRefreshToken ? { hubRefreshToken } : {})
|
|
57
|
+
});
|
|
52
58
|
}
|
|
53
|
-
/** The full two-call exchange. The hub key goes to the hub ONLY
|
|
59
|
+
/** The full two-call exchange. The hub key goes to the hub ONLY; the
|
|
60
|
+
* offline grant goes to the TOOL only — neither is ever persisted here. */
|
|
54
61
|
async exchange(hubApiKey, body) {
|
|
55
62
|
const minted = await this.toolToken(hubApiKey, body);
|
|
56
|
-
const connected = await this.cliConnect(minted.token);
|
|
63
|
+
const connected = await this.cliConnect(minted.token, minted.hubRefreshToken);
|
|
57
64
|
return {
|
|
58
65
|
key: connected.key,
|
|
59
66
|
apiKey: connected.apiKey,
|
|
60
67
|
user: connected.user,
|
|
61
|
-
hubWorkspaceId: minted.workspaceId,
|
|
62
68
|
toolWorkspaceId: connected.workspaceId
|
|
63
69
|
};
|
|
64
70
|
}
|
package/dist/connect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version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C,EAAE,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAC+B,CAAC;QAChF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,OAAO,GAAG,CAAC,IAAI,IAAI,EAAE,CAAuE,CAAC;YACnG,MAAM,IAAI,eAAe,CACvB,KAAK,EACL,GAAG,CAAC,MAAM,EACV,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,eAAe,EACtC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,uBAAuB,GAAG,CAAC,MAAM,EAAE,EAC7D,OAAO,CAAC,KAAK,EAAE,OAAO,CACvB,CAAC;QACJ,CAAC;QACD,OAAO,IAAS,CAAC;IACnB,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
* builds on (hub-architecture §8): the `~/.config/antasphere/` config home
|
|
4
4
|
* with tool-namespaced profiles, the flag → env → profile → default URL
|
|
5
5
|
* resolution order, the instance email-OTP auth client, the hub→tool
|
|
6
|
-
* cross-tool connect exchange (+ its per-(tool,
|
|
7
|
-
* hub-profile org context, and the connect-on-demand seam a
|
|
8
|
-
* when no direct credential resolved), and the CliIo prompt
|
|
6
|
+
* cross-tool connect exchange (+ its per-(tool, hub profile) user-scoped
|
|
7
|
+
* key cache, the hub-profile org context, and the connect-on-demand seam a
|
|
8
|
+
* tool CLI runs when no direct credential resolved), and the CliIo prompt
|
|
9
|
+
* seam. Tool
|
|
9
10
|
* commands, wire types, and API surfaces live in the tools; this package
|
|
10
11
|
* carries only config/login plumbing, never secrets.
|
|
11
12
|
*/
|
|
12
|
-
export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig,
|
|
13
|
-
export type { CliConfig, CliEnv, CliProfile
|
|
13
|
+
export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
|
|
14
|
+
export type { CliConfig, CliConnectKey, CliEnv, CliProfile } from './config.js';
|
|
14
15
|
export { ask, printJson } from './io.js';
|
|
15
16
|
export type { CliIo } from './io.js';
|
|
16
17
|
export { CliUsageError, DEFAULT_PROFILE, resolveApiKey, resolveBaseUrl, resolveProfile } from './resolve.js';
|
|
@@ -19,7 +20,7 @@ export { CliAuthClient, CliAuthError } from './auth.js';
|
|
|
19
20
|
export type { CliAuthClientOptions, CliAuthCompleteBody, CliAuthCompleted, CliAuthMintedKey, CliAuthRequestBody, CliAuthRequested, CliAuthRevoked } from './auth.js';
|
|
20
21
|
export { CliConnectClient, CliConnectError } from './connect.js';
|
|
21
22
|
export type { CliConnectClientOptions, CliConnected, CliConnectResult, CliConnectStage, CliToolTokenBody, CliToolTokenMinted } from './connect.js';
|
|
22
|
-
export { connectOnDemand, probeToolInstance } from './connect-on-demand.js';
|
|
23
|
+
export { activeHubProfile, connectOnDemand, probeToolInstance } from './connect-on-demand.js';
|
|
23
24
|
export type { ConnectNoticeFacts, ConnectOnDemandMessages, ConnectOnDemandOptions, ConnectOnDemandOutcome, ToolInstanceProbe } from './connect-on-demand.js';
|
|
24
25
|
export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
|
|
25
26
|
export type { OrgContextOptions, ResolveTargetWorkspaceOptions } from './org.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,gBAAgB,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c,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
* builds on (hub-architecture §8): the `~/.config/antasphere/` config home
|
|
4
4
|
* with tool-namespaced profiles, the flag → env → profile → default URL
|
|
5
5
|
* resolution order, the instance email-OTP auth client, the hub→tool
|
|
6
|
-
* cross-tool connect exchange (+ its per-(tool,
|
|
7
|
-
* hub-profile org context, and the connect-on-demand seam a
|
|
8
|
-
* when no direct credential resolved), and the CliIo prompt
|
|
6
|
+
* cross-tool connect exchange (+ its per-(tool, hub profile) user-scoped
|
|
7
|
+
* key cache, the hub-profile org context, and the connect-on-demand seam a
|
|
8
|
+
* tool CLI runs when no direct credential resolved), and the CliIo prompt
|
|
9
|
+
* seam. Tool
|
|
9
10
|
* commands, wire types, and API surfaces live in the tools; this package
|
|
10
11
|
* carries only config/login plumbing, never secrets.
|
|
11
12
|
*/
|
|
12
|
-
export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig,
|
|
13
|
+
export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
|
|
13
14
|
export { ask, printJson } from './io.js';
|
|
14
15
|
export { CliUsageError, DEFAULT_PROFILE, resolveApiKey, resolveBaseUrl, resolveProfile } from './resolve.js';
|
|
15
16
|
export { CliAuthClient, CliAuthError } from './auth.js';
|
|
16
17
|
export { CliConnectClient, CliConnectError } from './connect.js';
|
|
17
|
-
export { connectOnDemand, probeToolInstance } from './connect-on-demand.js';
|
|
18
|
+
export { activeHubProfile, connectOnDemand, probeToolInstance } from './connect-on-demand.js';
|
|
18
19
|
export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
|
|
19
20
|
export { migrateLegacyConfig } from './migrate.js';
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,eAAe,EAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG7G,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAWxD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAUjE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAS9F,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antasphere/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared CLI foundation for Antasphere tool CLIs: the ~/.config/antasphere config home, tool-namespaced profiles, URL resolution, the instance email-OTP auth client, the hub→tool cross-tool connect exchange with its connect-on-demand seam, and the CliIo prompt seam",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/config.ts
CHANGED
|
@@ -30,14 +30,15 @@ export type CliEnv = Record<string, string | undefined>;
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* A tool-local key minted by the cross-tool connect exchange (binding
|
|
33
|
-
* patterns §7), cached in the tool's profile under the HUB
|
|
34
|
-
*
|
|
33
|
+
* patterns §7), cached in the tool's profile under the HUB PROFILE whose
|
|
34
|
+
* `antasphere login` credential minted it. The key is USER-scoped (hub
|
|
35
|
+
* ADR 014): one key serves every org — the org is a per-request parameter,
|
|
36
|
+
* never part of the credential or of this cache's slot. Every field beyond
|
|
37
|
+
* the key itself is informational.
|
|
35
38
|
*/
|
|
36
|
-
export interface
|
|
39
|
+
export interface CliConnectKey {
|
|
37
40
|
/** Full tool-local API key (`slk_`-style) — shown once at mint, cached here. */
|
|
38
41
|
apiKey: string;
|
|
39
|
-
/** The tool-local workspace the key is bound to (the hub org's projection). */
|
|
40
|
-
toolWorkspaceId?: string;
|
|
41
42
|
/** The signed-in account's email at mint. */
|
|
42
43
|
email?: string;
|
|
43
44
|
/** ISO timestamp of the exchange that minted the key. */
|
|
@@ -53,12 +54,13 @@ export interface CliProfile {
|
|
|
53
54
|
email?: string;
|
|
54
55
|
/** The org/workspace the key is bound to (one workspace per credential). */
|
|
55
56
|
workspaceId?: string;
|
|
56
|
-
/** Hub profiles only: the org selected via `antasphere org use` (
|
|
57
|
-
*
|
|
57
|
+
/** Hub profiles only: the org selected via `antasphere org use` (the
|
|
58
|
+
* default per-request org context; never part of any credential). */
|
|
58
59
|
activeWorkspaceId?: string;
|
|
59
|
-
/** Tool profiles only: exchange-minted keys,
|
|
60
|
-
*
|
|
61
|
-
|
|
60
|
+
/** Tool profiles only: exchange-minted USER-scoped keys, ONE per hub
|
|
61
|
+
* profile — the (tool, hub profile) cache of the cross-tool connect
|
|
62
|
+
* flow. Org-independent: a cached key serves every org the user selects. */
|
|
63
|
+
connectKeys?: Record<string, CliConnectKey>;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export interface CliConfig {
|
|
@@ -147,62 +149,61 @@ export function redactKey(key: string): string {
|
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
/**
|
|
150
|
-
* The cached
|
|
151
|
-
*
|
|
152
|
-
* the
|
|
153
|
-
*
|
|
152
|
+
* The cached user-scoped connect key a HUB PROFILE minted for this tool
|
|
153
|
+
* profile, if any. The slot is the hub profile NAME — stable across runs
|
|
154
|
+
* and orgs (the key identifies the user; selecting a different org between
|
|
155
|
+
* runs never misses the cache).
|
|
154
156
|
*/
|
|
155
|
-
export function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return undefined;
|
|
157
|
+
export function lookupConnectKey(
|
|
158
|
+
profile: CliProfile | undefined,
|
|
159
|
+
hubProfileName: string
|
|
160
|
+
): string | undefined {
|
|
161
|
+
return profile?.connectKeys?.[hubProfileName]?.apiKey;
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
/**
|
|
164
|
-
* Cache an exchange-minted tool key under (profile, hub
|
|
165
|
-
* profile on first contact (and making it active when no profile is
|
|
166
|
-
* yet — first cloud connect on a fresh machine). Every other profile
|
|
167
|
-
* is preserved untouched. Returns the file written.
|
|
165
|
+
* Cache an exchange-minted tool key under (profile, hub profile), creating
|
|
166
|
+
* the profile on first contact (and making it active when no profile is
|
|
167
|
+
* active yet — first cloud connect on a fresh machine). Every other profile
|
|
168
|
+
* field is preserved untouched. Returns the file written.
|
|
168
169
|
*/
|
|
169
|
-
export function
|
|
170
|
+
export function storeConnectKey(
|
|
170
171
|
env: CliEnv,
|
|
171
172
|
tool: string,
|
|
172
173
|
profileName: string,
|
|
173
|
-
|
|
174
|
-
entry:
|
|
174
|
+
hubProfileName: string,
|
|
175
|
+
entry: CliConnectKey
|
|
175
176
|
): string {
|
|
176
177
|
const config = loadConfig(env, tool);
|
|
177
178
|
const profile = config.profiles[profileName] ?? {};
|
|
178
179
|
config.profiles[profileName] = {
|
|
179
180
|
...profile,
|
|
180
|
-
|
|
181
|
+
connectKeys: { ...profile.connectKeys, [hubProfileName]: entry }
|
|
181
182
|
};
|
|
182
183
|
if (!config.activeProfile) config.activeProfile = profileName;
|
|
183
184
|
return saveConfig(env, tool, config);
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
/**
|
|
187
|
-
* Drop one
|
|
188
|
-
* Returns whether anything was removed; the legacy single
|
|
189
|
-
* touched — it belongs to the tool's own login flow.
|
|
188
|
+
* Drop one hub profile's cached connect key (disconnect this tool from the
|
|
189
|
+
* hub account). Returns whether anything was removed; the legacy single
|
|
190
|
+
* `apiKey` is never touched — it belongs to the tool's own login flow.
|
|
190
191
|
*/
|
|
191
|
-
export function
|
|
192
|
+
export function removeConnectKey(
|
|
192
193
|
env: CliEnv,
|
|
193
194
|
tool: string,
|
|
194
195
|
profileName: string,
|
|
195
|
-
|
|
196
|
+
hubProfileName: string
|
|
196
197
|
): boolean {
|
|
197
198
|
const config = loadConfig(env, tool);
|
|
198
199
|
const profile = config.profiles[profileName];
|
|
199
|
-
if (!profile?.
|
|
200
|
-
const { [
|
|
200
|
+
if (!profile?.connectKeys || !(hubProfileName in profile.connectKeys)) return false;
|
|
201
|
+
const { [hubProfileName]: _dropped, ...rest } = profile.connectKeys;
|
|
201
202
|
if (Object.keys(rest).length === 0) {
|
|
202
|
-
const {
|
|
203
|
+
const { connectKeys: _empty, ...bare } = profile;
|
|
203
204
|
config.profiles[profileName] = bare;
|
|
204
205
|
} else {
|
|
205
|
-
config.profiles[profileName] = { ...profile,
|
|
206
|
+
config.profiles[profileName] = { ...profile, connectKeys: rest };
|
|
206
207
|
}
|
|
207
208
|
saveConfig(env, tool, config);
|
|
208
209
|
return true;
|