@tinycloud/cli 1.5.0-beta.16 → 1.5.0-beta.18

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.
@@ -174,6 +174,35 @@ var init_storage = __esm({
174
174
  }
175
175
  });
176
176
 
177
+ // src/config/types.ts
178
+ function isCLIProfilePosture(value) {
179
+ return typeof value === "string" && CLI_PROFILE_POSTURES.includes(value);
180
+ }
181
+ function isCLIOperatorType(value) {
182
+ return typeof value === "string" && CLI_OPERATOR_TYPES.includes(value);
183
+ }
184
+ function resolveProfilePosture(profile) {
185
+ if (isCLIProfilePosture(profile.posture)) return profile.posture;
186
+ if (profile.authMethod === "local") return "local-owner-key";
187
+ return "owner-openkey";
188
+ }
189
+ function resolveProfileOperatorType(profile) {
190
+ if (isCLIOperatorType(profile.operatorType)) return profile.operatorType;
191
+ return "human";
192
+ }
193
+ var CLI_PROFILE_POSTURES, CLI_OPERATOR_TYPES;
194
+ var init_types = __esm({
195
+ "src/config/types.ts"() {
196
+ "use strict";
197
+ CLI_PROFILE_POSTURES = [
198
+ "owner-openkey",
199
+ "delegate-session",
200
+ "local-owner-key"
201
+ ];
202
+ CLI_OPERATOR_TYPES = ["human", "agent"];
203
+ }
204
+ });
205
+
177
206
  // src/lib/replication-registry.ts
