@tinycloud/cli 1.2.4-beta.1 → 1.2.4-beta.3

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.
@@ -36193,6 +36193,7 @@ function registerShareCommand(program) {
36193
36193
 
36194
36194
  // src/commands/space.ts
36195
36195
  init_profiles();
36196
+ init_types();
36196
36197
  init_formatter();
36197
36198
  init_errors();
36198
36199
  init_constants();
@@ -36200,6 +36201,7 @@ init_sdk();
36200
36201
  init_host();
36201
36202
  init_theme();
36202
36203
  import { CLI_NAME as CLI_NAME26 } from "@tinycloud/operations/cli-name";
36204
+ import { ACCOUNT_REGISTRY_SPACE as ACCOUNT_REGISTRY_SPACE2 } from "@tinycloud/node-sdk";
36203
36205
  import { randomBytes as randomBytes8 } from "crypto";
36204
36206
  import { mkdir as mkdir5, writeFile as writeFile4 } from "fs/promises";
36205
36207
  import { dirname as dirname6 } from "path";
@@ -36214,21 +36216,52 @@ function registerSpaceCommand(program) {
36214
36216
  const globalOpts = cmd.optsWithGlobals();
36215
36217
  const ctx = await ProfileManager.resolveContext(globalOpts);
36216
36218
  const node = await ensureAuthenticated(ctx);
36217
- const result = await node.spaces.list();
36218
- if (!result.ok) {
36219
- throw cliErrorFromService(result.error);
36219
+ const accountSpaceId = node.accountSpaceId;
36220
+ const sessionCapabilities = node.getVerifiedSessionCapabilities();
36221
+ const sessionSpaceId = node.restorableSession?.spaceId;
36222
+ const sessionSpace = sessionSpaceId?.slice(sessionSpaceId.lastIndexOf(":") + 1);
36223
+ let spaces;
36224
+ if (accountSpaceId !== void 0 && node.hasRuntimePermissions([{
36225
+ service: "tinycloud.kv",
36226
+ space: accountSpaceId,
36227
+ path: "spaces/",
36228
+ actions: ["tinycloud.kv/get", "tinycloud.kv/list"]
36229
+ }])) {
36230
+ const result = await node.account.spaces.list();
36231
+ if (!result.ok) throw cliErrorFromService(result.error);
36232
+ spaces = result.data.map((s) => ({
36233
+ id: s.spaceId,
36234
+ name: s.name,
36235
+ owner: s.ownerDid,
36236
+ type: s.type,
36237
+ permissions: s.permissions,
36238
+ status: s.status,
36239
+ registeredAt: s.registeredAt,
36240
+ updatedAt: s.updatedAt,
36241
+ expiresAt: s.expiresAt
36242
+ }));
36243
+ } else if (sessionCapabilities.length === 0 || sessionCapabilities.some((capability) => capability.service === "tinycloud.space" && capability.space === sessionSpace && capability.path === "" && capability.actions.includes("tinycloud.space/list"))) {
36244
+ const result = await node.spaces.list();
36245
+ if (!result.ok) throw cliErrorFromService(result.error);
36246
+ spaces = result.data;
36247
+ } else {
36248
+ const profile = await ProfileManager.getProfile(ctx.profile);
36249
+ const cap = "tinycloud.kv:account:spaces/:get,list";
36250
+ const hint = resolveProfilePosture(profile) === "delegate-session" ? `Ask the space owner to grant it. Create the request with: ${CLI_NAME26} --profile ${ctx.profile} auth request --cap ${cap} --emit` : `Grant it to this session with: ${CLI_NAME26} --profile ${ctx.profile} auth request --grant --cap ${cap}. The default OpenKey owner sign-in covers only the default space, so it includes neither.`;
36251
+ throw new CLIError(
36252
+ "PERMISSION_DENIED",
36253
+ `Listing spaces needs tinycloud.kv/get and tinycloud.kv/list on the account space's spaces/ registry (${accountSpaceId ?? ACCOUNT_REGISTRY_SPACE2}), or tinycloud.space/list. This session holds neither.`,
36254
+ ExitCode.PERMISSION_DENIED,
36255
+ { hint }
36256
+ );
36220
36257
  }
36221
36258
  if (shouldOutputJson()) {
36222
- outputJson({ spaces: result.data, count: result.data.length });
36259
+ outputJson({ spaces, count: spaces.length });
36223
36260
  } else {
36224
- if (result.data.length === 0) {
36261
+ if (spaces.length === 0) {
36225
36262
  process.stdout.write(theme.muted("No spaces found.") + "\n");
36226
36263
  } else {
36227
- const rows = result.data.map((s) => [
36228
- s.id || s.spaceId || "\u2014",
36229
- s.name || "\u2014",
36230
- s.owner || "\u2014"
36231
- ]);
36264
+ const rows = spaces.map((s) => [s.id, s.name || "\u2014", s.owner || "\u2014"]);
36232
36265
  process.stdout.write(formatTable(["Space ID", "Name", "Owner"], rows) + "\n");
36233
36266
  }
36234
36267
  }