const odspTenants = new Map < string , string > ( [ [ "spo" , "microsoft-my.sharepoint.com" ] , [ "spo-df" , "microsoft-my.sharepoint-df.com" ] , ] ) ; export function isOdspHostname ( server ) { return server . endsWith ( "sharepoint.com" ) || server . endsWith ( "sharepoint-df.com" ) ; } export function isPushChannelHostname ( server ) { return server . includes ( ".push" ) && server . endsWith ( ".svc.ms" ) ; } export function getAadUrl ( server ) { if ( server === "localhost" || server . startsWith ( "localhost:" ) ) { return `http://${ server }` ; } if ( isPushChannelHostname ( server ) ) { return getSiteUrl ( server ) ; } return `https://login.microsoftonline.com` ; } export function getAadTenant ( server ) { let hostname = server ; if ( hostname . startsWith ( "http://" ) ) { hostname = hostname . substring ( 7 ) ; } else if ( hostname . startsWith ( "https://" ) ) { hostname = hostname . substring ( 8 ) ; } let tenantName = hostname . substr ( 0 , hostname . indexOf ( "." ) ) . toLowerCase ( ) ; let restOfTenantHostname = hostname . substr ( tenantName . length ) . toLowerCase ( ) ; if ( tenantName . endsWith ( "-my" ) ) { tenantName = tenantName . substr ( 0 , tenantName . length - 3 ) ; } else if ( tenantName . endsWith ( "-admin" ) ) { tenantName = tenantName . substr ( 0 , tenantName . length - 6 ) ; } if ( restOfTenantHostname . indexOf ( ".sharepoint." ) === 0 ) { restOfTenantHostname = `.onmicrosoft.${ restOfTenantHostname . substr ( 12 ) }` ; } if ( restOfTenantHostname . indexOf ( ".sharepoint-df." ) === 0 ) { restOfTenantHostname = `.onmicrosoft.${ restOfTenantHostname . substr ( 15 ) }` ; } return `${ tenantName }${ restOfTenantHostname }` ; } export function getServer ( tenantId ) { const server = odspTenants . get ( tenantId ) ; if ( ! server ) { throw Error ( `Invalid SPO tenantId ${ tenantId }.` ) ; } return server ; } export function getSiteUrl ( server ) { if ( server . startsWith ( "http://" ) || server . startsWith ( "https://" ) ) { return server ; } return `https://${ server }` ; }