chyz 1.0.13-rc.3 → 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 (176) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +0 -0
  2. package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/{dist/base → base}/ActionFilter.js +0 -0
  6. package/{dist/base → base}/ActionFilter.js.map +0 -0
  7. package/{dist/base → base}/BaseError.js +0 -0
  8. package/{dist/base → base}/BaseError.js.map +0 -0
  9. package/{dist/base → base}/BaseObject.js +0 -0
  10. package/{dist/base → base}/BaseObject.js.map +0 -0
  11. package/{dist/base → base}/Behavior.js +0 -0
  12. package/{dist/base → base}/Behavior.js.map +0 -0
  13. package/{dist/base → base}/Component.js +0 -0
  14. package/{dist/base → base}/Component.js.map +0 -0
  15. package/{dist/base → base}/Configurable.js +0 -0
  16. package/{dist/base → base}/Configurable.js.map +0 -0
  17. package/{dist/base → base}/Controller.js +0 -0
  18. package/{dist/base → base}/Controller.js.map +0 -0
  19. package/{dist/base → base}/DataErrorDbException.js +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js.map +0 -0
  21. package/{dist/base → base}/DbConnection.js +0 -0
  22. package/{dist/base → base}/DbConnection.js.map +0 -0
  23. package/{dist/base → base}/ForbiddenHttpException.js +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
  25. package/{dist/base → base}/InvalidConfigException.js +0 -0
  26. package/{dist/base → base}/InvalidConfigException.js.map +0 -0
  27. package/{dist/base → base}/Model.js +0 -0
  28. package/{dist/base → base}/Model.js.map +0 -0
  29. package/{dist/base → base}/NotFoundHttpException.js +0 -0
  30. package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
  31. package/{dist/base → base}/RestClient.js +0 -0
  32. package/{dist/base → base}/RestClient.js.map +0 -0
  33. package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
  34. package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
  35. package/{dist/base → base}/ValidationHttpException.js +0 -0
  36. package/{dist/base → base}/ValidationHttpException.js.map +0 -0
  37. package/{dist/base → base}/db/Exception.js +0 -0
  38. package/{dist/base → base}/db/Exception.js.map +0 -0
  39. package/{dist/base → base}/index.js +0 -0
  40. package/{dist/base → base}/index.js.map +0 -0
  41. package/{dist/decorator → decorator}/Middleware.js +0 -0
  42. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  43. package/{dist/decorator → decorator}/controller.js +0 -0
  44. package/{dist/decorator → decorator}/controller.js.map +0 -0
  45. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  46. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  47. package/{dist/decorator → decorator}/get.js +0 -0
  48. package/{dist/decorator → decorator}/get.js.map +0 -0
  49. package/{dist/decorator → decorator}/index.js +0 -0
  50. package/{dist/decorator → decorator}/index.js.map +0 -0
  51. package/{dist/decorator → decorator}/post.js +0 -0
  52. package/{dist/decorator → decorator}/post.js.map +0 -0
  53. package/{dist/filters → filters}/AccessControl.js +0 -0
  54. package/{dist/filters → filters}/AccessControl.js.map +0 -0
  55. package/{dist/filters → filters}/AccessRule.js +0 -0
  56. package/{dist/filters → filters}/AccessRule.js.map +0 -0
  57. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  58. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  59. package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
  60. package/{dist/filters → filters}/auth/AuthMethod.js.map +0 -0
  61. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  62. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  63. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  64. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  65. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  66. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
  67. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +0 -0
  68. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +0 -0
  69. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  70. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  71. package/{dist/filters → filters}/auth/index.js +0 -0
  72. package/{dist/filters → filters}/auth/index.js.map +0 -0
  73. package/{dist/filters → filters}/index.js +0 -0
  74. package/{dist/filters → filters}/index.js.map +0 -0
  75. package/{dist/index.js → index.js} +0 -0
  76. package/{dist/index.js.map → index.js.map} +0 -0
  77. package/{dist/model → model}/RouteDefinition.js +0 -0
  78. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  79. package/package.json +1 -1
  80. package/{dist/requiments → requiments}/Glob.js +0 -0
  81. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  82. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  83. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  84. package/{dist/requiments → requiments}/Utils.js +0 -0
  85. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  86. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  87. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  88. package/{dist/validators → validators}/CompareValidator.js +0 -0
  89. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  90. package/{dist/validators → validators}/DateValidator.js +0 -0
  91. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  92. package/{dist/validators → validators}/EmailValidator.js +0 -0
  93. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  94. package/{dist/validators → validators}/Validator.js +0 -0
  95. package/{dist/validators → validators}/Validator.js.map +0 -0
  96. package/{dist/web → web}/IdentityInterface.js +0 -0
  97. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  98. package/{dist/web → web}/WebUser.js +0 -0
  99. package/{dist/web → web}/WebUser.js.map +0 -0
  100. package/BaseChyz.ts +0 -361
  101. package/Chyz.ts +0 -11
  102. package/Examples/Controllers/ApiController.ts +0 -131
  103. package/Examples/Controllers/KeyCloakController.ts +0 -100
  104. package/Examples/Controllers/PublicController.ts +0 -42
  105. package/Examples/Controllers/SiteController.ts +0 -139
  106. package/Examples/Models/Categories.ts +0 -36
  107. package/Examples/Models/Customer.ts +0 -115
  108. package/Examples/Models/KeycloakUser.ts +0 -66
  109. package/Examples/Models/Order.ts +0 -64
  110. package/Examples/Models/OrderItem.ts +0 -27
  111. package/Examples/Models/ProductModels.ts +0 -50
  112. package/Examples/Models/ProductToCategories.ts +0 -35
  113. package/Examples/Models/Products.ts +0 -49
  114. package/Examples/Models/Stocks.ts +0 -60
  115. package/Examples/Models/User.ts +0 -100
  116. package/Examples/Models/UserPermission.ts +0 -37
  117. package/Examples/index-keycloack.ts +0 -78
  118. package/Examples/index.ts +0 -39
  119. package/Examples/keycloak.json +0 -7
  120. package/Examples/log/access.log +0 -0
  121. package/Examples/log/app.log +0 -923
  122. package/Examples/log/errors.log +0 -80
  123. package/Examples/package.json +0 -46
  124. package/Examples/tsconfig.json +0 -20
  125. package/base/ActionFilter.ts +0 -71
  126. package/base/BaseError.ts +0 -26
  127. package/base/BaseObject.ts +0 -19
  128. package/base/Behavior.ts +0 -6
  129. package/base/Component.ts +0 -66
  130. package/base/Configurable.ts +0 -10
  131. package/base/Controller.ts +0 -84
  132. package/base/DataErrorDbException.ts +0 -16
  133. package/base/DbConnection.ts +0 -51
  134. package/base/ForbiddenHttpException.ts +0 -15
  135. package/base/InvalidConfigException.ts +0 -16
  136. package/base/Model.ts +0 -354
  137. package/base/NotFoundHttpException.ts +0 -14
  138. package/base/RestClient.ts +0 -28
  139. package/base/UnauthorizedHttpException.ts +0 -17
  140. package/base/ValidationHttpException.ts +0 -14
  141. package/base/db/Exception.ts +0 -14
  142. package/base/index.ts +0 -16
  143. package/decorator/Middleware.ts +0 -9
  144. package/decorator/controller.ts +0 -22
  145. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  146. package/decorator/get.ts +0 -37
  147. package/decorator/index.ts +0 -3
  148. package/decorator/post.ts +0 -36
  149. package/dist/README.md +0 -270
  150. package/dist/log/config/log4js.json +0 -55
  151. package/dist/package.json +0 -55
  152. package/filters/AccessControl.ts +0 -64
  153. package/filters/AccessRule.ts +0 -137
  154. package/filters/auth/AuthInterface.ts +0 -34
  155. package/filters/auth/AuthMethod.ts +0 -88
  156. package/filters/auth/HttpBasicAuth.ts +0 -7
  157. package/filters/auth/HttpBearerAuth.ts +0 -31
  158. package/filters/auth/HttpHeaderAuth.ts +0 -53
  159. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  160. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  161. package/filters/auth/index.ts +0 -3
  162. package/filters/index.ts +0 -2
  163. package/index.ts +0 -14
  164. package/model/RouteDefinition.ts +0 -18
  165. package/package-lock.json +0 -5259
  166. package/requiments/Glob.ts +0 -9
  167. package/requiments/ReflectUtil.ts +0 -26
  168. package/requiments/Utils.ts +0 -57
  169. package/tsconfig.json +0 -18
  170. package/validators/BooleanValidator.ts +0 -0
  171. package/validators/CompareValidator.ts +0 -0
  172. package/validators/DateValidator.ts +0 -0
  173. package/validators/EmailValidator.ts +0 -0
  174. package/validators/Validator.ts +0 -27
  175. package/web/IdentityInterface.ts +0 -62
  176. package/web/WebUser.ts +0 -100
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chyz",
3
- "version": "1.0.13-rc.3",
3
+ "version": "1.0.13-rc.4",
4
4
  "description": "Nodejs MicroServis Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/BaseChyz.ts DELETED
