UNPKG

permix

Version:

Permix is a lightweight, framework-agnostic, type-safe permissions management library for JavaScript applications on the client and server sides.

29 lines (26 loc) 1.4 kB
import { FastifyRequest, FastifyReply, FastifyPluginAsync, RouteHandler } from 'fastify'; import { P as PermixDefinition, C as CheckContext, e as PermixRules, h as CheckFunctionParams, a as Permix } from '../shared/permix.CuefdCK4.js'; import { M as MaybePromise } from '../shared/permix.BDsgFWDK.js'; interface MiddlewareContext { request: FastifyRequest; reply: FastifyReply; } interface PermixOptions<T extends PermixDefinition> { /** * Custom error handler */ onForbidden?: (params: CheckContext<T> & MiddlewareContext) => MaybePromise<void>; } /** * Create a middleware function that checks permissions for Fastify routes. * * @link https://permix.letstri.dev/docs/integrations/fastify */ declare function createPermix<Definition extends PermixDefinition>({ onForbidden, }?: PermixOptions<Definition>): { plugin: (callback: (context: MiddlewareContext) => MaybePromise<PermixRules<Definition>>) => FastifyPluginAsync; checkHandler: <K extends keyof Definition>(...params: CheckFunctionParams<Definition, K>) => RouteHandler; template: <T = void>(rules: PermixRules<Definition> | ((param: T) => PermixRules<Definition>)) => (param: T) => PermixRules<Definition>; get: (request: FastifyRequest, reply: FastifyReply) => Pick<Permix<Definition>, "check" | "dehydrate">; }; export { createPermix }; export type { MiddlewareContext, PermixOptions };