-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(confluence): added list space labels, delete label, delete page prop #3201
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
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
103 changes: 103 additions & 0 deletions
103
apps/sim/app/api/tools/confluence/pages-by-label/route.ts
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,103 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid' | ||
| import { validateAlphanumericId, validateJiraCloudId } from '@/lib/core/security/input-validation' | ||
| import { getConfluenceCloudId } from '@/tools/confluence/utils' | ||
|
|
||
| const logger = createLogger('ConfluencePagesByLabelAPI') | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| try { | ||
| const auth = await checkSessionOrInternalAuth(request) | ||
| if (!auth.success || !auth.userId) { | ||
| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const { searchParams } = new URL(request.url) | ||
| const domain = searchParams.get('domain') | ||
| const accessToken = searchParams.get('accessToken') | ||
| const labelId = searchParams.get('labelId') | ||
| const providedCloudId = searchParams.get('cloudId') | ||
| const limit = searchParams.get('limit') || '50' | ||
| const cursor = searchParams.get('cursor') | ||
|
|
||
| if (!domain) { | ||
| return NextResponse.json({ error: 'Domain is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
| return NextResponse.json({ error: 'Access token is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!labelId) { | ||
| return NextResponse.json({ error: 'Label ID is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const labelIdValidation = validateAlphanumericId(labelId, 'labelId', 255) | ||
| if (!labelIdValidation.isValid) { | ||
| return NextResponse.json({ error: labelIdValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const cloudId = providedCloudId || (await getConfluenceCloudId(domain, accessToken)) | ||
|
|
||
| const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId') | ||
| if (!cloudIdValidation.isValid) { | ||
| return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const queryParams = new URLSearchParams() | ||
| queryParams.append('limit', String(Math.min(Number(limit), 250))) | ||
| if (cursor) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid limit can produce broken upstream requestsLow Severity
Additional Locations (1) |
||
| queryParams.append('cursor', cursor) | ||
| } | ||
| const url = `https://api.atlassian.com/ex/confluence/${cloudId}/wiki/api/v2/labels/${labelId}/pages?${queryParams.toString()}` | ||
|
|
||
| const response = await fetch(url, { | ||
| method: 'GET', | ||
| headers: { | ||
| Accept: 'application/json', | ||
| Authorization: `Bearer ${accessToken}`, | ||
| }, | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const errorData = await response.json().catch(() => null) | ||
| logger.error('Confluence API error response:', { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| error: JSON.stringify(errorData, null, 2), | ||
| }) | ||
| const errorMessage = errorData?.message || `Failed to get pages by label (${response.status})` | ||
| return NextResponse.json({ error: errorMessage }, { status: response.status }) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| const pages = (data.results || []).map((page: any) => ({ | ||
| id: page.id, | ||
| title: page.title, | ||
| status: page.status ?? null, | ||
| spaceId: page.spaceId ?? null, | ||
| parentId: page.parentId ?? null, | ||
| authorId: page.authorId ?? null, | ||
| createdAt: page.createdAt ?? null, | ||
| version: page.version ?? null, | ||
| })) | ||
|
|
||
| return NextResponse.json({ | ||
| pages, | ||
| labelId, | ||
| nextCursor: data._links?.next | ||
| ? new URL(data._links.next, 'https://placeholder').searchParams.get('cursor') | ||
| : null, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error getting pages by label:', error) | ||
| return NextResponse.json( | ||
| { error: (error as Error).message || 'Internal server error' }, | ||
| { 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.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete label cannot target prefixed labels
Medium Severity
confluence_delete_labelonly acceptslabelNameand builds the delete path from that value, butadd_labelsupports non-global prefixes. Without aprefixinput, prefixed labels cannot be unambiguously targeted, so deletes for labels likemy/teamcan fail or hit the wrong label variant.Additional Locations (1)
apps/sim/tools/confluence/delete_label.ts#L54-L83