@tinycloud/node-sdk 3.1.0-beta.5 → 3.1.0-beta.6
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 +101 -58
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +102 -58
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +101 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +102 -58
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/core.js
CHANGED
|
@@ -262,6 +262,10 @@ var defaultSignStrategy = { type: "auto-sign" };
|
|
|
262
262
|
// src/authorization/NodeUserAuthorization.ts
|
|
263
263
|
var DECRYPT_ACTION = ENCRYPTION.DECRYPT;
|
|
264
264
|
var NETWORK_CREATE_ACTION = ENCRYPTION.NETWORK_CREATE;
|
|
265
|
+
function describeHostFailure(result) {
|
|
266
|
+
const text = result.error?.trim();
|
|
267
|
+
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
268
|
+
}
|
|
265
269
|
function canonicalizeOpenKeyManifestJson(value) {
|
|
266
270
|
const json = JSON.stringify(value);
|
|
267
271
|
if (json === void 0) {
|
|
@@ -790,10 +794,12 @@ var NodeUserAuthorization = class {
|
|
|
790
794
|
return;
|
|
791
795
|
}
|
|
792
796
|
try {
|
|
793
|
-
const created =
|
|
794
|
-
if (!created) {
|
|
795
|
-
const err =
|
|
796
|
-
|
|
797
|
+
const created = await this.hostSpace();
|
|
798
|
+
if (!created.success) {
|
|
799
|
+
const err = Object.assign(
|
|
800
|
+
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
801
|
+
{ cause: created }
|
|
802
|
+
);
|
|
797
803
|
throw err;
|
|
798
804
|
}
|
|
799
805
|
} catch (error) {
|
|
@@ -809,8 +815,9 @@ var NodeUserAuthorization = class {
|
|
|
809
815
|
this._tinyCloudSession.delegationHeader
|
|
810
816
|
);
|
|
811
817
|
if (!retryResult.success) {
|
|
812
|
-
const err =
|
|
813
|
-
`Failed to activate session after creating space: ${retryResult
|
|
818
|
+
const err = Object.assign(
|
|
819
|
+
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
820
|
+
{ cause: retryResult }
|
|
814
821
|
);
|
|
815
822
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
816
823
|
throw err;
|
|
@@ -827,10 +834,12 @@ var NodeUserAuthorization = class {
|
|
|
827
834
|
return;
|
|
828
835
|
}
|
|
829
836
|
try {
|
|
830
|
-
const created =
|
|
831
|
-
if (!created) {
|
|
832
|
-
const err =
|
|
833
|
-
|
|
837
|
+
const created = await this.hostSpace();
|
|
838
|
+
if (!created.success) {
|
|
839
|
+
const err = Object.assign(
|
|
840
|
+
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
841
|
+
{ cause: created }
|
|
842
|
+
);
|
|
834
843
|
throw err;
|
|
835
844
|
}
|
|
836
845
|
} catch (error) {
|
|
@@ -846,8 +855,9 @@ var NodeUserAuthorization = class {
|
|
|
846
855
|
this._tinyCloudSession.delegationHeader
|
|
847
856
|
);
|
|
848
857
|
if (!retryResult.success) {
|
|
849
|
-
const err =
|
|
850
|
-
`Failed to activate session after creating space: ${retryResult
|
|
858
|
+
const err = Object.assign(
|
|
859
|
+
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
860
|
+
{ cause: retryResult }
|
|
851
861
|
);
|
|
852
862
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
853
863
|
throw err;
|
|
@@ -855,7 +865,10 @@ var NodeUserAuthorization = class {
|
|
|
855
865
|
handler.onSpaceCreated?.(creationContext);
|
|
856
866
|
return;
|
|
857
867
|
}
|
|
858
|
-
throw
|
|
868
|
+
throw Object.assign(
|
|
869
|
+
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
870
|
+
{ cause: result }
|
|
871
|
+
);
|
|
859
872
|
}
|
|
860
873
|
recordActivationSkippedSpaces(result, primarySpaceId) {
|
|
861
874
|
if (result.success) {
|
|
@@ -1670,6 +1683,7 @@ import {
|
|
|
1670
1683
|
TinyCloud,
|
|
1671
1684
|
activateSessionWithHost as activateSessionWithHost2,
|
|
1672
1685
|
authorizationVerdictOf,
|
|
1686
|
+
httpResponseError,
|
|
1673
1687
|
KVService as KVService2,
|
|
1674
1688
|
SQLService as SQLService2,
|
|
1675
1689
|
DuckDbService as DuckDbService2,
|
|
@@ -2411,7 +2425,7 @@ function persistedExpiry(value) {
|
|
|
2411
2425
|
function sameInstant(left, right) {
|
|
2412
2426
|
return left.getTime() === right.getTime();
|
|
2413
2427
|
}
|
|
2414
|
-
function
|
|
2428
|
+
function describeHostFailure2(result) {
|
|
2415
2429
|
const text = result.error?.trim();
|
|
2416
2430
|
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
2417
2431
|
}
|
|
@@ -3218,7 +3232,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3218
3232
|
marker
|
|
3219
3233
|
);
|
|
3220
3234
|
if (!written.ok) {
|
|
3221
|
-
throw
|
|
3235
|
+
throw Object.assign(
|
|
3236
|
+
new Error(`Failed to write bootstrap completion marker: ${written.error.message}`),
|
|
3237
|
+
{ cause: written.error }
|
|
3238
|
+
);
|
|
3222
3239
|
}
|
|
3223
3240
|
}
|
|
3224
3241
|
isAcceptedBootstrapCompletionMarker(value) {
|
|
@@ -3264,17 +3281,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3264
3281
|
rawAbilities
|
|
3265
3282
|
});
|
|
3266
3283
|
} catch (err) {
|
|
3267
|
-
throw
|
|
3268
|
-
|
|
3284
|
+
throw Object.assign(
|
|
3285
|
+
new Error(
|
|
3286
|
+
`Account bootstrap aborted: signature rejected for space "${step.space}". Cause: ${err instanceof Error ? err.message : String(err)}`
|
|
3287
|
+
),
|
|
3288
|
+
{ cause: err }
|
|
3269
3289
|
);
|
|
3270
3290
|
}
|
|
3271
3291
|
sessions.set(step.space, session);
|
|
3272
3292
|
}
|
|
3273
3293
|
for (const step of steps) {
|
|
3274
3294
|
if (step.kind !== "host") continue;
|
|
3275
|
-
const hosted = await auth.
|
|
3276
|
-
if (!hosted) {
|
|
3277
|
-
throw
|
|
3295
|
+
const hosted = await auth.hostOwnedSpaceResult(step.spaceId, "bootstrap-host");
|
|
3296
|
+
if (!hosted.success) {
|
|
3297
|
+
throw Object.assign(
|
|
3298
|
+
new Error(`Failed to host bootstrap space ${step.spaceId}: ${describeHostFailure2(hosted)}`),
|
|
3299
|
+
{ cause: hosted }
|
|
3300
|
+
);
|
|
3278
3301
|
}
|
|
3279
3302
|
}
|
|
3280
3303
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -3286,8 +3309,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3286
3309
|
}
|
|
3287
3310
|
const activated = await activateSessionWithHost2(host, session.delegationHeader);
|
|
3288
3311
|
if (!activated.success || activated.skipped?.includes(step.spaceId)) {
|
|
3289
|
-
throw
|
|
3290
|
-
|
|
3312
|
+
throw Object.assign(
|
|
3313
|
+
new Error(
|
|
3314
|
+
`Failed to activate bootstrap session for ${step.spaceId}: ${activated.success ? "space was skipped" : describeHostFailure2(activated)}`
|
|
3315
|
+
),
|
|
3316
|
+
{ cause: activated }
|
|
3291
3317
|
);
|
|
3292
3318
|
}
|
|
3293
3319
|
this.registerBootstrapRuntimeGrant(
|
|
@@ -3300,7 +3326,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3300
3326
|
if (step.kind === "account-index-schema") {
|
|
3301
3327
|
const ensured = await this.account.index.ensure();
|
|
3302
3328
|
if (!ensured.ok) {
|
|
3303
|
-
throw new Error(`Failed to create account index schema: ${ensured.error.message}`);
|
|
3329
|
+
throw Object.assign(new Error(`Failed to create account index schema: ${ensured.error.message}`), { cause: ensured.error });
|
|
3304
3330
|
}
|
|
3305
3331
|
}
|
|
3306
3332
|
if (step.kind === "seed-spaces") {
|
|
@@ -3315,8 +3341,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3315
3341
|
}))
|
|
3316
3342
|
);
|
|
3317
3343
|
if (!registered.ok) {
|
|
3318
|
-
throw
|
|
3319
|
-
`Failed to seed account spaces: ${registered.error.message}`
|
|
3344
|
+
throw Object.assign(
|
|
3345
|
+
new Error(`Failed to seed account spaces: ${registered.error.message}`),
|
|
3346
|
+
{ cause: registered.error }
|
|
3320
3347
|
);
|
|
3321
3348
|
}
|
|
3322
3349
|
const batchError = registered.data.recoveredFromBatchError;
|
|
@@ -3337,7 +3364,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3337
3364
|
{ assumeUnregistered: true }
|
|
3338
3365
|
);
|
|
3339
3366
|
if (!registered.ok) {
|
|
3340
|
-
throw new Error(`Failed to seed bootstrap applications: ${registered.error.message}`);
|
|
3367
|
+
throw Object.assign(new Error(`Failed to seed bootstrap applications: ${registered.error.message}`), { cause: registered.error });
|
|
3341
3368
|
}
|
|
3342
3369
|
}
|
|
3343
3370
|
if (step.kind === "encryption-network-create") {
|
|
@@ -3355,8 +3382,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3355
3382
|
]
|
|
3356
3383
|
});
|
|
3357
3384
|
if (!migrated.ok) {
|
|
3358
|
-
throw
|
|
3359
|
-
`Failed to create secret_records schema: ${migrated.error.message}`
|
|
3385
|
+
throw Object.assign(
|
|
3386
|
+
new Error(`Failed to create secret_records schema: ${migrated.error.message}`),
|
|
3387
|
+
{ cause: migrated.error }
|
|
3360
3388
|
);
|
|
3361
3389
|
}
|
|
3362
3390
|
}
|
|
@@ -3701,14 +3729,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3701
3729
|
}
|
|
3702
3730
|
if (!activation.success && activation.status !== 404) {
|
|
3703
3731
|
throw Object.assign(
|
|
3704
|
-
new Error(`Failed to check owned space ${spaceId}: ${
|
|
3732
|
+
new Error(`Failed to check owned space ${spaceId}: ${describeHostFailure2(activation)}`),
|
|
3705
3733
|
{ cause: activation }
|
|
3706
3734
|
);
|
|
3707
3735
|
}
|
|
3708
3736
|
const created = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
3709
3737
|
if (!created.success) {
|
|
3710
3738
|
throw Object.assign(
|
|
3711
|
-
new Error(`Failed to create owned space ${spaceId}: ${
|
|
3739
|
+
new Error(`Failed to create owned space ${spaceId}: ${describeHostFailure2(created)}`),
|
|
3712
3740
|
{ cause: created }
|
|
3713
3741
|
);
|
|
3714
3742
|
}
|
|
@@ -3717,7 +3745,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3717
3745
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
3718
3746
|
throw Object.assign(
|
|
3719
3747
|
new Error(
|
|
3720
|
-
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" :
|
|
3748
|
+
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" : describeHostFailure2(retry)}`
|
|
3721
3749
|
),
|
|
3722
3750
|
{ cause: retry }
|
|
3723
3751
|
);
|
|
@@ -3754,19 +3782,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3754
3782
|
if (!host) {
|
|
3755
3783
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
3756
3784
|
}
|
|
3757
|
-
const hosted = await this.auth.
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3785
|
+
const hosted = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
3786
|
+
if (!hosted.success) {
|
|
3787
|
+
throw Object.assign(
|
|
3788
|
+
new Error(`Failed to host owned space ${spaceId}: ${describeHostFailure2(hosted)}`),
|
|
3789
|
+
{ cause: hosted }
|
|
3790
|
+
);
|
|
3762
3791
|
}
|
|
3763
3792
|
const activation = await activateSessionWithHost2(
|
|
3764
3793
|
host,
|
|
3765
3794
|
session.delegationHeader
|
|
3766
3795
|
);
|
|
3767
3796
|
if (!activation.success || activation.skipped?.includes(spaceId)) {
|
|
3768
|
-
throw
|
|
3769
|
-
|
|
3797
|
+
throw Object.assign(
|
|
3798
|
+
new Error(
|
|
3799
|
+
`Failed to activate session for owned space ${spaceId}: ${activation.success ? "space was skipped" : describeHostFailure2(activation)}`
|
|
3800
|
+
),
|
|
3801
|
+
{ cause: activation }
|
|
3770
3802
|
);
|
|
3771
3803
|
}
|
|
3772
3804
|
try {
|
|
@@ -4782,7 +4814,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4782
4814
|
if (cached) return cached;
|
|
4783
4815
|
const response = await fetch(`${this.config.host}/info`);
|
|
4784
4816
|
if (!response.ok) {
|
|
4785
|
-
throw
|
|
4817
|
+
throw await httpResponseError(response, "Failed to fetch node info");
|
|
4786
4818
|
}
|
|
4787
4819
|
const info = await response.json();
|
|
4788
4820
|
if (typeof info.nodeId !== "string" || info.nodeId.length === 0) {
|
|
@@ -4832,9 +4864,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4832
4864
|
);
|
|
4833
4865
|
if (response.status === 404) return null;
|
|
4834
4866
|
if (!response.ok) {
|
|
4835
|
-
throw
|
|
4836
|
-
`Failed to fetch encryption network ${networkId}: HTTP ${response.status} ${await response.text()}`
|
|
4837
|
-
);
|
|
4867
|
+
throw await httpResponseError(response, `Failed to fetch encryption network ${networkId}`);
|
|
4838
4868
|
}
|
|
4839
4869
|
const body = await response.json();
|
|
4840
4870
|
return "descriptor" in body && body.descriptor ? body.descriptor : body;
|
|
@@ -5335,7 +5365,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5335
5365
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
5336
5366
|
body: canonicalizeEncryptionJson(request)
|
|
5337
5367
|
});
|
|
5338
|
-
if (!response.ok) throw
|
|
5368
|
+
if (!response.ok) throw await httpResponseError(response, "V3 share delivery authorization failed");
|
|
5339
5369
|
const verified = validateShareDeliveryAuthorizationV3Bytes(new Uint8Array(await response.arrayBuffer()), {
|
|
5340
5370
|
request,
|
|
5341
5371
|
senderKeyDid: this.credentialHolderDid,
|
|
@@ -5557,9 +5587,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5557
5587
|
);
|
|
5558
5588
|
}
|
|
5559
5589
|
if (!response.ok) {
|
|
5560
|
-
throw
|
|
5561
|
-
`Failed to create encryption network ${networkId}: HTTP ${response.status} ${await response.text()}`
|
|
5562
|
-
);
|
|
5590
|
+
throw await httpResponseError(response, `Failed to create encryption network ${networkId}`);
|
|
5563
5591
|
}
|
|
5564
5592
|
const created = await response.json();
|
|
5565
5593
|
return created.descriptor;
|
|
@@ -5867,8 +5895,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5867
5895
|
delegation.delegationHeader
|
|
5868
5896
|
);
|
|
5869
5897
|
if (!activateResult.success) {
|
|
5870
|
-
throw
|
|
5871
|
-
`Failed to activate runtime permission delegation: ${activateResult
|
|
5898
|
+
throw Object.assign(
|
|
5899
|
+
new Error(`Failed to activate runtime permission delegation: ${describeHostFailure2(activateResult)}`),
|
|
5900
|
+
{ cause: activateResult }
|
|
5872
5901
|
);
|
|
5873
5902
|
}
|
|
5874
5903
|
this.runtimePermissionGrants = this.runtimePermissionGrants.filter(
|
|
@@ -5964,8 +5993,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5964
5993
|
delegatedSession.delegationHeader
|
|
5965
5994
|
);
|
|
5966
5995
|
if (!activateResult.success) {
|
|
5967
|
-
throw
|
|
5968
|
-
`Failed to activate runtime permission delegation: ${activateResult
|
|
5996
|
+
throw Object.assign(
|
|
5997
|
+
new Error(`Failed to activate runtime permission delegation: ${describeHostFailure2(activateResult)}`),
|
|
5998
|
+
{ cause: activateResult }
|
|
5969
5999
|
);
|
|
5970
6000
|
}
|
|
5971
6001
|
const delegation = this.runtimeDelegationFromSession(
|
|
@@ -6150,7 +6180,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6150
6180
|
delegationSession.delegationHeader
|
|
6151
6181
|
);
|
|
6152
6182
|
if (!activateResult.success) {
|
|
6153
|
-
throw
|
|
6183
|
+
throw Object.assign(
|
|
6184
|
+
new Error(`Failed to activate public space delegation: ${describeHostFailure2(activateResult)}`),
|
|
6185
|
+
{ cause: activateResult }
|
|
6186
|
+
);
|
|
6154
6187
|
}
|
|
6155
6188
|
if (this._capabilityRegistry && this.session) {
|
|
6156
6189
|
const sessionKey = {
|
|
@@ -6503,8 +6536,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6503
6536
|
delegationHeader
|
|
6504
6537
|
);
|
|
6505
6538
|
if (!activateResult.success) {
|
|
6506
|
-
throw
|
|
6507
|
-
`Failed to activate delegation with host: ${activateResult
|
|
6539
|
+
throw Object.assign(
|
|
6540
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6541
|
+
{ cause: activateResult }
|
|
6508
6542
|
);
|
|
6509
6543
|
}
|
|
6510
6544
|
return {
|
|
@@ -6540,8 +6574,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6540
6574
|
delegationHeader
|
|
6541
6575
|
);
|
|
6542
6576
|
if (!activateResult.success) {
|
|
6543
|
-
throw
|
|
6544
|
-
`Failed to activate delegation with host: ${activateResult
|
|
6577
|
+
throw Object.assign(
|
|
6578
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6579
|
+
{ cause: activateResult }
|
|
6545
6580
|
);
|
|
6546
6581
|
}
|
|
6547
6582
|
return {
|
|
@@ -7148,7 +7183,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7148
7183
|
delegationSession.delegationHeader
|
|
7149
7184
|
);
|
|
7150
7185
|
if (!activateResult.success) {
|
|
7151
|
-
throw
|
|
7186
|
+
throw Object.assign(
|
|
7187
|
+
new Error(`Failed to activate delegation: ${describeHostFailure2(activateResult)}`),
|
|
7188
|
+
{ cause: activateResult }
|
|
7189
|
+
);
|
|
7152
7190
|
}
|
|
7153
7191
|
const result = {
|
|
7154
7192
|
cid: delegationSession.delegationCid,
|
|
@@ -7298,7 +7336,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7298
7336
|
invokerSession.delegationHeader
|
|
7299
7337
|
);
|
|
7300
7338
|
if (!activateResult.success) {
|
|
7301
|
-
throw
|
|
7339
|
+
throw Object.assign(
|
|
7340
|
+
new Error(`Failed to activate delegated session: ${describeHostFailure2(activateResult)}`),
|
|
7341
|
+
{ cause: activateResult }
|
|
7342
|
+
);
|
|
7302
7343
|
}
|
|
7303
7344
|
const session = {
|
|
7304
7345
|
address: mySession.address,
|
|
@@ -7415,7 +7456,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7415
7456
|
subDelegationSession.delegationHeader
|
|
7416
7457
|
);
|
|
7417
7458
|
if (!activateResult.success) {
|
|
7418
|
-
throw
|
|
7459
|
+
throw Object.assign(
|
|
7460
|
+
new Error(`Failed to activate sub-delegation: ${describeHostFailure2(activateResult)}`),
|
|
7461
|
+
{ cause: activateResult }
|
|
7462
|
+
);
|
|
7419
7463
|
}
|
|
7420
7464
|
return {
|
|
7421
7465
|
cid: subDelegationSession.delegationCid,
|