@ruiapp/rapid-core 0.9.8 → 0.10.0

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.
@@ -435,6 +435,57 @@ declare const _default: {
435
435
  description?: undefined;
436
436
  })[];
437
437
  indexes?: undefined;
438
+ } | {
439
+ maintainedBy: string;
440
+ namespace: string;
441
+ name: string;
442
+ code: string;
443
+ singularCode: string;
444
+ pluralCode: string;
445
+ schema: string;
446
+ tableName: string;
447
+ properties: ({
448
+ name: string;
449
+ code: string;
450
+ columnName: string;
451
+ type: "integer";
452
+ required: true;
453
+ autoIncrement: true;
454
+ } | {
455
+ name: string;
456
+ code: string;
457
+ columnName: string;
458
+ type: "text";
459
+ required: true;
460
+ autoIncrement?: undefined;
461
+ } | {
462
+ name: string;
463
+ code: string;
464
+ columnName: string;
465
+ type: "text";
466
+ required: false;
467
+ autoIncrement?: undefined;
468
+ } | {
469
+ name: string;
470
+ code: string;
471
+ columnName: string;
472
+ type: "json";
473
+ required: false;
474
+ autoIncrement?: undefined;
475
+ })[];
476
+ indexes: ({
477
+ name: string;
478
+ properties: {
479
+ code: string;
480
+ }[];
481
+ unique: true;
482
+ } | {
483
+ name: string;
484
+ properties: {
485
+ code: string;
486
+ }[];
487
+ unique?: undefined;
488
+ })[];
438
489
  })[];
439
490
  dataDictionaries: any[];
440
491
  routes: {
package/dist/index.js CHANGED
@@ -1968,6 +1968,114 @@ var bootstrapApplicationConfig = {
1968
1968
  },
1969
1969
  ],
1970
1970
  },
1971
+ {
1972
+ maintainedBy: "metaManager",
1973
+ namespace: "meta",
1974
+ name: "page",
1975
+ code: "Page",
1976
+ singularCode: "page",
1977
+ pluralCode: "pages",
1978
+ schema: "public",
1979
+ tableName: "meta_pages",
1980
+ properties: [
1981
+ {
1982
+ name: "id",
1983
+ code: "id",
1984
+ columnName: "id",
1985
+ type: "integer",
1986
+ required: true,
1987
+ autoIncrement: true,
1988
+ },
1989
+ {
1990
+ name: "code",
1991
+ code: "code",
1992
+ columnName: "code",
1993
+ type: "text",
1994
+ required: true,
1995
+ },
1996
+ {
1997
+ name: "parentCode",
1998
+ code: "parentCode",
1999
+ columnName: "parent_code",
2000
+ type: "text",
2001
+ required: false,
2002
+ },
2003
+ {
2004
+ name: "subSystem",
2005
+ code: "subSystem",
2006
+ columnName: "sub_system",
2007
+ type: "text",
2008
+ required: false,
2009
+ },
2010
+ {
2011
+ name: "appCode",
2012
+ code: "appCode",
2013
+ columnName: "app_code",
2014
+ type: "text",
2015
+ required: false,
2016
+ },
2017
+ {
2018
+ name: "routePath",
2019
+ code: "routePath",
2020
+ columnName: "route_path",
2021
+ type: "text",
2022
+ required: false,
2023
+ },
2024
+ {
2025
+ name: "name",
2026
+ code: "name",
2027
+ columnName: "name",
2028
+ type: "text",
2029
+ required: false,
2030
+ },
2031
+ {
2032
+ name: "title",
2033
+ code: "title",
2034
+ columnName: "title",
2035
+ type: "text",
2036
+ required: false,
2037
+ },
2038
+ {
2039
+ name: "config",
2040
+ code: "config",
2041
+ columnName: "config",
2042
+ type: "json",
2043
+ required: false,
2044
+ },
2045
+ {
2046
+ name: "permissionCheck",
2047
+ code: "permissionCheck",
2048
+ columnName: "permission_check",
2049
+ type: "json",
2050
+ required: false,
2051
+ },
2052
+ ],
2053
+ indexes: [
2054
+ {
2055
+ name: "meta_pages_code_uindex",
2056
+ properties: [
2057
+ {
2058
+ code: "code",
2059
+ },
2060
+ ],
2061
+ unique: true,
2062
+ },
2063
+ {
2064
+ name: "meta_pages_subsystem_appcode_code_idx",
2065
+ properties: [
2066
+ {
2067
+ code: "subSystem",
2068
+ },
2069
+ {
2070
+ code: "appCode",
2071
+ },
2072
+ {
2073
+ code: "code",
2074
+ },
2075
+ ],
2076
+ },
2077
+ ],
2078
+ },
1971
2079
  ],
