@tinycloud/sdk-core 3.7.0 → 3.8.0-beta.14
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/delegations/index.cjs +65 -6
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +4 -2
- package/dist/delegations/index.d.ts +4 -2
- package/dist/delegations/index.js +66 -7
- package/dist/delegations/index.js.map +1 -1
- package/dist/delegations/issued.cjs +697 -0
- package/dist/delegations/issued.cjs.map +1 -0
- package/dist/delegations/issued.d.cts +54 -0
- package/dist/delegations/issued.d.ts +54 -0
- package/dist/delegations/issued.js +674 -0
- package/dist/delegations/issued.js.map +1 -0
- package/dist/index.cjs +118 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +124 -12
- package/dist/index.js.map +1 -1
- package/dist/{recipient-types.schema-BApcOn1t.d.cts → recipient-types.schema-BIJcihno.d.cts} +42 -1741
- package/dist/{recipient-types.schema-BApcOn1t.d.ts → recipient-types.schema-Ebi5aliq.d.ts} +42 -1741
- package/dist/types.schema-BmN-OnCA.d.cts +1763 -0
- package/dist/types.schema-BmN-OnCA.d.ts +1763 -0
- package/package.json +9 -4
|
@@ -189,7 +189,11 @@ var DelegationErrorCodes = {
|
|
|
189
189
|
KV_SERVICE_UNAVAILABLE: "KV_SERVICE_UNAVAILABLE",
|
|
190
190
|
DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
|
|
191
191
|
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
192
|
-
UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION"
|
|
192
|
+
UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION",
|
|
193
|
+
/** The node answered 503: the delegation chain is too deep to evaluate right now. Retry later. */
|
|
194
|
+
CHAIN_TOO_DEEP: "CHAIN_TOO_DEEP",
|
|
195
|
+
/** The node answered 400 "invalid delegation query cursor": malformed, foreign or from another filter. Start the listing again without it. */
|
|
196
|
+
INVALID_CURSOR: "INVALID_CURSOR"
|
|
193
197
|
};
|
|
194
198
|
var DelegationSchema = import_zod.z.object({
|
|
195
199
|
/** Content identifier (CID) of the delegation */
|
|
@@ -266,7 +270,7 @@ var AccountDelegationPageSchema = import_zod.z.object({
|
|
|
266
270
|
nextCursor: import_zod.z.string().optional()
|
|
267
271
|
}).strict();
|
|
268
272
|
var AccountDelegationQueryOptionsSchema = import_zod.z.object({
|
|
269
|
-
direction: import_zod.z.enum(["granted", "received", "all"]).optional(),
|
|
273
|
+
direction: import_zod.z.enum(["granted", "received", "all", "issued"]).optional(),
|
|
270
274
|
status: import_zod.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
|
|
271
275
|
space: import_zod.z.string().trim().min(1).optional(),
|
|
272
276
|
limit: import_zod.z.number().int().min(1).max(100).optional(),
|
|
@@ -452,6 +456,8 @@ var DelegationManagerConfigSchema = import_zod.z.object({
|
|
|
452
456
|
).optional(),
|
|
453
457
|
/** Optional owner-signed authorization for direct CID revocation */
|
|
454
458
|
signOwnerRevocation: import_zod.z.custom().optional(),
|
|
459
|
+
/** Optional signer for proofless invocations by the session's own did:key (issued-delegation list and revoke) */
|
|
460
|
+
sessionInvocationSigner: import_zod.z.custom().optional(),
|
|
455
461
|
/** Optional custom fetch implementation */
|
|
456
462
|
fetch: import_zod.z.unknown().refine(
|
|
457
463
|
(val) => val === void 0 || typeof val === "function",
|
|
@@ -547,7 +553,7 @@ var CreateDelegationWasmResultSchema = import_zod.z.object({
|
|
|
547
553
|
resources: import_zod.z.array(DelegatedResourceSchema)
|
|
548
554
|
});
|
|
549
555
|
|
|
550
|
-
// src/delegations/
|
|
556
|
+
// src/delegations/shared.ts
|
|
551
557
|
var DelegationAction = {
|
|
552
558
|
REVOKE: "tinycloud.delegation/revoke",
|
|
553
559
|
STATUS: "tinycloud.delegation/status",
|
|
@@ -564,6 +570,8 @@ function createError(code3, message, cause, meta) {
|
|
|
564
570
|
meta
|
|
565
571
|
};
|
|
566
572
|
}
|
|
573
|
+
|
|
574
|
+
// src/delegations/DelegationManager.ts
|
|
567
575
|
async function readInvokedJson(response, action) {
|
|
568
576
|
const text = await response.text();
|
|
569
577
|
if (text.trim() === "") {
|
|
@@ -586,11 +594,13 @@ var DelegationManager = class {
|
|
|
586
594
|
* @param config - Configuration including hosts, session, and invoke function
|
|
587
595
|
*/
|
|
588
596
|
constructor(config) {
|
|
597
|
+
this.issuedState = { issuedQuerySupported: false };
|
|
589
598
|
this.hosts = config.hosts;
|
|
590
599
|
this.session = config.session;
|
|
591
600
|
this.invoke = config.invoke;
|
|
592
601
|
this.invokeAny = config.invokeAny;
|
|
593
602
|
this.signOwnerRevocation = config.signOwnerRevocation;
|
|
603
|
+
this.sessionInvocationSigner = config.sessionInvocationSigner;
|
|
594
604
|
this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
595
605
|
this.accountSpaceId = config.accountSpaceId;
|
|
596
606
|
}
|
|
@@ -813,8 +823,14 @@ var DelegationManager = class {
|
|
|
813
823
|
};
|
|
814
824
|
}
|
|
815
825
|
}
|
|
816
|
-
/**
|
|
817
|
-
|
|
826
|
+
/**
|
|
827
|
+
* Query lifecycle-complete delegation history for the authenticated account.
|
|
828
|
+
*
|
|
829
|
+
* `scope.spaces` lists the spaces to sign `tinycloud.delegation/list` for, in order. Omitted, the
|
|
830
|
+
* account space is tried, then the session's own space. A caller that knows which of them the session
|
|
831
|
+
* holds passes only those; an empty list sends nothing and answers PERMISSION_DENIED.
|
|
832
|
+
*/
|
|
833
|
+
async query(options = {}, scope = {}) {
|
|
818
834
|
const validated = AccountDelegationQueryOptionsSchema.safeParse(options);
|
|
819
835
|
if (!validated.success) {
|
|
820
836
|
return {
|
|
@@ -827,6 +843,7 @@ var DelegationManager = class {
|
|
|
827
843
|
)
|
|
828
844
|
};
|
|
829
845
|
}
|
|
846
|
+
if (validated.data.direction === "issued") return this.queryIssued(validated.data);
|
|
830
847
|
if (!this.invokeAny) {
|
|
831
848
|
return {
|
|
832
849
|
ok: false,
|
|
@@ -848,7 +865,7 @@ var DelegationManager = class {
|
|
|
848
865
|
}
|
|
849
866
|
try {
|
|
850
867
|
let response;
|
|
851
|
-
for (const spaceId of
|
|
868
|
+
for (const spaceId of new Set(scope.spaces ?? [accountSpaceId, this.session.spaceId])) {
|
|
852
869
|
const headers = Object.fromEntries(new Headers(this.invokeAny(this.session, [{
|
|
853
870
|
spaceId,
|
|
854
871
|
service: "delegation",
|
|
@@ -908,6 +925,45 @@ var DelegationManager = class {
|
|
|
908
925
|
};
|
|
909
926
|
}
|
|
910
927
|
}
|
|
928
|
+
/** The state the lazily loaded issued-delegation module reads and updates. */
|
|
929
|
+
issuedContext() {
|
|
930
|
+
return {
|
|
931
|
+
host: this.host,
|
|
932
|
+
fetchFn: this.fetchFn,
|
|
933
|
+
sessionInvocationSigner: this.sessionInvocationSigner,
|
|
934
|
+
state: this.issuedState
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Lists the delegations this session's own key issued (`direction: "issued"`).
|
|
939
|
+
* The implementation loads on first use.
|
|
940
|
+
*/
|
|
941
|
+
async queryIssued(options) {
|
|
942
|
+
const issued = await import("@tinycloud/sdk-core/delegations/issued");
|
|
943
|
+
return issued.queryIssued(this.issuedContext(), options);
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Every delegation this session's key issued, following `nextCursor` until
|
|
947
|
+
* it is absent. `maxItems` stops early once that many are collected;
|
|
948
|
+
* `untilCid` stops after the page that contains that delegation. Items come
|
|
949
|
+
* in CID order (each carries `issuedAt`). The implementation loads on first use.
|
|
950
|
+
*/
|
|
951
|
+
async queryAllIssued(options = {}) {
|
|
952
|
+
const issued = await import("@tinycloud/sdk-core/delegations/issued");
|
|
953
|
+
return issued.queryAllIssued((page) => this.query(page), options);
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Revokes a delegation this session's key issued, with no proof: a UCAN
|
|
957
|
+
* signed by the session's own did:key carrying `urn:cid:<cid>` and
|
|
958
|
+
* `tinycloud.delegation/revoke`. Revoking a delegation that is already revoked
|
|
959
|
+
* succeeds. A refusal (the key is not the delegator) carries the node's
|
|
960
|
+
* message; 503 means the chain is too deep right now, retry later.
|
|
961
|
+
* The implementation loads on first use.
|
|
962
|
+
*/
|
|
963
|
+
async revokeIssued(cid2) {
|
|
964
|
+
const issued = await import("@tinycloud/sdk-core/delegations/issued");
|
|
965
|
+
return issued.revokeIssued(this.issuedContext(), cid2);
|
|
966
|
+
}
|
|
911
967
|
/**
|
|
912
968
|
* Gets the full delegation chain for a given delegation.
|
|
913
969
|
*
|
|
@@ -1260,6 +1316,9 @@ var SERVICE_LONG_TO_SHORT = Object.freeze(
|
|
|
1260
1316
|
Object.entries(SERVICE_SHORT_TO_LONG).map(([s, l]) => [l, s])
|
|
1261
1317
|
)
|
|
1262
1318
|
);
|
|
1319
|
+
var KEY_SEGMENT = "[a-z0-9][a-z0-9._-]{0,63}";
|
|
1320
|
+
var KEY_APP_ID = new RegExp(`^${KEY_SEGMENT}$`);
|
|
1321
|
+
var KEY_PATH = new RegExp(`^${KEY_SEGMENT}(?:/${KEY_SEGMENT}){2,7}$`);
|
|
1263
1322
|
|
|
1264
1323
|
// src/identity.ts
|
|
1265
1324
|
var import_viem = require("viem");
|