Skip to content

Commit

Permalink
🚑 Set proper env defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Aug 28, 2023
1 parent 1c680c3 commit efd4600
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions apps/builder/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,15 +72,15 @@ 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,
clientSecret: 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,
})
)
}
Expand All @@ -102,22 +102,22 @@ 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,
clientSecret: env.CUSTOM_OAUTH_CLIENT_SECRET,
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
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 19 additions & 15 deletions packages/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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'])
.refine((str) =>
['FREE', 'STARTER', 'PRO', 'LIFETIME', 'UNLIMITED'].includes(str)
)
.default('FREE'),
DEBUG: boolean.optional(),
DEBUG: boolean.optional().default('false'),
},
client: {
NEXT_PUBLIC_E2E_TEST: boolean.optional(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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))
Expand All @@ -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'),
},
}

Expand Down Expand Up @@ -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(),
},
}
Expand Down

1 comment on commit efd4600

@vercel
Copy link

@vercel vercel bot commented on efd4600 Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

Please sign in to comment.