Skip to content

Commit

Permalink
fix: add CustomAgent support
Browse files Browse the repository at this point in the history
  • Loading branch information
ilfa committed Sep 12, 2023
1 parent 6fdf561 commit 01d5024
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/fpjs-provider.tsx
@@ -1,6 +1,7 @@
import { PropsWithChildren, useCallback, useEffect, useMemo, useRef } from 'react'
import { FpjsContext } from '../fpjs-context'
import { FpjsClient, FpjsClientOptions, GetOptions } from '@fingerprintjs/fingerprintjs-pro-spa'
import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro'
import * as packageInfo from '../../package.json'
import { isSSR } from '../ssr'
import { waitUntil } from '../utils/wait-until'
Expand All @@ -9,12 +10,16 @@ import type { EnvDetails } from '../env.types'

const pkgName = packageInfo.name.split('/')[1]

interface CustomAgent {
load: (options: FingerprintJS.LoadOptions) => Promise<FingerprintJS.Agent>
}
interface FpjsProviderOptions extends FpjsClientOptions {
/**
* If set to `true`, will force FpjsClient to be rebuilt with the new options. Should be used with caution
* since it can be triggered too often (e.g. on every render) and negatively affect performance of the JS agent.
*/
forceRebuild?: boolean
customAgent?: CustomAgent
}

/**
Expand Down Expand Up @@ -61,6 +66,7 @@ function ProviderWithEnv<TExtended extends boolean>({
cacheTimeInSeconds,
cachePrefix,
cacheLocation,
customAgent,
loadOptions,
env,
}: PropsWithChildren<ProviderWithEnvProps>) {
Expand All @@ -73,9 +79,10 @@ function ProviderWithEnv<TExtended extends boolean>({
cacheTimeInSeconds,
cachePrefix,
cacheLocation,
customAgent,
loadOptions,
}
}, [loadOptions, cache, cacheTimeInSeconds, cachePrefix, cacheLocation])
}, [loadOptions, cache, cacheTimeInSeconds, cachePrefix, cacheLocation, customAgent])

const createClient = useCallback(() => {
let integrationInfo = `${pkgName}/${packageInfo.version}`
Expand Down

0 comments on commit 01d5024

Please sign in to comment.