chyz 1.0.12-rc.7 → 1.0.13-rc.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.
Files changed (96) hide show
  1. package/BaseChyz.ts +76 -14
  2. package/Chyz.ts +0 -3
  3. package/Examples/Controllers/ApiController.ts +88 -30
  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 +36 -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 +50 -0
  13. package/Examples/Models/ProductToCategories.ts +35 -0
  14. package/Examples/Models/Products.ts +49 -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/index-keycloack.ts +78 -0
  19. package/Examples/index.ts +16 -15
  20. package/Examples/keycloak.json +7 -0
  21. package/Examples/log/app.log +903 -1034
  22. package/Examples/log/errors.log +79 -256
  23. package/Examples/package.json +46 -44
  24. package/Examples/tsconfig.json +1 -1
  25. package/Examples/yarn.lock +2549 -0
  26. package/README.md +118 -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/InvalidConfigException.ts +1 -1
  33. package/base/Model.ts +204 -15
  34. package/base/NotFoundHttpException.ts +1 -1
  35. package/base/RestClient.ts +28 -0
  36. package/base/UnauthorizedHttpException.ts +2 -1
  37. package/base/ValidationHttpException.ts +14 -0
  38. package/base/db/Exception.ts +14 -0
  39. package/base/index.ts +2 -0
  40. package/dist/BaseChyz.js +72 -25
  41. package/dist/BaseChyz.js.map +1 -1
  42. package/dist/Chyz.js.map +1 -1
  43. package/dist/base/ActionFilter.js +2 -2
  44. package/dist/base/ActionFilter.js.map +1 -1
  45. package/dist/base/BaseError.js +2 -2
  46. package/dist/base/BaseError.js.map +1 -1
  47. package/dist/base/DataErrorDbException.js +1 -1
  48. package/dist/base/DataErrorDbException.js.map +1 -1
  49. package/dist/base/DbConnection.js +9 -2
  50. package/dist/base/DbConnection.js.map +1 -1
  51. package/dist/base/ForbiddenHttpException.js +1 -1
  52. package/dist/base/ForbiddenHttpException.js.map +1 -1
  53. package/dist/base/InvalidConfigException.js +1 -1
  54. package/dist/base/InvalidConfigException.js.map +1 -1
  55. package/dist/base/Model.js +181 -13
  56. package/dist/base/Model.js.map +1 -1
  57. package/dist/base/NotFoundHttpException.js +1 -1
  58. package/dist/base/NotFoundHttpException.js.map +1 -1
  59. package/dist/base/RestClient.js +27 -0
  60. package/dist/base/RestClient.js.map +1 -0
  61. package/dist/base/UnauthorizedHttpException.js +1 -1
  62. package/dist/base/UnauthorizedHttpException.js.map +1 -1
  63. package/dist/base/ValidationHttpException.js +18 -0
  64. package/dist/base/ValidationHttpException.js.map +1 -0
  65. package/dist/base/db/Exception.js +16 -0
  66. package/dist/base/db/Exception.js.map +1 -0
  67. package/dist/base/index.js +2 -0
  68. package/dist/base/index.js.map +1 -1
  69. package/dist/filters/AccessControl.js +2 -2
  70. package/dist/filters/AccessControl.js.map +1 -1
  71. package/dist/filters/AccessRule.js.map +1 -1
  72. package/dist/filters/auth/AuthMethod.js +2 -2
  73. package/dist/filters/auth/AuthMethod.js.map +1 -1
  74. package/dist/filters/auth/HttpHeaderAuth.js.map +1 -1
  75. package/dist/filters/auth/JwtHttpBearerAuth.js +1 -0
  76. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
  77. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
  78. package/dist/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
  79. package/dist/index.js +29 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/web/{User.js → WebUser.js} +12 -7
  82. package/dist/web/WebUser.js.map +1 -0
  83. package/filters/AccessControl.ts +3 -3
  84. package/filters/AccessRule.ts +2 -2
  85. package/filters/auth/AuthMethod.ts +4 -4
  86. package/filters/auth/HttpHeaderAuth.ts +2 -2
  87. package/filters/auth/JwtHttpBearerAuth.ts +4 -5
  88. package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
  89. package/index.ts +14 -0
  90. package/package.json +55 -52
  91. package/web/{User.ts → WebUser.ts} +10 -6
  92. package/.idea/Chy-Nodejs-Framework.iml +0 -12
  93. package/.idea/jsLibraryMappings.xml +0 -6
  94. package/.idea/modules.xml +0 -8
  95. package/.idea/vcs.xml +0 -6
  96. package/dist/web/User.js.map +0 -1
