-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(confluence): add get user by account ID tool #3345
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
16 commits
Select commit
Hold shift + click to select a range
3eb6c08
feat(confluence): add get user by account ID tool
waleedlatif1 2a97824
feat(confluence): add missing tools for tasks, blog posts, spaces, de…
waleedlatif1 f09fef9
fix(confluence): add missing OAuth scopes to auth.ts provider config
waleedlatif1 1dc4ff2
lint
waleedlatif1 58a5c7d
fix(confluence): fix truncated get_user tool description in docs
waleedlatif1 3ff8342
fix(confluence): address PR review feedback
waleedlatif1 973fe96
feat(confluence): add missing response fields for descendants and tasks
waleedlatif1 6da784e
lint
waleedlatif1 a494656
fix(confluence): use validatePathSegment for Atlassian account IDs
waleedlatif1 ea45ee6
ran lint
waleedlatif1 490de05
update mock
waleedlatif1 f185b6b
upgrade turborepo
waleedlatif1 e96b847
fix(confluence): reject empty update body for space PUT
waleedlatif1 04461de
fix(confluence): remove spaceId requirement for create_space and fix …
waleedlatif1 696547c
ran lint
waleedlatif1 cc6c1d8
fixed type errors
waleedlatif1 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
107 changes: 107 additions & 0 deletions
107
apps/sim/app/api/tools/confluence/page-descendants/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,107 @@ | ||
| 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('ConfluencePageDescendantsAPI') | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| /** | ||
| * Get all descendants of a Confluence page recursively. | ||
| * Uses GET /wiki/api/v2/pages/{id}/descendants | ||
| */ | ||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const auth = await checkSessionOrInternalAuth(request) | ||
| if (!auth.success || !auth.userId) { | ||
| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const body = await request.json() | ||
| const { domain, accessToken, pageId, cloudId: providedCloudId, limit = 50, cursor } = body | ||
|
|
||
| if (!domain) { | ||
| return NextResponse.json({ error: 'Domain is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
| return NextResponse.json({ error: 'Access token is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!pageId) { | ||
| return NextResponse.json({ error: 'Page ID is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const pageIdValidation = validateAlphanumericId(pageId, 'pageId', 255) | ||
| if (!pageIdValidation.isValid) { | ||
| return NextResponse.json({ error: pageIdValidation.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(limit, 250))) | ||
|
|
||
| if (cursor) { | ||
| queryParams.append('cursor', cursor) | ||
| } | ||
|
|
||
| const url = `https://api.atlassian.com/ex/confluence/${cloudId}/wiki/api/v2/pages/${pageId}/descendants?${queryParams.toString()}` | ||
|
|
||
| logger.info(`Fetching descendants for page ${pageId}`) | ||
|
|
||
| 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 page descendants (${response.status})` | ||
| return NextResponse.json({ error: errorMessage }, { status: response.status }) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| const descendants = (data.results || []).map((page: any) => ({ | ||
| id: page.id, | ||
| title: page.title, | ||
| type: page.type ?? null, | ||
| status: page.status ?? null, | ||
| spaceId: page.spaceId ?? null, | ||
| parentId: page.parentId ?? null, | ||
| childPosition: page.childPosition ?? null, | ||
| depth: page.depth ?? null, | ||
| })) | ||
|
|
||
| return NextResponse.json({ | ||
| descendants, | ||
| pageId, | ||
| nextCursor: data._links?.next | ||
| ? new URL(data._links.next, 'https://placeholder').searchParams.get('cursor') | ||
| : null, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error getting page descendants:', error) | ||
| return NextResponse.json( | ||
| { error: (error as Error).message || 'Internal server error' }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
apps/sim/app/api/tools/confluence/space-permissions/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,106 @@ | ||
| 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('ConfluenceSpacePermissionsAPI') | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| /** | ||
| * List permissions for a Confluence space. | ||
| * Uses GET /wiki/api/v2/spaces/{id}/permissions | ||
| */ | ||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const auth = await checkSessionOrInternalAuth(request) | ||
| if (!auth.success || !auth.userId) { | ||
| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const body = await request.json() | ||
| const { domain, accessToken, spaceId, cloudId: providedCloudId, limit = 50, cursor } = body | ||
|
|
||
| if (!domain) { | ||
| return NextResponse.json({ error: 'Domain is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
| return NextResponse.json({ error: 'Access token is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!spaceId) { | ||
| return NextResponse.json({ error: 'Space ID is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const spaceIdValidation = validateAlphanumericId(spaceId, 'spaceId', 255) | ||
| if (!spaceIdValidation.isValid) { | ||
| return NextResponse.json({ error: spaceIdValidation.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(limit, 250))) | ||
|
|
||
| if (cursor) { | ||
| queryParams.append('cursor', cursor) | ||
| } | ||
|
|
||
| const url = `https://api.atlassian.com/ex/confluence/${cloudId}/wiki/api/v2/spaces/${spaceId}/permissions?${queryParams.toString()}` | ||
|
|
||
| logger.info(`Fetching permissions for space ${spaceId}`) | ||
|
|
||
| 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 list space permissions (${response.status})` | ||
| return NextResponse.json({ error: errorMessage }, { status: response.status }) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| const permissions = (data.results || []).map((perm: any) => ({ | ||
| id: perm.id, | ||
| principalType: perm.principal?.type ?? null, | ||
| principalId: perm.principal?.id ?? null, | ||
| operationKey: perm.operation?.key ?? null, | ||
| operationTargetType: perm.operation?.targetType ?? null, | ||
| anonymousAccess: perm.anonymousAccess ?? false, | ||
| unlicensedAccess: perm.unlicensedAccess ?? false, | ||
| })) | ||
|
|
||
| return NextResponse.json({ | ||
| permissions, | ||
| spaceId, | ||
| nextCursor: data._links?.next | ||
| ? new URL(data._links.next, 'https://placeholder').searchParams.get('cursor') | ||
| : null, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error listing space permissions:', error) | ||
| return NextResponse.json( | ||
| { error: (error as Error).message || 'Internal server error' }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
| } |
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.