@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/dist/connect.js
CHANGED
|
@@ -6,6 +6,8 @@ import { CliAuthError } from './auth.js';
|
|
|
6
6
|
* - hub 400 `unknown_resource` — the resource URL is not in the registry.
|
|
7
7
|
* - `needsHubLogin` — the hub rejected the KEY itself; re-run
|
|
8
8
|
* `antasphere login`.
|
|
9
|
+
* - `refusal` — the account was refused (403), not the key: print the
|
|
10
|
+
* server's own sentence and exit 3. No login fixes it.
|
|
9
11
|
* - `needsReExchange` — the tool rejected the 120 s JWT (expired/replayed
|
|
10
12
|
* in transit); run the exchange again.
|
|
11
13
|
* - tool 429 `rate_limited` — back off and retry.
|
|
@@ -30,6 +32,20 @@ export class CliConnectError extends CliAuthError {
|
|
|
30
32
|
get needsReExchange() {
|
|
31
33
|
return this.stage === 'tool' && this.status === 401;
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The person was refused, not the credential: a 403 that is not the
|
|
37
|
+
* scope case, from either side (`tool_access_denied` on a restricted
|
|
38
|
+
* tool, `unverified_email`, a grant the tool will not take). `message`
|
|
39
|
+
* is the server's own sentence; a runner prints it as is and exits
|
|
40
|
+
* `exitCode`, 3, the code the tool docs promise for a refusal.
|
|
41
|
+
*/
|
|
42
|
+
get refusal() {
|
|
43
|
+
return this.status === 403 && !this.needsHubLogin;
|
|
44
|
+
}
|
|
45
|
+
/** The exit code a runner uses for this error: 3 for a refusal, 1 otherwise. */
|
|
46
|
+
get exitCode() {
|
|
47
|
+
return this.refusal ? 3 : 1;
|
|
48
|
+
}
|
|
33
49
|
}
|
|
34
50
|
export class CliConnectClient {
|
|
35
51
|
hubBaseUrl;
|
|
@@ -40,7 +56,7 @@ export class CliConnectClient {
|
|
|
40
56
|
this.toolBaseUrl = options.toolBaseUrl.replace(/\/+$/, '');
|
|
41
57
|
this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
42
58
|
}
|
|
43
|
-
/** Step 1 — the hub mints the 120 s
|
|
59
|
+
/** Step 1 — the hub mints the 120 s user-scoped JWT for the tool's resource. */
|
|
44
60
|
toolToken(hubApiKey, body) {
|
|
45
61
|
return this.call('hub', `${this.hubBaseUrl}/api/v1/sso/tool-token`, body, hubApiKey);
|
|
46
62
|
}
|
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":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,WAAW,CAAC;AAgChE;;;;;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AAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,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
|
@@ -1,29 +1,31 @@
|
|
|
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
|
-
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';
|
|
17
|
+
export { assertToolNamespace, cachedConnectKey, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, profileCredential, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
|
|
18
|
+
export type { CliConfig, CliConnectKey, CliEnv, CliProfile, ProfileCredential, StoreConnectKeyOptions } from './config.js';
|
|
15
19
|
export { ask, printJson } from './io.js';
|
|
16
20
|
export type { CliIo } from './io.js';
|
|
17
|
-
export { CliUsageError,
|
|
18
|
-
export type { ResolveApiKeyOptions, ResolveBaseUrlOptions, ResolvedProfile } from './resolve.js';
|
|
21
|
+
export { CLOUD_PROFILE, CliUsageError, firstSet, normalizeUrl, profileNameFor, profileUrl, resolveApiKey, resolveBaseUrl, resolveOrg, resolveProfile, sameInstance, selectProfile } from './resolve.js';
|
|
22
|
+
export type { ProfileSource, ResolveApiKeyOptions, ResolveBaseUrlOptions, ResolveOrgOptions, ResolvedProfile, SelectProfileOptions, SelectedProfile } from './resolve.js';
|
|
19
23
|
export { CliAuthClient, CliAuthError } from './auth.js';
|
|
20
24
|
export type { CliAuthClientOptions, CliAuthCompleteBody, CliAuthCompleted, CliAuthMintedKey, CliAuthRequestBody, CliAuthRequested, CliAuthRevoked } from './auth.js';
|
|
21
25
|
export { CliConnectClient, CliConnectError } from './connect.js';
|
|
22
26
|
export type { CliConnectClientOptions, CliConnected, CliConnectResult, CliConnectStage, CliToolTokenBody, CliToolTokenMinted } from './connect.js';
|
|
23
|
-
export { activeHubProfile, connectOnDemand, probeToolInstance } from './connect-on-demand.js';
|
|
27
|
+
export { activeHubProfile, connectOnDemand, HUB_URL_ENV, probeToolInstance, refreshConnectKey, selectHubProfile } from './connect-on-demand.js';
|
|
24
28
|
export type { ConnectNoticeFacts, ConnectOnDemandMessages, ConnectOnDemandOptions, ConnectOnDemandOutcome, ToolInstanceProbe } from './connect-on-demand.js';
|
|
25
|
-
export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
|
|
26
|
-
export type { OrgContextOptions, ResolveTargetWorkspaceOptions } from './org.js';
|
|
27
29
|
export { migrateLegacyConfig } from './migrate.js';
|
|
28
30
|
export type { LegacyMigrationSpec, MigrationResult } from './migrate.js';
|
|
29
31
|
//# sourceMappingURL=index.d.ts.map
|
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;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,SAAS,EACT,aAAa,EACb,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EACL,aAAa,EACb,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EACV,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
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
|
-
export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
|
|
17
|
+
export { assertToolNamespace, cachedConnectKey, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, profileCredential, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
|
|
14
18
|
export { ask, printJson } from './io.js';
|
|
15
|
-
export { CliUsageError,
|
|
19
|
+
export { CLOUD_PROFILE, CliUsageError, firstSet, normalizeUrl, profileNameFor, profileUrl, resolveApiKey, resolveBaseUrl, resolveOrg, resolveProfile, sameInstance, selectProfile } from './resolve.js';
|
|
16
20
|
export { CliAuthClient, CliAuthError } from './auth.js';
|
|
17
21
|
export { CliConnectClient, CliConnectError } from './connect.js';
|
|
18
|
-
export { activeHubProfile, connectOnDemand, probeToolInstance } from './connect-on-demand.js';
|
|
19
|
-
export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
|
|
22
|
+
export { activeHubProfile, connectOnDemand, HUB_URL_ENV, probeToolInstance, refreshConnectKey, selectHubProfile } from './connect-on-demand.js';
|
|
20
23
|
export { migrateLegacyConfig } from './migrate.js';
|
|
21
24
|
//# 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;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,eAAe,EAChB,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EACL,aAAa,EACb,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACd,MAAM,cAAc,CAAC;AAWtB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAWxD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAUjE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/resolve.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import type { CliConfig, CliEnv, CliProfile } from './config.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A usage-level error: runners print `Error: <message>` and exit with
|
|
4
|
+
* `exitCode`. 1 is a usage or wire error; 3 is a refusal, the code the tool
|
|
5
|
+
* docs promise when the account may not do what it asked (the thrower says
|
|
6
|
+
* so, nothing else does).
|
|
7
|
+
*/
|
|
3
8
|
export declare class CliUsageError extends Error {
|
|
9
|
+
readonly exitCode: number;
|
|
10
|
+
constructor(message: string, opts?: {
|
|
11
|
+
exitCode?: number;
|
|
12
|
+
});
|
|
4
13
|
}
|
|
5
|
-
/**
|
|
6
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The implicit profile every tool CLI has at its cloud URL. It exists before
|
|
16
|
+
* anything is written to disk: a clean machine with an `antasphere login`
|
|
17
|
+
* runs the tool on it. `default` is not a magic name any more, just a
|
|
18
|
+
* profile a person may have.
|
|
19
|
+
*/
|
|
20
|
+
export declare const CLOUD_PROFILE = "cloud";
|
|
7
21
|
export interface ResolvedProfile {
|
|
8
22
|
/** The resolved profile name (undefined = flags/env only, nothing stored). */
|
|
9
23
|
name: string | undefined;
|
|
@@ -15,8 +29,85 @@ export interface ResolvedProfile {
|
|
|
15
29
|
* remedy (e.g. 'run `slideless profiles` to list them.').
|
|
16
30
|
*/
|
|
17
31
|
export declare function resolveProfile(config: CliConfig, requested: string | undefined, opts?: {
|
|
18
|
-
unknownHint?: string;
|
|
32
|
+
unknownHint?: string | undefined;
|
|
19
33
|
}): ResolvedProfile;
|
|
34
|
+
/**
|
|
35
|
+
* The comparable form of an instance URL: the scheme, the host (case-folded,
|
|
36
|
+
* port kept) and the path without trailing slashes; query and fragment
|
|
37
|
+
* dropped. Two URLs name the same instance when their normalized forms are
|
|
38
|
+
* equal. A string the URL parser refuses is only stripped of its trailing
|
|
39
|
+
* slashes.
|
|
40
|
+
*/
|
|
41
|
+
export declare function normalizeUrl(url: string): string;
|
|
42
|
+
/** Whether two URLs name the same instance (`normalizeUrl` equality). */
|
|
43
|
+
export declare function sameInstance(a: string, b: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The name an instance URL's profile gets when nothing named it: `cloud`
|
|
46
|
+
* for the tool's cloud URL, else the host with its port
|
|
47
|
+
* (`share.antasphere.com`, `localhost:3400`). The person may rename it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function profileNameFor(url: string, cloudUrl?: string | undefined): string;
|
|
50
|
+
/**
|
|
51
|
+
* The first value that is set, trimmed. An empty or whitespace-only flag,
|
|
52
|
+
* env var or profile field counts as unset and the next source applies (a
|
|
53
|
+
* `.env` leftover such as `SLIDELESS_URL=""` never hides the cloud URL).
|
|
54
|
+
*/
|
|
55
|
+
export declare function firstSet(...values: Array<string | undefined>): string | undefined;
|
|
56
|
+
/** The instance a profile is at: its `baseUrl`, else the tool's cloud URL.
|
|
57
|
+
* A blank `baseUrl` is no `baseUrl`. */
|
|
58
|
+
export declare function profileUrl(profile: CliProfile, cloudUrl: string | undefined): string | undefined;
|
|
59
|
+
/** The rule that picked the profile. */
|
|
60
|
+
export type ProfileSource = 'flag' | 'url' | 'active' | 'cloud';
|
|
61
|
+
export interface SelectedProfile extends ResolvedProfile {
|
|
62
|
+
/** Which rule chose it; undefined when nothing could be selected. */
|
|
63
|
+
source: ProfileSource | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* true = the profile is not on disk yet: it was made in memory for the
|
|
66
|
+
* instance URL given, or it is the implicit cloud profile, under a name
|
|
67
|
+
* no profile on disk has. `storeConnectKey` writes it on first contact,
|
|
68
|
+
* nothing else does.
|
|
69
|
+
*/
|
|
70
|
+
created: boolean;
|
|
71
|
+
}
|
|
72
|
+
export interface SelectProfileOptions {
|
|
73
|
+
config: CliConfig;
|
|
74
|
+
/** Value of --profile when given: wins over everything, must exist. */
|
|
75
|
+
requested?: string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The instance URL the run was pointed at, when one was: --api-url, else
|
|
78
|
+
* the tool's URL env var (the caller applies that order; a blank value
|
|
79
|
+
* counts as none). It selects the profile of that instance, or makes one
|
|
80
|
+
* in memory named for its host.
|
|
81
|
+
*/
|
|
82
|
+
apiUrl?: string | undefined;
|
|
83
|
+
/** The tool's cloud home; the implicit `cloud` profile lives there. */
|
|
84
|
+
cloudUrl?: string | undefined;
|
|
85
|
+
/** Appended to the unknown-profile error, e.g. 'run `slideless profiles`'. */
|
|
86
|
+
unknownHint?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A profile is an instance. The selection rule every tool CLI applies, in
|
|
90
|
+
* this order:
|
|
91
|
+
*
|
|
92
|
+
* 1. --profile <name>: that profile, which must exist.
|
|
93
|
+
* 2. --api-url / the URL env var: the profile whose instance that is (the
|
|
94
|
+
* active one first when several name it, then `cloud`, then the first
|
|
95
|
+
* declared); none → a profile made in memory, named for the host under
|
|
96
|
+
* a free name (`created: true`), so a cached key never travels to
|
|
97
|
+
* another origin and nothing is ever written onto another instance's
|
|
98
|
+
* profile.
|
|
99
|
+
* 3. The active profile, the choice the person made with `<tool> use`.
|
|
100
|
+
* 4. The profile at `cloudUrl`, `cloud` by default: the one on disk at
|
|
101
|
+
* that instance whatever its name (a `cloud` profile that lives
|
|
102
|
+
* elsewhere is not it), else made in memory under a free name
|
|
103
|
+
* (`created: true`).
|
|
104
|
+
*
|
|
105
|
+
* A profile with no `baseUrl` is at the cloud URL. Nothing here writes to
|
|
106
|
+
* disk, and no profile is ever repointed. A tool without a cloud URL and
|
|
107
|
+
* without a profile selects nothing (both fields undefined), and its URL
|
|
108
|
+
* resolution errors with the tool's own message.
|
|
109
|
+
*/
|
|
110
|
+
export declare function selectProfile(opts: SelectProfileOptions): SelectedProfile;
|
|
20
111
|
export interface ResolveBaseUrlOptions {
|
|
21
112
|
/** Value of --api-url (or an alias) when given. */
|
|
22
113
|
flag?: string | undefined;
|
|
@@ -24,15 +115,21 @@ export interface ResolveBaseUrlOptions {
|
|
|
24
115
|
/** The tool's URL env var, e.g. 'ANTASPHERE_URL' / 'SLIDELESS_URL'. */
|
|
25
116
|
envVar: string;
|
|
26
117
|
profile?: CliProfile | undefined;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
118
|
+
/**
|
|
119
|
+
* The tool's cloud home, the last fallback: every CLI that has a cloud
|
|
120
|
+
* instance ships it (`https://slideless.antasphere.com`), so a clean
|
|
121
|
+
* machine with an `antasphere login` needs no flag. A tool with none (a
|
|
122
|
+
* template placeholder) errors with `missingMessage` as before.
|
|
123
|
+
*/
|
|
124
|
+
cloudUrl?: string | undefined;
|
|
125
|
+
/** Error text when nothing resolves and there is no cloud URL. */
|
|
30
126
|
missingMessage?: string;
|
|
31
127
|
}
|
|
32
128
|
/**
|
|
33
129
|
* Base-URL resolution in the ecosystem-wide order:
|
|
34
|
-
* flag → tool env var → profile →
|
|
35
|
-
*
|
|
130
|
+
* flag → tool env var → profile → cloud URL → CliUsageError.
|
|
131
|
+
* A blank value counts as unset (the next source applies). The result is
|
|
132
|
+
* origin-normalized (trailing slashes stripped).
|
|
36
133
|
*/
|
|
37
134
|
export declare function resolveBaseUrl(opts: ResolveBaseUrlOptions): string;
|
|
38
135
|
export interface ResolveApiKeyOptions {
|
|
@@ -43,6 +140,24 @@ export interface ResolveApiKeyOptions {
|
|
|
43
140
|
envVar: string;
|
|
44
141
|
profile?: CliProfile | undefined;
|
|
45
142
|
}
|
|
46
|
-
/** API-key resolution: flag → tool env var → profile (undefined = public
|
|
143
|
+
/** API-key resolution: flag → tool env var → profile (undefined = public
|
|
144
|
+
* only); a blank value counts as unset. */
|
|
47
145
|
export declare function resolveApiKey(opts: ResolveApiKeyOptions): string | undefined;
|
|
146
|
+
export interface ResolveOrgOptions {
|
|
147
|
+
/** Value of --org when given: a hub organization id or name. */
|
|
148
|
+
flag?: string | undefined;
|
|
149
|
+
env: CliEnv;
|
|
150
|
+
/** The tool's org env var, e.g. 'ANTASPHERE_ORG' / 'SLIDELESS_ORG'. */
|
|
151
|
+
envVar: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The organization override for one command: --org, else the tool's org
|
|
155
|
+
* env var, else undefined. There is one organization notion in the family:
|
|
156
|
+
* the hub's server-side default organization applies when this answers
|
|
157
|
+
* undefined, and the override names a hub organization (id or name) that
|
|
158
|
+
* the tool maps to its own workspace through `central_account_id`. An empty
|
|
159
|
+
* or blank value counts as unset and the next source applies. Nothing is
|
|
160
|
+
* stored on this machine; nothing here ever reaches the exchange.
|
|
161
|
+
*/
|
|
162
|
+
export declare function resolveOrg(opts: ResolveOrgOptions): string | undefined;
|
|
48
163
|
//# sourceMappingURL=resolve.d.ts.map
|
package/dist/resolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjE
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;CAK9D;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAC9C,eAAe,CAajB;AAED;;;;;;GAMG;AACH,wBAAgB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,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAQlE;AAED,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAClC;AAED;4CAC4C;AAC5C,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAE5E;AAED,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAEtE"}
|
package/dist/resolve.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A usage-level error: runners print `Error: <message>` and exit with
|
|
3
|
+
* `exitCode`. 1 is a usage or wire error; 3 is a refusal, the code the tool
|
|
4
|
+
* docs promise when the account may not do what it asked (the thrower says
|
|
5
|
+
* so, nothing else does).
|
|
6
|
+
*/
|
|
2
7
|
export class CliUsageError extends Error {
|
|
8
|
+
exitCode;
|
|
9
|
+
constructor(message, opts = {}) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'CliUsageError';
|
|
12
|
+
this.exitCode = opts.exitCode ?? 1;
|
|
13
|
+
}
|
|
3
14
|
}
|
|
4
|
-
/**
|
|
5
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The implicit profile every tool CLI has at its cloud URL. It exists before
|
|
17
|
+
* anything is written to disk: a clean machine with an `antasphere login`
|
|
18
|
+
* runs the tool on it. `default` is not a magic name any more, just a
|
|
19
|
+
* profile a person may have.
|
|
20
|
+
*/
|
|
21
|
+
export const CLOUD_PROFILE = 'cloud';
|
|
6
22
|
/**
|
|
7
23
|
* The named (or active) profile of a tool's config, erroring on an
|
|
8
24
|
* explicitly named missing one. `unknownHint` lets the tool append its own
|
|
@@ -20,20 +36,163 @@ export function resolveProfile(config, requested, opts = {}) {
|
|
|
20
36
|
const profile = name ? config.profiles[name] : undefined;
|
|
21
37
|
return { name: profile ? name : undefined, profile };
|
|
22
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* The comparable form of an instance URL: the scheme, the host (case-folded,
|
|
41
|
+
* port kept) and the path without trailing slashes; query and fragment
|
|
42
|
+
* dropped. Two URLs name the same instance when their normalized forms are
|
|
43
|
+
* equal. A string the URL parser refuses is only stripped of its trailing
|
|
44
|
+
* slashes.
|
|
45
|
+
*/
|
|
46
|
+
export function normalizeUrl(url) {
|
|
47
|
+
try {
|
|
48
|
+
const u = new URL(url);
|
|
49
|
+
return `${u.protocol}//${u.host}${u.pathname}`.replace(/\/+$/, '');
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return url.replace(/\/+$/, '');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Whether two URLs name the same instance (`normalizeUrl` equality). */
|
|
56
|
+
export function sameInstance(a, b) {
|
|
57
|
+
return normalizeUrl(a) === normalizeUrl(b);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The name an instance URL's profile gets when nothing named it: `cloud`
|
|
61
|
+
* for the tool's cloud URL, else the host with its port
|
|
62
|
+
* (`share.antasphere.com`, `localhost:3400`). The person may rename it.
|
|
63
|
+
*/
|
|
64
|
+
export function profileNameFor(url, cloudUrl) {
|
|
65
|
+
if (cloudUrl && sameInstance(url, cloudUrl))
|
|
66
|
+
return CLOUD_PROFILE;
|
|
67
|
+
try {
|
|
68
|
+
return new URL(url).host;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return normalizeUrl(url).replace(/^[a-z][a-z0-9+.-]*:\/\//i, '');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The first value that is set, trimmed. An empty or whitespace-only flag,
|
|
76
|
+
* env var or profile field counts as unset and the next source applies (a
|
|
77
|
+
* `.env` leftover such as `SLIDELESS_URL=""` never hides the cloud URL).
|
|
78
|
+
*/
|
|
79
|
+
export function firstSet(...values) {
|
|
80
|
+
for (const v of values) {
|
|
81
|
+
const t = v?.trim();
|
|
82
|
+
if (t)
|
|
83
|
+
return t;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
/** The instance a profile is at: its `baseUrl`, else the tool's cloud URL.
|
|
88
|
+
* A blank `baseUrl` is no `baseUrl`. */
|
|
89
|
+
export function profileUrl(profile, cloudUrl) {
|
|
90
|
+
return firstSet(profile.baseUrl, cloudUrl);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The profile on disk at an instance, if any. When several name it: the
|
|
94
|
+
* active one, then the one named `cloud`, then the first declared.
|
|
95
|
+
*/
|
|
96
|
+
function profileAt(config, url, cloudUrl) {
|
|
97
|
+
const at = Object.entries(config.profiles).filter(([, p]) => {
|
|
98
|
+
const u = profileUrl(p, cloudUrl);
|
|
99
|
+
return u !== undefined && sameInstance(u, url);
|
|
100
|
+
});
|
|
101
|
+
const pick = at.find(([name]) => name === config.activeProfile) ??
|
|
102
|
+
at.find(([name]) => name === CLOUD_PROFILE) ??
|
|
103
|
+
at[0];
|
|
104
|
+
return pick ? { name: pick[0], profile: pick[1] } : undefined;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A profile made in memory for an instance nothing on disk names, under a
|
|
108
|
+
* name nothing on disk has: `cloud` for the cloud URL, else the host; when
|
|
109
|
+
* that name belongs to a profile at ANOTHER instance, the host, then
|
|
110
|
+
* `<host>-2`, `<host>-3`, … so `storeConnectKey` never writes onto a
|
|
111
|
+
* profile that is not this instance's.
|
|
112
|
+
*/
|
|
113
|
+
function freshProfileAt(config, url, cloudUrl) {
|
|
114
|
+
const host = profileNameFor(url);
|
|
115
|
+
let name = [profileNameFor(url, cloudUrl), host].find((c) => !(c in config.profiles));
|
|
116
|
+
for (let n = 2; name === undefined; n += 1) {
|
|
117
|
+
if (!(`${host}-${n}` in config.profiles))
|
|
118
|
+
name = `${host}-${n}`;
|
|
119
|
+
}
|
|
120
|
+
return { name, profile: { baseUrl: normalizeUrl(url) } };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A profile is an instance. The selection rule every tool CLI applies, in
|
|
124
|
+
* this order:
|
|
125
|
+
*
|
|
126
|
+
* 1. --profile <name>: that profile, which must exist.
|
|
127
|
+
* 2. --api-url / the URL env var: the profile whose instance that is (the
|
|
128
|
+
* active one first when several name it, then `cloud`, then the first
|
|
129
|
+
* declared); none → a profile made in memory, named for the host under
|
|
130
|
+
* a free name (`created: true`), so a cached key never travels to
|
|
131
|
+
* another origin and nothing is ever written onto another instance's
|
|
132
|
+
* profile.
|
|
133
|
+
* 3. The active profile, the choice the person made with `<tool> use`.
|
|
134
|
+
* 4. The profile at `cloudUrl`, `cloud` by default: the one on disk at
|
|
135
|
+
* that instance whatever its name (a `cloud` profile that lives
|
|
136
|
+
* elsewhere is not it), else made in memory under a free name
|
|
137
|
+
* (`created: true`).
|
|
138
|
+
*
|
|
139
|
+
* A profile with no `baseUrl` is at the cloud URL. Nothing here writes to
|
|
140
|
+
* disk, and no profile is ever repointed. A tool without a cloud URL and
|
|
141
|
+
* without a profile selects nothing (both fields undefined), and its URL
|
|
142
|
+
* resolution errors with the tool's own message.
|
|
143
|
+
*/
|
|
144
|
+
export function selectProfile(opts) {
|
|
145
|
+
const { config, cloudUrl } = opts;
|
|
146
|
+
if (opts.requested) {
|
|
147
|
+
const { name, profile } = resolveProfile(config, opts.requested, { unknownHint: opts.unknownHint });
|
|
148
|
+
return { name, profile, source: 'flag', created: false };
|
|
149
|
+
}
|
|
150
|
+
const apiUrl = firstSet(opts.apiUrl);
|
|
151
|
+
if (apiUrl) {
|
|
152
|
+
const found = profileAt(config, apiUrl, cloudUrl);
|
|
153
|
+
if (found)
|
|
154
|
+
return { ...found, source: 'url', created: false };
|
|
155
|
+
return { ...freshProfileAt(config, apiUrl, cloudUrl), source: 'url', created: true };
|
|
156
|
+
}
|
|
157
|
+
const active = resolveProfile(config, undefined);
|
|
158
|
+
if (active.name && active.profile)
|
|
159
|
+
return { ...active, source: 'active', created: false };
|
|
160
|
+
if (cloudUrl) {
|
|
161
|
+
const found = profileAt(config, cloudUrl, cloudUrl);
|
|
162
|
+
if (found)
|
|
163
|
+
return { ...found, source: 'cloud', created: false };
|
|
164
|
+
return { ...freshProfileAt(config, cloudUrl, cloudUrl), source: 'cloud', created: true };
|
|
165
|
+
}
|
|
166
|
+
return { name: undefined, profile: undefined, source: undefined, created: false };
|
|
167
|
+
}
|
|
23
168
|
/**
|
|
24
169
|
* Base-URL resolution in the ecosystem-wide order:
|
|
25
|
-
* flag → tool env var → profile →
|
|
26
|
-
*
|
|
170
|
+
* flag → tool env var → profile → cloud URL → CliUsageError.
|
|
171
|
+
* A blank value counts as unset (the next source applies). The result is
|
|
172
|
+
* origin-normalized (trailing slashes stripped).
|
|
27
173
|
*/
|
|
28
174
|
export function resolveBaseUrl(opts) {
|
|
29
|
-
const raw = opts.flag
|
|
175
|
+
const raw = firstSet(opts.flag, opts.env[opts.envVar], opts.profile?.baseUrl, opts.cloudUrl);
|
|
30
176
|
if (!raw) {
|
|
31
177
|
throw new CliUsageError(opts.missingMessage ?? `No instance configured — pass --api-url <url> or set ${opts.envVar}.`);
|
|
32
178
|
}
|
|
33
179
|
return raw.replace(/\/+$/, '');
|
|
34
180
|
}
|
|
35
|
-
/** API-key resolution: flag → tool env var → profile (undefined = public
|
|
181
|
+
/** API-key resolution: flag → tool env var → profile (undefined = public
|
|
182
|
+
* only); a blank value counts as unset. */
|
|
36
183
|
export function resolveApiKey(opts) {
|
|
37
|
-
return opts.flag
|
|
184
|
+
return firstSet(opts.flag, opts.env[opts.envVar], opts.profile?.apiKey);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The organization override for one command: --org, else the tool's org
|
|
188
|
+
* env var, else undefined. There is one organization notion in the family:
|
|
189
|
+
* the hub's server-side default organization applies when this answers
|
|
190
|
+
* undefined, and the override names a hub organization (id or name) that
|
|
191
|
+
* the tool maps to its own workspace through `central_account_id`. An empty
|
|
192
|
+
* or blank value counts as unset and the next source applies. Nothing is
|
|
193
|
+
* stored on this machine; nothing here ever reaches the exchange.
|
|
194
|
+
*/
|
|
195
|
+
export function resolveOrg(opts) {
|
|
196
|
+
return firstSet(opts.flag, opts.env[opts.envVar]);
|
|
38
197
|
}
|
|
39
198
|
//# sourceMappingURL=resolve.js.map
|
package/dist/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,QAAQ,CAAS;IAE1B,YAAY,OAAe,EAAE,OAA8B,EAAE;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,QAAQ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/cli-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Shared CLI foundation for Antasphere tool CLIs: the ~/.config/antasphere config home,
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Shared CLI foundation for Antasphere tool CLIs: the ~/.config/antasphere config home, profiles that are instances (with the implicit cloud profile), the flag → env → profile → cloud URL resolution, the per-command organization override, the instance email-OTP auth client, the hub→tool connect exchange with its connect-on-demand seam and stranded-key recovery, and the CliIo prompt seam",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|