-
Notifications
You must be signed in to change notification settings - Fork 5
Add optional baseURL override to Configuration
#119
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ | |
| export interface IConfigurationOpts { | ||
| apiKey: string; | ||
| env: TEnvironments; | ||
| baseURL?: string; | ||
| httpsAgent?: any; | ||
| onRequest?: TOnRequest; | ||
| onResponse?: TOnResponse; | ||
|
|
@@ -76,7 +77,8 @@ | |
| constructor(opts: IConfigurationOpts) { | ||
| Configuration._validateConfiguration(opts); | ||
|
|
||
| this.baseURL = `https://${opts.env}.methodfi.com`; | ||
| const baseURL = opts.baseURL ?? `https://${opts.env}.methodfi.com`; | ||
| this.baseURL = baseURL.replace(/\/+$/, ''); | ||
| this.apiKey = opts.apiKey; | ||
| this.httpsAgent = opts.httpsAgent || null; | ||
| this.onRequest = opts.onRequest || null; | ||
|
|
@@ -94,5 +96,12 @@ | |
| private static _validateConfiguration(opts: IConfigurationOpts): void { | ||
| if (!Environments[opts.env]) throw new Error(`Invalid env: ${opts.env}`); | ||
| if (!opts.apiKey) throw new Error(`Invalid apiKey: ${opts.apiKey}`); | ||
| if (opts.baseURL) { | ||
| try { | ||
| new URL(opts.baseURL); | ||
|
Comment on lines
+99
to
+101
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. If a caller passes Useful? React with 👍 / 👎. |
||
| } catch (error) { | ||
| throw new Error(`Invalid baseURL: ${opts.baseURL}`); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data High