🧑💻 Improve env variables type safety and management (#718)
Closes #679
This commit is contained in:
@@ -7,14 +7,14 @@ import {
|
||||
} from '@typebot.io/prisma'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { NextApiResponse } from 'next'
|
||||
import { env, isNotEmpty } from '@typebot.io/lib'
|
||||
import { forbidden } from '@typebot.io/lib/api'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
export const canWriteTypebots = (
|
||||
typebotIds: string[] | string,
|
||||
user: Pick<User, 'email' | 'id'>
|
||||
): Prisma.TypebotWhereInput =>
|
||||
isNotEmpty(env('E2E_TEST'))
|
||||
env.NEXT_PUBLIC_E2E_TEST
|
||||
? { id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds } }
|
||||
: {
|
||||
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
|
||||
@@ -40,7 +40,7 @@ export const canReadTypebots = (
|
||||
) => ({
|
||||
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
|
||||
workspace:
|
||||
user.email === process.env.ADMIN_EMAIL || isNotEmpty(env('E2E_TEST'))
|
||||
user.email === env.ADMIN_EMAIL || env.NEXT_PUBLIC_E2E_TEST
|
||||
? undefined
|
||||
: {
|
||||
members: {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { Client } from 'minio'
|
||||
|
||||
export const deleteFilesFromBucket = async ({
|
||||
@@ -5,32 +6,26 @@ export 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])
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user