Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / lib / shares / share.parser.ts
blobb7cc6ff5ae23ee76299c6092154847305e8386ff
1 import { PassCrypto } from '@proton/pass/lib/crypto';
2 import { getAllShareKeys, getShareLatestEventId } from '@proton/pass/lib/shares/share.requests';
3 import { decodeVaultContent } from '@proton/pass/lib/vaults/vault-proto.transformer';
4 import type { Maybe, Share, ShareGetResponse, ShareKeyResponse, ShareType } from '@proton/pass/types';
6 export const parseShareResponse = async (
7     encryptedShare: ShareGetResponse,
8     options?: { eventId?: string; shareKeys?: ShareKeyResponse[] }
9 ): Promise<Maybe<Share<ShareType.Vault>>> => {
10     const shareId = encryptedShare.ShareID;
11     const [shareKeys, eventId] = await Promise.all([
12         options?.shareKeys ?? getAllShareKeys(shareId),
13         options?.eventId ?? getShareLatestEventId(shareId),
14     ]);
16     const share = await PassCrypto.openShare<ShareType.Vault>({ encryptedShare, shareKeys });
18     if (share) {
19         return {
20             content: decodeVaultContent(share.content),
21             createTime: share.createTime,
22             eventId,
23             newUserInvitesReady: share.newUserInvitesReady,
24             owner: share.owner,
25             shared: share.shared,
26             shareId: share.shareId,
27             shareRoleId: share.shareRoleId,
28             targetId: share.targetId,
29             targetMembers: share.targetMembers,
30             targetMaxMembers: share.targetMaxMembers,
31             targetType: share.targetType,
32             vaultId: share.vaultId,
33         };
34     }