From ef41c7170180919f7e246610d16c12a22c18b319 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Date: Wed, 9 Jul 2025 15:54:40 -0300 Subject: [PATCH] fix: update API Access codes to include only authenticated code (#8957) * changed code tabs to show authenticated values * Fixed file upload test --- .../modals/apiModal/codeTabs/code-tabs.tsx | 1 - .../modals/apiModal/utils/get-curl-code.tsx | 34 +++++-------------- .../modals/apiModal/utils/get-js-api-code.tsx | 13 ++----- .../apiModal/utils/get-python-api-code.tsx | 12 ++----- .../core/unit/fileUploadComponent.spec.ts | 10 ++++++ 5 files changed, 24 insertions(+), 46 deletions(-) diff --git a/src/frontend/src/modals/apiModal/codeTabs/code-tabs.tsx b/src/frontend/src/modals/apiModal/codeTabs/code-tabs.tsx index 98687544f..97cf2144e 100644 --- a/src/frontend/src/modals/apiModal/codeTabs/code-tabs.tsx +++ b/src/frontend/src/modals/apiModal/codeTabs/code-tabs.tsx @@ -78,7 +78,6 @@ export default function APITabsComponent() { endpointName: endpointName || "", streaming: streaming, flowId: flowId || "", - isAuthenticated: autologin || false, processedPayload: processedPayload, }; diff --git a/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx b/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx index d96c59b8a..3e3274dcc 100644 --- a/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx +++ b/src/frontend/src/modals/apiModal/utils/get-curl-code.tsx @@ -40,13 +40,11 @@ export function getCurlWebhookCode({ export function getNewCurlCode({ flowId, - isAuthenticated, endpointName, processedPayload, platform, }: { flowId: string; - isAuthenticated: boolean; endpointName: string; processedPayload: any; platform?: "unix" | "powershell"; @@ -65,27 +63,19 @@ export function getNewCurlCode({ if (detectedPlatform === "powershell") { // PowerShell with here-string (most robust for complex JSON) - return `${ - isAuthenticated - ? `if (-not $env:LANGFLOW_API_KEY) { + return `if (-not $env:LANGFLOW_API_KEY) { Write-Error "LANGFLOW_API_KEY environment variable not found" exit 1 } -` - : "" - }$jsonData = @' +$jsonData = @' ${singleLinePayload} '@ curl --request POST \` --url "${apiUrl}?stream=false" \` - --header "Content-Type: application/json"${ - isAuthenticated - ? ` \` - --header "x-api-key: $env:LANGFLOW_API_KEY"` - : "" - } \` + --header "Content-Type: application/json" \` + --header "x-api-key: $env:LANGFLOW_API_KEY" \` --data $jsonData`; } else { // Unix-like systems (Linux, Mac, WSL2) @@ -94,24 +84,16 @@ curl --request POST \` .map((line, index) => (index === 0 ? line : " " + line)) .join("\n\t\t"); - return `${ - isAuthenticated - ? `# Get API key from environment variable + return `# Get API key from environment variable if [ -z "$LANGFLOW_API_KEY" ]; then echo "Error: LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables." exit 1 fi -` - : "" - }curl --request POST \\ +curl --request POST \\ --url '${apiUrl}?stream=false' \\ - --header 'Content-Type: application/json' \\${ - isAuthenticated - ? ` - --header "x-api-key: $LANGFLOW_API_KEY" \\` - : "" - } + --header 'Content-Type: application/json' \\ + --header "x-api-key: $LANGFLOW_API_KEY" \\ --data '${unixFormattedPayload}'`; } } diff --git a/src/frontend/src/modals/apiModal/utils/get-js-api-code.tsx b/src/frontend/src/modals/apiModal/utils/get-js-api-code.tsx index 110bed58d..6aad93d12 100644 --- a/src/frontend/src/modals/apiModal/utils/get-js-api-code.tsx +++ b/src/frontend/src/modals/apiModal/utils/get-js-api-code.tsx @@ -5,19 +5,16 @@ import { customGetHostProtocol } from "@/customization/utils/custom-get-host-pro * * @param {Object} params - The parameters for generating the API code * @param {string} params.flowId - The ID of the flow to run - * @param {boolean} params.isAuthenticated - Whether authentication is required * @param {string} params.endpointName - The endpoint name for the flow * @param {Object} params.processedPayload - The pre-processed payload object * @returns {string} Generated JavaScript code as a string */ export function getNewJsApiCode({ flowId, - isAuthenticated, endpointName, processedPayload, }: { flowId: string; - isAuthenticated: boolean; endpointName: string; processedPayload: any; }): string { @@ -32,21 +29,17 @@ export function getNewJsApiCode({ const payloadString = JSON.stringify(payloadWithSession, null, 4); - return `${ - isAuthenticated - ? `// Get API key from environment variable + return `// Get API key from environment variable if (!process.env.LANGFLOW_API_KEY) { throw new Error('LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables.'); } -` - : "" - }const payload = ${payloadString}; +const payload = ${payloadString}; const options = { method: 'POST', headers: { - 'Content-Type': 'application/json'${isAuthenticated ? ',\n "x-api-key": process.env.LANGFLOW_API_KEY' : ""} + 'Content-Type': 'application/json',\n "x-api-key": process.env.LANGFLOW_API_KEY }, body: JSON.stringify(payload) }; diff --git a/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx b/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx index 4580b0f09..b76d56a8e 100644 --- a/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx +++ b/src/frontend/src/modals/apiModal/utils/get-python-api-code.tsx @@ -2,12 +2,10 @@ import { customGetHostProtocol } from "@/customization/utils/custom-get-host-pro export function getNewPythonApiCode({ flowId, - isAuthenticated, endpointName, processedPayload, }: { flowId: string; - isAuthenticated: boolean; endpointName: string; processedPayload: any; }): string { @@ -20,18 +18,14 @@ export function getNewPythonApiCode({ .replace(/null/g, "None"); return `import requests -${ - isAuthenticated - ? `import os +import os # API Configuration try: api_key = os.environ["LANGFLOW_API_KEY"] except KeyError: raise ValueError("LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables.") -` - : "" -} + url = "${apiUrl}" # The complete API endpoint URL for this flow # Request payload configuration @@ -39,7 +33,7 @@ payload = ${payloadString} # Request headers headers = { - "Content-Type": "application/json"${isAuthenticated ? ',\n "x-api-key": api_key # Authentication key from environment variable' : ""} + "Content-Type": "application/json",\n "x-api-key": api_key # Authentication key from environment variable } try: diff --git a/src/frontend/tests/core/unit/fileUploadComponent.spec.ts b/src/frontend/tests/core/unit/fileUploadComponent.spec.ts index 9df144a59..ccf4d2076 100644 --- a/src/frontend/tests/core/unit/fileUploadComponent.spec.ts +++ b/src/frontend/tests/core/unit/fileUploadComponent.spec.ts @@ -323,6 +323,16 @@ test( }); await page.getByTestId(`remove-file-button-${renamedTxtFile}`).click(); + await page + .getByTestId("handle-file-shownode-raw content-right") + .first() + .click(); + + await page + .getByTestId("handle-chatoutput-noshownode-inputs-target") + .first() + .click(); + await page .getByRole("button", { name: "Playground", exact: true }) .click();