import { ValidationError } from "../ValidationError.js"; import { Mechanism } from "./Mechanism.js"; export class DomainMechanism extends Mechanism { separator = ":"; constructor(key) { super(key); } validate(value) { // https://www.rfc-editor.org/rfc/rfc7208#section-7.1 const valid = value .split(".") .every(segment => segment.match(/^([^%]|%_|%%|%-|%\{[slodiphcrtv]\d*r?[-.+,\/_=]*})+$/)); if (!valid) throw new ValidationError(`Value for "${this.key}" is not a valid domain name`); return true; } }