From 586e5d5570afd4d724671d0e4d17449acb419d08 Mon Sep 17 00:00:00 2001 From: "Elias W. BA" Date: Sun, 15 Feb 2026 16:42:30 +0000 Subject: [PATCH 1/2] Validate API key and endpoint before making requests 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 --- packages/cli/src/projects/util.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/projects/util.ts b/packages/cli/src/projects/util.ts index be6f8b1a0..9d5ca1cd4 100644 --- a/packages/cli/src/projects/util.ts +++ b/packages/cli/src/projects/util.ts @@ -32,7 +32,17 @@ export const loadAppAuthConfig = ( config.endpoint = OPENFN_ENDPOINT; } - // TODO probably need to throw + if (!config.apiKey) { + throw new CLIError( + 'OPENFN_API_KEY is required. Set it in .env, pass --api-key, or set the environment variable.' + ); + } + if (!config.endpoint) { + throw new CLIError( + 'OPENFN_ENDPOINT is required. Set it in .env, pass --endpoint, or set the environment variable.\n' + + 'Example: OPENFN_ENDPOINT=https://app.openfn.org' + ); + } return config as Required; }; From 0ee819ce6969ea43e62a4c7d75845d47259bf56f Mon Sep 17 00:00:00 2001 From: "Elias W. BA" Date: Sun, 15 Feb 2026 17:38:45 +0000 Subject: [PATCH 2/2] Move endpoint validation to getLightningUrl 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. --- packages/cli/src/projects/util.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/projects/util.ts b/packages/cli/src/projects/util.ts index 9d5ca1cd4..634349c5d 100644 --- a/packages/cli/src/projects/util.ts +++ b/packages/cli/src/projects/util.ts @@ -37,13 +37,6 @@ export const loadAppAuthConfig = ( 'OPENFN_API_KEY is required. Set it in .env, pass --api-key, or set the environment variable.' ); } - if (!config.endpoint) { - throw new CLIError( - 'OPENFN_ENDPOINT is required. Set it in .env, pass --endpoint, or set the environment variable.\n' + - 'Example: OPENFN_ENDPOINT=https://app.openfn.org' - ); - } - return config as Required; }; @@ -103,6 +96,12 @@ export const getLightningUrl = ( path: string = '', snapshots?: string[] ) => { + if (!endpoint) { + throw new CLIError( + 'OPENFN_ENDPOINT is required. Set it in .env, pass --endpoint, or set the environment variable.\n' + + 'Example: OPENFN_ENDPOINT=https://app.openfn.org' + ); + } const params = new URLSearchParams(); snapshots?.forEach((snapshot) => params.append('snapshots[]', snapshot)); return new URL(`/api/provision/${path}?${params.toString()}`, endpoint);