chyz 1.2.1-rc.0 → 1.2.1-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 (200) hide show
  1. package/BaseChyz.ts +454 -0
  2. package/Chyz.ts +11 -0
  3. package/Doc/Moel kullanma.md +13 -0
  4. package/Examples/Controllers/ApiController.ts +140 -0
  5. package/Examples/Controllers/BasicApiController.ts +121 -0
  6. package/Examples/Controllers/KeyCloakController.ts +100 -0
  7. package/Examples/Controllers/PublicController.ts +42 -0
  8. package/Examples/Controllers/SiteController.ts +149 -0
  9. package/Examples/Models/AuthAssignment.ts +50 -0
  10. package/Examples/Models/AuthItem.ts +59 -0
  11. package/Examples/Models/AuthItemChild.ts +49 -0
  12. package/Examples/Models/Categories.ts +51 -0
  13. package/Examples/Models/Customer.ts +115 -0
  14. package/Examples/Models/KeycloakUser.ts +70 -0
  15. package/Examples/Models/Order.ts +64 -0
  16. package/Examples/Models/OrderItem.ts +27 -0
  17. package/Examples/Models/ProductModels.ts +49 -0
  18. package/Examples/Models/ProductToCategories.ts +46 -0
  19. package/Examples/Models/Products.ts +50 -0
  20. package/Examples/Models/Stocks.ts +60 -0
  21. package/Examples/Models/User.ts +128 -0
  22. package/Examples/Models/UserPermission.ts +37 -0
  23. package/Examples/Models/index.ts +19 -0
  24. package/Examples/index-keycloack.ts +78 -0
  25. package/Examples/index.ts +60 -0
  26. package/Examples/keycloak.json +7 -0
  27. package/Examples/log/access.log +0 -0
  28. package/Examples/log/app.log +20601 -0
  29. package/Examples/log/errors.log +2120 -0
  30. package/Examples/package.json +49 -0
  31. package/Examples/tsconfig.json +21 -0
  32. package/README.md +518 -0
  33. package/base/ActionFilter.ts +71 -0
  34. package/base/BaseError.ts +28 -0
  35. package/base/BaseObject.ts +19 -0
  36. package/base/Behavior.ts +6 -0
  37. package/base/CWebController.ts +84 -0
  38. package/base/Component.ts +66 -0
  39. package/base/Configurable.ts +10 -0
  40. package/base/DataErrorDbException.ts +16 -0
  41. package/base/DbConnection.ts +55 -0
  42. package/base/ForbiddenHttpException.ts +15 -0
  43. package/base/InvalidArgumentException.ts +16 -0
  44. package/base/InvalidConfigException.ts +16 -0
  45. package/base/Model.ts +555 -0
  46. package/base/ModelManager.ts +19 -0
  47. package/base/NotFoundHttpException.ts +14 -0
  48. package/base/RestClient.ts +28 -0
  49. package/base/UnauthorizedHttpException.ts +17 -0
  50. package/base/ValidationHttpException.ts +14 -0
  51. package/base/db/Exception.ts +14 -0
  52. package/base/index.ts +18 -0
  53. package/decorator/Middleware.ts +9 -0
  54. package/decorator/controller.ts +22 -0
  55. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  56. package/decorator/get.ts +37 -0
  57. package/decorator/index.ts +3 -0
  58. package/decorator/post.ts +36 -0
  59. package/{BaseChyz.js → dist/BaseChyz.js} +0 -0
  60. package/{BaseChyz.js.map → dist/BaseChyz.js.map} +0 -0
  61. package/{Chyz.js → dist/Chyz.js} +0 -0
  62. package/{Chyz.js.map → dist/Chyz.js.map} +0 -0
  63. package/{base → dist/base}/ActionFilter.js +0 -0
  64. package/{base → dist/base}/ActionFilter.js.map +0 -0
  65. package/{base → dist/base}/BaseError.js +0 -0
  66. package/{base → dist/base}/BaseError.js.map +0 -0
  67. package/{base → dist/base}/BaseObject.js +0 -0
  68. package/{base → dist/base}/BaseObject.js.map +0 -0
  69. package/{base → dist/base}/Behavior.js +0 -0
  70. package/{base → dist/base}/Behavior.js.map +0 -0
  71. package/{base → dist/base}/CWebController.js +0 -0
  72. package/{base → dist/base}/CWebController.js.map +0 -0
  73. package/{base → dist/base}/Component.js +0 -0
  74. package/{base → dist/base}/Component.js.map +0 -0
  75. package/{base → dist/base}/Configurable.js +0 -0
  76. package/{base → dist/base}/Configurable.js.map +0 -0
  77. package/{base → dist/base}/DataErrorDbException.js +0 -0
  78. package/{base → dist/base}/DataErrorDbException.js.map +0 -0
  79. package/{base → dist/base}/DbConnection.js +0 -0
  80. package/{base → dist/base}/DbConnection.js.map +0 -0
  81. package/{base → dist/base}/ForbiddenHttpException.js +0 -0
  82. package/{base → dist/base}/ForbiddenHttpException.js.map +0 -0
  83. package/{base → dist/base}/InvalidArgumentException.js +0 -0
  84. package/{base → dist/base}/InvalidArgumentException.js.map +0 -0
  85. package/{base → dist/base}/InvalidConfigException.js +0 -0
  86. package/{base → dist/base}/InvalidConfigException.js.map +0 -0
  87. package/{base → dist/base}/Model.js +0 -0
  88. package/{base → dist/base}/Model.js.map +0 -0
  89. package/{base → dist/base}/ModelManager.js +0 -0
  90. package/{base → dist/base}/ModelManager.js.map +0 -0
  91. package/{base → dist/base}/NotFoundHttpException.js +0 -0
  92. package/{base → dist/base}/NotFoundHttpException.js.map +0 -0
  93. package/{base → dist/base}/RestClient.js +0 -0
  94. package/{base → dist/base}/RestClient.js.map +0 -0
  95. package/{base → dist/base}/UnauthorizedHttpException.js +0 -0
  96. package/{base → dist/base}/UnauthorizedHttpException.js.map +0 -0
  97. package/{base → dist/base}/ValidationHttpException.js +0 -0
  98. package/{base → dist/base}/ValidationHttpException.js.map +0 -0
  99. package/{base → dist/base}/db/Exception.js +0 -0
  100. package/{base → dist/base}/db/Exception.js.map +0 -0
  101. package/{base → dist/base}/index.js +0 -0
  102. package/{base → dist/base}/index.js.map +0 -0
  103. package/{decorator → dist/decorator}/Middleware.js +0 -0
  104. package/{decorator → dist/decorator}/Middleware.js.map +0 -0
  105. package/{decorator → dist/decorator}/controller.js +0 -0
  106. package/{decorator → dist/decorator}/controller.js.map +0 -0
  107. package/{decorator → dist/decorator}/enums/ControllerDecoratorParams.js +0 -0
  108. package/{decorator → dist/decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  109. package/{decorator → dist/decorator}/get.js +0 -0
  110. package/{decorator → dist/decorator}/get.js.map +0 -0
  111. package/{decorator → dist/decorator}/index.js +0 -0
  112. package/{decorator → dist/decorator}/index.js.map +0 -0
  113. package/{decorator → dist/decorator}/post.js +0 -0
  114. package/{decorator → dist/decorator}/post.js.map +0 -0
  115. package/{filters → dist/filters}/AccessControl.js +0 -0
  116. package/{filters → dist/filters}/AccessControl.js.map +0 -0
  117. package/{filters → dist/filters}/AccessRule.js +0 -0
  118. package/{filters → dist/filters}/AccessRule.js.map +0 -0
  119. package/{filters → dist/filters}/auth/AuthInterface.js +0 -0
  120. package/{filters → dist/filters}/auth/AuthInterface.js.map +0 -0
  121. package/{filters → dist/filters}/auth/AuthMethod.js +0 -0
  122. package/{filters → dist/filters}/auth/AuthMethod.js.map +0 -0
  123. package/{filters → dist/filters}/auth/HttpBasicAuth.js +0 -0
  124. package/{filters → dist/filters}/auth/HttpBasicAuth.js.map +0 -0
  125. package/{filters → dist/filters}/auth/HttpBearerAuth.js +0 -0
  126. package/{filters → dist/filters}/auth/HttpBearerAuth.js.map +0 -0
  127. package/{filters → dist/filters}/auth/HttpHeaderAuth.js +0 -0
  128. package/{filters → dist/filters}/auth/HttpHeaderAuth.js.map +0 -0
  129. package/{filters → dist/filters}/auth/JwtHttpBearerAuth.js +0 -0
  130. package/{filters → dist/filters}/auth/JwtHttpBearerAuth.js.map +0 -0
  131. package/{filters → dist/filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  132. package/{filters → dist/filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  133. package/{filters → dist/filters}/auth/index.js +0 -0
  134. package/{filters → dist/filters}/auth/index.js.map +0 -0
  135. package/{filters → dist/filters}/index.js +0 -0
  136. package/{filters → dist/filters}/index.js.map +0 -0
  137. package/{index.js → dist/index.js} +0 -3
  138. package/{index.js.map → dist/index.js.map} +1 -1
  139. package/dist/log/config/log4js.json +55 -0
  140. package/{model → dist/model}/RouteDefinition.js +0 -0
  141. package/{model → dist/model}/RouteDefinition.js.map +0 -0
  142. package/dist/package.json +59 -0
  143. package/{rbac → dist/rbac}/AuthAssignment.js +0 -0
  144. package/{rbac → dist/rbac}/AuthAssignment.js.map +0 -0
  145. package/{rbac → dist/rbac}/AuthItem.js +0 -0
  146. package/{rbac → dist/rbac}/AuthItem.js.map +0 -0
  147. package/{rbac → dist/rbac}/AuthItemChild.js +0 -0
  148. package/{rbac → dist/rbac}/AuthItemChild.js.map +0 -0
  149. package/{rbac → dist/rbac}/AuthManager.js +0 -0
  150. package/{rbac → dist/rbac}/AuthManager.js.map +0 -0
  151. package/{requiments → dist/requiments}/Glob.js +0 -0
  152. package/{requiments → dist/requiments}/Glob.js.map +0 -0
  153. package/{requiments → dist/requiments}/ReflectUtil.js +0 -0
  154. package/{requiments → dist/requiments}/ReflectUtil.js.map +0 -0
  155. package/{requiments → dist/requiments}/Utils.js +0 -0
  156. package/{requiments → dist/requiments}/Utils.js.map +0 -0
  157. package/{validators → dist/validators}/BooleanValidator.js +0 -0
  158. package/{validators → dist/validators}/BooleanValidator.js.map +0 -0
  159. package/{validators → dist/validators}/CompareValidator.js +0 -0
  160. package/{validators → dist/validators}/CompareValidator.js.map +0 -0
  161. package/{validators → dist/validators}/DateValidator.js +0 -0
  162. package/{validators → dist/validators}/DateValidator.js.map +0 -0
  163. package/{validators → dist/validators}/EmailValidator.js +0 -0
  164. package/{validators → dist/validators}/EmailValidator.js.map +0 -0
  165. package/{validators → dist/validators}/Validator.js +0 -0
  166. package/{validators → dist/validators}/Validator.js.map +0 -0
  167. package/{web → dist/web}/IdentityInterface.js +0 -0
  168. package/{web → dist/web}/IdentityInterface.js.map +0 -0
  169. package/{web → dist/web}/WebUser.js +0 -0
  170. package/{web → dist/web}/WebUser.js.map +0 -0
  171. package/filters/AccessControl.ts +77 -0
  172. package/filters/AccessRule.ts +182 -0
  173. package/filters/auth/AuthInterface.ts +34 -0
  174. package/filters/auth/AuthMethod.ts +88 -0
  175. package/filters/auth/HttpBasicAuth.ts +75 -0
  176. package/filters/auth/HttpBearerAuth.ts +31 -0
  177. package/filters/auth/HttpHeaderAuth.ts +53 -0
  178. package/filters/auth/JwtHttpBearerAuth.ts +80 -0
  179. package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
  180. package/filters/auth/index.ts +4 -0
  181. package/filters/index.ts +2 -0
  182. package/index.ts +16 -0
  183. package/model/RouteDefinition.ts +18 -0
  184. package/package-lock.json +5259 -0
  185. package/package.json +1 -1
  186. package/rbac/AuthAssignment.ts +50 -0
  187. package/rbac/AuthItem.ts +57 -0
  188. package/rbac/AuthItemChild.ts +50 -0
  189. package/rbac/AuthManager.ts +398 -0
  190. package/requiments/Glob.ts +9 -0
  191. package/requiments/ReflectUtil.ts +26 -0
  192. package/requiments/Utils.ts +63 -0
  193. package/tsconfig.json +18 -0
  194. package/validators/BooleanValidator.ts +0 -0
  195. package/validators/CompareValidator.ts +0 -0
  196. package/validators/DateValidator.ts +0 -0
  197. package/validators/EmailValidator.ts +0 -0
  198. package/validators/Validator.ts +27 -0
  199. package/web/IdentityInterface.ts +68 -0
  200. package/web/WebUser.ts +187 -0
@@ -0,0 +1,22 @@
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
+ // @ts-ignore
9
+ import "reflect-metadata";
10
+ export const controller = (prefix: string = ''): ClassDecorator => {
11
+ return (target: any) => {
12
+ // @ts-ignore
13
+ Reflect.defineMetadata('prefix', prefix, target);
14
+
15
+ // Since routes are set by our methods this should almost never be true (except the controller has no methods)
16
+ // @ts-ignore
17
+ if (! Reflect.hasMetadata('routes', target)) {
18
+ // @ts-ignore
19
+ Reflect.defineMetadata('routes', [], target);
20
+ }
21
+ };
22
+ };
@@ -0,0 +1,5 @@
1
+ export enum ControllerDecoratorParams {
2
+ Path = 'path',
3
+ Method = 'method',
4
+ Middleware = 'middleware'
5
+ }
@@ -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
+ import "reflect-metadata";
9
+ import {RouteDefinition} from '../model/RouteDefinition';
10
+
11
+ export const get = (path: string): MethodDecorator => {
12
+ // `target` equals our class, `propertyKey` equals our decorated method name
13
+ // @ts-ignore
14
+ return (target, propertyKey: string): void => {
15
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
16
+ // To prevent any further validation simply set it to an empty array here.
17
+ // @ts-ignore
18
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
19
+ // @ts-ignore
20
+ Reflect.defineMetadata('routes', [], target.constructor);
21
+ }
22
+
23
+ // Get the routes stored so far, extend it by the new route and re-set the metadata.
24
+ // @ts-ignore
25
+ const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
26
+
27
+ routes.push({
28
+ id:"",
29
+ requestMethod: 'get',
30
+ path,
31
+ methodName: propertyKey
32
+ });
33
+
34
+ // @ts-ignore
35
+ Reflect.defineMetadata('routes', routes, target.constructor);
36
+ };
37
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./controller"
2
+ export * from "./get"
3
+ export * from "./post"
@@ -0,0 +1,36 @@
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
+ import "reflect-metadata";
9
+ import {RouteDefinition} from '../model/RouteDefinition';
10
+
11
+ export const post = (path: string): MethodDecorator => {
12
+ // `target` equals our class, `propertyKey` equals our decorated method name
13
+ // @ts-ignore
14
+ return (target, propertyKey: string): void => {
15
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
16
+ // To prevent any further validation simply set it to an empty array here.
17
+ // @ts-ignore
18
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
19
+ // @ts-ignore
20
+ Reflect.defineMetadata('routes', [], target.constructor);
21
+ }
22
+
23
+ // Get the routes stored so far, extend it by the new route and re-set the metadata.
24
+ // @ts-ignore
25
+ const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
26
+
27
+ routes.push({
28
+ id:"",
29
+ requestMethod: 'post',
30
+ path,
31
+ methodName: propertyKey
32
+ });
33
+ // @ts-ignore
34
+ Reflect.defineMetadata('routes', routes, target.constructor);
35
+ };
36
+ };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -23,9 +23,6 @@ var WebUser_1 = require("./web/WebUser");
23
23
  Object.defineProperty(exports, "WebUser", { enumerable: true, get: function () { return WebUser_1.WebUser; } });
24
24
  const BaseChyz_1 = __importDefault(require("./BaseChyz"));
25
25
  exports.BaseChyz = BaseChyz_1.default;
26
- /**
27
- *
28
- */
29
26
  const Chyz = new BaseChyz_1.default();
30
27
  exports.default = Chyz;
31
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,yCAAuB;AACvB,4CAA0B;AAC1B,iDAA+B;AAC/B,8CAA4B;AAC5B,qDAAmC;AAEnC,yCAAsC;AAA9B,kGAAA,OAAO,OAAA;AAEf,0DAAkC;AAC1B,mBADD,kBAAQ,CACC;AAChB;;GAEG;AACH,MAAM,IAAI,GAAG,IAAI,kBAAQ,EAAE,CAAC;AAC5B,kBAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,yCAAuB;AACvB,4CAA0B;AAC1B,iDAA+B;AAC/B,8CAA4B;AAC5B,qDAAmC;AAEnC,yCAAsC;AAA9B,kGAAA,OAAO,OAAA;AAEf,0DAAkC;AAC1B,mBADD,kBAAQ,CACC;AAEhB,MAAM,IAAI,GAAG,IAAI,kBAAQ,EAAE,CAAC;AAC5B,kBAAe,IAAI,CAAC"}
@@ -0,0 +1,55 @@
1
+ {
2
+ "appenders": {
3
+ "access": {
4
+ "type": "dateFile",
5
+ "filename": "log/access.log",
6
+ "pattern": "-yyyy-MM-dd",
7
+ "category": "http",
8
+ "layout": {
9
+ "type": "pattern",
10
+ "pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
11
+ }
12
+ },
13
+ "app": {
14
+ "type": "file",
15
+ "filename": "log/app.log",
16
+ "maxLogSize": 10485760,
17
+ "numBackups": 3,
18
+ "layout": {
19
+ "type": "pattern",
20
+ "pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
21
+ }
22
+ },
23
+ "errorFile": {
24
+ "type": "file",
25
+ "filename": "log/errors.log",
26
+ "layout": {
27
+ "type": "pattern",
28
+ "pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
29
+ }
30
+ },
31
+ "errors": {
32
+ "type": "logLevelFilter",
33
+ "level": "ERROR",
34
+ "appender": "errorFile",
35
+ "layout": {
36
+ "type": "pattern",
37
+ "pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
38
+ }
39
+ },
40
+ "console": {
41
+ "type": "stdout"
42
+ }
43
+ },
44
+ "categories": {
45
+ "default": {
46
+ "appenders": ["console","app" ,"errors" ],
47
+ "level": "ALL",
48
+ "enableCallStack": true
49
+ },
50
+ "http": {
51
+ "level": "INFO",
52
+ "appenders": [ "access" ]
53
+ }
54
+ }
55
+ }
File without changes
File without changes
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "chyz",
3
+ "version": "1.1.1-rc.2",
4
+ "description": "Nodejs Micro service Framework",
5
+ "scripts": {
6
+ "dev": "nodemon -t --trace-warnings index.ts",
7
+ "debug": "ts-node index.ts",
8
+ "build": "rmdir /S /Q .\\dist && npx tsc && xcopy .\\log .\\dist\\log /e /i /h /Y && copy .\\package.json .\\dist\\package.json",
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "postversion": "git push && git push --tags"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/cihan53/Chy-Nodejs-Framework.git"
15
+ },
16
+ "author": "Cihan Ozturk",
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/cihan53/Chy-Nodejs-Framework/issues"
20
+ },
21
+ "homepage": "https://github.com/cihan53/Chy-Nodejs-Framework#readme",
22
+ "dependencies": {
23
+ "axios": "^0.23.0",
24
+ "babel-plugin-transform-decorators-legacy": "^1.3.5",
25
+ "body-parser": "^1.19.0",
26
+ "dotenv-flow": "^3.2.0",
27
+ "express": "^4.17.1",
28
+ "express-session": "^1.17.2",
29
+ "glob": "^7.1.7",
30
+ "ip": "^1.1.5",
31
+ "jsonwebtoken": "^8.5.1",
32
+ "lodash": "^4.17.21",
33
+ "log4js": "^6.3.0",
34
+ "method-override": "^3.0.0",
35
+ "passport": "^0.4.1",
36
+ "pg": "^8.7.1",
37
+ "pg-hstore": "^2.3.4",
38
+ "reflect-metadata": "^0.1.13",
39
+ "sequelize": "^6.6.5",
40
+ "sequelize-transparent-cache": "^2.3.0",
41
+ "validate.js": "^0.13.1"
42
+ },
43
+ "devDependencies": {
44
+ "@types/express": "^4.17.13",
45
+ "@types/node": "^16.6.1",
46
+ "@types/validator": "^13.6.3",
47
+ "nodemon": "^2.0.12",
48
+ "ts-node": "^10.2.0",
49
+ "typescript": "^4.3.5"
50
+ },
51
+ "keywords": [
52
+ "Framework",
53
+ "RespAPI",
54
+ "microservice",
55
+ "micro service",
56
+ "easy configuration",
57
+ "Rbac support"
58
+ ]
59
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,77 @@
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 BaseChyz from "../BaseChyz";
8
+ import {ForbiddenHttpException} from "../base/ForbiddenHttpException";
9
+ import {ActionFilter} from "../base/ActionFilter";
10
+ import {AccessRule} from "./AccessRule";
11
+ import {WebUser} from "../web/WebUser";
12
+ import Utils from "../requiments/Utils";
13
+ import {NextFunction, Request, Response} from "express";
14
+
15
+ var _ = require('lodash');
16
+
17
+
18
+ export class AccessControl extends ActionFilter {
19
+
20
+ public user: any = null;
21
+ public rules: any;
22
+ public denyCallback: any = null;
23
+
24
+ public init() {
25
+ super.init()
26
+
27
+ if (this.user == undefined) {
28
+ this.user = Utils.cloneDeep(BaseChyz.getComponent("user")) ?? new WebUser();
29
+ }
30
+
31
+ this.rules.forEach((rule: any, index: number) => {
32
+ if (rule === Object(rule)) {
33
+ this.rules[index] = Utils.createObject(new AccessRule(), rule);
34
+ }
35
+ })
36
+ }
37
+
38
+
39
+ public async beforeAction(action: any, request: Request) {
40
+ let allow;
41
+ // @ts-ignore
42
+ let user = request.user ?? this.user;
43
+ // @ts-ignore
44
+ user.identity = request.identity ?? null;
45
+
46
+ for (const rulesKey in this.rules) {
47
+
48
+ let rule = this.rules[rulesKey];
49
+ if ((allow = await rule.allows(action, user, request))) {
50
+ return true;
51
+ } else if (allow === false) {
52
+ if (this.denyCallback != null) {
53
+ rule.denyCallback.apply(rule, action);
54
+ } else {
55
+ this.denyAccess(user);
56
+ }
57
+ return false;
58
+ }
59
+ }
60
+
61
+
62
+ if (this.denyCallback != null) {
63
+ this.denyCallback.apply(null, action);
64
+ } else {
65
+ this.denyAccess(user);
66
+ }
67
+
68
+ return false;
69
+ }
70
+
71
+ public denyAccess(user: WebUser) {
72
+ if (user != undefined && user.getIsGuest()) {
73
+ user.loginRequired();
74
+ } else throw new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'));
75
+ }
76
+
77
+ }