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'
|
|
|
|
import isRelativeUrl from 'is-relative-url'
|
|
|
|
|
|
|
|
export const usernameRe = /^[a-zA-Z0-9-]{1,64}$/
|
|
|
|
export const passwordRe = /^.{3,1024}$/
|
|
|
|
|
2025-05-25 16:02:13 +00:00
|
|
|
export const projectNameRe = /^[a-z0-9-]{2,64}$/
|
2025-04-24 21:54:33 +00:00
|
|
|
export const deploymentHashRe = /^[a-z0-9]{8}$/
|
|
|
|
|
2025-06-03 12:46:02 +00:00
|
|
|
export const projectIdentifierRe = /^[a-zA-Z0-9-]{1,64}\/[a-z0-9-]{3,64}$/
|
|
|
|
export const deploymentIdentifierRe =
|
|
|
|
/^[a-zA-Z0-9-]{1,64}\/[a-z0-9-]{3,64}@[a-z0-9]{8}$/
|
2025-04-24 21:54:33 +00:00
|
|
|
|
2025-05-28 19:03:42 +00:00
|
|
|
// tool names may be any valid JavaScript identifier
|
|
|
|
// TODO: should tool names be any label?
|
|
|
|
export const toolNameRe = /^[a-zA-Z_][a-zA-Z0-9_]*$/
|
|
|
|
export const toolPathRe = /^\/[a-zA-Z0-9\-._~%!$&'()*+,;=:/]*$/
|
2025-04-24 21:54:33 +00:00
|
|
|
|
|
|
|
export function email(value: string): boolean {
|
|
|
|
return emailValidator.validate(value)
|
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function username(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && usernameRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function team(value?: string): boolean {
|
2025-04-29 11:56:28 +00:00
|
|
|
return username(value)
|
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function password(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && passwordRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function projectName(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && projectNameRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function deploymentHash(value?: string): boolean {
|
2025-04-24 21:54:33 +00:00
|
|
|
return !!value && deploymentHashRe.test(value)
|
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function projectIdentifier(value?: string): boolean {
|
2025-06-03 12:46:02 +00:00
|
|
|
return !!value && projectIdentifierRe.test(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function deploymentIdentifier(value?: string): boolean {
|
2025-06-03 12:46:02 +00:00
|
|
|
return !!value && deploymentIdentifierRe.test(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-05-28 19:03:42 +00:00
|
|
|
export function toolName(value?: string): boolean {
|
|
|
|
return !!value && toolNameRe.test(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2025-05-28 19:03:42 +00:00
|
|
|
export function toolPath(value?: string): boolean {
|
|
|
|
return !!value && toolPathRe.test(value) && isRelativeUrl(value)
|
2025-04-24 21:54:33 +00:00
|
|
|
}
|
2025-04-25 23:11:33 +00:00
|
|
|
|
2025-05-20 10:02:55 +00:00
|
|
|
export function cuid(value?: string): boolean {
|
2025-04-25 23:11:33 +00:00
|
|
|
return !!value && isCuid(value)
|
|
|
|
}
|