Skip to content

@vperms/hono

interface VPermsVariables {
ability: RequestAbility;
subject: Subject | undefined;
kind: SubjectType | undefined;
}
interface VPermsEnv {
Variables: VPermsVariables;
}
type VPermsContext = Context<VPermsEnv>;
interface VpermsMiddlewareOptions {
adapter: VeguiPermsAdapter;
resolver: SubjectResolver;
workspace: string | WorkspaceResolver;
defaultParents?: DefaultParents;
permissionsExport?: PermissionsExportOptions;
}
type SubjectResolverResult = SubjectId | Principal | null;
type SubjectResolver =
(c: VPermsContext) => SubjectResolverResult | Promise<SubjectResolverResult>;
type WorkspaceResolver =
(c: VPermsContext) => string | Promise<string>;
interface PermissionsExportOptions {
path: string;
}
function vpermsMiddleware(
options: VpermsMiddlewareOptions,
): MiddlewareHandler<VPermsEnv>;

Sets ability, subject and kind on the context, serves the export endpoint when configured, otherwise calls await next().

type PermissionBuilder = (
c: VPermsContext,
) => string | Promise<string>;
type PermissionInput = string | PermissionBuilder;
function hasPermission(...inputs: PermissionInput[]): MiddlewareHandler; // ALL
function hasAnyPermission(...inputs: PermissionInput[]): MiddlewareHandler; // ANY

Both return c.body(null, 403) when denied.

RequestAbility (alias of the vperms request Ability), ANONYMOUS_SUBJECT_ID.