import type { Context } from 'hono' import type * as App from '../../App.js' import type * as FundingTransfers from '../../db/tables/fundingTransfers.js' import * as Auth from '../../internal/Auth.js' import * as Response from '../../internal/Response.js' /** Returns the funding owner encoded by an API-key principal. */ export function owner(c: Context): FundingTransfers.Owner | null { const principal = Auth.getPrincipal(c) if (principal?.type !== 'api_key') return null return { environment: principal.environment, orgId: principal.orgId, projectId: principal.projectId, } } /** Returns the error used when a funding resource has no API-key owner. */ export function unauthorized(c: Context) { return Response.error(c, { code: 'unauthorized', message: 'Tempo could not determine which organization owns this funding resource.', status: 401, }) }