Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / pass / lib / shares / share.requests.ts
blob7df305091015c42db157f4173d907dd289af3daa
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`,
10         params: { Page: 0 },
11         method: 'get',
12     });
14     return response.ShareKeys?.Keys ?? [];
17 export const getShareLatestEventId = async (shareId: string): Promise<string> =>
18     api({
19         url: `pass/v1/share/${shareId}/event`,
20         method: 'get',
21     })
22         .then(({ EventID }) => EventID!)
23         .catch(() => '');
25 export const requestShares = async (): Promise<ShareGetResponse[]> =>
26     (
27         await api({
28             url: 'pass/v1/share',
29             method: 'get',
30         })
31     ).Shares;
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`,
38         method: 'get',
39     });
41     return members.map((member) => ({
42         shareId: member.ShareID,
43         name: member.UserName,
44         email: member.UserEmail,
45         owner: member.Owner,
46         targetType: member.TargetType,
47         targetId: member.TargetID,
48         shareRoleId: member.ShareRoleID as ShareRole,
49         expireTime: member.ExpireTime,
50         createTime: member.CreateTime,
51     }));
54 export const removeUserAccess = async ({ shareId, userShareId }: ShareRemoveMemberAccessIntent) =>
55     api({
56         url: `pass/v1/share/${shareId}/user/${userShareId}`,
57         method: 'delete',
58     });
60 export const editMemberAccess = async ({ shareId, userShareId, shareRoleId }: ShareEditMemberAccessIntent) =>
61     api({
62         url: `pass/v1/share/${shareId}/user/${userShareId}`,
63         method: 'put',
64         data: { ShareRoleID: shareRoleId, ExpireTime: null },
65     });