@tinycloud/node-sdk 2.2.0-beta.10 → 2.2.0-beta.12
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-DcJ27GsA.d.cts → core-M5RMfMIi.d.cts} +56 -0
- package/dist/{core-DcJ27GsA.d.ts → core-M5RMfMIi.d.ts} +56 -0
- package/dist/core.cjs +87 -11
- 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 +97 -15
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +87 -11
- 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 +97 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -17032,6 +17032,7 @@ __export(index_exports, {
|
|
|
17032
17032
|
CapabilityKeyRegistryErrorCodes: () => import_sdk_core16.CapabilityKeyRegistryErrorCodes,
|
|
17033
17033
|
DEFAULT_MANIFEST_SPACE: () => import_sdk_core9.DEFAULT_MANIFEST_SPACE,
|
|
17034
17034
|
DEFAULT_MANIFEST_VERSION: () => import_sdk_core9.DEFAULT_MANIFEST_VERSION,
|
|
17035
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core10.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
17035
17036
|
DataVaultService: () => import_sdk_core13.DataVaultService,
|
|
17036
17037
|
DatabaseHandle: () => import_sdk_core11.DatabaseHandle,
|
|
17037
17038
|
DelegatedAccess: () => DelegatedAccess,
|
|
@@ -17331,7 +17332,7 @@ var NodeUserAuthorization = class {
|
|
|
17331
17332
|
]
|
|
17332
17333
|
}
|
|
17333
17334
|
};
|
|
17334
|
-
this.sessionExpirationMs = config.sessionExpirationMs ??
|
|
17335
|
+
this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core.EXPIRY.SESSION_MS;
|
|
17335
17336
|
this.autoCreateSpace = config.autoCreateSpace ?? false;
|
|
17336
17337
|
this.spaceCreationHandler = config.spaceCreationHandler;
|
|
17337
17338
|
this.tinycloudHosts = config.tinycloudHosts;
|
|
@@ -17384,6 +17385,23 @@ var NodeUserAuthorization = class {
|
|
|
17384
17385
|
get tinyCloudSession() {
|
|
17385
17386
|
return this._tinyCloudSession;
|
|
17386
17387
|
}
|
|
17388
|
+
/**
|
|
17389
|
+
* Rehydrate the auth-layer session from previously-persisted delegation
|
|
17390
|
+
* data. Used by {@link TinyCloudNode.restoreSession} so that downstream
|
|
17391
|
+
* surfaces that read from `tinyCloudSession` (notably
|
|
17392
|
+
* `grantRuntimePermissions`, which extracts the SIWE expiry from it) work
|
|
17393
|
+
* without re-running the full sign-in flow.
|
|
17394
|
+
*
|
|
17395
|
+
* Caller must supply the same fields that `signIn` would have written —
|
|
17396
|
+
* `siwe` is the load-bearing one because `extractSiweExpiration` returns
|
|
17397
|
+
* undefined for missing SIWEs and the SDK then treats the session as
|
|
17398
|
+
* expired-at-epoch-zero.
|
|
17399
|
+
*/
|
|
17400
|
+
setRestoredTinyCloudSession(session) {
|
|
17401
|
+
this._tinyCloudSession = session;
|
|
17402
|
+
this._address = session.address;
|
|
17403
|
+
this._chainId = session.chainId;
|
|
17404
|
+
}
|
|
17387
17405
|
async resolveTinyCloudHostsForSignIn(address, chainId) {
|
|
17388
17406
|
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
17389
17407
|
return;
|
|
@@ -18216,9 +18234,10 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
18216
18234
|
}
|
|
18217
18235
|
return entries;
|
|
18218
18236
|
}
|
|
18237
|
+
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core3.EXPIRY.SESSION_MS;
|
|
18219
18238
|
function resolveExpiryMs(expiry) {
|
|
18220
18239
|
if (expiry === void 0) {
|
|
18221
|
-
return
|
|
18240
|
+
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
18222
18241
|
}
|
|
18223
18242
|
if (typeof expiry === "number") {
|
|
18224
18243
|
if (!Number.isFinite(expiry) || expiry <= 0) {
|
|
@@ -18388,6 +18407,7 @@ var NodeSecretsService = class {
|
|
|
18388
18407
|
|
|
18389
18408
|
// src/TinyCloudNode.ts
|
|
18390
18409
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
18410
|
+
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core5.EXPIRY.SESSION_MS;
|
|
18391
18411
|
var _TinyCloudNode = class _TinyCloudNode {
|
|
18392
18412
|
/**
|
|
18393
18413
|
* Create a new TinyCloudNode instance.
|
|
@@ -18530,7 +18550,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18530
18550
|
sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
|
|
18531
18551
|
domain: this.siweDomain,
|
|
18532
18552
|
spacePrefix: config.prefix,
|
|
18533
|
-
sessionExpirationMs: config.sessionExpirationMs ??
|
|
18553
|
+
sessionExpirationMs: config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS,
|
|
18534
18554
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18535
18555
|
tinycloudRegistryUrl: config.tinycloudRegistryUrl,
|
|
18536
18556
|
tinycloudFallbackHosts: config.tinycloudFallbackHosts,
|
|
@@ -18796,6 +18816,33 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18796
18816
|
this._vault.initialize(this._serviceContext);
|
|
18797
18817
|
this._serviceContext.registerService("vault", this._vault);
|
|
18798
18818
|
this.initializeV2Services(serviceSession);
|
|
18819
|
+
if (sessionData.siwe && sessionData.address && sessionData.chainId) {
|
|
18820
|
+
const tcSession = {
|
|
18821
|
+
address: sessionData.address,
|
|
18822
|
+
chainId: sessionData.chainId,
|
|
18823
|
+
sessionKey: JSON.stringify(sessionData.jwk),
|
|
18824
|
+
spaceId: sessionData.spaceId,
|
|
18825
|
+
delegationCid: sessionData.delegationCid,
|
|
18826
|
+
delegationHeader: sessionData.delegationHeader,
|
|
18827
|
+
verificationMethod: sessionData.verificationMethod,
|
|
18828
|
+
jwk: sessionData.jwk,
|
|
18829
|
+
siwe: sessionData.siwe,
|
|
18830
|
+
signature: sessionData.signature ?? ""
|
|
18831
|
+
};
|
|
18832
|
+
if (this.auth) {
|
|
18833
|
+
this.auth.setRestoredTinyCloudSession(tcSession);
|
|
18834
|
+
} else {
|
|
18835
|
+
this._restoredTcSession = tcSession;
|
|
18836
|
+
}
|
|
18837
|
+
}
|
|
18838
|
+
}
|
|
18839
|
+
/**
|
|
18840
|
+
* Resolve the currently-active TinyCloudSession, preferring the auth
|
|
18841
|
+
* layer's value (wallet mode) and falling back to the node-level
|
|
18842
|
+
* rehydration set by {@link restoreSession} (session-only mode).
|
|
18843
|
+
*/
|
|
18844
|
+
currentTinyCloudSession() {
|
|
18845
|
+
return this.auth?.tinyCloudSession ?? this._restoredTcSession;
|
|
18799
18846
|
}
|
|
18800
18847
|
/**
|
|
18801
18848
|
* Connect a wallet to upgrade from session-only mode to wallet mode.
|
|
@@ -18840,7 +18887,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18840
18887
|
sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
|
|
18841
18888
|
domain: this.siweDomain,
|
|
18842
18889
|
spacePrefix: prefix,
|
|
18843
|
-
sessionExpirationMs: this.config.sessionExpirationMs ??
|
|
18890
|
+
sessionExpirationMs: this.config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS,
|
|
18844
18891
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18845
18892
|
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
18846
18893
|
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
@@ -18884,7 +18931,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18884
18931
|
sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
|
|
18885
18932
|
domain: this.siweDomain,
|
|
18886
18933
|
spacePrefix: prefix,
|
|
18887
|
-
sessionExpirationMs: this.config.sessionExpirationMs ??
|
|
18934
|
+
sessionExpirationMs: this.config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS,
|
|
18888
18935
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18889
18936
|
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
18890
18937
|
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
@@ -19160,7 +19207,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19160
19207
|
* @internal
|
|
19161
19208
|
*/
|
|
19162
19209
|
getSessionExpiry() {
|
|
19163
|
-
const expirationMs = this.config.sessionExpirationMs ??
|
|
19210
|
+
const expirationMs = this.config.sessionExpirationMs ?? DEFAULT_SESSION_EXPIRATION_MS;
|
|
19164
19211
|
return new Date(Date.now() + expirationMs);
|
|
19165
19212
|
}
|
|
19166
19213
|
/**
|
|
@@ -19317,6 +19364,34 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19317
19364
|
}
|
|
19318
19365
|
return this._sql;
|
|
19319
19366
|
}
|
|
19367
|
+
/**
|
|
19368
|
+
* Get an SQL service scoped to a specific space.
|
|
19369
|
+
*
|
|
19370
|
+
* Mirrors {@link SpaceService}'s per-space KV factory: clones the active
|
|
19371
|
+
* service context and overrides its session's spaceId so that subsequent
|
|
19372
|
+
* `sql/<dbName>/<action>` invocations route to that space. Useful when
|
|
19373
|
+
* the caller already holds a delegation covering the target space (e.g.
|
|
19374
|
+
* via {@link grantRuntimePermissions} or {@link useRuntimeDelegation})
|
|
19375
|
+
* but the SDK's per-space SQL surface isn't otherwise exposed.
|
|
19376
|
+
*
|
|
19377
|
+
* Does NOT auto-create the space.
|
|
19378
|
+
*
|
|
19379
|
+
* @param spaceId - Full space URI (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`).
|
|
19380
|
+
*/
|
|
19381
|
+
sqlForSpace(spaceId) {
|
|
19382
|
+
if (!this._serviceContext || !this._serviceContext.session) {
|
|
19383
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
19384
|
+
}
|
|
19385
|
+
const sql = new import_sdk_core5.SQLService({});
|
|
19386
|
+
const spaceScopedContext = new import_sdk_core5.ServiceContext({
|
|
19387
|
+
invoke: this._serviceContext.invoke,
|
|
19388
|
+
fetch: this._serviceContext.fetch,
|
|
19389
|
+
hosts: this._serviceContext.hosts
|
|
19390
|
+
});
|
|
19391
|
+
spaceScopedContext.setSession({ ...this._serviceContext.session, spaceId });
|
|
19392
|
+
sql.initialize(spaceScopedContext);
|
|
19393
|
+
return sql;
|
|
19394
|
+
}
|
|
19320
19395
|
/**
|
|
19321
19396
|
* DuckDB database operations on this user's space.
|
|
19322
19397
|
*/
|
|
@@ -19442,7 +19517,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19442
19517
|
* every requested permission.
|
|
19443
19518
|
*/
|
|
19444
19519
|
hasRuntimePermissions(permissions) {
|
|
19445
|
-
const session = this.
|
|
19520
|
+
const session = this.currentTinyCloudSession();
|
|
19446
19521
|
if (!session || !Array.isArray(permissions) || permissions.length === 0) {
|
|
19447
19522
|
return false;
|
|
19448
19523
|
}
|
|
@@ -19462,7 +19537,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19462
19537
|
if (permissions === void 0) {
|
|
19463
19538
|
return this.runtimePermissionGrants.map((grant) => grant.delegation);
|
|
19464
19539
|
}
|
|
19465
|
-
const session = this.
|
|
19540
|
+
const session = this.currentTinyCloudSession();
|
|
19466
19541
|
if (!session || !Array.isArray(permissions) || permissions.length === 0) {
|
|
19467
19542
|
return [];
|
|
19468
19543
|
}
|
|
@@ -19476,7 +19551,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19476
19551
|
* matching service calls and downstream `delegateTo()` calls can use it.
|
|
19477
19552
|
*/
|
|
19478
19553
|
async useRuntimeDelegation(delegation) {
|
|
19479
|
-
const session = this.
|
|
19554
|
+
const session = this.currentTinyCloudSession();
|
|
19480
19555
|
if (!session) {
|
|
19481
19556
|
throw new import_sdk_core5.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
19482
19557
|
}
|
|
@@ -19515,7 +19590,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19515
19590
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
19516
19591
|
throw new Error("grantRuntimePermissions requires a non-empty permissions array");
|
|
19517
19592
|
}
|
|
19518
|
-
const session = this.
|
|
19593
|
+
const session = this.currentTinyCloudSession();
|
|
19519
19594
|
if (!session) {
|
|
19520
19595
|
throw new import_sdk_core5.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
19521
19596
|
}
|
|
@@ -19743,7 +19818,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19743
19818
|
];
|
|
19744
19819
|
const abilities = { kv: { "": kvActions } };
|
|
19745
19820
|
const now = /* @__PURE__ */ new Date();
|
|
19746
|
-
const expiryMs =
|
|
19821
|
+
const expiryMs = import_sdk_core5.EXPIRY.EPHEMERAL_MS;
|
|
19747
19822
|
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
19748
19823
|
const prepared = this.wasmBindings.prepareSession({
|
|
19749
19824
|
abilities,
|
|
@@ -20933,6 +21008,7 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
|
20933
21008
|
CapabilityKeyRegistryErrorCodes,
|
|
20934
21009
|
DEFAULT_MANIFEST_SPACE,
|
|
20935
21010
|
DEFAULT_MANIFEST_VERSION,
|
|
21011
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
20936
21012
|
DataVaultService,
|
|
20937
21013
|
DatabaseHandle,
|
|
20938
21014
|
DelegatedAccess,
|