@volcanicminds/backend 2.0.4 → 2.1.1

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 (289) hide show
  1. package/README.md +8 -7
  2. package/dist/index.d.ts +7 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +160 -210
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/api/auth/controller/auth.d.ts +35 -0
  7. package/dist/lib/api/auth/controller/auth.d.ts.map +1 -0
  8. package/dist/lib/api/auth/controller/auth.js +245 -333
  9. package/dist/lib/api/auth/controller/auth.js.map +1 -1
  10. package/dist/lib/api/auth/routes.d.ts +90 -0
  11. package/dist/lib/api/auth/routes.d.ts.map +1 -0
  12. package/dist/lib/api/auth/routes.js +1 -2
  13. package/dist/lib/api/auth/routes.js.map +1 -1
  14. package/dist/lib/api/health/controller/health.d.ts +3 -0
  15. package/dist/lib/api/health/controller/health.d.ts.map +1 -0
  16. package/dist/lib/api/health/controller/health.js +1 -4
  17. package/dist/lib/api/health/controller/health.js.map +1 -1
  18. package/dist/lib/api/health/routes.d.ts +26 -0
  19. package/dist/lib/api/health/routes.d.ts.map +1 -0
  20. package/dist/lib/api/health/routes.js +1 -2
  21. package/dist/lib/api/health/routes.js.map +1 -1
  22. package/dist/lib/api/token/controller/token.d.ts +16 -0
  23. package/dist/lib/api/token/controller/token.d.ts.map +1 -0
  24. package/dist/lib/api/token/controller/token.js +69 -105
  25. package/dist/lib/api/token/controller/token.js.map +1 -1
  26. package/dist/lib/api/token/routes.d.ts +179 -0
  27. package/dist/lib/api/token/routes.d.ts.map +1 -0
  28. package/dist/lib/api/token/routes.js +1 -2
  29. package/dist/lib/api/token/routes.js.map +1 -1
  30. package/dist/lib/api/tool/controller/tool.d.ts +3 -0
  31. package/dist/lib/api/tool/controller/tool.d.ts.map +1 -0
  32. package/dist/lib/api/tool/controller/tool.js +8 -22
  33. package/dist/lib/api/tool/controller/tool.js.map +1 -1
  34. package/dist/lib/api/tool/routes.d.ts +26 -0
  35. package/dist/lib/api/tool/routes.d.ts.map +1 -0
  36. package/dist/lib/api/tool/routes.js +1 -2
  37. package/dist/lib/api/tool/routes.js.map +1 -1
  38. package/dist/lib/api/users/controller/user.d.ts +12 -0
  39. package/dist/lib/api/users/controller/user.d.ts.map +1 -0
  40. package/dist/lib/api/users/controller/user.js +59 -112
  41. package/dist/lib/api/users/controller/user.js.map +1 -1
  42. package/dist/lib/api/users/routes.d.ts +173 -0
  43. package/dist/lib/api/users/routes.d.ts.map +1 -0
  44. package/dist/lib/api/users/routes.js +1 -2
  45. package/dist/lib/api/users/routes.js.map +1 -1
  46. package/dist/lib/apollo/context.d.ts +6 -0
  47. package/dist/lib/apollo/context.d.ts.map +1 -0
  48. package/dist/lib/apollo/context.js +2 -16
  49. package/dist/lib/apollo/context.js.map +1 -1
  50. package/dist/lib/apollo/resolvers.d.ts +8 -0
  51. package/dist/lib/apollo/resolvers.d.ts.map +1 -0
  52. package/dist/lib/apollo/resolvers.js +1 -2
  53. package/dist/lib/apollo/resolvers.js.map +1 -1
  54. package/dist/lib/apollo/type-defs.d.ts +3 -0
  55. package/dist/lib/apollo/type-defs.d.ts.map +1 -0
  56. package/dist/lib/apollo/type-defs.js +1 -2
  57. package/dist/lib/apollo/type-defs.js.map +1 -1
  58. package/dist/lib/config/general.d.ts +12 -0
  59. package/dist/lib/config/general.d.ts.map +1 -0
  60. package/dist/lib/config/general.js +1 -2
  61. package/dist/lib/config/general.js.map +1 -1
  62. package/dist/lib/config/plugins.d.ts +25 -0
  63. package/dist/lib/config/plugins.d.ts.map +1 -0
  64. package/dist/lib/config/plugins.js +1 -2
  65. package/dist/lib/config/plugins.js.map +1 -1
  66. package/dist/lib/config/roles.d.ts +7 -0
  67. package/dist/lib/config/roles.d.ts.map +1 -0
  68. package/dist/lib/config/roles.js +1 -2
  69. package/dist/lib/config/roles.js.map +1 -1
  70. package/dist/lib/config/tracking.d.ts +10 -0
  71. package/dist/lib/config/tracking.d.ts.map +1 -0
  72. package/dist/lib/config/tracking.js +1 -2
  73. package/dist/lib/config/tracking.js.map +1 -1
  74. package/dist/lib/hooks/onError.d.ts +3 -0
  75. package/dist/lib/hooks/onError.d.ts.map +1 -0
  76. package/dist/lib/hooks/onError.js +2 -12
  77. package/dist/lib/hooks/onError.js.map +1 -1
  78. package/dist/lib/hooks/onRequest.d.ts +3 -0
  79. package/dist/lib/hooks/onRequest.d.ts.map +1 -0
  80. package/dist/lib/hooks/onRequest.js +24 -35
  81. package/dist/lib/hooks/onRequest.js.map +1 -1
  82. package/dist/lib/hooks/onResponse.d.ts +3 -0
  83. package/dist/lib/hooks/onResponse.d.ts.map +1 -0
  84. package/dist/lib/hooks/onResponse.js +2 -12
  85. package/dist/lib/hooks/onResponse.js.map +1 -1
  86. package/dist/lib/hooks/preHandler.d.ts +3 -0
  87. package/dist/lib/hooks/preHandler.d.ts.map +1 -0
  88. package/dist/lib/hooks/preHandler.js +3 -47
  89. package/dist/lib/hooks/preHandler.js.map +1 -1
  90. package/dist/lib/hooks/preSerialization.d.ts +3 -0
  91. package/dist/lib/hooks/preSerialization.d.ts.map +1 -0
  92. package/dist/lib/hooks/preSerialization.js +6 -53
  93. package/dist/lib/hooks/preSerialization.js.map +1 -1
  94. package/dist/lib/loader/general.d.ts +3 -0
  95. package/dist/lib/loader/general.d.ts.map +1 -0
  96. package/dist/lib/loader/general.js +15 -13
  97. package/dist/lib/loader/general.js.map +1 -1
  98. package/dist/lib/loader/hooks.d.ts +2 -0
  99. package/dist/lib/loader/hooks.d.ts.map +1 -0
  100. package/dist/lib/loader/hooks.js +19 -18
  101. package/dist/lib/loader/hooks.js.map +1 -1
  102. package/dist/lib/loader/plugins.d.ts +2 -0
  103. package/dist/lib/loader/plugins.d.ts.map +1 -0
  104. package/dist/lib/loader/plugins.js +11 -12
  105. package/dist/lib/loader/plugins.js.map +1 -1
  106. package/dist/lib/loader/roles.d.ts +3 -0
  107. package/dist/lib/loader/roles.d.ts.map +1 -0
  108. package/dist/lib/loader/roles.js +11 -12
  109. package/dist/lib/loader/roles.js.map +1 -1
  110. package/dist/lib/loader/router.d.ts +2 -0
  111. package/dist/lib/loader/router.d.ts.map +1 -0
  112. package/dist/lib/loader/router.js +111 -129
  113. package/dist/lib/loader/router.js.map +1 -1
  114. package/dist/lib/loader/schedules.d.ts +3 -0
  115. package/dist/lib/loader/schedules.d.ts.map +1 -0
  116. package/dist/lib/loader/schedules.js +18 -25
  117. package/dist/lib/loader/schedules.js.map +1 -1
  118. package/dist/lib/loader/schemas.d.ts +2 -0
  119. package/dist/lib/loader/schemas.d.ts.map +1 -0
  120. package/dist/lib/loader/schemas.js +26 -22
  121. package/dist/lib/loader/schemas.js.map +1 -1
  122. package/dist/lib/loader/tracking.d.ts +6 -0
  123. package/dist/lib/loader/tracking.d.ts.map +1 -0
  124. package/dist/lib/loader/tracking.js +17 -19
  125. package/dist/lib/loader/tracking.js.map +1 -1
  126. package/dist/lib/loader/translation.d.ts +2 -0
  127. package/dist/lib/loader/translation.d.ts.map +1 -0
  128. package/dist/lib/loader/translation.js +11 -10
  129. package/dist/lib/loader/translation.js.map +1 -1
  130. package/dist/lib/middleware/dispatchForgotPasswordLink.d.ts +3 -0
  131. package/dist/lib/middleware/dispatchForgotPasswordLink.d.ts.map +1 -0
  132. package/dist/lib/middleware/dispatchForgotPasswordLink.js +2 -16
  133. package/dist/lib/middleware/dispatchForgotPasswordLink.js.map +1 -1
  134. package/dist/lib/middleware/isAdmin.d.ts +3 -0
  135. package/dist/lib/middleware/isAdmin.d.ts.map +1 -0
  136. package/dist/lib/middleware/isAdmin.js +1 -4
  137. package/dist/lib/middleware/isAdmin.js.map +1 -1
  138. package/dist/lib/middleware/isAuthenticated.d.ts +3 -0
  139. package/dist/lib/middleware/isAuthenticated.d.ts.map +1 -0
  140. package/dist/lib/middleware/isAuthenticated.js +2 -6
  141. package/dist/lib/middleware/isAuthenticated.js.map +1 -1
  142. package/dist/lib/middleware/postAuth.d.ts +3 -0
  143. package/dist/lib/middleware/postAuth.d.ts.map +1 -0
  144. package/dist/lib/middleware/postAuth.js +2 -16
  145. package/dist/lib/middleware/postAuth.js.map +1 -1
  146. package/dist/lib/middleware/preAuth.d.ts +3 -0
  147. package/dist/lib/middleware/preAuth.d.ts.map +1 -0
  148. package/dist/lib/middleware/preAuth.js +1 -15
  149. package/dist/lib/middleware/preAuth.js.map +1 -1
  150. package/dist/lib/middleware/preForgotPasswordHandler.d.ts +3 -0
  151. package/dist/lib/middleware/preForgotPasswordHandler.d.ts.map +1 -0
  152. package/dist/lib/middleware/preForgotPasswordHandler.js +1 -15
  153. package/dist/lib/middleware/preForgotPasswordHandler.js.map +1 -1
  154. package/dist/lib/schedules/test.job.d.ts +4 -0
  155. package/dist/lib/schedules/test.job.d.ts.map +1 -0
  156. package/dist/lib/schedules/test.job.js +3 -18
  157. package/dist/lib/schedules/test.job.js.map +1 -1
  158. package/dist/lib/schemas/auth.d.ts +175 -0
  159. package/dist/lib/schemas/auth.d.ts.map +1 -0
  160. package/dist/lib/schemas/auth.js +9 -12
  161. package/dist/lib/schemas/auth.js.map +1 -1
  162. package/dist/lib/schemas/common.d.ts +81 -0
  163. package/dist/lib/schemas/common.d.ts.map +1 -0
  164. package/dist/lib/schemas/common.js +6 -9
  165. package/dist/lib/schemas/common.js.map +1 -1
  166. package/dist/lib/schemas/global.d.ts +29 -0
  167. package/dist/lib/schemas/global.d.ts.map +1 -0
  168. package/dist/lib/schemas/global.js +2 -5
  169. package/dist/lib/schemas/global.js.map +1 -1
  170. package/dist/lib/schemas/token.d.ts +68 -0
  171. package/dist/lib/schemas/token.d.ts.map +1 -0
  172. package/dist/lib/schemas/token.js +3 -6
  173. package/dist/lib/schemas/token.js.map +1 -1
  174. package/dist/lib/schemas/user.d.ts +120 -0
  175. package/dist/lib/schemas/user.d.ts.map +1 -0
  176. package/dist/lib/schemas/user.js +5 -8
  177. package/dist/lib/schemas/user.js.map +1 -1
  178. package/dist/lib/util/common.d.ts +5 -0
  179. package/dist/lib/util/common.d.ts.map +1 -0
  180. package/dist/lib/util/common.js +4 -8
  181. package/dist/lib/util/common.js.map +1 -1
  182. package/dist/lib/util/errors.d.ts +15 -0
  183. package/dist/lib/util/errors.d.ts.map +1 -0
  184. package/dist/lib/util/errors.js +7 -7
  185. package/dist/lib/util/errors.js.map +1 -1
  186. package/dist/lib/util/generate.d.ts +2 -0
  187. package/dist/lib/util/generate.d.ts.map +1 -0
  188. package/dist/lib/util/generate.js +2 -5
  189. package/dist/lib/util/generate.js.map +1 -1
  190. package/dist/lib/util/logger.d.ts +35 -0
  191. package/dist/lib/util/logger.d.ts.map +1 -0
  192. package/dist/lib/util/logger.js +8 -12
  193. package/dist/lib/util/logger.js.map +1 -1
  194. package/dist/lib/util/mark.d.ts +2 -0
  195. package/dist/lib/util/mark.d.ts.map +1 -0
  196. package/dist/lib/util/mark.js +2 -4
  197. package/dist/lib/util/mark.js.map +1 -1
  198. package/dist/lib/util/path.d.ts +2 -0
  199. package/dist/lib/util/path.d.ts.map +1 -0
  200. package/dist/lib/util/path.js +5 -5
  201. package/dist/lib/util/path.js.map +1 -1
  202. package/dist/lib/util/regexp.d.ts +12 -0
  203. package/dist/lib/util/regexp.d.ts.map +1 -0
  204. package/dist/lib/util/regexp.js +11 -14
  205. package/dist/lib/util/regexp.js.map +1 -1
  206. package/dist/lib/util/require.d.ts +3 -0
  207. package/dist/lib/util/require.d.ts.map +1 -0
  208. package/dist/lib/util/require.js +4 -0
  209. package/dist/lib/util/require.js.map +1 -0
  210. package/dist/lib/util/tracker.d.ts +4 -0
  211. package/dist/lib/util/tracker.d.ts.map +1 -0
  212. package/dist/lib/util/tracker.js +63 -86
  213. package/dist/lib/util/tracker.js.map +1 -1
  214. package/dist/lib/util/yn.d.ts +2 -0
  215. package/dist/lib/util/yn.d.ts.map +1 -0
  216. package/dist/lib/util/yn.js +1 -3
  217. package/dist/lib/util/yn.js.map +1 -1
  218. package/dist/server.d.ts +2 -0
  219. package/dist/server.d.ts.map +1 -0
  220. package/dist/server.js +1 -2
  221. package/dist/server.js.map +1 -1
  222. package/lib/api/auth/controller/auth.ts +1 -1
  223. package/lib/api/auth/routes.ts +1 -1
  224. package/lib/api/health/routes.ts +1 -1
  225. package/lib/api/token/routes.ts +1 -1
  226. package/lib/api/tool/routes.ts +1 -1
  227. package/lib/api/users/controller/user.ts +2 -2
  228. package/lib/api/users/routes.ts +1 -1
  229. package/lib/apollo/resolvers.ts +1 -1
  230. package/lib/config/general.ts +1 -3
  231. package/lib/config/plugins.ts +1 -3
  232. package/lib/config/roles.ts +1 -1
  233. package/lib/config/tracking.ts +1 -1
  234. package/lib/hooks/onError.ts +1 -1
  235. package/lib/hooks/onRequest.ts +8 -6
  236. package/lib/hooks/onResponse.ts +1 -1
  237. package/lib/hooks/preHandler.ts +2 -2
  238. package/lib/hooks/preSerialization.ts +2 -2
  239. package/lib/loader/general.ts +13 -9
  240. package/lib/loader/hooks.ts +15 -11
  241. package/lib/loader/plugins.ts +14 -10
  242. package/lib/loader/roles.ts +14 -9
  243. package/lib/loader/router.ts +106 -88
  244. package/lib/loader/schedules.ts +6 -6
  245. package/lib/loader/schemas.ts +27 -19
  246. package/lib/loader/tracking.ts +14 -9
  247. package/lib/loader/translation.ts +9 -14
  248. package/lib/schedules/test.job.ts +1 -1
  249. package/lib/util/common.ts +1 -1
  250. package/lib/util/generate.ts +1 -1
  251. package/lib/util/logger.ts +1 -1
  252. package/lib/util/mark.ts +1 -0
  253. package/lib/util/path.ts +6 -1
  254. package/lib/util/require.ts +3 -0
  255. package/lib/util/tracker.ts +1 -1
  256. package/package.json +24 -15
  257. package/.dockerignore +0 -6
  258. package/.mocharc.json +0 -3
  259. package/.nvmrc +0 -1
  260. package/.prettierignore +0 -5
  261. package/.prettierrc +0 -9
  262. package/DOCKER.md +0 -27
  263. package/Dockerfile +0 -24
  264. package/Dockerfile.prod +0 -33
  265. package/NPM.md +0 -24
  266. package/TODO.md +0 -14
  267. package/combine.js +0 -124
  268. package/dist/lib/locales/en.json +0 -12
  269. package/dist/lib/locales/it.json +0 -12
  270. package/dist/nodemon.json +0 -7
  271. package/dist/package-lock.json +0 -9787
  272. package/dist/package.json +0 -108
  273. package/dist/tsconfig.json +0 -32
  274. package/index.d.ts +0 -16
  275. package/index.ts +0 -410
  276. package/logo-dark.png +0 -0
  277. package/nodemon.json +0 -7
  278. package/server.ts +0 -5
  279. package/test/common/api.ts +0 -80
  280. package/test/common/bootstrap.ts +0 -33
  281. package/test/demo/demo.ts +0 -9
  282. package/test/demo/index.ts +0 -14
  283. package/test/e2e/index.ts +0 -14
  284. package/test/index.spec.ts +0 -20
  285. package/test/unit/index.ts +0 -14
  286. package/test/unit/semver.ts +0 -24
  287. package/test/unit/translation.ts +0 -77
  288. package/tsconfig.json +0 -40
  289. package/types/global.d.ts +0 -225
