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'
|
2025-06-07 17:36:20 +00:00
|
|
|
import { namespaceBlacklist } from './namespace-blacklist'
|
2025-06-05 16:00:07 +00:00
|
|
|
import { parseDeploymentIdentifier } from './parse-deployment-identifier'
|
|
|
|
import { parseProjectIdentifier } from './parse-project-identifier'
|
2025-06-13 19:31:20 +00:00
|
|
|
import { toolNameBlacklist } from './tool-name-blacklist'
|
2025-06-05 16:00:07 +00:00
|
|
|
|
|
|
|
export const namespaceRe = /^[a-z0-9-]{1,256}$/
|
2025-04-24 21:54:33 +00:00
|
|
|
export const passwordRe = /^.{3,1024}$/
|
|
|
|
|
2025-06-26 04:01:38 +00:00
|
|
|
export const projectSlugRe = /^[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)
|
|
|
|
}
|
|
|
|
|
2025-06-07 17:36:20 +00:00
|
|
|
export function isNamespaceAllowed(value?: string): boolean {
|
|
|
|
return !!value && isValidNamespace(value) && !namespaceBlacklist.has(value)
|
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
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-26 04:01:38 +00:00
|
|
|
export function isValidProjectSlug(value?: string): boolean {
|
|
|
|
return !!value && projectSlugRe.test(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2025-06-09 11:17:34 +00:00
|
|
|
try {
|
|
|
|
return !!parseProjectIdentifier(value, opts)
|
|
|
|
} catch {
|
|
|
|
return false
|
|
|
|
}
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-06-05 16:00:07 +00:00
|
|
|
export function isValidDeploymentIdentifier(
|
|
|
|
value?: string,
|
|
|
|
opts?: ParseIdentifierOptions
|
|
|
|
): boolean {
|
2025-06-09 11:17:34 +00:00
|
|
|
try {
|
|
|
|
return !!parseDeploymentIdentifier(value, opts)
|
|
|
|
} catch {
|
|
|
|
return false
|
|
|
|
}
|
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-13 19:31:20 +00:00
|
|
|
export function isToolNameAllowed(value?: string): boolean {
|
|
|
|
return !!value && isValidToolName(value) && !toolNameBlacklist.has(value)
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|