@ruiapp/rapid-core 0.9.1 → 0.9.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.d.ts CHANGED
@@ -29,6 +29,7 @@ export { default as SequencePlugin } from "./plugins/sequence/SequencePlugin";
29
29
  export * from "./plugins/sequence/SequencePluginTypes";
30
30
  export { default as WebhooksPlugin } from "./plugins/webhooks/WebhooksPlugin";
31
31
  export { default as AuthPlugin } from "./plugins/auth/AuthPlugin";
32
+ export * from "./plugins/auth/AuthPluginTypes";
32
33
  export { default as FileManagePlugin } from "./plugins/fileManage/FileManagePlugin";
33
34
  export { default as LicensePlugin } from "./plugins/license/LicensePlugin";
34
35
  export * from "./plugins/license/LicensePluginTypes";
package/dist/index.js CHANGED
@@ -6876,8 +6876,9 @@ async function handler$e(plugin, ctx, options) {
6876
6876
  };
6877
6877
  return;
6878
6878
  }
6879
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
6879
6880
  const userDataAccessor = server.getDataAccessor({
6880
- singularCode: "oc_user",
6881
+ singularCode: userEntitySingularCode,
6881
6882
  });
6882
6883
  const user = await userDataAccessor.findOne({
6883
6884
  filters: [
@@ -6915,8 +6916,9 @@ async function handler$d(plugin, ctx, options) {
6915
6916
  const { response } = routeContext;
6916
6917
  const { account, password } = input;
6917
6918
  validateLicense(server);
6919
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
6918
6920
  const userDataAccessor = server.getDataAccessor({
6919
- singularCode: "oc_user",
6921
+ singularCode: userEntitySingularCode,
6920
6922
  });
6921
6923
  const user = await userDataAccessor.findOne({
6922
6924
  filters: [
@@ -6994,7 +6996,9 @@ async function handler$b(plugin, ctx, options) {
6994
6996
  };
6995
6997
  return;
6996
6998
  }
6997
- const entityManager = server.getEntityManager("oc_user");
6999
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
7000
+ const profilePropertyCodes = plugin.options?.profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
7001
+ const entityManager = server.getEntityManager(userEntitySingularCode);
6998
7002
  const user = await entityManager.findEntity({
6999
7003
  filters: [
7000
7004
  {
@@ -7003,7 +7007,7 @@ async function handler$b(plugin, ctx, options) {
7003
7007
  value: userId,
7004
7008
  },
7005
7009
  ],
7006
- properties: ["id", "name", "login", "email", "department", "roles", "state", "createdAt"],
7010
+ properties: profilePropertyCodes,
7007
7011
  });
7008
7012
  ctx.output = {
7009
7013
  user,
@@ -7020,8 +7024,9 @@ const code$a = "resetPassword";
7020
7024
  async function handler$a(plugin, ctx, options) {
7021
7025
  const { server, input, routerContext: routeContext } = ctx;
7022
7026
  const { userId, password } = input;
7027
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
7023
7028
  const userDataAccessor = server.getDataAccessor({
7024
- singularCode: "oc_user",
7029
+ singularCode: userEntitySingularCode,
7025
7030
  });
7026
7031
  const user = await userDataAccessor.findOne({
7027
7032
  filters: [
@@ -7204,7 +7209,14 @@ class AuthService {
7204
7209
  * Auth manager plugin
7205
7210
  */
7206
7211
  class AuthPlugin {
7212
+ #options;
7207
7213
  #authService;
7214
+ constructor(options) {
7215
+ this.#options = Object.freeze(options);
7216
+ }
7217
+ get options() {
7218
+ return this.#options;
7219
+ }
7208
7220
  get code() {
7209
7221
  return "authManager";
7210
7222
  }
@@ -4,8 +4,11 @@
4
4
  import { RpdApplicationConfig } from "../../types";
5
5
  import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "../../core/server";
6
6
  import { RouteContext } from "../../core/routeContext";
7
+ import { AuthPluginInitOptions } from "./AuthPluginTypes";
7
8
  declare class AuthPlugin implements RapidPlugin {
8
9
  #private;
10
+ constructor(options: AuthPluginInitOptions);
11
+ get options(): AuthPluginInitOptions;
9
12
  get code(): string;
10
13
  get description(): string;
11
14
  get extendingAbilities(): RpdServerPluginExtendingAbilities[];
@@ -0,0 +1,10 @@
1
+ export type AuthPluginInitOptions = {
2
+ /**
3
+ * 用户实体代号。默认为`oc_user`
4
+ */
5
+ userEntitySingularCode?: string;
6
+ /**
7
+ * 个人资料属性。默认为`["id", "name", "login", "email", "department", "roles", "state", "createdAt"]`
8
+ */
9
+ profilePropertyCodes?: string[];
10
+ };
@@ -1,4 +1,4 @@
1
1
  import { ActionHandlerContext } from "../../../core/actionHandler";
2
- import { RapidPlugin } from "../../../core/server";
2
+ import AuthPlugin from "../AuthPlugin";
3
3
  export declare const code = "changePassword";
4
- export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
4
+ export declare function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
1
  import { ActionHandlerContext } from "../../../core/actionHandler";
2
- import { RapidPlugin } from "../../../core/server";
2
+ import AuthPlugin from "../AuthPlugin";
3
3
  export declare const code = "createSession";
4
- export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
4
+ export declare function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
1
  import { ActionHandlerContext } from "../../../core/actionHandler";
2
- import { RapidPlugin } from "../../../core/server";
2
+ import AuthPlugin from "../AuthPlugin";
3
3
  export declare const code = "getMyProfile";
4
- export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
4
+ export declare function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
@@ -1,4 +1,4 @@
1
1
  import { ActionHandlerContext } from "../../../core/actionHandler";
2
- import { RapidPlugin } from "../../../core/server";
2
+ import AuthPlugin from "../AuthPlugin";
3
3
  export declare const code = "resetPassword";
4
- export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
4
+ export declare function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -47,6 +47,7 @@ export * from "./plugins/sequence/SequencePluginTypes";
47
47
  export { default as WebhooksPlugin } from "./plugins/webhooks/WebhooksPlugin";
48
48
 
49
49
  export { default as AuthPlugin } from "./plugins/auth/AuthPlugin";
50
+ export * from "./plugins/auth/AuthPluginTypes";
50
51
 
51
52
  export { default as FileManagePlugin } from "./plugins/fileManage/FileManagePlugin";
52
53
 
@@ -17,10 +17,20 @@ import pluginRoutes from "./routes";
17
17
  import { RouteContext } from "~/core/routeContext";
18
18
  import { verifyJwt } from "~/utilities/jwtUtility";
19
19
  import AuthService from "./services/AuthService";
20
+ import { AuthPluginInitOptions } from "./AuthPluginTypes";
20
21
 
21
22
  class AuthPlugin implements RapidPlugin {
23
+ #options: AuthPluginInitOptions;
22
24
  #authService!: AuthService;
23
25
 
26
+ constructor(options: AuthPluginInitOptions) {
27
+ this.#options = Object.freeze(options);
28
+ }
29
+
30
+ get options(): AuthPluginInitOptions {
31
+ return this.#options;
32
+ }
33
+
24
34
  get code(): string {
25
35
  return "authManager";
26
36
  }
@@ -0,0 +1,11 @@
1
+ export type AuthPluginInitOptions = {
2
+ /**
3
+ * 用户实体代号。默认为`oc_user`
4
+ */
5
+ userEntitySingularCode?: string;
6
+
7
+ /**
8
+ * 个人资料属性。默认为`["id", "name", "login", "email", "department", "roles", "state", "createdAt"]`
9
+ */
10
+ profilePropertyCodes?: string[];
11
+ };
@@ -1,10 +1,11 @@
1
1
  import bcrypt from "bcrypt";
2
2
  import { ActionHandlerContext } from "~/core/actionHandler";
3
3
  import { RapidPlugin } from "~/core/server";
4
+ import AuthPlugin from "../AuthPlugin";
4
5
 
5
6
  export const code = "changePassword";
6
7
 
7
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
8
+ export async function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any) {
8
9
  const { server, input, routerContext: routeContext } = ctx;
9
10
  const { response } = routeContext;
10
11
  const { id, oldPassword, newPassword } = input;
@@ -20,8 +21,9 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
20
21
  return;
21
22
  }
22
23
 
24
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
23
25
  const userDataAccessor = server.getDataAccessor({
24
- singularCode: "oc_user",
26
+ singularCode: userEntitySingularCode,
25
27
  });
26
28
 
27
29
  const user = await userDataAccessor.findOne(
@@ -4,18 +4,20 @@ import { ActionHandlerContext } from "~/core/actionHandler";
4
4
  import { RapidPlugin } from "~/core/server";
5
5
  import AuthService from "../services/AuthService";
6
6
  import { validateLicense } from "~/helpers/licenseHelper";
7
+ import AuthPlugin from "../AuthPlugin";
7
8
 
8
9
  export const code = "createSession";
9
10
 
10
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
11
+ export async function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any) {
11
12
  const { server, input, routerContext: routeContext, logger } = ctx;
12
13
  const { response } = routeContext;
13
14
  const { account, password } = input;
14
15
 
15
16
  validateLicense(server);
16
17
 
18
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
17
19
  const userDataAccessor = server.getDataAccessor({
18
- singularCode: "oc_user",
20
+ singularCode: userEntitySingularCode,
19
21
  });
20
22
 
21
23
  const user = await userDataAccessor.findOne(
@@ -1,9 +1,10 @@
1
1
  import { ActionHandlerContext } from "~/core/actionHandler";
2
2
  import { RapidPlugin } from "~/core/server";
3
+ import AuthPlugin from "../AuthPlugin";
3
4
 
4
5
  export const code = "getMyProfile";
5
6
 
6
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
7
+ export async function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any) {
7
8
  const { server, input, routerContext } = ctx;
8
9
 
9
10
  const userId = routerContext.state.userId;
@@ -17,7 +18,9 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
17
18
  return;
18
19
  }
19
20
 
20
- const entityManager = server.getEntityManager("oc_user");
21
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
22
+ const profilePropertyCodes = plugin.options?.profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
23
+ const entityManager = server.getEntityManager(userEntitySingularCode);
21
24
  const user = await entityManager.findEntity({
22
25
  filters: [
23
26
  {
@@ -26,7 +29,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
26
29
  value: userId,
27
30
  },
28
31
  ],
29
- properties: ["id", "name", "login", "email", "department", "roles", "state", "createdAt"],
32
+ properties: profilePropertyCodes,
30
33
  });
31
34
 
32
35
  ctx.output = {
@@ -1,16 +1,18 @@
1
1
  import bcrypt from "bcrypt";
2
2
  import { ActionHandlerContext } from "~/core/actionHandler";
3
3
  import { RapidPlugin } from "~/core/server";
4
+ import AuthPlugin from "../AuthPlugin";
4
5
 
5
6
  export const code = "resetPassword";
6
7
 
7
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
8
+ export async function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, options: any) {
8
9
  const { server, input, routerContext: routeContext } = ctx;
9
10
  const { response } = routeContext;
10
11
  const { userId, password } = input;
11
12
 
13
+ const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
12
14
  const userDataAccessor = server.getDataAccessor({
13
- singularCode: "oc_user",
15
+ singularCode: userEntitySingularCode,
14
16
  });
15
17
 
16
18
  const user = await userDataAccessor.findOne(