@@ -1,9 +1,8 @@
1
- import { normalizePatterns } from '../util/path'
1
+ import { normalizePatterns } from '../util/path.js'
2
+ import { globSync } from 'glob'
3
+ import path from 'path'
2
4
 
3
- const glob = require('glob')
4
- const path = require('path')
5
-
6
- export function apply(server: any): void {
5
+ export async function apply(server: any): Promise<void> {
7
6
  const [baseSchemaPath, customSchemaPath] = normalizePatterns(
8
7
  ['..', 'schemas', '*.{ts,js}'],
9
8
  ['src', 'schemas', '*.{ts,js}']
@@ -14,14 +13,19 @@ export function apply(server: any): void {
14
13
  let schemaCount = 0
15
14
 
16
15
  log.t && log.trace('Looking for custom schemas in ' + customSchemaPath)
17
- glob.sync(customSchemaPath).forEach((f: string) => {
16
+ const customFiles = globSync(customSchemaPath, { windowsPathsNoEscape: true })
17
+
18
+ for (const f of customFiles) {
19
+ if (f.endsWith('.d.ts')) continue
20
+
18
21
  try {
19
- const schemaClass = require(f)
20
- const schemaNames = Object.keys(schemaClass)
22
+ const schemaModule = await import(f)
23
+ const schemaClass = schemaModule.default || schemaModule
24
+ const schemaNames = Object.keys(schemaModule)
21
25
 
22
26
  schemaNames.forEach((name) => {
23
- const schema = schemaClass[name]
24
- if (schema?.$id) {
27
+ const schema = schemaModule[name]
28
+ if (schema && typeof schema === 'object' && schema.$id) {
25
29
  customSchemas.push(schema)
26
30
  customSchemaIds.add(schema.$id)
27
31
  }
@@ -29,7 +33,7 @@ export function apply(server: any): void {
29
33
  } catch (e) {
30
34
  log.w && log.warn(`Could not load custom schema file: ${f}`, e)
31
35
  }
32
- })
36
+ }
33
37
 
34
38
  customSchemas.forEach((schema) => {
35
39
  log.trace(`* Registering custom schema [${schema.$id}]`)
@@ -38,15 +42,19 @@ export function apply(server: any): void {
38
42
  })
39
43
 
40
44
  log.t && log.trace('Looking for base schemas in ' + baseSchemaPath)
41
- glob.sync(baseSchemaPath).forEach((f: string) => {
45
+ const baseFiles = globSync(baseSchemaPath, { windowsPathsNoEscape: true })
46
+
47
+ for (const f of baseFiles) {
48
+ if (f.endsWith('.d.ts')) continue
49
+
42
50
  try {
43
51
  const schemaFileName = path.basename(f)
44
- const schemaClass = require(f)
45
- const schemaNames = Object.keys(schemaClass)
52
+ const schemaModule = await import(f)
53
+ const schemaNames = Object.keys(schemaModule)
46
54
 
47
55
  schemaNames.forEach((name) => {
48
- const schema = schemaClass[name]
49
- if (schema?.$id) {
56
+ const schema = schemaModule[name]
57
+ if (schema && typeof schema === 'object' && schema.$id) {
50
58
  if (customSchemaIds.has(schema.$id)) {
51
59
  log.w &&
52
60
  log.warn(
@@ -57,14 +65,14 @@ export function apply(server: any): void {
57
65
  server.addSchema(schema)
58
66
  schemaCount++
59
67
  }
60
- } else {
61
- log.w && log.warn(`* Schema with no $id found in ${schemaFileName}, cannot be registered.`)
68
+ } else if (name !== 'default') {
69
+ log.w && log.warn(`* Schema with no $id found in ${schemaFileName} (export ${name}), cannot be registered.`)
62
70
  }
63
71
  })
64
72
  } catch (e) {
65
73
  log.w && log.warn(`Could not load base schema file: ${f}`, e)
66
74
  }
67
- })
75
+ }
68
76
 
69
77
  log.d && log.debug(`Schemas loaded: ${schemaCount} referenceable by $ref`)
70
78
  }
@@ -1,18 +1,23 @@
1
- import { TrackChanges, TrackChangesList, Data } from '../../types/global'
2
- import { normalizePatterns } from '../util/path'
3
- const glob = require('glob')
1
+ import type { TrackChanges, TrackChangesList, Data } from '../../types/global.js'
2
+ import { normalizePatterns } from '../util/path.js'
3
+ import { globSync } from 'glob'
4
4
 
5
5
  const METHODS = ['POST', 'PUT', 'DELETE']
6
6
 
7
- export function load() {
7
+ export async function load() {
8
8
  const trackChangesList: TrackChangesList = {}
9
9
  let trackConfig: Data = {}
10
10
 
11
11
  const patterns = normalizePatterns(['..', 'config', 'tracking.{ts,js}'], ['src', 'config', 'tracking.{ts,js}'])
12
- patterns.forEach((pattern) => {
12
+
13
+ for (const pattern of patterns) {
13
14
  log.t && log.trace('Looking for ' + pattern)
14
- glob.sync(pattern).forEach((f: string) => {
15
- const configTracking = require(f)
15
+ const files = globSync(pattern, { windowsPathsNoEscape: true })
16
+
17
+ for (const f of files) {
18
+ const module = await import(f)
19
+ const configTracking = module.default || module
20
+
16
21
  const { config, changes } = configTracking || {}
17
22
  const { enableAll = true, primaryKey = 'id', changeEntity = 'Change' } = config || {}
18
23
 
@@ -30,8 +35,8 @@ export function load() {
30
35
  trackChangesList[code] = tc
31
36
  }
32
37
  })
33
- })
34
- })
38
+ }
39
+ }
35
40
 
36
41
  const keys = Object.keys(trackChangesList) || []
37
42
  log.d && log.debug(`Tracking changes loaded: ${keys?.length || 0}`)
@@ -1,8 +1,11 @@
1
- const path = require('path')
2
- const glob = require('glob')
3
- const { I18n } = require('i18n')
1
+ import path from 'path'
2
+ import { globSync } from 'glob'
3
+ import { I18n } from 'i18n'
4
+ import { fileURLToPath } from 'url'
5
+ import require from '../util/require.js'
4
6
 
5
- // import { normalizePatterns } from '../util/path'
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = path.dirname(__filename)
6
9
 
7
10
  export function load(): any {
8
11
  const i18n = new I18n({
@@ -25,7 +28,7 @@ export function load(): any {
25
28
 
26
29
  const basePath = path.join(__dirname, '..', 'locales', '*.json').replaceAll('\\', '/')
27
30
 
28
- glob.sync(basePath).forEach((f: string) => {
31
+ globSync(basePath, { windowsPathsNoEscape: true }).forEach((f: string) => {
29
32
  log.info('* Loading base dictionary %s', path.parse(f).base)
30
33
  try {
31
34
  const content = require(f)
@@ -37,7 +40,7 @@ export function load(): any {
37
40
 
38
41
  const addPath = path.join(process.cwd(), 'src', 'locales', '*.json').replaceAll('\\', '/')
39
42
 
40
- glob.sync(addPath).forEach((f: string) => {
43
+ globSync(addPath, { windowsPathsNoEscape: true }).forEach((f: string) => {
41
44
  log.info('* Loading additional dictionary %s', path.parse(f).base)
42
45
  try {
43
46
  const content = require(f)
@@ -48,14 +51,6 @@ export function load(): any {
48
51
  })
49
52
 
50
53
  i18n.setLocale(i18n.defaultLocale || 'en')
51
- // let test1 = i18n.__('greeting.formal')
52
- // let test2 = i18n.__('hello')
53
- // let test3 = i18n.__('greeting.placeholder.formal', 'UGO')
54
- // let test4 = i18n.__('greeting.placeholder.formalize:Buondì %s', 'UGO')
55
- // let test5 = i18n.__('greeting.formal')
56
- // let test6 = i18n.__({ phrase: 'greeting.formal', locale: 'it' })
57
- // let test7 = i18n.__({ phrase: 'greeting.placeholder.formal', locale: 'it' }, 'UGO')
58
- // i18n.setLocale(i18n.defaultLocale || 'en')
59
54
  return i18n
60
55
  }
61
56
 
@@ -1,4 +1,4 @@
1
- import { JobSchedule } from '../../types/global'
1
+ import type { JobSchedule } from '../../types/global.js'
2
2
 
3
3
  export const schedule: JobSchedule = {
4
4
  active: false,
@@ -1,5 +1,5 @@
1
1
  import { FastifyRequest } from 'fastify'
2
- import { Data } from '../../types/global'
2
+ import type { Data } from '../../types/global.js'
3
3
 
4
4
  export function getData(req: FastifyRequest): Data {
5
5
  if (!req) return {}
@@ -1,4 +1,4 @@
1
- const { customAlphabet } = require('nanoid')
1
+ import { customAlphabet } from 'nanoid'
2
2
  const nanoid = customAlphabet('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789')
3
3
 
4
4
  export function newAuthCode() {
@@ -12,7 +12,7 @@
12
12
  // log.trace('test log test log test log')
13
13
 
14
14
  import pino from 'pino'
15
- import yn from './yn'
15
+ import yn from './yn.js'
16
16
 
17
17
  const logLevels = ['fatal', 'error', 'warn', 'info', 'debug', 'trace']
18
18
 
package/lib/util/mark.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import require from './require.js'
1
2
  const pkg = require('root-require')('package.json')
2
3
 
3
4
  /**
package/lib/util/path.ts CHANGED
@@ -1,4 +1,9 @@
1
- const path = require('path')
1
+ import path from 'path'
2
+ import { fileURLToPath } from 'url'
3
+
4
+ const __filename = fileURLToPath(import.meta.url)
5
+ const __dirname = path.dirname(__filename)
6
+
2
7
  export function normalizePatterns(path1: Array<string>, path2: Array<string>): Array<string> {
3
8
  // replaceAll is needed for windows
4
9
  return [
@@ -0,0 +1,3 @@
1
+ import { createRequire } from 'module'
2
+ const require = createRequire(import.meta.url)
3
+ export default require
@@ -1,5 +1,5 @@
1
1
  import dayjs from 'dayjs'
2
- import { FastifyRequest, FastifyReply } from '../../types/global'
2
+ import type { FastifyRequest, FastifyReply } from '../../types/global.js'
3
3
 
4
4
  export async function initialize(req: FastifyRequest, reply: FastifyReply) {
5
5
  if (req.server['dataBaseManager'].isImplemented()) {
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@volcanicminds/backend",
3
- "version": "2.0.4",
3
+ "version": "2.1.1",
4
+ "type": "module",
4
5
  "codename": "rome",
5
6
  "license": "MIT",
6
7
  "description": "The volcanic (minds) backend",
@@ -27,23 +28,32 @@
27
28
  "rate limit",
28
29
  "jest"
29
30
  ],
30
- "main": "dist/index",
31
- "typings": "dist/index",
31
+ "main": "dist/index.js",
32
+ "module": "dist/index.js",
33
+ "types": "dist/index.d.ts",
34
+ "sideEffects": false,
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js",
39
+ "require": "./dist/index.js"
40
+ }
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "lib"
45
+ ],
32
46
  "scripts": {
33
- "clean": "rm -rf dist esm",
47
+ "clean": "rm -rf dist",
34
48
  "prebuild": "npm run clean",
35
- "build:esm": "tsc --target es2018 --outDir esm",
36
- "build:cjs": "tsc --target es2015 --module commonjs --outDir dist",
37
- "build": "npm run build:esm && npm run build:cjs",
38
- "compile": "npm run build",
49
+ "build": "tsc",
39
50
  "preprod": "npm run build",
40
51
  "prod": "cd dist && node server.js",
41
- "server": "cd dist && node server.js",
42
- "start": "ts-node server.ts",
43
- "dev": "nodemon --exec \"ts-node\" server.ts",
52
+ "start": "tsx server.ts",
53
+ "dev": "node --import tsx/esm --watch server.ts",
44
54
  "test": "npm run test:full",
45
- "test:full": "cross-env PORT=2231 NODE_ENV=memory BROWSER=false mocha ./test/index.spec.ts -t 100000",
46
- "reset": "npm install && npm update && npm run compile",
55
+ "test:full": "cross-env PORT=2231 NODE_ENV=memory BROWSER=false mocha --loader=tsx ./test/index.spec.ts -t 100000",
56
+ "reset": "npm install && npm update && npm run build",
47
57
  "upgrade-deps": "npx npm-check-updates -u",
48
58
  "combine": "node combine.js"
49
59
  },
@@ -81,9 +91,8 @@
81
91
  "cross-env": "^10.1.0",
82
92
  "expect": "^30.2.0",
83
93
  "mocha": "^11.7.5",
84
- "nodemon": "^3.1.10",
85
94
  "npm-upgrade": "^3.1.2",
86
- "ts-node": "^10.9.2",
95
+ "tsx": "^4.19.2",
87
96
  "typescript": "^5.9.3"
88
97
  },
89
98
  "repository": {
package/.dockerignore DELETED
@@ -1,6 +0,0 @@
1
- .git
2
- dist
3
- esm
4
- test
5
- node_modules
6
- **/node_modules
package/.mocharc.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "loader": "ts-node/esm"
3
- }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- v24.11.0
package/.prettierignore DELETED
@@ -1,5 +0,0 @@
1
- node_modules
2
-
3
- # Ignore artifacts:
4
- build
5
- coverage
package/.prettierrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "semi": false,
3
- "singleQuote": true,
4
- "useTabs": false,
5
- "bracketSpacing": true,
6
- "trailingComma": "none",
7
- "tabWidth": 2,
8
- "printWidth": 120
9
- }
package/DOCKER.md DELETED
@@ -1,27 +0,0 @@
1
- # Docker
2
-
3
- try to use these to run the app in a docker node:16-alpine image:
4
-
5
- ```js
6
-
7
- // easy
8
- docker build -t volcanic-backend .
9
- docker run -dp 2230:2230 -it volcanic-backend
10
-
11
- // prod
12
- docker build -f Dockerfile.prod -t volcanic-backend-prod .
13
- docker run -dp 2230:2230 -it volcanic-backend-prod
14
-
15
- // detached mode with autoremove when stopped
16
- docker run --rm -dp 2230:2230 -it volcanic-backend
17
-
18
- // attached mode with autoremove when stopped
19
- docker run --rm -p 2230:2230 -it volcanic-backend
20
-
21
- // remove
22
- docker image rm volcanic-backend
23
-
24
- // prune all
25
- docker system prune --all
26
-
27
- ```
package/Dockerfile DELETED
@@ -1,24 +0,0 @@
1
- FROM --platform=linux/amd64 node:18-alpine AS builder
2
-
3
- # Create app directory
4
- WORKDIR /usr/src/app
5
-
6
- # Install app dependencies
7
- COPY package*.json ./
8
- COPY lib lib/
9
-
10
- RUN npm install
11
-
12
- # Bundle app source
13
- COPY . .
14
-
15
- FROM --platform=linux/amd64 node:18-alpine
16
- LABEL version="0.1.0"
17
- LABEL description="Volcanic Backend"
18
- LABEL maintainer="Developers <developers@volcanicminds.com>"
19
-
20
- WORKDIR /usr/src/app
21
- COPY --from=builder /usr/src/app .
22
-
23
- EXPOSE 2230
24
- CMD [ "npm", "run start" ]
package/Dockerfile.prod DELETED
@@ -1,33 +0,0 @@
1
- FROM --platform=linux/amd64 node:18-alpine AS builder
2
-
3
- # Create app directory
4
- WORKDIR /usr/src/app
5
-
6
- # Install app dependencies
7
- COPY package*.json ./
8
- COPY lib lib/
9
-
10
- RUN npm install \
11
- --prefer-offline \
12
- --non-interactive
13
-
14
- # Bundle app source
15
- COPY . .
16
-
17
- RUN npm run compile && \
18
- rm -rf node_modules && \
19
- npm install \
20
- --prefer-offline \
21
- --non-interactive \
22
- --production
23
-
24
- FROM --platform=linux/amd64 node:18-alpine
25
- LABEL version="0.1.0"
26
- LABEL description="Volcanic Backend"
27
- LABEL maintainer="Developers <developers@volcanicminds.com>"
28
-
29
- WORKDIR /usr/src/app
30
- COPY --from=builder /usr/src/app .
31
-
32
- EXPOSE 2230
33
- CMD [ "npm", "run server" ]
package/NPM.md DELETED
@@ -1,24 +0,0 @@
1
- # NPM
2
-
3
- [more info](https://zellwk.com/blog/publish-to-npm/)
4
-
5
- ## how to publish
6
-
7
- ```ruby
8
- npm install npm@latest -g
9
- npm login
10
- npm init --scope=volcanicminds
11
- npm publish --access public
12
- ```
13
-
14
- ## local linking
15
-
16
- ```ruby
17
- npm link
18
- npm link "@volcanicminds/backend"
19
- ```
20
-
21
- ```ruby
22
- npm unlink
23
- npm unlink "@volcanicminds/backend"
24
- ```
package/TODO.md DELETED
@@ -1,14 +0,0 @@
1
- # TODO
2
-
3
- - add example / demo project (with @volcanicminds/backend & @volcanicminds/typeorm)
4
- - validations (see typeorm)
5
- - subscribers / hooks (Active Records: in separated files)
6
- - api versioning
7
-
8
- ## Useful links
9
-
10
- https://tutorialjavascript.altervista.org/moduli-typescript
11
- https://swagger.io/specification/v2/#swaggerObject
12
- https://github.com/fastify/fastify-swagger
13
- https://www.fastify.io/docs/latest/Reference/Validation-and-Serialization/
14
- https://json-schema.org/draft/2020-12/json-schema-validation.html#name-pattern
package/combine.js DELETED
@@ -1,124 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
-
4
- const MAIN_DIRECTORY = './'
5
- const INCLUDE_FILES = ['package.json', 'tsconfig.json', 'README.md', '.nvmrc', 'index.ts', 'index.d.ts']
6
- const SUB_DIRECTORIES = ['lib', 'types']
7
- const OUTPUT_FILE = 'OUTPUT.md'
8
-
9
- /**
10
- * Recursively collects .js and .ts files from a given directory.
11
- *
12
- * @param {string} directory - _The directory to scan recursively._
13
- * @returns {Array<{ relativePath: string }>} - _List of file objects with relative paths._
14
- */
15
- const getFilesFromDirectory = (directory) => {
16
- let filesList = []
17
- const items = fs.readdirSync(directory)
18
-
19
- items.forEach((item) => {
20
- const itemPath = path.join(directory, item)
21
- const stats = fs.statSync(itemPath)
22
-
23
- if (stats.isDirectory()) {
24
- filesList = filesList.concat(getFilesFromDirectory(itemPath))
25
- } else if (
26
- item.endsWith('.html') ||
27
- item.endsWith('.vue') ||
28
- item.endsWith('.css') ||
29
- item.endsWith('.json') ||
30
- item.endsWith('.js') ||
31
- item.endsWith('.ts') ||
32
- item.endsWith('.md')
33
- ) {
34
- filesList.push({ relativePath: path.relative(MAIN_DIRECTORY, itemPath) })
35
- }
36
- })
37
-
38
- return filesList
39
- }
40
-
41
- /**
42
- * Retrieves files from the specified subdirectories.
43
- *
44
- * @returns {Object} - _Object containing individual subdirectory files and a combined list._
45
- */
46
- const getFilesFromSubDirectories = () => {
47
- const subDirectoryFiles = {}
48
- let combinedFiles = []
49
-
50
- SUB_DIRECTORIES.forEach((dir) => {
51
- const files = getFilesFromDirectory(dir)
52
- subDirectoryFiles[dir] = files
53
- combinedFiles = combinedFiles.concat(files)
54
- })
55
-
56
- return { subDirectoryFiles, combinedFiles }
57
- }
58
-
59
- async function generateMarkdown() {
60
- const rootFiles = fs
61
- .readdirSync(MAIN_DIRECTORY)
62
- .filter(
63
- (file) =>
64
- file.endsWith('.html') ||
65
- (file.endsWith('.ts') && file !== 'combine.ts') ||
66
- (file.endsWith('.js') && file !== 'combine.js') ||
67
- INCLUDE_FILES.includes(file)
68
- )
69
- .map((file) => ({ relativePath: file }))
70
-
71
- const { subDirectoryFiles, combinedFiles } = getFilesFromSubDirectories()
72
- const allFiles = [...rootFiles, ...combinedFiles]
73
- const currentISOString = new Date().toISOString()
74
-
75
- const markdownLines = []
76
- markdownLines.push('# Full Project - Updated At ' + currentISOString, '')
77
- markdownLines.push('Below are all the files, materials and documentation of the project to analyze.', '')
78
- markdownLines.push('```bash')
79
- markdownLines.push('./')
80
-
81
- rootFiles.forEach((file) => {
82
- markdownLines.push(`├── ${file.relativePath}`)
83
- })
84
-
85
- if (SUB_DIRECTORIES.length > 0) {
86
- SUB_DIRECTORIES.forEach((dir) => {
87
- markdownLines.push(`├── ${dir}`)
88
-
89
- const sortedSubFiles = subDirectoryFiles[dir].sort((a, b) => a.relativePath.localeCompare(b.relativePath))
90
- sortedSubFiles.forEach((file) => {
91
- const displayPath = file.relativePath.replace(new RegExp(`^(${SUB_DIRECTORIES.join('|')})[\\\\/]`), '')
92
- markdownLines.push(` ├── ${displayPath}`)
93
- })
94
- })
95
- }
96
- markdownLines.push('```', '')
97
-
98
- markdownLines.push('## Source Files Index', '')
99
- allFiles.forEach((file) => {
100
- const filePath = file.relativePath
101
-
102
- const slug = filePath.replace(/[\/.]/g, '-')
103
- markdownLines.push(`- [${filePath}](#file-${slug})`)
104
- })
105
- markdownLines.push('')
106
-
107
- for (const file of allFiles) {
108
- const filePath = file.relativePath
109
- const fullPath = path.join(MAIN_DIRECTORY, filePath)
110
-
111
- const language = filePath.endsWith('.md') ? 'markdown' : filePath.endsWith('.ts') ? 'typescript' : 'javascript'
112
-
113
- const fileContent = fs.readFileSync(fullPath, 'utf-8')
114
- markdownLines.push(`## File: ${filePath}`, '')
115
- markdownLines.push('```' + language)
116
- markdownLines.push(fileContent)
117
- markdownLines.push('```', '')
118
- }
119
-
120
- fs.writeFileSync(OUTPUT_FILE, markdownLines.join('\n'))
121
- console.log(`Markdown file generated: ${OUTPUT_FILE}`)
122
- }
123
-
124
- generateMarkdown()
@@ -1,12 +0,0 @@
1
- {
2
- "hello": "Hello",
3
- "greeting": {
4
- "formal": "Hello",
5
- "informal": "Hi",
6
- "placeholder": {
7
- "formal": "Hello %s",
8
- "informal": "Hi %s"
9
- }
10
- },
11
- "complex": "Hello {{user.firstname}} {{user.lastname}}"
12
- }
@@ -1,12 +0,0 @@
1
- {
2
- "hello": "Ciao",
3
- "greeting": {
4
- "formal": "Ciao",
5
- "informal": "Cià",
6
- "placeholder": {
7
- "formal": "Ciao %s",
8
- "informal": "Cià %s"
9
- }
10
- },
11
- "complex": "Ciao {{user.firstname}} {{user.lastname}}"
12
- }
package/dist/nodemon.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "watch": ["lib"],
3
- "verbose": true,
4
- "ext": "js,ts,json,jsonc",
5
- "ignore": [".git", "coverage", "dist", "lib/**/*.spec.ts", "node_modules"],
6
- "exec": "ts-node ./lib/index.ts"
7
- }