diff --git a/packages/configure/src/utils/authenticated.client.ts b/packages/configure/src/utils/authenticated.client.ts index 6e08a9ef..e56f825b 100644 --- a/packages/configure/src/utils/authenticated.client.ts +++ b/packages/configure/src/utils/authenticated.client.ts @@ -2,8 +2,11 @@ import { Configuration, DefaultApi } from '@flatfile/api' // TODO: We will need to make this conditional depending on if it's in the NodeVM or the Browser import fetch, { RequestInit } from 'node-fetch' -const FLATFILE_API_URL = - process.env.AGENT_INTERNAL_URL || 'http://localhost:3000' +const FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL + +if (FLATFILE_API_URL == null) { + throw new Error('AGENT_INTERNAL_URL must be set in the environment') +} export class AuthenticatedClient { private _api?: DefaultApi diff --git a/packages/listener/src/events/authenticated.client.ts b/packages/listener/src/events/authenticated.client.ts index 6d994acc..614f174d 100644 --- a/packages/listener/src/events/authenticated.client.ts +++ b/packages/listener/src/events/authenticated.client.ts @@ -7,8 +7,12 @@ export class AuthenticatedClient { public _apiUrl?: string constructor(accessToken?: string, apiUrl?: string) { - const FLATFILE_API_URL = - CrossEnvConfig.get('AGENT_INTERNAL_URL') || 'http://localhost:3000' + const FLATFILE_API_URL = CrossEnvConfig.get('AGENT_INTERNAL_URL') + + if (FLATFILE_API_URL == null) { + throw new Error('AGENT_INTERNAL_URL must be set in the environment') + } + const bearerToken = CrossEnvConfig.get('FLATFILE_BEARER_TOKEN') this._accessToken = accessToken || bearerToken || '...' diff --git a/packages/listener/src/events/event.handler.spec.ts b/packages/listener/src/events/event.handler.spec.ts index 8eb31205..ce12c47a 100644 --- a/packages/listener/src/events/event.handler.spec.ts +++ b/packages/listener/src/events/event.handler.spec.ts @@ -1,8 +1,13 @@ +import { CrossEnvConfig } from '@flatfile/cross-env-config' import { EventHandler } from './event.handler' describe('EventHandler', () => { let testFn: jest.Mock + if (CrossEnvConfig.get('AGENT_INTERNAL_URL') == null) { + process.env.AGENT_INTERNAL_URL = 'agent_internal_url' + } + beforeEach(() => { testFn = jest.fn() }) @@ -86,4 +91,19 @@ describe('EventHandler', () => { expect(testFn).toHaveBeenCalledTimes(1) }) }) + + describe('AGENT_INTERNAL_URL', () => { + test('throws error when not set', () => { + process.env.AGENT_INTERNAL_URL = undefined + + try { + new EventHandler().on('foo', testFn) + } catch (e) { + expect(e).toBeInstanceOf(Error) + expect((e as Error).message).toBe( + 'AGENT_INTERNAL_URL must be set in the environment' + ) + } + }) + }) }) diff --git a/packages/listener/src/flatfile.listener.spec.ts b/packages/listener/src/flatfile.listener.spec.ts index a0e884b1..a301f006 100644 --- a/packages/listener/src/flatfile.listener.spec.ts +++ b/packages/listener/src/flatfile.listener.spec.ts @@ -1,8 +1,13 @@ +import { CrossEnvConfig } from '@flatfile/cross-env-config' import { FlatfileListener } from './flatfile.listener' describe('Client', () => { let testFn: jest.Mock + if (CrossEnvConfig.get('AGENT_INTERNAL_URL') == null) { + process.env.AGENT_INTERNAL_URL = 'agent_internal_url' + } + beforeEach(() => { testFn = jest.fn() }) @@ -150,4 +155,21 @@ describe('Client', () => { expect(testFn).toHaveBeenCalledTimes(3) }) }) + + describe('AGENT_INTERNAL_URL', () => { + test('throws error when not set', () => { + process.env.AGENT_INTERNAL_URL = undefined + + try { + FlatfileListener.create((c) => { + c.on('foo', () => {}) + }) + } catch (e) { + expect(e).toBeInstanceOf(Error) + expect((e as Error).message).toBe( + 'AGENT_INTERNAL_URL must be set in the environment' + ) + } + }) + }) })