chyz 1.0.12-rc.7 → 1.0.13-rc.10

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.
Files changed (116) hide show
  1. package/BaseChyz.ts +118 -18
  2. package/Chyz.ts +0 -3
  3. package/Examples/Controllers/ApiController.ts +96 -29
  4. package/Examples/Controllers/KeyCloakController.ts +100 -0
  5. package/Examples/Controllers/PublicController.ts +5 -7
  6. package/Examples/Controllers/SiteController.ts +82 -32
  7. package/Examples/Models/Categories.ts +47 -0
  8. package/Examples/Models/Customer.ts +115 -0
  9. package/Examples/Models/KeycloakUser.ts +66 -0
  10. package/Examples/Models/Order.ts +64 -0
  11. package/Examples/Models/OrderItem.ts +27 -0
  12. package/Examples/Models/ProductModels.ts +49 -0
  13. package/Examples/Models/ProductToCategories.ts +46 -0
  14. package/Examples/Models/Products.ts +50 -0
  15. package/Examples/Models/Stocks.ts +60 -0
  16. package/Examples/Models/User.ts +66 -35
  17. package/Examples/Models/UserPermission.ts +37 -0
  18. package/Examples/Models/index.ts +19 -0
  19. package/Examples/index-keycloack.ts +78 -0
  20. package/Examples/index.ts +16 -14
  21. package/Examples/keycloak.json +7 -0
  22. package/Examples/log/app.log +6126 -1045
  23. package/Examples/log/errors.log +1503 -234
  24. package/Examples/package.json +46 -44
  25. package/Examples/tsconfig.json +3 -2
  26. package/README.md +116 -16
  27. package/base/ActionFilter.ts +2 -2
  28. package/base/BaseError.ts +2 -2
  29. package/base/DataErrorDbException.ts +1 -1
  30. package/base/DbConnection.ts +8 -2
  31. package/base/ForbiddenHttpException.ts +1 -1
  32. package/base/InvalidArgumentException.ts +16 -0
  33. package/base/InvalidConfigException.ts +1 -1
  34. package/base/Model.ts +206 -17
  35. package/base/ModelManager.ts +14 -0
  36. package/base/NotFoundHttpException.ts +1 -1
  37. package/base/RestClient.ts +28 -0
  38. package/base/UnauthorizedHttpException.ts +2 -1
  39. package/base/ValidationHttpException.ts +14 -0
  40. package/base/db/Exception.ts +14 -0
  41. package/base/index.ts +4 -0
  42. package/dist/BaseChyz.js +108 -23
  43. package/dist/BaseChyz.js.map +1 -1
  44. package/dist/Chyz.js.map +1 -1
  45. package/dist/base/ActionFilter.js +2 -2
  46. package/dist/base/ActionFilter.js.map +1 -1
  47. package/dist/base/BaseError.js +2 -2
  48. package/dist/base/BaseError.js.map +1 -1
  49. package/dist/base/DataErrorDbException.js +1 -1
  50. package/dist/base/DataErrorDbException.js.map +1 -1
  51. package/dist/base/DbConnection.js +9 -2
  52. package/dist/base/DbConnection.js.map +1 -1
  53. package/dist/base/ForbiddenHttpException.js +1 -1
  54. package/dist/base/ForbiddenHttpException.js.map +1 -1
  55. package/dist/base/InvalidArgumentException.js +18 -0
  56. package/dist/base/InvalidArgumentException.js.map +1 -0
  57. package/dist/base/InvalidConfigException.js +1 -1
  58. package/dist/base/InvalidConfigException.js.map +1 -1
  59. package/dist/base/Model.js +187 -15
  60. package/dist/base/Model.js.map +1 -1
  61. package/dist/base/ModelManager.js +17 -0
  62. package/dist/base/ModelManager.js.map +1 -0
  63. package/dist/base/NotFoundHttpException.js +1 -1
  64. package/dist/base/NotFoundHttpException.js.map +1 -1
  65. package/dist/base/RestClient.js +27 -0
  66. package/dist/base/RestClient.js.map +1 -0
  67. package/dist/base/UnauthorizedHttpException.js +1 -1
  68. package/dist/base/UnauthorizedHttpException.js.map +1 -1
  69. package/dist/base/ValidationHttpException.js +18 -0
  70. package/dist/base/ValidationHttpException.js.map +1 -0
  71. package/dist/base/db/Exception.js +16 -0
  72. package/dist/base/db/Exception.js.map +1 -0
  73. package/dist/base/index.js +4 -0
  74. package/dist/base/index.js.map +1 -1
  75. package/dist/filters/AccessControl.js +2 -2
  76. package/dist/filters/AccessControl.js.map +1 -1
  77. package/dist/filters/AccessRule.js.map +1 -1
  78. package/dist/filters/auth/AuthMethod.js +2 -2
  79. package/dist/filters/auth/AuthMethod.js.map +1 -1
  80. package/dist/filters/auth/HttpHeaderAuth.js.map +1 -1
  81. package/dist/filters/auth/JwtHttpBearerAuth.js +1 -0
  82. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
  83. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
  84. package/dist/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
  85. package/dist/index.js +28 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/package.json +57 -0
  88. package/dist/rbac/AuthAssignment.js +45 -0
  89. package/dist/rbac/AuthAssignment.js.map +1 -0
  90. package/dist/rbac/AuthItem.js +52 -0
  91. package/dist/rbac/AuthItem.js.map +1 -0
  92. package/dist/rbac/AuthItemChild.js +44 -0
  93. package/dist/rbac/AuthItemChild.js.map +1 -0
  94. package/dist/rbac/AuthManager.js +351 -0
  95. package/dist/rbac/AuthManager.js.map +1 -0
  96. package/dist/web/{User.js → WebUser.js} +12 -7
  97. package/dist/web/WebUser.js.map +1 -0
  98. package/filters/AccessControl.ts +3 -3
  99. package/filters/AccessRule.ts +2 -2
  100. package/filters/auth/AuthMethod.ts +4 -4
  101. package/filters/auth/HttpHeaderAuth.ts +2 -2
  102. package/filters/auth/JwtHttpBearerAuth.ts +4 -5
  103. package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
  104. package/index.ts +14 -0
  105. package/package-lock.json +5259 -0
  106. package/package.json +57 -52
  107. package/rbac/AuthAssignment.ts +50 -0
  108. package/rbac/AuthItem.ts +57 -0
  109. package/rbac/AuthItemChild.ts +50 -0
  110. package/rbac/AuthManager.ts +388 -0
  111. package/web/{User.ts → WebUser.ts} +10 -6
  112. package/.idea/Chy-Nodejs-Framework.iml +0 -12
  113. package/.idea/jsLibraryMappings.xml +0 -6
  114. package/.idea/modules.xml +0 -8
  115. package/.idea/vcs.xml +0 -6
  116. package/dist/web/User.js.map +0 -1
