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
@@ -1,49 +0,0 @@
1
- {
2
- "name": "edis-manager-node",
3
- "version": "1.0.0",
4
- "description": "Entranet ve Erken Deprem Bildirim Sistemi (EDİS) entegrasyonu",
5
- "main": "index.js",
6
- "scripts": {
7
- "dev": "nodemon -x ts-node index.ts",
8
- "debug": "ts-node index.ts",
9
- "test": "echo \"Error: no test specified\" && exit 1"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/cihan53/edis-manager-node.git"
14
- },
15
- "author": "",
16
- "license": "MIT",
17
- "bugs": {
18
- "url": "https://github.com/cihan53/edis-manager-node/issues"
19
- },
20
- "homepage": "https://github.com/cihan53/edis-manager-node#readme",
21
- "dependencies": {
22
- "babel-plugin-transform-decorators-legacy": "^1.3.5",
23
- "bcrypt": "^5.0.1",
24
- "body-parser": "^1.19.0",
25
- "dotenv-flow": "^3.2.0",
26
- "express": "^4.17.1",
27
- "glob": "^7.1.7",
28
- "ioredis": "^4.28.5",
29
- "jsonwebtoken": "^8.5.1",
30
- "keycloak-connect": "^15.0.2",
31
- "lodash": "^4.17.21",
32
- "log4js": "^6.3.0",
33
- "method-override": "^3.0.0",
34
- "passport": "^0.4.1",
35
- "pg": "^8.7.1",
36
- "pg-hstore": "^2.3.4",
37
- "reflect-metadata": "^0.1.13",
38
- "sequelize": "^6.6.5",
39
- "sequelize-transparent-cache": "^2.3.0",
40
- "sequelize-transparent-cache-ioredis": "^2.3.0"
41
- },
42
- "devDependencies": {
43
- "@types/express": "^4.17.13",
44
- "@types/node": "^16.4.13",
45
- "nodemon": "^2.0.12",
46
- "ts-node": "^10.2.0",
47
- "typescript": "^4.3.5"
48
- }
49
- }
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "experimentalDecorators": true,
5
- "emitDecoratorMetadata": true,
6
- // "isolatedModules": true,
7
- "removeComments": true,
8
- // "esModuleInterop": true,
9
- "allowSyntheticDefaultImports": true,
10
- "moduleResolution": "node"
11
- },
12
- "exclude": [
13
- "node_modules"
14
- ],
15
- "include": [
16
- "__tests__/**/*.ts",
17
- "Controllers/**/*.ts",
18
- "Models/**/*.ts",
19
- "environment.d.ts",
20
- ]
21
- }
package/README.md DELETED
@@ -1,521 +0,0 @@
1
- Hızlı şekilde microservis hazırlama için geliştirmeye başladım<br>
2
-
3
- Temel olarak yii2 php framework'ten örnekler alındı<br>
4
-
5
- Temel olarak basit bir Controller geliştirildi, ayrıca authentication geliştirildi.<br>
6
-
7
- Klasör Yapısı<br>
8
- *---Controllers <br>
9
- *---Models<br>
10
- *---Log<br>
11
- index.ts<br>
12
-
13
- `##Başlangıç<br>
14
- yarn start
15
-
16
- ## index.ts alanlar düzenlenmeli.
17
-
18
- ```typescript
19
-
20
- import {BaseChyz} from "../index";
21
-
22
- require('dotenv-flow').config();
23
- import Chyz ,{ DbConnection, BaseChyz} from "chyz/dist/";
24
- import {AuthManager} from "chyz/dist/rbac/AuthManager"
25
- import {WebUser} from "chyz/dist/web/WebUser";
26
- import {User as Identity} from "./Models/User";
27
-
28
-
29
- let config = {
30
- port: process.env.PORT || 8870,
31
- controllerpath: "Examples\\Controllers",
32
- components: {
33
- authManager: {
34
- class: AuthManager,
35
- },
36
- db: {
37
- class: DbConnection,
38
- database: process.env.DBDATABASE,
39
- username: process.env.DBUSER,
40
- password: process.env.DBPASS,
41
- options: {
42
- host: process.env.DBHOST,
43
- dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
44
- // disable logging; default: console.log
45
- logging: (msg: any) => BaseChyz.debug(msg)
46
- }
47
- },
48
- user: {
49
- 'class': WebUser,
50
- 'identityClass': User
51
- }
52
- }
53
-
54
- }
55
- Chyz.app(config).Start();
56
- ```
57
-
58
- ##Controller
59
- Basit şekilde kontroller oluşturulabilir.
60
- ```typescript
61
- /*
62
- *
63
- * Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
64
- * Author: Cihan Ozturk
65
- * E-mail: cihan@chy.com.tr
66
- * Github:https://github.com/cihan53/
67
- *
68
- */
69
-
70
- import {AccessControl, BaseChyz, JwtHttpBearerAuth, ModelManager, Request, Response,} from "chyz/dist";
71
- import {ForbiddenHttpException, Model, NotFoundHttpException, ValidationHttpException} from "chyz/dist/base";
72
-
73
- import Utils from 'chyz/dist/requiments/Utils';
74
- import {controller, get, post} from "chyz/dist/decorator";
75
- import {Controller} from "chyz/dist/base/Controller";
76
- import * as Util from "util";
77
- import {uid} from "uid";
78
-
79
- import {User} from "../Models/User";
80
- import {AuthManager} from "../Lib/AuthManager";
81
- import {CategoriesClass} from "../Models/Categories";
82
-
83
-
84
- const keygen = require('ssh-keygen');
85
- const os = require('os');
86
- const bcrypt = require('bcrypt');
87
- const JsonWebToken = require("jsonwebtoken");
88
- const {Op} = require("sequelize");
89
-
90
-
91
- @controller("/api")
92
- class ApiController extends Controller {
93
-
94
- public myCheck(token) {
95
- console.log("myyyyyyyyyyyyyyyyyyyyy")
96
- }
97
-
98
- public behaviors(): any[] {
99
-
100
- return [{
101
- 'authenticator': {
102
- "class": JwtHttpBearerAuth,
103
- // "auth": this.myCheck
104
- },
105
- 'access': {
106
- 'class': AccessControl,
107
- 'only': ['order/list' ],
108
- 'rules': [
109
-
110
- {
111
- 'allow': true,
112
- 'actions': ['order/list' ],
113
- 'roles': ['editor'],
114
- }
115
- ]
116
- }
117
- }]
118
- }
119
-
120
- @get("/")
121
- Index(req: Request, res: Response) {
122
-
123
- BaseChyz.logs().info("Site Controller Burası", this.id)
124
- return res.json({message: "index sayfası"})
125
- }
126
-
127
- @post("orderCreate")
128
- async Login(req: Request, res: Response) {
129
- let data = req.body;
130
- data.Customer.status = "true";
131
-
132
- //Customer Model Create
133
- let customer = ModelManager.Customer.save();
134
- //Order Model Create
135
- let order = ModelManager.Order;
136
-
137
-
138
- let transaction
139
- try {
140
- // get transaction
141
- transaction = await BaseChyz.getComponent("db").transaction();
142
- customer.load(data, "Customer");//load customer data
143
- let cus: any = await customer.save({}, {transaction});
144
-
145
- if (!cus) {
146
- throw new ValidationHttpException(customer.errors);
147
- }
148
-
149
- data.Order.customer_id = cus.id;
150
-
151
- order.load(data, "Order");
152
- let res1 = await order.save({}, {transaction});
153
- if (!res1) {
154
- throw new ValidationHttpException(order.errors);
155
- }
156
-
157
- // commit
158
- await transaction.commit();
159
-
160
- } catch (e) {
161
- if (transaction) {
162
- await transaction.rollback();
163
- BaseChyz.warn("Rollback transaction")
164
- }
165
-
166
- if (e instanceof ValidationHttpException)
167
- throw new ValidationHttpException(e.message)
168
- else
169
- throw new ForbiddenHttpException(e.message)
170
- }
171
- return res.send("Post Controller")
172
- }
173
-
174
-
175
- @get("order/list")
176
- async listOrder(req: Request, res: Response) {
177
- const {Products}: { Products: ProductsClass } = ModelManager;
178
- let product = await Products.findAll( );
179
- return res.json(product)
180
-
181
- }
182
-
183
- @get("categories")
184
- async Categories(req: Request, res: Response) {
185
- let product = await ModelManager.Categories.findAll({
186
- include: [
187
- {
188
- model: ModelManager.Products.model(),
189
- }
190
- ]
191
- });
192
- return res.json(product)
193
-
194
- }
195
-
196
- error(req: Request, res: Response) {
197
- BaseChyz.logs().info("Error Sayfası")
198
- return res.send("Post Controller")
199
- }
200
- }
201
-
202
- module.exports = ApiController
203
-
204
- ```
205
-
206
-
207
- ## Create Model
208
-
209
- Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
210
-
211
- Model adı "**Class**" şeklinde bitmeli.
212
-
213
- Örnek = "ModelName**Class**"
214
-
215
- ```typescript
216
- import {Model, DataTypes} from "chyz/base/Model";
217
-
218
- export class CustomerCLass extends Model {
219
- public tableName() {
220
- return 'customer';
221
- }
222
-
223
- public attributes() {
224
- return {
225
- username: {
226
- type: DataTypes.STRING,
227
- allowNull: false,
228
- validate: {
229
- notEmpty: true,
230
- len: [4, 255],
231
- }
232
- },
233
- email: {
234
- type: DataTypes.STRING,
235
- validate: {
236
- isEmail: true
237
- }
238
- },
239
- firstname: {
240
- type: DataTypes.STRING,
241
- allowNull: false
242
- },
243
- lastname: {
244
- type: DataTypes.STRING,
245
- },
246
- }
247
- }
248
-
249
- }
250
-
251
-
252
- ```
253
- ````typescript
254
-
255
- export class ProductsClass extends Model {
256
- [x: string]: any;
257
-
258
- tableName() {
259
- return 'products';
260
- }
261
-
262
- attributes() {
263
- return {
264
- // Model attributes are defined here
265
- title: {
266
- type: DataTypes.STRING,
267
- allowNull: false
268
- },
269
- model_id: {
270
- type: DataTypes.INTEGER,
271
- allowNull: false
272
- },
273
- properties: {
274
- type: DataTypes.STRING,
275
- allowNull: false
276
- }
277
-
278
- }
279
- }
280
-
281
- relations(): Relation[] {
282
- return [
283
- {
284
- type: "hasOne",
285
- foreignKey: "id",
286
- sourceKey: "customer_id",
287
- model: Customer.model()
288
- }
289
- ]
290
- }
291
- }
292
-
293
- /**
294
- *
295
- */
296
- export class CategoriesClass extends Model {
297
- [x: string]: any;
298
-
299
- alias() {
300
- return "c"
301
- }
302
-
303
- tableName() {
304
- return 'categories';
305
- }
306
- attributes() {
307
- return {
308
- // Model attributes are defined here
309
- title: {
310
- type: DataTypes.STRING,
311
- allowNull: false
312
- },
313
- properties: {
314
- type: DataTypes.STRING,
315
- allowNull: false
316
- }
317
-
318
- }
319
- }
320
- relations(): Relation[] {
321
- return [
322
- {
323
- type: "belongsToMany",
324
- foreignKey: "category_id",
325
- sourceKey: "id",
326
- as: 'product',
327
- model: ModelManager.Products.model(),
328
- through: ModelManager.ProductToCategories.model()
329
- }
330
- ]
331
- }
332
-
333
- }
334
-
335
-
336
- ````
337
-
338
- ## Http POST ve GET verilerini model'e yükleme
339
-
340
- ````typescript
341
-
342
- /**
343
- * post data
344
- * {
345
- * "Customer":{
346
- * "firstname":"cihan",
347
- * "lastname":"ozturk"
348
- * ....
349
- * }
350
- * }
351
- * @type {Customer}
352
- */
353
- import { ModelManager} from "chyz/dist";
354
- import {Customer} from "./Customer";
355
-
356
- //Customer Model Create
357
- let customer: Customer = ModelManager.Customer;
358
- customer.load(req.body, "Customer");//load customer data
359
- let cus: any = await customer.save();
360
-
361
-
362
- ````
363
- ## Transaction
364
- Transaction oluşturma
365
-
366
-
367
- ```typescript
368
- let transaction
369
- try {
370
- // get transaction
371
- transaction = await BaseChyz.getComponent("db").transaction();
372
- //Customer Model Create
373
- let customer: Customer = ModelManager.Customer;
374
- customer.load(data, "Customer");//load customer data
375
- let cus: any = await customer.save({}, {transaction});
376
- if (!cus) {
377
- throw new ValidationHttpException(customer.errors);
378
- }
379
- } catch (e) {
380
- if (transaction) {
381
- await transaction.rollback();
382
- BaseChyz.warn("Rollback transaction");
383
- }
384
-
385
- }
386
- ```
387
-
388
- ## Yetkilendirme için kullanıcı modeli
389
-
390
- ```typescript
391
- /*
392
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
393
- * Author: Cihan Ozturk
394
- * E-mail: cihan@chy.com.tr
395
- * Github:https://github.com/cihan53/
396
- */
397
- import {IdentityInterface} from "chyz/web/IdentityInterface";
398
- // @ts-ignore
399
- import {DataTypes} from "chyz/base";
400
- import {Model} from "chyz/base";
401
- import BaseChyz from "chyz/BaseChyz";
402
-
403
- const bcrypt = require('bcrypt');
404
- const JsonWebToken = require("jsonwebtoken");
405
-
406
- export class User extends Model implements IdentityInterface {
407
- public tableName() {
408
- return 'users';
409
- }
410
- findIdentity(id: number) {
411
- throw new Error("Method not implemented.");
412
- }
413
-
414
- getId(): number {
415
- throw new Error("Method not implemented.");
416
- }
417
-
418
- getAuthKey(): string {
419
- throw new Error("Method not implemented.");
420
- }
421
-
422
- validateAuthKey(authKey: string): boolean {
423
- throw new Error("Method not implemented.");
424
- }
425
-
426
- /**
427
- * Returns auth manager associated with the user component.
428
- *
429
- * By default this is the `authManager` application component.
430
- * You may override this method to return a different auth manager instance if needed.
431
- */
432
- protected getAuthManager() {
433
- return BaseChyz.getComponent("authManager");
434
- }
435
-
436
- /**
437
- * Returns the access checker used for checking access.
438
- * @return CheckAccessInterface
439
- */
440
- protected getAccessChecker() {
441
- return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
442
- }
443
-
444
- /**
445
- *
446
- * @param permissionName
447
- * @param params
448
- * @param allowCaching
449
- */
450
- public async can(permissionName, params: any[] = [], allowCaching: boolean = true) {
451
- let accessChecker;
452
- if ((accessChecker = this.getAccessChecker()) === null) {
453
- return false;
454
- }
455
-
456
- let access = await accessChecker.checkAccess(this.getId(), permissionName, params);
457
- this._access[permissionName] = access;
458
- if (allowCaching && Utils.isEmpty(params)) {
459
-
460
- }
461
- return access;
462
- }
463
-
464
- public attributes() {
465
- return {
466
- // Model attributes are defined here
467
- username: {
468
- type: DataTypes.STRING,
469
- allowNull: false
470
- },
471
- password: {
472
- type: DataTypes.STRING,
473
- allowNull: false
474
- },
475
- user_role: {
476
- type: DataTypes.STRING,
477
- allowNull: false
478
- },
479
- salt_text: {
480
- type: DataTypes.STRING
481
- // allowNull defaults to true
482
- }
483
- }
484
- }
485
-
486
- async findIdentityByAccessToken(token, type) {
487
-
488
-
489
- let decoded = JsonWebToken.decode(token, {complete: true})
490
- if (!decoded.payload.user) {
491
- return null;
492
- }
493
- let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
494
- if(identity){
495
- BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
496
- try {
497
- JsonWebToken.verify(token, identity.salt_text);
498
- this.setIdentity(identity);
499
- BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
500
- return this;
501
- } catch(err) {
502
- if (err.name == "TokenExpiredError")
503
- BaseChyz.debug("Find Identity By AccessToken: Token Expired")
504
- else
505
- BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
506
- return null;
507
- }
508
- }
509
- BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
510
- return null;
511
- }
512
-
513
-
514
- }
515
-
516
-
517
-
518
-
519
-
520
-
521
- ```
@@ -1,71 +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
- // @ts-ignore
8
- import {NextFunction, Request, Response} from "express";
9
- import Utils from "../requiments/Utils";
10
- import {Behavior} from "./Behavior";
11
-
12
- export class ActionFilter extends Behavior {
13
-
14
- public only: any;
15
-
16
- /**
17
- * @var array list of action IDs that this filter should not apply to.
18
- * @see only
19
- */
20
- public except = [];
21
-
22
-
23
- public init() {
24
-
25
- }
26
-
27
- public async beforeFilter(route: any, req: Request, res: Response) {
28
- if (!this.isActive(route)) {
29
- return;
30
- }
31
-
32
- await this.beforeAction(route, req, res)
33
- }
34
-
35
- protected isActive(action: any) {
36
- let id = action.id;
37
- let onlyMatch: boolean = false;
38
- let exceptMatch: boolean = false;
39
- if (Utils.isEmpty(this.only)) {
40
- onlyMatch = true;
41
- } else {
42
- onlyMatch = false;
43
- for (const onlyKey of this.only) {
44
- if (Utils.matchWildcard(action.id, onlyKey)) {
45
- onlyMatch = true;
46
- break;
47
- }
48
- }
49
- }
50
-
51
- for (const exceptKey in this.except) {
52
- let pattern = this.except[exceptKey];
53
- let match = id.match(pattern)
54
- if (match && match.length > 0) {
55
- exceptMatch = true;
56
- }
57
- }
58
-
59
- return !exceptMatch && onlyMatch;
60
- }
61
-
62
- /**
63
- * This method is invoked right before an action is to be executed (after all possible filters.)
64
- * You may override this method to do last-minute preparation for the action.
65
- * @param Action $action the action to be executed.
66
- * @return bool whether the action should continue to be executed.
67
- */
68
- public async beforeAction(route: any, req: Request, res: Response) {
69
- return true;
70
- }
71
- }
package/base/BaseError.ts DELETED
@@ -1,28 +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 Utils from "../requiments/Utils";
9
-
10
- export class BaseError extends Error {
11
- private statusCode: number;
12
-
13
- constructor(message: string,statusCode=500) {
14
- super(message);
15
- this.message= Utils.isString(message)?message: JSON.stringify(message);
16
- this.name = this.constructor.name // good practice
17
- this.statusCode = statusCode // error code for responding to client
18
- //Error.captureStackTrace(this)
19
- }
20
-
21
- toString(){
22
- return `${this.name}[${this.statusCode}] ${this.message}`
23
- }
24
- toJSON(){
25
- return {code: this?.statusCode, name: this.name, message: this.message}
26
- }
27
- }
28
-
@@ -1,19 +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 {Configurable} from "./Configurable";
9
- import BaseChyz from "../BaseChyz";
10
-
11
- export class BaseObject implements Configurable {
12
-
13
-
14
- public init() {
15
-
16
- BaseChyz.debug("BaseObject init.....",)
17
-
18
- }
19
- }