import * as url from "url" ; import { Url } from "url" ; import { Global } from "../core/global" ; export class URLMangler { public static mangle ( urlString , sourceID , secretKey ) { let urlValue = url . parse ( urlString , true , false ) ; return URLMangler . mangleJustPath ( urlValue . path , sourceID , secretKey ) ; } public static manglePipeToPath ( sourceID , secretKey ? ) { const secureParam = secretKey ? "?bespoken-key=" + secretKey : "" ; return `https://${ sourceID }.${ Global . SpokesPipeDomain }${ secureParam }` ; } public static mangleJustPath ( path , sourceID , secretKey ) { let newUrl = "https://" ; newUrl += Global . SpokesDashboardHost ; newUrl += path ; if ( path . indexOf ( "?" ) !== - 1 ) { newUrl += "&" ; } else { newUrl += "?" ; } newUrl += "id=" + sourceID ; newUrl += "&key=" + secretKey ; return newUrl ; } param sourceID returns { string } param secretKey returns { string } public static mangleNoPath ( sourceID , secretKey ) { let newUrl = "https://" ; newUrl += Global . SpokesDashboardHost ; newUrl += "?id=" + sourceID ; newUrl += "&key=" + secretKey ; return newUrl ; } }