@tinycloud/share-sdk 1.0.1-beta.0 → 1.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/index.cjs +74 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +73 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -707,6 +707,8 @@ interface SenderShareRecord {
|
|
|
707
707
|
readonly filename?: string;
|
|
708
708
|
/** Policy/v3 delivery material. The containing history record must remain encrypted at rest. */
|
|
709
709
|
readonly deliveryMaterial?: PublishedShareDeliveryMaterial;
|
|
710
|
+
/** Canonical mailboxes whose invitation delivery was confirmed; history is encrypted at rest. */
|
|
711
|
+
readonly deliveredRecipients?: readonly string[];
|
|
710
712
|
}
|
|
711
713
|
/** Create the durable encrypted-history shape from canonical publication receipts. */
|
|
712
714
|
declare function historyRecordForPublishedShare(result: PublishedShare, now?: Date): SenderShareRecord;
|
|
@@ -720,6 +722,9 @@ declare function historyRecordForPublishedShare(result: PublishedShare, now?: Da
|
|
|
720
722
|
type SenderShareRevocationScope = "direct" | "ancestor";
|
|
721
723
|
interface SenderShareRecordStorage {
|
|
722
724
|
put(record: SenderShareRecord): Promise<void>;
|
|
725
|
+
/** Atomically transform the latest record, if present. Implementations that
|
|
726
|
+
* provide this must serialize the read and write with every other writer. */
|
|
727
|
+
update?(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
|
|
723
728
|
list(): Promise<readonly SenderShareRecord[]>;
|
|
724
729
|
get(shareId: string): Promise<SenderShareRecord | undefined>;
|
|
725
730
|
delete(shareId: string): Promise<void>;
|
|
@@ -737,7 +742,10 @@ interface SenderShareKeyStorage {
|
|
|
737
742
|
/** In-memory reference implementation. Real deployments back these with IndexedDB so the non-extractable `CryptoKey` survives a reload via structured clone. */
|
|
738
743
|
declare class MemorySenderShareRecordStorage implements SenderShareRecordStorage {
|
|
739
744
|
private readonly records;
|
|
745
|
+
private operation;
|
|
746
|
+
private serialize;
|
|
740
747
|
put(record: SenderShareRecord): Promise<void>;
|
|
748
|
+
update(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
|
|
741
749
|
list(): Promise<readonly SenderShareRecord[]>;
|
|
742
750
|
get(shareId: string): Promise<SenderShareRecord | undefined>;
|
|
743
751
|
delete(shareId: string): Promise<void>;
|
|
@@ -809,6 +817,7 @@ interface ShareNotifyResult {
|
|
|
809
817
|
readonly idempotencyKey: string;
|
|
810
818
|
readonly attempts: number;
|
|
811
819
|
readonly retryable?: boolean;
|
|
820
|
+
readonly reason?: "delivery-window-expired";
|
|
812
821
|
}
|
|
813
822
|
interface ShareNotifyInput {
|
|
814
823
|
readonly shareId: string;
|
|
@@ -822,8 +831,9 @@ interface ShareDeliveryAdapter {
|
|
|
822
831
|
deliver(input: ShareNotifyInput): Promise<"delivered" | "already-delivered">;
|
|
823
832
|
}
|
|
824
833
|
declare class ShareNotifyError extends Error {
|
|
834
|
+
readonly reason?: "delivery-window-expired" | undefined;
|
|
825
835
|
readonly code: "delivery-failed";
|
|
826
|
-
constructor(message?: string);
|
|
836
|
+
constructor(message?: string, reason?: "delivery-window-expired" | undefined);
|
|
827
837
|
}
|
|
828
838
|
/**
|
|
829
839
|
* Match a delivery address against the recipient constraint recorded when the
|
|
@@ -831,6 +841,8 @@ declare class ShareNotifyError extends Error {
|
|
|
831
841
|
* the only form the credential issuer accepts.
|
|
832
842
|
*/
|
|
833
843
|
declare function recipientMatchesShareRecord(record: SenderShareRecord, recipient: string): boolean;
|
|
844
|
+
/** The sender can authorize a fresh invitation only until this persisted deadline. */
|
|
845
|
+
declare function shareDeliveryWindowExpiresAt(record: SenderShareRecord): number;
|
|
834
846
|
/**
|
|
835
847
|
* Delivery is deliberately separate from publication. A failed notification
|
|
836
848
|
* never causes a second envelope or link to be minted.
|
|
@@ -843,6 +855,8 @@ declare function notifyShare(input: {
|
|
|
843
855
|
readonly idempotencyKey?: string;
|
|
844
856
|
readonly maxAttempts?: number;
|
|
845
857
|
readonly signal?: AbortSignal;
|
|
858
|
+
/** Check the persisted delivery window locally before calling the adapter. */
|
|
859
|
+
readonly checkDeliveryWindow?: boolean;
|
|
846
860
|
}): Promise<ShareNotifyResult>;
|
|
847
861
|
|
|
848
862
|
/** The signed, app-neutral receipt accepted by OpenCredentials' invitation endpoint. */
|
|
@@ -1133,4 +1147,4 @@ declare function parseNativeShareUrl(value: string): string;
|
|
|
1133
1147
|
/** Receive through the public SDK without creating another transport protocol. */
|
|
1134
1148
|
declare function openNativeShare(sharing: NativeSharingService, link: string): Promise<unknown>;
|
|
1135
1149
|
|
|
1136
|
-
export { type AddressedOwnerRootInput, type AddressedOwnerRootReceipt, type AddressedPolicyRegistrationInput, type AddressedPolicyRegistrationReceipt, type AddressedPublishAuthority, type AddressedSharePublishOptions, type AddressedShareRequest, type CreateOwnerDelegationParams, CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, DEFAULT_SHARE_LIFETIME_MS, type DelegatedShareKey, EncryptedSenderShareHistory, type EncryptedShareHistoryStorage, MAX_CONTENT_BYTES, MemoryEncryptedShareHistoryStorage, MemorySenderShareKeyStorage, MemorySenderShareRecordStorage, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, OWNER_SHARE_REGISTRATION_DOMAIN, type OwnerDelegationPermission, type OwnerDelegationReceipt, type OwnerShareAction, type OwnerShareDecryption, type OwnerShareMatcher, type OwnerSharePolicyRegistration, type OwnerSharePolicyRegistrationReceipt, type OwnerSharePolicyV2, type ParsedAddressedEnvelope, type PreparedAddressedShare, type PublishedShare, type PublishedShareDeliveryMaterial, type PublishedShareMetadata, type RegisterOwnerSharePolicyParams, SHARE_CONTENT_LIMIT, SHARE_PUBLISH_RESULT_VERSION, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, type SenderShareKeyStorage, type SenderShareRecord, type SenderShareRecordStorage, type SenderShareRevocationScope, SenderShareStore, type ShareAuthorizationAdapter, type ShareAuthorizationDenied, type ShareAuthorizationMethod, type ShareAuthorizationReady, type ShareAuthorizationRequired, type ShareAuthorizationResult, type ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, SharePublishError, type SharePublishErrorCode, type SharePublishOptions, type SharePublishTarget, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, type ShareTarget, type SignedDelegation, type TargetPublishAdapter, type TargetPublishInput, type TargetPublishOutcome, addressedCredentialRequirement, authorizationMethodForTarget, authorizeShare, canonicalOwnerSharePolicy, canonicalShareFilename, claimShare, computeOwnerShareRegistrationCid, createAddressedAuthorization, createDelegatedShareKey, createNativeShare, createPolicyEnforcementDelegation, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, historyRecordForPublishedShare, inspectShare, listShares, normalizeShareTarget, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, prepareAddressedShare, publishAddressedShare, publishPolicyShare, publishTargetShare, receiveShare, recipientMatchesShareRecord, redactPublishedShare, restoreDelegatedShareKey, resumeShareAuthorization, revokeShare, showShare, targetAuthorizationMethod, toShareErrorInfo, validateOwnerSharePolicyRegistration, validateOwnerSharePolicyRegistrationBytes };
|
|
1150
|
+
export { type AddressedOwnerRootInput, type AddressedOwnerRootReceipt, type AddressedPolicyRegistrationInput, type AddressedPolicyRegistrationReceipt, type AddressedPublishAuthority, type AddressedSharePublishOptions, type AddressedShareRequest, type CreateOwnerDelegationParams, CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, DEFAULT_SHARE_LIFETIME_MS, type DelegatedShareKey, EncryptedSenderShareHistory, type EncryptedShareHistoryStorage, MAX_CONTENT_BYTES, MemoryEncryptedShareHistoryStorage, MemorySenderShareKeyStorage, MemorySenderShareRecordStorage, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, OWNER_SHARE_REGISTRATION_DOMAIN, type OwnerDelegationPermission, type OwnerDelegationReceipt, type OwnerShareAction, type OwnerShareDecryption, type OwnerShareMatcher, type OwnerSharePolicyRegistration, type OwnerSharePolicyRegistrationReceipt, type OwnerSharePolicyV2, type ParsedAddressedEnvelope, type PreparedAddressedShare, type PublishedShare, type PublishedShareDeliveryMaterial, type PublishedShareMetadata, type RegisterOwnerSharePolicyParams, SHARE_CONTENT_LIMIT, SHARE_PUBLISH_RESULT_VERSION, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, type SenderShareKeyStorage, type SenderShareRecord, type SenderShareRecordStorage, type SenderShareRevocationScope, SenderShareStore, type ShareAuthorizationAdapter, type ShareAuthorizationDenied, type ShareAuthorizationMethod, type ShareAuthorizationReady, type ShareAuthorizationRequired, type ShareAuthorizationResult, type ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, SharePublishError, type SharePublishErrorCode, type SharePublishOptions, type SharePublishTarget, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, type ShareTarget, type SignedDelegation, type TargetPublishAdapter, type TargetPublishInput, type TargetPublishOutcome, addressedCredentialRequirement, authorizationMethodForTarget, authorizeShare, canonicalOwnerSharePolicy, canonicalShareFilename, claimShare, computeOwnerShareRegistrationCid, createAddressedAuthorization, createDelegatedShareKey, createNativeShare, createPolicyEnforcementDelegation, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, historyRecordForPublishedShare, inspectShare, listShares, normalizeShareTarget, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, prepareAddressedShare, publishAddressedShare, publishPolicyShare, publishTargetShare, receiveShare, recipientMatchesShareRecord, redactPublishedShare, restoreDelegatedShareKey, resumeShareAuthorization, revokeShare, shareDeliveryWindowExpiresAt, showShare, targetAuthorizationMethod, toShareErrorInfo, validateOwnerSharePolicyRegistration, validateOwnerSharePolicyRegistrationBytes };
|
package/dist/index.d.ts
CHANGED
|
@@ -707,6 +707,8 @@ interface SenderShareRecord {
|
|
|
707
707
|
readonly filename?: string;
|
|
708
708
|
/** Policy/v3 delivery material. The containing history record must remain encrypted at rest. */
|
|
709
709
|
readonly deliveryMaterial?: PublishedShareDeliveryMaterial;
|
|
710
|
+
/** Canonical mailboxes whose invitation delivery was confirmed; history is encrypted at rest. */
|
|
711
|
+
readonly deliveredRecipients?: readonly string[];
|
|
710
712
|
}
|
|
711
713
|
/** Create the durable encrypted-history shape from canonical publication receipts. */
|
|
712
714
|
declare function historyRecordForPublishedShare(result: PublishedShare, now?: Date): SenderShareRecord;
|
|
@@ -720,6 +722,9 @@ declare function historyRecordForPublishedShare(result: PublishedShare, now?: Da
|
|
|
720
722
|
type SenderShareRevocationScope = "direct" | "ancestor";
|
|
721
723
|
interface SenderShareRecordStorage {
|
|
722
724
|
put(record: SenderShareRecord): Promise<void>;
|
|
725
|
+
/** Atomically transform the latest record, if present. Implementations that
|
|
726
|
+
* provide this must serialize the read and write with every other writer. */
|
|
727
|
+
update?(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
|
|
723
728
|
list(): Promise<readonly SenderShareRecord[]>;
|
|
724
729
|
get(shareId: string): Promise<SenderShareRecord | undefined>;
|
|
725
730
|
delete(shareId: string): Promise<void>;
|
|
@@ -737,7 +742,10 @@ interface SenderShareKeyStorage {
|
|
|
737
742
|
/** In-memory reference implementation. Real deployments back these with IndexedDB so the non-extractable `CryptoKey` survives a reload via structured clone. */
|
|
738
743
|
declare class MemorySenderShareRecordStorage implements SenderShareRecordStorage {
|
|
739
744
|
private readonly records;
|
|
745
|
+
private operation;
|
|
746
|
+
private serialize;
|
|
740
747
|
put(record: SenderShareRecord): Promise<void>;
|
|
748
|
+
update(shareId: string, change: (record: SenderShareRecord) => SenderShareRecord | Promise<SenderShareRecord>): Promise<SenderShareRecord | undefined>;
|
|
741
749
|
list(): Promise<readonly SenderShareRecord[]>;
|
|
742
750
|
get(shareId: string): Promise<SenderShareRecord | undefined>;
|
|
743
751
|
delete(shareId: string): Promise<void>;
|
|
@@ -809,6 +817,7 @@ interface ShareNotifyResult {
|
|
|
809
817
|
readonly idempotencyKey: string;
|
|
810
818
|
readonly attempts: number;
|
|
811
819
|
readonly retryable?: boolean;
|
|
820
|
+
readonly reason?: "delivery-window-expired";
|
|
812
821
|
}
|
|
813
822
|
interface ShareNotifyInput {
|
|
814
823
|
readonly shareId: string;
|
|
@@ -822,8 +831,9 @@ interface ShareDeliveryAdapter {
|
|
|
822
831
|
deliver(input: ShareNotifyInput): Promise<"delivered" | "already-delivered">;
|
|
823
832
|
}
|
|
824
833
|
declare class ShareNotifyError extends Error {
|
|
834
|
+
readonly reason?: "delivery-window-expired" | undefined;
|
|
825
835
|
readonly code: "delivery-failed";
|
|
826
|
-
constructor(message?: string);
|
|
836
|
+
constructor(message?: string, reason?: "delivery-window-expired" | undefined);
|
|
827
837
|
}
|
|
828
838
|
/**
|
|
829
839
|
* Match a delivery address against the recipient constraint recorded when the
|
|
@@ -831,6 +841,8 @@ declare class ShareNotifyError extends Error {
|
|
|
831
841
|
* the only form the credential issuer accepts.
|
|
832
842
|
*/
|
|
833
843
|
declare function recipientMatchesShareRecord(record: SenderShareRecord, recipient: string): boolean;
|
|
844
|
+
/** The sender can authorize a fresh invitation only until this persisted deadline. */
|
|
845
|
+
declare function shareDeliveryWindowExpiresAt(record: SenderShareRecord): number;
|
|
834
846
|
/**
|
|
835
847
|
* Delivery is deliberately separate from publication. A failed notification
|
|
836
848
|
* never causes a second envelope or link to be minted.
|
|
@@ -843,6 +855,8 @@ declare function notifyShare(input: {
|
|
|
843
855
|
readonly idempotencyKey?: string;
|
|
844
856
|
readonly maxAttempts?: number;
|
|
845
857
|
readonly signal?: AbortSignal;
|
|
858
|
+
/** Check the persisted delivery window locally before calling the adapter. */
|
|
859
|
+
readonly checkDeliveryWindow?: boolean;
|
|
846
860
|
}): Promise<ShareNotifyResult>;
|
|
847
861
|
|
|
848
862
|
/** The signed, app-neutral receipt accepted by OpenCredentials' invitation endpoint. */
|
|
@@ -1133,4 +1147,4 @@ declare function parseNativeShareUrl(value: string): string;
|
|
|
1133
1147
|
/** Receive through the public SDK without creating another transport protocol. */
|
|
1134
1148
|
declare function openNativeShare(sharing: NativeSharingService, link: string): Promise<unknown>;
|
|
1135
1149
|
|
|
1136
|
-
export { type AddressedOwnerRootInput, type AddressedOwnerRootReceipt, type AddressedPolicyRegistrationInput, type AddressedPolicyRegistrationReceipt, type AddressedPublishAuthority, type AddressedSharePublishOptions, type AddressedShareRequest, type CreateOwnerDelegationParams, CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, DEFAULT_SHARE_LIFETIME_MS, type DelegatedShareKey, EncryptedSenderShareHistory, type EncryptedShareHistoryStorage, MAX_CONTENT_BYTES, MemoryEncryptedShareHistoryStorage, MemorySenderShareKeyStorage, MemorySenderShareRecordStorage, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, OWNER_SHARE_REGISTRATION_DOMAIN, type OwnerDelegationPermission, type OwnerDelegationReceipt, type OwnerShareAction, type OwnerShareDecryption, type OwnerShareMatcher, type OwnerSharePolicyRegistration, type OwnerSharePolicyRegistrationReceipt, type OwnerSharePolicyV2, type ParsedAddressedEnvelope, type PreparedAddressedShare, type PublishedShare, type PublishedShareDeliveryMaterial, type PublishedShareMetadata, type RegisterOwnerSharePolicyParams, SHARE_CONTENT_LIMIT, SHARE_PUBLISH_RESULT_VERSION, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, type SenderShareKeyStorage, type SenderShareRecord, type SenderShareRecordStorage, type SenderShareRevocationScope, SenderShareStore, type ShareAuthorizationAdapter, type ShareAuthorizationDenied, type ShareAuthorizationMethod, type ShareAuthorizationReady, type ShareAuthorizationRequired, type ShareAuthorizationResult, type ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, SharePublishError, type SharePublishErrorCode, type SharePublishOptions, type SharePublishTarget, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, type ShareTarget, type SignedDelegation, type TargetPublishAdapter, type TargetPublishInput, type TargetPublishOutcome, addressedCredentialRequirement, authorizationMethodForTarget, authorizeShare, canonicalOwnerSharePolicy, canonicalShareFilename, claimShare, computeOwnerShareRegistrationCid, createAddressedAuthorization, createDelegatedShareKey, createNativeShare, createPolicyEnforcementDelegation, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, historyRecordForPublishedShare, inspectShare, listShares, normalizeShareTarget, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, prepareAddressedShare, publishAddressedShare, publishPolicyShare, publishTargetShare, receiveShare, recipientMatchesShareRecord, redactPublishedShare, restoreDelegatedShareKey, resumeShareAuthorization, revokeShare, showShare, targetAuthorizationMethod, toShareErrorInfo, validateOwnerSharePolicyRegistration, validateOwnerSharePolicyRegistrationBytes };
|
|
1150
|
+
export { type AddressedOwnerRootInput, type AddressedOwnerRootReceipt, type AddressedPolicyRegistrationInput, type AddressedPolicyRegistrationReceipt, type AddressedPublishAuthority, type AddressedSharePublishOptions, type AddressedShareRequest, type CreateOwnerDelegationParams, CredentialInvitationError, type CredentialInvitationErrorCode, type CredentialInvitationReceipt, type CredentialInvitationResult, DEFAULT_MAX_CONTENT_BLOB_BYTES, DEFAULT_MAX_SEALED_BLOB_BYTES, DEFAULT_SHARE_LIFETIME_MS, type DelegatedShareKey, EncryptedSenderShareHistory, type EncryptedShareHistoryStorage, MAX_CONTENT_BYTES, MemoryEncryptedShareHistoryStorage, MemorySenderShareKeyStorage, MemorySenderShareRecordStorage, MemoryShareCache, NATIVE_SHARE_FRAGMENT_PARAMETER, type NativeShareResult, type NativeSharingService, OWNER_SHARE_REGISTRATION_DOMAIN, type OwnerDelegationPermission, type OwnerDelegationReceipt, type OwnerShareAction, type OwnerShareDecryption, type OwnerShareMatcher, type OwnerSharePolicyRegistration, type OwnerSharePolicyRegistrationReceipt, type OwnerSharePolicyV2, type ParsedAddressedEnvelope, type PreparedAddressedShare, type PublishedShare, type PublishedShareDeliveryMaterial, type PublishedShareMetadata, type RegisterOwnerSharePolicyParams, SHARE_CONTENT_LIMIT, SHARE_PUBLISH_RESULT_VERSION, SHARE_RESULT_VERSION, SHARE_V2_PROTOCOL, type SenderShareKeyStorage, type SenderShareRecord, type SenderShareRecordStorage, type SenderShareRevocationScope, SenderShareStore, type ShareAuthorizationAdapter, type ShareAuthorizationDenied, type ShareAuthorizationMethod, type ShareAuthorizationReady, type ShareAuthorizationRequired, type ShareAuthorizationResult, type ShareAuthorizedContent, type ShareCache, type ShareCacheEntry, type ShareCacheKey, type ShareCacheMetadata, type ShareDeliveryAdapter, type ShareErrorCode, type ShareErrorInfo, type ShareFetchOptions, type ShareHistoryView, type ShareInspection, type ShareMetadata, type ShareNodeTrust, ShareNotifyError, type ShareNotifyInput, type ShareNotifyResult, type ShareNotifyState, type SharePolicyChallenge, type SharePolicyDelegationLink, type SharePolicyPublishAdapter, type SharePolicyRootRevocation, type SharePolicySession, type SharePresentationMaterial, SharePublishError, type SharePublishErrorCode, type SharePublishOptions, type SharePublishTarget, type ShareReceiveAuthorizationRequired, ShareReceiveError, type ShareReceiveOutcome, type ShareReceiveResult, ShareRecipientClient, type ShareRecipientClientOptions, type ShareRevocationAdapter, type ShareRevocationResult, type ShareTarget, type SignedDelegation, type TargetPublishAdapter, type TargetPublishInput, type TargetPublishOutcome, addressedCredentialRequirement, authorizationMethodForTarget, authorizeShare, canonicalOwnerSharePolicy, canonicalShareFilename, claimShare, computeOwnerShareRegistrationCid, createAddressedAuthorization, createDelegatedShareKey, createNativeShare, createPolicyEnforcementDelegation, createShareV2HolderBindingArtifact, deliverCredentialInvitation, hasUnsafeFilenameCodePoint, historyRecordForPublishedShare, inspectShare, listShares, normalizeShareTarget, notifyShare, openNativeShare, parseAddressedEnvelope, parseNativeShareUrl, prepareAddressedShare, publishAddressedShare, publishPolicyShare, publishTargetShare, receiveShare, recipientMatchesShareRecord, redactPublishedShare, restoreDelegatedShareKey, resumeShareAuthorization, revokeShare, shareDeliveryWindowExpiresAt, showShare, targetAuthorizationMethod, toShareErrorInfo, validateOwnerSharePolicyRegistration, validateOwnerSharePolicyRegistrationBytes };
|
package/dist/index.js
CHANGED
|
@@ -7700,8 +7700,25 @@ function historyRecordForPublishedShare(result, now = /* @__PURE__ */ new Date()
|
|
|
7700
7700
|
}
|
|
7701
7701
|
var MemorySenderShareRecordStorage = class {
|
|
7702
7702
|
records = /* @__PURE__ */ new Map();
|
|
7703
|
+
operation = Promise.resolve();
|
|
7704
|
+
serialize(action) {
|
|
7705
|
+
const next = this.operation.then(action, action);
|
|
7706
|
+
this.operation = next.then(() => void 0, () => void 0);
|
|
7707
|
+
return next;
|
|
7708
|
+
}
|
|
7703
7709
|
async put(record) {
|
|
7704
|
-
this.
|
|
7710
|
+
return this.serialize(async () => {
|
|
7711
|
+
this.records.set(record.shareId, record);
|
|
7712
|
+
});
|
|
7713
|
+
}
|
|
7714
|
+
async update(shareId, change) {
|
|
7715
|
+
return this.serialize(async () => {
|
|
7716
|
+
const current = this.records.get(shareId);
|
|
7717
|
+
if (current === void 0) return void 0;
|
|
7718
|
+
const updated = await change(current);
|
|
7719
|
+
this.records.set(shareId, updated);
|
|
7720
|
+
return updated;
|
|
7721
|
+
});
|
|
7705
7722
|
}
|
|
7706
7723
|
async list() {
|
|
7707
7724
|
return [...this.records.values()];
|
|
@@ -7710,7 +7727,9 @@ var MemorySenderShareRecordStorage = class {
|
|
|
7710
7727
|
return this.records.get(shareId);
|
|
7711
7728
|
}
|
|
7712
7729
|
async delete(shareId) {
|
|
7713
|
-
this.
|
|
7730
|
+
return this.serialize(async () => {
|
|
7731
|
+
this.records.delete(shareId);
|
|
7732
|
+
});
|
|
7714
7733
|
}
|
|
7715
7734
|
};
|
|
7716
7735
|
var MemorySenderShareKeyStorage = class {
|
|
@@ -7794,6 +7813,11 @@ var SenderShareStore = class {
|
|
|
7794
7813
|
}
|
|
7795
7814
|
/** Mark a share revoked locally after the caller's node-side revoke call succeeds. */
|
|
7796
7815
|
async markRevoked(shareId, revokedAt = this.now().toISOString()) {
|
|
7816
|
+
if (this.records.update !== void 0) {
|
|
7817
|
+
const updated = await this.records.update(shareId, (record2) => ({ ...record2, revokedAt }));
|
|
7818
|
+
if (updated === void 0) throw new Error(`Unknown share: ${shareId}`);
|
|
7819
|
+
return updated;
|
|
7820
|
+
}
|
|
7797
7821
|
const record = await this.records.get(shareId);
|
|
7798
7822
|
if (record === void 0) throw new Error(`Unknown share: ${shareId}`);
|
|
7799
7823
|
const revoked = { ...record, revokedAt };
|
|
@@ -7841,11 +7865,12 @@ var EncryptedSenderShareHistory = class {
|
|
|
7841
7865
|
|
|
7842
7866
|
// src/notify.ts
|
|
7843
7867
|
var ShareNotifyError = class extends Error {
|
|
7844
|
-
|
|
7845
|
-
constructor(message = "share delivery did not complete") {
|
|
7868
|
+
constructor(message = "share delivery did not complete", reason) {
|
|
7846
7869
|
super(message);
|
|
7870
|
+
this.reason = reason;
|
|
7847
7871
|
this.name = "ShareNotifyError";
|
|
7848
7872
|
}
|
|
7873
|
+
code = "delivery-failed";
|
|
7849
7874
|
};
|
|
7850
7875
|
function recipientMatchesShareRecord(record, recipient) {
|
|
7851
7876
|
const matcher = record.recipientMatcher;
|
|
@@ -7855,6 +7880,11 @@ function recipientMatchesShareRecord(record, recipient) {
|
|
|
7855
7880
|
if (matcher.kind === "emailDomain") return mailbox.domain === matcher.value;
|
|
7856
7881
|
return false;
|
|
7857
7882
|
}
|
|
7883
|
+
function shareDeliveryWindowExpiresAt(record) {
|
|
7884
|
+
const expiresAt = Math.min(Date.parse(record.expiresAt), Date.parse(record.registeredAt) + 5 * 60 * 1e3);
|
|
7885
|
+
if (!Number.isFinite(expiresAt)) throw new ShareNotifyError("share delivery history has invalid timestamps");
|
|
7886
|
+
return expiresAt;
|
|
7887
|
+
}
|
|
7858
7888
|
async function notifyShare(input) {
|
|
7859
7889
|
const mailbox = canonicalMailbox(input.recipient);
|
|
7860
7890
|
if (!input.shareId || mailbox === void 0) throw new ShareNotifyError("recipient is invalid");
|
|
@@ -7865,6 +7895,19 @@ async function notifyShare(input) {
|
|
|
7865
7895
|
const idempotencyKey = input.idempotencyKey ?? await defaultIdempotencyKey(input.shareId, recipient);
|
|
7866
7896
|
const attemptsLimit = input.maxAttempts ?? 3;
|
|
7867
7897
|
if (!Number.isSafeInteger(attemptsLimit) || attemptsLimit < 1 || attemptsLimit > 8) throw new ShareNotifyError("maxAttempts is invalid");
|
|
7898
|
+
if (input.signal?.aborted) throw new ShareNotifyError("share delivery was cancelled");
|
|
7899
|
+
if (input.checkDeliveryWindow && input.record !== void 0 && shareDeliveryWindowExpiresAt(input.record) <= Date.now()) {
|
|
7900
|
+
return {
|
|
7901
|
+
protocol: "tinycloud-share",
|
|
7902
|
+
version: 1,
|
|
7903
|
+
shareId: input.shareId,
|
|
7904
|
+
state: "partial-failure",
|
|
7905
|
+
idempotencyKey,
|
|
7906
|
+
attempts: 1,
|
|
7907
|
+
retryable: false,
|
|
7908
|
+
reason: "delivery-window-expired"
|
|
7909
|
+
};
|
|
7910
|
+
}
|
|
7868
7911
|
let attempts = 0;
|
|
7869
7912
|
let lastError;
|
|
7870
7913
|
while (attempts < attemptsLimit) {
|
|
@@ -7872,8 +7915,27 @@ async function notifyShare(input) {
|
|
|
7872
7915
|
attempts += 1;
|
|
7873
7916
|
try {
|
|
7874
7917
|
const state = await input.adapter.deliver({ shareId: input.shareId, recipient, idempotencyKey, ...input.record === void 0 ? {} : { record: input.record }, ...input.signal === void 0 ? {} : { signal: input.signal } });
|
|
7875
|
-
return {
|
|
7918
|
+
return {
|
|
7919
|
+
protocol: "tinycloud-share",
|
|
7920
|
+
version: 1,
|
|
7921
|
+
shareId: input.shareId,
|
|
7922
|
+
state: state === "delivered" && input.record?.deliveredRecipients?.includes(recipient) ? "already-delivered" : state,
|
|
7923
|
+
idempotencyKey,
|
|
7924
|
+
attempts
|
|
7925
|
+
};
|
|
7876
7926
|
} catch (error) {
|
|
7927
|
+
if (error instanceof ShareNotifyError && error.reason === "delivery-window-expired") {
|
|
7928
|
+
return {
|
|
7929
|
+
protocol: "tinycloud-share",
|
|
7930
|
+
version: 1,
|
|
7931
|
+
shareId: input.shareId,
|
|
7932
|
+
state: "partial-failure",
|
|
7933
|
+
idempotencyKey,
|
|
7934
|
+
attempts,
|
|
7935
|
+
retryable: false,
|
|
7936
|
+
reason: "delivery-window-expired"
|
|
7937
|
+
};
|
|
7938
|
+
}
|
|
7877
7939
|
lastError = error;
|
|
7878
7940
|
}
|
|
7879
7941
|
}
|
|
@@ -8036,7 +8098,11 @@ async function revokeShare(input) {
|
|
|
8036
8098
|
});
|
|
8037
8099
|
}
|
|
8038
8100
|
const revokedAt = (input.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
8039
|
-
if (input.records !== void 0)
|
|
8101
|
+
if (input.records?.update !== void 0) {
|
|
8102
|
+
await input.records.update(input.record.shareId, (record) => ({ ...record, revokedAt }));
|
|
8103
|
+
} else if (input.records !== void 0) {
|
|
8104
|
+
await input.records.put({ ...input.record, revokedAt });
|
|
8105
|
+
}
|
|
8040
8106
|
return { state: "revoked", target, delegationCid, revokedAt };
|
|
8041
8107
|
}
|
|
8042
8108
|
function redactRecord(record, revealLink, link) {
|
|
@@ -8662,6 +8728,7 @@ export {
|
|
|
8662
8728
|
restoreDelegatedShareKey,
|
|
8663
8729
|
resumeShareAuthorization,
|
|
8664
8730
|
revokeShare,
|
|
8731
|
+
shareDeliveryWindowExpiresAt,
|
|
8665
8732
|
showShare,
|
|
8666
8733
|
targetAuthorizationMethod,
|
|
8667
8734
|
toBase64Url,
|