@tinycloud/node-sdk 3.0.1-beta.0 → 3.1.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-DufYfxi-.d.cts → core-Bm76PnOz.d.cts} +7 -1
- package/dist/{core-DufYfxi-.d.ts → core-Bm76PnOz.d.ts} +7 -1
- package/dist/core.cjs +44 -17
- 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 +45 -17
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +44 -17
- 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 +45 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
|
|
2
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SpaceHostResult, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
5
5
|
|
|
@@ -465,6 +465,12 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
465
465
|
* Used by manifest registry setup for the account space.
|
|
466
466
|
*/
|
|
467
467
|
hostOwnedSpace(spaceId: string, purpose?: SignRequest["purpose"]): Promise<boolean>;
|
|
468
|
+
/**
|
|
469
|
+
* {@link hostOwnedSpace} with the full host-delegation result, so a failure
|
|
470
|
+
* keeps its HTTP status (e.g. a typed 401/403) instead of collapsing to
|
|
471
|
+
* `false`.
|
|
472
|
+
*/
|
|
473
|
+
hostOwnedSpaceResult(spaceId: string, purpose?: SignRequest["purpose"]): Promise<SpaceHostResult>;
|
|
468
474
|
/**
|
|
469
475
|
* Ensure the user's space exists on the TinyCloud server.
|
|
470
476
|
* Creates the space if it doesn't exist and autoCreateSpace is enabled.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
|
|
2
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SpaceHostResult, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
5
5
|
|
|
@@ -465,6 +465,12 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
465
465
|
* Used by manifest registry setup for the account space.
|
|
466
466
|
*/
|
|
467
467
|
hostOwnedSpace(spaceId: string, purpose?: SignRequest["purpose"]): Promise<boolean>;
|
|
468
|
+
/**
|
|
469
|
+
* {@link hostOwnedSpace} with the full host-delegation result, so a failure
|
|
470
|
+
* keeps its HTTP status (e.g. a typed 401/403) instead of collapsing to
|
|
471
|
+
* `false`.
|
|
472
|
+
*/
|
|
473
|
+
hostOwnedSpaceResult(spaceId: string, purpose?: SignRequest["purpose"]): Promise<SpaceHostResult>;
|
|
468
474
|
/**
|
|
469
475
|
* Ensure the user's space exists on the TinyCloud server.
|
|
470
476
|
* Creates the space if it doesn't exist and autoCreateSpace is enabled.
|
package/dist/core.cjs
CHANGED
|
@@ -800,21 +800,28 @@ var NodeUserAuthorization = class {
|
|
|
800
800
|
});
|
|
801
801
|
const signature = await this.signMessage(siwe, purpose);
|
|
802
802
|
const headers = this.wasm.siweToDelegationHeaders({ siwe, signature });
|
|
803
|
-
|
|
804
|
-
return result.success;
|
|
803
|
+
return (0, import_sdk_core3.submitHostDelegation)(host, headers);
|
|
805
804
|
}
|
|
806
805
|
/**
|
|
807
806
|
* Create a specific space on the server via host delegation.
|
|
808
807
|
* Used for lazy creation of additional spaces (e.g., public).
|
|
809
808
|
*/
|
|
810
809
|
async hostPublicSpace(spaceId) {
|
|
811
|
-
return this.hostSpace(spaceId);
|
|
810
|
+
return (await this.hostSpace(spaceId)).success;
|
|
812
811
|
}
|
|
813
812
|
/**
|
|
814
813
|
* Create a specific owned space on the server via host delegation.
|
|
815
814
|
* Used by manifest registry setup for the account space.
|
|
816
815
|
*/
|
|
817
816
|
async hostOwnedSpace(spaceId, purpose) {
|
|
817
|
+
return (await this.hostOwnedSpaceResult(spaceId, purpose)).success;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* {@link hostOwnedSpace} with the full host-delegation result, so a failure
|
|
821
|
+
* keeps its HTTP status (e.g. a typed 401/403) instead of collapsing to
|
|
822
|
+
* `false`.
|
|
823
|
+
*/
|
|
824
|
+
async hostOwnedSpaceResult(spaceId, purpose) {
|
|
818
825
|
return this.hostSpace(spaceId, purpose);
|
|
819
826
|
}
|
|
820
827
|
/**
|
|
@@ -857,7 +864,7 @@ var NodeUserAuthorization = class {
|
|
|
857
864
|
return;
|
|
858
865
|
}
|
|
859
866
|
try {
|
|
860
|
-
const created = await this.hostSpace();
|
|
867
|
+
const created = (await this.hostSpace()).success;
|
|
861
868
|
if (!created) {
|
|
862
869
|
const err = new Error(`Failed to create space: ${primarySpaceId}`);
|
|
863
870
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
@@ -894,7 +901,7 @@ var NodeUserAuthorization = class {
|
|
|
894
901
|
return;
|
|
895
902
|
}
|
|
896
903
|
try {
|
|
897
|
-
const created = await this.hostSpace();
|
|
904
|
+
const created = (await this.hostSpace()).success;
|
|
898
905
|
if (!created) {
|
|
899
906
|
const err = new Error(`Failed to create space: ${primarySpaceId}`);
|
|
900
907
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
@@ -2397,6 +2404,10 @@ function persistedExpiry(value) {
|
|
|
2397
2404
|
function sameInstant(left, right) {
|
|
2398
2405
|
return left.getTime() === right.getTime();
|
|
2399
2406
|
}
|
|
2407
|
+
function describeHostFailure(result) {
|
|
2408
|
+
const text = result.error?.trim();
|
|
2409
|
+
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
2410
|
+
}
|
|
2400
2411
|
function ownerDelegationPermissions(params) {
|
|
2401
2412
|
const hasPermissions = Object.prototype.hasOwnProperty.call(params, "permissions");
|
|
2402
2413
|
const hasLegacy = Object.prototype.hasOwnProperty.call(params, "path") || Object.prototype.hasOwnProperty.call(params, "actions");
|
|
@@ -3510,8 +3521,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3510
3521
|
await this.ensureOwnedSpaceHostedById(accountSpaceId);
|
|
3511
3522
|
const result = await this.account.applications.register(request.manifests);
|
|
3512
3523
|
if (!result.ok) {
|
|
3513
|
-
throw
|
|
3514
|
-
`Failed to write manifest registry records: ${result.error.message}`
|
|
3524
|
+
throw Object.assign(
|
|
3525
|
+
new Error(`Failed to write manifest registry records: ${result.error.message}`),
|
|
3526
|
+
{ cause: result.error }
|
|
3515
3527
|
);
|
|
3516
3528
|
}
|
|
3517
3529
|
}
|
|
@@ -3536,7 +3548,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3536
3548
|
if (this.currentSessionCanListSpaces()) {
|
|
3537
3549
|
const spaces = await this.account.spaces.syncAccessible();
|
|
3538
3550
|
if (!spaces.ok) {
|
|
3539
|
-
throw
|
|
3551
|
+
throw Object.assign(
|
|
3552
|
+
new Error(`Failed to sync account spaces: ${spaces.error.message}`),
|
|
3553
|
+
{ cause: spaces.error }
|
|
3554
|
+
);
|
|
3540
3555
|
}
|
|
3541
3556
|
}
|
|
3542
3557
|
});
|
|
@@ -3591,8 +3606,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3591
3606
|
await task();
|
|
3592
3607
|
return;
|
|
3593
3608
|
} catch (error) {
|
|
3609
|
+
const verdict = (0, import_sdk_core8.authorizationVerdictOf)(error);
|
|
3594
3610
|
const message = error instanceof Error ? error.message : String(error);
|
|
3595
|
-
|
|
3611
|
+
const isAuthorizationVerdict = verdict === void 0 ? /Unauthorized Action|\b(?:401|403)\b/.test(message) : verdict !== "other";
|
|
3612
|
+
if (isAuthorizationVerdict) {
|
|
3596
3613
|
console.warn(
|
|
3597
3614
|
"TinyCloud account registry sync stopped: authorization verdict is not retryable",
|
|
3598
3615
|
error
|
|
@@ -3672,19 +3689,26 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3672
3689
|
return;
|
|
3673
3690
|
}
|
|
3674
3691
|
if (!activation.success && activation.status !== 404) {
|
|
3675
|
-
throw
|
|
3676
|
-
`Failed to check owned space ${spaceId}: ${activation
|
|
3692
|
+
throw Object.assign(
|
|
3693
|
+
new Error(`Failed to check owned space ${spaceId}: ${describeHostFailure(activation)}`),
|
|
3694
|
+
{ cause: activation }
|
|
3677
3695
|
);
|
|
3678
3696
|
}
|
|
3679
|
-
const created = await this.auth.
|
|
3680
|
-
if (!created) {
|
|
3681
|
-
throw
|
|
3697
|
+
const created = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
3698
|
+
if (!created.success) {
|
|
3699
|
+
throw Object.assign(
|
|
3700
|
+
new Error(`Failed to create owned space ${spaceId}: ${describeHostFailure(created)}`),
|
|
3701
|
+
{ cause: created }
|
|
3702
|
+
);
|
|
3682
3703
|
}
|
|
3683
3704
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3684
3705
|
const retry = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
|
|
3685
3706
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
3686
|
-
throw
|
|
3687
|
-
|
|
3707
|
+
throw Object.assign(
|
|
3708
|
+
new Error(
|
|
3709
|
+
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" : describeHostFailure(retry)}`
|
|
3710
|
+
),
|
|
3711
|
+
{ cause: retry }
|
|
3688
3712
|
);
|
|
3689
3713
|
}
|
|
3690
3714
|
this.confirmedHostedSpaceIds.add(spaceId);
|
|
@@ -5232,7 +5256,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5232
5256
|
const activation = await (0, import_sdk_core8.activateSessionWithHost)(host, delegationSession.delegationHeader);
|
|
5233
5257
|
assertOwnerGraphActive();
|
|
5234
5258
|
if (!activation.success) {
|
|
5235
|
-
throw
|
|
5259
|
+
throw Object.assign(
|
|
5260
|
+
new Error(`Owner delegation import failed: ${activation.status} ${activation.error ?? ""}`.trim()),
|
|
5261
|
+
{ cause: activation }
|
|
5262
|
+
);
|
|
5236
5263
|
}
|
|
5237
5264
|
const delegation = {
|
|
5238
5265
|
cid: delegationSession.delegationCid,
|