chyz 1.2.1-rc.2 → 1.2.4-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 (201) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +0 -0
  2. package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/{dist/base → base}/ActionFilter.js +0 -0
  6. package/{dist/base → base}/ActionFilter.js.map +0 -0
  7. package/{dist/base → base}/BaseError.js +0 -0
  8. package/{dist/base → base}/BaseError.js.map +0 -0
  9. package/{dist/base → base}/BaseObject.js +0 -0
  10. package/{dist/base → base}/BaseObject.js.map +0 -0
  11. package/{dist/base → base}/Behavior.js +0 -0
  12. package/{dist/base → base}/Behavior.js.map +0 -0
  13. package/{dist/base → base}/CWebController.js +0 -0
  14. package/{dist/base → base}/CWebController.js.map +0 -0
  15. package/{dist/base → base}/Component.js +0 -0
  16. package/{dist/base → base}/Component.js.map +0 -0
  17. package/{dist/base → base}/Configurable.js +0 -0
  18. package/{dist/base → base}/Configurable.js.map +0 -0
  19. package/{dist/base → base}/DataErrorDbException.js +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js.map +0 -0
  21. package/{dist/base → base}/DbConnection.js +0 -0
  22. package/{dist/base → base}/DbConnection.js.map +0 -0
  23. package/{dist/base → base}/ForbiddenHttpException.js +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
  25. package/{dist/base → base}/InvalidArgumentException.js +0 -0
  26. package/{dist/base → base}/InvalidArgumentException.js.map +0 -0
  27. package/{dist/base → base}/InvalidConfigException.js +0 -0
  28. package/{dist/base → base}/InvalidConfigException.js.map +0 -0
  29. package/{dist/base → base}/Model.js +0 -0
  30. package/{dist/base → base}/Model.js.map +0 -0
  31. package/{dist/base → base}/ModelManager.js +0 -0
  32. package/{dist/base → base}/ModelManager.js.map +0 -0
  33. package/{dist/base → base}/NotFoundHttpException.js +0 -0
  34. package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
  35. package/{dist/base → base}/RestClient.js +0 -0
  36. package/{dist/base → base}/RestClient.js.map +0 -0
  37. package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
  38. package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
  39. package/{dist/base → base}/ValidationHttpException.js +0 -0
  40. package/{dist/base → base}/ValidationHttpException.js.map +0 -0
  41. package/{dist/base → base}/db/Exception.js +0 -0
  42. package/{dist/base → base}/db/Exception.js.map +0 -0
  43. package/{dist/base → base}/index.js +0 -0
  44. package/{dist/base → base}/index.js.map +0 -0
  45. package/{dist/decorator → decorator}/Middleware.js +0 -0
  46. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  47. package/{dist/decorator → decorator}/controller.js +0 -0
  48. package/{dist/decorator → decorator}/controller.js.map +0 -0
  49. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  50. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  51. package/{dist/decorator → decorator}/get.js +0 -0
  52. package/{dist/decorator → decorator}/get.js.map +0 -0
  53. package/{dist/decorator → decorator}/index.js +0 -0
  54. package/{dist/decorator → decorator}/index.js.map +0 -0
  55. package/{dist/decorator → decorator}/post.js +0 -0
  56. package/{dist/decorator → decorator}/post.js.map +0 -0
  57. package/{dist/filters → filters}/AccessControl.js +0 -1
  58. package/filters/AccessControl.js.map +1 -0
  59. package/{dist/filters → filters}/AccessRule.js +0 -0
  60. package/{dist/filters → filters}/AccessRule.js.map +0 -0
  61. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  62. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  63. package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
  64. package/{dist/filters → filters}/auth/AuthMethod.js.map +1 -1
  65. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  66. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  67. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  68. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  69. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  70. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
  71. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +2 -3
  72. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +1 -1
  73. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  74. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  75. package/{dist/filters → filters}/auth/index.js +0 -0
  76. package/{dist/filters → filters}/auth/index.js.map +0 -0
  77. package/{dist/filters → filters}/index.js +0 -0
  78. package/{dist/filters → filters}/index.js.map +0 -0
  79. package/{dist/index.js → index.js} +3 -0
  80. package/{dist/index.js.map → index.js.map} +1 -1
  81. package/log/config/log4js.json +1 -1
  82. package/{dist/model → model}/RouteDefinition.js +0 -0
  83. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  84. package/package.json +2 -2
  85. package/{dist/rbac → rbac}/AuthAssignment.js +0 -0
  86. package/{dist/rbac → rbac}/AuthAssignment.js.map +0 -0
  87. package/{dist/rbac → rbac}/AuthItem.js +0 -0
  88. package/{dist/rbac → rbac}/AuthItem.js.map +0 -0
  89. package/{dist/rbac → rbac}/AuthItemChild.js +0 -0
  90. package/{dist/rbac → rbac}/AuthItemChild.js.map +0 -0
  91. package/{dist/rbac → rbac}/AuthManager.js +0 -0
  92. package/{dist/rbac → rbac}/AuthManager.js.map +0 -0
  93. package/{dist/requiments → requiments}/Glob.js +0 -0
  94. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  95. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  96. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  97. package/{dist/requiments → requiments}/Utils.js +0 -0
  98. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  99. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  100. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  101. package/{dist/validators → validators}/CompareValidator.js +0 -0
  102. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  103. package/{dist/validators → validators}/DateValidator.js +0 -0
  104. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  105. package/{dist/validators → validators}/EmailValidator.js +0 -0
  106. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  107. package/{dist/validators → validators}/Validator.js +0 -0
  108. package/{dist/validators → validators}/Validator.js.map +0 -0
  109. package/{dist/web → web}/IdentityInterface.js +0 -0
  110. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  111. package/{dist/web → web}/WebUser.js +0 -0
  112. package/{dist/web → web}/WebUser.js.map +0 -0
  113. package/BaseChyz.ts +0 -454
  114. package/Chyz.ts +0 -11
  115. package/Doc/Moel kullanma.md +0 -13
  116. package/Examples/Controllers/ApiController.ts +0 -140
  117. package/Examples/Controllers/BasicApiController.ts +0 -121
  118. package/Examples/Controllers/KeyCloakController.ts +0 -100
  119. package/Examples/Controllers/PublicController.ts +0 -42
  120. package/Examples/Controllers/SiteController.ts +0 -149
  121. package/Examples/Models/AuthAssignment.ts +0 -50
  122. package/Examples/Models/AuthItem.ts +0 -59
  123. package/Examples/Models/AuthItemChild.ts +0 -49
  124. package/Examples/Models/Categories.ts +0 -51
  125. package/Examples/Models/Customer.ts +0 -115
  126. package/Examples/Models/KeycloakUser.ts +0 -70
  127. package/Examples/Models/Order.ts +0 -64
  128. package/Examples/Models/OrderItem.ts +0 -27
  129. package/Examples/Models/ProductModels.ts +0 -49
  130. package/Examples/Models/ProductToCategories.ts +0 -46
  131. package/Examples/Models/Products.ts +0 -50
  132. package/Examples/Models/Stocks.ts +0 -60
  133. package/Examples/Models/User.ts +0 -128
  134. package/Examples/Models/UserPermission.ts +0 -37
  135. package/Examples/Models/index.ts +0 -19
  136. package/Examples/index-keycloack.ts +0 -78
  137. package/Examples/index.ts +0 -60
  138. package/Examples/keycloak.json +0 -7
  139. package/Examples/log/access.log +0 -0
  140. package/Examples/log/app.log +0 -20601
  141. package/Examples/log/errors.log +0 -2120
  142. package/Examples/package.json +0 -49
  143. package/Examples/tsconfig.json +0 -21
  144. package/base/ActionFilter.ts +0 -71
  145. package/base/BaseError.ts +0 -28
  146. package/base/BaseObject.ts +0 -19
  147. package/base/Behavior.ts +0 -6
  148. package/base/CWebController.ts +0 -84
  149. package/base/Component.ts +0 -66
  150. package/base/Configurable.ts +0 -10
  151. package/base/DataErrorDbException.ts +0 -16
  152. package/base/DbConnection.ts +0 -55
  153. package/base/ForbiddenHttpException.ts +0 -15
  154. package/base/InvalidArgumentException.ts +0 -16
  155. package/base/InvalidConfigException.ts +0 -16
  156. package/base/Model.ts +0 -555
  157. package/base/ModelManager.ts +0 -19
  158. package/base/NotFoundHttpException.ts +0 -14
  159. package/base/RestClient.ts +0 -28
  160. package/base/UnauthorizedHttpException.ts +0 -17
  161. package/base/ValidationHttpException.ts +0 -14
  162. package/base/db/Exception.ts +0 -14
  163. package/base/index.ts +0 -18
  164. package/decorator/Middleware.ts +0 -9
  165. package/decorator/controller.ts +0 -22
  166. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  167. package/decorator/get.ts +0 -37
  168. package/decorator/index.ts +0 -3
  169. package/decorator/post.ts +0 -36
  170. package/dist/filters/AccessControl.js.map +0 -1
  171. package/dist/log/config/log4js.json +0 -55
  172. package/dist/package.json +0 -59
  173. package/filters/AccessControl.ts +0 -77
  174. package/filters/AccessRule.ts +0 -182
  175. package/filters/auth/AuthInterface.ts +0 -34
  176. package/filters/auth/AuthMethod.ts +0 -88
  177. package/filters/auth/HttpBasicAuth.ts +0 -75
  178. package/filters/auth/HttpBearerAuth.ts +0 -31
  179. package/filters/auth/HttpHeaderAuth.ts +0 -53
  180. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  181. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  182. package/filters/auth/index.ts +0 -4
  183. package/filters/index.ts +0 -2
  184. package/index.ts +0 -16
  185. package/model/RouteDefinition.ts +0 -18
  186. package/package-lock.json +0 -5259
  187. package/rbac/AuthAssignment.ts +0 -50
  188. package/rbac/AuthItem.ts +0 -57
  189. package/rbac/AuthItemChild.ts +0 -50
  190. package/rbac/AuthManager.ts +0 -398
  191. package/requiments/Glob.ts +0 -9
  192. package/requiments/ReflectUtil.ts +0 -26
  193. package/requiments/Utils.ts +0 -63
  194. package/tsconfig.json +0 -18
  195. package/validators/BooleanValidator.ts +0 -0
  196. package/validators/CompareValidator.ts +0 -0
  197. package/validators/DateValidator.ts +0 -0
  198. package/validators/EmailValidator.ts +0 -0
  199. package/validators/Validator.ts +0 -27
  200. package/web/IdentityInterface.ts +0 -68
  201. package/web/WebUser.ts +0 -187
