2
0

fix(docker): 🐛 Runtime public environment

This commit is contained in:
Baptiste Arnaud
2022-06-21 10:36:41 +02:00
parent ea765640cf
commit e03fe9f7d9
54 changed files with 349 additions and 164 deletions

View File

@ -1,7 +1,7 @@
import { CollaborationType, Plan, Prisma, User, WorkspaceRole } from 'db'
import prisma from 'libs/prisma'
import { NextApiResponse } from 'next'
import { forbidden, isNotEmpty } from 'utils'
import { env, forbidden, isNotEmpty } from 'utils'
const parseWhereFilter = (
typebotIds: string[] | string,
@ -22,7 +22,7 @@ const parseWhereFilter = (
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
workspace:
(type === 'read' && user.email === process.env.ADMIN_EMAIL) ||
isNotEmpty(process.env.NEXT_PUBLIC_E2E_TEST)
isNotEmpty(env('E2E_TEST'))
? undefined
: {
members: {

View File

@ -1,4 +1,5 @@
import { createTransport } from 'nodemailer'
import { env } from 'utils'
export const sendEmailNotification = ({
to,
@ -19,7 +20,7 @@ export const sendEmailNotification = ({
})
return transporter.sendMail({
from: process.env.NEXT_PUBLIC_SMTP_FROM,
from: env('SMTP_FORM'),
to,
subject,
html: content,

View File

@ -2,7 +2,7 @@ import { DashboardFolder } from 'db'
import useSWR from 'swr'
import { fetcher } from './utils'
import { stringify } from 'qs'
import { isNotEmpty, sendRequest } from 'utils'
import { env, sendRequest } from 'utils'
export const useFolders = ({
parentId,
@ -18,9 +18,7 @@ export const useFolders = ({
workspaceId ? `/api/folders?${params}` : null,
fetcher,
{
dedupingInterval: isNotEmpty(process.env.NEXT_PUBLIC_E2E_TEST)
? 0
: undefined,
dedupingInterval: env('E2E_TEST') === 'enabled' ? 0 : undefined,
}
)
if (error) onError(error)

View File

@ -1,4 +1,4 @@
import { sendRequest } from 'utils'
import { env, sendRequest } from 'utils'
import { stringify } from 'qs'
import useSWR from 'swr'
import { fetcher } from './utils'
@ -78,7 +78,9 @@ export const executeWebhook = (
{ blockId }: { blockId: string }
) =>
sendRequest<WebhookResponse>({
url: `${process.env.NEXT_PUBLIC_VIEWER_URL}/api/typebots/${typebotId}/blocks/${blockId}/executeWebhook`,
url: `${env(
'VIEWER_URL'
)}/api/typebots/${typebotId}/blocks/${blockId}/executeWebhook`,
method: 'POST',
body: {
variables,

View File

@ -1,7 +1,6 @@
import { Plan, User } from 'db'
import { loadStripe } from '@stripe/stripe-js/pure'
import { isDefined, isEmpty, sendRequest } from 'utils'
import getConfig from 'next/config'
import { env, isDefined, isEmpty, sendRequest } from 'utils'
type Props = {
user: User
@ -40,10 +39,7 @@ const redirectToCheckout = async ({
plan,
workspaceId,
}: Omit<Props, 'customerId'>) => {
const {
publicRuntimeConfig: { NEXT_PUBLIC_STRIPE_PUBLIC_KEY },
} = getConfig()
if (isEmpty(NEXT_PUBLIC_STRIPE_PUBLIC_KEY))
if (isEmpty(env('STRIPE_PUBLIC_KEY')))
throw new Error('NEXT_PUBLIC_STRIPE_PUBLIC_KEY is missing in env')
const { data, error } = await sendRequest<{ sessionId: string }>({
method: 'POST',
@ -57,7 +53,7 @@ const redirectToCheckout = async ({
},
})
if (error || !data) return
const stripe = await loadStripe(NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
const stripe = await loadStripe(env('STRIPE_PUBLIC_KEY') as string)
await stripe?.redirectToCheckout({
sessionId: data?.sessionId,
})

View File

@ -1,7 +1,7 @@
import { CollaborationType, Invitation } from 'db'
import { fetcher } from 'services/utils'
import useSWR from 'swr'
import { isNotEmpty, sendRequest } from 'utils'
import { env, sendRequest } from 'utils'
export const useInvitations = ({
typebotId,
@ -14,9 +14,7 @@ export const useInvitations = ({
typebotId ? `/api/typebots/${typebotId}/invitations` : null,
fetcher,
{
dedupingInterval: isNotEmpty(process.env.NEXT_PUBLIC_E2E_TEST)
? 0
: undefined,
dedupingInterval: env('E2E_TEST') === 'enabled' ? 0 : undefined,
}
)
if (error) onError(error)

View File

@ -7,7 +7,7 @@ import {
import useSWRInfinite from 'swr/infinite'
import { stringify } from 'qs'
import { Answer } from 'db'
import { isDefined, isEmpty, sendRequest } from 'utils'
import { env, isDefined, sendRequest } from 'utils'
import { fetcher } from 'services/utils'
import { HStack, Text, Wrap, WrapItem } from '@chakra-ui/react'
import { CodeIcon, CalendarIcon, FileIcon } from 'assets/icons'
@ -54,9 +54,7 @@ export const useResults = ({
fetcher,
{
revalidateAll: true,
dedupingInterval: isEmpty(process.env.NEXT_PUBLIC_E2E_TEST)
? undefined
: 0,
dedupingInterval: env('E2E_TEST') === 'enabled' ? 0 : undefined,
}
)

View File

@ -46,13 +46,13 @@ import useSWR from 'swr'
import { fetcher, toKebabCase } from '../utils'
import {
isBubbleBlockType,
isNotEmpty,
isWebhookBlock,
omit,
blockHasItems,
blockTypeHasItems,
blockTypeHasOption,
blockTypeHasWebhook,
env,
} from 'utils'
import { dequal } from 'dequal'
import { stringify } from 'qs'
@ -83,9 +83,7 @@ export const useTypebots = ({
{ typebots: TypebotInDashboard[] },
Error
>(workspaceId ? `/api/typebots?${params}` : null, fetcher, {
dedupingInterval: isNotEmpty(process.env.NEXT_PUBLIC_E2E_TEST)
? 0
: undefined,
dedupingInterval: env('E2E_TEST') === 'enabled' ? 0 : undefined,
})
if (error) onError(error)
return {

View File

@ -1,7 +1,7 @@
import { ApiToken } from 'db'
import { fetcher } from 'services/utils'
import useSWR, { KeyedMutator } from 'swr'
import { isNotEmpty, sendRequest } from 'utils'
import { env, sendRequest } from 'utils'
export type ApiTokenFromServer = { id: string; name: string; createdAt: string }
@ -25,9 +25,7 @@ export const useApiTokens = ({
userId ? `/api/users/${userId}/api-tokens` : null,
fetcher,
{
dedupingInterval: isNotEmpty(process.env.NEXT_PUBLIC_E2E_TEST)
? 0
: undefined,
dedupingInterval: env('E2E_TEST') === 'enabled' ? 0 : undefined,
}
)
if (error) onError(error)

View File

@ -1,7 +1,7 @@
import { MemberInWorkspace, WorkspaceInvitation } from 'db'
import { fetcher } from 'services/utils'
import useSWR from 'swr'
import { isEmpty, sendRequest } from 'utils'
import { env, sendRequest } from 'utils'
export type Member = MemberInWorkspace & {
name: string | null
@ -14,7 +14,7 @@ export const useMembers = ({ workspaceId }: { workspaceId?: string }) => {
{ members: Member[]; invitations: WorkspaceInvitation[] },
Error
>(workspaceId ? `/api/workspaces/${workspaceId}/members` : null, fetcher, {
dedupingInterval: isEmpty(process.env.NEXT_PUBLIC_E2E_TEST) ? undefined : 0,
dedupingInterval: env('E2E_TEST') === 'enabled' ? 0 : undefined,
})
return {
members: data?.members,