@tinycloud/cli 0.7.7-beta.2 → 0.7.7-beta.4
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/dist/index.js +65 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43176,7 +43176,6 @@ async function parseCapSpec(spec, profile) {
|
|
|
43176
43176
|
const actionsCsv = spec.slice(lastColon + 1);
|
|
43177
43177
|
const spaceAndPath = spec.slice(firstColon + 1, lastColon);
|
|
43178
43178
|
const { space, path } = splitSpaceAndPath(spaceAndPath);
|
|
43179
|
-
const resolvedSpace = await resolveSpaceUri(space, profile) ?? space;
|
|
43180
43179
|
const actions = expandActionShortNames(
|
|
43181
43180
|
service,
|
|
43182
43181
|
actionsCsv.split(",").map((action) => action.trim()).filter(Boolean)
|
|
@@ -43184,7 +43183,9 @@ async function parseCapSpec(spec, profile) {
|
|
|
43184
43183
|
if (actions.length === 0) {
|
|
43185
43184
|
throw new CLIError("INVALID_CAP", `Capability "${spec}" has no actions.`, ExitCode.USAGE_ERROR);
|
|
43186
43185
|
}
|
|
43187
|
-
return
|
|
43186
|
+
return (await resolvePermissionSpaces([
|
|
43187
|
+
{ service, space, path, actions }
|
|
43188
|
+
], profile))[0];
|
|
43188
43189
|
}
|
|
43189
43190
|
async function loadPermissionRequest(source, profile) {
|
|
43190
43191
|
const raw = JSON.parse(await readFile2(source, "utf8"));
|
|
@@ -43292,13 +43293,24 @@ function compactPermission(permission) {
|
|
|
43292
43293
|
return `${service}:${space}:${permission.path}:${actions}`;
|
|
43293
43294
|
}
|
|
43294
43295
|
async function resolvePermissionSpaces(entries, profile) {
|
|
43296
|
+
const profileConfig = await ProfileManager.getProfile(profile);
|
|
43297
|
+
const allowLogicalSpaces = resolveProfilePosture(profileConfig) === "delegate-session";
|
|
43295
43298
|
const resolved = [];
|
|
43296
43299
|
for (const entry of entries) {
|
|
43297
43300
|
const service = normalizeService(entry.service);
|
|
43301
|
+
let space;
|
|
43302
|
+
try {
|
|
43303
|
+
space = await resolveSpaceUri(entry.space, profile) ?? entry.space;
|
|
43304
|
+
} catch (error) {
|
|
43305
|
+
if (!allowLogicalSpaces || entry.space.startsWith("tinycloud:") || !(error instanceof CLIError) || error.code !== "ADDRESS_UNKNOWN") {
|
|
43306
|
+
throw error;
|
|
43307
|
+
}
|
|
43308
|
+
space = entry.space;
|
|
43309
|
+
}
|
|
43298
43310
|
resolved.push({
|
|
43299
43311
|
...entry,
|
|
43300
43312
|
service,
|
|
43301
|
-
space
|
|
43313
|
+
space,
|
|
43302
43314
|
actions: expandActionShortNames(service, entry.actions)
|
|
43303
43315
|
});
|
|
43304
43316
|
}
|
|
@@ -43446,6 +43458,43 @@ async function createSDKInstance(ctx, options) {
|
|
|
43446
43458
|
await replayAdditionalDelegations(node, ctx.profile);
|
|
43447
43459
|
return node;
|
|
43448
43460
|
}
|
|
43461
|
+
async function bootstrapDelegatedSession(ctx, delegation) {
|
|
43462
|
+
const profile = await ProfileManager.getProfile(ctx.profile);
|
|
43463
|
+
if (resolveProfilePosture(profile) !== "delegate-session") {
|
|
43464
|
+
throw new CLIError(
|
|
43465
|
+
"AUTH_REQUIRED",
|
|
43466
|
+
`Profile "${ctx.profile}" is not a delegate-session profile.`,
|
|
43467
|
+
ExitCode.AUTH_REQUIRED
|
|
43468
|
+
);
|
|
43469
|
+
}
|
|
43470
|
+
const sessionDid = profile.sessionDid ?? profile.did;
|
|
43471
|
+
if (delegation.delegateDID.split("#", 1)[0] !== sessionDid.split("#", 1)[0]) {
|
|
43472
|
+
throw new CLIError(
|
|
43473
|
+
"DELEGATION_AUDIENCE_MISMATCH",
|
|
43474
|
+
`Delegation targets ${delegation.delegateDID}, but profile "${ctx.profile}" uses ${sessionDid}.`,
|
|
43475
|
+
ExitCode.PERMISSION_DENIED
|
|
43476
|
+
);
|
|
43477
|
+
}
|
|
43478
|
+
const key2 = await ProfileManager.getKey(ctx.profile);
|
|
43479
|
+
const jwk = signerJwkForProfile(ctx.profile, void 0, key2);
|
|
43480
|
+
await ProfileManager.setSession(ctx.profile, {
|
|
43481
|
+
delegationHeader: delegation.delegationHeader,
|
|
43482
|
+
delegationCid: delegation.cid,
|
|
43483
|
+
spaceId: delegation.spaceId,
|
|
43484
|
+
jwk,
|
|
43485
|
+
verificationMethod: sessionDid,
|
|
43486
|
+
address: delegation.ownerAddress,
|
|
43487
|
+
chainId: delegation.chainId,
|
|
43488
|
+
siwe: "",
|
|
43489
|
+
signature: ""
|
|
43490
|
+
});
|
|
43491
|
+
await ProfileManager.setProfile(ctx.profile, {
|
|
43492
|
+
...profile,
|
|
43493
|
+
sessionDid,
|
|
43494
|
+
spaceId: delegation.spaceId
|
|
43495
|
+
});
|
|
43496
|
+
return createSDKInstance(ctx);
|
|
43497
|
+
}
|
|
43449
43498
|
async function ensureAuthenticated(ctx, options) {
|
|
43450
43499
|
if (options?.privateKey) {
|
|
43451
43500
|
return createSDKInstance(ctx, options);
|
|
@@ -43745,7 +43794,15 @@ function registerAuthCommand(program2) {
|
|
|
43745
43794
|
return;
|
|
43746
43795
|
}
|
|
43747
43796
|
const imported = normalizeDelegationImport(parsed);
|
|
43748
|
-
|
|
43797
|
+
let node;
|
|
43798
|
+
try {
|
|
43799
|
+
node = await ensureAuthenticated(ctx);
|
|
43800
|
+
} catch (error) {
|
|
43801
|
+
const profile = await ProfileManager.getProfile(ctx.profile);
|
|
43802
|
+
const session = await ProfileManager.getSession(ctx.profile);
|
|
43803
|
+
if (session || resolveProfilePosture(profile) !== "delegate-session") throw error;
|
|
43804
|
+
node = await bootstrapDelegatedSession(ctx, imported.delegation);
|
|
43805
|
+
}
|
|
43749
43806
|
await appendAdditionalDelegation(ctx.profile, storedAdditionalDelegation(
|
|
43750
43807
|
imported.delegation,
|
|
43751
43808
|
imported.permissions
|
|
@@ -43791,17 +43848,19 @@ function registerAuthCommand(program2) {
|
|
|
43791
43848
|
ExitCode.USAGE_ERROR
|
|
43792
43849
|
);
|
|
43793
43850
|
}
|
|
43851
|
+
const requested = await resolvePermissionSpaces(parsed.requested, ctx.profile);
|
|
43852
|
+
const resolvedRequest = { ...parsed, requested };
|
|
43794
43853
|
const node = await ensureAuthenticated(ctx);
|
|
43795
43854
|
await ensureDelegationAuthority({
|
|
43796
43855
|
ctx,
|
|
43797
43856
|
profile,
|
|
43798
43857
|
node,
|
|
43799
|
-
requested
|
|
43858
|
+
requested,
|
|
43800
43859
|
expiryOption: parsed.requestedExpiry,
|
|
43801
43860
|
reason: "Grant permissions requested by a TinyCloud auth request artifact.",
|
|
43802
43861
|
yes: options.yes === true
|
|
43803
43862
|
});
|
|
43804
|
-
const grant = await grantAuthRequest(node,
|
|
43863
|
+
const grant = await grantAuthRequest(node, resolvedRequest);
|
|
43805
43864
|
outputJson(grant);
|
|
43806
43865
|
} catch (error) {
|
|
43807
43866
|
handleError(error);
|