178
207
  function stopForSignal(signal) {
179
208
  void closeReplication().finally(() => {
@@ -903,35 +932,6 @@ var init_errors = __esm({
903
932
  }
904
933
  });
905
934
 
906
- // src/config/types.ts
907
- function isCLIProfilePosture(value) {
908
- return typeof value === "string" && CLI_PROFILE_POSTURES.includes(value);
909
- }
910
- function isCLIOperatorType(value) {
911
- return typeof value === "string" && CLI_OPERATOR_TYPES.includes(value);
912
- }
913
- function resolveProfilePosture(profile) {
914
- if (isCLIProfilePosture(profile.posture)) return profile.posture;
915
- if (profile.authMethod === "local") return "local-owner-key";
916
- return "owner-openkey";
917
- }
918
- function resolveProfileOperatorType(profile) {
919
- if (isCLIOperatorType(profile.operatorType)) return profile.operatorType;
920
- return "human";
921
- }
922
- var CLI_PROFILE_POSTURES, CLI_OPERATOR_TYPES;
923
- var init_types = __esm({
924
- "src/config/types.ts"() {
925
- "use strict";
926
- CLI_PROFILE_POSTURES = [
927
- "owner-openkey",
928
- "delegate-session",
929
- "local-owner-key"
930
- ];
931
- CLI_OPERATOR_TYPES = ["human", "agent"];
932
- }
933
- });
934
-
935
935
  // src/lib/space.ts
936
936
  import { CLI_NAME as CLI_NAME3 } from "@tinycloud/operations/cli-name";
937
937
  function invalidSpaceError(input) {
@@ -9841,6 +9841,7 @@ var init_profiles = __esm({
9841
9841
  "use strict";
9842
9842
  init_constants();
9843
9843
  init_storage();
9844
+ init_types();
9844
9845
  init_errors();
9845
9846
  ProfileManager = class _ProfileManager {
9846
9847
  // ── Initialization ──────────────────────────────────────────────────
@@ -10122,6 +10123,7 @@ var init_profiles = __esm({
10122
10123
  quiet: options.quiet ?? false,
10123
10124
  replication,
10124
10125
  replicationDebug: options.replicationDebug === true || process.env.TC_REPLICATION_DEBUG === "1",
10126
+ ...profileConfig === void 0 ? {} : { posture: resolveProfilePosture(profileConfig) },
10125
10127
  ...localDiscovery === void 0 ? {} : { localDiscovery }
10126
10128
  };
10127
10129
  }
@@ -36336,6 +36338,52 @@ function listedDelegation(d) {
36336
36338
  resources
36337
36339
  };
36338
36340
  }
36341
+ var ISSUED_ORDER_NOTE = "Sorted by delegation ID, not by date.";
36342
+ function issuedFailure(error, host) {
36343
+ if (error.code === "UNSUPPORTED_OPERATION") {
36344
+ return new CLIError(
36345
+ "ISSUED_DELEGATIONS_UNAVAILABLE",
36346
+ `${host} can't list the delegations you issued yet.`,
36347
+ ExitCode.NODE_ERROR
36348
+ );
36349
+ }
36350
+ if (error.code === "CHAIN_TOO_DEEP") {
36351
+ return new CLIError(
36352
+ "CHAIN_TOO_DEEP",
36353
+ "The node can't check this delegation chain right now because it's too long. Try again later.",
36354
+ ExitCode.NODE_ERROR,
36355
+ { status: 503 }
36356
+ );
36357
+ }
36358
+ if (error.code === "INVALID_CURSOR") {
36359
+ return new CLIError(
36360
+ "INVALID_CURSOR",
36361
+ "The node couldn't continue the list. Run the command again.",
36362
+ ExitCode.NODE_ERROR,
36363
+ { status: 400 }
36364
+ );
36365
+ }
36366
+ return cliErrorFromService(error);
36367
+ }
36368
+ async function revokeIssuedDelegation(node, ctx, cid) {
36369
+ const result = await node.delegationManager.revokeIssued(cid);
36370
+ if (result.ok) return { cid: result.data.cid, revoked: true };
36371
+ if (result.error.code === "PERMISSION_DENIED") {
36372
+ throw new CLIError(
36373
+ "REVOKE_UNAUTHORIZED",
36374
+ `The node refused this revocation: ${result.error.message}.`,
36375
+ ExitCode.PERMISSION_DENIED,
36376
+ {
36377
+ status: result.error.meta?.status,
36378
+ hint: `A profile can revoke only the delegations its own key issued. See them with \`${CLI_NAME21} --profile ${ctx.profile} delegation list --granted\`.`
36379
+ }
36380
+ );
36381
+ }
36382
+ if (result.error.code === "NOT_FOUND") {
36383
+ throw new CLIError("TARGET_NOT_FOUND", `The node has no delegation "${cid}".`, ExitCode.NOT_FOUND);
36384
+ }
36385
+ throw issuedFailure(result.error, ctx.host);
36386
+ }
36339
36387
  async function confirmCurrentSessionRevoke(yes) {
36340
36388
  if (yes) return;
36341
36389
  const warning = "This is your current sign-in session; revoking it signs you out";
@@ -36424,6 +36472,16 @@ function registerDelegationCommand(program, configuration = {}) {
36424
36472
  if (options.granted && options.received) {
36425
36473
  throw new CLIError("USAGE_ERROR", "Use only one of --granted or --received.", ExitCode.USAGE_ERROR);
36426
36474
  }
36475
+ if (options.granted && ctx.posture === "delegate-session" && node.address === void 0) {
36476
+ const issued = await node.delegationManager.queryAllIssued({ space: options.space });
36477
+ if (!issued.ok) throw issuedFailure(issued.error, ctx.host);
36478
+ outputJson({
36479
+ delegations: issued.data.map(listedDelegation),
36480
+ count: issued.data.length,
36481
+ note: ISSUED_ORDER_NOTE
36482
+ });
36483
+ return;
36484
+ }
36427
36485
  const delegations = await queryDelegations(node, {
36428
36486
  direction: options.granted ? "granted" : options.received ? "received" : "all",
36429
36487
  space: options.space
@@ -36454,11 +36512,16 @@ function registerDelegationCommand(program, configuration = {}) {
36454
36512
  try {
36455
36513
  const globalOpts = cmd.optsWithGlobals();
36456
36514
  const ctx = await ProfileManager.resolveContext(globalOpts);
36515
+ const delegateCandidate = ctx.posture === "delegate-session" ? await ensureAuthenticated(ctx) : void 0;
36516
+ if (delegateCandidate !== void 0 && delegateCandidate.address === void 0) {
36517
+ outputJson(await revokeIssuedDelegation(delegateCandidate, ctx, cid));
36518
+ return;
36519
+ }
36457
36520
  const session = await ProfileManager.getSession(ctx.profile);
36458
36521
  const currentSession = session && "delegationCid" in session && session.delegationCid === cid;
36459
36522
  if (currentSession) await confirmCurrentSessionRevoke(options.yes === true);
36460
36523
  const prepared = currentSession ? await prepareProfileRemoteLogout(ctx, cid) : void 0;
36461
- const node = prepared?.node ?? await ensureAuthenticated(ctx);
36524
+ const node = prepared?.node ?? delegateCandidate ?? await ensureAuthenticated(ctx);
36462
36525
  const profile = prepared?.profile ?? await ProfileManager.getProfile(ctx.profile);
36463
36526
  const revoked = await revokeDelegationOnNode({
36464
36527
  ctx,