-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: add version to apiUrl #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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(); | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
Comment on lines
+39
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure - if (options.apiUrl && !options.apiUrl.endsWith("/v1")) {
+ if (options.apiUrl !== undefined && !options.apiUrl.endsWith("/v1")) {
return urlJoin(options.apiUrl, "v1");
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const environmentSupplier = () => { | ||||||||||||||||||||||||||
const url = CrossEnvConfig.get("FLATFILE_API_URL"); | ||||||||||||||||||||||||||
if (!url) { | ||||||||||||||||||||||||||
|
@@ -47,7 +54,7 @@ const environmentSupplier = () => { | |||||||||||||||||||||||||
const tokenSupplier = () => { | ||||||||||||||||||||||||||
const token = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN"); | ||||||||||||||||||||||||||
if (token == undefined) { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use strict equality for checking undefined. - if (token == undefined) {
+ if (token === undefined) { Committable suggestion
Suggested change
ToolsBiome
|
||||||||||||||||||||||||||
throw new Error("FLATFILE_BEARER_TOKEN is not undefined"); | ||||||||||||||||||||||||||
throw new Error("FLATFILE_BEARER_TOKEN is undefined"); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return token; | ||||||||||||||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve the static analysis error regarding assignment in an expression.