🧑‍💻 Improve env variables type safety and management (#718)

Closes #679
This commit is contained in:
Baptiste Arnaud
2023-08-28 09:13:53 +02:00
committed by GitHub
parent a23a8c4456
commit 786e5cb582
148 changed files with 1550 additions and 1293 deletions

View File

@@ -4,11 +4,12 @@ import { GoogleSheetsCredentials } from '@typebot.io/schemas'
import { isDefined } from '@typebot.io/lib'
import { decrypt, encrypt } from '@typebot.io/lib/api'
import prisma from './prisma'
import { env } from '@typebot.io/env'
export const oauth2Client = new OAuth2Client(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
`${process.env.NEXTAUTH_URL}/api/credentials/google-sheets/callback`
env.GOOGLE_CLIENT_ID,
env.GOOGLE_CLIENT_SECRET,
`${env.NEXTAUTH_URL}/api/credentials/google-sheets/callback`
)
export const getAuthenticatedGoogleClient = async (

View File

@@ -2,6 +2,7 @@
* Instantiates a single instance PrismaClient and save it on the global object.
* @link https://www.prisma.io/docs/support/help-articles/nextjs-prisma-client-dev-practices
*/
import { env } from '@typebot.io/env'
import { PrismaClient } from '@typebot.io/prisma'
const prismaGlobal = global as typeof global & {
@@ -11,10 +12,10 @@ const prismaGlobal = global as typeof global & {
const prisma: PrismaClient =
prismaGlobal.prisma ||
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
log: env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
})
if (process.env.NODE_ENV !== 'production') {
if (env.NODE_ENV !== 'production') {
prismaGlobal.prisma = prisma
}

View File

@@ -2,10 +2,9 @@ import { createTRPCProxyClient, httpBatchLink, loggerLink } from '@trpc/client'
import { createTRPCNext } from '@trpc/next'
import type { AppRouter } from '../helpers/server/routers/v1/trpcRouter'
import superjson from 'superjson'
import { env } from '@typebot.io/lib'
import { env } from '@typebot.io/env'
const getBaseUrl = () =>
typeof window !== 'undefined' ? '' : process.env.NEXTAUTH_URL
const getBaseUrl = () => (typeof window !== 'undefined' ? '' : env.NEXTAUTH_URL)
export const trpc = createTRPCNext<AppRouter>({
config() {
@@ -36,5 +35,5 @@ export const trpcVanilla = createTRPCProxyClient<AppRouter>({
})
export const defaultQueryOptions = {
refetchOnMount: env('E2E_TEST') === 'true',
refetchOnMount: env.NEXT_PUBLIC_E2E_TEST,
}