@ruiapp/rapid-core 0.3.3 → 0.3.5
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/helpers/licenseHelper.d.ts +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +31 -11
- package/dist/plugins/cronJob/CronJobPluginTypes.d.ts +14 -0
- package/package.json +1 -1
- package/src/helpers/licenseHelper.ts +29 -0
- package/src/index.ts +2 -0
- package/src/plugins/auth/actionHandlers/createSession.ts +4 -13
- package/src/plugins/cronJob/CronJobPlugin.ts +4 -0
- package/src/plugins/cronJob/CronJobPluginTypes.ts +17 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./utilities/accessControlUtility";
|
|
|
9
9
|
export * from "./utilities/entityUtility";
|
|
10
10
|
export * from "./utilities/jwtUtility";
|
|
11
11
|
export * from "./utilities/timeUtility";
|
|
12
|
+
export * from "./helpers/licenseHelper";
|
|
12
13
|
export { mapDbRowToEntity } from "./dataAccess/entityMapper";
|
|
13
14
|
export * as bootstrapApplicationConfig from "./bootstrapApplicationConfig";
|
|
14
15
|
export { default as MetaManagePlugin } from "./plugins/metaManage/MetaManagePlugin";
|
package/dist/index.js
CHANGED
|
@@ -4361,6 +4361,30 @@ async function generateJwtSecretKey() {
|
|
|
4361
4361
|
return encode(exportedKey);
|
|
4362
4362
|
}
|
|
4363
4363
|
|
|
4364
|
+
function validateLicense(server) {
|
|
4365
|
+
const licenseService = server.getService("licenseService");
|
|
4366
|
+
const license = licenseService.getLicense();
|
|
4367
|
+
if (!license) {
|
|
4368
|
+
const errorMessage = `无法获取系统授权信息。`;
|
|
4369
|
+
throw new Error(errorMessage);
|
|
4370
|
+
}
|
|
4371
|
+
if (licenseService.isExpired()) {
|
|
4372
|
+
const expireDate = lodash.get(license.authority, "expireDate");
|
|
4373
|
+
const errorMessage = `您的系统授权已于${expireDate}过期。`;
|
|
4374
|
+
throw new Error(errorMessage);
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4377
|
+
function tryValidateLicense(logger, server) {
|
|
4378
|
+
try {
|
|
4379
|
+
validateLicense(server);
|
|
4380
|
+
return true;
|
|
4381
|
+
}
|
|
4382
|
+
catch (err) {
|
|
4383
|
+
logger.error("授权验证失败:%s", err.message || "");
|
|
4384
|
+
}
|
|
4385
|
+
return false;
|
|
4386
|
+
}
|
|
4387
|
+
|
|
4364
4388
|
const code$u = "listMetaModels";
|
|
4365
4389
|
async function handler$u(plugin, ctx, options) {
|
|
4366
4390
|
const { applicationConfig } = ctx;
|
|
@@ -6043,18 +6067,10 @@ var changePassword$1 = /*#__PURE__*/Object.freeze({
|
|
|
6043
6067
|
|
|
6044
6068
|
const code$d = "createSession";
|
|
6045
6069
|
async function handler$d(plugin, ctx, options) {
|
|
6046
|
-
const { server, input, routerContext } = ctx;
|
|
6047
|
-
const { response } =
|
|
6070
|
+
const { server, input, routerContext: routeContext, logger } = ctx;
|
|
6071
|
+
const { response } = routeContext;
|
|
6048
6072
|
const { account, password } = input;
|
|
6049
|
-
|
|
6050
|
-
const license = licenseService.getLicense();
|
|
6051
|
-
if (!license) {
|
|
6052
|
-
throw new Error(`登录失败,无法获取系统授权信息。`);
|
|
6053
|
-
}
|
|
6054
|
-
if (licenseService.isExpired()) {
|
|
6055
|
-
const expireDate = lodash.get(license.authority, "expireDate");
|
|
6056
|
-
throw new Error(`登录失败,系统授权已于${expireDate}过期。`);
|
|
6057
|
-
}
|
|
6073
|
+
validateLicense(server);
|
|
6058
6074
|
const userDataAccessor = server.getDataAccessor({
|
|
6059
6075
|
singularCode: "oc_user",
|
|
6060
6076
|
});
|
|
@@ -7853,6 +7869,7 @@ class CronJobPlugin {
|
|
|
7853
7869
|
async onApplicationReady(server, applicationConfig) {
|
|
7854
7870
|
for (const job of this.#jobs) {
|
|
7855
7871
|
const jobInstance = cron__namespace.CronJob.from({
|
|
7872
|
+
...(job.jobOptions || {}),
|
|
7856
7873
|
cronTime: job.cronTime,
|
|
7857
7874
|
onTick: async () => {
|
|
7858
7875
|
server.getLogger().info(`Executing cron job '${job.code}'...`);
|
|
@@ -7868,6 +7885,7 @@ class CronJobPlugin {
|
|
|
7868
7885
|
async executeJob(server, job) {
|
|
7869
7886
|
const logger = server.getLogger();
|
|
7870
7887
|
try {
|
|
7888
|
+
validateLicense(server);
|
|
7871
7889
|
let handlerContext = {
|
|
7872
7890
|
logger,
|
|
7873
7891
|
routerContext: null,
|
|
@@ -8303,4 +8321,6 @@ exports.getNowString = getNowString;
|
|
|
8303
8321
|
exports.getNowStringWithTimezone = getNowStringWithTimezone;
|
|
8304
8322
|
exports.isAccessAllowed = isAccessAllowed;
|
|
8305
8323
|
exports.mapDbRowToEntity = mapDbRowToEntity;
|
|
8324
|
+
exports.tryValidateLicense = tryValidateLicense;
|
|
8325
|
+
exports.validateLicense = validateLicense;
|
|
8306
8326
|
exports.verifyJwt = verifyJwt;
|
|
@@ -12,6 +12,10 @@ export interface CronJobConfiguration {
|
|
|
12
12
|
* crontab 表达式
|
|
13
13
|
*/
|
|
14
14
|
cronTime: string;
|
|
15
|
+
/**
|
|
16
|
+
* 任务设置
|
|
17
|
+
*/
|
|
18
|
+
jobOptions?: CronJobOptions;
|
|
15
19
|
/**
|
|
16
20
|
* 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
|
|
17
21
|
*/
|
|
@@ -28,6 +32,16 @@ export interface CronJobConfiguration {
|
|
|
28
32
|
*/
|
|
29
33
|
handleOptions?: any;
|
|
30
34
|
}
|
|
35
|
+
export interface CronJobOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Instantly triggers the onTick function post initialization. Default is false.
|
|
38
|
+
*/
|
|
39
|
+
runOnInit?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* If true, no additional instances of the onTick callback function will run until the current onTick callback has completed. Any new scheduled executions that occur while the current callback is running will be skipped entirely. Default is false.
|
|
42
|
+
*/
|
|
43
|
+
waitForCompletion?: boolean;
|
|
44
|
+
}
|
|
31
45
|
export interface CronJobPluginInitOptions {
|
|
32
46
|
jobs: CronJobConfiguration[];
|
|
33
47
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
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(server: IRpdServer) {
|
|
7
|
+
const licenseService = server.getService<LicenseService>("licenseService");
|
|
8
|
+
const license = licenseService.getLicense();
|
|
9
|
+
if (!license) {
|
|
10
|
+
const errorMessage = `无法获取系统授权信息。`;
|
|
11
|
+
throw new Error(errorMessage);
|
|
12
|
+
}
|
|
13
|
+
if (licenseService.isExpired()) {
|
|
14
|
+
const expireDate = get(license.authority, "expireDate");
|
|
15
|
+
const errorMessage = `您的系统授权已于${expireDate}过期。`;
|
|
16
|
+
throw new Error(errorMessage);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function tryValidateLicense(logger: Logger, server: IRpdServer) {
|
|
21
|
+
try {
|
|
22
|
+
validateLicense(server);
|
|
23
|
+
return true;
|
|
24
|
+
} catch (err: any) {
|
|
25
|
+
logger.error("授权验证失败:%s", err.message || "");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,8 @@ export * from "./utilities/entityUtility";
|
|
|
15
15
|
export * from "./utilities/jwtUtility";
|
|
16
16
|
export * from "./utilities/timeUtility";
|
|
17
17
|
|
|
18
|
+
export * from "./helpers/licenseHelper";
|
|
19
|
+
|
|
18
20
|
export { mapDbRowToEntity } from "./dataAccess/entityMapper";
|
|
19
21
|
|
|
20
22
|
export * as bootstrapApplicationConfig from "./bootstrapApplicationConfig";
|
|
@@ -3,8 +3,7 @@ import { setCookie } from "~/deno-std/http/cookie";
|
|
|
3
3
|
import { createJwt } from "~/utilities/jwtUtility";
|
|
4
4
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
5
5
|
import { RapidPlugin } from "~/core/server";
|
|
6
|
-
import
|
|
7
|
-
import { get } from "lodash";
|
|
6
|
+
import { validateLicense } from "~/helpers/licenseHelper";
|
|
8
7
|
|
|
9
8
|
export interface UserAccessToken {
|
|
10
9
|
sub: "userAccessToken";
|
|
@@ -14,19 +13,11 @@ export interface UserAccessToken {
|
|
|
14
13
|
export const code = "createSession";
|
|
15
14
|
|
|
16
15
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
17
|
-
const { server, input, routerContext } = ctx;
|
|
18
|
-
const { response } =
|
|
16
|
+
const { server, input, routerContext: routeContext, logger } = ctx;
|
|
17
|
+
const { response } = routeContext;
|
|
19
18
|
const { account, password } = input;
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
const license = licenseService.getLicense();
|
|
23
|
-
if (!license) {
|
|
24
|
-
throw new Error(`登录失败,无法获取系统授权信息。`);
|
|
25
|
-
}
|
|
26
|
-
if (licenseService.isExpired()) {
|
|
27
|
-
const expireDate = get(license.authority, "expireDate");
|
|
28
|
-
throw new Error(`登录失败,系统授权已于${expireDate}过期。`);
|
|
29
|
-
}
|
|
20
|
+
validateLicense(server);
|
|
30
21
|
|
|
31
22
|
const userDataAccessor = server.getDataAccessor({
|
|
32
23
|
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
|
#jobs: CronJobConfiguration[];
|
|
@@ -71,6 +72,7 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
71
72
|
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
72
73
|
for (const job of this.#jobs) {
|
|
73
74
|
const jobInstance = cron.CronJob.from({
|
|
75
|
+
...(job.jobOptions || {}),
|
|
74
76
|
cronTime: job.cronTime,
|
|
75
77
|
onTick: async () => {
|
|
76
78
|
server.getLogger().info(`Executing cron job '${job.code}'...`);
|
|
@@ -88,6 +90,8 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
88
90
|
async executeJob(server: IRpdServer, job: CronJobConfiguration) {
|
|
89
91
|
const logger = server.getLogger();
|
|
90
92
|
try {
|
|
93
|
+
validateLicense(server);
|
|
94
|
+
|
|
91
95
|
let handlerContext: ActionHandlerContext = {
|
|
92
96
|
logger,
|
|
93
97
|
routerContext: null,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
2
|
-
import { RpdHttpMethod } from "~/types";
|
|
3
2
|
|
|
4
3
|
export interface CronJobConfiguration {
|
|
5
4
|
/**
|
|
@@ -17,6 +16,11 @@ export interface CronJobConfiguration {
|
|
|
17
16
|
*/
|
|
18
17
|
cronTime: string;
|
|
19
18
|
|
|
19
|
+
/**
|
|
20
|
+
* 任务设置
|
|
21
|
+
*/
|
|
22
|
+
jobOptions?: CronJobOptions;
|
|
23
|
+
|
|
20
24
|
/**
|
|
21
25
|
* 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
|
|
22
26
|
*/
|
|
@@ -36,6 +40,18 @@ export interface CronJobConfiguration {
|
|
|
36
40
|
handleOptions?: any;
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
export interface CronJobOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Instantly triggers the onTick function post initialization. Default is false.
|
|
46
|
+
*/
|
|
47
|
+
runOnInit?: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* If true, no additional instances of the onTick callback function will run until the current onTick callback has completed. Any new scheduled executions that occur while the current callback is running will be skipped entirely. Default is false.
|
|
51
|
+
*/
|
|
52
|
+
waitForCompletion?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
export interface CronJobPluginInitOptions {
|
|
40
56
|
jobs: CronJobConfiguration[];
|
|
41
57
|
}
|