@lakutata/entrypoint 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +183 -0
- package/THIRD_PARTY_NOTICES.md +206 -0
- package/dist/cjs/Entrypoint.d.ts +868 -0
- package/dist/cjs/Entrypoint.js +998 -0
- package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
- package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.js +439 -0
- package/dist/cjs/adapter/commander/Prompt.d.ts +22 -0
- package/dist/cjs/adapter/commander/Prompt.js +164 -0
- package/dist/cjs/adapter/commander/Width.d.ts +12 -0
- package/dist/cjs/adapter/commander/Width.js +67 -0
- package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
- package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.js +249 -0
- package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
- package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.js +301 -0
- package/dist/cjs/adapter/express/Responders.d.ts +89 -0
- package/dist/cjs/adapter/express/Responders.js +71 -0
- package/dist/cjs/adapter/express/StaticUI.d.ts +83 -0
- package/dist/cjs/adapter/express/StaticUI.js +104 -0
- package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
- package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.js +339 -0
- package/dist/cjs/adapter/fastify/Responders.d.ts +88 -0
- package/dist/cjs/adapter/fastify/Responders.js +77 -0
- package/dist/cjs/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
- package/dist/cjs/adapter/http/HTTPServiceEntrypoint.js +257 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.js +187 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +397 -0
- package/dist/cjs/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
- package/dist/cjs/adapter/schedule/ScheduleEntrypoint.js +275 -0
- package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
- package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.js +216 -0
- package/dist/cjs/channel/BuiltinChannels.d.ts +18 -0
- package/dist/cjs/channel/BuiltinChannels.js +128 -0
- package/dist/cjs/channel/Channel.d.ts +196 -0
- package/dist/cjs/channel/Channel.js +106 -0
- package/dist/cjs/channel/EntrypointAdapter.d.ts +195 -0
- package/dist/cjs/channel/EntrypointAdapter.js +43 -0
- package/dist/cjs/context/BaseContext.d.ts +75 -0
- package/dist/cjs/context/BaseContext.js +90 -0
- package/dist/cjs/context/CLIContext.d.ts +38 -0
- package/dist/cjs/context/CLIContext.js +53 -0
- package/dist/cjs/context/HTTPContext.d.ts +52 -0
- package/dist/cjs/context/HTTPContext.js +78 -0
- package/dist/cjs/context/ScheduleContext.d.ts +47 -0
- package/dist/cjs/context/ScheduleContext.js +65 -0
- package/dist/cjs/context/ServiceContext.d.ts +47 -0
- package/dist/cjs/context/ServiceContext.js +62 -0
- package/dist/cjs/decorators/CLIAction.d.ts +120 -0
- package/dist/cjs/decorators/CLIAction.js +13 -0
- package/dist/cjs/decorators/HTTPAction.d.ts +178 -0
- package/dist/cjs/decorators/HTTPAction.js +14 -0
- package/dist/cjs/decorators/Prefix.d.ts +44 -0
- package/dist/cjs/decorators/Prefix.js +48 -0
- package/dist/cjs/decorators/Schedule.d.ts +120 -0
- package/dist/cjs/decorators/Schedule.js +64 -0
- package/dist/cjs/decorators/ServiceAction.d.ts +116 -0
- package/dist/cjs/decorators/ServiceAction.js +12 -0
- package/dist/cjs/decorators/UseMiddlewares.d.ts +52 -0
- package/dist/cjs/decorators/UseMiddlewares.js +58 -0
- package/dist/cjs/decorators/http/DELETE.d.ts +87 -0
- package/dist/cjs/decorators/http/DELETE.js +7 -0
- package/dist/cjs/decorators/http/GET.d.ts +89 -0
- package/dist/cjs/decorators/http/GET.js +7 -0
- package/dist/cjs/decorators/http/HEAD.d.ts +84 -0
- package/dist/cjs/decorators/http/HEAD.js +7 -0
- package/dist/cjs/decorators/http/OPTIONS.d.ts +80 -0
- package/dist/cjs/decorators/http/OPTIONS.js +7 -0
- package/dist/cjs/decorators/http/PATCH.d.ts +90 -0
- package/dist/cjs/decorators/http/PATCH.js +7 -0
- package/dist/cjs/decorators/http/POST.d.ts +91 -0
- package/dist/cjs/decorators/http/POST.js +7 -0
- package/dist/cjs/decorators/http/PUT.d.ts +92 -0
- package/dist/cjs/decorators/http/PUT.js +7 -0
- package/dist/cjs/exceptions/AccessDeniedException.d.ts +10 -0
- package/dist/cjs/exceptions/AccessDeniedException.js +17 -0
- package/dist/cjs/exceptions/ControllerActionNotFoundException.d.ts +9 -0
- package/dist/cjs/exceptions/ControllerActionNotFoundException.js +16 -0
- package/dist/cjs/exceptions/DuplicateActionNameException.d.ts +8 -0
- package/dist/cjs/exceptions/DuplicateActionNameException.js +15 -0
- package/dist/cjs/exceptions/EntrypointStoppedException.d.ts +9 -0
- package/dist/cjs/exceptions/EntrypointStoppedException.js +16 -0
- package/dist/cjs/exceptions/InvalidActionGroupException.d.ts +4 -0
- package/dist/cjs/exceptions/InvalidActionGroupException.js +11 -0
- package/dist/cjs/exceptions/InvalidChannelException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidChannelException.js +15 -0
- package/dist/cjs/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
- package/dist/cjs/exceptions/InvalidEntrypointAdapterException.js +16 -0
- package/dist/cjs/exceptions/InvalidMiddlewareException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidMiddlewareException.js +15 -0
- package/dist/cjs/exceptions/InvalidPrefixException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidPrefixException.js +15 -0
- package/dist/cjs/exceptions/MiddlewareNextCalledException.d.ts +8 -0
- package/dist/cjs/exceptions/MiddlewareNextCalledException.js +15 -0
- package/dist/cjs/exceptions/RouteNotFoundException.d.ts +9 -0
- package/dist/cjs/exceptions/RouteNotFoundException.js +16 -0
- package/dist/cjs/exceptions/ServiceInvokeException.d.ts +11 -0
- package/dist/cjs/exceptions/ServiceInvokeException.js +14 -0
- package/dist/cjs/exports/CTRLDecorators.d.ts +13 -0
- package/dist/cjs/exports/CTRLDecorators.js +38 -0
- package/dist/cjs/exports/Channel.d.ts +14 -0
- package/dist/cjs/exports/Channel.js +33 -0
- package/dist/cjs/exports/CommanderAdapter.d.ts +1 -0
- package/dist/cjs/exports/CommanderAdapter.js +8 -0
- package/dist/cjs/exports/ElectronAdapter.d.ts +1 -0
- package/dist/cjs/exports/ElectronAdapter.js +9 -0
- package/dist/cjs/exports/Entrypoint.d.ts +24 -0
- package/dist/cjs/exports/Entrypoint.js +55 -0
- package/dist/cjs/exports/ExpressAdapter.d.ts +4 -0
- package/dist/cjs/exports/ExpressAdapter.js +15 -0
- package/dist/cjs/exports/FastifyAdapter.d.ts +4 -0
- package/dist/cjs/exports/FastifyAdapter.js +14 -0
- package/dist/cjs/exports/JSONRPCAdapter.d.ts +2 -0
- package/dist/cjs/exports/JSONRPCAdapter.js +11 -0
- package/dist/cjs/exports/SocketIOAdapter.d.ts +1 -0
- package/dist/cjs/exports/SocketIOAdapter.js +9 -0
- package/dist/cjs/lib/AccessControl.d.ts +118 -0
- package/dist/cjs/lib/AccessControl.js +208 -0
- package/dist/cjs/lib/AccessControlRule.d.ts +91 -0
- package/dist/cjs/lib/AccessControlRule.js +76 -0
- package/dist/cjs/lib/ActionOptions.d.ts +67 -0
- package/dist/cjs/lib/ActionOptions.js +67 -0
- package/dist/cjs/lib/ActionResult.d.ts +28 -0
- package/dist/cjs/lib/ActionResult.js +28 -0
- package/dist/cjs/lib/ApplicationOf.d.ts +6 -0
- package/dist/cjs/lib/ApplicationOf.js +14 -0
- package/dist/cjs/lib/Controller.d.ts +59 -0
- package/dist/cjs/lib/Controller.js +64 -0
- package/dist/cjs/lib/ControllerEntrypoint.d.ts +168 -0
- package/dist/cjs/lib/ControllerEntrypoint.js +239 -0
- package/dist/cjs/lib/GetActionDTOAndOptions.d.ts +29 -0
- package/dist/cjs/lib/GetActionDTOAndOptions.js +49 -0
- package/dist/cjs/lib/HTTPErrors.d.ts +55 -0
- package/dist/cjs/lib/HTTPErrors.js +52 -0
- package/dist/cjs/lib/Middleware.d.ts +146 -0
- package/dist/cjs/lib/Middleware.js +144 -0
- package/dist/cjs/lib/Prefix.d.ts +98 -0
- package/dist/cjs/lib/Prefix.js +151 -0
- package/dist/cjs/lib/Result.d.ts +173 -0
- package/dist/cjs/lib/Result.js +153 -0
- package/dist/cjs/lib/ServiceResponseCodec.d.ts +82 -0
- package/dist/cjs/lib/ServiceResponseCodec.js +117 -0
- package/dist/cjs/lib/StringifyPattern.d.ts +7 -0
- package/dist/cjs/lib/StringifyPattern.js +58 -0
- package/dist/cjs/lib/UnsetValue.d.ts +12 -0
- package/dist/cjs/lib/UnsetValue.js +216 -0
- package/dist/cjs/lib/pattern/GlobPattern.d.ts +34 -0
- package/dist/cjs/lib/pattern/GlobPattern.js +68 -0
- package/dist/cjs/lib/pattern/PatternManager.d.ts +103 -0
- package/dist/cjs/lib/pattern/PatternManager.js +233 -0
- package/dist/cjs/lib/schedule/Cron.d.ts +56 -0
- package/dist/cjs/lib/schedule/Cron.js +282 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/CLIContextParams.d.ts +14 -0
- package/dist/cjs/types/CLIContextParams.js +2 -0
- package/dist/cjs/types/ErrorDescription.d.ts +14 -0
- package/dist/cjs/types/ErrorDescription.js +2 -0
- package/dist/cjs/types/HTTPContextParams.d.ts +27 -0
- package/dist/cjs/types/HTTPContextParams.js +2 -0
- package/dist/cjs/types/ScheduleContextParams.d.ts +21 -0
- package/dist/cjs/types/ScheduleContextParams.js +2 -0
- package/dist/cjs/types/ServiceContextParams.d.ts +16 -0
- package/dist/cjs/types/ServiceContextParams.js +2 -0
- package/dist/esm/Entrypoint.js +985 -0
- package/dist/esm/adapter/commander/CommanderCLIEntrypoint.js +433 -0
- package/dist/esm/adapter/commander/Prompt.js +127 -0
- package/dist/esm/adapter/commander/Width.js +63 -0
- package/dist/esm/adapter/electron/ElectronIPCServiceEntrypoint.js +212 -0
- package/dist/esm/adapter/express/ExpressHTTPEntrypoint.js +295 -0
- package/dist/esm/adapter/express/Responders.js +66 -0
- package/dist/esm/adapter/express/StaticUI.js +96 -0
- package/dist/esm/adapter/fastify/FastifyHTTPEntrypoint.js +333 -0
- package/dist/esm/adapter/fastify/Responders.js +73 -0
- package/dist/esm/adapter/http/HTTPServiceEntrypoint.js +253 -0
- package/dist/esm/adapter/jsonrpc/JSONRPCProtocol.js +182 -0
- package/dist/esm/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +361 -0
- package/dist/esm/adapter/schedule/ScheduleEntrypoint.js +272 -0
- package/dist/esm/adapter/socket.io/SocketIOServiceEntrypoint.js +212 -0
- package/dist/esm/channel/BuiltinChannels.js +125 -0
- package/dist/esm/channel/Channel.js +100 -0
- package/dist/esm/channel/EntrypointAdapter.js +39 -0
- package/dist/esm/context/BaseContext.js +87 -0
- package/dist/esm/context/CLIContext.js +49 -0
- package/dist/esm/context/HTTPContext.js +74 -0
- package/dist/esm/context/ScheduleContext.js +61 -0
- package/dist/esm/context/ServiceContext.js +58 -0
- package/dist/esm/decorators/CLIAction.js +10 -0
- package/dist/esm/decorators/HTTPAction.js +11 -0
- package/dist/esm/decorators/Prefix.js +45 -0
- package/dist/esm/decorators/Schedule.js +61 -0
- package/dist/esm/decorators/ServiceAction.js +9 -0
- package/dist/esm/decorators/UseMiddlewares.js +55 -0
- package/dist/esm/decorators/http/DELETE.js +4 -0
- package/dist/esm/decorators/http/GET.js +4 -0
- package/dist/esm/decorators/http/HEAD.js +4 -0
- package/dist/esm/decorators/http/OPTIONS.js +4 -0
- package/dist/esm/decorators/http/PATCH.js +4 -0
- package/dist/esm/decorators/http/POST.js +4 -0
- package/dist/esm/decorators/http/PUT.js +4 -0
- package/dist/esm/exceptions/AccessDeniedException.js +13 -0
- package/dist/esm/exceptions/ControllerActionNotFoundException.js +12 -0
- package/dist/esm/exceptions/DuplicateActionNameException.js +11 -0
- package/dist/esm/exceptions/EntrypointStoppedException.js +12 -0
- package/dist/esm/exceptions/InvalidActionGroupException.js +7 -0
- package/dist/esm/exceptions/InvalidChannelException.js +11 -0
- package/dist/esm/exceptions/InvalidEntrypointAdapterException.js +12 -0
- package/dist/esm/exceptions/InvalidMiddlewareException.js +11 -0
- package/dist/esm/exceptions/InvalidPrefixException.js +11 -0
- package/dist/esm/exceptions/MiddlewareNextCalledException.js +11 -0
- package/dist/esm/exceptions/RouteNotFoundException.js +12 -0
- package/dist/esm/exceptions/ServiceInvokeException.js +10 -0
- package/dist/esm/exports/CTRLDecorators.js +19 -0
- package/dist/esm/exports/Channel.js +11 -0
- package/dist/esm/exports/CommanderAdapter.js +1 -0
- package/dist/esm/exports/ElectronAdapter.js +1 -0
- package/dist/esm/exports/Entrypoint.js +22 -0
- package/dist/esm/exports/ExpressAdapter.js +3 -0
- package/dist/esm/exports/FastifyAdapter.js +3 -0
- package/dist/esm/exports/JSONRPCAdapter.js +2 -0
- package/dist/esm/exports/SocketIOAdapter.js +1 -0
- package/dist/esm/lib/AccessControl.js +204 -0
- package/dist/esm/lib/AccessControlRule.js +72 -0
- package/dist/esm/lib/ActionOptions.js +63 -0
- package/dist/esm/lib/ActionResult.js +24 -0
- package/dist/esm/lib/ApplicationOf.js +11 -0
- package/dist/esm/lib/Controller.js +61 -0
- package/dist/esm/lib/ControllerEntrypoint.js +229 -0
- package/dist/esm/lib/GetActionDTOAndOptions.js +46 -0
- package/dist/esm/lib/HTTPErrors.js +48 -0
- package/dist/esm/lib/Middleware.js +134 -0
- package/dist/esm/lib/Prefix.js +143 -0
- package/dist/esm/lib/Result.js +147 -0
- package/dist/esm/lib/ServiceResponseCodec.js +113 -0
- package/dist/esm/lib/StringifyPattern.js +55 -0
- package/dist/esm/lib/UnsetValue.js +213 -0
- package/dist/esm/lib/pattern/GlobPattern.js +64 -0
- package/dist/esm/lib/pattern/PatternManager.js +229 -0
- package/dist/esm/lib/schedule/Cron.js +277 -0
- package/dist/esm/types/CLIContextParams.js +1 -0
- package/dist/esm/types/ErrorDescription.js +1 -0
- package/dist/esm/types/HTTPContextParams.js +1 -0
- package/dist/esm/types/ScheduleContextParams.js +1 -0
- package/dist/esm/types/ServiceContextParams.js +1 -0
- package/dist/types/Entrypoint.d.ts +868 -0
- package/dist/types/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
- package/dist/types/adapter/commander/Prompt.d.ts +22 -0
- package/dist/types/adapter/commander/Width.d.ts +12 -0
- package/dist/types/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
- package/dist/types/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
- package/dist/types/adapter/express/Responders.d.ts +89 -0
- package/dist/types/adapter/express/StaticUI.d.ts +83 -0
- package/dist/types/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
- package/dist/types/adapter/fastify/Responders.d.ts +88 -0
- package/dist/types/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
- package/dist/types/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
- package/dist/types/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
- package/dist/types/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
- package/dist/types/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
- package/dist/types/channel/BuiltinChannels.d.ts +18 -0
- package/dist/types/channel/Channel.d.ts +196 -0
- package/dist/types/channel/EntrypointAdapter.d.ts +195 -0
- package/dist/types/context/BaseContext.d.ts +75 -0
- package/dist/types/context/CLIContext.d.ts +38 -0
- package/dist/types/context/HTTPContext.d.ts +52 -0
- package/dist/types/context/ScheduleContext.d.ts +47 -0
- package/dist/types/context/ServiceContext.d.ts +47 -0
- package/dist/types/decorators/CLIAction.d.ts +120 -0
- package/dist/types/decorators/HTTPAction.d.ts +178 -0
- package/dist/types/decorators/Prefix.d.ts +44 -0
- package/dist/types/decorators/Schedule.d.ts +120 -0
- package/dist/types/decorators/ServiceAction.d.ts +116 -0
- package/dist/types/decorators/UseMiddlewares.d.ts +52 -0
- package/dist/types/decorators/http/DELETE.d.ts +87 -0
- package/dist/types/decorators/http/GET.d.ts +89 -0
- package/dist/types/decorators/http/HEAD.d.ts +84 -0
- package/dist/types/decorators/http/OPTIONS.d.ts +80 -0
- package/dist/types/decorators/http/PATCH.d.ts +90 -0
- package/dist/types/decorators/http/POST.d.ts +91 -0
- package/dist/types/decorators/http/PUT.d.ts +92 -0
- package/dist/types/exceptions/AccessDeniedException.d.ts +10 -0
- package/dist/types/exceptions/ControllerActionNotFoundException.d.ts +9 -0
- package/dist/types/exceptions/DuplicateActionNameException.d.ts +8 -0
- package/dist/types/exceptions/EntrypointStoppedException.d.ts +9 -0
- package/dist/types/exceptions/InvalidActionGroupException.d.ts +4 -0
- package/dist/types/exceptions/InvalidChannelException.d.ts +8 -0
- package/dist/types/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
- package/dist/types/exceptions/InvalidMiddlewareException.d.ts +8 -0
- package/dist/types/exceptions/InvalidPrefixException.d.ts +8 -0
- package/dist/types/exceptions/MiddlewareNextCalledException.d.ts +8 -0
- package/dist/types/exceptions/RouteNotFoundException.d.ts +9 -0
- package/dist/types/exceptions/ServiceInvokeException.d.ts +11 -0
- package/dist/types/exports/CTRLDecorators.d.ts +13 -0
- package/dist/types/exports/Channel.d.ts +14 -0
- package/dist/types/exports/CommanderAdapter.d.ts +1 -0
- package/dist/types/exports/ElectronAdapter.d.ts +1 -0
- package/dist/types/exports/Entrypoint.d.ts +24 -0
- package/dist/types/exports/ExpressAdapter.d.ts +4 -0
- package/dist/types/exports/FastifyAdapter.d.ts +4 -0
- package/dist/types/exports/JSONRPCAdapter.d.ts +2 -0
- package/dist/types/exports/SocketIOAdapter.d.ts +1 -0
- package/dist/types/lib/AccessControl.d.ts +118 -0
- package/dist/types/lib/AccessControlRule.d.ts +91 -0
- package/dist/types/lib/ActionOptions.d.ts +67 -0
- package/dist/types/lib/ActionResult.d.ts +28 -0
- package/dist/types/lib/ApplicationOf.d.ts +6 -0
- package/dist/types/lib/Controller.d.ts +59 -0
- package/dist/types/lib/ControllerEntrypoint.d.ts +168 -0
- package/dist/types/lib/GetActionDTOAndOptions.d.ts +29 -0
- package/dist/types/lib/HTTPErrors.d.ts +55 -0
- package/dist/types/lib/Middleware.d.ts +146 -0
- package/dist/types/lib/Prefix.d.ts +98 -0
- package/dist/types/lib/Result.d.ts +173 -0
- package/dist/types/lib/ServiceResponseCodec.d.ts +82 -0
- package/dist/types/lib/StringifyPattern.d.ts +7 -0
- package/dist/types/lib/UnsetValue.d.ts +12 -0
- package/dist/types/lib/pattern/GlobPattern.d.ts +34 -0
- package/dist/types/lib/pattern/PatternManager.d.ts +103 -0
- package/dist/types/lib/schedule/Cron.d.ts +56 -0
- package/dist/types/types/CLIContextParams.d.ts +14 -0
- package/dist/types/types/ErrorDescription.d.ts +14 -0
- package/dist/types/types/HTTPContextParams.d.ts +27 -0
- package/dist/types/types/ScheduleContextParams.d.ts +21 -0
- package/dist/types/types/ServiceContextParams.d.ts +16 -0
- package/package.json +152 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { addMiddlewares, validateMiddlewares } from '../lib/Middleware.js';
|
|
2
|
+
/**
|
|
3
|
+
* Add middlewares to all the actions of a controller (on the class) or to one action (on the method). A middleware is a
|
|
4
|
+
* function `(invocation, next) => Promise<unknown>` or a class extending `Middleware`, created in the container of each
|
|
5
|
+
* request (its dependencies injected). It receives the request's context, whose data is the input before validation,
|
|
6
|
+
* and returns the result of `next()` (the rest of the pipeline), or another value without calling it, which is then
|
|
7
|
+
* answered instead of the action's result; an error it throws is answered as the action's error.
|
|
8
|
+
*
|
|
9
|
+
* The order of a request: the entrypoint's `middlewares`, the adapter's `middlewares`, the ones of the controller classes
|
|
10
|
+
* (the parent classes first), of the action options, of the action method, then the input validation, the access
|
|
11
|
+
* control and the action. Several `@UseMiddlewares` on a target run from top to bottom, the middlewares of each in their
|
|
12
|
+
* order. The middlewares of a method are taken from the nearest class declaring them for it: an overriding method
|
|
13
|
+
* replaces them.
|
|
14
|
+
* @param middlewares The middleware functions and classes, in their running order.
|
|
15
|
+
* @returns The class or method decorator.
|
|
16
|
+
* @throws {InvalidMiddlewareException} When the decorator is called, if a middleware is neither a function nor a class
|
|
17
|
+
* extending `Middleware`.
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {Controller, Middleware, type ActionInvocation, type Next} from 'lakutata/com/entrypoint'
|
|
21
|
+
* import {GET, UseMiddlewares} from 'lakutata/decorator/ctrl'
|
|
22
|
+
*
|
|
23
|
+
* //A middleware function: logs the duration of each action of the controller
|
|
24
|
+
* async function Timing(invocation: ActionInvocation, next: Next): Promise<unknown> {
|
|
25
|
+
* const started: number = Date.now()
|
|
26
|
+
* try {
|
|
27
|
+
* return await next()
|
|
28
|
+
* } finally {
|
|
29
|
+
* console.log(`${invocation.action.name}: ${Date.now() - started}ms`)
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* //A middleware class: answers without running the action during a maintenance
|
|
34
|
+
* class Maintenance extends Middleware {
|
|
35
|
+
* public async handle(invocation: ActionInvocation, next: Next): Promise<unknown> {
|
|
36
|
+
* if (process.env.MAINTENANCE) return {maintenance: true}
|
|
37
|
+
* return await next()
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* @UseMiddlewares(Timing)
|
|
42
|
+
* class StatusController extends Controller {
|
|
43
|
+
* //Timing, then Maintenance, then the action
|
|
44
|
+
* @GET('/status')
|
|
45
|
+
* @UseMiddlewares(Maintenance)
|
|
46
|
+
* public async status(): Promise<{ ok: boolean }> {
|
|
47
|
+
* return {ok: true}
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function UseMiddlewares(...middlewares) {
|
|
53
|
+
validateMiddlewares(middlewares);
|
|
54
|
+
return (target, propertyKey) => addMiddlewares(target, propertyKey, middlewares);
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* An access control rule denied the request: a rule of the entrypoint (`rules`) or of the action resolved `false`.
|
|
4
|
+
* Its errno is `E_ACCESS_DENY`, its HTTP status 403.
|
|
5
|
+
*/
|
|
6
|
+
export class AccessDeniedException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_ACCESS_DENY';
|
|
10
|
+
this.message = 'Access denied';
|
|
11
|
+
this.statusCode = 403;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* No action matches the request: the service pattern, the command or the route of no controller action matches it.
|
|
4
|
+
* Its errno is `E_CONTROLLER_ACTION_NOT_FOUND`, its HTTP status 404.
|
|
5
|
+
*/
|
|
6
|
+
export class ControllerActionNotFoundException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_CONTROLLER_ACTION_NOT_FOUND';
|
|
10
|
+
this.statusCode = 404;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Two actions of a channel have the same name (`name` of their options, `Class:method` by default), when the
|
|
4
|
+
* entrypoint initializes. Its errno is `E_DUPLICATE_ACTION_NAME`.
|
|
5
|
+
*/
|
|
6
|
+
export class DuplicateActionNameException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_DUPLICATE_ACTION_NAME';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* The request arrived while the entrypoint is stopping (the application exiting): it is refused, the requests in
|
|
4
|
+
* progress being waited for. Its errno is `E_ENTRYPOINT_STOPPED`, its HTTP status 503.
|
|
5
|
+
*/
|
|
6
|
+
export class EntrypointStoppedException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_ENTRYPOINT_STOPPED';
|
|
10
|
+
this.statusCode = 503;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* A channel is defined twice under the same name, or a channel used is not defined. Its errno is
|
|
4
|
+
* `E_INVALID_CHANNEL`.
|
|
5
|
+
*/
|
|
6
|
+
export class InvalidChannelException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_INVALID_CHANNEL';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* An option of the entrypoint is given an adapter of another channel, an adapter of an undefined channel, or a value
|
|
4
|
+
* which is neither an option nor an adapter, when the entrypoint initializes. Its errno is
|
|
5
|
+
* `E_INVALID_ENTRYPOINT_ADAPTER`.
|
|
6
|
+
*/
|
|
7
|
+
export class InvalidEntrypointAdapterException extends Exception {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.errno = 'E_INVALID_ENTRYPOINT_ADAPTER';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* A middleware is neither a function nor a class extending `Middleware`, when the entrypoint initializes. Its errno is
|
|
4
|
+
* `E_INVALID_MIDDLEWARE`.
|
|
5
|
+
*/
|
|
6
|
+
export class InvalidMiddlewareException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_INVALID_MIDDLEWARE';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* A pattern prefix of a controller (`@Prefix`) and the pattern of one of its service actions set the same key to
|
|
4
|
+
* different values, when the entrypoint initializes. Its errno is `E_INVALID_PREFIX`.
|
|
5
|
+
*/
|
|
6
|
+
export class InvalidPrefixException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_INVALID_PREFIX';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* A middleware called `next()` more than once for a request (the request rejects with it). Its errno is
|
|
4
|
+
* `E_MIDDLEWARE_NEXT_CALLED`.
|
|
5
|
+
*/
|
|
6
|
+
export class MiddlewareNextCalledException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_MIDDLEWARE_NEXT_CALLED';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* No HTTP route matches the request (the HTTP adapters answer it). Its errno is `E_ROUTE_NOT_FOUND`, its HTTP status
|
|
4
|
+
* 404.
|
|
5
|
+
*/
|
|
6
|
+
export class RouteNotFoundException extends Exception {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.errno = 'E_ROUTE_NOT_FOUND';
|
|
10
|
+
this.statusCode = 404;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* The failure of a service invocation: the error of the remote service, with its properties (errno, errMsg, statusCode…)
|
|
4
|
+
*/
|
|
5
|
+
export class ServiceInvokeException extends Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_SERVICE_INVOKE';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//CLI actions
|
|
2
|
+
export { CLIAction } from '../decorators/CLIAction.js';
|
|
3
|
+
//HTTP actions
|
|
4
|
+
export { HTTPAction } from '../decorators/HTTPAction.js';
|
|
5
|
+
export { DELETE } from '../decorators/http/DELETE.js';
|
|
6
|
+
export { GET } from '../decorators/http/GET.js';
|
|
7
|
+
export { HEAD } from '../decorators/http/HEAD.js';
|
|
8
|
+
export { OPTIONS } from '../decorators/http/OPTIONS.js';
|
|
9
|
+
export { PATCH } from '../decorators/http/PATCH.js';
|
|
10
|
+
export { POST } from '../decorators/http/POST.js';
|
|
11
|
+
export { PUT } from '../decorators/http/PUT.js';
|
|
12
|
+
//Service actions
|
|
13
|
+
export { ServiceAction } from '../decorators/ServiceAction.js';
|
|
14
|
+
//Middlewares
|
|
15
|
+
export { UseMiddlewares } from '../decorators/UseMiddlewares.js';
|
|
16
|
+
//Controller prefixes
|
|
17
|
+
export { Prefix } from '../decorators/Prefix.js';
|
|
18
|
+
//Scheduled actions
|
|
19
|
+
export { Schedule } from '../decorators/Schedule.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API of the packages providing a channel or an adapter
|
|
3
|
+
*/
|
|
4
|
+
export { defineChannel, getChannel, hasChannel, getChannelByContextType } from '../channel/Channel.js';
|
|
5
|
+
export { isEntrypointAdapter, commandMap } from '../channel/EntrypointAdapter.js';
|
|
6
|
+
export { registerControllerAction } from '../lib/ControllerEntrypoint.js';
|
|
7
|
+
export { getActionDTOAndOptions } from '../lib/GetActionDTOAndOptions.js';
|
|
8
|
+
export { ActionOptions } from '../lib/ActionOptions.js';
|
|
9
|
+
export { HTTPChannel, CLIChannel, ServiceChannel, ScheduleChannel } from '../channel/BuiltinChannels.js';
|
|
10
|
+
export { ServiceResponseCodec } from '../lib/ServiceResponseCodec.js';
|
|
11
|
+
export { getPrefix, setPrefix } from '../lib/Prefix.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { commanderCLIEntrypoint } from '../adapter/commander/CommanderCLIEntrypoint.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { electronIPCServiceEntrypoint, ipcEventOfContext } from '../adapter/electron/ElectronIPCServiceEntrypoint.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from '../Entrypoint.js';
|
|
2
|
+
export * from '../lib/Controller.js';
|
|
3
|
+
export * from '../lib/AccessControlRule.js';
|
|
4
|
+
export * from '../exceptions/AccessDeniedException.js';
|
|
5
|
+
export * from '../exceptions/DuplicateActionNameException.js';
|
|
6
|
+
export * from '../exceptions/ControllerActionNotFoundException.js';
|
|
7
|
+
export { AccessControl } from '../lib/AccessControl.js';
|
|
8
|
+
export { Middleware } from '../lib/Middleware.js';
|
|
9
|
+
export * from '../exceptions/InvalidMiddlewareException.js';
|
|
10
|
+
export * from '../exceptions/MiddlewareNextCalledException.js';
|
|
11
|
+
export { PrefixOptions } from '../lib/Prefix.js';
|
|
12
|
+
export * from '../exceptions/InvalidPrefixException.js';
|
|
13
|
+
export { ActionResult } from '../lib/ActionResult.js';
|
|
14
|
+
export * from '../exceptions/InvalidChannelException.js';
|
|
15
|
+
export * from '../exceptions/InvalidEntrypointAdapterException.js';
|
|
16
|
+
export { Result, StatusResult, FileResult, EventsResult } from '../lib/Result.js';
|
|
17
|
+
export * from '../exceptions/RouteNotFoundException.js';
|
|
18
|
+
export * from '../exceptions/EntrypointStoppedException.js';
|
|
19
|
+
export * from '../exceptions/ServiceInvokeException.js';
|
|
20
|
+
export { scheduleEntrypoint } from '../adapter/schedule/ScheduleEntrypoint.js';
|
|
21
|
+
export { httpServiceEntrypoint, httpRequestOfContext } from '../adapter/http/HTTPServiceEntrypoint.js';
|
|
22
|
+
export { Cron, parseDuration } from '../lib/schedule/Cron.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { socketIOServiceEntrypoint, socketOfContext } from '../adapter/socket.io/SocketIOServiceEntrypoint.js';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { BaseObject, Container, DTO } from '@lakutata/core';
|
|
11
|
+
import { Configurable } from '@lakutata/core/decorator/di';
|
|
12
|
+
import { AccessDeniedException } from '../exceptions/AccessDeniedException.js';
|
|
13
|
+
import { AccessControlRule } from './AccessControlRule.js';
|
|
14
|
+
import { As, isSubclassOf } from '@lakutata/utils';
|
|
15
|
+
/**
|
|
16
|
+
* The access control of the entrypoint's actions: it checks a request to an action declared with `acl: true` against
|
|
17
|
+
* the entrypoint's rules and the action's own `rule`, or against the action's `rule` alone when `acl` is off. The
|
|
18
|
+
* entrypoint calls {@link AccessControl.run} for each request, after the input validation and before the action; a
|
|
19
|
+
* subclass of the entrypoint may replace it with a subclass (its protected `accessControl` property), for example to
|
|
20
|
+
* audit the decisions.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import {Application} from 'lakutata'
|
|
24
|
+
* import {AccessControl, Controller, Entrypoint} from 'lakutata/com/entrypoint'
|
|
25
|
+
* import {GET} from 'lakutata/decorator/ctrl'
|
|
26
|
+
*
|
|
27
|
+
* //Log every access decision
|
|
28
|
+
* class AuditedAccessControl extends AccessControl {
|
|
29
|
+
* protected async match(): Promise<boolean> {
|
|
30
|
+
* const allowed: boolean = await super.match()
|
|
31
|
+
* console.log(`${this.target.name}: ${allowed ? 'allowed' : 'denied'}`)
|
|
32
|
+
* return allowed
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* class AuditedEntrypoint extends Entrypoint {
|
|
37
|
+
* protected readonly accessControl: typeof AccessControl = AuditedAccessControl
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* class ReportController extends Controller {
|
|
41
|
+
* @GET('/reports', {acl: true, rule: async (): Promise<boolean> => true})
|
|
42
|
+
* public async list(): Promise<string[]> {
|
|
43
|
+
* return []
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* Application.run(() => ({
|
|
48
|
+
* id: 'report.app',
|
|
49
|
+
* name: 'Report',
|
|
50
|
+
* components: {
|
|
51
|
+
* entrypoint: {class: AuditedEntrypoint, controllers: [ReportController]}
|
|
52
|
+
* }
|
|
53
|
+
* }))
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export class AccessControl extends BaseObject {
|
|
57
|
+
/**
|
|
58
|
+
* Schema of access control rule constructors, built only when it is used
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
get accessControlRuleConstructorDTO() {
|
|
62
|
+
return DTO.Class(AccessControlRule);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check the rules and call the allow or deny callback.
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
68
|
+
async init() {
|
|
69
|
+
try {
|
|
70
|
+
const matchResult = await this.match();
|
|
71
|
+
if (matchResult)
|
|
72
|
+
return this.allowCallback();
|
|
73
|
+
return this.denyCallback();
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
return this.denyCallback(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check the rules in order: a rule class is created in the request's container and checked when it supports the
|
|
81
|
+
* request's context type, a rule function is called with the context and the input.
|
|
82
|
+
* @returns `false` as soon as a rule resolves `false`, `true` when none does (no rule included).
|
|
83
|
+
* @throws {Error} The error a rule throws (the request is then denied with it).
|
|
84
|
+
* @protected
|
|
85
|
+
*/
|
|
86
|
+
async match() {
|
|
87
|
+
for (const rule of this.rules) {
|
|
88
|
+
if (isSubclassOf(rule, AccessControlRule)) {
|
|
89
|
+
const RuleObjectConstructor = As(rule);
|
|
90
|
+
const ruleObjectInstance = await this.runtimeContainer.build(RuleObjectConstructor, {
|
|
91
|
+
actions: this.actions,
|
|
92
|
+
targetAction: this.target,
|
|
93
|
+
context: this.context,
|
|
94
|
+
input: this.input
|
|
95
|
+
});
|
|
96
|
+
if (!ruleObjectInstance.supportContextTypes.includes(this.context.type))
|
|
97
|
+
continue;
|
|
98
|
+
if (!(await ruleObjectInstance.rule()))
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const handler = As(rule);
|
|
103
|
+
if (!(await handler(this.context, this.input)))
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check the access to an action: with `acl: true`, against the rules then the action's own `rule`; with `acl`
|
|
111
|
+
* off, against the action's `rule` alone; without either, the request is allowed without check.
|
|
112
|
+
* @param rules The entrypoint's rule classes.
|
|
113
|
+
* @param runtimeContainer The request's container, where the access control and the rules are created.
|
|
114
|
+
* @param context The request's context.
|
|
115
|
+
* @param input The action's validated input.
|
|
116
|
+
* @param details The requested action.
|
|
117
|
+
* @param getActionsCallback Returns the descriptions of the actions of a context type's channel.
|
|
118
|
+
* @returns Whether the request is allowed, and when it is not, the error to fail it with: the error a rule
|
|
119
|
+
* threw, or an `AccessDeniedException`.
|
|
120
|
+
*/
|
|
121
|
+
static async run(rules, runtimeContainer, context, input, details, getActionsCallback) {
|
|
122
|
+
const actions = getActionsCallback(context.type);
|
|
123
|
+
let allowed = !details.acl;
|
|
124
|
+
//The exception is created only when access is denied (building it captures a stack trace)
|
|
125
|
+
let exception;
|
|
126
|
+
if (!allowed) {
|
|
127
|
+
await runtimeContainer.set(this, {
|
|
128
|
+
// await runtimeContainer.build(this, {
|
|
129
|
+
rules: [...rules, details.rule].filter((rule) => !!rule),
|
|
130
|
+
runtimeContainer: runtimeContainer,
|
|
131
|
+
actions: actions,
|
|
132
|
+
context: context,
|
|
133
|
+
input: input,
|
|
134
|
+
target: details.getActionInfo(),
|
|
135
|
+
allowCallback: () => {
|
|
136
|
+
allowed = true;
|
|
137
|
+
},
|
|
138
|
+
denyCallback: (error) => {
|
|
139
|
+
allowed = false;
|
|
140
|
+
exception = error ? error : exception;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else if (details.rule) {
|
|
145
|
+
await runtimeContainer.set(this, {
|
|
146
|
+
// await runtimeContainer.build(this, {
|
|
147
|
+
rules: [details.rule],
|
|
148
|
+
runtimeContainer: runtimeContainer,
|
|
149
|
+
actions: actions,
|
|
150
|
+
context: context,
|
|
151
|
+
input: input,
|
|
152
|
+
target: details.getActionInfo(),
|
|
153
|
+
allowCallback: () => {
|
|
154
|
+
allowed = true;
|
|
155
|
+
},
|
|
156
|
+
denyCallback: (error) => {
|
|
157
|
+
allowed = false;
|
|
158
|
+
exception = error ? error : exception;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return [
|
|
163
|
+
allowed,
|
|
164
|
+
allowed ? undefined : (exception ? exception : new AccessDeniedException())
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
__decorate([
|
|
169
|
+
Configurable(),
|
|
170
|
+
__metadata("design:type", Container
|
|
171
|
+
/**
|
|
172
|
+
* The descriptions of every action of the request's channel.
|
|
173
|
+
* @protected
|
|
174
|
+
*/
|
|
175
|
+
)
|
|
176
|
+
], AccessControl.prototype, "runtimeContainer", void 0);
|
|
177
|
+
__decorate([
|
|
178
|
+
Configurable(),
|
|
179
|
+
__metadata("design:type", Array)
|
|
180
|
+
], AccessControl.prototype, "actions", void 0);
|
|
181
|
+
__decorate([
|
|
182
|
+
Configurable(),
|
|
183
|
+
__metadata("design:type", Object)
|
|
184
|
+
], AccessControl.prototype, "target", void 0);
|
|
185
|
+
__decorate([
|
|
186
|
+
Configurable(),
|
|
187
|
+
__metadata("design:type", Object)
|
|
188
|
+
], AccessControl.prototype, "context", void 0);
|
|
189
|
+
__decorate([
|
|
190
|
+
Configurable(),
|
|
191
|
+
__metadata("design:type", Object)
|
|
192
|
+
], AccessControl.prototype, "input", void 0);
|
|
193
|
+
__decorate([
|
|
194
|
+
Configurable(),
|
|
195
|
+
__metadata("design:type", Function)
|
|
196
|
+
], AccessControl.prototype, "allowCallback", void 0);
|
|
197
|
+
__decorate([
|
|
198
|
+
Configurable(),
|
|
199
|
+
__metadata("design:type", Function)
|
|
200
|
+
], AccessControl.prototype, "denyCallback", void 0);
|
|
201
|
+
__decorate([
|
|
202
|
+
Configurable(),
|
|
203
|
+
__metadata("design:type", Array)
|
|
204
|
+
], AccessControl.prototype, "rules", void 0);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { BaseObject } from '@lakutata/core';
|
|
11
|
+
import { Configurable } from '@lakutata/core/decorator/di';
|
|
12
|
+
/**
|
|
13
|
+
* An access control rule, checked for the actions declared with `acl: true`: give the rule classes to the
|
|
14
|
+
* entrypoint's `rules` option. For each request to such an action, every rule supporting the request's context type
|
|
15
|
+
* is created in the request's container (its dependencies injected) and its {@link AccessControlRule.rule} called, in
|
|
16
|
+
* the order of the option; the first one resolving `false` denies the request with an `AccessDeniedException`, the
|
|
17
|
+
* first one throwing denies it with its error. A request no rule denies is allowed.
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {Application} from 'lakutata'
|
|
21
|
+
* import {AccessControlRule, buildEntrypoints, ContextType, Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
22
|
+
* import {DELETE} from 'lakutata/decorator/ctrl'
|
|
23
|
+
*
|
|
24
|
+
* //Only the requests of an administrator reach the actions of the "admin" group
|
|
25
|
+
* class AdminRule extends AccessControlRule<HTTPContext> {
|
|
26
|
+
* public get supportContextTypes(): ContextType[] {
|
|
27
|
+
* return [ContextType.HTTP]
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* public async rule(): Promise<boolean> {
|
|
31
|
+
* if (!this.targetAction.groups.includes('admin')) return true
|
|
32
|
+
* return this.context.request.headers['x-role'] === 'admin'
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* class UserController extends Controller {
|
|
37
|
+
* @DELETE('/users/:id', {acl: true, groups: ['admin']})
|
|
38
|
+
* public async remove(input: {id: string}): Promise<void> {
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* Application.run(() => ({
|
|
43
|
+
* id: 'admin.app',
|
|
44
|
+
* name: 'Admin',
|
|
45
|
+
* components: {
|
|
46
|
+
* entrypoint: buildEntrypoints({
|
|
47
|
+
* controllers: [UserController],
|
|
48
|
+
* rules: [AdminRule],
|
|
49
|
+
* httpActionGroups: {admin: 'Administration'}
|
|
50
|
+
* })
|
|
51
|
+
* }
|
|
52
|
+
* }))
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export class AccessControlRule extends BaseObject {
|
|
56
|
+
}
|
|
57
|
+
__decorate([
|
|
58
|
+
Configurable(),
|
|
59
|
+
__metadata("design:type", Object)
|
|
60
|
+
], AccessControlRule.prototype, "context", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
Configurable(),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], AccessControlRule.prototype, "input", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
Configurable(),
|
|
67
|
+
__metadata("design:type", Array)
|
|
68
|
+
], AccessControlRule.prototype, "actions", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
Configurable(),
|
|
71
|
+
__metadata("design:type", Object)
|
|
72
|
+
], AccessControlRule.prototype, "targetAction", void 0);
|