All files client.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6

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              17x 19x 1x     18x 15x     18x      
import { start } from '@fingerprint/agent'
import type { Agent, GetOptions, GetResult, StartOptions } from '@fingerprint/agent'
import type { GetVisitorData } from './types'
 
export function makeGetVisitorData(startOptions: StartOptions): GetVisitorData {
  let agent: Agent | undefined
 
  return async (options?: GetOptions): Promise<GetResult> => {
    if (typeof window === 'undefined') {
      throw new Error('getVisitorData() can only be called in the browser.')
    }
 
    if (!agent) {
      agent = start(startOptions)
    }
 
    return agent.get(options)
  }
}