@intlayer/backend 5.6.0 → 5.7.0

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 (508) hide show
  1. package/README.md +3 -0
  2. package/dist/cjs/controllers/ai.controller.cjs +10 -7
  3. package/dist/cjs/controllers/ai.controller.cjs.map +1 -1
  4. package/dist/cjs/controllers/dictionary.controller.cjs +50 -58
  5. package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
  6. package/dist/cjs/controllers/eventListener.controller.cjs +2 -18
  7. package/dist/cjs/controllers/eventListener.controller.cjs.map +1 -1
  8. package/dist/cjs/controllers/newsletter.controller.cjs +38 -3
  9. package/dist/cjs/controllers/newsletter.controller.cjs.map +1 -1
  10. package/dist/cjs/controllers/oAuth2.controller.cjs +3 -3
  11. package/dist/cjs/controllers/oAuth2.controller.cjs.map +1 -1
  12. package/dist/cjs/controllers/organization.controller.cjs +92 -106
  13. package/dist/cjs/controllers/organization.controller.cjs.map +1 -1
  14. package/dist/cjs/controllers/project.controller.cjs +81 -83
  15. package/dist/cjs/controllers/project.controller.cjs.map +1 -1
  16. package/dist/cjs/controllers/projectAccessKey.controller.cjs +30 -24
  17. package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -1
  18. package/dist/cjs/controllers/search.controller.cjs.map +1 -1
  19. package/dist/cjs/controllers/stripe.controller.cjs +4 -25
  20. package/dist/cjs/controllers/stripe.controller.cjs.map +1 -1
  21. package/dist/cjs/controllers/tag.controller.cjs +27 -16
  22. package/dist/cjs/controllers/tag.controller.cjs.map +1 -1
  23. package/dist/cjs/controllers/user.controller.cjs +88 -24
  24. package/dist/cjs/controllers/user.controller.cjs.map +1 -1
  25. package/dist/cjs/emails/InviteUserEmail.cjs +30 -12
  26. package/dist/cjs/emails/InviteUserEmail.cjs.map +1 -1
  27. package/dist/cjs/emails/OAuthTokenCreatedEmail.cjs +266 -0
  28. package/dist/cjs/emails/OAuthTokenCreatedEmail.cjs.map +1 -0
  29. package/dist/cjs/emails/ResetUserPassword.cjs +27 -15
  30. package/dist/cjs/emails/ResetUserPassword.cjs.map +1 -1
  31. package/dist/cjs/emails/ValidateUserEmail.cjs +27 -36
  32. package/dist/cjs/emails/ValidateUserEmail.cjs.map +1 -1
  33. package/dist/cjs/emails/Welcome.cjs +27 -15
  34. package/dist/cjs/emails/Welcome.cjs.map +1 -1
  35. package/dist/cjs/emails/index.cjs +7 -5
  36. package/dist/cjs/emails/index.cjs.map +1 -1
  37. package/dist/cjs/export.cjs +2 -5
  38. package/dist/cjs/export.cjs.map +1 -1
  39. package/dist/cjs/index.cjs +61 -111
  40. package/dist/cjs/index.cjs.map +1 -1
  41. package/dist/cjs/middlewares/oAuth2.middleware.cjs +26 -38
  42. package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -1
  43. package/dist/cjs/middlewares/request.middleware.cjs.map +1 -1
  44. package/dist/cjs/middlewares/sessionAuth.middleware.cjs +17 -138
  45. package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +1 -1
  46. package/dist/cjs/models/dictionary.model.cjs.map +1 -1
  47. package/dist/cjs/models/discussion.model.cjs.map +1 -1
  48. package/dist/cjs/models/oAuth2.model.cjs +4 -1
  49. package/dist/cjs/models/oAuth2.model.cjs.map +1 -1
  50. package/dist/cjs/models/organization.model.cjs +1 -4
  51. package/dist/cjs/models/organization.model.cjs.map +1 -1
  52. package/dist/cjs/models/project.model.cjs +4 -1
  53. package/dist/cjs/models/project.model.cjs.map +1 -1
  54. package/dist/cjs/models/session.model.cjs +34 -0
  55. package/dist/cjs/models/session.model.cjs.map +1 -0
  56. package/dist/cjs/models/tag.model.cjs.map +1 -1
  57. package/dist/cjs/models/user.model.cjs.map +1 -1
  58. package/dist/cjs/routes/ai.routes.cjs +3 -1
  59. package/dist/cjs/routes/ai.routes.cjs.map +1 -1
  60. package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
  61. package/dist/cjs/routes/eventListener.routes.cjs +1 -1
  62. package/dist/cjs/routes/eventListener.routes.cjs.map +1 -1
  63. package/dist/cjs/routes/newsletter.routes.cjs.map +1 -1
  64. package/dist/cjs/routes/organization.routes.cjs +8 -8
  65. package/dist/cjs/routes/organization.routes.cjs.map +1 -1
  66. package/dist/cjs/routes/project.routes.cjs +23 -14
  67. package/dist/cjs/routes/project.routes.cjs.map +1 -1
  68. package/dist/cjs/routes/search.routes.cjs.map +1 -1
  69. package/dist/cjs/routes/stripe.routes.cjs.map +1 -1
  70. package/dist/cjs/routes/tags.routes.cjs +4 -4
  71. package/dist/cjs/routes/tags.routes.cjs.map +1 -1
  72. package/dist/cjs/routes/user.routes.cjs +12 -12
  73. package/dist/cjs/routes/user.routes.cjs.map +1 -1
  74. package/dist/cjs/schemas/dictionary.schema.cjs +18 -1
  75. package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
  76. package/dist/cjs/schemas/discussion.schema.cjs +18 -1
  77. package/dist/cjs/schemas/discussion.schema.cjs.map +1 -1
  78. package/dist/cjs/schemas/oAuth2.schema.cjs +18 -1
  79. package/dist/cjs/schemas/oAuth2.schema.cjs.map +1 -1
  80. package/dist/cjs/schemas/organization.schema.cjs +21 -1
  81. package/dist/cjs/schemas/organization.schema.cjs.map +1 -1
  82. package/dist/cjs/schemas/plans.schema.cjs +18 -1
  83. package/dist/cjs/schemas/plans.schema.cjs.map +1 -1
  84. package/dist/cjs/schemas/project.schema.cjs +19 -14
  85. package/dist/cjs/schemas/project.schema.cjs.map +1 -1
  86. package/dist/cjs/schemas/session.schema.cjs +63 -0
  87. package/dist/cjs/schemas/session.schema.cjs.map +1 -0
  88. package/dist/cjs/schemas/tag.schema.cjs +18 -1
  89. package/dist/cjs/schemas/tag.schema.cjs.map +1 -1
  90. package/dist/cjs/schemas/user.schema.cjs +18 -48
  91. package/dist/cjs/schemas/user.schema.cjs.map +1 -1
  92. package/dist/cjs/services/dictionary.service.cjs +6 -5
  93. package/dist/cjs/services/dictionary.service.cjs.map +1 -1
  94. package/dist/cjs/services/email.service.cjs +13 -0
  95. package/dist/cjs/services/email.service.cjs.map +1 -1
  96. package/dist/cjs/services/oAuth2.service.cjs +49 -10
  97. package/dist/cjs/services/oAuth2.service.cjs.map +1 -1
  98. package/dist/cjs/services/organization.service.cjs +16 -15
  99. package/dist/cjs/services/organization.service.cjs.map +1 -1
  100. package/dist/cjs/services/project.service.cjs +1 -1
  101. package/dist/cjs/services/project.service.cjs.map +1 -1
  102. package/dist/cjs/services/projectAccessKey.service.cjs +17 -33
  103. package/dist/cjs/services/projectAccessKey.service.cjs.map +1 -1
  104. package/dist/cjs/services/subscription.service.cjs +10 -10
  105. package/dist/cjs/services/subscription.service.cjs.map +1 -1
  106. package/dist/cjs/services/tag.service.cjs.map +1 -1
  107. package/dist/cjs/services/user.service.cjs +2 -42
  108. package/dist/cjs/services/user.service.cjs.map +1 -1
  109. package/dist/cjs/types/dictionary.types.cjs.map +1 -1
  110. package/dist/cjs/types/discussion.types.cjs.map +1 -1
  111. package/dist/cjs/types/oAuth2.types.cjs.map +1 -1
  112. package/dist/cjs/types/organization.types.cjs.map +1 -1
  113. package/dist/cjs/types/plan.types.cjs.map +1 -1
  114. package/dist/cjs/types/project.types.cjs.map +1 -1
  115. package/dist/cjs/types/session.types.cjs.map +1 -1
  116. package/dist/cjs/types/tag.types.cjs.map +1 -1
  117. package/dist/cjs/types/user.types.cjs.map +1 -1
  118. package/dist/cjs/utils/AI/aiSdk.cjs.map +1 -1
  119. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs +14 -9
  120. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs.map +1 -1
  121. package/dist/cjs/utils/AI/autocomplete/PROMPT.md +18 -2
  122. package/dist/cjs/utils/AI/autocomplete/index.cjs +8 -5
  123. package/dist/cjs/utils/AI/autocomplete/index.cjs.map +1 -1
  124. package/dist/cjs/utils/access.cjs +2 -0
  125. package/dist/cjs/utils/access.cjs.map +1 -0
  126. package/dist/cjs/utils/accessControl.cjs +7 -0
  127. package/dist/cjs/utils/accessControl.cjs.map +1 -1
  128. package/dist/cjs/utils/auth/getAuth.cjs +248 -0
  129. package/dist/cjs/utils/auth/getAuth.cjs.map +1 -0
  130. package/dist/cjs/utils/cors.cjs +55 -0
  131. package/dist/cjs/utils/cors.cjs.map +1 -0
  132. package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +1 -1
  133. package/dist/cjs/utils/errors/ErrorHandler.cjs +2 -2
  134. package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
  135. package/dist/cjs/utils/errors/errorCodes.cjs +114 -153
  136. package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
  137. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
  138. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
  139. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -1
  140. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +1 -1
  141. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
  142. package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
  143. package/dist/cjs/utils/mapper/organization.cjs +10 -8
  144. package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
  145. package/dist/cjs/utils/mapper/project.cjs +5 -18
  146. package/dist/cjs/utils/mapper/project.cjs.map +1 -1
  147. package/dist/cjs/utils/mapper/tag.cjs +4 -2
  148. package/dist/cjs/utils/mapper/tag.cjs.map +1 -1
  149. package/dist/cjs/utils/mapper/user.cjs +6 -3
  150. package/dist/cjs/utils/mapper/user.cjs.map +1 -1
  151. package/dist/cjs/utils/mergeFunctionTypes.cjs +17 -0
  152. package/dist/cjs/utils/mergeFunctionTypes.cjs.map +1 -0
  153. package/dist/cjs/utils/mongoDB/connectDB.cjs +3 -1
  154. package/dist/cjs/utils/mongoDB/connectDB.cjs.map +1 -1
  155. package/dist/cjs/utils/mongoDB/types.cjs +17 -0
  156. package/dist/cjs/utils/mongoDB/types.cjs.map +1 -0
  157. package/dist/cjs/utils/oAuth2.cjs.map +1 -1
  158. package/dist/cjs/utils/permissions.cjs +166 -0
  159. package/dist/cjs/utils/permissions.cjs.map +1 -0
  160. package/dist/cjs/utils/rateLimiter.cjs +88 -0
  161. package/dist/cjs/utils/rateLimiter.cjs.map +1 -0
  162. package/dist/esm/controllers/ai.controller.mjs +10 -7
  163. package/dist/esm/controllers/ai.controller.mjs.map +1 -1
  164. package/dist/esm/controllers/dictionary.controller.mjs +50 -58
  165. package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
  166. package/dist/esm/controllers/eventListener.controller.mjs +2 -8
  167. package/dist/esm/controllers/eventListener.controller.mjs.map +1 -1
  168. package/dist/esm/controllers/newsletter.controller.mjs +38 -3
  169. package/dist/esm/controllers/newsletter.controller.mjs.map +1 -1
  170. package/dist/esm/controllers/oAuth2.controller.mjs +2 -2
  171. package/dist/esm/controllers/oAuth2.controller.mjs.map +1 -1
  172. package/dist/esm/controllers/organization.controller.mjs +95 -106
  173. package/dist/esm/controllers/organization.controller.mjs.map +1 -1
  174. package/dist/esm/controllers/project.controller.mjs +81 -83
  175. package/dist/esm/controllers/project.controller.mjs.map +1 -1
  176. package/dist/esm/controllers/projectAccessKey.controller.mjs +30 -24
  177. package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
  178. package/dist/esm/controllers/search.controller.mjs.map +1 -1
  179. package/dist/esm/controllers/stripe.controller.mjs +4 -25
  180. package/dist/esm/controllers/stripe.controller.mjs.map +1 -1
  181. package/dist/esm/controllers/tag.controller.mjs +27 -16
  182. package/dist/esm/controllers/tag.controller.mjs.map +1 -1
  183. package/dist/esm/controllers/user.controller.mjs +85 -22
  184. package/dist/esm/controllers/user.controller.mjs.map +1 -1
  185. package/dist/esm/emails/InviteUserEmail.mjs +32 -14
  186. package/dist/esm/emails/InviteUserEmail.mjs.map +1 -1
  187. package/dist/esm/emails/OAuthTokenCreatedEmail.mjs +254 -0
  188. package/dist/esm/emails/OAuthTokenCreatedEmail.mjs.map +1 -0
  189. package/dist/esm/emails/ResetUserPassword.mjs +29 -17
  190. package/dist/esm/emails/ResetUserPassword.mjs.map +1 -1
  191. package/dist/esm/emails/ValidateUserEmail.mjs +29 -38
  192. package/dist/esm/emails/ValidateUserEmail.mjs.map +1 -1
  193. package/dist/esm/emails/Welcome.mjs +29 -17
  194. package/dist/esm/emails/Welcome.mjs.map +1 -1
  195. package/dist/esm/emails/index.mjs +3 -2
  196. package/dist/esm/emails/index.mjs.map +1 -1
  197. package/dist/esm/export.mjs +1 -3
  198. package/dist/esm/export.mjs.map +1 -1
  199. package/dist/esm/index.mjs +60 -111
  200. package/dist/esm/index.mjs.map +1 -1
  201. package/dist/esm/middlewares/oAuth2.middleware.mjs +27 -36
  202. package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
  203. package/dist/esm/middlewares/request.middleware.mjs.map +1 -1
  204. package/dist/esm/middlewares/sessionAuth.middleware.mjs +16 -127
  205. package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -1
  206. package/dist/esm/models/dictionary.model.mjs.map +1 -1
  207. package/dist/esm/models/discussion.model.mjs.map +1 -1
  208. package/dist/esm/models/oAuth2.model.mjs +4 -1
  209. package/dist/esm/models/oAuth2.model.mjs.map +1 -1
  210. package/dist/esm/models/organization.model.mjs +1 -4
  211. package/dist/esm/models/organization.model.mjs.map +1 -1
  212. package/dist/esm/models/project.model.mjs +4 -1
  213. package/dist/esm/models/project.model.mjs.map +1 -1
  214. package/dist/esm/models/session.model.mjs +10 -0
  215. package/dist/esm/models/session.model.mjs.map +1 -0
  216. package/dist/esm/models/tag.model.mjs.map +1 -1
  217. package/dist/esm/models/user.model.mjs.map +1 -1
  218. package/dist/esm/routes/ai.routes.mjs +3 -1
  219. package/dist/esm/routes/ai.routes.mjs.map +1 -1
  220. package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
  221. package/dist/esm/routes/eventListener.routes.mjs +1 -1
  222. package/dist/esm/routes/eventListener.routes.mjs.map +1 -1
  223. package/dist/esm/routes/newsletter.routes.mjs.map +1 -1
  224. package/dist/esm/routes/organization.routes.mjs +8 -8
  225. package/dist/esm/routes/organization.routes.mjs.map +1 -1
  226. package/dist/esm/routes/project.routes.mjs +23 -14
  227. package/dist/esm/routes/project.routes.mjs.map +1 -1
  228. package/dist/esm/routes/search.routes.mjs.map +1 -1
  229. package/dist/esm/routes/stripe.routes.mjs.map +1 -1
  230. package/dist/esm/routes/tags.routes.mjs +4 -4
  231. package/dist/esm/routes/tags.routes.mjs.map +1 -1
  232. package/dist/esm/routes/user.routes.mjs +14 -14
  233. package/dist/esm/routes/user.routes.mjs.map +1 -1
  234. package/dist/esm/schemas/dictionary.schema.mjs +18 -1
  235. package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
  236. package/dist/esm/schemas/discussion.schema.mjs +18 -1
  237. package/dist/esm/schemas/discussion.schema.mjs.map +1 -1
  238. package/dist/esm/schemas/oAuth2.schema.mjs +18 -1
  239. package/dist/esm/schemas/oAuth2.schema.mjs.map +1 -1
  240. package/dist/esm/schemas/organization.schema.mjs +21 -1
  241. package/dist/esm/schemas/organization.schema.mjs.map +1 -1
  242. package/dist/esm/schemas/plans.schema.mjs +18 -1
  243. package/dist/esm/schemas/plans.schema.mjs.map +1 -1
  244. package/dist/esm/schemas/project.schema.mjs +21 -15
  245. package/dist/esm/schemas/project.schema.mjs.map +1 -1
  246. package/dist/esm/schemas/session.schema.mjs +39 -0
  247. package/dist/esm/schemas/session.schema.mjs.map +1 -0
  248. package/dist/esm/schemas/tag.schema.mjs +21 -4
  249. package/dist/esm/schemas/tag.schema.mjs.map +1 -1
  250. package/dist/esm/schemas/user.schema.mjs +18 -48
  251. package/dist/esm/schemas/user.schema.mjs.map +1 -1
  252. package/dist/esm/services/dictionary.service.mjs +6 -5
  253. package/dist/esm/services/dictionary.service.mjs.map +1 -1
  254. package/dist/esm/services/email.service.mjs +33 -16
  255. package/dist/esm/services/email.service.mjs.map +1 -1
  256. package/dist/esm/services/oAuth2.service.mjs +47 -10
  257. package/dist/esm/services/oAuth2.service.mjs.map +1 -1
  258. package/dist/esm/services/organization.service.mjs +16 -14
  259. package/dist/esm/services/organization.service.mjs.map +1 -1
  260. package/dist/esm/services/project.service.mjs +1 -1
  261. package/dist/esm/services/project.service.mjs.map +1 -1
  262. package/dist/esm/services/projectAccessKey.service.mjs +15 -31
  263. package/dist/esm/services/projectAccessKey.service.mjs.map +1 -1
  264. package/dist/esm/services/subscription.service.mjs +10 -10
  265. package/dist/esm/services/subscription.service.mjs.map +1 -1
  266. package/dist/esm/services/tag.service.mjs.map +1 -1
  267. package/dist/esm/services/user.service.mjs +2 -40
  268. package/dist/esm/services/user.service.mjs.map +1 -1
  269. package/dist/esm/types/user.types.mjs.map +1 -1
  270. package/dist/esm/utils/AI/aiSdk.mjs.map +1 -1
  271. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs +14 -9
  272. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs.map +1 -1
  273. package/dist/esm/utils/AI/autocomplete/PROMPT.md +18 -2
  274. package/dist/esm/utils/AI/autocomplete/index.mjs +8 -5
  275. package/dist/esm/utils/AI/autocomplete/index.mjs.map +1 -1
  276. package/dist/esm/utils/access.mjs +1 -0
  277. package/dist/esm/utils/access.mjs.map +1 -0
  278. package/dist/esm/utils/accessControl.mjs +7 -0
  279. package/dist/esm/utils/accessControl.mjs.map +1 -1
  280. package/dist/esm/utils/auth/getAuth.mjs +227 -0
  281. package/dist/esm/utils/auth/getAuth.mjs.map +1 -0
  282. package/dist/esm/utils/cors.mjs +31 -0
  283. package/dist/esm/utils/cors.mjs.map +1 -0
  284. package/dist/esm/utils/ensureMongoDocumentToObject.mjs.map +1 -1
  285. package/dist/esm/utils/errors/ErrorHandler.mjs +2 -2
  286. package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
  287. package/dist/esm/utils/errors/errorCodes.mjs +114 -153
  288. package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
  289. package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
  290. package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
  291. package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -1
  292. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +1 -1
  293. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
  294. package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
  295. package/dist/esm/utils/mapper/organization.mjs +8 -7
  296. package/dist/esm/utils/mapper/organization.mjs.map +1 -1
  297. package/dist/esm/utils/mapper/project.mjs +5 -18
  298. package/dist/esm/utils/mapper/project.mjs.map +1 -1
  299. package/dist/esm/utils/mapper/tag.mjs +4 -2
  300. package/dist/esm/utils/mapper/tag.mjs.map +1 -1
  301. package/dist/esm/utils/mapper/user.mjs +6 -3
  302. package/dist/esm/utils/mapper/user.mjs.map +1 -1
  303. package/dist/esm/utils/mergeFunctionTypes.mjs +1 -0
  304. package/dist/esm/utils/mergeFunctionTypes.mjs.map +1 -0
  305. package/dist/esm/utils/mongoDB/connectDB.mjs +3 -1
  306. package/dist/esm/utils/mongoDB/connectDB.mjs.map +1 -1
  307. package/dist/esm/utils/mongoDB/types.mjs +1 -0
  308. package/dist/esm/utils/mongoDB/types.mjs.map +1 -0
  309. package/dist/esm/utils/oAuth2.mjs +3 -3
  310. package/dist/esm/utils/oAuth2.mjs.map +1 -1
  311. package/dist/esm/utils/permissions.mjs +138 -0
  312. package/dist/esm/utils/permissions.mjs.map +1 -0
  313. package/dist/esm/utils/rateLimiter.mjs +53 -0
  314. package/dist/esm/utils/rateLimiter.mjs.map +1 -0
  315. package/dist/types/controllers/ai.controller.d.ts +12 -10
  316. package/dist/types/controllers/ai.controller.d.ts.map +1 -1
  317. package/dist/types/controllers/dictionary.controller.d.ts +8 -9
  318. package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
  319. package/dist/types/controllers/eventListener.controller.d.ts +2 -3
  320. package/dist/types/controllers/eventListener.controller.d.ts.map +1 -1
  321. package/dist/types/controllers/newsletter.controller.d.ts +5 -6
  322. package/dist/types/controllers/newsletter.controller.d.ts.map +1 -1
  323. package/dist/types/controllers/oAuth2.controller.d.ts +3 -3
  324. package/dist/types/controllers/oAuth2.controller.d.ts.map +1 -1
  325. package/dist/types/controllers/organization.controller.d.ts +22 -23
  326. package/dist/types/controllers/organization.controller.d.ts.map +1 -1
  327. package/dist/types/controllers/project.controller.d.ts +13 -14
  328. package/dist/types/controllers/project.controller.d.ts.map +1 -1
  329. package/dist/types/controllers/projectAccessKey.controller.d.ts +5 -6
  330. package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
  331. package/dist/types/controllers/search.controller.d.ts +2 -3
  332. package/dist/types/controllers/search.controller.d.ts.map +1 -1
  333. package/dist/types/controllers/stripe.controller.d.ts +5 -6
  334. package/dist/types/controllers/stripe.controller.d.ts.map +1 -1
  335. package/dist/types/controllers/tag.controller.d.ts +9 -10
  336. package/dist/types/controllers/tag.controller.d.ts.map +1 -1
  337. package/dist/types/controllers/user.controller.d.ts +16 -19
  338. package/dist/types/controllers/user.controller.d.ts.map +1 -1
  339. package/dist/types/emails/InviteUserEmail.d.ts.map +1 -1
  340. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts +21 -0
  341. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts.map +1 -0
  342. package/dist/types/emails/ResetUserPassword.d.ts.map +1 -1
  343. package/dist/types/emails/Welcome.d.ts.map +1 -1
  344. package/dist/types/emails/index.d.ts +3 -2
  345. package/dist/types/emails/index.d.ts.map +1 -1
  346. package/dist/types/export.d.ts +2 -3
  347. package/dist/types/export.d.ts.map +1 -1
  348. package/dist/types/index.d.ts +1 -3
  349. package/dist/types/index.d.ts.map +1 -1
  350. package/dist/types/middlewares/oAuth2.middleware.d.ts +1 -2
  351. package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -1
  352. package/dist/types/middlewares/request.middleware.d.ts +3 -3
  353. package/dist/types/middlewares/request.middleware.d.ts.map +1 -1
  354. package/dist/types/middlewares/sessionAuth.middleware.d.ts +3 -25
  355. package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
  356. package/dist/types/models/dictionary.model.d.ts +6 -5
  357. package/dist/types/models/dictionary.model.d.ts.map +1 -1
  358. package/dist/types/models/discussion.model.d.ts +7 -2
  359. package/dist/types/models/discussion.model.d.ts.map +1 -1
  360. package/dist/types/models/oAuth2.model.d.ts +3 -2
  361. package/dist/types/models/oAuth2.model.d.ts.map +1 -1
  362. package/dist/types/models/organization.model.d.ts +2 -12
  363. package/dist/types/models/organization.model.d.ts.map +1 -1
  364. package/dist/types/models/project.model.d.ts +2 -11
  365. package/dist/types/models/project.model.d.ts.map +1 -1
  366. package/dist/types/models/session.model.d.ts +3 -0
  367. package/dist/types/models/session.model.d.ts.map +1 -0
  368. package/dist/types/models/tag.model.d.ts.map +1 -1
  369. package/dist/types/models/user.model.d.ts.map +1 -1
  370. package/dist/types/routes/ai.routes.d.ts.map +1 -1
  371. package/dist/types/routes/organization.routes.d.ts +4 -4
  372. package/dist/types/routes/project.routes.d.ts +4 -4
  373. package/dist/types/routes/project.routes.d.ts.map +1 -1
  374. package/dist/types/routes/tags.routes.d.ts +2 -2
  375. package/dist/types/routes/user.routes.d.ts +6 -7
  376. package/dist/types/routes/user.routes.d.ts.map +1 -1
  377. package/dist/types/schemas/dictionary.schema.d.ts +6 -8
  378. package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
  379. package/dist/types/schemas/discussion.schema.d.ts +7 -5
  380. package/dist/types/schemas/discussion.schema.d.ts.map +1 -1
  381. package/dist/types/schemas/oAuth2.schema.d.ts +4 -3
  382. package/dist/types/schemas/oAuth2.schema.d.ts.map +1 -1
  383. package/dist/types/schemas/organization.schema.d.ts +6 -10
  384. package/dist/types/schemas/organization.schema.d.ts.map +1 -1
  385. package/dist/types/schemas/plans.schema.d.ts +6 -8
  386. package/dist/types/schemas/plans.schema.d.ts.map +1 -1
  387. package/dist/types/schemas/project.schema.d.ts +5 -17
  388. package/dist/types/schemas/project.schema.d.ts.map +1 -1
  389. package/dist/types/schemas/session.schema.d.ts +14 -0
  390. package/dist/types/schemas/session.schema.d.ts.map +1 -0
  391. package/dist/types/schemas/tag.schema.d.ts +6 -8
  392. package/dist/types/schemas/tag.schema.d.ts.map +1 -1
  393. package/dist/types/schemas/user.schema.d.ts +7 -5
  394. package/dist/types/schemas/user.schema.d.ts.map +1 -1
  395. package/dist/types/services/dictionary.service.d.ts +9 -9
  396. package/dist/types/services/dictionary.service.d.ts.map +1 -1
  397. package/dist/types/services/email.service.d.ts +4 -0
  398. package/dist/types/services/email.service.d.ts.map +1 -1
  399. package/dist/types/services/oAuth2.service.d.ts +23 -14
  400. package/dist/types/services/oAuth2.service.d.ts.map +1 -1
  401. package/dist/types/services/organization.service.d.ts +6 -12
  402. package/dist/types/services/organization.service.d.ts.map +1 -1
  403. package/dist/types/services/project.service.d.ts +5 -5
  404. package/dist/types/services/project.service.d.ts.map +1 -1
  405. package/dist/types/services/projectAccessKey.service.d.ts +5 -5
  406. package/dist/types/services/projectAccessKey.service.d.ts.map +1 -1
  407. package/dist/types/services/subscription.service.d.ts +1 -1
  408. package/dist/types/services/subscription.service.d.ts.map +1 -1
  409. package/dist/types/services/tag.service.d.ts +6 -6
  410. package/dist/types/services/tag.service.d.ts.map +1 -1
  411. package/dist/types/services/user.service.d.ts +7 -21
  412. package/dist/types/services/user.service.d.ts.map +1 -1
  413. package/dist/types/types/dictionary.types.d.ts +11 -9
  414. package/dist/types/types/dictionary.types.d.ts.map +1 -1
  415. package/dist/types/types/discussion.types.d.ts +5 -2
  416. package/dist/types/types/discussion.types.d.ts.map +1 -1
  417. package/dist/types/types/oAuth2.types.d.ts +5 -2
  418. package/dist/types/types/oAuth2.types.d.ts.map +1 -1
  419. package/dist/types/types/organization.types.d.ts +11 -8
  420. package/dist/types/types/organization.types.d.ts.map +1 -1
  421. package/dist/types/types/plan.types.d.ts +6 -3
  422. package/dist/types/types/plan.types.d.ts.map +1 -1
  423. package/dist/types/types/project.types.d.ts +25 -25
  424. package/dist/types/types/project.types.d.ts.map +1 -1
  425. package/dist/types/types/session.types.d.ts +31 -17
  426. package/dist/types/types/session.types.d.ts.map +1 -1
  427. package/dist/types/types/tag.types.d.ts +8 -6
  428. package/dist/types/types/tag.types.d.ts.map +1 -1
  429. package/dist/types/types/user.types.d.ts +14 -21
  430. package/dist/types/types/user.types.d.ts.map +1 -1
  431. package/dist/types/utils/AI/aiSdk.d.ts +2 -2
  432. package/dist/types/utils/AI/aiSdk.d.ts.map +1 -1
  433. package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts.map +1 -1
  434. package/dist/types/utils/AI/autocomplete/index.d.ts +4 -1
  435. package/dist/types/utils/AI/autocomplete/index.d.ts.map +1 -1
  436. package/dist/types/utils/access.d.ts +1 -0
  437. package/dist/types/utils/access.d.ts.map +1 -0
  438. package/dist/types/utils/accessControl.d.ts +9 -9
  439. package/dist/types/utils/accessControl.d.ts.map +1 -1
  440. package/dist/types/utils/auth/getAuth.d.ts +7 -0
  441. package/dist/types/utils/auth/getAuth.d.ts.map +1 -0
  442. package/dist/types/utils/cors.d.ts +3 -0
  443. package/dist/types/utils/cors.d.ts.map +1 -0
  444. package/dist/types/utils/ensureMongoDocumentToObject.d.ts +2 -2
  445. package/dist/types/utils/ensureMongoDocumentToObject.d.ts.map +1 -1
  446. package/dist/types/utils/errors/ErrorHandler.d.ts +1 -1
  447. package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
  448. package/dist/types/utils/errors/errorCodes.d.ts +57 -96
  449. package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
  450. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +1 -1
  451. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
  452. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +1 -1
  453. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
  454. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +1 -1
  455. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -1
  456. package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts +1 -1
  457. package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
  458. package/dist/types/utils/mapper/dictionary.d.ts +1 -1
  459. package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
  460. package/dist/types/utils/mapper/organization.d.ts +3 -2
  461. package/dist/types/utils/mapper/organization.d.ts.map +1 -1
  462. package/dist/types/utils/mapper/project.d.ts +4 -5
  463. package/dist/types/utils/mapper/project.d.ts.map +1 -1
  464. package/dist/types/utils/mapper/tag.d.ts +1 -1
  465. package/dist/types/utils/mapper/tag.d.ts.map +1 -1
  466. package/dist/types/utils/mapper/user.d.ts +2 -2
  467. package/dist/types/utils/mapper/user.d.ts.map +1 -1
  468. package/dist/types/utils/mergeFunctionTypes.d.ts +18 -0
  469. package/dist/types/utils/mergeFunctionTypes.d.ts.map +1 -0
  470. package/dist/types/utils/mongoDB/connectDB.d.ts +1 -1
  471. package/dist/types/utils/mongoDB/connectDB.d.ts.map +1 -1
  472. package/dist/types/utils/mongoDB/types.d.ts +11 -0
  473. package/dist/types/utils/mongoDB/types.d.ts.map +1 -0
  474. package/dist/types/utils/permissions.d.ts +115 -0
  475. package/dist/types/utils/permissions.d.ts.map +1 -0
  476. package/dist/types/utils/rateLimiter.d.ts +4 -0
  477. package/dist/types/utils/rateLimiter.d.ts.map +1 -0
  478. package/package.json +15 -15
  479. package/dist/cjs/controllers/sessionAuth.controller.cjs +0 -839
  480. package/dist/cjs/controllers/sessionAuth.controller.cjs.map +0 -1
  481. package/dist/cjs/routes/sessionAuth.routes.cjs +0 -154
  482. package/dist/cjs/routes/sessionAuth.routes.cjs.map +0 -1
  483. package/dist/cjs/services/sessionAuth.service.cjs +0 -385
  484. package/dist/cjs/services/sessionAuth.service.cjs.map +0 -1
  485. package/dist/cjs/utils/CSRF.cjs +0 -50
  486. package/dist/cjs/utils/CSRF.cjs.map +0 -1
  487. package/dist/cjs/utils/cookies.cjs +0 -59
  488. package/dist/cjs/utils/cookies.cjs.map +0 -1
  489. package/dist/esm/controllers/sessionAuth.controller.mjs +0 -790
  490. package/dist/esm/controllers/sessionAuth.controller.mjs.map +0 -1
  491. package/dist/esm/routes/sessionAuth.routes.mjs +0 -142
  492. package/dist/esm/routes/sessionAuth.routes.mjs.map +0 -1
  493. package/dist/esm/services/sessionAuth.service.mjs +0 -337
  494. package/dist/esm/services/sessionAuth.service.mjs.map +0 -1
  495. package/dist/esm/utils/CSRF.mjs +0 -24
  496. package/dist/esm/utils/CSRF.mjs.map +0 -1
  497. package/dist/esm/utils/cookies.mjs +0 -32
  498. package/dist/esm/utils/cookies.mjs.map +0 -1
  499. package/dist/types/controllers/sessionAuth.controller.d.ts +0 -140
  500. package/dist/types/controllers/sessionAuth.controller.d.ts.map +0 -1
  501. package/dist/types/routes/sessionAuth.routes.d.ts +0 -77
  502. package/dist/types/routes/sessionAuth.routes.d.ts.map +0 -1
  503. package/dist/types/services/sessionAuth.service.d.ts +0 -141
  504. package/dist/types/services/sessionAuth.service.d.ts.map +0 -1
  505. package/dist/types/utils/CSRF.d.ts +0 -3
  506. package/dist/types/utils/CSRF.d.ts.map +0 -1
  507. package/dist/types/utils/cookies.d.ts +0 -12
  508. package/dist/types/utils/cookies.d.ts.map +0 -1
