@tinycloud/operations 0.4.0-beta.11 → 0.4.0-beta.12
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/artifacts.d.cts +1 -1
- package/dist/artifacts.d.ts +1 -1
- package/dist/cli-runtime.cjs +110 -19
- package/dist/cli-runtime.cjs.map +1 -1
- package/dist/cli-runtime.d.cts +1 -1
- package/dist/cli-runtime.d.ts +1 -1
- package/dist/cli-runtime.js +110 -18
- package/dist/cli-runtime.js.map +1 -1
- package/dist/{contract-eWtDSMeI.d.cts → contract-BRwWJpPs.d.cts} +23 -1
- package/dist/{contract-eWtDSMeI.d.ts → contract-BRwWJpPs.d.ts} +23 -1
- package/dist/delegation-binding.cjs +60 -12
- package/dist/delegation-binding.cjs.map +1 -1
- package/dist/delegation-binding.d.cts +43 -13
- package/dist/delegation-binding.d.ts +43 -13
- package/dist/delegation-binding.js +59 -12
- package/dist/delegation-binding.js.map +1 -1
- package/dist/index.cjs +108 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +108 -19
- package/dist/index.js.map +1 -1
- package/dist/profile.d.cts +1 -1
- package/dist/profile.d.ts +1 -1
- package/generated/operations.json +2628 -4
- package/package.json +3 -3
|
@@ -25,6 +25,24 @@ interface OperationContextSummary {
|
|
|
25
25
|
readonly ownerDid?: string;
|
|
26
26
|
readonly space?: string;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Why a stored grant was not used. A fixed vocabulary: diagnostics never
|
|
30
|
+
* carry exception text, node responses, URLs or other stored transport data.
|
|
31
|
+
* `unbound`: the record has no valid request binding where one is required;
|
|
32
|
+
* `outside_request`: its signed authority exceeds its binding.
|
|
33
|
+
*/
|
|
34
|
+
declare const STORED_GRANT_SKIP_REASONS: readonly ["malformed", "unbound", "outside_request", "host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected", "invalid"];
|
|
35
|
+
type StoredGrantSkipReason = typeof STORED_GRANT_SKIP_REASONS[number];
|
|
36
|
+
/**
|
|
37
|
+
* A non-fatal diagnostic attached to a result. `STORED_GRANT_SKIPPED`: a
|
|
38
|
+
* stored grant failed validation and gave no authority; `grantCid` is present
|
|
39
|
+
* only when the stored CID is the CID of the stored authorization bytes.
|
|
40
|
+
*/
|
|
41
|
+
interface OperationWarning {
|
|
42
|
+
readonly code: "STORED_GRANT_SKIPPED";
|
|
43
|
+
readonly reason: StoredGrantSkipReason;
|
|
44
|
+
readonly grantCid?: string;
|
|
45
|
+
}
|
|
28
46
|
/**
|
|
29
47
|
* Capability details are finalized by the authority/artifacts increment. The
|
|
30
48
|
* kernel intentionally preserves them as canonical operation-owned data.
|
|
@@ -58,6 +76,7 @@ interface OperationOkResult<O> {
|
|
|
58
76
|
readonly operation: OperationRef;
|
|
59
77
|
readonly context: OperationContextSummary;
|
|
60
78
|
readonly output: O;
|
|
79
|
+
readonly warnings?: readonly OperationWarning[];
|
|
61
80
|
}
|
|
62
81
|
interface OperationAuthorityRequiredResult {
|
|
63
82
|
readonly status: "authority_required";
|
|
@@ -67,6 +86,7 @@ interface OperationAuthorityRequiredResult {
|
|
|
67
86
|
readonly request: PermissionRequestArtifact;
|
|
68
87
|
readonly approval: ApprovalAction;
|
|
69
88
|
readonly retry: RetryDescriptor;
|
|
89
|
+
readonly warnings?: readonly OperationWarning[];
|
|
70
90
|
}
|
|
71
91
|
interface OperationSetupRequiredResult {
|
|
72
92
|
readonly status: "setup_required";
|
|
@@ -74,12 +94,14 @@ interface OperationSetupRequiredResult {
|
|
|
74
94
|
readonly context: OperationContextSummary;
|
|
75
95
|
readonly setup: SetupAction;
|
|
76
96
|
readonly retry: RetryDescriptor;
|
|
97
|
+
readonly warnings?: readonly OperationWarning[];
|
|
77
98
|
}
|
|
78
99
|
interface OperationErrorResult {
|
|
79
100
|
readonly status: "error";
|
|
80
101
|
readonly operation: OperationRef;
|
|
81
102
|
readonly context: OperationContextSummary;
|
|
82
103
|
readonly error: OperationError;
|
|
104
|
+
readonly warnings?: readonly OperationWarning[];
|
|
83
105
|
}
|
|
84
106
|
type OperationResult<O> = OperationOkResult<O> | OperationAuthorityRequiredResult | OperationSetupRequiredResult | OperationErrorResult;
|
|
85
107
|
/**
|
|
@@ -100,4 +122,4 @@ interface InvocationTarget {
|
|
|
100
122
|
readonly privateKey?: string;
|
|
101
123
|
}
|
|
102
124
|
|
|
103
|
-
export type { InvocationTarget as I, OperationOperatorType as O, TinyCloudPosture as T, OperationResult as a, OperationContextSummary as b };
|
|
125
|
+
export type { InvocationTarget as I, OperationOperatorType as O, StoredGrantSkipReason as S, TinyCloudPosture as T, OperationResult as a, OperationContextSummary as b };
|
|
@@ -25,6 +25,24 @@ interface OperationContextSummary {
|
|
|
25
25
|
readonly ownerDid?: string;
|
|
26
26
|
readonly space?: string;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Why a stored grant was not used. A fixed vocabulary: diagnostics never
|
|
30
|
+
* carry exception text, node responses, URLs or other stored transport data.
|
|
31
|
+
* `unbound`: the record has no valid request binding where one is required;
|
|
32
|
+
* `outside_request`: its signed authority exceeds its binding.
|
|
33
|
+
*/
|
|
34
|
+
declare const STORED_GRANT_SKIP_REASONS: readonly ["malformed", "unbound", "outside_request", "host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected", "invalid"];
|
|
35
|
+
type StoredGrantSkipReason = typeof STORED_GRANT_SKIP_REASONS[number];
|
|
36
|
+
/**
|
|
37
|
+
* A non-fatal diagnostic attached to a result. `STORED_GRANT_SKIPPED`: a
|
|
38
|
+
* stored grant failed validation and gave no authority; `grantCid` is present
|
|
39
|
+
* only when the stored CID is the CID of the stored authorization bytes.
|
|
40
|
+
*/
|
|
41
|
+
interface OperationWarning {
|
|
42
|
+
readonly code: "STORED_GRANT_SKIPPED";
|
|
43
|
+
readonly reason: StoredGrantSkipReason;
|
|
44
|
+
readonly grantCid?: string;
|
|
45
|
+
}
|
|
28
46
|
/**
|
|
29
47
|
* Capability details are finalized by the authority/artifacts increment. The
|
|
30
48
|
* kernel intentionally preserves them as canonical operation-owned data.
|
|
@@ -58,6 +76,7 @@ interface OperationOkResult<O> {
|
|
|
58
76
|
readonly operation: OperationRef;
|
|
59
77
|
readonly context: OperationContextSummary;
|
|
60
78
|
readonly output: O;
|
|
79
|
+
readonly warnings?: readonly OperationWarning[];
|
|
61
80
|
}
|
|
62
81
|
interface OperationAuthorityRequiredResult {
|
|
63
82
|
readonly status: "authority_required";
|
|
@@ -67,6 +86,7 @@ interface OperationAuthorityRequiredResult {
|
|
|
67
86
|
readonly request: PermissionRequestArtifact;
|
|
68
87
|
readonly approval: ApprovalAction;
|
|
69
88
|
readonly retry: RetryDescriptor;
|
|
89
|
+
readonly warnings?: readonly OperationWarning[];
|
|
70
90
|
}
|
|
71
91
|
interface OperationSetupRequiredResult {
|
|
72
92
|
readonly status: "setup_required";
|
|
@@ -74,12 +94,14 @@ interface OperationSetupRequiredResult {
|
|
|
74
94
|
readonly context: OperationContextSummary;
|
|
75
95
|
readonly setup: SetupAction;
|
|
76
96
|
readonly retry: RetryDescriptor;
|
|
97
|
+
readonly warnings?: readonly OperationWarning[];
|
|
77
98
|
}
|
|
78
99
|
interface OperationErrorResult {
|
|
79
100
|
readonly status: "error";
|
|
80
101
|
readonly operation: OperationRef;
|
|
81
102
|
readonly context: OperationContextSummary;
|
|
82
103
|
readonly error: OperationError;
|
|
104
|
+
readonly warnings?: readonly OperationWarning[];
|
|
83
105
|
}
|
|
84
106
|
type OperationResult<O> = OperationOkResult<O> | OperationAuthorityRequiredResult | OperationSetupRequiredResult | OperationErrorResult;
|
|
85
107
|
/**
|
|
@@ -100,4 +122,4 @@ interface InvocationTarget {
|
|
|
100
122
|
readonly privateKey?: string;
|
|
101
123
|
}
|
|
102
124
|
|
|
103
|
-
export type { InvocationTarget as I, OperationOperatorType as O, TinyCloudPosture as T, OperationResult as a, OperationContextSummary as b };
|
|
125
|
+
export type { InvocationTarget as I, OperationOperatorType as O, StoredGrantSkipReason as S, TinyCloudPosture as T, OperationResult as a, OperationContextSummary as b };
|
|
@@ -152,6 +152,7 @@ var delegation_binding_exports = {};
|
|
|
152
152
|
__export(delegation_binding_exports, {
|
|
153
153
|
BINDING_NOTES: () => BINDING_NOTES,
|
|
154
154
|
activateUnboundCompactImport: () => activateUnboundCompactImport,
|
|
155
|
+
bindCliGrant: () => bindCliGrant,
|
|
155
156
|
bindingMigrationPath: () => bindingMigrationPath,
|
|
156
157
|
bindingMigrationRecorded: () => bindingMigrationRecorded,
|
|
157
158
|
mergeDelegationsWithoutRequest: () => mergeDelegationsWithoutRequest,
|
|
@@ -1144,6 +1145,25 @@ var DelegationImportArtifactSchema = import_zod.z.object({
|
|
|
1144
1145
|
}).strict();
|
|
1145
1146
|
var DelegationRequestBindingSchema = PermissionRequestArtifactSchema.pick({ requestId: true, requested: true }).strict();
|
|
1146
1147
|
|
|
1148
|
+
// src/contract.ts
|
|
1149
|
+
var STORED_GRANT_SKIP_REASONS = [
|
|
1150
|
+
"malformed",
|
|
1151
|
+
"unbound",
|
|
1152
|
+
"outside_request",
|
|
1153
|
+
"host_mismatch",
|
|
1154
|
+
"expired",
|
|
1155
|
+
"cid_mismatch",
|
|
1156
|
+
"authority_invalid",
|
|
1157
|
+
"proof_missing",
|
|
1158
|
+
"proof_invalid",
|
|
1159
|
+
"owner_mismatch",
|
|
1160
|
+
"audience_mismatch",
|
|
1161
|
+
"resources_mismatch",
|
|
1162
|
+
"unsupported",
|
|
1163
|
+
"activation_rejected",
|
|
1164
|
+
"invalid"
|
|
1165
|
+
];
|
|
1166
|
+
|
|
1147
1167
|
// src/secrets.ts
|
|
1148
1168
|
var nodeSdk = __toESM(require("@tinycloud/node-sdk"), 1);
|
|
1149
1169
|
|
|
@@ -1224,11 +1244,13 @@ function invalidSecretInput() {
|
|
|
1224
1244
|
// src/delegation-binding.ts
|
|
1225
1245
|
var REQUEST_ID_PREFIX = {
|
|
1226
1246
|
migration: "migrated",
|
|
1227
|
-
"unbound-import": "unbound-import"
|
|
1247
|
+
"unbound-import": "unbound-import",
|
|
1248
|
+
"cli-grant": "cli-grant"
|
|
1228
1249
|
};
|
|
1229
1250
|
var BINDING_NOTES = {
|
|
1230
1251
|
migration: "Stored without a request binding before bindings were required. Bound at migration to exactly its own signed capabilities, so replay refuses any delegation in this record that exceeds them.",
|
|
1231
|
-
"unbound-import": "Imported by `tc auth import` without a stored request. Bound to exactly its own signed capabilities, so replay refuses any delegation in this record that exceeds them."
|
|
1252
|
+
"unbound-import": "Imported by `tc auth import` without a stored request. Bound to exactly its own signed capabilities, so replay refuses any delegation in this record that exceeds them.",
|
|
1253
|
+
"cli-grant": "Granted to this CLI by `tc auth request --grant` or a permission escalation, and checked against the request it answered. Bound to exactly its own signed capabilities, so replay refuses any delegation in this record that exceeds them."
|
|
1232
1254
|
};
|
|
1233
1255
|
var MIGRATION_LOCK_TIMEOUT_MS = 250;
|
|
1234
1256
|
function bindingMigrationPath(profile) {
|
|
@@ -1253,19 +1275,26 @@ function replayLimit(entry, migrated) {
|
|
|
1253
1275
|
if (binding.success) return binding.data.requested;
|
|
1254
1276
|
return !migrated && kind === "compact" && !("authorityRequest" in entry) ? "signed" : void 0;
|
|
1255
1277
|
}
|
|
1256
|
-
function
|
|
1278
|
+
function bindToRequest(record, requested, source, recordedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1257
1279
|
return {
|
|
1258
1280
|
...record,
|
|
1259
1281
|
authorityRequest: DelegationRequestBindingSchema.parse({
|
|
1260
1282
|
requestId: `${REQUEST_ID_PREFIX[source]}:${record.delegation.cid}`,
|
|
1261
|
-
requested: structuredClone(
|
|
1283
|
+
requested: structuredClone(requested)
|
|
1262
1284
|
}),
|
|
1263
1285
|
authorityRequestAudit: { source, recordedAt, note: BINDING_NOTES[source] }
|
|
1264
1286
|
};
|
|
1265
1287
|
}
|
|
1288
|
+
async function bindCliGrant(node, record, host) {
|
|
1289
|
+
const signed = await signedCapabilities(node, record.delegation, host);
|
|
1290
|
+
if (signed === void 0) {
|
|
1291
|
+
throw new Error("The grant's signed authority could not be validated for this session.");
|
|
1292
|
+
}
|
|
1293
|
+
return bindToRequest(record, signed, "cli-grant");
|
|
1294
|
+
}
|
|
1266
1295
|
async function activateUnboundCompactImport(node, delegation, host) {
|
|
1267
1296
|
const activated = await nodeSdk2.activateValidatedRuntimeDelegation(node, delegation, { host });
|
|
1268
|
-
return
|
|
1297
|
+
return bindToRequest(
|
|
1269
1298
|
// The record keeps the delegation as imported; replay validates it again.
|
|
1270
1299
|
{ delegation, permissions: [...activated.effectivePermissions] },
|
|
1271
1300
|
activated.effectivePermissions,
|
|
@@ -1334,23 +1363,41 @@ async function migratedRecord(node, entry, host, recordedAt) {
|
|
|
1334
1363
|
const signed = await signedCapabilities(node, delegation, host);
|
|
1335
1364
|
if (signed === void 0) return void 0;
|
|
1336
1365
|
try {
|
|
1337
|
-
return
|
|
1366
|
+
return bindToRequest({ ...entry, delegation: { ...entry.delegation, cid: delegation.cid } }, signed, "migration", recordedAt);
|
|
1338
1367
|
} catch {
|
|
1339
1368
|
return void 0;
|
|
1340
1369
|
}
|
|
1341
1370
|
}
|
|
1371
|
+
var NOT_REPLAYED = { status: "not-replayed" };
|
|
1372
|
+
function skipped(reason) {
|
|
1373
|
+
return { status: "skipped", reason };
|
|
1374
|
+
}
|
|
1342
1375
|
async function replayStoredDelegation(node, entry, options) {
|
|
1376
|
+
const kind = storedDelegationKind(entry);
|
|
1343
1377
|
const delegation = normalizeStoredDelegation(entry);
|
|
1344
|
-
if (
|
|
1378
|
+
if (kind === "refused" || delegation === void 0) return skipped("malformed");
|
|
1379
|
+
if (delegation.expiry.getTime() <= Date.now()) return NOT_REPLAYED;
|
|
1380
|
+
if (kind === "other") return skipped("proof_missing");
|
|
1345
1381
|
const limit = replayLimit(entry, options.migrated);
|
|
1346
|
-
if (limit === void 0) return
|
|
1347
|
-
|
|
1382
|
+
if (limit === void 0) return skipped("unbound");
|
|
1383
|
+
let outsideRequest = false;
|
|
1384
|
+
const authorize = limit === "signed" ? () => true : (effective) => {
|
|
1385
|
+
outsideRequest = !delegationWithinRequest(limit, effective, options.resolveSpace);
|
|
1386
|
+
return !outsideRequest;
|
|
1387
|
+
};
|
|
1348
1388
|
try {
|
|
1349
|
-
return
|
|
1350
|
-
|
|
1351
|
-
|
|
1389
|
+
return {
|
|
1390
|
+
status: "installed",
|
|
1391
|
+
delegation: await nodeSdk2.activateValidatedRuntimeDelegation(node, delegation, { host: options.host, authorize })
|
|
1392
|
+
};
|
|
1393
|
+
} catch (error) {
|
|
1394
|
+
return skipped(outsideRequest ? "outside_request" : rejectionReason(error));
|
|
1352
1395
|
}
|
|
1353
1396
|
}
|
|
1397
|
+
function rejectionReason(error) {
|
|
1398
|
+
const reason = isRecord(error) ? error.reason : void 0;
|
|
1399
|
+
return typeof reason === "string" && STORED_GRANT_SKIP_REASONS.includes(reason) ? reason : "invalid";
|
|
1400
|
+
}
|
|
1354
1401
|
async function bindingMigrationRecorded(profile) {
|
|
1355
1402
|
try {
|
|
1356
1403
|
return await readJson(bindingMigrationPath(profile)) !== null;
|
|
@@ -1399,6 +1446,7 @@ function isRecord(value) {
|
|
|
1399
1446
|
0 && (module.exports = {
|
|
1400
1447
|
BINDING_NOTES,
|
|
1401
1448
|
activateUnboundCompactImport,
|
|
1449
|
+
bindCliGrant,
|
|
1402
1450
|
bindingMigrationPath,
|
|
1403
1451
|
bindingMigrationRecorded,
|
|
1404
1452
|
mergeDelegationsWithoutRequest,
|