All files / src/utils proxyEndpoint.ts

100% Statements 23/23
100% Branches 15/15
100% Functions 2/2
100% Lines 23/23

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 34 35 36 37 38 3912x   12x   12x 26x 26x   26x 26x 26x   26x     12x       51x 51x 51x   4x 4x   9x 9x   38x 38x   51x 51x 2x   51x    
import { config } from '../config'
 
export const DEFAULT_AGENT_VERSION = '3'
 
export function getAgentScriptEndpoint(searchParams: URLSearchParams): string {
  const apiKey = searchParams.get('apiKey')
  const apiVersion = searchParams.get('version') || DEFAULT_AGENT_VERSION
 
  const base = `https://${config.fpcdn}/v${apiVersion}/${apiKey}`
  const loaderVersion = searchParams.get('loaderVersion')
  const lv = loaderVersion ? `/loader_v${loaderVersion}.js` : ''
 
  return `${base}${lv}`
}
 
export function getVisitorIdEndpoint(
  searchParams: URLSearchParams,
  pathSuffix: string | undefined = undefined
): string {
  const region = searchParams.get('region') || 'us'
  let prefix = ''
  switch (region) {
    case 'eu':
      prefix = 'eu.'
      break
    case 'ap':
      prefix = 'ap.'
      break
    default:
      prefix = ''
      break
  }
  let suffix = pathSuffix ?? ''
  if (suffix.length > 0 && !suffix.startsWith('/')) {
    suffix = '/' + suffix
  }
  return `https://${prefix}${config.ingressApi}${suffix}`
}