@rapidrest/service-core 1.0.0-beta.1
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 +16 -0
- package/dist/lib/ApiErrors.js +41 -0
- package/dist/lib/ApiErrors.js.map +1 -0
- package/dist/lib/BackgroundService.js +16 -0
- package/dist/lib/BackgroundService.js.map +1 -0
- package/dist/lib/BackgroundServiceManager.js +135 -0
- package/dist/lib/BackgroundServiceManager.js.map +1 -0
- package/dist/lib/BulkError.js +24 -0
- package/dist/lib/BulkError.js.map +1 -0
- package/dist/lib/EventListenerManager.js +161 -0
- package/dist/lib/EventListenerManager.js.map +1 -0
- package/dist/lib/NetUtils.js +103 -0
- package/dist/lib/NetUtils.js.map +1 -0
- package/dist/lib/NotificationUtils.js +34 -0
- package/dist/lib/NotificationUtils.js.map +1 -0
- package/dist/lib/ObjectFactory.js +90 -0
- package/dist/lib/ObjectFactory.js.map +1 -0
- package/dist/lib/OpenApiSpec.js +748 -0
- package/dist/lib/OpenApiSpec.js.map +1 -0
- package/dist/lib/Server.js +549 -0
- package/dist/lib/Server.js.map +1 -0
- package/dist/lib/Types.js +2 -0
- package/dist/lib/Types.js.map +1 -0
- package/dist/lib/auth/AuthMiddleware.js +229 -0
- package/dist/lib/auth/AuthMiddleware.js.map +1 -0
- package/dist/lib/auth/AuthStrategy.js +2 -0
- package/dist/lib/auth/AuthStrategy.js.map +1 -0
- package/dist/lib/auth/BasicStrategy.js +106 -0
- package/dist/lib/auth/BasicStrategy.js.map +1 -0
- package/dist/lib/auth/JWTStrategy.js +161 -0
- package/dist/lib/auth/JWTStrategy.js.map +1 -0
- package/dist/lib/auth/index.js +5 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/database/ConnectionKinds.js +14 -0
- package/dist/lib/database/ConnectionKinds.js.map +1 -0
- package/dist/lib/database/ConnectionManager.js +161 -0
- package/dist/lib/database/ConnectionManager.js.map +1 -0
- package/dist/lib/database/MongoConnection.js +86 -0
- package/dist/lib/database/MongoConnection.js.map +1 -0
- package/dist/lib/database/MongoRepository.js +136 -0
- package/dist/lib/database/MongoRepository.js.map +1 -0
- package/dist/lib/database/MongoSchemaSync.js +136 -0
- package/dist/lib/database/MongoSchemaSync.js.map +1 -0
- package/dist/lib/database/NamingUtils.js +52 -0
- package/dist/lib/database/NamingUtils.js.map +1 -0
- package/dist/lib/database/TypeOrmSupport.js +146 -0
- package/dist/lib/database/TypeOrmSupport.js.map +1 -0
- package/dist/lib/database/index.js +7 -0
- package/dist/lib/database/index.js.map +1 -0
- package/dist/lib/decorators/DatabaseDecorators.js +52 -0
- package/dist/lib/decorators/DatabaseDecorators.js.map +1 -0
- package/dist/lib/decorators/DocDecorators.js +120 -0
- package/dist/lib/decorators/DocDecorators.js.map +1 -0
- package/dist/lib/decorators/EventDecorators.js +24 -0
- package/dist/lib/decorators/EventDecorators.js.map +1 -0
- package/dist/lib/decorators/ModelDecorators.js +173 -0
- package/dist/lib/decorators/ModelDecorators.js.map +1 -0
- package/dist/lib/decorators/PersistenceDecorators.js +177 -0
- package/dist/lib/decorators/PersistenceDecorators.js.map +1 -0
- package/dist/lib/decorators/RouteDecorators.js +324 -0
- package/dist/lib/decorators/RouteDecorators.js.map +1 -0
- package/dist/lib/decorators/index.js +7 -0
- package/dist/lib/decorators/index.js.map +1 -0
- package/dist/lib/http/Adapters.js +230 -0
- package/dist/lib/http/Adapters.js.map +1 -0
- package/dist/lib/http/Router.js +403 -0
- package/dist/lib/http/Router.js.map +1 -0
- package/dist/lib/http/WebSocket.js +82 -0
- package/dist/lib/http/WebSocket.js.map +1 -0
- package/dist/lib/http/index.js +4 -0
- package/dist/lib/http/index.js.map +1 -0
- package/dist/lib/http/types.js +5 -0
- package/dist/lib/http/types.js.map +1 -0
- package/dist/lib/index.js +18 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/models/BaseEntity.js +83 -0
- package/dist/lib/models/BaseEntity.js.map +1 -0
- package/dist/lib/models/BaseMongoEntity.js +40 -0
- package/dist/lib/models/BaseMongoEntity.js.map +1 -0
- package/dist/lib/models/ModelUtils.js +645 -0
- package/dist/lib/models/ModelUtils.js.map +1 -0
- package/dist/lib/models/RecoverableBaseEntity.js +39 -0
- package/dist/lib/models/RecoverableBaseEntity.js.map +1 -0
- package/dist/lib/models/RecoverableBaseMongoEntity.js +40 -0
- package/dist/lib/models/RecoverableBaseMongoEntity.js.map +1 -0
- package/dist/lib/models/RepoUtils.js +717 -0
- package/dist/lib/models/RepoUtils.js.map +1 -0
- package/dist/lib/models/SimpleEntity.js +42 -0
- package/dist/lib/models/SimpleEntity.js.map +1 -0
- package/dist/lib/models/SimpleMongoEntity.js +38 -0
- package/dist/lib/models/SimpleMongoEntity.js.map +1 -0
- package/dist/lib/models/StatusExtraData.js +15 -0
- package/dist/lib/models/StatusExtraData.js.map +1 -0
- package/dist/lib/models/index.js +10 -0
- package/dist/lib/models/index.js.map +1 -0
- package/dist/lib/routes/AdminRoute.js +268 -0
- package/dist/lib/routes/AdminRoute.js.map +1 -0
- package/dist/lib/routes/MetricsRoute.js +86 -0
- package/dist/lib/routes/MetricsRoute.js.map +1 -0
- package/dist/lib/routes/ModelRoute.js +481 -0
- package/dist/lib/routes/ModelRoute.js.map +1 -0
- package/dist/lib/routes/OpenAPIRoute.js +115 -0
- package/dist/lib/routes/OpenAPIRoute.js.map +1 -0
- package/dist/lib/routes/RouteUtils.js +445 -0
- package/dist/lib/routes/RouteUtils.js.map +1 -0
- package/dist/lib/routes/StatusRoute.js +55 -0
- package/dist/lib/routes/StatusRoute.js.map +1 -0
- package/dist/lib/routes/index.js +7 -0
- package/dist/lib/routes/index.js.map +1 -0
- package/dist/lib/security/ACLRouteMongo.js +194 -0
- package/dist/lib/security/ACLRouteMongo.js.map +1 -0
- package/dist/lib/security/ACLRouteSQL.js +193 -0
- package/dist/lib/security/ACLRouteSQL.js.map +1 -0
- package/dist/lib/security/ACLUtils.js +457 -0
- package/dist/lib/security/ACLUtils.js.map +1 -0
- package/dist/lib/security/AccessControlList.js +18 -0
- package/dist/lib/security/AccessControlList.js.map +1 -0
- package/dist/lib/security/AccessControlListMongo.js +155 -0
- package/dist/lib/security/AccessControlListMongo.js.map +1 -0
- package/dist/lib/security/AccessControlListSQL.js +149 -0
- package/dist/lib/security/AccessControlListSQL.js.map +1 -0
- package/dist/lib/security/index.js +3 -0
- package/dist/lib/security/index.js.map +1 -0
- package/dist/lib/test/index.js +3 -0
- package/dist/lib/test/index.js.map +1 -0
- package/dist/lib/test/request.js +99 -0
- package/dist/lib/test/request.js.map +1 -0
- package/dist/lib/test/requestws.js +173 -0
- package/dist/lib/test/requestws.js.map +1 -0
- package/dist/types/ApiErrors.d.ts +38 -0
- package/dist/types/BackgroundService.d.ts +30 -0
- package/dist/types/BackgroundServiceManager.d.ts +66 -0
- package/dist/types/BulkError.d.ts +11 -0
- package/dist/types/EventListenerManager.d.ts +36 -0
- package/dist/types/NetUtils.d.ts +29 -0
- package/dist/types/NotificationUtils.d.ts +25 -0
- package/dist/types/ObjectFactory.d.ts +17 -0
- package/dist/types/OpenApiSpec.d.ts +114 -0
- package/dist/types/Server.d.ts +180 -0
- package/dist/types/Types.d.ts +8 -0
- package/dist/types/auth/AuthMiddleware.d.ts +42 -0
- package/dist/types/auth/AuthStrategy.d.ts +32 -0
- package/dist/types/auth/BasicStrategy.d.ts +33 -0
- package/dist/types/auth/JWTStrategy.d.ts +61 -0
- package/dist/types/auth/index.d.ts +4 -0
- package/dist/types/database/ConnectionKinds.d.ts +7 -0
- package/dist/types/database/ConnectionManager.d.ts +35 -0
- package/dist/types/database/MongoConnection.d.ts +54 -0
- package/dist/types/database/MongoRepository.d.ts +92 -0
- package/dist/types/database/MongoSchemaSync.d.ts +41 -0
- package/dist/types/database/NamingUtils.d.ts +24 -0
- package/dist/types/database/TypeOrmSupport.d.ts +20 -0
- package/dist/types/database/index.d.ts +6 -0
- package/dist/types/decorators/DatabaseDecorators.d.ts +18 -0
- package/dist/types/decorators/DocDecorators.d.ts +69 -0
- package/dist/types/decorators/EventDecorators.d.ts +12 -0
- package/dist/types/decorators/ModelDecorators.d.ts +80 -0
- package/dist/types/decorators/PersistenceDecorators.d.ts +117 -0
- package/dist/types/decorators/RouteDecorators.d.ts +172 -0
- package/dist/types/decorators/index.d.ts +6 -0
- package/dist/types/http/Adapters.d.ts +68 -0
- package/dist/types/http/Router.d.ts +99 -0
- package/dist/types/http/WebSocket.d.ts +56 -0
- package/dist/types/http/index.d.ts +6 -0
- package/dist/types/http/types.d.ts +54 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/models/BaseEntity.d.ts +29 -0
- package/dist/types/models/BaseMongoEntity.d.ts +13 -0
- package/dist/types/models/ModelUtils.d.ts +166 -0
- package/dist/types/models/RecoverableBaseEntity.d.ts +16 -0
- package/dist/types/models/RecoverableBaseMongoEntity.d.ts +16 -0
- package/dist/types/models/RepoUtils.d.ts +154 -0
- package/dist/types/models/SimpleEntity.d.ts +14 -0
- package/dist/types/models/SimpleMongoEntity.d.ts +15 -0
- package/dist/types/models/StatusExtraData.d.ts +6 -0
- package/dist/types/models/index.d.ts +9 -0
- package/dist/types/routes/AdminRoute.d.ts +47 -0
- package/dist/types/routes/MetricsRoute.d.ts +15 -0
- package/dist/types/routes/ModelRoute.d.ts +226 -0
- package/dist/types/routes/OpenAPIRoute.d.ts +17 -0
- package/dist/types/routes/RouteUtils.d.ts +55 -0
- package/dist/types/routes/StatusRoute.d.ts +11 -0
- package/dist/types/routes/index.d.ts +6 -0
- package/dist/types/security/ACLRouteMongo.d.ts +19 -0
- package/dist/types/security/ACLRouteSQL.d.ts +19 -0
- package/dist/types/security/ACLUtils.d.ts +94 -0
- package/dist/types/security/AccessControlList.d.ts +103 -0
- package/dist/types/security/AccessControlListMongo.d.ts +24 -0
- package/dist/types/security/AccessControlListSQL.d.ts +24 -0
- package/dist/types/security/index.d.ts +2 -0
- package/dist/types/test/index.d.ts +2 -0
- package/dist/types/test/request.d.ts +24 -0
- package/dist/types/test/requestws.d.ts +21 -0
- package/docs/Makefile +20 -0
- package/docs/conf.py +58 -0
- package/docs/index.rst +17 -0
- package/docs/make.bat +35 -0
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/README.md +13 -0
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/MongoRepository.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/RedisConnection.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/Repository.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/README.md +23 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Default.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Description.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Document.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Example.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Format.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Returns.md +28 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Summary.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Tags.md +25 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/TypeInfo.md +28 -0
- package/docs/reference/@rapidrest/namespaces/DocDecorators/interfaces/DocumentsData.md +57 -0
- package/docs/reference/@rapidrest/namespaces/EventDecorators/README.md +12 -0
- package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/EventListener.md +17 -0
- package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/OnEvent.md +26 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/README.md +26 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Cache.md +25 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/ChildEntity.md +18 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/DataStore.md +25 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Identifier.md +27 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Protect.md +35 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Reference.md +25 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Shard.md +27 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/TrackChanges.md +26 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/interfaces/PendingTypeOrmColumn.md +45 -0
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/variables/pendingTypeOrmColumns.md +14 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/README.md +25 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Column.md +25 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Entity.md +26 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Index.md +119 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/PrimaryColumn.md +25 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Unique.md +68 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getColumnMetadata.md +26 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getEntityName.md +26 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getIndexMetadata.md +27 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnInfo.md +41 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnOptions.md +51 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexInfo.md +41 -0
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexOptions.md +51 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/README.md +36 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/After.md +26 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Auth.md +33 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/AuthResult.md +31 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Before.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/ContentType.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Delete.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Get.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Head.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Header.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Method.md +31 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Model.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Options.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Param.md +26 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Patch.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Post.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Protect.md +31 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Put.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Query.md +26 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Request.md +31 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/RequiresRole.md +26 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Response.md +31 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Route.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Socket.md +33 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/User.md +31 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Validate.md +25 -0
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/WebSocket.md +25 -0
- package/docs/reference/README.md +20 -0
- package/docs/reference/classes/ACLUtils.md +251 -0
- package/docs/reference/classes/AdminRoute.md +51 -0
- package/docs/reference/classes/AuthMiddleware.md +131 -0
- package/docs/reference/classes/BackgroundService.md +117 -0
- package/docs/reference/classes/BackgroundServiceManager.md +172 -0
- package/docs/reference/classes/BaseEntity.md +82 -0
- package/docs/reference/classes/BaseMongoEntity.md +107 -0
- package/docs/reference/classes/BasicStrategy.md +89 -0
- package/docs/reference/classes/BasicStrategyOptions.md +91 -0
- package/docs/reference/classes/BulkError.md +271 -0
- package/docs/reference/classes/ConnectionManager.md +75 -0
- package/docs/reference/classes/EventListenerManager.md +88 -0
- package/docs/reference/classes/JWTStrategy.md +77 -0
- package/docs/reference/classes/JWTStrategyOptions.md +97 -0
- package/docs/reference/classes/MetricsRoute.md +27 -0
- package/docs/reference/classes/ModelRoute.md +527 -0
- package/docs/reference/classes/ModelUtils.md +448 -0
- package/docs/reference/classes/MongoConnection.md +218 -0
- package/docs/reference/classes/MongoRepository.md +354 -0
- package/docs/reference/classes/MongoSchemaSync.md +67 -0
- package/docs/reference/classes/NetUtils.md +90 -0
- package/docs/reference/classes/NotificationUtils.md +77 -0
- package/docs/reference/classes/ObjectFactory.md +336 -0
- package/docs/reference/classes/OpenAPIRoute.md +77 -0
- package/docs/reference/classes/OpenApiSpec.md +892 -0
- package/docs/reference/classes/RecoverableBaseEntity.md +114 -0
- package/docs/reference/classes/RecoverableBaseMongoEntity.md +124 -0
- package/docs/reference/classes/RedisTransport.md +2202 -0
- package/docs/reference/classes/RepoUtils.md +486 -0
- package/docs/reference/classes/RouteUtils.md +191 -0
- package/docs/reference/classes/Server.md +408 -0
- package/docs/reference/classes/SimpleEntity.md +48 -0
- package/docs/reference/classes/SimpleMongoEntity.md +66 -0
- package/docs/reference/classes/StatusExtraData.md +57 -0
- package/docs/reference/classes/StatusRoute.md +26 -0
- package/docs/reference/enumerations/ACLAction.md +63 -0
- package/docs/reference/enumerations/ApiErrorMessages.md +123 -0
- package/docs/reference/enumerations/ApiErrors.md +123 -0
- package/docs/reference/functions/isSqlDataSource.md +26 -0
- package/docs/reference/functions/resolveCollectionName.md +33 -0
- package/docs/reference/functions/snakeCase.md +28 -0
- package/docs/reference/globals.md +91 -0
- package/docs/reference/interfaces/ACLRecord.md +96 -0
- package/docs/reference/interfaces/AccessControlList.md +76 -0
- package/docs/reference/interfaces/AuthResult.md +55 -0
- package/docs/reference/interfaces/AuthStrategy.md +57 -0
- package/docs/reference/interfaces/CreateRequestOptions.md +121 -0
- package/docs/reference/interfaces/DeleteRequestOptions.md +147 -0
- package/docs/reference/interfaces/FindRequestOptions.md +133 -0
- package/docs/reference/interfaces/JWTAuthResult.md +84 -0
- package/docs/reference/interfaces/RepoCreateOptions.md +95 -0
- package/docs/reference/interfaces/RepoDeleteOptions.md +115 -0
- package/docs/reference/interfaces/RepoFindOptions.md +135 -0
- package/docs/reference/interfaces/RepoOperationOptions.md +69 -0
- package/docs/reference/interfaces/RepoUpdateOptions.md +111 -0
- package/docs/reference/interfaces/RequestOptions.md +112 -0
- package/docs/reference/interfaces/TruncateRequestOptions.md +175 -0
- package/docs/reference/interfaces/UpdateRequestOptions.md +149 -0
- package/docs/reference/type-aliases/OneOrMany.md +19 -0
- package/docs/reference/type-aliases/OneOrNull.md +19 -0
- package/docs/reference/type-aliases/PartialBaseEntity.md +17 -0
- package/docs/reference/type-aliases/PartialSimpleEntity.md +17 -0
- package/docs/reference/type-aliases/UpdateObject.md +19 -0
- package/package.json +125 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import { ObjectFactory } from "./ObjectFactory.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `EventListenerManager` is responsible for managing event handlers and processing of incoming
|
|
5
|
+
* events from the configured redis pubsub channels. An event handler is any function that has been
|
|
6
|
+
* decorated with the `@OnEvent` decorator and registered with this manager. Once registered, any event
|
|
7
|
+
* that is received corresponding to the list of types specified in the decorator arguments will be
|
|
8
|
+
* sent to the designated function(s). If no type is specified, the handler function will be called
|
|
9
|
+
* for any event that is received.
|
|
10
|
+
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
11
|
+
*/
|
|
12
|
+
export declare class EventListenerManager {
|
|
13
|
+
private channels;
|
|
14
|
+
private logger;
|
|
15
|
+
private objectFactory;
|
|
16
|
+
private handlers;
|
|
17
|
+
private redis;
|
|
18
|
+
constructor(objectFactory: ObjectFactory, redis: Redis);
|
|
19
|
+
init(): Promise<void>;
|
|
20
|
+
destroy(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Handler function for events that arrive from redis.
|
|
23
|
+
*/
|
|
24
|
+
private onEvent;
|
|
25
|
+
/**
|
|
26
|
+
* Adds the given function to the list of designated event handlers for the specified type.
|
|
27
|
+
* @param event The type of event to add a handler for
|
|
28
|
+
* @param func The function to add
|
|
29
|
+
*/
|
|
30
|
+
private addEventHandler;
|
|
31
|
+
/**
|
|
32
|
+
* Registers the given object to be notified of events that arrive.
|
|
33
|
+
* @param obj The object to register for event handling.
|
|
34
|
+
*/
|
|
35
|
+
register(obj: any): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpRequest as XRequest } from "./http/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provides common utilities and functions for working with networking related problems.
|
|
4
|
+
*
|
|
5
|
+
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
6
|
+
*/
|
|
7
|
+
export declare class NetUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Performs DNS lookup of the IP address from a given url.
|
|
10
|
+
*
|
|
11
|
+
* @param url The url to lookup the IP from.
|
|
12
|
+
* @param family ip family used for dns lookup
|
|
13
|
+
* @returns A `string` containing the IP address if found, otherwise `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
static lookupIPAddress(url: string, family?: number): Promise<string | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts the IP address from a given url or HTTP request.
|
|
18
|
+
*
|
|
19
|
+
* When `trustedProxies` is provided, forwarding headers (`X-Forwarded-For`, etc.) are
|
|
20
|
+
* only trusted when the direct connection's `remoteAddress` is in that list. Without a
|
|
21
|
+
* trusted-proxy list the headers are ignored and the socket address is returned directly,
|
|
22
|
+
* preventing clients from spoofing their IP in audit logs.
|
|
23
|
+
*
|
|
24
|
+
* @param urlOrRequest The url or HTTP request to extract the IP from.
|
|
25
|
+
* @param trustedProxies Optional list of proxy IP addresses whose forwarding headers should be trusted.
|
|
26
|
+
* @returns A `string` containing the IP address if found, otherwise `undefined`.
|
|
27
|
+
*/
|
|
28
|
+
static getIPAddress(urlOrRequest: string | XRequest, trustedProxies?: string[]): string | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for sending push notifications to registered clients.
|
|
4
|
+
*
|
|
5
|
+
* @author Jean-Philippe Steinmetz
|
|
6
|
+
*/
|
|
7
|
+
export declare class NotificationUtils {
|
|
8
|
+
/** The redis client to use for broadcasting messages. */
|
|
9
|
+
private redis;
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the utility using the given redis connection.
|
|
12
|
+
*
|
|
13
|
+
* @param {any} redis The redis connection to publish to.
|
|
14
|
+
*/
|
|
15
|
+
constructor(redis: Redis);
|
|
16
|
+
/**
|
|
17
|
+
* Sends a given message to the room or user with the specified uid(s).
|
|
18
|
+
*
|
|
19
|
+
* @param {string} uids The universally unique identifier of the room or user to send the message to.
|
|
20
|
+
* @param {string} type The type of message being sent.
|
|
21
|
+
* @param {string} action The action performed on the data (if applicable).
|
|
22
|
+
* @param {string} data The contents of the message to send to the room or user.
|
|
23
|
+
*/
|
|
24
|
+
sendMessage(uids: string | string[], type: string, action: string, data: any): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { ObjectFactory as CoreObjectFactory } from "@rapidrest/core";
|
|
3
|
+
/**
|
|
4
|
+
* The `ObjectFactory` is a manager for creating objects based on registered
|
|
5
|
+
* class types. This allows for the tracking of multiple instances of objects
|
|
6
|
+
* so that references can be referenced by unique name.
|
|
7
|
+
*
|
|
8
|
+
* @author Jean-Philippe Steinmetz
|
|
9
|
+
*/
|
|
10
|
+
export declare class ObjectFactory extends CoreObjectFactory {
|
|
11
|
+
constructor(config?: any, logger?: any);
|
|
12
|
+
/**
|
|
13
|
+
* Scans the given object for any properties with the @Inject decorator and assigns the correct values.
|
|
14
|
+
* @param obj The object to initialize with injected defaults
|
|
15
|
+
*/
|
|
16
|
+
initialize<T>(obj: any): Promise<T>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { oas31 as oa } from "openapi3-ts";
|
|
2
|
+
import { DocumentsData } from "./decorators/DocDecorators.js";
|
|
3
|
+
/**
|
|
4
|
+
* `OpenApiSpec` is a container for an OpenAPI specification.
|
|
5
|
+
*
|
|
6
|
+
* This class wraps the behavior of openapi-ts to make it easier to build an OpenAPI
|
|
7
|
+
* specification dynamically at runtime using the server RapidREST information.
|
|
8
|
+
*
|
|
9
|
+
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
10
|
+
*/
|
|
11
|
+
export declare class OpenApiSpec {
|
|
12
|
+
private _builder;
|
|
13
|
+
private config?;
|
|
14
|
+
constructor(spec?: oa.OpenAPIObject);
|
|
15
|
+
get builder(): oa.OpenApiBuilder;
|
|
16
|
+
set builder(value: oa.OpenApiBuilder);
|
|
17
|
+
get openapi(): string;
|
|
18
|
+
get info(): oa.InfoObject;
|
|
19
|
+
get servers(): oa.ServerObject[] | undefined;
|
|
20
|
+
get paths(): oa.PathsObject | undefined;
|
|
21
|
+
get components(): oa.ComponentsObject | undefined;
|
|
22
|
+
get security(): oa.SecurityRequirementObject[] | undefined;
|
|
23
|
+
get tags(): oa.TagObject[] | undefined;
|
|
24
|
+
get externalDocs(): oa.ExternalDocumentationObject | undefined;
|
|
25
|
+
get webhooks(): oa.PathsObject | undefined;
|
|
26
|
+
private init;
|
|
27
|
+
getSpec(): oa.OpenAPIObject;
|
|
28
|
+
getSpecAsJson(replacer?: (key: string, value: unknown) => unknown, space?: string | number): string;
|
|
29
|
+
getSpecAsYaml(): string;
|
|
30
|
+
addOpenApiVersion(openApiVersion: string): OpenApiSpec;
|
|
31
|
+
addInfo(info: oa.InfoObject): OpenApiSpec;
|
|
32
|
+
addContact(contact: oa.ContactObject): OpenApiSpec;
|
|
33
|
+
addLicense(license: oa.LicenseObject): OpenApiSpec;
|
|
34
|
+
addTitle(title: string): OpenApiSpec;
|
|
35
|
+
addDescription(description: string): OpenApiSpec;
|
|
36
|
+
addTermsOfService(termsOfService: string): OpenApiSpec;
|
|
37
|
+
addVersion(version: string): OpenApiSpec;
|
|
38
|
+
addPath(path: string, pathItem: oa.PathItemObject): OpenApiSpec;
|
|
39
|
+
addSchema(name: string, schema: oa.SchemaObject | oa.ReferenceObject): OpenApiSpec;
|
|
40
|
+
addResponse(name: string, response: oa.ResponseObject | oa.ReferenceObject): OpenApiSpec;
|
|
41
|
+
addParameter(name: string, parameter: oa.ParameterObject | oa.ReferenceObject): OpenApiSpec;
|
|
42
|
+
addExample(name: string, example: oa.ExampleObject | oa.ReferenceObject): OpenApiSpec;
|
|
43
|
+
addRequestBody(name: string, reqBody: oa.RequestBodyObject | oa.ReferenceObject): OpenApiSpec;
|
|
44
|
+
addHeader(name: string, header: oa.HeaderObject | oa.ReferenceObject): OpenApiSpec;
|
|
45
|
+
addSecurityScheme(name: string, secScheme: oa.SecuritySchemeObject | oa.ReferenceObject): OpenApiSpec;
|
|
46
|
+
addLink(name: string, link: oa.LinkObject | oa.ReferenceObject): OpenApiSpec;
|
|
47
|
+
addCallback(name: string, callback: oa.CallbackObject | oa.ReferenceObject): OpenApiSpec;
|
|
48
|
+
addServer(server: oa.ServerObject): OpenApiSpec;
|
|
49
|
+
addTag(tag: oa.TagObject): OpenApiSpec;
|
|
50
|
+
addExternalDocs(extDoc: oa.ExternalDocumentationObject): OpenApiSpec;
|
|
51
|
+
addWebhook(webhook: string, webhookItem: oa.PathItemObject): OpenApiSpec;
|
|
52
|
+
/**
|
|
53
|
+
* Adds a RapidREST model class to the OpenAPI specification as a schema.
|
|
54
|
+
*
|
|
55
|
+
* @param name The name of the model to add.
|
|
56
|
+
* @param clazz The class prototype to build the schema from.
|
|
57
|
+
*/
|
|
58
|
+
addModel(name: string, clazz: any): OpenApiSpec;
|
|
59
|
+
/**
|
|
60
|
+
* Adds a RapidREST route handler to the OpenAPI specification.
|
|
61
|
+
*
|
|
62
|
+
* @param name The name of the route handler. (e.g. findAll)
|
|
63
|
+
* @param path The complete path of the route handler. (e.g. `/my/resources/:id`)
|
|
64
|
+
* @param method The HTTP verb type that the route handler processes. (e.g. `GET`)
|
|
65
|
+
* @param metadata The object containing all API information about the route handler.
|
|
66
|
+
* @param docs The object containing all documentation information about the route handler.
|
|
67
|
+
* @param routeClass The parent route class that the route handler belongs to.
|
|
68
|
+
*/
|
|
69
|
+
addRoute(name: string, path: string, method: string, metadata: any, docs: DocumentsData, routeClass: any): OpenApiSpec;
|
|
70
|
+
/**
|
|
71
|
+
* Determines if the given type is a primitive or built-in class type.
|
|
72
|
+
* @param value
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
private isBuiltInType;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new SchemaObject given the specified class prototype.
|
|
78
|
+
*
|
|
79
|
+
* @param clazz The class prototype to build a schema object from.
|
|
80
|
+
* @returns The schema object with all information derived from the given class prototype.
|
|
81
|
+
*/
|
|
82
|
+
createSchemaClass(clazz: any): oa.SchemaObject;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a schema object for the given type.
|
|
85
|
+
*
|
|
86
|
+
* @param typeInfo
|
|
87
|
+
* @param defaultValue
|
|
88
|
+
* @param description
|
|
89
|
+
* @param example
|
|
90
|
+
* @param format
|
|
91
|
+
* @param identifier
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
createSchemaObject(typeInfo: any, defaultValue?: any, description?: string, example?: any, format?: string, identifier?: boolean): oa.SchemaObject | oa.ReferenceObject;
|
|
95
|
+
/**
|
|
96
|
+
* Returns a reference to an existing parameter defined in the OpenAPI specification for the given name.
|
|
97
|
+
*
|
|
98
|
+
* @param name The name of the parameter to find a reference for.
|
|
99
|
+
* @returns The reference to the parameter with the given name, otherwise `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
getParameterReference(name: string): oa.ReferenceObject | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a reference to an existing schema defined in the OpenAPI specification for the given name.
|
|
104
|
+
*
|
|
105
|
+
* @param name The name of the schema to find a reference for.
|
|
106
|
+
* @returns The reference to the schema with the given name, otherwise `undefined`.
|
|
107
|
+
*/
|
|
108
|
+
getSchemaReference(name: string): oa.ReferenceObject | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Merges a provided OpenAPI specification with this specification.
|
|
111
|
+
* @param other The other OpenAPI spec object to merge.
|
|
112
|
+
*/
|
|
113
|
+
merge(other: any): void;
|
|
114
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as prom from "prom-client";
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
import { ConnectionManager } from "./database/ConnectionManager.js";
|
|
4
|
+
import { ObjectFactory } from "./ObjectFactory.js";
|
|
5
|
+
import { BackgroundServiceManager } from "./BackgroundServiceManager.js";
|
|
6
|
+
import { RouteUtils } from "./routes/RouteUtils.js";
|
|
7
|
+
import { OpenApiSpec } from "./OpenApiSpec.js";
|
|
8
|
+
import { EventListenerManager } from "./EventListenerManager.js";
|
|
9
|
+
import { HttpRouter } from "./http/Router.js";
|
|
10
|
+
/**
|
|
11
|
+
* Provides an HTTP server utilizing uWebSockets.js. The server automatically registers all routes, and
|
|
12
|
+
* establishes database connections for all configured data stores. Additionally provides automatic authentication
|
|
13
|
+
* handling using JSON Web Token (JWT) directly — no Passport dependency required. When provided an OpenAPI
|
|
14
|
+
* specification object the server will also automatically serve this specification via the `GET /openapi.json` route.
|
|
15
|
+
*
|
|
16
|
+
* Routes are defined by creating any class definition using the various decorators found in `RouteDecorators` and
|
|
17
|
+
* saving these files in the `routes` subfolder. Upon server start, the `routes` folder is scanned for any class
|
|
18
|
+
* that has been decorated with `@Route` and is automatically loaded and registered. Similarly, if the
|
|
19
|
+
* class is decorated with the `@Model` decorator the resulting route object will have the associated data model
|
|
20
|
+
* definition object injected into the constructor.
|
|
21
|
+
*
|
|
22
|
+
* SSL termination is supported by providing an `ssl` configuration block with `key`, `cert`, and optionally
|
|
23
|
+
* `ca` and `passphrase` file paths. When `ssl` is present the server uses `uWS.SSLApp()`.
|
|
24
|
+
*
|
|
25
|
+
* IPv6 is supported by setting `listen_host` to `"::"` in configuration (default `"0.0.0.0"`).
|
|
26
|
+
*
|
|
27
|
+
* By default all registered endpoints that do not explicitly have an `@Auth` decorator have the `JWT`
|
|
28
|
+
* authentication strategy applied. This allows users to be implicitly authenticated without requiring additional
|
|
29
|
+
* configuration. Once authenticated, the provided `request` argument will have the `user` property available
|
|
30
|
+
* containing information about the authenticated user. If the `user` property is `undefined` then no user has
|
|
31
|
+
* been authenticated or the authentication attempt failed.
|
|
32
|
+
*
|
|
33
|
+
* The following is an example of a simple route class.
|
|
34
|
+
*
|
|
35
|
+
* ```javascript
|
|
36
|
+
* import { DefaultBehaviors, RouteDecorators } from "@rapidrest/service-core";
|
|
37
|
+
* import { Get, Route } = RouteDecorators;
|
|
38
|
+
*
|
|
39
|
+
* @Route("/hello")
|
|
40
|
+
* class TestRoute extends ModelRoute {
|
|
41
|
+
* constructor(model: any) {
|
|
42
|
+
* super(model);
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* @Get()
|
|
46
|
+
* count(req: any, res: any, next: Function): any {
|
|
47
|
+
* return res.send("Hello World!");
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* export default TestRoute;
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* The following is an example of a route class that is bound to a data model providing basic CRUDS operations.
|
|
55
|
+
*
|
|
56
|
+
* ```javascript
|
|
57
|
+
* import { DefaultBehaviors, ModelDecorators, ModelRoute, RouteDecorators } from "@rapidrest/service-core";
|
|
58
|
+
* import { After, Before, Delete, Get, Post, Put, Route, Validate } = RouteDecorators;
|
|
59
|
+
* import { Model } = ModelDecorators;
|
|
60
|
+
* import { marshall } = DefaultBehaviors;
|
|
61
|
+
*
|
|
62
|
+
* @Model("Item")
|
|
63
|
+
* @Route("/items")
|
|
64
|
+
* class ItemRoute extends ModelRoute {
|
|
65
|
+
* constructor(model: any) {
|
|
66
|
+
* super(model);
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* @Get()
|
|
70
|
+
* @Before(super.count)
|
|
71
|
+
* @After(marshall)
|
|
72
|
+
* count(req: any, res: any, next: Function): any {
|
|
73
|
+
* return next();
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* @Post()
|
|
77
|
+
* @Before([super.create])
|
|
78
|
+
* @After([this.prepare, marshall])
|
|
79
|
+
* create(req: any, res: any, next: Function): any {
|
|
80
|
+
* return next();
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* @Delete(":id")
|
|
84
|
+
* @Before([super.delete])
|
|
85
|
+
* delete(req: any, res: any, next: Function): any {
|
|
86
|
+
* return next();
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* @Get()
|
|
90
|
+
* @Before([super.findAll])
|
|
91
|
+
* @After(this.prepareAndSend)
|
|
92
|
+
* findAll(req: any, res: any, next: Function): any {
|
|
93
|
+
* return next();
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* @Get(":id")
|
|
97
|
+
* @Before([super.findById])
|
|
98
|
+
* @After([this.prepare, marshall])
|
|
99
|
+
* findById(req: any, res: any, next: Function): any {
|
|
100
|
+
* return next();
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* @Put(":id")
|
|
104
|
+
* @Before([super.update])
|
|
105
|
+
* @After([this.prepare, marshall])
|
|
106
|
+
* update(req: any, res: any, next: Function): any {
|
|
107
|
+
* return next();
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* export default ItemRoute;
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @author Jean-Philippe Steinmetz
|
|
115
|
+
*/
|
|
116
|
+
export declare class Server {
|
|
117
|
+
/** The OpenAPI specification object to use to construct the server with. */
|
|
118
|
+
protected apiSpec?: OpenApiSpec;
|
|
119
|
+
/** The underlying HTTP router (uWS-backed) that provides HTTP processing services. */
|
|
120
|
+
protected app: HttpRouter;
|
|
121
|
+
/** The base file system path that will be searched for models and routes. */
|
|
122
|
+
protected readonly basePath: string;
|
|
123
|
+
/** The global object containing configuration information to use. */
|
|
124
|
+
protected readonly config?: any;
|
|
125
|
+
/** The manager for handling database connections. */
|
|
126
|
+
protected connectionManager?: ConnectionManager;
|
|
127
|
+
/** The manager for handling events. */
|
|
128
|
+
protected eventListenerManager?: EventListenerManager;
|
|
129
|
+
/** The logging utility to use when outputing to console/file. */
|
|
130
|
+
protected readonly logger: any;
|
|
131
|
+
/** The object factory to use when injecting dependencies. */
|
|
132
|
+
protected readonly objectFactory: ObjectFactory;
|
|
133
|
+
/** The port that the server is listening on. */
|
|
134
|
+
readonly port: number;
|
|
135
|
+
protected routeUtils?: RouteUtils;
|
|
136
|
+
protected serviceManager?: BackgroundServiceManager;
|
|
137
|
+
protected metricRequestPath: prom.Counter<string>;
|
|
138
|
+
protected metricRequestStatus: prom.Counter<string>;
|
|
139
|
+
protected metricRequestTime: prom.Histogram<string>;
|
|
140
|
+
protected metricCompletedRequests: prom.Counter<string>;
|
|
141
|
+
protected metricFailedRequests: prom.Counter<string>;
|
|
142
|
+
protected metricTotalRequests: prom.Counter<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a new instance of Server with the specified defaults.
|
|
145
|
+
*
|
|
146
|
+
* @param {any} config The nconf-compatible configuration object to initialize the server with.
|
|
147
|
+
* @param {string} basePath The base file system path that models and routes will be searched from.
|
|
148
|
+
* @param {Logger} logger The logging utility to use for outputing to console/file.
|
|
149
|
+
* @param objectFactory The object factory to use for automatic dependency injection (IOC).
|
|
150
|
+
*/
|
|
151
|
+
constructor(config: any, basePath?: string, logger?: any, objectFactory?: ObjectFactory);
|
|
152
|
+
/**
|
|
153
|
+
* Returns the HTTP router instance.
|
|
154
|
+
*/
|
|
155
|
+
getApplication(): HttpRouter;
|
|
156
|
+
/**
|
|
157
|
+
* Returns `true` if the server is running, otherwise `false`.
|
|
158
|
+
*/
|
|
159
|
+
isRunning(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Override this function to add custom behavior before the server is started.
|
|
162
|
+
*/
|
|
163
|
+
protected preStart(): void | Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Override this function to add custom behavior after the server is started.
|
|
166
|
+
*/
|
|
167
|
+
protected postStart(): void | Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Starts an HTTP listen server based on the provided configuration and OpenAPI specification.
|
|
170
|
+
*/
|
|
171
|
+
start(): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Stops the HTTP listen server.
|
|
174
|
+
*/
|
|
175
|
+
stop(): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Restarts the HTTP listen server using the provided configuration and OpenAPI specification.
|
|
178
|
+
*/
|
|
179
|
+
restart(): Promise<void>;
|
|
180
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse, RequestHandler } from "../http/types.js";
|
|
2
|
+
import { AuthResult, AuthStrategy } from "./AuthStrategy.js";
|
|
3
|
+
/**
|
|
4
|
+
* A set of common utilities for performing authentication using one or more strategies.
|
|
5
|
+
*
|
|
6
|
+
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
7
|
+
*/
|
|
8
|
+
export declare class AuthMiddleware {
|
|
9
|
+
private authConfig;
|
|
10
|
+
private authSocketTimeout;
|
|
11
|
+
private objectFactory?;
|
|
12
|
+
/** The authentication strategies that have been registered. */
|
|
13
|
+
readonly strategies: Map<string, AuthStrategy>;
|
|
14
|
+
private init;
|
|
15
|
+
/**
|
|
16
|
+
* Performs authentication of the given request using one of the provided strategies.
|
|
17
|
+
*
|
|
18
|
+
* @param strategies The list of strategy names to attempt authentication with.
|
|
19
|
+
* @param req The request containing data to perform authenticate with.
|
|
20
|
+
* @param res The response to use when writing back directly to the client.
|
|
21
|
+
* @param required Set to `true` to if authentication is required to pass, otherwise set to `false`.
|
|
22
|
+
*/
|
|
23
|
+
authenticate(strategies: string[], req: HttpRequest, res?: HttpResponse, required?: boolean): AuthResult | Promise<AuthResult> | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a request handler function that will perform authentication of a websocket connection. Authentication
|
|
26
|
+
* can be handled in two ways:
|
|
27
|
+
*
|
|
28
|
+
* 1. Authorization header
|
|
29
|
+
* 2. Negotiation via handshake
|
|
30
|
+
*
|
|
31
|
+
* This middleware function primarily provides the implementation for item 2 above.
|
|
32
|
+
*
|
|
33
|
+
* @param required Set to `true` to indicate that auth is required, otherwise `false`.
|
|
34
|
+
*/
|
|
35
|
+
authWebSocket(required: boolean): RequestHandler;
|
|
36
|
+
/**
|
|
37
|
+
* Registers the provided authentication strategy to be used
|
|
38
|
+
* @param name The name of the authentication type to associate the given strategy with
|
|
39
|
+
* @param strategy The strategy to register
|
|
40
|
+
*/
|
|
41
|
+
register(name: string, strategy: AuthStrategy): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { JWTUser } from "@rapidrest/core";
|
|
2
|
+
import { HttpRequest, HttpResponse } from "../http/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Result returned by `AuthStrategy.authenticate()`.
|
|
5
|
+
*/
|
|
6
|
+
export interface AuthResult {
|
|
7
|
+
/** The raw auth data that was verified. */
|
|
8
|
+
data?: string;
|
|
9
|
+
/** The name of the auth strategy that produced this result. */
|
|
10
|
+
method: string;
|
|
11
|
+
/** The fully decoded payload from the auth data. */
|
|
12
|
+
payload?: any;
|
|
13
|
+
/** The authenticated user profile, or `undefined` if authentication failed. */
|
|
14
|
+
user?: JWTUser;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Describes an interface for implementing strategies that will perform authentication.
|
|
18
|
+
*/
|
|
19
|
+
export interface AuthStrategy {
|
|
20
|
+
/** The unique name of the strategy used to register with the `AuthMiddleware`. */
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/**
|
|
23
|
+
* Attempts to perform authentication with the given request data. If authentication was successful, returns an
|
|
24
|
+
* `AuthResult` containing the authentication details. If authentication fails and `required` is set to `true`
|
|
25
|
+
* throws an error, otherwise returns `undefined`.
|
|
26
|
+
*
|
|
27
|
+
* @param req The request containing data to attempt authentication with.
|
|
28
|
+
* @param res The response to use when writing back directly to the client.
|
|
29
|
+
* @param required Set to `true` to if authentication is required to pass, otherwise set to `false`.
|
|
30
|
+
*/
|
|
31
|
+
authenticate(req: HttpRequest, res?: HttpResponse, required?: boolean): AuthResult | Promise<AuthResult> | undefined;
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { JWTUser } from "@rapidrest/core";
|
|
2
|
+
import { HttpRequest, HttpResponse } from "../http/types.js";
|
|
3
|
+
import { AuthResult, AuthStrategy } from "./AuthStrategy.js";
|
|
4
|
+
/**
|
|
5
|
+
* Describes the configuration options that can be used to initialize BasicStrategy.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class BasicStrategyOptions {
|
|
10
|
+
/** The name of the header to look for when performing header based authentication. Default value is `Authorization`. */
|
|
11
|
+
headerKey: string;
|
|
12
|
+
/** The authorization scheme type when using header based authentication. Default value is `jwt`. */
|
|
13
|
+
headerScheme: string;
|
|
14
|
+
/** The name of the request query parameter to retrieve the token from when using query based authentication. Default value is `auth_basic`. */
|
|
15
|
+
queryKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* Set to `true` to allow credentials to be supplied via the `queryKey` URL parameter.
|
|
18
|
+
* Disabled by default — query parameters appear in server logs, browser history, and
|
|
19
|
+
* Referer headers, which permanently exposes credentials outside the application.
|
|
20
|
+
*/
|
|
21
|
+
allowQueryParam: boolean;
|
|
22
|
+
/** You must override this function to perform verification of the login information. */
|
|
23
|
+
verify(uid: string, secret: string): JWTUser | Promise<JWTUser> | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
27
|
+
*/
|
|
28
|
+
export declare class BasicStrategy implements AuthStrategy {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
private options;
|
|
31
|
+
constructor(options?: BasicStrategyOptions);
|
|
32
|
+
authenticate(req: HttpRequest, res: HttpResponse, required?: boolean): AuthResult | Promise<AuthResult> | undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { JWTUtilsConfig } from "@rapidrest/core";
|
|
2
|
+
import type { HttpRequest, HttpResponse } from "../http/types.js";
|
|
3
|
+
import { AuthResult } from "./AuthStrategy.js";
|
|
4
|
+
/**
|
|
5
|
+
* Describes the configuration options that can be used to initialize JWTStrategy.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class JWTStrategyOptions {
|
|
10
|
+
/** The configuration options to pass to the JWTUtils library during token verification. */
|
|
11
|
+
config?: JWTUtilsConfig;
|
|
12
|
+
/** The name of the header to look for when performing header based authentication. Default value is `Authorization`. */
|
|
13
|
+
headerKey: string;
|
|
14
|
+
/** The authorization scheme type when using header based authentication. Default value is `jwt`. */
|
|
15
|
+
headerScheme: string;
|
|
16
|
+
/** The name of the cookie to retrieve the token from when using cookie based authentication. Default value is `jwt`. */
|
|
17
|
+
cookieName: string;
|
|
18
|
+
/** The name of the secured cookie to retreive the token from when using cookie based authentication. */
|
|
19
|
+
cookieSecure: boolean;
|
|
20
|
+
/** The name of the request query parameter to retrieve the token from when using query based authentication. Default value is `auth_token`. */
|
|
21
|
+
queryKey: string;
|
|
22
|
+
/**
|
|
23
|
+
* Set to `true` to allow tokens to be supplied via the `queryKey` URL parameter.
|
|
24
|
+
* Disabled by default — query parameters appear in server logs, browser history, and
|
|
25
|
+
* Referer headers, which permanently exposes tokens outside the application.
|
|
26
|
+
*/
|
|
27
|
+
allowQueryParam: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Result returned by `JWTStrategy.authenticate()`. */
|
|
30
|
+
export interface JWTAuthResult extends AuthResult {
|
|
31
|
+
/**
|
|
32
|
+
* `true` when at least one credential (header, query param, or cookie) was present in
|
|
33
|
+
* the request, even if it was ultimately invalid. Distinguishes "no token submitted" from
|
|
34
|
+
* "bad token submitted" — useful for deciding whether to reject early vs. fall through to
|
|
35
|
+
* an alternative auth path (e.g. WebSocket message-based LOGIN).
|
|
36
|
+
*/
|
|
37
|
+
tokenFound?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* JWT authentication strategy. Performs JWT verification and searches for a token by one of the
|
|
41
|
+
* following methods (in order of precedence):
|
|
42
|
+
* * Query Parameter
|
|
43
|
+
* * Authorization Header
|
|
44
|
+
* * Cookie
|
|
45
|
+
*
|
|
46
|
+
* This class no longer extends `passport-strategy`; it is used directly by route middleware
|
|
47
|
+
* and returns a plain result object instead of calling Passport callbacks.
|
|
48
|
+
*
|
|
49
|
+
* @author Jean-Philippe Steinmetz
|
|
50
|
+
*/
|
|
51
|
+
export declare class JWTStrategy {
|
|
52
|
+
private config;
|
|
53
|
+
readonly name: string;
|
|
54
|
+
private options;
|
|
55
|
+
constructor(options?: JWTStrategyOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Attempts to authenticate the incoming request by extracting and verifying a JWT token.
|
|
58
|
+
* Returns a `JWTAuthResult` describing the outcome.
|
|
59
|
+
*/
|
|
60
|
+
authenticate(req: HttpRequest, res: HttpResponse, required?: boolean): JWTAuthResult | undefined;
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines whether the given connection object is a TypeORM `DataSource` for a SQL database. This check is
|
|
3
|
+
* performed without importing the optional `typeorm` package by duck-typing the connection object.
|
|
4
|
+
*
|
|
5
|
+
* @param conn The connection object to inspect.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSqlDataSource(conn: any): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import type { DataSource } from "typeorm";
|
|
3
|
+
import { MongoConnection } from "./MongoConnection.js";
|
|
4
|
+
/**
|
|
5
|
+
* Provides database connection management.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class ConnectionManager {
|
|
10
|
+
connections: Map<string, DataSource | MongoConnection | Redis>;
|
|
11
|
+
private logger;
|
|
12
|
+
/**
|
|
13
|
+
* Builds a compatible connection URI for the database by the provided configuration.
|
|
14
|
+
*/
|
|
15
|
+
private buildConnectionUri;
|
|
16
|
+
/**
|
|
17
|
+
* Dynamically imports the given optional peer dependency, throwing a helpful error if it is not installed.
|
|
18
|
+
*
|
|
19
|
+
* @param pkg The name of the package to import.
|
|
20
|
+
* @param datastoreName The name of the datastore requiring the package.
|
|
21
|
+
* @param datastoreType The type of the datastore requiring the package.
|
|
22
|
+
*/
|
|
23
|
+
private importOptionalDependency;
|
|
24
|
+
/**
|
|
25
|
+
* Attempts to initiate all database connections as defined in the config.
|
|
26
|
+
*
|
|
27
|
+
* @param datastores A map of configured datastores to be passed to the underlying engine.
|
|
28
|
+
* @param models A map of model names and associated class definitions to establish database connections for.
|
|
29
|
+
*/
|
|
30
|
+
connect(datastores: any, models: Map<string, any>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Attempts to disconnect all active database connections.
|
|
33
|
+
*/
|
|
34
|
+
disconnect(): Promise<void>;
|
|
35
|
+
}
|