@tinycloud/node-sdk 3.5.0-beta.0 → 3.5.0-beta.1
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.cjs +40 -7
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +52 -15
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +40 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20811,6 +20811,16 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
20811
20811
|
return entries;
|
|
20812
20812
|
}
|
|
20813
20813
|
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core7.EXPIRY.SESSION_MS;
|
|
20814
|
+
var SHARE_NETWORK_NAME_RE = /^share-[a-z0-9][a-z0-9-]{15,35}$/;
|
|
20815
|
+
function grantsCappedDecrypt(path, actions) {
|
|
20816
|
+
if (!actions.some((action) => (0, import_sdk_core7.actionContains)(action, import_sdk_core7.ENCRYPTION.DECRYPT))) {
|
|
20817
|
+
return false;
|
|
20818
|
+
}
|
|
20819
|
+
return !((0, import_sdk_core7.isNetworkId)(path) && SHARE_NETWORK_NAME_RE.test((0, import_sdk_core7.parseNetworkId)(path).name));
|
|
20820
|
+
}
|
|
20821
|
+
function includesDecrypt(entries) {
|
|
20822
|
+
return entries.some((entry) => grantsCappedDecrypt(entry.path, entry.actions));
|
|
20823
|
+
}
|
|
20814
20824
|
function resolveExpiryMs(expiry) {
|
|
20815
20825
|
if (expiry === void 0) {
|
|
20816
20826
|
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
@@ -20978,6 +20988,15 @@ var NodeSecretsService = class {
|
|
|
20978
20988
|
if (this.hasPermission(permissionEntries)) {
|
|
20979
20989
|
return ok();
|
|
20980
20990
|
}
|
|
20991
|
+
let escalation;
|
|
20992
|
+
try {
|
|
20993
|
+
escalation = this.config.uncoveredEntries?.(permissionEntries) ?? permissionEntries;
|
|
20994
|
+
} catch (error) {
|
|
20995
|
+
return this.escalationError(action, target, error);
|
|
20996
|
+
}
|
|
20997
|
+
if (this.config.uncoveredEntries !== void 0 && escalation.length === 0) {
|
|
20998
|
+
return ok();
|
|
20999
|
+
}
|
|
20981
21000
|
if (!this.config.canEscalate()) {
|
|
20982
21001
|
return secretsError(
|
|
20983
21002
|
import_sdk_core8.ErrorCodes.PERMISSION_DENIED,
|
|
@@ -20985,16 +21004,20 @@ var NodeSecretsService = class {
|
|
|
20985
21004
|
);
|
|
20986
21005
|
}
|
|
20987
21006
|
try {
|
|
20988
|
-
|
|
21007
|
+
const grant = action === "get" && this.config.grantGetPermissions !== void 0 ? this.config.grantGetPermissions : this.config.grantPermissions;
|
|
21008
|
+
await grant(escalation);
|
|
20989
21009
|
return this.restoreUnlockAfterEscalation();
|
|
20990
21010
|
} catch (error) {
|
|
20991
|
-
return
|
|
20992
|
-
import_sdk_core8.ErrorCodes.PERMISSION_DENIED,
|
|
20993
|
-
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
20994
|
-
error instanceof Error ? error : void 0
|
|
20995
|
-
);
|
|
21011
|
+
return this.escalationError(action, target, error);
|
|
20996
21012
|
}
|
|
20997
21013
|
}
|
|
21014
|
+
escalationError(action, target, error) {
|
|
21015
|
+
return secretsError(
|
|
21016
|
+
import_sdk_core8.ErrorCodes.PERMISSION_DENIED,
|
|
21017
|
+
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
21018
|
+
error instanceof Error ? error : void 0
|
|
21019
|
+
);
|
|
21020
|
+
}
|
|
20998
21021
|
async restoreUnlockAfterEscalation() {
|
|
20999
21022
|
if (!this.shouldRestoreUnlock) {
|
|
21000
21023
|
return ok();
|
|
@@ -21400,6 +21423,8 @@ function ownerPermissionsToAbilities(permissions) {
|
|
|
21400
21423
|
return { abilities, rawAbilities };
|
|
21401
21424
|
}
|
|
21402
21425
|
var TERMINAL_DELEGATION_REQUIRES_SESSION_KEY = "disableSubDelegation requires a session-key delegation to a did:key (not did:pkh); use the session-key DID or drop the flag";
|
|
21426
|
+
var DECRYPT_GRANT_MAX_EXPIRY_MS = 60 * 60 * 1e3;
|
|
21427
|
+
var SECRET_GET_GRANT_EXPIRY_MS = 59 * 60 * 1e3;
|
|
21403
21428
|
function base64UrlEncode(bytes) {
|
|
21404
21429
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
21405
21430
|
let output = "";
|
|
@@ -25522,6 +25547,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
25522
25547
|
getManifest: () => this.manifest,
|
|
25523
25548
|
hasPermissions: (permissions) => this.hasRuntimePermissions(permissions),
|
|
25524
25549
|
grantPermissions: (additional) => this.grantRuntimePermissions(additional),
|
|
25550
|
+
grantGetPermissions: (additional) => this.grantRuntimePermissions(additional, { expiry: SECRET_GET_GRANT_EXPIRY_MS }),
|
|
25551
|
+
uncoveredEntries: (permissions) => permissions.filter((entry) => !this.hasRuntimePermissions([entry])),
|
|
25525
25552
|
canEscalate: () => this.signer !== void 0 && this.tc !== void 0,
|
|
25526
25553
|
getEncryptionNetworkId: () => this.getEncryptionNetworkIdForSpace(resolvedSpace),
|
|
25527
25554
|
resolveSpace: (space) => space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space),
|
|
@@ -25869,6 +25896,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
25869
25896
|
}
|
|
25870
25897
|
}
|
|
25871
25898
|
const expanded = this.expandPermissionEntries(permissions);
|
|
25899
|
+
const requestsDecrypt = includesDecrypt(expanded);
|
|
25900
|
+
const requestedExpiryMs = requestsDecrypt && options?.expiry === void 0 ? DECRYPT_GRANT_MAX_EXPIRY_MS : resolveExpiryMs(options?.expiry);
|
|
25901
|
+
if (requestsDecrypt && requestedExpiryMs > DECRYPT_GRANT_MAX_EXPIRY_MS) {
|
|
25902
|
+
throw Object.assign(new Error("decrypt grants last at most one hour"), {
|
|
25903
|
+
code: "DECRYPT_EXPIRY_TOO_LONG"
|
|
25904
|
+
});
|
|
25905
|
+
}
|
|
25872
25906
|
if (this.sessionCoversPermissionEntries(session, expanded)) {
|
|
25873
25907
|
return [];
|
|
25874
25908
|
}
|
|
@@ -25899,7 +25933,6 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
25899
25933
|
bySpace.set(session.spaceId, []);
|
|
25900
25934
|
}
|
|
25901
25935
|
const now = /* @__PURE__ */ new Date();
|
|
25902
|
-
const requestedExpiryMs = resolveExpiryMs(options?.expiry);
|
|
25903
25936
|
let expiresAt = new Date(now.getTime() + requestedExpiryMs);
|
|
25904
25937
|
if (sessionExpiry !== void 0 && sessionExpiry < expiresAt) {
|
|
25905
25938
|
expiresAt = sessionExpiry;
|