1 import type { ADDRESS_PERMISSIONS } from '@proton/shared/lib/constants';
3 import type { Address, Api, SignedKeyList } from '../interfaces';
4 import queryPages from './helpers/queryPages';
5 import type { PaginationParams } from './interface';
7 export const queryAddresses = (params?: PaginationParams) => ({
8 url: 'core/v4/addresses',
13 export const getAllAddresses = (api: Api): Promise<Address[]> => {
14 return queryPages((page, pageSize) => {
15 return api<{ Addresses: Address[]; Total: number }>(
22 return pages.flatMap(({ Addresses }) => Addresses);
26 interface CreateAddressArgs {
34 export const createAddress = ({ MemberID, Local, Domain, DisplayName, Signature }: CreateAddressArgs) => ({
35 url: 'core/v4/addresses',
37 data: { MemberID, Local, Domain, DisplayName, Signature },
40 export const orderAddress = (AddressIDs: string[]) => ({
41 url: 'core/v4/addresses/order',
46 interface SetupAddressArgs {
52 export const setupAddress = ({ Domain, DisplayName, Signature }: SetupAddressArgs) => ({
53 url: 'core/v4/addresses/setup',
55 data: { Domain, DisplayName, Signature },
58 export const getAddress = (addressID: string) => ({
59 url: `core/v4/addresses/${addressID}`,
63 export const getCanonicalAddresses = (Emails: string[]) => ({
64 // params doesn't work correctly so
65 url: `core/v4/addresses/canonical?${Emails.map((email) => `Emails[]=${email}`).join('&')}`,
67 // params: { Emails },
70 export const updateAddress = (
72 { DisplayName, Signature }: { DisplayName?: string; Signature?: string }
74 url: `core/v4/addresses/${addressID}`,
76 data: { DisplayName, Signature },
79 export const enableAddress = (addressID: string) => ({
80 url: `core/v4/addresses/${addressID}/enable`,
84 export const disableAddress = (addressID: string) => ({
85 url: `core/v4/addresses/${addressID}/disable`,
89 export const deleteAddress = (addressID: string) => ({
90 url: `core/v4/addresses/${addressID}/delete`,
94 interface RenamedAddressKey {
99 interface RenameInternalAddressData {
101 AddressKeys: RenamedAddressKey[];
104 export const renameInternalAddress = (addressID: string, data: RenameInternalAddressData) => ({
105 url: `core/v4/addresses/${addressID}/rename/internal`,
110 interface RenameExternalAddressData {
113 AddressKeys: RenamedAddressKey[];
116 export const renameExternalAddress = (addressID: string, data: RenameExternalAddressData) => ({
117 url: `core/v4/addresses/${addressID}/rename/external`,
122 export const addressType = (addressID: string, data: { Type: number; SignedKeyList: SignedKeyList }) => ({
123 url: `core/v4/addresses/${addressID}/type`,
128 export const switchAddressesOrganizationPermissions = ({
133 Permissions: ADDRESS_PERMISSIONS[];
135 url: `core/v4/members/addresses/permissions/organization/switch`,
137 data: { Ids, Permissions },
140 export const getAllowAddressDeletion = () => ({
141 url: `core/v4/addresses/allowAddressDeletion`,