diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab42638..8ba5b6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,5 +31,8 @@ jobs: - name: Run lint run: pnpm lint + - name: Run typecheck + run: pnpm typecheck + - name: Run tests run: pnpm vitest run diff --git a/.husky/pre-commit b/.husky/pre-commit index 5ee7abd..10a68e8 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,2 @@ pnpm exec lint-staged +pnpm typecheck diff --git a/README.md b/README.md index e816b58..db97826 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Interactive CLI for querying Atlassian Forge SQL databases via web triggers. Announcement and discussion on dev forum: [here](https://community.developer.atlassian.com/t/introducing-fsql-an-interactive-cli-for-querying-forge-sql-databases-via-web-triggers/98076) + ## Demo ![demo](demo-usage.gif) diff --git a/package.json b/package.json index 76bf497..39de9d0 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "lint": "pnpm lint:eslint && pnpm lint:prettier", "lint:eslint": "eslint '**/*.{ts,tsx,js,jsx}' --ignore-pattern '**/eslint.config.js'", "lint:prettier": "prettier '**/*.{ts,tsx,js,jsx,json,md,yaml,yml}' --check || echo '⚠️ Warning: Prettier formatting issues found. Run \"pnpm fixstyle\" to fix them.'", + "typecheck": "tsc --noEmit", "fixall": "pnpm fixstyle && pnpm fixsrc", "fixsrc": "eslint '**/*.{ts,tsx,js,jsx}' --ignore-pattern '**/eslint.config.js' --fix", "fixstyle": "prettier '**/*.{ts,tsx,js,jsx,json,md,yaml,yml}' --write", diff --git a/src/execute-sql.ts b/src/execute-sql.ts index b51de95..592d96f 100644 --- a/src/execute-sql.ts +++ b/src/execute-sql.ts @@ -6,8 +6,11 @@ const executeSql = async (req: { }): Promise> => { console.log("\n=== Executing Custom SQL Query ==="); - if (getAppContext()?.environmentType === `PRODUCTION`) { - const errorMsg = `executeSql is disabled in PRODUCTION for security.`; + const appContext = getAppContext(); + if (!appContext || appContext.environmentType === `PRODUCTION`) { + const errorMsg = !appContext + ? `executeSql requires a valid Forge context.` + : `executeSql is disabled in PRODUCTION for security.`; console.log(errorMsg); return getHttpResponse(403, { success: false, @@ -16,11 +19,10 @@ const executeSql = async (req: { } const payload = req.body; - let sqlRequest: { query?: string } | null = null; let query: string | undefined; try { - sqlRequest = JSON.parse(payload); + const sqlRequest: { query?: string } | null = JSON.parse(payload); query = sqlRequest?.query; if (!query) {