2
0

🚑 Set proper env defaults

This commit is contained in:
Baptiste Arnaud
2023-08-28 11:00:25 +02:00
parent 1c680c3ef5
commit efd4600b7e
5 changed files with 32 additions and 29 deletions

View File

@@ -10,7 +10,6 @@ test.describe('Send email block', () => {
test('its configuration should work', async ({ page }) => {
if (
!env.SMTP_USERNAME ||
!env.SMTP_PORT ||
!env.SMTP_HOST ||
!env.SMTP_PASSWORD ||
!env.NEXT_PUBLIC_SMTP_FROM

View File

@@ -3,7 +3,7 @@ import { Plan } from '@typebot.io/prisma'
export const parseWorkspaceDefaultPlan = (userEmail: string) => {
if (env.ADMIN_EMAIL === userEmail) return Plan.UNLIMITED
const defaultPlan = env.DEFAULT_WORKSPACE_PLAN as Plan | undefined
const defaultPlan = env.DEFAULT_WORKSPACE_PLAN as Plan
if (defaultPlan && Object.values(Plan).includes(defaultPlan))
return defaultPlan
return Plan.FREE

View File

@@ -38,13 +38,13 @@ if (env.GITHUB_CLIENT_ID && env.GITHUB_CLIENT_SECRET)
})
)
if (env.NEXT_PUBLIC_SMTP_FROM && env.SMTP_AUTH_DISABLED)
if (env.NEXT_PUBLIC_SMTP_FROM && !env.SMTP_AUTH_DISABLED)
providers.push(
EmailProvider({
server: {
host: env.SMTP_HOST,
port: env.SMTP_PORT ? Number(env.SMTP_PORT) : 25,
secure: env.SMTP_SECURE ? env.SMTP_SECURE : false,
port: env.SMTP_PORT,
secure: env.SMTP_SECURE,
auth: {
user: env.SMTP_USERNAME,
pass: env.SMTP_PASSWORD,
@@ -72,7 +72,7 @@ if (env.FACEBOOK_CLIENT_ID && env.FACEBOOK_CLIENT_SECRET)
)
if (env.GITLAB_CLIENT_ID && env.GITLAB_CLIENT_SECRET) {
const BASE_URL = env.GITLAB_BASE_URL || 'https://gitlab.com'
const BASE_URL = env.GITLAB_BASE_URL
providers.push(
GitlabProvider({
clientId: env.GITLAB_CLIENT_ID,
@@ -80,7 +80,7 @@ if (env.GITLAB_CLIENT_ID && env.GITLAB_CLIENT_SECRET) {
authorization: `${BASE_URL}/oauth/authorize?scope=read_api`,
token: `${BASE_URL}/oauth/token`,
userinfo: `${BASE_URL}/api/v4/user`,
name: env.GITLAB_NAME || 'GitLab',
name: env.GITLAB_NAME,
})
)
}
@@ -102,11 +102,11 @@ if (
if (env.CUSTOM_OAUTH_WELL_KNOWN_URL) {
providers.push({
id: 'custom-oauth',
name: env.CUSTOM_OAUTH_NAME ?? 'Custom OAuth',
name: env.CUSTOM_OAUTH_NAME,
type: 'oauth',
authorization: {
params: {
scope: env.CUSTOM_OAUTH_SCOPE ?? 'openid profile email',
scope: env.CUSTOM_OAUTH_SCOPE,
},
},
clientId: env.CUSTOM_OAUTH_CLIENT_ID,
@@ -114,10 +114,10 @@ if (env.CUSTOM_OAUTH_WELL_KNOWN_URL) {
wellKnown: env.CUSTOM_OAUTH_WELL_KNOWN_URL,
profile(profile) {
return {
id: getAtPath(profile, env.CUSTOM_OAUTH_USER_ID_PATH ?? 'id'),
name: getAtPath(profile, env.CUSTOM_OAUTH_USER_NAME_PATH ?? 'name'),
email: getAtPath(profile, env.CUSTOM_OAUTH_USER_EMAIL_PATH ?? 'email'),
image: getAtPath(profile, env.CUSTOM_OAUTH_USER_IMAGE_PATH ?? 'image'),
id: getAtPath(profile, env.CUSTOM_OAUTH_USER_ID_PATH),
name: getAtPath(profile, env.CUSTOM_OAUTH_USER_NAME_PATH),
email: getAtPath(profile, env.CUSTOM_OAUTH_USER_EMAIL_PATH),
image: getAtPath(profile, env.CUSTOM_OAUTH_USER_IMAGE_PATH),
} as User
},
})

View File

@@ -187,7 +187,7 @@ const getEmailInfo = async (
if (credentialsId === 'default')
return {
host: defaultTransportOptions.host,
port: defaultTransportOptions.port ?? 22,
port: defaultTransportOptions.port,
username: defaultTransportOptions.auth.user,
password: defaultTransportOptions.auth.pass,
isTlsEnabled: undefined,

34
packages/env/env.ts vendored
View File

@@ -21,7 +21,7 @@ const baseEnv = {
.refine((url) => url.startsWith('postgres') || url.startsWith('mysql')),
ENCRYPTION_SECRET: z.string().length(32),
NEXTAUTH_URL: z.string().url(),
DISABLE_SIGNUP: boolean.optional(),
DISABLE_SIGNUP: boolean.optional().default('false'),
ADMIN_EMAIL: z.string().email().optional(),
DEFAULT_WORKSPACE_PLAN: z
.enum(['FREE', 'STARTER', 'PRO', 'LIFETIME', 'UNLIMITED'])
@@ -29,7 +29,7 @@ const baseEnv = {
['FREE', 'STARTER', 'PRO', 'LIFETIME', 'UNLIMITED'].includes(str)
)
.default('FREE'),
DEBUG: boolean.optional(),
DEBUG: boolean.optional().default('false'),
},
client: {
NEXT_PUBLIC_E2E_TEST: boolean.optional(),
@@ -70,9 +70,9 @@ const smtpEnv = {
SMTP_USERNAME: z.string().min(1).optional(),
SMTP_PASSWORD: z.string().min(1).optional(),
SMTP_HOST: z.string().min(1).optional(),
SMTP_PORT: z.coerce.number().optional(),
SMTP_AUTH_DISABLED: boolean.optional(),
SMTP_SECURE: boolean.optional(),
SMTP_PORT: z.coerce.number().optional().default(25),
SMTP_AUTH_DISABLED: boolean.optional().default('false'),
SMTP_SECURE: boolean.optional().default('false'),
},
client: {
NEXT_PUBLIC_SMTP_FROM: z.string().min(1).optional(),
@@ -86,8 +86,8 @@ const gitlabEnv = {
server: {
GITLAB_CLIENT_ID: z.string().min(1).optional(),
GITLAB_CLIENT_SECRET: z.string().min(1).optional(),
GITLAB_BASE_URL: z.string().url().optional(),
GITLAB_NAME: z.string().min(1).optional(),
GITLAB_BASE_URL: z.string().url().optional().default('https://gitlab.com'),
GITLAB_NAME: z.string().min(1).optional().default('GitLab'),
GITLAB_REQUIRED_GROUPS: z
.string()
.transform((string) => (string ? string.split(',') : undefined))
@@ -105,15 +105,19 @@ const azureEnv = {
const customOAuthEnv = {
server: {
CUSTOM_OAUTH_NAME: z.string().min(1).optional(),
CUSTOM_OAUTH_SCOPE: z.string().min(1).optional(),
CUSTOM_OAUTH_NAME: z.string().min(1).optional().default('Custom OAuth'),
CUSTOM_OAUTH_SCOPE: z
.string()
.min(1)
.optional()
.default('openid profile email'),
CUSTOM_OAUTH_CLIENT_ID: z.string().min(1).optional(),
CUSTOM_OAUTH_CLIENT_SECRET: z.string().min(1).optional(),
CUSTOM_OAUTH_WELL_KNOWN_URL: z.string().url().optional(),
CUSTOM_OAUTH_USER_ID_PATH: z.string().min(1).optional(),
CUSTOM_OAUTH_USER_EMAIL_PATH: z.string().min(1).optional(),
CUSTOM_OAUTH_USER_NAME_PATH: z.string().min(1).optional(),
CUSTOM_OAUTH_USER_IMAGE_PATH: z.string().min(1).optional(),
CUSTOM_OAUTH_USER_ID_PATH: z.string().min(1).optional().default('id'),
CUSTOM_OAUTH_USER_EMAIL_PATH: z.string().min(1).optional().default('email'),
CUSTOM_OAUTH_USER_NAME_PATH: z.string().min(1).optional().default('name'),
CUSTOM_OAUTH_USER_IMAGE_PATH: z.string().min(1).optional().default('image'),
},
}
@@ -165,10 +169,10 @@ const s3Env = {
server: {
S3_ACCESS_KEY: z.string().min(1).optional(),
S3_SECRET_KEY: z.string().min(1).optional(),
S3_BUCKET: z.string().min(1).optional(),
S3_BUCKET: z.string().min(1).optional().default('typebot'),
S3_PORT: z.coerce.number().optional(),
S3_ENDPOINT: z.string().min(1).optional(),
S3_SSL: boolean.optional(),
S3_SSL: boolean.optional().default('true'),
S3_REGION: z.string().min(1).optional(),
},
}