1 import { api } from '@proton/pass/lib/api/api';
2 import { type ShareGetResponse, type ShareKeyResponse, type ShareRole } from '@proton/pass/types';
3 import { type ShareMember } from '@proton/pass/types/data/invites';
4 import type { ShareEditMemberAccessIntent, ShareRemoveMemberAccessIntent } from '@proton/pass/types/data/shares.dto';
6 /* ⚠️ This endpoint is not paginated yet back-end side. */
7 export const getAllShareKeys = async (shareId: string): Promise<ShareKeyResponse[]> => {
8 const response = await api({
9 url: `pass/v1/share/${shareId}/key`,
14 return response.ShareKeys?.Keys ?? [];
17 export const getShareLatestEventId = async (shareId: string): Promise<string> =>
19 url: `pass/v1/share/${shareId}/event`,
22 .then(({ EventID }) => EventID!)
25 export const requestShares = async (): Promise<ShareGetResponse[]> =>
33 export const deleteShare = async (shareId: string) => api({ url: `pass/v1/share/${shareId}`, method: 'delete' });
35 export const loadShareMembers = async (shareId: string): Promise<ShareMember[]> => {
36 const { Shares: members } = await api({
37 url: `pass/v1/share/${shareId}/user`,
41 return members.map((member) => ({
42 shareId: member.ShareID,
43 name: member.UserName,
44 email: member.UserEmail,
46 targetType: member.TargetType,
47 targetId: member.TargetID,
48 shareRoleId: member.ShareRoleID as ShareRole,
49 expireTime: member.ExpireTime,
50 createTime: member.CreateTime,
54 export const removeUserAccess = async ({ shareId, userShareId }: ShareRemoveMemberAccessIntent) =>
56 url: `pass/v1/share/${shareId}/user/${userShareId}`,
60 export const editMemberAccess = async ({ shareId, userShareId, shareRoleId }: ShareEditMemberAccessIntent) =>
62 url: `pass/v1/share/${shareId}/user/${userShareId}`,
64 data: { ShareRoleID: shareRoleId, ExpireTime: null },