@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,176 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Context = exports.f = exports.IsPublicMethod = exports.IsPublic = exports.Payload = exports.Field = exports.Controller = exports.Method = exports.auth = void 0;
21
- exports.default = Server;
22
- const index_js_1 = __importDefault(require("./controller/index.js"));
23
- const index_js_2 = __importDefault(require("../system/index.js"));
24
- const permission_js_1 = __importDefault(require("./security/middleware/permission.js"));
25
- const autorization_js_1 = __importDefault(require("./security/middleware/autorization.js"));
26
- const auth_js_1 = __importDefault(require("./security/controller/auth.js"));
27
- const index_js_3 = __importDefault(require("../scheduler/index.js"));
28
- const index_js_4 = require("../orm/index.js");
29
- // Core
30
- const index_js_5 = __importDefault(require("./core/index.js"));
31
- const cors_js_1 = __importDefault(require("./core/middleware/cors.js"));
32
- const body_parser_js_1 = __importDefault(require("./core/middleware/body-parser.js"));
33
- const logger_js_1 = __importDefault(require("./core/middleware/logger.js"));
34
- const index_js_6 = __importDefault(require("./context/index.js"));
35
- // Playground
36
- const index_js_7 = __importDefault(require("../playground/index.js"));
37
- async function initializeDatabase(props, models) {
38
- const settings = index_js_2.default.getSettingsFile();
39
- const allModels = await index_js_2.default.getAllModels(models);
40
- const entities = allModels.map((x) => x.entity);
41
- let driver;
42
- const type = props.type || settings.database?.type;
43
- switch (type) {
44
- case 'postgres':
45
- driver = new index_js_4.PostgresDriver(props);
46
- break;
47
- case 'sqlite':
48
- driver = new index_js_4.SQLiteDriver(props);
49
- break;
50
- case 'mysql':
51
- driver = new index_js_4.MySQLDriver(props);
52
- break;
53
- default:
54
- throw new Error(`[database] Unsupported database type: ${type}`);
55
- }
56
- const db = new index_js_4.OpposerDatabase(driver, entities);
57
- await db.connect();
58
- return db;
59
- }
60
- async function ensureManager(db, settings, models) {
61
- if (!settings.auth)
62
- return;
63
- try {
64
- const allModels = await index_js_2.default.getAllModels(models);
65
- const userEntity = allModels.find((x) => x.name === 'User' || x.name === 'usr');
66
- const roleEntity = allModels.find((x) => x.name === 'Role' || x.name === 'rl');
67
- if (userEntity && roleEntity) {
68
- const userRepository = db.getRepository(userEntity.entity);
69
- const roleRepository = db.getRepository(roleEntity.entity);
70
- let login = process.env.MANAGER_LOGIN || settings.manager?.login;
71
- let firstName = process.env.MANAGER_FIRST_NAME || settings.manager?.firstName;
72
- let lastName = process.env.MANAGER_LAST_NAME || settings.manager?.lastName;
73
- let password = process.env.MANAGER_PASSWORD || settings.manager?.password;
74
- let manager = await userRepository.findOne({
75
- where: { lg: login },
76
- });
77
- if (!manager) {
78
- console.log('-> Creating manager account.');
79
- manager = await userRepository.insert({
80
- fn: firstName,
81
- ln: lastName,
82
- lg: login,
83
- ps: password,
84
- ac: true,
85
- });
86
- }
87
- const hasAllRole = await roleRepository.findOne({
88
- where: { usr: manager.id, sm: 'all', mt: 'all' },
89
- });
90
- if (!hasAllRole) {
91
- console.log('-> Creating all-access role for manager.');
92
- await roleRepository.insert({
93
- usr: manager.id,
94
- sm: 'all',
95
- mt: 'all',
96
- });
97
- }
98
- }
99
- }
100
- catch (error) {
101
- console.error('[database] Manager creation failed:', error);
102
- }
103
- }
104
- async function Server(props) {
105
- console.log('-> Initializing database connection.');
106
- const settings = index_js_2.default.getSettingsFile();
107
- if (!settings.database) {
108
- throw new Error('-> It is necessary to inform database properties.');
109
- }
110
- const db = await initializeDatabase(settings.database, props.models);
111
- await ensureManager(db, settings, props.models);
112
- // Store database in server context
113
- index_js_6.default.set('db', db);
114
- index_js_6.default.set('models', props.models);
115
- index_js_6.default.set('controllers', props.controllers);
116
- console.log('-> Initializing scheduler.');
117
- await index_js_3.default.initialize(props.schedules);
118
- index_js_3.default.start();
119
- console.log('-> Initializing core server.');
120
- let url = '/opposer';
121
- if (settings.url) {
122
- url = settings.url;
123
- }
124
- // 1. Logger
125
- if (settings.logger) {
126
- index_js_5.default.use((0, logger_js_1.default)());
127
- }
128
- // 2. CORS (Global)
129
- if (props.cors || settings.cors) {
130
- index_js_5.default.use((0, cors_js_1.default)(props.cors || settings.cors));
131
- }
132
- // 3. Body Parser
133
- index_js_5.default.use((0, body_parser_js_1.default)());
134
- // 4. Playground
135
- index_js_5.default.use(index_js_7.default);
136
- // 5. Auth/Security Middlewares
137
- if (settings.auth) {
138
- index_js_5.default.use(autorization_js_1.default);
139
- index_js_5.default.use(permission_js_1.default);
140
- }
141
- // 6. Main Route Handler
142
- index_js_5.default.use(async (req, res, next) => {
143
- if (req.url === url && req.method === 'POST') {
144
- await (0, index_js_1.default)(req, res);
145
- }
146
- else {
147
- next();
148
- }
149
- });
150
- // 7. 404 Handler
151
- index_js_5.default.use((req, res) => {
152
- res.status(404).json({ message: `Route ${req.method} ${req.url} not found` });
153
- });
154
- function initialize() {
155
- index_js_5.default.listen(settings.port, () => {
156
- console.log(`⚡Opposer Core is running in port ${settings.port}`);
157
- });
158
- }
159
- return {
160
- opposer: index_js_5.default,
161
- initialize,
162
- };
163
- }
164
- exports.auth = { social: auth_js_1.default.social };
165
- __exportStar(require("./constants/index.js"), exports);
166
- __exportStar(require("./helpers/index.js"), exports);
167
- var index_js_8 = require("./decorators/index.js");
168
- Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return index_js_8.Method; } });
169
- Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return index_js_8.Controller; } });
170
- Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return index_js_8.Field; } });
171
- Object.defineProperty(exports, "Payload", { enumerable: true, get: function () { return index_js_8.Payload; } });
172
- Object.defineProperty(exports, "IsPublic", { enumerable: true, get: function () { return index_js_8.IsPublic; } });
173
- Object.defineProperty(exports, "IsPublicMethod", { enumerable: true, get: function () { return index_js_8.IsPublicMethod; } });
174
- Object.defineProperty(exports, "f", { enumerable: true, get: function () { return index_js_8.f; } });
175
- var index_js_9 = require("./context/index.js");
176
- Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return __importDefault(index_js_9).default; } });
@@ -1,76 +0,0 @@
1
- import { PayloadAuthChangePassword, PayloadAuthForgetPassword, PayloadAuthLogin, PayloadAuthRegister, PayloadSocialLogin } from '../../../interfaces/security.js';
2
- import { PayloadRequest } from '../../../interfaces/controller.js';
3
- export default class Auth {
4
- private get db();
5
- register(payload: PayloadRequest<PayloadAuthRegister>): Promise<{
6
- readonly success: true;
7
- readonly data: any;
8
- } | {
9
- readonly success: false;
10
- readonly error: {
11
- name: string;
12
- code: number;
13
- message: any;
14
- };
15
- }>;
16
- login(payload: PayloadRequest<PayloadAuthLogin>): Promise<{
17
- readonly success: true;
18
- readonly data: any;
19
- } | {
20
- readonly success: false;
21
- readonly error: {
22
- name: string;
23
- code: number;
24
- message: any;
25
- };
26
- }>;
27
- refresh(payload: PayloadRequest<string>): Promise<{
28
- readonly success: true;
29
- readonly data: any;
30
- } | {
31
- readonly success: false;
32
- readonly error: {
33
- name: string;
34
- code: number;
35
- message: any;
36
- };
37
- }>;
38
- logout(payload: PayloadRequest<string>): Promise<{
39
- readonly success: false;
40
- readonly error: {
41
- name: string;
42
- code: number;
43
- message: any;
44
- };
45
- } | undefined>;
46
- me(payload: PayloadRequest<any>): Promise<{
47
- readonly success: true;
48
- readonly data: any;
49
- } | null>;
50
- changePassword(payload: PayloadRequest<PayloadAuthChangePassword>): Promise<{
51
- readonly success: true;
52
- readonly data: any;
53
- } | {
54
- readonly success: false;
55
- readonly error: {
56
- name: string;
57
- code: number;
58
- message: any;
59
- };
60
- }>;
61
- forgotPassword(payload: PayloadRequest<PayloadAuthForgetPassword>): Promise<{
62
- readonly success: true;
63
- readonly data: any;
64
- } | {
65
- readonly success: false;
66
- readonly error: {
67
- name: string;
68
- code: number;
69
- message: any;
70
- };
71
- }>;
72
- static social(payload: PayloadRequest<PayloadSocialLogin>): Promise<{
73
- readonly success: true;
74
- readonly data: any;
75
- }>;
76
- }
@@ -1,346 +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("../../decorators/index.js");
16
- const usr_js_1 = __importDefault(require("../models/usr.js"));
17
- const rl_js_1 = __importDefault(require("../models/rl.js"));
18
- const index_js_2 = require("../../helpers/index.js");
19
- const index_js_3 = require("../../constants/index.js");
20
- const index_js_4 = __importDefault(require("../jwt/index.js"));
21
- const se_js_1 = __importDefault(require("../models/se.js"));
22
- const crp_js_1 = __importDefault(require("../models/crp.js"));
23
- const index_js_5 = require("../../index.js");
24
- let Auth = class Auth {
25
- get db() {
26
- return index_js_5.Context.get('db');
27
- }
28
- async register(payload) {
29
- var errors = (0, index_js_2.validateData)(usr_js_1.default, payload.data);
30
- if (Object.keys(errors).length > 0) {
31
- return (0, index_js_2.Exception)({
32
- ...index_js_3.HttpStatus[400],
33
- message: errors,
34
- });
35
- }
36
- var userRepository = this.db.getRepository(usr_js_1.default);
37
- if (await userRepository.findOne({ where: { lg: payload.data.lg } })) {
38
- return (0, index_js_2.Exception)({
39
- ...index_js_3.HttpStatus[400],
40
- message: 'User with this login already exists.',
41
- });
42
- }
43
- const result = await userRepository.insert(payload.data);
44
- return (0, index_js_2.Success)(result);
45
- }
46
- async login(payload) {
47
- if (!payload.data.lg) {
48
- return (0, index_js_2.Exception)({
49
- ...index_js_3.HttpStatus[400],
50
- message: 'Login is required',
51
- });
52
- }
53
- if (!payload.data.ps) {
54
- return (0, index_js_2.Exception)({
55
- ...index_js_3.HttpStatus[400],
56
- message: 'Password is required',
57
- });
58
- }
59
- var userRepository = this.db.getRepository(usr_js_1.default);
60
- var sessionRepository = this.db.getRepository(se_js_1.default);
61
- var usr = await userRepository.findOne({
62
- where: { lg: payload.data.lg },
63
- });
64
- if (!usr) {
65
- return (0, index_js_2.Exception)({
66
- ...index_js_3.HttpStatus[400],
67
- message: 'Invalid login or password, check the data and try again.',
68
- });
69
- }
70
- if (!(await usr.comparePassword(payload.data.ps))) {
71
- return (0, index_js_2.Exception)({
72
- ...index_js_3.HttpStatus[400],
73
- message: 'Invalid login or password, check the data and try again.',
74
- });
75
- }
76
- var roleRepository = this.db.getRepository(rl_js_1.default);
77
- var roles = await roleRepository.find({
78
- where: { usr: usr.id },
79
- });
80
- var { token, refresh } = await index_js_4.default.sign({
81
- fn: usr.fn,
82
- id: usr.id,
83
- lg: usr.lg,
84
- ln: usr.ln,
85
- exp: 0,
86
- rl: roles.map(({ sm, mt }) => ({ sm, mt })),
87
- });
88
- // register new session init
89
- await sessionRepository.insert({
90
- ac: true,
91
- ag: payload.headers.userAgent,
92
- ip: payload.headers.ip,
93
- loi: new Date(),
94
- rt: refresh,
95
- usr: usr.id,
96
- });
97
- const current = new Date();
98
- payload.headers.cookies.set('access_token', token, {
99
- httpOnly: true,
100
- secure: true,
101
- sameSite: 'none',
102
- path: '/',
103
- expires: new Date(current.getTime() + 15 * 60 * 1000), // 15 mim
104
- });
105
- payload.headers.cookies.set('refresh_token', refresh, {
106
- httpOnly: true,
107
- secure: true,
108
- sameSite: 'none',
109
- path: '/',
110
- expires: new Date(current.getTime() + 15 * 24 * 60 * 60 * 1000), // 15 dias
111
- });
112
- return (0, index_js_2.Success)({
113
- token,
114
- refresh,
115
- usr: {
116
- id: usr.id,
117
- fn: usr.fn,
118
- ln: usr.ln,
119
- lg: usr.lg,
120
- rl: roles.map(({ sm, mt }) => ({ sm, mt })),
121
- },
122
- });
123
- }
124
- async refresh(payload) {
125
- if (!payload.data) {
126
- return (0, index_js_2.Exception)({
127
- ...index_js_3.HttpStatus[400],
128
- message: 'Refresh token is required.',
129
- });
130
- }
131
- var sessionRepository = this.db.getRepository(se_js_1.default);
132
- var last = await sessionRepository.findOne({
133
- where: { rt: payload.data },
134
- });
135
- if (!last) {
136
- return (0, index_js_2.Exception)({
137
- ...index_js_3.HttpStatus[401],
138
- message: "Don't find session.",
139
- });
140
- }
141
- if (!last.ac) {
142
- return (0, index_js_2.Exception)({
143
- ...index_js_3.HttpStatus[401],
144
- message: 'Refresh expired.',
145
- });
146
- }
147
- var usr = await index_js_4.default.validate.refresh(payload.data);
148
- if (!usr || typeof usr === 'string') {
149
- return (0, index_js_2.Exception)({
150
- ...index_js_3.HttpStatus[401],
151
- message: 'Invalid token.',
152
- });
153
- }
154
- //cancel last session and update in database;
155
- await sessionRepository.update({ rt: last.rt }, {
156
- ac: false,
157
- lou: new Date(),
158
- });
159
- var { token, refresh } = await index_js_4.default.sign(usr);
160
- await sessionRepository.insert({
161
- ac: true,
162
- ag: last.ag,
163
- ip: last.ip,
164
- loi: new Date(),
165
- rt: refresh,
166
- usr: usr.id,
167
- });
168
- const current = new Date();
169
- payload.headers.cookies.set('access_token', token, {
170
- httpOnly: true,
171
- secure: true,
172
- sameSite: 'none',
173
- path: '/',
174
- expires: new Date(current.getTime() + 15 * 60 * 1000), // 15 mim
175
- });
176
- payload.headers.cookies.set('refresh_token', refresh, {
177
- httpOnly: true,
178
- secure: true,
179
- sameSite: 'none',
180
- path: '/',
181
- expires: new Date(current.getTime() + 15 * 24 * 60 * 60 * 1000), // 15 dias
182
- });
183
- return (0, index_js_2.Success)({
184
- token,
185
- refresh,
186
- ...usr,
187
- });
188
- }
189
- async logout(payload) {
190
- const token = payload.data || payload.headers.cookies.data.refresh_token;
191
- if (!token) {
192
- return (0, index_js_2.Exception)({
193
- ...index_js_3.HttpStatus[400],
194
- message: 'Token is required for logout user.',
195
- });
196
- }
197
- payload.headers.cookies.remove('access_token');
198
- payload.headers.cookies.remove('refresh_token');
199
- var sessionRepository = this.db.getRepository(se_js_1.default);
200
- await sessionRepository.update({ rt: token }, {
201
- ac: false,
202
- lou: new Date(),
203
- });
204
- }
205
- async me(payload) {
206
- const token = payload.headers.cookies.data.refresh_token;
207
- if (!token) {
208
- return null;
209
- }
210
- var usr = await index_js_4.default.validate.refresh(token);
211
- if (typeof usr === 'string') {
212
- return null;
213
- }
214
- return (0, index_js_2.Success)(usr);
215
- }
216
- async changePassword(payload) {
217
- var errors = (0, index_js_2.validateData)(usr_js_1.default, { ps: payload.data.ps });
218
- if (Object.keys(errors).length > 0) {
219
- return (0, index_js_2.Exception)({
220
- ...index_js_3.HttpStatus[400],
221
- message: errors,
222
- });
223
- }
224
- if (!payload.data.tk) {
225
- return (0, index_js_2.Exception)({
226
- ...index_js_3.HttpStatus[400],
227
- message: 'Ticket is required for change password.',
228
- });
229
- }
230
- var ticket = await index_js_4.default.validate.recover(payload.data.tk);
231
- if (typeof ticket === 'string' || !ticket) {
232
- return (0, index_js_2.Exception)({
233
- ...index_js_3.HttpStatus[401],
234
- message: 'Invalid token.',
235
- });
236
- }
237
- var changePasswordRepository = this.db.getRepository(crp_js_1.default);
238
- var userRepository = this.db.getRepository(usr_js_1.default);
239
- var usr = await userRepository.findOne({
240
- where: { lg: ticket.lg },
241
- });
242
- if (!usr) {
243
- return (0, index_js_2.Exception)({
244
- ...index_js_3.HttpStatus[401],
245
- message: "Don't find user, verify payload and try again.",
246
- });
247
- }
248
- // finaly update password...
249
- await userRepository.update({ lg: ticket.lg }, { ps: payload.data.ps });
250
- await changePasswordRepository.update({ tk: payload.data.tk }, {
251
- ud: true,
252
- });
253
- return (0, index_js_2.Success)({ message: 'Success for change password.' });
254
- }
255
- async forgotPassword(payload) {
256
- if (!payload.data.lg) {
257
- return (0, index_js_2.Exception)({
258
- ...index_js_3.HttpStatus[400],
259
- message: 'Login is required.',
260
- });
261
- }
262
- var { token } = await index_js_4.default.forget(payload.data);
263
- var changePasswordRepository = this.db.getRepository(crp_js_1.default);
264
- await changePasswordRepository.insert({
265
- ...payload.data,
266
- tk: token,
267
- ex: new Date(new Date().getTime() + 5 * 60 * 1000), // five min
268
- });
269
- return (0, index_js_2.Success)({ token });
270
- }
271
- static async social(payload) {
272
- const usr = payload.data;
273
- const db = index_js_5.Context.get('db');
274
- var sessionRepository = db.getRepository(se_js_1.default);
275
- var { token, refresh } = await index_js_4.default.sign({
276
- ...usr,
277
- exp: 0,
278
- });
279
- // register new session init
280
- await sessionRepository.insert({
281
- ac: true,
282
- ag: payload.headers.userAgent,
283
- ip: payload.headers.ip,
284
- loi: new Date(),
285
- rt: refresh,
286
- usr: usr.id,
287
- });
288
- return (0, index_js_2.Success)({
289
- token,
290
- refresh,
291
- usr: {
292
- id: usr.id,
293
- fn: usr.fn,
294
- ln: usr.ln,
295
- lg: usr.lg,
296
- },
297
- });
298
- }
299
- };
300
- __decorate([
301
- (0, index_js_1.Method)(),
302
- __metadata("design:type", Function),
303
- __metadata("design:paramtypes", [Object]),
304
- __metadata("design:returntype", Promise)
305
- ], Auth.prototype, "register", null);
306
- __decorate([
307
- (0, index_js_1.Method)(),
308
- __metadata("design:type", Function),
309
- __metadata("design:paramtypes", [Object]),
310
- __metadata("design:returntype", Promise)
311
- ], Auth.prototype, "login", null);
312
- __decorate([
313
- (0, index_js_1.Method)(),
314
- __metadata("design:type", Function),
315
- __metadata("design:paramtypes", [Object]),
316
- __metadata("design:returntype", Promise)
317
- ], Auth.prototype, "refresh", null);
318
- __decorate([
319
- (0, index_js_1.Method)(),
320
- __metadata("design:type", Function),
321
- __metadata("design:paramtypes", [Object]),
322
- __metadata("design:returntype", Promise)
323
- ], Auth.prototype, "logout", null);
324
- __decorate([
325
- (0, index_js_1.Method)(),
326
- (0, index_js_1.IsPublicMethod)(),
327
- __metadata("design:type", Function),
328
- __metadata("design:paramtypes", [Object]),
329
- __metadata("design:returntype", Promise)
330
- ], Auth.prototype, "me", null);
331
- __decorate([
332
- (0, index_js_1.Method)(),
333
- __metadata("design:type", Function),
334
- __metadata("design:paramtypes", [Object]),
335
- __metadata("design:returntype", Promise)
336
- ], Auth.prototype, "changePassword", null);
337
- __decorate([
338
- (0, index_js_1.Method)(),
339
- __metadata("design:type", Function),
340
- __metadata("design:paramtypes", [Object]),
341
- __metadata("design:returntype", Promise)
342
- ], Auth.prototype, "forgotPassword", null);
343
- Auth = __decorate([
344
- (0, index_js_1.Controller)('auth')
345
- ], Auth);
346
- exports.default = Auth;
@@ -1,2 +0,0 @@
1
- export { default as User } from "./models/usr.js";
2
- export { default as Role } from "./models/rl.js";
@@ -1,10 +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
- exports.Role = exports.User = void 0;
7
- var usr_js_1 = require("./models/usr.js");
8
- Object.defineProperty(exports, "User", { enumerable: true, get: function () { return __importDefault(usr_js_1).default; } });
9
- var rl_js_1 = require("./models/rl.js");
10
- Object.defineProperty(exports, "Role", { enumerable: true, get: function () { return __importDefault(rl_js_1).default; } });
@@ -1,23 +0,0 @@
1
- import { ForgetJwt, SignJwt } from "../../../interfaces/jwt.js";
2
- declare function access(token: string): Promise<string | SignJwt | undefined>;
3
- declare function refresh(token: string): Promise<string | SignJwt | undefined>;
4
- declare function sign({ exp, ...payload }: SignJwt): Promise<{
5
- token: any;
6
- refresh: any;
7
- }>;
8
- declare function forget(payload: ForgetJwt): Promise<{
9
- token: any;
10
- }>;
11
- declare function recover(token: string): Promise<string | ForgetJwt | undefined>;
12
- declare function verify(token: string): Promise<string | true | undefined>;
13
- declare const _default: {
14
- verify: typeof verify;
15
- sign: typeof sign;
16
- forget: typeof forget;
17
- validate: {
18
- access: typeof access;
19
- refresh: typeof refresh;
20
- recover: typeof recover;
21
- };
22
- };
23
- export default _default;