@@ -1,22 +0,0 @@
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
- };
@@ -1,5 +0,0 @@
1
- export enum ControllerDecoratorParams {
2
- Path = 'path',
3
- Method = 'method',
4
- Middleware = 'middleware'
5
- }
package/decorator/get.ts DELETED
@@ -1,37 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- export * from "./controller"
2
- export * from "./get"
3
- export * from "./post"
package/decorator/post.ts DELETED
@@ -1,36 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccessControl.js","sourceRoot":"","sources":["../../filters/AccessControl.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,2DAAmC;AACnC,2EAAsE;AACtE,uDAAkD;AAClD,6CAAwC;AACxC,4CAAuC;AACvC,gEAAwC;AAGxC,IAAI,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAG1B,MAAa,aAAc,SAAQ,2BAAY;IAA/C;;QAEW,SAAI,GAAQ,IAAI,CAAC;QAEjB,iBAAY,GAAQ,IAAI,CAAC;IAuDpC,CAAC;IArDU,IAAI;;QACP,KAAK,CAAC,IAAI,EAAE,CAAA;QAEZ,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE;YACxB,IAAI,CAAC,IAAI,GAAG,MAAA,eAAK,CAAC,SAAS,CAAC,kBAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,mCAAI,IAAI,iBAAO,EAAE,CAAC;SAC/E;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,KAAa,EAAE,EAAE;YAC5C,IAAI,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;gBACvB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,eAAK,CAAC,YAAY,CAAC,IAAI,uBAAU,EAAE,EAAE,IAAI,CAAC,CAAC;aAClE;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAGY,YAAY,CAAC,MAAW,EAAE,OAAgB;;;YACnD,IAAI,KAAK,CAAC;YACV,aAAa;YACb,IAAI,IAAI,GAAG,MAAA,OAAO,CAAC,IAAI,mCAAI,IAAI,CAAC,IAAI,CAAC;YACrC,aAAa;YACb,IAAI,CAAC,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAI,CAAC;YAEzC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,KAAK,EAAE;gBAE/B,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAChC,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE;oBACpD,OAAO,IAAI,CAAC;iBACf;qBAAM,IAAI,KAAK,KAAK,KAAK,EAAE;oBACxB,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;wBAC3B,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;qBACzC;yBAAM;wBACH,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;qBACzB;oBACD,OAAO,KAAK,CAAC;iBAChB;aACJ;YAGD,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;gBAC3B,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aACzC;iBAAM;gBACH,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;aACzB;YAED,OAAO,KAAK,CAAC;;KAChB;IAEM,UAAU,CAAC,IAAa;QAC3B,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE;YACxC,IAAI,CAAC,aAAa,EAAE,CAAC;SACxB;;YAAM,MAAM,IAAI,+CAAsB,CAAC,kBAAQ,CAAC,CAAC,CAAC,6CAA6C,CAAC,CAAC,CAAC;IACvG,CAAC;CAEJ;AA3DD,sCA2DC"}
@@ -1,55 +0,0 @@
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
- }
package/dist/package.json DELETED
@@ -1,59 +0,0 @@
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
- }
@@ -1,77 +0,0 @@
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
- }
@@ -1,182 +0,0 @@
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 {WebUser} from "../web/WebUser";
8
-
9
- var _ = require('lodash');
10
- import {Component} from "../base/Component";
11
- import {InvalidConfigException} from "../base/InvalidConfigException";
12
- import {Request, Response} from "express";
13
- import Utils from "../requiments/Utils";
14
-
15
- export class AccessRule extends Component {
16
-
17
- /**
18
- * @var bool whether this is an 'allow' rule or 'deny' rule.
19
- */
20
- public allow: any;
21
- /**
22
- * @var array list of action IDs that this rule applies to. The comparison is case-sensitive.
23
- * If not set or empty, it means this rule applies to all actions.
24
- */
25
- public actions: any;
26
-
27
- /**
28
- * @var array list of the controller IDs that this rule applies to.
29
- */
30
- public controllers: any;
31
-
32
- /**
33
- * - `?`: matches a guest user (not authenticated yet)
34
- * - `@`: matches an authenticated user
35
- */
36
-
37
- public roles: any;
38
-
39
- /**
40
- * @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
41
- */
42
- public permissions: any;
43
-
44
- /**
45
- * @var array|Closure parameters to pass to the [[User::can()]] function for evaluating
46
- * user permissions in [[$roles]].
47
- *
48
- * If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
49
- * ID from the current request, you may use the following:
50
- *
51
- * ```php
52
- * ['postId' => Yii::$app->request->get('id')]
53
- * ```
54
- *
55
- * You may also specify a closure that returns an array. This can be used to
56
- * evaluate the array values only if they are needed, for example when a model needs to be
57
- * loaded like in the following code:
58
- *
59
- * ```php
60
- * 'rules' => [
61
- * [
62
- * 'allow' => true,
63
- * 'actions' => ['update'],
64
- * 'roles' => ['updatePost'],
65
- * 'roleParams' => function($rule) {
66
- * return ['post' => Post::findOne(Yii::$app->request->get('id'))];
67
- * },
68
- * ],
69
- * ],
70
- * ```
71
- *
72
- * A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
73
- *
74
- * @see roles
75
- * @since 2.0.12
76
- */
77
- public roleParams: any = [];
78
-
79
-
80
- /**
81
- * @var array list of user IP addresses that this rule applies to. An IP address
82
- * can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
83
- * For example, '192.168.*' matches all IP addresses in the segment '192.168.'.
84
- * It may also contain a pattern/mask like '172.16.0.0/12' which would match all IPs from the
85
- * 20-bit private network block in RFC1918.
86
- * If not set or empty, it means this rule applies to all IP addresses.
87
- */
88
- public ips: any;
89
-
90
-
91
- public async allows(action: any, user: WebUser, request: Request) {
92
- if (
93
- this.matchAction(action)
94
- && await this.matchRole(user)
95
- ) {
96
- return this.allow
97
- }
98
- // if (this.matchAction($action)
99
- // && this.matchRole($user)
100
- // && this.matchIP($request->getUserIP())
101
- // && this.matchVerb($request->getMethod())
102
- // && this.matchController($action->controller)
103
- // && this.matchCustom($action)
104
- // ) {
105
- // return $this->allow ? true : false;
106
- // }
107
-
108
- return null;
109
- }
110
-
111
- /**
112
- * @param Action $action the action
113
- * @return bool whether the rule applies to the action
114
- */
115
- protected matchAction(action: any) {
116
- return _.isEmpty(this.actions) || this.actions.includes(action.id);
117
- }
118
-
119
- /**
120
- * @param Controller $controller the controller
121
- * @return bool whether the rule applies to the controller
122
- */
123
- protected matchController(controller: any) {
124
- // if (empty($this->controllers)) {
125
- // return true;
126
- // }
127
- //
128
- // $id = $controller->getUniqueId();
129
- // foreach ($this->controllers as $pattern) {
130
- // if (StringHelper::matchWildcard($pattern, $id)) {
131
- // return true;
132
- // }
133
- // }
134
-
135
- return false;
136
- }
137
-
138
- protected async matchRole(user: WebUser) {
139
- let items = Utils.isEmpty(this.roles) ? [] : this.roles;
140
-
141
- if (!Utils.isEmpty(this.permissions)) {
142
- items = Utils.merge(items, this.permissions);
143
- }
144
-
145
- if (Utils.isEmpty(items)) {
146
- return true;
147
- }
148
-
149
-
150
- if (!user) {
151
- throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
152
- }
153
-
154
- let roleParams: any = [];
155
- for (const itemsKey in items) {
156
- let item = items[itemsKey];
157
- if (item === '?') {
158
- if (user.getIsGuest()) {
159
- return true;
160
- }
161
- } else if (item === '@') {
162
- if (!user.getIsGuest()) {
163
- return true;
164
- }
165
- } else {
166
- //roleparams
167
- if (!Utils.isEmpty(this.roleParams)) {
168
- roleParams = !Utils.isArray(this.roleParams) ? this.roleParams.apply(this) : this.roleParams;
169
- }
170
-
171
- if (await user.can(item, this.roleParams)) {
172
- return true;
173
- }
174
- }
175
- }
176
-
177
-
178
- return false;
179
- }
180
-
181
-
182
- }
@@ -1,34 +0,0 @@
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 {Request, Response} from "express";
8
-
9
- export interface AuthInterface{
10
- /**
11
- * Authenticates the current user.
12
- * @param User $user
13
- * @param Request $request
14
- * @param Response $response
15
- * @return IdentityInterface the authenticated user identity. If authentication information is not provided, null will be returned.
16
- * @throws UnauthorizedHttpException if authentication information is provided but is invalid.
17
- */
18
- authenticate(user:any, request:Request, response:Response):any;
19
-
20
- /**
21
- * Generates challenges upon authentication failure.
22
- * For example, some appropriate HTTP headers may be generated.
23
- * @param Response $response
24
- */
25
- challenge(response:Response):Response;
26
-
27
- /**
28
- * Handles authentication failure.
29
- * The implementation should normally throw UnauthorizedHttpException to indicate authentication failure.
30
- * @param Response $response
31
- * @throws UnauthorizedHttpException
32
- */
33
- handleFailure(response:Response):Response;
34
- }
@@ -1,88 +0,0 @@
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 {ActionFilter} from "../../base/ActionFilter";
9
- import {AuthInterface} from "./AuthInterface";
10
- import {UnauthorizedHttpException} from "../../base/UnauthorizedHttpException";
11
- import {WebUser} from "../../web/WebUser";
12
- import {Request, Response} from "express";
13
-
14
- export abstract class AuthMethod extends ActionFilter implements AuthInterface {
15
-
16
- /**
17
- * @var User the user object representing the user authentication status. If not set, the `user` application component will be used.
18
- */
19
- public user: WebUser | undefined;
20
-
21
- /**
22
- * @var Request the current request. If not set, the `request` application component will be used.
23
- */
24
- public request: Request | undefined;
25
-
26
- /**
27
- * @var Response the response to be sent. If not set, the `response` application component will be used.
28
- */
29
- public response: Response | undefined;
30
-
31
-
32
- public optional = [];
33
-
34
- public async beforeAction(action: any, request: Request, response: Response) {
35
- let identity = await this.authenticate(
36
- this.user ?? new WebUser(),
37
- request,
38
- response
39
- )
40
-
41
-
42
- // @ts-ignore
43
- request.identity = identity;
44
-
45
- if (identity !== null) {
46
- return true;
47
- }
48
-
49
- this.challenge(response);
50
- this.handleFailure(response);
51
- return false;
52
- }
53
-
54
- authenticate(user: WebUser, request: Request, response: Response) {
55
-
56
- }
57
-
58
- // @ts-ignore
59
- challenge(response: Response): void {
60
- }
61
-
62
- // @ts-ignore
63
- handleFailure(response: Response) {
64
- throw new UnauthorizedHttpException('Your request was made with invalid credentials.');
65
- }
66
-
67
- getHeaderByKey(headers: any, findKey: any) {
68
- let key = Object.keys(headers).find(key => key.toLowerCase() === findKey.toLowerCase())
69
- if (key) {
70
- return headers[key];
71
- }
72
-
73
- return null
74
- }
75
-
76
- patternCheck(headerText:any, pattern:RegExp) {
77
- if (pattern) {
78
- let matches = headerText.match(pattern)
79
- if (matches && matches.length > 0) {
80
- return matches;
81
- } else {
82
- return null
83
- }
84
- }
85
-
86
- return null
87
- }
88
- }
@@ -1,75 +0,0 @@
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 {HttpHeaderAuth} from "./HttpHeaderAuth";
9
- import {Request, Response} from "express";
10
- import {WebUser} from "../../web/WebUser";
11
- import Utils from "../../requiments/Utils";
12
- import {AuthMethod} from "./AuthMethod";
13
- import {InvalidConfigException} from "../../base";
14
- import BaseChyz from "../../BaseChyz";
15
-
16
- export class HttpBasicAuth extends AuthMethod {
17
-
18
- /**
19
- * @var string the HTTP header name
20
- */
21
- public header = 'Authorization';
22
-
23
-
24
- /**
25
- * @var string a pattern to use to extract the HTTP authentication value
26
- */
27
-
28
- public pattern = /^Basic\s+(.*?)$/;
29
-
30
-
31
- /**
32
- * @throws InvalidConfigException
33
- */
34
- public init(): void {
35
- super.init();
36
-
37
- if (!this.pattern) {
38
- throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
39
- }
40
-
41
- this.user = BaseChyz.getComponent("user") ?? null;
42
- }
43
-
44
-
45
- async authenticate(user: WebUser, request:Request, response:Response) {
46
-
47
-
48
- let autHeader = this.getHeaderByKey(request.headers, this.header)
49
- if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
50
- return null;
51
- }
52
-
53
- let basicauth = autHeader[1].split(":")
54
-
55
- let identity = await user.loginByAccessToken(basicauth, "HttpBasicAuth");
56
- if (identity === null) {
57
- this.challenge(response);
58
- this.handleFailure(response);
59
- }
60
-
61
- return identity;
62
-
63
-
64
- return null;
65
- }
66
-
67
-
68
- /**
69
- * @throws UnauthorizedHttpException
70
- */
71
- public fail(response:Response): void {
72
- this.challenge(response)
73
- this.handleFailure(response);
74
- }
75
- }