@tinycloud/node-sdk 2.3.1-beta.0 → 2.4.0-beta.2
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/{core-D2hPECHW.d.cts → core-BucTrpWH.d.cts} +86 -2
- package/dist/{core-D2hPECHW.d.ts → core-BucTrpWH.d.ts} +86 -2
- package/dist/core.cjs +46 -0
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +46 -0
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +74 -0
- 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 +73 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -17126,6 +17126,7 @@ __export(index_exports, {
|
|
|
17126
17126
|
expandPermissionEntries: () => import_sdk_core9.expandPermissionEntries,
|
|
17127
17127
|
expandPermissionEntry: () => import_sdk_core9.expandPermissionEntry,
|
|
17128
17128
|
generateRandomReceiverKey: () => import_sdk_core14.generateRandomReceiverKey,
|
|
17129
|
+
grantAuthRequest: () => grantAuthRequest,
|
|
17129
17130
|
hexDecode: () => import_sdk_core14.hexDecode,
|
|
17130
17131
|
hexEncode: () => import_sdk_core14.hexEncode,
|
|
17131
17132
|
isCapabilitySubset: () => import_sdk_core9.isCapabilitySubset,
|
|
@@ -18987,6 +18988,52 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18987
18988
|
);
|
|
18988
18989
|
}
|
|
18989
18990
|
}
|
|
18991
|
+
/**
|
|
18992
|
+
* Host one of this user's owned spaces by name (e.g. `"applications"`).
|
|
18993
|
+
*
|
|
18994
|
+
* Resolves the name to the owned space URI
|
|
18995
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and registers it on the
|
|
18996
|
+
* server via the host-SIWE delegation flow, so subsequent KV/SQL writes to
|
|
18997
|
+
* that space succeed instead of returning `404 - Space not found`. The
|
|
18998
|
+
* caller is the root authority of their own owned spaces, so no additional
|
|
18999
|
+
* delegation is required.
|
|
19000
|
+
*
|
|
19001
|
+
* Unlike {@link ensureOwnedSpaceHosted}, this always submits the host
|
|
19002
|
+
* delegation rather than inferring hosting from session activation: a space
|
|
19003
|
+
* the current session has never referenced is reported neither as
|
|
19004
|
+
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
19005
|
+
* skip the host. The host SIWE is idempotent server-side, so re-hosting an
|
|
19006
|
+
* existing space is a safe no-op. Must be called after {@link signIn}.
|
|
19007
|
+
*
|
|
19008
|
+
* @param name - The owned space name (e.g. `"applications"`).
|
|
19009
|
+
* @returns The hosted space URI.
|
|
19010
|
+
*/
|
|
19011
|
+
async hostOwnedSpace(name) {
|
|
19012
|
+
if (!this.auth || !this.auth.tinyCloudSession) {
|
|
19013
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
19014
|
+
}
|
|
19015
|
+
const spaceId = this.ownedSpaceId(name);
|
|
19016
|
+
const host = this.hosts[0] ?? this.config.host;
|
|
19017
|
+
if (!host) {
|
|
19018
|
+
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
19019
|
+
}
|
|
19020
|
+
const hosted = await this.auth.hostOwnedSpace(
|
|
19021
|
+
spaceId
|
|
19022
|
+
);
|
|
19023
|
+
if (!hosted) {
|
|
19024
|
+
throw new Error(`Failed to host owned space: ${spaceId}`);
|
|
19025
|
+
}
|
|
19026
|
+
const activation = await (0, import_sdk_core5.activateSessionWithHost)(
|
|
19027
|
+
host,
|
|
19028
|
+
this.auth.tinyCloudSession.delegationHeader
|
|
19029
|
+
);
|
|
19030
|
+
if (!activation.success || activation.skipped?.includes(spaceId)) {
|
|
19031
|
+
throw new Error(
|
|
19032
|
+
`Failed to activate session for owned space ${spaceId}: ${activation.error ?? "space was skipped"}`
|
|
19033
|
+
);
|
|
19034
|
+
}
|
|
19035
|
+
return spaceId;
|
|
19036
|
+
}
|
|
18990
19037
|
/**
|
|
18991
19038
|
* Restore a previously established session from stored delegation data.
|
|
18992
19039
|
*
|
|
@@ -21662,6 +21709,32 @@ var FileSessionStorage = class {
|
|
|
21662
21709
|
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
21663
21710
|
|
|
21664
21711
|
// src/delegation.ts
|
|
21712
|
+
async function grantAuthRequest(authority, request, options) {
|
|
21713
|
+
if (request.kind !== "tinycloud.auth.request") {
|
|
21714
|
+
throw new Error(
|
|
21715
|
+
`grantAuthRequest expects a tinycloud.auth.request artifact, got "${request.kind}".`
|
|
21716
|
+
);
|
|
21717
|
+
}
|
|
21718
|
+
if (!Array.isArray(request.requested) || request.requested.length === 0) {
|
|
21719
|
+
throw new Error("grantAuthRequest request has no requested capabilities.");
|
|
21720
|
+
}
|
|
21721
|
+
const expiry = options?.expiry ?? request.requestedExpiry;
|
|
21722
|
+
const result = await authority.delegateTo(
|
|
21723
|
+
request.sessionDid,
|
|
21724
|
+
request.requested,
|
|
21725
|
+
expiry !== void 0 ? { expiry } : void 0
|
|
21726
|
+
);
|
|
21727
|
+
return {
|
|
21728
|
+
kind: "tinycloud.auth.delegation",
|
|
21729
|
+
version: 1,
|
|
21730
|
+
requestId: request.requestId,
|
|
21731
|
+
delegationCid: result.delegation.cid,
|
|
21732
|
+
delegation: result.delegation,
|
|
21733
|
+
permissions: request.requested,
|
|
21734
|
+
expiry: result.delegation.expiry.toISOString(),
|
|
21735
|
+
prompted: result.prompted
|
|
21736
|
+
};
|
|
21737
|
+
}
|
|
21665
21738
|
function serializeDelegation(delegation) {
|
|
21666
21739
|
return JSON.stringify({
|
|
21667
21740
|
...delegation,
|
|
@@ -21792,6 +21865,7 @@ var import_sdk_core20 = require("@tinycloud/sdk-core");
|
|
|
21792
21865
|
expandPermissionEntries,
|
|
21793
21866
|
expandPermissionEntry,
|
|
21794
21867
|
generateRandomReceiverKey,
|
|
21868
|
+
grantAuthRequest,
|
|
21795
21869
|
hexDecode,
|
|
21796
21870
|
hexEncode,
|
|
21797
21871
|
isCapabilitySubset,
|