@@ -4,20 +4,45 @@
4
4
  * E-mail: cihan@chy.com.tr
5
5
  * Github:https://github.com/cihan53/
6
6
  */
7
+ // @ts-ignore
8
+
7
9
 
8
10
  import {IdentityInterface} from "../../web/IdentityInterface";
9
- // @ts-ignore
10
- import {DataTypes, Model} from "sequelize";
11
- import BaseChyz from "../../BaseChyz";
11
+ import {DataTypes, Model} from "../../base";
12
+ import {BaseChyz} from "../../index";
13
+
14
+ const JsonWebToken = require("jsonwebtoken");
15
+
16
+ export class User extends Model implements IdentityInterface {
17
+ [x: string]: any;
18
+
19
+ public tableName() {
20
+ return 'users';
21
+ }
22
+
23
+ findIdentity(id: number) {
24
+ throw new Error("Method not implemented.");
25
+ }
12
26
 
13
- export class User implements IdentityInterface {
27
+ getId(): number {
28
+ throw new Error("Method not implemented.");
29
+ }
14
30
 
15
- private _model ;
31
+ getAuthKey(): string {
32
+ throw new Error("Method not implemented.");
33
+ }
16
34
 
17
- constructor() {
18
- const sequelize = BaseChyz.getComponent("db").db;
19
- this._model = sequelize.define('User', {
35
+ validateAuthKey(authKey: string): boolean {
36
+ throw new Error("Method not implemented.");
37
+ }
38
+
39
+ public attributes() {
40
+ return {
20
41
  // Model attributes are defined here
42
+ name: {
43
+ type: DataTypes.STRING,
44
+ allowNull: false
45
+ },
21
46
  username: {
22
47
  type: DataTypes.STRING,
23
48
  allowNull: false
@@ -26,44 +51,50 @@ export class User implements IdentityInterface {
26
51
  type: DataTypes.STRING,
27
52
  allowNull: false
28
53
  },
29
- user_role: {
54
+ email: {
30
55
  type: DataTypes.STRING,
31
56
  allowNull: false
32
57
  },
33
- salt_text: {
58
+ permissions_id: {
59
+ type: DataTypes.INTEGER,
60
+ allowNull: false
61
+ },
62
+ authkey: {
63
+ type: DataTypes.STRING
64
+ // allowNull defaults to true
65
+ },
66
+ status: {
34
67
  type: DataTypes.STRING
35
68
  // allowNull defaults to true
36
69
  }
37
- }, {
38
- tableName: 'users',
39
- timestamps: false
40
- });
41
- }
42
-
43
-
44
- get model(): any {
45
- return this._model;
46
- }
47
-
48
- findIdentity(id) {
70
+ }
49
71
  }
50
72
 
51
73
  async findIdentityByAccessToken(token, type) {
52
- let identity = await this._model.findOne({where: {salt_text: token.signature}});
53
- return identity;
54
- }
55
-
56
- getAuthKey(): string {
57
- return "";
58
- }
74
+ let decoded = JsonWebToken.decode(token, {complete: true})
59
75
 
60
- getId(): number {
61
- return 0;
62
- }
76
+ if(!decoded.payload.user) {
77
+ return null;
78
+ }
63
79
 
64
- validateAuthKey(authKey: string): boolean | null {
65
- return undefined;
80
+ let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
81
+ if (identity) {
82
+ BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
83
+ try {
84
+ JsonWebToken.verify(token, identity.authkey);
85
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
86
+ return identity;
87
+ } catch (err) {
88
+ if (err.name == "TokenExpiredError")
89
+ BaseChyz.debug("Find Identity By AccessToken: Token Expired")
90
+ else
91
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
92
+ return null;
93
+ }
94
+ }
95
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
96
+ return null;
66
97
  }
67
- }
68
98
 
69
99
 
100
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ // @ts-ignore
8
+
9
+
10
+ import {DataTypes, Model} from "../../base";
11
+
12
+ export class UserPermissionClass extends Model {
13
+ [x: string]: any;
14
+
15
+ public tableName() {
16
+ return 'user_permissions';
17
+ }
18
+
19
+
20
+ public attributes() {
21
+ return {
22
+ // Model attributes are defined here
23
+ object_type: {
24
+ type: DataTypes.STRING,
25
+ allowNull: false
26
+ },
27
+ object_value: {
28
+ type: DataTypes.STRING,
29
+ allowNull: false
30
+ }
31
+
32
+ }
33
+ }
34
+ }
35
+
36
+ // const UserPermission = new UserPermissionClass();
37
+ // export {UserPermission}
@@ -0,0 +1,19 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
+ * Author: Cihan Ozturk
5
+ * E-mail: cihan@chy.com.tr
6
+ * Github:https://github.com/cihan53/
7
+ *
8
+ */
9
+ import {ModelManager} from "../../base";
10
+ // import {Order, OrderClass} from "./Order";
11
+ // import {Customer, CustomerClass} from "./Customer";
12
+ // import {Products} from "./Products";
13
+ // import {ProductModels} from "./ProductModels";
14
+ // import {Categories} from "./Categories";
15
+ // import {ProductToCategories} from "./ProductToCategories";
16
+ //
17
+ // Dependencies._register({Order, Customer,CustomerClass,OrderClass, Products, ProductModels, Categories, ProductToCategories});
18
+ //
19
+ // console.log("denmemem")
@@ -0,0 +1,78 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+
9
+ require('dotenv-flow').config();
10
+
11
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
12
+
13
+ import Chyz from "../Chyz";
14
+ import {WebUser} from "../web/WebUser";
15
+ import {KeycloakUser as Identity} from "./Models/KeycloakUser";
16
+ // @ts-ignore
17
+ import {DbConnection} from "../base/DbConnection";
18
+
19
+ var Keycloak = require('keycloak-connect');
20
+ var session = require('express-session');
21
+ var memoryStore = new session.MemoryStore();
22
+
23
+
24
+ var keycloakConfig = {
25
+ "realm": "CameraBox",
26
+ "auth-server-url": "https://keycloak.hubbox.io:8080/auth/",
27
+ //"ssl-required": "external",
28
+ "resource": "izanami",
29
+ "verify-token-audience": true,
30
+ "bearerOnly": true,
31
+ "confidential-port":0,
32
+ "policy-enforcer":{},
33
+ "credentials": {
34
+ "secret": "0b476571-28ab-49b1-9968-90fce6294d5a"
35
+ }
36
+
37
+ };
38
+
39
+
40
+
41
+ Keycloak.prototype.accessDenied = function () {
42
+ return null;
43
+ }
44
+
45
+ var keycloak = new Keycloak({scope: 'offline_access'}, keycloakConfig);
46
+
47
+
48
+ let config = {
49
+ port: 3000,
50
+ controllerpath: "C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
51
+ components: {
52
+ db: {
53
+ class: DbConnection,
54
+ database: process.env.DBDATABASE,
55
+ username: process.env.DBUSER,
56
+ password: process.env.DBPASS,
57
+ options: {
58
+ host: process.env.DBHOST,
59
+ dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
60
+ // disable logging; default: console.log
61
+ logging: false
62
+ }
63
+ },
64
+ user: {
65
+ 'class': WebUser,
66
+ 'identityClass': Identity
67
+ }
68
+ },
69
+ middlewares: {
70
+ keycloak: {
71
+ keycloak: keycloak,
72
+ config: {
73
+ logout: '/logout'
74
+ }
75
+ }
76
+ }
77
+ }
78
+ Chyz.app(config).Start();
package/Examples/index.ts CHANGED
@@ -6,33 +6,35 @@
6
6
  */
7
7
 
8
8
 
9
+ import {BaseChyz} from "../index";
10
+ require('dotenv-flow').config();
9
11
  import Chyz from "../Chyz";
10
- import {User} from "../web/User";
11
- import {User as Identity } from "./Models/User";
12
- // @ts-ignore
13
- import {DbConnection} from "../base/DbConnection";
12
+ import {WebUser} from "../web/WebUser";
13
+ import {User} from "./Models/User";
14
+ import {DbConnection} from "../base";
14
15
 
15
16
 
16
17
  let config = {
17
- port: 3000,
18
- controllerpath:"C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
18
+ port: process.env.PORT,
19
+ controllerpath: "C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
19
20
  components: {
20
- db:{
21
- class:DbConnection,
21
+ db: {
22
+ class: DbConnection,
22
23
  database: process.env.DBDATABASE,
23
- username:process.env.DBUSER,
24
- password:process.env.DBPASS,
25
- options:{
24
+ username: process.env.DBUSER,
25
+ password: process.env.DBPASS,
26
+ options: {
26
27
  host: process.env.DBHOST,
27
28
  dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
28
29
  // disable logging; default: console.log
29
- logging: false
30
+ logging: (msg: any) => BaseChyz.debug(msg)
30
31
  }
31
32
  },
32
33
  user: {
33
- 'class': User,
34
- 'identityClass':Identity
34
+ 'class': WebUser,
35
+ 'identityClass': User
35
36
  }
36
37
  }
38
+
37
39
  }
38
40
  Chyz.app(config).Start();
@@ -0,0 +1,7 @@
1
+ {
2
+ "realm": "quickstart",
3
+ "bearer-only": true,
4
+ "auth-server-url": "http://localhost:8180/auth",
5
+ "ssl-required": "external",
6
+ "resource": "service-nodejs"
7
+ }