@@ -1,361 +0,0 @@
1
- import 'reflect-metadata';
2
- import {RouteDefinition} from "./model/RouteDefinition";
3
- import {NextFunction, Request, Response} from "express";
4
- import {Controller} from "./base/Controller";
5
- import Utils from "./requiments/Utils";
6
-
7
-
8
- const express = require("express");
9
- const log4js = require("log4js");
10
- const fs = require('fs');
11
-
12
- var ip = require('ip');
13
- var bodyParser = require('body-parser')
14
- var methodOverride = require('method-override')
15
-
16
- export {Request, Response, NextFunction} from "express";
17
- export default class BaseChyz {
18
- private config: any;
19
- static app: string;
20
- static express = express()
21
- private _port: number = 3001;
22
- static db: any;
23
- static routes: any;
24
- private _logConfig: any = require('./log/config/log4js.json') ?? {}
25
- private _controllerpath: string = "Controllers"
26
- private static controllers: Array<Controller> = []
27
- public static components: any = {}
28
- public static middlewares: any = {}
29
-
30
-
31
- get logConfig(): any {
32
- return this._logConfig;
33
- }
34
-
35
- set logConfig(value: any) {
36
- this._logConfig = value;
37
- }
38
-
39
- get controllerpath(): string {
40
- return this._controllerpath;
41
- }
42
-
43
- set controllerpath(value: string) {
44
- this._controllerpath = value;
45
- }
46
-
47
- init() {
48
- this.logProvider().level = log4js.levels.ALL;
49
- this.logProvider().configure(this._logConfig);
50
-
51
- /**
52
- * set request id
53
- */
54
- Object.defineProperty(BaseChyz.express.request, 'reqId', {
55
- configurable: true,
56
- enumerable: true,
57
- writable: true
58
- })
59
-
60
- Object.defineProperty(BaseChyz.express.request, 'user', {
61
- configurable: true,
62
- enumerable: true,
63
- writable: true
64
- })
65
-
66
- Object.defineProperty(BaseChyz.express.request, 'identity', {
67
- configurable: true,
68
- enumerable: true,
69
- writable: true
70
- })
71
-
72
-
73
- /**
74
- * server port setting
75
- */
76
- if (this.config.hasOwnProperty("port"))
77
- this.port = this.config.port;
78
-
79
- /**
80
- * controller path
81
- */
82
- if (this.config.controllerpath) {
83
- this.controllerpath = this.config.controllerpath
84
- }
85
-
86
- /**
87
- * Express Server
88
- */
89
- this.middleware()
90
-
91
- /**
92
- * Load Controller
93
- */
94
- this.loadController();
95
-
96
-
97
- }
98
-
99
- /**
100
- * Listen port number
101
- * Server port number get
102
- */
103
- get port(): number {
104
- return this._port;
105
- }
106
-
107
- /**
108
- * Listen port number
109
- * Server port number setting
110
- * @param value
111
- */
112
- set port(value: number) {
113
- this._port = value;
114
- }
115
-
116
-
117
- app(config: any = {}): BaseChyz {
118
-
119
- /**
120
- * Config set
121
- */
122
- this.config = config;
123
-
124
-
125
- let components = Utils.findKeyValue(config, "components")
126
- if (components) {
127
- for (const componentsKey in components) {
128
- let comp = components[componentsKey];
129
- BaseChyz.debug("Create Component ", componentsKey)
130
- BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
131
- BaseChyz.components[componentsKey]?.init();
132
- }
133
- }
134
-
135
-
136
- let middlewares = Utils.findKeyValue(config, "middlewares")
137
- if (middlewares) {
138
- for (const middlewareKey in middlewares) {
139
- let middleware1 = middlewares[middlewareKey];
140
- BaseChyz.debug("Create middlewares ", middlewareKey)
141
- BaseChyz.middlewares[middlewareKey] = middleware1;
142
- // BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
143
- }
144
- }
145
-
146
-
147
-
148
- this.init();
149
-
150
- return this;
151
- }
152
-
153
-
154
- public logProvider() {
155
- return log4js;
156
- }
157
-
158
- public getLogger() {
159
- return this.logProvider().getLogger(this.constructor.name);
160
- }
161
-
162
- static logs(...args: any[]) {
163
- return log4js.getLogger(this.name);
164
- }
165
-
166
- public static trace(...args: any[]) {
167
- BaseChyz.logs().fatal(...arguments)
168
- }
169
-
170
- public static debug(...args: any[]) {
171
- BaseChyz.logs().debug(...arguments)
172
- }
173
-
174
- public static info(...args: any[]) {
175
- BaseChyz.logs().info(...arguments)
176
- }
177
-
178
- public static warn(...args: any[]) {
179
- BaseChyz.logs().warn(...arguments)
180
- }
181
-
182
- public static error(...args: any[]) {
183
- BaseChyz.logs().error(...arguments)
184
- }
185
-
186
- public static fatal(...args: any[]) {
187
- BaseChyz.logs().fatal(...arguments)
188
- }
189
-
190
-
191
- public static warning(...args: any[]) {
192
- BaseChyz.logs().warn(...arguments)
193
- }
194
-
195
- public static t(text: string) {
196
- return text;
197
- }
198
-
199
-
200
- public errorLogger(error: any, req: any, res: any, next: any) { // for logging errors
201
- BaseChyz.error(error)
202
- next(error) // forward to next middleware
203
- }
204
-
205
- public errorResponder(error: any, req: any, res: any, next: any) { // responding to client
206
- if (error.type == 'redirect')
207
- res.redirect('/error')
208
- else if (error.type == 'time-out') // arbitrary condition check
209
- res.status(408).json(error)
210
- else
211
- next(error) // forwarding exceptional case to fail-safe middleware
212
- }
213
-
214
-
215
- public errorHandler(err: any, req: any, res: any, next: any) {
216
- if (res.headersSent) {
217
- return next(err)
218
- }
219
- res.status(500)
220
- res.json('error', {error: err})
221
- }
222
-
223
- public static getComponent(key: any) {
224
- return BaseChyz.components[key] ?? null
225
- }
226
-
227
-
228
- public static getMiddlewares(key: any) {
229
- return BaseChyz.middlewares[key] ?? null
230
- }
231
-
232
-
233
- /**
234
- * load contoller
235
- */
236
- async loadController() {
237
- let articlesEndpoints: string[] = [];
238
- fs.readdirSync(`${this._controllerpath}/`).forEach((file: string) => {
239
- let controller = require(`${this._controllerpath}/${file}`);
240
-
241
- // This is our instantiated class
242
- const instance: Controller = new controller();
243
-
244
- BaseChyz.controllers.push(instance);
245
-
246
- // The prefix saved to our controller
247
- // @ts-ignore
248
- const prefix = Reflect.getMetadata('prefix', controller);
249
- // Our `routes` array containing all our routes for this controller
250
- // @ts-ignore
251
- const routes: Array<RouteDefinition> = Reflect.getMetadata('routes', controller);
252
- BaseChyz.logs().debug("Controller load ", controller.name, `(${prefix})`)
253
-
254
- if (routes) {
255
- routes.forEach(route => {
256
-
257
- let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
258
- route.id = actionId;
259
- BaseChyz.logs().debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`))
260
-
261
- BaseChyz.express[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`),
262
- async (req: Request, res: Response, next: NextFunction) => {
263
- try {
264
- BaseChyz.debug(`Call Request id ${instance.id}`)
265
- await instance.beforeAction(route, req, res)
266
- next()
267
- } catch (e) {
268
- BaseChyz.error(e);
269
-
270
- res.status(e.statusCode || 500)
271
- res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
272
- // next(e)
273
- }
274
-
275
- },
276
- async (req: Request, res: Response, next: NextFunction) => {
277
- try {
278
- // @ts-ignore
279
- BaseChyz.debug("Request ID ", req.reqId)
280
- // @ts-ignore
281
- await instance[route.methodName](req, res, next);
282
- instance.afterAction(route, req, res);
283
- } catch (e) {
284
- if (e instanceof Error) {
285
- BaseChyz.error(e)
286
-
287
- // @ts-ignore
288
- res.status(e.statusCode || 500)
289
- // @ts-ignore
290
- res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
291
- }else{
292
- res.json(e )
293
- }
294
- }
295
- })
296
-
297
-
298
- });
299
- }
300
- })
301
- }
302
-
303
- public middleware() {
304
-
305
- BaseChyz.express.use(bodyParser.json())
306
- BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
307
- BaseChyz.express.use(methodOverride());
308
- BaseChyz.express.use(methodOverride());
309
-
310
-
311
-
312
- // CORS
313
- BaseChyz.express.use(function (req: any, res: Response, next: any) {
314
- // @ts-ignore
315
- req.reqId = Utils.uniqueId("chyzzzz_")
316
- res.setHeader('Content-Type', 'application/json');
317
- res.setHeader("Access-Control-Allow-Origin", "*");
318
- res.setHeader("Access-Control-Allow-Credentials", "true");
319
- res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
320
- 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");
321
- next();
322
- });
323
-
324
- //Middlewares
325
- for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
326
- if (!Utils.isFunction(middleware1)) {
327
- let keycloak = BaseChyz.middlewares[middleware1].keycloak;
328
- BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
329
- } else {
330
- BaseChyz.express.use(BaseChyz.middlewares[middleware1]);
331
- }
332
-
333
- }
334
-
335
-
336
- BaseChyz.express.use(this.errorResponder)
337
- BaseChyz.express.use(this.errorHandler)
338
- }
339
-
340
-
341
- public Start() {
342
-
343
- BaseChyz.info("Express Server Starting")
344
- BaseChyz.express.listen(this._port, () => {
345
- BaseChyz.info("Express Server Start ")
346
- BaseChyz.info(`Liten Port ${this._port}`)
347
- BaseChyz.info(`http://localhost:${this._port}`)
348
- BaseChyz.info(`http://${ip.address()}:${this._port}`)
349
- })
350
- return this;
351
- }
352
-
353
-
354
- }
355
-
356
-
357
- process.on('uncaughtException', err => {
358
- BaseChyz.error('There was an uncaught error', err)
359
- process.exit(1) //mandatory (as per the Node.js docs)
360
- })
361
-
package/Chyz.ts DELETED
@@ -1,11 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- import BaseChyz from "./BaseChyz";
9
- const Chyz = new BaseChyz();
10
-
11
- export default Chyz;