@tinycloud/sdk-core 2.7.0-beta.2 → 2.7.0-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.
- package/dist/{capability-Dbx-xqUh.d.cts → capability-DpdAwc1W.d.cts} +1 -1
- package/dist/{capability-Dbx-xqUh.d.ts → capability-DpdAwc1W.d.ts} +1 -1
- package/dist/index.cjs +175 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +241 -11
- package/dist/index.d.ts +241 -11
- package/dist/index.js +175 -10
- package/dist/index.js.map +1 -1
- package/dist/policy/index.d.cts +4 -4
- package/dist/policy/index.d.ts +4 -4
- package/dist/requester/index.d.cts +1 -1
- package/dist/requester/index.d.ts +1 -1
- package/dist/{signed-object-C9Gur3ZY.d.ts → signed-object-BHkLbCXI.d.ts} +1 -1
- package/dist/{signed-object-Cy_81K45.d.cts → signed-object-CpXNKC4d.d.cts} +1 -1
- package/package.json +3 -3
|
@@ -43,4 +43,4 @@ declare function canonicalizePolicyCapability(input: unknown): PolicyCapability;
|
|
|
43
43
|
declare function policyCapabilityDigestHex(input: unknown): string;
|
|
44
44
|
declare function policyCapabilityContains(authority: unknown, request: unknown): boolean;
|
|
45
45
|
|
|
46
|
-
export { type JsonObject as J,
|
|
46
|
+
export { type JsonObject as J, type PolicyCapability as P, PolicyCapabilityError as a, type JsonValue as b, type PolicyCapabilityErrorCode as c, canonicalizePolicyCapability as d, normalizePolicyCapability as e, policyCapabilityDigestHex as f, jcsCanonicalize as j, normalizeJson as n, policyCapabilityContains as p, serialize as s };
|
|
@@ -43,4 +43,4 @@ declare function canonicalizePolicyCapability(input: unknown): PolicyCapability;
|
|
|
43
43
|
declare function policyCapabilityDigestHex(input: unknown): string;
|
|
44
44
|
declare function policyCapabilityContains(authority: unknown, request: unknown): boolean;
|
|
45
45
|
|
|
46
|
-
export { type JsonObject as J,
|
|
46
|
+
export { type JsonObject as J, type PolicyCapability as P, PolicyCapabilityError as a, type JsonValue as b, type PolicyCapabilityErrorCode as c, canonicalizePolicyCapability as d, normalizePolicyCapability as e, policyCapabilityDigestHex as f, jcsCanonicalize as j, normalizeJson as n, policyCapabilityContains as p, serialize as s };
|
package/dist/index.cjs
CHANGED
|
@@ -3731,6 +3731,43 @@ var DelegationStatusSchema = import_zod4.z.object({
|
|
|
3731
3731
|
});
|
|
3732
3732
|
}
|
|
3733
3733
|
});
|
|
3734
|
+
var DelegationRevocationReceiptSchema = import_zod4.z.object({
|
|
3735
|
+
revoked: import_zod4.z.literal(true),
|
|
3736
|
+
cid: import_zod4.z.string().min(1)
|
|
3737
|
+
}).strict();
|
|
3738
|
+
var AccountDelegationResourceSchema = import_zod4.z.object({
|
|
3739
|
+
resource: import_zod4.z.string().min(1),
|
|
3740
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
3741
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()))
|
|
3742
|
+
}).strict();
|
|
3743
|
+
var AccountDelegationDateSchema = import_zod4.z.string().datetime({ offset: true }).transform((value) => new Date(value));
|
|
3744
|
+
var AccountDelegationRecordSchema = import_zod4.z.object({
|
|
3745
|
+
cid: import_zod4.z.string().min(1),
|
|
3746
|
+
direction: import_zod4.z.enum(["granted", "received"]),
|
|
3747
|
+
delegatorDid: import_zod4.z.string().min(1),
|
|
3748
|
+
delegateDid: import_zod4.z.string().min(1),
|
|
3749
|
+
resources: import_zod4.z.array(AccountDelegationResourceSchema),
|
|
3750
|
+
parents: import_zod4.z.array(import_zod4.z.string()),
|
|
3751
|
+
issuedAt: AccountDelegationDateSchema.nullable(),
|
|
3752
|
+
notBefore: AccountDelegationDateSchema.nullable(),
|
|
3753
|
+
expiresAt: AccountDelegationDateSchema.nullable(),
|
|
3754
|
+
status: import_zod4.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]),
|
|
3755
|
+
revokedAt: AccountDelegationDateSchema.nullable().optional(),
|
|
3756
|
+
revokedBy: import_zod4.z.string().optional(),
|
|
3757
|
+
revokedAncestorCid: import_zod4.z.string().optional()
|
|
3758
|
+
}).strict();
|
|
3759
|
+
var AccountDelegationPageSchema = import_zod4.z.object({
|
|
3760
|
+
schemaVersion: import_zod4.z.literal(2),
|
|
3761
|
+
items: import_zod4.z.array(AccountDelegationRecordSchema),
|
|
3762
|
+
nextCursor: import_zod4.z.string().optional()
|
|
3763
|
+
}).strict();
|
|
3764
|
+
var AccountDelegationQueryOptionsSchema = import_zod4.z.object({
|
|
3765
|
+
direction: import_zod4.z.enum(["granted", "received", "all"]).optional(),
|
|
3766
|
+
status: import_zod4.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
|
|
3767
|
+
space: import_zod4.z.string().trim().min(1).optional(),
|
|
3768
|
+
limit: import_zod4.z.number().int().min(1).max(100).optional(),
|
|
3769
|
+
cursor: import_zod4.z.string().min(1).optional()
|
|
3770
|
+
}).strict();
|
|
3734
3771
|
var CapabilityEntrySchema = import_zod4.z.object({
|
|
3735
3772
|
/** Resource URI this capability applies to */
|
|
3736
3773
|
resource: import_zod4.z.string(),
|
|
@@ -3885,6 +3922,8 @@ var GenerateShareParamsSchema = import_zod4.z.object({
|
|
|
3885
3922
|
var DelegationManagerConfigSchema = import_zod4.z.object({
|
|
3886
3923
|
/** TinyCloud host URLs */
|
|
3887
3924
|
hosts: import_zod4.z.array(import_zod4.z.string()),
|
|
3925
|
+
/** Account space used by account-wide delegation history queries */
|
|
3926
|
+
accountSpaceId: import_zod4.z.string().min(1).optional(),
|
|
3888
3927
|
/** Active session for authentication */
|
|
3889
3928
|
session: import_zod4.z.unknown().refine(
|
|
3890
3929
|
(val) => val !== null && typeof val === "object",
|
|
@@ -6170,12 +6209,20 @@ function withCapabilitiesReadForSpaces(resources) {
|
|
|
6170
6209
|
]);
|
|
6171
6210
|
}
|
|
6172
6211
|
function accountRegistryPermissions() {
|
|
6173
|
-
return [
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6212
|
+
return [
|
|
6213
|
+
...[ACCOUNT_REGISTRY_PATH, "spaces/"].map((path) => ({
|
|
6214
|
+
service: "tinycloud.kv",
|
|
6215
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
6216
|
+
path,
|
|
6217
|
+
actions: ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/list"]
|
|
6218
|
+
})),
|
|
6219
|
+
{
|
|
6220
|
+
service: "tinycloud.delegation",
|
|
6221
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
6222
|
+
path: "",
|
|
6223
|
+
actions: ["tinycloud.delegation/list"]
|
|
6224
|
+
}
|
|
6225
|
+
];
|
|
6179
6226
|
}
|
|
6180
6227
|
function accountRegistryIndexPermission() {
|
|
6181
6228
|
return {
|
|
@@ -6442,6 +6489,18 @@ var AccountService = class {
|
|
|
6442
6489
|
}
|
|
6443
6490
|
};
|
|
6444
6491
|
this.delegations = {
|
|
6492
|
+
query: async (options = {}) => {
|
|
6493
|
+
const manager = this.config.getDelegationManager?.();
|
|
6494
|
+
if (!manager) {
|
|
6495
|
+
return (0, import_sdk_services5.err)((0, import_sdk_services5.serviceError)(
|
|
6496
|
+
"NOT_INITIALIZED",
|
|
6497
|
+
"Delegation history requires an authenticated delegation manager",
|
|
6498
|
+
SERVICE_NAME2
|
|
6499
|
+
));
|
|
6500
|
+
}
|
|
6501
|
+
const queried = await manager.query(options);
|
|
6502
|
+
return queried.ok ? (0, import_sdk_services5.ok)(queried.data) : accountErr(queried.error);
|
|
6503
|
+
},
|
|
6445
6504
|
list: async (options = {}) => {
|
|
6446
6505
|
if (options.preferIndex) {
|
|
6447
6506
|
const indexed = await this.index.delegations.list(options);
|
|
@@ -6476,10 +6535,23 @@ var AccountService = class {
|
|
|
6476
6535
|
delegations.sort((a, b) => a.spaceId.localeCompare(b.spaceId) || a.cid.localeCompare(b.cid));
|
|
6477
6536
|
return (0, import_sdk_services5.ok)(delegations);
|
|
6478
6537
|
},
|
|
6479
|
-
revoke: async (
|
|
6480
|
-
const
|
|
6538
|
+
revoke: async (input) => {
|
|
6539
|
+
const cid = typeof input === "string" ? input : input.cid;
|
|
6540
|
+
const manager = this.config.getDelegationManager?.();
|
|
6541
|
+
if (manager) {
|
|
6542
|
+
const revoked2 = await manager.revoke(cid);
|
|
6543
|
+
return revoked2.ok ? (0, import_sdk_services5.ok)(revoked2.data) : accountErr(revoked2.error);
|
|
6544
|
+
}
|
|
6545
|
+
if (typeof input === "string") {
|
|
6546
|
+
return (0, import_sdk_services5.err)((0, import_sdk_services5.serviceError)(
|
|
6547
|
+
"NOT_INITIALIZED",
|
|
6548
|
+
"CID-only revocation requires an authenticated delegation manager",
|
|
6549
|
+
SERVICE_NAME2
|
|
6550
|
+
));
|
|
6551
|
+
}
|
|
6552
|
+
const space = await this.resolveSpace(input.space);
|
|
6481
6553
|
if (!space.ok) return space;
|
|
6482
|
-
const revoked = await this.config.getSpaces().get(space.data.id).delegations.revoke(
|
|
6554
|
+
const revoked = await this.config.getSpaces().get(space.data.id).delegations.revoke(cid);
|
|
6483
6555
|
if (!revoked.ok) return accountErr(revoked.error);
|
|
6484
6556
|
return (0, import_sdk_services5.ok)(void 0);
|
|
6485
6557
|
}
|
|
@@ -7180,6 +7252,7 @@ var DelegationManager = class {
|
|
|
7180
7252
|
this.invoke = config.invoke;
|
|
7181
7253
|
this.invokeAny = config.invokeAny;
|
|
7182
7254
|
this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
7255
|
+
this.accountSpaceId = config.accountSpaceId;
|
|
7183
7256
|
}
|
|
7184
7257
|
/**
|
|
7185
7258
|
* Updates the session (e.g., after re-authentication).
|
|
@@ -7385,7 +7458,19 @@ var DelegationManager = class {
|
|
|
7385
7458
|
)
|
|
7386
7459
|
};
|
|
7387
7460
|
}
|
|
7388
|
-
|
|
7461
|
+
const parsed = DelegationRevocationReceiptSchema.safeParse(await response.json());
|
|
7462
|
+
if (!parsed.success || parsed.data.cid !== cid) {
|
|
7463
|
+
return {
|
|
7464
|
+
ok: false,
|
|
7465
|
+
error: createError(
|
|
7466
|
+
DelegationErrorCodes.REVOCATION_FAILED,
|
|
7467
|
+
"Node returned an invalid delegation revocation receipt",
|
|
7468
|
+
void 0,
|
|
7469
|
+
{ cid }
|
|
7470
|
+
)
|
|
7471
|
+
};
|
|
7472
|
+
}
|
|
7473
|
+
return { ok: true, data: parsed.data };
|
|
7389
7474
|
} catch (error) {
|
|
7390
7475
|
if (error instanceof Error && error.name === "AbortError") {
|
|
7391
7476
|
return {
|
|
@@ -7482,6 +7567,86 @@ var DelegationManager = class {
|
|
|
7482
7567
|
};
|
|
7483
7568
|
}
|
|
7484
7569
|
}
|
|
7570
|
+
/** Query lifecycle-complete delegation history for the authenticated account. */
|
|
7571
|
+
async query(options = {}) {
|
|
7572
|
+
const validated = AccountDelegationQueryOptionsSchema.safeParse(options);
|
|
7573
|
+
if (!validated.success) {
|
|
7574
|
+
return {
|
|
7575
|
+
ok: false,
|
|
7576
|
+
error: createError(
|
|
7577
|
+
DelegationErrorCodes.INVALID_INPUT,
|
|
7578
|
+
"Invalid delegation query options",
|
|
7579
|
+
void 0,
|
|
7580
|
+
{ issues: validated.error.issues }
|
|
7581
|
+
)
|
|
7582
|
+
};
|
|
7583
|
+
}
|
|
7584
|
+
if (!this.invokeAny) {
|
|
7585
|
+
return {
|
|
7586
|
+
ok: false,
|
|
7587
|
+
error: createError(
|
|
7588
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
7589
|
+
"Delegation query requires an invokeAny function"
|
|
7590
|
+
)
|
|
7591
|
+
};
|
|
7592
|
+
}
|
|
7593
|
+
if (!this.accountSpaceId) {
|
|
7594
|
+
return {
|
|
7595
|
+
ok: false,
|
|
7596
|
+
error: createError(
|
|
7597
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
7598
|
+
"Delegation query requires an account space"
|
|
7599
|
+
)
|
|
7600
|
+
};
|
|
7601
|
+
}
|
|
7602
|
+
try {
|
|
7603
|
+
const invocationHeaders = this.invokeAny(this.session, [{
|
|
7604
|
+
spaceId: this.accountSpaceId,
|
|
7605
|
+
service: "delegation",
|
|
7606
|
+
path: "",
|
|
7607
|
+
action: DelegationAction.LIST
|
|
7608
|
+
}]);
|
|
7609
|
+
const headers = Object.fromEntries(new Headers(invocationHeaders).entries());
|
|
7610
|
+
headers["content-type"] = "application/json";
|
|
7611
|
+
const response = await this.fetchFn(`${this.host}/delegation/query`, {
|
|
7612
|
+
method: "POST",
|
|
7613
|
+
headers,
|
|
7614
|
+
body: JSON.stringify(validated.data)
|
|
7615
|
+
});
|
|
7616
|
+
if (!response.ok) {
|
|
7617
|
+
const errorText = await response.text();
|
|
7618
|
+
return {
|
|
7619
|
+
ok: false,
|
|
7620
|
+
error: createError(
|
|
7621
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
7622
|
+
`Failed to query delegations: ${response.status} - ${errorText}`,
|
|
7623
|
+
void 0,
|
|
7624
|
+
{ status: response.status }
|
|
7625
|
+
)
|
|
7626
|
+
};
|
|
7627
|
+
}
|
|
7628
|
+
const parsed = AccountDelegationPageSchema.safeParse(await response.json());
|
|
7629
|
+
if (!parsed.success) {
|
|
7630
|
+
return {
|
|
7631
|
+
ok: false,
|
|
7632
|
+
error: createError(
|
|
7633
|
+
DelegationErrorCodes.INVALID_TOKEN,
|
|
7634
|
+
"Node returned an invalid delegation query response"
|
|
7635
|
+
)
|
|
7636
|
+
};
|
|
7637
|
+
}
|
|
7638
|
+
return { ok: true, data: parsed.data };
|
|
7639
|
+
} catch (error) {
|
|
7640
|
+
return {
|
|
7641
|
+
ok: false,
|
|
7642
|
+
error: createError(
|
|
7643
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
7644
|
+
`Network error during delegation query: ${String(error)}`,
|
|
7645
|
+
error instanceof Error ? error : void 0
|
|
7646
|
+
)
|
|
7647
|
+
};
|
|
7648
|
+
}
|
|
7649
|
+
}
|
|
7485
7650
|
/**
|
|
7486
7651
|
* Lists all delegations for the current session's space.
|
|
7487
7652
|
*
|