@antasphere/cli-core 0.4.0 → 0.6.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 +217 -111
- package/dist/config.d.ts +63 -24
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +49 -9
- package/dist/config.js.map +1 -1
- package/dist/connect-on-demand.d.ts +101 -26
- package/dist/connect-on-demand.d.ts.map +1 -1
- package/dist/connect-on-demand.js +125 -53
- package/dist/connect-on-demand.js.map +1 -1
- package/dist/connect.d.ts +21 -6
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +17 -1
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +15 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -10
- package/dist/index.js.map +1 -1
- package/dist/resolve.d.ts +125 -10
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +167 -8
- package/dist/resolve.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +92 -25
- package/src/connect-on-demand.ts +206 -73
- package/src/connect.ts +27 -6
- package/src/index.ts +51 -13
- package/src/resolve.ts +234 -13
- package/dist/org.d.ts +0 -42
- package/dist/org.d.ts.map +0 -1
- package/dist/org.js +0 -39
- package/dist/org.js.map +0 -1
- package/src/org.ts +0 -73
package/src/index.ts
CHANGED
|
@@ -1,36 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @antasphere/cli-core — the shared foundation every Antasphere tool CLI
|
|
3
3
|
* builds on (hub-architecture §8): the `~/.config/antasphere/` config home
|
|
4
|
-
* with tool-namespaced profiles
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* with tool-namespaced profiles where A PROFILE IS AN INSTANCE (named for
|
|
5
|
+
* its host, the implicit `cloud` profile at the tool's cloud URL), the
|
|
6
|
+
* profile selection rule (--profile → instance URL → active → cloud), the
|
|
7
|
+
* flag → env → profile → cloud URL resolution order, the per-command
|
|
8
|
+
* organization override (`resolveOrg`; the hub's server-side default
|
|
9
|
+
* organization applies otherwise), the instance email-OTP auth client, the
|
|
10
|
+
* hub→tool cross-tool connect exchange (user-scoped, no org in the
|
|
11
|
+
* exchange) with its per-(tool profile, hub profile) key cache, the
|
|
12
|
+
* connect-on-demand seam a tool CLI runs when no direct credential
|
|
13
|
+
* resolved, the stranded-key recovery, and the CliIo prompt seam. Tool
|
|
10
14
|
* commands, wire types, and API surfaces live in the tools; this package
|
|
11
15
|
* carries only config/login plumbing, never secrets.
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
18
|
export {
|
|
15
19
|
assertToolNamespace,
|
|
20
|
+
cachedConnectKey,
|
|
16
21
|
clearConfig,
|
|
17
22
|
configPath,
|
|
18
23
|
HUB_TOOL,
|
|
19
24
|
loadConfig,
|
|
20
25
|
lookupConnectKey,
|
|
21
26
|
parseConfig,
|
|
27
|
+
profileCredential,
|
|
22
28
|
redactKey,
|
|
23
29
|
removeConnectKey,
|
|
24
30
|
saveConfig,
|
|
25
31
|
storeConnectKey
|
|
26
32
|
} from './config.js';
|
|
27
|
-
export type {
|
|
33
|
+
export type {
|
|
34
|
+
CliConfig,
|
|
35
|
+
CliConnectKey,
|
|
36
|
+
CliEnv,
|
|
37
|
+
CliProfile,
|
|
38
|
+
ProfileCredential,
|
|
39
|
+
StoreConnectKeyOptions
|
|
40
|
+
} from './config.js';
|
|
28
41
|
|
|
29
42
|
export { ask, printJson } from './io.js';
|
|
30
43
|
export type { CliIo } from './io.js';
|
|
31
44
|
|
|
32
|
-
export {
|
|
33
|
-
|
|
45
|
+
export {
|
|
46
|
+
CLOUD_PROFILE,
|
|
47
|
+
CliUsageError,
|
|
48
|
+
firstSet,
|
|
49
|
+
normalizeUrl,
|
|
50
|
+
profileNameFor,
|
|
51
|
+
profileUrl,
|
|
52
|
+
resolveApiKey,
|
|
53
|
+
resolveBaseUrl,
|
|
54
|
+
resolveOrg,
|
|
55
|
+
resolveProfile,
|
|
56
|
+
sameInstance,
|
|
57
|
+
selectProfile
|
|
58
|
+
} from './resolve.js';
|
|
59
|
+
export type {
|
|
60
|
+
ProfileSource,
|
|
61
|
+
ResolveApiKeyOptions,
|
|
62
|
+
ResolveBaseUrlOptions,
|
|
63
|
+
ResolveOrgOptions,
|
|
64
|
+
ResolvedProfile,
|
|
65
|
+
SelectProfileOptions,
|
|
66
|
+
SelectedProfile
|
|
67
|
+
} from './resolve.js';
|
|
34
68
|
|
|
35
69
|
export { CliAuthClient, CliAuthError } from './auth.js';
|
|
36
70
|
export type {
|
|
@@ -53,7 +87,14 @@ export type {
|
|
|
53
87
|
CliToolTokenMinted
|
|
54
88
|
} from './connect.js';
|
|
55
89
|
|
|
56
|
-
export {
|
|
90
|
+
export {
|
|
91
|
+
activeHubProfile,
|
|
92
|
+
connectOnDemand,
|
|
93
|
+
HUB_URL_ENV,
|
|
94
|
+
probeToolInstance,
|
|
95
|
+
refreshConnectKey,
|
|
96
|
+
selectHubProfile
|
|
97
|
+
} from './connect-on-demand.js';
|
|
57
98
|
export type {
|
|
58
99
|
ConnectNoticeFacts,
|
|
59
100
|
ConnectOnDemandMessages,
|
|
@@ -62,8 +103,5 @@ export type {
|
|
|
62
103
|
ToolInstanceProbe
|
|
63
104
|
} from './connect-on-demand.js';
|
|
64
105
|
|
|
65
|
-
export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
|
|
66
|
-
export type { OrgContextOptions, ResolveTargetWorkspaceOptions } from './org.js';
|
|
67
|
-
|
|
68
106
|
export { migrateLegacyConfig } from './migrate.js';
|
|
69
107
|
export type { LegacyMigrationSpec, MigrationResult } from './migrate.js';
|
package/src/resolve.ts
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import type { CliConfig, CliEnv, CliProfile } from './config.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A usage-level error: runners print `Error: <message>` and exit with
|
|
5
|
+
* `exitCode`. 1 is a usage or wire error; 3 is a refusal, the code the tool
|
|
6
|
+
* docs promise when the account may not do what it asked (the thrower says
|
|
7
|
+
* so, nothing else does).
|
|
8
|
+
*/
|
|
9
|
+
export class CliUsageError extends Error {
|
|
10
|
+
readonly exitCode: number;
|
|
11
|
+
|
|
12
|
+
constructor(message: string, opts: { exitCode?: number } = {}) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'CliUsageError';
|
|
15
|
+
this.exitCode = opts.exitCode ?? 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
5
18
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The implicit profile every tool CLI has at its cloud URL. It exists before
|
|
21
|
+
* anything is written to disk: a clean machine with an `antasphere login`
|
|
22
|
+
* runs the tool on it. `default` is not a magic name any more, just a
|
|
23
|
+
* profile a person may have.
|
|
24
|
+
*/
|
|
25
|
+
export const CLOUD_PROFILE = 'cloud';
|
|
8
26
|
|
|
9
27
|
export interface ResolvedProfile {
|
|
10
28
|
/** The resolved profile name (undefined = flags/env only, nothing stored). */
|
|
@@ -20,7 +38,7 @@ export interface ResolvedProfile {
|
|
|
20
38
|
export function resolveProfile(
|
|
21
39
|
config: CliConfig,
|
|
22
40
|
requested: string | undefined,
|
|
23
|
-
opts: { unknownHint?: string } = {}
|
|
41
|
+
opts: { unknownHint?: string | undefined } = {}
|
|
24
42
|
): ResolvedProfile {
|
|
25
43
|
if (requested) {
|
|
26
44
|
const profile = config.profiles[requested];
|
|
@@ -36,6 +54,181 @@ export function resolveProfile(
|
|
|
36
54
|
return { name: profile ? name : undefined, profile };
|
|
37
55
|
}
|
|
38
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The comparable form of an instance URL: the scheme, the host (case-folded,
|
|
59
|
+
* port kept) and the path without trailing slashes; query and fragment
|
|
60
|
+
* dropped. Two URLs name the same instance when their normalized forms are
|
|
61
|
+
* equal. A string the URL parser refuses is only stripped of its trailing
|
|
62
|
+
* slashes.
|
|
63
|
+
*/
|
|
64
|
+
export function normalizeUrl(url: string): string {
|
|
65
|
+
try {
|
|
66
|
+
const u = new URL(url);
|
|
67
|
+
return `${u.protocol}//${u.host}${u.pathname}`.replace(/\/+$/, '');
|
|
68
|
+
} catch {
|
|
69
|
+
return url.replace(/\/+$/, '');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether two URLs name the same instance (`normalizeUrl` equality). */
|
|
74
|
+
export function sameInstance(a: string, b: string): boolean {
|
|
75
|
+
return normalizeUrl(a) === normalizeUrl(b);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The name an instance URL's profile gets when nothing named it: `cloud`
|
|
80
|
+
* for the tool's cloud URL, else the host with its port
|
|
81
|
+
* (`share.antasphere.com`, `localhost:3400`). The person may rename it.
|
|
82
|
+
*/
|
|
83
|
+
export function profileNameFor(url: string, cloudUrl?: string | undefined): string {
|
|
84
|
+
if (cloudUrl && sameInstance(url, cloudUrl)) return CLOUD_PROFILE;
|
|
85
|
+
try {
|
|
86
|
+
return new URL(url).host;
|
|
87
|
+
} catch {
|
|
88
|
+
return normalizeUrl(url).replace(/^[a-z][a-z0-9+.-]*:\/\//i, '');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The first value that is set, trimmed. An empty or whitespace-only flag,
|
|
94
|
+
* env var or profile field counts as unset and the next source applies (a
|
|
95
|
+
* `.env` leftover such as `SLIDELESS_URL=""` never hides the cloud URL).
|
|
96
|
+
*/
|
|
97
|
+
export function firstSet(...values: Array<string | undefined>): string | undefined {
|
|
98
|
+
for (const v of values) {
|
|
99
|
+
const t = v?.trim();
|
|
100
|
+
if (t) return t;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The instance a profile is at: its `baseUrl`, else the tool's cloud URL.
|
|
106
|
+
* A blank `baseUrl` is no `baseUrl`. */
|
|
107
|
+
export function profileUrl(profile: CliProfile, cloudUrl: string | undefined): string | undefined {
|
|
108
|
+
return firstSet(profile.baseUrl, cloudUrl);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The profile on disk at an instance, if any. When several name it: the
|
|
113
|
+
* active one, then the one named `cloud`, then the first declared.
|
|
114
|
+
*/
|
|
115
|
+
function profileAt(
|
|
116
|
+
config: CliConfig,
|
|
117
|
+
url: string,
|
|
118
|
+
cloudUrl: string | undefined
|
|
119
|
+
): { name: string; profile: CliProfile } | undefined {
|
|
120
|
+
const at = Object.entries(config.profiles).filter(([, p]) => {
|
|
121
|
+
const u = profileUrl(p, cloudUrl);
|
|
122
|
+
return u !== undefined && sameInstance(u, url);
|
|
123
|
+
});
|
|
124
|
+
const pick =
|
|
125
|
+
at.find(([name]) => name === config.activeProfile) ??
|
|
126
|
+
at.find(([name]) => name === CLOUD_PROFILE) ??
|
|
127
|
+
at[0];
|
|
128
|
+
return pick ? { name: pick[0], profile: pick[1] } : undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A profile made in memory for an instance nothing on disk names, under a
|
|
133
|
+
* name nothing on disk has: `cloud` for the cloud URL, else the host; when
|
|
134
|
+
* that name belongs to a profile at ANOTHER instance, the host, then
|
|
135
|
+
* `<host>-2`, `<host>-3`, … so `storeConnectKey` never writes onto a
|
|
136
|
+
* profile that is not this instance's.
|
|
137
|
+
*/
|
|
138
|
+
function freshProfileAt(
|
|
139
|
+
config: CliConfig,
|
|
140
|
+
url: string,
|
|
141
|
+
cloudUrl: string | undefined
|
|
142
|
+
): { name: string; profile: CliProfile } {
|
|
143
|
+
const host = profileNameFor(url);
|
|
144
|
+
let name = [profileNameFor(url, cloudUrl), host].find((c) => !(c in config.profiles));
|
|
145
|
+
for (let n = 2; name === undefined; n += 1) {
|
|
146
|
+
if (!(`${host}-${n}` in config.profiles)) name = `${host}-${n}`;
|
|
147
|
+
}
|
|
148
|
+
return { name, profile: { baseUrl: normalizeUrl(url) } };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The rule that picked the profile. */
|
|
152
|
+
export type ProfileSource = 'flag' | 'url' | 'active' | 'cloud';
|
|
153
|
+
|
|
154
|
+
export interface SelectedProfile extends ResolvedProfile {
|
|
155
|
+
/** Which rule chose it; undefined when nothing could be selected. */
|
|
156
|
+
source: ProfileSource | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* true = the profile is not on disk yet: it was made in memory for the
|
|
159
|
+
* instance URL given, or it is the implicit cloud profile, under a name
|
|
160
|
+
* no profile on disk has. `storeConnectKey` writes it on first contact,
|
|
161
|
+
* nothing else does.
|
|
162
|
+
*/
|
|
163
|
+
created: boolean;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface SelectProfileOptions {
|
|
167
|
+
config: CliConfig;
|
|
168
|
+
/** Value of --profile when given: wins over everything, must exist. */
|
|
169
|
+
requested?: string | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* The instance URL the run was pointed at, when one was: --api-url, else
|
|
172
|
+
* the tool's URL env var (the caller applies that order; a blank value
|
|
173
|
+
* counts as none). It selects the profile of that instance, or makes one
|
|
174
|
+
* in memory named for its host.
|
|
175
|
+
*/
|
|
176
|
+
apiUrl?: string | undefined;
|
|
177
|
+
/** The tool's cloud home; the implicit `cloud` profile lives there. */
|
|
178
|
+
cloudUrl?: string | undefined;
|
|
179
|
+
/** Appended to the unknown-profile error, e.g. 'run `slideless profiles`'. */
|
|
180
|
+
unknownHint?: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* A profile is an instance. The selection rule every tool CLI applies, in
|
|
185
|
+
* this order:
|
|
186
|
+
*
|
|
187
|
+
* 1. --profile <name>: that profile, which must exist.
|
|
188
|
+
* 2. --api-url / the URL env var: the profile whose instance that is (the
|
|
189
|
+
* active one first when several name it, then `cloud`, then the first
|
|
190
|
+
* declared); none → a profile made in memory, named for the host under
|
|
191
|
+
* a free name (`created: true`), so a cached key never travels to
|
|
192
|
+
* another origin and nothing is ever written onto another instance's
|
|
193
|
+
* profile.
|
|
194
|
+
* 3. The active profile, the choice the person made with `<tool> use`.
|
|
195
|
+
* 4. The profile at `cloudUrl`, `cloud` by default: the one on disk at
|
|
196
|
+
* that instance whatever its name (a `cloud` profile that lives
|
|
197
|
+
* elsewhere is not it), else made in memory under a free name
|
|
198
|
+
* (`created: true`).
|
|
199
|
+
*
|
|
200
|
+
* A profile with no `baseUrl` is at the cloud URL. Nothing here writes to
|
|
201
|
+
* disk, and no profile is ever repointed. A tool without a cloud URL and
|
|
202
|
+
* without a profile selects nothing (both fields undefined), and its URL
|
|
203
|
+
* resolution errors with the tool's own message.
|
|
204
|
+
*/
|
|
205
|
+
export function selectProfile(opts: SelectProfileOptions): SelectedProfile {
|
|
206
|
+
const { config, cloudUrl } = opts;
|
|
207
|
+
|
|
208
|
+
if (opts.requested) {
|
|
209
|
+
const { name, profile } = resolveProfile(config, opts.requested, { unknownHint: opts.unknownHint });
|
|
210
|
+
return { name, profile, source: 'flag', created: false };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const apiUrl = firstSet(opts.apiUrl);
|
|
214
|
+
if (apiUrl) {
|
|
215
|
+
const found = profileAt(config, apiUrl, cloudUrl);
|
|
216
|
+
if (found) return { ...found, source: 'url', created: false };
|
|
217
|
+
return { ...freshProfileAt(config, apiUrl, cloudUrl), source: 'url', created: true };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const active = resolveProfile(config, undefined);
|
|
221
|
+
if (active.name && active.profile) return { ...active, source: 'active', created: false };
|
|
222
|
+
|
|
223
|
+
if (cloudUrl) {
|
|
224
|
+
const found = profileAt(config, cloudUrl, cloudUrl);
|
|
225
|
+
if (found) return { ...found, source: 'cloud', created: false };
|
|
226
|
+
return { ...freshProfileAt(config, cloudUrl, cloudUrl), source: 'cloud', created: true };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return { name: undefined, profile: undefined, source: undefined, created: false };
|
|
230
|
+
}
|
|
231
|
+
|
|
39
232
|
export interface ResolveBaseUrlOptions {
|
|
40
233
|
/** Value of --api-url (or an alias) when given. */
|
|
41
234
|
flag?: string | undefined;
|
|
@@ -43,19 +236,25 @@ export interface ResolveBaseUrlOptions {
|
|
|
43
236
|
/** The tool's URL env var, e.g. 'ANTASPHERE_URL' / 'SLIDELESS_URL'. */
|
|
44
237
|
envVar: string;
|
|
45
238
|
profile?: CliProfile | undefined;
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
239
|
+
/**
|
|
240
|
+
* The tool's cloud home, the last fallback: every CLI that has a cloud
|
|
241
|
+
* instance ships it (`https://slideless.antasphere.com`), so a clean
|
|
242
|
+
* machine with an `antasphere login` needs no flag. A tool with none (a
|
|
243
|
+
* template placeholder) errors with `missingMessage` as before.
|
|
244
|
+
*/
|
|
245
|
+
cloudUrl?: string | undefined;
|
|
246
|
+
/** Error text when nothing resolves and there is no cloud URL. */
|
|
49
247
|
missingMessage?: string;
|
|
50
248
|
}
|
|
51
249
|
|
|
52
250
|
/**
|
|
53
251
|
* Base-URL resolution in the ecosystem-wide order:
|
|
54
|
-
* flag → tool env var → profile →
|
|
55
|
-
*
|
|
252
|
+
* flag → tool env var → profile → cloud URL → CliUsageError.
|
|
253
|
+
* A blank value counts as unset (the next source applies). The result is
|
|
254
|
+
* origin-normalized (trailing slashes stripped).
|
|
56
255
|
*/
|
|
57
256
|
export function resolveBaseUrl(opts: ResolveBaseUrlOptions): string {
|
|
58
|
-
const raw = opts.flag
|
|
257
|
+
const raw = firstSet(opts.flag, opts.env[opts.envVar], opts.profile?.baseUrl, opts.cloudUrl);
|
|
59
258
|
if (!raw) {
|
|
60
259
|
throw new CliUsageError(
|
|
61
260
|
opts.missingMessage ?? `No instance configured — pass --api-url <url> or set ${opts.envVar}.`
|
|
@@ -73,7 +272,29 @@ export interface ResolveApiKeyOptions {
|
|
|
73
272
|
profile?: CliProfile | undefined;
|
|
74
273
|
}
|
|
75
274
|
|
|
76
|
-
/** API-key resolution: flag → tool env var → profile (undefined = public
|
|
275
|
+
/** API-key resolution: flag → tool env var → profile (undefined = public
|
|
276
|
+
* only); a blank value counts as unset. */
|
|
77
277
|
export function resolveApiKey(opts: ResolveApiKeyOptions): string | undefined {
|
|
78
|
-
return opts.flag
|
|
278
|
+
return firstSet(opts.flag, opts.env[opts.envVar], opts.profile?.apiKey);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface ResolveOrgOptions {
|
|
282
|
+
/** Value of --org when given: a hub organization id or name. */
|
|
283
|
+
flag?: string | undefined;
|
|
284
|
+
env: CliEnv;
|
|
285
|
+
/** The tool's org env var, e.g. 'ANTASPHERE_ORG' / 'SLIDELESS_ORG'. */
|
|
286
|
+
envVar: string;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The organization override for one command: --org, else the tool's org
|
|
291
|
+
* env var, else undefined. There is one organization notion in the family:
|
|
292
|
+
* the hub's server-side default organization applies when this answers
|
|
293
|
+
* undefined, and the override names a hub organization (id or name) that
|
|
294
|
+
* the tool maps to its own workspace through `central_account_id`. An empty
|
|
295
|
+
* or blank value counts as unset and the next source applies. Nothing is
|
|
296
|
+
* stored on this machine; nothing here ever reaches the exchange.
|
|
297
|
+
*/
|
|
298
|
+
export function resolveOrg(opts: ResolveOrgOptions): string | undefined {
|
|
299
|
+
return firstSet(opts.flag, opts.env[opts.envVar]);
|
|
79
300
|
}
|
package/dist/org.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type CliEnv } from './config.js';
|
|
2
|
-
/**
|
|
3
|
-
* Org context for the cross-tool connect flow (binding patterns §7). Orgs
|
|
4
|
-
* are HUB-level entities and the hub login is the one credential shared
|
|
5
|
-
* across the tool family, so the active org lives on the HUB profile:
|
|
6
|
-
* `antasphere org use` sets it, every tool CLI reads it when picking the
|
|
7
|
-
* org to exchange for.
|
|
8
|
-
*
|
|
9
|
-
* The effective target org for an exchange resolves in this order:
|
|
10
|
-
*
|
|
11
|
-
* explicit per-invocation override (--org)
|
|
12
|
-
* → the hub profile's active org (`org use`)
|
|
13
|
-
* → the hub key's bound workspace (set at login)
|
|
14
|
-
* → undefined — the exchange then omits `workspaceId` and the hub
|
|
15
|
-
* defaults to the key's bound org server-side.
|
|
16
|
-
*/
|
|
17
|
-
export interface OrgContextOptions {
|
|
18
|
-
/** Hub profile name; default = the hub config's active profile. */
|
|
19
|
-
profile?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The hub profile's effective active org: the `org use` choice when one is
|
|
23
|
-
* set, else the org the hub key was bound to at login. Undefined when not
|
|
24
|
-
* logged in (or an explicitly named profile is missing → CliUsageError).
|
|
25
|
-
*/
|
|
26
|
-
export declare function getActiveWorkspace(env: CliEnv, opts?: OrgContextOptions): string | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* What `antasphere org use` calls: persist the org choice on the hub
|
|
29
|
-
* profile (`null` clears it, falling back to the key's bound workspace).
|
|
30
|
-
* Every other profile field is preserved. Returns the file written.
|
|
31
|
-
*/
|
|
32
|
-
export declare function setActiveWorkspace(env: CliEnv, workspaceId: string | null, opts?: OrgContextOptions): string;
|
|
33
|
-
export interface ResolveTargetWorkspaceOptions extends OrgContextOptions {
|
|
34
|
-
/** Per-invocation override (--org). */
|
|
35
|
-
override?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* The org a cross-tool exchange should target: explicit override → active
|
|
39
|
-
* org → the hub key's bound workspace → undefined (hub decides).
|
|
40
|
-
*/
|
|
41
|
-
export declare function resolveTargetWorkspace(env: CliEnv, opts?: ResolveTargetWorkspaceOptions): string | undefined;
|
|
42
|
-
//# sourceMappingURL=org.d.ts.map
|
package/dist/org.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"org.d.ts","sourceRoot":"","sources":["../src/org.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAG5E;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,iBAAsB,GAAG,MAAM,GAAG,SAAS,CAGhG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,IAAI,GAAE,iBAAsB,GAC3B,MAAM,CAaR;AAED,MAAM,WAAW,6BAA8B,SAAQ,iBAAiB;IACtE,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,6BAAkC,GACvC,MAAM,GAAG,SAAS,CAEpB"}
|
package/dist/org.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { HUB_TOOL, loadConfig, saveConfig } from './config.js';
|
|
2
|
-
import { CliUsageError, resolveProfile } from './resolve.js';
|
|
3
|
-
/**
|
|
4
|
-
* The hub profile's effective active org: the `org use` choice when one is
|
|
5
|
-
* set, else the org the hub key was bound to at login. Undefined when not
|
|
6
|
-
* logged in (or an explicitly named profile is missing → CliUsageError).
|
|
7
|
-
*/
|
|
8
|
-
export function getActiveWorkspace(env, opts = {}) {
|
|
9
|
-
const { profile } = resolveProfile(loadConfig(env, HUB_TOOL), opts.profile);
|
|
10
|
-
return profile?.activeWorkspaceId ?? profile?.workspaceId;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* What `antasphere org use` calls: persist the org choice on the hub
|
|
14
|
-
* profile (`null` clears it, falling back to the key's bound workspace).
|
|
15
|
-
* Every other profile field is preserved. Returns the file written.
|
|
16
|
-
*/
|
|
17
|
-
export function setActiveWorkspace(env, workspaceId, opts = {}) {
|
|
18
|
-
const config = loadConfig(env, HUB_TOOL);
|
|
19
|
-
const { name, profile } = resolveProfile(config, opts.profile);
|
|
20
|
-
if (!name || !profile) {
|
|
21
|
-
throw new CliUsageError('No hub profile to set the org on — run `antasphere login` first.');
|
|
22
|
-
}
|
|
23
|
-
if (workspaceId === null) {
|
|
24
|
-
const { activeWorkspaceId: _cleared, ...rest } = profile;
|
|
25
|
-
config.profiles[name] = rest;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
config.profiles[name] = { ...profile, activeWorkspaceId: workspaceId };
|
|
29
|
-
}
|
|
30
|
-
return saveConfig(env, HUB_TOOL, config);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* The org a cross-tool exchange should target: explicit override → active
|
|
34
|
-
* org → the hub key's bound workspace → undefined (hub decides).
|
|
35
|
-
*/
|
|
36
|
-
export function resolveTargetWorkspace(env, opts = {}) {
|
|
37
|
-
return opts.override ?? getActiveWorkspace(env, opts);
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=org.js.map
|
package/dist/org.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"org.js","sourceRoot":"","sources":["../src/org.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAuB7D;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,OAA0B,EAAE;IAC1E,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5E,OAAO,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,WAAW,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAW,EACX,WAA0B,EAC1B,OAA0B,EAAE;IAE5B,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACzC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,aAAa,CAAC,kEAAkE,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QACzB,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QACzD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACzE,CAAC;IACD,OAAO,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAOD;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,GAAW,EACX,OAAsC,EAAE;IAExC,OAAO,IAAI,CAAC,QAAQ,IAAI,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACxD,CAAC"}
|
package/src/org.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { HUB_TOOL, loadConfig, saveConfig, type CliEnv } from './config.js';
|
|
2
|
-
import { CliUsageError, resolveProfile } from './resolve.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Org context for the cross-tool connect flow (binding patterns §7). Orgs
|
|
6
|
-
* are HUB-level entities and the hub login is the one credential shared
|
|
7
|
-
* across the tool family, so the active org lives on the HUB profile:
|
|
8
|
-
* `antasphere org use` sets it, every tool CLI reads it when picking the
|
|
9
|
-
* org to exchange for.
|
|
10
|
-
*
|
|
11
|
-
* The effective target org for an exchange resolves in this order:
|
|
12
|
-
*
|
|
13
|
-
* explicit per-invocation override (--org)
|
|
14
|
-
* → the hub profile's active org (`org use`)
|
|
15
|
-
* → the hub key's bound workspace (set at login)
|
|
16
|
-
* → undefined — the exchange then omits `workspaceId` and the hub
|
|
17
|
-
* defaults to the key's bound org server-side.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
export interface OrgContextOptions {
|
|
21
|
-
/** Hub profile name; default = the hub config's active profile. */
|
|
22
|
-
profile?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The hub profile's effective active org: the `org use` choice when one is
|
|
27
|
-
* set, else the org the hub key was bound to at login. Undefined when not
|
|
28
|
-
* logged in (or an explicitly named profile is missing → CliUsageError).
|
|
29
|
-
*/
|
|
30
|
-
export function getActiveWorkspace(env: CliEnv, opts: OrgContextOptions = {}): string | undefined {
|
|
31
|
-
const { profile } = resolveProfile(loadConfig(env, HUB_TOOL), opts.profile);
|
|
32
|
-
return profile?.activeWorkspaceId ?? profile?.workspaceId;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* What `antasphere org use` calls: persist the org choice on the hub
|
|
37
|
-
* profile (`null` clears it, falling back to the key's bound workspace).
|
|
38
|
-
* Every other profile field is preserved. Returns the file written.
|
|
39
|
-
*/
|
|
40
|
-
export function setActiveWorkspace(
|
|
41
|
-
env: CliEnv,
|
|
42
|
-
workspaceId: string | null,
|
|
43
|
-
opts: OrgContextOptions = {}
|
|
44
|
-
): string {
|
|
45
|
-
const config = loadConfig(env, HUB_TOOL);
|
|
46
|
-
const { name, profile } = resolveProfile(config, opts.profile);
|
|
47
|
-
if (!name || !profile) {
|
|
48
|
-
throw new CliUsageError('No hub profile to set the org on — run `antasphere login` first.');
|
|
49
|
-
}
|
|
50
|
-
if (workspaceId === null) {
|
|
51
|
-
const { activeWorkspaceId: _cleared, ...rest } = profile;
|
|
52
|
-
config.profiles[name] = rest;
|
|
53
|
-
} else {
|
|
54
|
-
config.profiles[name] = { ...profile, activeWorkspaceId: workspaceId };
|
|
55
|
-
}
|
|
56
|
-
return saveConfig(env, HUB_TOOL, config);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface ResolveTargetWorkspaceOptions extends OrgContextOptions {
|
|
60
|
-
/** Per-invocation override (--org). */
|
|
61
|
-
override?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The org a cross-tool exchange should target: explicit override → active
|
|
66
|
-
* org → the hub key's bound workspace → undefined (hub decides).
|
|
67
|
-
*/
|
|
68
|
-
export function resolveTargetWorkspace(
|
|
69
|
-
env: CliEnv,
|
|
70
|
-
opts: ResolveTargetWorkspaceOptions = {}
|
|
71
|
-
): string | undefined {
|
|
72
|
-
return opts.override ?? getActiveWorkspace(env, opts);
|
|
73
|
-
}
|