1 import { DEFAULT_APP } from '@proton/shared/lib/apps/slugHelper';
2 import type { User } from '@proton/shared/lib/interfaces';
5 getIsPublicUserWithoutProtonAddress,
6 getIsSSOVPNOnlyAccount,
8 } from '@proton/shared/lib/keys';
10 import type { APP_NAMES } from '../constants';
11 import { APPS, APPS_CONFIGURATION, CLIENT_TYPES, PRODUCT_BIT } from '../constants';
13 export const getToAppName = (toApp?: APP_NAMES) => {
14 if (!toApp || toApp === APPS.PROTONACCOUNT) {
18 return APPS_CONFIGURATION[toApp]?.name || '';
21 export const vpnApps = [APPS.PROTONVPN_SETTINGS, APPS.PROTONVPNBROWSEREXTENSION];
22 export const passApps = [APPS.PROTONPASS, APPS.PROTONEXTENSION, APPS.PROTONPASSBROWSEREXTENSION];
24 export const externalApps = [...vpnApps, APPS.PROTONDRIVE, ...passApps];
26 export const requiresProtonAddress: APP_NAMES[] = [APPS.PROTONMAIL, APPS.PROTONCALENDAR];
27 export const requiresAddress: APP_NAMES[] = [...requiresProtonAddress, APPS.PROTONDRIVE, ...passApps];
29 export const requiresNonDelinquent: APP_NAMES[] = [
36 export const getHasAppExternalSignup = (toApp?: APP_NAMES) => {
37 return externalApps.includes(toApp as any);
40 export const getIsPassApp = (toApp?: APP_NAMES) => {
41 return passApps.includes(toApp as any);
44 export const getIsVPNApp = (toApp?: APP_NAMES, clientType?: CLIENT_TYPES) => {
45 return vpnApps.includes(toApp as any) || clientType === CLIENT_TYPES.VPN;
48 export const getIsMailApp = (toApp?: APP_NAMES) => {
49 return toApp === APPS.PROTONMAIL;
51 export const getIsCalendarApp = (toApp?: APP_NAMES) => {
52 return toApp === APPS.PROTONCALENDAR;
54 export const getIsDriveApp = (toApp?: APP_NAMES) => {
55 return toApp === APPS.PROTONDRIVE;
57 export const getIsDocsApp = (toApp?: APP_NAMES) => {
58 return toApp === APPS.PROTONDOCS;
60 export const getIsWalletApp = (toApp?: APP_NAMES) => {
61 return toApp === APPS.PROTONWALLET;
64 export const getRequiresAddress = (toApp: APP_NAMES) => {
65 return requiresAddress.includes(toApp);
68 export const getRequiresProtonAddress = (toApp: APP_NAMES) => {
69 return requiresProtonAddress.includes(toApp);
72 export const getToApp = (toApp: APP_NAMES | undefined, user: User) => {
76 if (getIsSSOVPNOnlyAccount(user) || getIsVPNOnlyAccount(user)) {
77 return APPS.PROTONVPN_SETTINGS;
79 if (getIsPublicUserWithoutProtonAddress(user)) {
80 return APPS.PROTONPASS;
82 if (getIsExternalAccount(user)) {
83 const { Subscribed } = user;
85 if (Subscribed === PRODUCT_BIT.VPN) {
86 return APPS.PROTONVPN_SETTINGS;
89 if (Subscribed === PRODUCT_BIT.PASS) {
90 return APPS.PROTONPASS;
93 // VPN and Pass bundle
94 if (Subscribed === (PRODUCT_BIT.VPN | PRODUCT_BIT.PASS)) {
95 return APPS.PROTONVPN_SETTINGS;
98 return APPS.PROTONDRIVE;
103 export const getToAppFromSubscribed = (user: User) => {
105 { bit: PRODUCT_BIT.MAIL, app: APPS.PROTONMAIL },
106 { bit: PRODUCT_BIT.DRIVE, app: APPS.PROTONDRIVE },
107 { bit: PRODUCT_BIT.VPN | PRODUCT_BIT.PASS, app: APPS.PROTONVPN_SETTINGS }, // VPN + Pass Bundle
108 { bit: PRODUCT_BIT.PASS, app: APPS.PROTONPASS },
109 { bit: PRODUCT_BIT.VPN, app: APPS.PROTONVPN_SETTINGS },
111 return list.find(({ bit }) => {
112 if (user.Subscribed === bit) {