-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ (customDomains) Fix custom domain update feedback
- Loading branch information
1 parent
dc4c19a
commit c08e0cd
Showing
19 changed files
with
506 additions
and
104 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
apps/builder/src/features/customDomains/api/createCustomDomain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import prisma from '@/lib/prisma' | ||
import { authenticatedProcedure } from '@/helpers/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { z } from 'zod' | ||
import { customDomainSchema } from '@typebot.io/schemas/features/customDomains' | ||
import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden copy' | ||
import got, { HTTPError } from 'got' | ||
|
||
export const createCustomDomain = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'POST', | ||
path: '/custom-domains', | ||
protect: true, | ||
summary: 'Create custom domain', | ||
tags: ['Custom domains'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
workspaceId: z.string(), | ||
name: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
customDomain: customDomainSchema.pick({ | ||
name: true, | ||
createdAt: true, | ||
}), | ||
}) | ||
) | ||
.mutation(async ({ input: { workspaceId, name }, ctx: { user } }) => { | ||
const workspace = await prisma.workspace.findFirst({ | ||
where: { id: workspaceId }, | ||
select: { | ||
members: { | ||
select: { | ||
userId: true, | ||
role: true, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
if (!workspace || isWriteWorkspaceForbidden(workspace, user)) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' }) | ||
|
||
const existingCustomDomain = await prisma.customDomain.findFirst({ | ||
where: { name }, | ||
}) | ||
|
||
if (existingCustomDomain) | ||
throw new TRPCError({ | ||
code: 'CONFLICT', | ||
message: 'Custom domain already registered', | ||
}) | ||
|
||
try { | ||
await createDomainOnVercel(name) | ||
} catch (err) { | ||
console.log(err) | ||
if (err instanceof HTTPError && err.response.statusCode !== 409) | ||
throw new TRPCError({ | ||
code: 'INTERNAL_SERVER_ERROR', | ||
message: 'Failed to create custom domain on Vercel', | ||
}) | ||
} | ||
|
||
const customDomain = await prisma.customDomain.create({ | ||
data: { | ||
name, | ||
workspaceId, | ||
}, | ||
}) | ||
|
||
return { customDomain } | ||
}) | ||
|
||
const createDomainOnVercel = (name: string) => | ||
got.post({ | ||
url: `https://api.vercel.com/v10/projects/${process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME}/domains?teamId=${process.env.VERCEL_TEAM_ID}`, | ||
headers: { Authorization: `Bearer ${process.env.VERCEL_TOKEN}` }, | ||
json: { name }, | ||
}) |
68 changes: 68 additions & 0 deletions
68
apps/builder/src/features/customDomains/api/deleteCustomDomain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import prisma from '@/lib/prisma' | ||
import { authenticatedProcedure } from '@/helpers/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { z } from 'zod' | ||
import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden copy' | ||
import got from 'got' | ||
|
||
export const deleteCustomDomain = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'DELETE', | ||
path: '/custom-domains', | ||
protect: true, | ||
summary: 'Delete custom domain', | ||
tags: ['Custom domains'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
workspaceId: z.string(), | ||
name: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
message: z.literal('success'), | ||
}) | ||
) | ||
.mutation(async ({ input: { workspaceId, name }, ctx: { user } }) => { | ||
const workspace = await prisma.workspace.findFirst({ | ||
where: { id: workspaceId }, | ||
select: { | ||
members: { | ||
select: { | ||
userId: true, | ||
role: true, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
if (!workspace || isWriteWorkspaceForbidden(workspace, user)) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' }) | ||
|
||
try { | ||
await deleteDomainOnVercel(name) | ||
} catch (error) { | ||
console.error(error) | ||
throw new TRPCError({ | ||
code: 'INTERNAL_SERVER_ERROR', | ||
message: 'Failed to delete domain on Vercel', | ||
}) | ||
} | ||
await prisma.customDomain.deleteMany({ | ||
where: { | ||
name, | ||
workspaceId, | ||
}, | ||
}) | ||
|
||
return { message: 'success' } | ||
}) | ||
|
||
const deleteDomainOnVercel = (name: string) => | ||
got.delete({ | ||
url: `https://api.vercel.com/v9/projects/${process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME}/domains/${name}?teamId=${process.env.VERCEL_TEAM_ID}`, | ||
headers: { Authorization: `Bearer ${process.env.VERCEL_TOKEN}` }, | ||
}) |
54 changes: 54 additions & 0 deletions
54
apps/builder/src/features/customDomains/api/listCustomDomains.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import prisma from '@/lib/prisma' | ||
import { authenticatedProcedure } from '@/helpers/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { z } from 'zod' | ||
import { isReadWorkspaceFobidden } from '@/features/workspace/helpers/isReadWorkspaceFobidden' | ||
import { customDomainSchema } from '@typebot.io/schemas/features/customDomains' | ||
|
||
export const listCustomDomains = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'GET', | ||
path: '/custom-domains', | ||
protect: true, | ||
summary: 'List custom domains', | ||
tags: ['Custom domains'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
workspaceId: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
customDomains: z.array( | ||
customDomainSchema.pick({ | ||
name: true, | ||
createdAt: true, | ||
}) | ||
), | ||
}) | ||
) | ||
.query(async ({ input: { workspaceId }, ctx: { user } }) => { | ||
const workspace = await prisma.workspace.findFirst({ | ||
where: { id: workspaceId }, | ||
select: { | ||
members: { | ||
select: { | ||
userId: true, | ||
}, | ||
}, | ||
customDomains: true, | ||
}, | ||
}) | ||
|
||
if (!workspace || isReadWorkspaceFobidden(workspace, user)) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' }) | ||
|
||
const descSortedCustomDomains = workspace.customDomains.sort( | ||
(a, b) => b.createdAt.getTime() - a.createdAt.getTime() | ||
) | ||
|
||
return { customDomains: descSortedCustomDomains } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { router } from '@/helpers/server/trpc' | ||
import { createCustomDomain } from './createCustomDomain' | ||
import { deleteCustomDomain } from './deleteCustomDomain' | ||
import { listCustomDomains } from './listCustomDomains' | ||
|
||
export const customDomainsRouter = router({ | ||
createCustomDomain, | ||
deleteCustomDomain, | ||
listCustomDomains, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c08e0cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viewer-v2 – ./apps/viewer
gsbulletin.com
journey.cr8.ai
kopibayane.com
panther.cr7.ai
panther.cr8.ai
pay.sifuim.com
penguin.cr8.ai
segredomeu.com
talk.gocare.io
test.bot.gives
ticketfute.com
unicorn.cr8.ai
whats-app.chat
apo.nigerias.io
app.blogely.com
apr.nigerias.io
aso.nigerias.io
blackcan.cr8.ai
blackvip.online
bot.4display.nl
bot.a6t-you.com
bot.artiweb.app
bot.devitus.com
bot.reeplai.com
bot.scayver.com
bot.tc-mail.com
carspecs.lam.ee
chat.lalmon.com
chat.sureb4.com
conversawpp.com
eventhub.com.au
feiraododia.com
fitness.riku.ai
games.klujo.com
localove.online
proscale.com.br
sellmycarbr.com
svhmapp.mprs.in
typebot.aloe.do
app-liberado.pro
ask.pemantau.org
batepapo.digital
bot.contakit.com
bot.imovfast.com
bot.piccinato.co
botc.ceox.com.br
chat.sifucrm.com
chat.syncwin.com
chatonlineja.com
clo.closeer.work
desafioem21d.com
faqs.nigerias.io
revistasaudeemdia.com
rossano.thegymgame.it
sbutton.wpwakanda.com
segredosdothreads.com
talk.convobuilder.com
terrosdoscassinos.com
test.leadbooster.help
whats.laracardoso.com
www.acesso-app.online
www.hemertonsilva.com
zillabot.saaszilla.co
815639944.21000000.one
83720273.bouclidom.com
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bolsamaisbrasil.app.br
bot.chat-debora.online
bot.clubedotrader.club
bot.louismarcondes.com
bot.perfaceacademy.com
bot.pratikmandalia.com
bot.sucessodigital.xyz
bot.t20worldcup.com.au
bot.whatsappweb.adm.br
bot2.mycompany.reviews
bot3.mycompany.reviews
bot4.mycompany.reviews
c23111azqw.nigerias.io
chat.footballmeetup.ie
conto.barrettamario.it
dieta.barrettamario.it
felipewelington.com.br
form.bridesquadapp.com
form.searchcube.com.sg
go.orodrigoribeiro.com
help.giversforgood.com
info.clickasuransi.com
jenifferrodrigues.club
kodawariab736.skeep.it
mdb.diego.progenbr.com
michaeljackson.riku.ai
premium.kandabrand.com
psicologiacognitiva.co
report.gratirabbit.com
resume.gratirabbit.com
suporte.pedroallan.com
teambuilding.hidden.sg
c08e0cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
landing-page-v2 – ./apps/landing-page
landing-page-v2-typebot-io.vercel.app
www.get-typebot.com
www.typebot.io
home.typebot.io
landing-page-v2-git-main-typebot-io.vercel.app
get-typebot.com
c08e0cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder-v2 – ./apps/builder
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
c08e0cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./apps/docs
docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app