@intlayer/backend 7.2.1-canary.1 → 7.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/dist/esm/utils/AI/aiSdk.mjs +7 -1
  2. package/dist/esm/utils/AI/aiSdk.mjs.map +1 -1
  3. package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
  4. package/dist/types/controllers/tag.controller.d.ts.map +1 -1
  5. package/dist/types/emails/InviteUserEmail.d.ts +4 -4
  6. package/dist/types/emails/InviteUserEmail.d.ts.map +1 -1
  7. package/dist/types/emails/MagicLinkEmail.d.ts +4 -4
  8. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts +4 -4
  9. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts.map +1 -1
  10. package/dist/types/emails/PasswordChangeConfirmation.d.ts +4 -4
  11. package/dist/types/emails/ResetUserPassword.d.ts +4 -4
  12. package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +4 -4
  13. package/dist/types/emails/SubscriptionPaymentError.d.ts +4 -4
  14. package/dist/types/emails/SubscriptionPaymentError.d.ts.map +1 -1
  15. package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +4 -4
  16. package/dist/types/emails/ValidateUserEmail.d.ts +4 -4
  17. package/dist/types/emails/Welcome.d.ts +4 -4
  18. package/dist/types/emails/Welcome.d.ts.map +1 -1
  19. package/dist/types/models/dictionary.model.d.ts +4 -4
  20. package/dist/types/models/dictionary.model.d.ts.map +1 -1
  21. package/dist/types/models/discussion.model.d.ts +2 -2
  22. package/dist/types/models/oAuth2.model.d.ts +3 -3
  23. package/dist/types/models/oAuth2.model.d.ts.map +1 -1
  24. package/dist/types/routes/ai.routes.d.ts.map +1 -1
  25. package/dist/types/routes/eventListener.routes.d.ts.map +1 -1
  26. package/dist/types/routes/project.routes.d.ts.map +1 -1
  27. package/dist/types/schemas/dictionary.schema.d.ts +6 -6
  28. package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
  29. package/dist/types/schemas/discussion.schema.d.ts +6 -6
  30. package/dist/types/schemas/oAuth2.schema.d.ts +5 -5
  31. package/dist/types/schemas/organization.schema.d.ts +6 -6
  32. package/dist/types/schemas/plans.schema.d.ts +6 -6
  33. package/dist/types/schemas/project.schema.d.ts +6 -6
  34. package/dist/types/schemas/project.schema.d.ts.map +1 -1
  35. package/dist/types/schemas/session.schema.d.ts +6 -6
  36. package/dist/types/schemas/tag.schema.d.ts +6 -6
  37. package/dist/types/schemas/user.schema.d.ts +6 -6
  38. package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -2
  39. package/dist/types/utils/filtersAndPagination/getDiscussionFiltersAndPagination.d.ts +2 -2
  40. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +2 -2
  41. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +2 -2
  42. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +2 -2
  43. package/package.json +17 -18
  44. package/dist/cjs/_virtual/_utils_asset.cjs +0 -98
  45. package/dist/cjs/_virtual/rolldown_runtime.cjs +0 -25
  46. package/dist/cjs/controllers/ai.controller.cjs +0 -381
  47. package/dist/cjs/controllers/ai.controller.cjs.map +0 -1
  48. package/dist/cjs/controllers/dictionary.controller.cjs +0 -463
  49. package/dist/cjs/controllers/dictionary.controller.cjs.map +0 -1
  50. package/dist/cjs/controllers/eventListener.controller.cjs +0 -53
  51. package/dist/cjs/controllers/eventListener.controller.cjs.map +0 -1
  52. package/dist/cjs/controllers/newsletter.controller.cjs +0 -164
  53. package/dist/cjs/controllers/newsletter.controller.cjs.map +0 -1
  54. package/dist/cjs/controllers/oAuth2.controller.cjs +0 -22
  55. package/dist/cjs/controllers/oAuth2.controller.cjs.map +0 -1
  56. package/dist/cjs/controllers/organization.controller.cjs +0 -492
  57. package/dist/cjs/controllers/organization.controller.cjs.map +0 -1
  58. package/dist/cjs/controllers/project.controller.cjs +0 -430
  59. package/dist/cjs/controllers/project.controller.cjs.map +0 -1
  60. package/dist/cjs/controllers/projectAccessKey.controller.cjs +0 -161
  61. package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +0 -1
  62. package/dist/cjs/controllers/search.controller.cjs +0 -14
  63. package/dist/cjs/controllers/search.controller.cjs.map +0 -1
  64. package/dist/cjs/controllers/stripe.controller.cjs +0 -149
  65. package/dist/cjs/controllers/stripe.controller.cjs.map +0 -1
  66. package/dist/cjs/controllers/tag.controller.cjs +0 -226
  67. package/dist/cjs/controllers/tag.controller.cjs.map +0 -1
  68. package/dist/cjs/controllers/user.controller.cjs +0 -269
  69. package/dist/cjs/controllers/user.controller.cjs.map +0 -1
  70. package/dist/cjs/emails/InviteUserEmail.cjs +0 -325
  71. package/dist/cjs/emails/InviteUserEmail.cjs.map +0 -1
  72. package/dist/cjs/emails/MagicLinkEmail.cjs +0 -242
  73. package/dist/cjs/emails/MagicLinkEmail.cjs.map +0 -1
  74. package/dist/cjs/emails/OAuthTokenCreatedEmail.cjs +0 -301
  75. package/dist/cjs/emails/OAuthTokenCreatedEmail.cjs.map +0 -1
  76. package/dist/cjs/emails/PasswordChangeConfirmation.cjs +0 -177
  77. package/dist/cjs/emails/PasswordChangeConfirmation.cjs.map +0 -1
  78. package/dist/cjs/emails/ResetUserPassword.cjs +0 -240
  79. package/dist/cjs/emails/ResetUserPassword.cjs.map +0 -1
  80. package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs +0 -202
  81. package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs.map +0 -1
  82. package/dist/cjs/emails/SubscriptionPaymentError.cjs +0 -202
  83. package/dist/cjs/emails/SubscriptionPaymentError.cjs.map +0 -1
  84. package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs +0 -208
  85. package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs.map +0 -1
  86. package/dist/cjs/emails/ValidateUserEmail.cjs +0 -240
  87. package/dist/cjs/emails/ValidateUserEmail.cjs.map +0 -1
  88. package/dist/cjs/emails/Welcome.cjs +0 -216
  89. package/dist/cjs/emails/Welcome.cjs.map +0 -1
  90. package/dist/cjs/emails/index.cjs +0 -25
  91. package/dist/cjs/export.cjs +0 -24
  92. package/dist/cjs/index.cjs +0 -91
  93. package/dist/cjs/index.cjs.map +0 -1
  94. package/dist/cjs/logger/index.cjs +0 -13
  95. package/dist/cjs/logger/index.cjs.map +0 -1
  96. package/dist/cjs/middlewares/oAuth2.middleware.cjs +0 -42
  97. package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +0 -1
  98. package/dist/cjs/middlewares/request.middleware.cjs +0 -17
  99. package/dist/cjs/middlewares/request.middleware.cjs.map +0 -1
  100. package/dist/cjs/middlewares/sessionAuth.middleware.cjs +0 -22
  101. package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +0 -1
  102. package/dist/cjs/models/dictionary.model.cjs +0 -10
  103. package/dist/cjs/models/dictionary.model.cjs.map +0 -1
  104. package/dist/cjs/models/discussion.model.cjs +0 -10
  105. package/dist/cjs/models/discussion.model.cjs.map +0 -1
  106. package/dist/cjs/models/oAuth2.model.cjs +0 -10
  107. package/dist/cjs/models/oAuth2.model.cjs.map +0 -1
  108. package/dist/cjs/models/organization.model.cjs +0 -10
  109. package/dist/cjs/models/organization.model.cjs.map +0 -1
  110. package/dist/cjs/models/project.model.cjs +0 -10
  111. package/dist/cjs/models/project.model.cjs.map +0 -1
  112. package/dist/cjs/models/session.model.cjs +0 -10
  113. package/dist/cjs/models/session.model.cjs.map +0 -1
  114. package/dist/cjs/models/tag.model.cjs +0 -10
  115. package/dist/cjs/models/tag.model.cjs.map +0 -1
  116. package/dist/cjs/models/user.model.cjs +0 -10
  117. package/dist/cjs/models/user.model.cjs.map +0 -1
  118. package/dist/cjs/routes/ai.routes.cjs +0 -75
  119. package/dist/cjs/routes/ai.routes.cjs.map +0 -1
  120. package/dist/cjs/routes/dictionary.routes.cjs +0 -64
  121. package/dist/cjs/routes/dictionary.routes.cjs.map +0 -1
  122. package/dist/cjs/routes/eventListener.routes.cjs +0 -20
  123. package/dist/cjs/routes/eventListener.routes.cjs.map +0 -1
  124. package/dist/cjs/routes/newsletter.routes.cjs +0 -34
  125. package/dist/cjs/routes/newsletter.routes.cjs.map +0 -1
  126. package/dist/cjs/routes/organization.routes.cjs +0 -70
  127. package/dist/cjs/routes/organization.routes.cjs.map +0 -1
  128. package/dist/cjs/routes/project.routes.cjs +0 -83
  129. package/dist/cjs/routes/project.routes.cjs.map +0 -1
  130. package/dist/cjs/routes/search.routes.cjs +0 -20
  131. package/dist/cjs/routes/search.routes.cjs.map +0 -1
  132. package/dist/cjs/routes/stripe.routes.cjs +0 -34
  133. package/dist/cjs/routes/stripe.routes.cjs.map +0 -1
  134. package/dist/cjs/routes/tags.routes.cjs +0 -40
  135. package/dist/cjs/routes/tags.routes.cjs.map +0 -1
  136. package/dist/cjs/routes/user.routes.cjs +0 -58
  137. package/dist/cjs/routes/user.routes.cjs.map +0 -1
  138. package/dist/cjs/schemas/dictionary.schema.cjs +0 -73
  139. package/dist/cjs/schemas/dictionary.schema.cjs.map +0 -1
  140. package/dist/cjs/schemas/discussion.schema.cjs +0 -81
  141. package/dist/cjs/schemas/discussion.schema.cjs.map +0 -1
  142. package/dist/cjs/schemas/oAuth2.schema.cjs +0 -49
  143. package/dist/cjs/schemas/oAuth2.schema.cjs.map +0 -1
  144. package/dist/cjs/schemas/organization.schema.cjs +0 -62
  145. package/dist/cjs/schemas/organization.schema.cjs.map +0 -1
  146. package/dist/cjs/schemas/plans.schema.cjs +0 -75
  147. package/dist/cjs/schemas/plans.schema.cjs.map +0 -1
  148. package/dist/cjs/schemas/project.schema.cjs +0 -112
  149. package/dist/cjs/schemas/project.schema.cjs.map +0 -1
  150. package/dist/cjs/schemas/session.schema.cjs +0 -43
  151. package/dist/cjs/schemas/session.schema.cjs.map +0 -1
  152. package/dist/cjs/schemas/tag.schema.cjs +0 -62
  153. package/dist/cjs/schemas/tag.schema.cjs.map +0 -1
  154. package/dist/cjs/schemas/user.schema.cjs +0 -87
  155. package/dist/cjs/schemas/user.schema.cjs.map +0 -1
  156. package/dist/cjs/services/dictionary.service.cjs +0 -176
  157. package/dist/cjs/services/dictionary.service.cjs.map +0 -1
  158. package/dist/cjs/services/email.service.cjs +0 -155
  159. package/dist/cjs/services/email.service.cjs.map +0 -1
  160. package/dist/cjs/services/oAuth2.service.cjs +0 -211
  161. package/dist/cjs/services/oAuth2.service.cjs.map +0 -1
  162. package/dist/cjs/services/organization.service.cjs +0 -106
  163. package/dist/cjs/services/organization.service.cjs.map +0 -1
  164. package/dist/cjs/services/project.service.cjs +0 -89
  165. package/dist/cjs/services/project.service.cjs.map +0 -1
  166. package/dist/cjs/services/projectAccessKey.service.cjs +0 -111
  167. package/dist/cjs/services/projectAccessKey.service.cjs.map +0 -1
  168. package/dist/cjs/services/subscription.service.cjs +0 -184
  169. package/dist/cjs/services/subscription.service.cjs.map +0 -1
  170. package/dist/cjs/services/tag.service.cjs +0 -88
  171. package/dist/cjs/services/tag.service.cjs.map +0 -1
  172. package/dist/cjs/services/user.service.cjs +0 -120
  173. package/dist/cjs/services/user.service.cjs.map +0 -1
  174. package/dist/cjs/types/Routes.cjs +0 -0
  175. package/dist/cjs/types/dictionary.types.cjs +0 -0
  176. package/dist/cjs/types/discussion.types.cjs +0 -0
  177. package/dist/cjs/types/oAuth2.types.cjs +0 -0
  178. package/dist/cjs/types/organization.types.cjs +0 -0
  179. package/dist/cjs/types/plan.types.cjs +0 -0
  180. package/dist/cjs/types/project.types.cjs +0 -0
  181. package/dist/cjs/types/session.types.cjs +0 -0
  182. package/dist/cjs/types/tag.types.cjs +0 -0
  183. package/dist/cjs/types/user.types.cjs +0 -10
  184. package/dist/cjs/types/user.types.cjs.map +0 -1
  185. package/dist/cjs/utils/AI/aiSdk.cjs +0 -94
  186. package/dist/cjs/utils/AI/aiSdk.cjs.map +0 -1
  187. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs +0 -201
  188. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs.map +0 -1
  189. package/dist/cjs/utils/AI/askDocQuestion/indexMarkdownFiles.cjs +0 -150
  190. package/dist/cjs/utils/AI/askDocQuestion/indexMarkdownFiles.cjs.map +0 -1
  191. package/dist/cjs/utils/AI/auditDictionary/index.cjs +0 -60
  192. package/dist/cjs/utils/AI/auditDictionary/index.cjs.map +0 -1
  193. package/dist/cjs/utils/AI/auditDictionaryField/index.cjs +0 -63
  194. package/dist/cjs/utils/AI/auditDictionaryField/index.cjs.map +0 -1
  195. package/dist/cjs/utils/AI/auditDictionaryMetadata/index.cjs +0 -45
  196. package/dist/cjs/utils/AI/auditDictionaryMetadata/index.cjs.map +0 -1
  197. package/dist/cjs/utils/AI/auditTag/index.cjs +0 -40
  198. package/dist/cjs/utils/AI/auditTag/index.cjs.map +0 -1
  199. package/dist/cjs/utils/AI/autocomplete/index.cjs +0 -41
  200. package/dist/cjs/utils/AI/autocomplete/index.cjs.map +0 -1
  201. package/dist/cjs/utils/AI/customQuery/index.cjs +0 -27
  202. package/dist/cjs/utils/AI/customQuery/index.cjs.map +0 -1
  203. package/dist/cjs/utils/AI/translateJSON/index.cjs +0 -71
  204. package/dist/cjs/utils/AI/translateJSON/index.cjs.map +0 -1
  205. package/dist/cjs/utils/access.cjs +0 -0
  206. package/dist/cjs/utils/accessControl.cjs +0 -133
  207. package/dist/cjs/utils/accessControl.cjs.map +0 -1
  208. package/dist/cjs/utils/auth/getAuth.cjs +0 -218
  209. package/dist/cjs/utils/auth/getAuth.cjs.map +0 -1
  210. package/dist/cjs/utils/cors.cjs +0 -33
  211. package/dist/cjs/utils/cors.cjs.map +0 -1
  212. package/dist/cjs/utils/ensureArrayQueryFilter.cjs +0 -13
  213. package/dist/cjs/utils/ensureArrayQueryFilter.cjs.map +0 -1
  214. package/dist/cjs/utils/ensureMongoDocumentToObject.cjs +0 -16
  215. package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +0 -1
  216. package/dist/cjs/utils/errors/ErrorHandler.cjs +0 -76
  217. package/dist/cjs/utils/errors/ErrorHandler.cjs.map +0 -1
  218. package/dist/cjs/utils/errors/ErrorsClass.cjs +0 -54
  219. package/dist/cjs/utils/errors/ErrorsClass.cjs.map +0 -1
  220. package/dist/cjs/utils/errors/errorCodes.cjs +0 -1387
  221. package/dist/cjs/utils/errors/errorCodes.cjs.map +0 -1
  222. package/dist/cjs/utils/errors/index.cjs +0 -8
  223. package/dist/cjs/utils/extractJSON.cjs +0 -61
  224. package/dist/cjs/utils/extractJSON.cjs.map +0 -1
  225. package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +0 -94
  226. package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +0 -1
  227. package/dist/cjs/utils/filtersAndPagination/getDiscussionFiltersAndPagination.cjs +0 -65
  228. package/dist/cjs/utils/filtersAndPagination/getDiscussionFiltersAndPagination.cjs.map +0 -1
  229. package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs +0 -36
  230. package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs.map +0 -1
  231. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +0 -49
  232. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +0 -1
  233. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +0 -53
  234. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +0 -1
  235. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs +0 -57
  236. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +0 -1
  237. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +0 -74
  238. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +0 -1
  239. package/dist/cjs/utils/httpStatusCodes.cjs +0 -401
  240. package/dist/cjs/utils/httpStatusCodes.cjs.map +0 -1
  241. package/dist/cjs/utils/mapper/dictionary.cjs +0 -29
  242. package/dist/cjs/utils/mapper/dictionary.cjs.map +0 -1
  243. package/dist/cjs/utils/mapper/organization.cjs +0 -19
  244. package/dist/cjs/utils/mapper/organization.cjs.map +0 -1
  245. package/dist/cjs/utils/mapper/project.cjs +0 -26
  246. package/dist/cjs/utils/mapper/project.cjs.map +0 -1
  247. package/dist/cjs/utils/mapper/session.cjs +0 -15
  248. package/dist/cjs/utils/mapper/session.cjs.map +0 -1
  249. package/dist/cjs/utils/mapper/tag.cjs +0 -25
  250. package/dist/cjs/utils/mapper/tag.cjs.map +0 -1
  251. package/dist/cjs/utils/mapper/user.cjs +0 -24
  252. package/dist/cjs/utils/mapper/user.cjs.map +0 -1
  253. package/dist/cjs/utils/mergeFunctionTypes.cjs +0 -0
  254. package/dist/cjs/utils/mongoDB/connectDB.cjs +0 -32
  255. package/dist/cjs/utils/mongoDB/connectDB.cjs.map +0 -1
  256. package/dist/cjs/utils/mongoDB/types.cjs +0 -0
  257. package/dist/cjs/utils/oAuth2.cjs +0 -25
  258. package/dist/cjs/utils/oAuth2.cjs.map +0 -1
  259. package/dist/cjs/utils/permissions.cjs +0 -103
  260. package/dist/cjs/utils/permissions.cjs.map +0 -1
  261. package/dist/cjs/utils/plan.cjs +0 -63
  262. package/dist/cjs/utils/plan.cjs.map +0 -1
  263. package/dist/cjs/utils/rateLimiter.cjs +0 -48
  264. package/dist/cjs/utils/rateLimiter.cjs.map +0 -1
  265. package/dist/cjs/utils/removeObjectKeys.cjs +0 -11
  266. package/dist/cjs/utils/removeObjectKeys.cjs.map +0 -1
  267. package/dist/cjs/utils/responseData.cjs +0 -33
  268. package/dist/cjs/utils/responseData.cjs.map +0 -1
  269. package/dist/cjs/utils/validation/validateArray.cjs +0 -31
  270. package/dist/cjs/utils/validation/validateArray.cjs.map +0 -1
  271. package/dist/cjs/utils/validation/validateDictionary.cjs +0 -35
  272. package/dist/cjs/utils/validation/validateDictionary.cjs.map +0 -1
  273. package/dist/cjs/utils/validation/validateEmail.cjs +0 -20
  274. package/dist/cjs/utils/validation/validateEmail.cjs.map +0 -1
  275. package/dist/cjs/utils/validation/validateOrganization.cjs +0 -43
  276. package/dist/cjs/utils/validation/validateOrganization.cjs.map +0 -1
  277. package/dist/cjs/utils/validation/validatePhone.cjs +0 -20
  278. package/dist/cjs/utils/validation/validatePhone.cjs.map +0 -1
  279. package/dist/cjs/utils/validation/validateProject.cjs +0 -55
  280. package/dist/cjs/utils/validation/validateProject.cjs.map +0 -1
  281. package/dist/cjs/utils/validation/validateString.cjs +0 -21
  282. package/dist/cjs/utils/validation/validateString.cjs.map +0 -1
  283. package/dist/cjs/utils/validation/validateTag.cjs +0 -47
  284. package/dist/cjs/utils/validation/validateTag.cjs.map +0 -1
  285. package/dist/cjs/utils/validation/validateUser.cjs +0 -47
  286. package/dist/cjs/utils/validation/validateUser.cjs.map +0 -1
  287. package/dist/cjs/webhooks/stripe.webhook.cjs +0 -116
  288. package/dist/cjs/webhooks/stripe.webhook.cjs.map +0 -1
