@tinycloud/sdk-core 3.0.1-beta.0 → 3.1.0-beta.10
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 +35 -9
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +2 -2
- package/dist/delegations/index.d.ts +2 -2
- package/dist/delegations/index.js +33 -7
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +412 -357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -8
- package/dist/index.d.ts +35 -8
- package/dist/index.js +246 -184
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +36 -16
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.js +36 -16
- package/dist/policy/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/{recipient-types.schema-D9AI8tjN.d.cts → recipient-types.schema-_JkBDZB6.d.cts} +2 -2
- package/dist/{recipient-types.schema-D9AI8tjN.d.ts → recipient-types.schema-_JkBDZB6.d.ts} +2 -2
package/dist/index.js
CHANGED
|
@@ -3437,6 +3437,32 @@ import { sha256 as sha2564 } from "@noble/hashes/sha256";
|
|
|
3437
3437
|
import { blake3 } from "@noble/hashes/blake3";
|
|
3438
3438
|
import { ed25519 as ed255193 } from "@noble/curves/ed25519";
|
|
3439
3439
|
import { z as z2 } from "zod";
|
|
3440
|
+
|
|
3441
|
+
// src/http-error.ts
|
|
3442
|
+
import { ErrorCodes, serviceError } from "@tinycloud/sdk-services";
|
|
3443
|
+
async function httpResponseError(response, context) {
|
|
3444
|
+
let body;
|
|
3445
|
+
try {
|
|
3446
|
+
body = await response.text();
|
|
3447
|
+
} catch {
|
|
3448
|
+
body = response.statusText;
|
|
3449
|
+
}
|
|
3450
|
+
body = body.trim().slice(0, 512);
|
|
3451
|
+
return Object.assign(new Error(`${context}: HTTP ${response.status}${body ? ` - ${body}` : ""}`), {
|
|
3452
|
+
status: response.status
|
|
3453
|
+
});
|
|
3454
|
+
}
|
|
3455
|
+
async function serviceHttpError(response, code3, context, service) {
|
|
3456
|
+
const failure = await httpResponseError(response, context);
|
|
3457
|
+
return serviceError(
|
|
3458
|
+
response.status === 401 || response.status === 403 ? ErrorCodes.AUTH_UNAUTHORIZED : code3,
|
|
3459
|
+
failure.message,
|
|
3460
|
+
service,
|
|
3461
|
+
{ meta: { status: response.status } }
|
|
3462
|
+
);
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
// src/policy/unified.ts
|
|
3440
3466
|
var POLICY_V1_SCHEMA = "xyz.tinycloud.policy/policy/v1";
|
|
3441
3467
|
var POLICY_CAPABILITY_V1_SCHEMA = "xyz.tinycloud.policy/capability/v1";
|
|
3442
3468
|
var POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA = "xyz.tinycloud.policy/enforcement-delegation/v2";
|
|
@@ -3464,7 +3490,7 @@ async function requestPolicyChallengeV3(input) {
|
|
|
3464
3490
|
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3465
3491
|
body: JSON.stringify({ policyCid: input.policyCid, recipientDid: input.recipientDid, requestedCapabilities: input.requestedCapabilities.map(normalizeUnifiedPolicyCapability) })
|
|
3466
3492
|
});
|
|
3467
|
-
if (!response.ok) throw
|
|
3493
|
+
if (!response.ok) throw await httpResponseError(response, "policy challenge rejected");
|
|
3468
3494
|
const value = object2(await response.json(), "policy challenge");
|
|
3469
3495
|
if (typeof value.challengeId !== "string" || typeof value.nonce !== "string" || value.policyCid !== input.policyCid || value.recipientDid !== input.recipientDid)
|
|
3470
3496
|
throw new Error("policy challenge binding is invalid");
|
|
@@ -3527,7 +3553,7 @@ async function getPolicyRootStatusV3(input) {
|
|
|
3527
3553
|
redirect: "error",
|
|
3528
3554
|
headers: { accept: "application/json" }
|
|
3529
3555
|
});
|
|
3530
|
-
if (!response.ok) throw
|
|
3556
|
+
if (!response.ok) throw await httpResponseError(response, "policy root status rejected");
|
|
3531
3557
|
const value = object2(await response.json(), "policy root status");
|
|
3532
3558
|
const checkpoint = object2(value.checkpoint, "policy root checkpoint");
|
|
3533
3559
|
if (value.rootCid !== input.rootCid || value.state !== "active" && value.state !== "revoked" || value.state !== checkpoint.state || !verifyPolicyRootStatusCheckpointV3({ rootCid: input.rootCid, checkpoint, expectedNodeAudience: input.expectedNodeAudience, now: input.now }))
|
|
@@ -3587,9 +3613,12 @@ async function renewPolicyRootStatusV3(input) {
|
|
|
3587
3613
|
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3588
3614
|
body: JSON.stringify({ rootCid: input.rootCid, renewal: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.ownerDid, value: encodeBase64Url2(signature) } } })
|
|
3589
3615
|
});
|
|
3590
|
-
if (!response.ok) throw
|
|
3616
|
+
if (!response.ok) throw await httpResponseError(response, "policy root renewal rejected");
|
|
3591
3617
|
return object2(await response.json(), "policy root renewal");
|
|
3592
3618
|
}
|
|
3619
|
+
function rfc3339Seconds(value) {
|
|
3620
|
+
return new Date(Math.floor(value.getTime() / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
|
|
3621
|
+
}
|
|
3593
3622
|
async function revokePolicyRootV3(input) {
|
|
3594
3623
|
if (input.reason.length === 0) throw new Error("policy root revocation reason is required");
|
|
3595
3624
|
const unsigned = {
|
|
@@ -3598,7 +3627,7 @@ async function revokePolicyRootV3(input) {
|
|
|
3598
3627
|
targetRole: input.targetRole,
|
|
3599
3628
|
ownerDid: input.ownerDid,
|
|
3600
3629
|
nodeAudience: input.nodeAudience,
|
|
3601
|
-
revokedAt: (input.now ?? /* @__PURE__ */ new Date())
|
|
3630
|
+
revokedAt: rfc3339Seconds(input.now ?? /* @__PURE__ */ new Date()),
|
|
3602
3631
|
reason: input.reason,
|
|
3603
3632
|
issuerDid: input.issuerDid
|
|
3604
3633
|
};
|
|
@@ -3611,7 +3640,7 @@ async function revokePolicyRootV3(input) {
|
|
|
3611
3640
|
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3612
3641
|
body: JSON.stringify({ revocation: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.issuerDid, value: encodeBase64Url2(signature) } } })
|
|
3613
3642
|
});
|
|
3614
|
-
if (!response.ok) throw
|
|
3643
|
+
if (!response.ok) throw await httpResponseError(response, "policy root revocation rejected");
|
|
3615
3644
|
return object2(await response.json(), "policy root revocation");
|
|
3616
3645
|
}
|
|
3617
3646
|
var POLICY_SESSION_FACT_KEYS = [
|
|
@@ -3880,7 +3909,7 @@ async function registerPolicyV3(input) {
|
|
|
3880
3909
|
}
|
|
3881
3910
|
);
|
|
3882
3911
|
if (!bindingResponse.ok) {
|
|
3883
|
-
throw
|
|
3912
|
+
throw await httpResponseError(bindingResponse, "policy enforcer binding rejected");
|
|
3884
3913
|
}
|
|
3885
3914
|
const binding = exactObject(
|
|
3886
3915
|
await bindingResponse.json(),
|
|
@@ -3946,7 +3975,7 @@ async function registerPolicyV3(input) {
|
|
|
3946
3975
|
}
|
|
3947
3976
|
);
|
|
3948
3977
|
if (!response.ok) {
|
|
3949
|
-
throw
|
|
3978
|
+
throw await httpResponseError(response, "policy registration rejected");
|
|
3950
3979
|
}
|
|
3951
3980
|
const receipt = exactObject(
|
|
3952
3981
|
await response.json(),
|
|
@@ -4349,7 +4378,7 @@ function date(value, label) {
|
|
|
4349
4378
|
if (!Number.isFinite(Date.parse(text2))) throw new Error(`${label} is invalid`);
|
|
4350
4379
|
return text2;
|
|
4351
4380
|
}
|
|
4352
|
-
function
|
|
4381
|
+
function rfc3339Seconds2(value) {
|
|
4353
4382
|
return new Date(Math.floor(value.getTime() / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
|
|
4354
4383
|
}
|
|
4355
4384
|
function validateUnifiedPolicyV2(value, expectedPolicyCid) {
|
|
@@ -4514,8 +4543,8 @@ async function buildPolicyCredentialPresentationV4(input) {
|
|
|
4514
4543
|
requirementDigest,
|
|
4515
4544
|
descriptorDigest: input.credential.descriptorDigest,
|
|
4516
4545
|
requestedCapabilities: Object.freeze(requestedCapabilities),
|
|
4517
|
-
issuedAt:
|
|
4518
|
-
expiresAt:
|
|
4546
|
+
issuedAt: rfc3339Seconds2(now),
|
|
4547
|
+
expiresAt: rfc3339Seconds2(new Date(expiresAtMs))
|
|
4519
4548
|
}), input.sign);
|
|
4520
4549
|
}
|
|
4521
4550
|
async function buildPolicyCredentialPresentationV3(input) {
|
|
@@ -4569,8 +4598,8 @@ async function buildPolicyCredentialPresentationV3(input) {
|
|
|
4569
4598
|
requirementDigest,
|
|
4570
4599
|
descriptorDigest: input.credential.descriptorDigest,
|
|
4571
4600
|
requestedCapabilities: Object.freeze(requestedCapabilities),
|
|
4572
|
-
issuedAt:
|
|
4573
|
-
expiresAt:
|
|
4601
|
+
issuedAt: rfc3339Seconds2(now),
|
|
4602
|
+
expiresAt: rfc3339Seconds2(new Date(expiresAtMs))
|
|
4574
4603
|
});
|
|
4575
4604
|
const digest4 = sha2565(
|
|
4576
4605
|
new TextEncoder().encode(
|
|
@@ -4632,7 +4661,7 @@ async function admitPolicyCredentialV3(input) {
|
|
|
4632
4661
|
requestedSessionExpiry(input.requestedExpiresAt, policy),
|
|
4633
4662
|
input.signal
|
|
4634
4663
|
);
|
|
4635
|
-
if (!response.ok) throw
|
|
4664
|
+
if (!response.ok) throw await httpResponseError(response, "policy delegation rejected");
|
|
4636
4665
|
const value = record(await response.json(), "policy delegation");
|
|
4637
4666
|
if (value.admitted !== true || typeof value.sessionCid !== "string" || typeof value.authorization !== "string") {
|
|
4638
4667
|
throw new Error("policy delegation response is invalid");
|
|
@@ -4685,7 +4714,7 @@ async function admitPolicyCredentialV4(input) {
|
|
|
4685
4714
|
requestedSessionExpiry(input.requestedExpiresAt, policy),
|
|
4686
4715
|
input.signal
|
|
4687
4716
|
);
|
|
4688
|
-
if (!response.ok) throw
|
|
4717
|
+
if (!response.ok) throw await httpResponseError(response, "policy delegation rejected");
|
|
4689
4718
|
const value = record(await response.json(), "policy delegation");
|
|
4690
4719
|
if (value.admitted !== true || typeof value.sessionCid !== "string" || typeof value.authorization !== "string") throw new Error("policy delegation response is invalid");
|
|
4691
4720
|
const session = parsePolicySessionUcan(value.authorization, [
|
|
@@ -4704,7 +4733,7 @@ async function admitPolicyCredentialV4(input) {
|
|
|
4704
4733
|
signal: input.signal,
|
|
4705
4734
|
headers: { Authorization: session.authorization }
|
|
4706
4735
|
});
|
|
4707
|
-
if (!importResponse.ok) throw
|
|
4736
|
+
if (!importResponse.ok) throw await httpResponseError(importResponse, "delegation import rejected");
|
|
4708
4737
|
input.signal?.throwIfAborted();
|
|
4709
4738
|
return Object.freeze({ challenge, presentation, session, delegationImported: true });
|
|
4710
4739
|
}
|
|
@@ -8160,8 +8189,17 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
8160
8189
|
}
|
|
8161
8190
|
return `[${branches.join(",")}]`;
|
|
8162
8191
|
}
|
|
8192
|
+
var EXPLICIT_ONLY_ACTIONS = {
|
|
8193
|
+
"tinycloud.kv/sync": true,
|
|
8194
|
+
"tinycloud.kv/retain": true
|
|
8195
|
+
};
|
|
8196
|
+
function isExplicitOnlyAction(action) {
|
|
8197
|
+
return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
|
|
8198
|
+
}
|
|
8163
8199
|
function actionContains(grantedAction, requestedAction) {
|
|
8164
|
-
if (grantedAction ===
|
|
8200
|
+
if (grantedAction === requestedAction) return true;
|
|
8201
|
+
if (isExplicitOnlyAction(requestedAction)) return false;
|
|
8202
|
+
if (grantedAction === "*") return true;
|
|
8165
8203
|
if (!grantedAction.endsWith("/*")) return false;
|
|
8166
8204
|
const service = grantedAction.slice(0, -2);
|
|
8167
8205
|
return requestedAction === service || requestedAction.startsWith(`${service}/`);
|
|
@@ -8225,7 +8263,7 @@ import { ed25519 as ed255197 } from "@noble/curves/ed25519";
|
|
|
8225
8263
|
|
|
8226
8264
|
// src/delegations/ShareRecipientClient.ts
|
|
8227
8265
|
import {
|
|
8228
|
-
ErrorCodes,
|
|
8266
|
+
ErrorCodes as ErrorCodes2,
|
|
8229
8267
|
KVService,
|
|
8230
8268
|
ServiceContext
|
|
8231
8269
|
} from "@tinycloud/sdk-services";
|
|
@@ -9346,7 +9384,7 @@ async function importPortableDelegation(fetchFn, host, delegation) {
|
|
|
9346
9384
|
headers: { Authorization: parsed.delegationHeader.Authorization }
|
|
9347
9385
|
});
|
|
9348
9386
|
if (!response.ok)
|
|
9349
|
-
throw
|
|
9387
|
+
throw await httpResponseError(response, "node rejected delegation import");
|
|
9350
9388
|
const body = await response.json().catch(() => ({}));
|
|
9351
9389
|
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
9352
9390
|
return {};
|
|
@@ -9415,7 +9453,7 @@ function redactedCode(error) {
|
|
|
9415
9453
|
if (error instanceof ShareConflict) return error.code;
|
|
9416
9454
|
const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
|
|
9417
9455
|
if (typeof code3 !== "string") return "SHARE_INVALID";
|
|
9418
|
-
if (code3 ===
|
|
9456
|
+
if (code3 === ErrorCodes2.KV_PRECONDITION_FAILED || code3 === ErrorCodes2.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
|
|
9419
9457
|
if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
|
|
9420
9458
|
if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
|
|
9421
9459
|
if (code3.includes("REVOK")) return "SHARE_REVOKED";
|
|
@@ -9654,7 +9692,7 @@ var ShareRecipientClient = class {
|
|
|
9654
9692
|
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
9655
9693
|
const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
9656
9694
|
if (!result2.ok) {
|
|
9657
|
-
if (result2.error.code ===
|
|
9695
|
+
if (result2.error.code === ErrorCodes2.KV_PRECONDITION_FAILED || result2.error.code === ErrorCodes2.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
|
|
9658
9696
|
throw result2.error;
|
|
9659
9697
|
}
|
|
9660
9698
|
return { etag: result2.data.headers.etag };
|
|
@@ -9662,7 +9700,7 @@ var ShareRecipientClient = class {
|
|
|
9662
9700
|
if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
|
|
9663
9701
|
const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
9664
9702
|
if (!result.ok) {
|
|
9665
|
-
if (result.error.code ===
|
|
9703
|
+
if (result.error.code === ErrorCodes2.KV_PRECONDITION_FAILED || result.error.code === ErrorCodes2.KV_CONFLICT) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
|
|
9666
9704
|
throw result.error;
|
|
9667
9705
|
}
|
|
9668
9706
|
return { etag: result.data.headers.etag };
|
|
@@ -10848,7 +10886,9 @@ var SharingService = class {
|
|
|
10848
10886
|
if (delegation.allowSubDelegation === false) continue;
|
|
10849
10887
|
if (!this.pathMatches(delegation.path || "", path)) continue;
|
|
10850
10888
|
const delegationActions = delegation.actions || [];
|
|
10851
|
-
if (!actions.every(
|
|
10889
|
+
if (!actions.every(
|
|
10890
|
+
(action) => delegationActions.some((granted) => actionContains(granted, action))
|
|
10891
|
+
)) {
|
|
10852
10892
|
continue;
|
|
10853
10893
|
}
|
|
10854
10894
|
if ((delegation.caveats?.length ?? 0) > 0) {
|
|
@@ -12141,12 +12181,12 @@ import {
|
|
|
12141
12181
|
HooksService,
|
|
12142
12182
|
ok as ok2,
|
|
12143
12183
|
err as err2,
|
|
12144
|
-
serviceError as
|
|
12145
|
-
ErrorCodes as
|
|
12184
|
+
serviceError as serviceError3,
|
|
12185
|
+
ErrorCodes as ErrorCodes3
|
|
12146
12186
|
} from "@tinycloud/sdk-services";
|
|
12147
12187
|
|
|
12148
12188
|
// src/spaces/SpaceService.ts
|
|
12149
|
-
import { ok, err, serviceError } from "@tinycloud/sdk-services";
|
|
12189
|
+
import { ok, err, serviceError as serviceError2, authorizationVerdictOf } from "@tinycloud/sdk-services";
|
|
12150
12190
|
|
|
12151
12191
|
// src/spaces/Space.ts
|
|
12152
12192
|
function unavailableSecretsService() {
|
|
@@ -12576,7 +12616,7 @@ var SpaceService = class {
|
|
|
12576
12616
|
async list() {
|
|
12577
12617
|
if (!this.session) {
|
|
12578
12618
|
return err(
|
|
12579
|
-
|
|
12619
|
+
serviceError2(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
12580
12620
|
);
|
|
12581
12621
|
}
|
|
12582
12622
|
try {
|
|
@@ -12584,6 +12624,9 @@ var SpaceService = class {
|
|
|
12584
12624
|
const ownedResult = await this.listOwnedSpaces();
|
|
12585
12625
|
if (ownedResult.ok) {
|
|
12586
12626
|
spaces.push(...ownedResult.data);
|
|
12627
|
+
} else {
|
|
12628
|
+
const verdict = authorizationVerdictOf(ownedResult.error);
|
|
12629
|
+
if (verdict === "unauthenticated" || verdict === "forbidden") return err(ownedResult.error);
|
|
12587
12630
|
}
|
|
12588
12631
|
if (this.capabilityRegistry) {
|
|
12589
12632
|
const delegatedSpaces = this.discoverDelegatedSpaces();
|
|
@@ -12596,7 +12639,7 @@ var SpaceService = class {
|
|
|
12596
12639
|
return ok(uniqueSpaces);
|
|
12597
12640
|
} catch (error) {
|
|
12598
12641
|
return err(
|
|
12599
|
-
|
|
12642
|
+
serviceError2(
|
|
12600
12643
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
12601
12644
|
`Failed to list spaces: ${String(error)}`,
|
|
12602
12645
|
SERVICE_NAME,
|
|
@@ -12616,21 +12659,18 @@ var SpaceService = class {
|
|
|
12616
12659
|
headers
|
|
12617
12660
|
});
|
|
12618
12661
|
if (!response.ok) {
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
{ meta: { status: response.status } }
|
|
12626
|
-
)
|
|
12627
|
-
);
|
|
12662
|
+
return err(await serviceHttpError(
|
|
12663
|
+
response,
|
|
12664
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
12665
|
+
"Failed to list owned spaces",
|
|
12666
|
+
SERVICE_NAME
|
|
12667
|
+
));
|
|
12628
12668
|
}
|
|
12629
12669
|
const rawData = await response.json();
|
|
12630
12670
|
const validationResult = validateServerOwnedSpacesResponse(rawData);
|
|
12631
12671
|
if (!validationResult.ok) {
|
|
12632
12672
|
return err(
|
|
12633
|
-
|
|
12673
|
+
serviceError2(
|
|
12634
12674
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
12635
12675
|
validationResult.error.message,
|
|
12636
12676
|
SERVICE_NAME,
|
|
@@ -12649,7 +12689,7 @@ var SpaceService = class {
|
|
|
12649
12689
|
return ok(spaces);
|
|
12650
12690
|
} catch (error) {
|
|
12651
12691
|
return err(
|
|
12652
|
-
|
|
12692
|
+
serviceError2(
|
|
12653
12693
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
12654
12694
|
`Network error listing owned spaces: ${String(error)}`,
|
|
12655
12695
|
SERVICE_NAME,
|
|
@@ -12731,12 +12771,12 @@ var SpaceService = class {
|
|
|
12731
12771
|
async create(name2) {
|
|
12732
12772
|
if (!this.session) {
|
|
12733
12773
|
return err(
|
|
12734
|
-
|
|
12774
|
+
serviceError2(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
12735
12775
|
);
|
|
12736
12776
|
}
|
|
12737
12777
|
if (!name2 || !/^[a-zA-Z0-9_-]+$/.test(name2)) {
|
|
12738
12778
|
return err(
|
|
12739
|
-
|
|
12779
|
+
serviceError2(
|
|
12740
12780
|
SpaceErrorCodes.INVALID_NAME,
|
|
12741
12781
|
"Space name must contain only alphanumeric characters, underscores, and hyphens",
|
|
12742
12782
|
SERVICE_NAME
|
|
@@ -12751,30 +12791,26 @@ var SpaceService = class {
|
|
|
12751
12791
|
body: JSON.stringify({ name: name2 })
|
|
12752
12792
|
});
|
|
12753
12793
|
if (!response.ok) {
|
|
12754
|
-
const errorText = await response.text();
|
|
12755
12794
|
if (response.status === 409) {
|
|
12756
|
-
return err(
|
|
12757
|
-
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
);
|
|
12795
|
+
return err(await serviceHttpError(
|
|
12796
|
+
response,
|
|
12797
|
+
SpaceErrorCodes.ALREADY_EXISTS,
|
|
12798
|
+
`Space "${name2}" already exists`,
|
|
12799
|
+
SERVICE_NAME
|
|
12800
|
+
));
|
|
12763
12801
|
}
|
|
12764
|
-
return err(
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
)
|
|
12771
|
-
);
|
|
12802
|
+
return err(await serviceHttpError(
|
|
12803
|
+
response,
|
|
12804
|
+
SpaceErrorCodes.CREATION_FAILED,
|
|
12805
|
+
"Failed to create space",
|
|
12806
|
+
SERVICE_NAME
|
|
12807
|
+
));
|
|
12772
12808
|
}
|
|
12773
12809
|
const rawData = await response.json();
|
|
12774
12810
|
const validationResult = validateServerCreateSpaceResponse(rawData);
|
|
12775
12811
|
if (!validationResult.ok) {
|
|
12776
12812
|
return err(
|
|
12777
|
-
|
|
12813
|
+
serviceError2(
|
|
12778
12814
|
SpaceErrorCodes.CREATION_FAILED,
|
|
12779
12815
|
validationResult.error.message,
|
|
12780
12816
|
SERVICE_NAME,
|
|
@@ -12794,7 +12830,7 @@ var SpaceService = class {
|
|
|
12794
12830
|
return ok(spaceInfo);
|
|
12795
12831
|
} catch (error) {
|
|
12796
12832
|
return err(
|
|
12797
|
-
|
|
12833
|
+
serviceError2(
|
|
12798
12834
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
12799
12835
|
`Network error creating space: ${String(error)}`,
|
|
12800
12836
|
SERVICE_NAME,
|
|
@@ -12882,7 +12918,7 @@ var SpaceService = class {
|
|
|
12882
12918
|
}
|
|
12883
12919
|
if (!this.session) {
|
|
12884
12920
|
return err(
|
|
12885
|
-
|
|
12921
|
+
serviceError2(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
12886
12922
|
);
|
|
12887
12923
|
}
|
|
12888
12924
|
try {
|
|
@@ -12894,24 +12930,25 @@ var SpaceService = class {
|
|
|
12894
12930
|
});
|
|
12895
12931
|
if (!response.ok) {
|
|
12896
12932
|
if (response.status === 404) {
|
|
12897
|
-
return err(
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
const errorText = await response.text();
|
|
12902
|
-
return err(
|
|
12903
|
-
serviceError(
|
|
12904
|
-
SpaceErrorCodes.NETWORK_ERROR,
|
|
12905
|
-
`Failed to get space info: ${response.status} - ${errorText}`,
|
|
12933
|
+
return err(await serviceHttpError(
|
|
12934
|
+
response,
|
|
12935
|
+
SpaceErrorCodes.NOT_FOUND,
|
|
12936
|
+
`Space not found: ${spaceId}`,
|
|
12906
12937
|
SERVICE_NAME
|
|
12907
|
-
)
|
|
12908
|
-
|
|
12938
|
+
));
|
|
12939
|
+
}
|
|
12940
|
+
return err(await serviceHttpError(
|
|
12941
|
+
response,
|
|
12942
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
12943
|
+
"Failed to get space info",
|
|
12944
|
+
SERVICE_NAME
|
|
12945
|
+
));
|
|
12909
12946
|
}
|
|
12910
12947
|
const rawData = await response.json();
|
|
12911
12948
|
const validationResult = validateServerSpaceInfoResponse(rawData);
|
|
12912
12949
|
if (!validationResult.ok) {
|
|
12913
12950
|
return err(
|
|
12914
|
-
|
|
12951
|
+
serviceError2(
|
|
12915
12952
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
12916
12953
|
validationResult.error.message,
|
|
12917
12954
|
SERVICE_NAME,
|
|
@@ -12932,7 +12969,7 @@ var SpaceService = class {
|
|
|
12932
12969
|
return ok(spaceInfo);
|
|
12933
12970
|
} catch (error) {
|
|
12934
12971
|
return err(
|
|
12935
|
-
|
|
12972
|
+
serviceError2(
|
|
12936
12973
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
12937
12974
|
`Network error getting space info: ${String(error)}`,
|
|
12938
12975
|
SERVICE_NAME,
|
|
@@ -13017,20 +13054,18 @@ var SpaceService = class {
|
|
|
13017
13054
|
headers
|
|
13018
13055
|
});
|
|
13019
13056
|
if (!response.ok) {
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
)
|
|
13027
|
-
);
|
|
13057
|
+
return err(await serviceHttpError(
|
|
13058
|
+
response,
|
|
13059
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13060
|
+
"Failed to list delegations",
|
|
13061
|
+
SERVICE_NAME
|
|
13062
|
+
));
|
|
13028
13063
|
}
|
|
13029
13064
|
const rawData = await response.json();
|
|
13030
13065
|
const validationResult = validateServerDelegationsResponse(rawData);
|
|
13031
13066
|
if (!validationResult.ok) {
|
|
13032
13067
|
return err(
|
|
13033
|
-
|
|
13068
|
+
serviceError2(
|
|
13034
13069
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13035
13070
|
validationResult.error.message,
|
|
13036
13071
|
SERVICE_NAME,
|
|
@@ -13042,7 +13077,7 @@ var SpaceService = class {
|
|
|
13042
13077
|
return ok(delegations);
|
|
13043
13078
|
} catch (error) {
|
|
13044
13079
|
return err(
|
|
13045
|
-
|
|
13080
|
+
serviceError2(
|
|
13046
13081
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13047
13082
|
`Network error listing delegations: ${String(error)}`,
|
|
13048
13083
|
SERVICE_NAME
|
|
@@ -13072,20 +13107,18 @@ var SpaceService = class {
|
|
|
13072
13107
|
headers
|
|
13073
13108
|
});
|
|
13074
13109
|
if (!response.ok) {
|
|
13075
|
-
|
|
13076
|
-
|
|
13077
|
-
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
|
|
13081
|
-
)
|
|
13082
|
-
);
|
|
13110
|
+
return err(await serviceHttpError(
|
|
13111
|
+
response,
|
|
13112
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13113
|
+
"Failed to list received delegations",
|
|
13114
|
+
SERVICE_NAME
|
|
13115
|
+
));
|
|
13083
13116
|
}
|
|
13084
13117
|
const rawData = await response.json();
|
|
13085
13118
|
const validationResult = validateServerDelegationsResponse(rawData);
|
|
13086
13119
|
if (!validationResult.ok) {
|
|
13087
13120
|
return err(
|
|
13088
|
-
|
|
13121
|
+
serviceError2(
|
|
13089
13122
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13090
13123
|
validationResult.error.message,
|
|
13091
13124
|
SERVICE_NAME,
|
|
@@ -13097,7 +13130,7 @@ var SpaceService = class {
|
|
|
13097
13130
|
return ok(delegations);
|
|
13098
13131
|
} catch (error) {
|
|
13099
13132
|
return err(
|
|
13100
|
-
|
|
13133
|
+
serviceError2(
|
|
13101
13134
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13102
13135
|
`Network error listing received delegations: ${String(error)}`,
|
|
13103
13136
|
SERVICE_NAME
|
|
@@ -13110,7 +13143,7 @@ var SpaceService = class {
|
|
|
13110
13143
|
return self.createDelegationFn({ ...params, spaceId });
|
|
13111
13144
|
}
|
|
13112
13145
|
return err(
|
|
13113
|
-
|
|
13146
|
+
serviceError2(
|
|
13114
13147
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13115
13148
|
"Delegation creation requires a createDelegation function. This should be provided by the platform SDK (web-sdk or node-sdk).",
|
|
13116
13149
|
SERVICE_NAME
|
|
@@ -13131,19 +13164,17 @@ var SpaceService = class {
|
|
|
13131
13164
|
body: JSON.stringify({ cid: cid2, spaceId })
|
|
13132
13165
|
});
|
|
13133
13166
|
if (!response.ok) {
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
13137
|
-
|
|
13138
|
-
|
|
13139
|
-
|
|
13140
|
-
)
|
|
13141
|
-
);
|
|
13167
|
+
return err(await serviceHttpError(
|
|
13168
|
+
response,
|
|
13169
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13170
|
+
"Failed to revoke delegation",
|
|
13171
|
+
SERVICE_NAME
|
|
13172
|
+
));
|
|
13142
13173
|
}
|
|
13143
13174
|
return ok(void 0);
|
|
13144
13175
|
} catch (error) {
|
|
13145
13176
|
return err(
|
|
13146
|
-
|
|
13177
|
+
serviceError2(
|
|
13147
13178
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13148
13179
|
`Network error revoking delegation: ${String(error)}`,
|
|
13149
13180
|
SERVICE_NAME
|
|
@@ -13167,7 +13198,7 @@ var SpaceService = class {
|
|
|
13167
13198
|
const result = await self.sharingService.generate(params);
|
|
13168
13199
|
if (!result.ok) {
|
|
13169
13200
|
return err(
|
|
13170
|
-
|
|
13201
|
+
serviceError2(
|
|
13171
13202
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13172
13203
|
result.error.message || "Failed to generate share link",
|
|
13173
13204
|
SERVICE_NAME
|
|
@@ -13177,7 +13208,7 @@ var SpaceService = class {
|
|
|
13177
13208
|
return ok(result.data);
|
|
13178
13209
|
}
|
|
13179
13210
|
return err(
|
|
13180
|
-
|
|
13211
|
+
serviceError2(
|
|
13181
13212
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13182
13213
|
"SharingService not configured. V2 sharing requires a SharingService instance.",
|
|
13183
13214
|
SERVICE_NAME
|
|
@@ -13186,7 +13217,7 @@ var SpaceService = class {
|
|
|
13186
13217
|
},
|
|
13187
13218
|
async list() {
|
|
13188
13219
|
return err(
|
|
13189
|
-
|
|
13220
|
+
serviceError2(
|
|
13190
13221
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13191
13222
|
"Listing share links is not supported in v2. Share links are self-contained tokens that are not tracked on the server.",
|
|
13192
13223
|
SERVICE_NAME
|
|
@@ -13195,7 +13226,7 @@ var SpaceService = class {
|
|
|
13195
13226
|
},
|
|
13196
13227
|
async revoke(token) {
|
|
13197
13228
|
return err(
|
|
13198
|
-
|
|
13229
|
+
serviceError2(
|
|
13199
13230
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13200
13231
|
"Revoking share links by token is not supported in v2. To revoke access, revoke the underlying delegation using space.delegations.revoke(cid).",
|
|
13201
13232
|
SERVICE_NAME
|
|
@@ -13532,8 +13563,8 @@ var TinyCloud = class _TinyCloud {
|
|
|
13532
13563
|
const chainId = this.chainId();
|
|
13533
13564
|
if (!address || !chainId) {
|
|
13534
13565
|
return err2(
|
|
13535
|
-
|
|
13536
|
-
|
|
13566
|
+
serviceError3(
|
|
13567
|
+
ErrorCodes3.AUTH_REQUIRED,
|
|
13537
13568
|
"Must be signed in to ensure public space",
|
|
13538
13569
|
"public-space"
|
|
13539
13570
|
)
|
|
@@ -13541,8 +13572,8 @@ var TinyCloud = class _TinyCloud {
|
|
|
13541
13572
|
}
|
|
13542
13573
|
if (!this._serviceContext) {
|
|
13543
13574
|
return err2(
|
|
13544
|
-
|
|
13545
|
-
|
|
13575
|
+
serviceError3(
|
|
13576
|
+
ErrorCodes3.AUTH_REQUIRED,
|
|
13546
13577
|
"Services not initialized. Call initializeServices() or signIn() first.",
|
|
13547
13578
|
"public-space"
|
|
13548
13579
|
)
|
|
@@ -13553,8 +13584,8 @@ var TinyCloud = class _TinyCloud {
|
|
|
13553
13584
|
const session = this._serviceContext.session;
|
|
13554
13585
|
if (!session) {
|
|
13555
13586
|
return err2(
|
|
13556
|
-
|
|
13557
|
-
|
|
13587
|
+
serviceError3(
|
|
13588
|
+
ErrorCodes3.AUTH_REQUIRED,
|
|
13558
13589
|
"No active session",
|
|
13559
13590
|
"public-space"
|
|
13560
13591
|
)
|
|
@@ -13592,29 +13623,25 @@ var TinyCloud = class _TinyCloud {
|
|
|
13592
13623
|
if (createResponse.status === 409) {
|
|
13593
13624
|
return ok2(void 0);
|
|
13594
13625
|
}
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
)
|
|
13602
|
-
);
|
|
13626
|
+
return err2(await serviceHttpError(
|
|
13627
|
+
createResponse,
|
|
13628
|
+
ErrorCodes3.NETWORK_ERROR,
|
|
13629
|
+
"Failed to create public space",
|
|
13630
|
+
"public-space"
|
|
13631
|
+
));
|
|
13603
13632
|
}
|
|
13604
13633
|
return ok2(void 0);
|
|
13605
13634
|
}
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
)
|
|
13613
|
-
);
|
|
13635
|
+
return err2(await serviceHttpError(
|
|
13636
|
+
response,
|
|
13637
|
+
ErrorCodes3.NETWORK_ERROR,
|
|
13638
|
+
"Failed to check public space",
|
|
13639
|
+
"public-space"
|
|
13640
|
+
));
|
|
13614
13641
|
} catch (error) {
|
|
13615
13642
|
return err2(
|
|
13616
|
-
|
|
13617
|
-
|
|
13643
|
+
serviceError3(
|
|
13644
|
+
ErrorCodes3.NETWORK_ERROR,
|
|
13618
13645
|
`Network error ensuring public space: ${String(error)}`,
|
|
13619
13646
|
"public-space",
|
|
13620
13647
|
{ cause: error instanceof Error ? error : void 0 }
|
|
@@ -13681,23 +13708,19 @@ var TinyCloud = class _TinyCloud {
|
|
|
13681
13708
|
const response = await doFetch(url, { method: "GET" });
|
|
13682
13709
|
if (!response.ok) {
|
|
13683
13710
|
if (response.status === 404) {
|
|
13684
|
-
return err2(
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
);
|
|
13711
|
+
return err2(await serviceHttpError(
|
|
13712
|
+
response,
|
|
13713
|
+
ErrorCodes3.NOT_FOUND,
|
|
13714
|
+
`Key not found: ${key} in space ${spaceId}`,
|
|
13715
|
+
"public-space"
|
|
13716
|
+
));
|
|
13691
13717
|
}
|
|
13692
|
-
|
|
13693
|
-
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13698
|
-
{ meta: { status: response.status } }
|
|
13699
|
-
)
|
|
13700
|
-
);
|
|
13718
|
+
return err2(await serviceHttpError(
|
|
13719
|
+
response,
|
|
13720
|
+
ErrorCodes3.NETWORK_ERROR,
|
|
13721
|
+
"Failed to read public space",
|
|
13722
|
+
"public-space"
|
|
13723
|
+
));
|
|
13701
13724
|
}
|
|
13702
13725
|
const contentType = response.headers.get("content-type");
|
|
13703
13726
|
let data;
|
|
@@ -13714,8 +13737,8 @@ var TinyCloud = class _TinyCloud {
|
|
|
13714
13737
|
return ok2(data);
|
|
13715
13738
|
} catch (error) {
|
|
13716
13739
|
return err2(
|
|
13717
|
-
|
|
13718
|
-
|
|
13740
|
+
serviceError3(
|
|
13741
|
+
ErrorCodes3.NETWORK_ERROR,
|
|
13719
13742
|
`Network error reading public space: ${String(error)}`,
|
|
13720
13743
|
"public-space",
|
|
13721
13744
|
{ cause: error instanceof Error ? error : void 0 }
|
|
@@ -13744,8 +13767,9 @@ var TinyCloud = class _TinyCloud {
|
|
|
13744
13767
|
import {
|
|
13745
13768
|
err as err3,
|
|
13746
13769
|
ok as ok3,
|
|
13747
|
-
serviceError as
|
|
13748
|
-
ErrorCodes as
|
|
13770
|
+
serviceError as serviceError4,
|
|
13771
|
+
ErrorCodes as ErrorCodes4,
|
|
13772
|
+
isStorageFullError
|
|
13749
13773
|
} from "@tinycloud/sdk-services";
|
|
13750
13774
|
import { ACCOUNT_INDEX_SCHEMA } from "@tinycloud/bootstrap";
|
|
13751
13775
|
var SERVICE_NAME2 = "account";
|
|
@@ -13759,10 +13783,10 @@ var AccountService = class {
|
|
|
13759
13783
|
* Per-account-space memo for {@link ensureAccountIndex}.
|
|
13760
13784
|
*
|
|
13761
13785
|
* Applying the index migration is a no-op once the schema exists, but the
|
|
13762
|
-
* SQL service still spends
|
|
13763
|
-
*
|
|
13764
|
-
*
|
|
13765
|
-
*
|
|
13786
|
+
* SQL service still spends a round trip discovering that (reading the
|
|
13787
|
+
* applied-migration rows). Account bootstrap touches the index eight times,
|
|
13788
|
+
* so without a memo that is ~7 wasted requests on the cold sign-in path.
|
|
13789
|
+
* The in-flight dedupe inside SQLService
|
|
13766
13790
|
* never helps here: the node SDK builds a fresh SQLService per
|
|
13767
13791
|
* `getAccountDb()` call, so its lock map is always empty.
|
|
13768
13792
|
*
|
|
@@ -13809,7 +13833,7 @@ var AccountService = class {
|
|
|
13809
13833
|
const request = composeManifestRequest(manifests);
|
|
13810
13834
|
if (request.registryRecords.length === 0) {
|
|
13811
13835
|
return err3(
|
|
13812
|
-
|
|
13836
|
+
serviceError4(
|
|
13813
13837
|
"INVALID_MANIFEST",
|
|
13814
13838
|
"Manifest did not produce an account application registry record",
|
|
13815
13839
|
SERVICE_NAME2
|
|
@@ -13860,11 +13884,12 @@ var AccountService = class {
|
|
|
13860
13884
|
const indexed = await this.index.spaces.list();
|
|
13861
13885
|
if (indexed.ok && indexed.data.length > 0) return indexed;
|
|
13862
13886
|
if (!indexed.ok && !isMissingIndexError(indexed.error)) return indexed;
|
|
13863
|
-
const canonical = await this.
|
|
13864
|
-
if (canonical.ok
|
|
13865
|
-
|
|
13887
|
+
const canonical = await this.syncAccessibleSpaces({ tolerateStorageFull: true });
|
|
13888
|
+
if (!canonical.ok) return canonical;
|
|
13889
|
+
if (canonical.data.allRegistered && options2.refreshIndex !== false) {
|
|
13890
|
+
await this.replaceSpacesIndexQuietly(canonical.data.spaces);
|
|
13866
13891
|
}
|
|
13867
|
-
return canonical;
|
|
13892
|
+
return ok3(canonical.data.spaces);
|
|
13868
13893
|
}
|
|
13869
13894
|
const kvResult = this.accountKV();
|
|
13870
13895
|
if (!kvResult.ok) return kvResult;
|
|
@@ -13937,7 +13962,7 @@ var AccountService = class {
|
|
|
13937
13962
|
}
|
|
13938
13963
|
if (reconcileFailures.length > 0) {
|
|
13939
13964
|
return err3(
|
|
13940
|
-
|
|
13965
|
+
serviceError4(
|
|
13941
13966
|
"KV_BATCH_RECONCILE_FAILED",
|
|
13942
13967
|
`KV batch write for ${items.length} space(s) failed ambiguously (${batchResult.error.message}) and per-space reconciliation also failed for: ${reconcileFailures.join("; ")}`,
|
|
13943
13968
|
SERVICE_NAME2,
|
|
@@ -13952,15 +13977,8 @@ var AccountService = class {
|
|
|
13952
13977
|
return ok3({ spaces: registered, recoveredFromBatchError: batchResult.error });
|
|
13953
13978
|
},
|
|
13954
13979
|
syncAccessible: async () => {
|
|
13955
|
-
const
|
|
13956
|
-
|
|
13957
|
-
const registered = [];
|
|
13958
|
-
for (const space of listed.data) {
|
|
13959
|
-
const result = await this.spaces.register(space);
|
|
13960
|
-
if (!result.ok) return result;
|
|
13961
|
-
registered.push(result.data);
|
|
13962
|
-
}
|
|
13963
|
-
return ok3(registered);
|
|
13980
|
+
const synced = await this.syncAccessibleSpaces({ tolerateStorageFull: false });
|
|
13981
|
+
return synced.ok ? ok3(synced.data.spaces) : synced;
|
|
13964
13982
|
},
|
|
13965
13983
|
remove: async (spaceId) => {
|
|
13966
13984
|
const kvResult = this.accountKV();
|
|
@@ -13975,7 +13993,7 @@ var AccountService = class {
|
|
|
13975
13993
|
query: async (options2 = {}) => {
|
|
13976
13994
|
const manager = this.config.getDelegationManager?.();
|
|
13977
13995
|
if (!manager) {
|
|
13978
|
-
return err3(
|
|
13996
|
+
return err3(serviceError4(
|
|
13979
13997
|
"NOT_INITIALIZED",
|
|
13980
13998
|
"Delegation history requires an authenticated delegation manager",
|
|
13981
13999
|
SERVICE_NAME2
|
|
@@ -14026,7 +14044,7 @@ var AccountService = class {
|
|
|
14026
14044
|
return revoked2.ok ? ok3(revoked2.data) : accountErr(revoked2.error);
|
|
14027
14045
|
}
|
|
14028
14046
|
if (typeof input === "string") {
|
|
14029
|
-
return err3(
|
|
14047
|
+
return err3(serviceError4(
|
|
14030
14048
|
"NOT_INITIALIZED",
|
|
14031
14049
|
"CID-only revocation requires an authenticated delegation manager",
|
|
14032
14050
|
SERVICE_NAME2
|
|
@@ -14232,7 +14250,7 @@ var AccountService = class {
|
|
|
14232
14250
|
const accountSpaceId = this.config.getAccountSpaceId();
|
|
14233
14251
|
if (!accountSpaceId) {
|
|
14234
14252
|
return err3(
|
|
14235
|
-
|
|
14253
|
+
serviceError4(
|
|
14236
14254
|
"ACCOUNT_SPACE_UNAVAILABLE",
|
|
14237
14255
|
"Account space is unavailable. Sign in with a wallet-backed profile first.",
|
|
14238
14256
|
SERVICE_NAME2
|
|
@@ -14245,7 +14263,7 @@ var AccountService = class {
|
|
|
14245
14263
|
const db = this.config.getAccountDb?.();
|
|
14246
14264
|
if (!db) {
|
|
14247
14265
|
return err3(
|
|
14248
|
-
|
|
14266
|
+
serviceError4(
|
|
14249
14267
|
"ACCOUNT_INDEX_UNAVAILABLE",
|
|
14250
14268
|
"Account index database is unavailable. Sign in with a wallet-backed profile first.",
|
|
14251
14269
|
SERVICE_NAME2
|
|
@@ -14392,13 +14410,41 @@ var AccountService = class {
|
|
|
14392
14410
|
if (!deleted.ok) return accountErr(deleted.error);
|
|
14393
14411
|
return ok3(void 0);
|
|
14394
14412
|
}
|
|
14413
|
+
/**
|
|
14414
|
+
* Register every space the session can reach and return them. With
|
|
14415
|
+
* `tolerateStorageFull`, a full account space stops the registration
|
|
14416
|
+
* writes but not the listing: the remaining spaces are returned as they
|
|
14417
|
+
* would have been registered, and `allRegistered` is false.
|
|
14418
|
+
*/
|
|
14419
|
+
async syncAccessibleSpaces(options2) {
|
|
14420
|
+
const listed = await this.config.getSpaces().list();
|
|
14421
|
+
if (!listed.ok) return accountErr(listed.error);
|
|
14422
|
+
const spaces = [];
|
|
14423
|
+
let allRegistered = true;
|
|
14424
|
+
for (const space of listed.data) {
|
|
14425
|
+
if (allRegistered) {
|
|
14426
|
+
const result = await this.spaces.register(space);
|
|
14427
|
+
if (result.ok) {
|
|
14428
|
+
spaces.push(result.data);
|
|
14429
|
+
continue;
|
|
14430
|
+
}
|
|
14431
|
+
if (!options2.tolerateStorageFull || !isStorageFullError(result.error)) {
|
|
14432
|
+
return result;
|
|
14433
|
+
}
|
|
14434
|
+
allRegistered = false;
|
|
14435
|
+
}
|
|
14436
|
+
const record2 = spaceRecordFromInput(space);
|
|
14437
|
+
spaces.push(spaceFromRecord(spaceKey(record2.space_id), record2));
|
|
14438
|
+
}
|
|
14439
|
+
return ok3({ spaces, allRegistered });
|
|
14440
|
+
}
|
|
14395
14441
|
async resolveSpace(space) {
|
|
14396
14442
|
const listed = await this.config.getSpaces().list();
|
|
14397
14443
|
if (!listed.ok) return accountErr(listed.error);
|
|
14398
14444
|
const found = listed.data.find((candidate) => candidate.id === space || candidate.name === space);
|
|
14399
14445
|
if (!found) {
|
|
14400
14446
|
return err3(
|
|
14401
|
-
|
|
14447
|
+
serviceError4("SPACE_NOT_FOUND", `No account space found for ${JSON.stringify(space)}`, SERVICE_NAME2)
|
|
14402
14448
|
);
|
|
14403
14449
|
}
|
|
14404
14450
|
return ok3(found);
|
|
@@ -14699,17 +14745,17 @@ function mapDelegation(delegation, space, direction) {
|
|
|
14699
14745
|
};
|
|
14700
14746
|
}
|
|
14701
14747
|
function accountErr(error) {
|
|
14702
|
-
return err3(
|
|
14748
|
+
return err3(serviceError4(error.code, error.message, SERVICE_NAME2, { cause: error.cause, meta: error.meta }));
|
|
14703
14749
|
}
|
|
14704
14750
|
function isMissingIndexError(error) {
|
|
14705
14751
|
return /no such table:/i.test(error.message);
|
|
14706
14752
|
}
|
|
14707
14753
|
var AMBIGUOUS_WRITE_STATUSES = /* @__PURE__ */ new Set([500, 502, 503, 504, 520, 522, 524]);
|
|
14708
14754
|
function isAmbiguousBatchFailure(error) {
|
|
14709
|
-
if (error.code ===
|
|
14755
|
+
if (error.code === ErrorCodes4.NETWORK_ERROR || error.code === ErrorCodes4.TIMEOUT) {
|
|
14710
14756
|
return error.meta?.requestMayHaveDispatched === true;
|
|
14711
14757
|
}
|
|
14712
|
-
if (error.code ===
|
|
14758
|
+
if (error.code === ErrorCodes4.KV_WRITE_FAILED) {
|
|
14713
14759
|
const status = error.meta?.status;
|
|
14714
14760
|
return typeof status === "number" && AMBIGUOUS_WRITE_STATUSES.has(status);
|
|
14715
14761
|
}
|
|
@@ -14729,8 +14775,14 @@ import {
|
|
|
14729
14775
|
PrefixedKVService,
|
|
14730
14776
|
ok as ok5,
|
|
14731
14777
|
err as err5,
|
|
14732
|
-
serviceError as
|
|
14733
|
-
ErrorCodes as
|
|
14778
|
+
serviceError as serviceError6,
|
|
14779
|
+
ErrorCodes as ErrorCodes5,
|
|
14780
|
+
authorizationVerdictOf as authorizationVerdictOf2,
|
|
14781
|
+
validatedCapabilityOf,
|
|
14782
|
+
parseCapabilityResource,
|
|
14783
|
+
isStorageFullError as isStorageFullError2,
|
|
14784
|
+
STORAGE_FULL_MESSAGE,
|
|
14785
|
+
STORAGE_WRITE_TOO_LARGE_MESSAGE,
|
|
14734
14786
|
TinyCloudDebugLogger,
|
|
14735
14787
|
tinyCloudDebugLogger,
|
|
14736
14788
|
enableTinyCloudDebug,
|
|
@@ -14806,7 +14858,9 @@ async function fetchPeerId(host, spaceId) {
|
|
|
14806
14858
|
);
|
|
14807
14859
|
if (!res.ok) {
|
|
14808
14860
|
const error = await res.text().catch(() => res.statusText);
|
|
14809
|
-
throw new Error(`Failed to get peer ID: ${res.status} - ${error}`)
|
|
14861
|
+
throw Object.assign(new Error(`Failed to get peer ID: ${res.status} - ${error}`), {
|
|
14862
|
+
status: res.status
|
|
14863
|
+
});
|
|
14810
14864
|
}
|
|
14811
14865
|
return res.text();
|
|
14812
14866
|
}
|
|
@@ -14896,7 +14950,7 @@ async function postSessionActivation(host, delegationHeader) {
|
|
|
14896
14950
|
}
|
|
14897
14951
|
|
|
14898
14952
|
// src/authorization/CapabilityKeyRegistry.ts
|
|
14899
|
-
import { ok as ok4, err as err4, serviceError as
|
|
14953
|
+
import { ok as ok4, err as err4, serviceError as serviceError5 } from "@tinycloud/sdk-services";
|
|
14900
14954
|
var SERVICE_NAME3 = "capability-key-registry";
|
|
14901
14955
|
var CapabilityKeyRegistryErrorCodes = {
|
|
14902
14956
|
/** Key not found in registry */
|
|
@@ -15122,7 +15176,7 @@ var CapabilityKeyRegistry = class {
|
|
|
15122
15176
|
const stored = this.store.byCid.get(cid2);
|
|
15123
15177
|
if (!stored || stored.length === 0) {
|
|
15124
15178
|
return err4(
|
|
15125
|
-
|
|
15179
|
+
serviceError5(
|
|
15126
15180
|
CapabilityKeyRegistryErrorCodes.KEY_NOT_FOUND,
|
|
15127
15181
|
`Delegation not found: ${cid2}`,
|
|
15128
15182
|
SERVICE_NAME3
|
|
@@ -18554,7 +18608,7 @@ export {
|
|
|
18554
18608
|
EXPIRY,
|
|
18555
18609
|
EncryptionService,
|
|
18556
18610
|
EnsDataSchema,
|
|
18557
|
-
|
|
18611
|
+
ErrorCodes5 as ErrorCodes,
|
|
18558
18612
|
HOLDER_BINDING_DOMAIN,
|
|
18559
18613
|
HOLDER_KEY_BINDING_PRESENTATION_SCHEMA,
|
|
18560
18614
|
HOOKS,
|
|
@@ -18627,6 +18681,8 @@ export {
|
|
|
18627
18681
|
SQL,
|
|
18628
18682
|
SQLAction,
|
|
18629
18683
|
SQLService2 as SQLService,
|
|
18684
|
+
STORAGE_FULL_MESSAGE,
|
|
18685
|
+
STORAGE_WRITE_TOO_LARGE_MESSAGE,
|
|
18630
18686
|
SecretsService,
|
|
18631
18687
|
SenderShareStore,
|
|
18632
18688
|
ServiceContext3 as ServiceContext,
|
|
@@ -18677,6 +18733,7 @@ export {
|
|
|
18677
18733
|
admitPolicyCredentialV3,
|
|
18678
18734
|
admitPolicyCredentialV4,
|
|
18679
18735
|
applyPrefix,
|
|
18736
|
+
authorizationVerdictOf2 as authorizationVerdictOf,
|
|
18680
18737
|
bootstrapEncryptionNetworkId,
|
|
18681
18738
|
bootstrapSpaceId,
|
|
18682
18739
|
bootstrapSteps,
|
|
@@ -18789,6 +18846,7 @@ export {
|
|
|
18789
18846
|
hexEncode,
|
|
18790
18847
|
holderBindingCanonicalBytes,
|
|
18791
18848
|
holderBindingSigningBytes,
|
|
18849
|
+
httpResponseError,
|
|
18792
18850
|
httpUrlToMultiaddr,
|
|
18793
18851
|
importPortableDelegation,
|
|
18794
18852
|
installTinyCloudDebugGlobals,
|
|
@@ -18797,8 +18855,10 @@ export {
|
|
|
18797
18855
|
isCapabilitySubset,
|
|
18798
18856
|
isDigest,
|
|
18799
18857
|
isEvmAddress,
|
|
18858
|
+
isExplicitOnlyAction,
|
|
18800
18859
|
isNetworkId,
|
|
18801
18860
|
isPlausibleOpenKeyActionId,
|
|
18861
|
+
isStorageFullError2 as isStorageFullError,
|
|
18802
18862
|
isV2ShareLink,
|
|
18803
18863
|
issuedCredentialEnvelopeFromVerified,
|
|
18804
18864
|
jcsCanonicalize,
|
|
@@ -18822,6 +18882,7 @@ export {
|
|
|
18822
18882
|
parseCanonicalRecapResource,
|
|
18823
18883
|
parseCanonicalTinyCloudIdentity,
|
|
18824
18884
|
parseCanonicalTinyCloudIdentityClaims,
|
|
18885
|
+
parseCapabilityResource,
|
|
18825
18886
|
parseCompactUcanAuthorization,
|
|
18826
18887
|
parseExpiry,
|
|
18827
18888
|
parseNetworkId2 as parseNetworkId,
|
|
@@ -18860,7 +18921,7 @@ export {
|
|
|
18860
18921
|
revokePolicyRootV3,
|
|
18861
18922
|
serialize as serializeJcsJson,
|
|
18862
18923
|
serializePortableDelegation,
|
|
18863
|
-
|
|
18924
|
+
serviceError6 as serviceError,
|
|
18864
18925
|
sha256Base64Url,
|
|
18865
18926
|
shareCapabilityAllows,
|
|
18866
18927
|
signCompactPolicyDescendant,
|
|
@@ -18902,6 +18963,7 @@ export {
|
|
|
18902
18963
|
validatePolicyUnsigned,
|
|
18903
18964
|
validateShareDeliveryAuthorizationV3Bytes,
|
|
18904
18965
|
validateUnifiedPolicyV2,
|
|
18966
|
+
validatedCapabilityOf,
|
|
18905
18967
|
verifyDecryptResponse,
|
|
18906
18968
|
verifyDidKeyEd25519Signature,
|
|
18907
18969
|
verifyEip191MessageSignature,
|