-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1985 from ever-co/improve-recaptcha
Improve Env Variable Retrieval
- Loading branch information
Showing
25 changed files
with
241 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { JitsuOptions } from '@jitsu/jitsu-react/dist/useJitsu'; | ||
import { I_SMTPRequest } from './interfaces/ISmtp'; | ||
import { getNextPublicEnv } from './env'; | ||
|
||
export const API_BASE_URL = '/api'; | ||
export const DEFAULT_APP_PATH = '/auth/passcode'; | ||
|
@@ -28,24 +29,47 @@ export const NO_TEAM_POPUP_SHOW_COOKIE_NAME = 'no-team-popup-show'; | |
export const ACTIVE_PROJECT_COOKIE_NAME = 'auth-active-project'; | ||
|
||
// Recaptcha | ||
export const RECAPTCHA_SITE_KEY = process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY; | ||
export const RECAPTCHA_SITE_KEY = getNextPublicEnv( | ||
'NEXT_PUBLIC_CAPTCHA_SITE_KEY', | ||
process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY | ||
); | ||
export const RECAPTCHA_SECRET_KEY = process.env.CAPTCHA_SECRET_KEY; | ||
|
||
// Gauzy Server URL | ||
export const GAUZY_API_SERVER_URL = process.env.GAUZY_API_SERVER_URL || 'https://api.gauzy.co/api'; | ||
export const GAUZY_API_BASE_SERVER_URL = getNextPublicEnv( | ||
'NEXT_PUBLIC_GAUZY_API_SERVER_URL', | ||
process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL | ||
); | ||
|
||
// Invite | ||
export const INVITE_CALLBACK_URL = process.env.INVITE_CALLBACK_URL || 'https://app.ever.team/auth/passcode'; | ||
export const INVITE_CALLBACK_PATH = '/auth/passcode'; | ||
export const VERIFY_EMAIL_CALLBACK_URL = process.env.VERIFY_EMAIL_CALLBACK_URL || 'https://app.ever.team/verify-email'; | ||
export const VERIFY_EMAIL_CALLBACK_PATH = '/verify-email'; | ||
export const GA_MEASUREMENT_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID; | ||
export const GA_MEASUREMENT_ID = getNextPublicEnv( | ||
'NEXT_PUBLIC_GA_MEASUREMENT_ID', | ||
process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID | ||
); | ||
|
||
// Chatwoot | ||
export const CHATWOOT_API_KEY = getNextPublicEnv( | ||
'NEXT_PUBLIC_CHATWOOT_API_KEY', | ||
process.env.NEXT_PUBLIC_CHATWOOT_API_KEY | ||
); | ||
|
||
export const SMTP_FROM_ADDRESS = process.env.SMTP_FROM_ADDRESS || '[email protected]'; | ||
export const SMTP_HOST = process.env.SMTP_HOST || ''; | ||
export const SMTP_PORT = process.env.SMTP_PORT || ''; | ||
export const SMTP_SECURE = process.env.SMTP_SECURE || ''; | ||
export const SMTP_USERNAME = process.env.SMTP_USERNAME || ''; | ||
export const SMTP_PASSWORD = process.env.SMTP_PASSWORD || ''; | ||
export const DISABLE_AUTO_REFRESH = process.env.NEXT_PUBLIC_DISABLE_AUTO_REFRESH === 'true'; | ||
export const DISABLE_AUTO_REFRESH = getNextPublicEnv('NEXT_PUBLIC_DISABLE_AUTO_REFRESH', { | ||
default: process.env.NEXT_PUBLIC_DISABLE_AUTO_REFRESH, | ||
map(value) { | ||
return value === 'true'; | ||
} | ||
}); | ||
|
||
export const APP_NAME = process.env.APP_NAME || 'Ever Teams'; | ||
export const APP_SIGNATURE = process.env.APP_SIGNATURE || 'Ever Teams'; | ||
|
@@ -64,31 +88,53 @@ export const smtpConfiguration: () => I_SMTPRequest = () => ({ | |
}); | ||
|
||
// Cookies | ||
export const COOKIE_DOMAINS = (process.env.NEXT_PUBLIC_COOKIE_DOMAINS || 'ever.team').split(',').map((d) => d.trim()); | ||
export const COOKIE_DOMAINS = getNextPublicEnv('NEXT_PUBLIC_COOKIE_DOMAINS', { | ||
default: process.env.NEXT_PUBLIC_COOKIE_DOMAINS || 'ever.team', | ||
map(value) { | ||
return value?.split(',').map((d) => d.trim()) || []; | ||
} | ||
}); | ||
|
||
// MEET Constants | ||
export const MEET_DOMAIN = process.env.NEXT_PUBLIC_MEET_DOMAIN || 'meet.ever.team'; | ||
export const MEET_DOMAIN = getNextPublicEnv( | ||
'NEXT_PUBLIC_MEET_DOMAIN', | ||
process.env.NEXT_PUBLIC_MEET_DOMAIN || 'meet.ever.team' | ||
); | ||
export const MEET_JWT_APP_ID = process.env.MEET_JWT_APP_ID || 'ever_teams'; | ||
export const MEET_JWT_APP_SECRET = process.env.MEET_JWT_APP_SECRET; | ||
export const MEET_JWT_TOKEN_COOKIE_NAME = 'meet-jwt-session'; | ||
|
||
// BOARD board | ||
export const BOARD_APP_DOMAIN = process.env.NEXT_PUBLIC_BOARD_APP_DOMAIN || 'https://board.ever.team'; | ||
export const BOARD_BACKEND_POST_URL = process.env.NEXT_PUBLIC_BOARD_BACKEND_POST_URL || 'https://jsonboard.ever.team/api/v2/post/'; | ||
export const BOARD_FIREBASE_CONFIG = process.env.NEXT_PUBLIC_BOARD_FIREBASE_CONFIG; | ||
export const BOARD_APP_DOMAIN = getNextPublicEnv( | ||
'NEXT_PUBLIC_BOARD_APP_DOMAIN', | ||
process.env.NEXT_PUBLIC_BOARD_APP_DOMAIN || 'https://board.ever.team' | ||
); | ||
|
||
export const BOARD_BACKEND_POST_URL = getNextPublicEnv( | ||
'NEXT_PUBLIC_BOARD_BACKEND_POST_URL', | ||
process.env.NEXT_PUBLIC_BOARD_BACKEND_POST_URL || 'https://jsonboard.ever.team/api/v2/post/' | ||
); | ||
export const BOARD_FIREBASE_CONFIG = getNextPublicEnv( | ||
'NEXT_PUBLIC_BOARD_FIREBASE_CONFIG', | ||
process.env.NEXT_PUBLIC_BOARD_FIREBASE_CONFIG | ||
); | ||
|
||
// Jitsu | ||
export const jitsuConfiguration: () => JitsuOptions = () => ({ | ||
host: process.env.NEXT_PUBLIC_JITSU_BROWSER_URL || '', | ||
writeKey: process.env.NEXT_PUBLIC_JITSU_BROWSER_WRITE_KEY || '', | ||
host: getNextPublicEnv('NEXT_PUBLIC_JITSU_BROWSER_URL', process.env.NEXT_PUBLIC_JITSU_BROWSER_URL).value, | ||
writeKey: getNextPublicEnv('NEXT_PUBLIC_JITSU_BROWSER_WRITE_KEY', process.env.NEXT_PUBLIC_JITSU_BROWSER_WRITE_KEY) | ||
.value, | ||
// if enabled - events will be sent to the console but no data sent to Jitsu. | ||
// Strange this is not mentioned in the documentation https://github.com/jitsucom/jitsu/blob/35c4ecaff54d61a87853381cb17262b7bfbd4a6e/libs/jitsu-js/src/jitsu.ts#L40 | ||
echoEvents: false, | ||
debug: false | ||
}); | ||
|
||
// Github Integration | ||
export const GITHUB_APP_NAME = process.env.NEXT_PUBLIC_GITHUB_APP_NAME || 'ever-github'; | ||
export const GITHUB_APP_NAME = getNextPublicEnv( | ||
'NEXT_PUBLIC_GITHUB_APP_NAME', | ||
process.env.NEXT_PUBLIC_GITHUB_APP_NAME || 'ever-github' | ||
); | ||
|
||
// Application Languages | ||
export const APPLICATION_LANGUAGES = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const NEXT_PUBLIC_ENVS: { value: Env } = { value: {} }; | ||
|
||
type Env = Record<string, string | undefined>; | ||
|
||
type OptionObject<T> = { | ||
default?: string; | ||
map?: (value: string | undefined) => T; | ||
}; | ||
type Options<T> = string | OptionObject<T>; | ||
|
||
type InferValue<T> = T extends { map: (value: any) => infer U } ? U : string | undefined; | ||
|
||
type ReturnedType<T> = { | ||
readonly value: T extends string ? string : InferValue<T>; | ||
}; | ||
|
||
/** | ||
* This function only loads environment variables starting with NEXT_PUBLIC_* | ||
* | ||
* Useful for getting the latest value of the variable at runtime rather than at build time | ||
* | ||
* @param name | ||
* @param options | ||
* @returns | ||
*/ | ||
export function getNextPublicEnv<O extends Options<unknown>>(name: string, options?: O): ReturnedType<O> { | ||
return { | ||
get value() { | ||
const defaultValue = typeof options === 'string' ? options : options?.default; | ||
|
||
let value = NEXT_PUBLIC_ENVS.value[name] || defaultValue; | ||
if (typeof options === 'object' && options.map) { | ||
value = options.map(value) as any; | ||
} | ||
|
||
return value as any; | ||
} | ||
}; | ||
} | ||
|
||
export function setNextPublicEnv(envs: Env) { | ||
if (envs) { | ||
NEXT_PUBLIC_ENVS.value = { | ||
...NEXT_PUBLIC_ENVS.value, | ||
...envs | ||
}; | ||
} | ||
} | ||
|
||
export function loadNextPublicEnvs() { | ||
return Object.keys(process.env) | ||
.filter((key) => key.startsWith('NEXT_PUBLIC')) | ||
.reduce( | ||
(acc, value) => { | ||
if (process.env[value]) { | ||
acc[value] = process.env[value] as string; | ||
} | ||
return acc; | ||
}, | ||
{} as Record<string, string> | ||
); | ||
} | ||
|
||
// Preload Some variables | ||
setNextPublicEnv(loadNextPublicEnvs()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { GAUZY_API_BASE_SERVER_URL } from '@app/constants'; | ||
import { get } from '../axios'; | ||
|
||
export async function getLanguageListAPI(is_system: boolean) { | ||
const endpoint = `/languages?is_system=${is_system}`; | ||
const data = await get(endpoint, true); | ||
|
||
return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; | ||
return GAUZY_API_BASE_SERVER_URL.value ? data.data : data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.