@ruiapp/rapid-core 0.3.4 → 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.
@@ -0,0 +1,4 @@
1
+ import { IRpdServer } from "../core/server";
2
+ import { Logger } from "../facilities/log/LogFacility";
3
+ export declare function validateLicense(server: IRpdServer): void;
4
+ export declare function tryValidateLicense(logger: Logger, server: IRpdServer): boolean;
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 } = routerContext;
6070
+ const { server, input, routerContext: routeContext, logger } = ctx;
6071
+ const { response } = routeContext;
6048
6072
  const { account, password } = input;
6049
- const licenseService = server.getService("licenseService");
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
  });
@@ -7869,6 +7885,7 @@ class CronJobPlugin {
7869
7885
  async executeJob(server, job) {
7870
7886
  const logger = server.getLogger();
7871
7887
  try {
7888
+ validateLicense(server);
7872
7889
  let handlerContext = {
7873
7890
  logger,
7874
7891
  routerContext: null,
@@ -8304,4 +8321,6 @@ exports.getNowString = getNowString;
8304
8321
  exports.getNowStringWithTimezone = getNowStringWithTimezone;
8305
8322
  exports.isAccessAllowed = isAccessAllowed;
8306
8323
  exports.mapDbRowToEntity = mapDbRowToEntity;
8324
+ exports.tryValidateLicense = tryValidateLicense;
8325
+ exports.validateLicense = validateLicense;
8307
8326
  exports.verifyJwt = verifyJwt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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 LicenseService from "~/plugins/license/LicenseService";
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 } = routerContext;
16
+ const { server, input, routerContext: routeContext, logger } = ctx;
17
+ const { response } = routeContext;
19
18
  const { account, password } = input;
20
19
 
21
- const licenseService = server.getService<LicenseService>("licenseService");
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[];
@@ -89,6 +90,8 @@ class CronJobPlugin implements RapidPlugin {
89
90
  async executeJob(server: IRpdServer, job: CronJobConfiguration) {
90
91
  const logger = server.getLogger();
91
92
  try {
93
+ validateLicense(server);
94
+
92
95
  let handlerContext: ActionHandlerContext = {
93
96
  logger,
94
97
  routerContext: null,