Skip to content

Commit 3003b36

Browse files
authored
fix(job-handler): add apiUrl option for non-production environments (#875)
Added `apiUrl` option to `jobHandler` plugin to support non-production environments. Previously, the plugin hardcoded the FlatfileClient to use the default production API URL, causing 401 errors for customers using staging environments. - Added `apiUrl` option to PluginOptions interface - FlatfileClient now instantiated per-event to support per-handler config - Passes `environment` option to FlatfileClient (the correct option name)
1 parent c41380d commit 3003b36

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

plugins/job-handler/src/job.handler.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import type {
77
} from '@flatfile/listener'
88
import { log, logError } from '@flatfile/util-common'
99

10-
const api = new FlatfileClient()
11-
1210
export interface PluginOptions {
1311
readonly debug?: boolean
12+
/**
13+
* Custom API URL to use for the Flatfile API client.
14+
* This is useful when working with non-production environments.
15+
* If not provided, defaults to the standard Flatfile API URL.
16+
*/
17+
readonly apiUrl?: string
1418
}
1519

1620
export type TickFunction = (
@@ -33,6 +37,9 @@ export type TickFunction = (
3337
* @param {PluginOptions} opts - An optional object containing plugin options.
3438
* @param {boolean} opts.debug - An optional boolean that will enable debug logging.
3539
* Defaults to false.
40+
* @param {string} opts.apiUrl - An optional custom API URL for non-production environments
41+
* (e.g., 'https://<special-url>.flatfile.com/api'). If not provided, uses the default
42+
* Flatfile API URL.
3643
*
3744
* @returns {Function} Returns a function that takes a FlatfileListener, adding an event
3845
* listener for the "job:ready" event and processing the job with the provided handler.
@@ -50,6 +57,10 @@ export function jobHandler(
5057
listener.on('job:ready', filter, async (event) => {
5158
const { jobId } = event.context
5259

60+
const api = new FlatfileClient(
61+
opts.apiUrl ? { environment: opts.apiUrl } : undefined
62+
)
63+
5364
await api.jobs.ack(jobId, {
5465
info: 'Accepted',
5566
progress: 0,

0 commit comments

Comments
 (0)