All files / src/utils registerPlugin.ts

14.28% Statements 1/7
0% Branches 0/6
0% Functions 0/2
14.28% Lines 1/7

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                                    4x  
import { EventResponse } from '@fingerprintjs/fingerprintjs-pro-server-api'
import { type Event } from '@fingerprint/node-sdk'
import loadedPlugins from '../../plugins'
 
export type ProcessOpenClientResponseContext = {
  event: EventResponse | Event | null
  httpResponse: Response
}
 
export type ProcessSealedResultContext = {
  event: EventResponse | Event | null
  httpResponse: Response
}
 
export type ProcessIdentificationResponseContext = {
  response: Record<string, unknown>
  httpResponse: Response
}
 
export function isV4Event(event: EventResponse | Event | null): event is Event {
  return event != null && 'event_id' in event
}
 
export function getEventId(event: EventResponse | Event | null): string | undefined {
  if (event == null) {
    return undefined
  }
  if (isV4Event(event)) {
    return event.event_id
  }
  return event.products?.identification?.data?.requestId
}
 
export type ProcessSealedResultPluginFunction = (context: ProcessSealedResultContext) => void | Promise<void>
/**
 * @deprecated Use {@link ProcessSealedResultPluginFunction} or {@link ProcessIdentificationResponsePluginFunction} instead.
 */
export type ProcessOpenClientResponsePluginFunction = (
  context: ProcessOpenClientResponseContext
) => void | Promise<void>
export type ProcessIdentificationResponsePluginFunction = (
  context: ProcessIdentificationResponseContext
) => void | Promise<void>
 
export type ProcessSealedResultPlugin = {
  name: string
  type: 'processSealedResult'
  callback: ProcessSealedResultPluginFunction
}
 
/**
 * @deprecated Use {@link ProcessSealedResultPlugin} or {@link ProcessIdentificationResponsePlugin} instead.
 */
export type ProcessOpenClientResponsePlugin = {
  name: string
  type: 'processOpenClientResponse'
  callback: ProcessOpenClientResponsePluginFunction
}
 
export type ProcessIdentificationResponsePlugin = {
  name: string
  type: 'processIdentificationResponse'
  callback: ProcessIdentificationResponsePluginFunction
}
 
export type Plugin = ProcessSealedResultPlugin | ProcessOpenClientResponsePlugin | ProcessIdentificationResponsePlugin
export const plugins: Plugin[] = loadedPlugins