@becomes/cms-cloud-client
Version:
SDK for accessing BCMS Cloud API
44 lines (43 loc) • 1.91 kB
TypeScript
import { JWTPermissionName, JWTRoleName } from '@becomes/purple-cheetah-mod-jwt/types';
import { ControllerMethodPreRequestHandler, HTTPError, ObjectSchema } from '@becomes/purple-cheetah/types';
import type { UserJwt } from './user';
export interface RouteProtectionJwtConfig {
roles?: JWTRoleName[];
permission: JWTPermissionName;
instanceRoles?: JWTRoleName[];
admin?: boolean;
}
export interface RouteProtectionJwtAndBodyConfig extends RouteProtectionJwtConfig {
schema: ObjectSchema;
}
export interface RouteProtectionJwtResult {
token: UserJwt;
}
export interface RouteProtectionBodyCheckResult<Body> {
body: Body;
}
export type RouteProtectionJwtAndBodyCheckResult<Body> = RouteProtectionJwtResult & RouteProtectionBodyCheckResult<Body>;
export interface RouteProtectionShimChannelCheckResult<Payload> {
instanceId: string;
payload: Payload;
}
export declare class RouteProtection {
static verifyAdminAccess(config: RouteProtectionJwtConfig & {
token: string;
errorHandler: HTTPError;
orgId?: string;
instanceId?: string;
}): UserJwt;
static verifyAccess(config: RouteProtectionJwtConfig & {
token: string;
errorHandler: HTTPError;
orgId?: string;
instanceId?: string;
}): UserJwt;
static createBodyCheck<Body = any>(schema: ObjectSchema): ControllerMethodPreRequestHandler<RouteProtectionBodyCheckResult<Body>>;
static createJwtCheck(config: RouteProtectionJwtConfig): ControllerMethodPreRequestHandler<RouteProtectionJwtResult>;
static createJwtAndBodyCheck<Body>(config: RouteProtectionJwtAndBodyConfig): ControllerMethodPreRequestHandler<RouteProtectionJwtAndBodyCheckResult<Body>>;
static createShimChannelCheck<Payload = any>(config: {
payloadSchema: ObjectSchema;
}): ControllerMethodPreRequestHandler<RouteProtectionShimChannelCheckResult<Payload>>;
}