Created
August 15, 2025 13:58
-
-
Save sandalsoft/81639409d9a66cca79fe89f9d153dd84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check required environment variables | |
| const PROMPTQL_ACCESS_TOKEN = process.env.PROMPTQL_ACCESS_TOKEN; | |
| if (!PROMPTQL_ACCESS_TOKEN) { | |
| console.error("Error: PROMPTQL_ACCESS_TOKEN environment variable is not set or empty. Use a project service account token or Personal Access Token (PAT)"); | |
| process.exit(1); | |
| } | |
| const PROMPTQL_PROJECT_ID = process.env.PROMPTQL_PROJECT_ID; | |
| if (!PROMPTQL_PROJECT_ID) { | |
| console.error("Error: PROMPTQL_PROJECT_ID environment variable is not set or empty"); | |
| process.exit(1); | |
| } | |
| const PROMPTQL_TOKEN_REFRESH_URL = process.env.PROMPTQL_TOKEN_REFRESH_URL || "https://auth.pro.hasura.io/ddn/promptql/token"; | |
| async function getToken() { | |
| const response = await fetch(PROMPTQL_TOKEN_REFRESH_URL, { | |
| method: "POST", | |
| headers: { | |
| "Authorization": `pat ${PROMPTQL_ACCESS_TOKEN}`, | |
| "x-hasura-project-id": PROMPTQL_PROJECT_ID, | |
| "Content-Type": "application/json" | |
| } | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`Failed to fetch token: ${response.status} ${response.statusText}`); | |
| } | |
| const data = await response.json(); | |
| return data.token; | |
| } | |
| async function main() { | |
| try { | |
| const token = await getToken(); | |
| console.log(token); | |
| } catch (err) { | |
| console.error(err); | |
| process.exit(1); | |
| } | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment