@agledger/cli 1.4.1 → 2.0.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/LICENSE +10 -14
- package/README.md +162 -16
- package/SKILL.md +14 -9
- package/dist/api-client.d.ts +24 -5
- package/dist/api-client.js +85 -16
- package/dist/base.d.ts +106 -31
- package/dist/base.js +299 -41
- package/dist/commands/api.d.ts +1 -0
- package/dist/commands/api.js +4 -3
- package/dist/commands/auth.d.ts +6 -2
- package/dist/commands/auth.js +20 -10
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.js +17 -1
- package/dist/commands/discover.d.ts +1 -0
- package/dist/commands/discover.js +5 -1
- package/dist/commands/docs.d.ts +1 -0
- package/dist/commands/docs.js +7 -1
- package/dist/commands/help-json.d.ts +1 -0
- package/dist/commands/list-commands.d.ts +1 -0
- package/dist/commands/login.d.ts +16 -3
- package/dist/commands/login.js +121 -10
- package/dist/commands/logout.d.ts +3 -1
- package/dist/commands/logout.js +35 -11
- package/dist/commands/verify.d.ts +22 -1
- package/dist/commands/verify.js +241 -21
- package/dist/oidc.d.ts +143 -0
- package/dist/oidc.js +384 -0
- package/dist/util/config.d.ts +13 -1
- package/oclif.manifest.json +147 -12
- package/package.json +2 -2
package/dist/base.d.ts
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
import { Command } from '@oclif/core';
|
|
12
12
|
import { ApiClient } from './api-client.js';
|
|
13
13
|
import type { ApiResponse } from './api-client.js';
|
|
14
|
+
import { OidcCertCredential, type OidcTokenSource } from './oidc.js';
|
|
15
|
+
import { type Profile } from './util/config.js';
|
|
14
16
|
/** Semantic exit codes for agent consumption. Stable across releases. */
|
|
15
17
|
export declare const ExitCode: {
|
|
16
18
|
readonly SUCCESS: 0;
|
|
@@ -32,8 +34,12 @@ export declare const ExitCode: {
|
|
|
32
34
|
*/
|
|
33
35
|
export declare const ErrorCode: {
|
|
34
36
|
readonly AUTH_REQUIRED: 'AUTH_REQUIRED';
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
+
/** The OIDC token command or file could not produce a token. */
|
|
38
|
+
readonly OIDC_TOKEN_SOURCE_FAILED: 'OIDC_TOKEN_SOURCE_FAILED';
|
|
39
|
+
/** The Server refused `POST /v1/auth/oidc/cert`; its error body rides along as `apiError`. */
|
|
40
|
+
readonly OIDC_EXCHANGE_FAILED: 'OIDC_EXCHANGE_FAILED';
|
|
41
|
+
/** Required configuration (currently the API URL) is absent or unusable.
|
|
42
|
+
* Exits as a usage error rather than claiming a new exit code. */
|
|
37
43
|
readonly CONFIG_ERROR: 'CONFIG_ERROR';
|
|
38
44
|
readonly COMMAND_NOT_FOUND: 'COMMAND_NOT_FOUND';
|
|
39
45
|
readonly MISSING_INPUT: 'MISSING_INPUT';
|
|
@@ -46,65 +52,133 @@ export declare const ErrorCode: {
|
|
|
46
52
|
readonly NETWORK_ERROR: 'NETWORK_ERROR';
|
|
47
53
|
readonly UNKNOWN_ERROR: 'UNKNOWN_ERROR';
|
|
48
54
|
};
|
|
55
|
+
type AuthFlags = {
|
|
56
|
+
'api-key'?: string;
|
|
57
|
+
'api-url'?: string;
|
|
58
|
+
profile?: string;
|
|
59
|
+
verbose?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** Where a command's credential comes from. Never holds a cert or a private key. */
|
|
62
|
+
export type ResolvedCredential = {
|
|
63
|
+
kind: 'api-key';
|
|
64
|
+
key: string;
|
|
65
|
+
from: 'flag-or-env' | 'profile';
|
|
66
|
+
origin: string;
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'oidc';
|
|
69
|
+
source: OidcTokenSource;
|
|
70
|
+
agentId?: string;
|
|
71
|
+
from: 'env' | 'profile';
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'none';
|
|
74
|
+
};
|
|
75
|
+
/** The OIDC token source stored on a profile, if it has one. */
|
|
76
|
+
export declare function profileOidcSource(name: string, profile: Profile | undefined): OidcTokenSource | undefined;
|
|
77
|
+
/** The OIDC token source named by the environment: the command outranks the file. */
|
|
78
|
+
export declare function envOidcSource(): OidcTokenSource | undefined;
|
|
79
|
+
/** The delegation token source from the environment. The command wins over the file. */
|
|
80
|
+
export declare function envOnBehalfOfSource(): OidcTokenSource | undefined;
|
|
81
|
+
/** Whether a flag was passed on the command line (`--flag value` or `--flag=value`),
|
|
82
|
+
* as opposed to reaching oclif through its `env` binding. */
|
|
83
|
+
export declare function argvHasFlag(flag: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Why an API URL cannot be used, or undefined when it can. Only an absolute
|
|
86
|
+
* http(s) URL can be: `new URL` alone takes `localhost:3100` as a URL whose
|
|
87
|
+
* scheme is `localhost:`, which then fails at request time as a fetch error.
|
|
88
|
+
*/
|
|
89
|
+
export declare function apiUrlProblem(url: string): string | undefined;
|
|
49
90
|
export declare abstract class BaseCommand extends Command {
|
|
50
91
|
/** The URL the most recent client was built for, so a network failure can
|
|
51
92
|
* name the host it actually tried. */
|
|
52
93
|
private lastApiUrl?;
|
|
94
|
+
/** The client `callApi` built for this invocation, reused by every later call. */
|
|
95
|
+
private client?;
|
|
96
|
+
/** True on a command whose --profile names the profile it is about to write
|
|
97
|
+
* (`login`), so a profile that does not exist yet is not an error there. */
|
|
98
|
+
protected readonly createsProfile: boolean;
|
|
99
|
+
/** The Idempotency-Key the most recent POST went out under, so a timeout or a
|
|
100
|
+
* dropped connection can hand it back for the retry. Undefined for any other
|
|
101
|
+
* method: the API ignores the header there, so there is no key to claim. */
|
|
102
|
+
private sentIdempotencyKey?;
|
|
53
103
|
static baseFlags: {
|
|
54
104
|
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
55
105
|
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
56
106
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
57
107
|
'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
58
108
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
109
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
59
110
|
};
|
|
60
111
|
protected get isJson(): boolean;
|
|
61
112
|
protected get isQuiet(): boolean;
|
|
113
|
+
/** Write one diagnostic line to stderr under --verbose. Callers pass no secrets. */
|
|
114
|
+
protected verboseLog(flags: {
|
|
115
|
+
verbose?: boolean;
|
|
116
|
+
}, event: Record<string, unknown>): void;
|
|
62
117
|
/**
|
|
63
|
-
* Resolve
|
|
118
|
+
* Resolve which credential a command uses, without calling anything.
|
|
64
119
|
*
|
|
65
|
-
* Precedence:
|
|
66
|
-
* API key
|
|
67
|
-
*
|
|
68
|
-
*
|
|
120
|
+
* Precedence, highest first:
|
|
121
|
+
* 1. An API key from `--api-key` or `AGLEDGER_API_KEY` (oclif merges the
|
|
122
|
+
* two into `flags['api-key']`).
|
|
123
|
+
* 2. `AGLEDGER_OIDC_TOKEN_CMD`, then `AGLEDGER_OIDC_TOKEN_FILE`.
|
|
124
|
+
* 3. The selected profile (`--profile <name>`, else the active one): its
|
|
125
|
+
* API key, or the OIDC token source `agledger login --oidc` stored.
|
|
69
126
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
127
|
+
* Explicit per-invocation sources outrank stored ones, which is the rule the
|
|
128
|
+
* API key already followed. `AGLEDGER_OIDC_AGENT_ID` overrides a profile's
|
|
129
|
+
* stored agent id. That id is only an assertion sent on the exchange: the
|
|
130
|
+
* token decides the agent, and the Server refuses a mismatch.
|
|
74
131
|
*/
|
|
75
|
-
protected
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
profile?:
|
|
79
|
-
}
|
|
132
|
+
protected resolveCredential(flags: AuthFlags): {
|
|
133
|
+
credential: ResolvedCredential;
|
|
134
|
+
profileName?: string;
|
|
135
|
+
profile?: Profile;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Resolve credentials and build the API client.
|
|
139
|
+
*
|
|
140
|
+
* Credential precedence is `resolveCredential`'s. API URL: `--api-url` flag >
|
|
141
|
+
* `AGLEDGER_API_URL` env > stored profile url. There is no default;
|
|
142
|
+
* AGLedger is self-hosted.
|
|
143
|
+
*/
|
|
144
|
+
protected createApiClient(flags: AuthFlags, options?: {
|
|
80
145
|
allowAnonymous?: boolean;
|
|
81
146
|
}): ApiClient;
|
|
147
|
+
/** Exit 3 when `--profile` names a profile that is not stored. */
|
|
148
|
+
protected requireNamedProfile(flags: {
|
|
149
|
+
profile?: string;
|
|
150
|
+
}, profile: Profile | undefined): void;
|
|
151
|
+
/** Refuse an API URL that is not an absolute http(s) URL, naming where it came from. */
|
|
152
|
+
protected requireUsableApiUrl(apiUrl: string, origin: string): void;
|
|
153
|
+
/** Build a cert credential for one invocation. Its key pair never leaves memory. */
|
|
154
|
+
protected oidcCredential(flags: {
|
|
155
|
+
verbose?: boolean;
|
|
156
|
+
}, credential: {
|
|
157
|
+
source: OidcTokenSource;
|
|
158
|
+
agentId?: string;
|
|
159
|
+
}): OidcCertCredential;
|
|
160
|
+
/** A secret-free description of a credential, for --verbose, --dry-run and `auth`. */
|
|
161
|
+
protected describeCredential(credential: ResolvedCredential): Record<string, unknown>;
|
|
82
162
|
/**
|
|
83
163
|
* Resolve the credentials that an actual call would use, for --dry-run display.
|
|
84
|
-
* Same precedence as `createApiClient
|
|
85
|
-
*
|
|
86
|
-
*
|
|
164
|
+
* Same precedence as `createApiClient`, but the key is masked so it is safe
|
|
165
|
+
* to print, and an OIDC token source is named, never run. Does not throw on
|
|
166
|
+
* a missing credential (dry-run is non-fatal).
|
|
87
167
|
*/
|
|
88
|
-
protected resolvedAuth(flags: {
|
|
89
|
-
'api-key'?: string;
|
|
90
|
-
'api-url'?: string;
|
|
91
|
-
profile?: string;
|
|
92
|
-
}): {
|
|
168
|
+
protected resolvedAuth(flags: AuthFlags): {
|
|
93
169
|
apiUrl: string | null;
|
|
94
170
|
apiUrlSource?: string;
|
|
95
171
|
apiKey: string | null;
|
|
96
|
-
source: 'flag-or-env' | 'profile' | 'none';
|
|
172
|
+
source: 'flag-or-env' | 'env' | 'profile' | 'none';
|
|
173
|
+
credential: 'api-key' | 'oidc-cert' | 'none';
|
|
174
|
+
oidcTokenSource?: string;
|
|
97
175
|
profile?: string;
|
|
98
176
|
};
|
|
99
177
|
/**
|
|
100
178
|
* Call the API. Path is passed through as-is; caller provides the full path
|
|
101
179
|
* (e.g. `/v1/records`, `/health`, `/federation/v1/peer`). No auto-prefixing.
|
|
102
180
|
*/
|
|
103
|
-
protected callApi(flags: {
|
|
104
|
-
'api-key'?: string;
|
|
105
|
-
'api-url'?: string;
|
|
106
|
-
profile?: string;
|
|
107
|
-
}, method: string, path: string, options?: {
|
|
181
|
+
protected callApi(flags: AuthFlags, method: string, path: string, options?: {
|
|
108
182
|
query?: Record<string, unknown>;
|
|
109
183
|
body?: unknown;
|
|
110
184
|
idempotencyKey?: string;
|
|
@@ -126,7 +200,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
126
200
|
protected parseJsonInput(source: string, fieldName: string, suggestion?: string): unknown;
|
|
127
201
|
/** Read and parse a JSON file with structured errors. `-` reads from stdin. */
|
|
128
202
|
protected readJsonSource(path: string, fieldName: string, suggestion?: string): unknown;
|
|
129
|
-
protected failWith(code: string, message: string, exitCode: number, suggestion?: string): never;
|
|
203
|
+
protected failWith(code: string, message: string, exitCode: number, suggestion?: string, extra?: Record<string, unknown>): never;
|
|
130
204
|
/**
|
|
131
205
|
* Forward the full API error body to stderr verbatim. The API owns error
|
|
132
206
|
* guidance (code, message, suggestion, validationErrors, nextSteps); the CLI
|
|
@@ -136,3 +210,4 @@ export declare abstract class BaseCommand extends Command {
|
|
|
136
210
|
protected handleError(err: unknown): never;
|
|
137
211
|
private statusToExitCode;
|
|
138
212
|
}
|
|
213
|
+
export {};
|