|
1 | 1 | import { createLogger } from '@sim/logger' |
2 | 2 | import { type NextRequest, NextResponse } from 'next/server' |
3 | 3 | import { checkInternalAuth } from '@/lib/auth/hybrid' |
4 | | -import { validateJiraCloudId } from '@/lib/core/security/input-validation' |
5 | | -import { getJiraCloudId, getJsmFormsApiBaseUrl, getJsmHeaders } from '@/tools/jsm/utils' |
| 4 | +import { validateJiraCloudId, validateJiraIssueKey } from '@/lib/core/security/input-validation' |
| 5 | +import { |
| 6 | + getJiraCloudId, |
| 7 | + getJsmFormsApiBaseUrl, |
| 8 | + getJsmHeaders, |
| 9 | + parseJsmErrorMessage, |
| 10 | +} from '@/tools/jsm/utils' |
6 | 11 |
|
7 | 12 | export const dynamic = 'force-dynamic' |
8 | 13 |
|
9 | 14 | const logger = createLogger('JsmFormStructureAPI') |
10 | 15 |
|
11 | | -function parseJsmErrorMessage(status: number, statusText: string, errorText: string): string { |
12 | | - try { |
13 | | - const errorData = JSON.parse(errorText) |
14 | | - if (errorData.errorMessage) { |
15 | | - return `JSM Forms API error: ${errorData.errorMessage}` |
16 | | - } |
17 | | - } catch { |
18 | | - if (errorText) { |
19 | | - return `JSM Forms API error: ${errorText}` |
20 | | - } |
21 | | - } |
22 | | - return `JSM Forms API error: ${status} ${statusText}` |
23 | | -} |
24 | | - |
25 | 16 | export async function POST(request: NextRequest) { |
26 | 17 | const auth = await checkInternalAuth(request) |
27 | 18 | if (!auth.success || !auth.userId) { |
@@ -59,6 +50,16 @@ export async function POST(request: NextRequest) { |
59 | 50 | return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 }) |
60 | 51 | } |
61 | 52 |
|
| 53 | + const projectIdOrKeyValidation = validateJiraIssueKey(projectIdOrKey, 'projectIdOrKey') |
| 54 | + if (!projectIdOrKeyValidation.isValid) { |
| 55 | + return NextResponse.json({ error: projectIdOrKeyValidation.error }, { status: 400 }) |
| 56 | + } |
| 57 | + |
| 58 | + const formIdValidation = validateJiraCloudId(formId, 'formId') |
| 59 | + if (!formIdValidation.isValid) { |
| 60 | + return NextResponse.json({ error: formIdValidation.error }, { status: 400 }) |
| 61 | + } |
| 62 | + |
62 | 63 | const baseUrl = getJsmFormsApiBaseUrl(cloudId) |
63 | 64 | const url = `${baseUrl}/project/${encodeURIComponent(projectIdOrKey)}/form/${encodeURIComponent(formId)}` |
64 | 65 |
|
|
0 commit comments