2 getIsAlmostPerfectEmailState,
3 getIsAlmostPerfectPhoneState,
4 getIsPerfectDeviceRecoveryState,
5 getIsPerfectEmailState,
6 getIsPerfectPhoneState,
7 getIsPerfectPhraseState,
8 } from '@proton/shared/lib/helpers/securityCheckup';
9 import type { SecurityCheckupAction } from '@proton/shared/lib/interfaces/securityCheckup';
10 import SecurityCheckupCohort from '@proton/shared/lib/interfaces/securityCheckup/SecurityCheckupCohort';
11 import type SecurityState from '@proton/shared/lib/interfaces/securityCheckup/SecurityState';
14 private actionsSet: Set<SecurityCheckupAction>;
16 private securityState: SecurityState;
18 private isPerfectPhraseState: boolean;
20 private isPerfectEmailState: boolean;
22 private isPerfectPhoneState: boolean;
24 private isPerfectDeviceRecoveryState: boolean;
26 public shouldActionDevice: boolean;
28 constructor(securityState: SecurityState) {
29 this.actionsSet = new Set<SecurityCheckupAction>();
31 this.securityState = securityState;
33 this.isPerfectPhraseState = getIsPerfectPhraseState(securityState);
34 this.isPerfectEmailState = getIsPerfectEmailState(securityState);
35 this.isPerfectPhoneState = getIsPerfectPhoneState(securityState);
36 this.isPerfectDeviceRecoveryState = getIsPerfectDeviceRecoveryState(securityState);
38 this.shouldActionDevice =
39 (this.isPerfectEmailState || this.isPerfectPhoneState) && !this.isPerfectDeviceRecoveryState;
43 if (!this.securityState.phrase.isAvailable) {
47 if (!this.isPerfectPhraseState) {
48 this.actionsSet.add('phrase');
53 if (!this.isPerfectEmailState) {
54 this.actionsSet.add('email');
59 if (!this.isPerfectPhoneState) {
60 this.actionsSet.add('phone');
64 public emailOrPhone() {
70 if (!this.securityState.deviceRecovery.isAvailable) {
74 if (this.shouldActionDevice) {
75 this.actionsSet.add('device');
80 return Array.from(this.actionsSet);
84 interface SecurityCheckupHealth {
85 cohort: SecurityCheckupCohort;
86 actions: SecurityCheckupAction[];
87 furtherActions: SecurityCheckupAction[];
90 const getSecurityCheckupRecommendations = (securityState: SecurityState): SecurityCheckupHealth => {
91 const isPerfectPhraseState = getIsPerfectPhraseState(securityState);
93 const isPerfectEmailState = getIsPerfectEmailState(securityState);
94 const isAlmostPerfectEmailState = getIsAlmostPerfectEmailState(securityState);
96 const isPerfectPhoneState = getIsPerfectPhoneState(securityState);
97 const isAlmostPerfectPhoneState = getIsAlmostPerfectPhoneState(securityState);
99 const isPerfectEmailOrPhoneState = isPerfectEmailState || isPerfectPhoneState;
101 const isPerfectDeviceState = getIsPerfectDeviceRecoveryState(securityState);
103 const actions = new Actions(securityState);
104 const furtherActions = new Actions(securityState);
111 cohort: SecurityCheckupCohort;
113 furtherActions: Actions;
117 actions: actions.toArray(),
118 furtherActions: furtherActions.toArray(),
123 * COMPLETE_RECOVERY_MULTIPLE
125 if (isPerfectPhraseState && isPerfectEmailOrPhoneState && isPerfectDeviceState) {
127 furtherActions.emailOrPhone();
130 cohort: SecurityCheckupCohort.COMPLETE_RECOVERY_MULTIPLE,
137 * COMPLETE_RECOVERY_SINGLE
139 if (isPerfectPhraseState && !isPerfectEmailOrPhoneState) {
140 actions.emailOrPhone();
143 cohort: SecurityCheckupCohort.COMPLETE_RECOVERY_SINGLE,
149 if (isPerfectPhraseState && isPerfectEmailOrPhoneState && !isPerfectDeviceState) {
152 furtherActions.emailOrPhone();
155 cohort: SecurityCheckupCohort.COMPLETE_RECOVERY_SINGLE,
161 if (!isPerfectPhraseState && isPerfectEmailOrPhoneState && isPerfectDeviceState) {
164 furtherActions.emailOrPhone();
167 cohort: SecurityCheckupCohort.COMPLETE_RECOVERY_SINGLE,
174 * ACCOUNT_RECOVERY_ENABLED
176 if (!isPerfectPhraseState && isPerfectEmailOrPhoneState && !isPerfectDeviceState) {
179 furtherActions.phrase();
180 furtherActions.emailOrPhone();
183 cohort: SecurityCheckupCohort.ACCOUNT_RECOVERY_ENABLED,
192 if (isAlmostPerfectEmailState || isAlmostPerfectPhoneState) {
193 if (isAlmostPerfectEmailState) {
196 if (isAlmostPerfectPhoneState) {
203 if (!isAlmostPerfectEmailState) {
204 furtherActions.email();
207 if (!isAlmostPerfectPhoneState) {
208 furtherActions.phone();
212 cohort: SecurityCheckupCohort.NO_RECOVERY_METHOD,
218 export default getSecurityCheckupRecommendations;