@@ -7,13 +7,14 @@ import {
7
7
  getDictionaryFiltersAndPagination
8
8
  } from "./../utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs";
9
9
  import { mapDictionaryToAPI } from "./../utils/mapper/dictionary.mjs";
10
+ import { hasPermission } from "./../utils/permissions.mjs";
10
11
  import {
11
12
  formatPaginatedResponse,
12
13
  formatResponse
13
14
  } from "./../utils/responseData.mjs";
14
15
  import { t } from "express-intlayer";
15
16
  const getDictionaries = async (req, res, _next) => {
16
- const { user, project, organization, dictionaryRights } = res.locals;
17
+ const { user, project, roles } = res.locals;
17
18
  const { filters, pageSize, skip, page, getNumberOfPages } = getDictionaryFiltersAndPagination(req);
18
19
  if (!project) {
19
20
  ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
@@ -23,22 +24,22 @@ const getDictionaries = async (req, res, _next) => {
23
24
  ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
24
25
  return;
25
26
  }
26
- if (!dictionaryRights?.read) {
27
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
27
+ if (!hasPermission(roles, "dictionary:read")(res.locals)) {
28
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
28
29
  return;
29
30
  }
30
31
  try {
31
32
  const dictionaries = await dictionaryService.findDictionaries(
32
33
  {
33
34
  ...filters,
34
- projectIds: project._id
35
+ projectIds: project.id
35
36
  },
36
37
  skip,
37
38
  pageSize
38
39
  );
39
40
  const totalItems = await dictionaryService.countDictionaries(filters);
40
41
  const dictionariesAPI = dictionaries.map(
41
- (el) => mapDictionaryToAPI(el, project._id)
42
+ (el) => mapDictionaryToAPI(el, project.id)
42
43
  );
43
44
  const responseData = formatPaginatedResponse({
44
45
  data: dictionariesAPI,
@@ -55,18 +56,18 @@ const getDictionaries = async (req, res, _next) => {
55
56
  }
56
57
  };
57
58
  const getDictionariesKeys = async (_req, res, _next) => {
58
- const { project, dictionaryRights } = res.locals;
59
+ const { project, roles } = res.locals;
59
60
  if (!project) {
60
61
  ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
61
62
  return;
62
63
  }
63
- if (!dictionaryRights?.read) {
64
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
64
+ if (!hasPermission(roles, "dictionary:read")(res.locals)) {
65
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
65
66
  return;
66
67
  }
67
68
  try {
68
69
  const dictionariesKeys = await dictionaryService.getDictionariesKeys(
69
- project._id
70
+ project.id
70
71
  );
71
72
  const responseData = formatResponse({
72
73
  data: dictionariesKeys
@@ -79,7 +80,7 @@ const getDictionariesKeys = async (_req, res, _next) => {
79
80
  }
80
81
  };
81
82
  const getDictionaryByKey = async (req, res, _next) => {
82
- const { project, user, dictionaryRights } = res.locals;
83
+ const { project, user, roles } = res.locals;
83
84
  const { dictionaryKey } = req.params;
84
85
  const version = req.query.version;
85
86
  if (!project) {
@@ -90,23 +91,23 @@ const getDictionaryByKey = async (req, res, _next) => {
90
91
  ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
91
92
  return;
92
93
  }
93
- if (!dictionaryRights?.read) {
94
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
94
+ if (!hasPermission(roles, "dictionary:read")(res.locals)) {
95
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
95
96
  return;
96
97
  }
97
98
  try {
98
99
  const dictionary = await dictionaryService.getDictionaryByKey(
99
100
  dictionaryKey,
100
- project._id
101
+ project.id
101
102
  );
102
- if (!dictionary.projectIds.map(String).includes(String(project._id))) {
103
+ if (!dictionary.projectIds.map(String).includes(String(project.id))) {
103
104
  ErrorHandler.handleGenericErrorResponse(
104
105
  res,
105
106
  "DICTIONARY_PROJECT_MISMATCH"
106
107
  );
107
108
  return;
108
109
  }
109
- const apiResult = mapDictionaryToAPI(dictionary, project._id, version);
110
+ const apiResult = mapDictionaryToAPI(dictionary, project.id, version);
110
111
  const responseData = formatResponse({
111
112
  data: apiResult
112
113
  });
@@ -118,7 +119,7 @@ const getDictionaryByKey = async (req, res, _next) => {
118
119
  }
119
120
  };
120
121
  const addDictionary = async (req, res, _next) => {
121
- const { project, user, dictionaryRights } = res.locals;
122
+ const { project, user, roles } = res.locals;
122
123
  const dictionaryData = req.body.dictionary;
123
124
  if (!dictionaryData) {
124
125
  ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
@@ -132,12 +133,12 @@ const addDictionary = async (req, res, _next) => {
132
133
  ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
133
134
  return;
134
135
  }
135
- if (!dictionaryData.projectIds?.includes(String(project._id))) {
136
+ if (!dictionaryData.projectIds?.includes(String(project.id))) {
136
137
  ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
137
138
  return;
138
139
  }
139
- if (!dictionaryRights?.admin) {
140
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
140
+ if (!hasPermission(roles, "dictionary:write")(res.locals)) {
141
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
141
142
  return;
142
143
  }
143
144
  const dictionary = {
@@ -147,15 +148,15 @@ const addDictionary = async (req, res, _next) => {
147
148
  content: /* @__PURE__ */ new Map([
148
149
  ["v1", { content: dictionaryData.content ?? {} }]
149
150
  ]),
150
- creatorId: user._id,
151
+ creatorId: user.id,
151
152
  filePath: {
152
- [String(project._id)]: dictionaryData.filePath ?? ""
153
+ [String(project.id)]: dictionaryData.filePath ?? ""
153
154
  },
154
- projectIds: dictionaryData.projectIds ?? [String(project._id)]
155
+ projectIds: dictionaryData.projectIds ?? [String(project.id)]
155
156
  };
156
157
  try {
157
158
  const newDictionary = await dictionaryService.createDictionary(dictionary);
158
- const apiResult = mapDictionaryToAPI(newDictionary, project._id);
159
+ const apiResult = mapDictionaryToAPI(newDictionary, project.id);
159
160
  const responseData = formatResponse({
160
161
  message: t({
161
162
  en: "Dictionary created successfully",
@@ -172,7 +173,7 @@ const addDictionary = async (req, res, _next) => {
172
173
  res.json(responseData);
173
174
  eventListener.sendDictionaryUpdate([
174
175
  {
175
- dictionary: mapDictionaryToAPI(newDictionary, project._id),
176
+ dictionary: mapDictionaryToAPI(newDictionary, project.id),
176
177
  status: "ADDED"
177
178
  }
178
179
  ]);
@@ -183,7 +184,7 @@ const addDictionary = async (req, res, _next) => {
183
184
  }
184
185
  };
185
186
  const pushDictionaries = async (req, res, _next) => {
186
- const { project, user, dictionaryRights } = res.locals;
187
+ const { project, user, roles } = res.locals;
187
188
  const dictionaryData = req.body.dictionaries;
188
189
  const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);
189
190
  if (typeof dictionaryData === "object" && Array.isArray(dictionaryData) && dictionaryData.length === 0) {
@@ -201,18 +202,14 @@ const pushDictionaries = async (req, res, _next) => {
201
202
  ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
202
203
  return;
203
204
  }
204
- if (!dictionaryRights?.write) {
205
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_WRITE");
206
- return;
207
- }
208
- if (!dictionaryRights?.admin) {
209
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
205
+ if (!hasPermission(roles, "dictionary:write")(res.locals)) {
206
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
210
207
  return;
211
208
  }
212
209
  try {
213
210
  const { existingDictionariesKey, newDictionariesKey } = await dictionaryService.getExistingDictionaryKey(
214
211
  dictionariesKeys,
215
- project._id
212
+ project.id
216
213
  );
217
214
  const existingDictionaries = dictionaryData.filter(
218
215
  (dictionary) => existingDictionariesKey.includes(dictionary.key)
@@ -227,20 +224,20 @@ const pushDictionaries = async (req, res, _next) => {
227
224
  const dictionary = {
228
225
  title: dictionaryDataEl.title,
229
226
  description: dictionaryDataEl.description,
230
- projectIds: [String(project._id)],
231
- creatorId: user._id,
227
+ projectIds: [String(project.id)],
228
+ creatorId: user.id,
232
229
  content: /* @__PURE__ */ new Map([
233
230
  ["v1", { content: dictionaryDataEl.content ?? {} }]
234
231
  ]),
235
232
  filePath: {
236
- [String(project._id)]: dictionaryDataEl.filePath ?? ""
233
+ [String(project.id)]: dictionaryDataEl.filePath ?? ""
237
234
  },
238
235
  key: dictionaryDataEl.key
239
236
  };
240
237
  try {
241
238
  const newDictionary = await dictionaryService.createDictionary(dictionary);
242
239
  newDictionariesResult.push(
243
- mapDictionaryToAPI(newDictionary, project._id)
240
+ mapDictionaryToAPI(newDictionary, project.id)
244
241
  );
245
242
  } catch (error) {
246
243
  ErrorHandler.handleAppErrorResponse(res, error);
@@ -250,7 +247,7 @@ const pushDictionaries = async (req, res, _next) => {
250
247
  if (existingDictionariesKey.length >= 0) {
251
248
  const existingDictionariesDB = await dictionaryService.getDictionariesByKeys(
252
249
  existingDictionariesKey,
253
- project._id
250
+ project.id
254
251
  );
255
252
  for (const dictionaryDataEl of existingDictionaries) {
256
253
  const existingDictionaryDB = existingDictionariesDB.find(
@@ -272,10 +269,10 @@ const pushDictionaries = async (req, res, _next) => {
272
269
  ...ensureMongoDocumentToObject(existingDictionaryDB),
273
270
  ...dictionaryDataEl,
274
271
  content: newContent,
275
- projectIds: [String(project._id)],
276
- creatorId: user._id,
272
+ projectIds: [String(project.id)],
273
+ creatorId: user.id,
277
274
  filePath: {
278
- [String(project._id)]: dictionaryDataEl.filePath ?? ""
275
+ [String(project.id)]: dictionaryDataEl.filePath ?? ""
279
276
  },
280
277
  key: dictionaryDataEl.key
281
278
  };
@@ -283,10 +280,10 @@ const pushDictionaries = async (req, res, _next) => {
283
280
  const updatedDictionary = await dictionaryService.updateDictionaryByKey(
284
281
  dictionaryDataEl.key,
285
282
  dictionary,
286
- project._id
283
+ project.id
287
284
  );
288
285
  updatedDictionariesResult.push(
289
- mapDictionaryToAPI(updatedDictionary, project._id)
286
+ mapDictionaryToAPI(updatedDictionary, project.id)
290
287
  );
291
288
  } catch (error) {
292
289
  ErrorHandler.handleAppErrorResponse(res, error);
@@ -339,7 +336,7 @@ const pushDictionaries = async (req, res, _next) => {
339
336
  };
340
337
  const updateDictionary = async (req, res, _next) => {
341
338
  const { dictionaryId } = req.params;
342
- const { project, dictionaryRights } = res.locals;
339
+ const { project, roles } = res.locals;
343
340
  const dictionaryData = req.body;
344
341
  if (!dictionaryData) {
345
342
  ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
@@ -349,7 +346,7 @@ const updateDictionary = async (req, res, _next) => {
349
346
  ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
350
347
  return;
351
348
  }
352
- if (!dictionaryData.projectIds?.includes(String(project._id))) {
349
+ if (!dictionaryData.projectIds?.includes(String(project.id))) {
353
350
  ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
354
351
  return;
355
352
  }
@@ -357,8 +354,8 @@ const updateDictionary = async (req, res, _next) => {
357
354
  ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
358
355
  return;
359
356
  }
360
- if (!dictionaryRights?.write) {
361
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_WRITE");
357
+ if (!hasPermission(roles, "dictionary:write")(res.locals)) {
358
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
362
359
  return;
363
360
  }
364
361
  try {
@@ -366,7 +363,7 @@ const updateDictionary = async (req, res, _next) => {
366
363
  dictionaryId,
367
364
  dictionaryData
368
365
  );
369
- const apiResult = mapDictionaryToAPI(updatedDictionary, project._id);
366
+ const apiResult = mapDictionaryToAPI(updatedDictionary, project.id);
370
367
  const responseData = formatResponse({
371
368
  message: t({
372
369
  en: "Dictionary updated successfully",
@@ -394,28 +391,23 @@ const updateDictionary = async (req, res, _next) => {
394
391
  }
395
392
  };
396
393
  const deleteDictionary = async (req, res, _next) => {
397
- const { project, dictionaryRights } = res.locals;
394
+ const { project, roles } = res.locals;
398
395
  const { dictionaryId } = req.params;
399
- console.log("dictionaryId1", dictionaryId);
400
396
  if (!dictionaryId) {
401
397
  ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
402
398
  return;
403
399
  }
404
- console.log("dictionaryId2", dictionaryId);
405
400
  if (!project) {
406
401
  ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
407
402
  return;
408
403
  }
409
- console.log("dictionaryId3", dictionaryId);
410
- if (!dictionaryRights?.admin) {
411
- ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
404
+ if (!hasPermission(roles, "dictionary:admin")()) {
405
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
412
406
  return;
413
407
  }
414
- console.log("dictionaryId4", dictionaryId);
415
408
  try {
416
409
  const dictionaryToDelete = await dictionaryService.getDictionaryById(dictionaryId);
417
- console.log("dictionaryToDelete", dictionaryToDelete);
418
- if (!dictionaryToDelete.projectIds.includes(project._id)) {
410
+ if (!dictionaryToDelete.projectIds.includes(project.id)) {
419
411
  ErrorHandler.handleGenericErrorResponse(
420
412
  res,
421
413
  "DICTIONARY_PROJECT_MISMATCH"
@@ -429,8 +421,8 @@ const deleteDictionary = async (req, res, _next) => {
429
421
  });
430
422
  return;
431
423
  }
432
- logger.info(`Dictionary deleted: ${String(deletedDictionary._id)}`);
433
- const apiResult = mapDictionaryToAPI(deletedDictionary, project._id);
424
+ logger.info(`Dictionary deleted: ${String(deletedDictionary.id)}`);
425
+ const apiResult = mapDictionaryToAPI(deletedDictionary, project.id);
434
426
  const responseData = formatResponse({
435
427
  message: t({
436
428
  en: "Dictionary deleted successfully",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/controllers/dictionary.controller.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionaryAPI,\n DictionaryCreationData,\n DictionaryData,\n VersionedContent,\n} from '@/types/dictionary.types';\nimport * as eventListener from '@controllers/eventListener.controller';\nimport type {\n ContentNode,\n Dictionary as LocalDictionary,\n} from '@intlayer/core';\nimport { logger } from '@logger';\nimport type { ResponseWithInformation } from '@middlewares/sessionAuth.middleware';\nimport * as dictionaryService from '@services/dictionary.service';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DictionaryFiltersParams,\n getDictionaryFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { mapDictionaryToAPI } from '@utils/mapper/dictionary';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport { t } from 'express-intlayer';\n\nexport type GetDictionariesParams =\n FiltersAndPagination<DictionaryFiltersParams>;\nexport type GetDictionariesResult = PaginatedResponse<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaries = async (\n req: Request<GetDictionariesParams>,\n res: ResponseWithInformation<GetDictionariesResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, project, organization, dictionaryRights } = res.locals;\n const { filters, pageSize, skip, page, getNumberOfPages } =\n getDictionaryFiltersAndPagination(req);\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!dictionaryRights?.read) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_READ');\n return;\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries(\n {\n ...filters,\n projectIds: project._id,\n },\n skip,\n pageSize\n );\n const totalItems = await dictionaryService.countDictionaries(filters);\n\n const dictionariesAPI = dictionaries.map((el) =>\n mapDictionaryToAPI(el, project._id)\n );\n\n const responseData = formatPaginatedResponse<DictionaryAPI>({\n data: dictionariesAPI,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDictionariesKeysResult = ResponseData<string[]>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesKeys = async (\n _req: Request,\n res: ResponseWithInformation<GetDictionariesKeysResult>,\n _next: NextFunction\n) => {\n const { project, dictionaryRights } = res.locals;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!dictionaryRights?.read) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_READ');\n return;\n }\n\n try {\n const dictionariesKeys = await dictionaryService.getDictionariesKeys(\n project._id\n );\n\n const responseData = formatResponse<string[]>({\n data: dictionariesKeys,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDictionaryParams = { dictionaryKey: string };\nexport type GetDictionaryQuery = { version?: string };\nexport type GetDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaryByKey = async (\n req: Request<GetDictionaryParams, any, any, GetDictionaryQuery>,\n res: ResponseWithInformation<GetDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user, dictionaryRights } = res.locals;\n const { dictionaryKey } = req.params;\n const version = req.query.version;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!dictionaryRights?.read) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_READ');\n return;\n }\n\n try {\n const dictionary = await dictionaryService.getDictionaryByKey(\n dictionaryKey,\n project._id\n );\n\n if (!dictionary.projectIds.map(String).includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const apiResult = mapDictionaryToAPI(dictionary, project._id, version);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AddDictionaryBody = { dictionary: DictionaryCreationData };\nexport type AddDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Adds a new dictionary to the database.\n */\nexport const addDictionary = async (\n req: Request<any, any, AddDictionaryBody>,\n res: ResponseWithInformation<AddDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user, dictionaryRights } = res.locals;\n const dictionaryData = req.body.dictionary;\n\n if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!dictionaryData.projectIds?.includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_PROJECT_MISMATCH');\n return;\n }\n\n if (!dictionaryRights?.admin) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_ADMIN');\n return;\n }\n\n const dictionary: DictionaryData = {\n key: dictionaryData.key,\n title: dictionaryData.title,\n description: dictionaryData.description,\n content: new Map([\n ['v1', { content: dictionaryData.content ?? ({} as ContentNode) }],\n ]),\n creatorId: user._id,\n filePath: {\n [String(project._id)]: dictionaryData.filePath ?? '',\n },\n projectIds: dictionaryData.projectIds ?? [String(project._id)],\n };\n\n try {\n const newDictionary = await dictionaryService.createDictionary(dictionary);\n\n const apiResult = mapDictionaryToAPI(newDictionary, project._id);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary created successfully',\n fr: 'Dictionnaire créé avec succès',\n es: 'Diccionario creado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been created successfully',\n fr: 'Votre dictionnaire a été créé avec succès',\n es: 'Su diccionario ha sido creado con éxito',\n }),\n data: apiResult,\n });\n\n res.json(responseData);\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: mapDictionaryToAPI(newDictionary, project._id),\n status: 'ADDED',\n },\n ]);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type PushDictionariesBody = {\n dictionaries: LocalDictionary[];\n};\ntype PushDictionariesResultData = {\n newDictionaries: string[];\n updatedDictionaries: string[];\n error: { dictionaryId: string; message: string }[];\n};\nexport type PushDictionariesResult = ResponseData<PushDictionariesResultData>;\n\n/**\n * Check each dictionaries, add the new ones and update the existing ones.\n * @param req - Express request object.\n * @param res - Express response object.\n * @returns Response containing the created dictionary.\n */\nexport const pushDictionaries = async (\n req: Request<any, any, PushDictionariesBody>,\n res: ResponseWithInformation<PushDictionariesResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user, dictionaryRights } = res.locals;\n const dictionaryData = req.body.dictionaries;\n const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);\n\n if (\n typeof dictionaryData === 'object' &&\n Array.isArray(dictionaryData) &&\n dictionaryData.length === 0\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARIES_NOT_PROVIDED');\n return;\n } else if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!dictionaryRights?.write) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_WRITE');\n return;\n }\n\n if (!dictionaryRights?.admin) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_ADMIN');\n return;\n }\n\n try {\n const { existingDictionariesKey, newDictionariesKey } =\n await dictionaryService.getExistingDictionaryKey(\n dictionariesKeys,\n project._id\n );\n\n const existingDictionaries = dictionaryData.filter((dictionary) =>\n existingDictionariesKey.includes(dictionary.key)\n );\n const newDictionaries = dictionaryData.filter((dictionary) =>\n newDictionariesKey.includes(dictionary.key)\n );\n\n const newDictionariesResult: DictionaryAPI[] = [];\n const updatedDictionariesResult: DictionaryAPI[] = [];\n const errorResult: PushDictionariesResultData['error'] = [];\n\n for (const dictionaryDataEl of newDictionaries) {\n const dictionary: DictionaryData = {\n title: dictionaryDataEl.title,\n description: dictionaryDataEl.description,\n projectIds: [String(project._id)],\n creatorId: user._id,\n content: new Map([\n ['v1', { content: dictionaryDataEl.content ?? ({} as ContentNode) }],\n ]),\n filePath: {\n [String(project._id)]: dictionaryDataEl.filePath ?? '',\n },\n key: dictionaryDataEl.key,\n };\n\n try {\n const newDictionary =\n await dictionaryService.createDictionary(dictionary);\n newDictionariesResult.push(\n mapDictionaryToAPI(newDictionary, project._id)\n );\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n }\n\n if (existingDictionariesKey.length >= 0) {\n const existingDictionariesDB =\n await dictionaryService.getDictionariesByKeys(\n existingDictionariesKey,\n project._id\n );\n\n for (const dictionaryDataEl of existingDictionaries) {\n const existingDictionaryDB = existingDictionariesDB.find(\n (dictionaryDB) => dictionaryDB.key === dictionaryDataEl.key\n )!;\n\n const versionList = [...(existingDictionaryDB.content.keys() ?? [])];\n const lastVersion = versionList[versionList.length - 1];\n\n const lastContent =\n (existingDictionaryDB.content.get(lastVersion)\n ?.content as DictionaryAPI['content']) ?? null;\n\n const isSameContent =\n JSON.stringify(lastContent) ===\n JSON.stringify(dictionaryDataEl.content);\n\n let newContent: VersionedContent = existingDictionaryDB.content;\n\n if (!isSameContent) {\n const newContentVersion =\n dictionaryService.incrementVersion(existingDictionaryDB);\n\n existingDictionaryDB.content.set(newContentVersion, {\n content: dictionaryDataEl.content ?? ({} as ContentNode),\n });\n\n newContent = existingDictionaryDB.content;\n }\n\n const dictionary: DictionaryData = {\n ...ensureMongoDocumentToObject(existingDictionaryDB),\n ...dictionaryDataEl,\n content: newContent,\n projectIds: [String(project._id)],\n creatorId: user._id,\n filePath: {\n [String(project._id)]: dictionaryDataEl.filePath ?? '',\n },\n key: dictionaryDataEl.key,\n };\n\n try {\n const updatedDictionary =\n await dictionaryService.updateDictionaryByKey(\n dictionaryDataEl.key,\n dictionary,\n project._id\n );\n updatedDictionariesResult.push(\n mapDictionaryToAPI(updatedDictionary, project._id)\n );\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n }\n }\n\n const result: PushDictionariesResultData = {\n newDictionaries: newDictionariesResult.map(\n (dictionary) => dictionary.key\n ),\n updatedDictionaries: updatedDictionariesResult.map(\n (dictionary) => dictionary.key\n ),\n error: errorResult,\n };\n\n const responseData = formatResponse<PushDictionariesResultData>({\n message: t({\n en: 'Dictionaries updated successfully',\n fr: 'Dictionnaires mis à jour avec succès',\n es: 'Diccionarios actualizados con éxito',\n }),\n description: t({\n en: 'Your dictionaries have been updated successfully',\n fr: 'Vos dictionnaires ont été mis à jour avec succès',\n es: 'Sus diccionarios han sido actualizados con éxito',\n }),\n data: result,\n });\n\n eventListener.sendDictionaryUpdate([\n ...newDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'ADDED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ...updatedDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'UPDATED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ]);\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type UpdateDictionaryParam = { dictionaryId: string };\nexport type UpdateDictionaryBody = Partial<Dictionary>;\nexport type UpdateDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Updates an existing dictionary in the database.\n */\nexport const updateDictionary = async (\n req: Request<UpdateDictionaryParam, any, UpdateDictionaryBody>,\n res: ResponseWithInformation<UpdateDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { dictionaryId } = req.params;\n const { project, dictionaryRights } = res.locals;\n const dictionaryData = req.body;\n\n if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!dictionaryData.projectIds?.includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_PROJECT_MISMATCH');\n return;\n }\n\n if (typeof dictionaryId === 'undefined') {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_ID_NOT_FOUND');\n return;\n }\n\n if (!dictionaryRights?.write) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_WRITE');\n return;\n }\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryById(\n dictionaryId,\n dictionaryData\n );\n\n const apiResult = mapDictionaryToAPI(updatedDictionary, project._id);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary updated successfully',\n fr: 'Dictionnaire mis à jour avec succès',\n es: 'Diccionario actualizado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been updated successfully',\n fr: 'Votre dictionnaire a été mis à jour avec succès',\n es: 'Su diccionario ha sido actualizado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'UPDATED',\n },\n ]);\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type DeleteDictionaryParam = { dictionaryId: string };\nexport type DeleteDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Deletes a dictionary from the database by its ID.\n */\nexport const deleteDictionary = async (\n req: Request<DeleteDictionaryParam>,\n res: ResponseWithInformation<DeleteDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, dictionaryRights } = res.locals;\n const { dictionaryId } = req.params as Partial<DeleteDictionaryParam>;\n\n console.log('dictionaryId1', dictionaryId);\n\n if (!dictionaryId) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_ID_NOT_FOUND');\n return;\n }\n\n console.log('dictionaryId2', dictionaryId);\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n console.log('dictionaryId3', dictionaryId);\n\n if (!dictionaryRights?.admin) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_ADMIN');\n return;\n }\n\n console.log('dictionaryId4', dictionaryId);\n\n try {\n const dictionaryToDelete =\n await dictionaryService.getDictionaryById(dictionaryId);\n\n console.log('dictionaryToDelete', dictionaryToDelete);\n\n if (!dictionaryToDelete.projectIds.includes(project._id)) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const deletedDictionary =\n await dictionaryService.deleteDictionaryById(dictionaryId);\n\n if (!deletedDictionary) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_NOT_FOUND', {\n dictionaryId,\n });\n return;\n }\n\n logger.info(`Dictionary deleted: ${String(deletedDictionary._id)}`);\n\n const apiResult = mapDictionaryToAPI(deletedDictionary, project._id);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary deleted successfully',\n fr: 'Dictionnaire supprimé avec succès',\n es: 'Diccionario eliminado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been deleted successfully',\n fr: 'Votre dictionnaire a été supprimé avec succès',\n es: 'Su diccionario ha sido eliminado con éxito',\n }),\n data: apiResult,\n });\n\n res.json(responseData);\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'DELETED',\n },\n ]);\n\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n"],"mappings":"AAOA,YAAY,mBAAmB;AAK/B,SAAS,cAAc;AAEvB,YAAY,uBAAuB;AACnC,SAAS,mCAAmC;AAC5C,SAAwB,oBAAoB;AAC5C;AAAA,EAEE;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,SAAS;AASX,MAAM,kBAAkB,OAC7B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM,SAAS,cAAc,iBAAiB,IAAI,IAAI;AAC9D,QAAM,EAAE,SAAS,UAAU,MAAM,MAAM,iBAAiB,IACtD,kCAAkC,GAAG;AAEvC,MAAI,CAAC,SAAS;AACZ,iBAAa,2BAA2B,KAAK,qBAAqB;AAClE;AAAA,EACF;AACA,MAAI,CAAC,MAAM;AACT,iBAAa,2BAA2B,KAAK,kBAAkB;AAC/D;AAAA,EACF;AACA,MAAI,CAAC,kBAAkB,MAAM;AAC3B,iBAAa,2BAA2B,KAAK,4BAA4B;AACzE;AAAA,EACF;AAEA,MAAI;AACF,UAAM,eAAe,MAAM,kBAAkB;AAAA,MAC3C;AAAA,QACE,GAAG;AAAA,QACH,YAAY,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,UAAM,aAAa,MAAM,kBAAkB,kBAAkB,OAAO;AAEpE,UAAM,kBAAkB,aAAa;AAAA,MAAI,CAAC,OACxC,mBAAmB,IAAI,QAAQ,GAAG;AAAA,IACpC;AAEA,UAAM,eAAe,wBAAuC;AAAA,MAC1D,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA,YAAY,iBAAiB,UAAU;AAAA,MACvC;A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,GAAG;AACxD,mBAAa;AAAA,QACX;AAAA,QACA;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,oBACJ,MAAM,kBAAkB,qBAAqB,YAAY;AAE3D,QAAI,CAAC,mBAAmB;AACtB,mBAAa,2BAA2B,KAAK,wBAAwB;AAAA,QACnE;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,WAAO,KAAK,uBAAuB,OAAO,kBAAkB,GAAG,CAAC,EAAE;AAElE,UAAM,YAAY,mBAAmB,mBAAmB,QAAQ,GAAG;AAEnE,UAAM,eAAe,eAA8B;AAAA,MACjD,SAAS,EAAE;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,aAAa,EAAE;AAAA,QACb,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,MAAM;AAAA,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AAErB,kBAAc,qBAAqB;AAAA,MACjC;AAAA,QACE,YAAY;AAAA,QACZ,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAED;AAAA,EACF,SAAS,OAAO;AACd,iBAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/controllers/dictionary.controller.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionaryAPI,\n DictionaryCreationData,\n DictionaryData,\n VersionedContent,\n} from '@/types/dictionary.types';\nimport * as eventListener from '@controllers/eventListener.controller';\nimport type {\n ContentNode,\n Dictionary as LocalDictionary,\n} from '@intlayer/core';\nimport { logger } from '@logger';\nimport * as dictionaryService from '@services/dictionary.service';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DictionaryFiltersParams,\n getDictionaryFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { mapDictionaryToAPI } from '@utils/mapper/dictionary';\nimport { hasPermission } from '@utils/permissions';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { NextFunction, Request, Response } from 'express';\nimport { t } from 'express-intlayer';\n\nexport type GetDictionariesParams =\n FiltersAndPagination<DictionaryFiltersParams>;\nexport type GetDictionariesResult = PaginatedResponse<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaries = async (\n req: Request<GetDictionariesParams>,\n res: Response<GetDictionariesResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, project, roles } = res.locals;\n const { filters, pageSize, skip, page, getNumberOfPages } =\n getDictionaryFiltersAndPagination(req);\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:read')(res.locals)) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries(\n {\n ...filters,\n projectIds: project.id,\n },\n skip,\n pageSize\n );\n const totalItems = await dictionaryService.countDictionaries(filters);\n\n const dictionariesAPI = dictionaries.map((el) =>\n mapDictionaryToAPI(el, project.id)\n );\n\n const responseData = formatPaginatedResponse<DictionaryAPI>({\n data: dictionariesAPI,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDictionariesKeysResult = ResponseData<string[]>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesKeys = async (\n _req: Request,\n res: Response<GetDictionariesKeysResult>,\n _next: NextFunction\n) => {\n const { project, roles } = res.locals;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:read')(res.locals)) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const dictionariesKeys = await dictionaryService.getDictionariesKeys(\n project.id\n );\n\n const responseData = formatResponse<string[]>({\n data: dictionariesKeys,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDictionaryParams = { dictionaryKey: string };\nexport type GetDictionaryQuery = { version?: string };\nexport type GetDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaryByKey = async (\n req: Request<GetDictionaryParams, any, any, GetDictionaryQuery>,\n res: Response<GetDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user, roles } = res.locals;\n const { dictionaryKey } = req.params;\n const version = req.query.version;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:read')(res.locals)) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const dictionary = await dictionaryService.getDictionaryByKey(\n dictionaryKey,\n project.id\n );\n\n if (!dictionary.projectIds.map(String).includes(String(project.id))) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const apiResult = mapDictionaryToAPI(dictionary, project.id, version);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AddDictionaryBody = { dictionary: DictionaryCreationData };\nexport type AddDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Adds a new dictionary to the database.\n */\nexport const addDictionary = async (\n req: Request<any, any, AddDictionaryBody>,\n res: Response<AddDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user, roles } = res.locals;\n const dictionaryData = req.body.dictionary;\n\n if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!dictionaryData.projectIds?.includes(String(project.id))) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_PROJECT_MISMATCH');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:write')(res.locals)) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const dictionary: DictionaryData = {\n key: dictionaryData.key,\n title: dictionaryData.title,\n description: dictionaryData.description,\n content: new Map([\n ['v1', { content: dictionaryData.content ?? ({} as ContentNode) }],\n ]),\n creatorId: user.id,\n filePath: {\n [String(project.id)]: dictionaryData.filePath ?? '',\n },\n projectIds: dictionaryData.projectIds ?? [String(project.id)],\n };\n\n try {\n const newDictionary = await dictionaryService.createDictionary(dictionary);\n\n const apiResult = mapDictionaryToAPI(newDictionary, project.id);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary created successfully',\n fr: 'Dictionnaire créé avec succès',\n es: 'Diccionario creado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been created successfully',\n fr: 'Votre dictionnaire a été créé avec succès',\n es: 'Su diccionario ha sido creado con éxito',\n }),\n data: apiResult,\n });\n\n res.json(responseData);\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: mapDictionaryToAPI(newDictionary, project.id),\n status: 'ADDED',\n },\n ]);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type PushDictionariesBody = {\n dictionaries: LocalDictionary[];\n};\ntype PushDictionariesResultData = {\n newDictionaries: string[];\n updatedDictionaries: string[];\n error: { dictionaryId: string; message: string }[];\n};\nexport type PushDictionariesResult = ResponseData<PushDictionariesResultData>;\n\n/**\n * Check each dictionaries, add the new ones and update the existing ones.\n * @param req - Express request object.\n * @param res - Express response object.\n * @returns Response containing the created dictionary.\n */\nexport const pushDictionaries = async (\n req: Request<any, any, PushDictionariesBody>,\n res: Response<PushDictionariesResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user, roles } = res.locals;\n const dictionaryData = req.body.dictionaries;\n const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);\n\n if (\n typeof dictionaryData === 'object' &&\n Array.isArray(dictionaryData) &&\n dictionaryData.length === 0\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARIES_NOT_PROVIDED');\n return;\n } else if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:write')(res.locals)) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const { existingDictionariesKey, newDictionariesKey } =\n await dictionaryService.getExistingDictionaryKey(\n dictionariesKeys,\n project.id\n );\n\n const existingDictionaries = dictionaryData.filter((dictionary) =>\n existingDictionariesKey.includes(dictionary.key)\n );\n const newDictionaries = dictionaryData.filter((dictionary) =>\n newDictionariesKey.includes(dictionary.key)\n );\n\n const newDictionariesResult: DictionaryAPI[] = [];\n const updatedDictionariesResult: DictionaryAPI[] = [];\n const errorResult: PushDictionariesResultData['error'] = [];\n\n for (const dictionaryDataEl of newDictionaries) {\n const dictionary: DictionaryData = {\n title: dictionaryDataEl.title,\n description: dictionaryDataEl.description,\n projectIds: [String(project.id)],\n creatorId: user.id,\n content: new Map([\n ['v1', { content: dictionaryDataEl.content ?? ({} as ContentNode) }],\n ]),\n filePath: {\n [String(project.id)]: dictionaryDataEl.filePath ?? '',\n },\n key: dictionaryDataEl.key,\n };\n\n try {\n const newDictionary =\n await dictionaryService.createDictionary(dictionary);\n newDictionariesResult.push(\n mapDictionaryToAPI(newDictionary, project.id)\n );\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n }\n\n if (existingDictionariesKey.length >= 0) {\n const existingDictionariesDB =\n await dictionaryService.getDictionariesByKeys(\n existingDictionariesKey,\n project.id\n );\n\n for (const dictionaryDataEl of existingDictionaries) {\n const existingDictionaryDB = existingDictionariesDB.find(\n (dictionaryDB) => dictionaryDB.key === dictionaryDataEl.key\n )!;\n\n const versionList = [...(existingDictionaryDB.content.keys() ?? [])];\n const lastVersion = versionList[versionList.length - 1];\n\n const lastContent =\n (existingDictionaryDB.content.get(lastVersion)\n ?.content as DictionaryAPI['content']) ?? null;\n\n const isSameContent =\n JSON.stringify(lastContent) ===\n JSON.stringify(dictionaryDataEl.content);\n\n let newContent: VersionedContent = existingDictionaryDB.content;\n\n if (!isSameContent) {\n const newContentVersion =\n dictionaryService.incrementVersion(existingDictionaryDB);\n\n existingDictionaryDB.content.set(newContentVersion, {\n content: dictionaryDataEl.content ?? ({} as ContentNode),\n });\n\n newContent = existingDictionaryDB.content;\n }\n\n const dictionary: DictionaryData = {\n ...ensureMongoDocumentToObject(existingDictionaryDB),\n ...dictionaryDataEl,\n content: newContent,\n projectIds: [String(project.id)],\n creatorId: user.id,\n filePath: {\n [String(project.id)]: dictionaryDataEl.filePath ?? '',\n },\n key: dictionaryDataEl.key,\n };\n\n try {\n const updatedDictionary =\n await dictionaryService.updateDictionaryByKey(\n dictionaryDataEl.key,\n dictionary,\n project.id\n );\n updatedDictionariesResult.push(\n mapDictionaryToAPI(updatedDictionary, project.id)\n );\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n }\n }\n\n const result: PushDictionariesResultData = {\n newDictionaries: newDictionariesResult.map(\n (dictionary) => dictionary.key\n ),\n updatedDictionaries: updatedDictionariesResult.map(\n (dictionary) => dictionary.key\n ),\n error: errorResult,\n };\n\n const responseData = formatResponse<PushDictionariesResultData>({\n message: t({\n en: 'Dictionaries updated successfully',\n fr: 'Dictionnaires mis à jour avec succès',\n es: 'Diccionarios actualizados con éxito',\n }),\n description: t({\n en: 'Your dictionaries have been updated successfully',\n fr: 'Vos dictionnaires ont été mis à jour avec succès',\n es: 'Sus diccionarios han sido actualizados con éxito',\n }),\n data: result,\n });\n\n eventListener.sendDictionaryUpdate([\n ...newDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'ADDED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ...updatedDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'UPDATED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ]);\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type UpdateDictionaryParam = { dictionaryId: string };\nexport type UpdateDictionaryBody = Partial<Dictionary>;\nexport type UpdateDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Updates an existing dictionary in the database.\n */\nexport const updateDictionary = async (\n req: Request<UpdateDictionaryParam, any, UpdateDictionaryBody>,\n res: Response<UpdateDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { dictionaryId } = req.params;\n const { project, roles } = res.locals;\n const dictionaryData = req.body;\n\n if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!dictionaryData.projectIds?.includes(String(project.id))) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_PROJECT_MISMATCH');\n return;\n }\n\n if (typeof dictionaryId === 'undefined') {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_ID_NOT_FOUND');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:write')(res.locals)) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryById(\n dictionaryId,\n dictionaryData\n );\n\n const apiResult = mapDictionaryToAPI(updatedDictionary, project.id);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary updated successfully',\n fr: 'Dictionnaire mis à jour avec succès',\n es: 'Diccionario actualizado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been updated successfully',\n fr: 'Votre dictionnaire a été mis à jour avec succès',\n es: 'Su diccionario ha sido actualizado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'UPDATED',\n },\n ]);\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type DeleteDictionaryParam = { dictionaryId: string };\nexport type DeleteDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Deletes a dictionary from the database by its ID.\n */\nexport const deleteDictionary = async (\n req: Request<DeleteDictionaryParam>,\n res: Response<DeleteDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, roles } = res.locals;\n const { dictionaryId } = req.params as Partial<DeleteDictionaryParam>;\n\n if (!dictionaryId) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_ID_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n\n if (!hasPermission(roles, 'dictionary:admin')()) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n try {\n const dictionaryToDelete =\n await dictionaryService.getDictionaryById(dictionaryId);\n\n if (!dictionaryToDelete.projectIds.includes(project.id)) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const deletedDictionary =\n await dictionaryService.deleteDictionaryById(dictionaryId);\n\n if (!deletedDictionary) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_NOT_FOUND', {\n dictionaryId,\n });\n return;\n }\n\n logger.info(`Dictionary deleted: ${String(deletedDictionary.id)}`);\n\n const apiResult = mapDictionaryToAPI(deletedDictionary, project.id);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary deleted successfully',\n fr: 'Dictionnaire supprimé avec succès',\n es: 'Diccionario eliminado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been deleted successfully',\n fr: 'Votre dictionnaire a été supprimé avec succès',\n es: 'Su diccionario ha sido eliminado con éxito',\n }),\n data: apiResult,\n });\n\n res.json(responseData);\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'DELETED',\n },\n ]);\n\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n"],"mappings":"AAOA,YAAY,mBAAmB;AAK/B,SAAS,cAAc;AACvB,YAAY,uBAAuB;AACnC,SAAS,mCAAmC;AAC5C,SAAwB,oBAAoB;AAC5C;AAAA,EAEE;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,SAAS;AASX,MAAM,kBAAkB,OAC7B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM,SAAS,MAAM,IAAI,IAAI;AACrC,QAAM,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MACjC;AAAA,QACE,YAAY;AAAA,QACZ,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAED;AAAA,EACF,SAAS,OAAO;AACd,iBAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;","names":[]}
@@ -1,6 +1,5 @@
1
- import * as oAuth2Service from "./../services/oAuth2.service.mjs";
2
- import { ErrorHandler } from "./../utils/errors/index.mjs";
3
1
  import { logger } from "./../logger/index.mjs";
2
+ import { ErrorHandler } from "./../utils/errors/index.mjs";
4
3
  let clients = [];
5
4
  const MAX_SSE_CONNECTIONS = 10;
6
5
  const sendDictionaryUpdate = (args) => {
@@ -28,11 +27,6 @@ const listenChangeSSE = async (req, res) => {
28
27
  ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_AUTHENTICATED");
29
28
  return;
30
29
  }
31
- const tokenInformation = await oAuth2Service.getAccessToken(accessToken);
32
- if (!tokenInformation) {
33
- ErrorHandler.handleGenericErrorResponse(res, "AUTH_ERROR");
34
- return;
35
- }
36
30
  if (clients.length >= MAX_SSE_CONNECTIONS) {
37
31
  ErrorHandler.handleGenericErrorResponse(res, "TOO_MANY_CONNECTIONS");
38
32
  return;
@@ -46,7 +40,7 @@ const listenChangeSSE = async (req, res) => {
46
40
  const clientId = Date.now();
47
41
  const newClient = {
48
42
  id: clientId,
49
- projectId: String(tokenInformation.project._id),
43
+ projectId: String(res.locals.session.session.activeProjectId),
50
44
  res
51
45
  };
52
46
  clients.push(newClient);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/controllers/eventListener.controller.ts"],"sourcesContent":["import type { ResponseWithInformation } from '@middlewares/sessionAuth.middleware';\nimport type { Token } from '@schemas/oAuth2.schema';\nimport * as oAuth2Service from '@services/oAuth2.service';\nimport { ErrorHandler } from '@utils/errors';\nimport type { Response, Request } from 'express';\nimport type { DictionaryAPI } from '@/types/dictionary.types';\nimport { logger } from '@logger';\n\nexport type Object = 'DICTIONARY';\nexport type Status = 'ADDED' | 'UPDATED' | 'DELETED' | 'CREATED';\n\nexport type MessageEventData = {\n object: Object;\n status: Status;\n data: any;\n};\n\nlet clients: Array<{ id: number; projectId: string; res: Response }> = [];\nconst MAX_SSE_CONNECTIONS = 10;\n\nexport type SendDictionaryUpdateArg = {\n dictionary: DictionaryAPI;\n status: 'ADDED' | 'UPDATED' | 'DELETED' | 'CREATED';\n};\n\nexport const sendDictionaryUpdate = (args: SendDictionaryUpdateArg[]) => {\n const projectIds = args.flatMap((arg) => arg.dictionary.projectIds);\n\n const filteredClients = clients.filter((client) =>\n projectIds.map((id) => String(id)).includes(String(client.projectId))\n );\n\n const data: MessageEventData[] = args.map((arg) => ({\n object: 'DICTIONARY',\n status: arg.status,\n data: arg.dictionary,\n }));\n\n process.nextTick(() => {\n for (const client of filteredClients) {\n client.res.write(`data: ${JSON.stringify(data)}\\n\\n`);\n client.res.flush?.(); // Ensure the data is sent immediately\n }\n });\n};\n\nexport type CheckDictionaryChangeSSEParams = { accessToken: string };\n\n/**\n * SSE to check the email verification status\n */\nexport const listenChangeSSE = async (\n req: Request<CheckDictionaryChangeSSEParams, any, any>,\n res: ResponseWithInformation\n) => {\n const { accessToken } = req.params;\n\n if (!accessToken) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_AUTHENTICATED');\n return;\n }\n\n const tokenInformation = await oAuth2Service.getAccessToken(accessToken);\n\n if (!tokenInformation) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUTH_ERROR');\n return;\n }\n\n if (clients.length >= MAX_SSE_CONNECTIONS) {\n ErrorHandler.handleGenericErrorResponse(res, 'TOO_MANY_CONNECTIONS');\n return;\n }\n\n // Set headers for SSE\n res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');\n res.setHeader('Cache-Control', 'no-cache, no-transform');\n res.setHeader('Connection', 'keep-alive');\n res.setHeader('X-Accel-Buffering', 'no'); // For Nginx buffering\n\n // Send initial data to ensure the connection is open\n res.write(':\\n\\n'); // Comment to keep connection alive\n res.flushHeaders?.();\n\n const clientId = Date.now();\n\n // Add client to the list\n const newClient = {\n id: clientId,\n projectId: String((tokenInformation as unknown as Token).project._id),\n res,\n };\n clients.push(newClient);\n\n logger.info(\n `New client connected to SSE. Total clients: ${clients.length ?? 0}`\n );\n\n // Remove client on connection close\n req.on('close', () => {\n clients = clients.filter((client) => client.id !== clientId);\n });\n};\n"],"mappings":"AAEA,YAAY,mBAAmB;AAC/B,SAAS,oBAAoB;AAG7B,SAAS,cAAc;AAWvB,IAAI,UAAmE,CAAC;AACxE,MAAM,sBAAsB;AAOrB,MAAM,uBAAuB,CAAC,SAAoC;AACvE,QAAM,aAAa,KAAK,QAAQ,CAAC,QAAQ,IAAI,WAAW,UAAU;AAElE,QAAM,kBAAkB,QAAQ;AAAA,IAAO,CAAC,WACtC,WAAW,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,EAAE,SAAS,OAAO,OAAO,SAAS,CAAC;AAAA,EACtE;AAEA,QAAM,OAA2B,KAAK,IAAI,CAAC,SAAS;AAAA,IAClD,QAAQ;AAAA,IACR,QAAQ,IAAI;AAAA,IACZ,MAAM,IAAI;AAAA,EACZ,EAAE;AAEF,UAAQ,SAAS,MAAM;AACrB,eAAW,UAAU,iBAAiB;AACpC,aAAO,IAAI,MAAM,SAAS,KAAK,UAAU,IAAI,CAAC;AAAA;AAAA,CAAM;AACpD,aAAO,IAAI,QAAQ;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAOO,MAAM,kBAAkB,OAC7B,KACA,QACG;AACH,QAAM,EAAE,YAAY,IAAI,IAAI;AAE5B,MAAI,CAAC,aAAa;AAChB,iBAAa,2BAA2B,KAAK,wBAAwB;AACrE;AAAA,EACF;AAEA,QAAM,mBAAmB,MAAM,cAAc,eAAe,WAAW;AAEvE,MAAI,CAAC,kBAAkB;AACrB,iBAAa,2BAA2B,KAAK,YAAY;AACzD;AAAA,EACF;AAEA,MAAI,QAAQ,UAAU,qBAAqB;AACzC,iBAAa,2BAA2B,KAAK,sBAAsB;AACnE;AAAA,EACF;AAGA,MAAI,UAAU,gBAAgB,iCAAiC;AAC/D,MAAI,UAAU,iBAAiB,wBAAwB;AACvD,MAAI,UAAU,cAAc,YAAY;AACxC,MAAI,UAAU,qBAAqB,IAAI;AAGvC,MAAI,MAAM,OAAO;AACjB,MAAI,eAAe;AAEnB,QAAM,WAAW,KAAK,IAAI;AAG1B,QAAM,YAAY;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW,OAAQ,iBAAsC,QAAQ,GAAG;AAAA,IACpE;AAAA,EACF;AACA,UAAQ,KAAK,SAAS;AAEtB,SAAO;AAAA,IACL,+CAA+C,QAAQ,UAAU,CAAC;AAAA,EACpE;AAGA,MAAI,GAAG,SAAS,MAAM;AACpB,cAAU,QAAQ,OAAO,CAAC,WAAW,OAAO,OAAO,QAAQ;AAAA,EAC7D,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/controllers/eventListener.controller.ts"],"sourcesContent":["import type { DictionaryAPI } from '@/types/dictionary.types';\nimport { logger } from '@logger';\nimport { ErrorHandler } from '@utils/errors';\nimport type { Request, Response } from 'express';\n\nexport type Object = 'DICTIONARY';\nexport type Status = 'ADDED' | 'UPDATED' | 'DELETED' | 'CREATED';\n\nexport type MessageEventData = {\n object: Object;\n status: Status;\n data: any;\n};\n\nlet clients: Array<{ id: number; projectId: string; res: Response }> = [];\nconst MAX_SSE_CONNECTIONS = 10;\n\nexport type SendDictionaryUpdateArg = {\n dictionary: DictionaryAPI;\n status: 'ADDED' | 'UPDATED' | 'DELETED' | 'CREATED';\n};\n\nexport const sendDictionaryUpdate = (args: SendDictionaryUpdateArg[]) => {\n const projectIds = args.flatMap((arg) => arg.dictionary.projectIds);\n\n const filteredClients = clients.filter((client) =>\n projectIds.map((id) => String(id)).includes(String(client.projectId))\n );\n\n const data: MessageEventData[] = args.map((arg) => ({\n object: 'DICTIONARY',\n status: arg.status,\n data: arg.dictionary,\n }));\n\n process.nextTick(() => {\n for (const client of filteredClients) {\n client.res.write(`data: ${JSON.stringify(data)}\\n\\n`);\n client.res.flush?.(); // Ensure the data is sent immediately\n }\n });\n};\n\nexport type CheckDictionaryChangeSSEParams = { accessToken: string };\n\n/**\n * SSE to check the email verification status\n */\nexport const listenChangeSSE = async (\n req: Request<CheckDictionaryChangeSSEParams, any, any>,\n res: Response\n) => {\n const { accessToken } = req.params;\n\n if (!accessToken) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_AUTHENTICATED');\n return;\n }\n\n if (clients.length >= MAX_SSE_CONNECTIONS) {\n ErrorHandler.handleGenericErrorResponse(res, 'TOO_MANY_CONNECTIONS');\n return;\n }\n\n // Set headers for SSE\n res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');\n res.setHeader('Cache-Control', 'no-cache, no-transform');\n res.setHeader('Connection', 'keep-alive');\n res.setHeader('X-Accel-Buffering', 'no'); // For Nginx buffering\n\n // Send initial data to ensure the connection is open\n res.write(':\\n\\n'); // Comment to keep connection alive\n res.flushHeaders?.();\n\n const clientId = Date.now();\n\n // Add client to the list\n const newClient = {\n id: clientId,\n projectId: String((res.locals.session as any).session.activeProjectId),\n res,\n };\n clients.push(newClient);\n\n logger.info(\n `New client connected to SSE. Total clients: ${clients.length ?? 0}`\n );\n\n // Remove client on connection close\n req.on('close', () => {\n clients = clients.filter((client) => client.id !== clientId);\n });\n};\n"],"mappings":"AACA,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAY7B,IAAI,UAAmE,CAAC;AACxE,MAAM,sBAAsB;AAOrB,MAAM,uBAAuB,CAAC,SAAoC;AACvE,QAAM,aAAa,KAAK,QAAQ,CAAC,QAAQ,IAAI,WAAW,UAAU;AAElE,QAAM,kBAAkB,QAAQ;AAAA,IAAO,CAAC,WACtC,WAAW,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,EAAE,SAAS,OAAO,OAAO,SAAS,CAAC;AAAA,EACtE;AAEA,QAAM,OAA2B,KAAK,IAAI,CAAC,SAAS;AAAA,IAClD,QAAQ;AAAA,IACR,QAAQ,IAAI;AAAA,IACZ,MAAM,IAAI;AAAA,EACZ,EAAE;AAEF,UAAQ,SAAS,MAAM;AACrB,eAAW,UAAU,iBAAiB;AACpC,aAAO,IAAI,MAAM,SAAS,KAAK,UAAU,IAAI,CAAC;AAAA;AAAA,CAAM;AACpD,aAAO,IAAI,QAAQ;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAOO,MAAM,kBAAkB,OAC7B,KACA,QACG;AACH,QAAM,EAAE,YAAY,IAAI,IAAI;AAE5B,MAAI,CAAC,aAAa;AAChB,iBAAa,2BAA2B,KAAK,wBAAwB;AACrE;AAAA,EACF;AAEA,MAAI,QAAQ,UAAU,qBAAqB;AACzC,iBAAa,2BAA2B,KAAK,sBAAsB;AACnE;AAAA,EACF;AAGA,MAAI,UAAU,gBAAgB,iCAAiC;AAC/D,MAAI,UAAU,iBAAiB,wBAAwB;AACvD,MAAI,UAAU,cAAc,YAAY;AACxC,MAAI,UAAU,qBAAqB,IAAI;AAGvC,MAAI,MAAM,OAAO;AACjB,MAAI,eAAe;AAEnB,QAAM,WAAW,KAAK,IAAI;AAG1B,QAAM,YAAY;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW,OAAQ,IAAI,OAAO,QAAgB,QAAQ,eAAe;AAAA,IACrE;AAAA,EACF;AACA,UAAQ,KAAK,SAAS;AAEtB,SAAO;AAAA,IACL,+CAA+C,QAAQ,UAAU,CAAC;AAAA,EACpE;AAGA,MAAI,GAAG,SAAS,MAAM;AACpB,cAAU,QAAQ,OAAO,CAAC,WAAW,OAAO,OAAO,QAAQ;AAAA,EAC7D,CAAC;AACH;","names":[]}
@@ -2,9 +2,12 @@ import { logger } from "./../logger/index.mjs";
2
2
  import * as userService from "./../services/user.service.mjs";
3
3
  import { ErrorHandler } from "./../utils/errors/index.mjs";
4
4
  import { mapUserToAPI } from "./../utils/mapper/user.mjs";
5
+ import { hasPermission } from "./../utils/permissions.mjs";
5
6
  import { formatResponse } from "./../utils/responseData.mjs";
6
7
  import { t } from "express-intlayer";
8
+ import { ObjectId } from "mongodb";
7
9
  const subscribeToNewsletter = async (req, res, _next) => {
10
+ const { roles } = res.locals;
8
11
  const { email, emailList } = req.body;
9
12
  if (!email) {
10
13
  ErrorHandler.handleGenericErrorResponse(res, "USER_DATA_NOT_FOUND");
@@ -23,7 +26,17 @@ const subscribeToNewsletter = async (req, res, _next) => {
23
26
  });
24
27
  logger.info(`New user created and subscribed to newsletter: ${email}`);
25
28
  } else {
26
- user = await userService.updateUserById(user._id, {
29
+ if (!hasPermission(
30
+ roles,
31
+ "user:write"
32
+ )({
33
+ ...res.locals,
34
+ targetUserIds: [user.id]
35
+ })) {
36
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
37
+ return;
38
+ }
39
+ user = await userService.updateUserById(user.id, {
27
40
  emailsList: { ...user.emailsList, ...emailsListObject }
28
41
  });
29
42
  logger.info(`User subscribed to newsletter: ${email}`);
@@ -51,10 +64,21 @@ const subscribeToNewsletter = async (req, res, _next) => {
51
64
  };
52
65
  const unsubscribeFromNewsletter = async (req, res, _next) => {
53
66
  const { userId, emailList } = req.body;
67
+ const { roles } = res.locals;
54
68
  if (!userId) {
55
69
  ErrorHandler.handleGenericErrorResponse(res, "USER_DATA_NOT_FOUND");
56
70
  return;
57
71
  }
72
+ if (!hasPermission(
73
+ roles,
74
+ "user:write"
75
+ )({
76
+ ...res.locals,
77
+ targetUserIds: [new ObjectId(userId)]
78
+ })) {
79
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
80
+ return;
81
+ }
58
82
  try {
59
83
  const user = await userService.getUserById(userId);
60
84
  if (!user) {
@@ -65,7 +89,7 @@ const unsubscribeFromNewsletter = async (req, res, _next) => {
65
89
  const emailsListObject = Object.fromEntries(
66
90
  emailLists.map((list) => [list, false])
67
91
  );
68
- const updatedUser = await userService.updateUserById(user._id, {
92
+ const updatedUser = await userService.updateUserById(user.id, {
69
93
  emailsList: { ...user.emailsList, ...emailsListObject }
70
94
  });
71
95
  logger.info(`User unsubscribed from newsletter: ${updatedUser.email}`);
@@ -90,8 +114,9 @@ const unsubscribeFromNewsletter = async (req, res, _next) => {
90
114
  return;
91
115
  }
92
116
  };
93
- const getNewsletterStatus = async (req, res, _next) => {
117
+ const getNewsletterStatus = async (_req, res, _next) => {
94
118
  const email = res.locals.user?.email;
119
+ const { roles } = res.locals;
95
120
  if (!email) {
96
121
  ErrorHandler.handleGenericErrorResponse(res, "USER_DATA_NOT_FOUND");
97
122
  return;
@@ -102,6 +127,16 @@ const getNewsletterStatus = async (req, res, _next) => {
102
127
  ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
103
128
  return;
104
129
  }
130
+ if (!hasPermission(
131
+ roles,
132
+ "user:read"
133
+ )({
134
+ ...res.locals,
135
+ targetUserIds: [user.id]
136
+ })) {
137
+ ErrorHandler.handleGenericErrorResponse(res, "PERMISSION_DENIED");
138
+ return;
139
+ }
105
140
  const formattedUser = mapUserToAPI(user);
106
141
  const responseData = formatResponse({
107
142
  message: t({