Skip to content

Commit

Permalink
🐛 Fix legacy publicId format validation
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Aug 22, 2023
1 parent 83352d7 commit fe54888
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions apps/builder/src/features/publish/components/SharePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export const SharePage = () => {

if (!isCorrectlyFormatted) {
showToast({
description:
'Should contain only contain letters, numbers. Words can be separated by dashes.',
description: 'Can only contain lowercase letters, numbers and dashes.',
})
return false
}
Expand Down
10 changes: 9 additions & 1 deletion apps/builder/src/features/typebot/api/updateTypebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ export const updateTypebot = authenticatedProcedure
typebot.resultsTablePreferences === null
? Prisma.DbNull
: typebot.resultsTablePreferences,
publicId: typebot.publicId === null ? null : typebot.publicId,
publicId:
typebot.publicId === null
? null
: typebot.publicId && isPublicIdValid(typebot.publicId)
? typebot.publicId
: undefined,
customDomain:
typebot.customDomain === null ? null : typebot.customDomain,
isClosed: typebot.isClosed,
Expand All @@ -149,3 +154,6 @@ export const updateTypebot = authenticatedProcedure
return { typebot: typebotSchema.parse(newTypebot) }
}
)

const isPublicIdValid = (str: string) =>
/^([a-z0-9]+-[a-z0-9]*)*$/.test(str) || /^[a-z0-9]*$/.test(str)
7 changes: 6 additions & 1 deletion apps/builder/src/helpers/toKebabCase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { isNotEmpty } from '@typebot.io/lib'

export const toKebabCase = (value: string) => {
const matched = value.match(
/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g
)
if (!matched) return ''
return matched.map((x) => x.toLowerCase()).join('-')
return matched
.filter(isNotEmpty)
.map((x) => x.toLowerCase())
.join('-')
}
8 changes: 4 additions & 4 deletions packages/schemas/features/typebot/typebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ const resultsTablePreferencesSchema = z.object({
columnsWidth: z.record(z.string(), z.number()),
})

const isPathNameCompatible = (str: string) =>
/^([a-zA-Z0-9]+(-|.)[a-zA-z0-9]*)*$/.test(str) || /^[a-zA-Z0-9]*$/.test(str)

const isDomainNameWithPathNameCompatible = (str: string) =>
/^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?:\/[\w-\/]*)?)$/.test(
str
Expand All @@ -60,7 +57,10 @@ export const typebotSchema = z.object({
updatedAt: z.date(),
icon: z.string().nullable(),
folderId: z.string().nullable(),
publicId: z.string().refine(isPathNameCompatible).nullable(),
publicId: z
.string()
.refine((str) => /^[a-zA-Z0-9-.]+$/.test(str))
.nullable(),
customDomain: z
.string()
.refine(isDomainNameWithPathNameCompatible)
Expand Down

4 comments on commit fe54888

@vercel
Copy link

@vercel vercel bot commented on fe54888 Aug 22, 2023

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-git-main-typebot-io.vercel.app
docs.typebot.io
docs-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on fe54888 Aug 22, 2023

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

bii.bj
1stop.au
wasap.nl
x.cr8.ai
yobot.me
klujo.com
me.cr8.ai
wachat.io
wassep.io
247987.com
8jours.top
aginap.com
ai.mprs.in
bee.cr8.ai
bot.aws.bj
bot.bbc.bj
cat.cr8.ai
finplex.be
jxi.cr8.ai
nepkit.com
pig.cr8.ai
sat.cr8.ai
typebot.io
wachats.me
wsapio.com
zamrin.net
blogely.com
bot.aipr.kr
bot.kloo.me
broprio.com
bull.cr8.ai
docs.cr8.ai
getyour.sbs
icon.cr8.ai
minipost.uk
mole.cr8.ai
nurraysa.me
team.cr8.ai
wolf.cr8.ai
ai.meant.com
alphamen.pro
bet7k.online
bot.afric.ai
bot.grace.bj
cinecorn.com
ezbooking.ai
gniorder.com
help.taxt.co
kusamint.com
malayanboosterhq.com
menukb.wpwakanda.com
offer.botscientis.us
ore.barrettamario.it
sellmycarglasgow.com
stephanesampa.online
superglicemia.com.br
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
83701274.21000000.lol
viewer-v2-typebot-io.vercel.app
mdb.assessoria.desideri.progenbr.com
mdb.assessoria.fernanda.progenbr.com
mdb.assessoria.jbatista.progenbr.com
mdb.assessoria.mauricio.progenbr.com
mdb.evento.autocadastro.progenbr.com
form.shopmercedesbenzsouthorlando.com
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

@vercel
Copy link

@vercel vercel bot commented on fe54888 Aug 22, 2023

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

builder-v2-typebot-io.vercel.app
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on fe54888 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.