Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / lib / api / forwardings.ts
blob70fc918573246a19e1c4fd44fec8b0ffe2e5c3f2
1 import type { SIEVE_VERSION, SieveBranch } from '@proton/sieve/src/interface';
3 import type {
4     Api,
5     ForwardingState,
6     ForwardingType,
7     IncomingAddressForwarding,
8     OutgoingAddressForwarding,
9 } from '../interfaces';
10 import queryPages from './helpers/queryPages';
12 interface ProxyInstance {
13     PgpVersion: number;
14     ForwarderKeyFingerprint: string;
15     ForwardeeKeyFingerprint: string;
16     ProxyParam: string;
18 interface QueryProps {
19     AddressID?: string;
20     Page?: number;
21     PageSize?: number;
24 export const queryOutgoingForwardings = ({ AddressID, Page, PageSize }: QueryProps) => ({
25     method: 'get',
26     url: 'mail/v4/forwardings/outgoing',
27     params: { Page, PageSize, AddressID },
28 });
30 export const queryAllOutgoingForwardings = (api: Api) => {
31     return queryPages((Page, PageSize) => {
32         return api<{ OutgoingAddressForwardings: OutgoingAddressForwarding[]; Total: number }>(
33             queryOutgoingForwardings({
34                 Page,
35                 PageSize,
36             })
37         );
38     }).then((pages) => {
39         return pages.flatMap(({ OutgoingAddressForwardings }) => OutgoingAddressForwardings);
40     });
43 export const queryIncomingForwardings = ({ AddressID, Page, PageSize }: QueryProps) => ({
44     method: 'get',
45     url: 'mail/v4/forwardings/incoming',
46     params: { Page, PageSize, AddressID },
47 });
49 export const queryAllIncomingForwardings = (api: Api) => {
50     return queryPages((Page, PageSize) => {
51         return api<{ IncomingAddressForwardings: IncomingAddressForwarding[]; Total: number }>(
52             queryIncomingForwardings({
53                 Page,
54                 PageSize,
55             })
56         );
57     }).then((pages) => {
58         return pages.flatMap(({ IncomingAddressForwardings }) => IncomingAddressForwardings);
59     });
62 export interface SetupForwardingParameters {
63     Type: ForwardingType;
64     ForwarderAddressID: string;
65     ForwardeeEmail: string;
66     ForwardeePrivateKey?: string; // Only for internal E2EE forwarding
67     ActivationToken?: string; // Only for internal E2EE forwarding
68     ProxyInstances?: ProxyInstance[]; // Only for E2EE forwarding
69     Tree: SieveBranch[] | null;
70     Version: SIEVE_VERSION;
73 export const setupForwarding = ({
74     Type,
75     ForwarderAddressID,
76     ForwardeeEmail,
77     ForwardeePrivateKey,
78     ActivationToken,
79     ProxyInstances,
80     Tree,
81     Version,
82 }: SetupForwardingParameters) => ({
83     method: 'post',
84     url: 'mail/v4/forwardings',
85     data: {
86         Type,
87         ForwarderAddressID,
88         ForwardeeEmail,
89         ForwardeePrivateKey,
90         ActivationToken,
91         ProxyInstances,
92         Tree,
93         Version,
94     },
95 });
97 interface UpdateForwardingParameters {
98     ID: string;
99     ForwardeePrivateKey: string;
100     ActivationToken: string;
101     ProxyInstances: ProxyInstance[];
104 export const updateForwarding = ({
105     ID,
106     ForwardeePrivateKey,
107     ActivationToken,
108     ProxyInstances,
109 }: UpdateForwardingParameters) => ({
110     method: 'put',
111     url: `mail/v4/forwardings/${ID}`,
112     data: {
113         ForwardeePrivateKey,
114         ActivationToken,
115         ProxyInstances,
116     },
119 export const deleteForwarding = (ID: string) => ({
120     method: 'delete',
121     url: `mail/v4/forwardings/${ID}`,
124 export const rejectForwarding = (ID: string) => ({
125     method: 'delete',
126     url: `mail/v4/forwardings/${ID}`,
129 export const acceptExternalForwarding = (jwt: string) => ({
130     method: 'put',
131     url: `mail/v4/forwardings/external/${jwt}`,
134 export const rejectExternalForwarding = (jwt: string) => ({
135     method: 'delete',
136     url: `mail/v4/forwardings/external/${jwt}`,
139 export interface ExternalForwardingResult {
140     Code: number;
141     Type: ForwardingType;
142     State: ForwardingState;
143     ForwarderEmail: string;
144     ForwardeeEmail: string;
147 export const getExternalForwarding = (jwt: string) => ({
148     method: 'get',
149     url: `mail/v4/forwardings/external/${jwt}`,
152 export const pauseForwarding = (ID: string) => ({
153     method: 'put',
154     url: `mail/v4/forwardings/${ID}/pause`,
157 export const resumeForwarding = (ID: string) => ({
158     method: 'put',
159     url: `mail/v4/forwardings/${ID}/resume`,
162 export const resendForwardingInvitation = (ID: string) => ({
163     method: 'put',
164     url: `mail/v4/forwardings/${ID}/reinvite`,
167 export const updateForwardingFilter = (ID: string, Tree: SieveBranch[] | null, Version: SIEVE_VERSION) => ({
168     method: 'put',
169     url: `mail/v4/forwardings/${ID}/filter`,
170     data: { Tree, Version },