import { isAbsolute , normalize } from "path" ; import isFQDN from "validator/lib/isFQDN" ; import { EntrypointUrlMatcherNotValidError } from "../common/errors" ; import { IConfiguration } from "./Configuration" ; export interface IEntrypoint { id : string ; appId : string ; bundleId : string | null ; redirectTo : string | null ; urlMatcher : string ; configuration : IConfiguration | null ; createdAt : Date ; updatedAt : Date ; } export function isEntrypointUrlMatcherValid ( urlMatcher ) { const indexOfFirstSlash = urlMatcher . indexOf ( "/" ) ; if ( indexOfFirstSlash === - 1 ) { return false ; } const domain = urlMatcher . slice ( 0 , indexOfFirstSlash ) ; const path = urlMatcher . slice ( indexOfFirstSlash ) ; return ( isFQDN ( domain , { allow_trailing_dot : false } ) && isAbsolute ( path ) && normalize ( path ) === path && /\/$/ . test ( path ) ) ; } export function validateEntrypointUrlMatcher ( urlMatcher ) { if ( ! isEntrypointUrlMatcherValid ( urlMatcher ) ) { throw new EntrypointUrlMatcherNotValidError ( urlMatcher ) ; } }