@intlayer/backend 5.5.11 → 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 (513) 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/PROMPT.md +7 -1
  120. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs +32 -14
  121. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs.map +1 -1
  122. package/dist/cjs/utils/AI/askDocQuestion/embeddings.json +88086 -76800
  123. package/dist/cjs/utils/AI/autocomplete/PROMPT.md +18 -2
  124. package/dist/cjs/utils/AI/autocomplete/index.cjs +8 -5
  125. package/dist/cjs/utils/AI/autocomplete/index.cjs.map +1 -1
  126. package/dist/cjs/utils/access.cjs +2 -0
  127. package/dist/cjs/utils/access.cjs.map +1 -0
  128. package/dist/cjs/utils/accessControl.cjs +7 -0
  129. package/dist/cjs/utils/accessControl.cjs.map +1 -1
  130. package/dist/cjs/utils/auth/getAuth.cjs +248 -0
  131. package/dist/cjs/utils/auth/getAuth.cjs.map +1 -0
  132. package/dist/cjs/utils/cors.cjs +55 -0
  133. package/dist/cjs/utils/cors.cjs.map +1 -0
  134. package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +1 -1
  135. package/dist/cjs/utils/errors/ErrorHandler.cjs +2 -2
  136. package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
  137. package/dist/cjs/utils/errors/errorCodes.cjs +114 -153
  138. package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
  139. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
  140. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
  141. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -1
  142. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +1 -1
  143. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
  144. package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
  145. package/dist/cjs/utils/mapper/organization.cjs +10 -8
  146. package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
  147. package/dist/cjs/utils/mapper/project.cjs +5 -18
  148. package/dist/cjs/utils/mapper/project.cjs.map +1 -1
  149. package/dist/cjs/utils/mapper/tag.cjs +4 -2
  150. package/dist/cjs/utils/mapper/tag.cjs.map +1 -1
  151. package/dist/cjs/utils/mapper/user.cjs +6 -3
  152. package/dist/cjs/utils/mapper/user.cjs.map +1 -1
  153. package/dist/cjs/utils/mergeFunctionTypes.cjs +17 -0
  154. package/dist/cjs/utils/mergeFunctionTypes.cjs.map +1 -0
  155. package/dist/cjs/utils/mongoDB/connectDB.cjs +3 -1
  156. package/dist/cjs/utils/mongoDB/connectDB.cjs.map +1 -1
  157. package/dist/cjs/utils/mongoDB/types.cjs +17 -0
  158. package/dist/cjs/utils/mongoDB/types.cjs.map +1 -0
  159. package/dist/cjs/utils/oAuth2.cjs.map +1 -1
  160. package/dist/cjs/utils/permissions.cjs +166 -0
  161. package/dist/cjs/utils/permissions.cjs.map +1 -0
  162. package/dist/cjs/utils/rateLimiter.cjs +88 -0
  163. package/dist/cjs/utils/rateLimiter.cjs.map +1 -0
  164. package/dist/esm/controllers/ai.controller.mjs +10 -7
  165. package/dist/esm/controllers/ai.controller.mjs.map +1 -1
  166. package/dist/esm/controllers/dictionary.controller.mjs +50 -58
  167. package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
  168. package/dist/esm/controllers/eventListener.controller.mjs +2 -8
  169. package/dist/esm/controllers/eventListener.controller.mjs.map +1 -1
  170. package/dist/esm/controllers/newsletter.controller.mjs +38 -3
  171. package/dist/esm/controllers/newsletter.controller.mjs.map +1 -1
  172. package/dist/esm/controllers/oAuth2.controller.mjs +2 -2
  173. package/dist/esm/controllers/oAuth2.controller.mjs.map +1 -1
  174. package/dist/esm/controllers/organization.controller.mjs +95 -106
  175. package/dist/esm/controllers/organization.controller.mjs.map +1 -1
  176. package/dist/esm/controllers/project.controller.mjs +81 -83
  177. package/dist/esm/controllers/project.controller.mjs.map +1 -1
  178. package/dist/esm/controllers/projectAccessKey.controller.mjs +30 -24
  179. package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
  180. package/dist/esm/controllers/search.controller.mjs.map +1 -1
  181. package/dist/esm/controllers/stripe.controller.mjs +4 -25
  182. package/dist/esm/controllers/stripe.controller.mjs.map +1 -1
  183. package/dist/esm/controllers/tag.controller.mjs +27 -16
  184. package/dist/esm/controllers/tag.controller.mjs.map +1 -1
  185. package/dist/esm/controllers/user.controller.mjs +85 -22
  186. package/dist/esm/controllers/user.controller.mjs.map +1 -1
  187. package/dist/esm/emails/InviteUserEmail.mjs +32 -14
  188. package/dist/esm/emails/InviteUserEmail.mjs.map +1 -1
  189. package/dist/esm/emails/OAuthTokenCreatedEmail.mjs +254 -0
  190. package/dist/esm/emails/OAuthTokenCreatedEmail.mjs.map +1 -0
  191. package/dist/esm/emails/ResetUserPassword.mjs +29 -17
  192. package/dist/esm/emails/ResetUserPassword.mjs.map +1 -1
  193. package/dist/esm/emails/ValidateUserEmail.mjs +29 -38
  194. package/dist/esm/emails/ValidateUserEmail.mjs.map +1 -1
  195. package/dist/esm/emails/Welcome.mjs +29 -17
  196. package/dist/esm/emails/Welcome.mjs.map +1 -1
  197. package/dist/esm/emails/index.mjs +3 -2
  198. package/dist/esm/emails/index.mjs.map +1 -1
  199. package/dist/esm/export.mjs +1 -3
  200. package/dist/esm/export.mjs.map +1 -1
  201. package/dist/esm/index.mjs +60 -111
  202. package/dist/esm/index.mjs.map +1 -1
  203. package/dist/esm/middlewares/oAuth2.middleware.mjs +27 -36
  204. package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
  205. package/dist/esm/middlewares/request.middleware.mjs.map +1 -1
  206. package/dist/esm/middlewares/sessionAuth.middleware.mjs +16 -127
  207. package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -1
  208. package/dist/esm/models/dictionary.model.mjs.map +1 -1
  209. package/dist/esm/models/discussion.model.mjs.map +1 -1
  210. package/dist/esm/models/oAuth2.model.mjs +4 -1
  211. package/dist/esm/models/oAuth2.model.mjs.map +1 -1
  212. package/dist/esm/models/organization.model.mjs +1 -4
  213. package/dist/esm/models/organization.model.mjs.map +1 -1
  214. package/dist/esm/models/project.model.mjs +4 -1
  215. package/dist/esm/models/project.model.mjs.map +1 -1
  216. package/dist/esm/models/session.model.mjs +10 -0
  217. package/dist/esm/models/session.model.mjs.map +1 -0
  218. package/dist/esm/models/tag.model.mjs.map +1 -1
  219. package/dist/esm/models/user.model.mjs.map +1 -1
  220. package/dist/esm/routes/ai.routes.mjs +3 -1
  221. package/dist/esm/routes/ai.routes.mjs.map +1 -1
  222. package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
  223. package/dist/esm/routes/eventListener.routes.mjs +1 -1
  224. package/dist/esm/routes/eventListener.routes.mjs.map +1 -1
  225. package/dist/esm/routes/newsletter.routes.mjs.map +1 -1
  226. package/dist/esm/routes/organization.routes.mjs +8 -8
  227. package/dist/esm/routes/organization.routes.mjs.map +1 -1
  228. package/dist/esm/routes/project.routes.mjs +23 -14
  229. package/dist/esm/routes/project.routes.mjs.map +1 -1
  230. package/dist/esm/routes/search.routes.mjs.map +1 -1
  231. package/dist/esm/routes/stripe.routes.mjs.map +1 -1
  232. package/dist/esm/routes/tags.routes.mjs +4 -4
  233. package/dist/esm/routes/tags.routes.mjs.map +1 -1
  234. package/dist/esm/routes/user.routes.mjs +14 -14
  235. package/dist/esm/routes/user.routes.mjs.map +1 -1
  236. package/dist/esm/schemas/dictionary.schema.mjs +18 -1
  237. package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
  238. package/dist/esm/schemas/discussion.schema.mjs +18 -1
  239. package/dist/esm/schemas/discussion.schema.mjs.map +1 -1
  240. package/dist/esm/schemas/oAuth2.schema.mjs +18 -1
  241. package/dist/esm/schemas/oAuth2.schema.mjs.map +1 -1
  242. package/dist/esm/schemas/organization.schema.mjs +21 -1
  243. package/dist/esm/schemas/organization.schema.mjs.map +1 -1
  244. package/dist/esm/schemas/plans.schema.mjs +18 -1
  245. package/dist/esm/schemas/plans.schema.mjs.map +1 -1
  246. package/dist/esm/schemas/project.schema.mjs +21 -15
  247. package/dist/esm/schemas/project.schema.mjs.map +1 -1
  248. package/dist/esm/schemas/session.schema.mjs +39 -0
  249. package/dist/esm/schemas/session.schema.mjs.map +1 -0
  250. package/dist/esm/schemas/tag.schema.mjs +21 -4
  251. package/dist/esm/schemas/tag.schema.mjs.map +1 -1
  252. package/dist/esm/schemas/user.schema.mjs +18 -48
  253. package/dist/esm/schemas/user.schema.mjs.map +1 -1
  254. package/dist/esm/services/dictionary.service.mjs +6 -5
  255. package/dist/esm/services/dictionary.service.mjs.map +1 -1
  256. package/dist/esm/services/email.service.mjs +33 -16
  257. package/dist/esm/services/email.service.mjs.map +1 -1
  258. package/dist/esm/services/oAuth2.service.mjs +47 -10
  259. package/dist/esm/services/oAuth2.service.mjs.map +1 -1
  260. package/dist/esm/services/organization.service.mjs +16 -14
  261. package/dist/esm/services/organization.service.mjs.map +1 -1
  262. package/dist/esm/services/project.service.mjs +1 -1
  263. package/dist/esm/services/project.service.mjs.map +1 -1
  264. package/dist/esm/services/projectAccessKey.service.mjs +15 -31
  265. package/dist/esm/services/projectAccessKey.service.mjs.map +1 -1
  266. package/dist/esm/services/subscription.service.mjs +10 -10
  267. package/dist/esm/services/subscription.service.mjs.map +1 -1
  268. package/dist/esm/services/tag.service.mjs.map +1 -1
  269. package/dist/esm/services/user.service.mjs +2 -40
  270. package/dist/esm/services/user.service.mjs.map +1 -1
  271. package/dist/esm/types/user.types.mjs.map +1 -1
  272. package/dist/esm/utils/AI/aiSdk.mjs.map +1 -1
  273. package/dist/esm/utils/AI/askDocQuestion/PROMPT.md +7 -1
  274. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs +32 -14
  275. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs.map +1 -1
  276. package/dist/esm/utils/AI/askDocQuestion/embeddings.json +88086 -76800
  277. package/dist/esm/utils/AI/autocomplete/PROMPT.md +18 -2
  278. package/dist/esm/utils/AI/autocomplete/index.mjs +8 -5
  279. package/dist/esm/utils/AI/autocomplete/index.mjs.map +1 -1
  280. package/dist/esm/utils/access.mjs +1 -0
  281. package/dist/esm/utils/access.mjs.map +1 -0
  282. package/dist/esm/utils/accessControl.mjs +7 -0
  283. package/dist/esm/utils/accessControl.mjs.map +1 -1
  284. package/dist/esm/utils/auth/getAuth.mjs +227 -0
  285. package/dist/esm/utils/auth/getAuth.mjs.map +1 -0
  286. package/dist/esm/utils/cors.mjs +31 -0
  287. package/dist/esm/utils/cors.mjs.map +1 -0
  288. package/dist/esm/utils/ensureMongoDocumentToObject.mjs.map +1 -1
  289. package/dist/esm/utils/errors/ErrorHandler.mjs +2 -2
  290. package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
  291. package/dist/esm/utils/errors/errorCodes.mjs +114 -153
  292. package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
  293. package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
  294. package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
  295. package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -1
  296. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +1 -1
  297. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
  298. package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
  299. package/dist/esm/utils/mapper/organization.mjs +8 -7
  300. package/dist/esm/utils/mapper/organization.mjs.map +1 -1
  301. package/dist/esm/utils/mapper/project.mjs +5 -18
  302. package/dist/esm/utils/mapper/project.mjs.map +1 -1
  303. package/dist/esm/utils/mapper/tag.mjs +4 -2
  304. package/dist/esm/utils/mapper/tag.mjs.map +1 -1
  305. package/dist/esm/utils/mapper/user.mjs +6 -3
  306. package/dist/esm/utils/mapper/user.mjs.map +1 -1
  307. package/dist/esm/utils/mergeFunctionTypes.mjs +1 -0
  308. package/dist/esm/utils/mergeFunctionTypes.mjs.map +1 -0
  309. package/dist/esm/utils/mongoDB/connectDB.mjs +3 -1
  310. package/dist/esm/utils/mongoDB/connectDB.mjs.map +1 -1
  311. package/dist/esm/utils/mongoDB/types.mjs +1 -0
  312. package/dist/esm/utils/mongoDB/types.mjs.map +1 -0
  313. package/dist/esm/utils/oAuth2.mjs +3 -3
  314. package/dist/esm/utils/oAuth2.mjs.map +1 -1
  315. package/dist/esm/utils/permissions.mjs +138 -0
  316. package/dist/esm/utils/permissions.mjs.map +1 -0
  317. package/dist/esm/utils/rateLimiter.mjs +53 -0
  318. package/dist/esm/utils/rateLimiter.mjs.map +1 -0
  319. package/dist/types/controllers/ai.controller.d.ts +12 -10
  320. package/dist/types/controllers/ai.controller.d.ts.map +1 -1
  321. package/dist/types/controllers/dictionary.controller.d.ts +8 -9
  322. package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
  323. package/dist/types/controllers/eventListener.controller.d.ts +2 -3
  324. package/dist/types/controllers/eventListener.controller.d.ts.map +1 -1
  325. package/dist/types/controllers/newsletter.controller.d.ts +5 -6
  326. package/dist/types/controllers/newsletter.controller.d.ts.map +1 -1
  327. package/dist/types/controllers/oAuth2.controller.d.ts +3 -3
  328. package/dist/types/controllers/oAuth2.controller.d.ts.map +1 -1
  329. package/dist/types/controllers/organization.controller.d.ts +22 -23
  330. package/dist/types/controllers/organization.controller.d.ts.map +1 -1
  331. package/dist/types/controllers/project.controller.d.ts +13 -14
  332. package/dist/types/controllers/project.controller.d.ts.map +1 -1
  333. package/dist/types/controllers/projectAccessKey.controller.d.ts +5 -6
  334. package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
  335. package/dist/types/controllers/search.controller.d.ts +2 -3
  336. package/dist/types/controllers/search.controller.d.ts.map +1 -1
  337. package/dist/types/controllers/stripe.controller.d.ts +5 -6
  338. package/dist/types/controllers/stripe.controller.d.ts.map +1 -1
  339. package/dist/types/controllers/tag.controller.d.ts +9 -10
  340. package/dist/types/controllers/tag.controller.d.ts.map +1 -1
  341. package/dist/types/controllers/user.controller.d.ts +16 -19
  342. package/dist/types/controllers/user.controller.d.ts.map +1 -1
  343. package/dist/types/emails/InviteUserEmail.d.ts.map +1 -1
  344. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts +21 -0
  345. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts.map +1 -0
  346. package/dist/types/emails/ResetUserPassword.d.ts.map +1 -1
  347. package/dist/types/emails/Welcome.d.ts.map +1 -1
  348. package/dist/types/emails/index.d.ts +3 -2
  349. package/dist/types/emails/index.d.ts.map +1 -1
  350. package/dist/types/export.d.ts +2 -3
  351. package/dist/types/export.d.ts.map +1 -1
  352. package/dist/types/index.d.ts +1 -3
  353. package/dist/types/index.d.ts.map +1 -1
  354. package/dist/types/middlewares/oAuth2.middleware.d.ts +1 -2
  355. package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -1
  356. package/dist/types/middlewares/request.middleware.d.ts +3 -3
  357. package/dist/types/middlewares/request.middleware.d.ts.map +1 -1
  358. package/dist/types/middlewares/sessionAuth.middleware.d.ts +3 -25
  359. package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
  360. package/dist/types/models/dictionary.model.d.ts +6 -5
  361. package/dist/types/models/dictionary.model.d.ts.map +1 -1
  362. package/dist/types/models/discussion.model.d.ts +7 -2
  363. package/dist/types/models/discussion.model.d.ts.map +1 -1
  364. package/dist/types/models/oAuth2.model.d.ts +3 -2
  365. package/dist/types/models/oAuth2.model.d.ts.map +1 -1
  366. package/dist/types/models/organization.model.d.ts +2 -12
  367. package/dist/types/models/organization.model.d.ts.map +1 -1
  368. package/dist/types/models/project.model.d.ts +2 -11
  369. package/dist/types/models/project.model.d.ts.map +1 -1
  370. package/dist/types/models/session.model.d.ts +3 -0
  371. package/dist/types/models/session.model.d.ts.map +1 -0
  372. package/dist/types/models/tag.model.d.ts.map +1 -1
  373. package/dist/types/models/user.model.d.ts.map +1 -1
  374. package/dist/types/routes/ai.routes.d.ts.map +1 -1
  375. package/dist/types/routes/organization.routes.d.ts +4 -4
  376. package/dist/types/routes/project.routes.d.ts +4 -4
  377. package/dist/types/routes/project.routes.d.ts.map +1 -1
  378. package/dist/types/routes/tags.routes.d.ts +2 -2
  379. package/dist/types/routes/user.routes.d.ts +6 -7
  380. package/dist/types/routes/user.routes.d.ts.map +1 -1
  381. package/dist/types/schemas/dictionary.schema.d.ts +6 -8
  382. package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
  383. package/dist/types/schemas/discussion.schema.d.ts +7 -5
  384. package/dist/types/schemas/discussion.schema.d.ts.map +1 -1
  385. package/dist/types/schemas/oAuth2.schema.d.ts +4 -3
  386. package/dist/types/schemas/oAuth2.schema.d.ts.map +1 -1
  387. package/dist/types/schemas/organization.schema.d.ts +6 -10
  388. package/dist/types/schemas/organization.schema.d.ts.map +1 -1
  389. package/dist/types/schemas/plans.schema.d.ts +6 -8
  390. package/dist/types/schemas/plans.schema.d.ts.map +1 -1
  391. package/dist/types/schemas/project.schema.d.ts +5 -17
  392. package/dist/types/schemas/project.schema.d.ts.map +1 -1
  393. package/dist/types/schemas/session.schema.d.ts +14 -0
  394. package/dist/types/schemas/session.schema.d.ts.map +1 -0
  395. package/dist/types/schemas/tag.schema.d.ts +6 -8
  396. package/dist/types/schemas/tag.schema.d.ts.map +1 -1
  397. package/dist/types/schemas/user.schema.d.ts +7 -5
  398. package/dist/types/schemas/user.schema.d.ts.map +1 -1
  399. package/dist/types/services/dictionary.service.d.ts +9 -9
  400. package/dist/types/services/dictionary.service.d.ts.map +1 -1
  401. package/dist/types/services/email.service.d.ts +4 -0
  402. package/dist/types/services/email.service.d.ts.map +1 -1
  403. package/dist/types/services/oAuth2.service.d.ts +23 -14
  404. package/dist/types/services/oAuth2.service.d.ts.map +1 -1
  405. package/dist/types/services/organization.service.d.ts +6 -12
  406. package/dist/types/services/organization.service.d.ts.map +1 -1
  407. package/dist/types/services/project.service.d.ts +5 -5
  408. package/dist/types/services/project.service.d.ts.map +1 -1
  409. package/dist/types/services/projectAccessKey.service.d.ts +5 -5
  410. package/dist/types/services/projectAccessKey.service.d.ts.map +1 -1
  411. package/dist/types/services/subscription.service.d.ts +1 -1
  412. package/dist/types/services/subscription.service.d.ts.map +1 -1
  413. package/dist/types/services/tag.service.d.ts +6 -6
  414. package/dist/types/services/tag.service.d.ts.map +1 -1
  415. package/dist/types/services/user.service.d.ts +7 -21
  416. package/dist/types/services/user.service.d.ts.map +1 -1
  417. package/dist/types/types/dictionary.types.d.ts +11 -9
  418. package/dist/types/types/dictionary.types.d.ts.map +1 -1
  419. package/dist/types/types/discussion.types.d.ts +5 -2
  420. package/dist/types/types/discussion.types.d.ts.map +1 -1
  421. package/dist/types/types/oAuth2.types.d.ts +5 -2
  422. package/dist/types/types/oAuth2.types.d.ts.map +1 -1
  423. package/dist/types/types/organization.types.d.ts +11 -8
  424. package/dist/types/types/organization.types.d.ts.map +1 -1
  425. package/dist/types/types/plan.types.d.ts +6 -3
  426. package/dist/types/types/plan.types.d.ts.map +1 -1
  427. package/dist/types/types/project.types.d.ts +25 -25
  428. package/dist/types/types/project.types.d.ts.map +1 -1
  429. package/dist/types/types/session.types.d.ts +31 -17
  430. package/dist/types/types/session.types.d.ts.map +1 -1
  431. package/dist/types/types/tag.types.d.ts +8 -6
  432. package/dist/types/types/tag.types.d.ts.map +1 -1
  433. package/dist/types/types/user.types.d.ts +14 -21
  434. package/dist/types/types/user.types.d.ts.map +1 -1
  435. package/dist/types/utils/AI/aiSdk.d.ts +2 -2
  436. package/dist/types/utils/AI/aiSdk.d.ts.map +1 -1
  437. package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts +2 -0
  438. package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts.map +1 -1
  439. package/dist/types/utils/AI/autocomplete/index.d.ts +4 -1
  440. package/dist/types/utils/AI/autocomplete/index.d.ts.map +1 -1
  441. package/dist/types/utils/access.d.ts +1 -0
  442. package/dist/types/utils/access.d.ts.map +1 -0
  443. package/dist/types/utils/accessControl.d.ts +9 -9
  444. package/dist/types/utils/accessControl.d.ts.map +1 -1
  445. package/dist/types/utils/auth/getAuth.d.ts +7 -0
  446. package/dist/types/utils/auth/getAuth.d.ts.map +1 -0
  447. package/dist/types/utils/cors.d.ts +3 -0
  448. package/dist/types/utils/cors.d.ts.map +1 -0
  449. package/dist/types/utils/ensureMongoDocumentToObject.d.ts +2 -2
  450. package/dist/types/utils/ensureMongoDocumentToObject.d.ts.map +1 -1
  451. package/dist/types/utils/errors/ErrorHandler.d.ts +1 -1
  452. package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
  453. package/dist/types/utils/errors/errorCodes.d.ts +57 -96
  454. package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
  455. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +1 -1
  456. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
  457. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +1 -1
  458. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
  459. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +1 -1
  460. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -1
  461. package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts +1 -1
  462. package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
  463. package/dist/types/utils/mapper/dictionary.d.ts +1 -1
  464. package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
  465. package/dist/types/utils/mapper/organization.d.ts +3 -2
  466. package/dist/types/utils/mapper/organization.d.ts.map +1 -1
  467. package/dist/types/utils/mapper/project.d.ts +4 -5
  468. package/dist/types/utils/mapper/project.d.ts.map +1 -1
  469. package/dist/types/utils/mapper/tag.d.ts +1 -1
  470. package/dist/types/utils/mapper/tag.d.ts.map +1 -1
  471. package/dist/types/utils/mapper/user.d.ts +2 -2
  472. package/dist/types/utils/mapper/user.d.ts.map +1 -1
  473. package/dist/types/utils/mergeFunctionTypes.d.ts +18 -0
  474. package/dist/types/utils/mergeFunctionTypes.d.ts.map +1 -0
  475. package/dist/types/utils/mongoDB/connectDB.d.ts +1 -1
  476. package/dist/types/utils/mongoDB/connectDB.d.ts.map +1 -1
  477. package/dist/types/utils/mongoDB/types.d.ts +11 -0
  478. package/dist/types/utils/mongoDB/types.d.ts.map +1 -0
  479. package/dist/types/utils/permissions.d.ts +115 -0
  480. package/dist/types/utils/permissions.d.ts.map +1 -0
  481. package/dist/types/utils/rateLimiter.d.ts +4 -0
  482. package/dist/types/utils/rateLimiter.d.ts.map +1 -0
  483. package/package.json +16 -14
  484. package/dist/cjs/controllers/sessionAuth.controller.cjs +0 -839
  485. package/dist/cjs/controllers/sessionAuth.controller.cjs.map +0 -1
  486. package/dist/cjs/routes/sessionAuth.routes.cjs +0 -154
  487. package/dist/cjs/routes/sessionAuth.routes.cjs.map +0 -1
  488. package/dist/cjs/services/sessionAuth.service.cjs +0 -385
  489. package/dist/cjs/services/sessionAuth.service.cjs.map +0 -1
  490. package/dist/cjs/utils/CSRF.cjs +0 -50
  491. package/dist/cjs/utils/CSRF.cjs.map +0 -1
  492. package/dist/cjs/utils/cookies.cjs +0 -59
  493. package/dist/cjs/utils/cookies.cjs.map +0 -1
  494. package/dist/esm/controllers/sessionAuth.controller.mjs +0 -790
  495. package/dist/esm/controllers/sessionAuth.controller.mjs.map +0 -1
  496. package/dist/esm/routes/sessionAuth.routes.mjs +0 -142
  497. package/dist/esm/routes/sessionAuth.routes.mjs.map +0 -1
  498. package/dist/esm/services/sessionAuth.service.mjs +0 -337
  499. package/dist/esm/services/sessionAuth.service.mjs.map +0 -1
  500. package/dist/esm/utils/CSRF.mjs +0 -24
  501. package/dist/esm/utils/CSRF.mjs.map +0 -1
  502. package/dist/esm/utils/cookies.mjs +0 -32
  503. package/dist/esm/utils/cookies.mjs.map +0 -1
  504. package/dist/types/controllers/sessionAuth.controller.d.ts +0 -140
  505. package/dist/types/controllers/sessionAuth.controller.d.ts.map +0 -1
  506. package/dist/types/routes/sessionAuth.routes.d.ts +0 -77
  507. package/dist/types/routes/sessionAuth.routes.d.ts.map +0 -1
  508. package/dist/types/services/sessionAuth.service.d.ts +0 -141
  509. package/dist/types/services/sessionAuth.service.d.ts.map +0 -1
  510. package/dist/types/utils/CSRF.d.ts +0 -3
  511. package/dist/types/utils/CSRF.d.ts.map +0 -1
  512. package/dist/types/utils/cookies.d.ts +0 -12
  513. package/dist/types/utils/cookies.d.ts.map +0 -1
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var session_schema_exports = {};
20
+ __export(session_schema_exports, {
21
+ sessionSchema: () => sessionSchema
22
+ });
23
+ module.exports = __toCommonJS(session_schema_exports);
24
+ var import_mongoose = require("mongoose");
25
+ const sessionSchema = new import_mongoose.Schema(
26
+ {
27
+ activeOrganizationId: {
28
+ type: import_mongoose.Schema.Types.ObjectId,
29
+ ref: "Organization",
30
+ required: false
31
+ },
32
+ activeProjectId: {
33
+ type: import_mongoose.Schema.Types.ObjectId,
34
+ ref: "Project",
35
+ required: false
36
+ }
37
+ },
38
+ {
39
+ timestamps: true,
40
+ toJSON: {
41
+ virtuals: true,
42
+ // keep the automatic `id` getter
43
+ versionKey: false,
44
+ // drop __v
45
+ transform(doc, ret) {
46
+ ret.id = ret._id.toString();
47
+ delete ret._id;
48
+ }
49
+ },
50
+ toObject: {
51
+ virtuals: true,
52
+ transform(doc, ret) {
53
+ ret.id = ret._id.toString();
54
+ delete ret._id;
55
+ }
56
+ }
57
+ }
58
+ );
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ sessionSchema
62
+ });
63
+ //# sourceMappingURL=session.schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/schemas/session.schema.ts"],"sourcesContent":["import { SessionSchema } from '@/export';\nimport { Schema } from 'mongoose';\n\nexport const sessionSchema = new Schema<SessionSchema>(\n {\n activeOrganizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: false,\n },\n activeProjectId: {\n type: Schema.Types.ObjectId,\n ref: 'Project',\n required: false,\n },\n },\n {\n timestamps: true,\n\n toJSON: {\n virtuals: true, // keep the automatic `id` getter\n versionKey: false, // drop __v\n transform(doc, ret) {\n ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n toObject: {\n virtuals: true,\n transform(doc, ret) {\n ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAuB;AAEhB,MAAM,gBAAgB,IAAI;AAAA,EAC/B;AAAA,IACE,sBAAsB;AAAA,MACpB,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,IAEZ,QAAQ;AAAA,MACN,UAAU;AAAA;AAAA,MACV,YAAY;AAAA;AAAA,MACZ,UAAU,KAAK,KAAK;AAClB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU,KAAK,KAAK;AAClB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -54,7 +54,24 @@ const tagSchema = new import_mongoose.Schema(
54
54
  }
