2025-04-25 23:11:33 +00:00
|
|
|
import { isCuid } from '@paralleldrive/cuid2'
|
2025-04-24 21:54:33 +00:00
|
|
|
import emailValidator from 'email-validator'
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
import type { ParseIdentifierOptions } from './types'
|
|
|
|
import { parseDeploymentIdentifier } from './parse-deployment-identifier'
|
|
|
|
import { parseProjectIdentifier } from './parse-project-identifier'
|
|
|
|
|
|
|
|
export const namespaceRe = /^[a-z0-9-]{1,256}$/
|
2025-04-24 21:54:33 +00:00
|
|
|
export const passwordRe = /^.{3,1024}$/
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export const projectNameRe = /^[a-z0-9-]{1,256}$/
|
2025-04-24 21:54:33 +00:00
|
|
|
export const deploymentHashRe = /^[a-z0-9]{8}$/
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export const toolNameRe = /^[a-zA-Z_][a-zA-Z0-9_]{0,63}$/
|
2025-04-24 21:54:33 +00:00
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidEmail(value: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return emailValidator.validate(value)
|
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidNamespace(value?: string): boolean {
|
|
|
|
return !!value && namespaceRe.test(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isValidUsername(value?: string): boolean {
|
|
|
|
return isValidNamespace(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidTeamSlug(value?: string): boolean {
|
|
|
|
return isValidNamespace(value)
|
2025-04-29 11:56:28 +00:00
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidPassword(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && passwordRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidProjectName(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && projectNameRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidDeploymentHash(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && deploymentHashRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidProjectIdentifier(
|
|
|
|
value?: string,
|
|
|
|
opts?: ParseIdentifierOptions
|
|
|
|
): boolean {
|
|
|
|
return !!parseProjectIdentifier(value, opts)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidDeploymentIdentifier(
|
|
|
|
value?: string,
|
|
|
|
opts?: ParseIdentifierOptions
|
|
|
|
): boolean {
|
|
|
|
return !!parseDeploymentIdentifier(value, opts)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidToolName(value?: string): boolean {
|
2025-05-28 19:03:42 +00:00
|
|
|
return !!value && toolNameRe.test(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidCuid(value?: string): boolean {
|
2025-04-25 23:11:33 +00:00
|
|
|
return !!value && isCuid(value)
|
|
|
|
}
|