UNPKG

@flatfile/plugin-job-handler

Version:
30 lines (27 loc) 1.6 kB
import { Flatfile } from '@flatfile/api'; import { EventFilter, FlatfileEvent, FlatfileListener } from '@flatfile/listener'; interface PluginOptions { readonly debug?: boolean; } type TickFunction = (progress: number, info?: string) => Promise<Flatfile.JobResponse>; /** * `jobHandler` is a factory function that constructs a job configuration plugin for * the Flatfile API. This function will take a string representing a job name and * a handler that will process the job, returning either void or a JobOutcome object. * * @param {string | EventFilter} job - The job name or event filter. * * @param {Function} handler - A function that takes an `event` and a `tick()` callback to * allow updating of the job's progress, returning a promise that resolves to either * void or a JobOutcome object. This function will be used to process the job when the * "job:ready" event is emitted. This function can fail the job by throwing an Error. * * @param {PluginOptions} opts - An optional object containing plugin options. * @param {boolean} opts.debug - An optional boolean that will enable debug logging. * Defaults to false. * * @returns {Function} Returns a function that takes a FlatfileListener, adding an event * listener for the "job:ready" event and processing the job with the provided handler. */ declare function jobHandler(job: string | EventFilter, handler: (event: FlatfileEvent, tick: TickFunction) => Promise<void | Flatfile.JobCompleteDetails>, opts?: PluginOptions): (listener: FlatfileListener) => void; export { type PluginOptions, type TickFunction, jobHandler };