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.
Files changed (201) 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}/CWebController.js +0 -0
  14. package/{dist/base → base}/CWebController.js.map +0 -0
  15. package/{dist/base → base}/Component.js +0 -0
  16. package/{dist/base → base}/Component.js.map +0 -0
  17. package/{dist/base → base}/Configurable.js +0 -0
  18. package/{dist/base → base}/Configurable.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 -1
  58. package/filters/AccessControl.js.map +1 -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 +1 -1
  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 +2 -3
  72. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +1 -1
  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} +3 -0
  80. package/{dist/index.js.map → index.js.map} +1 -1
  81. package/log/config/log4js.json +1 -1
  82. package/{dist/model → model}/RouteDefinition.js +0 -0
  83. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  84. package/package.json +2 -2
  85. package/{dist/rbac → rbac}/AuthAssignment.js +0 -0
  86. package/{dist/rbac → rbac}/AuthAssignment.js.map +0 -0
  87. package/{dist/rbac → rbac}/AuthItem.js +0 -0
  88. package/{dist/rbac → rbac}/AuthItem.js.map +0 -0
  89. package/{dist/rbac → rbac}/AuthItemChild.js +0 -0
  90. package/{dist/rbac → rbac}/AuthItemChild.js.map +0 -0
  91. package/{dist/rbac → rbac}/AuthManager.js +0 -0
  92. package/{dist/rbac → rbac}/AuthManager.js.map +0 -0
  93. package/{dist/requiments → requiments}/Glob.js +0 -0
  94. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  95. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  96. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  97. package/{dist/requiments → requiments}/Utils.js +0 -0
  98. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  99. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  100. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  101. package/{dist/validators → validators}/CompareValidator.js +0 -0
  102. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  103. package/{dist/validators → validators}/DateValidator.js +0 -0
  104. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  105. package/{dist/validators → validators}/EmailValidator.js +0 -0
  106. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  107. package/{dist/validators → validators}/Validator.js +0 -0
  108. package/{dist/validators → validators}/Validator.js.map +0 -0
  109. package/{dist/web → web}/IdentityInterface.js +0 -0
  110. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  111. package/{dist/web → web}/WebUser.js +0 -0
  112. package/{dist/web → web}/WebUser.js.map +0 -0
  113. package/BaseChyz.ts +0 -454
  114. package/Chyz.ts +0 -11
  115. package/Doc/Moel kullanma.md +0 -13
  116. package/Examples/Controllers/ApiController.ts +0 -140
  117. package/Examples/Controllers/BasicApiController.ts +0 -121
  118. package/Examples/Controllers/KeyCloakController.ts +0 -100
  119. package/Examples/Controllers/PublicController.ts +0 -42
  120. package/Examples/Controllers/SiteController.ts +0 -149
  121. package/Examples/Models/AuthAssignment.ts +0 -50
  122. package/Examples/Models/AuthItem.ts +0 -59
  123. package/Examples/Models/AuthItemChild.ts +0 -49
  124. package/Examples/Models/Categories.ts +0 -51
  125. package/Examples/Models/Customer.ts +0 -115
  126. package/Examples/Models/KeycloakUser.ts +0 -70
  127. package/Examples/Models/Order.ts +0 -64
  128. package/Examples/Models/OrderItem.ts +0 -27
  129. package/Examples/Models/ProductModels.ts +0 -49
  130. package/Examples/Models/ProductToCategories.ts +0 -46
  131. package/Examples/Models/Products.ts +0 -50
  132. package/Examples/Models/Stocks.ts +0 -60
  133. package/Examples/Models/User.ts +0 -128
  134. package/Examples/Models/UserPermission.ts +0 -37
  135. package/Examples/Models/index.ts +0 -19
  136. package/Examples/index-keycloack.ts +0 -78
  137. package/Examples/index.ts +0 -60
  138. package/Examples/keycloak.json +0 -7
  139. package/Examples/log/access.log +0 -0
  140. package/Examples/log/app.log +0 -20601
  141. package/Examples/log/errors.log +0 -2120
  142. package/Examples/package.json +0 -49
  143. package/Examples/tsconfig.json +0 -21
  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/CWebController.ts +0 -84
  149. package/base/Component.ts +0 -66
  150. package/base/Configurable.ts +0 -10
  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/filters/AccessControl.js.map +0 -1
  171. package/dist/log/config/log4js.json +0 -55
  172. package/dist/package.json +0 -59
  173. package/filters/AccessControl.ts +0 -77
  174. package/filters/AccessRule.ts +0 -182
  175. package/filters/auth/AuthInterface.ts +0 -34
  176. package/filters/auth/AuthMethod.ts +0 -88
  177. package/filters/auth/HttpBasicAuth.ts +0 -75
  178. package/filters/auth/HttpBearerAuth.ts +0 -31
  179. package/filters/auth/HttpHeaderAuth.ts +0 -53
  180. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  181. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  182. package/filters/auth/index.ts +0 -4
  183. package/filters/index.ts +0 -2
  184. package/index.ts +0 -16
  185. package/model/RouteDefinition.ts +0 -18
  186. package/package-lock.json +0 -5259
  187. package/rbac/AuthAssignment.ts +0 -50
  188. package/rbac/AuthItem.ts +0 -57
  189. package/rbac/AuthItemChild.ts +0 -50
  190. package/rbac/AuthManager.ts +0 -398
  191. package/requiments/Glob.ts +0 -9
  192. package/requiments/ReflectUtil.ts +0 -26
  193. package/requiments/Utils.ts +0 -63
  194. package/tsconfig.json +0 -18
  195. package/validators/BooleanValidator.ts +0 -0
  196. package/validators/CompareValidator.ts +0 -0
  197. package/validators/DateValidator.ts +0 -0
  198. package/validators/EmailValidator.ts +0 -0
  199. package/validators/Validator.ts +0 -27
  200. package/web/IdentityInterface.ts +0 -68
  201. 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
@@ -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 {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