@@ -0,0 +1,115 @@
1
+ // @ts-ignore
2
+ import {DataTypes, Model} from "../../base";
3
+
4
+ export class CustomerClass extends Model {
5
+ [x: string]: any;
6
+
7
+ public tableName() {
8
+ return 'customer';
9
+ }
10
+
11
+ public attributes() {
12
+ return {
13
+ name: {
14
+ type: DataTypes.STRING,
15
+ allowNull: false,
16
+ validate: {
17
+ notEmpty: true,
18
+ is: ["^[a-z0-9A-Z]+$", 'i'],
19
+ len: [4, 255],
20
+ }
21
+ },
22
+ firstname: {
23
+ type: DataTypes.STRING,
24
+ validate: {
25
+ is: ["^[a-z0-9A-Z]+$", 'i'],
26
+ len: [4, 255],
27
+ }
28
+ },
29
+ lastname: {
30
+ type: DataTypes.STRING,
31
+ validate: {
32
+ is: ["^[a-z0-9A-Z]+$", 'i'],
33
+ len: [4, 255],
34
+ }
35
+ },
36
+ companyName: {
37
+ type: DataTypes.STRING,
38
+ allowNull: true,
39
+ validate: {
40
+ is: /^[0-9A-Za-z =().:;+-şŞçÇöÖğĞıİüÜ]+$/i,
41
+ len: [4, 255],
42
+ }
43
+ },
44
+ email: {
45
+ type: DataTypes.STRING,
46
+ validate: {
47
+ isEmail: true
48
+ }
49
+ },
50
+ gsm_phone: {
51
+ type: DataTypes.STRING,
52
+ validate: {
53
+ is: ["^[0-9 +]+$", 'i'],
54
+ }
55
+ },
56
+ country: {
57
+ type: DataTypes.STRING,
58
+ validate: {
59
+ isAlpha: true,
60
+ }
61
+ },
62
+ address: {
63
+ type: DataTypes.STRING,
64
+ validate: {
65
+ is: ["^[\\w'\\-,.[0-9_\\/\\\\+=\"()<>;:\\[\\] şŞçÇöÖğĞıİüÜ ]{2,}$", "i"],
66
+ }
67
+ },
68
+ taxoffice: {
69
+ type: DataTypes.STRING,
70
+ validate: {
71
+ is: ["^[\\w'\\-,.[0-9_\\/\\\\+=\"()<>;:\\[\\] şŞçÇöÖğĞıİüÜ ]{2,}$", "i"],
72
+ }
73
+ },
74
+ taxnumber: {
75
+ unique: true,
76
+ type: DataTypes.STRING,
77
+ validate: {
78
+ is: ["^[0-9]+$", 'i'],
79
+ }
80
+ },
81
+ username: {
82
+ unique: true,
83
+ type: DataTypes.STRING,
84
+ validate: {
85
+ isEmail: true
86
+ }
87
+ },
88
+ password: {
89
+ type: DataTypes.STRING,
90
+ validate: {
91
+ is: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?\.#&])[A-Za-z\d$@$!%*\.?&]{8,12}/
92
+ }
93
+ },
94
+ "2fa": {
95
+ type: DataTypes.BOOLEAN,
96
+ validate: {
97
+ isBoolean: true
98
+ }
99
+ },
100
+ status: {
101
+ type: DataTypes.BOOLEAN,
102
+ validate: {
103
+ isBoolean: true
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ }
110
+
111
+ const Customer = new CustomerClass();
112
+ export {Customer};
113
+
114
+
115
+
@@ -0,0 +1,66 @@
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
+ import {IdentityInterface} from "../../web/IdentityInterface";
9
+ import {DataTypes, Model} from "../../base";
10
+ import BaseChyz from "../../BaseChyz";
11
+
12
+ const JsonWebToken = require("jsonwebtoken");
13
+
14
+ export class KeycloakUser implements IdentityInterface {
15
+
16
+ [x: string]: any;
17
+
18
+
19
+ findIdentity(id: number) {
20
+ throw new Error("Method not implemented.");
21
+ }
22
+
23
+ getId(): number {
24
+ throw new Error("Method not implemented.");
25
+ }
26
+
27
+ getAuthKey(): string {
28
+ throw new Error("Method not implemented.");
29
+ }
30
+
31
+ validateAuthKey(authKey: string): boolean {
32
+ throw new Error("Method not implemented.");
33
+ }
34
+
35
+ public attributes() {
36
+ return {
37
+ // Model attributes are defined here
38
+ username: {
39
+ type: DataTypes.STRING,
40
+ allowNull: false
41
+ },
42
+ password: {
43
+ type: DataTypes.STRING,
44
+ allowNull: false
45
+ },
46
+ user_role: {
47
+ type: DataTypes.STRING,
48
+ allowNull: false
49
+ },
50
+ salt_text: {
51
+ type: DataTypes.STRING
52
+ // allowNull defaults to true
53
+ }
54
+ }
55
+ }
56
+
57
+ async findIdentityByAccessToken(token, type) {
58
+ console.log(token,type)
59
+ // console.log(this)
60
+ // console.log(BaseChyz)
61
+ return null;
62
+ // return keycloak.protect('realm:user');
63
+ }
64
+ }
65
+
66
+
@@ -0,0 +1,64 @@
1
+ import {DataTypes, Model, Relation} from "../../base";
2
+ import {OrderItem} from "./OrderItem";
3
+
4
+ export class OrderClass extends Model {
5
+ [x: string]: any;
6
+
7
+ tableName() {
8
+ return 'order';
9
+ }
10
+
11
+
12
+ attributes() {
13
+
14
+ return {
15
+ customer_id: {
16
+ allowNull: false,
17
+ type: DataTypes.INTEGER,
18
+ },
19
+
20
+ crm_order_id: {
21
+ allowNull: false,
22
+ type: DataTypes.INTEGER,
23
+ },
24
+
25
+ total: {
26
+ allowNull: false,
27
+ type: DataTypes.FLOAT,
28
+ },
29
+
30
+ created_date: {
31
+ allowNull: false,
32
+ type: DataTypes.DATE,
33
+ // @ts-ignore
34
+ defaultValue: Model.NOW
35
+ },
36
+ status: {
37
+ type: DataTypes.BOOLEAN,
38
+ allowNull: false,
39
+ validate: {
40
+ isBoolean: true
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+
47
+ relation(): Relation[] {
48
+ return [
49
+ {
50
+ type: "hasOne",
51
+ sourceKey: "order_id",
52
+ foreignKey: "id",
53
+ model: OrderItem.model()
54
+ }
55
+ ]
56
+ }
57
+ }
58
+
59
+ const Order = new OrderClass()
60
+ export {Order};
61
+
62
+
63
+
64
+
@@ -0,0 +1,27 @@
1
+ import {DataTypes, Model} from "../../base";
2
+
3
+ export class OrderItemClass extends Model {
4
+ [x: string]: any;
5
+
6
+ public tableName() {
7
+ return 'order_items';
8
+ }
9
+
10
+ public attributes() {
11
+ return {
12
+
13
+ status: {
14
+ type: DataTypes.BOOLEAN,
15
+ validate: {
16
+ isBoolean: true
17
+ }
18
+ }
19
+ }
20
+ }
21
+
22
+ }
23
+ const OrderItem = new OrderItemClass()
24
+ export { OrderItem };
25
+
26
+
27
+
@@ -0,0 +1,50 @@
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
+ import {DataTypes, Model, Relation} from "../../base";
8
+ import {Products} from "./Products";
9
+
10
+ export class ProductModelsClass extends Model {
11
+ [x: string]: any;
12
+
13
+ tableName() {
14
+ return 'models';
15
+ }
16
+
17
+
18
+ attributes() {
19
+ return {
20
+ // Model attributes are defined here
21
+ title: {
22
+ type: DataTypes.STRING,
23
+ allowNull: false
24
+ },
25
+ stock_code: {
26
+ type: DataTypes.STRING,
27
+ allowNull: false
28
+ },
29
+ properties: {
30
+ type: DataTypes.STRING,
31
+ allowNull: false
32
+ }
33
+
34
+ }
35
+ }
36
+
37
+ relation(): Relation[] {
38
+ return [
39
+ {
40
+ type: "hasOne",
41
+ foreignKey: "id",
42
+ sourceKey: "category_id",
43
+ model: Products.model()
44
+ }
45
+ ]
46
+ }
47
+ }
48
+
49
+ const ProductModels = new ProductModelsClass();
50
+ export {ProductModels}
@@ -0,0 +1,35 @@
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
+ import {DataTypes, Model} from "../../base";
8
+
9
+ export class ProductToCategoriesClass extends Model {
10
+ [x: string]: any;
11
+
12
+ tableName() {
13
+ return 'product_to_categories';
14
+ }
15
+
16
+
17
+ attributes() {
18
+ return {
19
+ // Model attributes are defined here
20
+ product_id: {
21
+ type: DataTypes.INTEGER,
22
+ allowNull: false
23
+ },
24
+ categories_id: {
25
+ type: DataTypes.INTEGER,
26
+ allowNull: false
27
+ }
28
+
29
+ }
30
+ }
31
+
32
+ }
33
+
34
+ const ProductToCategories = new ProductToCategoriesClass()
35
+ export {ProductToCategories}
@@ -0,0 +1,49 @@
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
+ import {DataTypes, Model, Relation} from "../../base";
8
+ import {ProductModels} from "./ProductModels";
9
+
10
+ export class ProductsClass extends Model {
11
+ [x: string]: any;
12
+
13
+ tableName() {
14
+ return 'products';
15
+ }
16
+
17
+ attributes() {
18
+ return {
19
+ // Model attributes are defined here
20
+ title: {
21
+ type: DataTypes.STRING,
22
+ allowNull: false
23
+ },
24
+ model_id: {
25
+ type: DataTypes.INTEGER,
26
+ allowNull: false
27
+ },
28
+ properties: {
29
+ type: DataTypes.STRING,
30
+ allowNull: false
31
+ }
32
+
33
+ }
34
+ }
35
+
36
+ relations(): Relation[] {
37
+ return [
38
+ {
39
+ type: "hasOne",
40
+ foreignKey: "id",
41
+ sourceKey: "model_id",
42
+ model: ProductModels.model()
43
+ }
44
+ ]
45
+ }
46
+ }
47
+
48
+ const Products = new ProductsClass()
49
+ export {Products}
@@ -0,0 +1,60 @@
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
+ import {DataTypes, Model} from "../../base";
8
+
9
+ export class StocksClass extends Model {
10
+ [x: string]: any;
11
+
12
+ public tableName() {
13
+ return 'stock';
14
+ }
15
+
16
+ /**
17
+ * product_id int4
18
+ * properties jsonb
19
+ * status int2
20
+ * barcode string(20)
21
+ * stock_code string(20)
22
+ * model_id int4
23
+ */
24
+ public attributes() {
25
+ return {
26
+ // Model attributes are defined here
27
+ product_id: {
28
+ type: DataTypes.INTEGER,
29
+ allowNull: false
30
+ },
31
+
32
+ barcode: {
33
+ type: DataTypes.STRING,
34
+ allowNull: false,
35
+ validate: {
36
+ len: 20
37
+ }
38
+ },
39
+ stock_code: {
40
+ type: DataTypes.STRING,
41
+ allowNull: false,
42
+ validate: {
43
+ len: 20
44
+ }
45
+ },
46
+ model_id: {
47
+ type: DataTypes.INTEGER,
48
+ allowNull: false
49
+ },
50
+ status: {
51
+ type: DataTypes.INTEGER,
52
+ allowNull: false
53
+ }
54
+
55
+ }
56
+ }
57
+ }
58
+
59
+ const Stocks = new StocksClass();
60
+ export {Stocks}
@@ -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}