Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/remove localhost url #228

Merged
merged 10 commits into from
Dec 3, 2024
7 changes: 5 additions & 2 deletions packages/configure/src/utils/authenticated.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
bangarang marked this conversation as resolved.
Show resolved Hide resolved

if (FLATFILE_API_URL == null) {
throw new Error('AGENT_INTERNAL_URL must be set in the environment')
}

export class AuthenticatedClient {
private _api?: DefaultApi
Expand Down
8 changes: 6 additions & 2 deletions packages/listener/src/events/authenticated.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
console.log('FLATFILE_API_URL', FLATFILE_API_URL)
bangarang marked this conversation as resolved.
Show resolved Hide resolved
if (!FLATFILE_API_URL) {
throw new Error('AGENT_INTERNAL_URL must be set in the environment')
}

const bearerToken = CrossEnvConfig.get('FLATFILE_BEARER_TOKEN')

this._accessToken = accessToken || bearerToken || '...'
Expand Down
14 changes: 14 additions & 0 deletions packages/listener/src/events/event.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -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) {
bangarang marked this conversation as resolved.
Show resolved Hide resolved
process.env.AGENT_INTERNAL_URL = 'agent_internal_url'
}

beforeEach(() => {
testFn = jest.fn()
})
Expand Down Expand Up @@ -86,4 +91,13 @@ describe('EventHandler', () => {
expect(testFn).toHaveBeenCalledTimes(1)
})
})

describe('AGENT_INTERNAL_URL', () => {
test('throws error when not set', () => {
process.env.AGENT_INTERNAL_URL = undefined
expect(() => new EventHandler()).toThrow(
'AGENT_INTERNAL_URL must be set in the environment'
)
})
})
})
14 changes: 14 additions & 0 deletions packages/listener/src/flatfile.listener.spec.ts
Original file line number Diff line number Diff line change
@@ -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) {
bangarang marked this conversation as resolved.
Show resolved Hide resolved
process.env.AGENT_INTERNAL_URL = 'agent_internal_url'
}
bangarang marked this conversation as resolved.
Show resolved Hide resolved

beforeEach(() => {
testFn = jest.fn()
})
Expand Down Expand Up @@ -150,4 +155,13 @@ describe('Client', () => {
expect(testFn).toHaveBeenCalledTimes(3)
})
})

describe('AGENT_INTERNAL_URL', () => {
test('throws error when not set', () => {
delete process.env.AGENT_INTERNAL_URL
expect(() => new FlatfileListener()).toThrow(
'AGENT_INTERNAL_URL must be set in the environment'
)
})
})
})
Loading