@intlayer/backend 7.1.5 → 7.1.7

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 (125) hide show
  1. package/dist/assets/utils/AI/askDocQuestion/embeddings/docs/en/intlayer_with_tanstack.json +9216 -10242
  2. package/dist/cjs/controllers/ai.controller.cjs +2 -2
  3. package/dist/cjs/controllers/ai.controller.cjs.map +1 -1
  4. package/dist/cjs/schemas/dictionary.schema.cjs +2 -2
  5. package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
  6. package/dist/cjs/schemas/discussion.schema.cjs +2 -2
  7. package/dist/cjs/schemas/discussion.schema.cjs.map +1 -1
  8. package/dist/cjs/schemas/oAuth2.schema.cjs +2 -2
  9. package/dist/cjs/schemas/oAuth2.schema.cjs.map +1 -1
  10. package/dist/cjs/schemas/organization.schema.cjs +2 -2
  11. package/dist/cjs/schemas/organization.schema.cjs.map +1 -1
  12. package/dist/cjs/schemas/plans.schema.cjs +2 -2
  13. package/dist/cjs/schemas/plans.schema.cjs.map +1 -1
  14. package/dist/cjs/schemas/project.schema.cjs +2 -2
  15. package/dist/cjs/schemas/project.schema.cjs.map +1 -1
  16. package/dist/cjs/schemas/session.schema.cjs +2 -2
  17. package/dist/cjs/schemas/session.schema.cjs.map +1 -1
  18. package/dist/cjs/schemas/tag.schema.cjs +2 -2
  19. package/dist/cjs/schemas/tag.schema.cjs.map +1 -1
  20. package/dist/cjs/schemas/user.schema.cjs +2 -2
  21. package/dist/cjs/schemas/user.schema.cjs.map +1 -1
  22. package/dist/cjs/services/email.service.cjs +1 -1
  23. package/dist/cjs/services/email.service.cjs.map +1 -1
  24. package/dist/cjs/services/oAuth2.service.cjs +1 -1
  25. package/dist/cjs/services/oAuth2.service.cjs.map +1 -1
  26. package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +1 -1
  27. package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -1
  28. package/dist/cjs/utils/filtersAndPagination/getDiscussionFiltersAndPagination.cjs +1 -1
  29. package/dist/cjs/utils/filtersAndPagination/getDiscussionFiltersAndPagination.cjs.map +1 -1
  30. package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs +1 -1
  31. package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs.map +1 -1
  32. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +1 -1
  33. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
  34. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +1 -1
  35. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
  36. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs +1 -1
  37. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -1
  38. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +1 -1
  39. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
  40. package/dist/cjs/utils/mapper/user.cjs +1 -1
  41. package/dist/cjs/utils/mapper/user.cjs.map +1 -1
  42. package/dist/esm/controllers/ai.controller.mjs +2 -2
  43. package/dist/esm/controllers/ai.controller.mjs.map +1 -1
  44. package/dist/esm/schemas/dictionary.schema.mjs +2 -2
  45. package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
  46. package/dist/esm/schemas/discussion.schema.mjs +2 -2
  47. package/dist/esm/schemas/discussion.schema.mjs.map +1 -1
  48. package/dist/esm/schemas/oAuth2.schema.mjs +2 -2
  49. package/dist/esm/schemas/oAuth2.schema.mjs.map +1 -1
  50. package/dist/esm/schemas/organization.schema.mjs +2 -2
  51. package/dist/esm/schemas/organization.schema.mjs.map +1 -1
  52. package/dist/esm/schemas/plans.schema.mjs +2 -2
  53. package/dist/esm/schemas/plans.schema.mjs.map +1 -1
  54. package/dist/esm/schemas/project.schema.mjs +2 -2
  55. package/dist/esm/schemas/project.schema.mjs.map +1 -1
  56. package/dist/esm/schemas/session.schema.mjs +2 -2
  57. package/dist/esm/schemas/session.schema.mjs.map +1 -1
  58. package/dist/esm/schemas/tag.schema.mjs +2 -2
  59. package/dist/esm/schemas/tag.schema.mjs.map +1 -1
  60. package/dist/esm/schemas/user.schema.mjs +2 -2
  61. package/dist/esm/schemas/user.schema.mjs.map +1 -1
  62. package/dist/esm/services/email.service.mjs +1 -1
  63. package/dist/esm/services/email.service.mjs.map +1 -1
  64. package/dist/esm/services/oAuth2.service.mjs +1 -1
  65. package/dist/esm/services/oAuth2.service.mjs.map +1 -1
  66. package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +1 -1
  67. package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -1
  68. package/dist/esm/utils/filtersAndPagination/getDiscussionFiltersAndPagination.mjs +1 -1
  69. package/dist/esm/utils/filtersAndPagination/getDiscussionFiltersAndPagination.mjs.map +1 -1
  70. package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs +1 -1
  71. package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs.map +1 -1
  72. package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +1 -1
  73. package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
  74. package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +1 -1
  75. package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
  76. package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs +1 -1
  77. package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -1
  78. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +1 -1
  79. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
  80. package/dist/esm/utils/mapper/user.mjs +1 -1
  81. package/dist/esm/utils/mapper/user.mjs.map +1 -1
  82. package/dist/types/controllers/organization.controller.d.ts.map +1 -1
  83. package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
  84. package/dist/types/emails/InviteUserEmail.d.ts +4 -4
  85. package/dist/types/emails/InviteUserEmail.d.ts.map +1 -1
  86. package/dist/types/emails/MagicLinkEmail.d.ts +4 -4
  87. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts +4 -4
  88. package/dist/types/emails/OAuthTokenCreatedEmail.d.ts.map +1 -1
  89. package/dist/types/emails/PasswordChangeConfirmation.d.ts +4 -4
  90. package/dist/types/emails/ResetUserPassword.d.ts +4 -4
  91. package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +4 -4
  92. package/dist/types/emails/SubscriptionPaymentCancellation.d.ts.map +1 -1
  93. package/dist/types/emails/SubscriptionPaymentError.d.ts +4 -4
  94. package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +4 -4
  95. package/dist/types/emails/SubscriptionPaymentSuccess.d.ts.map +1 -1
  96. package/dist/types/emails/ValidateUserEmail.d.ts +4 -4
  97. package/dist/types/emails/Welcome.d.ts +4 -4
  98. package/dist/types/models/dictionary.model.d.ts +4 -4
  99. package/dist/types/models/dictionary.model.d.ts.map +1 -1
  100. package/dist/types/models/discussion.model.d.ts +2 -2
  101. package/dist/types/models/discussion.model.d.ts.map +1 -1
  102. package/dist/types/models/oAuth2.model.d.ts +3 -3
  103. package/dist/types/routes/ai.routes.d.ts.map +1 -1
  104. package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
  105. package/dist/types/routes/search.routes.d.ts.map +1 -1
  106. package/dist/types/routes/tags.routes.d.ts.map +1 -1
  107. package/dist/types/routes/user.routes.d.ts.map +1 -1
  108. package/dist/types/schemas/dictionary.schema.d.ts +6 -6
  109. package/dist/types/schemas/discussion.schema.d.ts +6 -6
  110. package/dist/types/schemas/discussion.schema.d.ts.map +1 -1
  111. package/dist/types/schemas/oAuth2.schema.d.ts +5 -5
  112. package/dist/types/schemas/organization.schema.d.ts +6 -6
  113. package/dist/types/schemas/plans.schema.d.ts +6 -6
  114. package/dist/types/schemas/project.schema.d.ts +6 -6
  115. package/dist/types/schemas/project.schema.d.ts.map +1 -1
  116. package/dist/types/schemas/session.schema.d.ts +6 -6
  117. package/dist/types/schemas/tag.schema.d.ts +6 -6
  118. package/dist/types/schemas/user.schema.d.ts +6 -6
  119. package/dist/types/services/email.service.d.ts +11 -11
  120. package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -2
  121. package/dist/types/utils/filtersAndPagination/getDiscussionFiltersAndPagination.d.ts +2 -2
  122. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +2 -2
  123. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +2 -2
  124. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +2 -2
  125. package/package.json +8 -8
