@agledger/cli 1.5.0 → 2.1.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.
@@ -19,7 +19,7 @@ export default class Api extends BaseCommand {
19
19
  'agledger api GET /v1/records -F status=ACTIVE -F limit=50',
20
20
  'agledger api POST /v1/records --data \'{"type":"notarize-generic-v1","criteria":{"summary":"..."}}\'',
21
21
  'agledger api POST /v1/records -F type=notarize-generic-v1 -F criteria.summary="summarize Q3 filings"',
22
- 'agledger api POST /v1/records -F type=notarize-generic-v1 -f externalTaskId=4821 # -f keeps a digit-only id a string',
22
+ 'agledger api POST /v1/records -F type=notarize-generic-v1 -F criteria.summary="file Q3 report" -f externalTaskId=4821 # -f keeps a digit-only id a string',
23
23
  'agledger api POST /v1/records --input payload.json',
24
24
  'cat payload.json | agledger api POST /v1/records --input -',
25
25
  'agledger api GET /v1/records --paginate # streams all pages as NDJSON',
@@ -60,7 +60,7 @@ export default class Api extends BaseCommand {
60
60
  default: false,
61
61
  }),
62
62
  'idempotency-key': Flags.string({
63
- description: 'Dedup key for POST, max 256 chars. One is generated per call, so pass this only when retrying a call that may already have reached the Server: reuse the first attempt\'s key and it replays the original result instead of creating a second record. Bound to method, route and body, so a retry with a changed body is rejected.',
63
+ description: 'Dedup key for POST, max 256 chars. One is generated per call and shown by --verbose, and a TIMEOUT or dropped-connection error carries it as `idempotencyKey`. Pass this only when retrying a call that may already have reached the Server: reuse the first attempt\'s key and it replays the original result instead of creating a second record, where a rerun without it can create a duplicate. Bound to method, route and body, so a retry with a changed body is rejected.',
64
64
  }),
