@ruiapp/rapid-core 0.1.20 → 0.1.21
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/dist/core/actionHandler.d.ts +2 -0
- package/dist/core/request.d.ts +2 -1
- package/dist/core/routeContext.d.ts +3 -1
- package/dist/core/server.d.ts +2 -0
- package/dist/dataAccess/dataAccessor.d.ts +2 -1
- package/dist/facilities/log/LogFacility.d.ts +33 -0
- package/dist/index.js +99 -171
- package/dist/plugins/auth/AuthPlugin.d.ts +0 -9
- package/dist/plugins/dataManage/DataManagePlugin.d.ts +0 -10
- package/dist/plugins/metaManage/MetaManagePlugin.d.ts +0 -8
- package/dist/plugins/routeManage/RouteManagePlugin.d.ts +0 -9
- package/dist/plugins/webhooks/WebhooksPlugin.d.ts +0 -6
- package/dist/server.d.ts +4 -1
- package/package.json +4 -1
- package/src/core/actionHandler.ts +2 -0
- package/src/core/request.ts +6 -2
- package/src/core/routeContext.ts +5 -1
- package/src/core/routesBuilder.ts +7 -2
- package/src/core/server.ts +2 -0
- package/src/dataAccess/dataAccessor.ts +6 -2
- package/src/facilities/log/LogFacility.ts +36 -0
- package/src/helpers/runCollectionEntityActionHandler.ts +3 -7
- package/src/plugins/auth/AuthPlugin.ts +3 -30
- package/src/plugins/dataManage/DataManagePlugin.ts +0 -31
- package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +2 -2
- package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +2 -2
- package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +2 -6
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +3 -8
- package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +3 -0
- package/src/plugins/metaManage/MetaManagePlugin.ts +10 -33
- package/src/plugins/routeManage/RouteManagePlugin.ts +4 -30
- package/src/plugins/routeManage/actionHandlers/httpProxy.ts +2 -1
- package/src/plugins/webhooks/WebhooksPlugin.ts +24 -34
- package/src/server.ts +22 -8
|
@@ -10,18 +10,9 @@ declare class AuthPlugin implements RapidPlugin {
|
|
|
10
10
|
get extendingAbilities(): RpdServerPluginExtendingAbilities[];
|
|
11
11
|
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
|
|
12
12
|
get configurations(): RpdConfigurationItemOptions[];
|
|
13
|
-
initPlugin(server: IRpdServer): Promise<any>;
|
|
14
|
-
registerMiddlewares(server: IRpdServer): Promise<any>;
|
|
15
13
|
registerActionHandlers(server: IRpdServer): Promise<any>;
|
|
16
|
-
registerEventHandlers(server: IRpdServer): Promise<any>;
|
|
17
|
-
registerMessageHandlers(server: IRpdServer): Promise<any>;
|
|
18
|
-
registerTaskProcessors(server: IRpdServer): Promise<any>;
|
|
19
|
-
onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
20
14
|
configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
21
|
-
configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
22
15
|
configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
23
|
-
onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
24
|
-
onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
25
16
|
onPrepareRouteContext(server: IRpdServer, routeContext: RouteContext): Promise<void>;
|
|
26
17
|
}
|
|
27
18
|
export default AuthPlugin;
|
|
@@ -11,17 +11,7 @@ declare class DataManager implements RapidPlugin {
|
|
|
11
11
|
get extendingAbilities(): RpdServerPluginExtendingAbilities[];
|
|
12
12
|
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
|
|
13
13
|
get configurations(): RpdConfigurationItemOptions[];
|
|
14
|
-
initPlugin(server: IRpdServer): Promise<any>;
|
|
15
|
-
registerMiddlewares(server: IRpdServer): Promise<any>;
|
|
16
14
|
registerActionHandlers(server: IRpdServer): Promise<any>;
|
|
17
|
-
registerEventHandlers(server: IRpdServer): Promise<any>;
|
|
18
|
-
registerMessageHandlers(server: IRpdServer): Promise<any>;
|
|
19
|
-
registerTaskProcessors(server: IRpdServer): Promise<any>;
|
|
20
|
-
onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
21
|
-
configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
22
|
-
configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
23
15
|
configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
24
|
-
onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
25
|
-
onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
26
16
|
}
|
|
27
17
|
export default DataManager;
|
|
@@ -9,17 +9,9 @@ declare class MetaManager implements RapidPlugin {
|
|
|
9
9
|
get extendingAbilities(): RpdServerPluginExtendingAbilities[];
|
|
10
10
|
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
|
|
11
11
|
get configurations(): RpdConfigurationItemOptions[];
|
|
12
|
-
initPlugin(server: IRpdServer): Promise<any>;
|
|
13
|
-
registerMiddlewares(server: IRpdServer): Promise<any>;
|
|
14
12
|
registerActionHandlers(server: IRpdServer): Promise<any>;
|
|
15
13
|
registerEventHandlers(server: IRpdServer): Promise<any>;
|
|
16
|
-
registerMessageHandlers(server: IRpdServer): Promise<any>;
|
|
17
|
-
registerTaskProcessors(server: IRpdServer): Promise<any>;
|
|
18
|
-
onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
19
14
|
configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
20
|
-
configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
21
|
-
configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
22
15
|
onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
23
|
-
onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
24
16
|
}
|
|
25
17
|
export default MetaManager;
|
|
@@ -9,17 +9,8 @@ declare class RouteManager implements RapidPlugin {
|
|
|
9
9
|
get extendingAbilities(): RpdServerPluginExtendingAbilities[];
|
|
10
10
|
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
|
|
11
11
|
get configurations(): RpdConfigurationItemOptions[];
|
|
12
|
-
initPlugin(server: IRpdServer): Promise<any>;
|
|
13
|
-
registerMiddlewares(server: IRpdServer): Promise<any>;
|
|
14
12
|
registerActionHandlers(server: IRpdServer): Promise<any>;
|
|
15
13
|
registerEventHandlers(server: IRpdServer): Promise<any>;
|
|
16
|
-
registerMessageHandlers(server: IRpdServer): Promise<any>;
|
|
17
|
-
registerTaskProcessors(server: IRpdServer): Promise<any>;
|
|
18
|
-
onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
19
|
-
configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
20
|
-
configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
21
14
|
configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
22
|
-
onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
23
|
-
onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
24
15
|
}
|
|
25
16
|
export default RouteManager;
|
|
@@ -21,13 +21,7 @@ declare class WebhooksPlugin implements RapidPlugin {
|
|
|
21
21
|
get extendingAbilities(): RpdServerPluginExtendingAbilities[];
|
|
22
22
|
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[];
|
|
23
23
|
get configurations(): RpdConfigurationItemOptions[];
|
|
24
|
-
initPlugin(server: IRpdServer): Promise<any>;
|
|
25
|
-
registerMiddlewares(server: IRpdServer): Promise<any>;
|
|
26
|
-
registerActionHandlers(server: IRpdServer): Promise<any>;
|
|
27
24
|
registerEventHandlers(server: IRpdServer): Promise<any>;
|
|
28
|
-
registerMessageHandlers(server: IRpdServer): Promise<any>;
|
|
29
|
-
registerTaskProcessors(server: IRpdServer): Promise<any>;
|
|
30
|
-
onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
31
25
|
configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
32
26
|
configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
|
33
27
|
configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any>;
|
package/dist/server.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { ActionHandler, ActionHandlerContext, IPluginActionHandler } from "./cor
|
|
|
3
3
|
import { IRpdServer, RapidPlugin } from "./core/server";
|
|
4
4
|
import { Next } from "./core/routeContext";
|
|
5
5
|
import EntityManager from "./dataAccess/entityManager";
|
|
6
|
+
import { Logger } from "./facilities/log/LogFacility";
|
|
6
7
|
export interface InitServerOptions {
|
|
8
|
+
logger: Logger;
|
|
7
9
|
databaseAccessor: IDatabaseAccessor;
|
|
8
10
|
databaseConfig: IDatabaseConfig;
|
|
9
11
|
serverConfig: RapidServerConfig;
|
|
@@ -16,6 +18,7 @@ export declare class RapidServer implements IRpdServer {
|
|
|
16
18
|
config: RapidServerConfig;
|
|
17
19
|
databaseConfig: IDatabaseConfig;
|
|
18
20
|
constructor(options: InitServerOptions);
|
|
21
|
+
getLogger(): Logger;
|
|
19
22
|
getApplicationConfig(): RpdApplicationConfig;
|
|
20
23
|
appendApplicationConfig(config: Partial<RpdApplicationConfig>): void;
|
|
21
24
|
appendModelProperties(modelSingularCode: string, properties: RpdDataModelProperty[]): void;
|
|
@@ -32,6 +35,6 @@ export declare class RapidServer implements IRpdServer {
|
|
|
32
35
|
queryDatabaseObject(sql: string, params?: unknown[] | Record<string, unknown>): Promise<any[]>;
|
|
33
36
|
tryQueryDatabaseObject(sql: string, params?: unknown[] | Record<string, unknown>): Promise<any[]>;
|
|
34
37
|
get middlewares(): any[];
|
|
35
|
-
handleRequest(request: Request, next: Next):
|
|
38
|
+
handleRequest(request: Request, next: Next): any;
|
|
36
39
|
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
|
37
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruiapp/rapid-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"qs": "^6.11.0",
|
|
24
24
|
"uuid": "^9.0.1"
|
|
25
25
|
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"winston": "^3.11.0"
|
|
28
|
+
},
|
|
26
29
|
"scripts": {
|
|
27
30
|
"build": "rimraf dist && rollup --config",
|
|
28
31
|
"dev": "rollup --config",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { RpdApplicationConfig } from "~/types";
|
|
2
2
|
import { IRpdServer, RapidPlugin } from "./server";
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
|
+
import { Logger } from "~/facilities/log/LogFacility";
|
|
4
5
|
|
|
5
6
|
export interface ActionHandlerContext {
|
|
7
|
+
logger: Logger;
|
|
6
8
|
routerContext: RouteContext;
|
|
7
9
|
next: Next;
|
|
8
10
|
server: IRpdServer;
|
package/src/core/request.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import qs from "qs";
|
|
2
2
|
import { parseFormDataBody } from "./http/formDataParser";
|
|
3
3
|
import { getCookies } from "~/deno-std/http/cookie";
|
|
4
|
+
import { IRpdServer } from "./server";
|
|
5
|
+
import { Logger } from "~/facilities/log/LogFacility";
|
|
4
6
|
|
|
5
7
|
export const GlobalRequest = global.Request;
|
|
6
8
|
|
|
@@ -10,6 +12,7 @@ export interface RapidRequestBody {
|
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export class RapidRequest {
|
|
15
|
+
#logger: Logger;
|
|
13
16
|
#raw: Request;
|
|
14
17
|
#bodyParsed: boolean;
|
|
15
18
|
#body: RapidRequestBody;
|
|
@@ -18,7 +21,8 @@ export class RapidRequest {
|
|
|
18
21
|
method: string;
|
|
19
22
|
url: URL;
|
|
20
23
|
|
|
21
|
-
constructor(req: Request) {
|
|
24
|
+
constructor(server: IRpdServer, req: Request) {
|
|
25
|
+
this.#logger = server.getLogger();
|
|
22
26
|
this.#raw = req;
|
|
23
27
|
this.method = req.method;
|
|
24
28
|
this.url = new URL(req.url);
|
|
@@ -27,7 +31,7 @@ export class RapidRequest {
|
|
|
27
31
|
|
|
28
32
|
async parseBody(): Promise<void> {
|
|
29
33
|
if (this.#bodyParsed) {
|
|
30
|
-
|
|
34
|
+
this.#logger.warn("Request body has been parsed. 'parseBody()' method should not be called more than once.");
|
|
31
35
|
return;
|
|
32
36
|
}
|
|
33
37
|
|
package/src/core/routeContext.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { isArray, isObject } from "lodash";
|
|
|
2
2
|
import { RapidRequest } from "./request";
|
|
3
3
|
import { RapidResponse } from "./response";
|
|
4
4
|
import { HttpStatus, ResponseData } from "./http-types";
|
|
5
|
+
import { IRpdServer } from "./server";
|
|
6
|
+
import { Logger } from "~/facilities/log/LogFacility";
|
|
5
7
|
|
|
6
8
|
export type Next = () => Promise<void>;
|
|
7
9
|
|
|
8
10
|
export class RouteContext {
|
|
11
|
+
#logger: Logger;
|
|
9
12
|
readonly request: RapidRequest;
|
|
10
13
|
readonly response: RapidResponse;
|
|
11
14
|
readonly state: Record<string, any>;
|
|
@@ -14,7 +17,8 @@ export class RouteContext {
|
|
|
14
17
|
params: Record<string, string>;
|
|
15
18
|
routeConfig: any;
|
|
16
19
|
|
|
17
|
-
constructor(request: RapidRequest) {
|
|
20
|
+
constructor(server: IRpdServer, request: RapidRequest) {
|
|
21
|
+
this.#logger = server.getLogger();
|
|
18
22
|
this.request = request;
|
|
19
23
|
this.state = {};
|
|
20
24
|
this.response = new RapidResponse();
|
|
@@ -11,6 +11,7 @@ export async function buildRoutes(
|
|
|
11
11
|
server: IRpdServer,
|
|
12
12
|
applicationConfig: RpdApplicationConfig,
|
|
13
13
|
) {
|
|
14
|
+
const logger = server.getLogger();
|
|
14
15
|
const router = new Router();
|
|
15
16
|
|
|
16
17
|
let baseUrl = server.config.baseUrl;
|
|
@@ -55,10 +56,14 @@ export async function buildRoutes(
|
|
|
55
56
|
|
|
56
57
|
// Normalize input value
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
logger.debug("Processing rapid request.", {
|
|
60
|
+
method: requestMethod,
|
|
61
|
+
url: request.url.toString(),
|
|
62
|
+
input
|
|
63
|
+
});
|
|
60
64
|
|
|
61
65
|
let handlerContext: ActionHandlerContext = {
|
|
66
|
+
logger,
|
|
62
67
|
routerContext,
|
|
63
68
|
next,
|
|
64
69
|
server,
|
package/src/core/server.ts
CHANGED
|
@@ -2,11 +2,13 @@ import { GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder
|
|
|
2
2
|
import { IPluginActionHandler, ActionHandler, ActionHandlerContext } from "./actionHandler";
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
4
|
import EntityManager from "~/dataAccess/entityManager";
|
|
5
|
+
import { Logger } from "~/facilities/log/LogFacility";
|
|
5
6
|
|
|
6
7
|
export interface IRpdServer {
|
|
7
8
|
config: RapidServerConfig;
|
|
8
9
|
databaseConfig: IDatabaseConfig;
|
|
9
10
|
queryBuilder: IQueryBuilder;
|
|
11
|
+
getLogger(): Logger;
|
|
10
12
|
queryDatabaseObject: (
|
|
11
13
|
sql: string,
|
|
12
14
|
params?: unknown[] | Record<string, unknown>,
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
} from "~/types";
|
|
10
10
|
import QueryBuilder from "~/queryBuilder/queryBuilder";
|
|
11
11
|
import { first, set } from "lodash";
|
|
12
|
+
import { IRpdServer } from "~/core/server";
|
|
13
|
+
import { Logger } from "~/facilities/log/LogFacility";
|
|
12
14
|
|
|
13
15
|
export interface IDataAccessorOptions {
|
|
14
16
|
model: RpdDataModel;
|
|
@@ -16,11 +18,13 @@ export interface IDataAccessorOptions {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
|
|
21
|
+
#logger: Logger;
|
|
19
22
|
#model: RpdDataModel;
|
|
20
23
|
#queryBuilder: QueryBuilder;
|
|
21
24
|
#databaseAccessor: IDatabaseAccessor;
|
|
22
25
|
|
|
23
|
-
constructor(databaseAccessor: IDatabaseAccessor, options: IDataAccessorOptions) {
|
|
26
|
+
constructor(server: IRpdServer, databaseAccessor: IDatabaseAccessor, options: IDataAccessorOptions) {
|
|
27
|
+
this.#logger = server.getLogger();
|
|
24
28
|
this.#databaseAccessor = databaseAccessor;
|
|
25
29
|
this.#queryBuilder = options.queryBuilder;
|
|
26
30
|
this.#model = options.model;
|
|
@@ -56,7 +60,7 @@ export default class DataAccessor<T = any> implements IRpdDataAccessor<T> {
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
async find(options: FindEntityOptions): Promise<T[]> {
|
|
59
|
-
|
|
63
|
+
this.#logger.debug(`Finding '${this.#model.singularCode}' entity.`, { options });
|
|
60
64
|
const query = this.#queryBuilder.select(this.#model, options);
|
|
61
65
|
return await this.#databaseAccessor.queryDatabaseObject(query.command, query.params);
|
|
62
66
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
|
|
3
|
+
export interface Logger {
|
|
4
|
+
log: winston.LogMethod;
|
|
5
|
+
/**
|
|
6
|
+
* The service/app is going to stop or become unusable now. An operator should definitely look into this immediately.
|
|
7
|
+
*/
|
|
8
|
+
emerg: winston.LeveledLogMethod;
|
|
9
|
+
/**
|
|
10
|
+
* Fatal for a particular service, but the app continues servicing other requests. An operator should look at this immediately.
|
|
11
|
+
*/
|
|
12
|
+
crit: winston.LeveledLogMethod;
|
|
13
|
+
/**
|
|
14
|
+
* Fatal for a particular request, but the service/app continues servicing other requests. An operator should look at this soon(ish).
|
|
15
|
+
*/
|
|
16
|
+
error: winston.LeveledLogMethod;
|
|
17
|
+
/**
|
|
18
|
+
* A note on something that should probably be looked at by an operator eventually.
|
|
19
|
+
*/
|
|
20
|
+
warn: winston.LeveledLogMethod;
|
|
21
|
+
/**
|
|
22
|
+
* Detail on regular operation.
|
|
23
|
+
*/
|
|
24
|
+
info: winston.LeveledLogMethod;
|
|
25
|
+
/**
|
|
26
|
+
* Anything else, i.e. too verbose to be included in "info" level.
|
|
27
|
+
*/
|
|
28
|
+
debug: winston.LeveledLogMethod;
|
|
29
|
+
/**
|
|
30
|
+
* Logging from external libraries used by your app or very detailed application logging.
|
|
31
|
+
*/
|
|
32
|
+
verbose: winston.LeveledLogMethod;
|
|
33
|
+
|
|
34
|
+
child(options: Object): Logger;
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -14,15 +14,11 @@ export default async function runCollectionEntityActionHandler(
|
|
|
14
14
|
code: string,
|
|
15
15
|
handleEntityAction: EntityActionHandler,
|
|
16
16
|
) {
|
|
17
|
-
const { server, input } = ctx;
|
|
18
|
-
const { defaultInput, fixedInput } = options;
|
|
19
|
-
|
|
20
|
-
console.debug(`Running ${code} handler...`);
|
|
17
|
+
const { logger, server, input } = ctx;
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
const { defaultInput, fixedInput } = options;
|
|
23
20
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
24
|
-
|
|
25
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
21
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
26
22
|
|
|
27
23
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
28
24
|
const result = handleEntityAction(entityManager, mergedInput);
|
|
@@ -35,48 +35,20 @@ class AuthPlugin implements RapidPlugin {
|
|
|
35
35
|
return [];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async initPlugin(server: IRpdServer): Promise<any> {
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
42
|
-
}
|
|
43
|
-
|
|
44
38
|
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
45
39
|
for (const actionHandler of pluginActionHandlers) {
|
|
46
40
|
server.registerActionHandler(this, actionHandler);
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
60
|
-
}
|
|
61
|
-
|
|
62
44
|
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
63
45
|
server.appendApplicationConfig({ models: pluginModels });
|
|
64
46
|
}
|
|
65
47
|
|
|
66
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
67
|
-
}
|
|
68
|
-
|
|
69
48
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
70
49
|
server.appendApplicationConfig({ routes: pluginRoutes });
|
|
71
50
|
}
|
|
72
51
|
|
|
73
|
-
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
74
|
-
console.log("authManager.onApplicationLoaded");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
78
|
-
}
|
|
79
|
-
|
|
80
52
|
async onPrepareRouteContext(server: IRpdServer, routeContext: RouteContext) {
|
|
81
53
|
const request = routeContext.request;
|
|
82
54
|
let token: string;
|
|
@@ -100,8 +72,9 @@ class AuthPlugin implements RapidPlugin {
|
|
|
100
72
|
const tokenPayload = verifyJwt(token, secretKey);
|
|
101
73
|
routeContext.state.userId = tokenPayload.aud as string;
|
|
102
74
|
routeContext.state.userLogin = tokenPayload.act as string;
|
|
103
|
-
} catch (
|
|
104
|
-
|
|
75
|
+
} catch (error) {
|
|
76
|
+
const logger = server.getLogger();
|
|
77
|
+
logger.debug("Verify JWT failed.", { error });
|
|
105
78
|
}
|
|
106
79
|
}
|
|
107
80
|
}
|
|
@@ -107,12 +107,6 @@ class DataManager implements RapidPlugin {
|
|
|
107
107
|
return [];
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
async initPlugin(server: IRpdServer): Promise<any> {
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
114
|
-
}
|
|
115
|
-
|
|
116
110
|
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
117
111
|
server.registerActionHandler(this, findCollectionEntities);
|
|
118
112
|
server.registerActionHandler(this, findCollectionEntityById);
|
|
@@ -126,24 +120,6 @@ class DataManager implements RapidPlugin {
|
|
|
126
120
|
server.registerActionHandler(this, queryDatabase);
|
|
127
121
|
}
|
|
128
122
|
|
|
129
|
-
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
145
|
-
}
|
|
146
|
-
|
|
147
123
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
148
124
|
const { models } = applicationConfig;
|
|
149
125
|
const routes: RpdRoute[] = [];
|
|
@@ -174,13 +150,6 @@ class DataManager implements RapidPlugin {
|
|
|
174
150
|
|
|
175
151
|
server.appendApplicationConfig({ routes });
|
|
176
152
|
}
|
|
177
|
-
|
|
178
|
-
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
179
|
-
console.log("[dataManager.onApplicationLoaded]");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
183
|
-
}
|
|
184
153
|
}
|
|
185
154
|
|
|
186
155
|
export default DataManager;
|
|
@@ -10,15 +10,11 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
14
|
-
const { defaultInput, fixedInput } = options;
|
|
15
|
-
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
const { defaultInput, fixedInput } = options;
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
24
20
|
await entityManager.addRelations(mergedInput, plugin);
|
|
@@ -11,23 +11,19 @@ export async function handler(
|
|
|
11
11
|
ctx: ActionHandlerContext,
|
|
12
12
|
options: RunEntityActionHandlerOptions,
|
|
13
13
|
) {
|
|
14
|
-
const { server, input } = ctx;
|
|
15
|
-
const { defaultInput, fixedInput } = options;
|
|
14
|
+
const { logger, server, input } = ctx;
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
const { defaultInput, fixedInput } = options;
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, input });
|
|
18
18
|
|
|
19
19
|
const { entities } = input;
|
|
20
20
|
if (!isArray(entities)) {
|
|
21
21
|
throw new Error("input.entities should be an array.");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
console.debug(`defaultInput: ${JSON.stringify(defaultInput)}`);
|
|
25
|
-
console.debug(`fixedInput: ${JSON.stringify(fixedInput)}`);
|
|
26
|
-
|
|
27
24
|
const output: any[] = [];
|
|
28
25
|
for(const entity of entities) {
|
|
29
26
|
const mergedEntity = mergeInput(defaultInput?.entity || {}, entity, fixedInput?.entity);
|
|
30
|
-
console.debug(`mergedEntity: ${JSON.stringify(mergedEntity)}`);
|
|
31
27
|
|
|
32
28
|
const userId = ctx.routerContext.state?.userId;
|
|
33
29
|
if (userId) {
|
|
@@ -10,15 +10,11 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
14
|
-
const { defaultInput, fixedInput } = options;
|
|
15
|
-
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
const { defaultInput, fixedInput } = options;
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const userId = ctx.routerContext.state?.userId;
|
|
24
20
|
if (userId) {
|
|
@@ -9,8 +9,8 @@ export async function handler(
|
|
|
9
9
|
ctx: ActionHandlerContext,
|
|
10
10
|
options: RunEntityActionHandlerOptions,
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const { logger, server, input } = ctx;
|
|
13
|
+
logger.debug(`Running ${code} handler...`);
|
|
14
14
|
|
|
15
15
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
16
16
|
await entityManager.deleteById(input.id, plugin);
|
|
@@ -9,8 +9,8 @@ export async function handler(
|
|
|
9
9
|
ctx: ActionHandlerContext,
|
|
10
10
|
options: RunEntityActionHandlerOptions,
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const { logger, server, input } = ctx;
|
|
13
|
+
logger.debug(`Running ${code} handler...`, { input });
|
|
14
14
|
const { id } = input;
|
|
15
15
|
|
|
16
16
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
@@ -11,15 +11,11 @@ export async function handler(
|
|
|
11
11
|
ctx: ActionHandlerContext,
|
|
12
12
|
options: RunQueryDatabaseHandlerOptions,
|
|
13
13
|
) {
|
|
14
|
-
const { server, input } = ctx;
|
|
15
|
-
const { sql, querySingle, defaultInput, fixedInput } = options;
|
|
16
|
-
|
|
17
|
-
console.debug(`Running ${code} handler...`);
|
|
14
|
+
const { logger, server, input } = ctx;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
const { sql, querySingle, defaultInput, fixedInput } = options;
|
|
20
17
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
21
|
-
|
|
22
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
18
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
23
19
|
|
|
24
20
|
const result = await server.queryDatabaseObject(sql, mergedInput);
|
|
25
21
|
if (querySingle) {
|
|
@@ -10,15 +10,11 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
14
14
|
const { defaultInput, fixedInput } = options;
|
|
15
15
|
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
17
|
-
|
|
18
|
-
console.debug(`defaultInput: ${JSON.stringify(defaultInput)}`);
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
24
20
|
await entityManager.removeRelations(mergedInput, plugin);
|
|
@@ -10,18 +10,13 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
14
|
-
const { defaultInput, fixedInput } = options;
|
|
15
|
-
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
const { defaultInput, fixedInput } = options;
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
24
|
-
|
|
25
20
|
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput }, plugin);
|
|
26
21
|
ctx.output = output;
|
|
27
22
|
}
|
|
@@ -43,6 +43,9 @@ class EntityAccessControlPlugin implements RapidPlugin {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
46
|
+
const logger = server.getLogger();
|
|
47
|
+
logger.info("Configuring entity access checking policies...")
|
|
48
|
+
|
|
46
49
|
const model = find(applicationConfig.models, (item) => item.singularCode === "model");
|
|
47
50
|
if (!model) {
|
|
48
51
|
return;
|