chyz 1.0.12-rc.14

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 (163) hide show
  1. package/BaseChyz.ts +316 -0
  2. package/Chyz.ts +11 -0
  3. package/Examples/Controllers/ApiController.ts +121 -0
  4. package/Examples/Controllers/PublicController.ts +44 -0
  5. package/Examples/Controllers/SiteController.ts +127 -0
  6. package/Examples/Models/Customer.ts +113 -0
  7. package/Examples/Models/Order.ts +48 -0
  8. package/Examples/Models/OrderItem.ts +26 -0
  9. package/Examples/Models/User.ts +80 -0
  10. package/Examples/index.ts +38 -0
  11. package/Examples/log/access.log +0 -0
  12. package/Examples/log/app.log +3264 -0
  13. package/Examples/log/errors.log +534 -0
  14. package/Examples/package.json +45 -0
  15. package/Examples/tsconfig.json +20 -0
  16. package/Examples/yarn.lock +2202 -0
  17. package/README.md +218 -0
  18. package/base/ActionFilter.ts +71 -0
  19. package/base/BaseError.ts +26 -0
  20. package/base/BaseObject.ts +19 -0
  21. package/base/Behavior.ts +6 -0
  22. package/base/Component.ts +66 -0
  23. package/base/Configurable.ts +10 -0
  24. package/base/Controller.ts +84 -0
  25. package/base/DataErrorDbException.ts +16 -0
  26. package/base/DbConnection.ts +51 -0
  27. package/base/ForbiddenHttpException.ts +15 -0
  28. package/base/InvalidConfigException.ts +16 -0
  29. package/base/Model.ts +254 -0
  30. package/base/NotFoundHttpException.ts +14 -0
  31. package/base/RestClient.ts +27 -0
  32. package/base/UnauthorizedHttpException.ts +16 -0
  33. package/base/ValidationHttpException.ts +14 -0
  34. package/base/db/Exception.ts +14 -0
  35. package/base/index.ts +16 -0
  36. package/decorator/Middleware.ts +9 -0
  37. package/decorator/controller.ts +22 -0
  38. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  39. package/decorator/get.ts +37 -0
  40. package/decorator/index.ts +3 -0
  41. package/decorator/post.ts +36 -0
  42. package/dist/BaseChyz.js +257 -0
  43. package/dist/BaseChyz.js.map +1 -0
  44. package/dist/Chyz.js +15 -0
  45. package/dist/Chyz.js.map +1 -0
  46. package/dist/base/ActionFilter.js +75 -0
  47. package/dist/base/ActionFilter.js.map +1 -0
  48. package/dist/base/BaseError.js +26 -0
  49. package/dist/base/BaseError.js.map +1 -0
  50. package/dist/base/BaseObject.js +20 -0
  51. package/dist/base/BaseObject.js.map +1 -0
  52. package/dist/base/Behavior.js +8 -0
  53. package/dist/base/Behavior.js.map +1 -0
  54. package/dist/base/Component.js +61 -0
  55. package/dist/base/Component.js.map +1 -0
  56. package/dist/base/Configurable.js +9 -0
  57. package/dist/base/Configurable.js.map +1 -0
  58. package/dist/base/Controller.js +75 -0
  59. package/dist/base/Controller.js.map +1 -0
  60. package/dist/base/DataErrorDbException.js +18 -0
  61. package/dist/base/DataErrorDbException.js.map +1 -0
  62. package/dist/base/DbConnection.js +53 -0
  63. package/dist/base/DbConnection.js.map +1 -0
  64. package/dist/base/ForbiddenHttpException.js +17 -0
  65. package/dist/base/ForbiddenHttpException.js.map +1 -0
  66. package/dist/base/InvalidConfigException.js +18 -0
  67. package/dist/base/InvalidConfigException.js.map +1 -0
  68. package/dist/base/Model.js +243 -0
  69. package/dist/base/Model.js.map +1 -0
  70. package/dist/base/NotFoundHttpException.js +18 -0
  71. package/dist/base/NotFoundHttpException.js.map +1 -0
  72. package/dist/base/RestClient.js +26 -0
  73. package/dist/base/RestClient.js.map +1 -0
  74. package/dist/base/UnauthorizedHttpException.js +18 -0
  75. package/dist/base/UnauthorizedHttpException.js.map +1 -0
  76. package/dist/base/ValidationHttpException.js +18 -0
  77. package/dist/base/ValidationHttpException.js.map +1 -0
  78. package/dist/base/db/Exception.js +16 -0
  79. package/dist/base/db/Exception.js.map +1 -0
  80. package/dist/base/index.js +29 -0
  81. package/dist/base/index.js.map +1 -0
  82. package/dist/decorator/Middleware.js +12 -0
  83. package/dist/decorator/Middleware.js.map +1 -0
  84. package/dist/decorator/controller.js +25 -0
  85. package/dist/decorator/controller.js.map +1 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.js +10 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js.map +1 -0
  88. package/dist/decorator/get.js +37 -0
  89. package/dist/decorator/get.js.map +1 -0
  90. package/dist/decorator/index.js +16 -0
  91. package/dist/decorator/index.js.map +1 -0
  92. package/dist/decorator/post.js +37 -0
  93. package/dist/decorator/post.js.map +1 -0
  94. package/dist/filters/AccessControl.js +76 -0
  95. package/dist/filters/AccessControl.js.map +1 -0
  96. package/dist/filters/AccessRule.js +79 -0
  97. package/dist/filters/AccessRule.js.map +1 -0
  98. package/dist/filters/auth/AuthInterface.js +3 -0
  99. package/dist/filters/auth/AuthInterface.js.map +1 -0
  100. package/dist/filters/auth/AuthMethod.js +71 -0
  101. package/dist/filters/auth/AuthMethod.js.map +1 -0
  102. package/dist/filters/auth/HttpBasicAuth.js +8 -0
  103. package/dist/filters/auth/HttpBasicAuth.js.map +1 -0
  104. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  105. package/dist/filters/auth/HttpBearerAuth.js.map +1 -0
  106. package/dist/filters/auth/HttpHeaderAuth.js +61 -0
  107. package/dist/filters/auth/HttpHeaderAuth.js.map +1 -0
  108. package/dist/filters/auth/JwtHttpBearerAuth.js +82 -0
  109. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -0
  110. package/dist/filters/auth/index.js +16 -0
  111. package/dist/filters/auth/index.js.map +1 -0
  112. package/dist/filters/index.js +15 -0
  113. package/dist/filters/index.js.map +1 -0
  114. package/dist/index.js +28 -0
  115. package/dist/index.js.map +1 -0
  116. package/dist/log/config/log4js.json +55 -0
  117. package/dist/model/RouteDefinition.js +9 -0
  118. package/dist/model/RouteDefinition.js.map +1 -0
  119. package/dist/requiments/Glob.js +11 -0
  120. package/dist/requiments/Glob.js.map +1 -0
  121. package/dist/requiments/ReflectUtil.js +25 -0
  122. package/dist/requiments/ReflectUtil.js.map +1 -0
  123. package/dist/requiments/Utils.js +40 -0
  124. package/dist/requiments/Utils.js.map +1 -0
  125. package/dist/validators/BooleanValidator.js +2 -0
  126. package/dist/validators/BooleanValidator.js.map +1 -0
  127. package/dist/validators/CompareValidator.js +2 -0
  128. package/dist/validators/CompareValidator.js.map +1 -0
  129. package/dist/validators/DateValidator.js +2 -0
  130. package/dist/validators/DateValidator.js.map +1 -0
  131. package/dist/validators/EmailValidator.js +2 -0
  132. package/dist/validators/EmailValidator.js.map +1 -0
  133. package/dist/validators/Validator.js +28 -0
  134. package/dist/validators/Validator.js.map +1 -0
  135. package/dist/web/IdentityInterface.js +9 -0
  136. package/dist/web/IdentityInterface.js.map +1 -0
  137. package/dist/web/User.js +83 -0
  138. package/dist/web/User.js.map +1 -0
  139. package/filters/AccessControl.ts +64 -0
  140. package/filters/AccessRule.ts +137 -0
  141. package/filters/auth/AuthInterface.ts +34 -0
  142. package/filters/auth/AuthMethod.ts +88 -0
  143. package/filters/auth/HttpBasicAuth.ts +7 -0
  144. package/filters/auth/HttpBearerAuth.ts +31 -0
  145. package/filters/auth/HttpHeaderAuth.ts +53 -0
  146. package/filters/auth/JwtHttpBearerAuth.ts +81 -0
  147. package/filters/auth/index.ts +3 -0
  148. package/filters/index.ts +2 -0
  149. package/index.ts +14 -0
  150. package/log/config/log4js.json +55 -0
  151. package/model/RouteDefinition.ts +18 -0
  152. package/package.json +52 -0
  153. package/requiments/Glob.ts +9 -0
  154. package/requiments/ReflectUtil.ts +26 -0
  155. package/requiments/Utils.ts +57 -0
  156. package/tsconfig.json +18 -0
  157. package/validators/BooleanValidator.ts +0 -0
  158. package/validators/CompareValidator.ts +0 -0
  159. package/validators/DateValidator.ts +0 -0
  160. package/validators/EmailValidator.ts +0 -0
  161. package/validators/Validator.ts +27 -0
  162. package/web/IdentityInterface.ts +62 -0
  163. package/web/User.ts +96 -0
