chyz 2.0.0-rc.8 → 2.0.1-rc.1

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 (153) hide show
  1. package/BaseChyz.d.ts +73 -56
  2. package/BaseChyz.d.ts.map +1 -1
  3. package/BaseChyz.js +569 -404
  4. package/README.md +1 -1
  5. package/base/ActionFilter.d.ts +32 -32
  6. package/base/ActionFilter.d.ts.map +1 -1
  7. package/base/ActionFilter.js +82 -82
  8. package/base/BadRequestHttpException.d.ts +6 -0
  9. package/base/BadRequestHttpException.d.ts.map +1 -0
  10. package/base/BadRequestHttpException.js +17 -0
  11. package/base/BaseError.d.ts +43 -10
  12. package/base/BaseError.d.ts.map +1 -1
  13. package/base/BaseError.js +58 -26
  14. package/base/Behavior.d.ts +3 -3
  15. package/base/Behavior.js +7 -7
  16. package/base/CBaseObject.d.ts +4 -4
  17. package/base/CBaseObject.d.ts.map +1 -1
  18. package/base/CBaseObject.js +16 -16
  19. package/base/CEvents.d.ts +13 -0
  20. package/base/CEvents.d.ts.map +1 -0
  21. package/base/CEvents.js +24 -0
  22. package/base/CRequest.d.ts +1 -1
  23. package/base/CRequest.js +10 -10
  24. package/base/CWebController.d.ts +43 -43
  25. package/base/CWebController.d.ts.map +1 -1
  26. package/base/CWebController.js +81 -74
  27. package/base/Component.d.ts +20 -20
  28. package/base/Component.d.ts.map +1 -1
  29. package/base/Component.js +57 -57
  30. package/base/Configurable.d.ts +2 -2
  31. package/base/Configurable.js +8 -8
  32. package/base/DataErrorDbException.d.ts +5 -5
  33. package/base/DataErrorDbException.d.ts.map +1 -1
  34. package/base/DataErrorDbException.js +17 -17
  35. package/base/DbConnection.d.ts +12 -12
  36. package/base/DbConnection.js +53 -53
  37. package/base/ForbiddenHttpException.d.ts +4 -4
  38. package/base/ForbiddenHttpException.d.ts.map +1 -1
  39. package/base/ForbiddenHttpException.js +16 -16
  40. package/base/InvalidArgumentException.d.ts +5 -5
  41. package/base/InvalidArgumentException.d.ts.map +1 -1
  42. package/base/InvalidArgumentException.js +17 -17
  43. package/base/InvalidConfigException.d.ts +5 -5
  44. package/base/InvalidConfigException.d.ts.map +1 -1
  45. package/base/InvalidConfigException.js +17 -17
  46. package/base/Logs.d.ts +21 -21
  47. package/base/Logs.d.ts.map +1 -1
  48. package/base/Logs.js +57 -57
  49. package/base/Model.d.ts +301 -298
  50. package/base/Model.d.ts.map +1 -1
  51. package/base/Model.js +545 -507
  52. package/base/ModelManager.d.ts +1 -1
  53. package/base/ModelManager.js +19 -19
  54. package/base/NotFoundHttpException.d.ts +5 -5
  55. package/base/NotFoundHttpException.d.ts.map +1 -1
  56. package/base/NotFoundHttpException.js +17 -17
  57. package/base/RestClient.d.ts +6 -6
  58. package/base/RestClient.d.ts.map +1 -1
  59. package/base/RestClient.js +25 -25
  60. package/base/UnauthorizedHttpException.d.ts +5 -5
  61. package/base/UnauthorizedHttpException.d.ts.map +1 -1
  62. package/base/UnauthorizedHttpException.js +17 -17
  63. package/base/ValidationHttpException.d.ts +5 -5
  64. package/base/ValidationHttpException.d.ts.map +1 -1
  65. package/base/ValidationHttpException.js +17 -17
  66. package/base/db/Exception.d.ts +6 -6
  67. package/base/db/Exception.js +15 -15
  68. package/base/index.d.ts +19 -18
  69. package/base/index.d.ts.map +1 -1
  70. package/base/index.js +41 -39
  71. package/decorator/Middleware.d.ts +3 -3
  72. package/decorator/Middleware.js +11 -11
  73. package/decorator/controller.d.ts +2 -2
  74. package/decorator/controller.js +24 -24
  75. package/decorator/delete.d.ts +3 -0
  76. package/decorator/delete.d.ts.map +1 -0
  77. package/decorator/delete.js +36 -0
  78. package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
  79. package/decorator/enums/ControllerDecoratorParams.js +9 -9
  80. package/decorator/get.d.ts +2 -2
  81. package/decorator/get.js +36 -36
  82. package/decorator/index.d.ts +5 -3
  83. package/decorator/index.d.ts.map +1 -1
  84. package/decorator/index.js +13 -9
  85. package/decorator/post.d.ts +2 -2
  86. package/decorator/post.js +36 -36
  87. package/decorator/put.d.ts +3 -0
  88. package/decorator/put.d.ts.map +1 -0
  89. package/decorator/put.js +36 -0
  90. package/filters/AccessControl.d.ts +12 -12
  91. package/filters/AccessControl.d.ts.map +1 -1
  92. package/filters/AccessControl.js +83 -83
  93. package/filters/AccessRule.d.ts +82 -82
  94. package/filters/AccessRule.d.ts.map +1 -1
  95. package/filters/AccessRule.js +136 -137
  96. package/filters/auth/AuthInterface.d.ts +25 -25
  97. package/filters/auth/AuthInterface.js +2 -2
  98. package/filters/auth/AuthMethod.d.ts +37 -37
  99. package/filters/auth/AuthMethod.d.ts.map +1 -1
  100. package/filters/auth/AuthMethod.js +82 -82
  101. package/filters/auth/HttpBasicAuth.d.ts +23 -22
  102. package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
  103. package/filters/auth/HttpBasicAuth.js +78 -72
  104. package/filters/auth/HttpBearerAuth.d.ts +17 -17
  105. package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
  106. package/filters/auth/HttpBearerAuth.js +33 -32
  107. package/filters/auth/HttpHeaderAuth.d.ts +18 -14
  108. package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
  109. package/filters/auth/HttpHeaderAuth.js +64 -57
  110. package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
  111. package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
  112. package/filters/auth/JwtHttpBearerAuth.js +87 -81
  113. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
  114. package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
  115. package/filters/auth/index.d.ts +4 -4
  116. package/filters/auth/index.js +11 -11
  117. package/filters/index.d.ts +2 -2
  118. package/filters/index.js +7 -7
  119. package/index.d.ts +28 -21
  120. package/index.d.ts.map +1 -1
  121. package/index.js +71 -60
  122. package/model/RouteDefinition.d.ts +6 -6
  123. package/model/RouteDefinition.js +8 -8
  124. package/package.json +22 -24
  125. package/rbac/AuthAssignment.d.ts +18 -18
  126. package/rbac/AuthAssignment.js +44 -44
  127. package/rbac/AuthItem.d.ts +26 -26
  128. package/rbac/AuthItem.js +51 -51
  129. package/rbac/AuthItemChild.d.ts +18 -18
  130. package/rbac/AuthItemChild.js +43 -43
  131. package/rbac/AuthManager.d.ts +111 -111
  132. package/rbac/AuthManager.d.ts.map +1 -1
  133. package/rbac/AuthManager.js +356 -355
  134. package/rbac/index.d.ts +5 -0
  135. package/rbac/index.d.ts.map +1 -0
  136. package/rbac/index.js +28 -0
  137. package/requiments/Glob.d.ts +2 -2
  138. package/requiments/Glob.js +10 -10
  139. package/requiments/ReflectUtil.js +24 -24
  140. package/requiments/Utils.d.ts +1 -8
  141. package/requiments/Utils.d.ts.map +1 -1
  142. package/requiments/Utils.js +115 -112
  143. package/validators/BooleanValidator.js +1 -1
  144. package/validators/CompareValidator.js +1 -1
  145. package/validators/DateValidator.js +1 -1
  146. package/validators/EmailValidator.js +1 -1
  147. package/validators/Validator.d.ts +17 -17
  148. package/validators/Validator.js +27 -27
  149. package/web/IdentityInterface.d.ts +55 -54
  150. package/web/IdentityInterface.d.ts.map +1 -1
  151. package/web/IdentityInterface.js +8 -8
  152. package/web/WebUser.d.ts +71 -71
  153. package/web/WebUser.js +165 -165
@@ -1,3 +1,3 @@
1
- import "reflect-metadata";
2
- export declare const get: (path: string) => MethodDecorator;
1
+ import "reflect-metadata";
2
+ export declare const get: (path: string) => MethodDecorator;
3
3
  //# sourceMappingURL=get.d.ts.map
package/decorator/get.js CHANGED
@@ -1,36 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.get = void 0;
4
- /*
5
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
6
- * Author: Cihan Ozturk
7
- * E-mail: cihan@chy.com.tr
8
- * Github:https://github.com/cihan53/
9
- */
10
- // @ts-ignore
11
- require("reflect-metadata");
12
- const get = (path) => {
13
- // `target` equals our class, `propertyKey` equals our decorated method name
14
- // @ts-ignore
15
- return (target, propertyKey) => {
16
- // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
17
- // To prevent any further validation simply set it to an empty array here.
18
- // @ts-ignore
19
- if (!Reflect.hasMetadata('routes', target.constructor)) {
20
- // @ts-ignore
21
- Reflect.defineMetadata('routes', [], target.constructor);
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);
26
- routes.push({
27
- id: "",
28
- requestMethod: 'get',
29
- path,
30
- methodName: propertyKey
31
- });
32
- // @ts-ignore
33
- Reflect.defineMetadata('routes', routes, target.constructor);
34
- };
35
- };
36
- exports.get = get;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get = void 0;
4
+ /*
5
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
6
+ * Author: Cihan Ozturk
7
+ * E-mail: cihan@chy.com.tr
8
+ * Github:https://github.com/cihan53/
9
+ */
10
+ // @ts-ignore
11
+ require("reflect-metadata");
12
+ const get = (path) => {
13
+ // `target` equals our class, `propertyKey` equals our decorated method name
14
+ // @ts-ignore
15
+ return (target, propertyKey) => {
16
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
17
+ // To prevent any further validation simply set it to an empty array here.
18
+ // @ts-ignore
19
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
20
+ // @ts-ignore
21
+ Reflect.defineMetadata('routes', [], target.constructor);
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);
26
+ routes.push({
27
+ id: "",
28
+ requestMethod: 'get',
29
+ path,
30
+ methodName: propertyKey
31
+ });
32
+ // @ts-ignore
33
+ Reflect.defineMetadata('routes', routes, target.constructor);
34
+ };
35
+ };
36
+ exports.get = get;
@@ -1,4 +1,6 @@
1
- export { controller } from "./controller";
2
- export { get } from "./get";
3
- export { post } from "./post";
1
+ export { controller } from "./controller";
2
+ export { get } from "./get";
3
+ export { post } from "./post";
4
+ export { put } from "./put";
5
+ export { del } from "./delete";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AACvC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AACvC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAA"}
@@ -1,9 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.post = exports.get = exports.controller = void 0;
4
- var controller_1 = require("./controller");
5
- Object.defineProperty(exports, "controller", { enumerable: true, get: function () { return controller_1.controller; } });
6
- var get_1 = require("./get");
7
- Object.defineProperty(exports, "get", { enumerable: true, get: function () { return get_1.get; } });
8
- var post_1 = require("./post");
9
- Object.defineProperty(exports, "post", { enumerable: true, get: function () { return post_1.post; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.del = exports.put = exports.post = exports.get = exports.controller = void 0;
4
+ var controller_1 = require("./controller");
5
+ Object.defineProperty(exports, "controller", { enumerable: true, get: function () { return controller_1.controller; } });
6
+ var get_1 = require("./get");
7
+ Object.defineProperty(exports, "get", { enumerable: true, get: function () { return get_1.get; } });
8
+ var post_1 = require("./post");
9
+ Object.defineProperty(exports, "post", { enumerable: true, get: function () { return post_1.post; } });
10
+ var put_1 = require("./put");
11
+ Object.defineProperty(exports, "put", { enumerable: true, get: function () { return put_1.put; } });
12
+ var delete_1 = require("./delete");
13
+ Object.defineProperty(exports, "del", { enumerable: true, get: function () { return delete_1.del; } });
@@ -1,3 +1,3 @@
1
- import "reflect-metadata";
2
- export declare const post: (path: string) => MethodDecorator;
1
+ import "reflect-metadata";
2
+ export declare const post: (path: string) => MethodDecorator;
3
3
  //# sourceMappingURL=post.d.ts.map
package/decorator/post.js CHANGED
@@ -1,36 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.post = void 0;
4
- /*
5
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
6
- * Author: Cihan Ozturk
7
- * E-mail: cihan@chy.com.tr
8
- * Github:https://github.com/cihan53/
9
- */
10
- // @ts-ignore
11
- require("reflect-metadata");
12
- const post = (path) => {
13
- // `target` equals our class, `propertyKey` equals our decorated method name
14
- // @ts-ignore
15
- return (target, propertyKey) => {
16
- // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
17
- // To prevent any further validation simply set it to an empty array here.
18
- // @ts-ignore
19
- if (!Reflect.hasMetadata('routes', target.constructor)) {
20
- // @ts-ignore
21
- Reflect.defineMetadata('routes', [], target.constructor);
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);
26
- routes.push({
27
- id: "",
28
- requestMethod: 'post',
29
- path,
30
- methodName: propertyKey
31
- });
32
- // @ts-ignore
33
- Reflect.defineMetadata('routes', routes, target.constructor);
34
- };
35
- };
36
- exports.post = post;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.post = void 0;
4
+ /*
5
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
6
+ * Author: Cihan Ozturk
7
+ * E-mail: cihan@chy.com.tr
8
+ * Github:https://github.com/cihan53/
9
+ */
10
+ // @ts-ignore
11
+ require("reflect-metadata");
12
+ const post = (path) => {
13
+ // `target` equals our class, `propertyKey` equals our decorated method name
14
+ // @ts-ignore
15
+ return (target, propertyKey) => {
16
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
17
+ // To prevent any further validation simply set it to an empty array here.
18
+ // @ts-ignore
19
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
20
+ // @ts-ignore
21
+ Reflect.defineMetadata('routes', [], target.constructor);
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);
26
+ routes.push({
27
+ id: "",
28
+ requestMethod: 'post',
29
+ path,
30
+ methodName: propertyKey
31
+ });
32
+ // @ts-ignore
33
+ Reflect.defineMetadata('routes', routes, target.constructor);
34
+ };
35
+ };
36
+ exports.post = post;
@@ -0,0 +1,3 @@
1
+ import "reflect-metadata";
2
+ export declare const put: (path: string) => MethodDecorator;
3
+ //# sourceMappingURL=put.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"put.d.ts","sourceRoot":"","sources":["../../src/decorator/put.ts"],"names":[],"mappings":"AAOA,OAAQ,kBAAkB,CAAC;AAG3B,eAAO,MAAM,GAAG,SAAU,MAAM,KAAG,eAyBlC,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.put = void 0;
4
+ /*
5
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
6
+ * Author: Cihan Ozturk
7
+ * E-mail: cihan@chy.com.tr
8
+ * Github:https://github.com/cihan53/
9
+ */
10
+ // @ts-ignore
11
+ require("reflect-metadata");
12
+ const put = (path) => {
13
+ // `target` equals our class, `propertyKey` equals our decorated method name
14
+ // @ts-ignore
15
+ return (target, propertyKey) => {
16
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
17
+ // To prevent any further validation simply set it to an empty array here.
18
+ // @ts-ignore
19
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
20
+ // @ts-ignore
21
+ Reflect.defineMetadata('routes', [], target.constructor);
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);
26
+ routes.push({
27
+ id: "",
28
+ requestMethod: 'put',
29
+ path,
30
+ methodName: propertyKey
31
+ });
32
+ // @ts-ignore
33
+ Reflect.defineMetadata('routes', routes, target.constructor);
34
+ };
35
+ };
36
+ exports.put = put;
@@ -1,13 +1,13 @@
1
- /// <reference types="express" />
2
- import { Request, Response } from "../index";
3
- import { ActionFilter } from "../base/ActionFilter";
4
- import { WebUser } from "../web/WebUser";
5
- export declare class AccessControl extends ActionFilter {
6
- user: any;
7
- rules: any;
8
- denyCallback: any;
9
- init(): void;
10
- beforeAction(action: any, request: Request, res: Response): Promise<boolean>;
11
- denyAccess(user: WebUser): void;
12
- }
1
+ /// <reference types="express" />
2
+ import { Request, Response } from "../index";
3
+ import { ActionFilter } from "../base";
4
+ import { WebUser } from "../web/WebUser";
5
+ export declare class AccessControl extends ActionFilter {
6
+ user: any;
7
+ rules: any;
8
+ denyCallback: any;
9
+ init(): void;
10
+ beforeAction(action: any, request: Request, res: Response): Promise<boolean>;
11
+ denyAccess(user: WebUser): void;
12
+ }
13
13
  //# sourceMappingURL=AccessControl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AccessControl.d.ts","sourceRoot":"","sources":["../../src/filters/AccessControl.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAU,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAIvC,qBAAa,aAAc,SAAQ,YAAY;IAEpC,IAAI,EAAE,GAAG,CAAQ;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,YAAY,EAAE,GAAG,CAAQ;IAEzB,IAAI;IAeE,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,EAAC,QAAQ;IAgC7D,UAAU,CAAC,IAAI,EAAE,OAAO;CAMlC"}
1
+ {"version":3,"file":"AccessControl.d.ts","sourceRoot":"","sources":["../../src/filters/AccessControl.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAU,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAErC,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAIvC,qBAAa,aAAc,SAAQ,YAAY;IAEpC,IAAI,EAAE,GAAG,CAAQ;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,YAAY,EAAE,GAAG,CAAQ;IAEzB,IAAI;IAgBE,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,EAAC,QAAQ;IAiC7D,UAAU,CAAC,IAAI,EAAE,OAAO;CAMlC"}
@@ -1,83 +1,83 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AccessControl = void 0;
13
- /*
14
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
15
- * Author: Cihan Ozturk
16
- * E-mail: cihan@chy.com.tr
17
- * Github:https://github.com/cihan53/
18
- */
19
- const index_1 = require("../index");
20
- const ForbiddenHttpException_1 = require("../base/ForbiddenHttpException");
21
- const ActionFilter_1 = require("../base/ActionFilter");
22
- const AccessRule_1 = require("./AccessRule");
23
- const WebUser_1 = require("../web/WebUser");
24
- const Utils_1 = require("../requiments/Utils");
25
- class AccessControl extends ActionFilter_1.ActionFilter {
26
- constructor() {
27
- super(...arguments);
28
- this.user = null;
29
- this.denyCallback = null;
30
- }
31
- init() {
32
- var _a;
33
- super.init();
34
- if (this.user == undefined) {
35
- this.user = (_a = Utils_1.Utils.cloneDeep(index_1.BaseChyz.getComponent("user"))) !== null && _a !== void 0 ? _a : new WebUser_1.WebUser();
36
- }
37
- this.rules.forEach((rule, index) => {
38
- if (rule === Object(rule)) {
39
- this.rules[index] = Utils_1.Utils.createObject(new AccessRule_1.AccessRule(), rule);
40
- }
41
- });
42
- }
43
- beforeAction(action, request, res) {
44
- var _a, _b;
45
- return __awaiter(this, void 0, void 0, function* () {
46
- let allow;
47
- // @ts-ignore
48
- let user = (_a = request.user) !== null && _a !== void 0 ? _a : this.user;
49
- // @ts-ignore
50
- user.identity = (_b = request.identity) !== null && _b !== void 0 ? _b : null;
51
- for (const rulesKey in this.rules) {
52
- let rule = this.rules[rulesKey];
53
- if ((allow = yield rule.allows(action, user, request))) {
54
- return true;
55
- }
56
- else if (allow === false) {
57
- if (this.denyCallback != null) {
58
- rule.denyCallback.apply(rule, action);
59
- }
60
- else {
61
- this.denyAccess(user);
62
- }
63
- return false;
64
- }
65
- }
66
- if (this.denyCallback != null) {
67
- this.denyCallback.apply(null, action);
68
- }
69
- else {
70
- this.denyAccess(user);
71
- }
72
- return false;
73
- });
74
- }
75
- denyAccess(user) {
76
- if (user != undefined && user.getIsGuest()) {
77
- user.loginRequired();
78
- }
79
- else
80
- throw new ForbiddenHttpException_1.ForbiddenHttpException(index_1.BaseChyz.t('You are not allowed to perform this action.'));
81
- }
82
- }
83
- exports.AccessControl = AccessControl;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AccessControl = void 0;
13
+ /*
14
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
15
+ * Author: Cihan Ozturk
16
+ * E-mail: cihan@chy.com.tr
17
+ * Github:https://github.com/cihan53/
18
+ */
19
+ const index_1 = require("../index");
20
+ const base_1 = require("../base");
21
+ const base_2 = require("../base");
22
+ const AccessRule_1 = require("./AccessRule");
23
+ const WebUser_1 = require("../web/WebUser");
24
+ const Utils_1 = require("../requiments/Utils");
25
+ class AccessControl extends base_2.ActionFilter {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.user = null;
29
+ this.denyCallback = null;
30
+ }
31
+ init() {
32
+ var _a;
33
+ super.init();
34
+ if (this.user == undefined) {
35
+ this.user = (_a = Utils_1.Utils.cloneDeep(index_1.BaseChyz.getComponent("user"))) !== null && _a !== void 0 ? _a : new WebUser_1.WebUser();
36
+ }
37
+ this.rules.forEach((rule, index) => {
38
+ if (rule === Object(rule)) {
39
+ this.rules[index] = Utils_1.Utils.createObject(new AccessRule_1.AccessRule(), rule);
40
+ }
41
+ });
42
+ }
43
+ beforeAction(action, request, res) {
44
+ var _a, _b;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ let allow;
47
+ // @ts-ignore
48
+ let user = (_a = request.user) !== null && _a !== void 0 ? _a : this.user;
49
+ // @ts-ignore
50
+ user.identity = (_b = request.identity) !== null && _b !== void 0 ? _b : null;
51
+ for (const rulesKey in this.rules) {
52
+ let rule = this.rules[rulesKey];
53
+ if ((allow = yield rule.allows(action, user, request))) {
54
+ return true;
55
+ }
56
+ else if (allow === false) {
57
+ if (this.denyCallback != null) {
58
+ rule.denyCallback.apply(rule, action);
59
+ }
60
+ else {
61
+ this.denyAccess(user);
62
+ }
63
+ return false;
64
+ }
65
+ }
66
+ if (this.denyCallback != null) {
67
+ this.denyCallback.apply(null, action);
68
+ }
69
+ else {
70
+ this.denyAccess(user);
71
+ }
72
+ return false;
73
+ });
74
+ }
75
+ denyAccess(user) {
76
+ if (user != undefined && user.getIsGuest()) {
77
+ user.loginRequired();
78
+ }
79
+ else
80
+ throw new base_1.ForbiddenHttpException(index_1.BaseChyz.t('You are not allowed to perform this action.'));
81
+ }
82
+ }
83
+ exports.AccessControl = AccessControl;
@@ -1,83 +1,83 @@
1
- import { WebUser } from "../web/WebUser";
2
- import { Component } from "../base/Component";
3
- import { Request } from "express";
4
- export declare class AccessRule extends Component {
5
- /**
6
- * @var bool whether this is an 'allow' rule or 'deny' rule.
7
- */
8
- allow: any;
9
- /**
10
- * @var array list of action IDs that this rule applies to. The comparison is case-sensitive.
11
- * If not set or empty, it means this rule applies to all actions.
12
- */
13
- actions: any;
14
- /**
15
- * @var array list of the controller IDs that this rule applies to.
16
- */
17
- controllers: any;
18
- /**
19
- * - `?`: matches a guest user (not authenticated yet)
20
- * - `@`: matches an authenticated user
21
- */
22
- roles: any;
23
- /**
24
- * @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
25
- */
26
- permissions: any;
27
- /**
28
- * @var array|Closure parameters to pass to the [[User::can()]] function for evaluating
29
- * user permissions in [[$roles]].
30
- *
31
- * If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
32
- * ID from the current request, you may use the following:
33
- *
34
- * ```php
35
- * ['postId' => Yii::$app->request->get('id')]
36
- * ```
37
- *
38
- * You may also specify a closure that returns an array. This can be used to
39
- * evaluate the array values only if they are needed, for example when a model needs to be
40
- * loaded like in the following code:
41
- *
42
- * ```php
43
- * 'rules' => [
44
- * [
45
- * 'allow' => true,
46
- * 'actions' => ['update'],
47
- * 'roles' => ['updatePost'],
48
- * 'roleParams' => function($rule) {
49
- * return ['post' => Post::findOne(Yii::$app->request->get('id'))];
50
- * },
51
- * ],
52
- * ],
53
- * ```
54
- *
55
- * A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
56
- *
57
- * @see roles
58
- * @since 2.0.12
59
- */
60
- roleParams: any;
61
- /**
62
- * @var array list of user IP addresses that this rule applies to. An IP address
63
- * can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
64
- * For example, '192.168.*' matches all IP addresses in the segment '192.168.'.
65
- * It may also contain a pattern/mask like '172.16.0.0/12' which would match all IPs from the
66
- * 20-bit private network block in RFC1918.
67
- * If not set or empty, it means this rule applies to all IP addresses.
68
- */
69
- ips: any;
70
- allows(action: any, user: WebUser, request: Request): Promise<any>;
71
- /**
72
- * @param Action $action the action
73
- * @return bool whether the rule applies to the action
74
- */
75
- protected matchAction(action: any): any;
76
- /**
77
- * @param Controller $controller the controller
78
- * @return bool whether the rule applies to the controller
79
- */
80
- protected matchController(controller: any): boolean;
81
- protected matchRole(user: WebUser): Promise<boolean>;
82
- }
1
+ import { WebUser } from "../web/WebUser";
2
+ import { Component } from "../base";
3
+ import { Request } from "express";
4
+ export declare class AccessRule extends Component {
5
+ /**
6
+ * @var allow whether this is an 'allow' rule or 'deny' rule.
7
+ */
8
+ allow: any;
9
+ /**
10
+ * @var array list of action IDs that this rule applies to. The comparison is case-sensitive.
11
+ * If not set or empty, it means this rule applies to all actions.
12
+ */
13
+ actions: any;
14
+ /**
15
+ * @var array list of the controller IDs that this rule applies to.
16
+ */
17
+ controllers: any;
18
+ /**
19
+ * - `?`: matches a guest user (not authenticated yet)
20
+ * - `@`: matches an authenticated user
21
+ */
22
+ roles: any;
23
+ /**
24
+ * @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
25
+ */
26
+ permissions: any;
27
+ /**
28
+ * @var array|Closure parameters to pass to the [[User::can()]] function for evaluating
29
+ * user permissions in [[$roles]].
30
+ *
31
+ * If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
32
+ * ID from the current request, you may use the following:
33
+ *
34
+ * ```php
35
+ * ['postId' => Yii::$app->request->get('id')]
36
+ * ```
37
+ *
38
+ * You may also specify a closure that returns an array. This can be used to
39
+ * evaluate the array values only if they are needed, for example when a model needs to be
40
+ * loaded like in the following code:
41
+ *
42
+ * ```php
43
+ * 'rules' => [
44
+ * [
45
+ * 'allow' => true,
46
+ * 'actions' => ['update'],
47
+ * 'roles' => ['updatePost'],
48
+ * 'roleParams' => function($rule) {
49
+ * return ['post' => Post::findOne(Yii::$app->request->get('id'))];
50
+ * },
51
+ * ],
52
+ * ],
53
+ * ```
54
+ *
55
+ * A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
56
+ *
57
+ * @see roles
58
+ * @since 2.0.12
59
+ */
60
+ roleParams: any;
61
+ /**
62
+ * @var array list of user IP addresses that this rule applies to. An IP address
63
+ * can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
64
+ * For example, '192.168.*' matches all IP addresses in the segment '192.168.'.
65
+ * It may also contain a pattern/mask like '172.16.0.0/12' which would match all IPs from the
66
+ * 20-bit private network block in RFC1918.
67
+ * If not set or empty, it means this rule applies to all IP addresses.
68
+ */
69
+ ips: any;
70
+ allows(action: any, user: WebUser, request: Request): Promise<any>;
71
+ /**
72
+ * @param action $action the action
73
+ * @return bool whether the rule applies to the action
74
+ */
75
+ protected matchAction(action: any): any;
76
+ /**
77
+ * @param controller $controller the controller
78
+ * @return bool whether the rule applies to the controller
79
+ */
80
+ protected matchController(controller: any): boolean;
81
+ protected matchRole(user: WebUser): Promise<boolean>;
82
+ }
83
83
  //# sourceMappingURL=AccessRule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AccessRule.d.ts","sourceRoot":"","sources":["../../src/filters/AccessRule.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAKhC,qBAAa,UAAW,SAAQ,SAAS;IAErC;;OAEG;IACI,KAAK,EAAE,GAAG,CAAC;IAClB;;;OAGG;IACI,OAAO,EAAE,GAAG,CAAC;IAEpB;;OAEG;IACI,WAAW,EAAE,GAAG,CAAC;IAExB;;;OAGG;IAEI,KAAK,EAAE,GAAG,CAAC;IAElB;;OAEG;IACI,WAAW,EAAE,GAAG,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACI,UAAU,EAAE,GAAG,CAAM;IAG5B;;;;;;;OAOG;IACI,GAAG,EAAE,GAAG,CAAC;IAGH,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO;IAoBhE;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG;IAIjC;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,GAAG;cAezB,SAAS,CAAC,IAAI,EAAE,OAAO;CA6C1C"}
1
+ {"version":3,"file":"AccessRule.d.ts","sourceRoot":"","sources":["../../src/filters/AccessRule.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAElC,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAIhC,qBAAa,UAAW,SAAQ,SAAS;IAErC;;OAEG;IACI,KAAK,EAAE,GAAG,CAAC;IAClB;;;OAGG;IACI,OAAO,EAAE,GAAG,CAAC;IAEpB;;OAEG;IACI,WAAW,EAAE,GAAG,CAAC;IAExB;;;OAGG;IAEI,KAAK,EAAE,GAAG,CAAC;IAElB;;OAEG;IACI,WAAW,EAAE,GAAG,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACI,UAAU,EAAE,GAAG,CAAM;IAG5B;;;;;;;OAOG;IACI,GAAG,EAAE,GAAG,CAAC;IAGH,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO;IAoBhE;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG;IAIjC;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,GAAG;cAezB,SAAS,CAAC,IAAI,EAAE,OAAO;CA6C1C"}