1 import type { Address, Api, Member, SignedKeyList } from '../interfaces';
2 import type { UnprivatizeMemberResult } from '../keys/unprivatization';
3 import queryPages from './helpers/queryPages';
4 import type { PaginationParams } from './interface';
6 export const queryMembers = (params?: PaginationParams) => ({
8 url: 'core/v4/members',
15 export const getAllMembers = (api: Api) => {
16 return queryPages((Page, PageSize) => {
17 return api<{ Members: Member[]; Total: number }>(
24 return pages.flatMap(({ Members }) => Members);
28 export const getMember = (memberID: string) => ({
30 url: `core/v4/members/${memberID}`,
33 export const getSelfMember = () => ({
35 url: 'core/v4/members/me',
38 export const queryAddresses = (memberID: string, params?: PaginationParams) => ({
40 url: `core/v4/members/${memberID}/addresses`,
44 export const getAllMemberAddresses = (api: Api, memberID: string) => {
45 return queryPages((page, pageSize) => {
46 return api<{ Addresses: Address[]; Total: number }>(
47 queryAddresses(memberID, {
53 return pages.flatMap(({ Addresses = [] }) => Addresses);
57 interface MemberPayload {
65 interface UnprivatizationInvitation {
69 PrivateIntent: boolean;
72 interface InviteMemberPayload extends Omit<MemberPayload, 'Private'> {
73 Invitation: UnprivatizationInvitation;
76 export const createMember = (data: MemberPayload | InviteMemberPayload) => ({
78 url: 'core/v4/members',
82 export const queryMemberUnprivatizationInfo = () => ({
84 url: `core/v4/members/me/unprivatize`,
86 export const acceptMemberUnprivatizationInfo = (data: { OrgUserKeys: string[]; OrgActivationToken: string }) => ({
88 url: `core/v4/members/me/unprivatize`,
92 export const deleteMemberUnprivatizationInfo = () => ({
94 url: `core/v4/members/me/unprivatize`,
97 export const unprivatizeMemberKeysRoute = (memberID: string, data: UnprivatizeMemberResult) => ({
99 url: `core/v4/members/${memberID}/keys/unprivatize`,
103 export const checkMemberAddressAvailability = (data: { Local: string; Domain: string }) => ({
105 url: `core/v4/members/addresses/available`,
109 export const createMemberAddress = (memberID: string, data: { Local: string; Domain: string }) => ({
111 url: `core/v4/members/${memberID}/addresses`,
115 export const updateName = (memberID: string, Name: string) => ({
117 url: `core/v4/members/${memberID}/name`,
121 export const updateQuota = (memberID: string, MaxSpace: number) => ({
123 url: `core/v4/members/${memberID}/quota`,
127 export const updateRole = (memberID: string, Role: number) => ({
129 url: `core/v4/members/${memberID}/role`,
133 export const activatePasswordlessKey = (data: { TokenKeyPacket: string; Signature: string }) => ({
135 url: `core/v4/organizations/keys/activate`,
139 export const updateRolePasswordless = ({
147 OrganizationKeyActivation: { TokenKeyPacket: string; Signature: string };
150 OrganizationKeyInvitation: {
151 TokenKeyPacket: string;
153 SignatureAddressID: string;
154 EncryptionAddressID: string;
159 url: `core/v4/members/${memberID}/role`,
163 export const updateVPN = (memberID: string, MaxVPN: number) => ({
165 url: `core/v4/members/${memberID}/vpn`,
169 export const updateAI = (memberID: string, MaxAI: number) => ({
171 url: `core/v4/members/${memberID}/ai`,
175 export interface RequestMemberUnprivatizationInput {
176 InvitationData: string;
177 InvitationSignature: string;
180 export const requestUnprivatization = (memberID: string, data: RequestMemberUnprivatizationInput) => ({
182 url: `core/v4/members/${memberID}/unprivatize`,
186 export const deleteUnprivatizationRequest = (memberID: string) => ({
188 url: `core/v4/members/${memberID}/unprivatize`,
191 export const resendUnprivatizationLink = (memberID: string) => ({
193 url: `core/v4/members/${memberID}/unprivatize/resend`,
196 export const privatizeMember = (memberID: string) => ({
198 url: `core/v4/members/${memberID}/privatize`,
201 export const authMember = (memberID: string, data: { Unlock?: boolean } = {}) => ({
203 url: `core/v4/members/${memberID}/auth`,
207 export const inviteMember = (email: string, maxSpace: number) => ({
208 url: `core/v4/members/invitations`,
216 export const deleteMember = (memberId: string) => ({
217 url: `core/v4/members/${memberId}`,
221 export const removeSSOSamlMember = (memberID: string) => ({
222 url: `core/v4/members/${memberID}/saml`,
226 export const addSSOSamlMember = (memberID: string) => ({
227 url: `core/v4/members/${memberID}/saml`,
231 export const editMemberInvitation = (memberID: string, maxSpace: number) => ({
233 url: `core/v4/members/invitations/${memberID}`,
239 export const updateAddressFlags = (
243 SignedKeyList: SignedKeyList
246 url: `core/v4/addresses/${addressID}/encryption`,
248 Encrypt: Encrypt ? 1 : 0,