-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.d.ts
53 lines (46 loc) · 1.94 KB
/
plugin.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/// <reference types="node" />
import { FastifyInstance, FastifyPluginAsync, FastifyReply, FastifyRequest } from 'fastify'
import {
ContextConfigDefault,
RawReplyDefaultExpression,
RawRequestDefaultExpression,
RawServerBase,
RawServerDefault
} from 'fastify/types/utils'
import { RouteGenericInterface } from 'fastify/types/route'
declare module 'fastify' {
interface RouteShorthandOptions<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault
> {
casbin?: {
rest?: boolean | {
getSub?: ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>) => string) | string,
getDom?: ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>) => string) | string,
getObj?: ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>) => string) | string,
getAct?: ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>) => string) | string
}
}
}
}
export type Hook =
| 'onRequest'
| 'preParsing'
| 'preValidation'
| 'preHandler'
export type Permission = { sub: string, dom?: string, obj: string, act: string }
export interface FastifyCasbinRestOptions {
getSub?(request: FastifyRequest): string
getDom?(request: FastifyRequest): string
getObj?(request: FastifyRequest): string
getAct?(request: FastifyRequest): string
onDeny?(reply: FastifyReply, checkParams: Permission): void
onAllow?(reply: FastifyReply, checkParams: Permission): void
log?(fastify: FastifyInstance, request: FastifyRequest, checkParams: Permission ): void
hook?: Hook
}
declare const fastifyCasbinRest: FastifyPluginAsync<FastifyCasbinRestOptions>
export default fastifyCasbinRest