🧑💻 Improve env variables type safety and management (#718)
Closes #679
This commit is contained in:
@@ -65,8 +65,6 @@ export const TypebotViewer = ({
|
||||
|
||||
const handleCompleted = () => onCompleted && onCompleted()
|
||||
|
||||
if (isEmpty(apiHost))
|
||||
return <p>process.env.NEXT_PUBLIC_VIEWER_URL is missing in env</p>
|
||||
return (
|
||||
<>
|
||||
<style>
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
"@typebot.io/lib": "workspace:*",
|
||||
"eslint": "8.44.0",
|
||||
"eslint-config-custom": "workspace:*",
|
||||
"@typebot.io/tsconfig": "workspace:*"
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@typebot.io/env": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@faire/mjml-react": "2.1.4",
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { createTransport, SendMailOptions } from 'nodemailer'
|
||||
import { env } from '@typebot.io/lib'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
export const sendEmail = (
|
||||
props: Pick<SendMailOptions, 'to' | 'html' | 'subject'>
|
||||
) => {
|
||||
const transporter = createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: Number(process.env.SMTP_PORT),
|
||||
host: env.SMTP_HOST,
|
||||
port: env.SMTP_PORT,
|
||||
auth: {
|
||||
user: process.env.SMTP_USERNAME,
|
||||
pass: process.env.SMTP_PASSWORD,
|
||||
user: env.SMTP_USERNAME,
|
||||
pass: env.SMTP_PASSWORD,
|
||||
},
|
||||
})
|
||||
|
||||
return transporter.sendMail({
|
||||
from: process.env.SMTP_FROM ?? env('SMTP_FROM'),
|
||||
from: env.NEXT_PUBLIC_SMTP_FROM,
|
||||
...props,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"@rollup/plugin-terser": "0.4.3",
|
||||
"@rollup/plugin-typescript": "11.1.2",
|
||||
"@typebot.io/lib": "workspace:*",
|
||||
"@typebot.io/env": "workspace:*",
|
||||
"@typebot.io/schemas": "workspace:*",
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"autoprefixer": "10.4.14",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { env } from '@typebot.io/lib'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
const cloudViewerUrl = 'https://viewer.typebot.io'
|
||||
|
||||
export const guessApiHost = () =>
|
||||
env('VIEWER_INTERNAL_URL') ??
|
||||
env('VIEWER_URL')?.split(',')[0] ??
|
||||
env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ??
|
||||
env.NEXT_PUBLIC_VIEWER_URL[0] ??
|
||||
cloudViewerUrl
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
DATABASE_URL=postgresql://postgres:typebot@localhost:5432/typebot
|
||||
315
packages/env/env.ts
vendored
Normal file
315
packages/env/env.ts
vendored
Normal file
@@ -0,0 +1,315 @@
|
||||
import { createEnv } from '@t3-oss/env-nextjs'
|
||||
import { z } from 'zod'
|
||||
|
||||
declare const window: {
|
||||
__ENV: any
|
||||
}
|
||||
|
||||
const getRuntimeVariable = (key: string) => {
|
||||
if (typeof window === 'undefined') return process.env[key]
|
||||
return window.__ENV[key]
|
||||
}
|
||||
|
||||
const boolean = z.enum(['true', 'false']).transform((value) => value === 'true')
|
||||
|
||||
const baseEnv = {
|
||||
server: {
|
||||
NODE_ENV: z.enum(['development', 'production', 'test']).optional(),
|
||||
DATABASE_URL: z
|
||||
.string()
|
||||
.url()
|
||||
.refine((url) => url.startsWith('postgres') || url.startsWith('mysql')),
|
||||
ENCRYPTION_SECRET: z.string().length(32),
|
||||
NEXTAUTH_URL: z.string().url(),
|
||||
DISABLE_SIGNUP: boolean.optional(),
|
||||
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(),
|
||||
},
|
||||
client: {
|
||||
NEXT_PUBLIC_E2E_TEST: boolean.optional(),
|
||||
NEXT_PUBLIC_VIEWER_URL: z
|
||||
.string()
|
||||
.min(1)
|
||||
.transform((string) => string.split(',')),
|
||||
NEXT_PUBLIC_VIEWER_INTERNAL_URL: z.string().url().optional(),
|
||||
NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_E2E_TEST: getRuntimeVariable('NEXT_PUBLIC_E2E_TEST'),
|
||||
NEXT_PUBLIC_VIEWER_URL: getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL'),
|
||||
NEXT_PUBLIC_VIEWER_INTERNAL_URL: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_VIEWER_INTERNAL_URL'
|
||||
),
|
||||
NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID'
|
||||
),
|
||||
},
|
||||
}
|
||||
const githubEnv = {
|
||||
server: {
|
||||
GITHUB_CLIENT_ID: z.string().min(1).optional(),
|
||||
GITHUB_CLIENT_SECRET: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const facebookEnv = {
|
||||
server: {
|
||||
FACEBOOK_CLIENT_ID: z.string().min(1).optional(),
|
||||
FACEBOOK_CLIENT_SECRET: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const smtpEnv = {
|
||||
server: {
|
||||
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(),
|
||||
},
|
||||
client: {
|
||||
NEXT_PUBLIC_SMTP_FROM: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_SMTP_FROM: getRuntimeVariable('NEXT_PUBLIC_SMTP_FROM'),
|
||||
},
|
||||
}
|
||||
|
||||
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_REQUIRED_GROUPS: z
|
||||
.string()
|
||||
.transform((string) => (string ? string.split(',') : undefined))
|
||||
.optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const azureEnv = {
|
||||
server: {
|
||||
AZURE_AD_CLIENT_ID: z.string().min(1).optional(),
|
||||
AZURE_AD_CLIENT_SECRET: z.string().min(1).optional(),
|
||||
AZURE_AD_TENANT_ID: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const customOAuthEnv = {
|
||||
server: {
|
||||
CUSTOM_OAUTH_NAME: z.string().min(1).optional(),
|
||||
CUSTOM_OAUTH_SCOPE: z.string().min(1).optional(),
|
||||
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(),
|
||||
},
|
||||
}
|
||||
|
||||
const googleEnv = {
|
||||
server: {
|
||||
GOOGLE_CLIENT_ID: z.string().min(1).optional(),
|
||||
GOOGLE_CLIENT_SECRET: z.string().min(1).optional(),
|
||||
},
|
||||
client: {
|
||||
NEXT_PUBLIC_GOOGLE_API_KEY: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_GOOGLE_API_KEY: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_GOOGLE_API_KEY'
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
const stripeEnv = {
|
||||
server: {
|
||||
STRIPE_SECRET_KEY: z.string().min(1).optional(),
|
||||
STRIPE_WEBHOOK_SECRET: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_PRODUCT_ID: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_MONTHLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_YEARLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_CHATS_MONTHLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_CHATS_YEARLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_STORAGE_MONTHLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_STARTER_STORAGE_YEARLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_PRODUCT_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_MONTHLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_YEARLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_CHATS_MONTHLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_CHATS_YEARLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_STORAGE_MONTHLY_PRICE_ID: z.string().min(1).optional(),
|
||||
STRIPE_PRO_STORAGE_YEARLY_PRICE_ID: z.string().min(1).optional(),
|
||||
},
|
||||
client: {
|
||||
NEXT_PUBLIC_STRIPE_PUBLIC_KEY: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_STRIPE_PUBLIC_KEY: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_STRIPE_PUBLIC_KEY'
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
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_PORT: z.coerce.number().optional(),
|
||||
S3_ENDPOINT: z.string().min(1).optional(),
|
||||
S3_SSL: boolean.optional(),
|
||||
S3_REGION: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const giphyEnv = {
|
||||
client: {
|
||||
NEXT_PUBLIC_GIPHY_API_KEY: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_GIPHY_API_KEY: getRuntimeVariable('NEXT_PUBLIC_GIPHY_API_KEY'),
|
||||
},
|
||||
}
|
||||
|
||||
const vercelEnv = {
|
||||
server: {
|
||||
VERCEL_TOKEN: z.string().min(1).optional(),
|
||||
VERCEL_TEAM_ID: z.string().min(1).optional(),
|
||||
VERCEL_GIT_COMMIT_SHA: z.string().min(1).optional(),
|
||||
},
|
||||
client: {
|
||||
NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME: z.string().min(1).optional(),
|
||||
NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA: z.string().min(1).optional(),
|
||||
NEXT_PUBLIC_VERCEL_ENV: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME'
|
||||
),
|
||||
NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA'
|
||||
),
|
||||
NEXT_PUBLIC_VERCEL_ENV: getRuntimeVariable('NEXT_PUBLIC_VERCEL_ENV'),
|
||||
},
|
||||
}
|
||||
|
||||
const sleekPlanEnv = {
|
||||
server: {
|
||||
SLEEKPLAN_SSO_KEY: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const unsplashEnv = {
|
||||
client: {
|
||||
NEXT_PUBLIC_UNSPLASH_APP_NAME: z.string().min(1).optional(),
|
||||
NEXT_PUBLIC_UNSPLASH_ACCESS_KEY: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_UNSPLASH_APP_NAME: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_UNSPLASH_APP_NAME'
|
||||
),
|
||||
NEXT_PUBLIC_UNSPLASH_ACCESS_KEY: getRuntimeVariable(
|
||||
'NEXT_PUBLIC_UNSPLASH_ACCESS_KEY'
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
const whatsAppEnv = {
|
||||
server: {
|
||||
META_SYSTEM_USER_TOKEN: z.string().min(1).optional(),
|
||||
WHATSAPP_PREVIEW_FROM_PHONE_NUMBER_ID: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const upstashRedis = {
|
||||
server: {
|
||||
UPSTASH_REDIS_REST_URL: z.string().url().optional(),
|
||||
UPSTASH_REDIS_REST_TOKEN: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const sentryEnv = {
|
||||
client: {
|
||||
NEXT_PUBLIC_SENTRY_DSN: z.string().min(1).optional(),
|
||||
},
|
||||
server: {
|
||||
SENTRY_AUTH_TOKEN: z.string().min(1).optional(),
|
||||
SENTRY_PROJECT: z.string().min(1).optional(),
|
||||
SENTRY_ORG: z.string().min(1).optional(),
|
||||
},
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_SENTRY_DSN: getRuntimeVariable('NEXT_PUBLIC_SENTRY_DSN'),
|
||||
},
|
||||
}
|
||||
|
||||
const telemetryEnv = {
|
||||
server: {
|
||||
TELEMETRY_WEBHOOK_URL: z.string().url().optional(),
|
||||
TELEMETRY_WEBHOOK_BEARER_TOKEN: z.string().min(1).optional(),
|
||||
USER_CREATED_WEBHOOK_URL: z.string().url().optional(),
|
||||
},
|
||||
}
|
||||
|
||||
const posthogEnv = {
|
||||
server: {
|
||||
POSTHOG_API_KEY: z.string().min(1).optional(),
|
||||
},
|
||||
}
|
||||
|
||||
export const env = createEnv({
|
||||
server: {
|
||||
...baseEnv.server,
|
||||
...githubEnv.server,
|
||||
...facebookEnv.server,
|
||||
...smtpEnv.server,
|
||||
...googleEnv.server,
|
||||
...stripeEnv.server,
|
||||
...s3Env.server,
|
||||
...vercelEnv.server,
|
||||
...sleekPlanEnv.server,
|
||||
...whatsAppEnv.server,
|
||||
...upstashRedis.server,
|
||||
...gitlabEnv.server,
|
||||
...azureEnv.server,
|
||||
...customOAuthEnv.server,
|
||||
...sentryEnv.server,
|
||||
...telemetryEnv.server,
|
||||
...posthogEnv.server,
|
||||
},
|
||||
client: {
|
||||
...baseEnv.client,
|
||||
...smtpEnv.client,
|
||||
...googleEnv.client,
|
||||
...stripeEnv.client,
|
||||
...giphyEnv.client,
|
||||
...vercelEnv.client,
|
||||
...unsplashEnv.client,
|
||||
...sentryEnv.client,
|
||||
},
|
||||
experimental__runtimeEnv: {
|
||||
...baseEnv.runtimeEnv,
|
||||
...smtpEnv.runtimeEnv,
|
||||
...googleEnv.runtimeEnv,
|
||||
...stripeEnv.runtimeEnv,
|
||||
...giphyEnv.runtimeEnv,
|
||||
...vercelEnv.runtimeEnv,
|
||||
...unsplashEnv.runtimeEnv,
|
||||
...sentryEnv.runtimeEnv,
|
||||
},
|
||||
// onInvalidAccess: (variable: string) => {
|
||||
// throw new Error(
|
||||
// `❌ Attempted to access a server-side environment variable on the client: ${variable}`
|
||||
// )
|
||||
// },
|
||||
})
|
||||
20
packages/env/package.json
vendored
Normal file
20
packages/env/package.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@typebot.io/env",
|
||||
"version": "1.0.0",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"private": true,
|
||||
"main": "./env.ts",
|
||||
"types": "./env.ts",
|
||||
"dependencies": {
|
||||
"@t3-oss/env-nextjs": "^0.6.0",
|
||||
"zod": "3.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@types/node": "^20.4.9",
|
||||
"esbuild": "^0.19.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "esbuild env.ts --packages=external --outfile=dist/env.mjs"
|
||||
}
|
||||
}
|
||||
5
packages/env/tsconfig.json
vendored
Normal file
5
packages/env/tsconfig.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "@typebot.io/tsconfig/base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Credentials } from '@typebot.io/schemas/features/credentials'
|
||||
import { decryptV1 } from './encryptionV1'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
const algorithm = 'AES-GCM'
|
||||
const secretKey = process.env.ENCRYPTION_SECRET
|
||||
const secretKey = env.ENCRYPTION_SECRET
|
||||
|
||||
export const encrypt = async (
|
||||
data: object
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { createDecipheriv } from 'crypto'
|
||||
|
||||
const algorithm = 'aes-256-gcm'
|
||||
const secretKey = process.env.ENCRYPTION_SECRET
|
||||
const secretKey = env.ENCRYPTION_SECRET
|
||||
|
||||
export const decryptV1 = (encryptedData: string, auth: string): object => {
|
||||
if (!secretKey) throw new Error(`ENCRYPTION_SECRET is not in environment`)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { Prisma, PrismaClient } from '@typebot.io/prisma'
|
||||
import { InputBlockType, Typebot } from '@typebot.io/schemas'
|
||||
import { Client } from 'minio'
|
||||
@@ -95,32 +96,26 @@ const deleteFilesFromBucket = async ({
|
||||
}: {
|
||||
urls: string[]
|
||||
}): Promise<void> => {
|
||||
if (
|
||||
!process.env.S3_ENDPOINT ||
|
||||
!process.env.S3_ACCESS_KEY ||
|
||||
!process.env.S3_SECRET_KEY
|
||||
)
|
||||
if (!env.S3_ENDPOINT || !env.S3_ACCESS_KEY || !env.S3_SECRET_KEY)
|
||||
throw new Error(
|
||||
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
|
||||
)
|
||||
|
||||
const useSSL =
|
||||
process.env.S3_SSL && process.env.S3_SSL === 'false' ? false : true
|
||||
const minioClient = new Client({
|
||||
endPoint: process.env.S3_ENDPOINT,
|
||||
port: process.env.S3_PORT ? parseInt(process.env.S3_PORT) : undefined,
|
||||
useSSL,
|
||||
accessKey: process.env.S3_ACCESS_KEY,
|
||||
secretKey: process.env.S3_SECRET_KEY,
|
||||
region: process.env.S3_REGION,
|
||||
endPoint: env.S3_ENDPOINT,
|
||||
port: env.S3_PORT,
|
||||
useSSL: env.S3_SSL,
|
||||
accessKey: env.S3_ACCESS_KEY,
|
||||
secretKey: env.S3_SECRET_KEY,
|
||||
region: env.S3_REGION,
|
||||
})
|
||||
|
||||
const bucket = process.env.S3_BUCKET ?? 'typebot'
|
||||
const bucket = env.S3_BUCKET ?? 'typebot'
|
||||
|
||||
return minioClient.removeObjects(
|
||||
bucket,
|
||||
urls
|
||||
.filter((url) => url.includes(process.env.S3_ENDPOINT as string))
|
||||
.filter((url) => url.includes(env.S3_ENDPOINT as string))
|
||||
.map((url) => url.split(`/${bucket}/`)[1])
|
||||
)
|
||||
}
|
||||
|
||||
33
packages/lib/api/pricing.ts
Normal file
33
packages/lib/api/pricing.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { Plan } from '@typebot.io/prisma'
|
||||
|
||||
export const priceIds = {
|
||||
[Plan.STARTER]: {
|
||||
base: {
|
||||
monthly: env.STRIPE_STARTER_MONTHLY_PRICE_ID,
|
||||
yearly: env.STRIPE_STARTER_YEARLY_PRICE_ID,
|
||||
},
|
||||
chats: {
|
||||
monthly: env.STRIPE_STARTER_CHATS_MONTHLY_PRICE_ID,
|
||||
yearly: env.STRIPE_STARTER_CHATS_YEARLY_PRICE_ID,
|
||||
},
|
||||
storage: {
|
||||
monthly: env.STRIPE_STARTER_STORAGE_MONTHLY_PRICE_ID,
|
||||
yearly: env.STRIPE_STARTER_STORAGE_YEARLY_PRICE_ID,
|
||||
},
|
||||
},
|
||||
[Plan.PRO]: {
|
||||
base: {
|
||||
monthly: env.STRIPE_PRO_MONTHLY_PRICE_ID,
|
||||
yearly: env.STRIPE_PRO_YEARLY_PRICE_ID,
|
||||
},
|
||||
chats: {
|
||||
monthly: env.STRIPE_PRO_CHATS_MONTHLY_PRICE_ID,
|
||||
yearly: env.STRIPE_PRO_CHATS_YEARLY_PRICE_ID,
|
||||
},
|
||||
storage: {
|
||||
monthly: env.STRIPE_PRO_STORAGE_MONTHLY_PRICE_ID,
|
||||
yearly: env.STRIPE_PRO_STORAGE_YEARLY_PRICE_ID,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { config, Endpoint, S3 } from 'aws-sdk'
|
||||
|
||||
type GeneratePresignedUrlProps = {
|
||||
@@ -14,34 +15,26 @@ export const generatePresignedUrl = ({
|
||||
fileType,
|
||||
sizeLimit = tenMB,
|
||||
}: GeneratePresignedUrlProps): S3.PresignedPost => {
|
||||
if (
|
||||
!process.env.S3_ENDPOINT ||
|
||||
!process.env.S3_ACCESS_KEY ||
|
||||
!process.env.S3_SECRET_KEY
|
||||
)
|
||||
if (!env.S3_ENDPOINT || !env.S3_ACCESS_KEY || !env.S3_SECRET_KEY)
|
||||
throw new Error(
|
||||
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
|
||||
)
|
||||
|
||||
const sslEnabled =
|
||||
process.env.S3_SSL && process.env.S3_SSL === 'false' ? false : true
|
||||
config.update({
|
||||
accessKeyId: process.env.S3_ACCESS_KEY,
|
||||
secretAccessKey: process.env.S3_SECRET_KEY,
|
||||
region: process.env.S3_REGION,
|
||||
sslEnabled,
|
||||
accessKeyId: env.S3_ACCESS_KEY,
|
||||
secretAccessKey: env.S3_SECRET_KEY,
|
||||
region: env.S3_REGION,
|
||||
sslEnabled: env.S3_SSL,
|
||||
})
|
||||
const protocol = sslEnabled ? 'https' : 'http'
|
||||
const protocol = env.S3_SSL ? 'https' : 'http'
|
||||
const s3 = new S3({
|
||||
endpoint: new Endpoint(
|
||||
`${protocol}://${process.env.S3_ENDPOINT}${
|
||||
process.env.S3_PORT ? `:${process.env.S3_PORT}` : ''
|
||||
}`
|
||||
`${protocol}://${env.S3_ENDPOINT}${env.S3_PORT ? `:${env.S3_PORT}` : ''}`
|
||||
),
|
||||
})
|
||||
|
||||
const presignedUrl = s3.createPresignedPost({
|
||||
Bucket: process.env.S3_BUCKET ?? 'typebot',
|
||||
Bucket: env.S3_BUCKET ?? 'typebot',
|
||||
Fields: {
|
||||
key: filePath,
|
||||
'Content-Type': fileType,
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@types/nodemailer": "6.4.8",
|
||||
"aws-sdk": "2.1415.0",
|
||||
"dotenv": "16.3.1",
|
||||
"next": "13.4.3",
|
||||
"nodemailer": "6.9.3",
|
||||
"typescript": "5.1.6"
|
||||
"typescript": "5.1.6",
|
||||
"@typebot.io/env": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"aws-sdk": "2.1152.0",
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
import { PlaywrightTestConfig } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
const builderLocalEnvPath = path.join(
|
||||
__dirname,
|
||||
'../../../apps/builder/.env.local'
|
||||
)
|
||||
const localViewerEnvPath = path.join(
|
||||
__dirname,
|
||||
'../../../apps/viewer/.env.local'
|
||||
)
|
||||
if (fs.existsSync(builderLocalEnvPath))
|
||||
require('dotenv').config({
|
||||
path: builderLocalEnvPath,
|
||||
})
|
||||
|
||||
if (fs.existsSync(localViewerEnvPath))
|
||||
require('dotenv').config({
|
||||
path: localViewerEnvPath,
|
||||
})
|
||||
|
||||
export const playwrightBaseConfig: PlaywrightTestConfig = {
|
||||
globalSetup: require.resolve(path.join(__dirname, 'globalSetup')),
|
||||
|
||||
@@ -3,37 +3,6 @@ import { Plan } from '@typebot.io/prisma'
|
||||
|
||||
const infinity = -1
|
||||
|
||||
export const priceIds = {
|
||||
[Plan.STARTER]: {
|
||||
base: {
|
||||
monthly: process.env.STRIPE_STARTER_MONTHLY_PRICE_ID,
|
||||
yearly: process.env.STRIPE_STARTER_YEARLY_PRICE_ID,
|
||||
},
|
||||
chats: {
|
||||
monthly: process.env.STRIPE_STARTER_CHATS_MONTHLY_PRICE_ID,
|
||||
yearly: process.env.STRIPE_STARTER_CHATS_YEARLY_PRICE_ID,
|
||||
},
|
||||
storage: {
|
||||
monthly: process.env.STRIPE_STARTER_STORAGE_MONTHLY_PRICE_ID,
|
||||
yearly: process.env.STRIPE_STARTER_STORAGE_YEARLY_PRICE_ID,
|
||||
},
|
||||
},
|
||||
[Plan.PRO]: {
|
||||
base: {
|
||||
monthly: process.env.STRIPE_PRO_MONTHLY_PRICE_ID,
|
||||
yearly: process.env.STRIPE_PRO_YEARLY_PRICE_ID,
|
||||
},
|
||||
chats: {
|
||||
monthly: process.env.STRIPE_PRO_CHATS_MONTHLY_PRICE_ID,
|
||||
yearly: process.env.STRIPE_PRO_CHATS_YEARLY_PRICE_ID,
|
||||
},
|
||||
storage: {
|
||||
monthly: process.env.STRIPE_PRO_STORAGE_MONTHLY_PRICE_ID,
|
||||
yearly: process.env.STRIPE_PRO_STORAGE_YEARLY_PRICE_ID,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const prices = {
|
||||
[Plan.STARTER]: 39,
|
||||
[Plan.PRO]: 89,
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import got from 'got'
|
||||
import { TelemetryEvent } from '@typebot.io/schemas/features/telemetry'
|
||||
import { isEmpty, isNotEmpty } from '../utils'
|
||||
import { isNotEmpty } from '../utils'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
export const sendTelemetryEvents = async (events: TelemetryEvent[]) => {
|
||||
if (events.length === 0) return { message: 'No events to send' }
|
||||
if (isEmpty(process.env.TELEMETRY_WEBHOOK_URL))
|
||||
return { message: 'Telemetry not enabled' }
|
||||
if (!env.TELEMETRY_WEBHOOK_URL) return { message: 'Telemetry not enabled' }
|
||||
|
||||
try {
|
||||
await got.post(process.env.TELEMETRY_WEBHOOK_URL, {
|
||||
await got.post(env.TELEMETRY_WEBHOOK_URL, {
|
||||
json: { events },
|
||||
headers: {
|
||||
authorization: isNotEmpty(process.env.TELEMETRY_WEBHOOK_BEARER_TOKEN)
|
||||
? `Bearer ${process.env.TELEMETRY_WEBHOOK_BEARER_TOKEN}`
|
||||
authorization: env.TELEMETRY_WEBHOOK_BEARER_TOKEN
|
||||
? `Bearer ${env.TELEMETRY_WEBHOOK_BEARER_TOKEN}`
|
||||
: undefined,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -19,6 +19,7 @@ import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/enu
|
||||
import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/enums'
|
||||
import { IntegrationBlockType } from '@typebot.io/schemas/features/blocks/integrations/enums'
|
||||
import { PictureChoiceBlock } from '@typebot.io/schemas/features/blocks/inputs/pictureChoice'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
export const sendRequest = async <ResponseData>(
|
||||
params:
|
||||
@@ -249,16 +250,6 @@ export const uploadFiles = async ({
|
||||
|
||||
declare const window: any
|
||||
|
||||
export const env = (key = ''): string | undefined => {
|
||||
if (typeof window === 'undefined')
|
||||
return isEmpty(process.env['NEXT_PUBLIC_' + key])
|
||||
? undefined
|
||||
: (process.env['NEXT_PUBLIC_' + key] as string)
|
||||
|
||||
if (typeof window !== 'undefined' && window.__env)
|
||||
return isEmpty(window.__env[key]) ? undefined : window.__env[key]
|
||||
}
|
||||
|
||||
export const hasValue = (
|
||||
value: string | undefined | null
|
||||
): value is NonNullable<string> =>
|
||||
@@ -268,10 +259,8 @@ export const hasValue = (
|
||||
value !== 'undefined' &&
|
||||
value !== 'null'
|
||||
|
||||
export const getViewerUrl = (props?: {
|
||||
returnAll?: boolean
|
||||
}): string | undefined =>
|
||||
props?.returnAll ? env('VIEWER_URL') : env('VIEWER_URL')?.split(',')[0]
|
||||
export const getViewerUrl = () =>
|
||||
env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ?? env.NEXT_PUBLIC_VIEWER_URL[0]
|
||||
|
||||
export const parseNumberWithCommas = (num: number) =>
|
||||
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
DATABASE_URL=postgresql://postgres:typebot@localhost:5432/typebot
|
||||
@@ -6,11 +6,11 @@
|
||||
"types": "./index.ts",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "tsx scripts/studio.ts",
|
||||
"db:generate": "tsx scripts/db-generate.ts",
|
||||
"db:push": "tsx scripts/db-push.ts",
|
||||
"migrate:deploy": "tsx scripts/migrate-deploy.ts",
|
||||
"migrate:dev": "prisma migrate dev --create-only --schema postgresql/schema.prisma",
|
||||
"dev": "dotenv -e ./.env -e ../../.env -- tsx scripts/studio.ts",
|
||||
"db:generate": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-generate.ts",
|
||||
"db:push": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-push.ts",
|
||||
"migrate:deploy": "dotenv -e ./.env -e ../../.env -- tsx scripts/migrate-deploy.ts",
|
||||
"migrate:dev": "dotenv -e ./.env -e ../../.env -- prisma migrate dev --create-only --schema postgresql/schema.prisma",
|
||||
"db:migrate": "pnpm migrate:deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "20.4.2",
|
||||
"dotenv": "16.3.1",
|
||||
"dotenv-cli": "^7.2.1",
|
||||
"prisma": "5.0.0",
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"tsx": "3.12.7",
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { exec } from 'child_process'
|
||||
import { join, relative } from 'path'
|
||||
|
||||
require('dotenv').config({
|
||||
override: true,
|
||||
path: join(__dirname, `../.env`),
|
||||
})
|
||||
|
||||
const postgesqlSchemaPath = relative(
|
||||
process.cwd(),
|
||||
join(__dirname, `../postgresql/schema.prisma`)
|
||||
@@ -34,13 +29,13 @@ export const executePrismaCommand = (command: string, options?: Options) => {
|
||||
executeCommand(`${command} --schema ${mysqlSchemaPath}`)
|
||||
}
|
||||
|
||||
if (databaseUrl?.startsWith('postgresql://')) {
|
||||
if (databaseUrl?.startsWith('postgres')) {
|
||||
console.log('Executing for PostgreSQL schema')
|
||||
executeCommand(`${command} --schema ${postgesqlSchemaPath}`)
|
||||
}
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgres://')) {
|
||||
console.error('PostgreSQL `DATABASE_URL` should start with postgresql://')
|
||||
console.error('PostgreSQL `DATABASE_URL` should start with postgres')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgresql://'))
|
||||
if (process.env.DATABASE_URL?.startsWith('postgres'))
|
||||
executePrismaCommand('prisma migrate deploy')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { executePrismaCommand } from './executeCommand'
|
||||
|
||||
if (process.env.DATABASE_URL?.startsWith('postgresql://'))
|
||||
if (process.env.DATABASE_URL?.startsWith('postgres'))
|
||||
executePrismaCommand('prisma migrate dev --create-only')
|
||||
|
||||
Reference in New Issue
Block a user