mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-10 22:55:16 -05:00
* improvement(jsm): destructured outputs for jsm, jira, and added 1password integration * update 1password to support cloud & locally hosted * updated & tested 1pass * added an additional wandConfig for OnePassword & jira search issues * finished jira * removed unused route * updated types * restore old outputs * updated types
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
/**
|
|
* Extracts plain text from Atlassian Document Format (ADF) content.
|
|
* Returns null if content is falsy.
|
|
*/
|
|
export function extractAdfText(content: any): string | null {
|
|
if (!content) return null
|
|
if (typeof content === 'string') return content
|
|
if (Array.isArray(content)) {
|
|
return content.map(extractAdfText).filter(Boolean).join(' ')
|
|
}
|
|
if (content.type === 'text') return content.text || ''
|
|
if (content.content) return extractAdfText(content.content)
|
|
return ''
|
|
}
|
|
|
|
/**
|
|
* Transforms a raw Jira API user object into a typed user output.
|
|
* Returns null if user data is falsy.
|
|
*/
|
|
export function transformUser(user: any): {
|
|
accountId: string
|
|
displayName: string
|
|
active?: boolean
|
|
emailAddress?: string
|
|
avatarUrl?: string
|
|
accountType?: string
|
|
timeZone?: string
|
|
} | null {
|
|
if (!user) return null
|
|
return {
|
|
accountId: user.accountId ?? '',
|
|
displayName: user.displayName ?? '',
|
|
active: user.active ?? null,
|
|
emailAddress: user.emailAddress ?? null,
|
|
avatarUrl: user.avatarUrls?.['48x48'] ?? null,
|
|
accountType: user.accountType ?? null,
|
|
timeZone: user.timeZone ?? null,
|
|
}
|
|
}
|
|
|
|
export async function getJiraCloudId(domain: string, accessToken: string): Promise<string> {
|
|
const response = await fetch('https://api.atlassian.com/oauth/token/accessible-resources', {
|
|
method: 'GET',
|
|
headers: {
|
|
Authorization: `Bearer ${accessToken}`,
|
|
Accept: 'application/json',
|
|
},
|
|
})
|
|
|
|
const resources = await response.json()
|
|
|
|
// If we have resources, find the matching one
|
|
if (Array.isArray(resources) && resources.length > 0) {
|
|
const normalizedInput = `https://${domain}`.toLowerCase()
|
|
const matchedResource = resources.find((r) => r.url.toLowerCase() === normalizedInput)
|
|
|
|
if (matchedResource) {
|
|
return matchedResource.id
|
|
}
|
|
}
|
|
|
|
// If we couldn't find a match, return the first resource's ID
|
|
// This is a fallback in case the URL matching fails
|
|
if (Array.isArray(resources) && resources.length > 0) {
|
|
return resources[0].id
|
|
}
|
|
|
|
throw new Error('No Jira resources found')
|
|
}
|