Skip to content

Validate API key and endpoint before making requests#1251

Merged
josephjclark merged 2 commits intorelease/nextfrom
fix/missing-endpoint-validation
Feb 17, 2026
Merged

Validate API key and endpoint before making requests#1251
josephjclark merged 2 commits intorelease/nextfrom
fix/missing-endpoint-validation

Conversation

@elias-ba
Copy link
Contributor

@elias-ba elias-ba commented Feb 15, 2026

Short Description

Throw a clear error when OPENFN_API_KEY or OPENFN_ENDPOINT is missing instead of letting it fall through to a cryptic TypeError: Invalid URL.

See #1249

Implementation Details

In loadAppAuthConfig (projects/util.ts), when OPENFN_ENDPOINT is not set, config.endpoint stays undefined. This later causes new URL('/api/provision/...', undefined) in getLightningUrl to throw TypeError: Invalid URL, which is not helpful to the user.

There was already a // TODO probably need to throw on line 35 anticipating this. This PR fills in that TODO with early validation for both apiKey and endpoint, with actionable error messages.

QA Notes

  1. Create a .env with only OPENFN_API_KEY (no OPENFN_ENDPOINT)
  2. Run openfn project pull <uuid> -c .env
  3. Verify you get OPENFN_ENDPOINT is required... instead of TypeError: Invalid URL
  4. Remove OPENFN_API_KEY too and verify you get OPENFN_API_KEY is required...

AI Usage

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

Throw a clear error when OPENFN_API_KEY or OPENFN_ENDPOINT is missing
instead of letting it fall through to a cryptic TypeError: Invalid URL.

See #1249
@github-project-automation github-project-automation bot moved this to New Issues in v2 Feb 15, 2026
The endpoint can come from the local project file (not just env/CLI
args), so validating in loadAppAuthConfig is too early. Move the check
to getLightningUrl where the endpoint is actually consumed.
@elias-ba elias-ba moved this from New Issues to In progress in v2 Feb 15, 2026
@josephjclark josephjclark changed the base branch from main to release/next February 17, 2026 12:53
@josephjclark josephjclark merged commit 76311cc into release/next Feb 17, 2026
5 of 6 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in v2 Feb 17, 2026
@josephjclark josephjclark deleted the fix/missing-endpoint-validation branch February 17, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants