chore: import DH V2 D5.6.4 production baseline
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { Request } from 'express';
|
||||
|
||||
export type AuthTransport = 'cookie' | 'bearer';
|
||||
|
||||
export interface AuthPrincipal {
|
||||
userId: string;
|
||||
username: string;
|
||||
sessionId: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string | null;
|
||||
mustChangePassword: boolean;
|
||||
roles: string[];
|
||||
permissions: string[];
|
||||
transport: AuthTransport;
|
||||
}
|
||||
|
||||
export interface RequestWithContext extends Request {
|
||||
requestId: string;
|
||||
auth?: AuthPrincipal;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import type { NextFunction, Response } from 'express';
|
||||
import type { RequestWithContext } from './request-context';
|
||||
|
||||
const REQUEST_ID_PATTERN = /^[A-Za-z0-9._:-]{8,128}$/;
|
||||
|
||||
export function requestIdMiddleware(
|
||||
request: RequestWithContext,
|
||||
response: Response,
|
||||
next: NextFunction,
|
||||
): void {
|
||||
const supplied = request.header('x-request-id');
|
||||
request.requestId =
|
||||
supplied && REQUEST_ID_PATTERN.test(supplied) ? supplied : randomUUID();
|
||||
response.setHeader('X-Request-ID', request.requestId);
|
||||
next();
|
||||
}
|
||||
Reference in New Issue
Block a user