chyz 1.0.13-rc.20 → 1.0.13-rc.6
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.
- package/BaseChyz.ts +4 -19
- package/Examples/Controllers/ApiController.ts +22 -22
- package/Examples/Controllers/SiteController.ts +8 -18
- package/Examples/Models/Categories.ts +2 -1
- package/Examples/Models/KeycloakUser.ts +0 -4
- package/Examples/Models/User.ts +1 -8
- package/Examples/index.ts +0 -5
- package/Examples/log/app.log +0 -4322
- package/Examples/log/errors.log +0 -458
- package/README.md +12 -265
- package/base/ActionFilter.ts +1 -1
- package/base/BaseError.ts +1 -3
- package/base/Model.ts +29 -43
- package/base/ModelManager.ts +1 -6
- package/base/RestClient.ts +4 -4
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +0 -1
- package/dist/BaseChyz.js +4 -17
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/ActionFilter.js +1 -1
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +1 -5
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/Model.js +2 -12
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +8 -0
- package/dist/base/ModelManager.js.map +1 -1
- package/dist/base/RestClient.js +4 -4
- package/dist/base/RestClient.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/index.js +0 -1
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +3 -15
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js +38 -99
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/HttpBasicAuth.js +0 -65
- package/dist/filters/auth/HttpBasicAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/index.js +0 -1
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/package.json +5 -4
- package/dist/web/WebUser.js +0 -78
- package/dist/web/WebUser.js.map +1 -1
- package/filters/AccessControl.ts +6 -19
- package/filters/AccessRule.ts +16 -61
- package/filters/auth/HttpBasicAuth.ts +0 -68
- package/filters/auth/JwtHttpBearerAuth.ts +1 -1
- package/filters/auth/index.ts +0 -1
- package/package.json +5 -4
- package/web/IdentityInterface.ts +0 -6
- package/web/WebUser.ts +1 -88
- package/Doc/Moel kullanma.md +0 -13
- package/Examples/Controllers/BasicApiController.ts +0 -121
- package/Examples/Models/AuthAssignment.ts +0 -50
- package/Examples/Models/AuthItem.ts +0 -59
- package/Examples/Models/AuthItemChild.ts +0 -49
- package/base/InvalidArgumentException.ts +0 -16
- package/dist/base/InvalidArgumentException.js +0 -18
- package/dist/base/InvalidArgumentException.js.map +0 -1
- package/dist/rbac/AuthAssignment.js +0 -45
- package/dist/rbac/AuthAssignment.js.map +0 -1
- package/dist/rbac/AuthItem.js +0 -52
- package/dist/rbac/AuthItem.js.map +0 -1
- package/dist/rbac/AuthItemChild.js +0 -44
- package/dist/rbac/AuthItemChild.js.map +0 -1
- package/dist/rbac/AuthManager.js +0 -359
- package/dist/rbac/AuthManager.js.map +0 -1
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthItem.ts +0 -57
- package/rbac/AuthItemChild.ts +0 -50
- package/rbac/AuthManager.ts +0 -398
package/BaseChyz.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {ModelManager} from "./base";
|
|
|
9
9
|
const express = require("express");
|
|
10
10
|
const log4js = require("log4js");
|
|
11
11
|
const fs = require('fs');
|
|
12
|
-
const validate = require('validate.js');
|
|
13
12
|
|
|
14
13
|
var ip = require('ip');
|
|
15
14
|
var bodyParser = require('body-parser')
|
|
@@ -23,7 +22,6 @@ export default class BaseChyz {
|
|
|
23
22
|
private _port: number = 3001;
|
|
24
23
|
static db: any;
|
|
25
24
|
static routes: any;
|
|
26
|
-
private static _validate:any=validate;
|
|
27
25
|
private _logConfig: any = require('./log/config/log4js.json') ?? {}
|
|
28
26
|
private _controllerpath: string = "Controllers"
|
|
29
27
|
private static controllers: Array<Controller> = []
|
|
@@ -124,14 +122,6 @@ export default class BaseChyz {
|
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
|
|
127
|
-
static get validate(): any {
|
|
128
|
-
return this._validate;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static set validate(value: any) {
|
|
132
|
-
this._validate = value;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
125
|
app(config: any = {}): BaseChyz {
|
|
136
126
|
|
|
137
127
|
/**
|
|
@@ -144,14 +134,9 @@ export default class BaseChyz {
|
|
|
144
134
|
if (components) {
|
|
145
135
|
for (const componentsKey in components) {
|
|
146
136
|
let comp = components[componentsKey];
|
|
147
|
-
BaseChyz.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
BaseChyz.components[componentsKey]?.init();
|
|
151
|
-
}catch (e) {
|
|
152
|
-
console.error(e)
|
|
153
|
-
}
|
|
154
|
-
|
|
137
|
+
BaseChyz.debug("Create Component ", componentsKey)
|
|
138
|
+
BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
|
|
139
|
+
BaseChyz.components[componentsKey]?.init();
|
|
155
140
|
}
|
|
156
141
|
}
|
|
157
142
|
|
|
@@ -160,7 +145,7 @@ export default class BaseChyz {
|
|
|
160
145
|
if (middlewares) {
|
|
161
146
|
for (const middlewareKey in middlewares) {
|
|
162
147
|
let middleware1 = middlewares[middlewareKey];
|
|
163
|
-
BaseChyz.
|
|
148
|
+
BaseChyz.debug("Create middlewares ", middlewareKey)
|
|
164
149
|
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
165
150
|
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
166
151
|
}
|
|
@@ -18,8 +18,7 @@ import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
|
18
18
|
|
|
19
19
|
import {ValidationHttpException} from "../../base";
|
|
20
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
-
|
|
22
|
-
import {AccessControl} from "../../filters";
|
|
21
|
+
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
@controller("/api")
|
|
@@ -36,18 +35,22 @@ class ApiController extends Controller {
|
|
|
36
35
|
"class": JwtHttpBearerAuth,
|
|
37
36
|
// "auth": this.myCheck
|
|
38
37
|
},
|
|
39
|
-
'access': {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
// 'access': {
|
|
39
|
+
// 'class': AccessControl,
|
|
40
|
+
// 'only': ['login', 'logout', 'signup'],
|
|
41
|
+
// 'rules': [
|
|
42
|
+
// {
|
|
43
|
+
// 'allow': true,
|
|
44
|
+
// 'actions': ['login', 'index'],
|
|
45
|
+
// 'roles': ['?'],
|
|
46
|
+
// },
|
|
47
|
+
// {
|
|
48
|
+
// 'allow': true,
|
|
49
|
+
// 'actions': ['logout', "logout2"],
|
|
50
|
+
// 'roles': ['@'],
|
|
51
|
+
// }
|
|
52
|
+
// ]
|
|
53
|
+
// }
|
|
51
54
|
}]
|
|
52
55
|
}
|
|
53
56
|
|
|
@@ -65,9 +68,9 @@ class ApiController extends Controller {
|
|
|
65
68
|
data.Customer["2fa"] = "true";
|
|
66
69
|
|
|
67
70
|
//Customer Model Create
|
|
68
|
-
let customer
|
|
71
|
+
let customer = ModelManager.Customer;
|
|
69
72
|
//Order Model Create
|
|
70
|
-
let order
|
|
73
|
+
let order = ModelManager.Order;
|
|
71
74
|
|
|
72
75
|
|
|
73
76
|
let transaction
|
|
@@ -110,23 +113,20 @@ class ApiController extends Controller {
|
|
|
110
113
|
|
|
111
114
|
@get("order/list")
|
|
112
115
|
async listOrder(req: Request, res: Response) {
|
|
113
|
-
|
|
114
|
-
let product = await Products.findAll( );
|
|
116
|
+
let product = await ModelManager.Products.findAll({include: [ModelManager.ProductModels.model()]});
|
|
115
117
|
return res.json(product)
|
|
116
118
|
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
@get("categories")
|
|
120
122
|
async Categories(req: Request, res: Response) {
|
|
121
|
-
let product = await ModelManager.Categories.findAll({
|
|
122
|
-
include: [
|
|
123
|
+
let product = await ModelManager.Categories.findAll( {include:[
|
|
123
124
|
{
|
|
124
125
|
model: ModelManager.Products.model(),
|
|
125
126
|
// as: 'product',
|
|
126
127
|
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
127
128
|
}
|
|
128
|
-
]
|
|
129
|
-
});
|
|
129
|
+
]} );
|
|
130
130
|
return res.json(product)
|
|
131
131
|
|
|
132
132
|
}
|
|
@@ -26,12 +26,11 @@ class SiteController extends Controller {
|
|
|
26
26
|
public myCheck(token) {
|
|
27
27
|
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
public behaviors(): any[] {
|
|
31
30
|
return [{
|
|
32
31
|
'authenticator': {
|
|
33
32
|
"class": JwtHttpBearerAuth,
|
|
34
|
-
"except":
|
|
33
|
+
"except":["index","login"]
|
|
35
34
|
// "auth": this.myCheck
|
|
36
35
|
}
|
|
37
36
|
}]
|
|
@@ -89,33 +88,25 @@ class SiteController extends Controller {
|
|
|
89
88
|
// @ts-ignore
|
|
90
89
|
let xForwardedFor = (req.headers['x-forwarded-for'] || '').replace(/:\d+$/, '');
|
|
91
90
|
let ip = xForwardedFor || req.socket.remoteAddress;
|
|
92
|
-
var source: string
|
|
91
|
+
var source: string = req.headers['user-agent'] || '';
|
|
93
92
|
if (req.headers['x-ucbrowser-ua']) { //special case of UC Browser
|
|
94
|
-
source = req.headers['x-ucbrowser-ua']
|
|
93
|
+
source = req.headers['x-ucbrowser-ua']+"";
|
|
95
94
|
}
|
|
96
95
|
token = await JsonWebToken.sign({
|
|
97
96
|
user: user.id,
|
|
98
97
|
ip: ip,
|
|
99
98
|
agent: source,
|
|
100
|
-
|
|
101
|
-
role: [
|
|
102
|
-
"admin"
|
|
103
|
-
],
|
|
104
|
-
permissions: [
|
|
105
|
-
"xxxx",
|
|
106
|
-
|
|
107
|
-
],
|
|
108
|
-
}, user.authkey, null);
|
|
99
|
+
}, user.authkey, {expiresIn: '1h'});
|
|
109
100
|
|
|
110
|
-
BaseChyz.debug("Db user create access token", username,
|
|
101
|
+
BaseChyz.debug("Db user create access token", username,"expiresIn","1h")
|
|
111
102
|
return res.json({token: token})
|
|
112
103
|
} else {
|
|
113
104
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
114
|
-
res.status(500).json(error.toJSON())
|
|
105
|
+
res.status(500).json( error.toJSON())
|
|
115
106
|
}
|
|
116
107
|
} else {
|
|
117
108
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
118
|
-
res.status(500).json(error.toJSON())
|
|
109
|
+
res.status(500).json( error.toJSON())
|
|
119
110
|
}
|
|
120
111
|
|
|
121
112
|
|
|
@@ -145,5 +136,4 @@ class SiteController extends Controller {
|
|
|
145
136
|
return res.send("Post Controller")
|
|
146
137
|
}
|
|
147
138
|
}
|
|
148
|
-
|
|
149
|
-
module.exports = SiteController
|
|
139
|
+
module.exports=SiteController
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes,
|
|
7
|
+
import {DataTypes, ModelManager, Model, Relation} from "../../base";
|
|
8
|
+
import {ProductToCategoriesClass} from "./ProductToCategories";
|
|
8
9
|
|
|
9
10
|
export class CategoriesClass extends Model {
|
|
10
11
|
[x: string]: any;
|
package/Examples/Models/User.ts
CHANGED
|
@@ -28,11 +28,6 @@ export class User extends Model implements IdentityInterface {
|
|
|
28
28
|
throw new Error("Method not implemented.");
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
can(permissionName: string, params: any[], allowCaching: boolean): boolean | null {
|
|
32
|
-
throw new Error("Method not implemented.");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
31
|
getAuthKey(): string {
|
|
37
32
|
throw new Error("Method not implemented.");
|
|
38
33
|
}
|
|
@@ -76,8 +71,8 @@ export class User extends Model implements IdentityInterface {
|
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
async findIdentityByAccessToken(token, type) {
|
|
79
|
-
|
|
80
74
|
let decoded = JsonWebToken.decode(token, {complete: true})
|
|
75
|
+
|
|
81
76
|
if(!decoded.payload.user) {
|
|
82
77
|
return null;
|
|
83
78
|
}
|
|
@@ -102,6 +97,4 @@ export class User extends Model implements IdentityInterface {
|
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
|
|
105
|
-
|
|
106
|
-
|
|
107
100
|
}
|
package/Examples/index.ts
CHANGED
|
@@ -7,22 +7,17 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
import {BaseChyz} from "../index";
|
|
10
|
-
|
|
11
10
|
require('dotenv-flow').config();
|
|
12
11
|
import Chyz from "../Chyz";
|
|
13
12
|
import {WebUser} from "../web/WebUser";
|
|
14
13
|
import {User} from "./Models/User";
|
|
15
14
|
import {DbConnection} from "../base";
|
|
16
|
-
import {AuthManager} from "../rbac/AuthManager";
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
let config = {
|
|
20
18
|
port: process.env.PORT,
|
|
21
19
|
controllerpath: "C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
|
|
22
20
|
components: {
|
|
23
|
-
authManager: {
|
|
24
|
-
class: AuthManager,
|
|
25
|
-
},
|
|
26
21
|
db: {
|
|
27
22
|
class: DbConnection,
|
|
28
23
|
database: process.env.DBDATABASE,
|