@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,10 @@
|
|
|
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 declare class AccessDeniedException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
message: string;
|
|
9
|
+
readonly statusCode: number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare class ControllerActionNotFoundException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare class DuplicateActionNameException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare class EntrypointStoppedException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare class InvalidChannelException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare class InvalidEntrypointAdapterException extends Exception {
|
|
8
|
+
errno: string | number;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare class InvalidMiddlewareException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare class InvalidPrefixException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare class MiddlewareNextCalledException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare class RouteNotFoundException extends Exception {
|
|
7
|
+
errno: string | number;
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 declare class ServiceInvokeException extends Exception {
|
|
6
|
+
errno: string | number;
|
|
7
|
+
/**
|
|
8
|
+
* The id of the service invoked.
|
|
9
|
+
*/
|
|
10
|
+
service?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { CLIAction } from '../decorators/CLIAction.js';
|
|
2
|
+
export { HTTPAction } from '../decorators/HTTPAction.js';
|
|
3
|
+
export { DELETE } from '../decorators/http/DELETE.js';
|
|
4
|
+
export { GET } from '../decorators/http/GET.js';
|
|
5
|
+
export { HEAD } from '../decorators/http/HEAD.js';
|
|
6
|
+
export { OPTIONS } from '../decorators/http/OPTIONS.js';
|
|
7
|
+
export { PATCH } from '../decorators/http/PATCH.js';
|
|
8
|
+
export { POST } from '../decorators/http/POST.js';
|
|
9
|
+
export { PUT } from '../decorators/http/PUT.js';
|
|
10
|
+
export { ServiceAction } from '../decorators/ServiceAction.js';
|
|
11
|
+
export { UseMiddlewares } from '../decorators/UseMiddlewares.js';
|
|
12
|
+
export { Prefix } from '../decorators/Prefix.js';
|
|
13
|
+
export { Schedule, type ScheduleOptions } from '../decorators/Schedule.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
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 type { ChannelDefinition, ChannelKind, ChannelEntry, ChannelMatch, ChannelMatcher } from '../channel/Channel.js';
|
|
6
|
+
export { isEntrypointAdapter, commandMap } from '../channel/EntrypointAdapter.js';
|
|
7
|
+
export type { EntrypointAdapter, ChannelRuntime, ChannelActionInfo, DispatchOptions } from '../channel/EntrypointAdapter.js';
|
|
8
|
+
export { registerControllerAction } from '../lib/ControllerEntrypoint.js';
|
|
9
|
+
export type { ActionDetails, ActionInfo } from '../lib/ControllerEntrypoint.js';
|
|
10
|
+
export { getActionDTOAndOptions } from '../lib/GetActionDTOAndOptions.js';
|
|
11
|
+
export { ActionOptions } from '../lib/ActionOptions.js';
|
|
12
|
+
export { HTTPChannel, CLIChannel, ServiceChannel, ScheduleChannel } from '../channel/BuiltinChannels.js';
|
|
13
|
+
export { ServiceResponseCodec, type ServiceResponse } from '../lib/ServiceResponseCodec.js';
|
|
14
|
+
export { getPrefix, setPrefix } from '../lib/Prefix.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { commanderCLIEntrypoint, type CommanderCLIEntrypointOptions, type CLIText, type CLITranslate } from '../adapter/commander/CommanderCLIEntrypoint.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { electronIPCServiceEntrypoint, ipcEventOfContext, type ElectronIPCServiceEntrypointOptions, type IPCMain, type IPCInvokeEvent, type IPCSender } from '../adapter/electron/ElectronIPCServiceEntrypoint.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
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, type ActionInvocation, type Next, type MiddlewareHandler, type MiddlewareDefinition } 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 type { ActionInfo } from '../lib/ControllerEntrypoint.js';
|
|
15
|
+
export type { EntrypointAdapter, ChannelRuntime, ChannelActionInfo, DispatchOptions } from '../channel/EntrypointAdapter.js';
|
|
16
|
+
export * from '../exceptions/InvalidChannelException.js';
|
|
17
|
+
export * from '../exceptions/InvalidEntrypointAdapterException.js';
|
|
18
|
+
export { Result, StatusResult, FileResult, EventsResult, type FileResultOptions, type SendEvent, type EventsProducer } from '../lib/Result.js';
|
|
19
|
+
export * from '../exceptions/RouteNotFoundException.js';
|
|
20
|
+
export * from '../exceptions/EntrypointStoppedException.js';
|
|
21
|
+
export * from '../exceptions/ServiceInvokeException.js';
|
|
22
|
+
export { scheduleEntrypoint, type ScheduleEntrypointOptions } from '../adapter/schedule/ScheduleEntrypoint.js';
|
|
23
|
+
export { httpServiceEntrypoint, httpRequestOfContext, type HTTPServiceEntrypointOptions } from '../adapter/http/HTTPServiceEntrypoint.js';
|
|
24
|
+
export { Cron, parseDuration } from '../lib/schedule/Cron.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { expressHTTPEntrypoint, type ExpressHTTPEntrypointOptions, type ExpressHookContext } from '../adapter/express/ExpressHTTPEntrypoint.js';
|
|
2
|
+
export { JSONResponder, jsonEnvelope, statusOfError, describeError, type ExpressResponder, type HTTPErrorOrigin, type JSONEnvelopeOptions } from '../adapter/express/Responders.js';
|
|
3
|
+
export { staticUI, type StaticUIOptions } from '../adapter/express/StaticUI.js';
|
|
4
|
+
export { type ErrorDescription } from '../types/ErrorDescription.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { fastifyHTTPEntrypoint, type FastifyHTTPEntrypointOptions, type FastifyHookContext } from '../adapter/fastify/FastifyHTTPEntrypoint.js';
|
|
2
|
+
export { FastifyJSONResponder, fastifyJSONEnvelope, type FastifyResponder, type FastifyJSONEnvelopeOptions } from '../adapter/fastify/Responders.js';
|
|
3
|
+
export { statusOfError, describeError, type HTTPErrorOrigin } from '../lib/HTTPErrors.js';
|
|
4
|
+
export { type ErrorDescription } from '../types/ErrorDescription.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { jsonRPCServiceEntrypoint, type JSONRPCServiceEntrypointOptions } from '../adapter/jsonrpc/JSONRPCServiceEntrypoint.js';
|
|
2
|
+
export { JSONRPCErrorCode, jsonRPCRequestOfContext, type JSONRPCMappingOptions, type JSONRPCRequest, type JSONRPCRequestInfo, type JSONRPCResponse } from '../adapter/jsonrpc/JSONRPCProtocol.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { socketIOServiceEntrypoint, socketOfContext, type SocketIOServiceEntrypointOptions } from '../adapter/socket.io/SocketIOServiceEntrypoint.js';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { BaseObject, Exception, Container, IBaseObjectConstructor, FunctionSchema } from '@lakutata/core';
|
|
2
|
+
import { BaseActionInfo, CLIActionInfo, CLIContext, ContextType, HTTPActionInfo, HTTPContext, ServiceActionInfo, ServiceContext } from '../Entrypoint.js';
|
|
3
|
+
import { ActionDetails, type ActionInfo } from './ControllerEntrypoint.js';
|
|
4
|
+
import { AccessControlRule, AccessControlRuleHandler } from './AccessControlRule.js';
|
|
5
|
+
/**
|
|
6
|
+
* The access control of the entrypoint's actions: it checks a request to an action declared with `acl: true` against
|
|
7
|
+
* the entrypoint's rules and the action's own `rule`, or against the action's `rule` alone when `acl` is off. The
|
|
8
|
+
* entrypoint calls {@link AccessControl.run} for each request, after the input validation and before the action; a
|
|
9
|
+
* subclass of the entrypoint may replace it with a subclass (its protected `accessControl` property), for example to
|
|
10
|
+
* audit the decisions.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import {Application} from 'lakutata'
|
|
14
|
+
* import {AccessControl, Controller, Entrypoint} from 'lakutata/com/entrypoint'
|
|
15
|
+
* import {GET} from 'lakutata/decorator/ctrl'
|
|
16
|
+
*
|
|
17
|
+
* //Log every access decision
|
|
18
|
+
* class AuditedAccessControl extends AccessControl {
|
|
19
|
+
* protected async match(): Promise<boolean> {
|
|
20
|
+
* const allowed: boolean = await super.match()
|
|
21
|
+
* console.log(`${this.target.name}: ${allowed ? 'allowed' : 'denied'}`)
|
|
22
|
+
* return allowed
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* class AuditedEntrypoint extends Entrypoint {
|
|
27
|
+
* protected readonly accessControl: typeof AccessControl = AuditedAccessControl
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* class ReportController extends Controller {
|
|
31
|
+
* @GET('/reports', {acl: true, rule: async (): Promise<boolean> => true})
|
|
32
|
+
* public async list(): Promise<string[]> {
|
|
33
|
+
* return []
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* Application.run(() => ({
|
|
38
|
+
* id: 'report.app',
|
|
39
|
+
* name: 'Report',
|
|
40
|
+
* components: {
|
|
41
|
+
* entrypoint: {class: AuditedEntrypoint, controllers: [ReportController]}
|
|
42
|
+
* }
|
|
43
|
+
* }))
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class AccessControl extends BaseObject {
|
|
47
|
+
/**
|
|
48
|
+
* The request's container, where the rules are created.
|
|
49
|
+
* @protected
|
|
50
|
+
*/
|
|
51
|
+
protected readonly runtimeContainer: Container;
|
|
52
|
+
/**
|
|
53
|
+
* The descriptions of every action of the request's channel.
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
protected readonly actions: HTTPActionInfo[] | ServiceActionInfo[] | CLIActionInfo[];
|
|
57
|
+
/**
|
|
58
|
+
* The requested action: its identity and options (without the channel's fields).
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
protected readonly target: ActionInfo;
|
|
62
|
+
/**
|
|
63
|
+
* The request's context.
|
|
64
|
+
* @protected
|
|
65
|
+
*/
|
|
66
|
+
protected readonly context: CLIContext | HTTPContext | ServiceContext;
|
|
67
|
+
/**
|
|
68
|
+
* The action's validated input.
|
|
69
|
+
* @protected
|
|
70
|
+
*/
|
|
71
|
+
protected readonly input: Record<string, any>;
|
|
72
|
+
/**
|
|
73
|
+
* Called when the rules allow the request.
|
|
74
|
+
* @protected
|
|
75
|
+
*/
|
|
76
|
+
protected readonly allowCallback: () => void;
|
|
77
|
+
/**
|
|
78
|
+
* Called when a rule denies the request, with the error a rule threw (none when a rule resolved `false`).
|
|
79
|
+
* @protected
|
|
80
|
+
*/
|
|
81
|
+
protected readonly denyCallback: (error?: Error | Exception) => void;
|
|
82
|
+
/**
|
|
83
|
+
* The rules to check, in order: rule classes and rule functions.
|
|
84
|
+
* @protected
|
|
85
|
+
*/
|
|
86
|
+
protected readonly rules: (IBaseObjectConstructor<AccessControlRule> | AccessControlRuleHandler<any>)[];
|
|
87
|
+
/**
|
|
88
|
+
* Schema of access control rule constructors, built only when it is used
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
91
|
+
protected get accessControlRuleConstructorDTO(): FunctionSchema<typeof AccessControlRule>;
|
|
92
|
+
/**
|
|
93
|
+
* Check the rules and call the allow or deny callback.
|
|
94
|
+
* @protected
|
|
95
|
+
*/
|
|
96
|
+
protected init(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Check the rules in order: a rule class is created in the request's container and checked when it supports the
|
|
99
|
+
* request's context type, a rule function is called with the context and the input.
|
|
100
|
+
* @returns `false` as soon as a rule resolves `false`, `true` when none does (no rule included).
|
|
101
|
+
* @throws {Error} The error a rule throws (the request is then denied with it).
|
|
102
|
+
* @protected
|
|
103
|
+
*/
|
|
104
|
+
protected match(): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Check the access to an action: with `acl: true`, against the rules then the action's own `rule`; with `acl`
|
|
107
|
+
* off, against the action's `rule` alone; without either, the request is allowed without check.
|
|
108
|
+
* @param rules The entrypoint's rule classes.
|
|
109
|
+
* @param runtimeContainer The request's container, where the access control and the rules are created.
|
|
110
|
+
* @param context The request's context.
|
|
111
|
+
* @param input The action's validated input.
|
|
112
|
+
* @param details The requested action.
|
|
113
|
+
* @param getActionsCallback Returns the descriptions of the actions of a context type's channel.
|
|
114
|
+
* @returns Whether the request is allowed, and when it is not, the error to fail it with: the error a rule
|
|
115
|
+
* threw, or an `AccessDeniedException`.
|
|
116
|
+
*/
|
|
117
|
+
static run(rules: IBaseObjectConstructor<AccessControlRule>[], runtimeContainer: Container, context: CLIContext | HTTPContext | ServiceContext, input: Record<string, any>, details: ActionDetails, getActionsCallback: (type: ContextType | string) => BaseActionInfo[]): Promise<[boolean, Error | Exception | undefined]>;
|
|
118
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BaseObject, type ActionPattern } from '@lakutata/core';
|
|
2
|
+
import { BaseContext, ContextType } from '../context/BaseContext.js';
|
|
3
|
+
import { CLIActionInfo, HTTPActionInfo, ServiceActionInfo } from '../Entrypoint.js';
|
|
4
|
+
import type { ActionInfo } from './ControllerEntrypoint.js';
|
|
5
|
+
/**
|
|
6
|
+
* An action's own access rule (the `rule` action option): resolve `true` to allow the request, `false` to deny it with
|
|
7
|
+
* an `AccessDeniedException`; a thrown error denies it with that error.
|
|
8
|
+
* @param context The request's context.
|
|
9
|
+
* @param input The action's validated input.
|
|
10
|
+
* @returns Whether the request is allowed.
|
|
11
|
+
*/
|
|
12
|
+
export type AccessControlRuleHandler<T extends BaseContext<Record<string, any>>> = (context: T, input?: ActionPattern<any>) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* An access control rule, checked for the actions declared with `acl: true`: give the rule classes to the
|
|
15
|
+
* entrypoint's `rules` option. For each request to such an action, every rule supporting the request's context type
|
|
16
|
+
* is created in the request's container (its dependencies injected) and its {@link AccessControlRule.rule} called, in
|
|
17
|
+
* the order of the option; the first one resolving `false` denies the request with an `AccessDeniedException`, the
|
|
18
|
+
* first one throwing denies it with its error. A request no rule denies is allowed.
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import {Application} from 'lakutata'
|
|
22
|
+
* import {AccessControlRule, buildEntrypoints, ContextType, Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
23
|
+
* import {DELETE} from 'lakutata/decorator/ctrl'
|
|
24
|
+
*
|
|
25
|
+
* //Only the requests of an administrator reach the actions of the "admin" group
|
|
26
|
+
* class AdminRule extends AccessControlRule<HTTPContext> {
|
|
27
|
+
* public get supportContextTypes(): ContextType[] {
|
|
28
|
+
* return [ContextType.HTTP]
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* public async rule(): Promise<boolean> {
|
|
32
|
+
* if (!this.targetAction.groups.includes('admin')) return true
|
|
33
|
+
* return this.context.request.headers['x-role'] === 'admin'
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* class UserController extends Controller {
|
|
38
|
+
* @DELETE('/users/:id', {acl: true, groups: ['admin']})
|
|
39
|
+
* public async remove(input: {id: string}): Promise<void> {
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* Application.run(() => ({
|
|
44
|
+
* id: 'admin.app',
|
|
45
|
+
* name: 'Admin',
|
|
46
|
+
* components: {
|
|
47
|
+
* entrypoint: buildEntrypoints({
|
|
48
|
+
* controllers: [UserController],
|
|
49
|
+
* rules: [AdminRule],
|
|
50
|
+
* httpActionGroups: {admin: 'Administration'}
|
|
51
|
+
* })
|
|
52
|
+
* }
|
|
53
|
+
* }))
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare abstract class AccessControlRule<T extends BaseContext<Record<string, any>> = BaseContext<Record<string, any>>> extends BaseObject {
|
|
57
|
+
/**
|
|
58
|
+
* The request's context.
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
protected readonly context: T;
|
|
62
|
+
/**
|
|
63
|
+
* The action's validated input.
|
|
64
|
+
* @protected
|
|
65
|
+
*/
|
|
66
|
+
protected readonly input: ActionPattern<any>;
|
|
67
|
+
/**
|
|
68
|
+
* The descriptions of every action of the request's channel (to check the permissions an action requires against
|
|
69
|
+
* the others).
|
|
70
|
+
* @protected
|
|
71
|
+
*/
|
|
72
|
+
protected readonly actions: HTTPActionInfo[] | ServiceActionInfo[] | CLIActionInfo[];
|
|
73
|
+
/**
|
|
74
|
+
* The requested action: its `id`, `name`, `description`, `groups`, `acl`, `rule` and `action`
|
|
75
|
+
* (`ControllerClass:method`). Its channel's fields (`route`, `command`, `pattern`), `controller`, `method` and
|
|
76
|
+
* `jsonSchema` are in {@link AccessControlRule.actions}, found by `id`.
|
|
77
|
+
* @protected
|
|
78
|
+
*/
|
|
79
|
+
protected readonly targetAction: ActionInfo;
|
|
80
|
+
/**
|
|
81
|
+
* The context types of the requests the rule checks (`ContextType.HTTP`…, or the context type of another channel);
|
|
82
|
+
* for the other requests the rule is created but its {@link AccessControlRule.rule} is not called.
|
|
83
|
+
*/
|
|
84
|
+
abstract get supportContextTypes(): ContextType[];
|
|
85
|
+
/**
|
|
86
|
+
* Check the request.
|
|
87
|
+
* @returns `true` to let the next rules check the request, `false` to deny it with an `AccessDeniedException`.
|
|
88
|
+
* @throws {Error} Any error, to deny the request with it.
|
|
89
|
+
*/
|
|
90
|
+
abstract rule(): Promise<boolean>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DTO } from '@lakutata/core';
|
|
2
|
+
import type { AccessControlRuleHandler } from './AccessControlRule.js';
|
|
3
|
+
import { BaseContext } from '../context/BaseContext.js';
|
|
4
|
+
import type { MiddlewareDefinition } from './Middleware.js';
|
|
5
|
+
/**
|
|
6
|
+
* The options of a controller action, the last argument of the action decorators (`@GET`, `@CLIAction`,
|
|
7
|
+
* `@ServiceAction`, `@Schedule`…).
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {Controller, type HTTPContext} from 'lakutata/com/entrypoint'
|
|
11
|
+
* import {type ActionOptions} from '@lakutata/entrypoint/channel'
|
|
12
|
+
* import {GET} from 'lakutata/decorator/ctrl'
|
|
13
|
+
*
|
|
14
|
+
* //Only the requests carrying the admin token reach the action
|
|
15
|
+
* const adminOnly: ActionOptions<HTTPContext> = {
|
|
16
|
+
* acl: true,
|
|
17
|
+
* name: 'listUsers',
|
|
18
|
+
* description: 'List the users',
|
|
19
|
+
* groups: ['admin'],
|
|
20
|
+
* rule: async (context: HTTPContext): Promise<boolean> => context.request.headers.authorization === 'Bearer admin'
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* class UserController extends Controller {
|
|
24
|
+
* @GET('/users', adminOnly)
|
|
25
|
+
* public async list(): Promise<string[]> {
|
|
26
|
+
* return []
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class ActionOptions<T extends BaseContext<Record<string, any>>> extends DTO {
|
|
32
|
+
/**
|
|
33
|
+
* Whether the entrypoint's access control rules are checked for the action; a request they deny fails with an
|
|
34
|
+
* `AccessDeniedException`. With no rule (or none supporting the request's context type), the access is
|
|
35
|
+
* allowed.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
acl?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The action's name, unique within its channel among the controller methods (the addresses of one method may
|
|
41
|
+
* share it): `ControllerClass:method` when empty.
|
|
42
|
+
* @default ''
|
|
43
|
+
*/
|
|
44
|
+
name?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The action's description, listed with the action.
|
|
47
|
+
* @default ''
|
|
48
|
+
*/
|
|
49
|
+
description?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The ids of the action's groups; for HTTP, CLI and service actions each id must be a key of the entrypoint's
|
|
52
|
+
* action groups option (`httpActionGroups`…), or the entrypoint fails to initialize.
|
|
53
|
+
* @default []
|
|
54
|
+
*/
|
|
55
|
+
groups?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* The action's own access rule, checked after the entrypoint's rules when `acl` is on, and alone when it is off:
|
|
58
|
+
* resolving `false` denies the request (`AccessDeniedException`), throwing denies it with the thrown error.
|
|
59
|
+
*/
|
|
60
|
+
rule?: AccessControlRuleHandler<T>;
|
|
61
|
+
/**
|
|
62
|
+
* The action's middlewares, run after the ones of the controller class and before the ones added to the method
|
|
63
|
+
* by `@UseMiddlewares`.
|
|
64
|
+
* @default []
|
|
65
|
+
*/
|
|
66
|
+
middlewares?: MiddlewareDefinition[];
|
|
67
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base of the results an action returns to describe its output beyond its data (a status, headers, a file, an
|
|
3
|
+
* event stream): {@link StatusResult}, {@link FileResult}, {@link EventsResult}, built with `Result`. The HTTP and CLI
|
|
4
|
+
* adapters output the results they support, and the `data` of the others; the service adapters (Socket.IO, JSON-RPC,
|
|
5
|
+
* Electron IPC, the HTTP service, gRPC, NATS) send the `data` of a `StatusResult` and answer a `FileResult` or an
|
|
6
|
+
* `EventsResult` with an error.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {ActionResult} from 'lakutata/com/entrypoint'
|
|
10
|
+
*
|
|
11
|
+
* //A result carrying a page of items, an adapter of its own may output its paging
|
|
12
|
+
* export class PageResult<T> extends ActionResult {
|
|
13
|
+
* constructor(public readonly items: T[], public readonly next?: string) {
|
|
14
|
+
* super()
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* public get data(): T[] {
|
|
18
|
+
* return this.items
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class ActionResult {
|
|
24
|
+
/**
|
|
25
|
+
* The result's data: what the adapters not supporting the result output.
|
|
26
|
+
*/
|
|
27
|
+
abstract get data(): unknown;
|
|
28
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Provider } from '@lakutata/core';
|
|
2
|
+
import { CLIContext } from '../context/CLIContext.js';
|
|
3
|
+
import { HTTPContext } from '../context/HTTPContext.js';
|
|
4
|
+
import { ServiceContext } from '../context/ServiceContext.js';
|
|
5
|
+
import { BaseContext } from '../context/BaseContext.js';
|
|
6
|
+
/**
|
|
7
|
+
* The names of a controller's own members (the ones {@link Controller} does not declare): the methods an action
|
|
8
|
+
* decorator may be applied to.
|
|
9
|
+
*/
|
|
10
|
+
export type ControllerProperty<ClassPrototype extends Controller> = Exclude<keyof ClassPrototype, keyof Controller>;
|
|
11
|
+
/**
|
|
12
|
+
* The base class of the controllers: classes whose methods, decorated with the action decorators (`@GET`, `@POST`…,
|
|
13
|
+
* `@CLIAction`, `@ServiceAction`, `@Schedule`), serve the entrypoint's requests. Give the controller classes to the
|
|
14
|
+
* entrypoint's `controllers` option.
|
|
15
|
+
*
|
|
16
|
+
* A controller is scoped: each request creates its own instance in the request's container, with the request's
|
|
17
|
+
* context and abort signal, and destroys it when the request ends; its injected providers are scoped to the request
|
|
18
|
+
* too. An action method receives its input (the request's data merged with the address parameters, validated by the
|
|
19
|
+
* action's DTO, its defaults applied) and returns the result the adapter outputs; the actions declared in a parent
|
|
20
|
+
* class are served by the registered subclasses.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import {DTO} from 'lakutata'
|
|
24
|
+
* import {Controller, HTTPContext} from 'lakutata/com/entrypoint'
|
|
25
|
+
* import {CLIAction, GET, ServiceAction} from 'lakutata/decorator/ctrl'
|
|
26
|
+
* import {Expect} from 'lakutata/decorator/dto'
|
|
27
|
+
*
|
|
28
|
+
* class FindUserDTO extends DTO {
|
|
29
|
+
* @Expect(DTO.String().required())
|
|
30
|
+
* public id: string
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* class UserController extends Controller {
|
|
34
|
+
* //The same action over HTTP (GET /users/:id), the CLI (user-get --id 1) and the services ({act: 'user.get', id})
|
|
35
|
+
* @GET('/users/:id', FindUserDTO)
|
|
36
|
+
* @CLIAction('user-get', FindUserDTO)
|
|
37
|
+
* @ServiceAction({act: 'user.get'}, FindUserDTO)
|
|
38
|
+
* public async get(input: FindUserDTO): Promise<{id: string, via: string}> {
|
|
39
|
+
* this.signal?.throwIfAborted()
|
|
40
|
+
* const via: string = this.context instanceof HTTPContext ? this.context.request.headers['user-agent'] ?? 'http' : this.context.type
|
|
41
|
+
* return {id: input.id, via: via}
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class Controller extends Provider {
|
|
47
|
+
/**
|
|
48
|
+
* The request's context: an {@link HTTPContext}, {@link CLIContext}, {@link ServiceContext}, or the context of
|
|
49
|
+
* another channel (`ScheduleContext`…); check its `type` or its class to tell them apart.
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
protected readonly context: CLIContext | HTTPContext | ServiceContext | BaseContext;
|
|
53
|
+
/**
|
|
54
|
+
* Aborts when the request is aborted: its client gone (the HTTP connection closed, the gRPC call cancelled), its
|
|
55
|
+
* deadline passed, or the entrypoint stopping. Long-running actions should stop then: their result is dropped.
|
|
56
|
+
* @protected
|
|
57
|
+
*/
|
|
58
|
+
protected readonly signal?: AbortSignal;
|
|
59
|
+
}
|