export type SentryResource = 'event' | 'project' | 'org'
export function inferResource(path: string): SentryResource {
const normalizedPath = path.toLowerCase()
if (normalizedPath.includes('/issues') || normalizedPath.includes('/events')) return 'event'
if (normalizedPath.includes('/projects')) return 'project'
return 'org'
}
export function inferRequiredScope(method: string, path: string): string {
const normalizedMethod = method.toUpperCase()
const resource = inferResource(path)
switch (resource) {
case 'event':
if (normalizedMethod === 'GET' || normalizedMethod === 'HEAD') return 'event:read'
if (normalizedMethod === 'DELETE') return 'event:admin'
return 'event:write'
case 'project':
if (normalizedMethod === 'GET' || normalizedMethod === 'HEAD') return 'project:read'
if (normalizedMethod === 'DELETE') return 'project:admin'
return 'project:write'
case 'org':
if (normalizedMethod === 'GET' || normalizedMethod === 'HEAD') return 'org:read'
if (normalizedMethod === 'DELETE') return 'org:admin'
return 'org:write'
default: {
const exhaustive: never = resource
throw new Error('Unhandled Sentry resource: ' + String(exhaustive))
}
}
}