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

feat: add version to apiUrl #45

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/wrapper/FlatfileClient.ts
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");
Expand All @@ -24,7 +24,7 @@ export class FlatfileClient extends FernClient {

constructor(options: FlatfileClient.Options = {}) {
super({
environment: (options.environment || options.apiUrl) ?? environmentSupplier,
environment: resolveEnvironment(options),
Copy link

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.

- return (this._records ??= new Records(this._options));
+ if (!this._records) {
+     this._records = new Records(this._options);
+ }
+ return this._records;

Committable suggestion was skipped due low confidence.

token: options.token ?? tokenSupplier,
});
}
Expand All @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure apiUrl is not undefined before manipulating it.

- if (options.apiUrl && !options.apiUrl.endsWith("/v1")) {
+ if (options.apiUrl !== undefined && !options.apiUrl.endsWith("/v1")) {
    return urlJoin(options.apiUrl, "v1");
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const resolveEnvironment = (options: FlatfileClient.Options) => {
if (options.apiUrl && !options.apiUrl.endsWith("/v1")) {
return urlJoin(options.apiUrl, "v1");
}
return options.environment || options.apiUrl || environmentSupplier();
};
const resolveEnvironment = (options: FlatfileClient.Options) => {
if (options.apiUrl !== undefined && !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) {
Expand All @@ -47,7 +54,7 @@ const environmentSupplier = () => {
const tokenSupplier = () => {
const token = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN");
if (token == undefined) {
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (token == undefined) {
if (token === undefined) {
Tools
Biome

[error] 56-56: Use === instead of ==.
== is only allowed when comparing against null

throw new Error("FLATFILE_BEARER_TOKEN is not undefined");
throw new Error("FLATFILE_BEARER_TOKEN is undefined");
}
return token;
};
Loading