All files / src/utils proxyEndpoint.ts

100% Statements 19/19
100% Branches 11/11
100% Functions 2/2
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3414x     28x 28x   28x 28x 28x   28x       150x 1x     149x 149x 149x   7x 7x   12x 12x   130x 130x   149x    
export const DEFAULT_AGENT_VERSION = '3'
 
export function getAgentScriptEndpoint(baseCdnUrl: string, searchParams: URLSearchParams): string {
  const apiKey = searchParams.get('apiKey')
  const apiVersion = searchParams.get('version') || DEFAULT_AGENT_VERSION
 
  const base = `https://${baseCdnUrl}/web/v${apiVersion}/${apiKey}`
  const loaderVersion = searchParams.get('loaderVersion')
  const lv = loaderVersion ? `/loader_v${loaderVersion}.js` : ''
 
  return `${base}${lv}`
}
 
export function getIngressEndpoint(baseIngressUrl: string, searchParams: URLSearchParams, targetPath: string): string {
  if (!targetPath.startsWith('/')) {
    throw new Error('targetPath must start with /')
  }
 
  const region = searchParams.get('region') || 'us'
  let prefix = ''
  switch (region) {
    case 'eu':
      prefix = 'eu.'
      break
    case 'ap':
      prefix = 'ap.'
      break
    default:
      prefix = ''
      break
  }
  return `https://${prefix}${baseIngressUrl}${targetPath}`
}