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;
71 interface InviteMemberPayload extends Omit<MemberPayload, 'Private'> {
72 Invitation: UnprivatizationInvitation;
75 export const createMember = (data: MemberPayload | InviteMemberPayload) => ({
77 url: 'core/v4/members',
81 export const queryMemberUnprivatizationInfo = () => ({
83 url: `core/v4/members/me/unprivatize`,
86 export const unprivatizeMemberKeysRoute = (memberID: string, data: UnprivatizeMemberResult) => ({
88 url: `core/v4/members/${memberID}/keys/unprivatize`,
92 export const checkMemberAddressAvailability = (data: { Local: string; Domain: string }) => ({
94 url: `core/v4/members/addresses/available`,
98 export const createMemberAddress = (memberID: string, data: { Local: string; Domain: string }) => ({
100 url: `core/v4/members/${memberID}/addresses`,
104 export const updateName = (memberID: string, Name: string) => ({
106 url: `core/v4/members/${memberID}/name`,
110 export const updateQuota = (memberID: string, MaxSpace: number) => ({
112 url: `core/v4/members/${memberID}/quota`,
116 export const updateRole = (memberID: string, Role: number) => ({
118 url: `core/v4/members/${memberID}/role`,
122 export const activatePasswordlessKey = (data: { TokenKeyPacket: string; Signature: string }) => ({
124 url: `core/v4/organizations/keys/activate`,
128 export const updateRolePasswordless = ({
136 OrganizationKeyActivation: { TokenKeyPacket: string; Signature: string };
139 OrganizationKeyInvitation: {
140 TokenKeyPacket: string;
142 SignatureAddressID: string;
143 EncryptionAddressID: string;
148 url: `core/v4/members/${memberID}/role`,
152 export const updateVPN = (memberID: string, MaxVPN: number) => ({
154 url: `core/v4/members/${memberID}/vpn`,
158 export const updateAI = (memberID: string, MaxAI: number) => ({
160 url: `core/v4/members/${memberID}/ai`,
164 export const resendUnprivatizationLink = (memberID: string) => ({
166 url: `core/v4/members/${memberID}/unprivatize/resend`,
169 export const removeMember = (memberID: string) => ({
171 url: `core/v4/members/${memberID}`,
174 export const privatizeMember = (memberID: string) => ({
176 url: `core/v4/members/${memberID}/privatize`,
179 export const authMember = (memberID: string, data: { Unlock?: boolean } = {}) => ({
181 url: `core/v4/members/${memberID}/auth`,
185 export const inviteMember = (email: string, maxSpace: number) => ({
186 url: `core/v4/members/invitations`,
194 export const deleteMember = (memberId: string) => ({
195 url: `core/v4/members/${memberId}`,
199 export const editMemberInvitation = (memberID: string, maxSpace: number) => ({
201 url: `core/v4/members/invitations/${memberID}`,
207 export const updateAddressFlags = (
211 SignedKeyList: SignedKeyList
214 url: `core/v4/addresses/${addressID}/encryption`,
216 Encrypt: Encrypt ? 1 : 0,