55
55
  },
56
56
  {
57
- timestamps: true
57
+ timestamps: true,
58
+ toJSON: {
59
+ virtuals: true,
60
+ // keep the automatic `id` getter
61
+ versionKey: false,
62
+ // drop __v
63
+ transform(doc, ret) {
64
+ ret.id = ret._id.toString();
65
+ delete ret._id;
66
+ }
67
+ },
68
+ toObject: {
69
+ virtuals: true,
70
+ transform(doc, ret) {
71
+ ret.id = ret._id.toString();
72
+ delete ret._id;
73
+ }
74
+ }
58
75
  }
59
76
  );
60
77
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/tag.schema.ts"],"sourcesContent":["import {\n NAME_MIN_LENGTH,\n NAME_MAX_LENGTH,\n KEY_MAX_LENGTH,\n KEY_MIN_LENGTH,\n} from '@utils/validation/validateTag';\nimport { Schema } from 'mongoose';\nimport type { Tag } from '@/types/tag.types';\n\nexport const tagSchema = new Schema<Tag>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n key: {\n type: String,\n required: true,\n minlength: KEY_MIN_LENGTH,\n maxlength: KEY_MAX_LENGTH,\n },\n name: {\n type: String,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n description: {\n type: String,\n },\n instructions: {\n type: String,\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAKO;AACP,sBAAuB;AAGhB,MAAM,YAAY,IAAI;AAAA,EAC3B;AAAA,IACE,gBAAgB;AAAA,MACd,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,KAAK;AAAA,MACH,MAAM;AAAA,MACN,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,aAAa;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,cAAc;AAAA,MACZ,MAAM;AAAA,IACR;AAAA,IACA,WAAW;AAAA,MACT,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/schemas/tag.schema.ts"],"sourcesContent":["import type { TagSchema } from '@/types/tag.types';\nimport {\n KEY_MAX_LENGTH,\n KEY_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateTag';\nimport { Schema } from 'mongoose';\n\nexport const tagSchema = new Schema<TagSchema>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n key: {\n type: String,\n required: true,\n minlength: KEY_MIN_LENGTH,\n maxlength: KEY_MAX_LENGTH,\n },\n name: {\n type: String,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n description: {\n type: String,\n },\n instructions: {\n type: String,\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n },\n {\n timestamps: true,\n\n toJSON: {\n virtuals: true, // keep the automatic `id` getter\n versionKey: false, // drop __v\n transform(doc, ret) {\n ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n toObject: {\n virtuals: true,\n transform(doc, ret) {\n ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAKO;AACP,sBAAuB;AAEhB,MAAM,YAAY,IAAI;AAAA,EAC3B;AAAA,IACE,gBAAgB;AAAA,MACd,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,KAAK;AAAA,MACH,MAAM;AAAA,MACN,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,aAAa;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,cAAc;AAAA,MACZ,MAAM;AAAA,IACR;AAAA,IACA,WAAW;AAAA,MACT,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,IAEZ,QAAQ;AAAA,MACN,UAAU;AAAA;AAAA,MACV,YAAY;AAAA;AAAA,MACZ,UAAU,KAAK,KAAK;AAClB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU,KAAK,KAAK;AAClB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -34,44 +34,6 @@ module.exports = __toCommonJS(user_schema_exports);
34
34
  var import_validateUser = require('./../utils/validation/validateUser.cjs');
35
35
  var import_mongoose = require("mongoose");
36
36
  var import_validator = __toESM(require("validator"), 1);
37
- const SessionSchema = new import_mongoose.Schema(
38
- {
39
- sessionToken: {
40
- type: String,
41
- required: true
42
- },
43
- expires: {
44
- type: Date,
45
- required: true
46
- }
47
- },
48
- { _id: false }
49
- // This prevents Mongoose from creating an _id field for the session subdocument
50
- );
51
- const ProviderSchema = new import_mongoose.Schema(
52
- {
53
- provider: {
54
- type: String,
55
- required: true
56
- },
57
- providerAccountId: {
58
- type: String
59
- },
60
- secret: {
61
- type: String,
62
- maxlength: 1024,
63
- minlength: 6
64
- },
65
- emailValidated: {
66
- type: String
67
- },
68
- passwordHash: {
69
- type: String
70
- }
71
- },
72
- { _id: false }
73
- // This prevents Mongoose from creating an _id field for the session subdocument
74
- );
75
37
  const userSchema = new import_mongoose.Schema(
76
38
  {
77
39
  email: {
@@ -91,10 +53,6 @@ const userSchema = new import_mongoose.Schema(
91
53
  type: String,
92
54
  maxlength: 20
93
55
  },
94
- session: {
95
- type: SessionSchema,
96
- required: false
97
- },
98
56
  customerId: {
99
57
  type: String,
100
58
  required: false
@@ -107,15 +65,27 @@ const userSchema = new import_mongoose.Schema(
107
65
  }
108
66
  },
109
67
  required: false
110
- },
111
- provider: {
112
- type: [ProviderSchema],
113
- default: void 0,
114
- required: false
115
68
  }
116
69
  },
117
70
  {
118
- timestamps: true
71
+ timestamps: true,
72
+ toJSON: {
73
+ virtuals: true,
74
+ // keep the automatic `id` getter
75
+ versionKey: false,
76
+ // drop __v
77
+ transform(doc, ret) {
78
+ ret.id = ret._id.toString();
79
+ delete ret._id;
80
+ }
81
+ },
82
+ toObject: {
83
+ virtuals: true,
84
+ transform(doc, ret) {
85
+ ret.id = ret._id.toString();
86
+ delete ret._id;
87
+ }
88
+ }
119
89
  }
120
90
  );
121
91
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import type { User } from '@/types/user.types';\nimport {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\n\nconst SessionSchema = new Schema(\n {\n sessionToken: {\n type: String,\n required: true,\n },\n expires: {\n type: Date,\n required: true,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nconst ProviderSchema = new Schema(\n {\n provider: {\n type: String,\n required: true,\n },\n providerAccountId: {\n type: String,\n },\n secret: {\n type: String,\n maxlength: 1024,\n minlength: 6,\n },\n emailValidated: {\n type: String,\n },\n passwordHash: {\n type: String,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nexport const userSchema = new Schema<User>(\n {\n email: {\n type: String,\n required: true,\n unique: true,\n validate: [validator.isEmail, 'Please fill a valid email address'],\n lowercase: true,\n trim: true,\n },\n name: {\n type: String,\n maxlength: NAMES_MAX_LENGTH,\n minlength: NAMES_MIN_LENGTH,\n },\n phone: {\n type: String,\n maxlength: 20,\n },\n session: {\n type: SessionSchema,\n required: false,\n },\n\n customerId: {\n type: String,\n required: false,\n },\n\n emailsList: {\n type: {\n newsLetter: {\n type: Boolean,\n default: false,\n },\n },\n required: false,\n },\n\n provider: {\n type: [ProviderSchema],\n default: undefined,\n required: false,\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAGO;AACP,sBAAuB;AACvB,uBAAsB;AAEtB,MAAM,gBAAgB,IAAI;AAAA,EACxB;AAAA,IACE,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,EAAE,KAAK,MAAM;AAAA;AACf;AAEA,MAAM,iBAAiB,IAAI;AAAA,EACzB;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AAAA,MACjB,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,gBAAgB;AAAA,MACd,MAAM;AAAA,IACR;AAAA,IACA,cAAc;AAAA,MACZ,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,EAAE,KAAK,MAAM;AAAA;AACf;AAEO,MAAM,aAAa,IAAI;AAAA,EAC5B;AAAA,IACE,OAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,UAAU,CAAC,iBAAAA,QAAU,SAAS,mCAAmC;AAAA,MACjE,WAAW;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,IACb;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,YAAY;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,YAAY;AAAA,MACV,MAAM;AAAA,QACJ,YAAY;AAAA,UACV,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU;AAAA,IACZ;AAAA,IAEA,UAAU;AAAA,MACR,MAAM,CAAC,cAAc;AAAA,MACrB,SAAS;AAAA,MACT,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":["validator"]}
1
+ {"version":3,"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import type { UserSchema } from '@/types/user.types';\nimport {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\n\nexport const userSchema = new Schema<UserSchema>(\n {\n email: {\n type: String,\n required: true,\n unique: true,\n validate: [validator.isEmail, 'Please fill a valid email address'],\n lowercase: true,\n trim: true,\n },\n name: {\n type: String,\n maxlength: NAMES_MAX_LENGTH,\n minlength: NAMES_MIN_LENGTH,\n },\n phone: {\n type: String,\n maxlength: 20,\n },\n\n customerId: {\n type: String,\n required: false,\n },\n\n emailsList: {\n type: {\n newsLetter: {\n type: Boolean,\n default: false,\n },\n },\n required: false,\n },\n },\n {\n timestamps: true,\n\n toJSON: {\n virtuals: true, // keep the automatic `id` getter\n versionKey: false, // drop __v\n transform(doc, ret) {\n ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n toObject: {\n virtuals: true,\n transform(doc, ret) {\n ret.id = ret._id.toString(); // convert _id to id\n delete ret._id; // remove _id\n },\n },\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAGO;AACP,sBAAuB;AACvB,uBAAsB;AAEf,MAAM,aAAa,IAAI;AAAA,EAC5B;AAAA,IACE,OAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,UAAU,CAAC,iBAAAA,QAAU,SAAS,mCAAmC;AAAA,MACjE,WAAW;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,IACb;AAAA,IAEA,YAAY;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,YAAY;AAAA,MACV,MAAM;AAAA,QACJ,YAAY;AAAA,UACV,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,IAEZ,QAAQ;AAAA,MACN,UAAU;AAAA;AAAA,MACV,YAAY;AAAA;AAAA,MACZ,UAAU,KAAK,KAAK;AAClB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU,KAAK,KAAK;AAClB,YAAI,KAAK,IAAI,IAAI,SAAS;AAC1B,eAAO,IAAI;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":["validator"]}
@@ -76,7 +76,6 @@ const getDictionaryById = async (dictionaryId) => {
76
76
  }
77
77
  }
78
78
  ]);
79
- console.log("dictionaries", dictionaries);
80
79
  if (!dictionaries.length) {
81
80
  throw new import_errors.GenericError("DICTIONARY_NOT_FOUND", { dictionaryId });
82
81
  }
@@ -184,7 +183,9 @@ const getExistingDictionaryKey = async (dictionariesKeys, projectId) => {
184
183
  };
185
184
  const updateDictionaryById = async (dictionaryId, dictionary) => {
186
185
  const dictionaryObject = (0, import_ensureMongoDocumentToObject.ensureMongoDocumentToObject)(dictionary);
187
- const dictionaryToUpdate = (0, import_removeObjectKeys.removeObjectKeys)(dictionaryObject, ["_id"]);
186
+ const dictionaryToUpdate = (0, import_removeObjectKeys.removeObjectKeys)(dictionaryObject, [
187
+ "id"
188
+ ]);
188
189
  const updatedKeys = Object.keys(dictionaryToUpdate);
189
190
  const errors = await (0, import_validateDictionary.validateDictionary)(dictionaryToUpdate, updatedKeys);
190
191
  if (Object.keys(errors).length > 0) {
@@ -205,7 +206,9 @@ const updateDictionaryById = async (dictionaryId, dictionary) => {
205
206
  };
206
207
  const updateDictionaryByKey = async (dictionaryKey, dictionary, projectId) => {
207
208
  const dictionaryObject = (0, import_ensureMongoDocumentToObject.ensureMongoDocumentToObject)(dictionary);
208
- const dictionaryToUpdate = (0, import_removeObjectKeys.removeObjectKeys)(dictionaryObject, ["_id"]);
209
+ const dictionaryToUpdate = (0, import_removeObjectKeys.removeObjectKeys)(dictionaryObject, [
210
+ "id"
211
+ ]);
209
212
  const updatedKeys = Object.keys(dictionaryToUpdate);
210
213
  const errors = await (0, import_validateDictionary.validateDictionary)(dictionaryToUpdate, updatedKeys);
211
214
  if (Object.keys(errors).length > 0) {
@@ -226,9 +229,7 @@ const updateDictionaryByKey = async (dictionaryKey, dictionary, projectId) => {
226
229
  return updatedDictionary;
227
230
  };
228
231
  const deleteDictionaryById = async (dictionaryId) => {
229
- console.log("dictionaryId", dictionaryId);
230
232
  const dictionary = await import_dictionary.DictionaryModel.findByIdAndDelete(dictionaryId);
231
- console.log("dictionary", dictionary);
232
233
  if (!dictionary) {
233
234
  throw new import_errors.GenericError("DICTIONARY_NOT_FOUND", { dictionaryId });
234
235
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\nimport type { Project } from '@/types/project.types';\nimport { DictionaryModel } from '@models/dictionary.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n validateDictionary,\n type DictionaryFields,\n} from '@utils/validation/validateDictionary';\nimport { Types, type ObjectId } from 'mongoose';\n\n/**\n * Finds dictionaries based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> => {\n try {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the filters\n { $match: filters },\n\n // Stage 2: Skip for pagination\n { $skip: skip },\n\n // Stage 3: Limit the number of documents\n { $limit: limit },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n } catch (error) {\n console.error('Error fetching dictionaries:', error);\n throw error;\n }\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\n/**\n * Finds a dictionary by its ID and includes the 'availableVersions' field.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID with available versions.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const id = Types.ObjectId.isValid(dictionaryId as string)\n ? new Types.ObjectId(dictionaryId as string)\n : dictionaryId;\n\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by ID\n { $match: { _id: id } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n console.log('dictionaries', dictionaries);\n\n if (!dictionaries.length) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return new DictionaryModel(dictionaries[0]);\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaries = await getDictionariesByKeys([dictionaryKey], projectId);\n\n return dictionaries[0];\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n projectId: string | ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by key\n { $match: { key: { $in: dictionaryKeys }, projectIds: projectId } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKeys,\n projectId,\n });\n }\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\nexport const getDictionariesByTags = async (\n tags: string[],\n projectId: string | Project['_id']\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by tags\n {\n $match: {\n tags: { $in: tags },\n projectIds: projectId,\n },\n },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, ['_id']);\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n const updatedDictionary = await getDictionaryById(dictionaryId);\n\n return updatedDictionary;\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, ['_id']);\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n const updatedDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n return updatedDictionary;\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n console.log('dictionaryId', dictionaryId);\n\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n console.log('dictionary', dictionary);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n// Function to extract the numeric part of the version\nconst getVersionNumber = (version: string): number => {\n const match = version.match(/^v(\\d+)$/);\n if (!match) {\n throw new Error(`Invalid version format: ${version}`);\n }\n return parseInt(match[1], 10);\n};\n\nexport const incrementVersion = (dictionary: Dictionary): string => {\n const VERSION_PREFIX = 'v';\n\n const availableVersions = [...(dictionary.content.keys() ?? [])];\n const lastVersion = availableVersions[availableVersions.length - 1];\n\n // Start with the next version number\n let newNumber = getVersionNumber(lastVersion) + 1;\n let newVersion = `${VERSION_PREFIX}${newNumber}`;\n\n // Loop until a unique version is found\n while (availableVersions.includes(newVersion)) {\n newNumber += 1;\n newVersion = `${VERSION_PREFIX}${newNumber}`;\n }\n\n return newVersion;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,wBAAgC;AAChC,yCAA4C;AAC5C,oBAA6B;AAE7B,8BAAiC;AACjC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AE;AAAA,EACtD;AACA,SAAO,SAAS,MAAM,CAAC,GAAG,EAAE;AAC9B;AAEO,MAAM,mBAAmB,CAAC,eAAmC;AAClE,QAAM,iBAAiB;AAEvB,QAAM,oBAAoB,CAAC,GAAI,WAAW,QAAQ,KAAK,KAAK,CAAC,CAAE;AAC/D,QAAM,cAAc,kBAAkB,kBAAkB,SAAS,CAAC;AAGlE,MAAI,YAAY,iBAAiB,WAAW,IAAI;AAChD,MAAI,aAAa,GAAG,cAAc,GAAG,SAAS;AAG9C,SAAO,kBAAkB,SAAS,UAAU,GAAG;AAC7C,iBAAa;AACb,iBAAa,GAAG,cAAc,GAAG,SAAS;AAAA,EAC5C;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\nimport type { Project } from '@/types/project.types';\nimport { DictionaryModel } from '@models/dictionary.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n validateDictionary,\n type DictionaryFields,\n} from '@utils/validation/validateDictionary';\nimport { Types } from 'mongoose';\n\n/**\n * Finds dictionaries based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> => {\n try {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the filters\n { $match: filters },\n\n // Stage 2: Skip for pagination\n { $skip: skip },\n\n // Stage 3: Limit the number of documents\n { $limit: limit },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n } catch (error) {\n console.error('Error fetching dictionaries:', error);\n throw error;\n }\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\n/**\n * Finds a dictionary by its ID and includes the 'availableVersions' field.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID with available versions.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const id = Types.ObjectId.isValid(dictionaryId as string)\n ? new Types.ObjectId(dictionaryId as string)\n : dictionaryId;\n\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by ID\n { $match: { _id: id } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries.length) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return new DictionaryModel(dictionaries[0]);\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaries = await getDictionariesByKeys([dictionaryKey], projectId);\n\n return dictionaries[0];\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by key\n { $match: { key: { $in: dictionaryKeys }, projectIds: projectId } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKeys,\n projectId,\n });\n }\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | Types.ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\nexport const getDictionariesByTags = async (\n tags: string[],\n projectId: string | Project['id']\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by tags\n {\n $match: {\n tags: { $in: tags },\n projectIds: projectId,\n },\n },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n const formattedResults = dictionaries.map(\n (result) => new DictionaryModel(result)\n );\n\n return formattedResults;\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | Types.ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | Types.ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, [\n 'id',\n ]) as unknown as Partial<Dictionary>;\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n const updatedDictionary = await getDictionaryById(dictionaryId);\n\n return updatedDictionary;\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | Types.ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, [\n 'id',\n ]) as unknown as Partial<Dictionary>;\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n const updatedDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n return updatedDictionary;\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n// Function to extract the numeric part of the version\nconst getVersionNumber = (version: string): number => {\n const match = version.match(/^v(\\d+)$/);\n if (!match) {\n throw new Error(`Invalid version format: ${version}`);\n }\n return parseInt(match[1], 10);\n};\n\nexport const incrementVersion = (dictionary: Dictionary): string => {\n const VERSION_PREFIX = 'v';\n\n const availableVersions = [...(dictionary.content.keys() ?? [])];\n const lastVersion = availableVersions[availableVersions.length - 1];\n\n // Start with the next version number\n let newNumber = getVersionNumber(lastVersion) + 1;\n let newVersion = `${VERSION_PREFIX}${newNumber}`;\n\n // Loop until a unique version is found\n while (availableVersions.includes(newVersion)) {\n newNumber += 1;\n newVersion = `${VERSION_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E;AAEA,SAAO;AACT;AAGA,MAAM,mBAAmB,CAAC,YAA4B;AACpD,QAAM,QAAQ,QAAQ,MAAM,UAAU;AACtC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,2BAA2B,OAAO,EAAE;AAAA,EACtD;AACA,SAAO,SAAS,MAAM,CAAC,GAAG,EAAE;AAC9B;AAEO,MAAM,mBAAmB,CAAC,eAAmC;AAClE,QAAM,iBAAiB;AAEvB,QAAM,oBAAoB,CAAC,GAAI,WAAW,QAAQ,KAAK,KAAK,CAAC,CAAE;AAC/D,QAAM,cAAc,kBAAkB,kBAAkB,SAAS,CAAC;AAGlE,MAAI,YAAY,iBAAiB,WAAW,IAAI;AAChD,MAAI,aAAa,GAAG,cAAc,GAAG,SAAS;AAG9C,SAAO,kBAAkB,SAAS,UAAU,GAAG;AAC7C,iBAAa;AACb,iBAAa,GAAG,cAAc,GAAG,SAAS;AAAA,EAC5C;AAEA,SAAO;AACT;","names":[]}
@@ -23,6 +23,7 @@ __export(email_service_exports, {
23
23
  module.exports = __toCommonJS(email_service_exports);
24
24
  var import_jsx_runtime = require("react/jsx-runtime");
25
25
  var import_InviteUserEmail = require('./../emails/InviteUserEmail.cjs');
26
+ var import_OAuthTokenCreatedEmail = require('./../emails/OAuthTokenCreatedEmail.cjs');
26
27
  var import_PasswordChangeConfirmation = require('./../emails/PasswordChangeConfirmation.cjs');
27
28
  var import_ResetUserPassword = require('./../emails/ResetUserPassword.cjs');
28
29
  var import_SubscriptionPaymentCancellation = require('./../emails/SubscriptionPaymentCancellation.cjs');
@@ -159,6 +160,18 @@ const getEmailComponents = (locale) => ({
159
160
  fr: "Un probl\xE8me est survenu avec votre paiement pour l'abonnement Intlayer",
160
161
  es: "Hubo un problema con el pago de tu suscripci\xF3n de Intlayer"
161
162
  })
163
+ },
164
+ oAuthTokenCreated: {
165
+ template: (0, import_express_intlayer.t)({
166
+ en: import_OAuthTokenCreatedEmail.OAuthTokenCreatedEmailEN,
167
+ fr: import_OAuthTokenCreatedEmail.OAuthTokenCreatedEmailFR,
168
+ es: import_OAuthTokenCreatedEmail.OAuthTokenCreatedEmailES
169
+ }),
170
+ subject: (0, import_express_intlayer.t)({
171
+ en: "A third-party OAuth application has been added to your Intlayer account",
172
+ fr: "Une application OAuth tierce a \xE9t\xE9 ajout\xE9e \xE0 votre compte Intlayer",
173
+ es: "Una aplicaci\xF3n OAuth de terceros ha sido a\xF1adida a tu cuenta de Intlayer"
174
+ })
162
175
  }
163
176
  });
164
177
  const sendEmail = async ({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["import {\n InviteUserEmailEN,\n InviteUserEmailFR,\n InviteUserEmailES,\n} from '@emails/InviteUserEmail';\nimport {\n PasswordChangeConfirmationEmailEN,\n PasswordChangeConfirmationEmailFR,\n PasswordChangeConfirmationEmailES,\n} from '@emails/PasswordChangeConfirmation';\nimport {\n ResetPasswordEmailEN,\n ResetPasswordEmailFR,\n ResetPasswordEmailES,\n} from '@emails/ResetUserPassword';\n\nimport {\n SubscriptionPaymentCancellationEN,\n SubscriptionPaymentCancellationFR,\n SubscriptionPaymentCancellationES,\n} from '@emails/SubscriptionPaymentCancellation';\nimport {\n SubscriptionPaymentErrorEN,\n SubscriptionPaymentErrorFR,\n SubscriptionPaymentErrorES,\n} from '@emails/SubscriptionPaymentError';\nimport {\n SubscriptionPaymentSuccessEN,\n SubscriptionPaymentSuccessFR,\n SubscriptionPaymentSuccessES,\n} from '@emails/SubscriptionPaymentSuccess';\nimport {\n ValidateUserEmailEN,\n ValidateUserEmailFR,\n ValidateUserEmailES,\n} from '@emails/ValidateUserEmail';\nimport {\n WelcomeEmailEN,\n WelcomeEmailFR,\n WelcomeEmailES,\n} from '@emails/Welcome';\n\nimport { logger } from '@logger';\nimport { t } from 'express-intlayer';\nimport type { Locales } from 'intlayer';\nimport type { ComponentProps, JSX } from 'react';\nimport { Resend } from 'resend';\n\ntype EmailComponentsType = (...props: any) => JSX.Element;\ntype EmailComponents = {\n [key: string]: {\n template: EmailComponentsType;\n subject: string;\n };\n};\n\nconst getEmailComponents = (locale?: Locales) =>\n ({\n invite: {\n template: t(\n {\n en: InviteUserEmailEN,\n fr: InviteUserEmailFR,\n es: InviteUserEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'You have been invited to join Intlayer',\n fr: 'Vous êtes invité à rejoindre Intlayer',\n es: 'Has sido invitado a unirte a Intlayer',\n },\n locale\n ),\n },\n validate: {\n template: t(\n {\n en: ValidateUserEmailEN,\n fr: ValidateUserEmailFR,\n es: ValidateUserEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Validate your email for Intlayer',\n fr: 'Validez votre email pour Intlayer',\n es: 'Valida tu correo electrónico para Intlayer',\n },\n locale\n ),\n },\n resetPassword: {\n template: t(\n {\n en: ResetPasswordEmailEN,\n fr: ResetPasswordEmailFR,\n es: ResetPasswordEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Reset your password for Intlayer',\n fr: 'Réinitialisez votre mot de passe pour Intlayer',\n es: 'Restablece tu contraseña para Intlayer',\n },\n locale\n ),\n },\n welcome: {\n template: t(\n {\n en: WelcomeEmailEN,\n fr: WelcomeEmailFR,\n es: WelcomeEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Welcome to Intlayer!',\n fr: 'Bienvenue chez Intlayer!',\n es: '¡Bienvenido a Intlayer!',\n },\n locale\n ),\n },\n passwordChangeConfirmation: {\n template: t(\n {\n en: PasswordChangeConfirmationEmailEN,\n fr: PasswordChangeConfirmationEmailFR,\n es: PasswordChangeConfirmationEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Your Intlayer password has been changed',\n fr: 'Votre mot de passe Intlayer a été modifié',\n es: 'Tu contraseña de Intlayer ha sido cambiada',\n },\n locale\n ),\n },\n subscriptionPaymentSuccess: {\n template: t({\n en: SubscriptionPaymentSuccessEN,\n fr: SubscriptionPaymentSuccessFR,\n es: SubscriptionPaymentSuccessES,\n }),\n subject: t({\n en: 'Your payment for Intlayer subscription is confirmed',\n fr: \"Votre paiement pour l'abonnement Intlayer est confirmé\",\n es: 'Tu pago por la suscripción de Intlayer ha sido confirmado',\n }),\n },\n subscriptionPaymentCancellation: {\n template: t({\n en: SubscriptionPaymentCancellationEN,\n fr: SubscriptionPaymentCancellationFR,\n es: SubscriptionPaymentCancellationES,\n }),\n subject: t({\n en: 'Your Intlayer subscription has been canceled',\n fr: 'Votre abonnement Intlayer a été annulé',\n es: 'Tu suscripción de Intlayer ha sido cancelada',\n }),\n },\n subscriptionPaymentError: {\n template: t({\n en: SubscriptionPaymentErrorEN,\n fr: SubscriptionPaymentErrorFR,\n es: SubscriptionPaymentErrorES,\n }),\n subject: t({\n en: 'There was an issue with your Intlayer subscription payment',\n fr: \"Un problème est survenu avec votre paiement pour l'abonnement Intlayer\",\n es: 'Hubo un problema con el pago de tu suscripción de Intlayer',\n }),\n },\n }) satisfies EmailComponents;\n\ntype EmailType = keyof ReturnType<typeof getEmailComponents>;\n\nexport type SendEmailProps<T extends EmailType> = {\n type: T;\n to: string;\n subject?: string;\n locale?: Locales;\n} & ComponentProps<ReturnType<typeof getEmailComponents>[T]['template']>;\n\nexport const sendEmail = async <T extends EmailType>({\n type,\n to,\n subject,\n locale,\n ...props\n}: SendEmailProps<T>) => {\n const resend = new Resend(process.env.RESEND_API_KEY);\n\n const emailComponents = getEmailComponents(locale);\n\n const { template, subject: baseSubject } = emailComponents[type];\n\n type EmailComponentType = (typeof emailComponents)[T]['template'];\n\n const EmailComponent: EmailComponentType = template;\n\n const react = <EmailComponent {...(props as any)} />;\n\n await resend.emails\n .send({\n from: 'Intlayer <no-reply@intlayer.org>',\n to,\n subject: subject ?? baseSubject,\n react,\n })\n .catch((err) => logger.error(err));\n\n logger.info(`Email sent ${type} to ${to}`);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoNgB;AApNhB,6BAIO;AACP,wCAIO;AACP,+BAIO;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S,WAAW;AAAA,IACpB;AAAA,EACF,CAAC,EACA,MAAM,CAAC,QAAQ,qBAAO,MAAM,GAAG,CAAC;AAEnC,uBAAO,KAAK,cAAc,IAAI,OAAO,EAAE,EAAE;AAC3C;","names":[]}
1
+ {"version":3,"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["import {\n InviteUserEmailEN,\n InviteUserEmailES,\n InviteUserEmailFR,\n} from '@emails/InviteUserEmail';\nimport {\n OAuthTokenCreatedEmailEN,\n OAuthTokenCreatedEmailES,\n OAuthTokenCreatedEmailFR,\n} from '@emails/OAuthTokenCreatedEmail';\nimport {\n PasswordChangeConfirmationEmailEN,\n PasswordChangeConfirmationEmailES,\n PasswordChangeConfirmationEmailFR,\n} from '@emails/PasswordChangeConfirmation';\nimport {\n ResetPasswordEmailEN,\n ResetPasswordEmailES,\n ResetPasswordEmailFR,\n} from '@emails/ResetUserPassword';\n\nimport {\n SubscriptionPaymentCancellationEN,\n SubscriptionPaymentCancellationES,\n SubscriptionPaymentCancellationFR,\n} from '@emails/SubscriptionPaymentCancellation';\nimport {\n SubscriptionPaymentErrorEN,\n SubscriptionPaymentErrorES,\n SubscriptionPaymentErrorFR,\n} from '@emails/SubscriptionPaymentError';\nimport {\n SubscriptionPaymentSuccessEN,\n SubscriptionPaymentSuccessES,\n SubscriptionPaymentSuccessFR,\n} from '@emails/SubscriptionPaymentSuccess';\nimport {\n ValidateUserEmailEN,\n ValidateUserEmailES,\n ValidateUserEmailFR,\n} from '@emails/ValidateUserEmail';\nimport {\n WelcomeEmailEN,\n WelcomeEmailES,\n WelcomeEmailFR,\n} from '@emails/Welcome';\n\nimport { logger } from '@logger';\nimport { t } from 'express-intlayer';\nimport type { Locales } from 'intlayer';\nimport type { ComponentProps, JSX } from 'react';\nimport { Resend } from 'resend';\n\ntype EmailComponentsType = (...props: any) => JSX.Element;\ntype EmailComponents = {\n [key: string]: {\n template: EmailComponentsType;\n subject: string;\n };\n};\n\nconst getEmailComponents = (locale?: Locales) =>\n ({\n invite: {\n template: t(\n {\n en: InviteUserEmailEN,\n fr: InviteUserEmailFR,\n es: InviteUserEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'You have been invited to join Intlayer',\n fr: 'Vous êtes invité à rejoindre Intlayer',\n es: 'Has sido invitado a unirte a Intlayer',\n },\n locale\n ),\n },\n validate: {\n template: t(\n {\n en: ValidateUserEmailEN,\n fr: ValidateUserEmailFR,\n es: ValidateUserEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Validate your email for Intlayer',\n fr: 'Validez votre email pour Intlayer',\n es: 'Valida tu correo electrónico para Intlayer',\n },\n locale\n ),\n },\n resetPassword: {\n template: t(\n {\n en: ResetPasswordEmailEN,\n fr: ResetPasswordEmailFR,\n es: ResetPasswordEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Reset your password for Intlayer',\n fr: 'Réinitialisez votre mot de passe pour Intlayer',\n es: 'Restablece tu contraseña para Intlayer',\n },\n locale\n ),\n },\n welcome: {\n template: t(\n {\n en: WelcomeEmailEN,\n fr: WelcomeEmailFR,\n es: WelcomeEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Welcome to Intlayer!',\n fr: 'Bienvenue chez Intlayer!',\n es: '¡Bienvenido a Intlayer!',\n },\n locale\n ),\n },\n passwordChangeConfirmation: {\n template: t(\n {\n en: PasswordChangeConfirmationEmailEN,\n fr: PasswordChangeConfirmationEmailFR,\n es: PasswordChangeConfirmationEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Your Intlayer password has been changed',\n fr: 'Votre mot de passe Intlayer a été modifié',\n es: 'Tu contraseña de Intlayer ha sido cambiada',\n },\n locale\n ),\n },\n subscriptionPaymentSuccess: {\n template: t({\n en: SubscriptionPaymentSuccessEN,\n fr: SubscriptionPaymentSuccessFR,\n es: SubscriptionPaymentSuccessES,\n }),\n subject: t({\n en: 'Your payment for Intlayer subscription is confirmed',\n fr: \"Votre paiement pour l'abonnement Intlayer est confirmé\",\n es: 'Tu pago por la suscripción de Intlayer ha sido confirmado',\n }),\n },\n subscriptionPaymentCancellation: {\n template: t({\n en: SubscriptionPaymentCancellationEN,\n fr: SubscriptionPaymentCancellationFR,\n es: SubscriptionPaymentCancellationES,\n }),\n subject: t({\n en: 'Your Intlayer subscription has been canceled',\n fr: 'Votre abonnement Intlayer a été annulé',\n es: 'Tu suscripción de Intlayer ha sido cancelada',\n }),\n },\n subscriptionPaymentError: {\n template: t({\n en: SubscriptionPaymentErrorEN,\n fr: SubscriptionPaymentErrorFR,\n es: SubscriptionPaymentErrorES,\n }),\n subject: t({\n en: 'There was an issue with your Intlayer subscription payment',\n fr: \"Un problème est survenu avec votre paiement pour l'abonnement Intlayer\",\n es: 'Hubo un problema con el pago de tu suscripción de Intlayer',\n }),\n },\n oAuthTokenCreated: {\n template: t({\n en: OAuthTokenCreatedEmailEN,\n fr: OAuthTokenCreatedEmailFR,\n es: OAuthTokenCreatedEmailES,\n }),\n subject: t({\n en: 'A third-party OAuth application has been added to your Intlayer account',\n fr: 'Une application OAuth tierce a été ajoutée à votre compte Intlayer',\n es: 'Una aplicación OAuth de terceros ha sido añadida a tu cuenta de Intlayer',\n }),\n },\n }) satisfies EmailComponents;\n\ntype EmailType = keyof ReturnType<typeof getEmailComponents>;\n\nexport type SendEmailProps<T extends EmailType> = {\n type: T;\n to: string;\n subject?: string;\n locale?: Locales;\n} & ComponentProps<ReturnType<typeof getEmailComponents>[T]['template']>;\n\nexport const sendEmail = async <T extends EmailType>({\n type,\n to,\n subject,\n locale,\n ...props\n}: SendEmailProps<T>) => {\n const resend = new Resend(process.env.RESEND_API_KEY);\n\n const emailComponents = getEmailComponents(locale);\n\n const { template, subject: baseSubject } = emailComponents[type];\n\n type EmailComponentType = (typeof emailComponents)[T]['template'];\n\n const EmailComponent: EmailComponentType = template;\n\n const react = <EmailComponent {...(props as any)} />;\n\n await resend.emails\n .send({\n from: 'Intlayer <no-reply@intlayer.org>',\n to,\n subject: subject ?? baseSubject,\n react,\n })\n .catch((err) => logger.error(err));\n\n logger.info(`Email sent ${type} to ${to}`);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqOgB;AArOhB,6BAIO;AACP,oCAIO;AACP,wCAIO;AACP,+BAIO;AAEP,6CAIO;AACP,sCAIO;AACP,wCAIO;AACP,+BAIO;AACP,qBAIO;AAEP,oBAAuB;AACvB,8BAAkB;AAGlB,oBAAuB;AAUvB,MAAM,qBAAqB,CAAC,YACzB;AAAA,EACC,QAAQ;AAAA,IACN,cAAU;AAAA,MACR;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,IACA,aAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,cAAU;AAAA,MACR;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,IACA,aAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA,eAAe;AAAA,IACb,cAAU;AAAA,MACR;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,IACA,aAAS;AAAA,MACP;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA,SAAS;AAAA,IACP,cAAU;AAAA,MACR;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,IACA,aAAS;AAAA,MACP;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;AACF;AAWK,MAAM,YAAY,OAA4B;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyB;AACvB,QAAM,SAAS,IAAI,qBAAO,QAAQ,IAAI,cAAc;AAEpD,QAAM,kBAAkB,mBAAmB,MAAM;AAEjD,QAAM,EAAE,UAAU,SAAS,YAAY,IAAI,gBAAgB,IAAI;AAI/D,QAAM,iBAAqC;AAE3C,QAAM,QAAQ,4CAAC,kBAAgB,GAAI,OAAe;AAElD,QAAM,OAAO,OACV,KAAK;AAAA,IACJ,MAAM;AAAA,IACN;AAAA,IACA,SAAS,WAAW;AAAA,IACpB;AAAA,EACF,CAAC,EACA,MAAM,CAAC,QAAQ,qBAAO,MAAM,GAAG,CAAC;AAEnC,uBAAO,KAAK,cAAc,IAAI,OAAO,EAAE,EAAE;AAC3C;","names":[]}
@@ -24,19 +24,22 @@ __export(oAuth2_service_exports, {
24
24
  getAccessToken: () => getAccessToken,
25
25
  getClient: () => getClient,
26
26
  getClientAndProjectByClientId: () => getClientAndProjectByClientId,
27
+ getOAuth2AccessTokenContext: () => getOAuth2AccessTokenContext,
27
28
  getUserFromClient: () => getUserFromClient,
28
29
  saveToken: () => saveToken,
30
+ validateOAuth2AccessToken: () => validateOAuth2AccessToken,
29
31
  verifyScope: () => verifyScope
30
32
  });
31
33
  module.exports = __toCommonJS(oAuth2_service_exports);
32
- var import_crypto = require("crypto");
33
34
  var import_oAuth2 = require('./../models/oAuth2.model.cjs');
34
35
  var import_project = require('./../models/project.model.cjs');
36
+ var import_ensureMongoDocumentToObject = require('./../utils/ensureMongoDocumentToObject.cjs');
35
37
  var import_errors = require('./../utils/errors/index.cjs');
36
38
  var import_organization = require('./../utils/mapper/organization.cjs');
37
39
  var import_project2 = require('./../utils/mapper/project.cjs');
38
40
  var import_user = require('./../utils/mapper/user.cjs');
39
41
  var import_oAuth22 = require('./../utils/oAuth2.cjs');
42
+ var import_crypto = require("crypto");
40
43
  var import_organization2 = require('./organization.service.cjs');
41
44
  var import_user2 = require('./user.service.cjs');
42
45
  const generateClientCredentials = () => {
@@ -66,7 +69,7 @@ const getClientAndProjectByClientId = async (clientId) => {
66
69
  return {
67
70
  client: formattedClient,
68
71
  oAuth2Access,
69
- rights: oAuth2Access.rights,
72
+ grants: oAuth2Access.grants,
70
73
  project
71
74
  };
72
75
  };
@@ -81,25 +84,26 @@ const getClient = async (clientId, clientSecret) => {
81
84
  }
82
85
  return client;
83
86
  };
84
- const formatOAuth2Token = (token, client, user, project, organization, rights) => {
87
+ const formatOAuth2Token = (token, client, user, project, organization, grants) => {
85
88
  const { clientId, userId, ...restToken } = token;
86
- if (String(userId) !== String(user._id)) {
89
+ if (String(userId) !== String(user.id)) {
87
90
  throw new import_errors.GenericError("USER_ID_MISMATCH");
88
91
  }
89
92
  const formattedToken = {
90
93
  ...restToken,
91
94
  client,
92
95
  user: (0, import_user.mapUserToAPI)(user),
93
- organization: (0, import_organization.mapOrganizationToAPI)(organization, false),
94
- project: (0, import_project2.mapProjectToAPI)(project, user, false),
96
+ organization: (0, import_organization.mapOrganizationToAPI)(organization),
97
+ project: (0, import_project2.mapProjectToAPI)(project),
95
98
  accessToken: token.accessToken,
96
99
  accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99"),
97
- rights
100
+ grants
98
101
  };
99
102
  return formattedToken;
100
103
  };
101
104
  const formatDBToken = (token, clientId, userId) => {
102
105
  const formattedToken = {
106
+ id: token.id,
103
107
  clientId,
104
108
  userId,
105
109
  accessToken: token.accessToken,
@@ -108,7 +112,7 @@ const formatDBToken = (token, clientId, userId) => {
108
112
  return formattedToken;
109
113
  };
110
114
  const saveToken = async (token, client, user) => {
111
- const formattedAccessToken = formatDBToken(token, client.id, user._id);
115
+ const formattedAccessToken = formatDBToken(token, client.id, user.id);
112
116
  const result = await import_oAuth2.OAuth2AccessTokenModel.create(formattedAccessToken);
113
117
  if (!result) {
114
118
  return false;
@@ -148,7 +152,7 @@ const getAccessToken = async (accessToken) => {
148
152
  if (!result) {
149
153
  return false;
150
154
  }
151
- const { client, project, rights } = result;
155
+ const { client, project, grants } = result;
152
156
  const organization = await (0, import_organization2.getOrganizationById)(project.organizationId);
153
157
  if (!organization) {
154
158
  return false;
@@ -159,7 +163,7 @@ const getAccessToken = async (accessToken) => {
159
163
  user,
160
164
  project,
161
165
  organization,
162
- rights
166
+ grants
163
167
  );
164
168
  return formattedAccessToken;
165
169
  };
@@ -178,6 +182,39 @@ const getUserFromClient = async (client) => {
178
182
  const verifyScope = async (_token, _scope, _callback) => {
179
183
  return true;
180
184
  };
185
+ const validateOAuth2AccessToken = async (accessToken) => {
186
+ try {
187
+ const token = await import_oAuth2.OAuth2AccessTokenModel.findOne({
188
+ accessToken
189
+ });
190
+ if (!token) {
191
+ throw new import_errors.GenericError("INVALID_ACCESS_TOKEN");
192
+ }
193
+ if (/* @__PURE__ */ new Date() > new Date(token.expiresIn)) {
194
+ throw new import_errors.GenericError("EXPIRED_ACCESS_TOKEN");
195
+ }
196
+ return (0, import_ensureMongoDocumentToObject.ensureMongoDocumentToObject)(token);
197
+ } catch (error) {
198
+ throw new import_errors.GenericError("INVALID_ACCESS_TOKEN");
199
+ }
200
+ };
201
+ const getOAuth2AccessTokenContext = async (token) => {
202
+ const { userId, clientId } = token;
203
+ const user = await (0, import_user2.getUserById)(String(userId));
204
+ const result = await getClientAndProjectByClientId(clientId);
205
+ if (!result) {
206
+ throw new import_errors.GenericError("INVALID_ACCESS_TOKEN");
207
+ }
208
+ const { project, grants } = result;
209
+ let organization = await (0, import_organization2.getOrganizationById)(project.organizationId);
210
+ return {
211
+ accessToken: token.accessToken,
212
+ user: user ? (0, import_user.mapUserToAPI)(user) : void 0,
213
+ project: project ? (0, import_project2.mapProjectToAPI)(project) : void 0,
214
+ organization: organization ? (0, import_organization.mapOrganizationToAPI)(organization) : void 0,
215
+ grants
216
+ };
217
+ };
181
218
  // Annotate the CommonJS export names for ESM import in node:
182
219
  0 && (module.exports = {
183
220
  formatDBToken,
@@ -186,8 +223,10 @@ const verifyScope = async (_token, _scope, _callback) => {
186
223
  getAccessToken,
187
224
  getClient,
188
225
  getClientAndProjectByClientId,
226
+ getOAuth2AccessTokenContext,
189
227
  getUserFromClient,
190
228
  saveToken,
229
+ validateOAuth2AccessToken,
191
230
  verifyScope
192
231
  });
193
232
  //# sourceMappingURL=oAuth2.service.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/oAuth2.service.ts"],"sourcesContent":["import { randomBytes } from 'crypto';\nimport { OAuth2AccessTokenModel } from '@models/oAuth2.model';\nimport { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport { mapOrganizationToAPI } from '@utils/mapper/organization';\nimport { mapProjectToAPI } from '@utils/mapper/project';\nimport { mapUserToAPI } from '@utils/mapper/user';\nimport { getTokenExpireAt } from '@utils/oAuth2';\nimport type { Client, Callback } from 'oauth2-server';\nimport type { Token } from '../schemas/oAuth2.schema';\nimport { getOrganizationById } from './organization.service';\nimport { getUserById } from './user.service';\nimport type { OAuth2Token } from '@/types/oAuth2.types';\nimport type { Organization } from '@/types/organization.types';\nimport type {\n OAuth2Access,\n Project,\n ProjectDocument,\n} from '@/types/project.types';\nimport type { User, UserDocument } from '@/types/user.types';\n\n/**\n * Function to generate client credentials\n *\n * @returns The client id and client secret\n */\nexport const generateClientCredentials = (): {\n clientId: string;\n clientSecret: string;\n} => {\n const clientId = randomBytes(16).toString('hex'); // Generate a 16 character hexadecimal string\n const clientSecret = randomBytes(32).toString('hex'); // Generate a 32 character hexadecimal string\n\n return { clientId, clientSecret };\n};\n\n/**\n * Method to get the client and the project\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The an object containing the client, the rights and the project or false if not found\n */\nexport const getClientAndProjectByClientId = async (\n clientId: string\n): Promise<\n | {\n client: Client;\n oAuth2Access: OAuth2Access;\n project: ProjectDocument;\n rights: Token['rights'];\n }\n | false\n> => {\n const project = await ProjectModel.findOne({\n 'oAuth2Access.clientId': clientId,\n });\n\n if (!project) {\n return false;\n }\n\n const oAuth2Access = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!oAuth2Access) {\n return false;\n }\n\n const formattedClient: Client = {\n id: oAuth2Access.clientId,\n clientId,\n clientSecret: oAuth2Access.clientSecret,\n grants: ['client_credentials'],\n };\n\n return {\n client: formattedClient,\n oAuth2Access,\n rights: oAuth2Access.rights,\n project,\n };\n};\n\n/**\n * Get the client and verify that the client secret is correct\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The client or false if not found\n */\nexport const getClient = async (\n clientId: string,\n clientSecret: string\n): Promise<Client | false> => {\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client } = result;\n\n if (!client || client.clientSecret !== clientSecret) {\n return false;\n }\n\n return client;\n};\n\n/**\n * Format an OAuth2Token\n *\n * @param token\n * @param client\n * @param user\n * @param project\n * @param organization\n * @returns\n */\nexport const formatOAuth2Token = (\n token: Token,\n client: Client,\n user: User,\n project: Project,\n organization: Organization,\n rights: Token['rights']\n): OAuth2Token => {\n const { clientId, userId, ...restToken } = token;\n\n if (String(userId) !== String(user._id)) {\n throw new GenericError('USER_ID_MISMATCH');\n }\n\n const formattedToken: OAuth2Token = {\n ...restToken,\n client,\n user: mapUserToAPI(user),\n organization: mapOrganizationToAPI(organization, false),\n project: mapProjectToAPI(project, user, false),\n accessToken: token.accessToken,\n accessTokenExpiresAt: token.accessTokenExpiresAt ?? new Date('999-99-99'),\n rights,\n };\n\n return formattedToken;\n};\n\n/**\n * Format a auth token for the database\n *\n * @param token - The oAuth2 token to format\n * @param clientId - The client ID\n * @param userId - The user ID\n * @returns\n */\nexport const formatDBToken = (\n token: OAuth2Token,\n clientId: Client['id'],\n userId: User['_id']\n): Token => {\n const formattedToken: Token = {\n clientId: clientId,\n userId: userId,\n accessToken: token.accessToken,\n expiresIn: token.accessTokenExpiresAt ?? getTokenExpireAt(),\n };\n\n return formattedToken;\n};\n\n/**\n * Method to save the token\n *\n * @param token - The token\n * @param client - The client\n * @param user - The user\n * @returns The saved token or false if not saved\n */\nexport const saveToken = async (\n token: OAuth2Token,\n client: Client,\n user: User\n): Promise<OAuth2Token | false> => {\n const formattedAccessToken: Token = formatDBToken(token, client.id, user._id);\n\n const result = await OAuth2AccessTokenModel.create(formattedAccessToken);\n\n if (!result) {\n return false;\n }\n\n const result2 = await getClientAndProjectByClientId(result.clientId);\n\n if (!result2) {\n return false;\n }\n\n const { project } = result2;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedResult = formatOAuth2Token(\n formattedAccessToken,\n client,\n user,\n project,\n organization,\n token.rights\n );\n return formattedResult;\n};\n\n/**\n * Method to get the access token\n *\n * @param accessToken - The access token\n * @returns The access token or false if not found\n */\nexport const getAccessToken = async (\n accessToken: string\n): Promise<OAuth2Token | false> => {\n const token = await OAuth2AccessTokenModel.findOne({\n accessToken,\n });\n\n if (!token) {\n return false;\n }\n\n const { userId, clientId } = token;\n\n const user = await getUserById(userId);\n\n if (!user) {\n return false;\n }\n\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client, project, rights } = result;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedAccessToken = formatOAuth2Token(\n token,\n client,\n user,\n project,\n organization,\n rights\n );\n\n return formattedAccessToken;\n};\n\n/**\n * Method to get the user from the client\n *\n * @param client - The client\n * @returns The user or false if not found\n */\nexport const getUserFromClient = async (\n client: Client\n): Promise<UserDocument | false> => {\n const response = await getClientAndProjectByClientId(client.id);\n\n if (!response) {\n return false;\n }\n\n const { userId } = response.oAuth2Access;\n\n if (!userId) {\n return false;\n }\n\n const user = await getUserById(userId);\n\n return user ?? false;\n};\n\n/**\n * Method to verify the permissions (grants)\n *\n * @param token - The token\n * @param scope - The scope\n * @returns True if the token has the required scope, false otherwise\n */\nexport const verifyScope = async (\n _token: OAuth2Token,\n _scope: string,\n _callback?: Callback<boolean> | undefined\n): Promise<boolean> => {\n // Implement the verification of scopes if necessary\n return true;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4B;AAC5B,oBAAuC;AACvC,qBAA6B;AAC7B,oBAA6B;AAC7B,0BAAqC;AACrC,IAAAA,kBAAgC;AAChC,kBAA6B;AAC7B,IAAAC,iBAAiC;AAGjC,IAAAC,uBAAoC;AACpC,IAAAC,eAA4B;AAerB,MAAM,4BAA4B,MAGpC;AACH,QAAM,eAAW,2BAAY,EAAE,EAAE,SAAS,KAAK;AAC/C,QAAM,mBAAe,2BAAY,EAAE,EAAE,SAAS,KAAK;AAEnD,SAAO,EAAE,UAAU,aAAa;AAClC;AASO,MAAM,gCAAgC,OAC3C,aASG;AACH,QAAM,UAAU,MAAM,4BAAa,QAAQ;AAAA,IACzC,yBAAyB;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,QAAQ,aAAa;AAAA,IACxC,CAAC,WAAW,OAAO,aAAa;AAAA,EAClC;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,kBAA0B;AAAA,IAC9B,IAAI,aAAa;AAAA,IACjB;AAAA,IACA,cAAc,aAAa;AAAA,IAC3B,QAAQ,CAAC,oBAAoB;AAAA,EAC/B;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,QAAQ,aAAa;AAAA,IACrB;AAAA,EACF;AACF;AASO,MAAM,YAAY,OACvB,UACA,iBAC4B;AAC5B,QAAM,SAAS,MAAM,8BAA8B,QAAQ;AAE3D,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,OAAO,IAAI;AAEnB,MAA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;AAAA,IACA,MAAM;AAAA,EACR;AACA,SAAO;AACT;AAQO,MAAM,iBAAiB,OAC5B,gBACiC;AACjC,QAAM,QAAQ,MAAM,qCAAuB,QAAQ;AAAA,IACjD;AAAA,EACF,CAAC;AAED,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,QAAQ,SAAS,IAAI;AAE7B,QAAM,OAAO,UAAM,0BAAY,MAAM;AAErC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,8BAA8B,QAAQ;AAE3D,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,QAAQ,SAAS,OAAO,IAAI;AAEpC,QAAM,eAAe,UAAM,0CAAoB,QAAQ,cAAc;AAErE,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,uBAAuB;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAQO,MAAM,oBAAoB,OAC/B,WACkC;AAClC,QAAM,WAAW,MAAM,8BAA8B,OAAO,EAAE;AAE9D,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,OAAO,IAAI,SAAS;AAE5B,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,UAAM,0BAAY,MAAM;AAErC,SAAO,QAAQ;AACjB;AASO,MAAM,cAAc,OACzB,QACA,QACA,cACqB;AAErB,SAAO;AACT;","names":["import_project","import_oAuth2","import_organization","import_user"]}
1
+ {"version":3,"sources":["../../../src/services/oAuth2.service.ts"],"sourcesContent":["import type { OAuth2Token } from '@/types/oAuth2.types';\nimport type { Organization } from '@/types/organization.types';\nimport type {\n OAuth2Access,\n OAuth2AccessContext,\n Project,\n ProjectDocument,\n} from '@/types/project.types';\nimport type { User, UserAPI, UserDocument } from '@/types/user.types';\nimport { OAuth2AccessTokenModel } from '@models/oAuth2.model';\nimport { ProjectModel } from '@models/project.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport { mapOrganizationToAPI } from '@utils/mapper/organization';\nimport { mapProjectToAPI } from '@utils/mapper/project';\nimport { mapUserToAPI } from '@utils/mapper/user';\nimport { getTokenExpireAt } from '@utils/oAuth2';\nimport { randomBytes } from 'crypto';\nimport { Types } from 'mongoose';\nimport type { Callback, Client } from 'oauth2-server';\nimport type { Token } from '../schemas/oAuth2.schema';\nimport { getOrganizationById } from './organization.service';\nimport { getUserById } from './user.service';\n\n/**\n * Function to generate client credentials\n *\n * @returns The client id and client secret\n */\nexport const generateClientCredentials = (): {\n clientId: string;\n clientSecret: string;\n} => {\n const clientId = randomBytes(16).toString('hex'); // Generate a 16 character hexadecimal string\n const clientSecret = randomBytes(32).toString('hex'); // Generate a 32 character hexadecimal string\n\n return { clientId, clientSecret };\n};\n\n/**\n * Method to get the client and the project\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The an object containing the client, the rights and the project or false if not found\n */\nexport const getClientAndProjectByClientId = async (\n clientId: string\n): Promise<\n | {\n client: Client;\n oAuth2Access: OAuth2Access;\n project: ProjectDocument;\n grants: Token['grants'];\n }\n | false\n> => {\n const project = await ProjectModel.findOne({\n 'oAuth2Access.clientId': clientId,\n });\n\n if (!project) {\n return false;\n }\n\n const oAuth2Access = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!oAuth2Access) {\n return false;\n }\n\n const formattedClient: Client = {\n id: oAuth2Access.clientId,\n clientId,\n clientSecret: oAuth2Access.clientSecret,\n grants: ['client_credentials'],\n };\n\n return {\n client: formattedClient,\n oAuth2Access,\n grants: oAuth2Access.grants,\n project,\n };\n};\n\n/**\n * Get the client and verify that the client secret is correct\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The client or false if not found\n */\nexport const getClient = async (\n clientId: string,\n clientSecret: string\n): Promise<Client | false> => {\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client } = result;\n\n if (!client || client.clientSecret !== clientSecret) {\n return false;\n }\n\n return client;\n};\n\n/**\n * Format an OAuth2Token\n *\n * @param token - The token to format\n * @param client - The client\n * @param user - The user\n * @param project - The project\n * @param organization - The organization\n * @param grants - The grants\n * @returns The formatted token\n */\nexport const formatOAuth2Token = (\n token: Token,\n client: Client,\n user: UserAPI,\n project: Project,\n organization: Organization,\n grants: Token['grants']\n): OAuth2Token => {\n const { clientId, userId, ...restToken } = token;\n\n if (String(userId) !== String(user.id)) {\n throw new GenericError('USER_ID_MISMATCH');\n }\n\n const formattedToken: OAuth2Token = {\n ...restToken,\n client,\n user: mapUserToAPI(user),\n organization: mapOrganizationToAPI(organization),\n project: mapProjectToAPI(project),\n accessToken: token.accessToken,\n accessTokenExpiresAt: token.accessTokenExpiresAt ?? new Date('999-99-99'),\n grants,\n };\n\n return formattedToken;\n};\n\n/**\n * Format a auth token for the database\n *\n * @param token - The oAuth2 token to format\n * @param clientId - The client ID\n * @param userId - The user ID\n * @returns\n */\nexport const formatDBToken = (\n token: OAuth2Token,\n clientId: Client['id'],\n userId: User['id'] | string\n): Token => {\n const formattedToken: Token = {\n id: token.id,\n clientId: clientId,\n userId: userId as Types.ObjectId,\n accessToken: token.accessToken,\n expiresIn: token.accessTokenExpiresAt ?? getTokenExpireAt(),\n };\n\n return formattedToken;\n};\n\n/**\n * Method to save the token\n *\n * @param token - The token\n * @param client - The client\n * @param user - The user\n * @returns The saved token or false if not saved\n */\nexport const saveToken = async (\n token: OAuth2Token,\n client: Client,\n user: UserAPI\n): Promise<OAuth2Token | false> => {\n const formattedAccessToken: Token = formatDBToken(token, client.id, user.id);\n\n const result = await OAuth2AccessTokenModel.create(formattedAccessToken);\n\n if (!result) {\n return false;\n }\n\n const result2 = await getClientAndProjectByClientId(result.clientId);\n\n if (!result2) {\n return false;\n }\n\n const { project } = result2;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedResult = formatOAuth2Token(\n formattedAccessToken,\n client,\n user,\n project,\n organization,\n token.rights\n );\n return formattedResult;\n};\n\n/**\n * Method to get the access token\n *\n * @param accessToken - The access token\n * @returns The access token or false if not found\n */\nexport const getAccessToken = async (\n accessToken: string\n): Promise<OAuth2Token | false> => {\n const token = await OAuth2AccessTokenModel.findOne({\n accessToken,\n });\n\n if (!token) {\n return false;\n }\n\n const { userId, clientId } = token;\n\n const user = await getUserById(userId);\n\n if (!user) {\n return false;\n }\n\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client, project, grants } = result;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedAccessToken = formatOAuth2Token(\n token,\n client,\n user,\n project,\n organization,\n grants\n );\n\n return formattedAccessToken;\n};\n\n/**\n * Method to get the user from the client\n *\n * @param client - The client\n * @returns The user or false if not found\n */\nexport const getUserFromClient = async (\n client: Client\n): Promise<UserDocument | false> => {\n const response = await getClientAndProjectByClientId(client.id);\n\n if (!response) {\n return false;\n }\n\n const { userId } = response.oAuth2Access;\n\n if (!userId) {\n return false;\n }\n\n const user = await getUserById(userId);\n\n return user ?? false;\n};\n\n/**\n * Method to verify the permissions (grants)\n *\n * @param token - The token\n * @param scope - The scope\n * @returns True if the token has the required scope, false otherwise\n */\nexport const verifyScope = async (\n _token: OAuth2Token,\n _scope: string,\n _callback?: Callback<boolean> | undefined\n): Promise<boolean> => {\n // Implement the verification of scopes if necessary\n return true;\n};\n\n/**\n * Validate OAuth2 access token and return user context\n */\nexport const validateOAuth2AccessToken = async (\n accessToken: string\n): Promise<Token> => {\n try {\n const token = await OAuth2AccessTokenModel.findOne({\n accessToken,\n });\n\n if (!token) {\n throw new GenericError('INVALID_ACCESS_TOKEN');\n }\n\n // Check if token is expired\n if (new Date() > new Date(token.expiresIn)) {\n throw new GenericError('EXPIRED_ACCESS_TOKEN');\n }\n\n return ensureMongoDocumentToObject(token);\n } catch (error) {\n throw new GenericError('INVALID_ACCESS_TOKEN');\n }\n};\n\n/**\n * Validate OAuth2 access token and return user context\n */\nexport const getOAuth2AccessTokenContext = async (\n token: Token\n): Promise<OAuth2AccessContext> => {\n const { userId, clientId } = token;\n\n const user = await getUserById(String(userId));\n\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n throw new GenericError('INVALID_ACCESS_TOKEN');\n }\n\n const { project, grants } = result;\n\n let organization = await getOrganizationById(project.organizationId);\n\n return {\n accessToken: token.accessToken,\n user: user ? mapUserToAPI(user) : undefined,\n project: project ? mapProjectToAPI(project) : undefined,\n organization: organization ? mapOrganizationToAPI(organization) : undefined,\n grants,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,oBAAuC;AACvC,qBAA6B;AAC7B,yCAA4C;AAC5C,oBAA6B;AAC7B,0BAAqC;AACrC,IAAAA,kBAAgC;AAChC,kBAA6B;AAC7B,IAAAC,iBAAiC;AACjC,oBAA4B;AAI5B,IAAAC,uBAAoC;AACpC,IAAAC,eAA4B;AAOrB,MAAM,4BAA4B,MAGpC;AACH,QAAM,eAAW,2BAAY,EAAE,EAAE,SAAS,KAAK;AAC/C,QAAM,mBAAe,2BAAY,EAAE,EAAE,SAAS,KAAK;AAEnD,SAAO,EAAE,UAAU,aAAa;AAClC;AASO,MAAM,gCAAgC,OAC3C,aASG;AACH,QAAM,UAAU,MAAM,4BAAa,QAAQ;AAAA,IACzC,yBAAyB;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,QAAQ,aAAa;AAAA,IACxC,CAAC,WAAW,OAAO,aAAa;AAAA,EAClC;AAEA,MAAI,CAAC,cAAc;AACjB,W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