All files client.ts

87.5% Statements 7/8
0% Branches 0/1
100% Functions 2/2
87.5% Lines 7/8

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                  4x   4x       4x       4x   4x     4x   4x          
import type { FpjsClient, GetOptions } from '@fingerprintjs/fingerprintjs-pro-spa'
import type { ClearCache, GetVisitorData } from './types'
 
interface ClientMethods {
  clearCache: ClearCache
  getVisitorData: GetVisitorData
}
 
export function makeClientMethods(client: FpjsClient): ClientMethods {
  const initPromise = client.init()
 
  const getVisitorData: GetVisitorData = async <TExtended extends boolean>(
    agentOptions: GetOptions<TExtended>,
    ignoreCache?: boolean
  ) => {
    Iif (typeof window === 'undefined') {
      throw new Error('getVisitorData() can only be called in the browser.')
    }
 
    await initPromise
 
    return client.getVisitorData(agentOptions, ignoreCache)
  }
 
  const clearCache: ClearCache = client.clearCache.bind(client)
 
  return {
    clearCache,
    getVisitorData,
  }
}