mirror of
https://github.com/saltbo/zpan.git
synced 2026-09-21 13:20:33 +08:00
* fix(audit): resolve agent api key and device actors * fix(deps): address high severity advisories * test(audit): cover actor identity boundaries * fix(audit): support Cloudflare agent info fetches * docs: add audit actor preview evidence * docs: add api key audit preview evidence
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import type { RecordAuditEventInput } from '../usecases/ports'
|
|
import type { AuthPrincipal } from './platform'
|
|
|
|
export type AuditActor = Pick<RecordAuditEventInput, 'userId' | 'actorType' | 'actorRef' | 'actorIssuer'>
|
|
|
|
export function auditActor(principal: AuthPrincipal | null): AuditActor {
|
|
if (!principal) return { userId: null, actorType: 'anonymous', actorRef: null, actorIssuer: null }
|
|
if (principal.kind === 'user') {
|
|
return { userId: principal.userId, actorType: 'user', actorRef: null, actorIssuer: null }
|
|
}
|
|
if (principal.kind === 'api-key') {
|
|
return { userId: principal.userId, actorType: 'api_key', actorRef: principal.keyId, actorIssuer: null }
|
|
}
|
|
if (principal.kind === 'oauth') {
|
|
return {
|
|
userId: principal.userId,
|
|
actorType: 'oauth',
|
|
actorRef: principal.actorSubject,
|
|
actorIssuer: principal.actorIssuer,
|
|
}
|
|
}
|
|
if (principal.kind === 'downloader') {
|
|
return { userId: null, actorType: 'device', actorRef: principal.downloaderId, actorIssuer: null }
|
|
}
|
|
if (principal.kind === 'downloader-bootstrap') {
|
|
return { userId: principal.userId, actorType: 'user', actorRef: null, actorIssuer: null }
|
|
}
|
|
return {
|
|
userId: principal.createdByUserId,
|
|
actorType: 'device',
|
|
actorRef: principal.downloaderId,
|
|
actorIssuer: null,
|
|
}
|
|
}
|