@tinycloud/node-sdk 2.2.0-beta.6 → 2.2.0-beta.7
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-DdMPUB5s.d.cts → core-C3s0bgRe.d.cts} +14 -1
- package/dist/{core-DdMPUB5s.d.ts → core-C3s0bgRe.d.ts} +14 -1
- package/dist/core.cjs +348 -155
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +254 -58
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +351 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +255 -58
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/core.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
|
|
2
|
-
export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-
|
|
1
|
+
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
|
|
2
|
+
export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-C3s0bgRe.cjs';
|
|
3
3
|
import 'events';
|
|
4
4
|
import '@tinycloud/sdk-services';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
|
|
2
|
-
export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-
|
|
1
|
+
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
|
|
2
|
+
export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-C3s0bgRe.js';
|
|
3
3
|
import 'events';
|
|
4
4
|
import '@tinycloud/sdk-services';
|
package/dist/core.js
CHANGED
|
@@ -959,6 +959,7 @@ import {
|
|
|
959
959
|
DuckDbService as DuckDbService2,
|
|
960
960
|
HooksService as HooksService2,
|
|
961
961
|
DataVaultService,
|
|
962
|
+
SecretsService,
|
|
962
963
|
createVaultCrypto,
|
|
963
964
|
ServiceContext as ServiceContext2,
|
|
964
965
|
SilentNotificationHandler,
|
|
@@ -1217,6 +1218,179 @@ function extractSiweExpiration(siwe) {
|
|
|
1217
1218
|
return d;
|
|
1218
1219
|
}
|
|
1219
1220
|
|
|
1221
|
+
// src/NodeSecretsService.ts
|
|
1222
|
+
import {
|
|
1223
|
+
ErrorCodes,
|
|
1224
|
+
resolveManifest
|
|
1225
|
+
} from "@tinycloud/sdk-core";
|
|
1226
|
+
var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
1227
|
+
var SECRET_PREFIX = "secrets/";
|
|
1228
|
+
var SECRETS_SPACE = "secrets";
|
|
1229
|
+
function ok() {
|
|
1230
|
+
return { ok: true, data: void 0 };
|
|
1231
|
+
}
|
|
1232
|
+
function secretsError(code, message, cause) {
|
|
1233
|
+
return {
|
|
1234
|
+
ok: false,
|
|
1235
|
+
error: {
|
|
1236
|
+
code,
|
|
1237
|
+
service: "secrets",
|
|
1238
|
+
message,
|
|
1239
|
+
...cause ? { cause } : {}
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
function actionUrn(action) {
|
|
1244
|
+
return `tinycloud.kv/${action}`;
|
|
1245
|
+
}
|
|
1246
|
+
function secretResourcePath(base, name) {
|
|
1247
|
+
return `${base}/${SECRET_PREFIX}${name}`;
|
|
1248
|
+
}
|
|
1249
|
+
function secretPermissionEntries(name, action) {
|
|
1250
|
+
return [
|
|
1251
|
+
{
|
|
1252
|
+
service: "tinycloud.kv",
|
|
1253
|
+
space: SECRETS_SPACE,
|
|
1254
|
+
path: secretResourcePath("keys", name),
|
|
1255
|
+
actions: [action],
|
|
1256
|
+
skipPrefix: true
|
|
1257
|
+
},
|
|
1258
|
+
{
|
|
1259
|
+
service: "tinycloud.kv",
|
|
1260
|
+
space: SECRETS_SPACE,
|
|
1261
|
+
path: secretResourcePath("vault", name),
|
|
1262
|
+
actions: [action],
|
|
1263
|
+
skipPrefix: true
|
|
1264
|
+
}
|
|
1265
|
+
];
|
|
1266
|
+
}
|
|
1267
|
+
function isSecretsSpace(space) {
|
|
1268
|
+
return space === SECRETS_SPACE || space.endsWith(`:${SECRETS_SPACE}`);
|
|
1269
|
+
}
|
|
1270
|
+
function composeEscalatedManifest(manifest, additional) {
|
|
1271
|
+
if (Array.isArray(manifest)) {
|
|
1272
|
+
const [primary, ...rest] = manifest;
|
|
1273
|
+
return [
|
|
1274
|
+
{
|
|
1275
|
+
...primary,
|
|
1276
|
+
permissions: [...primary.permissions ?? [], ...additional]
|
|
1277
|
+
},
|
|
1278
|
+
...rest
|
|
1279
|
+
];
|
|
1280
|
+
}
|
|
1281
|
+
return {
|
|
1282
|
+
...manifest,
|
|
1283
|
+
permissions: [...manifest.permissions ?? [], ...additional]
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
var NodeSecretsService = class {
|
|
1287
|
+
constructor(config) {
|
|
1288
|
+
this.config = config;
|
|
1289
|
+
this.shouldRestoreUnlock = false;
|
|
1290
|
+
}
|
|
1291
|
+
get vault() {
|
|
1292
|
+
return this.service.vault;
|
|
1293
|
+
}
|
|
1294
|
+
get isUnlocked() {
|
|
1295
|
+
return this.service.isUnlocked;
|
|
1296
|
+
}
|
|
1297
|
+
async unlock(signer) {
|
|
1298
|
+
if (signer !== void 0) {
|
|
1299
|
+
this.unlockSigner = signer;
|
|
1300
|
+
}
|
|
1301
|
+
const result = await this.service.unlock(signer);
|
|
1302
|
+
if (result.ok) {
|
|
1303
|
+
this.shouldRestoreUnlock = true;
|
|
1304
|
+
}
|
|
1305
|
+
return result;
|
|
1306
|
+
}
|
|
1307
|
+
lock() {
|
|
1308
|
+
this.shouldRestoreUnlock = false;
|
|
1309
|
+
this.service.lock();
|
|
1310
|
+
}
|
|
1311
|
+
get(name) {
|
|
1312
|
+
return this.service.get(name);
|
|
1313
|
+
}
|
|
1314
|
+
async put(name, value) {
|
|
1315
|
+
const permission = await this.ensureMutationPermission(name, "put");
|
|
1316
|
+
if (!permission.ok) return permission;
|
|
1317
|
+
return this.service.put(name, value);
|
|
1318
|
+
}
|
|
1319
|
+
async delete(name) {
|
|
1320
|
+
const permission = await this.ensureMutationPermission(name, "del");
|
|
1321
|
+
if (!permission.ok) return permission;
|
|
1322
|
+
return this.service.delete(name);
|
|
1323
|
+
}
|
|
1324
|
+
list() {
|
|
1325
|
+
return this.service.list();
|
|
1326
|
+
}
|
|
1327
|
+
get service() {
|
|
1328
|
+
return this.config.getService();
|
|
1329
|
+
}
|
|
1330
|
+
async ensureMutationPermission(name, action) {
|
|
1331
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
1332
|
+
return secretsError(
|
|
1333
|
+
ErrorCodes.INVALID_INPUT,
|
|
1334
|
+
`Invalid secret name ${JSON.stringify(name)}. Secret names must match ${SECRET_NAME_RE.source}.`
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
if (this.hasMutationPermission(name, action)) {
|
|
1338
|
+
return ok();
|
|
1339
|
+
}
|
|
1340
|
+
if (!this.config.canEscalate()) {
|
|
1341
|
+
return secretsError(
|
|
1342
|
+
ErrorCodes.PERMISSION_DENIED,
|
|
1343
|
+
`Cannot autosign ${actionUrn(action)} for ${name}; TinyCloudNode needs wallet mode with a signer or privateKey.`
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
const manifest = this.config.getManifest();
|
|
1347
|
+
if (manifest === void 0) {
|
|
1348
|
+
return secretsError(
|
|
1349
|
+
ErrorCodes.PERMISSION_DENIED,
|
|
1350
|
+
`Cannot autosign ${actionUrn(action)} for ${name}; set a manifest before mutating secrets.`
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
try {
|
|
1354
|
+
this.config.setManifest(
|
|
1355
|
+
composeEscalatedManifest(
|
|
1356
|
+
manifest,
|
|
1357
|
+
secretPermissionEntries(name, action)
|
|
1358
|
+
)
|
|
1359
|
+
);
|
|
1360
|
+
await this.config.signIn();
|
|
1361
|
+
return this.restoreUnlockAfterEscalation();
|
|
1362
|
+
} catch (error) {
|
|
1363
|
+
return secretsError(
|
|
1364
|
+
ErrorCodes.PERMISSION_DENIED,
|
|
1365
|
+
error instanceof Error ? error.message : `Autosign escalation for ${actionUrn(action)} on ${name} failed.`,
|
|
1366
|
+
error instanceof Error ? error : void 0
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
async restoreUnlockAfterEscalation() {
|
|
1371
|
+
if (!this.shouldRestoreUnlock) {
|
|
1372
|
+
return ok();
|
|
1373
|
+
}
|
|
1374
|
+
return this.service.unlock(this.unlockSigner);
|
|
1375
|
+
}
|
|
1376
|
+
hasMutationPermission(name, action) {
|
|
1377
|
+
const manifest = this.config.getManifest();
|
|
1378
|
+
if (manifest === void 0) {
|
|
1379
|
+
return false;
|
|
1380
|
+
}
|
|
1381
|
+
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
1382
|
+
const requiredAction = actionUrn(action);
|
|
1383
|
+
return manifests.some((entry) => {
|
|
1384
|
+
const resolved = resolveManifest(entry);
|
|
1385
|
+
return ["keys", "vault"].every(
|
|
1386
|
+
(base) => resolved.resources.some(
|
|
1387
|
+
(resource) => resource.service === "tinycloud.kv" && isSecretsSpace(resource.space) && resource.path === secretResourcePath(base, name) && resource.actions.includes(requiredAction)
|
|
1388
|
+
)
|
|
1389
|
+
);
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1220
1394
|
// src/TinyCloudNode.ts
|
|
1221
1395
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
1222
1396
|
var _TinyCloudNode = class _TinyCloudNode {
|
|
@@ -1471,6 +1645,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1471
1645
|
this._sql = void 0;
|
|
1472
1646
|
this._duckdb = void 0;
|
|
1473
1647
|
this._hooks = void 0;
|
|
1648
|
+
this._vault = void 0;
|
|
1649
|
+
this._baseSecrets = void 0;
|
|
1650
|
+
this._secrets = void 0;
|
|
1651
|
+
this._spaceService = void 0;
|
|
1474
1652
|
this._serviceContext = void 0;
|
|
1475
1653
|
await this.tc.signIn(options);
|
|
1476
1654
|
this.syncResolvedHostFromAuth();
|
|
@@ -1556,6 +1734,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1556
1734
|
this._sql = void 0;
|
|
1557
1735
|
this._duckdb = void 0;
|
|
1558
1736
|
this._hooks = void 0;
|
|
1737
|
+
this._vault = void 0;
|
|
1738
|
+
this._baseSecrets = void 0;
|
|
1739
|
+
this._secrets = void 0;
|
|
1740
|
+
this._spaceService = void 0;
|
|
1559
1741
|
this._serviceContext = void 0;
|
|
1560
1742
|
if (sessionData.address) {
|
|
1561
1743
|
this._address = sessionData.address;
|
|
@@ -1589,41 +1771,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1589
1771
|
jwk: sessionData.jwk
|
|
1590
1772
|
};
|
|
1591
1773
|
this._serviceContext.setSession(serviceSession);
|
|
1592
|
-
|
|
1593
|
-
const vaultCrypto = createVaultCrypto({
|
|
1594
|
-
vault_encrypt: wasm.vault_encrypt,
|
|
1595
|
-
vault_decrypt: wasm.vault_decrypt,
|
|
1596
|
-
vault_derive_key: wasm.vault_derive_key,
|
|
1597
|
-
vault_x25519_from_seed: wasm.vault_x25519_from_seed,
|
|
1598
|
-
vault_x25519_dh: wasm.vault_x25519_dh,
|
|
1599
|
-
vault_random_bytes: wasm.vault_random_bytes,
|
|
1600
|
-
vault_sha256: wasm.vault_sha256
|
|
1601
|
-
});
|
|
1602
|
-
const self = this;
|
|
1603
|
-
this._vault = new DataVaultService({
|
|
1604
|
-
spaceId: sessionData.spaceId,
|
|
1605
|
-
crypto: vaultCrypto,
|
|
1606
|
-
tc: {
|
|
1607
|
-
kv: this._kv,
|
|
1608
|
-
ensurePublicSpace: async () => {
|
|
1609
|
-
try {
|
|
1610
|
-
await self.ensurePublicSpace();
|
|
1611
|
-
return { ok: true, data: void 0 };
|
|
1612
|
-
} catch (error) {
|
|
1613
|
-
return { ok: false, error: { code: "STORAGE_ERROR", message: error instanceof Error ? error.message : String(error), service: "vault" } };
|
|
1614
|
-
}
|
|
1615
|
-
},
|
|
1616
|
-
get publicKV() {
|
|
1617
|
-
return self._publicKV ?? self.tc.publicKV;
|
|
1618
|
-
},
|
|
1619
|
-
readPublicSpace: (host, spaceId, key) => TinyCloud.readPublicSpace(host, spaceId, key),
|
|
1620
|
-
makePublicSpaceId: TinyCloud.makePublicSpaceId,
|
|
1621
|
-
did: this.did,
|
|
1622
|
-
address: sessionData.address ?? this._address ?? "",
|
|
1623
|
-
chainId: sessionData.chainId ?? this._chainId,
|
|
1624
|
-
hosts: [this.config.host]
|
|
1625
|
-
}
|
|
1626
|
-
});
|
|
1774
|
+
this._vault = this.createVaultService(sessionData.spaceId, this._kv);
|
|
1627
1775
|
this._vault.initialize(this._serviceContext);
|
|
1628
1776
|
this._serviceContext.registerService("vault", this._vault);
|
|
1629
1777
|
this.initializeV2Services(serviceSession);
|
|
@@ -1775,6 +1923,28 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1775
1923
|
};
|
|
1776
1924
|
this._serviceContext.setSession(serviceSession);
|
|
1777
1925
|
this.tc.serviceContext.setSession(serviceSession);
|
|
1926
|
+
this._vault = this.createVaultService(session.spaceId, this._kv);
|
|
1927
|
+
this._vault.initialize(this._serviceContext);
|
|
1928
|
+
this._serviceContext.registerService("vault", this._vault);
|
|
1929
|
+
this.initializeV2Services(serviceSession);
|
|
1930
|
+
}
|
|
1931
|
+
createSpaceScopedKVService(spaceId) {
|
|
1932
|
+
const kvService = new KVService2({});
|
|
1933
|
+
if (this._serviceContext) {
|
|
1934
|
+
const spaceScopedContext = new ServiceContext2({
|
|
1935
|
+
invoke: this._serviceContext.invoke,
|
|
1936
|
+
fetch: this._serviceContext.fetch,
|
|
1937
|
+
hosts: this._serviceContext.hosts
|
|
1938
|
+
});
|
|
1939
|
+
const session = this._serviceContext.session;
|
|
1940
|
+
if (session) {
|
|
1941
|
+
spaceScopedContext.setSession({ ...session, spaceId });
|
|
1942
|
+
}
|
|
1943
|
+
kvService.initialize(spaceScopedContext);
|
|
1944
|
+
}
|
|
1945
|
+
return kvService;
|
|
1946
|
+
}
|
|
1947
|
+
createVaultService(spaceId, kv) {
|
|
1778
1948
|
const wasm = this.wasmBindings;
|
|
1779
1949
|
const vaultCrypto = createVaultCrypto({
|
|
1780
1950
|
vault_encrypt: wasm.vault_encrypt,
|
|
@@ -1786,11 +1956,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1786
1956
|
vault_sha256: wasm.vault_sha256
|
|
1787
1957
|
});
|
|
1788
1958
|
const self = this;
|
|
1789
|
-
|
|
1790
|
-
spaceId
|
|
1959
|
+
return new DataVaultService({
|
|
1960
|
+
spaceId,
|
|
1791
1961
|
crypto: vaultCrypto,
|
|
1792
1962
|
tc: {
|
|
1793
|
-
kv
|
|
1963
|
+
kv,
|
|
1794
1964
|
ensurePublicSpace: async () => {
|
|
1795
1965
|
try {
|
|
1796
1966
|
await self.ensurePublicSpace();
|
|
@@ -1802,17 +1972,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1802
1972
|
get publicKV() {
|
|
1803
1973
|
return self._publicKV ?? self.tc.publicKV;
|
|
1804
1974
|
},
|
|
1805
|
-
readPublicSpace: (host,
|
|
1975
|
+
readPublicSpace: (host, targetSpaceId, key) => TinyCloud.readPublicSpace(host, targetSpaceId, key),
|
|
1806
1976
|
makePublicSpaceId: TinyCloud.makePublicSpaceId,
|
|
1807
1977
|
did: this.did,
|
|
1808
|
-
address: this._address,
|
|
1978
|
+
address: this._address ?? "",
|
|
1809
1979
|
chainId: this._chainId,
|
|
1810
1980
|
hosts: [this.config.host]
|
|
1811
1981
|
}
|
|
1812
1982
|
});
|
|
1813
|
-
this._vault.initialize(this._serviceContext);
|
|
1814
|
-
this._serviceContext.registerService("vault", this._vault);
|
|
1815
|
-
this.initializeV2Services(serviceSession);
|
|
1816
1983
|
}
|
|
1817
1984
|
/**
|
|
1818
1985
|
* Initialize the v2 delegation system services.
|
|
@@ -1907,20 +2074,15 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1907
2074
|
capabilityRegistry: this._capabilityRegistry,
|
|
1908
2075
|
userDid: this.did,
|
|
1909
2076
|
createKVService: (spaceId) => {
|
|
1910
|
-
|
|
2077
|
+
return this.createSpaceScopedKVService(spaceId);
|
|
2078
|
+
},
|
|
2079
|
+
createVaultService: (spaceId) => {
|
|
2080
|
+
const kvService = this.createSpaceScopedKVService(spaceId);
|
|
2081
|
+
const vaultService = this.createVaultService(spaceId, kvService);
|
|
1911
2082
|
if (this._serviceContext) {
|
|
1912
|
-
|
|
1913
|
-
invoke: this._serviceContext.invoke,
|
|
1914
|
-
fetch: this._serviceContext.fetch,
|
|
1915
|
-
hosts: this._serviceContext.hosts
|
|
1916
|
-
});
|
|
1917
|
-
const session = this._serviceContext.session;
|
|
1918
|
-
if (session) {
|
|
1919
|
-
spaceScopedContext.setSession({ ...session, spaceId });
|
|
1920
|
-
}
|
|
1921
|
-
kvService.initialize(spaceScopedContext);
|
|
2083
|
+
vaultService.initialize(this._serviceContext);
|
|
1922
2084
|
}
|
|
1923
|
-
return
|
|
2085
|
+
return vaultService;
|
|
1924
2086
|
},
|
|
1925
2087
|
// Enable space.delegations.create() via SIWE-based delegation
|
|
1926
2088
|
createDelegation: async (params) => {
|
|
@@ -2157,6 +2319,33 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2157
2319
|
}
|
|
2158
2320
|
return this._vault;
|
|
2159
2321
|
}
|
|
2322
|
+
/**
|
|
2323
|
+
* App-facing secrets API backed by the `secrets` space vault.
|
|
2324
|
+
*/
|
|
2325
|
+
get secrets() {
|
|
2326
|
+
if (!this._spaceService) {
|
|
2327
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
2328
|
+
}
|
|
2329
|
+
if (!this._secrets) {
|
|
2330
|
+
this._secrets = new NodeSecretsService({
|
|
2331
|
+
getService: () => this.getBaseSecrets(),
|
|
2332
|
+
getManifest: () => this.manifest,
|
|
2333
|
+
setManifest: (manifest) => this.setManifest(manifest),
|
|
2334
|
+
signIn: () => this.signIn(),
|
|
2335
|
+
canEscalate: () => this.signer !== void 0 && this.tc !== void 0
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
return this._secrets;
|
|
2339
|
+
}
|
|
2340
|
+
getBaseSecrets() {
|
|
2341
|
+
if (!this._spaceService) {
|
|
2342
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
2343
|
+
}
|
|
2344
|
+
if (!this._baseSecrets) {
|
|
2345
|
+
this._baseSecrets = new SecretsService(() => this.space("secrets").vault);
|
|
2346
|
+
}
|
|
2347
|
+
return this._baseSecrets;
|
|
2348
|
+
}
|
|
2160
2349
|
/**
|
|
2161
2350
|
* Hooks write stream subscription API.
|
|
2162
2351
|
*/
|
|
@@ -2295,6 +2484,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2295
2484
|
get spaceService() {
|
|
2296
2485
|
return this.spaces;
|
|
2297
2486
|
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Get a Space object by short name or full URI.
|
|
2489
|
+
*/
|
|
2490
|
+
space(nameOrUri) {
|
|
2491
|
+
return this.spaces.get(nameOrUri);
|
|
2492
|
+
}
|
|
2298
2493
|
/**
|
|
2299
2494
|
* Get the SharingService for creating and receiving v2 sharing links.
|
|
2300
2495
|
*
|
|
@@ -3129,7 +3324,7 @@ import {
|
|
|
3129
3324
|
SessionExpiredError as SessionExpiredError2,
|
|
3130
3325
|
ManifestValidationError,
|
|
3131
3326
|
composeManifestRequest as composeManifestRequest2,
|
|
3132
|
-
resolveManifest,
|
|
3327
|
+
resolveManifest as resolveManifest2,
|
|
3133
3328
|
validateManifest,
|
|
3134
3329
|
loadManifest,
|
|
3135
3330
|
isCapabilitySubset as isCapabilitySubset2,
|
|
@@ -3158,7 +3353,7 @@ function deserializeDelegation(data) {
|
|
|
3158
3353
|
import { KVService as KVService3, PrefixedKVService } from "@tinycloud/sdk-core";
|
|
3159
3354
|
import { SQLService as SQLService3, SQLAction, DatabaseHandle } from "@tinycloud/sdk-core";
|
|
3160
3355
|
import { DuckDbService as DuckDbService3, DuckDbDatabaseHandle, DuckDbAction } from "@tinycloud/sdk-core";
|
|
3161
|
-
import { DataVaultService as DataVaultService2, VaultHeaders, VaultPublicSpaceKVActions, createVaultCrypto as createVaultCrypto2 } from "@tinycloud/sdk-core";
|
|
3356
|
+
import { DataVaultService as DataVaultService2, VaultHeaders, VaultPublicSpaceKVActions, createVaultCrypto as createVaultCrypto2, SecretsService as SecretsService2 } from "@tinycloud/sdk-core";
|
|
3162
3357
|
import {
|
|
3163
3358
|
DelegationManager as DelegationManager2,
|
|
3164
3359
|
SharingService as SharingService2,
|
|
@@ -3212,6 +3407,7 @@ export {
|
|
|
3212
3407
|
ProtocolMismatchError,
|
|
3213
3408
|
SQLAction,
|
|
3214
3409
|
SQLService3 as SQLService,
|
|
3410
|
+
SecretsService2 as SecretsService,
|
|
3215
3411
|
ServiceContext3 as ServiceContext,
|
|
3216
3412
|
SessionExpiredError2 as SessionExpiredError,
|
|
3217
3413
|
SharingService2 as SharingService,
|
|
@@ -3243,7 +3439,7 @@ export {
|
|
|
3243
3439
|
makePublicSpaceId2 as makePublicSpaceId,
|
|
3244
3440
|
parseExpiry2 as parseExpiry,
|
|
3245
3441
|
parseSpaceUri,
|
|
3246
|
-
resolveManifest,
|
|
3442
|
+
resolveManifest2 as resolveManifest,
|
|
3247
3443
|
resourceCapabilitiesToSpaceAbilitiesMap2 as resourceCapabilitiesToSpaceAbilitiesMap,
|
|
3248
3444
|
serializeDelegation,
|
|
3249
3445
|
validateManifest
|