-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(jsm): add ProForma/JSM Forms discovery tools #4078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { checkInternalAuth } from '@/lib/auth/hybrid' | ||
| import { validateJiraCloudId, validateJiraIssueKey } from '@/lib/core/security/input-validation' | ||
| import { | ||
| getJiraCloudId, | ||
| getJsmFormsApiBaseUrl, | ||
| getJsmHeaders, | ||
| parseJsmErrorMessage, | ||
| } from '@/tools/jsm/utils' | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| const logger = createLogger('JsmIssueFormsAPI') | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const auth = await checkInternalAuth(request) | ||
| if (!auth.success || !auth.userId) { | ||
| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| try { | ||
| const body = await request.json() | ||
| const { domain, accessToken, cloudId: cloudIdParam, issueIdOrKey } = body | ||
|
|
||
| if (!domain) { | ||
| logger.error('Missing domain in request') | ||
| return NextResponse.json({ error: 'Domain is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
| logger.error('Missing access token in request') | ||
| return NextResponse.json({ error: 'Access token is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!issueIdOrKey) { | ||
| logger.error('Missing issueIdOrKey in request') | ||
| return NextResponse.json({ error: 'Issue ID or key is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const cloudId = cloudIdParam || (await getJiraCloudId(domain, accessToken)) | ||
|
|
||
| const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId') | ||
| if (!cloudIdValidation.isValid) { | ||
| return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const issueIdOrKeyValidation = validateJiraIssueKey(issueIdOrKey, 'issueIdOrKey') | ||
| if (!issueIdOrKeyValidation.isValid) { | ||
| return NextResponse.json({ error: issueIdOrKeyValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const baseUrl = getJsmFormsApiBaseUrl(cloudId) | ||
| const url = `${baseUrl}/issue/${encodeURIComponent(issueIdOrKey)}/form` | ||
|
|
||
| logger.info('Fetching issue forms from:', { url, issueIdOrKey }) | ||
|
|
||
| const response = await fetch(url, { | ||
| method: 'GET', | ||
| headers: getJsmHeaders(accessToken), | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text() | ||
| logger.error('JSM Forms API error:', { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| error: errorText, | ||
| }) | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| error: parseJsmErrorMessage(response.status, response.statusText, errorText), | ||
| details: errorText, | ||
| }, | ||
| { status: response.status } | ||
| ) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| const forms = Array.isArray(data) ? data : (data.values ?? data.forms ?? []) | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| output: { | ||
| ts: new Date().toISOString(), | ||
| issueIdOrKey, | ||
| forms: forms.map((form: Record<string, unknown>) => ({ | ||
| id: form.id ?? null, | ||
| name: form.name ?? null, | ||
| updated: form.updated ?? null, | ||
| submitted: form.submitted ?? false, | ||
| lock: form.lock ?? false, | ||
| internal: form.internal ?? null, | ||
| formTemplateId: (form.formTemplate as Record<string, unknown>)?.id ?? null, | ||
| })), | ||
| total: forms.length, | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error fetching issue forms:', { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| }) | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| error: error instanceof Error ? error.message : 'Internal server error', | ||
| success: false, | ||
| }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { checkInternalAuth } from '@/lib/auth/hybrid' | ||
| import { validateJiraCloudId, validateJiraIssueKey } from '@/lib/core/security/input-validation' | ||
| import { | ||
| getJiraCloudId, | ||
| getJsmFormsApiBaseUrl, | ||
| getJsmHeaders, | ||
| parseJsmErrorMessage, | ||
| } from '@/tools/jsm/utils' | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| const logger = createLogger('JsmFormStructureAPI') | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const auth = await checkInternalAuth(request) | ||
| if (!auth.success || !auth.userId) { | ||
| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| try { | ||
| const body = await request.json() | ||
| const { domain, accessToken, cloudId: cloudIdParam, projectIdOrKey, formId } = body | ||
|
|
||
| if (!domain) { | ||
| logger.error('Missing domain in request') | ||
| return NextResponse.json({ error: 'Domain is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
| logger.error('Missing access token in request') | ||
| return NextResponse.json({ error: 'Access token is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!projectIdOrKey) { | ||
| logger.error('Missing projectIdOrKey in request') | ||
| return NextResponse.json({ error: 'Project ID or key is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!formId) { | ||
| logger.error('Missing formId in request') | ||
| return NextResponse.json({ error: 'Form ID is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const cloudId = cloudIdParam || (await getJiraCloudId(domain, accessToken)) | ||
|
|
||
| const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId') | ||
| if (!cloudIdValidation.isValid) { | ||
| return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const projectIdOrKeyValidation = validateJiraIssueKey(projectIdOrKey, 'projectIdOrKey') | ||
| if (!projectIdOrKeyValidation.isValid) { | ||
| return NextResponse.json({ error: projectIdOrKeyValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const formIdValidation = validateJiraCloudId(formId, 'formId') | ||
| if (!formIdValidation.isValid) { | ||
| return NextResponse.json({ error: formIdValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const baseUrl = getJsmFormsApiBaseUrl(cloudId) | ||
| const url = `${baseUrl}/project/${encodeURIComponent(projectIdOrKey)}/form/${encodeURIComponent(formId)}` | ||
|
|
||
| logger.info('Fetching form template from:', { url, projectIdOrKey, formId }) | ||
|
|
||
| const response = await fetch(url, { | ||
| method: 'GET', | ||
| headers: getJsmHeaders(accessToken), | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text() | ||
| logger.error('JSM Forms API error:', { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| error: errorText, | ||
| }) | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| error: parseJsmErrorMessage(response.status, response.statusText, errorText), | ||
| details: errorText, | ||
| }, | ||
| { status: response.status } | ||
| ) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| output: { | ||
| ts: new Date().toISOString(), | ||
| projectIdOrKey, | ||
| formId, | ||
| design: data.design ?? null, | ||
| updated: data.updated ?? null, | ||
| publish: data.publish ?? null, | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error fetching form structure:', { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| }) | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| error: error instanceof Error ? error.message : 'Internal server error', | ||
| success: false, | ||
| }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.