65
65
  'dry-run': Flags.boolean({
66
66
  description: 'Show the request that would be sent without calling the API.',
@@ -109,7 +109,8 @@ export default class Api extends BaseCommand {
109
109
  path: args.path,
110
110
  ...options,
111
111
  // A generated key is minted inside the client at send time, so
112
- // printing a concrete UUID here would name one that never ships.
112
+ // printing a concrete UUID here would name one that never ships. The real
113
+ // one is shown by --verbose and carried by a TIMEOUT error.
113
114
  ...(method === 'POST' && options.idempotencyKey === undefined
114
115
  ? { idempotencyKey: '<generated at send time>' }
115
116
  : {}),
@@ -11,6 +11,7 @@ import { BaseCommand } from '../base.js';
11
11
  export default class Login extends BaseCommand {
12
12
  static description: string;
13
13
  static examples: string[];
14
+ protected readonly createsProfile = true;
14
15
  static flags: {
15
16
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
17
  quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
@@ -20,6 +20,8 @@ export default class Login extends BaseCommand {
20
20
  "<%= config.bin %> login --oidc --api-url https://agledger.internal --oidc-token-cmd 'gcloud auth print-identity-token --audiences=agledger'",
21
21
  '<%= config.bin %> login --oidc --api-url https://agledger.internal --oidc-token-file /var/run/secrets/tokens/agledger',
22
22
  ];
23
+ // --profile names the profile this login writes, so it need not exist yet.
24
+ createsProfile = true;
23
25
  static flags = {
24
26
  ...BaseCommand.baseFlags,
25
27
  profile: Flags.string({ description: 'Profile name', default: 'default' }),
@@ -36,7 +38,10 @@ export default class Login extends BaseCommand {
36
38
  env: OIDC_ENV.TOKEN_FILE,
37
39
  }),
38
40
  'oidc-agent-id': Flags.string({
39
- description: 'With --oidc: the agent the cert binds to, when the token does not map to one itself.',
41
+ description: 'With --oidc: an optional assertion of the agent id the token binds to. The token decides the agent, never this ' +
42
+ 'value: when it names a different agent, or the token binds none, the exchange fails 403 ' +
43
+ 'CERT_AGENT_BINDING_MISMATCH instead of issuing a cert. To bind an agent, an administrator sets oidcIss/oidcSub ' +
44
+ 'on it (PATCH /v1/agents/{id}) or maps an agent_id claim on the trusted issuer (claimMapping.agent_id).',
40
45
  env: OIDC_ENV.AGENT_ID,
41
46
  }),
42
47
  };
@@ -76,6 +81,7 @@ export default class Login extends BaseCommand {
76
81
  if (!apiUrl) {
77
82
  this.failWith(ErrorCode.CONFIG_ERROR, 'No API URL configured. AGLedger is self-hosted, so there is no default server to call.', ExitCode.USAGE_ERROR, 'Pass --api-url <url> or set AGLEDGER_API_URL.');
78
83
  }
84
+ this.requireUsableApiUrl(apiUrl, argvHasFlag('--api-url') ? '--api-url' : 'AGLEDGER_API_URL');
79
85
  // The command outranks the file, as it does at call time.
80
86
  const source = command
81
87
  ? { kind: 'command', command, origin: argvHasFlag('--oidc-token-cmd') ? '--oidc-token-cmd' : OIDC_ENV.TOKEN_CMD }
@@ -1,13 +1,14 @@
1
1
  import { BaseCommand } from '../base.js';
2
2
  export default class Logout extends BaseCommand {
3
3
  static description: string;
4
+ static examples: string[];
4
5
  static flags: {
5
6
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
7
  quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
8
  'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
9
  'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
- profile: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  all: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
13
  };
13
14
  run(): Promise<void>;
@@ -1,11 +1,16 @@
1
1
  import { Flags } from '@oclif/core';
2
- import { BaseCommand } from '../base.js';
2
+ import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
3
3
  import { readConfig, writeConfig } from '../util/config.js';
4
4
  export default class Logout extends BaseCommand {
5
- static description = 'Remove a stored profile from ~/.agledger/config.json';
5
+ static description = 'Remove a stored profile from ~/.agledger/config.json: the active profile, the one named by --profile, or every profile with --all. Exits 2 when there is no such profile to remove. Removing the active profile leaves none active: pick another with `config use`.';
6
+ static examples = [
7
+ '<%= config.bin %> logout',
8
+ '<%= config.bin %> logout --profile prod',
9
+ '<%= config.bin %> logout --all',
10
+ ];
6
11
  static flags = {
7
12
  ...BaseCommand.baseFlags,
8
- profile: Flags.string({ description: 'Profile name to remove', default: 'default' }),
13
+ profile: Flags.string({ description: 'Profile name to remove (default: the active profile)' }),
9
14
  all: Flags.boolean({ description: 'Remove all profiles', default: false }),
10
15
  };
11
16
  async run() {
@@ -13,20 +18,39 @@ export default class Logout extends BaseCommand {
13
18
  const config = readConfig();
14
19
  if (flags.all) {
15
20
  const removed = Object.keys(config.profiles);
21
+ if (removed.length === 0) {
22
+ this.failWith(ErrorCode.MISSING_INPUT, 'No profiles are stored, so nothing was removed.', ExitCode.USAGE_ERROR, 'Run `agledger login` to store one.');
23
+ }
16
24
  writeConfig({ profiles: {} });
17
25
  this.output({ loggedOut: true, removedProfiles: removed });
18
26
  return;
19
27
  }
20
- if (!config.profiles[flags.profile]) {
21
- this.output({ loggedOut: false, message: `No profile '${flags.profile}' found.` });
22
- return;
28
+ // The profile a plain command authenticates with is the active one, so
29
+ // that is the one a plain logout removes. Removing nothing is an error,
30
+ // not a quiet success: the caller would otherwise stay logged in.
31
+ const name = flags.profile ?? config.activeProfile;
32
+ if (!name) {
33
+ this.failWith(ErrorCode.MISSING_INPUT, 'No active profile, so there is nothing to log out of.', ExitCode.USAGE_ERROR, 'Run `agledger config list` to see profiles, then `agledger logout --profile <name>`.');
23
34
  }
24
- delete config.profiles[flags.profile];
25
- if (config.activeProfile === flags.profile) {
26
- const remaining = Object.keys(config.profiles);
27
- config.activeProfile = remaining[0];
35
+ if (!config.profiles[name]) {
36
+ this.failWith(ErrorCode.MISSING_INPUT, `Profile '${name}' not found, so nothing was removed.`, ExitCode.USAGE_ERROR, 'Run `agledger config list` to see profiles.');
28
37
  }
38
+ delete config.profiles[name];
39
+ // Logging out the active profile leaves none active. Promoting whichever
40
+ // profile came first would quietly switch the next call to a different
41
+ // identity (an admin key, say), so the caller picks one with `config use`.
42
+ const wasActive = config.activeProfile === name;
43
+ if (wasActive)
44
+ delete config.activeProfile;
29
45
  writeConfig(config);
30
- this.output({ loggedOut: true, profile: flags.profile, activeProfile: config.activeProfile });
46
+ const remaining = Object.keys(config.profiles);
47
+ this.output({
48
+ loggedOut: true,
49
+ profile: name,
50
+ activeProfile: config.activeProfile ?? null,
51
+ ...(wasActive && remaining.length > 0
52
+ ? { note: `No profile is active now. Run \`agledger config use <name>\` to choose one of: ${remaining.join(', ')}.` }
53
+ : {}),
54
+ });
31
55
  }
32
56
  }
@@ -1,4 +1,13 @@
1
+ import { type VerifyExportResult } from '@agledger/verify-core';
1
2
  import { BaseCommand } from '../base.js';
3
+ /** One prose string from a result, its option names given as this command's flags. */
4
+ export declare function flagWording(text: string): string;
5
+ /**
6
+ * A result with its prose worded by {@link flagWording}: `brokenAt.detail`,
7
+ * each entry's detail, and the key-trust detail and each finding, note and
8
+ * accounted-for detail. Ids, digests and instants are data and pass through.
9
+ */
10
+ export declare function resultWithFlags(result: VerifyExportResult): VerifyExportResult;
2
11
  /**
3
12
  * Offline verification of a record audit export (format 2.0, COSE_Sign1).
4
13
  * Runs entirely offline: no network calls, no API key required. The
@@ -9,16 +18,23 @@ import { BaseCommand } from '../base.js';
9
18
  export default class Verify extends BaseCommand {
10
19
  static description: string;
11
20
  static examples: string[];
21
+ static usage: string;
12
22
  static args: {
13
- file: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
23
+ file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
14
24
  };
15
25
  static flags: {
16
26
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
27
  quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
28
  keys: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
29
+ 'trust-anchor': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
30
+ 'distrusted-key': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
31
  'agent-keys': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
32
+ 'federation-key': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
33
+ 'federation-key-history': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
34
  'require-key-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
35
+ 'distrusted-keys': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
36
  'require-out-of-band-keys': import("@oclif/core/interfaces").BooleanFlag<boolean>;
37
+ 'require-supplied-keys': import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
38
  };
23
39
  run(): Promise<void>;
24
40
  /**
@@ -35,6 +51,40 @@ export default class Verify extends BaseCommand {
35
51
  * entry that wraps its key as `{ publicKeyJwk: {...} }` (how an agent records
36
52
  * the key it sent at cert exchange) is unwrapped. verify-core validates each.
37
53
  */
54
+ /**
55
+ * `--federation-key` values into the `[{ hubId, publicKey }]` list
56
+ * verify-core takes, each checked here so a bad key is a usage error, not a
57
+ * verdict. A hub named twice pins two keys.
58
+ */
59
+ private parseFederationKeys;
60
+ /**
61
+ * Each `--federation-key-history` file attached to the `--federation-key`
62
+ * entry for the hub it names, or undefined when neither flag was given. A
63
+ * history needs a key for its hub: alone it is the peer's word.
64
+ */
65
+ private attachFederationKeyHistories;
38
66
  private unwrapAgentKeys;
39
67
  private renderHuman;
40
68
  }
69
+ /**
70
+ * The human line on the evidence bodies an `?evidence=true` export inlines,
71
+ * or null when it carries none. Each is hashed against the evidenceHash or
72
+ * payloadHash its entry signs; an encrypted-mode completion cannot be.
73
+ */
74
+ export declare function evidenceBodiesLine(counts: {
75
+ present: number;
76
+ verified: number;
77
+ clientHashed: number;
78
+ failed: number;
79
+ }): string | null;
80
+ /**
81
+ * The human line on the sealed federation messages, or null when the chain
82
+ * carries none. `failed` messages failed a check and are reported as
83
+ * failures; the rest of the unverified ones came from a hub with no key.
84
+ */
85
+ export declare function peerMessagesLine(wire: {
86
+ present: number;
87
+ verified: number;
88
+ failed: number;
89
+ afterRetirement: number;
90
+ }, federationKeysGiven: boolean): string | null;