🐛 Fix api doc CORS
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
"minio": "7.0.32",
|
"minio": "7.0.32",
|
||||||
"next": "13.0.5",
|
"next": "13.0.5",
|
||||||
"next-auth": "4.12.3",
|
"next-auth": "4.12.3",
|
||||||
|
"nextjs-cors": "^2.1.2",
|
||||||
"nodemailer": "6.8.0",
|
"nodemailer": "6.8.0",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
"papaparse": "5.3.2",
|
"papaparse": "5.3.2",
|
||||||
@@ -109,14 +110,14 @@
|
|||||||
"@types/tinycolor2": "1.4.3",
|
"@types/tinycolor2": "1.4.3",
|
||||||
"db": "workspace:*",
|
"db": "workspace:*",
|
||||||
"dotenv": "16.0.3",
|
"dotenv": "16.0.3",
|
||||||
|
"eslint": "8.28.0",
|
||||||
|
"eslint-config-custom": "workspace:*",
|
||||||
"models": "workspace:*",
|
"models": "workspace:*",
|
||||||
"next-transpile-modules": "10.0.0",
|
"next-transpile-modules": "10.0.0",
|
||||||
"superjson": "^1.11.0",
|
"superjson": "^1.11.0",
|
||||||
"tsconfig": "workspace:*",
|
"tsconfig": "workspace:*",
|
||||||
"typescript": "4.9.3",
|
"typescript": "4.9.3",
|
||||||
"utils": "workspace:*",
|
"utils": "workspace:*",
|
||||||
"zod": "3.19.1",
|
"zod": "3.19.1"
|
||||||
"eslint": "8.28.0",
|
|
||||||
"eslint-config-custom": "workspace:*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const createWorkspaceProcedure = authenticatedProcedure
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: { name: true },
|
select: { name: true },
|
||||||
})) satisfies Pick<Workspace, 'name'>[]
|
})) as Pick<Workspace, 'name'>[]
|
||||||
|
|
||||||
if (existingWorkspaceNames.some((workspace) => workspace.name === name))
|
if (existingWorkspaceNames.some((workspace) => workspace.name === name))
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -48,7 +48,7 @@ export const createWorkspaceProcedure = authenticatedProcedure
|
|||||||
members: { create: [{ role: 'ADMIN', userId: user.id }] },
|
members: { create: [{ role: 'ADMIN', userId: user.id }] },
|
||||||
plan,
|
plan,
|
||||||
},
|
},
|
||||||
})) satisfies Workspace
|
})) as Workspace
|
||||||
|
|
||||||
return {
|
return {
|
||||||
workspace: newWorkspace,
|
workspace: newWorkspace,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const getWorkspaceProcedure = authenticatedProcedure
|
|||||||
.query(async ({ input: { workspaceId }, ctx: { user } }) => {
|
.query(async ({ input: { workspaceId }, ctx: { user } }) => {
|
||||||
const workspace = (await prisma.workspace.findFirst({
|
const workspace = (await prisma.workspace.findFirst({
|
||||||
where: { members: { some: { userId: user.id } }, id: workspaceId },
|
where: { members: { some: { userId: user.id } }, id: workspaceId },
|
||||||
})) satisfies Workspace | null
|
})) as Workspace | null
|
||||||
|
|
||||||
if (!workspace)
|
if (!workspace)
|
||||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' })
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' })
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const listInvitationsInWorkspaceProcedure = authenticatedProcedure
|
|||||||
workspace: { members: { some: { userId: user.id } } },
|
workspace: { members: { some: { userId: user.id } } },
|
||||||
},
|
},
|
||||||
select: { createdAt: true, email: true, type: true },
|
select: { createdAt: true, email: true, type: true },
|
||||||
})) satisfies WorkspaceInvitation[]
|
})) as WorkspaceInvitation[]
|
||||||
|
|
||||||
if (!invitations)
|
if (!invitations)
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const listMembersInWorkspaceProcedure = authenticatedProcedure
|
|||||||
const members = (await prisma.memberInWorkspace.findMany({
|
const members = (await prisma.memberInWorkspace.findMany({
|
||||||
where: { userId: user.id, workspaceId },
|
where: { userId: user.id, workspaceId },
|
||||||
include: { user: { select: { name: true, email: true, image: true } } },
|
include: { user: { select: { name: true, email: true, image: true } } },
|
||||||
})) satisfies WorkspaceMember[]
|
})) as WorkspaceMember[]
|
||||||
|
|
||||||
if (!members)
|
if (!members)
|
||||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No members found' })
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'No members found' })
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const listWorkspacesProcedure = authenticatedProcedure
|
|||||||
const workspaces = (await prisma.workspace.findMany({
|
const workspaces = (await prisma.workspace.findMany({
|
||||||
where: { members: { some: { userId: user.id } } },
|
where: { members: { some: { userId: user.id } } },
|
||||||
select: { name: true, id: true, icon: true, plan: true },
|
select: { name: true, id: true, icon: true, plan: true },
|
||||||
})) satisfies Pick<Workspace, 'id' | 'name' | 'icon' | 'plan'>[]
|
})) as Pick<Workspace, 'id' | 'name' | 'icon' | 'plan'>[]
|
||||||
|
|
||||||
if (!workspaces)
|
if (!workspaces)
|
||||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' })
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' })
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const updateWorkspaceProcedure = authenticatedProcedure
|
|||||||
|
|
||||||
const workspace = (await prisma.workspace.findFirst({
|
const workspace = (await prisma.workspace.findFirst({
|
||||||
where: { members: { some: { userId: user.id } }, id: workspaceId },
|
where: { members: { some: { userId: user.id } }, id: workspaceId },
|
||||||
})) satisfies Workspace | null
|
})) as Workspace | null
|
||||||
|
|
||||||
if (!workspace)
|
if (!workspace)
|
||||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Workspace not found' })
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'Workspace not found' })
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ const prismaGlobal = global as typeof global & {
|
|||||||
const prisma: PrismaClient =
|
const prisma: PrismaClient =
|
||||||
prismaGlobal.prisma ||
|
prismaGlobal.prisma ||
|
||||||
new PrismaClient({
|
new PrismaClient({
|
||||||
log:
|
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
||||||
process.env.NODE_ENV === 'development'
|
|
||||||
? ['query', 'error', 'warn']
|
|
||||||
: ['error'],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import { createContext } from '@/utils/server/context'
|
import { createContext } from '@/utils/server/context'
|
||||||
import { trpcRouter } from '@/utils/server/routers/v1/trpcRouter'
|
import { trpcRouter } from '@/utils/server/routers/v1/trpcRouter'
|
||||||
import { captureException } from '@sentry/nextjs'
|
import { captureException } from '@sentry/nextjs'
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { createOpenApiNextHandler } from 'trpc-openapi'
|
import { createOpenApiNextHandler } from 'trpc-openapi'
|
||||||
|
import cors from 'nextjs-cors'
|
||||||
|
|
||||||
export default createOpenApiNextHandler({
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
await cors(req, res, {
|
||||||
|
origin: 'https://docs.typebot.io',
|
||||||
|
})
|
||||||
|
|
||||||
|
return createOpenApiNextHandler({
|
||||||
router: trpcRouter,
|
router: trpcRouter,
|
||||||
createContext,
|
createContext,
|
||||||
onError({ error }) {
|
onError({ error }) {
|
||||||
@@ -12,4 +19,6 @@ export default createOpenApiNextHandler({
|
|||||||
console.error('Something went wrong', error)
|
console.error('Something went wrong', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})(req, res)
|
||||||
|
}
|
||||||
|
export default handler
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sentry/nextjs": "7.21.1",
|
"@sentry/nextjs": "7.21.1",
|
||||||
|
"@trpc/server": "10.3.0",
|
||||||
"aws-sdk": "2.1261.0",
|
"aws-sdk": "2.1261.0",
|
||||||
"bot-engine": "workspace:*",
|
"bot-engine": "workspace:*",
|
||||||
"cors": "2.8.5",
|
"cors": "2.8.5",
|
||||||
@@ -21,14 +22,14 @@
|
|||||||
"google-spreadsheet": "3.3.0",
|
"google-spreadsheet": "3.3.0",
|
||||||
"got": "12.5.3",
|
"got": "12.5.3",
|
||||||
"next": "13.0.5",
|
"next": "13.0.5",
|
||||||
|
"nextjs-cors": "^2.1.2",
|
||||||
"nodemailer": "6.8.0",
|
"nodemailer": "6.8.0",
|
||||||
"qs": "6.11.0",
|
"qs": "6.11.0",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"sanitize-html": "2.7.3",
|
"sanitize-html": "2.7.3",
|
||||||
"stripe": "11.1.0",
|
"stripe": "11.1.0",
|
||||||
"trpc-openapi": "1.0.0-alpha.4",
|
"trpc-openapi": "1.0.0-alpha.4"
|
||||||
"@trpc/server": "10.3.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "7.20.2",
|
"@babel/preset-env": "7.20.2",
|
||||||
@@ -51,10 +52,10 @@
|
|||||||
"next-transpile-modules": "10.0.0",
|
"next-transpile-modules": "10.0.0",
|
||||||
"node-fetch": "^3.3.0",
|
"node-fetch": "^3.3.0",
|
||||||
"papaparse": "5.3.2",
|
"papaparse": "5.3.2",
|
||||||
|
"superjson": "^1.11.0",
|
||||||
"tsconfig": "workspace:*",
|
"tsconfig": "workspace:*",
|
||||||
"typescript": "4.9.3",
|
"typescript": "4.9.3",
|
||||||
"zod": "3.19.1",
|
"utils": "workspace:*",
|
||||||
"superjson": "^1.11.0",
|
"zod": "3.19.1"
|
||||||
"utils": "workspace:*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { appRouter } from '@/utils/server/routers/v1/_app'
|
import { appRouter } from '@/utils/server/routers/v1/_app'
|
||||||
import { captureException } from '@sentry/nextjs'
|
import { captureException } from '@sentry/nextjs'
|
||||||
import { createOpenApiNextHandler } from 'trpc-openapi'
|
import { createOpenApiNextHandler } from 'trpc-openapi'
|
||||||
|
import cors from 'nextjs-cors'
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
|
|
||||||
export default createOpenApiNextHandler({
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
await cors(req, res, {
|
||||||
|
origin: 'https://docs.typebot.io',
|
||||||
|
})
|
||||||
|
|
||||||
|
return createOpenApiNextHandler({
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
onError({ error }) {
|
onError({ error }) {
|
||||||
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
||||||
@@ -10,4 +17,6 @@ export default createOpenApiNextHandler({
|
|||||||
console.error('Something went wrong', error)
|
console.error('Something went wrong', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})(req, res)
|
||||||
|
}
|
||||||
|
export default handler
|
||||||
|
|||||||
13
pnpm-lock.yaml
generated
13
pnpm-lock.yaml
generated
@@ -94,6 +94,7 @@ importers:
|
|||||||
next: 13.0.5
|
next: 13.0.5
|
||||||
next-auth: 4.12.3
|
next-auth: 4.12.3
|
||||||
next-transpile-modules: 10.0.0
|
next-transpile-modules: 10.0.0
|
||||||
|
nextjs-cors: ^2.1.2
|
||||||
nodemailer: 6.8.0
|
nodemailer: 6.8.0
|
||||||
nprogress: 0.2.0
|
nprogress: 0.2.0
|
||||||
papaparse: 5.3.2
|
papaparse: 5.3.2
|
||||||
@@ -177,6 +178,7 @@ importers:
|
|||||||
minio: 7.0.32
|
minio: 7.0.32
|
||||||
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
||||||
next-auth: 4.12.3_2xoejpawkzgot77rbv5mbik6ve
|
next-auth: 4.12.3_2xoejpawkzgot77rbv5mbik6ve
|
||||||
|
nextjs-cors: 2.1.2_next@13.0.5
|
||||||
nodemailer: 6.8.0
|
nodemailer: 6.8.0
|
||||||
nprogress: 0.2.0
|
nprogress: 0.2.0
|
||||||
papaparse: 5.3.2
|
papaparse: 5.3.2
|
||||||
@@ -363,6 +365,7 @@ importers:
|
|||||||
models: workspace:*
|
models: workspace:*
|
||||||
next: 13.0.5
|
next: 13.0.5
|
||||||
next-transpile-modules: 10.0.0
|
next-transpile-modules: 10.0.0
|
||||||
|
nextjs-cors: ^2.1.2
|
||||||
node-fetch: ^3.3.0
|
node-fetch: ^3.3.0
|
||||||
nodemailer: 6.8.0
|
nodemailer: 6.8.0
|
||||||
papaparse: 5.3.2
|
papaparse: 5.3.2
|
||||||
@@ -388,6 +391,7 @@ importers:
|
|||||||
google-spreadsheet: 3.3.0
|
google-spreadsheet: 3.3.0
|
||||||
got: 12.5.3
|
got: 12.5.3
|
||||||
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
||||||
|
nextjs-cors: 2.1.2_next@13.0.5
|
||||||
nodemailer: 6.8.0
|
nodemailer: 6.8.0
|
||||||
qs: 6.11.0
|
qs: 6.11.0
|
||||||
react: 18.2.0
|
react: 18.2.0
|
||||||
@@ -13924,6 +13928,15 @@ packages:
|
|||||||
- babel-plugin-macros
|
- babel-plugin-macros
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/nextjs-cors/2.1.2_next@13.0.5:
|
||||||
|
resolution: {integrity: sha512-2yOVivaaf2ILe4f/qY32hnj3oC77VCOsUQJQfhVMGsXE/YMEWUY2zy78sH9FKUCM7eG42/l3pDofIzMD781XGA==}
|
||||||
|
peerDependencies:
|
||||||
|
next: ^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0
|
||||||
|
dependencies:
|
||||||
|
cors: 2.8.5
|
||||||
|
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
||||||
|
dev: false
|
||||||
|
|
||||||
/no-case/2.3.2:
|
/no-case/2.3.2:
|
||||||
resolution: {integrity: sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==}
|
resolution: {integrity: sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user