feat(research): retain immutable strategy versions and review history
This commit is contained in:
parent
b106c1ca85
commit
4a2e5ad362
36 changed files with 3236 additions and 148 deletions
|
|
@ -3,11 +3,16 @@ import type { Hono, MiddlewareHandler } from 'hono';
|
|||
|
||||
type Role = 'read' | 'admin' | 'service';
|
||||
const verifiedPrincipals = new WeakMap<Request, 'operator' | 'service'>();
|
||||
const credentialRequests = new WeakSet<Request>();
|
||||
|
||||
/** Server-owned identity established only after successful HTTP authorization. */
|
||||
export function getVerifiedHttpPrincipal(request: Request): 'operator' | 'service' | undefined {
|
||||
return verifiedPrincipals.get(request);
|
||||
}
|
||||
/** Catalog authorship/review needs a credential, not the loopback development bypass. */
|
||||
export function getCredentialHttpPrincipal(request: Request): 'operator' | 'service' | undefined {
|
||||
return credentialRequests.has(request) ? verifiedPrincipals.get(request) : undefined;
|
||||
}
|
||||
export interface HttpSecurityOptions {
|
||||
readToken?: string;
|
||||
adminToken?: string;
|
||||
|
|
@ -149,6 +154,7 @@ export function createHttpSecurity(options: HttpSecurityOptions = httpSecurityOp
|
|||
}
|
||||
function authorize(request: Request, admin = false): Response | undefined {
|
||||
verifiedPrincipals.delete(request);
|
||||
credentialRequests.delete(request);
|
||||
const identity = authenticate(request);
|
||||
if (!identity) {
|
||||
return Response.json(
|
||||
|
|
@ -170,6 +176,9 @@ export function createHttpSecurity(options: HttpSecurityOptions = httpSecurityOp
|
|||
}
|
||||
if (identity.role !== 'read') {
|
||||
verifiedPrincipals.set(request, identity.role === 'service' ? 'service' : 'operator');
|
||||
if (!disabled) {
|
||||
credentialRequests.add(request);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue