chyz 1.0.12-rc.9 → 1.0.13-rc.4

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 (167) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +45 -8
  2. package/BaseChyz.js.map +1 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/README.md +80 -28
  6. package/{dist/base → base}/ActionFilter.js +2 -2
  7. package/base/ActionFilter.js.map +1 -0
  8. package/{dist/base → base}/BaseError.js +2 -2
  9. package/base/BaseError.js.map +1 -0
  10. package/{dist/base → base}/BaseObject.js +0 -0
  11. package/{dist/base → base}/BaseObject.js.map +0 -0
  12. package/{dist/base → base}/Behavior.js +0 -0
  13. package/{dist/base → base}/Behavior.js.map +0 -0
  14. package/{dist/base → base}/Component.js +0 -0
  15. package/{dist/base → base}/Component.js.map +0 -0
  16. package/{dist/base → base}/Configurable.js +0 -0
  17. package/{dist/base → base}/Configurable.js.map +0 -0
  18. package/{dist/base → base}/Controller.js +0 -0
  19. package/{dist/base → base}/Controller.js.map +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js +1 -1
  21. package/{dist/base → base}/DataErrorDbException.js.map +1 -1
  22. package/{dist/base → base}/DbConnection.js +0 -0
  23. package/{dist/base → base}/DbConnection.js.map +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js +1 -1
  25. package/{dist/base → base}/ForbiddenHttpException.js.map +1 -1
  26. package/{dist/base → base}/InvalidConfigException.js +1 -1
  27. package/{dist/base → base}/InvalidConfigException.js.map +1 -1
  28. package/{dist/base → base}/Model.js +121 -3
  29. package/base/Model.js.map +1 -0
  30. package/{dist/base → base}/NotFoundHttpException.js +1 -1
  31. package/{dist/base → base}/NotFoundHttpException.js.map +1 -1
  32. package/base/RestClient.js +27 -0
  33. package/base/RestClient.js.map +1 -0
  34. package/{dist/base → base}/UnauthorizedHttpException.js +1 -1
  35. package/{dist/base → base}/UnauthorizedHttpException.js.map +1 -1
  36. package/{dist/base → base}/ValidationHttpException.js +1 -1
  37. package/{dist/base → base}/ValidationHttpException.js.map +1 -1
  38. package/{dist/base → base}/db/Exception.js +0 -0
  39. package/{dist/base → base}/db/Exception.js.map +0 -0
  40. package/{dist/base → base}/index.js +2 -0
  41. package/{dist/base → base}/index.js.map +1 -1
  42. package/{dist/decorator → decorator}/Middleware.js +0 -0
  43. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  44. package/{dist/decorator → decorator}/controller.js +0 -0
  45. package/{dist/decorator → decorator}/controller.js.map +0 -0
  46. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  47. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  48. package/{dist/decorator → decorator}/get.js +0 -0
  49. package/{dist/decorator → decorator}/get.js.map +0 -0
  50. package/{dist/decorator → decorator}/index.js +0 -0
  51. package/{dist/decorator → decorator}/index.js.map +0 -0
  52. package/{dist/decorator → decorator}/post.js +0 -0
  53. package/{dist/decorator → decorator}/post.js.map +0 -0
  54. package/{dist/filters → filters}/AccessControl.js +2 -2
  55. package/filters/AccessControl.js.map +1 -0
  56. package/{dist/filters → filters}/AccessRule.js +0 -0
  57. package/{dist/filters → filters}/AccessRule.js.map +1 -1
  58. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  59. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  60. package/{dist/filters → filters}/auth/AuthMethod.js +2 -2
  61. package/filters/auth/AuthMethod.js.map +1 -0
  62. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  63. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  64. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  65. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  66. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  67. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +1 -1
  68. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +1 -0
  69. package/filters/auth/JwtHttpBearerAuth.js.map +1 -0
  70. package/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
  71. package/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
  72. package/{dist/filters → filters}/auth/index.js +0 -0
  73. package/{dist/filters → filters}/auth/index.js.map +0 -0
  74. package/{dist/filters → filters}/index.js +0 -0
  75. package/{dist/filters → filters}/index.js.map +0 -0
  76. package/index.js +28 -0
  77. package/index.js.map +1 -0
  78. package/log/config/log4js.json +55 -0
  79. package/{dist/model → model}/RouteDefinition.js +0 -0
  80. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  81. package/package.json +56 -52
  82. package/{dist/requiments → requiments}/Glob.js +0 -0
  83. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  84. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  85. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  86. package/{dist/requiments → requiments}/Utils.js +0 -0
  87. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  88. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  89. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  90. package/{dist/validators → validators}/CompareValidator.js +0 -0
  91. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  92. package/{dist/validators → validators}/DateValidator.js +0 -0
  93. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  94. package/{dist/validators → validators}/EmailValidator.js +0 -0
  95. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  96. package/{dist/validators → validators}/Validator.js +0 -0
  97. package/{dist/validators → validators}/Validator.js.map +0 -0
  98. package/{dist/web → web}/IdentityInterface.js +0 -0
  99. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  100. package/{dist/web/User.js → web/WebUser.js} +12 -7
  101. package/web/WebUser.js.map +1 -0
  102. package/BaseChyz.ts +0 -313
  103. package/Chyz.ts +0 -11
  104. package/Examples/Controllers/ApiController.ts +0 -121
  105. package/Examples/Controllers/PublicController.ts +0 -44
  106. package/Examples/Controllers/SiteController.ts +0 -127
  107. package/Examples/Models/Customer.ts +0 -113
  108. package/Examples/Models/Order.ts +0 -48
  109. package/Examples/Models/OrderItem.ts +0 -26
  110. package/Examples/Models/User.ts +0 -80
  111. package/Examples/index.ts +0 -38
  112. package/Examples/package.json +0 -45
  113. package/Examples/tsconfig.json +0 -20
  114. package/Examples/yarn.lock +0 -2202
  115. package/base/ActionFilter.ts +0 -71
  116. package/base/BaseError.ts +0 -26
  117. package/base/BaseObject.ts +0 -19
  118. package/base/Behavior.ts +0 -6
  119. package/base/Component.ts +0 -66
  120. package/base/Configurable.ts +0 -10
  121. package/base/Controller.ts +0 -84
  122. package/base/DataErrorDbException.ts +0 -16
  123. package/base/DbConnection.ts +0 -51
  124. package/base/ForbiddenHttpException.ts +0 -15
  125. package/base/InvalidConfigException.ts +0 -16
  126. package/base/Model.ts +0 -209
  127. package/base/NotFoundHttpException.ts +0 -14
  128. package/base/UnauthorizedHttpException.ts +0 -16
  129. package/base/ValidationHttpException.ts +0 -14
  130. package/base/db/Exception.ts +0 -14
  131. package/base/index.ts +0 -14
  132. package/decorator/Middleware.ts +0 -9
  133. package/decorator/controller.ts +0 -22
  134. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  135. package/decorator/get.ts +0 -37
  136. package/decorator/index.ts +0 -3
  137. package/decorator/post.ts +0 -36
  138. package/dist/BaseChyz.js.map +0 -1
  139. package/dist/base/ActionFilter.js.map +0 -1
  140. package/dist/base/BaseError.js.map +0 -1
  141. package/dist/base/Model.js.map +0 -1
  142. package/dist/filters/AccessControl.js.map +0 -1
  143. package/dist/filters/auth/AuthMethod.js.map +0 -1
  144. package/dist/filters/auth/JwtHttpBearerAuth.js.map +0 -1
  145. package/dist/web/User.js.map +0 -1
  146. package/filters/AccessControl.ts +0 -64
  147. package/filters/AccessRule.ts +0 -137
  148. package/filters/auth/AuthInterface.ts +0 -34
  149. package/filters/auth/AuthMethod.ts +0 -88
  150. package/filters/auth/HttpBasicAuth.ts +0 -7
  151. package/filters/auth/HttpBearerAuth.ts +0 -31
  152. package/filters/auth/HttpHeaderAuth.ts +0 -53
  153. package/filters/auth/JwtHttpBearerAuth.ts +0 -81
  154. package/filters/auth/index.ts +0 -3
  155. package/filters/index.ts +0 -2
  156. package/model/RouteDefinition.ts +0 -18
  157. package/requiments/Glob.ts +0 -9
  158. package/requiments/ReflectUtil.ts +0 -26
  159. package/requiments/Utils.ts +0 -57
  160. package/tsconfig.json +0 -18
  161. package/validators/BooleanValidator.ts +0 -0
  162. package/validators/CompareValidator.ts +0 -0
  163. package/validators/DateValidator.ts +0 -0
  164. package/validators/EmailValidator.ts +0 -0
  165. package/validators/Validator.ts +0 -27
  166. package/web/IdentityInterface.ts +0 -62
  167. package/web/User.ts +0 -96
@@ -1,81 +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 {HttpBearerAuth} from "./HttpBearerAuth";
9
- import {InvalidConfigException} from "../../base/InvalidConfigException";
10
- import {UnauthorizedHttpException} from "../../base/UnauthorizedHttpException";
11
- import {Response,Request} from "express";
12
- import {User} from "../../web/User";
13
-
14
- const JsonWebToken = require("jsonwebtoken");
15
-
16
- export class JwtHttpBearerAuth extends HttpBearerAuth {
17
- /**
18
- * @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
19
- * itself. By default it's assumes that component of ID "jwt" has been configured.
20
- */
21
- public jwt = 'jwt'
22
- public auth:any = null;
23
-
24
- /**
25
- * @throws InvalidConfigException
26
- */
27
- public init(): void {
28
- super.init();
29
-
30
- if (!this.pattern) {
31
- throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
32
- }
33
-
34
- this.user = BaseChyz.getComponent("user") ?? null;
35
- }
36
-
37
-
38
- public async authenticate(user:User, request:Request, response:Response) // BC signature
39
- {
40
-
41
- let autHeader = this.getHeaderByKey(request.headers, this.header)
42
-
43
- if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
44
- return null;
45
- }
46
-
47
-
48
- let identity = null;
49
- let token = null;
50
-
51
-
52
- token = JsonWebToken.decode(autHeader[1], {complete: true})
53
- if (!token) {
54
- BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
55
- this.fail(response);
56
- }
57
-
58
- if (token !== null) {
59
- if (this.auth != null) {
60
- identity = await this.auth(autHeader[1])
61
- } else {
62
- identity = await user.loginByAccessToken(autHeader[1], "JwtHttpBearerAuth")
63
- }
64
- }
65
-
66
- if (identity == null) this.fail(response)
67
-
68
-
69
- return identity;
70
- }
71
-
72
-
73
- /**
74
- * @throws UnauthorizedHttpException
75
- */
76
- public fail(response:Response): void {
77
- this.challenge(response)
78
- this.handleFailure(response);
79
- }
80
-
81
- }
@@ -1,3 +0,0 @@
1
- export * from "./JwtHttpBearerAuth"
2
- export * from "./HttpBearerAuth"
3
- export * from "./HttpHeaderAuth"
package/filters/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./AccessControl"
2
- export * from "./AccessRule"
@@ -1,18 +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
- export interface RouteDefinition {
9
- //id
10
- id:string;
11
- // Path to our route
12
- path: string;
13
- // HTTP Request method (get, post, ...)
14
- requestMethod: 'get' | 'post' | 'delete' | 'options' | 'put';
15
- // Method name within our class responsible for this route
16
- methodName: string;
17
- }
18
-
@@ -1,9 +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
- const Glob = require("glob");
9
- export default Glob;
@@ -1,26 +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
- /**
9
- * @param strClass:
10
- * class name
11
- * @param optionals:
12
- * constructor arguments
13
- */
14
- // @ts-ignore
15
- Reflect.newInstance = function (strClass: string) {
16
- var args = Array.prototype.slice.call(arguments, 1);
17
- var clsClass = eval(strClass);
18
-
19
- const F = () => {
20
- return clsClass.apply(this, args);
21
- }
22
-
23
- F.prototype = clsClass.prototype;
24
- // @ts-ignore
25
- return new F();
26
- };
@@ -1,57 +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 _ from "lodash";
8
- import {Utils} from "sequelize";
9
-
10
- const _ = require('lodash');
11
-
12
- const createObject = (object: any, params: any) => {
13
- let newParams: any = {}
14
- Object.keys(params).forEach((param) => {
15
- newParams[param] = {}
16
- Object.assign(newParams[param], {
17
- writable: true,
18
- configurable: true,
19
- value: params[param]
20
- });
21
- })
22
- return Object.create(object, newParams);
23
- }
24
-
25
- const findKeyValue = (object: any, findKey: string) => {
26
- let key = Object.keys(object).find(key => key.toLowerCase() === findKey.toLowerCase())
27
- if (key) {
28
- return object[key];
29
- }
30
-
31
- return null
32
- }
33
-
34
-
35
- const sleep = (seconds = 1) => {
36
- var waitTill = new Date(new Date().getTime() + seconds * 1000);
37
- while (waitTill > new Date()) {
38
- }
39
- }
40
-
41
-
42
- function wildTest(wildcard: string, str: string) {
43
- let w = wildcard.replace(/[.+^${}()|[\]\\]/g, '\\$&'); // regexp escape
44
- const re = new RegExp(`^${w.replace(/\*/g,'.*').replace(/\?/g,'.')}$`, 'i');
45
- return re.test(str); // remove last 'i' above to have case sensitive
46
- }
47
-
48
- const matchWildcard = (pattern: string, string: string, options: any = {}) => {
49
- return wildTest(pattern, string)
50
- }
51
- export default {
52
- createObject,
53
- findKeyValue,
54
- sleep,
55
- matchWildcard,
56
- ..._
57
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es6",
5
- "sourceMap": true,
6
- "strict": true,
7
- "outDir": "dist",
8
- "resolveJsonModule": true,
9
- "emitDecoratorMetadata": true,
10
- "esModuleInterop": true,
11
- "experimentalDecorators": true,
12
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
13
- },
14
- "exclude": [
15
- "node_modules",
16
- "**/Examples/*"
17
- ]
18
- }
File without changes
File without changes
File without changes
File without changes
@@ -1,27 +0,0 @@
1
- import {Component} from "../base";
2
-
3
- export class Validator extends Component {
4
- public static builtInValidators = {
5
- 'boolean': '',
6
- 'email': '',
7
- }
8
-
9
-
10
- /**
11
- * @var array|string attributes to be validated by this validator. For multiple attributes,
12
- * please specify them as an array; for single attribute, you may use either a string or an array.
13
- */
14
- public attributes = [];
15
- public message: string = "";
16
-
17
- public except = [];
18
- public isEmpty = [];
19
-
20
- public init() {
21
- super.init();
22
- }
23
-
24
- public static createValidator(type: any, model: any, attributes: any, params = []) {
25
-
26
- }
27
- }
@@ -1,62 +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
- export interface IdentityInterface {
9
- /**
10
- * Finds an identity by the given ID.
11
- * @param string|int $id the ID to be looked for
12
- * @return IdentityInterface|null the identity object that matches the given ID.
13
- * Null should be returned if such an identity cannot be found
14
- * or the identity is not in an active state (disabled, deleted, etc.)
15
- */
16
- findIdentity(id: number): any
17
-
18
- /**
19
- * Finds an identity by the given token.
20
- * For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
21
- * @return IdentityInterface|null the identity object that matches the given token.
22
- * Null should be returned if such an identity cannot be found
23
- * or the identity is not in an active state (disabled, deleted, etc.)
24
- * @param token
25
- * @param type
26
- */
27
- findIdentityByAccessToken(token: any, type: string): any;
28
-
29
- /**
30
- * Returns an ID that can uniquely identify a user identity.
31
- * @return string|int an ID that uniquely identifies a user identity.
32
- */
33
- getId(): number;
34
-
35
- /**
36
- * Returns a key that can be used to check the validity of a given identity ID.
37
- *
38
- * The key should be unique for each individual user, and should be persistent
39
- * so that it can be used to check the validity of the user identity.
40
- *
41
- * The space of such keys should be big enough to defeat potential identity attacks.
42
- *
43
- * The returned key is used to validate session and auto-login (if [[User::enableAutoLogin]] is enabled).
44
- *
45
- * Make sure to invalidate earlier issued authKeys when you implement force user logout, password change and
46
- * other scenarios, that require forceful access revocation for old sessions.
47
- *
48
- * @return string|null a key that is used to check the validity of a given identity ID.
49
- * @see validateAuthKey()
50
- */
51
- getAuthKey(): string;
52
-
53
- /**
54
- * Validates the given auth key.
55
- *
56
- * @param string $authKey the given auth key
57
- * @return bool|null whether the given auth key is valid.
58
- * @see getAuthKey()
59
- */
60
- validateAuthKey(authKey: string): (boolean | null);
61
-
62
- }
package/web/User.ts DELETED
@@ -1,96 +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 {Component} from "../base/Component";
9
- import {ForbiddenHttpException} from "../base/ForbiddenHttpException";
10
- import {InvalidConfigException} from "../base/InvalidConfigException";
11
- import {IdentityInterface} from "./IdentityInterface";
12
-
13
- export class User extends Component {
14
-
15
- /**
16
- * @var string the class name of the [[identity]] object.
17
- */
18
- public identityClass: any;
19
- private _identity: any;
20
-
21
-
22
- get identity() {
23
- return this._identity;
24
- }
25
-
26
- set identity(value) {
27
- this._identity = value;
28
- }
29
-
30
- public init() {
31
- super.init();
32
-
33
- if (this.identityClass === null) {
34
- throw new InvalidConfigException('User::identityClass must be set.');
35
- }
36
-
37
-
38
- this.identityClass = new this.identityClass();
39
-
40
- }
41
-
42
- public getIsGuest() {
43
- return this.getIdentity() === null ;
44
- }
45
-
46
- public getIdentity(autoRenew = true) {
47
- return this._identity;
48
- }
49
-
50
- public loginRequired() {
51
-
52
- throw new ForbiddenHttpException(BaseChyz.t('Login Required'));
53
- }
54
-
55
-
56
- /**
57
- * Regenerates CSRF token
58
- *
59
- * @since 2.0.14.2
60
- */
61
- protected regenerateCsrfToken() {
62
-
63
- }
64
-
65
- /**
66
- * Logs in a user by the given access token.
67
- * @param token
68
- * @param type
69
- */
70
- public async loginByAccessToken(token: any, type:any = null) {
71
-
72
- let $class = this.identityClass;
73
- this.identity = await $class.findIdentityByAccessToken(token, type)
74
- if (this.identity && this.login(this.identity)) {
75
- return this.identity;
76
- }
77
- return null;
78
- }
79
-
80
- public login(identity: IdentityInterface, duration = 0): boolean {
81
-
82
- if (this.beforeLogin(identity, false, duration)) {
83
-
84
- }
85
- return !this.getIsGuest()
86
- }
87
-
88
- public beforeLogin(identity: any, cookieBased: boolean, duration: number) {
89
-
90
- return true;
91
- }
92
-
93
- public afterLogin() {
94
-
95
- }
96
- }