@tinycloud/node-sdk 2.3.0 → 2.3.1-beta.0
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-BdlIWB-K.d.cts → core-D2hPECHW.d.cts} +22 -0
- package/dist/{core-BdlIWB-K.d.ts → core-D2hPECHW.d.ts} +22 -0
- package/dist/core.cjs +54 -20
- 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 +54 -20
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +54 -20
- 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 +54 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20967,6 +20967,59 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20967
20967
|
actions
|
|
20968
20968
|
}));
|
|
20969
20969
|
}
|
|
20970
|
+
/**
|
|
20971
|
+
* Build the abilities/rawAbilities maps for a wallet-mode activation
|
|
20972
|
+
* sub-delegation from the FULL resource set of a received delegation.
|
|
20973
|
+
*
|
|
20974
|
+
* Each entry in `delegation.resources[]` is one `(service, space, path,
|
|
20975
|
+
* actions)` grant; the flat top-level `path`/`actions` mirror only the
|
|
20976
|
+
* first resource. We must reconstruct every grant so the activated
|
|
20977
|
+
* session carries all of them (e.g. both `tinycloud.kv/get` and
|
|
20978
|
+
* `tinycloud.encryption/decrypt`) — not just the primary one.
|
|
20979
|
+
*
|
|
20980
|
+
* Encryption resources are raw network URNs (space-independent) and go
|
|
20981
|
+
* into `rawAbilities`. All other resources are space-scoped and go into
|
|
20982
|
+
* `abilities` keyed by short service name. The activation `prepareSession`
|
|
20983
|
+
* call uses a single `spaceId` (`delegation.spaceId`), so every
|
|
20984
|
+
* non-encryption resource must target that same space — which is exactly
|
|
20985
|
+
* what the multi-resource issuance path enforces. A resource targeting a
|
|
20986
|
+
* different space cannot be activated in one call, so we fail loudly
|
|
20987
|
+
* rather than silently dropping it.
|
|
20988
|
+
*
|
|
20989
|
+
* @internal
|
|
20990
|
+
*/
|
|
20991
|
+
buildActivationAbilities(delegation) {
|
|
20992
|
+
var _a, _b, _c;
|
|
20993
|
+
const resources = delegation.resources !== void 0 && delegation.resources.length > 0 ? delegation.resources : this.flatDelegationResources(delegation);
|
|
20994
|
+
const abilities = {};
|
|
20995
|
+
const rawAbilities = {};
|
|
20996
|
+
const addActions = (target, actions) => {
|
|
20997
|
+
const seen = new Set(target);
|
|
20998
|
+
for (const action of actions) {
|
|
20999
|
+
if (!seen.has(action)) {
|
|
21000
|
+
target.push(action);
|
|
21001
|
+
seen.add(action);
|
|
21002
|
+
}
|
|
21003
|
+
}
|
|
21004
|
+
};
|
|
21005
|
+
for (const resource of resources) {
|
|
21006
|
+
const service = this.invocationServiceName(resource.service);
|
|
21007
|
+
if (this.isEncryptionNetworkOperation(service, resource.path)) {
|
|
21008
|
+
rawAbilities[_a = resource.path] ?? (rawAbilities[_a] = []);
|
|
21009
|
+
addActions(rawAbilities[resource.path], resource.actions);
|
|
21010
|
+
continue;
|
|
21011
|
+
}
|
|
21012
|
+
if (resource.space !== delegation.spaceId) {
|
|
21013
|
+
throw new Error(
|
|
21014
|
+
`useDelegation: resource targets space '${resource.space}' but the delegation activates space '${delegation.spaceId}'. Multi-space delegations cannot be activated in a single useDelegation call.`
|
|
21015
|
+
);
|
|
21016
|
+
}
|
|
21017
|
+
abilities[service] ?? (abilities[service] = {});
|
|
21018
|
+
(_b = abilities[service])[_c = resource.path] ?? (_b[_c] = []);
|
|
21019
|
+
addActions(abilities[service][resource.path], resource.actions);
|
|
21020
|
+
}
|
|
21021
|
+
return { abilities, rawAbilities };
|
|
21022
|
+
}
|
|
20970
21023
|
selectInvocationSession(fallback, service, path, action) {
|
|
20971
21024
|
const grant = this.findGrantForOperation({
|
|
20972
21025
|
spaceId: fallback.spaceId,
|
|
@@ -21313,26 +21366,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21313
21366
|
throw new Error("Not signed in. Call signIn() first.");
|
|
21314
21367
|
}
|
|
21315
21368
|
const jwk = mySession.jwk;
|
|
21316
|
-
const abilities =
|
|
21317
|
-
const kvActions = delegation.actions.filter((a) => a.startsWith("tinycloud.kv/"));
|
|
21318
|
-
const sqlActions = delegation.actions.filter((a) => a.startsWith("tinycloud.sql/"));
|
|
21319
|
-
const duckdbActions = delegation.actions.filter((a) => a.startsWith("tinycloud.duckdb/"));
|
|
21320
|
-
const encryptionActions = delegation.actions.filter(
|
|
21321
|
-
(a) => a.startsWith("tinycloud.encryption/")
|
|
21322
|
-
);
|
|
21323
|
-
const rawAbilities = {};
|
|
21324
|
-
if (kvActions.length > 0) {
|
|
21325
|
-
abilities.kv = { [delegation.path]: kvActions };
|
|
21326
|
-
}
|
|
21327
|
-
if (sqlActions.length > 0) {
|
|
21328
|
-
abilities.sql = { [delegation.path]: sqlActions };
|
|
21329
|
-
}
|
|
21330
|
-
if (duckdbActions.length > 0) {
|
|
21331
|
-
abilities.duckdb = { [delegation.path]: duckdbActions };
|
|
21332
|
-
}
|
|
21333
|
-
if (encryptionActions.length > 0 && delegation.path.startsWith("urn:tinycloud:encryption:")) {
|
|
21334
|
-
rawAbilities[delegation.path] = encryptionActions;
|
|
21335
|
-
}
|
|
21369
|
+
const { abilities, rawAbilities } = this.buildActivationAbilities(delegation);
|
|
21336
21370
|
const now = /* @__PURE__ */ new Date();
|
|
21337
21371
|
const maxExpiry = new Date(now.getTime() + 60 * 60 * 1e3);
|
|
21338
21372
|
const expirationTime = delegation.expiry < maxExpiry ? delegation.expiry : maxExpiry;
|