@adaptivestone/framework 5.0.0-beta.9 → 5.0.0-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 (370) hide show
  1. package/LICENCE +1 -1
  2. package/README.md +69 -2
  3. package/dist/Cli.d.ts +7 -0
  4. package/dist/Cli.js +19 -0
  5. package/dist/Cli.js.map +1 -0
  6. package/dist/cluster.d.ts +1 -0
  7. package/dist/cluster.js +67 -0
  8. package/dist/cluster.js.map +1 -0
  9. package/dist/codegen/appTypes.d.ts +19 -0
  10. package/dist/codegen/appTypes.js +126 -0
  11. package/dist/codegen/appTypes.js.map +1 -0
  12. package/dist/codegen/astEmit.d.ts +53 -0
  13. package/dist/codegen/astEmit.js +242 -0
  14. package/dist/codegen/astEmit.js.map +1 -0
  15. package/dist/codegen/astExtract.d.ts +78 -0
  16. package/dist/codegen/astExtract.js +539 -0
  17. package/dist/codegen/astExtract.js.map +1 -0
  18. package/dist/codegen/astModel.d.ts +14 -0
  19. package/dist/codegen/astModel.js +73 -0
  20. package/dist/codegen/astModel.js.map +1 -0
  21. package/dist/codegen/astResolve.d.ts +53 -0
  22. package/dist/codegen/astResolve.js +276 -0
  23. package/dist/codegen/astResolve.js.map +1 -0
  24. package/dist/codegen/astSpec.d.ts +25 -0
  25. package/dist/codegen/astSpec.js +63 -0
  26. package/dist/codegen/astSpec.js.map +1 -0
  27. package/dist/codegen/collectMetadata.d.ts +39 -0
  28. package/dist/codegen/collectMetadata.js +7 -0
  29. package/dist/codegen/collectMetadata.js.map +1 -0
  30. package/dist/codegen/emit.d.ts +30 -0
  31. package/dist/codegen/emit.js +213 -0
  32. package/dist/codegen/emit.js.map +1 -0
  33. package/dist/codegen/index.d.ts +30 -0
  34. package/dist/codegen/index.js +76 -0
  35. package/dist/codegen/index.js.map +1 -0
  36. package/dist/codegen/paths.d.ts +9 -0
  37. package/dist/codegen/paths.js +25 -0
  38. package/dist/codegen/paths.js.map +1 -0
  39. package/dist/commands/CreateUser.d.ts +32 -0
  40. package/dist/commands/CreateUser.js +85 -0
  41. package/dist/commands/CreateUser.js.map +1 -0
  42. package/dist/commands/DropIndex.d.ts +16 -0
  43. package/dist/commands/DropIndex.js +30 -0
  44. package/dist/commands/DropIndex.js.map +1 -0
  45. package/dist/commands/GenerateRandomBytes.d.ts +7 -0
  46. package/dist/commands/GenerateRandomBytes.js +18 -0
  47. package/dist/commands/GenerateRandomBytes.js.map +1 -0
  48. package/dist/commands/GenerateTypes.d.ts +13 -0
  49. package/dist/commands/GenerateTypes.js +34 -0
  50. package/dist/commands/GenerateTypes.js.map +1 -0
  51. package/dist/commands/SyncIndexes.d.ts +6 -0
  52. package/dist/commands/SyncIndexes.js +31 -0
  53. package/dist/commands/SyncIndexes.js.map +1 -0
  54. package/dist/commands/migration/Create.d.ts +18 -0
  55. package/dist/commands/migration/Create.js +57 -0
  56. package/dist/commands/migration/Create.js.map +1 -0
  57. package/dist/commands/migration/Migrate.d.ts +6 -0
  58. package/dist/commands/migration/Migrate.js +73 -0
  59. package/dist/commands/migration/Migrate.js.map +1 -0
  60. package/dist/config/auth.d.ts +11 -0
  61. package/dist/config/auth.js +18 -0
  62. package/dist/config/auth.js.map +1 -0
  63. package/dist/config/http.d.ts +22 -0
  64. package/dist/config/http.js +40 -0
  65. package/dist/config/http.js.map +1 -0
  66. package/dist/config/i18n.d.ts +13 -0
  67. package/dist/config/i18n.js +13 -0
  68. package/dist/config/i18n.js.map +1 -0
  69. package/dist/config/ipDetector.d.ts +5 -0
  70. package/dist/config/ipDetector.js +15 -0
  71. package/dist/config/ipDetector.js.map +1 -0
  72. package/dist/config/log.d.ts +11 -0
  73. package/dist/config/log.js +21 -0
  74. package/dist/config/log.js.map +1 -0
  75. package/dist/config/mongo.d.ts +4 -0
  76. package/dist/config/mongo.js +4 -0
  77. package/dist/config/mongo.js.map +1 -0
  78. package/dist/config/rateLimiter.d.ts +13 -0
  79. package/dist/config/rateLimiter.js +17 -0
  80. package/dist/config/rateLimiter.js.map +1 -0
  81. package/dist/config/redis.d.ts +5 -0
  82. package/dist/config/redis.js +5 -0
  83. package/dist/config/redis.js.map +1 -0
  84. package/dist/controllers/Auth.d.ts +59 -0
  85. package/dist/controllers/Auth.js +356 -0
  86. package/dist/controllers/Auth.js.map +1 -0
  87. package/dist/controllers/Auth.routes.gen.d.ts +57 -0
  88. package/dist/controllers/Auth.routes.gen.js +10 -0
  89. package/dist/controllers/Auth.routes.gen.js.map +1 -0
  90. package/dist/controllers/Home.d.ts +14 -0
  91. package/dist/controllers/Home.js +26 -0
  92. package/dist/controllers/Home.js.map +1 -0
  93. package/dist/controllers/Home.routes.gen.d.ts +13 -0
  94. package/dist/controllers/Home.routes.gen.js +10 -0
  95. package/dist/controllers/Home.routes.gen.js.map +1 -0
  96. package/dist/controllers/index.d.ts +107 -0
  97. package/dist/controllers/index.js +548 -0
  98. package/dist/controllers/index.js.map +1 -0
  99. package/dist/folderConfig.d.ts +34 -0
  100. package/dist/folderConfig.js +14 -0
  101. package/dist/folderConfig.js.map +1 -0
  102. package/dist/helpers/appInstance.d.ts +10 -0
  103. package/dist/helpers/appInstance.js +19 -0
  104. package/dist/helpers/appInstance.js.map +1 -0
  105. package/dist/helpers/crypto.d.ts +26 -0
  106. package/dist/helpers/crypto.js +160 -0
  107. package/dist/helpers/crypto.js.map +1 -0
  108. package/dist/helpers/deprecation.d.ts +8 -0
  109. package/dist/helpers/deprecation.js +19 -0
  110. package/dist/helpers/deprecation.js.map +1 -0
  111. package/dist/helpers/env.d.ts +8 -0
  112. package/dist/helpers/env.js +15 -0
  113. package/dist/helpers/env.js.map +1 -0
  114. package/dist/helpers/files.d.ts +16 -0
  115. package/dist/helpers/files.js +83 -0
  116. package/dist/helpers/files.js.map +1 -0
  117. package/dist/helpers/logger.d.ts +6 -0
  118. package/dist/helpers/logger.js +34 -0
  119. package/dist/helpers/logger.js.map +1 -0
  120. package/dist/helpers/redis/clearNamespace.d.ts +10 -0
  121. package/dist/helpers/redis/clearNamespace.js +31 -0
  122. package/dist/helpers/redis/clearNamespace.js.map +1 -0
  123. package/dist/helpers/redis/redisConnection.d.ts +8 -0
  124. package/dist/helpers/redis/redisConnection.js +63 -0
  125. package/dist/helpers/redis/redisConnection.js.map +1 -0
  126. package/dist/helpers/yup.d.ts +22 -0
  127. package/dist/helpers/yup.js +39 -0
  128. package/dist/helpers/yup.js.map +1 -0
  129. package/dist/index.d.ts +1 -0
  130. package/dist/index.js +8 -0
  131. package/dist/index.js.map +1 -0
  132. package/{locales → dist/locales}/en/translation.json +5 -0
  133. package/{locales → dist/locales}/ru/translation.json +5 -0
  134. package/dist/models/KeyValue.d.ts +22 -0
  135. package/dist/models/KeyValue.js +17 -0
  136. package/dist/models/KeyValue.js.map +1 -0
  137. package/dist/models/Lock.d.ts +99 -0
  138. package/dist/models/Lock.js +123 -0
  139. package/dist/models/Lock.js.map +1 -0
  140. package/dist/models/Migration.d.ts +13 -0
  141. package/dist/models/Migration.js +14 -0
  142. package/dist/models/Migration.js.map +1 -0
  143. package/dist/models/Sequence.d.ts +28 -0
  144. package/dist/models/Sequence.js +31 -0
  145. package/dist/models/Sequence.js.map +1 -0
  146. package/dist/models/User.d.ts +769 -0
  147. package/dist/models/User.js +336 -0
  148. package/dist/models/User.js.map +1 -0
  149. package/dist/models/UserOld.d.ts +191 -0
  150. package/dist/models/UserOld.js +231 -0
  151. package/dist/models/UserOld.js.map +1 -0
  152. package/dist/modules/AbstractCommand.d.ts +51 -0
  153. package/dist/modules/AbstractCommand.js +60 -0
  154. package/dist/modules/AbstractCommand.js.map +1 -0
  155. package/dist/modules/AbstractConnector.d.ts +5 -0
  156. package/dist/modules/AbstractConnector.js +8 -0
  157. package/dist/modules/AbstractConnector.js.map +1 -0
  158. package/dist/modules/AbstractController.d.ts +99 -0
  159. package/dist/modules/AbstractController.js +83 -0
  160. package/dist/modules/AbstractController.js.map +1 -0
  161. package/dist/modules/AbstractModel.d.ts +29 -0
  162. package/dist/modules/AbstractModel.js +42 -0
  163. package/dist/modules/AbstractModel.js.map +1 -0
  164. package/dist/modules/Base.d.ts +29 -0
  165. package/dist/modules/Base.js +62 -0
  166. package/dist/modules/Base.js.map +1 -0
  167. package/dist/modules/BaseCli.d.ts +25 -0
  168. package/dist/modules/BaseCli.js +159 -0
  169. package/dist/modules/BaseCli.js.map +1 -0
  170. package/dist/modules/BaseModel.d.ts +57 -0
  171. package/dist/modules/BaseModel.js +37 -0
  172. package/dist/modules/BaseModel.js.map +1 -0
  173. package/dist/server.d.ts +130 -0
  174. package/dist/server.js +603 -0
  175. package/dist/server.js.map +1 -0
  176. package/dist/services/cache/Cache.d.ts +31 -0
  177. package/dist/services/cache/Cache.js +146 -0
  178. package/dist/services/cache/Cache.js.map +1 -0
  179. package/dist/services/http/HttpServer.d.ts +46 -0
  180. package/dist/services/http/HttpServer.js +114 -0
  181. package/dist/services/http/HttpServer.js.map +1 -0
  182. package/dist/services/http/files.d.ts +18 -0
  183. package/dist/services/http/files.js +19 -0
  184. package/dist/services/http/files.js.map +1 -0
  185. package/dist/services/http/middleware/AbstractMiddleware.d.ts +58 -0
  186. package/dist/services/http/middleware/AbstractMiddleware.js +73 -0
  187. package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -0
  188. package/dist/services/http/middleware/Auth.d.ts +22 -0
  189. package/dist/services/http/middleware/Auth.js +30 -0
  190. package/dist/services/http/middleware/Auth.js.map +1 -0
  191. package/dist/services/http/middleware/Cors.d.ts +12 -0
  192. package/dist/services/http/middleware/Cors.js +45 -0
  193. package/dist/services/http/middleware/Cors.js.map +1 -0
  194. package/dist/services/http/middleware/GetUserByToken.d.ts +36 -0
  195. package/dist/services/http/middleware/GetUserByToken.js +59 -0
  196. package/dist/services/http/middleware/GetUserByToken.js.map +1 -0
  197. package/dist/services/http/middleware/I18n.d.ts +23 -0
  198. package/dist/services/http/middleware/I18n.js +61 -0
  199. package/dist/services/http/middleware/I18n.js.map +1 -0
  200. package/dist/services/http/middleware/IpDetector.d.ts +14 -0
  201. package/dist/services/http/middleware/IpDetector.js +80 -0
  202. package/dist/services/http/middleware/IpDetector.js.map +1 -0
  203. package/dist/services/http/middleware/Pagination.d.ts +26 -0
  204. package/dist/services/http/middleware/Pagination.js +70 -0
  205. package/dist/services/http/middleware/Pagination.js.map +1 -0
  206. package/dist/services/http/middleware/PrepareAppInfo.d.ts +8 -0
  207. package/dist/services/http/middleware/PrepareAppInfo.js +17 -0
  208. package/dist/services/http/middleware/PrepareAppInfo.js.map +1 -0
  209. package/dist/services/http/middleware/RateLimiter.d.ts +31 -0
  210. package/dist/services/http/middleware/RateLimiter.js +118 -0
  211. package/dist/services/http/middleware/RateLimiter.js.map +1 -0
  212. package/dist/services/http/middleware/RequestLogger.d.ts +8 -0
  213. package/dist/services/http/middleware/RequestLogger.js +20 -0
  214. package/dist/services/http/middleware/RequestLogger.js.map +1 -0
  215. package/dist/services/http/middleware/RequestParser.d.ts +15 -0
  216. package/dist/services/http/middleware/RequestParser.js +112 -0
  217. package/dist/services/http/middleware/RequestParser.js.map +1 -0
  218. package/dist/services/http/middleware/Role.d.ts +12 -0
  219. package/dist/services/http/middleware/Role.js +27 -0
  220. package/dist/services/http/middleware/Role.js.map +1 -0
  221. package/dist/services/http/routing/ExpressAdapter.d.ts +12 -0
  222. package/dist/services/http/routing/ExpressAdapter.js +95 -0
  223. package/dist/services/http/routing/ExpressAdapter.js.map +1 -0
  224. package/dist/services/http/routing/RouteNode.d.ts +105 -0
  225. package/dist/services/http/routing/RouteNode.js +21 -0
  226. package/dist/services/http/routing/RouteNode.js.map +1 -0
  227. package/dist/services/http/routing/RouteRegistry.d.ts +37 -0
  228. package/dist/services/http/routing/RouteRegistry.js +244 -0
  229. package/dist/services/http/routing/RouteRegistry.js.map +1 -0
  230. package/dist/services/http/routing/formatTree.d.ts +23 -0
  231. package/dist/services/http/routing/formatTree.js +159 -0
  232. package/dist/services/http/routing/formatTree.js.map +1 -0
  233. package/dist/services/http/routing/match.d.ts +31 -0
  234. package/dist/services/http/routing/match.js +164 -0
  235. package/dist/services/http/routing/match.js.map +1 -0
  236. package/dist/services/http/routing/middlewareNormalization.d.ts +11 -0
  237. package/dist/services/http/routing/middlewareNormalization.js +23 -0
  238. package/dist/services/http/routing/middlewareNormalization.js.map +1 -0
  239. package/dist/services/http/types.d.ts +74 -0
  240. package/dist/services/http/types.js +8 -0
  241. package/dist/services/http/types.js.map +1 -0
  242. package/dist/services/i18n/I18n.d.ts +15 -0
  243. package/dist/services/i18n/I18n.js +58 -0
  244. package/dist/services/i18n/I18n.js.map +1 -0
  245. package/dist/services/logging/SentryTransport.d.ts +13 -0
  246. package/dist/services/logging/SentryTransport.js +134 -0
  247. package/dist/services/logging/SentryTransport.js.map +1 -0
  248. package/dist/services/validate/ValidateService.d.ts +54 -0
  249. package/dist/services/validate/ValidateService.js +144 -0
  250. package/dist/services/validate/ValidateService.js.map +1 -0
  251. package/dist/services/validate/ValidationError.d.ts +35 -0
  252. package/dist/services/validate/ValidationError.js +90 -0
  253. package/dist/services/validate/ValidationError.js.map +1 -0
  254. package/dist/services/validate/contentType.d.ts +18 -0
  255. package/dist/services/validate/contentType.js +30 -0
  256. package/dist/services/validate/contentType.js.map +1 -0
  257. package/dist/services/validate/defineSchema.d.ts +23 -0
  258. package/dist/services/validate/defineSchema.js +25 -0
  259. package/dist/services/validate/defineSchema.js.map +1 -0
  260. package/dist/services/validate/drivers/StandardSchemaDriver.d.ts +15 -0
  261. package/dist/services/validate/drivers/StandardSchemaDriver.js +38 -0
  262. package/dist/services/validate/drivers/StandardSchemaDriver.js.map +1 -0
  263. package/dist/services/validate/drivers/YupDriver.d.ts +21 -0
  264. package/dist/services/validate/drivers/YupDriver.js +81 -0
  265. package/dist/services/validate/drivers/YupDriver.js.map +1 -0
  266. package/dist/services/validate/types.d.ts +104 -0
  267. package/dist/services/validate/types.js +11 -0
  268. package/dist/services/validate/types.js.map +1 -0
  269. package/dist/tests/frameworkVitestSetup.d.ts +1 -0
  270. package/dist/tests/frameworkVitestSetup.js +9 -0
  271. package/dist/tests/frameworkVitestSetup.js.map +1 -0
  272. package/dist/tests/globalSetupVitest.d.ts +3 -0
  273. package/dist/tests/globalSetupVitest.js +29 -0
  274. package/dist/tests/globalSetupVitest.js.map +1 -0
  275. package/dist/tests/setupVitest.d.ts +1 -0
  276. package/dist/tests/setupVitest.js +101 -0
  277. package/dist/tests/setupVitest.js.map +1 -0
  278. package/dist/tests/testHelpers.d.ts +361 -0
  279. package/dist/tests/testHelpers.js +48 -0
  280. package/dist/tests/testHelpers.js.map +1 -0
  281. package/dist/types.d.ts +4 -0
  282. package/dist/types.js +5 -0
  283. package/dist/types.js.map +1 -0
  284. package/package.json +84 -39
  285. package/.env.example +0 -18
  286. package/CHANGELOG.md +0 -956
  287. package/Cli.js +0 -21
  288. package/cluster.js +0 -25
  289. package/commands/CreateUser.js +0 -106
  290. package/commands/Documentation.js +0 -17
  291. package/commands/DropIndex.js +0 -38
  292. package/commands/GenerateRandomBytes.js +0 -21
  293. package/commands/GetOpenApiJson.js +0 -336
  294. package/commands/SyncIndexes.js +0 -40
  295. package/commands/migration/Create.js +0 -72
  296. package/commands/migration/Migrate.js +0 -56
  297. package/config/auth.js +0 -9
  298. package/config/http.js +0 -9
  299. package/config/i18n.js +0 -12
  300. package/config/ipDetector.js +0 -14
  301. package/config/log.js +0 -22
  302. package/config/mongo.js +0 -3
  303. package/config/rateLimiter.js +0 -16
  304. package/config/redis.js +0 -4
  305. package/config/validate.js +0 -3
  306. package/controllers/Auth.js +0 -201
  307. package/controllers/Home.js +0 -28
  308. package/controllers/index.js +0 -60
  309. package/eslint.config.js +0 -68
  310. package/folderConfig.js +0 -13
  311. package/helpers/files.js +0 -76
  312. package/helpers/logger.js +0 -16
  313. package/helpers/redis/clearNamespace.js +0 -14
  314. package/helpers/yup.js +0 -22
  315. package/index.js +0 -8
  316. package/jsconfig.json +0 -9
  317. package/models/Lock.js +0 -107
  318. package/models/Migration.js +0 -15
  319. package/models/Sequence.js +0 -22
  320. package/models/User.js +0 -280
  321. package/modules/AbstractCommand.js +0 -52
  322. package/modules/AbstractConnector.js +0 -9
  323. package/modules/AbstractController.js +0 -406
  324. package/modules/AbstractModel.d.ts +0 -48
  325. package/modules/AbstractModel.js +0 -92
  326. package/modules/Base.d.ts +0 -37
  327. package/modules/Base.js +0 -64
  328. package/modules/BaseCli.js +0 -157
  329. package/server.d.ts +0 -100
  330. package/server.js +0 -439
  331. package/services/cache/Cache.d.ts +0 -35
  332. package/services/cache/Cache.js +0 -124
  333. package/services/documentation/DocumentationGenerator.js +0 -169
  334. package/services/http/HttpServer.js +0 -89
  335. package/services/http/middleware/AbstractMiddleware.js +0 -51
  336. package/services/http/middleware/Auth.js +0 -20
  337. package/services/http/middleware/Cors.js +0 -46
  338. package/services/http/middleware/GetUserByToken.js +0 -47
  339. package/services/http/middleware/I18n.js +0 -117
  340. package/services/http/middleware/IpDetector.js +0 -59
  341. package/services/http/middleware/Pagination.js +0 -57
  342. package/services/http/middleware/PrepareAppInfo.js +0 -18
  343. package/services/http/middleware/RateLimiter.js +0 -134
  344. package/services/http/middleware/RequestLogger.js +0 -22
  345. package/services/http/middleware/RequestParser.js +0 -40
  346. package/services/http/middleware/Role.js +0 -29
  347. package/services/messaging/email/templates/.gitkeep +0 -0
  348. package/services/validate/ValidateService.js +0 -157
  349. package/services/validate/drivers/AbstractValidator.js +0 -37
  350. package/services/validate/drivers/CustomValidator.js +0 -51
  351. package/services/validate/drivers/YupValidator.js +0 -103
  352. package/tests/globalSetupVitest.js +0 -35
  353. package/tests/setup.js +0 -120
  354. package/tests/setupVitest.js +0 -111
  355. package/types/Expand.d.ts +0 -11
  356. package/types/ICommandArguments.d.ts +0 -41
  357. package/types/TFoldersConfig.d.ts +0 -20
  358. package/views/404.pug +0 -3
  359. package/views/home.pug +0 -3
  360. package/views/layouts/base.pug +0 -39
  361. package/vitest.config.js +0 -17
  362. /package/{commands → dist/migrations}/.gitkeep +0 -0
  363. /package/{services → dist/services}/messaging/email/resources/.gitkeep +0 -0
  364. /package/{migrations → dist/services/messaging/email/templates}/.gitkeep +0 -0
  365. /package/{services → dist/services}/messaging/email/templates/recovery/html.pug +0 -0
  366. /package/{services → dist/services}/messaging/email/templates/recovery/subject.pug +0 -0
  367. /package/{services → dist/services}/messaging/email/templates/recovery/text.pug +0 -0
  368. /package/{services → dist/services}/messaging/email/templates/verification/html.pug +0 -0
  369. /package/{services → dist/services}/messaging/email/templates/verification/subject.pug +0 -0
  370. /package/{services → dist/services}/messaging/email/templates/verification/text.pug +0 -0