@@ -16,7 +16,7 @@ const require_models_discussion_model = require('../models/discussion.model.cjs'
16
16
 
17
17
  //#region src/controllers/ai.controller.ts
18
18
  const customQuery = async (req, res, _next) => {
19
- const { aiOptions, tagsKeys,...rest } = req.body;
19
+ const { aiOptions, tagsKeys, ...rest } = req.body;
20
20
  let aiConfig;
21
21
  try {
22
22
  aiConfig = await require_utils_AI_aiSdk.getAIConfig(res, {
@@ -48,7 +48,7 @@ const customQuery = async (req, res, _next) => {
48
48
  };
49
49
  const translateJSON = async (req, res, _next) => {
50
50
  const { project } = res.locals;
51
- const { aiOptions, tagsKeys,...rest } = req.body;
51
+ const { aiOptions, tagsKeys, ...rest } = req.body;
52
52
  let aiConfig;
53
53
  try {
54
54
  aiConfig = await require_utils_AI_aiSdk.getAIConfig(res, {
@@ -1 +1 @@
1
- {"version":3,"file":"ai.controller.cjs","names":["aiConfig: AIConfig","getAIConfig","formatResponse","tags: Tag[]","getTagsByKeys","dictionaries: Dictionary[]","getDictionariesByTags","DiscussionModel","getDiscussionFiltersAndPagination","numberOfMessagesById: Record<string, number>","formatPaginatedResponse"],"sources":["../../../src/controllers/ai.controller.ts"],"sourcesContent":["import type { KeyPath, Locale } from '@intlayer/types';\nimport type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { getDictionariesByTags } from '@services/dictionary.service';\nimport * as tagService from '@services/tag.service';\nimport { getTagsByKeys } from '@services/tag.service';\nimport {\n type AIConfig,\n type AIOptions,\n type ChatCompletionRequestMessage,\n getAIConfig,\n} from '@utils/AI/aiSdk';\nimport * as askDocQuestionUtil from '@utils/AI/askDocQuestion/askDocQuestion';\nimport * as auditContentDeclarationUtil from '@utils/AI/auditDictionary';\nimport * as auditContentDeclarationFieldUtil from '@utils/AI/auditDictionaryField';\nimport * as auditContentDeclarationMetadataUtil from '@utils/AI/auditDictionaryMetadata';\nimport * as auditTagUtil from '@utils/AI/auditTag';\nimport * as autocompleteUtil from '@utils/AI/autocomplete';\nimport * as customQueryUtil from '@utils/AI/customQuery';\nimport * as translateJSONUtil from '@utils/AI/translateJSON';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DiscussionFiltersParams,\n getDiscussionFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDiscussionFiltersAndPagination';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport { DiscussionModel } from '@/models/discussion.model';\nimport type { Dictionary } from '@/types/dictionary.types';\nimport type { DiscussionAPI } from '@/types/discussion.types';\nimport type { Tag, TagAPI } from '@/types/tag.types';\n\ntype ReplaceAIConfigByOptions<T> = Omit<T, 'aiConfig'> & {\n aiOptions?: AIOptions;\n};\n\nexport type CustomQueryBody =\n ReplaceAIConfigByOptions<customQueryUtil.CustomQueryOptions> & {\n tagsKeys?: string[];\n applicationContext?: string;\n };\nexport type CustomQueryResult =\n ResponseData<customQueryUtil.CustomQueryResultData>;\n\nexport const customQuery = async (\n req: Request<CustomQueryBody>,\n res: ResponseWithSession<CustomQueryResult>,\n _next: NextFunction\n): Promise<void> => {\n // biome-ignore lint/correctness/noUnusedVariables: Just filter out tagsKeys\n const { aiOptions, tagsKeys, ...rest } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: customQueryUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n const auditResponse = await customQueryUtil.customQuery({\n ...rest,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'QUERY_FAILED');\n return;\n }\n\n const responseData = formatResponse<customQueryUtil.CustomQueryResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type TranslateJSONBody = Omit<\n ReplaceAIConfigByOptions<translateJSONUtil.TranslateJSONOptions>,\n 'tags'\n> & {\n tagsKeys?: string[];\n};\nexport type TranslateJSONResult =\n ResponseData<translateJSONUtil.TranslateJSONResultData>;\n\nexport const translateJSON = async (\n req: Request<TranslateJSONBody>,\n res: ResponseWithSession<TranslateJSONResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { aiOptions, tagsKeys, ...rest } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: translateJSONUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId && tagsKeys) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse = await translateJSONUtil.translateJSON({\n ...rest,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<translateJSONUtil.TranslateJSONResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditContentDeclarationBody = {\n aiOptions?: AIOptions;\n locales: Locale[];\n defaultLocale: Locale;\n fileContent: string;\n filePath?: string;\n tagsKeys?: string[];\n};\nexport type AuditContentDeclarationResult =\n ResponseData<auditContentDeclarationUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclaration = async (\n req: Request<AuditContentDeclarationBody>,\n res: ResponseWithSession<AuditContentDeclarationResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { fileContent, filePath, aiOptions, locales, defaultLocale, tagsKeys } =\n req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditContentDeclarationUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse = await auditContentDeclarationUtil.auditDictionary({\n fileContent,\n filePath,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n locales,\n defaultLocale,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationUtil.AuditFileResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditContentDeclarationFieldBody = {\n aiOptions?: AIOptions;\n locales: Locale[];\n fileContent: string;\n filePath?: string;\n tagsKeys?: string[];\n keyPath: KeyPath[];\n};\nexport type AuditContentDeclarationFieldResult =\n ResponseData<auditContentDeclarationFieldUtil.AuditDictionaryFieldResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclarationField = async (\n req: Request<AuditContentDeclarationFieldBody>,\n res: ResponseWithSession<AuditContentDeclarationFieldResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { fileContent, aiOptions, locales, tagsKeys, keyPath } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditContentDeclarationFieldUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse =\n await auditContentDeclarationFieldUtil.auditDictionaryField({\n fileContent,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n locales,\n tags,\n keyPath,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationFieldUtil.AuditDictionaryFieldResultData>(\n {\n data: auditResponse,\n }\n );\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditContentDeclarationMetadataBody = {\n aiOptions?: AIOptions;\n fileContent: string;\n};\n\nexport type AuditContentDeclarationMetadataResult =\n ResponseData<auditContentDeclarationMetadataUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclarationMetadata = async (\n req: Request<AuditContentDeclarationMetadataBody>,\n res: ResponseWithSession<AuditContentDeclarationMetadataResult>,\n _next: NextFunction\n): Promise<void> => {\n const { organization } = res.locals;\n const { fileContent, aiOptions } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditContentDeclarationMetadataUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n const tags: Tag[] = await tagService.findTags(\n {\n organizationId: organization?.id,\n },\n 0,\n 1000\n );\n\n const auditResponse =\n await auditContentDeclarationMetadataUtil.auditDictionaryMetadata({\n fileContent,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationMetadataUtil.AuditFileResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditTagBody = {\n aiOptions?: AIOptions;\n tag: TagAPI;\n};\nexport type AuditTagResult = ResponseData<auditTagUtil.TranslateJSONResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditTag = async (\n req: Request<undefined, undefined, AuditTagBody>,\n res: ResponseWithSession<AuditTagResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { aiOptions, tag } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditTagUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let dictionaries: Dictionary[] = [];\n if (project?.organizationId) {\n dictionaries = await getDictionariesByTags([tag.key], project.id);\n }\n\n const auditResponse = await auditTagUtil.auditTag({\n aiConfig,\n dictionaries,\n tag,\n applicationContext: aiOptions?.applicationContext,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData = formatResponse<auditTagUtil.TranslateJSONResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n};\nexport type AskDocQuestionResult =\n ResponseData<askDocQuestionUtil.AskDocQuestionResult>;\n\nexport const askDocQuestion = async (\n req: Request<undefined, undefined, AskDocQuestionBody>,\n res: ResponseWithSession<AskDocQuestionResult>,\n _next: NextFunction\n): Promise<void> => {\n const { messages = [], discussionId } = req.body;\n const { user, project, organization } = res.locals;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: {},\n defaultOptions: askDocQuestionUtil.aiDefaultOptions,\n accessType: ['public'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n // 1. Prepare SSE headers and flush them NOW\n res.setHeader('Content-Type', 'text/event-stream; charset=utf-8');\n res.setHeader('Cache-Control', 'no-cache, no-transform');\n res.setHeader('Connection', 'keep-alive');\n res.setHeader('X-Accel-Buffering', 'no'); // disable nginx buffering\n res.flushHeaders?.();\n res.write(': connected\\n\\n'); // initial comment keeps some browsers happy\n res.flush?.();\n\n // 2. Kick off the upstream stream WITHOUT awaiting it\n askDocQuestionUtil\n .askDocQuestion(messages, aiConfig, {\n onMessage: (chunk) => {\n res.write(`data: ${JSON.stringify({ chunk })}\\n\\n`);\n res.flush?.();\n },\n })\n .then(async (fullResponse) => {\n const lastUserMessageContent = messages.findLast(\n (message) => message.role === 'user'\n )?.content;\n const lastUserMessageNbWords = lastUserMessageContent\n ? lastUserMessageContent.split(' ').length\n : 0;\n if (lastUserMessageNbWords > 2) {\n // If the last user message is less than 3 words, don't persist the discussion\n // Example: \"Hello\", \"Hi\", \"Hey\", \"test\", etc.\n\n // 3. Persist discussion while the client already has all chunks\n await DiscussionModel.findOneAndUpdate(\n { discussionId },\n {\n $set: {\n discussionId,\n userId: user?.id,\n projectId: project?.id,\n organizationId: organization?.id,\n messages: [\n ...messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n timestamp: msg.timestamp,\n })),\n {\n role: 'assistant',\n content: fullResponse.response,\n relatedFiles: fullResponse.relatedFiles,\n timestamp: new Date(),\n },\n ],\n },\n },\n { upsert: true, new: true }\n );\n }\n\n // 4. Tell the client we're done and close the stream\n res.write(\n `data: ${JSON.stringify({ done: true, response: fullResponse })}\\n\\n`\n );\n res.end();\n })\n .catch((err) => {\n // propagate error as an SSE event so the client knows why it closed\n res.write(\n `event: error\\ndata: ${JSON.stringify({ message: err.message })}\\n\\n`\n );\n res.end();\n });\n};\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n\nexport type AutocompleteResponse = ResponseData<{\n autocompletion: string;\n}>;\n\nexport const autocomplete = async (\n req: Request<AutocompleteBody>,\n res: ResponseWithSession<AutocompleteResponse>,\n _next: NextFunction\n): Promise<void> => {\n try {\n const { text, aiOptions, contextBefore, currentLine, contextAfter } =\n req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: autocompleteUtil.aiDefaultOptions,\n accessType: ['public'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n const response = (await autocompleteUtil.autocomplete({\n text,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n contextBefore,\n currentLine,\n contextAfter,\n })) ?? {\n autocompletion: '',\n tokenUsed: 0,\n };\n\n const responseData =\n formatResponse<autocompleteUtil.AutocompleteFileResultData>({\n data: response,\n });\n\n res.json(responseData);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDiscussionsParams =\n | ({\n page?: string | number;\n pageSize?: string | number;\n includeMessages?: 'true' | 'false';\n } & DiscussionFiltersParams)\n | undefined;\n\nexport type GetDiscussionsResult = PaginatedResponse<DiscussionAPI>;\n\n/**\n * Retrieves a list of discussions with filters and pagination.\n * Only the owner or admins can access. By default, users only see their own.\n */\nexport const getDiscussions = async (\n req: Request<GetDiscussionsParams>,\n res: ResponseWithSession<GetDiscussionsResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, roles } = res.locals;\n const { filters, sortOptions, pageSize, skip, page, getNumberOfPages } =\n getDiscussionFiltersAndPagination(req, res);\n const includeMessagesParam = (req.query as any)?.includeMessages as\n | 'true'\n | 'false'\n | undefined;\n const includeMessages = includeMessagesParam !== 'false';\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n try {\n const projection = includeMessages ? {} : { messages: 0 };\n const discussions = await DiscussionModel.find(filters, projection)\n .sort(sortOptions)\n .skip(skip)\n .limit(pageSize)\n .lean();\n\n // Compute number of messages for each discussion\n const numberOfMessagesById: Record<string, number> = {};\n if (!includeMessages && discussions.length > 0) {\n const ids = discussions.map((d: any) => d._id);\n const counts = await DiscussionModel.aggregate([\n { $match: { _id: { $in: ids } } },\n {\n $project: {\n numberOfMessages: { $size: { $ifNull: ['$messages', []] } },\n },\n },\n ]);\n for (const c of counts as any[]) {\n numberOfMessagesById[String(c._id)] = c.numberOfMessages ?? 0;\n }\n }\n\n // Permission: allow admin, or the owner for all returned entries\n const allOwnedByUser = discussions.every(\n (d) => String(d.userId) === String(user.id)\n );\n const isAllowed = roles.includes('admin') || allOwnedByUser;\n\n if (!isAllowed) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const totalItems = await DiscussionModel.countDocuments(filters);\n\n const responseData = formatPaginatedResponse({\n data: discussions.map((d: any) => ({\n ...d,\n id: String(d._id ?? d.id),\n numberOfMessages: includeMessages\n ? Array.isArray(d.messages)\n ? d.messages.length\n : 0\n : (numberOfMessagesById[String(d._id ?? d.id)] ?? 0),\n })),\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData as any);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgDA,MAAa,cAAc,OACzB,KACA,KACA,UACkB;CAElB,MAAM,EAAE,WAAW,SAAU,GAAG,SAAS,IAAI;CAE7C,IAAIA;AACJ,KAAI;AACF,aAAW,MAAMC,mCAAY,KAAK;GAChC,aAAa;GACb;GACA,YAAY,CAAC,mBAAmB,SAAS;GAC1C,CAAC;UACK,QAAQ;AACf,iDAAa,2BAA2B,KAAK,mBAAmB;AAChE;;AAGF,KAAI;EACF,MAAM,gBAAgB,qDAAkC;GACtD,GAAG;GACH;GACA,oBAAoB,WAAW;GAChC,CAAC;AAEF,MAAI,CAAC,eAAe;AAClB,kDAAa,2BAA2B,KAAK,eAAe;AAC5D;;EAGF,MAAM,eAAeC,0CAAsD,EACzE,MAAM,eACP,CAAC;AAEF,MAAI,KAAK,aAAa;AACtB;UACO,OAAO;AACd,iDAAa,uBAAuB,KAAK,MAAkB;AAC3D;;;AAaJ,MAAa,gBAAgB,OAC3B,KACA,KACA,UACkB;CAClB,MAAM,EAAE,YAAY,IAAI;CACxB,MAAM,EAAE,WAAW,SAAU,GAAG,SAAS,IAAI;CAE7C,IAAIF;AACJ,KAAI;AACF,aAAW,MAAMC,mCAAY,KAAK;GAChC,aAAa;GACb;GACA,YAAY,CAAC,mBAAmB,SAAS;GAC1C,CAAC;U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e,QAAQ;EAEhE,MAAM,eAAeG,mDAAwB;GAC3C,MAAM,YAAY,KAAK,OAAY;IACjC,GAAG;IACH,IAAI,OAAO,EAAE,OAAO,EAAE,GAAG;IACzB,kBAAkB,kBACd,MAAM,QAAQ,EAAE,SAAS,GACvB,EAAE,SAAS,SACX,IACD,qBAAqB,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK;IACrD,EAAE;GACH;GACA;GACA,YAAY,iBAAiB,WAAW;GACxC;GACD,CAAC;AAEF,MAAI,KAAK,aAAoB;AAC7B;UACO,OAAO;AACd,iDAAa,uBAAuB,KAAK,MAAkB;AAC3D"}
1
+ {"version":3,"file":"ai.controller.cjs","names":["aiConfig: AIConfig","getAIConfig","formatResponse","tags: Tag[]","getTagsByKeys","dictionaries: Dictionary[]","getDictionariesByTags","DiscussionModel","getDiscussionFiltersAndPagination","numberOfMessagesById: Record<string, number>","formatPaginatedResponse"],"sources":["../../../src/controllers/ai.controller.ts"],"sourcesContent":["import type { KeyPath, Locale } from '@intlayer/types';\nimport type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { getDictionariesByTags } from '@services/dictionary.service';\nimport * as tagService from '@services/tag.service';\nimport { getTagsByKeys } from '@services/tag.service';\nimport {\n type AIConfig,\n type AIOptions,\n type ChatCompletionRequestMessage,\n getAIConfig,\n} from '@utils/AI/aiSdk';\nimport * as askDocQuestionUtil from '@utils/AI/askDocQuestion/askDocQuestion';\nimport * as auditContentDeclarationUtil from '@utils/AI/auditDictionary';\nimport * as auditContentDeclarationFieldUtil from '@utils/AI/auditDictionaryField';\nimport * as auditContentDeclarationMetadataUtil from '@utils/AI/auditDictionaryMetadata';\nimport * as auditTagUtil from '@utils/AI/auditTag';\nimport * as autocompleteUtil from '@utils/AI/autocomplete';\nimport * as customQueryUtil from '@utils/AI/customQuery';\nimport * as translateJSONUtil from '@utils/AI/translateJSON';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DiscussionFiltersParams,\n getDiscussionFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDiscussionFiltersAndPagination';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport { DiscussionModel } from '@/models/discussion.model';\nimport type { Dictionary } from '@/types/dictionary.types';\nimport type { DiscussionAPI } from '@/types/discussion.types';\nimport type { Tag, TagAPI } from '@/types/tag.types';\n\ntype ReplaceAIConfigByOptions<T> = Omit<T, 'aiConfig'> & {\n aiOptions?: AIOptions;\n};\n\nexport type CustomQueryBody =\n ReplaceAIConfigByOptions<customQueryUtil.CustomQueryOptions> & {\n tagsKeys?: string[];\n applicationContext?: string;\n };\nexport type CustomQueryResult =\n ResponseData<customQueryUtil.CustomQueryResultData>;\n\nexport const customQuery = async (\n req: Request<CustomQueryBody>,\n res: ResponseWithSession<CustomQueryResult>,\n _next: NextFunction\n): Promise<void> => {\n // biome-ignore lint/correctness/noUnusedVariables: Just filter out tagsKeys\n const { aiOptions, tagsKeys, ...rest } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: customQueryUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n const auditResponse = await customQueryUtil.customQuery({\n ...rest,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'QUERY_FAILED');\n return;\n }\n\n const responseData = formatResponse<customQueryUtil.CustomQueryResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type TranslateJSONBody = Omit<\n ReplaceAIConfigByOptions<translateJSONUtil.TranslateJSONOptions>,\n 'tags'\n> & {\n tagsKeys?: string[];\n};\nexport type TranslateJSONResult =\n ResponseData<translateJSONUtil.TranslateJSONResultData>;\n\nexport const translateJSON = async (\n req: Request<TranslateJSONBody>,\n res: ResponseWithSession<TranslateJSONResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { aiOptions, tagsKeys, ...rest } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: translateJSONUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId && tagsKeys) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse = await translateJSONUtil.translateJSON({\n ...rest,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<translateJSONUtil.TranslateJSONResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditContentDeclarationBody = {\n aiOptions?: AIOptions;\n locales: Locale[];\n defaultLocale: Locale;\n fileContent: string;\n filePath?: string;\n tagsKeys?: string[];\n};\nexport type AuditContentDeclarationResult =\n ResponseData<auditContentDeclarationUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclaration = async (\n req: Request<AuditContentDeclarationBody>,\n res: ResponseWithSession<AuditContentDeclarationResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { fileContent, filePath, aiOptions, locales, defaultLocale, tagsKeys } =\n req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditContentDeclarationUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse = await auditContentDeclarationUtil.auditDictionary({\n fileContent,\n filePath,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n locales,\n defaultLocale,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationUtil.AuditFileResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditContentDeclarationFieldBody = {\n aiOptions?: AIOptions;\n locales: Locale[];\n fileContent: string;\n filePath?: string;\n tagsKeys?: string[];\n keyPath: KeyPath[];\n};\nexport type AuditContentDeclarationFieldResult =\n ResponseData<auditContentDeclarationFieldUtil.AuditDictionaryFieldResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclarationField = async (\n req: Request<AuditContentDeclarationFieldBody>,\n res: ResponseWithSession<AuditContentDeclarationFieldResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { fileContent, aiOptions, locales, tagsKeys, keyPath } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditContentDeclarationFieldUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse =\n await auditContentDeclarationFieldUtil.auditDictionaryField({\n fileContent,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n locales,\n tags,\n keyPath,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationFieldUtil.AuditDictionaryFieldResultData>(\n {\n data: auditResponse,\n }\n );\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditContentDeclarationMetadataBody = {\n aiOptions?: AIOptions;\n fileContent: string;\n};\n\nexport type AuditContentDeclarationMetadataResult =\n ResponseData<auditContentDeclarationMetadataUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclarationMetadata = async (\n req: Request<AuditContentDeclarationMetadataBody>,\n res: ResponseWithSession<AuditContentDeclarationMetadataResult>,\n _next: NextFunction\n): Promise<void> => {\n const { organization } = res.locals;\n const { fileContent, aiOptions } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditContentDeclarationMetadataUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n const tags: Tag[] = await tagService.findTags(\n {\n organizationId: organization?.id,\n },\n 0,\n 1000\n );\n\n const auditResponse =\n await auditContentDeclarationMetadataUtil.auditDictionaryMetadata({\n fileContent,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationMetadataUtil.AuditFileResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AuditTagBody = {\n aiOptions?: AIOptions;\n tag: TagAPI;\n};\nexport type AuditTagResult = ResponseData<auditTagUtil.TranslateJSONResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditTag = async (\n req: Request<undefined, undefined, AuditTagBody>,\n res: ResponseWithSession<AuditTagResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { aiOptions, tag } = req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: auditTagUtil.aiDefaultOptions,\n accessType: ['registered_user', 'apiKey'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n try {\n let dictionaries: Dictionary[] = [];\n if (project?.organizationId) {\n dictionaries = await getDictionariesByTags([tag.key], project.id);\n }\n\n const auditResponse = await auditTagUtil.auditTag({\n aiConfig,\n dictionaries,\n tag,\n applicationContext: aiOptions?.applicationContext,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData = formatResponse<auditTagUtil.TranslateJSONResultData>({\n data: auditResponse,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n};\nexport type AskDocQuestionResult =\n ResponseData<askDocQuestionUtil.AskDocQuestionResult>;\n\nexport const askDocQuestion = async (\n req: Request<undefined, undefined, AskDocQuestionBody>,\n res: ResponseWithSession<AskDocQuestionResult>,\n _next: NextFunction\n): Promise<void> => {\n const { messages = [], discussionId } = req.body;\n const { user, project, organization } = res.locals;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: {},\n defaultOptions: askDocQuestionUtil.aiDefaultOptions,\n accessType: ['public'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n // 1. Prepare SSE headers and flush them NOW\n res.setHeader('Content-Type', 'text/event-stream; charset=utf-8');\n res.setHeader('Cache-Control', 'no-cache, no-transform');\n res.setHeader('Connection', 'keep-alive');\n res.setHeader('X-Accel-Buffering', 'no'); // disable nginx buffering\n res.flushHeaders?.();\n res.write(': connected\\n\\n'); // initial comment keeps some browsers happy\n res.flush?.();\n\n // 2. Kick off the upstream stream WITHOUT awaiting it\n askDocQuestionUtil\n .askDocQuestion(messages, aiConfig, {\n onMessage: (chunk) => {\n res.write(`data: ${JSON.stringify({ chunk })}\\n\\n`);\n res.flush?.();\n },\n })\n .then(async (fullResponse) => {\n const lastUserMessageContent = messages.findLast(\n (message) => message.role === 'user'\n )?.content;\n const lastUserMessageNbWords = lastUserMessageContent\n ? lastUserMessageContent.split(' ').length\n : 0;\n if (lastUserMessageNbWords > 2) {\n // If the last user message is less than 3 words, don't persist the discussion\n // Example: \"Hello\", \"Hi\", \"Hey\", \"test\", etc.\n\n // 3. Persist discussion while the client already has all chunks\n await DiscussionModel.findOneAndUpdate(\n { discussionId },\n {\n $set: {\n discussionId,\n userId: user?.id,\n projectId: project?.id,\n organizationId: organization?.id,\n messages: [\n ...messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n timestamp: msg.timestamp,\n })),\n {\n role: 'assistant',\n content: fullResponse.response,\n relatedFiles: fullResponse.relatedFiles,\n timestamp: new Date(),\n },\n ],\n },\n },\n { upsert: true, new: true }\n );\n }\n\n // 4. Tell the client we're done and close the stream\n res.write(\n `data: ${JSON.stringify({ done: true, response: fullResponse })}\\n\\n`\n );\n res.end();\n })\n .catch((err) => {\n // propagate error as an SSE event so the client knows why it closed\n res.write(\n `event: error\\ndata: ${JSON.stringify({ message: err.message })}\\n\\n`\n );\n res.end();\n });\n};\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n\nexport type AutocompleteResponse = ResponseData<{\n autocompletion: string;\n}>;\n\nexport const autocomplete = async (\n req: Request<AutocompleteBody>,\n res: ResponseWithSession<AutocompleteResponse>,\n _next: NextFunction\n): Promise<void> => {\n try {\n const { text, aiOptions, contextBefore, currentLine, contextAfter } =\n req.body;\n\n let aiConfig: AIConfig;\n try {\n aiConfig = await getAIConfig(res, {\n userOptions: aiOptions,\n defaultOptions: autocompleteUtil.aiDefaultOptions,\n accessType: ['public'],\n });\n } catch (_error) {\n ErrorHandler.handleGenericErrorResponse(res, 'AI_ACCESS_DENIED');\n return;\n }\n\n const response = (await autocompleteUtil.autocomplete({\n text,\n aiConfig,\n applicationContext: aiOptions?.applicationContext,\n contextBefore,\n currentLine,\n contextAfter,\n })) ?? {\n autocompletion: '',\n tokenUsed: 0,\n };\n\n const responseData =\n formatResponse<autocompleteUtil.AutocompleteFileResultData>({\n data: response,\n });\n\n res.json(responseData);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDiscussionsParams =\n | ({\n page?: string | number;\n pageSize?: string | number;\n includeMessages?: 'true' | 'false';\n } & DiscussionFiltersParams)\n | undefined;\n\nexport type GetDiscussionsResult = PaginatedResponse<DiscussionAPI>;\n\n/**\n * Retrieves a list of discussions with filters and pagination.\n * Only the owner or admins can access. By default, users only see their own.\n */\nexport const getDiscussions = async (\n req: Request<GetDiscussionsParams>,\n res: ResponseWithSession<GetDiscussionsResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, roles } = res.locals;\n const { filters, sortOptions, pageSize, skip, page, getNumberOfPages } =\n getDiscussionFiltersAndPagination(req, res);\n const includeMessagesParam = (req.query as any)?.includeMessages as\n | 'true'\n | 'false'\n | undefined;\n const includeMessages = includeMessagesParam !== 'false';\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n try {\n const projection = includeMessages ? {} : { messages: 0 };\n const discussions = await DiscussionModel.find(filters, projection)\n .sort(sortOptions)\n .skip(skip)\n .limit(pageSize)\n .lean();\n\n // Compute number of messages for each discussion\n const numberOfMessagesById: Record<string, number> = {};\n if (!includeMessages && discussions.length > 0) {\n const ids = discussions.map((d: any) => d._id);\n const counts = await DiscussionModel.aggregate([\n { $match: { _id: { $in: ids } } },\n {\n $project: {\n numberOfMessages: { $size: { $ifNull: ['$messages', []] } },\n },\n },\n ]);\n for (const c of counts as any[]) {\n numberOfMessagesById[String(c._id)] = c.numberOfMessages ?? 0;\n }\n }\n\n // Permission: allow admin, or the owner for all returned entries\n const allOwnedByUser = discussions.every(\n (d) => String(d.userId) === String(user.id)\n );\n const isAllowed = roles.includes('admin') || allOwnedByUser;\n\n if (!isAllowed) {\n ErrorHandler.handleGenericErrorResponse(res, 'PERMISSION_DENIED');\n return;\n }\n\n const totalItems = await DiscussionModel.countDocuments(filters);\n\n const responseData = formatPaginatedResponse({\n data: discussions.map((d: any) => ({\n ...d,\n id: String(d._id ?? d.id),\n numberOfMessages: includeMessages\n ? Array.isArray(d.messages)\n ? d.messages.length\n : 0\n : (numberOfMessagesById[String(d._id ?? d.id)] ?? 0),\n })),\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData as any);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgDA,MAAa,cAAc,OACzB,KACA,KACA,UACkB;CAElB,MAAM,EAAE,WAAW,UAAU,GAAG,SAAS,IAAI;CAE7C,IAAIA;AACJ,KAAI;AACF,aAAW,MAAMC,mCAAY,KAAK;GAChC,aAAa;GACb;GACA,YAAY,CAAC,mBAAmB,SAAS;GAC1C,CAAC;UACK,QAAQ;AACf,iDAAa,2BAA2B,KAAK,mBAAmB;AAChE;;AAGF,KAAI;EACF,MAAM,gBAAgB,qDAAkC;GACtD,GA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AAgB,UAAU,CAC7C,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,EAAE,EACjC,EACE,UAAU,EACR,kBAAkB,EAAE,OAAO,EAAE,SAAS,CAAC,aAAa,EAAE,CAAC,EAAE,EAAE,EAC5D,EACF,CACF,CAAC;AACF,QAAK,MAAM,KAAK,OACd,sBAAqB,OAAO,EAAE,IAAI,IAAI,EAAE,oBAAoB;;EAKhE,MAAM,iBAAiB,YAAY,OAChC,MAAM,OAAO,EAAE,OAAO,KAAK,OAAO,KAAK,GAAG,CAC5C;AAGD,MAAI,EAFc,MAAM,SAAS,QAAQ,IAAI,iBAE7B;AACd,kDAAa,2BAA2B,KAAK,oBAAoB;AACjE;;EAGF,MAAM,aAAa,MAAMA,gDAAgB,eAAe,QAAQ;EAEhE,MAAM,eAAeG,mDAAwB;GAC3C,MAAM,YAAY,KAAK,OAAY;IACjC,GAAG;IACH,IAAI,OAAO,EAAE,OAAO,EAAE,GAAG;IACzB,kBAAkB,kBACd,MAAM,QAAQ,EAAE,SAAS,GACvB,EAAE,SAAS,SACX,IACD,qBAAqB,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK;IACrD,EAAE;GACH;GACA;GACA,YAAY,iBAAiB,WAAW;GACxC;GACD,CAAC;AAEF,MAAI,KAAK,aAAoB;AAC7B;UACO,OAAO;AACd,iDAAa,uBAAuB,KAAK,MAAkB;AAC3D"}
@@ -49,7 +49,7 @@ const dictionarySchema = new mongoose.Schema({
49
49
  virtuals: true,
50
50
  versionKey: false,
51
51
  transform(_doc, ret) {
52
- const { _id,...rest } = ret;
52
+ const { _id, ...rest } = ret;
53
53
  return {
54
54
  ...rest,
55
55
  id: _id.toString()
@@ -59,7 +59,7 @@ const dictionarySchema = new mongoose.Schema({
59
59
  toObject: {
60
60
  virtuals: true,
61
61
  transform(_doc, ret) {
62
- const { _id,...rest } = ret;
62
+ const { _id, ...rest } = ret;
63
63
  return {
64
64
  ...rest,
65
65
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"dictionary.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/dictionary.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DictionarySchema,\n VersionedContentEl,\n} from '@/types/dictionary.types';\n\nconst versionedContentElSchema = new Schema<VersionedContentEl>(\n {\n name: {\n type: String,\n },\n description: {\n type: String,\n },\n content: {\n type: Schema.Types.Mixed,\n required: true,\n },\n },\n {\n timestamps: true,\n }\n);\n\nexport const dictionarySchema = new Schema<DictionarySchema>(\n {\n projectIds: {\n type: [Schema.Types.ObjectId],\n ref: 'Project',\n required: true,\n },\n key: {\n type: String,\n required: true,\n },\n title: {\n type: String,\n default: '',\n },\n description: {\n type: String,\n default: '',\n },\n tags: {\n type: [String],\n default: [],\n },\n content: {\n type: Map,\n of: versionedContentElSchema,\n required: true,\n default: null,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAMA,MAAM,2BAA2B,IAAIA,gBACnC;CACE,MAAM,EACJ,MAAM,QACP;CACD,aAAa,EACX,MAAM,QACP;CACD,SAAS;EACP,MAAMA,gBAAO,MAAM;EACnB,UAAU;EACX;CACF,EACD,EACE,YAAY,MACb,CACF;AAED,MAAa,mBAAmB,IAAIA,gBAClC;CACE,YAAY;EACV,MAAM,CAACA,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACX;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACX;CACD,OAAO;EACL,MAAM;EACN,SAAS;EACV;CACD,aAAa;EACX,MAAM;EACN,SAAS;EACV;CACD,MAAM;EACJ,MAAM,CAAC,OAAO;EACd,SAAS,EAAE;EACZ;CACD,SAAS;EACP,MAAM;EACN,IAAI;EACJ,UAAU;EACV,SAAS;EACV;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"dictionary.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/dictionary.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type {\n DictionarySchema,\n VersionedContentEl,\n} from '@/types/dictionary.types';\n\nconst versionedContentElSchema = new Schema<VersionedContentEl>(\n {\n name: {\n type: String,\n },\n description: {\n type: String,\n },\n content: {\n type: Schema.Types.Mixed,\n required: true,\n },\n },\n {\n timestamps: true,\n }\n);\n\nexport const dictionarySchema = new Schema<DictionarySchema>(\n {\n projectIds: {\n type: [Schema.Types.ObjectId],\n ref: 'Project',\n required: true,\n },\n key: {\n type: String,\n required: true,\n },\n title: {\n type: String,\n default: '',\n },\n description: {\n type: String,\n default: '',\n },\n tags: {\n type: [String],\n default: [],\n },\n content: {\n type: Map,\n of: versionedContentElSchema,\n required: true,\n default: null,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAMA,MAAM,2BAA2B,IAAIA,gBACnC;CACE,MAAM,EACJ,MAAM,QACP;CACD,aAAa,EACX,MAAM,QACP;CACD,SAAS;EACP,MAAMA,gBAAO,MAAM;EACnB,UAAU;EACX;CACF,EACD,EACE,YAAY,MACb,CACF;AAED,MAAa,mBAAmB,IAAIA,gBAClC;CACE,YAAY;EACV,MAAM,CAACA,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACX;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACX;CACD,OAAO;EACL,MAAM;EACN,SAAS;EACV;CACD,aAAa;EACX,MAAM;EACN,SAAS;EACV;CACD,MAAM;EACJ,MAAM,CAAC,OAAO;EACd,SAAS,EAAE;EACZ;CACD,SAAS;EACP,MAAM;EACN,IAAI;EACJ,UAAU;EACV,SAAS;EACV;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -57,7 +57,7 @@ const discussionSchema = new mongoose.Schema({
57
57
  virtuals: true,
58
58
  versionKey: false,
59
59
  transform(_doc, ret) {
60
- const { _id,...rest } = ret;
60
+ const { _id, ...rest } = ret;
61
61
  return {
62
62
  ...rest,
63
63
  id: _id.toString()
@@ -67,7 +67,7 @@ const discussionSchema = new mongoose.Schema({
67
67
  toObject: {
68
68
  virtuals: true,
69
69
  transform(_doc, ret) {
70
- const { _id,...rest } = ret;
70
+ const { _id, ...rest } = ret;
71
71
  return {
72
72
  ...rest,
73
73
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"discussion.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/discussion.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { DiscussionSchema } from '@/types/discussion.types';\n\nexport const discussionSchema = new Schema<DiscussionSchema>(\n {\n discussionId: {\n type: String,\n required: true,\n unique: true,\n },\n messages: [\n {\n role: {\n type: String,\n required: true,\n enum: ['user', 'assistant', 'system'],\n },\n content: {\n type: String,\n required: true,\n },\n timestamp: {\n type: Date,\n default: Date.now,\n },\n relatedFiles: {\n type: [String],\n },\n },\n ],\n userId: {\n type: Schema.Types.ObjectId,\n ref: 'user',\n required: true,\n },\n projectId: {\n type: Schema.Types.ObjectId,\n ref: 'project',\n required: true,\n },\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'organization',\n required: true,\n },\n title: {\n type: String,\n required: false,\n },\n isArchived: {\n type: Boolean,\n default: 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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAGA,MAAa,mBAAmB,IAAIA,gBAClC;CACE,cAAc;EACZ,MAAM;EACN,UAAU;EACV,QAAQ;EACT;CACD,UAAU,CACR;EACE,MAAM;GACJ,MAAM;GACN,UAAU;GACV,MAAM;IAAC;IAAQ;IAAa;IAAS;GACtC;EACD,SAAS;GACP,MAAM;GACN,UAAU;GACX;EACD,WAAW;GACT,MAAM;GACN,SAAS,KAAK;GACf;EACD,cAAc,EACZ,MAAM,CAAC,OAAO,EACf;EACF,CACF;CACD,QAAQ;EACN,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,gBAAgB;EACd,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,OAAO;EACL,MAAM;EACN,UAAU;EACX;CACD,YAAY;EACV,MAAM;EACN,SAAS;EACV;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"discussion.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/discussion.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { DiscussionSchema } from '@/types/discussion.types';\n\nexport const discussionSchema = new Schema<DiscussionSchema>(\n {\n discussionId: {\n type: String,\n required: true,\n unique: true,\n },\n messages: [\n {\n role: {\n type: String,\n required: true,\n enum: ['user', 'assistant', 'system'],\n },\n content: {\n type: String,\n required: true,\n },\n timestamp: {\n type: Date,\n default: Date.now,\n },\n relatedFiles: {\n type: [String],\n },\n },\n ],\n userId: {\n type: Schema.Types.ObjectId,\n ref: 'user',\n required: true,\n },\n projectId: {\n type: Schema.Types.ObjectId,\n ref: 'project',\n required: true,\n },\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'organization',\n required: true,\n },\n title: {\n type: String,\n required: false,\n },\n isArchived: {\n type: Boolean,\n default: 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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAGA,MAAa,mBAAmB,IAAIA,gBAClC;CACE,cAAc;EACZ,MAAM;EACN,UAAU;EACV,QAAQ;EACT;CACD,UAAU,CACR;EACE,MAAM;GACJ,MAAM;GACN,UAAU;GACV,MAAM;IAAC;IAAQ;IAAa;IAAS;GACtC;EACD,SAAS;GACP,MAAM;GACN,UAAU;GACX;EACD,WAAW;GACT,MAAM;GACN,SAAS,KAAK;GACf;EACD,cAAc,EACZ,MAAM,CAAC,OAAO,EACf;EACF,CACF;CACD,QAAQ;EACN,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,gBAAgB;EACd,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,OAAO;EACL,MAAM;EACN,UAAU;EACX;CACD,YAAY;EACV,MAAM;EACN,SAAS;EACV;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -24,7 +24,7 @@ const accessTokenSchema = new mongoose.Schema({
24
24
  virtuals: true,
25
25
  versionKey: false,
26
26
  transform(_doc, ret) {
27
- const { _id,...rest } = ret;
27
+ const { _id, ...rest } = ret;
28
28
  return {
29
29
  ...rest,
30
30
  id: _id.toString()
@@ -34,7 +34,7 @@ const accessTokenSchema = new mongoose.Schema({
34
34
  toObject: {
35
35
  virtuals: true,
36
36
  transform(_doc, ret) {
37
- const { _id,...rest } = ret;
37
+ const { _id, ...rest } = ret;
38
38
  return {
39
39
  ...rest,
40
40
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"oAuth2.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/oAuth2.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { Client, Token as TokenType } from 'oauth2-server';\nimport type { User } from '@/types/user.types';\n\nexport type Token = Omit<TokenType, 'client' | 'user'> & {\n clientId: Client['id'];\n userId: User['id'];\n};\n\nexport const accessTokenSchema = new Schema<Token>(\n {\n accessToken: {\n type: String,\n required: true,\n },\n accessTokenExpiresAt: {\n type: Date,\n },\n clientId: {\n type: String,\n ref: 'Project',\n required: true,\n },\n userId: {\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n\naccessTokenSchema.index(\n { createdAt: 1 },\n {\n expireAfterSeconds: 60 * 60 * 24 * 10, // 10 Days\n }\n);\n"],"mappings":";;;;AASA,MAAa,oBAAoB,IAAIA,gBACnC;CACE,aAAa;EACX,MAAM;EACN,UAAU;EACX;CACD,sBAAsB,EACpB,MAAM,MACP;CACD,UAAU;EACR,MAAM;EACN,KAAK;EACL,UAAU;EACX;CACD,QAAQ;EACN,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF;AAED,kBAAkB,MAChB,EAAE,WAAW,GAAG,EAChB,EACE,oBAAoB,OAAU,KAAK,IACpC,CACF"}
1
+ {"version":3,"file":"oAuth2.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/oAuth2.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { Client, Token as TokenType } from 'oauth2-server';\nimport type { User } from '@/types/user.types';\n\nexport type Token = Omit<TokenType, 'client' | 'user'> & {\n clientId: Client['id'];\n userId: User['id'];\n};\n\nexport const accessTokenSchema = new Schema<Token>(\n {\n accessToken: {\n type: String,\n required: true,\n },\n accessTokenExpiresAt: {\n type: Date,\n },\n clientId: {\n type: String,\n ref: 'Project',\n required: true,\n },\n userId: {\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n\naccessTokenSchema.index(\n { createdAt: 1 },\n {\n expireAfterSeconds: 60 * 60 * 24 * 10, // 10 Days\n }\n);\n"],"mappings":";;;;AASA,MAAa,oBAAoB,IAAIA,gBACnC;CACE,aAAa;EACX,MAAM;EACN,UAAU;EACX;CACD,sBAAsB,EACpB,MAAM,MACP;CACD,UAAU;EACR,MAAM;EACN,KAAK;EACL,UAAU;EACX;CACD,QAAQ;EACN,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF;AAED,kBAAkB,MAChB,EAAE,WAAW,GAAG,EAChB,EACE,oBAAoB,OAAU,KAAK,IACpC,CACF"}
@@ -35,7 +35,7 @@ const organizationSchema = new mongoose.Schema({
35
35
  virtuals: true,
36
36
  versionKey: false,
37
37
  transform(_doc, ret) {
38
- const { _id,...rest } = ret;
38
+ const { _id, ...rest } = ret;
39
39
  return {
40
40
  ...rest,
41
41
  id: _id.toString()
@@ -45,7 +45,7 @@ const organizationSchema = new mongoose.Schema({
45
45
  toObject: {
46
46
  virtuals: true,
47
47
  transform(_doc, ret) {
48
- const { _id,...rest } = ret;
48
+ const { _id, ...rest } = ret;
49
49
  return {
50
50
  ...rest,
51
51
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"organization.schema.cjs","names":["Schema","NAME_MIN_LENGTH","NAME_MAX_LENGTH","MEMBERS_MIN_LENGTH","planSchema"],"sources":["../../../src/schemas/organization.schema.ts"],"sourcesContent":["import {\n MEMBERS_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateOrganization';\nimport { Schema } from 'mongoose';\nimport type { OrganizationSchema } from '@/types/organization.types';\nimport { planSchema } from './plans.schema';\n\nexport const organizationSchema = new Schema<OrganizationSchema>(\n {\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n membersIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n adminsIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n plan: {\n type: planSchema,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n\n// Add virtual field for id\norganizationSchema.virtual('id').get(function () {\n return this._id.toString();\n});\n"],"mappings":";;;;;;AASA,MAAa,qBAAqB,IAAIA,gBACpC;CACE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,WAAWC;EACX,WAAWC;EACZ;CACD,YAAY;EACV,MAAM,CAACF,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACV,WAAWG;EACZ;CACD,WAAW;EACT,MAAM,CAACH,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACV,WAAWG;EACZ;CACD,WAAW;EACT,MAAMH,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,MAAM,EACJ,MAAMI,yCACP;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF;AAGD,mBAAmB,QAAQ,KAAK,CAAC,IAAI,WAAY;AAC/C,QAAO,KAAK,IAAI,UAAU;EAC1B"}
1
+ {"version":3,"file":"organization.schema.cjs","names":["Schema","NAME_MIN_LENGTH","NAME_MAX_LENGTH","MEMBERS_MIN_LENGTH","planSchema"],"sources":["../../../src/schemas/organization.schema.ts"],"sourcesContent":["import {\n MEMBERS_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateOrganization';\nimport { Schema } from 'mongoose';\nimport type { OrganizationSchema } from '@/types/organization.types';\nimport { planSchema } from './plans.schema';\n\nexport const organizationSchema = new Schema<OrganizationSchema>(\n {\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n membersIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n adminsIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n plan: {\n type: planSchema,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n\n// Add virtual field for id\norganizationSchema.virtual('id').get(function () {\n return this._id.toString();\n});\n"],"mappings":";;;;;;AASA,MAAa,qBAAqB,IAAIA,gBACpC;CACE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,WAAWC;EACX,WAAWC;EACZ;CACD,YAAY;EACV,MAAM,CAACF,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACV,WAAWG;EACZ;CACD,WAAW;EACT,MAAM,CAACH,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACV,WAAWG;EACZ;CACD,WAAW;EACT,MAAMH,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,MAAM,EACJ,MAAMI,yCACP;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF;AAGD,mBAAmB,QAAQ,KAAK,CAAC,IAAI,WAAY;AAC/C,QAAO,KAAK,IAAI,UAAU;EAC1B"}
@@ -51,7 +51,7 @@ const planSchema = new mongoose.Schema({
51
51
  virtuals: true,
52
52
  versionKey: false,
53
53
  transform(_doc, ret) {
54
- const { _id,...rest } = ret;
54
+ const { _id, ...rest } = ret;
55
55
  return {
56
56
  ...rest,
57
57
  id: _id.toString()
@@ -61,7 +61,7 @@ const planSchema = new mongoose.Schema({
61
61
  toObject: {
62
62
  virtuals: true,
63
63
  transform(_doc, ret) {
64
- const { _id,...rest } = ret;
64
+ const { _id, ...rest } = ret;
65
65
  return {
66
66
  ...rest,
67
67
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"plans.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/plans.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { PlanSchema } from '@/types/plan.types';\n\nexport const planSchema = new Schema<PlanSchema>(\n {\n type: {\n type: String,\n required: true,\n enum: ['PREMIUM', 'ENTERPRISE'],\n },\n period: {\n type: String,\n required: true,\n enum: ['MONTHLY', 'YEARLY'],\n default: 'MONTHLY',\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n subscriptionId: {\n type: String,\n required: true,\n },\n customerId: {\n type: String,\n required: true,\n },\n priceId: {\n type: String,\n required: true,\n },\n status: {\n type: String,\n required: true,\n enum: [\n 'active',\n 'canceled',\n 'past_due',\n 'unpaid',\n 'incomplete',\n 'incomplete_expired',\n 'paused',\n 'trialing',\n ],\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAGA,MAAa,aAAa,IAAIA,gBAC5B;CACE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,MAAM,CAAC,WAAW,aAAa;EAChC;CACD,QAAQ;EACN,MAAM;EACN,UAAU;EACV,MAAM,CAAC,WAAW,SAAS;EAC3B,SAAS;EACV;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,gBAAgB;EACd,MAAM;EACN,UAAU;EACX;CACD,YAAY;EACV,MAAM;EACN,UAAU;EACX;CACD,SAAS;EACP,MAAM;EACN,UAAU;EACX;CACD,QAAQ;EACN,MAAM;EACN,UAAU;EACV,MAAM;GACJ;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACF;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"plans.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/plans.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { PlanSchema } from '@/types/plan.types';\n\nexport const planSchema = new Schema<PlanSchema>(\n {\n type: {\n type: String,\n required: true,\n enum: ['PREMIUM', 'ENTERPRISE'],\n },\n period: {\n type: String,\n required: true,\n enum: ['MONTHLY', 'YEARLY'],\n default: 'MONTHLY',\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n subscriptionId: {\n type: String,\n required: true,\n },\n customerId: {\n type: String,\n required: true,\n },\n priceId: {\n type: String,\n required: true,\n },\n status: {\n type: String,\n required: true,\n enum: [\n 'active',\n 'canceled',\n 'past_due',\n 'unpaid',\n 'incomplete',\n 'incomplete_expired',\n 'paused',\n 'trialing',\n ],\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAGA,MAAa,aAAa,IAAIA,gBAC5B;CACE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,MAAM,CAAC,WAAW,aAAa;EAChC;CACD,QAAQ;EACN,MAAM;EACN,UAAU;EACV,MAAM,CAAC,WAAW,SAAS;EAC3B,SAAS;EACV;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,gBAAgB;EACd,MAAM;EACN,UAAU;EACX;CACD,YAAY;EACV,MAAM;EACN,UAAU;EACX;CACD,SAAS;EACP,MAAM;EACN,UAAU;EACX;CACD,QAAQ;EACN,MAAM;EACN,UAAU;EACV,MAAM;GACJ;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACF;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -88,7 +88,7 @@ const projectSchema = new mongoose.Schema({
88
88
  virtuals: true,
89
89
  versionKey: false,
90
90
  transform(_doc, ret) {
91
- const { _id,...rest } = ret;
91
+ const { _id, ...rest } = ret;
92
92
  return {
93
93
  ...rest,
94
94
  id: _id.toString()
@@ -98,7 +98,7 @@ const projectSchema = new mongoose.Schema({
98
98
  toObject: {
99
99
  virtuals: true,
100
100
  transform(_doc, ret) {
101
- const { _id,...rest } = ret;
101
+ const { _id, ...rest } = ret;
102
102
  return {
103
103
  ...rest,
104
104
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"project.schema.cjs","names":["Schema","Locales","NAME_MIN_LENGTH","NAME_MAX_LENGTH","MEMBERS_MIN_LENGTH"],"sources":["../../../src/schemas/project.schema.ts"],"sourcesContent":["import { Locales } from '@intlayer/types';\nimport type { RenameId } from '@utils/mongoDB/types';\nimport {\n MEMBERS_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateProject';\nimport { Schema } from 'mongoose';\nimport type {\n OAuth2Access,\n Project,\n ProjectSchema,\n} from '@/types/project.types';\n\n// Define the oAuth2Access subdocument schema with timestamps\nconst oAuth2AccessSchema = new Schema<RenameId<OAuth2Access>>(\n {\n clientId: { type: String, required: true },\n clientSecret: { type: String, required: true },\n userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },\n name: { type: String, required: true },\n expiresAt: { type: Date },\n accessToken: { type: [String], required: true, default: [] },\n grants: { type: [String], required: true, default: [] },\n },\n {\n timestamps: true,\n }\n);\n\nconst projectConfigSchema = new Schema<Project['configuration']>(\n {\n internationalization: {\n locales: {\n type: [String],\n enum: Object.values(Locales.ALL_LOCALES),\n required: true,\n },\n defaultLocale: {\n type: String,\n enum: Object.values(Locales.ALL_LOCALES),\n },\n },\n editor: {\n applicationURL: {\n type: String,\n },\n cmsURL: {\n type: String,\n },\n },\n },\n {\n _id: false, // Prevents the generation of an _id field for this subdocument\n }\n);\n\nexport const projectSchema = new Schema<ProjectSchema>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n configuration: projectConfigSchema,\n oAuth2Access: [oAuth2AccessSchema],\n membersIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n adminsIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;;;AAeA,MAAM,qBAAqB,IAAIA,gBAC7B;CACE,UAAU;EAAE,MAAM;EAAQ,UAAU;EAAM;CAC1C,cAAc;EAAE,MAAM;EAAQ,UAAU;EAAM;CAC9C,QAAQ;EAAE,MAAMA,gBAAO,MAAM;EAAU,KAAK;E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AAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"project.schema.cjs","names":["Schema","Locales","NAME_MIN_LENGTH","NAME_MAX_LENGTH","MEMBERS_MIN_LENGTH"],"sources":["../../../src/schemas/project.schema.ts"],"sourcesContent":["import { Locales } from '@intlayer/types';\nimport type { RenameId } from '@utils/mongoDB/types';\nimport {\n MEMBERS_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateProject';\nimport { Schema } from 'mongoose';\nimport type {\n OAuth2Access,\n Project,\n ProjectSchema,\n} from '@/types/project.types';\n\n// Define the oAuth2Access subdocument schema with timestamps\nconst oAuth2AccessSchema = new Schema<RenameId<OAuth2Access>>(\n {\n clientId: { type: String, required: true },\n clientSecret: { type: String, required: true },\n userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },\n name: { type: String, required: true },\n expiresAt: { type: Date },\n accessToken: { type: [String], required: true, default: [] },\n grants: { type: [String], required: true, default: [] },\n },\n {\n timestamps: true,\n }\n);\n\nconst projectConfigSchema = new Schema<Project['configuration']>(\n {\n internationalization: {\n locales: {\n type: [String],\n enum: Object.values(Locales.ALL_LOCALES),\n required: true,\n },\n defaultLocale: {\n type: String,\n enum: Object.values(Locales.ALL_LOCALES),\n },\n },\n editor: {\n applicationURL: {\n type: String,\n },\n cmsURL: {\n type: String,\n },\n },\n },\n {\n _id: false, // Prevents the generation of an _id field for this subdocument\n }\n);\n\nexport const projectSchema = new Schema<ProjectSchema>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n configuration: projectConfigSchema,\n oAuth2Access: [oAuth2AccessSchema],\n membersIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n adminsIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;;;AAeA,MAAM,qBAAqB,IAAIA,gBAC7B;CACE,UAAU;EAAE,MAAM;EAAQ,UAAU;EAAM;CAC1C,cAAc;EAAE,MAAM;EAAQ,UAAU;EAAM;CAC9C,QAAQ;EAAE,MAAMA,gBAAO,MAAM;EAAU,KAAK;EAAQ,UAAU;EAAM;CACpE,MAAM;EAAE,MAAM;EAAQ,UAAU;EAAM;CACtC,WAAW,EAAE,MAAM,MAAM;CACzB,aAAa;EAAE,MAAM,CAAC,OAAO;EAAE,UAAU;EAAM,SAAS,EAAE;EAAE;CAC5D,QAAQ;EAAE,MAAM,CAAC,OAAO;EAAE,UAAU;EAAM,SAAS,EAAE;EAAE;CACxD,EACD,EACE,YAAY,MACb,CACF;AAED,MAAM,sBAAsB,IAAIA,gBAC9B;CACE,sBAAsB;EACpB,SAAS;GACP,MAAM,CAAC,OAAO;GACd,MAAM,OAAO,OAAOC,yBAAQ,YAAY;GACxC,UAAU;GACX;EACD,eAAe;GACb,MAAM;GACN,MAAM,OAAO,OAAOA,yBAAQ,YAAY;GACzC;EACF;CACD,QAAQ;EACN,gBAAgB,EACd,MAAM,QACP;EACD,QAAQ,EACN,MAAM,QACP;EACF;CACF,EACD,EACE,KAAK,OACN,CACF;AAED,MAAa,gBAAgB,IAAID,gBAC/B;CACE,gBAAgB;EACd,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,MAAM;EACJ,MAAM;EACN,UAAU;EACV,WAAWE;EACX,WAAWC;EACZ;CACD,eAAe;CACf,cAAc,CAAC,mBAAmB;CAClC,YAAY;EACV,MAAM,CAACH,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACV,WAAWI;EACZ;CACD,WAAW;EACT,MAAM,CAACJ,gBAAO,MAAM,SAAS;EAC7B,KAAK;EACL,UAAU;EACV,WAAWI;EACZ;CACD,WAAW;EACT,MAAMJ,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -19,7 +19,7 @@ const sessionSchema = new mongoose.Schema({
19
19
  virtuals: true,
20
20
  versionKey: false,
21
21
  transform(_doc, ret) {
22
- const { _id,...rest } = ret;
22
+ const { _id, ...rest } = ret;
23
23
  return {
24
24
  ...rest,
25
25
  id: _id.toString()
@@ -29,7 +29,7 @@ const sessionSchema = new mongoose.Schema({
29
29
  toObject: {
30
30
  virtuals: true,
31
31
  transform(_doc, ret) {
32
- const { _id,...rest } = ret;
32
+ const { _id, ...rest } = ret;
33
33
  return {
34
34
  ...rest,
35
35
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"session.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/session.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { SessionSchema } from '@/types/session.types';\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,IAAIA,gBAC/B;CACE,sBAAsB;EACpB,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,iBAAiB;EACf,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"session.schema.cjs","names":["Schema"],"sources":["../../../src/schemas/session.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport type { SessionSchema } from '@/types/session.types';\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,IAAIA,gBAC/B;CACE,sBAAsB;EACpB,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,iBAAiB;EACf,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -38,7 +38,7 @@ const tagSchema = new mongoose.Schema({
38
38
  virtuals: true,
39
39
  versionKey: false,
40
40
  transform(_doc, ret) {
41
- const { _id,...rest } = ret;
41
+ const { _id, ...rest } = ret;
42
42
  return {
43
43
  ...rest,
44
44
  id: _id.toString()
@@ -48,7 +48,7 @@ const tagSchema = new mongoose.Schema({
48
48
  toObject: {
49
49
  virtuals: true,
50
50
  transform(_doc, ret) {
51
- const { _id,...rest } = ret;
51
+ const { _id, ...rest } = ret;
52
52
  return {
53
53
  ...rest,
54
54
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"tag.schema.cjs","names":["Schema","KEY_MIN_LENGTH","KEY_MAX_LENGTH","NAME_MIN_LENGTH","NAME_MAX_LENGTH"],"sources":["../../../src/schemas/tag.schema.ts"],"sourcesContent":["import {\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';\nimport type { TagSchema } from '@/types/tag.types';\n\nexport const tagSchema = new Schema<TagSchema>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n projectId: {\n type: Schema.Types.ObjectId,\n ref: 'Project',\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;;AASA,MAAa,YAAY,IAAIA,gBAC3B;CACE,gBAAgB;EACd,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACV,WAAWC;EACX,WAAWC;EACZ;CACD,MAAM;EACJ,MAAM;EACN,WAAWC;EACX,WAAWC;EACZ;CACD,aAAa,EACX,MAAM,QACP;CACD,cAAc,EACZ,MAAM,QACP;CACD,WAAW;EACT,MAAMJ,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"tag.schema.cjs","names":["Schema","KEY_MIN_LENGTH","KEY_MAX_LENGTH","NAME_MIN_LENGTH","NAME_MAX_LENGTH"],"sources":["../../../src/schemas/tag.schema.ts"],"sourcesContent":["import {\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';\nimport type { TagSchema } from '@/types/tag.types';\n\nexport const tagSchema = new Schema<TagSchema>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n projectId: {\n type: Schema.Types.ObjectId,\n ref: 'Project',\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;;AASA,MAAa,YAAY,IAAIA,gBAC3B;CACE,gBAAgB;EACd,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,WAAW;EACT,MAAMA,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACV,WAAWC;EACX,WAAWC;EACZ;CACD,MAAM;EACJ,MAAM;EACN,WAAWC;EACX,WAAWC;EACZ;CACD,aAAa,EACX,MAAM,QACP;CACD,cAAc,EACZ,MAAM,QACP;CACD,WAAW;EACT,MAAMJ,gBAAO,MAAM;EACnB,KAAK;EACL,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -63,7 +63,7 @@ const userSchema = new mongoose.Schema({
63
63
  virtuals: true,
64
64
  versionKey: false,
65
65
  transform(_doc, ret) {
66
- const { _id,...rest } = ret;
66
+ const { _id, ...rest } = ret;
67
67
  return {
68
68
  ...rest,
69
69
  id: _id.toString()
@@ -73,7 +73,7 @@ const userSchema = new mongoose.Schema({
73
73
  toObject: {
74
74
  virtuals: true,
75
75
  transform(_doc, ret) {
76
- const { _id,...rest } = ret;
76
+ const { _id, ...rest } = ret;
77
77
  return {
78
78
  ...rest,
79
79
  id: _id
@@ -1 +1 @@
1
- {"version":3,"file":"user.schema.cjs","names":["Schema","NAMES_MAX_LENGTH","NAMES_MIN_LENGTH"],"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\nimport type { UserSchema } from '@/types/user.types';\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 role: {\n type: String,\n enum: ['admin', 'user'],\n default: 'user',\n required: false,\n },\n lastLoginMethod: {\n type: String,\n enum: ['email', 'google', 'github'],\n required: false,\n },\n lang: {\n type: String,\n required: false,\n },\n dateOfBirth: {\n type: Date,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;;;;AAQA,MAAa,aAAa,IAAIA,gBAC5B;CACE,OAAO;EACL,MAAM;EACN,UAAU;EACV,QAAQ;EACR,UAAU,CAAC,kBAAU,SAAS,oCAAoC;EAClE,WAAW;EACX,MAAM;EACP;CACD,MAAM;EACJ,MAAM;EACN,WAAWC;EACX,WAAWC;EACZ;CACD,OAAO;EACL,MAAM;EACN,WAAW;EACZ;CAED,YAAY;EACV,MAAM;EACN,UAAU;EACX;CAED,YAAY;EACV,MAAM,EACJ,YAAY;GACV,MAAM;GACN,SAAS;GACV,EACF;EACD,UAAU;EACX;CACD,MAAM;EACJ,MAAM;EACN,MAAM,CAAC,SAAS,OAAO;EACvB,SAAS;EACT,UAAU;EACX;CACD,iBAAiB;EACf,MAAM;EACN,MAAM;GAAC;GAAS;GAAU;GAAS;EACnC,UAAU;EACX;CACD,MAAM;EACJ,MAAM;EACN,UAAU;EACX;CACD,aAAa;EACX,MAAM;EACN,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,IAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
1
+ {"version":3,"file":"user.schema.cjs","names":["Schema","NAMES_MAX_LENGTH","NAMES_MIN_LENGTH"],"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\nimport type { UserSchema } from '@/types/user.types';\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 role: {\n type: String,\n enum: ['admin', 'user'],\n default: 'user',\n required: false,\n },\n lastLoginMethod: {\n type: String,\n enum: ['email', 'google', 'github'],\n required: false,\n },\n lang: {\n type: String,\n required: false,\n },\n dateOfBirth: {\n type: Date,\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: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id.toString(),\n };\n },\n },\n toObject: {\n virtuals: true,\n transform(_doc, ret: any) {\n const { _id, ...rest } = ret;\n return {\n ...rest,\n id: _id,\n };\n },\n },\n }\n);\n"],"mappings":";;;;;;;AAQA,MAAa,aAAa,IAAIA,gBAC5B;CACE,OAAO;EACL,MAAM;EACN,UAAU;EACV,QAAQ;EACR,UAAU,CAAC,kBAAU,SAAS,oCAAoC;EAClE,WAAW;EACX,MAAM;EACP;CACD,MAAM;EACJ,MAAM;EACN,WAAWC;EACX,WAAWC;EACZ;CACD,OAAO;EACL,MAAM;EACN,WAAW;EACZ;CAED,YAAY;EACV,MAAM;EACN,UAAU;EACX;CAED,YAAY;EACV,MAAM,EACJ,YAAY;GACV,MAAM;GACN,SAAS;GACV,EACF;EACD,UAAU;EACX;CACD,MAAM;EACJ,MAAM;EACN,MAAM,CAAC,SAAS,OAAO;EACvB,SAAS;EACT,UAAU;EACX;CACD,iBAAiB;EACf,MAAM;EACN,MAAM;GAAC;GAAS;GAAU;GAAS;EACnC,UAAU;EACX;CACD,MAAM;EACJ,MAAM;EACN,UAAU;EACX;CACD,aAAa;EACX,MAAM;EACN,UAAU;EACX;CACF,EACD;CACE,YAAY;CAEZ,QAAQ;EACN,UAAU;EACV,YAAY;EACZ,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI,IAAI,UAAU;IACnB;;EAEJ;CACD,UAAU;EACR,UAAU;EACV,UAAU,MAAM,KAAU;GACxB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,UAAO;IACL,GAAG;IACH,IAAI;IACL;;EAEJ;CACF,CACF"}
@@ -137,7 +137,7 @@ const getEmailComponents = (locale) => ({
137
137
  })
138
138
  }
139
139
  });
140
- const sendEmail = async ({ type, to, subject, locale,...props }) => {
140
+ const sendEmail = async ({ type, to, subject, locale, ...props }) => {
141
141
  const resend$1 = new resend.Resend(process.env.RESEND_API_KEY);
142
142
  const { template, subject: baseSubject } = getEmailComponents(locale)[type];
143
143
  const react = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(template, { ...props });
@@ -1 +1 @@
1
- {"version":3,"file":"email.service.cjs","names":["InviteUserEmailEN","InviteUserEmailFR","InviteUserEmailES","ValidateUserEmailEN","ValidateUserEmailFR","ValidateUserEmailES","ResetPasswordEmailEN","ResetPasswordEmailFR","ResetPasswordEmailES","WelcomeEmailEN","WelcomeEmailFR","WelcomeEmailES","MagicLinkEmailEN","MagicLinkEmailFR","MagicLinkEmailES","PasswordChangeConfirmationEmailEN","PasswordChangeConfirmationEmailFR","PasswordChangeConfirmationEmailES","SubscriptionPaymentSuccessEN","SubscriptionPaymentSuccessFR","SubscriptionPaymentSuccessES","SubscriptionPaymentCancellationEN","SubscriptionPaymentCancellationFR","SubscriptionPaymentCancellationES","SubscriptionPaymentErrorEN","SubscriptionPaymentErrorFR","SubscriptionPaymentErrorES","OAuthTokenCreatedEmailEN","OAuthTokenCreatedEmailFR","OAuthTokenCreatedEmailES","resend","Resend","logger"],"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["import {\n InviteUserEmailEN,\n InviteUserEmailES,\n InviteUserEmailFR,\n} from '@emails/InviteUserEmail';\nimport {\n MagicLinkEmailEN,\n MagicLinkEmailES,\n MagicLinkEmailFR,\n} from '@emails/MagicLinkEmail';\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';\nimport type { Locale } from '@intlayer/types';\nimport { logger } from '@logger';\nimport { t } from 'express-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?: Locale) =>\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 magicLink: {\n template: t(\n {\n en: MagicLinkEmailEN,\n fr: MagicLinkEmailFR,\n es: MagicLinkEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Sign in to Intlayer',\n fr: 'Connectez-vous à Intlayer',\n es: 'Inicia sesión en 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?: Locale;\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":";;;;;;;;;;;;;;;;;AAiEA,MAAM,sBAAsB,YACzB;CACC,QAAQ;EACN,kCACE;GACE,IAAIA;GACJ,IAAIC;GACJ,IAAIC;GACL,EACD,OACD;EACD,iCACE;GACE,IAAI;GACJ,IAAI;GACJ,IAAI;GACL,EACD,OACD;EACF;CACD,UAAU;EACR,kCACE;GACE,IAAIC;GACJ,IAAIC;GACJ,IAAIC;GACL,EACD,OACD;EACD,iCACE;GACE,IAAI;GACJ,IAAI;GACJ,IAAI;GACL,EACD,OACD;EACF;CACD,eAAe;EACb,kCACE;GACE,IAAIC;GACJ,IAAIC;GACJ,IAAIC;GACL,EACD,OACD;EACD,iCACE;GACE,IAAI;GACJ,IAAI;GACJ,IAAI;GACL,EACD,OACD;EACF;CACD,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ACJ,MAAM;EACN;EACA,SAAS,WAAW;EACpB;EACD,CAAC,CACD,OAAO,QAAQE,4BAAO,MAAM,IAAI,CAAC;AAEpC,6BAAO,KAAK,cAAc,KAAK,MAAM,KAAK"}
1
+ {"version":3,"file":"email.service.cjs","names":["InviteUserEmailEN","InviteUserEmailFR","InviteUserEmailES","ValidateUserEmailEN","ValidateUserEmailFR","ValidateUserEmailES","ResetPasswordEmailEN","ResetPasswordEmailFR","ResetPasswordEmailES","WelcomeEmailEN","WelcomeEmailFR","WelcomeEmailES","MagicLinkEmailEN","MagicLinkEmailFR","MagicLinkEmailES","PasswordChangeConfirmationEmailEN","PasswordChangeConfirmationEmailFR","PasswordChangeConfirmationEmailES","SubscriptionPaymentSuccessEN","SubscriptionPaymentSuccessFR","SubscriptionPaymentSuccessES","SubscriptionPaymentCancellationEN","SubscriptionPaymentCancellationFR","SubscriptionPaymentCancellationES","SubscriptionPaymentErrorEN","SubscriptionPaymentErrorFR","SubscriptionPaymentErrorES","OAuthTokenCreatedEmailEN","OAuthTokenCreatedEmailFR","OAuthTokenCreatedEmailES","resend","Resend","logger"],"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["import {\n InviteUserEmailEN,\n InviteUserEmailES,\n InviteUserEmailFR,\n} from '@emails/InviteUserEmail';\nimport {\n MagicLinkEmailEN,\n MagicLinkEmailES,\n MagicLinkEmailFR,\n} from '@emails/MagicLinkEmail';\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';\nimport type { Locale } from '@intlayer/types';\nimport { logger } from '@logger';\nimport { t } from 'express-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?: Locale) =>\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 magicLink: {\n template: t(\n {\n en: MagicLinkEmailEN,\n fr: MagicLinkEmailFR,\n es: MagicLinkEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Sign in to Intlayer',\n fr: 'Connectez-vous à Intlayer',\n es: 'Inicia sesión en 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?: Locale;\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":";;;;;;;;;;;;;;;;;AAiEA,MAAM,sBAAsB,YACzB;CACC,QAAQ;EACN,kCACE;GACE,IAAIA;GACJ,IAAIC;GACJ,IAAIC;GACL,EACD,OACD;EACD,iCACE;GACE,IAAI;GACJ,IAAI;GACJ,IAAI;GACL,EACD,OACD;EACF;CACD,UAAU;EACR,kCACE;GACE,IAAIC;GACJ,IAAIC;GACJ,IAAIC;GACL,EACD,OACD;EACD,iCACE;GACE,IAAI;GACJ,IAAI;GACJ,IAAI;GACL,EACD,OACD;EACF;CACD,eAAe;EACb,kCACE;GACE,IAAIC;GACJ,IAAIC;G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AmB,OAAO,CAES;CAM3D,MAAM,QAAQ,2CAF6B,YAEb,GAAK,QAAiB;AAEpD,OAAMD,SAAO,OACV,KAAK;EACJ,MAAM;EACN;EACA,SAAS,WAAW;EACpB;EACD,CAAC,CACD,OAAO,QAAQE,4BAAO,MAAM,IAAI,CAAC;AAEpC,6BAAO,KAAK,cAAc,KAAK,MAAM,KAAK"}
@@ -73,7 +73,7 @@ const getClient = async (clientId, clientSecret) => {
73
73
  * @returns The formatted token
74
74
  */
75
75
  const formatOAuth2Token = (token, client, user, project, organization, grants) => {
76
- const { clientId, userId,...restToken } = token;
76
+ const { clientId, userId, ...restToken } = token;
77
77
  if (String(userId) !== String(user.id)) throw new require_utils_errors_ErrorsClass.GenericError("USER_ID_MISMATCH");
78
78
  return {
79
79
  ...restToken,
@@ -1 +1 @@
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,QAAO;EAAE,uCAHoB,GAAG,CAAC,SAAS,MAAM;EAG7B,2CAFc,GAAG,CAAC,SAAS,MAAM;EAEnB;;;;;;;;;AAUnC,MAAa,gCAAgC,OAC3C,aASG;CACH,MAAM,UAAU,MAAMA,0CAAa,QAAQ,EACzC,yBAAyB,UAC1B,CAAC;AAEF,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,eAAe,QAAQ,aAAa,MACvC,WAAW,OAAO,aAAa,SACjC;AAED,KAAI,CAAC,aACH,QAAO;AAUT,QAAO;EACL,QAR8B;GAC9B,IAAI,aAAa;GACjB;GACA,cAAc,aAAa;GAC3B,QAAQ,CAAC,qBAAqB;GAC/B;EAIC;EACA,QAAQ,aAAa;EACrB;EACD;;;;;;;;;AAUH,MAAa,YAAY,OACvB,UACA,iBAC4B;CAC5B,MAAM,SAAS,MAAM,8BAA8B,SAAS;AAE5D,KAAI,CAAC,OACH,QAAO;CAGT,MAAM,EAAE,WAAW;AAEnB,KAAI,CAAC,UAAU,OAAO,iBAAiB,aACrC,QAAO;AAGT,QAAO;;;;;;;;;;;;;AAcT,MAAa,qBACX,OACA,QACA,MACA,SACA,cACA,WACgB;CAEhB,MAAM,EAAE,UAAU,OAAQ,GAAG,cAAc;AAE3C,KAAI,OAAO,OAAO,KAAK,OAAO,KAAK,GAAG,CACpC,OAAM,IAAIC,8CAAa,mBAAmB;AAc5C,QAXoC;EAClC,GAAG;EACH;EACA,MAAMC,uCAAa,KAAK;EACxB,cAAcC,uDAAqB,aAAa;EAChD,SAASC,6CAAgB,QAAQ;EACjC,aAAa,MAAM;EACnB,sBAAsB,MA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AC,OACH,QAAO;AAKT,QAFa,MAAMC,0CAAY,OAAO,IAEvB;;;;;;;;;AAUjB,MAAa,cAAc,OACzB,QACA,QACA,cACqB;AAErB,QAAO;;;;;AAMT,MAAa,4BAA4B,OACvC,gBACmB;AACnB,KAAI;EACF,MAAM,QAAQ,MAAMF,mDAAuB,QAAQ,EACjD,aACD,CAAC;AAEF,MAAI,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
+ {"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,QAAO;EAAE,uCAHoB,GAAG,CAAC,SAAS,MAAM;EAG7B,2CAFc,GAAG,CAAC,SAAS,MAAM;EAEnB;;;;;;;;;AAUnC,MAAa,gCAAgC,OAC3C,aASG;CACH,MAAM,UAAU,MAAMA,0CAAa,QAAQ,EACzC,yBAAyB,UAC1B,CAAC;AAEF,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,eAAe,QAAQ,aAAa,MACvC,WAAW,OAAO,aAAa,SACjC;AAED,KAAI,CAAC,aACH,QAAO;AAUT,QAAO;EACL,QAR8B;GAC9B,IAAI,aAAa;GACjB;GACA,cAAc,aAAa;GAC3B,QAAQ,CAAC,qBAAqB;GAC/B;EAIC;EACA,QAAQ,aAAa;EACrB;EACD;;;;;;;;;AAUH,MAAa,YAAY,OACvB,UACA,iBAC4B;CAC5B,MAAM,SAAS,MAAM,8BAA8B,SAAS;AAE5D,KAAI,CAAC,OACH,QAAO;CAGT,MAAM,EAAE,WAAW;AAEnB,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