1972
2080
  dataDictionaries: [],
1973
2081
  routes: [
@@ -5582,7 +5690,7 @@ class MetaService {
5582
5690
  const tablesInDb = await server.queryDatabaseObject(sqlQueryTableInformations);
5583
5691
  const { queryBuilder } = server;
5584
5692
  for (const model of applicationConfig.models) {
5585
- logger.debug(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
5693
+ logger.info(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
5586
5694
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
5587
5695
  const expectedTableName = model.tableName;
5588
5696
  const tableInDb = lodash.find(tablesInDb, { table_schema: expectedTableSchema, table_name: expectedTableName });
@@ -5599,7 +5707,7 @@ class MetaService {
5599
5707
  LEFT JOIN pg_catalog.pg_description d ON (d.objoid = st.relid and d.objsubid = c.ordinal_position);`;
5600
5708
  const columnsInDb = await server.queryDatabaseObject(sqlQueryColumnInformations, []);
5601
5709
  for (const model of applicationConfig.models) {
5602
- logger.debug(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
5710
+ logger.info(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
5603
5711
  for (const property of model.properties) {
5604
5712
  let columnDDL = "";
5605
5713
  if (isRelationProperty(property)) {
@@ -5740,7 +5848,7 @@ class MetaService {
5740
5848
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
5741
5849
  const expectedTableName = model.tableName;
5742
5850
  const expectedContraintName = `${expectedTableName}_pk`;
5743
- logger.debug(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
5851
+ logger.info(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
5744
5852
  const constraintInDb = lodash.find(constraintsInDb, {
5745
5853
  table_schema: expectedTableSchema,
5746
5854
  table_name: expectedTableName,
@@ -5756,7 +5864,7 @@ class MetaService {
5756
5864
  if (!model.indexes || !model.indexes.length) {
5757
5865
  continue;
5758
5866
  }
5759
- logger.debug(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
5867
+ logger.info(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
5760
5868
  for (const index of model.indexes) {
5761
5869
  const sqlCreateIndex = generateTableIndexDDL(queryBuilder, server, model, index);
5762
5870
  try {
@@ -7216,19 +7324,8 @@ async function handler$c(plugin, ctx, options) {
7216
7324
  };
7217
7325
  return;
7218
7326
  }
7219
- const userEntitySingularCode = plugin.options?.userEntitySingularCode || "oc_user";
7220
- const profilePropertyCodes = plugin.options?.profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
7221
- const entityManager = server.getEntityManager(userEntitySingularCode);
7222
- const user = await entityManager.findEntity({
7223
- filters: [
7224
- {
7225
- operator: "eq",
7226
- field: "id",
7227
- value: userId,
7228
- },
7229
- ],
7230
- properties: profilePropertyCodes,
7231
- });
7327
+ const authService = server.getService("authService");
7328
+ const user = await authService.getProfileOfUser(userId);
7232
7329
  ctx.output = {
7233
7330
  user,
7234
7331
  };
@@ -7407,9 +7504,13 @@ var pluginRoutes$7 = [changePassword, getMyProfile$1, resetPassword, signin$1, s
7407
7504
  class AuthService {
7408
7505
  #server;
7409
7506
  #jwtKey;
7410
- constructor(server, jwtKey) {
7507
+ #userEntitySingularCode;
7508
+ #profilePropertyCodes;
7509
+ constructor(server, options) {
7411
7510
  this.#server = server;
7412
- this.#jwtKey = jwtKey;
7511
+ this.#jwtKey = options.jwtKey;
7512
+ this.#userEntitySingularCode = options.userEntitySingularCode;
7513
+ this.#profilePropertyCodes = options.profilePropertyCodes;
7413
7514
  }
7414
7515
  createUserAccessToken(options) {
7415
7516
  const secretKey = Buffer.from(this.#jwtKey, "base64");
@@ -7422,6 +7523,22 @@ class AuthService {
7422
7523
  }, secretKey);
7423
7524
  return token;
7424
7525
  }
7526
+ async getProfileOfUser(userId) {
7527
+ const userEntitySingularCode = this.#userEntitySingularCode || "oc_user";
7528
+ const profilePropertyCodes = this.#profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
7529
+ const entityManager = this.#server.getEntityManager(userEntitySingularCode);
7530
+ const user = await entityManager.findEntity({
7531
+ filters: [
7532
+ {
7533
+ operator: "eq",
7534
+ field: "id",
7535
+ value: userId,
7536
+ },
7537
+ ],
7538
+ properties: profilePropertyCodes,
7539
+ });
7540
+ return user;
7541
+ }
7425
7542
  }
7426
7543
 
7427
7544
  /**
@@ -7460,7 +7577,11 @@ class AuthPlugin {
7460
7577
  server.appendApplicationConfig({ models: pluginModels$6 });
7461
7578
  }
7462
7579
  async configureServices(server, applicationConfig) {
7463
- this.#authService = new AuthService(server, server.config.jwtKey);
7580
+ this.#authService = new AuthService(server, {
7581
+ jwtKey: server.config.jwtKey,
7582
+ userEntitySingularCode: this.#options.userEntitySingularCode,
7583
+ profilePropertyCodes: this.#options.profilePropertyCodes,
7584
+ });
7464
7585
  server.registerService("authService", this.#authService);
7465
7586
  }
7466
7587
  async configureRoutes(server, applicationConfig) {
@@ -1,4 +1,9 @@
1
1
  import { IRpdServer } from "../../../core/server";
2
+ export type AuthServiceOptions = {
3
+ jwtKey: string;
4
+ userEntitySingularCode?: string;
5
+ profilePropertyCodes?: string[];
6
+ };
2
7
  export interface UserAccessToken {
3
8
  sub: "userAccessToken";
4
9
  aud: string;
@@ -10,6 +15,7 @@ export interface CreateUserAccessTokenOptions {
10
15
  }
11
16
  export default class AuthService {
12
17
  #private;
13
- constructor(server: IRpdServer, jwtKey: string);
18
+ constructor(server: IRpdServer, options: AuthServiceOptions);
14
19
  createUserAccessToken(options: CreateUserAccessTokenOptions): string;
20
+ getProfileOfUser(userId: number): Promise<any>;
15
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.9.8",
3
+ "version": "0.10.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -736,6 +736,114 @@ export default {
736
736
  },
737
737
  ],
738
738
  },
739
+ {
740
+ maintainedBy: "metaManager",
741
+ namespace: "meta",
742
+ name: "page",
743
+ code: "Page",
744
+ singularCode: "page",
745
+ pluralCode: "pages",
746
+ schema: "public",
747
+ tableName: "meta_pages",
748
+ properties: [
749
+ {
750
+ name: "id",
751
+ code: "id",
752
+ columnName: "id",
753
+ type: "integer",
754
+ required: true,
755
+ autoIncrement: true,
756
+ },
757
+ {
758
+ name: "code",
759
+ code: "code",
760
+ columnName: "code",
761
+ type: "text",
762
+ required: true,
763
+ },
764
+ {
765
+ name: "parentCode",
766
+ code: "parentCode",
767
+ columnName: "parent_code",
768
+ type: "text",
769
+ required: false,
770
+ },
771
+ {
772
+ name: "subSystem",
773
+ code: "subSystem",
774
+ columnName: "sub_system",
775
+ type: "text",
776
+ required: false,
777
+ },
778
+ {
779
+ name: "appCode",
780
+ code: "appCode",
781
+ columnName: "app_code",
782
+ type: "text",
783
+ required: false,
784
+ },
785
+ {
786
+ name: "routePath",
787
+ code: "routePath",
788
+ columnName: "route_path",
789
+ type: "text",
790
+ required: false,
791
+ },
792
+ {
793
+ name: "name",
794
+ code: "name",
795
+ columnName: "name",
796
+ type: "text",
797
+ required: false,
798
+ },
799
+ {
800
+ name: "title",
801
+ code: "title",
802
+ columnName: "title",
803
+ type: "text",
804
+ required: false,
805
+ },
806
+ {
807
+ name: "config",
808
+ code: "config",
809
+ columnName: "config",
810
+ type: "json",
811
+ required: false,
812
+ },
813
+ {
814
+ name: "permissionCheck",
815
+ code: "permissionCheck",
816
+ columnName: "permission_check",
817
+ type: "json",
818
+ required: false,
819
+ },
820
+ ],
821
+ indexes: [
822
+ {
823
+ name: "meta_pages_code_uindex",
824
+ properties: [
825
+ {
826
+ code: "code",
827
+ },
828
+ ],
829
+ unique: true,
830
+ },
831
+ {
832
+ name: "meta_pages_subsystem_appcode_code_idx",
833
+ properties: [
834
+ {
835
+ code: "subSystem",
836
+ },
837
+ {
838
+ code: "appCode",
839
+ },
840
+ {
841
+ code: "code",
842
+ },
843
+ ],
844
+ },
845
+ ],
846
+ },
739
847
  ],
740
848
  dataDictionaries: [],
741
849
  routes: [
@@ -62,7 +62,11 @@ class AuthPlugin implements RapidPlugin {
62
62
  }
63
63
 
64
64
  async configureServices(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
65
- this.#authService = new AuthService(server, server.config.jwtKey);
65
+ this.#authService = new AuthService(server, {
66
+ jwtKey: server.config.jwtKey,
67
+ userEntitySingularCode: this.#options.userEntitySingularCode,
68
+ profilePropertyCodes: this.#options.profilePropertyCodes,
69
+ });
66
70
  server.registerService("authService", this.#authService);
67
71
  }
68
72
 
@@ -1,6 +1,7 @@
1
1
  import { ActionHandlerContext } from "~/core/actionHandler";
2
2
  import { RapidPlugin } from "~/core/server";
3
3
  import AuthPlugin from "../AuthPlugin";
4
+ import AuthService from "../services/AuthService";
4
5
 
5
6
  export const code = "getMyProfile";
6
7
 
@@ -18,19 +19,8 @@ export async function handler(plugin: AuthPlugin, ctx: ActionHandlerContext, opt
18
19
  return;
19
20
  }
20
21
 
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);
24
- const user = await entityManager.findEntity({
25
- filters: [
26
- {
27
- operator: "eq",
28
- field: "id",
29
- value: userId,
30
- },
31
- ],
32
- properties: profilePropertyCodes,
33
- });
22
+ const authService = server.getService<AuthService>("authService");
23
+ const user = await authService.getProfileOfUser(userId);
34
24
 
35
25
  ctx.output = {
36
26
  user,
@@ -1,6 +1,12 @@
1
1
  import { IRpdServer } from "~/core/server";
2
2
  import { createJwt } from "~/utilities/jwtUtility";
3
3
 
4
+ export type AuthServiceOptions = {
5
+ jwtKey: string;
6
+ userEntitySingularCode?: string;
7
+ profilePropertyCodes?: string[];
8
+ };
9
+
4
10
  export interface UserAccessToken {
5
11
  sub: "userAccessToken";
6
12
  aud: string;
@@ -15,10 +21,14 @@ export interface CreateUserAccessTokenOptions {
15
21
  export default class AuthService {
16
22
  #server: IRpdServer;
17
23
  #jwtKey: string;
24
+ #userEntitySingularCode?: string;
25
+ #profilePropertyCodes?: string[];
18
26
 
19
- constructor(server: IRpdServer, jwtKey: string) {
27
+ constructor(server: IRpdServer, options: AuthServiceOptions) {
20
28
  this.#server = server;
21
- this.#jwtKey = jwtKey;
29
+ this.#jwtKey = options.jwtKey;
30
+ this.#userEntitySingularCode = options.userEntitySingularCode;
31
+ this.#profilePropertyCodes = options.profilePropertyCodes;
22
32
  }
23
33
 
24
34
  createUserAccessToken(options: CreateUserAccessTokenOptions): string {
@@ -36,4 +46,21 @@ export default class AuthService {
36
46
 
37
47
  return token;
38
48
  }
49
+
50
+ async getProfileOfUser(userId: number) {
51
+ const userEntitySingularCode = this.#userEntitySingularCode || "oc_user";
52
+ const profilePropertyCodes = this.#profilePropertyCodes || ["id", "name", "login", "email", "department", "roles", "state", "createdAt"];
53
+ const entityManager = this.#server.getEntityManager(userEntitySingularCode);
54
+ const user = await entityManager.findEntity({
55
+ filters: [
56
+ {
57
+ operator: "eq",
58
+ field: "id",
59
+ value: userId,
60
+ },
61
+ ],
62
+ properties: profilePropertyCodes,
63
+ });
64
+ return user;
65
+ }
39
66
  }
@@ -156,7 +156,7 @@ export default class MetaService {
156
156
  const { queryBuilder } = server;
157
157
 
158
158
  for (const model of applicationConfig.models) {
159
- logger.debug(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
159
+ logger.info(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
160
160
 
161
161
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
162
162
  const expectedTableName = model.tableName;
@@ -176,7 +176,7 @@ export default class MetaService {
176
176
  const columnsInDb: ColumnInformation[] = await server.queryDatabaseObject(sqlQueryColumnInformations, []);
177
177
 
178
178
  for (const model of applicationConfig.models) {
179
- logger.debug(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
179
+ logger.info(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
180
180
 
181
181
  for (const property of model.properties) {
182
182
  let columnDDL = "";
@@ -336,7 +336,7 @@ export default class MetaService {
336
336
  const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
337
337
  const expectedTableName = model.tableName;
338
338
  const expectedContraintName = `${expectedTableName}_pk`;
339
- logger.debug(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
339
+ logger.info(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
340
340
  const constraintInDb = find(constraintsInDb, {
341
341
  table_schema: expectedTableSchema,
342
342
  table_name: expectedTableName,
@@ -357,7 +357,7 @@ export default class MetaService {
357
357
  continue;
358
358
  }
359
359
 
360
- logger.debug(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
360
+ logger.info(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
361
361
  for (const index of model.indexes) {
362
362
  const sqlCreateIndex = generateTableIndexDDL(queryBuilder, server, model, index);
363
363
  try {