1 import { api } from '@proton/pass/lib/api/api';
3 BreachCustomEmailGetResponse,
4 BreachEmailCreateRequest,
5 BreachEmailValidateRequest,
6 BreachUpdateCustomEmailRequest,
7 BreachUpdateMonitorAddressRequest,
10 UpdateUserMonitorStateRequest,
11 } from '@proton/pass/types/api/pass';
12 import type { SETTINGS_PROTON_SENTINEL_STATE } from '@proton/shared/lib/interfaces';
14 /** Toggle the ProtonSentinel setting */
15 export const toggleSentinel = (value: SETTINGS_PROTON_SENTINEL_STATE) =>
16 api({ url: `core/v4/settings/highsecurity`, method: value ? 'post' : 'delete' });
18 /** Update PassMonitor settings */
19 export const setMonitorSettings = async (data: UpdateUserMonitorStateRequest): Promise<UpdateUserMonitorStateRequest> =>
20 (await api({ url: 'pass/v1/user/monitor', method: 'put', data })).Monitor!;
22 /* Get all the breaches for this user (Proton addresses) */
23 export const getAllBreaches = async (): Promise<BreachesGetResponse> =>
24 (await api({ url: 'pass/v1/breach', method: 'get' })).Breaches!;
26 /* Get breaches for a proton address */
27 export const getBreachesForProtonAddress = async (AddressID: string): Promise<BreachesResponse> =>
28 (await api({ url: `pass/v1/breach/address/${AddressID}/breaches`, method: 'get' })).Breaches!;
30 /** Get breaches for custom email */
31 export const getCustomEmailBreaches = async (customEmailId: string): Promise<BreachesResponse> =>
32 (await api({ url: `pass/v1/breach/custom_email/${customEmailId}/breaches`, method: 'get' })).Breaches!;
34 /* Get breaches for an alias item */
35 export const getAliasBreaches = async (shareId: string, itemId: string): Promise<BreachesResponse> =>
36 (await api({ url: `pass/v1/share/${shareId}/alias/${itemId}/breaches`, method: 'get' })).Breaches!;
38 /* Update the monitor status for a Proton Address */
39 export const setMonitorForProtonAddress = (AddressID: string, monitor: BreachUpdateMonitorAddressRequest) =>
40 api({ url: `pass/v1/breach/address/${AddressID}/monitor`, method: 'put', data: monitor });
42 /** Add a custom email to breaches monitoring */
43 export const monitorCustomEmail = async (data: BreachEmailCreateRequest): Promise<BreachCustomEmailGetResponse> =>
44 (await api({ url: `pass/v1/breach/custom_email`, method: 'post', data })).Email!;
46 /** Remove a custom email from breaches monitoring */
47 export const deleteCustomEmail = async (addressId: string): Promise<boolean> =>
48 api({ url: `pass/v1/breach/custom_email/${addressId}`, method: 'delete' }).then(() => true);
50 /** Update the monitor status for a custom email */
51 export const toggleCustomEmail = async (
53 data: BreachUpdateCustomEmailRequest
54 ): Promise<BreachCustomEmailGetResponse> =>
55 (await api({ url: `pass/v1/breach/custom_email/${addressId}/monitor`, method: 'put', data })).Email!;
57 /** Update the monitor status for a custom email */
58 export const toggleProtonEmail = (addressId: string, data: BreachUpdateCustomEmailRequest): Promise<boolean> =>
59 api({ url: `pass/v1/breach/address/${addressId}/monitor`, method: 'put', data }).then(() => true);
61 /** Mark a Proton address as resolved */
62 export const setBreachedProtonAddressResolved = (AddressID: string): Promise<boolean> =>
63 api({ url: `pass/v1/breach/address/${AddressID}/resolved`, method: 'post' }).then(() => true);
65 /** Mark alias breaches as resolved */
66 export const setBreachedAliasResolved = (shareId: string, itemId: string): Promise<boolean> =>
67 api({ url: `pass/v1/share/${shareId}/alias/${itemId}/breaches/resolved`, method: 'post' }).then(() => true);
69 /** Mark custom email breaches as resolved */
70 export const setBreachedCustomEmailResolved = (customEmailId: string): Promise<boolean> =>
71 api({ url: `pass/v1/breach/custom_email/${customEmailId}/resolved`, method: 'put' }).then(() => true);
73 /** Verify a custom email with the validation code */
74 export const verifyCustomEmail = async (
76 data: BreachEmailValidateRequest
77 ): Promise<BreachCustomEmailGetResponse> =>
78 (await api({ url: `pass/v1/breach/custom_email/${addressId}/verify`, method: 'put', data })).Email!;
80 /** Re-send the verification email for custom address */
81 export const resendVerificationCustomEmail = (addressId: string): Promise<boolean> =>
82 api({ url: `pass/v1/breach/custom_email/${addressId}/resend_verification`, method: 'post' }).then(() => true);