@@ -0,0 +1,113 @@
1
+ // @ts-ignore
2
+ import {DataTypes, Model} from "../../base";
3
+
4
+ export class Customer 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
+
112
+
113
+
@@ -0,0 +1,48 @@
1
+ import {DataTypes, Model} from "../../base";
2
+
3
+ export class Order extends Model {
4
+ [x: string]: any;
5
+
6
+ public tableName() {
7
+ return 'order';
8
+ }
9
+
10
+ public attributes() {
11
+
12
+ return {
13
+ customer_id:{
14
+ allowNull:false,
15
+ type:DataTypes.INTEGER,
16
+ },
17
+
18
+ crm_order_id:{
19
+ allowNull:false,
20
+ type:DataTypes.INTEGER,
21
+ },
22
+
23
+ total:{
24
+ allowNull:false,
25
+ type:DataTypes.FLOAT,
26
+ },
27
+
28
+ created_date:{
29
+ allowNull:false,
30
+ type:DataTypes.DATE,
31
+ // @ts-ignore
32
+ defaultValue: Model.NOW
33
+ },
34
+ status: {
35
+ type: DataTypes.BOOLEAN,
36
+ allowNull:false,
37
+ validate: {
38
+ isBoolean: true
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ }
45
+
46
+
47
+
48
+
@@ -0,0 +1,26 @@
1
+ import {DataTypes, Model} from "../../Chy-Nodejs-Framework/dist/base";
2
+
3
+ export class OrderItem 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
+
24
+
25
+
26
+
@@ -0,0 +1,80 @@
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
+ const JsonWebToken = require("jsonwebtoken");
12
+ export class User extends Model implements IdentityInterface {
13
+
14
+ [x: string]: any;
15
+
16
+ public tableName() {
17
+ return 'users';
18
+ }
19
+
20
+ findIdentity(id: number) {
21
+ throw new Error("Method not implemented.");
22
+ }
23
+
24
+ getId(): number {
25
+ throw new Error("Method not implemented.");
26
+ }
27
+
28
+ getAuthKey(): string {
29
+ throw new Error("Method not implemented.");
30
+ }
31
+
32
+ validateAuthKey(authKey: string): boolean {
33
+ throw new Error("Method not implemented.");
34
+ }
35
+
36
+ public attributes() {
37
+ return {
38
+ // Model attributes are defined here
39
+ username: {
40
+ type: DataTypes.STRING,
41
+ allowNull: false
42
+ },
43
+ password: {
44
+ type: DataTypes.STRING,
45
+ allowNull: false
46
+ },
47
+ user_role: {
48
+ type: DataTypes.STRING,
49
+ allowNull: false
50
+ },
51
+ salt_text: {
52
+ type: DataTypes.STRING
53
+ // allowNull defaults to true
54
+ }
55
+ }
56
+ }
57
+
58
+ async findIdentityByAccessToken(token, type) {
59
+ let decoded = JsonWebToken.decode(token, {complete: true})
60
+ let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
61
+ if (identity) {
62
+ BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
63
+ try {
64
+ JsonWebToken.verify(token, identity.salt_text);
65
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
66
+ return identity;
67
+ } catch (err) {
68
+ if (err.name == "TokenExpiredError")
69
+ BaseChyz.debug("Find Identity By AccessToken: Token Expired")
70
+ else
71
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
72
+ return null;
73
+ }
74
+ }
75
+ BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
76
+ return null;
77
+ }
78
+ }
79
+
80
+
@@ -0,0 +1,38 @@
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
+ require('dotenv-flow').config();
9
+ 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";
14
+
15
+
16
+ let config = {
17
+ port: 3000,
18
+ controllerpath:"C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
19
+ components: {
20
+ db:{
21
+ class:DbConnection,
22
+ database: process.env.DBDATABASE,
23
+ username:process.env.DBUSER,
24
+ password:process.env.DBPASS,
25
+ options:{
26
+ host: process.env.DBHOST,
27
+ dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
28
+ // disable logging; default: console.log
29
+ logging: false
30
+ }
31
+ },
32
+ user: {
33
+ 'class': User,
34
+ 'identityClass':Identity
35
+ }
36
+ }
37
+ }
38
+ Chyz.app(config).Start();
File without changes