Skip to content

Conversation

@josebet1
Copy link

Motivation

  • Enable overriding the SDK base URL so integration tests and local mocks can target a local or self-hosted endpoint instead of Method's remote environments.
  • Prevent accidental calls to production/sandbox during local development by allowing explicit endpoint control.
  • Maintain existing environment-driven defaults and validation while following common SaaS SDK patterns (e.g. Stripe) for configurability.

Description

  • Added an optional baseURL?: string field to the IConfigurationOpts interface.
  • Updated Configuration constructor to use opts.baseURL ?? \\https://${opts.env}.methodfi.com\`` and normalize the value by stripping trailing slashes with baseURL.replace(/\/+$/, '').
  • Added URL validation in Configuration._validateConfiguration to throw a clear error for invalid baseURL values.
  • Documented the new baseURL option in the README.md usage example showing how to point the SDK at http://localhost:4010 for local mocks.

Testing

  • No automated tests were run for this change.

Codex Task


this.baseURL = `https://${opts.env}.methodfi.com`;
const baseURL = opts.baseURL ?? `https://${opts.env}.methodfi.com`;
this.baseURL = baseURL.replace(/\/+$/, '');

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '/'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '/'.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07d91bacd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +99 to +101
if (opts.baseURL) {
try {
new URL(opts.baseURL);

Choose a reason for hiding this comment

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

P2 Badge Reject empty baseURL values

If a caller passes baseURL: '' (e.g., from an unset env var), the opts.baseURL check is falsy so validation is skipped, but the constructor still uses the empty string because ?? does not fall back on ''. This results in Configuration.baseURL being empty, and later new URL(${request.baseURL}${request.url}) in src/resource.ts throws for relative-only URLs, breaking all requests at runtime. Consider treating empty/whitespace strings as invalid or falling back to the env default.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants