From e14cff658e5b66863525145a617e972616e9e695 Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Thu, 30 May 2024 18:19:02 -0500 Subject: [PATCH 1/2] feat: add version to apiUrl --- src/wrapper/FlatfileClient.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wrapper/FlatfileClient.ts b/src/wrapper/FlatfileClient.ts index b6681bb7..66f067fb 100644 --- a/src/wrapper/FlatfileClient.ts +++ b/src/wrapper/FlatfileClient.ts @@ -1,8 +1,8 @@ +import { CrossEnvConfig } from "@flatfile/cross-env-config"; +import urlJoin from "url-join"; import { FlatfileClient as FernClient } from "../Client"; -import * as environments from "../environments"; import * as core from "../core"; -import urlJoin from "url-join"; -import { CrossEnvConfig } from "@flatfile/cross-env-config"; +import * as environments from "../environments"; import { Records } from "./RecordsClient"; CrossEnvConfig.alias("FLATFILE_API_URL", "AGENT_INTERNAL_URL"); @@ -24,7 +24,7 @@ export class FlatfileClient extends FernClient { constructor(options: FlatfileClient.Options = {}) { super({ - environment: (options.environment || options.apiUrl) ?? environmentSupplier, + environment: resolveEnvironment(options), token: options.token ?? tokenSupplier, }); } @@ -36,6 +36,13 @@ export class FlatfileClient extends FernClient { } } +const resolveEnvironment = (options: FlatfileClient.Options) => { + if (options.apiUrl && !options.apiUrl.endsWith("/v1")) { + return urlJoin(options.apiUrl, "v1"); + } + return options.environment || options.apiUrl || environmentSupplier(); +}; + const environmentSupplier = () => { const url = CrossEnvConfig.get("FLATFILE_API_URL"); if (!url) { From cb15797ea12384371a1986ac99fd9b1abd4f0fcb Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Fri, 31 May 2024 08:18:36 -0500 Subject: [PATCH 2/2] Fix error message --- src/wrapper/FlatfileClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrapper/FlatfileClient.ts b/src/wrapper/FlatfileClient.ts index 66f067fb..17bd2f29 100644 --- a/src/wrapper/FlatfileClient.ts +++ b/src/wrapper/FlatfileClient.ts @@ -54,7 +54,7 @@ const environmentSupplier = () => { const tokenSupplier = () => { const token = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN"); if (token == undefined) { - throw new Error("FLATFILE_BEARER_TOKEN is not undefined"); + throw new Error("FLATFILE_BEARER_TOKEN is undefined"); } return token; };