@ug.software/opposer 3.0.10 → 3.0.11

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 (227) hide show
  1. package/lib/bin/commands/build.js +15 -28
  2. package/lib/bin/commands/init.js +27 -30
  3. package/lib/esm/server/security/jwt/index.d.ts +1 -1
  4. package/lib/esm/server/security/jwt/index.js +21 -29
  5. package/lib/esm/system/index.d.ts +1 -1
  6. package/lib/esm/system/index.js +42 -55
  7. package/package.json +3 -3
  8. package/lib/cjs/examples/full-app/index.d.ts +0 -1
  9. package/lib/cjs/examples/full-app/index.js +0 -102
  10. package/lib/cjs/examples/full-app/models/author.d.ts +0 -7
  11. package/lib/cjs/examples/full-app/models/author.js +0 -42
  12. package/lib/cjs/examples/full-app/models/book.d.ts +0 -9
  13. package/lib/cjs/examples/full-app/models/book.js +0 -51
  14. package/lib/cjs/examples/full-app/models/category.d.ts +0 -4
  15. package/lib/cjs/examples/full-app/models/category.js +0 -26
  16. package/lib/cjs/examples/full-app/schedules/catalog-refresh.d.ts +0 -28
  17. package/lib/cjs/examples/full-app/schedules/catalog-refresh.js +0 -149
  18. package/lib/cjs/examples/full-app/schedules/inventory-sync.d.ts +0 -12
  19. package/lib/cjs/examples/full-app/schedules/inventory-sync.js +0 -61
  20. package/lib/cjs/examples/full-app/schedules/library-alerts.d.ts +0 -11
  21. package/lib/cjs/examples/full-app/schedules/library-alerts.js +0 -55
  22. package/lib/cjs/examples/minimal/src/handlers/book.d.ts +0 -11
  23. package/lib/cjs/examples/minimal/src/handlers/book.js +0 -51
  24. package/lib/cjs/examples/minimal/src/index.d.ts +0 -1
  25. package/lib/cjs/examples/minimal/src/index.js +0 -14
  26. package/lib/cjs/examples/minimal/src/models/books.d.ts +0 -4
  27. package/lib/cjs/examples/minimal/src/models/books.js +0 -26
  28. package/lib/cjs/examples/orm/models/permission.d.ts +0 -6
  29. package/lib/cjs/examples/orm/models/permission.js +0 -38
  30. package/lib/cjs/examples/orm/models/profile.d.ts +0 -7
  31. package/lib/cjs/examples/orm/models/profile.js +0 -42
  32. package/lib/cjs/examples/orm/models/user.d.ts +0 -11
  33. package/lib/cjs/examples/orm/models/user.js +0 -70
  34. package/lib/cjs/examples/orm/mysql/index.d.ts +0 -1
  35. package/lib/cjs/examples/orm/mysql/index.js +0 -44
  36. package/lib/cjs/examples/orm/postgres/index.d.ts +0 -1
  37. package/lib/cjs/examples/orm/postgres/index.js +0 -40
  38. package/lib/cjs/examples/orm/sqlite/index.d.ts +0 -1
  39. package/lib/cjs/examples/orm/sqlite/index.js +0 -41
  40. package/lib/cjs/index.d.ts +0 -2
  41. package/lib/cjs/index.js +0 -23
  42. package/lib/cjs/interfaces/controller.d.ts +0 -109
  43. package/lib/cjs/interfaces/controller.js +0 -2
  44. package/lib/cjs/interfaces/field.d.ts +0 -23
  45. package/lib/cjs/interfaces/field.js +0 -2
  46. package/lib/cjs/interfaces/handler.d.ts +0 -18
  47. package/lib/cjs/interfaces/handler.js +0 -2
  48. package/lib/cjs/interfaces/jwt.d.ts +0 -21
  49. package/lib/cjs/interfaces/jwt.js +0 -2
  50. package/lib/cjs/interfaces/model.d.ts +0 -9
  51. package/lib/cjs/interfaces/model.js +0 -2
  52. package/lib/cjs/interfaces/request.d.ts +0 -13
  53. package/lib/cjs/interfaces/request.js +0 -2
  54. package/lib/cjs/interfaces/schema.d.ts +0 -9
  55. package/lib/cjs/interfaces/schema.js +0 -2
  56. package/lib/cjs/interfaces/security.d.ts +0 -32
  57. package/lib/cjs/interfaces/security.js +0 -2
  58. package/lib/cjs/interfaces/server.d.ts +0 -37
  59. package/lib/cjs/interfaces/server.js +0 -2
  60. package/lib/cjs/interfaces/system.d.ts +0 -41
  61. package/lib/cjs/interfaces/system.js +0 -2
  62. package/lib/cjs/orm/decorators/index.d.ts +0 -33
  63. package/lib/cjs/orm/decorators/index.js +0 -131
  64. package/lib/cjs/orm/driver/mysql.d.ts +0 -14
  65. package/lib/cjs/orm/driver/mysql.js +0 -103
  66. package/lib/cjs/orm/driver/postgres.d.ts +0 -14
  67. package/lib/cjs/orm/driver/postgres.js +0 -105
  68. package/lib/cjs/orm/driver/sqlite.d.ts +0 -14
  69. package/lib/cjs/orm/driver/sqlite.js +0 -143
  70. package/lib/cjs/orm/index.d.ts +0 -8
  71. package/lib/cjs/orm/index.js +0 -28
  72. package/lib/cjs/orm/metadata.d.ts +0 -47
  73. package/lib/cjs/orm/metadata.js +0 -47
  74. package/lib/cjs/orm/opposer.d.ts +0 -30
  75. package/lib/cjs/orm/opposer.js +0 -33
  76. package/lib/cjs/orm/query-builder.d.ts +0 -32
  77. package/lib/cjs/orm/query-builder.js +0 -278
  78. package/lib/cjs/orm/repository.d.ts +0 -54
  79. package/lib/cjs/orm/repository.js +0 -325
  80. package/lib/cjs/orm/validation.d.ts +0 -44
  81. package/lib/cjs/orm/validation.js +0 -128
  82. package/lib/cjs/package.json +0 -3
  83. package/lib/cjs/persistent/cache/core-context.d.ts +0 -17
  84. package/lib/cjs/persistent/cache/core-context.js +0 -39
  85. package/lib/cjs/persistent/cache/global.d.ts +0 -18
  86. package/lib/cjs/persistent/cache/global.js +0 -22
  87. package/lib/cjs/persistent/cache/index.d.ts +0 -3
  88. package/lib/cjs/persistent/cache/index.js +0 -12
  89. package/lib/cjs/persistent/cache/session.d.ts +0 -19
  90. package/lib/cjs/persistent/cache/session.js +0 -39
  91. package/lib/cjs/persistent/cache/storage.d.ts +0 -14
  92. package/lib/cjs/persistent/cache/storage.js +0 -88
  93. package/lib/cjs/persistent/cache/store.d.ts +0 -16
  94. package/lib/cjs/persistent/cache/store.js +0 -112
  95. package/lib/cjs/persistent/context/index.d.ts +0 -3
  96. package/lib/cjs/persistent/context/index.js +0 -5
  97. package/lib/cjs/persistent/decorators/global.d.ts +0 -1
  98. package/lib/cjs/persistent/decorators/global.js +0 -25
  99. package/lib/cjs/persistent/decorators/session.d.ts +0 -1
  100. package/lib/cjs/persistent/decorators/session.js +0 -27
  101. package/lib/cjs/persistent/index.d.ts +0 -6
  102. package/lib/cjs/persistent/index.js +0 -18
  103. package/lib/cjs/persistent/interfaces/context.d.ts +0 -5
  104. package/lib/cjs/persistent/interfaces/context.js +0 -2
  105. package/lib/cjs/persistent/interfaces/system.d.ts +0 -47
  106. package/lib/cjs/persistent/interfaces/system.js +0 -29
  107. package/lib/cjs/persistent/system/index.d.ts +0 -7
  108. package/lib/cjs/persistent/system/index.js +0 -44
  109. package/lib/cjs/persistent/utils/memory.d.ts +0 -8
  110. package/lib/cjs/persistent/utils/memory.js +0 -44
  111. package/lib/cjs/persistent/utils/timer.d.ts +0 -14
  112. package/lib/cjs/persistent/utils/timer.js +0 -21
  113. package/lib/cjs/playground/build/client/assets/AddRounded-ByHfnsiW.js +0 -4
  114. package/lib/cjs/playground/build/client/assets/Button-DLrxHRm7.js +0 -1
  115. package/lib/cjs/playground/build/client/assets/Container-CgITmmbk.js +0 -1
  116. package/lib/cjs/playground/build/client/assets/Divider-B_Wx9srO.js +0 -1
  117. package/lib/cjs/playground/build/client/assets/List-juBjUmfP.js +0 -1
  118. package/lib/cjs/playground/build/client/assets/ListItemText-DgWZmgzc.js +0 -1
  119. package/lib/cjs/playground/build/client/assets/MenuItem-D_5SuVKQ.js +0 -1
  120. package/lib/cjs/playground/build/client/assets/Modal-BwXR_5Bh.js +0 -1
  121. package/lib/cjs/playground/build/client/assets/TableRow-B9hAmlnV.js +0 -2
  122. package/lib/cjs/playground/build/client/assets/TextField-UybdTIGB.js +0 -3
  123. package/lib/cjs/playground/build/client/assets/Tooltip-BGcUWUcF.js +0 -1
  124. package/lib/cjs/playground/build/client/assets/auth-CD1rXHzz.js +0 -1
  125. package/lib/cjs/playground/build/client/assets/auth-GyTIVKy5.js +0 -1
  126. package/lib/cjs/playground/build/client/assets/confirm-Dr0pbiV6.js +0 -1
  127. package/lib/cjs/playground/build/client/assets/dividerClasses-CIiqeEPO.js +0 -1
  128. package/lib/cjs/playground/build/client/assets/entry.client-D6FYz1yh.js +0 -13
  129. package/lib/cjs/playground/build/client/assets/index-CJ0wdt6Z.js +0 -1
  130. package/lib/cjs/playground/build/client/assets/index-CQc11yq_.js +0 -1153
  131. package/lib/cjs/playground/build/client/assets/index-Cr4I-4J2.js +0 -1
  132. package/lib/cjs/playground/build/client/assets/index-CtPqstFl.js +0 -26
  133. package/lib/cjs/playground/build/client/assets/index-Ct_NE85o.js +0 -1
  134. package/lib/cjs/playground/build/client/assets/index-D0I6xwmb.js +0 -1
  135. package/lib/cjs/playground/build/client/assets/index-DmDCpKb3.js +0 -1
  136. package/lib/cjs/playground/build/client/assets/index-DsSkAwyn.js +0 -1
  137. package/lib/cjs/playground/build/client/assets/index-_DMgWZ3Y.js +0 -1
  138. package/lib/cjs/playground/build/client/assets/listItemIconClasses-39Itzgzt.js +0 -1
  139. package/lib/cjs/playground/build/client/assets/listItemTextClasses-EQFLPLzt.js +0 -1
  140. package/lib/cjs/playground/build/client/assets/manifest-c06e9a7f.js +0 -1
  141. package/lib/cjs/playground/build/client/assets/mergeSlotProps-DptgQgAT.js +0 -1
  142. package/lib/cjs/playground/build/client/assets/playground-Hl52p9f5.js +0 -108
  143. package/lib/cjs/playground/build/client/assets/root-CQTBmuv8.js +0 -1
  144. package/lib/cjs/playground/build/client/assets/toast-CsAH5FIf.js +0 -1
  145. package/lib/cjs/playground/build/client/assets/use-request-BZNkzlTr.js +0 -1
  146. package/lib/cjs/playground/build/client/favicon.ico +0 -0
  147. package/lib/cjs/playground/build/client/index.html +0 -6
  148. package/lib/cjs/playground/index.d.ts +0 -2
  149. package/lib/cjs/playground/index.js +0 -135
  150. package/lib/cjs/scheduler/controllers/index.d.ts +0 -19
  151. package/lib/cjs/scheduler/controllers/index.js +0 -62
  152. package/lib/cjs/scheduler/decorators/index.d.ts +0 -9
  153. package/lib/cjs/scheduler/decorators/index.js +0 -21
  154. package/lib/cjs/scheduler/handlers/index.d.ts +0 -19
  155. package/lib/cjs/scheduler/handlers/index.js +0 -62
  156. package/lib/cjs/scheduler/index.d.ts +0 -24
  157. package/lib/cjs/scheduler/index.js +0 -110
  158. package/lib/cjs/scheduler/models/history.d.ts +0 -10
  159. package/lib/cjs/scheduler/models/history.js +0 -50
  160. package/lib/cjs/server/constants/index.d.ts +0 -78
  161. package/lib/cjs/server/constants/index.js +0 -372
  162. package/lib/cjs/server/context/index.d.ts +0 -17
  163. package/lib/cjs/server/context/index.js +0 -33
  164. package/lib/cjs/server/controller/index.d.ts +0 -3
  165. package/lib/cjs/server/controller/index.js +0 -217
  166. package/lib/cjs/server/controllers/index.d.ts +0 -5
  167. package/lib/cjs/server/controllers/index.js +0 -72
  168. package/lib/cjs/server/core/index.d.ts +0 -16
  169. package/lib/cjs/server/core/index.js +0 -110
  170. package/lib/cjs/server/core/middleware/body-parser.d.ts +0 -2
  171. package/lib/cjs/server/core/middleware/body-parser.js +0 -27
  172. package/lib/cjs/server/core/middleware/cors.d.ts +0 -4
  173. package/lib/cjs/server/core/middleware/cors.js +0 -32
  174. package/lib/cjs/server/core/middleware/logger.d.ts +0 -2
  175. package/lib/cjs/server/core/middleware/logger.js +0 -15
  176. package/lib/cjs/server/decorators/controller.d.ts +0 -3
  177. package/lib/cjs/server/decorators/controller.js +0 -14
  178. package/lib/cjs/server/decorators/field.d.ts +0 -2
  179. package/lib/cjs/server/decorators/field.js +0 -36
  180. package/lib/cjs/server/decorators/handler.d.ts +0 -3
  181. package/lib/cjs/server/decorators/handler.js +0 -14
  182. package/lib/cjs/server/decorators/index.d.ts +0 -7
  183. package/lib/cjs/server/decorators/index.js +0 -26
  184. package/lib/cjs/server/decorators/is-public-method.d.ts +0 -3
  185. package/lib/cjs/server/decorators/is-public-method.js +0 -16
  186. package/lib/cjs/server/decorators/is-public.d.ts +0 -3
  187. package/lib/cjs/server/decorators/is-public.js +0 -14
  188. package/lib/cjs/server/decorators/method.d.ts +0 -3
  189. package/lib/cjs/server/decorators/method.js +0 -16
  190. package/lib/cjs/server/decorators/payload.d.ts +0 -3
  191. package/lib/cjs/server/decorators/payload.js +0 -15
  192. package/lib/cjs/server/handlers/index.d.ts +0 -5
  193. package/lib/cjs/server/handlers/index.js +0 -72
  194. package/lib/cjs/server/helpers/index.d.ts +0 -17
  195. package/lib/cjs/server/helpers/index.js +0 -39
  196. package/lib/cjs/server/index.d.ts +0 -12
  197. package/lib/cjs/server/index.js +0 -176
  198. package/lib/cjs/server/security/controller/auth.d.ts +0 -76
  199. package/lib/cjs/server/security/controller/auth.js +0 -346
  200. package/lib/cjs/server/security/index.d.ts +0 -2
  201. package/lib/cjs/server/security/index.js +0 -10
  202. package/lib/cjs/server/security/jwt/index.d.ts +0 -23
  203. package/lib/cjs/server/security/jwt/index.js +0 -108
  204. package/lib/cjs/server/security/middleware/autorization.d.ts +0 -3
  205. package/lib/cjs/server/security/middleware/autorization.js +0 -46
  206. package/lib/cjs/server/security/middleware/permission.d.ts +0 -3
  207. package/lib/cjs/server/security/middleware/permission.js +0 -138
  208. package/lib/cjs/server/security/models/crp.d.ts +0 -8
  209. package/lib/cjs/server/security/models/crp.js +0 -42
  210. package/lib/cjs/server/security/models/ke.d.ts +0 -7
  211. package/lib/cjs/server/security/models/ke.js +0 -38
  212. package/lib/cjs/server/security/models/rl.d.ts +0 -9
  213. package/lib/cjs/server/security/models/rl.js +0 -50
  214. package/lib/cjs/server/security/models/se.d.ts +0 -11
  215. package/lib/cjs/server/security/models/se.js +0 -54
  216. package/lib/cjs/server/security/models/usr.d.ts +0 -14
  217. package/lib/cjs/server/security/models/usr.js +0 -82
  218. package/lib/cjs/server/services/delete.d.ts +0 -13
  219. package/lib/cjs/server/services/delete.js +0 -49
  220. package/lib/cjs/server/services/get.d.ts +0 -4
  221. package/lib/cjs/server/services/get.js +0 -145
  222. package/lib/cjs/server/services/insert.d.ts +0 -13
  223. package/lib/cjs/server/services/insert.js +0 -74
  224. package/lib/cjs/server/services/update.d.ts +0 -13
  225. package/lib/cjs/server/services/update.js +0 -60
  226. package/lib/cjs/system/index.d.ts +0 -13
  227. package/lib/cjs/system/index.js +0 -237
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- //@ts-ignore
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- const index_js_1 = __importDefault(require("../../../system/index.js"));
9
- const settings = index_js_1.default.getSettingsFile();
10
- const accessJwt = process.env.ACCESS_JWT
11
- ? process.env.ACCESS_JWT
12
- : settings.jwt.access;
13
- const refreshJwt = process.env.REFRESH_JWT
14
- ? process.env.REFRESH_JWT
15
- : settings.jwt.refresh;
16
- const recoverJwt = process.env.RECOVER_JWT
17
- ? process.env.RECOVER_JWT
18
- : settings.jwt.recover;
19
- async function access(token) {
20
- if (!accessJwt) {
21
- throw new Error("[jwt] - Don't finded token for access jwt, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
22
- }
23
- try {
24
- const user = jsonwebtoken_1.default.verify(token, accessJwt);
25
- return user;
26
- }
27
- catch (err) {
28
- var erro = err;
29
- if (erro.name === "TokenExpiredError") {
30
- return erro.message;
31
- }
32
- if (erro.name === "JsonWebTokenError") {
33
- return "Check your data and try again.";
34
- }
35
- }
36
- }
37
- async function refresh(token) {
38
- if (!refreshJwt) {
39
- throw new Error("[jwt] - Don't finded token for refresh jwt, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
40
- }
41
- try {
42
- const user = jsonwebtoken_1.default.verify(token, refreshJwt);
43
- return user;
44
- }
45
- catch (err) {
46
- var erro = err;
47
- if (erro.name === "TokenExpiredError") {
48
- return erro.message;
49
- }
50
- if (erro.name === "JsonWebTokenError") {
51
- return "Check your data and try again.";
52
- }
53
- }
54
- }
55
- async function sign({ exp, ...payload }) {
56
- if (!accessJwt) {
57
- throw new Error("[jwt] - Don't finded token secret, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
58
- }
59
- const token = jsonwebtoken_1.default.sign({ ...payload }, accessJwt, { expiresIn: "15m" });
60
- const refresh = jsonwebtoken_1.default.sign({ ...payload }, refreshJwt, {
61
- expiresIn: "15d",
62
- });
63
- return { token, refresh };
64
- }
65
- async function forget(payload) {
66
- if (!recoverJwt) {
67
- throw new Error("[jwt] - Don't finded token secret for recover password, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
68
- }
69
- const token = jsonwebtoken_1.default.sign(payload, accessJwt, { expiresIn: "5m" });
70
- return { token };
71
- }
72
- async function recover(token) {
73
- if (!recoverJwt) {
74
- throw new Error("[jwt] - Don't finded token secret for recover password, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
75
- }
76
- try {
77
- const user = jsonwebtoken_1.default.verify(token, recoverJwt);
78
- return user;
79
- }
80
- catch (err) {
81
- var erro = err;
82
- if (erro.name === "TokenExpiredError") {
83
- return erro.message;
84
- }
85
- if (erro.name === "JsonWebTokenError") {
86
- return "Check your data and try again.";
87
- }
88
- }
89
- }
90
- async function verify(token) {
91
- try {
92
- const secret = process.env.ACCESS_JWT
93
- ? process.env.ACCESS_JWT
94
- : settings.jwt;
95
- jsonwebtoken_1.default.verify(token, secret);
96
- return true;
97
- }
98
- catch (err) {
99
- var erro = err;
100
- if (erro.name === "TokenExpiredError") {
101
- return erro.message;
102
- }
103
- if (erro.name === "JsonWebTokenError") {
104
- return "Check your data and try again.";
105
- }
106
- }
107
- }
108
- exports.default = { verify, sign, forget, validate: { access, refresh, recover } };
@@ -1,3 +0,0 @@
1
- import { Request, Response, NextFunction } from "../../core/index.js";
2
- declare const _default: (req: Request, res: Response, next: NextFunction) => Promise<void>;
3
- export default _default;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../../helpers/index.js");
7
- const index_js_2 = require("../../constants/index.js");
8
- const ke_js_1 = __importDefault(require("../models/ke.js"));
9
- const index_js_3 = require("../../index.js");
10
- exports.default = async (req, res, next) => {
11
- const host = req.headers.host;
12
- const referer = req.headers.referer;
13
- // Bypass for playground or same domain requests
14
- if (referer && host && referer.includes(host)) {
15
- return next();
16
- }
17
- var api = (req.headers["opposer-key"] || req.cookies.opposer_key);
18
- if (!api) {
19
- return res.status(index_js_2.HttpStatus[401].code).send((0, index_js_1.Exception)({
20
- ...index_js_2.HttpStatus[401],
21
- message: "[autorization] - Unauthorized in system.",
22
- }));
23
- }
24
- const db = index_js_3.Context.get("db");
25
- if (!db) {
26
- return res.status(index_js_2.HttpStatus[403].code).send((0, index_js_1.Exception)({
27
- ...index_js_2.HttpStatus[403],
28
- message: "[database] - Database connection not found.",
29
- }));
30
- }
31
- var keRepository = db.getRepository(ke_js_1.default);
32
- var authorization = await keRepository.findOne({ where: { hs: api } });
33
- if (!authorization) {
34
- return res.status(index_js_2.HttpStatus[403].code).send((0, index_js_1.Exception)({
35
- ...index_js_2.HttpStatus[403],
36
- message: "[autorization] - Unauthorized in system.",
37
- }));
38
- }
39
- if (new Date() > new Date(authorization.ex)) {
40
- return res.status(index_js_2.HttpStatus[403].code).send((0, index_js_1.Exception)({
41
- ...index_js_2.HttpStatus[403],
42
- message: "[autorization] - Unauthorized in system.",
43
- }));
44
- }
45
- next();
46
- };
@@ -1,3 +0,0 @@
1
- import { Request, Response, NextFunction } from '../../core/index.js';
2
- declare const _default: (req: Request, res: Response, next: NextFunction) => Promise<void>;
3
- export default _default;
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../../helpers/index.js");
7
- const index_js_2 = require("../../constants/index.js");
8
- const index_js_3 = __importDefault(require("../jwt/index.js"));
9
- const index_js_4 = __importDefault(require("../../../system/index.js"));
10
- const index_js_5 = require("../../../server/decorators/index.js");
11
- const se_js_1 = __importDefault(require("../models/se.js"));
12
- const index_js_6 = require("../../index.js");
13
- exports.default = async (req, res, next) => {
14
- const host = req.headers.host;
15
- const referer = req.headers.referer;
16
- // Bypass for playground or same domain requests
17
- if (referer && host && referer.includes(host)) {
18
- return next();
19
- }
20
- const request = req.body;
21
- //skip session method
22
- if (['login', 'register', 'refresh'].includes(request.method)) {
23
- return next();
24
- }
25
- //skip for public models
26
- if (request.model) {
27
- const customModels = index_js_6.Context.get('models');
28
- var allModels = await index_js_4.default.getAllModels(customModels);
29
- var model = allModels.find((x) => x.name === request.model);
30
- if (model) {
31
- var isPublic = (0, index_js_5.getIsPublicMetadata)(model.entity);
32
- if (isPublic) {
33
- return next();
34
- }
35
- }
36
- }
37
- //skip for public methods
38
- if (request.controller) {
39
- const customControllers = index_js_6.Context.get('controllers');
40
- const allControllers = await index_js_4.default.getAllControllers(customControllers);
41
- var controller = allControllers.find((x) => x.name.toUpperCase() === request.controller?.toUpperCase());
42
- if (controller) {
43
- var methods = (0, index_js_5.getIsPublicMethodMetadata)(controller);
44
- if (methods.some((x) => x.name === request.method)) {
45
- return next();
46
- }
47
- }
48
- }
49
- const db = index_js_6.Context.get('db');
50
- var decoded = null;
51
- const authorization = req.headers.authorization || req.cookies.access_token;
52
- if (authorization) {
53
- var token = authorization.replace('Bearer ', '');
54
- decoded = await index_js_3.default.validate.access(token);
55
- }
56
- if (typeof decoded === 'string' || !decoded || !authorization) {
57
- const refresh = req.cookies.refresh_token;
58
- if (!refresh) {
59
- return res.status(index_js_2.HttpStatus[403].code).send((0, index_js_1.Exception)({
60
- ...index_js_2.HttpStatus[403],
61
- message: "[autorization] - Don't authorized, verify data and try again.",
62
- }));
63
- }
64
- if (!db) {
65
- return res.status(index_js_2.HttpStatus[500].code).send((0, index_js_1.Exception)({
66
- ...index_js_2.HttpStatus[500],
67
- message: '[database] - Database connection not found.',
68
- }));
69
- }
70
- var sessionRepository = db.getRepository(se_js_1.default);
71
- var last = await sessionRepository.findOne({
72
- where: { rt: refresh },
73
- });
74
- if (!last) {
75
- return res.status(index_js_2.HttpStatus[401].code).send((0, index_js_1.Exception)({
76
- ...index_js_2.HttpStatus[401],
77
- message: "Don't find session.",
78
- }));
79
- }
80
- //cancel last session and update in database;
81
- sessionRepository.update({ rt: last.rt }, {
82
- ac: false,
83
- lou: new Date(),
84
- });
85
- decoded = await index_js_3.default.validate.refresh(refresh);
86
- if (!decoded || typeof decoded === 'string') {
87
- return res.status(index_js_2.HttpStatus[401].code).send((0, index_js_1.Exception)({
88
- ...index_js_2.HttpStatus[401],
89
- message: 'Invalid refresh token.',
90
- }));
91
- }
92
- const { fn, id, lg, ln, rl } = decoded;
93
- var revalidate = await index_js_3.default.sign({ fn, id, lg, ln, rl });
94
- token = revalidate.token;
95
- const current = new Date();
96
- //seta os novos cookies
97
- res.cookie('access_token', token, {
98
- httpOnly: true,
99
- secure: true,
100
- sameSite: 'none',
101
- path: '/',
102
- expires: new Date(current.getTime() + 15 * 60 * 1000), // 15 mim
103
- });
104
- res.cookie('refresh_token', revalidate.refresh, {
105
- httpOnly: true,
106
- secure: true,
107
- sameSite: 'none',
108
- path: '/',
109
- expires: new Date(current.getTime() + 15 * 24 * 60 * 60 * 1000), // 15 dias
110
- });
111
- await sessionRepository.insert({
112
- ac: true,
113
- ag: last.ag,
114
- ip: last.ip,
115
- loi: new Date(),
116
- rt: refresh,
117
- usr: decoded.id,
118
- });
119
- }
120
- if (typeof decoded !== 'string' && decoded !== undefined) {
121
- //manager permission
122
- if (decoded.rl.some((x) => x.mt === 'all' && x.sm === 'all')) {
123
- return next();
124
- }
125
- //granular permission
126
- if (!decoded.rl.some((x) => x.mt === request.method && x.sm === request.model)) {
127
- return res.status(index_js_2.HttpStatus[403].code).send((0, index_js_1.Exception)({
128
- ...index_js_2.HttpStatus[403],
129
- message: "[autorization] - Don't authorized, verify our permissions and try again.",
130
- }));
131
- }
132
- return next();
133
- }
134
- return res.status(index_js_2.HttpStatus[403].code).send((0, index_js_1.Exception)({
135
- ...index_js_2.HttpStatus[403],
136
- message: 'Unabled authorization key.',
137
- }));
138
- };
@@ -1,8 +0,0 @@
1
- export default class ChangeRequestPassword {
2
- id: string;
3
- usr: string;
4
- tk: string;
5
- ex: Date;
6
- ac: boolean;
7
- ct: Date;
8
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const index_js_1 = require("../../../orm/index.js");
13
- let ChangeRequestPassword = class ChangeRequestPassword {
14
- };
15
- __decorate([
16
- (0, index_js_1.PrimaryColumn)({ type: "uuid" }),
17
- __metadata("design:type", String)
18
- ], ChangeRequestPassword.prototype, "id", void 0);
19
- __decorate([
20
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("usr is string.").required("usr is required.")),
21
- __metadata("design:type", String)
22
- ], ChangeRequestPassword.prototype, "usr", void 0);
23
- __decorate([
24
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("tk is string.").required("tk is required.")),
25
- __metadata("design:type", String)
26
- ], ChangeRequestPassword.prototype, "tk", void 0);
27
- __decorate([
28
- (0, index_js_1.Field)(() => (0, index_js_1.f)().date("ex is date.").required("ex is required.")),
29
- __metadata("design:type", Date)
30
- ], ChangeRequestPassword.prototype, "ex", void 0);
31
- __decorate([
32
- (0, index_js_1.Field)(() => (0, index_js_1.f)().boolean("ac is boolean.").required("ac is required.")),
33
- __metadata("design:type", Boolean)
34
- ], ChangeRequestPassword.prototype, "ac", void 0);
35
- __decorate([
36
- (0, index_js_1.CreateDateColumn)(),
37
- __metadata("design:type", Date)
38
- ], ChangeRequestPassword.prototype, "ct", void 0);
39
- ChangeRequestPassword = __decorate([
40
- (0, index_js_1.Entity)("crp")
41
- ], ChangeRequestPassword);
42
- exports.default = ChangeRequestPassword;
@@ -1,7 +0,0 @@
1
- export default class Key {
2
- id: string;
3
- nm: string;
4
- hs: string;
5
- ex: Date;
6
- ct: Date;
7
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const index_js_1 = require("../../../orm/index.js");
13
- let Key = class Key {
14
- };
15
- __decorate([
16
- (0, index_js_1.PrimaryColumn)({ type: "uuid" }),
17
- __metadata("design:type", String)
18
- ], Key.prototype, "id", void 0);
19
- __decorate([
20
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("nm is string.").required("nm is required.")),
21
- __metadata("design:type", String)
22
- ], Key.prototype, "nm", void 0);
23
- __decorate([
24
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("hs is string.").required("hs is required.")),
25
- __metadata("design:type", String)
26
- ], Key.prototype, "hs", void 0);
27
- __decorate([
28
- (0, index_js_1.Field)(() => (0, index_js_1.f)().date("ex is date.").required("ex is required.")),
29
- __metadata("design:type", Date)
30
- ], Key.prototype, "ex", void 0);
31
- __decorate([
32
- (0, index_js_1.CreateDateColumn)(),
33
- __metadata("design:type", Date)
34
- ], Key.prototype, "ct", void 0);
35
- Key = __decorate([
36
- (0, index_js_1.Entity)("ke")
37
- ], Key);
38
- exports.default = Key;
@@ -1,9 +0,0 @@
1
- import User from "./usr.js";
2
- export default class Role {
3
- id: string;
4
- sm: string;
5
- mt: string;
6
- ct: Date;
7
- ut: Date;
8
- usr: User;
9
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const index_js_1 = require("../../../orm/index.js");
16
- const usr_js_1 = __importDefault(require("./usr.js"));
17
- let Role = class Role {
18
- };
19
- __decorate([
20
- (0, index_js_1.PrimaryColumn)({ type: "uuid" }),
21
- __metadata("design:type", String)
22
- ], Role.prototype, "id", void 0);
23
- __decorate([
24
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("model is string.").required("model is required.")),
25
- __metadata("design:type", String)
26
- ], Role.prototype, "sm", void 0);
27
- __decorate([
28
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("model is string.").required("model is required.")),
29
- __metadata("design:type", String)
30
- ], Role.prototype, "mt", void 0);
31
- __decorate([
32
- (0, index_js_1.CreateDateColumn)(),
33
- __metadata("design:type", Date)
34
- ], Role.prototype, "ct", void 0);
35
- __decorate([
36
- (0, index_js_1.UpdateDateColumn)(),
37
- __metadata("design:type", Date)
38
- ], Role.prototype, "ut", void 0);
39
- __decorate([
40
- (0, index_js_1.Relation)({
41
- type: "many-to-one",
42
- target: () => usr_js_1.default,
43
- inverseSide: "rl"
44
- }),
45
- __metadata("design:type", usr_js_1.default)
46
- ], Role.prototype, "usr", void 0);
47
- Role = __decorate([
48
- (0, index_js_1.Entity)("rl")
49
- ], Role);
50
- exports.default = Role;
@@ -1,11 +0,0 @@
1
- export default class Session {
2
- id: string;
3
- usr: string;
4
- ip: string;
5
- ag: string;
6
- rt: string;
7
- ac: boolean;
8
- loi: Date;
9
- lou?: Date;
10
- ct: Date;
11
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const index_js_1 = require("../../../orm/index.js");
13
- let Session = class Session {
14
- };
15
- __decorate([
16
- (0, index_js_1.PrimaryColumn)({ type: "uuid" }),
17
- __metadata("design:type", String)
18
- ], Session.prototype, "id", void 0);
19
- __decorate([
20
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("usr is string.").required("usr is required.")),
21
- __metadata("design:type", String)
22
- ], Session.prototype, "usr", void 0);
23
- __decorate([
24
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("ip is string.").required("ip is required.")),
25
- __metadata("design:type", String)
26
- ], Session.prototype, "ip", void 0);
27
- __decorate([
28
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("ag is string.").required("ag is required.")),
29
- __metadata("design:type", String)
30
- ], Session.prototype, "ag", void 0);
31
- __decorate([
32
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("rt is string.").required("rt is required.")),
33
- __metadata("design:type", String)
34
- ], Session.prototype, "rt", void 0);
35
- __decorate([
36
- (0, index_js_1.Field)(() => (0, index_js_1.f)().boolean("ac is boolean.").required("ac is required.")),
37
- __metadata("design:type", Boolean)
38
- ], Session.prototype, "ac", void 0);
39
- __decorate([
40
- (0, index_js_1.Field)(() => (0, index_js_1.f)().date("loi is date.").required("loi is required.")),
41
- __metadata("design:type", Date)
42
- ], Session.prototype, "loi", void 0);
43
- __decorate([
44
- (0, index_js_1.Field)({ nullable: true, validation: () => (0, index_js_1.f)().date("lou is date.") }),
45
- __metadata("design:type", Date)
46
- ], Session.prototype, "lou", void 0);
47
- __decorate([
48
- (0, index_js_1.CreateDateColumn)(),
49
- __metadata("design:type", Date)
50
- ], Session.prototype, "ct", void 0);
51
- Session = __decorate([
52
- (0, index_js_1.Entity)("se")
53
- ], Session);
54
- exports.default = Session;
@@ -1,14 +0,0 @@
1
- import Role from "./rl.js";
2
- export default class User {
3
- id: string;
4
- fn: string;
5
- ln: string;
6
- lg: string;
7
- ps: string;
8
- ac: boolean;
9
- ct: Date;
10
- ut: Date;
11
- rl: Role[];
12
- hashPassword(): Promise<void>;
13
- comparePassword(plainPassword: string): Promise<boolean>;
14
- }
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const index_js_1 = require("../../../orm/index.js");
16
- const bcrypt_1 = __importDefault(require("bcrypt"));
17
- const rl_js_1 = __importDefault(require("./rl.js"));
18
- let User = class User {
19
- async hashPassword() {
20
- if (this.ps) {
21
- const salt = await bcrypt_1.default.genSalt(10);
22
- this.ps = await bcrypt_1.default.hash(this.ps, salt);
23
- }
24
- }
25
- async comparePassword(plainPassword) {
26
- return await bcrypt_1.default.compare(plainPassword, this.ps);
27
- }
28
- };
29
- __decorate([
30
- (0, index_js_1.PrimaryColumn)({ type: "uuid" }),
31
- __metadata("design:type", String)
32
- ], User.prototype, "id", void 0);
33
- __decorate([
34
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("first name is string.").required("first name is required.")),
35
- __metadata("design:type", String)
36
- ], User.prototype, "fn", void 0);
37
- __decorate([
38
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("last name is string.").required("last name is required.")),
39
- __metadata("design:type", String)
40
- ], User.prototype, "ln", void 0);
41
- __decorate([
42
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("ln is string.").required("ln is required.")),
43
- __metadata("design:type", String)
44
- ], User.prototype, "lg", void 0);
45
- __decorate([
46
- (0, index_js_1.Field)(() => (0, index_js_1.f)()
47
- .string("password is string.")
48
- .required("password is required.")
49
- .match(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9])[^\s]{8,}$/, "password not security, for strong password is necessary upper words, numbers and special characters.")),
50
- __metadata("design:type", String)
51
- ], User.prototype, "ps", void 0);
52
- __decorate([
53
- (0, index_js_1.Field)({ type: "boolean", default: true }),
54
- __metadata("design:type", Boolean)
55
- ], User.prototype, "ac", void 0);
56
- __decorate([
57
- (0, index_js_1.CreateDateColumn)(),
58
- __metadata("design:type", Date)
59
- ], User.prototype, "ct", void 0);
60
- __decorate([
61
- (0, index_js_1.UpdateDateColumn)(),
62
- __metadata("design:type", Date)
63
- ], User.prototype, "ut", void 0);
64
- __decorate([
65
- (0, index_js_1.Relation)({
66
- type: "one-to-many",
67
- target: () => rl_js_1.default,
68
- inverseSide: "usr",
69
- }),
70
- __metadata("design:type", Array)
71
- ], User.prototype, "rl", void 0);
72
- __decorate([
73
- (0, index_js_1.BeforeInsert)(),
74
- (0, index_js_1.BeforeUpdate)(),
75
- __metadata("design:type", Function),
76
- __metadata("design:paramtypes", []),
77
- __metadata("design:returntype", Promise)
78
- ], User.prototype, "hashPassword", null);
79
- User = __decorate([
80
- (0, index_js_1.Entity)("usr")
81
- ], User);
82
- exports.default = User;
@@ -1,13 +0,0 @@
1
- import { HandleDeleteProps } from '../../interfaces/controller.js';
2
- declare const _default: (props: HandleDeleteProps) => Promise<{
3
- readonly success: true;
4
- readonly data: any;
5
- } | {
6
- readonly success: false;
7
- readonly error: {
8
- name: string;
9
- code: number;
10
- message: any;
11
- };
12
- }>;
13
- export default _default;