package/models/Lock.js DELETED
@@ -1,107 +0,0 @@
1
- import AbstractModel from '../modules/AbstractModel.js';
2
-
3
- class Lock extends AbstractModel {
4
- initHooks() {
5
- this.mongooseSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
6
- }
7
-
8
- // eslint-disable-next-line class-methods-use-this
9
- get modelSchema() {
10
- return {
11
- _id: { type: String, required: true },
12
- expiredAt: {
13
- type: Date,
14
- },
15
- };
16
- }
17
-
18
- /**
19
- * acquire lock based on lock name
20
- * @param {string} name
21
- * @param {number} [ttlSeconds=30]
22
- * @returns {Promise<boolean>}
23
- */
24
- static async acquireLock(name, ttlSeconds = 30) {
25
- try {
26
- await this.create({
27
- _id: name,
28
- expiredAt: new Date(Date.now() + ttlSeconds * 1000),
29
- });
30
- } catch (error) {
31
- if (error.code !== 11000) {
32
- // not a duplicate leys
33
- throw error;
34
- }
35
- return false;
36
- }
37
- return true;
38
- }
39
-
40
- /**
41
- * release lock based on lock name
42
- * @param {string} name
43
- * @returns {Promise<boolean>}
44
- */
45
- static async releaseLock(name) {
46
- const res = await this.deleteOne({ _id: name });
47
- if (res.acknowledged && res.deletedCount) {
48
- return true;
49
- }
50
- return false;
51
- }
52
-
53
- /**
54
- * wait lock based on lock name
55
- * @param {string} name
56
- * @returns {Promise}
57
- */
58
- static async waitForUnlock(name) {
59
- const res = await this.findOne({ _id: name });
60
- if (!res) {
61
- return Promise.resolve();
62
- }
63
-
64
- return new Promise((resolve) => {
65
- const stream = this.watch([
66
- { $match: { operationType: 'delete', 'documentKey._id': name } },
67
- ]);
68
- stream.on('change', () => {
69
- stream.close();
70
- resolve();
71
- });
72
- });
73
- }
74
-
75
- /**
76
- * get lock remaining time based on lock name
77
- * @param {string} name
78
- * @returns {Promise<{ttl: number}>}
79
- */
80
- static async getLockData(name) {
81
- const res = await this.findOne({ _id: name });
82
- if (!res) {
83
- return { ttl: 0 };
84
- }
85
- return { ttl: res.expiredAt.getTime() - Date.now() };
86
- }
87
-
88
- /**
89
- * get lock remaining time based on lock name
90
- * @param {string[]} names
91
- * @returns {Promise<{name: string, ttl: number}[]>}
92
- */
93
- static async getLocksData(names) {
94
- const res = await this.find({ _id: { $in: names } });
95
- const lockMap = new Map(res.map((lock) => [lock._id, lock]));
96
-
97
- return names.map((name) => {
98
- const lock = lockMap.get(name);
99
- return {
100
- name,
101
- ttl: lock ? lock.expiredAt.getTime() - Date.now() : 0,
102
- };
103
- });
104
- }
105
- }
106
-
107
- export default Lock;
@@ -1,15 +0,0 @@
1
- import AbstractModel from '../modules/AbstractModel.js';
2
-
3
- class Migration extends AbstractModel {
4
- // eslint-disable-next-line class-methods-use-this
5
- get modelSchema() {
6
- return {
7
- migrationFile: {
8
- type: String,
9
- unique: true,
10
- },
11
- };
12
- }
13
- }
14
-
15
- export default Migration;
@@ -1,22 +0,0 @@
1
- import AbstractModel from '../modules/AbstractModel.js';
2
-
3
- class Sequence extends AbstractModel {
4
- // eslint-disable-next-line class-methods-use-this
5
- get modelSchema() {
6
- return {
7
- _id: { type: String, required: true },
8
- seq: { type: Number, default: 1 },
9
- };
10
- }
11
-
12
- static async getSequence(forType) {
13
- const sequence = await this.findByIdAndUpdate(
14
- { _id: forType },
15
- { $inc: { seq: 1 } },
16
- { new: true, upsert: true },
17
- );
18
- return sequence.seq;
19
- }
20
- }
21
-
22
- export default Sequence;
package/models/User.js DELETED
@@ -1,280 +0,0 @@
1
- import { scrypt } from 'node:crypto';
2
-
3
- import { promisify } from 'node:util';
4
- import AbstractModel from '../modules/AbstractModel.js';
5
-
6
- class User extends AbstractModel {
7
- constructor(app) {
8
- super(app);
9
- const authConfig = this.app.getConfig('auth');
10
- this.hashRounds = authConfig.hashRounds;
11
- this.saltSecret = authConfig.saltSecret;
12
- }
13
-
14
- initHooks() {
15
- this.mongooseSchema.pre('save', async function userPreSaveHook() {
16
- if (this.isModified('password')) {
17
- // @ts-ignore
18
- this.password = await this.constructor.hashPassword(this.password);
19
- }
20
- });
21
- }
22
-
23
- // eslint-disable-next-line class-methods-use-this
24
- get modelSchema() {
25
- return {
26
- avatar: {
27
- type: String,
28
- maxlength: 255,
29
- },
30
- name: {
31
- first: {
32
- type: String,
33
- maxlength: 255,
34
- },
35
- last: {
36
- type: String,
37
- maxlength: 255,
38
- },
39
- nick: {
40
- minlength: 3,
41
- maxlength: 255,
42
- type: String,
43
- index: {
44
- unique: true,
45
- partialFilterExpression: { 'name.nick': { $type: 'string' } },
46
- },
47
- },
48
- },
49
- password: String,
50
- email: {
51
- type: String,
52
- maxlength: 255,
53
- index: {
54
- unique: true,
55
- partialFilterExpression: { email: { $type: 'string' } },
56
- },
57
- },
58
- sessionTokens: [{ token: String, valid: Date }],
59
- verificationTokens: [{ until: Date, token: String }],
60
- passwordRecoveryTokens: [{ until: Date, token: String }],
61
- permissions: [],
62
- roles: [],
63
- isVerified: { type: Boolean, default: false },
64
- locale: { type: String, default: 'en' },
65
- languages: [String],
66
- };
67
- }
68
-
69
- static async getUserByEmailAndPassword(email, password) {
70
- const data = await this.findOne({ email: String(email) });
71
- if (!data) {
72
- return false;
73
- }
74
- const hashedPasswords = await this.hashPassword(password);
75
-
76
- if (data.password !== hashedPasswords) {
77
- return false;
78
- }
79
- return data;
80
- }
81
-
82
- async generateToken() {
83
- const timestamp = new Date();
84
- timestamp.setDate(timestamp.getDate() + 30);
85
- const scryptAsync = promisify(scrypt);
86
- const data = await scryptAsync(
87
- this.email + Date.now(),
88
- this.getSuper().saltSecret,
89
- this.getSuper().hashRounds,
90
- );
91
- const token = data.toString('base64url');
92
- this.sessionTokens.push({ token, valid: timestamp });
93
- await this.save();
94
- return { token, valid: timestamp };
95
- }
96
-
97
- getPublic() {
98
- return {
99
- avatar: this.avatar,
100
- name: this.name,
101
- email: this.email,
102
- id: this.id,
103
- isVerified: this.isVerified,
104
- permissions: this.permissions,
105
- locale: this.locale,
106
- };
107
- }
108
-
109
- static async hashPassword(password) {
110
- const scryptAsync = promisify(scrypt);
111
- const data = await scryptAsync(
112
- String(password),
113
- this.getSuper().saltSecret,
114
- this.getSuper().hashRounds,
115
- );
116
- return data.toString('base64url');
117
- }
118
-
119
- static async getUserByToken(token) {
120
- const data = await this.findOne({ 'sessionTokens.token': String(token) });
121
- return data || false;
122
- }
123
-
124
- static async getUserByEmail(email) {
125
- const data = await this.findOne({ email: String(email) });
126
- if (!data) {
127
- return false;
128
- }
129
- return data;
130
- }
131
-
132
- static async generateUserPasswordRecoveryToken(userMongoose) {
133
- const date = new Date();
134
- date.setDate(date.getDate() + 14);
135
- const scryptAsync = promisify(scrypt);
136
- const data = await scryptAsync(
137
- userMongoose.email + Date.now(),
138
- userMongoose.getSuper().saltSecret,
139
- userMongoose.getSuper().hashRounds,
140
- );
141
- const token = data.toString('base64url');
142
- // if (err) {
143
- // this.logger.error("Hash 2 error ", err);
144
- // reject(err);
145
- // return;
146
- // }
147
- userMongoose.passwordRecoveryTokens = [];
148
- userMongoose.passwordRecoveryTokens.push({
149
- until: date,
150
- token,
151
- });
152
- await userMongoose.save();
153
- return { token, until: date.getTime() };
154
- }
155
-
156
- static async getUserByPasswordRecoveryToken(passwordRecoveryToken) {
157
- const data = await this.findOne({
158
- passwordRecoveryTokens: {
159
- $elemMatch: { token: String(passwordRecoveryToken) },
160
- },
161
- });
162
- if (!data) {
163
- return Promise.reject(new Error('User not exists'));
164
- }
165
- // TODO token expiration and remove that token
166
-
167
- data.passwordRecoveryTokens.pop();
168
-
169
- const result = await data.save();
170
- return result;
171
- }
172
-
173
- async sendPasswordRecoveryEmail(i18n) {
174
- const passwordRecoveryToken =
175
- await User.generateUserPasswordRecoveryToken(this);
176
- let Mailer;
177
- // speed optimisation
178
- try {
179
- // @ts-ignore
180
- // eslint-disable-next-line import-x/no-unresolved
181
- Mailer = (await import('@adaptivestone/framework-module-email')).default;
182
- } catch {
183
- const error =
184
- 'Mailer not found. Please install @adaptivestone/framework-module-email in order to use it';
185
- this.getSuper().logger.error(error);
186
- return false;
187
- }
188
-
189
- const mail = new Mailer(
190
- this.getSuper().app,
191
- 'recovery',
192
- {
193
- link: `${i18n.language}/auth/recovery?password_recovery_token=${passwordRecoveryToken.token}`,
194
- editor: this.name.nick,
195
- },
196
- i18n,
197
- );
198
- return mail.send(this.email);
199
- }
200
-
201
- static async generateUserVerificationToken(userMongoose) {
202
- const date = new Date();
203
- date.setDate(date.getDate() + 14);
204
- const scryptAsync = promisify(scrypt);
205
- const data = await scryptAsync(
206
- userMongoose.email + Date.now(),
207
- userMongoose.getSuper().saltSecret,
208
- userMongoose.getSuper().hashRounds,
209
- );
210
- const token = data.toString('base64url');
211
- // if (err) {
212
- // this.logger.error("Hash 2 error ", err);
213
- // reject(err);
214
- // return;
215
- // }
216
- userMongoose.verificationTokens = [];
217
- userMongoose.verificationTokens.push({
218
- until: date,
219
- token,
220
- });
221
- await userMongoose.save();
222
- return { token, until: date.getTime() };
223
- }
224
-
225
- static async getUserByVerificationToken(verificationToken) {
226
- const data = await this.findOne({
227
- verificationTokens: {
228
- $elemMatch: { token: String(verificationToken) },
229
- },
230
- });
231
- if (!data) {
232
- return Promise.reject(new Error('User not exists'));
233
- }
234
- // TODO token expiration and remove that token
235
-
236
- data.verificationTokens.pop();
237
-
238
- const result = await data.save();
239
- return result;
240
- }
241
-
242
- // async removeVerificationToken(verificationToken) {
243
- // this.mongooseModel.updateOne(
244
- // {
245
- // verificationTokens: {
246
- // $elemMatch: { token: String(verificationToken) },
247
- // },
248
- // },
249
- // { $pop: { verificationTokens: 1 } },
250
- // );
251
- // }
252
-
253
- async sendVerificationEmail(i18n) {
254
- const verificationToken = await User.generateUserVerificationToken(this);
255
- // speed optimisation
256
- let Mailer;
257
- try {
258
- // @ts-ignore
259
- // eslint-disable-next-line import-x/no-unresolved
260
- Mailer = (await import('@adaptivestone/framework-module-email')).default;
261
- } catch {
262
- const error =
263
- 'Mailer not found. Please install @adaptivestone/framework-module-email in order to use it';
264
- this.getSuper().logger.error(error);
265
- return false;
266
- }
267
- const mail = new Mailer(
268
- this.getSuper().app,
269
- 'verification',
270
- {
271
- link: `${i18n.language}/auth/login?verification_token=${verificationToken.token}`,
272
- editor: this.name.nick,
273
- },
274
- i18n,
275
- );
276
- return mail.send(this.email);
277
- }
278
- }
279
-
280
- export default User;
@@ -1,52 +0,0 @@
1
- import Base from './Base.js';
2
-
3
- class AbstractCommand extends Base {
4
- constructor(app, commands, args) {
5
- super(app);
6
- this.args = args;
7
- this.commands = commands;
8
- }
9
-
10
- static get description() {
11
- return 'Command description. PLEASE PROVIDE IT';
12
- }
13
-
14
- /**
15
- * If true, then this command will load models and init mongo connection
16
- */
17
- static isShouldInitModels = true;
18
-
19
- /**
20
- * Get mongo connection name
21
- * @param {String} commandName
22
- * @param {object} args
23
- * @returns string
24
- */
25
- static getMongoConnectionName(commandName, args) {
26
- return `CLI: ${commandName} ${JSON.stringify(args)}`;
27
- }
28
-
29
- /**
30
- * You able to add command arguments for parsing there.
31
- * @see https://nodejs.org/api/util.html#utilparseargsconfig in config.options plus extended with description and required
32
- * @returns {import("../types/ICommandArguments.js").ICommandArguments}
33
- */
34
- static get commandArguments() {
35
- return {};
36
- }
37
-
38
- /**
39
- * Entry point to every command. This method should be overridden
40
- * @return {Promise<boolean>} result
41
- */
42
- async run() {
43
- this.logger.error('You should implement run method');
44
- return false;
45
- }
46
-
47
- static get loggerGroup() {
48
- return 'command';
49
- }
50
- }
51
-
52
- export default AbstractCommand;
@@ -1,9 +0,0 @@
1
- import Base from './Base.js';
2
-
3
- class AbstractConnector extends Base {
4
- static get loggerGroup() {
5
- return 'connector';
6
- }
7
- }
8
-
9
- export default AbstractConnector;