@tinycloud/node-sdk 2.4.0-beta.14 → 2.4.0-beta.16
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--mjBU9Jq.d.cts → core-BX7hRUSI.d.cts} +33 -4
- package/dist/{core--mjBU9Jq.d.ts → core-BX7hRUSI.d.ts} +33 -4
- package/dist/core.cjs +67 -5
- 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 +67 -5
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +67 -5
- 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 +67 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -19195,16 +19195,78 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19195
19195
|
* registered on the node.
|
|
19196
19196
|
*
|
|
19197
19197
|
* Calling this resolves `name` to the owner's owned-space URI
|
|
19198
|
-
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`)
|
|
19199
|
-
*
|
|
19200
|
-
*
|
|
19201
|
-
*
|
|
19198
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`). It first consults the
|
|
19199
|
+
* account-space spaces registry (`account/spaces/{space_id}`, the canonical
|
|
19200
|
+
* KV source of truth, fronted by a best-effort SQLite index): if the space is
|
|
19201
|
+
* already registered/hosted it returns the URI WITHOUT submitting a host
|
|
19202
|
+
* delegation, avoiding a redundant host-SIWE signature prompt for owners who
|
|
19203
|
+
* already use the space. Only when the space is absent — or the registry
|
|
19204
|
+
* check fails for any reason (e.g. a cold SQLite index reporting
|
|
19205
|
+
* `no such table: spaces`) — does it fall through to {@link hostOwnedSpace}.
|
|
19206
|
+
*
|
|
19207
|
+
* The registry check is purely an optimization: any failure falls back to
|
|
19208
|
+
* hosting, and the host SIWE is idempotent server-side, so re-hosting an
|
|
19209
|
+
* existing space remains a safe no-op. Must be called after {@link signIn}.
|
|
19202
19210
|
*
|
|
19203
19211
|
* @param name - The owned space name (e.g. `"secrets"`).
|
|
19204
19212
|
* @returns The hosted owned-space URI.
|
|
19205
19213
|
*/
|
|
19206
19214
|
async ensureOwnedSpaceHosted(name) {
|
|
19207
|
-
|
|
19215
|
+
if (!this.auth || !this.auth.tinyCloudSession) {
|
|
19216
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
19217
|
+
}
|
|
19218
|
+
const spaceId = this.ownedSpaceId(name);
|
|
19219
|
+
if (await this.isOwnedSpaceRegistered(spaceId)) {
|
|
19220
|
+
return spaceId;
|
|
19221
|
+
}
|
|
19222
|
+
const hosted = await this.hostOwnedSpace(name);
|
|
19223
|
+
try {
|
|
19224
|
+
await this.account.spaces.register({
|
|
19225
|
+
spaceId,
|
|
19226
|
+
name,
|
|
19227
|
+
ownerDid: this.did,
|
|
19228
|
+
type: "owned",
|
|
19229
|
+
permissions: ["*"],
|
|
19230
|
+
status: "active"
|
|
19231
|
+
});
|
|
19232
|
+
} catch {
|
|
19233
|
+
}
|
|
19234
|
+
return hosted;
|
|
19235
|
+
}
|
|
19236
|
+
/**
|
|
19237
|
+
* Check whether an owned space is already registered/hosted by consulting the
|
|
19238
|
+
* account spaces registry.
|
|
19239
|
+
*
|
|
19240
|
+
* Source of truth is the canonical KV registry record
|
|
19241
|
+
* `account/spaces/{space_id}`, read here via `account.spaces.get(spaceId)`.
|
|
19242
|
+
* The KV path is used (rather than `syncAccessible()`) because it works under
|
|
19243
|
+
* a manifest/recap session with NO extra prompt: the composed manifest recap
|
|
19244
|
+
* already grants `tinycloud.kv get/list` on the account space `spaces/`
|
|
19245
|
+
* prefix, whereas `syncAccessible()` depends on `tinycloud.space/list`, which
|
|
19246
|
+
* a recap session does not hold. Before reading, it consults the fast SQLite
|
|
19247
|
+
* index (`account.index.spaces.list()`) as a best-effort short-circuit; on a
|
|
19248
|
+
* cold index (`no such table: spaces`) or any other index failure it falls
|
|
19249
|
+
* back to the canonical KV read.
|
|
19250
|
+
*
|
|
19251
|
+
* This is a best-effort optimization. ANY failure of the check path (missing
|
|
19252
|
+
* table, KV error, missing record, thrown exception) resolves to `false` so
|
|
19253
|
+
* the caller falls through to hosting — per the directive, "if it fails in any
|
|
19254
|
+
* way then create the space".
|
|
19255
|
+
*/
|
|
19256
|
+
async isOwnedSpaceRegistered(spaceId) {
|
|
19257
|
+
try {
|
|
19258
|
+
const indexed = await this.account.index.spaces.list();
|
|
19259
|
+
if (indexed.ok && indexed.data.some((space) => space.spaceId === spaceId)) {
|
|
19260
|
+
return true;
|
|
19261
|
+
}
|
|
19262
|
+
} catch {
|
|
19263
|
+
}
|
|
19264
|
+
try {
|
|
19265
|
+
const record = await this.account.spaces.get(spaceId);
|
|
19266
|
+
return record.ok;
|
|
19267
|
+
} catch {
|
|
19268
|
+
return false;
|
|
19269
|
+
}
|
|
19208
19270
|
}
|
|
19209
19271
|
/**
|
|
19210
19272
|
* Restore a previously established session from stored delegation data.
|