@tinycloud/sdk-core 3.3.0-beta.21 → 3.3.0-beta.23
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/{capability-BA49Uboq.d.cts → capability-BjzXwtNw.d.cts} +1 -1
- package/dist/{capability-BA49Uboq.d.ts → capability-BjzXwtNw.d.ts} +1 -1
- package/dist/{credential-admission-CJbnvwJa.d.ts → credential-admission-7I_ymo-C.d.ts} +1 -1
- package/dist/{credential-admission-CIMA0jGE.d.cts → credential-admission-Cg1M9uyV.d.cts} +1 -1
- package/dist/delegations/index.cjs +71 -228
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +3 -10
- package/dist/delegations/index.d.ts +3 -10
- package/dist/delegations/index.js +71 -228
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +71 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +71 -228
- package/dist/index.js.map +1 -1
- package/dist/policy/index.d.cts +4 -4
- package/dist/policy/index.d.ts +4 -4
- package/dist/{recipient-types.schema-CPDoAVh4.d.cts → recipient-types.schema-DWLT3lo3.d.cts} +10 -61
- package/dist/{recipient-types.schema-CPDoAVh4.d.ts → recipient-types.schema-DWLT3lo3.d.ts} +10 -61
- package/dist/requester/index.d.cts +1 -1
- package/dist/requester/index.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as ICapabilityKeyRegistry,
|
|
2
|
-
export { A as AccountDelegationPage,
|
|
1
|
+
import { I as ICapabilityKeyRegistry, R as Result, D as DelegationError } from '../recipient-types.schema-DWLT3lo3.cjs';
|
|
2
|
+
export { A as AccountDelegationPage, a as AccountDelegationQueryOptions, b as AccountDelegationRecord, c as AccountDelegationResource, C as CREDENTIAL_INVITATION_REQUEST_DOMAIN, d as CapabilityEntry, e as CreateDelegationParams, f as CreateDelegationWasmParams, g as CreateDelegationWasmResult, h as CreateOwnerDelegationParams, i as CredentialInvitationRequest, j as DELIVERY_ADMISSION_DOMAIN, k as DelegateReceivedShareParams, l as DelegatedResource, m as DelegatedShareAccess, n as DelegatedShareKey, o as Delegation, p as DelegationApiResponse, q as DelegationChain, r as DelegationChainV2, s as DelegationDirection, t as DelegationErrorCode, u as DelegationErrorCodes, v as DelegationFilters, w as DelegationManager, x as DelegationManagerConfig, y as DelegationRecord, z as DelegationRevocationReceipt, B as DelegationStatus, E as DeliveryAdmission, F as EncodedShareData, G as GenerateShareParams, H as ISharingService, J as IngestOptions, K as JWK, L as KeyInfo, M as KeyProvider, N as KeyType, O as MAX_CONTENT_BYTES, P as MAX_SEALED_SHARE_CONTENT_BYTES, Q as MAX_SHARE_ARTIFACT_BYTES, S as MAX_SHARE_CONTENT_BYTES, T as MemorySenderShareKeyStorage, U as MemorySenderShareRecordStorage, V as MemoryShareCache, W as OwnerDelegationPermission, X as OwnerDelegationReceipt, Y as OwnerShareAction, Z as OwnerShareDecryption, _ as OwnerShareMatcher, $ as OwnerSharePolicyRegistration, a0 as OwnerSharePolicyRegistrationReceipt, a1 as OwnerSharePolicyV2, a2 as PortableDelegationImportReceipt, a3 as ReceiveOptions, a4 as RegisterOwnerSharePolicyParams, a5 as SenderShareKeyStorage, a6 as SenderShareRecord, a7 as SenderShareRecordStorage, a8 as SenderShareRevocationScope, a9 as SenderShareStore, aa as ShareAccess, ab as ShareAccessError, ac as ShareAccessV2, ad as ShareAction, ae as ShareActionSchema, af as ShareAddressedDelegationEnvelopeV2, ag as ShareAddressedDelegationEnvelopeV2Schema, ah as ShareAddressedDelegationRequestV2, ai as ShareAddressedDelegationRequestV2Schema, aj as ShareAddressedDelegationResponseV2, ak as ShareAddressedDelegationResponseV2Schema, al as ShareAddressedRecipientMatcher, am as ShareArtifactInput, an as ShareArtifactResult, ao as ShareArtifactV2, ap as ShareCache, aq as ShareCacheEntry, ar as ShareCacheKey, as as ShareCacheMetadata, at as ShareCapabilityLike, au as ShareConflict, av as ShareContentMetadata, aw as ShareContentSource, ax as ShareDelegationPreflight, ay as ShareDeliveryAuthorizationV3Receipt, az as ShareDeliveryAuthorizationV3Request, aA as ShareDetachedProof, aB as ShareEnvelopeError, aC as ShareEnvelopeV2, aD as ShareExpiryBounds, aE as ShareKvContentSource, aF as ShareLink, aG as ShareLinkData, aH as ShareLinkLocation, aI as ShareListEntry, aJ as ShareListResult, aK as ShareNativeAction, aL as ShareNativeInvokeEnvelopeV1, aM as ShareNativeInvokeErrorResult, aN as ShareNativeInvokeInput, aO as ShareNativeInvokeResult, aP as ShareNativeInvokeSuccessResult, aQ as ShareNativeResponse, aR as ShareNativeResponseSchema, aS as SharePolicy, aT as SharePolicyBinding, aU as SharePolicySession, aV as SharePolicySessionV1, aW as SharePolicySessionWireV1, aX as SharePortableDelegation, aY as ShareReadInvocationV1, aZ as ShareReadResult, a_ as ShareRecipientClient, a$ as ShareRecipientClientOptions, b0 as ShareRecipientClientOptionsSchema, b1 as ShareRecipientPolicy, b2 as ShareRecipientPolicySchema, b3 as ShareRecipientResult, b4 as ShareRecipientTarget, b5 as ShareRecipientTargetSchema, b6 as ShareResource, b7 as ShareResourceSchema, b8 as ShareSaveOptions, b9 as ShareSchema, ba as ShareSqlContentSource, bb as ShareWireAction, bc as SharingService, bd as SharingServiceConfig, be as SignedDelegation, bf as SpaceInfo, bg as SpaceOwnership, bh as VerifyShareEnvelopeOptions, bi as canonicalOwnerSharePolicy, bj as computeOwnerShareRegistrationCid, bk as computeShareCid, bl as createDelegatedShareKey, bm as createPolicyEnforcementDelegation, bn as createShareArtifact, bo as createShareArtifactAsync, bp as createSharePolicy, bq as createSharingService, br as decryptShareBytesAsync, bs as delegatePortablePolicySession, bt as encodeInlineShareUrl, bu as encodeShareArtifact, bv as encodeShareUrl, bw as encryptShareBytes, bx as encryptShareBytesAsync, by as importPortableDelegation, bz as intersectShareCapabilities, bA as isV2ShareLink, bB as normalizeShareActions, bC as normalizeShareRecipientTarget, bD as normalizeShareResource, bE as parsePortableDelegation, bF as parseShareArtifact, bG as parseShareUrl, bH as restoreDelegatedShareKey, bI as serializePortableDelegation, bJ as shareCapabilityAllows, bK as signShareEnvelope, bL as validateOwnerSharePolicyRegistration, bM as validateOwnerSharePolicyRegistrationBytes, bN as validateShareDeliveryAuthorizationV3Bytes, bO as verifyShareCid, bP as verifyShareEnvelope } from '../recipient-types.schema-DWLT3lo3.cjs';
|
|
3
3
|
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage, MemoryEncryptedShareHistoryStorage, ShareAuthorizationAdapter, ShareAuthorizationDenied, ShareAuthorizationMethod, ShareAuthorizationReady, ShareAuthorizationRequired, ShareAuthorizationResult, ShareDeliveryAdapter, ShareErrorCode, ShareErrorInfo, ShareFetchOptions, ShareHistoryView, ShareInspection, ShareMetadata, ShareNotifyResult, ShareNotifyState, SharePolicyPublishAdapter, ShareReceiveError, ShareReceiveResult, ShareRevocationAdapter, ShareRevocationResult, ShareTarget, TargetPublishAdapter, TargetPublishInput, TargetPublishOutcome, authorizationMethodForTarget, authorizeShare, claimShare, inspectShare, listShares, notifyShare, publishPolicyShare, publishTargetShare, receiveShare, resumeShareAuthorization, revokeShare, showShare, toShareErrorInfo } from '@tinycloud/share-sdk';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ServiceSession, InvokeFunction, FetchFunction, IKVService } from '@tinycloud/sdk-services';
|
|
@@ -299,11 +299,6 @@ declare const SharingServiceConfigSchema: z.ZodObject<{
|
|
|
299
299
|
}>;
|
|
300
300
|
/** Capability key registry for key/delegation management */
|
|
301
301
|
registry: z.ZodEffects<z.ZodUnknown, ICapabilityKeyRegistry, unknown>;
|
|
302
|
-
/**
|
|
303
|
-
* Delegation manager for creating delegations.
|
|
304
|
-
* Required for generate(), optional for receive().
|
|
305
|
-
*/
|
|
306
|
-
delegationManager: z.ZodOptional<z.ZodEffects<z.ZodUnknown, DelegationManager, unknown>>;
|
|
307
302
|
/** Factory for creating KV service instances */
|
|
308
303
|
createKVService: z.ZodEffects<z.ZodUnknown, (config: {
|
|
309
304
|
hosts: string[];
|
|
@@ -357,7 +352,6 @@ declare const SharingServiceConfigSchema: z.ZodObject<{
|
|
|
357
352
|
session?: ServiceSession | undefined;
|
|
358
353
|
baseUrl?: string | undefined;
|
|
359
354
|
fetch?: FetchFunction | undefined;
|
|
360
|
-
delegationManager?: DelegationManager | undefined;
|
|
361
355
|
createDelegation?: Function | undefined;
|
|
362
356
|
createDelegationWasm?: Function | undefined;
|
|
363
357
|
computeCid?: ((data: Uint8Array, codec: bigint) => string) | undefined;
|
|
@@ -376,7 +370,6 @@ declare const SharingServiceConfigSchema: z.ZodObject<{
|
|
|
376
370
|
invoke?: unknown;
|
|
377
371
|
fetch?: unknown;
|
|
378
372
|
registry?: unknown;
|
|
379
|
-
delegationManager?: unknown;
|
|
380
373
|
createKVService?: unknown;
|
|
381
374
|
createDelegation?: unknown;
|
|
382
375
|
createDelegationWasm?: unknown;
|
|
@@ -418,4 +411,4 @@ declare function validateReceiveOptions(data: unknown): Result<ReceiveOptions, D
|
|
|
418
411
|
*/
|
|
419
412
|
declare function validateSharingServiceConfig(data: unknown): Result<SharingServiceConfig, DelegationError>;
|
|
420
413
|
|
|
421
|
-
export { DelegationError,
|
|
414
|
+
export { DelegationError, EncodedShareDataSchema, ReceiveOptionsSchema, Result, SharingServiceConfigSchema, validateEncodedShareData, validateReceiveOptions, validateSharingServiceConfig };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as ICapabilityKeyRegistry,
|
|
2
|
-
export { A as AccountDelegationPage,
|
|
1
|
+
import { I as ICapabilityKeyRegistry, R as Result, D as DelegationError } from '../recipient-types.schema-DWLT3lo3.js';
|
|
2
|
+
export { A as AccountDelegationPage, a as AccountDelegationQueryOptions, b as AccountDelegationRecord, c as AccountDelegationResource, C as CREDENTIAL_INVITATION_REQUEST_DOMAIN, d as CapabilityEntry, e as CreateDelegationParams, f as CreateDelegationWasmParams, g as CreateDelegationWasmResult, h as CreateOwnerDelegationParams, i as CredentialInvitationRequest, j as DELIVERY_ADMISSION_DOMAIN, k as DelegateReceivedShareParams, l as DelegatedResource, m as DelegatedShareAccess, n as DelegatedShareKey, o as Delegation, p as DelegationApiResponse, q as DelegationChain, r as DelegationChainV2, s as DelegationDirection, t as DelegationErrorCode, u as DelegationErrorCodes, v as DelegationFilters, w as DelegationManager, x as DelegationManagerConfig, y as DelegationRecord, z as DelegationRevocationReceipt, B as DelegationStatus, E as DeliveryAdmission, F as EncodedShareData, G as GenerateShareParams, H as ISharingService, J as IngestOptions, K as JWK, L as KeyInfo, M as KeyProvider, N as KeyType, O as MAX_CONTENT_BYTES, P as MAX_SEALED_SHARE_CONTENT_BYTES, Q as MAX_SHARE_ARTIFACT_BYTES, S as MAX_SHARE_CONTENT_BYTES, T as MemorySenderShareKeyStorage, U as MemorySenderShareRecordStorage, V as MemoryShareCache, W as OwnerDelegationPermission, X as OwnerDelegationReceipt, Y as OwnerShareAction, Z as OwnerShareDecryption, _ as OwnerShareMatcher, $ as OwnerSharePolicyRegistration, a0 as OwnerSharePolicyRegistrationReceipt, a1 as OwnerSharePolicyV2, a2 as PortableDelegationImportReceipt, a3 as ReceiveOptions, a4 as RegisterOwnerSharePolicyParams, a5 as SenderShareKeyStorage, a6 as SenderShareRecord, a7 as SenderShareRecordStorage, a8 as SenderShareRevocationScope, a9 as SenderShareStore, aa as ShareAccess, ab as ShareAccessError, ac as ShareAccessV2, ad as ShareAction, ae as ShareActionSchema, af as ShareAddressedDelegationEnvelopeV2, ag as ShareAddressedDelegationEnvelopeV2Schema, ah as ShareAddressedDelegationRequestV2, ai as ShareAddressedDelegationRequestV2Schema, aj as ShareAddressedDelegationResponseV2, ak as ShareAddressedDelegationResponseV2Schema, al as ShareAddressedRecipientMatcher, am as ShareArtifactInput, an as ShareArtifactResult, ao as ShareArtifactV2, ap as ShareCache, aq as ShareCacheEntry, ar as ShareCacheKey, as as ShareCacheMetadata, at as ShareCapabilityLike, au as ShareConflict, av as ShareContentMetadata, aw as ShareContentSource, ax as ShareDelegationPreflight, ay as ShareDeliveryAuthorizationV3Receipt, az as ShareDeliveryAuthorizationV3Request, aA as ShareDetachedProof, aB as ShareEnvelopeError, aC as ShareEnvelopeV2, aD as ShareExpiryBounds, aE as ShareKvContentSource, aF as ShareLink, aG as ShareLinkData, aH as ShareLinkLocation, aI as ShareListEntry, aJ as ShareListResult, aK as ShareNativeAction, aL as ShareNativeInvokeEnvelopeV1, aM as ShareNativeInvokeErrorResult, aN as ShareNativeInvokeInput, aO as ShareNativeInvokeResult, aP as ShareNativeInvokeSuccessResult, aQ as ShareNativeResponse, aR as ShareNativeResponseSchema, aS as SharePolicy, aT as SharePolicyBinding, aU as SharePolicySession, aV as SharePolicySessionV1, aW as SharePolicySessionWireV1, aX as SharePortableDelegation, aY as ShareReadInvocationV1, aZ as ShareReadResult, a_ as ShareRecipientClient, a$ as ShareRecipientClientOptions, b0 as ShareRecipientClientOptionsSchema, b1 as ShareRecipientPolicy, b2 as ShareRecipientPolicySchema, b3 as ShareRecipientResult, b4 as ShareRecipientTarget, b5 as ShareRecipientTargetSchema, b6 as ShareResource, b7 as ShareResourceSchema, b8 as ShareSaveOptions, b9 as ShareSchema, ba as ShareSqlContentSource, bb as ShareWireAction, bc as SharingService, bd as SharingServiceConfig, be as SignedDelegation, bf as SpaceInfo, bg as SpaceOwnership, bh as VerifyShareEnvelopeOptions, bi as canonicalOwnerSharePolicy, bj as computeOwnerShareRegistrationCid, bk as computeShareCid, bl as createDelegatedShareKey, bm as createPolicyEnforcementDelegation, bn as createShareArtifact, bo as createShareArtifactAsync, bp as createSharePolicy, bq as createSharingService, br as decryptShareBytesAsync, bs as delegatePortablePolicySession, bt as encodeInlineShareUrl, bu as encodeShareArtifact, bv as encodeShareUrl, bw as encryptShareBytes, bx as encryptShareBytesAsync, by as importPortableDelegation, bz as intersectShareCapabilities, bA as isV2ShareLink, bB as normalizeShareActions, bC as normalizeShareRecipientTarget, bD as normalizeShareResource, bE as parsePortableDelegation, bF as parseShareArtifact, bG as parseShareUrl, bH as restoreDelegatedShareKey, bI as serializePortableDelegation, bJ as shareCapabilityAllows, bK as signShareEnvelope, bL as validateOwnerSharePolicyRegistration, bM as validateOwnerSharePolicyRegistrationBytes, bN as validateShareDeliveryAuthorizationV3Bytes, bO as verifyShareCid, bP as verifyShareEnvelope } from '../recipient-types.schema-DWLT3lo3.js';
|
|
3
3
|
export { EncryptedSenderShareHistory, EncryptedShareHistoryStorage, MemoryEncryptedShareHistoryStorage, ShareAuthorizationAdapter, ShareAuthorizationDenied, ShareAuthorizationMethod, ShareAuthorizationReady, ShareAuthorizationRequired, ShareAuthorizationResult, ShareDeliveryAdapter, ShareErrorCode, ShareErrorInfo, ShareFetchOptions, ShareHistoryView, ShareInspection, ShareMetadata, ShareNotifyResult, ShareNotifyState, SharePolicyPublishAdapter, ShareReceiveError, ShareReceiveResult, ShareRevocationAdapter, ShareRevocationResult, ShareTarget, TargetPublishAdapter, TargetPublishInput, TargetPublishOutcome, authorizationMethodForTarget, authorizeShare, claimShare, inspectShare, listShares, notifyShare, publishPolicyShare, publishTargetShare, receiveShare, resumeShareAuthorization, revokeShare, showShare, toShareErrorInfo } from '@tinycloud/share-sdk';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ServiceSession, InvokeFunction, FetchFunction, IKVService } from '@tinycloud/sdk-services';
|
|
@@ -299,11 +299,6 @@ declare const SharingServiceConfigSchema: z.ZodObject<{
|
|
|
299
299
|
}>;
|
|
300
300
|
/** Capability key registry for key/delegation management */
|
|
301
301
|
registry: z.ZodEffects<z.ZodUnknown, ICapabilityKeyRegistry, unknown>;
|
|
302
|
-
/**
|
|
303
|
-
* Delegation manager for creating delegations.
|
|
304
|
-
* Required for generate(), optional for receive().
|
|
305
|
-
*/
|
|
306
|
-
delegationManager: z.ZodOptional<z.ZodEffects<z.ZodUnknown, DelegationManager, unknown>>;
|
|
307
302
|
/** Factory for creating KV service instances */
|
|
308
303
|
createKVService: z.ZodEffects<z.ZodUnknown, (config: {
|
|
309
304
|
hosts: string[];
|
|
@@ -357,7 +352,6 @@ declare const SharingServiceConfigSchema: z.ZodObject<{
|
|
|
357
352
|
session?: ServiceSession | undefined;
|
|
358
353
|
baseUrl?: string | undefined;
|
|
359
354
|
fetch?: FetchFunction | undefined;
|
|
360
|
-
delegationManager?: DelegationManager | undefined;
|
|
361
355
|
createDelegation?: Function | undefined;
|
|
362
356
|
createDelegationWasm?: Function | undefined;
|
|
363
357
|
computeCid?: ((data: Uint8Array, codec: bigint) => string) | undefined;
|
|
@@ -376,7 +370,6 @@ declare const SharingServiceConfigSchema: z.ZodObject<{
|
|
|
376
370
|
invoke?: unknown;
|
|
377
371
|
fetch?: unknown;
|
|
378
372
|
registry?: unknown;
|
|
379
|
-
delegationManager?: unknown;
|
|
380
373
|
createKVService?: unknown;
|
|
381
374
|
createDelegation?: unknown;
|
|
382
375
|
createDelegationWasm?: unknown;
|
|
@@ -418,4 +411,4 @@ declare function validateReceiveOptions(data: unknown): Result<ReceiveOptions, D
|
|
|
418
411
|
*/
|
|
419
412
|
declare function validateSharingServiceConfig(data: unknown): Result<SharingServiceConfig, DelegationError>;
|
|
420
413
|
|
|
421
|
-
export { DelegationError,
|
|
414
|
+
export { DelegationError, EncodedShareDataSchema, ReceiveOptionsSchema, Result, SharingServiceConfigSchema, validateEncodedShareData, validateReceiveOptions, validateSharingServiceConfig };
|
|
@@ -74,7 +74,8 @@ var DelegationErrorCodes = {
|
|
|
74
74
|
INVALID_TOKEN: "INVALID_TOKEN",
|
|
75
75
|
KV_SERVICE_UNAVAILABLE: "KV_SERVICE_UNAVAILABLE",
|
|
76
76
|
DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
|
|
77
|
-
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
77
|
+
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
78
|
+
UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION"
|
|
78
79
|
};
|
|
79
80
|
var DelegationSchema = z.object({
|
|
80
81
|
/** Content identifier (CID) of the delegation */
|
|
@@ -423,26 +424,8 @@ var CreateDelegationWasmResultSchema = z.object({
|
|
|
423
424
|
resources: z.array(DelegatedResourceSchema)
|
|
424
425
|
});
|
|
425
426
|
|
|
426
|
-
// src/expiry.ts
|
|
427
|
-
var EPHEMERAL_MS = 60 * 60 * 1e3;
|
|
428
|
-
var SIGNED_READ_URL_MS = 5 * 60 * 1e3;
|
|
429
|
-
var SESSION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
430
|
-
var SHARE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
431
|
-
var APP_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
432
|
-
var MAX_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
433
|
-
var EXPIRY = {
|
|
434
|
-
EPHEMERAL_MS,
|
|
435
|
-
SIGNED_READ_URL_MS,
|
|
436
|
-
SESSION_MS,
|
|
437
|
-
SHARE_MS,
|
|
438
|
-
APP_MS,
|
|
439
|
-
MAX_MS
|
|
440
|
-
};
|
|
441
|
-
var DEFAULT_SIGNED_READ_URL_EXPIRY_MS = EXPIRY.SIGNED_READ_URL_MS;
|
|
442
|
-
|
|
443
427
|
// src/delegations/DelegationManager.ts
|
|
444
428
|
var DelegationAction = {
|
|
445
|
-
CREATE: "tinycloud.delegation/create",
|
|
446
429
|
REVOKE: "tinycloud.delegation/revoke",
|
|
447
430
|
STATUS: "tinycloud.delegation/status",
|
|
448
431
|
LIST: "tinycloud.delegation/list",
|
|
@@ -458,6 +441,21 @@ function createError(code3, message, cause, meta) {
|
|
|
458
441
|
meta
|
|
459
442
|
};
|
|
460
443
|
}
|
|
444
|
+
async function readInvokedJson(response, action) {
|
|
445
|
+
const text = await response.text();
|
|
446
|
+
if (text.trim() === "") {
|
|
447
|
+
return {
|
|
448
|
+
ok: false,
|
|
449
|
+
error: createError(
|
|
450
|
+
DelegationErrorCodes.UNSUPPORTED_OPERATION,
|
|
451
|
+
`The node answered ${action} with an empty ${response.status} response; it does not support this operation`,
|
|
452
|
+
void 0,
|
|
453
|
+
{ status: response.status, action }
|
|
454
|
+
)
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return { ok: true, data: JSON.parse(text) };
|
|
458
|
+
}
|
|
461
459
|
var DelegationManager = class {
|
|
462
460
|
/**
|
|
463
461
|
* Creates a new DelegationManager instance.
|
|
@@ -498,114 +496,6 @@ var DelegationManager = class {
|
|
|
498
496
|
body
|
|
499
497
|
});
|
|
500
498
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Creates a new delegation.
|
|
503
|
-
*
|
|
504
|
-
* Delegates specific permissions to another DID for a given path.
|
|
505
|
-
* The delegatee can then use these permissions to access resources
|
|
506
|
-
* within the specified scope.
|
|
507
|
-
*
|
|
508
|
-
* @param params - Parameters for the delegation
|
|
509
|
-
* @returns Result containing the created Delegation or an error
|
|
510
|
-
*
|
|
511
|
-
* @example
|
|
512
|
-
* ```typescript
|
|
513
|
-
* const result = await manager.create({
|
|
514
|
-
* delegateDID: bob.did,
|
|
515
|
-
* path: "documents/shared/",
|
|
516
|
-
* actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
|
|
517
|
-
* expiry: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days
|
|
518
|
-
* });
|
|
519
|
-
* ```
|
|
520
|
-
*/
|
|
521
|
-
async create(params) {
|
|
522
|
-
if (!params.delegateDID) {
|
|
523
|
-
return {
|
|
524
|
-
ok: false,
|
|
525
|
-
error: createError(
|
|
526
|
-
DelegationErrorCodes.INVALID_INPUT,
|
|
527
|
-
"delegateDID is required"
|
|
528
|
-
)
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
if (!params.path) {
|
|
532
|
-
return {
|
|
533
|
-
ok: false,
|
|
534
|
-
error: createError(
|
|
535
|
-
DelegationErrorCodes.INVALID_INPUT,
|
|
536
|
-
"path is required"
|
|
537
|
-
)
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
if (!params.actions || params.actions.length === 0) {
|
|
541
|
-
return {
|
|
542
|
-
ok: false,
|
|
543
|
-
error: createError(
|
|
544
|
-
DelegationErrorCodes.INVALID_INPUT,
|
|
545
|
-
"at least one action is required"
|
|
546
|
-
)
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
try {
|
|
550
|
-
const body = JSON.stringify({
|
|
551
|
-
delegateDID: params.delegateDID,
|
|
552
|
-
path: params.path,
|
|
553
|
-
actions: params.actions,
|
|
554
|
-
expiry: params.expiry?.toISOString(),
|
|
555
|
-
disableSubDelegation: params.disableSubDelegation ?? false,
|
|
556
|
-
statement: params.statement
|
|
557
|
-
});
|
|
558
|
-
const response = await this.invokeOperation(
|
|
559
|
-
params.path,
|
|
560
|
-
DelegationAction.CREATE,
|
|
561
|
-
body
|
|
562
|
-
);
|
|
563
|
-
if (!response.ok) {
|
|
564
|
-
const errorText = await response.text();
|
|
565
|
-
return {
|
|
566
|
-
ok: false,
|
|
567
|
-
error: createError(
|
|
568
|
-
DelegationErrorCodes.CREATION_FAILED,
|
|
569
|
-
`Failed to create delegation: ${response.status} - ${errorText}`,
|
|
570
|
-
void 0,
|
|
571
|
-
{ status: response.status, path: params.path }
|
|
572
|
-
)
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
const apiResponse = await response.json();
|
|
576
|
-
const delegation = {
|
|
577
|
-
cid: apiResponse.cid ?? "",
|
|
578
|
-
delegateDID: params.delegateDID,
|
|
579
|
-
spaceId: this.session.spaceId,
|
|
580
|
-
path: params.path,
|
|
581
|
-
actions: params.actions,
|
|
582
|
-
expiry: params.expiry ?? new Date(Date.now() + EXPIRY.SHARE_MS),
|
|
583
|
-
isRevoked: false,
|
|
584
|
-
allowSubDelegation: !(params.disableSubDelegation ?? false),
|
|
585
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
586
|
-
};
|
|
587
|
-
return { ok: true, data: delegation };
|
|
588
|
-
} catch (error) {
|
|
589
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
590
|
-
return {
|
|
591
|
-
ok: false,
|
|
592
|
-
error: createError(
|
|
593
|
-
DelegationErrorCodes.ABORTED,
|
|
594
|
-
"Request aborted",
|
|
595
|
-
error
|
|
596
|
-
)
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
ok: false,
|
|
601
|
-
error: createError(
|
|
602
|
-
DelegationErrorCodes.NETWORK_ERROR,
|
|
603
|
-
`Network error during delegation creation: ${String(error)}`,
|
|
604
|
-
error instanceof Error ? error : void 0
|
|
605
|
-
)
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
499
|
/**
|
|
610
500
|
* Revokes an existing delegation.
|
|
611
501
|
*
|
|
@@ -834,19 +724,33 @@ var DelegationManager = class {
|
|
|
834
724
|
};
|
|
835
725
|
}
|
|
836
726
|
try {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
727
|
+
let response;
|
|
728
|
+
for (const spaceId of /* @__PURE__ */ new Set([accountSpaceId, this.session.spaceId])) {
|
|
729
|
+
const headers = Object.fromEntries(new Headers(this.invokeAny(this.session, [{
|
|
730
|
+
spaceId,
|
|
731
|
+
service: "delegation",
|
|
732
|
+
path: "",
|
|
733
|
+
action: DelegationAction.LIST
|
|
734
|
+
}])).entries());
|
|
735
|
+
headers["content-type"] = "application/json";
|
|
736
|
+
response = await this.fetchFn(`${this.host}/delegation/query`, {
|
|
737
|
+
method: "POST",
|
|
738
|
+
headers,
|
|
739
|
+
body: JSON.stringify(validated.data)
|
|
740
|
+
});
|
|
741
|
+
if (response.status !== 403) break;
|
|
742
|
+
}
|
|
743
|
+
if (!response || response.status === 403) {
|
|
744
|
+
return {
|
|
745
|
+
ok: false,
|
|
746
|
+
error: createError(
|
|
747
|
+
DelegationErrorCodes.PERMISSION_DENIED,
|
|
748
|
+
"This session does not hold tinycloud.delegation/list on the account space or its own space",
|
|
749
|
+
void 0,
|
|
750
|
+
{ status: 403 }
|
|
751
|
+
)
|
|
752
|
+
};
|
|
753
|
+
}
|
|
850
754
|
if (!response.ok) {
|
|
851
755
|
const errorText = await response.text();
|
|
852
756
|
return {
|
|
@@ -881,75 +785,6 @@ var DelegationManager = class {
|
|
|
881
785
|
};
|
|
882
786
|
}
|
|
883
787
|
}
|
|
884
|
-
/**
|
|
885
|
-
* Lists all delegations for the current session's space.
|
|
886
|
-
*
|
|
887
|
-
* Returns both delegations created by the current user (as delegator)
|
|
888
|
-
* and delegations granted to the current user (as delegatee).
|
|
889
|
-
*
|
|
890
|
-
* @returns Result containing an array of Delegations or an error
|
|
891
|
-
*
|
|
892
|
-
* @example
|
|
893
|
-
* ```typescript
|
|
894
|
-
* const result = await manager.list();
|
|
895
|
-
* if (result.ok) {
|
|
896
|
-
* for (const delegation of result.data) {
|
|
897
|
-
* console.log(`${delegation.cid}: ${delegation.path} -> ${delegation.delegateDID}`);
|
|
898
|
-
* }
|
|
899
|
-
* }
|
|
900
|
-
* ```
|
|
901
|
-
*/
|
|
902
|
-
async list() {
|
|
903
|
-
try {
|
|
904
|
-
const response = await this.invokeOperation("", DelegationAction.LIST);
|
|
905
|
-
if (!response.ok) {
|
|
906
|
-
const errorText = await response.text();
|
|
907
|
-
return {
|
|
908
|
-
ok: false,
|
|
909
|
-
error: createError(
|
|
910
|
-
DelegationErrorCodes.NETWORK_ERROR,
|
|
911
|
-
`Failed to list delegations: ${response.status} - ${errorText}`,
|
|
912
|
-
void 0,
|
|
913
|
-
{ status: response.status }
|
|
914
|
-
)
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
const data = await response.json();
|
|
918
|
-
const delegations = data.map((item) => ({
|
|
919
|
-
cid: item.cid,
|
|
920
|
-
delegateDID: item.delegateDID,
|
|
921
|
-
delegatorDID: item.delegatorDID,
|
|
922
|
-
spaceId: item.spaceId,
|
|
923
|
-
path: item.path,
|
|
924
|
-
actions: item.actions,
|
|
925
|
-
expiry: new Date(item.expiry),
|
|
926
|
-
isRevoked: item.isRevoked,
|
|
927
|
-
createdAt: item.createdAt ? new Date(item.createdAt) : void 0,
|
|
928
|
-
parentCid: item.parentCid,
|
|
929
|
-
allowSubDelegation: item.allowSubDelegation
|
|
930
|
-
}));
|
|
931
|
-
return { ok: true, data: delegations };
|
|
932
|
-
} catch (error) {
|
|
933
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
934
|
-
return {
|
|
935
|
-
ok: false,
|
|
936
|
-
error: createError(
|
|
937
|
-
DelegationErrorCodes.ABORTED,
|
|
938
|
-
"Request aborted",
|
|
939
|
-
error
|
|
940
|
-
)
|
|
941
|
-
};
|
|
942
|
-
}
|
|
943
|
-
return {
|
|
944
|
-
ok: false,
|
|
945
|
-
error: createError(
|
|
946
|
-
DelegationErrorCodes.NETWORK_ERROR,
|
|
947
|
-
`Network error during delegation list: ${String(error)}`,
|
|
948
|
-
error instanceof Error ? error : void 0
|
|
949
|
-
)
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
788
|
/**
|
|
954
789
|
* Gets the full delegation chain for a given delegation.
|
|
955
790
|
*
|
|
@@ -1008,7 +843,9 @@ var DelegationManager = class {
|
|
|
1008
843
|
)
|
|
1009
844
|
};
|
|
1010
845
|
}
|
|
1011
|
-
const
|
|
846
|
+
const parsed = await readInvokedJson(response, DelegationAction.GET);
|
|
847
|
+
if (!parsed.ok) return parsed;
|
|
848
|
+
const data = parsed.data;
|
|
1012
849
|
const chain = data.chain.map((item) => ({
|
|
1013
850
|
cid: item.cid,
|
|
1014
851
|
delegateDID: item.delegateDID,
|
|
@@ -1105,8 +942,9 @@ var DelegationManager = class {
|
|
|
1105
942
|
)
|
|
1106
943
|
};
|
|
1107
944
|
}
|
|
1108
|
-
const
|
|
1109
|
-
|
|
945
|
+
const body2 = await readInvokedJson(response, DelegationAction.CHECK);
|
|
946
|
+
if (!body2.ok) return body2;
|
|
947
|
+
return { ok: true, data: body2.data.allowed };
|
|
1110
948
|
} catch (error) {
|
|
1111
949
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1112
950
|
return {
|
|
@@ -1194,14 +1032,6 @@ var SharingServiceConfigSchema = z2.object({
|
|
|
1194
1032
|
(val) => val !== null && typeof val === "object",
|
|
1195
1033
|
{ message: "Expected an ICapabilityKeyRegistry object" }
|
|
1196
1034
|
),
|
|
1197
|
-
/**
|
|
1198
|
-
* Delegation manager for creating delegations.
|
|
1199
|
-
* Required for generate(), optional for receive().
|
|
1200
|
-
*/
|
|
1201
|
-
delegationManager: z2.unknown().refine(
|
|
1202
|
-
(val) => val === void 0 || val !== null && typeof val === "object",
|
|
1203
|
-
{ message: "Expected a DelegationManager object or undefined" }
|
|
1204
|
-
).optional(),
|
|
1205
1035
|
/** Factory for creating KV service instances */
|
|
1206
1036
|
createKVService: z2.unknown().refine(
|
|
1207
1037
|
(val) => typeof val === "function",
|
|
@@ -5306,6 +5136,23 @@ var ShareRecipientClient = class {
|
|
|
5306
5136
|
}
|
|
5307
5137
|
};
|
|
5308
5138
|
|
|
5139
|
+
// src/expiry.ts
|
|
5140
|
+
var EPHEMERAL_MS = 60 * 60 * 1e3;
|
|
5141
|
+
var SIGNED_READ_URL_MS = 5 * 60 * 1e3;
|
|
5142
|
+
var SESSION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
5143
|
+
var SHARE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
5144
|
+
var APP_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
5145
|
+
var MAX_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
5146
|
+
var EXPIRY = {
|
|
5147
|
+
EPHEMERAL_MS,
|
|
5148
|
+
SIGNED_READ_URL_MS,
|
|
5149
|
+
SESSION_MS,
|
|
5150
|
+
SHARE_MS,
|
|
5151
|
+
APP_MS,
|
|
5152
|
+
MAX_MS
|
|
5153
|
+
};
|
|
5154
|
+
var DEFAULT_SIGNED_READ_URL_EXPIRY_MS = EXPIRY.SIGNED_READ_URL_MS;
|
|
5155
|
+
|
|
5309
5156
|
// src/delegations/SharingService.ts
|
|
5310
5157
|
function spaceIdsEqual(left, right) {
|
|
5311
5158
|
const normalizeOwnerAddress = (space) => {
|
|
@@ -5404,7 +5251,6 @@ var SharingService = class {
|
|
|
5404
5251
|
this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
5405
5252
|
this.keyProvider = config.keyProvider;
|
|
5406
5253
|
this.registry = config.registry;
|
|
5407
|
-
this.delegationManager = config.delegationManager;
|
|
5408
5254
|
this.createKVService = config.createKVService;
|
|
5409
5255
|
this.baseUrl = (config.baseUrl ?? "").replace(/\/$/, "");
|
|
5410
5256
|
this.createDelegationFn = config.createDelegation;
|
|
@@ -5430,16 +5276,13 @@ var SharingService = class {
|
|
|
5430
5276
|
}
|
|
5431
5277
|
/**
|
|
5432
5278
|
* Updates the service configuration.
|
|
5433
|
-
* Used to add full capabilities (session,
|
|
5279
|
+
* Used to add full capabilities (session, createDelegation, createDelegationWasm) after signIn.
|
|
5434
5280
|
*/
|
|
5435
5281
|
updateConfig(config) {
|
|
5436
5282
|
this.assertActiveFn?.();
|
|
5437
5283
|
if (config.session !== void 0) {
|
|
5438
5284
|
this.session = config.session;
|
|
5439
5285
|
}
|
|
5440
|
-
if (config.delegationManager !== void 0) {
|
|
5441
|
-
this.delegationManager = config.delegationManager;
|
|
5442
|
-
}
|
|
5443
5286
|
if (config.createDelegation !== void 0) {
|
|
5444
5287
|
this.createDelegationFn = config.createDelegation;
|
|
5445
5288
|
}
|
|
@@ -5478,12 +5321,12 @@ var SharingService = class {
|
|
|
5478
5321
|
)
|
|
5479
5322
|
};
|
|
5480
5323
|
}
|
|
5481
|
-
if (!this.createDelegationWasmFn && !this.createDelegationFn
|
|
5324
|
+
if (!this.createDelegationWasmFn && !this.createDelegationFn) {
|
|
5482
5325
|
return {
|
|
5483
5326
|
ok: false,
|
|
5484
5327
|
error: createError2(
|
|
5485
5328
|
DelegationErrorCodes.NOT_INITIALIZED,
|
|
5486
|
-
"
|
|
5329
|
+
"createDelegation or createDelegationWasm function required for generating sharing links."
|
|
5487
5330
|
)
|
|
5488
5331
|
};
|
|
5489
5332
|
}
|
|
@@ -5835,7 +5678,7 @@ var SharingService = class {
|
|
|
5835
5678
|
expiry,
|
|
5836
5679
|
disableSubDelegation: false
|
|
5837
5680
|
};
|
|
5838
|
-
const delegationResult =
|
|
5681
|
+
const delegationResult = await this.createDelegationFn(delegationParams);
|
|
5839
5682
|
const delegationCreationActiveError = this.retiredGraphError();
|
|
5840
5683
|
if (delegationCreationActiveError) return { ok: false, error: delegationCreationActiveError };
|
|
5841
5684
|
if (!delegationResult.ok) {
|