()
| 69 | } |
| 70 | |
| 71 | const resolveCloudId = async () => { |
| 72 | if (params?.cloudId) return params.cloudId |
| 73 | const accessibleResources = await response.json() |
| 74 | if (!Array.isArray(accessibleResources) || accessibleResources.length === 0) { |
| 75 | throw new Error('No Jira resources found') |
| 76 | } |
| 77 | const normalizedInput = normalizeDomain(params?.domain ?? '') |
| 78 | const matchedResource = accessibleResources.find( |
| 79 | (r: { url: string }) => r.url.toLowerCase().replace(/\/+$/, '') === normalizedInput |
| 80 | ) |
| 81 | if (matchedResource) return matchedResource.id |
| 82 | if (accessibleResources.length === 1) return accessibleResources[0].id |
| 83 | throw new Error( |
| 84 | `Could not match Jira domain "${params?.domain}" to any accessible resource. ` + |
| 85 | `Available sites: ${accessibleResources.map((r: { url: string }) => r.url).join(', ')}` |
| 86 | ) |
| 87 | } |
| 88 | |
| 89 | const cloudId = await resolveCloudId() |
| 90 | const projectKey = await resolveProjectKey(cloudId, params!.accessToken, params!.projectId) |
no test coverage detected