Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions plugins/job-handler/src/job.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import type {
} from '@flatfile/listener'
import { log, logError } from '@flatfile/util-common'

const api = new FlatfileClient()

export interface PluginOptions {
readonly debug?: boolean
/**
* Custom API URL to use for the Flatfile API client.
* This is useful when working with non-production environments.
* If not provided, defaults to the standard Flatfile API URL.
*/
readonly apiUrl?: string
}

export type TickFunction = (
Expand All @@ -33,6 +37,9 @@ export type TickFunction = (
* @param {PluginOptions} opts - An optional object containing plugin options.
* @param {boolean} opts.debug - An optional boolean that will enable debug logging.
* Defaults to false.
* @param {string} opts.apiUrl - An optional custom API URL for non-production environments
* (e.g., 'https://<special-url>.flatfile.com/api'). If not provided, uses the default
* Flatfile API URL.
*
* @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.
Expand All @@ -50,6 +57,10 @@ export function jobHandler(
listener.on('job:ready', filter, async (event) => {
const { jobId } = event.context

const api = new FlatfileClient(
opts.apiUrl ? { environment: opts.apiUrl } : undefined
)

await api.jobs.ack(jobId, {
info: 'Accepted',
progress: 0,
Expand Down
Loading