1 import { stripLocalBasenameFromPathname } from '../authentication/pathnameHelper';
2 import type { APP_NAMES } from '../constants';
3 import { APPS, APPS_CONFIGURATION } from '../constants';
4 import { stripLeadingAndTrailingSlash } from '../helpers/string';
6 export const DEFAULT_APP = APPS.PROTONMAIL;
8 export const ALLOWED_APPS = [
12 APPS.PROTONVPN_SETTINGS,
19 export const getSlugFromApp = (app: APP_NAMES) => APPS_CONFIGURATION[app].settingsSlug;
21 export const getAppFromPathname = (pathname: string): APP_NAMES | undefined => {
22 return ALLOWED_APPS.find((appName) => {
23 const slug = getSlugFromApp(appName);
24 // Expects a trimmed string
25 return pathname.match(`^${slug}(/|$)`);
29 export const getAppFromHostname = (hostname: string): APP_NAMES | undefined => {
30 return ALLOWED_APPS.find((appName) => {
31 const slug = getSlugFromApp(appName);
32 return hostname.match(`^${slug}\.`);
36 export const getAppFromPathnameSafe = (pathname: string) => {
37 const trimmedPathname = stripLeadingAndTrailingSlash(stripLocalBasenameFromPathname(pathname));
38 return getAppFromPathname(trimmedPathname);
41 export const ALLOWED_SLUGS = ALLOWED_APPS.map((app) => APPS_CONFIGURATION[app].settingsSlug);
43 export type AppSlug = (typeof ALLOWED_SLUGS)[number];
45 export const stripSlugFromPathname = (pathname: string) => {
46 return pathname.replace(new RegExp(`/(${ALLOWED_SLUGS.join('|')})`), '');