@ruiapp/rapid-core 0.7.0 → 0.7.2
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/index.js
CHANGED
|
@@ -4585,12 +4585,17 @@ class RapidServer {
|
|
|
4585
4585
|
await this.#buildedRoutes(routeContext, next);
|
|
4586
4586
|
}
|
|
4587
4587
|
catch (ex) {
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
error
|
|
4591
|
-
message: ex
|
|
4592
|
-
}
|
|
4593
|
-
}
|
|
4588
|
+
let error;
|
|
4589
|
+
if (lodash.isString(ex)) {
|
|
4590
|
+
error = {
|
|
4591
|
+
message: ex,
|
|
4592
|
+
};
|
|
4593
|
+
}
|
|
4594
|
+
else {
|
|
4595
|
+
error = { name: ex.name, message: ex.message, stack: ex.stack };
|
|
4596
|
+
}
|
|
4597
|
+
this.#logger.error("handle request error.", { error });
|
|
4598
|
+
response.json({ error }, 500);
|
|
4594
4599
|
}
|
|
4595
4600
|
if (!response.status && !response.body) {
|
|
4596
4601
|
response.json({
|
|
@@ -6647,20 +6652,28 @@ var changePassword$1 = /*#__PURE__*/Object.freeze({
|
|
|
6647
6652
|
handler: handler$e
|
|
6648
6653
|
});
|
|
6649
6654
|
|
|
6650
|
-
|
|
6651
|
-
async function handler$d(plugin, ctx, options) {
|
|
6652
|
-
const { server, input, routerContext: routeContext } = ctx;
|
|
6653
|
-
const { response } = routeContext;
|
|
6654
|
-
const { account, password } = input;
|
|
6655
|
+
function validateLicense(logger, server) {
|
|
6655
6656
|
const licenseService = server.getService("licenseService");
|
|
6656
6657
|
const license = licenseService.getLicense();
|
|
6657
6658
|
if (!license) {
|
|
6658
|
-
|
|
6659
|
+
const errorMessage = `无法获取系统授权信息。`;
|
|
6660
|
+
logger.error(errorMessage);
|
|
6661
|
+
throw new Error(errorMessage);
|
|
6659
6662
|
}
|
|
6660
6663
|
if (licenseService.isExpired()) {
|
|
6661
6664
|
const expireDate = lodash.get(license.authority, "expireDate");
|
|
6662
|
-
|
|
6665
|
+
const errorMessage = `您的系统授权已于${expireDate}过期。`;
|
|
6666
|
+
logger.error(errorMessage);
|
|
6667
|
+
throw new Error(errorMessage);
|
|
6663
6668
|
}
|
|
6669
|
+
}
|
|
6670
|
+
|
|
6671
|
+
const code$d = "createSession";
|
|
6672
|
+
async function handler$d(plugin, ctx, options) {
|
|
6673
|
+
const { server, input, routerContext: routeContext, logger } = ctx;
|
|
6674
|
+
const { response } = routeContext;
|
|
6675
|
+
const { account, password } = input;
|
|
6676
|
+
validateLicense(logger, server);
|
|
6664
6677
|
const userDataAccessor = server.getDataAccessor({
|
|
6665
6678
|
singularCode: "oc_user",
|
|
6666
6679
|
});
|
|
@@ -8503,6 +8516,7 @@ class CronJobPlugin {
|
|
|
8503
8516
|
async executeJob(server, job) {
|
|
8504
8517
|
const logger = server.getLogger();
|
|
8505
8518
|
try {
|
|
8519
|
+
validateLicense(logger, server);
|
|
8506
8520
|
let handlerContext = {
|
|
8507
8521
|
logger,
|
|
8508
8522
|
routerContext: null,
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { get } from "lodash";
|
|
2
|
+
import { IRpdServer } from "~/core/server";
|
|
3
|
+
import { Logger } from "~/facilities/log/LogFacility";
|
|
4
|
+
import LicenseService from "~/plugins/license/LicenseService";
|
|
5
|
+
|
|
6
|
+
export function validateLicense(logger: Logger, server: IRpdServer) {
|
|
7
|
+
const licenseService = server.getService<LicenseService>("licenseService");
|
|
8
|
+
const license = licenseService.getLicense();
|
|
9
|
+
if (!license) {
|
|
10
|
+
const errorMessage = `无法获取系统授权信息。`;
|
|
11
|
+
logger.error(errorMessage);
|
|
12
|
+
throw new Error(errorMessage);
|
|
13
|
+
}
|
|
14
|
+
if (licenseService.isExpired()) {
|
|
15
|
+
const expireDate = get(license.authority, "expireDate");
|
|
16
|
+
const errorMessage = `您的系统授权已于${expireDate}过期。`;
|
|
17
|
+
logger.error(errorMessage);
|
|
18
|
+
throw new Error(errorMessage);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -2,26 +2,17 @@ import bcrypt from "bcrypt";
|
|
|
2
2
|
import { setCookie } from "~/deno-std/http/cookie";
|
|
3
3
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
4
|
import { RapidPlugin } from "~/core/server";
|
|
5
|
-
import LicenseService from "~/plugins/license/LicenseService";
|
|
6
|
-
import { get } from "lodash";
|
|
7
5
|
import AuthService from "../services/AuthService";
|
|
6
|
+
import { validateLicense } from "~/helpers/licenseHelper";
|
|
8
7
|
|
|
9
8
|
export const code = "createSession";
|
|
10
9
|
|
|
11
10
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
12
|
-
const { server, input, routerContext: routeContext } = ctx;
|
|
11
|
+
const { server, input, routerContext: routeContext, logger } = ctx;
|
|
13
12
|
const { response } = routeContext;
|
|
14
13
|
const { account, password } = input;
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
const license = licenseService.getLicense();
|
|
18
|
-
if (!license) {
|
|
19
|
-
throw new Error(`登录失败,无法获取系统授权信息。`);
|
|
20
|
-
}
|
|
21
|
-
if (licenseService.isExpired()) {
|
|
22
|
-
const expireDate = get(license.authority, "expireDate");
|
|
23
|
-
throw new Error(`登录失败,系统授权已于${expireDate}过期。`);
|
|
24
|
-
}
|
|
15
|
+
validateLicense(logger, server);
|
|
25
16
|
|
|
26
17
|
const userDataAccessor = server.getDataAccessor({
|
|
27
18
|
singularCode: "oc_user",
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "~/core/server";
|
|
13
13
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
14
14
|
import { find } from "lodash";
|
|
15
|
+
import { validateLicense } from "~/helpers/licenseHelper";
|
|
15
16
|
|
|
16
17
|
class CronJobPlugin implements RapidPlugin {
|
|
17
18
|
#server: IRpdServer;
|
|
@@ -90,6 +91,8 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
90
91
|
async executeJob(server: IRpdServer, job: CronJobConfiguration) {
|
|
91
92
|
const logger = server.getLogger();
|
|
92
93
|
try {
|
|
94
|
+
validateLicense(logger, server);
|
|
95
|
+
|
|
93
96
|
let handlerContext: ActionHandlerContext = {
|
|
94
97
|
logger,
|
|
95
98
|
routerContext: null,
|
package/src/server.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { Next, RouteContext } from "./core/routeContext";
|
|
|
30
30
|
import { RapidRequest } from "./core/request";
|
|
31
31
|
import bootstrapApplicationConfig from "./bootstrapApplicationConfig";
|
|
32
32
|
import EntityManager from "./dataAccess/entityManager";
|
|
33
|
-
import { bind, cloneDeep, find, forEach, merge, omit } from "lodash";
|
|
33
|
+
import { bind, cloneDeep, find, forEach, isString, merge, omit } from "lodash";
|
|
34
34
|
import { Logger } from "./facilities/log/LogFacility";
|
|
35
35
|
import { FacilityFactory } from "./core/facility";
|
|
36
36
|
import { CronJobConfiguration } from "./types/cron-job-types";
|
|
@@ -443,15 +443,16 @@ export class RapidServer implements IRpdServer {
|
|
|
443
443
|
await this.#pluginManager.onPrepareRouteContext(routeContext);
|
|
444
444
|
await this.#buildedRoutes(routeContext, next);
|
|
445
445
|
} catch (ex) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
{
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
);
|
|
446
|
+
let error: any;
|
|
447
|
+
if (isString(ex)) {
|
|
448
|
+
error = {
|
|
449
|
+
message: ex,
|
|
450
|
+
};
|
|
451
|
+
} else {
|
|
452
|
+
error = { name: ex.name, message: ex.message, stack: ex.stack };
|
|
453
|
+
}
|
|
454
|
+
this.#logger.error("handle request error.", { error });
|
|
455
|
+
response.json({ error }, 500);
|
|
455
456
|
}
|
|
456
457
|
|
|
457
458
|
if (!response.status && !response.body) {
|