@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
|
@@ -1507,8 +1507,17 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
1507
1507
|
}
|
|
1508
1508
|
return `[${branches.join(",")}]`;
|
|
1509
1509
|
}
|
|
1510
|
+
var EXPLICIT_ONLY_ACTIONS = {
|
|
1511
|
+
"tinycloud.kv/sync": true,
|
|
1512
|
+
"tinycloud.kv/retain": true
|
|
1513
|
+
};
|
|
1514
|
+
function isExplicitOnlyAction(action) {
|
|
1515
|
+
return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
|
|
1516
|
+
}
|
|
1510
1517
|
function actionContains(grantedAction, requestedAction) {
|
|
1511
|
-
if (grantedAction ===
|
|
1518
|
+
if (grantedAction === requestedAction) return true;
|
|
1519
|
+
if (isExplicitOnlyAction(requestedAction)) return false;
|
|
1520
|
+
if (grantedAction === "*") return true;
|
|
1512
1521
|
if (!grantedAction.endsWith("/*")) return false;
|
|
1513
1522
|
const service = grantedAction.slice(0, -2);
|
|
1514
1523
|
return requestedAction === service || requestedAction.startsWith(`${service}/`);
|
|
@@ -2681,7 +2690,7 @@ var hashes = { ...sha2_browser_exports, ...identity_exports2 };
|
|
|
2681
2690
|
var import_ed255194 = require("@noble/curves/ed25519");
|
|
2682
2691
|
|
|
2683
2692
|
// src/delegations/ShareRecipientClient.ts
|
|
2684
|
-
var
|
|
2693
|
+
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
2685
2694
|
var import_ed255193 = require("@noble/curves/ed25519");
|
|
2686
2695
|
var import_sha2564 = require("@noble/hashes/sha256");
|
|
2687
2696
|
|
|
@@ -3959,6 +3968,21 @@ function assertUnicodeScalarString(value, path) {
|
|
|
3959
3968
|
}
|
|
3960
3969
|
}
|
|
3961
3970
|
|
|
3971
|
+
// src/http-error.ts
|
|
3972
|
+
var import_sdk_services2 = require("@tinycloud/sdk-services");
|
|
3973
|
+
async function httpResponseError(response, context) {
|
|
3974
|
+
let body;
|
|
3975
|
+
try {
|
|
3976
|
+
body = await response.text();
|
|
3977
|
+
} catch {
|
|
3978
|
+
body = response.statusText;
|
|
3979
|
+
}
|
|
3980
|
+
body = body.trim().slice(0, 512);
|
|
3981
|
+
return Object.assign(new Error(`${context}: HTTP ${response.status}${body ? ` - ${body}` : ""}`), {
|
|
3982
|
+
status: response.status
|
|
3983
|
+
});
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3962
3986
|
// src/policy/unified.ts
|
|
3963
3987
|
var POLICY_SESSION_UCAN_V1_PROFILE = "policy-session-ucan/v1";
|
|
3964
3988
|
var POLICY_SESSION_FACT_KEYS = [
|
|
@@ -4223,7 +4247,7 @@ async function importPortableDelegation(fetchFn, host, delegation) {
|
|
|
4223
4247
|
headers: { Authorization: parsed.delegationHeader.Authorization }
|
|
4224
4248
|
});
|
|
4225
4249
|
if (!response.ok)
|
|
4226
|
-
throw
|
|
4250
|
+
throw await httpResponseError(response, "node rejected delegation import");
|
|
4227
4251
|
const body = await response.json().catch(() => ({}));
|
|
4228
4252
|
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
4229
4253
|
return {};
|
|
@@ -4292,7 +4316,7 @@ function redactedCode(error) {
|
|
|
4292
4316
|
if (error instanceof ShareConflict) return error.code;
|
|
4293
4317
|
const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
|
|
4294
4318
|
if (typeof code3 !== "string") return "SHARE_INVALID";
|
|
4295
|
-
if (code3 ===
|
|
4319
|
+
if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === import_sdk_services3.ErrorCodes.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
|
|
4296
4320
|
if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
|
|
4297
4321
|
if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
|
|
4298
4322
|
if (code3.includes("REVOK")) return "SHARE_REVOKED";
|
|
@@ -4531,7 +4555,7 @@ var ShareRecipientClient = class {
|
|
|
4531
4555
|
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
4532
4556
|
const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
4533
4557
|
if (!result2.ok) {
|
|
4534
|
-
if (result2.error.code ===
|
|
4558
|
+
if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
|
|
4535
4559
|
throw result2.error;
|
|
4536
4560
|
}
|
|
4537
4561
|
return { etag: result2.data.headers.etag };
|
|
@@ -4539,7 +4563,7 @@ var ShareRecipientClient = class {
|
|
|
4539
4563
|
if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
|
|
4540
4564
|
const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
4541
4565
|
if (!result.ok) {
|
|
4542
|
-
if (result.error.code ===
|
|
4566
|
+
if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
|
|
4543
4567
|
throw result.error;
|
|
4544
4568
|
}
|
|
4545
4569
|
return { etag: result.data.headers.etag };
|
|
@@ -4623,8 +4647,8 @@ var ShareRecipientClient = class {
|
|
|
4623
4647
|
if (this.options.createKVService !== void 0) {
|
|
4624
4648
|
return this.options.createKVService({ hosts: [origin], session, invoke, fetch: this.fetchFn });
|
|
4625
4649
|
}
|
|
4626
|
-
const context = new
|
|
4627
|
-
const service = new
|
|
4650
|
+
const context = new import_sdk_services3.ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
|
|
4651
|
+
const service = new import_sdk_services3.KVService({ prefix: "" });
|
|
4628
4652
|
context.registerService("kv", service);
|
|
4629
4653
|
service.initialize(context);
|
|
4630
4654
|
return service;
|
|
@@ -5725,7 +5749,9 @@ var SharingService = class {
|
|
|
5725
5749
|
if (delegation.allowSubDelegation === false) continue;
|
|
5726
5750
|
if (!this.pathMatches(delegation.path || "", path)) continue;
|
|
5727
5751
|
const delegationActions = delegation.actions || [];
|
|
5728
|
-
if (!actions.every(
|
|
5752
|
+
if (!actions.every(
|
|
5753
|
+
(action) => delegationActions.some((granted) => actionContains(granted, action))
|
|
5754
|
+
)) {
|
|
5729
5755
|
continue;
|
|
5730
5756
|
}
|
|
5731
5757
|
if ((delegation.caveats?.length ?? 0) > 0) {
|