@@ -1,211 +0,0 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const require_utils_ensureMongoDocumentToObject = require('../utils/ensureMongoDocumentToObject.cjs');
3
- const require_utils_errors_ErrorsClass = require('../utils/errors/ErrorsClass.cjs');
4
- const require_services_organization_service = require('./organization.service.cjs');
5
- const require_models_project_model = require('../models/project.model.cjs');
6
- const require_services_user_service = require('./user.service.cjs');
7
- const require_utils_mapper_user = require('../utils/mapper/user.cjs');
8
- const require_utils_mapper_organization = require('../utils/mapper/organization.cjs');
9
- const require_utils_mapper_project = require('../utils/mapper/project.cjs');
10
- const require_models_oAuth2_model = require('../models/oAuth2.model.cjs');
11
- const require_utils_oAuth2 = require('../utils/oAuth2.cjs');
12
- let node_crypto = require("node:crypto");
13
-
14
- //#region src/services/oAuth2.service.ts
15
- /**
16
- * Function to generate client credentials
17
- *
18
- * @returns The client id and client secret
19
- */
20
- const generateClientCredentials = () => {
21
- return {
22
- clientId: (0, node_crypto.randomBytes)(16).toString("hex"),
23
- clientSecret: (0, node_crypto.randomBytes)(32).toString("hex")
24
- };
25
- };
26
- /**
27
- * Method to get the client and the project
28
- *
29
- * @param clientId - The client id
30
- * @param clientSecret - The client secret
31
- * @returns The an object containing the client, the rights and the project or false if not found
32
- */
33
- const getClientAndProjectByClientId = async (clientId) => {
34
- const project = await require_models_project_model.ProjectModel.findOne({ "oAuth2Access.clientId": clientId });
35
- if (!project) return false;
36
- const oAuth2Access = project.oAuth2Access.find((access) => access.clientId === clientId);
37
- if (!oAuth2Access) return false;
38
- return {
39
- client: {
40
- id: oAuth2Access.clientId,
41
- clientId,
42
- clientSecret: oAuth2Access.clientSecret,
43
- grants: ["client_credentials"]
44
- },
45
- oAuth2Access,
46
- grants: oAuth2Access.grants,
47
- project
48
- };
49
- };
50
- /**
51
- * Get the client and verify that the client secret is correct
52
- *
53
- * @param clientId - The client id
54
- * @param clientSecret - The client secret
55
- * @returns The client or false if not found
56
- */
57
- const getClient = async (clientId, clientSecret) => {
58
- const result = await getClientAndProjectByClientId(clientId);
59
- if (!result) return false;
60
- const { client } = result;
61
- if (!client || client.clientSecret !== clientSecret) return false;
62
- return client;
63
- };
64
- /**
65
- * Format an OAuth2Token
66
- *
67
- * @param token - The token to format
68
- * @param client - The client
69
- * @param user - The user
70
- * @param project - The project
71
- * @param organization - The organization
72
- * @param grants - The grants
73
- * @returns The formatted token
74
- */
75
- const formatOAuth2Token = (token, client, user, project, organization, grants) => {
76
- const { clientId, userId, ...restToken } = token;
77
- if (String(userId) !== String(user.id)) throw new require_utils_errors_ErrorsClass.GenericError("USER_ID_MISMATCH");
78
- return {
79
- ...restToken,
80
- client,
81
- user: require_utils_mapper_user.mapUserToAPI(user),
82
- organization: require_utils_mapper_organization.mapOrganizationToAPI(organization),
83
- project: require_utils_mapper_project.mapProjectToAPI(project),
84
- accessToken: token.accessToken,
85
- accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99"),
86
- grants
87
- };
88
- };
89
- /**
90
- * Format a auth token for the database
91
- *
92
- * @param token - The oAuth2 token to format
93
- * @param clientId - The client ID
94
- * @param userId - The user ID
95
- * @returns
96
- */
97
- const formatDBToken = (token, clientId, userId) => {
98
- return {
99
- id: token.id,
100
- clientId,
101
- userId,
102
- accessToken: token.accessToken,
103
- expiresIn: token.accessTokenExpiresAt ?? require_utils_oAuth2.getTokenExpireAt()
104
- };
105
- };
106
- /**
107
- * Method to save the token
108
- *
109
- * @param token - The token
110
- * @param client - The client
111
- * @param user - The user
112
- * @returns The saved token or false if not saved
113
- */
114
- const saveToken = async (token, client, user) => {
115
- const formattedAccessToken = formatDBToken(token, client.id, user.id);
116
- const result = await require_models_oAuth2_model.OAuth2AccessTokenModel.create(formattedAccessToken);
117
- if (!result) return false;
118
- const result2 = await getClientAndProjectByClientId(result.clientId);
119
- if (!result2) return false;
120
- const { project } = result2;
121
- const organization = await require_services_organization_service.getOrganizationById(project.organizationId);
122
- if (!organization) return false;
123
- return formatOAuth2Token(formattedAccessToken, client, user, project, organization, token.rights);
124
- };
125
- /**
126
- * Method to get the access token
127
- *
128
- * @param accessToken - The access token
129
- * @returns The access token or false if not found
130
- */
131
- const getAccessToken = async (accessToken) => {
132
- const token = await require_models_oAuth2_model.OAuth2AccessTokenModel.findOne({ accessToken });
133
- if (!token) return false;
134
- const { userId, clientId } = token;
135
- const user = await require_services_user_service.getUserById(userId);
136
- if (!user) return false;
137
- const result = await getClientAndProjectByClientId(clientId);
138
- if (!result) return false;
139
- const { client, project, grants } = result;
140
- const organization = await require_services_organization_service.getOrganizationById(project.organizationId);
141
- if (!organization) return false;
142
- return formatOAuth2Token(token, client, user, project, organization, grants);
143
- };
144
- /**
145
- * Method to get the user from the client
146
- *
147
- * @param client - The client
148
- * @returns The user or false if not found
149
- */
150
- const getUserFromClient = async (client) => {
151
- const response = await getClientAndProjectByClientId(client.id);
152
- if (!response) return false;
153
- const { userId } = response.oAuth2Access;
154
- if (!userId) return false;
155
- return await require_services_user_service.getUserById(userId) ?? false;
156
- };
157
- /**
158
- * Method to verify the permissions (grants)
159
- *
160
- * @param token - The token
161
- * @param scope - The scope
162
- * @returns True if the token has the required scope, false otherwise
163
- */
164
- const verifyScope = async (_token, _scope, _callback) => {
165
- return true;
166
- };
167
- /**
168
- * Validate OAuth2 access token and return user context
169
- */
170
- const validateOAuth2AccessToken = async (accessToken) => {
171
- try {
172
- const token = await require_models_oAuth2_model.OAuth2AccessTokenModel.findOne({ accessToken });
173
- if (!token) throw new require_utils_errors_ErrorsClass.GenericError("INVALID_ACCESS_TOKEN");
174
- if (/* @__PURE__ */ new Date() > new Date(token.expiresIn)) throw new require_utils_errors_ErrorsClass.GenericError("EXPIRED_ACCESS_TOKEN");
175
- return require_utils_ensureMongoDocumentToObject.ensureMongoDocumentToObject(token);
176
- } catch (_error) {
177
- throw new require_utils_errors_ErrorsClass.GenericError("INVALID_ACCESS_TOKEN");
178
- }
179
- };
180
- /**
181
- * Validate OAuth2 access token and return user context
182
- */
183
- const getOAuth2AccessTokenContext = async (token) => {
184
- const { userId, clientId } = token;
185
- const user = await require_services_user_service.getUserById(String(userId));
186
- const result = await getClientAndProjectByClientId(clientId);
187
- if (!result) throw new require_utils_errors_ErrorsClass.GenericError("INVALID_ACCESS_TOKEN");
188
- const { project, grants } = result;
189
- const organization = await require_services_organization_service.getOrganizationById(project.organizationId);
190
- return {
191
- accessToken: token.accessToken,
192
- user: user ? require_utils_mapper_user.mapUserToAPI(user) : void 0,
193
- project: project ? require_utils_mapper_project.mapProjectToAPI(project) : void 0,
194
- organization: organization ? require_utils_mapper_organization.mapOrganizationToAPI(organization) : void 0,
195
- grants
196
- };
197
- };
198
-
199
- //#endregion
200
- exports.formatDBToken = formatDBToken;
201
- exports.formatOAuth2Token = formatOAuth2Token;
202
- exports.generateClientCredentials = generateClientCredentials;
203
- exports.getAccessToken = getAccessToken;
204
- exports.getClient = getClient;
205
- exports.getClientAndProjectByClientId = getClientAndProjectByClientId;
206
- exports.getOAuth2AccessTokenContext = getOAuth2AccessTokenContext;
207
- exports.getUserFromClient = getUserFromClient;
208
- exports.saveToken = saveToken;
209
- exports.validateOAuth2AccessToken = validateOAuth2AccessToken;
210
- exports.verifyScope = verifyScope;
211
- //# sourceMappingURL=oAuth2.service.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oAuth2.service.cjs","names":["ProjectModel","GenericError","mapUserToAPI","mapOrganizationToAPI","mapProjectToAPI","getTokenExpireAt","formattedAccessToken: Token","OAuth2AccessTokenModel","getOrganizationById","getUserById","ensureMongoDocumentToObject"],"sources":["../../../src/services/oAuth2.service.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto';\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 type { Types } from 'mongoose';\nimport type { Callback, Client } from 'oauth2-server';\nimport 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 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 // biome-ignore lint/correctness/noUnusedVariables: Just filter out clientId\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 const 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":";;;;;;;;;;;;;;;;;;;AA6BA,MAAa,kCAGR;AAIH,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I,CAAC,MACH,OAAM,IAAIN,8CAAa,uBAAuB;AAIhD,sBAAI,IAAI,MAAM,GAAG,IAAI,KAAK,MAAM,UAAU,CACxC,OAAM,IAAIA,8CAAa,uBAAuB;AAGhD,SAAOS,sEAA4B,MAAM;UAClC,QAAQ;AACf,QAAM,IAAIT,8CAAa,uBAAuB;;;;;;AAOlD,MAAa,8BAA8B,OACzC,UACiC;CACjC,MAAM,EAAE,QAAQ,aAAa;CAE7B,MAAM,OAAO,MAAMQ,0CAAY,OAAO,OAAO,CAAC;CAE9C,MAAM,SAAS,MAAM,8BAA8B,SAAS;AAE5D,KAAI,CAAC,OACH,OAAM,IAAIR,8CAAa,uBAAuB;CAGhD,MAAM,EAAE,SAAS,WAAW;CAE5B,MAAM,eAAe,MAAMO,0DAAoB,QAAQ,eAAe;AAEtE,QAAO;EACL,aAAa,MAAM;EACnB,MAAM,OAAON,uCAAa,KAAK,GAAG;EAClC,SAAS,UAAUE,6CAAgB,QAAQ,GAAG;EAC9C,cAAc,eAAeD,uDAAqB,aAAa,GAAG;EAClE;EACD"}
@@ -1,106 +0,0 @@
1
- const require_utils_errors_ErrorsClass = require('../utils/errors/ErrorsClass.cjs');
2
- const require_utils_validation_validateOrganization = require('../utils/validation/validateOrganization.cjs');
3
- const require_models_organization_model = require('../models/organization.model.cjs');
4
-
5
- //#region src/services/organization.service.ts
6
- /**
7
- * Finds organizations based on filters and pagination options.
8
- * @param filters - MongoDB filter query.
9
- * @param skip - Number of documents to skip.
10
- * @param limit - Number of documents to limit.
11
- * @returns List of organizations matching the filters.
12
- */
13
- const findOrganizations = async (filters, skip, limit, sortOptions) => {
14
- let query = require_models_organization_model.OrganizationModel.find(filters).skip(skip).limit(limit);
15
- if (sortOptions && Object.keys(sortOptions).length > 0) query = query.sort(sortOptions);
16
- return await query;
17
- };
18
- /**
19
- * Finds an organization by its ID.
20
- * @param organizationId - The ID of the organization to find.
21
- * @returns The organization matching the ID.
22
- */
23
- const getOrganizationById = async (organizationId) => {
24
- const organization = await require_models_organization_model.OrganizationModel.findById(organizationId);
25
- if (!organization) throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_NOT_FOUND", { organizationId });
26
- return organization;
27
- };
28
- /**
29
- * Counts the total number of organizations that match the filters.
30
- * @param filters - MongoDB filter query.
31
- * @returns Total number of organizations.
32
- */
33
- const countOrganizations = async (filters) => {
34
- const result = await require_models_organization_model.OrganizationModel.countDocuments(filters);
35
- if (typeof result === "undefined") throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_COUNT_FAILED", { filters });
36
- return result;
37
- };
38
- /**
39
- * Creates a new organization in the database.
40
- * @param organization - The organization data to create.
41
- * @returns The created organization.
42
- */
43
- const createOrganization = async (organization, userId) => {
44
- const errors = require_utils_validation_validateOrganization.validateOrganization(organization, ["name"]);
45
- if (Object.keys(errors).length > 0) throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_INVALID_FIELDS", { errors });
46
- try {
47
- return await require_models_organization_model.OrganizationModel.create({
48
- creatorId: userId,
49
- membersIds: [userId],
50
- adminsIds: [userId],
51
- ...organization
52
- });
53
- } catch (error) {
54
- throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_CREATION_FAILED", { error: error.message });
55
- }
56
- };
57
- /**
58
- * Updates an existing organization in the database by its ID.
59
- * @param organizationId - The ID of the organization to update.
60
- * @param organization - The updated organization data.
61
- * @returns The updated organization.
62
- */
63
- const updateOrganizationById = async (organizationId, organization) => {
64
- const errors = require_utils_validation_validateOrganization.validateOrganization(organization, Object.keys(organization));
65
- if (Object.keys(errors).length > 0) throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_INVALID_FIELDS", {
66
- organizationId,
67
- errors
68
- });
69
- if ((await require_models_organization_model.OrganizationModel.updateOne({ _id: organizationId }, organization)).matchedCount === 0) throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_UPDATE_FAILED", { organizationId });
70
- return await getOrganizationById(organizationId);
71
- };
72
- /**
73
- * Deletes an organization from the database by its ID.
74
- * @param organizationId - The ID of the organization to delete.
75
- * @returns The result of the deletion operation.
76
- */
77
- const deleteOrganizationById = async (organizationId) => {
78
- const organization = await require_models_organization_model.OrganizationModel.findByIdAndDelete(organizationId);
79
- if (!organization) throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_NOT_FOUND", { organizationId });
80
- return organization;
81
- };
82
- /**
83
- * Updates an existing plan in the database by its ID.
84
- * @param planId - The ID of the plan to update.
85
- * @param plan - The updated plan data.
86
- * @returns The updated plan.
87
- */
88
- const updatePlan = async (organization, plan) => {
89
- let prevPlan = organization.plan ?? {};
90
- if (typeof prevPlan?.toObject === "function") prevPlan = prevPlan.toObject();
91
- if ((await require_models_organization_model.OrganizationModel.updateOne({ _id: organization.id }, { $set: { plan: {
92
- ...prevPlan,
93
- ...plan
94
- } } })).matchedCount === 0) throw new require_utils_errors_ErrorsClass.GenericError("ORGANIZATION_UPDATE_FAILED", { organizationId: organization.id });
95
- return await getOrganizationById(organization.id);
96
- };
97
-
98
- //#endregion
99
- exports.countOrganizations = countOrganizations;
100
- exports.createOrganization = createOrganization;
101
- exports.deleteOrganizationById = deleteOrganizationById;
102
- exports.findOrganizations = findOrganizations;
103
- exports.getOrganizationById = getOrganizationById;
104
- exports.updateOrganizationById = updateOrganizationById;
105
- exports.updatePlan = updatePlan;
106
- //# sourceMappingURL=organization.service.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"organization.service.cjs","names":["OrganizationModel","GenericError","validateOrganization"],"sources":["../../../src/services/organization.service.ts"],"sourcesContent":["import { OrganizationModel } from '@models/organization.model';\nimport { GenericError } from '@utils/errors';\nimport type { OrganizationFilters } from '@utils/filtersAndPagination/getOrganizationFiltersAndPagination';\nimport {\n type OrganizationFields,\n validateOrganization,\n} from '@utils/validation/validateOrganization';\nimport type { Types } from 'mongoose';\nimport type {\n Organization,\n OrganizationAPI,\n OrganizationCreationData,\n OrganizationDocument,\n} from '@/types/organization.types';\nimport type { Plan, PlanDocument } from '@/types/plan.types';\n\n/**\n * Finds organizations 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 organizations matching the filters.\n */\nexport const findOrganizations = async (\n filters: OrganizationFilters,\n skip: number,\n limit: number,\n sortOptions?: Record<string, 1 | -1>\n): Promise<OrganizationDocument[]> => {\n let query = OrganizationModel.find(filters).skip(skip).limit(limit);\n\n if (sortOptions && Object.keys(sortOptions).length > 0) {\n query = query.sort(sortOptions);\n }\n\n return await query;\n};\n\n/**\n * Finds an organization by its ID.\n * @param organizationId - The ID of the organization to find.\n * @returns The organization matching the ID.\n */\nexport const getOrganizationById = async (\n organizationId: string | Types.ObjectId\n): Promise<OrganizationDocument> => {\n const organization = await OrganizationModel.findById(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n\n/**\n * Counts the total number of organizations that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of organizations.\n */\nexport const countOrganizations = async (\n filters: OrganizationFilters\n): Promise<number> => {\n const result = await OrganizationModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('ORGANIZATION_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new organization in the database.\n * @param organization - The organization data to create.\n * @returns The created organization.\n */\nexport const createOrganization = async (\n organization: OrganizationCreationData,\n userId: string | Types.ObjectId\n): Promise<OrganizationDocument> => {\n const errors = validateOrganization(organization, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', { errors });\n }\n\n try {\n const result = await OrganizationModel.create({\n creatorId: userId,\n membersIds: [userId],\n adminsIds: [userId],\n ...organization,\n });\n\n return result;\n } catch (error) {\n throw new GenericError('ORGANIZATION_CREATION_FAILED', {\n error: (error as Error).message,\n });\n }\n};\n\n/**\n * Updates an existing organization in the database by its ID.\n * @param organizationId - The ID of the organization to update.\n * @param organization - The updated organization data.\n * @returns The updated organization.\n */\nexport const updateOrganizationById = async (\n organizationId: string | Types.ObjectId,\n organization: Partial<Organization | OrganizationAPI>\n): Promise<OrganizationDocument> => {\n const updatedKeys = Object.keys(organization) as OrganizationFields;\n const errors = validateOrganization(organization, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', {\n organizationId,\n errors,\n });\n }\n\n const result = await OrganizationModel.updateOne(\n { _id: organizationId },\n organization\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('ORGANIZATION_UPDATE_FAILED', { organizationId });\n }\n\n return await getOrganizationById(organizationId);\n};\n\n/**\n * Deletes an organization from the database by its ID.\n * @param organizationId - The ID of the organization to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteOrganizationById = async (\n organizationId: string | Types.ObjectId\n): Promise<OrganizationDocument> => {\n const organization =\n await OrganizationModel.findByIdAndDelete(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n\n/**\n * Updates an existing plan in the database by its ID.\n * @param planId - The ID of the plan to update.\n * @param plan - The updated plan data.\n * @returns The updated plan.\n */\nexport const updatePlan = async (\n organization: Organization | OrganizationDocument,\n plan: Partial<Plan>\n): Promise<OrganizationDocument | null> => {\n let prevPlan = organization.plan ?? {};\n\n if (typeof (prevPlan as PlanDocument)?.toObject === 'function') {\n prevPlan = (prevPlan as PlanDocument).toObject();\n }\n\n const updateOrganizationResult = await OrganizationModel.updateOne(\n { _id: organization.id },\n { $set: { plan: { ...prevPlan, ...plan } } }\n );\n\n if (updateOrganizationResult.matchedCount === 0) {\n throw new GenericError('ORGANIZATION_UPDATE_FAILED', {\n organizationId: organization.id,\n });\n }\n\n const updatedOrganization = await getOrganizationById(organization.id);\n\n return updatedOrganization;\n};\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,oBAAoB,OAC/B,SACA,MACA,OACA,gBACoC;CACpC,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Aa,8BAA8B,EAAE,gBAAgB,CAAC;AAG1E,QAAO,MAAM,oBAAoB,eAAe;;;;;;;AAQlD,MAAa,yBAAyB,OACpC,mBACkC;CAClC,MAAM,eACJ,MAAMD,oDAAkB,kBAAkB,eAAe;AAE3D,KAAI,CAAC,aACH,OAAM,IAAIC,8CAAa,0BAA0B,EAAE,gBAAgB,CAAC;AAGtE,QAAO;;;;;;;;AAST,MAAa,aAAa,OACxB,cACA,SACyC;CACzC,IAAI,WAAW,aAAa,QAAQ,EAAE;AAEtC,KAAI,OAAQ,UAA2B,aAAa,WAClD,YAAY,SAA0B,UAAU;AAQlD,MALiC,MAAMD,oDAAkB,UACvD,EAAE,KAAK,aAAa,IAAI,EACxB,EAAE,MAAM,EAAE,MAAM;EAAE,GAAG;EAAU,GAAG;EAAM,EAAE,EAAE,CAC7C,EAE4B,iBAAiB,EAC5C,OAAM,IAAIC,8CAAa,8BAA8B,EACnD,gBAAgB,aAAa,IAC9B,CAAC;AAKJ,QAF4B,MAAM,oBAAoB,aAAa,GAAG"}
@@ -1,89 +0,0 @@
1
- const require_utils_ensureMongoDocumentToObject = require('../utils/ensureMongoDocumentToObject.cjs');
2
- const require_utils_errors_ErrorsClass = require('../utils/errors/ErrorsClass.cjs');
3
- const require_utils_removeObjectKeys = require('../utils/removeObjectKeys.cjs');
4
- const require_utils_validation_validateProject = require('../utils/validation/validateProject.cjs');
5
- const require_models_project_model = require('../models/project.model.cjs');
6
-
7
- //#region src/services/project.service.ts
8
- /**
9
- * Finds projects based on filters and pagination options.
10
- * @param filters - MongoDB filter query.
11
- * @param skip - Number of documents to skip.
12
- * @param limit - Number of documents to limit.
13
- * @returns List of projects matching the filters.
14
- */
15
- const findProjects = async (filters, skip = 0, limit = 100, sortOptions) => {
16
- let query = require_models_project_model.ProjectModel.find(filters).skip(skip).limit(limit);
17
- if (sortOptions && Object.keys(sortOptions).length > 0) query = query.sort(sortOptions);
18
- return await query;
19
- };
20
- /**
21
- * Finds a project by its ID.
22
- * @param projectId - The ID of the project to find.
23
- * @returns The project matching the ID.
24
- */
25
- const getProjectById = async (projectId) => {
26
- const project = await require_models_project_model.ProjectModel.findById(projectId);
27
- if (!project) throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_NOT_DEFINED", { projectId });
28
- return project;
29
- };
30
- /**
31
- * Counts the total number of projects that match the filters.
32
- * @param filters - MongoDB filter query.
33
- * @returns Total number of projects.
34
- */
35
- const countProjects = async (filters) => {
36
- const result = await require_models_project_model.ProjectModel.countDocuments(filters);
37
- if (typeof result === "undefined") throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_COUNT_FAILED", { filters });
38
- return result;
39
- };
40
- /**
41
- * Creates a new project in the database.
42
- * @param project - The project data to create.
43
- * @returns The created project.
44
- */
45
- const createProject = async (project) => {
46
- if (project.oAuth2Access) project.oAuth2Access = void 0;
47
- const errors = await require_utils_validation_validateProject.validateProject(project, ["name"]);
48
- if (Object.keys(errors).length > 0) throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_INVALID_FIELDS", { errors });
49
- return await require_models_project_model.ProjectModel.create(project);
50
- };
51
- /**
52
- * Updates an existing project in the database by its ID.
53
- * @param projectId - The ID of the project to update.
54
- * @param project - The updated project data.
55
- * @returns The updated project.
56
- */
57
- const updateProjectById = async (projectId, project) => {
58
- const projectToUpdate = require_utils_removeObjectKeys.removeObjectKeys(require_utils_ensureMongoDocumentToObject.ensureMongoDocumentToObject(project), [
59
- "id",
60
- "oAuth2Access",
61
- "organizationId"
62
- ]);
63
- const errors = require_utils_validation_validateProject.validateProject(project, Object.keys(projectToUpdate));
64
- if (Object.keys(errors).length > 0) throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_INVALID_FIELDS", {
65
- projectId,
66
- errors
67
- });
68
- if ((await require_models_project_model.ProjectModel.updateOne({ _id: projectId }, projectToUpdate)).matchedCount === 0) throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_UPDATE_FAILED", { projectId });
69
- return await getProjectById(projectId);
70
- };
71
- /**
72
- * Deletes a project from the database by its ID.
73
- * @param projectId - The ID of the project to delete.
74
- * @returns The result of the deletion operation.
75
- */
76
- const deleteProjectById = async (projectId) => {
77
- const project = await require_models_project_model.ProjectModel.findByIdAndDelete(projectId);
78
- if (!project) throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_NOT_DEFINED", { projectId });
79
- return project;
80
- };
81
-
82
- //#endregion
83
- exports.countProjects = countProjects;
84
- exports.createProject = createProject;
85
- exports.deleteProjectById = deleteProjectById;
86
- exports.findProjects = findProjects;
87
- exports.getProjectById = getProjectById;
88
- exports.updateProjectById = updateProjectById;
89
- //# sourceMappingURL=project.service.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"project.service.cjs","names":["ProjectModel","GenericError","validateProject","removeObjectKeys","ensureMongoDocumentToObject"],"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { Types } from 'mongoose';\nimport type {\n Project,\n ProjectAPI,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects 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 projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100,\n sortOptions?: Record<string, 1 | -1>\n): Promise<ProjectDocument[]> => {\n let query = ProjectModel.find(filters).skip(skip).limit(limit);\n\n if (sortOptions && Object.keys(sortOptions).length > 0) {\n query = query.sort(sortOptions);\n }\n\n return await query;\n};\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | Types.ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n (project as Partial<Project>).oAuth2Access = undefined;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | Types.ObjectId,\n project: Partial<Project | ProjectAPI>\n): Promise<ProjectDocument> => {\n const projectObject = ensureMongoDocumentToObject(project);\n const projectToUpdate = removeObjectKeys(projectObject, [\n 'id',\n 'oAuth2Access',\n 'organizationId',\n ]);\n\n const updatedKeys = Object.keys(projectToUpdate) as ProjectFields;\n\n const errors = validateProject(project, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', {\n projectId,\n errors,\n });\n }\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n projectToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('PROJECT_UPDATE_FAILED', { projectId });\n }\n\n return await getProjectById(projectId);\n};\n\n/**\n * Deletes a project from the database by its ID.\n * @param projectId - The ID of the project to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteProjectById = async (\n projectId: string | Types.ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,eAAe,OAC1B,SACA,OAAO,GACP,QAAQ,KACR,gBAC+B;CAC/B,IAAI,QAAQA,0CAAa,KAAK,QAAQ,CAAC,KAAK,KAAK,CAAC,MAAM,MAAM;AAE9D,KAAI,eAAe,OAAO,KAAK,YAAY,CAAC,SAAS,EACnD,SAAQ,MAAM,KAAK,YAAY;AAGjC,QAAO,MAAM;;;;;;;AAQf,MAAa,iBAAiB,OAC5B,cAC6B;CAC7B,MAAM,UAAU,MAAMA,0CAAa,SAAS,UAAU;AAEtD,KAAI,CAAC,QACH,OAAM,IAAIC,8CAAa,uBAAuB,EAAE,WAAW,CAAC;AAG9D,QAAO;;;;;;;AAQT,MAAa,gBAAgB,OAC3B,YACoB;CACpB,MAAM,SAAS,MAAMD,0CAAa,eAAe,QAAQ;AAEzD,KAAI,OAAO,WAAW,YACpB,OAAM,IAAIC,8CAAa,wBAAwB,EAAE,SAAS,CAAC;AAG7D,QAAO;;;;;;;AAQT,MAAa,gBAAgB,OAC3B,YAC6B;AAC7B,KAAK,QAA6B,aAChC,CAAC,QAA6B,eAAe;CAG/C,MAAM,SAAS,MAAMC,yDAAgB,SAAS,CAAC,OAAO,CAAC;AAEvD,KAAI,OAAO,KAAK,OAAO,CAAC,SAAS,EAC/B,OAAM,IAAID,8CAAa,0BAA0B,EAAE,QAAQ,CAAC;AAG9D,QAAO,MAAMD,0CAAa,OAAO,QAAQ;;;;;;;;AAS3C,MAAa,oBAAoB,OAC/B,WACA,YAC6B;CAE7B,MAAM,kBAAkBG,gDADFC,sEAA4B,QAAQ,EACF;EACtD;EACA;EACA;EACD,CAAC;CAIF,MAAM,SAASF,yDAAgB,SAFX,OAAO,KAAK,gBAAgB,CAEI;AAEpD,KAAI,OAAO,KAAK,OAAO,CAAC,SAAS,EAC/B,OAAM,IAAID,8CAAa,0BAA0B;EAC/C;EACA;EACD,CAAC;AAQJ,MALe,MAAMD,0CAAa,UAChC,EAAE,KAAK,WAAW,EAClB,gBACD,EAEU,iBAAiB,EAC1B,OAAM,IAAIC,8CAAa,yBAAyB,EAAE,WAAW,CAAC;AAGhE,QAAO,MAAM,eAAe,UAAU;;;;;;;AAQxC,MAAa,oBAAoB,OAC/B,cAC6B;CAC7B,MAAM,UAAU,MAAMD,0CAAa,kBAAkB,UAAU;AAE/D,KAAI,CAAC,QACH,OAAM,IAAIC,8CAAa,uBAAuB,EAAE,WAAW,CAAC;AAG9D,QAAO"}
@@ -1,111 +0,0 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const require_utils_errors_ErrorsClass = require('../utils/errors/ErrorsClass.cjs');
3
- const require_models_project_model = require('../models/project.model.cjs');
4
- const require_services_project_service = require('./project.service.cjs');
5
- let node_crypto = require("node:crypto");
6
-
7
- //#region src/services/projectAccessKey.service.ts
8
- /**
9
- * Generates cryptographically secure OAuth2 client credentials
10
- *
11
- * @returns Object containing clientId and clientSecret
12
- *
13
- * Security improvements:
14
- * - clientId: 32 characters (128 bits of entropy)
15
- * - clientSecret: 64 characters (256 bits of entropy)
16
- * - Uses crypto.randomBytes for cryptographically secure random generation
17
- * - Follows OAuth2 best practices for credential strength
18
- */
19
- const generateClientCredentials = () => ({
20
- clientId: (0, node_crypto.randomBytes)(16).toString("hex"),
21
- clientSecret: (0, node_crypto.randomBytes)(32).toString("hex")
22
- });
23
- /**
24
- * Adds a new access key to a project.
25
- *
26
- * @param accessKeyData - The access key data.
27
- * @param projectId - The ID of the project to add the access key to.
28
- * @param user - The user adding the access key.
29
- * @returns The new access key.
30
- *
31
- */
32
- const addNewAccessKey = async (accessKeyData, projectId, user) => {
33
- const { clientId, clientSecret } = generateClientCredentials();
34
- const newAccessKey = {
35
- ...accessKeyData,
36
- clientId,
37
- clientSecret,
38
- userId: user.id,
39
- accessToken: [],
40
- grants: accessKeyData.grants
41
- };
42
- if ((await require_models_project_model.ProjectModel.updateOne({ _id: projectId }, { $push: { oAuth2Access: newAccessKey } })).modifiedCount === 0) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_CREATION_FAILED", {
43
- accessKeyData,
44
- projectId,
45
- userId: user.id
46
- });
47
- const newAccessKeyId = (await require_services_project_service.getProjectById(projectId)).oAuth2Access.find((access) => access.clientId === clientId);
48
- if (!newAccessKeyId) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_CREATION_FAILED", {
49
- accessKeyData,
50
- projectId,
51
- userId: user.id
52
- });
53
- return newAccessKeyId;
54
- };
55
- const deleteAccessKey = async (clientId, project, userId) => {
56
- const projectAccess = project.oAuth2Access.find((access) => access.clientId === clientId && String(access.userId) === String(userId));
57
- if (!projectAccess) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_NOT_FOUND", {
58
- clientId,
59
- projectId: project.id
60
- });
61
- if ((await require_models_project_model.ProjectModel.updateOne({
62
- "oAuth2Access.clientId": clientId,
63
- "oAuth2Access.userId": String(userId)
64
- }, { $pull: { oAuth2Access: { clientId } } })).modifiedCount === 0) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_DELETION_FAILED", {
65
- clientId,
66
- projectId: project.id
67
- });
68
- return projectAccess;
69
- };
70
- const refreshAccessKey = async (clientId, projectId, userId) => {
71
- const project = await require_models_project_model.ProjectModel.findOne({
72
- _id: projectId,
73
- "oAuth2Access.clientId": clientId,
74
- "oAuth2Access.userId": String(userId)
75
- });
76
- if (!project) throw new require_utils_errors_ErrorsClass.GenericError("PROJECT_NOT_FOUND", {
77
- clientId,
78
- projectId,
79
- userId
80
- });
81
- const projectAccess = project.oAuth2Access.find((access) => access.clientId === clientId);
82
- if (!projectAccess) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_NOT_FOUND", {
83
- clientId,
84
- projectId: project.id
85
- });
86
- const { clientSecret } = generateClientCredentials();
87
- if ((await require_models_project_model.ProjectModel.updateOne({
88
- "oAuth2Access.clientId": clientId,
89
- "oAuth2Access.userId": String(userId)
90
- }, { $set: {
91
- "oAuth2Access.$.clientId": projectAccess.clientId,
92
- "oAuth2Access.$.clientSecret": clientSecret
93
- } })).modifiedCount === 0) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_UPDATE_FAILED", {
94
- clientId,
95
- projectId
96
- });
97
- const updatedProject = await require_services_project_service.getProjectById(projectId);
98
- const newAccessKeyId = updatedProject.oAuth2Access.find((access) => access.clientId === projectAccess.clientId);
99
- if (!newAccessKeyId) throw new require_utils_errors_ErrorsClass.GenericError("ACCESS_KEY_CREATION_FAILED", {
100
- accessKeyData: updatedProject.oAuth2Access,
101
- projectId,
102
- userId
103
- });
104
- return newAccessKeyId;
105
- };
106
-
107
- //#endregion
108
- exports.addNewAccessKey = addNewAccessKey;
109
- exports.deleteAccessKey = deleteAccessKey;
110
- exports.refreshAccessKey = refreshAccessKey;
111
- //# sourceMappingURL=projectAccessKey.service.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"projectAccessKey.service.cjs","names":["newAccessKey: OAuth2AccessData","ProjectModel","GenericError","getProjectById"],"sources":["../../../src/services/projectAccessKey.service.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto';\nimport { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { Types } from 'mongoose';\nimport type {\n AccessKeyData,\n OAuth2Access,\n OAuth2AccessData,\n Project,\n} from '@/types/project.types';\nimport type { User } from '@/types/user.types';\nimport { getProjectById } from './project.service';\n\n/**\n * Generates cryptographically secure OAuth2 client credentials\n *\n * @returns Object containing clientId and clientSecret\n *\n * Security improvements:\n * - clientId: 32 characters (128 bits of entropy)\n * - clientSecret: 64 characters (256 bits of entropy)\n * - Uses crypto.randomBytes for cryptographically secure random generation\n * - Follows OAuth2 best practices for credential strength\n */\nconst generateClientCredentials = () => ({\n clientId: randomBytes(16).toString('hex'), // 32 character hexadecimal string\n clientSecret: randomBytes(32).toString('hex'), // 64 character hexadecimal string\n});\n\n/**\n * Adds a new access key to a project.\n *\n * @param accessKeyData - The access key data.\n * @param projectId - The ID of the project to add the access key to.\n * @param user - The user adding the access key.\n * @returns The new access key.\n *\n */\nexport const addNewAccessKey = async (\n accessKeyData: AccessKeyData,\n projectId: string | Types.ObjectId,\n user: User\n): Promise<OAuth2Access> => {\n const { clientId, clientSecret } = generateClientCredentials();\n\n const newAccessKey: OAuth2AccessData = {\n ...accessKeyData,\n clientId,\n clientSecret,\n userId: user.id,\n accessToken: [],\n grants: accessKeyData.grants,\n };\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n { $push: { oAuth2Access: newAccessKey } }\n );\n\n if (result.modifiedCount === 0) {\n throw new GenericError('ACCESS_KEY_CREATION_FAILED', {\n accessKeyData,\n projectId,\n userId: user.id,\n });\n }\n\n const updatedProject = await getProjectById(projectId);\n\n const newAccessKeyId = updatedProject.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!newAccessKeyId) {\n throw new GenericError('ACCESS_KEY_CREATION_FAILED', {\n accessKeyData,\n projectId,\n userId: user.id,\n });\n }\n\n return newAccessKeyId;\n};\n\nexport const deleteAccessKey = async (\n clientId: string | Types.ObjectId,\n project: Project,\n userId: string | Types.ObjectId\n) => {\n const projectAccess = project.oAuth2Access.find(\n (access) =>\n access.clientId === clientId && String(access.userId) === String(userId)\n );\n\n if (!projectAccess) {\n throw new GenericError('ACCESS_KEY_NOT_FOUND', {\n clientId,\n projectId: project.id,\n });\n }\n\n const result = await ProjectModel.updateOne(\n {\n 'oAuth2Access.clientId': clientId,\n 'oAuth2Access.userId': String(userId),\n },\n { $pull: { oAuth2Access: { clientId } } }\n );\n\n if (result.modifiedCount === 0) {\n throw new GenericError('ACCESS_KEY_DELETION_FAILED', {\n clientId,\n projectId: project.id,\n });\n }\n\n return projectAccess;\n};\n\nexport const refreshAccessKey = async (\n clientId: string | Types.ObjectId,\n projectId: string | Types.ObjectId,\n userId: string | Types.ObjectId\n): Promise<OAuth2Access> => {\n const project = await ProjectModel.findOne({\n _id: projectId,\n 'oAuth2Access.clientId': clientId,\n 'oAuth2Access.userId': String(userId),\n });\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_FOUND', {\n clientId,\n projectId,\n userId,\n });\n }\n\n const projectAccess = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!projectAccess) {\n throw new GenericError('ACCESS_KEY_NOT_FOUND', {\n clientId,\n projectId: project.id,\n });\n }\n\n const { clientSecret } = generateClientCredentials();\n\n const result = await ProjectModel.updateOne(\n {\n 'oAuth2Access.clientId': clientId,\n 'oAuth2Access.userId': String(userId),\n },\n {\n $set: {\n 'oAuth2Access.$.clientId': projectAccess.clientId,\n 'oAuth2Access.$.clientSecret': clientSecret,\n },\n }\n );\n\n if (result.modifiedCount === 0) {\n throw new GenericError('ACCESS_KEY_UPDATE_FAILED', {\n clientId,\n projectId,\n });\n }\n\n const updatedProject = await getProjectById(projectId);\n\n const newAccessKeyId = updatedProject.oAuth2Access.find(\n (access) => access.clientId === projectAccess.clientId\n );\n\n if (!newAccessKeyId) {\n throw new GenericError('ACCESS_KEY_CREATION_FAILED', {\n accessKeyData: updatedProject.oAuth2Access,\n projectId,\n userId,\n });\n }\n\n return newAccessKeyId;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,MAAM,mCAAmC;CACvC,uCAAsB,GAAG,CAAC,SAAS,MAAM;CACzC,2CAA0B,GAAG,CAAC,SAAS,MAAM;CAC9C;;;;;;;;;;AAWD,MAAa,kBAAkB,OAC7B,eACA,WACA,SAC0B;CAC1B,MAAM,EAAE,UAAU,iBAAiB,2BAA2B;CAE9D,MAAMA,eAAiC;EACrC,GAAG;EACH;EACA;EACA,QAAQ,KAAK;EACb,aAAa,EAAE;EACf,QAAQ,cAAc;EAC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