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.
- package/{dist/BaseChyz.js → BaseChyz.js} +0 -0
- package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
- package/{dist/Chyz.js → Chyz.js} +0 -0
- package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
- package/{dist/base → base}/ActionFilter.js +0 -0
- package/{dist/base → base}/ActionFilter.js.map +0 -0
- package/{dist/base → base}/BaseError.js +0 -0
- package/{dist/base → base}/BaseError.js.map +0 -0
- package/{dist/base → base}/BaseObject.js +0 -0
- package/{dist/base → base}/BaseObject.js.map +0 -0
- package/{dist/base → base}/Behavior.js +0 -0
- package/{dist/base → base}/Behavior.js.map +0 -0
- package/{dist/base → base}/CWebController.js +0 -0
- package/{dist/base → base}/CWebController.js.map +0 -0
- package/{dist/base → base}/Component.js +0 -0
- package/{dist/base → base}/Component.js.map +0 -0
- package/{dist/base → base}/Configurable.js +0 -0
- package/{dist/base → base}/Configurable.js.map +0 -0
- package/{dist/base → base}/DataErrorDbException.js +0 -0
- package/{dist/base → base}/DataErrorDbException.js.map +0 -0
- package/{dist/base → base}/DbConnection.js +0 -0
- package/{dist/base → base}/DbConnection.js.map +0 -0
- package/{dist/base → base}/ForbiddenHttpException.js +0 -0
- package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
- package/{dist/base → base}/InvalidArgumentException.js +0 -0
- package/{dist/base → base}/InvalidArgumentException.js.map +0 -0
- package/{dist/base → base}/InvalidConfigException.js +0 -0
- package/{dist/base → base}/InvalidConfigException.js.map +0 -0
- package/{dist/base → base}/Model.js +0 -0
- package/{dist/base → base}/Model.js.map +0 -0
- package/{dist/base → base}/ModelManager.js +0 -0
- package/{dist/base → base}/ModelManager.js.map +0 -0
- package/{dist/base → base}/NotFoundHttpException.js +0 -0
- package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
- package/{dist/base → base}/RestClient.js +0 -0
- package/{dist/base → base}/RestClient.js.map +0 -0
- package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
- package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
- package/{dist/base → base}/ValidationHttpException.js +0 -0
- package/{dist/base → base}/ValidationHttpException.js.map +0 -0
- package/{dist/base → base}/db/Exception.js +0 -0
- package/{dist/base → base}/db/Exception.js.map +0 -0
- package/{dist/base → base}/index.js +0 -0
- package/{dist/base → base}/index.js.map +0 -0
- package/{dist/decorator → decorator}/Middleware.js +0 -0
- package/{dist/decorator → decorator}/Middleware.js.map +0 -0
- package/{dist/decorator → decorator}/controller.js +0 -0
- package/{dist/decorator → decorator}/controller.js.map +0 -0
- package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
- package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
- package/{dist/decorator → decorator}/get.js +0 -0
- package/{dist/decorator → decorator}/get.js.map +0 -0
- package/{dist/decorator → decorator}/index.js +0 -0
- package/{dist/decorator → decorator}/index.js.map +0 -0
- package/{dist/decorator → decorator}/post.js +0 -0
- package/{dist/decorator → decorator}/post.js.map +0 -0
- package/{dist/filters → filters}/AccessControl.js +0 -1
- package/filters/AccessControl.js.map +1 -0
- package/{dist/filters → filters}/AccessRule.js +0 -0
- package/{dist/filters → filters}/AccessRule.js.map +0 -0
- package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
- package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
- package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
- package/{dist/filters → filters}/auth/AuthMethod.js.map +1 -1
- package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
- package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
- package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
- package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +2 -3
- package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +1 -1
- package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
- package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
- package/{dist/filters → filters}/auth/index.js +0 -0
- package/{dist/filters → filters}/auth/index.js.map +0 -0
- package/{dist/filters → filters}/index.js +0 -0
- package/{dist/filters → filters}/index.js.map +0 -0
- package/{dist/index.js → index.js} +3 -0
- package/{dist/index.js.map → index.js.map} +1 -1
- package/log/config/log4js.json +1 -1
- package/{dist/model → model}/RouteDefinition.js +0 -0
- package/{dist/model → model}/RouteDefinition.js.map +0 -0
- package/package.json +2 -2
- package/{dist/rbac → rbac}/AuthAssignment.js +0 -0
- package/{dist/rbac → rbac}/AuthAssignment.js.map +0 -0
- package/{dist/rbac → rbac}/AuthItem.js +0 -0
- package/{dist/rbac → rbac}/AuthItem.js.map +0 -0
- package/{dist/rbac → rbac}/AuthItemChild.js +0 -0
- package/{dist/rbac → rbac}/AuthItemChild.js.map +0 -0
- package/{dist/rbac → rbac}/AuthManager.js +0 -0
- package/{dist/rbac → rbac}/AuthManager.js.map +0 -0
- package/{dist/requiments → requiments}/Glob.js +0 -0
- package/{dist/requiments → requiments}/Glob.js.map +0 -0
- package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
- package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
- package/{dist/requiments → requiments}/Utils.js +0 -0
- package/{dist/requiments → requiments}/Utils.js.map +0 -0
- package/{dist/validators → validators}/BooleanValidator.js +0 -0
- package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
- package/{dist/validators → validators}/CompareValidator.js +0 -0
- package/{dist/validators → validators}/CompareValidator.js.map +0 -0
- package/{dist/validators → validators}/DateValidator.js +0 -0
- package/{dist/validators → validators}/DateValidator.js.map +0 -0
- package/{dist/validators → validators}/EmailValidator.js +0 -0
- package/{dist/validators → validators}/EmailValidator.js.map +0 -0
- package/{dist/validators → validators}/Validator.js +0 -0
- package/{dist/validators → validators}/Validator.js.map +0 -0
- package/{dist/web → web}/IdentityInterface.js +0 -0
- package/{dist/web → web}/IdentityInterface.js.map +0 -0
- package/{dist/web → web}/WebUser.js +0 -0
- package/{dist/web → web}/WebUser.js.map +0 -0
- package/BaseChyz.ts +0 -454
- package/Chyz.ts +0 -11
- package/Doc/Moel kullanma.md +0 -13
- package/Examples/Controllers/ApiController.ts +0 -140
- package/Examples/Controllers/BasicApiController.ts +0 -121
- package/Examples/Controllers/KeyCloakController.ts +0 -100
- package/Examples/Controllers/PublicController.ts +0 -42
- package/Examples/Controllers/SiteController.ts +0 -149
- package/Examples/Models/AuthAssignment.ts +0 -50
- package/Examples/Models/AuthItem.ts +0 -59
- package/Examples/Models/AuthItemChild.ts +0 -49
- package/Examples/Models/Categories.ts +0 -51
- package/Examples/Models/Customer.ts +0 -115
- package/Examples/Models/KeycloakUser.ts +0 -70
- package/Examples/Models/Order.ts +0 -64
- package/Examples/Models/OrderItem.ts +0 -27
- package/Examples/Models/ProductModels.ts +0 -49
- package/Examples/Models/ProductToCategories.ts +0 -46
- package/Examples/Models/Products.ts +0 -50
- package/Examples/Models/Stocks.ts +0 -60
- package/Examples/Models/User.ts +0 -128
- package/Examples/Models/UserPermission.ts +0 -37
- package/Examples/Models/index.ts +0 -19
- package/Examples/index-keycloack.ts +0 -78
- package/Examples/index.ts +0 -60
- package/Examples/keycloak.json +0 -7
- package/Examples/log/access.log +0 -0
- package/Examples/log/app.log +0 -20601
- package/Examples/log/errors.log +0 -2120
- package/Examples/package.json +0 -49
- package/Examples/tsconfig.json +0 -21
- package/base/ActionFilter.ts +0 -71
- package/base/BaseError.ts +0 -28
- package/base/BaseObject.ts +0 -19
- package/base/Behavior.ts +0 -6
- package/base/CWebController.ts +0 -84
- package/base/Component.ts +0 -66
- package/base/Configurable.ts +0 -10
- package/base/DataErrorDbException.ts +0 -16
- package/base/DbConnection.ts +0 -55
- package/base/ForbiddenHttpException.ts +0 -15
- package/base/InvalidArgumentException.ts +0 -16
- package/base/InvalidConfigException.ts +0 -16
- package/base/Model.ts +0 -555
- package/base/ModelManager.ts +0 -19
- package/base/NotFoundHttpException.ts +0 -14
- package/base/RestClient.ts +0 -28
- package/base/UnauthorizedHttpException.ts +0 -17
- package/base/ValidationHttpException.ts +0 -14
- package/base/db/Exception.ts +0 -14
- package/base/index.ts +0 -18
- package/decorator/Middleware.ts +0 -9
- package/decorator/controller.ts +0 -22
- package/decorator/enums/ControllerDecoratorParams.ts +0 -5
- package/decorator/get.ts +0 -37
- package/decorator/index.ts +0 -3
- package/decorator/post.ts +0 -36
- package/dist/filters/AccessControl.js.map +0 -1
- package/dist/log/config/log4js.json +0 -55
- package/dist/package.json +0 -59
- package/filters/AccessControl.ts +0 -77
- package/filters/AccessRule.ts +0 -182
- package/filters/auth/AuthInterface.ts +0 -34
- package/filters/auth/AuthMethod.ts +0 -88
- package/filters/auth/HttpBasicAuth.ts +0 -75
- package/filters/auth/HttpBearerAuth.ts +0 -31
- package/filters/auth/HttpHeaderAuth.ts +0 -53
- package/filters/auth/JwtHttpBearerAuth.ts +0 -80
- package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
- package/filters/auth/index.ts +0 -4
- package/filters/index.ts +0 -2
- package/index.ts +0 -16
- package/model/RouteDefinition.ts +0 -18
- package/package-lock.json +0 -5259
- 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/requiments/Glob.ts +0 -9
- package/requiments/ReflectUtil.ts +0 -26
- package/requiments/Utils.ts +0 -63
- package/tsconfig.json +0 -18
- package/validators/BooleanValidator.ts +0 -0
- package/validators/CompareValidator.ts +0 -0
- package/validators/DateValidator.ts +0 -0
- package/validators/EmailValidator.ts +0 -0
- package/validators/Validator.ts +0 -27
- package/web/IdentityInterface.ts +0 -68
- package/web/WebUser.ts +0 -187
package/BaseChyz.ts
DELETED
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import {RouteDefinition} from "./model/RouteDefinition";
|
|
3
|
-
import {NextFunction, Request, Response} from "express";
|
|
4
|
-
import {CWebController} from "./base/CWebController";
|
|
5
|
-
import Utils from "./requiments/Utils";
|
|
6
|
-
import {ModelManager} from "./base";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const https = require('https');
|
|
10
|
-
const express = require("express");
|
|
11
|
-
const log4js = require("log4js");
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const validate = require('validate.js');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Use
|
|
17
|
-
* selectedBox: {
|
|
18
|
-
* array: {
|
|
19
|
-
* id: {
|
|
20
|
-
* numericality: {
|
|
21
|
-
* onlyInteger: true,
|
|
22
|
-
* greaterThan: 0
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* },
|
|
27
|
-
* @param arrayItems
|
|
28
|
-
* @param itemConstraints
|
|
29
|
-
*/
|
|
30
|
-
validate.validators.array = (arrayItems: any, itemConstraints: any) => {
|
|
31
|
-
const arrayItemErrors = arrayItems.reduce((errors: any, item: any, index: any) => {
|
|
32
|
-
const error = validate(item, itemConstraints);
|
|
33
|
-
if (error) errors[index] = {error: error};
|
|
34
|
-
return errors;
|
|
35
|
-
}, {});
|
|
36
|
-
|
|
37
|
-
return Utils.isEmpty(arrayItemErrors) ? null : {errors: arrayItemErrors};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
validate.validators.tokenString = (items: any, itemConstraints: any) => {
|
|
42
|
-
let arrayItems = items.split(",");
|
|
43
|
-
const arrayItemErrors = arrayItems.reduce((errors: any, item: any, index: any) => {
|
|
44
|
-
const error = validate(item, itemConstraints);
|
|
45
|
-
if (error) errors[index] = {error: error};
|
|
46
|
-
return errors;
|
|
47
|
-
}, {});
|
|
48
|
-
|
|
49
|
-
return Utils.isEmpty(arrayItemErrors) ? null : {errors: arrayItemErrors};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
var ip = require('ip');
|
|
53
|
-
var bodyParser = require('body-parser')
|
|
54
|
-
var methodOverride = require('method-override')
|
|
55
|
-
|
|
56
|
-
export {Request, Response, NextFunction} from "express";
|
|
57
|
-
export default class BaseChyz {
|
|
58
|
-
private config: any;
|
|
59
|
-
static app: string;
|
|
60
|
-
static httpServer: any;
|
|
61
|
-
static express = express()
|
|
62
|
-
private _port: number = 3001;
|
|
63
|
-
static db: any;
|
|
64
|
-
static routes: any;
|
|
65
|
-
private static _validate: any = validate;
|
|
66
|
-
private _logConfig: any = require('./log/config/log4js.json') ?? {}
|
|
67
|
-
private _controllerpath: string = "Controllers"
|
|
68
|
-
private static controllers: Array<CWebController> = []
|
|
69
|
-
public static components: any = {}
|
|
70
|
-
public static middlewares: any = {}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
get logConfig(): any {
|
|
74
|
-
return this._logConfig;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
set logConfig(value: any) {
|
|
78
|
-
this._logConfig = value;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get controllerpath(): string {
|
|
82
|
-
return this._controllerpath;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
set controllerpath(value: string) {
|
|
86
|
-
this._controllerpath = value;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
init() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* set request id
|
|
94
|
-
*/
|
|
95
|
-
Object.defineProperty(BaseChyz.express.request, 'reqId', {
|
|
96
|
-
configurable: true,
|
|
97
|
-
enumerable: true,
|
|
98
|
-
writable: true
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
Object.defineProperty(BaseChyz.express.request, 'user', {
|
|
102
|
-
configurable: true,
|
|
103
|
-
enumerable: true,
|
|
104
|
-
writable: true
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
Object.defineProperty(BaseChyz.express.request, 'identity', {
|
|
108
|
-
configurable: true,
|
|
109
|
-
enumerable: true,
|
|
110
|
-
writable: true
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* server port setting
|
|
116
|
-
*/
|
|
117
|
-
if (this.config.hasOwnProperty("port"))
|
|
118
|
-
this.port = this.config.port;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* controller path
|
|
122
|
-
*/
|
|
123
|
-
if (this.config.controllerpath) {
|
|
124
|
-
this.controllerpath = this.config.controllerpath
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Model Register
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
this.loadModels();
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Express Server
|
|
136
|
-
*/
|
|
137
|
-
this.middleware()
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Load Controller
|
|
141
|
-
*/
|
|
142
|
-
this.loadController();
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Listen port number
|
|
149
|
-
* Server port number get
|
|
150
|
-
*/
|
|
151
|
-
get port(): number {
|
|
152
|
-
return this._port;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Listen port number
|
|
157
|
-
* Server port number setting
|
|
158
|
-
* @param value
|
|
159
|
-
*/
|
|
160
|
-
set port(value: number) {
|
|
161
|
-
this._port = value;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
static get validate(): any {
|
|
166
|
-
return this._validate;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
static set validate(value: any) {
|
|
170
|
-
this._validate = value;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
app(config: any = {}): BaseChyz {
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Config set
|
|
177
|
-
*/
|
|
178
|
-
this.config = config;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// logger setting
|
|
182
|
-
this.logProvider().level = log4js.levels.ALL;
|
|
183
|
-
this.logProvider().configure(this._logConfig);
|
|
184
|
-
|
|
185
|
-
let components = Utils.findKeyValue(config, "components")
|
|
186
|
-
if (components) {
|
|
187
|
-
for (const componentsKey in components) {
|
|
188
|
-
|
|
189
|
-
let comp = components[componentsKey];
|
|
190
|
-
BaseChyz.debug("Create Component ", componentsKey)
|
|
191
|
-
try {
|
|
192
|
-
BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
|
|
193
|
-
BaseChyz.components[componentsKey]?.init();
|
|
194
|
-
} catch (e) {
|
|
195
|
-
BaseChyz.error("Create Component Error", e)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
let middlewares = Utils.findKeyValue(config, "middlewares")
|
|
203
|
-
if (middlewares) {
|
|
204
|
-
for (const middlewareKey in middlewares) {
|
|
205
|
-
let middleware1 = middlewares[middlewareKey];
|
|
206
|
-
BaseChyz.logs().debug("Create middlewares ", middlewareKey)
|
|
207
|
-
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
208
|
-
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.init();
|
|
213
|
-
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
public logProvider() {
|
|
219
|
-
return log4js;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
public getLogger() {
|
|
223
|
-
return this.logProvider().getLogger(this.constructor.name);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
static logs(...args: any[]) {
|
|
227
|
-
return log4js.getLogger(this.name);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public static trace(...args: any[]) {
|
|
231
|
-
BaseChyz.logs().fatal(...arguments)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public static debug(...args: any[]) {
|
|
235
|
-
BaseChyz.logs().debug(...arguments)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
public static info(...args: any[]) {
|
|
239
|
-
BaseChyz.logs().info(...arguments)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
public static warn(...args: any[]) {
|
|
243
|
-
BaseChyz.logs().warn(...arguments)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
public static error(...args: any[]) {
|
|
247
|
-
BaseChyz.logs().error(...arguments)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
public static fatal(...args: any[]) {
|
|
251
|
-
BaseChyz.logs().fatal(...arguments)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
public static warning(...args: any[]) {
|
|
256
|
-
BaseChyz.logs().warn(...arguments)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
public static t(text: string) {
|
|
260
|
-
return text;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
public errorLogger(error: any, req: any, res: any, next: any) { // for logging errors
|
|
265
|
-
BaseChyz.error(error)
|
|
266
|
-
next(error) // forward to next middleware
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
public errorResponder(error: any, req: any, res: any, next: any) { // responding to client
|
|
270
|
-
if (error.type == 'redirect')
|
|
271
|
-
res.redirect('/error')
|
|
272
|
-
else if (error.type == 'time-out') // arbitrary condition check
|
|
273
|
-
res.status(408).json(error)
|
|
274
|
-
else
|
|
275
|
-
next(error) // forwarding exceptional case to fail-safe middleware
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
public errorHandler(err: any, req: any, res: any, next: any) {
|
|
280
|
-
if (res.headersSent) {
|
|
281
|
-
return next(err)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
res.status(500).json({error: err})
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
public static getComponent(key: any) {
|
|
288
|
-
return BaseChyz.components[key] ?? null
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
public static getMiddlewares(key: any) {
|
|
293
|
-
return BaseChyz.middlewares[key] ?? null
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* load model
|
|
298
|
-
*/
|
|
299
|
-
async loadModels() {
|
|
300
|
-
let models: any = {}
|
|
301
|
-
let path = `${this._controllerpath}/../Models`;
|
|
302
|
-
fs.readdirSync(path).forEach((file: string) => {
|
|
303
|
-
if (file !== "index.ts") {
|
|
304
|
-
let model = require(`${path}/${file}`);
|
|
305
|
-
// @ts-ignore
|
|
306
|
-
let className = file.split(".")[0] + "Class";
|
|
307
|
-
if (model[className])
|
|
308
|
-
models[className.replace("Class", "")] = new model[className];
|
|
309
|
-
}
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
ModelManager._register(models);
|
|
313
|
-
|
|
314
|
-
for (const key of Object.keys(ModelManager)) {
|
|
315
|
-
if (key != "_register") {
|
|
316
|
-
ModelManager[key].init();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* load contoller
|
|
323
|
-
*/
|
|
324
|
-
async loadController() {
|
|
325
|
-
let articlesEndpoints: string[] = [];
|
|
326
|
-
fs.readdirSync(`${this._controllerpath}/`).forEach((file: string) => {
|
|
327
|
-
let controller = require(`${this._controllerpath}/${file}`);
|
|
328
|
-
|
|
329
|
-
// This is our instantiated class
|
|
330
|
-
const instance: CWebController = new controller();
|
|
331
|
-
|
|
332
|
-
BaseChyz.controllers.push(instance);
|
|
333
|
-
|
|
334
|
-
// The prefix saved to our controller
|
|
335
|
-
// @ts-ignore
|
|
336
|
-
const prefix = Reflect.getMetadata('prefix', controller);
|
|
337
|
-
// Our `routes` array containing all our routes for this controller
|
|
338
|
-
// @ts-ignore
|
|
339
|
-
const routes: Array<RouteDefinition> = Reflect.getMetadata('routes', controller);
|
|
340
|
-
BaseChyz.logs().debug("Controller load ", controller.name, `(${prefix})`)
|
|
341
|
-
|
|
342
|
-
if (routes) {
|
|
343
|
-
routes.forEach(route => {
|
|
344
|
-
|
|
345
|
-
let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
|
|
346
|
-
route.id = actionId;
|
|
347
|
-
BaseChyz.logs().debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`))
|
|
348
|
-
|
|
349
|
-
BaseChyz.express[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`),
|
|
350
|
-
async (req: Request, res: Response, next: NextFunction) => {
|
|
351
|
-
try {
|
|
352
|
-
BaseChyz.debug(`Call Request id ${instance.id}`)
|
|
353
|
-
await instance.beforeAction(route, req, res)
|
|
354
|
-
next()
|
|
355
|
-
} catch (e: any) {
|
|
356
|
-
BaseChyz.error(e);
|
|
357
|
-
|
|
358
|
-
res.status(e.statusCode || 500)
|
|
359
|
-
res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
|
|
360
|
-
// next(e)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
},
|
|
364
|
-
async (req: Request, res: Response, next: NextFunction) => {
|
|
365
|
-
try {
|
|
366
|
-
// @ts-ignore
|
|
367
|
-
BaseChyz.debug("Request ID ", req.reqId)
|
|
368
|
-
// @ts-ignore
|
|
369
|
-
await instance[route.methodName](req, res, next);
|
|
370
|
-
instance.afterAction(route, req, res);
|
|
371
|
-
} catch (e) {
|
|
372
|
-
if (e instanceof Error) {
|
|
373
|
-
BaseChyz.error(e)
|
|
374
|
-
|
|
375
|
-
// @ts-ignore
|
|
376
|
-
res.status(e.statusCode || 500)
|
|
377
|
-
// @ts-ignore
|
|
378
|
-
res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
|
|
379
|
-
} else {
|
|
380
|
-
res.json(e)
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
})
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
public middleware() {
|
|
392
|
-
|
|
393
|
-
BaseChyz.express.use(bodyParser.json({limit: '1mb'}));
|
|
394
|
-
BaseChyz.express.use(bodyParser.urlencoded({limit: '1mb', extended: true})); // support encoded bodies
|
|
395
|
-
BaseChyz.express.use(methodOverride());
|
|
396
|
-
BaseChyz.express.use(methodOverride());
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
// CORS
|
|
400
|
-
BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
401
|
-
// @ts-ignore
|
|
402
|
-
req.reqId = Utils.uniqueId("chyzzzz_")
|
|
403
|
-
res.setHeader('Content-Type', 'application/json');
|
|
404
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
405
|
-
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
406
|
-
res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
|
|
407
|
-
res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization");
|
|
408
|
-
next();
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
//Middlewares
|
|
412
|
-
for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
|
|
413
|
-
if (!Utils.isFunction(middleware1)) {
|
|
414
|
-
let keycloak = BaseChyz.middlewares[middleware1].keycloak;
|
|
415
|
-
BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
|
|
416
|
-
} else {
|
|
417
|
-
BaseChyz.express.use(BaseChyz.middlewares[middleware1]);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
BaseChyz.express.use(this.errorResponder)
|
|
424
|
-
BaseChyz.express.use(this.errorHandler)
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
public Start() {
|
|
429
|
-
|
|
430
|
-
BaseChyz.info("Express Server Starting")
|
|
431
|
-
|
|
432
|
-
if (this.config?.ssl) {
|
|
433
|
-
BaseChyz.httpServer = https.createServer(this.config?.ssl, BaseChyz.express);
|
|
434
|
-
BaseChyz.httpServer.listen(this._port, () => {
|
|
435
|
-
BaseChyz.info("Express Server Start ")
|
|
436
|
-
BaseChyz.info(`Liten Port ${this._port}`)
|
|
437
|
-
BaseChyz.info(`https://localhost:${this._port}`)
|
|
438
|
-
BaseChyz.info(`https://${ip.address()}:${this._port}`)
|
|
439
|
-
})
|
|
440
|
-
} else {
|
|
441
|
-
BaseChyz.httpServer = BaseChyz.express.listen(this._port, () => {
|
|
442
|
-
BaseChyz.info("Express Server Start ")
|
|
443
|
-
BaseChyz.info(`Liten Port ${this._port}`)
|
|
444
|
-
BaseChyz.info(`http://localhost:${this._port}`)
|
|
445
|
-
BaseChyz.info(`http://${ip.address()}:${this._port}`)
|
|
446
|
-
})
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return this;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
package/Chyz.ts
DELETED
package/Doc/Moel kullanma.md
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
4
|
-
* Author: Cihan Ozturk
|
|
5
|
-
* E-mail: cihan@chy.com.tr
|
|
6
|
-
* Github:https://github.com/cihan53/
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {CWebController, ModelManager} from "../../base";
|
|
11
|
-
import BaseChyz from "../../BaseChyz";
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
import {Request, Response} from "express";
|
|
14
|
-
import {get} from "../../decorator";
|
|
15
|
-
import {post} from "../../decorator";
|
|
16
|
-
import {controller} from "../../decorator";
|
|
17
|
-
import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
18
|
-
|
|
19
|
-
import {ValidationHttpException} from "../../base";
|
|
20
|
-
import {ForbiddenHttpException} from "../../base";
|
|
21
|
-
import {ProductsClass} from "../Models/Products";
|
|
22
|
-
import {AccessControl} from "../../filters";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@controller("/api")
|
|
26
|
-
class ApiController extends CWebController {
|
|
27
|
-
|
|
28
|
-
public myCheck(token) {
|
|
29
|
-
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public behaviors(): any[] {
|
|
33
|
-
|
|
34
|
-
return [{
|
|
35
|
-
'authenticator': {
|
|
36
|
-
"class": JwtHttpBearerAuth,
|
|
37
|
-
// "auth": this.myCheck
|
|
38
|
-
},
|
|
39
|
-
'access': {
|
|
40
|
-
'class': AccessControl,
|
|
41
|
-
'only': ['order/list' ],
|
|
42
|
-
'rules': [
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
'allow': true,
|
|
46
|
-
'actions': ['order/list' ],
|
|
47
|
-
'roles': ['edis-manager'],
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
}]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@get("/")
|
|
55
|
-
Index(req: Request, res: Response) {
|
|
56
|
-
|
|
57
|
-
BaseChyz.logs().info("Site Controller Burası", this.id)
|
|
58
|
-
return res.json({message: "index sayfası"})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@post("orderCreate")
|
|
62
|
-
async Login(req: Request, res: Response) {
|
|
63
|
-
let data = req.body;
|
|
64
|
-
data.Customer.status = "true";
|
|
65
|
-
data.Customer["2fa"] = "true";
|
|
66
|
-
|
|
67
|
-
//Customer Model Create
|
|
68
|
-
let customer = ModelManager.Customer.save();
|
|
69
|
-
//Order Model Create
|
|
70
|
-
let order = ModelManager.Order;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let transaction
|
|
74
|
-
try {
|
|
75
|
-
// get transaction
|
|
76
|
-
transaction = await BaseChyz.getComponent("db").transaction();
|
|
77
|
-
customer.load(data, "Customer");//load customer data
|
|
78
|
-
let cus: any = await customer.save({}, {transaction});
|
|
79
|
-
|
|
80
|
-
if (!cus) {
|
|
81
|
-
throw new ValidationHttpException(customer.errors);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
data.Order.customer_id = cus.id;
|
|
85
|
-
// data.Order.total = 0;
|
|
86
|
-
// data.Order.status = true;
|
|
87
|
-
order.load(data, "Order");
|
|
88
|
-
let res1 = await order.save({}, {transaction});
|
|
89
|
-
if (!res1) {
|
|
90
|
-
throw new ValidationHttpException(order.errors);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// commit
|
|
94
|
-
await transaction.commit();
|
|
95
|
-
|
|
96
|
-
} catch (e) {
|
|
97
|
-
if (transaction) {
|
|
98
|
-
await transaction.rollback();
|
|
99
|
-
BaseChyz.warn("Rollback transaction")
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (e instanceof ValidationHttpException)
|
|
103
|
-
throw new ValidationHttpException(e.message)
|
|
104
|
-
else
|
|
105
|
-
throw new ForbiddenHttpException(e.message)
|
|
106
|
-
}
|
|
107
|
-
return res.send("Post Controller")
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
@get("order/list")
|
|
112
|
-
async listOrder(req: Request, res: Response) {
|
|
113
|
-
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
114
|
-
let product = await Products.cache().findAll( );
|
|
115
|
-
return res.json(product)
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@get("categories")
|
|
120
|
-
async Categories(req: Request, res: Response) {
|
|
121
|
-
let product = await ModelManager.Categories.findAll({
|
|
122
|
-
include: [
|
|
123
|
-
{
|
|
124
|
-
model: ModelManager.Products.model(),
|
|
125
|
-
// as: 'product',
|
|
126
|
-
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
127
|
-
}
|
|
128
|
-
]
|
|
129
|
-
});
|
|
130
|
-
return res.json(product)
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
error(req: Request, res: Response) {
|
|
135
|
-
BaseChyz.logs().info("Error Sayfası")
|
|
136
|
-
return res.send("Post Controller")
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
module.exports = ApiController
|