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