@tinycloud/cli 1.2.2-beta.0 → 1.2.2-beta.1

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.
@@ -20772,6 +20772,16 @@ function sessionExpiresAt(session) {
20772
20772
  if (typeof value === "string") return new Date(value).toISOString();
20773
20773
  return null;
20774
20774
  }
20775
+ function storedSessionState(session) {
20776
+ if (session === null) return { state: "missing", expiresAt: null };
20777
+ const siweExpiry = typeof session.siwe === "string" ? session.siwe.match(/^Expiration Time:\s*(.+)$/m)?.[1] : void 0;
20778
+ const expiresAt = siweExpiry !== void 0 && Number.isFinite(Date.parse(siweExpiry)) ? new Date(siweExpiry).toISOString() : sessionExpiresAt(session);
20779
+ if (expiresAt === null) return { state: "unknown-expiry", expiresAt };
20780
+ return { state: Date.parse(expiresAt) <= Date.now() ? "expired" : "present", expiresAt };
20781
+ }
20782
+ function sessionStateIsUsable(state2) {
20783
+ return state2 === "present" || state2 === "unknown-expiry";
20784
+ }
20775
20785
  function ownerSpaceId(space, ownerDid) {
20776
20786
  return space.startsWith("tinycloud:") ? space : `tinycloud:${ownerDid.slice("did:".length)}:${space}`;
20777
20787
  }
@@ -22244,10 +22254,12 @@ function registerAuthCommand(program, options) {
22244
22254
  }
22245
22255
  const posture = profile ? resolveProfilePosture(profile) : null;
22246
22256
  const operatorType = profile ? resolveProfileOperatorType(profile) : null;
22247
- const authenticated = session !== null;
22257
+ const { state: sessionState, expiresAt } = storedSessionState(session);
22258
+ const authenticated = sessionStateIsUsable(sessionState);
22248
22259
  if (shouldOutputJson()) {
22249
22260
  outputJson({
22250
22261
  authenticated,
22262
+ session: { state: sessionState, expiresAt },
22251
22263
  did: profile?.did ?? null,
22252
22264
  sessionDid: profile?.sessionDid ?? null,
22253
22265
  ownerDid: profile?.ownerDid ?? null,
@@ -22265,6 +22277,7 @@ function registerAuthCommand(program, options) {
22265
22277
  process.stdout.write(theme.heading("Authentication Status") + "\n");
22266
22278
  process.stdout.write(formatField("Profile", ctx.profile) + "\n");
22267
22279
  process.stdout.write(formatField("Authenticated", authenticated) + "\n");
22280
+ process.stdout.write(formatField("Session", describeSession(sessionState, expiresAt)) + "\n");
22268
22281
  process.stdout.write(formatField("Auth Method", profile?.authMethod ?? null) + "\n");
22269
22282
  process.stdout.write(formatField("Posture", posture) + "\n");
22270
22283
  process.stdout.write(formatField("Operator", operatorType) + "\n");
@@ -22276,6 +22289,11 @@ function registerAuthCommand(program, options) {
22276
22289
  process.stdout.write(formatField("Address", profile?.address ?? null) + "\n");
22277
22290
  process.stdout.write(formatField("Space ID", profile?.spaceId ?? null) + "\n");
22278
22291
  process.stdout.write(formatField("Has Key", hasKey !== null) + "\n");
22292
+ if (sessionState === "expired") {
22293
+ process.stdout.write(`
22294
+ ${signInAgainHint(ctx.profile, posture ?? void 0)}
22295
+ `);
22296
+ }
22279
22297
  }
22280
22298
  } catch (error) {
22281
22299
  return handleError(error);
@@ -22723,7 +22741,8 @@ function registerAuthCommand(program, options) {
22723
22741
  const ctx = await ProfileManager.resolveContext(globalOpts, { storedSession: "unused" });
22724
22742
  const profile = await ProfileManager.getProfile(ctx.profile);
22725
22743
  const session = await ProfileManager.getSession(ctx.profile);
22726
- const authenticated = session !== null;
22744
+ const { state: sessionState, expiresAt } = storedSessionState(session);
22745
+ const authenticated = sessionStateIsUsable(sessionState);
22727
22746
  const posture = resolveProfilePosture(profile);
22728
22747
  const operatorType = resolveProfileOperatorType(profile);
22729
22748
  if (shouldOutputJson()) {
@@ -22735,6 +22754,7 @@ function registerAuthCommand(program, options) {
22735
22754
  spaceId: profile.spaceId ?? null,
22736
22755
  host: profile.host,
22737
22756
  authenticated,
22757
+ session: { state: sessionState, expiresAt },
22738
22758
  authMethod: profile.authMethod ?? null,
22739
22759
  posture,
22740
22760
  operatorType,
@@ -22753,12 +22773,25 @@ function registerAuthCommand(program, options) {
22753
22773
  process.stdout.write(formatField("Space ID", profile.spaceId ?? null) + "\n");
22754
22774
  process.stdout.write(formatField("Host", profile.host) + "\n");
22755
22775
  process.stdout.write(formatField("Authenticated", authenticated) + "\n");
22776
+ process.stdout.write(formatField("Session", describeSession(sessionState, expiresAt)) + "\n");
22756
22777
  }
22757
22778
  } catch (error) {
22758
22779
  return handleError(error);
22759
22780
  }
22760
22781
  });
22761
22782
  }
22783
+ function describeSession(state2, expiresAt) {
22784
+ switch (state2) {
22785
+ case "missing":
22786
+ return "none";
22787
+ case "expired":
22788
+ return `expired ${expiresAt}`;
22789
+ case "present":
22790
+ return `active until ${expiresAt}`;
22791
+ case "unknown-expiry":
22792
+ return "active (no recorded expiry)";
22793
+ }
22794
+ }
22762
22795
  async function emitPermissionRequestArtifact(artifact, emitOption) {
22763
22796
  if (typeof emitOption === "string" && emitOption.length > 0) {
22764
22797
  await mkdir3(dirname3(emitOption), { recursive: true });
@@ -23687,7 +23720,6 @@ function registerContextCommand(program) {
23687
23720
  const profile = await ProfileManager.getProfile(ctx.profile);
23688
23721
  const session = await ProfileManager.getSession(ctx.profile);
23689
23722
  const spaceId = await resolveSpaceUri(options.space, ctx.profile) ?? (typeof session?.spaceId === "string" ? session.spaceId : profile.spaceId ?? null);
23690
- const expiresAt = sessionExpiresAt(session);
23691
23723
  let root = cmd;
23692
23724
  while (root.parent) root = root.parent;
23693
23725
  outputJson({
@@ -23699,8 +23731,7 @@ function registerContextCommand(program) {
23699
23731
  host: ctx.host,
23700
23732
  spaceId,
23701
23733
  session: {
23702
- state: session === null ? "missing" : expiresAt === null ? "unknown-expiry" : Date.parse(expiresAt) <= Date.now() ? "expired" : "present",
23703
- expiresAt,
23734
+ ...storedSessionState(session),
23704
23735
  evidence: "local-metadata"
23705
23736
  },
23706
23737
  access: "not-tested"